Line data Source code
1 : %{
2 :
3 : /*#define YYDEBUG 1*/
4 : /*-------------------------------------------------------------------------
5 : *
6 : * gram.y
7 : * POSTGRESQL BISON rules/actions
8 : *
9 : * Portions Copyright (c) 1996-2025, PostgreSQL Global Development Group
10 : * Portions Copyright (c) 1994, Regents of the University of California
11 : *
12 : *
13 : * IDENTIFICATION
14 : * src/backend/parser/gram.y
15 : *
16 : * HISTORY
17 : * AUTHOR DATE MAJOR EVENT
18 : * Andrew Yu Sept, 1994 POSTQUEL to SQL conversion
19 : * Andrew Yu Oct, 1994 lispy code conversion
20 : *
21 : * NOTES
22 : * CAPITALS are used to represent terminal symbols.
23 : * non-capitals are used to represent non-terminals.
24 : *
25 : * In general, nothing in this file should initiate database accesses
26 : * nor depend on changeable state (such as SET variables). If you do
27 : * database accesses, your code will fail when we have aborted the
28 : * current transaction and are just parsing commands to find the next
29 : * ROLLBACK or COMMIT. If you make use of SET variables, then you
30 : * will do the wrong thing in multi-query strings like this:
31 : * SET constraint_exclusion TO off; SELECT * FROM foo;
32 : * because the entire string is parsed by gram.y before the SET gets
33 : * executed. Anything that depends on the database or changeable state
34 : * should be handled during parse analysis so that it happens at the
35 : * right time not the wrong time.
36 : *
37 : * WARNINGS
38 : * If you use a list, make sure the datum is a node so that the printing
39 : * routines work.
40 : *
41 : * Sometimes we assign constants to makeStrings. Make sure we don't free
42 : * those.
43 : *
44 : *-------------------------------------------------------------------------
45 : */
46 : #include "postgres.h"
47 :
48 : #include <ctype.h>
49 : #include <limits.h>
50 :
51 : #include "catalog/index.h"
52 : #include "catalog/namespace.h"
53 : #include "catalog/pg_am.h"
54 : #include "catalog/pg_trigger.h"
55 : #include "commands/defrem.h"
56 : #include "commands/trigger.h"
57 : #include "gramparse.h"
58 : #include "nodes/makefuncs.h"
59 : #include "nodes/nodeFuncs.h"
60 : #include "parser/parser.h"
61 : #include "utils/datetime.h"
62 : #include "utils/xml.h"
63 :
64 :
65 : /*
66 : * Location tracking support. Unlike bison's default, we only want
67 : * to track the start position not the end position of each nonterminal.
68 : * Nonterminals that reduce to empty receive position "-1". Since a
69 : * production's leading RHS nonterminal(s) may have reduced to empty,
70 : * we have to scan to find the first one that's not -1.
71 : */
72 : #define YYLLOC_DEFAULT(Current, Rhs, N) \
73 : do { \
74 : (Current) = (-1); \
75 : for (int _i = 1; _i <= (N); _i++) \
76 : { \
77 : if ((Rhs)[_i] >= 0) \
78 : { \
79 : (Current) = (Rhs)[_i]; \
80 : break; \
81 : } \
82 : } \
83 : } while (0)
84 :
85 : /*
86 : * Bison doesn't allocate anything that needs to live across parser calls,
87 : * so we can easily have it use palloc instead of malloc. This prevents
88 : * memory leaks if we error out during parsing.
89 : */
90 : #define YYMALLOC palloc
91 : #define YYFREE pfree
92 :
93 : /* Private struct for the result of privilege_target production */
94 : typedef struct PrivTarget
95 : {
96 : GrantTargetType targtype;
97 : ObjectType objtype;
98 : List *objs;
99 : } PrivTarget;
100 :
101 : /* Private struct for the result of import_qualification production */
102 : typedef struct ImportQual
103 : {
104 : ImportForeignSchemaType type;
105 : List *table_names;
106 : } ImportQual;
107 :
108 : /* Private struct for the result of select_limit & limit_clause productions */
109 : typedef struct SelectLimit
110 : {
111 : Node *limitOffset;
112 : Node *limitCount;
113 : LimitOption limitOption; /* indicates presence of WITH TIES */
114 : ParseLoc offsetLoc; /* location of OFFSET token, if present */
115 : ParseLoc countLoc; /* location of LIMIT/FETCH token, if present */
116 : ParseLoc optionLoc; /* location of WITH TIES, if present */
117 : } SelectLimit;
118 :
119 : /* Private struct for the result of group_clause production */
120 : typedef struct GroupClause
121 : {
122 : bool distinct;
123 : bool all;
124 : List *list;
125 : } GroupClause;
126 :
127 : /* Private structs for the result of key_actions and key_action productions */
128 : typedef struct KeyAction
129 : {
130 : char action;
131 : List *cols;
132 : } KeyAction;
133 :
134 : typedef struct KeyActions
135 : {
136 : KeyAction *updateAction;
137 : KeyAction *deleteAction;
138 : } KeyActions;
139 :
140 : /* ConstraintAttributeSpec yields an integer bitmask of these flags: */
141 : #define CAS_NOT_DEFERRABLE 0x01
142 : #define CAS_DEFERRABLE 0x02
143 : #define CAS_INITIALLY_IMMEDIATE 0x04
144 : #define CAS_INITIALLY_DEFERRED 0x08
145 : #define CAS_NOT_VALID 0x10
146 : #define CAS_NO_INHERIT 0x20
147 : #define CAS_NOT_ENFORCED 0x40
148 : #define CAS_ENFORCED 0x80
149 :
150 :
151 : #define parser_yyerror(msg) scanner_yyerror(msg, yyscanner)
152 : #define parser_errposition(pos) scanner_errposition(pos, yyscanner)
153 :
154 : static void base_yyerror(YYLTYPE *yylloc, core_yyscan_t yyscanner,
155 : const char *msg);
156 : static RawStmt *makeRawStmt(Node *stmt, int stmt_location);
157 : static void updateRawStmtEnd(RawStmt *rs, int end_location);
158 : static Node *makeColumnRef(char *colname, List *indirection,
159 : int location, core_yyscan_t yyscanner);
160 : static Node *makeTypeCast(Node *arg, TypeName *typename, int location);
161 : static Node *makeStringConstCast(char *str, int location, TypeName *typename);
162 : static Node *makeIntConst(int val, int location);
163 : static Node *makeFloatConst(char *str, int location);
164 : static Node *makeBoolAConst(bool state, int location);
165 : static Node *makeBitStringConst(char *str, int location);
166 : static Node *makeNullAConst(int location);
167 : static Node *makeAConst(Node *v, int location);
168 : static RoleSpec *makeRoleSpec(RoleSpecType type, int location);
169 : static void check_qualified_name(List *names, core_yyscan_t yyscanner);
170 : static List *check_func_name(List *names, core_yyscan_t yyscanner);
171 : static List *check_indirection(List *indirection, core_yyscan_t yyscanner);
172 : static List *extractArgTypes(List *parameters);
173 : static List *extractAggrArgTypes(List *aggrargs);
174 : static List *makeOrderedSetArgs(List *directargs, List *orderedargs,
175 : core_yyscan_t yyscanner);
176 : static void insertSelectOptions(SelectStmt *stmt,
177 : List *sortClause, List *lockingClause,
178 : SelectLimit *limitClause,
179 : WithClause *withClause,
180 : core_yyscan_t yyscanner);
181 : static Node *makeSetOp(SetOperation op, bool all, Node *larg, Node *rarg);
182 : static Node *doNegate(Node *n, int location);
183 : static void doNegateFloat(Float *v);
184 : static Node *makeAndExpr(Node *lexpr, Node *rexpr, int location);
185 : static Node *makeOrExpr(Node *lexpr, Node *rexpr, int location);
186 : static Node *makeNotExpr(Node *expr, int location);
187 : static Node *makeAArrayExpr(List *elements, int location, int end_location);
188 : static Node *makeSQLValueFunction(SQLValueFunctionOp op, int32 typmod,
189 : int location);
190 : static Node *makeXmlExpr(XmlExprOp op, char *name, List *named_args,
191 : List *args, int location);
192 : static List *mergeTableFuncParameters(List *func_args, List *columns, core_yyscan_t yyscanner);
193 : static TypeName *TableFuncTypeName(List *columns);
194 : static RangeVar *makeRangeVarFromAnyName(List *names, int position, core_yyscan_t yyscanner);
195 : static RangeVar *makeRangeVarFromQualifiedName(char *name, List *namelist, int location,
196 : core_yyscan_t yyscanner);
197 : static void SplitColQualList(List *qualList,
198 : List **constraintList, CollateClause **collClause,
199 : core_yyscan_t yyscanner);
200 : static void processCASbits(int cas_bits, int location, const char *constrType,
201 : bool *deferrable, bool *initdeferred, bool *is_enforced,
202 : bool *not_valid, bool *no_inherit, core_yyscan_t yyscanner);
203 : static PartitionStrategy parsePartitionStrategy(char *strategy, int location,
204 : core_yyscan_t yyscanner);
205 : static void preprocess_pubobj_list(List *pubobjspec_list,
206 : core_yyscan_t yyscanner);
207 : static Node *makeRecursiveViewSelect(char *relname, List *aliases, Node *query);
208 :
209 : %}
210 :
211 : %pure-parser
212 : %expect 0
213 : %name-prefix="base_yy"
214 : %locations
215 :
216 : %parse-param {core_yyscan_t yyscanner}
217 : %lex-param {core_yyscan_t yyscanner}
218 :
219 : %union
220 : {
221 : core_YYSTYPE core_yystype;
222 : /* these fields must match core_YYSTYPE: */
223 : int ival;
224 : char *str;
225 : const char *keyword;
226 :
227 : char chr;
228 : bool boolean;
229 : JoinType jtype;
230 : DropBehavior dbehavior;
231 : OnCommitAction oncommit;
232 : List *list;
233 : Node *node;
234 : ObjectType objtype;
235 : TypeName *typnam;
236 : FunctionParameter *fun_param;
237 : FunctionParameterMode fun_param_mode;
238 : ObjectWithArgs *objwithargs;
239 : DefElem *defelt;
240 : SortBy *sortby;
241 : WindowDef *windef;
242 : JoinExpr *jexpr;
243 : IndexElem *ielem;
244 : StatsElem *selem;
245 : Alias *alias;
246 : RangeVar *range;
247 : IntoClause *into;
248 : WithClause *with;
249 : InferClause *infer;
250 : OnConflictClause *onconflict;
251 : A_Indices *aind;
252 : ResTarget *target;
253 : struct PrivTarget *privtarget;
254 : AccessPriv *accesspriv;
255 : struct ImportQual *importqual;
256 : InsertStmt *istmt;
257 : VariableSetStmt *vsetstmt;
258 : PartitionElem *partelem;
259 : PartitionSpec *partspec;
260 : PartitionBoundSpec *partboundspec;
261 : RoleSpec *rolespec;
262 : PublicationObjSpec *publicationobjectspec;
263 : struct SelectLimit *selectlimit;
264 : SetQuantifier setquantifier;
265 : struct GroupClause *groupclause;
266 : MergeMatchKind mergematch;
267 : MergeWhenClause *mergewhen;
268 : struct KeyActions *keyactions;
269 : struct KeyAction *keyaction;
270 : ReturningClause *retclause;
271 : ReturningOptionKind retoptionkind;
272 : }
273 :
274 : %type <node> stmt toplevel_stmt schema_stmt routine_body_stmt
275 : AlterEventTrigStmt AlterCollationStmt
276 : AlterDatabaseStmt AlterDatabaseSetStmt AlterDomainStmt AlterEnumStmt
277 : AlterFdwStmt AlterForeignServerStmt AlterGroupStmt
278 : AlterObjectDependsStmt AlterObjectSchemaStmt AlterOwnerStmt
279 : AlterOperatorStmt AlterTypeStmt AlterSeqStmt AlterSystemStmt AlterTableStmt
280 : AlterTblSpcStmt AlterExtensionStmt AlterExtensionContentsStmt
281 : AlterCompositeTypeStmt AlterUserMappingStmt
282 : AlterRoleStmt AlterRoleSetStmt AlterPolicyStmt AlterStatsStmt
283 : AlterDefaultPrivilegesStmt DefACLAction
284 : AnalyzeStmt CallStmt ClosePortalStmt ClusterStmt CommentStmt
285 : ConstraintsSetStmt CopyStmt CreateAsStmt CreateCastStmt
286 : CreateDomainStmt CreateExtensionStmt CreateGroupStmt CreateOpClassStmt
287 : CreateOpFamilyStmt AlterOpFamilyStmt CreatePLangStmt
288 : CreateSchemaStmt CreateSeqStmt CreateStmt CreateStatsStmt CreateTableSpaceStmt
289 : CreateFdwStmt CreateForeignServerStmt CreateForeignTableStmt
290 : CreateAssertionStmt CreateTransformStmt CreateTrigStmt CreateEventTrigStmt
291 : CreateUserStmt CreateUserMappingStmt CreateRoleStmt CreatePolicyStmt
292 : CreatedbStmt DeclareCursorStmt DefineStmt DeleteStmt DiscardStmt DoStmt
293 : DropOpClassStmt DropOpFamilyStmt DropStmt
294 : DropCastStmt DropRoleStmt
295 : DropdbStmt DropTableSpaceStmt
296 : DropTransformStmt
297 : DropUserMappingStmt ExplainStmt FetchStmt
298 : GrantStmt GrantRoleStmt ImportForeignSchemaStmt IndexStmt InsertStmt
299 : ListenStmt LoadStmt LockStmt MergeStmt NotifyStmt ExplainableStmt PreparableStmt
300 : CreateFunctionStmt AlterFunctionStmt ReindexStmt RemoveAggrStmt
301 : RemoveFuncStmt RemoveOperStmt RenameStmt ReturnStmt RevokeStmt RevokeRoleStmt
302 : RuleActionStmt RuleActionStmtOrEmpty RuleStmt
303 : SecLabelStmt SelectStmt TransactionStmt TransactionStmtLegacy TruncateStmt
304 : UnlistenStmt UpdateStmt VacuumStmt
305 : VariableResetStmt VariableSetStmt VariableShowStmt
306 : ViewStmt CheckPointStmt CreateConversionStmt
307 : DeallocateStmt PrepareStmt ExecuteStmt
308 : DropOwnedStmt ReassignOwnedStmt
309 : AlterTSConfigurationStmt AlterTSDictionaryStmt
310 : CreateMatViewStmt RefreshMatViewStmt CreateAmStmt
311 : CreatePublicationStmt AlterPublicationStmt
312 : CreateSubscriptionStmt AlterSubscriptionStmt DropSubscriptionStmt
313 :
314 : %type <node> select_no_parens select_with_parens select_clause
315 : simple_select values_clause
316 : PLpgSQL_Expr PLAssignStmt
317 :
318 : %type <str> opt_single_name
319 : %type <list> opt_qualified_name
320 : %type <boolean> opt_concurrently
321 : %type <dbehavior> opt_drop_behavior
322 : %type <list> opt_utility_option_list
323 : %type <list> utility_option_list
324 : %type <defelt> utility_option_elem
325 : %type <str> utility_option_name
326 : %type <node> utility_option_arg
327 :
328 : %type <node> alter_column_default opclass_item opclass_drop alter_using
329 : %type <ival> add_drop opt_asc_desc opt_nulls_order
330 :
331 : %type <node> alter_table_cmd alter_type_cmd opt_collate_clause
332 : replica_identity partition_cmd index_partition_cmd
333 : %type <list> alter_table_cmds alter_type_cmds
334 : %type <list> alter_identity_column_option_list
335 : %type <defelt> alter_identity_column_option
336 : %type <node> set_statistics_value
337 : %type <str> set_access_method_name
338 :
339 : %type <list> createdb_opt_list createdb_opt_items copy_opt_list
340 : transaction_mode_list
341 : create_extension_opt_list alter_extension_opt_list
342 : %type <defelt> createdb_opt_item copy_opt_item
343 : transaction_mode_item
344 : create_extension_opt_item alter_extension_opt_item
345 :
346 : %type <ival> opt_lock lock_type cast_context
347 : %type <defelt> drop_option
348 : %type <boolean> opt_or_replace opt_no
349 : opt_grant_grant_option
350 : opt_nowait opt_if_exists opt_with_data
351 : opt_transaction_chain
352 : %type <list> grant_role_opt_list
353 : %type <defelt> grant_role_opt
354 : %type <node> grant_role_opt_value
355 : %type <ival> opt_nowait_or_skip
356 :
357 : %type <list> OptRoleList AlterOptRoleList
358 : %type <defelt> CreateOptRoleElem AlterOptRoleElem
359 :
360 : %type <str> opt_type
361 : %type <str> foreign_server_version opt_foreign_server_version
362 : %type <str> opt_in_database
363 :
364 : %type <str> parameter_name
365 : %type <list> OptSchemaEltList parameter_name_list
366 :
367 : %type <chr> am_type
368 :
369 : %type <boolean> TriggerForSpec TriggerForType
370 : %type <ival> TriggerActionTime
371 : %type <list> TriggerEvents TriggerOneEvent
372 : %type <node> TriggerFuncArg
373 : %type <node> TriggerWhen
374 : %type <str> TransitionRelName
375 : %type <boolean> TransitionRowOrTable TransitionOldOrNew
376 : %type <node> TriggerTransition
377 :
378 : %type <list> event_trigger_when_list event_trigger_value_list
379 : %type <defelt> event_trigger_when_item
380 : %type <chr> enable_trigger
381 :
382 : %type <str> copy_file_name
383 : access_method_clause attr_name
384 : table_access_method_clause name cursor_name file_name
385 : cluster_index_specification
386 :
387 : %type <list> func_name handler_name qual_Op qual_all_Op subquery_Op
388 : opt_inline_handler opt_validator validator_clause
389 : opt_collate
390 :
391 : %type <range> qualified_name insert_target OptConstrFromTable
392 :
393 : %type <str> all_Op MathOp
394 :
395 : %type <str> row_security_cmd RowSecurityDefaultForCmd
396 : %type <boolean> RowSecurityDefaultPermissive
397 : %type <node> RowSecurityOptionalWithCheck RowSecurityOptionalExpr
398 : %type <list> RowSecurityDefaultToRole RowSecurityOptionalToRole
399 :
400 : %type <str> iso_level opt_encoding
401 : %type <rolespec> grantee
402 : %type <list> grantee_list
403 : %type <accesspriv> privilege
404 : %type <list> privileges privilege_list
405 : %type <privtarget> privilege_target
406 : %type <objwithargs> function_with_argtypes aggregate_with_argtypes operator_with_argtypes
407 : %type <list> function_with_argtypes_list aggregate_with_argtypes_list operator_with_argtypes_list
408 : %type <ival> defacl_privilege_target
409 : %type <defelt> DefACLOption
410 : %type <list> DefACLOptionList
411 : %type <ival> import_qualification_type
412 : %type <importqual> import_qualification
413 : %type <node> vacuum_relation
414 : %type <selectlimit> opt_select_limit select_limit limit_clause
415 :
416 : %type <list> parse_toplevel stmtmulti routine_body_stmt_list
417 : OptTableElementList TableElementList OptInherit definition
418 : OptTypedTableElementList TypedTableElementList
419 : reloptions opt_reloptions
420 : OptWith opt_definition func_args func_args_list
421 : func_args_with_defaults func_args_with_defaults_list
422 : aggr_args aggr_args_list
423 : func_as createfunc_opt_list opt_createfunc_opt_list alterfunc_opt_list
424 : old_aggr_definition old_aggr_list
425 : oper_argtypes RuleActionList RuleActionMulti
426 : opt_column_list columnList opt_name_list
427 : sort_clause opt_sort_clause sortby_list index_params
428 : stats_params
429 : opt_include opt_c_include index_including_params
430 : name_list role_list from_clause from_list opt_array_bounds
431 : qualified_name_list any_name any_name_list type_name_list
432 : any_operator expr_list attrs
433 : distinct_clause opt_distinct_clause
434 : target_list opt_target_list insert_column_list set_target_list
435 : merge_values_clause
436 : set_clause_list set_clause
437 : def_list operator_def_list indirection opt_indirection
438 : reloption_list TriggerFuncArgs opclass_item_list opclass_drop_list
439 : opclass_purpose opt_opfamily transaction_mode_list_or_empty
440 : OptTableFuncElementList TableFuncElementList opt_type_modifiers
441 : prep_type_clause
442 : execute_param_clause using_clause
443 : returning_with_clause returning_options
444 : opt_enum_val_list enum_val_list table_func_column_list
445 : create_generic_options alter_generic_options
446 : relation_expr_list dostmt_opt_list
447 : transform_element_list transform_type_list
448 : TriggerTransitions TriggerReferencing
449 : vacuum_relation_list opt_vacuum_relation_list
450 : drop_option_list pub_obj_list
451 :
452 : %type <retclause> returning_clause
453 : %type <node> returning_option
454 : %type <retoptionkind> returning_option_kind
455 : %type <node> opt_routine_body
456 : %type <groupclause> group_clause
457 : %type <list> group_by_list
458 : %type <node> group_by_item empty_grouping_set rollup_clause cube_clause
459 : %type <node> grouping_sets_clause
460 :
461 : %type <list> opt_fdw_options fdw_options
462 : %type <defelt> fdw_option
463 :
464 : %type <range> OptTempTableName
465 : %type <into> into_clause create_as_target create_mv_target
466 :
467 : %type <defelt> createfunc_opt_item common_func_opt_item dostmt_opt_item
468 : %type <fun_param> func_arg func_arg_with_default table_func_column aggr_arg
469 : %type <fun_param_mode> arg_class
470 : %type <typnam> func_return func_type
471 :
472 : %type <boolean> opt_trusted opt_restart_seqs
473 : %type <ival> OptTemp
474 : %type <ival> OptNoLog
475 : %type <oncommit> OnCommitOption
476 :
477 : %type <ival> for_locking_strength
478 : %type <node> for_locking_item
479 : %type <list> for_locking_clause opt_for_locking_clause for_locking_items
480 : %type <list> locked_rels_list
481 : %type <setquantifier> set_quantifier
482 :
483 : %type <node> join_qual
484 : %type <jtype> join_type
485 :
486 : %type <list> extract_list overlay_list position_list
487 : %type <list> substr_list trim_list
488 : %type <list> opt_interval interval_second
489 : %type <str> unicode_normal_form
490 :
491 : %type <boolean> opt_instead
492 : %type <boolean> opt_unique opt_verbose opt_full
493 : %type <boolean> opt_freeze opt_analyze opt_default
494 : %type <defelt> opt_binary copy_delimiter
495 :
496 : %type <boolean> copy_from opt_program
497 :
498 : %type <ival> event cursor_options opt_hold opt_set_data
499 : %type <objtype> object_type_any_name object_type_name object_type_name_on_any_name
500 : drop_type_name
501 :
502 : %type <node> fetch_args select_limit_value
503 : offset_clause select_offset_value
504 : select_fetch_first_value I_or_F_const
505 : %type <ival> row_or_rows first_or_next
506 :
507 : %type <list> OptSeqOptList SeqOptList OptParenthesizedSeqOptList
508 : %type <defelt> SeqOptElem
509 :
510 : %type <istmt> insert_rest
511 : %type <infer> opt_conf_expr
512 : %type <onconflict> opt_on_conflict
513 : %type <mergewhen> merge_insert merge_update merge_delete
514 :
515 : %type <mergematch> merge_when_tgt_matched merge_when_tgt_not_matched
516 : %type <node> merge_when_clause opt_merge_when_condition
517 : %type <list> merge_when_list
518 :
519 : %type <vsetstmt> generic_set set_rest set_rest_more generic_reset reset_rest
520 : SetResetClause FunctionSetResetClause
521 :
522 : %type <node> TableElement TypedTableElement ConstraintElem DomainConstraintElem TableFuncElement
523 : %type <node> columnDef columnOptions optionalPeriodName
524 : %type <defelt> def_elem reloption_elem old_aggr_elem operator_def_elem
525 : %type <node> def_arg columnElem where_clause where_or_current_clause
526 : a_expr b_expr c_expr AexprConst indirection_el opt_slice_bound
527 : columnref having_clause func_table xmltable array_expr
528 : OptWhereClause operator_def_arg
529 : %type <list> opt_column_and_period_list
530 : %type <list> rowsfrom_item rowsfrom_list opt_col_def_list
531 : %type <boolean> opt_ordinality opt_without_overlaps
532 : %type <list> ExclusionConstraintList ExclusionConstraintElem
533 : %type <list> func_arg_list func_arg_list_opt
534 : %type <node> func_arg_expr
535 : %type <list> row explicit_row implicit_row type_list array_expr_list
536 : %type <node> case_expr case_arg when_clause case_default
537 : %type <list> when_clause_list
538 : %type <node> opt_search_clause opt_cycle_clause
539 : %type <ival> sub_type opt_materialized
540 : %type <node> NumericOnly
541 : %type <list> NumericOnly_list
542 : %type <alias> alias_clause opt_alias_clause opt_alias_clause_for_join_using
543 : %type <list> func_alias_clause
544 : %type <sortby> sortby
545 : %type <ielem> index_elem index_elem_options
546 : %type <selem> stats_param
547 : %type <node> table_ref
548 : %type <jexpr> joined_table
549 : %type <range> relation_expr
550 : %type <range> extended_relation_expr
551 : %type <range> relation_expr_opt_alias
552 : %type <node> tablesample_clause opt_repeatable_clause
553 : %type <target> target_el set_target insert_column_item
554 :
555 : %type <str> generic_option_name
556 : %type <node> generic_option_arg
557 : %type <defelt> generic_option_elem alter_generic_option_elem
558 : %type <list> generic_option_list alter_generic_option_list
559 :
560 : %type <ival> reindex_target_relation reindex_target_all
561 :
562 : %type <node> copy_generic_opt_arg copy_generic_opt_arg_list_item
563 : %type <defelt> copy_generic_opt_elem
564 : %type <list> copy_generic_opt_list copy_generic_opt_arg_list
565 : %type <list> copy_options
566 :
567 : %type <typnam> Typename SimpleTypename ConstTypename
568 : GenericType Numeric opt_float JsonType
569 : Character ConstCharacter
570 : CharacterWithLength CharacterWithoutLength
571 : ConstDatetime ConstInterval
572 : Bit ConstBit BitWithLength BitWithoutLength
573 : %type <str> character
574 : %type <str> extract_arg
575 : %type <boolean> opt_varying opt_timezone opt_no_inherit
576 :
577 : %type <ival> Iconst SignedIconst
578 : %type <str> Sconst comment_text notify_payload
579 : %type <str> RoleId opt_boolean_or_string
580 : %type <list> var_list
581 : %type <str> ColId ColLabel BareColLabel
582 : %type <str> NonReservedWord NonReservedWord_or_Sconst
583 : %type <str> var_name type_function_name param_name
584 : %type <str> createdb_opt_name plassign_target
585 : %type <node> var_value zone_value
586 : %type <rolespec> auth_ident RoleSpec opt_granted_by
587 : %type <publicationobjectspec> PublicationObjSpec
588 :
589 : %type <keyword> unreserved_keyword type_func_name_keyword
590 : %type <keyword> col_name_keyword reserved_keyword
591 : %type <keyword> bare_label_keyword
592 :
593 : %type <node> DomainConstraint TableConstraint TableLikeClause
594 : %type <ival> TableLikeOptionList TableLikeOption
595 : %type <str> column_compression opt_column_compression column_storage opt_column_storage
596 : %type <list> ColQualList
597 : %type <node> ColConstraint ColConstraintElem ConstraintAttr
598 : %type <ival> key_match
599 : %type <keyaction> key_delete key_update key_action
600 : %type <keyactions> key_actions
601 : %type <ival> ConstraintAttributeSpec ConstraintAttributeElem
602 : %type <str> ExistingIndex
603 :
604 : %type <list> constraints_set_list
605 : %type <boolean> constraints_set_mode
606 : %type <str> OptTableSpace OptConsTableSpace
607 : %type <rolespec> OptTableSpaceOwner
608 : %type <ival> opt_check_option
609 :
610 : %type <str> opt_provider security_label
611 :
612 : %type <target> xml_attribute_el
613 : %type <list> xml_attribute_list xml_attributes
614 : %type <node> xml_root_version opt_xml_root_standalone
615 : %type <node> xmlexists_argument
616 : %type <ival> document_or_content
617 : %type <boolean> xml_indent_option xml_whitespace_option
618 : %type <list> xmltable_column_list xmltable_column_option_list
619 : %type <node> xmltable_column_el
620 : %type <defelt> xmltable_column_option_el
621 : %type <list> xml_namespace_list
622 : %type <target> xml_namespace_el
623 :
624 : %type <node> func_application func_expr_common_subexpr
625 : %type <node> func_expr func_expr_windowless
626 : %type <node> common_table_expr
627 : %type <with> with_clause opt_with_clause
628 : %type <list> cte_list
629 :
630 : %type <list> within_group_clause
631 : %type <node> filter_clause
632 : %type <list> window_clause window_definition_list opt_partition_clause
633 : %type <windef> window_definition over_clause window_specification
634 : opt_frame_clause frame_extent frame_bound
635 : %type <ival> opt_window_exclusion_clause
636 : %type <str> opt_existing_window_name
637 : %type <boolean> opt_if_not_exists
638 : %type <boolean> opt_unique_null_treatment
639 : %type <ival> generated_when override_kind opt_virtual_or_stored
640 : %type <partspec> PartitionSpec OptPartitionSpec
641 : %type <partelem> part_elem
642 : %type <list> part_params
643 : %type <partboundspec> PartitionBoundSpec
644 : %type <list> hash_partbound
645 : %type <defelt> hash_partbound_elem
646 :
647 : %type <node> json_format_clause
648 : json_format_clause_opt
649 : json_value_expr
650 : json_returning_clause_opt
651 : json_name_and_value
652 : json_aggregate_func
653 : json_argument
654 : json_behavior
655 : json_on_error_clause_opt
656 : json_table
657 : json_table_column_definition
658 : json_table_column_path_clause_opt
659 : %type <list> json_name_and_value_list
660 : json_value_expr_list
661 : json_array_aggregate_order_by_clause_opt
662 : json_arguments
663 : json_behavior_clause_opt
664 : json_passing_clause_opt
665 : json_table_column_definition_list
666 : %type <str> json_table_path_name_opt
667 : %type <ival> json_behavior_type
668 : json_predicate_type_constraint
669 : json_quotes_clause_opt
670 : json_wrapper_behavior
671 : %type <boolean> json_key_uniqueness_constraint_opt
672 : json_object_constructor_null_clause_opt
673 : json_array_constructor_null_clause_opt
674 :
675 :
676 : /*
677 : * Non-keyword token types. These are hard-wired into the "flex" lexer.
678 : * They must be listed first so that their numeric codes do not depend on
679 : * the set of keywords. PL/pgSQL depends on this so that it can share the
680 : * same lexer. If you add/change tokens here, fix PL/pgSQL to match!
681 : *
682 : * UIDENT and USCONST are reduced to IDENT and SCONST in parser.c, so that
683 : * they need no productions here; but we must assign token codes to them.
684 : *
685 : * DOT_DOT is unused in the core SQL grammar, and so will always provoke
686 : * parse errors. It is needed by PL/pgSQL.
687 : */
688 : %token <str> IDENT UIDENT FCONST SCONST USCONST BCONST XCONST Op
689 : %token <ival> ICONST PARAM
690 : %token TYPECAST DOT_DOT COLON_EQUALS EQUALS_GREATER
691 : %token LESS_EQUALS GREATER_EQUALS NOT_EQUALS
692 :
693 : /*
694 : * If you want to make any keyword changes, update the keyword table in
695 : * src/include/parser/kwlist.h and add new keywords to the appropriate one
696 : * of the reserved-or-not-so-reserved keyword lists, below; search
697 : * this file for "Keyword category lists".
698 : */
699 :
700 : /* ordinary key words in alphabetical order */
701 : %token <keyword> ABORT_P ABSENT ABSOLUTE_P ACCESS ACTION ADD_P ADMIN AFTER
702 : AGGREGATE ALL ALSO ALTER ALWAYS ANALYSE ANALYZE AND ANY ARRAY AS ASC
703 : ASENSITIVE ASSERTION ASSIGNMENT ASYMMETRIC ATOMIC AT ATTACH ATTRIBUTE AUTHORIZATION
704 :
705 : BACKWARD BEFORE BEGIN_P BETWEEN BIGINT BINARY BIT
706 : BOOLEAN_P BOTH BREADTH BY
707 :
708 : CACHE CALL CALLED CASCADE CASCADED CASE CAST CATALOG_P CHAIN CHAR_P
709 : CHARACTER CHARACTERISTICS CHECK CHECKPOINT CLASS CLOSE
710 : CLUSTER COALESCE COLLATE COLLATION COLUMN COLUMNS COMMENT COMMENTS COMMIT
711 : COMMITTED COMPRESSION CONCURRENTLY CONDITIONAL CONFIGURATION CONFLICT
712 : CONNECTION CONSTRAINT CONSTRAINTS CONTENT_P CONTINUE_P CONVERSION_P COPY
713 : COST CREATE CROSS CSV CUBE CURRENT_P
714 : CURRENT_CATALOG CURRENT_DATE CURRENT_ROLE CURRENT_SCHEMA
715 : CURRENT_TIME CURRENT_TIMESTAMP CURRENT_USER CURSOR CYCLE
716 :
717 : DATA_P DATABASE DAY_P DEALLOCATE DEC DECIMAL_P DECLARE DEFAULT DEFAULTS
718 : DEFERRABLE DEFERRED DEFINER DELETE_P DELIMITER DELIMITERS DEPENDS DEPTH DESC
719 : DETACH DICTIONARY DISABLE_P DISCARD DISTINCT DO DOCUMENT_P DOMAIN_P
720 : DOUBLE_P DROP
721 :
722 : EACH ELSE EMPTY_P ENABLE_P ENCODING ENCRYPTED END_P ENFORCED ENUM_P ERROR_P
723 : ESCAPE EVENT EXCEPT EXCLUDE EXCLUDING EXCLUSIVE EXECUTE EXISTS EXPLAIN
724 : EXPRESSION EXTENSION EXTERNAL EXTRACT
725 :
726 : FALSE_P FAMILY FETCH FILTER FINALIZE FIRST_P FLOAT_P FOLLOWING FOR
727 : FORCE FOREIGN FORMAT FORWARD FREEZE FROM FULL FUNCTION FUNCTIONS
728 :
729 : GENERATED GLOBAL GRANT GRANTED GREATEST GROUP_P GROUPING GROUPS
730 :
731 : HANDLER HAVING HEADER_P HOLD HOUR_P
732 :
733 : IDENTITY_P IF_P ILIKE IMMEDIATE IMMUTABLE IMPLICIT_P IMPORT_P IN_P INCLUDE
734 : INCLUDING INCREMENT INDENT INDEX INDEXES INHERIT INHERITS INITIALLY INLINE_P
735 : INNER_P INOUT INPUT_P INSENSITIVE INSERT INSTEAD INT_P INTEGER
736 : INTERSECT INTERVAL INTO INVOKER IS ISNULL ISOLATION
737 :
738 : JOIN JSON JSON_ARRAY JSON_ARRAYAGG JSON_EXISTS JSON_OBJECT JSON_OBJECTAGG
739 : JSON_QUERY JSON_SCALAR JSON_SERIALIZE JSON_TABLE JSON_VALUE
740 :
741 : KEEP KEY KEYS
742 :
743 : LABEL LANGUAGE LARGE_P LAST_P LATERAL_P
744 : LEADING LEAKPROOF LEAST LEFT LEVEL LIKE LIMIT LISTEN LOAD LOCAL
745 : LOCALTIME LOCALTIMESTAMP LOCATION LOCK_P LOCKED LOGGED
746 :
747 : MAPPING MATCH MATCHED MATERIALIZED MAXVALUE MERGE MERGE_ACTION METHOD
748 : MINUTE_P MINVALUE MODE MONTH_P MOVE
749 :
750 : NAME_P NAMES NATIONAL NATURAL NCHAR NESTED NEW NEXT NFC NFD NFKC NFKD NO
751 : NONE NORMALIZE NORMALIZED
752 : NOT NOTHING NOTIFY NOTNULL NOWAIT NULL_P NULLIF
753 : NULLS_P NUMERIC
754 :
755 : OBJECT_P OBJECTS_P OF OFF OFFSET OIDS OLD OMIT ON ONLY OPERATOR OPTION OPTIONS OR
756 : ORDER ORDINALITY OTHERS OUT_P OUTER_P
757 : OVER OVERLAPS OVERLAY OVERRIDING OWNED OWNER
758 :
759 : PARALLEL PARAMETER PARSER PARTIAL PARTITION PASSING PASSWORD PATH
760 : PERIOD PLACING PLAN PLANS POLICY
761 : POSITION PRECEDING PRECISION PRESERVE PREPARE PREPARED PRIMARY
762 : PRIOR PRIVILEGES PROCEDURAL PROCEDURE PROCEDURES PROGRAM PUBLICATION
763 :
764 : QUOTE QUOTES
765 :
766 : RANGE READ REAL REASSIGN RECURSIVE REF_P REFERENCES REFERENCING
767 : REFRESH REINDEX RELATIVE_P RELEASE RENAME REPEATABLE REPLACE REPLICA
768 : RESET RESTART RESTRICT RETURN RETURNING RETURNS REVOKE RIGHT ROLE ROLLBACK ROLLUP
769 : ROUTINE ROUTINES ROW ROWS RULE
770 :
771 : SAVEPOINT SCALAR SCHEMA SCHEMAS SCROLL SEARCH SECOND_P SECURITY SELECT
772 : SEQUENCE SEQUENCES
773 : SERIALIZABLE SERVER SESSION SESSION_USER SET SETS SETOF SHARE SHOW
774 : SIMILAR SIMPLE SKIP SMALLINT SNAPSHOT SOME SOURCE SQL_P STABLE STANDALONE_P
775 : START STATEMENT STATISTICS STDIN STDOUT STORAGE STORED STRICT_P STRING_P STRIP_P
776 : SUBSCRIPTION SUBSTRING SUPPORT SYMMETRIC SYSID SYSTEM_P SYSTEM_USER
777 :
778 : TABLE TABLES TABLESAMPLE TABLESPACE TARGET TEMP TEMPLATE TEMPORARY TEXT_P THEN
779 : TIES TIME TIMESTAMP TO TRAILING TRANSACTION TRANSFORM
780 : TREAT TRIGGER TRIM TRUE_P
781 : TRUNCATE TRUSTED TYPE_P TYPES_P
782 :
783 : UESCAPE UNBOUNDED UNCONDITIONAL UNCOMMITTED UNENCRYPTED UNION UNIQUE UNKNOWN
784 : UNLISTEN UNLOGGED UNTIL UPDATE USER USING
785 :
786 : VACUUM VALID VALIDATE VALIDATOR VALUE_P VALUES VARCHAR VARIADIC VARYING
787 : VERBOSE VERSION_P VIEW VIEWS VIRTUAL VOLATILE
788 :
789 : WHEN WHERE WHITESPACE_P WINDOW WITH WITHIN WITHOUT WORK WRAPPER WRITE
790 :
791 : XML_P XMLATTRIBUTES XMLCONCAT XMLELEMENT XMLEXISTS XMLFOREST XMLNAMESPACES
792 : XMLPARSE XMLPI XMLROOT XMLSERIALIZE XMLTABLE
793 :
794 : YEAR_P YES_P
795 :
796 : ZONE
797 :
798 : /*
799 : * The grammar thinks these are keywords, but they are not in the kwlist.h
800 : * list and so can never be entered directly. The filter in parser.c
801 : * creates these tokens when required (based on looking one token ahead).
802 : *
803 : * NOT_LA exists so that productions such as NOT LIKE can be given the same
804 : * precedence as LIKE; otherwise they'd effectively have the same precedence
805 : * as NOT, at least with respect to their left-hand subexpression.
806 : * FORMAT_LA, NULLS_LA, WITH_LA, and WITHOUT_LA are needed to make the grammar
807 : * LALR(1).
808 : */
809 : %token FORMAT_LA NOT_LA NULLS_LA WITH_LA WITHOUT_LA
810 :
811 : /*
812 : * The grammar likewise thinks these tokens are keywords, but they are never
813 : * generated by the scanner. Rather, they can be injected by parser.c as
814 : * the initial token of the string (using the lookahead-token mechanism
815 : * implemented there). This provides a way to tell the grammar to parse
816 : * something other than the usual list of SQL commands.
817 : */
818 : %token MODE_TYPE_NAME
819 : %token MODE_PLPGSQL_EXPR
820 : %token MODE_PLPGSQL_ASSIGN1
821 : %token MODE_PLPGSQL_ASSIGN2
822 : %token MODE_PLPGSQL_ASSIGN3
823 :
824 :
825 : /* Precedence: lowest to highest */
826 : %left UNION EXCEPT
827 : %left INTERSECT
828 : %left OR
829 : %left AND
830 : %right NOT
831 : %nonassoc IS ISNULL NOTNULL /* IS sets precedence for IS NULL, etc */
832 : %nonassoc '<' '>' '=' LESS_EQUALS GREATER_EQUALS NOT_EQUALS
833 : %nonassoc BETWEEN IN_P LIKE ILIKE SIMILAR NOT_LA
834 : %nonassoc ESCAPE /* ESCAPE must be just above LIKE/ILIKE/SIMILAR */
835 :
836 : /*
837 : * Sometimes it is necessary to assign precedence to keywords that are not
838 : * really part of the operator hierarchy, in order to resolve grammar
839 : * ambiguities. It's best to avoid doing so whenever possible, because such
840 : * assignments have global effect and may hide ambiguities besides the one
841 : * you intended to solve. (Attaching a precedence to a single rule with
842 : * %prec is far safer and should be preferred.) If you must give precedence
843 : * to a new keyword, try very hard to give it the same precedence as IDENT.
844 : * If the keyword has IDENT's precedence then it clearly acts the same as
845 : * non-keywords and other similar keywords, thus reducing the risk of
846 : * unexpected precedence effects.
847 : *
848 : * We used to need to assign IDENT an explicit precedence just less than Op,
849 : * to support target_el without AS. While that's not really necessary since
850 : * we removed postfix operators, we continue to do so because it provides a
851 : * reference point for a precedence level that we can assign to other
852 : * keywords that lack a natural precedence level.
853 : *
854 : * We need to do this for PARTITION, RANGE, ROWS, and GROUPS to support
855 : * opt_existing_window_name (see comment there).
856 : *
857 : * The frame_bound productions UNBOUNDED PRECEDING and UNBOUNDED FOLLOWING
858 : * are even messier: since UNBOUNDED is an unreserved keyword (per spec!),
859 : * there is no principled way to distinguish these from the productions
860 : * a_expr PRECEDING/FOLLOWING. We hack this up by giving UNBOUNDED slightly
861 : * lower precedence than PRECEDING and FOLLOWING. At present this doesn't
862 : * appear to cause UNBOUNDED to be treated differently from other unreserved
863 : * keywords anywhere else in the grammar, but it's definitely risky. We can
864 : * blame any funny behavior of UNBOUNDED on the SQL standard, though.
865 : *
866 : * To support CUBE and ROLLUP in GROUP BY without reserving them, we give them
867 : * an explicit priority lower than '(', so that a rule with CUBE '(' will shift
868 : * rather than reducing a conflicting rule that takes CUBE as a function name.
869 : * Using the same precedence as IDENT seems right for the reasons given above.
870 : *
871 : * SET is likewise assigned the same precedence as IDENT, to support the
872 : * relation_expr_opt_alias production (see comment there).
873 : *
874 : * KEYS, OBJECT_P, SCALAR, VALUE_P, WITH, and WITHOUT are similarly assigned
875 : * the same precedence as IDENT. This allows resolving conflicts in the
876 : * json_predicate_type_constraint and json_key_uniqueness_constraint_opt
877 : * productions (see comments there).
878 : *
879 : * Like the UNBOUNDED PRECEDING/FOLLOWING case, NESTED is assigned a lower
880 : * precedence than PATH to fix ambiguity in the json_table production.
881 : */
882 : %nonassoc UNBOUNDED NESTED /* ideally would have same precedence as IDENT */
883 : %nonassoc IDENT PARTITION RANGE ROWS GROUPS PRECEDING FOLLOWING CUBE ROLLUP
884 : SET KEYS OBJECT_P SCALAR VALUE_P WITH WITHOUT PATH
885 : %left Op OPERATOR /* multi-character ops and user-defined operators */
886 : %left '+' '-'
887 : %left '*' '/' '%'
888 : %left '^'
889 : /* Unary Operators */
890 : %left AT /* sets precedence for AT TIME ZONE, AT LOCAL */
891 : %left COLLATE
892 : %right UMINUS
893 : %left '[' ']'
894 : %left '(' ')'
895 : %left TYPECAST
896 : %left '.'
897 : /*
898 : * These might seem to be low-precedence, but actually they are not part
899 : * of the arithmetic hierarchy at all in their use as JOIN operators.
900 : * We make them high-precedence to support their use as function names.
901 : * They wouldn't be given a precedence at all, were it not that we need
902 : * left-associativity among the JOIN rules themselves.
903 : */
904 : %left JOIN CROSS LEFT FULL RIGHT INNER_P NATURAL
905 :
906 : %%
907 :
908 : /*
909 : * The target production for the whole parse.
910 : *
911 : * Ordinarily we parse a list of statements, but if we see one of the
912 : * special MODE_XXX symbols as first token, we parse something else.
913 : * The options here correspond to enum RawParseMode, which see for details.
914 : */
915 : parse_toplevel:
916 : stmtmulti
917 : {
918 714850 : pg_yyget_extra(yyscanner)->parsetree = $1;
919 : (void) yynerrs; /* suppress compiler warning */
920 : }
921 : | MODE_TYPE_NAME Typename
922 : {
923 9668 : pg_yyget_extra(yyscanner)->parsetree = list_make1($2);
924 : }
925 : | MODE_PLPGSQL_EXPR PLpgSQL_Expr
926 : {
927 33298 : pg_yyget_extra(yyscanner)->parsetree =
928 33298 : list_make1(makeRawStmt($2, @2));
929 : }
930 : | MODE_PLPGSQL_ASSIGN1 PLAssignStmt
931 : {
932 6342 : PLAssignStmt *n = (PLAssignStmt *) $2;
933 :
934 6342 : n->nnames = 1;
935 6342 : pg_yyget_extra(yyscanner)->parsetree =
936 6342 : list_make1(makeRawStmt((Node *) n, @2));
937 : }
938 : | MODE_PLPGSQL_ASSIGN2 PLAssignStmt
939 : {
940 674 : PLAssignStmt *n = (PLAssignStmt *) $2;
941 :
942 674 : n->nnames = 2;
943 674 : pg_yyget_extra(yyscanner)->parsetree =
944 674 : list_make1(makeRawStmt((Node *) n, @2));
945 : }
946 : | MODE_PLPGSQL_ASSIGN3 PLAssignStmt
947 : {
948 28 : PLAssignStmt *n = (PLAssignStmt *) $2;
949 :
950 28 : n->nnames = 3;
951 28 : pg_yyget_extra(yyscanner)->parsetree =
952 28 : list_make1(makeRawStmt((Node *) n, @2));
953 : }
954 : ;
955 :
956 : /*
957 : * At top level, we wrap each stmt with a RawStmt node carrying start location
958 : * and length of the stmt's text.
959 : * We also take care to discard empty statements entirely (which among other
960 : * things dodges the problem of assigning them a location).
961 : */
962 : stmtmulti: stmtmulti ';' toplevel_stmt
963 : {
964 583000 : if ($1 != NIL)
965 : {
966 : /* update length of previous stmt */
967 582434 : updateRawStmtEnd(llast_node(RawStmt, $1), @2);
968 : }
969 583000 : if ($3 != NULL)
970 59116 : $$ = lappend($1, makeRawStmt($3, @3));
971 : else
972 523884 : $$ = $1;
973 : }
974 : | toplevel_stmt
975 : {
976 714858 : if ($1 != NULL)
977 713538 : $$ = list_make1(makeRawStmt($1, @1));
978 : else
979 1320 : $$ = NIL;
980 : }
981 : ;
982 :
983 : /*
984 : * toplevel_stmt includes BEGIN and END. stmt does not include them, because
985 : * those words have different meanings in function bodies.
986 : */
987 : toplevel_stmt:
988 : stmt
989 : | TransactionStmtLegacy
990 : ;
991 :
992 : stmt:
993 : AlterEventTrigStmt
994 : | AlterCollationStmt
995 : | AlterDatabaseStmt
996 : | AlterDatabaseSetStmt
997 : | AlterDefaultPrivilegesStmt
998 : | AlterDomainStmt
999 : | AlterEnumStmt
1000 : | AlterExtensionStmt
1001 : | AlterExtensionContentsStmt
1002 : | AlterFdwStmt
1003 : | AlterForeignServerStmt
1004 : | AlterFunctionStmt
1005 : | AlterGroupStmt
1006 : | AlterObjectDependsStmt
1007 : | AlterObjectSchemaStmt
1008 : | AlterOwnerStmt
1009 : | AlterOperatorStmt
1010 : | AlterTypeStmt
1011 : | AlterPolicyStmt
1012 : | AlterSeqStmt
1013 : | AlterSystemStmt
1014 : | AlterTableStmt
1015 : | AlterTblSpcStmt
1016 : | AlterCompositeTypeStmt
1017 : | AlterPublicationStmt
1018 : | AlterRoleSetStmt
1019 : | AlterRoleStmt
1020 : | AlterSubscriptionStmt
1021 : | AlterStatsStmt
1022 : | AlterTSConfigurationStmt
1023 : | AlterTSDictionaryStmt
1024 : | AlterUserMappingStmt
1025 : | AnalyzeStmt
1026 : | CallStmt
1027 : | CheckPointStmt
1028 : | ClosePortalStmt
1029 : | ClusterStmt
1030 : | CommentStmt
1031 : | ConstraintsSetStmt
1032 : | CopyStmt
1033 : | CreateAmStmt
1034 : | CreateAsStmt
1035 : | CreateAssertionStmt
1036 : | CreateCastStmt
1037 : | CreateConversionStmt
1038 : | CreateDomainStmt
1039 : | CreateExtensionStmt
1040 : | CreateFdwStmt
1041 : | CreateForeignServerStmt
1042 : | CreateForeignTableStmt
1043 : | CreateFunctionStmt
1044 : | CreateGroupStmt
1045 : | CreateMatViewStmt
1046 : | CreateOpClassStmt
1047 : | CreateOpFamilyStmt
1048 : | CreatePublicationStmt
1049 : | AlterOpFamilyStmt
1050 : | CreatePolicyStmt
1051 : | CreatePLangStmt
1052 : | CreateSchemaStmt
1053 : | CreateSeqStmt
1054 : | CreateStmt
1055 : | CreateSubscriptionStmt
1056 : | CreateStatsStmt
1057 : | CreateTableSpaceStmt
1058 : | CreateTransformStmt
1059 : | CreateTrigStmt
1060 : | CreateEventTrigStmt
1061 : | CreateRoleStmt
1062 : | CreateUserStmt
1063 : | CreateUserMappingStmt
1064 : | CreatedbStmt
1065 : | DeallocateStmt
1066 : | DeclareCursorStmt
1067 : | DefineStmt
1068 : | DeleteStmt
1069 : | DiscardStmt
1070 : | DoStmt
1071 : | DropCastStmt
1072 : | DropOpClassStmt
1073 : | DropOpFamilyStmt
1074 : | DropOwnedStmt
1075 : | DropStmt
1076 : | DropSubscriptionStmt
1077 : | DropTableSpaceStmt
1078 : | DropTransformStmt
1079 : | DropRoleStmt
1080 : | DropUserMappingStmt
1081 : | DropdbStmt
1082 : | ExecuteStmt
1083 : | ExplainStmt
1084 : | FetchStmt
1085 : | GrantStmt
1086 : | GrantRoleStmt
1087 : | ImportForeignSchemaStmt
1088 : | IndexStmt
1089 : | InsertStmt
1090 : | ListenStmt
1091 : | RefreshMatViewStmt
1092 : | LoadStmt
1093 : | LockStmt
1094 : | MergeStmt
1095 : | NotifyStmt
1096 : | PrepareStmt
1097 : | ReassignOwnedStmt
1098 : | ReindexStmt
1099 : | RemoveAggrStmt
1100 : | RemoveFuncStmt
1101 : | RemoveOperStmt
1102 : | RenameStmt
1103 : | RevokeStmt
1104 : | RevokeRoleStmt
1105 : | RuleStmt
1106 : | SecLabelStmt
1107 : | SelectStmt
1108 : | TransactionStmt
1109 : | TruncateStmt
1110 : | UnlistenStmt
1111 : | UpdateStmt
1112 : | VacuumStmt
1113 : | VariableResetStmt
1114 : | VariableSetStmt
1115 : | VariableShowStmt
1116 : | ViewStmt
1117 : | /*EMPTY*/
1118 525220 : { $$ = NULL; }
1119 : ;
1120 :
1121 : /*
1122 : * Generic supporting productions for DDL
1123 : */
1124 : opt_single_name:
1125 5370 : ColId { $$ = $1; }
1126 1564 : | /* EMPTY */ { $$ = NULL; }
1127 : ;
1128 :
1129 : opt_qualified_name:
1130 1888 : any_name { $$ = $1; }
1131 15274 : | /*EMPTY*/ { $$ = NIL; }
1132 : ;
1133 :
1134 : opt_concurrently:
1135 1052 : CONCURRENTLY { $$ = true; }
1136 7638 : | /*EMPTY*/ { $$ = false; }
1137 : ;
1138 :
1139 : opt_drop_behavior:
1140 1974 : CASCADE { $$ = DROP_CASCADE; }
1141 170 : | RESTRICT { $$ = DROP_RESTRICT; }
1142 39208 : | /* EMPTY */ { $$ = DROP_RESTRICT; /* default */ }
1143 : ;
1144 :
1145 : opt_utility_option_list:
1146 366 : '(' utility_option_list ')' { $$ = $2; }
1147 5878 : | /* EMPTY */ { $$ = NULL; }
1148 : ;
1149 :
1150 : utility_option_list:
1151 : utility_option_elem
1152 : {
1153 22140 : $$ = list_make1($1);
1154 : }
1155 : | utility_option_list ',' utility_option_elem
1156 : {
1157 12600 : $$ = lappend($1, $3);
1158 : }
1159 : ;
1160 :
1161 : utility_option_elem:
1162 : utility_option_name utility_option_arg
1163 : {
1164 34740 : $$ = makeDefElem($1, $2, @1);
1165 : }
1166 : ;
1167 :
1168 : utility_option_name:
1169 30946 : NonReservedWord { $$ = $1; }
1170 3652 : | analyze_keyword { $$ = "analyze"; }
1171 148 : | FORMAT_LA { $$ = "format"; }
1172 : ;
1173 :
1174 : utility_option_arg:
1175 17794 : opt_boolean_or_string { $$ = (Node *) makeString($1); }
1176 382 : | NumericOnly { $$ = (Node *) $1; }
1177 16564 : | /* EMPTY */ { $$ = NULL; }
1178 : ;
1179 :
1180 : /*****************************************************************************
1181 : *
1182 : * CALL statement
1183 : *
1184 : *****************************************************************************/
1185 :
1186 : CallStmt: CALL func_application
1187 : {
1188 628 : CallStmt *n = makeNode(CallStmt);
1189 :
1190 628 : n->funccall = castNode(FuncCall, $2);
1191 628 : $$ = (Node *) n;
1192 : }
1193 : ;
1194 :
1195 : /*****************************************************************************
1196 : *
1197 : * Create a new Postgres DBMS role
1198 : *
1199 : *****************************************************************************/
1200 :
1201 : CreateRoleStmt:
1202 : CREATE ROLE RoleId opt_with OptRoleList
1203 : {
1204 1384 : CreateRoleStmt *n = makeNode(CreateRoleStmt);
1205 :
1206 1384 : n->stmt_type = ROLESTMT_ROLE;
1207 1384 : n->role = $3;
1208 1384 : n->options = $5;
1209 1384 : $$ = (Node *) n;
1210 : }
1211 : ;
1212 :
1213 :
1214 : opt_with: WITH
1215 : | WITH_LA
1216 : | /*EMPTY*/
1217 : ;
1218 :
1219 : /*
1220 : * Options for CREATE ROLE and ALTER ROLE (also used by CREATE/ALTER USER
1221 : * for backwards compatibility). Note: the only option required by SQL99
1222 : * is "WITH ADMIN name".
1223 : */
1224 : OptRoleList:
1225 1160 : OptRoleList CreateOptRoleElem { $$ = lappend($1, $2); }
1226 1864 : | /* EMPTY */ { $$ = NIL; }
1227 : ;
1228 :
1229 : AlterOptRoleList:
1230 770 : AlterOptRoleList AlterOptRoleElem { $$ = lappend($1, $2); }
1231 434 : | /* EMPTY */ { $$ = NIL; }
1232 : ;
1233 :
1234 : AlterOptRoleElem:
1235 : PASSWORD Sconst
1236 : {
1237 188 : $$ = makeDefElem("password",
1238 188 : (Node *) makeString($2), @1);
1239 : }
1240 : | PASSWORD NULL_P
1241 : {
1242 12 : $$ = makeDefElem("password", NULL, @1);
1243 : }
1244 : | ENCRYPTED PASSWORD Sconst
1245 : {
1246 : /*
1247 : * These days, passwords are always stored in encrypted
1248 : * form, so there is no difference between PASSWORD and
1249 : * ENCRYPTED PASSWORD.
1250 : */
1251 16 : $$ = makeDefElem("password",
1252 16 : (Node *) makeString($3), @1);
1253 : }
1254 : | UNENCRYPTED PASSWORD Sconst
1255 : {
1256 0 : ereport(ERROR,
1257 : (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
1258 : errmsg("UNENCRYPTED PASSWORD is no longer supported"),
1259 : errhint("Remove UNENCRYPTED to store the password in encrypted form instead."),
1260 : parser_errposition(@1)));
1261 : }
1262 : | INHERIT
1263 : {
1264 108 : $$ = makeDefElem("inherit", (Node *) makeBoolean(true), @1);
1265 : }
1266 : | CONNECTION LIMIT SignedIconst
1267 : {
1268 24 : $$ = makeDefElem("connectionlimit", (Node *) makeInteger($3), @1);
1269 : }
1270 : | VALID UNTIL Sconst
1271 : {
1272 2 : $$ = makeDefElem("validUntil", (Node *) makeString($3), @1);
1273 : }
1274 : /* Supported but not documented for roles, for use by ALTER GROUP. */
1275 : | USER role_list
1276 : {
1277 6 : $$ = makeDefElem("rolemembers", (Node *) $2, @1);
1278 : }
1279 : | IDENT
1280 : {
1281 : /*
1282 : * We handle identifiers that aren't parser keywords with
1283 : * the following special-case codes, to avoid bloating the
1284 : * size of the main parser.
1285 : */
1286 1426 : if (strcmp($1, "superuser") == 0)
1287 192 : $$ = makeDefElem("superuser", (Node *) makeBoolean(true), @1);
1288 1234 : else if (strcmp($1, "nosuperuser") == 0)
1289 112 : $$ = makeDefElem("superuser", (Node *) makeBoolean(false), @1);
1290 1122 : else if (strcmp($1, "createrole") == 0)
1291 102 : $$ = makeDefElem("createrole", (Node *) makeBoolean(true), @1);
1292 1020 : else if (strcmp($1, "nocreaterole") == 0)
1293 50 : $$ = makeDefElem("createrole", (Node *) makeBoolean(false), @1);
1294 970 : else if (strcmp($1, "replication") == 0)
1295 130 : $$ = makeDefElem("isreplication", (Node *) makeBoolean(true), @1);
1296 840 : else if (strcmp($1, "noreplication") == 0)
1297 108 : $$ = makeDefElem("isreplication", (Node *) makeBoolean(false), @1);
1298 732 : else if (strcmp($1, "createdb") == 0)
1299 92 : $$ = makeDefElem("createdb", (Node *) makeBoolean(true), @1);
1300 640 : else if (strcmp($1, "nocreatedb") == 0)
1301 58 : $$ = makeDefElem("createdb", (Node *) makeBoolean(false), @1);
1302 582 : else if (strcmp($1, "login") == 0)
1303 282 : $$ = makeDefElem("canlogin", (Node *) makeBoolean(true), @1);
1304 300 : else if (strcmp($1, "nologin") == 0)
1305 102 : $$ = makeDefElem("canlogin", (Node *) makeBoolean(false), @1);
1306 198 : else if (strcmp($1, "bypassrls") == 0)
1307 82 : $$ = makeDefElem("bypassrls", (Node *) makeBoolean(true), @1);
1308 116 : else if (strcmp($1, "nobypassrls") == 0)
1309 80 : $$ = makeDefElem("bypassrls", (Node *) makeBoolean(false), @1);
1310 36 : else if (strcmp($1, "noinherit") == 0)
1311 : {
1312 : /*
1313 : * Note that INHERIT is a keyword, so it's handled by main parser, but
1314 : * NOINHERIT is handled here.
1315 : */
1316 36 : $$ = makeDefElem("inherit", (Node *) makeBoolean(false), @1);
1317 : }
1318 : else
1319 0 : ereport(ERROR,
1320 : (errcode(ERRCODE_SYNTAX_ERROR),
1321 : errmsg("unrecognized role option \"%s\"", $1),
1322 : parser_errposition(@1)));
1323 : }
1324 : ;
1325 :
1326 : CreateOptRoleElem:
1327 1012 : AlterOptRoleElem { $$ = $1; }
1328 : /* The following are not supported by ALTER ROLE/USER/GROUP */
1329 : | SYSID Iconst
1330 : {
1331 6 : $$ = makeDefElem("sysid", (Node *) makeInteger($2), @1);
1332 : }
1333 : | ADMIN role_list
1334 : {
1335 22 : $$ = makeDefElem("adminmembers", (Node *) $2, @1);
1336 : }
1337 : | ROLE role_list
1338 : {
1339 22 : $$ = makeDefElem("rolemembers", (Node *) $2, @1);
1340 : }
1341 : | IN_P ROLE role_list
1342 : {
1343 98 : $$ = makeDefElem("addroleto", (Node *) $3, @1);
1344 : }
1345 : | IN_P GROUP_P role_list
1346 : {
1347 0 : $$ = makeDefElem("addroleto", (Node *) $3, @1);
1348 : }
1349 : ;
1350 :
1351 :
1352 : /*****************************************************************************
1353 : *
1354 : * Create a new Postgres DBMS user (role with implied login ability)
1355 : *
1356 : *****************************************************************************/
1357 :
1358 : CreateUserStmt:
1359 : CREATE USER RoleId opt_with OptRoleList
1360 : {
1361 456 : CreateRoleStmt *n = makeNode(CreateRoleStmt);
1362 :
1363 456 : n->stmt_type = ROLESTMT_USER;
1364 456 : n->role = $3;
1365 456 : n->options = $5;
1366 456 : $$ = (Node *) n;
1367 : }
1368 : ;
1369 :
1370 :
1371 : /*****************************************************************************
1372 : *
1373 : * Alter a postgresql DBMS role
1374 : *
1375 : *****************************************************************************/
1376 :
1377 : AlterRoleStmt:
1378 : ALTER ROLE RoleSpec opt_with AlterOptRoleList
1379 : {
1380 342 : AlterRoleStmt *n = makeNode(AlterRoleStmt);
1381 :
1382 342 : n->role = $3;
1383 342 : n->action = +1; /* add, if there are members */
1384 342 : n->options = $5;
1385 342 : $$ = (Node *) n;
1386 : }
1387 : | ALTER USER RoleSpec opt_with AlterOptRoleList
1388 : {
1389 92 : AlterRoleStmt *n = makeNode(AlterRoleStmt);
1390 :
1391 92 : n->role = $3;
1392 92 : n->action = +1; /* add, if there are members */
1393 92 : n->options = $5;
1394 92 : $$ = (Node *) n;
1395 : }
1396 : ;
1397 :
1398 : opt_in_database:
1399 94 : /* EMPTY */ { $$ = NULL; }
1400 4 : | IN_P DATABASE name { $$ = $3; }
1401 : ;
1402 :
1403 : AlterRoleSetStmt:
1404 : ALTER ROLE RoleSpec opt_in_database SetResetClause
1405 : {
1406 58 : AlterRoleSetStmt *n = makeNode(AlterRoleSetStmt);
1407 :
1408 58 : n->role = $3;
1409 58 : n->database = $4;
1410 58 : n->setstmt = $5;
1411 58 : $$ = (Node *) n;
1412 : }
1413 : | ALTER ROLE ALL opt_in_database SetResetClause
1414 : {
1415 4 : AlterRoleSetStmt *n = makeNode(AlterRoleSetStmt);
1416 :
1417 4 : n->role = NULL;
1418 4 : n->database = $4;
1419 4 : n->setstmt = $5;
1420 4 : $$ = (Node *) n;
1421 : }
1422 : | ALTER USER RoleSpec opt_in_database SetResetClause
1423 : {
1424 28 : AlterRoleSetStmt *n = makeNode(AlterRoleSetStmt);
1425 :
1426 28 : n->role = $3;
1427 28 : n->database = $4;
1428 28 : n->setstmt = $5;
1429 28 : $$ = (Node *) n;
1430 : }
1431 : | ALTER USER ALL opt_in_database SetResetClause
1432 : {
1433 4 : AlterRoleSetStmt *n = makeNode(AlterRoleSetStmt);
1434 :
1435 4 : n->role = NULL;
1436 4 : n->database = $4;
1437 4 : n->setstmt = $5;
1438 4 : $$ = (Node *) n;
1439 : }
1440 : ;
1441 :
1442 :
1443 : /*****************************************************************************
1444 : *
1445 : * Drop a postgresql DBMS role
1446 : *
1447 : * XXX Ideally this would have CASCADE/RESTRICT options, but a role
1448 : * might own objects in multiple databases, and there is presently no way to
1449 : * implement cascading to other databases. So we always behave as RESTRICT.
1450 : *****************************************************************************/
1451 :
1452 : DropRoleStmt:
1453 : DROP ROLE role_list
1454 : {
1455 1106 : DropRoleStmt *n = makeNode(DropRoleStmt);
1456 :
1457 1106 : n->missing_ok = false;
1458 1106 : n->roles = $3;
1459 1106 : $$ = (Node *) n;
1460 : }
1461 : | DROP ROLE IF_P EXISTS role_list
1462 : {
1463 134 : DropRoleStmt *n = makeNode(DropRoleStmt);
1464 :
1465 134 : n->missing_ok = true;
1466 134 : n->roles = $5;
1467 134 : $$ = (Node *) n;
1468 : }
1469 : | DROP USER role_list
1470 : {
1471 404 : DropRoleStmt *n = makeNode(DropRoleStmt);
1472 :
1473 404 : n->missing_ok = false;
1474 404 : n->roles = $3;
1475 404 : $$ = (Node *) n;
1476 : }
1477 : | DROP USER IF_P EXISTS role_list
1478 : {
1479 36 : DropRoleStmt *n = makeNode(DropRoleStmt);
1480 :
1481 36 : n->roles = $5;
1482 36 : n->missing_ok = true;
1483 36 : $$ = (Node *) n;
1484 : }
1485 : | DROP GROUP_P role_list
1486 : {
1487 36 : DropRoleStmt *n = makeNode(DropRoleStmt);
1488 :
1489 36 : n->missing_ok = false;
1490 36 : n->roles = $3;
1491 36 : $$ = (Node *) n;
1492 : }
1493 : | DROP GROUP_P IF_P EXISTS role_list
1494 : {
1495 6 : DropRoleStmt *n = makeNode(DropRoleStmt);
1496 :
1497 6 : n->missing_ok = true;
1498 6 : n->roles = $5;
1499 6 : $$ = (Node *) n;
1500 : }
1501 : ;
1502 :
1503 :
1504 : /*****************************************************************************
1505 : *
1506 : * Create a postgresql group (role without login ability)
1507 : *
1508 : *****************************************************************************/
1509 :
1510 : CreateGroupStmt:
1511 : CREATE GROUP_P RoleId opt_with OptRoleList
1512 : {
1513 24 : CreateRoleStmt *n = makeNode(CreateRoleStmt);
1514 :
1515 24 : n->stmt_type = ROLESTMT_GROUP;
1516 24 : n->role = $3;
1517 24 : n->options = $5;
1518 24 : $$ = (Node *) n;
1519 : }
1520 : ;
1521 :
1522 :
1523 : /*****************************************************************************
1524 : *
1525 : * Alter a postgresql group
1526 : *
1527 : *****************************************************************************/
1528 :
1529 : AlterGroupStmt:
1530 : ALTER GROUP_P RoleSpec add_drop USER role_list
1531 : {
1532 42 : AlterRoleStmt *n = makeNode(AlterRoleStmt);
1533 :
1534 42 : n->role = $3;
1535 42 : n->action = $4;
1536 42 : n->options = list_make1(makeDefElem("rolemembers",
1537 : (Node *) $6, @6));
1538 42 : $$ = (Node *) n;
1539 : }
1540 : ;
1541 :
1542 94 : add_drop: ADD_P { $$ = +1; }
1543 222 : | DROP { $$ = -1; }
1544 : ;
1545 :
1546 :
1547 : /*****************************************************************************
1548 : *
1549 : * Manipulate a schema
1550 : *
1551 : *****************************************************************************/
1552 :
1553 : CreateSchemaStmt:
1554 : CREATE SCHEMA opt_single_name AUTHORIZATION RoleSpec OptSchemaEltList
1555 : {
1556 158 : CreateSchemaStmt *n = makeNode(CreateSchemaStmt);
1557 :
1558 : /* One can omit the schema name or the authorization id. */
1559 158 : n->schemaname = $3;
1560 158 : n->authrole = $5;
1561 158 : n->schemaElts = $6;
1562 158 : n->if_not_exists = false;
1563 158 : $$ = (Node *) n;
1564 : }
1565 : | CREATE SCHEMA ColId OptSchemaEltList
1566 : {
1567 874 : CreateSchemaStmt *n = makeNode(CreateSchemaStmt);
1568 :
1569 : /* ...but not both */
1570 874 : n->schemaname = $3;
1571 874 : n->authrole = NULL;
1572 874 : n->schemaElts = $4;
1573 874 : n->if_not_exists = false;
1574 874 : $$ = (Node *) n;
1575 : }
1576 : | CREATE SCHEMA IF_P NOT EXISTS opt_single_name AUTHORIZATION RoleSpec OptSchemaEltList
1577 : {
1578 18 : CreateSchemaStmt *n = makeNode(CreateSchemaStmt);
1579 :
1580 : /* schema name can be omitted here, too */
1581 18 : n->schemaname = $6;
1582 18 : n->authrole = $8;
1583 18 : if ($9 != NIL)
1584 0 : ereport(ERROR,
1585 : (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
1586 : errmsg("CREATE SCHEMA IF NOT EXISTS cannot include schema elements"),
1587 : parser_errposition(@9)));
1588 18 : n->schemaElts = $9;
1589 18 : n->if_not_exists = true;
1590 18 : $$ = (Node *) n;
1591 : }
1592 : | CREATE SCHEMA IF_P NOT EXISTS ColId OptSchemaEltList
1593 : {
1594 34 : CreateSchemaStmt *n = makeNode(CreateSchemaStmt);
1595 :
1596 : /* ...but not here */
1597 34 : n->schemaname = $6;
1598 34 : n->authrole = NULL;
1599 34 : if ($7 != NIL)
1600 6 : ereport(ERROR,
1601 : (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
1602 : errmsg("CREATE SCHEMA IF NOT EXISTS cannot include schema elements"),
1603 : parser_errposition(@7)));
1604 28 : n->schemaElts = $7;
1605 28 : n->if_not_exists = true;
1606 28 : $$ = (Node *) n;
1607 : }
1608 : ;
1609 :
1610 : OptSchemaEltList:
1611 : OptSchemaEltList schema_stmt
1612 : {
1613 564 : $$ = lappend($1, $2);
1614 : }
1615 : | /* EMPTY */
1616 1084 : { $$ = NIL; }
1617 : ;
1618 :
1619 : /*
1620 : * schema_stmt are the ones that can show up inside a CREATE SCHEMA
1621 : * statement (in addition to by themselves).
1622 : */
1623 : schema_stmt:
1624 : CreateStmt
1625 : | IndexStmt
1626 : | CreateSeqStmt
1627 : | CreateTrigStmt
1628 : | GrantStmt
1629 : | ViewStmt
1630 : ;
1631 :
1632 :
1633 : /*****************************************************************************
1634 : *
1635 : * Set PG internal variable
1636 : * SET name TO 'var_value'
1637 : * Include SQL syntax (thomas 1997-10-22):
1638 : * SET TIME ZONE 'var_value'
1639 : *
1640 : *****************************************************************************/
1641 :
1642 : VariableSetStmt:
1643 : SET set_rest
1644 : {
1645 21618 : VariableSetStmt *n = $2;
1646 :
1647 21618 : n->is_local = false;
1648 21618 : $$ = (Node *) n;
1649 : }
1650 : | SET LOCAL set_rest
1651 : {
1652 1236 : VariableSetStmt *n = $3;
1653 :
1654 1236 : n->is_local = true;
1655 1236 : $$ = (Node *) n;
1656 : }
1657 : | SET SESSION set_rest
1658 : {
1659 84 : VariableSetStmt *n = $3;
1660 :
1661 84 : n->is_local = false;
1662 84 : $$ = (Node *) n;
1663 : }
1664 : ;
1665 :
1666 : set_rest:
1667 : TRANSACTION transaction_mode_list
1668 : {
1669 580 : VariableSetStmt *n = makeNode(VariableSetStmt);
1670 :
1671 580 : n->kind = VAR_SET_MULTI;
1672 580 : n->name = "TRANSACTION";
1673 580 : n->args = $2;
1674 580 : n->jumble_args = true;
1675 580 : n->location = -1;
1676 580 : $$ = n;
1677 : }
1678 : | SESSION CHARACTERISTICS AS TRANSACTION transaction_mode_list
1679 : {
1680 18 : VariableSetStmt *n = makeNode(VariableSetStmt);
1681 :
1682 18 : n->kind = VAR_SET_MULTI;
1683 18 : n->name = "SESSION CHARACTERISTICS";
1684 18 : n->args = $5;
1685 18 : n->jumble_args = true;
1686 18 : n->location = -1;
1687 18 : $$ = n;
1688 : }
1689 : | set_rest_more
1690 : ;
1691 :
1692 : generic_set:
1693 : var_name TO var_list
1694 : {
1695 5130 : VariableSetStmt *n = makeNode(VariableSetStmt);
1696 :
1697 5130 : n->kind = VAR_SET_VALUE;
1698 5130 : n->name = $1;
1699 5130 : n->args = $3;
1700 5130 : n->location = @3;
1701 5130 : $$ = n;
1702 : }
1703 : | var_name '=' var_list
1704 : {
1705 14890 : VariableSetStmt *n = makeNode(VariableSetStmt);
1706 :
1707 14890 : n->kind = VAR_SET_VALUE;
1708 14890 : n->name = $1;
1709 14890 : n->args = $3;
1710 14890 : n->location = @3;
1711 14890 : $$ = n;
1712 : }
1713 : | var_name TO DEFAULT
1714 : {
1715 136 : VariableSetStmt *n = makeNode(VariableSetStmt);
1716 :
1717 136 : n->kind = VAR_SET_DEFAULT;
1718 136 : n->name = $1;
1719 136 : n->location = -1;
1720 136 : $$ = n;
1721 : }
1722 : | var_name '=' DEFAULT
1723 : {
1724 10 : VariableSetStmt *n = makeNode(VariableSetStmt);
1725 :
1726 10 : n->kind = VAR_SET_DEFAULT;
1727 10 : n->name = $1;
1728 10 : n->location = -1;
1729 10 : $$ = n;
1730 : }
1731 : ;
1732 :
1733 : set_rest_more: /* Generic SET syntaxes: */
1734 20034 : generic_set {$$ = $1;}
1735 : | var_name FROM CURRENT_P
1736 : {
1737 4 : VariableSetStmt *n = makeNode(VariableSetStmt);
1738 :
1739 4 : n->kind = VAR_SET_CURRENT;
1740 4 : n->name = $1;
1741 4 : n->location = -1;
1742 4 : $$ = n;
1743 : }
1744 : /* Special syntaxes mandated by SQL standard: */
1745 : | TIME ZONE zone_value
1746 : {
1747 104 : VariableSetStmt *n = makeNode(VariableSetStmt);
1748 :
1749 104 : n->kind = VAR_SET_VALUE;
1750 104 : n->name = "timezone";
1751 104 : n->location = -1;
1752 104 : n->jumble_args = true;
1753 104 : if ($3 != NULL)
1754 88 : n->args = list_make1($3);
1755 : else
1756 16 : n->kind = VAR_SET_DEFAULT;
1757 104 : $$ = n;
1758 : }
1759 : | CATALOG_P Sconst
1760 : {
1761 0 : ereport(ERROR,
1762 : (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
1763 : errmsg("current database cannot be changed"),
1764 : parser_errposition(@2)));
1765 : $$ = NULL; /*not reached*/
1766 : }
1767 : | SCHEMA Sconst
1768 : {
1769 4 : VariableSetStmt *n = makeNode(VariableSetStmt);
1770 :
1771 4 : n->kind = VAR_SET_VALUE;
1772 4 : n->name = "search_path";
1773 4 : n->args = list_make1(makeStringConst($2, @2));
1774 4 : n->location = @2;
1775 4 : $$ = n;
1776 : }
1777 : | NAMES opt_encoding
1778 : {
1779 0 : VariableSetStmt *n = makeNode(VariableSetStmt);
1780 :
1781 0 : n->kind = VAR_SET_VALUE;
1782 0 : n->name = "client_encoding";
1783 0 : n->location = @2;
1784 0 : if ($2 != NULL)
1785 0 : n->args = list_make1(makeStringConst($2, @2));
1786 : else
1787 0 : n->kind = VAR_SET_DEFAULT;
1788 0 : $$ = n;
1789 : }
1790 : | ROLE NonReservedWord_or_Sconst
1791 : {
1792 960 : VariableSetStmt *n = makeNode(VariableSetStmt);
1793 :
1794 960 : n->kind = VAR_SET_VALUE;
1795 960 : n->name = "role";
1796 960 : n->args = list_make1(makeStringConst($2, @2));
1797 960 : n->location = @2;
1798 960 : $$ = n;
1799 : }
1800 : | SESSION AUTHORIZATION NonReservedWord_or_Sconst
1801 : {
1802 2586 : VariableSetStmt *n = makeNode(VariableSetStmt);
1803 :
1804 2586 : n->kind = VAR_SET_VALUE;
1805 2586 : n->name = "session_authorization";
1806 2586 : n->args = list_make1(makeStringConst($3, @3));
1807 2586 : n->location = @3;
1808 2586 : $$ = n;
1809 : }
1810 : | SESSION AUTHORIZATION DEFAULT
1811 : {
1812 4 : VariableSetStmt *n = makeNode(VariableSetStmt);
1813 :
1814 4 : n->kind = VAR_SET_DEFAULT;
1815 4 : n->name = "session_authorization";
1816 4 : n->location = -1;
1817 4 : $$ = n;
1818 : }
1819 : | XML_P OPTION document_or_content
1820 : {
1821 16 : VariableSetStmt *n = makeNode(VariableSetStmt);
1822 :
1823 16 : n->kind = VAR_SET_VALUE;
1824 16 : n->name = "xmloption";
1825 16 : n->args = list_make1(makeStringConst($3 == XMLOPTION_DOCUMENT ? "DOCUMENT" : "CONTENT", @3));
1826 16 : n->jumble_args = true;
1827 16 : n->location = -1;
1828 16 : $$ = n;
1829 : }
1830 : /* Special syntaxes invented by PostgreSQL: */
1831 : | TRANSACTION SNAPSHOT Sconst
1832 : {
1833 44 : VariableSetStmt *n = makeNode(VariableSetStmt);
1834 :
1835 44 : n->kind = VAR_SET_MULTI;
1836 44 : n->name = "TRANSACTION SNAPSHOT";
1837 44 : n->args = list_make1(makeStringConst($3, @3));
1838 44 : n->location = @3;
1839 44 : $$ = n;
1840 : }
1841 : ;
1842 :
1843 24886 : var_name: ColId { $$ = $1; }
1844 : | var_name '.' ColId
1845 496 : { $$ = psprintf("%s.%s", $1, $3); }
1846 : ;
1847 :
1848 20020 : var_list: var_value { $$ = list_make1($1); }
1849 182 : | var_list ',' var_value { $$ = lappend($1, $3); }
1850 : ;
1851 :
1852 : var_value: opt_boolean_or_string
1853 14942 : { $$ = makeStringConst($1, @1); }
1854 : | NumericOnly
1855 5260 : { $$ = makeAConst($1, @1); }
1856 : ;
1857 :
1858 0 : iso_level: READ UNCOMMITTED { $$ = "read uncommitted"; }
1859 994 : | READ COMMITTED { $$ = "read committed"; }
1860 2638 : | REPEATABLE READ { $$ = "repeatable read"; }
1861 3228 : | SERIALIZABLE { $$ = "serializable"; }
1862 : ;
1863 :
1864 : opt_boolean_or_string:
1865 690 : TRUE_P { $$ = "true"; }
1866 1486 : | FALSE_P { $$ = "false"; }
1867 2252 : | ON { $$ = "on"; }
1868 : /*
1869 : * OFF is also accepted as a boolean value, but is handled by
1870 : * the NonReservedWord rule. The action for booleans and strings
1871 : * is the same, so we don't need to distinguish them here.
1872 : */
1873 30670 : | NonReservedWord_or_Sconst { $$ = $1; }
1874 : ;
1875 :
1876 : /* Timezone values can be:
1877 : * - a string such as 'pst8pdt'
1878 : * - an identifier such as "pst8pdt"
1879 : * - an integer or floating point number
1880 : * - a time interval per SQL99
1881 : * ColId gives reduce/reduce errors against ConstInterval and LOCAL,
1882 : * so use IDENT (meaning we reject anything that is a key word).
1883 : */
1884 : zone_value:
1885 : Sconst
1886 : {
1887 60 : $$ = makeStringConst($1, @1);
1888 : }
1889 : | IDENT
1890 : {
1891 4 : $$ = makeStringConst($1, @1);
1892 : }
1893 : | ConstInterval Sconst opt_interval
1894 : {
1895 0 : TypeName *t = $1;
1896 :
1897 0 : if ($3 != NIL)
1898 : {
1899 0 : A_Const *n = (A_Const *) linitial($3);
1900 :
1901 0 : if ((n->val.ival.ival & ~(INTERVAL_MASK(HOUR) | INTERVAL_MASK(MINUTE))) != 0)
1902 0 : ereport(ERROR,
1903 : (errcode(ERRCODE_SYNTAX_ERROR),
1904 : errmsg("time zone interval must be HOUR or HOUR TO MINUTE"),
1905 : parser_errposition(@3)));
1906 : }
1907 0 : t->typmods = $3;
1908 0 : $$ = makeStringConstCast($2, @2, t);
1909 : }
1910 : | ConstInterval '(' Iconst ')' Sconst
1911 : {
1912 0 : TypeName *t = $1;
1913 :
1914 0 : t->typmods = list_make2(makeIntConst(INTERVAL_FULL_RANGE, -1),
1915 : makeIntConst($3, @3));
1916 0 : $$ = makeStringConstCast($5, @5, t);
1917 : }
1918 24 : | NumericOnly { $$ = makeAConst($1, @1); }
1919 14 : | DEFAULT { $$ = NULL; }
1920 2 : | LOCAL { $$ = NULL; }
1921 : ;
1922 :
1923 : opt_encoding:
1924 0 : Sconst { $$ = $1; }
1925 0 : | DEFAULT { $$ = NULL; }
1926 0 : | /*EMPTY*/ { $$ = NULL; }
1927 : ;
1928 :
1929 : NonReservedWord_or_Sconst:
1930 54530 : NonReservedWord { $$ = $1; }
1931 5598 : | Sconst { $$ = $1; }
1932 : ;
1933 :
1934 : VariableResetStmt:
1935 4628 : RESET reset_rest { $$ = (Node *) $2; }
1936 : ;
1937 :
1938 : reset_rest:
1939 3824 : generic_reset { $$ = $1; }
1940 : | TIME ZONE
1941 : {
1942 14 : VariableSetStmt *n = makeNode(VariableSetStmt);
1943 :
1944 14 : n->kind = VAR_RESET;
1945 14 : n->name = "timezone";
1946 14 : n->location = -1;
1947 14 : $$ = n;
1948 : }
1949 : | TRANSACTION ISOLATION LEVEL
1950 : {
1951 0 : VariableSetStmt *n = makeNode(VariableSetStmt);
1952 :
1953 0 : n->kind = VAR_RESET;
1954 0 : n->name = "transaction_isolation";
1955 0 : n->location = -1;
1956 0 : $$ = n;
1957 : }
1958 : | SESSION AUTHORIZATION
1959 : {
1960 790 : VariableSetStmt *n = makeNode(VariableSetStmt);
1961 :
1962 790 : n->kind = VAR_RESET;
1963 790 : n->name = "session_authorization";
1964 790 : n->location = -1;
1965 790 : $$ = n;
1966 : }
1967 : ;
1968 :
1969 : generic_reset:
1970 : var_name
1971 : {
1972 3852 : VariableSetStmt *n = makeNode(VariableSetStmt);
1973 :
1974 3852 : n->kind = VAR_RESET;
1975 3852 : n->name = $1;
1976 3852 : n->location = -1;
1977 3852 : $$ = n;
1978 : }
1979 : | ALL
1980 : {
1981 28 : VariableSetStmt *n = makeNode(VariableSetStmt);
1982 :
1983 28 : n->kind = VAR_RESET_ALL;
1984 28 : n->location = -1;
1985 28 : $$ = n;
1986 : }
1987 : ;
1988 :
1989 : /* SetResetClause allows SET or RESET without LOCAL */
1990 : SetResetClause:
1991 1282 : SET set_rest { $$ = $2; }
1992 42 : | VariableResetStmt { $$ = (VariableSetStmt *) $1; }
1993 : ;
1994 :
1995 : /* SetResetClause allows SET or RESET without LOCAL */
1996 : FunctionSetResetClause:
1997 134 : SET set_rest_more { $$ = $2; }
1998 12 : | VariableResetStmt { $$ = (VariableSetStmt *) $1; }
1999 : ;
2000 :
2001 :
2002 : VariableShowStmt:
2003 : SHOW var_name
2004 : {
2005 864 : VariableShowStmt *n = makeNode(VariableShowStmt);
2006 :
2007 864 : n->name = $2;
2008 864 : $$ = (Node *) n;
2009 : }
2010 : | SHOW TIME ZONE
2011 : {
2012 10 : VariableShowStmt *n = makeNode(VariableShowStmt);
2013 :
2014 10 : n->name = "timezone";
2015 10 : $$ = (Node *) n;
2016 : }
2017 : | SHOW TRANSACTION ISOLATION LEVEL
2018 : {
2019 4 : VariableShowStmt *n = makeNode(VariableShowStmt);
2020 :
2021 4 : n->name = "transaction_isolation";
2022 4 : $$ = (Node *) n;
2023 : }
2024 : | SHOW SESSION AUTHORIZATION
2025 : {
2026 0 : VariableShowStmt *n = makeNode(VariableShowStmt);
2027 :
2028 0 : n->name = "session_authorization";
2029 0 : $$ = (Node *) n;
2030 : }
2031 : | SHOW ALL
2032 : {
2033 0 : VariableShowStmt *n = makeNode(VariableShowStmt);
2034 :
2035 0 : n->name = "all";
2036 0 : $$ = (Node *) n;
2037 : }
2038 : ;
2039 :
2040 :
2041 : ConstraintsSetStmt:
2042 : SET CONSTRAINTS constraints_set_list constraints_set_mode
2043 : {
2044 104 : ConstraintsSetStmt *n = makeNode(ConstraintsSetStmt);
2045 :
2046 104 : n->constraints = $3;
2047 104 : n->deferred = $4;
2048 104 : $$ = (Node *) n;
2049 : }
2050 : ;
2051 :
2052 : constraints_set_list:
2053 56 : ALL { $$ = NIL; }
2054 48 : | qualified_name_list { $$ = $1; }
2055 : ;
2056 :
2057 : constraints_set_mode:
2058 68 : DEFERRED { $$ = true; }
2059 36 : | IMMEDIATE { $$ = false; }
2060 : ;
2061 :
2062 :
2063 : /*
2064 : * Checkpoint statement
2065 : */
2066 : CheckPointStmt:
2067 : CHECKPOINT opt_utility_option_list
2068 : {
2069 242 : CheckPointStmt *n = makeNode(CheckPointStmt);
2070 :
2071 242 : $$ = (Node *) n;
2072 242 : n->options = $2;
2073 : }
2074 : ;
2075 :
2076 :
2077 : /*****************************************************************************
2078 : *
2079 : * DISCARD { ALL | TEMP | PLANS | SEQUENCES }
2080 : *
2081 : *****************************************************************************/
2082 :
2083 : DiscardStmt:
2084 : DISCARD ALL
2085 : {
2086 6 : DiscardStmt *n = makeNode(DiscardStmt);
2087 :
2088 6 : n->target = DISCARD_ALL;
2089 6 : $$ = (Node *) n;
2090 : }
2091 : | DISCARD TEMP
2092 : {
2093 8 : DiscardStmt *n = makeNode(DiscardStmt);
2094 :
2095 8 : n->target = DISCARD_TEMP;
2096 8 : $$ = (Node *) n;
2097 : }
2098 : | DISCARD TEMPORARY
2099 : {
2100 0 : DiscardStmt *n = makeNode(DiscardStmt);
2101 :
2102 0 : n->target = DISCARD_TEMP;
2103 0 : $$ = (Node *) n;
2104 : }
2105 : | DISCARD PLANS
2106 : {
2107 4 : DiscardStmt *n = makeNode(DiscardStmt);
2108 :
2109 4 : n->target = DISCARD_PLANS;
2110 4 : $$ = (Node *) n;
2111 : }
2112 : | DISCARD SEQUENCES
2113 : {
2114 12 : DiscardStmt *n = makeNode(DiscardStmt);
2115 :
2116 12 : n->target = DISCARD_SEQUENCES;
2117 12 : $$ = (Node *) n;
2118 : }
2119 :
2120 : ;
2121 :
2122 :
2123 : /*****************************************************************************
2124 : *
2125 : * ALTER [ TABLE | INDEX | SEQUENCE | VIEW | MATERIALIZED VIEW | FOREIGN TABLE ] variations
2126 : *
2127 : * Note: we accept all subcommands for each of the variants, and sort
2128 : * out what's really legal at execution time.
2129 : *****************************************************************************/
2130 :
2131 : AlterTableStmt:
2132 : ALTER TABLE relation_expr alter_table_cmds
2133 : {
2134 26356 : AlterTableStmt *n = makeNode(AlterTableStmt);
2135 :
2136 26356 : n->relation = $3;
2137 26356 : n->cmds = $4;
2138 26356 : n->objtype = OBJECT_TABLE;
2139 26356 : n->missing_ok = false;
2140 26356 : $$ = (Node *) n;
2141 : }
2142 : | ALTER TABLE IF_P EXISTS relation_expr alter_table_cmds
2143 : {
2144 54 : AlterTableStmt *n = makeNode(AlterTableStmt);
2145 :
2146 54 : n->relation = $5;
2147 54 : n->cmds = $6;
2148 54 : n->objtype = OBJECT_TABLE;
2149 54 : n->missing_ok = true;
2150 54 : $$ = (Node *) n;
2151 : }
2152 : | ALTER TABLE relation_expr partition_cmd
2153 : {
2154 3052 : AlterTableStmt *n = makeNode(AlterTableStmt);
2155 :
2156 3052 : n->relation = $3;
2157 3052 : n->cmds = list_make1($4);
2158 3052 : n->objtype = OBJECT_TABLE;
2159 3052 : n->missing_ok = false;
2160 3052 : $$ = (Node *) n;
2161 : }
2162 : | ALTER TABLE IF_P EXISTS relation_expr partition_cmd
2163 : {
2164 0 : AlterTableStmt *n = makeNode(AlterTableStmt);
2165 :
2166 0 : n->relation = $5;
2167 0 : n->cmds = list_make1($6);
2168 0 : n->objtype = OBJECT_TABLE;
2169 0 : n->missing_ok = true;
2170 0 : $$ = (Node *) n;
2171 : }
2172 : | ALTER TABLE ALL IN_P TABLESPACE name SET TABLESPACE name opt_nowait
2173 : {
2174 : AlterTableMoveAllStmt *n =
2175 12 : makeNode(AlterTableMoveAllStmt);
2176 :
2177 12 : n->orig_tablespacename = $6;
2178 12 : n->objtype = OBJECT_TABLE;
2179 12 : n->roles = NIL;
2180 12 : n->new_tablespacename = $9;
2181 12 : n->nowait = $10;
2182 12 : $$ = (Node *) n;
2183 : }
2184 : | ALTER TABLE ALL IN_P TABLESPACE name OWNED BY role_list SET TABLESPACE name opt_nowait
2185 : {
2186 : AlterTableMoveAllStmt *n =
2187 0 : makeNode(AlterTableMoveAllStmt);
2188 :
2189 0 : n->orig_tablespacename = $6;
2190 0 : n->objtype = OBJECT_TABLE;
2191 0 : n->roles = $9;
2192 0 : n->new_tablespacename = $12;
2193 0 : n->nowait = $13;
2194 0 : $$ = (Node *) n;
2195 : }
2196 : | ALTER INDEX qualified_name alter_table_cmds
2197 : {
2198 228 : AlterTableStmt *n = makeNode(AlterTableStmt);
2199 :
2200 228 : n->relation = $3;
2201 228 : n->cmds = $4;
2202 228 : n->objtype = OBJECT_INDEX;
2203 228 : n->missing_ok = false;
2204 228 : $$ = (Node *) n;
2205 : }
2206 : | ALTER INDEX IF_P EXISTS qualified_name alter_table_cmds
2207 : {
2208 0 : AlterTableStmt *n = makeNode(AlterTableStmt);
2209 :
2210 0 : n->relation = $5;
2211 0 : n->cmds = $6;
2212 0 : n->objtype = OBJECT_INDEX;
2213 0 : n->missing_ok = true;
2214 0 : $$ = (Node *) n;
2215 : }
2216 : | ALTER INDEX qualified_name index_partition_cmd
2217 : {
2218 386 : AlterTableStmt *n = makeNode(AlterTableStmt);
2219 :
2220 386 : n->relation = $3;
2221 386 : n->cmds = list_make1($4);
2222 386 : n->objtype = OBJECT_INDEX;
2223 386 : n->missing_ok = false;
2224 386 : $$ = (Node *) n;
2225 : }
2226 : | ALTER INDEX ALL IN_P TABLESPACE name SET TABLESPACE name opt_nowait
2227 : {
2228 : AlterTableMoveAllStmt *n =
2229 6 : makeNode(AlterTableMoveAllStmt);
2230 :
2231 6 : n->orig_tablespacename = $6;
2232 6 : n->objtype = OBJECT_INDEX;
2233 6 : n->roles = NIL;
2234 6 : n->new_tablespacename = $9;
2235 6 : n->nowait = $10;
2236 6 : $$ = (Node *) n;
2237 : }
2238 : | ALTER INDEX ALL IN_P TABLESPACE name OWNED BY role_list SET TABLESPACE name opt_nowait
2239 : {
2240 : AlterTableMoveAllStmt *n =
2241 0 : makeNode(AlterTableMoveAllStmt);
2242 :
2243 0 : n->orig_tablespacename = $6;
2244 0 : n->objtype = OBJECT_INDEX;
2245 0 : n->roles = $9;
2246 0 : n->new_tablespacename = $12;
2247 0 : n->nowait = $13;
2248 0 : $$ = (Node *) n;
2249 : }
2250 : | ALTER SEQUENCE qualified_name alter_table_cmds
2251 : {
2252 94 : AlterTableStmt *n = makeNode(AlterTableStmt);
2253 :
2254 94 : n->relation = $3;
2255 94 : n->cmds = $4;
2256 94 : n->objtype = OBJECT_SEQUENCE;
2257 94 : n->missing_ok = false;
2258 94 : $$ = (Node *) n;
2259 : }
2260 : | ALTER SEQUENCE IF_P EXISTS qualified_name alter_table_cmds
2261 : {
2262 0 : AlterTableStmt *n = makeNode(AlterTableStmt);
2263 :
2264 0 : n->relation = $5;
2265 0 : n->cmds = $6;
2266 0 : n->objtype = OBJECT_SEQUENCE;
2267 0 : n->missing_ok = true;
2268 0 : $$ = (Node *) n;
2269 : }
2270 : | ALTER VIEW qualified_name alter_table_cmds
2271 : {
2272 254 : AlterTableStmt *n = makeNode(AlterTableStmt);
2273 :
2274 254 : n->relation = $3;
2275 254 : n->cmds = $4;
2276 254 : n->objtype = OBJECT_VIEW;
2277 254 : n->missing_ok = false;
2278 254 : $$ = (Node *) n;
2279 : }
2280 : | ALTER VIEW IF_P EXISTS qualified_name alter_table_cmds
2281 : {
2282 0 : AlterTableStmt *n = makeNode(AlterTableStmt);
2283 :
2284 0 : n->relation = $5;
2285 0 : n->cmds = $6;
2286 0 : n->objtype = OBJECT_VIEW;
2287 0 : n->missing_ok = true;
2288 0 : $$ = (Node *) n;
2289 : }
2290 : | ALTER MATERIALIZED VIEW qualified_name alter_table_cmds
2291 : {
2292 48 : AlterTableStmt *n = makeNode(AlterTableStmt);
2293 :
2294 48 : n->relation = $4;
2295 48 : n->cmds = $5;
2296 48 : n->objtype = OBJECT_MATVIEW;
2297 48 : n->missing_ok = false;
2298 48 : $$ = (Node *) n;
2299 : }
2300 : | ALTER MATERIALIZED VIEW IF_P EXISTS qualified_name alter_table_cmds
2301 : {
2302 0 : AlterTableStmt *n = makeNode(AlterTableStmt);
2303 :
2304 0 : n->relation = $6;
2305 0 : n->cmds = $7;
2306 0 : n->objtype = OBJECT_MATVIEW;
2307 0 : n->missing_ok = true;
2308 0 : $$ = (Node *) n;
2309 : }
2310 : | ALTER MATERIALIZED VIEW ALL IN_P TABLESPACE name SET TABLESPACE name opt_nowait
2311 : {
2312 : AlterTableMoveAllStmt *n =
2313 12 : makeNode(AlterTableMoveAllStmt);
2314 :
2315 12 : n->orig_tablespacename = $7;
2316 12 : n->objtype = OBJECT_MATVIEW;
2317 12 : n->roles = NIL;
2318 12 : n->new_tablespacename = $10;
2319 12 : n->nowait = $11;
2320 12 : $$ = (Node *) n;
2321 : }
2322 : | ALTER MATERIALIZED VIEW ALL IN_P TABLESPACE name OWNED BY role_list SET TABLESPACE name opt_nowait
2323 : {
2324 : AlterTableMoveAllStmt *n =
2325 0 : makeNode(AlterTableMoveAllStmt);
2326 :
2327 0 : n->orig_tablespacename = $7;
2328 0 : n->objtype = OBJECT_MATVIEW;
2329 0 : n->roles = $10;
2330 0 : n->new_tablespacename = $13;
2331 0 : n->nowait = $14;
2332 0 : $$ = (Node *) n;
2333 : }
2334 : | ALTER FOREIGN TABLE relation_expr alter_table_cmds
2335 : {
2336 378 : AlterTableStmt *n = makeNode(AlterTableStmt);
2337 :
2338 378 : n->relation = $4;
2339 378 : n->cmds = $5;
2340 378 : n->objtype = OBJECT_FOREIGN_TABLE;
2341 378 : n->missing_ok = false;
2342 378 : $$ = (Node *) n;
2343 : }
2344 : | ALTER FOREIGN TABLE IF_P EXISTS relation_expr alter_table_cmds
2345 : {
2346 108 : AlterTableStmt *n = makeNode(AlterTableStmt);
2347 :
2348 108 : n->relation = $6;
2349 108 : n->cmds = $7;
2350 108 : n->objtype = OBJECT_FOREIGN_TABLE;
2351 108 : n->missing_ok = true;
2352 108 : $$ = (Node *) n;
2353 : }
2354 : ;
2355 :
2356 : alter_table_cmds:
2357 27520 : alter_table_cmd { $$ = list_make1($1); }
2358 1020 : | alter_table_cmds ',' alter_table_cmd { $$ = lappend($1, $3); }
2359 : ;
2360 :
2361 : partition_cmd:
2362 : /* ALTER TABLE <name> ATTACH PARTITION <table_name> FOR VALUES */
2363 : ATTACH PARTITION qualified_name PartitionBoundSpec
2364 : {
2365 2430 : AlterTableCmd *n = makeNode(AlterTableCmd);
2366 2430 : PartitionCmd *cmd = makeNode(PartitionCmd);
2367 :
2368 2430 : n->subtype = AT_AttachPartition;
2369 2430 : cmd->name = $3;
2370 2430 : cmd->bound = $4;
2371 2430 : cmd->concurrent = false;
2372 2430 : n->def = (Node *) cmd;
2373 :
2374 2430 : $$ = (Node *) n;
2375 : }
2376 : /* ALTER TABLE <name> DETACH PARTITION <partition_name> [CONCURRENTLY] */
2377 : | DETACH PARTITION qualified_name opt_concurrently
2378 : {
2379 602 : AlterTableCmd *n = makeNode(AlterTableCmd);
2380 602 : PartitionCmd *cmd = makeNode(PartitionCmd);
2381 :
2382 602 : n->subtype = AT_DetachPartition;
2383 602 : cmd->name = $3;
2384 602 : cmd->bound = NULL;
2385 602 : cmd->concurrent = $4;
2386 602 : n->def = (Node *) cmd;
2387 :
2388 602 : $$ = (Node *) n;
2389 : }
2390 : | DETACH PARTITION qualified_name FINALIZE
2391 : {
2392 20 : AlterTableCmd *n = makeNode(AlterTableCmd);
2393 20 : PartitionCmd *cmd = makeNode(PartitionCmd);
2394 :
2395 20 : n->subtype = AT_DetachPartitionFinalize;
2396 20 : cmd->name = $3;
2397 20 : cmd->bound = NULL;
2398 20 : cmd->concurrent = false;
2399 20 : n->def = (Node *) cmd;
2400 20 : $$ = (Node *) n;
2401 : }
2402 : ;
2403 :
2404 : index_partition_cmd:
2405 : /* ALTER INDEX <name> ATTACH PARTITION <index_name> */
2406 : ATTACH PARTITION qualified_name
2407 : {
2408 386 : AlterTableCmd *n = makeNode(AlterTableCmd);
2409 386 : PartitionCmd *cmd = makeNode(PartitionCmd);
2410 :
2411 386 : n->subtype = AT_AttachPartition;
2412 386 : cmd->name = $3;
2413 386 : cmd->bound = NULL;
2414 386 : cmd->concurrent = false;
2415 386 : n->def = (Node *) cmd;
2416 :
2417 386 : $$ = (Node *) n;
2418 : }
2419 : ;
2420 :
2421 : alter_table_cmd:
2422 : /* ALTER TABLE <name> ADD <coldef> */
2423 : ADD_P columnDef
2424 : {
2425 192 : AlterTableCmd *n = makeNode(AlterTableCmd);
2426 :
2427 192 : n->subtype = AT_AddColumn;
2428 192 : n->def = $2;
2429 192 : n->missing_ok = false;
2430 192 : $$ = (Node *) n;
2431 : }
2432 : /* ALTER TABLE <name> ADD IF NOT EXISTS <coldef> */
2433 : | ADD_P IF_P NOT EXISTS columnDef
2434 : {
2435 0 : AlterTableCmd *n = makeNode(AlterTableCmd);
2436 :
2437 0 : n->subtype = AT_AddColumn;
2438 0 : n->def = $5;
2439 0 : n->missing_ok = true;
2440 0 : $$ = (Node *) n;
2441 : }
2442 : /* ALTER TABLE <name> ADD COLUMN <coldef> */
2443 : | ADD_P COLUMN columnDef
2444 : {
2445 1918 : AlterTableCmd *n = makeNode(AlterTableCmd);
2446 :
2447 1918 : n->subtype = AT_AddColumn;
2448 1918 : n->def = $3;
2449 1918 : n->missing_ok = false;
2450 1918 : $$ = (Node *) n;
2451 : }
2452 : /* ALTER TABLE <name> ADD COLUMN IF NOT EXISTS <coldef> */
2453 : | ADD_P COLUMN IF_P NOT EXISTS columnDef
2454 : {
2455 60 : AlterTableCmd *n = makeNode(AlterTableCmd);
2456 :
2457 60 : n->subtype = AT_AddColumn;
2458 60 : n->def = $6;
2459 60 : n->missing_ok = true;
2460 60 : $$ = (Node *) n;
2461 : }
2462 : /* ALTER TABLE <name> ALTER [COLUMN] <colname> {SET DEFAULT <expr>|DROP DEFAULT} */
2463 : | ALTER opt_column ColId alter_column_default
2464 : {
2465 550 : AlterTableCmd *n = makeNode(AlterTableCmd);
2466 :
2467 550 : n->subtype = AT_ColumnDefault;
2468 550 : n->name = $3;
2469 550 : n->def = $4;
2470 550 : $$ = (Node *) n;
2471 : }
2472 : /* ALTER TABLE <name> ALTER [COLUMN] <colname> DROP NOT NULL */
2473 : | ALTER opt_column ColId DROP NOT NULL_P
2474 : {
2475 294 : AlterTableCmd *n = makeNode(AlterTableCmd);
2476 :
2477 294 : n->subtype = AT_DropNotNull;
2478 294 : n->name = $3;
2479 294 : $$ = (Node *) n;
2480 : }
2481 : /* ALTER TABLE <name> ALTER [COLUMN] <colname> SET NOT NULL */
2482 : | ALTER opt_column ColId SET NOT NULL_P
2483 : {
2484 434 : AlterTableCmd *n = makeNode(AlterTableCmd);
2485 :
2486 434 : n->subtype = AT_SetNotNull;
2487 434 : n->name = $3;
2488 434 : $$ = (Node *) n;
2489 : }
2490 : /* ALTER TABLE <name> ALTER [COLUMN] <colname> SET EXPRESSION AS <expr> */
2491 : | ALTER opt_column ColId SET EXPRESSION AS '(' a_expr ')'
2492 : {
2493 168 : AlterTableCmd *n = makeNode(AlterTableCmd);
2494 :
2495 168 : n->subtype = AT_SetExpression;
2496 168 : n->name = $3;
2497 168 : n->def = $8;
2498 168 : $$ = (Node *) n;
2499 : }
2500 : /* ALTER TABLE <name> ALTER [COLUMN] <colname> DROP EXPRESSION */
2501 : | ALTER opt_column ColId DROP EXPRESSION
2502 : {
2503 62 : AlterTableCmd *n = makeNode(AlterTableCmd);
2504 :
2505 62 : n->subtype = AT_DropExpression;
2506 62 : n->name = $3;
2507 62 : $$ = (Node *) n;
2508 : }
2509 : /* ALTER TABLE <name> ALTER [COLUMN] <colname> DROP EXPRESSION IF EXISTS */
2510 : | ALTER opt_column ColId DROP EXPRESSION IF_P EXISTS
2511 : {
2512 12 : AlterTableCmd *n = makeNode(AlterTableCmd);
2513 :
2514 12 : n->subtype = AT_DropExpression;
2515 12 : n->name = $3;
2516 12 : n->missing_ok = true;
2517 12 : $$ = (Node *) n;
2518 : }
2519 : /* ALTER TABLE <name> ALTER [COLUMN] <colname> SET STATISTICS */
2520 : | ALTER opt_column ColId SET STATISTICS set_statistics_value
2521 : {
2522 62 : AlterTableCmd *n = makeNode(AlterTableCmd);
2523 :
2524 62 : n->subtype = AT_SetStatistics;
2525 62 : n->name = $3;
2526 62 : n->def = $6;
2527 62 : $$ = (Node *) n;
2528 : }
2529 : /* ALTER TABLE <name> ALTER [COLUMN] <colnum> SET STATISTICS */
2530 : | ALTER opt_column Iconst SET STATISTICS set_statistics_value
2531 : {
2532 70 : AlterTableCmd *n = makeNode(AlterTableCmd);
2533 :
2534 70 : if ($3 <= 0 || $3 > PG_INT16_MAX)
2535 6 : ereport(ERROR,
2536 : (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
2537 : errmsg("column number must be in range from 1 to %d", PG_INT16_MAX),
2538 : parser_errposition(@3)));
2539 :
2540 64 : n->subtype = AT_SetStatistics;
2541 64 : n->num = (int16) $3;
2542 64 : n->def = $6;
2543 64 : $$ = (Node *) n;
2544 : }
2545 : /* ALTER TABLE <name> ALTER [COLUMN] <colname> SET ( column_parameter = value [, ... ] ) */
2546 : | ALTER opt_column ColId SET reloptions
2547 : {
2548 38 : AlterTableCmd *n = makeNode(AlterTableCmd);
2549 :
2550 38 : n->subtype = AT_SetOptions;
2551 38 : n->name = $3;
2552 38 : n->def = (Node *) $5;
2553 38 : $$ = (Node *) n;
2554 : }
2555 : /* ALTER TABLE <name> ALTER [COLUMN] <colname> RESET ( column_parameter [, ... ] ) */
2556 : | ALTER opt_column ColId RESET reloptions
2557 : {
2558 6 : AlterTableCmd *n = makeNode(AlterTableCmd);
2559 :
2560 6 : n->subtype = AT_ResetOptions;
2561 6 : n->name = $3;
2562 6 : n->def = (Node *) $5;
2563 6 : $$ = (Node *) n;
2564 : }
2565 : /* ALTER TABLE <name> ALTER [COLUMN] <colname> SET STORAGE <storagemode> */
2566 : | ALTER opt_column ColId SET column_storage
2567 : {
2568 238 : AlterTableCmd *n = makeNode(AlterTableCmd);
2569 :
2570 238 : n->subtype = AT_SetStorage;
2571 238 : n->name = $3;
2572 238 : n->def = (Node *) makeString($5);
2573 238 : $$ = (Node *) n;
2574 : }
2575 : /* ALTER TABLE <name> ALTER [COLUMN] <colname> SET COMPRESSION <cm> */
2576 : | ALTER opt_column ColId SET column_compression
2577 : {
2578 78 : AlterTableCmd *n = makeNode(AlterTableCmd);
2579 :
2580 78 : n->subtype = AT_SetCompression;
2581 78 : n->name = $3;
2582 78 : n->def = (Node *) makeString($5);
2583 78 : $$ = (Node *) n;
2584 : }
2585 : /* ALTER TABLE <name> ALTER [COLUMN] <colname> ADD GENERATED ... AS IDENTITY ... */
2586 : | ALTER opt_column ColId ADD_P GENERATED generated_when AS IDENTITY_P OptParenthesizedSeqOptList
2587 : {
2588 166 : AlterTableCmd *n = makeNode(AlterTableCmd);
2589 166 : Constraint *c = makeNode(Constraint);
2590 :
2591 166 : c->contype = CONSTR_IDENTITY;
2592 166 : c->generated_when = $6;
2593 166 : c->options = $9;
2594 166 : c->location = @5;
2595 :
2596 166 : n->subtype = AT_AddIdentity;
2597 166 : n->name = $3;
2598 166 : n->def = (Node *) c;
2599 :
2600 166 : $$ = (Node *) n;
2601 : }
2602 : /* ALTER TABLE <name> ALTER [COLUMN] <colname> SET <sequence options>/RESET */
2603 : | ALTER opt_column ColId alter_identity_column_option_list
2604 : {
2605 62 : AlterTableCmd *n = makeNode(AlterTableCmd);
2606 :
2607 62 : n->subtype = AT_SetIdentity;
2608 62 : n->name = $3;
2609 62 : n->def = (Node *) $4;
2610 62 : $$ = (Node *) n;
2611 : }
2612 : /* ALTER TABLE <name> ALTER [COLUMN] <colname> DROP IDENTITY */
2613 : | ALTER opt_column ColId DROP IDENTITY_P
2614 : {
2615 50 : AlterTableCmd *n = makeNode(AlterTableCmd);
2616 :
2617 50 : n->subtype = AT_DropIdentity;
2618 50 : n->name = $3;
2619 50 : n->missing_ok = false;
2620 50 : $$ = (Node *) n;
2621 : }
2622 : /* ALTER TABLE <name> ALTER [COLUMN] <colname> DROP IDENTITY IF EXISTS */
2623 : | ALTER opt_column ColId DROP IDENTITY_P IF_P EXISTS
2624 : {
2625 6 : AlterTableCmd *n = makeNode(AlterTableCmd);
2626 :
2627 6 : n->subtype = AT_DropIdentity;
2628 6 : n->name = $3;
2629 6 : n->missing_ok = true;
2630 6 : $$ = (Node *) n;
2631 : }
2632 : /* ALTER TABLE <name> DROP [COLUMN] IF EXISTS <colname> [RESTRICT|CASCADE] */
2633 : | DROP opt_column IF_P EXISTS ColId opt_drop_behavior
2634 : {
2635 18 : AlterTableCmd *n = makeNode(AlterTableCmd);
2636 :
2637 18 : n->subtype = AT_DropColumn;
2638 18 : n->name = $5;
2639 18 : n->behavior = $6;
2640 18 : n->missing_ok = true;
2641 18 : $$ = (Node *) n;
2642 : }
2643 : /* ALTER TABLE <name> DROP [COLUMN] <colname> [RESTRICT|CASCADE] */
2644 : | DROP opt_column ColId opt_drop_behavior
2645 : {
2646 1574 : AlterTableCmd *n = makeNode(AlterTableCmd);
2647 :
2648 1574 : n->subtype = AT_DropColumn;
2649 1574 : n->name = $3;
2650 1574 : n->behavior = $4;
2651 1574 : n->missing_ok = false;
2652 1574 : $$ = (Node *) n;
2653 : }
2654 : /*
2655 : * ALTER TABLE <name> ALTER [COLUMN] <colname> [SET DATA] TYPE <typename>
2656 : * [ USING <expression> ]
2657 : */
2658 : | ALTER opt_column ColId opt_set_data TYPE_P Typename opt_collate_clause alter_using
2659 : {
2660 1024 : AlterTableCmd *n = makeNode(AlterTableCmd);
2661 1024 : ColumnDef *def = makeNode(ColumnDef);
2662 :
2663 1024 : n->subtype = AT_AlterColumnType;
2664 1024 : n->name = $3;
2665 1024 : n->def = (Node *) def;
2666 : /* We only use these fields of the ColumnDef node */
2667 1024 : def->typeName = $6;
2668 1024 : def->collClause = (CollateClause *) $7;
2669 1024 : def->raw_default = $8;
2670 1024 : def->location = @3;
2671 1024 : $$ = (Node *) n;
2672 : }
2673 : /* ALTER FOREIGN TABLE <name> ALTER [COLUMN] <colname> OPTIONS */
2674 : | ALTER opt_column ColId alter_generic_options
2675 : {
2676 50 : AlterTableCmd *n = makeNode(AlterTableCmd);
2677 :
2678 50 : n->subtype = AT_AlterColumnGenericOptions;
2679 50 : n->name = $3;
2680 50 : n->def = (Node *) $4;
2681 50 : $$ = (Node *) n;
2682 : }
2683 : /* ALTER TABLE <name> ADD CONSTRAINT ... */
2684 : | ADD_P TableConstraint
2685 : {
2686 14560 : AlterTableCmd *n = makeNode(AlterTableCmd);
2687 :
2688 14560 : n->subtype = AT_AddConstraint;
2689 14560 : n->def = $2;
2690 14560 : $$ = (Node *) n;
2691 : }
2692 : /* ALTER TABLE <name> ALTER CONSTRAINT ... */
2693 : | ALTER CONSTRAINT name ConstraintAttributeSpec
2694 : {
2695 240 : AlterTableCmd *n = makeNode(AlterTableCmd);
2696 240 : ATAlterConstraint *c = makeNode(ATAlterConstraint);
2697 :
2698 240 : n->subtype = AT_AlterConstraint;
2699 240 : n->def = (Node *) c;
2700 240 : c->conname = $3;
2701 240 : if ($4 & (CAS_NOT_ENFORCED | CAS_ENFORCED))
2702 84 : c->alterEnforceability = true;
2703 240 : if ($4 & (CAS_DEFERRABLE | CAS_NOT_DEFERRABLE |
2704 : CAS_INITIALLY_DEFERRED | CAS_INITIALLY_IMMEDIATE))
2705 120 : c->alterDeferrability = true;
2706 240 : if ($4 & CAS_NO_INHERIT)
2707 30 : c->alterInheritability = true;
2708 : /* handle unsupported case with specific error message */
2709 240 : if ($4 & CAS_NOT_VALID)
2710 12 : ereport(ERROR,
2711 : errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
2712 : errmsg("constraints cannot be altered to be NOT VALID"),
2713 : parser_errposition(@4));
2714 228 : processCASbits($4, @4, "FOREIGN KEY",
2715 : &c->deferrable,
2716 : &c->initdeferred,
2717 : &c->is_enforced,
2718 : NULL,
2719 : &c->noinherit,
2720 : yyscanner);
2721 228 : $$ = (Node *) n;
2722 : }
2723 : /* ALTER TABLE <name> ALTER CONSTRAINT INHERIT */
2724 : | ALTER CONSTRAINT name INHERIT
2725 : {
2726 66 : AlterTableCmd *n = makeNode(AlterTableCmd);
2727 66 : ATAlterConstraint *c = makeNode(ATAlterConstraint);
2728 :
2729 66 : n->subtype = AT_AlterConstraint;
2730 66 : n->def = (Node *) c;
2731 66 : c->conname = $3;
2732 66 : c->alterInheritability = true;
2733 66 : c->noinherit = false;
2734 :
2735 66 : $$ = (Node *) n;
2736 : }
2737 : /* ALTER TABLE <name> VALIDATE CONSTRAINT ... */
2738 : | VALIDATE CONSTRAINT name
2739 : {
2740 476 : AlterTableCmd *n = makeNode(AlterTableCmd);
2741 :
2742 476 : n->subtype = AT_ValidateConstraint;
2743 476 : n->name = $3;
2744 476 : $$ = (Node *) n;
2745 : }
2746 : /* ALTER TABLE <name> DROP CONSTRAINT IF EXISTS <name> [RESTRICT|CASCADE] */
2747 : | DROP CONSTRAINT IF_P EXISTS name opt_drop_behavior
2748 : {
2749 18 : AlterTableCmd *n = makeNode(AlterTableCmd);
2750 :
2751 18 : n->subtype = AT_DropConstraint;
2752 18 : n->name = $5;
2753 18 : n->behavior = $6;
2754 18 : n->missing_ok = true;
2755 18 : $$ = (Node *) n;
2756 : }
2757 : /* ALTER TABLE <name> DROP CONSTRAINT <name> [RESTRICT|CASCADE] */
2758 : | DROP CONSTRAINT name opt_drop_behavior
2759 : {
2760 818 : AlterTableCmd *n = makeNode(AlterTableCmd);
2761 :
2762 818 : n->subtype = AT_DropConstraint;
2763 818 : n->name = $3;
2764 818 : n->behavior = $4;
2765 818 : n->missing_ok = false;
2766 818 : $$ = (Node *) n;
2767 : }
2768 : /* ALTER TABLE <name> SET WITHOUT OIDS, for backward compat */
2769 : | SET WITHOUT OIDS
2770 : {
2771 6 : AlterTableCmd *n = makeNode(AlterTableCmd);
2772 :
2773 6 : n->subtype = AT_DropOids;
2774 6 : $$ = (Node *) n;
2775 : }
2776 : /* ALTER TABLE <name> CLUSTER ON <indexname> */
2777 : | CLUSTER ON name
2778 : {
2779 46 : AlterTableCmd *n = makeNode(AlterTableCmd);
2780 :
2781 46 : n->subtype = AT_ClusterOn;
2782 46 : n->name = $3;
2783 46 : $$ = (Node *) n;
2784 : }
2785 : /* ALTER TABLE <name> SET WITHOUT CLUSTER */
2786 : | SET WITHOUT CLUSTER
2787 : {
2788 18 : AlterTableCmd *n = makeNode(AlterTableCmd);
2789 :
2790 18 : n->subtype = AT_DropCluster;
2791 18 : n->name = NULL;
2792 18 : $$ = (Node *) n;
2793 : }
2794 : /* ALTER TABLE <name> SET LOGGED */
2795 : | SET LOGGED
2796 : {
2797 50 : AlterTableCmd *n = makeNode(AlterTableCmd);
2798 :
2799 50 : n->subtype = AT_SetLogged;
2800 50 : $$ = (Node *) n;
2801 : }
2802 : /* ALTER TABLE <name> SET UNLOGGED */
2803 : | SET UNLOGGED
2804 : {
2805 62 : AlterTableCmd *n = makeNode(AlterTableCmd);
2806 :
2807 62 : n->subtype = AT_SetUnLogged;
2808 62 : $$ = (Node *) n;
2809 : }
2810 : /* ALTER TABLE <name> ENABLE TRIGGER <trig> */
2811 : | ENABLE_P TRIGGER name
2812 : {
2813 122 : AlterTableCmd *n = makeNode(AlterTableCmd);
2814 :
2815 122 : n->subtype = AT_EnableTrig;
2816 122 : n->name = $3;
2817 122 : $$ = (Node *) n;
2818 : }
2819 : /* ALTER TABLE <name> ENABLE ALWAYS TRIGGER <trig> */
2820 : | ENABLE_P ALWAYS TRIGGER name
2821 : {
2822 42 : AlterTableCmd *n = makeNode(AlterTableCmd);
2823 :
2824 42 : n->subtype = AT_EnableAlwaysTrig;
2825 42 : n->name = $4;
2826 42 : $$ = (Node *) n;
2827 : }
2828 : /* ALTER TABLE <name> ENABLE REPLICA TRIGGER <trig> */
2829 : | ENABLE_P REPLICA TRIGGER name
2830 : {
2831 16 : AlterTableCmd *n = makeNode(AlterTableCmd);
2832 :
2833 16 : n->subtype = AT_EnableReplicaTrig;
2834 16 : n->name = $4;
2835 16 : $$ = (Node *) n;
2836 : }
2837 : /* ALTER TABLE <name> ENABLE TRIGGER ALL */
2838 : | ENABLE_P TRIGGER ALL
2839 : {
2840 0 : AlterTableCmd *n = makeNode(AlterTableCmd);
2841 :
2842 0 : n->subtype = AT_EnableTrigAll;
2843 0 : $$ = (Node *) n;
2844 : }
2845 : /* ALTER TABLE <name> ENABLE TRIGGER USER */
2846 : | ENABLE_P TRIGGER USER
2847 : {
2848 0 : AlterTableCmd *n = makeNode(AlterTableCmd);
2849 :
2850 0 : n->subtype = AT_EnableTrigUser;
2851 0 : $$ = (Node *) n;
2852 : }
2853 : /* ALTER TABLE <name> DISABLE TRIGGER <trig> */
2854 : | DISABLE_P TRIGGER name
2855 : {
2856 138 : AlterTableCmd *n = makeNode(AlterTableCmd);
2857 :
2858 138 : n->subtype = AT_DisableTrig;
2859 138 : n->name = $3;
2860 138 : $$ = (Node *) n;
2861 : }
2862 : /* ALTER TABLE <name> DISABLE TRIGGER ALL */
2863 : | DISABLE_P TRIGGER ALL
2864 : {
2865 12 : AlterTableCmd *n = makeNode(AlterTableCmd);
2866 :
2867 12 : n->subtype = AT_DisableTrigAll;
2868 12 : $$ = (Node *) n;
2869 : }
2870 : /* ALTER TABLE <name> DISABLE TRIGGER USER */
2871 : | DISABLE_P TRIGGER USER
2872 : {
2873 12 : AlterTableCmd *n = makeNode(AlterTableCmd);
2874 :
2875 12 : n->subtype = AT_DisableTrigUser;
2876 12 : $$ = (Node *) n;
2877 : }
2878 : /* ALTER TABLE <name> ENABLE RULE <rule> */
2879 : | ENABLE_P RULE name
2880 : {
2881 8 : AlterTableCmd *n = makeNode(AlterTableCmd);
2882 :
2883 8 : n->subtype = AT_EnableRule;
2884 8 : n->name = $3;
2885 8 : $$ = (Node *) n;
2886 : }
2887 : /* ALTER TABLE <name> ENABLE ALWAYS RULE <rule> */
2888 : | ENABLE_P ALWAYS RULE name
2889 : {
2890 0 : AlterTableCmd *n = makeNode(AlterTableCmd);
2891 :
2892 0 : n->subtype = AT_EnableAlwaysRule;
2893 0 : n->name = $4;
2894 0 : $$ = (Node *) n;
2895 : }
2896 : /* ALTER TABLE <name> ENABLE REPLICA RULE <rule> */
2897 : | ENABLE_P REPLICA RULE name
2898 : {
2899 6 : AlterTableCmd *n = makeNode(AlterTableCmd);
2900 :
2901 6 : n->subtype = AT_EnableReplicaRule;
2902 6 : n->name = $4;
2903 6 : $$ = (Node *) n;
2904 : }
2905 : /* ALTER TABLE <name> DISABLE RULE <rule> */
2906 : | DISABLE_P RULE name
2907 : {
2908 32 : AlterTableCmd *n = makeNode(AlterTableCmd);
2909 :
2910 32 : n->subtype = AT_DisableRule;
2911 32 : n->name = $3;
2912 32 : $$ = (Node *) n;
2913 : }
2914 : /* ALTER TABLE <name> INHERIT <parent> */
2915 : | INHERIT qualified_name
2916 : {
2917 462 : AlterTableCmd *n = makeNode(AlterTableCmd);
2918 :
2919 462 : n->subtype = AT_AddInherit;
2920 462 : n->def = (Node *) $2;
2921 462 : $$ = (Node *) n;
2922 : }
2923 : /* ALTER TABLE <name> NO INHERIT <parent> */
2924 : | NO INHERIT qualified_name
2925 : {
2926 94 : AlterTableCmd *n = makeNode(AlterTableCmd);
2927 :
2928 94 : n->subtype = AT_DropInherit;
2929 94 : n->def = (Node *) $3;
2930 94 : $$ = (Node *) n;
2931 : }
2932 : /* ALTER TABLE <name> OF <type_name> */
2933 : | OF any_name
2934 : {
2935 66 : AlterTableCmd *n = makeNode(AlterTableCmd);
2936 66 : TypeName *def = makeTypeNameFromNameList($2);
2937 :
2938 66 : def->location = @2;
2939 66 : n->subtype = AT_AddOf;
2940 66 : n->def = (Node *) def;
2941 66 : $$ = (Node *) n;
2942 : }
2943 : /* ALTER TABLE <name> NOT OF */
2944 : | NOT OF
2945 : {
2946 6 : AlterTableCmd *n = makeNode(AlterTableCmd);
2947 :
2948 6 : n->subtype = AT_DropOf;
2949 6 : $$ = (Node *) n;
2950 : }
2951 : /* ALTER TABLE <name> OWNER TO RoleSpec */
2952 : | OWNER TO RoleSpec
2953 : {
2954 2022 : AlterTableCmd *n = makeNode(AlterTableCmd);
2955 :
2956 2022 : n->subtype = AT_ChangeOwner;
2957 2022 : n->newowner = $3;
2958 2022 : $$ = (Node *) n;
2959 : }
2960 : /* ALTER TABLE <name> SET ACCESS METHOD { <amname> | DEFAULT } */
2961 : | SET ACCESS METHOD set_access_method_name
2962 : {
2963 128 : AlterTableCmd *n = makeNode(AlterTableCmd);
2964 :
2965 128 : n->subtype = AT_SetAccessMethod;
2966 128 : n->name = $4;
2967 128 : $$ = (Node *) n;
2968 : }
2969 : /* ALTER TABLE <name> SET TABLESPACE <tablespacename> */
2970 : | SET TABLESPACE name
2971 : {
2972 104 : AlterTableCmd *n = makeNode(AlterTableCmd);
2973 :
2974 104 : n->subtype = AT_SetTableSpace;
2975 104 : n->name = $3;
2976 104 : $$ = (Node *) n;
2977 : }
2978 : /* ALTER TABLE <name> SET (...) */
2979 : | SET reloptions
2980 : {
2981 600 : AlterTableCmd *n = makeNode(AlterTableCmd);
2982 :
2983 600 : n->subtype = AT_SetRelOptions;
2984 600 : n->def = (Node *) $2;
2985 600 : $$ = (Node *) n;
2986 : }
2987 : /* ALTER TABLE <name> RESET (...) */
2988 : | RESET reloptions
2989 : {
2990 170 : AlterTableCmd *n = makeNode(AlterTableCmd);
2991 :
2992 170 : n->subtype = AT_ResetRelOptions;
2993 170 : n->def = (Node *) $2;
2994 170 : $$ = (Node *) n;
2995 : }
2996 : /* ALTER TABLE <name> REPLICA IDENTITY */
2997 : | REPLICA IDENTITY_P replica_identity
2998 : {
2999 494 : AlterTableCmd *n = makeNode(AlterTableCmd);
3000 :
3001 494 : n->subtype = AT_ReplicaIdentity;
3002 494 : n->def = $3;
3003 494 : $$ = (Node *) n;
3004 : }
3005 : /* ALTER TABLE <name> ENABLE ROW LEVEL SECURITY */
3006 : | ENABLE_P ROW LEVEL SECURITY
3007 : {
3008 326 : AlterTableCmd *n = makeNode(AlterTableCmd);
3009 :
3010 326 : n->subtype = AT_EnableRowSecurity;
3011 326 : $$ = (Node *) n;
3012 : }
3013 : /* ALTER TABLE <name> DISABLE ROW LEVEL SECURITY */
3014 : | DISABLE_P ROW LEVEL SECURITY
3015 : {
3016 10 : AlterTableCmd *n = makeNode(AlterTableCmd);
3017 :
3018 10 : n->subtype = AT_DisableRowSecurity;
3019 10 : $$ = (Node *) n;
3020 : }
3021 : /* ALTER TABLE <name> FORCE ROW LEVEL SECURITY */
3022 : | FORCE ROW LEVEL SECURITY
3023 : {
3024 100 : AlterTableCmd *n = makeNode(AlterTableCmd);
3025 :
3026 100 : n->subtype = AT_ForceRowSecurity;
3027 100 : $$ = (Node *) n;
3028 : }
3029 : /* ALTER TABLE <name> NO FORCE ROW LEVEL SECURITY */
3030 : | NO FORCE ROW LEVEL SECURITY
3031 : {
3032 32 : AlterTableCmd *n = makeNode(AlterTableCmd);
3033 :
3034 32 : n->subtype = AT_NoForceRowSecurity;
3035 32 : $$ = (Node *) n;
3036 : }
3037 : | alter_generic_options
3038 : {
3039 64 : AlterTableCmd *n = makeNode(AlterTableCmd);
3040 :
3041 64 : n->subtype = AT_GenericOptions;
3042 64 : n->def = (Node *) $1;
3043 64 : $$ = (Node *) n;
3044 : }
3045 : ;
3046 :
3047 : alter_column_default:
3048 378 : SET DEFAULT a_expr { $$ = $3; }
3049 186 : | DROP DEFAULT { $$ = NULL; }
3050 : ;
3051 :
3052 : opt_collate_clause:
3053 : COLLATE any_name
3054 : {
3055 18 : CollateClause *n = makeNode(CollateClause);
3056 :
3057 18 : n->arg = NULL;
3058 18 : n->collname = $2;
3059 18 : n->location = @1;
3060 18 : $$ = (Node *) n;
3061 : }
3062 4732 : | /* EMPTY */ { $$ = NULL; }
3063 : ;
3064 :
3065 : alter_using:
3066 180 : USING a_expr { $$ = $2; }
3067 844 : | /* EMPTY */ { $$ = NULL; }
3068 : ;
3069 :
3070 : replica_identity:
3071 : NOTHING
3072 : {
3073 48 : ReplicaIdentityStmt *n = makeNode(ReplicaIdentityStmt);
3074 :
3075 48 : n->identity_type = REPLICA_IDENTITY_NOTHING;
3076 48 : n->name = NULL;
3077 48 : $$ = (Node *) n;
3078 : }
3079 : | FULL
3080 : {
3081 170 : ReplicaIdentityStmt *n = makeNode(ReplicaIdentityStmt);
3082 :
3083 170 : n->identity_type = REPLICA_IDENTITY_FULL;
3084 170 : n->name = NULL;
3085 170 : $$ = (Node *) n;
3086 : }
3087 : | DEFAULT
3088 : {
3089 6 : ReplicaIdentityStmt *n = makeNode(ReplicaIdentityStmt);
3090 :
3091 6 : n->identity_type = REPLICA_IDENTITY_DEFAULT;
3092 6 : n->name = NULL;
3093 6 : $$ = (Node *) n;
3094 : }
3095 : | USING INDEX name
3096 : {
3097 270 : ReplicaIdentityStmt *n = makeNode(ReplicaIdentityStmt);
3098 :
3099 270 : n->identity_type = REPLICA_IDENTITY_INDEX;
3100 270 : n->name = $3;
3101 270 : $$ = (Node *) n;
3102 : }
3103 : ;
3104 :
3105 : reloptions:
3106 2698 : '(' reloption_list ')' { $$ = $2; }
3107 : ;
3108 :
3109 964 : opt_reloptions: WITH reloptions { $$ = $2; }
3110 23422 : | /* EMPTY */ { $$ = NIL; }
3111 : ;
3112 :
3113 : reloption_list:
3114 2698 : reloption_elem { $$ = list_make1($1); }
3115 250 : | reloption_list ',' reloption_elem { $$ = lappend($1, $3); }
3116 : ;
3117 :
3118 : /* This should match def_elem and also allow qualified names */
3119 : reloption_elem:
3120 : ColLabel '=' def_arg
3121 : {
3122 2286 : $$ = makeDefElem($1, (Node *) $3, @1);
3123 : }
3124 : | ColLabel
3125 : {
3126 584 : $$ = makeDefElem($1, NULL, @1);
3127 : }
3128 : | ColLabel '.' ColLabel '=' def_arg
3129 : {
3130 72 : $$ = makeDefElemExtended($1, $3, (Node *) $5,
3131 72 : DEFELEM_UNSPEC, @1);
3132 : }
3133 : | ColLabel '.' ColLabel
3134 : {
3135 6 : $$ = makeDefElemExtended($1, $3, NULL, DEFELEM_UNSPEC, @1);
3136 : }
3137 : ;
3138 :
3139 : alter_identity_column_option_list:
3140 : alter_identity_column_option
3141 62 : { $$ = list_make1($1); }
3142 : | alter_identity_column_option_list alter_identity_column_option
3143 60 : { $$ = lappend($1, $2); }
3144 : ;
3145 :
3146 : alter_identity_column_option:
3147 : RESTART
3148 : {
3149 24 : $$ = makeDefElem("restart", NULL, @1);
3150 : }
3151 : | RESTART opt_with NumericOnly
3152 : {
3153 0 : $$ = makeDefElem("restart", (Node *) $3, @1);
3154 : }
3155 : | SET SeqOptElem
3156 : {
3157 54 : if (strcmp($2->defname, "as") == 0 ||
3158 54 : strcmp($2->defname, "restart") == 0 ||
3159 54 : strcmp($2->defname, "owned_by") == 0)
3160 0 : ereport(ERROR,
3161 : (errcode(ERRCODE_SYNTAX_ERROR),
3162 : errmsg("sequence option \"%s\" not supported here", $2->defname),
3163 : parser_errposition(@2)));
3164 54 : $$ = $2;
3165 : }
3166 : | SET GENERATED generated_when
3167 : {
3168 44 : $$ = makeDefElem("generated", (Node *) makeInteger($3), @1);
3169 : }
3170 : ;
3171 :
3172 : set_statistics_value:
3173 158 : SignedIconst { $$ = (Node *) makeInteger($1); }
3174 0 : | DEFAULT { $$ = NULL; }
3175 : ;
3176 :
3177 : set_access_method_name:
3178 92 : ColId { $$ = $1; }
3179 36 : | DEFAULT { $$ = NULL; }
3180 : ;
3181 :
3182 : PartitionBoundSpec:
3183 : /* a HASH partition */
3184 : FOR VALUES WITH '(' hash_partbound ')'
3185 : {
3186 : ListCell *lc;
3187 726 : PartitionBoundSpec *n = makeNode(PartitionBoundSpec);
3188 :
3189 726 : n->strategy = PARTITION_STRATEGY_HASH;
3190 726 : n->modulus = n->remainder = -1;
3191 :
3192 2178 : foreach (lc, $5)
3193 : {
3194 1452 : DefElem *opt = lfirst_node(DefElem, lc);
3195 :
3196 1452 : if (strcmp(opt->defname, "modulus") == 0)
3197 : {
3198 726 : if (n->modulus != -1)
3199 0 : ereport(ERROR,
3200 : (errcode(ERRCODE_DUPLICATE_OBJECT),
3201 : errmsg("modulus for hash partition provided more than once"),
3202 : parser_errposition(opt->location)));
3203 726 : n->modulus = defGetInt32(opt);
3204 : }
3205 726 : else if (strcmp(opt->defname, "remainder") == 0)
3206 : {
3207 726 : if (n->remainder != -1)
3208 0 : ereport(ERROR,
3209 : (errcode(ERRCODE_DUPLICATE_OBJECT),
3210 : errmsg("remainder for hash partition provided more than once"),
3211 : parser_errposition(opt->location)));
3212 726 : n->remainder = defGetInt32(opt);
3213 : }
3214 : else
3215 0 : ereport(ERROR,
3216 : (errcode(ERRCODE_SYNTAX_ERROR),
3217 : errmsg("unrecognized hash partition bound specification \"%s\"",
3218 : opt->defname),
3219 : parser_errposition(opt->location)));
3220 : }
3221 :
3222 726 : if (n->modulus == -1)
3223 0 : ereport(ERROR,
3224 : (errcode(ERRCODE_SYNTAX_ERROR),
3225 : errmsg("modulus for hash partition must be specified"),
3226 : parser_errposition(@3)));
3227 726 : if (n->remainder == -1)
3228 0 : ereport(ERROR,
3229 : (errcode(ERRCODE_SYNTAX_ERROR),
3230 : errmsg("remainder for hash partition must be specified"),
3231 : parser_errposition(@3)));
3232 :
3233 726 : n->location = @3;
3234 :
3235 726 : $$ = n;
3236 : }
3237 :
3238 : /* a LIST partition */
3239 : | FOR VALUES IN_P '(' expr_list ')'
3240 : {
3241 4986 : PartitionBoundSpec *n = makeNode(PartitionBoundSpec);
3242 :
3243 4986 : n->strategy = PARTITION_STRATEGY_LIST;
3244 4986 : n->is_default = false;
3245 4986 : n->listdatums = $5;
3246 4986 : n->location = @3;
3247 :
3248 4986 : $$ = n;
3249 : }
3250 :
3251 : /* a RANGE partition */
3252 : | FOR VALUES FROM '(' expr_list ')' TO '(' expr_list ')'
3253 : {
3254 4226 : PartitionBoundSpec *n = makeNode(PartitionBoundSpec);
3255 :
3256 4226 : n->strategy = PARTITION_STRATEGY_RANGE;
3257 4226 : n->is_default = false;
3258 4226 : n->lowerdatums = $5;
3259 4226 : n->upperdatums = $9;
3260 4226 : n->location = @3;
3261 :
3262 4226 : $$ = n;
3263 : }
3264 :
3265 : /* a DEFAULT partition */
3266 : | DEFAULT
3267 : {
3268 598 : PartitionBoundSpec *n = makeNode(PartitionBoundSpec);
3269 :
3270 598 : n->is_default = true;
3271 598 : n->location = @1;
3272 :
3273 598 : $$ = n;
3274 : }
3275 : ;
3276 :
3277 : hash_partbound_elem:
3278 : NonReservedWord Iconst
3279 : {
3280 1452 : $$ = makeDefElem($1, (Node *) makeInteger($2), @1);
3281 : }
3282 : ;
3283 :
3284 : hash_partbound:
3285 : hash_partbound_elem
3286 : {
3287 726 : $$ = list_make1($1);
3288 : }
3289 : | hash_partbound ',' hash_partbound_elem
3290 : {
3291 726 : $$ = lappend($1, $3);
3292 : }
3293 : ;
3294 :
3295 : /*****************************************************************************
3296 : *
3297 : * ALTER TYPE
3298 : *
3299 : * really variants of the ALTER TABLE subcommands with different spellings
3300 : *****************************************************************************/
3301 :
3302 : AlterCompositeTypeStmt:
3303 : ALTER TYPE_P any_name alter_type_cmds
3304 : {
3305 210 : AlterTableStmt *n = makeNode(AlterTableStmt);
3306 :
3307 : /* can't use qualified_name, sigh */
3308 210 : n->relation = makeRangeVarFromAnyName($3, @3, yyscanner);
3309 210 : n->cmds = $4;
3310 210 : n->objtype = OBJECT_TYPE;
3311 210 : $$ = (Node *) n;
3312 : }
3313 : ;
3314 :
3315 : alter_type_cmds:
3316 210 : alter_type_cmd { $$ = list_make1($1); }
3317 12 : | alter_type_cmds ',' alter_type_cmd { $$ = lappend($1, $3); }
3318 : ;
3319 :
3320 : alter_type_cmd:
3321 : /* ALTER TYPE <name> ADD ATTRIBUTE <coldef> [RESTRICT|CASCADE] */
3322 : ADD_P ATTRIBUTE TableFuncElement opt_drop_behavior
3323 : {
3324 64 : AlterTableCmd *n = makeNode(AlterTableCmd);
3325 :
3326 64 : n->subtype = AT_AddColumn;
3327 64 : n->def = $3;
3328 64 : n->behavior = $4;
3329 64 : $$ = (Node *) n;
3330 : }
3331 : /* ALTER TYPE <name> DROP ATTRIBUTE IF EXISTS <attname> [RESTRICT|CASCADE] */
3332 : | DROP ATTRIBUTE IF_P EXISTS ColId opt_drop_behavior
3333 : {
3334 6 : AlterTableCmd *n = makeNode(AlterTableCmd);
3335 :
3336 6 : n->subtype = AT_DropColumn;
3337 6 : n->name = $5;
3338 6 : n->behavior = $6;
3339 6 : n->missing_ok = true;
3340 6 : $$ = (Node *) n;
3341 : }
3342 : /* ALTER TYPE <name> DROP ATTRIBUTE <attname> [RESTRICT|CASCADE] */
3343 : | DROP ATTRIBUTE ColId opt_drop_behavior
3344 : {
3345 78 : AlterTableCmd *n = makeNode(AlterTableCmd);
3346 :
3347 78 : n->subtype = AT_DropColumn;
3348 78 : n->name = $3;
3349 78 : n->behavior = $4;
3350 78 : n->missing_ok = false;
3351 78 : $$ = (Node *) n;
3352 : }
3353 : /* ALTER TYPE <name> ALTER ATTRIBUTE <attname> [SET DATA] TYPE <typename> [RESTRICT|CASCADE] */
3354 : | ALTER ATTRIBUTE ColId opt_set_data TYPE_P Typename opt_collate_clause opt_drop_behavior
3355 : {
3356 74 : AlterTableCmd *n = makeNode(AlterTableCmd);
3357 74 : ColumnDef *def = makeNode(ColumnDef);
3358 :
3359 74 : n->subtype = AT_AlterColumnType;
3360 74 : n->name = $3;
3361 74 : n->def = (Node *) def;
3362 74 : n->behavior = $8;
3363 : /* We only use these fields of the ColumnDef node */
3364 74 : def->typeName = $6;
3365 74 : def->collClause = (CollateClause *) $7;
3366 74 : def->raw_default = NULL;
3367 74 : def->location = @3;
3368 74 : $$ = (Node *) n;
3369 : }
3370 : ;
3371 :
3372 :
3373 : /*****************************************************************************
3374 : *
3375 : * QUERY :
3376 : * close <portalname>
3377 : *
3378 : *****************************************************************************/
3379 :
3380 : ClosePortalStmt:
3381 : CLOSE cursor_name
3382 : {
3383 2230 : ClosePortalStmt *n = makeNode(ClosePortalStmt);
3384 :
3385 2230 : n->portalname = $2;
3386 2230 : $$ = (Node *) n;
3387 : }
3388 : | CLOSE ALL
3389 : {
3390 12 : ClosePortalStmt *n = makeNode(ClosePortalStmt);
3391 :
3392 12 : n->portalname = NULL;
3393 12 : $$ = (Node *) n;
3394 : }
3395 : ;
3396 :
3397 :
3398 : /*****************************************************************************
3399 : *
3400 : * QUERY :
3401 : * COPY relname [(columnList)] FROM/TO file [WITH] [(options)]
3402 : * COPY ( query ) TO file [WITH] [(options)]
3403 : *
3404 : * where 'query' can be one of:
3405 : * { SELECT | UPDATE | INSERT | DELETE }
3406 : *
3407 : * and 'file' can be one of:
3408 : * { PROGRAM 'command' | STDIN | STDOUT | 'filename' }
3409 : *
3410 : * In the preferred syntax the options are comma-separated
3411 : * and use generic identifiers instead of keywords. The pre-9.0
3412 : * syntax had a hard-wired, space-separated set of options.
3413 : *
3414 : * Really old syntax, from versions 7.2 and prior:
3415 : * COPY [ BINARY ] table FROM/TO file
3416 : * [ [ USING ] DELIMITERS 'delimiter' ] ]
3417 : * [ WITH NULL AS 'null string' ]
3418 : * This option placement is not supported with COPY (query...).
3419 : *
3420 : *****************************************************************************/
3421 :
3422 : CopyStmt: COPY opt_binary qualified_name opt_column_list
3423 : copy_from opt_program copy_file_name copy_delimiter opt_with
3424 : copy_options where_clause
3425 : {
3426 11208 : CopyStmt *n = makeNode(CopyStmt);
3427 :
3428 11208 : n->relation = $3;
3429 11208 : n->query = NULL;
3430 11208 : n->attlist = $4;
3431 11208 : n->is_from = $5;
3432 11208 : n->is_program = $6;
3433 11208 : n->filename = $7;
3434 11208 : n->whereClause = $11;
3435 :
3436 11208 : if (n->is_program && n->filename == NULL)
3437 0 : ereport(ERROR,
3438 : (errcode(ERRCODE_SYNTAX_ERROR),
3439 : errmsg("STDIN/STDOUT not allowed with PROGRAM"),
3440 : parser_errposition(@8)));
3441 :
3442 11208 : if (!n->is_from && n->whereClause != NULL)
3443 6 : ereport(ERROR,
3444 : (errcode(ERRCODE_SYNTAX_ERROR),
3445 : errmsg("WHERE clause not allowed with COPY TO"),
3446 : errhint("Try the COPY (SELECT ... WHERE ...) TO variant."),
3447 : parser_errposition(@11)));
3448 :
3449 11202 : n->options = NIL;
3450 : /* Concatenate user-supplied flags */
3451 11202 : if ($2)
3452 12 : n->options = lappend(n->options, $2);
3453 11202 : if ($8)
3454 0 : n->options = lappend(n->options, $8);
3455 11202 : if ($10)
3456 968 : n->options = list_concat(n->options, $10);
3457 11202 : $$ = (Node *) n;
3458 : }
3459 : | COPY '(' PreparableStmt ')' TO opt_program copy_file_name opt_with copy_options
3460 : {
3461 608 : CopyStmt *n = makeNode(CopyStmt);
3462 :
3463 608 : n->relation = NULL;
3464 608 : n->query = $3;
3465 608 : n->attlist = NIL;
3466 608 : n->is_from = false;
3467 608 : n->is_program = $6;
3468 608 : n->filename = $7;
3469 608 : n->options = $9;
3470 :
3471 608 : if (n->is_program && n->filename == NULL)
3472 0 : ereport(ERROR,
3473 : (errcode(ERRCODE_SYNTAX_ERROR),
3474 : errmsg("STDIN/STDOUT not allowed with PROGRAM"),
3475 : parser_errposition(@5)));
3476 :
3477 608 : $$ = (Node *) n;
3478 : }
3479 : ;
3480 :
3481 : copy_from:
3482 1856 : FROM { $$ = true; }
3483 9352 : | TO { $$ = false; }
3484 : ;
3485 :
3486 : opt_program:
3487 0 : PROGRAM { $$ = true; }
3488 11816 : | /* EMPTY */ { $$ = false; }
3489 : ;
3490 :
3491 : /*
3492 : * copy_file_name NULL indicates stdio is used. Whether stdin or stdout is
3493 : * used depends on the direction. (It really doesn't make sense to copy from
3494 : * stdout. We silently correct the "typo".) - AY 9/94
3495 : */
3496 : copy_file_name:
3497 452 : Sconst { $$ = $1; }
3498 1468 : | STDIN { $$ = NULL; }
3499 9896 : | STDOUT { $$ = NULL; }
3500 : ;
3501 :
3502 11118 : copy_options: copy_opt_list { $$ = $1; }
3503 698 : | '(' copy_generic_opt_list ')' { $$ = $2; }
3504 : ;
3505 :
3506 : /* old COPY option syntax */
3507 : copy_opt_list:
3508 504 : copy_opt_list copy_opt_item { $$ = lappend($1, $2); }
3509 11118 : | /* EMPTY */ { $$ = NIL; }
3510 : ;
3511 :
3512 : copy_opt_item:
3513 : BINARY
3514 : {
3515 0 : $$ = makeDefElem("format", (Node *) makeString("binary"), @1);
3516 : }
3517 : | FREEZE
3518 : {
3519 50 : $$ = makeDefElem("freeze", (Node *) makeBoolean(true), @1);
3520 : }
3521 : | DELIMITER opt_as Sconst
3522 : {
3523 172 : $$ = makeDefElem("delimiter", (Node *) makeString($3), @1);
3524 : }
3525 : | NULL_P opt_as Sconst
3526 : {
3527 48 : $$ = makeDefElem("null", (Node *) makeString($3), @1);
3528 : }
3529 : | CSV
3530 : {
3531 150 : $$ = makeDefElem("format", (Node *) makeString("csv"), @1);
3532 : }
3533 : | HEADER_P
3534 : {
3535 18 : $$ = makeDefElem("header", (Node *) makeBoolean(true), @1);
3536 : }
3537 : | QUOTE opt_as Sconst
3538 : {
3539 18 : $$ = makeDefElem("quote", (Node *) makeString($3), @1);
3540 : }
3541 : | ESCAPE opt_as Sconst
3542 : {
3543 18 : $$ = makeDefElem("escape", (Node *) makeString($3), @1);
3544 : }
3545 : | FORCE QUOTE columnList
3546 : {
3547 12 : $$ = makeDefElem("force_quote", (Node *) $3, @1);
3548 : }
3549 : | FORCE QUOTE '*'
3550 : {
3551 6 : $$ = makeDefElem("force_quote", (Node *) makeNode(A_Star), @1);
3552 : }
3553 : | FORCE NOT NULL_P columnList
3554 : {
3555 0 : $$ = makeDefElem("force_not_null", (Node *) $4, @1);
3556 : }
3557 : | FORCE NOT NULL_P '*'
3558 : {
3559 0 : $$ = makeDefElem("force_not_null", (Node *) makeNode(A_Star), @1);
3560 : }
3561 : | FORCE NULL_P columnList
3562 : {
3563 0 : $$ = makeDefElem("force_null", (Node *) $3, @1);
3564 : }
3565 : | FORCE NULL_P '*'
3566 : {
3567 0 : $$ = makeDefElem("force_null", (Node *) makeNode(A_Star), @1);
3568 : }
3569 : | ENCODING Sconst
3570 : {
3571 12 : $$ = makeDefElem("encoding", (Node *) makeString($2), @1);
3572 : }
3573 : ;
3574 :
3575 : /* The following exist for backward compatibility with very old versions */
3576 :
3577 : opt_binary:
3578 : BINARY
3579 : {
3580 12 : $$ = makeDefElem("format", (Node *) makeString("binary"), @1);
3581 : }
3582 11196 : | /*EMPTY*/ { $$ = NULL; }
3583 : ;
3584 :
3585 : copy_delimiter:
3586 : opt_using DELIMITERS Sconst
3587 : {
3588 0 : $$ = makeDefElem("delimiter", (Node *) makeString($3), @2);
3589 : }
3590 11208 : | /*EMPTY*/ { $$ = NULL; }
3591 : ;
3592 :
3593 : opt_using:
3594 : USING
3595 : | /*EMPTY*/
3596 : ;
3597 :
3598 : /* new COPY option syntax */
3599 : copy_generic_opt_list:
3600 : copy_generic_opt_elem
3601 : {
3602 698 : $$ = list_make1($1);
3603 : }
3604 : | copy_generic_opt_list ',' copy_generic_opt_elem
3605 : {
3606 468 : $$ = lappend($1, $3);
3607 : }
3608 : ;
3609 :
3610 : copy_generic_opt_elem:
3611 : ColLabel copy_generic_opt_arg
3612 : {
3613 1166 : $$ = makeDefElem($1, $2, @1);
3614 : }
3615 : ;
3616 :
3617 : copy_generic_opt_arg:
3618 818 : opt_boolean_or_string { $$ = (Node *) makeString($1); }
3619 60 : | NumericOnly { $$ = (Node *) $1; }
3620 90 : | '*' { $$ = (Node *) makeNode(A_Star); }
3621 6 : | DEFAULT { $$ = (Node *) makeString("default"); }
3622 150 : | '(' copy_generic_opt_arg_list ')' { $$ = (Node *) $2; }
3623 42 : | /* EMPTY */ { $$ = NULL; }
3624 : ;
3625 :
3626 : copy_generic_opt_arg_list:
3627 : copy_generic_opt_arg_list_item
3628 : {
3629 150 : $$ = list_make1($1);
3630 : }
3631 : | copy_generic_opt_arg_list ',' copy_generic_opt_arg_list_item
3632 : {
3633 12 : $$ = lappend($1, $3);
3634 : }
3635 : ;
3636 :
3637 : /* beware of emitting non-string list elements here; see commands/define.c */
3638 : copy_generic_opt_arg_list_item:
3639 162 : opt_boolean_or_string { $$ = (Node *) makeString($1); }
3640 : ;
3641 :
3642 :
3643 : /*****************************************************************************
3644 : *
3645 : * QUERY :
3646 : * CREATE TABLE relname
3647 : *
3648 : *****************************************************************************/
3649 :
3650 : CreateStmt: CREATE OptTemp TABLE qualified_name '(' OptTableElementList ')'
3651 : OptInherit OptPartitionSpec table_access_method_clause OptWith
3652 : OnCommitOption OptTableSpace
3653 : {
3654 29844 : CreateStmt *n = makeNode(CreateStmt);
3655 :
3656 29844 : $4->relpersistence = $2;
3657 29844 : n->relation = $4;
3658 29844 : n->tableElts = $6;
3659 29844 : n->inhRelations = $8;
3660 29844 : n->partspec = $9;
3661 29844 : n->ofTypename = NULL;
3662 29844 : n->constraints = NIL;
3663 29844 : n->accessMethod = $10;
3664 29844 : n->options = $11;
3665 29844 : n->oncommit = $12;
3666 29844 : n->tablespacename = $13;
3667 29844 : n->if_not_exists = false;
3668 29844 : $$ = (Node *) n;
3669 : }
3670 : | CREATE OptTemp TABLE IF_P NOT EXISTS qualified_name '('
3671 : OptTableElementList ')' OptInherit OptPartitionSpec table_access_method_clause
3672 : OptWith OnCommitOption OptTableSpace
3673 : {
3674 30 : CreateStmt *n = makeNode(CreateStmt);
3675 :
3676 30 : $7->relpersistence = $2;
3677 30 : n->relation = $7;
3678 30 : n->tableElts = $9;
3679 30 : n->inhRelations = $11;
3680 30 : n->partspec = $12;
3681 30 : n->ofTypename = NULL;
3682 30 : n->constraints = NIL;
3683 30 : n->accessMethod = $13;
3684 30 : n->options = $14;
3685 30 : n->oncommit = $15;
3686 30 : n->tablespacename = $16;
3687 30 : n->if_not_exists = true;
3688 30 : $$ = (Node *) n;
3689 : }
3690 : | CREATE OptTemp TABLE qualified_name OF any_name
3691 : OptTypedTableElementList OptPartitionSpec table_access_method_clause
3692 : OptWith OnCommitOption OptTableSpace
3693 : {
3694 122 : CreateStmt *n = makeNode(CreateStmt);
3695 :
3696 122 : $4->relpersistence = $2;
3697 122 : n->relation = $4;
3698 122 : n->tableElts = $7;
3699 122 : n->inhRelations = NIL;
3700 122 : n->partspec = $8;
3701 122 : n->ofTypename = makeTypeNameFromNameList($6);
3702 122 : n->ofTypename->location = @6;
3703 122 : n->constraints = NIL;
3704 122 : n->accessMethod = $9;
3705 122 : n->options = $10;
3706 122 : n->oncommit = $11;
3707 122 : n->tablespacename = $12;
3708 122 : n->if_not_exists = false;
3709 122 : $$ = (Node *) n;
3710 : }
3711 : | CREATE OptTemp TABLE IF_P NOT EXISTS qualified_name OF any_name
3712 : OptTypedTableElementList OptPartitionSpec table_access_method_clause
3713 : OptWith OnCommitOption OptTableSpace
3714 : {
3715 6 : CreateStmt *n = makeNode(CreateStmt);
3716 :
3717 6 : $7->relpersistence = $2;
3718 6 : n->relation = $7;
3719 6 : n->tableElts = $10;
3720 6 : n->inhRelations = NIL;
3721 6 : n->partspec = $11;
3722 6 : n->ofTypename = makeTypeNameFromNameList($9);
3723 6 : n->ofTypename->location = @9;
3724 6 : n->constraints = NIL;
3725 6 : n->accessMethod = $12;
3726 6 : n->options = $13;
3727 6 : n->oncommit = $14;
3728 6 : n->tablespacename = $15;
3729 6 : n->if_not_exists = true;
3730 6 : $$ = (Node *) n;
3731 : }
3732 : | CREATE OptTemp TABLE qualified_name PARTITION OF qualified_name
3733 : OptTypedTableElementList PartitionBoundSpec OptPartitionSpec
3734 : table_access_method_clause OptWith OnCommitOption OptTableSpace
3735 : {
3736 8016 : CreateStmt *n = makeNode(CreateStmt);
3737 :
3738 8016 : $4->relpersistence = $2;
3739 8016 : n->relation = $4;
3740 8016 : n->tableElts = $8;
3741 8016 : n->inhRelations = list_make1($7);
3742 8016 : n->partbound = $9;
3743 8016 : n->partspec = $10;
3744 8016 : n->ofTypename = NULL;
3745 8016 : n->constraints = NIL;
3746 8016 : n->accessMethod = $11;
3747 8016 : n->options = $12;
3748 8016 : n->oncommit = $13;
3749 8016 : n->tablespacename = $14;
3750 8016 : n->if_not_exists = false;
3751 8016 : $$ = (Node *) n;
3752 : }
3753 : | CREATE OptTemp TABLE IF_P NOT EXISTS qualified_name PARTITION OF
3754 : qualified_name OptTypedTableElementList PartitionBoundSpec OptPartitionSpec
3755 : table_access_method_clause OptWith OnCommitOption OptTableSpace
3756 : {
3757 0 : CreateStmt *n = makeNode(CreateStmt);
3758 :
3759 0 : $7->relpersistence = $2;
3760 0 : n->relation = $7;
3761 0 : n->tableElts = $11;
3762 0 : n->inhRelations = list_make1($10);
3763 0 : n->partbound = $12;
3764 0 : n->partspec = $13;
3765 0 : n->ofTypename = NULL;
3766 0 : n->constraints = NIL;
3767 0 : n->accessMethod = $14;
3768 0 : n->options = $15;
3769 0 : n->oncommit = $16;
3770 0 : n->tablespacename = $17;
3771 0 : n->if_not_exists = true;
3772 0 : $$ = (Node *) n;
3773 : }
3774 : ;
3775 :
3776 : /*
3777 : * Redundancy here is needed to avoid shift/reduce conflicts,
3778 : * since TEMP is not a reserved word. See also OptTempTableName.
3779 : *
3780 : * NOTE: we accept both GLOBAL and LOCAL options. They currently do nothing,
3781 : * but future versions might consider GLOBAL to request SQL-spec-compliant
3782 : * temp table behavior, so warn about that. Since we have no modules the
3783 : * LOCAL keyword is really meaningless; furthermore, some other products
3784 : * implement LOCAL as meaning the same as our default temp table behavior,
3785 : * so we'll probably continue to treat LOCAL as a noise word.
3786 : */
3787 346 : OptTemp: TEMPORARY { $$ = RELPERSISTENCE_TEMP; }
3788 2792 : | TEMP { $$ = RELPERSISTENCE_TEMP; }
3789 0 : | LOCAL TEMPORARY { $$ = RELPERSISTENCE_TEMP; }
3790 0 : | LOCAL TEMP { $$ = RELPERSISTENCE_TEMP; }
3791 : | GLOBAL TEMPORARY
3792 : {
3793 0 : ereport(WARNING,
3794 : (errmsg("GLOBAL is deprecated in temporary table creation"),
3795 : parser_errposition(@1)));
3796 0 : $$ = RELPERSISTENCE_TEMP;
3797 : }
3798 : | GLOBAL TEMP
3799 : {
3800 0 : ereport(WARNING,
3801 : (errmsg("GLOBAL is deprecated in temporary table creation"),
3802 : parser_errposition(@1)));
3803 0 : $$ = RELPERSISTENCE_TEMP;
3804 : }
3805 162 : | UNLOGGED { $$ = RELPERSISTENCE_UNLOGGED; }
3806 53856 : | /*EMPTY*/ { $$ = RELPERSISTENCE_PERMANENT; }
3807 : ;
3808 :
3809 : OptTableElementList:
3810 28656 : TableElementList { $$ = $1; }
3811 1656 : | /*EMPTY*/ { $$ = NIL; }
3812 : ;
3813 :
3814 : OptTypedTableElementList:
3815 358 : '(' TypedTableElementList ')' { $$ = $2; }
3816 7882 : | /*EMPTY*/ { $$ = NIL; }
3817 : ;
3818 :
3819 : TableElementList:
3820 : TableElement
3821 : {
3822 28710 : $$ = list_make1($1);
3823 : }
3824 : | TableElementList ',' TableElement
3825 : {
3826 40750 : $$ = lappend($1, $3);
3827 : }
3828 : ;
3829 :
3830 : TypedTableElementList:
3831 : TypedTableElement
3832 : {
3833 358 : $$ = list_make1($1);
3834 : }
3835 : | TypedTableElementList ',' TypedTableElement
3836 : {
3837 68 : $$ = lappend($1, $3);
3838 : }
3839 : ;
3840 :
3841 : TableElement:
3842 65924 : columnDef { $$ = $1; }
3843 774 : | TableLikeClause { $$ = $1; }
3844 2762 : | TableConstraint { $$ = $1; }
3845 : ;
3846 :
3847 : TypedTableElement:
3848 356 : columnOptions { $$ = $1; }
3849 70 : | TableConstraint { $$ = $1; }
3850 : ;
3851 :
3852 : columnDef: ColId Typename opt_column_storage opt_column_compression create_generic_options ColQualList
3853 : {
3854 68094 : ColumnDef *n = makeNode(ColumnDef);
3855 :
3856 68094 : n->colname = $1;
3857 68094 : n->typeName = $2;
3858 68094 : n->storage_name = $3;
3859 68094 : n->compression = $4;
3860 68094 : n->inhcount = 0;
3861 68094 : n->is_local = true;
3862 68094 : n->is_not_null = false;
3863 68094 : n->is_from_type = false;
3864 68094 : n->storage = 0;
3865 68094 : n->raw_default = NULL;
3866 68094 : n->cooked_default = NULL;
3867 68094 : n->collOid = InvalidOid;
3868 68094 : n->fdwoptions = $5;
3869 68094 : SplitColQualList($6, &n->constraints, &n->collClause,
3870 : yyscanner);
3871 68094 : n->location = @1;
3872 68094 : $$ = (Node *) n;
3873 : }
3874 : ;
3875 :
3876 : columnOptions: ColId ColQualList
3877 : {
3878 138 : ColumnDef *n = makeNode(ColumnDef);
3879 :
3880 138 : n->colname = $1;
3881 138 : n->typeName = NULL;
3882 138 : n->inhcount = 0;
3883 138 : n->is_local = true;
3884 138 : n->is_not_null = false;
3885 138 : n->is_from_type = false;
3886 138 : n->storage = 0;
3887 138 : n->raw_default = NULL;
3888 138 : n->cooked_default = NULL;
3889 138 : n->collOid = InvalidOid;
3890 138 : SplitColQualList($2, &n->constraints, &n->collClause,
3891 : yyscanner);
3892 138 : n->location = @1;
3893 138 : $$ = (Node *) n;
3894 : }
3895 : | ColId WITH OPTIONS ColQualList
3896 : {
3897 218 : ColumnDef *n = makeNode(ColumnDef);
3898 :
3899 218 : n->colname = $1;
3900 218 : n->typeName = NULL;
3901 218 : n->inhcount = 0;
3902 218 : n->is_local = true;
3903 218 : n->is_not_null = false;
3904 218 : n->is_from_type = false;
3905 218 : n->storage = 0;
3906 218 : n->raw_default = NULL;
3907 218 : n->cooked_default = NULL;
3908 218 : n->collOid = InvalidOid;
3909 218 : SplitColQualList($4, &n->constraints, &n->collClause,
3910 : yyscanner);
3911 218 : n->location = @1;
3912 218 : $$ = (Node *) n;
3913 : }
3914 : ;
3915 :
3916 : column_compression:
3917 166 : COMPRESSION ColId { $$ = $2; }
3918 6 : | COMPRESSION DEFAULT { $$ = pstrdup("default"); }
3919 : ;
3920 :
3921 : opt_column_compression:
3922 94 : column_compression { $$ = $1; }
3923 68066 : | /*EMPTY*/ { $$ = NULL; }
3924 : ;
3925 :
3926 : column_storage:
3927 258 : STORAGE ColId { $$ = $2; }
3928 6 : | STORAGE DEFAULT { $$ = pstrdup("default"); }
3929 : ;
3930 :
3931 : opt_column_storage:
3932 26 : column_storage { $$ = $1; }
3933 68134 : | /*EMPTY*/ { $$ = NULL; }
3934 : ;
3935 :
3936 : ColQualList:
3937 20136 : ColQualList ColConstraint { $$ = lappend($1, $2); }
3938 69968 : | /*EMPTY*/ { $$ = NIL; }
3939 : ;
3940 :
3941 : ColConstraint:
3942 : CONSTRAINT name ColConstraintElem
3943 : {
3944 802 : Constraint *n = castNode(Constraint, $3);
3945 :
3946 802 : n->conname = $2;
3947 802 : n->location = @1;
3948 802 : $$ = (Node *) n;
3949 : }
3950 18278 : | ColConstraintElem { $$ = $1; }
3951 294 : | ConstraintAttr { $$ = $1; }
3952 : | COLLATE any_name
3953 : {
3954 : /*
3955 : * Note: the CollateClause is momentarily included in
3956 : * the list built by ColQualList, but we split it out
3957 : * again in SplitColQualList.
3958 : */
3959 762 : CollateClause *n = makeNode(CollateClause);
3960 :
3961 762 : n->arg = NULL;
3962 762 : n->collname = $2;
3963 762 : n->location = @1;
3964 762 : $$ = (Node *) n;
3965 : }
3966 : ;
3967 :
3968 : /* DEFAULT NULL is already the default for Postgres.
3969 : * But define it here and carry it forward into the system
3970 : * to make it explicit.
3971 : * - thomas 1998-09-13
3972 : *
3973 : * WITH NULL and NULL are not SQL-standard syntax elements,
3974 : * so leave them out. Use DEFAULT NULL to explicitly indicate
3975 : * that a column may have that value. WITH NULL leads to
3976 : * shift/reduce conflicts with WITH TIME ZONE anyway.
3977 : * - thomas 1999-01-08
3978 : *
3979 : * DEFAULT expression must be b_expr not a_expr to prevent shift/reduce
3980 : * conflict on NOT (since NOT might start a subsequent NOT NULL constraint,
3981 : * or be part of a_expr NOT LIKE or similar constructs).
3982 : */
3983 : ColConstraintElem:
3984 : NOT NULL_P opt_no_inherit
3985 : {
3986 6884 : Constraint *n = makeNode(Constraint);
3987 :
3988 6884 : n->contype = CONSTR_NOTNULL;
3989 6884 : n->location = @1;
3990 6884 : n->is_no_inherit = $3;
3991 6884 : n->is_enforced = true;
3992 6884 : n->skip_validation = false;
3993 6884 : n->initially_valid = true;
3994 6884 : $$ = (Node *) n;
3995 : }
3996 : | NULL_P
3997 : {
3998 30 : Constraint *n = makeNode(Constraint);
3999 :
4000 30 : n->contype = CONSTR_NULL;
4001 30 : n->location = @1;
4002 30 : $$ = (Node *) n;
4003 : }
4004 : | UNIQUE opt_unique_null_treatment opt_definition OptConsTableSpace
4005 : {
4006 464 : Constraint *n = makeNode(Constraint);
4007 :
4008 464 : n->contype = CONSTR_UNIQUE;
4009 464 : n->location = @1;
4010 464 : n->nulls_not_distinct = !$2;
4011 464 : n->keys = NULL;
4012 464 : n->options = $3;
4013 464 : n->indexname = NULL;
4014 464 : n->indexspace = $4;
4015 464 : $$ = (Node *) n;
4016 : }
4017 : | PRIMARY KEY opt_definition OptConsTableSpace
4018 : {
4019 5864 : Constraint *n = makeNode(Constraint);
4020 :
4021 5864 : n->contype = CONSTR_PRIMARY;
4022 5864 : n->location = @1;
4023 5864 : n->keys = NULL;
4024 5864 : n->options = $3;
4025 5864 : n->indexname = NULL;
4026 5864 : n->indexspace = $4;
4027 5864 : $$ = (Node *) n;
4028 : }
4029 : | CHECK '(' a_expr ')' opt_no_inherit
4030 : {
4031 1086 : Constraint *n = makeNode(Constraint);
4032 :
4033 1086 : n->contype = CONSTR_CHECK;
4034 1086 : n->location = @1;
4035 1086 : n->is_no_inherit = $5;
4036 1086 : n->raw_expr = $3;
4037 1086 : n->cooked_expr = NULL;
4038 1086 : n->is_enforced = true;
4039 1086 : n->skip_validation = false;
4040 1086 : n->initially_valid = true;
4041 1086 : $$ = (Node *) n;
4042 : }
4043 : | DEFAULT b_expr
4044 : {
4045 1846 : Constraint *n = makeNode(Constraint);
4046 :
4047 1846 : n->contype = CONSTR_DEFAULT;
4048 1846 : n->location = @1;
4049 1846 : n->raw_expr = $2;
4050 1846 : n->cooked_expr = NULL;
4051 1846 : $$ = (Node *) n;
4052 : }
4053 : | GENERATED generated_when AS IDENTITY_P OptParenthesizedSeqOptList
4054 : {
4055 332 : Constraint *n = makeNode(Constraint);
4056 :
4057 332 : n->contype = CONSTR_IDENTITY;
4058 332 : n->generated_when = $2;
4059 332 : n->options = $5;
4060 332 : n->location = @1;
4061 332 : $$ = (Node *) n;
4062 : }
4063 : | GENERATED generated_when AS '(' a_expr ')' opt_virtual_or_stored
4064 : {
4065 1746 : Constraint *n = makeNode(Constraint);
4066 :
4067 1746 : n->contype = CONSTR_GENERATED;
4068 1746 : n->generated_when = $2;
4069 1746 : n->raw_expr = $5;
4070 1746 : n->cooked_expr = NULL;
4071 1746 : n->generated_kind = $7;
4072 1746 : n->location = @1;
4073 :
4074 : /*
4075 : * Can't do this in the grammar because of shift/reduce
4076 : * conflicts. (IDENTITY allows both ALWAYS and BY
4077 : * DEFAULT, but generated columns only allow ALWAYS.) We
4078 : * can also give a more useful error message and location.
4079 : */
4080 1746 : if ($2 != ATTRIBUTE_IDENTITY_ALWAYS)
4081 12 : ereport(ERROR,
4082 : (errcode(ERRCODE_SYNTAX_ERROR),
4083 : errmsg("for a generated column, GENERATED ALWAYS must be specified"),
4084 : parser_errposition(@2)));
4085 :
4086 1734 : $$ = (Node *) n;
4087 : }
4088 : | REFERENCES qualified_name opt_column_list key_match key_actions
4089 : {
4090 840 : Constraint *n = makeNode(Constraint);
4091 :
4092 840 : n->contype = CONSTR_FOREIGN;
4093 840 : n->location = @1;
4094 840 : n->pktable = $2;
4095 840 : n->fk_attrs = NIL;
4096 840 : n->pk_attrs = $3;
4097 840 : n->fk_matchtype = $4;
4098 840 : n->fk_upd_action = ($5)->updateAction->action;
4099 840 : n->fk_del_action = ($5)->deleteAction->action;
4100 840 : n->fk_del_set_cols = ($5)->deleteAction->cols;
4101 840 : n->is_enforced = true;
4102 840 : n->skip_validation = false;
4103 840 : n->initially_valid = true;
4104 840 : $$ = (Node *) n;
4105 : }
4106 : ;
4107 :
4108 : opt_unique_null_treatment:
4109 12 : NULLS_P DISTINCT { $$ = true; }
4110 36 : | NULLS_P NOT DISTINCT { $$ = false; }
4111 7718 : | /*EMPTY*/ { $$ = true; }
4112 : ;
4113 :
4114 : generated_when:
4115 2106 : ALWAYS { $$ = ATTRIBUTE_IDENTITY_ALWAYS; }
4116 182 : | BY DEFAULT { $$ = ATTRIBUTE_IDENTITY_BY_DEFAULT; }
4117 : ;
4118 :
4119 : opt_virtual_or_stored:
4120 998 : STORED { $$ = ATTRIBUTE_GENERATED_STORED; }
4121 640 : | VIRTUAL { $$ = ATTRIBUTE_GENERATED_VIRTUAL; }
4122 108 : | /*EMPTY*/ { $$ = ATTRIBUTE_GENERATED_VIRTUAL; }
4123 : ;
4124 :
4125 : /*
4126 : * ConstraintAttr represents constraint attributes, which we parse as if
4127 : * they were independent constraint clauses, in order to avoid shift/reduce
4128 : * conflicts (since NOT might start either an independent NOT NULL clause
4129 : * or an attribute). parse_utilcmd.c is responsible for attaching the
4130 : * attribute information to the preceding "real" constraint node, and for
4131 : * complaining if attribute clauses appear in the wrong place or wrong
4132 : * combinations.
4133 : *
4134 : * See also ConstraintAttributeSpec, which can be used in places where
4135 : * there is no parsing conflict. (Note: currently, NOT VALID and NO INHERIT
4136 : * are allowed clauses in ConstraintAttributeSpec, but not here. Someday we
4137 : * might need to allow them here too, but for the moment it doesn't seem
4138 : * useful in the statements that use ConstraintAttr.)
4139 : */
4140 : ConstraintAttr:
4141 : DEFERRABLE
4142 : {
4143 102 : Constraint *n = makeNode(Constraint);
4144 :
4145 102 : n->contype = CONSTR_ATTR_DEFERRABLE;
4146 102 : n->location = @1;
4147 102 : $$ = (Node *) n;
4148 : }
4149 : | NOT DEFERRABLE
4150 : {
4151 0 : Constraint *n = makeNode(Constraint);
4152 :
4153 0 : n->contype = CONSTR_ATTR_NOT_DEFERRABLE;
4154 0 : n->location = @1;
4155 0 : $$ = (Node *) n;
4156 : }
4157 : | INITIALLY DEFERRED
4158 : {
4159 78 : Constraint *n = makeNode(Constraint);
4160 :
4161 78 : n->contype = CONSTR_ATTR_DEFERRED;
4162 78 : n->location = @1;
4163 78 : $$ = (Node *) n;
4164 : }
4165 : | INITIALLY IMMEDIATE
4166 : {
4167 6 : Constraint *n = makeNode(Constraint);
4168 :
4169 6 : n->contype = CONSTR_ATTR_IMMEDIATE;
4170 6 : n->location = @1;
4171 6 : $$ = (Node *) n;
4172 : }
4173 : | ENFORCED
4174 : {
4175 42 : Constraint *n = makeNode(Constraint);
4176 :
4177 42 : n->contype = CONSTR_ATTR_ENFORCED;
4178 42 : n->location = @1;
4179 42 : $$ = (Node *) n;
4180 : }
4181 : | NOT ENFORCED
4182 : {
4183 66 : Constraint *n = makeNode(Constraint);
4184 :
4185 66 : n->contype = CONSTR_ATTR_NOT_ENFORCED;
4186 66 : n->location = @1;
4187 66 : $$ = (Node *) n;
4188 : }
4189 : ;
4190 :
4191 :
4192 : TableLikeClause:
4193 : LIKE qualified_name TableLikeOptionList
4194 : {
4195 774 : TableLikeClause *n = makeNode(TableLikeClause);
4196 :
4197 774 : n->relation = $2;
4198 774 : n->options = $3;
4199 774 : n->relationOid = InvalidOid;
4200 774 : $$ = (Node *) n;
4201 : }
4202 : ;
4203 :
4204 : TableLikeOptionList:
4205 288 : TableLikeOptionList INCLUDING TableLikeOption { $$ = $1 | $3; }
4206 8 : | TableLikeOptionList EXCLUDING TableLikeOption { $$ = $1 & ~$3; }
4207 774 : | /* EMPTY */ { $$ = 0; }
4208 : ;
4209 :
4210 : TableLikeOption:
4211 30 : COMMENTS { $$ = CREATE_TABLE_LIKE_COMMENTS; }
4212 6 : | COMPRESSION { $$ = CREATE_TABLE_LIKE_COMPRESSION; }
4213 54 : | CONSTRAINTS { $$ = CREATE_TABLE_LIKE_CONSTRAINTS; }
4214 20 : | DEFAULTS { $$ = CREATE_TABLE_LIKE_DEFAULTS; }
4215 12 : | IDENTITY_P { $$ = CREATE_TABLE_LIKE_IDENTITY; }
4216 30 : | GENERATED { $$ = CREATE_TABLE_LIKE_GENERATED; }
4217 50 : | INDEXES { $$ = CREATE_TABLE_LIKE_INDEXES; }
4218 0 : | STATISTICS { $$ = CREATE_TABLE_LIKE_STATISTICS; }
4219 26 : | STORAGE { $$ = CREATE_TABLE_LIKE_STORAGE; }
4220 68 : | ALL { $$ = CREATE_TABLE_LIKE_ALL; }
4221 : ;
4222 :
4223 :
4224 : /* ConstraintElem specifies constraint syntax which is not embedded into
4225 : * a column definition. ColConstraintElem specifies the embedded form.
4226 : * - thomas 1997-12-03
4227 : */
4228 : TableConstraint:
4229 : CONSTRAINT name ConstraintElem
4230 : {
4231 4108 : Constraint *n = castNode(Constraint, $3);
4232 :
4233 4108 : n->conname = $2;
4234 4108 : n->location = @1;
4235 4108 : $$ = (Node *) n;
4236 : }
4237 13284 : | ConstraintElem { $$ = $1; }
4238 : ;
4239 :
4240 : ConstraintElem:
4241 : CHECK '(' a_expr ')' ConstraintAttributeSpec
4242 : {
4243 1278 : Constraint *n = makeNode(Constraint);
4244 :
4245 1278 : n->contype = CONSTR_CHECK;
4246 1278 : n->location = @1;
4247 1278 : n->raw_expr = $3;
4248 1278 : n->cooked_expr = NULL;
4249 1278 : processCASbits($5, @5, "CHECK",
4250 : NULL, NULL, &n->is_enforced, &n->skip_validation,
4251 : &n->is_no_inherit, yyscanner);
4252 1278 : n->initially_valid = !n->skip_validation;
4253 1278 : $$ = (Node *) n;
4254 : }
4255 : | NOT NULL_P ColId ConstraintAttributeSpec
4256 : {
4257 598 : Constraint *n = makeNode(Constraint);
4258 :
4259 598 : n->contype = CONSTR_NOTNULL;
4260 598 : n->location = @1;
4261 598 : n->keys = list_make1(makeString($3));
4262 598 : processCASbits($4, @4, "NOT NULL",
4263 : NULL, NULL, NULL, &n->skip_validation,
4264 : &n->is_no_inherit, yyscanner);
4265 598 : n->initially_valid = !n->skip_validation;
4266 598 : $$ = (Node *) n;
4267 : }
4268 : | UNIQUE opt_unique_null_treatment '(' columnList opt_without_overlaps ')' opt_c_include opt_definition OptConsTableSpace
4269 : ConstraintAttributeSpec
4270 : {
4271 598 : Constraint *n = makeNode(Constraint);
4272 :
4273 598 : n->contype = CONSTR_UNIQUE;
4274 598 : n->location = @1;
4275 598 : n->nulls_not_distinct = !$2;
4276 598 : n->keys = $4;
4277 598 : n->without_overlaps = $5;
4278 598 : n->including = $7;
4279 598 : n->options = $8;
4280 598 : n->indexname = NULL;
4281 598 : n->indexspace = $9;
4282 598 : processCASbits($10, @10, "UNIQUE",
4283 : &n->deferrable, &n->initdeferred, NULL,
4284 : NULL, NULL, yyscanner);
4285 598 : $$ = (Node *) n;
4286 : }
4287 : | UNIQUE ExistingIndex ConstraintAttributeSpec
4288 : {
4289 4648 : Constraint *n = makeNode(Constraint);
4290 :
4291 4648 : n->contype = CONSTR_UNIQUE;
4292 4648 : n->location = @1;
4293 4648 : n->keys = NIL;
4294 4648 : n->including = NIL;
4295 4648 : n->options = NIL;
4296 4648 : n->indexname = $2;
4297 4648 : n->indexspace = NULL;
4298 4648 : processCASbits($3, @3, "UNIQUE",
4299 : &n->deferrable, &n->initdeferred, NULL,
4300 : NULL, NULL, yyscanner);
4301 4648 : $$ = (Node *) n;
4302 : }
4303 : | PRIMARY KEY '(' columnList opt_without_overlaps ')' opt_c_include opt_definition OptConsTableSpace
4304 : ConstraintAttributeSpec
4305 : {
4306 2174 : Constraint *n = makeNode(Constraint);
4307 :
4308 2174 : n->contype = CONSTR_PRIMARY;
4309 2174 : n->location = @1;
4310 2174 : n->keys = $4;
4311 2174 : n->without_overlaps = $5;
4312 2174 : n->including = $7;
4313 2174 : n->options = $8;
4314 2174 : n->indexname = NULL;
4315 2174 : n->indexspace = $9;
4316 2174 : processCASbits($10, @10, "PRIMARY KEY",
4317 : &n->deferrable, &n->initdeferred, NULL,
4318 : NULL, NULL, yyscanner);
4319 2174 : $$ = (Node *) n;
4320 : }
4321 : | PRIMARY KEY ExistingIndex ConstraintAttributeSpec
4322 : {
4323 6018 : Constraint *n = makeNode(Constraint);
4324 :
4325 6018 : n->contype = CONSTR_PRIMARY;
4326 6018 : n->location = @1;
4327 6018 : n->keys = NIL;
4328 6018 : n->including = NIL;
4329 6018 : n->options = NIL;
4330 6018 : n->indexname = $3;
4331 6018 : n->indexspace = NULL;
4332 6018 : processCASbits($4, @4, "PRIMARY KEY",
4333 : &n->deferrable, &n->initdeferred, NULL,
4334 : NULL, NULL, yyscanner);
4335 6018 : $$ = (Node *) n;
4336 : }
4337 : | EXCLUDE access_method_clause '(' ExclusionConstraintList ')'
4338 : opt_c_include opt_definition OptConsTableSpace OptWhereClause
4339 : ConstraintAttributeSpec
4340 : {
4341 234 : Constraint *n = makeNode(Constraint);
4342 :
4343 234 : n->contype = CONSTR_EXCLUSION;
4344 234 : n->location = @1;
4345 234 : n->access_method = $2;
4346 234 : n->exclusions = $4;
4347 234 : n->including = $6;
4348 234 : n->options = $7;
4349 234 : n->indexname = NULL;
4350 234 : n->indexspace = $8;
4351 234 : n->where_clause = $9;
4352 234 : processCASbits($10, @10, "EXCLUDE",
4353 : &n->deferrable, &n->initdeferred, NULL,
4354 : NULL, NULL, yyscanner);
4355 234 : $$ = (Node *) n;
4356 : }
4357 : | FOREIGN KEY '(' columnList optionalPeriodName ')' REFERENCES qualified_name
4358 : opt_column_and_period_list key_match key_actions ConstraintAttributeSpec
4359 : {
4360 1844 : Constraint *n = makeNode(Constraint);
4361 :
4362 1844 : n->contype = CONSTR_FOREIGN;
4363 1844 : n->location = @1;
4364 1844 : n->pktable = $8;
4365 1844 : n->fk_attrs = $4;
4366 1844 : if ($5)
4367 : {
4368 326 : n->fk_attrs = lappend(n->fk_attrs, $5);
4369 326 : n->fk_with_period = true;
4370 : }
4371 1844 : n->pk_attrs = linitial($9);
4372 1844 : if (lsecond($9))
4373 : {
4374 170 : n->pk_attrs = lappend(n->pk_attrs, lsecond($9));
4375 170 : n->pk_with_period = true;
4376 : }
4377 1844 : n->fk_matchtype = $10;
4378 1844 : n->fk_upd_action = ($11)->updateAction->action;
4379 1844 : n->fk_del_action = ($11)->deleteAction->action;
4380 1844 : n->fk_del_set_cols = ($11)->deleteAction->cols;
4381 1844 : processCASbits($12, @12, "FOREIGN KEY",
4382 : &n->deferrable, &n->initdeferred,
4383 : &n->is_enforced, &n->skip_validation, NULL,
4384 : yyscanner);
4385 1844 : n->initially_valid = !n->skip_validation;
4386 1844 : $$ = (Node *) n;
4387 : }
4388 : ;
4389 :
4390 : /*
4391 : * DomainConstraint is separate from TableConstraint because the syntax for
4392 : * NOT NULL constraints is different. For table constraints, we need to
4393 : * accept a column name, but for domain constraints, we don't. (We could
4394 : * accept something like NOT NULL VALUE, but that seems weird.) CREATE DOMAIN
4395 : * (which uses ColQualList) has for a long time accepted NOT NULL without a
4396 : * column name, so it makes sense that ALTER DOMAIN (which uses
4397 : * DomainConstraint) does as well. None of these syntaxes are per SQL
4398 : * standard; we are just living with the bits of inconsistency that have built
4399 : * up over time.
4400 : */
4401 : DomainConstraint:
4402 : CONSTRAINT name DomainConstraintElem
4403 : {
4404 164 : Constraint *n = castNode(Constraint, $3);
4405 :
4406 164 : n->conname = $2;
4407 164 : n->location = @1;
4408 164 : $$ = (Node *) n;
4409 : }
4410 18 : | DomainConstraintElem { $$ = $1; }
4411 : ;
4412 :
4413 : DomainConstraintElem:
4414 : CHECK '(' a_expr ')' ConstraintAttributeSpec
4415 : {
4416 164 : Constraint *n = makeNode(Constraint);
4417 :
4418 164 : n->contype = CONSTR_CHECK;
4419 164 : n->location = @1;
4420 164 : n->raw_expr = $3;
4421 164 : n->cooked_expr = NULL;
4422 164 : processCASbits($5, @5, "CHECK",
4423 : NULL, NULL, NULL, &n->skip_validation,
4424 : &n->is_no_inherit, yyscanner);
4425 152 : n->is_enforced = true;
4426 152 : n->initially_valid = !n->skip_validation;
4427 152 : $$ = (Node *) n;
4428 : }
4429 : | NOT NULL_P ConstraintAttributeSpec
4430 : {
4431 30 : Constraint *n = makeNode(Constraint);
4432 :
4433 30 : n->contype = CONSTR_NOTNULL;
4434 30 : n->location = @1;
4435 30 : n->keys = list_make1(makeString("value"));
4436 : /* no NOT VALID, NO INHERIT support */
4437 30 : processCASbits($3, @3, "NOT NULL",
4438 : NULL, NULL, NULL,
4439 : NULL, NULL, yyscanner);
4440 30 : n->initially_valid = true;
4441 30 : $$ = (Node *) n;
4442 : }
4443 : ;
4444 :
4445 138 : opt_no_inherit: NO INHERIT { $$ = true; }
4446 7832 : | /* EMPTY */ { $$ = false; }
4447 : ;
4448 :
4449 : opt_without_overlaps:
4450 590 : WITHOUT OVERLAPS { $$ = true; }
4451 2182 : | /*EMPTY*/ { $$ = false; }
4452 : ;
4453 :
4454 : opt_column_list:
4455 10740 : '(' columnList ')' { $$ = $2; }
4456 42700 : | /*EMPTY*/ { $$ = NIL; }
4457 : ;
4458 :
4459 : columnList:
4460 17050 : columnElem { $$ = list_make1($1); }
4461 29010 : | columnList ',' columnElem { $$ = lappend($1, $3); }
4462 : ;
4463 :
4464 : optionalPeriodName:
4465 496 : ',' PERIOD columnElem { $$ = $3; }
4466 2478 : | /*EMPTY*/ { $$ = NULL; }
4467 : ;
4468 :
4469 : opt_column_and_period_list:
4470 1124 : '(' columnList optionalPeriodName ')' { $$ = list_make2($2, $3); }
4471 726 : | /*EMPTY*/ { $$ = list_make2(NIL, NULL); }
4472 : ;
4473 :
4474 : columnElem: ColId
4475 : {
4476 46556 : $$ = (Node *) makeString($1);
4477 : }
4478 : ;
4479 :
4480 168 : opt_c_include: INCLUDE '(' columnList ')' { $$ = $3; }
4481 2838 : | /* EMPTY */ { $$ = NIL; }
4482 : ;
4483 :
4484 : key_match: MATCH FULL
4485 : {
4486 98 : $$ = FKCONSTR_MATCH_FULL;
4487 : }
4488 : | MATCH PARTIAL
4489 : {
4490 0 : ereport(ERROR,
4491 : (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
4492 : errmsg("MATCH PARTIAL not yet implemented"),
4493 : parser_errposition(@1)));
4494 : $$ = FKCONSTR_MATCH_PARTIAL;
4495 : }
4496 : | MATCH SIMPLE
4497 : {
4498 6 : $$ = FKCONSTR_MATCH_SIMPLE;
4499 : }
4500 : | /*EMPTY*/
4501 : {
4502 2586 : $$ = FKCONSTR_MATCH_SIMPLE;
4503 : }
4504 : ;
4505 :
4506 : ExclusionConstraintList:
4507 234 : ExclusionConstraintElem { $$ = list_make1($1); }
4508 : | ExclusionConstraintList ',' ExclusionConstraintElem
4509 106 : { $$ = lappend($1, $3); }
4510 : ;
4511 :
4512 : ExclusionConstraintElem: index_elem WITH any_operator
4513 : {
4514 340 : $$ = list_make2($1, $3);
4515 : }
4516 : /* allow OPERATOR() decoration for the benefit of ruleutils.c */
4517 : | index_elem WITH OPERATOR '(' any_operator ')'
4518 : {
4519 0 : $$ = list_make2($1, $5);
4520 : }
4521 : ;
4522 :
4523 : OptWhereClause:
4524 464 : WHERE '(' a_expr ')' { $$ = $3; }
4525 1264 : | /*EMPTY*/ { $$ = NULL; }
4526 : ;
4527 :
4528 : key_actions:
4529 : key_update
4530 : {
4531 74 : KeyActions *n = palloc(sizeof(KeyActions));
4532 :
4533 74 : n->updateAction = $1;
4534 74 : n->deleteAction = palloc(sizeof(KeyAction));
4535 74 : n->deleteAction->action = FKCONSTR_ACTION_NOACTION;
4536 74 : n->deleteAction->cols = NIL;
4537 74 : $$ = n;
4538 : }
4539 : | key_delete
4540 : {
4541 150 : KeyActions *n = palloc(sizeof(KeyActions));
4542 :
4543 150 : n->updateAction = palloc(sizeof(KeyAction));
4544 150 : n->updateAction->action = FKCONSTR_ACTION_NOACTION;
4545 150 : n->updateAction->cols = NIL;
4546 150 : n->deleteAction = $1;
4547 150 : $$ = n;
4548 : }
4549 : | key_update key_delete
4550 : {
4551 156 : KeyActions *n = palloc(sizeof(KeyActions));
4552 :
4553 156 : n->updateAction = $1;
4554 156 : n->deleteAction = $2;
4555 156 : $$ = n;
4556 : }
4557 : | key_delete key_update
4558 : {
4559 150 : KeyActions *n = palloc(sizeof(KeyActions));
4560 :
4561 150 : n->updateAction = $2;
4562 150 : n->deleteAction = $1;
4563 150 : $$ = n;
4564 : }
4565 : | /*EMPTY*/
4566 : {
4567 2154 : KeyActions *n = palloc(sizeof(KeyActions));
4568 :
4569 2154 : n->updateAction = palloc(sizeof(KeyAction));
4570 2154 : n->updateAction->action = FKCONSTR_ACTION_NOACTION;
4571 2154 : n->updateAction->cols = NIL;
4572 2154 : n->deleteAction = palloc(sizeof(KeyAction));
4573 2154 : n->deleteAction->action = FKCONSTR_ACTION_NOACTION;
4574 2154 : n->deleteAction->cols = NIL;
4575 2154 : $$ = n;
4576 : }
4577 : ;
4578 :
4579 : key_update: ON UPDATE key_action
4580 : {
4581 386 : if (($3)->cols)
4582 6 : ereport(ERROR,
4583 : (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
4584 : errmsg("a column list with %s is only supported for ON DELETE actions",
4585 : ($3)->action == FKCONSTR_ACTION_SETNULL ? "SET NULL" : "SET DEFAULT"),
4586 : parser_errposition(@1)));
4587 380 : $$ = $3;
4588 : }
4589 : ;
4590 :
4591 : key_delete: ON DELETE_P key_action
4592 : {
4593 456 : $$ = $3;
4594 : }
4595 : ;
4596 :
4597 : key_action:
4598 : NO ACTION
4599 : {
4600 80 : KeyAction *n = palloc(sizeof(KeyAction));
4601 :
4602 80 : n->action = FKCONSTR_ACTION_NOACTION;
4603 80 : n->cols = NIL;
4604 80 : $$ = n;
4605 : }
4606 : | RESTRICT
4607 : {
4608 48 : KeyAction *n = palloc(sizeof(KeyAction));
4609 :
4610 48 : n->action = FKCONSTR_ACTION_RESTRICT;
4611 48 : n->cols = NIL;
4612 48 : $$ = n;
4613 : }
4614 : | CASCADE
4615 : {
4616 422 : KeyAction *n = palloc(sizeof(KeyAction));
4617 :
4618 422 : n->action = FKCONSTR_ACTION_CASCADE;
4619 422 : n->cols = NIL;
4620 422 : $$ = n;
4621 : }
4622 : | SET NULL_P opt_column_list
4623 : {
4624 190 : KeyAction *n = palloc(sizeof(KeyAction));
4625 :
4626 190 : n->action = FKCONSTR_ACTION_SETNULL;
4627 190 : n->cols = $3;
4628 190 : $$ = n;
4629 : }
4630 : | SET DEFAULT opt_column_list
4631 : {
4632 102 : KeyAction *n = palloc(sizeof(KeyAction));
4633 :
4634 102 : n->action = FKCONSTR_ACTION_SETDEFAULT;
4635 102 : n->cols = $3;
4636 102 : $$ = n;
4637 : }
4638 : ;
4639 :
4640 2120 : OptInherit: INHERITS '(' qualified_name_list ')' { $$ = $3; }
4641 28174 : | /*EMPTY*/ { $$ = NIL; }
4642 : ;
4643 :
4644 : /* Optional partition key specification */
4645 5048 : OptPartitionSpec: PartitionSpec { $$ = $1; }
4646 32982 : | /*EMPTY*/ { $$ = NULL; }
4647 : ;
4648 :
4649 : PartitionSpec: PARTITION BY ColId '(' part_params ')'
4650 : {
4651 5054 : PartitionSpec *n = makeNode(PartitionSpec);
4652 :
4653 5054 : n->strategy = parsePartitionStrategy($3, @3, yyscanner);
4654 5048 : n->partParams = $5;
4655 5048 : n->location = @1;
4656 :
4657 5048 : $$ = n;
4658 : }
4659 : ;
4660 :
4661 5054 : part_params: part_elem { $$ = list_make1($1); }
4662 456 : | part_params ',' part_elem { $$ = lappend($1, $3); }
4663 : ;
4664 :
4665 : part_elem: ColId opt_collate opt_qualified_name
4666 : {
4667 5206 : PartitionElem *n = makeNode(PartitionElem);
4668 :
4669 5206 : n->name = $1;
4670 5206 : n->expr = NULL;
4671 5206 : n->collation = $2;
4672 5206 : n->opclass = $3;
4673 5206 : n->location = @1;
4674 5206 : $$ = n;
4675 : }
4676 : | func_expr_windowless opt_collate opt_qualified_name
4677 : {
4678 130 : PartitionElem *n = makeNode(PartitionElem);
4679 :
4680 130 : n->name = NULL;
4681 130 : n->expr = $1;
4682 130 : n->collation = $2;
4683 130 : n->opclass = $3;
4684 130 : n->location = @1;
4685 130 : $$ = n;
4686 : }
4687 : | '(' a_expr ')' opt_collate opt_qualified_name
4688 : {
4689 174 : PartitionElem *n = makeNode(PartitionElem);
4690 :
4691 174 : n->name = NULL;
4692 174 : n->expr = $2;
4693 174 : n->collation = $4;
4694 174 : n->opclass = $5;
4695 174 : n->location = @1;
4696 174 : $$ = n;
4697 : }
4698 : ;
4699 :
4700 : table_access_method_clause:
4701 122 : USING name { $$ = $2; }
4702 39846 : | /*EMPTY*/ { $$ = NULL; }
4703 : ;
4704 :
4705 : /* WITHOUT OIDS is legacy only */
4706 : OptWith:
4707 754 : WITH reloptions { $$ = $2; }
4708 24 : | WITHOUT OIDS { $$ = NIL; }
4709 38602 : | /*EMPTY*/ { $$ = NIL; }
4710 : ;
4711 :
4712 60 : OnCommitOption: ON COMMIT DROP { $$ = ONCOMMIT_DROP; }
4713 104 : | ON COMMIT DELETE_P ROWS { $$ = ONCOMMIT_DELETE_ROWS; }
4714 24 : | ON COMMIT PRESERVE ROWS { $$ = ONCOMMIT_PRESERVE_ROWS; }
4715 39192 : | /*EMPTY*/ { $$ = ONCOMMIT_NOOP; }
4716 : ;
4717 :
4718 216 : OptTableSpace: TABLESPACE name { $$ = $2; }
4719 46450 : | /*EMPTY*/ { $$ = NULL; }
4720 : ;
4721 :
4722 66 : OptConsTableSpace: USING INDEX TABLESPACE name { $$ = $4; }
4723 9268 : | /*EMPTY*/ { $$ = NULL; }
4724 : ;
4725 :
4726 10666 : ExistingIndex: USING INDEX name { $$ = $3; }
4727 : ;
4728 :
4729 : /*****************************************************************************
4730 : *
4731 : * QUERY :
4732 : * CREATE STATISTICS [[IF NOT EXISTS] stats_name] [(stat types)]
4733 : * ON expression-list FROM from_list
4734 : *
4735 : * Note: the expectation here is that the clauses after ON are a subset of
4736 : * SELECT syntax, allowing for expressions and joined tables, and probably
4737 : * someday a WHERE clause. Much less than that is currently implemented,
4738 : * but the grammar accepts it and then we'll throw FEATURE_NOT_SUPPORTED
4739 : * errors as necessary at execution.
4740 : *
4741 : * Statistics name is optional unless IF NOT EXISTS is specified.
4742 : *
4743 : *****************************************************************************/
4744 :
4745 : CreateStatsStmt:
4746 : CREATE STATISTICS opt_qualified_name
4747 : opt_name_list ON stats_params FROM from_list
4748 : {
4749 736 : CreateStatsStmt *n = makeNode(CreateStatsStmt);
4750 :
4751 736 : n->defnames = $3;
4752 736 : n->stat_types = $4;
4753 736 : n->exprs = $6;
4754 736 : n->relations = $8;
4755 736 : n->stxcomment = NULL;
4756 736 : n->if_not_exists = false;
4757 736 : $$ = (Node *) n;
4758 : }
4759 : | CREATE STATISTICS IF_P NOT EXISTS any_name
4760 : opt_name_list ON stats_params FROM from_list
4761 : {
4762 12 : CreateStatsStmt *n = makeNode(CreateStatsStmt);
4763 :
4764 12 : n->defnames = $6;
4765 12 : n->stat_types = $7;
4766 12 : n->exprs = $9;
4767 12 : n->relations = $11;
4768 12 : n->stxcomment = NULL;
4769 12 : n->if_not_exists = true;
4770 12 : $$ = (Node *) n;
4771 : }
4772 : ;
4773 :
4774 : /*
4775 : * Statistics attributes can be either simple column references, or arbitrary
4776 : * expressions in parens. For compatibility with index attributes permitted
4777 : * in CREATE INDEX, we allow an expression that's just a function call to be
4778 : * written without parens.
4779 : */
4780 :
4781 760 : stats_params: stats_param { $$ = list_make1($1); }
4782 978 : | stats_params ',' stats_param { $$ = lappend($1, $3); }
4783 : ;
4784 :
4785 : stats_param: ColId
4786 : {
4787 1228 : $$ = makeNode(StatsElem);
4788 1228 : $$->name = $1;
4789 1228 : $$->expr = NULL;
4790 : }
4791 : | func_expr_windowless
4792 : {
4793 38 : $$ = makeNode(StatsElem);
4794 38 : $$->name = NULL;
4795 38 : $$->expr = $1;
4796 : }
4797 : | '(' a_expr ')'
4798 : {
4799 472 : $$ = makeNode(StatsElem);
4800 472 : $$->name = NULL;
4801 472 : $$->expr = $2;
4802 : }
4803 : ;
4804 :
4805 : /*****************************************************************************
4806 : *
4807 : * QUERY :
4808 : * ALTER STATISTICS [IF EXISTS] stats_name
4809 : * SET STATISTICS <SignedIconst>
4810 : *
4811 : *****************************************************************************/
4812 :
4813 : AlterStatsStmt:
4814 : ALTER STATISTICS any_name SET STATISTICS set_statistics_value
4815 : {
4816 20 : AlterStatsStmt *n = makeNode(AlterStatsStmt);
4817 :
4818 20 : n->defnames = $3;
4819 20 : n->missing_ok = false;
4820 20 : n->stxstattarget = $6;
4821 20 : $$ = (Node *) n;
4822 : }
4823 : | ALTER STATISTICS IF_P EXISTS any_name SET STATISTICS set_statistics_value
4824 : {
4825 6 : AlterStatsStmt *n = makeNode(AlterStatsStmt);
4826 :
4827 6 : n->defnames = $5;
4828 6 : n->missing_ok = true;
4829 6 : n->stxstattarget = $8;
4830 6 : $$ = (Node *) n;
4831 : }
4832 : ;
4833 :
4834 : /*****************************************************************************
4835 : *
4836 : * QUERY :
4837 : * CREATE TABLE relname AS SelectStmt [ WITH [NO] DATA ]
4838 : *
4839 : *
4840 : * Note: SELECT ... INTO is a now-deprecated alternative for this.
4841 : *
4842 : *****************************************************************************/
4843 :
4844 : CreateAsStmt:
4845 : CREATE OptTemp TABLE create_as_target AS SelectStmt opt_with_data
4846 : {
4847 1222 : CreateTableAsStmt *ctas = makeNode(CreateTableAsStmt);
4848 :
4849 1222 : ctas->query = $6;
4850 1222 : ctas->into = $4;
4851 1222 : ctas->objtype = OBJECT_TABLE;
4852 1222 : ctas->is_select_into = false;
4853 1222 : ctas->if_not_exists = false;
4854 : /* cram additional flags into the IntoClause */
4855 1222 : $4->rel->relpersistence = $2;
4856 1222 : $4->skipData = !($7);
4857 1222 : $$ = (Node *) ctas;
4858 : }
4859 : | CREATE OptTemp TABLE IF_P NOT EXISTS create_as_target AS SelectStmt opt_with_data
4860 : {
4861 52 : CreateTableAsStmt *ctas = makeNode(CreateTableAsStmt);
4862 :
4863 52 : ctas->query = $9;
4864 52 : ctas->into = $7;
4865 52 : ctas->objtype = OBJECT_TABLE;
4866 52 : ctas->is_select_into = false;
4867 52 : ctas->if_not_exists = true;
4868 : /* cram additional flags into the IntoClause */
4869 52 : $7->rel->relpersistence = $2;
4870 52 : $7->skipData = !($10);
4871 52 : $$ = (Node *) ctas;
4872 : }
4873 : ;
4874 :
4875 : create_as_target:
4876 : qualified_name opt_column_list table_access_method_clause
4877 : OptWith OnCommitOption OptTableSpace
4878 : {
4879 1362 : $$ = makeNode(IntoClause);
4880 1362 : $$->rel = $1;
4881 1362 : $$->colNames = $2;
4882 1362 : $$->accessMethod = $3;
4883 1362 : $$->options = $4;
4884 1362 : $$->onCommit = $5;
4885 1362 : $$->tableSpaceName = $6;
4886 1362 : $$->viewQuery = NULL;
4887 1362 : $$->skipData = false; /* might get changed later */
4888 : }
4889 : ;
4890 :
4891 : opt_with_data:
4892 36 : WITH DATA_P { $$ = true; }
4893 218 : | WITH NO DATA_P { $$ = false; }
4894 1958 : | /*EMPTY*/ { $$ = true; }
4895 : ;
4896 :
4897 :
4898 : /*****************************************************************************
4899 : *
4900 : * QUERY :
4901 : * CREATE MATERIALIZED VIEW relname AS SelectStmt
4902 : *
4903 : *****************************************************************************/
4904 :
4905 : CreateMatViewStmt:
4906 : CREATE OptNoLog MATERIALIZED VIEW create_mv_target AS SelectStmt opt_with_data
4907 : {
4908 534 : CreateTableAsStmt *ctas = makeNode(CreateTableAsStmt);
4909 :
4910 534 : ctas->query = $7;
4911 534 : ctas->into = $5;
4912 534 : ctas->objtype = OBJECT_MATVIEW;
4913 534 : ctas->is_select_into = false;
4914 534 : ctas->if_not_exists = false;
4915 : /* cram additional flags into the IntoClause */
4916 534 : $5->rel->relpersistence = $2;
4917 534 : $5->skipData = !($8);
4918 534 : $$ = (Node *) ctas;
4919 : }
4920 : | CREATE OptNoLog MATERIALIZED VIEW IF_P NOT EXISTS create_mv_target AS SelectStmt opt_with_data
4921 : {
4922 48 : CreateTableAsStmt *ctas = makeNode(CreateTableAsStmt);
4923 :
4924 48 : ctas->query = $10;
4925 48 : ctas->into = $8;
4926 48 : ctas->objtype = OBJECT_MATVIEW;
4927 48 : ctas->is_select_into = false;
4928 48 : ctas->if_not_exists = true;
4929 : /* cram additional flags into the IntoClause */
4930 48 : $8->rel->relpersistence = $2;
4931 48 : $8->skipData = !($11);
4932 48 : $$ = (Node *) ctas;
4933 : }
4934 : ;
4935 :
4936 : create_mv_target:
4937 : qualified_name opt_column_list table_access_method_clause opt_reloptions OptTableSpace
4938 : {
4939 582 : $$ = makeNode(IntoClause);
4940 582 : $$->rel = $1;
4941 582 : $$->colNames = $2;
4942 582 : $$->accessMethod = $3;
4943 582 : $$->options = $4;
4944 582 : $$->onCommit = ONCOMMIT_NOOP;
4945 582 : $$->tableSpaceName = $5;
4946 582 : $$->viewQuery = NULL; /* filled at analysis time */
4947 582 : $$->skipData = false; /* might get changed later */
4948 : }
4949 : ;
4950 :
4951 0 : OptNoLog: UNLOGGED { $$ = RELPERSISTENCE_UNLOGGED; }
4952 582 : | /*EMPTY*/ { $$ = RELPERSISTENCE_PERMANENT; }
4953 : ;
4954 :
4955 :
4956 : /*****************************************************************************
4957 : *
4958 : * QUERY :
4959 : * REFRESH MATERIALIZED VIEW qualified_name
4960 : *
4961 : *****************************************************************************/
4962 :
4963 : RefreshMatViewStmt:
4964 : REFRESH MATERIALIZED VIEW opt_concurrently qualified_name opt_with_data
4965 : {
4966 268 : RefreshMatViewStmt *n = makeNode(RefreshMatViewStmt);
4967 :
4968 268 : n->concurrent = $4;
4969 268 : n->relation = $5;
4970 268 : n->skipData = !($6);
4971 268 : $$ = (Node *) n;
4972 : }
4973 : ;
4974 :
4975 :
4976 : /*****************************************************************************
4977 : *
4978 : * QUERY :
4979 : * CREATE SEQUENCE seqname
4980 : * ALTER SEQUENCE seqname
4981 : *
4982 : *****************************************************************************/
4983 :
4984 : CreateSeqStmt:
4985 : CREATE OptTemp SEQUENCE qualified_name OptSeqOptList
4986 : {
4987 656 : CreateSeqStmt *n = makeNode(CreateSeqStmt);
4988 :
4989 656 : $4->relpersistence = $2;
4990 656 : n->sequence = $4;
4991 656 : n->options = $5;
4992 656 : n->ownerId = InvalidOid;
4993 656 : n->if_not_exists = false;
4994 656 : $$ = (Node *) n;
4995 : }
4996 : | CREATE OptTemp SEQUENCE IF_P NOT EXISTS qualified_name OptSeqOptList
4997 : {
4998 24 : CreateSeqStmt *n = makeNode(CreateSeqStmt);
4999 :
5000 24 : $7->relpersistence = $2;
5001 24 : n->sequence = $7;
5002 24 : n->options = $8;
5003 24 : n->ownerId = InvalidOid;
5004 24 : n->if_not_exists = true;
5005 24 : $$ = (Node *) n;
5006 : }
5007 : ;
5008 :
5009 : AlterSeqStmt:
5010 : ALTER SEQUENCE qualified_name SeqOptList
5011 : {
5012 184 : AlterSeqStmt *n = makeNode(AlterSeqStmt);
5013 :
5014 184 : n->sequence = $3;
5015 184 : n->options = $4;
5016 184 : n->missing_ok = false;
5017 184 : $$ = (Node *) n;
5018 : }
5019 : | ALTER SEQUENCE IF_P EXISTS qualified_name SeqOptList
5020 : {
5021 12 : AlterSeqStmt *n = makeNode(AlterSeqStmt);
5022 :
5023 12 : n->sequence = $5;
5024 12 : n->options = $6;
5025 12 : n->missing_ok = true;
5026 12 : $$ = (Node *) n;
5027 : }
5028 :
5029 : ;
5030 :
5031 262 : OptSeqOptList: SeqOptList { $$ = $1; }
5032 418 : | /*EMPTY*/ { $$ = NIL; }
5033 : ;
5034 :
5035 74 : OptParenthesizedSeqOptList: '(' SeqOptList ')' { $$ = $2; }
5036 424 : | /*EMPTY*/ { $$ = NIL; }
5037 : ;
5038 :
5039 532 : SeqOptList: SeqOptElem { $$ = list_make1($1); }
5040 802 : | SeqOptList SeqOptElem { $$ = lappend($1, $2); }
5041 : ;
5042 :
5043 : SeqOptElem: AS SimpleTypename
5044 : {
5045 190 : $$ = makeDefElem("as", (Node *) $2, @1);
5046 : }
5047 : | CACHE NumericOnly
5048 : {
5049 130 : $$ = makeDefElem("cache", (Node *) $2, @1);
5050 : }
5051 : | CYCLE
5052 : {
5053 34 : $$ = makeDefElem("cycle", (Node *) makeBoolean(true), @1);
5054 : }
5055 : | NO CYCLE
5056 : {
5057 14 : $$ = makeDefElem("cycle", (Node *) makeBoolean(false), @1);
5058 : }
5059 : | INCREMENT opt_by NumericOnly
5060 : {
5061 246 : $$ = makeDefElem("increment", (Node *) $3, @1);
5062 : }
5063 : | LOGGED
5064 : {
5065 2 : $$ = makeDefElem("logged", NULL, @1);
5066 : }
5067 : | MAXVALUE NumericOnly
5068 : {
5069 68 : $$ = makeDefElem("maxvalue", (Node *) $2, @1);
5070 : }
5071 : | MINVALUE NumericOnly
5072 : {
5073 68 : $$ = makeDefElem("minvalue", (Node *) $2, @1);
5074 : }
5075 : | NO MAXVALUE
5076 : {
5077 108 : $$ = makeDefElem("maxvalue", NULL, @1);
5078 : }
5079 : | NO MINVALUE
5080 : {
5081 108 : $$ = makeDefElem("minvalue", NULL, @1);
5082 : }
5083 : | OWNED BY any_name
5084 : {
5085 72 : $$ = makeDefElem("owned_by", (Node *) $3, @1);
5086 : }
5087 : | SEQUENCE NAME_P any_name
5088 : {
5089 44 : $$ = makeDefElem("sequence_name", (Node *) $3, @1);
5090 : }
5091 : | START opt_with NumericOnly
5092 : {
5093 236 : $$ = makeDefElem("start", (Node *) $3, @1);
5094 : }
5095 : | RESTART
5096 : {
5097 6 : $$ = makeDefElem("restart", NULL, @1);
5098 : }
5099 : | RESTART opt_with NumericOnly
5100 : {
5101 60 : $$ = makeDefElem("restart", (Node *) $3, @1);
5102 : }
5103 : | UNLOGGED
5104 : {
5105 2 : $$ = makeDefElem("unlogged", NULL, @1);
5106 : }
5107 : ;
5108 :
5109 : opt_by: BY
5110 : | /* EMPTY */
5111 : ;
5112 :
5113 : NumericOnly:
5114 324 : FCONST { $$ = (Node *) makeFloat($1); }
5115 0 : | '+' FCONST { $$ = (Node *) makeFloat($2); }
5116 : | '-' FCONST
5117 : {
5118 20 : Float *f = makeFloat($2);
5119 :
5120 20 : doNegateFloat(f);
5121 20 : $$ = (Node *) f;
5122 : }
5123 12922 : | SignedIconst { $$ = (Node *) makeInteger($1); }
5124 : ;
5125 :
5126 90 : NumericOnly_list: NumericOnly { $$ = list_make1($1); }
5127 6 : | NumericOnly_list ',' NumericOnly { $$ = lappend($1, $3); }
5128 : ;
5129 :
5130 : /*****************************************************************************
5131 : *
5132 : * QUERIES :
5133 : * CREATE [OR REPLACE] [TRUSTED] [PROCEDURAL] LANGUAGE ...
5134 : * DROP [PROCEDURAL] LANGUAGE ...
5135 : *
5136 : *****************************************************************************/
5137 :
5138 : CreatePLangStmt:
5139 : CREATE opt_or_replace opt_trusted opt_procedural LANGUAGE name
5140 : {
5141 : /*
5142 : * We now interpret parameterless CREATE LANGUAGE as
5143 : * CREATE EXTENSION. "OR REPLACE" is silently translated
5144 : * to "IF NOT EXISTS", which isn't quite the same, but
5145 : * seems more useful than throwing an error. We just
5146 : * ignore TRUSTED, as the previous code would have too.
5147 : */
5148 0 : CreateExtensionStmt *n = makeNode(CreateExtensionStmt);
5149 :
5150 0 : n->if_not_exists = $2;
5151 0 : n->extname = $6;
5152 0 : n->options = NIL;
5153 0 : $$ = (Node *) n;
5154 : }
5155 : | CREATE opt_or_replace opt_trusted opt_procedural LANGUAGE name
5156 : HANDLER handler_name opt_inline_handler opt_validator
5157 : {
5158 142 : CreatePLangStmt *n = makeNode(CreatePLangStmt);
5159 :
5160 142 : n->replace = $2;
5161 142 : n->plname = $6;
5162 142 : n->plhandler = $8;
5163 142 : n->plinline = $9;
5164 142 : n->plvalidator = $10;
5165 142 : n->pltrusted = $3;
5166 142 : $$ = (Node *) n;
5167 : }
5168 : ;
5169 :
5170 : opt_trusted:
5171 112 : TRUSTED { $$ = true; }
5172 38 : | /*EMPTY*/ { $$ = false; }
5173 : ;
5174 :
5175 : /* This ought to be just func_name, but that causes reduce/reduce conflicts
5176 : * (CREATE LANGUAGE is the only place where func_name isn't followed by '(').
5177 : * Work around by using simple names, instead.
5178 : */
5179 : handler_name:
5180 554 : name { $$ = list_make1(makeString($1)); }
5181 2 : | name attrs { $$ = lcons(makeString($1), $2); }
5182 : ;
5183 :
5184 : opt_inline_handler:
5185 124 : INLINE_P handler_name { $$ = $2; }
5186 18 : | /*EMPTY*/ { $$ = NIL; }
5187 : ;
5188 :
5189 : validator_clause:
5190 124 : VALIDATOR handler_name { $$ = $2; }
5191 0 : | NO VALIDATOR { $$ = NIL; }
5192 : ;
5193 :
5194 : opt_validator:
5195 124 : validator_clause { $$ = $1; }
5196 18 : | /*EMPTY*/ { $$ = NIL; }
5197 : ;
5198 :
5199 : opt_procedural:
5200 : PROCEDURAL
5201 : | /*EMPTY*/
5202 : ;
5203 :
5204 : /*****************************************************************************
5205 : *
5206 : * QUERY:
5207 : * CREATE TABLESPACE tablespace LOCATION '/path/to/tablespace/'
5208 : *
5209 : *****************************************************************************/
5210 :
5211 : CreateTableSpaceStmt: CREATE TABLESPACE name OptTableSpaceOwner LOCATION Sconst opt_reloptions
5212 : {
5213 130 : CreateTableSpaceStmt *n = makeNode(CreateTableSpaceStmt);
5214 :
5215 130 : n->tablespacename = $3;
5216 130 : n->owner = $4;
5217 130 : n->location = $6;
5218 130 : n->options = $7;
5219 130 : $$ = (Node *) n;
5220 : }
5221 : ;
5222 :
5223 10 : OptTableSpaceOwner: OWNER RoleSpec { $$ = $2; }
5224 120 : | /*EMPTY */ { $$ = NULL; }
5225 : ;
5226 :
5227 : /*****************************************************************************
5228 : *
5229 : * QUERY :
5230 : * DROP TABLESPACE <tablespace>
5231 : *
5232 : * No need for drop behaviour as we cannot implement dependencies for
5233 : * objects in other databases; we can only support RESTRICT.
5234 : *
5235 : ****************************************************************************/
5236 :
5237 : DropTableSpaceStmt: DROP TABLESPACE name
5238 : {
5239 64 : DropTableSpaceStmt *n = makeNode(DropTableSpaceStmt);
5240 :
5241 64 : n->tablespacename = $3;
5242 64 : n->missing_ok = false;
5243 64 : $$ = (Node *) n;
5244 : }
5245 : | DROP TABLESPACE IF_P EXISTS name
5246 : {
5247 0 : DropTableSpaceStmt *n = makeNode(DropTableSpaceStmt);
5248 :
5249 0 : n->tablespacename = $5;
5250 0 : n->missing_ok = true;
5251 0 : $$ = (Node *) n;
5252 : }
5253 : ;
5254 :
5255 : /*****************************************************************************
5256 : *
5257 : * QUERY:
5258 : * CREATE EXTENSION extension
5259 : * [ WITH ] [ SCHEMA schema ] [ VERSION version ]
5260 : *
5261 : *****************************************************************************/
5262 :
5263 : CreateExtensionStmt: CREATE EXTENSION name opt_with create_extension_opt_list
5264 : {
5265 540 : CreateExtensionStmt *n = makeNode(CreateExtensionStmt);
5266 :
5267 540 : n->extname = $3;
5268 540 : n->if_not_exists = false;
5269 540 : n->options = $5;
5270 540 : $$ = (Node *) n;
5271 : }
5272 : | CREATE EXTENSION IF_P NOT EXISTS name opt_with create_extension_opt_list
5273 : {
5274 18 : CreateExtensionStmt *n = makeNode(CreateExtensionStmt);
5275 :
5276 18 : n->extname = $6;
5277 18 : n->if_not_exists = true;
5278 18 : n->options = $8;
5279 18 : $$ = (Node *) n;
5280 : }
5281 : ;
5282 :
5283 : create_extension_opt_list:
5284 : create_extension_opt_list create_extension_opt_item
5285 98 : { $$ = lappend($1, $2); }
5286 : | /* EMPTY */
5287 558 : { $$ = NIL; }
5288 : ;
5289 :
5290 : create_extension_opt_item:
5291 : SCHEMA name
5292 : {
5293 46 : $$ = makeDefElem("schema", (Node *) makeString($2), @1);
5294 : }
5295 : | VERSION_P NonReservedWord_or_Sconst
5296 : {
5297 12 : $$ = makeDefElem("new_version", (Node *) makeString($2), @1);
5298 : }
5299 : | FROM NonReservedWord_or_Sconst
5300 : {
5301 0 : ereport(ERROR,
5302 : (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
5303 : errmsg("CREATE EXTENSION ... FROM is no longer supported"),
5304 : parser_errposition(@1)));
5305 : }
5306 : | CASCADE
5307 : {
5308 40 : $$ = makeDefElem("cascade", (Node *) makeBoolean(true), @1);
5309 : }
5310 : ;
5311 :
5312 : /*****************************************************************************
5313 : *
5314 : * ALTER EXTENSION name UPDATE [ TO version ]
5315 : *
5316 : *****************************************************************************/
5317 :
5318 : AlterExtensionStmt: ALTER EXTENSION name UPDATE alter_extension_opt_list
5319 : {
5320 40 : AlterExtensionStmt *n = makeNode(AlterExtensionStmt);
5321 :
5322 40 : n->extname = $3;
5323 40 : n->options = $5;
5324 40 : $$ = (Node *) n;
5325 : }
5326 : ;
5327 :
5328 : alter_extension_opt_list:
5329 : alter_extension_opt_list alter_extension_opt_item
5330 40 : { $$ = lappend($1, $2); }
5331 : | /* EMPTY */
5332 40 : { $$ = NIL; }
5333 : ;
5334 :
5335 : alter_extension_opt_item:
5336 : TO NonReservedWord_or_Sconst
5337 : {
5338 40 : $$ = makeDefElem("new_version", (Node *) makeString($2), @1);
5339 : }
5340 : ;
5341 :
5342 : /*****************************************************************************
5343 : *
5344 : * ALTER EXTENSION name ADD/DROP object-identifier
5345 : *
5346 : *****************************************************************************/
5347 :
5348 : AlterExtensionContentsStmt:
5349 : ALTER EXTENSION name add_drop object_type_name name
5350 : {
5351 18 : AlterExtensionContentsStmt *n = makeNode(AlterExtensionContentsStmt);
5352 :
5353 18 : n->extname = $3;
5354 18 : n->action = $4;
5355 18 : n->objtype = $5;
5356 18 : n->object = (Node *) makeString($6);
5357 18 : $$ = (Node *) n;
5358 : }
5359 : | ALTER EXTENSION name add_drop object_type_any_name any_name
5360 : {
5361 88 : AlterExtensionContentsStmt *n = makeNode(AlterExtensionContentsStmt);
5362 :
5363 88 : n->extname = $3;
5364 88 : n->action = $4;
5365 88 : n->objtype = $5;
5366 88 : n->object = (Node *) $6;
5367 88 : $$ = (Node *) n;
5368 : }
5369 : | ALTER EXTENSION name add_drop AGGREGATE aggregate_with_argtypes
5370 : {
5371 8 : AlterExtensionContentsStmt *n = makeNode(AlterExtensionContentsStmt);
5372 :
5373 8 : n->extname = $3;
5374 8 : n->action = $4;
5375 8 : n->objtype = OBJECT_AGGREGATE;
5376 8 : n->object = (Node *) $6;
5377 8 : $$ = (Node *) n;
5378 : }
5379 : | ALTER EXTENSION name add_drop CAST '(' Typename AS Typename ')'
5380 : {
5381 4 : AlterExtensionContentsStmt *n = makeNode(AlterExtensionContentsStmt);
5382 :
5383 4 : n->extname = $3;
5384 4 : n->action = $4;
5385 4 : n->objtype = OBJECT_CAST;
5386 4 : n->object = (Node *) list_make2($7, $9);
5387 4 : $$ = (Node *) n;
5388 : }
5389 : | ALTER EXTENSION name add_drop DOMAIN_P Typename
5390 : {
5391 0 : AlterExtensionContentsStmt *n = makeNode(AlterExtensionContentsStmt);
5392 :
5393 0 : n->extname = $3;
5394 0 : n->action = $4;
5395 0 : n->objtype = OBJECT_DOMAIN;
5396 0 : n->object = (Node *) $6;
5397 0 : $$ = (Node *) n;
5398 : }
5399 : | ALTER EXTENSION name add_drop FUNCTION function_with_argtypes
5400 : {
5401 118 : AlterExtensionContentsStmt *n = makeNode(AlterExtensionContentsStmt);
5402 :
5403 118 : n->extname = $3;
5404 118 : n->action = $4;
5405 118 : n->objtype = OBJECT_FUNCTION;
5406 118 : n->object = (Node *) $6;
5407 118 : $$ = (Node *) n;
5408 : }
5409 : | ALTER EXTENSION name add_drop OPERATOR operator_with_argtypes
5410 : {
5411 18 : AlterExtensionContentsStmt *n = makeNode(AlterExtensionContentsStmt);
5412 :
5413 18 : n->extname = $3;
5414 18 : n->action = $4;
5415 18 : n->objtype = OBJECT_OPERATOR;
5416 18 : n->object = (Node *) $6;
5417 18 : $$ = (Node *) n;
5418 : }
5419 : | ALTER EXTENSION name add_drop OPERATOR CLASS any_name USING name
5420 : {
5421 4 : AlterExtensionContentsStmt *n = makeNode(AlterExtensionContentsStmt);
5422 :
5423 4 : n->extname = $3;
5424 4 : n->action = $4;
5425 4 : n->objtype = OBJECT_OPCLASS;
5426 4 : n->object = (Node *) lcons(makeString($9), $7);
5427 4 : $$ = (Node *) n;
5428 : }
5429 : | ALTER EXTENSION name add_drop OPERATOR FAMILY any_name USING name
5430 : {
5431 4 : AlterExtensionContentsStmt *n = makeNode(AlterExtensionContentsStmt);
5432 :
5433 4 : n->extname = $3;
5434 4 : n->action = $4;
5435 4 : n->objtype = OBJECT_OPFAMILY;
5436 4 : n->object = (Node *) lcons(makeString($9), $7);
5437 4 : $$ = (Node *) n;
5438 : }
5439 : | ALTER EXTENSION name add_drop PROCEDURE function_with_argtypes
5440 : {
5441 0 : AlterExtensionContentsStmt *n = makeNode(AlterExtensionContentsStmt);
5442 :
5443 0 : n->extname = $3;
5444 0 : n->action = $4;
5445 0 : n->objtype = OBJECT_PROCEDURE;
5446 0 : n->object = (Node *) $6;
5447 0 : $$ = (Node *) n;
5448 : }
5449 : | ALTER EXTENSION name add_drop ROUTINE function_with_argtypes
5450 : {
5451 0 : AlterExtensionContentsStmt *n = makeNode(AlterExtensionContentsStmt);
5452 :
5453 0 : n->extname = $3;
5454 0 : n->action = $4;
5455 0 : n->objtype = OBJECT_ROUTINE;
5456 0 : n->object = (Node *) $6;
5457 0 : $$ = (Node *) n;
5458 : }
5459 : | ALTER EXTENSION name add_drop TRANSFORM FOR Typename LANGUAGE name
5460 : {
5461 4 : AlterExtensionContentsStmt *n = makeNode(AlterExtensionContentsStmt);
5462 :
5463 4 : n->extname = $3;
5464 4 : n->action = $4;
5465 4 : n->objtype = OBJECT_TRANSFORM;
5466 4 : n->object = (Node *) list_make2($7, makeString($9));
5467 4 : $$ = (Node *) n;
5468 : }
5469 : | ALTER EXTENSION name add_drop TYPE_P Typename
5470 : {
5471 8 : AlterExtensionContentsStmt *n = makeNode(AlterExtensionContentsStmt);
5472 :
5473 8 : n->extname = $3;
5474 8 : n->action = $4;
5475 8 : n->objtype = OBJECT_TYPE;
5476 8 : n->object = (Node *) $6;
5477 8 : $$ = (Node *) n;
5478 : }
5479 : ;
5480 :
5481 : /*****************************************************************************
5482 : *
5483 : * QUERY:
5484 : * CREATE FOREIGN DATA WRAPPER name options
5485 : *
5486 : *****************************************************************************/
5487 :
5488 : CreateFdwStmt: CREATE FOREIGN DATA_P WRAPPER name opt_fdw_options create_generic_options
5489 : {
5490 206 : CreateFdwStmt *n = makeNode(CreateFdwStmt);
5491 :
5492 206 : n->fdwname = $5;
5493 206 : n->func_options = $6;
5494 206 : n->options = $7;
5495 206 : $$ = (Node *) n;
5496 : }
5497 : ;
5498 :
5499 : fdw_option:
5500 56 : HANDLER handler_name { $$ = makeDefElem("handler", (Node *) $2, @1); }
5501 0 : | NO HANDLER { $$ = makeDefElem("handler", NULL, @1); }
5502 48 : | VALIDATOR handler_name { $$ = makeDefElem("validator", (Node *) $2, @1); }
5503 6 : | NO VALIDATOR { $$ = makeDefElem("validator", NULL, @1); }
5504 : ;
5505 :
5506 : fdw_options:
5507 90 : fdw_option { $$ = list_make1($1); }
5508 20 : | fdw_options fdw_option { $$ = lappend($1, $2); }
5509 : ;
5510 :
5511 : opt_fdw_options:
5512 54 : fdw_options { $$ = $1; }
5513 244 : | /*EMPTY*/ { $$ = NIL; }
5514 : ;
5515 :
5516 : /*****************************************************************************
5517 : *
5518 : * QUERY :
5519 : * ALTER FOREIGN DATA WRAPPER name options
5520 : *
5521 : ****************************************************************************/
5522 :
5523 : AlterFdwStmt: ALTER FOREIGN DATA_P WRAPPER name opt_fdw_options alter_generic_options
5524 : {
5525 86 : AlterFdwStmt *n = makeNode(AlterFdwStmt);
5526 :
5527 86 : n->fdwname = $5;
5528 86 : n->func_options = $6;
5529 86 : n->options = $7;
5530 86 : $$ = (Node *) n;
5531 : }
5532 : | ALTER FOREIGN DATA_P WRAPPER name fdw_options
5533 : {
5534 36 : AlterFdwStmt *n = makeNode(AlterFdwStmt);
5535 :
5536 36 : n->fdwname = $5;
5537 36 : n->func_options = $6;
5538 36 : n->options = NIL;
5539 36 : $$ = (Node *) n;
5540 : }
5541 : ;
5542 :
5543 : /* Options definition for CREATE FDW, SERVER and USER MAPPING */
5544 : create_generic_options:
5545 740 : OPTIONS '(' generic_option_list ')' { $$ = $3; }
5546 68708 : | /*EMPTY*/ { $$ = NIL; }
5547 : ;
5548 :
5549 : generic_option_list:
5550 : generic_option_elem
5551 : {
5552 740 : $$ = list_make1($1);
5553 : }
5554 : | generic_option_list ',' generic_option_elem
5555 : {
5556 480 : $$ = lappend($1, $3);
5557 : }
5558 : ;
5559 :
5560 : /* Options definition for ALTER FDW, SERVER and USER MAPPING */
5561 : alter_generic_options:
5562 508 : OPTIONS '(' alter_generic_option_list ')' { $$ = $3; }
5563 : ;
5564 :
5565 : alter_generic_option_list:
5566 : alter_generic_option_elem
5567 : {
5568 508 : $$ = list_make1($1);
5569 : }
5570 : | alter_generic_option_list ',' alter_generic_option_elem
5571 : {
5572 168 : $$ = lappend($1, $3);
5573 : }
5574 : ;
5575 :
5576 : alter_generic_option_elem:
5577 : generic_option_elem
5578 : {
5579 200 : $$ = $1;
5580 : }
5581 : | SET generic_option_elem
5582 : {
5583 128 : $$ = $2;
5584 128 : $$->defaction = DEFELEM_SET;
5585 : }
5586 : | ADD_P generic_option_elem
5587 : {
5588 220 : $$ = $2;
5589 220 : $$->defaction = DEFELEM_ADD;
5590 : }
5591 : | DROP generic_option_name
5592 : {
5593 128 : $$ = makeDefElemExtended(NULL, $2, NULL, DEFELEM_DROP, @2);
5594 : }
5595 : ;
5596 :
5597 : generic_option_elem:
5598 : generic_option_name generic_option_arg
5599 : {
5600 1768 : $$ = makeDefElem($1, $2, @1);
5601 : }
5602 : ;
5603 :
5604 : generic_option_name:
5605 1896 : ColLabel { $$ = $1; }
5606 : ;
5607 :
5608 : /* We could use def_arg here, but the spec only requires string literals */
5609 : generic_option_arg:
5610 1768 : Sconst { $$ = (Node *) makeString($1); }
5611 : ;
5612 :
5613 : /*****************************************************************************
5614 : *
5615 : * QUERY:
5616 : * CREATE SERVER name [TYPE] [VERSION] [OPTIONS]
5617 : *
5618 : *****************************************************************************/
5619 :
5620 : CreateForeignServerStmt: CREATE SERVER name opt_type opt_foreign_server_version
5621 : FOREIGN DATA_P WRAPPER name create_generic_options
5622 : {
5623 272 : CreateForeignServerStmt *n = makeNode(CreateForeignServerStmt);
5624 :
5625 272 : n->servername = $3;
5626 272 : n->servertype = $4;
5627 272 : n->version = $5;
5628 272 : n->fdwname = $9;
5629 272 : n->options = $10;
5630 272 : n->if_not_exists = false;
5631 272 : $$ = (Node *) n;
5632 : }
5633 : | CREATE SERVER IF_P NOT EXISTS name opt_type opt_foreign_server_version
5634 : FOREIGN DATA_P WRAPPER name create_generic_options
5635 : {
5636 24 : CreateForeignServerStmt *n = makeNode(CreateForeignServerStmt);
5637 :
5638 24 : n->servername = $6;
5639 24 : n->servertype = $7;
5640 24 : n->version = $8;
5641 24 : n->fdwname = $12;
5642 24 : n->options = $13;
5643 24 : n->if_not_exists = true;
5644 24 : $$ = (Node *) n;
5645 : }
5646 : ;
5647 :
5648 : opt_type:
5649 18 : TYPE_P Sconst { $$ = $2; }
5650 278 : | /*EMPTY*/ { $$ = NULL; }
5651 : ;
5652 :
5653 :
5654 : foreign_server_version:
5655 66 : VERSION_P Sconst { $$ = $2; }
5656 0 : | VERSION_P NULL_P { $$ = NULL; }
5657 : ;
5658 :
5659 : opt_foreign_server_version:
5660 18 : foreign_server_version { $$ = $1; }
5661 278 : | /*EMPTY*/ { $$ = NULL; }
5662 : ;
5663 :
5664 : /*****************************************************************************
5665 : *
5666 : * QUERY :
5667 : * ALTER SERVER name [VERSION] [OPTIONS]
5668 : *
5669 : ****************************************************************************/
5670 :
5671 : AlterForeignServerStmt: ALTER SERVER name foreign_server_version alter_generic_options
5672 : {
5673 6 : AlterForeignServerStmt *n = makeNode(AlterForeignServerStmt);
5674 :
5675 6 : n->servername = $3;
5676 6 : n->version = $4;
5677 6 : n->options = $5;
5678 6 : n->has_version = true;
5679 6 : $$ = (Node *) n;
5680 : }
5681 : | ALTER SERVER name foreign_server_version
5682 : {
5683 42 : AlterForeignServerStmt *n = makeNode(AlterForeignServerStmt);
5684 :
5685 42 : n->servername = $3;
5686 42 : n->version = $4;
5687 42 : n->has_version = true;
5688 42 : $$ = (Node *) n;
5689 : }
5690 : | ALTER SERVER name alter_generic_options
5691 : {
5692 184 : AlterForeignServerStmt *n = makeNode(AlterForeignServerStmt);
5693 :
5694 184 : n->servername = $3;
5695 184 : n->options = $4;
5696 184 : $$ = (Node *) n;
5697 : }
5698 : ;
5699 :
5700 : /*****************************************************************************
5701 : *
5702 : * QUERY:
5703 : * CREATE FOREIGN TABLE relname (...) SERVER name (...)
5704 : *
5705 : *****************************************************************************/
5706 :
5707 : CreateForeignTableStmt:
5708 : CREATE FOREIGN TABLE qualified_name
5709 : '(' OptTableElementList ')'
5710 : OptInherit SERVER name create_generic_options
5711 : {
5712 396 : CreateForeignTableStmt *n = makeNode(CreateForeignTableStmt);
5713 :
5714 396 : $4->relpersistence = RELPERSISTENCE_PERMANENT;
5715 396 : n->base.relation = $4;
5716 396 : n->base.tableElts = $6;
5717 396 : n->base.inhRelations = $8;
5718 396 : n->base.ofTypename = NULL;
5719 396 : n->base.constraints = NIL;
5720 396 : n->base.options = NIL;
5721 396 : n->base.oncommit = ONCOMMIT_NOOP;
5722 396 : n->base.tablespacename = NULL;
5723 396 : n->base.if_not_exists = false;
5724 : /* FDW-specific data */
5725 396 : n->servername = $10;
5726 396 : n->options = $11;
5727 396 : $$ = (Node *) n;
5728 : }
5729 : | CREATE FOREIGN TABLE IF_P NOT EXISTS qualified_name
5730 : '(' OptTableElementList ')'
5731 : OptInherit SERVER name create_generic_options
5732 : {
5733 0 : CreateForeignTableStmt *n = makeNode(CreateForeignTableStmt);
5734 :
5735 0 : $7->relpersistence = RELPERSISTENCE_PERMANENT;
5736 0 : n->base.relation = $7;
5737 0 : n->base.tableElts = $9;
5738 0 : n->base.inhRelations = $11;
5739 0 : n->base.ofTypename = NULL;
5740 0 : n->base.constraints = NIL;
5741 0 : n->base.options = NIL;
5742 0 : n->base.oncommit = ONCOMMIT_NOOP;
5743 0 : n->base.tablespacename = NULL;
5744 0 : n->base.if_not_exists = true;
5745 : /* FDW-specific data */
5746 0 : n->servername = $13;
5747 0 : n->options = $14;
5748 0 : $$ = (Node *) n;
5749 : }
5750 : | CREATE FOREIGN TABLE qualified_name
5751 : PARTITION OF qualified_name OptTypedTableElementList PartitionBoundSpec
5752 : SERVER name create_generic_options
5753 : {
5754 90 : CreateForeignTableStmt *n = makeNode(CreateForeignTableStmt);
5755 :
5756 90 : $4->relpersistence = RELPERSISTENCE_PERMANENT;
5757 90 : n->base.relation = $4;
5758 90 : n->base.inhRelations = list_make1($7);
5759 90 : n->base.tableElts = $8;
5760 90 : n->base.partbound = $9;
5761 90 : n->base.ofTypename = NULL;
5762 90 : n->base.constraints = NIL;
5763 90 : n->base.options = NIL;
5764 90 : n->base.oncommit = ONCOMMIT_NOOP;
5765 90 : n->base.tablespacename = NULL;
5766 90 : n->base.if_not_exists = false;
5767 : /* FDW-specific data */
5768 90 : n->servername = $11;
5769 90 : n->options = $12;
5770 90 : $$ = (Node *) n;
5771 : }
5772 : | CREATE FOREIGN TABLE IF_P NOT EXISTS qualified_name
5773 : PARTITION OF qualified_name OptTypedTableElementList PartitionBoundSpec
5774 : SERVER name create_generic_options
5775 : {
5776 0 : CreateForeignTableStmt *n = makeNode(CreateForeignTableStmt);
5777 :
5778 0 : $7->relpersistence = RELPERSISTENCE_PERMANENT;
5779 0 : n->base.relation = $7;
5780 0 : n->base.inhRelations = list_make1($10);
5781 0 : n->base.tableElts = $11;
5782 0 : n->base.partbound = $12;
5783 0 : n->base.ofTypename = NULL;
5784 0 : n->base.constraints = NIL;
5785 0 : n->base.options = NIL;
5786 0 : n->base.oncommit = ONCOMMIT_NOOP;
5787 0 : n->base.tablespacename = NULL;
5788 0 : n->base.if_not_exists = true;
5789 : /* FDW-specific data */
5790 0 : n->servername = $14;
5791 0 : n->options = $15;
5792 0 : $$ = (Node *) n;
5793 : }
5794 : ;
5795 :
5796 : /*****************************************************************************
5797 : *
5798 : * QUERY:
5799 : * IMPORT FOREIGN SCHEMA remote_schema
5800 : * [ { LIMIT TO | EXCEPT } ( table_list ) ]
5801 : * FROM SERVER server_name INTO local_schema [ OPTIONS (...) ]
5802 : *
5803 : ****************************************************************************/
5804 :
5805 : ImportForeignSchemaStmt:
5806 : IMPORT_P FOREIGN SCHEMA name import_qualification
5807 : FROM SERVER name INTO name create_generic_options
5808 : {
5809 48 : ImportForeignSchemaStmt *n = makeNode(ImportForeignSchemaStmt);
5810 :
5811 48 : n->server_name = $8;
5812 48 : n->remote_schema = $4;
5813 48 : n->local_schema = $10;
5814 48 : n->list_type = $5->type;
5815 48 : n->table_list = $5->table_names;
5816 48 : n->options = $11;
5817 48 : $$ = (Node *) n;
5818 : }
5819 : ;
5820 :
5821 : import_qualification_type:
5822 14 : LIMIT TO { $$ = FDW_IMPORT_SCHEMA_LIMIT_TO; }
5823 14 : | EXCEPT { $$ = FDW_IMPORT_SCHEMA_EXCEPT; }
5824 : ;
5825 :
5826 : import_qualification:
5827 : import_qualification_type '(' relation_expr_list ')'
5828 : {
5829 28 : ImportQual *n = (ImportQual *) palloc(sizeof(ImportQual));
5830 :
5831 28 : n->type = $1;
5832 28 : n->table_names = $3;
5833 28 : $$ = n;
5834 : }
5835 : | /*EMPTY*/
5836 : {
5837 20 : ImportQual *n = (ImportQual *) palloc(sizeof(ImportQual));
5838 20 : n->type = FDW_IMPORT_SCHEMA_ALL;
5839 20 : n->table_names = NIL;
5840 20 : $$ = n;
5841 : }
5842 : ;
5843 :
5844 : /*****************************************************************************
5845 : *
5846 : * QUERY:
5847 : * CREATE USER MAPPING FOR auth_ident SERVER name [OPTIONS]
5848 : *
5849 : *****************************************************************************/
5850 :
5851 : CreateUserMappingStmt: CREATE USER MAPPING FOR auth_ident SERVER name create_generic_options
5852 : {
5853 246 : CreateUserMappingStmt *n = makeNode(CreateUserMappingStmt);
5854 :
5855 246 : n->user = $5;
5856 246 : n->servername = $7;
5857 246 : n->options = $8;
5858 246 : n->if_not_exists = false;
5859 246 : $$ = (Node *) n;
5860 : }
5861 : | CREATE USER MAPPING IF_P NOT EXISTS FOR auth_ident SERVER name create_generic_options
5862 : {
5863 6 : CreateUserMappingStmt *n = makeNode(CreateUserMappingStmt);
5864 :
5865 6 : n->user = $8;
5866 6 : n->servername = $10;
5867 6 : n->options = $11;
5868 6 : n->if_not_exists = true;
5869 6 : $$ = (Node *) n;
5870 : }
5871 : ;
5872 :
5873 : /* User mapping authorization identifier */
5874 450 : auth_ident: RoleSpec { $$ = $1; }
5875 46 : | USER { $$ = makeRoleSpec(ROLESPEC_CURRENT_USER, @1); }
5876 : ;
5877 :
5878 : /*****************************************************************************
5879 : *
5880 : * QUERY :
5881 : * DROP USER MAPPING FOR auth_ident SERVER name
5882 : *
5883 : * XXX you'd think this should have a CASCADE/RESTRICT option, even if it's
5884 : * only pro forma; but the SQL standard doesn't show one.
5885 : ****************************************************************************/
5886 :
5887 : DropUserMappingStmt: DROP USER MAPPING FOR auth_ident SERVER name
5888 : {
5889 88 : DropUserMappingStmt *n = makeNode(DropUserMappingStmt);
5890 :
5891 88 : n->user = $5;
5892 88 : n->servername = $7;
5893 88 : n->missing_ok = false;
5894 88 : $$ = (Node *) n;
5895 : }
5896 : | DROP USER MAPPING IF_P EXISTS FOR auth_ident SERVER name
5897 : {
5898 38 : DropUserMappingStmt *n = makeNode(DropUserMappingStmt);
5899 :
5900 38 : n->user = $7;
5901 38 : n->servername = $9;
5902 38 : n->missing_ok = true;
5903 38 : $$ = (Node *) n;
5904 : }
5905 : ;
5906 :
5907 : /*****************************************************************************
5908 : *
5909 : * QUERY :
5910 : * ALTER USER MAPPING FOR auth_ident SERVER name OPTIONS
5911 : *
5912 : ****************************************************************************/
5913 :
5914 : AlterUserMappingStmt: ALTER USER MAPPING FOR auth_ident SERVER name alter_generic_options
5915 : {
5916 118 : AlterUserMappingStmt *n = makeNode(AlterUserMappingStmt);
5917 :
5918 118 : n->user = $5;
5919 118 : n->servername = $7;
5920 118 : n->options = $8;
5921 118 : $$ = (Node *) n;
5922 : }
5923 : ;
5924 :
5925 : /*****************************************************************************
5926 : *
5927 : * QUERIES:
5928 : * CREATE POLICY name ON table
5929 : * [AS { PERMISSIVE | RESTRICTIVE } ]
5930 : * [FOR { SELECT | INSERT | UPDATE | DELETE } ]
5931 : * [TO role, ...]
5932 : * [USING (qual)] [WITH CHECK (with check qual)]
5933 : * ALTER POLICY name ON table [TO role, ...]
5934 : * [USING (qual)] [WITH CHECK (with check qual)]
5935 : *
5936 : *****************************************************************************/
5937 :
5938 : CreatePolicyStmt:
5939 : CREATE POLICY name ON qualified_name RowSecurityDefaultPermissive
5940 : RowSecurityDefaultForCmd RowSecurityDefaultToRole
5941 : RowSecurityOptionalExpr RowSecurityOptionalWithCheck
5942 : {
5943 736 : CreatePolicyStmt *n = makeNode(CreatePolicyStmt);
5944 :
5945 736 : n->policy_name = $3;
5946 736 : n->table = $5;
5947 736 : n->permissive = $6;
5948 736 : n->cmd_name = $7;
5949 736 : n->roles = $8;
5950 736 : n->qual = $9;
5951 736 : n->with_check = $10;
5952 736 : $$ = (Node *) n;
5953 : }
5954 : ;
5955 :
5956 : AlterPolicyStmt:
5957 : ALTER POLICY name ON qualified_name RowSecurityOptionalToRole
5958 : RowSecurityOptionalExpr RowSecurityOptionalWithCheck
5959 : {
5960 84 : AlterPolicyStmt *n = makeNode(AlterPolicyStmt);
5961 :
5962 84 : n->policy_name = $3;
5963 84 : n->table = $5;
5964 84 : n->roles = $6;
5965 84 : n->qual = $7;
5966 84 : n->with_check = $8;
5967 84 : $$ = (Node *) n;
5968 : }
5969 : ;
5970 :
5971 : RowSecurityOptionalExpr:
5972 762 : USING '(' a_expr ')' { $$ = $3; }
5973 58 : | /* EMPTY */ { $$ = NULL; }
5974 : ;
5975 :
5976 : RowSecurityOptionalWithCheck:
5977 122 : WITH CHECK '(' a_expr ')' { $$ = $4; }
5978 698 : | /* EMPTY */ { $$ = NULL; }
5979 : ;
5980 :
5981 : RowSecurityDefaultToRole:
5982 130 : TO role_list { $$ = $2; }
5983 606 : | /* EMPTY */ { $$ = list_make1(makeRoleSpec(ROLESPEC_PUBLIC, -1)); }
5984 : ;
5985 :
5986 : RowSecurityOptionalToRole:
5987 12 : TO role_list { $$ = $2; }
5988 72 : | /* EMPTY */ { $$ = NULL; }
5989 : ;
5990 :
5991 : RowSecurityDefaultPermissive:
5992 : AS IDENT
5993 : {
5994 98 : if (strcmp($2, "permissive") == 0)
5995 24 : $$ = true;
5996 74 : else if (strcmp($2, "restrictive") == 0)
5997 68 : $$ = false;
5998 : else
5999 6 : ereport(ERROR,
6000 : (errcode(ERRCODE_SYNTAX_ERROR),
6001 : errmsg("unrecognized row security option \"%s\"", $2),
6002 : errhint("Only PERMISSIVE or RESTRICTIVE policies are supported currently."),
6003 : parser_errposition(@2)));
6004 :
6005 : }
6006 644 : | /* EMPTY */ { $$ = true; }
6007 : ;
6008 :
6009 : RowSecurityDefaultForCmd:
6010 320 : FOR row_security_cmd { $$ = $2; }
6011 416 : | /* EMPTY */ { $$ = "all"; }
6012 : ;
6013 :
6014 : row_security_cmd:
6015 44 : ALL { $$ = "all"; }
6016 112 : | SELECT { $$ = "select"; }
6017 44 : | INSERT { $$ = "insert"; }
6018 78 : | UPDATE { $$ = "update"; }
6019 42 : | DELETE_P { $$ = "delete"; }
6020 : ;
6021 :
6022 : /*****************************************************************************
6023 : *
6024 : * QUERY:
6025 : * CREATE ACCESS METHOD name HANDLER handler_name
6026 : *
6027 : *****************************************************************************/
6028 :
6029 : CreateAmStmt: CREATE ACCESS METHOD name TYPE_P am_type HANDLER handler_name
6030 : {
6031 62 : CreateAmStmt *n = makeNode(CreateAmStmt);
6032 :
6033 62 : n->amname = $4;
6034 62 : n->handler_name = $8;
6035 62 : n->amtype = $6;
6036 62 : $$ = (Node *) n;
6037 : }
6038 : ;
6039 :
6040 : am_type:
6041 34 : INDEX { $$ = AMTYPE_INDEX; }
6042 28 : | TABLE { $$ = AMTYPE_TABLE; }
6043 : ;
6044 :
6045 : /*****************************************************************************
6046 : *
6047 : * QUERIES :
6048 : * CREATE TRIGGER ...
6049 : *
6050 : *****************************************************************************/
6051 :
6052 : CreateTrigStmt:
6053 : CREATE opt_or_replace TRIGGER name TriggerActionTime TriggerEvents ON
6054 : qualified_name TriggerReferencing TriggerForSpec TriggerWhen
6055 : EXECUTE FUNCTION_or_PROCEDURE func_name '(' TriggerFuncArgs ')'
6056 : {
6057 3168 : CreateTrigStmt *n = makeNode(CreateTrigStmt);
6058 :
6059 3168 : n->replace = $2;
6060 3168 : n->isconstraint = false;
6061 3168 : n->trigname = $4;
6062 3168 : n->relation = $8;
6063 3168 : n->funcname = $14;
6064 3168 : n->args = $16;
6065 3168 : n->row = $10;
6066 3168 : n->timing = $5;
6067 3168 : n->events = intVal(linitial($6));
6068 3168 : n->columns = (List *) lsecond($6);
6069 3168 : n->whenClause = $11;
6070 3168 : n->transitionRels = $9;
6071 3168 : n->deferrable = false;
6072 3168 : n->initdeferred = false;
6073 3168 : n->constrrel = NULL;
6074 3168 : $$ = (Node *) n;
6075 : }
6076 : | CREATE opt_or_replace CONSTRAINT TRIGGER name AFTER TriggerEvents ON
6077 : qualified_name OptConstrFromTable ConstraintAttributeSpec
6078 : FOR EACH ROW TriggerWhen
6079 : EXECUTE FUNCTION_or_PROCEDURE func_name '(' TriggerFuncArgs ')'
6080 : {
6081 80 : CreateTrigStmt *n = makeNode(CreateTrigStmt);
6082 : bool dummy;
6083 :
6084 80 : if (($11 & CAS_NOT_VALID) != 0)
6085 6 : ereport(ERROR,
6086 : errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
6087 : errmsg("constraint triggers cannot be marked %s",
6088 : "NOT VALID"),
6089 : parser_errposition(@11));
6090 74 : if (($11 & CAS_NO_INHERIT) != 0)
6091 6 : ereport(ERROR,
6092 : errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
6093 : errmsg("constraint triggers cannot be marked %s",
6094 : "NO INHERIT"),
6095 : parser_errposition(@11));
6096 68 : if (($11 & CAS_NOT_ENFORCED) != 0)
6097 6 : ereport(ERROR,
6098 : errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
6099 : errmsg("constraint triggers cannot be marked %s",
6100 : "NOT ENFORCED"),
6101 : parser_errposition(@11));
6102 :
6103 62 : n->replace = $2;
6104 62 : if (n->replace) /* not supported, see CreateTrigger */
6105 0 : ereport(ERROR,
6106 : (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
6107 : errmsg("CREATE OR REPLACE CONSTRAINT TRIGGER is not supported"),
6108 : parser_errposition(@1)));
6109 62 : n->isconstraint = true;
6110 62 : n->trigname = $5;
6111 62 : n->relation = $9;
6112 62 : n->funcname = $18;
6113 62 : n->args = $20;
6114 62 : n->row = true;
6115 62 : n->timing = TRIGGER_TYPE_AFTER;
6116 62 : n->events = intVal(linitial($7));
6117 62 : n->columns = (List *) lsecond($7);
6118 62 : n->whenClause = $15;
6119 62 : n->transitionRels = NIL;
6120 62 : processCASbits($11, @11, "TRIGGER",
6121 : &n->deferrable, &n->initdeferred, &dummy,
6122 : NULL, NULL, yyscanner);
6123 62 : n->constrrel = $10;
6124 62 : $$ = (Node *) n;
6125 : }
6126 : ;
6127 :
6128 : TriggerActionTime:
6129 1436 : BEFORE { $$ = TRIGGER_TYPE_BEFORE; }
6130 1600 : | AFTER { $$ = TRIGGER_TYPE_AFTER; }
6131 144 : | INSTEAD OF { $$ = TRIGGER_TYPE_INSTEAD; }
6132 : ;
6133 :
6134 : TriggerEvents:
6135 : TriggerOneEvent
6136 3260 : { $$ = $1; }
6137 : | TriggerEvents OR TriggerOneEvent
6138 : {
6139 1156 : int events1 = intVal(linitial($1));
6140 1156 : int events2 = intVal(linitial($3));
6141 1156 : List *columns1 = (List *) lsecond($1);
6142 1156 : List *columns2 = (List *) lsecond($3);
6143 :
6144 1156 : if (events1 & events2)
6145 6 : parser_yyerror("duplicate trigger events specified");
6146 : /*
6147 : * concat'ing the columns lists loses information about
6148 : * which columns went with which event, but so long as
6149 : * only UPDATE carries columns and we disallow multiple
6150 : * UPDATE items, it doesn't matter. Command execution
6151 : * should just ignore the columns for non-UPDATE events.
6152 : */
6153 1150 : $$ = list_make2(makeInteger(events1 | events2),
6154 : list_concat(columns1, columns2));
6155 : }
6156 : ;
6157 :
6158 : TriggerOneEvent:
6159 : INSERT
6160 1674 : { $$ = list_make2(makeInteger(TRIGGER_TYPE_INSERT), NIL); }
6161 : | DELETE_P
6162 886 : { $$ = list_make2(makeInteger(TRIGGER_TYPE_DELETE), NIL); }
6163 : | UPDATE
6164 1718 : { $$ = list_make2(makeInteger(TRIGGER_TYPE_UPDATE), NIL); }
6165 : | UPDATE OF columnList
6166 100 : { $$ = list_make2(makeInteger(TRIGGER_TYPE_UPDATE), $3); }
6167 : | TRUNCATE
6168 38 : { $$ = list_make2(makeInteger(TRIGGER_TYPE_TRUNCATE), NIL); }
6169 : ;
6170 :
6171 : TriggerReferencing:
6172 464 : REFERENCING TriggerTransitions { $$ = $2; }
6173 2704 : | /*EMPTY*/ { $$ = NIL; }
6174 : ;
6175 :
6176 : TriggerTransitions:
6177 464 : TriggerTransition { $$ = list_make1($1); }
6178 142 : | TriggerTransitions TriggerTransition { $$ = lappend($1, $2); }
6179 : ;
6180 :
6181 : TriggerTransition:
6182 : TransitionOldOrNew TransitionRowOrTable opt_as TransitionRelName
6183 : {
6184 606 : TriggerTransition *n = makeNode(TriggerTransition);
6185 :
6186 606 : n->name = $4;
6187 606 : n->isNew = $1;
6188 606 : n->isTable = $2;
6189 606 : $$ = (Node *) n;
6190 : }
6191 : ;
6192 :
6193 : TransitionOldOrNew:
6194 330 : NEW { $$ = true; }
6195 276 : | OLD { $$ = false; }
6196 : ;
6197 :
6198 : TransitionRowOrTable:
6199 606 : TABLE { $$ = true; }
6200 : /*
6201 : * According to the standard, lack of a keyword here implies ROW.
6202 : * Support for that would require prohibiting ROW entirely here,
6203 : * reserving the keyword ROW, and/or requiring AS (instead of
6204 : * allowing it to be optional, as the standard specifies) as the
6205 : * next token. Requiring ROW seems cleanest and easiest to
6206 : * explain.
6207 : */
6208 0 : | ROW { $$ = false; }
6209 : ;
6210 :
6211 : TransitionRelName:
6212 606 : ColId { $$ = $1; }
6213 : ;
6214 :
6215 : TriggerForSpec:
6216 : FOR TriggerForOptEach TriggerForType
6217 : {
6218 2928 : $$ = $3;
6219 : }
6220 : | /* EMPTY */
6221 : {
6222 : /*
6223 : * If ROW/STATEMENT not specified, default to
6224 : * STATEMENT, per SQL
6225 : */
6226 240 : $$ = false;
6227 : }
6228 : ;
6229 :
6230 : TriggerForOptEach:
6231 : EACH
6232 : | /*EMPTY*/
6233 : ;
6234 :
6235 : TriggerForType:
6236 2108 : ROW { $$ = true; }
6237 820 : | STATEMENT { $$ = false; }
6238 : ;
6239 :
6240 : TriggerWhen:
6241 190 : WHEN '(' a_expr ')' { $$ = $3; }
6242 3058 : | /*EMPTY*/ { $$ = NULL; }
6243 : ;
6244 :
6245 : FUNCTION_or_PROCEDURE:
6246 : FUNCTION
6247 : | PROCEDURE
6248 : ;
6249 :
6250 : TriggerFuncArgs:
6251 546 : TriggerFuncArg { $$ = list_make1($1); }
6252 162 : | TriggerFuncArgs ',' TriggerFuncArg { $$ = lappend($1, $3); }
6253 2702 : | /*EMPTY*/ { $$ = NIL; }
6254 : ;
6255 :
6256 : TriggerFuncArg:
6257 : Iconst
6258 : {
6259 94 : $$ = (Node *) makeString(psprintf("%d", $1));
6260 : }
6261 0 : | FCONST { $$ = (Node *) makeString($1); }
6262 592 : | Sconst { $$ = (Node *) makeString($1); }
6263 22 : | ColLabel { $$ = (Node *) makeString($1); }
6264 : ;
6265 :
6266 : OptConstrFromTable:
6267 12 : FROM qualified_name { $$ = $2; }
6268 68 : | /*EMPTY*/ { $$ = NULL; }
6269 : ;
6270 :
6271 : ConstraintAttributeSpec:
6272 : /*EMPTY*/
6273 17918 : { $$ = 0; }
6274 : | ConstraintAttributeSpec ConstraintAttributeElem
6275 : {
6276 : /*
6277 : * We must complain about conflicting options.
6278 : * We could, but choose not to, complain about redundant
6279 : * options (ie, where $2's bit is already set in $1).
6280 : */
6281 1682 : int newspec = $1 | $2;
6282 :
6283 : /* special message for this case */
6284 1682 : if ((newspec & (CAS_NOT_DEFERRABLE | CAS_INITIALLY_DEFERRED)) == (CAS_NOT_DEFERRABLE | CAS_INITIALLY_DEFERRED))
6285 6 : ereport(ERROR,
6286 : (errcode(ERRCODE_SYNTAX_ERROR),
6287 : errmsg("constraint declared INITIALLY DEFERRED must be DEFERRABLE"),
6288 : parser_errposition(@2)));
6289 : /* generic message for other conflicts */
6290 1676 : if ((newspec & (CAS_NOT_DEFERRABLE | CAS_DEFERRABLE)) == (CAS_NOT_DEFERRABLE | CAS_DEFERRABLE) ||
6291 1676 : (newspec & (CAS_INITIALLY_IMMEDIATE | CAS_INITIALLY_DEFERRED)) == (CAS_INITIALLY_IMMEDIATE | CAS_INITIALLY_DEFERRED) ||
6292 1676 : (newspec & (CAS_NOT_ENFORCED | CAS_ENFORCED)) == (CAS_NOT_ENFORCED | CAS_ENFORCED))
6293 6 : ereport(ERROR,
6294 : (errcode(ERRCODE_SYNTAX_ERROR),
6295 : errmsg("conflicting constraint properties"),
6296 : parser_errposition(@2)));
6297 1670 : $$ = newspec;
6298 : }
6299 : ;
6300 :
6301 : ConstraintAttributeElem:
6302 42 : NOT DEFERRABLE { $$ = CAS_NOT_DEFERRABLE; }
6303 200 : | DEFERRABLE { $$ = CAS_DEFERRABLE; }
6304 30 : | INITIALLY IMMEDIATE { $$ = CAS_INITIALLY_IMMEDIATE; }
6305 152 : | INITIALLY DEFERRED { $$ = CAS_INITIALLY_DEFERRED; }
6306 732 : | NOT VALID { $$ = CAS_NOT_VALID; }
6307 250 : | NO INHERIT { $$ = CAS_NO_INHERIT; }
6308 168 : | NOT ENFORCED { $$ = CAS_NOT_ENFORCED; }
6309 108 : | ENFORCED { $$ = CAS_ENFORCED; }
6310 : ;
6311 :
6312 :
6313 : /*****************************************************************************
6314 : *
6315 : * QUERIES :
6316 : * CREATE EVENT TRIGGER ...
6317 : * ALTER EVENT TRIGGER ...
6318 : *
6319 : *****************************************************************************/
6320 :
6321 : CreateEventTrigStmt:
6322 : CREATE EVENT TRIGGER name ON ColLabel
6323 : EXECUTE FUNCTION_or_PROCEDURE func_name '(' ')'
6324 : {
6325 102 : CreateEventTrigStmt *n = makeNode(CreateEventTrigStmt);
6326 :
6327 102 : n->trigname = $4;
6328 102 : n->eventname = $6;
6329 102 : n->whenclause = NULL;
6330 102 : n->funcname = $9;
6331 102 : $$ = (Node *) n;
6332 : }
6333 : | CREATE EVENT TRIGGER name ON ColLabel
6334 : WHEN event_trigger_when_list
6335 : EXECUTE FUNCTION_or_PROCEDURE func_name '(' ')'
6336 : {
6337 98 : CreateEventTrigStmt *n = makeNode(CreateEventTrigStmt);
6338 :
6339 98 : n->trigname = $4;
6340 98 : n->eventname = $6;
6341 98 : n->whenclause = $8;
6342 98 : n->funcname = $11;
6343 98 : $$ = (Node *) n;
6344 : }
6345 : ;
6346 :
6347 : event_trigger_when_list:
6348 : event_trigger_when_item
6349 98 : { $$ = list_make1($1); }
6350 : | event_trigger_when_list AND event_trigger_when_item
6351 6 : { $$ = lappend($1, $3); }
6352 : ;
6353 :
6354 : event_trigger_when_item:
6355 : ColId IN_P '(' event_trigger_value_list ')'
6356 104 : { $$ = makeDefElem($1, (Node *) $4, @1); }
6357 : ;
6358 :
6359 : event_trigger_value_list:
6360 : SCONST
6361 104 : { $$ = list_make1(makeString($1)); }
6362 : | event_trigger_value_list ',' SCONST
6363 66 : { $$ = lappend($1, makeString($3)); }
6364 : ;
6365 :
6366 : AlterEventTrigStmt:
6367 : ALTER EVENT TRIGGER name enable_trigger
6368 : {
6369 48 : AlterEventTrigStmt *n = makeNode(AlterEventTrigStmt);
6370 :
6371 48 : n->trigname = $4;
6372 48 : n->tgenabled = $5;
6373 48 : $$ = (Node *) n;
6374 : }
6375 : ;
6376 :
6377 : enable_trigger:
6378 6 : ENABLE_P { $$ = TRIGGER_FIRES_ON_ORIGIN; }
6379 6 : | ENABLE_P REPLICA { $$ = TRIGGER_FIRES_ON_REPLICA; }
6380 16 : | ENABLE_P ALWAYS { $$ = TRIGGER_FIRES_ALWAYS; }
6381 20 : | DISABLE_P { $$ = TRIGGER_DISABLED; }
6382 : ;
6383 :
6384 : /*****************************************************************************
6385 : *
6386 : * QUERY :
6387 : * CREATE ASSERTION ...
6388 : *
6389 : *****************************************************************************/
6390 :
6391 : CreateAssertionStmt:
6392 : CREATE ASSERTION any_name CHECK '(' a_expr ')' ConstraintAttributeSpec
6393 : {
6394 0 : ereport(ERROR,
6395 : (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
6396 : errmsg("CREATE ASSERTION is not yet implemented"),
6397 : parser_errposition(@1)));
6398 :
6399 : $$ = NULL;
6400 : }
6401 : ;
6402 :
6403 :
6404 : /*****************************************************************************
6405 : *
6406 : * QUERY :
6407 : * define (aggregate,operator,type)
6408 : *
6409 : *****************************************************************************/
6410 :
6411 : DefineStmt:
6412 : CREATE opt_or_replace AGGREGATE func_name aggr_args definition
6413 : {
6414 544 : DefineStmt *n = makeNode(DefineStmt);
6415 :
6416 544 : n->kind = OBJECT_AGGREGATE;
6417 544 : n->oldstyle = false;
6418 544 : n->replace = $2;
6419 544 : n->defnames = $4;
6420 544 : n->args = $5;
6421 544 : n->definition = $6;
6422 544 : $$ = (Node *) n;
6423 : }
6424 : | CREATE opt_or_replace AGGREGATE func_name old_aggr_definition
6425 : {
6426 : /* old-style (pre-8.2) syntax for CREATE AGGREGATE */
6427 362 : DefineStmt *n = makeNode(DefineStmt);
6428 :
6429 362 : n->kind = OBJECT_AGGREGATE;
6430 362 : n->oldstyle = true;
6431 362 : n->replace = $2;
6432 362 : n->defnames = $4;
6433 362 : n->args = NIL;
6434 362 : n->definition = $5;
6435 362 : $$ = (Node *) n;
6436 : }
6437 : | CREATE OPERATOR any_operator definition
6438 : {
6439 1642 : DefineStmt *n = makeNode(DefineStmt);
6440 :
6441 1642 : n->kind = OBJECT_OPERATOR;
6442 1642 : n->oldstyle = false;
6443 1642 : n->defnames = $3;
6444 1642 : n->args = NIL;
6445 1642 : n->definition = $4;
6446 1642 : $$ = (Node *) n;
6447 : }
6448 : | CREATE TYPE_P any_name definition
6449 : {
6450 240 : DefineStmt *n = makeNode(DefineStmt);
6451 :
6452 240 : n->kind = OBJECT_TYPE;
6453 240 : n->oldstyle = false;
6454 240 : n->defnames = $3;
6455 240 : n->args = NIL;
6456 240 : n->definition = $4;
6457 240 : $$ = (Node *) n;
6458 : }
6459 : | CREATE TYPE_P any_name
6460 : {
6461 : /* Shell type (identified by lack of definition) */
6462 156 : DefineStmt *n = makeNode(DefineStmt);
6463 :
6464 156 : n->kind = OBJECT_TYPE;
6465 156 : n->oldstyle = false;
6466 156 : n->defnames = $3;
6467 156 : n->args = NIL;
6468 156 : n->definition = NIL;
6469 156 : $$ = (Node *) n;
6470 : }
6471 : | CREATE TYPE_P any_name AS '(' OptTableFuncElementList ')'
6472 : {
6473 4502 : CompositeTypeStmt *n = makeNode(CompositeTypeStmt);
6474 :
6475 : /* can't use qualified_name, sigh */
6476 4502 : n->typevar = makeRangeVarFromAnyName($3, @3, yyscanner);
6477 4502 : n->coldeflist = $6;
6478 4502 : $$ = (Node *) n;
6479 : }
6480 : | CREATE TYPE_P any_name AS ENUM_P '(' opt_enum_val_list ')'
6481 : {
6482 208 : CreateEnumStmt *n = makeNode(CreateEnumStmt);
6483 :
6484 208 : n->typeName = $3;
6485 208 : n->vals = $7;
6486 208 : $$ = (Node *) n;
6487 : }
6488 : | CREATE TYPE_P any_name AS RANGE definition
6489 : {
6490 184 : CreateRangeStmt *n = makeNode(CreateRangeStmt);
6491 :
6492 184 : n->typeName = $3;
6493 184 : n->params = $6;
6494 184 : $$ = (Node *) n;
6495 : }
6496 : | CREATE TEXT_P SEARCH PARSER any_name definition
6497 : {
6498 40 : DefineStmt *n = makeNode(DefineStmt);
6499 :
6500 40 : n->kind = OBJECT_TSPARSER;
6501 40 : n->args = NIL;
6502 40 : n->defnames = $5;
6503 40 : n->definition = $6;
6504 40 : $$ = (Node *) n;
6505 : }
6506 : | CREATE TEXT_P SEARCH DICTIONARY any_name definition
6507 : {
6508 2930 : DefineStmt *n = makeNode(DefineStmt);
6509 :
6510 2930 : n->kind = OBJECT_TSDICTIONARY;
6511 2930 : n->args = NIL;
6512 2930 : n->defnames = $5;
6513 2930 : n->definition = $6;
6514 2930 : $$ = (Node *) n;
6515 : }
6516 : | CREATE TEXT_P SEARCH TEMPLATE any_name definition
6517 : {
6518 140 : DefineStmt *n = makeNode(DefineStmt);
6519 :
6520 140 : n->kind = OBJECT_TSTEMPLATE;
6521 140 : n->args = NIL;
6522 140 : n->defnames = $5;
6523 140 : n->definition = $6;
6524 140 : $$ = (Node *) n;
6525 : }
6526 : | CREATE TEXT_P SEARCH CONFIGURATION any_name definition
6527 : {
6528 2872 : DefineStmt *n = makeNode(DefineStmt);
6529 :
6530 2872 : n->kind = OBJECT_TSCONFIGURATION;
6531 2872 : n->args = NIL;
6532 2872 : n->defnames = $5;
6533 2872 : n->definition = $6;
6534 2872 : $$ = (Node *) n;
6535 : }
6536 : | CREATE COLLATION any_name definition
6537 : {
6538 292 : DefineStmt *n = makeNode(DefineStmt);
6539 :
6540 292 : n->kind = OBJECT_COLLATION;
6541 292 : n->args = NIL;
6542 292 : n->defnames = $3;
6543 292 : n->definition = $4;
6544 292 : $$ = (Node *) n;
6545 : }
6546 : | CREATE COLLATION IF_P NOT EXISTS any_name definition
6547 : {
6548 18 : DefineStmt *n = makeNode(DefineStmt);
6549 :
6550 18 : n->kind = OBJECT_COLLATION;
6551 18 : n->args = NIL;
6552 18 : n->defnames = $6;
6553 18 : n->definition = $7;
6554 18 : n->if_not_exists = true;
6555 18 : $$ = (Node *) n;
6556 : }
6557 : | CREATE COLLATION any_name FROM any_name
6558 : {
6559 54 : DefineStmt *n = makeNode(DefineStmt);
6560 :
6561 54 : n->kind = OBJECT_COLLATION;
6562 54 : n->args = NIL;
6563 54 : n->defnames = $3;
6564 54 : n->definition = list_make1(makeDefElem("from", (Node *) $5, @5));
6565 54 : $$ = (Node *) n;
6566 : }
6567 : | CREATE COLLATION IF_P NOT EXISTS any_name FROM any_name
6568 : {
6569 0 : DefineStmt *n = makeNode(DefineStmt);
6570 :
6571 0 : n->kind = OBJECT_COLLATION;
6572 0 : n->args = NIL;
6573 0 : n->defnames = $6;
6574 0 : n->definition = list_make1(makeDefElem("from", (Node *) $8, @8));
6575 0 : n->if_not_exists = true;
6576 0 : $$ = (Node *) n;
6577 : }
6578 : ;
6579 :
6580 9956 : definition: '(' def_list ')' { $$ = $2; }
6581 : ;
6582 :
6583 9956 : def_list: def_elem { $$ = list_make1($1); }
6584 14814 : | def_list ',' def_elem { $$ = lappend($1, $3); }
6585 : ;
6586 :
6587 : def_elem: ColLabel '=' def_arg
6588 : {
6589 24432 : $$ = makeDefElem($1, (Node *) $3, @1);
6590 : }
6591 : | ColLabel
6592 : {
6593 338 : $$ = makeDefElem($1, NULL, @1);
6594 : }
6595 : ;
6596 :
6597 : /* Note: any simple identifier will be returned as a type name! */
6598 19732 : def_arg: func_type { $$ = (Node *) $1; }
6599 4128 : | reserved_keyword { $$ = (Node *) makeString(pstrdup($1)); }
6600 1176 : | qual_all_Op { $$ = (Node *) $1; }
6601 1334 : | NumericOnly { $$ = (Node *) $1; }
6602 1892 : | Sconst { $$ = (Node *) makeString($1); }
6603 182 : | NONE { $$ = (Node *) makeString(pstrdup($1)); }
6604 : ;
6605 :
6606 362 : old_aggr_definition: '(' old_aggr_list ')' { $$ = $2; }
6607 : ;
6608 :
6609 362 : old_aggr_list: old_aggr_elem { $$ = list_make1($1); }
6610 1292 : | old_aggr_list ',' old_aggr_elem { $$ = lappend($1, $3); }
6611 : ;
6612 :
6613 : /*
6614 : * Must use IDENT here to avoid reduce/reduce conflicts; fortunately none of
6615 : * the item names needed in old aggregate definitions are likely to become
6616 : * SQL keywords.
6617 : */
6618 : old_aggr_elem: IDENT '=' def_arg
6619 : {
6620 1654 : $$ = makeDefElem($1, (Node *) $3, @1);
6621 : }
6622 : ;
6623 :
6624 : opt_enum_val_list:
6625 200 : enum_val_list { $$ = $1; }
6626 8 : | /*EMPTY*/ { $$ = NIL; }
6627 : ;
6628 :
6629 : enum_val_list: Sconst
6630 200 : { $$ = list_make1(makeString($1)); }
6631 : | enum_val_list ',' Sconst
6632 10420 : { $$ = lappend($1, makeString($3)); }
6633 : ;
6634 :
6635 : /*****************************************************************************
6636 : *
6637 : * ALTER TYPE enumtype ADD ...
6638 : *
6639 : *****************************************************************************/
6640 :
6641 : AlterEnumStmt:
6642 : ALTER TYPE_P any_name ADD_P VALUE_P opt_if_not_exists Sconst
6643 : {
6644 154 : AlterEnumStmt *n = makeNode(AlterEnumStmt);
6645 :
6646 154 : n->typeName = $3;
6647 154 : n->oldVal = NULL;
6648 154 : n->newVal = $7;
6649 154 : n->newValNeighbor = NULL;
6650 154 : n->newValIsAfter = true;
6651 154 : n->skipIfNewValExists = $6;
6652 154 : $$ = (Node *) n;
6653 : }
6654 : | ALTER TYPE_P any_name ADD_P VALUE_P opt_if_not_exists Sconst BEFORE Sconst
6655 : {
6656 196 : AlterEnumStmt *n = makeNode(AlterEnumStmt);
6657 :
6658 196 : n->typeName = $3;
6659 196 : n->oldVal = NULL;
6660 196 : n->newVal = $7;
6661 196 : n->newValNeighbor = $9;
6662 196 : n->newValIsAfter = false;
6663 196 : n->skipIfNewValExists = $6;
6664 196 : $$ = (Node *) n;
6665 : }
6666 : | ALTER TYPE_P any_name ADD_P VALUE_P opt_if_not_exists Sconst AFTER Sconst
6667 : {
6668 22 : AlterEnumStmt *n = makeNode(AlterEnumStmt);
6669 :
6670 22 : n->typeName = $3;
6671 22 : n->oldVal = NULL;
6672 22 : n->newVal = $7;
6673 22 : n->newValNeighbor = $9;
6674 22 : n->newValIsAfter = true;
6675 22 : n->skipIfNewValExists = $6;
6676 22 : $$ = (Node *) n;
6677 : }
6678 : | ALTER TYPE_P any_name RENAME VALUE_P Sconst TO Sconst
6679 : {
6680 24 : AlterEnumStmt *n = makeNode(AlterEnumStmt);
6681 :
6682 24 : n->typeName = $3;
6683 24 : n->oldVal = $6;
6684 24 : n->newVal = $8;
6685 24 : n->newValNeighbor = NULL;
6686 24 : n->newValIsAfter = false;
6687 24 : n->skipIfNewValExists = false;
6688 24 : $$ = (Node *) n;
6689 : }
6690 : | ALTER TYPE_P any_name DROP VALUE_P Sconst
6691 : {
6692 : /*
6693 : * The following problems must be solved before this can be
6694 : * implemented:
6695 : *
6696 : * - There must be no instance of the target value in
6697 : * any table.
6698 : *
6699 : * - The value must not appear in any catalog metadata,
6700 : * such as stored view expressions or column defaults.
6701 : *
6702 : * - The value must not appear in any non-leaf page of a
6703 : * btree (and similar issues with other index types).
6704 : * This is problematic because a value could persist
6705 : * there long after it's gone from user-visible data.
6706 : *
6707 : * - Concurrent sessions must not be able to insert the
6708 : * value while the preceding conditions are being checked.
6709 : *
6710 : * - Possibly more...
6711 : */
6712 0 : ereport(ERROR,
6713 : (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
6714 : errmsg("dropping an enum value is not implemented"),
6715 : parser_errposition(@4)));
6716 : }
6717 : ;
6718 :
6719 12 : opt_if_not_exists: IF_P NOT EXISTS { $$ = true; }
6720 360 : | /* EMPTY */ { $$ = false; }
6721 : ;
6722 :
6723 :
6724 : /*****************************************************************************
6725 : *
6726 : * QUERIES :
6727 : * CREATE OPERATOR CLASS ...
6728 : * CREATE OPERATOR FAMILY ...
6729 : * ALTER OPERATOR FAMILY ...
6730 : * DROP OPERATOR CLASS ...
6731 : * DROP OPERATOR FAMILY ...
6732 : *
6733 : *****************************************************************************/
6734 :
6735 : CreateOpClassStmt:
6736 : CREATE OPERATOR CLASS any_name opt_default FOR TYPE_P Typename
6737 : USING name opt_opfamily AS opclass_item_list
6738 : {
6739 556 : CreateOpClassStmt *n = makeNode(CreateOpClassStmt);
6740 :
6741 556 : n->opclassname = $4;
6742 556 : n->isDefault = $5;
6743 556 : n->datatype = $8;
6744 556 : n->amname = $10;
6745 556 : n->opfamilyname = $11;
6746 556 : n->items = $13;
6747 556 : $$ = (Node *) n;
6748 : }
6749 : ;
6750 :
6751 : opclass_item_list:
6752 1412 : opclass_item { $$ = list_make1($1); }
6753 5388 : | opclass_item_list ',' opclass_item { $$ = lappend($1, $3); }
6754 : ;
6755 :
6756 : opclass_item:
6757 : OPERATOR Iconst any_operator opclass_purpose
6758 : {
6759 1866 : CreateOpClassItem *n = makeNode(CreateOpClassItem);
6760 1866 : ObjectWithArgs *owa = makeNode(ObjectWithArgs);
6761 :
6762 1866 : owa->objname = $3;
6763 1866 : owa->objargs = NIL;
6764 1866 : n->itemtype = OPCLASS_ITEM_OPERATOR;
6765 1866 : n->name = owa;
6766 1866 : n->number = $2;
6767 1866 : n->order_family = $4;
6768 1866 : $$ = (Node *) n;
6769 : }
6770 : | OPERATOR Iconst operator_with_argtypes opclass_purpose
6771 : {
6772 1570 : CreateOpClassItem *n = makeNode(CreateOpClassItem);
6773 :
6774 1570 : n->itemtype = OPCLASS_ITEM_OPERATOR;
6775 1570 : n->name = $3;
6776 1570 : n->number = $2;
6777 1570 : n->order_family = $4;
6778 1570 : $$ = (Node *) n;
6779 : }
6780 : | FUNCTION Iconst function_with_argtypes
6781 : {
6782 2414 : CreateOpClassItem *n = makeNode(CreateOpClassItem);
6783 :
6784 2414 : n->itemtype = OPCLASS_ITEM_FUNCTION;
6785 2414 : n->name = $3;
6786 2414 : n->number = $2;
6787 2414 : $$ = (Node *) n;
6788 : }
6789 : | FUNCTION Iconst '(' type_list ')' function_with_argtypes
6790 : {
6791 590 : CreateOpClassItem *n = makeNode(CreateOpClassItem);
6792 :
6793 590 : n->itemtype = OPCLASS_ITEM_FUNCTION;
6794 590 : n->name = $6;
6795 590 : n->number = $2;
6796 590 : n->class_args = $4;
6797 590 : $$ = (Node *) n;
6798 : }
6799 : | STORAGE Typename
6800 : {
6801 360 : CreateOpClassItem *n = makeNode(CreateOpClassItem);
6802 :
6803 360 : n->itemtype = OPCLASS_ITEM_STORAGETYPE;
6804 360 : n->storedtype = $2;
6805 360 : $$ = (Node *) n;
6806 : }
6807 : ;
6808 :
6809 452 : opt_default: DEFAULT { $$ = true; }
6810 168 : | /*EMPTY*/ { $$ = false; }
6811 : ;
6812 :
6813 44 : opt_opfamily: FAMILY any_name { $$ = $2; }
6814 512 : | /*EMPTY*/ { $$ = NIL; }
6815 : ;
6816 :
6817 0 : opclass_purpose: FOR SEARCH { $$ = NIL; }
6818 120 : | FOR ORDER BY any_name { $$ = $4; }
6819 3316 : | /*EMPTY*/ { $$ = NIL; }
6820 : ;
6821 :
6822 :
6823 : CreateOpFamilyStmt:
6824 : CREATE OPERATOR FAMILY any_name USING name
6825 : {
6826 148 : CreateOpFamilyStmt *n = makeNode(CreateOpFamilyStmt);
6827 :
6828 148 : n->opfamilyname = $4;
6829 148 : n->amname = $6;
6830 148 : $$ = (Node *) n;
6831 : }
6832 : ;
6833 :
6834 : AlterOpFamilyStmt:
6835 : ALTER OPERATOR FAMILY any_name USING name ADD_P opclass_item_list
6836 : {
6837 856 : AlterOpFamilyStmt *n = makeNode(AlterOpFamilyStmt);
6838 :
6839 856 : n->opfamilyname = $4;
6840 856 : n->amname = $6;
6841 856 : n->isDrop = false;
6842 856 : n->items = $8;
6843 856 : $$ = (Node *) n;
6844 : }
6845 : | ALTER OPERATOR FAMILY any_name USING name DROP opclass_drop_list
6846 : {
6847 64 : AlterOpFamilyStmt *n = makeNode(AlterOpFamilyStmt);
6848 :
6849 64 : n->opfamilyname = $4;
6850 64 : n->amname = $6;
6851 64 : n->isDrop = true;
6852 64 : n->items = $8;
6853 64 : $$ = (Node *) n;
6854 : }
6855 : ;
6856 :
6857 : opclass_drop_list:
6858 64 : opclass_drop { $$ = list_make1($1); }
6859 30 : | opclass_drop_list ',' opclass_drop { $$ = lappend($1, $3); }
6860 : ;
6861 :
6862 : opclass_drop:
6863 : OPERATOR Iconst '(' type_list ')'
6864 : {
6865 56 : CreateOpClassItem *n = makeNode(CreateOpClassItem);
6866 :
6867 56 : n->itemtype = OPCLASS_ITEM_OPERATOR;
6868 56 : n->number = $2;
6869 56 : n->class_args = $4;
6870 56 : $$ = (Node *) n;
6871 : }
6872 : | FUNCTION Iconst '(' type_list ')'
6873 : {
6874 38 : CreateOpClassItem *n = makeNode(CreateOpClassItem);
6875 :
6876 38 : n->itemtype = OPCLASS_ITEM_FUNCTION;
6877 38 : n->number = $2;
6878 38 : n->class_args = $4;
6879 38 : $$ = (Node *) n;
6880 : }
6881 : ;
6882 :
6883 :
6884 : DropOpClassStmt:
6885 : DROP OPERATOR CLASS any_name USING name opt_drop_behavior
6886 : {
6887 38 : DropStmt *n = makeNode(DropStmt);
6888 :
6889 38 : n->objects = list_make1(lcons(makeString($6), $4));
6890 38 : n->removeType = OBJECT_OPCLASS;
6891 38 : n->behavior = $7;
6892 38 : n->missing_ok = false;
6893 38 : n->concurrent = false;
6894 38 : $$ = (Node *) n;
6895 : }
6896 : | DROP OPERATOR CLASS IF_P EXISTS any_name USING name opt_drop_behavior
6897 : {
6898 18 : DropStmt *n = makeNode(DropStmt);
6899 :
6900 18 : n->objects = list_make1(lcons(makeString($8), $6));
6901 18 : n->removeType = OBJECT_OPCLASS;
6902 18 : n->behavior = $9;
6903 18 : n->missing_ok = true;
6904 18 : n->concurrent = false;
6905 18 : $$ = (Node *) n;
6906 : }
6907 : ;
6908 :
6909 : DropOpFamilyStmt:
6910 : DROP OPERATOR FAMILY any_name USING name opt_drop_behavior
6911 : {
6912 110 : DropStmt *n = makeNode(DropStmt);
6913 :
6914 110 : n->objects = list_make1(lcons(makeString($6), $4));
6915 110 : n->removeType = OBJECT_OPFAMILY;
6916 110 : n->behavior = $7;
6917 110 : n->missing_ok = false;
6918 110 : n->concurrent = false;
6919 110 : $$ = (Node *) n;
6920 : }
6921 : | DROP OPERATOR FAMILY IF_P EXISTS any_name USING name opt_drop_behavior
6922 : {
6923 18 : DropStmt *n = makeNode(DropStmt);
6924 :
6925 18 : n->objects = list_make1(lcons(makeString($8), $6));
6926 18 : n->removeType = OBJECT_OPFAMILY;
6927 18 : n->behavior = $9;
6928 18 : n->missing_ok = true;
6929 18 : n->concurrent = false;
6930 18 : $$ = (Node *) n;
6931 : }
6932 : ;
6933 :
6934 :
6935 : /*****************************************************************************
6936 : *
6937 : * QUERY:
6938 : *
6939 : * DROP OWNED BY username [, username ...] [ RESTRICT | CASCADE ]
6940 : * REASSIGN OWNED BY username [, username ...] TO username
6941 : *
6942 : *****************************************************************************/
6943 : DropOwnedStmt:
6944 : DROP OWNED BY role_list opt_drop_behavior
6945 : {
6946 146 : DropOwnedStmt *n = makeNode(DropOwnedStmt);
6947 :
6948 146 : n->roles = $4;
6949 146 : n->behavior = $5;
6950 146 : $$ = (Node *) n;
6951 : }
6952 : ;
6953 :
6954 : ReassignOwnedStmt:
6955 : REASSIGN OWNED BY role_list TO RoleSpec
6956 : {
6957 46 : ReassignOwnedStmt *n = makeNode(ReassignOwnedStmt);
6958 :
6959 46 : n->roles = $4;
6960 46 : n->newrole = $6;
6961 46 : $$ = (Node *) n;
6962 : }
6963 : ;
6964 :
6965 : /*****************************************************************************
6966 : *
6967 : * QUERY:
6968 : *
6969 : * DROP itemtype [ IF EXISTS ] itemname [, itemname ...]
6970 : * [ RESTRICT | CASCADE ]
6971 : *
6972 : *****************************************************************************/
6973 :
6974 : DropStmt: DROP object_type_any_name IF_P EXISTS any_name_list opt_drop_behavior
6975 : {
6976 1352 : DropStmt *n = makeNode(DropStmt);
6977 :
6978 1352 : n->removeType = $2;
6979 1352 : n->missing_ok = true;
6980 1352 : n->objects = $5;
6981 1352 : n->behavior = $6;
6982 1352 : n->concurrent = false;
6983 1352 : $$ = (Node *) n;
6984 : }
6985 : | DROP object_type_any_name any_name_list opt_drop_behavior
6986 : {
6987 16312 : DropStmt *n = makeNode(DropStmt);
6988 :
6989 16312 : n->removeType = $2;
6990 16312 : n->missing_ok = false;
6991 16312 : n->objects = $3;
6992 16312 : n->behavior = $4;
6993 16312 : n->concurrent = false;
6994 16312 : $$ = (Node *) n;
6995 : }
6996 : | DROP drop_type_name IF_P EXISTS name_list opt_drop_behavior
6997 : {
6998 86 : DropStmt *n = makeNode(DropStmt);
6999 :
7000 86 : n->removeType = $2;
7001 86 : n->missing_ok = true;
7002 86 : n->objects = $5;
7003 86 : n->behavior = $6;
7004 86 : n->concurrent = false;
7005 86 : $$ = (Node *) n;
7006 : }
7007 : | DROP drop_type_name name_list opt_drop_behavior
7008 : {
7009 1432 : DropStmt *n = makeNode(DropStmt);
7010 :
7011 1432 : n->removeType = $2;
7012 1432 : n->missing_ok = false;
7013 1432 : n->objects = $3;
7014 1432 : n->behavior = $4;
7015 1432 : n->concurrent = false;
7016 1432 : $$ = (Node *) n;
7017 : }
7018 : | DROP object_type_name_on_any_name name ON any_name opt_drop_behavior
7019 : {
7020 1130 : DropStmt *n = makeNode(DropStmt);
7021 :
7022 1130 : n->removeType = $2;
7023 1130 : n->objects = list_make1(lappend($5, makeString($3)));
7024 1130 : n->behavior = $6;
7025 1130 : n->missing_ok = false;
7026 1130 : n->concurrent = false;
7027 1130 : $$ = (Node *) n;
7028 : }
7029 : | DROP object_type_name_on_any_name IF_P EXISTS name ON any_name opt_drop_behavior
7030 : {
7031 48 : DropStmt *n = makeNode(DropStmt);
7032 :
7033 48 : n->removeType = $2;
7034 48 : n->objects = list_make1(lappend($7, makeString($5)));
7035 48 : n->behavior = $8;
7036 48 : n->missing_ok = true;
7037 48 : n->concurrent = false;
7038 48 : $$ = (Node *) n;
7039 : }
7040 : | DROP TYPE_P type_name_list opt_drop_behavior
7041 : {
7042 560 : DropStmt *n = makeNode(DropStmt);
7043 :
7044 560 : n->removeType = OBJECT_TYPE;
7045 560 : n->missing_ok = false;
7046 560 : n->objects = $3;
7047 560 : n->behavior = $4;
7048 560 : n->concurrent = false;
7049 560 : $$ = (Node *) n;
7050 : }
7051 : | DROP TYPE_P IF_P EXISTS type_name_list opt_drop_behavior
7052 : {
7053 26 : DropStmt *n = makeNode(DropStmt);
7054 :
7055 26 : n->removeType = OBJECT_TYPE;
7056 26 : n->missing_ok = true;
7057 26 : n->objects = $5;
7058 26 : n->behavior = $6;
7059 26 : n->concurrent = false;
7060 26 : $$ = (Node *) n;
7061 : }
7062 : | DROP DOMAIN_P type_name_list opt_drop_behavior
7063 : {
7064 464 : DropStmt *n = makeNode(DropStmt);
7065 :
7066 464 : n->removeType = OBJECT_DOMAIN;
7067 464 : n->missing_ok = false;
7068 464 : n->objects = $3;
7069 464 : n->behavior = $4;
7070 464 : n->concurrent = false;
7071 464 : $$ = (Node *) n;
7072 : }
7073 : | DROP DOMAIN_P IF_P EXISTS type_name_list opt_drop_behavior
7074 : {
7075 18 : DropStmt *n = makeNode(DropStmt);
7076 :
7077 18 : n->removeType = OBJECT_DOMAIN;
7078 18 : n->missing_ok = true;
7079 18 : n->objects = $5;
7080 18 : n->behavior = $6;
7081 18 : n->concurrent = false;
7082 18 : $$ = (Node *) n;
7083 : }
7084 : | DROP INDEX CONCURRENTLY any_name_list opt_drop_behavior
7085 : {
7086 162 : DropStmt *n = makeNode(DropStmt);
7087 :
7088 162 : n->removeType = OBJECT_INDEX;
7089 162 : n->missing_ok = false;
7090 162 : n->objects = $4;
7091 162 : n->behavior = $5;
7092 162 : n->concurrent = true;
7093 162 : $$ = (Node *) n;
7094 : }
7095 : | DROP INDEX CONCURRENTLY IF_P EXISTS any_name_list opt_drop_behavior
7096 : {
7097 12 : DropStmt *n = makeNode(DropStmt);
7098 :
7099 12 : n->removeType = OBJECT_INDEX;
7100 12 : n->missing_ok = true;
7101 12 : n->objects = $6;
7102 12 : n->behavior = $7;
7103 12 : n->concurrent = true;
7104 12 : $$ = (Node *) n;
7105 : }
7106 : ;
7107 :
7108 : /* object types taking any_name/any_name_list */
7109 : object_type_any_name:
7110 15242 : TABLE { $$ = OBJECT_TABLE; }
7111 192 : | SEQUENCE { $$ = OBJECT_SEQUENCE; }
7112 1046 : | VIEW { $$ = OBJECT_VIEW; }
7113 130 : | MATERIALIZED VIEW { $$ = OBJECT_MATVIEW; }
7114 778 : | INDEX { $$ = OBJECT_INDEX; }
7115 186 : | FOREIGN TABLE { $$ = OBJECT_FOREIGN_TABLE; }
7116 96 : | COLLATION { $$ = OBJECT_COLLATION; }
7117 56 : | CONVERSION_P { $$ = OBJECT_CONVERSION; }
7118 222 : | STATISTICS { $$ = OBJECT_STATISTIC_EXT; }
7119 20 : | TEXT_P SEARCH PARSER { $$ = OBJECT_TSPARSER; }
7120 2814 : | TEXT_P SEARCH DICTIONARY { $$ = OBJECT_TSDICTIONARY; }
7121 116 : | TEXT_P SEARCH TEMPLATE { $$ = OBJECT_TSTEMPLATE; }
7122 2818 : | TEXT_P SEARCH CONFIGURATION { $$ = OBJECT_TSCONFIGURATION; }
7123 : ;
7124 :
7125 : /*
7126 : * object types taking name/name_list
7127 : *
7128 : * DROP handles some of them separately
7129 : */
7130 :
7131 : object_type_name:
7132 250 : drop_type_name { $$ = $1; }
7133 238 : | DATABASE { $$ = OBJECT_DATABASE; }
7134 52 : | ROLE { $$ = OBJECT_ROLE; }
7135 10 : | SUBSCRIPTION { $$ = OBJECT_SUBSCRIPTION; }
7136 0 : | TABLESPACE { $$ = OBJECT_TABLESPACE; }
7137 : ;
7138 :
7139 : drop_type_name:
7140 46 : ACCESS METHOD { $$ = OBJECT_ACCESS_METHOD; }
7141 128 : | EVENT TRIGGER { $$ = OBJECT_EVENT_TRIGGER; }
7142 176 : | EXTENSION { $$ = OBJECT_EXTENSION; }
7143 154 : | FOREIGN DATA_P WRAPPER { $$ = OBJECT_FDW; }
7144 154 : | opt_procedural LANGUAGE { $$ = OBJECT_LANGUAGE; }
7145 390 : | PUBLICATION { $$ = OBJECT_PUBLICATION; }
7146 590 : | SCHEMA { $$ = OBJECT_SCHEMA; }
7147 130 : | SERVER { $$ = OBJECT_FOREIGN_SERVER; }
7148 : ;
7149 :
7150 : /* object types attached to a table */
7151 : object_type_name_on_any_name:
7152 166 : POLICY { $$ = OBJECT_POLICY; }
7153 268 : | RULE { $$ = OBJECT_RULE; }
7154 798 : | TRIGGER { $$ = OBJECT_TRIGGER; }
7155 : ;
7156 :
7157 : any_name_list:
7158 26520 : any_name { $$ = list_make1($1); }
7159 4254 : | any_name_list ',' any_name { $$ = lappend($1, $3); }
7160 : ;
7161 :
7162 67620 : any_name: ColId { $$ = list_make1(makeString($1)); }
7163 8960 : | ColId attrs { $$ = lcons(makeString($1), $2); }
7164 : ;
7165 :
7166 : attrs: '.' attr_name
7167 126836 : { $$ = list_make1(makeString($2)); }
7168 : | attrs '.' attr_name
7169 64 : { $$ = lappend($1, makeString($3)); }
7170 : ;
7171 :
7172 : type_name_list:
7173 1068 : Typename { $$ = list_make1($1); }
7174 96 : | type_name_list ',' Typename { $$ = lappend($1, $3); }
7175 : ;
7176 :
7177 : /*****************************************************************************
7178 : *
7179 : * QUERY:
7180 : * truncate table relname1, relname2, ...
7181 : *
7182 : *****************************************************************************/
7183 :
7184 : TruncateStmt:
7185 : TRUNCATE opt_table relation_expr_list opt_restart_seqs opt_drop_behavior
7186 : {
7187 1750 : TruncateStmt *n = makeNode(TruncateStmt);
7188 :
7189 1750 : n->relations = $3;
7190 1750 : n->restart_seqs = $4;
7191 1750 : n->behavior = $5;
7192 1750 : $$ = (Node *) n;
7193 : }
7194 : ;
7195 :
7196 : opt_restart_seqs:
7197 24 : CONTINUE_P IDENTITY_P { $$ = false; }
7198 22 : | RESTART IDENTITY_P { $$ = true; }
7199 1704 : | /* EMPTY */ { $$ = false; }
7200 : ;
7201 :
7202 : /*****************************************************************************
7203 : *
7204 : * COMMENT ON <object> IS <text>
7205 : *
7206 : *****************************************************************************/
7207 :
7208 : CommentStmt:
7209 : COMMENT ON object_type_any_name any_name IS comment_text
7210 : {
7211 5898 : CommentStmt *n = makeNode(CommentStmt);
7212 :
7213 5898 : n->objtype = $3;
7214 5898 : n->object = (Node *) $4;
7215 5898 : n->comment = $6;
7216 5898 : $$ = (Node *) n;
7217 : }
7218 : | COMMENT ON COLUMN any_name IS comment_text
7219 : {
7220 114 : CommentStmt *n = makeNode(CommentStmt);
7221 :
7222 114 : n->objtype = OBJECT_COLUMN;
7223 114 : n->object = (Node *) $4;
7224 114 : n->comment = $6;
7225 114 : $$ = (Node *) n;
7226 : }
7227 : | COMMENT ON object_type_name name IS comment_text
7228 : {
7229 488 : CommentStmt *n = makeNode(CommentStmt);
7230 :
7231 488 : n->objtype = $3;
7232 488 : n->object = (Node *) makeString($4);
7233 488 : n->comment = $6;
7234 488 : $$ = (Node *) n;
7235 : }
7236 : | COMMENT ON TYPE_P Typename IS comment_text
7237 : {
7238 56 : CommentStmt *n = makeNode(CommentStmt);
7239 :
7240 56 : n->objtype = OBJECT_TYPE;
7241 56 : n->object = (Node *) $4;
7242 56 : n->comment = $6;
7243 56 : $$ = (Node *) n;
7244 : }
7245 : | COMMENT ON DOMAIN_P Typename IS comment_text
7246 : {
7247 8 : CommentStmt *n = makeNode(CommentStmt);
7248 :
7249 8 : n->objtype = OBJECT_DOMAIN;
7250 8 : n->object = (Node *) $4;
7251 8 : n->comment = $6;
7252 8 : $$ = (Node *) n;
7253 : }
7254 : | COMMENT ON AGGREGATE aggregate_with_argtypes IS comment_text
7255 : {
7256 40 : CommentStmt *n = makeNode(CommentStmt);
7257 :
7258 40 : n->objtype = OBJECT_AGGREGATE;
7259 40 : n->object = (Node *) $4;
7260 40 : n->comment = $6;
7261 40 : $$ = (Node *) n;
7262 : }
7263 : | COMMENT ON FUNCTION function_with_argtypes IS comment_text
7264 : {
7265 170 : CommentStmt *n = makeNode(CommentStmt);
7266 :
7267 170 : n->objtype = OBJECT_FUNCTION;
7268 170 : n->object = (Node *) $4;
7269 170 : n->comment = $6;
7270 170 : $$ = (Node *) n;
7271 : }
7272 : | COMMENT ON OPERATOR operator_with_argtypes IS comment_text
7273 : {
7274 18 : CommentStmt *n = makeNode(CommentStmt);
7275 :
7276 18 : n->objtype = OBJECT_OPERATOR;
7277 18 : n->object = (Node *) $4;
7278 18 : n->comment = $6;
7279 18 : $$ = (Node *) n;
7280 : }
7281 : | COMMENT ON CONSTRAINT name ON any_name IS comment_text
7282 : {
7283 150 : CommentStmt *n = makeNode(CommentStmt);
7284 :
7285 150 : n->objtype = OBJECT_TABCONSTRAINT;
7286 150 : n->object = (Node *) lappend($6, makeString($4));
7287 150 : n->comment = $8;
7288 150 : $$ = (Node *) n;
7289 : }
7290 : | COMMENT ON CONSTRAINT name ON DOMAIN_P any_name IS comment_text
7291 : {
7292 48 : CommentStmt *n = makeNode(CommentStmt);
7293 :
7294 48 : n->objtype = OBJECT_DOMCONSTRAINT;
7295 : /*
7296 : * should use Typename not any_name in the production, but
7297 : * there's a shift/reduce conflict if we do that, so fix it
7298 : * up here.
7299 : */
7300 48 : n->object = (Node *) list_make2(makeTypeNameFromNameList($7), makeString($4));
7301 48 : n->comment = $9;
7302 48 : $$ = (Node *) n;
7303 : }
7304 : | COMMENT ON object_type_name_on_any_name name ON any_name IS comment_text
7305 : {
7306 42 : CommentStmt *n = makeNode(CommentStmt);
7307 :
7308 42 : n->objtype = $3;
7309 42 : n->object = (Node *) lappend($6, makeString($4));
7310 42 : n->comment = $8;
7311 42 : $$ = (Node *) n;
7312 : }
7313 : | COMMENT ON PROCEDURE function_with_argtypes IS comment_text
7314 : {
7315 0 : CommentStmt *n = makeNode(CommentStmt);
7316 :
7317 0 : n->objtype = OBJECT_PROCEDURE;
7318 0 : n->object = (Node *) $4;
7319 0 : n->comment = $6;
7320 0 : $$ = (Node *) n;
7321 : }
7322 : | COMMENT ON ROUTINE function_with_argtypes IS comment_text
7323 : {
7324 0 : CommentStmt *n = makeNode(CommentStmt);
7325 :
7326 0 : n->objtype = OBJECT_ROUTINE;
7327 0 : n->object = (Node *) $4;
7328 0 : n->comment = $6;
7329 0 : $$ = (Node *) n;
7330 : }
7331 : | COMMENT ON TRANSFORM FOR Typename LANGUAGE name IS comment_text
7332 : {
7333 14 : CommentStmt *n = makeNode(CommentStmt);
7334 :
7335 14 : n->objtype = OBJECT_TRANSFORM;
7336 14 : n->object = (Node *) list_make2($5, makeString($7));
7337 14 : n->comment = $9;
7338 14 : $$ = (Node *) n;
7339 : }
7340 : | COMMENT ON OPERATOR CLASS any_name USING name IS comment_text
7341 : {
7342 0 : CommentStmt *n = makeNode(CommentStmt);
7343 :
7344 0 : n->objtype = OBJECT_OPCLASS;
7345 0 : n->object = (Node *) lcons(makeString($7), $5);
7346 0 : n->comment = $9;
7347 0 : $$ = (Node *) n;
7348 : }
7349 : | COMMENT ON OPERATOR FAMILY any_name USING name IS comment_text
7350 : {
7351 0 : CommentStmt *n = makeNode(CommentStmt);
7352 :
7353 0 : n->objtype = OBJECT_OPFAMILY;
7354 0 : n->object = (Node *) lcons(makeString($7), $5);
7355 0 : n->comment = $9;
7356 0 : $$ = (Node *) n;
7357 : }
7358 : | COMMENT ON LARGE_P OBJECT_P NumericOnly IS comment_text
7359 : {
7360 42 : CommentStmt *n = makeNode(CommentStmt);
7361 :
7362 42 : n->objtype = OBJECT_LARGEOBJECT;
7363 42 : n->object = (Node *) $5;
7364 42 : n->comment = $7;
7365 42 : $$ = (Node *) n;
7366 : }
7367 : | COMMENT ON CAST '(' Typename AS Typename ')' IS comment_text
7368 : {
7369 0 : CommentStmt *n = makeNode(CommentStmt);
7370 :
7371 0 : n->objtype = OBJECT_CAST;
7372 0 : n->object = (Node *) list_make2($5, $7);
7373 0 : n->comment = $10;
7374 0 : $$ = (Node *) n;
7375 : }
7376 : ;
7377 :
7378 : comment_text:
7379 6984 : Sconst { $$ = $1; }
7380 104 : | NULL_P { $$ = NULL; }
7381 : ;
7382 :
7383 :
7384 : /*****************************************************************************
7385 : *
7386 : * SECURITY LABEL [FOR <provider>] ON <object> IS <label>
7387 : *
7388 : * As with COMMENT ON, <object> can refer to various types of database
7389 : * objects (e.g. TABLE, COLUMN, etc.).
7390 : *
7391 : *****************************************************************************/
7392 :
7393 : SecLabelStmt:
7394 : SECURITY LABEL opt_provider ON object_type_any_name any_name
7395 : IS security_label
7396 : {
7397 48 : SecLabelStmt *n = makeNode(SecLabelStmt);
7398 :
7399 48 : n->provider = $3;
7400 48 : n->objtype = $5;
7401 48 : n->object = (Node *) $6;
7402 48 : n->label = $8;
7403 48 : $$ = (Node *) n;
7404 : }
7405 : | SECURITY LABEL opt_provider ON COLUMN any_name
7406 : IS security_label
7407 : {
7408 4 : SecLabelStmt *n = makeNode(SecLabelStmt);
7409 :
7410 4 : n->provider = $3;
7411 4 : n->objtype = OBJECT_COLUMN;
7412 4 : n->object = (Node *) $6;
7413 4 : n->label = $8;
7414 4 : $$ = (Node *) n;
7415 : }
7416 : | SECURITY LABEL opt_provider ON object_type_name name
7417 : IS security_label
7418 : {
7419 44 : SecLabelStmt *n = makeNode(SecLabelStmt);
7420 :
7421 44 : n->provider = $3;
7422 44 : n->objtype = $5;
7423 44 : n->object = (Node *) makeString($6);
7424 44 : n->label = $8;
7425 44 : $$ = (Node *) n;
7426 : }
7427 : | SECURITY LABEL opt_provider ON TYPE_P Typename
7428 : IS security_label
7429 : {
7430 0 : SecLabelStmt *n = makeNode(SecLabelStmt);
7431 :
7432 0 : n->provider = $3;
7433 0 : n->objtype = OBJECT_TYPE;
7434 0 : n->object = (Node *) $6;
7435 0 : n->label = $8;
7436 0 : $$ = (Node *) n;
7437 : }
7438 : | SECURITY LABEL opt_provider ON DOMAIN_P Typename
7439 : IS security_label
7440 : {
7441 2 : SecLabelStmt *n = makeNode(SecLabelStmt);
7442 :
7443 2 : n->provider = $3;
7444 2 : n->objtype = OBJECT_DOMAIN;
7445 2 : n->object = (Node *) $6;
7446 2 : n->label = $8;
7447 2 : $$ = (Node *) n;
7448 : }
7449 : | SECURITY LABEL opt_provider ON AGGREGATE aggregate_with_argtypes
7450 : IS security_label
7451 : {
7452 0 : SecLabelStmt *n = makeNode(SecLabelStmt);
7453 :
7454 0 : n->provider = $3;
7455 0 : n->objtype = OBJECT_AGGREGATE;
7456 0 : n->object = (Node *) $6;
7457 0 : n->label = $8;
7458 0 : $$ = (Node *) n;
7459 : }
7460 : | SECURITY LABEL opt_provider ON FUNCTION function_with_argtypes
7461 : IS security_label
7462 : {
7463 2 : SecLabelStmt *n = makeNode(SecLabelStmt);
7464 :
7465 2 : n->provider = $3;
7466 2 : n->objtype = OBJECT_FUNCTION;
7467 2 : n->object = (Node *) $6;
7468 2 : n->label = $8;
7469 2 : $$ = (Node *) n;
7470 : }
7471 : | SECURITY LABEL opt_provider ON LARGE_P OBJECT_P NumericOnly
7472 : IS security_label
7473 : {
7474 18 : SecLabelStmt *n = makeNode(SecLabelStmt);
7475 :
7476 18 : n->provider = $3;
7477 18 : n->objtype = OBJECT_LARGEOBJECT;
7478 18 : n->object = (Node *) $7;
7479 18 : n->label = $9;
7480 18 : $$ = (Node *) n;
7481 : }
7482 : | SECURITY LABEL opt_provider ON PROCEDURE function_with_argtypes
7483 : IS security_label
7484 : {
7485 0 : SecLabelStmt *n = makeNode(SecLabelStmt);
7486 :
7487 0 : n->provider = $3;
7488 0 : n->objtype = OBJECT_PROCEDURE;
7489 0 : n->object = (Node *) $6;
7490 0 : n->label = $8;
7491 0 : $$ = (Node *) n;
7492 : }
7493 : | SECURITY LABEL opt_provider ON ROUTINE function_with_argtypes
7494 : IS security_label
7495 : {
7496 0 : SecLabelStmt *n = makeNode(SecLabelStmt);
7497 :
7498 0 : n->provider = $3;
7499 0 : n->objtype = OBJECT_ROUTINE;
7500 0 : n->object = (Node *) $6;
7501 0 : n->label = $8;
7502 0 : $$ = (Node *) n;
7503 : }
7504 : ;
7505 :
7506 28 : opt_provider: FOR NonReservedWord_or_Sconst { $$ = $2; }
7507 90 : | /* EMPTY */ { $$ = NULL; }
7508 : ;
7509 :
7510 118 : security_label: Sconst { $$ = $1; }
7511 0 : | NULL_P { $$ = NULL; }
7512 : ;
7513 :
7514 : /*****************************************************************************
7515 : *
7516 : * QUERY:
7517 : * fetch/move
7518 : *
7519 : *****************************************************************************/
7520 :
7521 : FetchStmt: FETCH fetch_args
7522 : {
7523 7644 : FetchStmt *n = (FetchStmt *) $2;
7524 :
7525 7644 : n->ismove = false;
7526 7644 : $$ = (Node *) n;
7527 : }
7528 : | MOVE fetch_args
7529 : {
7530 68 : FetchStmt *n = (FetchStmt *) $2;
7531 :
7532 68 : n->ismove = true;
7533 68 : $$ = (Node *) n;
7534 : }
7535 : ;
7536 :
7537 : fetch_args: cursor_name
7538 : {
7539 272 : FetchStmt *n = makeNode(FetchStmt);
7540 :
7541 272 : n->portalname = $1;
7542 272 : n->direction = FETCH_FORWARD;
7543 272 : n->howMany = 1;
7544 272 : n->location = -1;
7545 272 : n->direction_keyword = FETCH_KEYWORD_NONE;
7546 272 : $$ = (Node *) n;
7547 : }
7548 : | from_in cursor_name
7549 : {
7550 218 : FetchStmt *n = makeNode(FetchStmt);
7551 :
7552 218 : n->portalname = $2;
7553 218 : n->direction = FETCH_FORWARD;
7554 218 : n->howMany = 1;
7555 218 : n->location = -1;
7556 218 : n->direction_keyword = FETCH_KEYWORD_NONE;
7557 218 : $$ = (Node *) n;
7558 : }
7559 : | SignedIconst opt_from_in cursor_name
7560 : {
7561 4278 : FetchStmt *n = makeNode(FetchStmt);
7562 :
7563 4278 : n->portalname = $3;
7564 4278 : n->direction = FETCH_FORWARD;
7565 4278 : n->howMany = $1;
7566 4278 : n->location = @1;
7567 4278 : n->direction_keyword = FETCH_KEYWORD_NONE;
7568 4278 : $$ = (Node *) n;
7569 : }
7570 : | NEXT opt_from_in cursor_name
7571 : {
7572 2010 : FetchStmt *n = makeNode(FetchStmt);
7573 :
7574 2010 : n->portalname = $3;
7575 2010 : n->direction = FETCH_FORWARD;
7576 2010 : n->howMany = 1;
7577 2010 : n->location = -1;
7578 2010 : n->direction_keyword = FETCH_KEYWORD_NEXT;
7579 2010 : $$ = (Node *) n;
7580 : }
7581 : | PRIOR opt_from_in cursor_name
7582 : {
7583 32 : FetchStmt *n = makeNode(FetchStmt);
7584 :
7585 32 : n->portalname = $3;
7586 32 : n->direction = FETCH_BACKWARD;
7587 32 : n->howMany = 1;
7588 32 : n->location = -1;
7589 32 : n->direction_keyword = FETCH_KEYWORD_PRIOR;
7590 32 : $$ = (Node *) n;
7591 : }
7592 : | FIRST_P opt_from_in cursor_name
7593 : {
7594 26 : FetchStmt *n = makeNode(FetchStmt);
7595 :
7596 26 : n->portalname = $3;
7597 26 : n->direction = FETCH_ABSOLUTE;
7598 26 : n->howMany = 1;
7599 26 : n->location = -1;
7600 26 : n->direction_keyword = FETCH_KEYWORD_FIRST;
7601 26 : $$ = (Node *) n;
7602 : }
7603 : | LAST_P opt_from_in cursor_name
7604 : {
7605 20 : FetchStmt *n = makeNode(FetchStmt);
7606 :
7607 20 : n->portalname = $3;
7608 20 : n->direction = FETCH_ABSOLUTE;
7609 20 : n->howMany = -1;
7610 20 : n->location = -1;
7611 20 : n->direction_keyword = FETCH_KEYWORD_LAST;
7612 20 : $$ = (Node *) n;
7613 : }
7614 : | ABSOLUTE_P SignedIconst opt_from_in cursor_name
7615 : {
7616 94 : FetchStmt *n = makeNode(FetchStmt);
7617 :
7618 94 : n->portalname = $4;
7619 94 : n->direction = FETCH_ABSOLUTE;
7620 94 : n->howMany = $2;
7621 94 : n->location = @2;
7622 94 : n->direction_keyword = FETCH_KEYWORD_ABSOLUTE;
7623 94 : $$ = (Node *) n;
7624 : }
7625 : | RELATIVE_P SignedIconst opt_from_in cursor_name
7626 : {
7627 36 : FetchStmt *n = makeNode(FetchStmt);
7628 :
7629 36 : n->portalname = $4;
7630 36 : n->direction = FETCH_RELATIVE;
7631 36 : n->howMany = $2;
7632 36 : n->location = @2;
7633 36 : n->direction_keyword = FETCH_KEYWORD_RELATIVE;
7634 36 : $$ = (Node *) n;
7635 : }
7636 : | ALL opt_from_in cursor_name
7637 : {
7638 270 : FetchStmt *n = makeNode(FetchStmt);
7639 :
7640 270 : n->portalname = $3;
7641 270 : n->direction = FETCH_FORWARD;
7642 270 : n->howMany = FETCH_ALL;
7643 270 : n->location = -1;
7644 270 : n->direction_keyword = FETCH_KEYWORD_ALL;
7645 270 : $$ = (Node *) n;
7646 : }
7647 : | FORWARD opt_from_in cursor_name
7648 : {
7649 30 : FetchStmt *n = makeNode(FetchStmt);
7650 :
7651 30 : n->portalname = $3;
7652 30 : n->direction = FETCH_FORWARD;
7653 30 : n->howMany = 1;
7654 30 : n->location = -1;
7655 30 : n->direction_keyword = FETCH_KEYWORD_FORWARD;
7656 30 : $$ = (Node *) n;
7657 : }
7658 : | FORWARD SignedIconst opt_from_in cursor_name
7659 : {
7660 12 : FetchStmt *n = makeNode(FetchStmt);
7661 :
7662 12 : n->portalname = $4;
7663 12 : n->direction = FETCH_FORWARD;
7664 12 : n->howMany = $2;
7665 12 : n->location = @2;
7666 12 : n->direction_keyword = FETCH_KEYWORD_FORWARD;
7667 12 : $$ = (Node *) n;
7668 : }
7669 : | FORWARD ALL opt_from_in cursor_name
7670 : {
7671 16 : FetchStmt *n = makeNode(FetchStmt);
7672 :
7673 16 : n->portalname = $4;
7674 16 : n->direction = FETCH_FORWARD;
7675 16 : n->howMany = FETCH_ALL;
7676 16 : n->location = -1;
7677 16 : n->direction_keyword = FETCH_KEYWORD_FORWARD_ALL;
7678 16 : $$ = (Node *) n;
7679 : }
7680 : | BACKWARD opt_from_in cursor_name
7681 : {
7682 80 : FetchStmt *n = makeNode(FetchStmt);
7683 :
7684 80 : n->portalname = $3;
7685 80 : n->direction = FETCH_BACKWARD;
7686 80 : n->howMany = 1;
7687 80 : n->location = -1;
7688 80 : n->direction_keyword = FETCH_KEYWORD_BACKWARD;
7689 80 : $$ = (Node *) n;
7690 : }
7691 : | BACKWARD SignedIconst opt_from_in cursor_name
7692 : {
7693 226 : FetchStmt *n = makeNode(FetchStmt);
7694 :
7695 226 : n->portalname = $4;
7696 226 : n->direction = FETCH_BACKWARD;
7697 226 : n->howMany = $2;
7698 226 : n->location = @2;
7699 226 : n->direction_keyword = FETCH_KEYWORD_BACKWARD;
7700 226 : $$ = (Node *) n;
7701 : }
7702 : | BACKWARD ALL opt_from_in cursor_name
7703 : {
7704 92 : FetchStmt *n = makeNode(FetchStmt);
7705 :
7706 92 : n->portalname = $4;
7707 92 : n->direction = FETCH_BACKWARD;
7708 92 : n->howMany = FETCH_ALL;
7709 92 : n->location = -1;
7710 92 : n->direction_keyword = FETCH_KEYWORD_BACKWARD_ALL;
7711 92 : $$ = (Node *) n;
7712 : }
7713 : ;
7714 :
7715 : from_in: FROM
7716 : | IN_P
7717 : ;
7718 :
7719 : opt_from_in: from_in
7720 : | /* EMPTY */
7721 : ;
7722 :
7723 :
7724 : /*****************************************************************************
7725 : *
7726 : * GRANT and REVOKE statements
7727 : *
7728 : *****************************************************************************/
7729 :
7730 : GrantStmt: GRANT privileges ON privilege_target TO grantee_list
7731 : opt_grant_grant_option opt_granted_by
7732 : {
7733 11606 : GrantStmt *n = makeNode(GrantStmt);
7734 :
7735 11606 : n->is_grant = true;
7736 11606 : n->privileges = $2;
7737 11606 : n->targtype = ($4)->targtype;
7738 11606 : n->objtype = ($4)->objtype;
7739 11606 : n->objects = ($4)->objs;
7740 11606 : n->grantees = $6;
7741 11606 : n->grant_option = $7;
7742 11606 : n->grantor = $8;
7743 11606 : $$ = (Node *) n;
7744 : }
7745 : ;
7746 :
7747 : RevokeStmt:
7748 : REVOKE privileges ON privilege_target
7749 : FROM grantee_list opt_granted_by opt_drop_behavior
7750 : {
7751 10262 : GrantStmt *n = makeNode(GrantStmt);
7752 :
7753 10262 : n->is_grant = false;
7754 10262 : n->grant_option = false;
7755 10262 : n->privileges = $2;
7756 10262 : n->targtype = ($4)->targtype;
7757 10262 : n->objtype = ($4)->objtype;
7758 10262 : n->objects = ($4)->objs;
7759 10262 : n->grantees = $6;
7760 10262 : n->grantor = $7;
7761 10262 : n->behavior = $8;
7762 10262 : $$ = (Node *) n;
7763 : }
7764 : | REVOKE GRANT OPTION FOR privileges ON privilege_target
7765 : FROM grantee_list opt_granted_by opt_drop_behavior
7766 : {
7767 16 : GrantStmt *n = makeNode(GrantStmt);
7768 :
7769 16 : n->is_grant = false;
7770 16 : n->grant_option = true;
7771 16 : n->privileges = $5;
7772 16 : n->targtype = ($7)->targtype;
7773 16 : n->objtype = ($7)->objtype;
7774 16 : n->objects = ($7)->objs;
7775 16 : n->grantees = $9;
7776 16 : n->grantor = $10;
7777 16 : n->behavior = $11;
7778 16 : $$ = (Node *) n;
7779 : }
7780 : ;
7781 :
7782 :
7783 : /*
7784 : * Privilege names are represented as strings; the validity of the privilege
7785 : * names gets checked at execution. This is a bit annoying but we have little
7786 : * choice because of the syntactic conflict with lists of role names in
7787 : * GRANT/REVOKE. What's more, we have to call out in the "privilege"
7788 : * production any reserved keywords that need to be usable as privilege names.
7789 : */
7790 :
7791 : /* either ALL [PRIVILEGES] or a list of individual privileges */
7792 : privileges: privilege_list
7793 19270 : { $$ = $1; }
7794 : | ALL
7795 2694 : { $$ = NIL; }
7796 : | ALL PRIVILEGES
7797 120 : { $$ = NIL; }
7798 : | ALL '(' columnList ')'
7799 : {
7800 18 : AccessPriv *n = makeNode(AccessPriv);
7801 :
7802 18 : n->priv_name = NULL;
7803 18 : n->cols = $3;
7804 18 : $$ = list_make1(n);
7805 : }
7806 : | ALL PRIVILEGES '(' columnList ')'
7807 : {
7808 0 : AccessPriv *n = makeNode(AccessPriv);
7809 :
7810 0 : n->priv_name = NULL;
7811 0 : n->cols = $4;
7812 0 : $$ = list_make1(n);
7813 : }
7814 : ;
7815 :
7816 20180 : privilege_list: privilege { $$ = list_make1($1); }
7817 550 : | privilege_list ',' privilege { $$ = lappend($1, $3); }
7818 : ;
7819 :
7820 : privilege: SELECT opt_column_list
7821 : {
7822 9214 : AccessPriv *n = makeNode(AccessPriv);
7823 :
7824 9214 : n->priv_name = pstrdup($1);
7825 9214 : n->cols = $2;
7826 9214 : $$ = n;
7827 : }
7828 : | REFERENCES opt_column_list
7829 : {
7830 14 : AccessPriv *n = makeNode(AccessPriv);
7831 :
7832 14 : n->priv_name = pstrdup($1);
7833 14 : n->cols = $2;
7834 14 : $$ = n;
7835 : }
7836 : | CREATE opt_column_list
7837 : {
7838 290 : AccessPriv *n = makeNode(AccessPriv);
7839 :
7840 290 : n->priv_name = pstrdup($1);
7841 290 : n->cols = $2;
7842 290 : $$ = n;
7843 : }
7844 : | ALTER SYSTEM_P
7845 : {
7846 24 : AccessPriv *n = makeNode(AccessPriv);
7847 24 : n->priv_name = pstrdup("alter system");
7848 24 : n->cols = NIL;
7849 24 : $$ = n;
7850 : }
7851 : | ColId opt_column_list
7852 : {
7853 11188 : AccessPriv *n = makeNode(AccessPriv);
7854 :
7855 11188 : n->priv_name = $1;
7856 11188 : n->cols = $2;
7857 11188 : $$ = n;
7858 : }
7859 : ;
7860 :
7861 : parameter_name_list:
7862 : parameter_name
7863 : {
7864 74 : $$ = list_make1(makeString($1));
7865 : }
7866 : | parameter_name_list ',' parameter_name
7867 : {
7868 50 : $$ = lappend($1, makeString($3));
7869 : }
7870 : ;
7871 :
7872 : parameter_name:
7873 : ColId
7874 : {
7875 124 : $$ = $1;
7876 : }
7877 : | parameter_name '.' ColId
7878 : {
7879 30 : $$ = psprintf("%s.%s", $1, $3);
7880 : }
7881 : ;
7882 :
7883 :
7884 : /* Don't bother trying to fold the first two rules into one using
7885 : * opt_table. You're going to get conflicts.
7886 : */
7887 : privilege_target:
7888 : qualified_name_list
7889 : {
7890 11244 : PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
7891 :
7892 11244 : n->targtype = ACL_TARGET_OBJECT;
7893 11244 : n->objtype = OBJECT_TABLE;
7894 11244 : n->objs = $1;
7895 11244 : $$ = n;
7896 : }
7897 : | TABLE qualified_name_list
7898 : {
7899 388 : PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
7900 :
7901 388 : n->targtype = ACL_TARGET_OBJECT;
7902 388 : n->objtype = OBJECT_TABLE;
7903 388 : n->objs = $2;
7904 388 : $$ = n;
7905 : }
7906 : | SEQUENCE qualified_name_list
7907 : {
7908 22 : PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
7909 :
7910 22 : n->targtype = ACL_TARGET_OBJECT;
7911 22 : n->objtype = OBJECT_SEQUENCE;
7912 22 : n->objs = $2;
7913 22 : $$ = n;
7914 : }
7915 : | FOREIGN DATA_P WRAPPER name_list
7916 : {
7917 92 : PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
7918 :
7919 92 : n->targtype = ACL_TARGET_OBJECT;
7920 92 : n->objtype = OBJECT_FDW;
7921 92 : n->objs = $4;
7922 92 : $$ = n;
7923 : }
7924 : | FOREIGN SERVER name_list
7925 : {
7926 88 : PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
7927 :
7928 88 : n->targtype = ACL_TARGET_OBJECT;
7929 88 : n->objtype = OBJECT_FOREIGN_SERVER;
7930 88 : n->objs = $3;
7931 88 : $$ = n;
7932 : }
7933 : | FUNCTION function_with_argtypes_list
7934 : {
7935 8932 : PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
7936 :
7937 8932 : n->targtype = ACL_TARGET_OBJECT;
7938 8932 : n->objtype = OBJECT_FUNCTION;
7939 8932 : n->objs = $2;
7940 8932 : $$ = n;
7941 : }
7942 : | PROCEDURE function_with_argtypes_list
7943 : {
7944 42 : PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
7945 :
7946 42 : n->targtype = ACL_TARGET_OBJECT;
7947 42 : n->objtype = OBJECT_PROCEDURE;
7948 42 : n->objs = $2;
7949 42 : $$ = n;
7950 : }
7951 : | ROUTINE function_with_argtypes_list
7952 : {
7953 0 : PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
7954 :
7955 0 : n->targtype = ACL_TARGET_OBJECT;
7956 0 : n->objtype = OBJECT_ROUTINE;
7957 0 : n->objs = $2;
7958 0 : $$ = n;
7959 : }
7960 : | DATABASE name_list
7961 : {
7962 346 : PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
7963 :
7964 346 : n->targtype = ACL_TARGET_OBJECT;
7965 346 : n->objtype = OBJECT_DATABASE;
7966 346 : n->objs = $2;
7967 346 : $$ = n;
7968 : }
7969 : | DOMAIN_P any_name_list
7970 : {
7971 26 : PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
7972 :
7973 26 : n->targtype = ACL_TARGET_OBJECT;
7974 26 : n->objtype = OBJECT_DOMAIN;
7975 26 : n->objs = $2;
7976 26 : $$ = n;
7977 : }
7978 : | LANGUAGE name_list
7979 : {
7980 42 : PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
7981 :
7982 42 : n->targtype = ACL_TARGET_OBJECT;
7983 42 : n->objtype = OBJECT_LANGUAGE;
7984 42 : n->objs = $2;
7985 42 : $$ = n;
7986 : }
7987 : | LARGE_P OBJECT_P NumericOnly_list
7988 : {
7989 90 : PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
7990 :
7991 90 : n->targtype = ACL_TARGET_OBJECT;
7992 90 : n->objtype = OBJECT_LARGEOBJECT;
7993 90 : n->objs = $3;
7994 90 : $$ = n;
7995 : }
7996 : | PARAMETER parameter_name_list
7997 : {
7998 74 : PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
7999 74 : n->targtype = ACL_TARGET_OBJECT;
8000 74 : n->objtype = OBJECT_PARAMETER_ACL;
8001 74 : n->objs = $2;
8002 74 : $$ = n;
8003 : }
8004 : | SCHEMA name_list
8005 : {
8006 362 : PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
8007 :
8008 362 : n->targtype = ACL_TARGET_OBJECT;
8009 362 : n->objtype = OBJECT_SCHEMA;
8010 362 : n->objs = $2;
8011 362 : $$ = n;
8012 : }
8013 : | TABLESPACE name_list
8014 : {
8015 6 : PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
8016 :
8017 6 : n->targtype = ACL_TARGET_OBJECT;
8018 6 : n->objtype = OBJECT_TABLESPACE;
8019 6 : n->objs = $2;
8020 6 : $$ = n;
8021 : }
8022 : | TYPE_P any_name_list
8023 : {
8024 112 : PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
8025 :
8026 112 : n->targtype = ACL_TARGET_OBJECT;
8027 112 : n->objtype = OBJECT_TYPE;
8028 112 : n->objs = $2;
8029 112 : $$ = n;
8030 : }
8031 : | ALL TABLES IN_P SCHEMA name_list
8032 : {
8033 12 : PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
8034 :
8035 12 : n->targtype = ACL_TARGET_ALL_IN_SCHEMA;
8036 12 : n->objtype = OBJECT_TABLE;
8037 12 : n->objs = $5;
8038 12 : $$ = n;
8039 : }
8040 : | ALL SEQUENCES IN_P SCHEMA name_list
8041 : {
8042 0 : PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
8043 :
8044 0 : n->targtype = ACL_TARGET_ALL_IN_SCHEMA;
8045 0 : n->objtype = OBJECT_SEQUENCE;
8046 0 : n->objs = $5;
8047 0 : $$ = n;
8048 : }
8049 : | ALL FUNCTIONS IN_P SCHEMA name_list
8050 : {
8051 6 : PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
8052 :
8053 6 : n->targtype = ACL_TARGET_ALL_IN_SCHEMA;
8054 6 : n->objtype = OBJECT_FUNCTION;
8055 6 : n->objs = $5;
8056 6 : $$ = n;
8057 : }
8058 : | ALL PROCEDURES IN_P SCHEMA name_list
8059 : {
8060 6 : PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
8061 :
8062 6 : n->targtype = ACL_TARGET_ALL_IN_SCHEMA;
8063 6 : n->objtype = OBJECT_PROCEDURE;
8064 6 : n->objs = $5;
8065 6 : $$ = n;
8066 : }
8067 : | ALL ROUTINES IN_P SCHEMA name_list
8068 : {
8069 6 : PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
8070 :
8071 6 : n->targtype = ACL_TARGET_ALL_IN_SCHEMA;
8072 6 : n->objtype = OBJECT_ROUTINE;
8073 6 : n->objs = $5;
8074 6 : $$ = n;
8075 : }
8076 : ;
8077 :
8078 :
8079 : grantee_list:
8080 22090 : grantee { $$ = list_make1($1); }
8081 108 : | grantee_list ',' grantee { $$ = lappend($1, $3); }
8082 : ;
8083 :
8084 : grantee:
8085 22174 : RoleSpec { $$ = $1; }
8086 24 : | GROUP_P RoleSpec { $$ = $2; }
8087 : ;
8088 :
8089 :
8090 : opt_grant_grant_option:
8091 102 : WITH GRANT OPTION { $$ = true; }
8092 11628 : | /*EMPTY*/ { $$ = false; }
8093 : ;
8094 :
8095 : /*****************************************************************************
8096 : *
8097 : * GRANT and REVOKE ROLE statements
8098 : *
8099 : *****************************************************************************/
8100 :
8101 : GrantRoleStmt:
8102 : GRANT privilege_list TO role_list opt_granted_by
8103 : {
8104 576 : GrantRoleStmt *n = makeNode(GrantRoleStmt);
8105 :
8106 576 : n->is_grant = true;
8107 576 : n->granted_roles = $2;
8108 576 : n->grantee_roles = $4;
8109 576 : n->opt = NIL;
8110 576 : n->grantor = $5;
8111 576 : $$ = (Node *) n;
8112 : }
8113 : | GRANT privilege_list TO role_list WITH grant_role_opt_list opt_granted_by
8114 : {
8115 178 : GrantRoleStmt *n = makeNode(GrantRoleStmt);
8116 :
8117 178 : n->is_grant = true;
8118 178 : n->granted_roles = $2;
8119 178 : n->grantee_roles = $4;
8120 178 : n->opt = $6;
8121 178 : n->grantor = $7;
8122 178 : $$ = (Node *) n;
8123 : }
8124 : ;
8125 :
8126 : RevokeRoleStmt:
8127 : REVOKE privilege_list FROM role_list opt_granted_by opt_drop_behavior
8128 : {
8129 90 : GrantRoleStmt *n = makeNode(GrantRoleStmt);
8130 :
8131 90 : n->is_grant = false;
8132 90 : n->opt = NIL;
8133 90 : n->granted_roles = $2;
8134 90 : n->grantee_roles = $4;
8135 90 : n->grantor = $5;
8136 90 : n->behavior = $6;
8137 90 : $$ = (Node *) n;
8138 : }
8139 : | REVOKE ColId OPTION FOR privilege_list FROM role_list opt_granted_by opt_drop_behavior
8140 : {
8141 66 : GrantRoleStmt *n = makeNode(GrantRoleStmt);
8142 : DefElem *opt;
8143 :
8144 66 : opt = makeDefElem(pstrdup($2),
8145 66 : (Node *) makeBoolean(false), @2);
8146 66 : n->is_grant = false;
8147 66 : n->opt = list_make1(opt);
8148 66 : n->granted_roles = $5;
8149 66 : n->grantee_roles = $7;
8150 66 : n->grantor = $8;
8151 66 : n->behavior = $9;
8152 66 : $$ = (Node *) n;
8153 : }
8154 : ;
8155 :
8156 : grant_role_opt_list:
8157 120 : grant_role_opt_list ',' grant_role_opt { $$ = lappend($1, $3); }
8158 178 : | grant_role_opt { $$ = list_make1($1); }
8159 : ;
8160 :
8161 : grant_role_opt:
8162 : ColLabel grant_role_opt_value
8163 : {
8164 298 : $$ = makeDefElem(pstrdup($1), $2, @1);
8165 : }
8166 : ;
8167 :
8168 : grant_role_opt_value:
8169 72 : OPTION { $$ = (Node *) makeBoolean(true); }
8170 112 : | TRUE_P { $$ = (Node *) makeBoolean(true); }
8171 114 : | FALSE_P { $$ = (Node *) makeBoolean(false); }
8172 : ;
8173 :
8174 138 : opt_granted_by: GRANTED BY RoleSpec { $$ = $3; }
8175 22656 : | /*EMPTY*/ { $$ = NULL; }
8176 : ;
8177 :
8178 : /*****************************************************************************
8179 : *
8180 : * ALTER DEFAULT PRIVILEGES statement
8181 : *
8182 : *****************************************************************************/
8183 :
8184 : AlterDefaultPrivilegesStmt:
8185 : ALTER DEFAULT PRIVILEGES DefACLOptionList DefACLAction
8186 : {
8187 206 : AlterDefaultPrivilegesStmt *n = makeNode(AlterDefaultPrivilegesStmt);
8188 :
8189 206 : n->options = $4;
8190 206 : n->action = (GrantStmt *) $5;
8191 206 : $$ = (Node *) n;
8192 : }
8193 : ;
8194 :
8195 : DefACLOptionList:
8196 144 : DefACLOptionList DefACLOption { $$ = lappend($1, $2); }
8197 206 : | /* EMPTY */ { $$ = NIL; }
8198 : ;
8199 :
8200 : DefACLOption:
8201 : IN_P SCHEMA name_list
8202 : {
8203 60 : $$ = makeDefElem("schemas", (Node *) $3, @1);
8204 : }
8205 : | FOR ROLE role_list
8206 : {
8207 84 : $$ = makeDefElem("roles", (Node *) $3, @1);
8208 : }
8209 : | FOR USER role_list
8210 : {
8211 0 : $$ = makeDefElem("roles", (Node *) $3, @1);
8212 : }
8213 : ;
8214 :
8215 : /*
8216 : * This should match GRANT/REVOKE, except that individual target objects
8217 : * are not mentioned and we only allow a subset of object types.
8218 : */
8219 : DefACLAction:
8220 : GRANT privileges ON defacl_privilege_target TO grantee_list
8221 : opt_grant_grant_option
8222 : {
8223 124 : GrantStmt *n = makeNode(GrantStmt);
8224 :
8225 124 : n->is_grant = true;
8226 124 : n->privileges = $2;
8227 124 : n->targtype = ACL_TARGET_DEFAULTS;
8228 124 : n->objtype = $4;
8229 124 : n->objects = NIL;
8230 124 : n->grantees = $6;
8231 124 : n->grant_option = $7;
8232 124 : $$ = (Node *) n;
8233 : }
8234 : | REVOKE privileges ON defacl_privilege_target
8235 : FROM grantee_list opt_drop_behavior
8236 : {
8237 82 : GrantStmt *n = makeNode(GrantStmt);
8238 :
8239 82 : n->is_grant = false;
8240 82 : n->grant_option = false;
8241 82 : n->privileges = $2;
8242 82 : n->targtype = ACL_TARGET_DEFAULTS;
8243 82 : n->objtype = $4;
8244 82 : n->objects = NIL;
8245 82 : n->grantees = $6;
8246 82 : n->behavior = $7;
8247 82 : $$ = (Node *) n;
8248 : }
8249 : | REVOKE GRANT OPTION FOR privileges ON defacl_privilege_target
8250 : FROM grantee_list opt_drop_behavior
8251 : {
8252 0 : GrantStmt *n = makeNode(GrantStmt);
8253 :
8254 0 : n->is_grant = false;
8255 0 : n->grant_option = true;
8256 0 : n->privileges = $5;
8257 0 : n->targtype = ACL_TARGET_DEFAULTS;
8258 0 : n->objtype = $7;
8259 0 : n->objects = NIL;
8260 0 : n->grantees = $9;
8261 0 : n->behavior = $10;
8262 0 : $$ = (Node *) n;
8263 : }
8264 : ;
8265 :
8266 : defacl_privilege_target:
8267 78 : TABLES { $$ = OBJECT_TABLE; }
8268 16 : | FUNCTIONS { $$ = OBJECT_FUNCTION; }
8269 6 : | ROUTINES { $$ = OBJECT_FUNCTION; }
8270 6 : | SEQUENCES { $$ = OBJECT_SEQUENCE; }
8271 34 : | TYPES_P { $$ = OBJECT_TYPE; }
8272 36 : | SCHEMAS { $$ = OBJECT_SCHEMA; }
8273 30 : | LARGE_P OBJECTS_P { $$ = OBJECT_LARGEOBJECT; }
8274 : ;
8275 :
8276 :
8277 : /*****************************************************************************
8278 : *
8279 : * QUERY: CREATE INDEX
8280 : *
8281 : * Note: we cannot put TABLESPACE clause after WHERE clause unless we are
8282 : * willing to make TABLESPACE a fully reserved word.
8283 : *****************************************************************************/
8284 :
8285 : IndexStmt: CREATE opt_unique INDEX opt_concurrently opt_single_name
8286 : ON relation_expr access_method_clause '(' index_params ')'
8287 : opt_include opt_unique_null_treatment opt_reloptions OptTableSpace where_clause
8288 : {
8289 6686 : IndexStmt *n = makeNode(IndexStmt);
8290 :
8291 6686 : n->unique = $2;
8292 6686 : n->concurrent = $4;
8293 6686 : n->idxname = $5;
8294 6686 : n->relation = $7;
8295 6686 : n->accessMethod = $8;
8296 6686 : n->indexParams = $10;
8297 6686 : n->indexIncludingParams = $12;
8298 6686 : n->nulls_not_distinct = !$13;
8299 6686 : n->options = $14;
8300 6686 : n->tableSpace = $15;
8301 6686 : n->whereClause = $16;
8302 6686 : n->excludeOpNames = NIL;
8303 6686 : n->idxcomment = NULL;
8304 6686 : n->indexOid = InvalidOid;
8305 6686 : n->oldNumber = InvalidRelFileNumber;
8306 6686 : n->oldCreateSubid = InvalidSubTransactionId;
8307 6686 : n->oldFirstRelfilelocatorSubid = InvalidSubTransactionId;
8308 6686 : n->primary = false;
8309 6686 : n->isconstraint = false;
8310 6686 : n->deferrable = false;
8311 6686 : n->initdeferred = false;
8312 6686 : n->transformed = false;
8313 6686 : n->if_not_exists = false;
8314 6686 : n->reset_default_tblspc = false;
8315 6686 : $$ = (Node *) n;
8316 : }
8317 : | CREATE opt_unique INDEX opt_concurrently IF_P NOT EXISTS name
8318 : ON relation_expr access_method_clause '(' index_params ')'
8319 : opt_include opt_unique_null_treatment opt_reloptions OptTableSpace where_clause
8320 : {
8321 18 : IndexStmt *n = makeNode(IndexStmt);
8322 :
8323 18 : n->unique = $2;
8324 18 : n->concurrent = $4;
8325 18 : n->idxname = $8;
8326 18 : n->relation = $10;
8327 18 : n->accessMethod = $11;
8328 18 : n->indexParams = $13;
8329 18 : n->indexIncludingParams = $15;
8330 18 : n->nulls_not_distinct = !$16;
8331 18 : n->options = $17;
8332 18 : n->tableSpace = $18;
8333 18 : n->whereClause = $19;
8334 18 : n->excludeOpNames = NIL;
8335 18 : n->idxcomment = NULL;
8336 18 : n->indexOid = InvalidOid;
8337 18 : n->oldNumber = InvalidRelFileNumber;
8338 18 : n->oldCreateSubid = InvalidSubTransactionId;
8339 18 : n->oldFirstRelfilelocatorSubid = InvalidSubTransactionId;
8340 18 : n->primary = false;
8341 18 : n->isconstraint = false;
8342 18 : n->deferrable = false;
8343 18 : n->initdeferred = false;
8344 18 : n->transformed = false;
8345 18 : n->if_not_exists = true;
8346 18 : n->reset_default_tblspc = false;
8347 18 : $$ = (Node *) n;
8348 : }
8349 : ;
8350 :
8351 : opt_unique:
8352 1294 : UNIQUE { $$ = true; }
8353 5416 : | /*EMPTY*/ { $$ = false; }
8354 : ;
8355 :
8356 : access_method_clause:
8357 3024 : USING name { $$ = $2; }
8358 3914 : | /*EMPTY*/ { $$ = DEFAULT_INDEX_TYPE; }
8359 : ;
8360 :
8361 8146 : index_params: index_elem { $$ = list_make1($1); }
8362 2158 : | index_params ',' index_elem { $$ = lappend($1, $3); }
8363 : ;
8364 :
8365 :
8366 : index_elem_options:
8367 : opt_collate opt_qualified_name opt_asc_desc opt_nulls_order
8368 : {
8369 10886 : $$ = makeNode(IndexElem);
8370 10886 : $$->name = NULL;
8371 10886 : $$->expr = NULL;
8372 10886 : $$->indexcolname = NULL;
8373 10886 : $$->collation = $1;
8374 10886 : $$->opclass = $2;
8375 10886 : $$->opclassopts = NIL;
8376 10886 : $$->ordering = $3;
8377 10886 : $$->nulls_ordering = $4;
8378 : }
8379 : | opt_collate any_name reloptions opt_asc_desc opt_nulls_order
8380 : {
8381 142 : $$ = makeNode(IndexElem);
8382 142 : $$->name = NULL;
8383 142 : $$->expr = NULL;
8384 142 : $$->indexcolname = NULL;
8385 142 : $$->collation = $1;
8386 142 : $$->opclass = $2;
8387 142 : $$->opclassopts = $3;
8388 142 : $$->ordering = $4;
8389 142 : $$->nulls_ordering = $5;
8390 : }
8391 : ;
8392 :
8393 : /*
8394 : * Index attributes can be either simple column references, or arbitrary
8395 : * expressions in parens. For backwards-compatibility reasons, we allow
8396 : * an expression that's just a function call to be written without parens.
8397 : */
8398 : index_elem: ColId index_elem_options
8399 : {
8400 9902 : $$ = $2;
8401 9902 : $$->name = $1;
8402 : }
8403 : | func_expr_windowless index_elem_options
8404 : {
8405 610 : $$ = $2;
8406 610 : $$->expr = $1;
8407 : }
8408 : | '(' a_expr ')' index_elem_options
8409 : {
8410 516 : $$ = $4;
8411 516 : $$->expr = $2;
8412 : }
8413 : ;
8414 :
8415 218 : opt_include: INCLUDE '(' index_including_params ')' { $$ = $3; }
8416 6486 : | /* EMPTY */ { $$ = NIL; }
8417 : ;
8418 :
8419 218 : index_including_params: index_elem { $$ = list_make1($1); }
8420 166 : | index_including_params ',' index_elem { $$ = lappend($1, $3); }
8421 : ;
8422 :
8423 192 : opt_collate: COLLATE any_name { $$ = $2; }
8424 16346 : | /*EMPTY*/ { $$ = NIL; }
8425 : ;
8426 :
8427 :
8428 1820 : opt_asc_desc: ASC { $$ = SORTBY_ASC; }
8429 3558 : | DESC { $$ = SORTBY_DESC; }
8430 113114 : | /*EMPTY*/ { $$ = SORTBY_DEFAULT; }
8431 : ;
8432 :
8433 344 : opt_nulls_order: NULLS_LA FIRST_P { $$ = SORTBY_NULLS_FIRST; }
8434 1732 : | NULLS_LA LAST_P { $$ = SORTBY_NULLS_LAST; }
8435 116636 : | /*EMPTY*/ { $$ = SORTBY_NULLS_DEFAULT; }
8436 : ;
8437 :
8438 :
8439 : /*****************************************************************************
8440 : *
8441 : * QUERY:
8442 : * create [or replace] function <fname>
8443 : * [(<type-1> { , <type-n>})]
8444 : * returns <type-r>
8445 : * as <filename or code in language as appropriate>
8446 : * language <lang> [with parameters]
8447 : *
8448 : *****************************************************************************/
8449 :
8450 : CreateFunctionStmt:
8451 : CREATE opt_or_replace FUNCTION func_name func_args_with_defaults
8452 : RETURNS func_return opt_createfunc_opt_list opt_routine_body
8453 : {
8454 24656 : CreateFunctionStmt *n = makeNode(CreateFunctionStmt);
8455 :
8456 24656 : n->is_procedure = false;
8457 24656 : n->replace = $2;
8458 24656 : n->funcname = $4;
8459 24656 : n->parameters = $5;
8460 24656 : n->returnType = $7;
8461 24656 : n->options = $8;
8462 24656 : n->sql_body = $9;
8463 24656 : $$ = (Node *) n;
8464 : }
8465 : | CREATE opt_or_replace FUNCTION func_name func_args_with_defaults
8466 : RETURNS TABLE '(' table_func_column_list ')' opt_createfunc_opt_list opt_routine_body
8467 : {
8468 194 : CreateFunctionStmt *n = makeNode(CreateFunctionStmt);
8469 :
8470 194 : n->is_procedure = false;
8471 194 : n->replace = $2;
8472 194 : n->funcname = $4;
8473 194 : n->parameters = mergeTableFuncParameters($5, $9, yyscanner);
8474 194 : n->returnType = TableFuncTypeName($9);
8475 194 : n->returnType->location = @7;
8476 194 : n->options = $11;
8477 194 : n->sql_body = $12;
8478 194 : $$ = (Node *) n;
8479 : }
8480 : | CREATE opt_or_replace FUNCTION func_name func_args_with_defaults
8481 : opt_createfunc_opt_list opt_routine_body
8482 : {
8483 488 : CreateFunctionStmt *n = makeNode(CreateFunctionStmt);
8484 :
8485 488 : n->is_procedure = false;
8486 488 : n->replace = $2;
8487 488 : n->funcname = $4;
8488 488 : n->parameters = $5;
8489 488 : n->returnType = NULL;
8490 488 : n->options = $6;
8491 488 : n->sql_body = $7;
8492 488 : $$ = (Node *) n;
8493 : }
8494 : | CREATE opt_or_replace PROCEDURE func_name func_args_with_defaults
8495 : opt_createfunc_opt_list opt_routine_body
8496 : {
8497 370 : CreateFunctionStmt *n = makeNode(CreateFunctionStmt);
8498 :
8499 370 : n->is_procedure = true;
8500 370 : n->replace = $2;
8501 370 : n->funcname = $4;
8502 370 : n->parameters = $5;
8503 370 : n->returnType = NULL;
8504 370 : n->options = $6;
8505 370 : n->sql_body = $7;
8506 370 : $$ = (Node *) n;
8507 : }
8508 : ;
8509 :
8510 : opt_or_replace:
8511 10096 : OR REPLACE { $$ = true; }
8512 21070 : | /*EMPTY*/ { $$ = false; }
8513 : ;
8514 :
8515 12118 : func_args: '(' func_args_list ')' { $$ = $2; }
8516 5912 : | '(' ')' { $$ = NIL; }
8517 : ;
8518 :
8519 : func_args_list:
8520 12118 : func_arg { $$ = list_make1($1); }
8521 11396 : | func_args_list ',' func_arg { $$ = lappend($1, $3); }
8522 : ;
8523 :
8524 : function_with_argtypes_list:
8525 12738 : function_with_argtypes { $$ = list_make1($1); }
8526 : | function_with_argtypes_list ',' function_with_argtypes
8527 84 : { $$ = lappend($1, $3); }
8528 : ;
8529 :
8530 : function_with_argtypes:
8531 : func_name func_args
8532 : {
8533 18030 : ObjectWithArgs *n = makeNode(ObjectWithArgs);
8534 :
8535 18030 : n->objname = $1;
8536 18030 : n->objargs = extractArgTypes($2);
8537 18030 : n->objfuncargs = $2;
8538 18030 : $$ = n;
8539 : }
8540 : /*
8541 : * Because of reduce/reduce conflicts, we can't use func_name
8542 : * below, but we can write it out the long way, which actually
8543 : * allows more cases.
8544 : */
8545 : | type_func_name_keyword
8546 : {
8547 0 : ObjectWithArgs *n = makeNode(ObjectWithArgs);
8548 :
8549 0 : n->objname = list_make1(makeString(pstrdup($1)));
8550 0 : n->args_unspecified = true;
8551 0 : $$ = n;
8552 : }
8553 : | ColId
8554 : {
8555 370 : ObjectWithArgs *n = makeNode(ObjectWithArgs);
8556 :
8557 370 : n->objname = list_make1(makeString($1));
8558 370 : n->args_unspecified = true;
8559 370 : $$ = n;
8560 : }
8561 : | ColId indirection
8562 : {
8563 28 : ObjectWithArgs *n = makeNode(ObjectWithArgs);
8564 :
8565 28 : n->objname = check_func_name(lcons(makeString($1), $2),
8566 : yyscanner);
8567 28 : n->args_unspecified = true;
8568 28 : $$ = n;
8569 : }
8570 : ;
8571 :
8572 : /*
8573 : * func_args_with_defaults is separate because we only want to accept
8574 : * defaults in CREATE FUNCTION, not in ALTER etc.
8575 : */
8576 : func_args_with_defaults:
8577 21080 : '(' func_args_with_defaults_list ')' { $$ = $2; }
8578 4628 : | '(' ')' { $$ = NIL; }
8579 : ;
8580 :
8581 : func_args_with_defaults_list:
8582 21080 : func_arg_with_default { $$ = list_make1($1); }
8583 : | func_args_with_defaults_list ',' func_arg_with_default
8584 35956 : { $$ = lappend($1, $3); }
8585 : ;
8586 :
8587 : /*
8588 : * The style with arg_class first is SQL99 standard, but Oracle puts
8589 : * param_name first; accept both since it's likely people will try both
8590 : * anyway. Don't bother trying to save productions by letting arg_class
8591 : * have an empty alternative ... you'll get shift/reduce conflicts.
8592 : *
8593 : * We can catch over-specified arguments here if we want to,
8594 : * but for now better to silently swallow typmod, etc.
8595 : * - thomas 2000-03-22
8596 : */
8597 : func_arg:
8598 : arg_class param_name func_type
8599 : {
8600 16978 : FunctionParameter *n = makeNode(FunctionParameter);
8601 :
8602 16978 : n->name = $2;
8603 16978 : n->argType = $3;
8604 16978 : n->mode = $1;
8605 16978 : n->defexpr = NULL;
8606 16978 : n->location = @1;
8607 16978 : $$ = n;
8608 : }
8609 : | param_name arg_class func_type
8610 : {
8611 420 : FunctionParameter *n = makeNode(FunctionParameter);
8612 :
8613 420 : n->name = $1;
8614 420 : n->argType = $3;
8615 420 : n->mode = $2;
8616 420 : n->defexpr = NULL;
8617 420 : n->location = @1;
8618 420 : $$ = n;
8619 : }
8620 : | param_name func_type
8621 : {
8622 15916 : FunctionParameter *n = makeNode(FunctionParameter);
8623 :
8624 15916 : n->name = $1;
8625 15916 : n->argType = $2;
8626 15916 : n->mode = FUNC_PARAM_DEFAULT;
8627 15916 : n->defexpr = NULL;
8628 15916 : n->location = @1;
8629 15916 : $$ = n;
8630 : }
8631 : | arg_class func_type
8632 : {
8633 328 : FunctionParameter *n = makeNode(FunctionParameter);
8634 :
8635 328 : n->name = NULL;
8636 328 : n->argType = $2;
8637 328 : n->mode = $1;
8638 328 : n->defexpr = NULL;
8639 328 : n->location = @1;
8640 328 : $$ = n;
8641 : }
8642 : | func_type
8643 : {
8644 47808 : FunctionParameter *n = makeNode(FunctionParameter);
8645 :
8646 47808 : n->name = NULL;
8647 47808 : n->argType = $1;
8648 47808 : n->mode = FUNC_PARAM_DEFAULT;
8649 47808 : n->defexpr = NULL;
8650 47808 : n->location = @1;
8651 47808 : $$ = n;
8652 : }
8653 : ;
8654 :
8655 : /* INOUT is SQL99 standard, IN OUT is for Oracle compatibility */
8656 4038 : arg_class: IN_P { $$ = FUNC_PARAM_IN; }
8657 12912 : | OUT_P { $$ = FUNC_PARAM_OUT; }
8658 198 : | INOUT { $$ = FUNC_PARAM_INOUT; }
8659 0 : | IN_P OUT_P { $$ = FUNC_PARAM_INOUT; }
8660 578 : | VARIADIC { $$ = FUNC_PARAM_VARIADIC; }
8661 : ;
8662 :
8663 : /*
8664 : * Ideally param_name should be ColId, but that causes too many conflicts.
8665 : */
8666 : param_name: type_function_name
8667 : ;
8668 :
8669 : func_return:
8670 : func_type
8671 : {
8672 : /* We can catch over-specified results here if we want to,
8673 : * but for now better to silently swallow typmod, etc.
8674 : * - thomas 2000-03-22
8675 : */
8676 24656 : $$ = $1;
8677 : }
8678 : ;
8679 :
8680 : /*
8681 : * We would like to make the %TYPE productions here be ColId attrs etc,
8682 : * but that causes reduce/reduce conflicts. type_function_name
8683 : * is next best choice.
8684 : */
8685 127300 : func_type: Typename { $$ = $1; }
8686 : | type_function_name attrs '%' TYPE_P
8687 : {
8688 18 : $$ = makeTypeNameFromNameList(lcons(makeString($1), $2));
8689 18 : $$->pct_type = true;
8690 18 : $$->location = @1;
8691 : }
8692 : | SETOF type_function_name attrs '%' TYPE_P
8693 : {
8694 6 : $$ = makeTypeNameFromNameList(lcons(makeString($2), $3));
8695 6 : $$->pct_type = true;
8696 6 : $$->setof = true;
8697 6 : $$->location = @2;
8698 : }
8699 : ;
8700 :
8701 : func_arg_with_default:
8702 : func_arg
8703 : {
8704 50502 : $$ = $1;
8705 : }
8706 : | func_arg DEFAULT a_expr
8707 : {
8708 6338 : $$ = $1;
8709 6338 : $$->defexpr = $3;
8710 : }
8711 : | func_arg '=' a_expr
8712 : {
8713 196 : $$ = $1;
8714 196 : $$->defexpr = $3;
8715 : }
8716 : ;
8717 :
8718 : /* Aggregate args can be most things that function args can be */
8719 : aggr_arg: func_arg
8720 : {
8721 900 : if (!($1->mode == FUNC_PARAM_DEFAULT ||
8722 60 : $1->mode == FUNC_PARAM_IN ||
8723 60 : $1->mode == FUNC_PARAM_VARIADIC))
8724 0 : ereport(ERROR,
8725 : (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
8726 : errmsg("aggregates cannot have output arguments"),
8727 : parser_errposition(@1)));
8728 900 : $$ = $1;
8729 : }
8730 : ;
8731 :
8732 : /*
8733 : * The SQL standard offers no guidance on how to declare aggregate argument
8734 : * lists, since it doesn't have CREATE AGGREGATE etc. We accept these cases:
8735 : *
8736 : * (*) - normal agg with no args
8737 : * (aggr_arg,...) - normal agg with args
8738 : * (ORDER BY aggr_arg,...) - ordered-set agg with no direct args
8739 : * (aggr_arg,... ORDER BY aggr_arg,...) - ordered-set agg with direct args
8740 : *
8741 : * The zero-argument case is spelled with '*' for consistency with COUNT(*).
8742 : *
8743 : * An additional restriction is that if the direct-args list ends in a
8744 : * VARIADIC item, the ordered-args list must contain exactly one item that
8745 : * is also VARIADIC with the same type. This allows us to collapse the two
8746 : * VARIADIC items into one, which is necessary to represent the aggregate in
8747 : * pg_proc. We check this at the grammar stage so that we can return a list
8748 : * in which the second VARIADIC item is already discarded, avoiding extra work
8749 : * in cases such as DROP AGGREGATE.
8750 : *
8751 : * The return value of this production is a two-element list, in which the
8752 : * first item is a sublist of FunctionParameter nodes (with any duplicate
8753 : * VARIADIC item already dropped, as per above) and the second is an Integer
8754 : * node, containing -1 if there was no ORDER BY and otherwise the number
8755 : * of argument declarations before the ORDER BY. (If this number is equal
8756 : * to the first sublist's length, then we dropped a duplicate VARIADIC item.)
8757 : * This representation is passed as-is to CREATE AGGREGATE; for operations
8758 : * on existing aggregates, we can just apply extractArgTypes to the first
8759 : * sublist.
8760 : */
8761 : aggr_args: '(' '*' ')'
8762 : {
8763 136 : $$ = list_make2(NIL, makeInteger(-1));
8764 : }
8765 : | '(' aggr_args_list ')'
8766 : {
8767 732 : $$ = list_make2($2, makeInteger(-1));
8768 : }
8769 : | '(' ORDER BY aggr_args_list ')'
8770 : {
8771 6 : $$ = list_make2($4, makeInteger(0));
8772 : }
8773 : | '(' aggr_args_list ORDER BY aggr_args_list ')'
8774 : {
8775 : /* this is the only case requiring consistency checking */
8776 32 : $$ = makeOrderedSetArgs($2, $5, yyscanner);
8777 : }
8778 : ;
8779 :
8780 : aggr_args_list:
8781 802 : aggr_arg { $$ = list_make1($1); }
8782 98 : | aggr_args_list ',' aggr_arg { $$ = lappend($1, $3); }
8783 : ;
8784 :
8785 : aggregate_with_argtypes:
8786 : func_name aggr_args
8787 : {
8788 362 : ObjectWithArgs *n = makeNode(ObjectWithArgs);
8789 :
8790 362 : n->objname = $1;
8791 362 : n->objargs = extractAggrArgTypes($2);
8792 362 : n->objfuncargs = (List *) linitial($2);
8793 362 : $$ = n;
8794 : }
8795 : ;
8796 :
8797 : aggregate_with_argtypes_list:
8798 104 : aggregate_with_argtypes { $$ = list_make1($1); }
8799 : | aggregate_with_argtypes_list ',' aggregate_with_argtypes
8800 0 : { $$ = lappend($1, $3); }
8801 : ;
8802 :
8803 : opt_createfunc_opt_list:
8804 : createfunc_opt_list
8805 54 : | /*EMPTY*/ { $$ = NIL; }
8806 : ;
8807 :
8808 : createfunc_opt_list:
8809 : /* Must be at least one to prevent conflict */
8810 25654 : createfunc_opt_item { $$ = list_make1($1); }
8811 68150 : | createfunc_opt_list createfunc_opt_item { $$ = lappend($1, $2); }
8812 : ;
8813 :
8814 : /*
8815 : * Options common to both CREATE FUNCTION and ALTER FUNCTION
8816 : */
8817 : common_func_opt_item:
8818 : CALLED ON NULL_P INPUT_P
8819 : {
8820 382 : $$ = makeDefElem("strict", (Node *) makeBoolean(false), @1);
8821 : }
8822 : | RETURNS NULL_P ON NULL_P INPUT_P
8823 : {
8824 882 : $$ = makeDefElem("strict", (Node *) makeBoolean(true), @1);
8825 : }
8826 : | STRICT_P
8827 : {
8828 13962 : $$ = makeDefElem("strict", (Node *) makeBoolean(true), @1);
8829 : }
8830 : | IMMUTABLE
8831 : {
8832 10206 : $$ = makeDefElem("volatility", (Node *) makeString("immutable"), @1);
8833 : }
8834 : | STABLE
8835 : {
8836 2524 : $$ = makeDefElem("volatility", (Node *) makeString("stable"), @1);
8837 : }
8838 : | VOLATILE
8839 : {
8840 1846 : $$ = makeDefElem("volatility", (Node *) makeString("volatile"), @1);
8841 : }
8842 : | EXTERNAL SECURITY DEFINER
8843 : {
8844 0 : $$ = makeDefElem("security", (Node *) makeBoolean(true), @1);
8845 : }
8846 : | EXTERNAL SECURITY INVOKER
8847 : {
8848 0 : $$ = makeDefElem("security", (Node *) makeBoolean(false), @1);
8849 : }
8850 : | SECURITY DEFINER
8851 : {
8852 58 : $$ = makeDefElem("security", (Node *) makeBoolean(true), @1);
8853 : }
8854 : | SECURITY INVOKER
8855 : {
8856 18 : $$ = makeDefElem("security", (Node *) makeBoolean(false), @1);
8857 : }
8858 : | LEAKPROOF
8859 : {
8860 46 : $$ = makeDefElem("leakproof", (Node *) makeBoolean(true), @1);
8861 : }
8862 : | NOT LEAKPROOF
8863 : {
8864 12 : $$ = makeDefElem("leakproof", (Node *) makeBoolean(false), @1);
8865 : }
8866 : | COST NumericOnly
8867 : {
8868 4360 : $$ = makeDefElem("cost", (Node *) $2, @1);
8869 : }
8870 : | ROWS NumericOnly
8871 : {
8872 600 : $$ = makeDefElem("rows", (Node *) $2, @1);
8873 : }
8874 : | SUPPORT any_name
8875 : {
8876 114 : $$ = makeDefElem("support", (Node *) $2, @1);
8877 : }
8878 : | FunctionSetResetClause
8879 : {
8880 : /* we abuse the normal content of a DefElem here */
8881 146 : $$ = makeDefElem("set", (Node *) $1, @1);
8882 : }
8883 : | PARALLEL ColId
8884 : {
8885 14236 : $$ = makeDefElem("parallel", (Node *) makeString($2), @1);
8886 : }
8887 : ;
8888 :
8889 : createfunc_opt_item:
8890 : AS func_as
8891 : {
8892 20034 : $$ = makeDefElem("as", (Node *) $2, @1);
8893 : }
8894 : | LANGUAGE NonReservedWord_or_Sconst
8895 : {
8896 25634 : $$ = makeDefElem("language", (Node *) makeString($2), @1);
8897 : }
8898 : | TRANSFORM transform_type_list
8899 : {
8900 118 : $$ = makeDefElem("transform", (Node *) $2, @1);
8901 : }
8902 : | WINDOW
8903 : {
8904 20 : $$ = makeDefElem("window", (Node *) makeBoolean(true), @1);
8905 : }
8906 : | common_func_opt_item
8907 : {
8908 47998 : $$ = $1;
8909 : }
8910 : ;
8911 :
8912 16650 : func_as: Sconst { $$ = list_make1(makeString($1)); }
8913 : | Sconst ',' Sconst
8914 : {
8915 3384 : $$ = list_make2(makeString($1), makeString($3));
8916 : }
8917 : ;
8918 :
8919 : ReturnStmt: RETURN a_expr
8920 : {
8921 4878 : ReturnStmt *r = makeNode(ReturnStmt);
8922 :
8923 4878 : r->returnval = (Node *) $2;
8924 4878 : $$ = (Node *) r;
8925 : }
8926 : ;
8927 :
8928 : opt_routine_body:
8929 : ReturnStmt
8930 : {
8931 4872 : $$ = $1;
8932 : }
8933 : | BEGIN_P ATOMIC routine_body_stmt_list END_P
8934 : {
8935 : /*
8936 : * A compound statement is stored as a single-item list
8937 : * containing the list of statements as its member. That
8938 : * way, the parse analysis code can tell apart an empty
8939 : * body from no body at all.
8940 : */
8941 808 : $$ = (Node *) list_make1($3);
8942 : }
8943 : | /*EMPTY*/
8944 : {
8945 20028 : $$ = NULL;
8946 : }
8947 : ;
8948 :
8949 : routine_body_stmt_list:
8950 : routine_body_stmt_list routine_body_stmt ';'
8951 : {
8952 : /* As in stmtmulti, discard empty statements */
8953 824 : if ($2 != NULL)
8954 806 : $$ = lappend($1, $2);
8955 : else
8956 18 : $$ = $1;
8957 : }
8958 : | /*EMPTY*/
8959 : {
8960 808 : $$ = NIL;
8961 : }
8962 : ;
8963 :
8964 : routine_body_stmt:
8965 : stmt
8966 : | ReturnStmt
8967 : ;
8968 :
8969 : transform_type_list:
8970 118 : FOR TYPE_P Typename { $$ = list_make1($3); }
8971 4 : | transform_type_list ',' FOR TYPE_P Typename { $$ = lappend($1, $5); }
8972 : ;
8973 :
8974 : opt_definition:
8975 656 : WITH definition { $$ = $2; }
8976 10222 : | /*EMPTY*/ { $$ = NIL; }
8977 : ;
8978 :
8979 : table_func_column: param_name func_type
8980 : {
8981 454 : FunctionParameter *n = makeNode(FunctionParameter);
8982 :
8983 454 : n->name = $1;
8984 454 : n->argType = $2;
8985 454 : n->mode = FUNC_PARAM_TABLE;
8986 454 : n->defexpr = NULL;
8987 454 : n->location = @1;
8988 454 : $$ = n;
8989 : }
8990 : ;
8991 :
8992 : table_func_column_list:
8993 : table_func_column
8994 : {
8995 194 : $$ = list_make1($1);
8996 : }
8997 : | table_func_column_list ',' table_func_column
8998 : {
8999 260 : $$ = lappend($1, $3);
9000 : }
9001 : ;
9002 :
9003 : /*****************************************************************************
9004 : * ALTER FUNCTION / ALTER PROCEDURE / ALTER ROUTINE
9005 : *
9006 : * RENAME and OWNER subcommands are already provided by the generic
9007 : * ALTER infrastructure, here we just specify alterations that can
9008 : * only be applied to functions.
9009 : *
9010 : *****************************************************************************/
9011 : AlterFunctionStmt:
9012 : ALTER FUNCTION function_with_argtypes alterfunc_opt_list opt_restrict
9013 : {
9014 1372 : AlterFunctionStmt *n = makeNode(AlterFunctionStmt);
9015 :
9016 1372 : n->objtype = OBJECT_FUNCTION;
9017 1372 : n->func = $3;
9018 1372 : n->actions = $4;
9019 1372 : $$ = (Node *) n;
9020 : }
9021 : | ALTER PROCEDURE function_with_argtypes alterfunc_opt_list opt_restrict
9022 : {
9023 18 : AlterFunctionStmt *n = makeNode(AlterFunctionStmt);
9024 :
9025 18 : n->objtype = OBJECT_PROCEDURE;
9026 18 : n->func = $3;
9027 18 : n->actions = $4;
9028 18 : $$ = (Node *) n;
9029 : }
9030 : | ALTER ROUTINE function_with_argtypes alterfunc_opt_list opt_restrict
9031 : {
9032 0 : AlterFunctionStmt *n = makeNode(AlterFunctionStmt);
9033 :
9034 0 : n->objtype = OBJECT_ROUTINE;
9035 0 : n->func = $3;
9036 0 : n->actions = $4;
9037 0 : $$ = (Node *) n;
9038 : }
9039 : ;
9040 :
9041 : alterfunc_opt_list:
9042 : /* At least one option must be specified */
9043 1390 : common_func_opt_item { $$ = list_make1($1); }
9044 4 : | alterfunc_opt_list common_func_opt_item { $$ = lappend($1, $2); }
9045 : ;
9046 :
9047 : /* Ignored, merely for SQL compliance */
9048 : opt_restrict:
9049 : RESTRICT
9050 : | /* EMPTY */
9051 : ;
9052 :
9053 :
9054 : /*****************************************************************************
9055 : *
9056 : * QUERY:
9057 : *
9058 : * DROP FUNCTION funcname (arg1, arg2, ...) [ RESTRICT | CASCADE ]
9059 : * DROP PROCEDURE procname (arg1, arg2, ...) [ RESTRICT | CASCADE ]
9060 : * DROP ROUTINE routname (arg1, arg2, ...) [ RESTRICT | CASCADE ]
9061 : * DROP AGGREGATE aggname (arg1, ...) [ RESTRICT | CASCADE ]
9062 : * DROP OPERATOR opname (leftoperand_typ, rightoperand_typ) [ RESTRICT | CASCADE ]
9063 : *
9064 : *****************************************************************************/
9065 :
9066 : RemoveFuncStmt:
9067 : DROP FUNCTION function_with_argtypes_list opt_drop_behavior
9068 : {
9069 3340 : DropStmt *n = makeNode(DropStmt);
9070 :
9071 3340 : n->removeType = OBJECT_FUNCTION;
9072 3340 : n->objects = $3;
9073 3340 : n->behavior = $4;
9074 3340 : n->missing_ok = false;
9075 3340 : n->concurrent = false;
9076 3340 : $$ = (Node *) n;
9077 : }
9078 : | DROP FUNCTION IF_P EXISTS function_with_argtypes_list opt_drop_behavior
9079 : {
9080 260 : DropStmt *n = makeNode(DropStmt);
9081 :
9082 260 : n->removeType = OBJECT_FUNCTION;
9083 260 : n->objects = $5;
9084 260 : n->behavior = $6;
9085 260 : n->missing_ok = true;
9086 260 : n->concurrent = false;
9087 260 : $$ = (Node *) n;
9088 : }
9089 : | DROP PROCEDURE function_with_argtypes_list opt_drop_behavior
9090 : {
9091 140 : DropStmt *n = makeNode(DropStmt);
9092 :
9093 140 : n->removeType = OBJECT_PROCEDURE;
9094 140 : n->objects = $3;
9095 140 : n->behavior = $4;
9096 140 : n->missing_ok = false;
9097 140 : n->concurrent = false;
9098 140 : $$ = (Node *) n;
9099 : }
9100 : | DROP PROCEDURE IF_P EXISTS function_with_argtypes_list opt_drop_behavior
9101 : {
9102 6 : DropStmt *n = makeNode(DropStmt);
9103 :
9104 6 : n->removeType = OBJECT_PROCEDURE;
9105 6 : n->objects = $5;
9106 6 : n->behavior = $6;
9107 6 : n->missing_ok = true;
9108 6 : n->concurrent = false;
9109 6 : $$ = (Node *) n;
9110 : }
9111 : | DROP ROUTINE function_with_argtypes_list opt_drop_behavior
9112 : {
9113 12 : DropStmt *n = makeNode(DropStmt);
9114 :
9115 12 : n->removeType = OBJECT_ROUTINE;
9116 12 : n->objects = $3;
9117 12 : n->behavior = $4;
9118 12 : n->missing_ok = false;
9119 12 : n->concurrent = false;
9120 12 : $$ = (Node *) n;
9121 : }
9122 : | DROP ROUTINE IF_P EXISTS function_with_argtypes_list opt_drop_behavior
9123 : {
9124 6 : DropStmt *n = makeNode(DropStmt);
9125 :
9126 6 : n->removeType = OBJECT_ROUTINE;
9127 6 : n->objects = $5;
9128 6 : n->behavior = $6;
9129 6 : n->missing_ok = true;
9130 6 : n->concurrent = false;
9131 6 : $$ = (Node *) n;
9132 : }
9133 : ;
9134 :
9135 : RemoveAggrStmt:
9136 : DROP AGGREGATE aggregate_with_argtypes_list opt_drop_behavior
9137 : {
9138 74 : DropStmt *n = makeNode(DropStmt);
9139 :
9140 74 : n->removeType = OBJECT_AGGREGATE;
9141 74 : n->objects = $3;
9142 74 : n->behavior = $4;
9143 74 : n->missing_ok = false;
9144 74 : n->concurrent = false;
9145 74 : $$ = (Node *) n;
9146 : }
9147 : | DROP AGGREGATE IF_P EXISTS aggregate_with_argtypes_list opt_drop_behavior
9148 : {
9149 30 : DropStmt *n = makeNode(DropStmt);
9150 :
9151 30 : n->removeType = OBJECT_AGGREGATE;
9152 30 : n->objects = $5;
9153 30 : n->behavior = $6;
9154 30 : n->missing_ok = true;
9155 30 : n->concurrent = false;
9156 30 : $$ = (Node *) n;
9157 : }
9158 : ;
9159 :
9160 : RemoveOperStmt:
9161 : DROP OPERATOR operator_with_argtypes_list opt_drop_behavior
9162 : {
9163 200 : DropStmt *n = makeNode(DropStmt);
9164 :
9165 200 : n->removeType = OBJECT_OPERATOR;
9166 200 : n->objects = $3;
9167 200 : n->behavior = $4;
9168 200 : n->missing_ok = false;
9169 200 : n->concurrent = false;
9170 200 : $$ = (Node *) n;
9171 : }
9172 : | DROP OPERATOR IF_P EXISTS operator_with_argtypes_list opt_drop_behavior
9173 : {
9174 30 : DropStmt *n = makeNode(DropStmt);
9175 :
9176 30 : n->removeType = OBJECT_OPERATOR;
9177 30 : n->objects = $5;
9178 30 : n->behavior = $6;
9179 30 : n->missing_ok = true;
9180 30 : n->concurrent = false;
9181 30 : $$ = (Node *) n;
9182 : }
9183 : ;
9184 :
9185 : oper_argtypes:
9186 : '(' Typename ')'
9187 : {
9188 12 : ereport(ERROR,
9189 : (errcode(ERRCODE_SYNTAX_ERROR),
9190 : errmsg("missing argument"),
9191 : errhint("Use NONE to denote the missing argument of a unary operator."),
9192 : parser_errposition(@3)));
9193 : }
9194 : | '(' Typename ',' Typename ')'
9195 2464 : { $$ = list_make2($2, $4); }
9196 : | '(' NONE ',' Typename ')' /* left unary */
9197 32 : { $$ = list_make2(NULL, $4); }
9198 : | '(' Typename ',' NONE ')' /* right unary */
9199 12 : { $$ = list_make2($2, NULL); }
9200 : ;
9201 :
9202 : any_operator:
9203 : all_Op
9204 22478 : { $$ = list_make1(makeString($1)); }
9205 : | ColId '.' any_operator
9206 16228 : { $$ = lcons(makeString($1), $3); }
9207 : ;
9208 :
9209 : operator_with_argtypes_list:
9210 230 : operator_with_argtypes { $$ = list_make1($1); }
9211 : | operator_with_argtypes_list ',' operator_with_argtypes
9212 0 : { $$ = lappend($1, $3); }
9213 : ;
9214 :
9215 : operator_with_argtypes:
9216 : any_operator oper_argtypes
9217 : {
9218 2508 : ObjectWithArgs *n = makeNode(ObjectWithArgs);
9219 :
9220 2508 : n->objname = $1;
9221 2508 : n->objargs = $2;
9222 2508 : $$ = n;
9223 : }
9224 : ;
9225 :
9226 : /*****************************************************************************
9227 : *
9228 : * DO <anonymous code block> [ LANGUAGE language ]
9229 : *
9230 : * We use a DefElem list for future extensibility, and to allow flexibility
9231 : * in the clause order.
9232 : *
9233 : *****************************************************************************/
9234 :
9235 : DoStmt: DO dostmt_opt_list
9236 : {
9237 1142 : DoStmt *n = makeNode(DoStmt);
9238 :
9239 1142 : n->args = $2;
9240 1142 : $$ = (Node *) n;
9241 : }
9242 : ;
9243 :
9244 : dostmt_opt_list:
9245 1142 : dostmt_opt_item { $$ = list_make1($1); }
9246 198 : | dostmt_opt_list dostmt_opt_item { $$ = lappend($1, $2); }
9247 : ;
9248 :
9249 : dostmt_opt_item:
9250 : Sconst
9251 : {
9252 1142 : $$ = makeDefElem("as", (Node *) makeString($1), @1);
9253 : }
9254 : | LANGUAGE NonReservedWord_or_Sconst
9255 : {
9256 198 : $$ = makeDefElem("language", (Node *) makeString($2), @1);
9257 : }
9258 : ;
9259 :
9260 : /*****************************************************************************
9261 : *
9262 : * CREATE CAST / DROP CAST
9263 : *
9264 : *****************************************************************************/
9265 :
9266 : CreateCastStmt: CREATE CAST '(' Typename AS Typename ')'
9267 : WITH FUNCTION function_with_argtypes cast_context
9268 : {
9269 108 : CreateCastStmt *n = makeNode(CreateCastStmt);
9270 :
9271 108 : n->sourcetype = $4;
9272 108 : n->targettype = $6;
9273 108 : n->func = $10;
9274 108 : n->context = (CoercionContext) $11;
9275 108 : n->inout = false;
9276 108 : $$ = (Node *) n;
9277 : }
9278 : | CREATE CAST '(' Typename AS Typename ')'
9279 : WITHOUT FUNCTION cast_context
9280 : {
9281 162 : CreateCastStmt *n = makeNode(CreateCastStmt);
9282 :
9283 162 : n->sourcetype = $4;
9284 162 : n->targettype = $6;
9285 162 : n->func = NULL;
9286 162 : n->context = (CoercionContext) $10;
9287 162 : n->inout = false;
9288 162 : $$ = (Node *) n;
9289 : }
9290 : | CREATE CAST '(' Typename AS Typename ')'
9291 : WITH INOUT cast_context
9292 : {
9293 8 : CreateCastStmt *n = makeNode(CreateCastStmt);
9294 :
9295 8 : n->sourcetype = $4;
9296 8 : n->targettype = $6;
9297 8 : n->func = NULL;
9298 8 : n->context = (CoercionContext) $10;
9299 8 : n->inout = true;
9300 8 : $$ = (Node *) n;
9301 : }
9302 : ;
9303 :
9304 36 : cast_context: AS IMPLICIT_P { $$ = COERCION_IMPLICIT; }
9305 58 : | AS ASSIGNMENT { $$ = COERCION_ASSIGNMENT; }
9306 184 : | /*EMPTY*/ { $$ = COERCION_EXPLICIT; }
9307 : ;
9308 :
9309 :
9310 : DropCastStmt: DROP CAST opt_if_exists '(' Typename AS Typename ')' opt_drop_behavior
9311 : {
9312 60 : DropStmt *n = makeNode(DropStmt);
9313 :
9314 60 : n->removeType = OBJECT_CAST;
9315 60 : n->objects = list_make1(list_make2($5, $7));
9316 60 : n->behavior = $9;
9317 60 : n->missing_ok = $3;
9318 60 : n->concurrent = false;
9319 60 : $$ = (Node *) n;
9320 : }
9321 : ;
9322 :
9323 36 : opt_if_exists: IF_P EXISTS { $$ = true; }
9324 38 : | /*EMPTY*/ { $$ = false; }
9325 : ;
9326 :
9327 :
9328 : /*****************************************************************************
9329 : *
9330 : * CREATE TRANSFORM / DROP TRANSFORM
9331 : *
9332 : *****************************************************************************/
9333 :
9334 : CreateTransformStmt: CREATE opt_or_replace TRANSFORM FOR Typename LANGUAGE name '(' transform_element_list ')'
9335 : {
9336 50 : CreateTransformStmt *n = makeNode(CreateTransformStmt);
9337 :
9338 50 : n->replace = $2;
9339 50 : n->type_name = $5;
9340 50 : n->lang = $7;
9341 50 : n->fromsql = linitial($9);
9342 50 : n->tosql = lsecond($9);
9343 50 : $$ = (Node *) n;
9344 : }
9345 : ;
9346 :
9347 : transform_element_list: FROM SQL_P WITH FUNCTION function_with_argtypes ',' TO SQL_P WITH FUNCTION function_with_argtypes
9348 : {
9349 44 : $$ = list_make2($5, $11);
9350 : }
9351 : | TO SQL_P WITH FUNCTION function_with_argtypes ',' FROM SQL_P WITH FUNCTION function_with_argtypes
9352 : {
9353 0 : $$ = list_make2($11, $5);
9354 : }
9355 : | FROM SQL_P WITH FUNCTION function_with_argtypes
9356 : {
9357 4 : $$ = list_make2($5, NULL);
9358 : }
9359 : | TO SQL_P WITH FUNCTION function_with_argtypes
9360 : {
9361 2 : $$ = list_make2(NULL, $5);
9362 : }
9363 : ;
9364 :
9365 :
9366 : DropTransformStmt: DROP TRANSFORM opt_if_exists FOR Typename LANGUAGE name opt_drop_behavior
9367 : {
9368 14 : DropStmt *n = makeNode(DropStmt);
9369 :
9370 14 : n->removeType = OBJECT_TRANSFORM;
9371 14 : n->objects = list_make1(list_make2($5, makeString($7)));
9372 14 : n->behavior = $8;
9373 14 : n->missing_ok = $3;
9374 14 : $$ = (Node *) n;
9375 : }
9376 : ;
9377 :
9378 :
9379 : /*****************************************************************************
9380 : *
9381 : * QUERY:
9382 : *
9383 : * REINDEX [ (options) ] {INDEX | TABLE | SCHEMA} [CONCURRENTLY] <name>
9384 : * REINDEX [ (options) ] {DATABASE | SYSTEM} [CONCURRENTLY] [<name>]
9385 : *****************************************************************************/
9386 :
9387 : ReindexStmt:
9388 : REINDEX opt_utility_option_list reindex_target_relation opt_concurrently qualified_name
9389 : {
9390 932 : ReindexStmt *n = makeNode(ReindexStmt);
9391 :
9392 932 : n->kind = $3;
9393 932 : n->relation = $5;
9394 932 : n->name = NULL;
9395 932 : n->params = $2;
9396 932 : if ($4)
9397 528 : n->params = lappend(n->params,
9398 528 : makeDefElem("concurrently", NULL, @4));
9399 932 : $$ = (Node *) n;
9400 : }
9401 : | REINDEX opt_utility_option_list SCHEMA opt_concurrently name
9402 : {
9403 114 : ReindexStmt *n = makeNode(ReindexStmt);
9404 :
9405 114 : n->kind = REINDEX_OBJECT_SCHEMA;
9406 114 : n->relation = NULL;
9407 114 : n->name = $5;
9408 114 : n->params = $2;
9409 114 : if ($4)
9410 40 : n->params = lappend(n->params,
9411 40 : makeDefElem("concurrently", NULL, @4));
9412 114 : $$ = (Node *) n;
9413 : }
9414 : | REINDEX opt_utility_option_list reindex_target_all opt_concurrently opt_single_name
9415 : {
9416 64 : ReindexStmt *n = makeNode(ReindexStmt);
9417 :
9418 64 : n->kind = $3;
9419 64 : n->relation = NULL;
9420 64 : n->name = $5;
9421 64 : n->params = $2;
9422 64 : if ($4)
9423 10 : n->params = lappend(n->params,
9424 10 : makeDefElem("concurrently", NULL, @4));
9425 64 : $$ = (Node *) n;
9426 : }
9427 : ;
9428 : reindex_target_relation:
9429 404 : INDEX { $$ = REINDEX_OBJECT_INDEX; }
9430 528 : | TABLE { $$ = REINDEX_OBJECT_TABLE; }
9431 : ;
9432 : reindex_target_all:
9433 34 : SYSTEM_P { $$ = REINDEX_OBJECT_SYSTEM; }
9434 30 : | DATABASE { $$ = REINDEX_OBJECT_DATABASE; }
9435 : ;
9436 :
9437 : /*****************************************************************************
9438 : *
9439 : * ALTER TABLESPACE
9440 : *
9441 : *****************************************************************************/
9442 :
9443 : AlterTblSpcStmt:
9444 : ALTER TABLESPACE name SET reloptions
9445 : {
9446 : AlterTableSpaceOptionsStmt *n =
9447 12 : makeNode(AlterTableSpaceOptionsStmt);
9448 :
9449 12 : n->tablespacename = $3;
9450 12 : n->options = $5;
9451 12 : n->isReset = false;
9452 12 : $$ = (Node *) n;
9453 : }
9454 : | ALTER TABLESPACE name RESET reloptions
9455 : {
9456 : AlterTableSpaceOptionsStmt *n =
9457 12 : makeNode(AlterTableSpaceOptionsStmt);
9458 :
9459 12 : n->tablespacename = $3;
9460 12 : n->options = $5;
9461 12 : n->isReset = true;
9462 12 : $$ = (Node *) n;
9463 : }
9464 : ;
9465 :
9466 : /*****************************************************************************
9467 : *
9468 : * ALTER THING name RENAME TO newname
9469 : *
9470 : *****************************************************************************/
9471 :
9472 : RenameStmt: ALTER AGGREGATE aggregate_with_argtypes RENAME TO name
9473 : {
9474 42 : RenameStmt *n = makeNode(RenameStmt);
9475 :
9476 42 : n->renameType = OBJECT_AGGREGATE;
9477 42 : n->object = (Node *) $3;
9478 42 : n->newname = $6;
9479 42 : n->missing_ok = false;
9480 42 : $$ = (Node *) n;
9481 : }
9482 : | ALTER COLLATION any_name RENAME TO name
9483 : {
9484 18 : RenameStmt *n = makeNode(RenameStmt);
9485 :
9486 18 : n->renameType = OBJECT_COLLATION;
9487 18 : n->object = (Node *) $3;
9488 18 : n->newname = $6;
9489 18 : n->missing_ok = false;
9490 18 : $$ = (Node *) n;
9491 : }
9492 : | ALTER CONVERSION_P any_name RENAME TO name
9493 : {
9494 24 : RenameStmt *n = makeNode(RenameStmt);
9495 :
9496 24 : n->renameType = OBJECT_CONVERSION;
9497 24 : n->object = (Node *) $3;
9498 24 : n->newname = $6;
9499 24 : n->missing_ok = false;
9500 24 : $$ = (Node *) n;
9501 : }
9502 : | ALTER DATABASE name RENAME TO name
9503 : {
9504 12 : RenameStmt *n = makeNode(RenameStmt);
9505 :
9506 12 : n->renameType = OBJECT_DATABASE;
9507 12 : n->subname = $3;
9508 12 : n->newname = $6;
9509 12 : n->missing_ok = false;
9510 12 : $$ = (Node *) n;
9511 : }
9512 : | ALTER DOMAIN_P any_name RENAME TO name
9513 : {
9514 6 : RenameStmt *n = makeNode(RenameStmt);
9515 :
9516 6 : n->renameType = OBJECT_DOMAIN;
9517 6 : n->object = (Node *) $3;
9518 6 : n->newname = $6;
9519 6 : n->missing_ok = false;
9520 6 : $$ = (Node *) n;
9521 : }
9522 : | ALTER DOMAIN_P any_name RENAME CONSTRAINT name TO name
9523 : {
9524 6 : RenameStmt *n = makeNode(RenameStmt);
9525 :
9526 6 : n->renameType = OBJECT_DOMCONSTRAINT;
9527 6 : n->object = (Node *) $3;
9528 6 : n->subname = $6;
9529 6 : n->newname = $8;
9530 6 : $$ = (Node *) n;
9531 : }
9532 : | ALTER FOREIGN DATA_P WRAPPER name RENAME TO name
9533 : {
9534 24 : RenameStmt *n = makeNode(RenameStmt);
9535 :
9536 24 : n->renameType = OBJECT_FDW;
9537 24 : n->object = (Node *) makeString($5);
9538 24 : n->newname = $8;
9539 24 : n->missing_ok = false;
9540 24 : $$ = (Node *) n;
9541 : }
9542 : | ALTER FUNCTION function_with_argtypes RENAME TO name
9543 : {
9544 24 : RenameStmt *n = makeNode(RenameStmt);
9545 :
9546 24 : n->renameType = OBJECT_FUNCTION;
9547 24 : n->object = (Node *) $3;
9548 24 : n->newname = $6;
9549 24 : n->missing_ok = false;
9550 24 : $$ = (Node *) n;
9551 : }
9552 : | ALTER GROUP_P RoleId RENAME TO RoleId
9553 : {
9554 0 : RenameStmt *n = makeNode(RenameStmt);
9555 :
9556 0 : n->renameType = OBJECT_ROLE;
9557 0 : n->subname = $3;
9558 0 : n->newname = $6;
9559 0 : n->missing_ok = false;
9560 0 : $$ = (Node *) n;
9561 : }
9562 : | ALTER opt_procedural LANGUAGE name RENAME TO name
9563 : {
9564 18 : RenameStmt *n = makeNode(RenameStmt);
9565 :
9566 18 : n->renameType = OBJECT_LANGUAGE;
9567 18 : n->object = (Node *) makeString($4);
9568 18 : n->newname = $7;
9569 18 : n->missing_ok = false;
9570 18 : $$ = (Node *) n;
9571 : }
9572 : | ALTER OPERATOR CLASS any_name USING name RENAME TO name
9573 : {
9574 24 : RenameStmt *n = makeNode(RenameStmt);
9575 :
9576 24 : n->renameType = OBJECT_OPCLASS;
9577 24 : n->object = (Node *) lcons(makeString($6), $4);
9578 24 : n->newname = $9;
9579 24 : n->missing_ok = false;
9580 24 : $$ = (Node *) n;
9581 : }
9582 : | ALTER OPERATOR FAMILY any_name USING name RENAME TO name
9583 : {
9584 24 : RenameStmt *n = makeNode(RenameStmt);
9585 :
9586 24 : n->renameType = OBJECT_OPFAMILY;
9587 24 : n->object = (Node *) lcons(makeString($6), $4);
9588 24 : n->newname = $9;
9589 24 : n->missing_ok = false;
9590 24 : $$ = (Node *) n;
9591 : }
9592 : | ALTER POLICY name ON qualified_name RENAME TO name
9593 : {
9594 18 : RenameStmt *n = makeNode(RenameStmt);
9595 :
9596 18 : n->renameType = OBJECT_POLICY;
9597 18 : n->relation = $5;
9598 18 : n->subname = $3;
9599 18 : n->newname = $8;
9600 18 : n->missing_ok = false;
9601 18 : $$ = (Node *) n;
9602 : }
9603 : | ALTER POLICY IF_P EXISTS name ON qualified_name RENAME TO name
9604 : {
9605 0 : RenameStmt *n = makeNode(RenameStmt);
9606 :
9607 0 : n->renameType = OBJECT_POLICY;
9608 0 : n->relation = $7;
9609 0 : n->subname = $5;
9610 0 : n->newname = $10;
9611 0 : n->missing_ok = true;
9612 0 : $$ = (Node *) n;
9613 : }
9614 : | ALTER PROCEDURE function_with_argtypes RENAME TO name
9615 : {
9616 0 : RenameStmt *n = makeNode(RenameStmt);
9617 :
9618 0 : n->renameType = OBJECT_PROCEDURE;
9619 0 : n->object = (Node *) $3;
9620 0 : n->newname = $6;
9621 0 : n->missing_ok = false;
9622 0 : $$ = (Node *) n;
9623 : }
9624 : | ALTER PUBLICATION name RENAME TO name
9625 : {
9626 42 : RenameStmt *n = makeNode(RenameStmt);
9627 :
9628 42 : n->renameType = OBJECT_PUBLICATION;
9629 42 : n->object = (Node *) makeString($3);
9630 42 : n->newname = $6;
9631 42 : n->missing_ok = false;
9632 42 : $$ = (Node *) n;
9633 : }
9634 : | ALTER ROUTINE function_with_argtypes RENAME TO name
9635 : {
9636 24 : RenameStmt *n = makeNode(RenameStmt);
9637 :
9638 24 : n->renameType = OBJECT_ROUTINE;
9639 24 : n->object = (Node *) $3;
9640 24 : n->newname = $6;
9641 24 : n->missing_ok = false;
9642 24 : $$ = (Node *) n;
9643 : }
9644 : | ALTER SCHEMA name RENAME TO name
9645 : {
9646 20 : RenameStmt *n = makeNode(RenameStmt);
9647 :
9648 20 : n->renameType = OBJECT_SCHEMA;
9649 20 : n->subname = $3;
9650 20 : n->newname = $6;
9651 20 : n->missing_ok = false;
9652 20 : $$ = (Node *) n;
9653 : }
9654 : | ALTER SERVER name RENAME TO name
9655 : {
9656 24 : RenameStmt *n = makeNode(RenameStmt);
9657 :
9658 24 : n->renameType = OBJECT_FOREIGN_SERVER;
9659 24 : n->object = (Node *) makeString($3);
9660 24 : n->newname = $6;
9661 24 : n->missing_ok = false;
9662 24 : $$ = (Node *) n;
9663 : }
9664 : | ALTER SUBSCRIPTION name RENAME TO name
9665 : {
9666 38 : RenameStmt *n = makeNode(RenameStmt);
9667 :
9668 38 : n->renameType = OBJECT_SUBSCRIPTION;
9669 38 : n->object = (Node *) makeString($3);
9670 38 : n->newname = $6;
9671 38 : n->missing_ok = false;
9672 38 : $$ = (Node *) n;
9673 : }
9674 : | ALTER TABLE relation_expr RENAME TO name
9675 : {
9676 288 : RenameStmt *n = makeNode(RenameStmt);
9677 :
9678 288 : n->renameType = OBJECT_TABLE;
9679 288 : n->relation = $3;
9680 288 : n->subname = NULL;
9681 288 : n->newname = $6;
9682 288 : n->missing_ok = false;
9683 288 : $$ = (Node *) n;
9684 : }
9685 : | ALTER TABLE IF_P EXISTS relation_expr RENAME TO name
9686 : {
9687 0 : RenameStmt *n = makeNode(RenameStmt);
9688 :
9689 0 : n->renameType = OBJECT_TABLE;
9690 0 : n->relation = $5;
9691 0 : n->subname = NULL;
9692 0 : n->newname = $8;
9693 0 : n->missing_ok = true;
9694 0 : $$ = (Node *) n;
9695 : }
9696 : | ALTER SEQUENCE qualified_name RENAME TO name
9697 : {
9698 2 : RenameStmt *n = makeNode(RenameStmt);
9699 :
9700 2 : n->renameType = OBJECT_SEQUENCE;
9701 2 : n->relation = $3;
9702 2 : n->subname = NULL;
9703 2 : n->newname = $6;
9704 2 : n->missing_ok = false;
9705 2 : $$ = (Node *) n;
9706 : }
9707 : | ALTER SEQUENCE IF_P EXISTS qualified_name RENAME TO name
9708 : {
9709 0 : RenameStmt *n = makeNode(RenameStmt);
9710 :
9711 0 : n->renameType = OBJECT_SEQUENCE;
9712 0 : n->relation = $5;
9713 0 : n->subname = NULL;
9714 0 : n->newname = $8;
9715 0 : n->missing_ok = true;
9716 0 : $$ = (Node *) n;
9717 : }
9718 : | ALTER VIEW qualified_name RENAME TO name
9719 : {
9720 6 : RenameStmt *n = makeNode(RenameStmt);
9721 :
9722 6 : n->renameType = OBJECT_VIEW;
9723 6 : n->relation = $3;
9724 6 : n->subname = NULL;
9725 6 : n->newname = $6;
9726 6 : n->missing_ok = false;
9727 6 : $$ = (Node *) n;
9728 : }
9729 : | ALTER VIEW IF_P EXISTS qualified_name RENAME TO name
9730 : {
9731 0 : RenameStmt *n = makeNode(RenameStmt);
9732 :
9733 0 : n->renameType = OBJECT_VIEW;
9734 0 : n->relation = $5;
9735 0 : n->subname = NULL;
9736 0 : n->newname = $8;
9737 0 : n->missing_ok = true;
9738 0 : $$ = (Node *) n;
9739 : }
9740 : | ALTER MATERIALIZED VIEW qualified_name RENAME TO name
9741 : {
9742 0 : RenameStmt *n = makeNode(RenameStmt);
9743 :
9744 0 : n->renameType = OBJECT_MATVIEW;
9745 0 : n->relation = $4;
9746 0 : n->subname = NULL;
9747 0 : n->newname = $7;
9748 0 : n->missing_ok = false;
9749 0 : $$ = (Node *) n;
9750 : }
9751 : | ALTER MATERIALIZED VIEW IF_P EXISTS qualified_name RENAME TO name
9752 : {
9753 0 : RenameStmt *n = makeNode(RenameStmt);
9754 :
9755 0 : n->renameType = OBJECT_MATVIEW;
9756 0 : n->relation = $6;
9757 0 : n->subname = NULL;
9758 0 : n->newname = $9;
9759 0 : n->missing_ok = true;
9760 0 : $$ = (Node *) n;
9761 : }
9762 : | ALTER INDEX qualified_name RENAME TO name
9763 : {
9764 192 : RenameStmt *n = makeNode(RenameStmt);
9765 :
9766 192 : n->renameType = OBJECT_INDEX;
9767 192 : n->relation = $3;
9768 192 : n->subname = NULL;
9769 192 : n->newname = $6;
9770 192 : n->missing_ok = false;
9771 192 : $$ = (Node *) n;
9772 : }
9773 : | ALTER INDEX IF_P EXISTS qualified_name RENAME TO name
9774 : {
9775 12 : RenameStmt *n = makeNode(RenameStmt);
9776 :
9777 12 : n->renameType = OBJECT_INDEX;
9778 12 : n->relation = $5;
9779 12 : n->subname = NULL;
9780 12 : n->newname = $8;
9781 12 : n->missing_ok = true;
9782 12 : $$ = (Node *) n;
9783 : }
9784 : | ALTER FOREIGN TABLE relation_expr RENAME TO name
9785 : {
9786 6 : RenameStmt *n = makeNode(RenameStmt);
9787 :
9788 6 : n->renameType = OBJECT_FOREIGN_TABLE;
9789 6 : n->relation = $4;
9790 6 : n->subname = NULL;
9791 6 : n->newname = $7;
9792 6 : n->missing_ok = false;
9793 6 : $$ = (Node *) n;
9794 : }
9795 : | ALTER FOREIGN TABLE IF_P EXISTS relation_expr RENAME TO name
9796 : {
9797 6 : RenameStmt *n = makeNode(RenameStmt);
9798 :
9799 6 : n->renameType = OBJECT_FOREIGN_TABLE;
9800 6 : n->relation = $6;
9801 6 : n->subname = NULL;
9802 6 : n->newname = $9;
9803 6 : n->missing_ok = true;
9804 6 : $$ = (Node *) n;
9805 : }
9806 : | ALTER TABLE relation_expr RENAME opt_column name TO name
9807 : {
9808 238 : RenameStmt *n = makeNode(RenameStmt);
9809 :
9810 238 : n->renameType = OBJECT_COLUMN;
9811 238 : n->relationType = OBJECT_TABLE;
9812 238 : n->relation = $3;
9813 238 : n->subname = $6;
9814 238 : n->newname = $8;
9815 238 : n->missing_ok = false;
9816 238 : $$ = (Node *) n;
9817 : }
9818 : | ALTER TABLE IF_P EXISTS relation_expr RENAME opt_column name TO name
9819 : {
9820 24 : RenameStmt *n = makeNode(RenameStmt);
9821 :
9822 24 : n->renameType = OBJECT_COLUMN;
9823 24 : n->relationType = OBJECT_TABLE;
9824 24 : n->relation = $5;
9825 24 : n->subname = $8;
9826 24 : n->newname = $10;
9827 24 : n->missing_ok = true;
9828 24 : $$ = (Node *) n;
9829 : }
9830 : | ALTER VIEW qualified_name RENAME opt_column name TO name
9831 : {
9832 18 : RenameStmt *n = makeNode(RenameStmt);
9833 :
9834 18 : n->renameType = OBJECT_COLUMN;
9835 18 : n->relationType = OBJECT_VIEW;
9836 18 : n->relation = $3;
9837 18 : n->subname = $6;
9838 18 : n->newname = $8;
9839 18 : n->missing_ok = false;
9840 18 : $$ = (Node *) n;
9841 : }
9842 : | ALTER VIEW IF_P EXISTS qualified_name RENAME opt_column name TO name
9843 : {
9844 0 : RenameStmt *n = makeNode(RenameStmt);
9845 :
9846 0 : n->renameType = OBJECT_COLUMN;
9847 0 : n->relationType = OBJECT_VIEW;
9848 0 : n->relation = $5;
9849 0 : n->subname = $8;
9850 0 : n->newname = $10;
9851 0 : n->missing_ok = true;
9852 0 : $$ = (Node *) n;
9853 : }
9854 : | ALTER MATERIALIZED VIEW qualified_name RENAME opt_column name TO name
9855 : {
9856 0 : RenameStmt *n = makeNode(RenameStmt);
9857 :
9858 0 : n->renameType = OBJECT_COLUMN;
9859 0 : n->relationType = OBJECT_MATVIEW;
9860 0 : n->relation = $4;
9861 0 : n->subname = $7;
9862 0 : n->newname = $9;
9863 0 : n->missing_ok = false;
9864 0 : $$ = (Node *) n;
9865 : }
9866 : | ALTER MATERIALIZED VIEW IF_P EXISTS qualified_name RENAME opt_column name TO name
9867 : {
9868 0 : RenameStmt *n = makeNode(RenameStmt);
9869 :
9870 0 : n->renameType = OBJECT_COLUMN;
9871 0 : n->relationType = OBJECT_MATVIEW;
9872 0 : n->relation = $6;
9873 0 : n->subname = $9;
9874 0 : n->newname = $11;
9875 0 : n->missing_ok = true;
9876 0 : $$ = (Node *) n;
9877 : }
9878 : | ALTER TABLE relation_expr RENAME CONSTRAINT name TO name
9879 : {
9880 72 : RenameStmt *n = makeNode(RenameStmt);
9881 :
9882 72 : n->renameType = OBJECT_TABCONSTRAINT;
9883 72 : n->relation = $3;
9884 72 : n->subname = $6;
9885 72 : n->newname = $8;
9886 72 : n->missing_ok = false;
9887 72 : $$ = (Node *) n;
9888 : }
9889 : | ALTER TABLE IF_P EXISTS relation_expr RENAME CONSTRAINT name TO name
9890 : {
9891 6 : RenameStmt *n = makeNode(RenameStmt);
9892 :
9893 6 : n->renameType = OBJECT_TABCONSTRAINT;
9894 6 : n->relation = $5;
9895 6 : n->subname = $8;
9896 6 : n->newname = $10;
9897 6 : n->missing_ok = true;
9898 6 : $$ = (Node *) n;
9899 : }
9900 : | ALTER FOREIGN TABLE relation_expr RENAME opt_column name TO name
9901 : {
9902 6 : RenameStmt *n = makeNode(RenameStmt);
9903 :
9904 6 : n->renameType = OBJECT_COLUMN;
9905 6 : n->relationType = OBJECT_FOREIGN_TABLE;
9906 6 : n->relation = $4;
9907 6 : n->subname = $7;
9908 6 : n->newname = $9;
9909 6 : n->missing_ok = false;
9910 6 : $$ = (Node *) n;
9911 : }
9912 : | ALTER FOREIGN TABLE IF_P EXISTS relation_expr RENAME opt_column name TO name
9913 : {
9914 6 : RenameStmt *n = makeNode(RenameStmt);
9915 :
9916 6 : n->renameType = OBJECT_COLUMN;
9917 6 : n->relationType = OBJECT_FOREIGN_TABLE;
9918 6 : n->relation = $6;
9919 6 : n->subname = $9;
9920 6 : n->newname = $11;
9921 6 : n->missing_ok = true;
9922 6 : $$ = (Node *) n;
9923 : }
9924 : | ALTER RULE name ON qualified_name RENAME TO name
9925 : {
9926 34 : RenameStmt *n = makeNode(RenameStmt);
9927 :
9928 34 : n->renameType = OBJECT_RULE;
9929 34 : n->relation = $5;
9930 34 : n->subname = $3;
9931 34 : n->newname = $8;
9932 34 : n->missing_ok = false;
9933 34 : $$ = (Node *) n;
9934 : }
9935 : | ALTER TRIGGER name ON qualified_name RENAME TO name
9936 : {
9937 40 : RenameStmt *n = makeNode(RenameStmt);
9938 :
9939 40 : n->renameType = OBJECT_TRIGGER;
9940 40 : n->relation = $5;
9941 40 : n->subname = $3;
9942 40 : n->newname = $8;
9943 40 : n->missing_ok = false;
9944 40 : $$ = (Node *) n;
9945 : }
9946 : | ALTER EVENT TRIGGER name RENAME TO name
9947 : {
9948 12 : RenameStmt *n = makeNode(RenameStmt);
9949 :
9950 12 : n->renameType = OBJECT_EVENT_TRIGGER;
9951 12 : n->object = (Node *) makeString($4);
9952 12 : n->newname = $7;
9953 12 : $$ = (Node *) n;
9954 : }
9955 : | ALTER ROLE RoleId RENAME TO RoleId
9956 : {
9957 32 : RenameStmt *n = makeNode(RenameStmt);
9958 :
9959 32 : n->renameType = OBJECT_ROLE;
9960 32 : n->subname = $3;
9961 32 : n->newname = $6;
9962 32 : n->missing_ok = false;
9963 32 : $$ = (Node *) n;
9964 : }
9965 : | ALTER USER RoleId RENAME TO RoleId
9966 : {
9967 0 : RenameStmt *n = makeNode(RenameStmt);
9968 :
9969 0 : n->renameType = OBJECT_ROLE;
9970 0 : n->subname = $3;
9971 0 : n->newname = $6;
9972 0 : n->missing_ok = false;
9973 0 : $$ = (Node *) n;
9974 : }
9975 : | ALTER TABLESPACE name RENAME TO name
9976 : {
9977 6 : RenameStmt *n = makeNode(RenameStmt);
9978 :
9979 6 : n->renameType = OBJECT_TABLESPACE;
9980 6 : n->subname = $3;
9981 6 : n->newname = $6;
9982 6 : n->missing_ok = false;
9983 6 : $$ = (Node *) n;
9984 : }
9985 : | ALTER STATISTICS any_name RENAME TO name
9986 : {
9987 30 : RenameStmt *n = makeNode(RenameStmt);
9988 :
9989 30 : n->renameType = OBJECT_STATISTIC_EXT;
9990 30 : n->object = (Node *) $3;
9991 30 : n->newname = $6;
9992 30 : n->missing_ok = false;
9993 30 : $$ = (Node *) n;
9994 : }
9995 : | ALTER TEXT_P SEARCH PARSER any_name RENAME TO name
9996 : {
9997 12 : RenameStmt *n = makeNode(RenameStmt);
9998 :
9999 12 : n->renameType = OBJECT_TSPARSER;
10000 12 : n->object = (Node *) $5;
10001 12 : n->newname = $8;
10002 12 : n->missing_ok = false;
10003 12 : $$ = (Node *) n;
10004 : }
10005 : | ALTER TEXT_P SEARCH DICTIONARY any_name RENAME TO name
10006 : {
10007 24 : RenameStmt *n = makeNode(RenameStmt);
10008 :
10009 24 : n->renameType = OBJECT_TSDICTIONARY;
10010 24 : n->object = (Node *) $5;
10011 24 : n->newname = $8;
10012 24 : n->missing_ok = false;
10013 24 : $$ = (Node *) n;
10014 : }
10015 : | ALTER TEXT_P SEARCH TEMPLATE any_name RENAME TO name
10016 : {
10017 12 : RenameStmt *n = makeNode(RenameStmt);
10018 :
10019 12 : n->renameType = OBJECT_TSTEMPLATE;
10020 12 : n->object = (Node *) $5;
10021 12 : n->newname = $8;
10022 12 : n->missing_ok = false;
10023 12 : $$ = (Node *) n;
10024 : }
10025 : | ALTER TEXT_P SEARCH CONFIGURATION any_name RENAME TO name
10026 : {
10027 24 : RenameStmt *n = makeNode(RenameStmt);
10028 :
10029 24 : n->renameType = OBJECT_TSCONFIGURATION;
10030 24 : n->object = (Node *) $5;
10031 24 : n->newname = $8;
10032 24 : n->missing_ok = false;
10033 24 : $$ = (Node *) n;
10034 : }
10035 : | ALTER TYPE_P any_name RENAME TO name
10036 : {
10037 26 : RenameStmt *n = makeNode(RenameStmt);
10038 :
10039 26 : n->renameType = OBJECT_TYPE;
10040 26 : n->object = (Node *) $3;
10041 26 : n->newname = $6;
10042 26 : n->missing_ok = false;
10043 26 : $$ = (Node *) n;
10044 : }
10045 : | ALTER TYPE_P any_name RENAME ATTRIBUTE name TO name opt_drop_behavior
10046 : {
10047 24 : RenameStmt *n = makeNode(RenameStmt);
10048 :
10049 24 : n->renameType = OBJECT_ATTRIBUTE;
10050 24 : n->relationType = OBJECT_TYPE;
10051 24 : n->relation = makeRangeVarFromAnyName($3, @3, yyscanner);
10052 24 : n->subname = $6;
10053 24 : n->newname = $8;
10054 24 : n->behavior = $9;
10055 24 : n->missing_ok = false;
10056 24 : $$ = (Node *) n;
10057 : }
10058 : ;
10059 :
10060 : opt_column: COLUMN
10061 : | /*EMPTY*/
10062 : ;
10063 :
10064 184 : opt_set_data: SET DATA_P { $$ = 1; }
10065 914 : | /*EMPTY*/ { $$ = 0; }
10066 : ;
10067 :
10068 : /*****************************************************************************
10069 : *
10070 : * ALTER THING name DEPENDS ON EXTENSION name
10071 : *
10072 : *****************************************************************************/
10073 :
10074 : AlterObjectDependsStmt:
10075 : ALTER FUNCTION function_with_argtypes opt_no DEPENDS ON EXTENSION name
10076 : {
10077 12 : AlterObjectDependsStmt *n = makeNode(AlterObjectDependsStmt);
10078 :
10079 12 : n->objectType = OBJECT_FUNCTION;
10080 12 : n->object = (Node *) $3;
10081 12 : n->extname = makeString($8);
10082 12 : n->remove = $4;
10083 12 : $$ = (Node *) n;
10084 : }
10085 : | ALTER PROCEDURE function_with_argtypes opt_no DEPENDS ON EXTENSION name
10086 : {
10087 0 : AlterObjectDependsStmt *n = makeNode(AlterObjectDependsStmt);
10088 :
10089 0 : n->objectType = OBJECT_PROCEDURE;
10090 0 : n->object = (Node *) $3;
10091 0 : n->extname = makeString($8);
10092 0 : n->remove = $4;
10093 0 : $$ = (Node *) n;
10094 : }
10095 : | ALTER ROUTINE function_with_argtypes opt_no DEPENDS ON EXTENSION name
10096 : {
10097 0 : AlterObjectDependsStmt *n = makeNode(AlterObjectDependsStmt);
10098 :
10099 0 : n->objectType = OBJECT_ROUTINE;
10100 0 : n->object = (Node *) $3;
10101 0 : n->extname = makeString($8);
10102 0 : n->remove = $4;
10103 0 : $$ = (Node *) n;
10104 : }
10105 : | ALTER TRIGGER name ON qualified_name opt_no DEPENDS ON EXTENSION name
10106 : {
10107 10 : AlterObjectDependsStmt *n = makeNode(AlterObjectDependsStmt);
10108 :
10109 10 : n->objectType = OBJECT_TRIGGER;
10110 10 : n->relation = $5;
10111 10 : n->object = (Node *) list_make1(makeString($3));
10112 10 : n->extname = makeString($10);
10113 10 : n->remove = $6;
10114 10 : $$ = (Node *) n;
10115 : }
10116 : | ALTER MATERIALIZED VIEW qualified_name opt_no DEPENDS ON EXTENSION name
10117 : {
10118 10 : AlterObjectDependsStmt *n = makeNode(AlterObjectDependsStmt);
10119 :
10120 10 : n->objectType = OBJECT_MATVIEW;
10121 10 : n->relation = $4;
10122 10 : n->extname = makeString($9);
10123 10 : n->remove = $5;
10124 10 : $$ = (Node *) n;
10125 : }
10126 : | ALTER INDEX qualified_name opt_no DEPENDS ON EXTENSION name
10127 : {
10128 14 : AlterObjectDependsStmt *n = makeNode(AlterObjectDependsStmt);
10129 :
10130 14 : n->objectType = OBJECT_INDEX;
10131 14 : n->relation = $3;
10132 14 : n->extname = makeString($8);
10133 14 : n->remove = $4;
10134 14 : $$ = (Node *) n;
10135 : }
10136 : ;
10137 :
10138 8 : opt_no: NO { $$ = true; }
10139 38 : | /* EMPTY */ { $$ = false; }
10140 : ;
10141 :
10142 : /*****************************************************************************
10143 : *
10144 : * ALTER THING name SET SCHEMA name
10145 : *
10146 : *****************************************************************************/
10147 :
10148 : AlterObjectSchemaStmt:
10149 : ALTER AGGREGATE aggregate_with_argtypes SET SCHEMA name
10150 : {
10151 24 : AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
10152 :
10153 24 : n->objectType = OBJECT_AGGREGATE;
10154 24 : n->object = (Node *) $3;
10155 24 : n->newschema = $6;
10156 24 : n->missing_ok = false;
10157 24 : $$ = (Node *) n;
10158 : }
10159 : | ALTER COLLATION any_name SET SCHEMA name
10160 : {
10161 6 : AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
10162 :
10163 6 : n->objectType = OBJECT_COLLATION;
10164 6 : n->object = (Node *) $3;
10165 6 : n->newschema = $6;
10166 6 : n->missing_ok = false;
10167 6 : $$ = (Node *) n;
10168 : }
10169 : | ALTER CONVERSION_P any_name SET SCHEMA name
10170 : {
10171 24 : AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
10172 :
10173 24 : n->objectType = OBJECT_CONVERSION;
10174 24 : n->object = (Node *) $3;
10175 24 : n->newschema = $6;
10176 24 : n->missing_ok = false;
10177 24 : $$ = (Node *) n;
10178 : }
10179 : | ALTER DOMAIN_P any_name SET SCHEMA name
10180 : {
10181 6 : AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
10182 :
10183 6 : n->objectType = OBJECT_DOMAIN;
10184 6 : n->object = (Node *) $3;
10185 6 : n->newschema = $6;
10186 6 : n->missing_ok = false;
10187 6 : $$ = (Node *) n;
10188 : }
10189 : | ALTER EXTENSION name SET SCHEMA name
10190 : {
10191 12 : AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
10192 :
10193 12 : n->objectType = OBJECT_EXTENSION;
10194 12 : n->object = (Node *) makeString($3);
10195 12 : n->newschema = $6;
10196 12 : n->missing_ok = false;
10197 12 : $$ = (Node *) n;
10198 : }
10199 : | ALTER FUNCTION function_with_argtypes SET SCHEMA name
10200 : {
10201 42 : AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
10202 :
10203 42 : n->objectType = OBJECT_FUNCTION;
10204 42 : n->object = (Node *) $3;
10205 42 : n->newschema = $6;
10206 42 : n->missing_ok = false;
10207 42 : $$ = (Node *) n;
10208 : }
10209 : | ALTER OPERATOR operator_with_argtypes SET SCHEMA name
10210 : {
10211 18 : AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
10212 :
10213 18 : n->objectType = OBJECT_OPERATOR;
10214 18 : n->object = (Node *) $3;
10215 18 : n->newschema = $6;
10216 18 : n->missing_ok = false;
10217 18 : $$ = (Node *) n;
10218 : }
10219 : | ALTER OPERATOR CLASS any_name USING name SET SCHEMA name
10220 : {
10221 24 : AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
10222 :
10223 24 : n->objectType = OBJECT_OPCLASS;
10224 24 : n->object = (Node *) lcons(makeString($6), $4);
10225 24 : n->newschema = $9;
10226 24 : n->missing_ok = false;
10227 24 : $$ = (Node *) n;
10228 : }
10229 : | ALTER OPERATOR FAMILY any_name USING name SET SCHEMA name
10230 : {
10231 24 : AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
10232 :
10233 24 : n->objectType = OBJECT_OPFAMILY;
10234 24 : n->object = (Node *) lcons(makeString($6), $4);
10235 24 : n->newschema = $9;
10236 24 : n->missing_ok = false;
10237 24 : $$ = (Node *) n;
10238 : }
10239 : | ALTER PROCEDURE function_with_argtypes SET SCHEMA name
10240 : {
10241 0 : AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
10242 :
10243 0 : n->objectType = OBJECT_PROCEDURE;
10244 0 : n->object = (Node *) $3;
10245 0 : n->newschema = $6;
10246 0 : n->missing_ok = false;
10247 0 : $$ = (Node *) n;
10248 : }
10249 : | ALTER ROUTINE function_with_argtypes SET SCHEMA name
10250 : {
10251 0 : AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
10252 :
10253 0 : n->objectType = OBJECT_ROUTINE;
10254 0 : n->object = (Node *) $3;
10255 0 : n->newschema = $6;
10256 0 : n->missing_ok = false;
10257 0 : $$ = (Node *) n;
10258 : }
10259 : | ALTER TABLE relation_expr SET SCHEMA name
10260 : {
10261 66 : AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
10262 :
10263 66 : n->objectType = OBJECT_TABLE;
10264 66 : n->relation = $3;
10265 66 : n->newschema = $6;
10266 66 : n->missing_ok = false;
10267 66 : $$ = (Node *) n;
10268 : }
10269 : | ALTER TABLE IF_P EXISTS relation_expr SET SCHEMA name
10270 : {
10271 12 : AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
10272 :
10273 12 : n->objectType = OBJECT_TABLE;
10274 12 : n->relation = $5;
10275 12 : n->newschema = $8;
10276 12 : n->missing_ok = true;
10277 12 : $$ = (Node *) n;
10278 : }
10279 : | ALTER STATISTICS any_name SET SCHEMA name
10280 : {
10281 18 : AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
10282 :
10283 18 : n->objectType = OBJECT_STATISTIC_EXT;
10284 18 : n->object = (Node *) $3;
10285 18 : n->newschema = $6;
10286 18 : n->missing_ok = false;
10287 18 : $$ = (Node *) n;
10288 : }
10289 : | ALTER TEXT_P SEARCH PARSER any_name SET SCHEMA name
10290 : {
10291 18 : AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
10292 :
10293 18 : n->objectType = OBJECT_TSPARSER;
10294 18 : n->object = (Node *) $5;
10295 18 : n->newschema = $8;
10296 18 : n->missing_ok = false;
10297 18 : $$ = (Node *) n;
10298 : }
10299 : | ALTER TEXT_P SEARCH DICTIONARY any_name SET SCHEMA name
10300 : {
10301 24 : AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
10302 :
10303 24 : n->objectType = OBJECT_TSDICTIONARY;
10304 24 : n->object = (Node *) $5;
10305 24 : n->newschema = $8;
10306 24 : n->missing_ok = false;
10307 24 : $$ = (Node *) n;
10308 : }
10309 : | ALTER TEXT_P SEARCH TEMPLATE any_name SET SCHEMA name
10310 : {
10311 18 : AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
10312 :
10313 18 : n->objectType = OBJECT_TSTEMPLATE;
10314 18 : n->object = (Node *) $5;
10315 18 : n->newschema = $8;
10316 18 : n->missing_ok = false;
10317 18 : $$ = (Node *) n;
10318 : }
10319 : | ALTER TEXT_P SEARCH CONFIGURATION any_name SET SCHEMA name
10320 : {
10321 24 : AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
10322 :
10323 24 : n->objectType = OBJECT_TSCONFIGURATION;
10324 24 : n->object = (Node *) $5;
10325 24 : n->newschema = $8;
10326 24 : n->missing_ok = false;
10327 24 : $$ = (Node *) n;
10328 : }
10329 : | ALTER SEQUENCE qualified_name SET SCHEMA name
10330 : {
10331 8 : AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
10332 :
10333 8 : n->objectType = OBJECT_SEQUENCE;
10334 8 : n->relation = $3;
10335 8 : n->newschema = $6;
10336 8 : n->missing_ok = false;
10337 8 : $$ = (Node *) n;
10338 : }
10339 : | ALTER SEQUENCE IF_P EXISTS qualified_name SET SCHEMA name
10340 : {
10341 0 : AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
10342 :
10343 0 : n->objectType = OBJECT_SEQUENCE;
10344 0 : n->relation = $5;
10345 0 : n->newschema = $8;
10346 0 : n->missing_ok = true;
10347 0 : $$ = (Node *) n;
10348 : }
10349 : | ALTER VIEW qualified_name SET SCHEMA name
10350 : {
10351 0 : AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
10352 :
10353 0 : n->objectType = OBJECT_VIEW;
10354 0 : n->relation = $3;
10355 0 : n->newschema = $6;
10356 0 : n->missing_ok = false;
10357 0 : $$ = (Node *) n;
10358 : }
10359 : | ALTER VIEW IF_P EXISTS qualified_name SET SCHEMA name
10360 : {
10361 0 : AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
10362 :
10363 0 : n->objectType = OBJECT_VIEW;
10364 0 : n->relation = $5;
10365 0 : n->newschema = $8;
10366 0 : n->missing_ok = true;
10367 0 : $$ = (Node *) n;
10368 : }
10369 : | ALTER MATERIALIZED VIEW qualified_name SET SCHEMA name
10370 : {
10371 6 : AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
10372 :
10373 6 : n->objectType = OBJECT_MATVIEW;
10374 6 : n->relation = $4;
10375 6 : n->newschema = $7;
10376 6 : n->missing_ok = false;
10377 6 : $$ = (Node *) n;
10378 : }
10379 : | ALTER MATERIALIZED VIEW IF_P EXISTS qualified_name SET SCHEMA name
10380 : {
10381 0 : AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
10382 :
10383 0 : n->objectType = OBJECT_MATVIEW;
10384 0 : n->relation = $6;
10385 0 : n->newschema = $9;
10386 0 : n->missing_ok = true;
10387 0 : $$ = (Node *) n;
10388 : }
10389 : | ALTER FOREIGN TABLE relation_expr SET SCHEMA name
10390 : {
10391 6 : AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
10392 :
10393 6 : n->objectType = OBJECT_FOREIGN_TABLE;
10394 6 : n->relation = $4;
10395 6 : n->newschema = $7;
10396 6 : n->missing_ok = false;
10397 6 : $$ = (Node *) n;
10398 : }
10399 : | ALTER FOREIGN TABLE IF_P EXISTS relation_expr SET SCHEMA name
10400 : {
10401 6 : AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
10402 :
10403 6 : n->objectType = OBJECT_FOREIGN_TABLE;
10404 6 : n->relation = $6;
10405 6 : n->newschema = $9;
10406 6 : n->missing_ok = true;
10407 6 : $$ = (Node *) n;
10408 : }
10409 : | ALTER TYPE_P any_name SET SCHEMA name
10410 : {
10411 12 : AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
10412 :
10413 12 : n->objectType = OBJECT_TYPE;
10414 12 : n->object = (Node *) $3;
10415 12 : n->newschema = $6;
10416 12 : n->missing_ok = false;
10417 12 : $$ = (Node *) n;
10418 : }
10419 : ;
10420 :
10421 : /*****************************************************************************
10422 : *
10423 : * ALTER OPERATOR name SET define
10424 : *
10425 : *****************************************************************************/
10426 :
10427 : AlterOperatorStmt:
10428 : ALTER OPERATOR operator_with_argtypes SET '(' operator_def_list ')'
10429 : {
10430 608 : AlterOperatorStmt *n = makeNode(AlterOperatorStmt);
10431 :
10432 608 : n->opername = $3;
10433 608 : n->options = $6;
10434 608 : $$ = (Node *) n;
10435 : }
10436 : ;
10437 :
10438 668 : operator_def_list: operator_def_elem { $$ = list_make1($1); }
10439 506 : | operator_def_list ',' operator_def_elem { $$ = lappend($1, $3); }
10440 : ;
10441 :
10442 : operator_def_elem: ColLabel '=' NONE
10443 30 : { $$ = makeDefElem($1, NULL, @1); }
10444 : | ColLabel '=' operator_def_arg
10445 1110 : { $$ = makeDefElem($1, (Node *) $3, @1); }
10446 : | ColLabel
10447 34 : { $$ = makeDefElem($1, NULL, @1); }
10448 : ;
10449 :
10450 : /* must be similar enough to def_arg to avoid reduce/reduce conflicts */
10451 : operator_def_arg:
10452 1032 : func_type { $$ = (Node *) $1; }
10453 24 : | reserved_keyword { $$ = (Node *) makeString(pstrdup($1)); }
10454 54 : | qual_all_Op { $$ = (Node *) $1; }
10455 0 : | NumericOnly { $$ = (Node *) $1; }
10456 0 : | Sconst { $$ = (Node *) makeString($1); }
10457 : ;
10458 :
10459 : /*****************************************************************************
10460 : *
10461 : * ALTER TYPE name SET define
10462 : *
10463 : * We repurpose ALTER OPERATOR's version of "definition" here
10464 : *
10465 : *****************************************************************************/
10466 :
10467 : AlterTypeStmt:
10468 : ALTER TYPE_P any_name SET '(' operator_def_list ')'
10469 : {
10470 60 : AlterTypeStmt *n = makeNode(AlterTypeStmt);
10471 :
10472 60 : n->typeName = $3;
10473 60 : n->options = $6;
10474 60 : $$ = (Node *) n;
10475 : }
10476 : ;
10477 :
10478 : /*****************************************************************************
10479 : *
10480 : * ALTER THING name OWNER TO newname
10481 : *
10482 : *****************************************************************************/
10483 :
10484 : AlterOwnerStmt: ALTER AGGREGATE aggregate_with_argtypes OWNER TO RoleSpec
10485 : {
10486 142 : AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
10487 :
10488 142 : n->objectType = OBJECT_AGGREGATE;
10489 142 : n->object = (Node *) $3;
10490 142 : n->newowner = $6;
10491 142 : $$ = (Node *) n;
10492 : }
10493 : | ALTER COLLATION any_name OWNER TO RoleSpec
10494 : {
10495 18 : AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
10496 :
10497 18 : n->objectType = OBJECT_COLLATION;
10498 18 : n->object = (Node *) $3;
10499 18 : n->newowner = $6;
10500 18 : $$ = (Node *) n;
10501 : }
10502 : | ALTER CONVERSION_P any_name OWNER TO RoleSpec
10503 : {
10504 24 : AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
10505 :
10506 24 : n->objectType = OBJECT_CONVERSION;
10507 24 : n->object = (Node *) $3;
10508 24 : n->newowner = $6;
10509 24 : $$ = (Node *) n;
10510 : }
10511 : | ALTER DATABASE name OWNER TO RoleSpec
10512 : {
10513 86 : AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
10514 :
10515 86 : n->objectType = OBJECT_DATABASE;
10516 86 : n->object = (Node *) makeString($3);
10517 86 : n->newowner = $6;
10518 86 : $$ = (Node *) n;
10519 : }
10520 : | ALTER DOMAIN_P any_name OWNER TO RoleSpec
10521 : {
10522 48 : AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
10523 :
10524 48 : n->objectType = OBJECT_DOMAIN;
10525 48 : n->object = (Node *) $3;
10526 48 : n->newowner = $6;
10527 48 : $$ = (Node *) n;
10528 : }
10529 : | ALTER FUNCTION function_with_argtypes OWNER TO RoleSpec
10530 : {
10531 594 : AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
10532 :
10533 594 : n->objectType = OBJECT_FUNCTION;
10534 594 : n->object = (Node *) $3;
10535 594 : n->newowner = $6;
10536 594 : $$ = (Node *) n;
10537 : }
10538 : | ALTER opt_procedural LANGUAGE name OWNER TO RoleSpec
10539 : {
10540 142 : AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
10541 :
10542 142 : n->objectType = OBJECT_LANGUAGE;
10543 142 : n->object = (Node *) makeString($4);
10544 142 : n->newowner = $7;
10545 142 : $$ = (Node *) n;
10546 : }
10547 : | ALTER LARGE_P OBJECT_P NumericOnly OWNER TO RoleSpec
10548 : {
10549 16 : AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
10550 :
10551 16 : n->objectType = OBJECT_LARGEOBJECT;
10552 16 : n->object = (Node *) $4;
10553 16 : n->newowner = $7;
10554 16 : $$ = (Node *) n;
10555 : }
10556 : | ALTER OPERATOR operator_with_argtypes OWNER TO RoleSpec
10557 : {
10558 46 : AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
10559 :
10560 46 : n->objectType = OBJECT_OPERATOR;
10561 46 : n->object = (Node *) $3;
10562 46 : n->newowner = $6;
10563 46 : $$ = (Node *) n;
10564 : }
10565 : | ALTER OPERATOR CLASS any_name USING name OWNER TO RoleSpec
10566 : {
10567 54 : AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
10568 :
10569 54 : n->objectType = OBJECT_OPCLASS;
10570 54 : n->object = (Node *) lcons(makeString($6), $4);
10571 54 : n->newowner = $9;
10572 54 : $$ = (Node *) n;
10573 : }
10574 : | ALTER OPERATOR FAMILY any_name USING name OWNER TO RoleSpec
10575 : {
10576 62 : AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
10577 :
10578 62 : n->objectType = OBJECT_OPFAMILY;
10579 62 : n->object = (Node *) lcons(makeString($6), $4);
10580 62 : n->newowner = $9;
10581 62 : $$ = (Node *) n;
10582 : }
10583 : | ALTER PROCEDURE function_with_argtypes OWNER TO RoleSpec
10584 : {
10585 24 : AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
10586 :
10587 24 : n->objectType = OBJECT_PROCEDURE;
10588 24 : n->object = (Node *) $3;
10589 24 : n->newowner = $6;
10590 24 : $$ = (Node *) n;
10591 : }
10592 : | ALTER ROUTINE function_with_argtypes OWNER TO RoleSpec
10593 : {
10594 0 : AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
10595 :
10596 0 : n->objectType = OBJECT_ROUTINE;
10597 0 : n->object = (Node *) $3;
10598 0 : n->newowner = $6;
10599 0 : $$ = (Node *) n;
10600 : }
10601 : | ALTER SCHEMA name OWNER TO RoleSpec
10602 : {
10603 64 : AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
10604 :
10605 64 : n->objectType = OBJECT_SCHEMA;
10606 64 : n->object = (Node *) makeString($3);
10607 64 : n->newowner = $6;
10608 64 : $$ = (Node *) n;
10609 : }
10610 : | ALTER TYPE_P any_name OWNER TO RoleSpec
10611 : {
10612 84 : AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
10613 :
10614 84 : n->objectType = OBJECT_TYPE;
10615 84 : n->object = (Node *) $3;
10616 84 : n->newowner = $6;
10617 84 : $$ = (Node *) n;
10618 : }
10619 : | ALTER TABLESPACE name OWNER TO RoleSpec
10620 : {
10621 6 : AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
10622 :
10623 6 : n->objectType = OBJECT_TABLESPACE;
10624 6 : n->object = (Node *) makeString($3);
10625 6 : n->newowner = $6;
10626 6 : $$ = (Node *) n;
10627 : }
10628 : | ALTER STATISTICS any_name OWNER TO RoleSpec
10629 : {
10630 32 : AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
10631 :
10632 32 : n->objectType = OBJECT_STATISTIC_EXT;
10633 32 : n->object = (Node *) $3;
10634 32 : n->newowner = $6;
10635 32 : $$ = (Node *) n;
10636 : }
10637 : | ALTER TEXT_P SEARCH DICTIONARY any_name OWNER TO RoleSpec
10638 : {
10639 42 : AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
10640 :
10641 42 : n->objectType = OBJECT_TSDICTIONARY;
10642 42 : n->object = (Node *) $5;
10643 42 : n->newowner = $8;
10644 42 : $$ = (Node *) n;
10645 : }
10646 : | ALTER TEXT_P SEARCH CONFIGURATION any_name OWNER TO RoleSpec
10647 : {
10648 32 : AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
10649 :
10650 32 : n->objectType = OBJECT_TSCONFIGURATION;
10651 32 : n->object = (Node *) $5;
10652 32 : n->newowner = $8;
10653 32 : $$ = (Node *) n;
10654 : }
10655 : | ALTER FOREIGN DATA_P WRAPPER name OWNER TO RoleSpec
10656 : {
10657 20 : AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
10658 :
10659 20 : n->objectType = OBJECT_FDW;
10660 20 : n->object = (Node *) makeString($5);
10661 20 : n->newowner = $8;
10662 20 : $$ = (Node *) n;
10663 : }
10664 : | ALTER SERVER name OWNER TO RoleSpec
10665 : {
10666 68 : AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
10667 :
10668 68 : n->objectType = OBJECT_FOREIGN_SERVER;
10669 68 : n->object = (Node *) makeString($3);
10670 68 : n->newowner = $6;
10671 68 : $$ = (Node *) n;
10672 : }
10673 : | ALTER EVENT TRIGGER name OWNER TO RoleSpec
10674 : {
10675 14 : AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
10676 :
10677 14 : n->objectType = OBJECT_EVENT_TRIGGER;
10678 14 : n->object = (Node *) makeString($4);
10679 14 : n->newowner = $7;
10680 14 : $$ = (Node *) n;
10681 : }
10682 : | ALTER PUBLICATION name OWNER TO RoleSpec
10683 : {
10684 36 : AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
10685 :
10686 36 : n->objectType = OBJECT_PUBLICATION;
10687 36 : n->object = (Node *) makeString($3);
10688 36 : n->newowner = $6;
10689 36 : $$ = (Node *) n;
10690 : }
10691 : | ALTER SUBSCRIPTION name OWNER TO RoleSpec
10692 : {
10693 18 : AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
10694 :
10695 18 : n->objectType = OBJECT_SUBSCRIPTION;
10696 18 : n->object = (Node *) makeString($3);
10697 18 : n->newowner = $6;
10698 18 : $$ = (Node *) n;
10699 : }
10700 : ;
10701 :
10702 :
10703 : /*****************************************************************************
10704 : *
10705 : * CREATE PUBLICATION name [WITH options]
10706 : *
10707 : * CREATE PUBLICATION FOR ALL TABLES [WITH options]
10708 : *
10709 : * CREATE PUBLICATION FOR pub_obj [, ...] [WITH options]
10710 : *
10711 : * pub_obj is one of:
10712 : *
10713 : * TABLE table [, ...]
10714 : * TABLES IN SCHEMA schema [, ...]
10715 : *
10716 : *****************************************************************************/
10717 :
10718 : CreatePublicationStmt:
10719 : CREATE PUBLICATION name opt_definition
10720 : {
10721 146 : CreatePublicationStmt *n = makeNode(CreatePublicationStmt);
10722 :
10723 146 : n->pubname = $3;
10724 146 : n->options = $4;
10725 146 : $$ = (Node *) n;
10726 : }
10727 : | CREATE PUBLICATION name FOR ALL TABLES opt_definition
10728 : {
10729 100 : CreatePublicationStmt *n = makeNode(CreatePublicationStmt);
10730 :
10731 100 : n->pubname = $3;
10732 100 : n->options = $7;
10733 100 : n->for_all_tables = true;
10734 100 : $$ = (Node *) n;
10735 : }
10736 : | CREATE PUBLICATION name FOR pub_obj_list opt_definition
10737 : {
10738 658 : CreatePublicationStmt *n = makeNode(CreatePublicationStmt);
10739 :
10740 658 : n->pubname = $3;
10741 658 : n->options = $6;
10742 658 : n->pubobjects = (List *) $5;
10743 658 : preprocess_pubobj_list(n->pubobjects, yyscanner);
10744 628 : $$ = (Node *) n;
10745 : }
10746 : ;
10747 :
10748 : /*
10749 : * FOR TABLE and FOR TABLES IN SCHEMA specifications
10750 : *
10751 : * This rule parses publication objects with and without keyword prefixes.
10752 : *
10753 : * The actual type of the object without keyword prefix depends on the previous
10754 : * one with keyword prefix. It will be preprocessed in preprocess_pubobj_list().
10755 : *
10756 : * For the object without keyword prefix, we cannot just use relation_expr here,
10757 : * because some extended expressions in relation_expr cannot be used as a
10758 : * schemaname and we cannot differentiate it. So, we extract the rules from
10759 : * relation_expr here.
10760 : */
10761 : PublicationObjSpec:
10762 : TABLE relation_expr opt_column_list OptWhereClause
10763 : {
10764 1326 : $$ = makeNode(PublicationObjSpec);
10765 1326 : $$->pubobjtype = PUBLICATIONOBJ_TABLE;
10766 1326 : $$->pubtable = makeNode(PublicationTable);
10767 1326 : $$->pubtable->relation = $2;
10768 1326 : $$->pubtable->columns = $3;
10769 1326 : $$->pubtable->whereClause = $4;
10770 : }
10771 : | TABLES IN_P SCHEMA ColId
10772 : {
10773 372 : $$ = makeNode(PublicationObjSpec);
10774 372 : $$->pubobjtype = PUBLICATIONOBJ_TABLES_IN_SCHEMA;
10775 372 : $$->name = $4;
10776 372 : $$->location = @4;
10777 : }
10778 : | TABLES IN_P SCHEMA CURRENT_SCHEMA
10779 : {
10780 18 : $$ = makeNode(PublicationObjSpec);
10781 18 : $$->pubobjtype = PUBLICATIONOBJ_TABLES_IN_CUR_SCHEMA;
10782 18 : $$->location = @4;
10783 : }
10784 : | ColId opt_column_list OptWhereClause
10785 : {
10786 130 : $$ = makeNode(PublicationObjSpec);
10787 130 : $$->pubobjtype = PUBLICATIONOBJ_CONTINUATION;
10788 : /*
10789 : * If either a row filter or column list is specified, create
10790 : * a PublicationTable object.
10791 : */
10792 130 : if ($2 || $3)
10793 : {
10794 : /*
10795 : * The OptWhereClause must be stored here but it is
10796 : * valid only for tables. For non-table objects, an
10797 : * error will be thrown later via
10798 : * preprocess_pubobj_list().
10799 : */
10800 42 : $$->pubtable = makeNode(PublicationTable);
10801 42 : $$->pubtable->relation = makeRangeVar(NULL, $1, @1);
10802 42 : $$->pubtable->columns = $2;
10803 42 : $$->pubtable->whereClause = $3;
10804 : }
10805 : else
10806 : {
10807 88 : $$->name = $1;
10808 : }
10809 130 : $$->location = @1;
10810 : }
10811 : | ColId indirection opt_column_list OptWhereClause
10812 : {
10813 32 : $$ = makeNode(PublicationObjSpec);
10814 32 : $$->pubobjtype = PUBLICATIONOBJ_CONTINUATION;
10815 32 : $$->pubtable = makeNode(PublicationTable);
10816 32 : $$->pubtable->relation = makeRangeVarFromQualifiedName($1, $2, @1, yyscanner);
10817 32 : $$->pubtable->columns = $3;
10818 32 : $$->pubtable->whereClause = $4;
10819 32 : $$->location = @1;
10820 : }
10821 : /* grammar like tablename * , ONLY tablename, ONLY ( tablename ) */
10822 : | extended_relation_expr opt_column_list OptWhereClause
10823 : {
10824 6 : $$ = makeNode(PublicationObjSpec);
10825 6 : $$->pubobjtype = PUBLICATIONOBJ_CONTINUATION;
10826 6 : $$->pubtable = makeNode(PublicationTable);
10827 6 : $$->pubtable->relation = $1;
10828 6 : $$->pubtable->columns = $2;
10829 6 : $$->pubtable->whereClause = $3;
10830 : }
10831 : | CURRENT_SCHEMA
10832 : {
10833 18 : $$ = makeNode(PublicationObjSpec);
10834 18 : $$->pubobjtype = PUBLICATIONOBJ_CONTINUATION;
10835 18 : $$->location = @1;
10836 : }
10837 : ;
10838 :
10839 : pub_obj_list: PublicationObjSpec
10840 1648 : { $$ = list_make1($1); }
10841 : | pub_obj_list ',' PublicationObjSpec
10842 254 : { $$ = lappend($1, $3); }
10843 : ;
10844 :
10845 : /*****************************************************************************
10846 : *
10847 : * ALTER PUBLICATION name SET ( options )
10848 : *
10849 : * ALTER PUBLICATION name ADD pub_obj [, ...]
10850 : *
10851 : * ALTER PUBLICATION name DROP pub_obj [, ...]
10852 : *
10853 : * ALTER PUBLICATION name SET pub_obj [, ...]
10854 : *
10855 : * pub_obj is one of:
10856 : *
10857 : * TABLE table_name [, ...]
10858 : * TABLES IN SCHEMA schema_name [, ...]
10859 : *
10860 : *****************************************************************************/
10861 :
10862 : AlterPublicationStmt:
10863 : ALTER PUBLICATION name SET definition
10864 : {
10865 116 : AlterPublicationStmt *n = makeNode(AlterPublicationStmt);
10866 :
10867 116 : n->pubname = $3;
10868 116 : n->options = $5;
10869 116 : $$ = (Node *) n;
10870 : }
10871 : | ALTER PUBLICATION name ADD_P pub_obj_list
10872 : {
10873 370 : AlterPublicationStmt *n = makeNode(AlterPublicationStmt);
10874 :
10875 370 : n->pubname = $3;
10876 370 : n->pubobjects = $5;
10877 370 : preprocess_pubobj_list(n->pubobjects, yyscanner);
10878 364 : n->action = AP_AddObjects;
10879 364 : $$ = (Node *) n;
10880 : }
10881 : | ALTER PUBLICATION name SET pub_obj_list
10882 : {
10883 464 : AlterPublicationStmt *n = makeNode(AlterPublicationStmt);
10884 :
10885 464 : n->pubname = $3;
10886 464 : n->pubobjects = $5;
10887 464 : preprocess_pubobj_list(n->pubobjects, yyscanner);
10888 464 : n->action = AP_SetObjects;
10889 464 : $$ = (Node *) n;
10890 : }
10891 : | ALTER PUBLICATION name DROP pub_obj_list
10892 : {
10893 156 : AlterPublicationStmt *n = makeNode(AlterPublicationStmt);
10894 :
10895 156 : n->pubname = $3;
10896 156 : n->pubobjects = $5;
10897 156 : preprocess_pubobj_list(n->pubobjects, yyscanner);
10898 156 : n->action = AP_DropObjects;
10899 156 : $$ = (Node *) n;
10900 : }
10901 : ;
10902 :
10903 : /*****************************************************************************
10904 : *
10905 : * CREATE SUBSCRIPTION name ...
10906 : *
10907 : *****************************************************************************/
10908 :
10909 : CreateSubscriptionStmt:
10910 : CREATE SUBSCRIPTION name CONNECTION Sconst PUBLICATION name_list opt_definition
10911 : {
10912 : CreateSubscriptionStmt *n =
10913 480 : makeNode(CreateSubscriptionStmt);
10914 480 : n->subname = $3;
10915 480 : n->conninfo = $5;
10916 480 : n->publication = $7;
10917 480 : n->options = $8;
10918 480 : $$ = (Node *) n;
10919 : }
10920 : ;
10921 :
10922 : /*****************************************************************************
10923 : *
10924 : * ALTER SUBSCRIPTION name ...
10925 : *
10926 : *****************************************************************************/
10927 :
10928 : AlterSubscriptionStmt:
10929 : ALTER SUBSCRIPTION name SET definition
10930 : {
10931 : AlterSubscriptionStmt *n =
10932 218 : makeNode(AlterSubscriptionStmt);
10933 :
10934 218 : n->kind = ALTER_SUBSCRIPTION_OPTIONS;
10935 218 : n->subname = $3;
10936 218 : n->options = $5;
10937 218 : $$ = (Node *) n;
10938 : }
10939 : | ALTER SUBSCRIPTION name CONNECTION Sconst
10940 : {
10941 : AlterSubscriptionStmt *n =
10942 26 : makeNode(AlterSubscriptionStmt);
10943 :
10944 26 : n->kind = ALTER_SUBSCRIPTION_CONNECTION;
10945 26 : n->subname = $3;
10946 26 : n->conninfo = $5;
10947 26 : $$ = (Node *) n;
10948 : }
10949 : | ALTER SUBSCRIPTION name REFRESH PUBLICATION opt_definition
10950 : {
10951 : AlterSubscriptionStmt *n =
10952 62 : makeNode(AlterSubscriptionStmt);
10953 :
10954 62 : n->kind = ALTER_SUBSCRIPTION_REFRESH;
10955 62 : n->subname = $3;
10956 62 : n->options = $6;
10957 62 : $$ = (Node *) n;
10958 : }
10959 : | ALTER SUBSCRIPTION name ADD_P PUBLICATION name_list opt_definition
10960 : {
10961 : AlterSubscriptionStmt *n =
10962 28 : makeNode(AlterSubscriptionStmt);
10963 :
10964 28 : n->kind = ALTER_SUBSCRIPTION_ADD_PUBLICATION;
10965 28 : n->subname = $3;
10966 28 : n->publication = $6;
10967 28 : n->options = $7;
10968 28 : $$ = (Node *) n;
10969 : }
10970 : | ALTER SUBSCRIPTION name DROP PUBLICATION name_list opt_definition
10971 : {
10972 : AlterSubscriptionStmt *n =
10973 26 : makeNode(AlterSubscriptionStmt);
10974 :
10975 26 : n->kind = ALTER_SUBSCRIPTION_DROP_PUBLICATION;
10976 26 : n->subname = $3;
10977 26 : n->publication = $6;
10978 26 : n->options = $7;
10979 26 : $$ = (Node *) n;
10980 : }
10981 : | ALTER SUBSCRIPTION name SET PUBLICATION name_list opt_definition
10982 : {
10983 : AlterSubscriptionStmt *n =
10984 44 : makeNode(AlterSubscriptionStmt);
10985 :
10986 44 : n->kind = ALTER_SUBSCRIPTION_SET_PUBLICATION;
10987 44 : n->subname = $3;
10988 44 : n->publication = $6;
10989 44 : n->options = $7;
10990 44 : $$ = (Node *) n;
10991 : }
10992 : | ALTER SUBSCRIPTION name ENABLE_P
10993 : {
10994 : AlterSubscriptionStmt *n =
10995 60 : makeNode(AlterSubscriptionStmt);
10996 :
10997 60 : n->kind = ALTER_SUBSCRIPTION_ENABLED;
10998 60 : n->subname = $3;
10999 60 : n->options = list_make1(makeDefElem("enabled",
11000 : (Node *) makeBoolean(true), @1));
11001 60 : $$ = (Node *) n;
11002 : }
11003 : | ALTER SUBSCRIPTION name DISABLE_P
11004 : {
11005 : AlterSubscriptionStmt *n =
11006 44 : makeNode(AlterSubscriptionStmt);
11007 :
11008 44 : n->kind = ALTER_SUBSCRIPTION_ENABLED;
11009 44 : n->subname = $3;
11010 44 : n->options = list_make1(makeDefElem("enabled",
11011 : (Node *) makeBoolean(false), @1));
11012 44 : $$ = (Node *) n;
11013 : }
11014 : | ALTER SUBSCRIPTION name SKIP definition
11015 : {
11016 : AlterSubscriptionStmt *n =
11017 24 : makeNode(AlterSubscriptionStmt);
11018 :
11019 24 : n->kind = ALTER_SUBSCRIPTION_SKIP;
11020 24 : n->subname = $3;
11021 24 : n->options = $5;
11022 24 : $$ = (Node *) n;
11023 : }
11024 : ;
11025 :
11026 : /*****************************************************************************
11027 : *
11028 : * DROP SUBSCRIPTION [ IF EXISTS ] name
11029 : *
11030 : *****************************************************************************/
11031 :
11032 : DropSubscriptionStmt: DROP SUBSCRIPTION name opt_drop_behavior
11033 : {
11034 242 : DropSubscriptionStmt *n = makeNode(DropSubscriptionStmt);
11035 :
11036 242 : n->subname = $3;
11037 242 : n->missing_ok = false;
11038 242 : n->behavior = $4;
11039 242 : $$ = (Node *) n;
11040 : }
11041 : | DROP SUBSCRIPTION IF_P EXISTS name opt_drop_behavior
11042 : {
11043 6 : DropSubscriptionStmt *n = makeNode(DropSubscriptionStmt);
11044 :
11045 6 : n->subname = $5;
11046 6 : n->missing_ok = true;
11047 6 : n->behavior = $6;
11048 6 : $$ = (Node *) n;
11049 : }
11050 : ;
11051 :
11052 : /*****************************************************************************
11053 : *
11054 : * QUERY: Define Rewrite Rule
11055 : *
11056 : *****************************************************************************/
11057 :
11058 : RuleStmt: CREATE opt_or_replace RULE name AS
11059 : ON event TO qualified_name where_clause
11060 : DO opt_instead RuleActionList
11061 : {
11062 1092 : RuleStmt *n = makeNode(RuleStmt);
11063 :
11064 1092 : n->replace = $2;
11065 1092 : n->relation = $9;
11066 1092 : n->rulename = $4;
11067 1092 : n->whereClause = $10;
11068 1092 : n->event = $7;
11069 1092 : n->instead = $12;
11070 1092 : n->actions = $13;
11071 1092 : $$ = (Node *) n;
11072 : }
11073 : ;
11074 :
11075 : RuleActionList:
11076 162 : NOTHING { $$ = NIL; }
11077 884 : | RuleActionStmt { $$ = list_make1($1); }
11078 46 : | '(' RuleActionMulti ')' { $$ = $2; }
11079 : ;
11080 :
11081 : /* the thrashing around here is to discard "empty" statements... */
11082 : RuleActionMulti:
11083 : RuleActionMulti ';' RuleActionStmtOrEmpty
11084 62 : { if ($3 != NULL)
11085 46 : $$ = lappend($1, $3);
11086 : else
11087 16 : $$ = $1;
11088 : }
11089 : | RuleActionStmtOrEmpty
11090 46 : { if ($1 != NULL)
11091 46 : $$ = list_make1($1);
11092 : else
11093 0 : $$ = NIL;
11094 : }
11095 : ;
11096 :
11097 : RuleActionStmt:
11098 : SelectStmt
11099 : | InsertStmt
11100 : | UpdateStmt
11101 : | DeleteStmt
11102 : | NotifyStmt
11103 : ;
11104 :
11105 : RuleActionStmtOrEmpty:
11106 92 : RuleActionStmt { $$ = $1; }
11107 16 : | /*EMPTY*/ { $$ = NULL; }
11108 : ;
11109 :
11110 18 : event: SELECT { $$ = CMD_SELECT; }
11111 432 : | UPDATE { $$ = CMD_UPDATE; }
11112 164 : | DELETE_P { $$ = CMD_DELETE; }
11113 478 : | INSERT { $$ = CMD_INSERT; }
11114 : ;
11115 :
11116 : opt_instead:
11117 752 : INSTEAD { $$ = true; }
11118 156 : | ALSO { $$ = false; }
11119 184 : | /*EMPTY*/ { $$ = false; }
11120 : ;
11121 :
11122 :
11123 : /*****************************************************************************
11124 : *
11125 : * QUERY:
11126 : * NOTIFY <identifier> can appear both in rule bodies and
11127 : * as a query-level command
11128 : *
11129 : *****************************************************************************/
11130 :
11131 : NotifyStmt: NOTIFY ColId notify_payload
11132 : {
11133 128 : NotifyStmt *n = makeNode(NotifyStmt);
11134 :
11135 128 : n->conditionname = $2;
11136 128 : n->payload = $3;
11137 128 : $$ = (Node *) n;
11138 : }
11139 : ;
11140 :
11141 : notify_payload:
11142 62 : ',' Sconst { $$ = $2; }
11143 66 : | /*EMPTY*/ { $$ = NULL; }
11144 : ;
11145 :
11146 : ListenStmt: LISTEN ColId
11147 : {
11148 74 : ListenStmt *n = makeNode(ListenStmt);
11149 :
11150 74 : n->conditionname = $2;
11151 74 : $$ = (Node *) n;
11152 : }
11153 : ;
11154 :
11155 : UnlistenStmt:
11156 : UNLISTEN ColId
11157 : {
11158 6 : UnlistenStmt *n = makeNode(UnlistenStmt);
11159 :
11160 6 : n->conditionname = $2;
11161 6 : $$ = (Node *) n;
11162 : }
11163 : | UNLISTEN '*'
11164 : {
11165 32 : UnlistenStmt *n = makeNode(UnlistenStmt);
11166 :
11167 32 : n->conditionname = NULL;
11168 32 : $$ = (Node *) n;
11169 : }
11170 : ;
11171 :
11172 :
11173 : /*****************************************************************************
11174 : *
11175 : * Transactions:
11176 : *
11177 : * BEGIN / COMMIT / ROLLBACK
11178 : * (also older versions END / ABORT)
11179 : *
11180 : *****************************************************************************/
11181 :
11182 : TransactionStmt:
11183 : ABORT_P opt_transaction opt_transaction_chain
11184 : {
11185 232 : TransactionStmt *n = makeNode(TransactionStmt);
11186 :
11187 232 : n->kind = TRANS_STMT_ROLLBACK;
11188 232 : n->options = NIL;
11189 232 : n->chain = $3;
11190 232 : n->location = -1;
11191 232 : $$ = (Node *) n;
11192 : }
11193 : | START TRANSACTION transaction_mode_list_or_empty
11194 : {
11195 1638 : TransactionStmt *n = makeNode(TransactionStmt);
11196 :
11197 1638 : n->kind = TRANS_STMT_START;
11198 1638 : n->options = $3;
11199 1638 : n->location = -1;
11200 1638 : $$ = (Node *) n;
11201 : }
11202 : | COMMIT opt_transaction opt_transaction_chain
11203 : {
11204 11938 : TransactionStmt *n = makeNode(TransactionStmt);
11205 :
11206 11938 : n->kind = TRANS_STMT_COMMIT;
11207 11938 : n->options = NIL;
11208 11938 : n->chain = $3;
11209 11938 : n->location = -1;
11210 11938 : $$ = (Node *) n;
11211 : }
11212 : | ROLLBACK opt_transaction opt_transaction_chain
11213 : {
11214 2676 : TransactionStmt *n = makeNode(TransactionStmt);
11215 :
11216 2676 : n->kind = TRANS_STMT_ROLLBACK;
11217 2676 : n->options = NIL;
11218 2676 : n->chain = $3;
11219 2676 : n->location = -1;
11220 2676 : $$ = (Node *) n;
11221 : }
11222 : | SAVEPOINT ColId
11223 : {
11224 1912 : TransactionStmt *n = makeNode(TransactionStmt);
11225 :
11226 1912 : n->kind = TRANS_STMT_SAVEPOINT;
11227 1912 : n->savepoint_name = $2;
11228 1912 : n->location = @2;
11229 1912 : $$ = (Node *) n;
11230 : }
11231 : | RELEASE SAVEPOINT ColId
11232 : {
11233 208 : TransactionStmt *n = makeNode(TransactionStmt);
11234 :
11235 208 : n->kind = TRANS_STMT_RELEASE;
11236 208 : n->savepoint_name = $3;
11237 208 : n->location = @3;
11238 208 : $$ = (Node *) n;
11239 : }
11240 : | RELEASE ColId
11241 : {
11242 86 : TransactionStmt *n = makeNode(TransactionStmt);
11243 :
11244 86 : n->kind = TRANS_STMT_RELEASE;
11245 86 : n->savepoint_name = $2;
11246 86 : n->location = @2;
11247 86 : $$ = (Node *) n;
11248 : }
11249 : | ROLLBACK opt_transaction TO SAVEPOINT ColId
11250 : {
11251 228 : TransactionStmt *n = makeNode(TransactionStmt);
11252 :
11253 228 : n->kind = TRANS_STMT_ROLLBACK_TO;
11254 228 : n->savepoint_name = $5;
11255 228 : n->location = @5;
11256 228 : $$ = (Node *) n;
11257 : }
11258 : | ROLLBACK opt_transaction TO ColId
11259 : {
11260 496 : TransactionStmt *n = makeNode(TransactionStmt);
11261 :
11262 496 : n->kind = TRANS_STMT_ROLLBACK_TO;
11263 496 : n->savepoint_name = $4;
11264 496 : n->location = @4;
11265 496 : $$ = (Node *) n;
11266 : }
11267 : | PREPARE TRANSACTION Sconst
11268 : {
11269 634 : TransactionStmt *n = makeNode(TransactionStmt);
11270 :
11271 634 : n->kind = TRANS_STMT_PREPARE;
11272 634 : n->gid = $3;
11273 634 : n->location = @3;
11274 634 : $$ = (Node *) n;
11275 : }
11276 : | COMMIT PREPARED Sconst
11277 : {
11278 474 : TransactionStmt *n = makeNode(TransactionStmt);
11279 :
11280 474 : n->kind = TRANS_STMT_COMMIT_PREPARED;
11281 474 : n->gid = $3;
11282 474 : n->location = @3;
11283 474 : $$ = (Node *) n;
11284 : }
11285 : | ROLLBACK PREPARED Sconst
11286 : {
11287 72 : TransactionStmt *n = makeNode(TransactionStmt);
11288 :
11289 72 : n->kind = TRANS_STMT_ROLLBACK_PREPARED;
11290 72 : n->gid = $3;
11291 72 : n->location = @3;
11292 72 : $$ = (Node *) n;
11293 : }
11294 : ;
11295 :
11296 : TransactionStmtLegacy:
11297 : BEGIN_P opt_transaction transaction_mode_list_or_empty
11298 : {
11299 14556 : TransactionStmt *n = makeNode(TransactionStmt);
11300 :
11301 14556 : n->kind = TRANS_STMT_BEGIN;
11302 14556 : n->options = $3;
11303 14556 : n->location = -1;
11304 14556 : $$ = (Node *) n;
11305 : }
11306 : | END_P opt_transaction opt_transaction_chain
11307 : {
11308 360 : TransactionStmt *n = makeNode(TransactionStmt);
11309 :
11310 360 : n->kind = TRANS_STMT_COMMIT;
11311 360 : n->options = NIL;
11312 360 : n->chain = $3;
11313 360 : n->location = -1;
11314 360 : $$ = (Node *) n;
11315 : }
11316 : ;
11317 :
11318 : opt_transaction: WORK
11319 : | TRANSACTION
11320 : | /*EMPTY*/
11321 : ;
11322 :
11323 : transaction_mode_item:
11324 : ISOLATION LEVEL iso_level
11325 6860 : { $$ = makeDefElem("transaction_isolation",
11326 6860 : makeStringConst($3, @3), @1); }
11327 : | READ ONLY
11328 1408 : { $$ = makeDefElem("transaction_read_only",
11329 1408 : makeIntConst(true, @1), @1); }
11330 : | READ WRITE
11331 90 : { $$ = makeDefElem("transaction_read_only",
11332 90 : makeIntConst(false, @1), @1); }
11333 : | DEFERRABLE
11334 44 : { $$ = makeDefElem("transaction_deferrable",
11335 : makeIntConst(true, @1), @1); }
11336 : | NOT DEFERRABLE
11337 10 : { $$ = makeDefElem("transaction_deferrable",
11338 10 : makeIntConst(false, @1), @1); }
11339 : ;
11340 :
11341 : /* Syntax with commas is SQL-spec, without commas is Postgres historical */
11342 : transaction_mode_list:
11343 : transaction_mode_item
11344 7076 : { $$ = list_make1($1); }
11345 : | transaction_mode_list ',' transaction_mode_item
11346 938 : { $$ = lappend($1, $3); }
11347 : | transaction_mode_list transaction_mode_item
11348 398 : { $$ = lappend($1, $2); }
11349 : ;
11350 :
11351 : transaction_mode_list_or_empty:
11352 : transaction_mode_list
11353 : | /* EMPTY */
11354 9716 : { $$ = NIL; }
11355 : ;
11356 :
11357 : opt_transaction_chain:
11358 120 : AND CHAIN { $$ = true; }
11359 2 : | AND NO CHAIN { $$ = false; }
11360 15084 : | /* EMPTY */ { $$ = false; }
11361 : ;
11362 :
11363 :
11364 : /*****************************************************************************
11365 : *
11366 : * QUERY:
11367 : * CREATE [ OR REPLACE ] [ TEMP ] VIEW <viewname> '('target-list ')'
11368 : * AS <query> [ WITH [ CASCADED | LOCAL ] CHECK OPTION ]
11369 : *
11370 : *****************************************************************************/
11371 :
11372 : ViewStmt: CREATE OptTemp VIEW qualified_name opt_column_list opt_reloptions
11373 : AS SelectStmt opt_check_option
11374 : {
11375 16706 : ViewStmt *n = makeNode(ViewStmt);
11376 :
11377 16706 : n->view = $4;
11378 16706 : n->view->relpersistence = $2;
11379 16706 : n->aliases = $5;
11380 16706 : n->query = $8;
11381 16706 : n->replace = false;
11382 16706 : n->options = $6;
11383 16706 : n->withCheckOption = $9;
11384 16706 : $$ = (Node *) n;
11385 : }
11386 : | CREATE OR REPLACE OptTemp VIEW qualified_name opt_column_list opt_reloptions
11387 : AS SelectStmt opt_check_option
11388 : {
11389 244 : ViewStmt *n = makeNode(ViewStmt);
11390 :
11391 244 : n->view = $6;
11392 244 : n->view->relpersistence = $4;
11393 244 : n->aliases = $7;
11394 244 : n->query = $10;
11395 244 : n->replace = true;
11396 244 : n->options = $8;
11397 244 : n->withCheckOption = $11;
11398 244 : $$ = (Node *) n;
11399 : }
11400 : | CREATE OptTemp RECURSIVE VIEW qualified_name '(' columnList ')' opt_reloptions
11401 : AS SelectStmt opt_check_option
11402 : {
11403 8 : ViewStmt *n = makeNode(ViewStmt);
11404 :
11405 8 : n->view = $5;
11406 8 : n->view->relpersistence = $2;
11407 8 : n->aliases = $7;
11408 8 : n->query = makeRecursiveViewSelect(n->view->relname, n->aliases, $11);
11409 8 : n->replace = false;
11410 8 : n->options = $9;
11411 8 : n->withCheckOption = $12;
11412 8 : if (n->withCheckOption != NO_CHECK_OPTION)
11413 0 : ereport(ERROR,
11414 : (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
11415 : errmsg("WITH CHECK OPTION not supported on recursive views"),
11416 : parser_errposition(@12)));
11417 8 : $$ = (Node *) n;
11418 : }
11419 : | CREATE OR REPLACE OptTemp RECURSIVE VIEW qualified_name '(' columnList ')' opt_reloptions
11420 : AS SelectStmt opt_check_option
11421 : {
11422 6 : ViewStmt *n = makeNode(ViewStmt);
11423 :
11424 6 : n->view = $7;
11425 6 : n->view->relpersistence = $4;
11426 6 : n->aliases = $9;
11427 6 : n->query = makeRecursiveViewSelect(n->view->relname, n->aliases, $13);
11428 6 : n->replace = true;
11429 6 : n->options = $11;
11430 6 : n->withCheckOption = $14;
11431 6 : if (n->withCheckOption != NO_CHECK_OPTION)
11432 0 : ereport(ERROR,
11433 : (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
11434 : errmsg("WITH CHECK OPTION not supported on recursive views"),
11435 : parser_errposition(@14)));
11436 6 : $$ = (Node *) n;
11437 : }
11438 : ;
11439 :
11440 : opt_check_option:
11441 96 : WITH CHECK OPTION { $$ = CASCADED_CHECK_OPTION; }
11442 6 : | WITH CASCADED CHECK OPTION { $$ = CASCADED_CHECK_OPTION; }
11443 24 : | WITH LOCAL CHECK OPTION { $$ = LOCAL_CHECK_OPTION; }
11444 16838 : | /* EMPTY */ { $$ = NO_CHECK_OPTION; }
11445 : ;
11446 :
11447 : /*****************************************************************************
11448 : *
11449 : * QUERY:
11450 : * LOAD "filename"
11451 : *
11452 : *****************************************************************************/
11453 :
11454 : LoadStmt: LOAD file_name
11455 : {
11456 64 : LoadStmt *n = makeNode(LoadStmt);
11457 :
11458 64 : n->filename = $2;
11459 64 : $$ = (Node *) n;
11460 : }
11461 : ;
11462 :
11463 :
11464 : /*****************************************************************************
11465 : *
11466 : * CREATE DATABASE
11467 : *
11468 : *****************************************************************************/
11469 :
11470 : CreatedbStmt:
11471 : CREATE DATABASE name opt_with createdb_opt_list
11472 : {
11473 802 : CreatedbStmt *n = makeNode(CreatedbStmt);
11474 :
11475 802 : n->dbname = $3;
11476 802 : n->options = $5;
11477 802 : $$ = (Node *) n;
11478 : }
11479 : ;
11480 :
11481 : createdb_opt_list:
11482 654 : createdb_opt_items { $$ = $1; }
11483 208 : | /* EMPTY */ { $$ = NIL; }
11484 : ;
11485 :
11486 : createdb_opt_items:
11487 654 : createdb_opt_item { $$ = list_make1($1); }
11488 994 : | createdb_opt_items createdb_opt_item { $$ = lappend($1, $2); }
11489 : ;
11490 :
11491 : createdb_opt_item:
11492 : createdb_opt_name opt_equal NumericOnly
11493 : {
11494 266 : $$ = makeDefElem($1, $3, @1);
11495 : }
11496 : | createdb_opt_name opt_equal opt_boolean_or_string
11497 : {
11498 1382 : $$ = makeDefElem($1, (Node *) makeString($3), @1);
11499 : }
11500 : | createdb_opt_name opt_equal DEFAULT
11501 : {
11502 0 : $$ = makeDefElem($1, NULL, @1);
11503 : }
11504 : ;
11505 :
11506 : /*
11507 : * Ideally we'd use ColId here, but that causes shift/reduce conflicts against
11508 : * the ALTER DATABASE SET/RESET syntaxes. Instead call out specific keywords
11509 : * we need, and allow IDENT so that database option names don't have to be
11510 : * parser keywords unless they are already keywords for other reasons.
11511 : *
11512 : * XXX this coding technique is fragile since if someone makes a formerly
11513 : * non-keyword option name into a keyword and forgets to add it here, the
11514 : * option will silently break. Best defense is to provide a regression test
11515 : * exercising every such option, at least at the syntax level.
11516 : */
11517 : createdb_opt_name:
11518 1148 : IDENT { $$ = $1; }
11519 2 : | CONNECTION LIMIT { $$ = pstrdup("connection_limit"); }
11520 104 : | ENCODING { $$ = pstrdup($1); }
11521 0 : | LOCATION { $$ = pstrdup($1); }
11522 2 : | OWNER { $$ = pstrdup($1); }
11523 34 : | TABLESPACE { $$ = pstrdup($1); }
11524 358 : | TEMPLATE { $$ = pstrdup($1); }
11525 : ;
11526 :
11527 : /*
11528 : * Though the equals sign doesn't match other WITH options, pg_dump uses
11529 : * equals for backward compatibility, and it doesn't seem worth removing it.
11530 : */
11531 : opt_equal: '='
11532 : | /*EMPTY*/
11533 : ;
11534 :
11535 :
11536 : /*****************************************************************************
11537 : *
11538 : * ALTER DATABASE
11539 : *
11540 : *****************************************************************************/
11541 :
11542 : AlterDatabaseStmt:
11543 : ALTER DATABASE name WITH createdb_opt_list
11544 : {
11545 0 : AlterDatabaseStmt *n = makeNode(AlterDatabaseStmt);
11546 :
11547 0 : n->dbname = $3;
11548 0 : n->options = $5;
11549 0 : $$ = (Node *) n;
11550 : }
11551 : | ALTER DATABASE name createdb_opt_list
11552 : {
11553 60 : AlterDatabaseStmt *n = makeNode(AlterDatabaseStmt);
11554 :
11555 60 : n->dbname = $3;
11556 60 : n->options = $4;
11557 60 : $$ = (Node *) n;
11558 : }
11559 : | ALTER DATABASE name SET TABLESPACE name
11560 : {
11561 22 : AlterDatabaseStmt *n = makeNode(AlterDatabaseStmt);
11562 :
11563 22 : n->dbname = $3;
11564 22 : n->options = list_make1(makeDefElem("tablespace",
11565 : (Node *) makeString($6), @6));
11566 22 : $$ = (Node *) n;
11567 : }
11568 : | ALTER DATABASE name REFRESH COLLATION VERSION_P
11569 : {
11570 6 : AlterDatabaseRefreshCollStmt *n = makeNode(AlterDatabaseRefreshCollStmt);
11571 :
11572 6 : n->dbname = $3;
11573 6 : $$ = (Node *) n;
11574 : }
11575 : ;
11576 :
11577 : AlterDatabaseSetStmt:
11578 : ALTER DATABASE name SetResetClause
11579 : {
11580 1230 : AlterDatabaseSetStmt *n = makeNode(AlterDatabaseSetStmt);
11581 :
11582 1230 : n->dbname = $3;
11583 1230 : n->setstmt = $4;
11584 1230 : $$ = (Node *) n;
11585 : }
11586 : ;
11587 :
11588 :
11589 : /*****************************************************************************
11590 : *
11591 : * DROP DATABASE [ IF EXISTS ] dbname [ [ WITH ] ( options ) ]
11592 : *
11593 : * This is implicitly CASCADE, no need for drop behavior
11594 : *****************************************************************************/
11595 :
11596 : DropdbStmt: DROP DATABASE name
11597 : {
11598 94 : DropdbStmt *n = makeNode(DropdbStmt);
11599 :
11600 94 : n->dbname = $3;
11601 94 : n->missing_ok = false;
11602 94 : n->options = NULL;
11603 94 : $$ = (Node *) n;
11604 : }
11605 : | DROP DATABASE IF_P EXISTS name
11606 : {
11607 4 : DropdbStmt *n = makeNode(DropdbStmt);
11608 :
11609 4 : n->dbname = $5;
11610 4 : n->missing_ok = true;
11611 4 : n->options = NULL;
11612 4 : $$ = (Node *) n;
11613 : }
11614 : | DROP DATABASE name opt_with '(' drop_option_list ')'
11615 : {
11616 14 : DropdbStmt *n = makeNode(DropdbStmt);
11617 :
11618 14 : n->dbname = $3;
11619 14 : n->missing_ok = false;
11620 14 : n->options = $6;
11621 14 : $$ = (Node *) n;
11622 : }
11623 : | DROP DATABASE IF_P EXISTS name opt_with '(' drop_option_list ')'
11624 : {
11625 12 : DropdbStmt *n = makeNode(DropdbStmt);
11626 :
11627 12 : n->dbname = $5;
11628 12 : n->missing_ok = true;
11629 12 : n->options = $8;
11630 12 : $$ = (Node *) n;
11631 : }
11632 : ;
11633 :
11634 : drop_option_list:
11635 : drop_option
11636 : {
11637 26 : $$ = list_make1((Node *) $1);
11638 : }
11639 : | drop_option_list ',' drop_option
11640 : {
11641 0 : $$ = lappend($1, (Node *) $3);
11642 : }
11643 : ;
11644 :
11645 : /*
11646 : * Currently only the FORCE option is supported, but the syntax is designed
11647 : * to be extensible so that we can add more options in the future if required.
11648 : */
11649 : drop_option:
11650 : FORCE
11651 : {
11652 26 : $$ = makeDefElem("force", NULL, @1);
11653 : }
11654 : ;
11655 :
11656 : /*****************************************************************************
11657 : *
11658 : * ALTER COLLATION
11659 : *
11660 : *****************************************************************************/
11661 :
11662 : AlterCollationStmt: ALTER COLLATION any_name REFRESH VERSION_P
11663 : {
11664 6 : AlterCollationStmt *n = makeNode(AlterCollationStmt);
11665 :
11666 6 : n->collname = $3;
11667 6 : $$ = (Node *) n;
11668 : }
11669 : ;
11670 :
11671 :
11672 : /*****************************************************************************
11673 : *
11674 : * ALTER SYSTEM
11675 : *
11676 : * This is used to change configuration parameters persistently.
11677 : *****************************************************************************/
11678 :
11679 : AlterSystemStmt:
11680 : ALTER SYSTEM_P SET generic_set
11681 : {
11682 132 : AlterSystemStmt *n = makeNode(AlterSystemStmt);
11683 :
11684 132 : n->setstmt = $4;
11685 132 : $$ = (Node *) n;
11686 : }
11687 : | ALTER SYSTEM_P RESET generic_reset
11688 : {
11689 56 : AlterSystemStmt *n = makeNode(AlterSystemStmt);
11690 :
11691 56 : n->setstmt = $4;
11692 56 : $$ = (Node *) n;
11693 : }
11694 : ;
11695 :
11696 :
11697 : /*****************************************************************************
11698 : *
11699 : * Manipulate a domain
11700 : *
11701 : *****************************************************************************/
11702 :
11703 : CreateDomainStmt:
11704 : CREATE DOMAIN_P any_name opt_as Typename ColQualList
11705 : {
11706 1452 : CreateDomainStmt *n = makeNode(CreateDomainStmt);
11707 :
11708 1452 : n->domainname = $3;
11709 1452 : n->typeName = $5;
11710 1452 : SplitColQualList($6, &n->constraints, &n->collClause,
11711 : yyscanner);
11712 1452 : $$ = (Node *) n;
11713 : }
11714 : ;
11715 :
11716 : AlterDomainStmt:
11717 : /* ALTER DOMAIN <domain> {SET DEFAULT <expr>|DROP DEFAULT} */
11718 : ALTER DOMAIN_P any_name alter_column_default
11719 : {
11720 14 : AlterDomainStmt *n = makeNode(AlterDomainStmt);
11721 :
11722 14 : n->subtype = AD_AlterDefault;
11723 14 : n->typeName = $3;
11724 14 : n->def = $4;
11725 14 : $$ = (Node *) n;
11726 : }
11727 : /* ALTER DOMAIN <domain> DROP NOT NULL */
11728 : | ALTER DOMAIN_P any_name DROP NOT NULL_P
11729 : {
11730 12 : AlterDomainStmt *n = makeNode(AlterDomainStmt);
11731 :
11732 12 : n->subtype = AD_DropNotNull;
11733 12 : n->typeName = $3;
11734 12 : $$ = (Node *) n;
11735 : }
11736 : /* ALTER DOMAIN <domain> SET NOT NULL */
11737 : | ALTER DOMAIN_P any_name SET NOT NULL_P
11738 : {
11739 24 : AlterDomainStmt *n = makeNode(AlterDomainStmt);
11740 :
11741 24 : n->subtype = AD_SetNotNull;
11742 24 : n->typeName = $3;
11743 24 : $$ = (Node *) n;
11744 : }
11745 : /* ALTER DOMAIN <domain> ADD CONSTRAINT ... */
11746 : | ALTER DOMAIN_P any_name ADD_P DomainConstraint
11747 : {
11748 182 : AlterDomainStmt *n = makeNode(AlterDomainStmt);
11749 :
11750 182 : n->subtype = AD_AddConstraint;
11751 182 : n->typeName = $3;
11752 182 : n->def = $5;
11753 182 : $$ = (Node *) n;
11754 : }
11755 : /* ALTER DOMAIN <domain> DROP CONSTRAINT <name> [RESTRICT|CASCADE] */
11756 : | ALTER DOMAIN_P any_name DROP CONSTRAINT name opt_drop_behavior
11757 : {
11758 54 : AlterDomainStmt *n = makeNode(AlterDomainStmt);
11759 :
11760 54 : n->subtype = AD_DropConstraint;
11761 54 : n->typeName = $3;
11762 54 : n->name = $6;
11763 54 : n->behavior = $7;
11764 54 : n->missing_ok = false;
11765 54 : $$ = (Node *) n;
11766 : }
11767 : /* ALTER DOMAIN <domain> DROP CONSTRAINT IF EXISTS <name> [RESTRICT|CASCADE] */
11768 : | ALTER DOMAIN_P any_name DROP CONSTRAINT IF_P EXISTS name opt_drop_behavior
11769 : {
11770 6 : AlterDomainStmt *n = makeNode(AlterDomainStmt);
11771 :
11772 6 : n->subtype = AD_DropConstraint;
11773 6 : n->typeName = $3;
11774 6 : n->name = $8;
11775 6 : n->behavior = $9;
11776 6 : n->missing_ok = true;
11777 6 : $$ = (Node *) n;
11778 : }
11779 : /* ALTER DOMAIN <domain> VALIDATE CONSTRAINT <name> */
11780 : | ALTER DOMAIN_P any_name VALIDATE CONSTRAINT name
11781 : {
11782 12 : AlterDomainStmt *n = makeNode(AlterDomainStmt);
11783 :
11784 12 : n->subtype = AD_ValidateConstraint;
11785 12 : n->typeName = $3;
11786 12 : n->name = $6;
11787 12 : $$ = (Node *) n;
11788 : }
11789 : ;
11790 :
11791 : opt_as: AS
11792 : | /* EMPTY */
11793 : ;
11794 :
11795 :
11796 : /*****************************************************************************
11797 : *
11798 : * Manipulate a text search dictionary or configuration
11799 : *
11800 : *****************************************************************************/
11801 :
11802 : AlterTSDictionaryStmt:
11803 : ALTER TEXT_P SEARCH DICTIONARY any_name definition
11804 : {
11805 40 : AlterTSDictionaryStmt *n = makeNode(AlterTSDictionaryStmt);
11806 :
11807 40 : n->dictname = $5;
11808 40 : n->options = $6;
11809 40 : $$ = (Node *) n;
11810 : }
11811 : ;
11812 :
11813 : AlterTSConfigurationStmt:
11814 : ALTER TEXT_P SEARCH CONFIGURATION any_name ADD_P MAPPING FOR name_list any_with any_name_list
11815 : {
11816 8518 : AlterTSConfigurationStmt *n = makeNode(AlterTSConfigurationStmt);
11817 :
11818 8518 : n->kind = ALTER_TSCONFIG_ADD_MAPPING;
11819 8518 : n->cfgname = $5;
11820 8518 : n->tokentype = $9;
11821 8518 : n->dicts = $11;
11822 8518 : n->override = false;
11823 8518 : n->replace = false;
11824 8518 : $$ = (Node *) n;
11825 : }
11826 : | ALTER TEXT_P SEARCH CONFIGURATION any_name ALTER MAPPING FOR name_list any_with any_name_list
11827 : {
11828 26 : AlterTSConfigurationStmt *n = makeNode(AlterTSConfigurationStmt);
11829 :
11830 26 : n->kind = ALTER_TSCONFIG_ALTER_MAPPING_FOR_TOKEN;
11831 26 : n->cfgname = $5;
11832 26 : n->tokentype = $9;
11833 26 : n->dicts = $11;
11834 26 : n->override = true;
11835 26 : n->replace = false;
11836 26 : $$ = (Node *) n;
11837 : }
11838 : | ALTER TEXT_P SEARCH CONFIGURATION any_name ALTER MAPPING REPLACE any_name any_with any_name
11839 : {
11840 18 : AlterTSConfigurationStmt *n = makeNode(AlterTSConfigurationStmt);
11841 :
11842 18 : n->kind = ALTER_TSCONFIG_REPLACE_DICT;
11843 18 : n->cfgname = $5;
11844 18 : n->tokentype = NIL;
11845 18 : n->dicts = list_make2($9,$11);
11846 18 : n->override = false;
11847 18 : n->replace = true;
11848 18 : $$ = (Node *) n;
11849 : }
11850 : | ALTER TEXT_P SEARCH CONFIGURATION any_name ALTER MAPPING FOR name_list REPLACE any_name any_with any_name
11851 : {
11852 0 : AlterTSConfigurationStmt *n = makeNode(AlterTSConfigurationStmt);
11853 :
11854 0 : n->kind = ALTER_TSCONFIG_REPLACE_DICT_FOR_TOKEN;
11855 0 : n->cfgname = $5;
11856 0 : n->tokentype = $9;
11857 0 : n->dicts = list_make2($11,$13);
11858 0 : n->override = false;
11859 0 : n->replace = true;
11860 0 : $$ = (Node *) n;
11861 : }
11862 : | ALTER TEXT_P SEARCH CONFIGURATION any_name DROP MAPPING FOR name_list
11863 : {
11864 18 : AlterTSConfigurationStmt *n = makeNode(AlterTSConfigurationStmt);
11865 :
11866 18 : n->kind = ALTER_TSCONFIG_DROP_MAPPING;
11867 18 : n->cfgname = $5;
11868 18 : n->tokentype = $9;
11869 18 : n->missing_ok = false;
11870 18 : $$ = (Node *) n;
11871 : }
11872 : | ALTER TEXT_P SEARCH CONFIGURATION any_name DROP MAPPING IF_P EXISTS FOR name_list
11873 : {
11874 12 : AlterTSConfigurationStmt *n = makeNode(AlterTSConfigurationStmt);
11875 :
11876 12 : n->kind = ALTER_TSCONFIG_DROP_MAPPING;
11877 12 : n->cfgname = $5;
11878 12 : n->tokentype = $11;
11879 12 : n->missing_ok = true;
11880 12 : $$ = (Node *) n;
11881 : }
11882 : ;
11883 :
11884 : /* Use this if TIME or ORDINALITY after WITH should be taken as an identifier */
11885 : any_with: WITH
11886 : | WITH_LA
11887 : ;
11888 :
11889 :
11890 : /*****************************************************************************
11891 : *
11892 : * Manipulate a conversion
11893 : *
11894 : * CREATE [DEFAULT] CONVERSION <conversion_name>
11895 : * FOR <encoding_name> TO <encoding_name> FROM <func_name>
11896 : *
11897 : *****************************************************************************/
11898 :
11899 : CreateConversionStmt:
11900 : CREATE opt_default CONVERSION_P any_name FOR Sconst
11901 : TO Sconst FROM any_name
11902 : {
11903 64 : CreateConversionStmt *n = makeNode(CreateConversionStmt);
11904 :
11905 64 : n->conversion_name = $4;
11906 64 : n->for_encoding_name = $6;
11907 64 : n->to_encoding_name = $8;
11908 64 : n->func_name = $10;
11909 64 : n->def = $2;
11910 64 : $$ = (Node *) n;
11911 : }
11912 : ;
11913 :
11914 : /*****************************************************************************
11915 : *
11916 : * QUERY:
11917 : * CLUSTER (options) [ <qualified_name> [ USING <index_name> ] ]
11918 : * CLUSTER [VERBOSE] [ <qualified_name> [ USING <index_name> ] ]
11919 : * CLUSTER [VERBOSE] <index_name> ON <qualified_name> (for pre-8.3)
11920 : *
11921 : *****************************************************************************/
11922 :
11923 : ClusterStmt:
11924 : CLUSTER '(' utility_option_list ')' qualified_name cluster_index_specification
11925 : {
11926 0 : ClusterStmt *n = makeNode(ClusterStmt);
11927 :
11928 0 : n->relation = $5;
11929 0 : n->indexname = $6;
11930 0 : n->params = $3;
11931 0 : $$ = (Node *) n;
11932 : }
11933 : | CLUSTER opt_utility_option_list
11934 : {
11935 16 : ClusterStmt *n = makeNode(ClusterStmt);
11936 :
11937 16 : n->relation = NULL;
11938 16 : n->indexname = NULL;
11939 16 : n->params = $2;
11940 16 : $$ = (Node *) n;
11941 : }
11942 : /* unparenthesized VERBOSE kept for pre-14 compatibility */
11943 : | CLUSTER opt_verbose qualified_name cluster_index_specification
11944 : {
11945 190 : ClusterStmt *n = makeNode(ClusterStmt);
11946 :
11947 190 : n->relation = $3;
11948 190 : n->indexname = $4;
11949 190 : if ($2)
11950 0 : n->params = list_make1(makeDefElem("verbose", NULL, @2));
11951 190 : $$ = (Node *) n;
11952 : }
11953 : /* unparenthesized VERBOSE kept for pre-17 compatibility */
11954 : | CLUSTER VERBOSE
11955 : {
11956 2 : ClusterStmt *n = makeNode(ClusterStmt);
11957 :
11958 2 : n->relation = NULL;
11959 2 : n->indexname = NULL;
11960 2 : n->params = list_make1(makeDefElem("verbose", NULL, @2));
11961 2 : $$ = (Node *) n;
11962 : }
11963 : /* kept for pre-8.3 compatibility */
11964 : | CLUSTER opt_verbose name ON qualified_name
11965 : {
11966 20 : ClusterStmt *n = makeNode(ClusterStmt);
11967 :
11968 20 : n->relation = $5;
11969 20 : n->indexname = $3;
11970 20 : if ($2)
11971 0 : n->params = list_make1(makeDefElem("verbose", NULL, @2));
11972 20 : $$ = (Node *) n;
11973 : }
11974 : ;
11975 :
11976 : cluster_index_specification:
11977 156 : USING name { $$ = $2; }
11978 34 : | /*EMPTY*/ { $$ = NULL; }
11979 : ;
11980 :
11981 :
11982 : /*****************************************************************************
11983 : *
11984 : * QUERY:
11985 : * VACUUM
11986 : * ANALYZE
11987 : *
11988 : *****************************************************************************/
11989 :
11990 : VacuumStmt: VACUUM opt_full opt_freeze opt_verbose opt_analyze opt_vacuum_relation_list
11991 : {
11992 1232 : VacuumStmt *n = makeNode(VacuumStmt);
11993 :
11994 1232 : n->options = NIL;
11995 1232 : if ($2)
11996 152 : n->options = lappend(n->options,
11997 152 : makeDefElem("full", NULL, @2));
11998 1232 : if ($3)
11999 162 : n->options = lappend(n->options,
12000 162 : makeDefElem("freeze", NULL, @3));
12001 1232 : if ($4)
12002 16 : n->options = lappend(n->options,
12003 16 : makeDefElem("verbose", NULL, @4));
12004 1232 : if ($5)
12005 292 : n->options = lappend(n->options,
12006 292 : makeDefElem("analyze", NULL, @5));
12007 1232 : n->rels = $6;
12008 1232 : n->is_vacuumcmd = true;
12009 1232 : $$ = (Node *) n;
12010 : }
12011 : | VACUUM '(' utility_option_list ')' opt_vacuum_relation_list
12012 : {
12013 7618 : VacuumStmt *n = makeNode(VacuumStmt);
12014 :
12015 7618 : n->options = $3;
12016 7618 : n->rels = $5;
12017 7618 : n->is_vacuumcmd = true;
12018 7618 : $$ = (Node *) n;
12019 : }
12020 : ;
12021 :
12022 : AnalyzeStmt: analyze_keyword opt_utility_option_list opt_vacuum_relation_list
12023 : {
12024 4876 : VacuumStmt *n = makeNode(VacuumStmt);
12025 :
12026 4876 : n->options = $2;
12027 4876 : n->rels = $3;
12028 4876 : n->is_vacuumcmd = false;
12029 4876 : $$ = (Node *) n;
12030 : }
12031 : | analyze_keyword VERBOSE opt_vacuum_relation_list
12032 : {
12033 0 : VacuumStmt *n = makeNode(VacuumStmt);
12034 :
12035 0 : n->options = list_make1(makeDefElem("verbose", NULL, @2));
12036 0 : n->rels = $3;
12037 0 : n->is_vacuumcmd = false;
12038 0 : $$ = (Node *) n;
12039 : }
12040 : ;
12041 :
12042 : analyze_keyword:
12043 : ANALYZE
12044 : | ANALYSE /* British */
12045 : ;
12046 :
12047 : opt_analyze:
12048 292 : analyze_keyword { $$ = true; }
12049 940 : | /*EMPTY*/ { $$ = false; }
12050 : ;
12051 :
12052 : opt_verbose:
12053 16 : VERBOSE { $$ = true; }
12054 3742 : | /*EMPTY*/ { $$ = false; }
12055 : ;
12056 :
12057 152 : opt_full: FULL { $$ = true; }
12058 1080 : | /*EMPTY*/ { $$ = false; }
12059 : ;
12060 :
12061 162 : opt_freeze: FREEZE { $$ = true; }
12062 1070 : | /*EMPTY*/ { $$ = false; }
12063 : ;
12064 :
12065 : opt_name_list:
12066 2866 : '(' name_list ')' { $$ = $2; }
12067 16030 : | /*EMPTY*/ { $$ = NIL; }
12068 : ;
12069 :
12070 : vacuum_relation:
12071 : relation_expr opt_name_list
12072 : {
12073 13536 : $$ = (Node *) makeVacuumRelation($1, InvalidOid, $2);
12074 : }
12075 : ;
12076 :
12077 : vacuum_relation_list:
12078 : vacuum_relation
12079 13372 : { $$ = list_make1($1); }
12080 : | vacuum_relation_list ',' vacuum_relation
12081 164 : { $$ = lappend($1, $3); }
12082 : ;
12083 :
12084 : opt_vacuum_relation_list:
12085 13372 : vacuum_relation_list { $$ = $1; }
12086 354 : | /*EMPTY*/ { $$ = NIL; }
12087 : ;
12088 :
12089 :
12090 : /*****************************************************************************
12091 : *
12092 : * QUERY:
12093 : * EXPLAIN [ANALYZE] [VERBOSE] query
12094 : * EXPLAIN ( options ) query
12095 : *
12096 : *****************************************************************************/
12097 :
12098 : ExplainStmt:
12099 : EXPLAIN ExplainableStmt
12100 : {
12101 7718 : ExplainStmt *n = makeNode(ExplainStmt);
12102 :
12103 7718 : n->query = $2;
12104 7718 : n->options = NIL;
12105 7718 : $$ = (Node *) n;
12106 : }
12107 : | EXPLAIN analyze_keyword opt_verbose ExplainableStmt
12108 : {
12109 2316 : ExplainStmt *n = makeNode(ExplainStmt);
12110 :
12111 2316 : n->query = $4;
12112 2316 : n->options = list_make1(makeDefElem("analyze", NULL, @2));
12113 2316 : if ($3)
12114 0 : n->options = lappend(n->options,
12115 0 : makeDefElem("verbose", NULL, @3));
12116 2316 : $$ = (Node *) n;
12117 : }
12118 : | EXPLAIN VERBOSE ExplainableStmt
12119 : {
12120 12 : ExplainStmt *n = makeNode(ExplainStmt);
12121 :
12122 12 : n->query = $3;
12123 12 : n->options = list_make1(makeDefElem("verbose", NULL, @2));
12124 12 : $$ = (Node *) n;
12125 : }
12126 : | EXPLAIN '(' utility_option_list ')' ExplainableStmt
12127 : {
12128 14156 : ExplainStmt *n = makeNode(ExplainStmt);
12129 :
12130 14156 : n->query = $5;
12131 14156 : n->options = $3;
12132 14156 : $$ = (Node *) n;
12133 : }
12134 : ;
12135 :
12136 : ExplainableStmt:
12137 : SelectStmt
12138 : | InsertStmt
12139 : | UpdateStmt
12140 : | DeleteStmt
12141 : | MergeStmt
12142 : | DeclareCursorStmt
12143 : | CreateAsStmt
12144 : | CreateMatViewStmt
12145 : | RefreshMatViewStmt
12146 : | ExecuteStmt /* by default all are $$=$1 */
12147 : ;
12148 :
12149 : /*****************************************************************************
12150 : *
12151 : * QUERY:
12152 : * PREPARE <plan_name> [(args, ...)] AS <query>
12153 : *
12154 : *****************************************************************************/
12155 :
12156 : PrepareStmt: PREPARE name prep_type_clause AS PreparableStmt
12157 : {
12158 2042 : PrepareStmt *n = makeNode(PrepareStmt);
12159 :
12160 2042 : n->name = $2;
12161 2042 : n->argtypes = $3;
12162 2042 : n->query = $5;
12163 2042 : $$ = (Node *) n;
12164 : }
12165 : ;
12166 :
12167 1728 : prep_type_clause: '(' type_list ')' { $$ = $2; }
12168 332 : | /* EMPTY */ { $$ = NIL; }
12169 : ;
12170 :
12171 : PreparableStmt:
12172 : SelectStmt
12173 : | InsertStmt
12174 : | UpdateStmt
12175 : | DeleteStmt
12176 : | MergeStmt /* by default all are $$=$1 */
12177 : ;
12178 :
12179 : /*****************************************************************************
12180 : *
12181 : * EXECUTE <plan_name> [(params, ...)]
12182 : * CREATE TABLE <name> AS EXECUTE <plan_name> [(params, ...)]
12183 : *
12184 : *****************************************************************************/
12185 :
12186 : ExecuteStmt: EXECUTE name execute_param_clause
12187 : {
12188 16524 : ExecuteStmt *n = makeNode(ExecuteStmt);
12189 :
12190 16524 : n->name = $2;
12191 16524 : n->params = $3;
12192 16524 : $$ = (Node *) n;
12193 : }
12194 : | CREATE OptTemp TABLE create_as_target AS
12195 : EXECUTE name execute_param_clause opt_with_data
12196 : {
12197 76 : CreateTableAsStmt *ctas = makeNode(CreateTableAsStmt);
12198 76 : ExecuteStmt *n = makeNode(ExecuteStmt);
12199 :
12200 76 : n->name = $7;
12201 76 : n->params = $8;
12202 76 : ctas->query = (Node *) n;
12203 76 : ctas->into = $4;
12204 76 : ctas->objtype = OBJECT_TABLE;
12205 76 : ctas->is_select_into = false;
12206 76 : ctas->if_not_exists = false;
12207 : /* cram additional flags into the IntoClause */
12208 76 : $4->rel->relpersistence = $2;
12209 76 : $4->skipData = !($9);
12210 76 : $$ = (Node *) ctas;
12211 : }
12212 : | CREATE OptTemp TABLE IF_P NOT EXISTS create_as_target AS
12213 : EXECUTE name execute_param_clause opt_with_data
12214 : {
12215 12 : CreateTableAsStmt *ctas = makeNode(CreateTableAsStmt);
12216 12 : ExecuteStmt *n = makeNode(ExecuteStmt);
12217 :
12218 12 : n->name = $10;
12219 12 : n->params = $11;
12220 12 : ctas->query = (Node *) n;
12221 12 : ctas->into = $7;
12222 12 : ctas->objtype = OBJECT_TABLE;
12223 12 : ctas->is_select_into = false;
12224 12 : ctas->if_not_exists = true;
12225 : /* cram additional flags into the IntoClause */
12226 12 : $7->rel->relpersistence = $2;
12227 12 : $7->skipData = !($12);
12228 12 : $$ = (Node *) ctas;
12229 : }
12230 : ;
12231 :
12232 15470 : execute_param_clause: '(' expr_list ')' { $$ = $2; }
12233 1142 : | /* EMPTY */ { $$ = NIL; }
12234 : ;
12235 :
12236 : /*****************************************************************************
12237 : *
12238 : * QUERY:
12239 : * DEALLOCATE [PREPARE] <plan_name>
12240 : *
12241 : *****************************************************************************/
12242 :
12243 : DeallocateStmt: DEALLOCATE name
12244 : {
12245 3996 : DeallocateStmt *n = makeNode(DeallocateStmt);
12246 :
12247 3996 : n->name = $2;
12248 3996 : n->isall = false;
12249 3996 : n->location = @2;
12250 3996 : $$ = (Node *) n;
12251 : }
12252 : | DEALLOCATE PREPARE name
12253 : {
12254 20 : DeallocateStmt *n = makeNode(DeallocateStmt);
12255 :
12256 20 : n->name = $3;
12257 20 : n->isall = false;
12258 20 : n->location = @3;
12259 20 : $$ = (Node *) n;
12260 : }
12261 : | DEALLOCATE ALL
12262 : {
12263 70 : DeallocateStmt *n = makeNode(DeallocateStmt);
12264 :
12265 70 : n->name = NULL;
12266 70 : n->isall = true;
12267 70 : n->location = -1;
12268 70 : $$ = (Node *) n;
12269 : }
12270 : | DEALLOCATE PREPARE ALL
12271 : {
12272 2 : DeallocateStmt *n = makeNode(DeallocateStmt);
12273 :
12274 2 : n->name = NULL;
12275 2 : n->isall = true;
12276 2 : n->location = -1;
12277 2 : $$ = (Node *) n;
12278 : }
12279 : ;
12280 :
12281 : /*****************************************************************************
12282 : *
12283 : * QUERY:
12284 : * INSERT STATEMENTS
12285 : *
12286 : *****************************************************************************/
12287 :
12288 : InsertStmt:
12289 : opt_with_clause INSERT INTO insert_target insert_rest
12290 : opt_on_conflict returning_clause
12291 : {
12292 68646 : $5->relation = $4;
12293 68646 : $5->onConflictClause = $6;
12294 68646 : $5->returningClause = $7;
12295 68646 : $5->withClause = $1;
12296 68646 : $$ = (Node *) $5;
12297 : }
12298 : ;
12299 :
12300 : /*
12301 : * Can't easily make AS optional here, because VALUES in insert_rest would
12302 : * have a shift/reduce conflict with VALUES as an optional alias. We could
12303 : * easily allow unreserved_keywords as optional aliases, but that'd be an odd
12304 : * divergence from other places. So just require AS for now.
12305 : */
12306 : insert_target:
12307 : qualified_name
12308 : {
12309 68520 : $$ = $1;
12310 : }
12311 : | qualified_name AS ColId
12312 : {
12313 132 : $1->alias = makeAlias($3, NIL);
12314 132 : $$ = $1;
12315 : }
12316 : ;
12317 :
12318 : insert_rest:
12319 : SelectStmt
12320 : {
12321 43460 : $$ = makeNode(InsertStmt);
12322 43460 : $$->cols = NIL;
12323 43460 : $$->selectStmt = $1;
12324 : }
12325 : | OVERRIDING override_kind VALUE_P SelectStmt
12326 : {
12327 96 : $$ = makeNode(InsertStmt);
12328 96 : $$->cols = NIL;
12329 96 : $$->override = $2;
12330 96 : $$->selectStmt = $4;
12331 : }
12332 : | '(' insert_column_list ')' SelectStmt
12333 : {
12334 14288 : $$ = makeNode(InsertStmt);
12335 14288 : $$->cols = $2;
12336 14288 : $$->selectStmt = $4;
12337 : }
12338 : | '(' insert_column_list ')' OVERRIDING override_kind VALUE_P SelectStmt
12339 : {
12340 0 : $$ = makeNode(InsertStmt);
12341 0 : $$->cols = $2;
12342 0 : $$->override = $5;
12343 0 : $$->selectStmt = $7;
12344 : }
12345 : | DEFAULT VALUES
12346 : {
12347 10808 : $$ = makeNode(InsertStmt);
12348 10808 : $$->cols = NIL;
12349 10808 : $$->selectStmt = NULL;
12350 : }
12351 : ;
12352 :
12353 : override_kind:
12354 66 : USER { $$ = OVERRIDING_USER_VALUE; }
12355 60 : | SYSTEM_P { $$ = OVERRIDING_SYSTEM_VALUE; }
12356 : ;
12357 :
12358 : insert_column_list:
12359 : insert_column_item
12360 14622 : { $$ = list_make1($1); }
12361 : | insert_column_list ',' insert_column_item
12362 16220 : { $$ = lappend($1, $3); }
12363 : ;
12364 :
12365 : insert_column_item:
12366 : ColId opt_indirection
12367 : {
12368 30842 : $$ = makeNode(ResTarget);
12369 30842 : $$->name = $1;
12370 30842 : $$->indirection = check_indirection($2, yyscanner);
12371 30842 : $$->val = NULL;
12372 30842 : $$->location = @1;
12373 : }
12374 : ;
12375 :
12376 : opt_on_conflict:
12377 : ON CONFLICT opt_conf_expr DO UPDATE SET set_clause_list where_clause
12378 : {
12379 1318 : $$ = makeNode(OnConflictClause);
12380 1318 : $$->action = ONCONFLICT_UPDATE;
12381 1318 : $$->infer = $3;
12382 1318 : $$->targetList = $7;
12383 1318 : $$->whereClause = $8;
12384 1318 : $$->location = @1;
12385 : }
12386 : |
12387 : ON CONFLICT opt_conf_expr DO NOTHING
12388 : {
12389 562 : $$ = makeNode(OnConflictClause);
12390 562 : $$->action = ONCONFLICT_NOTHING;
12391 562 : $$->infer = $3;
12392 562 : $$->targetList = NIL;
12393 562 : $$->whereClause = NULL;
12394 562 : $$->location = @1;
12395 : }
12396 : | /*EMPTY*/
12397 : {
12398 66772 : $$ = NULL;
12399 : }
12400 : ;
12401 :
12402 : opt_conf_expr:
12403 : '(' index_params ')' where_clause
12404 : {
12405 1442 : $$ = makeNode(InferClause);
12406 1442 : $$->indexElems = $2;
12407 1442 : $$->whereClause = $4;
12408 1442 : $$->conname = NULL;
12409 1442 : $$->location = @1;
12410 : }
12411 : |
12412 : ON CONSTRAINT name
12413 : {
12414 192 : $$ = makeNode(InferClause);
12415 192 : $$->indexElems = NIL;
12416 192 : $$->whereClause = NULL;
12417 192 : $$->conname = $3;
12418 192 : $$->location = @1;
12419 : }
12420 : | /*EMPTY*/
12421 : {
12422 246 : $$ = NULL;
12423 : }
12424 : ;
12425 :
12426 : returning_clause:
12427 : RETURNING returning_with_clause target_list
12428 : {
12429 3184 : ReturningClause *n = makeNode(ReturningClause);
12430 :
12431 3184 : n->options = $2;
12432 3184 : n->exprs = $3;
12433 3184 : $$ = n;
12434 : }
12435 : | /* EMPTY */
12436 : {
12437 86568 : $$ = NULL;
12438 : }
12439 : ;
12440 :
12441 : returning_with_clause:
12442 72 : WITH '(' returning_options ')' { $$ = $3; }
12443 3112 : | /* EMPTY */ { $$ = NIL; }
12444 : ;
12445 :
12446 : returning_options:
12447 72 : returning_option { $$ = list_make1($1); }
12448 54 : | returning_options ',' returning_option { $$ = lappend($1, $3); }
12449 : ;
12450 :
12451 : returning_option:
12452 : returning_option_kind AS ColId
12453 : {
12454 126 : ReturningOption *n = makeNode(ReturningOption);
12455 :
12456 126 : n->option = $1;
12457 126 : n->value = $3;
12458 126 : n->location = @1;
12459 126 : $$ = (Node *) n;
12460 : }
12461 : ;
12462 :
12463 : returning_option_kind:
12464 54 : OLD { $$ = RETURNING_OPTION_OLD; }
12465 72 : | NEW { $$ = RETURNING_OPTION_NEW; }
12466 : ;
12467 :
12468 :
12469 : /*****************************************************************************
12470 : *
12471 : * QUERY:
12472 : * DELETE STATEMENTS
12473 : *
12474 : *****************************************************************************/
12475 :
12476 : DeleteStmt: opt_with_clause DELETE_P FROM relation_expr_opt_alias
12477 : using_clause where_or_current_clause returning_clause
12478 : {
12479 4678 : DeleteStmt *n = makeNode(DeleteStmt);
12480 :
12481 4678 : n->relation = $4;
12482 4678 : n->usingClause = $5;
12483 4678 : n->whereClause = $6;
12484 4678 : n->returningClause = $7;
12485 4678 : n->withClause = $1;
12486 4678 : $$ = (Node *) n;
12487 : }
12488 : ;
12489 :
12490 : using_clause:
12491 108 : USING from_list { $$ = $2; }
12492 4570 : | /*EMPTY*/ { $$ = NIL; }
12493 : ;
12494 :
12495 :
12496 : /*****************************************************************************
12497 : *
12498 : * QUERY:
12499 : * LOCK TABLE
12500 : *
12501 : *****************************************************************************/
12502 :
12503 : LockStmt: LOCK_P opt_table relation_expr_list opt_lock opt_nowait
12504 : {
12505 1192 : LockStmt *n = makeNode(LockStmt);
12506 :
12507 1192 : n->relations = $3;
12508 1192 : n->mode = $4;
12509 1192 : n->nowait = $5;
12510 1192 : $$ = (Node *) n;
12511 : }
12512 : ;
12513 :
12514 1084 : opt_lock: IN_P lock_type MODE { $$ = $2; }
12515 108 : | /*EMPTY*/ { $$ = AccessExclusiveLock; }
12516 : ;
12517 :
12518 594 : lock_type: ACCESS SHARE { $$ = AccessShareLock; }
12519 14 : | ROW SHARE { $$ = RowShareLock; }
12520 88 : | ROW EXCLUSIVE { $$ = RowExclusiveLock; }
12521 66 : | SHARE UPDATE EXCLUSIVE { $$ = ShareUpdateExclusiveLock; }
12522 80 : | SHARE { $$ = ShareLock; }
12523 14 : | SHARE ROW EXCLUSIVE { $$ = ShareRowExclusiveLock; }
12524 102 : | EXCLUSIVE { $$ = ExclusiveLock; }
12525 126 : | ACCESS EXCLUSIVE { $$ = AccessExclusiveLock; }
12526 : ;
12527 :
12528 334 : opt_nowait: NOWAIT { $$ = true; }
12529 888 : | /*EMPTY*/ { $$ = false; }
12530 : ;
12531 :
12532 : opt_nowait_or_skip:
12533 50 : NOWAIT { $$ = LockWaitError; }
12534 190 : | SKIP LOCKED { $$ = LockWaitSkip; }
12535 5118 : | /*EMPTY*/ { $$ = LockWaitBlock; }
12536 : ;
12537 :
12538 :
12539 : /*****************************************************************************
12540 : *
12541 : * QUERY:
12542 : * UpdateStmt (UPDATE)
12543 : *
12544 : *****************************************************************************/
12545 :
12546 : UpdateStmt: opt_with_clause UPDATE relation_expr_opt_alias
12547 : SET set_clause_list
12548 : from_clause
12549 : where_or_current_clause
12550 : returning_clause
12551 : {
12552 14310 : UpdateStmt *n = makeNode(UpdateStmt);
12553 :
12554 14310 : n->relation = $3;
12555 14310 : n->targetList = $5;
12556 14310 : n->fromClause = $6;
12557 14310 : n->whereClause = $7;
12558 14310 : n->returningClause = $8;
12559 14310 : n->withClause = $1;
12560 14310 : $$ = (Node *) n;
12561 : }
12562 : ;
12563 :
12564 : set_clause_list:
12565 17226 : set_clause { $$ = $1; }
12566 4320 : | set_clause_list ',' set_clause { $$ = list_concat($1,$3); }
12567 : ;
12568 :
12569 : set_clause:
12570 : set_target '=' a_expr
12571 : {
12572 21362 : $1->val = (Node *) $3;
12573 21362 : $$ = list_make1($1);
12574 : }
12575 : | '(' set_target_list ')' '=' a_expr
12576 : {
12577 184 : int ncolumns = list_length($2);
12578 184 : int i = 1;
12579 : ListCell *col_cell;
12580 :
12581 : /* Create a MultiAssignRef source for each target */
12582 568 : foreach(col_cell, $2)
12583 : {
12584 384 : ResTarget *res_col = (ResTarget *) lfirst(col_cell);
12585 384 : MultiAssignRef *r = makeNode(MultiAssignRef);
12586 :
12587 384 : r->source = (Node *) $5;
12588 384 : r->colno = i;
12589 384 : r->ncolumns = ncolumns;
12590 384 : res_col->val = (Node *) r;
12591 384 : i++;
12592 : }
12593 :
12594 184 : $$ = $2;
12595 : }
12596 : ;
12597 :
12598 : set_target:
12599 : ColId opt_indirection
12600 : {
12601 21752 : $$ = makeNode(ResTarget);
12602 21752 : $$->name = $1;
12603 21752 : $$->indirection = check_indirection($2, yyscanner);
12604 21752 : $$->val = NULL; /* upper production sets this */
12605 21752 : $$->location = @1;
12606 : }
12607 : ;
12608 :
12609 : set_target_list:
12610 190 : set_target { $$ = list_make1($1); }
12611 200 : | set_target_list ',' set_target { $$ = lappend($1,$3); }
12612 : ;
12613 :
12614 :
12615 : /*****************************************************************************
12616 : *
12617 : * QUERY:
12618 : * MERGE
12619 : *
12620 : *****************************************************************************/
12621 :
12622 : MergeStmt:
12623 : opt_with_clause MERGE INTO relation_expr_opt_alias
12624 : USING table_ref
12625 : ON a_expr
12626 : merge_when_list
12627 : returning_clause
12628 : {
12629 2118 : MergeStmt *m = makeNode(MergeStmt);
12630 :
12631 2118 : m->withClause = $1;
12632 2118 : m->relation = $4;
12633 2118 : m->sourceRelation = $6;
12634 2118 : m->joinCondition = $8;
12635 2118 : m->mergeWhenClauses = $9;
12636 2118 : m->returningClause = $10;
12637 :
12638 2118 : $$ = (Node *) m;
12639 : }
12640 : ;
12641 :
12642 : merge_when_list:
12643 2118 : merge_when_clause { $$ = list_make1($1); }
12644 1200 : | merge_when_list merge_when_clause { $$ = lappend($1,$2); }
12645 : ;
12646 :
12647 : /*
12648 : * A WHEN clause may be WHEN MATCHED, WHEN NOT MATCHED BY SOURCE, or WHEN NOT
12649 : * MATCHED [BY TARGET]. The first two cases match target tuples, and support
12650 : * UPDATE/DELETE/DO NOTHING actions. The third case does not match target
12651 : * tuples, and only supports INSERT/DO NOTHING actions.
12652 : */
12653 : merge_when_clause:
12654 : merge_when_tgt_matched opt_merge_when_condition THEN merge_update
12655 : {
12656 1598 : $4->matchKind = $1;
12657 1598 : $4->condition = $2;
12658 :
12659 1598 : $$ = (Node *) $4;
12660 : }
12661 : | merge_when_tgt_matched opt_merge_when_condition THEN merge_delete
12662 : {
12663 530 : $4->matchKind = $1;
12664 530 : $4->condition = $2;
12665 :
12666 530 : $$ = (Node *) $4;
12667 : }
12668 : | merge_when_tgt_not_matched opt_merge_when_condition THEN merge_insert
12669 : {
12670 1100 : $4->matchKind = $1;
12671 1100 : $4->condition = $2;
12672 :
12673 1100 : $$ = (Node *) $4;
12674 : }
12675 : | merge_when_tgt_matched opt_merge_when_condition THEN DO NOTHING
12676 : {
12677 70 : MergeWhenClause *m = makeNode(MergeWhenClause);
12678 :
12679 70 : m->matchKind = $1;
12680 70 : m->commandType = CMD_NOTHING;
12681 70 : m->condition = $2;
12682 :
12683 70 : $$ = (Node *) m;
12684 : }
12685 : | merge_when_tgt_not_matched opt_merge_when_condition THEN DO NOTHING
12686 : {
12687 20 : MergeWhenClause *m = makeNode(MergeWhenClause);
12688 :
12689 20 : m->matchKind = $1;
12690 20 : m->commandType = CMD_NOTHING;
12691 20 : m->condition = $2;
12692 :
12693 20 : $$ = (Node *) m;
12694 : }
12695 : ;
12696 :
12697 : merge_when_tgt_matched:
12698 2036 : WHEN MATCHED { $$ = MERGE_WHEN_MATCHED; }
12699 180 : | WHEN NOT MATCHED BY SOURCE { $$ = MERGE_WHEN_NOT_MATCHED_BY_SOURCE; }
12700 : ;
12701 :
12702 : merge_when_tgt_not_matched:
12703 1126 : WHEN NOT MATCHED { $$ = MERGE_WHEN_NOT_MATCHED_BY_TARGET; }
12704 18 : | WHEN NOT MATCHED BY TARGET { $$ = MERGE_WHEN_NOT_MATCHED_BY_TARGET; }
12705 : ;
12706 :
12707 : opt_merge_when_condition:
12708 850 : AND a_expr { $$ = $2; }
12709 2510 : | { $$ = NULL; }
12710 : ;
12711 :
12712 : merge_update:
12713 : UPDATE SET set_clause_list
12714 : {
12715 1598 : MergeWhenClause *n = makeNode(MergeWhenClause);
12716 1598 : n->commandType = CMD_UPDATE;
12717 1598 : n->override = OVERRIDING_NOT_SET;
12718 1598 : n->targetList = $3;
12719 1598 : n->values = NIL;
12720 :
12721 1598 : $$ = n;
12722 : }
12723 : ;
12724 :
12725 : merge_delete:
12726 : DELETE_P
12727 : {
12728 530 : MergeWhenClause *n = makeNode(MergeWhenClause);
12729 530 : n->commandType = CMD_DELETE;
12730 530 : n->override = OVERRIDING_NOT_SET;
12731 530 : n->targetList = NIL;
12732 530 : n->values = NIL;
12733 :
12734 530 : $$ = n;
12735 : }
12736 : ;
12737 :
12738 : merge_insert:
12739 : INSERT merge_values_clause
12740 : {
12741 730 : MergeWhenClause *n = makeNode(MergeWhenClause);
12742 730 : n->commandType = CMD_INSERT;
12743 730 : n->override = OVERRIDING_NOT_SET;
12744 730 : n->targetList = NIL;
12745 730 : n->values = $2;
12746 730 : $$ = n;
12747 : }
12748 : | INSERT OVERRIDING override_kind VALUE_P merge_values_clause
12749 : {
12750 0 : MergeWhenClause *n = makeNode(MergeWhenClause);
12751 0 : n->commandType = CMD_INSERT;
12752 0 : n->override = $3;
12753 0 : n->targetList = NIL;
12754 0 : n->values = $5;
12755 0 : $$ = n;
12756 : }
12757 : | INSERT '(' insert_column_list ')' merge_values_clause
12758 : {
12759 304 : MergeWhenClause *n = makeNode(MergeWhenClause);
12760 304 : n->commandType = CMD_INSERT;
12761 304 : n->override = OVERRIDING_NOT_SET;
12762 304 : n->targetList = $3;
12763 304 : n->values = $5;
12764 304 : $$ = n;
12765 : }
12766 : | INSERT '(' insert_column_list ')' OVERRIDING override_kind VALUE_P merge_values_clause
12767 : {
12768 30 : MergeWhenClause *n = makeNode(MergeWhenClause);
12769 30 : n->commandType = CMD_INSERT;
12770 30 : n->override = $6;
12771 30 : n->targetList = $3;
12772 30 : n->values = $8;
12773 30 : $$ = n;
12774 : }
12775 : | INSERT DEFAULT VALUES
12776 : {
12777 36 : MergeWhenClause *n = makeNode(MergeWhenClause);
12778 36 : n->commandType = CMD_INSERT;
12779 36 : n->override = OVERRIDING_NOT_SET;
12780 36 : n->targetList = NIL;
12781 36 : n->values = NIL;
12782 36 : $$ = n;
12783 : }
12784 : ;
12785 :
12786 : merge_values_clause:
12787 : VALUES '(' expr_list ')'
12788 : {
12789 1064 : $$ = $3;
12790 : }
12791 : ;
12792 :
12793 : /*****************************************************************************
12794 : *
12795 : * QUERY:
12796 : * CURSOR STATEMENTS
12797 : *
12798 : *****************************************************************************/
12799 : DeclareCursorStmt: DECLARE cursor_name cursor_options CURSOR opt_hold FOR SelectStmt
12800 : {
12801 4608 : DeclareCursorStmt *n = makeNode(DeclareCursorStmt);
12802 :
12803 4608 : n->portalname = $2;
12804 : /* currently we always set FAST_PLAN option */
12805 4608 : n->options = $3 | $5 | CURSOR_OPT_FAST_PLAN;
12806 4608 : n->query = $7;
12807 4608 : $$ = (Node *) n;
12808 : }
12809 : ;
12810 :
12811 14816 : cursor_name: name { $$ = $1; }
12812 : ;
12813 :
12814 4608 : cursor_options: /*EMPTY*/ { $$ = 0; }
12815 28 : | cursor_options NO SCROLL { $$ = $1 | CURSOR_OPT_NO_SCROLL; }
12816 240 : | cursor_options SCROLL { $$ = $1 | CURSOR_OPT_SCROLL; }
12817 14 : | cursor_options BINARY { $$ = $1 | CURSOR_OPT_BINARY; }
12818 0 : | cursor_options ASENSITIVE { $$ = $1 | CURSOR_OPT_ASENSITIVE; }
12819 6 : | cursor_options INSENSITIVE { $$ = $1 | CURSOR_OPT_INSENSITIVE; }
12820 : ;
12821 :
12822 4510 : opt_hold: /* EMPTY */ { $$ = 0; }
12823 92 : | WITH HOLD { $$ = CURSOR_OPT_HOLD; }
12824 6 : | WITHOUT HOLD { $$ = 0; }
12825 : ;
12826 :
12827 : /*****************************************************************************
12828 : *
12829 : * QUERY:
12830 : * SELECT STATEMENTS
12831 : *
12832 : *****************************************************************************/
12833 :
12834 : /* A complete SELECT statement looks like this.
12835 : *
12836 : * The rule returns either a single SelectStmt node or a tree of them,
12837 : * representing a set-operation tree.
12838 : *
12839 : * There is an ambiguity when a sub-SELECT is within an a_expr and there
12840 : * are excess parentheses: do the parentheses belong to the sub-SELECT or
12841 : * to the surrounding a_expr? We don't really care, but bison wants to know.
12842 : * To resolve the ambiguity, we are careful to define the grammar so that
12843 : * the decision is staved off as long as possible: as long as we can keep
12844 : * absorbing parentheses into the sub-SELECT, we will do so, and only when
12845 : * it's no longer possible to do that will we decide that parens belong to
12846 : * the expression. For example, in "SELECT (((SELECT 2)) + 3)" the extra
12847 : * parentheses are treated as part of the sub-select. The necessity of doing
12848 : * it that way is shown by "SELECT (((SELECT 2)) UNION SELECT 2)". Had we
12849 : * parsed "((SELECT 2))" as an a_expr, it'd be too late to go back to the
12850 : * SELECT viewpoint when we see the UNION.
12851 : *
12852 : * This approach is implemented by defining a nonterminal select_with_parens,
12853 : * which represents a SELECT with at least one outer layer of parentheses,
12854 : * and being careful to use select_with_parens, never '(' SelectStmt ')',
12855 : * in the expression grammar. We will then have shift-reduce conflicts
12856 : * which we can resolve in favor of always treating '(' <select> ')' as
12857 : * a select_with_parens. To resolve the conflicts, the productions that
12858 : * conflict with the select_with_parens productions are manually given
12859 : * precedences lower than the precedence of ')', thereby ensuring that we
12860 : * shift ')' (and then reduce to select_with_parens) rather than trying to
12861 : * reduce the inner <select> nonterminal to something else. We use UMINUS
12862 : * precedence for this, which is a fairly arbitrary choice.
12863 : *
12864 : * To be able to define select_with_parens itself without ambiguity, we need
12865 : * a nonterminal select_no_parens that represents a SELECT structure with no
12866 : * outermost parentheses. This is a little bit tedious, but it works.
12867 : *
12868 : * In non-expression contexts, we use SelectStmt which can represent a SELECT
12869 : * with or without outer parentheses.
12870 : */
12871 :
12872 : SelectStmt: select_no_parens %prec UMINUS
12873 : | select_with_parens %prec UMINUS
12874 : ;
12875 :
12876 : select_with_parens:
12877 65118 : '(' select_no_parens ')' { $$ = $2; }
12878 156 : | '(' select_with_parens ')' { $$ = $2; }
12879 : ;
12880 :
12881 : /*
12882 : * This rule parses the equivalent of the standard's <query expression>.
12883 : * The duplicative productions are annoying, but hard to get rid of without
12884 : * creating shift/reduce conflicts.
12885 : *
12886 : * The locking clause (FOR UPDATE etc) may be before or after LIMIT/OFFSET.
12887 : * In <=7.2.X, LIMIT/OFFSET had to be after FOR UPDATE
12888 : * We now support both orderings, but prefer LIMIT/OFFSET before the locking
12889 : * clause.
12890 : * 2002-08-28 bjm
12891 : */
12892 : select_no_parens:
12893 390920 : simple_select { $$ = $1; }
12894 : | select_clause sort_clause
12895 : {
12896 70592 : insertSelectOptions((SelectStmt *) $1, $2, NIL,
12897 : NULL, NULL,
12898 : yyscanner);
12899 70592 : $$ = $1;
12900 : }
12901 : | select_clause opt_sort_clause for_locking_clause opt_select_limit
12902 : {
12903 4910 : insertSelectOptions((SelectStmt *) $1, $2, $3,
12904 4910 : $4,
12905 : NULL,
12906 : yyscanner);
12907 4910 : $$ = $1;
12908 : }
12909 : | select_clause opt_sort_clause select_limit opt_for_locking_clause
12910 : {
12911 4894 : insertSelectOptions((SelectStmt *) $1, $2, $4,
12912 4894 : $3,
12913 : NULL,
12914 : yyscanner);
12915 4882 : $$ = $1;
12916 : }
12917 : | with_clause select_clause
12918 : {
12919 2202 : insertSelectOptions((SelectStmt *) $2, NULL, NIL,
12920 : NULL,
12921 2202 : $1,
12922 : yyscanner);
12923 2202 : $$ = $2;
12924 : }
12925 : | with_clause select_clause sort_clause
12926 : {
12927 608 : insertSelectOptions((SelectStmt *) $2, $3, NIL,
12928 : NULL,
12929 608 : $1,
12930 : yyscanner);
12931 608 : $$ = $2;
12932 : }
12933 : | with_clause select_clause opt_sort_clause for_locking_clause opt_select_limit
12934 : {
12935 6 : insertSelectOptions((SelectStmt *) $2, $3, $4,
12936 6 : $5,
12937 6 : $1,
12938 : yyscanner);
12939 6 : $$ = $2;
12940 : }
12941 : | with_clause select_clause opt_sort_clause select_limit opt_for_locking_clause
12942 : {
12943 64 : insertSelectOptions((SelectStmt *) $2, $3, $5,
12944 64 : $4,
12945 64 : $1,
12946 : yyscanner);
12947 64 : $$ = $2;
12948 : }
12949 : ;
12950 :
12951 : select_clause:
12952 121468 : simple_select { $$ = $1; }
12953 588 : | select_with_parens { $$ = $1; }
12954 : ;
12955 :
12956 : /*
12957 : * This rule parses SELECT statements that can appear within set operations,
12958 : * including UNION, INTERSECT and EXCEPT. '(' and ')' can be used to specify
12959 : * the ordering of the set operations. Without '(' and ')' we want the
12960 : * operations to be ordered per the precedence specs at the head of this file.
12961 : *
12962 : * As with select_no_parens, simple_select cannot have outer parentheses,
12963 : * but can have parenthesized subclauses.
12964 : *
12965 : * It might appear that we could fold the first two alternatives into one
12966 : * by using opt_distinct_clause. However, that causes a shift/reduce conflict
12967 : * against INSERT ... SELECT ... ON CONFLICT. We avoid the ambiguity by
12968 : * requiring SELECT DISTINCT [ON] to be followed by a non-empty target_list.
12969 : *
12970 : * Note that sort clauses cannot be included at this level --- SQL requires
12971 : * SELECT foo UNION SELECT bar ORDER BY baz
12972 : * to be parsed as
12973 : * (SELECT foo UNION SELECT bar) ORDER BY baz
12974 : * not
12975 : * SELECT foo UNION (SELECT bar ORDER BY baz)
12976 : * Likewise for WITH, FOR UPDATE and LIMIT. Therefore, those clauses are
12977 : * described as part of the select_no_parens production, not simple_select.
12978 : * This does not limit functionality, because you can reintroduce these
12979 : * clauses inside parentheses.
12980 : *
12981 : * NOTE: only the leftmost component SelectStmt should have INTO.
12982 : * However, this is not checked by the grammar; parse analysis must check it.
12983 : */
12984 : simple_select:
12985 : SELECT opt_all_clause opt_target_list
12986 : into_clause from_clause where_clause
12987 : group_clause having_clause window_clause
12988 : {
12989 429970 : SelectStmt *n = makeNode(SelectStmt);
12990 :
12991 429968 : n->targetList = $3;
12992 429968 : n->intoClause = $4;
12993 429968 : n->fromClause = $5;
12994 429968 : n->whereClause = $6;
12995 429968 : n->groupClause = ($7)->list;
12996 429968 : n->groupDistinct = ($7)->distinct;
12997 429968 : n->groupByAll = ($7)->all;
12998 429968 : n->havingClause = $8;
12999 429968 : n->windowClause = $9;
13000 429968 : $$ = (Node *) n;
13001 : }
13002 : | SELECT distinct_clause target_list
13003 : into_clause from_clause where_clause
13004 : group_clause having_clause window_clause
13005 : {
13006 3674 : SelectStmt *n = makeNode(SelectStmt);
13007 :
13008 3674 : n->distinctClause = $2;
13009 3674 : n->targetList = $3;
13010 3674 : n->intoClause = $4;
13011 3674 : n->fromClause = $5;
13012 3674 : n->whereClause = $6;
13013 3674 : n->groupClause = ($7)->list;
13014 3674 : n->groupDistinct = ($7)->distinct;
13015 3674 : n->groupByAll = ($7)->all;
13016 3674 : n->havingClause = $8;
13017 3674 : n->windowClause = $9;
13018 3674 : $$ = (Node *) n;
13019 : }
13020 59052 : | values_clause { $$ = $1; }
13021 : | TABLE relation_expr
13022 : {
13023 : /* same as SELECT * FROM relation_expr */
13024 308 : ColumnRef *cr = makeNode(ColumnRef);
13025 308 : ResTarget *rt = makeNode(ResTarget);
13026 308 : SelectStmt *n = makeNode(SelectStmt);
13027 :
13028 308 : cr->fields = list_make1(makeNode(A_Star));
13029 308 : cr->location = -1;
13030 :
13031 308 : rt->name = NULL;
13032 308 : rt->indirection = NIL;
13033 308 : rt->val = (Node *) cr;
13034 308 : rt->location = -1;
13035 :
13036 308 : n->targetList = list_make1(rt);
13037 308 : n->fromClause = list_make1($2);
13038 308 : $$ = (Node *) n;
13039 : }
13040 : | select_clause UNION set_quantifier select_clause
13041 : {
13042 18650 : $$ = makeSetOp(SETOP_UNION, $3 == SET_QUANTIFIER_ALL, $1, $4);
13043 : }
13044 : | select_clause INTERSECT set_quantifier select_clause
13045 : {
13046 258 : $$ = makeSetOp(SETOP_INTERSECT, $3 == SET_QUANTIFIER_ALL, $1, $4);
13047 : }
13048 : | select_clause EXCEPT set_quantifier select_clause
13049 : {
13050 476 : $$ = makeSetOp(SETOP_EXCEPT, $3 == SET_QUANTIFIER_ALL, $1, $4);
13051 : }
13052 : ;
13053 :
13054 : /*
13055 : * SQL standard WITH clause looks like:
13056 : *
13057 : * WITH [ RECURSIVE ] <query name> [ (<column>,...) ]
13058 : * AS (query) [ SEARCH or CYCLE clause ]
13059 : *
13060 : * Recognizing WITH_LA here allows a CTE to be named TIME or ORDINALITY.
13061 : */
13062 : with_clause:
13063 : WITH cte_list
13064 : {
13065 2080 : $$ = makeNode(WithClause);
13066 2080 : $$->ctes = $2;
13067 2080 : $$->recursive = false;
13068 2080 : $$->location = @1;
13069 : }
13070 : | WITH_LA cte_list
13071 : {
13072 6 : $$ = makeNode(WithClause);
13073 6 : $$->ctes = $2;
13074 6 : $$->recursive = false;
13075 6 : $$->location = @1;
13076 : }
13077 : | WITH RECURSIVE cte_list
13078 : {
13079 1244 : $$ = makeNode(WithClause);
13080 1244 : $$->ctes = $3;
13081 1244 : $$->recursive = true;
13082 1244 : $$->location = @1;
13083 : }
13084 : ;
13085 :
13086 : cte_list:
13087 3330 : common_table_expr { $$ = list_make1($1); }
13088 1252 : | cte_list ',' common_table_expr { $$ = lappend($1, $3); }
13089 : ;
13090 :
13091 : common_table_expr: name opt_name_list AS opt_materialized '(' PreparableStmt ')' opt_search_clause opt_cycle_clause
13092 : {
13093 4582 : CommonTableExpr *n = makeNode(CommonTableExpr);
13094 :
13095 4582 : n->ctename = $1;
13096 4582 : n->aliascolnames = $2;
13097 4582 : n->ctematerialized = $4;
13098 4582 : n->ctequery = $6;
13099 4582 : n->search_clause = castNode(CTESearchClause, $8);
13100 4582 : n->cycle_clause = castNode(CTECycleClause, $9);
13101 4582 : n->location = @1;
13102 4582 : $$ = (Node *) n;
13103 : }
13104 : ;
13105 :
13106 : opt_materialized:
13107 178 : MATERIALIZED { $$ = CTEMaterializeAlways; }
13108 48 : | NOT MATERIALIZED { $$ = CTEMaterializeNever; }
13109 4356 : | /*EMPTY*/ { $$ = CTEMaterializeDefault; }
13110 : ;
13111 :
13112 : opt_search_clause:
13113 : SEARCH DEPTH FIRST_P BY columnList SET ColId
13114 : {
13115 90 : CTESearchClause *n = makeNode(CTESearchClause);
13116 :
13117 90 : n->search_col_list = $5;
13118 90 : n->search_breadth_first = false;
13119 90 : n->search_seq_column = $7;
13120 90 : n->location = @1;
13121 90 : $$ = (Node *) n;
13122 : }
13123 : | SEARCH BREADTH FIRST_P BY columnList SET ColId
13124 : {
13125 36 : CTESearchClause *n = makeNode(CTESearchClause);
13126 :
13127 36 : n->search_col_list = $5;
13128 36 : n->search_breadth_first = true;
13129 36 : n->search_seq_column = $7;
13130 36 : n->location = @1;
13131 36 : $$ = (Node *) n;
13132 : }
13133 : | /*EMPTY*/
13134 : {
13135 4456 : $$ = NULL;
13136 : }
13137 : ;
13138 :
13139 : opt_cycle_clause:
13140 : CYCLE columnList SET ColId TO AexprConst DEFAULT AexprConst USING ColId
13141 : {
13142 66 : CTECycleClause *n = makeNode(CTECycleClause);
13143 :
13144 66 : n->cycle_col_list = $2;
13145 66 : n->cycle_mark_column = $4;
13146 66 : n->cycle_mark_value = $6;
13147 66 : n->cycle_mark_default = $8;
13148 66 : n->cycle_path_column = $10;
13149 66 : n->location = @1;
13150 66 : $$ = (Node *) n;
13151 : }
13152 : | CYCLE columnList SET ColId USING ColId
13153 : {
13154 60 : CTECycleClause *n = makeNode(CTECycleClause);
13155 :
13156 60 : n->cycle_col_list = $2;
13157 60 : n->cycle_mark_column = $4;
13158 60 : n->cycle_mark_value = makeBoolAConst(true, -1);
13159 60 : n->cycle_mark_default = makeBoolAConst(false, -1);
13160 60 : n->cycle_path_column = $6;
13161 60 : n->location = @1;
13162 60 : $$ = (Node *) n;
13163 : }
13164 : | /*EMPTY*/
13165 : {
13166 4456 : $$ = NULL;
13167 : }
13168 : ;
13169 :
13170 : opt_with_clause:
13171 450 : with_clause { $$ = $1; }
13172 89418 : | /*EMPTY*/ { $$ = NULL; }
13173 : ;
13174 :
13175 : into_clause:
13176 : INTO OptTempTableName
13177 : {
13178 138 : $$ = makeNode(IntoClause);
13179 138 : $$->rel = $2;
13180 138 : $$->colNames = NIL;
13181 138 : $$->options = NIL;
13182 138 : $$->onCommit = ONCOMMIT_NOOP;
13183 138 : $$->tableSpaceName = NULL;
13184 138 : $$->viewQuery = NULL;
13185 138 : $$->skipData = false;
13186 : }
13187 : | /*EMPTY*/
13188 433536 : { $$ = NULL; }
13189 : ;
13190 :
13191 : /*
13192 : * Redundancy here is needed to avoid shift/reduce conflicts,
13193 : * since TEMP is not a reserved word. See also OptTemp.
13194 : */
13195 : OptTempTableName:
13196 : TEMPORARY opt_table qualified_name
13197 : {
13198 0 : $$ = $3;
13199 0 : $$->relpersistence = RELPERSISTENCE_TEMP;
13200 : }
13201 : | TEMP opt_table qualified_name
13202 : {
13203 6 : $$ = $3;
13204 6 : $$->relpersistence = RELPERSISTENCE_TEMP;
13205 : }
13206 : | LOCAL TEMPORARY opt_table qualified_name
13207 : {
13208 0 : $$ = $4;
13209 0 : $$->relpersistence = RELPERSISTENCE_TEMP;
13210 : }
13211 : | LOCAL TEMP opt_table qualified_name
13212 : {
13213 0 : $$ = $4;
13214 0 : $$->relpersistence = RELPERSISTENCE_TEMP;
13215 : }
13216 : | GLOBAL TEMPORARY opt_table qualified_name
13217 : {
13218 0 : ereport(WARNING,
13219 : (errmsg("GLOBAL is deprecated in temporary table creation"),
13220 : parser_errposition(@1)));
13221 0 : $$ = $4;
13222 0 : $$->relpersistence = RELPERSISTENCE_TEMP;
13223 : }
13224 : | GLOBAL TEMP opt_table qualified_name
13225 : {
13226 0 : ereport(WARNING,
13227 : (errmsg("GLOBAL is deprecated in temporary table creation"),
13228 : parser_errposition(@1)));
13229 0 : $$ = $4;
13230 0 : $$->relpersistence = RELPERSISTENCE_TEMP;
13231 : }
13232 : | UNLOGGED opt_table qualified_name
13233 : {
13234 0 : $$ = $3;
13235 0 : $$->relpersistence = RELPERSISTENCE_UNLOGGED;
13236 : }
13237 : | TABLE qualified_name
13238 : {
13239 30 : $$ = $2;
13240 30 : $$->relpersistence = RELPERSISTENCE_PERMANENT;
13241 : }
13242 : | qualified_name
13243 : {
13244 102 : $$ = $1;
13245 102 : $$->relpersistence = RELPERSISTENCE_PERMANENT;
13246 : }
13247 : ;
13248 :
13249 : opt_table: TABLE
13250 : | /*EMPTY*/
13251 : ;
13252 :
13253 : set_quantifier:
13254 10770 : ALL { $$ = SET_QUANTIFIER_ALL; }
13255 32 : | DISTINCT { $$ = SET_QUANTIFIER_DISTINCT; }
13256 13226 : | /*EMPTY*/ { $$ = SET_QUANTIFIER_DEFAULT; }
13257 : ;
13258 :
13259 : /* We use (NIL) as a placeholder to indicate that all target expressions
13260 : * should be placed in the DISTINCT list during parsetree analysis.
13261 : */
13262 : distinct_clause:
13263 3420 : DISTINCT { $$ = list_make1(NIL); }
13264 260 : | DISTINCT ON '(' expr_list ')' { $$ = $4; }
13265 : ;
13266 :
13267 : opt_all_clause:
13268 : ALL
13269 : | /*EMPTY*/
13270 : ;
13271 :
13272 : opt_distinct_clause:
13273 0 : distinct_clause { $$ = $1; }
13274 40342 : | opt_all_clause { $$ = NIL; }
13275 : ;
13276 :
13277 : opt_sort_clause:
13278 7390 : sort_clause { $$ = $1; }
13279 364198 : | /*EMPTY*/ { $$ = NIL; }
13280 : ;
13281 :
13282 : sort_clause:
13283 78938 : ORDER BY sortby_list { $$ = $3; }
13284 : ;
13285 :
13286 : sortby_list:
13287 78956 : sortby { $$ = list_make1($1); }
13288 28728 : | sortby_list ',' sortby { $$ = lappend($1, $3); }
13289 : ;
13290 :
13291 : sortby: a_expr USING qual_all_Op opt_nulls_order
13292 : {
13293 220 : $$ = makeNode(SortBy);
13294 220 : $$->node = $1;
13295 220 : $$->sortby_dir = SORTBY_USING;
13296 220 : $$->sortby_nulls = $4;
13297 220 : $$->useOp = $3;
13298 220 : $$->location = @3;
13299 : }
13300 : | a_expr opt_asc_desc opt_nulls_order
13301 : {
13302 107464 : $$ = makeNode(SortBy);
13303 107464 : $$->node = $1;
13304 107464 : $$->sortby_dir = $2;
13305 107464 : $$->sortby_nulls = $3;
13306 107464 : $$->useOp = NIL;
13307 107464 : $$->location = -1; /* no operator */
13308 : }
13309 : ;
13310 :
13311 :
13312 : select_limit:
13313 : limit_clause offset_clause
13314 : {
13315 172 : $$ = $1;
13316 172 : ($$)->limitOffset = $2;
13317 172 : ($$)->offsetLoc = @2;
13318 : }
13319 : | offset_clause limit_clause
13320 : {
13321 222 : $$ = $2;
13322 222 : ($$)->limitOffset = $1;
13323 222 : ($$)->offsetLoc = @1;
13324 : }
13325 : | limit_clause
13326 : {
13327 4304 : $$ = $1;
13328 : }
13329 : | offset_clause
13330 : {
13331 450 : SelectLimit *n = (SelectLimit *) palloc(sizeof(SelectLimit));
13332 :
13333 450 : n->limitOffset = $1;
13334 450 : n->limitCount = NULL;
13335 450 : n->limitOption = LIMIT_OPTION_COUNT;
13336 450 : n->offsetLoc = @1;
13337 450 : n->countLoc = -1;
13338 450 : n->optionLoc = -1;
13339 450 : $$ = n;
13340 : }
13341 : ;
13342 :
13343 : opt_select_limit:
13344 190 : select_limit { $$ = $1; }
13345 45068 : | /* EMPTY */ { $$ = NULL; }
13346 : ;
13347 :
13348 : limit_clause:
13349 : LIMIT select_limit_value
13350 : {
13351 4602 : SelectLimit *n = (SelectLimit *) palloc(sizeof(SelectLimit));
13352 :
13353 4602 : n->limitOffset = NULL;
13354 4602 : n->limitCount = $2;
13355 4602 : n->limitOption = LIMIT_OPTION_COUNT;
13356 4602 : n->offsetLoc = -1;
13357 4602 : n->countLoc = @1;
13358 4602 : n->optionLoc = -1;
13359 4602 : $$ = n;
13360 : }
13361 : | LIMIT select_limit_value ',' select_offset_value
13362 : {
13363 : /* Disabled because it was too confusing, bjm 2002-02-18 */
13364 0 : ereport(ERROR,
13365 : (errcode(ERRCODE_SYNTAX_ERROR),
13366 : errmsg("LIMIT #,# syntax is not supported"),
13367 : errhint("Use separate LIMIT and OFFSET clauses."),
13368 : parser_errposition(@1)));
13369 : }
13370 : /* SQL:2008 syntax */
13371 : /* to avoid shift/reduce conflicts, handle the optional value with
13372 : * a separate production rather than an opt_ expression. The fact
13373 : * that ONLY is fully reserved means that this way, we defer any
13374 : * decision about what rule reduces ROW or ROWS to the point where
13375 : * we can see the ONLY token in the lookahead slot.
13376 : */
13377 : | FETCH first_or_next select_fetch_first_value row_or_rows ONLY
13378 : {
13379 24 : SelectLimit *n = (SelectLimit *) palloc(sizeof(SelectLimit));
13380 :
13381 24 : n->limitOffset = NULL;
13382 24 : n->limitCount = $3;
13383 24 : n->limitOption = LIMIT_OPTION_COUNT;
13384 24 : n->offsetLoc = -1;
13385 24 : n->countLoc = @1;
13386 24 : n->optionLoc = -1;
13387 24 : $$ = n;
13388 : }
13389 : | FETCH first_or_next select_fetch_first_value row_or_rows WITH TIES
13390 : {
13391 66 : SelectLimit *n = (SelectLimit *) palloc(sizeof(SelectLimit));
13392 :
13393 66 : n->limitOffset = NULL;
13394 66 : n->limitCount = $3;
13395 66 : n->limitOption = LIMIT_OPTION_WITH_TIES;
13396 66 : n->offsetLoc = -1;
13397 66 : n->countLoc = @1;
13398 66 : n->optionLoc = @5;
13399 66 : $$ = n;
13400 : }
13401 : | FETCH first_or_next row_or_rows ONLY
13402 : {
13403 0 : SelectLimit *n = (SelectLimit *) palloc(sizeof(SelectLimit));
13404 :
13405 0 : n->limitOffset = NULL;
13406 0 : n->limitCount = makeIntConst(1, -1);
13407 0 : n->limitOption = LIMIT_OPTION_COUNT;
13408 0 : n->offsetLoc = -1;
13409 0 : n->countLoc = @1;
13410 0 : n->optionLoc = -1;
13411 0 : $$ = n;
13412 : }
13413 : | FETCH first_or_next row_or_rows WITH TIES
13414 : {
13415 6 : SelectLimit *n = (SelectLimit *) palloc(sizeof(SelectLimit));
13416 :
13417 6 : n->limitOffset = NULL;
13418 6 : n->limitCount = makeIntConst(1, -1);
13419 6 : n->limitOption = LIMIT_OPTION_WITH_TIES;
13420 6 : n->offsetLoc = -1;
13421 6 : n->countLoc = @1;
13422 6 : n->optionLoc = @4;
13423 6 : $$ = n;
13424 : }
13425 : ;
13426 :
13427 : offset_clause:
13428 : OFFSET select_offset_value
13429 844 : { $$ = $2; }
13430 : /* SQL:2008 syntax */
13431 : | OFFSET select_fetch_first_value row_or_rows
13432 0 : { $$ = $2; }
13433 : ;
13434 :
13435 : select_limit_value:
13436 4600 : a_expr { $$ = $1; }
13437 : | ALL
13438 : {
13439 : /* LIMIT ALL is represented as a NULL constant */
13440 2 : $$ = makeNullAConst(@1);
13441 : }
13442 : ;
13443 :
13444 : select_offset_value:
13445 844 : a_expr { $$ = $1; }
13446 : ;
13447 :
13448 : /*
13449 : * Allowing full expressions without parentheses causes various parsing
13450 : * problems with the trailing ROW/ROWS key words. SQL spec only calls for
13451 : * <simple value specification>, which is either a literal or a parameter (but
13452 : * an <SQL parameter reference> could be an identifier, bringing up conflicts
13453 : * with ROW/ROWS). We solve this by leveraging the presence of ONLY (see above)
13454 : * to determine whether the expression is missing rather than trying to make it
13455 : * optional in this rule.
13456 : *
13457 : * c_expr covers almost all the spec-required cases (and more), but it doesn't
13458 : * cover signed numeric literals, which are allowed by the spec. So we include
13459 : * those here explicitly. We need FCONST as well as ICONST because values that
13460 : * don't fit in the platform's "long", but do fit in bigint, should still be
13461 : * accepted here. (This is possible in 64-bit Windows as well as all 32-bit
13462 : * builds.)
13463 : */
13464 : select_fetch_first_value:
13465 90 : c_expr { $$ = $1; }
13466 : | '+' I_or_F_const
13467 0 : { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "+", NULL, $2, @1); }
13468 : | '-' I_or_F_const
13469 0 : { $$ = doNegate($2, @1); }
13470 : ;
13471 :
13472 : I_or_F_const:
13473 0 : Iconst { $$ = makeIntConst($1,@1); }
13474 0 : | FCONST { $$ = makeFloatConst($1,@1); }
13475 : ;
13476 :
13477 : /* noise words */
13478 36 : row_or_rows: ROW { $$ = 0; }
13479 60 : | ROWS { $$ = 0; }
13480 : ;
13481 :
13482 96 : first_or_next: FIRST_P { $$ = 0; }
13483 0 : | NEXT { $$ = 0; }
13484 : ;
13485 :
13486 :
13487 : /*
13488 : * This syntax for group_clause tries to follow the spec quite closely.
13489 : * However, the spec allows only column references, not expressions,
13490 : * which introduces an ambiguity between implicit row constructors
13491 : * (a,b) and lists of column references.
13492 : *
13493 : * We handle this by using the a_expr production for what the spec calls
13494 : * <ordinary grouping set>, which in the spec represents either one column
13495 : * reference or a parenthesized list of column references. Then, we check the
13496 : * top node of the a_expr to see if it's an implicit RowExpr, and if so, just
13497 : * grab and use the list, discarding the node. (this is done in parse analysis,
13498 : * not here)
13499 : *
13500 : * (we abuse the row_format field of RowExpr to distinguish implicit and
13501 : * explicit row constructors; it's debatable if anyone sanely wants to use them
13502 : * in a group clause, but if they have a reason to, we make it possible.)
13503 : *
13504 : * Each item in the group_clause list is either an expression tree or a
13505 : * GroupingSet node of some type.
13506 : */
13507 : group_clause:
13508 : GROUP_P BY set_quantifier group_by_list
13509 : {
13510 4632 : GroupClause *n = (GroupClause *) palloc(sizeof(GroupClause));
13511 :
13512 4632 : n->distinct = $3 == SET_QUANTIFIER_DISTINCT;
13513 4632 : n->all = false;
13514 4632 : n->list = $4;
13515 4632 : $$ = n;
13516 : }
13517 : | GROUP_P BY ALL
13518 : {
13519 66 : GroupClause *n = (GroupClause *) palloc(sizeof(GroupClause));
13520 66 : n->distinct = false;
13521 66 : n->all = true;
13522 66 : n->list = NIL;
13523 66 : $$ = n;
13524 : }
13525 : | /*EMPTY*/
13526 : {
13527 469288 : GroupClause *n = (GroupClause *) palloc(sizeof(GroupClause));
13528 :
13529 469284 : n->distinct = false;
13530 469284 : n->all = false;
13531 469284 : n->list = NIL;
13532 469284 : $$ = n;
13533 : }
13534 : ;
13535 :
13536 : group_by_list:
13537 5230 : group_by_item { $$ = list_make1($1); }
13538 3028 : | group_by_list ',' group_by_item { $$ = lappend($1,$3); }
13539 : ;
13540 :
13541 : group_by_item:
13542 6968 : a_expr { $$ = $1; }
13543 222 : | empty_grouping_set { $$ = $1; }
13544 184 : | cube_clause { $$ = $1; }
13545 286 : | rollup_clause { $$ = $1; }
13546 598 : | grouping_sets_clause { $$ = $1; }
13547 : ;
13548 :
13549 : empty_grouping_set:
13550 : '(' ')'
13551 : {
13552 222 : $$ = (Node *) makeGroupingSet(GROUPING_SET_EMPTY, NIL, @1);
13553 : }
13554 : ;
13555 :
13556 : /*
13557 : * These hacks rely on setting precedence of CUBE and ROLLUP below that of '(',
13558 : * so that they shift in these rules rather than reducing the conflicting
13559 : * unreserved_keyword rule.
13560 : */
13561 :
13562 : rollup_clause:
13563 : ROLLUP '(' expr_list ')'
13564 : {
13565 286 : $$ = (Node *) makeGroupingSet(GROUPING_SET_ROLLUP, $3, @1);
13566 : }
13567 : ;
13568 :
13569 : cube_clause:
13570 : CUBE '(' expr_list ')'
13571 : {
13572 184 : $$ = (Node *) makeGroupingSet(GROUPING_SET_CUBE, $3, @1);
13573 : }
13574 : ;
13575 :
13576 : grouping_sets_clause:
13577 : GROUPING SETS '(' group_by_list ')'
13578 : {
13579 598 : $$ = (Node *) makeGroupingSet(GROUPING_SET_SETS, $4, @1);
13580 : }
13581 : ;
13582 :
13583 : having_clause:
13584 720 : HAVING a_expr { $$ = $2; }
13585 473266 : | /*EMPTY*/ { $$ = NULL; }
13586 : ;
13587 :
13588 : for_locking_clause:
13589 5256 : for_locking_items { $$ = $1; }
13590 0 : | FOR READ ONLY { $$ = NIL; }
13591 : ;
13592 :
13593 : opt_for_locking_clause:
13594 340 : for_locking_clause { $$ = $1; }
13595 44960 : | /* EMPTY */ { $$ = NIL; }
13596 : ;
13597 :
13598 : for_locking_items:
13599 5256 : for_locking_item { $$ = list_make1($1); }
13600 102 : | for_locking_items for_locking_item { $$ = lappend($1, $2); }
13601 : ;
13602 :
13603 : for_locking_item:
13604 : for_locking_strength locked_rels_list opt_nowait_or_skip
13605 : {
13606 5358 : LockingClause *n = makeNode(LockingClause);
13607 :
13608 5358 : n->lockedRels = $2;
13609 5358 : n->strength = $1;
13610 5358 : n->waitPolicy = $3;
13611 5358 : $$ = (Node *) n;
13612 : }
13613 : ;
13614 :
13615 : for_locking_strength:
13616 1534 : FOR UPDATE { $$ = LCS_FORUPDATE; }
13617 76 : | FOR NO KEY UPDATE { $$ = LCS_FORNOKEYUPDATE; }
13618 214 : | FOR SHARE { $$ = LCS_FORSHARE; }
13619 3534 : | FOR KEY SHARE { $$ = LCS_FORKEYSHARE; }
13620 : ;
13621 :
13622 : locked_rels_list:
13623 3560 : OF qualified_name_list { $$ = $2; }
13624 1798 : | /* EMPTY */ { $$ = NIL; }
13625 : ;
13626 :
13627 :
13628 : /*
13629 : * We should allow ROW '(' expr_list ')' too, but that seems to require
13630 : * making VALUES a fully reserved word, which will probably break more apps
13631 : * than allowing the noise-word is worth.
13632 : */
13633 : values_clause:
13634 : VALUES '(' expr_list ')'
13635 : {
13636 59052 : SelectStmt *n = makeNode(SelectStmt);
13637 :
13638 59052 : n->valuesLists = list_make1($3);
13639 59052 : $$ = (Node *) n;
13640 : }
13641 : | values_clause ',' '(' expr_list ')'
13642 : {
13643 25152 : SelectStmt *n = (SelectStmt *) $1;
13644 :
13645 25152 : n->valuesLists = lappend(n->valuesLists, $4);
13646 25152 : $$ = (Node *) n;
13647 : }
13648 : ;
13649 :
13650 :
13651 : /*****************************************************************************
13652 : *
13653 : * clauses common to all Optimizable Stmts:
13654 : * from_clause - allow list of both JOIN expressions and table names
13655 : * where_clause - qualifications for joins or restrictions
13656 : *
13657 : *****************************************************************************/
13658 :
13659 : from_clause:
13660 314256 : FROM from_list { $$ = $2; }
13661 174040 : | /*EMPTY*/ { $$ = NIL; }
13662 : ;
13663 :
13664 : from_list:
13665 315112 : table_ref { $$ = list_make1($1); }
13666 61266 : | from_list ',' table_ref { $$ = lappend($1, $3); }
13667 : ;
13668 :
13669 : /*
13670 : * table_ref is where an alias clause can be attached.
13671 : */
13672 : table_ref: relation_expr opt_alias_clause
13673 : {
13674 397178 : $1->alias = $2;
13675 397178 : $$ = (Node *) $1;
13676 : }
13677 : | relation_expr opt_alias_clause tablesample_clause
13678 : {
13679 266 : RangeTableSample *n = (RangeTableSample *) $3;
13680 :
13681 266 : $1->alias = $2;
13682 : /* relation_expr goes inside the RangeTableSample node */
13683 266 : n->relation = (Node *) $1;
13684 266 : $$ = (Node *) n;
13685 : }
13686 : | func_table func_alias_clause
13687 : {
13688 46542 : RangeFunction *n = (RangeFunction *) $1;
13689 :
13690 46542 : n->alias = linitial($2);
13691 46542 : n->coldeflist = lsecond($2);
13692 46542 : $$ = (Node *) n;
13693 : }
13694 : | LATERAL_P func_table func_alias_clause
13695 : {
13696 1168 : RangeFunction *n = (RangeFunction *) $2;
13697 :
13698 1168 : n->lateral = true;
13699 1168 : n->alias = linitial($3);
13700 1168 : n->coldeflist = lsecond($3);
13701 1168 : $$ = (Node *) n;
13702 : }
13703 : | xmltable opt_alias_clause
13704 : {
13705 86 : RangeTableFunc *n = (RangeTableFunc *) $1;
13706 :
13707 86 : n->alias = $2;
13708 86 : $$ = (Node *) n;
13709 : }
13710 : | LATERAL_P xmltable opt_alias_clause
13711 : {
13712 140 : RangeTableFunc *n = (RangeTableFunc *) $2;
13713 :
13714 140 : n->lateral = true;
13715 140 : n->alias = $3;
13716 140 : $$ = (Node *) n;
13717 : }
13718 : | select_with_parens opt_alias_clause
13719 : {
13720 14170 : RangeSubselect *n = makeNode(RangeSubselect);
13721 :
13722 14170 : n->lateral = false;
13723 14170 : n->subquery = $1;
13724 14170 : n->alias = $2;
13725 14170 : $$ = (Node *) n;
13726 : }
13727 : | LATERAL_P select_with_parens opt_alias_clause
13728 : {
13729 1900 : RangeSubselect *n = makeNode(RangeSubselect);
13730 :
13731 1900 : n->lateral = true;
13732 1900 : n->subquery = $2;
13733 1900 : n->alias = $3;
13734 1900 : $$ = (Node *) n;
13735 : }
13736 : | joined_table
13737 : {
13738 83268 : $$ = (Node *) $1;
13739 : }
13740 : | '(' joined_table ')' alias_clause
13741 : {
13742 174 : $2->alias = $4;
13743 174 : $$ = (Node *) $2;
13744 : }
13745 : | json_table opt_alias_clause
13746 : {
13747 530 : JsonTable *jt = castNode(JsonTable, $1);
13748 :
13749 530 : jt->alias = $2;
13750 530 : $$ = (Node *) jt;
13751 : }
13752 : | LATERAL_P json_table opt_alias_clause
13753 : {
13754 0 : JsonTable *jt = castNode(JsonTable, $2);
13755 :
13756 0 : jt->alias = $3;
13757 0 : jt->lateral = true;
13758 0 : $$ = (Node *) jt;
13759 : }
13760 : ;
13761 :
13762 :
13763 : /*
13764 : * It may seem silly to separate joined_table from table_ref, but there is
13765 : * method in SQL's madness: if you don't do it this way you get reduce-
13766 : * reduce conflicts, because it's not clear to the parser generator whether
13767 : * to expect alias_clause after ')' or not. For the same reason we must
13768 : * treat 'JOIN' and 'join_type JOIN' separately, rather than allowing
13769 : * join_type to expand to empty; if we try it, the parser generator can't
13770 : * figure out when to reduce an empty join_type right after table_ref.
13771 : *
13772 : * Note that a CROSS JOIN is the same as an unqualified
13773 : * INNER JOIN, and an INNER JOIN/ON has the same shape
13774 : * but a qualification expression to limit membership.
13775 : * A NATURAL JOIN implicitly matches column names between
13776 : * tables and the shape is determined by which columns are
13777 : * in common. We'll collect columns during the later transformations.
13778 : */
13779 :
13780 : joined_table:
13781 : '(' joined_table ')'
13782 : {
13783 3962 : $$ = $2;
13784 : }
13785 : | table_ref CROSS JOIN table_ref
13786 : {
13787 : /* CROSS JOIN is same as unqualified inner join */
13788 508 : JoinExpr *n = makeNode(JoinExpr);
13789 :
13790 508 : n->jointype = JOIN_INNER;
13791 508 : n->isNatural = false;
13792 508 : n->larg = $1;
13793 508 : n->rarg = $4;
13794 508 : n->usingClause = NIL;
13795 508 : n->join_using_alias = NULL;
13796 508 : n->quals = NULL;
13797 508 : $$ = n;
13798 : }
13799 : | table_ref join_type JOIN table_ref join_qual
13800 : {
13801 47252 : JoinExpr *n = makeNode(JoinExpr);
13802 :
13803 47252 : n->jointype = $2;
13804 47252 : n->isNatural = false;
13805 47252 : n->larg = $1;
13806 47252 : n->rarg = $4;
13807 47252 : if ($5 != NULL && IsA($5, List))
13808 : {
13809 : /* USING clause */
13810 498 : n->usingClause = linitial_node(List, castNode(List, $5));
13811 498 : n->join_using_alias = lsecond_node(Alias, castNode(List, $5));
13812 : }
13813 : else
13814 : {
13815 : /* ON clause */
13816 46754 : n->quals = $5;
13817 : }
13818 47252 : $$ = n;
13819 : }
13820 : | table_ref JOIN table_ref join_qual
13821 : {
13822 : /* letting join_type reduce to empty doesn't work */
13823 35418 : JoinExpr *n = makeNode(JoinExpr);
13824 :
13825 35418 : n->jointype = JOIN_INNER;
13826 35418 : n->isNatural = false;
13827 35418 : n->larg = $1;
13828 35418 : n->rarg = $3;
13829 35418 : if ($4 != NULL && IsA($4, List))
13830 : {
13831 : /* USING clause */
13832 744 : n->usingClause = linitial_node(List, castNode(List, $4));
13833 744 : n->join_using_alias = lsecond_node(Alias, castNode(List, $4));
13834 : }
13835 : else
13836 : {
13837 : /* ON clause */
13838 34674 : n->quals = $4;
13839 : }
13840 35418 : $$ = n;
13841 : }
13842 : | table_ref NATURAL join_type JOIN table_ref
13843 : {
13844 78 : JoinExpr *n = makeNode(JoinExpr);
13845 :
13846 78 : n->jointype = $3;
13847 78 : n->isNatural = true;
13848 78 : n->larg = $1;
13849 78 : n->rarg = $5;
13850 78 : n->usingClause = NIL; /* figure out which columns later... */
13851 78 : n->join_using_alias = NULL;
13852 78 : n->quals = NULL; /* fill later */
13853 78 : $$ = n;
13854 : }
13855 : | table_ref NATURAL JOIN table_ref
13856 : {
13857 : /* letting join_type reduce to empty doesn't work */
13858 186 : JoinExpr *n = makeNode(JoinExpr);
13859 :
13860 186 : n->jointype = JOIN_INNER;
13861 186 : n->isNatural = true;
13862 186 : n->larg = $1;
13863 186 : n->rarg = $4;
13864 186 : n->usingClause = NIL; /* figure out which columns later... */
13865 186 : n->join_using_alias = NULL;
13866 186 : n->quals = NULL; /* fill later */
13867 186 : $$ = n;
13868 : }
13869 : ;
13870 :
13871 : alias_clause:
13872 : AS ColId '(' name_list ')'
13873 : {
13874 6680 : $$ = makeNode(Alias);
13875 6680 : $$->aliasname = $2;
13876 6680 : $$->colnames = $4;
13877 : }
13878 : | AS ColId
13879 : {
13880 10916 : $$ = makeNode(Alias);
13881 10916 : $$->aliasname = $2;
13882 : }
13883 : | ColId '(' name_list ')'
13884 : {
13885 5856 : $$ = makeNode(Alias);
13886 5856 : $$->aliasname = $1;
13887 5856 : $$->colnames = $3;
13888 : }
13889 : | ColId
13890 : {
13891 262950 : $$ = makeNode(Alias);
13892 262950 : $$->aliasname = $1;
13893 : }
13894 : ;
13895 :
13896 257538 : opt_alias_clause: alias_clause { $$ = $1; }
13897 156732 : | /*EMPTY*/ { $$ = NULL; }
13898 : ;
13899 :
13900 : /*
13901 : * The alias clause after JOIN ... USING only accepts the AS ColId spelling,
13902 : * per SQL standard. (The grammar could parse the other variants, but they
13903 : * don't seem to be useful, and it might lead to parser problems in the
13904 : * future.)
13905 : */
13906 : opt_alias_clause_for_join_using:
13907 : AS ColId
13908 : {
13909 84 : $$ = makeNode(Alias);
13910 84 : $$->aliasname = $2;
13911 : /* the column name list will be inserted later */
13912 : }
13913 1158 : | /*EMPTY*/ { $$ = NULL; }
13914 : ;
13915 :
13916 : /*
13917 : * func_alias_clause can include both an Alias and a coldeflist, so we make it
13918 : * return a 2-element list that gets disassembled by calling production.
13919 : */
13920 : func_alias_clause:
13921 : alias_clause
13922 : {
13923 28690 : $$ = list_make2($1, NIL);
13924 : }
13925 : | AS '(' TableFuncElementList ')'
13926 : {
13927 114 : $$ = list_make2(NULL, $3);
13928 : }
13929 : | AS ColId '(' TableFuncElementList ')'
13930 : {
13931 596 : Alias *a = makeNode(Alias);
13932 :
13933 596 : a->aliasname = $2;
13934 596 : $$ = list_make2(a, $4);
13935 : }
13936 : | ColId '(' TableFuncElementList ')'
13937 : {
13938 50 : Alias *a = makeNode(Alias);
13939 :
13940 50 : a->aliasname = $1;
13941 50 : $$ = list_make2(a, $3);
13942 : }
13943 : | /*EMPTY*/
13944 : {
13945 18260 : $$ = list_make2(NULL, NIL);
13946 : }
13947 : ;
13948 :
13949 1042 : join_type: FULL opt_outer { $$ = JOIN_FULL; }
13950 41948 : | LEFT opt_outer { $$ = JOIN_LEFT; }
13951 378 : | RIGHT opt_outer { $$ = JOIN_RIGHT; }
13952 3962 : | INNER_P { $$ = JOIN_INNER; }
13953 : ;
13954 :
13955 : /* OUTER is just noise... */
13956 : opt_outer: OUTER_P
13957 : | /*EMPTY*/
13958 : ;
13959 :
13960 : /* JOIN qualification clauses
13961 : * Possibilities are:
13962 : * USING ( column list ) [ AS alias ]
13963 : * allows only unqualified column names,
13964 : * which must match between tables.
13965 : * ON expr allows more general qualifications.
13966 : *
13967 : * We return USING as a two-element List (the first item being a sub-List
13968 : * of the common column names, and the second either an Alias item or NULL).
13969 : * An ON-expr will not be a List, so it can be told apart that way.
13970 : */
13971 :
13972 : join_qual: USING '(' name_list ')' opt_alias_clause_for_join_using
13973 : {
13974 1242 : $$ = (Node *) list_make2($3, $5);
13975 : }
13976 : | ON a_expr
13977 : {
13978 81428 : $$ = $2;
13979 : }
13980 : ;
13981 :
13982 :
13983 : relation_expr:
13984 : qualified_name
13985 : {
13986 : /* inheritance query, implicitly */
13987 478712 : $$ = $1;
13988 478712 : $$->inh = true;
13989 478712 : $$->alias = NULL;
13990 : }
13991 : | extended_relation_expr
13992 : {
13993 7286 : $$ = $1;
13994 : }
13995 : ;
13996 :
13997 : extended_relation_expr:
13998 : qualified_name '*'
13999 : {
14000 : /* inheritance query, explicitly */
14001 204 : $$ = $1;
14002 204 : $$->inh = true;
14003 204 : $$->alias = NULL;
14004 : }
14005 : | ONLY qualified_name
14006 : {
14007 : /* no inheritance */
14008 7088 : $$ = $2;
14009 7088 : $$->inh = false;
14010 7088 : $$->alias = NULL;
14011 : }
14012 : | ONLY '(' qualified_name ')'
14013 : {
14014 : /* no inheritance, SQL99-style syntax */
14015 0 : $$ = $3;
14016 0 : $$->inh = false;
14017 0 : $$->alias = NULL;
14018 : }
14019 : ;
14020 :
14021 :
14022 : relation_expr_list:
14023 2970 : relation_expr { $$ = list_make1($1); }
14024 11822 : | relation_expr_list ',' relation_expr { $$ = lappend($1, $3); }
14025 : ;
14026 :
14027 :
14028 : /*
14029 : * Given "UPDATE foo set set ...", we have to decide without looking any
14030 : * further ahead whether the first "set" is an alias or the UPDATE's SET
14031 : * keyword. Since "set" is allowed as a column name both interpretations
14032 : * are feasible. We resolve the shift/reduce conflict by giving the first
14033 : * relation_expr_opt_alias production a higher precedence than the SET token
14034 : * has, causing the parser to prefer to reduce, in effect assuming that the
14035 : * SET is not an alias.
14036 : */
14037 : relation_expr_opt_alias: relation_expr %prec UMINUS
14038 : {
14039 18820 : $$ = $1;
14040 : }
14041 : | relation_expr ColId
14042 : {
14043 2250 : Alias *alias = makeNode(Alias);
14044 :
14045 2250 : alias->aliasname = $2;
14046 2250 : $1->alias = alias;
14047 2250 : $$ = $1;
14048 : }
14049 : | relation_expr AS ColId
14050 : {
14051 90 : Alias *alias = makeNode(Alias);
14052 :
14053 90 : alias->aliasname = $3;
14054 90 : $1->alias = alias;
14055 90 : $$ = $1;
14056 : }
14057 : ;
14058 :
14059 : /*
14060 : * TABLESAMPLE decoration in a FROM item
14061 : */
14062 : tablesample_clause:
14063 : TABLESAMPLE func_name '(' expr_list ')' opt_repeatable_clause
14064 : {
14065 266 : RangeTableSample *n = makeNode(RangeTableSample);
14066 :
14067 : /* n->relation will be filled in later */
14068 266 : n->method = $2;
14069 266 : n->args = $4;
14070 266 : n->repeatable = $6;
14071 266 : n->location = @2;
14072 266 : $$ = (Node *) n;
14073 : }
14074 : ;
14075 :
14076 : opt_repeatable_clause:
14077 108 : REPEATABLE '(' a_expr ')' { $$ = (Node *) $3; }
14078 158 : | /*EMPTY*/ { $$ = NULL; }
14079 : ;
14080 :
14081 : /*
14082 : * func_table represents a function invocation in a FROM list. It can be
14083 : * a plain function call, like "foo(...)", or a ROWS FROM expression with
14084 : * one or more function calls, "ROWS FROM (foo(...), bar(...))",
14085 : * optionally with WITH ORDINALITY attached.
14086 : * In the ROWS FROM syntax, a column definition list can be given for each
14087 : * function, for example:
14088 : * ROWS FROM (foo() AS (foo_res_a text, foo_res_b text),
14089 : * bar() AS (bar_res_a text, bar_res_b text))
14090 : * It's also possible to attach a column definition list to the RangeFunction
14091 : * as a whole, but that's handled by the table_ref production.
14092 : */
14093 : func_table: func_expr_windowless opt_ordinality
14094 : {
14095 47584 : RangeFunction *n = makeNode(RangeFunction);
14096 :
14097 47584 : n->lateral = false;
14098 47584 : n->ordinality = $2;
14099 47584 : n->is_rowsfrom = false;
14100 47584 : n->functions = list_make1(list_make2($1, NIL));
14101 : /* alias and coldeflist are set by table_ref production */
14102 47584 : $$ = (Node *) n;
14103 : }
14104 : | ROWS FROM '(' rowsfrom_list ')' opt_ordinality
14105 : {
14106 132 : RangeFunction *n = makeNode(RangeFunction);
14107 :
14108 132 : n->lateral = false;
14109 132 : n->ordinality = $6;
14110 132 : n->is_rowsfrom = true;
14111 132 : n->functions = $4;
14112 : /* alias and coldeflist are set by table_ref production */
14113 132 : $$ = (Node *) n;
14114 : }
14115 : ;
14116 :
14117 : rowsfrom_item: func_expr_windowless opt_col_def_list
14118 318 : { $$ = list_make2($1, $2); }
14119 : ;
14120 :
14121 : rowsfrom_list:
14122 132 : rowsfrom_item { $$ = list_make1($1); }
14123 186 : | rowsfrom_list ',' rowsfrom_item { $$ = lappend($1, $3); }
14124 : ;
14125 :
14126 54 : opt_col_def_list: AS '(' TableFuncElementList ')' { $$ = $3; }
14127 264 : | /*EMPTY*/ { $$ = NIL; }
14128 : ;
14129 :
14130 920 : opt_ordinality: WITH_LA ORDINALITY { $$ = true; }
14131 46796 : | /*EMPTY*/ { $$ = false; }
14132 : ;
14133 :
14134 :
14135 : where_clause:
14136 211800 : WHERE a_expr { $$ = $2; }
14137 283950 : | /*EMPTY*/ { $$ = NULL; }
14138 : ;
14139 :
14140 : /* variant for UPDATE and DELETE */
14141 : where_or_current_clause:
14142 13640 : WHERE a_expr { $$ = $2; }
14143 : | WHERE CURRENT_P OF cursor_name
14144 : {
14145 266 : CurrentOfExpr *n = makeNode(CurrentOfExpr);
14146 :
14147 : /* cvarno is filled in by parse analysis */
14148 266 : n->cursor_name = $4;
14149 266 : n->cursor_param = 0;
14150 266 : $$ = (Node *) n;
14151 : }
14152 5082 : | /*EMPTY*/ { $$ = NULL; }
14153 : ;
14154 :
14155 :
14156 : OptTableFuncElementList:
14157 716 : TableFuncElementList { $$ = $1; }
14158 3786 : | /*EMPTY*/ { $$ = NIL; }
14159 : ;
14160 :
14161 : TableFuncElementList:
14162 : TableFuncElement
14163 : {
14164 1530 : $$ = list_make1($1);
14165 : }
14166 : | TableFuncElementList ',' TableFuncElement
14167 : {
14168 2058 : $$ = lappend($1, $3);
14169 : }
14170 : ;
14171 :
14172 : TableFuncElement: ColId Typename opt_collate_clause
14173 : {
14174 3652 : ColumnDef *n = makeNode(ColumnDef);
14175 :
14176 3652 : n->colname = $1;
14177 3652 : n->typeName = $2;
14178 3652 : n->inhcount = 0;
14179 3652 : n->is_local = true;
14180 3652 : n->is_not_null = false;
14181 3652 : n->is_from_type = false;
14182 3652 : n->storage = 0;
14183 3652 : n->raw_default = NULL;
14184 3652 : n->cooked_default = NULL;
14185 3652 : n->collClause = (CollateClause *) $3;
14186 3652 : n->collOid = InvalidOid;
14187 3652 : n->constraints = NIL;
14188 3652 : n->location = @1;
14189 3652 : $$ = (Node *) n;
14190 : }
14191 : ;
14192 :
14193 : /*
14194 : * XMLTABLE
14195 : */
14196 : xmltable:
14197 : XMLTABLE '(' c_expr xmlexists_argument COLUMNS xmltable_column_list ')'
14198 : {
14199 206 : RangeTableFunc *n = makeNode(RangeTableFunc);
14200 :
14201 206 : n->rowexpr = $3;
14202 206 : n->docexpr = $4;
14203 206 : n->columns = $6;
14204 206 : n->namespaces = NIL;
14205 206 : n->location = @1;
14206 206 : $$ = (Node *) n;
14207 : }
14208 : | XMLTABLE '(' XMLNAMESPACES '(' xml_namespace_list ')' ','
14209 : c_expr xmlexists_argument COLUMNS xmltable_column_list ')'
14210 : {
14211 20 : RangeTableFunc *n = makeNode(RangeTableFunc);
14212 :
14213 20 : n->rowexpr = $8;
14214 20 : n->docexpr = $9;
14215 20 : n->columns = $11;
14216 20 : n->namespaces = $5;
14217 20 : n->location = @1;
14218 20 : $$ = (Node *) n;
14219 : }
14220 : ;
14221 :
14222 226 : xmltable_column_list: xmltable_column_el { $$ = list_make1($1); }
14223 530 : | xmltable_column_list ',' xmltable_column_el { $$ = lappend($1, $3); }
14224 : ;
14225 :
14226 : xmltable_column_el:
14227 : ColId Typename
14228 : {
14229 204 : RangeTableFuncCol *fc = makeNode(RangeTableFuncCol);
14230 :
14231 204 : fc->colname = $1;
14232 204 : fc->for_ordinality = false;
14233 204 : fc->typeName = $2;
14234 204 : fc->is_not_null = false;
14235 204 : fc->colexpr = NULL;
14236 204 : fc->coldefexpr = NULL;
14237 204 : fc->location = @1;
14238 :
14239 204 : $$ = (Node *) fc;
14240 : }
14241 : | ColId Typename xmltable_column_option_list
14242 : {
14243 490 : RangeTableFuncCol *fc = makeNode(RangeTableFuncCol);
14244 : ListCell *option;
14245 490 : bool nullability_seen = false;
14246 :
14247 490 : fc->colname = $1;
14248 490 : fc->typeName = $2;
14249 490 : fc->for_ordinality = false;
14250 490 : fc->is_not_null = false;
14251 490 : fc->colexpr = NULL;
14252 490 : fc->coldefexpr = NULL;
14253 490 : fc->location = @1;
14254 :
14255 1092 : foreach(option, $3)
14256 : {
14257 602 : DefElem *defel = (DefElem *) lfirst(option);
14258 :
14259 602 : if (strcmp(defel->defname, "default") == 0)
14260 : {
14261 56 : if (fc->coldefexpr != NULL)
14262 0 : ereport(ERROR,
14263 : (errcode(ERRCODE_SYNTAX_ERROR),
14264 : errmsg("only one DEFAULT value is allowed"),
14265 : parser_errposition(defel->location)));
14266 56 : fc->coldefexpr = defel->arg;
14267 : }
14268 546 : else if (strcmp(defel->defname, "path") == 0)
14269 : {
14270 490 : if (fc->colexpr != NULL)
14271 0 : ereport(ERROR,
14272 : (errcode(ERRCODE_SYNTAX_ERROR),
14273 : errmsg("only one PATH value per column is allowed"),
14274 : parser_errposition(defel->location)));
14275 490 : fc->colexpr = defel->arg;
14276 : }
14277 56 : else if (strcmp(defel->defname, "__pg__is_not_null") == 0)
14278 : {
14279 56 : if (nullability_seen)
14280 0 : ereport(ERROR,
14281 : (errcode(ERRCODE_SYNTAX_ERROR),
14282 : errmsg("conflicting or redundant NULL / NOT NULL declarations for column \"%s\"", fc->colname),
14283 : parser_errposition(defel->location)));
14284 56 : fc->is_not_null = boolVal(defel->arg);
14285 56 : nullability_seen = true;
14286 : }
14287 : else
14288 : {
14289 0 : ereport(ERROR,
14290 : (errcode(ERRCODE_SYNTAX_ERROR),
14291 : errmsg("unrecognized column option \"%s\"",
14292 : defel->defname),
14293 : parser_errposition(defel->location)));
14294 : }
14295 : }
14296 490 : $$ = (Node *) fc;
14297 : }
14298 : | ColId FOR ORDINALITY
14299 : {
14300 62 : RangeTableFuncCol *fc = makeNode(RangeTableFuncCol);
14301 :
14302 62 : fc->colname = $1;
14303 62 : fc->for_ordinality = true;
14304 : /* other fields are ignored, initialized by makeNode */
14305 62 : fc->location = @1;
14306 :
14307 62 : $$ = (Node *) fc;
14308 : }
14309 : ;
14310 :
14311 : xmltable_column_option_list:
14312 : xmltable_column_option_el
14313 490 : { $$ = list_make1($1); }
14314 : | xmltable_column_option_list xmltable_column_option_el
14315 112 : { $$ = lappend($1, $2); }
14316 : ;
14317 :
14318 : xmltable_column_option_el:
14319 : IDENT b_expr
14320 : {
14321 6 : if (strcmp($1, "__pg__is_not_null") == 0)
14322 6 : ereport(ERROR,
14323 : (errcode(ERRCODE_SYNTAX_ERROR),
14324 : errmsg("option name \"%s\" cannot be used in XMLTABLE", $1),
14325 : parser_errposition(@1)));
14326 0 : $$ = makeDefElem($1, $2, @1);
14327 : }
14328 : | DEFAULT b_expr
14329 56 : { $$ = makeDefElem("default", $2, @1); }
14330 : | NOT NULL_P
14331 56 : { $$ = makeDefElem("__pg__is_not_null", (Node *) makeBoolean(true), @1); }
14332 : | NULL_P
14333 0 : { $$ = makeDefElem("__pg__is_not_null", (Node *) makeBoolean(false), @1); }
14334 : | PATH b_expr
14335 490 : { $$ = makeDefElem("path", $2, @1); }
14336 : ;
14337 :
14338 : xml_namespace_list:
14339 : xml_namespace_el
14340 20 : { $$ = list_make1($1); }
14341 : | xml_namespace_list ',' xml_namespace_el
14342 0 : { $$ = lappend($1, $3); }
14343 : ;
14344 :
14345 : xml_namespace_el:
14346 : b_expr AS ColLabel
14347 : {
14348 14 : $$ = makeNode(ResTarget);
14349 14 : $$->name = $3;
14350 14 : $$->indirection = NIL;
14351 14 : $$->val = $1;
14352 14 : $$->location = @1;
14353 : }
14354 : | DEFAULT b_expr
14355 : {
14356 6 : $$ = makeNode(ResTarget);
14357 6 : $$->name = NULL;
14358 6 : $$->indirection = NIL;
14359 6 : $$->val = $2;
14360 6 : $$->location = @1;
14361 : }
14362 : ;
14363 :
14364 : json_table:
14365 : JSON_TABLE '('
14366 : json_value_expr ',' a_expr json_table_path_name_opt
14367 : json_passing_clause_opt
14368 : COLUMNS '(' json_table_column_definition_list ')'
14369 : json_on_error_clause_opt
14370 : ')'
14371 : {
14372 536 : JsonTable *n = makeNode(JsonTable);
14373 : char *pathstring;
14374 :
14375 536 : n->context_item = (JsonValueExpr *) $3;
14376 536 : if (!IsA($5, A_Const) ||
14377 530 : castNode(A_Const, $5)->val.node.type != T_String)
14378 6 : ereport(ERROR,
14379 : errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
14380 : errmsg("only string constants are supported in JSON_TABLE path specification"),
14381 : parser_errposition(@5));
14382 530 : pathstring = castNode(A_Const, $5)->val.sval.sval;
14383 530 : n->pathspec = makeJsonTablePathSpec(pathstring, $6, @5, @6);
14384 530 : n->passing = $7;
14385 530 : n->columns = $10;
14386 530 : n->on_error = (JsonBehavior *) $12;
14387 530 : n->location = @1;
14388 530 : $$ = (Node *) n;
14389 : }
14390 : ;
14391 :
14392 : json_table_path_name_opt:
14393 62 : AS name { $$ = $2; }
14394 486 : | /* empty */ { $$ = NULL; }
14395 : ;
14396 :
14397 : json_table_column_definition_list:
14398 : json_table_column_definition
14399 826 : { $$ = list_make1($1); }
14400 : | json_table_column_definition_list ',' json_table_column_definition
14401 528 : { $$ = lappend($1, $3); }
14402 : ;
14403 :
14404 : json_table_column_definition:
14405 : ColId FOR ORDINALITY
14406 : {
14407 84 : JsonTableColumn *n = makeNode(JsonTableColumn);
14408 :
14409 84 : n->coltype = JTC_FOR_ORDINALITY;
14410 84 : n->name = $1;
14411 84 : n->location = @1;
14412 84 : $$ = (Node *) n;
14413 : }
14414 : | ColId Typename
14415 : json_table_column_path_clause_opt
14416 : json_wrapper_behavior
14417 : json_quotes_clause_opt
14418 : json_behavior_clause_opt
14419 : {
14420 734 : JsonTableColumn *n = makeNode(JsonTableColumn);
14421 :
14422 734 : n->coltype = JTC_REGULAR;
14423 734 : n->name = $1;
14424 734 : n->typeName = $2;
14425 734 : n->format = makeJsonFormat(JS_FORMAT_DEFAULT, JS_ENC_DEFAULT, -1);
14426 734 : n->pathspec = (JsonTablePathSpec *) $3;
14427 734 : n->wrapper = $4;
14428 734 : n->quotes = $5;
14429 734 : n->on_empty = (JsonBehavior *) linitial($6);
14430 734 : n->on_error = (JsonBehavior *) lsecond($6);
14431 734 : n->location = @1;
14432 734 : $$ = (Node *) n;
14433 : }
14434 : | ColId Typename json_format_clause
14435 : json_table_column_path_clause_opt
14436 : json_wrapper_behavior
14437 : json_quotes_clause_opt
14438 : json_behavior_clause_opt
14439 : {
14440 108 : JsonTableColumn *n = makeNode(JsonTableColumn);
14441 :
14442 108 : n->coltype = JTC_FORMATTED;
14443 108 : n->name = $1;
14444 108 : n->typeName = $2;
14445 108 : n->format = (JsonFormat *) $3;
14446 108 : n->pathspec = (JsonTablePathSpec *) $4;
14447 108 : n->wrapper = $5;
14448 108 : n->quotes = $6;
14449 108 : n->on_empty = (JsonBehavior *) linitial($7);
14450 108 : n->on_error = (JsonBehavior *) lsecond($7);
14451 108 : n->location = @1;
14452 108 : $$ = (Node *) n;
14453 : }
14454 : | ColId Typename
14455 : EXISTS json_table_column_path_clause_opt
14456 : json_on_error_clause_opt
14457 : {
14458 138 : JsonTableColumn *n = makeNode(JsonTableColumn);
14459 :
14460 138 : n->coltype = JTC_EXISTS;
14461 138 : n->name = $1;
14462 138 : n->typeName = $2;
14463 138 : n->format = makeJsonFormat(JS_FORMAT_DEFAULT, JS_ENC_DEFAULT, -1);
14464 138 : n->wrapper = JSW_NONE;
14465 138 : n->quotes = JS_QUOTES_UNSPEC;
14466 138 : n->pathspec = (JsonTablePathSpec *) $4;
14467 138 : n->on_empty = NULL;
14468 138 : n->on_error = (JsonBehavior *) $5;
14469 138 : n->location = @1;
14470 138 : $$ = (Node *) n;
14471 : }
14472 : | NESTED path_opt Sconst
14473 : COLUMNS '(' json_table_column_definition_list ')'
14474 : {
14475 144 : JsonTableColumn *n = makeNode(JsonTableColumn);
14476 :
14477 144 : n->coltype = JTC_NESTED;
14478 288 : n->pathspec = (JsonTablePathSpec *)
14479 144 : makeJsonTablePathSpec($3, NULL, @3, -1);
14480 144 : n->columns = $6;
14481 144 : n->location = @1;
14482 144 : $$ = (Node *) n;
14483 : }
14484 : | NESTED path_opt Sconst AS name
14485 : COLUMNS '(' json_table_column_definition_list ')'
14486 : {
14487 146 : JsonTableColumn *n = makeNode(JsonTableColumn);
14488 :
14489 146 : n->coltype = JTC_NESTED;
14490 292 : n->pathspec = (JsonTablePathSpec *)
14491 146 : makeJsonTablePathSpec($3, $5, @3, @5);
14492 146 : n->columns = $8;
14493 146 : n->location = @1;
14494 146 : $$ = (Node *) n;
14495 : }
14496 : ;
14497 :
14498 : path_opt:
14499 : PATH
14500 : | /* EMPTY */
14501 : ;
14502 :
14503 : json_table_column_path_clause_opt:
14504 : PATH Sconst
14505 828 : { $$ = (Node *) makeJsonTablePathSpec($2, NULL, @2, -1); }
14506 : | /* EMPTY */
14507 158 : { $$ = NULL; }
14508 : ;
14509 :
14510 : /*****************************************************************************
14511 : *
14512 : * Type syntax
14513 : * SQL introduces a large amount of type-specific syntax.
14514 : * Define individual clauses to handle these cases, and use
14515 : * the generic case to handle regular type-extensible Postgres syntax.
14516 : * - thomas 1997-10-10
14517 : *
14518 : *****************************************************************************/
14519 :
14520 : Typename: SimpleTypename opt_array_bounds
14521 : {
14522 522038 : $$ = $1;
14523 522038 : $$->arrayBounds = $2;
14524 : }
14525 : | SETOF SimpleTypename opt_array_bounds
14526 : {
14527 2358 : $$ = $2;
14528 2358 : $$->arrayBounds = $3;
14529 2358 : $$->setof = true;
14530 : }
14531 : /* SQL standard syntax, currently only one-dimensional */
14532 : | SimpleTypename ARRAY '[' Iconst ']'
14533 : {
14534 6 : $$ = $1;
14535 6 : $$->arrayBounds = list_make1(makeInteger($4));
14536 : }
14537 : | SETOF SimpleTypename ARRAY '[' Iconst ']'
14538 : {
14539 0 : $$ = $2;
14540 0 : $$->arrayBounds = list_make1(makeInteger($5));
14541 0 : $$->setof = true;
14542 : }
14543 : | SimpleTypename ARRAY
14544 : {
14545 0 : $$ = $1;
14546 0 : $$->arrayBounds = list_make1(makeInteger(-1));
14547 : }
14548 : | SETOF SimpleTypename ARRAY
14549 : {
14550 0 : $$ = $2;
14551 0 : $$->arrayBounds = list_make1(makeInteger(-1));
14552 0 : $$->setof = true;
14553 : }
14554 : ;
14555 :
14556 : opt_array_bounds:
14557 : opt_array_bounds '[' ']'
14558 14612 : { $$ = lappend($1, makeInteger(-1)); }
14559 : | opt_array_bounds '[' Iconst ']'
14560 62 : { $$ = lappend($1, makeInteger($3)); }
14561 : | /*EMPTY*/
14562 524396 : { $$ = NIL; }
14563 : ;
14564 :
14565 : SimpleTypename:
14566 410734 : GenericType { $$ = $1; }
14567 97928 : | Numeric { $$ = $1; }
14568 1972 : | Bit { $$ = $1; }
14569 3014 : | Character { $$ = $1; }
14570 5406 : | ConstDatetime { $$ = $1; }
14571 : | ConstInterval opt_interval
14572 : {
14573 3866 : $$ = $1;
14574 3866 : $$->typmods = $2;
14575 : }
14576 : | ConstInterval '(' Iconst ')'
14577 : {
14578 0 : $$ = $1;
14579 0 : $$->typmods = list_make2(makeIntConst(INTERVAL_FULL_RANGE, -1),
14580 : makeIntConst($3, @3));
14581 : }
14582 1890 : | JsonType { $$ = $1; }
14583 : ;
14584 :
14585 : /* We have a separate ConstTypename to allow defaulting fixed-length
14586 : * types such as CHAR() and BIT() to an unspecified length.
14587 : * SQL9x requires that these default to a length of one, but this
14588 : * makes no sense for constructs like CHAR 'hi' and BIT '0101',
14589 : * where there is an obvious better choice to make.
14590 : * Note that ConstInterval is not included here since it must
14591 : * be pushed up higher in the rules to accommodate the postfix
14592 : * options (e.g. INTERVAL '1' YEAR). Likewise, we have to handle
14593 : * the generic-type-name case in AexprConst to avoid premature
14594 : * reduce/reduce conflicts against function names.
14595 : */
14596 : ConstTypename:
14597 78 : Numeric { $$ = $1; }
14598 0 : | ConstBit { $$ = $1; }
14599 34 : | ConstCharacter { $$ = $1; }
14600 2798 : | ConstDatetime { $$ = $1; }
14601 264 : | JsonType { $$ = $1; }
14602 : ;
14603 :
14604 : /*
14605 : * GenericType covers all type names that don't have special syntax mandated
14606 : * by the standard, including qualified names. We also allow type modifiers.
14607 : * To avoid parsing conflicts against function invocations, the modifiers
14608 : * have to be shown as expr_list here, but parse analysis will only accept
14609 : * constants for them.
14610 : */
14611 : GenericType:
14612 : type_function_name opt_type_modifiers
14613 : {
14614 292884 : $$ = makeTypeName($1);
14615 292884 : $$->typmods = $2;
14616 292884 : $$->location = @1;
14617 : }
14618 : | type_function_name attrs opt_type_modifiers
14619 : {
14620 117850 : $$ = makeTypeNameFromNameList(lcons(makeString($1), $2));
14621 117850 : $$->typmods = $3;
14622 117850 : $$->location = @1;
14623 : }
14624 : ;
14625 :
14626 1350 : opt_type_modifiers: '(' expr_list ')' { $$ = $2; }
14627 415652 : | /* EMPTY */ { $$ = NIL; }
14628 : ;
14629 :
14630 : /*
14631 : * SQL numeric data types
14632 : */
14633 : Numeric: INT_P
14634 : {
14635 38862 : $$ = SystemTypeName("int4");
14636 38862 : $$->location = @1;
14637 : }
14638 : | INTEGER
14639 : {
14640 25364 : $$ = SystemTypeName("int4");
14641 25364 : $$->location = @1;
14642 : }
14643 : | SMALLINT
14644 : {
14645 1422 : $$ = SystemTypeName("int2");
14646 1422 : $$->location = @1;
14647 : }
14648 : | BIGINT
14649 : {
14650 5172 : $$ = SystemTypeName("int8");
14651 5172 : $$->location = @1;
14652 : }
14653 : | REAL
14654 : {
14655 6936 : $$ = SystemTypeName("float4");
14656 6936 : $$->location = @1;
14657 : }
14658 : | FLOAT_P opt_float
14659 : {
14660 538 : $$ = $2;
14661 538 : $$->location = @1;
14662 : }
14663 : | DOUBLE_P PRECISION
14664 : {
14665 766 : $$ = SystemTypeName("float8");
14666 766 : $$->location = @1;
14667 : }
14668 : | DECIMAL_P opt_type_modifiers
14669 : {
14670 36 : $$ = SystemTypeName("numeric");
14671 36 : $$->typmods = $2;
14672 36 : $$->location = @1;
14673 : }
14674 : | DEC opt_type_modifiers
14675 : {
14676 0 : $$ = SystemTypeName("numeric");
14677 0 : $$->typmods = $2;
14678 0 : $$->location = @1;
14679 : }
14680 : | NUMERIC opt_type_modifiers
14681 : {
14682 6232 : $$ = SystemTypeName("numeric");
14683 6232 : $$->typmods = $2;
14684 6232 : $$->location = @1;
14685 : }
14686 : | BOOLEAN_P
14687 : {
14688 12678 : $$ = SystemTypeName("bool");
14689 12678 : $$->location = @1;
14690 : }
14691 : ;
14692 :
14693 : opt_float: '(' Iconst ')'
14694 : {
14695 : /*
14696 : * Check FLOAT() precision limits assuming IEEE floating
14697 : * types - thomas 1997-09-18
14698 : */
14699 2 : if ($2 < 1)
14700 0 : ereport(ERROR,
14701 : (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
14702 : errmsg("precision for type float must be at least 1 bit"),
14703 : parser_errposition(@2)));
14704 2 : else if ($2 <= 24)
14705 2 : $$ = SystemTypeName("float4");
14706 0 : else if ($2 <= 53)
14707 0 : $$ = SystemTypeName("float8");
14708 : else
14709 0 : ereport(ERROR,
14710 : (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
14711 : errmsg("precision for type float must be less than 54 bits"),
14712 : parser_errposition(@2)));
14713 : }
14714 : | /*EMPTY*/
14715 : {
14716 536 : $$ = SystemTypeName("float8");
14717 : }
14718 : ;
14719 :
14720 : /*
14721 : * SQL bit-field data types
14722 : * The following implements BIT() and BIT VARYING().
14723 : */
14724 : Bit: BitWithLength
14725 : {
14726 1696 : $$ = $1;
14727 : }
14728 : | BitWithoutLength
14729 : {
14730 276 : $$ = $1;
14731 : }
14732 : ;
14733 :
14734 : /* ConstBit is like Bit except "BIT" defaults to unspecified length */
14735 : /* See notes for ConstCharacter, which addresses same issue for "CHAR" */
14736 : ConstBit: BitWithLength
14737 : {
14738 0 : $$ = $1;
14739 : }
14740 : | BitWithoutLength
14741 : {
14742 0 : $$ = $1;
14743 0 : $$->typmods = NIL;
14744 : }
14745 : ;
14746 :
14747 : BitWithLength:
14748 : BIT opt_varying '(' expr_list ')'
14749 : {
14750 : char *typname;
14751 :
14752 1696 : typname = $2 ? "varbit" : "bit";
14753 1696 : $$ = SystemTypeName(typname);
14754 1696 : $$->typmods = $4;
14755 1696 : $$->location = @1;
14756 : }
14757 : ;
14758 :
14759 : BitWithoutLength:
14760 : BIT opt_varying
14761 : {
14762 : /* bit defaults to bit(1), varbit to no limit */
14763 276 : if ($2)
14764 : {
14765 20 : $$ = SystemTypeName("varbit");
14766 : }
14767 : else
14768 : {
14769 256 : $$ = SystemTypeName("bit");
14770 256 : $$->typmods = list_make1(makeIntConst(1, -1));
14771 : }
14772 276 : $$->location = @1;
14773 : }
14774 : ;
14775 :
14776 :
14777 : /*
14778 : * SQL character data types
14779 : * The following implements CHAR() and VARCHAR().
14780 : */
14781 : Character: CharacterWithLength
14782 : {
14783 1724 : $$ = $1;
14784 : }
14785 : | CharacterWithoutLength
14786 : {
14787 1290 : $$ = $1;
14788 : }
14789 : ;
14790 :
14791 : ConstCharacter: CharacterWithLength
14792 : {
14793 12 : $$ = $1;
14794 : }
14795 : | CharacterWithoutLength
14796 : {
14797 : /* Length was not specified so allow to be unrestricted.
14798 : * This handles problems with fixed-length (bpchar) strings
14799 : * which in column definitions must default to a length
14800 : * of one, but should not be constrained if the length
14801 : * was not specified.
14802 : */
14803 22 : $$ = $1;
14804 22 : $$->typmods = NIL;
14805 : }
14806 : ;
14807 :
14808 : CharacterWithLength: character '(' Iconst ')'
14809 : {
14810 1736 : $$ = SystemTypeName($1);
14811 1736 : $$->typmods = list_make1(makeIntConst($3, @3));
14812 1736 : $$->location = @1;
14813 : }
14814 : ;
14815 :
14816 : CharacterWithoutLength: character
14817 : {
14818 1312 : $$ = SystemTypeName($1);
14819 : /* char defaults to char(1), varchar to no limit */
14820 1312 : if (strcmp($1, "bpchar") == 0)
14821 256 : $$->typmods = list_make1(makeIntConst(1, -1));
14822 1312 : $$->location = @1;
14823 : }
14824 : ;
14825 :
14826 : character: CHARACTER opt_varying
14827 566 : { $$ = $2 ? "varchar": "bpchar"; }
14828 : | CHAR_P opt_varying
14829 1172 : { $$ = $2 ? "varchar": "bpchar"; }
14830 : | VARCHAR
14831 1306 : { $$ = "varchar"; }
14832 : | NATIONAL CHARACTER opt_varying
14833 0 : { $$ = $3 ? "varchar": "bpchar"; }
14834 : | NATIONAL CHAR_P opt_varying
14835 0 : { $$ = $3 ? "varchar": "bpchar"; }
14836 : | NCHAR opt_varying
14837 4 : { $$ = $2 ? "varchar": "bpchar"; }
14838 : ;
14839 :
14840 : opt_varying:
14841 458 : VARYING { $$ = true; }
14842 3256 : | /*EMPTY*/ { $$ = false; }
14843 : ;
14844 :
14845 : /*
14846 : * SQL date/time types
14847 : */
14848 : ConstDatetime:
14849 : TIMESTAMP '(' Iconst ')' opt_timezone
14850 : {
14851 134 : if ($5)
14852 110 : $$ = SystemTypeName("timestamptz");
14853 : else
14854 24 : $$ = SystemTypeName("timestamp");
14855 134 : $$->typmods = list_make1(makeIntConst($3, @3));
14856 134 : $$->location = @1;
14857 : }
14858 : | TIMESTAMP opt_timezone
14859 : {
14860 5456 : if ($2)
14861 1456 : $$ = SystemTypeName("timestamptz");
14862 : else
14863 4000 : $$ = SystemTypeName("timestamp");
14864 5456 : $$->location = @1;
14865 : }
14866 : | TIME '(' Iconst ')' opt_timezone
14867 : {
14868 22 : if ($5)
14869 8 : $$ = SystemTypeName("timetz");
14870 : else
14871 14 : $$ = SystemTypeName("time");
14872 22 : $$->typmods = list_make1(makeIntConst($3, @3));
14873 22 : $$->location = @1;
14874 : }
14875 : | TIME opt_timezone
14876 : {
14877 2592 : if ($2)
14878 348 : $$ = SystemTypeName("timetz");
14879 : else
14880 2244 : $$ = SystemTypeName("time");
14881 2592 : $$->location = @1;
14882 : }
14883 : ;
14884 :
14885 : ConstInterval:
14886 : INTERVAL
14887 : {
14888 7176 : $$ = SystemTypeName("interval");
14889 7176 : $$->location = @1;
14890 : }
14891 : ;
14892 :
14893 : opt_timezone:
14894 1922 : WITH_LA TIME ZONE { $$ = true; }
14895 624 : | WITHOUT_LA TIME ZONE { $$ = false; }
14896 5658 : | /*EMPTY*/ { $$ = false; }
14897 : ;
14898 :
14899 : opt_interval:
14900 : YEAR_P
14901 12 : { $$ = list_make1(makeIntConst(INTERVAL_MASK(YEAR), @1)); }
14902 : | MONTH_P
14903 18 : { $$ = list_make1(makeIntConst(INTERVAL_MASK(MONTH), @1)); }
14904 : | DAY_P
14905 18 : { $$ = list_make1(makeIntConst(INTERVAL_MASK(DAY), @1)); }
14906 : | HOUR_P
14907 12 : { $$ = list_make1(makeIntConst(INTERVAL_MASK(HOUR), @1)); }
14908 : | MINUTE_P
14909 12 : { $$ = list_make1(makeIntConst(INTERVAL_MASK(MINUTE), @1)); }
14910 : | interval_second
14911 36 : { $$ = $1; }
14912 : | YEAR_P TO MONTH_P
14913 : {
14914 18 : $$ = list_make1(makeIntConst(INTERVAL_MASK(YEAR) |
14915 : INTERVAL_MASK(MONTH), @1));
14916 : }
14917 : | DAY_P TO HOUR_P
14918 : {
14919 24 : $$ = list_make1(makeIntConst(INTERVAL_MASK(DAY) |
14920 : INTERVAL_MASK(HOUR), @1));
14921 : }
14922 : | DAY_P TO MINUTE_P
14923 : {
14924 24 : $$ = list_make1(makeIntConst(INTERVAL_MASK(DAY) |
14925 : INTERVAL_MASK(HOUR) |
14926 : INTERVAL_MASK(MINUTE), @1));
14927 : }
14928 : | DAY_P TO interval_second
14929 : {
14930 48 : $$ = $3;
14931 48 : linitial($$) = makeIntConst(INTERVAL_MASK(DAY) |
14932 : INTERVAL_MASK(HOUR) |
14933 : INTERVAL_MASK(MINUTE) |
14934 48 : INTERVAL_MASK(SECOND), @1);
14935 : }
14936 : | HOUR_P TO MINUTE_P
14937 : {
14938 18 : $$ = list_make1(makeIntConst(INTERVAL_MASK(HOUR) |
14939 : INTERVAL_MASK(MINUTE), @1));
14940 : }
14941 : | HOUR_P TO interval_second
14942 : {
14943 36 : $$ = $3;
14944 36 : linitial($$) = makeIntConst(INTERVAL_MASK(HOUR) |
14945 : INTERVAL_MASK(MINUTE) |
14946 36 : INTERVAL_MASK(SECOND), @1);
14947 : }
14948 : | MINUTE_P TO interval_second
14949 : {
14950 66 : $$ = $3;
14951 66 : linitial($$) = makeIntConst(INTERVAL_MASK(MINUTE) |
14952 66 : INTERVAL_MASK(SECOND), @1);
14953 : }
14954 : | /*EMPTY*/
14955 6822 : { $$ = NIL; }
14956 : ;
14957 :
14958 : interval_second:
14959 : SECOND_P
14960 : {
14961 102 : $$ = list_make1(makeIntConst(INTERVAL_MASK(SECOND), @1));
14962 : }
14963 : | SECOND_P '(' Iconst ')'
14964 : {
14965 84 : $$ = list_make2(makeIntConst(INTERVAL_MASK(SECOND), @1),
14966 : makeIntConst($3, @3));
14967 : }
14968 : ;
14969 :
14970 : JsonType:
14971 : JSON
14972 : {
14973 2154 : $$ = SystemTypeName("json");
14974 2154 : $$->location = @1;
14975 : }
14976 : ;
14977 :
14978 : /*****************************************************************************
14979 : *
14980 : * expression grammar
14981 : *
14982 : *****************************************************************************/
14983 :
14984 : /*
14985 : * General expressions
14986 : * This is the heart of the expression syntax.
14987 : *
14988 : * We have two expression types: a_expr is the unrestricted kind, and
14989 : * b_expr is a subset that must be used in some places to avoid shift/reduce
14990 : * conflicts. For example, we can't do BETWEEN as "BETWEEN a_expr AND a_expr"
14991 : * because that use of AND conflicts with AND as a boolean operator. So,
14992 : * b_expr is used in BETWEEN and we remove boolean keywords from b_expr.
14993 : *
14994 : * Note that '(' a_expr ')' is a b_expr, so an unrestricted expression can
14995 : * always be used by surrounding it with parens.
14996 : *
14997 : * c_expr is all the productions that are common to a_expr and b_expr;
14998 : * it's factored out just to eliminate redundant coding.
14999 : *
15000 : * Be careful of productions involving more than one terminal token.
15001 : * By default, bison will assign such productions the precedence of their
15002 : * last terminal, but in nearly all cases you want it to be the precedence
15003 : * of the first terminal instead; otherwise you will not get the behavior
15004 : * you expect! So we use %prec annotations freely to set precedences.
15005 : */
15006 3662646 : a_expr: c_expr { $$ = $1; }
15007 : | a_expr TYPECAST Typename
15008 235848 : { $$ = makeTypeCast($1, $3, @2); }
15009 : | a_expr COLLATE any_name
15010 : {
15011 9018 : CollateClause *n = makeNode(CollateClause);
15012 :
15013 9018 : n->arg = $1;
15014 9018 : n->collname = $3;
15015 9018 : n->location = @2;
15016 9018 : $$ = (Node *) n;
15017 : }
15018 : | a_expr AT TIME ZONE a_expr %prec AT
15019 : {
15020 408 : $$ = (Node *) makeFuncCall(SystemFuncName("timezone"),
15021 408 : list_make2($5, $1),
15022 : COERCE_SQL_SYNTAX,
15023 408 : @2);
15024 : }
15025 : | a_expr AT LOCAL %prec AT
15026 : {
15027 42 : $$ = (Node *) makeFuncCall(SystemFuncName("timezone"),
15028 42 : list_make1($1),
15029 : COERCE_SQL_SYNTAX,
15030 : -1);
15031 : }
15032 : /*
15033 : * These operators must be called out explicitly in order to make use
15034 : * of bison's automatic operator-precedence handling. All other
15035 : * operator names are handled by the generic productions using "Op",
15036 : * below; and all those operators will have the same precedence.
15037 : *
15038 : * If you add more explicitly-known operators, be sure to add them
15039 : * also to b_expr and to the MathOp list below.
15040 : */
15041 : | '+' a_expr %prec UMINUS
15042 12 : { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "+", NULL, $2, @1); }
15043 : | '-' a_expr %prec UMINUS
15044 9192 : { $$ = doNegate($2, @1); }
15045 : | a_expr '+' a_expr
15046 14296 : { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "+", $1, $3, @2); }
15047 : | a_expr '-' a_expr
15048 4526 : { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "-", $1, $3, @2); }
15049 : | a_expr '*' a_expr
15050 6346 : { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "*", $1, $3, @2); }
15051 : | a_expr '/' a_expr
15052 3472 : { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "/", $1, $3, @2); }
15053 : | a_expr '%' a_expr
15054 2892 : { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "%", $1, $3, @2); }
15055 : | a_expr '^' a_expr
15056 476 : { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "^", $1, $3, @2); }
15057 : | a_expr '<' a_expr
15058 10616 : { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "<", $1, $3, @2); }
15059 : | a_expr '>' a_expr
15060 16660 : { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, ">", $1, $3, @2); }
15061 : | a_expr '=' a_expr
15062 389956 : { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "=", $1, $3, @2); }
15063 : | a_expr LESS_EQUALS a_expr
15064 5338 : { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "<=", $1, $3, @2); }
15065 : | a_expr GREATER_EQUALS a_expr
15066 7146 : { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, ">=", $1, $3, @2); }
15067 : | a_expr NOT_EQUALS a_expr
15068 39746 : { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "<>", $1, $3, @2); }
15069 :
15070 : | a_expr qual_Op a_expr %prec Op
15071 59178 : { $$ = (Node *) makeA_Expr(AEXPR_OP, $2, $1, $3, @2); }
15072 : | qual_Op a_expr %prec Op
15073 246 : { $$ = (Node *) makeA_Expr(AEXPR_OP, $1, NULL, $2, @1); }
15074 :
15075 : | a_expr AND a_expr
15076 232810 : { $$ = makeAndExpr($1, $3, @2); }
15077 : | a_expr OR a_expr
15078 16038 : { $$ = makeOrExpr($1, $3, @2); }
15079 : | NOT a_expr
15080 16112 : { $$ = makeNotExpr($2, @1); }
15081 : | NOT_LA a_expr %prec NOT
15082 0 : { $$ = makeNotExpr($2, @1); }
15083 :
15084 : | a_expr LIKE a_expr
15085 : {
15086 1966 : $$ = (Node *) makeSimpleA_Expr(AEXPR_LIKE, "~~",
15087 1966 : $1, $3, @2);
15088 : }
15089 : | a_expr LIKE a_expr ESCAPE a_expr %prec LIKE
15090 : {
15091 96 : FuncCall *n = makeFuncCall(SystemFuncName("like_escape"),
15092 96 : list_make2($3, $5),
15093 : COERCE_EXPLICIT_CALL,
15094 96 : @2);
15095 96 : $$ = (Node *) makeSimpleA_Expr(AEXPR_LIKE, "~~",
15096 96 : $1, (Node *) n, @2);
15097 : }
15098 : | a_expr NOT_LA LIKE a_expr %prec NOT_LA
15099 : {
15100 198 : $$ = (Node *) makeSimpleA_Expr(AEXPR_LIKE, "!~~",
15101 198 : $1, $4, @2);
15102 : }
15103 : | a_expr NOT_LA LIKE a_expr ESCAPE a_expr %prec NOT_LA
15104 : {
15105 96 : FuncCall *n = makeFuncCall(SystemFuncName("like_escape"),
15106 96 : list_make2($4, $6),
15107 : COERCE_EXPLICIT_CALL,
15108 96 : @2);
15109 96 : $$ = (Node *) makeSimpleA_Expr(AEXPR_LIKE, "!~~",
15110 96 : $1, (Node *) n, @2);
15111 : }
15112 : | a_expr ILIKE a_expr
15113 : {
15114 172 : $$ = (Node *) makeSimpleA_Expr(AEXPR_ILIKE, "~~*",
15115 172 : $1, $3, @2);
15116 : }
15117 : | a_expr ILIKE a_expr ESCAPE a_expr %prec ILIKE
15118 : {
15119 0 : FuncCall *n = makeFuncCall(SystemFuncName("like_escape"),
15120 0 : list_make2($3, $5),
15121 : COERCE_EXPLICIT_CALL,
15122 0 : @2);
15123 0 : $$ = (Node *) makeSimpleA_Expr(AEXPR_ILIKE, "~~*",
15124 0 : $1, (Node *) n, @2);
15125 : }
15126 : | a_expr NOT_LA ILIKE a_expr %prec NOT_LA
15127 : {
15128 30 : $$ = (Node *) makeSimpleA_Expr(AEXPR_ILIKE, "!~~*",
15129 30 : $1, $4, @2);
15130 : }
15131 : | a_expr NOT_LA ILIKE a_expr ESCAPE a_expr %prec NOT_LA
15132 : {
15133 0 : FuncCall *n = makeFuncCall(SystemFuncName("like_escape"),
15134 0 : list_make2($4, $6),
15135 : COERCE_EXPLICIT_CALL,
15136 0 : @2);
15137 0 : $$ = (Node *) makeSimpleA_Expr(AEXPR_ILIKE, "!~~*",
15138 0 : $1, (Node *) n, @2);
15139 : }
15140 :
15141 : | a_expr SIMILAR TO a_expr %prec SIMILAR
15142 : {
15143 88 : FuncCall *n = makeFuncCall(SystemFuncName("similar_to_escape"),
15144 88 : list_make1($4),
15145 : COERCE_EXPLICIT_CALL,
15146 88 : @2);
15147 88 : $$ = (Node *) makeSimpleA_Expr(AEXPR_SIMILAR, "~",
15148 88 : $1, (Node *) n, @2);
15149 : }
15150 : | a_expr SIMILAR TO a_expr ESCAPE a_expr %prec SIMILAR
15151 : {
15152 36 : FuncCall *n = makeFuncCall(SystemFuncName("similar_to_escape"),
15153 36 : list_make2($4, $6),
15154 : COERCE_EXPLICIT_CALL,
15155 36 : @2);
15156 36 : $$ = (Node *) makeSimpleA_Expr(AEXPR_SIMILAR, "~",
15157 36 : $1, (Node *) n, @2);
15158 : }
15159 : | a_expr NOT_LA SIMILAR TO a_expr %prec NOT_LA
15160 : {
15161 0 : FuncCall *n = makeFuncCall(SystemFuncName("similar_to_escape"),
15162 0 : list_make1($5),
15163 : COERCE_EXPLICIT_CALL,
15164 0 : @2);
15165 0 : $$ = (Node *) makeSimpleA_Expr(AEXPR_SIMILAR, "!~",
15166 0 : $1, (Node *) n, @2);
15167 : }
15168 : | a_expr NOT_LA SIMILAR TO a_expr ESCAPE a_expr %prec NOT_LA
15169 : {
15170 0 : FuncCall *n = makeFuncCall(SystemFuncName("similar_to_escape"),
15171 0 : list_make2($5, $7),
15172 : COERCE_EXPLICIT_CALL,
15173 0 : @2);
15174 0 : $$ = (Node *) makeSimpleA_Expr(AEXPR_SIMILAR, "!~",
15175 0 : $1, (Node *) n, @2);
15176 : }
15177 :
15178 : /* NullTest clause
15179 : * Define SQL-style Null test clause.
15180 : * Allow two forms described in the standard:
15181 : * a IS NULL
15182 : * a IS NOT NULL
15183 : * Allow two SQL extensions
15184 : * a ISNULL
15185 : * a NOTNULL
15186 : */
15187 : | a_expr IS NULL_P %prec IS
15188 : {
15189 5266 : NullTest *n = makeNode(NullTest);
15190 :
15191 5266 : n->arg = (Expr *) $1;
15192 5266 : n->nulltesttype = IS_NULL;
15193 5266 : n->location = @2;
15194 5266 : $$ = (Node *) n;
15195 : }
15196 : | a_expr ISNULL
15197 : {
15198 96 : NullTest *n = makeNode(NullTest);
15199 :
15200 96 : n->arg = (Expr *) $1;
15201 96 : n->nulltesttype = IS_NULL;
15202 96 : n->location = @2;
15203 96 : $$ = (Node *) n;
15204 : }
15205 : | a_expr IS NOT NULL_P %prec IS
15206 : {
15207 12916 : NullTest *n = makeNode(NullTest);
15208 :
15209 12916 : n->arg = (Expr *) $1;
15210 12916 : n->nulltesttype = IS_NOT_NULL;
15211 12916 : n->location = @2;
15212 12916 : $$ = (Node *) n;
15213 : }
15214 : | a_expr NOTNULL
15215 : {
15216 6 : NullTest *n = makeNode(NullTest);
15217 :
15218 6 : n->arg = (Expr *) $1;
15219 6 : n->nulltesttype = IS_NOT_NULL;
15220 6 : n->location = @2;
15221 6 : $$ = (Node *) n;
15222 : }
15223 : | row OVERLAPS row
15224 : {
15225 966 : if (list_length($1) != 2)
15226 0 : ereport(ERROR,
15227 : (errcode(ERRCODE_SYNTAX_ERROR),
15228 : errmsg("wrong number of parameters on left side of OVERLAPS expression"),
15229 : parser_errposition(@1)));
15230 966 : if (list_length($3) != 2)
15231 0 : ereport(ERROR,
15232 : (errcode(ERRCODE_SYNTAX_ERROR),
15233 : errmsg("wrong number of parameters on right side of OVERLAPS expression"),
15234 : parser_errposition(@3)));
15235 966 : $$ = (Node *) makeFuncCall(SystemFuncName("overlaps"),
15236 966 : list_concat($1, $3),
15237 : COERCE_SQL_SYNTAX,
15238 966 : @2);
15239 : }
15240 : | a_expr IS TRUE_P %prec IS
15241 : {
15242 432 : BooleanTest *b = makeNode(BooleanTest);
15243 :
15244 432 : b->arg = (Expr *) $1;
15245 432 : b->booltesttype = IS_TRUE;
15246 432 : b->location = @2;
15247 432 : $$ = (Node *) b;
15248 : }
15249 : | a_expr IS NOT TRUE_P %prec IS
15250 : {
15251 140 : BooleanTest *b = makeNode(BooleanTest);
15252 :
15253 140 : b->arg = (Expr *) $1;
15254 140 : b->booltesttype = IS_NOT_TRUE;
15255 140 : b->location = @2;
15256 140 : $$ = (Node *) b;
15257 : }
15258 : | a_expr IS FALSE_P %prec IS
15259 : {
15260 154 : BooleanTest *b = makeNode(BooleanTest);
15261 :
15262 154 : b->arg = (Expr *) $1;
15263 154 : b->booltesttype = IS_FALSE;
15264 154 : b->location = @2;
15265 154 : $$ = (Node *) b;
15266 : }
15267 : | a_expr IS NOT FALSE_P %prec IS
15268 : {
15269 92 : BooleanTest *b = makeNode(BooleanTest);
15270 :
15271 92 : b->arg = (Expr *) $1;
15272 92 : b->booltesttype = IS_NOT_FALSE;
15273 92 : b->location = @2;
15274 92 : $$ = (Node *) b;
15275 : }
15276 : | a_expr IS UNKNOWN %prec IS
15277 : {
15278 52 : BooleanTest *b = makeNode(BooleanTest);
15279 :
15280 52 : b->arg = (Expr *) $1;
15281 52 : b->booltesttype = IS_UNKNOWN;
15282 52 : b->location = @2;
15283 52 : $$ = (Node *) b;
15284 : }
15285 : | a_expr IS NOT UNKNOWN %prec IS
15286 : {
15287 48 : BooleanTest *b = makeNode(BooleanTest);
15288 :
15289 48 : b->arg = (Expr *) $1;
15290 48 : b->booltesttype = IS_NOT_UNKNOWN;
15291 48 : b->location = @2;
15292 48 : $$ = (Node *) b;
15293 : }
15294 : | a_expr IS DISTINCT FROM a_expr %prec IS
15295 : {
15296 1072 : $$ = (Node *) makeSimpleA_Expr(AEXPR_DISTINCT, "=", $1, $5, @2);
15297 : }
15298 : | a_expr IS NOT DISTINCT FROM a_expr %prec IS
15299 : {
15300 68 : $$ = (Node *) makeSimpleA_Expr(AEXPR_NOT_DISTINCT, "=", $1, $6, @2);
15301 : }
15302 : | a_expr BETWEEN opt_asymmetric b_expr AND a_expr %prec BETWEEN
15303 : {
15304 470 : $$ = (Node *) makeSimpleA_Expr(AEXPR_BETWEEN,
15305 : "BETWEEN",
15306 470 : $1,
15307 470 : (Node *) list_make2($4, $6),
15308 470 : @2);
15309 : }
15310 : | a_expr NOT_LA BETWEEN opt_asymmetric b_expr AND a_expr %prec NOT_LA
15311 : {
15312 12 : $$ = (Node *) makeSimpleA_Expr(AEXPR_NOT_BETWEEN,
15313 : "NOT BETWEEN",
15314 12 : $1,
15315 12 : (Node *) list_make2($5, $7),
15316 12 : @2);
15317 : }
15318 : | a_expr BETWEEN SYMMETRIC b_expr AND a_expr %prec BETWEEN
15319 : {
15320 12 : $$ = (Node *) makeSimpleA_Expr(AEXPR_BETWEEN_SYM,
15321 : "BETWEEN SYMMETRIC",
15322 12 : $1,
15323 12 : (Node *) list_make2($4, $6),
15324 12 : @2);
15325 : }
15326 : | a_expr NOT_LA BETWEEN SYMMETRIC b_expr AND a_expr %prec NOT_LA
15327 : {
15328 12 : $$ = (Node *) makeSimpleA_Expr(AEXPR_NOT_BETWEEN_SYM,
15329 : "NOT BETWEEN SYMMETRIC",
15330 12 : $1,
15331 12 : (Node *) list_make2($5, $7),
15332 12 : @2);
15333 : }
15334 : | a_expr IN_P select_with_parens
15335 : {
15336 : /* generate foo = ANY (subquery) */
15337 5584 : SubLink *n = makeNode(SubLink);
15338 :
15339 5584 : n->subselect = $3;
15340 5584 : n->subLinkType = ANY_SUBLINK;
15341 5584 : n->subLinkId = 0;
15342 5584 : n->testexpr = $1;
15343 5584 : n->operName = NIL; /* show it's IN not = ANY */
15344 5584 : n->location = @2;
15345 5584 : $$ = (Node *) n;
15346 : }
15347 : | a_expr IN_P '(' expr_list ')'
15348 : {
15349 : /* generate scalar IN expression */
15350 18748 : A_Expr *n = makeSimpleA_Expr(AEXPR_IN, "=", $1, (Node *) $4, @2);
15351 :
15352 18748 : n->rexpr_list_start = @3;
15353 18748 : n->rexpr_list_end = @5;
15354 18748 : $$ = (Node *) n;
15355 : }
15356 : | a_expr NOT_LA IN_P select_with_parens %prec NOT_LA
15357 : {
15358 : /* generate NOT (foo = ANY (subquery)) */
15359 120 : SubLink *n = makeNode(SubLink);
15360 :
15361 120 : n->subselect = $4;
15362 120 : n->subLinkType = ANY_SUBLINK;
15363 120 : n->subLinkId = 0;
15364 120 : n->testexpr = $1;
15365 120 : n->operName = NIL; /* show it's IN not = ANY */
15366 120 : n->location = @2;
15367 : /* Stick a NOT on top; must have same parse location */
15368 120 : $$ = makeNotExpr((Node *) n, @2);
15369 : }
15370 : | a_expr NOT_LA IN_P '(' expr_list ')'
15371 : {
15372 : /* generate scalar NOT IN expression */
15373 2652 : A_Expr *n = makeSimpleA_Expr(AEXPR_IN, "<>", $1, (Node *) $5, @2);
15374 :
15375 2652 : n->rexpr_list_start = @4;
15376 2652 : n->rexpr_list_end = @6;
15377 2652 : $$ = (Node *) n;
15378 : }
15379 : | a_expr subquery_Op sub_type select_with_parens %prec Op
15380 : {
15381 180 : SubLink *n = makeNode(SubLink);
15382 :
15383 180 : n->subLinkType = $3;
15384 180 : n->subLinkId = 0;
15385 180 : n->testexpr = $1;
15386 180 : n->operName = $2;
15387 180 : n->subselect = $4;
15388 180 : n->location = @2;
15389 180 : $$ = (Node *) n;
15390 : }
15391 : | a_expr subquery_Op sub_type '(' a_expr ')' %prec Op
15392 : {
15393 16866 : if ($3 == ANY_SUBLINK)
15394 16566 : $$ = (Node *) makeA_Expr(AEXPR_OP_ANY, $2, $1, $5, @2);
15395 : else
15396 300 : $$ = (Node *) makeA_Expr(AEXPR_OP_ALL, $2, $1, $5, @2);
15397 : }
15398 : | UNIQUE opt_unique_null_treatment select_with_parens
15399 : {
15400 : /* Not sure how to get rid of the parentheses
15401 : * but there are lots of shift/reduce errors without them.
15402 : *
15403 : * Should be able to implement this by plopping the entire
15404 : * select into a node, then transforming the target expressions
15405 : * from whatever they are into count(*), and testing the
15406 : * entire result equal to one.
15407 : * But, will probably implement a separate node in the executor.
15408 : */
15409 0 : ereport(ERROR,
15410 : (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
15411 : errmsg("UNIQUE predicate is not yet implemented"),
15412 : parser_errposition(@1)));
15413 : }
15414 : | a_expr IS DOCUMENT_P %prec IS
15415 : {
15416 18 : $$ = makeXmlExpr(IS_DOCUMENT, NULL, NIL,
15417 18 : list_make1($1), @2);
15418 : }
15419 : | a_expr IS NOT DOCUMENT_P %prec IS
15420 : {
15421 18 : $$ = makeNotExpr(makeXmlExpr(IS_DOCUMENT, NULL, NIL,
15422 18 : list_make1($1), @2),
15423 18 : @2);
15424 : }
15425 : | a_expr IS NORMALIZED %prec IS
15426 : {
15427 12 : $$ = (Node *) makeFuncCall(SystemFuncName("is_normalized"),
15428 12 : list_make1($1),
15429 : COERCE_SQL_SYNTAX,
15430 12 : @2);
15431 : }
15432 : | a_expr IS unicode_normal_form NORMALIZED %prec IS
15433 : {
15434 36 : $$ = (Node *) makeFuncCall(SystemFuncName("is_normalized"),
15435 36 : list_make2($1, makeStringConst($3, @3)),
15436 : COERCE_SQL_SYNTAX,
15437 36 : @2);
15438 : }
15439 : | a_expr IS NOT NORMALIZED %prec IS
15440 : {
15441 0 : $$ = makeNotExpr((Node *) makeFuncCall(SystemFuncName("is_normalized"),
15442 0 : list_make1($1),
15443 : COERCE_SQL_SYNTAX,
15444 0 : @2),
15445 0 : @2);
15446 : }
15447 : | a_expr IS NOT unicode_normal_form NORMALIZED %prec IS
15448 : {
15449 0 : $$ = makeNotExpr((Node *) makeFuncCall(SystemFuncName("is_normalized"),
15450 0 : list_make2($1, makeStringConst($4, @4)),
15451 : COERCE_SQL_SYNTAX,
15452 0 : @2),
15453 0 : @2);
15454 : }
15455 : | a_expr IS json_predicate_type_constraint
15456 : json_key_uniqueness_constraint_opt %prec IS
15457 : {
15458 304 : JsonFormat *format = makeJsonFormat(JS_FORMAT_DEFAULT, JS_ENC_DEFAULT, -1);
15459 :
15460 304 : $$ = makeJsonIsPredicate($1, format, $3, $4, @1);
15461 : }
15462 : /*
15463 : * Required by SQL/JSON, but there are conflicts
15464 : | a_expr
15465 : json_format_clause
15466 : IS json_predicate_type_constraint
15467 : json_key_uniqueness_constraint_opt %prec IS
15468 : {
15469 : $$ = makeJsonIsPredicate($1, $2, $4, $5, @1);
15470 : }
15471 : */
15472 : | a_expr IS NOT
15473 : json_predicate_type_constraint
15474 : json_key_uniqueness_constraint_opt %prec IS
15475 : {
15476 46 : JsonFormat *format = makeJsonFormat(JS_FORMAT_DEFAULT, JS_ENC_DEFAULT, -1);
15477 :
15478 46 : $$ = makeNotExpr(makeJsonIsPredicate($1, format, $4, $5, @1), @1);
15479 : }
15480 : /*
15481 : * Required by SQL/JSON, but there are conflicts
15482 : | a_expr
15483 : json_format_clause
15484 : IS NOT
15485 : json_predicate_type_constraint
15486 : json_key_uniqueness_constraint_opt %prec IS
15487 : {
15488 : $$ = makeNotExpr(makeJsonIsPredicate($1, $2, $5, $6, @1), @1);
15489 : }
15490 : */
15491 : | DEFAULT
15492 : {
15493 : /*
15494 : * The SQL spec only allows DEFAULT in "contextually typed
15495 : * expressions", but for us, it's easier to allow it in
15496 : * any a_expr and then throw error during parse analysis
15497 : * if it's in an inappropriate context. This way also
15498 : * lets us say something smarter than "syntax error".
15499 : */
15500 1524 : SetToDefault *n = makeNode(SetToDefault);
15501 :
15502 : /* parse analysis will fill in the rest */
15503 1524 : n->location = @1;
15504 1524 : $$ = (Node *) n;
15505 : }
15506 : ;
15507 :
15508 : /*
15509 : * Restricted expressions
15510 : *
15511 : * b_expr is a subset of the complete expression syntax defined by a_expr.
15512 : *
15513 : * Presently, AND, NOT, IS, and IN are the a_expr keywords that would
15514 : * cause trouble in the places where b_expr is used. For simplicity, we
15515 : * just eliminate all the boolean-keyword-operator productions from b_expr.
15516 : */
15517 : b_expr: c_expr
15518 3802 : { $$ = $1; }
15519 : | b_expr TYPECAST Typename
15520 212 : { $$ = makeTypeCast($1, $3, @2); }
15521 : | '+' b_expr %prec UMINUS
15522 0 : { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "+", NULL, $2, @1); }
15523 : | '-' b_expr %prec UMINUS
15524 66 : { $$ = doNegate($2, @1); }
15525 : | b_expr '+' b_expr
15526 36 : { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "+", $1, $3, @2); }
15527 : | b_expr '-' b_expr
15528 12 : { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "-", $1, $3, @2); }
15529 : | b_expr '*' b_expr
15530 12 : { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "*", $1, $3, @2); }
15531 : | b_expr '/' b_expr
15532 0 : { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "/", $1, $3, @2); }
15533 : | b_expr '%' b_expr
15534 0 : { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "%", $1, $3, @2); }
15535 : | b_expr '^' b_expr
15536 6 : { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "^", $1, $3, @2); }
15537 : | b_expr '<' b_expr
15538 0 : { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "<", $1, $3, @2); }
15539 : | b_expr '>' b_expr
15540 0 : { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, ">", $1, $3, @2); }
15541 : | b_expr '=' b_expr
15542 0 : { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "=", $1, $3, @2); }
15543 : | b_expr LESS_EQUALS b_expr
15544 0 : { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "<=", $1, $3, @2); }
15545 : | b_expr GREATER_EQUALS b_expr
15546 0 : { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, ">=", $1, $3, @2); }
15547 : | b_expr NOT_EQUALS b_expr
15548 0 : { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "<>", $1, $3, @2); }
15549 : | b_expr qual_Op b_expr %prec Op
15550 12 : { $$ = (Node *) makeA_Expr(AEXPR_OP, $2, $1, $3, @2); }
15551 : | qual_Op b_expr %prec Op
15552 0 : { $$ = (Node *) makeA_Expr(AEXPR_OP, $1, NULL, $2, @1); }
15553 : | b_expr IS DISTINCT FROM b_expr %prec IS
15554 : {
15555 0 : $$ = (Node *) makeSimpleA_Expr(AEXPR_DISTINCT, "=", $1, $5, @2);
15556 : }
15557 : | b_expr IS NOT DISTINCT FROM b_expr %prec IS
15558 : {
15559 0 : $$ = (Node *) makeSimpleA_Expr(AEXPR_NOT_DISTINCT, "=", $1, $6, @2);
15560 : }
15561 : | b_expr IS DOCUMENT_P %prec IS
15562 : {
15563 0 : $$ = makeXmlExpr(IS_DOCUMENT, NULL, NIL,
15564 0 : list_make1($1), @2);
15565 : }
15566 : | b_expr IS NOT DOCUMENT_P %prec IS
15567 : {
15568 0 : $$ = makeNotExpr(makeXmlExpr(IS_DOCUMENT, NULL, NIL,
15569 0 : list_make1($1), @2),
15570 0 : @2);
15571 : }
15572 : ;
15573 :
15574 : /*
15575 : * Productions that can be used in both a_expr and b_expr.
15576 : *
15577 : * Note: productions that refer recursively to a_expr or b_expr mostly
15578 : * cannot appear here. However, it's OK to refer to a_exprs that occur
15579 : * inside parentheses, such as function arguments; that cannot introduce
15580 : * ambiguity to the b_expr syntax.
15581 : */
15582 1806254 : c_expr: columnref { $$ = $1; }
15583 1237612 : | AexprConst { $$ = $1; }
15584 : | PARAM opt_indirection
15585 : {
15586 46342 : ParamRef *p = makeNode(ParamRef);
15587 :
15588 46342 : p->number = $1;
15589 46342 : p->location = @1;
15590 46342 : if ($2)
15591 : {
15592 1084 : A_Indirection *n = makeNode(A_Indirection);
15593 :
15594 1084 : n->arg = (Node *) p;
15595 1084 : n->indirection = check_indirection($2, yyscanner);
15596 1084 : $$ = (Node *) n;
15597 : }
15598 : else
15599 45258 : $$ = (Node *) p;
15600 : }
15601 : | '(' a_expr ')' opt_indirection
15602 : {
15603 89752 : if ($4)
15604 : {
15605 12348 : A_Indirection *n = makeNode(A_Indirection);
15606 :
15607 12348 : n->arg = $2;
15608 12348 : n->indirection = check_indirection($4, yyscanner);
15609 12348 : $$ = (Node *) n;
15610 : }
15611 : else
15612 77404 : $$ = $2;
15613 : }
15614 : | case_expr
15615 39124 : { $$ = $1; }
15616 : | func_expr
15617 391510 : { $$ = $1; }
15618 : | select_with_parens %prec UMINUS
15619 : {
15620 27572 : SubLink *n = makeNode(SubLink);
15621 :
15622 27572 : n->subLinkType = EXPR_SUBLINK;
15623 27572 : n->subLinkId = 0;
15624 27572 : n->testexpr = NULL;
15625 27572 : n->operName = NIL;
15626 27572 : n->subselect = $1;
15627 27572 : n->location = @1;
15628 27572 : $$ = (Node *) n;
15629 : }
15630 : | select_with_parens indirection
15631 : {
15632 : /*
15633 : * Because the select_with_parens nonterminal is designed
15634 : * to "eat" as many levels of parens as possible, the
15635 : * '(' a_expr ')' opt_indirection production above will
15636 : * fail to match a sub-SELECT with indirection decoration;
15637 : * the sub-SELECT won't be regarded as an a_expr as long
15638 : * as there are parens around it. To support applying
15639 : * subscripting or field selection to a sub-SELECT result,
15640 : * we need this redundant-looking production.
15641 : */
15642 18 : SubLink *n = makeNode(SubLink);
15643 18 : A_Indirection *a = makeNode(A_Indirection);
15644 :
15645 18 : n->subLinkType = EXPR_SUBLINK;
15646 18 : n->subLinkId = 0;
15647 18 : n->testexpr = NULL;
15648 18 : n->operName = NIL;
15649 18 : n->subselect = $1;
15650 18 : n->location = @1;
15651 18 : a->arg = (Node *) n;
15652 18 : a->indirection = check_indirection($2, yyscanner);
15653 18 : $$ = (Node *) a;
15654 : }
15655 : | EXISTS select_with_parens
15656 : {
15657 6166 : SubLink *n = makeNode(SubLink);
15658 :
15659 6166 : n->subLinkType = EXISTS_SUBLINK;
15660 6166 : n->subLinkId = 0;
15661 6166 : n->testexpr = NULL;
15662 6166 : n->operName = NIL;
15663 6166 : n->subselect = $2;
15664 6166 : n->location = @1;
15665 6166 : $$ = (Node *) n;
15666 : }
15667 : | ARRAY select_with_parens
15668 : {
15669 8438 : SubLink *n = makeNode(SubLink);
15670 :
15671 8438 : n->subLinkType = ARRAY_SUBLINK;
15672 8438 : n->subLinkId = 0;
15673 8438 : n->testexpr = NULL;
15674 8438 : n->operName = NIL;
15675 8438 : n->subselect = $2;
15676 8438 : n->location = @1;
15677 8438 : $$ = (Node *) n;
15678 : }
15679 : | ARRAY array_expr
15680 : {
15681 7462 : A_ArrayExpr *n = castNode(A_ArrayExpr, $2);
15682 :
15683 : /* point outermost A_ArrayExpr to the ARRAY keyword */
15684 7462 : n->location = @1;
15685 7462 : $$ = (Node *) n;
15686 : }
15687 : | explicit_row
15688 : {
15689 3816 : RowExpr *r = makeNode(RowExpr);
15690 :
15691 3816 : r->args = $1;
15692 3816 : r->row_typeid = InvalidOid; /* not analyzed yet */
15693 3816 : r->colnames = NIL; /* to be filled in during analysis */
15694 3816 : r->row_format = COERCE_EXPLICIT_CALL; /* abuse */
15695 3816 : r->location = @1;
15696 3816 : $$ = (Node *) r;
15697 : }
15698 : | implicit_row
15699 : {
15700 2706 : RowExpr *r = makeNode(RowExpr);
15701 :
15702 2706 : r->args = $1;
15703 2706 : r->row_typeid = InvalidOid; /* not analyzed yet */
15704 2706 : r->colnames = NIL; /* to be filled in during analysis */
15705 2706 : r->row_format = COERCE_IMPLICIT_CAST; /* abuse */
15706 2706 : r->location = @1;
15707 2706 : $$ = (Node *) r;
15708 : }
15709 : | GROUPING '(' expr_list ')'
15710 : {
15711 362 : GroupingFunc *g = makeNode(GroupingFunc);
15712 :
15713 362 : g->args = $3;
15714 362 : g->location = @1;
15715 362 : $$ = (Node *) g;
15716 : }
15717 : ;
15718 :
15719 : func_application: func_name '(' ')'
15720 : {
15721 32766 : $$ = (Node *) makeFuncCall($1, NIL,
15722 : COERCE_EXPLICIT_CALL,
15723 32770 : @1);
15724 : }
15725 : | func_name '(' func_arg_list opt_sort_clause ')'
15726 : {
15727 316856 : FuncCall *n = makeFuncCall($1, $3,
15728 : COERCE_EXPLICIT_CALL,
15729 316856 : @1);
15730 :
15731 316856 : n->agg_order = $4;
15732 316856 : $$ = (Node *) n;
15733 : }
15734 : | func_name '(' VARIADIC func_arg_expr opt_sort_clause ')'
15735 : {
15736 624 : FuncCall *n = makeFuncCall($1, list_make1($4),
15737 : COERCE_EXPLICIT_CALL,
15738 624 : @1);
15739 :
15740 624 : n->func_variadic = true;
15741 624 : n->agg_order = $5;
15742 624 : $$ = (Node *) n;
15743 : }
15744 : | func_name '(' func_arg_list ',' VARIADIC func_arg_expr opt_sort_clause ')'
15745 : {
15746 168 : FuncCall *n = makeFuncCall($1, lappend($3, $6),
15747 : COERCE_EXPLICIT_CALL,
15748 168 : @1);
15749 :
15750 168 : n->func_variadic = true;
15751 168 : n->agg_order = $7;
15752 168 : $$ = (Node *) n;
15753 : }
15754 : | func_name '(' ALL func_arg_list opt_sort_clause ')'
15755 : {
15756 0 : FuncCall *n = makeFuncCall($1, $4,
15757 : COERCE_EXPLICIT_CALL,
15758 0 : @1);
15759 :
15760 0 : n->agg_order = $5;
15761 : /* Ideally we'd mark the FuncCall node to indicate
15762 : * "must be an aggregate", but there's no provision
15763 : * for that in FuncCall at the moment.
15764 : */
15765 0 : $$ = (Node *) n;
15766 : }
15767 : | func_name '(' DISTINCT func_arg_list opt_sort_clause ')'
15768 : {
15769 550 : FuncCall *n = makeFuncCall($1, $4,
15770 : COERCE_EXPLICIT_CALL,
15771 550 : @1);
15772 :
15773 550 : n->agg_order = $5;
15774 550 : n->agg_distinct = true;
15775 550 : $$ = (Node *) n;
15776 : }
15777 : | func_name '(' '*' ')'
15778 : {
15779 : /*
15780 : * We consider AGGREGATE(*) to invoke a parameterless
15781 : * aggregate. This does the right thing for COUNT(*),
15782 : * and there are no other aggregates in SQL that accept
15783 : * '*' as parameter.
15784 : *
15785 : * The FuncCall node is also marked agg_star = true,
15786 : * so that later processing can detect what the argument
15787 : * really was.
15788 : */
15789 12766 : FuncCall *n = makeFuncCall($1, NIL,
15790 : COERCE_EXPLICIT_CALL,
15791 12766 : @1);
15792 :
15793 12766 : n->agg_star = true;
15794 12766 : $$ = (Node *) n;
15795 : }
15796 : ;
15797 :
15798 :
15799 : /*
15800 : * func_expr and its cousin func_expr_windowless are split out from c_expr just
15801 : * so that we have classifications for "everything that is a function call or
15802 : * looks like one". This isn't very important, but it saves us having to
15803 : * document which variants are legal in places like "FROM function()" or the
15804 : * backwards-compatible functional-index syntax for CREATE INDEX.
15805 : * (Note that many of the special SQL functions wouldn't actually make any
15806 : * sense as functional index entries, but we ignore that consideration here.)
15807 : */
15808 : func_expr: func_application within_group_clause filter_clause over_clause
15809 : {
15810 314822 : FuncCall *n = (FuncCall *) $1;
15811 :
15812 : /*
15813 : * The order clause for WITHIN GROUP and the one for
15814 : * plain-aggregate ORDER BY share a field, so we have to
15815 : * check here that at most one is present. We also check
15816 : * for DISTINCT and VARIADIC here to give a better error
15817 : * location. Other consistency checks are deferred to
15818 : * parse analysis.
15819 : */
15820 314822 : if ($2 != NIL)
15821 : {
15822 348 : if (n->agg_order != NIL)
15823 6 : ereport(ERROR,
15824 : (errcode(ERRCODE_SYNTAX_ERROR),
15825 : errmsg("cannot use multiple ORDER BY clauses with WITHIN GROUP"),
15826 : parser_errposition(@2)));
15827 342 : if (n->agg_distinct)
15828 0 : ereport(ERROR,
15829 : (errcode(ERRCODE_SYNTAX_ERROR),
15830 : errmsg("cannot use DISTINCT with WITHIN GROUP"),
15831 : parser_errposition(@2)));
15832 342 : if (n->func_variadic)
15833 0 : ereport(ERROR,
15834 : (errcode(ERRCODE_SYNTAX_ERROR),
15835 : errmsg("cannot use VARIADIC with WITHIN GROUP"),
15836 : parser_errposition(@2)));
15837 342 : n->agg_order = $2;
15838 342 : n->agg_within_group = true;
15839 : }
15840 314816 : n->agg_filter = $3;
15841 314816 : n->over = $4;
15842 314816 : $$ = (Node *) n;
15843 : }
15844 : | json_aggregate_func filter_clause over_clause
15845 : {
15846 720 : JsonAggConstructor *n = IsA($1, JsonObjectAgg) ?
15847 360 : ((JsonObjectAgg *) $1)->constructor :
15848 156 : ((JsonArrayAgg *) $1)->constructor;
15849 :
15850 360 : n->agg_filter = $2;
15851 360 : n->over = $3;
15852 360 : $$ = (Node *) $1;
15853 : }
15854 : | func_expr_common_subexpr
15855 76334 : { $$ = $1; }
15856 : ;
15857 :
15858 : /*
15859 : * Like func_expr but does not accept WINDOW functions directly
15860 : * (but they can still be contained in arguments for functions etc).
15861 : * Use this when window expressions are not allowed, where needed to
15862 : * disambiguate the grammar (e.g. in CREATE INDEX).
15863 : */
15864 : func_expr_windowless:
15865 48278 : func_application { $$ = $1; }
15866 402 : | func_expr_common_subexpr { $$ = $1; }
15867 0 : | json_aggregate_func { $$ = $1; }
15868 : ;
15869 :
15870 : /*
15871 : * Special expressions that are considered to be functions.
15872 : */
15873 : func_expr_common_subexpr:
15874 : COLLATION FOR '(' a_expr ')'
15875 : {
15876 30 : $$ = (Node *) makeFuncCall(SystemFuncName("pg_collation_for"),
15877 30 : list_make1($4),
15878 : COERCE_SQL_SYNTAX,
15879 30 : @1);
15880 : }
15881 : | CURRENT_DATE
15882 : {
15883 308 : $$ = makeSQLValueFunction(SVFOP_CURRENT_DATE, -1, @1);
15884 : }
15885 : | CURRENT_TIME
15886 : {
15887 24 : $$ = makeSQLValueFunction(SVFOP_CURRENT_TIME, -1, @1);
15888 : }
15889 : | CURRENT_TIME '(' Iconst ')'
15890 : {
15891 24 : $$ = makeSQLValueFunction(SVFOP_CURRENT_TIME_N, $3, @1);
15892 : }
15893 : | CURRENT_TIMESTAMP
15894 : {
15895 284 : $$ = makeSQLValueFunction(SVFOP_CURRENT_TIMESTAMP, -1, @1);
15896 : }
15897 : | CURRENT_TIMESTAMP '(' Iconst ')'
15898 : {
15899 174 : $$ = makeSQLValueFunction(SVFOP_CURRENT_TIMESTAMP_N, $3, @1);
15900 : }
15901 : | LOCALTIME
15902 : {
15903 24 : $$ = makeSQLValueFunction(SVFOP_LOCALTIME, -1, @1);
15904 : }
15905 : | LOCALTIME '(' Iconst ')'
15906 : {
15907 24 : $$ = makeSQLValueFunction(SVFOP_LOCALTIME_N, $3, @1);
15908 : }
15909 : | LOCALTIMESTAMP
15910 : {
15911 36 : $$ = makeSQLValueFunction(SVFOP_LOCALTIMESTAMP, -1, @1);
15912 : }
15913 : | LOCALTIMESTAMP '(' Iconst ')'
15914 : {
15915 24 : $$ = makeSQLValueFunction(SVFOP_LOCALTIMESTAMP_N, $3, @1);
15916 : }
15917 : | CURRENT_ROLE
15918 : {
15919 68 : $$ = makeSQLValueFunction(SVFOP_CURRENT_ROLE, -1, @1);
15920 : }
15921 : | CURRENT_USER
15922 : {
15923 1060 : $$ = makeSQLValueFunction(SVFOP_CURRENT_USER, -1, @1);
15924 : }
15925 : | SESSION_USER
15926 : {
15927 578 : $$ = makeSQLValueFunction(SVFOP_SESSION_USER, -1, @1);
15928 : }
15929 : | SYSTEM_USER
15930 : {
15931 20 : $$ = (Node *) makeFuncCall(SystemFuncName("system_user"),
15932 : NIL,
15933 : COERCE_SQL_SYNTAX,
15934 : @1);
15935 : }
15936 : | USER
15937 : {
15938 24 : $$ = makeSQLValueFunction(SVFOP_USER, -1, @1);
15939 : }
15940 : | CURRENT_CATALOG
15941 : {
15942 60 : $$ = makeSQLValueFunction(SVFOP_CURRENT_CATALOG, -1, @1);
15943 : }
15944 : | CURRENT_SCHEMA
15945 : {
15946 30 : $$ = makeSQLValueFunction(SVFOP_CURRENT_SCHEMA, -1, @1);
15947 : }
15948 : | CAST '(' a_expr AS Typename ')'
15949 62472 : { $$ = makeTypeCast($3, $5, @1); }
15950 : | EXTRACT '(' extract_list ')'
15951 : {
15952 1382 : $$ = (Node *) makeFuncCall(SystemFuncName("extract"),
15953 1382 : $3,
15954 : COERCE_SQL_SYNTAX,
15955 1382 : @1);
15956 : }
15957 : | NORMALIZE '(' a_expr ')'
15958 : {
15959 18 : $$ = (Node *) makeFuncCall(SystemFuncName("normalize"),
15960 18 : list_make1($3),
15961 : COERCE_SQL_SYNTAX,
15962 18 : @1);
15963 : }
15964 : | NORMALIZE '(' a_expr ',' unicode_normal_form ')'
15965 : {
15966 42 : $$ = (Node *) makeFuncCall(SystemFuncName("normalize"),
15967 42 : list_make2($3, makeStringConst($5, @5)),
15968 : COERCE_SQL_SYNTAX,
15969 42 : @1);
15970 : }
15971 : | OVERLAY '(' overlay_list ')'
15972 : {
15973 82 : $$ = (Node *) makeFuncCall(SystemFuncName("overlay"),
15974 82 : $3,
15975 : COERCE_SQL_SYNTAX,
15976 82 : @1);
15977 : }
15978 : | OVERLAY '(' func_arg_list_opt ')'
15979 : {
15980 : /*
15981 : * allow functions named overlay() to be called without
15982 : * special syntax
15983 : */
15984 0 : $$ = (Node *) makeFuncCall(list_make1(makeString("overlay")),
15985 0 : $3,
15986 : COERCE_EXPLICIT_CALL,
15987 0 : @1);
15988 : }
15989 : | POSITION '(' position_list ')'
15990 : {
15991 : /*
15992 : * position(A in B) is converted to position(B, A)
15993 : *
15994 : * We deliberately don't offer a "plain syntax" option
15995 : * for position(), because the reversal of the arguments
15996 : * creates too much risk of confusion.
15997 : */
15998 400 : $$ = (Node *) makeFuncCall(SystemFuncName("position"),
15999 400 : $3,
16000 : COERCE_SQL_SYNTAX,
16001 400 : @1);
16002 : }
16003 : | SUBSTRING '(' substr_list ')'
16004 : {
16005 : /* substring(A from B for C) is converted to
16006 : * substring(A, B, C) - thomas 2000-11-28
16007 : */
16008 710 : $$ = (Node *) makeFuncCall(SystemFuncName("substring"),
16009 710 : $3,
16010 : COERCE_SQL_SYNTAX,
16011 710 : @1);
16012 : }
16013 : | SUBSTRING '(' func_arg_list_opt ')'
16014 : {
16015 : /*
16016 : * allow functions named substring() to be called without
16017 : * special syntax
16018 : */
16019 252 : $$ = (Node *) makeFuncCall(list_make1(makeString("substring")),
16020 252 : $3,
16021 : COERCE_EXPLICIT_CALL,
16022 252 : @1);
16023 : }
16024 : | TREAT '(' a_expr AS Typename ')'
16025 : {
16026 : /* TREAT(expr AS target) converts expr of a particular type to target,
16027 : * which is defined to be a subtype of the original expression.
16028 : * In SQL99, this is intended for use with structured UDTs,
16029 : * but let's make this a generally useful form allowing stronger
16030 : * coercions than are handled by implicit casting.
16031 : *
16032 : * Convert SystemTypeName() to SystemFuncName() even though
16033 : * at the moment they result in the same thing.
16034 : */
16035 0 : $$ = (Node *) makeFuncCall(SystemFuncName(strVal(llast($5->names))),
16036 0 : list_make1($3),
16037 : COERCE_EXPLICIT_CALL,
16038 0 : @1);
16039 : }
16040 : | TRIM '(' BOTH trim_list ')'
16041 : {
16042 : /* various trim expressions are defined in SQL
16043 : * - thomas 1997-07-19
16044 : */
16045 12 : $$ = (Node *) makeFuncCall(SystemFuncName("btrim"),
16046 12 : $4,
16047 : COERCE_SQL_SYNTAX,
16048 12 : @1);
16049 : }
16050 : | TRIM '(' LEADING trim_list ')'
16051 : {
16052 24 : $$ = (Node *) makeFuncCall(SystemFuncName("ltrim"),
16053 24 : $4,
16054 : COERCE_SQL_SYNTAX,
16055 24 : @1);
16056 : }
16057 : | TRIM '(' TRAILING trim_list ')'
16058 : {
16059 580 : $$ = (Node *) makeFuncCall(SystemFuncName("rtrim"),
16060 580 : $4,
16061 : COERCE_SQL_SYNTAX,
16062 580 : @1);
16063 : }
16064 : | TRIM '(' trim_list ')'
16065 : {
16066 98 : $$ = (Node *) makeFuncCall(SystemFuncName("btrim"),
16067 98 : $3,
16068 : COERCE_SQL_SYNTAX,
16069 98 : @1);
16070 : }
16071 : | NULLIF '(' a_expr ',' a_expr ')'
16072 : {
16073 386 : $$ = (Node *) makeSimpleA_Expr(AEXPR_NULLIF, "=", $3, $5, @1);
16074 : }
16075 : | COALESCE '(' expr_list ')'
16076 : {
16077 3242 : CoalesceExpr *c = makeNode(CoalesceExpr);
16078 :
16079 3242 : c->args = $3;
16080 3242 : c->location = @1;
16081 3242 : $$ = (Node *) c;
16082 : }
16083 : | GREATEST '(' expr_list ')'
16084 : {
16085 146 : MinMaxExpr *v = makeNode(MinMaxExpr);
16086 :
16087 146 : v->args = $3;
16088 146 : v->op = IS_GREATEST;
16089 146 : v->location = @1;
16090 146 : $$ = (Node *) v;
16091 : }
16092 : | LEAST '(' expr_list ')'
16093 : {
16094 148 : MinMaxExpr *v = makeNode(MinMaxExpr);
16095 :
16096 148 : v->args = $3;
16097 148 : v->op = IS_LEAST;
16098 148 : v->location = @1;
16099 148 : $$ = (Node *) v;
16100 : }
16101 : | XMLCONCAT '(' expr_list ')'
16102 : {
16103 62 : $$ = makeXmlExpr(IS_XMLCONCAT, NULL, NIL, $3, @1);
16104 : }
16105 : | XMLELEMENT '(' NAME_P ColLabel ')'
16106 : {
16107 6 : $$ = makeXmlExpr(IS_XMLELEMENT, $4, NIL, NIL, @1);
16108 : }
16109 : | XMLELEMENT '(' NAME_P ColLabel ',' xml_attributes ')'
16110 : {
16111 36 : $$ = makeXmlExpr(IS_XMLELEMENT, $4, $6, NIL, @1);
16112 : }
16113 : | XMLELEMENT '(' NAME_P ColLabel ',' expr_list ')'
16114 : {
16115 116 : $$ = makeXmlExpr(IS_XMLELEMENT, $4, NIL, $6, @1);
16116 : }
16117 : | XMLELEMENT '(' NAME_P ColLabel ',' xml_attributes ',' expr_list ')'
16118 : {
16119 20 : $$ = makeXmlExpr(IS_XMLELEMENT, $4, $6, $8, @1);
16120 : }
16121 : | XMLEXISTS '(' c_expr xmlexists_argument ')'
16122 : {
16123 : /* xmlexists(A PASSING [BY REF] B [BY REF]) is
16124 : * converted to xmlexists(A, B)*/
16125 54 : $$ = (Node *) makeFuncCall(SystemFuncName("xmlexists"),
16126 54 : list_make2($3, $4),
16127 : COERCE_SQL_SYNTAX,
16128 54 : @1);
16129 : }
16130 : | XMLFOREST '(' xml_attribute_list ')'
16131 : {
16132 32 : $$ = makeXmlExpr(IS_XMLFOREST, NULL, $3, NIL, @1);
16133 : }
16134 : | XMLPARSE '(' document_or_content a_expr xml_whitespace_option ')'
16135 : {
16136 : XmlExpr *x = (XmlExpr *)
16137 140 : makeXmlExpr(IS_XMLPARSE, NULL, NIL,
16138 140 : list_make2($4, makeBoolAConst($5, -1)),
16139 140 : @1);
16140 :
16141 140 : x->xmloption = $3;
16142 140 : $$ = (Node *) x;
16143 : }
16144 : | XMLPI '(' NAME_P ColLabel ')'
16145 : {
16146 30 : $$ = makeXmlExpr(IS_XMLPI, $4, NULL, NIL, @1);
16147 : }
16148 : | XMLPI '(' NAME_P ColLabel ',' a_expr ')'
16149 : {
16150 50 : $$ = makeXmlExpr(IS_XMLPI, $4, NULL, list_make1($6), @1);
16151 : }
16152 : | XMLROOT '(' a_expr ',' xml_root_version opt_xml_root_standalone ')'
16153 : {
16154 68 : $$ = makeXmlExpr(IS_XMLROOT, NULL, NIL,
16155 68 : list_make3($3, $5, $6), @1);
16156 : }
16157 : | XMLSERIALIZE '(' document_or_content a_expr AS SimpleTypename xml_indent_option ')'
16158 : {
16159 218 : XmlSerialize *n = makeNode(XmlSerialize);
16160 :
16161 218 : n->xmloption = $3;
16162 218 : n->expr = $4;
16163 218 : n->typeName = $6;
16164 218 : n->indent = $7;
16165 218 : n->location = @1;
16166 218 : $$ = (Node *) n;
16167 : }
16168 : | JSON_OBJECT '(' func_arg_list ')'
16169 : {
16170 : /* Support for legacy (non-standard) json_object() */
16171 90 : $$ = (Node *) makeFuncCall(SystemFuncName("json_object"),
16172 90 : $3, COERCE_EXPLICIT_CALL, @1);
16173 : }
16174 : | JSON_OBJECT '(' json_name_and_value_list
16175 : json_object_constructor_null_clause_opt
16176 : json_key_uniqueness_constraint_opt
16177 : json_returning_clause_opt ')'
16178 : {
16179 348 : JsonObjectConstructor *n = makeNode(JsonObjectConstructor);
16180 :
16181 348 : n->exprs = $3;
16182 348 : n->absent_on_null = $4;
16183 348 : n->unique = $5;
16184 348 : n->output = (JsonOutput *) $6;
16185 348 : n->location = @1;
16186 348 : $$ = (Node *) n;
16187 : }
16188 : | JSON_OBJECT '(' json_returning_clause_opt ')'
16189 : {
16190 92 : JsonObjectConstructor *n = makeNode(JsonObjectConstructor);
16191 :
16192 92 : n->exprs = NULL;
16193 92 : n->absent_on_null = false;
16194 92 : n->unique = false;
16195 92 : n->output = (JsonOutput *) $3;
16196 92 : n->location = @1;
16197 92 : $$ = (Node *) n;
16198 : }
16199 : | JSON_ARRAY '('
16200 : json_value_expr_list
16201 : json_array_constructor_null_clause_opt
16202 : json_returning_clause_opt
16203 : ')'
16204 : {
16205 120 : JsonArrayConstructor *n = makeNode(JsonArrayConstructor);
16206 :
16207 120 : n->exprs = $3;
16208 120 : n->absent_on_null = $4;
16209 120 : n->output = (JsonOutput *) $5;
16210 120 : n->location = @1;
16211 120 : $$ = (Node *) n;
16212 : }
16213 : | JSON_ARRAY '('
16214 : select_no_parens
16215 : json_format_clause_opt
16216 : /* json_array_constructor_null_clause_opt */
16217 : json_returning_clause_opt
16218 : ')'
16219 : {
16220 60 : JsonArrayQueryConstructor *n = makeNode(JsonArrayQueryConstructor);
16221 :
16222 60 : n->query = $3;
16223 60 : n->format = (JsonFormat *) $4;
16224 60 : n->absent_on_null = true; /* XXX */
16225 60 : n->output = (JsonOutput *) $5;
16226 60 : n->location = @1;
16227 60 : $$ = (Node *) n;
16228 : }
16229 : | JSON_ARRAY '('
16230 : json_returning_clause_opt
16231 : ')'
16232 : {
16233 86 : JsonArrayConstructor *n = makeNode(JsonArrayConstructor);
16234 :
16235 86 : n->exprs = NIL;
16236 86 : n->absent_on_null = true;
16237 86 : n->output = (JsonOutput *) $3;
16238 86 : n->location = @1;
16239 86 : $$ = (Node *) n;
16240 : }
16241 : | JSON '(' json_value_expr json_key_uniqueness_constraint_opt ')'
16242 : {
16243 164 : JsonParseExpr *n = makeNode(JsonParseExpr);
16244 :
16245 164 : n->expr = (JsonValueExpr *) $3;
16246 164 : n->unique_keys = $4;
16247 164 : n->output = NULL;
16248 164 : n->location = @1;
16249 164 : $$ = (Node *) n;
16250 : }
16251 : | JSON_SCALAR '(' a_expr ')'
16252 : {
16253 112 : JsonScalarExpr *n = makeNode(JsonScalarExpr);
16254 :
16255 112 : n->expr = (Expr *) $3;
16256 112 : n->output = NULL;
16257 112 : n->location = @1;
16258 112 : $$ = (Node *) n;
16259 : }
16260 : | JSON_SERIALIZE '(' json_value_expr json_returning_clause_opt ')'
16261 : {
16262 108 : JsonSerializeExpr *n = makeNode(JsonSerializeExpr);
16263 :
16264 108 : n->expr = (JsonValueExpr *) $3;
16265 108 : n->output = (JsonOutput *) $4;
16266 108 : n->location = @1;
16267 108 : $$ = (Node *) n;
16268 : }
16269 : | MERGE_ACTION '(' ')'
16270 : {
16271 210 : MergeSupportFunc *m = makeNode(MergeSupportFunc);
16272 :
16273 210 : m->msftype = TEXTOID;
16274 210 : m->location = @1;
16275 210 : $$ = (Node *) m;
16276 : }
16277 : | JSON_QUERY '('
16278 : json_value_expr ',' a_expr json_passing_clause_opt
16279 : json_returning_clause_opt
16280 : json_wrapper_behavior
16281 : json_quotes_clause_opt
16282 : json_behavior_clause_opt
16283 : ')'
16284 : {
16285 984 : JsonFuncExpr *n = makeNode(JsonFuncExpr);
16286 :
16287 984 : n->op = JSON_QUERY_OP;
16288 984 : n->context_item = (JsonValueExpr *) $3;
16289 984 : n->pathspec = $5;
16290 984 : n->passing = $6;
16291 984 : n->output = (JsonOutput *) $7;
16292 984 : n->wrapper = $8;
16293 984 : n->quotes = $9;
16294 984 : n->on_empty = (JsonBehavior *) linitial($10);
16295 984 : n->on_error = (JsonBehavior *) lsecond($10);
16296 984 : n->location = @1;
16297 984 : $$ = (Node *) n;
16298 : }
16299 : | JSON_EXISTS '('
16300 : json_value_expr ',' a_expr json_passing_clause_opt
16301 : json_on_error_clause_opt
16302 : ')'
16303 : {
16304 168 : JsonFuncExpr *n = makeNode(JsonFuncExpr);
16305 :
16306 168 : n->op = JSON_EXISTS_OP;
16307 168 : n->context_item = (JsonValueExpr *) $3;
16308 168 : n->pathspec = $5;
16309 168 : n->passing = $6;
16310 168 : n->output = NULL;
16311 168 : n->on_error = (JsonBehavior *) $7;
16312 168 : n->location = @1;
16313 168 : $$ = (Node *) n;
16314 : }
16315 : | JSON_VALUE '('
16316 : json_value_expr ',' a_expr json_passing_clause_opt
16317 : json_returning_clause_opt
16318 : json_behavior_clause_opt
16319 : ')'
16320 : {
16321 576 : JsonFuncExpr *n = makeNode(JsonFuncExpr);
16322 :
16323 576 : n->op = JSON_VALUE_OP;
16324 576 : n->context_item = (JsonValueExpr *) $3;
16325 576 : n->pathspec = $5;
16326 576 : n->passing = $6;
16327 576 : n->output = (JsonOutput *) $7;
16328 576 : n->on_empty = (JsonBehavior *) linitial($8);
16329 576 : n->on_error = (JsonBehavior *) lsecond($8);
16330 576 : n->location = @1;
16331 576 : $$ = (Node *) n;
16332 : }
16333 : ;
16334 :
16335 :
16336 : /*
16337 : * SQL/XML support
16338 : */
16339 : xml_root_version: VERSION_P a_expr
16340 24 : { $$ = $2; }
16341 : | VERSION_P NO VALUE_P
16342 44 : { $$ = makeNullAConst(-1); }
16343 : ;
16344 :
16345 : opt_xml_root_standalone: ',' STANDALONE_P YES_P
16346 26 : { $$ = makeIntConst(XML_STANDALONE_YES, -1); }
16347 : | ',' STANDALONE_P NO
16348 12 : { $$ = makeIntConst(XML_STANDALONE_NO, -1); }
16349 : | ',' STANDALONE_P NO VALUE_P
16350 12 : { $$ = makeIntConst(XML_STANDALONE_NO_VALUE, -1); }
16351 : | /*EMPTY*/
16352 18 : { $$ = makeIntConst(XML_STANDALONE_OMITTED, -1); }
16353 : ;
16354 :
16355 56 : xml_attributes: XMLATTRIBUTES '(' xml_attribute_list ')' { $$ = $3; }
16356 : ;
16357 :
16358 88 : xml_attribute_list: xml_attribute_el { $$ = list_make1($1); }
16359 144 : | xml_attribute_list ',' xml_attribute_el { $$ = lappend($1, $3); }
16360 : ;
16361 :
16362 : xml_attribute_el: a_expr AS ColLabel
16363 : {
16364 106 : $$ = makeNode(ResTarget);
16365 106 : $$->name = $3;
16366 106 : $$->indirection = NIL;
16367 106 : $$->val = (Node *) $1;
16368 106 : $$->location = @1;
16369 : }
16370 : | a_expr
16371 : {
16372 126 : $$ = makeNode(ResTarget);
16373 126 : $$->name = NULL;
16374 126 : $$->indirection = NIL;
16375 126 : $$->val = (Node *) $1;
16376 126 : $$->location = @1;
16377 : }
16378 : ;
16379 :
16380 186 : document_or_content: DOCUMENT_P { $$ = XMLOPTION_DOCUMENT; }
16381 188 : | CONTENT_P { $$ = XMLOPTION_CONTENT; }
16382 : ;
16383 :
16384 140 : xml_indent_option: INDENT { $$ = true; }
16385 36 : | NO INDENT { $$ = false; }
16386 42 : | /*EMPTY*/ { $$ = false; }
16387 : ;
16388 :
16389 0 : xml_whitespace_option: PRESERVE WHITESPACE_P { $$ = true; }
16390 2 : | STRIP_P WHITESPACE_P { $$ = false; }
16391 138 : | /*EMPTY*/ { $$ = false; }
16392 : ;
16393 :
16394 : /* We allow several variants for SQL and other compatibility. */
16395 : xmlexists_argument:
16396 : PASSING c_expr
16397 : {
16398 238 : $$ = $2;
16399 : }
16400 : | PASSING c_expr xml_passing_mech
16401 : {
16402 0 : $$ = $2;
16403 : }
16404 : | PASSING xml_passing_mech c_expr
16405 : {
16406 42 : $$ = $3;
16407 : }
16408 : | PASSING xml_passing_mech c_expr xml_passing_mech
16409 : {
16410 6 : $$ = $3;
16411 : }
16412 : ;
16413 :
16414 : xml_passing_mech:
16415 : BY REF_P
16416 : | BY VALUE_P
16417 : ;
16418 :
16419 :
16420 : /*
16421 : * Aggregate decoration clauses
16422 : */
16423 : within_group_clause:
16424 348 : WITHIN GROUP_P '(' sort_clause ')' { $$ = $4; }
16425 314478 : | /*EMPTY*/ { $$ = NIL; }
16426 : ;
16427 :
16428 : filter_clause:
16429 862 : FILTER '(' WHERE a_expr ')' { $$ = $4; }
16430 314324 : | /*EMPTY*/ { $$ = NULL; }
16431 : ;
16432 :
16433 :
16434 : /*
16435 : * Window Definitions
16436 : */
16437 : window_clause:
16438 540 : WINDOW window_definition_list { $$ = $2; }
16439 473444 : | /*EMPTY*/ { $$ = NIL; }
16440 : ;
16441 :
16442 : window_definition_list:
16443 540 : window_definition { $$ = list_make1($1); }
16444 : | window_definition_list ',' window_definition
16445 12 : { $$ = lappend($1, $3); }
16446 : ;
16447 :
16448 : window_definition:
16449 : ColId AS window_specification
16450 : {
16451 552 : WindowDef *n = $3;
16452 :
16453 552 : n->name = $1;
16454 552 : $$ = n;
16455 : }
16456 : ;
16457 :
16458 : over_clause: OVER window_specification
16459 2622 : { $$ = $2; }
16460 : | OVER ColId
16461 : {
16462 954 : WindowDef *n = makeNode(WindowDef);
16463 :
16464 954 : n->name = $2;
16465 954 : n->refname = NULL;
16466 954 : n->partitionClause = NIL;
16467 954 : n->orderClause = NIL;
16468 954 : n->frameOptions = FRAMEOPTION_DEFAULTS;
16469 954 : n->startOffset = NULL;
16470 954 : n->endOffset = NULL;
16471 954 : n->location = @2;
16472 954 : $$ = n;
16473 : }
16474 : | /*EMPTY*/
16475 311604 : { $$ = NULL; }
16476 : ;
16477 :
16478 : window_specification: '(' opt_existing_window_name opt_partition_clause
16479 : opt_sort_clause opt_frame_clause ')'
16480 : {
16481 3174 : WindowDef *n = makeNode(WindowDef);
16482 :
16483 3174 : n->name = NULL;
16484 3174 : n->refname = $2;
16485 3174 : n->partitionClause = $3;
16486 3174 : n->orderClause = $4;
16487 : /* copy relevant fields of opt_frame_clause */
16488 3174 : n->frameOptions = $5->frameOptions;
16489 3174 : n->startOffset = $5->startOffset;
16490 3174 : n->endOffset = $5->endOffset;
16491 3174 : n->location = @1;
16492 3174 : $$ = n;
16493 : }
16494 : ;
16495 :
16496 : /*
16497 : * If we see PARTITION, RANGE, ROWS or GROUPS as the first token after the '('
16498 : * of a window_specification, we want the assumption to be that there is
16499 : * no existing_window_name; but those keywords are unreserved and so could
16500 : * be ColIds. We fix this by making them have the same precedence as IDENT
16501 : * and giving the empty production here a slightly higher precedence, so
16502 : * that the shift/reduce conflict is resolved in favor of reducing the rule.
16503 : * These keywords are thus precluded from being an existing_window_name but
16504 : * are not reserved for any other purpose.
16505 : */
16506 54 : opt_existing_window_name: ColId { $$ = $1; }
16507 3126 : | /*EMPTY*/ %prec Op { $$ = NULL; }
16508 : ;
16509 :
16510 926 : opt_partition_clause: PARTITION BY expr_list { $$ = $3; }
16511 2248 : | /*EMPTY*/ { $$ = NIL; }
16512 : ;
16513 :
16514 : /*
16515 : * For frame clauses, we return a WindowDef, but only some fields are used:
16516 : * frameOptions, startOffset, and endOffset.
16517 : */
16518 : opt_frame_clause:
16519 : RANGE frame_extent opt_window_exclusion_clause
16520 : {
16521 796 : WindowDef *n = $2;
16522 :
16523 796 : n->frameOptions |= FRAMEOPTION_NONDEFAULT | FRAMEOPTION_RANGE;
16524 796 : n->frameOptions |= $3;
16525 796 : $$ = n;
16526 : }
16527 : | ROWS frame_extent opt_window_exclusion_clause
16528 : {
16529 624 : WindowDef *n = $2;
16530 :
16531 624 : n->frameOptions |= FRAMEOPTION_NONDEFAULT | FRAMEOPTION_ROWS;
16532 624 : n->frameOptions |= $3;
16533 624 : $$ = n;
16534 : }
16535 : | GROUPS frame_extent opt_window_exclusion_clause
16536 : {
16537 204 : WindowDef *n = $2;
16538 :
16539 204 : n->frameOptions |= FRAMEOPTION_NONDEFAULT | FRAMEOPTION_GROUPS;
16540 204 : n->frameOptions |= $3;
16541 204 : $$ = n;
16542 : }
16543 : | /*EMPTY*/
16544 : {
16545 1550 : WindowDef *n = makeNode(WindowDef);
16546 :
16547 1550 : n->frameOptions = FRAMEOPTION_DEFAULTS;
16548 1550 : n->startOffset = NULL;
16549 1550 : n->endOffset = NULL;
16550 1550 : $$ = n;
16551 : }
16552 : ;
16553 :
16554 : frame_extent: frame_bound
16555 : {
16556 12 : WindowDef *n = $1;
16557 :
16558 : /* reject invalid cases */
16559 12 : if (n->frameOptions & FRAMEOPTION_START_UNBOUNDED_FOLLOWING)
16560 0 : ereport(ERROR,
16561 : (errcode(ERRCODE_WINDOWING_ERROR),
16562 : errmsg("frame start cannot be UNBOUNDED FOLLOWING"),
16563 : parser_errposition(@1)));
16564 12 : if (n->frameOptions & FRAMEOPTION_START_OFFSET_FOLLOWING)
16565 0 : ereport(ERROR,
16566 : (errcode(ERRCODE_WINDOWING_ERROR),
16567 : errmsg("frame starting from following row cannot end with current row"),
16568 : parser_errposition(@1)));
16569 12 : n->frameOptions |= FRAMEOPTION_END_CURRENT_ROW;
16570 12 : $$ = n;
16571 : }
16572 : | BETWEEN frame_bound AND frame_bound
16573 : {
16574 1612 : WindowDef *n1 = $2;
16575 1612 : WindowDef *n2 = $4;
16576 :
16577 : /* form merged options */
16578 1612 : int frameOptions = n1->frameOptions;
16579 : /* shift converts START_ options to END_ options */
16580 1612 : frameOptions |= n2->frameOptions << 1;
16581 1612 : frameOptions |= FRAMEOPTION_BETWEEN;
16582 : /* reject invalid cases */
16583 1612 : if (frameOptions & FRAMEOPTION_START_UNBOUNDED_FOLLOWING)
16584 0 : ereport(ERROR,
16585 : (errcode(ERRCODE_WINDOWING_ERROR),
16586 : errmsg("frame start cannot be UNBOUNDED FOLLOWING"),
16587 : parser_errposition(@2)));
16588 1612 : if (frameOptions & FRAMEOPTION_END_UNBOUNDED_PRECEDING)
16589 0 : ereport(ERROR,
16590 : (errcode(ERRCODE_WINDOWING_ERROR),
16591 : errmsg("frame end cannot be UNBOUNDED PRECEDING"),
16592 : parser_errposition(@4)));
16593 1612 : if ((frameOptions & FRAMEOPTION_START_CURRENT_ROW) &&
16594 460 : (frameOptions & FRAMEOPTION_END_OFFSET_PRECEDING))
16595 0 : ereport(ERROR,
16596 : (errcode(ERRCODE_WINDOWING_ERROR),
16597 : errmsg("frame starting from current row cannot have preceding rows"),
16598 : parser_errposition(@4)));
16599 1612 : if ((frameOptions & FRAMEOPTION_START_OFFSET_FOLLOWING) &&
16600 168 : (frameOptions & (FRAMEOPTION_END_OFFSET_PRECEDING |
16601 : FRAMEOPTION_END_CURRENT_ROW)))
16602 0 : ereport(ERROR,
16603 : (errcode(ERRCODE_WINDOWING_ERROR),
16604 : errmsg("frame starting from following row cannot have preceding rows"),
16605 : parser_errposition(@4)));
16606 1612 : n1->frameOptions = frameOptions;
16607 1612 : n1->endOffset = n2->startOffset;
16608 1612 : $$ = n1;
16609 : }
16610 : ;
16611 :
16612 : /*
16613 : * This is used for both frame start and frame end, with output set up on
16614 : * the assumption it's frame start; the frame_extent productions must reject
16615 : * invalid cases.
16616 : */
16617 : frame_bound:
16618 : UNBOUNDED PRECEDING
16619 : {
16620 198 : WindowDef *n = makeNode(WindowDef);
16621 :
16622 198 : n->frameOptions = FRAMEOPTION_START_UNBOUNDED_PRECEDING;
16623 198 : n->startOffset = NULL;
16624 198 : n->endOffset = NULL;
16625 198 : $$ = n;
16626 : }
16627 : | UNBOUNDED FOLLOWING
16628 : {
16629 376 : WindowDef *n = makeNode(WindowDef);
16630 :
16631 376 : n->frameOptions = FRAMEOPTION_START_UNBOUNDED_FOLLOWING;
16632 376 : n->startOffset = NULL;
16633 376 : n->endOffset = NULL;
16634 376 : $$ = n;
16635 : }
16636 : | CURRENT_P ROW
16637 : {
16638 604 : WindowDef *n = makeNode(WindowDef);
16639 :
16640 604 : n->frameOptions = FRAMEOPTION_START_CURRENT_ROW;
16641 604 : n->startOffset = NULL;
16642 604 : n->endOffset = NULL;
16643 604 : $$ = n;
16644 : }
16645 : | a_expr PRECEDING
16646 : {
16647 906 : WindowDef *n = makeNode(WindowDef);
16648 :
16649 906 : n->frameOptions = FRAMEOPTION_START_OFFSET_PRECEDING;
16650 906 : n->startOffset = $1;
16651 906 : n->endOffset = NULL;
16652 906 : $$ = n;
16653 : }
16654 : | a_expr FOLLOWING
16655 : {
16656 1152 : WindowDef *n = makeNode(WindowDef);
16657 :
16658 1152 : n->frameOptions = FRAMEOPTION_START_OFFSET_FOLLOWING;
16659 1152 : n->startOffset = $1;
16660 1152 : n->endOffset = NULL;
16661 1152 : $$ = n;
16662 : }
16663 : ;
16664 :
16665 : opt_window_exclusion_clause:
16666 84 : EXCLUDE CURRENT_P ROW { $$ = FRAMEOPTION_EXCLUDE_CURRENT_ROW; }
16667 96 : | EXCLUDE GROUP_P { $$ = FRAMEOPTION_EXCLUDE_GROUP; }
16668 150 : | EXCLUDE TIES { $$ = FRAMEOPTION_EXCLUDE_TIES; }
16669 18 : | EXCLUDE NO OTHERS { $$ = 0; }
16670 1276 : | /*EMPTY*/ { $$ = 0; }
16671 : ;
16672 :
16673 :
16674 : /*
16675 : * Supporting nonterminals for expressions.
16676 : */
16677 :
16678 : /* Explicit row production.
16679 : *
16680 : * SQL99 allows an optional ROW keyword, so we can now do single-element rows
16681 : * without conflicting with the parenthesized a_expr production. Without the
16682 : * ROW keyword, there must be more than one a_expr inside the parens.
16683 : */
16684 0 : row: ROW '(' expr_list ')' { $$ = $3; }
16685 0 : | ROW '(' ')' { $$ = NIL; }
16686 1932 : | '(' expr_list ',' a_expr ')' { $$ = lappend($2, $4); }
16687 : ;
16688 :
16689 3780 : explicit_row: ROW '(' expr_list ')' { $$ = $3; }
16690 36 : | ROW '(' ')' { $$ = NIL; }
16691 : ;
16692 :
16693 2706 : implicit_row: '(' expr_list ',' a_expr ')' { $$ = lappend($2, $4); }
16694 : ;
16695 :
16696 16722 : sub_type: ANY { $$ = ANY_SUBLINK; }
16697 0 : | SOME { $$ = ANY_SUBLINK; }
16698 324 : | ALL { $$ = ALL_SUBLINK; }
16699 : ;
16700 :
16701 11392 : all_Op: Op { $$ = $1; }
16702 29244 : | MathOp { $$ = $1; }
16703 : ;
16704 :
16705 40 : MathOp: '+' { $$ = "+"; }
16706 66 : | '-' { $$ = "-"; }
16707 152 : | '*' { $$ = "*"; }
16708 0 : | '/' { $$ = "/"; }
16709 8 : | '%' { $$ = "%"; }
16710 0 : | '^' { $$ = "^"; }
16711 978 : | '<' { $$ = "<"; }
16712 880 : | '>' { $$ = ">"; }
16713 24656 : | '=' { $$ = "="; }
16714 844 : | LESS_EQUALS { $$ = "<="; }
16715 836 : | GREATER_EQUALS { $$ = ">="; }
16716 784 : | NOT_EQUALS { $$ = "<>"; }
16717 : ;
16718 :
16719 : qual_Op: Op
16720 43662 : { $$ = list_make1(makeString($1)); }
16721 : | OPERATOR '(' any_operator ')'
16722 15780 : { $$ = $3; }
16723 : ;
16724 :
16725 : qual_all_Op:
16726 : all_Op
16727 1416 : { $$ = list_make1(makeString($1)); }
16728 : | OPERATOR '(' any_operator ')'
16729 34 : { $$ = $3; }
16730 : ;
16731 :
16732 : subquery_Op:
16733 : all_Op
16734 16742 : { $$ = list_make1(makeString($1)); }
16735 : | OPERATOR '(' any_operator ')'
16736 272 : { $$ = $3; }
16737 : | LIKE
16738 24 : { $$ = list_make1(makeString("~~")); }
16739 : | NOT_LA LIKE
16740 12 : { $$ = list_make1(makeString("!~~")); }
16741 : | ILIKE
16742 12 : { $$ = list_make1(makeString("~~*")); }
16743 : | NOT_LA ILIKE
16744 0 : { $$ = list_make1(makeString("!~~*")); }
16745 : /* cannot put SIMILAR TO here, because SIMILAR TO is a hack.
16746 : * the regular expression is preprocessed by a function (similar_to_escape),
16747 : * and the ~ operator for posix regular expressions is used.
16748 : * x SIMILAR TO y -> x ~ similar_to_escape(y)
16749 : * this transformation is made on the fly by the parser upwards.
16750 : * however the SubLink structure which handles any/some/all stuff
16751 : * is not ready for such a thing.
16752 : */
16753 : ;
16754 :
16755 : expr_list: a_expr
16756 : {
16757 161490 : $$ = list_make1($1);
16758 : }
16759 : | expr_list ',' a_expr
16760 : {
16761 146156 : $$ = lappend($1, $3);
16762 : }
16763 : ;
16764 :
16765 : /* function arguments can have names */
16766 : func_arg_list: func_arg_expr
16767 : {
16768 317916 : $$ = list_make1($1);
16769 : }
16770 : | func_arg_list ',' func_arg_expr
16771 : {
16772 280816 : $$ = lappend($1, $3);
16773 : }
16774 : ;
16775 :
16776 : func_arg_expr: a_expr
16777 : {
16778 552324 : $$ = $1;
16779 : }
16780 : | param_name COLON_EQUALS a_expr
16781 : {
16782 45504 : NamedArgExpr *na = makeNode(NamedArgExpr);
16783 :
16784 45504 : na->name = $1;
16785 45504 : na->arg = (Expr *) $3;
16786 45504 : na->argnumber = -1; /* until determined */
16787 45504 : na->location = @1;
16788 45504 : $$ = (Node *) na;
16789 : }
16790 : | param_name EQUALS_GREATER a_expr
16791 : {
16792 1696 : NamedArgExpr *na = makeNode(NamedArgExpr);
16793 :
16794 1696 : na->name = $1;
16795 1696 : na->arg = (Expr *) $3;
16796 1696 : na->argnumber = -1; /* until determined */
16797 1696 : na->location = @1;
16798 1696 : $$ = (Node *) na;
16799 : }
16800 : ;
16801 :
16802 252 : func_arg_list_opt: func_arg_list { $$ = $1; }
16803 0 : | /*EMPTY*/ { $$ = NIL; }
16804 : ;
16805 :
16806 2412 : type_list: Typename { $$ = list_make1($1); }
16807 942 : | type_list ',' Typename { $$ = lappend($1, $3); }
16808 : ;
16809 :
16810 : array_expr: '[' expr_list ']'
16811 : {
16812 7706 : $$ = makeAArrayExpr($2, @1, @3);
16813 : }
16814 : | '[' array_expr_list ']'
16815 : {
16816 412 : $$ = makeAArrayExpr($2, @1, @3);
16817 : }
16818 : | '[' ']'
16819 : {
16820 98 : $$ = makeAArrayExpr(NIL, @1, @2);
16821 : }
16822 : ;
16823 :
16824 412 : array_expr_list: array_expr { $$ = list_make1($1); }
16825 342 : | array_expr_list ',' array_expr { $$ = lappend($1, $3); }
16826 : ;
16827 :
16828 :
16829 : extract_list:
16830 : extract_arg FROM a_expr
16831 : {
16832 1382 : $$ = list_make2(makeStringConst($1, @1), $3);
16833 : }
16834 : ;
16835 :
16836 : /* Allow delimited string Sconst in extract_arg as an SQL extension.
16837 : * - thomas 2001-04-12
16838 : */
16839 : extract_arg:
16840 1124 : IDENT { $$ = $1; }
16841 72 : | YEAR_P { $$ = "year"; }
16842 42 : | MONTH_P { $$ = "month"; }
16843 54 : | DAY_P { $$ = "day"; }
16844 30 : | HOUR_P { $$ = "hour"; }
16845 30 : | MINUTE_P { $$ = "minute"; }
16846 30 : | SECOND_P { $$ = "second"; }
16847 0 : | Sconst { $$ = $1; }
16848 : ;
16849 :
16850 : unicode_normal_form:
16851 24 : NFC { $$ = "NFC"; }
16852 18 : | NFD { $$ = "NFD"; }
16853 18 : | NFKC { $$ = "NFKC"; }
16854 18 : | NFKD { $$ = "NFKD"; }
16855 : ;
16856 :
16857 : /* OVERLAY() arguments */
16858 : overlay_list:
16859 : a_expr PLACING a_expr FROM a_expr FOR a_expr
16860 : {
16861 : /* overlay(A PLACING B FROM C FOR D) is converted to overlay(A, B, C, D) */
16862 34 : $$ = list_make4($1, $3, $5, $7);
16863 : }
16864 : | a_expr PLACING a_expr FROM a_expr
16865 : {
16866 : /* overlay(A PLACING B FROM C) is converted to overlay(A, B, C) */
16867 48 : $$ = list_make3($1, $3, $5);
16868 : }
16869 : ;
16870 :
16871 : /* position_list uses b_expr not a_expr to avoid conflict with general IN */
16872 : position_list:
16873 400 : b_expr IN_P b_expr { $$ = list_make2($3, $1); }
16874 : ;
16875 :
16876 : /*
16877 : * SUBSTRING() arguments
16878 : *
16879 : * Note that SQL:1999 has both
16880 : * text FROM int FOR int
16881 : * and
16882 : * text FROM pattern FOR escape
16883 : *
16884 : * In the parser we map them both to a call to the substring() function and
16885 : * rely on type resolution to pick the right one.
16886 : *
16887 : * In SQL:2003, the second variant was changed to
16888 : * text SIMILAR pattern ESCAPE escape
16889 : * We could in theory map that to a different function internally, but
16890 : * since we still support the SQL:1999 version, we don't. However,
16891 : * ruleutils.c will reverse-list the call in the newer style.
16892 : */
16893 : substr_list:
16894 : a_expr FROM a_expr FOR a_expr
16895 : {
16896 122 : $$ = list_make3($1, $3, $5);
16897 : }
16898 : | a_expr FOR a_expr FROM a_expr
16899 : {
16900 : /* not legal per SQL, but might as well allow it */
16901 0 : $$ = list_make3($1, $5, $3);
16902 : }
16903 : | a_expr FROM a_expr
16904 : {
16905 : /*
16906 : * Because we aren't restricting data types here, this
16907 : * syntax can end up resolving to textregexsubstr().
16908 : * We've historically allowed that to happen, so continue
16909 : * to accept it. However, ruleutils.c will reverse-list
16910 : * such a call in regular function call syntax.
16911 : */
16912 370 : $$ = list_make2($1, $3);
16913 : }
16914 : | a_expr FOR a_expr
16915 : {
16916 : /* not legal per SQL */
16917 :
16918 : /*
16919 : * Since there are no cases where this syntax allows
16920 : * a textual FOR value, we forcibly cast the argument
16921 : * to int4. The possible matches in pg_proc are
16922 : * substring(text,int4) and substring(text,text),
16923 : * and we don't want the parser to choose the latter,
16924 : * which it is likely to do if the second argument
16925 : * is unknown or doesn't have an implicit cast to int4.
16926 : */
16927 36 : $$ = list_make3($1, makeIntConst(1, -1),
16928 : makeTypeCast($3,
16929 : SystemTypeName("int4"), -1));
16930 : }
16931 : | a_expr SIMILAR a_expr ESCAPE a_expr
16932 : {
16933 182 : $$ = list_make3($1, $3, $5);
16934 : }
16935 : ;
16936 :
16937 604 : trim_list: a_expr FROM expr_list { $$ = lappend($3, $1); }
16938 24 : | FROM expr_list { $$ = $2; }
16939 86 : | expr_list { $$ = $1; }
16940 : ;
16941 :
16942 : /*
16943 : * Define SQL-style CASE clause.
16944 : * - Full specification
16945 : * CASE WHEN a = b THEN c ... ELSE d END
16946 : * - Implicit argument
16947 : * CASE a WHEN b THEN c ... ELSE d END
16948 : */
16949 : case_expr: CASE case_arg when_clause_list case_default END_P
16950 : {
16951 39124 : CaseExpr *c = makeNode(CaseExpr);
16952 :
16953 39124 : c->casetype = InvalidOid; /* not analyzed yet */
16954 39124 : c->arg = (Expr *) $2;
16955 39124 : c->args = $3;
16956 39124 : c->defresult = (Expr *) $4;
16957 39124 : c->location = @1;
16958 39124 : $$ = (Node *) c;
16959 : }
16960 : ;
16961 :
16962 : when_clause_list:
16963 : /* There must be at least one */
16964 39124 : when_clause { $$ = list_make1($1); }
16965 29056 : | when_clause_list when_clause { $$ = lappend($1, $2); }
16966 : ;
16967 :
16968 : when_clause:
16969 : WHEN a_expr THEN a_expr
16970 : {
16971 68180 : CaseWhen *w = makeNode(CaseWhen);
16972 :
16973 68180 : w->expr = (Expr *) $2;
16974 68180 : w->result = (Expr *) $4;
16975 68180 : w->location = @1;
16976 68180 : $$ = (Node *) w;
16977 : }
16978 : ;
16979 :
16980 : case_default:
16981 29396 : ELSE a_expr { $$ = $2; }
16982 9728 : | /*EMPTY*/ { $$ = NULL; }
16983 : ;
16984 :
16985 6758 : case_arg: a_expr { $$ = $1; }
16986 32366 : | /*EMPTY*/ { $$ = NULL; }
16987 : ;
16988 :
16989 : columnref: ColId
16990 : {
16991 749222 : $$ = makeColumnRef($1, NIL, @1, yyscanner);
16992 : }
16993 : | ColId indirection
16994 : {
16995 1057032 : $$ = makeColumnRef($1, $2, @1, yyscanner);
16996 : }
16997 : ;
16998 :
16999 : indirection_el:
17000 : '.' attr_name
17001 : {
17002 1428990 : $$ = (Node *) makeString($2);
17003 : }
17004 : | '.' '*'
17005 : {
17006 6976 : $$ = (Node *) makeNode(A_Star);
17007 : }
17008 : | '[' a_expr ']'
17009 : {
17010 12906 : A_Indices *ai = makeNode(A_Indices);
17011 :
17012 12906 : ai->is_slice = false;
17013 12906 : ai->lidx = NULL;
17014 12906 : ai->uidx = $2;
17015 12906 : $$ = (Node *) ai;
17016 : }
17017 : | '[' opt_slice_bound ':' opt_slice_bound ']'
17018 : {
17019 588 : A_Indices *ai = makeNode(A_Indices);
17020 :
17021 588 : ai->is_slice = true;
17022 588 : ai->lidx = $2;
17023 588 : ai->uidx = $4;
17024 588 : $$ = (Node *) ai;
17025 : }
17026 : ;
17027 :
17028 : opt_slice_bound:
17029 996 : a_expr { $$ = $1; }
17030 180 : | /*EMPTY*/ { $$ = NULL; }
17031 : ;
17032 :
17033 : indirection:
17034 1428972 : indirection_el { $$ = list_make1($1); }
17035 3084 : | indirection indirection_el { $$ = lappend($1, $2); }
17036 : ;
17037 :
17038 : opt_indirection:
17039 195732 : /*EMPTY*/ { $$ = NIL; }
17040 17404 : | opt_indirection indirection_el { $$ = lappend($1, $2); }
17041 : ;
17042 :
17043 : opt_asymmetric: ASYMMETRIC
17044 : | /*EMPTY*/
17045 : ;
17046 :
17047 : /* SQL/JSON support */
17048 : json_passing_clause_opt:
17049 336 : PASSING json_arguments { $$ = $2; }
17050 1940 : | /*EMPTY*/ { $$ = NIL; }
17051 : ;
17052 :
17053 : json_arguments:
17054 336 : json_argument { $$ = list_make1($1); }
17055 126 : | json_arguments ',' json_argument { $$ = lappend($1, $3); }
17056 : ;
17057 :
17058 : json_argument:
17059 : json_value_expr AS ColLabel
17060 : {
17061 462 : JsonArgument *n = makeNode(JsonArgument);
17062 :
17063 462 : n->val = (JsonValueExpr *) $1;
17064 462 : n->name = $3;
17065 462 : $$ = (Node *) n;
17066 : }
17067 : ;
17068 :
17069 : /* ARRAY is a noise word */
17070 : json_wrapper_behavior:
17071 42 : WITHOUT WRAPPER { $$ = JSW_NONE; }
17072 0 : | WITHOUT ARRAY WRAPPER { $$ = JSW_NONE; }
17073 78 : | WITH WRAPPER { $$ = JSW_UNCONDITIONAL; }
17074 12 : | WITH ARRAY WRAPPER { $$ = JSW_UNCONDITIONAL; }
17075 0 : | WITH CONDITIONAL ARRAY WRAPPER { $$ = JSW_CONDITIONAL; }
17076 12 : | WITH UNCONDITIONAL ARRAY WRAPPER { $$ = JSW_UNCONDITIONAL; }
17077 36 : | WITH CONDITIONAL WRAPPER { $$ = JSW_CONDITIONAL; }
17078 6 : | WITH UNCONDITIONAL WRAPPER { $$ = JSW_UNCONDITIONAL; }
17079 1640 : | /* empty */ { $$ = JSW_UNSPEC; }
17080 : ;
17081 :
17082 : json_behavior:
17083 : DEFAULT a_expr
17084 384 : { $$ = (Node *) makeJsonBehavior(JSON_BEHAVIOR_DEFAULT, $2, @1); }
17085 : | json_behavior_type
17086 702 : { $$ = (Node *) makeJsonBehavior($1, NULL, @1); }
17087 : ;
17088 :
17089 : json_behavior_type:
17090 492 : ERROR_P { $$ = JSON_BEHAVIOR_ERROR; }
17091 30 : | NULL_P { $$ = JSON_BEHAVIOR_NULL; }
17092 30 : | TRUE_P { $$ = JSON_BEHAVIOR_TRUE; }
17093 12 : | FALSE_P { $$ = JSON_BEHAVIOR_FALSE; }
17094 12 : | UNKNOWN { $$ = JSON_BEHAVIOR_UNKNOWN; }
17095 30 : | EMPTY_P ARRAY { $$ = JSON_BEHAVIOR_EMPTY_ARRAY; }
17096 72 : | EMPTY_P OBJECT_P { $$ = JSON_BEHAVIOR_EMPTY_OBJECT; }
17097 : /* non-standard, for Oracle compatibility only */
17098 24 : | EMPTY_P { $$ = JSON_BEHAVIOR_EMPTY_ARRAY; }
17099 : ;
17100 :
17101 : json_behavior_clause_opt:
17102 : json_behavior ON EMPTY_P
17103 174 : { $$ = list_make2($1, NULL); }
17104 : | json_behavior ON ERROR_P
17105 552 : { $$ = list_make2(NULL, $1); }
17106 : | json_behavior ON EMPTY_P json_behavior ON ERROR_P
17107 102 : { $$ = list_make2($1, $4); }
17108 : | /* EMPTY */
17109 1574 : { $$ = list_make2(NULL, NULL); }
17110 : ;
17111 :
17112 : json_on_error_clause_opt:
17113 : json_behavior ON ERROR_P
17114 150 : { $$ = $1; }
17115 : | /* EMPTY */
17116 692 : { $$ = NULL; }
17117 : ;
17118 :
17119 : json_value_expr:
17120 : a_expr json_format_clause_opt
17121 : {
17122 : /* formatted_expr will be set during parse-analysis. */
17123 4232 : $$ = (Node *) makeJsonValueExpr((Expr *) $1, NULL,
17124 4232 : castNode(JsonFormat, $2));
17125 : }
17126 : ;
17127 :
17128 : json_format_clause:
17129 : FORMAT_LA JSON ENCODING name
17130 : {
17131 : int encoding;
17132 :
17133 100 : if (!pg_strcasecmp($4, "utf8"))
17134 64 : encoding = JS_ENC_UTF8;
17135 36 : else if (!pg_strcasecmp($4, "utf16"))
17136 12 : encoding = JS_ENC_UTF16;
17137 24 : else if (!pg_strcasecmp($4, "utf32"))
17138 12 : encoding = JS_ENC_UTF32;
17139 : else
17140 12 : ereport(ERROR,
17141 : (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
17142 : errmsg("unrecognized JSON encoding: %s", $4),
17143 : parser_errposition(@4)));
17144 :
17145 88 : $$ = (Node *) makeJsonFormat(JS_FORMAT_JSON, encoding, @1);
17146 : }
17147 : | FORMAT_LA JSON
17148 : {
17149 412 : $$ = (Node *) makeJsonFormat(JS_FORMAT_JSON, JS_ENC_DEFAULT, @1);
17150 : }
17151 : ;
17152 :
17153 : json_format_clause_opt:
17154 : json_format_clause
17155 : {
17156 392 : $$ = $1;
17157 : }
17158 : | /* EMPTY */
17159 : {
17160 5344 : $$ = (Node *) makeJsonFormat(JS_FORMAT_DEFAULT, JS_ENC_DEFAULT, -1);
17161 : }
17162 : ;
17163 :
17164 : json_quotes_clause_opt:
17165 12 : KEEP QUOTES ON SCALAR STRING_P { $$ = JS_QUOTES_KEEP; }
17166 90 : | KEEP QUOTES { $$ = JS_QUOTES_KEEP; }
17167 12 : | OMIT QUOTES ON SCALAR STRING_P { $$ = JS_QUOTES_OMIT; }
17168 168 : | OMIT QUOTES { $$ = JS_QUOTES_OMIT; }
17169 1544 : | /* EMPTY */ { $$ = JS_QUOTES_UNSPEC; }
17170 : ;
17171 :
17172 : json_returning_clause_opt:
17173 : RETURNING Typename json_format_clause_opt
17174 : {
17175 1444 : JsonOutput *n = makeNode(JsonOutput);
17176 :
17177 1444 : n->typeName = $2;
17178 1444 : n->returning = makeNode(JsonReturning);
17179 1444 : n->returning->format = (JsonFormat *) $3;
17180 1444 : $$ = (Node *) n;
17181 : }
17182 1290 : | /* EMPTY */ { $$ = NULL; }
17183 : ;
17184 :
17185 : /*
17186 : * We must assign the only-JSON production a precedence less than IDENT in
17187 : * order to favor shifting over reduction when JSON is followed by VALUE_P,
17188 : * OBJECT_P, or SCALAR. (ARRAY doesn't need that treatment, because it's a
17189 : * fully reserved word.) Because json_predicate_type_constraint is always
17190 : * followed by json_key_uniqueness_constraint_opt, we also need the only-JSON
17191 : * production to have precedence less than WITH and WITHOUT. UNBOUNDED isn't
17192 : * really related to this syntax, but it's a convenient choice because it
17193 : * already has a precedence less than IDENT for other reasons.
17194 : */
17195 : json_predicate_type_constraint:
17196 202 : JSON %prec UNBOUNDED { $$ = JS_TYPE_ANY; }
17197 28 : | JSON VALUE_P { $$ = JS_TYPE_ANY; }
17198 40 : | JSON ARRAY { $$ = JS_TYPE_ARRAY; }
17199 40 : | JSON OBJECT_P { $$ = JS_TYPE_OBJECT; }
17200 40 : | JSON SCALAR { $$ = JS_TYPE_SCALAR; }
17201 : ;
17202 :
17203 : /*
17204 : * KEYS is a noise word here. To avoid shift/reduce conflicts, assign the
17205 : * KEYS-less productions a precedence less than IDENT (i.e., less than KEYS).
17206 : * This prevents reducing them when the next token is KEYS.
17207 : */
17208 : json_key_uniqueness_constraint_opt:
17209 108 : WITH UNIQUE KEYS { $$ = true; }
17210 100 : | WITH UNIQUE %prec UNBOUNDED { $$ = true; }
17211 44 : | WITHOUT UNIQUE KEYS { $$ = false; }
17212 16 : | WITHOUT UNIQUE %prec UNBOUNDED { $$ = false; }
17213 798 : | /* EMPTY */ %prec UNBOUNDED { $$ = false; }
17214 : ;
17215 :
17216 : json_name_and_value_list:
17217 : json_name_and_value
17218 348 : { $$ = list_make1($1); }
17219 : | json_name_and_value_list ',' json_name_and_value
17220 256 : { $$ = lappend($1, $3); }
17221 : ;
17222 :
17223 : json_name_and_value:
17224 : /* Supporting this syntax seems to require major surgery
17225 : KEY c_expr VALUE_P json_value_expr
17226 : { $$ = makeJsonKeyValue($2, $4); }
17227 : |
17228 : */
17229 : c_expr VALUE_P json_value_expr
17230 24 : { $$ = makeJsonKeyValue($1, $3); }
17231 : |
17232 : a_expr ':' json_value_expr
17233 784 : { $$ = makeJsonKeyValue($1, $3); }
17234 : ;
17235 :
17236 : /* empty means false for objects, true for arrays */
17237 : json_object_constructor_null_clause_opt:
17238 30 : NULL_P ON NULL_P { $$ = false; }
17239 110 : | ABSENT ON NULL_P { $$ = true; }
17240 412 : | /* EMPTY */ { $$ = false; }
17241 : ;
17242 :
17243 : json_array_constructor_null_clause_opt:
17244 60 : NULL_P ON NULL_P { $$ = false; }
17245 36 : | ABSENT ON NULL_P { $$ = true; }
17246 180 : | /* EMPTY */ { $$ = true; }
17247 : ;
17248 :
17249 : json_value_expr_list:
17250 120 : json_value_expr { $$ = list_make1($1); }
17251 138 : | json_value_expr_list ',' json_value_expr { $$ = lappend($1, $3);}
17252 : ;
17253 :
17254 : json_aggregate_func:
17255 : JSON_OBJECTAGG '('
17256 : json_name_and_value
17257 : json_object_constructor_null_clause_opt
17258 : json_key_uniqueness_constraint_opt
17259 : json_returning_clause_opt
17260 : ')'
17261 : {
17262 204 : JsonObjectAgg *n = makeNode(JsonObjectAgg);
17263 :
17264 204 : n->arg = (JsonKeyValue *) $3;
17265 204 : n->absent_on_null = $4;
17266 204 : n->unique = $5;
17267 204 : n->constructor = makeNode(JsonAggConstructor);
17268 204 : n->constructor->output = (JsonOutput *) $6;
17269 204 : n->constructor->agg_order = NULL;
17270 204 : n->constructor->location = @1;
17271 204 : $$ = (Node *) n;
17272 : }
17273 : | JSON_ARRAYAGG '('
17274 : json_value_expr
17275 : json_array_aggregate_order_by_clause_opt
17276 : json_array_constructor_null_clause_opt
17277 : json_returning_clause_opt
17278 : ')'
17279 : {
17280 156 : JsonArrayAgg *n = makeNode(JsonArrayAgg);
17281 :
17282 156 : n->arg = (JsonValueExpr *) $3;
17283 156 : n->absent_on_null = $5;
17284 156 : n->constructor = makeNode(JsonAggConstructor);
17285 156 : n->constructor->agg_order = $4;
17286 156 : n->constructor->output = (JsonOutput *) $6;
17287 156 : n->constructor->location = @1;
17288 156 : $$ = (Node *) n;
17289 : }
17290 : ;
17291 :
17292 : json_array_aggregate_order_by_clause_opt:
17293 18 : ORDER BY sortby_list { $$ = $3; }
17294 138 : | /* EMPTY */ { $$ = NIL; }
17295 : ;
17296 :
17297 : /*****************************************************************************
17298 : *
17299 : * target list for SELECT
17300 : *
17301 : *****************************************************************************/
17302 :
17303 469788 : opt_target_list: target_list { $$ = $1; }
17304 552 : | /* EMPTY */ { $$ = NIL; }
17305 : ;
17306 :
17307 : target_list:
17308 476652 : target_el { $$ = list_make1($1); }
17309 675298 : | target_list ',' target_el { $$ = lappend($1, $3); }
17310 : ;
17311 :
17312 : target_el: a_expr AS ColLabel
17313 : {
17314 236160 : $$ = makeNode(ResTarget);
17315 236160 : $$->name = $3;
17316 236160 : $$->indirection = NIL;
17317 236160 : $$->val = (Node *) $1;
17318 236160 : $$->location = @1;
17319 : }
17320 : | a_expr BareColLabel
17321 : {
17322 3562 : $$ = makeNode(ResTarget);
17323 3562 : $$->name = $2;
17324 3562 : $$->indirection = NIL;
17325 3562 : $$->val = (Node *) $1;
17326 3562 : $$->location = @1;
17327 : }
17328 : | a_expr
17329 : {
17330 855840 : $$ = makeNode(ResTarget);
17331 855838 : $$->name = NULL;
17332 855838 : $$->indirection = NIL;
17333 855838 : $$->val = (Node *) $1;
17334 855838 : $$->location = @1;
17335 : }
17336 : | '*'
17337 : {
17338 56388 : ColumnRef *n = makeNode(ColumnRef);
17339 :
17340 56388 : n->fields = list_make1(makeNode(A_Star));
17341 56388 : n->location = @1;
17342 :
17343 56388 : $$ = makeNode(ResTarget);
17344 56388 : $$->name = NULL;
17345 56388 : $$->indirection = NIL;
17346 56388 : $$->val = (Node *) n;
17347 56388 : $$->location = @1;
17348 : }
17349 : ;
17350 :
17351 :
17352 : /*****************************************************************************
17353 : *
17354 : * Names and constants
17355 : *
17356 : *****************************************************************************/
17357 :
17358 : qualified_name_list:
17359 17382 : qualified_name { $$ = list_make1($1); }
17360 454 : | qualified_name_list ',' qualified_name { $$ = lappend($1, $3); }
17361 : ;
17362 :
17363 : /*
17364 : * The production for a qualified relation name has to exactly match the
17365 : * production for a qualified func_name, because in a FROM clause we cannot
17366 : * tell which we are parsing until we see what comes after it ('(' for a
17367 : * func_name, something else for a relation). Therefore we allow 'indirection'
17368 : * which may contain subscripts, and reject that case in the C code.
17369 : */
17370 : qualified_name:
17371 : ColId
17372 : {
17373 420618 : $$ = makeRangeVar(NULL, $1, @1);
17374 : }
17375 : | ColId indirection
17376 : {
17377 245178 : $$ = makeRangeVarFromQualifiedName($1, $2, @1, yyscanner);
17378 : }
17379 : ;
17380 :
17381 : name_list: name
17382 28340 : { $$ = list_make1(makeString($1)); }
17383 : | name_list ',' name
17384 61566 : { $$ = lappend($1, makeString($3)); }
17385 : ;
17386 :
17387 :
17388 176908 : name: ColId { $$ = $1; };
17389 :
17390 1555890 : attr_name: ColLabel { $$ = $1; };
17391 :
17392 64 : file_name: Sconst { $$ = $1; };
17393 :
17394 : /*
17395 : * The production for a qualified func_name has to exactly match the
17396 : * production for a qualified columnref, because we cannot tell which we
17397 : * are parsing until we see what comes after it ('(' or Sconst for a func_name,
17398 : * anything else for a columnref). Therefore we allow 'indirection' which
17399 : * may contain subscripts, and reject that case in the C code. (If we
17400 : * ever implement SQL99-like methods, such syntax may actually become legal!)
17401 : */
17402 : func_name: type_function_name
17403 295616 : { $$ = list_make1(makeString($1)); }
17404 : | ColId indirection
17405 : {
17406 126684 : $$ = check_func_name(lcons(makeString($1), $2),
17407 : yyscanner);
17408 : }
17409 : ;
17410 :
17411 :
17412 : /*
17413 : * Constants
17414 : */
17415 : AexprConst: Iconst
17416 : {
17417 377086 : $$ = makeIntConst($1, @1);
17418 : }
17419 : | FCONST
17420 : {
17421 11718 : $$ = makeFloatConst($1, @1);
17422 : }
17423 : | Sconst
17424 : {
17425 694346 : $$ = makeStringConst($1, @1);
17426 : }
17427 : | BCONST
17428 : {
17429 754 : $$ = makeBitStringConst($1, @1);
17430 : }
17431 : | XCONST
17432 : {
17433 : /* This is a bit constant per SQL99:
17434 : * Without Feature F511, "BIT data type",
17435 : * a <general literal> shall not be a
17436 : * <bit string literal> or a <hex string literal>.
17437 : */
17438 3302 : $$ = makeBitStringConst($1, @1);
17439 : }
17440 : | func_name Sconst
17441 : {
17442 : /* generic type 'literal' syntax */
17443 9842 : TypeName *t = makeTypeNameFromNameList($1);
17444 :
17445 9842 : t->location = @1;
17446 9842 : $$ = makeStringConstCast($2, @2, t);
17447 : }
17448 : | func_name '(' func_arg_list opt_sort_clause ')' Sconst
17449 : {
17450 : /* generic syntax with a type modifier */
17451 0 : TypeName *t = makeTypeNameFromNameList($1);
17452 : ListCell *lc;
17453 :
17454 : /*
17455 : * We must use func_arg_list and opt_sort_clause in the
17456 : * production to avoid reduce/reduce conflicts, but we
17457 : * don't actually wish to allow NamedArgExpr in this
17458 : * context, nor ORDER BY.
17459 : */
17460 0 : foreach(lc, $3)
17461 : {
17462 0 : NamedArgExpr *arg = (NamedArgExpr *) lfirst(lc);
17463 :
17464 0 : if (IsA(arg, NamedArgExpr))
17465 0 : ereport(ERROR,
17466 : (errcode(ERRCODE_SYNTAX_ERROR),
17467 : errmsg("type modifier cannot have parameter name"),
17468 : parser_errposition(arg->location)));
17469 : }
17470 0 : if ($4 != NIL)
17471 0 : ereport(ERROR,
17472 : (errcode(ERRCODE_SYNTAX_ERROR),
17473 : errmsg("type modifier cannot have ORDER BY"),
17474 : parser_errposition(@4)));
17475 :
17476 0 : t->typmods = $3;
17477 0 : t->location = @1;
17478 0 : $$ = makeStringConstCast($6, @6, t);
17479 : }
17480 : | ConstTypename Sconst
17481 : {
17482 3174 : $$ = makeStringConstCast($2, @2, $1);
17483 : }
17484 : | ConstInterval Sconst opt_interval
17485 : {
17486 3298 : TypeName *t = $1;
17487 :
17488 3298 : t->typmods = $3;
17489 3298 : $$ = makeStringConstCast($2, @2, t);
17490 : }
17491 : | ConstInterval '(' Iconst ')' Sconst
17492 : {
17493 12 : TypeName *t = $1;
17494 :
17495 12 : t->typmods = list_make2(makeIntConst(INTERVAL_FULL_RANGE, -1),
17496 : makeIntConst($3, @3));
17497 12 : $$ = makeStringConstCast($5, @5, t);
17498 : }
17499 : | TRUE_P
17500 : {
17501 31156 : $$ = makeBoolAConst(true, @1);
17502 : }
17503 : | FALSE_P
17504 : {
17505 35814 : $$ = makeBoolAConst(false, @1);
17506 : }
17507 : | NULL_P
17508 : {
17509 67240 : $$ = makeNullAConst(@1);
17510 : }
17511 : ;
17512 :
17513 405296 : Iconst: ICONST { $$ = $1; };
17514 767754 : Sconst: SCONST { $$ = $1; };
17515 :
17516 17462 : SignedIconst: Iconst { $$ = $1; }
17517 0 : | '+' Iconst { $$ = + $2; }
17518 288 : | '-' Iconst { $$ = - $2; }
17519 : ;
17520 :
17521 : /* Role specifications */
17522 : RoleId: RoleSpec
17523 : {
17524 1938 : RoleSpec *spc = (RoleSpec *) $1;
17525 :
17526 1938 : switch (spc->roletype)
17527 : {
17528 1928 : case ROLESPEC_CSTRING:
17529 1928 : $$ = spc->rolename;
17530 1928 : break;
17531 4 : case ROLESPEC_PUBLIC:
17532 4 : ereport(ERROR,
17533 : (errcode(ERRCODE_RESERVED_NAME),
17534 : errmsg("role name \"%s\" is reserved",
17535 : "public"),
17536 : parser_errposition(@1)));
17537 : break;
17538 2 : case ROLESPEC_SESSION_USER:
17539 2 : ereport(ERROR,
17540 : (errcode(ERRCODE_RESERVED_NAME),
17541 : errmsg("%s cannot be used as a role name here",
17542 : "SESSION_USER"),
17543 : parser_errposition(@1)));
17544 : break;
17545 2 : case ROLESPEC_CURRENT_USER:
17546 2 : ereport(ERROR,
17547 : (errcode(ERRCODE_RESERVED_NAME),
17548 : errmsg("%s cannot be used as a role name here",
17549 : "CURRENT_USER"),
17550 : parser_errposition(@1)));
17551 : break;
17552 2 : case ROLESPEC_CURRENT_ROLE:
17553 2 : ereport(ERROR,
17554 : (errcode(ERRCODE_RESERVED_NAME),
17555 : errmsg("%s cannot be used as a role name here",
17556 : "CURRENT_ROLE"),
17557 : parser_errposition(@1)));
17558 : break;
17559 : }
17560 : }
17561 : ;
17562 :
17563 : RoleSpec: NonReservedWord
17564 : {
17565 : /*
17566 : * "public" and "none" are not keywords, but they must
17567 : * be treated specially here.
17568 : */
17569 : RoleSpec *n;
17570 :
17571 32354 : if (strcmp($1, "public") == 0)
17572 : {
17573 17482 : n = (RoleSpec *) makeRoleSpec(ROLESPEC_PUBLIC, @1);
17574 17482 : n->roletype = ROLESPEC_PUBLIC;
17575 : }
17576 14872 : else if (strcmp($1, "none") == 0)
17577 : {
17578 26 : ereport(ERROR,
17579 : (errcode(ERRCODE_RESERVED_NAME),
17580 : errmsg("role name \"%s\" is reserved",
17581 : "none"),
17582 : parser_errposition(@1)));
17583 : }
17584 : else
17585 : {
17586 14846 : n = makeRoleSpec(ROLESPEC_CSTRING, @1);
17587 14846 : n->rolename = pstrdup($1);
17588 : }
17589 32328 : $$ = n;
17590 : }
17591 : | CURRENT_ROLE
17592 : {
17593 130 : $$ = makeRoleSpec(ROLESPEC_CURRENT_ROLE, @1);
17594 : }
17595 : | CURRENT_USER
17596 : {
17597 228 : $$ = makeRoleSpec(ROLESPEC_CURRENT_USER, @1);
17598 : }
17599 : | SESSION_USER
17600 : {
17601 36 : $$ = makeRoleSpec(ROLESPEC_SESSION_USER, @1);
17602 : }
17603 : ;
17604 :
17605 : role_list: RoleSpec
17606 3240 : { $$ = list_make1($1); }
17607 : | role_list ',' RoleSpec
17608 270 : { $$ = lappend($1, $3); }
17609 : ;
17610 :
17611 :
17612 : /*****************************************************************************
17613 : *
17614 : * PL/pgSQL extensions
17615 : *
17616 : * You'd think a PL/pgSQL "expression" should be just an a_expr, but
17617 : * historically it can include just about anything that can follow SELECT.
17618 : * Therefore the returned struct is a SelectStmt.
17619 : *****************************************************************************/
17620 :
17621 : PLpgSQL_Expr: opt_distinct_clause opt_target_list
17622 : from_clause where_clause
17623 : group_clause having_clause window_clause
17624 : opt_sort_clause opt_select_limit opt_for_locking_clause
17625 : {
17626 40342 : SelectStmt *n = makeNode(SelectStmt);
17627 :
17628 40342 : n->distinctClause = $1;
17629 40342 : n->targetList = $2;
17630 40342 : n->fromClause = $3;
17631 40342 : n->whereClause = $4;
17632 40342 : n->groupClause = ($5)->list;
17633 40342 : n->groupDistinct = ($5)->distinct;
17634 40342 : n->groupByAll = ($5)->all;
17635 40342 : n->havingClause = $6;
17636 40342 : n->windowClause = $7;
17637 40342 : n->sortClause = $8;
17638 40342 : if ($9)
17639 : {
17640 4 : n->limitOffset = $9->limitOffset;
17641 4 : n->limitCount = $9->limitCount;
17642 4 : if (!n->sortClause &&
17643 4 : $9->limitOption == LIMIT_OPTION_WITH_TIES)
17644 0 : ereport(ERROR,
17645 : (errcode(ERRCODE_SYNTAX_ERROR),
17646 : errmsg("WITH TIES cannot be specified without ORDER BY clause"),
17647 : parser_errposition($9->optionLoc)));
17648 4 : n->limitOption = $9->limitOption;
17649 : }
17650 40342 : n->lockingClause = $10;
17651 40342 : $$ = (Node *) n;
17652 : }
17653 : ;
17654 :
17655 : /*
17656 : * PL/pgSQL Assignment statement: name opt_indirection := PLpgSQL_Expr
17657 : */
17658 :
17659 : PLAssignStmt: plassign_target opt_indirection plassign_equals PLpgSQL_Expr
17660 : {
17661 7044 : PLAssignStmt *n = makeNode(PLAssignStmt);
17662 :
17663 7044 : n->name = $1;
17664 7044 : n->indirection = check_indirection($2, yyscanner);
17665 : /* nnames will be filled by calling production */
17666 6950 : n->val = (SelectStmt *) $4;
17667 6950 : n->location = @1;
17668 6950 : $$ = (Node *) n;
17669 : }
17670 : ;
17671 :
17672 7020 : plassign_target: ColId { $$ = $1; }
17673 24 : | PARAM { $$ = psprintf("$%d", $1); }
17674 : ;
17675 :
17676 : plassign_equals: COLON_EQUALS
17677 : | '='
17678 : ;
17679 :
17680 :
17681 : /*
17682 : * Name classification hierarchy.
17683 : *
17684 : * IDENT is the lexeme returned by the lexer for identifiers that match
17685 : * no known keyword. In most cases, we can accept certain keywords as
17686 : * names, not only IDENTs. We prefer to accept as many such keywords
17687 : * as possible to minimize the impact of "reserved words" on programmers.
17688 : * So, we divide names into several possible classes. The classification
17689 : * is chosen in part to make keywords acceptable as names wherever possible.
17690 : */
17691 :
17692 : /* Column identifier --- names that can be column, table, etc names.
17693 : */
17694 3366038 : ColId: IDENT { $$ = $1; }
17695 57738 : | unreserved_keyword { $$ = pstrdup($1); }
17696 6174 : | col_name_keyword { $$ = pstrdup($1); }
17697 : ;
17698 :
17699 : /* Type/function identifier --- names that can be type or function names.
17700 : */
17701 712562 : type_function_name: IDENT { $$ = $1; }
17702 74714 : | unreserved_keyword { $$ = pstrdup($1); }
17703 66 : | type_func_name_keyword { $$ = pstrdup($1); }
17704 : ;
17705 :
17706 : /* Any not-fully-reserved word --- these names can be, eg, role names.
17707 : */
17708 83458 : NonReservedWord: IDENT { $$ = $1; }
17709 30368 : | unreserved_keyword { $$ = pstrdup($1); }
17710 178 : | col_name_keyword { $$ = pstrdup($1); }
17711 5278 : | type_func_name_keyword { $$ = pstrdup($1); }
17712 : ;
17713 :
17714 : /* Column label --- allowed labels in "AS" clauses.
17715 : * This presently includes *all* Postgres keywords.
17716 : */
17717 1776004 : ColLabel: IDENT { $$ = $1; }
17718 39868 : | unreserved_keyword { $$ = pstrdup($1); }
17719 284 : | col_name_keyword { $$ = pstrdup($1); }
17720 1784 : | type_func_name_keyword { $$ = pstrdup($1); }
17721 7508 : | reserved_keyword { $$ = pstrdup($1); }
17722 : ;
17723 :
17724 : /* Bare column label --- names that can be column labels without writing "AS".
17725 : * This classification is orthogonal to the other keyword categories.
17726 : */
17727 3548 : BareColLabel: IDENT { $$ = $1; }
17728 14 : | bare_label_keyword { $$ = pstrdup($1); }
17729 : ;
17730 :
17731 :
17732 : /*
17733 : * Keyword category lists. Generally, every keyword present in
17734 : * the Postgres grammar should appear in exactly one of these lists.
17735 : *
17736 : * Put a new keyword into the first list that it can go into without causing
17737 : * shift or reduce conflicts. The earlier lists define "less reserved"
17738 : * categories of keywords.
17739 : *
17740 : * Make sure that each keyword's category in kwlist.h matches where
17741 : * it is listed here. (Someday we may be able to generate these lists and
17742 : * kwlist.h's table from one source of truth.)
17743 : */
17744 :
17745 : /* "Unreserved" keywords --- available for use as any kind of name.
17746 : */
17747 : unreserved_keyword:
17748 : ABORT_P
17749 : | ABSENT
17750 : | ABSOLUTE_P
17751 : | ACCESS
17752 : | ACTION
17753 : | ADD_P
17754 : | ADMIN
17755 : | AFTER
17756 : | AGGREGATE
17757 : | ALSO
17758 : | ALTER
17759 : | ALWAYS
17760 : | ASENSITIVE
17761 : | ASSERTION
17762 : | ASSIGNMENT
17763 : | AT
17764 : | ATOMIC
17765 : | ATTACH
17766 : | ATTRIBUTE
17767 : | BACKWARD
17768 : | BEFORE
17769 : | BEGIN_P
17770 : | BREADTH
17771 : | BY
17772 : | CACHE
17773 : | CALL
17774 : | CALLED
17775 : | CASCADE
17776 : | CASCADED
17777 : | CATALOG_P
17778 : | CHAIN
17779 : | CHARACTERISTICS
17780 : | CHECKPOINT
17781 : | CLASS
17782 : | CLOSE
17783 : | CLUSTER
17784 : | COLUMNS
17785 : | COMMENT
17786 : | COMMENTS
17787 : | COMMIT
17788 : | COMMITTED
17789 : | COMPRESSION
17790 : | CONDITIONAL
17791 : | CONFIGURATION
17792 : | CONFLICT
17793 : | CONNECTION
17794 : | CONSTRAINTS
17795 : | CONTENT_P
17796 : | CONTINUE_P
17797 : | CONVERSION_P
17798 : | COPY
17799 : | COST
17800 : | CSV
17801 : | CUBE
17802 : | CURRENT_P
17803 : | CURSOR
17804 : | CYCLE
17805 : | DATA_P
17806 : | DATABASE
17807 : | DAY_P
17808 : | DEALLOCATE
17809 : | DECLARE
17810 : | DEFAULTS
17811 : | DEFERRED
17812 : | DEFINER
17813 : | DELETE_P
17814 : | DELIMITER
17815 : | DELIMITERS
17816 : | DEPENDS
17817 : | DEPTH
17818 : | DETACH
17819 : | DICTIONARY
17820 : | DISABLE_P
17821 : | DISCARD
17822 : | DOCUMENT_P
17823 : | DOMAIN_P
17824 : | DOUBLE_P
17825 : | DROP
17826 : | EACH
17827 : | EMPTY_P
17828 : | ENABLE_P
17829 : | ENCODING
17830 : | ENCRYPTED
17831 : | ENFORCED
17832 : | ENUM_P
17833 : | ERROR_P
17834 : | ESCAPE
17835 : | EVENT
17836 : | EXCLUDE
17837 : | EXCLUDING
17838 : | EXCLUSIVE
17839 : | EXECUTE
17840 : | EXPLAIN
17841 : | EXPRESSION
17842 : | EXTENSION
17843 : | EXTERNAL
17844 : | FAMILY
17845 : | FILTER
17846 : | FINALIZE
17847 : | FIRST_P
17848 : | FOLLOWING
17849 : | FORCE
17850 : | FORMAT
17851 : | FORWARD
17852 : | FUNCTION
17853 : | FUNCTIONS
17854 : | GENERATED
17855 : | GLOBAL
17856 : | GRANTED
17857 : | GROUPS
17858 : | HANDLER
17859 : | HEADER_P
17860 : | HOLD
17861 : | HOUR_P
17862 : | IDENTITY_P
17863 : | IF_P
17864 : | IMMEDIATE
17865 : | IMMUTABLE
17866 : | IMPLICIT_P
17867 : | IMPORT_P
17868 : | INCLUDE
17869 : | INCLUDING
17870 : | INCREMENT
17871 : | INDENT
17872 : | INDEX
17873 : | INDEXES
17874 : | INHERIT
17875 : | INHERITS
17876 : | INLINE_P
17877 : | INPUT_P
17878 : | INSENSITIVE
17879 : | INSERT
17880 : | INSTEAD
17881 : | INVOKER
17882 : | ISOLATION
17883 : | KEEP
17884 : | KEY
17885 : | KEYS
17886 : | LABEL
17887 : | LANGUAGE
17888 : | LARGE_P
17889 : | LAST_P
17890 : | LEAKPROOF
17891 : | LEVEL
17892 : | LISTEN
17893 : | LOAD
17894 : | LOCAL
17895 : | LOCATION
17896 : | LOCK_P
17897 : | LOCKED
17898 : | LOGGED
17899 : | MAPPING
17900 : | MATCH
17901 : | MATCHED
17902 : | MATERIALIZED
17903 : | MAXVALUE
17904 : | MERGE
17905 : | METHOD
17906 : | MINUTE_P
17907 : | MINVALUE
17908 : | MODE
17909 : | MONTH_P
17910 : | MOVE
17911 : | NAME_P
17912 : | NAMES
17913 : | NESTED
17914 : | NEW
17915 : | NEXT
17916 : | NFC
17917 : | NFD
17918 : | NFKC
17919 : | NFKD
17920 : | NO
17921 : | NORMALIZED
17922 : | NOTHING
17923 : | NOTIFY
17924 : | NOWAIT
17925 : | NULLS_P
17926 : | OBJECT_P
17927 : | OBJECTS_P
17928 : | OF
17929 : | OFF
17930 : | OIDS
17931 : | OLD
17932 : | OMIT
17933 : | OPERATOR
17934 : | OPTION
17935 : | OPTIONS
17936 : | ORDINALITY
17937 : | OTHERS
17938 : | OVER
17939 : | OVERRIDING
17940 : | OWNED
17941 : | OWNER
17942 : | PARALLEL
17943 : | PARAMETER
17944 : | PARSER
17945 : | PARTIAL
17946 : | PARTITION
17947 : | PASSING
17948 : | PASSWORD
17949 : | PATH
17950 : | PERIOD
17951 : | PLAN
17952 : | PLANS
17953 : | POLICY
17954 : | PRECEDING
17955 : | PREPARE
17956 : | PREPARED
17957 : | PRESERVE
17958 : | PRIOR
17959 : | PRIVILEGES
17960 : | PROCEDURAL
17961 : | PROCEDURE
17962 : | PROCEDURES
17963 : | PROGRAM
17964 : | PUBLICATION
17965 : | QUOTE
17966 : | QUOTES
17967 : | RANGE
17968 : | READ
17969 : | REASSIGN
17970 : | RECURSIVE
17971 : | REF_P
17972 : | REFERENCING
17973 : | REFRESH
17974 : | REINDEX
17975 : | RELATIVE_P
17976 : | RELEASE
17977 : | RENAME
17978 : | REPEATABLE
17979 : | REPLACE
17980 : | REPLICA
17981 : | RESET
17982 : | RESTART
17983 : | RESTRICT
17984 : | RETURN
17985 : | RETURNS
17986 : | REVOKE
17987 : | ROLE
17988 : | ROLLBACK
17989 : | ROLLUP
17990 : | ROUTINE
17991 : | ROUTINES
17992 : | ROWS
17993 : | RULE
17994 : | SAVEPOINT
17995 : | SCALAR
17996 : | SCHEMA
17997 : | SCHEMAS
17998 : | SCROLL
17999 : | SEARCH
18000 : | SECOND_P
18001 : | SECURITY
18002 : | SEQUENCE
18003 : | SEQUENCES
18004 : | SERIALIZABLE
18005 : | SERVER
18006 : | SESSION
18007 : | SET
18008 : | SETS
18009 : | SHARE
18010 : | SHOW
18011 : | SIMPLE
18012 : | SKIP
18013 : | SNAPSHOT
18014 : | SOURCE
18015 : | SQL_P
18016 : | STABLE
18017 : | STANDALONE_P
18018 : | START
18019 : | STATEMENT
18020 : | STATISTICS
18021 : | STDIN
18022 : | STDOUT
18023 : | STORAGE
18024 : | STORED
18025 : | STRICT_P
18026 : | STRING_P
18027 : | STRIP_P
18028 : | SUBSCRIPTION
18029 : | SUPPORT
18030 : | SYSID
18031 : | SYSTEM_P
18032 : | TABLES
18033 : | TABLESPACE
18034 : | TARGET
18035 : | TEMP
18036 : | TEMPLATE
18037 : | TEMPORARY
18038 : | TEXT_P
18039 : | TIES
18040 : | TRANSACTION
18041 : | TRANSFORM
18042 : | TRIGGER
18043 : | TRUNCATE
18044 : | TRUSTED
18045 : | TYPE_P
18046 : | TYPES_P
18047 : | UESCAPE
18048 : | UNBOUNDED
18049 : | UNCOMMITTED
18050 : | UNCONDITIONAL
18051 : | UNENCRYPTED
18052 : | UNKNOWN
18053 : | UNLISTEN
18054 : | UNLOGGED
18055 : | UNTIL
18056 : | UPDATE
18057 : | VACUUM
18058 : | VALID
18059 : | VALIDATE
18060 : | VALIDATOR
18061 : | VALUE_P
18062 : | VARYING
18063 : | VERSION_P
18064 : | VIEW
18065 : | VIEWS
18066 : | VIRTUAL
18067 : | VOLATILE
18068 : | WHITESPACE_P
18069 : | WITHIN
18070 : | WITHOUT
18071 : | WORK
18072 : | WRAPPER
18073 : | WRITE
18074 : | XML_P
18075 : | YEAR_P
18076 : | YES_P
18077 : | ZONE
18078 : ;
18079 :
18080 : /* Column identifier --- keywords that can be column, table, etc names.
18081 : *
18082 : * Many of these keywords will in fact be recognized as type or function
18083 : * names too; but they have special productions for the purpose, and so
18084 : * can't be treated as "generic" type or function names.
18085 : *
18086 : * The type names appearing here are not usable as function names
18087 : * because they can be followed by '(' in typename productions, which
18088 : * looks too much like a function call for an LR(1) parser.
18089 : */
18090 : col_name_keyword:
18091 : BETWEEN
18092 : | BIGINT
18093 : | BIT
18094 : | BOOLEAN_P
18095 : | CHAR_P
18096 : | CHARACTER
18097 : | COALESCE
18098 : | DEC
18099 : | DECIMAL_P
18100 : | EXISTS
18101 : | EXTRACT
18102 : | FLOAT_P
18103 : | GREATEST
18104 : | GROUPING
18105 : | INOUT
18106 : | INT_P
18107 : | INTEGER
18108 : | INTERVAL
18109 : | JSON
18110 : | JSON_ARRAY
18111 : | JSON_ARRAYAGG
18112 : | JSON_EXISTS
18113 : | JSON_OBJECT
18114 : | JSON_OBJECTAGG
18115 : | JSON_QUERY
18116 : | JSON_SCALAR
18117 : | JSON_SERIALIZE
18118 : | JSON_TABLE
18119 : | JSON_VALUE
18120 : | LEAST
18121 : | MERGE_ACTION
18122 : | NATIONAL
18123 : | NCHAR
18124 : | NONE
18125 : | NORMALIZE
18126 : | NULLIF
18127 : | NUMERIC
18128 : | OUT_P
18129 : | OVERLAY
18130 : | POSITION
18131 : | PRECISION
18132 : | REAL
18133 : | ROW
18134 : | SETOF
18135 : | SMALLINT
18136 : | SUBSTRING
18137 : | TIME
18138 : | TIMESTAMP
18139 : | TREAT
18140 : | TRIM
18141 : | VALUES
18142 : | VARCHAR
18143 : | XMLATTRIBUTES
18144 : | XMLCONCAT
18145 : | XMLELEMENT
18146 : | XMLEXISTS
18147 : | XMLFOREST
18148 : | XMLNAMESPACES
18149 : | XMLPARSE
18150 : | XMLPI
18151 : | XMLROOT
18152 : | XMLSERIALIZE
18153 : | XMLTABLE
18154 : ;
18155 :
18156 : /* Type/function identifier --- keywords that can be type or function names.
18157 : *
18158 : * Most of these are keywords that are used as operators in expressions;
18159 : * in general such keywords can't be column names because they would be
18160 : * ambiguous with variables, but they are unambiguous as function identifiers.
18161 : *
18162 : * Do not include POSITION, SUBSTRING, etc here since they have explicit
18163 : * productions in a_expr to support the goofy SQL9x argument syntax.
18164 : * - thomas 2000-11-28
18165 : */
18166 : type_func_name_keyword:
18167 : AUTHORIZATION
18168 : | BINARY
18169 : | COLLATION
18170 : | CONCURRENTLY
18171 : | CROSS
18172 : | CURRENT_SCHEMA
18173 : | FREEZE
18174 : | FULL
18175 : | ILIKE
18176 : | INNER_P
18177 : | IS
18178 : | ISNULL
18179 : | JOIN
18180 : | LEFT
18181 : | LIKE
18182 : | NATURAL
18183 : | NOTNULL
18184 : | OUTER_P
18185 : | OVERLAPS
18186 : | RIGHT
18187 : | SIMILAR
18188 : | TABLESAMPLE
18189 : | VERBOSE
18190 : ;
18191 :
18192 : /* Reserved keyword --- these keywords are usable only as a ColLabel.
18193 : *
18194 : * Keywords appear here if they could not be distinguished from variable,
18195 : * type, or function names in some contexts. Don't put things here unless
18196 : * forced to.
18197 : */
18198 : reserved_keyword:
18199 : ALL
18200 : | ANALYSE
18201 : | ANALYZE
18202 : | AND
18203 : | ANY
18204 : | ARRAY
18205 : | AS
18206 : | ASC
18207 : | ASYMMETRIC
18208 : | BOTH
18209 : | CASE
18210 : | CAST
18211 : | CHECK
18212 : | COLLATE
18213 : | COLUMN
18214 : | CONSTRAINT
18215 : | CREATE
18216 : | CURRENT_CATALOG
18217 : | CURRENT_DATE
18218 : | CURRENT_ROLE
18219 : | CURRENT_TIME
18220 : | CURRENT_TIMESTAMP
18221 : | CURRENT_USER
18222 : | DEFAULT
18223 : | DEFERRABLE
18224 : | DESC
18225 : | DISTINCT
18226 : | DO
18227 : | ELSE
18228 : | END_P
18229 : | EXCEPT
18230 : | FALSE_P
18231 : | FETCH
18232 : | FOR
18233 : | FOREIGN
18234 : | FROM
18235 : | GRANT
18236 : | GROUP_P
18237 : | HAVING
18238 : | IN_P
18239 : | INITIALLY
18240 : | INTERSECT
18241 : | INTO
18242 : | LATERAL_P
18243 : | LEADING
18244 : | LIMIT
18245 : | LOCALTIME
18246 : | LOCALTIMESTAMP
18247 : | NOT
18248 : | NULL_P
18249 : | OFFSET
18250 : | ON
18251 : | ONLY
18252 : | OR
18253 : | ORDER
18254 : | PLACING
18255 : | PRIMARY
18256 : | REFERENCES
18257 : | RETURNING
18258 : | SELECT
18259 : | SESSION_USER
18260 : | SOME
18261 : | SYMMETRIC
18262 : | SYSTEM_USER
18263 : | TABLE
18264 : | THEN
18265 : | TO
18266 : | TRAILING
18267 : | TRUE_P
18268 : | UNION
18269 : | UNIQUE
18270 : | USER
18271 : | USING
18272 : | VARIADIC
18273 : | WHEN
18274 : | WHERE
18275 : | WINDOW
18276 : | WITH
18277 : ;
18278 :
18279 : /*
18280 : * While all keywords can be used as column labels when preceded by AS,
18281 : * not all of them can be used as a "bare" column label without AS.
18282 : * Those that can be used as a bare label must be listed here,
18283 : * in addition to appearing in one of the category lists above.
18284 : *
18285 : * Always add a new keyword to this list if possible. Mark it BARE_LABEL
18286 : * in kwlist.h if it is included here, or AS_LABEL if it is not.
18287 : */
18288 : bare_label_keyword:
18289 : ABORT_P
18290 : | ABSENT
18291 : | ABSOLUTE_P
18292 : | ACCESS
18293 : | ACTION
18294 : | ADD_P
18295 : | ADMIN
18296 : | AFTER
18297 : | AGGREGATE
18298 : | ALL
18299 : | ALSO
18300 : | ALTER
18301 : | ALWAYS
18302 : | ANALYSE
18303 : | ANALYZE
18304 : | AND
18305 : | ANY
18306 : | ASC
18307 : | ASENSITIVE
18308 : | ASSERTION
18309 : | ASSIGNMENT
18310 : | ASYMMETRIC
18311 : | AT
18312 : | ATOMIC
18313 : | ATTACH
18314 : | ATTRIBUTE
18315 : | AUTHORIZATION
18316 : | BACKWARD
18317 : | BEFORE
18318 : | BEGIN_P
18319 : | BETWEEN
18320 : | BIGINT
18321 : | BINARY
18322 : | BIT
18323 : | BOOLEAN_P
18324 : | BOTH
18325 : | BREADTH
18326 : | BY
18327 : | CACHE
18328 : | CALL
18329 : | CALLED
18330 : | CASCADE
18331 : | CASCADED
18332 : | CASE
18333 : | CAST
18334 : | CATALOG_P
18335 : | CHAIN
18336 : | CHARACTERISTICS
18337 : | CHECK
18338 : | CHECKPOINT
18339 : | CLASS
18340 : | CLOSE
18341 : | CLUSTER
18342 : | COALESCE
18343 : | COLLATE
18344 : | COLLATION
18345 : | COLUMN
18346 : | COLUMNS
18347 : | COMMENT
18348 : | COMMENTS
18349 : | COMMIT
18350 : | COMMITTED
18351 : | COMPRESSION
18352 : | CONCURRENTLY
18353 : | CONDITIONAL
18354 : | CONFIGURATION
18355 : | CONFLICT
18356 : | CONNECTION
18357 : | CONSTRAINT
18358 : | CONSTRAINTS
18359 : | CONTENT_P
18360 : | CONTINUE_P
18361 : | CONVERSION_P
18362 : | COPY
18363 : | COST
18364 : | CROSS
18365 : | CSV
18366 : | CUBE
18367 : | CURRENT_P
18368 : | CURRENT_CATALOG
18369 : | CURRENT_DATE
18370 : | CURRENT_ROLE
18371 : | CURRENT_SCHEMA
18372 : | CURRENT_TIME
18373 : | CURRENT_TIMESTAMP
18374 : | CURRENT_USER
18375 : | CURSOR
18376 : | CYCLE
18377 : | DATA_P
18378 : | DATABASE
18379 : | DEALLOCATE
18380 : | DEC
18381 : | DECIMAL_P
18382 : | DECLARE
18383 : | DEFAULT
18384 : | DEFAULTS
18385 : | DEFERRABLE
18386 : | DEFERRED
18387 : | DEFINER
18388 : | DELETE_P
18389 : | DELIMITER
18390 : | DELIMITERS
18391 : | DEPENDS
18392 : | DEPTH
18393 : | DESC
18394 : | DETACH
18395 : | DICTIONARY
18396 : | DISABLE_P
18397 : | DISCARD
18398 : | DISTINCT
18399 : | DO
18400 : | DOCUMENT_P
18401 : | DOMAIN_P
18402 : | DOUBLE_P
18403 : | DROP
18404 : | EACH
18405 : | ELSE
18406 : | EMPTY_P
18407 : | ENABLE_P
18408 : | ENCODING
18409 : | ENCRYPTED
18410 : | END_P
18411 : | ENFORCED
18412 : | ENUM_P
18413 : | ERROR_P
18414 : | ESCAPE
18415 : | EVENT
18416 : | EXCLUDE
18417 : | EXCLUDING
18418 : | EXCLUSIVE
18419 : | EXECUTE
18420 : | EXISTS
18421 : | EXPLAIN
18422 : | EXPRESSION
18423 : | EXTENSION
18424 : | EXTERNAL
18425 : | EXTRACT
18426 : | FALSE_P
18427 : | FAMILY
18428 : | FINALIZE
18429 : | FIRST_P
18430 : | FLOAT_P
18431 : | FOLLOWING
18432 : | FORCE
18433 : | FOREIGN
18434 : | FORMAT
18435 : | FORWARD
18436 : | FREEZE
18437 : | FULL
18438 : | FUNCTION
18439 : | FUNCTIONS
18440 : | GENERATED
18441 : | GLOBAL
18442 : | GRANTED
18443 : | GREATEST
18444 : | GROUPING
18445 : | GROUPS
18446 : | HANDLER
18447 : | HEADER_P
18448 : | HOLD
18449 : | IDENTITY_P
18450 : | IF_P
18451 : | ILIKE
18452 : | IMMEDIATE
18453 : | IMMUTABLE
18454 : | IMPLICIT_P
18455 : | IMPORT_P
18456 : | IN_P
18457 : | INCLUDE
18458 : | INCLUDING
18459 : | INCREMENT
18460 : | INDENT
18461 : | INDEX
18462 : | INDEXES
18463 : | INHERIT
18464 : | INHERITS
18465 : | INITIALLY
18466 : | INLINE_P
18467 : | INNER_P
18468 : | INOUT
18469 : | INPUT_P
18470 : | INSENSITIVE
18471 : | INSERT
18472 : | INSTEAD
18473 : | INT_P
18474 : | INTEGER
18475 : | INTERVAL
18476 : | INVOKER
18477 : | IS
18478 : | ISOLATION
18479 : | JOIN
18480 : | JSON
18481 : | JSON_ARRAY
18482 : | JSON_ARRAYAGG
18483 : | JSON_EXISTS
18484 : | JSON_OBJECT
18485 : | JSON_OBJECTAGG
18486 : | JSON_QUERY
18487 : | JSON_SCALAR
18488 : | JSON_SERIALIZE
18489 : | JSON_TABLE
18490 : | JSON_VALUE
18491 : | KEEP
18492 : | KEY
18493 : | KEYS
18494 : | LABEL
18495 : | LANGUAGE
18496 : | LARGE_P
18497 : | LAST_P
18498 : | LATERAL_P
18499 : | LEADING
18500 : | LEAKPROOF
18501 : | LEAST
18502 : | LEFT
18503 : | LEVEL
18504 : | LIKE
18505 : | LISTEN
18506 : | LOAD
18507 : | LOCAL
18508 : | LOCALTIME
18509 : | LOCALTIMESTAMP
18510 : | LOCATION
18511 : | LOCK_P
18512 : | LOCKED
18513 : | LOGGED
18514 : | MAPPING
18515 : | MATCH
18516 : | MATCHED
18517 : | MATERIALIZED
18518 : | MAXVALUE
18519 : | MERGE
18520 : | MERGE_ACTION
18521 : | METHOD
18522 : | MINVALUE
18523 : | MODE
18524 : | MOVE
18525 : | NAME_P
18526 : | NAMES
18527 : | NATIONAL
18528 : | NATURAL
18529 : | NCHAR
18530 : | NESTED
18531 : | NEW
18532 : | NEXT
18533 : | NFC
18534 : | NFD
18535 : | NFKC
18536 : | NFKD
18537 : | NO
18538 : | NONE
18539 : | NORMALIZE
18540 : | NORMALIZED
18541 : | NOT
18542 : | NOTHING
18543 : | NOTIFY
18544 : | NOWAIT
18545 : | NULL_P
18546 : | NULLIF
18547 : | NULLS_P
18548 : | NUMERIC
18549 : | OBJECT_P
18550 : | OBJECTS_P
18551 : | OF
18552 : | OFF
18553 : | OIDS
18554 : | OLD
18555 : | OMIT
18556 : | ONLY
18557 : | OPERATOR
18558 : | OPTION
18559 : | OPTIONS
18560 : | OR
18561 : | ORDINALITY
18562 : | OTHERS
18563 : | OUT_P
18564 : | OUTER_P
18565 : | OVERLAY
18566 : | OVERRIDING
18567 : | OWNED
18568 : | OWNER
18569 : | PARALLEL
18570 : | PARAMETER
18571 : | PARSER
18572 : | PARTIAL
18573 : | PARTITION
18574 : | PASSING
18575 : | PASSWORD
18576 : | PATH
18577 : | PERIOD
18578 : | PLACING
18579 : | PLAN
18580 : | PLANS
18581 : | POLICY
18582 : | POSITION
18583 : | PRECEDING
18584 : | PREPARE
18585 : | PREPARED
18586 : | PRESERVE
18587 : | PRIMARY
18588 : | PRIOR
18589 : | PRIVILEGES
18590 : | PROCEDURAL
18591 : | PROCEDURE
18592 : | PROCEDURES
18593 : | PROGRAM
18594 : | PUBLICATION
18595 : | QUOTE
18596 : | QUOTES
18597 : | RANGE
18598 : | READ
18599 : | REAL
18600 : | REASSIGN
18601 : | RECURSIVE
18602 : | REF_P
18603 : | REFERENCES
18604 : | REFERENCING
18605 : | REFRESH
18606 : | REINDEX
18607 : | RELATIVE_P
18608 : | RELEASE
18609 : | RENAME
18610 : | REPEATABLE
18611 : | REPLACE
18612 : | REPLICA
18613 : | RESET
18614 : | RESTART
18615 : | RESTRICT
18616 : | RETURN
18617 : | RETURNS
18618 : | REVOKE
18619 : | RIGHT
18620 : | ROLE
18621 : | ROLLBACK
18622 : | ROLLUP
18623 : | ROUTINE
18624 : | ROUTINES
18625 : | ROW
18626 : | ROWS
18627 : | RULE
18628 : | SAVEPOINT
18629 : | SCALAR
18630 : | SCHEMA
18631 : | SCHEMAS
18632 : | SCROLL
18633 : | SEARCH
18634 : | SECURITY
18635 : | SELECT
18636 : | SEQUENCE
18637 : | SEQUENCES
18638 : | SERIALIZABLE
18639 : | SERVER
18640 : | SESSION
18641 : | SESSION_USER
18642 : | SET
18643 : | SETOF
18644 : | SETS
18645 : | SHARE
18646 : | SHOW
18647 : | SIMILAR
18648 : | SIMPLE
18649 : | SKIP
18650 : | SMALLINT
18651 : | SNAPSHOT
18652 : | SOME
18653 : | SOURCE
18654 : | SQL_P
18655 : | STABLE
18656 : | STANDALONE_P
18657 : | START
18658 : | STATEMENT
18659 : | STATISTICS
18660 : | STDIN
18661 : | STDOUT
18662 : | STORAGE
18663 : | STORED
18664 : | STRICT_P
18665 : | STRING_P
18666 : | STRIP_P
18667 : | SUBSCRIPTION
18668 : | SUBSTRING
18669 : | SUPPORT
18670 : | SYMMETRIC
18671 : | SYSID
18672 : | SYSTEM_P
18673 : | SYSTEM_USER
18674 : | TABLE
18675 : | TABLES
18676 : | TABLESAMPLE
18677 : | TABLESPACE
18678 : | TARGET
18679 : | TEMP
18680 : | TEMPLATE
18681 : | TEMPORARY
18682 : | TEXT_P
18683 : | THEN
18684 : | TIES
18685 : | TIME
18686 : | TIMESTAMP
18687 : | TRAILING
18688 : | TRANSACTION
18689 : | TRANSFORM
18690 : | TREAT
18691 : | TRIGGER
18692 : | TRIM
18693 : | TRUE_P
18694 : | TRUNCATE
18695 : | TRUSTED
18696 : | TYPE_P
18697 : | TYPES_P
18698 : | UESCAPE
18699 : | UNBOUNDED
18700 : | UNCOMMITTED
18701 : | UNCONDITIONAL
18702 : | UNENCRYPTED
18703 : | UNIQUE
18704 : | UNKNOWN
18705 : | UNLISTEN
18706 : | UNLOGGED
18707 : | UNTIL
18708 : | UPDATE
18709 : | USER
18710 : | USING
18711 : | VACUUM
18712 : | VALID
18713 : | VALIDATE
18714 : | VALIDATOR
18715 : | VALUE_P
18716 : | VALUES
18717 : | VARCHAR
18718 : | VARIADIC
18719 : | VERBOSE
18720 : | VERSION_P
18721 : | VIEW
18722 : | VIEWS
18723 : | VIRTUAL
18724 : | VOLATILE
18725 : | WHEN
18726 : | WHITESPACE_P
18727 : | WORK
18728 : | WRAPPER
18729 : | WRITE
18730 : | XML_P
18731 : | XMLATTRIBUTES
18732 : | XMLCONCAT
18733 : | XMLELEMENT
18734 : | XMLEXISTS
18735 : | XMLFOREST
18736 : | XMLNAMESPACES
18737 : | XMLPARSE
18738 : | XMLPI
18739 : | XMLROOT
18740 : | XMLSERIALIZE
18741 : | XMLTABLE
18742 : | YES_P
18743 : | ZONE
18744 : ;
18745 :
18746 : %%
18747 :
18748 : /*
18749 : * The signature of this function is required by bison. However, we
18750 : * ignore the passed yylloc and instead use the last token position
18751 : * available from the scanner.
18752 : */
18753 : static void
18754 696 : base_yyerror(YYLTYPE *yylloc, core_yyscan_t yyscanner, const char *msg)
18755 : {
18756 696 : parser_yyerror(msg);
18757 : }
18758 :
18759 : static RawStmt *
18760 812998 : makeRawStmt(Node *stmt, int stmt_location)
18761 : {
18762 812998 : RawStmt *rs = makeNode(RawStmt);
18763 :
18764 812998 : rs->stmt = stmt;
18765 812998 : rs->stmt_location = stmt_location;
18766 812998 : rs->stmt_len = 0; /* might get changed later */
18767 812998 : return rs;
18768 : }
18769 :
18770 : /* Adjust a RawStmt to reflect that it doesn't run to the end of the string */
18771 : static void
18772 582434 : updateRawStmtEnd(RawStmt *rs, int end_location)
18773 : {
18774 : /*
18775 : * If we already set the length, don't change it. This is for situations
18776 : * like "select foo ;; select bar" where the same statement will be last
18777 : * in the string for more than one semicolon.
18778 : */
18779 582434 : if (rs->stmt_len > 0)
18780 642 : return;
18781 :
18782 : /* OK, update length of RawStmt */
18783 581792 : rs->stmt_len = end_location - rs->stmt_location;
18784 : }
18785 :
18786 : static Node *
18787 1806268 : makeColumnRef(char *colname, List *indirection,
18788 : int location, core_yyscan_t yyscanner)
18789 : {
18790 : /*
18791 : * Generate a ColumnRef node, with an A_Indirection node added if there is
18792 : * any subscripting in the specified indirection list. However, any field
18793 : * selection at the start of the indirection list must be transposed into
18794 : * the "fields" part of the ColumnRef node.
18795 : */
18796 1806268 : ColumnRef *c = makeNode(ColumnRef);
18797 1806268 : int nfields = 0;
18798 : ListCell *l;
18799 :
18800 1806268 : c->location = location;
18801 2856174 : foreach(l, indirection)
18802 : {
18803 1059836 : if (IsA(lfirst(l), A_Indices))
18804 : {
18805 9930 : A_Indirection *i = makeNode(A_Indirection);
18806 :
18807 9930 : if (nfields == 0)
18808 : {
18809 : /* easy case - all indirection goes to A_Indirection */
18810 7212 : c->fields = list_make1(makeString(colname));
18811 7212 : i->indirection = check_indirection(indirection, yyscanner);
18812 : }
18813 : else
18814 : {
18815 : /* got to split the list in two */
18816 2718 : i->indirection = check_indirection(list_copy_tail(indirection,
18817 : nfields),
18818 : yyscanner);
18819 2718 : indirection = list_truncate(indirection, nfields);
18820 2718 : c->fields = lcons(makeString(colname), indirection);
18821 : }
18822 9930 : i->arg = (Node *) c;
18823 9930 : return (Node *) i;
18824 : }
18825 1049906 : else if (IsA(lfirst(l), A_Star))
18826 : {
18827 : /* We only allow '*' at the end of a ColumnRef */
18828 5514 : if (lnext(indirection, l) != NULL)
18829 0 : parser_yyerror("improper use of \"*\"");
18830 : }
18831 1049906 : nfields++;
18832 : }
18833 : /* No subscripting, so all indirection gets added to field list */
18834 1796338 : c->fields = lcons(makeString(colname), indirection);
18835 1796338 : return (Node *) c;
18836 : }
18837 :
18838 : static Node *
18839 314894 : makeTypeCast(Node *arg, TypeName *typename, int location)
18840 : {
18841 314894 : TypeCast *n = makeNode(TypeCast);
18842 :
18843 314894 : n->arg = arg;
18844 314894 : n->typeName = typename;
18845 314894 : n->location = location;
18846 314894 : return (Node *) n;
18847 : }
18848 :
18849 : static Node *
18850 16326 : makeStringConstCast(char *str, int location, TypeName *typename)
18851 : {
18852 16326 : Node *s = makeStringConst(str, location);
18853 :
18854 16326 : return makeTypeCast(s, typename, -1);
18855 : }
18856 :
18857 : static Node *
18858 386818 : makeIntConst(int val, int location)
18859 : {
18860 386818 : A_Const *n = makeNode(A_Const);
18861 :
18862 386818 : n->val.ival.type = T_Integer;
18863 386818 : n->val.ival.ival = val;
18864 386818 : n->location = location;
18865 :
18866 386818 : return (Node *) n;
18867 : }
18868 :
18869 : static Node *
18870 11936 : makeFloatConst(char *str, int location)
18871 : {
18872 11936 : A_Const *n = makeNode(A_Const);
18873 :
18874 11936 : n->val.fval.type = T_Float;
18875 11936 : n->val.fval.fval = str;
18876 11936 : n->location = location;
18877 :
18878 11936 : return (Node *) n;
18879 : }
18880 :
18881 : static Node *
18882 67230 : makeBoolAConst(bool state, int location)
18883 : {
18884 67230 : A_Const *n = makeNode(A_Const);
18885 :
18886 67230 : n->val.boolval.type = T_Boolean;
18887 67230 : n->val.boolval.boolval = state;
18888 67230 : n->location = location;
18889 :
18890 67230 : return (Node *) n;
18891 : }
18892 :
18893 : static Node *
18894 4056 : makeBitStringConst(char *str, int location)
18895 : {
18896 4056 : A_Const *n = makeNode(A_Const);
18897 :
18898 4056 : n->val.bsval.type = T_BitString;
18899 4056 : n->val.bsval.bsval = str;
18900 4056 : n->location = location;
18901 :
18902 4056 : return (Node *) n;
18903 : }
18904 :
18905 : static Node *
18906 67286 : makeNullAConst(int location)
18907 : {
18908 67286 : A_Const *n = makeNode(A_Const);
18909 :
18910 67286 : n->isnull = true;
18911 67286 : n->location = location;
18912 :
18913 67286 : return (Node *) n;
18914 : }
18915 :
18916 : static Node *
18917 5284 : makeAConst(Node *v, int location)
18918 : {
18919 : Node *n;
18920 :
18921 5284 : switch (v->type)
18922 : {
18923 218 : case T_Float:
18924 218 : n = makeFloatConst(castNode(Float, v)->fval, location);
18925 218 : break;
18926 :
18927 5066 : case T_Integer:
18928 5066 : n = makeIntConst(castNode(Integer, v)->ival, location);
18929 5066 : break;
18930 :
18931 0 : default:
18932 : /* currently not used */
18933 : Assert(false);
18934 0 : n = NULL;
18935 : }
18936 :
18937 5284 : return n;
18938 : }
18939 :
18940 : /* makeRoleSpec
18941 : * Create a RoleSpec with the given type
18942 : */
18943 : static RoleSpec *
18944 33374 : makeRoleSpec(RoleSpecType type, int location)
18945 : {
18946 33374 : RoleSpec *spec = makeNode(RoleSpec);
18947 :
18948 33374 : spec->roletype = type;
18949 33374 : spec->location = location;
18950 :
18951 33374 : return spec;
18952 : }
18953 :
18954 : /* check_qualified_name --- check the result of qualified_name production
18955 : *
18956 : * It's easiest to let the grammar production for qualified_name allow
18957 : * subscripts and '*', which we then must reject here.
18958 : */
18959 : static void
18960 245210 : check_qualified_name(List *names, core_yyscan_t yyscanner)
18961 : {
18962 : ListCell *i;
18963 :
18964 490420 : foreach(i, names)
18965 : {
18966 245210 : if (!IsA(lfirst(i), String))
18967 0 : parser_yyerror("syntax error");
18968 : }
18969 245210 : }
18970 :
18971 : /* check_func_name --- check the result of func_name production
18972 : *
18973 : * It's easiest to let the grammar production for func_name allow subscripts
18974 : * and '*', which we then must reject here.
18975 : */
18976 : static List *
18977 126712 : check_func_name(List *names, core_yyscan_t yyscanner)
18978 : {
18979 : ListCell *i;
18980 :
18981 380136 : foreach(i, names)
18982 : {
18983 253424 : if (!IsA(lfirst(i), String))
18984 0 : parser_yyerror("syntax error");
18985 : }
18986 126712 : return names;
18987 : }
18988 :
18989 : /* check_indirection --- check the result of indirection production
18990 : *
18991 : * We only allow '*' at the end of the list, but it's hard to enforce that
18992 : * in the grammar, so do it here.
18993 : */
18994 : static List *
18995 83018 : check_indirection(List *indirection, core_yyscan_t yyscanner)
18996 : {
18997 : ListCell *l;
18998 :
18999 110650 : foreach(l, indirection)
19000 : {
19001 27632 : if (IsA(lfirst(l), A_Star))
19002 : {
19003 1462 : if (lnext(indirection, l) != NULL)
19004 0 : parser_yyerror("improper use of \"*\"");
19005 : }
19006 : }
19007 83018 : return indirection;
19008 : }
19009 :
19010 : /* extractArgTypes()
19011 : * Given a list of FunctionParameter nodes, extract a list of just the
19012 : * argument types (TypeNames) for input parameters only. This is what
19013 : * is needed to look up an existing function, which is what is wanted by
19014 : * the productions that use this call.
19015 : */
19016 : static List *
19017 18392 : extractArgTypes(List *parameters)
19018 : {
19019 18392 : List *result = NIL;
19020 : ListCell *i;
19021 :
19022 42250 : foreach(i, parameters)
19023 : {
19024 23858 : FunctionParameter *p = (FunctionParameter *) lfirst(i);
19025 :
19026 23858 : if (p->mode != FUNC_PARAM_OUT && p->mode != FUNC_PARAM_TABLE)
19027 23702 : result = lappend(result, p->argType);
19028 : }
19029 18392 : return result;
19030 : }
19031 :
19032 : /* extractAggrArgTypes()
19033 : * As above, but work from the output of the aggr_args production.
19034 : */
19035 : static List *
19036 362 : extractAggrArgTypes(List *aggrargs)
19037 : {
19038 : Assert(list_length(aggrargs) == 2);
19039 362 : return extractArgTypes((List *) linitial(aggrargs));
19040 : }
19041 :
19042 : /* makeOrderedSetArgs()
19043 : * Build the result of the aggr_args production (which see the comments for).
19044 : * This handles only the case where both given lists are nonempty, so that
19045 : * we have to deal with multiple VARIADIC arguments.
19046 : */
19047 : static List *
19048 32 : makeOrderedSetArgs(List *directargs, List *orderedargs,
19049 : core_yyscan_t yyscanner)
19050 : {
19051 32 : FunctionParameter *lastd = (FunctionParameter *) llast(directargs);
19052 : Integer *ndirectargs;
19053 :
19054 : /* No restriction unless last direct arg is VARIADIC */
19055 32 : if (lastd->mode == FUNC_PARAM_VARIADIC)
19056 : {
19057 16 : FunctionParameter *firsto = (FunctionParameter *) linitial(orderedargs);
19058 :
19059 : /*
19060 : * We ignore the names, though the aggr_arg production allows them; it
19061 : * doesn't allow default values, so those need not be checked.
19062 : */
19063 16 : if (list_length(orderedargs) != 1 ||
19064 16 : firsto->mode != FUNC_PARAM_VARIADIC ||
19065 16 : !equal(lastd->argType, firsto->argType))
19066 0 : ereport(ERROR,
19067 : (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
19068 : errmsg("an ordered-set aggregate with a VARIADIC direct argument must have one VARIADIC aggregated argument of the same data type"),
19069 : parser_errposition(firsto->location)));
19070 :
19071 : /* OK, drop the duplicate VARIADIC argument from the internal form */
19072 16 : orderedargs = NIL;
19073 : }
19074 :
19075 : /* don't merge into the next line, as list_concat changes directargs */
19076 32 : ndirectargs = makeInteger(list_length(directargs));
19077 :
19078 32 : return list_make2(list_concat(directargs, orderedargs),
19079 : ndirectargs);
19080 : }
19081 :
19082 : /* insertSelectOptions()
19083 : * Insert ORDER BY, etc into an already-constructed SelectStmt.
19084 : *
19085 : * This routine is just to avoid duplicating code in SelectStmt productions.
19086 : */
19087 : static void
19088 83276 : insertSelectOptions(SelectStmt *stmt,
19089 : List *sortClause, List *lockingClause,
19090 : SelectLimit *limitClause,
19091 : WithClause *withClause,
19092 : core_yyscan_t yyscanner)
19093 : {
19094 : Assert(IsA(stmt, SelectStmt));
19095 :
19096 : /*
19097 : * Tests here are to reject constructs like
19098 : * (SELECT foo ORDER BY bar) ORDER BY baz
19099 : */
19100 83276 : if (sortClause)
19101 : {
19102 73784 : if (stmt->sortClause)
19103 0 : ereport(ERROR,
19104 : (errcode(ERRCODE_SYNTAX_ERROR),
19105 : errmsg("multiple ORDER BY clauses not allowed"),
19106 : parser_errposition(exprLocation((Node *) sortClause))));
19107 73784 : stmt->sortClause = sortClause;
19108 : }
19109 : /* We can handle multiple locking clauses, though */
19110 83276 : stmt->lockingClause = list_concat(stmt->lockingClause, lockingClause);
19111 83276 : if (limitClause && limitClause->limitOffset)
19112 : {
19113 844 : if (stmt->limitOffset)
19114 0 : ereport(ERROR,
19115 : (errcode(ERRCODE_SYNTAX_ERROR),
19116 : errmsg("multiple OFFSET clauses not allowed"),
19117 : parser_errposition(limitClause->offsetLoc)));
19118 844 : stmt->limitOffset = limitClause->limitOffset;
19119 : }
19120 83276 : if (limitClause && limitClause->limitCount)
19121 : {
19122 4694 : if (stmt->limitCount)
19123 0 : ereport(ERROR,
19124 : (errcode(ERRCODE_SYNTAX_ERROR),
19125 : errmsg("multiple LIMIT clauses not allowed"),
19126 : parser_errposition(limitClause->countLoc)));
19127 4694 : stmt->limitCount = limitClause->limitCount;
19128 : }
19129 83276 : if (limitClause)
19130 : {
19131 : /* If there was a conflict, we must have detected it above */
19132 : Assert(!stmt->limitOption);
19133 5144 : if (!stmt->sortClause && limitClause->limitOption == LIMIT_OPTION_WITH_TIES)
19134 6 : ereport(ERROR,
19135 : (errcode(ERRCODE_SYNTAX_ERROR),
19136 : errmsg("WITH TIES cannot be specified without ORDER BY clause"),
19137 : parser_errposition(limitClause->optionLoc)));
19138 5138 : if (limitClause->limitOption == LIMIT_OPTION_WITH_TIES && stmt->lockingClause)
19139 : {
19140 : ListCell *lc;
19141 :
19142 6 : foreach(lc, stmt->lockingClause)
19143 : {
19144 6 : LockingClause *lock = lfirst_node(LockingClause, lc);
19145 :
19146 6 : if (lock->waitPolicy == LockWaitSkip)
19147 6 : ereport(ERROR,
19148 : (errcode(ERRCODE_SYNTAX_ERROR),
19149 : errmsg("%s and %s options cannot be used together",
19150 : "SKIP LOCKED", "WITH TIES"),
19151 : parser_errposition(limitClause->optionLoc)));
19152 : }
19153 : }
19154 5132 : stmt->limitOption = limitClause->limitOption;
19155 : }
19156 83264 : if (withClause)
19157 : {
19158 2880 : if (stmt->withClause)
19159 0 : ereport(ERROR,
19160 : (errcode(ERRCODE_SYNTAX_ERROR),
19161 : errmsg("multiple WITH clauses not allowed"),
19162 : parser_errposition(exprLocation((Node *) withClause))));
19163 2880 : stmt->withClause = withClause;
19164 : }
19165 83264 : }
19166 :
19167 : static Node *
19168 19384 : makeSetOp(SetOperation op, bool all, Node *larg, Node *rarg)
19169 : {
19170 19384 : SelectStmt *n = makeNode(SelectStmt);
19171 :
19172 19384 : n->op = op;
19173 19384 : n->all = all;
19174 19384 : n->larg = (SelectStmt *) larg;
19175 19384 : n->rarg = (SelectStmt *) rarg;
19176 19384 : return (Node *) n;
19177 : }
19178 :
19179 : /* SystemFuncName()
19180 : * Build a properly-qualified reference to a built-in function.
19181 : */
19182 : List *
19183 19380 : SystemFuncName(char *name)
19184 : {
19185 19380 : return list_make2(makeString("pg_catalog"), makeString(name));
19186 : }
19187 :
19188 : /* SystemTypeName()
19189 : * Build a properly-qualified reference to a built-in type.
19190 : *
19191 : * typmod is defaulted, but may be changed afterwards by caller.
19192 : * Likewise for the location.
19193 : */
19194 : TypeName *
19195 121588 : SystemTypeName(char *name)
19196 : {
19197 121588 : return makeTypeNameFromNameList(list_make2(makeString("pg_catalog"),
19198 : makeString(name)));
19199 : }
19200 :
19201 : /* doNegate()
19202 : * Handle negation of a numeric constant.
19203 : *
19204 : * Formerly, we did this here because the optimizer couldn't cope with
19205 : * indexquals that looked like "var = -4" --- it wants "var = const"
19206 : * and a unary minus operator applied to a constant didn't qualify.
19207 : * As of Postgres 7.0, that problem doesn't exist anymore because there
19208 : * is a constant-subexpression simplifier in the optimizer. However,
19209 : * there's still a good reason for doing this here, which is that we can
19210 : * postpone committing to a particular internal representation for simple
19211 : * negative constants. It's better to leave "-123.456" in string form
19212 : * until we know what the desired type is.
19213 : */
19214 : static Node *
19215 9258 : doNegate(Node *n, int location)
19216 : {
19217 9258 : if (IsA(n, A_Const))
19218 : {
19219 8248 : A_Const *con = (A_Const *) n;
19220 :
19221 : /* report the constant's location as that of the '-' sign */
19222 8248 : con->location = location;
19223 :
19224 8248 : if (IsA(&con->val, Integer))
19225 : {
19226 7290 : con->val.ival.ival = -con->val.ival.ival;
19227 7290 : return n;
19228 : }
19229 958 : if (IsA(&con->val, Float))
19230 : {
19231 958 : doNegateFloat(&con->val.fval);
19232 958 : return n;
19233 : }
19234 : }
19235 :
19236 1010 : return (Node *) makeSimpleA_Expr(AEXPR_OP, "-", NULL, n, location);
19237 : }
19238 :
19239 : static void
19240 978 : doNegateFloat(Float *v)
19241 : {
19242 978 : char *oldval = v->fval;
19243 :
19244 978 : if (*oldval == '+')
19245 0 : oldval++;
19246 978 : if (*oldval == '-')
19247 0 : v->fval = oldval + 1; /* just strip the '-' */
19248 : else
19249 978 : v->fval = psprintf("-%s", oldval);
19250 978 : }
19251 :
19252 : static Node *
19253 232810 : makeAndExpr(Node *lexpr, Node *rexpr, int location)
19254 : {
19255 : /* Flatten "a AND b AND c ..." to a single BoolExpr on sight */
19256 232810 : if (IsA(lexpr, BoolExpr))
19257 : {
19258 110646 : BoolExpr *blexpr = (BoolExpr *) lexpr;
19259 :
19260 110646 : if (blexpr->boolop == AND_EXPR)
19261 : {
19262 108118 : blexpr->args = lappend(blexpr->args, rexpr);
19263 108118 : return (Node *) blexpr;
19264 : }
19265 : }
19266 124692 : return (Node *) makeBoolExpr(AND_EXPR, list_make2(lexpr, rexpr), location);
19267 : }
19268 :
19269 : static Node *
19270 16038 : makeOrExpr(Node *lexpr, Node *rexpr, int location)
19271 : {
19272 : /* Flatten "a OR b OR c ..." to a single BoolExpr on sight */
19273 16038 : if (IsA(lexpr, BoolExpr))
19274 : {
19275 5650 : BoolExpr *blexpr = (BoolExpr *) lexpr;
19276 :
19277 5650 : if (blexpr->boolop == OR_EXPR)
19278 : {
19279 4140 : blexpr->args = lappend(blexpr->args, rexpr);
19280 4140 : return (Node *) blexpr;
19281 : }
19282 : }
19283 11898 : return (Node *) makeBoolExpr(OR_EXPR, list_make2(lexpr, rexpr), location);
19284 : }
19285 :
19286 : static Node *
19287 16296 : makeNotExpr(Node *expr, int location)
19288 : {
19289 16296 : return (Node *) makeBoolExpr(NOT_EXPR, list_make1(expr), location);
19290 : }
19291 :
19292 : static Node *
19293 8216 : makeAArrayExpr(List *elements, int location, int location_end)
19294 : {
19295 8216 : A_ArrayExpr *n = makeNode(A_ArrayExpr);
19296 :
19297 8216 : n->elements = elements;
19298 8216 : n->location = location;
19299 8216 : n->list_start = location;
19300 8216 : n->list_end = location_end;
19301 8216 : return (Node *) n;
19302 : }
19303 :
19304 : static Node *
19305 2742 : makeSQLValueFunction(SQLValueFunctionOp op, int32 typmod, int location)
19306 : {
19307 2742 : SQLValueFunction *svf = makeNode(SQLValueFunction);
19308 :
19309 2742 : svf->op = op;
19310 : /* svf->type will be filled during parse analysis */
19311 2742 : svf->typmod = typmod;
19312 2742 : svf->location = location;
19313 2742 : return (Node *) svf;
19314 : }
19315 :
19316 : static Node *
19317 596 : makeXmlExpr(XmlExprOp op, char *name, List *named_args, List *args,
19318 : int location)
19319 : {
19320 596 : XmlExpr *x = makeNode(XmlExpr);
19321 :
19322 596 : x->op = op;
19323 596 : x->name = name;
19324 :
19325 : /*
19326 : * named_args is a list of ResTarget; it'll be split apart into separate
19327 : * expression and name lists in transformXmlExpr().
19328 : */
19329 596 : x->named_args = named_args;
19330 596 : x->arg_names = NIL;
19331 596 : x->args = args;
19332 : /* xmloption, if relevant, must be filled in by caller */
19333 : /* type and typmod will be filled in during parse analysis */
19334 596 : x->type = InvalidOid; /* marks the node as not analyzed */
19335 596 : x->location = location;
19336 596 : return (Node *) x;
19337 : }
19338 :
19339 : /*
19340 : * Merge the input and output parameters of a table function.
19341 : */
19342 : static List *
19343 194 : mergeTableFuncParameters(List *func_args, List *columns, core_yyscan_t yyscanner)
19344 : {
19345 : ListCell *lc;
19346 :
19347 : /* Explicit OUT and INOUT parameters shouldn't be used in this syntax */
19348 394 : foreach(lc, func_args)
19349 : {
19350 200 : FunctionParameter *p = (FunctionParameter *) lfirst(lc);
19351 :
19352 200 : if (p->mode != FUNC_PARAM_DEFAULT &&
19353 0 : p->mode != FUNC_PARAM_IN &&
19354 0 : p->mode != FUNC_PARAM_VARIADIC)
19355 0 : ereport(ERROR,
19356 : (errcode(ERRCODE_SYNTAX_ERROR),
19357 : errmsg("OUT and INOUT arguments aren't allowed in TABLE functions"),
19358 : parser_errposition(p->location)));
19359 : }
19360 :
19361 194 : return list_concat(func_args, columns);
19362 : }
19363 :
19364 : /*
19365 : * Determine return type of a TABLE function. A single result column
19366 : * returns setof that column's type; otherwise return setof record.
19367 : */
19368 : static TypeName *
19369 194 : TableFuncTypeName(List *columns)
19370 : {
19371 : TypeName *result;
19372 :
19373 194 : if (list_length(columns) == 1)
19374 : {
19375 62 : FunctionParameter *p = (FunctionParameter *) linitial(columns);
19376 :
19377 62 : result = copyObject(p->argType);
19378 : }
19379 : else
19380 132 : result = SystemTypeName("record");
19381 :
19382 194 : result->setof = true;
19383 :
19384 194 : return result;
19385 : }
19386 :
19387 : /*
19388 : * Convert a list of (dotted) names to a RangeVar (like
19389 : * makeRangeVarFromNameList, but with position support). The
19390 : * "AnyName" refers to the any_name production in the grammar.
19391 : */
19392 : static RangeVar *
19393 4736 : makeRangeVarFromAnyName(List *names, int position, core_yyscan_t yyscanner)
19394 : {
19395 4736 : RangeVar *r = makeNode(RangeVar);
19396 :
19397 4736 : switch (list_length(names))
19398 : {
19399 4646 : case 1:
19400 4646 : r->catalogname = NULL;
19401 4646 : r->schemaname = NULL;
19402 4646 : r->relname = strVal(linitial(names));
19403 4646 : break;
19404 90 : case 2:
19405 90 : r->catalogname = NULL;
19406 90 : r->schemaname = strVal(linitial(names));
19407 90 : r->relname = strVal(lsecond(names));
19408 90 : break;
19409 0 : case 3:
19410 0 : r->catalogname = strVal(linitial(names));
19411 0 : r->schemaname = strVal(lsecond(names));
19412 0 : r->relname = strVal(lthird(names));
19413 0 : break;
19414 0 : default:
19415 0 : ereport(ERROR,
19416 : (errcode(ERRCODE_SYNTAX_ERROR),
19417 : errmsg("improper qualified name (too many dotted names): %s",
19418 : NameListToString(names)),
19419 : parser_errposition(position)));
19420 : break;
19421 : }
19422 :
19423 4736 : r->relpersistence = RELPERSISTENCE_PERMANENT;
19424 4736 : r->location = position;
19425 :
19426 4736 : return r;
19427 : }
19428 :
19429 : /*
19430 : * Convert a relation_name with name and namelist to a RangeVar using
19431 : * makeRangeVar.
19432 : */
19433 : static RangeVar *
19434 245210 : makeRangeVarFromQualifiedName(char *name, List *namelist, int location,
19435 : core_yyscan_t yyscanner)
19436 : {
19437 : RangeVar *r;
19438 :
19439 245210 : check_qualified_name(namelist, yyscanner);
19440 245210 : r = makeRangeVar(NULL, NULL, location);
19441 :
19442 245210 : switch (list_length(namelist))
19443 : {
19444 245210 : case 1:
19445 245210 : r->catalogname = NULL;
19446 245210 : r->schemaname = name;
19447 245210 : r->relname = strVal(linitial(namelist));
19448 245210 : break;
19449 0 : case 2:
19450 0 : r->catalogname = name;
19451 0 : r->schemaname = strVal(linitial(namelist));
19452 0 : r->relname = strVal(lsecond(namelist));
19453 0 : break;
19454 0 : default:
19455 0 : ereport(ERROR,
19456 : errcode(ERRCODE_SYNTAX_ERROR),
19457 : errmsg("improper qualified name (too many dotted names): %s",
19458 : NameListToString(lcons(makeString(name), namelist))),
19459 : parser_errposition(location));
19460 : break;
19461 : }
19462 :
19463 245210 : return r;
19464 : }
19465 :
19466 : /* Separate Constraint nodes from COLLATE clauses in a ColQualList */
19467 : static void
19468 69902 : SplitColQualList(List *qualList,
19469 : List **constraintList, CollateClause **collClause,
19470 : core_yyscan_t yyscanner)
19471 : {
19472 : ListCell *cell;
19473 :
19474 69902 : *collClause = NULL;
19475 90038 : foreach(cell, qualList)
19476 : {
19477 20136 : Node *n = (Node *) lfirst(cell);
19478 :
19479 20136 : if (IsA(n, Constraint))
19480 : {
19481 : /* keep it in list */
19482 19374 : continue;
19483 : }
19484 762 : if (IsA(n, CollateClause))
19485 : {
19486 762 : CollateClause *c = (CollateClause *) n;
19487 :
19488 762 : if (*collClause)
19489 0 : ereport(ERROR,
19490 : (errcode(ERRCODE_SYNTAX_ERROR),
19491 : errmsg("multiple COLLATE clauses not allowed"),
19492 : parser_errposition(c->location)));
19493 762 : *collClause = c;
19494 : }
19495 : else
19496 0 : elog(ERROR, "unexpected node type %d", (int) n->type);
19497 : /* remove non-Constraint nodes from qualList */
19498 762 : qualList = foreach_delete_current(qualList, cell);
19499 : }
19500 69902 : *constraintList = qualList;
19501 69902 : }
19502 :
19503 : /*
19504 : * Process result of ConstraintAttributeSpec, and set appropriate bool flags
19505 : * in the output command node. Pass NULL for any flags the particular
19506 : * command doesn't support.
19507 : */
19508 : static void
19509 17876 : processCASbits(int cas_bits, int location, const char *constrType,
19510 : bool *deferrable, bool *initdeferred, bool *is_enforced,
19511 : bool *not_valid, bool *no_inherit, core_yyscan_t yyscanner)
19512 : {
19513 : /* defaults */
19514 17876 : if (deferrable)
19515 15806 : *deferrable = false;
19516 17876 : if (initdeferred)
19517 15806 : *initdeferred = false;
19518 17876 : if (not_valid)
19519 3884 : *not_valid = false;
19520 17876 : if (is_enforced)
19521 3412 : *is_enforced = true;
19522 :
19523 17876 : if (cas_bits & (CAS_DEFERRABLE | CAS_INITIALLY_DEFERRED))
19524 : {
19525 230 : if (deferrable)
19526 230 : *deferrable = true;
19527 : else
19528 0 : ereport(ERROR,
19529 : (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
19530 : /* translator: %s is CHECK, UNIQUE, or similar */
19531 : errmsg("%s constraints cannot be marked DEFERRABLE",
19532 : constrType),
19533 : parser_errposition(location)));
19534 : }
19535 :
19536 17876 : if (cas_bits & CAS_INITIALLY_DEFERRED)
19537 : {
19538 146 : if (initdeferred)
19539 146 : *initdeferred = true;
19540 : else
19541 0 : ereport(ERROR,
19542 : (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
19543 : /* translator: %s is CHECK, UNIQUE, or similar */
19544 : errmsg("%s constraints cannot be marked DEFERRABLE",
19545 : constrType),
19546 : parser_errposition(location)));
19547 : }
19548 :
19549 17876 : if (cas_bits & CAS_NOT_VALID)
19550 : {
19551 714 : if (not_valid)
19552 714 : *not_valid = true;
19553 : else
19554 0 : ereport(ERROR,
19555 : (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
19556 : /* translator: %s is CHECK, UNIQUE, or similar */
19557 : errmsg("%s constraints cannot be marked NOT VALID",
19558 : constrType),
19559 : parser_errposition(location)));
19560 : }
19561 :
19562 17876 : if (cas_bits & CAS_NO_INHERIT)
19563 : {
19564 244 : if (no_inherit)
19565 244 : *no_inherit = true;
19566 : else
19567 0 : ereport(ERROR,
19568 : (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
19569 : /* translator: %s is CHECK, UNIQUE, or similar */
19570 : errmsg("%s constraints cannot be marked NO INHERIT",
19571 : constrType),
19572 : parser_errposition(location)));
19573 : }
19574 :
19575 17876 : if (cas_bits & CAS_NOT_ENFORCED)
19576 : {
19577 156 : if (is_enforced)
19578 150 : *is_enforced = false;
19579 : else
19580 6 : ereport(ERROR,
19581 : (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
19582 : /* translator: %s is CHECK, UNIQUE, or similar */
19583 : errmsg("%s constraints cannot be marked NOT ENFORCED",
19584 : constrType),
19585 : parser_errposition(location)));
19586 :
19587 : /*
19588 : * NB: The validated status is irrelevant when the constraint is set to
19589 : * NOT ENFORCED, but for consistency, it should be set accordingly.
19590 : * This ensures that if the constraint is later changed to ENFORCED, it
19591 : * will automatically be in the correct NOT VALIDATED state.
19592 : */
19593 150 : if (not_valid)
19594 114 : *not_valid = true;
19595 : }
19596 :
19597 17870 : if (cas_bits & CAS_ENFORCED)
19598 : {
19599 102 : if (is_enforced)
19600 96 : *is_enforced = true;
19601 : else
19602 6 : ereport(ERROR,
19603 : (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
19604 : /* translator: %s is CHECK, UNIQUE, or similar */
19605 : errmsg("%s constraints cannot be marked ENFORCED",
19606 : constrType),
19607 : parser_errposition(location)));
19608 : }
19609 17864 : }
19610 :
19611 : /*
19612 : * Parse a user-supplied partition strategy string into parse node
19613 : * PartitionStrategy representation, or die trying.
19614 : */
19615 : static PartitionStrategy
19616 5054 : parsePartitionStrategy(char *strategy, int location, core_yyscan_t yyscanner)
19617 : {
19618 5054 : if (pg_strcasecmp(strategy, "list") == 0)
19619 2560 : return PARTITION_STRATEGY_LIST;
19620 2494 : else if (pg_strcasecmp(strategy, "range") == 0)
19621 2228 : return PARTITION_STRATEGY_RANGE;
19622 266 : else if (pg_strcasecmp(strategy, "hash") == 0)
19623 260 : return PARTITION_STRATEGY_HASH;
19624 :
19625 6 : ereport(ERROR,
19626 : (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
19627 : errmsg("unrecognized partitioning strategy \"%s\"", strategy),
19628 : parser_errposition(location)));
19629 : return PARTITION_STRATEGY_LIST; /* keep compiler quiet */
19630 :
19631 : }
19632 :
19633 : /*
19634 : * Process pubobjspec_list to check for errors in any of the objects and
19635 : * convert PUBLICATIONOBJ_CONTINUATION into appropriate PublicationObjSpecType.
19636 : */
19637 : static void
19638 1648 : preprocess_pubobj_list(List *pubobjspec_list, core_yyscan_t yyscanner)
19639 : {
19640 : ListCell *cell;
19641 : PublicationObjSpec *pubobj;
19642 1648 : PublicationObjSpecType prevobjtype = PUBLICATIONOBJ_CONTINUATION;
19643 :
19644 1648 : if (!pubobjspec_list)
19645 0 : return;
19646 :
19647 1648 : pubobj = (PublicationObjSpec *) linitial(pubobjspec_list);
19648 1648 : if (pubobj->pubobjtype == PUBLICATIONOBJ_CONTINUATION)
19649 12 : ereport(ERROR,
19650 : errcode(ERRCODE_SYNTAX_ERROR),
19651 : errmsg("invalid publication object list"),
19652 : errdetail("One of TABLE or TABLES IN SCHEMA must be specified before a standalone table or schema name."),
19653 : parser_errposition(pubobj->location));
19654 :
19655 3502 : foreach(cell, pubobjspec_list)
19656 : {
19657 1890 : pubobj = (PublicationObjSpec *) lfirst(cell);
19658 :
19659 1890 : if (pubobj->pubobjtype == PUBLICATIONOBJ_CONTINUATION)
19660 174 : pubobj->pubobjtype = prevobjtype;
19661 :
19662 1890 : if (pubobj->pubobjtype == PUBLICATIONOBJ_TABLE)
19663 : {
19664 : /* relation name or pubtable must be set for this type of object */
19665 1446 : if (!pubobj->name && !pubobj->pubtable)
19666 6 : ereport(ERROR,
19667 : errcode(ERRCODE_SYNTAX_ERROR),
19668 : errmsg("invalid table name"),
19669 : parser_errposition(pubobj->location));
19670 :
19671 1440 : if (pubobj->name)
19672 : {
19673 : /* convert it to PublicationTable */
19674 58 : PublicationTable *pubtable = makeNode(PublicationTable);
19675 :
19676 58 : pubtable->relation =
19677 58 : makeRangeVar(NULL, pubobj->name, pubobj->location);
19678 58 : pubobj->pubtable = pubtable;
19679 58 : pubobj->name = NULL;
19680 : }
19681 : }
19682 444 : else if (pubobj->pubobjtype == PUBLICATIONOBJ_TABLES_IN_SCHEMA ||
19683 24 : pubobj->pubobjtype == PUBLICATIONOBJ_TABLES_IN_CUR_SCHEMA)
19684 : {
19685 : /* WHERE clause is not allowed on a schema object */
19686 444 : if (pubobj->pubtable && pubobj->pubtable->whereClause)
19687 6 : ereport(ERROR,
19688 : errcode(ERRCODE_SYNTAX_ERROR),
19689 : errmsg("WHERE clause not allowed for schema"),
19690 : parser_errposition(pubobj->location));
19691 :
19692 : /* Column list is not allowed on a schema object */
19693 438 : if (pubobj->pubtable && pubobj->pubtable->columns)
19694 6 : ereport(ERROR,
19695 : errcode(ERRCODE_SYNTAX_ERROR),
19696 : errmsg("column specification not allowed for schema"),
19697 : parser_errposition(pubobj->location));
19698 :
19699 : /*
19700 : * We can distinguish between the different type of schema objects
19701 : * based on whether name and pubtable is set.
19702 : */
19703 432 : if (pubobj->name)
19704 402 : pubobj->pubobjtype = PUBLICATIONOBJ_TABLES_IN_SCHEMA;
19705 30 : else if (!pubobj->name && !pubobj->pubtable)
19706 24 : pubobj->pubobjtype = PUBLICATIONOBJ_TABLES_IN_CUR_SCHEMA;
19707 : else
19708 6 : ereport(ERROR,
19709 : errcode(ERRCODE_SYNTAX_ERROR),
19710 : errmsg("invalid schema name"),
19711 : parser_errposition(pubobj->location));
19712 : }
19713 :
19714 1866 : prevobjtype = pubobj->pubobjtype;
19715 : }
19716 : }
19717 :
19718 : /*----------
19719 : * Recursive view transformation
19720 : *
19721 : * Convert
19722 : *
19723 : * CREATE RECURSIVE VIEW relname (aliases) AS query
19724 : *
19725 : * to
19726 : *
19727 : * CREATE VIEW relname (aliases) AS
19728 : * WITH RECURSIVE relname (aliases) AS (query)
19729 : * SELECT aliases FROM relname
19730 : *
19731 : * Actually, just the WITH ... part, which is then inserted into the original
19732 : * view definition as the query.
19733 : * ----------
19734 : */
19735 : static Node *
19736 14 : makeRecursiveViewSelect(char *relname, List *aliases, Node *query)
19737 : {
19738 14 : SelectStmt *s = makeNode(SelectStmt);
19739 14 : WithClause *w = makeNode(WithClause);
19740 14 : CommonTableExpr *cte = makeNode(CommonTableExpr);
19741 14 : List *tl = NIL;
19742 : ListCell *lc;
19743 :
19744 : /* create common table expression */
19745 14 : cte->ctename = relname;
19746 14 : cte->aliascolnames = aliases;
19747 14 : cte->ctematerialized = CTEMaterializeDefault;
19748 14 : cte->ctequery = query;
19749 14 : cte->location = -1;
19750 :
19751 : /* create WITH clause and attach CTE */
19752 14 : w->recursive = true;
19753 14 : w->ctes = list_make1(cte);
19754 14 : w->location = -1;
19755 :
19756 : /*
19757 : * create target list for the new SELECT from the alias list of the
19758 : * recursive view specification
19759 : */
19760 28 : foreach(lc, aliases)
19761 : {
19762 14 : ResTarget *rt = makeNode(ResTarget);
19763 :
19764 14 : rt->name = NULL;
19765 14 : rt->indirection = NIL;
19766 14 : rt->val = makeColumnRef(strVal(lfirst(lc)), NIL, -1, 0);
19767 14 : rt->location = -1;
19768 :
19769 14 : tl = lappend(tl, rt);
19770 : }
19771 :
19772 : /*
19773 : * create new SELECT combining WITH clause, target list, and fake FROM
19774 : * clause
19775 : */
19776 14 : s->withClause = w;
19777 14 : s->targetList = tl;
19778 14 : s->fromClause = list_make1(makeRangeVar(NULL, relname, -1));
19779 :
19780 14 : return (Node *) s;
19781 : }
19782 :
19783 : /* parser_init()
19784 : * Initialize to parse one query string
19785 : */
19786 : void
19787 766018 : parser_init(base_yy_extra_type *yyext)
19788 : {
19789 766018 : yyext->parsetree = NIL; /* in case grammar forgets to set it */
19790 766018 : }
|