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-2026, 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_pub_all_objtype_list(List *all_objects_list,
206 : List **pubobjects,
207 : bool *all_tables,
208 : bool *all_sequences,
209 : core_yyscan_t yyscanner);
210 : static void preprocess_pubobj_list(List *pubobjspec_list,
211 : core_yyscan_t yyscanner);
212 : static Node *makeRecursiveViewSelect(char *relname, List *aliases, Node *query);
213 :
214 : %}
215 :
216 : %pure-parser
217 : %expect 0
218 : %name-prefix="base_yy"
219 : %locations
220 :
221 : %parse-param {core_yyscan_t yyscanner}
222 : %lex-param {core_yyscan_t yyscanner}
223 :
224 : %union
225 : {
226 : core_YYSTYPE core_yystype;
227 : /* these fields must match core_YYSTYPE: */
228 : int ival;
229 : char *str;
230 : const char *keyword;
231 :
232 : char chr;
233 : bool boolean;
234 : JoinType jtype;
235 : DropBehavior dbehavior;
236 : OnCommitAction oncommit;
237 : List *list;
238 : Node *node;
239 : ObjectType objtype;
240 : TypeName *typnam;
241 : FunctionParameter *fun_param;
242 : FunctionParameterMode fun_param_mode;
243 : ObjectWithArgs *objwithargs;
244 : DefElem *defelt;
245 : SortBy *sortby;
246 : WindowDef *windef;
247 : JoinExpr *jexpr;
248 : IndexElem *ielem;
249 : StatsElem *selem;
250 : Alias *alias;
251 : RangeVar *range;
252 : IntoClause *into;
253 : WithClause *with;
254 : InferClause *infer;
255 : OnConflictClause *onconflict;
256 : A_Indices *aind;
257 : ResTarget *target;
258 : struct PrivTarget *privtarget;
259 : AccessPriv *accesspriv;
260 : struct ImportQual *importqual;
261 : InsertStmt *istmt;
262 : VariableSetStmt *vsetstmt;
263 : PartitionElem *partelem;
264 : PartitionSpec *partspec;
265 : PartitionBoundSpec *partboundspec;
266 : SinglePartitionSpec *singlepartspec;
267 : RoleSpec *rolespec;
268 : PublicationObjSpec *publicationobjectspec;
269 : PublicationAllObjSpec *publicationallobjectspec;
270 : struct SelectLimit *selectlimit;
271 : SetQuantifier setquantifier;
272 : struct GroupClause *groupclause;
273 : MergeMatchKind mergematch;
274 : MergeWhenClause *mergewhen;
275 : struct KeyActions *keyactions;
276 : struct KeyAction *keyaction;
277 : ReturningClause *retclause;
278 : ReturningOptionKind retoptionkind;
279 : }
280 :
281 : %type <node> stmt toplevel_stmt schema_stmt routine_body_stmt
282 : AlterEventTrigStmt AlterCollationStmt
283 : AlterDatabaseStmt AlterDatabaseSetStmt AlterDomainStmt AlterEnumStmt
284 : AlterFdwStmt AlterForeignServerStmt AlterGroupStmt
285 : AlterObjectDependsStmt AlterObjectSchemaStmt AlterOwnerStmt
286 : AlterOperatorStmt AlterTypeStmt AlterSeqStmt AlterSystemStmt AlterTableStmt
287 : AlterTblSpcStmt AlterExtensionStmt AlterExtensionContentsStmt
288 : AlterCompositeTypeStmt AlterUserMappingStmt
289 : AlterRoleStmt AlterRoleSetStmt AlterPolicyStmt AlterStatsStmt
290 : AlterDefaultPrivilegesStmt DefACLAction
291 : AnalyzeStmt CallStmt ClosePortalStmt CommentStmt
292 : ConstraintsSetStmt CopyStmt CreateAsStmt CreateCastStmt
293 : CreateDomainStmt CreateExtensionStmt CreateGroupStmt CreateOpClassStmt
294 : CreateOpFamilyStmt AlterOpFamilyStmt CreatePLangStmt
295 : CreateSchemaStmt CreateSeqStmt CreateStmt CreateStatsStmt CreateTableSpaceStmt
296 : CreateFdwStmt CreateForeignServerStmt CreateForeignTableStmt
297 : CreateAssertionStmt CreateTransformStmt CreateTrigStmt CreateEventTrigStmt
298 : CreatePropGraphStmt AlterPropGraphStmt
299 : CreateUserStmt CreateUserMappingStmt CreateRoleStmt CreatePolicyStmt
300 : CreatedbStmt DeclareCursorStmt DefineStmt DeleteStmt DiscardStmt DoStmt
301 : DropOpClassStmt DropOpFamilyStmt DropStmt
302 : DropCastStmt DropRoleStmt
303 : DropdbStmt DropTableSpaceStmt
304 : DropTransformStmt
305 : DropUserMappingStmt ExplainStmt FetchStmt
306 : GrantStmt GrantRoleStmt ImportForeignSchemaStmt IndexStmt InsertStmt
307 : ListenStmt LoadStmt LockStmt MergeStmt NotifyStmt ExplainableStmt PreparableStmt
308 : CreateFunctionStmt AlterFunctionStmt ReindexStmt RemoveAggrStmt
309 : RemoveFuncStmt RemoveOperStmt RenameStmt RepackStmt ReturnStmt RevokeStmt RevokeRoleStmt
310 : RuleActionStmt RuleActionStmtOrEmpty RuleStmt
311 : SecLabelStmt SelectStmt TransactionStmt TransactionStmtLegacy TruncateStmt
312 : UnlistenStmt UpdateStmt VacuumStmt
313 : VariableResetStmt VariableSetStmt VariableShowStmt
314 : ViewStmt WaitStmt CheckPointStmt CreateConversionStmt
315 : DeallocateStmt PrepareStmt ExecuteStmt
316 : DropOwnedStmt ReassignOwnedStmt
317 : AlterTSConfigurationStmt AlterTSDictionaryStmt
318 : CreateMatViewStmt RefreshMatViewStmt CreateAmStmt
319 : CreatePublicationStmt AlterPublicationStmt
320 : CreateSubscriptionStmt AlterSubscriptionStmt DropSubscriptionStmt
321 :
322 : %type <node> select_no_parens select_with_parens select_clause
323 : simple_select values_clause
324 : PLpgSQL_Expr PLAssignStmt
325 :
326 : %type <str> opt_single_name
327 : %type <list> opt_qualified_name
328 : %type <boolean> opt_concurrently opt_usingindex
329 : %type <dbehavior> opt_drop_behavior
330 : %type <list> opt_utility_option_list
331 : %type <list> opt_wait_with_clause
332 : %type <list> utility_option_list
333 : %type <defelt> utility_option_elem
334 : %type <str> utility_option_name
335 : %type <node> utility_option_arg
336 :
337 : %type <node> alter_column_default opclass_item opclass_drop alter_using
338 : %type <ival> add_drop opt_asc_desc opt_nulls_order
339 :
340 : %type <node> alter_table_cmd alter_type_cmd opt_collate_clause
341 : replica_identity partition_cmd index_partition_cmd
342 : %type <list> alter_table_cmds alter_type_cmds
343 : %type <list> alter_identity_column_option_list
344 : %type <defelt> alter_identity_column_option
345 : %type <node> set_statistics_value
346 : %type <str> set_access_method_name
347 :
348 : %type <list> createdb_opt_list createdb_opt_items copy_opt_list
349 : transaction_mode_list
350 : create_extension_opt_list alter_extension_opt_list
351 : %type <defelt> createdb_opt_item copy_opt_item
352 : transaction_mode_item
353 : create_extension_opt_item alter_extension_opt_item
354 :
355 : %type <ival> opt_lock lock_type cast_context
356 : %type <defelt> drop_option
357 : %type <boolean> opt_or_replace opt_no
358 : opt_grant_grant_option
359 : opt_nowait opt_if_exists opt_with_data
360 : opt_transaction_chain
361 : %type <list> grant_role_opt_list
362 : %type <defelt> grant_role_opt
363 : %type <node> grant_role_opt_value
364 : %type <ival> opt_nowait_or_skip
365 :
366 : %type <list> OptRoleList AlterOptRoleList
367 : %type <defelt> CreateOptRoleElem AlterOptRoleElem
368 :
369 : %type <str> opt_type
370 : %type <str> foreign_server_version opt_foreign_server_version
371 : %type <str> opt_in_database
372 :
373 : %type <str> parameter_name
374 : %type <list> OptSchemaEltList parameter_name_list
375 :
376 : %type <chr> am_type
377 :
378 : %type <boolean> TriggerForSpec TriggerForType
379 : %type <ival> TriggerActionTime
380 : %type <list> TriggerEvents TriggerOneEvent
381 : %type <node> TriggerFuncArg
382 : %type <node> TriggerWhen
383 : %type <str> TransitionRelName
384 : %type <boolean> TransitionRowOrTable TransitionOldOrNew
385 : %type <node> TriggerTransition
386 :
387 : %type <list> event_trigger_when_list event_trigger_value_list
388 : %type <defelt> event_trigger_when_item
389 : %type <chr> enable_trigger
390 :
391 : %type <str> copy_file_name
392 : access_method_clause attr_name
393 : table_access_method_clause name cursor_name file_name
394 : cluster_index_specification
395 :
396 : %type <list> func_name handler_name qual_Op qual_all_Op subquery_Op
397 : opt_inline_handler opt_validator validator_clause
398 : opt_collate
399 :
400 : %type <range> qualified_name insert_target OptConstrFromTable
401 :
402 : %type <str> all_Op MathOp
403 :
404 : %type <str> row_security_cmd RowSecurityDefaultForCmd
405 : %type <boolean> RowSecurityDefaultPermissive
406 : %type <node> RowSecurityOptionalWithCheck RowSecurityOptionalExpr
407 : %type <list> RowSecurityDefaultToRole RowSecurityOptionalToRole
408 :
409 : %type <str> iso_level opt_encoding
410 : %type <rolespec> grantee
411 : %type <list> grantee_list
412 : %type <accesspriv> privilege
413 : %type <list> privileges privilege_list
414 : %type <privtarget> privilege_target
415 : %type <objwithargs> function_with_argtypes aggregate_with_argtypes operator_with_argtypes
416 : %type <list> function_with_argtypes_list aggregate_with_argtypes_list operator_with_argtypes_list
417 : %type <ival> defacl_privilege_target
418 : %type <defelt> DefACLOption
419 : %type <list> DefACLOptionList
420 : %type <ival> import_qualification_type
421 : %type <importqual> import_qualification
422 : %type <node> vacuum_relation
423 : %type <selectlimit> opt_select_limit select_limit limit_clause
424 :
425 : %type <list> parse_toplevel stmtmulti routine_body_stmt_list
426 : OptTableElementList TableElementList OptInherit definition
427 : OptTypedTableElementList TypedTableElementList
428 : reloptions opt_reloptions
429 : OptWith opt_definition func_args func_args_list
430 : func_args_with_defaults func_args_with_defaults_list
431 : aggr_args aggr_args_list
432 : func_as createfunc_opt_list opt_createfunc_opt_list alterfunc_opt_list
433 : old_aggr_definition old_aggr_list
434 : oper_argtypes RuleActionList RuleActionMulti
435 : opt_column_list columnList opt_name_list
436 : sort_clause opt_sort_clause sortby_list index_params
437 : stats_params
438 : opt_include opt_c_include index_including_params
439 : name_list role_list from_clause from_list opt_array_bounds
440 : qualified_name_list any_name any_name_list type_name_list
441 : any_operator expr_list attrs
442 : distinct_clause opt_distinct_clause
443 : target_list opt_target_list insert_column_list set_target_list
444 : merge_values_clause
445 : set_clause_list set_clause
446 : def_list operator_def_list indirection opt_indirection
447 : reloption_list TriggerFuncArgs opclass_item_list opclass_drop_list
448 : opclass_purpose opt_opfamily transaction_mode_list_or_empty
449 : OptTableFuncElementList TableFuncElementList opt_type_modifiers
450 : prep_type_clause
451 : execute_param_clause using_clause
452 : returning_with_clause returning_options
453 : opt_enum_val_list enum_val_list table_func_column_list
454 : create_generic_options alter_generic_options
455 : relation_expr_list dostmt_opt_list
456 : transform_element_list transform_type_list
457 : TriggerTransitions TriggerReferencing
458 : vacuum_relation_list opt_vacuum_relation_list
459 : drop_option_list pub_obj_list pub_all_obj_type_list
460 : pub_except_obj_list opt_pub_except_clause
461 :
462 : %type <retclause> returning_clause
463 : %type <node> returning_option
464 : %type <retoptionkind> returning_option_kind
465 : %type <node> opt_routine_body
466 : %type <groupclause> group_clause
467 : %type <list> group_by_list
468 : %type <node> group_by_item empty_grouping_set rollup_clause cube_clause
469 : %type <node> grouping_sets_clause
470 :
471 : %type <list> opt_fdw_options fdw_options
472 : %type <defelt> fdw_option
473 :
474 : %type <range> OptTempTableName
475 : %type <into> into_clause create_as_target create_mv_target
476 :
477 : %type <defelt> createfunc_opt_item common_func_opt_item dostmt_opt_item
478 : %type <fun_param> func_arg func_arg_with_default table_func_column aggr_arg
479 : %type <fun_param_mode> arg_class
480 : %type <typnam> func_return func_type
481 :
482 : %type <boolean> opt_trusted opt_restart_seqs
483 : %type <ival> OptTemp
484 : %type <ival> OptNoLog
485 : %type <oncommit> OnCommitOption
486 :
487 : %type <ival> for_locking_strength opt_for_locking_strength
488 : %type <node> for_locking_item
489 : %type <list> for_locking_clause opt_for_locking_clause for_locking_items
490 : %type <list> locked_rels_list
491 : %type <setquantifier> set_quantifier
492 :
493 : %type <node> join_qual
494 : %type <jtype> join_type
495 :
496 : %type <list> extract_list overlay_list position_list
497 : %type <list> substr_list trim_list
498 : %type <list> opt_interval interval_second
499 : %type <str> unicode_normal_form
500 :
501 : %type <boolean> opt_instead
502 : %type <boolean> opt_unique opt_verbose opt_full
503 : %type <boolean> opt_freeze opt_analyze opt_default
504 : %type <defelt> opt_binary copy_delimiter
505 :
506 : %type <boolean> copy_from opt_program
507 :
508 : %type <ival> event cursor_options opt_hold opt_set_data
509 : %type <objtype> object_type_any_name object_type_name object_type_name_on_any_name
510 : drop_type_name
511 :
512 : %type <node> fetch_args select_limit_value
513 : offset_clause select_offset_value
514 : select_fetch_first_value I_or_F_const
515 : %type <ival> row_or_rows first_or_next
516 :
517 : %type <list> OptSeqOptList SeqOptList OptParenthesizedSeqOptList
518 : %type <defelt> SeqOptElem
519 :
520 : %type <istmt> insert_rest
521 : %type <infer> opt_conf_expr
522 : %type <onconflict> opt_on_conflict
523 : %type <mergewhen> merge_insert merge_update merge_delete
524 :
525 : %type <mergematch> merge_when_tgt_matched merge_when_tgt_not_matched
526 : %type <node> merge_when_clause opt_merge_when_condition
527 : %type <list> merge_when_list
528 :
529 : %type <vsetstmt> generic_set set_rest set_rest_more generic_reset reset_rest
530 : SetResetClause FunctionSetResetClause
531 :
532 : %type <node> TableElement TypedTableElement ConstraintElem DomainConstraintElem TableFuncElement
533 : %type <node> columnDef columnOptions optionalPeriodName
534 : %type <defelt> def_elem reloption_elem old_aggr_elem operator_def_elem
535 : %type <node> def_arg columnElem where_clause where_or_current_clause
536 : a_expr b_expr c_expr AexprConst indirection_el opt_slice_bound
537 : columnref having_clause func_table xmltable array_expr
538 : OptWhereClause operator_def_arg
539 : %type <list> opt_column_and_period_list
540 : %type <list> rowsfrom_item rowsfrom_list opt_col_def_list
541 : %type <boolean> opt_ordinality opt_without_overlaps
542 : %type <list> ExclusionConstraintList ExclusionConstraintElem
543 : %type <list> func_arg_list func_arg_list_opt
544 : %type <node> func_arg_expr
545 : %type <list> row explicit_row implicit_row type_list array_expr_list
546 : %type <node> case_expr case_arg when_clause case_default
547 : %type <list> when_clause_list
548 : %type <node> opt_search_clause opt_cycle_clause
549 : %type <ival> sub_type opt_materialized
550 : %type <node> NumericOnly
551 : %type <list> NumericOnly_list
552 : %type <alias> alias_clause opt_alias_clause opt_alias_clause_for_join_using
553 : %type <list> func_alias_clause
554 : %type <sortby> sortby
555 : %type <ielem> index_elem index_elem_options
556 : %type <selem> stats_param
557 : %type <node> table_ref
558 : %type <jexpr> joined_table
559 : %type <range> relation_expr
560 : %type <range> extended_relation_expr
561 : %type <range> relation_expr_opt_alias
562 : %type <node> tablesample_clause opt_repeatable_clause
563 : %type <target> target_el set_target insert_column_item
564 :
565 : %type <str> generic_option_name
566 : %type <node> generic_option_arg
567 : %type <defelt> generic_option_elem alter_generic_option_elem
568 : %type <list> generic_option_list alter_generic_option_list
569 :
570 : %type <ival> reindex_target_relation reindex_target_all
571 :
572 : %type <node> copy_generic_opt_arg copy_generic_opt_arg_list_item
573 : %type <defelt> copy_generic_opt_elem
574 : %type <list> copy_generic_opt_list copy_generic_opt_arg_list
575 : %type <list> copy_options
576 :
577 : %type <typnam> Typename SimpleTypename ConstTypename
578 : GenericType Numeric opt_float JsonType
579 : Character ConstCharacter
580 : CharacterWithLength CharacterWithoutLength
581 : ConstDatetime ConstInterval
582 : Bit ConstBit BitWithLength BitWithoutLength
583 : %type <str> character
584 : %type <str> extract_arg
585 : %type <boolean> opt_varying opt_timezone opt_no_inherit
586 :
587 : %type <ival> Iconst SignedIconst
588 : %type <str> Sconst comment_text notify_payload
589 : %type <str> RoleId opt_boolean_or_string
590 : %type <list> var_list
591 : %type <str> ColId ColLabel BareColLabel
592 : %type <str> NonReservedWord NonReservedWord_or_Sconst
593 : %type <str> var_name type_function_name param_name
594 : %type <str> createdb_opt_name plassign_target
595 : %type <node> var_value zone_value
596 : %type <rolespec> auth_ident RoleSpec opt_granted_by
597 : %type <publicationobjectspec> PublicationObjSpec
598 : %type <publicationobjectspec> PublicationExceptObjSpec
599 : %type <publicationallobjectspec> PublicationAllObjSpec
600 :
601 : %type <keyword> unreserved_keyword type_func_name_keyword
602 : %type <keyword> col_name_keyword reserved_keyword
603 : %type <keyword> bare_label_keyword
604 :
605 : %type <node> DomainConstraint TableConstraint TableLikeClause
606 : %type <ival> TableLikeOptionList TableLikeOption
607 : %type <str> column_compression opt_column_compression column_storage opt_column_storage
608 : %type <list> ColQualList
609 : %type <node> ColConstraint ColConstraintElem ConstraintAttr
610 : %type <ival> key_match
611 : %type <keyaction> key_delete key_update key_action
612 : %type <keyactions> key_actions
613 : %type <ival> ConstraintAttributeSpec ConstraintAttributeElem
614 : %type <str> ExistingIndex
615 :
616 : %type <list> constraints_set_list
617 : %type <boolean> constraints_set_mode
618 : %type <str> OptTableSpace OptConsTableSpace
619 : %type <rolespec> OptTableSpaceOwner
620 : %type <ival> opt_check_option
621 :
622 : %type <str> opt_provider security_label
623 :
624 : %type <target> labeled_expr
625 : %type <list> labeled_expr_list xml_attributes
626 : %type <node> xml_root_version opt_xml_root_standalone
627 : %type <node> xmlexists_argument
628 : %type <ival> document_or_content
629 : %type <boolean> xml_indent_option xml_whitespace_option
630 : %type <list> xmltable_column_list xmltable_column_option_list
631 : %type <node> xmltable_column_el
632 : %type <defelt> xmltable_column_option_el
633 : %type <list> xml_namespace_list
634 : %type <target> xml_namespace_el
635 :
636 : %type <node> func_application func_expr_common_subexpr
637 : %type <node> func_expr func_expr_windowless
638 : %type <node> common_table_expr
639 : %type <with> with_clause opt_with_clause
640 : %type <list> cte_list
641 :
642 : %type <list> within_group_clause
643 : %type <node> filter_clause
644 : %type <list> window_clause window_definition_list opt_partition_clause
645 : %type <windef> window_definition over_clause window_specification
646 : opt_frame_clause frame_extent frame_bound
647 : %type <ival> null_treatment opt_window_exclusion_clause
648 : %type <str> opt_existing_window_name
649 : %type <boolean> opt_if_not_exists
650 : %type <boolean> opt_unique_null_treatment
651 : %type <ival> generated_when override_kind opt_virtual_or_stored
652 : %type <partspec> PartitionSpec OptPartitionSpec
653 : %type <partelem> part_elem
654 : %type <list> part_params
655 : %type <partboundspec> PartitionBoundSpec
656 : %type <singlepartspec> SinglePartitionSpec
657 : %type <list> partitions_list
658 : %type <list> hash_partbound
659 : %type <defelt> hash_partbound_elem
660 :
661 : %type <node> json_format_clause
662 : json_format_clause_opt
663 : json_value_expr
664 : json_returning_clause_opt
665 : json_name_and_value
666 : json_aggregate_func
667 : json_argument
668 : json_behavior
669 : json_on_error_clause_opt
670 : json_table
671 : json_table_column_definition
672 : json_table_column_path_clause_opt
673 : %type <list> json_name_and_value_list
674 : json_value_expr_list
675 : json_array_aggregate_order_by_clause_opt
676 : json_arguments
677 : json_behavior_clause_opt
678 : json_passing_clause_opt
679 : json_table_column_definition_list
680 : %type <str> json_table_path_name_opt
681 : %type <ival> json_behavior_type
682 : json_predicate_type_constraint
683 : json_quotes_clause_opt
684 : json_wrapper_behavior
685 : %type <boolean> json_key_uniqueness_constraint_opt
686 : json_object_constructor_null_clause_opt
687 : json_array_constructor_null_clause_opt
688 :
689 : %type <list> vertex_tables_clause edge_tables_clause
690 : opt_vertex_tables_clause opt_edge_tables_clause
691 : vertex_table_list
692 : opt_graph_table_key_clause
693 : edge_table_list
694 : source_vertex_table destination_vertex_table
695 : opt_element_table_label_and_properties
696 : label_and_properties_list
697 : add_label_list
698 : %type <node> vertex_table_definition edge_table_definition
699 : %type <alias> opt_propgraph_table_alias
700 : %type <str> element_table_label_clause
701 : %type <node> label_and_properties element_table_properties
702 : add_label
703 : %type <ival> vertex_or_edge
704 :
705 : %type <list> opt_graph_pattern_quantifier
706 : path_pattern_list
707 : path_pattern
708 : path_pattern_expression
709 : path_term
710 : %type <node> graph_pattern
711 : path_factor
712 : path_primary
713 : opt_is_label_expression
714 : label_expression
715 : label_disjunction
716 : label_term
717 : %type <str> opt_colid
718 :
719 : /*
720 : * Non-keyword token types. These are hard-wired into the "flex" lexer.
721 : * They must be listed first so that their numeric codes do not depend on
722 : * the set of keywords. PL/pgSQL depends on this so that it can share the
723 : * same lexer. If you add/change tokens here, fix PL/pgSQL to match!
724 : *
725 : * UIDENT and USCONST are reduced to IDENT and SCONST in parser.c, so that
726 : * they need no productions here; but we must assign token codes to them.
727 : *
728 : * DOT_DOT is unused in the core SQL grammar, and so will always provoke
729 : * parse errors. It is needed by PL/pgSQL.
730 : */
731 : %token <str> IDENT UIDENT FCONST SCONST USCONST BCONST XCONST Op
732 : %token <ival> ICONST PARAM
733 : %token TYPECAST DOT_DOT COLON_EQUALS EQUALS_GREATER
734 : %token LESS_EQUALS GREATER_EQUALS NOT_EQUALS
735 :
736 : /*
737 : * If you want to make any keyword changes, update the keyword table in
738 : * src/include/parser/kwlist.h and add new keywords to the appropriate one
739 : * of the reserved-or-not-so-reserved keyword lists, below; search
740 : * this file for "Keyword category lists".
741 : */
742 :
743 : /* ordinary key words in alphabetical order */
744 : %token <keyword> ABORT_P ABSENT ABSOLUTE_P ACCESS ACTION ADD_P ADMIN AFTER
745 : AGGREGATE ALL ALSO ALTER ALWAYS ANALYSE ANALYZE AND ANY ARRAY AS ASC
746 : ASENSITIVE ASSERTION ASSIGNMENT ASYMMETRIC ATOMIC AT ATTACH ATTRIBUTE AUTHORIZATION
747 :
748 : BACKWARD BEFORE BEGIN_P BETWEEN BIGINT BINARY BIT
749 : BOOLEAN_P BOTH BREADTH BY
750 :
751 : CACHE CALL CALLED CASCADE CASCADED CASE CAST CATALOG_P CHAIN CHAR_P
752 : CHARACTER CHARACTERISTICS CHECK CHECKPOINT CLASS CLOSE
753 : CLUSTER COALESCE COLLATE COLLATION COLUMN COLUMNS COMMENT COMMENTS COMMIT
754 : COMMITTED COMPRESSION CONCURRENTLY CONDITIONAL CONFIGURATION CONFLICT
755 : CONNECTION CONSTRAINT CONSTRAINTS CONTENT_P CONTINUE_P CONVERSION_P COPY
756 : COST CREATE CROSS CSV CUBE CURRENT_P
757 : CURRENT_CATALOG CURRENT_DATE CURRENT_ROLE CURRENT_SCHEMA
758 : CURRENT_TIME CURRENT_TIMESTAMP CURRENT_USER CURSOR CYCLE
759 :
760 : DATA_P DATABASE DAY_P DEALLOCATE DEC DECIMAL_P DECLARE DEFAULT DEFAULTS
761 : DEFERRABLE DEFERRED DEFINER DELETE_P DELIMITER DELIMITERS DEPENDS DEPTH DESC DESTINATION
762 : DETACH DICTIONARY DISABLE_P DISCARD DISTINCT DO DOCUMENT_P DOMAIN_P
763 : DOUBLE_P DROP
764 :
765 : EACH EDGE ELSE EMPTY_P ENABLE_P ENCODING ENCRYPTED END_P ENFORCED ENUM_P
766 : ERROR_P ESCAPE EVENT EXCEPT EXCLUDE EXCLUDING EXCLUSIVE EXECUTE EXISTS
767 : EXPLAIN EXPRESSION EXTENSION EXTERNAL EXTRACT
768 :
769 : FALSE_P FAMILY FETCH FILTER FINALIZE FIRST_P FLOAT_P FOLLOWING FOR
770 : FORCE FOREIGN FORMAT FORWARD FREEZE FROM FULL FUNCTION FUNCTIONS
771 :
772 : GENERATED GLOBAL GRANT GRANTED GRAPH GRAPH_TABLE GREATEST GROUP_P GROUPING GROUPS
773 :
774 : HANDLER HAVING HEADER_P HOLD HOUR_P
775 :
776 : IDENTITY_P IF_P IGNORE_P ILIKE IMMEDIATE IMMUTABLE IMPLICIT_P IMPORT_P IN_P INCLUDE
777 : INCLUDING INCREMENT INDENT INDEX INDEXES INHERIT INHERITS INITIALLY INLINE_P
778 : INNER_P INOUT INPUT_P INSENSITIVE INSERT INSTEAD INT_P INTEGER
779 : INTERSECT INTERVAL INTO INVOKER IS ISNULL ISOLATION
780 :
781 : JOIN JSON JSON_ARRAY JSON_ARRAYAGG JSON_EXISTS JSON_OBJECT JSON_OBJECTAGG
782 : JSON_QUERY JSON_SCALAR JSON_SERIALIZE JSON_TABLE JSON_VALUE
783 :
784 : KEEP KEY KEYS
785 :
786 : LABEL LANGUAGE LARGE_P LAST_P LATERAL_P
787 : LEADING LEAKPROOF LEAST LEFT LEVEL LIKE LIMIT LISTEN LOAD LOCAL
788 : LOCALTIME LOCALTIMESTAMP LOCATION LOCK_P LOCKED LOGGED LSN_P
789 :
790 : MAPPING MATCH MATCHED MATERIALIZED MAXVALUE MERGE MERGE_ACTION METHOD
791 : MINUTE_P MINVALUE MODE MONTH_P MOVE
792 :
793 : NAME_P NAMES NATIONAL NATURAL NCHAR NESTED NEW NEXT NFC NFD NFKC NFKD NO NODE
794 : NONE NORMALIZE NORMALIZED
795 : NOT NOTHING NOTIFY NOTNULL NOWAIT NULL_P NULLIF
796 : NULLS_P NUMERIC
797 :
798 : OBJECT_P OBJECTS_P OF OFF OFFSET OIDS OLD OMIT ON ONLY OPERATOR OPTION OPTIONS OR
799 : ORDER ORDINALITY OTHERS OUT_P OUTER_P
800 : OVER OVERLAPS OVERLAY OVERRIDING OWNED OWNER
801 :
802 : PARALLEL PARAMETER PARSER PARTIAL PARTITION PARTITIONS PASSING PASSWORD PATH
803 : PERIOD PLACING PLAN PLANS POLICY
804 : POSITION PRECEDING PRECISION PRESERVE PREPARE PREPARED PRIMARY
805 : PRIOR PRIVILEGES PROCEDURAL PROCEDURE PROCEDURES PROGRAM PROPERTIES PROPERTY PUBLICATION
806 :
807 : QUOTE QUOTES
808 :
809 : RANGE READ REAL REASSIGN RECURSIVE REF_P REFERENCES REFERENCING
810 : REFRESH REINDEX RELATIONSHIP RELATIVE_P RELEASE RENAME REPACK REPEATABLE REPLACE REPLICA
811 : RESET RESPECT_P RESTART RESTRICT RETURN RETURNING RETURNS REVOKE RIGHT ROLE ROLLBACK ROLLUP
812 : ROUTINE ROUTINES ROW ROWS RULE
813 :
814 : SAVEPOINT SCALAR SCHEMA SCHEMAS SCROLL SEARCH SECOND_P SECURITY SELECT
815 : SEQUENCE SEQUENCES
816 : SERIALIZABLE SERVER SESSION SESSION_USER SET SETS SETOF SHARE SHOW
817 : SIMILAR SIMPLE SKIP SMALLINT SNAPSHOT SOME SPLIT SOURCE SQL_P STABLE STANDALONE_P
818 : START STATEMENT STATISTICS STDIN STDOUT STORAGE STORED STRICT_P STRING_P STRIP_P
819 : SUBSCRIPTION SUBSTRING SUPPORT SYMMETRIC SYSID SYSTEM_P SYSTEM_USER
820 :
821 : TABLE TABLES TABLESAMPLE TABLESPACE TARGET TEMP TEMPLATE TEMPORARY TEXT_P THEN
822 : TIES TIME TIMESTAMP TO TRAILING TRANSACTION TRANSFORM
823 : TREAT TRIGGER TRIM TRUE_P
824 : TRUNCATE TRUSTED TYPE_P TYPES_P
825 :
826 : UESCAPE UNBOUNDED UNCONDITIONAL UNCOMMITTED UNENCRYPTED UNION UNIQUE UNKNOWN
827 : UNLISTEN UNLOGGED UNTIL UPDATE USER USING
828 :
829 : VACUUM VALID VALIDATE VALIDATOR VALUE_P VALUES VARCHAR VARIADIC VARYING
830 : VERBOSE VERSION_P VERTEX VIEW VIEWS VIRTUAL VOLATILE
831 :
832 : WAIT WHEN WHERE WHITESPACE_P WINDOW WITH WITHIN WITHOUT WORK WRAPPER WRITE
833 :
834 : XML_P XMLATTRIBUTES XMLCONCAT XMLELEMENT XMLEXISTS XMLFOREST XMLNAMESPACES
835 : XMLPARSE XMLPI XMLROOT XMLSERIALIZE XMLTABLE
836 :
837 : YEAR_P YES_P
838 :
839 : ZONE
840 :
841 : /*
842 : * The grammar thinks these are keywords, but they are not in the kwlist.h
843 : * list and so can never be entered directly. The filter in parser.c
844 : * creates these tokens when required (based on looking one token ahead).
845 : *
846 : * NOT_LA exists so that productions such as NOT LIKE can be given the same
847 : * precedence as LIKE; otherwise they'd effectively have the same precedence
848 : * as NOT, at least with respect to their left-hand subexpression.
849 : * FORMAT_LA, NULLS_LA, WITH_LA, and WITHOUT_LA are needed to make the grammar
850 : * LALR(1).
851 : */
852 : %token FORMAT_LA NOT_LA NULLS_LA WITH_LA WITHOUT_LA
853 :
854 : /*
855 : * The grammar likewise thinks these tokens are keywords, but they are never
856 : * generated by the scanner. Rather, they can be injected by parser.c as
857 : * the initial token of the string (using the lookahead-token mechanism
858 : * implemented there). This provides a way to tell the grammar to parse
859 : * something other than the usual list of SQL commands.
860 : */
861 : %token MODE_TYPE_NAME
862 : %token MODE_PLPGSQL_EXPR
863 : %token MODE_PLPGSQL_ASSIGN1
864 : %token MODE_PLPGSQL_ASSIGN2
865 : %token MODE_PLPGSQL_ASSIGN3
866 :
867 :
868 : /* Precedence: lowest to highest */
869 : %left UNION EXCEPT
870 : %left INTERSECT
871 : %left OR
872 : %left AND
873 : %right NOT
874 : %nonassoc IS ISNULL NOTNULL /* IS sets precedence for IS NULL, etc */
875 : %nonassoc '<' '>' '=' LESS_EQUALS GREATER_EQUALS NOT_EQUALS
876 : %nonassoc BETWEEN IN_P LIKE ILIKE SIMILAR NOT_LA
877 : %nonassoc ESCAPE /* ESCAPE must be just above LIKE/ILIKE/SIMILAR */
878 :
879 : /*
880 : * Sometimes it is necessary to assign precedence to keywords that are not
881 : * really part of the operator hierarchy, in order to resolve grammar
882 : * ambiguities. It's best to avoid doing so whenever possible, because such
883 : * assignments have global effect and may hide ambiguities besides the one
884 : * you intended to solve. (Attaching a precedence to a single rule with
885 : * %prec is far safer and should be preferred.) If you must give precedence
886 : * to a new keyword, try very hard to give it the same precedence as IDENT.
887 : * If the keyword has IDENT's precedence then it clearly acts the same as
888 : * non-keywords and other similar keywords, thus reducing the risk of
889 : * unexpected precedence effects.
890 : *
891 : * We used to need to assign IDENT an explicit precedence just less than Op,
892 : * to support target_el without AS. While that's not really necessary since
893 : * we removed postfix operators, we continue to do so because it provides a
894 : * reference point for a precedence level that we can assign to other
895 : * keywords that lack a natural precedence level.
896 : *
897 : * We need to do this for PARTITION, RANGE, ROWS, and GROUPS to support
898 : * opt_existing_window_name (see comment there).
899 : *
900 : * The frame_bound productions UNBOUNDED PRECEDING and UNBOUNDED FOLLOWING
901 : * are even messier: since UNBOUNDED is an unreserved keyword (per spec!),
902 : * there is no principled way to distinguish these from the productions
903 : * a_expr PRECEDING/FOLLOWING. We hack this up by giving UNBOUNDED slightly
904 : * lower precedence than PRECEDING and FOLLOWING. At present this doesn't
905 : * appear to cause UNBOUNDED to be treated differently from other unreserved
906 : * keywords anywhere else in the grammar, but it's definitely risky. We can
907 : * blame any funny behavior of UNBOUNDED on the SQL standard, though.
908 : *
909 : * To support CUBE and ROLLUP in GROUP BY without reserving them, we give them
910 : * an explicit priority lower than '(', so that a rule with CUBE '(' will shift
911 : * rather than reducing a conflicting rule that takes CUBE as a function name.
912 : * Using the same precedence as IDENT seems right for the reasons given above.
913 : *
914 : * SET is likewise assigned the same precedence as IDENT, to support the
915 : * relation_expr_opt_alias production (see comment there).
916 : *
917 : * KEYS, OBJECT_P, SCALAR, VALUE_P, WITH, and WITHOUT are similarly assigned
918 : * the same precedence as IDENT. This allows resolving conflicts in the
919 : * json_predicate_type_constraint and json_key_uniqueness_constraint_opt
920 : * productions (see comments there).
921 : *
922 : * Like the UNBOUNDED PRECEDING/FOLLOWING case, NESTED is assigned a lower
923 : * precedence than PATH to fix ambiguity in the json_table production.
924 : */
925 : %nonassoc UNBOUNDED NESTED /* ideally would have same precedence as IDENT */
926 : %nonassoc IDENT PARTITION RANGE ROWS GROUPS PRECEDING FOLLOWING CUBE ROLLUP
927 : SET KEYS OBJECT_P SCALAR VALUE_P WITH WITHOUT PATH
928 : %left Op OPERATOR RIGHT_ARROW '|' /* multi-character ops and user-defined operators */
929 : %left '+' '-'
930 : %left '*' '/' '%'
931 : %left '^'
932 : /* Unary Operators */
933 : %left AT /* sets precedence for AT TIME ZONE, AT LOCAL */
934 : %left COLLATE
935 : %right UMINUS
936 : %left '[' ']'
937 : %left '(' ')'
938 : %left TYPECAST
939 : %left '.'
940 : /*
941 : * These might seem to be low-precedence, but actually they are not part
942 : * of the arithmetic hierarchy at all in their use as JOIN operators.
943 : * We make them high-precedence to support their use as function names.
944 : * They wouldn't be given a precedence at all, were it not that we need
945 : * left-associativity among the JOIN rules themselves.
946 : */
947 : %left JOIN CROSS LEFT FULL RIGHT INNER_P NATURAL
948 :
949 : %%
950 :
951 : /*
952 : * The target production for the whole parse.
953 : *
954 : * Ordinarily we parse a list of statements, but if we see one of the
955 : * special MODE_XXX symbols as first token, we parse something else.
956 : * The options here correspond to enum RawParseMode, which see for details.
957 : */
958 : parse_toplevel:
959 : stmtmulti
960 : {
961 456893 : pg_yyget_extra(yyscanner)->parsetree = $1;
962 : (void) yynerrs; /* suppress compiler warning */
963 : }
964 : | MODE_TYPE_NAME Typename
965 : {
966 6378 : pg_yyget_extra(yyscanner)->parsetree = list_make1($2);
967 : }
968 : | MODE_PLPGSQL_EXPR PLpgSQL_Expr
969 : {
970 20493 : pg_yyget_extra(yyscanner)->parsetree =
971 20493 : list_make1(makeRawStmt($2, @2));
972 : }
973 : | MODE_PLPGSQL_ASSIGN1 PLAssignStmt
974 : {
975 3783 : PLAssignStmt *n = (PLAssignStmt *) $2;
976 :
977 3783 : n->nnames = 1;
978 3783 : pg_yyget_extra(yyscanner)->parsetree =
979 3783 : list_make1(makeRawStmt((Node *) n, @2));
980 : }
981 : | MODE_PLPGSQL_ASSIGN2 PLAssignStmt
982 : {
983 423 : PLAssignStmt *n = (PLAssignStmt *) $2;
984 :
985 423 : n->nnames = 2;
986 423 : pg_yyget_extra(yyscanner)->parsetree =
987 423 : list_make1(makeRawStmt((Node *) n, @2));
988 : }
989 : | MODE_PLPGSQL_ASSIGN3 PLAssignStmt
990 : {
991 14 : PLAssignStmt *n = (PLAssignStmt *) $2;
992 :
993 14 : n->nnames = 3;
994 14 : pg_yyget_extra(yyscanner)->parsetree =
995 14 : list_make1(makeRawStmt((Node *) n, @2));
996 : }
997 : ;
998 :
999 : /*
1000 : * At top level, we wrap each stmt with a RawStmt node carrying start location
1001 : * and length of the stmt's text.
1002 : * We also take care to discard empty statements entirely (which among other
1003 : * things dodges the problem of assigning them a location).
1004 : */
1005 : stmtmulti: stmtmulti ';' toplevel_stmt
1006 : {
1007 376035 : if ($1 != NIL)
1008 : {
1009 : /* update length of previous stmt */
1010 375474 : updateRawStmtEnd(llast_node(RawStmt, $1), @2);
1011 : }
1012 376035 : if ($3 != NULL)
1013 29597 : $$ = lappend($1, makeRawStmt($3, @3));
1014 : else
1015 346438 : $$ = $1;
1016 : }
1017 : | toplevel_stmt
1018 : {
1019 456898 : if ($1 != NULL)
1020 455908 : $$ = list_make1(makeRawStmt($1, @1));
1021 : else
1022 990 : $$ = NIL;
1023 : }
1024 : ;
1025 :
1026 : /*
1027 : * toplevel_stmt includes BEGIN and END. stmt does not include them, because
1028 : * those words have different meanings in function bodies.
1029 : */
1030 : toplevel_stmt:
1031 : stmt
1032 : | TransactionStmtLegacy
1033 : ;
1034 :
1035 : stmt:
1036 : AlterEventTrigStmt
1037 : | AlterCollationStmt
1038 : | AlterDatabaseStmt
1039 : | AlterDatabaseSetStmt
1040 : | AlterDefaultPrivilegesStmt
1041 : | AlterDomainStmt
1042 : | AlterEnumStmt
1043 : | AlterExtensionStmt
1044 : | AlterExtensionContentsStmt
1045 : | AlterFdwStmt
1046 : | AlterForeignServerStmt
1047 : | AlterFunctionStmt
1048 : | AlterGroupStmt
1049 : | AlterObjectDependsStmt
1050 : | AlterObjectSchemaStmt
1051 : | AlterOwnerStmt
1052 : | AlterOperatorStmt
1053 : | AlterTypeStmt
1054 : | AlterPolicyStmt
1055 : | AlterPropGraphStmt
1056 : | AlterSeqStmt
1057 : | AlterSystemStmt
1058 : | AlterTableStmt
1059 : | AlterTblSpcStmt
1060 : | AlterCompositeTypeStmt
1061 : | AlterPublicationStmt
1062 : | AlterRoleSetStmt
1063 : | AlterRoleStmt
1064 : | AlterSubscriptionStmt
1065 : | AlterStatsStmt
1066 : | AlterTSConfigurationStmt
1067 : | AlterTSDictionaryStmt
1068 : | AlterUserMappingStmt
1069 : | AnalyzeStmt
1070 : | CallStmt
1071 : | CheckPointStmt
1072 : | ClosePortalStmt
1073 : | CommentStmt
1074 : | ConstraintsSetStmt
1075 : | CopyStmt
1076 : | CreateAmStmt
1077 : | CreateAsStmt
1078 : | CreateAssertionStmt
1079 : | CreateCastStmt
1080 : | CreateConversionStmt
1081 : | CreateDomainStmt
1082 : | CreateExtensionStmt
1083 : | CreateFdwStmt
1084 : | CreateForeignServerStmt
1085 : | CreateForeignTableStmt
1086 : | CreateFunctionStmt
1087 : | CreateGroupStmt
1088 : | CreateMatViewStmt
1089 : | CreateOpClassStmt
1090 : | CreateOpFamilyStmt
1091 : | CreatePublicationStmt
1092 : | AlterOpFamilyStmt
1093 : | CreatePolicyStmt
1094 : | CreatePLangStmt
1095 : | CreatePropGraphStmt
1096 : | CreateSchemaStmt
1097 : | CreateSeqStmt
1098 : | CreateStmt
1099 : | CreateSubscriptionStmt
1100 : | CreateStatsStmt
1101 : | CreateTableSpaceStmt
1102 : | CreateTransformStmt
1103 : | CreateTrigStmt
1104 : | CreateEventTrigStmt
1105 : | CreateRoleStmt
1106 : | CreateUserStmt
1107 : | CreateUserMappingStmt
1108 : | CreatedbStmt
1109 : | DeallocateStmt
1110 : | DeclareCursorStmt
1111 : | DefineStmt
1112 : | DeleteStmt
1113 : | DiscardStmt
1114 : | DoStmt
1115 : | DropCastStmt
1116 : | DropOpClassStmt
1117 : | DropOpFamilyStmt
1118 : | DropOwnedStmt
1119 : | DropStmt
1120 : | DropSubscriptionStmt
1121 : | DropTableSpaceStmt
1122 : | DropTransformStmt
1123 : | DropRoleStmt
1124 : | DropUserMappingStmt
1125 : | DropdbStmt
1126 : | ExecuteStmt
1127 : | ExplainStmt
1128 : | FetchStmt
1129 : | GrantStmt
1130 : | GrantRoleStmt
1131 : | ImportForeignSchemaStmt
1132 : | IndexStmt
1133 : | InsertStmt
1134 : | ListenStmt
1135 : | RefreshMatViewStmt
1136 : | LoadStmt
1137 : | LockStmt
1138 : | MergeStmt
1139 : | NotifyStmt
1140 : | PrepareStmt
1141 : | ReassignOwnedStmt
1142 : | ReindexStmt
1143 : | RemoveAggrStmt
1144 : | RemoveFuncStmt
1145 : | RemoveOperStmt
1146 : | RenameStmt
1147 : | RepackStmt
1148 : | RevokeStmt
1149 : | RevokeRoleStmt
1150 : | RuleStmt
1151 : | SecLabelStmt
1152 : | SelectStmt
1153 : | TransactionStmt
1154 : | TruncateStmt
1155 : | UnlistenStmt
1156 : | UpdateStmt
1157 : | VacuumStmt
1158 : | VariableResetStmt
1159 : | VariableSetStmt
1160 : | VariableShowStmt
1161 : | ViewStmt
1162 : | WaitStmt
1163 : | /*EMPTY*/
1164 347440 : { $$ = NULL; }
1165 : ;
1166 :
1167 : /*
1168 : * Generic supporting productions for DDL
1169 : */
1170 : opt_single_name:
1171 3387 : ColId { $$ = $1; }
1172 1133 : | /* EMPTY */ { $$ = NULL; }
1173 : ;
1174 :
1175 : opt_qualified_name:
1176 1368 : any_name { $$ = $1; }
1177 10594 : | /*EMPTY*/ { $$ = NIL; }
1178 : ;
1179 :
1180 : opt_concurrently:
1181 648 : CONCURRENTLY { $$ = true; }
1182 4998 : | /*EMPTY*/ { $$ = false; }
1183 : ;
1184 :
1185 : opt_usingindex:
1186 4 : USING INDEX { $$ = true; }
1187 20 : | /* EMPTY */ { $$ = false; }
1188 : ;
1189 :
1190 : opt_drop_behavior:
1191 1353 : CASCADE { $$ = DROP_CASCADE; }
1192 109 : | RESTRICT { $$ = DROP_RESTRICT; }
1193 21004 : | /* EMPTY */ { $$ = DROP_RESTRICT; /* default */ }
1194 : ;
1195 :
1196 : opt_utility_option_list:
1197 232 : '(' utility_option_list ')' { $$ = $2; }
1198 3531 : | /* EMPTY */ { $$ = NULL; }
1199 : ;
1200 :
1201 : utility_option_list:
1202 : utility_option_elem
1203 : {
1204 15301 : $$ = list_make1($1);
1205 : }
1206 : | utility_option_list ',' utility_option_elem
1207 : {
1208 8649 : $$ = lappend($1, $3);
1209 : }
1210 : ;
1211 :
1212 : utility_option_elem:
1213 : utility_option_name utility_option_arg
1214 : {
1215 23950 : $$ = makeDefElem($1, $2, @1);
1216 : }
1217 : ;
1218 :
1219 : utility_option_name:
1220 21431 : NonReservedWord { $$ = $1; }
1221 2430 : | analyze_keyword { $$ = "analyze"; }
1222 93 : | FORMAT_LA { $$ = "format"; }
1223 : ;
1224 :
1225 : utility_option_arg:
1226 12437 : opt_boolean_or_string { $$ = (Node *) makeString($1); }
1227 220 : | NumericOnly { $$ = (Node *) $1; }
1228 11293 : | /* EMPTY */ { $$ = NULL; }
1229 : ;
1230 :
1231 : /*****************************************************************************
1232 : *
1233 : * CALL statement
1234 : *
1235 : *****************************************************************************/
1236 :
1237 : CallStmt: CALL func_application
1238 : {
1239 359 : CallStmt *n = makeNode(CallStmt);
1240 :
1241 359 : n->funccall = castNode(FuncCall, $2);
1242 359 : $$ = (Node *) n;
1243 : }
1244 : ;
1245 :
1246 : /*****************************************************************************
1247 : *
1248 : * Create a new Postgres DBMS role
1249 : *
1250 : *****************************************************************************/
1251 :
1252 : CreateRoleStmt:
1253 : CREATE ROLE RoleId opt_with OptRoleList
1254 : {
1255 937 : CreateRoleStmt *n = makeNode(CreateRoleStmt);
1256 :
1257 937 : n->stmt_type = ROLESTMT_ROLE;
1258 937 : n->role = $3;
1259 937 : n->options = $5;
1260 937 : $$ = (Node *) n;
1261 : }
1262 : ;
1263 :
1264 :
1265 : opt_with: WITH
1266 : | WITH_LA
1267 : | /*EMPTY*/
1268 : ;
1269 :
1270 : /*
1271 : * Options for CREATE ROLE and ALTER ROLE (also used by CREATE/ALTER USER
1272 : * for backwards compatibility). Note: the only option required by SQL99
1273 : * is "WITH ADMIN name".
1274 : */
1275 : OptRoleList:
1276 757 : OptRoleList CreateOptRoleElem { $$ = lappend($1, $2); }
1277 1268 : | /* EMPTY */ { $$ = NIL; }
1278 : ;
1279 :
1280 : AlterOptRoleList:
1281 446 : AlterOptRoleList AlterOptRoleElem { $$ = lappend($1, $2); }
1282 262 : | /* EMPTY */ { $$ = NIL; }
1283 : ;
1284 :
1285 : AlterOptRoleElem:
1286 : PASSWORD Sconst
1287 : {
1288 118 : $$ = makeDefElem("password",
1289 118 : (Node *) makeString($2), @1);
1290 : }
1291 : | PASSWORD NULL_P
1292 : {
1293 8 : $$ = makeDefElem("password", NULL, @1);
1294 : }
1295 : | ENCRYPTED PASSWORD Sconst
1296 : {
1297 : /*
1298 : * These days, passwords are always stored in encrypted
1299 : * form, so there is no difference between PASSWORD and
1300 : * ENCRYPTED PASSWORD.
1301 : */
1302 10 : $$ = makeDefElem("password",
1303 10 : (Node *) makeString($3), @1);
1304 : }
1305 : | UNENCRYPTED PASSWORD Sconst
1306 : {
1307 0 : ereport(ERROR,
1308 : (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
1309 : errmsg("UNENCRYPTED PASSWORD is no longer supported"),
1310 : errhint("Remove UNENCRYPTED to store the password in encrypted form instead."),
1311 : parser_errposition(@1)));
1312 : }
1313 : | INHERIT
1314 : {
1315 61 : $$ = makeDefElem("inherit", (Node *) makeBoolean(true), @1);
1316 : }
1317 : | CONNECTION LIMIT SignedIconst
1318 : {
1319 17 : $$ = makeDefElem("connectionlimit", (Node *) makeInteger($3), @1);
1320 : }
1321 : | VALID UNTIL Sconst
1322 : {
1323 4 : $$ = makeDefElem("validUntil", (Node *) makeString($3), @1);
1324 : }
1325 : /* Supported but not documented for roles, for use by ALTER GROUP. */
1326 : | USER role_list
1327 : {
1328 4 : $$ = makeDefElem("rolemembers", (Node *) $2, @1);
1329 : }
1330 : | IDENT
1331 : {
1332 : /*
1333 : * We handle identifiers that aren't parser keywords with
1334 : * the following special-case codes, to avoid bloating the
1335 : * size of the main parser.
1336 : */
1337 872 : if (strcmp($1, "superuser") == 0)
1338 114 : $$ = makeDefElem("superuser", (Node *) makeBoolean(true), @1);
1339 758 : else if (strcmp($1, "nosuperuser") == 0)
1340 65 : $$ = makeDefElem("superuser", (Node *) makeBoolean(false), @1);
1341 693 : else if (strcmp($1, "createrole") == 0)
1342 61 : $$ = makeDefElem("createrole", (Node *) makeBoolean(true), @1);
1343 632 : else if (strcmp($1, "nocreaterole") == 0)
1344 29 : $$ = makeDefElem("createrole", (Node *) makeBoolean(false), @1);
1345 603 : else if (strcmp($1, "replication") == 0)
1346 77 : $$ = makeDefElem("isreplication", (Node *) makeBoolean(true), @1);
1347 526 : else if (strcmp($1, "noreplication") == 0)
1348 58 : $$ = makeDefElem("isreplication", (Node *) makeBoolean(false), @1);
1349 468 : else if (strcmp($1, "createdb") == 0)
1350 55 : $$ = makeDefElem("createdb", (Node *) makeBoolean(true), @1);
1351 413 : else if (strcmp($1, "nocreatedb") == 0)
1352 34 : $$ = makeDefElem("createdb", (Node *) makeBoolean(false), @1);
1353 379 : else if (strcmp($1, "login") == 0)
1354 162 : $$ = makeDefElem("canlogin", (Node *) makeBoolean(true), @1);
1355 217 : else if (strcmp($1, "nologin") == 0)
1356 92 : $$ = makeDefElem("canlogin", (Node *) makeBoolean(false), @1);
1357 125 : else if (strcmp($1, "bypassrls") == 0)
1358 57 : $$ = makeDefElem("bypassrls", (Node *) makeBoolean(true), @1);
1359 68 : else if (strcmp($1, "nobypassrls") == 0)
1360 44 : $$ = makeDefElem("bypassrls", (Node *) makeBoolean(false), @1);
1361 24 : else if (strcmp($1, "noinherit") == 0)
1362 : {
1363 : /*
1364 : * Note that INHERIT is a keyword, so it's handled by main parser, but
1365 : * NOINHERIT is handled here.
1366 : */
1367 24 : $$ = makeDefElem("inherit", (Node *) makeBoolean(false), @1);
1368 : }
1369 : else
1370 0 : ereport(ERROR,
1371 : (errcode(ERRCODE_SYNTAX_ERROR),
1372 : errmsg("unrecognized role option \"%s\"", $1),
1373 : parser_errposition(@1)));
1374 : }
1375 : ;
1376 :
1377 : CreateOptRoleElem:
1378 648 : AlterOptRoleElem { $$ = $1; }
1379 : /* The following are not supported by ALTER ROLE/USER/GROUP */
1380 : | SYSID Iconst
1381 : {
1382 4 : $$ = makeDefElem("sysid", (Node *) makeInteger($2), @1);
1383 : }
1384 : | ADMIN role_list
1385 : {
1386 14 : $$ = makeDefElem("adminmembers", (Node *) $2, @1);
1387 : }
1388 : | ROLE role_list
1389 : {
1390 26 : $$ = makeDefElem("rolemembers", (Node *) $2, @1);
1391 : }
1392 : | IN_P ROLE role_list
1393 : {
1394 65 : $$ = makeDefElem("addroleto", (Node *) $3, @1);
1395 : }
1396 : | IN_P GROUP_P role_list
1397 : {
1398 0 : $$ = makeDefElem("addroleto", (Node *) $3, @1);
1399 : }
1400 : ;
1401 :
1402 :
1403 : /*****************************************************************************
1404 : *
1405 : * Create a new Postgres DBMS user (role with implied login ability)
1406 : *
1407 : *****************************************************************************/
1408 :
1409 : CreateUserStmt:
1410 : CREATE USER RoleId opt_with OptRoleList
1411 : {
1412 315 : CreateRoleStmt *n = makeNode(CreateRoleStmt);
1413 :
1414 315 : n->stmt_type = ROLESTMT_USER;
1415 315 : n->role = $3;
1416 315 : n->options = $5;
1417 315 : $$ = (Node *) n;
1418 : }
1419 : ;
1420 :
1421 :
1422 : /*****************************************************************************
1423 : *
1424 : * Alter a postgresql DBMS role
1425 : *
1426 : *****************************************************************************/
1427 :
1428 : AlterRoleStmt:
1429 : ALTER ROLE RoleSpec opt_with AlterOptRoleList
1430 : {
1431 213 : AlterRoleStmt *n = makeNode(AlterRoleStmt);
1432 :
1433 213 : n->role = $3;
1434 213 : n->action = +1; /* add, if there are members */
1435 213 : n->options = $5;
1436 213 : $$ = (Node *) n;
1437 : }
1438 : | ALTER USER RoleSpec opt_with AlterOptRoleList
1439 : {
1440 49 : AlterRoleStmt *n = makeNode(AlterRoleStmt);
1441 :
1442 49 : n->role = $3;
1443 49 : n->action = +1; /* add, if there are members */
1444 49 : n->options = $5;
1445 49 : $$ = (Node *) n;
1446 : }
1447 : ;
1448 :
1449 : opt_in_database:
1450 47 : /* EMPTY */ { $$ = NULL; }
1451 2 : | IN_P DATABASE name { $$ = $3; }
1452 : ;
1453 :
1454 : AlterRoleSetStmt:
1455 : ALTER ROLE RoleSpec opt_in_database SetResetClause
1456 : {
1457 29 : AlterRoleSetStmt *n = makeNode(AlterRoleSetStmt);
1458 :
1459 29 : n->role = $3;
1460 29 : n->database = $4;
1461 29 : n->setstmt = $5;
1462 29 : $$ = (Node *) n;
1463 : }
1464 : | ALTER ROLE ALL opt_in_database SetResetClause
1465 : {
1466 2 : AlterRoleSetStmt *n = makeNode(AlterRoleSetStmt);
1467 :
1468 2 : n->role = NULL;
1469 2 : n->database = $4;
1470 2 : n->setstmt = $5;
1471 2 : $$ = (Node *) n;
1472 : }
1473 : | ALTER USER RoleSpec opt_in_database SetResetClause
1474 : {
1475 14 : AlterRoleSetStmt *n = makeNode(AlterRoleSetStmt);
1476 :
1477 14 : n->role = $3;
1478 14 : n->database = $4;
1479 14 : n->setstmt = $5;
1480 14 : $$ = (Node *) n;
1481 : }
1482 : | ALTER USER ALL opt_in_database SetResetClause
1483 : {
1484 2 : AlterRoleSetStmt *n = makeNode(AlterRoleSetStmt);
1485 :
1486 2 : n->role = NULL;
1487 2 : n->database = $4;
1488 2 : n->setstmt = $5;
1489 2 : $$ = (Node *) n;
1490 : }
1491 : ;
1492 :
1493 :
1494 : /*****************************************************************************
1495 : *
1496 : * Drop a postgresql DBMS role
1497 : *
1498 : * XXX Ideally this would have CASCADE/RESTRICT options, but a role
1499 : * might own objects in multiple databases, and there is presently no way to
1500 : * implement cascading to other databases. So we always behave as RESTRICT.
1501 : *****************************************************************************/
1502 :
1503 : DropRoleStmt:
1504 : DROP ROLE role_list
1505 : {
1506 753 : DropRoleStmt *n = makeNode(DropRoleStmt);
1507 :
1508 753 : n->missing_ok = false;
1509 753 : n->roles = $3;
1510 753 : $$ = (Node *) n;
1511 : }
1512 : | DROP ROLE IF_P EXISTS role_list
1513 : {
1514 96 : DropRoleStmt *n = makeNode(DropRoleStmt);
1515 :
1516 96 : n->missing_ok = true;
1517 96 : n->roles = $5;
1518 96 : $$ = (Node *) n;
1519 : }
1520 : | DROP USER role_list
1521 : {
1522 288 : DropRoleStmt *n = makeNode(DropRoleStmt);
1523 :
1524 288 : n->missing_ok = false;
1525 288 : n->roles = $3;
1526 288 : $$ = (Node *) n;
1527 : }
1528 : | DROP USER IF_P EXISTS role_list
1529 : {
1530 44 : DropRoleStmt *n = makeNode(DropRoleStmt);
1531 :
1532 44 : n->roles = $5;
1533 44 : n->missing_ok = true;
1534 44 : $$ = (Node *) n;
1535 : }
1536 : | DROP GROUP_P role_list
1537 : {
1538 24 : DropRoleStmt *n = makeNode(DropRoleStmt);
1539 :
1540 24 : n->missing_ok = false;
1541 24 : n->roles = $3;
1542 24 : $$ = (Node *) n;
1543 : }
1544 : | DROP GROUP_P IF_P EXISTS role_list
1545 : {
1546 4 : DropRoleStmt *n = makeNode(DropRoleStmt);
1547 :
1548 4 : n->missing_ok = true;
1549 4 : n->roles = $5;
1550 4 : $$ = (Node *) n;
1551 : }
1552 : ;
1553 :
1554 :
1555 : /*****************************************************************************
1556 : *
1557 : * Create a postgresql group (role without login ability)
1558 : *
1559 : *****************************************************************************/
1560 :
1561 : CreateGroupStmt:
1562 : CREATE GROUP_P RoleId opt_with OptRoleList
1563 : {
1564 16 : CreateRoleStmt *n = makeNode(CreateRoleStmt);
1565 :
1566 16 : n->stmt_type = ROLESTMT_GROUP;
1567 16 : n->role = $3;
1568 16 : n->options = $5;
1569 16 : $$ = (Node *) n;
1570 : }
1571 : ;
1572 :
1573 :
1574 : /*****************************************************************************
1575 : *
1576 : * Alter a postgresql group
1577 : *
1578 : *****************************************************************************/
1579 :
1580 : AlterGroupStmt:
1581 : ALTER GROUP_P RoleSpec add_drop USER role_list
1582 : {
1583 28 : AlterRoleStmt *n = makeNode(AlterRoleStmt);
1584 :
1585 28 : n->role = $3;
1586 28 : n->action = $4;
1587 28 : n->options = list_make1(makeDefElem("rolemembers",
1588 : (Node *) $6, @6));
1589 28 : $$ = (Node *) n;
1590 : }
1591 : ;
1592 :
1593 52 : add_drop: ADD_P { $$ = +1; }
1594 105 : | DROP { $$ = -1; }
1595 : ;
1596 :
1597 :
1598 : /*****************************************************************************
1599 : *
1600 : * Manipulate a schema
1601 : *
1602 : *****************************************************************************/
1603 :
1604 : CreateSchemaStmt:
1605 : CREATE SCHEMA opt_single_name AUTHORIZATION RoleSpec OptSchemaEltList
1606 : {
1607 102 : CreateSchemaStmt *n = makeNode(CreateSchemaStmt);
1608 :
1609 : /* One can omit the schema name or the authorization id. */
1610 102 : n->schemaname = $3;
1611 102 : n->authrole = $5;
1612 102 : n->schemaElts = $6;
1613 102 : n->if_not_exists = false;
1614 102 : $$ = (Node *) n;
1615 : }
1616 : | CREATE SCHEMA ColId OptSchemaEltList
1617 : {
1618 586 : CreateSchemaStmt *n = makeNode(CreateSchemaStmt);
1619 :
1620 : /* ...but not both */
1621 586 : n->schemaname = $3;
1622 586 : n->authrole = NULL;
1623 586 : n->schemaElts = $4;
1624 586 : n->if_not_exists = false;
1625 586 : $$ = (Node *) n;
1626 : }
1627 : | CREATE SCHEMA IF_P NOT EXISTS opt_single_name AUTHORIZATION RoleSpec OptSchemaEltList
1628 : {
1629 9 : CreateSchemaStmt *n = makeNode(CreateSchemaStmt);
1630 :
1631 : /* schema name can be omitted here, too */
1632 9 : n->schemaname = $6;
1633 9 : n->authrole = $8;
1634 9 : if ($9 != NIL)
1635 0 : ereport(ERROR,
1636 : (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
1637 : errmsg("CREATE SCHEMA IF NOT EXISTS cannot include schema elements"),
1638 : parser_errposition(@9)));
1639 9 : n->schemaElts = $9;
1640 9 : n->if_not_exists = true;
1641 9 : $$ = (Node *) n;
1642 : }
1643 : | CREATE SCHEMA IF_P NOT EXISTS ColId OptSchemaEltList
1644 : {
1645 19 : CreateSchemaStmt *n = makeNode(CreateSchemaStmt);
1646 :
1647 : /* ...but not here */
1648 19 : n->schemaname = $6;
1649 19 : n->authrole = NULL;
1650 19 : if ($7 != NIL)
1651 4 : ereport(ERROR,
1652 : (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
1653 : errmsg("CREATE SCHEMA IF NOT EXISTS cannot include schema elements"),
1654 : parser_errposition(@7)));
1655 15 : n->schemaElts = $7;
1656 15 : n->if_not_exists = true;
1657 15 : $$ = (Node *) n;
1658 : }
1659 : ;
1660 :
1661 : OptSchemaEltList:
1662 : OptSchemaEltList schema_stmt
1663 : {
1664 392 : $$ = lappend($1, $2);
1665 : }
1666 : | /* EMPTY */
1667 716 : { $$ = NIL; }
1668 : ;
1669 :
1670 : /*
1671 : * schema_stmt are the ones that can show up inside a CREATE SCHEMA
1672 : * statement (in addition to by themselves).
1673 : */
1674 : schema_stmt:
1675 : CreateStmt
1676 : | IndexStmt
1677 : | CreateSeqStmt
1678 : | CreateTrigStmt
1679 : | GrantStmt
1680 : | ViewStmt
1681 : ;
1682 :
1683 :
1684 : /*****************************************************************************
1685 : *
1686 : * Set PG internal variable
1687 : * SET name TO 'var_value'
1688 : * Include SQL syntax (thomas 1997-10-22):
1689 : * SET TIME ZONE 'var_value'
1690 : *
1691 : *****************************************************************************/
1692 :
1693 : VariableSetStmt:
1694 : SET set_rest
1695 : {
1696 14392 : VariableSetStmt *n = $2;
1697 :
1698 14392 : n->is_local = false;
1699 14392 : $$ = (Node *) n;
1700 : }
1701 : | SET LOCAL set_rest
1702 : {
1703 936 : VariableSetStmt *n = $3;
1704 :
1705 936 : n->is_local = true;
1706 936 : $$ = (Node *) n;
1707 : }
1708 : | SET SESSION set_rest
1709 : {
1710 89 : VariableSetStmt *n = $3;
1711 :
1712 89 : n->is_local = false;
1713 89 : $$ = (Node *) n;
1714 : }
1715 : ;
1716 :
1717 : set_rest:
1718 : TRANSACTION transaction_mode_list
1719 : {
1720 387 : VariableSetStmt *n = makeNode(VariableSetStmt);
1721 :
1722 387 : n->kind = VAR_SET_MULTI;
1723 387 : n->name = "TRANSACTION";
1724 387 : n->args = $2;
1725 387 : n->jumble_args = true;
1726 387 : n->location = -1;
1727 387 : $$ = n;
1728 : }
1729 : | SESSION CHARACTERISTICS AS TRANSACTION transaction_mode_list
1730 : {
1731 11 : VariableSetStmt *n = makeNode(VariableSetStmt);
1732 :
1733 11 : n->kind = VAR_SET_MULTI;
1734 11 : n->name = "SESSION CHARACTERISTICS";
1735 11 : n->args = $5;
1736 11 : n->jumble_args = true;
1737 11 : n->location = -1;
1738 11 : $$ = n;
1739 : }
1740 : | set_rest_more
1741 : ;
1742 :
1743 : generic_set:
1744 : var_name TO var_list
1745 : {
1746 3315 : VariableSetStmt *n = makeNode(VariableSetStmt);
1747 :
1748 3315 : n->kind = VAR_SET_VALUE;
1749 3315 : n->name = $1;
1750 3315 : n->args = $3;
1751 3315 : n->location = @3;
1752 3315 : $$ = n;
1753 : }
1754 : | var_name '=' var_list
1755 : {
1756 9689 : VariableSetStmt *n = makeNode(VariableSetStmt);
1757 :
1758 9689 : n->kind = VAR_SET_VALUE;
1759 9689 : n->name = $1;
1760 9689 : n->args = $3;
1761 9689 : n->location = @3;
1762 9689 : $$ = n;
1763 : }
1764 : | var_name TO NULL_P
1765 : {
1766 5 : VariableSetStmt *n = makeNode(VariableSetStmt);
1767 :
1768 5 : n->kind = VAR_SET_VALUE;
1769 5 : n->name = $1;
1770 5 : n->args = list_make1(makeNullAConst(@3));
1771 5 : n->location = @3;
1772 5 : $$ = n;
1773 : }
1774 : | var_name '=' NULL_P
1775 : {
1776 12 : VariableSetStmt *n = makeNode(VariableSetStmt);
1777 :
1778 12 : n->kind = VAR_SET_VALUE;
1779 12 : n->name = $1;
1780 12 : n->args = list_make1(makeNullAConst(@3));
1781 12 : n->location = @3;
1782 12 : $$ = n;
1783 : }
1784 : | var_name TO DEFAULT
1785 : {
1786 90 : VariableSetStmt *n = makeNode(VariableSetStmt);
1787 :
1788 90 : n->kind = VAR_SET_DEFAULT;
1789 90 : n->name = $1;
1790 90 : n->location = -1;
1791 90 : $$ = n;
1792 : }
1793 : | var_name '=' DEFAULT
1794 : {
1795 6 : VariableSetStmt *n = makeNode(VariableSetStmt);
1796 :
1797 6 : n->kind = VAR_SET_DEFAULT;
1798 6 : n->name = $1;
1799 6 : n->location = -1;
1800 6 : $$ = n;
1801 : }
1802 : ;
1803 :
1804 : set_rest_more: /* Generic SET syntaxes: */
1805 13036 : generic_set {$$ = $1;}
1806 : | var_name FROM CURRENT_P
1807 : {
1808 2 : VariableSetStmt *n = makeNode(VariableSetStmt);
1809 :
1810 2 : n->kind = VAR_SET_CURRENT;
1811 2 : n->name = $1;
1812 2 : n->location = -1;
1813 2 : $$ = n;
1814 : }
1815 : /* Special syntaxes mandated by SQL standard: */
1816 : | TIME ZONE zone_value
1817 : {
1818 67 : VariableSetStmt *n = makeNode(VariableSetStmt);
1819 :
1820 67 : n->kind = VAR_SET_VALUE;
1821 67 : n->name = "timezone";
1822 67 : n->location = -1;
1823 67 : n->jumble_args = true;
1824 67 : if ($3 != NULL)
1825 57 : n->args = list_make1($3);
1826 : else
1827 10 : n->kind = VAR_SET_DEFAULT;
1828 67 : $$ = n;
1829 : }
1830 : | CATALOG_P Sconst
1831 : {
1832 0 : ereport(ERROR,
1833 : (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
1834 : errmsg("current database cannot be changed"),
1835 : parser_errposition(@2)));
1836 : $$ = NULL; /*not reached*/
1837 : }
1838 : | SCHEMA Sconst
1839 : {
1840 2 : VariableSetStmt *n = makeNode(VariableSetStmt);
1841 :
1842 2 : n->kind = VAR_SET_VALUE;
1843 2 : n->name = "search_path";
1844 2 : n->args = list_make1(makeStringConst($2, @2));
1845 2 : n->location = @2;
1846 2 : $$ = n;
1847 : }
1848 : | NAMES opt_encoding
1849 : {
1850 0 : VariableSetStmt *n = makeNode(VariableSetStmt);
1851 :
1852 0 : n->kind = VAR_SET_VALUE;
1853 0 : n->name = "client_encoding";
1854 0 : n->location = @2;
1855 0 : if ($2 != NULL)
1856 0 : n->args = list_make1(makeStringConst($2, @2));
1857 : else
1858 0 : n->kind = VAR_SET_DEFAULT;
1859 0 : $$ = n;
1860 : }
1861 : | ROLE NonReservedWord_or_Sconst
1862 : {
1863 682 : VariableSetStmt *n = makeNode(VariableSetStmt);
1864 :
1865 682 : n->kind = VAR_SET_VALUE;
1866 682 : n->name = "role";
1867 682 : n->args = list_make1(makeStringConst($2, @2));
1868 682 : n->location = @2;
1869 682 : $$ = n;
1870 : }
1871 : | SESSION AUTHORIZATION NonReservedWord_or_Sconst
1872 : {
1873 1965 : VariableSetStmt *n = makeNode(VariableSetStmt);
1874 :
1875 1965 : n->kind = VAR_SET_VALUE;
1876 1965 : n->name = "session_authorization";
1877 1965 : n->args = list_make1(makeStringConst($3, @3));
1878 1965 : n->location = @3;
1879 1965 : $$ = n;
1880 : }
1881 : | SESSION AUTHORIZATION DEFAULT
1882 : {
1883 2 : VariableSetStmt *n = makeNode(VariableSetStmt);
1884 :
1885 2 : n->kind = VAR_SET_DEFAULT;
1886 2 : n->name = "session_authorization";
1887 2 : n->location = -1;
1888 2 : $$ = n;
1889 : }
1890 : | XML_P OPTION document_or_content
1891 : {
1892 10 : VariableSetStmt *n = makeNode(VariableSetStmt);
1893 :
1894 10 : n->kind = VAR_SET_VALUE;
1895 10 : n->name = "xmloption";
1896 10 : n->args = list_make1(makeStringConst($3 == XMLOPTION_DOCUMENT ? "DOCUMENT" : "CONTENT", @3));
1897 10 : n->jumble_args = true;
1898 10 : n->location = -1;
1899 10 : $$ = n;
1900 : }
1901 : /* Special syntaxes invented by PostgreSQL: */
1902 : | TRANSACTION SNAPSHOT Sconst
1903 : {
1904 24 : VariableSetStmt *n = makeNode(VariableSetStmt);
1905 :
1906 24 : n->kind = VAR_SET_MULTI;
1907 24 : n->name = "TRANSACTION SNAPSHOT";
1908 24 : n->args = list_make1(makeStringConst($3, @3));
1909 24 : n->location = @3;
1910 24 : $$ = n;
1911 : }
1912 : ;
1913 :
1914 16334 : var_name: ColId { $$ = $1; }
1915 : | var_name '.' ColId
1916 433 : { $$ = psprintf("%s.%s", $1, $3); }
1917 : ;
1918 :
1919 13004 : var_list: var_value { $$ = list_make1($1); }
1920 198 : | var_list ',' var_value { $$ = lappend($1, $3); }
1921 : ;
1922 :
1923 : var_value: opt_boolean_or_string
1924 9770 : { $$ = makeStringConst($1, @1); }
1925 : | NumericOnly
1926 3432 : { $$ = makeAConst($1, @1); }
1927 : ;
1928 :
1929 0 : iso_level: READ UNCOMMITTED { $$ = "read uncommitted"; }
1930 548 : | READ COMMITTED { $$ = "read committed"; }
1931 1452 : | REPEATABLE READ { $$ = "repeatable read"; }
1932 1635 : | SERIALIZABLE { $$ = "serializable"; }
1933 : ;
1934 :
1935 : opt_boolean_or_string:
1936 429 : TRUE_P { $$ = "true"; }
1937 867 : | FALSE_P { $$ = "false"; }
1938 1669 : | ON { $$ = "on"; }
1939 : /*
1940 : * OFF is also accepted as a boolean value, but is handled by
1941 : * the NonReservedWord rule. The action for booleans and strings
1942 : * is the same, so we don't need to distinguish them here.
1943 : */
1944 20940 : | NonReservedWord_or_Sconst { $$ = $1; }
1945 : ;
1946 :
1947 : /* Timezone values can be:
1948 : * - a string such as 'pst8pdt'
1949 : * - an identifier such as "pst8pdt"
1950 : * - an integer or floating point number
1951 : * - a time interval per SQL99
1952 : * ColId gives reduce/reduce errors against ConstInterval and LOCAL,
1953 : * so use IDENT (meaning we reject anything that is a key word).
1954 : */
1955 : zone_value:
1956 : Sconst
1957 : {
1958 39 : $$ = makeStringConst($1, @1);
1959 : }
1960 : | IDENT
1961 : {
1962 2 : $$ = makeStringConst($1, @1);
1963 : }
1964 : | ConstInterval Sconst opt_interval
1965 : {
1966 0 : TypeName *t = $1;
1967 :
1968 0 : if ($3 != NIL)
1969 : {
1970 0 : A_Const *n = (A_Const *) linitial($3);
1971 :
1972 0 : if ((n->val.ival.ival & ~(INTERVAL_MASK(HOUR) | INTERVAL_MASK(MINUTE))) != 0)
1973 0 : ereport(ERROR,
1974 : (errcode(ERRCODE_SYNTAX_ERROR),
1975 : errmsg("time zone interval must be HOUR or HOUR TO MINUTE"),
1976 : parser_errposition(@3)));
1977 : }
1978 0 : t->typmods = $3;
1979 0 : $$ = makeStringConstCast($2, @2, t);
1980 : }
1981 : | ConstInterval '(' Iconst ')' Sconst
1982 : {
1983 0 : TypeName *t = $1;
1984 :
1985 0 : t->typmods = list_make2(makeIntConst(INTERVAL_FULL_RANGE, -1),
1986 : makeIntConst($3, @3));
1987 0 : $$ = makeStringConstCast($5, @5, t);
1988 : }
1989 16 : | NumericOnly { $$ = makeAConst($1, @1); }
1990 9 : | DEFAULT { $$ = NULL; }
1991 1 : | LOCAL { $$ = NULL; }
1992 : ;
1993 :
1994 : opt_encoding:
1995 0 : Sconst { $$ = $1; }
1996 0 : | DEFAULT { $$ = NULL; }
1997 0 : | /*EMPTY*/ { $$ = NULL; }
1998 : ;
1999 :
2000 : NonReservedWord_or_Sconst:
2001 32328 : NonReservedWord { $$ = $1; }
2002 3633 : | Sconst { $$ = $1; }
2003 : ;
2004 :
2005 : VariableResetStmt:
2006 3269 : RESET reset_rest { $$ = (Node *) $2; }
2007 : ;
2008 :
2009 : reset_rest:
2010 2635 : generic_reset { $$ = $1; }
2011 : | TIME ZONE
2012 : {
2013 9 : VariableSetStmt *n = makeNode(VariableSetStmt);
2014 :
2015 9 : n->kind = VAR_RESET;
2016 9 : n->name = "timezone";
2017 9 : n->location = -1;
2018 9 : $$ = n;
2019 : }
2020 : | TRANSACTION ISOLATION LEVEL
2021 : {
2022 0 : VariableSetStmt *n = makeNode(VariableSetStmt);
2023 :
2024 0 : n->kind = VAR_RESET;
2025 0 : n->name = "transaction_isolation";
2026 0 : n->location = -1;
2027 0 : $$ = n;
2028 : }
2029 : | SESSION AUTHORIZATION
2030 : {
2031 625 : VariableSetStmt *n = makeNode(VariableSetStmt);
2032 :
2033 625 : n->kind = VAR_RESET;
2034 625 : n->name = "session_authorization";
2035 625 : n->location = -1;
2036 625 : $$ = n;
2037 : }
2038 : ;
2039 :
2040 : generic_reset:
2041 : var_name
2042 : {
2043 2647 : VariableSetStmt *n = makeNode(VariableSetStmt);
2044 :
2045 2647 : n->kind = VAR_RESET;
2046 2647 : n->name = $1;
2047 2647 : n->location = -1;
2048 2647 : $$ = n;
2049 : }
2050 : | ALL
2051 : {
2052 17 : VariableSetStmt *n = makeNode(VariableSetStmt);
2053 :
2054 17 : n->kind = VAR_RESET_ALL;
2055 17 : n->location = -1;
2056 17 : $$ = n;
2057 : }
2058 : ;
2059 :
2060 : /* SetResetClause allows SET or RESET without LOCAL */
2061 : SetResetClause:
2062 683 : SET set_rest { $$ = $2; }
2063 21 : | VariableResetStmt { $$ = (VariableSetStmt *) $1; }
2064 : ;
2065 :
2066 : /* SetResetClause allows SET or RESET without LOCAL */
2067 : FunctionSetResetClause:
2068 88 : SET set_rest_more { $$ = $2; }
2069 8 : | VariableResetStmt { $$ = (VariableSetStmt *) $1; }
2070 : ;
2071 :
2072 :
2073 : VariableShowStmt:
2074 : SHOW var_name
2075 : {
2076 568 : VariableShowStmt *n = makeNode(VariableShowStmt);
2077 :
2078 568 : n->name = $2;
2079 568 : $$ = (Node *) n;
2080 : }
2081 : | SHOW TIME ZONE
2082 : {
2083 6 : VariableShowStmt *n = makeNode(VariableShowStmt);
2084 :
2085 6 : n->name = "timezone";
2086 6 : $$ = (Node *) n;
2087 : }
2088 : | SHOW TRANSACTION ISOLATION LEVEL
2089 : {
2090 2 : VariableShowStmt *n = makeNode(VariableShowStmt);
2091 :
2092 2 : n->name = "transaction_isolation";
2093 2 : $$ = (Node *) n;
2094 : }
2095 : | SHOW SESSION AUTHORIZATION
2096 : {
2097 0 : VariableShowStmt *n = makeNode(VariableShowStmt);
2098 :
2099 0 : n->name = "session_authorization";
2100 0 : $$ = (Node *) n;
2101 : }
2102 : | SHOW ALL
2103 : {
2104 0 : VariableShowStmt *n = makeNode(VariableShowStmt);
2105 :
2106 0 : n->name = "all";
2107 0 : $$ = (Node *) n;
2108 : }
2109 : ;
2110 :
2111 :
2112 : ConstraintsSetStmt:
2113 : SET CONSTRAINTS constraints_set_list constraints_set_mode
2114 : {
2115 68 : ConstraintsSetStmt *n = makeNode(ConstraintsSetStmt);
2116 :
2117 68 : n->constraints = $3;
2118 68 : n->deferred = $4;
2119 68 : $$ = (Node *) n;
2120 : }
2121 : ;
2122 :
2123 : constraints_set_list:
2124 36 : ALL { $$ = NIL; }
2125 32 : | qualified_name_list { $$ = $1; }
2126 : ;
2127 :
2128 : constraints_set_mode:
2129 45 : DEFERRED { $$ = true; }
2130 23 : | IMMEDIATE { $$ = false; }
2131 : ;
2132 :
2133 :
2134 : /*
2135 : * Checkpoint statement
2136 : */
2137 : CheckPointStmt:
2138 : CHECKPOINT opt_utility_option_list
2139 : {
2140 143 : CheckPointStmt *n = makeNode(CheckPointStmt);
2141 :
2142 143 : $$ = (Node *) n;
2143 143 : n->options = $2;
2144 : }
2145 : ;
2146 :
2147 :
2148 : /*****************************************************************************
2149 : *
2150 : * DISCARD { ALL | TEMP | PLANS | SEQUENCES }
2151 : *
2152 : *****************************************************************************/
2153 :
2154 : DiscardStmt:
2155 : DISCARD ALL
2156 : {
2157 4 : DiscardStmt *n = makeNode(DiscardStmt);
2158 :
2159 4 : n->target = DISCARD_ALL;
2160 4 : $$ = (Node *) n;
2161 : }
2162 : | DISCARD TEMP
2163 : {
2164 9 : DiscardStmt *n = makeNode(DiscardStmt);
2165 :
2166 9 : n->target = DISCARD_TEMP;
2167 9 : $$ = (Node *) n;
2168 : }
2169 : | DISCARD TEMPORARY
2170 : {
2171 0 : DiscardStmt *n = makeNode(DiscardStmt);
2172 :
2173 0 : n->target = DISCARD_TEMP;
2174 0 : $$ = (Node *) n;
2175 : }
2176 : | DISCARD PLANS
2177 : {
2178 3 : DiscardStmt *n = makeNode(DiscardStmt);
2179 :
2180 3 : n->target = DISCARD_PLANS;
2181 3 : $$ = (Node *) n;
2182 : }
2183 : | DISCARD SEQUENCES
2184 : {
2185 8 : DiscardStmt *n = makeNode(DiscardStmt);
2186 :
2187 8 : n->target = DISCARD_SEQUENCES;
2188 8 : $$ = (Node *) n;
2189 : }
2190 :
2191 : ;
2192 :
2193 :
2194 : /*****************************************************************************
2195 : *
2196 : * ALTER [ TABLE | INDEX | SEQUENCE | VIEW | MATERIALIZED VIEW | FOREIGN TABLE ] variations
2197 : *
2198 : * Note: we accept all subcommands for each of the variants, and sort
2199 : * out what's really legal at execution time.
2200 : *****************************************************************************/
2201 :
2202 : AlterTableStmt:
2203 : ALTER TABLE relation_expr alter_table_cmds
2204 : {
2205 16403 : AlterTableStmt *n = makeNode(AlterTableStmt);
2206 :
2207 16403 : n->relation = $3;
2208 16403 : n->cmds = $4;
2209 16403 : n->objtype = OBJECT_TABLE;
2210 16403 : n->missing_ok = false;
2211 16403 : $$ = (Node *) n;
2212 : }
2213 : | ALTER TABLE IF_P EXISTS relation_expr alter_table_cmds
2214 : {
2215 36 : AlterTableStmt *n = makeNode(AlterTableStmt);
2216 :
2217 36 : n->relation = $5;
2218 36 : n->cmds = $6;
2219 36 : n->objtype = OBJECT_TABLE;
2220 36 : n->missing_ok = true;
2221 36 : $$ = (Node *) n;
2222 : }
2223 : | ALTER TABLE relation_expr partition_cmd
2224 : {
2225 2442 : AlterTableStmt *n = makeNode(AlterTableStmt);
2226 :
2227 2442 : n->relation = $3;
2228 2442 : n->cmds = list_make1($4);
2229 2442 : n->objtype = OBJECT_TABLE;
2230 2442 : n->missing_ok = false;
2231 2442 : $$ = (Node *) n;
2232 : }
2233 : | ALTER TABLE IF_P EXISTS relation_expr partition_cmd
2234 : {
2235 0 : AlterTableStmt *n = makeNode(AlterTableStmt);
2236 :
2237 0 : n->relation = $5;
2238 0 : n->cmds = list_make1($6);
2239 0 : n->objtype = OBJECT_TABLE;
2240 0 : n->missing_ok = true;
2241 0 : $$ = (Node *) n;
2242 : }
2243 : | ALTER TABLE ALL IN_P TABLESPACE name SET TABLESPACE name opt_nowait
2244 : {
2245 : AlterTableMoveAllStmt *n =
2246 6 : makeNode(AlterTableMoveAllStmt);
2247 :
2248 6 : n->orig_tablespacename = $6;
2249 6 : n->objtype = OBJECT_TABLE;
2250 6 : n->roles = NIL;
2251 6 : n->new_tablespacename = $9;
2252 6 : n->nowait = $10;
2253 6 : $$ = (Node *) n;
2254 : }
2255 : | ALTER TABLE ALL IN_P TABLESPACE name OWNED BY role_list SET TABLESPACE name opt_nowait
2256 : {
2257 : AlterTableMoveAllStmt *n =
2258 0 : makeNode(AlterTableMoveAllStmt);
2259 :
2260 0 : n->orig_tablespacename = $6;
2261 0 : n->objtype = OBJECT_TABLE;
2262 0 : n->roles = $9;
2263 0 : n->new_tablespacename = $12;
2264 0 : n->nowait = $13;
2265 0 : $$ = (Node *) n;
2266 : }
2267 : | ALTER INDEX qualified_name alter_table_cmds
2268 : {
2269 145 : AlterTableStmt *n = makeNode(AlterTableStmt);
2270 :
2271 145 : n->relation = $3;
2272 145 : n->cmds = $4;
2273 145 : n->objtype = OBJECT_INDEX;
2274 145 : n->missing_ok = false;
2275 145 : $$ = (Node *) n;
2276 : }
2277 : | ALTER INDEX IF_P EXISTS qualified_name alter_table_cmds
2278 : {
2279 0 : AlterTableStmt *n = makeNode(AlterTableStmt);
2280 :
2281 0 : n->relation = $5;
2282 0 : n->cmds = $6;
2283 0 : n->objtype = OBJECT_INDEX;
2284 0 : n->missing_ok = true;
2285 0 : $$ = (Node *) n;
2286 : }
2287 : | ALTER INDEX qualified_name index_partition_cmd
2288 : {
2289 251 : AlterTableStmt *n = makeNode(AlterTableStmt);
2290 :
2291 251 : n->relation = $3;
2292 251 : n->cmds = list_make1($4);
2293 251 : n->objtype = OBJECT_INDEX;
2294 251 : n->missing_ok = false;
2295 251 : $$ = (Node *) n;
2296 : }
2297 : | ALTER INDEX ALL IN_P TABLESPACE name SET TABLESPACE name opt_nowait
2298 : {
2299 : AlterTableMoveAllStmt *n =
2300 3 : makeNode(AlterTableMoveAllStmt);
2301 :
2302 3 : n->orig_tablespacename = $6;
2303 3 : n->objtype = OBJECT_INDEX;
2304 3 : n->roles = NIL;
2305 3 : n->new_tablespacename = $9;
2306 3 : n->nowait = $10;
2307 3 : $$ = (Node *) n;
2308 : }
2309 : | ALTER INDEX ALL IN_P TABLESPACE name OWNED BY role_list SET TABLESPACE name opt_nowait
2310 : {
2311 : AlterTableMoveAllStmt *n =
2312 0 : makeNode(AlterTableMoveAllStmt);
2313 :
2314 0 : n->orig_tablespacename = $6;
2315 0 : n->objtype = OBJECT_INDEX;
2316 0 : n->roles = $9;
2317 0 : n->new_tablespacename = $12;
2318 0 : n->nowait = $13;
2319 0 : $$ = (Node *) n;
2320 : }
2321 : | ALTER SEQUENCE qualified_name alter_table_cmds
2322 : {
2323 51 : AlterTableStmt *n = makeNode(AlterTableStmt);
2324 :
2325 51 : n->relation = $3;
2326 51 : n->cmds = $4;
2327 51 : n->objtype = OBJECT_SEQUENCE;
2328 51 : n->missing_ok = false;
2329 51 : $$ = (Node *) n;
2330 : }
2331 : | ALTER SEQUENCE IF_P EXISTS qualified_name alter_table_cmds
2332 : {
2333 0 : AlterTableStmt *n = makeNode(AlterTableStmt);
2334 :
2335 0 : n->relation = $5;
2336 0 : n->cmds = $6;
2337 0 : n->objtype = OBJECT_SEQUENCE;
2338 0 : n->missing_ok = true;
2339 0 : $$ = (Node *) n;
2340 : }
2341 : | ALTER VIEW qualified_name alter_table_cmds
2342 : {
2343 153 : AlterTableStmt *n = makeNode(AlterTableStmt);
2344 :
2345 153 : n->relation = $3;
2346 153 : n->cmds = $4;
2347 153 : n->objtype = OBJECT_VIEW;
2348 153 : n->missing_ok = false;
2349 153 : $$ = (Node *) n;
2350 : }
2351 : | ALTER VIEW IF_P EXISTS qualified_name alter_table_cmds
2352 : {
2353 0 : AlterTableStmt *n = makeNode(AlterTableStmt);
2354 :
2355 0 : n->relation = $5;
2356 0 : n->cmds = $6;
2357 0 : n->objtype = OBJECT_VIEW;
2358 0 : n->missing_ok = true;
2359 0 : $$ = (Node *) n;
2360 : }
2361 : | ALTER MATERIALIZED VIEW qualified_name alter_table_cmds
2362 : {
2363 29 : AlterTableStmt *n = makeNode(AlterTableStmt);
2364 :
2365 29 : n->relation = $4;
2366 29 : n->cmds = $5;
2367 29 : n->objtype = OBJECT_MATVIEW;
2368 29 : n->missing_ok = false;
2369 29 : $$ = (Node *) n;
2370 : }
2371 : | ALTER MATERIALIZED VIEW IF_P EXISTS qualified_name alter_table_cmds
2372 : {
2373 0 : AlterTableStmt *n = makeNode(AlterTableStmt);
2374 :
2375 0 : n->relation = $6;
2376 0 : n->cmds = $7;
2377 0 : n->objtype = OBJECT_MATVIEW;
2378 0 : n->missing_ok = true;
2379 0 : $$ = (Node *) n;
2380 : }
2381 : | ALTER MATERIALIZED VIEW ALL IN_P TABLESPACE name SET TABLESPACE name opt_nowait
2382 : {
2383 : AlterTableMoveAllStmt *n =
2384 6 : makeNode(AlterTableMoveAllStmt);
2385 :
2386 6 : n->orig_tablespacename = $7;
2387 6 : n->objtype = OBJECT_MATVIEW;
2388 6 : n->roles = NIL;
2389 6 : n->new_tablespacename = $10;
2390 6 : n->nowait = $11;
2391 6 : $$ = (Node *) n;
2392 : }
2393 : | ALTER MATERIALIZED VIEW ALL IN_P TABLESPACE name OWNED BY role_list SET TABLESPACE name opt_nowait
2394 : {
2395 : AlterTableMoveAllStmt *n =
2396 0 : makeNode(AlterTableMoveAllStmt);
2397 :
2398 0 : n->orig_tablespacename = $7;
2399 0 : n->objtype = OBJECT_MATVIEW;
2400 0 : n->roles = $10;
2401 0 : n->new_tablespacename = $13;
2402 0 : n->nowait = $14;
2403 0 : $$ = (Node *) n;
2404 : }
2405 : | ALTER FOREIGN TABLE relation_expr alter_table_cmds
2406 : {
2407 247 : AlterTableStmt *n = makeNode(AlterTableStmt);
2408 :
2409 247 : n->relation = $4;
2410 247 : n->cmds = $5;
2411 247 : n->objtype = OBJECT_FOREIGN_TABLE;
2412 247 : n->missing_ok = false;
2413 247 : $$ = (Node *) n;
2414 : }
2415 : | ALTER FOREIGN TABLE IF_P EXISTS relation_expr alter_table_cmds
2416 : {
2417 88 : AlterTableStmt *n = makeNode(AlterTableStmt);
2418 :
2419 88 : n->relation = $6;
2420 88 : n->cmds = $7;
2421 88 : n->objtype = OBJECT_FOREIGN_TABLE;
2422 88 : n->missing_ok = true;
2423 88 : $$ = (Node *) n;
2424 : }
2425 : ;
2426 :
2427 : alter_table_cmds:
2428 17152 : alter_table_cmd { $$ = list_make1($1); }
2429 684 : | alter_table_cmds ',' alter_table_cmd { $$ = lappend($1, $3); }
2430 : ;
2431 :
2432 : partitions_list:
2433 256 : SinglePartitionSpec { $$ = list_make1($1); }
2434 472 : | partitions_list ',' SinglePartitionSpec { $$ = lappend($1, $3); }
2435 : ;
2436 :
2437 : SinglePartitionSpec:
2438 : PARTITION qualified_name PartitionBoundSpec
2439 : {
2440 728 : SinglePartitionSpec *n = makeNode(SinglePartitionSpec);
2441 :
2442 728 : n->name = $2;
2443 728 : n->bound = $3;
2444 :
2445 728 : $$ = n;
2446 : }
2447 : ;
2448 :
2449 : partition_cmd:
2450 : /* ALTER TABLE <name> ATTACH PARTITION <table_name> FOR VALUES */
2451 : ATTACH PARTITION qualified_name PartitionBoundSpec
2452 : {
2453 1618 : AlterTableCmd *n = makeNode(AlterTableCmd);
2454 1618 : PartitionCmd *cmd = makeNode(PartitionCmd);
2455 :
2456 1618 : n->subtype = AT_AttachPartition;
2457 1618 : cmd->name = $3;
2458 1618 : cmd->bound = $4;
2459 1618 : cmd->partlist = NIL;
2460 1618 : cmd->concurrent = false;
2461 1618 : n->def = (Node *) cmd;
2462 :
2463 1618 : $$ = (Node *) n;
2464 : }
2465 : /* ALTER TABLE <name> DETACH PARTITION <partition_name> [CONCURRENTLY] */
2466 : | DETACH PARTITION qualified_name opt_concurrently
2467 : {
2468 381 : AlterTableCmd *n = makeNode(AlterTableCmd);
2469 381 : PartitionCmd *cmd = makeNode(PartitionCmd);
2470 :
2471 381 : n->subtype = AT_DetachPartition;
2472 381 : cmd->name = $3;
2473 381 : cmd->bound = NULL;
2474 381 : cmd->partlist = NIL;
2475 381 : cmd->concurrent = $4;
2476 381 : n->def = (Node *) cmd;
2477 :
2478 381 : $$ = (Node *) n;
2479 : }
2480 : | DETACH PARTITION qualified_name FINALIZE
2481 : {
2482 11 : AlterTableCmd *n = makeNode(AlterTableCmd);
2483 11 : PartitionCmd *cmd = makeNode(PartitionCmd);
2484 :
2485 11 : n->subtype = AT_DetachPartitionFinalize;
2486 11 : cmd->name = $3;
2487 11 : cmd->bound = NULL;
2488 11 : cmd->partlist = NIL;
2489 11 : cmd->concurrent = false;
2490 11 : n->def = (Node *) cmd;
2491 11 : $$ = (Node *) n;
2492 : }
2493 : /* ALTER TABLE <name> SPLIT PARTITION <partition_name> INTO () */
2494 : | SPLIT PARTITION qualified_name INTO '(' partitions_list ')'
2495 : {
2496 256 : AlterTableCmd *n = makeNode(AlterTableCmd);
2497 256 : PartitionCmd *cmd = makeNode(PartitionCmd);
2498 :
2499 256 : n->subtype = AT_SplitPartition;
2500 256 : cmd->name = $3;
2501 256 : cmd->bound = NULL;
2502 256 : cmd->partlist = $6;
2503 256 : cmd->concurrent = false;
2504 256 : n->def = (Node *) cmd;
2505 256 : $$ = (Node *) n;
2506 : }
2507 : /* ALTER TABLE <name> MERGE PARTITIONS () INTO <partition_name> */
2508 : | MERGE PARTITIONS '(' qualified_name_list ')' INTO qualified_name
2509 : {
2510 176 : AlterTableCmd *n = makeNode(AlterTableCmd);
2511 176 : PartitionCmd *cmd = makeNode(PartitionCmd);
2512 :
2513 176 : n->subtype = AT_MergePartitions;
2514 176 : cmd->name = $7;
2515 176 : cmd->bound = NULL;
2516 176 : cmd->partlist = $4;
2517 176 : cmd->concurrent = false;
2518 176 : n->def = (Node *) cmd;
2519 176 : $$ = (Node *) n;
2520 : }
2521 : ;
2522 :
2523 : index_partition_cmd:
2524 : /* ALTER INDEX <name> ATTACH PARTITION <index_name> */
2525 : ATTACH PARTITION qualified_name
2526 : {
2527 251 : AlterTableCmd *n = makeNode(AlterTableCmd);
2528 251 : PartitionCmd *cmd = makeNode(PartitionCmd);
2529 :
2530 251 : n->subtype = AT_AttachPartition;
2531 251 : cmd->name = $3;
2532 251 : cmd->bound = NULL;
2533 251 : cmd->partlist = NIL;
2534 251 : cmd->concurrent = false;
2535 251 : n->def = (Node *) cmd;
2536 :
2537 251 : $$ = (Node *) n;
2538 : }
2539 : ;
2540 :
2541 : alter_table_cmd:
2542 : /* ALTER TABLE <name> ADD <coldef> */
2543 : ADD_P columnDef
2544 : {
2545 138 : AlterTableCmd *n = makeNode(AlterTableCmd);
2546 :
2547 138 : n->subtype = AT_AddColumn;
2548 138 : n->def = $2;
2549 138 : n->missing_ok = false;
2550 138 : $$ = (Node *) n;
2551 : }
2552 : /* ALTER TABLE <name> ADD IF NOT EXISTS <coldef> */
2553 : | ADD_P IF_P NOT EXISTS columnDef
2554 : {
2555 4 : AlterTableCmd *n = makeNode(AlterTableCmd);
2556 :
2557 4 : n->subtype = AT_AddColumn;
2558 4 : n->def = $5;
2559 4 : n->missing_ok = true;
2560 4 : $$ = (Node *) n;
2561 : }
2562 : /* ALTER TABLE <name> ADD COLUMN <coldef> */
2563 : | ADD_P COLUMN columnDef
2564 : {
2565 1368 : AlterTableCmd *n = makeNode(AlterTableCmd);
2566 :
2567 1368 : n->subtype = AT_AddColumn;
2568 1368 : n->def = $3;
2569 1368 : n->missing_ok = false;
2570 1368 : $$ = (Node *) n;
2571 : }
2572 : /* ALTER TABLE <name> ADD COLUMN IF NOT EXISTS <coldef> */
2573 : | ADD_P COLUMN IF_P NOT EXISTS columnDef
2574 : {
2575 48 : AlterTableCmd *n = makeNode(AlterTableCmd);
2576 :
2577 48 : n->subtype = AT_AddColumn;
2578 48 : n->def = $6;
2579 48 : n->missing_ok = true;
2580 48 : $$ = (Node *) n;
2581 : }
2582 : /* ALTER TABLE <name> ALTER [COLUMN] <colname> {SET DEFAULT <expr>|DROP DEFAULT} */
2583 : | ALTER opt_column ColId alter_column_default
2584 : {
2585 361 : AlterTableCmd *n = makeNode(AlterTableCmd);
2586 :
2587 361 : n->subtype = AT_ColumnDefault;
2588 361 : n->name = $3;
2589 361 : n->def = $4;
2590 361 : $$ = (Node *) n;
2591 : }
2592 : /* ALTER TABLE <name> ALTER [COLUMN] <colname> DROP NOT NULL */
2593 : | ALTER opt_column ColId DROP NOT NULL_P
2594 : {
2595 194 : AlterTableCmd *n = makeNode(AlterTableCmd);
2596 :
2597 194 : n->subtype = AT_DropNotNull;
2598 194 : n->name = $3;
2599 194 : $$ = (Node *) n;
2600 : }
2601 : /* ALTER TABLE <name> ALTER [COLUMN] <colname> SET NOT NULL */
2602 : | ALTER opt_column ColId SET NOT NULL_P
2603 : {
2604 289 : AlterTableCmd *n = makeNode(AlterTableCmd);
2605 :
2606 289 : n->subtype = AT_SetNotNull;
2607 289 : n->name = $3;
2608 289 : $$ = (Node *) n;
2609 : }
2610 : /* ALTER TABLE <name> ALTER [COLUMN] <colname> SET EXPRESSION AS <expr> */
2611 : | ALTER opt_column ColId SET EXPRESSION AS '(' a_expr ')'
2612 : {
2613 121 : AlterTableCmd *n = makeNode(AlterTableCmd);
2614 :
2615 121 : n->subtype = AT_SetExpression;
2616 121 : n->name = $3;
2617 121 : n->def = $8;
2618 121 : $$ = (Node *) n;
2619 : }
2620 : /* ALTER TABLE <name> ALTER [COLUMN] <colname> DROP EXPRESSION */
2621 : | ALTER opt_column ColId DROP EXPRESSION
2622 : {
2623 41 : AlterTableCmd *n = makeNode(AlterTableCmd);
2624 :
2625 41 : n->subtype = AT_DropExpression;
2626 41 : n->name = $3;
2627 41 : $$ = (Node *) n;
2628 : }
2629 : /* ALTER TABLE <name> ALTER [COLUMN] <colname> DROP EXPRESSION IF EXISTS */
2630 : | ALTER opt_column ColId DROP EXPRESSION IF_P EXISTS
2631 : {
2632 8 : AlterTableCmd *n = makeNode(AlterTableCmd);
2633 :
2634 8 : n->subtype = AT_DropExpression;
2635 8 : n->name = $3;
2636 8 : n->missing_ok = true;
2637 8 : $$ = (Node *) n;
2638 : }
2639 : /* ALTER TABLE <name> ALTER [COLUMN] <colname> SET STATISTICS */
2640 : | ALTER opt_column ColId SET STATISTICS set_statistics_value
2641 : {
2642 40 : AlterTableCmd *n = makeNode(AlterTableCmd);
2643 :
2644 40 : n->subtype = AT_SetStatistics;
2645 40 : n->name = $3;
2646 40 : n->def = $6;
2647 40 : $$ = (Node *) n;
2648 : }
2649 : /* ALTER TABLE <name> ALTER [COLUMN] <colnum> SET STATISTICS */
2650 : | ALTER opt_column Iconst SET STATISTICS set_statistics_value
2651 : {
2652 46 : AlterTableCmd *n = makeNode(AlterTableCmd);
2653 :
2654 46 : if ($3 <= 0 || $3 > PG_INT16_MAX)
2655 4 : ereport(ERROR,
2656 : (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
2657 : errmsg("column number must be in range from 1 to %d", PG_INT16_MAX),
2658 : parser_errposition(@3)));
2659 :
2660 42 : n->subtype = AT_SetStatistics;
2661 42 : n->num = (int16) $3;
2662 42 : n->def = $6;
2663 42 : $$ = (Node *) n;
2664 : }
2665 : /* ALTER TABLE <name> ALTER [COLUMN] <colname> SET ( column_parameter = value [, ... ] ) */
2666 : | ALTER opt_column ColId SET reloptions
2667 : {
2668 25 : AlterTableCmd *n = makeNode(AlterTableCmd);
2669 :
2670 25 : n->subtype = AT_SetOptions;
2671 25 : n->name = $3;
2672 25 : n->def = (Node *) $5;
2673 25 : $$ = (Node *) n;
2674 : }
2675 : /* ALTER TABLE <name> ALTER [COLUMN] <colname> RESET ( column_parameter [, ... ] ) */
2676 : | ALTER opt_column ColId RESET reloptions
2677 : {
2678 4 : AlterTableCmd *n = makeNode(AlterTableCmd);
2679 :
2680 4 : n->subtype = AT_ResetOptions;
2681 4 : n->name = $3;
2682 4 : n->def = (Node *) $5;
2683 4 : $$ = (Node *) n;
2684 : }
2685 : /* ALTER TABLE <name> ALTER [COLUMN] <colname> SET STORAGE <storagemode> */
2686 : | ALTER opt_column ColId SET column_storage
2687 : {
2688 159 : AlterTableCmd *n = makeNode(AlterTableCmd);
2689 :
2690 159 : n->subtype = AT_SetStorage;
2691 159 : n->name = $3;
2692 159 : n->def = (Node *) makeString($5);
2693 159 : $$ = (Node *) n;
2694 : }
2695 : /* ALTER TABLE <name> ALTER [COLUMN] <colname> SET COMPRESSION <cm> */
2696 : | ALTER opt_column ColId SET column_compression
2697 : {
2698 47 : AlterTableCmd *n = makeNode(AlterTableCmd);
2699 :
2700 47 : n->subtype = AT_SetCompression;
2701 47 : n->name = $3;
2702 47 : n->def = (Node *) makeString($5);
2703 47 : $$ = (Node *) n;
2704 : }
2705 : /* ALTER TABLE <name> ALTER [COLUMN] <colname> ADD GENERATED ... AS IDENTITY ... */
2706 : | ALTER opt_column ColId ADD_P GENERATED generated_when AS IDENTITY_P OptParenthesizedSeqOptList
2707 : {
2708 107 : AlterTableCmd *n = makeNode(AlterTableCmd);
2709 107 : Constraint *c = makeNode(Constraint);
2710 :
2711 107 : c->contype = CONSTR_IDENTITY;
2712 107 : c->generated_when = $6;
2713 107 : c->options = $9;
2714 107 : c->location = @5;
2715 :
2716 107 : n->subtype = AT_AddIdentity;
2717 107 : n->name = $3;
2718 107 : n->def = (Node *) c;
2719 :
2720 107 : $$ = (Node *) n;
2721 : }
2722 : /* ALTER TABLE <name> ALTER [COLUMN] <colname> SET <sequence options>/RESET */
2723 : | ALTER opt_column ColId alter_identity_column_option_list
2724 : {
2725 41 : AlterTableCmd *n = makeNode(AlterTableCmd);
2726 :
2727 41 : n->subtype = AT_SetIdentity;
2728 41 : n->name = $3;
2729 41 : n->def = (Node *) $4;
2730 41 : $$ = (Node *) n;
2731 : }
2732 : /* ALTER TABLE <name> ALTER [COLUMN] <colname> DROP IDENTITY */
2733 : | ALTER opt_column ColId DROP IDENTITY_P
2734 : {
2735 33 : AlterTableCmd *n = makeNode(AlterTableCmd);
2736 :
2737 33 : n->subtype = AT_DropIdentity;
2738 33 : n->name = $3;
2739 33 : n->missing_ok = false;
2740 33 : $$ = (Node *) n;
2741 : }
2742 : /* ALTER TABLE <name> ALTER [COLUMN] <colname> DROP IDENTITY IF EXISTS */
2743 : | ALTER opt_column ColId DROP IDENTITY_P IF_P EXISTS
2744 : {
2745 4 : AlterTableCmd *n = makeNode(AlterTableCmd);
2746 :
2747 4 : n->subtype = AT_DropIdentity;
2748 4 : n->name = $3;
2749 4 : n->missing_ok = true;
2750 4 : $$ = (Node *) n;
2751 : }
2752 : /* ALTER TABLE <name> DROP [COLUMN] IF EXISTS <colname> [RESTRICT|CASCADE] */
2753 : | DROP opt_column IF_P EXISTS ColId opt_drop_behavior
2754 : {
2755 16 : AlterTableCmd *n = makeNode(AlterTableCmd);
2756 :
2757 16 : n->subtype = AT_DropColumn;
2758 16 : n->name = $5;
2759 16 : n->behavior = $6;
2760 16 : n->missing_ok = true;
2761 16 : $$ = (Node *) n;
2762 : }
2763 : /* ALTER TABLE <name> DROP [COLUMN] <colname> [RESTRICT|CASCADE] */
2764 : | DROP opt_column ColId opt_drop_behavior
2765 : {
2766 1067 : AlterTableCmd *n = makeNode(AlterTableCmd);
2767 :
2768 1067 : n->subtype = AT_DropColumn;
2769 1067 : n->name = $3;
2770 1067 : n->behavior = $4;
2771 1067 : n->missing_ok = false;
2772 1067 : $$ = (Node *) n;
2773 : }
2774 : /*
2775 : * ALTER TABLE <name> ALTER [COLUMN] <colname> [SET DATA] TYPE <typename>
2776 : * [ USING <expression> ]
2777 : */
2778 : | ALTER opt_column ColId opt_set_data TYPE_P Typename opt_collate_clause alter_using
2779 : {
2780 745 : AlterTableCmd *n = makeNode(AlterTableCmd);
2781 745 : ColumnDef *def = makeNode(ColumnDef);
2782 :
2783 745 : n->subtype = AT_AlterColumnType;
2784 745 : n->name = $3;
2785 745 : n->def = (Node *) def;
2786 : /* We only use these fields of the ColumnDef node */
2787 745 : def->typeName = $6;
2788 745 : def->collClause = (CollateClause *) $7;
2789 745 : def->raw_default = $8;
2790 745 : def->location = @3;
2791 745 : $$ = (Node *) n;
2792 : }
2793 : /* ALTER FOREIGN TABLE <name> ALTER [COLUMN] <colname> OPTIONS */
2794 : | ALTER opt_column ColId alter_generic_options
2795 : {
2796 32 : AlterTableCmd *n = makeNode(AlterTableCmd);
2797 :
2798 32 : n->subtype = AT_AlterColumnGenericOptions;
2799 32 : n->name = $3;
2800 32 : n->def = (Node *) $4;
2801 32 : $$ = (Node *) n;
2802 : }
2803 : /* ALTER TABLE <name> ADD CONSTRAINT ... */
2804 : | ADD_P TableConstraint
2805 : {
2806 8544 : AlterTableCmd *n = makeNode(AlterTableCmd);
2807 :
2808 8544 : n->subtype = AT_AddConstraint;
2809 8544 : n->def = $2;
2810 8544 : $$ = (Node *) n;
2811 : }
2812 : /* ALTER TABLE <name> ALTER CONSTRAINT ... */
2813 : | ALTER CONSTRAINT name ConstraintAttributeSpec
2814 : {
2815 252 : AlterTableCmd *n = makeNode(AlterTableCmd);
2816 252 : ATAlterConstraint *c = makeNode(ATAlterConstraint);
2817 :
2818 252 : n->subtype = AT_AlterConstraint;
2819 252 : n->def = (Node *) c;
2820 252 : c->conname = $3;
2821 252 : if ($4 & (CAS_NOT_ENFORCED | CAS_ENFORCED))
2822 148 : c->alterEnforceability = true;
2823 252 : if ($4 & (CAS_DEFERRABLE | CAS_NOT_DEFERRABLE |
2824 : CAS_INITIALLY_DEFERRED | CAS_INITIALLY_IMMEDIATE))
2825 80 : c->alterDeferrability = true;
2826 252 : if ($4 & CAS_NO_INHERIT)
2827 20 : c->alterInheritability = true;
2828 : /* handle unsupported case with specific error message */
2829 252 : if ($4 & CAS_NOT_VALID)
2830 8 : ereport(ERROR,
2831 : errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
2832 : errmsg("constraints cannot be altered to be NOT VALID"),
2833 : parser_errposition(@4));
2834 244 : processCASbits($4, @4, "FOREIGN KEY",
2835 : &c->deferrable,
2836 : &c->initdeferred,
2837 : &c->is_enforced,
2838 : NULL,
2839 : &c->noinherit,
2840 : yyscanner);
2841 244 : $$ = (Node *) n;
2842 : }
2843 : /* ALTER TABLE <name> ALTER CONSTRAINT INHERIT */
2844 : | ALTER CONSTRAINT name INHERIT
2845 : {
2846 44 : AlterTableCmd *n = makeNode(AlterTableCmd);
2847 44 : ATAlterConstraint *c = makeNode(ATAlterConstraint);
2848 :
2849 44 : n->subtype = AT_AlterConstraint;
2850 44 : n->def = (Node *) c;
2851 44 : c->conname = $3;
2852 44 : c->alterInheritability = true;
2853 44 : c->noinherit = false;
2854 :
2855 44 : $$ = (Node *) n;
2856 : }
2857 : /* ALTER TABLE <name> VALIDATE CONSTRAINT ... */
2858 : | VALIDATE CONSTRAINT name
2859 : {
2860 275 : AlterTableCmd *n = makeNode(AlterTableCmd);
2861 :
2862 275 : n->subtype = AT_ValidateConstraint;
2863 275 : n->name = $3;
2864 275 : $$ = (Node *) n;
2865 : }
2866 : /* ALTER TABLE <name> DROP CONSTRAINT IF EXISTS <name> [RESTRICT|CASCADE] */
2867 : | DROP CONSTRAINT IF_P EXISTS name opt_drop_behavior
2868 : {
2869 12 : AlterTableCmd *n = makeNode(AlterTableCmd);
2870 :
2871 12 : n->subtype = AT_DropConstraint;
2872 12 : n->name = $5;
2873 12 : n->behavior = $6;
2874 12 : n->missing_ok = true;
2875 12 : $$ = (Node *) n;
2876 : }
2877 : /* ALTER TABLE <name> DROP CONSTRAINT <name> [RESTRICT|CASCADE] */
2878 : | DROP CONSTRAINT name opt_drop_behavior
2879 : {
2880 553 : AlterTableCmd *n = makeNode(AlterTableCmd);
2881 :
2882 553 : n->subtype = AT_DropConstraint;
2883 553 : n->name = $3;
2884 553 : n->behavior = $4;
2885 553 : n->missing_ok = false;
2886 553 : $$ = (Node *) n;
2887 : }
2888 : /* ALTER TABLE <name> SET WITHOUT OIDS, for backward compat */
2889 : | SET WITHOUT OIDS
2890 : {
2891 4 : AlterTableCmd *n = makeNode(AlterTableCmd);
2892 :
2893 4 : n->subtype = AT_DropOids;
2894 4 : $$ = (Node *) n;
2895 : }
2896 : /* ALTER TABLE <name> CLUSTER ON <indexname> */
2897 : | CLUSTER ON name
2898 : {
2899 31 : AlterTableCmd *n = makeNode(AlterTableCmd);
2900 :
2901 31 : n->subtype = AT_ClusterOn;
2902 31 : n->name = $3;
2903 31 : $$ = (Node *) n;
2904 : }
2905 : /* ALTER TABLE <name> SET WITHOUT CLUSTER */
2906 : | SET WITHOUT CLUSTER
2907 : {
2908 12 : AlterTableCmd *n = makeNode(AlterTableCmd);
2909 :
2910 12 : n->subtype = AT_DropCluster;
2911 12 : n->name = NULL;
2912 12 : $$ = (Node *) n;
2913 : }
2914 : /* ALTER TABLE <name> SET LOGGED */
2915 : | SET LOGGED
2916 : {
2917 33 : AlterTableCmd *n = makeNode(AlterTableCmd);
2918 :
2919 33 : n->subtype = AT_SetLogged;
2920 33 : $$ = (Node *) n;
2921 : }
2922 : /* ALTER TABLE <name> SET UNLOGGED */
2923 : | SET UNLOGGED
2924 : {
2925 41 : AlterTableCmd *n = makeNode(AlterTableCmd);
2926 :
2927 41 : n->subtype = AT_SetUnLogged;
2928 41 : $$ = (Node *) n;
2929 : }
2930 : /* ALTER TABLE <name> ENABLE TRIGGER <trig> */
2931 : | ENABLE_P TRIGGER name
2932 : {
2933 65 : AlterTableCmd *n = makeNode(AlterTableCmd);
2934 :
2935 65 : n->subtype = AT_EnableTrig;
2936 65 : n->name = $3;
2937 65 : $$ = (Node *) n;
2938 : }
2939 : /* ALTER TABLE <name> ENABLE ALWAYS TRIGGER <trig> */
2940 : | ENABLE_P ALWAYS TRIGGER name
2941 : {
2942 27 : AlterTableCmd *n = makeNode(AlterTableCmd);
2943 :
2944 27 : n->subtype = AT_EnableAlwaysTrig;
2945 27 : n->name = $4;
2946 27 : $$ = (Node *) n;
2947 : }
2948 : /* ALTER TABLE <name> ENABLE REPLICA TRIGGER <trig> */
2949 : | ENABLE_P REPLICA TRIGGER name
2950 : {
2951 8 : AlterTableCmd *n = makeNode(AlterTableCmd);
2952 :
2953 8 : n->subtype = AT_EnableReplicaTrig;
2954 8 : n->name = $4;
2955 8 : $$ = (Node *) n;
2956 : }
2957 : /* ALTER TABLE <name> ENABLE TRIGGER ALL */
2958 : | ENABLE_P TRIGGER ALL
2959 : {
2960 0 : AlterTableCmd *n = makeNode(AlterTableCmd);
2961 :
2962 0 : n->subtype = AT_EnableTrigAll;
2963 0 : $$ = (Node *) n;
2964 : }
2965 : /* ALTER TABLE <name> ENABLE TRIGGER USER */
2966 : | ENABLE_P TRIGGER USER
2967 : {
2968 0 : AlterTableCmd *n = makeNode(AlterTableCmd);
2969 :
2970 0 : n->subtype = AT_EnableTrigUser;
2971 0 : $$ = (Node *) n;
2972 : }
2973 : /* ALTER TABLE <name> DISABLE TRIGGER <trig> */
2974 : | DISABLE_P TRIGGER name
2975 : {
2976 75 : AlterTableCmd *n = makeNode(AlterTableCmd);
2977 :
2978 75 : n->subtype = AT_DisableTrig;
2979 75 : n->name = $3;
2980 75 : $$ = (Node *) n;
2981 : }
2982 : /* ALTER TABLE <name> DISABLE TRIGGER ALL */
2983 : | DISABLE_P TRIGGER ALL
2984 : {
2985 8 : AlterTableCmd *n = makeNode(AlterTableCmd);
2986 :
2987 8 : n->subtype = AT_DisableTrigAll;
2988 8 : $$ = (Node *) n;
2989 : }
2990 : /* ALTER TABLE <name> DISABLE TRIGGER USER */
2991 : | DISABLE_P TRIGGER USER
2992 : {
2993 8 : AlterTableCmd *n = makeNode(AlterTableCmd);
2994 :
2995 8 : n->subtype = AT_DisableTrigUser;
2996 8 : $$ = (Node *) n;
2997 : }
2998 : /* ALTER TABLE <name> ENABLE RULE <rule> */
2999 : | ENABLE_P RULE name
3000 : {
3001 5 : AlterTableCmd *n = makeNode(AlterTableCmd);
3002 :
3003 5 : n->subtype = AT_EnableRule;
3004 5 : n->name = $3;
3005 5 : $$ = (Node *) n;
3006 : }
3007 : /* ALTER TABLE <name> ENABLE ALWAYS RULE <rule> */
3008 : | ENABLE_P ALWAYS RULE name
3009 : {
3010 0 : AlterTableCmd *n = makeNode(AlterTableCmd);
3011 :
3012 0 : n->subtype = AT_EnableAlwaysRule;
3013 0 : n->name = $4;
3014 0 : $$ = (Node *) n;
3015 : }
3016 : /* ALTER TABLE <name> ENABLE REPLICA RULE <rule> */
3017 : | ENABLE_P REPLICA RULE name
3018 : {
3019 4 : AlterTableCmd *n = makeNode(AlterTableCmd);
3020 :
3021 4 : n->subtype = AT_EnableReplicaRule;
3022 4 : n->name = $4;
3023 4 : $$ = (Node *) n;
3024 : }
3025 : /* ALTER TABLE <name> DISABLE RULE <rule> */
3026 : | DISABLE_P RULE name
3027 : {
3028 20 : AlterTableCmd *n = makeNode(AlterTableCmd);
3029 :
3030 20 : n->subtype = AT_DisableRule;
3031 20 : n->name = $3;
3032 20 : $$ = (Node *) n;
3033 : }
3034 : /* ALTER TABLE <name> INHERIT <parent> */
3035 : | INHERIT qualified_name
3036 : {
3037 305 : AlterTableCmd *n = makeNode(AlterTableCmd);
3038 :
3039 305 : n->subtype = AT_AddInherit;
3040 305 : n->def = (Node *) $2;
3041 305 : $$ = (Node *) n;
3042 : }
3043 : /* ALTER TABLE <name> NO INHERIT <parent> */
3044 : | NO INHERIT qualified_name
3045 : {
3046 81 : AlterTableCmd *n = makeNode(AlterTableCmd);
3047 :
3048 81 : n->subtype = AT_DropInherit;
3049 81 : n->def = (Node *) $3;
3050 81 : $$ = (Node *) n;
3051 : }
3052 : /* ALTER TABLE <name> OF <type_name> */
3053 : | OF any_name
3054 : {
3055 42 : AlterTableCmd *n = makeNode(AlterTableCmd);
3056 42 : TypeName *def = makeTypeNameFromNameList($2);
3057 :
3058 42 : def->location = @2;
3059 42 : n->subtype = AT_AddOf;
3060 42 : n->def = (Node *) def;
3061 42 : $$ = (Node *) n;
3062 : }
3063 : /* ALTER TABLE <name> NOT OF */
3064 : | NOT OF
3065 : {
3066 4 : AlterTableCmd *n = makeNode(AlterTableCmd);
3067 :
3068 4 : n->subtype = AT_DropOf;
3069 4 : $$ = (Node *) n;
3070 : }
3071 : /* ALTER TABLE <name> OWNER TO RoleSpec */
3072 : | OWNER TO RoleSpec
3073 : {
3074 1139 : AlterTableCmd *n = makeNode(AlterTableCmd);
3075 :
3076 1139 : n->subtype = AT_ChangeOwner;
3077 1139 : n->newowner = $3;
3078 1139 : $$ = (Node *) n;
3079 : }
3080 : /* ALTER TABLE <name> SET ACCESS METHOD { <amname> | DEFAULT } */
3081 : | SET ACCESS METHOD set_access_method_name
3082 : {
3083 85 : AlterTableCmd *n = makeNode(AlterTableCmd);
3084 :
3085 85 : n->subtype = AT_SetAccessMethod;
3086 85 : n->name = $4;
3087 85 : $$ = (Node *) n;
3088 : }
3089 : /* ALTER TABLE <name> SET TABLESPACE <tablespacename> */
3090 : | SET TABLESPACE name
3091 : {
3092 74 : AlterTableCmd *n = makeNode(AlterTableCmd);
3093 :
3094 74 : n->subtype = AT_SetTableSpace;
3095 74 : n->name = $3;
3096 74 : $$ = (Node *) n;
3097 : }
3098 : /* ALTER TABLE <name> SET (...) */
3099 : | SET reloptions
3100 : {
3101 380 : AlterTableCmd *n = makeNode(AlterTableCmd);
3102 :
3103 380 : n->subtype = AT_SetRelOptions;
3104 380 : n->def = (Node *) $2;
3105 380 : $$ = (Node *) n;
3106 : }
3107 : /* ALTER TABLE <name> RESET (...) */
3108 : | RESET reloptions
3109 : {
3110 111 : AlterTableCmd *n = makeNode(AlterTableCmd);
3111 :
3112 111 : n->subtype = AT_ResetRelOptions;
3113 111 : n->def = (Node *) $2;
3114 111 : $$ = (Node *) n;
3115 : }
3116 : /* ALTER TABLE <name> REPLICA IDENTITY */
3117 : | REPLICA IDENTITY_P replica_identity
3118 : {
3119 301 : AlterTableCmd *n = makeNode(AlterTableCmd);
3120 :
3121 301 : n->subtype = AT_ReplicaIdentity;
3122 301 : n->def = $3;
3123 301 : $$ = (Node *) n;
3124 : }
3125 : /* ALTER TABLE <name> ENABLE ROW LEVEL SECURITY */
3126 : | ENABLE_P ROW LEVEL SECURITY
3127 : {
3128 236 : AlterTableCmd *n = makeNode(AlterTableCmd);
3129 :
3130 236 : n->subtype = AT_EnableRowSecurity;
3131 236 : $$ = (Node *) n;
3132 : }
3133 : /* ALTER TABLE <name> DISABLE ROW LEVEL SECURITY */
3134 : | DISABLE_P ROW LEVEL SECURITY
3135 : {
3136 6 : AlterTableCmd *n = makeNode(AlterTableCmd);
3137 :
3138 6 : n->subtype = AT_DisableRowSecurity;
3139 6 : $$ = (Node *) n;
3140 : }
3141 : /* ALTER TABLE <name> FORCE ROW LEVEL SECURITY */
3142 : | FORCE ROW LEVEL SECURITY
3143 : {
3144 70 : AlterTableCmd *n = makeNode(AlterTableCmd);
3145 :
3146 70 : n->subtype = AT_ForceRowSecurity;
3147 70 : $$ = (Node *) n;
3148 : }
3149 : /* ALTER TABLE <name> NO FORCE ROW LEVEL SECURITY */
3150 : | NO FORCE ROW LEVEL SECURITY
3151 : {
3152 20 : AlterTableCmd *n = makeNode(AlterTableCmd);
3153 :
3154 20 : n->subtype = AT_NoForceRowSecurity;
3155 20 : $$ = (Node *) n;
3156 : }
3157 : | alter_generic_options
3158 : {
3159 35 : AlterTableCmd *n = makeNode(AlterTableCmd);
3160 :
3161 35 : n->subtype = AT_GenericOptions;
3162 35 : n->def = (Node *) $1;
3163 35 : $$ = (Node *) n;
3164 : }
3165 : ;
3166 :
3167 : alter_column_default:
3168 246 : SET DEFAULT a_expr { $$ = $3; }
3169 124 : | DROP DEFAULT { $$ = NULL; }
3170 : ;
3171 :
3172 : opt_collate_clause:
3173 : COLLATE any_name
3174 : {
3175 12 : CollateClause *n = makeNode(CollateClause);
3176 :
3177 12 : n->arg = NULL;
3178 12 : n->collname = $2;
3179 12 : n->location = @1;
3180 12 : $$ = (Node *) n;
3181 : }
3182 3050 : | /* EMPTY */ { $$ = NULL; }
3183 : ;
3184 :
3185 : alter_using:
3186 119 : USING a_expr { $$ = $2; }
3187 626 : | /* EMPTY */ { $$ = NULL; }
3188 : ;
3189 :
3190 : replica_identity:
3191 : NOTHING
3192 : {
3193 29 : ReplicaIdentityStmt *n = makeNode(ReplicaIdentityStmt);
3194 :
3195 29 : n->identity_type = REPLICA_IDENTITY_NOTHING;
3196 29 : n->name = NULL;
3197 29 : $$ = (Node *) n;
3198 : }
3199 : | FULL
3200 : {
3201 98 : ReplicaIdentityStmt *n = makeNode(ReplicaIdentityStmt);
3202 :
3203 98 : n->identity_type = REPLICA_IDENTITY_FULL;
3204 98 : n->name = NULL;
3205 98 : $$ = (Node *) n;
3206 : }
3207 : | DEFAULT
3208 : {
3209 4 : ReplicaIdentityStmt *n = makeNode(ReplicaIdentityStmt);
3210 :
3211 4 : n->identity_type = REPLICA_IDENTITY_DEFAULT;
3212 4 : n->name = NULL;
3213 4 : $$ = (Node *) n;
3214 : }
3215 : | USING INDEX name
3216 : {
3217 170 : ReplicaIdentityStmt *n = makeNode(ReplicaIdentityStmt);
3218 :
3219 170 : n->identity_type = REPLICA_IDENTITY_INDEX;
3220 170 : n->name = $3;
3221 170 : $$ = (Node *) n;
3222 : }
3223 : ;
3224 :
3225 : reloptions:
3226 1779 : '(' reloption_list ')' { $$ = $2; }
3227 : ;
3228 :
3229 573 : opt_reloptions: WITH reloptions { $$ = $2; }
3230 14033 : | /* EMPTY */ { $$ = NIL; }
3231 : ;
3232 :
3233 : reloption_list:
3234 1779 : reloption_elem { $$ = list_make1($1); }
3235 158 : | reloption_list ',' reloption_elem { $$ = lappend($1, $3); }
3236 : ;
3237 :
3238 : /* This should match def_elem and also allow qualified names */
3239 : reloption_elem:
3240 : ColLabel '=' def_arg
3241 : {
3242 1540 : $$ = makeDefElem($1, (Node *) $3, @1);
3243 : }
3244 : | ColLabel
3245 : {
3246 347 : $$ = makeDefElem($1, NULL, @1);
3247 : }
3248 : | ColLabel '.' ColLabel '=' def_arg
3249 : {
3250 46 : $$ = makeDefElemExtended($1, $3, (Node *) $5,
3251 46 : DEFELEM_UNSPEC, @1);
3252 : }
3253 : | ColLabel '.' ColLabel
3254 : {
3255 4 : $$ = makeDefElemExtended($1, $3, NULL, DEFELEM_UNSPEC, @1);
3256 : }
3257 : ;
3258 :
3259 : alter_identity_column_option_list:
3260 : alter_identity_column_option
3261 41 : { $$ = list_make1($1); }
3262 : | alter_identity_column_option_list alter_identity_column_option
3263 40 : { $$ = lappend($1, $2); }
3264 : ;
3265 :
3266 : alter_identity_column_option:
3267 : RESTART
3268 : {
3269 16 : $$ = makeDefElem("restart", NULL, @1);
3270 : }
3271 : | RESTART opt_with NumericOnly
3272 : {
3273 0 : $$ = makeDefElem("restart", (Node *) $3, @1);
3274 : }
3275 : | SET SeqOptElem
3276 : {
3277 36 : if (strcmp($2->defname, "as") == 0 ||
3278 36 : strcmp($2->defname, "restart") == 0 ||
3279 36 : strcmp($2->defname, "owned_by") == 0)
3280 0 : ereport(ERROR,
3281 : (errcode(ERRCODE_SYNTAX_ERROR),
3282 : errmsg("sequence option \"%s\" not supported here", $2->defname),
3283 : parser_errposition(@2)));
3284 36 : $$ = $2;
3285 : }
3286 : | SET GENERATED generated_when
3287 : {
3288 29 : $$ = makeDefElem("generated", (Node *) makeInteger($3), @1);
3289 : }
3290 : ;
3291 :
3292 : set_statistics_value:
3293 103 : SignedIconst { $$ = (Node *) makeInteger($1); }
3294 0 : | DEFAULT { $$ = NULL; }
3295 : ;
3296 :
3297 : set_access_method_name:
3298 61 : ColId { $$ = $1; }
3299 24 : | DEFAULT { $$ = NULL; }
3300 : ;
3301 :
3302 : PartitionBoundSpec:
3303 : /* a HASH partition */
3304 : FOR VALUES WITH '(' hash_partbound ')'
3305 : {
3306 : ListCell *lc;
3307 500 : PartitionBoundSpec *n = makeNode(PartitionBoundSpec);
3308 :
3309 500 : n->strategy = PARTITION_STRATEGY_HASH;
3310 500 : n->modulus = n->remainder = -1;
3311 :
3312 1500 : foreach (lc, $5)
3313 : {
3314 1000 : DefElem *opt = lfirst_node(DefElem, lc);
3315 :
3316 1000 : if (strcmp(opt->defname, "modulus") == 0)
3317 : {
3318 500 : if (n->modulus != -1)
3319 0 : ereport(ERROR,
3320 : (errcode(ERRCODE_DUPLICATE_OBJECT),
3321 : errmsg("modulus for hash partition provided more than once"),
3322 : parser_errposition(opt->location)));
3323 500 : n->modulus = defGetInt32(opt);
3324 : }
3325 500 : else if (strcmp(opt->defname, "remainder") == 0)
3326 : {
3327 500 : if (n->remainder != -1)
3328 0 : ereport(ERROR,
3329 : (errcode(ERRCODE_DUPLICATE_OBJECT),
3330 : errmsg("remainder for hash partition provided more than once"),
3331 : parser_errposition(opt->location)));
3332 500 : n->remainder = defGetInt32(opt);
3333 : }
3334 : else
3335 0 : ereport(ERROR,
3336 : (errcode(ERRCODE_SYNTAX_ERROR),
3337 : errmsg("unrecognized hash partition bound specification \"%s\"",
3338 : opt->defname),
3339 : parser_errposition(opt->location)));
3340 : }
3341 :
3342 500 : if (n->modulus == -1)
3343 0 : ereport(ERROR,
3344 : (errcode(ERRCODE_SYNTAX_ERROR),
3345 : errmsg("modulus for hash partition must be specified"),
3346 : parser_errposition(@3)));
3347 500 : if (n->remainder == -1)
3348 0 : ereport(ERROR,
3349 : (errcode(ERRCODE_SYNTAX_ERROR),
3350 : errmsg("remainder for hash partition must be specified"),
3351 : parser_errposition(@3)));
3352 :
3353 500 : n->location = @3;
3354 :
3355 500 : $$ = n;
3356 : }
3357 :
3358 : /* a LIST partition */
3359 : | FOR VALUES IN_P '(' expr_list ')'
3360 : {
3361 3302 : PartitionBoundSpec *n = makeNode(PartitionBoundSpec);
3362 :
3363 3302 : n->strategy = PARTITION_STRATEGY_LIST;
3364 3302 : n->is_default = false;
3365 3302 : n->listdatums = $5;
3366 3302 : n->location = @3;
3367 :
3368 3302 : $$ = n;
3369 : }
3370 :
3371 : /* a RANGE partition */
3372 : | FOR VALUES FROM '(' expr_list ')' TO '(' expr_list ')'
3373 : {
3374 3864 : PartitionBoundSpec *n = makeNode(PartitionBoundSpec);
3375 :
3376 3864 : n->strategy = PARTITION_STRATEGY_RANGE;
3377 3864 : n->is_default = false;
3378 3864 : n->lowerdatums = $5;
3379 3864 : n->upperdatums = $9;
3380 3864 : n->location = @3;
3381 :
3382 3864 : $$ = n;
3383 : }
3384 :
3385 : /* a DEFAULT partition */
3386 : | DEFAULT
3387 : {
3388 543 : PartitionBoundSpec *n = makeNode(PartitionBoundSpec);
3389 :
3390 543 : n->is_default = true;
3391 543 : n->location = @1;
3392 :
3393 543 : $$ = n;
3394 : }
3395 : ;
3396 :
3397 : hash_partbound_elem:
3398 : NonReservedWord Iconst
3399 : {
3400 1000 : $$ = makeDefElem($1, (Node *) makeInteger($2), @1);
3401 : }
3402 : ;
3403 :
3404 : hash_partbound:
3405 : hash_partbound_elem
3406 : {
3407 500 : $$ = list_make1($1);
3408 : }
3409 : | hash_partbound ',' hash_partbound_elem
3410 : {
3411 500 : $$ = lappend($1, $3);
3412 : }
3413 : ;
3414 :
3415 : /*****************************************************************************
3416 : *
3417 : * ALTER TYPE
3418 : *
3419 : * really variants of the ALTER TABLE subcommands with different spellings
3420 : *****************************************************************************/
3421 :
3422 : AlterCompositeTypeStmt:
3423 : ALTER TYPE_P any_name alter_type_cmds
3424 : {
3425 137 : AlterTableStmt *n = makeNode(AlterTableStmt);
3426 :
3427 : /* can't use qualified_name, sigh */
3428 137 : n->relation = makeRangeVarFromAnyName($3, @3, yyscanner);
3429 137 : n->cmds = $4;
3430 137 : n->objtype = OBJECT_TYPE;
3431 137 : $$ = (Node *) n;
3432 : }
3433 : ;
3434 :
3435 : alter_type_cmds:
3436 137 : alter_type_cmd { $$ = list_make1($1); }
3437 8 : | alter_type_cmds ',' alter_type_cmd { $$ = lappend($1, $3); }
3438 : ;
3439 :
3440 : alter_type_cmd:
3441 : /* ALTER TYPE <name> ADD ATTRIBUTE <coldef> [RESTRICT|CASCADE] */
3442 : ADD_P ATTRIBUTE TableFuncElement opt_drop_behavior
3443 : {
3444 42 : AlterTableCmd *n = makeNode(AlterTableCmd);
3445 :
3446 42 : n->subtype = AT_AddColumn;
3447 42 : n->def = $3;
3448 42 : n->behavior = $4;
3449 42 : $$ = (Node *) n;
3450 : }
3451 : /* ALTER TYPE <name> DROP ATTRIBUTE IF EXISTS <attname> [RESTRICT|CASCADE] */
3452 : | DROP ATTRIBUTE IF_P EXISTS ColId opt_drop_behavior
3453 : {
3454 4 : AlterTableCmd *n = makeNode(AlterTableCmd);
3455 :
3456 4 : n->subtype = AT_DropColumn;
3457 4 : n->name = $5;
3458 4 : n->behavior = $6;
3459 4 : n->missing_ok = true;
3460 4 : $$ = (Node *) n;
3461 : }
3462 : /* ALTER TYPE <name> DROP ATTRIBUTE <attname> [RESTRICT|CASCADE] */
3463 : | DROP ATTRIBUTE ColId opt_drop_behavior
3464 : {
3465 50 : AlterTableCmd *n = makeNode(AlterTableCmd);
3466 :
3467 50 : n->subtype = AT_DropColumn;
3468 50 : n->name = $3;
3469 50 : n->behavior = $4;
3470 50 : n->missing_ok = false;
3471 50 : $$ = (Node *) n;
3472 : }
3473 : /* ALTER TYPE <name> ALTER ATTRIBUTE <attname> [SET DATA] TYPE <typename> [RESTRICT|CASCADE] */
3474 : | ALTER ATTRIBUTE ColId opt_set_data TYPE_P Typename opt_collate_clause opt_drop_behavior
3475 : {
3476 49 : AlterTableCmd *n = makeNode(AlterTableCmd);
3477 49 : ColumnDef *def = makeNode(ColumnDef);
3478 :
3479 49 : n->subtype = AT_AlterColumnType;
3480 49 : n->name = $3;
3481 49 : n->def = (Node *) def;
3482 49 : n->behavior = $8;
3483 : /* We only use these fields of the ColumnDef node */
3484 49 : def->typeName = $6;
3485 49 : def->collClause = (CollateClause *) $7;
3486 49 : def->raw_default = NULL;
3487 49 : def->location = @3;
3488 49 : $$ = (Node *) n;
3489 : }
3490 : ;
3491 :
3492 :
3493 : /*****************************************************************************
3494 : *
3495 : * QUERY :
3496 : * close <portalname>
3497 : *
3498 : *****************************************************************************/
3499 :
3500 : ClosePortalStmt:
3501 : CLOSE cursor_name
3502 : {
3503 1156 : ClosePortalStmt *n = makeNode(ClosePortalStmt);
3504 :
3505 1156 : n->portalname = $2;
3506 1156 : $$ = (Node *) n;
3507 : }
3508 : | CLOSE ALL
3509 : {
3510 8 : ClosePortalStmt *n = makeNode(ClosePortalStmt);
3511 :
3512 8 : n->portalname = NULL;
3513 8 : $$ = (Node *) n;
3514 : }
3515 : ;
3516 :
3517 :
3518 : /*****************************************************************************
3519 : *
3520 : * QUERY :
3521 : * COPY relname [(columnList)] FROM/TO file [WITH] [(options)]
3522 : * COPY ( query ) TO file [WITH] [(options)]
3523 : *
3524 : * where 'query' can be one of:
3525 : * { SELECT | UPDATE | INSERT | DELETE | MERGE }
3526 : *
3527 : * and 'file' can be one of:
3528 : * { PROGRAM 'command' | STDIN | STDOUT | 'filename' }
3529 : *
3530 : * In the preferred syntax the options are comma-separated
3531 : * and use generic identifiers instead of keywords. The pre-9.0
3532 : * syntax had a hard-wired, space-separated set of options.
3533 : *
3534 : * Really old syntax, from versions 7.2 and prior:
3535 : * COPY [ BINARY ] table FROM/TO file
3536 : * [ [ USING ] DELIMITERS 'delimiter' ] ]
3537 : * [ WITH NULL AS 'null string' ]
3538 : * This option placement is not supported with COPY (query...).
3539 : *
3540 : *****************************************************************************/
3541 :
3542 : CopyStmt: COPY opt_binary qualified_name opt_column_list
3543 : copy_from opt_program copy_file_name copy_delimiter opt_with
3544 : copy_options where_clause
3545 : {
3546 6337 : CopyStmt *n = makeNode(CopyStmt);
3547 :
3548 6337 : n->relation = $3;
3549 6337 : n->query = NULL;
3550 6337 : n->attlist = $4;
3551 6337 : n->is_from = $5;
3552 6337 : n->is_program = $6;
3553 6337 : n->filename = $7;
3554 6337 : n->whereClause = $11;
3555 :
3556 6337 : if (n->is_program && n->filename == NULL)
3557 0 : ereport(ERROR,
3558 : (errcode(ERRCODE_SYNTAX_ERROR),
3559 : errmsg("STDIN/STDOUT not allowed with PROGRAM"),
3560 : parser_errposition(@8)));
3561 :
3562 6337 : if (!n->is_from && n->whereClause != NULL)
3563 4 : ereport(ERROR,
3564 : (errcode(ERRCODE_SYNTAX_ERROR),
3565 : errmsg("WHERE clause not allowed with COPY TO"),
3566 : errhint("Try the COPY (SELECT ... WHERE ...) TO variant."),
3567 : parser_errposition(@11)));
3568 :
3569 6333 : n->options = NIL;
3570 : /* Concatenate user-supplied flags */
3571 6333 : if ($2)
3572 8 : n->options = lappend(n->options, $2);
3573 6333 : if ($8)
3574 0 : n->options = lappend(n->options, $8);
3575 6333 : if ($10)
3576 838 : n->options = list_concat(n->options, $10);
3577 6333 : $$ = (Node *) n;
3578 : }
3579 : | COPY '(' PreparableStmt ')' TO opt_program copy_file_name opt_with copy_options
3580 : {
3581 355 : CopyStmt *n = makeNode(CopyStmt);
3582 :
3583 355 : n->relation = NULL;
3584 355 : n->query = $3;
3585 355 : n->attlist = NIL;
3586 355 : n->is_from = false;
3587 355 : n->is_program = $6;
3588 355 : n->filename = $7;
3589 355 : n->options = $9;
3590 :
3591 355 : if (n->is_program && n->filename == NULL)
3592 0 : ereport(ERROR,
3593 : (errcode(ERRCODE_SYNTAX_ERROR),
3594 : errmsg("STDIN/STDOUT not allowed with PROGRAM"),
3595 : parser_errposition(@5)));
3596 :
3597 355 : $$ = (Node *) n;
3598 : }
3599 : ;
3600 :
3601 : copy_from:
3602 1225 : FROM { $$ = true; }
3603 5112 : | TO { $$ = false; }
3604 : ;
3605 :
3606 : opt_program:
3607 0 : PROGRAM { $$ = true; }
3608 6692 : | /* EMPTY */ { $$ = false; }
3609 : ;
3610 :
3611 : /*
3612 : * copy_file_name NULL indicates stdio is used. Whether stdin or stdout is
3613 : * used depends on the direction. (It really doesn't make sense to copy from
3614 : * stdout. We silently correct the "typo".) - AY 9/94
3615 : */
3616 : copy_file_name:
3617 302 : Sconst { $$ = $1; }
3618 973 : | STDIN { $$ = NULL; }
3619 5417 : | STDOUT { $$ = NULL; }
3620 : ;
3621 :
3622 6007 : copy_options: copy_opt_list { $$ = $1; }
3623 685 : | '(' copy_generic_opt_list ')' { $$ = $2; }
3624 : ;
3625 :
3626 : /* old COPY option syntax */
3627 : copy_opt_list:
3628 345 : copy_opt_list copy_opt_item { $$ = lappend($1, $2); }
3629 6007 : | /* EMPTY */ { $$ = NIL; }
3630 : ;
3631 :
3632 : copy_opt_item:
3633 : BINARY
3634 : {
3635 0 : $$ = makeDefElem("format", (Node *) makeString("binary"), @1);
3636 : }
3637 : | FREEZE
3638 : {
3639 32 : $$ = makeDefElem("freeze", (Node *) makeBoolean(true), @1);
3640 : }
3641 : | DELIMITER opt_as Sconst
3642 : {
3643 117 : $$ = makeDefElem("delimiter", (Node *) makeString($3), @1);
3644 : }
3645 : | NULL_P opt_as Sconst
3646 : {
3647 32 : $$ = makeDefElem("null", (Node *) makeString($3), @1);
3648 : }
3649 : | CSV
3650 : {
3651 100 : $$ = makeDefElem("format", (Node *) makeString("csv"), @1);
3652 : }
3653 : | JSON
3654 : {
3655 8 : $$ = makeDefElem("format", (Node *) makeString("json"), @1);
3656 : }
3657 : | HEADER_P
3658 : {
3659 12 : $$ = makeDefElem("header", (Node *) makeBoolean(true), @1);
3660 : }
3661 : | QUOTE opt_as Sconst
3662 : {
3663 12 : $$ = makeDefElem("quote", (Node *) makeString($3), @1);
3664 : }
3665 : | ESCAPE opt_as Sconst
3666 : {
3667 12 : $$ = makeDefElem("escape", (Node *) makeString($3), @1);
3668 : }
3669 : | FORCE QUOTE columnList
3670 : {
3671 8 : $$ = makeDefElem("force_quote", (Node *) $3, @1);
3672 : }
3673 : | FORCE QUOTE '*'
3674 : {
3675 4 : $$ = makeDefElem("force_quote", (Node *) makeNode(A_Star), @1);
3676 : }
3677 : | FORCE NOT NULL_P columnList
3678 : {
3679 0 : $$ = makeDefElem("force_not_null", (Node *) $4, @1);
3680 : }
3681 : | FORCE NOT NULL_P '*'
3682 : {
3683 0 : $$ = makeDefElem("force_not_null", (Node *) makeNode(A_Star), @1);
3684 : }
3685 : | FORCE NULL_P columnList
3686 : {
3687 0 : $$ = makeDefElem("force_null", (Node *) $3, @1);
3688 : }
3689 : | FORCE NULL_P '*'
3690 : {
3691 0 : $$ = makeDefElem("force_null", (Node *) makeNode(A_Star), @1);
3692 : }
3693 : | ENCODING Sconst
3694 : {
3695 8 : $$ = makeDefElem("encoding", (Node *) makeString($2), @1);
3696 : }
3697 : ;
3698 :
3699 : /* The following exist for backward compatibility with very old versions */
3700 :
3701 : opt_binary:
3702 : BINARY
3703 : {
3704 8 : $$ = makeDefElem("format", (Node *) makeString("binary"), @1);
3705 : }
3706 6329 : | /*EMPTY*/ { $$ = NULL; }
3707 : ;
3708 :
3709 : copy_delimiter:
3710 : opt_using DELIMITERS Sconst
3711 : {
3712 0 : $$ = makeDefElem("delimiter", (Node *) makeString($3), @2);
3713 : }
3714 6337 : | /*EMPTY*/ { $$ = NULL; }
3715 : ;
3716 :
3717 : opt_using:
3718 : USING
3719 : | /*EMPTY*/
3720 : ;
3721 :
3722 : /* new COPY option syntax */
3723 : copy_generic_opt_list:
3724 : copy_generic_opt_elem
3725 : {
3726 685 : $$ = list_make1($1);
3727 : }
3728 : | copy_generic_opt_list ',' copy_generic_opt_elem
3729 : {
3730 435 : $$ = lappend($1, $3);
3731 : }
3732 : ;
3733 :
3734 : copy_generic_opt_elem:
3735 : ColLabel copy_generic_opt_arg
3736 : {
3737 992 : $$ = makeDefElem($1, $2, @1);
3738 : }
3739 : | FORMAT_LA copy_generic_opt_arg
3740 : {
3741 128 : $$ = makeDefElem("format", $2, @1);
3742 : }
3743 : ;
3744 :
3745 : copy_generic_opt_arg:
3746 848 : opt_boolean_or_string { $$ = (Node *) makeString($1); }
3747 52 : | NumericOnly { $$ = (Node *) $1; }
3748 72 : | '*' { $$ = (Node *) makeNode(A_Star); }
3749 4 : | DEFAULT { $$ = (Node *) makeString("default"); }
3750 100 : | '(' copy_generic_opt_arg_list ')' { $$ = (Node *) $2; }
3751 44 : | /* EMPTY */ { $$ = NULL; }
3752 : ;
3753 :
3754 : copy_generic_opt_arg_list:
3755 : copy_generic_opt_arg_list_item
3756 : {
3757 100 : $$ = list_make1($1);
3758 : }
3759 : | copy_generic_opt_arg_list ',' copy_generic_opt_arg_list_item
3760 : {
3761 8 : $$ = lappend($1, $3);
3762 : }
3763 : ;
3764 :
3765 : /* beware of emitting non-string list elements here; see commands/define.c */
3766 : copy_generic_opt_arg_list_item:
3767 108 : opt_boolean_or_string { $$ = (Node *) makeString($1); }
3768 : ;
3769 :
3770 :
3771 : /*****************************************************************************
3772 : *
3773 : * QUERY :
3774 : * CREATE TABLE relname
3775 : *
3776 : *****************************************************************************/
3777 :
3778 : CreateStmt: CREATE OptTemp TABLE qualified_name '(' OptTableElementList ')'
3779 : OptInherit OptPartitionSpec table_access_method_clause OptWith
3780 : OnCommitOption OptTableSpace
3781 : {
3782 19095 : CreateStmt *n = makeNode(CreateStmt);
3783 :
3784 19095 : $4->relpersistence = $2;
3785 19095 : n->relation = $4;
3786 19095 : n->tableElts = $6;
3787 19095 : n->inhRelations = $8;
3788 19095 : n->partspec = $9;
3789 19095 : n->ofTypename = NULL;
3790 19095 : n->constraints = NIL;
3791 19095 : n->accessMethod = $10;
3792 19095 : n->options = $11;
3793 19095 : n->oncommit = $12;
3794 19095 : n->tablespacename = $13;
3795 19095 : n->if_not_exists = false;
3796 19095 : $$ = (Node *) n;
3797 : }
3798 : | CREATE OptTemp TABLE IF_P NOT EXISTS qualified_name '('
3799 : OptTableElementList ')' OptInherit OptPartitionSpec table_access_method_clause
3800 : OptWith OnCommitOption OptTableSpace
3801 : {
3802 16 : CreateStmt *n = makeNode(CreateStmt);
3803 :
3804 16 : $7->relpersistence = $2;
3805 16 : n->relation = $7;
3806 16 : n->tableElts = $9;
3807 16 : n->inhRelations = $11;
3808 16 : n->partspec = $12;
3809 16 : n->ofTypename = NULL;
3810 16 : n->constraints = NIL;
3811 16 : n->accessMethod = $13;
3812 16 : n->options = $14;
3813 16 : n->oncommit = $15;
3814 16 : n->tablespacename = $16;
3815 16 : n->if_not_exists = true;
3816 16 : $$ = (Node *) n;
3817 : }
3818 : | CREATE OptTemp TABLE qualified_name OF any_name
3819 : OptTypedTableElementList OptPartitionSpec table_access_method_clause
3820 : OptWith OnCommitOption OptTableSpace
3821 : {
3822 81 : CreateStmt *n = makeNode(CreateStmt);
3823 :
3824 81 : $4->relpersistence = $2;
3825 81 : n->relation = $4;
3826 81 : n->tableElts = $7;
3827 81 : n->inhRelations = NIL;
3828 81 : n->partspec = $8;
3829 81 : n->ofTypename = makeTypeNameFromNameList($6);
3830 81 : n->ofTypename->location = @6;
3831 81 : n->constraints = NIL;
3832 81 : n->accessMethod = $9;
3833 81 : n->options = $10;
3834 81 : n->oncommit = $11;
3835 81 : n->tablespacename = $12;
3836 81 : n->if_not_exists = false;
3837 81 : $$ = (Node *) n;
3838 : }
3839 : | CREATE OptTemp TABLE IF_P NOT EXISTS qualified_name OF any_name
3840 : OptTypedTableElementList OptPartitionSpec table_access_method_clause
3841 : OptWith OnCommitOption OptTableSpace
3842 : {
3843 4 : CreateStmt *n = makeNode(CreateStmt);
3844 :
3845 4 : $7->relpersistence = $2;
3846 4 : n->relation = $7;
3847 4 : n->tableElts = $10;
3848 4 : n->inhRelations = NIL;
3849 4 : n->partspec = $11;
3850 4 : n->ofTypename = makeTypeNameFromNameList($9);
3851 4 : n->ofTypename->location = @9;
3852 4 : n->constraints = NIL;
3853 4 : n->accessMethod = $12;
3854 4 : n->options = $13;
3855 4 : n->oncommit = $14;
3856 4 : n->tablespacename = $15;
3857 4 : n->if_not_exists = true;
3858 4 : $$ = (Node *) n;
3859 : }
3860 : | CREATE OptTemp TABLE qualified_name PARTITION OF qualified_name
3861 : OptTypedTableElementList PartitionBoundSpec OptPartitionSpec
3862 : table_access_method_clause OptWith OnCommitOption OptTableSpace
3863 : {
3864 5810 : CreateStmt *n = makeNode(CreateStmt);
3865 :
3866 5810 : $4->relpersistence = $2;
3867 5810 : n->relation = $4;
3868 5810 : n->tableElts = $8;
3869 5810 : n->inhRelations = list_make1($7);
3870 5810 : n->partbound = $9;
3871 5810 : n->partspec = $10;
3872 5810 : n->ofTypename = NULL;
3873 5810 : n->constraints = NIL;
3874 5810 : n->accessMethod = $11;
3875 5810 : n->options = $12;
3876 5810 : n->oncommit = $13;
3877 5810 : n->tablespacename = $14;
3878 5810 : n->if_not_exists = false;
3879 5810 : $$ = (Node *) n;
3880 : }
3881 : | CREATE OptTemp TABLE IF_P NOT EXISTS qualified_name PARTITION OF
3882 : qualified_name OptTypedTableElementList PartitionBoundSpec OptPartitionSpec
3883 : table_access_method_clause OptWith OnCommitOption OptTableSpace
3884 : {
3885 0 : CreateStmt *n = makeNode(CreateStmt);
3886 :
3887 0 : $7->relpersistence = $2;
3888 0 : n->relation = $7;
3889 0 : n->tableElts = $11;
3890 0 : n->inhRelations = list_make1($10);
3891 0 : n->partbound = $12;
3892 0 : n->partspec = $13;
3893 0 : n->ofTypename = NULL;
3894 0 : n->constraints = NIL;
3895 0 : n->accessMethod = $14;
3896 0 : n->options = $15;
3897 0 : n->oncommit = $16;
3898 0 : n->tablespacename = $17;
3899 0 : n->if_not_exists = true;
3900 0 : $$ = (Node *) n;
3901 : }
3902 : ;
3903 :
3904 : /*
3905 : * Redundancy here is needed to avoid shift/reduce conflicts,
3906 : * since TEMP is not a reserved word. See also OptTempTableName.
3907 : *
3908 : * NOTE: we accept both GLOBAL and LOCAL options. They currently do nothing,
3909 : * but future versions might consider GLOBAL to request SQL-spec-compliant
3910 : * temp table behavior, so warn about that. Since we have no modules the
3911 : * LOCAL keyword is really meaningless; furthermore, some other products
3912 : * implement LOCAL as meaning the same as our default temp table behavior,
3913 : * so we'll probably continue to treat LOCAL as a noise word.
3914 : */
3915 231 : OptTemp: TEMPORARY { $$ = RELPERSISTENCE_TEMP; }
3916 1977 : | TEMP { $$ = RELPERSISTENCE_TEMP; }
3917 0 : | LOCAL TEMPORARY { $$ = RELPERSISTENCE_TEMP; }
3918 0 : | LOCAL TEMP { $$ = RELPERSISTENCE_TEMP; }
3919 : | GLOBAL TEMPORARY
3920 : {
3921 0 : ereport(WARNING,
3922 : (errmsg("GLOBAL is deprecated in temporary table creation"),
3923 : parser_errposition(@1)));
3924 0 : $$ = RELPERSISTENCE_TEMP;
3925 : }
3926 : | GLOBAL TEMP
3927 : {
3928 0 : ereport(WARNING,
3929 : (errmsg("GLOBAL is deprecated in temporary table creation"),
3930 : parser_errposition(@1)));
3931 0 : $$ = RELPERSISTENCE_TEMP;
3932 : }
3933 105 : | UNLOGGED { $$ = RELPERSISTENCE_UNLOGGED; }
3934 34096 : | /*EMPTY*/ { $$ = RELPERSISTENCE_PERMANENT; }
3935 : ;
3936 :
3937 : OptTableElementList:
3938 18342 : TableElementList { $$ = $1; }
3939 1035 : | /*EMPTY*/ { $$ = NIL; }
3940 : ;
3941 :
3942 : OptTypedTableElementList:
3943 217 : '(' TypedTableElementList ')' { $$ = $2; }
3944 5735 : | /*EMPTY*/ { $$ = NIL; }
3945 : ;
3946 :
3947 : TableElementList:
3948 : TableElement
3949 : {
3950 18378 : $$ = list_make1($1);
3951 : }
3952 : | TableElementList ',' TableElement
3953 : {
3954 26096 : $$ = lappend($1, $3);
3955 : }
3956 : ;
3957 :
3958 : TypedTableElementList:
3959 : TypedTableElement
3960 : {
3961 217 : $$ = list_make1($1);
3962 : }
3963 : | TypedTableElementList ',' TypedTableElement
3964 : {
3965 45 : $$ = lappend($1, $3);
3966 : }
3967 : ;
3968 :
3969 : TableElement:
3970 42159 : columnDef { $$ = $1; }
3971 516 : | TableLikeClause { $$ = $1; }
3972 1799 : | TableConstraint { $$ = $1; }
3973 : ;
3974 :
3975 : TypedTableElement:
3976 220 : columnOptions { $$ = $1; }
3977 42 : | TableConstraint { $$ = $1; }
3978 : ;
3979 :
3980 : columnDef: ColId Typename opt_column_storage opt_column_compression create_generic_options ColQualList
3981 : {
3982 43717 : ColumnDef *n = makeNode(ColumnDef);
3983 :
3984 43717 : n->colname = $1;
3985 43717 : n->typeName = $2;
3986 43717 : n->storage_name = $3;
3987 43717 : n->compression = $4;
3988 43717 : n->inhcount = 0;
3989 43717 : n->is_local = true;
3990 43717 : n->is_not_null = false;
3991 43717 : n->is_from_type = false;
3992 43717 : n->storage = 0;
3993 43717 : n->raw_default = NULL;
3994 43717 : n->cooked_default = NULL;
3995 43717 : n->collOid = InvalidOid;
3996 43717 : n->fdwoptions = $5;
3997 43717 : SplitColQualList($6, &n->constraints, &n->collClause,
3998 : yyscanner);
3999 43717 : n->location = @1;
4000 43717 : $$ = (Node *) n;
4001 : }
4002 : ;
4003 :
4004 : columnOptions: ColId ColQualList
4005 : {
4006 91 : ColumnDef *n = makeNode(ColumnDef);
4007 :
4008 91 : n->colname = $1;
4009 91 : n->typeName = NULL;
4010 91 : n->inhcount = 0;
4011 91 : n->is_local = true;
4012 91 : n->is_not_null = false;
4013 91 : n->is_from_type = false;
4014 91 : n->storage = 0;
4015 91 : n->raw_default = NULL;
4016 91 : n->cooked_default = NULL;
4017 91 : n->collOid = InvalidOid;
4018 91 : SplitColQualList($2, &n->constraints, &n->collClause,
4019 : yyscanner);
4020 91 : n->location = @1;
4021 91 : $$ = (Node *) n;
4022 : }
4023 : | ColId WITH OPTIONS ColQualList
4024 : {
4025 129 : ColumnDef *n = makeNode(ColumnDef);
4026 :
4027 129 : n->colname = $1;
4028 129 : n->typeName = NULL;
4029 129 : n->inhcount = 0;
4030 129 : n->is_local = true;
4031 129 : n->is_not_null = false;
4032 129 : n->is_from_type = false;
4033 129 : n->storage = 0;
4034 129 : n->raw_default = NULL;
4035 129 : n->cooked_default = NULL;
4036 129 : n->collOid = InvalidOid;
4037 129 : SplitColQualList($4, &n->constraints, &n->collClause,
4038 : yyscanner);
4039 129 : n->location = @1;
4040 129 : $$ = (Node *) n;
4041 : }
4042 : ;
4043 :
4044 : column_compression:
4045 113 : COMPRESSION ColId { $$ = $2; }
4046 4 : | COMPRESSION DEFAULT { $$ = pstrdup("default"); }
4047 : ;
4048 :
4049 : opt_column_compression:
4050 70 : column_compression { $$ = $1; }
4051 43691 : | /*EMPTY*/ { $$ = NULL; }
4052 : ;
4053 :
4054 : column_storage:
4055 194 : STORAGE ColId { $$ = $2; }
4056 4 : | STORAGE DEFAULT { $$ = pstrdup("default"); }
4057 : ;
4058 :
4059 : opt_column_storage:
4060 39 : column_storage { $$ = $1; }
4061 43722 : | /*EMPTY*/ { $$ = NULL; }
4062 : ;
4063 :
4064 : ColQualList:
4065 12578 : ColQualList ColConstraint { $$ = lappend($1, $2); }
4066 44919 : | /*EMPTY*/ { $$ = NIL; }
4067 : ;
4068 :
4069 : ColConstraint:
4070 : CONSTRAINT name ColConstraintElem
4071 : {
4072 485 : Constraint *n = castNode(Constraint, $3);
4073 :
4074 485 : n->conname = $2;
4075 485 : n->location = @1;
4076 485 : $$ = (Node *) n;
4077 : }
4078 11409 : | ColConstraintElem { $$ = $1; }
4079 198 : | ConstraintAttr { $$ = $1; }
4080 : | COLLATE any_name
4081 : {
4082 : /*
4083 : * Note: the CollateClause is momentarily included in
4084 : * the list built by ColQualList, but we split it out
4085 : * again in SplitColQualList.
4086 : */
4087 486 : CollateClause *n = makeNode(CollateClause);
4088 :
4089 486 : n->arg = NULL;
4090 486 : n->collname = $2;
4091 486 : n->location = @1;
4092 486 : $$ = (Node *) n;
4093 : }
4094 : ;
4095 :
4096 : /* DEFAULT NULL is already the default for Postgres.
4097 : * But define it here and carry it forward into the system
4098 : * to make it explicit.
4099 : * - thomas 1998-09-13
4100 : *
4101 : * WITH NULL and NULL are not SQL-standard syntax elements,
4102 : * so leave them out. Use DEFAULT NULL to explicitly indicate
4103 : * that a column may have that value. WITH NULL leads to
4104 : * shift/reduce conflicts with WITH TIME ZONE anyway.
4105 : * - thomas 1999-01-08
4106 : *
4107 : * DEFAULT expression must be b_expr not a_expr to prevent shift/reduce
4108 : * conflict on NOT (since NOT might start a subsequent NOT NULL constraint,
4109 : * or be part of a_expr NOT LIKE or similar constructs).
4110 : */
4111 : ColConstraintElem:
4112 : NOT NULL_P opt_no_inherit
4113 : {
4114 3995 : Constraint *n = makeNode(Constraint);
4115 :
4116 3995 : n->contype = CONSTR_NOTNULL;
4117 3995 : n->location = @1;
4118 3995 : n->is_no_inherit = $3;
4119 3995 : n->is_enforced = true;
4120 3995 : n->skip_validation = false;
4121 3995 : n->initially_valid = true;
4122 3995 : $$ = (Node *) n;
4123 : }
4124 : | NULL_P
4125 : {
4126 19 : Constraint *n = makeNode(Constraint);
4127 :
4128 19 : n->contype = CONSTR_NULL;
4129 19 : n->location = @1;
4130 19 : $$ = (Node *) n;
4131 : }
4132 : | UNIQUE opt_unique_null_treatment opt_definition OptConsTableSpace
4133 : {
4134 302 : Constraint *n = makeNode(Constraint);
4135 :
4136 302 : n->contype = CONSTR_UNIQUE;
4137 302 : n->location = @1;
4138 302 : n->nulls_not_distinct = !$2;
4139 302 : n->keys = NULL;
4140 302 : n->options = $3;
4141 302 : n->indexname = NULL;
4142 302 : n->indexspace = $4;
4143 302 : $$ = (Node *) n;
4144 : }
4145 : | PRIMARY KEY opt_definition OptConsTableSpace
4146 : {
4147 3554 : Constraint *n = makeNode(Constraint);
4148 :
4149 3554 : n->contype = CONSTR_PRIMARY;
4150 3554 : n->location = @1;
4151 3554 : n->keys = NULL;
4152 3554 : n->options = $3;
4153 3554 : n->indexname = NULL;
4154 3554 : n->indexspace = $4;
4155 3554 : $$ = (Node *) n;
4156 : }
4157 : | CHECK '(' a_expr ')' opt_no_inherit
4158 : {
4159 735 : Constraint *n = makeNode(Constraint);
4160 :
4161 735 : n->contype = CONSTR_CHECK;
4162 735 : n->location = @1;
4163 735 : n->is_no_inherit = $5;
4164 735 : n->raw_expr = $3;
4165 735 : n->cooked_expr = NULL;
4166 735 : n->is_enforced = true;
4167 735 : n->skip_validation = false;
4168 735 : n->initially_valid = true;
4169 735 : $$ = (Node *) n;
4170 : }
4171 : | DEFAULT b_expr
4172 : {
4173 1228 : Constraint *n = makeNode(Constraint);
4174 :
4175 1228 : n->contype = CONSTR_DEFAULT;
4176 1228 : n->location = @1;
4177 1228 : n->raw_expr = $2;
4178 1228 : n->cooked_expr = NULL;
4179 1228 : $$ = (Node *) n;
4180 : }
4181 : | GENERATED generated_when AS IDENTITY_P OptParenthesizedSeqOptList
4182 : {
4183 248 : Constraint *n = makeNode(Constraint);
4184 :
4185 248 : n->contype = CONSTR_IDENTITY;
4186 248 : n->generated_when = $2;
4187 248 : n->options = $5;
4188 248 : n->location = @1;
4189 248 : $$ = (Node *) n;
4190 : }
4191 : | GENERATED generated_when AS '(' a_expr ')' opt_virtual_or_stored
4192 : {
4193 1241 : Constraint *n = makeNode(Constraint);
4194 :
4195 1241 : n->contype = CONSTR_GENERATED;
4196 1241 : n->generated_when = $2;
4197 1241 : n->raw_expr = $5;
4198 1241 : n->cooked_expr = NULL;
4199 1241 : n->generated_kind = $7;
4200 1241 : n->location = @1;
4201 :
4202 : /*
4203 : * Can't do this in the grammar because of shift/reduce
4204 : * conflicts. (IDENTITY allows both ALWAYS and BY
4205 : * DEFAULT, but generated columns only allow ALWAYS.) We
4206 : * can also give a more useful error message and location.
4207 : */
4208 1241 : if ($2 != ATTRIBUTE_IDENTITY_ALWAYS)
4209 8 : ereport(ERROR,
4210 : (errcode(ERRCODE_SYNTAX_ERROR),
4211 : errmsg("for a generated column, GENERATED ALWAYS must be specified"),
4212 : parser_errposition(@2)));
4213 :
4214 1233 : $$ = (Node *) n;
4215 : }
4216 : | REFERENCES qualified_name opt_column_list key_match key_actions
4217 : {
4218 580 : Constraint *n = makeNode(Constraint);
4219 :
4220 580 : n->contype = CONSTR_FOREIGN;
4221 580 : n->location = @1;
4222 580 : n->pktable = $2;
4223 580 : n->fk_attrs = NIL;
4224 580 : n->pk_attrs = $3;
4225 580 : n->fk_matchtype = $4;
4226 580 : n->fk_upd_action = ($5)->updateAction->action;
4227 580 : n->fk_del_action = ($5)->deleteAction->action;
4228 580 : n->fk_del_set_cols = ($5)->deleteAction->cols;
4229 580 : n->is_enforced = true;
4230 580 : n->skip_validation = false;
4231 580 : n->initially_valid = true;
4232 580 : $$ = (Node *) n;
4233 : }
4234 : ;
4235 :
4236 : opt_unique_null_treatment:
4237 8 : NULLS_P DISTINCT { $$ = true; }
4238 24 : | NULLS_P NOT DISTINCT { $$ = false; }
4239 5048 : | /*EMPTY*/ { $$ = true; }
4240 : ;
4241 :
4242 : generated_when:
4243 1507 : ALWAYS { $$ = ATTRIBUTE_IDENTITY_ALWAYS; }
4244 118 : | BY DEFAULT { $$ = ATTRIBUTE_IDENTITY_BY_DEFAULT; }
4245 : ;
4246 :
4247 : opt_virtual_or_stored:
4248 652 : STORED { $$ = ATTRIBUTE_GENERATED_STORED; }
4249 439 : | VIRTUAL { $$ = ATTRIBUTE_GENERATED_VIRTUAL; }
4250 150 : | /*EMPTY*/ { $$ = ATTRIBUTE_GENERATED_VIRTUAL; }
4251 : ;
4252 :
4253 : /*
4254 : * ConstraintAttr represents constraint attributes, which we parse as if
4255 : * they were independent constraint clauses, in order to avoid shift/reduce
4256 : * conflicts (since NOT might start either an independent NOT NULL clause
4257 : * or an attribute). parse_utilcmd.c is responsible for attaching the
4258 : * attribute information to the preceding "real" constraint node, and for
4259 : * complaining if attribute clauses appear in the wrong place or wrong
4260 : * combinations.
4261 : *
4262 : * See also ConstraintAttributeSpec, which can be used in places where
4263 : * there is no parsing conflict. (Note: currently, NOT VALID and NO INHERIT
4264 : * are allowed clauses in ConstraintAttributeSpec, but not here. Someday we
4265 : * might need to allow them here too, but for the moment it doesn't seem
4266 : * useful in the statements that use ConstraintAttr.)
4267 : */
4268 : ConstraintAttr:
4269 : DEFERRABLE
4270 : {
4271 66 : Constraint *n = makeNode(Constraint);
4272 :
4273 66 : n->contype = CONSTR_ATTR_DEFERRABLE;
4274 66 : n->location = @1;
4275 66 : $$ = (Node *) n;
4276 : }
4277 : | NOT DEFERRABLE
4278 : {
4279 0 : Constraint *n = makeNode(Constraint);
4280 :
4281 0 : n->contype = CONSTR_ATTR_NOT_DEFERRABLE;
4282 0 : n->location = @1;
4283 0 : $$ = (Node *) n;
4284 : }
4285 : | INITIALLY DEFERRED
4286 : {
4287 48 : Constraint *n = makeNode(Constraint);
4288 :
4289 48 : n->contype = CONSTR_ATTR_DEFERRED;
4290 48 : n->location = @1;
4291 48 : $$ = (Node *) n;
4292 : }
4293 : | INITIALLY IMMEDIATE
4294 : {
4295 4 : Constraint *n = makeNode(Constraint);
4296 :
4297 4 : n->contype = CONSTR_ATTR_IMMEDIATE;
4298 4 : n->location = @1;
4299 4 : $$ = (Node *) n;
4300 : }
4301 : | ENFORCED
4302 : {
4303 28 : Constraint *n = makeNode(Constraint);
4304 :
4305 28 : n->contype = CONSTR_ATTR_ENFORCED;
4306 28 : n->location = @1;
4307 28 : $$ = (Node *) n;
4308 : }
4309 : | NOT ENFORCED
4310 : {
4311 52 : Constraint *n = makeNode(Constraint);
4312 :
4313 52 : n->contype = CONSTR_ATTR_NOT_ENFORCED;
4314 52 : n->location = @1;
4315 52 : $$ = (Node *) n;
4316 : }
4317 : ;
4318 :
4319 :
4320 : TableLikeClause:
4321 : LIKE qualified_name TableLikeOptionList
4322 : {
4323 516 : TableLikeClause *n = makeNode(TableLikeClause);
4324 :
4325 516 : n->relation = $2;
4326 516 : n->options = $3;
4327 516 : n->relationOid = InvalidOid;
4328 516 : $$ = (Node *) n;
4329 : }
4330 : ;
4331 :
4332 : TableLikeOptionList:
4333 191 : TableLikeOptionList INCLUDING TableLikeOption { $$ = $1 | $3; }
4334 5 : | TableLikeOptionList EXCLUDING TableLikeOption { $$ = $1 & ~$3; }
4335 516 : | /* EMPTY */ { $$ = 0; }
4336 : ;
4337 :
4338 : TableLikeOption:
4339 20 : COMMENTS { $$ = CREATE_TABLE_LIKE_COMMENTS; }
4340 4 : | COMPRESSION { $$ = CREATE_TABLE_LIKE_COMPRESSION; }
4341 36 : | CONSTRAINTS { $$ = CREATE_TABLE_LIKE_CONSTRAINTS; }
4342 13 : | DEFAULTS { $$ = CREATE_TABLE_LIKE_DEFAULTS; }
4343 8 : | IDENTITY_P { $$ = CREATE_TABLE_LIKE_IDENTITY; }
4344 20 : | GENERATED { $$ = CREATE_TABLE_LIKE_GENERATED; }
4345 33 : | INDEXES { $$ = CREATE_TABLE_LIKE_INDEXES; }
4346 0 : | STATISTICS { $$ = CREATE_TABLE_LIKE_STATISTICS; }
4347 17 : | STORAGE { $$ = CREATE_TABLE_LIKE_STORAGE; }
4348 45 : | ALL { $$ = CREATE_TABLE_LIKE_ALL; }
4349 : ;
4350 :
4351 :
4352 : /* ConstraintElem specifies constraint syntax which is not embedded into
4353 : * a column definition. ColConstraintElem specifies the embedded form.
4354 : * - thomas 1997-12-03
4355 : */
4356 : TableConstraint:
4357 : CONSTRAINT name ConstraintElem
4358 : {
4359 2732 : Constraint *n = castNode(Constraint, $3);
4360 :
4361 2732 : n->conname = $2;
4362 2732 : n->location = @1;
4363 2732 : $$ = (Node *) n;
4364 : }
4365 7653 : | ConstraintElem { $$ = $1; }
4366 : ;
4367 :
4368 : ConstraintElem:
4369 : CHECK '(' a_expr ')' ConstraintAttributeSpec
4370 : {
4371 917 : Constraint *n = makeNode(Constraint);
4372 :
4373 917 : n->contype = CONSTR_CHECK;
4374 917 : n->location = @1;
4375 917 : n->raw_expr = $3;
4376 917 : n->cooked_expr = NULL;
4377 917 : processCASbits($5, @5, "CHECK",
4378 : NULL, NULL, &n->is_enforced, &n->skip_validation,
4379 : &n->is_no_inherit, yyscanner);
4380 917 : n->initially_valid = !n->skip_validation;
4381 917 : $$ = (Node *) n;
4382 : }
4383 : | NOT NULL_P ColId ConstraintAttributeSpec
4384 : {
4385 417 : Constraint *n = makeNode(Constraint);
4386 :
4387 417 : n->contype = CONSTR_NOTNULL;
4388 417 : n->location = @1;
4389 417 : n->keys = list_make1(makeString($3));
4390 417 : processCASbits($4, @4, "NOT NULL",
4391 : NULL, NULL, NULL, &n->skip_validation,
4392 : &n->is_no_inherit, yyscanner);
4393 417 : n->initially_valid = !n->skip_validation;
4394 417 : $$ = (Node *) n;
4395 : }
4396 : | UNIQUE opt_unique_null_treatment '(' columnList opt_without_overlaps ')' opt_c_include opt_definition OptConsTableSpace
4397 : ConstraintAttributeSpec
4398 : {
4399 398 : Constraint *n = makeNode(Constraint);
4400 :
4401 398 : n->contype = CONSTR_UNIQUE;
4402 398 : n->location = @1;
4403 398 : n->nulls_not_distinct = !$2;
4404 398 : n->keys = $4;
4405 398 : n->without_overlaps = $5;
4406 398 : n->including = $7;
4407 398 : n->options = $8;
4408 398 : n->indexname = NULL;
4409 398 : n->indexspace = $9;
4410 398 : processCASbits($10, @10, "UNIQUE",
4411 : &n->deferrable, &n->initdeferred, NULL,
4412 : NULL, NULL, yyscanner);
4413 398 : $$ = (Node *) n;
4414 : }
4415 : | UNIQUE ExistingIndex ConstraintAttributeSpec
4416 : {
4417 2623 : Constraint *n = makeNode(Constraint);
4418 :
4419 2623 : n->contype = CONSTR_UNIQUE;
4420 2623 : n->location = @1;
4421 2623 : n->keys = NIL;
4422 2623 : n->including = NIL;
4423 2623 : n->options = NIL;
4424 2623 : n->indexname = $2;
4425 2623 : n->indexspace = NULL;
4426 2623 : processCASbits($3, @3, "UNIQUE",
4427 : &n->deferrable, &n->initdeferred, NULL,
4428 : NULL, NULL, yyscanner);
4429 2623 : $$ = (Node *) n;
4430 : }
4431 : | PRIMARY KEY '(' columnList opt_without_overlaps ')' opt_c_include opt_definition OptConsTableSpace
4432 : ConstraintAttributeSpec
4433 : {
4434 1375 : Constraint *n = makeNode(Constraint);
4435 :
4436 1375 : n->contype = CONSTR_PRIMARY;
4437 1375 : n->location = @1;
4438 1375 : n->keys = $4;
4439 1375 : n->without_overlaps = $5;
4440 1375 : n->including = $7;
4441 1375 : n->options = $8;
4442 1375 : n->indexname = NULL;
4443 1375 : n->indexspace = $9;
4444 1375 : processCASbits($10, @10, "PRIMARY KEY",
4445 : &n->deferrable, &n->initdeferred, NULL,
4446 : NULL, NULL, yyscanner);
4447 1375 : $$ = (Node *) n;
4448 : }
4449 : | PRIMARY KEY ExistingIndex ConstraintAttributeSpec
4450 : {
4451 3327 : Constraint *n = makeNode(Constraint);
4452 :
4453 3327 : n->contype = CONSTR_PRIMARY;
4454 3327 : n->location = @1;
4455 3327 : n->keys = NIL;
4456 3327 : n->including = NIL;
4457 3327 : n->options = NIL;
4458 3327 : n->indexname = $3;
4459 3327 : n->indexspace = NULL;
4460 3327 : processCASbits($4, @4, "PRIMARY KEY",
4461 : &n->deferrable, &n->initdeferred, NULL,
4462 : NULL, NULL, yyscanner);
4463 3327 : $$ = (Node *) n;
4464 : }
4465 : | EXCLUDE access_method_clause '(' ExclusionConstraintList ')'
4466 : opt_c_include opt_definition OptConsTableSpace OptWhereClause
4467 : ConstraintAttributeSpec
4468 : {
4469 153 : Constraint *n = makeNode(Constraint);
4470 :
4471 153 : n->contype = CONSTR_EXCLUSION;
4472 153 : n->location = @1;
4473 153 : n->access_method = $2;
4474 153 : n->exclusions = $4;
4475 153 : n->including = $6;
4476 153 : n->options = $7;
4477 153 : n->indexname = NULL;
4478 153 : n->indexspace = $8;
4479 153 : n->where_clause = $9;
4480 153 : processCASbits($10, @10, "EXCLUDE",
4481 : &n->deferrable, &n->initdeferred, NULL,
4482 : NULL, NULL, yyscanner);
4483 153 : $$ = (Node *) n;
4484 : }
4485 : | FOREIGN KEY '(' columnList optionalPeriodName ')' REFERENCES qualified_name
4486 : opt_column_and_period_list key_match key_actions ConstraintAttributeSpec
4487 : {
4488 1175 : Constraint *n = makeNode(Constraint);
4489 :
4490 1175 : n->contype = CONSTR_FOREIGN;
4491 1175 : n->location = @1;
4492 1175 : n->pktable = $8;
4493 1175 : n->fk_attrs = $4;
4494 1175 : if ($5)
4495 : {
4496 210 : n->fk_attrs = lappend(n->fk_attrs, $5);
4497 210 : n->fk_with_period = true;
4498 : }
4499 1175 : n->pk_attrs = linitial($9);
4500 1175 : if (lsecond($9))
4501 : {
4502 112 : n->pk_attrs = lappend(n->pk_attrs, lsecond($9));
4503 112 : n->pk_with_period = true;
4504 : }
4505 1175 : n->fk_matchtype = $10;
4506 1175 : n->fk_upd_action = ($11)->updateAction->action;
4507 1175 : n->fk_del_action = ($11)->deleteAction->action;
4508 1175 : n->fk_del_set_cols = ($11)->deleteAction->cols;
4509 1175 : processCASbits($12, @12, "FOREIGN KEY",
4510 : &n->deferrable, &n->initdeferred,
4511 : &n->is_enforced, &n->skip_validation, NULL,
4512 : yyscanner);
4513 1175 : n->initially_valid = !n->skip_validation;
4514 1175 : $$ = (Node *) n;
4515 : }
4516 : ;
4517 :
4518 : /*
4519 : * DomainConstraint is separate from TableConstraint because the syntax for
4520 : * NOT NULL constraints is different. For table constraints, we need to
4521 : * accept a column name, but for domain constraints, we don't. (We could
4522 : * accept something like NOT NULL VALUE, but that seems weird.) CREATE DOMAIN
4523 : * (which uses ColQualList) has for a long time accepted NOT NULL without a
4524 : * column name, so it makes sense that ALTER DOMAIN (which uses
4525 : * DomainConstraint) does as well. None of these syntaxes are per SQL
4526 : * standard; we are just living with the bits of inconsistency that have built
4527 : * up over time.
4528 : */
4529 : DomainConstraint:
4530 : CONSTRAINT name DomainConstraintElem
4531 : {
4532 108 : Constraint *n = castNode(Constraint, $3);
4533 :
4534 108 : n->conname = $2;
4535 108 : n->location = @1;
4536 108 : $$ = (Node *) n;
4537 : }
4538 12 : | DomainConstraintElem { $$ = $1; }
4539 : ;
4540 :
4541 : DomainConstraintElem:
4542 : CHECK '(' a_expr ')' ConstraintAttributeSpec
4543 : {
4544 108 : Constraint *n = makeNode(Constraint);
4545 :
4546 108 : n->contype = CONSTR_CHECK;
4547 108 : n->location = @1;
4548 108 : n->raw_expr = $3;
4549 108 : n->cooked_expr = NULL;
4550 108 : processCASbits($5, @5, "CHECK",
4551 : NULL, NULL, NULL, &n->skip_validation,
4552 : &n->is_no_inherit, yyscanner);
4553 100 : n->is_enforced = true;
4554 100 : n->initially_valid = !n->skip_validation;
4555 100 : $$ = (Node *) n;
4556 : }
4557 : | NOT NULL_P ConstraintAttributeSpec
4558 : {
4559 20 : Constraint *n = makeNode(Constraint);
4560 :
4561 20 : n->contype = CONSTR_NOTNULL;
4562 20 : n->location = @1;
4563 20 : n->keys = list_make1(makeString("value"));
4564 : /* no NOT VALID, NO INHERIT support */
4565 20 : processCASbits($3, @3, "NOT NULL",
4566 : NULL, NULL, NULL,
4567 : NULL, NULL, yyscanner);
4568 20 : n->initially_valid = true;
4569 20 : $$ = (Node *) n;
4570 : }
4571 : ;
4572 :
4573 97 : opt_no_inherit: NO INHERIT { $$ = true; }
4574 4633 : | /* EMPTY */ { $$ = false; }
4575 : ;
4576 :
4577 : opt_without_overlaps:
4578 378 : WITHOUT OVERLAPS { $$ = true; }
4579 1395 : | /*EMPTY*/ { $$ = false; }
4580 : ;
4581 :
4582 : opt_column_list:
4583 5942 : '(' columnList ')' { $$ = $2; }
4584 20777 : | /*EMPTY*/ { $$ = NIL; }
4585 : ;
4586 :
4587 : columnList:
4588 11212 : columnElem { $$ = list_make1($1); }
4589 15927 : | columnList ',' columnElem { $$ = lappend($1, $3); }
4590 : ;
4591 :
4592 : optionalPeriodName:
4593 322 : ',' PERIOD columnElem { $$ = $3; }
4594 1546 : | /*EMPTY*/ { $$ = NULL; }
4595 : ;
4596 :
4597 : opt_column_and_period_list:
4598 689 : '(' columnList optionalPeriodName ')' { $$ = list_make2($2, $3); }
4599 490 : | /*EMPTY*/ { $$ = list_make2(NIL, NULL); }
4600 : ;
4601 :
4602 : columnElem: ColId
4603 : {
4604 27461 : $$ = (Node *) makeString($1);
4605 : }
4606 : ;
4607 :
4608 100 : opt_c_include: INCLUDE '(' columnList ')' { $$ = $3; }
4609 1826 : | /* EMPTY */ { $$ = NIL; }
4610 : ;
4611 :
4612 : key_match: MATCH FULL
4613 : {
4614 65 : $$ = FKCONSTR_MATCH_FULL;
4615 : }
4616 : | MATCH PARTIAL
4617 : {
4618 0 : ereport(ERROR,
4619 : (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
4620 : errmsg("MATCH PARTIAL not yet implemented"),
4621 : parser_errposition(@1)));
4622 : $$ = FKCONSTR_MATCH_PARTIAL;
4623 : }
4624 : | MATCH SIMPLE
4625 : {
4626 4 : $$ = FKCONSTR_MATCH_SIMPLE;
4627 : }
4628 : | /*EMPTY*/
4629 : {
4630 1690 : $$ = FKCONSTR_MATCH_SIMPLE;
4631 : }
4632 : ;
4633 :
4634 : ExclusionConstraintList:
4635 153 : ExclusionConstraintElem { $$ = list_make1($1); }
4636 : | ExclusionConstraintList ',' ExclusionConstraintElem
4637 69 : { $$ = lappend($1, $3); }
4638 : ;
4639 :
4640 : ExclusionConstraintElem: index_elem WITH any_operator
4641 : {
4642 222 : $$ = list_make2($1, $3);
4643 : }
4644 : /* allow OPERATOR() decoration for the benefit of ruleutils.c */
4645 : | index_elem WITH OPERATOR '(' any_operator ')'
4646 : {
4647 0 : $$ = list_make2($1, $5);
4648 : }
4649 : ;
4650 :
4651 : OptWhereClause:
4652 299 : WHERE '(' a_expr ')' { $$ = $3; }
4653 799 : | /*EMPTY*/ { $$ = NULL; }
4654 : ;
4655 :
4656 : key_actions:
4657 : key_update
4658 : {
4659 49 : KeyActions *n = palloc_object(KeyActions);
4660 :
4661 49 : n->updateAction = $1;
4662 49 : n->deleteAction = palloc_object(KeyAction);
4663 49 : n->deleteAction->action = FKCONSTR_ACTION_NOACTION;
4664 49 : n->deleteAction->cols = NIL;
4665 49 : $$ = n;
4666 : }
4667 : | key_delete
4668 : {
4669 93 : KeyActions *n = palloc_object(KeyActions);
4670 :
4671 93 : n->updateAction = palloc_object(KeyAction);
4672 93 : n->updateAction->action = FKCONSTR_ACTION_NOACTION;
4673 93 : n->updateAction->cols = NIL;
4674 93 : n->deleteAction = $1;
4675 93 : $$ = n;
4676 : }
4677 : | key_update key_delete
4678 : {
4679 111 : KeyActions *n = palloc_object(KeyActions);
4680 :
4681 111 : n->updateAction = $1;
4682 111 : n->deleteAction = $2;
4683 111 : $$ = n;
4684 : }
4685 : | key_delete key_update
4686 : {
4687 100 : KeyActions *n = palloc_object(KeyActions);
4688 :
4689 100 : n->updateAction = $2;
4690 100 : n->deleteAction = $1;
4691 100 : $$ = n;
4692 : }
4693 : | /*EMPTY*/
4694 : {
4695 1402 : KeyActions *n = palloc_object(KeyActions);
4696 :
4697 1402 : n->updateAction = palloc_object(KeyAction);
4698 1402 : n->updateAction->action = FKCONSTR_ACTION_NOACTION;
4699 1402 : n->updateAction->cols = NIL;
4700 1402 : n->deleteAction = palloc_object(KeyAction);
4701 1402 : n->deleteAction->action = FKCONSTR_ACTION_NOACTION;
4702 1402 : n->deleteAction->cols = NIL;
4703 1402 : $$ = n;
4704 : }
4705 : ;
4706 :
4707 : key_update: ON UPDATE key_action
4708 : {
4709 264 : if (($3)->cols)
4710 4 : ereport(ERROR,
4711 : (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
4712 : errmsg("a column list with %s is only supported for ON DELETE actions",
4713 : ($3)->action == FKCONSTR_ACTION_SETNULL ? "SET NULL" : "SET DEFAULT"),
4714 : parser_errposition(@1)));
4715 260 : $$ = $3;
4716 : }
4717 : ;
4718 :
4719 : key_delete: ON DELETE_P key_action
4720 : {
4721 304 : $$ = $3;
4722 : }
4723 : ;
4724 :
4725 : key_action:
4726 : NO ACTION
4727 : {
4728 51 : KeyAction *n = palloc_object(KeyAction);
4729 :
4730 51 : n->action = FKCONSTR_ACTION_NOACTION;
4731 51 : n->cols = NIL;
4732 51 : $$ = n;
4733 : }
4734 : | RESTRICT
4735 : {
4736 32 : KeyAction *n = palloc_object(KeyAction);
4737 :
4738 32 : n->action = FKCONSTR_ACTION_RESTRICT;
4739 32 : n->cols = NIL;
4740 32 : $$ = n;
4741 : }
4742 : | CASCADE
4743 : {
4744 293 : KeyAction *n = palloc_object(KeyAction);
4745 :
4746 293 : n->action = FKCONSTR_ACTION_CASCADE;
4747 293 : n->cols = NIL;
4748 293 : $$ = n;
4749 : }
4750 : | SET NULL_P opt_column_list
4751 : {
4752 124 : KeyAction *n = palloc_object(KeyAction);
4753 :
4754 124 : n->action = FKCONSTR_ACTION_SETNULL;
4755 124 : n->cols = $3;
4756 124 : $$ = n;
4757 : }
4758 : | SET DEFAULT opt_column_list
4759 : {
4760 68 : KeyAction *n = palloc_object(KeyAction);
4761 :
4762 68 : n->action = FKCONSTR_ACTION_SETDEFAULT;
4763 68 : n->cols = $3;
4764 68 : $$ = n;
4765 : }
4766 : ;
4767 :
4768 1375 : OptInherit: INHERITS '(' qualified_name_list ')' { $$ = $3; }
4769 17990 : | /*EMPTY*/ { $$ = NIL; }
4770 : ;
4771 :
4772 : /* Optional partition key specification */
4773 3566 : OptPartitionSpec: PartitionSpec { $$ = $1; }
4774 21448 : | /*EMPTY*/ { $$ = NULL; }
4775 : ;
4776 :
4777 : PartitionSpec: PARTITION BY ColId '(' part_params ')'
4778 : {
4779 3570 : PartitionSpec *n = makeNode(PartitionSpec);
4780 :
4781 3570 : n->strategy = parsePartitionStrategy($3, @3, yyscanner);
4782 3566 : n->partParams = $5;
4783 3566 : n->location = @1;
4784 :
4785 3566 : $$ = n;
4786 : }
4787 : ;
4788 :
4789 3570 : part_params: part_elem { $$ = list_make1($1); }
4790 322 : | part_params ',' part_elem { $$ = lappend($1, $3); }
4791 : ;
4792 :
4793 : part_elem: ColId opt_collate opt_qualified_name
4794 : {
4795 3660 : PartitionElem *n = makeNode(PartitionElem);
4796 :
4797 3660 : n->name = $1;
4798 3660 : n->expr = NULL;
4799 3660 : n->collation = $2;
4800 3660 : n->opclass = $3;
4801 3660 : n->location = @1;
4802 3660 : $$ = n;
4803 : }
4804 : | func_expr_windowless opt_collate opt_qualified_name
4805 : {
4806 94 : PartitionElem *n = makeNode(PartitionElem);
4807 :
4808 94 : n->name = NULL;
4809 94 : n->expr = $1;
4810 94 : n->collation = $2;
4811 94 : n->opclass = $3;
4812 94 : n->location = @1;
4813 94 : $$ = n;
4814 : }
4815 : | '(' a_expr ')' opt_collate opt_qualified_name
4816 : {
4817 138 : PartitionElem *n = makeNode(PartitionElem);
4818 :
4819 138 : n->name = NULL;
4820 138 : n->expr = $2;
4821 138 : n->collation = $4;
4822 138 : n->opclass = $5;
4823 138 : n->location = @1;
4824 138 : $$ = n;
4825 : }
4826 : ;
4827 :
4828 : table_access_method_clause:
4829 87 : USING name { $$ = $2; }
4830 26174 : | /*EMPTY*/ { $$ = NULL; }
4831 : ;
4832 :
4833 : /* WITHOUT OIDS is legacy only */
4834 : OptWith:
4835 579 : WITH reloptions { $$ = $2; }
4836 16 : | WITHOUT OIDS { $$ = NIL; }
4837 25297 : | /*EMPTY*/ { $$ = NIL; }
4838 : ;
4839 :
4840 43 : OnCommitOption: ON COMMIT DROP { $$ = ONCOMMIT_DROP; }
4841 69 : | ON COMMIT DELETE_P ROWS { $$ = ONCOMMIT_DELETE_ROWS; }
4842 16 : | ON COMMIT PRESERVE ROWS { $$ = ONCOMMIT_PRESERVE_ROWS; }
4843 25764 : | /*EMPTY*/ { $$ = ONCOMMIT_NOOP; }
4844 : ;
4845 :
4846 141 : OptTableSpace: TABLESPACE name { $$ = $2; }
4847 30496 : | /*EMPTY*/ { $$ = NULL; }
4848 : ;
4849 :
4850 50 : OptConsTableSpace: USING INDEX TABLESPACE name { $$ = $4; }
4851 5732 : | /*EMPTY*/ { $$ = NULL; }
4852 : ;
4853 :
4854 5950 : ExistingIndex: USING INDEX name { $$ = $3; }
4855 : ;
4856 :
4857 : /*****************************************************************************
4858 : *
4859 : * QUERY :
4860 : * CREATE STATISTICS [[IF NOT EXISTS] stats_name] [(stat types)]
4861 : * ON expression-list FROM from_list
4862 : *
4863 : * Note: the expectation here is that the clauses after ON are a subset of
4864 : * SELECT syntax, allowing for expressions and joined tables, and probably
4865 : * someday a WHERE clause. Much less than that is currently implemented,
4866 : * but the grammar accepts it and then we'll throw FEATURE_NOT_SUPPORTED
4867 : * errors as necessary at execution.
4868 : *
4869 : * Statistics name is optional unless IF NOT EXISTS is specified.
4870 : *
4871 : *****************************************************************************/
4872 :
4873 : CreateStatsStmt:
4874 : CREATE STATISTICS opt_qualified_name
4875 : opt_name_list ON stats_params FROM from_list
4876 : {
4877 640 : CreateStatsStmt *n = makeNode(CreateStatsStmt);
4878 :
4879 640 : n->defnames = $3;
4880 640 : n->stat_types = $4;
4881 640 : n->exprs = $6;
4882 640 : n->relations = $8;
4883 640 : n->stxcomment = NULL;
4884 640 : n->if_not_exists = false;
4885 640 : $$ = (Node *) n;
4886 : }
4887 : | CREATE STATISTICS IF_P NOT EXISTS any_name
4888 : opt_name_list ON stats_params FROM from_list
4889 : {
4890 8 : CreateStatsStmt *n = makeNode(CreateStatsStmt);
4891 :
4892 8 : n->defnames = $6;
4893 8 : n->stat_types = $7;
4894 8 : n->exprs = $9;
4895 8 : n->relations = $11;
4896 8 : n->stxcomment = NULL;
4897 8 : n->if_not_exists = true;
4898 8 : $$ = (Node *) n;
4899 : }
4900 : ;
4901 :
4902 : /*
4903 : * Statistics attributes can be either simple column references, or arbitrary
4904 : * expressions in parens. For compatibility with index attributes permitted
4905 : * in CREATE INDEX, we allow an expression that's just a function call to be
4906 : * written without parens.
4907 : */
4908 :
4909 656 : stats_params: stats_param { $$ = list_make1($1); }
4910 884 : | stats_params ',' stats_param { $$ = lappend($1, $3); }
4911 : ;
4912 :
4913 : stats_param: ColId
4914 : {
4915 1121 : $$ = makeNode(StatsElem);
4916 1121 : $$->name = $1;
4917 1121 : $$->expr = NULL;
4918 : }
4919 : | func_expr_windowless
4920 : {
4921 67 : $$ = makeNode(StatsElem);
4922 67 : $$->name = NULL;
4923 67 : $$->expr = $1;
4924 : }
4925 : | '(' a_expr ')'
4926 : {
4927 352 : $$ = makeNode(StatsElem);
4928 352 : $$->name = NULL;
4929 352 : $$->expr = $2;
4930 : }
4931 : ;
4932 :
4933 : /*****************************************************************************
4934 : *
4935 : * QUERY :
4936 : * ALTER STATISTICS [IF EXISTS] stats_name
4937 : * SET STATISTICS <SignedIconst>
4938 : *
4939 : *****************************************************************************/
4940 :
4941 : AlterStatsStmt:
4942 : ALTER STATISTICS any_name SET STATISTICS set_statistics_value
4943 : {
4944 13 : AlterStatsStmt *n = makeNode(AlterStatsStmt);
4945 :
4946 13 : n->defnames = $3;
4947 13 : n->missing_ok = false;
4948 13 : n->stxstattarget = $6;
4949 13 : $$ = (Node *) n;
4950 : }
4951 : | ALTER STATISTICS IF_P EXISTS any_name SET STATISTICS set_statistics_value
4952 : {
4953 4 : AlterStatsStmt *n = makeNode(AlterStatsStmt);
4954 :
4955 4 : n->defnames = $5;
4956 4 : n->missing_ok = true;
4957 4 : n->stxstattarget = $8;
4958 4 : $$ = (Node *) n;
4959 : }
4960 : ;
4961 :
4962 : /*****************************************************************************
4963 : *
4964 : * QUERY :
4965 : * CREATE TABLE relname AS SelectStmt [ WITH [NO] DATA ]
4966 : *
4967 : *
4968 : * Note: SELECT ... INTO is a now-deprecated alternative for this.
4969 : *
4970 : *****************************************************************************/
4971 :
4972 : CreateAsStmt:
4973 : CREATE OptTemp TABLE create_as_target AS SelectStmt opt_with_data
4974 : {
4975 797 : CreateTableAsStmt *ctas = makeNode(CreateTableAsStmt);
4976 :
4977 797 : ctas->query = $6;
4978 797 : ctas->into = $4;
4979 797 : ctas->objtype = OBJECT_TABLE;
4980 797 : ctas->is_select_into = false;
4981 797 : ctas->if_not_exists = false;
4982 : /* cram additional flags into the IntoClause */
4983 797 : $4->rel->relpersistence = $2;
4984 797 : $4->skipData = !($7);
4985 797 : $$ = (Node *) ctas;
4986 : }
4987 : | CREATE OptTemp TABLE IF_P NOT EXISTS create_as_target AS SelectStmt opt_with_data
4988 : {
4989 31 : CreateTableAsStmt *ctas = makeNode(CreateTableAsStmt);
4990 :
4991 31 : ctas->query = $9;
4992 31 : ctas->into = $7;
4993 31 : ctas->objtype = OBJECT_TABLE;
4994 31 : ctas->is_select_into = false;
4995 31 : ctas->if_not_exists = true;
4996 : /* cram additional flags into the IntoClause */
4997 31 : $7->rel->relpersistence = $2;
4998 31 : $7->skipData = !($10);
4999 31 : $$ = (Node *) ctas;
5000 : }
5001 : ;
5002 :
5003 : create_as_target:
5004 : qualified_name opt_column_list table_access_method_clause
5005 : OptWith OnCommitOption OptTableSpace
5006 : {
5007 886 : $$ = makeNode(IntoClause);
5008 886 : $$->rel = $1;
5009 886 : $$->colNames = $2;
5010 886 : $$->accessMethod = $3;
5011 886 : $$->options = $4;
5012 886 : $$->onCommit = $5;
5013 886 : $$->tableSpaceName = $6;
5014 886 : $$->viewQuery = NULL;
5015 886 : $$->skipData = false; /* might get changed later */
5016 : }
5017 : ;
5018 :
5019 : opt_with_data:
5020 24 : WITH DATA_P { $$ = true; }
5021 141 : | WITH NO DATA_P { $$ = false; }
5022 1260 : | /*EMPTY*/ { $$ = true; }
5023 : ;
5024 :
5025 :
5026 : /*****************************************************************************
5027 : *
5028 : * QUERY :
5029 : * CREATE MATERIALIZED VIEW relname AS SelectStmt
5030 : *
5031 : *****************************************************************************/
5032 :
5033 : CreateMatViewStmt:
5034 : CREATE OptNoLog MATERIALIZED VIEW create_mv_target AS SelectStmt opt_with_data
5035 : {
5036 336 : CreateTableAsStmt *ctas = makeNode(CreateTableAsStmt);
5037 :
5038 336 : ctas->query = $7;
5039 336 : ctas->into = $5;
5040 336 : ctas->objtype = OBJECT_MATVIEW;
5041 336 : ctas->is_select_into = false;
5042 336 : ctas->if_not_exists = false;
5043 : /* cram additional flags into the IntoClause */
5044 336 : $5->rel->relpersistence = $2;
5045 336 : $5->skipData = !($8);
5046 336 : $$ = (Node *) ctas;
5047 : }
5048 : | CREATE OptNoLog MATERIALIZED VIEW IF_P NOT EXISTS create_mv_target AS SelectStmt opt_with_data
5049 : {
5050 29 : CreateTableAsStmt *ctas = makeNode(CreateTableAsStmt);
5051 :
5052 29 : ctas->query = $10;
5053 29 : ctas->into = $8;
5054 29 : ctas->objtype = OBJECT_MATVIEW;
5055 29 : ctas->is_select_into = false;
5056 29 : ctas->if_not_exists = true;
5057 : /* cram additional flags into the IntoClause */
5058 29 : $8->rel->relpersistence = $2;
5059 29 : $8->skipData = !($11);
5060 29 : $$ = (Node *) ctas;
5061 : }
5062 : ;
5063 :
5064 : create_mv_target:
5065 : qualified_name opt_column_list table_access_method_clause opt_reloptions OptTableSpace
5066 : {
5067 365 : $$ = makeNode(IntoClause);
5068 365 : $$->rel = $1;
5069 365 : $$->colNames = $2;
5070 365 : $$->accessMethod = $3;
5071 365 : $$->options = $4;
5072 365 : $$->onCommit = ONCOMMIT_NOOP;
5073 365 : $$->tableSpaceName = $5;
5074 365 : $$->viewQuery = NULL; /* filled at analysis time */
5075 365 : $$->skipData = false; /* might get changed later */
5076 : }
5077 : ;
5078 :
5079 0 : OptNoLog: UNLOGGED { $$ = RELPERSISTENCE_UNLOGGED; }
5080 365 : | /*EMPTY*/ { $$ = RELPERSISTENCE_PERMANENT; }
5081 : ;
5082 :
5083 :
5084 : /*****************************************************************************
5085 : *
5086 : * QUERY :
5087 : * REFRESH MATERIALIZED VIEW qualified_name
5088 : *
5089 : *****************************************************************************/
5090 :
5091 : RefreshMatViewStmt:
5092 : REFRESH MATERIALIZED VIEW opt_concurrently qualified_name opt_with_data
5093 : {
5094 174 : RefreshMatViewStmt *n = makeNode(RefreshMatViewStmt);
5095 :
5096 174 : n->concurrent = $4;
5097 174 : n->relation = $5;
5098 174 : n->skipData = !($6);
5099 174 : $$ = (Node *) n;
5100 : }
5101 : ;
5102 :
5103 :
5104 : /*****************************************************************************
5105 : *
5106 : * QUERY :
5107 : * CREATE SEQUENCE seqname
5108 : * ALTER SEQUENCE seqname
5109 : *
5110 : *****************************************************************************/
5111 :
5112 : CreateSeqStmt:
5113 : CREATE OptTemp SEQUENCE qualified_name OptSeqOptList
5114 : {
5115 434 : CreateSeqStmt *n = makeNode(CreateSeqStmt);
5116 :
5117 434 : $4->relpersistence = $2;
5118 434 : n->sequence = $4;
5119 434 : n->options = $5;
5120 434 : n->ownerId = InvalidOid;
5121 434 : n->if_not_exists = false;
5122 434 : $$ = (Node *) n;
5123 : }
5124 : | CREATE OptTemp SEQUENCE IF_P NOT EXISTS qualified_name OptSeqOptList
5125 : {
5126 13 : CreateSeqStmt *n = makeNode(CreateSeqStmt);
5127 :
5128 13 : $7->relpersistence = $2;
5129 13 : n->sequence = $7;
5130 13 : n->options = $8;
5131 13 : n->ownerId = InvalidOid;
5132 13 : n->if_not_exists = true;
5133 13 : $$ = (Node *) n;
5134 : }
5135 : ;
5136 :
5137 : AlterSeqStmt:
5138 : ALTER SEQUENCE qualified_name SeqOptList
5139 : {
5140 117 : AlterSeqStmt *n = makeNode(AlterSeqStmt);
5141 :
5142 117 : n->sequence = $3;
5143 117 : n->options = $4;
5144 117 : n->missing_ok = false;
5145 117 : $$ = (Node *) n;
5146 : }
5147 : | ALTER SEQUENCE IF_P EXISTS qualified_name SeqOptList
5148 : {
5149 8 : AlterSeqStmt *n = makeNode(AlterSeqStmt);
5150 :
5151 8 : n->sequence = $5;
5152 8 : n->options = $6;
5153 8 : n->missing_ok = true;
5154 8 : $$ = (Node *) n;
5155 : }
5156 :
5157 : ;
5158 :
5159 164 : OptSeqOptList: SeqOptList { $$ = $1; }
5160 283 : | /*EMPTY*/ { $$ = NIL; }
5161 : ;
5162 :
5163 42 : OptParenthesizedSeqOptList: '(' SeqOptList ')' { $$ = $2; }
5164 313 : | /*EMPTY*/ { $$ = NIL; }
5165 : ;
5166 :
5167 331 : SeqOptList: SeqOptElem { $$ = list_make1($1); }
5168 440 : | SeqOptList SeqOptElem { $$ = lappend($1, $2); }
5169 : ;
5170 :
5171 : SeqOptElem: AS SimpleTypename
5172 : {
5173 119 : $$ = makeDefElem("as", (Node *) $2, @1);
5174 : }
5175 : | CACHE NumericOnly
5176 : {
5177 67 : $$ = makeDefElem("cache", (Node *) $2, @1);
5178 : }
5179 : | CYCLE
5180 : {
5181 22 : $$ = makeDefElem("cycle", (Node *) makeBoolean(true), @1);
5182 : }
5183 : | NO CYCLE
5184 : {
5185 9 : $$ = makeDefElem("cycle", (Node *) makeBoolean(false), @1);
5186 : }
5187 : | INCREMENT opt_by NumericOnly
5188 : {
5189 149 : $$ = makeDefElem("increment", (Node *) $3, @1);
5190 : }
5191 : | LOGGED
5192 : {
5193 1 : $$ = makeDefElem("logged", NULL, @1);
5194 : }
5195 : | MAXVALUE NumericOnly
5196 : {
5197 43 : $$ = makeDefElem("maxvalue", (Node *) $2, @1);
5198 : }
5199 : | MINVALUE NumericOnly
5200 : {
5201 43 : $$ = makeDefElem("minvalue", (Node *) $2, @1);
5202 : }
5203 : | NO MAXVALUE
5204 : {
5205 54 : $$ = makeDefElem("maxvalue", NULL, @1);
5206 : }
5207 : | NO MINVALUE
5208 : {
5209 54 : $$ = makeDefElem("minvalue", NULL, @1);
5210 : }
5211 : | OWNED BY any_name
5212 : {
5213 43 : $$ = makeDefElem("owned_by", (Node *) $3, @1);
5214 : }
5215 : | SEQUENCE NAME_P any_name
5216 : {
5217 22 : $$ = makeDefElem("sequence_name", (Node *) $3, @1);
5218 : }
5219 : | START opt_with NumericOnly
5220 : {
5221 137 : $$ = makeDefElem("start", (Node *) $3, @1);
5222 : }
5223 : | RESTART
5224 : {
5225 4 : $$ = makeDefElem("restart", NULL, @1);
5226 : }
5227 : | RESTART opt_with NumericOnly
5228 : {
5229 39 : $$ = makeDefElem("restart", (Node *) $3, @1);
5230 : }
5231 : | UNLOGGED
5232 : {
5233 1 : $$ = makeDefElem("unlogged", NULL, @1);
5234 : }
5235 : ;
5236 :
5237 : opt_by: BY
5238 : | /* EMPTY */
5239 : ;
5240 :
5241 : NumericOnly:
5242 209 : FCONST { $$ = (Node *) makeFloat($1); }
5243 0 : | '+' FCONST { $$ = (Node *) makeFloat($2); }
5244 : | '-' FCONST
5245 : {
5246 13 : Float *f = makeFloat($2);
5247 :
5248 13 : doNegateFloat(f);
5249 13 : $$ = (Node *) f;
5250 : }
5251 7146 : | SignedIconst { $$ = (Node *) makeInteger($1); }
5252 : ;
5253 :
5254 62 : NumericOnly_list: NumericOnly { $$ = list_make1($1); }
5255 4 : | NumericOnly_list ',' NumericOnly { $$ = lappend($1, $3); }
5256 : ;
5257 :
5258 : /*****************************************************************************
5259 : *
5260 : * QUERIES :
5261 : * CREATE [OR REPLACE] [TRUSTED] [PROCEDURAL] LANGUAGE ...
5262 : * DROP [PROCEDURAL] LANGUAGE ...
5263 : *
5264 : *****************************************************************************/
5265 :
5266 : CreatePLangStmt:
5267 : CREATE opt_or_replace opt_trusted opt_procedural LANGUAGE name
5268 : {
5269 : /*
5270 : * We now interpret parameterless CREATE LANGUAGE as
5271 : * CREATE EXTENSION. "OR REPLACE" is silently translated
5272 : * to "IF NOT EXISTS", which isn't quite the same, but
5273 : * seems more useful than throwing an error. We just
5274 : * ignore TRUSTED, as the previous code would have too.
5275 : */
5276 0 : CreateExtensionStmt *n = makeNode(CreateExtensionStmt);
5277 :
5278 0 : n->if_not_exists = $2;
5279 0 : n->extname = $6;
5280 0 : n->options = NIL;
5281 0 : $$ = (Node *) n;
5282 : }
5283 : | CREATE opt_or_replace opt_trusted opt_procedural LANGUAGE name
5284 : HANDLER handler_name opt_inline_handler opt_validator
5285 : {
5286 74 : CreatePLangStmt *n = makeNode(CreatePLangStmt);
5287 :
5288 74 : n->replace = $2;
5289 74 : n->plname = $6;
5290 74 : n->plhandler = $8;
5291 74 : n->plinline = $9;
5292 74 : n->plvalidator = $10;
5293 74 : n->pltrusted = $3;
5294 74 : $$ = (Node *) n;
5295 : }
5296 : ;
5297 :
5298 : opt_trusted:
5299 57 : TRUSTED { $$ = true; }
5300 22 : | /*EMPTY*/ { $$ = false; }
5301 : ;
5302 :
5303 : /* This ought to be just func_name, but that causes reduce/reduce conflicts
5304 : * (CREATE LANGUAGE is the only place where func_name isn't followed by '(').
5305 : * Work around by using simple names, instead.
5306 : */
5307 : handler_name:
5308 331 : name { $$ = list_make1(makeString($1)); }
5309 1 : | name attrs { $$ = lcons(makeString($1), $2); }
5310 : ;
5311 :
5312 : opt_inline_handler:
5313 63 : INLINE_P handler_name { $$ = $2; }
5314 11 : | /*EMPTY*/ { $$ = NIL; }
5315 : ;
5316 :
5317 : validator_clause:
5318 63 : VALIDATOR handler_name { $$ = $2; }
5319 0 : | NO VALIDATOR { $$ = NIL; }
5320 : ;
5321 :
5322 : opt_validator:
5323 63 : validator_clause { $$ = $1; }
5324 11 : | /*EMPTY*/ { $$ = NIL; }
5325 : ;
5326 :
5327 : opt_procedural:
5328 : PROCEDURAL
5329 : | /*EMPTY*/
5330 : ;
5331 :
5332 : /*****************************************************************************
5333 : *
5334 : * QUERY:
5335 : * CREATE TABLESPACE tablespace LOCATION '/path/to/tablespace/'
5336 : *
5337 : *****************************************************************************/
5338 :
5339 : CreateTableSpaceStmt: CREATE TABLESPACE name OptTableSpaceOwner LOCATION Sconst opt_reloptions
5340 : {
5341 76 : CreateTableSpaceStmt *n = makeNode(CreateTableSpaceStmt);
5342 :
5343 76 : n->tablespacename = $3;
5344 76 : n->owner = $4;
5345 76 : n->location = $6;
5346 76 : n->options = $7;
5347 76 : $$ = (Node *) n;
5348 : }
5349 : ;
5350 :
5351 7 : OptTableSpaceOwner: OWNER RoleSpec { $$ = $2; }
5352 69 : | /*EMPTY */ { $$ = NULL; }
5353 : ;
5354 :
5355 : /*****************************************************************************
5356 : *
5357 : * QUERY :
5358 : * DROP TABLESPACE <tablespace>
5359 : *
5360 : * No need for drop behaviour as we cannot implement dependencies for
5361 : * objects in other databases; we can only support RESTRICT.
5362 : *
5363 : ****************************************************************************/
5364 :
5365 : DropTableSpaceStmt: DROP TABLESPACE name
5366 : {
5367 35 : DropTableSpaceStmt *n = makeNode(DropTableSpaceStmt);
5368 :
5369 35 : n->tablespacename = $3;
5370 35 : n->missing_ok = false;
5371 35 : $$ = (Node *) n;
5372 : }
5373 : | DROP TABLESPACE IF_P EXISTS name
5374 : {
5375 0 : DropTableSpaceStmt *n = makeNode(DropTableSpaceStmt);
5376 :
5377 0 : n->tablespacename = $5;
5378 0 : n->missing_ok = true;
5379 0 : $$ = (Node *) n;
5380 : }
5381 : ;
5382 :
5383 : /*****************************************************************************
5384 : *
5385 : * QUERY:
5386 : * CREATE EXTENSION extension
5387 : * [ WITH ] [ SCHEMA schema ] [ VERSION version ]
5388 : *
5389 : *****************************************************************************/
5390 :
5391 : CreateExtensionStmt: CREATE EXTENSION name opt_with create_extension_opt_list
5392 : {
5393 286 : CreateExtensionStmt *n = makeNode(CreateExtensionStmt);
5394 :
5395 286 : n->extname = $3;
5396 286 : n->if_not_exists = false;
5397 286 : n->options = $5;
5398 286 : $$ = (Node *) n;
5399 : }
5400 : | CREATE EXTENSION IF_P NOT EXISTS name opt_with create_extension_opt_list
5401 : {
5402 10 : CreateExtensionStmt *n = makeNode(CreateExtensionStmt);
5403 :
5404 10 : n->extname = $6;
5405 10 : n->if_not_exists = true;
5406 10 : n->options = $8;
5407 10 : $$ = (Node *) n;
5408 : }
5409 : ;
5410 :
5411 : create_extension_opt_list:
5412 : create_extension_opt_list create_extension_opt_item
5413 49 : { $$ = lappend($1, $2); }
5414 : | /* EMPTY */
5415 296 : { $$ = NIL; }
5416 : ;
5417 :
5418 : create_extension_opt_item:
5419 : SCHEMA name
5420 : {
5421 23 : $$ = makeDefElem("schema", (Node *) makeString($2), @1);
5422 : }
5423 : | VERSION_P NonReservedWord_or_Sconst
5424 : {
5425 6 : $$ = makeDefElem("new_version", (Node *) makeString($2), @1);
5426 : }
5427 : | FROM NonReservedWord_or_Sconst
5428 : {
5429 0 : ereport(ERROR,
5430 : (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
5431 : errmsg("CREATE EXTENSION ... FROM is no longer supported"),
5432 : parser_errposition(@1)));
5433 : }
5434 : | CASCADE
5435 : {
5436 20 : $$ = makeDefElem("cascade", (Node *) makeBoolean(true), @1);
5437 : }
5438 : ;
5439 :
5440 : /*****************************************************************************
5441 : *
5442 : * ALTER EXTENSION name UPDATE [ TO version ]
5443 : *
5444 : *****************************************************************************/
5445 :
5446 : AlterExtensionStmt: ALTER EXTENSION name UPDATE alter_extension_opt_list
5447 : {
5448 20 : AlterExtensionStmt *n = makeNode(AlterExtensionStmt);
5449 :
5450 20 : n->extname = $3;
5451 20 : n->options = $5;
5452 20 : $$ = (Node *) n;
5453 : }
5454 : ;
5455 :
5456 : alter_extension_opt_list:
5457 : alter_extension_opt_list alter_extension_opt_item
5458 20 : { $$ = lappend($1, $2); }
5459 : | /* EMPTY */
5460 20 : { $$ = NIL; }
5461 : ;
5462 :
5463 : alter_extension_opt_item:
5464 : TO NonReservedWord_or_Sconst
5465 : {
5466 20 : $$ = makeDefElem("new_version", (Node *) makeString($2), @1);
5467 : }
5468 : ;
5469 :
5470 : /*****************************************************************************
5471 : *
5472 : * ALTER EXTENSION name ADD/DROP object-identifier
5473 : *
5474 : *****************************************************************************/
5475 :
5476 : AlterExtensionContentsStmt:
5477 : ALTER EXTENSION name add_drop object_type_name name
5478 : {
5479 9 : AlterExtensionContentsStmt *n = makeNode(AlterExtensionContentsStmt);
5480 :
5481 9 : n->extname = $3;
5482 9 : n->action = $4;
5483 9 : n->objtype = $5;
5484 9 : n->object = (Node *) makeString($6);
5485 9 : $$ = (Node *) n;
5486 : }
5487 : | ALTER EXTENSION name add_drop object_type_any_name any_name
5488 : {
5489 39 : AlterExtensionContentsStmt *n = makeNode(AlterExtensionContentsStmt);
5490 :
5491 39 : n->extname = $3;
5492 39 : n->action = $4;
5493 39 : n->objtype = $5;
5494 39 : n->object = (Node *) $6;
5495 39 : $$ = (Node *) n;
5496 : }
5497 : | ALTER EXTENSION name add_drop AGGREGATE aggregate_with_argtypes
5498 : {
5499 4 : AlterExtensionContentsStmt *n = makeNode(AlterExtensionContentsStmt);
5500 :
5501 4 : n->extname = $3;
5502 4 : n->action = $4;
5503 4 : n->objtype = OBJECT_AGGREGATE;
5504 4 : n->object = (Node *) $6;
5505 4 : $$ = (Node *) n;
5506 : }
5507 : | ALTER EXTENSION name add_drop CAST '(' Typename AS Typename ')'
5508 : {
5509 2 : AlterExtensionContentsStmt *n = makeNode(AlterExtensionContentsStmt);
5510 :
5511 2 : n->extname = $3;
5512 2 : n->action = $4;
5513 2 : n->objtype = OBJECT_CAST;
5514 2 : n->object = (Node *) list_make2($7, $9);
5515 2 : $$ = (Node *) n;
5516 : }
5517 : | ALTER EXTENSION name add_drop DOMAIN_P Typename
5518 : {
5519 0 : AlterExtensionContentsStmt *n = makeNode(AlterExtensionContentsStmt);
5520 :
5521 0 : n->extname = $3;
5522 0 : n->action = $4;
5523 0 : n->objtype = OBJECT_DOMAIN;
5524 0 : n->object = (Node *) $6;
5525 0 : $$ = (Node *) n;
5526 : }
5527 : | ALTER EXTENSION name add_drop FUNCTION function_with_argtypes
5528 : {
5529 56 : AlterExtensionContentsStmt *n = makeNode(AlterExtensionContentsStmt);
5530 :
5531 56 : n->extname = $3;
5532 56 : n->action = $4;
5533 56 : n->objtype = OBJECT_FUNCTION;
5534 56 : n->object = (Node *) $6;
5535 56 : $$ = (Node *) n;
5536 : }
5537 : | ALTER EXTENSION name add_drop OPERATOR operator_with_argtypes
5538 : {
5539 9 : AlterExtensionContentsStmt *n = makeNode(AlterExtensionContentsStmt);
5540 :
5541 9 : n->extname = $3;
5542 9 : n->action = $4;
5543 9 : n->objtype = OBJECT_OPERATOR;
5544 9 : n->object = (Node *) $6;
5545 9 : $$ = (Node *) n;
5546 : }
5547 : | ALTER EXTENSION name add_drop OPERATOR CLASS any_name USING name
5548 : {
5549 2 : AlterExtensionContentsStmt *n = makeNode(AlterExtensionContentsStmt);
5550 :
5551 2 : n->extname = $3;
5552 2 : n->action = $4;
5553 2 : n->objtype = OBJECT_OPCLASS;
5554 2 : n->object = (Node *) lcons(makeString($9), $7);
5555 2 : $$ = (Node *) n;
5556 : }
5557 : | ALTER EXTENSION name add_drop OPERATOR FAMILY any_name USING name
5558 : {
5559 2 : AlterExtensionContentsStmt *n = makeNode(AlterExtensionContentsStmt);
5560 :
5561 2 : n->extname = $3;
5562 2 : n->action = $4;
5563 2 : n->objtype = OBJECT_OPFAMILY;
5564 2 : n->object = (Node *) lcons(makeString($9), $7);
5565 2 : $$ = (Node *) n;
5566 : }
5567 : | ALTER EXTENSION name add_drop PROCEDURE function_with_argtypes
5568 : {
5569 0 : AlterExtensionContentsStmt *n = makeNode(AlterExtensionContentsStmt);
5570 :
5571 0 : n->extname = $3;
5572 0 : n->action = $4;
5573 0 : n->objtype = OBJECT_PROCEDURE;
5574 0 : n->object = (Node *) $6;
5575 0 : $$ = (Node *) n;
5576 : }
5577 : | ALTER EXTENSION name add_drop ROUTINE function_with_argtypes
5578 : {
5579 0 : AlterExtensionContentsStmt *n = makeNode(AlterExtensionContentsStmt);
5580 :
5581 0 : n->extname = $3;
5582 0 : n->action = $4;
5583 0 : n->objtype = OBJECT_ROUTINE;
5584 0 : n->object = (Node *) $6;
5585 0 : $$ = (Node *) n;
5586 : }
5587 : | ALTER EXTENSION name add_drop TRANSFORM FOR Typename LANGUAGE name
5588 : {
5589 2 : AlterExtensionContentsStmt *n = makeNode(AlterExtensionContentsStmt);
5590 :
5591 2 : n->extname = $3;
5592 2 : n->action = $4;
5593 2 : n->objtype = OBJECT_TRANSFORM;
5594 2 : n->object = (Node *) list_make2($7, makeString($9));
5595 2 : $$ = (Node *) n;
5596 : }
5597 : | ALTER EXTENSION name add_drop TYPE_P Typename
5598 : {
5599 4 : AlterExtensionContentsStmt *n = makeNode(AlterExtensionContentsStmt);
5600 :
5601 4 : n->extname = $3;
5602 4 : n->action = $4;
5603 4 : n->objtype = OBJECT_TYPE;
5604 4 : n->object = (Node *) $6;
5605 4 : $$ = (Node *) n;
5606 : }
5607 : ;
5608 :
5609 : /*****************************************************************************
5610 : *
5611 : * QUERY:
5612 : * CREATE FOREIGN DATA WRAPPER name options
5613 : *
5614 : *****************************************************************************/
5615 :
5616 : CreateFdwStmt: CREATE FOREIGN DATA_P WRAPPER name opt_fdw_options create_generic_options
5617 : {
5618 135 : CreateFdwStmt *n = makeNode(CreateFdwStmt);
5619 :
5620 135 : n->fdwname = $5;
5621 135 : n->func_options = $6;
5622 135 : n->options = $7;
5623 135 : $$ = (Node *) n;
5624 : }
5625 : ;
5626 :
5627 : fdw_option:
5628 38 : HANDLER handler_name { $$ = makeDefElem("handler", (Node *) $2, @1); }
5629 0 : | NO HANDLER { $$ = makeDefElem("handler", NULL, @1); }
5630 36 : | VALIDATOR handler_name { $$ = makeDefElem("validator", (Node *) $2, @1); }
5631 4 : | NO VALIDATOR { $$ = makeDefElem("validator", NULL, @1); }
5632 12 : | CONNECTION handler_name { $$ = makeDefElem("connection", (Node *) $2, @1); }
5633 4 : | NO CONNECTION { $$ = makeDefElem("connection", NULL, @1); }
5634 : ;
5635 :
5636 : fdw_options:
5637 80 : fdw_option { $$ = list_make1($1); }
5638 14 : | fdw_options fdw_option { $$ = lappend($1, $2); }
5639 : ;
5640 :
5641 : opt_fdw_options:
5642 36 : fdw_options { $$ = $1; }
5643 159 : | /*EMPTY*/ { $$ = NIL; }
5644 : ;
5645 :
5646 : /*****************************************************************************
5647 : *
5648 : * QUERY :
5649 : * ALTER FOREIGN DATA WRAPPER name options
5650 : *
5651 : ****************************************************************************/
5652 :
5653 : AlterFdwStmt: ALTER FOREIGN DATA_P WRAPPER name opt_fdw_options alter_generic_options
5654 : {
5655 56 : AlterFdwStmt *n = makeNode(AlterFdwStmt);
5656 :
5657 56 : n->fdwname = $5;
5658 56 : n->func_options = $6;
5659 56 : n->options = $7;
5660 56 : $$ = (Node *) n;
5661 : }
5662 : | ALTER FOREIGN DATA_P WRAPPER name fdw_options
5663 : {
5664 44 : AlterFdwStmt *n = makeNode(AlterFdwStmt);
5665 :
5666 44 : n->fdwname = $5;
5667 44 : n->func_options = $6;
5668 44 : n->options = NIL;
5669 44 : $$ = (Node *) n;
5670 : }
5671 : ;
5672 :
5673 : /* Options definition for CREATE FDW, SERVER and USER MAPPING */
5674 : create_generic_options:
5675 434 : OPTIONS '(' generic_option_list ')' { $$ = $3; }
5676 44133 : | /*EMPTY*/ { $$ = NIL; }
5677 : ;
5678 :
5679 : generic_option_list:
5680 : generic_option_elem
5681 : {
5682 434 : $$ = list_make1($1);
5683 : }
5684 : | generic_option_list ',' generic_option_elem
5685 : {
5686 293 : $$ = lappend($1, $3);
5687 : }
5688 : ;
5689 :
5690 : /* Options definition for ALTER FDW, SERVER and USER MAPPING */
5691 : alter_generic_options:
5692 294 : OPTIONS '(' alter_generic_option_list ')' { $$ = $3; }
5693 : ;
5694 :
5695 : alter_generic_option_list:
5696 : alter_generic_option_elem
5697 : {
5698 294 : $$ = list_make1($1);
5699 : }
5700 : | alter_generic_option_list ',' alter_generic_option_elem
5701 : {
5702 103 : $$ = lappend($1, $3);
5703 : }
5704 : ;
5705 :
5706 : alter_generic_option_elem:
5707 : generic_option_elem
5708 : {
5709 119 : $$ = $1;
5710 : }
5711 : | SET generic_option_elem
5712 : {
5713 73 : $$ = $2;
5714 73 : $$->defaction = DEFELEM_SET;
5715 : }
5716 : | ADD_P generic_option_elem
5717 : {
5718 129 : $$ = $2;
5719 129 : $$->defaction = DEFELEM_ADD;
5720 : }
5721 : | DROP generic_option_name
5722 : {
5723 76 : $$ = makeDefElemExtended(NULL, $2, NULL, DEFELEM_DROP, @2);
5724 : }
5725 : ;
5726 :
5727 : generic_option_elem:
5728 : generic_option_name generic_option_arg
5729 : {
5730 1048 : $$ = makeDefElem($1, $2, @1);
5731 : }
5732 : ;
5733 :
5734 : generic_option_name:
5735 1124 : ColLabel { $$ = $1; }
5736 : ;
5737 :
5738 : /* We could use def_arg here, but the spec only requires string literals */
5739 : generic_option_arg:
5740 1048 : Sconst { $$ = (Node *) makeString($1); }
5741 : ;
5742 :
5743 : /*****************************************************************************
5744 : *
5745 : * QUERY:
5746 : * CREATE SERVER name [TYPE] [VERSION] [OPTIONS]
5747 : *
5748 : *****************************************************************************/
5749 :
5750 : CreateForeignServerStmt: CREATE SERVER name opt_type opt_foreign_server_version
5751 : FOREIGN DATA_P WRAPPER name create_generic_options
5752 : {
5753 177 : CreateForeignServerStmt *n = makeNode(CreateForeignServerStmt);
5754 :
5755 177 : n->servername = $3;
5756 177 : n->servertype = $4;
5757 177 : n->version = $5;
5758 177 : n->fdwname = $9;
5759 177 : n->options = $10;
5760 177 : n->if_not_exists = false;
5761 177 : $$ = (Node *) n;
5762 : }
5763 : | CREATE SERVER IF_P NOT EXISTS name opt_type opt_foreign_server_version
5764 : FOREIGN DATA_P WRAPPER name create_generic_options
5765 : {
5766 13 : CreateForeignServerStmt *n = makeNode(CreateForeignServerStmt);
5767 :
5768 13 : n->servername = $6;
5769 13 : n->servertype = $7;
5770 13 : n->version = $8;
5771 13 : n->fdwname = $12;
5772 13 : n->options = $13;
5773 13 : n->if_not_exists = true;
5774 13 : $$ = (Node *) n;
5775 : }
5776 : ;
5777 :
5778 : opt_type:
5779 12 : TYPE_P Sconst { $$ = $2; }
5780 178 : | /*EMPTY*/ { $$ = NULL; }
5781 : ;
5782 :
5783 :
5784 : foreign_server_version:
5785 44 : VERSION_P Sconst { $$ = $2; }
5786 0 : | VERSION_P NULL_P { $$ = NULL; }
5787 : ;
5788 :
5789 : opt_foreign_server_version:
5790 12 : foreign_server_version { $$ = $1; }
5791 178 : | /*EMPTY*/ { $$ = NULL; }
5792 : ;
5793 :
5794 : /*****************************************************************************
5795 : *
5796 : * QUERY :
5797 : * ALTER SERVER name [VERSION] [OPTIONS]
5798 : *
5799 : ****************************************************************************/
5800 :
5801 : AlterForeignServerStmt: ALTER SERVER name foreign_server_version alter_generic_options
5802 : {
5803 4 : AlterForeignServerStmt *n = makeNode(AlterForeignServerStmt);
5804 :
5805 4 : n->servername = $3;
5806 4 : n->version = $4;
5807 4 : n->options = $5;
5808 4 : n->has_version = true;
5809 4 : $$ = (Node *) n;
5810 : }
5811 : | ALTER SERVER name foreign_server_version
5812 : {
5813 28 : AlterForeignServerStmt *n = makeNode(AlterForeignServerStmt);
5814 :
5815 28 : n->servername = $3;
5816 28 : n->version = $4;
5817 28 : n->has_version = true;
5818 28 : $$ = (Node *) n;
5819 : }
5820 : | ALTER SERVER name alter_generic_options
5821 : {
5822 97 : AlterForeignServerStmt *n = makeNode(AlterForeignServerStmt);
5823 :
5824 97 : n->servername = $3;
5825 97 : n->options = $4;
5826 97 : $$ = (Node *) n;
5827 : }
5828 : ;
5829 :
5830 : /*****************************************************************************
5831 : *
5832 : * QUERY:
5833 : * CREATE FOREIGN TABLE relname (...) SERVER name (...)
5834 : *
5835 : *****************************************************************************/
5836 :
5837 : CreateForeignTableStmt:
5838 : CREATE FOREIGN TABLE qualified_name
5839 : '(' OptTableElementList ')'
5840 : OptInherit SERVER name create_generic_options
5841 : {
5842 238 : CreateForeignTableStmt *n = makeNode(CreateForeignTableStmt);
5843 :
5844 238 : $4->relpersistence = RELPERSISTENCE_PERMANENT;
5845 238 : n->base.relation = $4;
5846 238 : n->base.tableElts = $6;
5847 238 : n->base.inhRelations = $8;
5848 238 : n->base.ofTypename = NULL;
5849 238 : n->base.constraints = NIL;
5850 238 : n->base.options = NIL;
5851 238 : n->base.oncommit = ONCOMMIT_NOOP;
5852 238 : n->base.tablespacename = NULL;
5853 238 : n->base.if_not_exists = false;
5854 : /* FDW-specific data */
5855 238 : n->servername = $10;
5856 238 : n->options = $11;
5857 238 : $$ = (Node *) n;
5858 : }
5859 : | CREATE FOREIGN TABLE IF_P NOT EXISTS qualified_name
5860 : '(' OptTableElementList ')'
5861 : OptInherit SERVER name create_generic_options
5862 : {
5863 0 : CreateForeignTableStmt *n = makeNode(CreateForeignTableStmt);
5864 :
5865 0 : $7->relpersistence = RELPERSISTENCE_PERMANENT;
5866 0 : n->base.relation = $7;
5867 0 : n->base.tableElts = $9;
5868 0 : n->base.inhRelations = $11;
5869 0 : n->base.ofTypename = NULL;
5870 0 : n->base.constraints = NIL;
5871 0 : n->base.options = NIL;
5872 0 : n->base.oncommit = ONCOMMIT_NOOP;
5873 0 : n->base.tablespacename = NULL;
5874 0 : n->base.if_not_exists = true;
5875 : /* FDW-specific data */
5876 0 : n->servername = $13;
5877 0 : n->options = $14;
5878 0 : $$ = (Node *) n;
5879 : }
5880 : | CREATE FOREIGN TABLE qualified_name
5881 : PARTITION OF qualified_name OptTypedTableElementList PartitionBoundSpec
5882 : SERVER name create_generic_options
5883 : {
5884 53 : CreateForeignTableStmt *n = makeNode(CreateForeignTableStmt);
5885 :
5886 53 : $4->relpersistence = RELPERSISTENCE_PERMANENT;
5887 53 : n->base.relation = $4;
5888 53 : n->base.inhRelations = list_make1($7);
5889 53 : n->base.tableElts = $8;
5890 53 : n->base.partbound = $9;
5891 53 : n->base.ofTypename = NULL;
5892 53 : n->base.constraints = NIL;
5893 53 : n->base.options = NIL;
5894 53 : n->base.oncommit = ONCOMMIT_NOOP;
5895 53 : n->base.tablespacename = NULL;
5896 53 : n->base.if_not_exists = false;
5897 : /* FDW-specific data */
5898 53 : n->servername = $11;
5899 53 : n->options = $12;
5900 53 : $$ = (Node *) n;
5901 : }
5902 : | CREATE FOREIGN TABLE IF_P NOT EXISTS qualified_name
5903 : PARTITION OF qualified_name OptTypedTableElementList PartitionBoundSpec
5904 : SERVER name create_generic_options
5905 : {
5906 0 : CreateForeignTableStmt *n = makeNode(CreateForeignTableStmt);
5907 :
5908 0 : $7->relpersistence = RELPERSISTENCE_PERMANENT;
5909 0 : n->base.relation = $7;
5910 0 : n->base.inhRelations = list_make1($10);
5911 0 : n->base.tableElts = $11;
5912 0 : n->base.partbound = $12;
5913 0 : n->base.ofTypename = NULL;
5914 0 : n->base.constraints = NIL;
5915 0 : n->base.options = NIL;
5916 0 : n->base.oncommit = ONCOMMIT_NOOP;
5917 0 : n->base.tablespacename = NULL;
5918 0 : n->base.if_not_exists = true;
5919 : /* FDW-specific data */
5920 0 : n->servername = $14;
5921 0 : n->options = $15;
5922 0 : $$ = (Node *) n;
5923 : }
5924 : ;
5925 :
5926 : /*****************************************************************************
5927 : *
5928 : * QUERY:
5929 : * IMPORT FOREIGN SCHEMA remote_schema
5930 : * [ { LIMIT TO | EXCEPT } ( table_list ) ]
5931 : * FROM SERVER server_name INTO local_schema [ OPTIONS (...) ]
5932 : *
5933 : ****************************************************************************/
5934 :
5935 : ImportForeignSchemaStmt:
5936 : IMPORT_P FOREIGN SCHEMA name import_qualification
5937 : FROM SERVER name INTO name create_generic_options
5938 : {
5939 28 : ImportForeignSchemaStmt *n = makeNode(ImportForeignSchemaStmt);
5940 :
5941 28 : n->server_name = $8;
5942 28 : n->remote_schema = $4;
5943 28 : n->local_schema = $10;
5944 28 : n->list_type = $5->type;
5945 28 : n->table_list = $5->table_names;
5946 28 : n->options = $11;
5947 28 : $$ = (Node *) n;
5948 : }
5949 : ;
5950 :
5951 : import_qualification_type:
5952 8 : LIMIT TO { $$ = FDW_IMPORT_SCHEMA_LIMIT_TO; }
5953 9 : | EXCEPT { $$ = FDW_IMPORT_SCHEMA_EXCEPT; }
5954 : ;
5955 :
5956 : import_qualification:
5957 : import_qualification_type '(' relation_expr_list ')'
5958 : {
5959 17 : ImportQual *n = palloc_object(ImportQual);
5960 :
5961 17 : n->type = $1;
5962 17 : n->table_names = $3;
5963 17 : $$ = n;
5964 : }
5965 : | /*EMPTY*/
5966 : {
5967 11 : ImportQual *n = palloc_object(ImportQual);
5968 11 : n->type = FDW_IMPORT_SCHEMA_ALL;
5969 11 : n->table_names = NIL;
5970 11 : $$ = n;
5971 : }
5972 : ;
5973 :
5974 : /*****************************************************************************
5975 : *
5976 : * QUERY:
5977 : * CREATE USER MAPPING FOR auth_ident SERVER name [OPTIONS]
5978 : *
5979 : *****************************************************************************/
5980 :
5981 : CreateUserMappingStmt: CREATE USER MAPPING FOR auth_ident SERVER name create_generic_options
5982 : {
5983 158 : CreateUserMappingStmt *n = makeNode(CreateUserMappingStmt);
5984 :
5985 158 : n->user = $5;
5986 158 : n->servername = $7;
5987 158 : n->options = $8;
5988 158 : n->if_not_exists = false;
5989 158 : $$ = (Node *) n;
5990 : }
5991 : | CREATE USER MAPPING IF_P NOT EXISTS FOR auth_ident SERVER name create_generic_options
5992 : {
5993 4 : CreateUserMappingStmt *n = makeNode(CreateUserMappingStmt);
5994 :
5995 4 : n->user = $8;
5996 4 : n->servername = $10;
5997 4 : n->options = $11;
5998 4 : n->if_not_exists = true;
5999 4 : $$ = (Node *) n;
6000 : }
6001 : ;
6002 :
6003 : /* User mapping authorization identifier */
6004 282 : auth_ident: RoleSpec { $$ = $1; }
6005 29 : | USER { $$ = makeRoleSpec(ROLESPEC_CURRENT_USER, @1); }
6006 : ;
6007 :
6008 : /*****************************************************************************
6009 : *
6010 : * QUERY :
6011 : * DROP USER MAPPING FOR auth_ident SERVER name
6012 : *
6013 : * XXX you'd think this should have a CASCADE/RESTRICT option, even if it's
6014 : * only pro forma; but the SQL standard doesn't show one.
6015 : ****************************************************************************/
6016 :
6017 : DropUserMappingStmt: DROP USER MAPPING FOR auth_ident SERVER name
6018 : {
6019 57 : DropUserMappingStmt *n = makeNode(DropUserMappingStmt);
6020 :
6021 57 : n->user = $5;
6022 57 : n->servername = $7;
6023 57 : n->missing_ok = false;
6024 57 : $$ = (Node *) n;
6025 : }
6026 : | DROP USER MAPPING IF_P EXISTS FOR auth_ident SERVER name
6027 : {
6028 22 : DropUserMappingStmt *n = makeNode(DropUserMappingStmt);
6029 :
6030 22 : n->user = $7;
6031 22 : n->servername = $9;
6032 22 : n->missing_ok = true;
6033 22 : $$ = (Node *) n;
6034 : }
6035 : ;
6036 :
6037 : /*****************************************************************************
6038 : *
6039 : * QUERY :
6040 : * ALTER USER MAPPING FOR auth_ident SERVER name OPTIONS
6041 : *
6042 : ****************************************************************************/
6043 :
6044 : AlterUserMappingStmt: ALTER USER MAPPING FOR auth_ident SERVER name alter_generic_options
6045 : {
6046 70 : AlterUserMappingStmt *n = makeNode(AlterUserMappingStmt);
6047 :
6048 70 : n->user = $5;
6049 70 : n->servername = $7;
6050 70 : n->options = $8;
6051 70 : $$ = (Node *) n;
6052 : }
6053 : ;
6054 :
6055 : /*****************************************************************************
6056 : *
6057 : * QUERIES:
6058 : * CREATE POLICY name ON table
6059 : * [AS { PERMISSIVE | RESTRICTIVE } ]
6060 : * [FOR { SELECT | INSERT | UPDATE | DELETE } ]
6061 : * [TO role, ...]
6062 : * [USING (qual)] [WITH CHECK (with check qual)]
6063 : * ALTER POLICY name ON table [TO role, ...]
6064 : * [USING (qual)] [WITH CHECK (with check qual)]
6065 : *
6066 : *****************************************************************************/
6067 :
6068 : CreatePolicyStmt:
6069 : CREATE POLICY name ON qualified_name RowSecurityDefaultPermissive
6070 : RowSecurityDefaultForCmd RowSecurityDefaultToRole
6071 : RowSecurityOptionalExpr RowSecurityOptionalWithCheck
6072 : {
6073 563 : CreatePolicyStmt *n = makeNode(CreatePolicyStmt);
6074 :
6075 563 : n->policy_name = $3;
6076 563 : n->table = $5;
6077 563 : n->permissive = $6;
6078 563 : n->cmd_name = $7;
6079 563 : n->roles = $8;
6080 563 : n->qual = $9;
6081 563 : n->with_check = $10;
6082 563 : $$ = (Node *) n;
6083 : }
6084 : ;
6085 :
6086 : AlterPolicyStmt:
6087 : ALTER POLICY name ON qualified_name RowSecurityOptionalToRole
6088 : RowSecurityOptionalExpr RowSecurityOptionalWithCheck
6089 : {
6090 56 : AlterPolicyStmt *n = makeNode(AlterPolicyStmt);
6091 :
6092 56 : n->policy_name = $3;
6093 56 : n->table = $5;
6094 56 : n->roles = $6;
6095 56 : n->qual = $7;
6096 56 : n->with_check = $8;
6097 56 : $$ = (Node *) n;
6098 : }
6099 : ;
6100 :
6101 : RowSecurityOptionalExpr:
6102 573 : USING '(' a_expr ')' { $$ = $3; }
6103 46 : | /* EMPTY */ { $$ = NULL; }
6104 : ;
6105 :
6106 : RowSecurityOptionalWithCheck:
6107 99 : WITH CHECK '(' a_expr ')' { $$ = $4; }
6108 520 : | /* EMPTY */ { $$ = NULL; }
6109 : ;
6110 :
6111 : RowSecurityDefaultToRole:
6112 113 : TO role_list { $$ = $2; }
6113 450 : | /* EMPTY */ { $$ = list_make1(makeRoleSpec(ROLESPEC_PUBLIC, -1)); }
6114 : ;
6115 :
6116 : RowSecurityOptionalToRole:
6117 8 : TO role_list { $$ = $2; }
6118 48 : | /* EMPTY */ { $$ = NULL; }
6119 : ;
6120 :
6121 : RowSecurityDefaultPermissive:
6122 : AS IDENT
6123 : {
6124 105 : if (strcmp($2, "permissive") == 0)
6125 36 : $$ = true;
6126 69 : else if (strcmp($2, "restrictive") == 0)
6127 65 : $$ = false;
6128 : else
6129 4 : ereport(ERROR,
6130 : (errcode(ERRCODE_SYNTAX_ERROR),
6131 : errmsg("unrecognized row security option \"%s\"", $2),
6132 : errhint("Only PERMISSIVE or RESTRICTIVE policies are supported currently."),
6133 : parser_errposition(@2)));
6134 :
6135 : }
6136 462 : | /* EMPTY */ { $$ = true; }
6137 : ;
6138 :
6139 : RowSecurityDefaultForCmd:
6140 253 : FOR row_security_cmd { $$ = $2; }
6141 310 : | /* EMPTY */ { $$ = "all"; }
6142 : ;
6143 :
6144 : row_security_cmd:
6145 29 : ALL { $$ = "all"; }
6146 93 : | SELECT { $$ = "select"; }
6147 37 : | INSERT { $$ = "insert"; }
6148 63 : | UPDATE { $$ = "update"; }
6149 31 : | DELETE_P { $$ = "delete"; }
6150 : ;
6151 :
6152 : /*****************************************************************************
6153 : *
6154 : * QUERY:
6155 : * CREATE ACCESS METHOD name HANDLER handler_name
6156 : *
6157 : *****************************************************************************/
6158 :
6159 : CreateAmStmt: CREATE ACCESS METHOD name TYPE_P am_type HANDLER handler_name
6160 : {
6161 46 : CreateAmStmt *n = makeNode(CreateAmStmt);
6162 :
6163 46 : n->amname = $4;
6164 46 : n->handler_name = $8;
6165 46 : n->amtype = $6;
6166 46 : $$ = (Node *) n;
6167 : }
6168 : ;
6169 :
6170 : am_type:
6171 20 : INDEX { $$ = AMTYPE_INDEX; }
6172 26 : | TABLE { $$ = AMTYPE_TABLE; }
6173 : ;
6174 :
6175 : /*****************************************************************************
6176 : *
6177 : * QUERIES :
6178 : * CREATE TRIGGER ...
6179 : *
6180 : *****************************************************************************/
6181 :
6182 : CreateTrigStmt:
6183 : CREATE opt_or_replace TRIGGER name TriggerActionTime TriggerEvents ON
6184 : qualified_name TriggerReferencing TriggerForSpec TriggerWhen
6185 : EXECUTE FUNCTION_or_PROCEDURE func_name '(' TriggerFuncArgs ')'
6186 : {
6187 1993 : CreateTrigStmt *n = makeNode(CreateTrigStmt);
6188 :
6189 1993 : n->replace = $2;
6190 1993 : n->isconstraint = false;
6191 1993 : n->trigname = $4;
6192 1993 : n->relation = $8;
6193 1993 : n->funcname = $14;
6194 1993 : n->args = $16;
6195 1993 : n->row = $10;
6196 1993 : n->timing = $5;
6197 1993 : n->events = intVal(linitial($6));
6198 1993 : n->columns = (List *) lsecond($6);
6199 1993 : n->whenClause = $11;
6200 1993 : n->transitionRels = $9;
6201 1993 : n->deferrable = false;
6202 1993 : n->initdeferred = false;
6203 1993 : n->constrrel = NULL;
6204 1993 : $$ = (Node *) n;
6205 : }
6206 : | CREATE opt_or_replace CONSTRAINT TRIGGER name AFTER TriggerEvents ON
6207 : qualified_name OptConstrFromTable ConstraintAttributeSpec
6208 : FOR EACH ROW TriggerWhen
6209 : EXECUTE FUNCTION_or_PROCEDURE func_name '(' TriggerFuncArgs ')'
6210 : {
6211 53 : CreateTrigStmt *n = makeNode(CreateTrigStmt);
6212 : bool dummy;
6213 :
6214 53 : if (($11 & CAS_NOT_VALID) != 0)
6215 4 : ereport(ERROR,
6216 : errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
6217 : errmsg("constraint triggers cannot be marked %s",
6218 : "NOT VALID"),
6219 : parser_errposition(@11));
6220 49 : if (($11 & CAS_NO_INHERIT) != 0)
6221 4 : ereport(ERROR,
6222 : errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
6223 : errmsg("constraint triggers cannot be marked %s",
6224 : "NO INHERIT"),
6225 : parser_errposition(@11));
6226 45 : if (($11 & CAS_NOT_ENFORCED) != 0)
6227 4 : ereport(ERROR,
6228 : errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
6229 : errmsg("constraint triggers cannot be marked %s",
6230 : "NOT ENFORCED"),
6231 : parser_errposition(@11));
6232 :
6233 41 : n->replace = $2;
6234 41 : if (n->replace) /* not supported, see CreateTrigger */
6235 0 : ereport(ERROR,
6236 : (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
6237 : errmsg("CREATE OR REPLACE CONSTRAINT TRIGGER is not supported"),
6238 : parser_errposition(@1)));
6239 41 : n->isconstraint = true;
6240 41 : n->trigname = $5;
6241 41 : n->relation = $9;
6242 41 : n->funcname = $18;
6243 41 : n->args = $20;
6244 41 : n->row = true;
6245 41 : n->timing = TRIGGER_TYPE_AFTER;
6246 41 : n->events = intVal(linitial($7));
6247 41 : n->columns = (List *) lsecond($7);
6248 41 : n->whenClause = $15;
6249 41 : n->transitionRels = NIL;
6250 41 : processCASbits($11, @11, "TRIGGER",
6251 : &n->deferrable, &n->initdeferred, &dummy,
6252 : NULL, NULL, yyscanner);
6253 41 : n->constrrel = $10;
6254 41 : $$ = (Node *) n;
6255 : }
6256 : ;
6257 :
6258 : TriggerActionTime:
6259 894 : BEFORE { $$ = TRIGGER_TYPE_BEFORE; }
6260 1012 : | AFTER { $$ = TRIGGER_TYPE_AFTER; }
6261 95 : | INSTEAD OF { $$ = TRIGGER_TYPE_INSTEAD; }
6262 : ;
6263 :
6264 : TriggerEvents:
6265 : TriggerOneEvent
6266 2054 : { $$ = $1; }
6267 : | TriggerEvents OR TriggerOneEvent
6268 : {
6269 695 : int events1 = intVal(linitial($1));
6270 695 : int events2 = intVal(linitial($3));
6271 695 : List *columns1 = (List *) lsecond($1);
6272 695 : List *columns2 = (List *) lsecond($3);
6273 :
6274 695 : if (events1 & events2)
6275 4 : parser_yyerror("duplicate trigger events specified");
6276 : /*
6277 : * concat'ing the columns lists loses information about
6278 : * which columns went with which event, but so long as
6279 : * only UPDATE carries columns and we disallow multiple
6280 : * UPDATE items, it doesn't matter. Command execution
6281 : * should just ignore the columns for non-UPDATE events.
6282 : */
6283 691 : $$ = list_make2(makeInteger(events1 | events2),
6284 : list_concat(columns1, columns2));
6285 : }
6286 : ;
6287 :
6288 : TriggerOneEvent:
6289 : INSERT
6290 1085 : { $$ = list_make2(makeInteger(TRIGGER_TYPE_INSERT), NIL); }
6291 : | DELETE_P
6292 537 : { $$ = list_make2(makeInteger(TRIGGER_TYPE_DELETE), NIL); }
6293 : | UPDATE
6294 1036 : { $$ = list_make2(makeInteger(TRIGGER_TYPE_UPDATE), NIL); }
6295 : | UPDATE OF columnList
6296 65 : { $$ = list_make2(makeInteger(TRIGGER_TYPE_UPDATE), $3); }
6297 : | TRUNCATE
6298 26 : { $$ = list_make2(makeInteger(TRIGGER_TYPE_TRUNCATE), NIL); }
6299 : ;
6300 :
6301 : TriggerReferencing:
6302 304 : REFERENCING TriggerTransitions { $$ = $2; }
6303 1689 : | /*EMPTY*/ { $$ = NIL; }
6304 : ;
6305 :
6306 : TriggerTransitions:
6307 304 : TriggerTransition { $$ = list_make1($1); }
6308 92 : | TriggerTransitions TriggerTransition { $$ = lappend($1, $2); }
6309 : ;
6310 :
6311 : TriggerTransition:
6312 : TransitionOldOrNew TransitionRowOrTable opt_as TransitionRelName
6313 : {
6314 396 : TriggerTransition *n = makeNode(TriggerTransition);
6315 :
6316 396 : n->name = $4;
6317 396 : n->isNew = $1;
6318 396 : n->isTable = $2;
6319 396 : $$ = (Node *) n;
6320 : }
6321 : ;
6322 :
6323 : TransitionOldOrNew:
6324 216 : NEW { $$ = true; }
6325 180 : | OLD { $$ = false; }
6326 : ;
6327 :
6328 : TransitionRowOrTable:
6329 396 : TABLE { $$ = true; }
6330 : /*
6331 : * According to the standard, lack of a keyword here implies ROW.
6332 : * Support for that would require prohibiting ROW entirely here,
6333 : * reserving the keyword ROW, and/or requiring AS (instead of
6334 : * allowing it to be optional, as the standard specifies) as the
6335 : * next token. Requiring ROW seems cleanest and easiest to
6336 : * explain.
6337 : */
6338 0 : | ROW { $$ = false; }
6339 : ;
6340 :
6341 : TransitionRelName:
6342 396 : ColId { $$ = $1; }
6343 : ;
6344 :
6345 : TriggerForSpec:
6346 : FOR TriggerForOptEach TriggerForType
6347 : {
6348 1859 : $$ = $3;
6349 : }
6350 : | /* EMPTY */
6351 : {
6352 : /*
6353 : * If ROW/STATEMENT not specified, default to
6354 : * STATEMENT, per SQL
6355 : */
6356 134 : $$ = false;
6357 : }
6358 : ;
6359 :
6360 : TriggerForOptEach:
6361 : EACH
6362 : | /*EMPTY*/
6363 : ;
6364 :
6365 : TriggerForType:
6366 1313 : ROW { $$ = true; }
6367 546 : | STATEMENT { $$ = false; }
6368 : ;
6369 :
6370 : TriggerWhen:
6371 124 : WHEN '(' a_expr ')' { $$ = $3; }
6372 1922 : | /*EMPTY*/ { $$ = NULL; }
6373 : ;
6374 :
6375 : FUNCTION_or_PROCEDURE:
6376 : FUNCTION
6377 : | PROCEDURE
6378 : ;
6379 :
6380 : TriggerFuncArgs:
6381 377 : TriggerFuncArg { $$ = list_make1($1); }
6382 86 : | TriggerFuncArgs ',' TriggerFuncArg { $$ = lappend($1, $3); }
6383 1669 : | /*EMPTY*/ { $$ = NIL; }
6384 : ;
6385 :
6386 : TriggerFuncArg:
6387 : Iconst
6388 : {
6389 51 : $$ = (Node *) makeString(psprintf("%d", $1));
6390 : }
6391 0 : | FCONST { $$ = (Node *) makeString($1); }
6392 399 : | Sconst { $$ = (Node *) makeString($1); }
6393 13 : | ColLabel { $$ = (Node *) makeString($1); }
6394 : ;
6395 :
6396 : OptConstrFromTable:
6397 8 : FROM qualified_name { $$ = $2; }
6398 45 : | /*EMPTY*/ { $$ = NULL; }
6399 : ;
6400 :
6401 : ConstraintAttributeSpec:
6402 : /*EMPTY*/
6403 10826 : { $$ = 0; }
6404 : | ConstraintAttributeSpec ConstraintAttributeElem
6405 : {
6406 : /*
6407 : * We must complain about conflicting options.
6408 : * We could, but choose not to, complain about redundant
6409 : * options (ie, where $2's bit is already set in $1).
6410 : */
6411 1195 : int newspec = $1 | $2;
6412 :
6413 : /* special message for this case */
6414 1195 : if ((newspec & (CAS_NOT_DEFERRABLE | CAS_INITIALLY_DEFERRED)) == (CAS_NOT_DEFERRABLE | CAS_INITIALLY_DEFERRED))
6415 4 : ereport(ERROR,
6416 : (errcode(ERRCODE_SYNTAX_ERROR),
6417 : errmsg("constraint declared INITIALLY DEFERRED must be DEFERRABLE"),
6418 : parser_errposition(@2)));
6419 : /* generic message for other conflicts */
6420 1191 : if ((newspec & (CAS_NOT_DEFERRABLE | CAS_DEFERRABLE)) == (CAS_NOT_DEFERRABLE | CAS_DEFERRABLE) ||
6421 1191 : (newspec & (CAS_INITIALLY_IMMEDIATE | CAS_INITIALLY_DEFERRED)) == (CAS_INITIALLY_IMMEDIATE | CAS_INITIALLY_DEFERRED) ||
6422 1191 : (newspec & (CAS_NOT_ENFORCED | CAS_ENFORCED)) == (CAS_NOT_ENFORCED | CAS_ENFORCED))
6423 4 : ereport(ERROR,
6424 : (errcode(ERRCODE_SYNTAX_ERROR),
6425 : errmsg("conflicting constraint properties"),
6426 : parser_errposition(@2)));
6427 1187 : $$ = newspec;
6428 : }
6429 : ;
6430 :
6431 : ConstraintAttributeElem:
6432 28 : NOT DEFERRABLE { $$ = CAS_NOT_DEFERRABLE; }
6433 131 : | DEFERRABLE { $$ = CAS_DEFERRABLE; }
6434 20 : | INITIALLY IMMEDIATE { $$ = CAS_INITIALLY_IMMEDIATE; }
6435 100 : | INITIALLY DEFERRED { $$ = CAS_INITIALLY_DEFERRED; }
6436 442 : | NOT VALID { $$ = CAS_NOT_VALID; }
6437 167 : | NO INHERIT { $$ = CAS_NO_INHERIT; }
6438 167 : | NOT ENFORCED { $$ = CAS_NOT_ENFORCED; }
6439 140 : | ENFORCED { $$ = CAS_ENFORCED; }
6440 : ;
6441 :
6442 :
6443 : /*****************************************************************************
6444 : *
6445 : * QUERIES :
6446 : * CREATE EVENT TRIGGER ...
6447 : * ALTER EVENT TRIGGER ...
6448 : *
6449 : *****************************************************************************/
6450 :
6451 : CreateEventTrigStmt:
6452 : CREATE EVENT TRIGGER name ON ColLabel
6453 : EXECUTE FUNCTION_or_PROCEDURE func_name '(' ')'
6454 : {
6455 63 : CreateEventTrigStmt *n = makeNode(CreateEventTrigStmt);
6456 :
6457 63 : n->trigname = $4;
6458 63 : n->eventname = $6;
6459 63 : n->whenclause = NULL;
6460 63 : n->funcname = $9;
6461 63 : $$ = (Node *) n;
6462 : }
6463 : | CREATE EVENT TRIGGER name ON ColLabel
6464 : WHEN event_trigger_when_list
6465 : EXECUTE FUNCTION_or_PROCEDURE func_name '(' ')'
6466 : {
6467 65 : CreateEventTrigStmt *n = makeNode(CreateEventTrigStmt);
6468 :
6469 65 : n->trigname = $4;
6470 65 : n->eventname = $6;
6471 65 : n->whenclause = $8;
6472 65 : n->funcname = $11;
6473 65 : $$ = (Node *) n;
6474 : }
6475 : ;
6476 :
6477 : event_trigger_when_list:
6478 : event_trigger_when_item
6479 65 : { $$ = list_make1($1); }
6480 : | event_trigger_when_list AND event_trigger_when_item
6481 4 : { $$ = lappend($1, $3); }
6482 : ;
6483 :
6484 : event_trigger_when_item:
6485 : ColId IN_P '(' event_trigger_value_list ')'
6486 69 : { $$ = makeDefElem($1, (Node *) $4, @1); }
6487 : ;
6488 :
6489 : event_trigger_value_list:
6490 : SCONST
6491 69 : { $$ = list_make1(makeString($1)); }
6492 : | event_trigger_value_list ',' SCONST
6493 44 : { $$ = lappend($1, makeString($3)); }
6494 : ;
6495 :
6496 : AlterEventTrigStmt:
6497 : ALTER EVENT TRIGGER name enable_trigger
6498 : {
6499 31 : AlterEventTrigStmt *n = makeNode(AlterEventTrigStmt);
6500 :
6501 31 : n->trigname = $4;
6502 31 : n->tgenabled = $5;
6503 31 : $$ = (Node *) n;
6504 : }
6505 : ;
6506 :
6507 : enable_trigger:
6508 4 : ENABLE_P { $$ = TRIGGER_FIRES_ON_ORIGIN; }
6509 4 : | ENABLE_P REPLICA { $$ = TRIGGER_FIRES_ON_REPLICA; }
6510 10 : | ENABLE_P ALWAYS { $$ = TRIGGER_FIRES_ALWAYS; }
6511 13 : | DISABLE_P { $$ = TRIGGER_DISABLED; }
6512 : ;
6513 :
6514 : /*****************************************************************************
6515 : *
6516 : * QUERY :
6517 : * CREATE ASSERTION ...
6518 : *
6519 : *****************************************************************************/
6520 :
6521 : CreateAssertionStmt:
6522 : CREATE ASSERTION any_name CHECK '(' a_expr ')' ConstraintAttributeSpec
6523 : {
6524 0 : ereport(ERROR,
6525 : (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
6526 : errmsg("CREATE ASSERTION is not yet implemented"),
6527 : parser_errposition(@1)));
6528 :
6529 : $$ = NULL;
6530 : }
6531 : ;
6532 :
6533 :
6534 : /*****************************************************************************
6535 : *
6536 : * QUERY :
6537 : * define (aggregate,operator,type)
6538 : *
6539 : *****************************************************************************/
6540 :
6541 : DefineStmt:
6542 : CREATE opt_or_replace AGGREGATE func_name aggr_args definition
6543 : {
6544 341 : DefineStmt *n = makeNode(DefineStmt);
6545 :
6546 341 : n->kind = OBJECT_AGGREGATE;
6547 341 : n->oldstyle = false;
6548 341 : n->replace = $2;
6549 341 : n->defnames = $4;
6550 341 : n->args = $5;
6551 341 : n->definition = $6;
6552 341 : $$ = (Node *) n;
6553 : }
6554 : | CREATE opt_or_replace AGGREGATE func_name old_aggr_definition
6555 : {
6556 : /* old-style (pre-8.2) syntax for CREATE AGGREGATE */
6557 240 : DefineStmt *n = makeNode(DefineStmt);
6558 :
6559 240 : n->kind = OBJECT_AGGREGATE;
6560 240 : n->oldstyle = true;
6561 240 : n->replace = $2;
6562 240 : n->defnames = $4;
6563 240 : n->args = NIL;
6564 240 : n->definition = $5;
6565 240 : $$ = (Node *) n;
6566 : }
6567 : | CREATE OPERATOR any_operator definition
6568 : {
6569 889 : DefineStmt *n = makeNode(DefineStmt);
6570 :
6571 889 : n->kind = OBJECT_OPERATOR;
6572 889 : n->oldstyle = false;
6573 889 : n->defnames = $3;
6574 889 : n->args = NIL;
6575 889 : n->definition = $4;
6576 889 : $$ = (Node *) n;
6577 : }
6578 : | CREATE TYPE_P any_name definition
6579 : {
6580 137 : DefineStmt *n = makeNode(DefineStmt);
6581 :
6582 137 : n->kind = OBJECT_TYPE;
6583 137 : n->oldstyle = false;
6584 137 : n->defnames = $3;
6585 137 : n->args = NIL;
6586 137 : n->definition = $4;
6587 137 : $$ = (Node *) n;
6588 : }
6589 : | CREATE TYPE_P any_name
6590 : {
6591 : /* Shell type (identified by lack of definition) */
6592 93 : DefineStmt *n = makeNode(DefineStmt);
6593 :
6594 93 : n->kind = OBJECT_TYPE;
6595 93 : n->oldstyle = false;
6596 93 : n->defnames = $3;
6597 93 : n->args = NIL;
6598 93 : n->definition = NIL;
6599 93 : $$ = (Node *) n;
6600 : }
6601 : | CREATE TYPE_P any_name AS '(' OptTableFuncElementList ')'
6602 : {
6603 2358 : CompositeTypeStmt *n = makeNode(CompositeTypeStmt);
6604 :
6605 : /* can't use qualified_name, sigh */
6606 2358 : n->typevar = makeRangeVarFromAnyName($3, @3, yyscanner);
6607 2358 : n->coldeflist = $6;
6608 2358 : $$ = (Node *) n;
6609 : }
6610 : | CREATE TYPE_P any_name AS ENUM_P '(' opt_enum_val_list ')'
6611 : {
6612 128 : CreateEnumStmt *n = makeNode(CreateEnumStmt);
6613 :
6614 128 : n->typeName = $3;
6615 128 : n->vals = $7;
6616 128 : $$ = (Node *) n;
6617 : }
6618 : | CREATE TYPE_P any_name AS RANGE definition
6619 : {
6620 127 : CreateRangeStmt *n = makeNode(CreateRangeStmt);
6621 :
6622 127 : n->typeName = $3;
6623 127 : n->params = $6;
6624 127 : $$ = (Node *) n;
6625 : }
6626 : | CREATE TEXT_P SEARCH PARSER any_name definition
6627 : {
6628 26 : DefineStmt *n = makeNode(DefineStmt);
6629 :
6630 26 : n->kind = OBJECT_TSPARSER;
6631 26 : n->args = NIL;
6632 26 : n->defnames = $5;
6633 26 : n->definition = $6;
6634 26 : $$ = (Node *) n;
6635 : }
6636 : | CREATE TEXT_P SEARCH DICTIONARY any_name definition
6637 : {
6638 1612 : DefineStmt *n = makeNode(DefineStmt);
6639 :
6640 1612 : n->kind = OBJECT_TSDICTIONARY;
6641 1612 : n->args = NIL;
6642 1612 : n->defnames = $5;
6643 1612 : n->definition = $6;
6644 1612 : $$ = (Node *) n;
6645 : }
6646 : | CREATE TEXT_P SEARCH TEMPLATE any_name definition
6647 : {
6648 77 : DefineStmt *n = makeNode(DefineStmt);
6649 :
6650 77 : n->kind = OBJECT_TSTEMPLATE;
6651 77 : n->args = NIL;
6652 77 : n->defnames = $5;
6653 77 : n->definition = $6;
6654 77 : $$ = (Node *) n;
6655 : }
6656 : | CREATE TEXT_P SEARCH CONFIGURATION any_name definition
6657 : {
6658 1576 : DefineStmt *n = makeNode(DefineStmt);
6659 :
6660 1576 : n->kind = OBJECT_TSCONFIGURATION;
6661 1576 : n->args = NIL;
6662 1576 : n->defnames = $5;
6663 1576 : n->definition = $6;
6664 1576 : $$ = (Node *) n;
6665 : }
6666 : | CREATE COLLATION any_name definition
6667 : {
6668 196 : DefineStmt *n = makeNode(DefineStmt);
6669 :
6670 196 : n->kind = OBJECT_COLLATION;
6671 196 : n->args = NIL;
6672 196 : n->defnames = $3;
6673 196 : n->definition = $4;
6674 196 : $$ = (Node *) n;
6675 : }
6676 : | CREATE COLLATION IF_P NOT EXISTS any_name definition
6677 : {
6678 9 : DefineStmt *n = makeNode(DefineStmt);
6679 :
6680 9 : n->kind = OBJECT_COLLATION;
6681 9 : n->args = NIL;
6682 9 : n->defnames = $6;
6683 9 : n->definition = $7;
6684 9 : n->if_not_exists = true;
6685 9 : $$ = (Node *) n;
6686 : }
6687 : | CREATE COLLATION any_name FROM any_name
6688 : {
6689 35 : DefineStmt *n = makeNode(DefineStmt);
6690 :
6691 35 : n->kind = OBJECT_COLLATION;
6692 35 : n->args = NIL;
6693 35 : n->defnames = $3;
6694 35 : n->definition = list_make1(makeDefElem("from", (Node *) $5, @5));
6695 35 : $$ = (Node *) n;
6696 : }
6697 : | CREATE COLLATION IF_P NOT EXISTS any_name FROM any_name
6698 : {
6699 0 : DefineStmt *n = makeNode(DefineStmt);
6700 :
6701 0 : n->kind = OBJECT_COLLATION;
6702 0 : n->args = NIL;
6703 0 : n->defnames = $6;
6704 0 : n->definition = list_make1(makeDefElem("from", (Node *) $8, @8));
6705 0 : n->if_not_exists = true;
6706 0 : $$ = (Node *) n;
6707 : }
6708 : ;
6709 :
6710 5696 : definition: '(' def_list ')' { $$ = $2; }
6711 : ;
6712 :
6713 5696 : def_list: def_elem { $$ = list_make1($1); }
6714 8176 : | def_list ',' def_elem { $$ = lappend($1, $3); }
6715 : ;
6716 :
6717 : def_elem: ColLabel '=' def_arg
6718 : {
6719 13677 : $$ = makeDefElem($1, (Node *) $3, @1);
6720 : }
6721 : | ColLabel
6722 : {
6723 195 : $$ = makeDefElem($1, NULL, @1);
6724 : }
6725 : ;
6726 :
6727 : /* Note: any simple identifier will be returned as a type name! */
6728 11134 : def_arg: func_type { $$ = (Node *) $1; }
6729 2453 : | reserved_keyword { $$ = (Node *) makeString(pstrdup($1)); }
6730 626 : | qual_all_Op { $$ = (Node *) $1; }
6731 871 : | NumericOnly { $$ = (Node *) $1; }
6732 1142 : | Sconst { $$ = (Node *) makeString($1); }
6733 133 : | NONE { $$ = (Node *) makeString(pstrdup($1)); }
6734 : ;
6735 :
6736 240 : old_aggr_definition: '(' old_aggr_list ')' { $$ = $2; }
6737 : ;
6738 :
6739 240 : old_aggr_list: old_aggr_elem { $$ = list_make1($1); }
6740 856 : | old_aggr_list ',' old_aggr_elem { $$ = lappend($1, $3); }
6741 : ;
6742 :
6743 : /*
6744 : * Must use IDENT here to avoid reduce/reduce conflicts; fortunately none of
6745 : * the item names needed in old aggregate definitions are likely to become
6746 : * SQL keywords.
6747 : */
6748 : old_aggr_elem: IDENT '=' def_arg
6749 : {
6750 1096 : $$ = makeDefElem($1, (Node *) $3, @1);
6751 : }
6752 : ;
6753 :
6754 : opt_enum_val_list:
6755 124 : enum_val_list { $$ = $1; }
6756 4 : | /*EMPTY*/ { $$ = NIL; }
6757 : ;
6758 :
6759 : enum_val_list: Sconst
6760 124 : { $$ = list_make1(makeString($1)); }
6761 : | enum_val_list ',' Sconst
6762 5258 : { $$ = lappend($1, makeString($3)); }
6763 : ;
6764 :
6765 : /*****************************************************************************
6766 : *
6767 : * ALTER TYPE enumtype ADD ...
6768 : *
6769 : *****************************************************************************/
6770 :
6771 : AlterEnumStmt:
6772 : ALTER TYPE_P any_name ADD_P VALUE_P opt_if_not_exists Sconst
6773 : {
6774 86 : AlterEnumStmt *n = makeNode(AlterEnumStmt);
6775 :
6776 86 : n->typeName = $3;
6777 86 : n->oldVal = NULL;
6778 86 : n->newVal = $7;
6779 86 : n->newValNeighbor = NULL;
6780 86 : n->newValIsAfter = true;
6781 86 : n->skipIfNewValExists = $6;
6782 86 : $$ = (Node *) n;
6783 : }
6784 : | ALTER TYPE_P any_name ADD_P VALUE_P opt_if_not_exists Sconst BEFORE Sconst
6785 : {
6786 130 : AlterEnumStmt *n = makeNode(AlterEnumStmt);
6787 :
6788 130 : n->typeName = $3;
6789 130 : n->oldVal = NULL;
6790 130 : n->newVal = $7;
6791 130 : n->newValNeighbor = $9;
6792 130 : n->newValIsAfter = false;
6793 130 : n->skipIfNewValExists = $6;
6794 130 : $$ = (Node *) n;
6795 : }
6796 : | ALTER TYPE_P any_name ADD_P VALUE_P opt_if_not_exists Sconst AFTER Sconst
6797 : {
6798 14 : AlterEnumStmt *n = makeNode(AlterEnumStmt);
6799 :
6800 14 : n->typeName = $3;
6801 14 : n->oldVal = NULL;
6802 14 : n->newVal = $7;
6803 14 : n->newValNeighbor = $9;
6804 14 : n->newValIsAfter = true;
6805 14 : n->skipIfNewValExists = $6;
6806 14 : $$ = (Node *) n;
6807 : }
6808 : | ALTER TYPE_P any_name RENAME VALUE_P Sconst TO Sconst
6809 : {
6810 16 : AlterEnumStmt *n = makeNode(AlterEnumStmt);
6811 :
6812 16 : n->typeName = $3;
6813 16 : n->oldVal = $6;
6814 16 : n->newVal = $8;
6815 16 : n->newValNeighbor = NULL;
6816 16 : n->newValIsAfter = false;
6817 16 : n->skipIfNewValExists = false;
6818 16 : $$ = (Node *) n;
6819 : }
6820 : | ALTER TYPE_P any_name DROP VALUE_P Sconst
6821 : {
6822 : /*
6823 : * The following problems must be solved before this can be
6824 : * implemented:
6825 : *
6826 : * - There must be no instance of the target value in
6827 : * any table.
6828 : *
6829 : * - The value must not appear in any catalog metadata,
6830 : * such as stored view expressions or column defaults.
6831 : *
6832 : * - The value must not appear in any non-leaf page of a
6833 : * btree (and similar issues with other index types).
6834 : * This is problematic because a value could persist
6835 : * there long after it's gone from user-visible data.
6836 : *
6837 : * - Concurrent sessions must not be able to insert the
6838 : * value while the preceding conditions are being checked.
6839 : *
6840 : * - Possibly more...
6841 : */
6842 0 : ereport(ERROR,
6843 : (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
6844 : errmsg("dropping an enum value is not implemented"),
6845 : parser_errposition(@4)));
6846 : }
6847 : ;
6848 :
6849 8 : opt_if_not_exists: IF_P NOT EXISTS { $$ = true; }
6850 222 : | /* EMPTY */ { $$ = false; }
6851 : ;
6852 :
6853 :
6854 : /*****************************************************************************
6855 : *
6856 : * QUERIES :
6857 : * CREATE OPERATOR CLASS ...
6858 : * CREATE OPERATOR FAMILY ...
6859 : * ALTER OPERATOR FAMILY ...
6860 : * DROP OPERATOR CLASS ...
6861 : * DROP OPERATOR FAMILY ...
6862 : *
6863 : *****************************************************************************/
6864 :
6865 : CreateOpClassStmt:
6866 : CREATE OPERATOR CLASS any_name opt_default FOR TYPE_P Typename
6867 : USING name opt_opfamily AS opclass_item_list
6868 : {
6869 295 : CreateOpClassStmt *n = makeNode(CreateOpClassStmt);
6870 :
6871 295 : n->opclassname = $4;
6872 295 : n->isDefault = $5;
6873 295 : n->datatype = $8;
6874 295 : n->amname = $10;
6875 295 : n->opfamilyname = $11;
6876 295 : n->items = $13;
6877 295 : $$ = (Node *) n;
6878 : }
6879 : ;
6880 :
6881 : opclass_item_list:
6882 533 : opclass_item { $$ = list_make1($1); }
6883 2994 : | opclass_item_list ',' opclass_item { $$ = lappend($1, $3); }
6884 : ;
6885 :
6886 : opclass_item:
6887 : OPERATOR Iconst any_operator opclass_purpose
6888 : {
6889 1063 : CreateOpClassItem *n = makeNode(CreateOpClassItem);
6890 1063 : ObjectWithArgs *owa = makeNode(ObjectWithArgs);
6891 :
6892 1063 : owa->objname = $3;
6893 1063 : owa->objargs = NIL;
6894 1063 : n->itemtype = OPCLASS_ITEM_OPERATOR;
6895 1063 : n->name = owa;
6896 1063 : n->number = $2;
6897 1063 : n->order_family = $4;
6898 1063 : $$ = (Node *) n;
6899 : }
6900 : | OPERATOR Iconst operator_with_argtypes opclass_purpose
6901 : {
6902 739 : CreateOpClassItem *n = makeNode(CreateOpClassItem);
6903 :
6904 739 : n->itemtype = OPCLASS_ITEM_OPERATOR;
6905 739 : n->name = $3;
6906 739 : n->number = $2;
6907 739 : n->order_family = $4;
6908 739 : $$ = (Node *) n;
6909 : }
6910 : | FUNCTION Iconst function_with_argtypes
6911 : {
6912 1419 : CreateOpClassItem *n = makeNode(CreateOpClassItem);
6913 :
6914 1419 : n->itemtype = OPCLASS_ITEM_FUNCTION;
6915 1419 : n->name = $3;
6916 1419 : n->number = $2;
6917 1419 : $$ = (Node *) n;
6918 : }
6919 : | FUNCTION Iconst '(' type_list ')' function_with_argtypes
6920 : {
6921 120 : CreateOpClassItem *n = makeNode(CreateOpClassItem);
6922 :
6923 120 : n->itemtype = OPCLASS_ITEM_FUNCTION;
6924 120 : n->name = $6;
6925 120 : n->number = $2;
6926 120 : n->class_args = $4;
6927 120 : $$ = (Node *) n;
6928 : }
6929 : | STORAGE Typename
6930 : {
6931 186 : CreateOpClassItem *n = makeNode(CreateOpClassItem);
6932 :
6933 186 : n->itemtype = OPCLASS_ITEM_STORAGETYPE;
6934 186 : n->storedtype = $2;
6935 186 : $$ = (Node *) n;
6936 : }
6937 : ;
6938 :
6939 226 : opt_default: DEFAULT { $$ = true; }
6940 111 : | /*EMPTY*/ { $$ = false; }
6941 : ;
6942 :
6943 22 : opt_opfamily: FAMILY any_name { $$ = $2; }
6944 273 : | /*EMPTY*/ { $$ = NIL; }
6945 : ;
6946 :
6947 0 : opclass_purpose: FOR SEARCH { $$ = NIL; }
6948 63 : | FOR ORDER BY any_name { $$ = $4; }
6949 1739 : | /*EMPTY*/ { $$ = NIL; }
6950 : ;
6951 :
6952 :
6953 : CreateOpFamilyStmt:
6954 : CREATE OPERATOR FAMILY any_name USING name
6955 : {
6956 95 : CreateOpFamilyStmt *n = makeNode(CreateOpFamilyStmt);
6957 :
6958 95 : n->opfamilyname = $4;
6959 95 : n->amname = $6;
6960 95 : $$ = (Node *) n;
6961 : }
6962 : ;
6963 :
6964 : AlterOpFamilyStmt:
6965 : ALTER OPERATOR FAMILY any_name USING name ADD_P opclass_item_list
6966 : {
6967 238 : AlterOpFamilyStmt *n = makeNode(AlterOpFamilyStmt);
6968 :
6969 238 : n->opfamilyname = $4;
6970 238 : n->amname = $6;
6971 238 : n->isDrop = false;
6972 238 : n->items = $8;
6973 238 : $$ = (Node *) n;
6974 : }
6975 : | ALTER OPERATOR FAMILY any_name USING name DROP opclass_drop_list
6976 : {
6977 38 : AlterOpFamilyStmt *n = makeNode(AlterOpFamilyStmt);
6978 :
6979 38 : n->opfamilyname = $4;
6980 38 : n->amname = $6;
6981 38 : n->isDrop = true;
6982 38 : n->items = $8;
6983 38 : $$ = (Node *) n;
6984 : }
6985 : ;
6986 :
6987 : opclass_drop_list:
6988 38 : opclass_drop { $$ = list_make1($1); }
6989 20 : | opclass_drop_list ',' opclass_drop { $$ = lappend($1, $3); }
6990 : ;
6991 :
6992 : opclass_drop:
6993 : OPERATOR Iconst '(' type_list ')'
6994 : {
6995 36 : CreateOpClassItem *n = makeNode(CreateOpClassItem);
6996 :
6997 36 : n->itemtype = OPCLASS_ITEM_OPERATOR;
6998 36 : n->number = $2;
6999 36 : n->class_args = $4;
7000 36 : $$ = (Node *) n;
7001 : }
7002 : | FUNCTION Iconst '(' type_list ')'
7003 : {
7004 22 : CreateOpClassItem *n = makeNode(CreateOpClassItem);
7005 :
7006 22 : n->itemtype = OPCLASS_ITEM_FUNCTION;
7007 22 : n->number = $2;
7008 22 : n->class_args = $4;
7009 22 : $$ = (Node *) n;
7010 : }
7011 : ;
7012 :
7013 :
7014 : DropOpClassStmt:
7015 : DROP OPERATOR CLASS any_name USING name opt_drop_behavior
7016 : {
7017 25 : DropStmt *n = makeNode(DropStmt);
7018 :
7019 25 : n->objects = list_make1(lcons(makeString($6), $4));
7020 25 : n->removeType = OBJECT_OPCLASS;
7021 25 : n->behavior = $7;
7022 25 : n->missing_ok = false;
7023 25 : n->concurrent = false;
7024 25 : $$ = (Node *) n;
7025 : }
7026 : | DROP OPERATOR CLASS IF_P EXISTS any_name USING name opt_drop_behavior
7027 : {
7028 12 : DropStmt *n = makeNode(DropStmt);
7029 :
7030 12 : n->objects = list_make1(lcons(makeString($8), $6));
7031 12 : n->removeType = OBJECT_OPCLASS;
7032 12 : n->behavior = $9;
7033 12 : n->missing_ok = true;
7034 12 : n->concurrent = false;
7035 12 : $$ = (Node *) n;
7036 : }
7037 : ;
7038 :
7039 : DropOpFamilyStmt:
7040 : DROP OPERATOR FAMILY any_name USING name opt_drop_behavior
7041 : {
7042 73 : DropStmt *n = makeNode(DropStmt);
7043 :
7044 73 : n->objects = list_make1(lcons(makeString($6), $4));
7045 73 : n->removeType = OBJECT_OPFAMILY;
7046 73 : n->behavior = $7;
7047 73 : n->missing_ok = false;
7048 73 : n->concurrent = false;
7049 73 : $$ = (Node *) n;
7050 : }
7051 : | DROP OPERATOR FAMILY IF_P EXISTS any_name USING name opt_drop_behavior
7052 : {
7053 12 : DropStmt *n = makeNode(DropStmt);
7054 :
7055 12 : n->objects = list_make1(lcons(makeString($8), $6));
7056 12 : n->removeType = OBJECT_OPFAMILY;
7057 12 : n->behavior = $9;
7058 12 : n->missing_ok = true;
7059 12 : n->concurrent = false;
7060 12 : $$ = (Node *) n;
7061 : }
7062 : ;
7063 :
7064 :
7065 : /*****************************************************************************
7066 : *
7067 : * QUERY:
7068 : *
7069 : * DROP OWNED BY username [, username ...] [ RESTRICT | CASCADE ]
7070 : * REASSIGN OWNED BY username [, username ...] TO username
7071 : *
7072 : *****************************************************************************/
7073 : DropOwnedStmt:
7074 : DROP OWNED BY role_list opt_drop_behavior
7075 : {
7076 94 : DropOwnedStmt *n = makeNode(DropOwnedStmt);
7077 :
7078 94 : n->roles = $4;
7079 94 : n->behavior = $5;
7080 94 : $$ = (Node *) n;
7081 : }
7082 : ;
7083 :
7084 : ReassignOwnedStmt:
7085 : REASSIGN OWNED BY role_list TO RoleSpec
7086 : {
7087 34 : ReassignOwnedStmt *n = makeNode(ReassignOwnedStmt);
7088 :
7089 34 : n->roles = $4;
7090 34 : n->newrole = $6;
7091 34 : $$ = (Node *) n;
7092 : }
7093 : ;
7094 :
7095 : /*****************************************************************************
7096 : *
7097 : * QUERY:
7098 : *
7099 : * DROP itemtype [ IF EXISTS ] itemname [, itemname ...]
7100 : * [ RESTRICT | CASCADE ]
7101 : *
7102 : *****************************************************************************/
7103 :
7104 : DropStmt: DROP object_type_any_name IF_P EXISTS any_name_list opt_drop_behavior
7105 : {
7106 757 : DropStmt *n = makeNode(DropStmt);
7107 :
7108 757 : n->removeType = $2;
7109 757 : n->missing_ok = true;
7110 757 : n->objects = $5;
7111 757 : n->behavior = $6;
7112 757 : n->concurrent = false;
7113 757 : $$ = (Node *) n;
7114 : }
7115 : | DROP object_type_any_name any_name_list opt_drop_behavior
7116 : {
7117 10637 : DropStmt *n = makeNode(DropStmt);
7118 :
7119 10637 : n->removeType = $2;
7120 10637 : n->missing_ok = false;
7121 10637 : n->objects = $3;
7122 10637 : n->behavior = $4;
7123 10637 : n->concurrent = false;
7124 10637 : $$ = (Node *) n;
7125 : }
7126 : | DROP drop_type_name IF_P EXISTS name_list opt_drop_behavior
7127 : {
7128 60 : DropStmt *n = makeNode(DropStmt);
7129 :
7130 60 : n->removeType = $2;
7131 60 : n->missing_ok = true;
7132 60 : n->objects = $5;
7133 60 : n->behavior = $6;
7134 60 : n->concurrent = false;
7135 60 : $$ = (Node *) n;
7136 : }
7137 : | DROP drop_type_name name_list opt_drop_behavior
7138 : {
7139 975 : DropStmt *n = makeNode(DropStmt);
7140 :
7141 975 : n->removeType = $2;
7142 975 : n->missing_ok = false;
7143 975 : n->objects = $3;
7144 975 : n->behavior = $4;
7145 975 : n->concurrent = false;
7146 975 : $$ = (Node *) n;
7147 : }
7148 : | DROP object_type_name_on_any_name name ON any_name opt_drop_behavior
7149 : {
7150 775 : DropStmt *n = makeNode(DropStmt);
7151 :
7152 775 : n->removeType = $2;
7153 775 : n->objects = list_make1(lappend($5, makeString($3)));
7154 775 : n->behavior = $6;
7155 775 : n->missing_ok = false;
7156 775 : n->concurrent = false;
7157 775 : $$ = (Node *) n;
7158 : }
7159 : | DROP object_type_name_on_any_name IF_P EXISTS name ON any_name opt_drop_behavior
7160 : {
7161 32 : DropStmt *n = makeNode(DropStmt);
7162 :
7163 32 : n->removeType = $2;
7164 32 : n->objects = list_make1(lappend($7, makeString($5)));
7165 32 : n->behavior = $8;
7166 32 : n->missing_ok = true;
7167 32 : n->concurrent = false;
7168 32 : $$ = (Node *) n;
7169 : }
7170 : | DROP TYPE_P type_name_list opt_drop_behavior
7171 : {
7172 388 : DropStmt *n = makeNode(DropStmt);
7173 :
7174 388 : n->removeType = OBJECT_TYPE;
7175 388 : n->missing_ok = false;
7176 388 : n->objects = $3;
7177 388 : n->behavior = $4;
7178 388 : n->concurrent = false;
7179 388 : $$ = (Node *) n;
7180 : }
7181 : | DROP TYPE_P IF_P EXISTS type_name_list opt_drop_behavior
7182 : {
7183 16 : DropStmt *n = makeNode(DropStmt);
7184 :
7185 16 : n->removeType = OBJECT_TYPE;
7186 16 : n->missing_ok = true;
7187 16 : n->objects = $5;
7188 16 : n->behavior = $6;
7189 16 : n->concurrent = false;
7190 16 : $$ = (Node *) n;
7191 : }
7192 : | DROP DOMAIN_P type_name_list opt_drop_behavior
7193 : {
7194 353 : DropStmt *n = makeNode(DropStmt);
7195 :
7196 353 : n->removeType = OBJECT_DOMAIN;
7197 353 : n->missing_ok = false;
7198 353 : n->objects = $3;
7199 353 : n->behavior = $4;
7200 353 : n->concurrent = false;
7201 353 : $$ = (Node *) n;
7202 : }
7203 : | DROP DOMAIN_P IF_P EXISTS type_name_list opt_drop_behavior
7204 : {
7205 12 : DropStmt *n = makeNode(DropStmt);
7206 :
7207 12 : n->removeType = OBJECT_DOMAIN;
7208 12 : n->missing_ok = true;
7209 12 : n->objects = $5;
7210 12 : n->behavior = $6;
7211 12 : n->concurrent = false;
7212 12 : $$ = (Node *) n;
7213 : }
7214 : | DROP INDEX CONCURRENTLY any_name_list opt_drop_behavior
7215 : {
7216 87 : DropStmt *n = makeNode(DropStmt);
7217 :
7218 87 : n->removeType = OBJECT_INDEX;
7219 87 : n->missing_ok = false;
7220 87 : n->objects = $4;
7221 87 : n->behavior = $5;
7222 87 : n->concurrent = true;
7223 87 : $$ = (Node *) n;
7224 : }
7225 : | DROP INDEX CONCURRENTLY IF_P EXISTS any_name_list opt_drop_behavior
7226 : {
7227 8 : DropStmt *n = makeNode(DropStmt);
7228 :
7229 8 : n->removeType = OBJECT_INDEX;
7230 8 : n->missing_ok = true;
7231 8 : n->objects = $6;
7232 8 : n->behavior = $7;
7233 8 : n->concurrent = true;
7234 8 : $$ = (Node *) n;
7235 : }
7236 : ;
7237 :
7238 : /* object types taking any_name/any_name_list */
7239 : object_type_any_name:
7240 9738 : TABLE { $$ = OBJECT_TABLE; }
7241 133 : | SEQUENCE { $$ = OBJECT_SEQUENCE; }
7242 688 : | VIEW { $$ = OBJECT_VIEW; }
7243 81 : | MATERIALIZED VIEW { $$ = OBJECT_MATVIEW; }
7244 513 : | INDEX { $$ = OBJECT_INDEX; }
7245 114 : | FOREIGN TABLE { $$ = OBJECT_FOREIGN_TABLE; }
7246 54 : | PROPERTY GRAPH { $$ = OBJECT_PROPGRAPH; }
7247 63 : | COLLATION { $$ = OBJECT_COLLATION; }
7248 37 : | CONVERSION_P { $$ = OBJECT_CONVERSION; }
7249 152 : | STATISTICS { $$ = OBJECT_STATISTIC_EXT; }
7250 13 : | TEXT_P SEARCH PARSER { $$ = OBJECT_TSPARSER; }
7251 1538 : | TEXT_P SEARCH DICTIONARY { $$ = OBJECT_TSDICTIONARY; }
7252 62 : | TEXT_P SEARCH TEMPLATE { $$ = OBJECT_TSTEMPLATE; }
7253 1541 : | TEXT_P SEARCH CONFIGURATION { $$ = OBJECT_TSCONFIGURATION; }
7254 : ;
7255 :
7256 : /*
7257 : * object types taking name/name_list
7258 : *
7259 : * DROP handles some of them separately
7260 : */
7261 :
7262 : object_type_name:
7263 135 : drop_type_name { $$ = $1; }
7264 127 : | DATABASE { $$ = OBJECT_DATABASE; }
7265 44 : | ROLE { $$ = OBJECT_ROLE; }
7266 6 : | SUBSCRIPTION { $$ = OBJECT_SUBSCRIPTION; }
7267 0 : | TABLESPACE { $$ = OBJECT_TABLESPACE; }
7268 : ;
7269 :
7270 : drop_type_name:
7271 37 : ACCESS METHOD { $$ = OBJECT_ACCESS_METHOD; }
7272 84 : | EVENT TRIGGER { $$ = OBJECT_EVENT_TRIGGER; }
7273 98 : | EXTENSION { $$ = OBJECT_EXTENSION; }
7274 105 : | FOREIGN DATA_P WRAPPER { $$ = OBJECT_FDW; }
7275 82 : | opt_procedural LANGUAGE { $$ = OBJECT_LANGUAGE; }
7276 268 : | PUBLICATION { $$ = OBJECT_PUBLICATION; }
7277 404 : | SCHEMA { $$ = OBJECT_SCHEMA; }
7278 92 : | SERVER { $$ = OBJECT_FOREIGN_SERVER; }
7279 : ;
7280 :
7281 : /* object types attached to a table */
7282 : object_type_name_on_any_name:
7283 158 : POLICY { $$ = OBJECT_POLICY; }
7284 181 : | RULE { $$ = OBJECT_RULE; }
7285 503 : | TRIGGER { $$ = OBJECT_TRIGGER; }
7286 : ;
7287 :
7288 : any_name_list:
7289 16237 : any_name { $$ = list_make1($1); }
7290 2480 : | any_name_list ',' any_name { $$ = lappend($1, $3); }
7291 : ;
7292 :
7293 40039 : any_name: ColId { $$ = list_make1(makeString($1)); }
7294 6077 : | ColId attrs { $$ = lcons(makeString($1), $2); }
7295 : ;
7296 :
7297 : attrs: '.' attr_name
7298 76552 : { $$ = list_make1(makeString($2)); }
7299 : | attrs '.' attr_name
7300 36 : { $$ = lappend($1, makeString($3)); }
7301 : ;
7302 :
7303 : type_name_list:
7304 769 : Typename { $$ = list_make1($1); }
7305 84 : | type_name_list ',' Typename { $$ = lappend($1, $3); }
7306 : ;
7307 :
7308 : /*****************************************************************************
7309 : *
7310 : * QUERY:
7311 : * truncate table relname1, relname2, ...
7312 : *
7313 : *****************************************************************************/
7314 :
7315 : TruncateStmt:
7316 : TRUNCATE opt_table relation_expr_list opt_restart_seqs opt_drop_behavior
7317 : {
7318 1145 : TruncateStmt *n = makeNode(TruncateStmt);
7319 :
7320 1145 : n->relations = $3;
7321 1145 : n->restart_seqs = $4;
7322 1145 : n->behavior = $5;
7323 1145 : $$ = (Node *) n;
7324 : }
7325 : ;
7326 :
7327 : opt_restart_seqs:
7328 12 : CONTINUE_P IDENTITY_P { $$ = false; }
7329 15 : | RESTART IDENTITY_P { $$ = true; }
7330 1118 : | /* EMPTY */ { $$ = false; }
7331 : ;
7332 :
7333 : /*****************************************************************************
7334 : *
7335 : * COMMENT ON <object> IS <text>
7336 : *
7337 : *****************************************************************************/
7338 :
7339 : CommentStmt:
7340 : COMMENT ON object_type_any_name any_name IS comment_text
7341 : {
7342 3254 : CommentStmt *n = makeNode(CommentStmt);
7343 :
7344 3254 : n->objtype = $3;
7345 3254 : n->object = (Node *) $4;
7346 3254 : n->comment = $6;
7347 3254 : $$ = (Node *) n;
7348 : }
7349 : | COMMENT ON COLUMN any_name IS comment_text
7350 : {
7351 94 : CommentStmt *n = makeNode(CommentStmt);
7352 :
7353 94 : n->objtype = OBJECT_COLUMN;
7354 94 : n->object = (Node *) $4;
7355 94 : n->comment = $6;
7356 94 : $$ = (Node *) n;
7357 : }
7358 : | COMMENT ON object_type_name name IS comment_text
7359 : {
7360 277 : CommentStmt *n = makeNode(CommentStmt);
7361 :
7362 277 : n->objtype = $3;
7363 277 : n->object = (Node *) makeString($4);
7364 277 : n->comment = $6;
7365 277 : $$ = (Node *) n;
7366 : }
7367 : | COMMENT ON TYPE_P Typename IS comment_text
7368 : {
7369 31 : CommentStmt *n = makeNode(CommentStmt);
7370 :
7371 31 : n->objtype = OBJECT_TYPE;
7372 31 : n->object = (Node *) $4;
7373 31 : n->comment = $6;
7374 31 : $$ = (Node *) n;
7375 : }
7376 : | COMMENT ON DOMAIN_P Typename IS comment_text
7377 : {
7378 5 : CommentStmt *n = makeNode(CommentStmt);
7379 :
7380 5 : n->objtype = OBJECT_DOMAIN;
7381 5 : n->object = (Node *) $4;
7382 5 : n->comment = $6;
7383 5 : $$ = (Node *) n;
7384 : }
7385 : | COMMENT ON AGGREGATE aggregate_with_argtypes IS comment_text
7386 : {
7387 26 : CommentStmt *n = makeNode(CommentStmt);
7388 :
7389 26 : n->objtype = OBJECT_AGGREGATE;
7390 26 : n->object = (Node *) $4;
7391 26 : n->comment = $6;
7392 26 : $$ = (Node *) n;
7393 : }
7394 : | COMMENT ON FUNCTION function_with_argtypes IS comment_text
7395 : {
7396 91 : CommentStmt *n = makeNode(CommentStmt);
7397 :
7398 91 : n->objtype = OBJECT_FUNCTION;
7399 91 : n->object = (Node *) $4;
7400 91 : n->comment = $6;
7401 91 : $$ = (Node *) n;
7402 : }
7403 : | COMMENT ON OPERATOR operator_with_argtypes IS comment_text
7404 : {
7405 12 : CommentStmt *n = makeNode(CommentStmt);
7406 :
7407 12 : n->objtype = OBJECT_OPERATOR;
7408 12 : n->object = (Node *) $4;
7409 12 : n->comment = $6;
7410 12 : $$ = (Node *) n;
7411 : }
7412 : | COMMENT ON CONSTRAINT name ON any_name IS comment_text
7413 : {
7414 97 : CommentStmt *n = makeNode(CommentStmt);
7415 :
7416 97 : n->objtype = OBJECT_TABCONSTRAINT;
7417 97 : n->object = (Node *) lappend($6, makeString($4));
7418 97 : n->comment = $8;
7419 97 : $$ = (Node *) n;
7420 : }
7421 : | COMMENT ON CONSTRAINT name ON DOMAIN_P any_name IS comment_text
7422 : {
7423 31 : CommentStmt *n = makeNode(CommentStmt);
7424 :
7425 31 : n->objtype = OBJECT_DOMCONSTRAINT;
7426 : /*
7427 : * should use Typename not any_name in the production, but
7428 : * there's a shift/reduce conflict if we do that, so fix it
7429 : * up here.
7430 : */
7431 31 : n->object = (Node *) list_make2(makeTypeNameFromNameList($7), makeString($4));
7432 31 : n->comment = $9;
7433 31 : $$ = (Node *) n;
7434 : }
7435 : | COMMENT ON object_type_name_on_any_name name ON any_name IS comment_text
7436 : {
7437 27 : CommentStmt *n = makeNode(CommentStmt);
7438 :
7439 27 : n->objtype = $3;
7440 27 : n->object = (Node *) lappend($6, makeString($4));
7441 27 : n->comment = $8;
7442 27 : $$ = (Node *) n;
7443 : }
7444 : | COMMENT ON PROCEDURE function_with_argtypes IS comment_text
7445 : {
7446 0 : CommentStmt *n = makeNode(CommentStmt);
7447 :
7448 0 : n->objtype = OBJECT_PROCEDURE;
7449 0 : n->object = (Node *) $4;
7450 0 : n->comment = $6;
7451 0 : $$ = (Node *) n;
7452 : }
7453 : | COMMENT ON ROUTINE function_with_argtypes IS comment_text
7454 : {
7455 0 : CommentStmt *n = makeNode(CommentStmt);
7456 :
7457 0 : n->objtype = OBJECT_ROUTINE;
7458 0 : n->object = (Node *) $4;
7459 0 : n->comment = $6;
7460 0 : $$ = (Node *) n;
7461 : }
7462 : | COMMENT ON TRANSFORM FOR Typename LANGUAGE name IS comment_text
7463 : {
7464 7 : CommentStmt *n = makeNode(CommentStmt);
7465 :
7466 7 : n->objtype = OBJECT_TRANSFORM;
7467 7 : n->object = (Node *) list_make2($5, makeString($7));
7468 7 : n->comment = $9;
7469 7 : $$ = (Node *) n;
7470 : }
7471 : | COMMENT ON OPERATOR CLASS any_name USING name IS comment_text
7472 : {
7473 0 : CommentStmt *n = makeNode(CommentStmt);
7474 :
7475 0 : n->objtype = OBJECT_OPCLASS;
7476 0 : n->object = (Node *) lcons(makeString($7), $5);
7477 0 : n->comment = $9;
7478 0 : $$ = (Node *) n;
7479 : }
7480 : | COMMENT ON OPERATOR FAMILY any_name USING name IS comment_text
7481 : {
7482 0 : CommentStmt *n = makeNode(CommentStmt);
7483 :
7484 0 : n->objtype = OBJECT_OPFAMILY;
7485 0 : n->object = (Node *) lcons(makeString($7), $5);
7486 0 : n->comment = $9;
7487 0 : $$ = (Node *) n;
7488 : }
7489 : | COMMENT ON LARGE_P OBJECT_P NumericOnly IS comment_text
7490 : {
7491 24 : CommentStmt *n = makeNode(CommentStmt);
7492 :
7493 24 : n->objtype = OBJECT_LARGEOBJECT;
7494 24 : n->object = (Node *) $5;
7495 24 : n->comment = $7;
7496 24 : $$ = (Node *) n;
7497 : }
7498 : | COMMENT ON CAST '(' Typename AS Typename ')' IS comment_text
7499 : {
7500 0 : CommentStmt *n = makeNode(CommentStmt);
7501 :
7502 0 : n->objtype = OBJECT_CAST;
7503 0 : n->object = (Node *) list_make2($5, $7);
7504 0 : n->comment = $10;
7505 0 : $$ = (Node *) n;
7506 : }
7507 : ;
7508 :
7509 : comment_text:
7510 3903 : Sconst { $$ = $1; }
7511 73 : | NULL_P { $$ = NULL; }
7512 : ;
7513 :
7514 :
7515 : /*****************************************************************************
7516 : *
7517 : * SECURITY LABEL [FOR <provider>] ON <object> IS <label>
7518 : *
7519 : * As with COMMENT ON, <object> can refer to various types of database
7520 : * objects (e.g. TABLE, COLUMN, etc.).
7521 : *
7522 : *****************************************************************************/
7523 :
7524 : SecLabelStmt:
7525 : SECURITY LABEL opt_provider ON object_type_any_name any_name
7526 : IS security_label
7527 : {
7528 28 : SecLabelStmt *n = makeNode(SecLabelStmt);
7529 :
7530 28 : n->provider = $3;
7531 28 : n->objtype = $5;
7532 28 : n->object = (Node *) $6;
7533 28 : n->label = $8;
7534 28 : $$ = (Node *) n;
7535 : }
7536 : | SECURITY LABEL opt_provider ON COLUMN any_name
7537 : IS security_label
7538 : {
7539 2 : SecLabelStmt *n = makeNode(SecLabelStmt);
7540 :
7541 2 : n->provider = $3;
7542 2 : n->objtype = OBJECT_COLUMN;
7543 2 : n->object = (Node *) $6;
7544 2 : n->label = $8;
7545 2 : $$ = (Node *) n;
7546 : }
7547 : | SECURITY LABEL opt_provider ON object_type_name name
7548 : IS security_label
7549 : {
7550 26 : SecLabelStmt *n = makeNode(SecLabelStmt);
7551 :
7552 26 : n->provider = $3;
7553 26 : n->objtype = $5;
7554 26 : n->object = (Node *) makeString($6);
7555 26 : n->label = $8;
7556 26 : $$ = (Node *) n;
7557 : }
7558 : | SECURITY LABEL opt_provider ON TYPE_P Typename
7559 : IS security_label
7560 : {
7561 0 : SecLabelStmt *n = makeNode(SecLabelStmt);
7562 :
7563 0 : n->provider = $3;
7564 0 : n->objtype = OBJECT_TYPE;
7565 0 : n->object = (Node *) $6;
7566 0 : n->label = $8;
7567 0 : $$ = (Node *) n;
7568 : }
7569 : | SECURITY LABEL opt_provider ON DOMAIN_P Typename
7570 : IS security_label
7571 : {
7572 1 : SecLabelStmt *n = makeNode(SecLabelStmt);
7573 :
7574 1 : n->provider = $3;
7575 1 : n->objtype = OBJECT_DOMAIN;
7576 1 : n->object = (Node *) $6;
7577 1 : n->label = $8;
7578 1 : $$ = (Node *) n;
7579 : }
7580 : | SECURITY LABEL opt_provider ON AGGREGATE aggregate_with_argtypes
7581 : IS security_label
7582 : {
7583 0 : SecLabelStmt *n = makeNode(SecLabelStmt);
7584 :
7585 0 : n->provider = $3;
7586 0 : n->objtype = OBJECT_AGGREGATE;
7587 0 : n->object = (Node *) $6;
7588 0 : n->label = $8;
7589 0 : $$ = (Node *) n;
7590 : }
7591 : | SECURITY LABEL opt_provider ON FUNCTION function_with_argtypes
7592 : IS security_label
7593 : {
7594 1 : SecLabelStmt *n = makeNode(SecLabelStmt);
7595 :
7596 1 : n->provider = $3;
7597 1 : n->objtype = OBJECT_FUNCTION;
7598 1 : n->object = (Node *) $6;
7599 1 : n->label = $8;
7600 1 : $$ = (Node *) n;
7601 : }
7602 : | SECURITY LABEL opt_provider ON LARGE_P OBJECT_P NumericOnly
7603 : IS security_label
7604 : {
7605 9 : SecLabelStmt *n = makeNode(SecLabelStmt);
7606 :
7607 9 : n->provider = $3;
7608 9 : n->objtype = OBJECT_LARGEOBJECT;
7609 9 : n->object = (Node *) $7;
7610 9 : n->label = $9;
7611 9 : $$ = (Node *) n;
7612 : }
7613 : | SECURITY LABEL opt_provider ON PROCEDURE function_with_argtypes
7614 : IS security_label
7615 : {
7616 0 : SecLabelStmt *n = makeNode(SecLabelStmt);
7617 :
7618 0 : n->provider = $3;
7619 0 : n->objtype = OBJECT_PROCEDURE;
7620 0 : n->object = (Node *) $6;
7621 0 : n->label = $8;
7622 0 : $$ = (Node *) n;
7623 : }
7624 : | SECURITY LABEL opt_provider ON ROUTINE function_with_argtypes
7625 : IS security_label
7626 : {
7627 0 : SecLabelStmt *n = makeNode(SecLabelStmt);
7628 :
7629 0 : n->provider = $3;
7630 0 : n->objtype = OBJECT_ROUTINE;
7631 0 : n->object = (Node *) $6;
7632 0 : n->label = $8;
7633 0 : $$ = (Node *) n;
7634 : }
7635 : ;
7636 :
7637 16 : opt_provider: FOR NonReservedWord_or_Sconst { $$ = $2; }
7638 51 : | /* EMPTY */ { $$ = NULL; }
7639 : ;
7640 :
7641 67 : security_label: Sconst { $$ = $1; }
7642 0 : | NULL_P { $$ = NULL; }
7643 : ;
7644 :
7645 : /*****************************************************************************
7646 : *
7647 : * QUERY:
7648 : * fetch/move
7649 : *
7650 : *****************************************************************************/
7651 :
7652 : FetchStmt: FETCH fetch_args
7653 : {
7654 4362 : FetchStmt *n = (FetchStmt *) $2;
7655 :
7656 4362 : n->ismove = false;
7657 4362 : $$ = (Node *) n;
7658 : }
7659 : | MOVE fetch_args
7660 : {
7661 42 : FetchStmt *n = (FetchStmt *) $2;
7662 :
7663 42 : n->ismove = true;
7664 42 : $$ = (Node *) n;
7665 : }
7666 : ;
7667 :
7668 : fetch_args: cursor_name
7669 : {
7670 148 : FetchStmt *n = makeNode(FetchStmt);
7671 :
7672 148 : n->portalname = $1;
7673 148 : n->direction = FETCH_FORWARD;
7674 148 : n->howMany = 1;
7675 148 : n->location = -1;
7676 148 : n->direction_keyword = FETCH_KEYWORD_NONE;
7677 148 : $$ = (Node *) n;
7678 : }
7679 : | from_in cursor_name
7680 : {
7681 124 : FetchStmt *n = makeNode(FetchStmt);
7682 :
7683 124 : n->portalname = $2;
7684 124 : n->direction = FETCH_FORWARD;
7685 124 : n->howMany = 1;
7686 124 : n->location = -1;
7687 124 : n->direction_keyword = FETCH_KEYWORD_NONE;
7688 124 : $$ = (Node *) n;
7689 : }
7690 : | SignedIconst opt_from_in cursor_name
7691 : {
7692 2193 : FetchStmt *n = makeNode(FetchStmt);
7693 :
7694 2193 : n->portalname = $3;
7695 2193 : n->direction = FETCH_FORWARD;
7696 2193 : n->howMany = $1;
7697 2193 : n->location = @1;
7698 2193 : n->direction_keyword = FETCH_KEYWORD_NONE;
7699 2193 : $$ = (Node *) n;
7700 : }
7701 : | NEXT opt_from_in cursor_name
7702 : {
7703 1336 : FetchStmt *n = makeNode(FetchStmt);
7704 :
7705 1336 : n->portalname = $3;
7706 1336 : n->direction = FETCH_FORWARD;
7707 1336 : n->howMany = 1;
7708 1336 : n->location = -1;
7709 1336 : n->direction_keyword = FETCH_KEYWORD_NEXT;
7710 1336 : $$ = (Node *) n;
7711 : }
7712 : | PRIOR opt_from_in cursor_name
7713 : {
7714 21 : FetchStmt *n = makeNode(FetchStmt);
7715 :
7716 21 : n->portalname = $3;
7717 21 : n->direction = FETCH_BACKWARD;
7718 21 : n->howMany = 1;
7719 21 : n->location = -1;
7720 21 : n->direction_keyword = FETCH_KEYWORD_PRIOR;
7721 21 : $$ = (Node *) n;
7722 : }
7723 : | FIRST_P opt_from_in cursor_name
7724 : {
7725 17 : FetchStmt *n = makeNode(FetchStmt);
7726 :
7727 17 : n->portalname = $3;
7728 17 : n->direction = FETCH_ABSOLUTE;
7729 17 : n->howMany = 1;
7730 17 : n->location = -1;
7731 17 : n->direction_keyword = FETCH_KEYWORD_FIRST;
7732 17 : $$ = (Node *) n;
7733 : }
7734 : | LAST_P opt_from_in cursor_name
7735 : {
7736 13 : FetchStmt *n = makeNode(FetchStmt);
7737 :
7738 13 : n->portalname = $3;
7739 13 : n->direction = FETCH_ABSOLUTE;
7740 13 : n->howMany = -1;
7741 13 : n->location = -1;
7742 13 : n->direction_keyword = FETCH_KEYWORD_LAST;
7743 13 : $$ = (Node *) n;
7744 : }
7745 : | ABSOLUTE_P SignedIconst opt_from_in cursor_name
7746 : {
7747 59 : FetchStmt *n = makeNode(FetchStmt);
7748 :
7749 59 : n->portalname = $4;
7750 59 : n->direction = FETCH_ABSOLUTE;
7751 59 : n->howMany = $2;
7752 59 : n->location = @2;
7753 59 : n->direction_keyword = FETCH_KEYWORD_ABSOLUTE;
7754 59 : $$ = (Node *) n;
7755 : }
7756 : | RELATIVE_P SignedIconst opt_from_in cursor_name
7757 : {
7758 23 : FetchStmt *n = makeNode(FetchStmt);
7759 :
7760 23 : n->portalname = $4;
7761 23 : n->direction = FETCH_RELATIVE;
7762 23 : n->howMany = $2;
7763 23 : n->location = @2;
7764 23 : n->direction_keyword = FETCH_KEYWORD_RELATIVE;
7765 23 : $$ = (Node *) n;
7766 : }
7767 : | ALL opt_from_in cursor_name
7768 : {
7769 176 : FetchStmt *n = makeNode(FetchStmt);
7770 :
7771 176 : n->portalname = $3;
7772 176 : n->direction = FETCH_FORWARD;
7773 176 : n->howMany = FETCH_ALL;
7774 176 : n->location = -1;
7775 176 : n->direction_keyword = FETCH_KEYWORD_ALL;
7776 176 : $$ = (Node *) n;
7777 : }
7778 : | FORWARD opt_from_in cursor_name
7779 : {
7780 15 : FetchStmt *n = makeNode(FetchStmt);
7781 :
7782 15 : n->portalname = $3;
7783 15 : n->direction = FETCH_FORWARD;
7784 15 : n->howMany = 1;
7785 15 : n->location = -1;
7786 15 : n->direction_keyword = FETCH_KEYWORD_FORWARD;
7787 15 : $$ = (Node *) n;
7788 : }
7789 : | FORWARD SignedIconst opt_from_in cursor_name
7790 : {
7791 6 : FetchStmt *n = makeNode(FetchStmt);
7792 :
7793 6 : n->portalname = $4;
7794 6 : n->direction = FETCH_FORWARD;
7795 6 : n->howMany = $2;
7796 6 : n->location = @2;
7797 6 : n->direction_keyword = FETCH_KEYWORD_FORWARD;
7798 6 : $$ = (Node *) n;
7799 : }
7800 : | FORWARD ALL opt_from_in cursor_name
7801 : {
7802 10 : FetchStmt *n = makeNode(FetchStmt);
7803 :
7804 10 : n->portalname = $4;
7805 10 : n->direction = FETCH_FORWARD;
7806 10 : n->howMany = FETCH_ALL;
7807 10 : n->location = -1;
7808 10 : n->direction_keyword = FETCH_KEYWORD_FORWARD_ALL;
7809 10 : $$ = (Node *) n;
7810 : }
7811 : | BACKWARD opt_from_in cursor_name
7812 : {
7813 53 : FetchStmt *n = makeNode(FetchStmt);
7814 :
7815 53 : n->portalname = $3;
7816 53 : n->direction = FETCH_BACKWARD;
7817 53 : n->howMany = 1;
7818 53 : n->location = -1;
7819 53 : n->direction_keyword = FETCH_KEYWORD_BACKWARD;
7820 53 : $$ = (Node *) n;
7821 : }
7822 : | BACKWARD SignedIconst opt_from_in cursor_name
7823 : {
7824 149 : FetchStmt *n = makeNode(FetchStmt);
7825 :
7826 149 : n->portalname = $4;
7827 149 : n->direction = FETCH_BACKWARD;
7828 149 : n->howMany = $2;
7829 149 : n->location = @2;
7830 149 : n->direction_keyword = FETCH_KEYWORD_BACKWARD;
7831 149 : $$ = (Node *) n;
7832 : }
7833 : | BACKWARD ALL opt_from_in cursor_name
7834 : {
7835 61 : FetchStmt *n = makeNode(FetchStmt);
7836 :
7837 61 : n->portalname = $4;
7838 61 : n->direction = FETCH_BACKWARD;
7839 61 : n->howMany = FETCH_ALL;
7840 61 : n->location = -1;
7841 61 : n->direction_keyword = FETCH_KEYWORD_BACKWARD_ALL;
7842 61 : $$ = (Node *) n;
7843 : }
7844 : ;
7845 :
7846 : from_in: FROM
7847 : | IN_P
7848 : ;
7849 :
7850 : opt_from_in: from_in
7851 : | /* EMPTY */
7852 : ;
7853 :
7854 :
7855 : /*****************************************************************************
7856 : *
7857 : * GRANT and REVOKE statements
7858 : *
7859 : *****************************************************************************/
7860 :
7861 : GrantStmt: GRANT privileges ON privilege_target TO grantee_list
7862 : opt_grant_grant_option opt_granted_by
7863 : {
7864 6135 : GrantStmt *n = makeNode(GrantStmt);
7865 :
7866 6135 : n->is_grant = true;
7867 6135 : n->privileges = $2;
7868 6135 : n->targtype = ($4)->targtype;
7869 6135 : n->objtype = ($4)->objtype;
7870 6135 : n->objects = ($4)->objs;
7871 6135 : n->grantees = $6;
7872 6135 : n->grant_option = $7;
7873 6135 : n->grantor = $8;
7874 6135 : $$ = (Node *) n;
7875 : }
7876 : ;
7877 :
7878 : RevokeStmt:
7879 : REVOKE privileges ON privilege_target
7880 : FROM grantee_list opt_granted_by opt_drop_behavior
7881 : {
7882 2174 : GrantStmt *n = makeNode(GrantStmt);
7883 :
7884 2174 : n->is_grant = false;
7885 2174 : n->grant_option = false;
7886 2174 : n->privileges = $2;
7887 2174 : n->targtype = ($4)->targtype;
7888 2174 : n->objtype = ($4)->objtype;
7889 2174 : n->objects = ($4)->objs;
7890 2174 : n->grantees = $6;
7891 2174 : n->grantor = $7;
7892 2174 : n->behavior = $8;
7893 2174 : $$ = (Node *) n;
7894 : }
7895 : | REVOKE GRANT OPTION FOR privileges ON privilege_target
7896 : FROM grantee_list opt_granted_by opt_drop_behavior
7897 : {
7898 9 : GrantStmt *n = makeNode(GrantStmt);
7899 :
7900 9 : n->is_grant = false;
7901 9 : n->grant_option = true;
7902 9 : n->privileges = $5;
7903 9 : n->targtype = ($7)->targtype;
7904 9 : n->objtype = ($7)->objtype;
7905 9 : n->objects = ($7)->objs;
7906 9 : n->grantees = $9;
7907 9 : n->grantor = $10;
7908 9 : n->behavior = $11;
7909 9 : $$ = (Node *) n;
7910 : }
7911 : ;
7912 :
7913 :
7914 : /*
7915 : * Privilege names are represented as strings; the validity of the privilege
7916 : * names gets checked at execution. This is a bit annoying but we have little
7917 : * choice because of the syntactic conflict with lists of role names in
7918 : * GRANT/REVOKE. What's more, we have to call out in the "privilege"
7919 : * production any reserved keywords that need to be usable as privilege names.
7920 : */
7921 :
7922 : /* either ALL [PRIVILEGES] or a list of individual privileges */
7923 : privileges: privilege_list
7924 6860 : { $$ = $1; }
7925 : | ALL
7926 1518 : { $$ = NIL; }
7927 : | ALL PRIVILEGES
7928 69 : { $$ = NIL; }
7929 : | ALL '(' columnList ')'
7930 : {
7931 12 : AccessPriv *n = makeNode(AccessPriv);
7932 :
7933 12 : n->priv_name = NULL;
7934 12 : n->cols = $3;
7935 12 : $$ = list_make1(n);
7936 : }
7937 : | ALL PRIVILEGES '(' columnList ')'
7938 : {
7939 0 : AccessPriv *n = makeNode(AccessPriv);
7940 :
7941 0 : n->priv_name = NULL;
7942 0 : n->cols = $4;
7943 0 : $$ = list_make1(n);
7944 : }
7945 : ;
7946 :
7947 7286 : privilege_list: privilege { $$ = list_make1($1); }
7948 364 : | privilege_list ',' privilege { $$ = lappend($1, $3); }
7949 : ;
7950 :
7951 : privilege: SELECT opt_column_list
7952 : {
7953 5539 : AccessPriv *n = makeNode(AccessPriv);
7954 :
7955 5539 : n->priv_name = pstrdup($1);
7956 5539 : n->cols = $2;
7957 5539 : $$ = n;
7958 : }
7959 : | REFERENCES opt_column_list
7960 : {
7961 9 : AccessPriv *n = makeNode(AccessPriv);
7962 :
7963 9 : n->priv_name = pstrdup($1);
7964 9 : n->cols = $2;
7965 9 : $$ = n;
7966 : }
7967 : | CREATE opt_column_list
7968 : {
7969 190 : AccessPriv *n = makeNode(AccessPriv);
7970 :
7971 190 : n->priv_name = pstrdup($1);
7972 190 : n->cols = $2;
7973 190 : $$ = n;
7974 : }
7975 : | ALTER SYSTEM_P
7976 : {
7977 12 : AccessPriv *n = makeNode(AccessPriv);
7978 12 : n->priv_name = pstrdup("alter system");
7979 12 : n->cols = NIL;
7980 12 : $$ = n;
7981 : }
7982 : | ColId opt_column_list
7983 : {
7984 1900 : AccessPriv *n = makeNode(AccessPriv);
7985 :
7986 1900 : n->priv_name = $1;
7987 1900 : n->cols = $2;
7988 1900 : $$ = n;
7989 : }
7990 : ;
7991 :
7992 : parameter_name_list:
7993 : parameter_name
7994 : {
7995 38 : $$ = list_make1(makeString($1));
7996 : }
7997 : | parameter_name_list ',' parameter_name
7998 : {
7999 25 : $$ = lappend($1, makeString($3));
8000 : }
8001 : ;
8002 :
8003 : parameter_name:
8004 : ColId
8005 : {
8006 63 : $$ = $1;
8007 : }
8008 : | parameter_name '.' ColId
8009 : {
8010 16 : $$ = psprintf("%s.%s", $1, $3);
8011 : }
8012 : ;
8013 :
8014 :
8015 : /* Don't bother trying to fold the first two rules into one using
8016 : * opt_table. You're going to get conflicts.
8017 : */
8018 : privilege_target:
8019 : qualified_name_list
8020 : {
8021 6690 : PrivTarget *n = palloc_object(PrivTarget);
8022 :
8023 6690 : n->targtype = ACL_TARGET_OBJECT;
8024 6690 : n->objtype = OBJECT_TABLE;
8025 6690 : n->objs = $1;
8026 6690 : $$ = n;
8027 : }
8028 : | TABLE qualified_name_list
8029 : {
8030 224 : PrivTarget *n = palloc_object(PrivTarget);
8031 :
8032 224 : n->targtype = ACL_TARGET_OBJECT;
8033 224 : n->objtype = OBJECT_TABLE;
8034 224 : n->objs = $2;
8035 224 : $$ = n;
8036 : }
8037 : | SEQUENCE qualified_name_list
8038 : {
8039 12 : PrivTarget *n = palloc_object(PrivTarget);
8040 :
8041 12 : n->targtype = ACL_TARGET_OBJECT;
8042 12 : n->objtype = OBJECT_SEQUENCE;
8043 12 : n->objs = $2;
8044 12 : $$ = n;
8045 : }
8046 : | FOREIGN DATA_P WRAPPER name_list
8047 : {
8048 60 : PrivTarget *n = palloc_object(PrivTarget);
8049 :
8050 60 : n->targtype = ACL_TARGET_OBJECT;
8051 60 : n->objtype = OBJECT_FDW;
8052 60 : n->objs = $4;
8053 60 : $$ = n;
8054 : }
8055 : | FOREIGN SERVER name_list
8056 : {
8057 63 : PrivTarget *n = palloc_object(PrivTarget);
8058 :
8059 63 : n->targtype = ACL_TARGET_OBJECT;
8060 63 : n->objtype = OBJECT_FOREIGN_SERVER;
8061 63 : n->objs = $3;
8062 63 : $$ = n;
8063 : }
8064 : | FUNCTION function_with_argtypes_list
8065 : {
8066 501 : PrivTarget *n = palloc_object(PrivTarget);
8067 :
8068 501 : n->targtype = ACL_TARGET_OBJECT;
8069 501 : n->objtype = OBJECT_FUNCTION;
8070 501 : n->objs = $2;
8071 501 : $$ = n;
8072 : }
8073 : | PROCEDURE function_with_argtypes_list
8074 : {
8075 28 : PrivTarget *n = palloc_object(PrivTarget);
8076 :
8077 28 : n->targtype = ACL_TARGET_OBJECT;
8078 28 : n->objtype = OBJECT_PROCEDURE;
8079 28 : n->objs = $2;
8080 28 : $$ = n;
8081 : }
8082 : | ROUTINE function_with_argtypes_list
8083 : {
8084 0 : PrivTarget *n = palloc_object(PrivTarget);
8085 :
8086 0 : n->targtype = ACL_TARGET_OBJECT;
8087 0 : n->objtype = OBJECT_ROUTINE;
8088 0 : n->objs = $2;
8089 0 : $$ = n;
8090 : }
8091 : | DATABASE name_list
8092 : {
8093 200 : PrivTarget *n = palloc_object(PrivTarget);
8094 :
8095 200 : n->targtype = ACL_TARGET_OBJECT;
8096 200 : n->objtype = OBJECT_DATABASE;
8097 200 : n->objs = $2;
8098 200 : $$ = n;
8099 : }
8100 : | DOMAIN_P any_name_list
8101 : {
8102 17 : PrivTarget *n = palloc_object(PrivTarget);
8103 :
8104 17 : n->targtype = ACL_TARGET_OBJECT;
8105 17 : n->objtype = OBJECT_DOMAIN;
8106 17 : n->objs = $2;
8107 17 : $$ = n;
8108 : }
8109 : | LANGUAGE name_list
8110 : {
8111 27 : PrivTarget *n = palloc_object(PrivTarget);
8112 :
8113 27 : n->targtype = ACL_TARGET_OBJECT;
8114 27 : n->objtype = OBJECT_LANGUAGE;
8115 27 : n->objs = $2;
8116 27 : $$ = n;
8117 : }
8118 : | LARGE_P OBJECT_P NumericOnly_list
8119 : {
8120 62 : PrivTarget *n = palloc_object(PrivTarget);
8121 :
8122 62 : n->targtype = ACL_TARGET_OBJECT;
8123 62 : n->objtype = OBJECT_LARGEOBJECT;
8124 62 : n->objs = $3;
8125 62 : $$ = n;
8126 : }
8127 : | PARAMETER parameter_name_list
8128 : {
8129 38 : PrivTarget *n = palloc_object(PrivTarget);
8130 38 : n->targtype = ACL_TARGET_OBJECT;
8131 38 : n->objtype = OBJECT_PARAMETER_ACL;
8132 38 : n->objs = $2;
8133 38 : $$ = n;
8134 : }
8135 : | PROPERTY GRAPH qualified_name_list
8136 : {
8137 12 : PrivTarget *n = palloc_object(PrivTarget);
8138 :
8139 12 : n->targtype = ACL_TARGET_OBJECT;
8140 12 : n->objtype = OBJECT_PROPGRAPH;
8141 12 : n->objs = $3;
8142 12 : $$ = n;
8143 : }
8144 : | SCHEMA name_list
8145 : {
8146 295 : PrivTarget *n = palloc_object(PrivTarget);
8147 :
8148 295 : n->targtype = ACL_TARGET_OBJECT;
8149 295 : n->objtype = OBJECT_SCHEMA;
8150 295 : n->objs = $2;
8151 295 : $$ = n;
8152 : }
8153 : | TABLESPACE name_list
8154 : {
8155 3 : PrivTarget *n = palloc_object(PrivTarget);
8156 :
8157 3 : n->targtype = ACL_TARGET_OBJECT;
8158 3 : n->objtype = OBJECT_TABLESPACE;
8159 3 : n->objs = $2;
8160 3 : $$ = n;
8161 : }
8162 : | TYPE_P any_name_list
8163 : {
8164 72 : PrivTarget *n = palloc_object(PrivTarget);
8165 :
8166 72 : n->targtype = ACL_TARGET_OBJECT;
8167 72 : n->objtype = OBJECT_TYPE;
8168 72 : n->objs = $2;
8169 72 : $$ = n;
8170 : }
8171 : | ALL TABLES IN_P SCHEMA name_list
8172 : {
8173 8 : PrivTarget *n = palloc_object(PrivTarget);
8174 :
8175 8 : n->targtype = ACL_TARGET_ALL_IN_SCHEMA;
8176 8 : n->objtype = OBJECT_TABLE;
8177 8 : n->objs = $5;
8178 8 : $$ = n;
8179 : }
8180 : | ALL SEQUENCES IN_P SCHEMA name_list
8181 : {
8182 0 : PrivTarget *n = palloc_object(PrivTarget);
8183 :
8184 0 : n->targtype = ACL_TARGET_ALL_IN_SCHEMA;
8185 0 : n->objtype = OBJECT_SEQUENCE;
8186 0 : n->objs = $5;
8187 0 : $$ = n;
8188 : }
8189 : | ALL FUNCTIONS IN_P SCHEMA name_list
8190 : {
8191 4 : PrivTarget *n = palloc_object(PrivTarget);
8192 :
8193 4 : n->targtype = ACL_TARGET_ALL_IN_SCHEMA;
8194 4 : n->objtype = OBJECT_FUNCTION;
8195 4 : n->objs = $5;
8196 4 : $$ = n;
8197 : }
8198 : | ALL PROCEDURES IN_P SCHEMA name_list
8199 : {
8200 4 : PrivTarget *n = palloc_object(PrivTarget);
8201 :
8202 4 : n->targtype = ACL_TARGET_ALL_IN_SCHEMA;
8203 4 : n->objtype = OBJECT_PROCEDURE;
8204 4 : n->objs = $5;
8205 4 : $$ = n;
8206 : }
8207 : | ALL ROUTINES IN_P SCHEMA name_list
8208 : {
8209 4 : PrivTarget *n = palloc_object(PrivTarget);
8210 :
8211 4 : n->targtype = ACL_TARGET_ALL_IN_SCHEMA;
8212 4 : n->objtype = OBJECT_ROUTINE;
8213 4 : n->objs = $5;
8214 4 : $$ = n;
8215 : }
8216 : ;
8217 :
8218 :
8219 : grantee_list:
8220 8453 : grantee { $$ = list_make1($1); }
8221 70 : | grantee_list ',' grantee { $$ = lappend($1, $3); }
8222 : ;
8223 :
8224 : grantee:
8225 8507 : RoleSpec { $$ = $1; }
8226 16 : | GROUP_P RoleSpec { $$ = $2; }
8227 : ;
8228 :
8229 :
8230 : opt_grant_grant_option:
8231 77 : WITH GRANT OPTION { $$ = true; }
8232 6140 : | /*EMPTY*/ { $$ = false; }
8233 : ;
8234 :
8235 : /*****************************************************************************
8236 : *
8237 : * GRANT and REVOKE ROLE statements
8238 : *
8239 : *****************************************************************************/
8240 :
8241 : GrantRoleStmt:
8242 : GRANT privilege_list TO role_list opt_granted_by
8243 : {
8244 206 : GrantRoleStmt *n = makeNode(GrantRoleStmt);
8245 :
8246 206 : n->is_grant = true;
8247 206 : n->granted_roles = $2;
8248 206 : n->grantee_roles = $4;
8249 206 : n->opt = NIL;
8250 206 : n->grantor = $5;
8251 206 : $$ = (Node *) n;
8252 : }
8253 : | GRANT privilege_list TO role_list WITH grant_role_opt_list opt_granted_by
8254 : {
8255 117 : GrantRoleStmt *n = makeNode(GrantRoleStmt);
8256 :
8257 117 : n->is_grant = true;
8258 117 : n->granted_roles = $2;
8259 117 : n->grantee_roles = $4;
8260 117 : n->opt = $6;
8261 117 : n->grantor = $7;
8262 117 : $$ = (Node *) n;
8263 : }
8264 : ;
8265 :
8266 : RevokeRoleStmt:
8267 : REVOKE privilege_list FROM role_list opt_granted_by opt_drop_behavior
8268 : {
8269 59 : GrantRoleStmt *n = makeNode(GrantRoleStmt);
8270 :
8271 59 : n->is_grant = false;
8272 59 : n->opt = NIL;
8273 59 : n->granted_roles = $2;
8274 59 : n->grantee_roles = $4;
8275 59 : n->grantor = $5;
8276 59 : n->behavior = $6;
8277 59 : $$ = (Node *) n;
8278 : }
8279 : | REVOKE ColId OPTION FOR privilege_list FROM role_list opt_granted_by opt_drop_behavior
8280 : {
8281 44 : GrantRoleStmt *n = makeNode(GrantRoleStmt);
8282 : DefElem *opt;
8283 :
8284 44 : opt = makeDefElem(pstrdup($2),
8285 44 : (Node *) makeBoolean(false), @2);
8286 44 : n->is_grant = false;
8287 44 : n->opt = list_make1(opt);
8288 44 : n->granted_roles = $5;
8289 44 : n->grantee_roles = $7;
8290 44 : n->grantor = $8;
8291 44 : n->behavior = $9;
8292 44 : $$ = (Node *) n;
8293 : }
8294 : ;
8295 :
8296 : grant_role_opt_list:
8297 78 : grant_role_opt_list ',' grant_role_opt { $$ = lappend($1, $3); }
8298 117 : | grant_role_opt { $$ = list_make1($1); }
8299 : ;
8300 :
8301 : grant_role_opt:
8302 : ColLabel grant_role_opt_value
8303 : {
8304 195 : $$ = makeDefElem(pstrdup($1), $2, @1);
8305 : }
8306 : ;
8307 :
8308 : grant_role_opt_value:
8309 48 : OPTION { $$ = (Node *) makeBoolean(true); }
8310 73 : | TRUE_P { $$ = (Node *) makeBoolean(true); }
8311 74 : | FALSE_P { $$ = (Node *) makeBoolean(false); }
8312 : ;
8313 :
8314 108 : opt_granted_by: GRANTED BY RoleSpec { $$ = $3; }
8315 8636 : | /*EMPTY*/ { $$ = NULL; }
8316 : ;
8317 :
8318 : /*****************************************************************************
8319 : *
8320 : * ALTER DEFAULT PRIVILEGES statement
8321 : *
8322 : *****************************************************************************/
8323 :
8324 : AlterDefaultPrivilegesStmt:
8325 : ALTER DEFAULT PRIVILEGES DefACLOptionList DefACLAction
8326 : {
8327 135 : AlterDefaultPrivilegesStmt *n = makeNode(AlterDefaultPrivilegesStmt);
8328 :
8329 135 : n->options = $4;
8330 135 : n->action = (GrantStmt *) $5;
8331 135 : $$ = (Node *) n;
8332 : }
8333 : ;
8334 :
8335 : DefACLOptionList:
8336 93 : DefACLOptionList DefACLOption { $$ = lappend($1, $2); }
8337 135 : | /* EMPTY */ { $$ = NIL; }
8338 : ;
8339 :
8340 : DefACLOption:
8341 : IN_P SCHEMA name_list
8342 : {
8343 39 : $$ = makeDefElem("schemas", (Node *) $3, @1);
8344 : }
8345 : | FOR ROLE role_list
8346 : {
8347 54 : $$ = makeDefElem("roles", (Node *) $3, @1);
8348 : }
8349 : | FOR USER role_list
8350 : {
8351 0 : $$ = makeDefElem("roles", (Node *) $3, @1);
8352 : }
8353 : ;
8354 :
8355 : /*
8356 : * This should match GRANT/REVOKE, except that individual target objects
8357 : * are not mentioned and we only allow a subset of object types.
8358 : */
8359 : DefACLAction:
8360 : GRANT privileges ON defacl_privilege_target TO grantee_list
8361 : opt_grant_grant_option
8362 : {
8363 82 : GrantStmt *n = makeNode(GrantStmt);
8364 :
8365 82 : n->is_grant = true;
8366 82 : n->privileges = $2;
8367 82 : n->targtype = ACL_TARGET_DEFAULTS;
8368 82 : n->objtype = $4;
8369 82 : n->objects = NIL;
8370 82 : n->grantees = $6;
8371 82 : n->grant_option = $7;
8372 82 : $$ = (Node *) n;
8373 : }
8374 : | REVOKE privileges ON defacl_privilege_target
8375 : FROM grantee_list opt_drop_behavior
8376 : {
8377 53 : GrantStmt *n = makeNode(GrantStmt);
8378 :
8379 53 : n->is_grant = false;
8380 53 : n->grant_option = false;
8381 53 : n->privileges = $2;
8382 53 : n->targtype = ACL_TARGET_DEFAULTS;
8383 53 : n->objtype = $4;
8384 53 : n->objects = NIL;
8385 53 : n->grantees = $6;
8386 53 : n->behavior = $7;
8387 53 : $$ = (Node *) n;
8388 : }
8389 : | REVOKE GRANT OPTION FOR privileges ON defacl_privilege_target
8390 : FROM grantee_list opt_drop_behavior
8391 : {
8392 0 : GrantStmt *n = makeNode(GrantStmt);
8393 :
8394 0 : n->is_grant = false;
8395 0 : n->grant_option = true;
8396 0 : n->privileges = $5;
8397 0 : n->targtype = ACL_TARGET_DEFAULTS;
8398 0 : n->objtype = $7;
8399 0 : n->objects = NIL;
8400 0 : n->grantees = $9;
8401 0 : n->behavior = $10;
8402 0 : $$ = (Node *) n;
8403 : }
8404 : ;
8405 :
8406 : defacl_privilege_target:
8407 51 : TABLES { $$ = OBJECT_TABLE; }
8408 10 : | FUNCTIONS { $$ = OBJECT_FUNCTION; }
8409 4 : | ROUTINES { $$ = OBJECT_FUNCTION; }
8410 4 : | SEQUENCES { $$ = OBJECT_SEQUENCE; }
8411 22 : | TYPES_P { $$ = OBJECT_TYPE; }
8412 24 : | SCHEMAS { $$ = OBJECT_SCHEMA; }
8413 20 : | LARGE_P OBJECTS_P { $$ = OBJECT_LARGEOBJECT; }
8414 : ;
8415 :
8416 :
8417 : /*****************************************************************************
8418 : *
8419 : * QUERY: CREATE INDEX
8420 : *
8421 : * Note: we cannot put TABLESPACE clause after WHERE clause unless we are
8422 : * willing to make TABLESPACE a fully reserved word.
8423 : *****************************************************************************/
8424 :
8425 : IndexStmt: CREATE opt_unique INDEX opt_concurrently opt_single_name
8426 : ON relation_expr access_method_clause '(' index_params ')'
8427 : opt_include opt_unique_null_treatment opt_reloptions OptTableSpace where_clause
8428 : {
8429 4368 : IndexStmt *n = makeNode(IndexStmt);
8430 :
8431 4368 : n->unique = $2;
8432 4368 : n->concurrent = $4;
8433 4368 : n->idxname = $5;
8434 4368 : n->relation = $7;
8435 4368 : n->accessMethod = $8;
8436 4368 : n->indexParams = $10;
8437 4368 : n->indexIncludingParams = $12;
8438 4368 : n->nulls_not_distinct = !$13;
8439 4368 : n->options = $14;
8440 4368 : n->tableSpace = $15;
8441 4368 : n->whereClause = $16;
8442 4368 : n->excludeOpNames = NIL;
8443 4368 : n->idxcomment = NULL;
8444 4368 : n->indexOid = InvalidOid;
8445 4368 : n->oldNumber = InvalidRelFileNumber;
8446 4368 : n->oldCreateSubid = InvalidSubTransactionId;
8447 4368 : n->oldFirstRelfilelocatorSubid = InvalidSubTransactionId;
8448 4368 : n->primary = false;
8449 4368 : n->isconstraint = false;
8450 4368 : n->deferrable = false;
8451 4368 : n->initdeferred = false;
8452 4368 : n->transformed = false;
8453 4368 : n->if_not_exists = false;
8454 4368 : n->reset_default_tblspc = false;
8455 4368 : $$ = (Node *) n;
8456 : }
8457 : | CREATE opt_unique INDEX opt_concurrently IF_P NOT EXISTS name
8458 : ON relation_expr access_method_clause '(' index_params ')'
8459 : opt_include opt_unique_null_treatment opt_reloptions OptTableSpace where_clause
8460 : {
8461 12 : IndexStmt *n = makeNode(IndexStmt);
8462 :
8463 12 : n->unique = $2;
8464 12 : n->concurrent = $4;
8465 12 : n->idxname = $8;
8466 12 : n->relation = $10;
8467 12 : n->accessMethod = $11;
8468 12 : n->indexParams = $13;
8469 12 : n->indexIncludingParams = $15;
8470 12 : n->nulls_not_distinct = !$16;
8471 12 : n->options = $17;
8472 12 : n->tableSpace = $18;
8473 12 : n->whereClause = $19;
8474 12 : n->excludeOpNames = NIL;
8475 12 : n->idxcomment = NULL;
8476 12 : n->indexOid = InvalidOid;
8477 12 : n->oldNumber = InvalidRelFileNumber;
8478 12 : n->oldCreateSubid = InvalidSubTransactionId;
8479 12 : n->oldFirstRelfilelocatorSubid = InvalidSubTransactionId;
8480 12 : n->primary = false;
8481 12 : n->isconstraint = false;
8482 12 : n->deferrable = false;
8483 12 : n->initdeferred = false;
8484 12 : n->transformed = false;
8485 12 : n->if_not_exists = true;
8486 12 : n->reset_default_tblspc = false;
8487 12 : $$ = (Node *) n;
8488 : }
8489 : ;
8490 :
8491 : opt_unique:
8492 831 : UNIQUE { $$ = true; }
8493 3553 : | /*EMPTY*/ { $$ = false; }
8494 : ;
8495 :
8496 : access_method_clause:
8497 1845 : USING name { $$ = $2; }
8498 2688 : | /*EMPTY*/ { $$ = DEFAULT_INDEX_TYPE; }
8499 : ;
8500 :
8501 5630 : index_params: index_elem { $$ = list_make1($1); }
8502 1399 : | index_params ',' index_elem { $$ = lappend($1, $3); }
8503 : ;
8504 :
8505 :
8506 : index_elem_options:
8507 : opt_collate opt_qualified_name opt_asc_desc opt_nulls_order
8508 : {
8509 7410 : $$ = makeNode(IndexElem);
8510 7410 : $$->name = NULL;
8511 7410 : $$->expr = NULL;
8512 7410 : $$->indexcolname = NULL;
8513 7410 : $$->collation = $1;
8514 7410 : $$->opclass = $2;
8515 7410 : $$->opclassopts = NIL;
8516 7410 : $$->ordering = $3;
8517 7410 : $$->nulls_ordering = $4;
8518 : /* location will be filled in index_elem production */
8519 : }
8520 : | opt_collate any_name reloptions opt_asc_desc opt_nulls_order
8521 : {
8522 91 : $$ = makeNode(IndexElem);
8523 91 : $$->name = NULL;
8524 91 : $$->expr = NULL;
8525 91 : $$->indexcolname = NULL;
8526 91 : $$->collation = $1;
8527 91 : $$->opclass = $2;
8528 91 : $$->opclassopts = $3;
8529 91 : $$->ordering = $4;
8530 91 : $$->nulls_ordering = $5;
8531 : /* location will be filled in index_elem production */
8532 : }
8533 : ;
8534 :
8535 : /*
8536 : * Index attributes can be either simple column references, or arbitrary
8537 : * expressions in parens. For backwards-compatibility reasons, we allow
8538 : * an expression that's just a function call to be written without parens.
8539 : */
8540 : index_elem: ColId index_elem_options
8541 : {
8542 6640 : $$ = $2;
8543 6640 : $$->name = $1;
8544 6640 : $$->location = @1;
8545 : }
8546 : | func_expr_windowless index_elem_options
8547 : {
8548 521 : $$ = $2;
8549 521 : $$->expr = $1;
8550 521 : $$->location = @1;
8551 : }
8552 : | '(' a_expr ')' index_elem_options
8553 : {
8554 340 : $$ = $4;
8555 340 : $$->expr = $2;
8556 340 : $$->location = @1;
8557 : }
8558 : ;
8559 :
8560 141 : opt_include: INCLUDE '(' index_including_params ')' { $$ = $3; }
8561 4239 : | /* EMPTY */ { $$ = NIL; }
8562 : ;
8563 :
8564 141 : index_including_params: index_elem { $$ = list_make1($1); }
8565 109 : | index_including_params ',' index_elem { $$ = lappend($1, $3); }
8566 : ;
8567 :
8568 126 : opt_collate: COLLATE any_name { $$ = $2; }
8569 11267 : | /*EMPTY*/ { $$ = NIL; }
8570 : ;
8571 :
8572 :
8573 1012 : opt_asc_desc: ASC { $$ = SORTBY_ASC; }
8574 2378 : | DESC { $$ = SORTBY_DESC; }
8575 78186 : | /*EMPTY*/ { $$ = SORTBY_DEFAULT; }
8576 : ;
8577 :
8578 212 : opt_nulls_order: NULLS_LA FIRST_P { $$ = SORTBY_NULLS_FIRST; }
8579 904 : | NULLS_LA LAST_P { $$ = SORTBY_NULLS_LAST; }
8580 80602 : | /*EMPTY*/ { $$ = SORTBY_NULLS_DEFAULT; }
8581 : ;
8582 :
8583 :
8584 : /*****************************************************************************
8585 : *
8586 : * QUERY:
8587 : * create [or replace] function <fname>
8588 : * [(<type-1> { , <type-n>})]
8589 : * returns <type-r>
8590 : * as <filename or code in language as appropriate>
8591 : * language <lang> [with parameters]
8592 : *
8593 : *****************************************************************************/
8594 :
8595 : CreateFunctionStmt:
8596 : CREATE opt_or_replace FUNCTION func_name func_args_with_defaults
8597 : RETURNS func_return opt_createfunc_opt_list opt_routine_body
8598 : {
8599 11644 : CreateFunctionStmt *n = makeNode(CreateFunctionStmt);
8600 :
8601 11644 : n->is_procedure = false;
8602 11644 : n->replace = $2;
8603 11644 : n->funcname = $4;
8604 11644 : n->parameters = $5;
8605 11644 : n->returnType = $7;
8606 11644 : n->options = $8;
8607 11644 : n->sql_body = $9;
8608 11644 : $$ = (Node *) n;
8609 : }
8610 : | CREATE opt_or_replace FUNCTION func_name func_args_with_defaults
8611 : RETURNS TABLE '(' table_func_column_list ')' opt_createfunc_opt_list opt_routine_body
8612 : {
8613 142 : CreateFunctionStmt *n = makeNode(CreateFunctionStmt);
8614 :
8615 142 : n->is_procedure = false;
8616 142 : n->replace = $2;
8617 142 : n->funcname = $4;
8618 142 : n->parameters = mergeTableFuncParameters($5, $9, yyscanner);
8619 142 : n->returnType = TableFuncTypeName($9);
8620 142 : n->returnType->location = @7;
8621 142 : n->options = $11;
8622 142 : n->sql_body = $12;
8623 142 : $$ = (Node *) n;
8624 : }
8625 : | CREATE opt_or_replace FUNCTION func_name func_args_with_defaults
8626 : opt_createfunc_opt_list opt_routine_body
8627 : {
8628 301 : CreateFunctionStmt *n = makeNode(CreateFunctionStmt);
8629 :
8630 301 : n->is_procedure = false;
8631 301 : n->replace = $2;
8632 301 : n->funcname = $4;
8633 301 : n->parameters = $5;
8634 301 : n->returnType = NULL;
8635 301 : n->options = $6;
8636 301 : n->sql_body = $7;
8637 301 : $$ = (Node *) n;
8638 : }
8639 : | CREATE opt_or_replace PROCEDURE func_name func_args_with_defaults
8640 : opt_createfunc_opt_list opt_routine_body
8641 : {
8642 218 : CreateFunctionStmt *n = makeNode(CreateFunctionStmt);
8643 :
8644 218 : n->is_procedure = true;
8645 218 : n->replace = $2;
8646 218 : n->funcname = $4;
8647 218 : n->parameters = $5;
8648 218 : n->returnType = NULL;
8649 218 : n->options = $6;
8650 218 : n->sql_body = $7;
8651 218 : $$ = (Node *) n;
8652 : }
8653 : ;
8654 :
8655 : opt_or_replace:
8656 3593 : OR REPLACE { $$ = true; }
8657 12142 : | /*EMPTY*/ { $$ = false; }
8658 : ;
8659 :
8660 3879 : func_args: '(' func_args_list ')' { $$ = $2; }
8661 1166 : | '(' ')' { $$ = NIL; }
8662 : ;
8663 :
8664 : func_args_list:
8665 3879 : func_arg { $$ = list_make1($1); }
8666 3920 : | func_args_list ',' func_arg { $$ = lappend($1, $3); }
8667 : ;
8668 :
8669 : function_with_argtypes_list:
8670 2895 : function_with_argtypes { $$ = list_make1($1); }
8671 : | function_with_argtypes_list ',' function_with_argtypes
8672 56 : { $$ = lappend($1, $3); }
8673 : ;
8674 :
8675 : function_with_argtypes:
8676 : func_name func_args
8677 : {
8678 5045 : ObjectWithArgs *n = makeNode(ObjectWithArgs);
8679 :
8680 5045 : n->objname = $1;
8681 5045 : n->objargs = extractArgTypes($2);
8682 5045 : n->objfuncargs = $2;
8683 5045 : $$ = n;
8684 : }
8685 : /*
8686 : * Because of reduce/reduce conflicts, we can't use func_name
8687 : * below, but we can write it out the long way, which actually
8688 : * allows more cases.
8689 : */
8690 : | type_func_name_keyword
8691 : {
8692 0 : ObjectWithArgs *n = makeNode(ObjectWithArgs);
8693 :
8694 0 : n->objname = list_make1(makeString(pstrdup($1)));
8695 0 : n->args_unspecified = true;
8696 0 : $$ = n;
8697 : }
8698 : | ColId
8699 : {
8700 286 : ObjectWithArgs *n = makeNode(ObjectWithArgs);
8701 :
8702 286 : n->objname = list_make1(makeString($1));
8703 286 : n->args_unspecified = true;
8704 286 : $$ = n;
8705 : }
8706 : | ColId indirection
8707 : {
8708 14 : ObjectWithArgs *n = makeNode(ObjectWithArgs);
8709 :
8710 14 : n->objname = check_func_name(lcons(makeString($1), $2),
8711 : yyscanner);
8712 14 : n->args_unspecified = true;
8713 14 : $$ = n;
8714 : }
8715 : ;
8716 :
8717 : /*
8718 : * func_args_with_defaults is separate because we only want to accept
8719 : * defaults in CREATE FUNCTION, not in ALTER etc.
8720 : */
8721 : func_args_with_defaults:
8722 9631 : '(' func_args_with_defaults_list ')' { $$ = $2; }
8723 2674 : | '(' ')' { $$ = NIL; }
8724 : ;
8725 :
8726 : func_args_with_defaults_list:
8727 9631 : func_arg_with_default { $$ = list_make1($1); }
8728 : | func_args_with_defaults_list ',' func_arg_with_default
8729 13621 : { $$ = lappend($1, $3); }
8730 : ;
8731 :
8732 : /*
8733 : * The style with arg_class first is SQL99 standard, but Oracle puts
8734 : * param_name first; accept both since it's likely people will try both
8735 : * anyway. Don't bother trying to save productions by letting arg_class
8736 : * have an empty alternative ... you'll get shift/reduce conflicts.
8737 : *
8738 : * We can catch over-specified arguments here if we want to,
8739 : * but for now better to silently swallow typmod, etc.
8740 : * - thomas 2000-03-22
8741 : */
8742 : func_arg:
8743 : arg_class param_name func_type
8744 : {
8745 6687 : FunctionParameter *n = makeNode(FunctionParameter);
8746 :
8747 6687 : n->name = $2;
8748 6687 : n->argType = $3;
8749 6687 : n->mode = $1;
8750 6687 : n->defexpr = NULL;
8751 6687 : n->location = @1;
8752 6687 : $$ = n;
8753 : }
8754 : | param_name arg_class func_type
8755 : {
8756 235 : FunctionParameter *n = makeNode(FunctionParameter);
8757 :
8758 235 : n->name = $1;
8759 235 : n->argType = $3;
8760 235 : n->mode = $2;
8761 235 : n->defexpr = NULL;
8762 235 : n->location = @1;
8763 235 : $$ = n;
8764 : }
8765 : | param_name func_type
8766 : {
8767 3996 : FunctionParameter *n = makeNode(FunctionParameter);
8768 :
8769 3996 : n->name = $1;
8770 3996 : n->argType = $2;
8771 3996 : n->mode = FUNC_PARAM_DEFAULT;
8772 3996 : n->defexpr = NULL;
8773 3996 : n->location = @1;
8774 3996 : $$ = n;
8775 : }
8776 : | arg_class func_type
8777 : {
8778 195 : FunctionParameter *n = makeNode(FunctionParameter);
8779 :
8780 195 : n->name = NULL;
8781 195 : n->argType = $2;
8782 195 : n->mode = $1;
8783 195 : n->defexpr = NULL;
8784 195 : n->location = @1;
8785 195 : $$ = n;
8786 : }
8787 : | func_type
8788 : {
8789 20494 : FunctionParameter *n = makeNode(FunctionParameter);
8790 :
8791 20494 : n->name = NULL;
8792 20494 : n->argType = $1;
8793 20494 : n->mode = FUNC_PARAM_DEFAULT;
8794 20494 : n->defexpr = NULL;
8795 20494 : n->location = @1;
8796 20494 : $$ = n;
8797 : }
8798 : ;
8799 :
8800 : /* INOUT is SQL99 standard, IN OUT is for Oracle compatibility */
8801 1309 : arg_class: IN_P { $$ = FUNC_PARAM_IN; }
8802 5568 : | OUT_P { $$ = FUNC_PARAM_OUT; }
8803 119 : | INOUT { $$ = FUNC_PARAM_INOUT; }
8804 0 : | IN_P OUT_P { $$ = FUNC_PARAM_INOUT; }
8805 121 : | VARIADIC { $$ = FUNC_PARAM_VARIADIC; }
8806 : ;
8807 :
8808 : /*
8809 : * Ideally param_name should be ColId, but that causes too many conflicts.
8810 : */
8811 : param_name: type_function_name
8812 : ;
8813 :
8814 : func_return:
8815 : func_type
8816 : {
8817 : /* We can catch over-specified results here if we want to,
8818 : * but for now better to silently swallow typmod, etc.
8819 : * - thomas 2000-03-22
8820 : */
8821 11644 : $$ = $1;
8822 : }
8823 : ;
8824 :
8825 : /*
8826 : * We would like to make the %TYPE productions here be ColId attrs etc,
8827 : * but that causes reduce/reduce conflicts. type_function_name
8828 : * is next best choice.
8829 : */
8830 55231 : func_type: Typename { $$ = $1; }
8831 : | type_function_name attrs '%' TYPE_P
8832 : {
8833 12 : $$ = makeTypeNameFromNameList(lcons(makeString($1), $2));
8834 12 : $$->pct_type = true;
8835 12 : $$->location = @1;
8836 : }
8837 : | SETOF type_function_name attrs '%' TYPE_P
8838 : {
8839 4 : $$ = makeTypeNameFromNameList(lcons(makeString($2), $3));
8840 4 : $$->pct_type = true;
8841 4 : $$->setof = true;
8842 4 : $$->location = @2;
8843 : }
8844 : ;
8845 :
8846 : func_arg_with_default:
8847 : func_arg
8848 : {
8849 22758 : $$ = $1;
8850 : }
8851 : | func_arg DEFAULT a_expr
8852 : {
8853 366 : $$ = $1;
8854 366 : $$->defexpr = $3;
8855 : }
8856 : | func_arg '=' a_expr
8857 : {
8858 128 : $$ = $1;
8859 128 : $$->defexpr = $3;
8860 : }
8861 : ;
8862 :
8863 : /* Aggregate args can be most things that function args can be */
8864 : aggr_arg: func_arg
8865 : {
8866 556 : if (!($1->mode == FUNC_PARAM_DEFAULT ||
8867 36 : $1->mode == FUNC_PARAM_IN ||
8868 36 : $1->mode == FUNC_PARAM_VARIADIC))
8869 0 : ereport(ERROR,
8870 : (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
8871 : errmsg("aggregates cannot have output arguments"),
8872 : parser_errposition(@1)));
8873 556 : $$ = $1;
8874 : }
8875 : ;
8876 :
8877 : /*
8878 : * The SQL standard offers no guidance on how to declare aggregate argument
8879 : * lists, since it doesn't have CREATE AGGREGATE etc. We accept these cases:
8880 : *
8881 : * (*) - normal agg with no args
8882 : * (aggr_arg,...) - normal agg with args
8883 : * (ORDER BY aggr_arg,...) - ordered-set agg with no direct args
8884 : * (aggr_arg,... ORDER BY aggr_arg,...) - ordered-set agg with direct args
8885 : *
8886 : * The zero-argument case is spelled with '*' for consistency with COUNT(*).
8887 : *
8888 : * An additional restriction is that if the direct-args list ends in a
8889 : * VARIADIC item, the ordered-args list must contain exactly one item that
8890 : * is also VARIADIC with the same type. This allows us to collapse the two
8891 : * VARIADIC items into one, which is necessary to represent the aggregate in
8892 : * pg_proc. We check this at the grammar stage so that we can return a list
8893 : * in which the second VARIADIC item is already discarded, avoiding extra work
8894 : * in cases such as DROP AGGREGATE.
8895 : *
8896 : * The return value of this production is a two-element list, in which the
8897 : * first item is a sublist of FunctionParameter nodes (with any duplicate
8898 : * VARIADIC item already dropped, as per above) and the second is an Integer
8899 : * node, containing -1 if there was no ORDER BY and otherwise the number
8900 : * of argument declarations before the ORDER BY. (If this number is equal
8901 : * to the first sublist's length, then we dropped a duplicate VARIADIC item.)
8902 : * This representation is passed as-is to CREATE AGGREGATE; for operations
8903 : * on existing aggregates, we can just apply extractArgTypes to the first
8904 : * sublist.
8905 : */
8906 : aggr_args: '(' '*' ')'
8907 : {
8908 85 : $$ = list_make2(NIL, makeInteger(-1));
8909 : }
8910 : | '(' aggr_args_list ')'
8911 : {
8912 452 : $$ = list_make2($2, makeInteger(-1));
8913 : }
8914 : | '(' ORDER BY aggr_args_list ')'
8915 : {
8916 4 : $$ = list_make2($4, makeInteger(0));
8917 : }
8918 : | '(' aggr_args_list ORDER BY aggr_args_list ')'
8919 : {
8920 : /* this is the only case requiring consistency checking */
8921 20 : $$ = makeOrderedSetArgs($2, $5, yyscanner);
8922 : }
8923 : ;
8924 :
8925 : aggr_args_list:
8926 496 : aggr_arg { $$ = list_make1($1); }
8927 60 : | aggr_args_list ',' aggr_arg { $$ = lappend($1, $3); }
8928 : ;
8929 :
8930 : aggregate_with_argtypes:
8931 : func_name aggr_args
8932 : {
8933 220 : ObjectWithArgs *n = makeNode(ObjectWithArgs);
8934 :
8935 220 : n->objname = $1;
8936 220 : n->objargs = extractAggrArgTypes($2);
8937 220 : n->objfuncargs = (List *) linitial($2);
8938 220 : $$ = n;
8939 : }
8940 : ;
8941 :
8942 : aggregate_with_argtypes_list:
8943 69 : aggregate_with_argtypes { $$ = list_make1($1); }
8944 : | aggregate_with_argtypes_list ',' aggregate_with_argtypes
8945 0 : { $$ = lappend($1, $3); }
8946 : ;
8947 :
8948 : opt_createfunc_opt_list:
8949 : createfunc_opt_list
8950 62 : | /*EMPTY*/ { $$ = NIL; }
8951 : ;
8952 :
8953 : createfunc_opt_list:
8954 : /* Must be at least one to prevent conflict */
8955 12243 : createfunc_opt_item { $$ = list_make1($1); }
8956 29529 : | createfunc_opt_list createfunc_opt_item { $$ = lappend($1, $2); }
8957 : ;
8958 :
8959 : /*
8960 : * Options common to both CREATE FUNCTION and ALTER FUNCTION
8961 : */
8962 : common_func_opt_item:
8963 : CALLED ON NULL_P INPUT_P
8964 : {
8965 57 : $$ = makeDefElem("strict", (Node *) makeBoolean(false), @1);
8966 : }
8967 : | RETURNS NULL_P ON NULL_P INPUT_P
8968 : {
8969 454 : $$ = makeDefElem("strict", (Node *) makeBoolean(true), @1);
8970 : }
8971 : | STRICT_P
8972 : {
8973 5767 : $$ = makeDefElem("strict", (Node *) makeBoolean(true), @1);
8974 : }
8975 : | IMMUTABLE
8976 : {
8977 4707 : $$ = makeDefElem("volatility", (Node *) makeString("immutable"), @1);
8978 : }
8979 : | STABLE
8980 : {
8981 889 : $$ = makeDefElem("volatility", (Node *) makeString("stable"), @1);
8982 : }
8983 : | VOLATILE
8984 : {
8985 179 : $$ = makeDefElem("volatility", (Node *) makeString("volatile"), @1);
8986 : }
8987 : | EXTERNAL SECURITY DEFINER
8988 : {
8989 0 : $$ = makeDefElem("security", (Node *) makeBoolean(true), @1);
8990 : }
8991 : | EXTERNAL SECURITY INVOKER
8992 : {
8993 0 : $$ = makeDefElem("security", (Node *) makeBoolean(false), @1);
8994 : }
8995 : | SECURITY DEFINER
8996 : {
8997 36 : $$ = makeDefElem("security", (Node *) makeBoolean(true), @1);
8998 : }
8999 : | SECURITY INVOKER
9000 : {
9001 12 : $$ = makeDefElem("security", (Node *) makeBoolean(false), @1);
9002 : }
9003 : | LEAKPROOF
9004 : {
9005 30 : $$ = makeDefElem("leakproof", (Node *) makeBoolean(true), @1);
9006 : }
9007 : | NOT LEAKPROOF
9008 : {
9009 8 : $$ = makeDefElem("leakproof", (Node *) makeBoolean(false), @1);
9010 : }
9011 : | COST NumericOnly
9012 : {
9013 1990 : $$ = makeDefElem("cost", (Node *) $2, @1);
9014 : }
9015 : | ROWS NumericOnly
9016 : {
9017 61 : $$ = makeDefElem("rows", (Node *) $2, @1);
9018 : }
9019 : | SUPPORT any_name
9020 : {
9021 64 : $$ = makeDefElem("support", (Node *) $2, @1);
9022 : }
9023 : | FunctionSetResetClause
9024 : {
9025 : /* we abuse the normal content of a DefElem here */
9026 96 : $$ = makeDefElem("set", (Node *) $1, @1);
9027 : }
9028 : | PARALLEL ColId
9029 : {
9030 5977 : $$ = makeDefElem("parallel", (Node *) makeString($2), @1);
9031 : }
9032 : ;
9033 :
9034 : createfunc_opt_item:
9035 : AS func_as
9036 : {
9037 9353 : $$ = makeDefElem("as", (Node *) $2, @1);
9038 : }
9039 : | LANGUAGE NonReservedWord_or_Sconst
9040 : {
9041 12230 : $$ = makeDefElem("language", (Node *) makeString($2), @1);
9042 : }
9043 : | TRANSFORM transform_type_list
9044 : {
9045 59 : $$ = makeDefElem("transform", (Node *) $2, @1);
9046 : }
9047 : | WINDOW
9048 : {
9049 13 : $$ = makeDefElem("window", (Node *) makeBoolean(true), @1);
9050 : }
9051 : | common_func_opt_item
9052 : {
9053 20117 : $$ = $1;
9054 : }
9055 : ;
9056 :
9057 7628 : func_as: Sconst { $$ = list_make1(makeString($1)); }
9058 : | Sconst ',' Sconst
9059 : {
9060 1725 : $$ = list_make2(makeString($1), makeString($3));
9061 : }
9062 : ;
9063 :
9064 : ReturnStmt: RETURN a_expr
9065 : {
9066 2507 : ReturnStmt *r = makeNode(ReturnStmt);
9067 :
9068 2507 : r->returnval = (Node *) $2;
9069 2507 : $$ = (Node *) r;
9070 : }
9071 : ;
9072 :
9073 : opt_routine_body:
9074 : ReturnStmt
9075 : {
9076 2503 : $$ = $1;
9077 : }
9078 : | BEGIN_P ATOMIC routine_body_stmt_list END_P
9079 : {
9080 : /*
9081 : * A compound statement is stored as a single-item list
9082 : * containing the list of statements as its member. That
9083 : * way, the parse analysis code can tell apart an empty
9084 : * body from no body at all.
9085 : */
9086 453 : $$ = (Node *) list_make1($3);
9087 : }
9088 : | /*EMPTY*/
9089 : {
9090 9349 : $$ = NULL;
9091 : }
9092 : ;
9093 :
9094 : routine_body_stmt_list:
9095 : routine_body_stmt_list routine_body_stmt ';'
9096 : {
9097 : /* As in stmtmulti, discard empty statements */
9098 464 : if ($2 != NULL)
9099 452 : $$ = lappend($1, $2);
9100 : else
9101 12 : $$ = $1;
9102 : }
9103 : | /*EMPTY*/
9104 : {
9105 453 : $$ = NIL;
9106 : }
9107 : ;
9108 :
9109 : routine_body_stmt:
9110 : stmt
9111 : | ReturnStmt
9112 : ;
9113 :
9114 : transform_type_list:
9115 59 : FOR TYPE_P Typename { $$ = list_make1($3); }
9116 2 : | transform_type_list ',' FOR TYPE_P Typename { $$ = lappend($1, $5); }
9117 : ;
9118 :
9119 : opt_definition:
9120 432 : WITH definition { $$ = $2; }
9121 6375 : | /*EMPTY*/ { $$ = NIL; }
9122 : ;
9123 :
9124 : table_func_column: param_name func_type
9125 : {
9126 327 : FunctionParameter *n = makeNode(FunctionParameter);
9127 :
9128 327 : n->name = $1;
9129 327 : n->argType = $2;
9130 327 : n->mode = FUNC_PARAM_TABLE;
9131 327 : n->defexpr = NULL;
9132 327 : n->location = @1;
9133 327 : $$ = n;
9134 : }
9135 : ;
9136 :
9137 : table_func_column_list:
9138 : table_func_column
9139 : {
9140 142 : $$ = list_make1($1);
9141 : }
9142 : | table_func_column_list ',' table_func_column
9143 : {
9144 185 : $$ = lappend($1, $3);
9145 : }
9146 : ;
9147 :
9148 : /*****************************************************************************
9149 : * ALTER FUNCTION / ALTER PROCEDURE / ALTER ROUTINE
9150 : *
9151 : * RENAME and OWNER subcommands are already provided by the generic
9152 : * ALTER infrastructure, here we just specify alterations that can
9153 : * only be applied to functions.
9154 : *
9155 : *****************************************************************************/
9156 : AlterFunctionStmt:
9157 : ALTER FUNCTION function_with_argtypes alterfunc_opt_list opt_restrict
9158 : {
9159 196 : AlterFunctionStmt *n = makeNode(AlterFunctionStmt);
9160 :
9161 196 : n->objtype = OBJECT_FUNCTION;
9162 196 : n->func = $3;
9163 196 : n->actions = $4;
9164 196 : $$ = (Node *) n;
9165 : }
9166 : | ALTER PROCEDURE function_with_argtypes alterfunc_opt_list opt_restrict
9167 : {
9168 12 : AlterFunctionStmt *n = makeNode(AlterFunctionStmt);
9169 :
9170 12 : n->objtype = OBJECT_PROCEDURE;
9171 12 : n->func = $3;
9172 12 : n->actions = $4;
9173 12 : $$ = (Node *) n;
9174 : }
9175 : | ALTER ROUTINE function_with_argtypes alterfunc_opt_list opt_restrict
9176 : {
9177 0 : AlterFunctionStmt *n = makeNode(AlterFunctionStmt);
9178 :
9179 0 : n->objtype = OBJECT_ROUTINE;
9180 0 : n->func = $3;
9181 0 : n->actions = $4;
9182 0 : $$ = (Node *) n;
9183 : }
9184 : ;
9185 :
9186 : alterfunc_opt_list:
9187 : /* At least one option must be specified */
9188 208 : common_func_opt_item { $$ = list_make1($1); }
9189 2 : | alterfunc_opt_list common_func_opt_item { $$ = lappend($1, $2); }
9190 : ;
9191 :
9192 : /* Ignored, merely for SQL compliance */
9193 : opt_restrict:
9194 : RESTRICT
9195 : | /* EMPTY */
9196 : ;
9197 :
9198 :
9199 : /*****************************************************************************
9200 : *
9201 : * QUERY:
9202 : *
9203 : * DROP FUNCTION funcname (arg1, arg2, ...) [ RESTRICT | CASCADE ]
9204 : * DROP PROCEDURE procname (arg1, arg2, ...) [ RESTRICT | CASCADE ]
9205 : * DROP ROUTINE routname (arg1, arg2, ...) [ RESTRICT | CASCADE ]
9206 : * DROP AGGREGATE aggname (arg1, ...) [ RESTRICT | CASCADE ]
9207 : * DROP OPERATOR opname (leftoperand_typ, rightoperand_typ) [ RESTRICT | CASCADE ]
9208 : *
9209 : *****************************************************************************/
9210 :
9211 : RemoveFuncStmt:
9212 : DROP FUNCTION function_with_argtypes_list opt_drop_behavior
9213 : {
9214 2125 : DropStmt *n = makeNode(DropStmt);
9215 :
9216 2125 : n->removeType = OBJECT_FUNCTION;
9217 2125 : n->objects = $3;
9218 2125 : n->behavior = $4;
9219 2125 : n->missing_ok = false;
9220 2125 : n->concurrent = false;
9221 2125 : $$ = (Node *) n;
9222 : }
9223 : | DROP FUNCTION IF_P EXISTS function_with_argtypes_list opt_drop_behavior
9224 : {
9225 136 : DropStmt *n = makeNode(DropStmt);
9226 :
9227 136 : n->removeType = OBJECT_FUNCTION;
9228 136 : n->objects = $5;
9229 136 : n->behavior = $6;
9230 136 : n->missing_ok = true;
9231 136 : n->concurrent = false;
9232 136 : $$ = (Node *) n;
9233 : }
9234 : | DROP PROCEDURE function_with_argtypes_list opt_drop_behavior
9235 : {
9236 89 : DropStmt *n = makeNode(DropStmt);
9237 :
9238 89 : n->removeType = OBJECT_PROCEDURE;
9239 89 : n->objects = $3;
9240 89 : n->behavior = $4;
9241 89 : n->missing_ok = false;
9242 89 : n->concurrent = false;
9243 89 : $$ = (Node *) n;
9244 : }
9245 : | DROP PROCEDURE IF_P EXISTS function_with_argtypes_list opt_drop_behavior
9246 : {
9247 4 : DropStmt *n = makeNode(DropStmt);
9248 :
9249 4 : n->removeType = OBJECT_PROCEDURE;
9250 4 : n->objects = $5;
9251 4 : n->behavior = $6;
9252 4 : n->missing_ok = true;
9253 4 : n->concurrent = false;
9254 4 : $$ = (Node *) n;
9255 : }
9256 : | DROP ROUTINE function_with_argtypes_list opt_drop_behavior
9257 : {
9258 8 : DropStmt *n = makeNode(DropStmt);
9259 :
9260 8 : n->removeType = OBJECT_ROUTINE;
9261 8 : n->objects = $3;
9262 8 : n->behavior = $4;
9263 8 : n->missing_ok = false;
9264 8 : n->concurrent = false;
9265 8 : $$ = (Node *) n;
9266 : }
9267 : | DROP ROUTINE IF_P EXISTS function_with_argtypes_list opt_drop_behavior
9268 : {
9269 4 : DropStmt *n = makeNode(DropStmt);
9270 :
9271 4 : n->removeType = OBJECT_ROUTINE;
9272 4 : n->objects = $5;
9273 4 : n->behavior = $6;
9274 4 : n->missing_ok = true;
9275 4 : n->concurrent = false;
9276 4 : $$ = (Node *) n;
9277 : }
9278 : ;
9279 :
9280 : RemoveAggrStmt:
9281 : DROP AGGREGATE aggregate_with_argtypes_list opt_drop_behavior
9282 : {
9283 49 : DropStmt *n = makeNode(DropStmt);
9284 :
9285 49 : n->removeType = OBJECT_AGGREGATE;
9286 49 : n->objects = $3;
9287 49 : n->behavior = $4;
9288 49 : n->missing_ok = false;
9289 49 : n->concurrent = false;
9290 49 : $$ = (Node *) n;
9291 : }
9292 : | DROP AGGREGATE IF_P EXISTS aggregate_with_argtypes_list opt_drop_behavior
9293 : {
9294 20 : DropStmt *n = makeNode(DropStmt);
9295 :
9296 20 : n->removeType = OBJECT_AGGREGATE;
9297 20 : n->objects = $5;
9298 20 : n->behavior = $6;
9299 20 : n->missing_ok = true;
9300 20 : n->concurrent = false;
9301 20 : $$ = (Node *) n;
9302 : }
9303 : ;
9304 :
9305 : RemoveOperStmt:
9306 : DROP OPERATOR operator_with_argtypes_list opt_drop_behavior
9307 : {
9308 124 : DropStmt *n = makeNode(DropStmt);
9309 :
9310 124 : n->removeType = OBJECT_OPERATOR;
9311 124 : n->objects = $3;
9312 124 : n->behavior = $4;
9313 124 : n->missing_ok = false;
9314 124 : n->concurrent = false;
9315 124 : $$ = (Node *) n;
9316 : }
9317 : | DROP OPERATOR IF_P EXISTS operator_with_argtypes_list opt_drop_behavior
9318 : {
9319 20 : DropStmt *n = makeNode(DropStmt);
9320 :
9321 20 : n->removeType = OBJECT_OPERATOR;
9322 20 : n->objects = $5;
9323 20 : n->behavior = $6;
9324 20 : n->missing_ok = true;
9325 20 : n->concurrent = false;
9326 20 : $$ = (Node *) n;
9327 : }
9328 : ;
9329 :
9330 : oper_argtypes:
9331 : '(' Typename ')'
9332 : {
9333 8 : ereport(ERROR,
9334 : (errcode(ERRCODE_SYNTAX_ERROR),
9335 : errmsg("missing argument"),
9336 : errhint("Use NONE to denote the missing argument of a unary operator."),
9337 : parser_errposition(@3)));
9338 : }
9339 : | '(' Typename ',' Typename ')'
9340 1247 : { $$ = list_make2($2, $4); }
9341 : | '(' NONE ',' Typename ')' /* left unary */
9342 20 : { $$ = list_make2(NULL, $4); }
9343 : | '(' Typename ',' NONE ')' /* right unary */
9344 8 : { $$ = list_make2($2, NULL); }
9345 : ;
9346 :
9347 : any_operator:
9348 : all_Op
9349 14105 : { $$ = list_make1(makeString($1)); }
9350 : | ColId '.' any_operator
9351 10709 : { $$ = lcons(makeString($1), $3); }
9352 : ;
9353 :
9354 : operator_with_argtypes_list:
9355 144 : operator_with_argtypes { $$ = list_make1($1); }
9356 : | operator_with_argtypes_list ',' operator_with_argtypes
9357 0 : { $$ = lappend($1, $3); }
9358 : ;
9359 :
9360 : operator_with_argtypes:
9361 : any_operator oper_argtypes
9362 : {
9363 1275 : ObjectWithArgs *n = makeNode(ObjectWithArgs);
9364 :
9365 1275 : n->objname = $1;
9366 1275 : n->objargs = $2;
9367 1275 : $$ = n;
9368 : }
9369 : ;
9370 :
9371 : /*****************************************************************************
9372 : *
9373 : * DO <anonymous code block> [ LANGUAGE language ]
9374 : *
9375 : * We use a DefElem list for future extensibility, and to allow flexibility
9376 : * in the clause order.
9377 : *
9378 : *****************************************************************************/
9379 :
9380 : DoStmt: DO dostmt_opt_list
9381 : {
9382 660 : DoStmt *n = makeNode(DoStmt);
9383 :
9384 660 : n->args = $2;
9385 660 : $$ = (Node *) n;
9386 : }
9387 : ;
9388 :
9389 : dostmt_opt_list:
9390 660 : dostmt_opt_item { $$ = list_make1($1); }
9391 102 : | dostmt_opt_list dostmt_opt_item { $$ = lappend($1, $2); }
9392 : ;
9393 :
9394 : dostmt_opt_item:
9395 : Sconst
9396 : {
9397 660 : $$ = makeDefElem("as", (Node *) makeString($1), @1);
9398 : }
9399 : | LANGUAGE NonReservedWord_or_Sconst
9400 : {
9401 102 : $$ = makeDefElem("language", (Node *) makeString($2), @1);
9402 : }
9403 : ;
9404 :
9405 : /*****************************************************************************
9406 : *
9407 : * CREATE CAST / DROP CAST
9408 : *
9409 : *****************************************************************************/
9410 :
9411 : CreateCastStmt: CREATE CAST '(' Typename AS Typename ')'
9412 : WITH FUNCTION function_with_argtypes cast_context
9413 : {
9414 60 : CreateCastStmt *n = makeNode(CreateCastStmt);
9415 :
9416 60 : n->sourcetype = $4;
9417 60 : n->targettype = $6;
9418 60 : n->func = $10;
9419 60 : n->context = (CoercionContext) $11;
9420 60 : n->inout = false;
9421 60 : $$ = (Node *) n;
9422 : }
9423 : | CREATE CAST '(' Typename AS Typename ')'
9424 : WITHOUT FUNCTION cast_context
9425 : {
9426 97 : CreateCastStmt *n = makeNode(CreateCastStmt);
9427 :
9428 97 : n->sourcetype = $4;
9429 97 : n->targettype = $6;
9430 97 : n->func = NULL;
9431 97 : n->context = (CoercionContext) $10;
9432 97 : n->inout = false;
9433 97 : $$ = (Node *) n;
9434 : }
9435 : | CREATE CAST '(' Typename AS Typename ')'
9436 : WITH INOUT cast_context
9437 : {
9438 5 : CreateCastStmt *n = makeNode(CreateCastStmt);
9439 :
9440 5 : n->sourcetype = $4;
9441 5 : n->targettype = $6;
9442 5 : n->func = NULL;
9443 5 : n->context = (CoercionContext) $10;
9444 5 : n->inout = true;
9445 5 : $$ = (Node *) n;
9446 : }
9447 : ;
9448 :
9449 22 : cast_context: AS IMPLICIT_P { $$ = COERCION_IMPLICIT; }
9450 30 : | AS ASSIGNMENT { $$ = COERCION_ASSIGNMENT; }
9451 110 : | /*EMPTY*/ { $$ = COERCION_EXPLICIT; }
9452 : ;
9453 :
9454 :
9455 : DropCastStmt: DROP CAST opt_if_exists '(' Typename AS Typename ')' opt_drop_behavior
9456 : {
9457 40 : DropStmt *n = makeNode(DropStmt);
9458 :
9459 40 : n->removeType = OBJECT_CAST;
9460 40 : n->objects = list_make1(list_make2($5, $7));
9461 40 : n->behavior = $9;
9462 40 : n->missing_ok = $3;
9463 40 : n->concurrent = false;
9464 40 : $$ = (Node *) n;
9465 : }
9466 : ;
9467 :
9468 23 : opt_if_exists: IF_P EXISTS { $$ = true; }
9469 24 : | /*EMPTY*/ { $$ = false; }
9470 : ;
9471 :
9472 :
9473 : /*****************************************************************************
9474 : *
9475 : * CREATE PROPERTY GRAPH
9476 : * ALTER PROPERTY GRAPH
9477 : *
9478 : *****************************************************************************/
9479 :
9480 : CreatePropGraphStmt: CREATE OptTemp PROPERTY GRAPH qualified_name opt_vertex_tables_clause opt_edge_tables_clause
9481 : {
9482 201 : CreatePropGraphStmt *n = makeNode(CreatePropGraphStmt);
9483 :
9484 201 : n->pgname = $5;
9485 201 : n->pgname->relpersistence = $2;
9486 201 : n->vertex_tables = $6;
9487 201 : n->edge_tables = $7;
9488 :
9489 201 : $$ = (Node *)n;
9490 : }
9491 : ;
9492 :
9493 : opt_vertex_tables_clause:
9494 164 : vertex_tables_clause { $$ = $1; }
9495 37 : | /*EMPTY*/ { $$ = NIL; }
9496 : ;
9497 :
9498 : vertex_tables_clause:
9499 196 : vertex_synonym TABLES '(' vertex_table_list ')' { $$ = $4; }
9500 : ;
9501 :
9502 : vertex_synonym: NODE | VERTEX
9503 : ;
9504 :
9505 196 : vertex_table_list: vertex_table_definition { $$ = list_make1($1); }
9506 202 : | vertex_table_list ',' vertex_table_definition { $$ = lappend($1, $3); }
9507 : ;
9508 :
9509 : vertex_table_definition: qualified_name opt_propgraph_table_alias opt_graph_table_key_clause
9510 : opt_element_table_label_and_properties
9511 : {
9512 398 : PropGraphVertex *n = makeNode(PropGraphVertex);
9513 :
9514 398 : $1->alias = $2;
9515 398 : n->vtable = $1;
9516 398 : n->vkey = $3;
9517 398 : n->labels = $4;
9518 398 : n->location = @1;
9519 :
9520 398 : $$ = (Node *) n;
9521 : }
9522 : ;
9523 :
9524 : opt_propgraph_table_alias:
9525 : AS name
9526 : {
9527 12 : $$ = makeNode(Alias);
9528 12 : $$->aliasname = $2;
9529 : }
9530 599 : | /*EMPTY*/ { $$ = NULL; }
9531 : ;
9532 :
9533 : opt_graph_table_key_clause:
9534 479 : KEY '(' columnList ')' { $$ = $3; }
9535 132 : | /*EMPTY*/ { $$ = NIL; }
9536 : ;
9537 :
9538 : opt_edge_tables_clause:
9539 110 : edge_tables_clause { $$ = $1; }
9540 91 : | /*EMPTY*/ { $$ = NIL; }
9541 : ;
9542 :
9543 : edge_tables_clause:
9544 138 : edge_synonym TABLES '(' edge_table_list ')' { $$ = $4; }
9545 : ;
9546 :
9547 : edge_synonym: EDGE | RELATIONSHIP
9548 : ;
9549 :
9550 138 : edge_table_list: edge_table_definition { $$ = list_make1($1); }
9551 75 : | edge_table_list ',' edge_table_definition { $$ = lappend($1, $3); }
9552 : ;
9553 :
9554 : edge_table_definition: qualified_name opt_propgraph_table_alias opt_graph_table_key_clause
9555 : source_vertex_table destination_vertex_table opt_element_table_label_and_properties
9556 : {
9557 213 : PropGraphEdge *n = makeNode(PropGraphEdge);
9558 :
9559 213 : $1->alias = $2;
9560 213 : n->etable = $1;
9561 213 : n->ekey = $3;
9562 213 : n->esrckey = linitial($4);
9563 213 : n->esrcvertex = lsecond($4);
9564 213 : n->esrcvertexcols = lthird($4);
9565 213 : n->edestkey = linitial($5);
9566 213 : n->edestvertex = lsecond($5);
9567 213 : n->edestvertexcols = lthird($5);
9568 213 : n->labels = $6;
9569 213 : n->location = @1;
9570 :
9571 213 : $$ = (Node *) n;
9572 : }
9573 : ;
9574 :
9575 : source_vertex_table: SOURCE name
9576 : {
9577 16 : $$ = list_make3(NULL, $2, NULL);
9578 : }
9579 : | SOURCE KEY '(' columnList ')' REFERENCES name '(' columnList ')'
9580 : {
9581 197 : $$ = list_make3($4, $7, $9);
9582 : }
9583 : ;
9584 :
9585 : destination_vertex_table: DESTINATION name
9586 : {
9587 16 : $$ = list_make3(NULL, $2, NULL);
9588 : }
9589 : | DESTINATION KEY '(' columnList ')' REFERENCES name '(' columnList ')'
9590 : {
9591 197 : $$ = list_make3($4, $7, $9);
9592 : }
9593 : ;
9594 :
9595 : opt_element_table_label_and_properties:
9596 : element_table_properties
9597 : {
9598 77 : PropGraphLabelAndProperties *lp = makeNode(PropGraphLabelAndProperties);
9599 :
9600 77 : lp->properties = (PropGraphProperties *) $1;
9601 77 : lp->location = @1;
9602 :
9603 77 : $$ = list_make1(lp);
9604 : }
9605 : | label_and_properties_list
9606 : {
9607 228 : $$ = $1;
9608 : }
9609 : | /*EMPTY*/
9610 : {
9611 306 : PropGraphLabelAndProperties *lp = makeNode(PropGraphLabelAndProperties);
9612 306 : PropGraphProperties *pr = makeNode(PropGraphProperties);
9613 :
9614 306 : pr->all = true;
9615 306 : pr->location = -1;
9616 306 : lp->properties = pr;
9617 306 : lp->location = -1;
9618 :
9619 306 : $$ = list_make1(lp);
9620 : }
9621 : ;
9622 :
9623 : element_table_properties:
9624 : NO PROPERTIES
9625 : {
9626 5 : PropGraphProperties *pr = makeNode(PropGraphProperties);
9627 :
9628 5 : pr->properties = NIL;
9629 5 : pr->location = @1;
9630 :
9631 5 : $$ = (Node *) pr;
9632 : }
9633 : | PROPERTIES ALL COLUMNS
9634 : /*
9635 : * SQL standard also allows "PROPERTIES ARE ALL COLUMNS", but that
9636 : * would require making ARE a keyword, which seems a bit much for
9637 : * such a marginal use. Could be added later if needed.
9638 : */
9639 : {
9640 16 : PropGraphProperties *pr = makeNode(PropGraphProperties);
9641 :
9642 16 : pr->all = true;
9643 16 : pr->location = @1;
9644 :
9645 16 : $$ = (Node *) pr;
9646 : }
9647 : | PROPERTIES '(' labeled_expr_list ')'
9648 : {
9649 368 : PropGraphProperties *pr = makeNode(PropGraphProperties);
9650 :
9651 368 : pr->properties = $3;
9652 368 : pr->location = @1;
9653 :
9654 368 : $$ = (Node *) pr;
9655 : }
9656 : ;
9657 :
9658 : label_and_properties_list:
9659 : label_and_properties
9660 : {
9661 228 : $$ = list_make1($1);
9662 : }
9663 : | label_and_properties_list label_and_properties
9664 : {
9665 116 : $$ = lappend($1, $2);
9666 : }
9667 : ;
9668 :
9669 : label_and_properties:
9670 : element_table_label_clause
9671 : {
9672 60 : PropGraphLabelAndProperties *lp = makeNode(PropGraphLabelAndProperties);
9673 60 : PropGraphProperties *pr = makeNode(PropGraphProperties);
9674 :
9675 60 : pr->all = true;
9676 60 : pr->location = -1;
9677 :
9678 60 : lp->label = $1;
9679 60 : lp->properties = pr;
9680 60 : lp->location = @1;
9681 :
9682 60 : $$ = (Node *) lp;
9683 : }
9684 : | element_table_label_clause element_table_properties
9685 : {
9686 284 : PropGraphLabelAndProperties *lp = makeNode(PropGraphLabelAndProperties);
9687 :
9688 284 : lp->label = $1;
9689 284 : lp->properties = (PropGraphProperties *) $2;
9690 284 : lp->location = @1;
9691 :
9692 284 : $$ = (Node *) lp;
9693 : }
9694 : ;
9695 :
9696 : element_table_label_clause:
9697 : LABEL name
9698 : {
9699 256 : $$ = $2;
9700 : }
9701 : | DEFAULT LABEL
9702 : {
9703 88 : $$ = NULL;
9704 : }
9705 : ;
9706 :
9707 : AlterPropGraphStmt:
9708 : ALTER PROPERTY GRAPH qualified_name ADD_P vertex_tables_clause
9709 : {
9710 28 : AlterPropGraphStmt *n = makeNode(AlterPropGraphStmt);
9711 :
9712 28 : n->pgname = $4;
9713 28 : n->add_vertex_tables = $6;
9714 :
9715 28 : $$ = (Node *) n;
9716 : }
9717 : | ALTER PROPERTY GRAPH qualified_name ADD_P vertex_tables_clause ADD_P edge_tables_clause
9718 : {
9719 4 : AlterPropGraphStmt *n = makeNode(AlterPropGraphStmt);
9720 :
9721 4 : n->pgname = $4;
9722 4 : n->add_vertex_tables = $6;
9723 4 : n->add_edge_tables = $8;
9724 :
9725 4 : $$ = (Node *) n;
9726 : }
9727 : | ALTER PROPERTY GRAPH qualified_name ADD_P edge_tables_clause
9728 : {
9729 24 : AlterPropGraphStmt *n = makeNode(AlterPropGraphStmt);
9730 :
9731 24 : n->pgname = $4;
9732 24 : n->add_edge_tables = $6;
9733 :
9734 24 : $$ = (Node *) n;
9735 : }
9736 : | ALTER PROPERTY GRAPH qualified_name DROP vertex_synonym TABLES '(' name_list ')' opt_drop_behavior
9737 : {
9738 8 : AlterPropGraphStmt *n = makeNode(AlterPropGraphStmt);
9739 :
9740 8 : n->pgname = $4;
9741 8 : n->drop_vertex_tables = $9;
9742 8 : n->drop_behavior = $11;
9743 :
9744 8 : $$ = (Node *) n;
9745 : }
9746 : | ALTER PROPERTY GRAPH qualified_name DROP edge_synonym TABLES '(' name_list ')' opt_drop_behavior
9747 : {
9748 8 : AlterPropGraphStmt *n = makeNode(AlterPropGraphStmt);
9749 :
9750 8 : n->pgname = $4;
9751 8 : n->drop_edge_tables = $9;
9752 8 : n->drop_behavior = $11;
9753 :
9754 8 : $$ = (Node *) n;
9755 : }
9756 : | ALTER PROPERTY GRAPH qualified_name ALTER vertex_or_edge TABLE name
9757 : add_label_list
9758 : {
9759 24 : AlterPropGraphStmt *n = makeNode(AlterPropGraphStmt);
9760 :
9761 24 : n->pgname = $4;
9762 24 : n->element_kind = $6;
9763 24 : n->element_alias = $8;
9764 24 : n->add_labels = $9;
9765 :
9766 24 : $$ = (Node *) n;
9767 : }
9768 : | ALTER PROPERTY GRAPH qualified_name ALTER vertex_or_edge TABLE name
9769 : DROP LABEL name opt_drop_behavior
9770 : {
9771 12 : AlterPropGraphStmt *n = makeNode(AlterPropGraphStmt);
9772 :
9773 12 : n->pgname = $4;
9774 12 : n->element_kind = $6;
9775 12 : n->element_alias = $8;
9776 12 : n->drop_label = $11;
9777 12 : n->drop_behavior = $12;
9778 :
9779 12 : $$ = (Node *) n;
9780 : }
9781 : | ALTER PROPERTY GRAPH qualified_name ALTER vertex_or_edge TABLE name
9782 : ALTER LABEL name ADD_P PROPERTIES '(' labeled_expr_list ')'
9783 : {
9784 8 : AlterPropGraphStmt *n = makeNode(AlterPropGraphStmt);
9785 8 : PropGraphProperties *pr = makeNode(PropGraphProperties);
9786 :
9787 8 : n->pgname = $4;
9788 8 : n->element_kind = $6;
9789 8 : n->element_alias = $8;
9790 8 : n->alter_label = $11;
9791 :
9792 8 : pr->properties = $15;
9793 8 : pr->location = @13;
9794 8 : n->add_properties = pr;
9795 :
9796 8 : $$ = (Node *) n;
9797 : }
9798 : | ALTER PROPERTY GRAPH qualified_name ALTER vertex_or_edge TABLE name
9799 : ALTER LABEL name DROP PROPERTIES '(' name_list ')' opt_drop_behavior
9800 : {
9801 8 : AlterPropGraphStmt *n = makeNode(AlterPropGraphStmt);
9802 :
9803 8 : n->pgname = $4;
9804 8 : n->element_kind = $6;
9805 8 : n->element_alias = $8;
9806 8 : n->alter_label = $11;
9807 8 : n->drop_properties = $15;
9808 8 : n->drop_behavior = $17;
9809 :
9810 8 : $$ = (Node *) n;
9811 : }
9812 : ;
9813 :
9814 : vertex_or_edge:
9815 44 : vertex_synonym { $$ = PROPGRAPH_ELEMENT_KIND_VERTEX; }
9816 8 : | edge_synonym { $$ = PROPGRAPH_ELEMENT_KIND_EDGE; }
9817 : ;
9818 :
9819 : add_label_list:
9820 24 : add_label { $$ = list_make1($1); }
9821 4 : | add_label_list add_label { $$ = lappend($1, $2); }
9822 : ;
9823 :
9824 : add_label: ADD_P LABEL name element_table_properties
9825 : {
9826 28 : PropGraphLabelAndProperties *lp = makeNode(PropGraphLabelAndProperties);
9827 :
9828 28 : lp->label = $3;
9829 28 : lp->properties = (PropGraphProperties *) $4;
9830 28 : lp->location = @1;
9831 :
9832 28 : $$ = (Node *) lp;
9833 : }
9834 : ;
9835 :
9836 :
9837 : /*****************************************************************************
9838 : *
9839 : * CREATE TRANSFORM / DROP TRANSFORM
9840 : *
9841 : *****************************************************************************/
9842 :
9843 : CreateTransformStmt: CREATE opt_or_replace TRANSFORM FOR Typename LANGUAGE name '(' transform_element_list ')'
9844 : {
9845 26 : CreateTransformStmt *n = makeNode(CreateTransformStmt);
9846 :
9847 26 : n->replace = $2;
9848 26 : n->type_name = $5;
9849 26 : n->lang = $7;
9850 26 : n->fromsql = linitial($9);
9851 26 : n->tosql = lsecond($9);
9852 26 : $$ = (Node *) n;
9853 : }
9854 : ;
9855 :
9856 : transform_element_list: FROM SQL_P WITH FUNCTION function_with_argtypes ',' TO SQL_P WITH FUNCTION function_with_argtypes
9857 : {
9858 23 : $$ = list_make2($5, $11);
9859 : }
9860 : | TO SQL_P WITH FUNCTION function_with_argtypes ',' FROM SQL_P WITH FUNCTION function_with_argtypes
9861 : {
9862 0 : $$ = list_make2($11, $5);
9863 : }
9864 : | FROM SQL_P WITH FUNCTION function_with_argtypes
9865 : {
9866 2 : $$ = list_make2($5, NULL);
9867 : }
9868 : | TO SQL_P WITH FUNCTION function_with_argtypes
9869 : {
9870 1 : $$ = list_make2(NULL, $5);
9871 : }
9872 : ;
9873 :
9874 :
9875 : DropTransformStmt: DROP TRANSFORM opt_if_exists FOR Typename LANGUAGE name opt_drop_behavior
9876 : {
9877 7 : DropStmt *n = makeNode(DropStmt);
9878 :
9879 7 : n->removeType = OBJECT_TRANSFORM;
9880 7 : n->objects = list_make1(list_make2($5, makeString($7)));
9881 7 : n->behavior = $8;
9882 7 : n->missing_ok = $3;
9883 7 : $$ = (Node *) n;
9884 : }
9885 : ;
9886 :
9887 :
9888 : /*****************************************************************************
9889 : *
9890 : * QUERY:
9891 : *
9892 : * REINDEX [ (options) ] {INDEX | TABLE | SCHEMA} [CONCURRENTLY] <name>
9893 : * REINDEX [ (options) ] {DATABASE | SYSTEM} [CONCURRENTLY] [<name>]
9894 : *****************************************************************************/
9895 :
9896 : ReindexStmt:
9897 : REINDEX opt_utility_option_list reindex_target_relation opt_concurrently qualified_name
9898 : {
9899 596 : ReindexStmt *n = makeNode(ReindexStmt);
9900 :
9901 596 : n->kind = $3;
9902 596 : n->relation = $5;
9903 596 : n->name = NULL;
9904 596 : n->params = $2;
9905 596 : if ($4)
9906 340 : n->params = lappend(n->params,
9907 340 : makeDefElem("concurrently", NULL, @4));
9908 596 : $$ = (Node *) n;
9909 : }
9910 : | REINDEX opt_utility_option_list SCHEMA opt_concurrently name
9911 : {
9912 74 : ReindexStmt *n = makeNode(ReindexStmt);
9913 :
9914 74 : n->kind = REINDEX_OBJECT_SCHEMA;
9915 74 : n->relation = NULL;
9916 74 : n->name = $5;
9917 74 : n->params = $2;
9918 74 : if ($4)
9919 26 : n->params = lappend(n->params,
9920 26 : makeDefElem("concurrently", NULL, @4));
9921 74 : $$ = (Node *) n;
9922 : }
9923 : | REINDEX opt_utility_option_list reindex_target_all opt_concurrently opt_single_name
9924 : {
9925 37 : ReindexStmt *n = makeNode(ReindexStmt);
9926 :
9927 37 : n->kind = $3;
9928 37 : n->relation = NULL;
9929 37 : n->name = $5;
9930 37 : n->params = $2;
9931 37 : if ($4)
9932 6 : n->params = lappend(n->params,
9933 6 : makeDefElem("concurrently", NULL, @4));
9934 37 : $$ = (Node *) n;
9935 : }
9936 : ;
9937 : reindex_target_relation:
9938 271 : INDEX { $$ = REINDEX_OBJECT_INDEX; }
9939 325 : | TABLE { $$ = REINDEX_OBJECT_TABLE; }
9940 : ;
9941 : reindex_target_all:
9942 20 : SYSTEM_P { $$ = REINDEX_OBJECT_SYSTEM; }
9943 17 : | DATABASE { $$ = REINDEX_OBJECT_DATABASE; }
9944 : ;
9945 :
9946 : /*****************************************************************************
9947 : *
9948 : * ALTER TABLESPACE
9949 : *
9950 : *****************************************************************************/
9951 :
9952 : AlterTblSpcStmt:
9953 : ALTER TABLESPACE name SET reloptions
9954 : {
9955 : AlterTableSpaceOptionsStmt *n =
9956 8 : makeNode(AlterTableSpaceOptionsStmt);
9957 :
9958 8 : n->tablespacename = $3;
9959 8 : n->options = $5;
9960 8 : n->isReset = false;
9961 8 : $$ = (Node *) n;
9962 : }
9963 : | ALTER TABLESPACE name RESET reloptions
9964 : {
9965 : AlterTableSpaceOptionsStmt *n =
9966 8 : makeNode(AlterTableSpaceOptionsStmt);
9967 :
9968 8 : n->tablespacename = $3;
9969 8 : n->options = $5;
9970 8 : n->isReset = true;
9971 8 : $$ = (Node *) n;
9972 : }
9973 : ;
9974 :
9975 : /*****************************************************************************
9976 : *
9977 : * ALTER THING name RENAME TO newname
9978 : *
9979 : *****************************************************************************/
9980 :
9981 : RenameStmt: ALTER AGGREGATE aggregate_with_argtypes RENAME TO name
9982 : {
9983 28 : RenameStmt *n = makeNode(RenameStmt);
9984 :
9985 28 : n->renameType = OBJECT_AGGREGATE;
9986 28 : n->object = (Node *) $3;
9987 28 : n->newname = $6;
9988 28 : n->missing_ok = false;
9989 28 : $$ = (Node *) n;
9990 : }
9991 : | ALTER COLLATION any_name RENAME TO name
9992 : {
9993 12 : RenameStmt *n = makeNode(RenameStmt);
9994 :
9995 12 : n->renameType = OBJECT_COLLATION;
9996 12 : n->object = (Node *) $3;
9997 12 : n->newname = $6;
9998 12 : n->missing_ok = false;
9999 12 : $$ = (Node *) n;
10000 : }
10001 : | ALTER CONVERSION_P any_name RENAME TO name
10002 : {
10003 16 : RenameStmt *n = makeNode(RenameStmt);
10004 :
10005 16 : n->renameType = OBJECT_CONVERSION;
10006 16 : n->object = (Node *) $3;
10007 16 : n->newname = $6;
10008 16 : n->missing_ok = false;
10009 16 : $$ = (Node *) n;
10010 : }
10011 : | ALTER DATABASE name RENAME TO name
10012 : {
10013 9 : RenameStmt *n = makeNode(RenameStmt);
10014 :
10015 9 : n->renameType = OBJECT_DATABASE;
10016 9 : n->subname = $3;
10017 9 : n->newname = $6;
10018 9 : n->missing_ok = false;
10019 9 : $$ = (Node *) n;
10020 : }
10021 : | ALTER DOMAIN_P any_name RENAME TO name
10022 : {
10023 4 : RenameStmt *n = makeNode(RenameStmt);
10024 :
10025 4 : n->renameType = OBJECT_DOMAIN;
10026 4 : n->object = (Node *) $3;
10027 4 : n->newname = $6;
10028 4 : n->missing_ok = false;
10029 4 : $$ = (Node *) n;
10030 : }
10031 : | ALTER DOMAIN_P any_name RENAME CONSTRAINT name TO name
10032 : {
10033 4 : RenameStmt *n = makeNode(RenameStmt);
10034 :
10035 4 : n->renameType = OBJECT_DOMCONSTRAINT;
10036 4 : n->object = (Node *) $3;
10037 4 : n->subname = $6;
10038 4 : n->newname = $8;
10039 4 : $$ = (Node *) n;
10040 : }
10041 : | ALTER FOREIGN DATA_P WRAPPER name RENAME TO name
10042 : {
10043 16 : RenameStmt *n = makeNode(RenameStmt);
10044 :
10045 16 : n->renameType = OBJECT_FDW;
10046 16 : n->object = (Node *) makeString($5);
10047 16 : n->newname = $8;
10048 16 : n->missing_ok = false;
10049 16 : $$ = (Node *) n;
10050 : }
10051 : | ALTER FUNCTION function_with_argtypes RENAME TO name
10052 : {
10053 16 : RenameStmt *n = makeNode(RenameStmt);
10054 :
10055 16 : n->renameType = OBJECT_FUNCTION;
10056 16 : n->object = (Node *) $3;
10057 16 : n->newname = $6;
10058 16 : n->missing_ok = false;
10059 16 : $$ = (Node *) n;
10060 : }
10061 : | ALTER GROUP_P RoleId RENAME TO RoleId
10062 : {
10063 0 : RenameStmt *n = makeNode(RenameStmt);
10064 :
10065 0 : n->renameType = OBJECT_ROLE;
10066 0 : n->subname = $3;
10067 0 : n->newname = $6;
10068 0 : n->missing_ok = false;
10069 0 : $$ = (Node *) n;
10070 : }
10071 : | ALTER opt_procedural LANGUAGE name RENAME TO name
10072 : {
10073 12 : RenameStmt *n = makeNode(RenameStmt);
10074 :
10075 12 : n->renameType = OBJECT_LANGUAGE;
10076 12 : n->object = (Node *) makeString($4);
10077 12 : n->newname = $7;
10078 12 : n->missing_ok = false;
10079 12 : $$ = (Node *) n;
10080 : }
10081 : | ALTER OPERATOR CLASS any_name USING name RENAME TO name
10082 : {
10083 16 : RenameStmt *n = makeNode(RenameStmt);
10084 :
10085 16 : n->renameType = OBJECT_OPCLASS;
10086 16 : n->object = (Node *) lcons(makeString($6), $4);
10087 16 : n->newname = $9;
10088 16 : n->missing_ok = false;
10089 16 : $$ = (Node *) n;
10090 : }
10091 : | ALTER OPERATOR FAMILY any_name USING name RENAME TO name
10092 : {
10093 16 : RenameStmt *n = makeNode(RenameStmt);
10094 :
10095 16 : n->renameType = OBJECT_OPFAMILY;
10096 16 : n->object = (Node *) lcons(makeString($6), $4);
10097 16 : n->newname = $9;
10098 16 : n->missing_ok = false;
10099 16 : $$ = (Node *) n;
10100 : }
10101 : | ALTER POLICY name ON qualified_name RENAME TO name
10102 : {
10103 12 : RenameStmt *n = makeNode(RenameStmt);
10104 :
10105 12 : n->renameType = OBJECT_POLICY;
10106 12 : n->relation = $5;
10107 12 : n->subname = $3;
10108 12 : n->newname = $8;
10109 12 : n->missing_ok = false;
10110 12 : $$ = (Node *) n;
10111 : }
10112 : | ALTER POLICY IF_P EXISTS name ON qualified_name RENAME TO name
10113 : {
10114 0 : RenameStmt *n = makeNode(RenameStmt);
10115 :
10116 0 : n->renameType = OBJECT_POLICY;
10117 0 : n->relation = $7;
10118 0 : n->subname = $5;
10119 0 : n->newname = $10;
10120 0 : n->missing_ok = true;
10121 0 : $$ = (Node *) n;
10122 : }
10123 : | ALTER PROCEDURE function_with_argtypes RENAME TO name
10124 : {
10125 0 : RenameStmt *n = makeNode(RenameStmt);
10126 :
10127 0 : n->renameType = OBJECT_PROCEDURE;
10128 0 : n->object = (Node *) $3;
10129 0 : n->newname = $6;
10130 0 : n->missing_ok = false;
10131 0 : $$ = (Node *) n;
10132 : }
10133 : | ALTER PROPERTY GRAPH qualified_name RENAME TO name
10134 : {
10135 24 : RenameStmt *n = makeNode(RenameStmt);
10136 :
10137 24 : n->renameType = OBJECT_PROPGRAPH;
10138 24 : n->relation = $4;
10139 24 : n->newname = $7;
10140 24 : n->missing_ok = false;
10141 24 : $$ = (Node *)n;
10142 : }
10143 : | ALTER PUBLICATION name RENAME TO name
10144 : {
10145 24 : RenameStmt *n = makeNode(RenameStmt);
10146 :
10147 24 : n->renameType = OBJECT_PUBLICATION;
10148 24 : n->object = (Node *) makeString($3);
10149 24 : n->newname = $6;
10150 24 : n->missing_ok = false;
10151 24 : $$ = (Node *) n;
10152 : }
10153 : | ALTER ROUTINE function_with_argtypes RENAME TO name
10154 : {
10155 16 : RenameStmt *n = makeNode(RenameStmt);
10156 :
10157 16 : n->renameType = OBJECT_ROUTINE;
10158 16 : n->object = (Node *) $3;
10159 16 : n->newname = $6;
10160 16 : n->missing_ok = false;
10161 16 : $$ = (Node *) n;
10162 : }
10163 : | ALTER SCHEMA name RENAME TO name
10164 : {
10165 13 : RenameStmt *n = makeNode(RenameStmt);
10166 :
10167 13 : n->renameType = OBJECT_SCHEMA;
10168 13 : n->subname = $3;
10169 13 : n->newname = $6;
10170 13 : n->missing_ok = false;
10171 13 : $$ = (Node *) n;
10172 : }
10173 : | ALTER SERVER name RENAME TO name
10174 : {
10175 16 : RenameStmt *n = makeNode(RenameStmt);
10176 :
10177 16 : n->renameType = OBJECT_FOREIGN_SERVER;
10178 16 : n->object = (Node *) makeString($3);
10179 16 : n->newname = $6;
10180 16 : n->missing_ok = false;
10181 16 : $$ = (Node *) n;
10182 : }
10183 : | ALTER SUBSCRIPTION name RENAME TO name
10184 : {
10185 25 : RenameStmt *n = makeNode(RenameStmt);
10186 :
10187 25 : n->renameType = OBJECT_SUBSCRIPTION;
10188 25 : n->object = (Node *) makeString($3);
10189 25 : n->newname = $6;
10190 25 : n->missing_ok = false;
10191 25 : $$ = (Node *) n;
10192 : }
10193 : | ALTER TABLE relation_expr RENAME TO name
10194 : {
10195 174 : RenameStmt *n = makeNode(RenameStmt);
10196 :
10197 174 : n->renameType = OBJECT_TABLE;
10198 174 : n->relation = $3;
10199 174 : n->subname = NULL;
10200 174 : n->newname = $6;
10201 174 : n->missing_ok = false;
10202 174 : $$ = (Node *) n;
10203 : }
10204 : | ALTER TABLE IF_P EXISTS relation_expr RENAME TO name
10205 : {
10206 0 : RenameStmt *n = makeNode(RenameStmt);
10207 :
10208 0 : n->renameType = OBJECT_TABLE;
10209 0 : n->relation = $5;
10210 0 : n->subname = NULL;
10211 0 : n->newname = $8;
10212 0 : n->missing_ok = true;
10213 0 : $$ = (Node *) n;
10214 : }
10215 : | ALTER SEQUENCE qualified_name RENAME TO name
10216 : {
10217 1 : RenameStmt *n = makeNode(RenameStmt);
10218 :
10219 1 : n->renameType = OBJECT_SEQUENCE;
10220 1 : n->relation = $3;
10221 1 : n->subname = NULL;
10222 1 : n->newname = $6;
10223 1 : n->missing_ok = false;
10224 1 : $$ = (Node *) n;
10225 : }
10226 : | ALTER SEQUENCE IF_P EXISTS qualified_name RENAME TO name
10227 : {
10228 0 : RenameStmt *n = makeNode(RenameStmt);
10229 :
10230 0 : n->renameType = OBJECT_SEQUENCE;
10231 0 : n->relation = $5;
10232 0 : n->subname = NULL;
10233 0 : n->newname = $8;
10234 0 : n->missing_ok = true;
10235 0 : $$ = (Node *) n;
10236 : }
10237 : | ALTER VIEW qualified_name RENAME TO name
10238 : {
10239 4 : RenameStmt *n = makeNode(RenameStmt);
10240 :
10241 4 : n->renameType = OBJECT_VIEW;
10242 4 : n->relation = $3;
10243 4 : n->subname = NULL;
10244 4 : n->newname = $6;
10245 4 : n->missing_ok = false;
10246 4 : $$ = (Node *) n;
10247 : }
10248 : | ALTER VIEW IF_P EXISTS qualified_name RENAME TO name
10249 : {
10250 0 : RenameStmt *n = makeNode(RenameStmt);
10251 :
10252 0 : n->renameType = OBJECT_VIEW;
10253 0 : n->relation = $5;
10254 0 : n->subname = NULL;
10255 0 : n->newname = $8;
10256 0 : n->missing_ok = true;
10257 0 : $$ = (Node *) n;
10258 : }
10259 : | ALTER MATERIALIZED VIEW qualified_name RENAME TO name
10260 : {
10261 0 : RenameStmt *n = makeNode(RenameStmt);
10262 :
10263 0 : n->renameType = OBJECT_MATVIEW;
10264 0 : n->relation = $4;
10265 0 : n->subname = NULL;
10266 0 : n->newname = $7;
10267 0 : n->missing_ok = false;
10268 0 : $$ = (Node *) n;
10269 : }
10270 : | ALTER MATERIALIZED VIEW IF_P EXISTS qualified_name RENAME TO name
10271 : {
10272 0 : RenameStmt *n = makeNode(RenameStmt);
10273 :
10274 0 : n->renameType = OBJECT_MATVIEW;
10275 0 : n->relation = $6;
10276 0 : n->subname = NULL;
10277 0 : n->newname = $9;
10278 0 : n->missing_ok = true;
10279 0 : $$ = (Node *) n;
10280 : }
10281 : | ALTER INDEX qualified_name RENAME TO name
10282 : {
10283 108 : RenameStmt *n = makeNode(RenameStmt);
10284 :
10285 108 : n->renameType = OBJECT_INDEX;
10286 108 : n->relation = $3;
10287 108 : n->subname = NULL;
10288 108 : n->newname = $6;
10289 108 : n->missing_ok = false;
10290 108 : $$ = (Node *) n;
10291 : }
10292 : | ALTER INDEX IF_P EXISTS qualified_name RENAME TO name
10293 : {
10294 8 : RenameStmt *n = makeNode(RenameStmt);
10295 :
10296 8 : n->renameType = OBJECT_INDEX;
10297 8 : n->relation = $5;
10298 8 : n->subname = NULL;
10299 8 : n->newname = $8;
10300 8 : n->missing_ok = true;
10301 8 : $$ = (Node *) n;
10302 : }
10303 : | ALTER FOREIGN TABLE relation_expr RENAME TO name
10304 : {
10305 4 : RenameStmt *n = makeNode(RenameStmt);
10306 :
10307 4 : n->renameType = OBJECT_FOREIGN_TABLE;
10308 4 : n->relation = $4;
10309 4 : n->subname = NULL;
10310 4 : n->newname = $7;
10311 4 : n->missing_ok = false;
10312 4 : $$ = (Node *) n;
10313 : }
10314 : | ALTER FOREIGN TABLE IF_P EXISTS relation_expr RENAME TO name
10315 : {
10316 4 : RenameStmt *n = makeNode(RenameStmt);
10317 :
10318 4 : n->renameType = OBJECT_FOREIGN_TABLE;
10319 4 : n->relation = $6;
10320 4 : n->subname = NULL;
10321 4 : n->newname = $9;
10322 4 : n->missing_ok = true;
10323 4 : $$ = (Node *) n;
10324 : }
10325 : | ALTER TABLE relation_expr RENAME opt_column name TO name
10326 : {
10327 157 : RenameStmt *n = makeNode(RenameStmt);
10328 :
10329 157 : n->renameType = OBJECT_COLUMN;
10330 157 : n->relationType = OBJECT_TABLE;
10331 157 : n->relation = $3;
10332 157 : n->subname = $6;
10333 157 : n->newname = $8;
10334 157 : n->missing_ok = false;
10335 157 : $$ = (Node *) n;
10336 : }
10337 : | ALTER TABLE IF_P EXISTS relation_expr RENAME opt_column name TO name
10338 : {
10339 16 : RenameStmt *n = makeNode(RenameStmt);
10340 :
10341 16 : n->renameType = OBJECT_COLUMN;
10342 16 : n->relationType = OBJECT_TABLE;
10343 16 : n->relation = $5;
10344 16 : n->subname = $8;
10345 16 : n->newname = $10;
10346 16 : n->missing_ok = true;
10347 16 : $$ = (Node *) n;
10348 : }
10349 : | ALTER VIEW qualified_name RENAME opt_column name TO name
10350 : {
10351 12 : RenameStmt *n = makeNode(RenameStmt);
10352 :
10353 12 : n->renameType = OBJECT_COLUMN;
10354 12 : n->relationType = OBJECT_VIEW;
10355 12 : n->relation = $3;
10356 12 : n->subname = $6;
10357 12 : n->newname = $8;
10358 12 : n->missing_ok = false;
10359 12 : $$ = (Node *) n;
10360 : }
10361 : | ALTER VIEW IF_P EXISTS qualified_name RENAME opt_column name TO name
10362 : {
10363 0 : RenameStmt *n = makeNode(RenameStmt);
10364 :
10365 0 : n->renameType = OBJECT_COLUMN;
10366 0 : n->relationType = OBJECT_VIEW;
10367 0 : n->relation = $5;
10368 0 : n->subname = $8;
10369 0 : n->newname = $10;
10370 0 : n->missing_ok = true;
10371 0 : $$ = (Node *) n;
10372 : }
10373 : | ALTER MATERIALIZED VIEW qualified_name RENAME opt_column name TO name
10374 : {
10375 0 : RenameStmt *n = makeNode(RenameStmt);
10376 :
10377 0 : n->renameType = OBJECT_COLUMN;
10378 0 : n->relationType = OBJECT_MATVIEW;
10379 0 : n->relation = $4;
10380 0 : n->subname = $7;
10381 0 : n->newname = $9;
10382 0 : n->missing_ok = false;
10383 0 : $$ = (Node *) n;
10384 : }
10385 : | ALTER MATERIALIZED VIEW IF_P EXISTS qualified_name RENAME opt_column name TO name
10386 : {
10387 0 : RenameStmt *n = makeNode(RenameStmt);
10388 :
10389 0 : n->renameType = OBJECT_COLUMN;
10390 0 : n->relationType = OBJECT_MATVIEW;
10391 0 : n->relation = $6;
10392 0 : n->subname = $9;
10393 0 : n->newname = $11;
10394 0 : n->missing_ok = true;
10395 0 : $$ = (Node *) n;
10396 : }
10397 : | ALTER TABLE relation_expr RENAME CONSTRAINT name TO name
10398 : {
10399 48 : RenameStmt *n = makeNode(RenameStmt);
10400 :
10401 48 : n->renameType = OBJECT_TABCONSTRAINT;
10402 48 : n->relation = $3;
10403 48 : n->subname = $6;
10404 48 : n->newname = $8;
10405 48 : n->missing_ok = false;
10406 48 : $$ = (Node *) n;
10407 : }
10408 : | ALTER TABLE IF_P EXISTS relation_expr RENAME CONSTRAINT name TO name
10409 : {
10410 4 : RenameStmt *n = makeNode(RenameStmt);
10411 :
10412 4 : n->renameType = OBJECT_TABCONSTRAINT;
10413 4 : n->relation = $5;
10414 4 : n->subname = $8;
10415 4 : n->newname = $10;
10416 4 : n->missing_ok = true;
10417 4 : $$ = (Node *) n;
10418 : }
10419 : | ALTER FOREIGN TABLE relation_expr RENAME opt_column name TO name
10420 : {
10421 4 : RenameStmt *n = makeNode(RenameStmt);
10422 :
10423 4 : n->renameType = OBJECT_COLUMN;
10424 4 : n->relationType = OBJECT_FOREIGN_TABLE;
10425 4 : n->relation = $4;
10426 4 : n->subname = $7;
10427 4 : n->newname = $9;
10428 4 : n->missing_ok = false;
10429 4 : $$ = (Node *) n;
10430 : }
10431 : | ALTER FOREIGN TABLE IF_P EXISTS relation_expr RENAME opt_column name TO name
10432 : {
10433 4 : RenameStmt *n = makeNode(RenameStmt);
10434 :
10435 4 : n->renameType = OBJECT_COLUMN;
10436 4 : n->relationType = OBJECT_FOREIGN_TABLE;
10437 4 : n->relation = $6;
10438 4 : n->subname = $9;
10439 4 : n->newname = $11;
10440 4 : n->missing_ok = true;
10441 4 : $$ = (Node *) n;
10442 : }
10443 : | ALTER RULE name ON qualified_name RENAME TO name
10444 : {
10445 22 : RenameStmt *n = makeNode(RenameStmt);
10446 :
10447 22 : n->renameType = OBJECT_RULE;
10448 22 : n->relation = $5;
10449 22 : n->subname = $3;
10450 22 : n->newname = $8;
10451 22 : n->missing_ok = false;
10452 22 : $$ = (Node *) n;
10453 : }
10454 : | ALTER TRIGGER name ON qualified_name RENAME TO name
10455 : {
10456 26 : RenameStmt *n = makeNode(RenameStmt);
10457 :
10458 26 : n->renameType = OBJECT_TRIGGER;
10459 26 : n->relation = $5;
10460 26 : n->subname = $3;
10461 26 : n->newname = $8;
10462 26 : n->missing_ok = false;
10463 26 : $$ = (Node *) n;
10464 : }
10465 : | ALTER EVENT TRIGGER name RENAME TO name
10466 : {
10467 8 : RenameStmt *n = makeNode(RenameStmt);
10468 :
10469 8 : n->renameType = OBJECT_EVENT_TRIGGER;
10470 8 : n->object = (Node *) makeString($4);
10471 8 : n->newname = $7;
10472 8 : $$ = (Node *) n;
10473 : }
10474 : | ALTER ROLE RoleId RENAME TO RoleId
10475 : {
10476 20 : RenameStmt *n = makeNode(RenameStmt);
10477 :
10478 20 : n->renameType = OBJECT_ROLE;
10479 20 : n->subname = $3;
10480 20 : n->newname = $6;
10481 20 : n->missing_ok = false;
10482 20 : $$ = (Node *) n;
10483 : }
10484 : | ALTER USER RoleId RENAME TO RoleId
10485 : {
10486 0 : RenameStmt *n = makeNode(RenameStmt);
10487 :
10488 0 : n->renameType = OBJECT_ROLE;
10489 0 : n->subname = $3;
10490 0 : n->newname = $6;
10491 0 : n->missing_ok = false;
10492 0 : $$ = (Node *) n;
10493 : }
10494 : | ALTER TABLESPACE name RENAME TO name
10495 : {
10496 6 : RenameStmt *n = makeNode(RenameStmt);
10497 :
10498 6 : n->renameType = OBJECT_TABLESPACE;
10499 6 : n->subname = $3;
10500 6 : n->newname = $6;
10501 6 : n->missing_ok = false;
10502 6 : $$ = (Node *) n;
10503 : }
10504 : | ALTER STATISTICS any_name RENAME TO name
10505 : {
10506 20 : RenameStmt *n = makeNode(RenameStmt);
10507 :
10508 20 : n->renameType = OBJECT_STATISTIC_EXT;
10509 20 : n->object = (Node *) $3;
10510 20 : n->newname = $6;
10511 20 : n->missing_ok = false;
10512 20 : $$ = (Node *) n;
10513 : }
10514 : | ALTER TEXT_P SEARCH PARSER any_name RENAME TO name
10515 : {
10516 8 : RenameStmt *n = makeNode(RenameStmt);
10517 :
10518 8 : n->renameType = OBJECT_TSPARSER;
10519 8 : n->object = (Node *) $5;
10520 8 : n->newname = $8;
10521 8 : n->missing_ok = false;
10522 8 : $$ = (Node *) n;
10523 : }
10524 : | ALTER TEXT_P SEARCH DICTIONARY any_name RENAME TO name
10525 : {
10526 16 : RenameStmt *n = makeNode(RenameStmt);
10527 :
10528 16 : n->renameType = OBJECT_TSDICTIONARY;
10529 16 : n->object = (Node *) $5;
10530 16 : n->newname = $8;
10531 16 : n->missing_ok = false;
10532 16 : $$ = (Node *) n;
10533 : }
10534 : | ALTER TEXT_P SEARCH TEMPLATE any_name RENAME TO name
10535 : {
10536 8 : RenameStmt *n = makeNode(RenameStmt);
10537 :
10538 8 : n->renameType = OBJECT_TSTEMPLATE;
10539 8 : n->object = (Node *) $5;
10540 8 : n->newname = $8;
10541 8 : n->missing_ok = false;
10542 8 : $$ = (Node *) n;
10543 : }
10544 : | ALTER TEXT_P SEARCH CONFIGURATION any_name RENAME TO name
10545 : {
10546 16 : RenameStmt *n = makeNode(RenameStmt);
10547 :
10548 16 : n->renameType = OBJECT_TSCONFIGURATION;
10549 16 : n->object = (Node *) $5;
10550 16 : n->newname = $8;
10551 16 : n->missing_ok = false;
10552 16 : $$ = (Node *) n;
10553 : }
10554 : | ALTER TYPE_P any_name RENAME TO name
10555 : {
10556 17 : RenameStmt *n = makeNode(RenameStmt);
10557 :
10558 17 : n->renameType = OBJECT_TYPE;
10559 17 : n->object = (Node *) $3;
10560 17 : n->newname = $6;
10561 17 : n->missing_ok = false;
10562 17 : $$ = (Node *) n;
10563 : }
10564 : | ALTER TYPE_P any_name RENAME ATTRIBUTE name TO name opt_drop_behavior
10565 : {
10566 16 : RenameStmt *n = makeNode(RenameStmt);
10567 :
10568 16 : n->renameType = OBJECT_ATTRIBUTE;
10569 16 : n->relationType = OBJECT_TYPE;
10570 16 : n->relation = makeRangeVarFromAnyName($3, @3, yyscanner);
10571 16 : n->subname = $6;
10572 16 : n->newname = $8;
10573 16 : n->behavior = $9;
10574 16 : n->missing_ok = false;
10575 16 : $$ = (Node *) n;
10576 : }
10577 : ;
10578 :
10579 : opt_column: COLUMN
10580 : | /*EMPTY*/
10581 : ;
10582 :
10583 122 : opt_set_data: SET DATA_P { $$ = 1; }
10584 672 : | /*EMPTY*/ { $$ = 0; }
10585 : ;
10586 :
10587 : /*****************************************************************************
10588 : *
10589 : * ALTER THING name DEPENDS ON EXTENSION name
10590 : *
10591 : *****************************************************************************/
10592 :
10593 : AlterObjectDependsStmt:
10594 : ALTER FUNCTION function_with_argtypes opt_no DEPENDS ON EXTENSION name
10595 : {
10596 6 : AlterObjectDependsStmt *n = makeNode(AlterObjectDependsStmt);
10597 :
10598 6 : n->objectType = OBJECT_FUNCTION;
10599 6 : n->object = (Node *) $3;
10600 6 : n->extname = makeString($8);
10601 6 : n->remove = $4;
10602 6 : $$ = (Node *) n;
10603 : }
10604 : | ALTER PROCEDURE function_with_argtypes opt_no DEPENDS ON EXTENSION name
10605 : {
10606 0 : AlterObjectDependsStmt *n = makeNode(AlterObjectDependsStmt);
10607 :
10608 0 : n->objectType = OBJECT_PROCEDURE;
10609 0 : n->object = (Node *) $3;
10610 0 : n->extname = makeString($8);
10611 0 : n->remove = $4;
10612 0 : $$ = (Node *) n;
10613 : }
10614 : | ALTER ROUTINE function_with_argtypes opt_no DEPENDS ON EXTENSION name
10615 : {
10616 0 : AlterObjectDependsStmt *n = makeNode(AlterObjectDependsStmt);
10617 :
10618 0 : n->objectType = OBJECT_ROUTINE;
10619 0 : n->object = (Node *) $3;
10620 0 : n->extname = makeString($8);
10621 0 : n->remove = $4;
10622 0 : $$ = (Node *) n;
10623 : }
10624 : | ALTER TRIGGER name ON qualified_name opt_no DEPENDS ON EXTENSION name
10625 : {
10626 5 : AlterObjectDependsStmt *n = makeNode(AlterObjectDependsStmt);
10627 :
10628 5 : n->objectType = OBJECT_TRIGGER;
10629 5 : n->relation = $5;
10630 5 : n->object = (Node *) list_make1(makeString($3));
10631 5 : n->extname = makeString($10);
10632 5 : n->remove = $6;
10633 5 : $$ = (Node *) n;
10634 : }
10635 : | ALTER MATERIALIZED VIEW qualified_name opt_no DEPENDS ON EXTENSION name
10636 : {
10637 5 : AlterObjectDependsStmt *n = makeNode(AlterObjectDependsStmt);
10638 :
10639 5 : n->objectType = OBJECT_MATVIEW;
10640 5 : n->relation = $4;
10641 5 : n->extname = makeString($9);
10642 5 : n->remove = $5;
10643 5 : $$ = (Node *) n;
10644 : }
10645 : | ALTER INDEX qualified_name opt_no DEPENDS ON EXTENSION name
10646 : {
10647 7 : AlterObjectDependsStmt *n = makeNode(AlterObjectDependsStmt);
10648 :
10649 7 : n->objectType = OBJECT_INDEX;
10650 7 : n->relation = $3;
10651 7 : n->extname = makeString($8);
10652 7 : n->remove = $4;
10653 7 : $$ = (Node *) n;
10654 : }
10655 : ;
10656 :
10657 4 : opt_no: NO { $$ = true; }
10658 19 : | /* EMPTY */ { $$ = false; }
10659 : ;
10660 :
10661 : /*****************************************************************************
10662 : *
10663 : * ALTER THING name SET SCHEMA name
10664 : *
10665 : *****************************************************************************/
10666 :
10667 : AlterObjectSchemaStmt:
10668 : ALTER AGGREGATE aggregate_with_argtypes SET SCHEMA name
10669 : {
10670 16 : AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
10671 :
10672 16 : n->objectType = OBJECT_AGGREGATE;
10673 16 : n->object = (Node *) $3;
10674 16 : n->newschema = $6;
10675 16 : n->missing_ok = false;
10676 16 : $$ = (Node *) n;
10677 : }
10678 : | ALTER COLLATION any_name SET SCHEMA name
10679 : {
10680 4 : AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
10681 :
10682 4 : n->objectType = OBJECT_COLLATION;
10683 4 : n->object = (Node *) $3;
10684 4 : n->newschema = $6;
10685 4 : n->missing_ok = false;
10686 4 : $$ = (Node *) n;
10687 : }
10688 : | ALTER CONVERSION_P any_name SET SCHEMA name
10689 : {
10690 16 : AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
10691 :
10692 16 : n->objectType = OBJECT_CONVERSION;
10693 16 : n->object = (Node *) $3;
10694 16 : n->newschema = $6;
10695 16 : n->missing_ok = false;
10696 16 : $$ = (Node *) n;
10697 : }
10698 : | ALTER DOMAIN_P any_name SET SCHEMA name
10699 : {
10700 4 : AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
10701 :
10702 4 : n->objectType = OBJECT_DOMAIN;
10703 4 : n->object = (Node *) $3;
10704 4 : n->newschema = $6;
10705 4 : n->missing_ok = false;
10706 4 : $$ = (Node *) n;
10707 : }
10708 : | ALTER EXTENSION name SET SCHEMA name
10709 : {
10710 6 : AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
10711 :
10712 6 : n->objectType = OBJECT_EXTENSION;
10713 6 : n->object = (Node *) makeString($3);
10714 6 : n->newschema = $6;
10715 6 : n->missing_ok = false;
10716 6 : $$ = (Node *) n;
10717 : }
10718 : | ALTER FUNCTION function_with_argtypes SET SCHEMA name
10719 : {
10720 27 : AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
10721 :
10722 27 : n->objectType = OBJECT_FUNCTION;
10723 27 : n->object = (Node *) $3;
10724 27 : n->newschema = $6;
10725 27 : n->missing_ok = false;
10726 27 : $$ = (Node *) n;
10727 : }
10728 : | ALTER OPERATOR operator_with_argtypes SET SCHEMA name
10729 : {
10730 12 : AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
10731 :
10732 12 : n->objectType = OBJECT_OPERATOR;
10733 12 : n->object = (Node *) $3;
10734 12 : n->newschema = $6;
10735 12 : n->missing_ok = false;
10736 12 : $$ = (Node *) n;
10737 : }
10738 : | ALTER OPERATOR CLASS any_name USING name SET SCHEMA name
10739 : {
10740 16 : AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
10741 :
10742 16 : n->objectType = OBJECT_OPCLASS;
10743 16 : n->object = (Node *) lcons(makeString($6), $4);
10744 16 : n->newschema = $9;
10745 16 : n->missing_ok = false;
10746 16 : $$ = (Node *) n;
10747 : }
10748 : | ALTER OPERATOR FAMILY any_name USING name SET SCHEMA name
10749 : {
10750 16 : AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
10751 :
10752 16 : n->objectType = OBJECT_OPFAMILY;
10753 16 : n->object = (Node *) lcons(makeString($6), $4);
10754 16 : n->newschema = $9;
10755 16 : n->missing_ok = false;
10756 16 : $$ = (Node *) n;
10757 : }
10758 : | ALTER PROCEDURE function_with_argtypes SET SCHEMA name
10759 : {
10760 0 : AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
10761 :
10762 0 : n->objectType = OBJECT_PROCEDURE;
10763 0 : n->object = (Node *) $3;
10764 0 : n->newschema = $6;
10765 0 : n->missing_ok = false;
10766 0 : $$ = (Node *) n;
10767 : }
10768 : | ALTER PROPERTY GRAPH qualified_name SET SCHEMA name
10769 : {
10770 16 : AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
10771 :
10772 16 : n->objectType = OBJECT_PROPGRAPH;
10773 16 : n->relation = $4;
10774 16 : n->newschema = $7;
10775 16 : n->missing_ok = false;
10776 16 : $$ = (Node *)n;
10777 : }
10778 : | ALTER PROPERTY GRAPH IF_P EXISTS qualified_name SET SCHEMA name
10779 : {
10780 4 : AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
10781 :
10782 4 : n->objectType = OBJECT_PROPGRAPH;
10783 4 : n->relation = $6;
10784 4 : n->newschema = $9;
10785 4 : n->missing_ok = true;
10786 4 : $$ = (Node *)n;
10787 : }
10788 : | ALTER ROUTINE function_with_argtypes SET SCHEMA name
10789 : {
10790 0 : AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
10791 :
10792 0 : n->objectType = OBJECT_ROUTINE;
10793 0 : n->object = (Node *) $3;
10794 0 : n->newschema = $6;
10795 0 : n->missing_ok = false;
10796 0 : $$ = (Node *) n;
10797 : }
10798 : | ALTER TABLE relation_expr SET SCHEMA name
10799 : {
10800 43 : AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
10801 :
10802 43 : n->objectType = OBJECT_TABLE;
10803 43 : n->relation = $3;
10804 43 : n->newschema = $6;
10805 43 : n->missing_ok = false;
10806 43 : $$ = (Node *) n;
10807 : }
10808 : | ALTER TABLE IF_P EXISTS relation_expr SET SCHEMA name
10809 : {
10810 8 : AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
10811 :
10812 8 : n->objectType = OBJECT_TABLE;
10813 8 : n->relation = $5;
10814 8 : n->newschema = $8;
10815 8 : n->missing_ok = true;
10816 8 : $$ = (Node *) n;
10817 : }
10818 : | ALTER STATISTICS any_name SET SCHEMA name
10819 : {
10820 12 : AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
10821 :
10822 12 : n->objectType = OBJECT_STATISTIC_EXT;
10823 12 : n->object = (Node *) $3;
10824 12 : n->newschema = $6;
10825 12 : n->missing_ok = false;
10826 12 : $$ = (Node *) n;
10827 : }
10828 : | ALTER TEXT_P SEARCH PARSER any_name SET SCHEMA name
10829 : {
10830 12 : AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
10831 :
10832 12 : n->objectType = OBJECT_TSPARSER;
10833 12 : n->object = (Node *) $5;
10834 12 : n->newschema = $8;
10835 12 : n->missing_ok = false;
10836 12 : $$ = (Node *) n;
10837 : }
10838 : | ALTER TEXT_P SEARCH DICTIONARY any_name SET SCHEMA name
10839 : {
10840 16 : AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
10841 :
10842 16 : n->objectType = OBJECT_TSDICTIONARY;
10843 16 : n->object = (Node *) $5;
10844 16 : n->newschema = $8;
10845 16 : n->missing_ok = false;
10846 16 : $$ = (Node *) n;
10847 : }
10848 : | ALTER TEXT_P SEARCH TEMPLATE any_name SET SCHEMA name
10849 : {
10850 12 : AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
10851 :
10852 12 : n->objectType = OBJECT_TSTEMPLATE;
10853 12 : n->object = (Node *) $5;
10854 12 : n->newschema = $8;
10855 12 : n->missing_ok = false;
10856 12 : $$ = (Node *) n;
10857 : }
10858 : | ALTER TEXT_P SEARCH CONFIGURATION any_name SET SCHEMA name
10859 : {
10860 16 : AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
10861 :
10862 16 : n->objectType = OBJECT_TSCONFIGURATION;
10863 16 : n->object = (Node *) $5;
10864 16 : n->newschema = $8;
10865 16 : n->missing_ok = false;
10866 16 : $$ = (Node *) n;
10867 : }
10868 : | ALTER SEQUENCE qualified_name SET SCHEMA name
10869 : {
10870 5 : AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
10871 :
10872 5 : n->objectType = OBJECT_SEQUENCE;
10873 5 : n->relation = $3;
10874 5 : n->newschema = $6;
10875 5 : n->missing_ok = false;
10876 5 : $$ = (Node *) n;
10877 : }
10878 : | ALTER SEQUENCE IF_P EXISTS qualified_name SET SCHEMA name
10879 : {
10880 0 : AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
10881 :
10882 0 : n->objectType = OBJECT_SEQUENCE;
10883 0 : n->relation = $5;
10884 0 : n->newschema = $8;
10885 0 : n->missing_ok = true;
10886 0 : $$ = (Node *) n;
10887 : }
10888 : | ALTER VIEW qualified_name SET SCHEMA name
10889 : {
10890 0 : AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
10891 :
10892 0 : n->objectType = OBJECT_VIEW;
10893 0 : n->relation = $3;
10894 0 : n->newschema = $6;
10895 0 : n->missing_ok = false;
10896 0 : $$ = (Node *) n;
10897 : }
10898 : | ALTER VIEW IF_P EXISTS qualified_name SET SCHEMA name
10899 : {
10900 0 : AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
10901 :
10902 0 : n->objectType = OBJECT_VIEW;
10903 0 : n->relation = $5;
10904 0 : n->newschema = $8;
10905 0 : n->missing_ok = true;
10906 0 : $$ = (Node *) n;
10907 : }
10908 : | ALTER MATERIALIZED VIEW qualified_name SET SCHEMA name
10909 : {
10910 4 : AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
10911 :
10912 4 : n->objectType = OBJECT_MATVIEW;
10913 4 : n->relation = $4;
10914 4 : n->newschema = $7;
10915 4 : n->missing_ok = false;
10916 4 : $$ = (Node *) n;
10917 : }
10918 : | ALTER MATERIALIZED VIEW IF_P EXISTS qualified_name SET SCHEMA name
10919 : {
10920 0 : AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
10921 :
10922 0 : n->objectType = OBJECT_MATVIEW;
10923 0 : n->relation = $6;
10924 0 : n->newschema = $9;
10925 0 : n->missing_ok = true;
10926 0 : $$ = (Node *) n;
10927 : }
10928 : | ALTER FOREIGN TABLE relation_expr SET SCHEMA name
10929 : {
10930 4 : AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
10931 :
10932 4 : n->objectType = OBJECT_FOREIGN_TABLE;
10933 4 : n->relation = $4;
10934 4 : n->newschema = $7;
10935 4 : n->missing_ok = false;
10936 4 : $$ = (Node *) n;
10937 : }
10938 : | ALTER FOREIGN TABLE IF_P EXISTS relation_expr SET SCHEMA name
10939 : {
10940 4 : AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
10941 :
10942 4 : n->objectType = OBJECT_FOREIGN_TABLE;
10943 4 : n->relation = $6;
10944 4 : n->newschema = $9;
10945 4 : n->missing_ok = true;
10946 4 : $$ = (Node *) n;
10947 : }
10948 : | ALTER TYPE_P any_name SET SCHEMA name
10949 : {
10950 8 : AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
10951 :
10952 8 : n->objectType = OBJECT_TYPE;
10953 8 : n->object = (Node *) $3;
10954 8 : n->newschema = $6;
10955 8 : n->missing_ok = false;
10956 8 : $$ = (Node *) n;
10957 : }
10958 : ;
10959 :
10960 : /*****************************************************************************
10961 : *
10962 : * ALTER OPERATOR name SET define
10963 : *
10964 : *****************************************************************************/
10965 :
10966 : AlterOperatorStmt:
10967 : ALTER OPERATOR operator_with_argtypes SET '(' operator_def_list ')'
10968 : {
10969 332 : AlterOperatorStmt *n = makeNode(AlterOperatorStmt);
10970 :
10971 332 : n->opername = $3;
10972 332 : n->options = $6;
10973 332 : $$ = (Node *) n;
10974 : }
10975 : ;
10976 :
10977 368 : operator_def_list: operator_def_elem { $$ = list_make1($1); }
10978 261 : | operator_def_list ',' operator_def_elem { $$ = lappend($1, $3); }
10979 : ;
10980 :
10981 : operator_def_elem: ColLabel '=' NONE
10982 20 : { $$ = makeDefElem($1, NULL, @1); }
10983 : | ColLabel '=' operator_def_arg
10984 587 : { $$ = makeDefElem($1, (Node *) $3, @1); }
10985 : | ColLabel
10986 22 : { $$ = makeDefElem($1, NULL, @1); }
10987 : ;
10988 :
10989 : /* must be similar enough to def_arg to avoid reduce/reduce conflicts */
10990 : operator_def_arg:
10991 535 : func_type { $$ = (Node *) $1; }
10992 16 : | reserved_keyword { $$ = (Node *) makeString(pstrdup($1)); }
10993 36 : | qual_all_Op { $$ = (Node *) $1; }
10994 0 : | NumericOnly { $$ = (Node *) $1; }
10995 0 : | Sconst { $$ = (Node *) makeString($1); }
10996 : ;
10997 :
10998 : /*****************************************************************************
10999 : *
11000 : * ALTER TYPE name SET define
11001 : *
11002 : * We repurpose ALTER OPERATOR's version of "definition" here
11003 : *
11004 : *****************************************************************************/
11005 :
11006 : AlterTypeStmt:
11007 : ALTER TYPE_P any_name SET '(' operator_def_list ')'
11008 : {
11009 36 : AlterTypeStmt *n = makeNode(AlterTypeStmt);
11010 :
11011 36 : n->typeName = $3;
11012 36 : n->options = $6;
11013 36 : $$ = (Node *) n;
11014 : }
11015 : ;
11016 :
11017 : /*****************************************************************************
11018 : *
11019 : * ALTER THING name OWNER TO newname
11020 : *
11021 : *****************************************************************************/
11022 :
11023 : AlterOwnerStmt: ALTER AGGREGATE aggregate_with_argtypes OWNER TO RoleSpec
11024 : {
11025 76 : AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
11026 :
11027 76 : n->objectType = OBJECT_AGGREGATE;
11028 76 : n->object = (Node *) $3;
11029 76 : n->newowner = $6;
11030 76 : $$ = (Node *) n;
11031 : }
11032 : | ALTER COLLATION any_name OWNER TO RoleSpec
11033 : {
11034 11 : AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
11035 :
11036 11 : n->objectType = OBJECT_COLLATION;
11037 11 : n->object = (Node *) $3;
11038 11 : n->newowner = $6;
11039 11 : $$ = (Node *) n;
11040 : }
11041 : | ALTER CONVERSION_P any_name OWNER TO RoleSpec
11042 : {
11043 16 : AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
11044 :
11045 16 : n->objectType = OBJECT_CONVERSION;
11046 16 : n->object = (Node *) $3;
11047 16 : n->newowner = $6;
11048 16 : $$ = (Node *) n;
11049 : }
11050 : | ALTER DATABASE name OWNER TO RoleSpec
11051 : {
11052 49 : AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
11053 :
11054 49 : n->objectType = OBJECT_DATABASE;
11055 49 : n->object = (Node *) makeString($3);
11056 49 : n->newowner = $6;
11057 49 : $$ = (Node *) n;
11058 : }
11059 : | ALTER DOMAIN_P any_name OWNER TO RoleSpec
11060 : {
11061 24 : AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
11062 :
11063 24 : n->objectType = OBJECT_DOMAIN;
11064 24 : n->object = (Node *) $3;
11065 24 : n->newowner = $6;
11066 24 : $$ = (Node *) n;
11067 : }
11068 : | ALTER FUNCTION function_with_argtypes OWNER TO RoleSpec
11069 : {
11070 313 : AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
11071 :
11072 313 : n->objectType = OBJECT_FUNCTION;
11073 313 : n->object = (Node *) $3;
11074 313 : n->newowner = $6;
11075 313 : $$ = (Node *) n;
11076 : }
11077 : | ALTER opt_procedural LANGUAGE name OWNER TO RoleSpec
11078 : {
11079 77 : AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
11080 :
11081 77 : n->objectType = OBJECT_LANGUAGE;
11082 77 : n->object = (Node *) makeString($4);
11083 77 : n->newowner = $7;
11084 77 : $$ = (Node *) n;
11085 : }
11086 : | ALTER LARGE_P OBJECT_P NumericOnly OWNER TO RoleSpec
11087 : {
11088 9 : AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
11089 :
11090 9 : n->objectType = OBJECT_LARGEOBJECT;
11091 9 : n->object = (Node *) $4;
11092 9 : n->newowner = $7;
11093 9 : $$ = (Node *) n;
11094 : }
11095 : | ALTER OPERATOR operator_with_argtypes OWNER TO RoleSpec
11096 : {
11097 27 : AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
11098 :
11099 27 : n->objectType = OBJECT_OPERATOR;
11100 27 : n->object = (Node *) $3;
11101 27 : n->newowner = $6;
11102 27 : $$ = (Node *) n;
11103 : }
11104 : | ALTER OPERATOR CLASS any_name USING name OWNER TO RoleSpec
11105 : {
11106 35 : AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
11107 :
11108 35 : n->objectType = OBJECT_OPCLASS;
11109 35 : n->object = (Node *) lcons(makeString($6), $4);
11110 35 : n->newowner = $9;
11111 35 : $$ = (Node *) n;
11112 : }
11113 : | ALTER OPERATOR FAMILY any_name USING name OWNER TO RoleSpec
11114 : {
11115 39 : AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
11116 :
11117 39 : n->objectType = OBJECT_OPFAMILY;
11118 39 : n->object = (Node *) lcons(makeString($6), $4);
11119 39 : n->newowner = $9;
11120 39 : $$ = (Node *) n;
11121 : }
11122 : | ALTER PROCEDURE function_with_argtypes OWNER TO RoleSpec
11123 : {
11124 12 : AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
11125 :
11126 12 : n->objectType = OBJECT_PROCEDURE;
11127 12 : n->object = (Node *) $3;
11128 12 : n->newowner = $6;
11129 12 : $$ = (Node *) n;
11130 : }
11131 : | ALTER PROPERTY GRAPH qualified_name OWNER TO RoleSpec
11132 : {
11133 33 : AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
11134 :
11135 33 : n->objectType = OBJECT_PROPGRAPH;
11136 33 : n->relation = $4;
11137 33 : n->newowner = $7;
11138 33 : $$ = (Node *) n;
11139 : }
11140 : | ALTER ROUTINE function_with_argtypes OWNER TO RoleSpec
11141 : {
11142 0 : AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
11143 :
11144 0 : n->objectType = OBJECT_ROUTINE;
11145 0 : n->object = (Node *) $3;
11146 0 : n->newowner = $6;
11147 0 : $$ = (Node *) n;
11148 : }
11149 : | ALTER SCHEMA name OWNER TO RoleSpec
11150 : {
11151 41 : AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
11152 :
11153 41 : n->objectType = OBJECT_SCHEMA;
11154 41 : n->object = (Node *) makeString($3);
11155 41 : n->newowner = $6;
11156 41 : $$ = (Node *) n;
11157 : }
11158 : | ALTER TYPE_P any_name OWNER TO RoleSpec
11159 : {
11160 44 : AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
11161 :
11162 44 : n->objectType = OBJECT_TYPE;
11163 44 : n->object = (Node *) $3;
11164 44 : n->newowner = $6;
11165 44 : $$ = (Node *) n;
11166 : }
11167 : | ALTER TABLESPACE name OWNER TO RoleSpec
11168 : {
11169 3 : AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
11170 :
11171 3 : n->objectType = OBJECT_TABLESPACE;
11172 3 : n->object = (Node *) makeString($3);
11173 3 : n->newowner = $6;
11174 3 : $$ = (Node *) n;
11175 : }
11176 : | ALTER STATISTICS any_name OWNER TO RoleSpec
11177 : {
11178 20 : AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
11179 :
11180 20 : n->objectType = OBJECT_STATISTIC_EXT;
11181 20 : n->object = (Node *) $3;
11182 20 : n->newowner = $6;
11183 20 : $$ = (Node *) n;
11184 : }
11185 : | ALTER TEXT_P SEARCH DICTIONARY any_name OWNER TO RoleSpec
11186 : {
11187 25 : AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
11188 :
11189 25 : n->objectType = OBJECT_TSDICTIONARY;
11190 25 : n->object = (Node *) $5;
11191 25 : n->newowner = $8;
11192 25 : $$ = (Node *) n;
11193 : }
11194 : | ALTER TEXT_P SEARCH CONFIGURATION any_name OWNER TO RoleSpec
11195 : {
11196 20 : AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
11197 :
11198 20 : n->objectType = OBJECT_TSCONFIGURATION;
11199 20 : n->object = (Node *) $5;
11200 20 : n->newowner = $8;
11201 20 : $$ = (Node *) n;
11202 : }
11203 : | ALTER FOREIGN DATA_P WRAPPER name OWNER TO RoleSpec
11204 : {
11205 13 : AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
11206 :
11207 13 : n->objectType = OBJECT_FDW;
11208 13 : n->object = (Node *) makeString($5);
11209 13 : n->newowner = $8;
11210 13 : $$ = (Node *) n;
11211 : }
11212 : | ALTER SERVER name OWNER TO RoleSpec
11213 : {
11214 45 : AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
11215 :
11216 45 : n->objectType = OBJECT_FOREIGN_SERVER;
11217 45 : n->object = (Node *) makeString($3);
11218 45 : n->newowner = $6;
11219 45 : $$ = (Node *) n;
11220 : }
11221 : | ALTER EVENT TRIGGER name OWNER TO RoleSpec
11222 : {
11223 9 : AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
11224 :
11225 9 : n->objectType = OBJECT_EVENT_TRIGGER;
11226 9 : n->object = (Node *) makeString($4);
11227 9 : n->newowner = $7;
11228 9 : $$ = (Node *) n;
11229 : }
11230 : | ALTER PUBLICATION name OWNER TO RoleSpec
11231 : {
11232 26 : AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
11233 :
11234 26 : n->objectType = OBJECT_PUBLICATION;
11235 26 : n->object = (Node *) makeString($3);
11236 26 : n->newowner = $6;
11237 26 : $$ = (Node *) n;
11238 : }
11239 : | ALTER SUBSCRIPTION name OWNER TO RoleSpec
11240 : {
11241 11 : AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
11242 :
11243 11 : n->objectType = OBJECT_SUBSCRIPTION;
11244 11 : n->object = (Node *) makeString($3);
11245 11 : n->newowner = $6;
11246 11 : $$ = (Node *) n;
11247 : }
11248 : ;
11249 :
11250 :
11251 : /*****************************************************************************
11252 : *
11253 : * CREATE PUBLICATION name [WITH options]
11254 : *
11255 : * CREATE PUBLICATION FOR ALL pub_all_obj_type [, ...] [WITH options]
11256 : *
11257 : * pub_all_obj_type is one of:
11258 : *
11259 : * TABLES [EXCEPT TABLE ( table [, ...] )]
11260 : * SEQUENCES
11261 : *
11262 : * CREATE PUBLICATION FOR pub_obj [, ...] [WITH options]
11263 : *
11264 : * pub_obj is one of:
11265 : *
11266 : * TABLE table [, ...]
11267 : * TABLES IN SCHEMA schema [, ...]
11268 : *
11269 : *****************************************************************************/
11270 :
11271 : CreatePublicationStmt:
11272 : CREATE PUBLICATION name opt_definition
11273 : {
11274 94 : CreatePublicationStmt *n = makeNode(CreatePublicationStmt);
11275 :
11276 94 : n->pubname = $3;
11277 94 : n->options = $4;
11278 94 : $$ = (Node *) n;
11279 : }
11280 : | CREATE PUBLICATION name FOR pub_all_obj_type_list opt_definition
11281 : {
11282 120 : CreatePublicationStmt *n = makeNode(CreatePublicationStmt);
11283 :
11284 120 : n->pubname = $3;
11285 120 : preprocess_pub_all_objtype_list($5, &n->pubobjects,
11286 : &n->for_all_tables,
11287 : &n->for_all_sequences,
11288 : yyscanner);
11289 112 : n->options = $6;
11290 112 : $$ = (Node *) n;
11291 : }
11292 : | CREATE PUBLICATION name FOR pub_obj_list opt_definition
11293 : {
11294 408 : CreatePublicationStmt *n = makeNode(CreatePublicationStmt);
11295 :
11296 408 : n->pubname = $3;
11297 408 : n->options = $6;
11298 408 : n->pubobjects = (List *) $5;
11299 408 : preprocess_pubobj_list(n->pubobjects, yyscanner);
11300 388 : $$ = (Node *) n;
11301 : }
11302 : ;
11303 :
11304 : /*
11305 : * FOR TABLE and FOR TABLES IN SCHEMA specifications
11306 : *
11307 : * This rule parses publication objects with and without keyword prefixes.
11308 : *
11309 : * The actual type of the object without keyword prefix depends on the previous
11310 : * one with keyword prefix. It will be preprocessed in preprocess_pubobj_list().
11311 : *
11312 : * For the object without keyword prefix, we cannot just use relation_expr here,
11313 : * because some extended expressions in relation_expr cannot be used as a
11314 : * schemaname and we cannot differentiate it. So, we extract the rules from
11315 : * relation_expr here.
11316 : */
11317 : PublicationObjSpec:
11318 : TABLE relation_expr opt_column_list OptWhereClause
11319 : {
11320 841 : $$ = makeNode(PublicationObjSpec);
11321 841 : $$->pubobjtype = PUBLICATIONOBJ_TABLE;
11322 841 : $$->pubtable = makeNode(PublicationTable);
11323 841 : $$->pubtable->relation = $2;
11324 841 : $$->pubtable->columns = $3;
11325 841 : $$->pubtable->whereClause = $4;
11326 : }
11327 : | TABLES IN_P SCHEMA ColId
11328 : {
11329 244 : $$ = makeNode(PublicationObjSpec);
11330 244 : $$->pubobjtype = PUBLICATIONOBJ_TABLES_IN_SCHEMA;
11331 244 : $$->name = $4;
11332 244 : $$->location = @4;
11333 : }
11334 : | TABLES IN_P SCHEMA CURRENT_SCHEMA
11335 : {
11336 12 : $$ = makeNode(PublicationObjSpec);
11337 12 : $$->pubobjtype = PUBLICATIONOBJ_TABLES_IN_CUR_SCHEMA;
11338 12 : $$->location = @4;
11339 : }
11340 : | ColId opt_column_list OptWhereClause
11341 : {
11342 79 : $$ = makeNode(PublicationObjSpec);
11343 79 : $$->pubobjtype = PUBLICATIONOBJ_CONTINUATION;
11344 : /*
11345 : * If either a row filter or column list is specified, create
11346 : * a PublicationTable object.
11347 : */
11348 79 : if ($2 || $3)
11349 : {
11350 : /*
11351 : * The OptWhereClause must be stored here but it is
11352 : * valid only for tables. For non-table objects, an
11353 : * error will be thrown later via
11354 : * preprocess_pubobj_list().
11355 : */
11356 26 : $$->pubtable = makeNode(PublicationTable);
11357 26 : $$->pubtable->relation = makeRangeVar(NULL, $1, @1);
11358 26 : $$->pubtable->columns = $2;
11359 26 : $$->pubtable->whereClause = $3;
11360 : }
11361 : else
11362 : {
11363 53 : $$->name = $1;
11364 : }
11365 79 : $$->location = @1;
11366 : }
11367 : | ColId indirection opt_column_list OptWhereClause
11368 : {
11369 21 : $$ = makeNode(PublicationObjSpec);
11370 21 : $$->pubobjtype = PUBLICATIONOBJ_CONTINUATION;
11371 21 : $$->pubtable = makeNode(PublicationTable);
11372 21 : $$->pubtable->relation = makeRangeVarFromQualifiedName($1, $2, @1, yyscanner);
11373 21 : $$->pubtable->columns = $3;
11374 21 : $$->pubtable->whereClause = $4;
11375 21 : $$->location = @1;
11376 : }
11377 : /* grammar like tablename * , ONLY tablename, ONLY ( tablename ) */
11378 : | extended_relation_expr opt_column_list OptWhereClause
11379 : {
11380 4 : $$ = makeNode(PublicationObjSpec);
11381 4 : $$->pubobjtype = PUBLICATIONOBJ_CONTINUATION;
11382 4 : $$->pubtable = makeNode(PublicationTable);
11383 4 : $$->pubtable->relation = $1;
11384 4 : $$->pubtable->columns = $2;
11385 4 : $$->pubtable->whereClause = $3;
11386 : }
11387 : | CURRENT_SCHEMA
11388 : {
11389 12 : $$ = makeNode(PublicationObjSpec);
11390 12 : $$->pubobjtype = PUBLICATIONOBJ_CONTINUATION;
11391 12 : $$->location = @1;
11392 : }
11393 : ;
11394 :
11395 : pub_obj_list: PublicationObjSpec
11396 1052 : { $$ = list_make1($1); }
11397 : | pub_obj_list ',' PublicationObjSpec
11398 161 : { $$ = lappend($1, $3); }
11399 : ;
11400 :
11401 : opt_pub_except_clause:
11402 52 : EXCEPT TABLE '(' pub_except_obj_list ')' { $$ = $4; }
11403 101 : | /*EMPTY*/ { $$ = NIL; }
11404 : ;
11405 :
11406 : PublicationAllObjSpec:
11407 : ALL TABLES opt_pub_except_clause
11408 : {
11409 153 : $$ = makeNode(PublicationAllObjSpec);
11410 153 : $$->pubobjtype = PUBLICATION_ALL_TABLES;
11411 153 : $$->except_tables = $3;
11412 153 : $$->location = @1;
11413 : }
11414 : | ALL SEQUENCES
11415 : {
11416 49 : $$ = makeNode(PublicationAllObjSpec);
11417 49 : $$->pubobjtype = PUBLICATION_ALL_SEQUENCES;
11418 49 : $$->location = @1;
11419 : }
11420 : ;
11421 :
11422 : pub_all_obj_type_list: PublicationAllObjSpec
11423 177 : { $$ = list_make1($1); }
11424 : | pub_all_obj_type_list ',' PublicationAllObjSpec
11425 25 : { $$ = lappend($1, $3); }
11426 : ;
11427 :
11428 : PublicationExceptObjSpec:
11429 : relation_expr
11430 : {
11431 59 : $$ = makeNode(PublicationObjSpec);
11432 59 : $$->pubobjtype = PUBLICATIONOBJ_EXCEPT_TABLE;
11433 59 : $$->pubtable = makeNode(PublicationTable);
11434 59 : $$->pubtable->except = true;
11435 59 : $$->pubtable->relation = $1;
11436 59 : $$->location = @1;
11437 : }
11438 : ;
11439 :
11440 : pub_except_obj_list: PublicationExceptObjSpec
11441 52 : { $$ = list_make1($1); }
11442 : | pub_except_obj_list ',' PublicationExceptObjSpec
11443 7 : { $$ = lappend($1, $3); }
11444 : ;
11445 :
11446 : /*****************************************************************************
11447 : *
11448 : * ALTER PUBLICATION name SET ( options )
11449 : *
11450 : * ALTER PUBLICATION name ADD pub_obj [, ...]
11451 : *
11452 : * ALTER PUBLICATION name DROP pub_obj [, ...]
11453 : *
11454 : * ALTER PUBLICATION name SET pub_obj [, ...]
11455 : *
11456 : * ALTER PUBLICATION name SET pub_all_obj_type [, ...]
11457 : *
11458 : * pub_obj is one of:
11459 : *
11460 : * TABLE table_name [, ...]
11461 : * TABLES IN SCHEMA schema_name [, ...]
11462 : *
11463 : * pub_all_obj_type is one of:
11464 : *
11465 : * ALL TABLES [ EXCEPT TABLE ( table_name [, ...] ) ]
11466 : * ALL SEQUENCES
11467 : *
11468 : *****************************************************************************/
11469 :
11470 : AlterPublicationStmt:
11471 : ALTER PUBLICATION name SET definition
11472 : {
11473 84 : AlterPublicationStmt *n = makeNode(AlterPublicationStmt);
11474 :
11475 84 : n->pubname = $3;
11476 84 : n->options = $5;
11477 84 : n->for_all_tables = false;
11478 84 : $$ = (Node *) n;
11479 : }
11480 : | ALTER PUBLICATION name ADD_P pub_obj_list
11481 : {
11482 233 : AlterPublicationStmt *n = makeNode(AlterPublicationStmt);
11483 :
11484 233 : n->pubname = $3;
11485 233 : n->pubobjects = $5;
11486 233 : preprocess_pubobj_list(n->pubobjects, yyscanner);
11487 229 : n->action = AP_AddObjects;
11488 229 : n->for_all_tables = false;
11489 229 : $$ = (Node *) n;
11490 : }
11491 : | ALTER PUBLICATION name SET pub_obj_list
11492 : {
11493 308 : AlterPublicationStmt *n = makeNode(AlterPublicationStmt);
11494 :
11495 308 : n->pubname = $3;
11496 308 : n->pubobjects = $5;
11497 308 : preprocess_pubobj_list(n->pubobjects, yyscanner);
11498 308 : n->action = AP_SetObjects;
11499 308 : n->for_all_tables = false;
11500 308 : $$ = (Node *) n;
11501 : }
11502 : | ALTER PUBLICATION name SET pub_all_obj_type_list
11503 : {
11504 57 : AlterPublicationStmt *n = makeNode(AlterPublicationStmt);
11505 :
11506 57 : n->pubname = $3;
11507 57 : n->action = AP_SetObjects;
11508 57 : preprocess_pub_all_objtype_list($5, &n->pubobjects,
11509 : &n->for_all_tables,
11510 : &n->for_all_sequences,
11511 : yyscanner);
11512 57 : $$ = (Node *) n;
11513 : }
11514 : | ALTER PUBLICATION name DROP pub_obj_list
11515 : {
11516 103 : AlterPublicationStmt *n = makeNode(AlterPublicationStmt);
11517 :
11518 103 : n->pubname = $3;
11519 103 : n->pubobjects = $5;
11520 103 : preprocess_pubobj_list(n->pubobjects, yyscanner);
11521 103 : n->action = AP_DropObjects;
11522 103 : n->for_all_tables = false;
11523 103 : $$ = (Node *) n;
11524 : }
11525 : ;
11526 :
11527 : /*****************************************************************************
11528 : *
11529 : * CREATE SUBSCRIPTION name ...
11530 : *
11531 : *****************************************************************************/
11532 :
11533 : CreateSubscriptionStmt:
11534 : CREATE SUBSCRIPTION name CONNECTION Sconst PUBLICATION name_list opt_definition
11535 : {
11536 : CreateSubscriptionStmt *n =
11537 285 : makeNode(CreateSubscriptionStmt);
11538 285 : n->subname = $3;
11539 285 : n->conninfo = $5;
11540 285 : n->publication = $7;
11541 285 : n->options = $8;
11542 285 : $$ = (Node *) n;
11543 : }
11544 : | CREATE SUBSCRIPTION name SERVER name PUBLICATION name_list opt_definition
11545 : {
11546 : CreateSubscriptionStmt *n =
11547 18 : makeNode(CreateSubscriptionStmt);
11548 18 : n->subname = $3;
11549 18 : n->servername = $5;
11550 18 : n->publication = $7;
11551 18 : n->options = $8;
11552 18 : $$ = (Node *) n;
11553 : }
11554 : ;
11555 :
11556 : /*****************************************************************************
11557 : *
11558 : * ALTER SUBSCRIPTION name ...
11559 : *
11560 : *****************************************************************************/
11561 :
11562 : AlterSubscriptionStmt:
11563 : ALTER SUBSCRIPTION name SET definition
11564 : {
11565 : AlterSubscriptionStmt *n =
11566 152 : makeNode(AlterSubscriptionStmt);
11567 :
11568 152 : n->kind = ALTER_SUBSCRIPTION_OPTIONS;
11569 152 : n->subname = $3;
11570 152 : n->options = $5;
11571 152 : $$ = (Node *) n;
11572 : }
11573 : | ALTER SUBSCRIPTION name CONNECTION Sconst
11574 : {
11575 : AlterSubscriptionStmt *n =
11576 17 : makeNode(AlterSubscriptionStmt);
11577 :
11578 17 : n->kind = ALTER_SUBSCRIPTION_CONNECTION;
11579 17 : n->subname = $3;
11580 17 : n->conninfo = $5;
11581 17 : $$ = (Node *) n;
11582 : }
11583 : | ALTER SUBSCRIPTION name SERVER name
11584 : {
11585 : AlterSubscriptionStmt *n =
11586 1 : makeNode(AlterSubscriptionStmt);
11587 :
11588 1 : n->kind = ALTER_SUBSCRIPTION_SERVER;
11589 1 : n->subname = $3;
11590 1 : n->servername = $5;
11591 1 : $$ = (Node *) n;
11592 : }
11593 : | ALTER SUBSCRIPTION name REFRESH PUBLICATION opt_definition
11594 : {
11595 : AlterSubscriptionStmt *n =
11596 37 : makeNode(AlterSubscriptionStmt);
11597 :
11598 37 : n->kind = ALTER_SUBSCRIPTION_REFRESH_PUBLICATION;
11599 37 : n->subname = $3;
11600 37 : n->options = $6;
11601 37 : $$ = (Node *) n;
11602 : }
11603 : | ALTER SUBSCRIPTION name REFRESH SEQUENCES
11604 : {
11605 : AlterSubscriptionStmt *n =
11606 1 : makeNode(AlterSubscriptionStmt);
11607 :
11608 1 : n->kind = ALTER_SUBSCRIPTION_REFRESH_SEQUENCES;
11609 1 : n->subname = $3;
11610 1 : $$ = (Node *) n;
11611 : }
11612 : | ALTER SUBSCRIPTION name ADD_P PUBLICATION name_list opt_definition
11613 : {
11614 : AlterSubscriptionStmt *n =
11615 18 : makeNode(AlterSubscriptionStmt);
11616 :
11617 18 : n->kind = ALTER_SUBSCRIPTION_ADD_PUBLICATION;
11618 18 : n->subname = $3;
11619 18 : n->publication = $6;
11620 18 : n->options = $7;
11621 18 : $$ = (Node *) n;
11622 : }
11623 : | ALTER SUBSCRIPTION name DROP PUBLICATION name_list opt_definition
11624 : {
11625 : AlterSubscriptionStmt *n =
11626 17 : makeNode(AlterSubscriptionStmt);
11627 :
11628 17 : n->kind = ALTER_SUBSCRIPTION_DROP_PUBLICATION;
11629 17 : n->subname = $3;
11630 17 : n->publication = $6;
11631 17 : n->options = $7;
11632 17 : $$ = (Node *) n;
11633 : }
11634 : | ALTER SUBSCRIPTION name SET PUBLICATION name_list opt_definition
11635 : {
11636 : AlterSubscriptionStmt *n =
11637 28 : makeNode(AlterSubscriptionStmt);
11638 :
11639 28 : n->kind = ALTER_SUBSCRIPTION_SET_PUBLICATION;
11640 28 : n->subname = $3;
11641 28 : n->publication = $6;
11642 28 : n->options = $7;
11643 28 : $$ = (Node *) n;
11644 : }
11645 : | ALTER SUBSCRIPTION name ENABLE_P
11646 : {
11647 : AlterSubscriptionStmt *n =
11648 34 : makeNode(AlterSubscriptionStmt);
11649 :
11650 34 : n->kind = ALTER_SUBSCRIPTION_ENABLED;
11651 34 : n->subname = $3;
11652 34 : n->options = list_make1(makeDefElem("enabled",
11653 : (Node *) makeBoolean(true), @1));
11654 34 : $$ = (Node *) n;
11655 : }
11656 : | ALTER SUBSCRIPTION name DISABLE_P
11657 : {
11658 : AlterSubscriptionStmt *n =
11659 24 : makeNode(AlterSubscriptionStmt);
11660 :
11661 24 : n->kind = ALTER_SUBSCRIPTION_ENABLED;
11662 24 : n->subname = $3;
11663 24 : n->options = list_make1(makeDefElem("enabled",
11664 : (Node *) makeBoolean(false), @1));
11665 24 : $$ = (Node *) n;
11666 : }
11667 : | ALTER SUBSCRIPTION name SKIP definition
11668 : {
11669 : AlterSubscriptionStmt *n =
11670 15 : makeNode(AlterSubscriptionStmt);
11671 :
11672 15 : n->kind = ALTER_SUBSCRIPTION_SKIP;
11673 15 : n->subname = $3;
11674 15 : n->options = $5;
11675 15 : $$ = (Node *) n;
11676 : }
11677 : ;
11678 :
11679 : /*****************************************************************************
11680 : *
11681 : * DROP SUBSCRIPTION [ IF EXISTS ] name
11682 : *
11683 : *****************************************************************************/
11684 :
11685 : DropSubscriptionStmt: DROP SUBSCRIPTION name opt_drop_behavior
11686 : {
11687 151 : DropSubscriptionStmt *n = makeNode(DropSubscriptionStmt);
11688 :
11689 151 : n->subname = $3;
11690 151 : n->missing_ok = false;
11691 151 : n->behavior = $4;
11692 151 : $$ = (Node *) n;
11693 : }
11694 : | DROP SUBSCRIPTION IF_P EXISTS name opt_drop_behavior
11695 : {
11696 4 : DropSubscriptionStmt *n = makeNode(DropSubscriptionStmt);
11697 :
11698 4 : n->subname = $5;
11699 4 : n->missing_ok = true;
11700 4 : n->behavior = $6;
11701 4 : $$ = (Node *) n;
11702 : }
11703 : ;
11704 :
11705 : /*****************************************************************************
11706 : *
11707 : * QUERY: Define Rewrite Rule
11708 : *
11709 : *****************************************************************************/
11710 :
11711 : RuleStmt: CREATE opt_or_replace RULE name AS
11712 : ON event TO qualified_name where_clause
11713 : DO opt_instead RuleActionList
11714 : {
11715 690 : RuleStmt *n = makeNode(RuleStmt);
11716 :
11717 690 : n->replace = $2;
11718 690 : n->relation = $9;
11719 690 : n->rulename = $4;
11720 690 : n->whereClause = $10;
11721 690 : n->event = $7;
11722 690 : n->instead = $12;
11723 690 : n->actions = $13;
11724 690 : $$ = (Node *) n;
11725 : }
11726 : ;
11727 :
11728 : RuleActionList:
11729 90 : NOTHING { $$ = NIL; }
11730 570 : | RuleActionStmt { $$ = list_make1($1); }
11731 30 : | '(' RuleActionMulti ')' { $$ = $2; }
11732 : ;
11733 :
11734 : /* the thrashing around here is to discard "empty" statements... */
11735 : RuleActionMulti:
11736 : RuleActionMulti ';' RuleActionStmtOrEmpty
11737 40 : { if ($3 != NULL)
11738 30 : $$ = lappend($1, $3);
11739 : else
11740 10 : $$ = $1;
11741 : }
11742 : | RuleActionStmtOrEmpty
11743 30 : { if ($1 != NULL)
11744 30 : $$ = list_make1($1);
11745 : else
11746 0 : $$ = NIL;
11747 : }
11748 : ;
11749 :
11750 : RuleActionStmt:
11751 : SelectStmt
11752 : | InsertStmt
11753 : | UpdateStmt
11754 : | DeleteStmt
11755 : | NotifyStmt
11756 : ;
11757 :
11758 : RuleActionStmtOrEmpty:
11759 60 : RuleActionStmt { $$ = $1; }
11760 10 : | /*EMPTY*/ { $$ = NULL; }
11761 : ;
11762 :
11763 12 : event: SELECT { $$ = CMD_SELECT; }
11764 254 : | UPDATE { $$ = CMD_UPDATE; }
11765 106 : | DELETE_P { $$ = CMD_DELETE; }
11766 318 : | INSERT { $$ = CMD_INSERT; }
11767 : ;
11768 :
11769 : opt_instead:
11770 485 : INSTEAD { $$ = true; }
11771 103 : | ALSO { $$ = false; }
11772 102 : | /*EMPTY*/ { $$ = false; }
11773 : ;
11774 :
11775 :
11776 : /*****************************************************************************
11777 : *
11778 : * QUERY:
11779 : * NOTIFY <identifier> can appear both in rule bodies and
11780 : * as a query-level command
11781 : *
11782 : *****************************************************************************/
11783 :
11784 : NotifyStmt: NOTIFY ColId notify_payload
11785 : {
11786 88 : NotifyStmt *n = makeNode(NotifyStmt);
11787 :
11788 88 : n->conditionname = $2;
11789 88 : n->payload = $3;
11790 88 : $$ = (Node *) n;
11791 : }
11792 : ;
11793 :
11794 : notify_payload:
11795 47 : ',' Sconst { $$ = $2; }
11796 41 : | /*EMPTY*/ { $$ = NULL; }
11797 : ;
11798 :
11799 : ListenStmt: LISTEN ColId
11800 : {
11801 60 : ListenStmt *n = makeNode(ListenStmt);
11802 :
11803 60 : n->conditionname = $2;
11804 60 : $$ = (Node *) n;
11805 : }
11806 : ;
11807 :
11808 : UnlistenStmt:
11809 : UNLISTEN ColId
11810 : {
11811 4 : UnlistenStmt *n = makeNode(UnlistenStmt);
11812 :
11813 4 : n->conditionname = $2;
11814 4 : $$ = (Node *) n;
11815 : }
11816 : | UNLISTEN '*'
11817 : {
11818 76 : UnlistenStmt *n = makeNode(UnlistenStmt);
11819 :
11820 76 : n->conditionname = NULL;
11821 76 : $$ = (Node *) n;
11822 : }
11823 : ;
11824 :
11825 :
11826 : /*****************************************************************************
11827 : *
11828 : * Transactions:
11829 : *
11830 : * BEGIN / COMMIT / ROLLBACK
11831 : * (also older versions END / ABORT)
11832 : *
11833 : *****************************************************************************/
11834 :
11835 : TransactionStmt:
11836 : ABORT_P opt_transaction opt_transaction_chain
11837 : {
11838 401 : TransactionStmt *n = makeNode(TransactionStmt);
11839 :
11840 401 : n->kind = TRANS_STMT_ROLLBACK;
11841 401 : n->options = NIL;
11842 401 : n->chain = $3;
11843 401 : n->location = -1;
11844 401 : $$ = (Node *) n;
11845 : }
11846 : | START TRANSACTION transaction_mode_list_or_empty
11847 : {
11848 845 : TransactionStmt *n = makeNode(TransactionStmt);
11849 :
11850 845 : n->kind = TRANS_STMT_START;
11851 845 : n->options = $3;
11852 845 : n->location = -1;
11853 845 : $$ = (Node *) n;
11854 : }
11855 : | COMMIT opt_transaction opt_transaction_chain
11856 : {
11857 9261 : TransactionStmt *n = makeNode(TransactionStmt);
11858 :
11859 9261 : n->kind = TRANS_STMT_COMMIT;
11860 9261 : n->options = NIL;
11861 9261 : n->chain = $3;
11862 9261 : n->location = -1;
11863 9261 : $$ = (Node *) n;
11864 : }
11865 : | ROLLBACK opt_transaction opt_transaction_chain
11866 : {
11867 1792 : TransactionStmt *n = makeNode(TransactionStmt);
11868 :
11869 1792 : n->kind = TRANS_STMT_ROLLBACK;
11870 1792 : n->options = NIL;
11871 1792 : n->chain = $3;
11872 1792 : n->location = -1;
11873 1792 : $$ = (Node *) n;
11874 : }
11875 : | SAVEPOINT ColId
11876 : {
11877 1125 : TransactionStmt *n = makeNode(TransactionStmt);
11878 :
11879 1125 : n->kind = TRANS_STMT_SAVEPOINT;
11880 1125 : n->savepoint_name = $2;
11881 1125 : n->location = @2;
11882 1125 : $$ = (Node *) n;
11883 : }
11884 : | RELEASE SAVEPOINT ColId
11885 : {
11886 125 : TransactionStmt *n = makeNode(TransactionStmt);
11887 :
11888 125 : n->kind = TRANS_STMT_RELEASE;
11889 125 : n->savepoint_name = $3;
11890 125 : n->location = @3;
11891 125 : $$ = (Node *) n;
11892 : }
11893 : | RELEASE ColId
11894 : {
11895 55 : TransactionStmt *n = makeNode(TransactionStmt);
11896 :
11897 55 : n->kind = TRANS_STMT_RELEASE;
11898 55 : n->savepoint_name = $2;
11899 55 : n->location = @2;
11900 55 : $$ = (Node *) n;
11901 : }
11902 : | ROLLBACK opt_transaction TO SAVEPOINT ColId
11903 : {
11904 157 : TransactionStmt *n = makeNode(TransactionStmt);
11905 :
11906 157 : n->kind = TRANS_STMT_ROLLBACK_TO;
11907 157 : n->savepoint_name = $5;
11908 157 : n->location = @5;
11909 157 : $$ = (Node *) n;
11910 : }
11911 : | ROLLBACK opt_transaction TO ColId
11912 : {
11913 311 : TransactionStmt *n = makeNode(TransactionStmt);
11914 :
11915 311 : n->kind = TRANS_STMT_ROLLBACK_TO;
11916 311 : n->savepoint_name = $4;
11917 311 : n->location = @4;
11918 311 : $$ = (Node *) n;
11919 : }
11920 : | PREPARE TRANSACTION Sconst
11921 : {
11922 350 : TransactionStmt *n = makeNode(TransactionStmt);
11923 :
11924 350 : n->kind = TRANS_STMT_PREPARE;
11925 350 : n->gid = $3;
11926 350 : n->location = @3;
11927 350 : $$ = (Node *) n;
11928 : }
11929 : | COMMIT PREPARED Sconst
11930 : {
11931 255 : TransactionStmt *n = makeNode(TransactionStmt);
11932 :
11933 255 : n->kind = TRANS_STMT_COMMIT_PREPARED;
11934 255 : n->gid = $3;
11935 255 : n->location = @3;
11936 255 : $$ = (Node *) n;
11937 : }
11938 : | ROLLBACK PREPARED Sconst
11939 : {
11940 48 : TransactionStmt *n = makeNode(TransactionStmt);
11941 :
11942 48 : n->kind = TRANS_STMT_ROLLBACK_PREPARED;
11943 48 : n->gid = $3;
11944 48 : n->location = @3;
11945 48 : $$ = (Node *) n;
11946 : }
11947 : ;
11948 :
11949 : TransactionStmtLegacy:
11950 : BEGIN_P opt_transaction transaction_mode_list_or_empty
11951 : {
11952 11411 : TransactionStmt *n = makeNode(TransactionStmt);
11953 :
11954 11411 : n->kind = TRANS_STMT_BEGIN;
11955 11411 : n->options = $3;
11956 11411 : n->location = -1;
11957 11411 : $$ = (Node *) n;
11958 : }
11959 : | END_P opt_transaction opt_transaction_chain
11960 : {
11961 207 : TransactionStmt *n = makeNode(TransactionStmt);
11962 :
11963 207 : n->kind = TRANS_STMT_COMMIT;
11964 207 : n->options = NIL;
11965 207 : n->chain = $3;
11966 207 : n->location = -1;
11967 207 : $$ = (Node *) n;
11968 : }
11969 : ;
11970 :
11971 : opt_transaction: WORK
11972 : | TRANSACTION
11973 : | /*EMPTY*/
11974 : ;
11975 :
11976 : transaction_mode_item:
11977 : ISOLATION LEVEL iso_level
11978 3635 : { $$ = makeDefElem("transaction_isolation",
11979 3635 : makeStringConst($3, @3), @1); }
11980 : | READ ONLY
11981 825 : { $$ = makeDefElem("transaction_read_only",
11982 825 : makeIntConst(true, @1), @1); }
11983 : | READ WRITE
11984 59 : { $$ = makeDefElem("transaction_read_only",
11985 59 : makeIntConst(false, @1), @1); }
11986 : | DEFERRABLE
11987 28 : { $$ = makeDefElem("transaction_deferrable",
11988 : makeIntConst(true, @1), @1); }
11989 : | NOT DEFERRABLE
11990 6 : { $$ = makeDefElem("transaction_deferrable",
11991 6 : makeIntConst(false, @1), @1); }
11992 : ;
11993 :
11994 : /* Syntax with commas is SQL-spec, without commas is Postgres historical */
11995 : transaction_mode_list:
11996 : transaction_mode_item
11997 3777 : { $$ = list_make1($1); }
11998 : | transaction_mode_list ',' transaction_mode_item
11999 558 : { $$ = lappend($1, $3); }
12000 : | transaction_mode_list transaction_mode_item
12001 218 : { $$ = lappend($1, $2); }
12002 : ;
12003 :
12004 : transaction_mode_list_or_empty:
12005 : transaction_mode_list
12006 : | /* EMPTY */
12007 8877 : { $$ = NIL; }
12008 : ;
12009 :
12010 : opt_transaction_chain:
12011 80 : AND CHAIN { $$ = true; }
12012 1 : | AND NO CHAIN { $$ = false; }
12013 11580 : | /* EMPTY */ { $$ = false; }
12014 : ;
12015 :
12016 :
12017 : /*****************************************************************************
12018 : *
12019 : * QUERY:
12020 : * CREATE [ OR REPLACE ] [ TEMP ] VIEW <viewname> '('target-list ')'
12021 : * AS <query> [ WITH [ CASCADED | LOCAL ] CHECK OPTION ]
12022 : *
12023 : *****************************************************************************/
12024 :
12025 : ViewStmt: CREATE OptTemp VIEW qualified_name opt_column_list opt_reloptions
12026 : AS SelectStmt opt_check_option
12027 : {
12028 9603 : ViewStmt *n = makeNode(ViewStmt);
12029 :
12030 9603 : n->view = $4;
12031 9603 : n->view->relpersistence = $2;
12032 9603 : n->aliases = $5;
12033 9603 : n->query = $8;
12034 9603 : n->replace = false;
12035 9603 : n->options = $6;
12036 9603 : n->withCheckOption = $9;
12037 9603 : $$ = (Node *) n;
12038 : }
12039 : | CREATE OR REPLACE OptTemp VIEW qualified_name opt_column_list opt_reloptions
12040 : AS SelectStmt opt_check_option
12041 : {
12042 169 : ViewStmt *n = makeNode(ViewStmt);
12043 :
12044 169 : n->view = $6;
12045 169 : n->view->relpersistence = $4;
12046 169 : n->aliases = $7;
12047 169 : n->query = $10;
12048 169 : n->replace = true;
12049 169 : n->options = $8;
12050 169 : n->withCheckOption = $11;
12051 169 : $$ = (Node *) n;
12052 : }
12053 : | CREATE OptTemp RECURSIVE VIEW qualified_name '(' columnList ')' opt_reloptions
12054 : AS SelectStmt opt_check_option
12055 : {
12056 5 : ViewStmt *n = makeNode(ViewStmt);
12057 :
12058 5 : n->view = $5;
12059 5 : n->view->relpersistence = $2;
12060 5 : n->aliases = $7;
12061 5 : n->query = makeRecursiveViewSelect(n->view->relname, n->aliases, $11);
12062 5 : n->replace = false;
12063 5 : n->options = $9;
12064 5 : n->withCheckOption = $12;
12065 5 : if (n->withCheckOption != NO_CHECK_OPTION)
12066 0 : ereport(ERROR,
12067 : (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
12068 : errmsg("WITH CHECK OPTION not supported on recursive views"),
12069 : parser_errposition(@12)));
12070 5 : $$ = (Node *) n;
12071 : }
12072 : | CREATE OR REPLACE OptTemp RECURSIVE VIEW qualified_name '(' columnList ')' opt_reloptions
12073 : AS SelectStmt opt_check_option
12074 : {
12075 4 : ViewStmt *n = makeNode(ViewStmt);
12076 :
12077 4 : n->view = $7;
12078 4 : n->view->relpersistence = $4;
12079 4 : n->aliases = $9;
12080 4 : n->query = makeRecursiveViewSelect(n->view->relname, n->aliases, $13);
12081 4 : n->replace = true;
12082 4 : n->options = $11;
12083 4 : n->withCheckOption = $14;
12084 4 : if (n->withCheckOption != NO_CHECK_OPTION)
12085 0 : ereport(ERROR,
12086 : (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
12087 : errmsg("WITH CHECK OPTION not supported on recursive views"),
12088 : parser_errposition(@14)));
12089 4 : $$ = (Node *) n;
12090 : }
12091 : ;
12092 :
12093 : opt_check_option:
12094 63 : WITH CHECK OPTION { $$ = CASCADED_CHECK_OPTION; }
12095 4 : | WITH CASCADED CHECK OPTION { $$ = CASCADED_CHECK_OPTION; }
12096 16 : | WITH LOCAL CHECK OPTION { $$ = LOCAL_CHECK_OPTION; }
12097 9698 : | /* EMPTY */ { $$ = NO_CHECK_OPTION; }
12098 : ;
12099 :
12100 : /*****************************************************************************
12101 : *
12102 : * QUERY:
12103 : * LOAD "filename"
12104 : *
12105 : *****************************************************************************/
12106 :
12107 : LoadStmt: LOAD file_name
12108 : {
12109 43 : LoadStmt *n = makeNode(LoadStmt);
12110 :
12111 43 : n->filename = $2;
12112 43 : $$ = (Node *) n;
12113 : }
12114 : ;
12115 :
12116 :
12117 : /*****************************************************************************
12118 : *
12119 : * CREATE DATABASE
12120 : *
12121 : *****************************************************************************/
12122 :
12123 : CreatedbStmt:
12124 : CREATE DATABASE name opt_with createdb_opt_list
12125 : {
12126 434 : CreatedbStmt *n = makeNode(CreatedbStmt);
12127 :
12128 434 : n->dbname = $3;
12129 434 : n->options = $5;
12130 434 : $$ = (Node *) n;
12131 : }
12132 : ;
12133 :
12134 : createdb_opt_list:
12135 352 : createdb_opt_items { $$ = $1; }
12136 120 : | /* EMPTY */ { $$ = NIL; }
12137 : ;
12138 :
12139 : createdb_opt_items:
12140 352 : createdb_opt_item { $$ = list_make1($1); }
12141 530 : | createdb_opt_items createdb_opt_item { $$ = lappend($1, $2); }
12142 : ;
12143 :
12144 : createdb_opt_item:
12145 : createdb_opt_name opt_equal NumericOnly
12146 : {
12147 140 : $$ = makeDefElem($1, $3, @1);
12148 : }
12149 : | createdb_opt_name opt_equal opt_boolean_or_string
12150 : {
12151 742 : $$ = makeDefElem($1, (Node *) makeString($3), @1);
12152 : }
12153 : | createdb_opt_name opt_equal DEFAULT
12154 : {
12155 0 : $$ = makeDefElem($1, NULL, @1);
12156 : }
12157 : ;
12158 :
12159 : /*
12160 : * Ideally we'd use ColId here, but that causes shift/reduce conflicts against
12161 : * the ALTER DATABASE SET/RESET syntaxes. Instead call out specific keywords
12162 : * we need, and allow IDENT so that database option names don't have to be
12163 : * parser keywords unless they are already keywords for other reasons.
12164 : *
12165 : * XXX this coding technique is fragile since if someone makes a formerly
12166 : * non-keyword option name into a keyword and forgets to add it here, the
12167 : * option will silently break. Best defense is to provide a regression test
12168 : * exercising every such option, at least at the syntax level.
12169 : */
12170 : createdb_opt_name:
12171 612 : IDENT { $$ = $1; }
12172 1 : | CONNECTION LIMIT { $$ = pstrdup("connection_limit"); }
12173 57 : | ENCODING { $$ = pstrdup($1); }
12174 0 : | LOCATION { $$ = pstrdup($1); }
12175 1 : | OWNER { $$ = pstrdup($1); }
12176 17 : | TABLESPACE { $$ = pstrdup($1); }
12177 194 : | TEMPLATE { $$ = pstrdup($1); }
12178 : ;
12179 :
12180 : /*
12181 : * Though the equals sign doesn't match other WITH options, pg_dump uses
12182 : * equals for backward compatibility, and it doesn't seem worth removing it.
12183 : */
12184 : opt_equal: '='
12185 : | /*EMPTY*/
12186 : ;
12187 :
12188 :
12189 : /*****************************************************************************
12190 : *
12191 : * ALTER DATABASE
12192 : *
12193 : *****************************************************************************/
12194 :
12195 : AlterDatabaseStmt:
12196 : ALTER DATABASE name WITH createdb_opt_list
12197 : {
12198 1 : AlterDatabaseStmt *n = makeNode(AlterDatabaseStmt);
12199 :
12200 1 : n->dbname = $3;
12201 1 : n->options = $5;
12202 1 : $$ = (Node *) n;
12203 : }
12204 : | ALTER DATABASE name createdb_opt_list
12205 : {
12206 37 : AlterDatabaseStmt *n = makeNode(AlterDatabaseStmt);
12207 :
12208 37 : n->dbname = $3;
12209 37 : n->options = $4;
12210 37 : $$ = (Node *) n;
12211 : }
12212 : | ALTER DATABASE name SET TABLESPACE name
12213 : {
12214 14 : AlterDatabaseStmt *n = makeNode(AlterDatabaseStmt);
12215 :
12216 14 : n->dbname = $3;
12217 14 : n->options = list_make1(makeDefElem("tablespace",
12218 : (Node *) makeString($6), @6));
12219 14 : $$ = (Node *) n;
12220 : }
12221 : | ALTER DATABASE name REFRESH COLLATION VERSION_P
12222 : {
12223 4 : AlterDatabaseRefreshCollStmt *n = makeNode(AlterDatabaseRefreshCollStmt);
12224 :
12225 4 : n->dbname = $3;
12226 4 : $$ = (Node *) n;
12227 : }
12228 : ;
12229 :
12230 : AlterDatabaseSetStmt:
12231 : ALTER DATABASE name SetResetClause
12232 : {
12233 657 : AlterDatabaseSetStmt *n = makeNode(AlterDatabaseSetStmt);
12234 :
12235 657 : n->dbname = $3;
12236 657 : n->setstmt = $4;
12237 657 : $$ = (Node *) n;
12238 : }
12239 : ;
12240 :
12241 :
12242 : /*****************************************************************************
12243 : *
12244 : * DROP DATABASE [ IF EXISTS ] dbname [ [ WITH ] ( options ) ]
12245 : *
12246 : * This is implicitly CASCADE, no need for drop behavior
12247 : *****************************************************************************/
12248 :
12249 : DropdbStmt: DROP DATABASE name
12250 : {
12251 55 : DropdbStmt *n = makeNode(DropdbStmt);
12252 :
12253 55 : n->dbname = $3;
12254 55 : n->missing_ok = false;
12255 55 : n->options = NULL;
12256 55 : $$ = (Node *) n;
12257 : }
12258 : | DROP DATABASE IF_P EXISTS name
12259 : {
12260 3 : DropdbStmt *n = makeNode(DropdbStmt);
12261 :
12262 3 : n->dbname = $5;
12263 3 : n->missing_ok = true;
12264 3 : n->options = NULL;
12265 3 : $$ = (Node *) n;
12266 : }
12267 : | DROP DATABASE name opt_with '(' drop_option_list ')'
12268 : {
12269 9 : DropdbStmt *n = makeNode(DropdbStmt);
12270 :
12271 9 : n->dbname = $3;
12272 9 : n->missing_ok = false;
12273 9 : n->options = $6;
12274 9 : $$ = (Node *) n;
12275 : }
12276 : | DROP DATABASE IF_P EXISTS name opt_with '(' drop_option_list ')'
12277 : {
12278 8 : DropdbStmt *n = makeNode(DropdbStmt);
12279 :
12280 8 : n->dbname = $5;
12281 8 : n->missing_ok = true;
12282 8 : n->options = $8;
12283 8 : $$ = (Node *) n;
12284 : }
12285 : ;
12286 :
12287 : drop_option_list:
12288 : drop_option
12289 : {
12290 17 : $$ = list_make1((Node *) $1);
12291 : }
12292 : | drop_option_list ',' drop_option
12293 : {
12294 0 : $$ = lappend($1, (Node *) $3);
12295 : }
12296 : ;
12297 :
12298 : /*
12299 : * Currently only the FORCE option is supported, but the syntax is designed
12300 : * to be extensible so that we can add more options in the future if required.
12301 : */
12302 : drop_option:
12303 : FORCE
12304 : {
12305 17 : $$ = makeDefElem("force", NULL, @1);
12306 : }
12307 : ;
12308 :
12309 : /*****************************************************************************
12310 : *
12311 : * ALTER COLLATION
12312 : *
12313 : *****************************************************************************/
12314 :
12315 : AlterCollationStmt: ALTER COLLATION any_name REFRESH VERSION_P
12316 : {
12317 4 : AlterCollationStmt *n = makeNode(AlterCollationStmt);
12318 :
12319 4 : n->collname = $3;
12320 4 : $$ = (Node *) n;
12321 : }
12322 : ;
12323 :
12324 :
12325 : /*****************************************************************************
12326 : *
12327 : * ALTER SYSTEM
12328 : *
12329 : * This is used to change configuration parameters persistently.
12330 : *****************************************************************************/
12331 :
12332 : AlterSystemStmt:
12333 : ALTER SYSTEM_P SET generic_set
12334 : {
12335 81 : AlterSystemStmt *n = makeNode(AlterSystemStmt);
12336 :
12337 81 : n->setstmt = $4;
12338 81 : $$ = (Node *) n;
12339 : }
12340 : | ALTER SYSTEM_P RESET generic_reset
12341 : {
12342 29 : AlterSystemStmt *n = makeNode(AlterSystemStmt);
12343 :
12344 29 : n->setstmt = $4;
12345 29 : $$ = (Node *) n;
12346 : }
12347 : ;
12348 :
12349 :
12350 : /*****************************************************************************
12351 : *
12352 : * Manipulate a domain
12353 : *
12354 : *****************************************************************************/
12355 :
12356 : CreateDomainStmt:
12357 : CREATE DOMAIN_P any_name opt_as Typename ColQualList
12358 : {
12359 938 : CreateDomainStmt *n = makeNode(CreateDomainStmt);
12360 :
12361 938 : n->domainname = $3;
12362 938 : n->typeName = $5;
12363 938 : SplitColQualList($6, &n->constraints, &n->collClause,
12364 : yyscanner);
12365 938 : $$ = (Node *) n;
12366 : }
12367 : ;
12368 :
12369 : AlterDomainStmt:
12370 : /* ALTER DOMAIN <domain> {SET DEFAULT <expr>|DROP DEFAULT} */
12371 : ALTER DOMAIN_P any_name alter_column_default
12372 : {
12373 9 : AlterDomainStmt *n = makeNode(AlterDomainStmt);
12374 :
12375 9 : n->subtype = AD_AlterDefault;
12376 9 : n->typeName = $3;
12377 9 : n->def = $4;
12378 9 : $$ = (Node *) n;
12379 : }
12380 : /* ALTER DOMAIN <domain> DROP NOT NULL */
12381 : | ALTER DOMAIN_P any_name DROP NOT NULL_P
12382 : {
12383 8 : AlterDomainStmt *n = makeNode(AlterDomainStmt);
12384 :
12385 8 : n->subtype = AD_DropNotNull;
12386 8 : n->typeName = $3;
12387 8 : $$ = (Node *) n;
12388 : }
12389 : /* ALTER DOMAIN <domain> SET NOT NULL */
12390 : | ALTER DOMAIN_P any_name SET NOT NULL_P
12391 : {
12392 16 : AlterDomainStmt *n = makeNode(AlterDomainStmt);
12393 :
12394 16 : n->subtype = AD_SetNotNull;
12395 16 : n->typeName = $3;
12396 16 : $$ = (Node *) n;
12397 : }
12398 : /* ALTER DOMAIN <domain> ADD CONSTRAINT ... */
12399 : | ALTER DOMAIN_P any_name ADD_P DomainConstraint
12400 : {
12401 120 : AlterDomainStmt *n = makeNode(AlterDomainStmt);
12402 :
12403 120 : n->subtype = AD_AddConstraint;
12404 120 : n->typeName = $3;
12405 120 : n->def = $5;
12406 120 : $$ = (Node *) n;
12407 : }
12408 : /* ALTER DOMAIN <domain> DROP CONSTRAINT <name> [RESTRICT|CASCADE] */
12409 : | ALTER DOMAIN_P any_name DROP CONSTRAINT name opt_drop_behavior
12410 : {
12411 36 : AlterDomainStmt *n = makeNode(AlterDomainStmt);
12412 :
12413 36 : n->subtype = AD_DropConstraint;
12414 36 : n->typeName = $3;
12415 36 : n->name = $6;
12416 36 : n->behavior = $7;
12417 36 : n->missing_ok = false;
12418 36 : $$ = (Node *) n;
12419 : }
12420 : /* ALTER DOMAIN <domain> DROP CONSTRAINT IF EXISTS <name> [RESTRICT|CASCADE] */
12421 : | ALTER DOMAIN_P any_name DROP CONSTRAINT IF_P EXISTS name opt_drop_behavior
12422 : {
12423 4 : AlterDomainStmt *n = makeNode(AlterDomainStmt);
12424 :
12425 4 : n->subtype = AD_DropConstraint;
12426 4 : n->typeName = $3;
12427 4 : n->name = $8;
12428 4 : n->behavior = $9;
12429 4 : n->missing_ok = true;
12430 4 : $$ = (Node *) n;
12431 : }
12432 : /* ALTER DOMAIN <domain> VALIDATE CONSTRAINT <name> */
12433 : | ALTER DOMAIN_P any_name VALIDATE CONSTRAINT name
12434 : {
12435 8 : AlterDomainStmt *n = makeNode(AlterDomainStmt);
12436 :
12437 8 : n->subtype = AD_ValidateConstraint;
12438 8 : n->typeName = $3;
12439 8 : n->name = $6;
12440 8 : $$ = (Node *) n;
12441 : }
12442 : ;
12443 :
12444 : opt_as: AS
12445 : | /* EMPTY */
12446 : ;
12447 :
12448 :
12449 : /*****************************************************************************
12450 : *
12451 : * Manipulate a text search dictionary or configuration
12452 : *
12453 : *****************************************************************************/
12454 :
12455 : AlterTSDictionaryStmt:
12456 : ALTER TEXT_P SEARCH DICTIONARY any_name definition
12457 : {
12458 23 : AlterTSDictionaryStmt *n = makeNode(AlterTSDictionaryStmt);
12459 :
12460 23 : n->dictname = $5;
12461 23 : n->options = $6;
12462 23 : $$ = (Node *) n;
12463 : }
12464 : ;
12465 :
12466 : AlterTSConfigurationStmt:
12467 : ALTER TEXT_P SEARCH CONFIGURATION any_name ADD_P MAPPING FOR name_list any_with any_name_list
12468 : {
12469 4642 : AlterTSConfigurationStmt *n = makeNode(AlterTSConfigurationStmt);
12470 :
12471 4642 : n->kind = ALTER_TSCONFIG_ADD_MAPPING;
12472 4642 : n->cfgname = $5;
12473 4642 : n->tokentype = $9;
12474 4642 : n->dicts = $11;
12475 4642 : n->override = false;
12476 4642 : n->replace = false;
12477 4642 : $$ = (Node *) n;
12478 : }
12479 : | ALTER TEXT_P SEARCH CONFIGURATION any_name ALTER MAPPING FOR name_list any_with any_name_list
12480 : {
12481 17 : AlterTSConfigurationStmt *n = makeNode(AlterTSConfigurationStmt);
12482 :
12483 17 : n->kind = ALTER_TSCONFIG_ALTER_MAPPING_FOR_TOKEN;
12484 17 : n->cfgname = $5;
12485 17 : n->tokentype = $9;
12486 17 : n->dicts = $11;
12487 17 : n->override = true;
12488 17 : n->replace = false;
12489 17 : $$ = (Node *) n;
12490 : }
12491 : | ALTER TEXT_P SEARCH CONFIGURATION any_name ALTER MAPPING REPLACE any_name any_with any_name
12492 : {
12493 12 : AlterTSConfigurationStmt *n = makeNode(AlterTSConfigurationStmt);
12494 :
12495 12 : n->kind = ALTER_TSCONFIG_REPLACE_DICT;
12496 12 : n->cfgname = $5;
12497 12 : n->tokentype = NIL;
12498 12 : n->dicts = list_make2($9,$11);
12499 12 : n->override = false;
12500 12 : n->replace = true;
12501 12 : $$ = (Node *) n;
12502 : }
12503 : | ALTER TEXT_P SEARCH CONFIGURATION any_name ALTER MAPPING FOR name_list REPLACE any_name any_with any_name
12504 : {
12505 0 : AlterTSConfigurationStmt *n = makeNode(AlterTSConfigurationStmt);
12506 :
12507 0 : n->kind = ALTER_TSCONFIG_REPLACE_DICT_FOR_TOKEN;
12508 0 : n->cfgname = $5;
12509 0 : n->tokentype = $9;
12510 0 : n->dicts = list_make2($11,$13);
12511 0 : n->override = false;
12512 0 : n->replace = true;
12513 0 : $$ = (Node *) n;
12514 : }
12515 : | ALTER TEXT_P SEARCH CONFIGURATION any_name DROP MAPPING FOR name_list
12516 : {
12517 13 : AlterTSConfigurationStmt *n = makeNode(AlterTSConfigurationStmt);
12518 :
12519 13 : n->kind = ALTER_TSCONFIG_DROP_MAPPING;
12520 13 : n->cfgname = $5;
12521 13 : n->tokentype = $9;
12522 13 : n->missing_ok = false;
12523 13 : $$ = (Node *) n;
12524 : }
12525 : | ALTER TEXT_P SEARCH CONFIGURATION any_name DROP MAPPING IF_P EXISTS FOR name_list
12526 : {
12527 8 : AlterTSConfigurationStmt *n = makeNode(AlterTSConfigurationStmt);
12528 :
12529 8 : n->kind = ALTER_TSCONFIG_DROP_MAPPING;
12530 8 : n->cfgname = $5;
12531 8 : n->tokentype = $11;
12532 8 : n->missing_ok = true;
12533 8 : $$ = (Node *) n;
12534 : }
12535 : ;
12536 :
12537 : /* Use this if TIME or ORDINALITY after WITH should be taken as an identifier */
12538 : any_with: WITH
12539 : | WITH_LA
12540 : ;
12541 :
12542 :
12543 : /*****************************************************************************
12544 : *
12545 : * Manipulate a conversion
12546 : *
12547 : * CREATE [DEFAULT] CONVERSION <conversion_name>
12548 : * FOR <encoding_name> TO <encoding_name> FROM <func_name>
12549 : *
12550 : *****************************************************************************/
12551 :
12552 : CreateConversionStmt:
12553 : CREATE opt_default CONVERSION_P any_name FOR Sconst
12554 : TO Sconst FROM any_name
12555 : {
12556 42 : CreateConversionStmt *n = makeNode(CreateConversionStmt);
12557 :
12558 42 : n->conversion_name = $4;
12559 42 : n->for_encoding_name = $6;
12560 42 : n->to_encoding_name = $8;
12561 42 : n->func_name = $10;
12562 42 : n->def = $2;
12563 42 : $$ = (Node *) n;
12564 : }
12565 : ;
12566 :
12567 : /*****************************************************************************
12568 : *
12569 : * QUERY:
12570 : * REPACK [ (options) ] [ <qualified_name> [ <name_list> ] [ USING INDEX <index_name> ] ]
12571 : *
12572 : * obsolete variants:
12573 : * CLUSTER (options) [ <qualified_name> [ USING <index_name> ] ]
12574 : * CLUSTER [VERBOSE] [ <qualified_name> [ USING <index_name> ] ]
12575 : * CLUSTER [VERBOSE] <index_name> ON <qualified_name> (for pre-8.3)
12576 : *
12577 : *****************************************************************************/
12578 :
12579 : RepackStmt:
12580 : REPACK opt_utility_option_list vacuum_relation USING INDEX name
12581 : {
12582 8 : RepackStmt *n = makeNode(RepackStmt);
12583 :
12584 8 : n->command = REPACK_COMMAND_REPACK;
12585 8 : n->relation = (VacuumRelation *) $3;
12586 8 : n->indexname = $6;
12587 8 : n->usingindex = true;
12588 8 : n->params = $2;
12589 8 : $$ = (Node *) n;
12590 : }
12591 : | REPACK opt_utility_option_list vacuum_relation opt_usingindex
12592 : {
12593 20 : RepackStmt *n = makeNode(RepackStmt);
12594 :
12595 20 : n->command = REPACK_COMMAND_REPACK;
12596 20 : n->relation = (VacuumRelation *) $3;
12597 20 : n->indexname = NULL;
12598 20 : n->usingindex = $4;
12599 20 : n->params = $2;
12600 20 : $$ = (Node *) n;
12601 : }
12602 : | REPACK opt_utility_option_list opt_usingindex
12603 : {
12604 4 : RepackStmt *n = makeNode(RepackStmt);
12605 :
12606 4 : n->command = REPACK_COMMAND_REPACK;
12607 4 : n->relation = NULL;
12608 4 : n->indexname = NULL;
12609 4 : n->usingindex = $3;
12610 4 : n->params = $2;
12611 4 : $$ = (Node *) n;
12612 : }
12613 : | CLUSTER '(' utility_option_list ')' qualified_name cluster_index_specification
12614 : {
12615 0 : RepackStmt *n = makeNode(RepackStmt);
12616 :
12617 0 : n->command = REPACK_COMMAND_CLUSTER;
12618 0 : n->relation = makeNode(VacuumRelation);
12619 0 : n->relation->relation = $5;
12620 0 : n->indexname = $6;
12621 0 : n->usingindex = true;
12622 0 : n->params = $3;
12623 0 : $$ = (Node *) n;
12624 : }
12625 : | CLUSTER opt_utility_option_list
12626 : {
12627 9 : RepackStmt *n = makeNode(RepackStmt);
12628 :
12629 9 : n->command = REPACK_COMMAND_CLUSTER;
12630 9 : n->relation = NULL;
12631 9 : n->indexname = NULL;
12632 9 : n->usingindex = true;
12633 9 : n->params = $2;
12634 9 : $$ = (Node *) n;
12635 : }
12636 : /* unparenthesized VERBOSE kept for pre-14 compatibility */
12637 : | CLUSTER opt_verbose qualified_name cluster_index_specification
12638 : {
12639 123 : RepackStmt *n = makeNode(RepackStmt);
12640 :
12641 123 : n->command = REPACK_COMMAND_CLUSTER;
12642 123 : n->relation = makeNode(VacuumRelation);
12643 123 : n->relation->relation = $3;
12644 123 : n->indexname = $4;
12645 123 : n->usingindex = true;
12646 123 : if ($2)
12647 0 : n->params = list_make1(makeDefElem("verbose", NULL, @2));
12648 123 : $$ = (Node *) n;
12649 : }
12650 : /* unparenthesized VERBOSE kept for pre-17 compatibility */
12651 : | CLUSTER VERBOSE
12652 : {
12653 2 : RepackStmt *n = makeNode(RepackStmt);
12654 :
12655 2 : n->command = REPACK_COMMAND_CLUSTER;
12656 2 : n->relation = NULL;
12657 2 : n->indexname = NULL;
12658 2 : n->usingindex = true;
12659 2 : n->params = list_make1(makeDefElem("verbose", NULL, @2));
12660 2 : $$ = (Node *) n;
12661 : }
12662 : /* kept for pre-8.3 compatibility */
12663 : | CLUSTER opt_verbose name ON qualified_name
12664 : {
12665 13 : RepackStmt *n = makeNode(RepackStmt);
12666 :
12667 13 : n->command = REPACK_COMMAND_CLUSTER;
12668 13 : n->relation = makeNode(VacuumRelation);
12669 13 : n->relation->relation = $5;
12670 13 : n->indexname = $3;
12671 13 : n->usingindex = true;
12672 13 : if ($2)
12673 0 : n->params = list_make1(makeDefElem("verbose", NULL, @2));
12674 13 : $$ = (Node *) n;
12675 : }
12676 : ;
12677 :
12678 : cluster_index_specification:
12679 99 : USING name { $$ = $2; }
12680 24 : | /*EMPTY*/ { $$ = NULL; }
12681 : ;
12682 :
12683 :
12684 : /*****************************************************************************
12685 : *
12686 : * QUERY:
12687 : * VACUUM
12688 : * ANALYZE
12689 : *
12690 : *****************************************************************************/
12691 :
12692 : VacuumStmt: VACUUM opt_full opt_freeze opt_verbose opt_analyze opt_vacuum_relation_list
12693 : {
12694 760 : VacuumStmt *n = makeNode(VacuumStmt);
12695 :
12696 760 : n->options = NIL;
12697 760 : if ($2)
12698 89 : n->options = lappend(n->options,
12699 89 : makeDefElem("full", NULL, @2));
12700 760 : if ($3)
12701 84 : n->options = lappend(n->options,
12702 84 : makeDefElem("freeze", NULL, @3));
12703 760 : if ($4)
12704 9 : n->options = lappend(n->options,
12705 9 : makeDefElem("verbose", NULL, @4));
12706 760 : if ($5)
12707 206 : n->options = lappend(n->options,
12708 206 : makeDefElem("analyze", NULL, @5));
12709 760 : n->rels = $6;
12710 760 : n->is_vacuumcmd = true;
12711 760 : $$ = (Node *) n;
12712 : }
12713 : | VACUUM '(' utility_option_list ')' opt_vacuum_relation_list
12714 : {
12715 5030 : VacuumStmt *n = makeNode(VacuumStmt);
12716 :
12717 5030 : n->options = $3;
12718 5030 : n->rels = $5;
12719 5030 : n->is_vacuumcmd = true;
12720 5030 : $$ = (Node *) n;
12721 : }
12722 : ;
12723 :
12724 : AnalyzeStmt: analyze_keyword opt_utility_option_list opt_vacuum_relation_list
12725 : {
12726 2872 : VacuumStmt *n = makeNode(VacuumStmt);
12727 :
12728 2872 : n->options = $2;
12729 2872 : n->rels = $3;
12730 2872 : n->is_vacuumcmd = false;
12731 2872 : $$ = (Node *) n;
12732 : }
12733 : | analyze_keyword VERBOSE opt_vacuum_relation_list
12734 : {
12735 0 : VacuumStmt *n = makeNode(VacuumStmt);
12736 :
12737 0 : n->options = list_make1(makeDefElem("verbose", NULL, @2));
12738 0 : n->rels = $3;
12739 0 : n->is_vacuumcmd = false;
12740 0 : $$ = (Node *) n;
12741 : }
12742 : ;
12743 :
12744 : analyze_keyword:
12745 : ANALYZE
12746 : | ANALYSE /* British */
12747 : ;
12748 :
12749 : opt_analyze:
12750 206 : analyze_keyword { $$ = true; }
12751 554 : | /*EMPTY*/ { $$ = false; }
12752 : ;
12753 :
12754 : opt_verbose:
12755 9 : VERBOSE { $$ = true; }
12756 2431 : | /*EMPTY*/ { $$ = false; }
12757 : ;
12758 :
12759 89 : opt_full: FULL { $$ = true; }
12760 671 : | /*EMPTY*/ { $$ = false; }
12761 : ;
12762 :
12763 84 : opt_freeze: FREEZE { $$ = true; }
12764 676 : | /*EMPTY*/ { $$ = false; }
12765 : ;
12766 :
12767 : opt_name_list:
12768 1783 : '(' name_list ')' { $$ = $2; }
12769 10452 : | /*EMPTY*/ { $$ = NIL; }
12770 : ;
12771 :
12772 : vacuum_relation:
12773 : relation_expr opt_name_list
12774 : {
12775 8615 : $$ = (Node *) makeVacuumRelation($1, InvalidOid, $2);
12776 : }
12777 : ;
12778 :
12779 : vacuum_relation_list:
12780 : vacuum_relation
12781 8466 : { $$ = list_make1($1); }
12782 : | vacuum_relation_list ',' vacuum_relation
12783 121 : { $$ = lappend($1, $3); }
12784 : ;
12785 :
12786 : opt_vacuum_relation_list:
12787 8466 : vacuum_relation_list { $$ = $1; }
12788 196 : | /*EMPTY*/ { $$ = NIL; }
12789 : ;
12790 :
12791 :
12792 : /*****************************************************************************
12793 : *
12794 : * QUERY:
12795 : * EXPLAIN [ANALYZE] [VERBOSE] query
12796 : * EXPLAIN ( options ) query
12797 : *
12798 : *****************************************************************************/
12799 :
12800 : ExplainStmt:
12801 : EXPLAIN ExplainableStmt
12802 : {
12803 4751 : ExplainStmt *n = makeNode(ExplainStmt);
12804 :
12805 4751 : n->query = $2;
12806 4751 : n->options = NIL;
12807 4751 : $$ = (Node *) n;
12808 : }
12809 : | EXPLAIN analyze_keyword opt_verbose ExplainableStmt
12810 : {
12811 1544 : ExplainStmt *n = makeNode(ExplainStmt);
12812 :
12813 1544 : n->query = $4;
12814 1544 : n->options = list_make1(makeDefElem("analyze", NULL, @2));
12815 1544 : if ($3)
12816 0 : n->options = lappend(n->options,
12817 0 : makeDefElem("verbose", NULL, @3));
12818 1544 : $$ = (Node *) n;
12819 : }
12820 : | EXPLAIN VERBOSE ExplainableStmt
12821 : {
12822 8 : ExplainStmt *n = makeNode(ExplainStmt);
12823 :
12824 8 : n->query = $3;
12825 8 : n->options = list_make1(makeDefElem("verbose", NULL, @2));
12826 8 : $$ = (Node *) n;
12827 : }
12828 : | EXPLAIN '(' utility_option_list ')' ExplainableStmt
12829 : {
12830 9994 : ExplainStmt *n = makeNode(ExplainStmt);
12831 :
12832 9994 : n->query = $5;
12833 9994 : n->options = $3;
12834 9994 : $$ = (Node *) n;
12835 : }
12836 : ;
12837 :
12838 : ExplainableStmt:
12839 : SelectStmt
12840 : | InsertStmt
12841 : | UpdateStmt
12842 : | DeleteStmt
12843 : | MergeStmt
12844 : | DeclareCursorStmt
12845 : | CreateAsStmt
12846 : | CreateMatViewStmt
12847 : | RefreshMatViewStmt
12848 : | ExecuteStmt /* by default all are $$=$1 */
12849 : ;
12850 :
12851 : /*****************************************************************************
12852 : *
12853 : * QUERY:
12854 : * PREPARE <plan_name> [(args, ...)] AS <query>
12855 : *
12856 : *****************************************************************************/
12857 :
12858 : PrepareStmt: PREPARE name prep_type_clause AS PreparableStmt
12859 : {
12860 1185 : PrepareStmt *n = makeNode(PrepareStmt);
12861 :
12862 1185 : n->name = $2;
12863 1185 : n->argtypes = $3;
12864 1185 : n->query = $5;
12865 1185 : $$ = (Node *) n;
12866 : }
12867 : ;
12868 :
12869 960 : prep_type_clause: '(' type_list ')' { $$ = $2; }
12870 237 : | /* EMPTY */ { $$ = NIL; }
12871 : ;
12872 :
12873 : PreparableStmt:
12874 : SelectStmt
12875 : | InsertStmt
12876 : | UpdateStmt
12877 : | DeleteStmt
12878 : | MergeStmt /* by default all are $$=$1 */
12879 : ;
12880 :
12881 : /*****************************************************************************
12882 : *
12883 : * EXECUTE <plan_name> [(params, ...)]
12884 : * CREATE TABLE <name> AS EXECUTE <plan_name> [(params, ...)]
12885 : *
12886 : *****************************************************************************/
12887 :
12888 : ExecuteStmt: EXECUTE name execute_param_clause
12889 : {
12890 8862 : ExecuteStmt *n = makeNode(ExecuteStmt);
12891 :
12892 8862 : n->name = $2;
12893 8862 : n->params = $3;
12894 8862 : $$ = (Node *) n;
12895 : }
12896 : | CREATE OptTemp TABLE create_as_target AS
12897 : EXECUTE name execute_param_clause opt_with_data
12898 : {
12899 50 : CreateTableAsStmt *ctas = makeNode(CreateTableAsStmt);
12900 50 : ExecuteStmt *n = makeNode(ExecuteStmt);
12901 :
12902 50 : n->name = $7;
12903 50 : n->params = $8;
12904 50 : ctas->query = (Node *) n;
12905 50 : ctas->into = $4;
12906 50 : ctas->objtype = OBJECT_TABLE;
12907 50 : ctas->is_select_into = false;
12908 50 : ctas->if_not_exists = false;
12909 : /* cram additional flags into the IntoClause */
12910 50 : $4->rel->relpersistence = $2;
12911 50 : $4->skipData = !($9);
12912 50 : $$ = (Node *) ctas;
12913 : }
12914 : | CREATE OptTemp TABLE IF_P NOT EXISTS create_as_target AS
12915 : EXECUTE name execute_param_clause opt_with_data
12916 : {
12917 8 : CreateTableAsStmt *ctas = makeNode(CreateTableAsStmt);
12918 8 : ExecuteStmt *n = makeNode(ExecuteStmt);
12919 :
12920 8 : n->name = $10;
12921 8 : n->params = $11;
12922 8 : ctas->query = (Node *) n;
12923 8 : ctas->into = $7;
12924 8 : ctas->objtype = OBJECT_TABLE;
12925 8 : ctas->is_select_into = false;
12926 8 : ctas->if_not_exists = true;
12927 : /* cram additional flags into the IntoClause */
12928 8 : $7->rel->relpersistence = $2;
12929 8 : $7->skipData = !($12);
12930 8 : $$ = (Node *) ctas;
12931 : }
12932 : ;
12933 :
12934 7988 : execute_param_clause: '(' expr_list ')' { $$ = $2; }
12935 932 : | /* EMPTY */ { $$ = NIL; }
12936 : ;
12937 :
12938 : /*****************************************************************************
12939 : *
12940 : * QUERY:
12941 : * DEALLOCATE [PREPARE] <plan_name>
12942 : *
12943 : *****************************************************************************/
12944 :
12945 : DeallocateStmt: DEALLOCATE name
12946 : {
12947 2043 : DeallocateStmt *n = makeNode(DeallocateStmt);
12948 :
12949 2043 : n->name = $2;
12950 2043 : n->isall = false;
12951 2043 : n->location = @2;
12952 2043 : $$ = (Node *) n;
12953 : }
12954 : | DEALLOCATE PREPARE name
12955 : {
12956 13 : DeallocateStmt *n = makeNode(DeallocateStmt);
12957 :
12958 13 : n->name = $3;
12959 13 : n->isall = false;
12960 13 : n->location = @3;
12961 13 : $$ = (Node *) n;
12962 : }
12963 : | DEALLOCATE ALL
12964 : {
12965 36 : DeallocateStmt *n = makeNode(DeallocateStmt);
12966 :
12967 36 : n->name = NULL;
12968 36 : n->isall = true;
12969 36 : n->location = -1;
12970 36 : $$ = (Node *) n;
12971 : }
12972 : | DEALLOCATE PREPARE ALL
12973 : {
12974 1 : DeallocateStmt *n = makeNode(DeallocateStmt);
12975 :
12976 1 : n->name = NULL;
12977 1 : n->isall = true;
12978 1 : n->location = -1;
12979 1 : $$ = (Node *) n;
12980 : }
12981 : ;
12982 :
12983 : /*****************************************************************************
12984 : *
12985 : * QUERY:
12986 : * INSERT STATEMENTS
12987 : *
12988 : *****************************************************************************/
12989 :
12990 : InsertStmt:
12991 : opt_with_clause INSERT INTO insert_target insert_rest
12992 : opt_on_conflict returning_clause
12993 : {
12994 44333 : $5->relation = $4;
12995 44333 : $5->onConflictClause = $6;
12996 44333 : $5->returningClause = $7;
12997 44333 : $5->withClause = $1;
12998 44333 : $$ = (Node *) $5;
12999 : }
13000 : ;
13001 :
13002 : /*
13003 : * Can't easily make AS optional here, because VALUES in insert_rest would
13004 : * have a shift/reduce conflict with VALUES as an optional alias. We could
13005 : * easily allow unreserved_keywords as optional aliases, but that'd be an odd
13006 : * divergence from other places. So just require AS for now.
13007 : */
13008 : insert_target:
13009 : qualified_name
13010 : {
13011 44226 : $$ = $1;
13012 : }
13013 : | qualified_name AS ColId
13014 : {
13015 111 : $1->alias = makeAlias($3, NIL);
13016 111 : $$ = $1;
13017 : }
13018 : ;
13019 :
13020 : insert_rest:
13021 : SelectStmt
13022 : {
13023 29968 : $$ = makeNode(InsertStmt);
13024 29968 : $$->cols = NIL;
13025 29968 : $$->selectStmt = $1;
13026 : }
13027 : | OVERRIDING override_kind VALUE_P SelectStmt
13028 : {
13029 64 : $$ = makeNode(InsertStmt);
13030 64 : $$->cols = NIL;
13031 64 : $$->override = $2;
13032 64 : $$->selectStmt = $4;
13033 : }
13034 : | '(' insert_column_list ')' SelectStmt
13035 : {
13036 8756 : $$ = makeNode(InsertStmt);
13037 8756 : $$->cols = $2;
13038 8756 : $$->selectStmt = $4;
13039 : }
13040 : | '(' insert_column_list ')' OVERRIDING override_kind VALUE_P SelectStmt
13041 : {
13042 0 : $$ = makeNode(InsertStmt);
13043 0 : $$->cols = $2;
13044 0 : $$->override = $5;
13045 0 : $$->selectStmt = $7;
13046 : }
13047 : | DEFAULT VALUES
13048 : {
13049 5549 : $$ = makeNode(InsertStmt);
13050 5549 : $$->cols = NIL;
13051 5549 : $$->selectStmt = NULL;
13052 : }
13053 : ;
13054 :
13055 : override_kind:
13056 44 : USER { $$ = OVERRIDING_USER_VALUE; }
13057 40 : | SYSTEM_P { $$ = OVERRIDING_SYSTEM_VALUE; }
13058 : ;
13059 :
13060 : insert_column_list:
13061 : insert_column_item
13062 8975 : { $$ = list_make1($1); }
13063 : | insert_column_list ',' insert_column_item
13064 9506 : { $$ = lappend($1, $3); }
13065 : ;
13066 :
13067 : insert_column_item:
13068 : ColId opt_indirection
13069 : {
13070 18481 : $$ = makeNode(ResTarget);
13071 18481 : $$->name = $1;
13072 18481 : $$->indirection = check_indirection($2, yyscanner);
13073 18481 : $$->val = NULL;
13074 18481 : $$->location = @1;
13075 : }
13076 : ;
13077 :
13078 : opt_on_conflict:
13079 : ON CONFLICT opt_conf_expr DO SELECT opt_for_locking_strength where_clause
13080 : {
13081 240 : $$ = makeNode(OnConflictClause);
13082 240 : $$->action = ONCONFLICT_SELECT;
13083 240 : $$->infer = $3;
13084 240 : $$->targetList = NIL;
13085 240 : $$->lockStrength = $6;
13086 240 : $$->whereClause = $7;
13087 240 : $$->location = @1;
13088 : }
13089 : |
13090 : ON CONFLICT opt_conf_expr DO UPDATE SET set_clause_list where_clause
13091 : {
13092 914 : $$ = makeNode(OnConflictClause);
13093 914 : $$->action = ONCONFLICT_UPDATE;
13094 914 : $$->infer = $3;
13095 914 : $$->targetList = $7;
13096 914 : $$->lockStrength = LCS_NONE;
13097 914 : $$->whereClause = $8;
13098 914 : $$->location = @1;
13099 : }
13100 : |
13101 : ON CONFLICT opt_conf_expr DO NOTHING
13102 : {
13103 386 : $$ = makeNode(OnConflictClause);
13104 386 : $$->action = ONCONFLICT_NOTHING;
13105 386 : $$->infer = $3;
13106 386 : $$->targetList = NIL;
13107 386 : $$->lockStrength = LCS_NONE;
13108 386 : $$->whereClause = NULL;
13109 386 : $$->location = @1;
13110 : }
13111 : | /*EMPTY*/
13112 : {
13113 42797 : $$ = NULL;
13114 : }
13115 : ;
13116 :
13117 : opt_conf_expr:
13118 : '(' index_params ')' where_clause
13119 : {
13120 1250 : $$ = makeNode(InferClause);
13121 1250 : $$->indexElems = $2;
13122 1250 : $$->whereClause = $4;
13123 1250 : $$->conname = NULL;
13124 1250 : $$->location = @1;
13125 : }
13126 : |
13127 : ON CONSTRAINT name
13128 : {
13129 138 : $$ = makeNode(InferClause);
13130 138 : $$->indexElems = NIL;
13131 138 : $$->whereClause = NULL;
13132 138 : $$->conname = $3;
13133 138 : $$->location = @1;
13134 : }
13135 : | /*EMPTY*/
13136 : {
13137 152 : $$ = NULL;
13138 : }
13139 : ;
13140 :
13141 : returning_clause:
13142 : RETURNING returning_with_clause target_list
13143 : {
13144 2297 : ReturningClause *n = makeNode(ReturningClause);
13145 :
13146 2297 : n->options = $2;
13147 2297 : n->exprs = $3;
13148 2297 : $$ = n;
13149 : }
13150 : | /* EMPTY */
13151 : {
13152 55141 : $$ = NULL;
13153 : }
13154 : ;
13155 :
13156 : returning_with_clause:
13157 48 : WITH '(' returning_options ')' { $$ = $3; }
13158 2249 : | /* EMPTY */ { $$ = NIL; }
13159 : ;
13160 :
13161 : returning_options:
13162 48 : returning_option { $$ = list_make1($1); }
13163 36 : | returning_options ',' returning_option { $$ = lappend($1, $3); }
13164 : ;
13165 :
13166 : returning_option:
13167 : returning_option_kind AS ColId
13168 : {
13169 84 : ReturningOption *n = makeNode(ReturningOption);
13170 :
13171 84 : n->option = $1;
13172 84 : n->value = $3;
13173 84 : n->location = @1;
13174 84 : $$ = (Node *) n;
13175 : }
13176 : ;
13177 :
13178 : returning_option_kind:
13179 36 : OLD { $$ = RETURNING_OPTION_OLD; }
13180 48 : | NEW { $$ = RETURNING_OPTION_NEW; }
13181 : ;
13182 :
13183 :
13184 : /*****************************************************************************
13185 : *
13186 : * QUERY:
13187 : * DELETE STATEMENTS
13188 : *
13189 : *****************************************************************************/
13190 :
13191 : DeleteStmt: opt_with_clause DELETE_P FROM relation_expr_opt_alias
13192 : using_clause where_or_current_clause returning_clause
13193 : {
13194 2943 : DeleteStmt *n = makeNode(DeleteStmt);
13195 :
13196 2943 : n->relation = $4;
13197 2943 : n->usingClause = $5;
13198 2943 : n->whereClause = $6;
13199 2943 : n->returningClause = $7;
13200 2943 : n->withClause = $1;
13201 2943 : $$ = (Node *) n;
13202 : }
13203 : ;
13204 :
13205 : using_clause:
13206 68 : USING from_list { $$ = $2; }
13207 2875 : | /*EMPTY*/ { $$ = NIL; }
13208 : ;
13209 :
13210 :
13211 : /*****************************************************************************
13212 : *
13213 : * QUERY:
13214 : * LOCK TABLE
13215 : *
13216 : *****************************************************************************/
13217 :
13218 : LockStmt: LOCK_P opt_table relation_expr_list opt_lock opt_nowait
13219 : {
13220 640 : LockStmt *n = makeNode(LockStmt);
13221 :
13222 640 : n->relations = $3;
13223 640 : n->mode = $4;
13224 640 : n->nowait = $5;
13225 640 : $$ = (Node *) n;
13226 : }
13227 : ;
13228 :
13229 575 : opt_lock: IN_P lock_type MODE { $$ = $2; }
13230 65 : | /*EMPTY*/ { $$ = AccessExclusiveLock; }
13231 : ;
13232 :
13233 288 : lock_type: ACCESS SHARE { $$ = AccessShareLock; }
13234 9 : | ROW SHARE { $$ = RowShareLock; }
13235 52 : | ROW EXCLUSIVE { $$ = RowExclusiveLock; }
13236 35 : | SHARE UPDATE EXCLUSIVE { $$ = ShareUpdateExclusiveLock; }
13237 42 : | SHARE { $$ = ShareLock; }
13238 9 : | SHARE ROW EXCLUSIVE { $$ = ShareRowExclusiveLock; }
13239 61 : | EXCLUSIVE { $$ = ExclusiveLock; }
13240 79 : | ACCESS EXCLUSIVE { $$ = AccessExclusiveLock; }
13241 : ;
13242 :
13243 102 : opt_nowait: NOWAIT { $$ = true; }
13244 553 : | /*EMPTY*/ { $$ = false; }
13245 : ;
13246 :
13247 : opt_nowait_or_skip:
13248 29 : NOWAIT { $$ = LockWaitError; }
13249 96 : | SKIP LOCKED { $$ = LockWaitSkip; }
13250 5805 : | /*EMPTY*/ { $$ = LockWaitBlock; }
13251 : ;
13252 :
13253 :
13254 : /*****************************************************************************
13255 : *
13256 : * QUERY:
13257 : * UpdateStmt (UPDATE)
13258 : *
13259 : *****************************************************************************/
13260 :
13261 : UpdateStmt: opt_with_clause UPDATE relation_expr_opt_alias
13262 : SET set_clause_list
13263 : from_clause
13264 : where_or_current_clause
13265 : returning_clause
13266 : {
13267 8740 : UpdateStmt *n = makeNode(UpdateStmt);
13268 :
13269 8740 : n->relation = $3;
13270 8740 : n->targetList = $5;
13271 8740 : n->fromClause = $6;
13272 8740 : n->whereClause = $7;
13273 8740 : n->returningClause = $8;
13274 8740 : n->withClause = $1;
13275 8740 : $$ = (Node *) n;
13276 : }
13277 : ;
13278 :
13279 : set_clause_list:
13280 10700 : set_clause { $$ = $1; }
13281 2503 : | set_clause_list ',' set_clause { $$ = list_concat($1,$3); }
13282 : ;
13283 :
13284 : set_clause:
13285 : set_target '=' a_expr
13286 : {
13287 13082 : $1->val = (Node *) $3;
13288 13082 : $$ = list_make1($1);
13289 : }
13290 : | '(' set_target_list ')' '=' a_expr
13291 : {
13292 121 : int ncolumns = list_length($2);
13293 121 : int i = 1;
13294 : ListCell *col_cell;
13295 :
13296 : /* Create a MultiAssignRef source for each target */
13297 374 : foreach(col_cell, $2)
13298 : {
13299 253 : ResTarget *res_col = (ResTarget *) lfirst(col_cell);
13300 253 : MultiAssignRef *r = makeNode(MultiAssignRef);
13301 :
13302 253 : r->source = (Node *) $5;
13303 253 : r->colno = i;
13304 253 : r->ncolumns = ncolumns;
13305 253 : res_col->val = (Node *) r;
13306 253 : i++;
13307 : }
13308 :
13309 121 : $$ = $2;
13310 : }
13311 : ;
13312 :
13313 : set_target:
13314 : ColId opt_indirection
13315 : {
13316 13339 : $$ = makeNode(ResTarget);
13317 13339 : $$->name = $1;
13318 13339 : $$->indirection = check_indirection($2, yyscanner);
13319 13339 : $$->val = NULL; /* upper production sets this */
13320 13339 : $$->location = @1;
13321 : }
13322 : ;
13323 :
13324 : set_target_list:
13325 125 : set_target { $$ = list_make1($1); }
13326 132 : | set_target_list ',' set_target { $$ = lappend($1,$3); }
13327 : ;
13328 :
13329 :
13330 : /*****************************************************************************
13331 : *
13332 : * QUERY:
13333 : * MERGE
13334 : *
13335 : *****************************************************************************/
13336 :
13337 : MergeStmt:
13338 : opt_with_clause MERGE INTO relation_expr_opt_alias
13339 : USING table_ref
13340 : ON a_expr
13341 : merge_when_list
13342 : returning_clause
13343 : {
13344 1422 : MergeStmt *m = makeNode(MergeStmt);
13345 :
13346 1422 : m->withClause = $1;
13347 1422 : m->relation = $4;
13348 1422 : m->sourceRelation = $6;
13349 1422 : m->joinCondition = $8;
13350 1422 : m->mergeWhenClauses = $9;
13351 1422 : m->returningClause = $10;
13352 :
13353 1422 : $$ = (Node *) m;
13354 : }
13355 : ;
13356 :
13357 : merge_when_list:
13358 1422 : merge_when_clause { $$ = list_make1($1); }
13359 777 : | merge_when_list merge_when_clause { $$ = lappend($1,$2); }
13360 : ;
13361 :
13362 : /*
13363 : * A WHEN clause may be WHEN MATCHED, WHEN NOT MATCHED BY SOURCE, or WHEN NOT
13364 : * MATCHED [BY TARGET]. The first two cases match target tuples, and support
13365 : * UPDATE/DELETE/DO NOTHING actions. The third case does not match target
13366 : * tuples, and only supports INSERT/DO NOTHING actions.
13367 : */
13368 : merge_when_clause:
13369 : merge_when_tgt_matched opt_merge_when_condition THEN merge_update
13370 : {
13371 1046 : $4->matchKind = $1;
13372 1046 : $4->condition = $2;
13373 :
13374 1046 : $$ = (Node *) $4;
13375 : }
13376 : | merge_when_tgt_matched opt_merge_when_condition THEN merge_delete
13377 : {
13378 358 : $4->matchKind = $1;
13379 358 : $4->condition = $2;
13380 :
13381 358 : $$ = (Node *) $4;
13382 : }
13383 : | merge_when_tgt_not_matched opt_merge_when_condition THEN merge_insert
13384 : {
13385 732 : $4->matchKind = $1;
13386 732 : $4->condition = $2;
13387 :
13388 732 : $$ = (Node *) $4;
13389 : }
13390 : | merge_when_tgt_matched opt_merge_when_condition THEN DO NOTHING
13391 : {
13392 46 : MergeWhenClause *m = makeNode(MergeWhenClause);
13393 :
13394 46 : m->matchKind = $1;
13395 46 : m->commandType = CMD_NOTHING;
13396 46 : m->condition = $2;
13397 :
13398 46 : $$ = (Node *) m;
13399 : }
13400 : | merge_when_tgt_not_matched opt_merge_when_condition THEN DO NOTHING
13401 : {
13402 17 : MergeWhenClause *m = makeNode(MergeWhenClause);
13403 :
13404 17 : m->matchKind = $1;
13405 17 : m->commandType = CMD_NOTHING;
13406 17 : m->condition = $2;
13407 :
13408 17 : $$ = (Node *) m;
13409 : }
13410 : ;
13411 :
13412 : merge_when_tgt_matched:
13413 1340 : WHEN MATCHED { $$ = MERGE_WHEN_MATCHED; }
13414 122 : | WHEN NOT MATCHED BY SOURCE { $$ = MERGE_WHEN_NOT_MATCHED_BY_SOURCE; }
13415 : ;
13416 :
13417 : merge_when_tgt_not_matched:
13418 753 : WHEN NOT MATCHED { $$ = MERGE_WHEN_NOT_MATCHED_BY_TARGET; }
13419 12 : | WHEN NOT MATCHED BY TARGET { $$ = MERGE_WHEN_NOT_MATCHED_BY_TARGET; }
13420 : ;
13421 :
13422 : opt_merge_when_condition:
13423 545 : AND a_expr { $$ = $2; }
13424 1682 : | { $$ = NULL; }
13425 : ;
13426 :
13427 : merge_update:
13428 : UPDATE SET set_clause_list
13429 : {
13430 1046 : MergeWhenClause *n = makeNode(MergeWhenClause);
13431 1046 : n->commandType = CMD_UPDATE;
13432 1046 : n->override = OVERRIDING_NOT_SET;
13433 1046 : n->targetList = $3;
13434 1046 : n->values = NIL;
13435 :
13436 1046 : $$ = n;
13437 : }
13438 : ;
13439 :
13440 : merge_delete:
13441 : DELETE_P
13442 : {
13443 358 : MergeWhenClause *n = makeNode(MergeWhenClause);
13444 358 : n->commandType = CMD_DELETE;
13445 358 : n->override = OVERRIDING_NOT_SET;
13446 358 : n->targetList = NIL;
13447 358 : n->values = NIL;
13448 :
13449 358 : $$ = n;
13450 : }
13451 : ;
13452 :
13453 : merge_insert:
13454 : INSERT merge_values_clause
13455 : {
13456 489 : MergeWhenClause *n = makeNode(MergeWhenClause);
13457 489 : n->commandType = CMD_INSERT;
13458 489 : n->override = OVERRIDING_NOT_SET;
13459 489 : n->targetList = NIL;
13460 489 : n->values = $2;
13461 489 : $$ = n;
13462 : }
13463 : | INSERT OVERRIDING override_kind VALUE_P merge_values_clause
13464 : {
13465 0 : MergeWhenClause *n = makeNode(MergeWhenClause);
13466 0 : n->commandType = CMD_INSERT;
13467 0 : n->override = $3;
13468 0 : n->targetList = NIL;
13469 0 : n->values = $5;
13470 0 : $$ = n;
13471 : }
13472 : | INSERT '(' insert_column_list ')' merge_values_clause
13473 : {
13474 199 : MergeWhenClause *n = makeNode(MergeWhenClause);
13475 199 : n->commandType = CMD_INSERT;
13476 199 : n->override = OVERRIDING_NOT_SET;
13477 199 : n->targetList = $3;
13478 199 : n->values = $5;
13479 199 : $$ = n;
13480 : }
13481 : | INSERT '(' insert_column_list ')' OVERRIDING override_kind VALUE_P merge_values_clause
13482 : {
13483 20 : MergeWhenClause *n = makeNode(MergeWhenClause);
13484 20 : n->commandType = CMD_INSERT;
13485 20 : n->override = $6;
13486 20 : n->targetList = $3;
13487 20 : n->values = $8;
13488 20 : $$ = n;
13489 : }
13490 : | INSERT DEFAULT VALUES
13491 : {
13492 24 : MergeWhenClause *n = makeNode(MergeWhenClause);
13493 24 : n->commandType = CMD_INSERT;
13494 24 : n->override = OVERRIDING_NOT_SET;
13495 24 : n->targetList = NIL;
13496 24 : n->values = NIL;
13497 24 : $$ = n;
13498 : }
13499 : ;
13500 :
13501 : merge_values_clause:
13502 : VALUES '(' expr_list ')'
13503 : {
13504 708 : $$ = $3;
13505 : }
13506 : ;
13507 :
13508 : /*****************************************************************************
13509 : *
13510 : * QUERY:
13511 : * CURSOR STATEMENTS
13512 : *
13513 : *****************************************************************************/
13514 : DeclareCursorStmt: DECLARE cursor_name cursor_options CURSOR opt_hold FOR SelectStmt
13515 : {
13516 2722 : DeclareCursorStmt *n = makeNode(DeclareCursorStmt);
13517 :
13518 2722 : n->portalname = $2;
13519 : /* currently we always set FAST_PLAN option */
13520 2722 : n->options = $3 | $5 | CURSOR_OPT_FAST_PLAN;
13521 2722 : n->query = $7;
13522 2722 : $$ = (Node *) n;
13523 : }
13524 : ;
13525 :
13526 8458 : cursor_name: name { $$ = $1; }
13527 : ;
13528 :
13529 2722 : cursor_options: /*EMPTY*/ { $$ = 0; }
13530 18 : | cursor_options NO SCROLL { $$ = $1 | CURSOR_OPT_NO_SCROLL; }
13531 160 : | cursor_options SCROLL { $$ = $1 | CURSOR_OPT_SCROLL; }
13532 8 : | cursor_options BINARY { $$ = $1 | CURSOR_OPT_BINARY; }
13533 0 : | cursor_options ASENSITIVE { $$ = $1 | CURSOR_OPT_ASENSITIVE; }
13534 4 : | cursor_options INSENSITIVE { $$ = $1 | CURSOR_OPT_INSENSITIVE; }
13535 : ;
13536 :
13537 2655 : opt_hold: /* EMPTY */ { $$ = 0; }
13538 63 : | WITH HOLD { $$ = CURSOR_OPT_HOLD; }
13539 4 : | WITHOUT HOLD { $$ = 0; }
13540 : ;
13541 :
13542 : /*****************************************************************************
13543 : *
13544 : * QUERY:
13545 : * SELECT STATEMENTS
13546 : *
13547 : *****************************************************************************/
13548 :
13549 : /* A complete SELECT statement looks like this.
13550 : *
13551 : * The rule returns either a single SelectStmt node or a tree of them,
13552 : * representing a set-operation tree.
13553 : *
13554 : * There is an ambiguity when a sub-SELECT is within an a_expr and there
13555 : * are excess parentheses: do the parentheses belong to the sub-SELECT or
13556 : * to the surrounding a_expr? We don't really care, but bison wants to know.
13557 : * To resolve the ambiguity, we are careful to define the grammar so that
13558 : * the decision is staved off as long as possible: as long as we can keep
13559 : * absorbing parentheses into the sub-SELECT, we will do so, and only when
13560 : * it's no longer possible to do that will we decide that parens belong to
13561 : * the expression. For example, in "SELECT (((SELECT 2)) + 3)" the extra
13562 : * parentheses are treated as part of the sub-select. The necessity of doing
13563 : * it that way is shown by "SELECT (((SELECT 2)) UNION SELECT 2)". Had we
13564 : * parsed "((SELECT 2))" as an a_expr, it'd be too late to go back to the
13565 : * SELECT viewpoint when we see the UNION.
13566 : *
13567 : * This approach is implemented by defining a nonterminal select_with_parens,
13568 : * which represents a SELECT with at least one outer layer of parentheses,
13569 : * and being careful to use select_with_parens, never '(' SelectStmt ')',
13570 : * in the expression grammar. We will then have shift-reduce conflicts
13571 : * which we can resolve in favor of always treating '(' <select> ')' as
13572 : * a select_with_parens. To resolve the conflicts, the productions that
13573 : * conflict with the select_with_parens productions are manually given
13574 : * precedences lower than the precedence of ')', thereby ensuring that we
13575 : * shift ')' (and then reduce to select_with_parens) rather than trying to
13576 : * reduce the inner <select> nonterminal to something else. We use UMINUS
13577 : * precedence for this, which is a fairly arbitrary choice.
13578 : *
13579 : * To be able to define select_with_parens itself without ambiguity, we need
13580 : * a nonterminal select_no_parens that represents a SELECT structure with no
13581 : * outermost parentheses. This is a little bit tedious, but it works.
13582 : *
13583 : * In non-expression contexts, we use SelectStmt which can represent a SELECT
13584 : * with or without outer parentheses.
13585 : */
13586 :
13587 : SelectStmt: select_no_parens %prec UMINUS
13588 : | select_with_parens %prec UMINUS
13589 : ;
13590 :
13591 : select_with_parens:
13592 47358 : '(' select_no_parens ')' { $$ = $2; }
13593 104 : | '(' select_with_parens ')' { $$ = $2; }
13594 : ;
13595 :
13596 : /*
13597 : * This rule parses the equivalent of the standard's <query expression>.
13598 : * The duplicative productions are annoying, but hard to get rid of without
13599 : * creating shift/reduce conflicts.
13600 : *
13601 : * The locking clause (FOR UPDATE etc) may be before or after LIMIT/OFFSET.
13602 : * In <=7.2.X, LIMIT/OFFSET had to be after FOR UPDATE
13603 : * We now support both orderings, but prefer LIMIT/OFFSET before the locking
13604 : * clause.
13605 : * 2002-08-28 bjm
13606 : */
13607 : select_no_parens:
13608 253725 : simple_select { $$ = $1; }
13609 : | select_clause sort_clause
13610 : {
13611 49159 : insertSelectOptions((SelectStmt *) $1, $2, NIL,
13612 : NULL, NULL,
13613 : yyscanner);
13614 49159 : $$ = $1;
13615 : }
13616 : | select_clause opt_sort_clause for_locking_clause opt_select_limit
13617 : {
13618 5704 : insertSelectOptions((SelectStmt *) $1, $2, $3,
13619 5704 : $4,
13620 : NULL,
13621 : yyscanner);
13622 5704 : $$ = $1;
13623 : }
13624 : | select_clause opt_sort_clause select_limit opt_for_locking_clause
13625 : {
13626 3114 : insertSelectOptions((SelectStmt *) $1, $2, $4,
13627 3114 : $3,
13628 : NULL,
13629 : yyscanner);
13630 3106 : $$ = $1;
13631 : }
13632 : | with_clause select_clause
13633 : {
13634 1514 : insertSelectOptions((SelectStmt *) $2, NULL, NIL,
13635 : NULL,
13636 1514 : $1,
13637 : yyscanner);
13638 1514 : $$ = $2;
13639 : }
13640 : | with_clause select_clause sort_clause
13641 : {
13642 359 : insertSelectOptions((SelectStmt *) $2, $3, NIL,
13643 : NULL,
13644 359 : $1,
13645 : yyscanner);
13646 359 : $$ = $2;
13647 : }
13648 : | with_clause select_clause opt_sort_clause for_locking_clause opt_select_limit
13649 : {
13650 4 : insertSelectOptions((SelectStmt *) $2, $3, $4,
13651 4 : $5,
13652 4 : $1,
13653 : yyscanner);
13654 4 : $$ = $2;
13655 : }
13656 : | with_clause select_clause opt_sort_clause select_limit opt_for_locking_clause
13657 : {
13658 42 : insertSelectOptions((SelectStmt *) $2, $3, $5,
13659 42 : $4,
13660 42 : $1,
13661 : yyscanner);
13662 42 : $$ = $2;
13663 : }
13664 : ;
13665 :
13666 : select_clause:
13667 85317 : simple_select { $$ = $1; }
13668 373 : | select_with_parens { $$ = $1; }
13669 : ;
13670 :
13671 : /*
13672 : * This rule parses SELECT statements that can appear within set operations,
13673 : * including UNION, INTERSECT and EXCEPT. '(' and ')' can be used to specify
13674 : * the ordering of the set operations. Without '(' and ')' we want the
13675 : * operations to be ordered per the precedence specs at the head of this file.
13676 : *
13677 : * As with select_no_parens, simple_select cannot have outer parentheses,
13678 : * but can have parenthesized subclauses.
13679 : *
13680 : * It might appear that we could fold the first two alternatives into one
13681 : * by using opt_distinct_clause. However, that causes a shift/reduce conflict
13682 : * against INSERT ... SELECT ... ON CONFLICT. We avoid the ambiguity by
13683 : * requiring SELECT DISTINCT [ON] to be followed by a non-empty target_list.
13684 : *
13685 : * Note that sort clauses cannot be included at this level --- SQL requires
13686 : * SELECT foo UNION SELECT bar ORDER BY baz
13687 : * to be parsed as
13688 : * (SELECT foo UNION SELECT bar) ORDER BY baz
13689 : * not
13690 : * SELECT foo UNION (SELECT bar ORDER BY baz)
13691 : * Likewise for WITH, FOR UPDATE and LIMIT. Therefore, those clauses are
13692 : * described as part of the select_no_parens production, not simple_select.
13693 : * This does not limit functionality, because you can reintroduce these
13694 : * clauses inside parentheses.
13695 : *
13696 : * NOTE: only the leftmost component SelectStmt should have INTO.
13697 : * However, this is not checked by the grammar; parse analysis must check it.
13698 : */
13699 : simple_select:
13700 : SELECT opt_all_clause opt_target_list
13701 : into_clause from_clause where_clause
13702 : group_clause having_clause window_clause
13703 : {
13704 283311 : SelectStmt *n = makeNode(SelectStmt);
13705 :
13706 283311 : n->targetList = $3;
13707 283311 : n->intoClause = $4;
13708 283311 : n->fromClause = $5;
13709 283311 : n->whereClause = $6;
13710 283311 : n->groupClause = ($7)->list;
13711 283311 : n->groupDistinct = ($7)->distinct;
13712 283311 : n->groupByAll = ($7)->all;
13713 283311 : n->havingClause = $8;
13714 283311 : n->windowClause = $9;
13715 283311 : $$ = (Node *) n;
13716 : }
13717 : | SELECT distinct_clause target_list
13718 : into_clause from_clause where_clause
13719 : group_clause having_clause window_clause
13720 : {
13721 2400 : SelectStmt *n = makeNode(SelectStmt);
13722 :
13723 2400 : n->distinctClause = $2;
13724 2400 : n->targetList = $3;
13725 2400 : n->intoClause = $4;
13726 2400 : n->fromClause = $5;
13727 2400 : n->whereClause = $6;
13728 2400 : n->groupClause = ($7)->list;
13729 2400 : n->groupDistinct = ($7)->distinct;
13730 2400 : n->groupByAll = ($7)->all;
13731 2400 : n->havingClause = $8;
13732 2400 : n->windowClause = $9;
13733 2400 : $$ = (Node *) n;
13734 : }
13735 40185 : | values_clause { $$ = $1; }
13736 : | TABLE relation_expr
13737 : {
13738 : /* same as SELECT * FROM relation_expr */
13739 253 : ColumnRef *cr = makeNode(ColumnRef);
13740 253 : ResTarget *rt = makeNode(ResTarget);
13741 253 : SelectStmt *n = makeNode(SelectStmt);
13742 :
13743 253 : cr->fields = list_make1(makeNode(A_Star));
13744 253 : cr->location = -1;
13745 :
13746 253 : rt->name = NULL;
13747 253 : rt->indirection = NIL;
13748 253 : rt->val = (Node *) cr;
13749 253 : rt->location = -1;
13750 :
13751 253 : n->targetList = list_make1(rt);
13752 253 : n->fromClause = list_make1($2);
13753 253 : $$ = (Node *) n;
13754 : }
13755 : | select_clause UNION set_quantifier select_clause
13756 : {
13757 12369 : $$ = makeSetOp(SETOP_UNION, $3 == SET_QUANTIFIER_ALL, $1, $4);
13758 : }
13759 : | select_clause INTERSECT set_quantifier select_clause
13760 : {
13761 184 : $$ = makeSetOp(SETOP_INTERSECT, $3 == SET_QUANTIFIER_ALL, $1, $4);
13762 : }
13763 : | select_clause EXCEPT set_quantifier select_clause
13764 : {
13765 340 : $$ = makeSetOp(SETOP_EXCEPT, $3 == SET_QUANTIFIER_ALL, $1, $4);
13766 : }
13767 : ;
13768 :
13769 : /*
13770 : * SQL standard WITH clause looks like:
13771 : *
13772 : * WITH [ RECURSIVE ] <query name> [ (<column>,...) ]
13773 : * AS (query) [ SEARCH or CYCLE clause ]
13774 : *
13775 : * Recognizing WITH_LA here allows a CTE to be named TIME or ORDINALITY.
13776 : */
13777 : with_clause:
13778 : WITH cte_list
13779 : {
13780 1382 : $$ = makeNode(WithClause);
13781 1382 : $$->ctes = $2;
13782 1382 : $$->recursive = false;
13783 1382 : $$->location = @1;
13784 : }
13785 : | WITH_LA cte_list
13786 : {
13787 4 : $$ = makeNode(WithClause);
13788 4 : $$->ctes = $2;
13789 4 : $$->recursive = false;
13790 4 : $$->location = @1;
13791 : }
13792 : | WITH RECURSIVE cte_list
13793 : {
13794 829 : $$ = makeNode(WithClause);
13795 829 : $$->ctes = $3;
13796 829 : $$->recursive = true;
13797 829 : $$->location = @1;
13798 : }
13799 : ;
13800 :
13801 : cte_list:
13802 2215 : common_table_expr { $$ = list_make1($1); }
13803 737 : | cte_list ',' common_table_expr { $$ = lappend($1, $3); }
13804 : ;
13805 :
13806 : common_table_expr: name opt_name_list AS opt_materialized '(' PreparableStmt ')' opt_search_clause opt_cycle_clause
13807 : {
13808 2952 : CommonTableExpr *n = makeNode(CommonTableExpr);
13809 :
13810 2952 : n->ctename = $1;
13811 2952 : n->aliascolnames = $2;
13812 2952 : n->ctematerialized = $4;
13813 2952 : n->ctequery = $6;
13814 2952 : n->search_clause = castNode(CTESearchClause, $8);
13815 2952 : n->cycle_clause = castNode(CTECycleClause, $9);
13816 2952 : n->location = @1;
13817 2952 : $$ = (Node *) n;
13818 : }
13819 : ;
13820 :
13821 : opt_materialized:
13822 118 : MATERIALIZED { $$ = CTEMaterializeAlways; }
13823 32 : | NOT MATERIALIZED { $$ = CTEMaterializeNever; }
13824 2802 : | /*EMPTY*/ { $$ = CTEMaterializeDefault; }
13825 : ;
13826 :
13827 : opt_search_clause:
13828 : SEARCH DEPTH FIRST_P BY columnList SET ColId
13829 : {
13830 60 : CTESearchClause *n = makeNode(CTESearchClause);
13831 :
13832 60 : n->search_col_list = $5;
13833 60 : n->search_breadth_first = false;
13834 60 : n->search_seq_column = $7;
13835 60 : n->location = @1;
13836 60 : $$ = (Node *) n;
13837 : }
13838 : | SEARCH BREADTH FIRST_P BY columnList SET ColId
13839 : {
13840 24 : CTESearchClause *n = makeNode(CTESearchClause);
13841 :
13842 24 : n->search_col_list = $5;
13843 24 : n->search_breadth_first = true;
13844 24 : n->search_seq_column = $7;
13845 24 : n->location = @1;
13846 24 : $$ = (Node *) n;
13847 : }
13848 : | /*EMPTY*/
13849 : {
13850 2868 : $$ = NULL;
13851 : }
13852 : ;
13853 :
13854 : opt_cycle_clause:
13855 : CYCLE columnList SET ColId TO AexprConst DEFAULT AexprConst USING ColId
13856 : {
13857 44 : CTECycleClause *n = makeNode(CTECycleClause);
13858 :
13859 44 : n->cycle_col_list = $2;
13860 44 : n->cycle_mark_column = $4;
13861 44 : n->cycle_mark_value = $6;
13862 44 : n->cycle_mark_default = $8;
13863 44 : n->cycle_path_column = $10;
13864 44 : n->location = @1;
13865 44 : $$ = (Node *) n;
13866 : }
13867 : | CYCLE columnList SET ColId USING ColId
13868 : {
13869 40 : CTECycleClause *n = makeNode(CTECycleClause);
13870 :
13871 40 : n->cycle_col_list = $2;
13872 40 : n->cycle_mark_column = $4;
13873 40 : n->cycle_mark_value = makeBoolAConst(true, -1);
13874 40 : n->cycle_mark_default = makeBoolAConst(false, -1);
13875 40 : n->cycle_path_column = $6;
13876 40 : n->location = @1;
13877 40 : $$ = (Node *) n;
13878 : }
13879 : | /*EMPTY*/
13880 : {
13881 2868 : $$ = NULL;
13882 : }
13883 : ;
13884 :
13885 : opt_with_clause:
13886 296 : with_clause { $$ = $1; }
13887 57216 : | /*EMPTY*/ { $$ = NULL; }
13888 : ;
13889 :
13890 : into_clause:
13891 : INTO OptTempTableName
13892 : {
13893 91 : $$ = makeNode(IntoClause);
13894 91 : $$->rel = $2;
13895 91 : $$->colNames = NIL;
13896 91 : $$->options = NIL;
13897 91 : $$->onCommit = ONCOMMIT_NOOP;
13898 91 : $$->tableSpaceName = NULL;
13899 91 : $$->viewQuery = NULL;
13900 91 : $$->skipData = false;
13901 : }
13902 : | /*EMPTY*/
13903 285648 : { $$ = NULL; }
13904 : ;
13905 :
13906 : /*
13907 : * Redundancy here is needed to avoid shift/reduce conflicts,
13908 : * since TEMP is not a reserved word. See also OptTemp.
13909 : */
13910 : OptTempTableName:
13911 : TEMPORARY opt_table qualified_name
13912 : {
13913 0 : $$ = $3;
13914 0 : $$->relpersistence = RELPERSISTENCE_TEMP;
13915 : }
13916 : | TEMP opt_table qualified_name
13917 : {
13918 4 : $$ = $3;
13919 4 : $$->relpersistence = RELPERSISTENCE_TEMP;
13920 : }
13921 : | LOCAL TEMPORARY opt_table qualified_name
13922 : {
13923 0 : $$ = $4;
13924 0 : $$->relpersistence = RELPERSISTENCE_TEMP;
13925 : }
13926 : | LOCAL TEMP opt_table qualified_name
13927 : {
13928 0 : $$ = $4;
13929 0 : $$->relpersistence = RELPERSISTENCE_TEMP;
13930 : }
13931 : | GLOBAL TEMPORARY opt_table qualified_name
13932 : {
13933 0 : ereport(WARNING,
13934 : (errmsg("GLOBAL is deprecated in temporary table creation"),
13935 : parser_errposition(@1)));
13936 0 : $$ = $4;
13937 0 : $$->relpersistence = RELPERSISTENCE_TEMP;
13938 : }
13939 : | GLOBAL TEMP opt_table qualified_name
13940 : {
13941 0 : ereport(WARNING,
13942 : (errmsg("GLOBAL is deprecated in temporary table creation"),
13943 : parser_errposition(@1)));
13944 0 : $$ = $4;
13945 0 : $$->relpersistence = RELPERSISTENCE_TEMP;
13946 : }
13947 : | UNLOGGED opt_table qualified_name
13948 : {
13949 0 : $$ = $3;
13950 0 : $$->relpersistence = RELPERSISTENCE_UNLOGGED;
13951 : }
13952 : | TABLE qualified_name
13953 : {
13954 20 : $$ = $2;
13955 20 : $$->relpersistence = RELPERSISTENCE_PERMANENT;
13956 : }
13957 : | qualified_name
13958 : {
13959 67 : $$ = $1;
13960 67 : $$->relpersistence = RELPERSISTENCE_PERMANENT;
13961 : }
13962 : ;
13963 :
13964 : opt_table: TABLE
13965 : | /*EMPTY*/
13966 : ;
13967 :
13968 : set_quantifier:
13969 7102 : ALL { $$ = SET_QUANTIFIER_ALL; }
13970 25 : | DISTINCT { $$ = SET_QUANTIFIER_DISTINCT; }
13971 9098 : | /*EMPTY*/ { $$ = SET_QUANTIFIER_DEFAULT; }
13972 : ;
13973 :
13974 : /* We use (NIL) as a placeholder to indicate that all target expressions
13975 : * should be placed in the DISTINCT list during parsetree analysis.
13976 : */
13977 : distinct_clause:
13978 2244 : DISTINCT { $$ = list_make1(NIL); }
13979 160 : | DISTINCT ON '(' expr_list ')' { $$ = $4; }
13980 : ;
13981 :
13982 : opt_all_clause:
13983 : ALL
13984 : | /*EMPTY*/
13985 : ;
13986 :
13987 : opt_distinct_clause:
13988 0 : distinct_clause { $$ = $1; }
13989 24713 : | opt_all_clause { $$ = NIL; }
13990 : ;
13991 :
13992 : opt_sort_clause:
13993 4893 : sort_clause { $$ = $1; }
13994 237869 : | /*EMPTY*/ { $$ = NIL; }
13995 : ;
13996 :
13997 : sort_clause:
13998 54639 : ORDER BY sortby_list { $$ = $3; }
13999 : ;
14000 :
14001 : sortby_list:
14002 54651 : sortby { $$ = list_make1($1); }
14003 19566 : | sortby_list ',' sortby { $$ = lappend($1, $3); }
14004 : ;
14005 :
14006 : sortby: a_expr USING qual_all_Op opt_nulls_order
14007 : {
14008 142 : $$ = makeNode(SortBy);
14009 142 : $$->node = $1;
14010 142 : $$->sortby_dir = SORTBY_USING;
14011 142 : $$->sortby_nulls = $4;
14012 142 : $$->useOp = $3;
14013 142 : $$->location = @3;
14014 : }
14015 : | a_expr opt_asc_desc opt_nulls_order
14016 : {
14017 74075 : $$ = makeNode(SortBy);
14018 74075 : $$->node = $1;
14019 74075 : $$->sortby_dir = $2;
14020 74075 : $$->sortby_nulls = $3;
14021 74075 : $$->useOp = NIL;
14022 74075 : $$->location = -1; /* no operator */
14023 : }
14024 : ;
14025 :
14026 :
14027 : select_limit:
14028 : limit_clause offset_clause
14029 : {
14030 99 : $$ = $1;
14031 99 : ($$)->limitOffset = $2;
14032 99 : ($$)->offsetLoc = @2;
14033 : }
14034 : | offset_clause limit_clause
14035 : {
14036 113 : $$ = $2;
14037 113 : ($$)->limitOffset = $1;
14038 113 : ($$)->offsetLoc = @1;
14039 : }
14040 : | limit_clause
14041 : {
14042 2717 : $$ = $1;
14043 : }
14044 : | offset_clause
14045 : {
14046 322 : SelectLimit *n = palloc_object(SelectLimit);
14047 :
14048 322 : n->limitOffset = $1;
14049 322 : n->limitCount = NULL;
14050 322 : n->limitOption = LIMIT_OPTION_COUNT;
14051 322 : n->offsetLoc = @1;
14052 322 : n->countLoc = -1;
14053 322 : n->optionLoc = -1;
14054 322 : $$ = n;
14055 : }
14056 : ;
14057 :
14058 : opt_select_limit:
14059 95 : select_limit { $$ = $1; }
14060 30326 : | /* EMPTY */ { $$ = NULL; }
14061 : ;
14062 :
14063 : limit_clause:
14064 : LIMIT select_limit_value
14065 : {
14066 2868 : SelectLimit *n = palloc_object(SelectLimit);
14067 :
14068 2868 : n->limitOffset = NULL;
14069 2868 : n->limitCount = $2;
14070 2868 : n->limitOption = LIMIT_OPTION_COUNT;
14071 2868 : n->offsetLoc = -1;
14072 2868 : n->countLoc = @1;
14073 2868 : n->optionLoc = -1;
14074 2868 : $$ = n;
14075 : }
14076 : | LIMIT select_limit_value ',' select_offset_value
14077 : {
14078 : /* Disabled because it was too confusing, bjm 2002-02-18 */
14079 0 : ereport(ERROR,
14080 : (errcode(ERRCODE_SYNTAX_ERROR),
14081 : errmsg("LIMIT #,# syntax is not supported"),
14082 : errhint("Use separate LIMIT and OFFSET clauses."),
14083 : parser_errposition(@1)));
14084 : }
14085 : /* SQL:2008 syntax */
14086 : /* to avoid shift/reduce conflicts, handle the optional value with
14087 : * a separate production rather than an opt_ expression. The fact
14088 : * that ONLY is fully reserved means that this way, we defer any
14089 : * decision about what rule reduces ROW or ROWS to the point where
14090 : * we can see the ONLY token in the lookahead slot.
14091 : */
14092 : | FETCH first_or_next select_fetch_first_value row_or_rows ONLY
14093 : {
14094 15 : SelectLimit *n = palloc_object(SelectLimit);
14095 :
14096 15 : n->limitOffset = NULL;
14097 15 : n->limitCount = $3;
14098 15 : n->limitOption = LIMIT_OPTION_COUNT;
14099 15 : n->offsetLoc = -1;
14100 15 : n->countLoc = @1;
14101 15 : n->optionLoc = -1;
14102 15 : $$ = n;
14103 : }
14104 : | FETCH first_or_next select_fetch_first_value row_or_rows WITH TIES
14105 : {
14106 42 : SelectLimit *n = palloc_object(SelectLimit);
14107 :
14108 42 : n->limitOffset = NULL;
14109 42 : n->limitCount = $3;
14110 42 : n->limitOption = LIMIT_OPTION_WITH_TIES;
14111 42 : n->offsetLoc = -1;
14112 42 : n->countLoc = @1;
14113 42 : n->optionLoc = @5;
14114 42 : $$ = n;
14115 : }
14116 : | FETCH first_or_next row_or_rows ONLY
14117 : {
14118 0 : SelectLimit *n = palloc_object(SelectLimit);
14119 :
14120 0 : n->limitOffset = NULL;
14121 0 : n->limitCount = makeIntConst(1, -1);
14122 0 : n->limitOption = LIMIT_OPTION_COUNT;
14123 0 : n->offsetLoc = -1;
14124 0 : n->countLoc = @1;
14125 0 : n->optionLoc = -1;
14126 0 : $$ = n;
14127 : }
14128 : | FETCH first_or_next row_or_rows WITH TIES
14129 : {
14130 4 : SelectLimit *n = palloc_object(SelectLimit);
14131 :
14132 4 : n->limitOffset = NULL;
14133 4 : n->limitCount = makeIntConst(1, -1);
14134 4 : n->limitOption = LIMIT_OPTION_WITH_TIES;
14135 4 : n->offsetLoc = -1;
14136 4 : n->countLoc = @1;
14137 4 : n->optionLoc = @4;
14138 4 : $$ = n;
14139 : }
14140 : ;
14141 :
14142 : offset_clause:
14143 : OFFSET select_offset_value
14144 534 : { $$ = $2; }
14145 : /* SQL:2008 syntax */
14146 : | OFFSET select_fetch_first_value row_or_rows
14147 0 : { $$ = $2; }
14148 : ;
14149 :
14150 : select_limit_value:
14151 2867 : a_expr { $$ = $1; }
14152 : | ALL
14153 : {
14154 : /* LIMIT ALL is represented as a NULL constant */
14155 1 : $$ = makeNullAConst(@1);
14156 : }
14157 : ;
14158 :
14159 : select_offset_value:
14160 534 : a_expr { $$ = $1; }
14161 : ;
14162 :
14163 : /*
14164 : * Allowing full expressions without parentheses causes various parsing
14165 : * problems with the trailing ROW/ROWS key words. SQL spec only calls for
14166 : * <simple value specification>, which is either a literal or a parameter (but
14167 : * an <SQL parameter reference> could be an identifier, bringing up conflicts
14168 : * with ROW/ROWS). We solve this by leveraging the presence of ONLY (see above)
14169 : * to determine whether the expression is missing rather than trying to make it
14170 : * optional in this rule.
14171 : *
14172 : * c_expr covers almost all the spec-required cases (and more), but it doesn't
14173 : * cover signed numeric literals, which are allowed by the spec. So we include
14174 : * those here explicitly. We need FCONST as well as ICONST because values that
14175 : * don't fit in the platform's "long", but do fit in bigint, should still be
14176 : * accepted here. (This is possible in 64-bit Windows as well as all 32-bit
14177 : * builds.)
14178 : */
14179 : select_fetch_first_value:
14180 57 : c_expr { $$ = $1; }
14181 : | '+' I_or_F_const
14182 0 : { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "+", NULL, $2, @1); }
14183 : | '-' I_or_F_const
14184 0 : { $$ = doNegate($2, @1); }
14185 : ;
14186 :
14187 : I_or_F_const:
14188 0 : Iconst { $$ = makeIntConst($1,@1); }
14189 0 : | FCONST { $$ = makeFloatConst($1,@1); }
14190 : ;
14191 :
14192 : /* noise words */
14193 23 : row_or_rows: ROW { $$ = 0; }
14194 38 : | ROWS { $$ = 0; }
14195 : ;
14196 :
14197 61 : first_or_next: FIRST_P { $$ = 0; }
14198 0 : | NEXT { $$ = 0; }
14199 : ;
14200 :
14201 :
14202 : /*
14203 : * This syntax for group_clause tries to follow the spec quite closely.
14204 : * However, the spec allows only column references, not expressions,
14205 : * which introduces an ambiguity between implicit row constructors
14206 : * (a,b) and lists of column references.
14207 : *
14208 : * We handle this by using the a_expr production for what the spec calls
14209 : * <ordinary grouping set>, which in the spec represents either one column
14210 : * reference or a parenthesized list of column references. Then, we check the
14211 : * top node of the a_expr to see if it's an implicit RowExpr, and if so, just
14212 : * grab and use the list, discarding the node. (this is done in parse analysis,
14213 : * not here)
14214 : *
14215 : * (we abuse the row_format field of RowExpr to distinguish implicit and
14216 : * explicit row constructors; it's debatable if anyone sanely wants to use them
14217 : * in a group clause, but if they have a reason to, we make it possible.)
14218 : *
14219 : * Each item in the group_clause list is either an expression tree or a
14220 : * GroupingSet node of some type.
14221 : */
14222 : group_clause:
14223 : GROUP_P BY set_quantifier group_by_list
14224 : {
14225 3324 : GroupClause *n = palloc_object(GroupClause);
14226 :
14227 3324 : n->distinct = $3 == SET_QUANTIFIER_DISTINCT;
14228 3324 : n->all = false;
14229 3324 : n->list = $4;
14230 3324 : $$ = n;
14231 : }
14232 : | GROUP_P BY ALL
14233 : {
14234 44 : GroupClause *n = palloc_object(GroupClause);
14235 44 : n->distinct = false;
14236 44 : n->all = true;
14237 44 : n->list = NIL;
14238 44 : $$ = n;
14239 : }
14240 : | /*EMPTY*/
14241 : {
14242 307056 : GroupClause *n = palloc_object(GroupClause);
14243 :
14244 307056 : n->distinct = false;
14245 307056 : n->all = false;
14246 307056 : n->list = NIL;
14247 307056 : $$ = n;
14248 : }
14249 : ;
14250 :
14251 : group_by_list:
14252 3812 : group_by_item { $$ = list_make1($1); }
14253 2034 : | group_by_list ',' group_by_item { $$ = lappend($1,$3); }
14254 : ;
14255 :
14256 : group_by_item:
14257 4806 : a_expr { $$ = $1; }
14258 214 : | empty_grouping_set { $$ = $1; }
14259 122 : | cube_clause { $$ = $1; }
14260 216 : | rollup_clause { $$ = $1; }
14261 488 : | grouping_sets_clause { $$ = $1; }
14262 : ;
14263 :
14264 : empty_grouping_set:
14265 : '(' ')'
14266 : {
14267 214 : $$ = (Node *) makeGroupingSet(GROUPING_SET_EMPTY, NIL, @1);
14268 : }
14269 : ;
14270 :
14271 : /*
14272 : * These hacks rely on setting precedence of CUBE and ROLLUP below that of '(',
14273 : * so that they shift in these rules rather than reducing the conflicting
14274 : * unreserved_keyword rule.
14275 : */
14276 :
14277 : rollup_clause:
14278 : ROLLUP '(' expr_list ')'
14279 : {
14280 216 : $$ = (Node *) makeGroupingSet(GROUPING_SET_ROLLUP, $3, @1);
14281 : }
14282 : ;
14283 :
14284 : cube_clause:
14285 : CUBE '(' expr_list ')'
14286 : {
14287 122 : $$ = (Node *) makeGroupingSet(GROUPING_SET_CUBE, $3, @1);
14288 : }
14289 : ;
14290 :
14291 : grouping_sets_clause:
14292 : GROUPING SETS '(' group_by_list ')'
14293 : {
14294 488 : $$ = (Node *) makeGroupingSet(GROUPING_SET_SETS, $4, @1);
14295 : }
14296 : ;
14297 :
14298 : having_clause:
14299 512 : HAVING a_expr { $$ = $2; }
14300 309912 : | /*EMPTY*/ { $$ = NULL; }
14301 : ;
14302 :
14303 : for_locking_clause:
14304 5879 : for_locking_items { $$ = $1; }
14305 0 : | FOR READ ONLY { $$ = NIL; }
14306 : ;
14307 :
14308 : opt_for_locking_clause:
14309 171 : for_locking_clause { $$ = $1; }
14310 27698 : | /* EMPTY */ { $$ = NIL; }
14311 : ;
14312 :
14313 : for_locking_items:
14314 5879 : for_locking_item { $$ = list_make1($1); }
14315 51 : | for_locking_items for_locking_item { $$ = lappend($1, $2); }
14316 : ;
14317 :
14318 : for_locking_item:
14319 : for_locking_strength locked_rels_list opt_nowait_or_skip
14320 : {
14321 5930 : LockingClause *n = makeNode(LockingClause);
14322 :
14323 5930 : n->lockedRels = $2;
14324 5930 : n->strength = $1;
14325 5930 : n->waitPolicy = $3;
14326 5930 : $$ = (Node *) n;
14327 : }
14328 : ;
14329 :
14330 : for_locking_strength:
14331 902 : FOR UPDATE { $$ = LCS_FORUPDATE; }
14332 44 : | FOR NO KEY UPDATE { $$ = LCS_FORNOKEYUPDATE; }
14333 123 : | FOR SHARE { $$ = LCS_FORSHARE; }
14334 4939 : | FOR KEY SHARE { $$ = LCS_FORKEYSHARE; }
14335 : ;
14336 :
14337 : opt_for_locking_strength:
14338 78 : for_locking_strength { $$ = $1; }
14339 162 : | /* EMPTY */ { $$ = LCS_NONE; }
14340 : ;
14341 :
14342 : locked_rels_list:
14343 2187 : OF qualified_name_list { $$ = $2; }
14344 3743 : | /* EMPTY */ { $$ = NIL; }
14345 : ;
14346 :
14347 :
14348 : /*
14349 : * We should allow ROW '(' expr_list ')' too, but that seems to require
14350 : * making VALUES a fully reserved word, which will probably break more apps
14351 : * than allowing the noise-word is worth.
14352 : */
14353 : values_clause:
14354 : VALUES '(' expr_list ')'
14355 : {
14356 40185 : SelectStmt *n = makeNode(SelectStmt);
14357 :
14358 40185 : n->valuesLists = list_make1($3);
14359 40185 : $$ = (Node *) n;
14360 : }
14361 : | values_clause ',' '(' expr_list ')'
14362 : {
14363 17663 : SelectStmt *n = (SelectStmt *) $1;
14364 :
14365 17663 : n->valuesLists = lappend(n->valuesLists, $4);
14366 17663 : $$ = (Node *) n;
14367 : }
14368 : ;
14369 :
14370 :
14371 : /*****************************************************************************
14372 : *
14373 : * clauses common to all Optimizable Stmts:
14374 : * from_clause - allow list of both JOIN expressions and table names
14375 : * where_clause - qualifications for joins or restrictions
14376 : *
14377 : *****************************************************************************/
14378 :
14379 : from_clause:
14380 210940 : FROM from_list { $$ = $2; }
14381 108224 : | /*EMPTY*/ { $$ = NIL; }
14382 : ;
14383 :
14384 : from_list:
14385 211656 : table_ref { $$ = list_make1($1); }
14386 37869 : | from_list ',' table_ref { $$ = lappend($1, $3); }
14387 : ;
14388 :
14389 : /*
14390 : * table_ref is where an alias clause can be attached.
14391 : */
14392 : table_ref: relation_expr opt_alias_clause
14393 : {
14394 262622 : $1->alias = $2;
14395 262622 : $$ = (Node *) $1;
14396 : }
14397 : | relation_expr opt_alias_clause tablesample_clause
14398 : {
14399 170 : RangeTableSample *n = (RangeTableSample *) $3;
14400 :
14401 170 : $1->alias = $2;
14402 : /* relation_expr goes inside the RangeTableSample node */
14403 170 : n->relation = (Node *) $1;
14404 170 : $$ = (Node *) n;
14405 : }
14406 : | func_table func_alias_clause
14407 : {
14408 28647 : RangeFunction *n = (RangeFunction *) $1;
14409 :
14410 28647 : n->alias = linitial($2);
14411 28647 : n->coldeflist = lsecond($2);
14412 28647 : $$ = (Node *) n;
14413 : }
14414 : | LATERAL_P func_table func_alias_clause
14415 : {
14416 753 : RangeFunction *n = (RangeFunction *) $2;
14417 :
14418 753 : n->lateral = true;
14419 753 : n->alias = linitial($3);
14420 753 : n->coldeflist = lsecond($3);
14421 753 : $$ = (Node *) n;
14422 : }
14423 : | xmltable opt_alias_clause
14424 : {
14425 57 : RangeTableFunc *n = (RangeTableFunc *) $1;
14426 :
14427 57 : n->alias = $2;
14428 57 : $$ = (Node *) n;
14429 : }
14430 : | LATERAL_P xmltable opt_alias_clause
14431 : {
14432 93 : RangeTableFunc *n = (RangeTableFunc *) $2;
14433 :
14434 93 : n->lateral = true;
14435 93 : n->alias = $3;
14436 93 : $$ = (Node *) n;
14437 : }
14438 : | GRAPH_TABLE '(' qualified_name MATCH graph_pattern COLUMNS '(' labeled_expr_list ')' ')' opt_alias_clause
14439 : {
14440 385 : RangeGraphTable *n = makeNode(RangeGraphTable);
14441 :
14442 385 : n->graph_name = $3;
14443 385 : n->graph_pattern = castNode(GraphPattern, $5);
14444 385 : n->columns = $8;
14445 385 : n->alias = $11;
14446 385 : n->location = @1;
14447 385 : $$ = (Node *) n;
14448 : }
14449 : | select_with_parens opt_alias_clause
14450 : {
14451 12202 : RangeSubselect *n = makeNode(RangeSubselect);
14452 :
14453 12202 : n->lateral = false;
14454 12202 : n->subquery = $1;
14455 12202 : n->alias = $2;
14456 12202 : $$ = (Node *) n;
14457 : }
14458 : | LATERAL_P select_with_parens opt_alias_clause
14459 : {
14460 1205 : RangeSubselect *n = makeNode(RangeSubselect);
14461 :
14462 1205 : n->lateral = true;
14463 1205 : n->subquery = $2;
14464 1205 : n->alias = $3;
14465 1205 : $$ = (Node *) n;
14466 : }
14467 : | joined_table
14468 : {
14469 55391 : $$ = (Node *) $1;
14470 : }
14471 : | '(' joined_table ')' alias_clause
14472 : {
14473 120 : $2->alias = $4;
14474 120 : $$ = (Node *) $2;
14475 : }
14476 : | json_table opt_alias_clause
14477 : {
14478 352 : JsonTable *jt = castNode(JsonTable, $1);
14479 :
14480 352 : jt->alias = $2;
14481 352 : $$ = (Node *) jt;
14482 : }
14483 : | LATERAL_P json_table opt_alias_clause
14484 : {
14485 0 : JsonTable *jt = castNode(JsonTable, $2);
14486 :
14487 0 : jt->alias = $3;
14488 0 : jt->lateral = true;
14489 0 : $$ = (Node *) jt;
14490 : }
14491 : ;
14492 :
14493 :
14494 : /*
14495 : * It may seem silly to separate joined_table from table_ref, but there is
14496 : * method in SQL's madness: if you don't do it this way you get reduce-
14497 : * reduce conflicts, because it's not clear to the parser generator whether
14498 : * to expect alias_clause after ')' or not. For the same reason we must
14499 : * treat 'JOIN' and 'join_type JOIN' separately, rather than allowing
14500 : * join_type to expand to empty; if we try it, the parser generator can't
14501 : * figure out when to reduce an empty join_type right after table_ref.
14502 : *
14503 : * Note that a CROSS JOIN is the same as an unqualified
14504 : * INNER JOIN, and an INNER JOIN/ON has the same shape
14505 : * but a qualification expression to limit membership.
14506 : * A NATURAL JOIN implicitly matches column names between
14507 : * tables and the shape is determined by which columns are
14508 : * in common. We'll collect columns during the later transformations.
14509 : */
14510 :
14511 : joined_table:
14512 : '(' joined_table ')'
14513 : {
14514 2318 : $$ = $2;
14515 : }
14516 : | table_ref CROSS JOIN table_ref
14517 : {
14518 : /* CROSS JOIN is same as unqualified inner join */
14519 356 : JoinExpr *n = makeNode(JoinExpr);
14520 :
14521 356 : n->jointype = JOIN_INNER;
14522 356 : n->isNatural = false;
14523 356 : n->larg = $1;
14524 356 : n->rarg = $4;
14525 356 : n->usingClause = NIL;
14526 356 : n->join_using_alias = NULL;
14527 356 : n->quals = NULL;
14528 356 : $$ = n;
14529 : }
14530 : | table_ref join_type JOIN table_ref join_qual
14531 : {
14532 29462 : JoinExpr *n = makeNode(JoinExpr);
14533 :
14534 29462 : n->jointype = $2;
14535 29462 : n->isNatural = false;
14536 29462 : n->larg = $1;
14537 29462 : n->rarg = $4;
14538 29462 : if ($5 != NULL && IsA($5, List))
14539 : {
14540 : /* USING clause */
14541 348 : n->usingClause = linitial_node(List, castNode(List, $5));
14542 348 : n->join_using_alias = lsecond_node(Alias, castNode(List, $5));
14543 : }
14544 : else
14545 : {
14546 : /* ON clause */
14547 29114 : n->quals = $5;
14548 : }
14549 29462 : $$ = n;
14550 : }
14551 : | table_ref JOIN table_ref join_qual
14552 : {
14553 : /* letting join_type reduce to empty doesn't work */
14554 25513 : JoinExpr *n = makeNode(JoinExpr);
14555 :
14556 25513 : n->jointype = JOIN_INNER;
14557 25513 : n->isNatural = false;
14558 25513 : n->larg = $1;
14559 25513 : n->rarg = $3;
14560 25513 : if ($4 != NULL && IsA($4, List))
14561 : {
14562 : /* USING clause */
14563 501 : n->usingClause = linitial_node(List, castNode(List, $4));
14564 501 : n->join_using_alias = lsecond_node(Alias, castNode(List, $4));
14565 : }
14566 : else
14567 : {
14568 : /* ON clause */
14569 25012 : n->quals = $4;
14570 : }
14571 25513 : $$ = n;
14572 : }
14573 : | table_ref NATURAL join_type JOIN table_ref
14574 : {
14575 52 : JoinExpr *n = makeNode(JoinExpr);
14576 :
14577 52 : n->jointype = $3;
14578 52 : n->isNatural = true;
14579 52 : n->larg = $1;
14580 52 : n->rarg = $5;
14581 52 : n->usingClause = NIL; /* figure out which columns later... */
14582 52 : n->join_using_alias = NULL;
14583 52 : n->quals = NULL; /* fill later */
14584 52 : $$ = n;
14585 : }
14586 : | table_ref NATURAL JOIN table_ref
14587 : {
14588 : /* letting join_type reduce to empty doesn't work */
14589 128 : JoinExpr *n = makeNode(JoinExpr);
14590 :
14591 128 : n->jointype = JOIN_INNER;
14592 128 : n->isNatural = true;
14593 128 : n->larg = $1;
14594 128 : n->rarg = $4;
14595 128 : n->usingClause = NIL; /* figure out which columns later... */
14596 128 : n->join_using_alias = NULL;
14597 128 : n->quals = NULL; /* fill later */
14598 128 : $$ = n;
14599 : }
14600 : ;
14601 :
14602 : alias_clause:
14603 : AS ColId '(' name_list ')'
14604 : {
14605 4371 : $$ = makeNode(Alias);
14606 4371 : $$->aliasname = $2;
14607 4371 : $$->colnames = $4;
14608 : }
14609 : | AS ColId
14610 : {
14611 9872 : $$ = makeNode(Alias);
14612 9872 : $$->aliasname = $2;
14613 : }
14614 : | ColId '(' name_list ')'
14615 : {
14616 3762 : $$ = makeNode(Alias);
14617 3762 : $$->aliasname = $1;
14618 3762 : $$->colnames = $3;
14619 : }
14620 : | ColId
14621 : {
14622 172950 : $$ = makeNode(Alias);
14623 172950 : $$->aliasname = $1;
14624 : }
14625 : ;
14626 :
14627 173190 : opt_alias_clause: alias_clause { $$ = $1; }
14628 103896 : | /*EMPTY*/ { $$ = NULL; }
14629 : ;
14630 :
14631 : /*
14632 : * The alias clause after JOIN ... USING only accepts the AS ColId spelling,
14633 : * per SQL standard. (The grammar could parse the other variants, but they
14634 : * don't seem to be useful, and it might lead to parser problems in the
14635 : * future.)
14636 : */
14637 : opt_alias_clause_for_join_using:
14638 : AS ColId
14639 : {
14640 56 : $$ = makeNode(Alias);
14641 56 : $$->aliasname = $2;
14642 : /* the column name list will be inserted later */
14643 : }
14644 793 : | /*EMPTY*/ { $$ = NULL; }
14645 : ;
14646 :
14647 : /*
14648 : * func_alias_clause can include both an Alias and a coldeflist, so we make it
14649 : * return a 2-element list that gets disassembled by calling production.
14650 : */
14651 : func_alias_clause:
14652 : alias_clause
14653 : {
14654 17645 : $$ = list_make2($1, NIL);
14655 : }
14656 : | AS '(' TableFuncElementList ')'
14657 : {
14658 70 : $$ = list_make2(NULL, $3);
14659 : }
14660 : | AS ColId '(' TableFuncElementList ')'
14661 : {
14662 358 : Alias *a = makeNode(Alias);
14663 :
14664 358 : a->aliasname = $2;
14665 358 : $$ = list_make2(a, $4);
14666 : }
14667 : | ColId '(' TableFuncElementList ')'
14668 : {
14669 33 : Alias *a = makeNode(Alias);
14670 :
14671 33 : a->aliasname = $1;
14672 33 : $$ = list_make2(a, $3);
14673 : }
14674 : | /*EMPTY*/
14675 : {
14676 11294 : $$ = list_make2(NULL, NIL);
14677 : }
14678 : ;
14679 :
14680 677 : join_type: FULL opt_outer { $$ = JOIN_FULL; }
14681 26222 : | LEFT opt_outer { $$ = JOIN_LEFT; }
14682 252 : | RIGHT opt_outer { $$ = JOIN_RIGHT; }
14683 2363 : | INNER_P { $$ = JOIN_INNER; }
14684 : ;
14685 :
14686 : /* OUTER is just noise... */
14687 : opt_outer: OUTER_P
14688 : | /*EMPTY*/
14689 : ;
14690 :
14691 : /* JOIN qualification clauses
14692 : * Possibilities are:
14693 : * USING ( column list ) [ AS alias ]
14694 : * allows only unqualified column names,
14695 : * which must match between tables.
14696 : * ON expr allows more general qualifications.
14697 : *
14698 : * We return USING as a two-element List (the first item being a sub-List
14699 : * of the common column names, and the second either an Alias item or NULL).
14700 : * An ON-expr will not be a List, so it can be told apart that way.
14701 : */
14702 :
14703 : join_qual: USING '(' name_list ')' opt_alias_clause_for_join_using
14704 : {
14705 849 : $$ = (Node *) list_make2($3, $5);
14706 : }
14707 : | ON a_expr
14708 : {
14709 54126 : $$ = $2;
14710 : }
14711 : ;
14712 :
14713 :
14714 : relation_expr:
14715 : qualified_name
14716 : {
14717 : /* inheritance query, implicitly */
14718 313177 : $$ = $1;
14719 313177 : $$->inh = true;
14720 313177 : $$->alias = NULL;
14721 : }
14722 : | extended_relation_expr
14723 : {
14724 4552 : $$ = $1;
14725 : }
14726 : ;
14727 :
14728 : extended_relation_expr:
14729 : qualified_name '*'
14730 : {
14731 : /* inheritance query, explicitly */
14732 140 : $$ = $1;
14733 140 : $$->inh = true;
14734 140 : $$->alias = NULL;
14735 : }
14736 : | ONLY qualified_name
14737 : {
14738 : /* no inheritance */
14739 4416 : $$ = $2;
14740 4416 : $$->inh = false;
14741 4416 : $$->alias = NULL;
14742 : }
14743 : | ONLY '(' qualified_name ')'
14744 : {
14745 : /* no inheritance, SQL99-style syntax */
14746 0 : $$ = $3;
14747 0 : $$->inh = false;
14748 0 : $$->alias = NULL;
14749 : }
14750 : ;
14751 :
14752 :
14753 : relation_expr_list:
14754 1802 : relation_expr { $$ = list_make1($1); }
14755 6131 : | relation_expr_list ',' relation_expr { $$ = lappend($1, $3); }
14756 : ;
14757 :
14758 :
14759 : /*
14760 : * Given "UPDATE foo set set ...", we have to decide without looking any
14761 : * further ahead whether the first "set" is an alias or the UPDATE's SET
14762 : * keyword. Since "set" is allowed as a column name both interpretations
14763 : * are feasible. We resolve the shift/reduce conflict by giving the first
14764 : * relation_expr_opt_alias production a higher precedence than the SET token
14765 : * has, causing the parser to prefer to reduce, in effect assuming that the
14766 : * SET is not an alias.
14767 : */
14768 : relation_expr_opt_alias: relation_expr %prec UMINUS
14769 : {
14770 11593 : $$ = $1;
14771 : }
14772 : | relation_expr ColId
14773 : {
14774 1489 : Alias *alias = makeNode(Alias);
14775 :
14776 1489 : alias->aliasname = $2;
14777 1489 : $1->alias = alias;
14778 1489 : $$ = $1;
14779 : }
14780 : | relation_expr AS ColId
14781 : {
14782 59 : Alias *alias = makeNode(Alias);
14783 :
14784 59 : alias->aliasname = $3;
14785 59 : $1->alias = alias;
14786 59 : $$ = $1;
14787 : }
14788 : ;
14789 :
14790 : /*
14791 : * TABLESAMPLE decoration in a FROM item
14792 : */
14793 : tablesample_clause:
14794 : TABLESAMPLE func_name '(' expr_list ')' opt_repeatable_clause
14795 : {
14796 170 : RangeTableSample *n = makeNode(RangeTableSample);
14797 :
14798 : /* n->relation will be filled in later */
14799 170 : n->method = $2;
14800 170 : n->args = $4;
14801 170 : n->repeatable = $6;
14802 170 : n->location = @2;
14803 170 : $$ = (Node *) n;
14804 : }
14805 : ;
14806 :
14807 : opt_repeatable_clause:
14808 71 : REPEATABLE '(' a_expr ')' { $$ = (Node *) $3; }
14809 99 : | /*EMPTY*/ { $$ = NULL; }
14810 : ;
14811 :
14812 : /*
14813 : * func_table represents a function invocation in a FROM list. It can be
14814 : * a plain function call, like "foo(...)", or a ROWS FROM expression with
14815 : * one or more function calls, "ROWS FROM (foo(...), bar(...))",
14816 : * optionally with WITH ORDINALITY attached.
14817 : * In the ROWS FROM syntax, a column definition list can be given for each
14818 : * function, for example:
14819 : * ROWS FROM (foo() AS (foo_res_a text, foo_res_b text),
14820 : * bar() AS (bar_res_a text, bar_res_b text))
14821 : * It's also possible to attach a column definition list to the RangeFunction
14822 : * as a whole, but that's handled by the table_ref production.
14823 : */
14824 : func_table: func_expr_windowless opt_ordinality
14825 : {
14826 29316 : RangeFunction *n = makeNode(RangeFunction);
14827 :
14828 29316 : n->lateral = false;
14829 29316 : n->ordinality = $2;
14830 29316 : n->is_rowsfrom = false;
14831 29316 : n->functions = list_make1(list_make2($1, NIL));
14832 : /* alias and coldeflist are set by table_ref production */
14833 29316 : $$ = (Node *) n;
14834 : }
14835 : | ROWS FROM '(' rowsfrom_list ')' opt_ordinality
14836 : {
14837 88 : RangeFunction *n = makeNode(RangeFunction);
14838 :
14839 88 : n->lateral = false;
14840 88 : n->ordinality = $6;
14841 88 : n->is_rowsfrom = true;
14842 88 : n->functions = $4;
14843 : /* alias and coldeflist are set by table_ref production */
14844 88 : $$ = (Node *) n;
14845 : }
14846 : ;
14847 :
14848 : rowsfrom_item: func_expr_windowless opt_col_def_list
14849 212 : { $$ = list_make2($1, $2); }
14850 : ;
14851 :
14852 : rowsfrom_list:
14853 88 : rowsfrom_item { $$ = list_make1($1); }
14854 124 : | rowsfrom_list ',' rowsfrom_item { $$ = lappend($1, $3); }
14855 : ;
14856 :
14857 36 : opt_col_def_list: AS '(' TableFuncElementList ')' { $$ = $3; }
14858 176 : | /*EMPTY*/ { $$ = NIL; }
14859 : ;
14860 :
14861 603 : opt_ordinality: WITH_LA ORDINALITY { $$ = true; }
14862 28801 : | /*EMPTY*/ { $$ = false; }
14863 : ;
14864 :
14865 :
14866 : where_clause:
14867 142328 : WHERE a_expr { $$ = $2; }
14868 183371 : | /*EMPTY*/ { $$ = NULL; }
14869 : ;
14870 :
14871 : /* variant for UPDATE and DELETE */
14872 : where_or_current_clause:
14873 8315 : WHERE a_expr { $$ = $2; }
14874 : | WHERE CURRENT_P OF cursor_name
14875 : {
14876 176 : CurrentOfExpr *n = makeNode(CurrentOfExpr);
14877 :
14878 : /* cvarno is filled in by parse analysis */
14879 176 : n->cursor_name = $4;
14880 176 : n->cursor_param = 0;
14881 176 : $$ = (Node *) n;
14882 : }
14883 3192 : | /*EMPTY*/ { $$ = NULL; }
14884 : ;
14885 :
14886 :
14887 : OptTableFuncElementList:
14888 464 : TableFuncElementList { $$ = $1; }
14889 1894 : | /*EMPTY*/ { $$ = NIL; }
14890 : ;
14891 :
14892 : TableFuncElementList:
14893 : TableFuncElement
14894 : {
14895 961 : $$ = list_make1($1);
14896 : }
14897 : | TableFuncElementList ',' TableFuncElement
14898 : {
14899 1265 : $$ = lappend($1, $3);
14900 : }
14901 : ;
14902 :
14903 : TableFuncElement: ColId Typename opt_collate_clause
14904 : {
14905 2268 : ColumnDef *n = makeNode(ColumnDef);
14906 :
14907 2268 : n->colname = $1;
14908 2268 : n->typeName = $2;
14909 2268 : n->inhcount = 0;
14910 2268 : n->is_local = true;
14911 2268 : n->is_not_null = false;
14912 2268 : n->is_from_type = false;
14913 2268 : n->storage = 0;
14914 2268 : n->raw_default = NULL;
14915 2268 : n->cooked_default = NULL;
14916 2268 : n->collClause = (CollateClause *) $3;
14917 2268 : n->collOid = InvalidOid;
14918 2268 : n->constraints = NIL;
14919 2268 : n->location = @1;
14920 2268 : $$ = (Node *) n;
14921 : }
14922 : ;
14923 :
14924 : /*
14925 : * XMLTABLE
14926 : */
14927 : xmltable:
14928 : XMLTABLE '(' c_expr xmlexists_argument COLUMNS xmltable_column_list ')'
14929 : {
14930 137 : RangeTableFunc *n = makeNode(RangeTableFunc);
14931 :
14932 137 : n->rowexpr = $3;
14933 137 : n->docexpr = $4;
14934 137 : n->columns = $6;
14935 137 : n->namespaces = NIL;
14936 137 : n->location = @1;
14937 137 : $$ = (Node *) n;
14938 : }
14939 : | XMLTABLE '(' XMLNAMESPACES '(' xml_namespace_list ')' ','
14940 : c_expr xmlexists_argument COLUMNS xmltable_column_list ')'
14941 : {
14942 13 : RangeTableFunc *n = makeNode(RangeTableFunc);
14943 :
14944 13 : n->rowexpr = $8;
14945 13 : n->docexpr = $9;
14946 13 : n->columns = $11;
14947 13 : n->namespaces = $5;
14948 13 : n->location = @1;
14949 13 : $$ = (Node *) n;
14950 : }
14951 : ;
14952 :
14953 150 : xmltable_column_list: xmltable_column_el { $$ = list_make1($1); }
14954 351 : | xmltable_column_list ',' xmltable_column_el { $$ = lappend($1, $3); }
14955 : ;
14956 :
14957 : xmltable_column_el:
14958 : ColId Typename
14959 : {
14960 136 : RangeTableFuncCol *fc = makeNode(RangeTableFuncCol);
14961 :
14962 136 : fc->colname = $1;
14963 136 : fc->for_ordinality = false;
14964 136 : fc->typeName = $2;
14965 136 : fc->is_not_null = false;
14966 136 : fc->colexpr = NULL;
14967 136 : fc->coldefexpr = NULL;
14968 136 : fc->location = @1;
14969 :
14970 136 : $$ = (Node *) fc;
14971 : }
14972 : | ColId Typename xmltable_column_option_list
14973 : {
14974 324 : RangeTableFuncCol *fc = makeNode(RangeTableFuncCol);
14975 : ListCell *option;
14976 324 : bool nullability_seen = false;
14977 :
14978 324 : fc->colname = $1;
14979 324 : fc->typeName = $2;
14980 324 : fc->for_ordinality = false;
14981 324 : fc->is_not_null = false;
14982 324 : fc->colexpr = NULL;
14983 324 : fc->coldefexpr = NULL;
14984 324 : fc->location = @1;
14985 :
14986 722 : foreach(option, $3)
14987 : {
14988 398 : DefElem *defel = (DefElem *) lfirst(option);
14989 :
14990 398 : if (strcmp(defel->defname, "default") == 0)
14991 : {
14992 37 : if (fc->coldefexpr != NULL)
14993 0 : ereport(ERROR,
14994 : (errcode(ERRCODE_SYNTAX_ERROR),
14995 : errmsg("only one DEFAULT value is allowed"),
14996 : parser_errposition(defel->location)));
14997 37 : fc->coldefexpr = defel->arg;
14998 : }
14999 361 : else if (strcmp(defel->defname, "path") == 0)
15000 : {
15001 324 : if (fc->colexpr != NULL)
15002 0 : ereport(ERROR,
15003 : (errcode(ERRCODE_SYNTAX_ERROR),
15004 : errmsg("only one PATH value per column is allowed"),
15005 : parser_errposition(defel->location)));
15006 324 : fc->colexpr = defel->arg;
15007 : }
15008 37 : else if (strcmp(defel->defname, "__pg__is_not_null") == 0)
15009 : {
15010 37 : if (nullability_seen)
15011 0 : ereport(ERROR,
15012 : (errcode(ERRCODE_SYNTAX_ERROR),
15013 : errmsg("conflicting or redundant NULL / NOT NULL declarations for column \"%s\"", fc->colname),
15014 : parser_errposition(defel->location)));
15015 37 : fc->is_not_null = boolVal(defel->arg);
15016 37 : nullability_seen = true;
15017 : }
15018 : else
15019 : {
15020 0 : ereport(ERROR,
15021 : (errcode(ERRCODE_SYNTAX_ERROR),
15022 : errmsg("unrecognized column option \"%s\"",
15023 : defel->defname),
15024 : parser_errposition(defel->location)));
15025 : }
15026 : }
15027 324 : $$ = (Node *) fc;
15028 : }
15029 : | ColId FOR ORDINALITY
15030 : {
15031 41 : RangeTableFuncCol *fc = makeNode(RangeTableFuncCol);
15032 :
15033 41 : fc->colname = $1;
15034 41 : fc->for_ordinality = true;
15035 : /* other fields are ignored, initialized by makeNode */
15036 41 : fc->location = @1;
15037 :
15038 41 : $$ = (Node *) fc;
15039 : }
15040 : ;
15041 :
15042 : xmltable_column_option_list:
15043 : xmltable_column_option_el
15044 324 : { $$ = list_make1($1); }
15045 : | xmltable_column_option_list xmltable_column_option_el
15046 74 : { $$ = lappend($1, $2); }
15047 : ;
15048 :
15049 : xmltable_column_option_el:
15050 : IDENT b_expr
15051 : {
15052 4 : if (strcmp($1, "__pg__is_not_null") == 0)
15053 4 : ereport(ERROR,
15054 : (errcode(ERRCODE_SYNTAX_ERROR),
15055 : errmsg("option name \"%s\" cannot be used in XMLTABLE", $1),
15056 : parser_errposition(@1)));
15057 0 : $$ = makeDefElem($1, $2, @1);
15058 : }
15059 : | DEFAULT b_expr
15060 37 : { $$ = makeDefElem("default", $2, @1); }
15061 : | NOT NULL_P
15062 37 : { $$ = makeDefElem("__pg__is_not_null", (Node *) makeBoolean(true), @1); }
15063 : | NULL_P
15064 0 : { $$ = makeDefElem("__pg__is_not_null", (Node *) makeBoolean(false), @1); }
15065 : | PATH b_expr
15066 324 : { $$ = makeDefElem("path", $2, @1); }
15067 : ;
15068 :
15069 : xml_namespace_list:
15070 : xml_namespace_el
15071 13 : { $$ = list_make1($1); }
15072 : | xml_namespace_list ',' xml_namespace_el
15073 0 : { $$ = lappend($1, $3); }
15074 : ;
15075 :
15076 : xml_namespace_el:
15077 : b_expr AS ColLabel
15078 : {
15079 9 : $$ = makeNode(ResTarget);
15080 9 : $$->name = $3;
15081 9 : $$->indirection = NIL;
15082 9 : $$->val = $1;
15083 9 : $$->location = @1;
15084 : }
15085 : | DEFAULT b_expr
15086 : {
15087 4 : $$ = makeNode(ResTarget);
15088 4 : $$->name = NULL;
15089 4 : $$->indirection = NIL;
15090 4 : $$->val = $2;
15091 4 : $$->location = @1;
15092 : }
15093 : ;
15094 :
15095 : json_table:
15096 : JSON_TABLE '('
15097 : json_value_expr ',' a_expr json_table_path_name_opt
15098 : json_passing_clause_opt
15099 : COLUMNS '(' json_table_column_definition_list ')'
15100 : json_on_error_clause_opt
15101 : ')'
15102 : {
15103 356 : JsonTable *n = makeNode(JsonTable);
15104 : char *pathstring;
15105 :
15106 356 : n->context_item = (JsonValueExpr *) $3;
15107 356 : if (!IsA($5, A_Const) ||
15108 352 : castNode(A_Const, $5)->val.node.type != T_String)
15109 4 : ereport(ERROR,
15110 : errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
15111 : errmsg("only string constants are supported in JSON_TABLE path specification"),
15112 : parser_errposition(@5));
15113 352 : pathstring = castNode(A_Const, $5)->val.sval.sval;
15114 352 : n->pathspec = makeJsonTablePathSpec(pathstring, $6, @5, @6);
15115 352 : n->passing = $7;
15116 352 : n->columns = $10;
15117 352 : n->on_error = (JsonBehavior *) $12;
15118 352 : n->location = @1;
15119 352 : $$ = (Node *) n;
15120 : }
15121 : ;
15122 :
15123 : json_table_path_name_opt:
15124 40 : AS name { $$ = $2; }
15125 324 : | /* empty */ { $$ = NULL; }
15126 : ;
15127 :
15128 : json_table_column_definition_list:
15129 : json_table_column_definition
15130 548 : { $$ = list_make1($1); }
15131 : | json_table_column_definition_list ',' json_table_column_definition
15132 352 : { $$ = lappend($1, $3); }
15133 : ;
15134 :
15135 : json_table_column_definition:
15136 : ColId FOR ORDINALITY
15137 : {
15138 56 : JsonTableColumn *n = makeNode(JsonTableColumn);
15139 :
15140 56 : n->coltype = JTC_FOR_ORDINALITY;
15141 56 : n->name = $1;
15142 56 : n->location = @1;
15143 56 : $$ = (Node *) n;
15144 : }
15145 : | ColId Typename
15146 : json_table_column_path_clause_opt
15147 : json_wrapper_behavior
15148 : json_quotes_clause_opt
15149 : json_behavior_clause_opt
15150 : {
15151 488 : JsonTableColumn *n = makeNode(JsonTableColumn);
15152 :
15153 488 : n->coltype = JTC_REGULAR;
15154 488 : n->name = $1;
15155 488 : n->typeName = $2;
15156 488 : n->format = makeJsonFormat(JS_FORMAT_DEFAULT, JS_ENC_DEFAULT, -1);
15157 488 : n->pathspec = (JsonTablePathSpec *) $3;
15158 488 : n->wrapper = $4;
15159 488 : n->quotes = $5;
15160 488 : n->on_empty = (JsonBehavior *) linitial($6);
15161 488 : n->on_error = (JsonBehavior *) lsecond($6);
15162 488 : n->location = @1;
15163 488 : $$ = (Node *) n;
15164 : }
15165 : | ColId Typename json_format_clause
15166 : json_table_column_path_clause_opt
15167 : json_wrapper_behavior
15168 : json_quotes_clause_opt
15169 : json_behavior_clause_opt
15170 : {
15171 72 : JsonTableColumn *n = makeNode(JsonTableColumn);
15172 :
15173 72 : n->coltype = JTC_FORMATTED;
15174 72 : n->name = $1;
15175 72 : n->typeName = $2;
15176 72 : n->format = (JsonFormat *) $3;
15177 72 : n->pathspec = (JsonTablePathSpec *) $4;
15178 72 : n->wrapper = $5;
15179 72 : n->quotes = $6;
15180 72 : n->on_empty = (JsonBehavior *) linitial($7);
15181 72 : n->on_error = (JsonBehavior *) lsecond($7);
15182 72 : n->location = @1;
15183 72 : $$ = (Node *) n;
15184 : }
15185 : | ColId Typename
15186 : EXISTS json_table_column_path_clause_opt
15187 : json_on_error_clause_opt
15188 : {
15189 92 : JsonTableColumn *n = makeNode(JsonTableColumn);
15190 :
15191 92 : n->coltype = JTC_EXISTS;
15192 92 : n->name = $1;
15193 92 : n->typeName = $2;
15194 92 : n->format = makeJsonFormat(JS_FORMAT_DEFAULT, JS_ENC_DEFAULT, -1);
15195 92 : n->wrapper = JSW_NONE;
15196 92 : n->quotes = JS_QUOTES_UNSPEC;
15197 92 : n->pathspec = (JsonTablePathSpec *) $4;
15198 92 : n->on_empty = NULL;
15199 92 : n->on_error = (JsonBehavior *) $5;
15200 92 : n->location = @1;
15201 92 : $$ = (Node *) n;
15202 : }
15203 : | NESTED path_opt Sconst
15204 : COLUMNS '(' json_table_column_definition_list ')'
15205 : {
15206 96 : JsonTableColumn *n = makeNode(JsonTableColumn);
15207 :
15208 96 : n->coltype = JTC_NESTED;
15209 192 : n->pathspec = (JsonTablePathSpec *)
15210 96 : makeJsonTablePathSpec($3, NULL, @3, -1);
15211 96 : n->columns = $6;
15212 96 : n->location = @1;
15213 96 : $$ = (Node *) n;
15214 : }
15215 : | NESTED path_opt Sconst AS name
15216 : COLUMNS '(' json_table_column_definition_list ')'
15217 : {
15218 96 : JsonTableColumn *n = makeNode(JsonTableColumn);
15219 :
15220 96 : n->coltype = JTC_NESTED;
15221 192 : n->pathspec = (JsonTablePathSpec *)
15222 96 : makeJsonTablePathSpec($3, $5, @3, @5);
15223 96 : n->columns = $8;
15224 96 : n->location = @1;
15225 96 : $$ = (Node *) n;
15226 : }
15227 : ;
15228 :
15229 : path_opt:
15230 : PATH
15231 : | /* EMPTY */
15232 : ;
15233 :
15234 : json_table_column_path_clause_opt:
15235 : PATH Sconst
15236 552 : { $$ = (Node *) makeJsonTablePathSpec($2, NULL, @2, -1); }
15237 : | /* EMPTY */
15238 104 : { $$ = NULL; }
15239 : ;
15240 :
15241 : /*****************************************************************************
15242 : *
15243 : * Type syntax
15244 : * SQL introduces a large amount of type-specific syntax.
15245 : * Define individual clauses to handle these cases, and use
15246 : * the generic case to handle regular type-extensible Postgres syntax.
15247 : * - thomas 1997-10-10
15248 : *
15249 : *****************************************************************************/
15250 :
15251 : Typename: SimpleTypename opt_array_bounds
15252 : {
15253 299145 : $$ = $1;
15254 299145 : $$->arrayBounds = $2;
15255 : }
15256 : | SETOF SimpleTypename opt_array_bounds
15257 : {
15258 991 : $$ = $2;
15259 991 : $$->arrayBounds = $3;
15260 991 : $$->setof = true;
15261 : }
15262 : /* SQL standard syntax, currently only one-dimensional */
15263 : | SimpleTypename ARRAY '[' Iconst ']'
15264 : {
15265 4 : $$ = $1;
15266 4 : $$->arrayBounds = list_make1(makeInteger($4));
15267 : }
15268 : | SETOF SimpleTypename ARRAY '[' Iconst ']'
15269 : {
15270 0 : $$ = $2;
15271 0 : $$->arrayBounds = list_make1(makeInteger($5));
15272 0 : $$->setof = true;
15273 : }
15274 : | SimpleTypename ARRAY
15275 : {
15276 0 : $$ = $1;
15277 0 : $$->arrayBounds = list_make1(makeInteger(-1));
15278 : }
15279 : | SETOF SimpleTypename ARRAY
15280 : {
15281 0 : $$ = $2;
15282 0 : $$->arrayBounds = list_make1(makeInteger(-1));
15283 0 : $$->setof = true;
15284 : }
15285 : ;
15286 :
15287 : opt_array_bounds:
15288 : opt_array_bounds '[' ']'
15289 8666 : { $$ = lappend($1, makeInteger(-1)); }
15290 : | opt_array_bounds '[' Iconst ']'
15291 38 : { $$ = lappend($1, makeInteger($3)); }
15292 : | /*EMPTY*/
15293 300136 : { $$ = NIL; }
15294 : ;
15295 :
15296 : SimpleTypename:
15297 235915 : GenericType { $$ = $1; }
15298 54874 : | Numeric { $$ = $1; }
15299 1269 : | Bit { $$ = $1; }
15300 2185 : | Character { $$ = $1; }
15301 2863 : | ConstDatetime { $$ = $1; }
15302 : | ConstInterval opt_interval
15303 : {
15304 2124 : $$ = $1;
15305 2124 : $$->typmods = $2;
15306 : }
15307 : | ConstInterval '(' Iconst ')'
15308 : {
15309 0 : $$ = $1;
15310 0 : $$->typmods = list_make2(makeIntConst(INTERVAL_FULL_RANGE, -1),
15311 : makeIntConst($3, @3));
15312 : }
15313 1173 : | JsonType { $$ = $1; }
15314 : ;
15315 :
15316 : /* We have a separate ConstTypename to allow defaulting fixed-length
15317 : * types such as CHAR() and BIT() to an unspecified length.
15318 : * SQL9x requires that these default to a length of one, but this
15319 : * makes no sense for constructs like CHAR 'hi' and BIT '0101',
15320 : * where there is an obvious better choice to make.
15321 : * Note that ConstInterval is not included here since it must
15322 : * be pushed up higher in the rules to accommodate the postfix
15323 : * options (e.g. INTERVAL '1' YEAR). Likewise, we have to handle
15324 : * the generic-type-name case in AexprConst to avoid premature
15325 : * reduce/reduce conflicts against function names.
15326 : */
15327 : ConstTypename:
15328 52 : Numeric { $$ = $1; }
15329 0 : | ConstBit { $$ = $1; }
15330 22 : | ConstCharacter { $$ = $1; }
15331 1793 : | ConstDatetime { $$ = $1; }
15332 176 : | JsonType { $$ = $1; }
15333 : ;
15334 :
15335 : /*
15336 : * GenericType covers all type names that don't have special syntax mandated
15337 : * by the standard, including qualified names. We also allow type modifiers.
15338 : * To avoid parsing conflicts against function invocations, the modifiers
15339 : * have to be shown as expr_list here, but parse analysis will only accept
15340 : * constants for them.
15341 : */
15342 : GenericType:
15343 : type_function_name opt_type_modifiers
15344 : {
15345 165457 : $$ = makeTypeName($1);
15346 165457 : $$->typmods = $2;
15347 165457 : $$->location = @1;
15348 : }
15349 : | type_function_name attrs opt_type_modifiers
15350 : {
15351 70458 : $$ = makeTypeNameFromNameList(lcons(makeString($1), $2));
15352 70458 : $$->typmods = $3;
15353 70458 : $$->location = @1;
15354 : }
15355 : ;
15356 :
15357 772 : opt_type_modifiers: '(' expr_list ')' { $$ = $2; }
15358 238919 : | /* EMPTY */ { $$ = NIL; }
15359 : ;
15360 :
15361 : /*
15362 : * SQL numeric data types
15363 : */
15364 : Numeric: INT_P
15365 : {
15366 25441 : $$ = SystemTypeName("int4");
15367 25441 : $$->location = @1;
15368 : }
15369 : | INTEGER
15370 : {
15371 13696 : $$ = SystemTypeName("int4");
15372 13696 : $$->location = @1;
15373 : }
15374 : | SMALLINT
15375 : {
15376 704 : $$ = SystemTypeName("int2");
15377 704 : $$->location = @1;
15378 : }
15379 : | BIGINT
15380 : {
15381 2571 : $$ = SystemTypeName("int8");
15382 2571 : $$->location = @1;
15383 : }
15384 : | REAL
15385 : {
15386 3672 : $$ = SystemTypeName("float4");
15387 3672 : $$->location = @1;
15388 : }
15389 : | FLOAT_P opt_float
15390 : {
15391 346 : $$ = $2;
15392 346 : $$->location = @1;
15393 : }
15394 : | DOUBLE_P PRECISION
15395 : {
15396 445 : $$ = SystemTypeName("float8");
15397 445 : $$->location = @1;
15398 : }
15399 : | DECIMAL_P opt_type_modifiers
15400 : {
15401 20 : $$ = SystemTypeName("numeric");
15402 20 : $$->typmods = $2;
15403 20 : $$->location = @1;
15404 : }
15405 : | DEC opt_type_modifiers
15406 : {
15407 0 : $$ = SystemTypeName("numeric");
15408 0 : $$->typmods = $2;
15409 0 : $$->location = @1;
15410 : }
15411 : | NUMERIC opt_type_modifiers
15412 : {
15413 3756 : $$ = SystemTypeName("numeric");
15414 3756 : $$->typmods = $2;
15415 3756 : $$->location = @1;
15416 : }
15417 : | BOOLEAN_P
15418 : {
15419 4275 : $$ = SystemTypeName("bool");
15420 4275 : $$->location = @1;
15421 : }
15422 : ;
15423 :
15424 : opt_float: '(' Iconst ')'
15425 : {
15426 : /*
15427 : * Check FLOAT() precision limits assuming IEEE floating
15428 : * types - thomas 1997-09-18
15429 : */
15430 1 : if ($2 < 1)
15431 0 : ereport(ERROR,
15432 : (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
15433 : errmsg("precision for type float must be at least 1 bit"),
15434 : parser_errposition(@2)));
15435 1 : else if ($2 <= 24)
15436 1 : $$ = SystemTypeName("float4");
15437 0 : else if ($2 <= 53)
15438 0 : $$ = SystemTypeName("float8");
15439 : else
15440 0 : ereport(ERROR,
15441 : (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
15442 : errmsg("precision for type float must be less than 54 bits"),
15443 : parser_errposition(@2)));
15444 : }
15445 : | /*EMPTY*/
15446 : {
15447 345 : $$ = SystemTypeName("float8");
15448 : }
15449 : ;
15450 :
15451 : /*
15452 : * SQL bit-field data types
15453 : * The following implements BIT() and BIT VARYING().
15454 : */
15455 : Bit: BitWithLength
15456 : {
15457 1146 : $$ = $1;
15458 : }
15459 : | BitWithoutLength
15460 : {
15461 123 : $$ = $1;
15462 : }
15463 : ;
15464 :
15465 : /* ConstBit is like Bit except "BIT" defaults to unspecified length */
15466 : /* See notes for ConstCharacter, which addresses same issue for "CHAR" */
15467 : ConstBit: BitWithLength
15468 : {
15469 0 : $$ = $1;
15470 : }
15471 : | BitWithoutLength
15472 : {
15473 0 : $$ = $1;
15474 0 : $$->typmods = NIL;
15475 : }
15476 : ;
15477 :
15478 : BitWithLength:
15479 : BIT opt_varying '(' expr_list ')'
15480 : {
15481 : char *typname;
15482 :
15483 1146 : typname = $2 ? "varbit" : "bit";
15484 1146 : $$ = SystemTypeName(typname);
15485 1146 : $$->typmods = $4;
15486 1146 : $$->location = @1;
15487 : }
15488 : ;
15489 :
15490 : BitWithoutLength:
15491 : BIT opt_varying
15492 : {
15493 : /* bit defaults to bit(1), varbit to no limit */
15494 123 : if ($2)
15495 : {
15496 10 : $$ = SystemTypeName("varbit");
15497 : }
15498 : else
15499 : {
15500 113 : $$ = SystemTypeName("bit");
15501 113 : $$->typmods = list_make1(makeIntConst(1, -1));
15502 : }
15503 123 : $$->location = @1;
15504 : }
15505 : ;
15506 :
15507 :
15508 : /*
15509 : * SQL character data types
15510 : * The following implements CHAR() and VARCHAR().
15511 : */
15512 : Character: CharacterWithLength
15513 : {
15514 1334 : $$ = $1;
15515 : }
15516 : | CharacterWithoutLength
15517 : {
15518 851 : $$ = $1;
15519 : }
15520 : ;
15521 :
15522 : ConstCharacter: CharacterWithLength
15523 : {
15524 8 : $$ = $1;
15525 : }
15526 : | CharacterWithoutLength
15527 : {
15528 : /* Length was not specified so allow to be unrestricted.
15529 : * This handles problems with fixed-length (bpchar) strings
15530 : * which in column definitions must default to a length
15531 : * of one, but should not be constrained if the length
15532 : * was not specified.
15533 : */
15534 14 : $$ = $1;
15535 14 : $$->typmods = NIL;
15536 : }
15537 : ;
15538 :
15539 : CharacterWithLength: character '(' Iconst ')'
15540 : {
15541 1342 : $$ = SystemTypeName($1);
15542 1342 : $$->typmods = list_make1(makeIntConst($3, @3));
15543 1342 : $$->location = @1;
15544 : }
15545 : ;
15546 :
15547 : CharacterWithoutLength: character
15548 : {
15549 865 : $$ = SystemTypeName($1);
15550 : /* char defaults to char(1), varchar to no limit */
15551 865 : if (strcmp($1, "bpchar") == 0)
15552 154 : $$->typmods = list_make1(makeIntConst(1, -1));
15553 865 : $$->location = @1;
15554 : }
15555 : ;
15556 :
15557 : character: CHARACTER opt_varying
15558 319 : { $$ = $2 ? "varchar": "bpchar"; }
15559 : | CHAR_P opt_varying
15560 745 : { $$ = $2 ? "varchar": "bpchar"; }
15561 : | VARCHAR
15562 1141 : { $$ = "varchar"; }
15563 : | NATIONAL CHARACTER opt_varying
15564 0 : { $$ = $3 ? "varchar": "bpchar"; }
15565 : | NATIONAL CHAR_P opt_varying
15566 0 : { $$ = $3 ? "varchar": "bpchar"; }
15567 : | NCHAR opt_varying
15568 2 : { $$ = $2 ? "varchar": "bpchar"; }
15569 : ;
15570 :
15571 : opt_varying:
15572 273 : VARYING { $$ = true; }
15573 2062 : | /*EMPTY*/ { $$ = false; }
15574 : ;
15575 :
15576 : /*
15577 : * SQL date/time types
15578 : */
15579 : ConstDatetime:
15580 : TIMESTAMP '(' Iconst ')' opt_timezone
15581 : {
15582 73 : if ($5)
15583 58 : $$ = SystemTypeName("timestamptz");
15584 : else
15585 15 : $$ = SystemTypeName("timestamp");
15586 73 : $$->typmods = list_make1(makeIntConst($3, @3));
15587 73 : $$->location = @1;
15588 : }
15589 : | TIMESTAMP opt_timezone
15590 : {
15591 3108 : if ($2)
15592 774 : $$ = SystemTypeName("timestamptz");
15593 : else
15594 2334 : $$ = SystemTypeName("timestamp");
15595 3108 : $$->location = @1;
15596 : }
15597 : | TIME '(' Iconst ')' opt_timezone
15598 : {
15599 14 : if ($5)
15600 5 : $$ = SystemTypeName("timetz");
15601 : else
15602 9 : $$ = SystemTypeName("time");
15603 14 : $$->typmods = list_make1(makeIntConst($3, @3));
15604 14 : $$->location = @1;
15605 : }
15606 : | TIME opt_timezone
15607 : {
15608 1461 : if ($2)
15609 226 : $$ = SystemTypeName("timetz");
15610 : else
15611 1235 : $$ = SystemTypeName("time");
15612 1461 : $$->location = @1;
15613 : }
15614 : ;
15615 :
15616 : ConstInterval:
15617 : INTERVAL
15618 : {
15619 4328 : $$ = SystemTypeName("interval");
15620 4328 : $$->location = @1;
15621 : }
15622 : ;
15623 :
15624 : opt_timezone:
15625 1063 : WITH_LA TIME ZONE { $$ = true; }
15626 376 : | WITHOUT_LA TIME ZONE { $$ = false; }
15627 3217 : | /*EMPTY*/ { $$ = false; }
15628 : ;
15629 :
15630 : opt_interval:
15631 : YEAR_P
15632 8 : { $$ = list_make1(makeIntConst(INTERVAL_MASK(YEAR), @1)); }
15633 : | MONTH_P
15634 12 : { $$ = list_make1(makeIntConst(INTERVAL_MASK(MONTH), @1)); }
15635 : | DAY_P
15636 12 : { $$ = list_make1(makeIntConst(INTERVAL_MASK(DAY), @1)); }
15637 : | HOUR_P
15638 8 : { $$ = list_make1(makeIntConst(INTERVAL_MASK(HOUR), @1)); }
15639 : | MINUTE_P
15640 8 : { $$ = list_make1(makeIntConst(INTERVAL_MASK(MINUTE), @1)); }
15641 : | interval_second
15642 24 : { $$ = $1; }
15643 : | YEAR_P TO MONTH_P
15644 : {
15645 12 : $$ = list_make1(makeIntConst(INTERVAL_MASK(YEAR) |
15646 : INTERVAL_MASK(MONTH), @1));
15647 : }
15648 : | DAY_P TO HOUR_P
15649 : {
15650 16 : $$ = list_make1(makeIntConst(INTERVAL_MASK(DAY) |
15651 : INTERVAL_MASK(HOUR), @1));
15652 : }
15653 : | DAY_P TO MINUTE_P
15654 : {
15655 16 : $$ = list_make1(makeIntConst(INTERVAL_MASK(DAY) |
15656 : INTERVAL_MASK(HOUR) |
15657 : INTERVAL_MASK(MINUTE), @1));
15658 : }
15659 : | DAY_P TO interval_second
15660 : {
15661 32 : $$ = $3;
15662 32 : linitial($$) = makeIntConst(INTERVAL_MASK(DAY) |
15663 : INTERVAL_MASK(HOUR) |
15664 : INTERVAL_MASK(MINUTE) |
15665 32 : INTERVAL_MASK(SECOND), @1);
15666 : }
15667 : | HOUR_P TO MINUTE_P
15668 : {
15669 12 : $$ = list_make1(makeIntConst(INTERVAL_MASK(HOUR) |
15670 : INTERVAL_MASK(MINUTE), @1));
15671 : }
15672 : | HOUR_P TO interval_second
15673 : {
15674 24 : $$ = $3;
15675 24 : linitial($$) = makeIntConst(INTERVAL_MASK(HOUR) |
15676 : INTERVAL_MASK(MINUTE) |
15677 24 : INTERVAL_MASK(SECOND), @1);
15678 : }
15679 : | MINUTE_P TO interval_second
15680 : {
15681 44 : $$ = $3;
15682 44 : linitial($$) = makeIntConst(INTERVAL_MASK(MINUTE) |
15683 44 : INTERVAL_MASK(SECOND), @1);
15684 : }
15685 : | /*EMPTY*/
15686 4092 : { $$ = NIL; }
15687 : ;
15688 :
15689 : interval_second:
15690 : SECOND_P
15691 : {
15692 68 : $$ = list_make1(makeIntConst(INTERVAL_MASK(SECOND), @1));
15693 : }
15694 : | SECOND_P '(' Iconst ')'
15695 : {
15696 56 : $$ = list_make2(makeIntConst(INTERVAL_MASK(SECOND), @1),
15697 : makeIntConst($3, @3));
15698 : }
15699 : ;
15700 :
15701 : JsonType:
15702 : JSON
15703 : {
15704 1349 : $$ = SystemTypeName("json");
15705 1349 : $$->location = @1;
15706 : }
15707 : ;
15708 :
15709 : /*****************************************************************************
15710 : *
15711 : * expression grammar
15712 : *
15713 : *****************************************************************************/
15714 :
15715 : /*
15716 : * General expressions
15717 : * This is the heart of the expression syntax.
15718 : *
15719 : * We have two expression types: a_expr is the unrestricted kind, and
15720 : * b_expr is a subset that must be used in some places to avoid shift/reduce
15721 : * conflicts. For example, we can't do BETWEEN as "BETWEEN a_expr AND a_expr"
15722 : * because that use of AND conflicts with AND as a boolean operator. So,
15723 : * b_expr is used in BETWEEN and we remove boolean keywords from b_expr.
15724 : *
15725 : * Note that '(' a_expr ')' is a b_expr, so an unrestricted expression can
15726 : * always be used by surrounding it with parens.
15727 : *
15728 : * c_expr is all the productions that are common to a_expr and b_expr;
15729 : * it's factored out just to eliminate redundant coding.
15730 : *
15731 : * Be careful of productions involving more than one terminal token.
15732 : * By default, bison will assign such productions the precedence of their
15733 : * last terminal, but in nearly all cases you want it to be the precedence
15734 : * of the first terminal instead; otherwise you will not get the behavior
15735 : * you expect! So we use %prec annotations freely to set precedences.
15736 : */
15737 2388786 : a_expr: c_expr { $$ = $1; }
15738 : | a_expr TYPECAST Typename
15739 146478 : { $$ = makeTypeCast($1, $3, @2); }
15740 : | a_expr COLLATE any_name
15741 : {
15742 6442 : CollateClause *n = makeNode(CollateClause);
15743 :
15744 6442 : n->arg = $1;
15745 6442 : n->collname = $3;
15746 6442 : n->location = @2;
15747 6442 : $$ = (Node *) n;
15748 : }
15749 : | a_expr AT TIME ZONE a_expr %prec AT
15750 : {
15751 272 : $$ = (Node *) makeFuncCall(SystemFuncName("timezone"),
15752 272 : list_make2($5, $1),
15753 : COERCE_SQL_SYNTAX,
15754 272 : @2);
15755 : }
15756 : | a_expr AT LOCAL %prec AT
15757 : {
15758 28 : $$ = (Node *) makeFuncCall(SystemFuncName("timezone"),
15759 28 : list_make1($1),
15760 : COERCE_SQL_SYNTAX,
15761 : -1);
15762 : }
15763 : /*
15764 : * These operators must be called out explicitly in order to make use
15765 : * of bison's automatic operator-precedence handling. All other
15766 : * operator names are handled by the generic productions using "Op",
15767 : * below; and all those operators will have the same precedence.
15768 : *
15769 : * If you add more explicitly-known operators, be sure to add them
15770 : * also to b_expr and to the MathOp list below.
15771 : */
15772 : | '+' a_expr %prec UMINUS
15773 8 : { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "+", NULL, $2, @1); }
15774 : | '-' a_expr %prec UMINUS
15775 5939 : { $$ = doNegate($2, @1); }
15776 : | a_expr '+' a_expr
15777 9241 : { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "+", $1, $3, @2); }
15778 : | a_expr '-' a_expr
15779 2741 : { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "-", $1, $3, @2); }
15780 : | a_expr '*' a_expr
15781 4064 : { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "*", $1, $3, @2); }
15782 : | a_expr '/' a_expr
15783 2178 : { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "/", $1, $3, @2); }
15784 : | a_expr '%' a_expr
15785 2004 : { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "%", $1, $3, @2); }
15786 : | a_expr '^' a_expr
15787 306 : { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "^", $1, $3, @2); }
15788 : | a_expr '<' a_expr
15789 6817 : { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "<", $1, $3, @2); }
15790 : | a_expr '>' a_expr
15791 10969 : { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, ">", $1, $3, @2); }
15792 : | a_expr '=' a_expr
15793 258459 : { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "=", $1, $3, @2); }
15794 : | a_expr LESS_EQUALS a_expr
15795 3076 : { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "<=", $1, $3, @2); }
15796 : | a_expr GREATER_EQUALS a_expr
15797 7423 : { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, ">=", $1, $3, @2); }
15798 : | a_expr NOT_EQUALS a_expr
15799 24654 : { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "<>", $1, $3, @2); }
15800 : | a_expr RIGHT_ARROW a_expr
15801 540 : { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "->", $1, $3, @2); }
15802 : | a_expr '|' a_expr
15803 57 : { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "|", $1, $3, @2); }
15804 :
15805 : | a_expr qual_Op a_expr %prec Op
15806 37366 : { $$ = (Node *) makeA_Expr(AEXPR_OP, $2, $1, $3, @2); }
15807 : | qual_Op a_expr %prec Op
15808 157 : { $$ = (Node *) makeA_Expr(AEXPR_OP, $1, NULL, $2, @1); }
15809 :
15810 : | a_expr AND a_expr
15811 153852 : { $$ = makeAndExpr($1, $3, @2); }
15812 : | a_expr OR a_expr
15813 14435 : { $$ = makeOrExpr($1, $3, @2); }
15814 : | NOT a_expr
15815 15535 : { $$ = makeNotExpr($2, @1); }
15816 : | NOT_LA a_expr %prec NOT
15817 0 : { $$ = makeNotExpr($2, @1); }
15818 :
15819 : | a_expr LIKE a_expr
15820 : {
15821 1265 : $$ = (Node *) makeSimpleA_Expr(AEXPR_LIKE, "~~",
15822 1265 : $1, $3, @2);
15823 : }
15824 : | a_expr LIKE a_expr ESCAPE a_expr %prec LIKE
15825 : {
15826 64 : FuncCall *n = makeFuncCall(SystemFuncName("like_escape"),
15827 64 : list_make2($3, $5),
15828 : COERCE_EXPLICIT_CALL,
15829 64 : @2);
15830 64 : $$ = (Node *) makeSimpleA_Expr(AEXPR_LIKE, "~~",
15831 64 : $1, (Node *) n, @2);
15832 : }
15833 : | a_expr NOT_LA LIKE a_expr %prec NOT_LA
15834 : {
15835 124 : $$ = (Node *) makeSimpleA_Expr(AEXPR_LIKE, "!~~",
15836 124 : $1, $4, @2);
15837 : }
15838 : | a_expr NOT_LA LIKE a_expr ESCAPE a_expr %prec NOT_LA
15839 : {
15840 64 : FuncCall *n = makeFuncCall(SystemFuncName("like_escape"),
15841 64 : list_make2($4, $6),
15842 : COERCE_EXPLICIT_CALL,
15843 64 : @2);
15844 64 : $$ = (Node *) makeSimpleA_Expr(AEXPR_LIKE, "!~~",
15845 64 : $1, (Node *) n, @2);
15846 : }
15847 : | a_expr ILIKE a_expr
15848 : {
15849 112 : $$ = (Node *) makeSimpleA_Expr(AEXPR_ILIKE, "~~*",
15850 112 : $1, $3, @2);
15851 : }
15852 : | a_expr ILIKE a_expr ESCAPE a_expr %prec ILIKE
15853 : {
15854 0 : FuncCall *n = makeFuncCall(SystemFuncName("like_escape"),
15855 0 : list_make2($3, $5),
15856 : COERCE_EXPLICIT_CALL,
15857 0 : @2);
15858 0 : $$ = (Node *) makeSimpleA_Expr(AEXPR_ILIKE, "~~*",
15859 0 : $1, (Node *) n, @2);
15860 : }
15861 : | a_expr NOT_LA ILIKE a_expr %prec NOT_LA
15862 : {
15863 20 : $$ = (Node *) makeSimpleA_Expr(AEXPR_ILIKE, "!~~*",
15864 20 : $1, $4, @2);
15865 : }
15866 : | a_expr NOT_LA ILIKE a_expr ESCAPE a_expr %prec NOT_LA
15867 : {
15868 0 : FuncCall *n = makeFuncCall(SystemFuncName("like_escape"),
15869 0 : list_make2($4, $6),
15870 : COERCE_EXPLICIT_CALL,
15871 0 : @2);
15872 0 : $$ = (Node *) makeSimpleA_Expr(AEXPR_ILIKE, "!~~*",
15873 0 : $1, (Node *) n, @2);
15874 : }
15875 :
15876 : | a_expr SIMILAR TO a_expr %prec SIMILAR
15877 : {
15878 58 : FuncCall *n = makeFuncCall(SystemFuncName("similar_to_escape"),
15879 58 : list_make1($4),
15880 : COERCE_EXPLICIT_CALL,
15881 58 : @2);
15882 58 : $$ = (Node *) makeSimpleA_Expr(AEXPR_SIMILAR, "~",
15883 58 : $1, (Node *) n, @2);
15884 : }
15885 : | a_expr SIMILAR TO a_expr ESCAPE a_expr %prec SIMILAR
15886 : {
15887 24 : FuncCall *n = makeFuncCall(SystemFuncName("similar_to_escape"),
15888 24 : list_make2($4, $6),
15889 : COERCE_EXPLICIT_CALL,
15890 24 : @2);
15891 24 : $$ = (Node *) makeSimpleA_Expr(AEXPR_SIMILAR, "~",
15892 24 : $1, (Node *) n, @2);
15893 : }
15894 : | a_expr NOT_LA SIMILAR TO a_expr %prec NOT_LA
15895 : {
15896 0 : FuncCall *n = makeFuncCall(SystemFuncName("similar_to_escape"),
15897 0 : list_make1($5),
15898 : COERCE_EXPLICIT_CALL,
15899 0 : @2);
15900 0 : $$ = (Node *) makeSimpleA_Expr(AEXPR_SIMILAR, "!~",
15901 0 : $1, (Node *) n, @2);
15902 : }
15903 : | a_expr NOT_LA SIMILAR TO a_expr ESCAPE a_expr %prec NOT_LA
15904 : {
15905 0 : FuncCall *n = makeFuncCall(SystemFuncName("similar_to_escape"),
15906 0 : list_make2($5, $7),
15907 : COERCE_EXPLICIT_CALL,
15908 0 : @2);
15909 0 : $$ = (Node *) makeSimpleA_Expr(AEXPR_SIMILAR, "!~",
15910 0 : $1, (Node *) n, @2);
15911 : }
15912 :
15913 : /* NullTest clause
15914 : * Define SQL-style Null test clause.
15915 : * Allow two forms described in the standard:
15916 : * a IS NULL
15917 : * a IS NOT NULL
15918 : * Allow two SQL extensions
15919 : * a ISNULL
15920 : * a NOTNULL
15921 : */
15922 : | a_expr IS NULL_P %prec IS
15923 : {
15924 3476 : NullTest *n = makeNode(NullTest);
15925 :
15926 3476 : n->arg = (Expr *) $1;
15927 3476 : n->nulltesttype = IS_NULL;
15928 3476 : n->location = @2;
15929 3476 : $$ = (Node *) n;
15930 : }
15931 : | a_expr ISNULL
15932 : {
15933 64 : NullTest *n = makeNode(NullTest);
15934 :
15935 64 : n->arg = (Expr *) $1;
15936 64 : n->nulltesttype = IS_NULL;
15937 64 : n->location = @2;
15938 64 : $$ = (Node *) n;
15939 : }
15940 : | a_expr IS NOT NULL_P %prec IS
15941 : {
15942 8275 : NullTest *n = makeNode(NullTest);
15943 :
15944 8275 : n->arg = (Expr *) $1;
15945 8275 : n->nulltesttype = IS_NOT_NULL;
15946 8275 : n->location = @2;
15947 8275 : $$ = (Node *) n;
15948 : }
15949 : | a_expr NOTNULL
15950 : {
15951 4 : NullTest *n = makeNode(NullTest);
15952 :
15953 4 : n->arg = (Expr *) $1;
15954 4 : n->nulltesttype = IS_NOT_NULL;
15955 4 : n->location = @2;
15956 4 : $$ = (Node *) n;
15957 : }
15958 : | row OVERLAPS row
15959 : {
15960 509 : if (list_length($1) != 2)
15961 0 : ereport(ERROR,
15962 : (errcode(ERRCODE_SYNTAX_ERROR),
15963 : errmsg("wrong number of parameters on left side of OVERLAPS expression"),
15964 : parser_errposition(@1)));
15965 509 : if (list_length($3) != 2)
15966 0 : ereport(ERROR,
15967 : (errcode(ERRCODE_SYNTAX_ERROR),
15968 : errmsg("wrong number of parameters on right side of OVERLAPS expression"),
15969 : parser_errposition(@3)));
15970 509 : $$ = (Node *) makeFuncCall(SystemFuncName("overlaps"),
15971 509 : list_concat($1, $3),
15972 : COERCE_SQL_SYNTAX,
15973 509 : @2);
15974 : }
15975 : | a_expr IS TRUE_P %prec IS
15976 : {
15977 322 : BooleanTest *b = makeNode(BooleanTest);
15978 :
15979 322 : b->arg = (Expr *) $1;
15980 322 : b->booltesttype = IS_TRUE;
15981 322 : b->location = @2;
15982 322 : $$ = (Node *) b;
15983 : }
15984 : | a_expr IS NOT TRUE_P %prec IS
15985 : {
15986 100 : BooleanTest *b = makeNode(BooleanTest);
15987 :
15988 100 : b->arg = (Expr *) $1;
15989 100 : b->booltesttype = IS_NOT_TRUE;
15990 100 : b->location = @2;
15991 100 : $$ = (Node *) b;
15992 : }
15993 : | a_expr IS FALSE_P %prec IS
15994 : {
15995 152 : BooleanTest *b = makeNode(BooleanTest);
15996 :
15997 152 : b->arg = (Expr *) $1;
15998 152 : b->booltesttype = IS_FALSE;
15999 152 : b->location = @2;
16000 152 : $$ = (Node *) b;
16001 : }
16002 : | a_expr IS NOT FALSE_P %prec IS
16003 : {
16004 69 : BooleanTest *b = makeNode(BooleanTest);
16005 :
16006 69 : b->arg = (Expr *) $1;
16007 69 : b->booltesttype = IS_NOT_FALSE;
16008 69 : b->location = @2;
16009 69 : $$ = (Node *) b;
16010 : }
16011 : | a_expr IS UNKNOWN %prec IS
16012 : {
16013 50 : BooleanTest *b = makeNode(BooleanTest);
16014 :
16015 50 : b->arg = (Expr *) $1;
16016 50 : b->booltesttype = IS_UNKNOWN;
16017 50 : b->location = @2;
16018 50 : $$ = (Node *) b;
16019 : }
16020 : | a_expr IS NOT UNKNOWN %prec IS
16021 : {
16022 40 : BooleanTest *b = makeNode(BooleanTest);
16023 :
16024 40 : b->arg = (Expr *) $1;
16025 40 : b->booltesttype = IS_NOT_UNKNOWN;
16026 40 : b->location = @2;
16027 40 : $$ = (Node *) b;
16028 : }
16029 : | a_expr IS DISTINCT FROM a_expr %prec IS
16030 : {
16031 786 : $$ = (Node *) makeSimpleA_Expr(AEXPR_DISTINCT, "=", $1, $5, @2);
16032 : }
16033 : | a_expr IS NOT DISTINCT FROM a_expr %prec IS
16034 : {
16035 84 : $$ = (Node *) makeSimpleA_Expr(AEXPR_NOT_DISTINCT, "=", $1, $6, @2);
16036 : }
16037 : | a_expr BETWEEN opt_asymmetric b_expr AND a_expr %prec BETWEEN
16038 : {
16039 308 : $$ = (Node *) makeSimpleA_Expr(AEXPR_BETWEEN,
16040 : "BETWEEN",
16041 308 : $1,
16042 308 : (Node *) list_make2($4, $6),
16043 308 : @2);
16044 : }
16045 : | a_expr NOT_LA BETWEEN opt_asymmetric b_expr AND a_expr %prec NOT_LA
16046 : {
16047 8 : $$ = (Node *) makeSimpleA_Expr(AEXPR_NOT_BETWEEN,
16048 : "NOT BETWEEN",
16049 8 : $1,
16050 8 : (Node *) list_make2($5, $7),
16051 8 : @2);
16052 : }
16053 : | a_expr BETWEEN SYMMETRIC b_expr AND a_expr %prec BETWEEN
16054 : {
16055 8 : $$ = (Node *) makeSimpleA_Expr(AEXPR_BETWEEN_SYM,
16056 : "BETWEEN SYMMETRIC",
16057 8 : $1,
16058 8 : (Node *) list_make2($4, $6),
16059 8 : @2);
16060 : }
16061 : | a_expr NOT_LA BETWEEN SYMMETRIC b_expr AND a_expr %prec NOT_LA
16062 : {
16063 8 : $$ = (Node *) makeSimpleA_Expr(AEXPR_NOT_BETWEEN_SYM,
16064 : "NOT BETWEEN SYMMETRIC",
16065 8 : $1,
16066 8 : (Node *) list_make2($5, $7),
16067 8 : @2);
16068 : }
16069 : | a_expr IN_P select_with_parens
16070 : {
16071 : /* generate foo = ANY (subquery) */
16072 3578 : SubLink *n = makeNode(SubLink);
16073 :
16074 3578 : n->subselect = $3;
16075 3578 : n->subLinkType = ANY_SUBLINK;
16076 3578 : n->subLinkId = 0;
16077 3578 : n->testexpr = $1;
16078 3578 : n->operName = NIL; /* show it's IN not = ANY */
16079 3578 : n->location = @2;
16080 3578 : $$ = (Node *) n;
16081 : }
16082 : | a_expr IN_P '(' expr_list ')'
16083 : {
16084 : /* generate scalar IN expression */
16085 11040 : A_Expr *n = makeSimpleA_Expr(AEXPR_IN, "=", $1, (Node *) $4, @2);
16086 :
16087 11040 : n->rexpr_list_start = @3;
16088 11040 : n->rexpr_list_end = @5;
16089 11040 : $$ = (Node *) n;
16090 : }
16091 : | a_expr NOT_LA IN_P select_with_parens %prec NOT_LA
16092 : {
16093 : /* generate NOT (foo = ANY (subquery)) */
16094 168 : SubLink *n = makeNode(SubLink);
16095 :
16096 168 : n->subselect = $4;
16097 168 : n->subLinkType = ANY_SUBLINK;
16098 168 : n->subLinkId = 0;
16099 168 : n->testexpr = $1;
16100 168 : n->operName = NIL; /* show it's IN not = ANY */
16101 168 : n->location = @2;
16102 : /* Stick a NOT on top; must have same parse location */
16103 168 : $$ = makeNotExpr((Node *) n, @2);
16104 : }
16105 : | a_expr NOT_LA IN_P '(' expr_list ')'
16106 : {
16107 : /* generate scalar NOT IN expression */
16108 1786 : A_Expr *n = makeSimpleA_Expr(AEXPR_IN, "<>", $1, (Node *) $5, @2);
16109 :
16110 1786 : n->rexpr_list_start = @4;
16111 1786 : n->rexpr_list_end = @6;
16112 1786 : $$ = (Node *) n;
16113 : }
16114 : | a_expr subquery_Op sub_type select_with_parens %prec Op
16115 : {
16116 124 : SubLink *n = makeNode(SubLink);
16117 :
16118 124 : n->subLinkType = $3;
16119 124 : n->subLinkId = 0;
16120 124 : n->testexpr = $1;
16121 124 : n->operName = $2;
16122 124 : n->subselect = $4;
16123 124 : n->location = @2;
16124 124 : $$ = (Node *) n;
16125 : }
16126 : | a_expr subquery_Op sub_type '(' a_expr ')' %prec Op
16127 : {
16128 11287 : if ($3 == ANY_SUBLINK)
16129 11082 : $$ = (Node *) makeA_Expr(AEXPR_OP_ANY, $2, $1, $5, @2);
16130 : else
16131 205 : $$ = (Node *) makeA_Expr(AEXPR_OP_ALL, $2, $1, $5, @2);
16132 : }
16133 : | UNIQUE opt_unique_null_treatment select_with_parens
16134 : {
16135 : /* Not sure how to get rid of the parentheses
16136 : * but there are lots of shift/reduce errors without them.
16137 : *
16138 : * Should be able to implement this by plopping the entire
16139 : * select into a node, then transforming the target expressions
16140 : * from whatever they are into count(*), and testing the
16141 : * entire result equal to one.
16142 : * But, will probably implement a separate node in the executor.
16143 : */
16144 0 : ereport(ERROR,
16145 : (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
16146 : errmsg("UNIQUE predicate is not yet implemented"),
16147 : parser_errposition(@1)));
16148 : }
16149 : | a_expr IS DOCUMENT_P %prec IS
16150 : {
16151 12 : $$ = makeXmlExpr(IS_DOCUMENT, NULL, NIL,
16152 12 : list_make1($1), @2);
16153 : }
16154 : | a_expr IS NOT DOCUMENT_P %prec IS
16155 : {
16156 12 : $$ = makeNotExpr(makeXmlExpr(IS_DOCUMENT, NULL, NIL,
16157 12 : list_make1($1), @2),
16158 12 : @2);
16159 : }
16160 : | a_expr IS NORMALIZED %prec IS
16161 : {
16162 8 : $$ = (Node *) makeFuncCall(SystemFuncName("is_normalized"),
16163 8 : list_make1($1),
16164 : COERCE_SQL_SYNTAX,
16165 8 : @2);
16166 : }
16167 : | a_expr IS unicode_normal_form NORMALIZED %prec IS
16168 : {
16169 24 : $$ = (Node *) makeFuncCall(SystemFuncName("is_normalized"),
16170 24 : list_make2($1, makeStringConst($3, @3)),
16171 : COERCE_SQL_SYNTAX,
16172 24 : @2);
16173 : }
16174 : | a_expr IS NOT NORMALIZED %prec IS
16175 : {
16176 0 : $$ = makeNotExpr((Node *) makeFuncCall(SystemFuncName("is_normalized"),
16177 0 : list_make1($1),
16178 : COERCE_SQL_SYNTAX,
16179 0 : @2),
16180 0 : @2);
16181 : }
16182 : | a_expr IS NOT unicode_normal_form NORMALIZED %prec IS
16183 : {
16184 0 : $$ = makeNotExpr((Node *) makeFuncCall(SystemFuncName("is_normalized"),
16185 0 : list_make2($1, makeStringConst($4, @4)),
16186 : COERCE_SQL_SYNTAX,
16187 0 : @2),
16188 0 : @2);
16189 : }
16190 : | a_expr IS json_predicate_type_constraint
16191 : json_key_uniqueness_constraint_opt %prec IS
16192 : {
16193 238 : JsonFormat *format = makeJsonFormat(JS_FORMAT_DEFAULT, JS_ENC_DEFAULT, -1);
16194 :
16195 238 : $$ = makeJsonIsPredicate($1, format, $3, $4, InvalidOid, @1);
16196 : }
16197 : /*
16198 : * Required by SQL/JSON, but there are conflicts
16199 : | a_expr
16200 : json_format_clause
16201 : IS json_predicate_type_constraint
16202 : json_key_uniqueness_constraint_opt %prec IS
16203 : {
16204 : $$ = makeJsonIsPredicate($1, $2, $4, $5, InvalidOid, @1);
16205 : }
16206 : */
16207 : | a_expr IS NOT
16208 : json_predicate_type_constraint
16209 : json_key_uniqueness_constraint_opt %prec IS
16210 : {
16211 34 : JsonFormat *format = makeJsonFormat(JS_FORMAT_DEFAULT, JS_ENC_DEFAULT, -1);
16212 :
16213 34 : $$ = makeNotExpr(makeJsonIsPredicate($1, format, $4, $5, InvalidOid, @1), @1);
16214 : }
16215 : /*
16216 : * Required by SQL/JSON, but there are conflicts
16217 : | a_expr
16218 : json_format_clause
16219 : IS NOT
16220 : json_predicate_type_constraint
16221 : json_key_uniqueness_constraint_opt %prec IS
16222 : {
16223 : $$ = makeNotExpr(makeJsonIsPredicate($1, $2, $5, $6, InvalidOid, @1), @1);
16224 : }
16225 : */
16226 : | DEFAULT
16227 : {
16228 : /*
16229 : * The SQL spec only allows DEFAULT in "contextually typed
16230 : * expressions", but for us, it's easier to allow it in
16231 : * any a_expr and then throw error during parse analysis
16232 : * if it's in an inappropriate context. This way also
16233 : * lets us say something smarter than "syntax error".
16234 : */
16235 1031 : SetToDefault *n = makeNode(SetToDefault);
16236 :
16237 : /* parse analysis will fill in the rest */
16238 1031 : n->location = @1;
16239 1031 : $$ = (Node *) n;
16240 : }
16241 : ;
16242 :
16243 : /*
16244 : * Restricted expressions
16245 : *
16246 : * b_expr is a subset of the complete expression syntax defined by a_expr.
16247 : *
16248 : * Presently, AND, NOT, IS, and IN are the a_expr keywords that would
16249 : * cause trouble in the places where b_expr is used. For simplicity, we
16250 : * just eliminate all the boolean-keyword-operator productions from b_expr.
16251 : */
16252 : b_expr: c_expr
16253 2500 : { $$ = $1; }
16254 : | b_expr TYPECAST Typename
16255 138 : { $$ = makeTypeCast($1, $3, @2); }
16256 : | '+' b_expr %prec UMINUS
16257 0 : { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "+", NULL, $2, @1); }
16258 : | '-' b_expr %prec UMINUS
16259 44 : { $$ = doNegate($2, @1); }
16260 : | b_expr '+' b_expr
16261 24 : { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "+", $1, $3, @2); }
16262 : | b_expr '-' b_expr
16263 8 : { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "-", $1, $3, @2); }
16264 : | b_expr '*' b_expr
16265 8 : { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "*", $1, $3, @2); }
16266 : | b_expr '/' b_expr
16267 0 : { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "/", $1, $3, @2); }
16268 : | b_expr '%' b_expr
16269 0 : { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "%", $1, $3, @2); }
16270 : | b_expr '^' b_expr
16271 4 : { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "^", $1, $3, @2); }
16272 : | b_expr '<' b_expr
16273 0 : { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "<", $1, $3, @2); }
16274 : | b_expr '>' b_expr
16275 0 : { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, ">", $1, $3, @2); }
16276 : | b_expr '=' b_expr
16277 0 : { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "=", $1, $3, @2); }
16278 : | b_expr LESS_EQUALS b_expr
16279 0 : { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "<=", $1, $3, @2); }
16280 : | b_expr GREATER_EQUALS b_expr
16281 0 : { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, ">=", $1, $3, @2); }
16282 : | b_expr NOT_EQUALS b_expr
16283 0 : { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "<>", $1, $3, @2); }
16284 : | b_expr RIGHT_ARROW b_expr
16285 0 : { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "->", $1, $3, @2); }
16286 : | b_expr '|' b_expr
16287 0 : { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "|", $1, $3, @2); }
16288 : | b_expr qual_Op b_expr %prec Op
16289 8 : { $$ = (Node *) makeA_Expr(AEXPR_OP, $2, $1, $3, @2); }
16290 : | qual_Op b_expr %prec Op
16291 0 : { $$ = (Node *) makeA_Expr(AEXPR_OP, $1, NULL, $2, @1); }
16292 : | b_expr IS DISTINCT FROM b_expr %prec IS
16293 : {
16294 0 : $$ = (Node *) makeSimpleA_Expr(AEXPR_DISTINCT, "=", $1, $5, @2);
16295 : }
16296 : | b_expr IS NOT DISTINCT FROM b_expr %prec IS
16297 : {
16298 0 : $$ = (Node *) makeSimpleA_Expr(AEXPR_NOT_DISTINCT, "=", $1, $6, @2);
16299 : }
16300 : | b_expr IS DOCUMENT_P %prec IS
16301 : {
16302 0 : $$ = makeXmlExpr(IS_DOCUMENT, NULL, NIL,
16303 0 : list_make1($1), @2);
16304 : }
16305 : | b_expr IS NOT DOCUMENT_P %prec IS
16306 : {
16307 0 : $$ = makeNotExpr(makeXmlExpr(IS_DOCUMENT, NULL, NIL,
16308 0 : list_make1($1), @2),
16309 0 : @2);
16310 : }
16311 : ;
16312 :
16313 : /*
16314 : * Productions that can be used in both a_expr and b_expr.
16315 : *
16316 : * Note: productions that refer recursively to a_expr or b_expr mostly
16317 : * cannot appear here. However, it's OK to refer to a_exprs that occur
16318 : * inside parentheses, such as function arguments; that cannot introduce
16319 : * ambiguity to the b_expr syntax.
16320 : */
16321 1181705 : c_expr: columnref { $$ = $1; }
16322 807078 : | AexprConst { $$ = $1; }
16323 : | PARAM opt_indirection
16324 : {
16325 26406 : ParamRef *p = makeNode(ParamRef);
16326 :
16327 26406 : p->number = $1;
16328 26406 : p->location = @1;
16329 26406 : if ($2)
16330 : {
16331 653 : A_Indirection *n = makeNode(A_Indirection);
16332 :
16333 653 : n->arg = (Node *) p;
16334 653 : n->indirection = check_indirection($2, yyscanner);
16335 653 : $$ = (Node *) n;
16336 : }
16337 : else
16338 25753 : $$ = (Node *) p;
16339 : }
16340 : | '(' a_expr ')' opt_indirection
16341 : {
16342 60695 : if ($4)
16343 : {
16344 8364 : A_Indirection *n = makeNode(A_Indirection);
16345 :
16346 8364 : n->arg = $2;
16347 8364 : n->indirection = check_indirection($4, yyscanner);
16348 8364 : $$ = (Node *) n;
16349 : }
16350 : else
16351 52331 : $$ = $2;
16352 : }
16353 : | case_expr
16354 25105 : { $$ = $1; }
16355 : | func_expr
16356 252006 : { $$ = $1; }
16357 : | select_with_parens %prec UMINUS
16358 : {
16359 17676 : SubLink *n = makeNode(SubLink);
16360 :
16361 17676 : n->subLinkType = EXPR_SUBLINK;
16362 17676 : n->subLinkId = 0;
16363 17676 : n->testexpr = NULL;
16364 17676 : n->operName = NIL;
16365 17676 : n->subselect = $1;
16366 17676 : n->location = @1;
16367 17676 : $$ = (Node *) n;
16368 : }
16369 : | select_with_parens indirection
16370 : {
16371 : /*
16372 : * Because the select_with_parens nonterminal is designed
16373 : * to "eat" as many levels of parens as possible, the
16374 : * '(' a_expr ')' opt_indirection production above will
16375 : * fail to match a sub-SELECT with indirection decoration;
16376 : * the sub-SELECT won't be regarded as an a_expr as long
16377 : * as there are parens around it. To support applying
16378 : * subscripting or field selection to a sub-SELECT result,
16379 : * we need this redundant-looking production.
16380 : */
16381 12 : SubLink *n = makeNode(SubLink);
16382 12 : A_Indirection *a = makeNode(A_Indirection);
16383 :
16384 12 : n->subLinkType = EXPR_SUBLINK;
16385 12 : n->subLinkId = 0;
16386 12 : n->testexpr = NULL;
16387 12 : n->operName = NIL;
16388 12 : n->subselect = $1;
16389 12 : n->location = @1;
16390 12 : a->arg = (Node *) n;
16391 12 : a->indirection = check_indirection($2, yyscanner);
16392 12 : $$ = (Node *) a;
16393 : }
16394 : | EXISTS select_with_parens
16395 : {
16396 6094 : SubLink *n = makeNode(SubLink);
16397 :
16398 6094 : n->subLinkType = EXISTS_SUBLINK;
16399 6094 : n->subLinkId = 0;
16400 6094 : n->testexpr = NULL;
16401 6094 : n->operName = NIL;
16402 6094 : n->subselect = $2;
16403 6094 : n->location = @1;
16404 6094 : $$ = (Node *) n;
16405 : }
16406 : | ARRAY select_with_parens
16407 : {
16408 5707 : SubLink *n = makeNode(SubLink);
16409 :
16410 5707 : n->subLinkType = ARRAY_SUBLINK;
16411 5707 : n->subLinkId = 0;
16412 5707 : n->testexpr = NULL;
16413 5707 : n->operName = NIL;
16414 5707 : n->subselect = $2;
16415 5707 : n->location = @1;
16416 5707 : $$ = (Node *) n;
16417 : }
16418 : | ARRAY array_expr
16419 : {
16420 4870 : A_ArrayExpr *n = castNode(A_ArrayExpr, $2);
16421 :
16422 : /* point outermost A_ArrayExpr to the ARRAY keyword */
16423 4870 : n->location = @1;
16424 4870 : $$ = (Node *) n;
16425 : }
16426 : | explicit_row
16427 : {
16428 2451 : RowExpr *r = makeNode(RowExpr);
16429 :
16430 2451 : r->args = $1;
16431 2451 : r->row_typeid = InvalidOid; /* not analyzed yet */
16432 2451 : r->colnames = NIL; /* to be filled in during analysis */
16433 2451 : r->row_format = COERCE_EXPLICIT_CALL; /* abuse */
16434 2451 : r->location = @1;
16435 2451 : $$ = (Node *) r;
16436 : }
16437 : | implicit_row
16438 : {
16439 1770 : RowExpr *r = makeNode(RowExpr);
16440 :
16441 1770 : r->args = $1;
16442 1770 : r->row_typeid = InvalidOid; /* not analyzed yet */
16443 1770 : r->colnames = NIL; /* to be filled in during analysis */
16444 1770 : r->row_format = COERCE_IMPLICIT_CAST; /* abuse */
16445 1770 : r->location = @1;
16446 1770 : $$ = (Node *) r;
16447 : }
16448 : | GROUPING '(' expr_list ')'
16449 : {
16450 252 : GroupingFunc *g = makeNode(GroupingFunc);
16451 :
16452 252 : g->args = $3;
16453 252 : g->location = @1;
16454 252 : $$ = (Node *) g;
16455 : }
16456 : ;
16457 :
16458 : func_application: func_name '(' ')'
16459 : {
16460 18944 : $$ = (Node *) makeFuncCall($1, NIL,
16461 : COERCE_EXPLICIT_CALL,
16462 18944 : @1);
16463 : }
16464 : | func_name '(' func_arg_list opt_sort_clause ')'
16465 : {
16466 206029 : FuncCall *n = makeFuncCall($1, $3,
16467 : COERCE_EXPLICIT_CALL,
16468 206029 : @1);
16469 :
16470 206029 : n->agg_order = $4;
16471 206029 : $$ = (Node *) n;
16472 : }
16473 : | func_name '(' VARIADIC func_arg_expr opt_sort_clause ')'
16474 : {
16475 376 : FuncCall *n = makeFuncCall($1, list_make1($4),
16476 : COERCE_EXPLICIT_CALL,
16477 376 : @1);
16478 :
16479 376 : n->func_variadic = true;
16480 376 : n->agg_order = $5;
16481 376 : $$ = (Node *) n;
16482 : }
16483 : | func_name '(' func_arg_list ',' VARIADIC func_arg_expr opt_sort_clause ')'
16484 : {
16485 112 : FuncCall *n = makeFuncCall($1, lappend($3, $6),
16486 : COERCE_EXPLICIT_CALL,
16487 112 : @1);
16488 :
16489 112 : n->func_variadic = true;
16490 112 : n->agg_order = $7;
16491 112 : $$ = (Node *) n;
16492 : }
16493 : | func_name '(' ALL func_arg_list opt_sort_clause ')'
16494 : {
16495 0 : FuncCall *n = makeFuncCall($1, $4,
16496 : COERCE_EXPLICIT_CALL,
16497 0 : @1);
16498 :
16499 0 : n->agg_order = $5;
16500 : /* Ideally we'd mark the FuncCall node to indicate
16501 : * "must be an aggregate", but there's no provision
16502 : * for that in FuncCall at the moment.
16503 : */
16504 0 : $$ = (Node *) n;
16505 : }
16506 : | func_name '(' DISTINCT func_arg_list opt_sort_clause ')'
16507 : {
16508 364 : FuncCall *n = makeFuncCall($1, $4,
16509 : COERCE_EXPLICIT_CALL,
16510 364 : @1);
16511 :
16512 364 : n->agg_order = $5;
16513 364 : n->agg_distinct = true;
16514 364 : $$ = (Node *) n;
16515 : }
16516 : | func_name '(' '*' ')'
16517 : {
16518 : /*
16519 : * We consider AGGREGATE(*) to invoke a parameterless
16520 : * aggregate. This does the right thing for COUNT(*),
16521 : * and there are no other aggregates in SQL that accept
16522 : * '*' as parameter.
16523 : *
16524 : * The FuncCall node is also marked agg_star = true,
16525 : * so that later processing can detect what the argument
16526 : * really was.
16527 : */
16528 11256 : FuncCall *n = makeFuncCall($1, NIL,
16529 : COERCE_EXPLICIT_CALL,
16530 11256 : @1);
16531 :
16532 11256 : n->agg_star = true;
16533 11256 : $$ = (Node *) n;
16534 : }
16535 : ;
16536 :
16537 :
16538 : /*
16539 : * func_expr and its cousin func_expr_windowless are split out from c_expr just
16540 : * so that we have classifications for "everything that is a function call or
16541 : * looks like one". This isn't very important, but it saves us having to
16542 : * document which variants are legal in places like "FROM function()" or the
16543 : * backwards-compatible functional-index syntax for CREATE INDEX.
16544 : * (Note that many of the special SQL functions wouldn't actually make any
16545 : * sense as functional index entries, but we ignore that consideration here.)
16546 : */
16547 : func_expr: func_application within_group_clause filter_clause null_treatment over_clause
16548 : {
16549 206888 : FuncCall *n = (FuncCall *) $1;
16550 :
16551 : /*
16552 : * The order clause for WITHIN GROUP and the one for
16553 : * plain-aggregate ORDER BY share a field, so we have to
16554 : * check here that at most one is present. We also check
16555 : * for DISTINCT and VARIADIC here to give a better error
16556 : * location. Other consistency checks are deferred to
16557 : * parse analysis.
16558 : */
16559 206888 : if ($2 != NIL)
16560 : {
16561 228 : if (n->agg_order != NIL)
16562 4 : ereport(ERROR,
16563 : (errcode(ERRCODE_SYNTAX_ERROR),
16564 : errmsg("cannot use multiple ORDER BY clauses with WITHIN GROUP"),
16565 : parser_errposition(@2)));
16566 224 : if (n->agg_distinct)
16567 0 : ereport(ERROR,
16568 : (errcode(ERRCODE_SYNTAX_ERROR),
16569 : errmsg("cannot use DISTINCT with WITHIN GROUP"),
16570 : parser_errposition(@2)));
16571 224 : if (n->func_variadic)
16572 0 : ereport(ERROR,
16573 : (errcode(ERRCODE_SYNTAX_ERROR),
16574 : errmsg("cannot use VARIADIC with WITHIN GROUP"),
16575 : parser_errposition(@2)));
16576 224 : n->agg_order = $2;
16577 224 : n->agg_within_group = true;
16578 : }
16579 206884 : n->agg_filter = $3;
16580 206884 : n->ignore_nulls = $4;
16581 206884 : n->over = $5;
16582 206884 : $$ = (Node *) n;
16583 : }
16584 : | json_aggregate_func filter_clause over_clause
16585 : {
16586 480 : JsonAggConstructor *n = IsA($1, JsonObjectAgg) ?
16587 240 : ((JsonObjectAgg *) $1)->constructor :
16588 104 : ((JsonArrayAgg *) $1)->constructor;
16589 :
16590 240 : n->agg_filter = $2;
16591 240 : n->over = $3;
16592 240 : $$ = (Node *) $1;
16593 : }
16594 : | func_expr_common_subexpr
16595 44882 : { $$ = $1; }
16596 : ;
16597 :
16598 : /*
16599 : * Like func_expr but does not accept WINDOW functions directly
16600 : * (but they can still be contained in arguments for functions etc).
16601 : * Use this when window expressions are not allowed, where needed to
16602 : * disambiguate the grammar (e.g. in CREATE INDEX).
16603 : */
16604 : func_expr_windowless:
16605 29830 : func_application { $$ = $1; }
16606 364 : | func_expr_common_subexpr { $$ = $1; }
16607 16 : | json_aggregate_func { $$ = $1; }
16608 : ;
16609 :
16610 : /*
16611 : * Special expressions that are considered to be functions.
16612 : */
16613 : func_expr_common_subexpr:
16614 : COLLATION FOR '(' a_expr ')'
16615 : {
16616 20 : $$ = (Node *) makeFuncCall(SystemFuncName("pg_collation_for"),
16617 20 : list_make1($4),
16618 : COERCE_SQL_SYNTAX,
16619 20 : @1);
16620 : }
16621 : | CURRENT_DATE
16622 : {
16623 175 : $$ = makeSQLValueFunction(SVFOP_CURRENT_DATE, -1, @1);
16624 : }
16625 : | CURRENT_TIME
16626 : {
16627 16 : $$ = makeSQLValueFunction(SVFOP_CURRENT_TIME, -1, @1);
16628 : }
16629 : | CURRENT_TIME '(' Iconst ')'
16630 : {
16631 16 : $$ = makeSQLValueFunction(SVFOP_CURRENT_TIME_N, $3, @1);
16632 : }
16633 : | CURRENT_TIMESTAMP
16634 : {
16635 153 : $$ = makeSQLValueFunction(SVFOP_CURRENT_TIMESTAMP, -1, @1);
16636 : }
16637 : | CURRENT_TIMESTAMP '(' Iconst ')'
16638 : {
16639 101 : $$ = makeSQLValueFunction(SVFOP_CURRENT_TIMESTAMP_N, $3, @1);
16640 : }
16641 : | LOCALTIME
16642 : {
16643 16 : $$ = makeSQLValueFunction(SVFOP_LOCALTIME, -1, @1);
16644 : }
16645 : | LOCALTIME '(' Iconst ')'
16646 : {
16647 16 : $$ = makeSQLValueFunction(SVFOP_LOCALTIME_N, $3, @1);
16648 : }
16649 : | LOCALTIMESTAMP
16650 : {
16651 24 : $$ = makeSQLValueFunction(SVFOP_LOCALTIMESTAMP, -1, @1);
16652 : }
16653 : | LOCALTIMESTAMP '(' Iconst ')'
16654 : {
16655 16 : $$ = makeSQLValueFunction(SVFOP_LOCALTIMESTAMP_N, $3, @1);
16656 : }
16657 : | CURRENT_ROLE
16658 : {
16659 44 : $$ = makeSQLValueFunction(SVFOP_CURRENT_ROLE, -1, @1);
16660 : }
16661 : | CURRENT_USER
16662 : {
16663 664 : $$ = makeSQLValueFunction(SVFOP_CURRENT_USER, -1, @1);
16664 : }
16665 : | SESSION_USER
16666 : {
16667 326 : $$ = makeSQLValueFunction(SVFOP_SESSION_USER, -1, @1);
16668 : }
16669 : | SYSTEM_USER
16670 : {
16671 12 : $$ = (Node *) makeFuncCall(SystemFuncName("system_user"),
16672 : NIL,
16673 : COERCE_SQL_SYNTAX,
16674 : @1);
16675 : }
16676 : | USER
16677 : {
16678 16 : $$ = makeSQLValueFunction(SVFOP_USER, -1, @1);
16679 : }
16680 : | CURRENT_CATALOG
16681 : {
16682 35 : $$ = makeSQLValueFunction(SVFOP_CURRENT_CATALOG, -1, @1);
16683 : }
16684 : | CURRENT_SCHEMA
16685 : {
16686 20 : $$ = makeSQLValueFunction(SVFOP_CURRENT_SCHEMA, -1, @1);
16687 : }
16688 : | CAST '(' a_expr AS Typename ')'
16689 35970 : { $$ = makeTypeCast($3, $5, @1); }
16690 : | EXTRACT '(' extract_list ')'
16691 : {
16692 860 : $$ = (Node *) makeFuncCall(SystemFuncName("extract"),
16693 860 : $3,
16694 : COERCE_SQL_SYNTAX,
16695 860 : @1);
16696 : }
16697 : | NORMALIZE '(' a_expr ')'
16698 : {
16699 12 : $$ = (Node *) makeFuncCall(SystemFuncName("normalize"),
16700 12 : list_make1($3),
16701 : COERCE_SQL_SYNTAX,
16702 12 : @1);
16703 : }
16704 : | NORMALIZE '(' a_expr ',' unicode_normal_form ')'
16705 : {
16706 28 : $$ = (Node *) makeFuncCall(SystemFuncName("normalize"),
16707 28 : list_make2($3, makeStringConst($5, @5)),
16708 : COERCE_SQL_SYNTAX,
16709 28 : @1);
16710 : }
16711 : | OVERLAY '(' overlay_list ')'
16712 : {
16713 54 : $$ = (Node *) makeFuncCall(SystemFuncName("overlay"),
16714 54 : $3,
16715 : COERCE_SQL_SYNTAX,
16716 54 : @1);
16717 : }
16718 : | OVERLAY '(' func_arg_list_opt ')'
16719 : {
16720 : /*
16721 : * allow functions named overlay() to be called without
16722 : * special syntax
16723 : */
16724 0 : $$ = (Node *) makeFuncCall(list_make1(makeString("overlay")),
16725 0 : $3,
16726 : COERCE_EXPLICIT_CALL,
16727 0 : @1);
16728 : }
16729 : | POSITION '(' position_list ')'
16730 : {
16731 : /*
16732 : * position(A in B) is converted to position(B, A)
16733 : *
16734 : * We deliberately don't offer a "plain syntax" option
16735 : * for position(), because the reversal of the arguments
16736 : * creates too much risk of confusion.
16737 : */
16738 255 : $$ = (Node *) makeFuncCall(SystemFuncName("position"),
16739 255 : $3,
16740 : COERCE_SQL_SYNTAX,
16741 255 : @1);
16742 : }
16743 : | SUBSTRING '(' substr_list ')'
16744 : {
16745 : /* substring(A from B for C) is converted to
16746 : * substring(A, B, C) - thomas 2000-11-28
16747 : */
16748 439 : $$ = (Node *) makeFuncCall(SystemFuncName("substring"),
16749 439 : $3,
16750 : COERCE_SQL_SYNTAX,
16751 439 : @1);
16752 : }
16753 : | SUBSTRING '(' func_arg_list_opt ')'
16754 : {
16755 : /*
16756 : * allow functions named substring() to be called without
16757 : * special syntax
16758 : */
16759 192 : $$ = (Node *) makeFuncCall(list_make1(makeString("substring")),
16760 192 : $3,
16761 : COERCE_EXPLICIT_CALL,
16762 192 : @1);
16763 : }
16764 : | TREAT '(' a_expr AS Typename ')'
16765 : {
16766 : /* TREAT(expr AS target) converts expr of a particular type to target,
16767 : * which is defined to be a subtype of the original expression.
16768 : * In SQL99, this is intended for use with structured UDTs,
16769 : * but let's make this a generally useful form allowing stronger
16770 : * coercions than are handled by implicit casting.
16771 : *
16772 : * Convert SystemTypeName() to SystemFuncName() even though
16773 : * at the moment they result in the same thing.
16774 : */
16775 0 : $$ = (Node *) makeFuncCall(SystemFuncName(strVal(llast($5->names))),
16776 0 : list_make1($3),
16777 : COERCE_EXPLICIT_CALL,
16778 0 : @1);
16779 : }
16780 : | TRIM '(' BOTH trim_list ')'
16781 : {
16782 : /* various trim expressions are defined in SQL
16783 : * - thomas 1997-07-19
16784 : */
16785 8 : $$ = (Node *) makeFuncCall(SystemFuncName("btrim"),
16786 8 : $4,
16787 : COERCE_SQL_SYNTAX,
16788 8 : @1);
16789 : }
16790 : | TRIM '(' LEADING trim_list ')'
16791 : {
16792 16 : $$ = (Node *) makeFuncCall(SystemFuncName("ltrim"),
16793 16 : $4,
16794 : COERCE_SQL_SYNTAX,
16795 16 : @1);
16796 : }
16797 : | TRIM '(' TRAILING trim_list ')'
16798 : {
16799 372 : $$ = (Node *) makeFuncCall(SystemFuncName("rtrim"),
16800 372 : $4,
16801 : COERCE_SQL_SYNTAX,
16802 372 : @1);
16803 : }
16804 : | TRIM '(' trim_list ')'
16805 : {
16806 64 : $$ = (Node *) makeFuncCall(SystemFuncName("btrim"),
16807 64 : $3,
16808 : COERCE_SQL_SYNTAX,
16809 64 : @1);
16810 : }
16811 : | NULLIF '(' a_expr ',' a_expr ')'
16812 : {
16813 269 : $$ = (Node *) makeSimpleA_Expr(AEXPR_NULLIF, "=", $3, $5, @1);
16814 : }
16815 : | COALESCE '(' expr_list ')'
16816 : {
16817 2002 : CoalesceExpr *c = makeNode(CoalesceExpr);
16818 :
16819 2002 : c->args = $3;
16820 2002 : c->location = @1;
16821 2002 : $$ = (Node *) c;
16822 : }
16823 : | GREATEST '(' expr_list ')'
16824 : {
16825 106 : MinMaxExpr *v = makeNode(MinMaxExpr);
16826 :
16827 106 : v->args = $3;
16828 106 : v->op = IS_GREATEST;
16829 106 : v->location = @1;
16830 106 : $$ = (Node *) v;
16831 : }
16832 : | LEAST '(' expr_list ')'
16833 : {
16834 100 : MinMaxExpr *v = makeNode(MinMaxExpr);
16835 :
16836 100 : v->args = $3;
16837 100 : v->op = IS_LEAST;
16838 100 : v->location = @1;
16839 100 : $$ = (Node *) v;
16840 : }
16841 : | XMLCONCAT '(' expr_list ')'
16842 : {
16843 41 : $$ = makeXmlExpr(IS_XMLCONCAT, NULL, NIL, $3, @1);
16844 : }
16845 : | XMLELEMENT '(' NAME_P ColLabel ')'
16846 : {
16847 4 : $$ = makeXmlExpr(IS_XMLELEMENT, $4, NIL, NIL, @1);
16848 : }
16849 : | XMLELEMENT '(' NAME_P ColLabel ',' xml_attributes ')'
16850 : {
16851 24 : $$ = makeXmlExpr(IS_XMLELEMENT, $4, $6, NIL, @1);
16852 : }
16853 : | XMLELEMENT '(' NAME_P ColLabel ',' expr_list ')'
16854 : {
16855 77 : $$ = makeXmlExpr(IS_XMLELEMENT, $4, NIL, $6, @1);
16856 : }
16857 : | XMLELEMENT '(' NAME_P ColLabel ',' xml_attributes ',' expr_list ')'
16858 : {
16859 13 : $$ = makeXmlExpr(IS_XMLELEMENT, $4, $6, $8, @1);
16860 : }
16861 : | XMLEXISTS '(' c_expr xmlexists_argument ')'
16862 : {
16863 : /* xmlexists(A PASSING [BY REF] B [BY REF]) is
16864 : * converted to xmlexists(A, B)*/
16865 36 : $$ = (Node *) makeFuncCall(SystemFuncName("xmlexists"),
16866 36 : list_make2($3, $4),
16867 : COERCE_SQL_SYNTAX,
16868 36 : @1);
16869 : }
16870 : | XMLFOREST '(' labeled_expr_list ')'
16871 : {
16872 21 : $$ = makeXmlExpr(IS_XMLFOREST, NULL, $3, NIL, @1);
16873 : }
16874 : | XMLPARSE '(' document_or_content a_expr xml_whitespace_option ')'
16875 : {
16876 : XmlExpr *x = (XmlExpr *)
16877 93 : makeXmlExpr(IS_XMLPARSE, NULL, NIL,
16878 93 : list_make2($4, makeBoolAConst($5, -1)),
16879 93 : @1);
16880 :
16881 93 : x->xmloption = $3;
16882 93 : $$ = (Node *) x;
16883 : }
16884 : | XMLPI '(' NAME_P ColLabel ')'
16885 : {
16886 20 : $$ = makeXmlExpr(IS_XMLPI, $4, NULL, NIL, @1);
16887 : }
16888 : | XMLPI '(' NAME_P ColLabel ',' a_expr ')'
16889 : {
16890 33 : $$ = makeXmlExpr(IS_XMLPI, $4, NULL, list_make1($6), @1);
16891 : }
16892 : | XMLROOT '(' a_expr ',' xml_root_version opt_xml_root_standalone ')'
16893 : {
16894 45 : $$ = makeXmlExpr(IS_XMLROOT, NULL, NIL,
16895 45 : list_make3($3, $5, $6), @1);
16896 : }
16897 : | XMLSERIALIZE '(' document_or_content a_expr AS SimpleTypename xml_indent_option ')'
16898 : {
16899 144 : XmlSerialize *n = makeNode(XmlSerialize);
16900 :
16901 144 : n->xmloption = $3;
16902 144 : n->expr = $4;
16903 144 : n->typeName = $6;
16904 144 : n->indent = $7;
16905 144 : n->location = @1;
16906 144 : $$ = (Node *) n;
16907 : }
16908 : | JSON_OBJECT '(' func_arg_list ')'
16909 : {
16910 : /* Support for legacy (non-standard) json_object() */
16911 60 : $$ = (Node *) makeFuncCall(SystemFuncName("json_object"),
16912 60 : $3, COERCE_EXPLICIT_CALL, @1);
16913 : }
16914 : | JSON_OBJECT '(' json_name_and_value_list
16915 : json_object_constructor_null_clause_opt
16916 : json_key_uniqueness_constraint_opt
16917 : json_returning_clause_opt ')'
16918 : {
16919 318 : JsonObjectConstructor *n = makeNode(JsonObjectConstructor);
16920 :
16921 318 : n->exprs = $3;
16922 318 : n->absent_on_null = $4;
16923 318 : n->unique = $5;
16924 318 : n->output = (JsonOutput *) $6;
16925 318 : n->location = @1;
16926 318 : $$ = (Node *) n;
16927 : }
16928 : | JSON_OBJECT '(' json_returning_clause_opt ')'
16929 : {
16930 60 : JsonObjectConstructor *n = makeNode(JsonObjectConstructor);
16931 :
16932 60 : n->exprs = NULL;
16933 60 : n->absent_on_null = false;
16934 60 : n->unique = false;
16935 60 : n->output = (JsonOutput *) $3;
16936 60 : n->location = @1;
16937 60 : $$ = (Node *) n;
16938 : }
16939 : | JSON_ARRAY '('
16940 : json_value_expr_list
16941 : json_array_constructor_null_clause_opt
16942 : json_returning_clause_opt
16943 : ')'
16944 : {
16945 168 : JsonArrayConstructor *n = makeNode(JsonArrayConstructor);
16946 :
16947 168 : n->exprs = $3;
16948 168 : n->absent_on_null = $4;
16949 168 : n->output = (JsonOutput *) $5;
16950 168 : n->location = @1;
16951 168 : $$ = (Node *) n;
16952 : }
16953 : | JSON_ARRAY '('
16954 : select_no_parens
16955 : json_format_clause_opt
16956 : /* json_array_constructor_null_clause_opt */
16957 : json_returning_clause_opt
16958 : ')'
16959 : {
16960 40 : JsonArrayQueryConstructor *n = makeNode(JsonArrayQueryConstructor);
16961 :
16962 40 : n->query = $3;
16963 40 : n->format = (JsonFormat *) $4;
16964 40 : n->absent_on_null = true; /* XXX */
16965 40 : n->output = (JsonOutput *) $5;
16966 40 : n->location = @1;
16967 40 : $$ = (Node *) n;
16968 : }
16969 : | JSON_ARRAY '('
16970 : json_returning_clause_opt
16971 : ')'
16972 : {
16973 56 : JsonArrayConstructor *n = makeNode(JsonArrayConstructor);
16974 :
16975 56 : n->exprs = NIL;
16976 56 : n->absent_on_null = true;
16977 56 : n->output = (JsonOutput *) $3;
16978 56 : n->location = @1;
16979 56 : $$ = (Node *) n;
16980 : }
16981 : | JSON '(' json_value_expr json_key_uniqueness_constraint_opt ')'
16982 : {
16983 104 : JsonParseExpr *n = makeNode(JsonParseExpr);
16984 :
16985 104 : n->expr = (JsonValueExpr *) $3;
16986 104 : n->unique_keys = $4;
16987 104 : n->output = NULL;
16988 104 : n->location = @1;
16989 104 : $$ = (Node *) n;
16990 : }
16991 : | JSON_SCALAR '(' a_expr ')'
16992 : {
16993 70 : JsonScalarExpr *n = makeNode(JsonScalarExpr);
16994 :
16995 70 : n->expr = (Expr *) $3;
16996 70 : n->output = NULL;
16997 70 : n->location = @1;
16998 70 : $$ = (Node *) n;
16999 : }
17000 : | JSON_SERIALIZE '(' json_value_expr json_returning_clause_opt ')'
17001 : {
17002 68 : JsonSerializeExpr *n = makeNode(JsonSerializeExpr);
17003 :
17004 68 : n->expr = (JsonValueExpr *) $3;
17005 68 : n->output = (JsonOutput *) $4;
17006 68 : n->location = @1;
17007 68 : $$ = (Node *) n;
17008 : }
17009 : | MERGE_ACTION '(' ')'
17010 : {
17011 142 : MergeSupportFunc *m = makeNode(MergeSupportFunc);
17012 :
17013 142 : m->msftype = TEXTOID;
17014 142 : m->location = @1;
17015 142 : $$ = (Node *) m;
17016 : }
17017 : | JSON_QUERY '('
17018 : json_value_expr ',' a_expr json_passing_clause_opt
17019 : json_returning_clause_opt
17020 : json_wrapper_behavior
17021 : json_quotes_clause_opt
17022 : json_behavior_clause_opt
17023 : ')'
17024 : {
17025 660 : JsonFuncExpr *n = makeNode(JsonFuncExpr);
17026 :
17027 660 : n->op = JSON_QUERY_OP;
17028 660 : n->context_item = (JsonValueExpr *) $3;
17029 660 : n->pathspec = $5;
17030 660 : n->passing = $6;
17031 660 : n->output = (JsonOutput *) $7;
17032 660 : n->wrapper = $8;
17033 660 : n->quotes = $9;
17034 660 : n->on_empty = (JsonBehavior *) linitial($10);
17035 660 : n->on_error = (JsonBehavior *) lsecond($10);
17036 660 : n->location = @1;
17037 660 : $$ = (Node *) n;
17038 : }
17039 : | JSON_EXISTS '('
17040 : json_value_expr ',' a_expr json_passing_clause_opt
17041 : json_on_error_clause_opt
17042 : ')'
17043 : {
17044 112 : JsonFuncExpr *n = makeNode(JsonFuncExpr);
17045 :
17046 112 : n->op = JSON_EXISTS_OP;
17047 112 : n->context_item = (JsonValueExpr *) $3;
17048 112 : n->pathspec = $5;
17049 112 : n->passing = $6;
17050 112 : n->output = NULL;
17051 112 : n->on_error = (JsonBehavior *) $7;
17052 112 : n->location = @1;
17053 112 : $$ = (Node *) n;
17054 : }
17055 : | JSON_VALUE '('
17056 : json_value_expr ',' a_expr json_passing_clause_opt
17057 : json_returning_clause_opt
17058 : json_behavior_clause_opt
17059 : ')'
17060 : {
17061 420 : JsonFuncExpr *n = makeNode(JsonFuncExpr);
17062 :
17063 420 : n->op = JSON_VALUE_OP;
17064 420 : n->context_item = (JsonValueExpr *) $3;
17065 420 : n->pathspec = $5;
17066 420 : n->passing = $6;
17067 420 : n->output = (JsonOutput *) $7;
17068 420 : n->on_empty = (JsonBehavior *) linitial($8);
17069 420 : n->on_error = (JsonBehavior *) lsecond($8);
17070 420 : n->location = @1;
17071 420 : $$ = (Node *) n;
17072 : }
17073 : ;
17074 :
17075 :
17076 : /*
17077 : * SQL/XML support
17078 : */
17079 : xml_root_version: VERSION_P a_expr
17080 16 : { $$ = $2; }
17081 : | VERSION_P NO VALUE_P
17082 29 : { $$ = makeNullAConst(-1); }
17083 : ;
17084 :
17085 : opt_xml_root_standalone: ',' STANDALONE_P YES_P
17086 17 : { $$ = makeIntConst(XML_STANDALONE_YES, -1); }
17087 : | ',' STANDALONE_P NO
17088 8 : { $$ = makeIntConst(XML_STANDALONE_NO, -1); }
17089 : | ',' STANDALONE_P NO VALUE_P
17090 8 : { $$ = makeIntConst(XML_STANDALONE_NO_VALUE, -1); }
17091 : | /*EMPTY*/
17092 12 : { $$ = makeIntConst(XML_STANDALONE_OMITTED, -1); }
17093 : ;
17094 :
17095 37 : xml_attributes: XMLATTRIBUTES '(' labeled_expr_list ')' { $$ = $3; }
17096 : ;
17097 :
17098 819 : labeled_expr_list: labeled_expr { $$ = list_make1($1); }
17099 758 : | labeled_expr_list ',' labeled_expr { $$ = lappend($1, $3); }
17100 : ;
17101 :
17102 : labeled_expr: a_expr AS ColLabel
17103 : {
17104 969 : $$ = makeNode(ResTarget);
17105 969 : $$->name = $3;
17106 969 : $$->indirection = NIL;
17107 969 : $$->val = (Node *) $1;
17108 969 : $$->location = @1;
17109 : }
17110 : | a_expr
17111 : {
17112 608 : $$ = makeNode(ResTarget);
17113 608 : $$->name = NULL;
17114 608 : $$->indirection = NIL;
17115 608 : $$->val = (Node *) $1;
17116 608 : $$->location = @1;
17117 : }
17118 : ;
17119 :
17120 123 : document_or_content: DOCUMENT_P { $$ = XMLOPTION_DOCUMENT; }
17121 124 : | CONTENT_P { $$ = XMLOPTION_CONTENT; }
17122 : ;
17123 :
17124 93 : xml_indent_option: INDENT { $$ = true; }
17125 23 : | NO INDENT { $$ = false; }
17126 28 : | /*EMPTY*/ { $$ = false; }
17127 : ;
17128 :
17129 0 : xml_whitespace_option: PRESERVE WHITESPACE_P { $$ = true; }
17130 1 : | STRIP_P WHITESPACE_P { $$ = false; }
17131 92 : | /*EMPTY*/ { $$ = false; }
17132 : ;
17133 :
17134 : /* We allow several variants for SQL and other compatibility. */
17135 : xmlexists_argument:
17136 : PASSING c_expr
17137 : {
17138 158 : $$ = $2;
17139 : }
17140 : | PASSING c_expr xml_passing_mech
17141 : {
17142 0 : $$ = $2;
17143 : }
17144 : | PASSING xml_passing_mech c_expr
17145 : {
17146 28 : $$ = $3;
17147 : }
17148 : | PASSING xml_passing_mech c_expr xml_passing_mech
17149 : {
17150 4 : $$ = $3;
17151 : }
17152 : ;
17153 :
17154 : xml_passing_mech:
17155 : BY REF_P
17156 : | BY VALUE_P
17157 : ;
17158 :
17159 : /*****************************************************************************
17160 : *
17161 : * WAIT FOR LSN
17162 : *
17163 : *****************************************************************************/
17164 :
17165 : WaitStmt:
17166 : WAIT FOR LSN_P Sconst opt_wait_with_clause
17167 : {
17168 56 : WaitStmt *n = makeNode(WaitStmt);
17169 56 : n->lsn_literal = $4;
17170 56 : n->options = $5;
17171 56 : $$ = (Node *) n;
17172 : }
17173 : ;
17174 :
17175 : opt_wait_with_clause:
17176 45 : WITH '(' utility_option_list ')' { $$ = $3; }
17177 11 : | /*EMPTY*/ { $$ = NIL; }
17178 : ;
17179 :
17180 : /*
17181 : * Aggregate decoration clauses
17182 : */
17183 : within_group_clause:
17184 228 : WITHIN GROUP_P '(' sort_clause ')' { $$ = $4; }
17185 206664 : | /*EMPTY*/ { $$ = NIL; }
17186 : ;
17187 :
17188 : filter_clause:
17189 489 : FILTER '(' WHERE a_expr ')' { $$ = $4; }
17190 206643 : | /*EMPTY*/ { $$ = NULL; }
17191 : ;
17192 :
17193 :
17194 : /*
17195 : * Window Definitions
17196 : */
17197 : null_treatment:
17198 132 : IGNORE_P NULLS_P { $$ = PARSER_IGNORE_NULLS; }
17199 64 : | RESPECT_P NULLS_P { $$ = PARSER_RESPECT_NULLS; }
17200 206696 : | /*EMPTY*/ { $$ = NO_NULLTREATMENT; }
17201 : ;
17202 :
17203 : window_clause:
17204 406 : WINDOW window_definition_list { $$ = $2; }
17205 310018 : | /*EMPTY*/ { $$ = NIL; }
17206 : ;
17207 :
17208 : window_definition_list:
17209 406 : window_definition { $$ = list_make1($1); }
17210 : | window_definition_list ',' window_definition
17211 20 : { $$ = lappend($1, $3); }
17212 : ;
17213 :
17214 : window_definition:
17215 : ColId AS window_specification
17216 : {
17217 426 : WindowDef *n = $3;
17218 :
17219 426 : n->name = $1;
17220 426 : $$ = n;
17221 : }
17222 : ;
17223 :
17224 : over_clause: OVER window_specification
17225 1878 : { $$ = $2; }
17226 : | OVER ColId
17227 : {
17228 790 : WindowDef *n = makeNode(WindowDef);
17229 :
17230 790 : n->name = $2;
17231 790 : n->refname = NULL;
17232 790 : n->partitionClause = NIL;
17233 790 : n->orderClause = NIL;
17234 790 : n->frameOptions = FRAMEOPTION_DEFAULTS;
17235 790 : n->startOffset = NULL;
17236 790 : n->endOffset = NULL;
17237 790 : n->location = @2;
17238 790 : $$ = n;
17239 : }
17240 : | /*EMPTY*/
17241 204460 : { $$ = NULL; }
17242 : ;
17243 :
17244 : window_specification: '(' opt_existing_window_name opt_partition_clause
17245 : opt_sort_clause opt_frame_clause ')'
17246 : {
17247 2304 : WindowDef *n = makeNode(WindowDef);
17248 :
17249 2304 : n->name = NULL;
17250 2304 : n->refname = $2;
17251 2304 : n->partitionClause = $3;
17252 2304 : n->orderClause = $4;
17253 : /* copy relevant fields of opt_frame_clause */
17254 2304 : n->frameOptions = $5->frameOptions;
17255 2304 : n->startOffset = $5->startOffset;
17256 2304 : n->endOffset = $5->endOffset;
17257 2304 : n->location = @1;
17258 2304 : $$ = n;
17259 : }
17260 : ;
17261 :
17262 : /*
17263 : * If we see PARTITION, RANGE, ROWS or GROUPS as the first token after the '('
17264 : * of a window_specification, we want the assumption to be that there is
17265 : * no existing_window_name; but those keywords are unreserved and so could
17266 : * be ColIds. We fix this by making them have the same precedence as IDENT
17267 : * and giving the empty production here a slightly higher precedence, so
17268 : * that the shift/reduce conflict is resolved in favor of reducing the rule.
17269 : * These keywords are thus precluded from being an existing_window_name but
17270 : * are not reserved for any other purpose.
17271 : */
17272 36 : opt_existing_window_name: ColId { $$ = $1; }
17273 2272 : | /*EMPTY*/ %prec Op { $$ = NULL; }
17274 : ;
17275 :
17276 604 : opt_partition_clause: PARTITION BY expr_list { $$ = $3; }
17277 1700 : | /*EMPTY*/ { $$ = NIL; }
17278 : ;
17279 :
17280 : /*
17281 : * For frame clauses, we return a WindowDef, but only some fields are used:
17282 : * frameOptions, startOffset, and endOffset.
17283 : */
17284 : opt_frame_clause:
17285 : RANGE frame_extent opt_window_exclusion_clause
17286 : {
17287 530 : WindowDef *n = $2;
17288 :
17289 530 : n->frameOptions |= FRAMEOPTION_NONDEFAULT | FRAMEOPTION_RANGE;
17290 530 : n->frameOptions |= $3;
17291 530 : $$ = n;
17292 : }
17293 : | ROWS frame_extent opt_window_exclusion_clause
17294 : {
17295 462 : WindowDef *n = $2;
17296 :
17297 462 : n->frameOptions |= FRAMEOPTION_NONDEFAULT | FRAMEOPTION_ROWS;
17298 462 : n->frameOptions |= $3;
17299 462 : $$ = n;
17300 : }
17301 : | GROUPS frame_extent opt_window_exclusion_clause
17302 : {
17303 136 : WindowDef *n = $2;
17304 :
17305 136 : n->frameOptions |= FRAMEOPTION_NONDEFAULT | FRAMEOPTION_GROUPS;
17306 136 : n->frameOptions |= $3;
17307 136 : $$ = n;
17308 : }
17309 : | /*EMPTY*/
17310 : {
17311 1176 : WindowDef *n = makeNode(WindowDef);
17312 :
17313 1176 : n->frameOptions = FRAMEOPTION_DEFAULTS;
17314 1176 : n->startOffset = NULL;
17315 1176 : n->endOffset = NULL;
17316 1176 : $$ = n;
17317 : }
17318 : ;
17319 :
17320 : frame_extent: frame_bound
17321 : {
17322 8 : WindowDef *n = $1;
17323 :
17324 : /* reject invalid cases */
17325 8 : if (n->frameOptions & FRAMEOPTION_START_UNBOUNDED_FOLLOWING)
17326 0 : ereport(ERROR,
17327 : (errcode(ERRCODE_WINDOWING_ERROR),
17328 : errmsg("frame start cannot be UNBOUNDED FOLLOWING"),
17329 : parser_errposition(@1)));
17330 8 : if (n->frameOptions & FRAMEOPTION_START_OFFSET_FOLLOWING)
17331 0 : ereport(ERROR,
17332 : (errcode(ERRCODE_WINDOWING_ERROR),
17333 : errmsg("frame starting from following row cannot end with current row"),
17334 : parser_errposition(@1)));
17335 8 : n->frameOptions |= FRAMEOPTION_END_CURRENT_ROW;
17336 8 : $$ = n;
17337 : }
17338 : | BETWEEN frame_bound AND frame_bound
17339 : {
17340 1120 : WindowDef *n1 = $2;
17341 1120 : WindowDef *n2 = $4;
17342 :
17343 : /* form merged options */
17344 1120 : int frameOptions = n1->frameOptions;
17345 : /* shift converts START_ options to END_ options */
17346 1120 : frameOptions |= n2->frameOptions << 1;
17347 1120 : frameOptions |= FRAMEOPTION_BETWEEN;
17348 : /* reject invalid cases */
17349 1120 : if (frameOptions & FRAMEOPTION_START_UNBOUNDED_FOLLOWING)
17350 0 : ereport(ERROR,
17351 : (errcode(ERRCODE_WINDOWING_ERROR),
17352 : errmsg("frame start cannot be UNBOUNDED FOLLOWING"),
17353 : parser_errposition(@2)));
17354 1120 : if (frameOptions & FRAMEOPTION_END_UNBOUNDED_PRECEDING)
17355 0 : ereport(ERROR,
17356 : (errcode(ERRCODE_WINDOWING_ERROR),
17357 : errmsg("frame end cannot be UNBOUNDED PRECEDING"),
17358 : parser_errposition(@4)));
17359 1120 : if ((frameOptions & FRAMEOPTION_START_CURRENT_ROW) &&
17360 308 : (frameOptions & FRAMEOPTION_END_OFFSET_PRECEDING))
17361 0 : ereport(ERROR,
17362 : (errcode(ERRCODE_WINDOWING_ERROR),
17363 : errmsg("frame starting from current row cannot have preceding rows"),
17364 : parser_errposition(@4)));
17365 1120 : if ((frameOptions & FRAMEOPTION_START_OFFSET_FOLLOWING) &&
17366 112 : (frameOptions & (FRAMEOPTION_END_OFFSET_PRECEDING |
17367 : FRAMEOPTION_END_CURRENT_ROW)))
17368 0 : ereport(ERROR,
17369 : (errcode(ERRCODE_WINDOWING_ERROR),
17370 : errmsg("frame starting from following row cannot have preceding rows"),
17371 : parser_errposition(@4)));
17372 1120 : n1->frameOptions = frameOptions;
17373 1120 : n1->endOffset = n2->startOffset;
17374 1120 : $$ = n1;
17375 : }
17376 : ;
17377 :
17378 : /*
17379 : * This is used for both frame start and frame end, with output set up on
17380 : * the assumption it's frame start; the frame_extent productions must reject
17381 : * invalid cases.
17382 : */
17383 : frame_bound:
17384 : UNBOUNDED PRECEDING
17385 : {
17386 144 : WindowDef *n = makeNode(WindowDef);
17387 :
17388 144 : n->frameOptions = FRAMEOPTION_START_UNBOUNDED_PRECEDING;
17389 144 : n->startOffset = NULL;
17390 144 : n->endOffset = NULL;
17391 144 : $$ = n;
17392 : }
17393 : | UNBOUNDED FOLLOWING
17394 : {
17395 262 : WindowDef *n = makeNode(WindowDef);
17396 :
17397 262 : n->frameOptions = FRAMEOPTION_START_UNBOUNDED_FOLLOWING;
17398 262 : n->startOffset = NULL;
17399 262 : n->endOffset = NULL;
17400 262 : $$ = n;
17401 : }
17402 : | CURRENT_P ROW
17403 : {
17404 404 : WindowDef *n = makeNode(WindowDef);
17405 :
17406 404 : n->frameOptions = FRAMEOPTION_START_CURRENT_ROW;
17407 404 : n->startOffset = NULL;
17408 404 : n->endOffset = NULL;
17409 404 : $$ = n;
17410 : }
17411 : | a_expr PRECEDING
17412 : {
17413 636 : WindowDef *n = makeNode(WindowDef);
17414 :
17415 636 : n->frameOptions = FRAMEOPTION_START_OFFSET_PRECEDING;
17416 636 : n->startOffset = $1;
17417 636 : n->endOffset = NULL;
17418 636 : $$ = n;
17419 : }
17420 : | a_expr FOLLOWING
17421 : {
17422 802 : WindowDef *n = makeNode(WindowDef);
17423 :
17424 802 : n->frameOptions = FRAMEOPTION_START_OFFSET_FOLLOWING;
17425 802 : n->startOffset = $1;
17426 802 : n->endOffset = NULL;
17427 802 : $$ = n;
17428 : }
17429 : ;
17430 :
17431 : opt_window_exclusion_clause:
17432 64 : EXCLUDE CURRENT_P ROW { $$ = FRAMEOPTION_EXCLUDE_CURRENT_ROW; }
17433 64 : | EXCLUDE GROUP_P { $$ = FRAMEOPTION_EXCLUDE_GROUP; }
17434 100 : | EXCLUDE TIES { $$ = FRAMEOPTION_EXCLUDE_TIES; }
17435 12 : | EXCLUDE NO OTHERS { $$ = 0; }
17436 888 : | /*EMPTY*/ { $$ = 0; }
17437 : ;
17438 :
17439 :
17440 : /*
17441 : * Supporting nonterminals for expressions.
17442 : */
17443 :
17444 : /* Explicit row production.
17445 : *
17446 : * SQL99 allows an optional ROW keyword, so we can now do single-element rows
17447 : * without conflicting with the parenthesized a_expr production. Without the
17448 : * ROW keyword, there must be more than one a_expr inside the parens.
17449 : */
17450 0 : row: ROW '(' expr_list ')' { $$ = $3; }
17451 0 : | ROW '(' ')' { $$ = NIL; }
17452 1018 : | '(' expr_list ',' a_expr ')' { $$ = lappend($2, $4); }
17453 : ;
17454 :
17455 2427 : explicit_row: ROW '(' expr_list ')' { $$ = $3; }
17456 24 : | ROW '(' ')' { $$ = NIL; }
17457 : ;
17458 :
17459 1770 : implicit_row: '(' expr_list ',' a_expr ')' { $$ = lappend($2, $4); }
17460 : ;
17461 :
17462 11190 : sub_type: ANY { $$ = ANY_SUBLINK; }
17463 0 : | SOME { $$ = ANY_SUBLINK; }
17464 221 : | ALL { $$ = ALL_SUBLINK; }
17465 : ;
17466 :
17467 7517 : all_Op: Op { $$ = $1; }
17468 18608 : | MathOp { $$ = $1; }
17469 : ;
17470 :
17471 25 : MathOp: '+' { $$ = "+"; }
17472 34 : | '-' { $$ = "-"; }
17473 95 : | '*' { $$ = "*"; }
17474 0 : | '/' { $$ = "/"; }
17475 4 : | '%' { $$ = "%"; }
17476 0 : | '^' { $$ = "^"; }
17477 549 : | '<' { $$ = "<"; }
17478 482 : | '>' { $$ = ">"; }
17479 16067 : | '=' { $$ = "="; }
17480 450 : | LESS_EQUALS { $$ = "<="; }
17481 444 : | GREATER_EQUALS { $$ = ">="; }
17482 438 : | NOT_EQUALS { $$ = "<>"; }
17483 17 : | RIGHT_ARROW { $$ = "->"; }
17484 3 : | '|' { $$ = "|"; }
17485 : ;
17486 :
17487 : qual_Op: Op
17488 27076 : { $$ = list_make1(makeString($1)); }
17489 : | OPERATOR '(' any_operator ')'
17490 10459 : { $$ = $3; }
17491 : ;
17492 :
17493 : qual_all_Op:
17494 : all_Op
17495 787 : { $$ = list_make1(makeString($1)); }
17496 : | OPERATOR '(' any_operator ')'
17497 17 : { $$ = $3; }
17498 : ;
17499 :
17500 : subquery_Op:
17501 : all_Op
17502 11233 : { $$ = list_make1(makeString($1)); }
17503 : | OPERATOR '(' any_operator ')'
17504 156 : { $$ = $3; }
17505 : | LIKE
17506 16 : { $$ = list_make1(makeString("~~")); }
17507 : | NOT_LA LIKE
17508 8 : { $$ = list_make1(makeString("!~~")); }
17509 : | ILIKE
17510 8 : { $$ = list_make1(makeString("~~*")); }
17511 : | NOT_LA ILIKE
17512 0 : { $$ = list_make1(makeString("!~~*")); }
17513 : /* cannot put SIMILAR TO here, because SIMILAR TO is a hack.
17514 : * the regular expression is preprocessed by a function (similar_to_escape),
17515 : * and the ~ operator for posix regular expressions is used.
17516 : * x SIMILAR TO y -> x ~ similar_to_escape(y)
17517 : * this transformation is made on the fly by the parser upwards.
17518 : * however the SubLink structure which handles any/some/all stuff
17519 : * is not ready for such a thing.
17520 : */
17521 : ;
17522 :
17523 : expr_list: a_expr
17524 : {
17525 106872 : $$ = list_make1($1);
17526 : }
17527 : | expr_list ',' a_expr
17528 : {
17529 97611 : $$ = lappend($1, $3);
17530 : }
17531 : ;
17532 :
17533 : /* function arguments can have names */
17534 : func_arg_list: func_arg_expr
17535 : {
17536 206757 : $$ = list_make1($1);
17537 : }
17538 : | func_arg_list ',' func_arg_expr
17539 : {
17540 176594 : $$ = lappend($1, $3);
17541 : }
17542 : ;
17543 :
17544 : func_arg_expr: a_expr
17545 : {
17546 358455 : $$ = $1;
17547 : }
17548 : | param_name COLON_EQUALS a_expr
17549 : {
17550 24070 : NamedArgExpr *na = makeNode(NamedArgExpr);
17551 :
17552 24070 : na->name = $1;
17553 24070 : na->arg = (Expr *) $3;
17554 24070 : na->argnumber = -1; /* until determined */
17555 24070 : na->location = @1;
17556 24070 : $$ = (Node *) na;
17557 : }
17558 : | param_name EQUALS_GREATER a_expr
17559 : {
17560 1314 : NamedArgExpr *na = makeNode(NamedArgExpr);
17561 :
17562 1314 : na->name = $1;
17563 1314 : na->arg = (Expr *) $3;
17564 1314 : na->argnumber = -1; /* until determined */
17565 1314 : na->location = @1;
17566 1314 : $$ = (Node *) na;
17567 : }
17568 : ;
17569 :
17570 192 : func_arg_list_opt: func_arg_list { $$ = $1; }
17571 0 : | /*EMPTY*/ { $$ = NIL; }
17572 : ;
17573 :
17574 1138 : type_list: Typename { $$ = list_make1($1); }
17575 304 : | type_list ',' Typename { $$ = lappend($1, $3); }
17576 : ;
17577 :
17578 : array_expr: '[' expr_list ']'
17579 : {
17580 5008 : $$ = makeAArrayExpr($2, @1, @3);
17581 : }
17582 : | '[' array_expr_list ']'
17583 : {
17584 255 : $$ = makeAArrayExpr($2, @1, @3);
17585 : }
17586 : | '[' ']'
17587 : {
17588 70 : $$ = makeAArrayExpr(NIL, @1, @2);
17589 : }
17590 : ;
17591 :
17592 255 : array_expr_list: array_expr { $$ = list_make1($1); }
17593 208 : | array_expr_list ',' array_expr { $$ = lappend($1, $3); }
17594 : ;
17595 :
17596 :
17597 : extract_list:
17598 : extract_arg FROM a_expr
17599 : {
17600 860 : $$ = list_make2(makeStringConst($1, @1), $3);
17601 : }
17602 : ;
17603 :
17604 : /* Allow delimited string Sconst in extract_arg as an SQL extension.
17605 : * - thomas 2001-04-12
17606 : */
17607 : extract_arg:
17608 688 : IDENT { $$ = $1; }
17609 48 : | YEAR_P { $$ = "year"; }
17610 28 : | MONTH_P { $$ = "month"; }
17611 36 : | DAY_P { $$ = "day"; }
17612 20 : | HOUR_P { $$ = "hour"; }
17613 20 : | MINUTE_P { $$ = "minute"; }
17614 20 : | SECOND_P { $$ = "second"; }
17615 0 : | Sconst { $$ = $1; }
17616 : ;
17617 :
17618 : unicode_normal_form:
17619 16 : NFC { $$ = "NFC"; }
17620 12 : | NFD { $$ = "NFD"; }
17621 12 : | NFKC { $$ = "NFKC"; }
17622 12 : | NFKD { $$ = "NFKD"; }
17623 : ;
17624 :
17625 : /* OVERLAY() arguments */
17626 : overlay_list:
17627 : a_expr PLACING a_expr FROM a_expr FOR a_expr
17628 : {
17629 : /* overlay(A PLACING B FROM C FOR D) is converted to overlay(A, B, C, D) */
17630 22 : $$ = list_make4($1, $3, $5, $7);
17631 : }
17632 : | a_expr PLACING a_expr FROM a_expr
17633 : {
17634 : /* overlay(A PLACING B FROM C) is converted to overlay(A, B, C) */
17635 32 : $$ = list_make3($1, $3, $5);
17636 : }
17637 : ;
17638 :
17639 : /* position_list uses b_expr not a_expr to avoid conflict with general IN */
17640 : position_list:
17641 255 : b_expr IN_P b_expr { $$ = list_make2($3, $1); }
17642 : ;
17643 :
17644 : /*
17645 : * SUBSTRING() arguments
17646 : *
17647 : * Note that SQL:1999 has both
17648 : * text FROM int FOR int
17649 : * and
17650 : * text FROM pattern FOR escape
17651 : *
17652 : * In the parser we map them both to a call to the substring() function and
17653 : * rely on type resolution to pick the right one.
17654 : *
17655 : * In SQL:2003, the second variant was changed to
17656 : * text SIMILAR pattern ESCAPE escape
17657 : * We could in theory map that to a different function internally, but
17658 : * since we still support the SQL:1999 version, we don't. However,
17659 : * ruleutils.c will reverse-list the call in the newer style.
17660 : */
17661 : substr_list:
17662 : a_expr FROM a_expr FOR a_expr
17663 : {
17664 101 : $$ = list_make3($1, $3, $5);
17665 : }
17666 : | a_expr FOR a_expr FROM a_expr
17667 : {
17668 : /* not legal per SQL, but might as well allow it */
17669 0 : $$ = list_make3($1, $5, $3);
17670 : }
17671 : | a_expr FROM a_expr
17672 : {
17673 : /*
17674 : * Because we aren't restricting data types here, this
17675 : * syntax can end up resolving to textregexsubstr().
17676 : * We've historically allowed that to happen, so continue
17677 : * to accept it. However, ruleutils.c will reverse-list
17678 : * such a call in regular function call syntax.
17679 : */
17680 201 : $$ = list_make2($1, $3);
17681 : }
17682 : | a_expr FOR a_expr
17683 : {
17684 : /* not legal per SQL */
17685 :
17686 : /*
17687 : * Since there are no cases where this syntax allows
17688 : * a textual FOR value, we forcibly cast the argument
17689 : * to int4. The possible matches in pg_proc are
17690 : * substring(text,int4) and substring(text,text),
17691 : * and we don't want the parser to choose the latter,
17692 : * which it is likely to do if the second argument
17693 : * is unknown or doesn't have an implicit cast to int4.
17694 : */
17695 27 : $$ = list_make3($1, makeIntConst(1, -1),
17696 : makeTypeCast($3,
17697 : SystemTypeName("int4"), -1));
17698 : }
17699 : | a_expr SIMILAR a_expr ESCAPE a_expr
17700 : {
17701 110 : $$ = list_make3($1, $3, $5);
17702 : }
17703 : ;
17704 :
17705 388 : trim_list: a_expr FROM expr_list { $$ = lappend($3, $1); }
17706 16 : | FROM expr_list { $$ = $2; }
17707 56 : | expr_list { $$ = $1; }
17708 : ;
17709 :
17710 : /*
17711 : * Define SQL-style CASE clause.
17712 : * - Full specification
17713 : * CASE WHEN a = b THEN c ... ELSE d END
17714 : * - Implicit argument
17715 : * CASE a WHEN b THEN c ... ELSE d END
17716 : */
17717 : case_expr: CASE case_arg when_clause_list case_default END_P
17718 : {
17719 25105 : CaseExpr *c = makeNode(CaseExpr);
17720 :
17721 25105 : c->casetype = InvalidOid; /* not analyzed yet */
17722 25105 : c->arg = (Expr *) $2;
17723 25105 : c->args = $3;
17724 25105 : c->defresult = (Expr *) $4;
17725 25105 : c->location = @1;
17726 25105 : $$ = (Node *) c;
17727 : }
17728 : ;
17729 :
17730 : when_clause_list:
17731 : /* There must be at least one */
17732 25105 : when_clause { $$ = list_make1($1); }
17733 18829 : | when_clause_list when_clause { $$ = lappend($1, $2); }
17734 : ;
17735 :
17736 : when_clause:
17737 : WHEN a_expr THEN a_expr
17738 : {
17739 43934 : CaseWhen *w = makeNode(CaseWhen);
17740 :
17741 43934 : w->expr = (Expr *) $2;
17742 43934 : w->result = (Expr *) $4;
17743 43934 : w->location = @1;
17744 43934 : $$ = (Node *) w;
17745 : }
17746 : ;
17747 :
17748 : case_default:
17749 18952 : ELSE a_expr { $$ = $2; }
17750 6153 : | /*EMPTY*/ { $$ = NULL; }
17751 : ;
17752 :
17753 4553 : case_arg: a_expr { $$ = $1; }
17754 20552 : | /*EMPTY*/ { $$ = NULL; }
17755 : ;
17756 :
17757 : columnref: ColId
17758 : {
17759 483909 : $$ = makeColumnRef($1, NIL, @1, yyscanner);
17760 : }
17761 : | ColId indirection
17762 : {
17763 697796 : $$ = makeColumnRef($1, $2, @1, yyscanner);
17764 : }
17765 : ;
17766 :
17767 : indirection_el:
17768 : '.' attr_name
17769 : {
17770 943517 : $$ = (Node *) makeString($2);
17771 : }
17772 : | '.' '*'
17773 : {
17774 4546 : $$ = (Node *) makeNode(A_Star);
17775 : }
17776 : | '[' a_expr ']'
17777 : {
17778 8638 : A_Indices *ai = makeNode(A_Indices);
17779 :
17780 8638 : ai->is_slice = false;
17781 8638 : ai->lidx = NULL;
17782 8638 : ai->uidx = $2;
17783 8638 : $$ = (Node *) ai;
17784 : }
17785 : | '[' opt_slice_bound ':' opt_slice_bound ']'
17786 : {
17787 405 : A_Indices *ai = makeNode(A_Indices);
17788 :
17789 405 : ai->is_slice = true;
17790 405 : ai->lidx = $2;
17791 405 : ai->uidx = $4;
17792 405 : $$ = (Node *) ai;
17793 : }
17794 : ;
17795 :
17796 : opt_slice_bound:
17797 690 : a_expr { $$ = $1; }
17798 120 : | /*EMPTY*/ { $$ = NULL; }
17799 : ;
17800 :
17801 : indirection:
17802 943234 : indirection_el { $$ = list_make1($1); }
17803 2094 : | indirection indirection_el { $$ = lappend($1, $2); }
17804 : ;
17805 :
17806 : opt_indirection:
17807 123141 : /*EMPTY*/ { $$ = NIL; }
17808 11778 : | opt_indirection indirection_el { $$ = lappend($1, $2); }
17809 : ;
17810 :
17811 : opt_asymmetric: ASYMMETRIC
17812 : | /*EMPTY*/
17813 : ;
17814 :
17815 : /* SQL/JSON support */
17816 : json_passing_clause_opt:
17817 224 : PASSING json_arguments { $$ = $2; }
17818 1332 : | /*EMPTY*/ { $$ = NIL; }
17819 : ;
17820 :
17821 : json_arguments:
17822 224 : json_argument { $$ = list_make1($1); }
17823 84 : | json_arguments ',' json_argument { $$ = lappend($1, $3); }
17824 : ;
17825 :
17826 : json_argument:
17827 : json_value_expr AS ColLabel
17828 : {
17829 308 : JsonArgument *n = makeNode(JsonArgument);
17830 :
17831 308 : n->val = (JsonValueExpr *) $1;
17832 308 : n->name = $3;
17833 308 : $$ = (Node *) n;
17834 : }
17835 : ;
17836 :
17837 : /* ARRAY is a noise word */
17838 : json_wrapper_behavior:
17839 28 : WITHOUT WRAPPER { $$ = JSW_NONE; }
17840 0 : | WITHOUT ARRAY WRAPPER { $$ = JSW_NONE; }
17841 56 : | WITH WRAPPER { $$ = JSW_UNCONDITIONAL; }
17842 8 : | WITH ARRAY WRAPPER { $$ = JSW_UNCONDITIONAL; }
17843 0 : | WITH CONDITIONAL ARRAY WRAPPER { $$ = JSW_CONDITIONAL; }
17844 8 : | WITH UNCONDITIONAL ARRAY WRAPPER { $$ = JSW_UNCONDITIONAL; }
17845 24 : | WITH CONDITIONAL WRAPPER { $$ = JSW_CONDITIONAL; }
17846 4 : | WITH UNCONDITIONAL WRAPPER { $$ = JSW_UNCONDITIONAL; }
17847 1092 : | /* empty */ { $$ = JSW_UNSPEC; }
17848 : ;
17849 :
17850 : json_behavior:
17851 : DEFAULT a_expr
17852 288 : { $$ = (Node *) makeJsonBehavior(JSON_BEHAVIOR_DEFAULT, $2, @1); }
17853 : | json_behavior_type
17854 468 : { $$ = (Node *) makeJsonBehavior($1, NULL, @1); }
17855 : ;
17856 :
17857 : json_behavior_type:
17858 328 : ERROR_P { $$ = JSON_BEHAVIOR_ERROR; }
17859 20 : | NULL_P { $$ = JSON_BEHAVIOR_NULL; }
17860 20 : | TRUE_P { $$ = JSON_BEHAVIOR_TRUE; }
17861 8 : | FALSE_P { $$ = JSON_BEHAVIOR_FALSE; }
17862 8 : | UNKNOWN { $$ = JSON_BEHAVIOR_UNKNOWN; }
17863 20 : | EMPTY_P ARRAY { $$ = JSON_BEHAVIOR_EMPTY_ARRAY; }
17864 48 : | EMPTY_P OBJECT_P { $$ = JSON_BEHAVIOR_EMPTY_OBJECT; }
17865 : /* non-standard, for Oracle compatibility only */
17866 16 : | EMPTY_P { $$ = JSON_BEHAVIOR_EMPTY_ARRAY; }
17867 : ;
17868 :
17869 : json_behavior_clause_opt:
17870 : json_behavior ON EMPTY_P
17871 148 : { $$ = list_make2($1, NULL); }
17872 : | json_behavior ON ERROR_P
17873 368 : { $$ = list_make2(NULL, $1); }
17874 : | json_behavior ON EMPTY_P json_behavior ON ERROR_P
17875 68 : { $$ = list_make2($1, $4); }
17876 : | /* EMPTY */
17877 1056 : { $$ = list_make2(NULL, NULL); }
17878 : ;
17879 :
17880 : json_on_error_clause_opt:
17881 : json_behavior ON ERROR_P
17882 100 : { $$ = $1; }
17883 : | /* EMPTY */
17884 460 : { $$ = NULL; }
17885 : ;
17886 :
17887 : json_value_expr:
17888 : a_expr json_format_clause_opt
17889 : {
17890 : /* formatted_expr will be set during parse-analysis. */
17891 3038 : $$ = (Node *) makeJsonValueExpr((Expr *) $1, NULL,
17892 3038 : castNode(JsonFormat, $2));
17893 : }
17894 : ;
17895 :
17896 : json_format_clause:
17897 : FORMAT_LA JSON ENCODING name
17898 : {
17899 : int encoding;
17900 :
17901 66 : if (!pg_strcasecmp($4, "utf8"))
17902 42 : encoding = JS_ENC_UTF8;
17903 24 : else if (!pg_strcasecmp($4, "utf16"))
17904 8 : encoding = JS_ENC_UTF16;
17905 16 : else if (!pg_strcasecmp($4, "utf32"))
17906 8 : encoding = JS_ENC_UTF32;
17907 : else
17908 8 : ereport(ERROR,
17909 : (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
17910 : errmsg("unrecognized JSON encoding: %s", $4),
17911 : parser_errposition(@4)));
17912 :
17913 58 : $$ = (Node *) makeJsonFormat(JS_FORMAT_JSON, encoding, @1);
17914 : }
17915 : | FORMAT_LA JSON
17916 : {
17917 272 : $$ = (Node *) makeJsonFormat(JS_FORMAT_JSON, JS_ENC_DEFAULT, @1);
17918 : }
17919 : ;
17920 :
17921 : json_format_clause_opt:
17922 : json_format_clause
17923 : {
17924 258 : $$ = $1;
17925 : }
17926 : | /* EMPTY */
17927 : {
17928 4006 : $$ = (Node *) makeJsonFormat(JS_FORMAT_DEFAULT, JS_ENC_DEFAULT, -1);
17929 : }
17930 : ;
17931 :
17932 : json_quotes_clause_opt:
17933 8 : KEEP QUOTES ON SCALAR STRING_P { $$ = JS_QUOTES_KEEP; }
17934 60 : | KEEP QUOTES { $$ = JS_QUOTES_KEEP; }
17935 8 : | OMIT QUOTES ON SCALAR STRING_P { $$ = JS_QUOTES_OMIT; }
17936 112 : | OMIT QUOTES { $$ = JS_QUOTES_OMIT; }
17937 1032 : | /* EMPTY */ { $$ = JS_QUOTES_UNSPEC; }
17938 : ;
17939 :
17940 : json_returning_clause_opt:
17941 : RETURNING Typename json_format_clause_opt
17942 : {
17943 1186 : JsonOutput *n = makeNode(JsonOutput);
17944 :
17945 1186 : n->typeName = $2;
17946 1186 : n->returning = makeNode(JsonReturning);
17947 1186 : n->returning->format = (JsonFormat *) $3;
17948 1186 : $$ = (Node *) n;
17949 : }
17950 860 : | /* EMPTY */ { $$ = NULL; }
17951 : ;
17952 :
17953 : /*
17954 : * We must assign the only-JSON production a precedence less than IDENT in
17955 : * order to favor shifting over reduction when JSON is followed by VALUE_P,
17956 : * OBJECT_P, or SCALAR. (ARRAY doesn't need that treatment, because it's a
17957 : * fully reserved word.) Because json_predicate_type_constraint is always
17958 : * followed by json_key_uniqueness_constraint_opt, we also need the only-JSON
17959 : * production to have precedence less than WITH and WITHOUT. UNBOUNDED isn't
17960 : * really related to this syntax, but it's a convenient choice because it
17961 : * already has a precedence less than IDENT for other reasons.
17962 : */
17963 : json_predicate_type_constraint:
17964 176 : JSON %prec UNBOUNDED { $$ = JS_TYPE_ANY; }
17965 18 : | JSON VALUE_P { $$ = JS_TYPE_ANY; }
17966 26 : | JSON ARRAY { $$ = JS_TYPE_ARRAY; }
17967 26 : | JSON OBJECT_P { $$ = JS_TYPE_OBJECT; }
17968 26 : | JSON SCALAR { $$ = JS_TYPE_SCALAR; }
17969 : ;
17970 :
17971 : /*
17972 : * KEYS is a noise word here. To avoid shift/reduce conflicts, assign the
17973 : * KEYS-less productions a precedence less than IDENT (i.e., less than KEYS).
17974 : * This prevents reducing them when the next token is KEYS.
17975 : */
17976 : json_key_uniqueness_constraint_opt:
17977 98 : WITH UNIQUE KEYS { $$ = true; }
17978 66 : | WITH UNIQUE %prec UNBOUNDED { $$ = true; }
17979 28 : | WITHOUT UNIQUE KEYS { $$ = false; }
17980 10 : | WITHOUT UNIQUE %prec UNBOUNDED { $$ = false; }
17981 636 : | /* EMPTY */ %prec UNBOUNDED { $$ = false; }
17982 : ;
17983 :
17984 : json_name_and_value_list:
17985 : json_name_and_value
17986 318 : { $$ = list_make1($1); }
17987 : | json_name_and_value_list ',' json_name_and_value
17988 168 : { $$ = lappend($1, $3); }
17989 : ;
17990 :
17991 : json_name_and_value:
17992 : /* Supporting this syntax seems to require major surgery
17993 : KEY c_expr VALUE_P json_value_expr
17994 : { $$ = makeJsonKeyValue($2, $4); }
17995 : |
17996 : */
17997 : c_expr VALUE_P json_value_expr
17998 104 : { $$ = makeJsonKeyValue($1, $3); }
17999 : |
18000 : a_expr ':' json_value_expr
18001 526 : { $$ = makeJsonKeyValue($1, $3); }
18002 : ;
18003 :
18004 : /* empty means false for objects, true for arrays */
18005 : json_object_constructor_null_clause_opt:
18006 20 : NULL_P ON NULL_P { $$ = false; }
18007 80 : | ABSENT ON NULL_P { $$ = true; }
18008 362 : | /* EMPTY */ { $$ = false; }
18009 : ;
18010 :
18011 : json_array_constructor_null_clause_opt:
18012 40 : NULL_P ON NULL_P { $$ = false; }
18013 24 : | ABSENT ON NULL_P { $$ = true; }
18014 216 : | /* EMPTY */ { $$ = true; }
18015 : ;
18016 :
18017 : json_value_expr_list:
18018 168 : json_value_expr { $$ = list_make1($1); }
18019 92 : | json_value_expr_list ',' json_value_expr { $$ = lappend($1, $3);}
18020 : ;
18021 :
18022 : json_aggregate_func:
18023 : JSON_OBJECTAGG '('
18024 : json_name_and_value
18025 : json_object_constructor_null_clause_opt
18026 : json_key_uniqueness_constraint_opt
18027 : json_returning_clause_opt
18028 : ')'
18029 : {
18030 144 : JsonObjectAgg *n = makeNode(JsonObjectAgg);
18031 :
18032 144 : n->arg = (JsonKeyValue *) $3;
18033 144 : n->absent_on_null = $4;
18034 144 : n->unique = $5;
18035 144 : n->constructor = makeNode(JsonAggConstructor);
18036 144 : n->constructor->output = (JsonOutput *) $6;
18037 144 : n->constructor->agg_order = NULL;
18038 144 : n->constructor->location = @1;
18039 144 : $$ = (Node *) n;
18040 : }
18041 : | JSON_ARRAYAGG '('
18042 : json_value_expr
18043 : json_array_aggregate_order_by_clause_opt
18044 : json_array_constructor_null_clause_opt
18045 : json_returning_clause_opt
18046 : ')'
18047 : {
18048 112 : JsonArrayAgg *n = makeNode(JsonArrayAgg);
18049 :
18050 112 : n->arg = (JsonValueExpr *) $3;
18051 112 : n->absent_on_null = $5;
18052 112 : n->constructor = makeNode(JsonAggConstructor);
18053 112 : n->constructor->agg_order = $4;
18054 112 : n->constructor->output = (JsonOutput *) $6;
18055 112 : n->constructor->location = @1;
18056 112 : $$ = (Node *) n;
18057 : }
18058 : ;
18059 :
18060 : json_array_aggregate_order_by_clause_opt:
18061 12 : ORDER BY sortby_list { $$ = $3; }
18062 100 : | /* EMPTY */ { $$ = NIL; }
18063 : ;
18064 :
18065 :
18066 : /*****************************************************************************
18067 : *
18068 : * graph patterns
18069 : *
18070 : *****************************************************************************/
18071 :
18072 : graph_pattern:
18073 : path_pattern_list where_clause
18074 : {
18075 385 : GraphPattern *gp = makeNode(GraphPattern);
18076 :
18077 385 : gp->path_pattern_list = $1;
18078 385 : gp->whereClause = $2;
18079 385 : $$ = (Node *) gp;
18080 : }
18081 : ;
18082 :
18083 : path_pattern_list:
18084 385 : path_pattern { $$ = list_make1($1); }
18085 4 : | path_pattern_list ',' path_pattern { $$ = lappend($1, $3); }
18086 : ;
18087 :
18088 : path_pattern:
18089 389 : path_pattern_expression { $$ = $1; }
18090 : ;
18091 :
18092 : /*
18093 : * path pattern expression
18094 : */
18095 :
18096 : path_pattern_expression:
18097 393 : path_term { $$ = $1; }
18098 : /* | path_multiset_alternation */
18099 : /* | path_pattern_union */
18100 : ;
18101 :
18102 : path_term:
18103 397 : path_factor { $$ = list_make1($1); }
18104 790 : | path_term path_factor { $$ = lappend($1, $2); }
18105 : ;
18106 :
18107 : path_factor:
18108 : path_primary opt_graph_pattern_quantifier
18109 : {
18110 1187 : GraphElementPattern *gep = (GraphElementPattern *) $1;
18111 :
18112 1187 : gep->quantifier = $2;
18113 :
18114 1187 : $$ = (Node *) gep;
18115 : }
18116 : ;
18117 :
18118 : path_primary:
18119 : '(' opt_colid opt_is_label_expression where_clause ')'
18120 : {
18121 788 : GraphElementPattern *gep = makeNode(GraphElementPattern);
18122 :
18123 788 : gep->kind = VERTEX_PATTERN;
18124 788 : gep->variable = $2;
18125 788 : gep->labelexpr = $3;
18126 788 : gep->whereClause = $4;
18127 788 : gep->location = @1;
18128 :
18129 788 : $$ = (Node *) gep;
18130 : }
18131 : /* full edge pointing left: <-[ xxx ]- */
18132 : | '<' '-' '[' opt_colid opt_is_label_expression where_clause ']' '-'
18133 : {
18134 8 : GraphElementPattern *gep = makeNode(GraphElementPattern);
18135 :
18136 8 : gep->kind = EDGE_PATTERN_LEFT;
18137 8 : gep->variable = $4;
18138 8 : gep->labelexpr = $5;
18139 8 : gep->whereClause = $6;
18140 8 : gep->location = @1;
18141 :
18142 8 : $$ = (Node *) gep;
18143 : }
18144 : /* full edge pointing right: -[ xxx ]-> */
18145 : | '-' '[' opt_colid opt_is_label_expression where_clause ']' '-' '>'
18146 : {
18147 0 : GraphElementPattern *gep = makeNode(GraphElementPattern);
18148 :
18149 0 : gep->kind = EDGE_PATTERN_RIGHT;
18150 0 : gep->variable = $3;
18151 0 : gep->labelexpr = $4;
18152 0 : gep->whereClause = $5;
18153 0 : gep->location = @1;
18154 :
18155 0 : $$ = (Node *) gep;
18156 : }
18157 : | '-' '[' opt_colid opt_is_label_expression where_clause ']' RIGHT_ARROW
18158 : {
18159 259 : GraphElementPattern *gep = makeNode(GraphElementPattern);
18160 :
18161 259 : gep->kind = EDGE_PATTERN_RIGHT;
18162 259 : gep->variable = $3;
18163 259 : gep->labelexpr = $4;
18164 259 : gep->whereClause = $5;
18165 259 : gep->location = @1;
18166 :
18167 259 : $$ = (Node *) gep;
18168 : }
18169 : /* full edge any direction: -[ xxx ]- */
18170 : | '-' '[' opt_colid opt_is_label_expression where_clause ']' '-'
18171 : {
18172 16 : GraphElementPattern *gep = makeNode(GraphElementPattern);
18173 :
18174 16 : gep->kind = EDGE_PATTERN_ANY;
18175 16 : gep->variable = $3;
18176 16 : gep->labelexpr = $4;
18177 16 : gep->whereClause = $5;
18178 16 : gep->location = @1;
18179 :
18180 16 : $$ = (Node *) gep;
18181 : }
18182 : /* abbreviated edge patterns */
18183 : | '<' '-'
18184 : {
18185 0 : GraphElementPattern *gep = makeNode(GraphElementPattern);
18186 :
18187 0 : gep->kind = EDGE_PATTERN_LEFT;
18188 0 : gep->location = @1;
18189 :
18190 0 : $$ = (Node *) gep;
18191 : }
18192 : | '-' '>'
18193 : {
18194 0 : GraphElementPattern *gep = makeNode(GraphElementPattern);
18195 :
18196 0 : gep->kind = EDGE_PATTERN_RIGHT;
18197 0 : gep->location = @1;
18198 :
18199 0 : $$ = (Node *) gep;
18200 : }
18201 : | RIGHT_ARROW
18202 : {
18203 104 : GraphElementPattern *gep = makeNode(GraphElementPattern);
18204 :
18205 104 : gep->kind = EDGE_PATTERN_RIGHT;
18206 104 : gep->location = @1;
18207 :
18208 104 : $$ = (Node *) gep;
18209 : }
18210 : | '-'
18211 : {
18212 8 : GraphElementPattern *gep = makeNode(GraphElementPattern);
18213 :
18214 8 : gep->kind = EDGE_PATTERN_ANY;
18215 8 : gep->location = @1;
18216 :
18217 8 : $$ = (Node *) gep;
18218 : }
18219 : | '(' path_pattern_expression where_clause ')'
18220 : {
18221 4 : GraphElementPattern *gep = makeNode(GraphElementPattern);
18222 :
18223 4 : gep->kind = PAREN_EXPR;
18224 4 : gep->subexpr = $2;
18225 4 : gep->whereClause = $3;
18226 4 : gep->location = @1;
18227 :
18228 4 : $$ = (Node *) gep;
18229 : }
18230 : ;
18231 :
18232 : opt_colid:
18233 904 : ColId { $$ = $1; }
18234 171 : | /*EMPTY*/ { $$ = NULL; }
18235 : ;
18236 :
18237 : opt_is_label_expression:
18238 591 : IS label_expression { $$ = $2; }
18239 484 : | /*EMPTY*/ { $$ = NULL; }
18240 : ;
18241 :
18242 : /*
18243 : * graph pattern quantifier
18244 : */
18245 :
18246 : opt_graph_pattern_quantifier:
18247 0 : '{' Iconst '}' { $$ = list_make2_int($2, $2); }
18248 0 : | '{' ',' Iconst '}' { $$ = list_make2_int(0, $3); }
18249 4 : | '{' Iconst ',' Iconst '}' { $$ = list_make2_int($2, $4); }
18250 1183 : | /*EMPTY*/ { $$ = NULL; }
18251 : ;
18252 :
18253 : /*
18254 : * label expression
18255 : */
18256 :
18257 : label_expression:
18258 : label_term
18259 : | label_disjunction
18260 : ;
18261 :
18262 : label_disjunction:
18263 : label_expression '|' label_term
18264 56 : { $$ = makeOrExpr($1, $3, @2); }
18265 : ;
18266 :
18267 : label_term:
18268 : name
18269 647 : { $$ = makeColumnRef($1, NIL, @1, yyscanner); }
18270 : ;
18271 :
18272 :
18273 : /*****************************************************************************
18274 : *
18275 : * target list for SELECT
18276 : *
18277 : *****************************************************************************/
18278 :
18279 307705 : opt_target_list: target_list { $$ = $1; }
18280 347 : | /* EMPTY */ { $$ = NIL; }
18281 : ;
18282 :
18283 : target_list:
18284 312406 : target_el { $$ = list_make1($1); }
18285 432226 : | target_list ',' target_el { $$ = lappend($1, $3); }
18286 : ;
18287 :
18288 : target_el: a_expr AS ColLabel
18289 : {
18290 147088 : $$ = makeNode(ResTarget);
18291 147088 : $$->name = $3;
18292 147088 : $$->indirection = NIL;
18293 147088 : $$->val = (Node *) $1;
18294 147088 : $$->location = @1;
18295 : }
18296 : | a_expr BareColLabel
18297 : {
18298 2309 : $$ = makeNode(ResTarget);
18299 2309 : $$->name = $2;
18300 2309 : $$->indirection = NIL;
18301 2309 : $$->val = (Node *) $1;
18302 2309 : $$->location = @1;
18303 : }
18304 : | a_expr
18305 : {
18306 555778 : $$ = makeNode(ResTarget);
18307 555778 : $$->name = NULL;
18308 555778 : $$->indirection = NIL;
18309 555778 : $$->val = (Node *) $1;
18310 555778 : $$->location = @1;
18311 : }
18312 : | '*'
18313 : {
18314 39457 : ColumnRef *n = makeNode(ColumnRef);
18315 :
18316 39457 : n->fields = list_make1(makeNode(A_Star));
18317 39457 : n->location = @1;
18318 :
18319 39457 : $$ = makeNode(ResTarget);
18320 39457 : $$->name = NULL;
18321 39457 : $$->indirection = NIL;
18322 39457 : $$->val = (Node *) n;
18323 39457 : $$->location = @1;
18324 : }
18325 : ;
18326 :
18327 :
18328 : /*****************************************************************************
18329 : *
18330 : * Names and constants
18331 : *
18332 : *****************************************************************************/
18333 :
18334 : qualified_name_list:
18335 10708 : qualified_name { $$ = list_make1($1); }
18336 531 : | qualified_name_list ',' qualified_name { $$ = lappend($1, $3); }
18337 : ;
18338 :
18339 : /*
18340 : * The production for a qualified relation name has to exactly match the
18341 : * production for a qualified func_name, because in a FROM clause we cannot
18342 : * tell which we are parsing until we see what comes after it ('(' for a
18343 : * func_name, something else for a relation). Therefore we allow 'indirection'
18344 : * which may contain subscripts, and reject that case in the C code.
18345 : */
18346 : qualified_name:
18347 : ColId
18348 : {
18349 274782 : $$ = makeRangeVar(NULL, $1, @1);
18350 : }
18351 : | ColId indirection
18352 : {
18353 160420 : $$ = makeRangeVarFromQualifiedName($1, $2, @1, yyscanner);
18354 : }
18355 : ;
18356 :
18357 : name_list: name
18358 17577 : { $$ = list_make1(makeString($1)); }
18359 : | name_list ',' name
18360 34343 : { $$ = lappend($1, makeString($3)); }
18361 : ;
18362 :
18363 :
18364 104381 : name: ColId { $$ = $1; };
18365 :
18366 1020105 : attr_name: ColLabel { $$ = $1; };
18367 :
18368 43 : file_name: Sconst { $$ = $1; };
18369 :
18370 : /*
18371 : * The production for a qualified func_name has to exactly match the
18372 : * production for a qualified columnref, because we cannot tell which we
18373 : * are parsing until we see what comes after it ('(' or Sconst for a func_name,
18374 : * anything else for a columnref). Therefore we allow 'indirection' which
18375 : * may contain subscripts, and reject that case in the C code. (If we
18376 : * ever implement SQL99-like methods, such syntax may actually become legal!)
18377 : */
18378 : func_name: type_function_name
18379 178926 : { $$ = list_make1(makeString($1)); }
18380 : | ColId indirection
18381 : {
18382 84971 : $$ = check_func_name(lcons(makeString($1), $2),
18383 : yyscanner);
18384 : }
18385 : ;
18386 :
18387 :
18388 : /*
18389 : * Constants
18390 : */
18391 : AexprConst: Iconst
18392 : {
18393 255866 : $$ = makeIntConst($1, @1);
18394 : }
18395 : | FCONST
18396 : {
18397 7612 : $$ = makeFloatConst($1, @1);
18398 : }
18399 : | Sconst
18400 : {
18401 449557 : $$ = makeStringConst($1, @1);
18402 : }
18403 : | BCONST
18404 : {
18405 502 : $$ = makeBitStringConst($1, @1);
18406 : }
18407 : | XCONST
18408 : {
18409 : /* This is a bit constant per SQL99:
18410 : * Without Feature F511, "BIT data type",
18411 : * a <general literal> shall not be a
18412 : * <bit string literal> or a <hex string literal>.
18413 : */
18414 2217 : $$ = makeBitStringConst($1, @1);
18415 : }
18416 : | func_name Sconst
18417 : {
18418 : /* generic type 'literal' syntax */
18419 6317 : TypeName *t = makeTypeNameFromNameList($1);
18420 :
18421 6317 : t->location = @1;
18422 6317 : $$ = makeStringConstCast($2, @2, t);
18423 : }
18424 : | func_name '(' func_arg_list opt_sort_clause ')' Sconst
18425 : {
18426 : /* generic syntax with a type modifier */
18427 0 : TypeName *t = makeTypeNameFromNameList($1);
18428 : ListCell *lc;
18429 :
18430 : /*
18431 : * We must use func_arg_list and opt_sort_clause in the
18432 : * production to avoid reduce/reduce conflicts, but we
18433 : * don't actually wish to allow NamedArgExpr in this
18434 : * context, nor ORDER BY.
18435 : */
18436 0 : foreach(lc, $3)
18437 : {
18438 0 : NamedArgExpr *arg = (NamedArgExpr *) lfirst(lc);
18439 :
18440 0 : if (IsA(arg, NamedArgExpr))
18441 0 : ereport(ERROR,
18442 : (errcode(ERRCODE_SYNTAX_ERROR),
18443 : errmsg("type modifier cannot have parameter name"),
18444 : parser_errposition(arg->location)));
18445 : }
18446 0 : if ($4 != NIL)
18447 0 : ereport(ERROR,
18448 : (errcode(ERRCODE_SYNTAX_ERROR),
18449 : errmsg("type modifier cannot have ORDER BY"),
18450 : parser_errposition(@4)));
18451 :
18452 0 : t->typmods = $3;
18453 0 : t->location = @1;
18454 0 : $$ = makeStringConstCast($6, @6, t);
18455 : }
18456 : | ConstTypename Sconst
18457 : {
18458 2043 : $$ = makeStringConstCast($2, @2, $1);
18459 : }
18460 : | ConstInterval Sconst opt_interval
18461 : {
18462 2196 : TypeName *t = $1;
18463 :
18464 2196 : t->typmods = $3;
18465 2196 : $$ = makeStringConstCast($2, @2, t);
18466 : }
18467 : | ConstInterval '(' Iconst ')' Sconst
18468 : {
18469 8 : TypeName *t = $1;
18470 :
18471 8 : t->typmods = list_make2(makeIntConst(INTERVAL_FULL_RANGE, -1),
18472 : makeIntConst($3, @3));
18473 8 : $$ = makeStringConstCast($5, @5, t);
18474 : }
18475 : | TRUE_P
18476 : {
18477 19254 : $$ = makeBoolAConst(true, @1);
18478 : }
18479 : | FALSE_P
18480 : {
18481 19974 : $$ = makeBoolAConst(false, @1);
18482 : }
18483 : | NULL_P
18484 : {
18485 41620 : $$ = makeNullAConst(@1);
18486 : }
18487 : ;
18488 :
18489 271755 : Iconst: ICONST { $$ = $1; };
18490 490584 : Sconst: SCONST { $$ = $1; };
18491 :
18492 9518 : SignedIconst: Iconst { $$ = $1; }
18493 0 : | '+' Iconst { $$ = + $2; }
18494 178 : | '-' Iconst { $$ = - $2; }
18495 : ;
18496 :
18497 : /* Role specifications */
18498 : RoleId: RoleSpec
18499 : {
18500 1313 : RoleSpec *spc = (RoleSpec *) $1;
18501 :
18502 1313 : switch (spc->roletype)
18503 : {
18504 1308 : case ROLESPEC_CSTRING:
18505 1308 : $$ = spc->rolename;
18506 1308 : break;
18507 2 : case ROLESPEC_PUBLIC:
18508 2 : ereport(ERROR,
18509 : (errcode(ERRCODE_RESERVED_NAME),
18510 : errmsg("role name \"%s\" is reserved",
18511 : "public"),
18512 : parser_errposition(@1)));
18513 : break;
18514 1 : case ROLESPEC_SESSION_USER:
18515 1 : ereport(ERROR,
18516 : (errcode(ERRCODE_RESERVED_NAME),
18517 : errmsg("%s cannot be used as a role name here",
18518 : "SESSION_USER"),
18519 : parser_errposition(@1)));
18520 : break;
18521 1 : case ROLESPEC_CURRENT_USER:
18522 1 : ereport(ERROR,
18523 : (errcode(ERRCODE_RESERVED_NAME),
18524 : errmsg("%s cannot be used as a role name here",
18525 : "CURRENT_USER"),
18526 : parser_errposition(@1)));
18527 : break;
18528 1 : case ROLESPEC_CURRENT_ROLE:
18529 1 : ereport(ERROR,
18530 : (errcode(ERRCODE_RESERVED_NAME),
18531 : errmsg("%s cannot be used as a role name here",
18532 : "CURRENT_ROLE"),
18533 : parser_errposition(@1)));
18534 : break;
18535 : }
18536 : }
18537 : ;
18538 :
18539 : RoleSpec: NonReservedWord
18540 : {
18541 : /*
18542 : * "public" and "none" are not keywords, but they must
18543 : * be treated specially here.
18544 : */
18545 : RoleSpec *n;
18546 :
18547 14866 : if (strcmp($1, "public") == 0)
18548 : {
18549 6403 : n = (RoleSpec *) makeRoleSpec(ROLESPEC_PUBLIC, @1);
18550 6403 : n->roletype = ROLESPEC_PUBLIC;
18551 : }
18552 8463 : else if (strcmp($1, "none") == 0)
18553 : {
18554 13 : ereport(ERROR,
18555 : (errcode(ERRCODE_RESERVED_NAME),
18556 : errmsg("role name \"%s\" is reserved",
18557 : "none"),
18558 : parser_errposition(@1)));
18559 : }
18560 : else
18561 : {
18562 8450 : n = makeRoleSpec(ROLESPEC_CSTRING, @1);
18563 8450 : n->rolename = pstrdup($1);
18564 : }
18565 14853 : $$ = n;
18566 : }
18567 : | CURRENT_ROLE
18568 : {
18569 80 : $$ = makeRoleSpec(ROLESPEC_CURRENT_ROLE, @1);
18570 : }
18571 : | CURRENT_USER
18572 : {
18573 145 : $$ = makeRoleSpec(ROLESPEC_CURRENT_USER, @1);
18574 : }
18575 : | SESSION_USER
18576 : {
18577 18 : $$ = makeRoleSpec(ROLESPEC_SESSION_USER, @1);
18578 : }
18579 : ;
18580 :
18581 : role_list: RoleSpec
18582 2075 : { $$ = list_make1($1); }
18583 : | role_list ',' RoleSpec
18584 193 : { $$ = lappend($1, $3); }
18585 : ;
18586 :
18587 :
18588 : /*****************************************************************************
18589 : *
18590 : * PL/pgSQL extensions
18591 : *
18592 : * You'd think a PL/pgSQL "expression" should be just an a_expr, but
18593 : * historically it can include just about anything that can follow SELECT.
18594 : * Therefore the returned struct is a SelectStmt.
18595 : *****************************************************************************/
18596 :
18597 : PLpgSQL_Expr: opt_distinct_clause opt_target_list
18598 : from_clause where_clause
18599 : group_clause having_clause window_clause
18600 : opt_sort_clause opt_select_limit opt_for_locking_clause
18601 : {
18602 24713 : SelectStmt *n = makeNode(SelectStmt);
18603 :
18604 24713 : n->distinctClause = $1;
18605 24713 : n->targetList = $2;
18606 24713 : n->fromClause = $3;
18607 24713 : n->whereClause = $4;
18608 24713 : n->groupClause = ($5)->list;
18609 24713 : n->groupDistinct = ($5)->distinct;
18610 24713 : n->groupByAll = ($5)->all;
18611 24713 : n->havingClause = $6;
18612 24713 : n->windowClause = $7;
18613 24713 : n->sortClause = $8;
18614 24713 : if ($9)
18615 : {
18616 2 : n->limitOffset = $9->limitOffset;
18617 2 : n->limitCount = $9->limitCount;
18618 2 : if (!n->sortClause &&
18619 2 : $9->limitOption == LIMIT_OPTION_WITH_TIES)
18620 0 : ereport(ERROR,
18621 : (errcode(ERRCODE_SYNTAX_ERROR),
18622 : errmsg("WITH TIES cannot be specified without ORDER BY clause"),
18623 : parser_errposition($9->optionLoc)));
18624 2 : n->limitOption = $9->limitOption;
18625 : }
18626 24713 : n->lockingClause = $10;
18627 24713 : $$ = (Node *) n;
18628 : }
18629 : ;
18630 :
18631 : /*
18632 : * PL/pgSQL Assignment statement: name opt_indirection := PLpgSQL_Expr
18633 : */
18634 :
18635 : PLAssignStmt: plassign_target opt_indirection plassign_equals PLpgSQL_Expr
18636 : {
18637 4220 : PLAssignStmt *n = makeNode(PLAssignStmt);
18638 :
18639 4220 : n->name = $1;
18640 4220 : n->indirection = check_indirection($2, yyscanner);
18641 : /* nnames will be filled by calling production */
18642 4220 : n->val = (SelectStmt *) $4;
18643 4220 : n->location = @1;
18644 4220 : $$ = (Node *) n;
18645 : }
18646 : ;
18647 :
18648 4204 : plassign_target: ColId { $$ = $1; }
18649 16 : | PARAM { $$ = psprintf("$%d", $1); }
18650 : ;
18651 :
18652 : plassign_equals: COLON_EQUALS
18653 : | '='
18654 : ;
18655 :
18656 :
18657 : /*
18658 : * Name classification hierarchy.
18659 : *
18660 : * IDENT is the lexeme returned by the lexer for identifiers that match
18661 : * no known keyword. In most cases, we can accept certain keywords as
18662 : * names, not only IDENTs. We prefer to accept as many such keywords
18663 : * as possible to minimize the impact of "reserved words" on programmers.
18664 : * So, we divide names into several possible classes. The classification
18665 : * is chosen in part to make keywords acceptable as names wherever possible.
18666 : */
18667 :
18668 : /* Column identifier --- names that can be column, table, etc names.
18669 : */
18670 2185360 : ColId: IDENT { $$ = $1; }
18671 31847 : | unreserved_keyword { $$ = pstrdup($1); }
18672 3403 : | col_name_keyword { $$ = pstrdup($1); }
18673 : ;
18674 :
18675 : /* Type/function identifier --- names that can be type or function names.
18676 : */
18677 413213 : type_function_name: IDENT { $$ = $1; }
18678 38229 : | unreserved_keyword { $$ = pstrdup($1); }
18679 44 : | type_func_name_keyword { $$ = pstrdup($1); }
18680 : ;
18681 :
18682 : /* Any not-fully-reserved word --- these names can be, eg, role names.
18683 : */
18684 45819 : NonReservedWord: IDENT { $$ = $1; }
18685 19778 : | unreserved_keyword { $$ = pstrdup($1); }
18686 259 : | col_name_keyword { $$ = pstrdup($1); }
18687 3769 : | type_func_name_keyword { $$ = pstrdup($1); }
18688 : ;
18689 :
18690 : /* Column label --- allowed labels in "AS" clauses.
18691 : * This presently includes *all* Postgres keywords.
18692 : */
18693 1156122 : ColLabel: IDENT { $$ = $1; }
18694 25047 : | unreserved_keyword { $$ = pstrdup($1); }
18695 190 : | col_name_keyword { $$ = pstrdup($1); }
18696 934 : | type_func_name_keyword { $$ = pstrdup($1); }
18697 5301 : | reserved_keyword { $$ = pstrdup($1); }
18698 : ;
18699 :
18700 : /* Bare column label --- names that can be column labels without writing "AS".
18701 : * This classification is orthogonal to the other keyword categories.
18702 : */
18703 2301 : BareColLabel: IDENT { $$ = $1; }
18704 8 : | bare_label_keyword { $$ = pstrdup($1); }
18705 : ;
18706 :
18707 :
18708 : /*
18709 : * Keyword category lists. Generally, every keyword present in
18710 : * the Postgres grammar should appear in exactly one of these lists.
18711 : *
18712 : * Put a new keyword into the first list that it can go into without causing
18713 : * shift or reduce conflicts. The earlier lists define "less reserved"
18714 : * categories of keywords.
18715 : *
18716 : * Make sure that each keyword's category in kwlist.h matches where
18717 : * it is listed here. (Someday we may be able to generate these lists and
18718 : * kwlist.h's table from one source of truth.)
18719 : */
18720 :
18721 : /* "Unreserved" keywords --- available for use as any kind of name.
18722 : */
18723 : unreserved_keyword:
18724 : ABORT_P
18725 : | ABSENT
18726 : | ABSOLUTE_P
18727 : | ACCESS
18728 : | ACTION
18729 : | ADD_P
18730 : | ADMIN
18731 : | AFTER
18732 : | AGGREGATE
18733 : | ALSO
18734 : | ALTER
18735 : | ALWAYS
18736 : | ASENSITIVE
18737 : | ASSERTION
18738 : | ASSIGNMENT
18739 : | AT
18740 : | ATOMIC
18741 : | ATTACH
18742 : | ATTRIBUTE
18743 : | BACKWARD
18744 : | BEFORE
18745 : | BEGIN_P
18746 : | BREADTH
18747 : | BY
18748 : | CACHE
18749 : | CALL
18750 : | CALLED
18751 : | CASCADE
18752 : | CASCADED
18753 : | CATALOG_P
18754 : | CHAIN
18755 : | CHARACTERISTICS
18756 : | CHECKPOINT
18757 : | CLASS
18758 : | CLOSE
18759 : | CLUSTER
18760 : | COLUMNS
18761 : | COMMENT
18762 : | COMMENTS
18763 : | COMMIT
18764 : | COMMITTED
18765 : | COMPRESSION
18766 : | CONDITIONAL
18767 : | CONFIGURATION
18768 : | CONFLICT
18769 : | CONNECTION
18770 : | CONSTRAINTS
18771 : | CONTENT_P
18772 : | CONTINUE_P
18773 : | CONVERSION_P
18774 : | COPY
18775 : | COST
18776 : | CSV
18777 : | CUBE
18778 : | CURRENT_P
18779 : | CURSOR
18780 : | CYCLE
18781 : | DATA_P
18782 : | DATABASE
18783 : | DAY_P
18784 : | DEALLOCATE
18785 : | DECLARE
18786 : | DEFAULTS
18787 : | DEFERRED
18788 : | DEFINER
18789 : | DELETE_P
18790 : | DELIMITER
18791 : | DELIMITERS
18792 : | DEPENDS
18793 : | DEPTH
18794 : | DESTINATION
18795 : | DETACH
18796 : | DICTIONARY
18797 : | DISABLE_P
18798 : | DISCARD
18799 : | DOCUMENT_P
18800 : | DOMAIN_P
18801 : | DOUBLE_P
18802 : | DROP
18803 : | EACH
18804 : | EDGE
18805 : | EMPTY_P
18806 : | ENABLE_P
18807 : | ENCODING
18808 : | ENCRYPTED
18809 : | ENFORCED
18810 : | ENUM_P
18811 : | ERROR_P
18812 : | ESCAPE
18813 : | EVENT
18814 : | EXCLUDE
18815 : | EXCLUDING
18816 : | EXCLUSIVE
18817 : | EXECUTE
18818 : | EXPLAIN
18819 : | EXPRESSION
18820 : | EXTENSION
18821 : | EXTERNAL
18822 : | FAMILY
18823 : | FILTER
18824 : | FINALIZE
18825 : | FIRST_P
18826 : | FOLLOWING
18827 : | FORCE
18828 : | FORMAT
18829 : | FORWARD
18830 : | FUNCTION
18831 : | FUNCTIONS
18832 : | GENERATED
18833 : | GLOBAL
18834 : | GRANTED
18835 : | GRAPH
18836 : | GROUPS
18837 : | HANDLER
18838 : | HEADER_P
18839 : | HOLD
18840 : | HOUR_P
18841 : | IDENTITY_P
18842 : | IF_P
18843 : | IGNORE_P
18844 : | IMMEDIATE
18845 : | IMMUTABLE
18846 : | IMPLICIT_P
18847 : | IMPORT_P
18848 : | INCLUDE
18849 : | INCLUDING
18850 : | INCREMENT
18851 : | INDENT
18852 : | INDEX
18853 : | INDEXES
18854 : | INHERIT
18855 : | INHERITS
18856 : | INLINE_P
18857 : | INPUT_P
18858 : | INSENSITIVE
18859 : | INSERT
18860 : | INSTEAD
18861 : | INVOKER
18862 : | ISOLATION
18863 : | KEEP
18864 : | KEY
18865 : | KEYS
18866 : | LABEL
18867 : | LANGUAGE
18868 : | LARGE_P
18869 : | LAST_P
18870 : | LEAKPROOF
18871 : | LEVEL
18872 : | LISTEN
18873 : | LOAD
18874 : | LOCAL
18875 : | LOCATION
18876 : | LOCK_P
18877 : | LOCKED
18878 : | LOGGED
18879 : | LSN_P
18880 : | MAPPING
18881 : | MATCH
18882 : | MATCHED
18883 : | MATERIALIZED
18884 : | MAXVALUE
18885 : | MERGE
18886 : | METHOD
18887 : | MINUTE_P
18888 : | MINVALUE
18889 : | MODE
18890 : | MONTH_P
18891 : | MOVE
18892 : | NAME_P
18893 : | NAMES
18894 : | NESTED
18895 : | NEW
18896 : | NEXT
18897 : | NFC
18898 : | NFD
18899 : | NFKC
18900 : | NFKD
18901 : | NO
18902 : | NODE
18903 : | NORMALIZED
18904 : | NOTHING
18905 : | NOTIFY
18906 : | NOWAIT
18907 : | NULLS_P
18908 : | OBJECT_P
18909 : | OBJECTS_P
18910 : | OF
18911 : | OFF
18912 : | OIDS
18913 : | OLD
18914 : | OMIT
18915 : | OPERATOR
18916 : | OPTION
18917 : | OPTIONS
18918 : | ORDINALITY
18919 : | OTHERS
18920 : | OVER
18921 : | OVERRIDING
18922 : | OWNED
18923 : | OWNER
18924 : | PARALLEL
18925 : | PARAMETER
18926 : | PARSER
18927 : | PARTIAL
18928 : | PARTITION
18929 : | PARTITIONS
18930 : | PASSING
18931 : | PASSWORD
18932 : | PATH
18933 : | PERIOD
18934 : | PLAN
18935 : | PLANS
18936 : | POLICY
18937 : | PRECEDING
18938 : | PREPARE
18939 : | PREPARED
18940 : | PRESERVE
18941 : | PRIOR
18942 : | PRIVILEGES
18943 : | PROCEDURAL
18944 : | PROCEDURE
18945 : | PROCEDURES
18946 : | PROGRAM
18947 : | PROPERTIES
18948 : | PROPERTY
18949 : | PUBLICATION
18950 : | QUOTE
18951 : | QUOTES
18952 : | RANGE
18953 : | READ
18954 : | REASSIGN
18955 : | RECURSIVE
18956 : | REF_P
18957 : | REFERENCING
18958 : | REFRESH
18959 : | REINDEX
18960 : | RELATIONSHIP
18961 : | RELATIVE_P
18962 : | RELEASE
18963 : | RENAME
18964 : | REPACK
18965 : | REPEATABLE
18966 : | REPLACE
18967 : | REPLICA
18968 : | RESET
18969 : | RESPECT_P
18970 : | RESTART
18971 : | RESTRICT
18972 : | RETURN
18973 : | RETURNS
18974 : | REVOKE
18975 : | ROLE
18976 : | ROLLBACK
18977 : | ROLLUP
18978 : | ROUTINE
18979 : | ROUTINES
18980 : | ROWS
18981 : | RULE
18982 : | SAVEPOINT
18983 : | SCALAR
18984 : | SCHEMA
18985 : | SCHEMAS
18986 : | SCROLL
18987 : | SEARCH
18988 : | SECOND_P
18989 : | SECURITY
18990 : | SEQUENCE
18991 : | SEQUENCES
18992 : | SERIALIZABLE
18993 : | SERVER
18994 : | SESSION
18995 : | SET
18996 : | SETS
18997 : | SHARE
18998 : | SHOW
18999 : | SIMPLE
19000 : | SKIP
19001 : | SNAPSHOT
19002 : | SOURCE
19003 : | SPLIT
19004 : | SQL_P
19005 : | STABLE
19006 : | STANDALONE_P
19007 : | START
19008 : | STATEMENT
19009 : | STATISTICS
19010 : | STDIN
19011 : | STDOUT
19012 : | STORAGE
19013 : | STORED
19014 : | STRICT_P
19015 : | STRING_P
19016 : | STRIP_P
19017 : | SUBSCRIPTION
19018 : | SUPPORT
19019 : | SYSID
19020 : | SYSTEM_P
19021 : | TABLES
19022 : | TABLESPACE
19023 : | TARGET
19024 : | TEMP
19025 : | TEMPLATE
19026 : | TEMPORARY
19027 : | TEXT_P
19028 : | TIES
19029 : | TRANSACTION
19030 : | TRANSFORM
19031 : | TRIGGER
19032 : | TRUNCATE
19033 : | TRUSTED
19034 : | TYPE_P
19035 : | TYPES_P
19036 : | UESCAPE
19037 : | UNBOUNDED
19038 : | UNCOMMITTED
19039 : | UNCONDITIONAL
19040 : | UNENCRYPTED
19041 : | UNKNOWN
19042 : | UNLISTEN
19043 : | UNLOGGED
19044 : | UNTIL
19045 : | UPDATE
19046 : | VACUUM
19047 : | VALID
19048 : | VALIDATE
19049 : | VALIDATOR
19050 : | VALUE_P
19051 : | VARYING
19052 : | VERSION_P
19053 : | VERTEX
19054 : | VIEW
19055 : | VIEWS
19056 : | VIRTUAL
19057 : | VOLATILE
19058 : | WAIT
19059 : | WHITESPACE_P
19060 : | WITHIN
19061 : | WITHOUT
19062 : | WORK
19063 : | WRAPPER
19064 : | WRITE
19065 : | XML_P
19066 : | YEAR_P
19067 : | YES_P
19068 : | ZONE
19069 : ;
19070 :
19071 : /* Column identifier --- keywords that can be column, table, etc names.
19072 : *
19073 : * Many of these keywords will in fact be recognized as type or function
19074 : * names too; but they have special productions for the purpose, and so
19075 : * can't be treated as "generic" type or function names.
19076 : *
19077 : * The type names appearing here are not usable as function names
19078 : * because they can be followed by '(' in typename productions, which
19079 : * looks too much like a function call for an LR(1) parser.
19080 : */
19081 : col_name_keyword:
19082 : BETWEEN
19083 : | BIGINT
19084 : | BIT
19085 : | BOOLEAN_P
19086 : | CHAR_P
19087 : | CHARACTER
19088 : | COALESCE
19089 : | DEC
19090 : | DECIMAL_P
19091 : | EXISTS
19092 : | EXTRACT
19093 : | FLOAT_P
19094 : | GRAPH_TABLE
19095 : | GREATEST
19096 : | GROUPING
19097 : | INOUT
19098 : | INT_P
19099 : | INTEGER
19100 : | INTERVAL
19101 : | JSON
19102 : | JSON_ARRAY
19103 : | JSON_ARRAYAGG
19104 : | JSON_EXISTS
19105 : | JSON_OBJECT
19106 : | JSON_OBJECTAGG
19107 : | JSON_QUERY
19108 : | JSON_SCALAR
19109 : | JSON_SERIALIZE
19110 : | JSON_TABLE
19111 : | JSON_VALUE
19112 : | LEAST
19113 : | MERGE_ACTION
19114 : | NATIONAL
19115 : | NCHAR
19116 : | NONE
19117 : | NORMALIZE
19118 : | NULLIF
19119 : | NUMERIC
19120 : | OUT_P
19121 : | OVERLAY
19122 : | POSITION
19123 : | PRECISION
19124 : | REAL
19125 : | ROW
19126 : | SETOF
19127 : | SMALLINT
19128 : | SUBSTRING
19129 : | TIME
19130 : | TIMESTAMP
19131 : | TREAT
19132 : | TRIM
19133 : | VALUES
19134 : | VARCHAR
19135 : | XMLATTRIBUTES
19136 : | XMLCONCAT
19137 : | XMLELEMENT
19138 : | XMLEXISTS
19139 : | XMLFOREST
19140 : | XMLNAMESPACES
19141 : | XMLPARSE
19142 : | XMLPI
19143 : | XMLROOT
19144 : | XMLSERIALIZE
19145 : | XMLTABLE
19146 : ;
19147 :
19148 : /* Type/function identifier --- keywords that can be type or function names.
19149 : *
19150 : * Most of these are keywords that are used as operators in expressions;
19151 : * in general such keywords can't be column names because they would be
19152 : * ambiguous with variables, but they are unambiguous as function identifiers.
19153 : *
19154 : * Do not include POSITION, SUBSTRING, etc here since they have explicit
19155 : * productions in a_expr to support the goofy SQL9x argument syntax.
19156 : * - thomas 2000-11-28
19157 : */
19158 : type_func_name_keyword:
19159 : AUTHORIZATION
19160 : | BINARY
19161 : | COLLATION
19162 : | CONCURRENTLY
19163 : | CROSS
19164 : | CURRENT_SCHEMA
19165 : | FREEZE
19166 : | FULL
19167 : | ILIKE
19168 : | INNER_P
19169 : | IS
19170 : | ISNULL
19171 : | JOIN
19172 : | LEFT
19173 : | LIKE
19174 : | NATURAL
19175 : | NOTNULL
19176 : | OUTER_P
19177 : | OVERLAPS
19178 : | RIGHT
19179 : | SIMILAR
19180 : | TABLESAMPLE
19181 : | VERBOSE
19182 : ;
19183 :
19184 : /* Reserved keyword --- these keywords are usable only as a ColLabel.
19185 : *
19186 : * Keywords appear here if they could not be distinguished from variable,
19187 : * type, or function names in some contexts. Don't put things here unless
19188 : * forced to.
19189 : */
19190 : reserved_keyword:
19191 : ALL
19192 : | ANALYSE
19193 : | ANALYZE
19194 : | AND
19195 : | ANY
19196 : | ARRAY
19197 : | AS
19198 : | ASC
19199 : | ASYMMETRIC
19200 : | BOTH
19201 : | CASE
19202 : | CAST
19203 : | CHECK
19204 : | COLLATE
19205 : | COLUMN
19206 : | CONSTRAINT
19207 : | CREATE
19208 : | CURRENT_CATALOG
19209 : | CURRENT_DATE
19210 : | CURRENT_ROLE
19211 : | CURRENT_TIME
19212 : | CURRENT_TIMESTAMP
19213 : | CURRENT_USER
19214 : | DEFAULT
19215 : | DEFERRABLE
19216 : | DESC
19217 : | DISTINCT
19218 : | DO
19219 : | ELSE
19220 : | END_P
19221 : | EXCEPT
19222 : | FALSE_P
19223 : | FETCH
19224 : | FOR
19225 : | FOREIGN
19226 : | FROM
19227 : | GRANT
19228 : | GROUP_P
19229 : | HAVING
19230 : | IN_P
19231 : | INITIALLY
19232 : | INTERSECT
19233 : | INTO
19234 : | LATERAL_P
19235 : | LEADING
19236 : | LIMIT
19237 : | LOCALTIME
19238 : | LOCALTIMESTAMP
19239 : | NOT
19240 : | NULL_P
19241 : | OFFSET
19242 : | ON
19243 : | ONLY
19244 : | OR
19245 : | ORDER
19246 : | PLACING
19247 : | PRIMARY
19248 : | REFERENCES
19249 : | RETURNING
19250 : | SELECT
19251 : | SESSION_USER
19252 : | SOME
19253 : | SYMMETRIC
19254 : | SYSTEM_USER
19255 : | TABLE
19256 : | THEN
19257 : | TO
19258 : | TRAILING
19259 : | TRUE_P
19260 : | UNION
19261 : | UNIQUE
19262 : | USER
19263 : | USING
19264 : | VARIADIC
19265 : | WHEN
19266 : | WHERE
19267 : | WINDOW
19268 : | WITH
19269 : ;
19270 :
19271 : /*
19272 : * While all keywords can be used as column labels when preceded by AS,
19273 : * not all of them can be used as a "bare" column label without AS.
19274 : * Those that can be used as a bare label must be listed here,
19275 : * in addition to appearing in one of the category lists above.
19276 : *
19277 : * Always add a new keyword to this list if possible. Mark it BARE_LABEL
19278 : * in kwlist.h if it is included here, or AS_LABEL if it is not.
19279 : */
19280 : bare_label_keyword:
19281 : ABORT_P
19282 : | ABSENT
19283 : | ABSOLUTE_P
19284 : | ACCESS
19285 : | ACTION
19286 : | ADD_P
19287 : | ADMIN
19288 : | AFTER
19289 : | AGGREGATE
19290 : | ALL
19291 : | ALSO
19292 : | ALTER
19293 : | ALWAYS
19294 : | ANALYSE
19295 : | ANALYZE
19296 : | AND
19297 : | ANY
19298 : | ASC
19299 : | ASENSITIVE
19300 : | ASSERTION
19301 : | ASSIGNMENT
19302 : | ASYMMETRIC
19303 : | AT
19304 : | ATOMIC
19305 : | ATTACH
19306 : | ATTRIBUTE
19307 : | AUTHORIZATION
19308 : | BACKWARD
19309 : | BEFORE
19310 : | BEGIN_P
19311 : | BETWEEN
19312 : | BIGINT
19313 : | BINARY
19314 : | BIT
19315 : | BOOLEAN_P
19316 : | BOTH
19317 : | BREADTH
19318 : | BY
19319 : | CACHE
19320 : | CALL
19321 : | CALLED
19322 : | CASCADE
19323 : | CASCADED
19324 : | CASE
19325 : | CAST
19326 : | CATALOG_P
19327 : | CHAIN
19328 : | CHARACTERISTICS
19329 : | CHECK
19330 : | CHECKPOINT
19331 : | CLASS
19332 : | CLOSE
19333 : | CLUSTER
19334 : | COALESCE
19335 : | COLLATE
19336 : | COLLATION
19337 : | COLUMN
19338 : | COLUMNS
19339 : | COMMENT
19340 : | COMMENTS
19341 : | COMMIT
19342 : | COMMITTED
19343 : | COMPRESSION
19344 : | CONCURRENTLY
19345 : | CONDITIONAL
19346 : | CONFIGURATION
19347 : | CONFLICT
19348 : | CONNECTION
19349 : | CONSTRAINT
19350 : | CONSTRAINTS
19351 : | CONTENT_P
19352 : | CONTINUE_P
19353 : | CONVERSION_P
19354 : | COPY
19355 : | COST
19356 : | CROSS
19357 : | CSV
19358 : | CUBE
19359 : | CURRENT_P
19360 : | CURRENT_CATALOG
19361 : | CURRENT_DATE
19362 : | CURRENT_ROLE
19363 : | CURRENT_SCHEMA
19364 : | CURRENT_TIME
19365 : | CURRENT_TIMESTAMP
19366 : | CURRENT_USER
19367 : | CURSOR
19368 : | CYCLE
19369 : | DATA_P
19370 : | DATABASE
19371 : | DEALLOCATE
19372 : | DEC
19373 : | DECIMAL_P
19374 : | DECLARE
19375 : | DEFAULT
19376 : | DEFAULTS
19377 : | DEFERRABLE
19378 : | DEFERRED
19379 : | DEFINER
19380 : | DELETE_P
19381 : | DELIMITER
19382 : | DELIMITERS
19383 : | DEPENDS
19384 : | DEPTH
19385 : | DESC
19386 : | DESTINATION
19387 : | DETACH
19388 : | DICTIONARY
19389 : | DISABLE_P
19390 : | DISCARD
19391 : | DISTINCT
19392 : | DO
19393 : | DOCUMENT_P
19394 : | DOMAIN_P
19395 : | DOUBLE_P
19396 : | DROP
19397 : | EACH
19398 : | EDGE
19399 : | ELSE
19400 : | EMPTY_P
19401 : | ENABLE_P
19402 : | ENCODING
19403 : | ENCRYPTED
19404 : | END_P
19405 : | ENFORCED
19406 : | ENUM_P
19407 : | ERROR_P
19408 : | ESCAPE
19409 : | EVENT
19410 : | EXCLUDE
19411 : | EXCLUDING
19412 : | EXCLUSIVE
19413 : | EXECUTE
19414 : | EXISTS
19415 : | EXPLAIN
19416 : | EXPRESSION
19417 : | EXTENSION
19418 : | EXTERNAL
19419 : | EXTRACT
19420 : | FALSE_P
19421 : | FAMILY
19422 : | FINALIZE
19423 : | FIRST_P
19424 : | FLOAT_P
19425 : | FOLLOWING
19426 : | FORCE
19427 : | FOREIGN
19428 : | FORMAT
19429 : | FORWARD
19430 : | FREEZE
19431 : | FULL
19432 : | FUNCTION
19433 : | FUNCTIONS
19434 : | GENERATED
19435 : | GLOBAL
19436 : | GRANTED
19437 : | GRAPH
19438 : | GRAPH_TABLE
19439 : | GREATEST
19440 : | GROUPING
19441 : | GROUPS
19442 : | HANDLER
19443 : | HEADER_P
19444 : | HOLD
19445 : | IDENTITY_P
19446 : | IF_P
19447 : | ILIKE
19448 : | IMMEDIATE
19449 : | IMMUTABLE
19450 : | IMPLICIT_P
19451 : | IMPORT_P
19452 : | IN_P
19453 : | INCLUDE
19454 : | INCLUDING
19455 : | INCREMENT
19456 : | INDENT
19457 : | INDEX
19458 : | INDEXES
19459 : | INHERIT
19460 : | INHERITS
19461 : | INITIALLY
19462 : | INLINE_P
19463 : | INNER_P
19464 : | INOUT
19465 : | INPUT_P
19466 : | INSENSITIVE
19467 : | INSERT
19468 : | INSTEAD
19469 : | INT_P
19470 : | INTEGER
19471 : | INTERVAL
19472 : | INVOKER
19473 : | IS
19474 : | ISOLATION
19475 : | JOIN
19476 : | JSON
19477 : | JSON_ARRAY
19478 : | JSON_ARRAYAGG
19479 : | JSON_EXISTS
19480 : | JSON_OBJECT
19481 : | JSON_OBJECTAGG
19482 : | JSON_QUERY
19483 : | JSON_SCALAR
19484 : | JSON_SERIALIZE
19485 : | JSON_TABLE
19486 : | JSON_VALUE
19487 : | KEEP
19488 : | KEY
19489 : | KEYS
19490 : | LABEL
19491 : | LANGUAGE
19492 : | LARGE_P
19493 : | LAST_P
19494 : | LATERAL_P
19495 : | LEADING
19496 : | LEAKPROOF
19497 : | LEAST
19498 : | LEFT
19499 : | LEVEL
19500 : | LIKE
19501 : | LISTEN
19502 : | LOAD
19503 : | LOCAL
19504 : | LOCALTIME
19505 : | LOCALTIMESTAMP
19506 : | LOCATION
19507 : | LOCK_P
19508 : | LOCKED
19509 : | LOGGED
19510 : | LSN_P
19511 : | MAPPING
19512 : | MATCH
19513 : | MATCHED
19514 : | MATERIALIZED
19515 : | MAXVALUE
19516 : | MERGE
19517 : | MERGE_ACTION
19518 : | METHOD
19519 : | MINVALUE
19520 : | MODE
19521 : | MOVE
19522 : | NAME_P
19523 : | NAMES
19524 : | NATIONAL
19525 : | NATURAL
19526 : | NCHAR
19527 : | NESTED
19528 : | NEW
19529 : | NEXT
19530 : | NFC
19531 : | NFD
19532 : | NFKC
19533 : | NFKD
19534 : | NO
19535 : | NODE
19536 : | NONE
19537 : | NORMALIZE
19538 : | NORMALIZED
19539 : | NOT
19540 : | NOTHING
19541 : | NOTIFY
19542 : | NOWAIT
19543 : | NULL_P
19544 : | NULLIF
19545 : | NULLS_P
19546 : | NUMERIC
19547 : | OBJECT_P
19548 : | OBJECTS_P
19549 : | OF
19550 : | OFF
19551 : | OIDS
19552 : | OLD
19553 : | OMIT
19554 : | ONLY
19555 : | OPERATOR
19556 : | OPTION
19557 : | OPTIONS
19558 : | OR
19559 : | ORDINALITY
19560 : | OTHERS
19561 : | OUT_P
19562 : | OUTER_P
19563 : | OVERLAY
19564 : | OVERRIDING
19565 : | OWNED
19566 : | OWNER
19567 : | PARALLEL
19568 : | PARAMETER
19569 : | PARSER
19570 : | PARTIAL
19571 : | PARTITION
19572 : | PARTITIONS
19573 : | PASSING
19574 : | PASSWORD
19575 : | PATH
19576 : | PERIOD
19577 : | PLACING
19578 : | PLAN
19579 : | PLANS
19580 : | POLICY
19581 : | POSITION
19582 : | PRECEDING
19583 : | PREPARE
19584 : | PREPARED
19585 : | PRESERVE
19586 : | PRIMARY
19587 : | PRIOR
19588 : | PRIVILEGES
19589 : | PROCEDURAL
19590 : | PROCEDURE
19591 : | PROCEDURES
19592 : | PROGRAM
19593 : | PROPERTIES
19594 : | PROPERTY
19595 : | PUBLICATION
19596 : | QUOTE
19597 : | QUOTES
19598 : | RANGE
19599 : | READ
19600 : | REAL
19601 : | REASSIGN
19602 : | RECURSIVE
19603 : | REF_P
19604 : | REFERENCES
19605 : | REFERENCING
19606 : | REFRESH
19607 : | REINDEX
19608 : | RELATIONSHIP
19609 : | RELATIVE_P
19610 : | RELEASE
19611 : | RENAME
19612 : | REPACK
19613 : | REPEATABLE
19614 : | REPLACE
19615 : | REPLICA
19616 : | RESET
19617 : | RESTART
19618 : | RESTRICT
19619 : | RETURN
19620 : | RETURNS
19621 : | REVOKE
19622 : | RIGHT
19623 : | ROLE
19624 : | ROLLBACK
19625 : | ROLLUP
19626 : | ROUTINE
19627 : | ROUTINES
19628 : | ROW
19629 : | ROWS
19630 : | RULE
19631 : | SAVEPOINT
19632 : | SCALAR
19633 : | SCHEMA
19634 : | SCHEMAS
19635 : | SCROLL
19636 : | SEARCH
19637 : | SECURITY
19638 : | SELECT
19639 : | SEQUENCE
19640 : | SEQUENCES
19641 : | SERIALIZABLE
19642 : | SERVER
19643 : | SESSION
19644 : | SESSION_USER
19645 : | SET
19646 : | SETOF
19647 : | SETS
19648 : | SHARE
19649 : | SHOW
19650 : | SIMILAR
19651 : | SIMPLE
19652 : | SKIP
19653 : | SMALLINT
19654 : | SNAPSHOT
19655 : | SOME
19656 : | SOURCE
19657 : | SPLIT
19658 : | SQL_P
19659 : | STABLE
19660 : | STANDALONE_P
19661 : | START
19662 : | STATEMENT
19663 : | STATISTICS
19664 : | STDIN
19665 : | STDOUT
19666 : | STORAGE
19667 : | STORED
19668 : | STRICT_P
19669 : | STRING_P
19670 : | STRIP_P
19671 : | SUBSCRIPTION
19672 : | SUBSTRING
19673 : | SUPPORT
19674 : | SYMMETRIC
19675 : | SYSID
19676 : | SYSTEM_P
19677 : | SYSTEM_USER
19678 : | TABLE
19679 : | TABLES
19680 : | TABLESAMPLE
19681 : | TABLESPACE
19682 : | TARGET
19683 : | TEMP
19684 : | TEMPLATE
19685 : | TEMPORARY
19686 : | TEXT_P
19687 : | THEN
19688 : | TIES
19689 : | TIME
19690 : | TIMESTAMP
19691 : | TRAILING
19692 : | TRANSACTION
19693 : | TRANSFORM
19694 : | TREAT
19695 : | TRIGGER
19696 : | TRIM
19697 : | TRUE_P
19698 : | TRUNCATE
19699 : | TRUSTED
19700 : | TYPE_P
19701 : | TYPES_P
19702 : | UESCAPE
19703 : | UNBOUNDED
19704 : | UNCOMMITTED
19705 : | UNCONDITIONAL
19706 : | UNENCRYPTED
19707 : | UNIQUE
19708 : | UNKNOWN
19709 : | UNLISTEN
19710 : | UNLOGGED
19711 : | UNTIL
19712 : | UPDATE
19713 : | USER
19714 : | USING
19715 : | VACUUM
19716 : | VALID
19717 : | VALIDATE
19718 : | VALIDATOR
19719 : | VALUE_P
19720 : | VALUES
19721 : | VARCHAR
19722 : | VARIADIC
19723 : | VERBOSE
19724 : | VERSION_P
19725 : | VERTEX
19726 : | VIEW
19727 : | VIEWS
19728 : | VIRTUAL
19729 : | VOLATILE
19730 : | WAIT
19731 : | WHEN
19732 : | WHITESPACE_P
19733 : | WORK
19734 : | WRAPPER
19735 : | WRITE
19736 : | XML_P
19737 : | XMLATTRIBUTES
19738 : | XMLCONCAT
19739 : | XMLELEMENT
19740 : | XMLEXISTS
19741 : | XMLFOREST
19742 : | XMLNAMESPACES
19743 : | XMLPARSE
19744 : | XMLPI
19745 : | XMLROOT
19746 : | XMLSERIALIZE
19747 : | XMLTABLE
19748 : | YES_P
19749 : | ZONE
19750 : ;
19751 :
19752 : %%
19753 :
19754 : /*
19755 : * The signature of this function is required by bison. However, we
19756 : * ignore the passed yylloc and instead use the last token position
19757 : * available from the scanner.
19758 : */
19759 : static void
19760 469 : base_yyerror(YYLTYPE *yylloc, core_yyscan_t yyscanner, const char *msg)
19761 : {
19762 469 : parser_yyerror(msg);
19763 : }
19764 :
19765 : static RawStmt *
19766 510218 : makeRawStmt(Node *stmt, int stmt_location)
19767 : {
19768 510218 : RawStmt *rs = makeNode(RawStmt);
19769 :
19770 510218 : rs->stmt = stmt;
19771 510218 : rs->stmt_location = stmt_location;
19772 510218 : rs->stmt_len = 0; /* might get changed later */
19773 510218 : return rs;
19774 : }
19775 :
19776 : /* Adjust a RawStmt to reflect that it doesn't run to the end of the string */
19777 : static void
19778 375474 : updateRawStmtEnd(RawStmt *rs, int end_location)
19779 : {
19780 : /*
19781 : * If we already set the length, don't change it. This is for situations
19782 : * like "select foo ;; select bar" where the same statement will be last
19783 : * in the string for more than one semicolon.
19784 : */
19785 375474 : if (rs->stmt_len > 0)
19786 301 : return;
19787 :
19788 : /* OK, update length of RawStmt */
19789 375173 : rs->stmt_len = end_location - rs->stmt_location;
19790 : }
19791 :
19792 : static Node *
19793 1182361 : makeColumnRef(char *colname, List *indirection,
19794 : int location, core_yyscan_t yyscanner)
19795 : {
19796 : /*
19797 : * Generate a ColumnRef node, with an A_Indirection node added if there is
19798 : * any subscripting in the specified indirection list. However, any field
19799 : * selection at the start of the indirection list must be transposed into
19800 : * the "fields" part of the ColumnRef node.
19801 : */
19802 1182361 : ColumnRef *c = makeNode(ColumnRef);
19803 1182361 : int nfields = 0;
19804 : ListCell *l;
19805 :
19806 1182361 : c->location = location;
19807 1875532 : foreach(l, indirection)
19808 : {
19809 699685 : if (IsA(lfirst(l), A_Indices))
19810 : {
19811 6514 : A_Indirection *i = makeNode(A_Indirection);
19812 :
19813 6514 : if (nfields == 0)
19814 : {
19815 : /* easy case - all indirection goes to A_Indirection */
19816 4680 : c->fields = list_make1(makeString(colname));
19817 4680 : i->indirection = check_indirection(indirection, yyscanner);
19818 : }
19819 : else
19820 : {
19821 : /* got to split the list in two */
19822 1834 : i->indirection = check_indirection(list_copy_tail(indirection,
19823 : nfields),
19824 : yyscanner);
19825 1834 : indirection = list_truncate(indirection, nfields);
19826 1834 : c->fields = lcons(makeString(colname), indirection);
19827 : }
19828 6514 : i->arg = (Node *) c;
19829 6514 : return (Node *) i;
19830 : }
19831 693171 : else if (IsA(lfirst(l), A_Star))
19832 : {
19833 : /* We only allow '*' at the end of a ColumnRef */
19834 3659 : if (lnext(indirection, l) != NULL)
19835 0 : parser_yyerror("improper use of \"*\"");
19836 : }
19837 693171 : nfields++;
19838 : }
19839 : /* No subscripting, so all indirection gets added to field list */
19840 1175847 : c->fields = lcons(makeString(colname), indirection);
19841 1175847 : return (Node *) c;
19842 : }
19843 :
19844 : static Node *
19845 193177 : makeTypeCast(Node *arg, TypeName *typename, int location)
19846 : {
19847 193177 : TypeCast *n = makeNode(TypeCast);
19848 :
19849 193177 : n->arg = arg;
19850 193177 : n->typeName = typename;
19851 193177 : n->location = location;
19852 193177 : return (Node *) n;
19853 : }
19854 :
19855 : static Node *
19856 10564 : makeStringConstCast(char *str, int location, TypeName *typename)
19857 : {
19858 10564 : Node *s = makeStringConst(str, location);
19859 :
19860 10564 : return makeTypeCast(s, typename, -1);
19861 : }
19862 :
19863 : static Node *
19864 262270 : makeIntConst(int val, int location)
19865 : {
19866 262270 : A_Const *n = makeNode(A_Const);
19867 :
19868 262270 : n->val.ival.type = T_Integer;
19869 262270 : n->val.ival.ival = val;
19870 262270 : n->location = location;
19871 :
19872 262270 : return (Node *) n;
19873 : }
19874 :
19875 : static Node *
19876 7746 : makeFloatConst(char *str, int location)
19877 : {
19878 7746 : A_Const *n = makeNode(A_Const);
19879 :
19880 7746 : n->val.fval.type = T_Float;
19881 7746 : n->val.fval.fval = str;
19882 7746 : n->location = location;
19883 :
19884 7746 : return (Node *) n;
19885 : }
19886 :
19887 : static Node *
19888 39401 : makeBoolAConst(bool state, int location)
19889 : {
19890 39401 : A_Const *n = makeNode(A_Const);
19891 :
19892 39401 : n->val.boolval.type = T_Boolean;
19893 39401 : n->val.boolval.boolval = state;
19894 39401 : n->location = location;
19895 :
19896 39401 : return (Node *) n;
19897 : }
19898 :
19899 : static Node *
19900 2719 : makeBitStringConst(char *str, int location)
19901 : {
19902 2719 : A_Const *n = makeNode(A_Const);
19903 :
19904 2719 : n->val.bsval.type = T_BitString;
19905 2719 : n->val.bsval.bsval = str;
19906 2719 : n->location = location;
19907 :
19908 2719 : return (Node *) n;
19909 : }
19910 :
19911 : static Node *
19912 41667 : makeNullAConst(int location)
19913 : {
19914 41667 : A_Const *n = makeNode(A_Const);
19915 :
19916 41667 : n->isnull = true;
19917 41667 : n->location = location;
19918 :
19919 41667 : return (Node *) n;
19920 : }
19921 :
19922 : static Node *
19923 3448 : makeAConst(Node *v, int location)
19924 : {
19925 : Node *n;
19926 :
19927 3448 : switch (v->type)
19928 : {
19929 134 : case T_Float:
19930 134 : n = makeFloatConst(castNode(Float, v)->fval, location);
19931 134 : break;
19932 :
19933 3314 : case T_Integer:
19934 3314 : n = makeIntConst(castNode(Integer, v)->ival, location);
19935 3314 : break;
19936 :
19937 0 : default:
19938 : /* currently not used */
19939 : Assert(false);
19940 0 : n = NULL;
19941 : }
19942 :
19943 3448 : return n;
19944 : }
19945 :
19946 : /* makeRoleSpec
19947 : * Create a RoleSpec with the given type
19948 : */
19949 : static RoleSpec *
19950 15575 : makeRoleSpec(RoleSpecType type, int location)
19951 : {
19952 15575 : RoleSpec *spec = makeNode(RoleSpec);
19953 :
19954 15575 : spec->roletype = type;
19955 15575 : spec->location = location;
19956 :
19957 15575 : return spec;
19958 : }
19959 :
19960 : /* check_qualified_name --- check the result of qualified_name production
19961 : *
19962 : * It's easiest to let the grammar production for qualified_name allow
19963 : * subscripts and '*', which we then must reject here.
19964 : */
19965 : static void
19966 160441 : check_qualified_name(List *names, core_yyscan_t yyscanner)
19967 : {
19968 : ListCell *i;
19969 :
19970 320882 : foreach(i, names)
19971 : {
19972 160441 : if (!IsA(lfirst(i), String))
19973 0 : parser_yyerror("syntax error");
19974 : }
19975 160441 : }
19976 :
19977 : /* check_func_name --- check the result of func_name production
19978 : *
19979 : * It's easiest to let the grammar production for func_name allow subscripts
19980 : * and '*', which we then must reject here.
19981 : */
19982 : static List *
19983 84985 : check_func_name(List *names, core_yyscan_t yyscanner)
19984 : {
19985 : ListCell *i;
19986 :
19987 254955 : foreach(i, names)
19988 : {
19989 169970 : if (!IsA(lfirst(i), String))
19990 0 : parser_yyerror("syntax error");
19991 : }
19992 84985 : return names;
19993 : }
19994 :
19995 : /* check_indirection --- check the result of indirection production
19996 : *
19997 : * We only allow '*' at the end of the list, but it's hard to enforce that
19998 : * in the grammar, so do it here.
19999 : */
20000 : static List *
20001 51583 : check_indirection(List *indirection, core_yyscan_t yyscanner)
20002 : {
20003 : ListCell *l;
20004 :
20005 70092 : foreach(l, indirection)
20006 : {
20007 18509 : if (IsA(lfirst(l), A_Star))
20008 : {
20009 887 : if (lnext(indirection, l) != NULL)
20010 0 : parser_yyerror("improper use of \"*\"");
20011 : }
20012 : }
20013 51583 : return indirection;
20014 : }
20015 :
20016 : /* extractArgTypes()
20017 : * Given a list of FunctionParameter nodes, extract a list of just the
20018 : * argument types (TypeNames) for input parameters only. This is what
20019 : * is needed to look up an existing function, which is what is wanted by
20020 : * the productions that use this call.
20021 : */
20022 : static List *
20023 5265 : extractArgTypes(List *parameters)
20024 : {
20025 5265 : List *result = NIL;
20026 : ListCell *i;
20027 :
20028 13272 : foreach(i, parameters)
20029 : {
20030 8007 : FunctionParameter *p = (FunctionParameter *) lfirst(i);
20031 :
20032 8007 : if (p->mode != FUNC_PARAM_OUT && p->mode != FUNC_PARAM_TABLE)
20033 7920 : result = lappend(result, p->argType);
20034 : }
20035 5265 : return result;
20036 : }
20037 :
20038 : /* extractAggrArgTypes()
20039 : * As above, but work from the output of the aggr_args production.
20040 : */
20041 : static List *
20042 220 : extractAggrArgTypes(List *aggrargs)
20043 : {
20044 : Assert(list_length(aggrargs) == 2);
20045 220 : return extractArgTypes((List *) linitial(aggrargs));
20046 : }
20047 :
20048 : /* makeOrderedSetArgs()
20049 : * Build the result of the aggr_args production (which see the comments for).
20050 : * This handles only the case where both given lists are nonempty, so that
20051 : * we have to deal with multiple VARIADIC arguments.
20052 : */
20053 : static List *
20054 20 : makeOrderedSetArgs(List *directargs, List *orderedargs,
20055 : core_yyscan_t yyscanner)
20056 : {
20057 20 : FunctionParameter *lastd = (FunctionParameter *) llast(directargs);
20058 : Integer *ndirectargs;
20059 :
20060 : /* No restriction unless last direct arg is VARIADIC */
20061 20 : if (lastd->mode == FUNC_PARAM_VARIADIC)
20062 : {
20063 10 : FunctionParameter *firsto = (FunctionParameter *) linitial(orderedargs);
20064 :
20065 : /*
20066 : * We ignore the names, though the aggr_arg production allows them; it
20067 : * doesn't allow default values, so those need not be checked.
20068 : */
20069 10 : if (list_length(orderedargs) != 1 ||
20070 10 : firsto->mode != FUNC_PARAM_VARIADIC ||
20071 10 : !equal(lastd->argType, firsto->argType))
20072 0 : ereport(ERROR,
20073 : (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
20074 : errmsg("an ordered-set aggregate with a VARIADIC direct argument must have one VARIADIC aggregated argument of the same data type"),
20075 : parser_errposition(firsto->location)));
20076 :
20077 : /* OK, drop the duplicate VARIADIC argument from the internal form */
20078 10 : orderedargs = NIL;
20079 : }
20080 :
20081 : /* don't merge into the next line, as list_concat changes directargs */
20082 20 : ndirectargs = makeInteger(list_length(directargs));
20083 :
20084 20 : return list_make2(list_concat(directargs, orderedargs),
20085 : ndirectargs);
20086 : }
20087 :
20088 : /* insertSelectOptions()
20089 : * Insert ORDER BY, etc into an already-constructed SelectStmt.
20090 : *
20091 : * This routine is just to avoid duplicating code in SelectStmt productions.
20092 : */
20093 : static void
20094 59896 : insertSelectOptions(SelectStmt *stmt,
20095 : List *sortClause, List *lockingClause,
20096 : SelectLimit *limitClause,
20097 : WithClause *withClause,
20098 : core_yyscan_t yyscanner)
20099 : {
20100 : Assert(IsA(stmt, SelectStmt));
20101 :
20102 : /*
20103 : * Tests here are to reject constructs like
20104 : * (SELECT foo ORDER BY bar) ORDER BY baz
20105 : */
20106 59896 : if (sortClause)
20107 : {
20108 51147 : if (stmt->sortClause)
20109 0 : ereport(ERROR,
20110 : (errcode(ERRCODE_SYNTAX_ERROR),
20111 : errmsg("multiple ORDER BY clauses not allowed"),
20112 : parser_errposition(exprLocation((Node *) sortClause))));
20113 51147 : stmt->sortClause = sortClause;
20114 : }
20115 : /* We can handle multiple locking clauses, though */
20116 59896 : stmt->lockingClause = list_concat(stmt->lockingClause, lockingClause);
20117 59896 : if (limitClause && limitClause->limitOffset)
20118 : {
20119 534 : if (stmt->limitOffset)
20120 0 : ereport(ERROR,
20121 : (errcode(ERRCODE_SYNTAX_ERROR),
20122 : errmsg("multiple OFFSET clauses not allowed"),
20123 : parser_errposition(limitClause->offsetLoc)));
20124 534 : stmt->limitOffset = limitClause->limitOffset;
20125 : }
20126 59896 : if (limitClause && limitClause->limitCount)
20127 : {
20128 2927 : if (stmt->limitCount)
20129 0 : ereport(ERROR,
20130 : (errcode(ERRCODE_SYNTAX_ERROR),
20131 : errmsg("multiple LIMIT clauses not allowed"),
20132 : parser_errposition(limitClause->countLoc)));
20133 2927 : stmt->limitCount = limitClause->limitCount;
20134 : }
20135 59896 : if (limitClause)
20136 : {
20137 : /* If there was a conflict, we must have detected it above */
20138 : Assert(!stmt->limitOption);
20139 3249 : if (!stmt->sortClause && limitClause->limitOption == LIMIT_OPTION_WITH_TIES)
20140 4 : ereport(ERROR,
20141 : (errcode(ERRCODE_SYNTAX_ERROR),
20142 : errmsg("WITH TIES cannot be specified without ORDER BY clause"),
20143 : parser_errposition(limitClause->optionLoc)));
20144 3245 : if (limitClause->limitOption == LIMIT_OPTION_WITH_TIES && stmt->lockingClause)
20145 : {
20146 : ListCell *lc;
20147 :
20148 4 : foreach(lc, stmt->lockingClause)
20149 : {
20150 4 : LockingClause *lock = lfirst_node(LockingClause, lc);
20151 :
20152 4 : if (lock->waitPolicy == LockWaitSkip)
20153 4 : ereport(ERROR,
20154 : (errcode(ERRCODE_SYNTAX_ERROR),
20155 : errmsg("%s and %s options cannot be used together",
20156 : "SKIP LOCKED", "WITH TIES"),
20157 : parser_errposition(limitClause->optionLoc)));
20158 : }
20159 : }
20160 3241 : stmt->limitOption = limitClause->limitOption;
20161 : }
20162 59888 : if (withClause)
20163 : {
20164 1919 : if (stmt->withClause)
20165 0 : ereport(ERROR,
20166 : (errcode(ERRCODE_SYNTAX_ERROR),
20167 : errmsg("multiple WITH clauses not allowed"),
20168 : parser_errposition(exprLocation((Node *) withClause))));
20169 1919 : stmt->withClause = withClause;
20170 : }
20171 59888 : }
20172 :
20173 : static Node *
20174 12893 : makeSetOp(SetOperation op, bool all, Node *larg, Node *rarg)
20175 : {
20176 12893 : SelectStmt *n = makeNode(SelectStmt);
20177 :
20178 12893 : n->op = op;
20179 12893 : n->all = all;
20180 12893 : n->larg = (SelectStmt *) larg;
20181 12893 : n->rarg = (SelectStmt *) rarg;
20182 12893 : return (Node *) n;
20183 : }
20184 :
20185 : /* SystemFuncName()
20186 : * Build a properly-qualified reference to a built-in function.
20187 : */
20188 : List *
20189 12453 : SystemFuncName(char *name)
20190 : {
20191 12453 : return list_make2(makeString("pg_catalog"), makeString(name));
20192 : }
20193 :
20194 : /* SystemTypeName()
20195 : * Build a properly-qualified reference to a built-in type.
20196 : *
20197 : * typmod is defaulted, but may be changed afterwards by caller.
20198 : * Likewise for the location.
20199 : */
20200 : TypeName *
20201 69410 : SystemTypeName(char *name)
20202 : {
20203 69410 : return makeTypeNameFromNameList(list_make2(makeString("pg_catalog"),
20204 : makeString(name)));
20205 : }
20206 :
20207 : /* doNegate()
20208 : * Handle negation of a numeric constant.
20209 : *
20210 : * Formerly, we did this here because the optimizer couldn't cope with
20211 : * indexquals that looked like "var = -4" --- it wants "var = const"
20212 : * and a unary minus operator applied to a constant didn't qualify.
20213 : * As of Postgres 7.0, that problem doesn't exist anymore because there
20214 : * is a constant-subexpression simplifier in the optimizer. However,
20215 : * there's still a good reason for doing this here, which is that we can
20216 : * postpone committing to a particular internal representation for simple
20217 : * negative constants. It's better to leave "-123.456" in string form
20218 : * until we know what the desired type is.
20219 : */
20220 : static Node *
20221 5983 : doNegate(Node *n, int location)
20222 : {
20223 5983 : if (IsA(n, A_Const))
20224 : {
20225 5329 : A_Const *con = (A_Const *) n;
20226 :
20227 : /* report the constant's location as that of the '-' sign */
20228 5329 : con->location = location;
20229 :
20230 5329 : if (IsA(&con->val, Integer))
20231 : {
20232 4694 : con->val.ival.ival = -con->val.ival.ival;
20233 4694 : return n;
20234 : }
20235 635 : if (IsA(&con->val, Float))
20236 : {
20237 635 : doNegateFloat(&con->val.fval);
20238 635 : return n;
20239 : }
20240 : }
20241 :
20242 654 : return (Node *) makeSimpleA_Expr(AEXPR_OP, "-", NULL, n, location);
20243 : }
20244 :
20245 : static void
20246 648 : doNegateFloat(Float *v)
20247 : {
20248 648 : char *oldval = v->fval;
20249 :
20250 648 : if (*oldval == '+')
20251 0 : oldval++;
20252 648 : if (*oldval == '-')
20253 0 : v->fval = oldval + 1; /* just strip the '-' */
20254 : else
20255 648 : v->fval = psprintf("-%s", oldval);
20256 648 : }
20257 :
20258 : static Node *
20259 153852 : makeAndExpr(Node *lexpr, Node *rexpr, int location)
20260 : {
20261 : /* Flatten "a AND b AND c ..." to a single BoolExpr on sight */
20262 153852 : if (IsA(lexpr, BoolExpr))
20263 : {
20264 71692 : BoolExpr *blexpr = (BoolExpr *) lexpr;
20265 :
20266 71692 : if (blexpr->boolop == AND_EXPR)
20267 : {
20268 67896 : blexpr->args = lappend(blexpr->args, rexpr);
20269 67896 : return (Node *) blexpr;
20270 : }
20271 : }
20272 85956 : return (Node *) makeBoolExpr(AND_EXPR, list_make2(lexpr, rexpr), location);
20273 : }
20274 :
20275 : static Node *
20276 14491 : makeOrExpr(Node *lexpr, Node *rexpr, int location)
20277 : {
20278 : /* Flatten "a OR b OR c ..." to a single BoolExpr on sight */
20279 14491 : if (IsA(lexpr, BoolExpr))
20280 : {
20281 3624 : BoolExpr *blexpr = (BoolExpr *) lexpr;
20282 :
20283 3624 : if (blexpr->boolop == OR_EXPR)
20284 : {
20285 2659 : blexpr->args = lappend(blexpr->args, rexpr);
20286 2659 : return (Node *) blexpr;
20287 : }
20288 : }
20289 11832 : return (Node *) makeBoolExpr(OR_EXPR, list_make2(lexpr, rexpr), location);
20290 : }
20291 :
20292 : static Node *
20293 15749 : makeNotExpr(Node *expr, int location)
20294 : {
20295 15749 : return (Node *) makeBoolExpr(NOT_EXPR, list_make1(expr), location);
20296 : }
20297 :
20298 : static Node *
20299 5333 : makeAArrayExpr(List *elements, int location, int location_end)
20300 : {
20301 5333 : A_ArrayExpr *n = makeNode(A_ArrayExpr);
20302 :
20303 5333 : n->elements = elements;
20304 5333 : n->location = location;
20305 5333 : n->list_start = location;
20306 5333 : n->list_end = location_end;
20307 5333 : return (Node *) n;
20308 : }
20309 :
20310 : static Node *
20311 1638 : makeSQLValueFunction(SQLValueFunctionOp op, int32 typmod, int location)
20312 : {
20313 1638 : SQLValueFunction *svf = makeNode(SQLValueFunction);
20314 :
20315 1638 : svf->op = op;
20316 : /* svf->type will be filled during parse analysis */
20317 1638 : svf->typmod = typmod;
20318 1638 : svf->location = location;
20319 1638 : return (Node *) svf;
20320 : }
20321 :
20322 : static Node *
20323 395 : makeXmlExpr(XmlExprOp op, char *name, List *named_args, List *args,
20324 : int location)
20325 : {
20326 395 : XmlExpr *x = makeNode(XmlExpr);
20327 :
20328 395 : x->op = op;
20329 395 : x->name = name;
20330 :
20331 : /*
20332 : * named_args is a list of ResTarget; it'll be split apart into separate
20333 : * expression and name lists in transformXmlExpr().
20334 : */
20335 395 : x->named_args = named_args;
20336 395 : x->arg_names = NIL;
20337 395 : x->args = args;
20338 : /* xmloption, if relevant, must be filled in by caller */
20339 : /* type and typmod will be filled in during parse analysis */
20340 395 : x->type = InvalidOid; /* marks the node as not analyzed */
20341 395 : x->location = location;
20342 395 : return (Node *) x;
20343 : }
20344 :
20345 : /*
20346 : * Merge the input and output parameters of a table function.
20347 : */
20348 : static List *
20349 142 : mergeTableFuncParameters(List *func_args, List *columns, core_yyscan_t yyscanner)
20350 : {
20351 : ListCell *lc;
20352 :
20353 : /* Explicit OUT and INOUT parameters shouldn't be used in this syntax */
20354 301 : foreach(lc, func_args)
20355 : {
20356 159 : FunctionParameter *p = (FunctionParameter *) lfirst(lc);
20357 :
20358 159 : if (p->mode != FUNC_PARAM_DEFAULT &&
20359 0 : p->mode != FUNC_PARAM_IN &&
20360 0 : p->mode != FUNC_PARAM_VARIADIC)
20361 0 : ereport(ERROR,
20362 : (errcode(ERRCODE_SYNTAX_ERROR),
20363 : errmsg("OUT and INOUT arguments aren't allowed in TABLE functions"),
20364 : parser_errposition(p->location)));
20365 : }
20366 :
20367 142 : return list_concat(func_args, columns);
20368 : }
20369 :
20370 : /*
20371 : * Determine return type of a TABLE function. A single result column
20372 : * returns setof that column's type; otherwise return setof record.
20373 : */
20374 : static TypeName *
20375 142 : TableFuncTypeName(List *columns)
20376 : {
20377 : TypeName *result;
20378 :
20379 142 : if (list_length(columns) == 1)
20380 : {
20381 40 : FunctionParameter *p = (FunctionParameter *) linitial(columns);
20382 :
20383 40 : result = copyObject(p->argType);
20384 : }
20385 : else
20386 102 : result = SystemTypeName("record");
20387 :
20388 142 : result->setof = true;
20389 :
20390 142 : return result;
20391 : }
20392 :
20393 : /*
20394 : * Convert a list of (dotted) names to a RangeVar (like
20395 : * makeRangeVarFromNameList, but with position support). The
20396 : * "AnyName" refers to the any_name production in the grammar.
20397 : */
20398 : static RangeVar *
20399 2511 : makeRangeVarFromAnyName(List *names, int position, core_yyscan_t yyscanner)
20400 : {
20401 2511 : RangeVar *r = makeNode(RangeVar);
20402 :
20403 2511 : switch (list_length(names))
20404 : {
20405 2461 : case 1:
20406 2461 : r->catalogname = NULL;
20407 2461 : r->schemaname = NULL;
20408 2461 : r->relname = strVal(linitial(names));
20409 2461 : break;
20410 50 : case 2:
20411 50 : r->catalogname = NULL;
20412 50 : r->schemaname = strVal(linitial(names));
20413 50 : r->relname = strVal(lsecond(names));
20414 50 : break;
20415 0 : case 3:
20416 0 : r->catalogname = strVal(linitial(names));
20417 0 : r->schemaname = strVal(lsecond(names));
20418 0 : r->relname = strVal(lthird(names));
20419 0 : break;
20420 0 : default:
20421 0 : ereport(ERROR,
20422 : (errcode(ERRCODE_SYNTAX_ERROR),
20423 : errmsg("improper qualified name (too many dotted names): %s",
20424 : NameListToString(names)),
20425 : parser_errposition(position)));
20426 : break;
20427 : }
20428 :
20429 2511 : r->relpersistence = RELPERSISTENCE_PERMANENT;
20430 2511 : r->location = position;
20431 :
20432 2511 : return r;
20433 : }
20434 :
20435 : /*
20436 : * Convert a relation_name with name and namelist to a RangeVar using
20437 : * makeRangeVar.
20438 : */
20439 : static RangeVar *
20440 160441 : makeRangeVarFromQualifiedName(char *name, List *namelist, int location,
20441 : core_yyscan_t yyscanner)
20442 : {
20443 : RangeVar *r;
20444 :
20445 160441 : check_qualified_name(namelist, yyscanner);
20446 160441 : r = makeRangeVar(NULL, NULL, location);
20447 :
20448 160441 : switch (list_length(namelist))
20449 : {
20450 160441 : case 1:
20451 160441 : r->catalogname = NULL;
20452 160441 : r->schemaname = name;
20453 160441 : r->relname = strVal(linitial(namelist));
20454 160441 : break;
20455 0 : case 2:
20456 0 : r->catalogname = name;
20457 0 : r->schemaname = strVal(linitial(namelist));
20458 0 : r->relname = strVal(lsecond(namelist));
20459 0 : break;
20460 0 : default:
20461 0 : ereport(ERROR,
20462 : errcode(ERRCODE_SYNTAX_ERROR),
20463 : errmsg("improper qualified name (too many dotted names): %s",
20464 : NameListToString(lcons(makeString(name), namelist))),
20465 : parser_errposition(location));
20466 : break;
20467 : }
20468 :
20469 160441 : return r;
20470 : }
20471 :
20472 : /* Separate Constraint nodes from COLLATE clauses in a ColQualList */
20473 : static void
20474 44875 : SplitColQualList(List *qualList,
20475 : List **constraintList, CollateClause **collClause,
20476 : core_yyscan_t yyscanner)
20477 : {
20478 : ListCell *cell;
20479 :
20480 44875 : *collClause = NULL;
20481 57453 : foreach(cell, qualList)
20482 : {
20483 12578 : Node *n = (Node *) lfirst(cell);
20484 :
20485 12578 : if (IsA(n, Constraint))
20486 : {
20487 : /* keep it in list */
20488 12092 : continue;
20489 : }
20490 486 : if (IsA(n, CollateClause))
20491 : {
20492 486 : CollateClause *c = (CollateClause *) n;
20493 :
20494 486 : if (*collClause)
20495 0 : ereport(ERROR,
20496 : (errcode(ERRCODE_SYNTAX_ERROR),
20497 : errmsg("multiple COLLATE clauses not allowed"),
20498 : parser_errposition(c->location)));
20499 486 : *collClause = c;
20500 : }
20501 : else
20502 0 : elog(ERROR, "unexpected node type %d", (int) n->type);
20503 : /* remove non-Constraint nodes from qualList */
20504 486 : qualList = foreach_delete_current(qualList, cell);
20505 : }
20506 44875 : *constraintList = qualList;
20507 44875 : }
20508 :
20509 : /*
20510 : * Process result of ConstraintAttributeSpec, and set appropriate bool flags
20511 : * in the output command node. Pass NULL for any flags the particular
20512 : * command doesn't support.
20513 : */
20514 : static void
20515 10798 : processCASbits(int cas_bits, int location, const char *constrType,
20516 : bool *deferrable, bool *initdeferred, bool *is_enforced,
20517 : bool *not_valid, bool *no_inherit, core_yyscan_t yyscanner)
20518 : {
20519 : /* defaults */
20520 10798 : if (deferrable)
20521 9336 : *deferrable = false;
20522 10798 : if (initdeferred)
20523 9336 : *initdeferred = false;
20524 10798 : if (not_valid)
20525 2617 : *not_valid = false;
20526 10798 : if (is_enforced)
20527 2377 : *is_enforced = true;
20528 :
20529 10798 : if (cas_bits & (CAS_DEFERRABLE | CAS_INITIALLY_DEFERRED))
20530 : {
20531 151 : if (deferrable)
20532 151 : *deferrable = true;
20533 : else
20534 0 : ereport(ERROR,
20535 : (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
20536 : /* translator: %s is CHECK, UNIQUE, or similar */
20537 : errmsg("%s constraints cannot be marked DEFERRABLE",
20538 : constrType),
20539 : parser_errposition(location)));
20540 : }
20541 :
20542 10798 : if (cas_bits & CAS_INITIALLY_DEFERRED)
20543 : {
20544 96 : if (initdeferred)
20545 96 : *initdeferred = true;
20546 : else
20547 0 : ereport(ERROR,
20548 : (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
20549 : /* translator: %s is CHECK, UNIQUE, or similar */
20550 : errmsg("%s constraints cannot be marked DEFERRABLE",
20551 : constrType),
20552 : parser_errposition(location)));
20553 : }
20554 :
20555 10798 : if (cas_bits & CAS_NOT_VALID)
20556 : {
20557 430 : if (not_valid)
20558 430 : *not_valid = true;
20559 : else
20560 0 : ereport(ERROR,
20561 : (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
20562 : /* translator: %s is CHECK, UNIQUE, or similar */
20563 : errmsg("%s constraints cannot be marked NOT VALID",
20564 : constrType),
20565 : parser_errposition(location)));
20566 : }
20567 :
20568 10798 : if (cas_bits & CAS_NO_INHERIT)
20569 : {
20570 163 : if (no_inherit)
20571 163 : *no_inherit = true;
20572 : else
20573 0 : ereport(ERROR,
20574 : (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
20575 : /* translator: %s is CHECK, UNIQUE, or similar */
20576 : errmsg("%s constraints cannot be marked NO INHERIT",
20577 : constrType),
20578 : parser_errposition(location)));
20579 : }
20580 :
20581 10798 : if (cas_bits & CAS_NOT_ENFORCED)
20582 : {
20583 159 : if (is_enforced)
20584 155 : *is_enforced = false;
20585 : else
20586 4 : ereport(ERROR,
20587 : (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
20588 : /* translator: %s is CHECK, UNIQUE, or similar */
20589 : errmsg("%s constraints cannot be marked NOT ENFORCED",
20590 : constrType),
20591 : parser_errposition(location)));
20592 :
20593 : /*
20594 : * NB: The validated status is irrelevant when the constraint is set to
20595 : * NOT ENFORCED, but for consistency, it should be set accordingly.
20596 : * This ensures that if the constraint is later changed to ENFORCED, it
20597 : * will automatically be in the correct NOT VALIDATED state.
20598 : */
20599 155 : if (not_valid)
20600 103 : *not_valid = true;
20601 : }
20602 :
20603 10794 : if (cas_bits & CAS_ENFORCED)
20604 : {
20605 136 : if (is_enforced)
20606 132 : *is_enforced = true;
20607 : else
20608 4 : ereport(ERROR,
20609 : (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
20610 : /* translator: %s is CHECK, UNIQUE, or similar */
20611 : errmsg("%s constraints cannot be marked ENFORCED",
20612 : constrType),
20613 : parser_errposition(location)));
20614 : }
20615 10790 : }
20616 :
20617 : /*
20618 : * Parse a user-supplied partition strategy string into parse node
20619 : * PartitionStrategy representation, or die trying.
20620 : */
20621 : static PartitionStrategy
20622 3570 : parsePartitionStrategy(char *strategy, int location, core_yyscan_t yyscanner)
20623 : {
20624 3570 : if (pg_strcasecmp(strategy, "list") == 0)
20625 1626 : return PARTITION_STRATEGY_LIST;
20626 1944 : else if (pg_strcasecmp(strategy, "range") == 0)
20627 1761 : return PARTITION_STRATEGY_RANGE;
20628 183 : else if (pg_strcasecmp(strategy, "hash") == 0)
20629 179 : return PARTITION_STRATEGY_HASH;
20630 :
20631 4 : ereport(ERROR,
20632 : (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
20633 : errmsg("unrecognized partitioning strategy \"%s\"", strategy),
20634 : parser_errposition(location)));
20635 : return PARTITION_STRATEGY_LIST; /* keep compiler quiet */
20636 :
20637 : }
20638 :
20639 : /*
20640 : * Process all_objects_list to set all_tables and/or all_sequences.
20641 : * Also, checks if the pub_object_type has been specified more than once.
20642 : */
20643 : static void
20644 177 : preprocess_pub_all_objtype_list(List *all_objects_list, List **pubobjects,
20645 : bool *all_tables, bool *all_sequences,
20646 : core_yyscan_t yyscanner)
20647 : {
20648 177 : if (!all_objects_list)
20649 0 : return;
20650 :
20651 177 : *all_tables = false;
20652 177 : *all_sequences = false;
20653 :
20654 540 : foreach_ptr(PublicationAllObjSpec, obj, all_objects_list)
20655 : {
20656 202 : if (obj->pubobjtype == PUBLICATION_ALL_TABLES)
20657 : {
20658 153 : if (*all_tables)
20659 4 : ereport(ERROR,
20660 : errcode(ERRCODE_SYNTAX_ERROR),
20661 : errmsg("invalid publication object list"),
20662 : errdetail("ALL TABLES can be specified only once."),
20663 : parser_errposition(obj->location));
20664 :
20665 149 : *all_tables = true;
20666 149 : *pubobjects = list_concat(*pubobjects, obj->except_tables);
20667 : }
20668 49 : else if (obj->pubobjtype == PUBLICATION_ALL_SEQUENCES)
20669 : {
20670 49 : if (*all_sequences)
20671 4 : ereport(ERROR,
20672 : errcode(ERRCODE_SYNTAX_ERROR),
20673 : errmsg("invalid publication object list"),
20674 : errdetail("ALL SEQUENCES can be specified only once."),
20675 : parser_errposition(obj->location));
20676 :
20677 45 : *all_sequences = true;
20678 : }
20679 : }
20680 : }
20681 :
20682 : /*
20683 : * Process pubobjspec_list to check for errors in any of the objects and
20684 : * convert PUBLICATIONOBJ_CONTINUATION into appropriate PublicationObjSpecType.
20685 : */
20686 : static void
20687 1052 : preprocess_pubobj_list(List *pubobjspec_list, core_yyscan_t yyscanner)
20688 : {
20689 : ListCell *cell;
20690 : PublicationObjSpec *pubobj;
20691 1052 : PublicationObjSpecType prevobjtype = PUBLICATIONOBJ_CONTINUATION;
20692 :
20693 1052 : if (!pubobjspec_list)
20694 0 : return;
20695 :
20696 1052 : pubobj = (PublicationObjSpec *) linitial(pubobjspec_list);
20697 1052 : if (pubobj->pubobjtype == PUBLICATIONOBJ_CONTINUATION)
20698 8 : ereport(ERROR,
20699 : errcode(ERRCODE_SYNTAX_ERROR),
20700 : errmsg("invalid publication object list"),
20701 : errdetail("One of TABLE or TABLES IN SCHEMA must be specified before a standalone table or schema name."),
20702 : parser_errposition(pubobj->location));
20703 :
20704 2233 : foreach(cell, pubobjspec_list)
20705 : {
20706 1205 : pubobj = (PublicationObjSpec *) lfirst(cell);
20707 :
20708 1205 : if (pubobj->pubobjtype == PUBLICATIONOBJ_CONTINUATION)
20709 108 : pubobj->pubobjtype = prevobjtype;
20710 :
20711 1205 : if (pubobj->pubobjtype == PUBLICATIONOBJ_TABLE)
20712 : {
20713 : /* relation name or pubtable must be set for this type of object */
20714 913 : if (!pubobj->name && !pubobj->pubtable)
20715 4 : ereport(ERROR,
20716 : errcode(ERRCODE_SYNTAX_ERROR),
20717 : errmsg("invalid table name"),
20718 : parser_errposition(pubobj->location));
20719 :
20720 909 : if (pubobj->name)
20721 : {
20722 : /* convert it to PublicationTable */
20723 33 : PublicationTable *pubtable = makeNode(PublicationTable);
20724 :
20725 33 : pubtable->relation =
20726 33 : makeRangeVar(NULL, pubobj->name, pubobj->location);
20727 33 : pubobj->pubtable = pubtable;
20728 33 : pubobj->name = NULL;
20729 : }
20730 : }
20731 292 : else if (pubobj->pubobjtype == PUBLICATIONOBJ_TABLES_IN_SCHEMA ||
20732 16 : pubobj->pubobjtype == PUBLICATIONOBJ_TABLES_IN_CUR_SCHEMA)
20733 : {
20734 : /* WHERE clause is not allowed on a schema object */
20735 292 : if (pubobj->pubtable && pubobj->pubtable->whereClause)
20736 4 : ereport(ERROR,
20737 : errcode(ERRCODE_SYNTAX_ERROR),
20738 : errmsg("WHERE clause not allowed for schema"),
20739 : parser_errposition(pubobj->location));
20740 :
20741 : /* Column list is not allowed on a schema object */
20742 288 : if (pubobj->pubtable && pubobj->pubtable->columns)
20743 4 : ereport(ERROR,
20744 : errcode(ERRCODE_SYNTAX_ERROR),
20745 : errmsg("column specification not allowed for schema"),
20746 : parser_errposition(pubobj->location));
20747 :
20748 : /*
20749 : * We can distinguish between the different type of schema objects
20750 : * based on whether name and pubtable is set.
20751 : */
20752 284 : if (pubobj->name)
20753 264 : pubobj->pubobjtype = PUBLICATIONOBJ_TABLES_IN_SCHEMA;
20754 20 : else if (!pubobj->name && !pubobj->pubtable)
20755 16 : pubobj->pubobjtype = PUBLICATIONOBJ_TABLES_IN_CUR_SCHEMA;
20756 : else
20757 4 : ereport(ERROR,
20758 : errcode(ERRCODE_SYNTAX_ERROR),
20759 : errmsg("invalid schema name"),
20760 : parser_errposition(pubobj->location));
20761 : }
20762 :
20763 1189 : prevobjtype = pubobj->pubobjtype;
20764 : }
20765 : }
20766 :
20767 : /*----------
20768 : * Recursive view transformation
20769 : *
20770 : * Convert
20771 : *
20772 : * CREATE RECURSIVE VIEW relname (aliases) AS query
20773 : *
20774 : * to
20775 : *
20776 : * CREATE VIEW relname (aliases) AS
20777 : * WITH RECURSIVE relname (aliases) AS (query)
20778 : * SELECT aliases FROM relname
20779 : *
20780 : * Actually, just the WITH ... part, which is then inserted into the original
20781 : * view definition as the query.
20782 : * ----------
20783 : */
20784 : static Node *
20785 9 : makeRecursiveViewSelect(char *relname, List *aliases, Node *query)
20786 : {
20787 9 : SelectStmt *s = makeNode(SelectStmt);
20788 9 : WithClause *w = makeNode(WithClause);
20789 9 : CommonTableExpr *cte = makeNode(CommonTableExpr);
20790 9 : List *tl = NIL;
20791 : ListCell *lc;
20792 :
20793 : /* create common table expression */
20794 9 : cte->ctename = relname;
20795 9 : cte->aliascolnames = aliases;
20796 9 : cte->ctematerialized = CTEMaterializeDefault;
20797 9 : cte->ctequery = query;
20798 9 : cte->location = -1;
20799 :
20800 : /* create WITH clause and attach CTE */
20801 9 : w->recursive = true;
20802 9 : w->ctes = list_make1(cte);
20803 9 : w->location = -1;
20804 :
20805 : /*
20806 : * create target list for the new SELECT from the alias list of the
20807 : * recursive view specification
20808 : */
20809 18 : foreach(lc, aliases)
20810 : {
20811 9 : ResTarget *rt = makeNode(ResTarget);
20812 :
20813 9 : rt->name = NULL;
20814 9 : rt->indirection = NIL;
20815 9 : rt->val = makeColumnRef(strVal(lfirst(lc)), NIL, -1, 0);
20816 9 : rt->location = -1;
20817 :
20818 9 : tl = lappend(tl, rt);
20819 : }
20820 :
20821 : /*
20822 : * create new SELECT combining WITH clause, target list, and fake FROM
20823 : * clause
20824 : */
20825 9 : s->withClause = w;
20826 9 : s->targetList = tl;
20827 9 : s->fromClause = list_make1(makeRangeVar(NULL, relname, -1));
20828 :
20829 9 : return (Node *) s;
20830 : }
20831 :
20832 : /* parser_init()
20833 : * Initialize to parse one query string
20834 : */
20835 : void
20836 488734 : parser_init(base_yy_extra_type *yyext)
20837 : {
20838 488734 : yyext->parsetree = NIL; /* in case grammar forgets to set it */
20839 488734 : }
|