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 <alias> for_portion_of_opt_alias
563 : %type <node> for_portion_of_clause
564 : %type <node> tablesample_clause opt_repeatable_clause
565 : %type <target> target_el set_target insert_column_item
566 :
567 : %type <str> generic_option_name
568 : %type <node> generic_option_arg
569 : %type <defelt> generic_option_elem alter_generic_option_elem
570 : %type <list> generic_option_list alter_generic_option_list
571 :
572 : %type <ival> reindex_target_relation reindex_target_all
573 :
574 : %type <node> copy_generic_opt_arg copy_generic_opt_arg_list_item
575 : %type <defelt> copy_generic_opt_elem
576 : %type <list> copy_generic_opt_list copy_generic_opt_arg_list
577 : %type <list> copy_options
578 :
579 : %type <typnam> Typename SimpleTypename ConstTypename
580 : GenericType Numeric opt_float JsonType
581 : Character ConstCharacter
582 : CharacterWithLength CharacterWithoutLength
583 : ConstDatetime ConstInterval
584 : Bit ConstBit BitWithLength BitWithoutLength
585 : %type <str> character
586 : %type <str> extract_arg
587 : %type <boolean> opt_varying opt_timezone opt_no_inherit
588 :
589 : %type <ival> Iconst SignedIconst
590 : %type <str> Sconst comment_text notify_payload
591 : %type <str> RoleId opt_boolean_or_string
592 : %type <list> var_list
593 : %type <str> ColId ColLabel BareColLabel
594 : %type <str> NonReservedWord NonReservedWord_or_Sconst
595 : %type <str> var_name type_function_name param_name
596 : %type <str> createdb_opt_name plassign_target
597 : %type <node> var_value zone_value
598 : %type <rolespec> auth_ident RoleSpec opt_granted_by
599 : %type <publicationobjectspec> PublicationObjSpec
600 : %type <publicationobjectspec> PublicationExceptObjSpec
601 : %type <publicationallobjectspec> PublicationAllObjSpec
602 :
603 : %type <keyword> unreserved_keyword type_func_name_keyword
604 : %type <keyword> col_name_keyword reserved_keyword
605 : %type <keyword> bare_label_keyword
606 :
607 : %type <node> DomainConstraint TableConstraint TableLikeClause
608 : %type <ival> TableLikeOptionList TableLikeOption
609 : %type <str> column_compression opt_column_compression column_storage opt_column_storage
610 : %type <list> ColQualList
611 : %type <node> ColConstraint ColConstraintElem ConstraintAttr
612 : %type <ival> key_match
613 : %type <keyaction> key_delete key_update key_action
614 : %type <keyactions> key_actions
615 : %type <ival> ConstraintAttributeSpec ConstraintAttributeElem
616 : %type <str> ExistingIndex
617 :
618 : %type <list> constraints_set_list
619 : %type <boolean> constraints_set_mode
620 : %type <str> OptTableSpace OptConsTableSpace
621 : %type <rolespec> OptTableSpaceOwner
622 : %type <ival> opt_check_option
623 :
624 : %type <str> opt_provider security_label
625 :
626 : %type <target> labeled_expr
627 : %type <list> labeled_expr_list xml_attributes
628 : %type <node> xml_root_version opt_xml_root_standalone
629 : %type <node> xmlexists_argument
630 : %type <ival> document_or_content
631 : %type <boolean> xml_indent_option xml_whitespace_option
632 : %type <list> xmltable_column_list xmltable_column_option_list
633 : %type <node> xmltable_column_el
634 : %type <defelt> xmltable_column_option_el
635 : %type <list> xml_namespace_list
636 : %type <target> xml_namespace_el
637 :
638 : %type <node> func_application func_expr_common_subexpr
639 : %type <node> func_expr func_expr_windowless
640 : %type <node> common_table_expr
641 : %type <with> with_clause opt_with_clause
642 : %type <list> cte_list
643 :
644 : %type <list> within_group_clause
645 : %type <node> filter_clause
646 : %type <list> window_clause window_definition_list opt_partition_clause
647 : %type <windef> window_definition over_clause window_specification
648 : opt_frame_clause frame_extent frame_bound
649 : %type <ival> null_treatment opt_window_exclusion_clause
650 : %type <str> opt_existing_window_name
651 : %type <boolean> opt_if_not_exists
652 : %type <boolean> opt_unique_null_treatment
653 : %type <ival> generated_when override_kind opt_virtual_or_stored
654 : %type <partspec> PartitionSpec OptPartitionSpec
655 : %type <partelem> part_elem
656 : %type <list> part_params
657 : %type <partboundspec> PartitionBoundSpec
658 : %type <singlepartspec> SinglePartitionSpec
659 : %type <list> partitions_list
660 : %type <list> hash_partbound
661 : %type <defelt> hash_partbound_elem
662 :
663 : %type <node> json_format_clause
664 : json_format_clause_opt
665 : json_value_expr
666 : json_returning_clause_opt
667 : json_name_and_value
668 : json_aggregate_func
669 : json_argument
670 : json_behavior
671 : json_on_error_clause_opt
672 : json_table
673 : json_table_column_definition
674 : json_table_column_path_clause_opt
675 : %type <list> json_name_and_value_list
676 : json_value_expr_list
677 : json_array_aggregate_order_by_clause_opt
678 : json_arguments
679 : json_behavior_clause_opt
680 : json_passing_clause_opt
681 : json_table_column_definition_list
682 : %type <str> json_table_path_name_opt
683 : %type <ival> json_behavior_type
684 : json_predicate_type_constraint
685 : json_quotes_clause_opt
686 : json_wrapper_behavior
687 : %type <boolean> json_key_uniqueness_constraint_opt
688 : json_object_constructor_null_clause_opt
689 : json_array_constructor_null_clause_opt
690 :
691 : %type <list> vertex_tables_clause edge_tables_clause
692 : opt_vertex_tables_clause opt_edge_tables_clause
693 : vertex_table_list
694 : opt_graph_table_key_clause
695 : edge_table_list
696 : source_vertex_table destination_vertex_table
697 : opt_element_table_label_and_properties
698 : label_and_properties_list
699 : add_label_list
700 : %type <node> vertex_table_definition edge_table_definition
701 : %type <alias> opt_propgraph_table_alias
702 : %type <str> element_table_label_clause
703 : %type <node> label_and_properties element_table_properties
704 : add_label
705 : %type <ival> vertex_or_edge
706 :
707 : %type <list> opt_graph_pattern_quantifier
708 : path_pattern_list
709 : path_pattern
710 : path_pattern_expression
711 : path_term
712 : %type <node> graph_pattern
713 : path_factor
714 : path_primary
715 : opt_is_label_expression
716 : label_expression
717 : label_disjunction
718 : label_term
719 : %type <str> opt_colid
720 :
721 : /*
722 : * Non-keyword token types. These are hard-wired into the "flex" lexer.
723 : * They must be listed first so that their numeric codes do not depend on
724 : * the set of keywords. PL/pgSQL depends on this so that it can share the
725 : * same lexer. If you add/change tokens here, fix PL/pgSQL to match!
726 : *
727 : * UIDENT and USCONST are reduced to IDENT and SCONST in parser.c, so that
728 : * they need no productions here; but we must assign token codes to them.
729 : *
730 : * DOT_DOT is unused in the core SQL grammar, and so will always provoke
731 : * parse errors. It is needed by PL/pgSQL.
732 : */
733 : %token <str> IDENT UIDENT FCONST SCONST USCONST BCONST XCONST Op
734 : %token <ival> ICONST PARAM
735 : %token TYPECAST DOT_DOT COLON_EQUALS EQUALS_GREATER
736 : %token LESS_EQUALS GREATER_EQUALS NOT_EQUALS
737 :
738 : /*
739 : * If you want to make any keyword changes, update the keyword table in
740 : * src/include/parser/kwlist.h and add new keywords to the appropriate one
741 : * of the reserved-or-not-so-reserved keyword lists, below; search
742 : * this file for "Keyword category lists".
743 : */
744 :
745 : /* ordinary key words in alphabetical order */
746 : %token <keyword> ABORT_P ABSENT ABSOLUTE_P ACCESS ACTION ADD_P ADMIN AFTER
747 : AGGREGATE ALL ALSO ALTER ALWAYS ANALYSE ANALYZE AND ANY ARRAY AS ASC
748 : ASENSITIVE ASSERTION ASSIGNMENT ASYMMETRIC ATOMIC AT ATTACH ATTRIBUTE AUTHORIZATION
749 :
750 : BACKWARD BEFORE BEGIN_P BETWEEN BIGINT BINARY BIT
751 : BOOLEAN_P BOTH BREADTH BY
752 :
753 : CACHE CALL CALLED CASCADE CASCADED CASE CAST CATALOG_P CHAIN CHAR_P
754 : CHARACTER CHARACTERISTICS CHECK CHECKPOINT CLASS CLOSE
755 : CLUSTER COALESCE COLLATE COLLATION COLUMN COLUMNS COMMENT COMMENTS COMMIT
756 : COMMITTED COMPRESSION CONCURRENTLY CONDITIONAL CONFIGURATION CONFLICT
757 : CONNECTION CONSTRAINT CONSTRAINTS CONTENT_P CONTINUE_P CONVERSION_P COPY
758 : COST CREATE CROSS CSV CUBE CURRENT_P
759 : CURRENT_CATALOG CURRENT_DATE CURRENT_ROLE CURRENT_SCHEMA
760 : CURRENT_TIME CURRENT_TIMESTAMP CURRENT_USER CURSOR CYCLE
761 :
762 : DATA_P DATABASE DAY_P DEALLOCATE DEC DECIMAL_P DECLARE DEFAULT DEFAULTS
763 : DEFERRABLE DEFERRED DEFINER DELETE_P DELIMITER DELIMITERS DEPENDS DEPTH DESC DESTINATION
764 : DETACH DICTIONARY DISABLE_P DISCARD DISTINCT DO DOCUMENT_P DOMAIN_P
765 : DOUBLE_P DROP
766 :
767 : EACH EDGE ELSE EMPTY_P ENABLE_P ENCODING ENCRYPTED END_P ENFORCED ENUM_P
768 : ERROR_P ESCAPE EVENT EXCEPT EXCLUDE EXCLUDING EXCLUSIVE EXECUTE EXISTS
769 : EXPLAIN EXPRESSION EXTENSION EXTERNAL EXTRACT
770 :
771 : FALSE_P FAMILY FETCH FILTER FINALIZE FIRST_P FLOAT_P FOLLOWING FOR
772 : FORCE FOREIGN FORMAT FORWARD FREEZE FROM FULL FUNCTION FUNCTIONS
773 :
774 : GENERATED GLOBAL GRANT GRANTED GRAPH GRAPH_TABLE GREATEST GROUP_P GROUPING GROUPS
775 :
776 : HANDLER HAVING HEADER_P HOLD HOUR_P
777 :
778 : IDENTITY_P IF_P IGNORE_P ILIKE IMMEDIATE IMMUTABLE IMPLICIT_P IMPORT_P IN_P INCLUDE
779 : INCLUDING INCREMENT INDENT INDEX INDEXES INHERIT INHERITS INITIALLY INLINE_P
780 : INNER_P INOUT INPUT_P INSENSITIVE INSERT INSTEAD INT_P INTEGER
781 : INTERSECT INTERVAL INTO INVOKER IS ISNULL ISOLATION
782 :
783 : JOIN JSON JSON_ARRAY JSON_ARRAYAGG JSON_EXISTS JSON_OBJECT JSON_OBJECTAGG
784 : JSON_QUERY JSON_SCALAR JSON_SERIALIZE JSON_TABLE JSON_VALUE
785 :
786 : KEEP KEY KEYS
787 :
788 : LABEL LANGUAGE LARGE_P LAST_P LATERAL_P
789 : LEADING LEAKPROOF LEAST LEFT LEVEL LIKE LIMIT LISTEN LOAD LOCAL
790 : LOCALTIME LOCALTIMESTAMP LOCATION LOCK_P LOCKED LOGGED LSN_P
791 :
792 : MAPPING MATCH MATCHED MATERIALIZED MAXVALUE MERGE MERGE_ACTION METHOD
793 : MINUTE_P MINVALUE MODE MONTH_P MOVE
794 :
795 : NAME_P NAMES NATIONAL NATURAL NCHAR NESTED NEW NEXT NFC NFD NFKC NFKD NO NODE
796 : NONE NORMALIZE NORMALIZED
797 : NOT NOTHING NOTIFY NOTNULL NOWAIT NULL_P NULLIF
798 : NULLS_P NUMERIC
799 :
800 : OBJECT_P OBJECTS_P OF OFF OFFSET OIDS OLD OMIT ON ONLY OPERATOR OPTION OPTIONS OR
801 : ORDER ORDINALITY OTHERS OUT_P OUTER_P
802 : OVER OVERLAPS OVERLAY OVERRIDING OWNED OWNER
803 :
804 : PARALLEL PARAMETER PARSER PARTIAL PARTITION PARTITIONS PASSING PASSWORD PATH
805 : PERIOD PLACING PLAN PLANS POLICY PORTION
806 : POSITION PRECEDING PRECISION PRESERVE PREPARE PREPARED PRIMARY
807 : PRIOR PRIVILEGES PROCEDURAL PROCEDURE PROCEDURES PROGRAM PROPERTIES PROPERTY PUBLICATION
808 :
809 : QUOTE QUOTES
810 :
811 : RANGE READ REAL REASSIGN RECURSIVE REF_P REFERENCES REFERENCING
812 : REFRESH REINDEX RELATIONSHIP RELATIVE_P RELEASE RENAME REPACK REPEATABLE REPLACE REPLICA
813 : RESET RESPECT_P RESTART RESTRICT RETURN RETURNING RETURNS REVOKE RIGHT ROLE ROLLBACK ROLLUP
814 : ROUTINE ROUTINES ROW ROWS RULE
815 :
816 : SAVEPOINT SCALAR SCHEMA SCHEMAS SCROLL SEARCH SECOND_P SECURITY SELECT
817 : SEQUENCE SEQUENCES
818 : SERIALIZABLE SERVER SESSION SESSION_USER SET SETS SETOF SHARE SHOW
819 : SIMILAR SIMPLE SKIP SMALLINT SNAPSHOT SOME SPLIT SOURCE SQL_P STABLE STANDALONE_P
820 : START STATEMENT STATISTICS STDIN STDOUT STORAGE STORED STRICT_P STRING_P STRIP_P
821 : SUBSCRIPTION SUBSTRING SUPPORT SYMMETRIC SYSID SYSTEM_P SYSTEM_USER
822 :
823 : TABLE TABLES TABLESAMPLE TABLESPACE TARGET TEMP TEMPLATE TEMPORARY TEXT_P THEN
824 : TIES TIME TIMESTAMP TO TRAILING TRANSACTION TRANSFORM
825 : TREAT TRIGGER TRIM TRUE_P
826 : TRUNCATE TRUSTED TYPE_P TYPES_P
827 :
828 : UESCAPE UNBOUNDED UNCONDITIONAL UNCOMMITTED UNENCRYPTED UNION UNIQUE UNKNOWN
829 : UNLISTEN UNLOGGED UNTIL UPDATE USER USING
830 :
831 : VACUUM VALID VALIDATE VALIDATOR VALUE_P VALUES VARCHAR VARIADIC VARYING
832 : VERBOSE VERSION_P VERTEX VIEW VIEWS VIRTUAL VOLATILE
833 :
834 : WAIT WHEN WHERE WHITESPACE_P WINDOW WITH WITHIN WITHOUT WORK WRAPPER WRITE
835 :
836 : XML_P XMLATTRIBUTES XMLCONCAT XMLELEMENT XMLEXISTS XMLFOREST XMLNAMESPACES
837 : XMLPARSE XMLPI XMLROOT XMLSERIALIZE XMLTABLE
838 :
839 : YEAR_P YES_P
840 :
841 : ZONE
842 :
843 : /*
844 : * The grammar thinks these are keywords, but they are not in the kwlist.h
845 : * list and so can never be entered directly. The filter in parser.c
846 : * creates these tokens when required (based on looking one token ahead).
847 : *
848 : * NOT_LA exists so that productions such as NOT LIKE can be given the same
849 : * precedence as LIKE; otherwise they'd effectively have the same precedence
850 : * as NOT, at least with respect to their left-hand subexpression.
851 : * FORMAT_LA, NULLS_LA, WITH_LA, and WITHOUT_LA are needed to make the grammar
852 : * LALR(1).
853 : */
854 : %token FORMAT_LA NOT_LA NULLS_LA WITH_LA WITHOUT_LA
855 :
856 : /*
857 : * The grammar likewise thinks these tokens are keywords, but they are never
858 : * generated by the scanner. Rather, they can be injected by parser.c as
859 : * the initial token of the string (using the lookahead-token mechanism
860 : * implemented there). This provides a way to tell the grammar to parse
861 : * something other than the usual list of SQL commands.
862 : */
863 : %token MODE_TYPE_NAME
864 : %token MODE_PLPGSQL_EXPR
865 : %token MODE_PLPGSQL_ASSIGN1
866 : %token MODE_PLPGSQL_ASSIGN2
867 : %token MODE_PLPGSQL_ASSIGN3
868 :
869 :
870 : /* Precedence: lowest to highest */
871 : %left UNION EXCEPT
872 : %left INTERSECT
873 : %left OR
874 : %left AND
875 : %right NOT
876 : %nonassoc IS ISNULL NOTNULL /* IS sets precedence for IS NULL, etc */
877 : %nonassoc '<' '>' '=' LESS_EQUALS GREATER_EQUALS NOT_EQUALS
878 : %nonassoc BETWEEN IN_P LIKE ILIKE SIMILAR NOT_LA
879 : %nonassoc ESCAPE /* ESCAPE must be just above LIKE/ILIKE/SIMILAR */
880 :
881 : /*
882 : * Sometimes it is necessary to assign precedence to keywords that are not
883 : * really part of the operator hierarchy, in order to resolve grammar
884 : * ambiguities. It's best to avoid doing so whenever possible, because such
885 : * assignments have global effect and may hide ambiguities besides the one
886 : * you intended to solve. (Attaching a precedence to a single rule with
887 : * %prec is far safer and should be preferred.) If you must give precedence
888 : * to a new keyword, try very hard to give it the same precedence as IDENT.
889 : * If the keyword has IDENT's precedence then it clearly acts the same as
890 : * non-keywords and other similar keywords, thus reducing the risk of
891 : * unexpected precedence effects.
892 : *
893 : * We used to need to assign IDENT an explicit precedence just less than Op,
894 : * to support target_el without AS. While that's not really necessary since
895 : * we removed postfix operators, we continue to do so because it provides a
896 : * reference point for a precedence level that we can assign to other
897 : * keywords that lack a natural precedence level.
898 : *
899 : * We need to do this for PARTITION, RANGE, ROWS, and GROUPS to support
900 : * opt_existing_window_name (see comment there).
901 : *
902 : * The frame_bound productions UNBOUNDED PRECEDING and UNBOUNDED FOLLOWING
903 : * are even messier: since UNBOUNDED is an unreserved keyword (per spec!),
904 : * there is no principled way to distinguish these from the productions
905 : * a_expr PRECEDING/FOLLOWING. We hack this up by giving UNBOUNDED slightly
906 : * lower precedence than PRECEDING and FOLLOWING. At present this doesn't
907 : * appear to cause UNBOUNDED to be treated differently from other unreserved
908 : * keywords anywhere else in the grammar, but it's definitely risky. We can
909 : * blame any funny behavior of UNBOUNDED on the SQL standard, though.
910 : *
911 : * To support CUBE and ROLLUP in GROUP BY without reserving them, we give them
912 : * an explicit priority lower than '(', so that a rule with CUBE '(' will shift
913 : * rather than reducing a conflicting rule that takes CUBE as a function name.
914 : * Using the same precedence as IDENT seems right for the reasons given above.
915 : *
916 : * SET is likewise assigned the same precedence as IDENT, to support the
917 : * relation_expr_opt_alias production (see comment there).
918 : *
919 : * KEYS, OBJECT_P, SCALAR, VALUE_P, WITH, and WITHOUT are similarly assigned
920 : * the same precedence as IDENT. This allows resolving conflicts in the
921 : * json_predicate_type_constraint and json_key_uniqueness_constraint_opt
922 : * productions (see comments there).
923 : *
924 : * TO is assigned the same precedence as IDENT, to support the opt_interval
925 : * production (see comment there).
926 : *
927 : * Like the UNBOUNDED PRECEDING/FOLLOWING case, NESTED is assigned a lower
928 : * precedence than PATH to fix ambiguity in the json_table production.
929 : */
930 : %nonassoc UNBOUNDED NESTED /* ideally would have same precedence as IDENT */
931 : %nonassoc IDENT PARTITION RANGE ROWS GROUPS PRECEDING FOLLOWING CUBE ROLLUP
932 : SET KEYS OBJECT_P SCALAR TO USING VALUE_P WITH WITHOUT PATH
933 : %left Op OPERATOR RIGHT_ARROW '|' /* multi-character ops and user-defined operators */
934 : %left '+' '-'
935 : %left '*' '/' '%'
936 : %left '^'
937 : /* Unary Operators */
938 : %left AT /* sets precedence for AT TIME ZONE, AT LOCAL */
939 : %left COLLATE
940 : %right UMINUS
941 : %left '[' ']'
942 : %left '(' ')'
943 : %left TYPECAST
944 : %left '.'
945 : /*
946 : * These might seem to be low-precedence, but actually they are not part
947 : * of the arithmetic hierarchy at all in their use as JOIN operators.
948 : * We make them high-precedence to support their use as function names.
949 : * They wouldn't be given a precedence at all, were it not that we need
950 : * left-associativity among the JOIN rules themselves.
951 : */
952 : %left JOIN CROSS LEFT FULL RIGHT INNER_P NATURAL
953 :
954 : %%
955 :
956 : /*
957 : * The target production for the whole parse.
958 : *
959 : * Ordinarily we parse a list of statements, but if we see one of the
960 : * special MODE_XXX symbols as first token, we parse something else.
961 : * The options here correspond to enum RawParseMode, which see for details.
962 : */
963 : parse_toplevel:
964 : stmtmulti
965 : {
966 464791 : pg_yyget_extra(yyscanner)->parsetree = $1;
967 : (void) yynerrs; /* suppress compiler warning */
968 : }
969 : | MODE_TYPE_NAME Typename
970 : {
971 6395 : pg_yyget_extra(yyscanner)->parsetree = list_make1($2);
972 : }
973 : | MODE_PLPGSQL_EXPR PLpgSQL_Expr
974 : {
975 21419 : pg_yyget_extra(yyscanner)->parsetree =
976 21419 : list_make1(makeRawStmt($2, @2));
977 : }
978 : | MODE_PLPGSQL_ASSIGN1 PLAssignStmt
979 : {
980 3801 : PLAssignStmt *n = (PLAssignStmt *) $2;
981 :
982 3801 : n->nnames = 1;
983 3801 : pg_yyget_extra(yyscanner)->parsetree =
984 3801 : list_make1(makeRawStmt((Node *) n, @2));
985 : }
986 : | MODE_PLPGSQL_ASSIGN2 PLAssignStmt
987 : {
988 423 : PLAssignStmt *n = (PLAssignStmt *) $2;
989 :
990 423 : n->nnames = 2;
991 423 : pg_yyget_extra(yyscanner)->parsetree =
992 423 : list_make1(makeRawStmt((Node *) n, @2));
993 : }
994 : | MODE_PLPGSQL_ASSIGN3 PLAssignStmt
995 : {
996 14 : PLAssignStmt *n = (PLAssignStmt *) $2;
997 :
998 14 : n->nnames = 3;
999 14 : pg_yyget_extra(yyscanner)->parsetree =
1000 14 : list_make1(makeRawStmt((Node *) n, @2));
1001 : }
1002 : ;
1003 :
1004 : /*
1005 : * At top level, we wrap each stmt with a RawStmt node carrying start location
1006 : * and length of the stmt's text.
1007 : * We also take care to discard empty statements entirely (which among other
1008 : * things dodges the problem of assigning them a location).
1009 : */
1010 : stmtmulti: stmtmulti ';' toplevel_stmt
1011 : {
1012 384500 : if ($1 != NIL)
1013 : {
1014 : /* update length of previous stmt */
1015 383870 : updateRawStmtEnd(llast_node(RawStmt, $1), @2);
1016 : }
1017 384500 : if ($3 != NULL)
1018 30590 : $$ = lappend($1, makeRawStmt($3, @3));
1019 : else
1020 353910 : $$ = $1;
1021 : }
1022 : | toplevel_stmt
1023 : {
1024 464796 : if ($1 != NULL)
1025 463743 : $$ = list_make1(makeRawStmt($1, @1));
1026 : else
1027 1053 : $$ = NIL;
1028 : }
1029 : ;
1030 :
1031 : /*
1032 : * toplevel_stmt includes BEGIN and END. stmt does not include them, because
1033 : * those words have different meanings in function bodies.
1034 : */
1035 : toplevel_stmt:
1036 : stmt
1037 : | TransactionStmtLegacy
1038 : ;
1039 :
1040 : stmt:
1041 : AlterEventTrigStmt
1042 : | AlterCollationStmt
1043 : | AlterDatabaseStmt
1044 : | AlterDatabaseSetStmt
1045 : | AlterDefaultPrivilegesStmt
1046 : | AlterDomainStmt
1047 : | AlterEnumStmt
1048 : | AlterExtensionStmt
1049 : | AlterExtensionContentsStmt
1050 : | AlterFdwStmt
1051 : | AlterForeignServerStmt
1052 : | AlterFunctionStmt
1053 : | AlterGroupStmt
1054 : | AlterObjectDependsStmt
1055 : | AlterObjectSchemaStmt
1056 : | AlterOwnerStmt
1057 : | AlterOperatorStmt
1058 : | AlterTypeStmt
1059 : | AlterPolicyStmt
1060 : | AlterPropGraphStmt
1061 : | AlterSeqStmt
1062 : | AlterSystemStmt
1063 : | AlterTableStmt
1064 : | AlterTblSpcStmt
1065 : | AlterCompositeTypeStmt
1066 : | AlterPublicationStmt
1067 : | AlterRoleSetStmt
1068 : | AlterRoleStmt
1069 : | AlterSubscriptionStmt
1070 : | AlterStatsStmt
1071 : | AlterTSConfigurationStmt
1072 : | AlterTSDictionaryStmt
1073 : | AlterUserMappingStmt
1074 : | AnalyzeStmt
1075 : | CallStmt
1076 : | CheckPointStmt
1077 : | ClosePortalStmt
1078 : | CommentStmt
1079 : | ConstraintsSetStmt
1080 : | CopyStmt
1081 : | CreateAmStmt
1082 : | CreateAsStmt
1083 : | CreateAssertionStmt
1084 : | CreateCastStmt
1085 : | CreateConversionStmt
1086 : | CreateDomainStmt
1087 : | CreateExtensionStmt
1088 : | CreateFdwStmt
1089 : | CreateForeignServerStmt
1090 : | CreateForeignTableStmt
1091 : | CreateFunctionStmt
1092 : | CreateGroupStmt
1093 : | CreateMatViewStmt
1094 : | CreateOpClassStmt
1095 : | CreateOpFamilyStmt
1096 : | CreatePublicationStmt
1097 : | AlterOpFamilyStmt
1098 : | CreatePolicyStmt
1099 : | CreatePLangStmt
1100 : | CreatePropGraphStmt
1101 : | CreateSchemaStmt
1102 : | CreateSeqStmt
1103 : | CreateStmt
1104 : | CreateSubscriptionStmt
1105 : | CreateStatsStmt
1106 : | CreateTableSpaceStmt
1107 : | CreateTransformStmt
1108 : | CreateTrigStmt
1109 : | CreateEventTrigStmt
1110 : | CreateRoleStmt
1111 : | CreateUserStmt
1112 : | CreateUserMappingStmt
1113 : | CreatedbStmt
1114 : | DeallocateStmt
1115 : | DeclareCursorStmt
1116 : | DefineStmt
1117 : | DeleteStmt
1118 : | DiscardStmt
1119 : | DoStmt
1120 : | DropCastStmt
1121 : | DropOpClassStmt
1122 : | DropOpFamilyStmt
1123 : | DropOwnedStmt
1124 : | DropStmt
1125 : | DropSubscriptionStmt
1126 : | DropTableSpaceStmt
1127 : | DropTransformStmt
1128 : | DropRoleStmt
1129 : | DropUserMappingStmt
1130 : | DropdbStmt
1131 : | ExecuteStmt
1132 : | ExplainStmt
1133 : | FetchStmt
1134 : | GrantStmt
1135 : | GrantRoleStmt
1136 : | ImportForeignSchemaStmt
1137 : | IndexStmt
1138 : | InsertStmt
1139 : | ListenStmt
1140 : | RefreshMatViewStmt
1141 : | LoadStmt
1142 : | LockStmt
1143 : | MergeStmt
1144 : | NotifyStmt
1145 : | PrepareStmt
1146 : | ReassignOwnedStmt
1147 : | ReindexStmt
1148 : | RemoveAggrStmt
1149 : | RemoveFuncStmt
1150 : | RemoveOperStmt
1151 : | RenameStmt
1152 : | RepackStmt
1153 : | RevokeStmt
1154 : | RevokeRoleStmt
1155 : | RuleStmt
1156 : | SecLabelStmt
1157 : | SelectStmt
1158 : | TransactionStmt
1159 : | TruncateStmt
1160 : | UnlistenStmt
1161 : | UpdateStmt
1162 : | VacuumStmt
1163 : | VariableResetStmt
1164 : | VariableSetStmt
1165 : | VariableShowStmt
1166 : | ViewStmt
1167 : | WaitStmt
1168 : | /*EMPTY*/
1169 354975 : { $$ = NULL; }
1170 : ;
1171 :
1172 : /*
1173 : * Generic supporting productions for DDL
1174 : */
1175 : opt_single_name:
1176 3401 : ColId { $$ = $1; }
1177 1168 : | /* EMPTY */ { $$ = NULL; }
1178 : ;
1179 :
1180 : opt_qualified_name:
1181 1368 : any_name { $$ = $1; }
1182 10651 : | /*EMPTY*/ { $$ = NIL; }
1183 : ;
1184 :
1185 : opt_concurrently:
1186 638 : CONCURRENTLY { $$ = true; }
1187 5044 : | /*EMPTY*/ { $$ = false; }
1188 : ;
1189 :
1190 : opt_usingindex:
1191 4 : USING INDEX { $$ = true; }
1192 29 : | /* EMPTY */ { $$ = false; }
1193 : ;
1194 :
1195 : opt_drop_behavior:
1196 1367 : CASCADE { $$ = DROP_CASCADE; }
1197 109 : | RESTRICT { $$ = DROP_RESTRICT; }
1198 21635 : | /* EMPTY */ { $$ = DROP_RESTRICT; /* default */ }
1199 : ;
1200 :
1201 : opt_utility_option_list:
1202 242 : '(' utility_option_list ')' { $$ = $2; }
1203 3545 : | /* EMPTY */ { $$ = NULL; }
1204 : ;
1205 :
1206 : utility_option_list:
1207 : utility_option_elem
1208 : {
1209 15507 : $$ = list_make1($1);
1210 : }
1211 : | utility_option_list ',' utility_option_elem
1212 : {
1213 8993 : $$ = lappend($1, $3);
1214 : }
1215 : ;
1216 :
1217 : utility_option_elem:
1218 : utility_option_name utility_option_arg
1219 : {
1220 24500 : $$ = makeDefElem($1, $2, @1);
1221 : }
1222 : ;
1223 :
1224 : utility_option_name:
1225 21981 : NonReservedWord { $$ = $1; }
1226 2430 : | analyze_keyword { $$ = "analyze"; }
1227 93 : | FORMAT_LA { $$ = "format"; }
1228 : ;
1229 :
1230 : utility_option_arg:
1231 12804 : opt_boolean_or_string { $$ = (Node *) makeString($1); }
1232 220 : | NumericOnly { $$ = (Node *) $1; }
1233 11476 : | /* EMPTY */ { $$ = NULL; }
1234 : ;
1235 :
1236 : /*****************************************************************************
1237 : *
1238 : * CALL statement
1239 : *
1240 : *****************************************************************************/
1241 :
1242 : CallStmt: CALL func_application
1243 : {
1244 359 : CallStmt *n = makeNode(CallStmt);
1245 :
1246 359 : n->funccall = castNode(FuncCall, $2);
1247 359 : $$ = (Node *) n;
1248 : }
1249 : ;
1250 :
1251 : /*****************************************************************************
1252 : *
1253 : * Create a new Postgres DBMS role
1254 : *
1255 : *****************************************************************************/
1256 :
1257 : CreateRoleStmt:
1258 : CREATE ROLE RoleId opt_with OptRoleList
1259 : {
1260 997 : CreateRoleStmt *n = makeNode(CreateRoleStmt);
1261 :
1262 997 : n->stmt_type = ROLESTMT_ROLE;
1263 997 : n->role = $3;
1264 997 : n->options = $5;
1265 997 : $$ = (Node *) n;
1266 : }
1267 : ;
1268 :
1269 :
1270 : opt_with: WITH
1271 : | WITH_LA
1272 : | /*EMPTY*/
1273 : ;
1274 :
1275 : /*
1276 : * Options for CREATE ROLE and ALTER ROLE (also used by CREATE/ALTER USER
1277 : * for backwards compatibility). Note: the only option required by SQL99
1278 : * is "WITH ADMIN name".
1279 : */
1280 : OptRoleList:
1281 797 : OptRoleList CreateOptRoleElem { $$ = lappend($1, $2); }
1282 1336 : | /* EMPTY */ { $$ = NIL; }
1283 : ;
1284 :
1285 : AlterOptRoleList:
1286 446 : AlterOptRoleList AlterOptRoleElem { $$ = lappend($1, $2); }
1287 262 : | /* EMPTY */ { $$ = NIL; }
1288 : ;
1289 :
1290 : AlterOptRoleElem:
1291 : PASSWORD Sconst
1292 : {
1293 118 : $$ = makeDefElem("password",
1294 118 : (Node *) makeString($2), @1);
1295 : }
1296 : | PASSWORD NULL_P
1297 : {
1298 8 : $$ = makeDefElem("password", NULL, @1);
1299 : }
1300 : | ENCRYPTED PASSWORD Sconst
1301 : {
1302 : /*
1303 : * These days, passwords are always stored in encrypted
1304 : * form, so there is no difference between PASSWORD and
1305 : * ENCRYPTED PASSWORD.
1306 : */
1307 10 : $$ = makeDefElem("password",
1308 10 : (Node *) makeString($3), @1);
1309 : }
1310 : | UNENCRYPTED PASSWORD Sconst
1311 : {
1312 0 : ereport(ERROR,
1313 : (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
1314 : errmsg("UNENCRYPTED PASSWORD is no longer supported"),
1315 : errhint("Remove UNENCRYPTED to store the password in encrypted form instead."),
1316 : parser_errposition(@1)));
1317 : }
1318 : | INHERIT
1319 : {
1320 61 : $$ = makeDefElem("inherit", (Node *) makeBoolean(true), @1);
1321 : }
1322 : | CONNECTION LIMIT SignedIconst
1323 : {
1324 21 : $$ = makeDefElem("connectionlimit", (Node *) makeInteger($3), @1);
1325 : }
1326 : | VALID UNTIL Sconst
1327 : {
1328 8 : $$ = makeDefElem("validUntil", (Node *) makeString($3), @1);
1329 : }
1330 : /* Supported but not documented for roles, for use by ALTER GROUP. */
1331 : | USER role_list
1332 : {
1333 4 : $$ = makeDefElem("rolemembers", (Node *) $2, @1);
1334 : }
1335 : | IDENT
1336 : {
1337 : /*
1338 : * We handle identifiers that aren't parser keywords with
1339 : * the following special-case codes, to avoid bloating the
1340 : * size of the main parser.
1341 : */
1342 904 : if (strcmp($1, "superuser") == 0)
1343 118 : $$ = makeDefElem("superuser", (Node *) makeBoolean(true), @1);
1344 786 : else if (strcmp($1, "nosuperuser") == 0)
1345 65 : $$ = makeDefElem("superuser", (Node *) makeBoolean(false), @1);
1346 721 : else if (strcmp($1, "createrole") == 0)
1347 69 : $$ = makeDefElem("createrole", (Node *) makeBoolean(true), @1);
1348 652 : else if (strcmp($1, "nocreaterole") == 0)
1349 29 : $$ = makeDefElem("createrole", (Node *) makeBoolean(false), @1);
1350 623 : else if (strcmp($1, "replication") == 0)
1351 77 : $$ = makeDefElem("isreplication", (Node *) makeBoolean(true), @1);
1352 546 : else if (strcmp($1, "noreplication") == 0)
1353 58 : $$ = makeDefElem("isreplication", (Node *) makeBoolean(false), @1);
1354 488 : else if (strcmp($1, "createdb") == 0)
1355 59 : $$ = makeDefElem("createdb", (Node *) makeBoolean(true), @1);
1356 429 : else if (strcmp($1, "nocreatedb") == 0)
1357 34 : $$ = makeDefElem("createdb", (Node *) makeBoolean(false), @1);
1358 395 : else if (strcmp($1, "login") == 0)
1359 170 : $$ = makeDefElem("canlogin", (Node *) makeBoolean(true), @1);
1360 225 : else if (strcmp($1, "nologin") == 0)
1361 100 : $$ = makeDefElem("canlogin", (Node *) makeBoolean(false), @1);
1362 125 : else if (strcmp($1, "bypassrls") == 0)
1363 57 : $$ = makeDefElem("bypassrls", (Node *) makeBoolean(true), @1);
1364 68 : else if (strcmp($1, "nobypassrls") == 0)
1365 44 : $$ = makeDefElem("bypassrls", (Node *) makeBoolean(false), @1);
1366 24 : else if (strcmp($1, "noinherit") == 0)
1367 : {
1368 : /*
1369 : * Note that INHERIT is a keyword, so it's handled by main parser, but
1370 : * NOINHERIT is handled here.
1371 : */
1372 24 : $$ = makeDefElem("inherit", (Node *) makeBoolean(false), @1);
1373 : }
1374 : else
1375 0 : ereport(ERROR,
1376 : (errcode(ERRCODE_SYNTAX_ERROR),
1377 : errmsg("unrecognized role option \"%s\"", $1),
1378 : parser_errposition(@1)));
1379 : }
1380 : ;
1381 :
1382 : CreateOptRoleElem:
1383 688 : AlterOptRoleElem { $$ = $1; }
1384 : /* The following are not supported by ALTER ROLE/USER/GROUP */
1385 : | SYSID Iconst
1386 : {
1387 4 : $$ = makeDefElem("sysid", (Node *) makeInteger($2), @1);
1388 : }
1389 : | ADMIN role_list
1390 : {
1391 14 : $$ = makeDefElem("adminmembers", (Node *) $2, @1);
1392 : }
1393 : | ROLE role_list
1394 : {
1395 26 : $$ = makeDefElem("rolemembers", (Node *) $2, @1);
1396 : }
1397 : | IN_P ROLE role_list
1398 : {
1399 65 : $$ = makeDefElem("addroleto", (Node *) $3, @1);
1400 : }
1401 : | IN_P GROUP_P role_list
1402 : {
1403 0 : $$ = makeDefElem("addroleto", (Node *) $3, @1);
1404 : }
1405 : ;
1406 :
1407 :
1408 : /*****************************************************************************
1409 : *
1410 : * Create a new Postgres DBMS user (role with implied login ability)
1411 : *
1412 : *****************************************************************************/
1413 :
1414 : CreateUserStmt:
1415 : CREATE USER RoleId opt_with OptRoleList
1416 : {
1417 323 : CreateRoleStmt *n = makeNode(CreateRoleStmt);
1418 :
1419 323 : n->stmt_type = ROLESTMT_USER;
1420 323 : n->role = $3;
1421 323 : n->options = $5;
1422 323 : $$ = (Node *) n;
1423 : }
1424 : ;
1425 :
1426 :
1427 : /*****************************************************************************
1428 : *
1429 : * Alter a postgresql DBMS role
1430 : *
1431 : *****************************************************************************/
1432 :
1433 : AlterRoleStmt:
1434 : ALTER ROLE RoleSpec opt_with AlterOptRoleList
1435 : {
1436 213 : AlterRoleStmt *n = makeNode(AlterRoleStmt);
1437 :
1438 213 : n->role = $3;
1439 213 : n->action = +1; /* add, if there are members */
1440 213 : n->options = $5;
1441 213 : $$ = (Node *) n;
1442 : }
1443 : | ALTER USER RoleSpec opt_with AlterOptRoleList
1444 : {
1445 49 : AlterRoleStmt *n = makeNode(AlterRoleStmt);
1446 :
1447 49 : n->role = $3;
1448 49 : n->action = +1; /* add, if there are members */
1449 49 : n->options = $5;
1450 49 : $$ = (Node *) n;
1451 : }
1452 : ;
1453 :
1454 : opt_in_database:
1455 55 : /* EMPTY */ { $$ = NULL; }
1456 10 : | IN_P DATABASE name { $$ = $3; }
1457 : ;
1458 :
1459 : AlterRoleSetStmt:
1460 : ALTER ROLE RoleSpec opt_in_database SetResetClause
1461 : {
1462 45 : AlterRoleSetStmt *n = makeNode(AlterRoleSetStmt);
1463 :
1464 45 : n->role = $3;
1465 45 : n->database = $4;
1466 45 : n->setstmt = $5;
1467 45 : $$ = (Node *) n;
1468 : }
1469 : | ALTER ROLE ALL opt_in_database SetResetClause
1470 : {
1471 2 : AlterRoleSetStmt *n = makeNode(AlterRoleSetStmt);
1472 :
1473 2 : n->role = NULL;
1474 2 : n->database = $4;
1475 2 : n->setstmt = $5;
1476 2 : $$ = (Node *) n;
1477 : }
1478 : | ALTER USER RoleSpec opt_in_database SetResetClause
1479 : {
1480 14 : AlterRoleSetStmt *n = makeNode(AlterRoleSetStmt);
1481 :
1482 14 : n->role = $3;
1483 14 : n->database = $4;
1484 14 : n->setstmt = $5;
1485 14 : $$ = (Node *) n;
1486 : }
1487 : | ALTER USER ALL opt_in_database SetResetClause
1488 : {
1489 2 : AlterRoleSetStmt *n = makeNode(AlterRoleSetStmt);
1490 :
1491 2 : n->role = NULL;
1492 2 : n->database = $4;
1493 2 : n->setstmt = $5;
1494 2 : $$ = (Node *) n;
1495 : }
1496 : ;
1497 :
1498 :
1499 : /*****************************************************************************
1500 : *
1501 : * Drop a postgresql DBMS role
1502 : *
1503 : * XXX Ideally this would have CASCADE/RESTRICT options, but a role
1504 : * might own objects in multiple databases, and there is presently no way to
1505 : * implement cascading to other databases. So we always behave as RESTRICT.
1506 : *****************************************************************************/
1507 :
1508 : DropRoleStmt:
1509 : DROP ROLE role_list
1510 : {
1511 815 : DropRoleStmt *n = makeNode(DropRoleStmt);
1512 :
1513 815 : n->missing_ok = false;
1514 815 : n->roles = $3;
1515 815 : $$ = (Node *) n;
1516 : }
1517 : | DROP ROLE IF_P EXISTS role_list
1518 : {
1519 96 : DropRoleStmt *n = makeNode(DropRoleStmt);
1520 :
1521 96 : n->missing_ok = true;
1522 96 : n->roles = $5;
1523 96 : $$ = (Node *) n;
1524 : }
1525 : | DROP USER role_list
1526 : {
1527 296 : DropRoleStmt *n = makeNode(DropRoleStmt);
1528 :
1529 296 : n->missing_ok = false;
1530 296 : n->roles = $3;
1531 296 : $$ = (Node *) n;
1532 : }
1533 : | DROP USER IF_P EXISTS role_list
1534 : {
1535 44 : DropRoleStmt *n = makeNode(DropRoleStmt);
1536 :
1537 44 : n->roles = $5;
1538 44 : n->missing_ok = true;
1539 44 : $$ = (Node *) n;
1540 : }
1541 : | DROP GROUP_P role_list
1542 : {
1543 24 : DropRoleStmt *n = makeNode(DropRoleStmt);
1544 :
1545 24 : n->missing_ok = false;
1546 24 : n->roles = $3;
1547 24 : $$ = (Node *) n;
1548 : }
1549 : | DROP GROUP_P IF_P EXISTS role_list
1550 : {
1551 4 : DropRoleStmt *n = makeNode(DropRoleStmt);
1552 :
1553 4 : n->missing_ok = true;
1554 4 : n->roles = $5;
1555 4 : $$ = (Node *) n;
1556 : }
1557 : ;
1558 :
1559 :
1560 : /*****************************************************************************
1561 : *
1562 : * Create a postgresql group (role without login ability)
1563 : *
1564 : *****************************************************************************/
1565 :
1566 : CreateGroupStmt:
1567 : CREATE GROUP_P RoleId opt_with OptRoleList
1568 : {
1569 16 : CreateRoleStmt *n = makeNode(CreateRoleStmt);
1570 :
1571 16 : n->stmt_type = ROLESTMT_GROUP;
1572 16 : n->role = $3;
1573 16 : n->options = $5;
1574 16 : $$ = (Node *) n;
1575 : }
1576 : ;
1577 :
1578 :
1579 : /*****************************************************************************
1580 : *
1581 : * Alter a postgresql group
1582 : *
1583 : *****************************************************************************/
1584 :
1585 : AlterGroupStmt:
1586 : ALTER GROUP_P RoleSpec add_drop USER role_list
1587 : {
1588 28 : AlterRoleStmt *n = makeNode(AlterRoleStmt);
1589 :
1590 28 : n->role = $3;
1591 28 : n->action = $4;
1592 28 : n->options = list_make1(makeDefElem("rolemembers",
1593 : (Node *) $6, @6));
1594 28 : $$ = (Node *) n;
1595 : }
1596 : ;
1597 :
1598 52 : add_drop: ADD_P { $$ = +1; }
1599 116 : | DROP { $$ = -1; }
1600 : ;
1601 :
1602 :
1603 : /*****************************************************************************
1604 : *
1605 : * Manipulate a schema
1606 : *
1607 : *****************************************************************************/
1608 :
1609 : CreateSchemaStmt:
1610 : CREATE SCHEMA opt_single_name AUTHORIZATION RoleSpec OptSchemaEltList
1611 : {
1612 110 : CreateSchemaStmt *n = makeNode(CreateSchemaStmt);
1613 :
1614 : /* One can omit the schema name or the authorization id. */
1615 110 : n->schemaname = $3;
1616 110 : n->authrole = $5;
1617 110 : n->schemaElts = $6;
1618 110 : n->if_not_exists = false;
1619 110 : $$ = (Node *) n;
1620 : }
1621 : | CREATE SCHEMA ColId OptSchemaEltList
1622 : {
1623 605 : CreateSchemaStmt *n = makeNode(CreateSchemaStmt);
1624 :
1625 : /* ...but not both */
1626 605 : n->schemaname = $3;
1627 605 : n->authrole = NULL;
1628 605 : n->schemaElts = $4;
1629 605 : n->if_not_exists = false;
1630 605 : $$ = (Node *) n;
1631 : }
1632 : | CREATE SCHEMA IF_P NOT EXISTS opt_single_name AUTHORIZATION RoleSpec OptSchemaEltList
1633 : {
1634 9 : CreateSchemaStmt *n = makeNode(CreateSchemaStmt);
1635 :
1636 : /* schema name can be omitted here, too */
1637 9 : n->schemaname = $6;
1638 9 : n->authrole = $8;
1639 9 : if ($9 != NIL)
1640 0 : ereport(ERROR,
1641 : (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
1642 : errmsg("CREATE SCHEMA IF NOT EXISTS cannot include schema elements"),
1643 : parser_errposition(@9)));
1644 9 : n->schemaElts = $9;
1645 9 : n->if_not_exists = true;
1646 9 : $$ = (Node *) n;
1647 : }
1648 : | CREATE SCHEMA IF_P NOT EXISTS ColId OptSchemaEltList
1649 : {
1650 19 : CreateSchemaStmt *n = makeNode(CreateSchemaStmt);
1651 :
1652 : /* ...but not here */
1653 19 : n->schemaname = $6;
1654 19 : n->authrole = NULL;
1655 19 : if ($7 != NIL)
1656 4 : ereport(ERROR,
1657 : (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
1658 : errmsg("CREATE SCHEMA IF NOT EXISTS cannot include schema elements"),
1659 : parser_errposition(@7)));
1660 15 : n->schemaElts = $7;
1661 15 : n->if_not_exists = true;
1662 15 : $$ = (Node *) n;
1663 : }
1664 : ;
1665 :
1666 : OptSchemaEltList:
1667 : OptSchemaEltList schema_stmt
1668 : {
1669 512 : $$ = lappend($1, $2);
1670 : }
1671 : | /* EMPTY */
1672 743 : { $$ = NIL; }
1673 : ;
1674 :
1675 : /*
1676 : * schema_stmt are the ones that can show up inside a CREATE SCHEMA
1677 : * statement (in addition to by themselves).
1678 : */
1679 : schema_stmt:
1680 : CreateStmt
1681 : | IndexStmt
1682 : | CreateDomainStmt
1683 : | CreateFunctionStmt
1684 : | CreateSeqStmt
1685 : | CreateTrigStmt
1686 : | DefineStmt
1687 : | GrantStmt
1688 : | ViewStmt
1689 : ;
1690 :
1691 :
1692 : /*****************************************************************************
1693 : *
1694 : * Set PG internal variable
1695 : * SET name TO 'var_value'
1696 : * Include SQL syntax (thomas 1997-10-22):
1697 : * SET TIME ZONE 'var_value'
1698 : *
1699 : *****************************************************************************/
1700 :
1701 : VariableSetStmt:
1702 : SET set_rest
1703 : {
1704 14742 : VariableSetStmt *n = $2;
1705 :
1706 14742 : n->is_local = false;
1707 14742 : $$ = (Node *) n;
1708 : }
1709 : | SET LOCAL set_rest
1710 : {
1711 937 : VariableSetStmt *n = $3;
1712 :
1713 937 : n->is_local = true;
1714 937 : $$ = (Node *) n;
1715 : }
1716 : | SET SESSION set_rest
1717 : {
1718 89 : VariableSetStmt *n = $3;
1719 :
1720 89 : n->is_local = false;
1721 89 : $$ = (Node *) n;
1722 : }
1723 : ;
1724 :
1725 : set_rest:
1726 : TRANSACTION transaction_mode_list
1727 : {
1728 387 : VariableSetStmt *n = makeNode(VariableSetStmt);
1729 :
1730 387 : n->kind = VAR_SET_MULTI;
1731 387 : n->name = "TRANSACTION";
1732 387 : n->args = $2;
1733 387 : n->jumble_args = true;
1734 387 : n->location = -1;
1735 387 : $$ = n;
1736 : }
1737 : | SESSION CHARACTERISTICS AS TRANSACTION transaction_mode_list
1738 : {
1739 11 : VariableSetStmt *n = makeNode(VariableSetStmt);
1740 :
1741 11 : n->kind = VAR_SET_MULTI;
1742 11 : n->name = "SESSION CHARACTERISTICS";
1743 11 : n->args = $5;
1744 11 : n->jumble_args = true;
1745 11 : n->location = -1;
1746 11 : $$ = n;
1747 : }
1748 : | set_rest_more
1749 : ;
1750 :
1751 : generic_set:
1752 : var_name TO var_list
1753 : {
1754 3598 : VariableSetStmt *n = makeNode(VariableSetStmt);
1755 :
1756 3598 : n->kind = VAR_SET_VALUE;
1757 3598 : n->name = $1;
1758 3598 : n->args = $3;
1759 3598 : n->location = @3;
1760 3598 : $$ = n;
1761 : }
1762 : | var_name '=' var_list
1763 : {
1764 9738 : VariableSetStmt *n = makeNode(VariableSetStmt);
1765 :
1766 9738 : n->kind = VAR_SET_VALUE;
1767 9738 : n->name = $1;
1768 9738 : n->args = $3;
1769 9738 : n->location = @3;
1770 9738 : $$ = n;
1771 : }
1772 : | var_name TO NULL_P
1773 : {
1774 5 : VariableSetStmt *n = makeNode(VariableSetStmt);
1775 :
1776 5 : n->kind = VAR_SET_VALUE;
1777 5 : n->name = $1;
1778 5 : n->args = list_make1(makeNullAConst(@3));
1779 5 : n->location = @3;
1780 5 : $$ = n;
1781 : }
1782 : | var_name '=' NULL_P
1783 : {
1784 12 : VariableSetStmt *n = makeNode(VariableSetStmt);
1785 :
1786 12 : n->kind = VAR_SET_VALUE;
1787 12 : n->name = $1;
1788 12 : n->args = list_make1(makeNullAConst(@3));
1789 12 : n->location = @3;
1790 12 : $$ = n;
1791 : }
1792 : | var_name TO DEFAULT
1793 : {
1794 90 : VariableSetStmt *n = makeNode(VariableSetStmt);
1795 :
1796 90 : n->kind = VAR_SET_DEFAULT;
1797 90 : n->name = $1;
1798 90 : n->location = -1;
1799 90 : $$ = n;
1800 : }
1801 : | var_name '=' DEFAULT
1802 : {
1803 6 : VariableSetStmt *n = makeNode(VariableSetStmt);
1804 :
1805 6 : n->kind = VAR_SET_DEFAULT;
1806 6 : n->name = $1;
1807 6 : n->location = -1;
1808 6 : $$ = n;
1809 : }
1810 : ;
1811 :
1812 : set_rest_more: /* Generic SET syntaxes: */
1813 13361 : generic_set {$$ = $1;}
1814 : | var_name FROM CURRENT_P
1815 : {
1816 2 : VariableSetStmt *n = makeNode(VariableSetStmt);
1817 :
1818 2 : n->kind = VAR_SET_CURRENT;
1819 2 : n->name = $1;
1820 2 : n->location = -1;
1821 2 : $$ = n;
1822 : }
1823 : /* Special syntaxes mandated by SQL standard: */
1824 : | TIME ZONE zone_value
1825 : {
1826 67 : VariableSetStmt *n = makeNode(VariableSetStmt);
1827 :
1828 67 : n->kind = VAR_SET_VALUE;
1829 67 : n->name = "timezone";
1830 67 : n->location = -1;
1831 67 : n->jumble_args = true;
1832 67 : if ($3 != NULL)
1833 57 : n->args = list_make1($3);
1834 : else
1835 10 : n->kind = VAR_SET_DEFAULT;
1836 67 : $$ = n;
1837 : }
1838 : | CATALOG_P Sconst
1839 : {
1840 0 : ereport(ERROR,
1841 : (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
1842 : errmsg("current database cannot be changed"),
1843 : parser_errposition(@2)));
1844 : $$ = NULL; /*not reached*/
1845 : }
1846 : | SCHEMA Sconst
1847 : {
1848 2 : VariableSetStmt *n = makeNode(VariableSetStmt);
1849 :
1850 2 : n->kind = VAR_SET_VALUE;
1851 2 : n->name = "search_path";
1852 2 : n->args = list_make1(makeStringConst($2, @2));
1853 2 : n->location = @2;
1854 2 : $$ = n;
1855 : }
1856 : | NAMES opt_encoding
1857 : {
1858 0 : VariableSetStmt *n = makeNode(VariableSetStmt);
1859 :
1860 0 : n->kind = VAR_SET_VALUE;
1861 0 : n->name = "client_encoding";
1862 0 : n->location = @2;
1863 0 : if ($2 != NULL)
1864 0 : n->args = list_make1(makeStringConst($2, @2));
1865 : else
1866 0 : n->kind = VAR_SET_DEFAULT;
1867 0 : $$ = n;
1868 : }
1869 : | ROLE NonReservedWord_or_Sconst
1870 : {
1871 706 : VariableSetStmt *n = makeNode(VariableSetStmt);
1872 :
1873 706 : n->kind = VAR_SET_VALUE;
1874 706 : n->name = "role";
1875 706 : n->args = list_make1(makeStringConst($2, @2));
1876 706 : n->location = @2;
1877 706 : $$ = n;
1878 : }
1879 : | SESSION AUTHORIZATION NonReservedWord_or_Sconst
1880 : {
1881 1993 : VariableSetStmt *n = makeNode(VariableSetStmt);
1882 :
1883 1993 : n->kind = VAR_SET_VALUE;
1884 1993 : n->name = "session_authorization";
1885 1993 : n->args = list_make1(makeStringConst($3, @3));
1886 1993 : n->location = @3;
1887 1993 : $$ = n;
1888 : }
1889 : | SESSION AUTHORIZATION DEFAULT
1890 : {
1891 2 : VariableSetStmt *n = makeNode(VariableSetStmt);
1892 :
1893 2 : n->kind = VAR_SET_DEFAULT;
1894 2 : n->name = "session_authorization";
1895 2 : n->location = -1;
1896 2 : $$ = n;
1897 : }
1898 : | XML_P OPTION document_or_content
1899 : {
1900 10 : VariableSetStmt *n = makeNode(VariableSetStmt);
1901 :
1902 10 : n->kind = VAR_SET_VALUE;
1903 10 : n->name = "xmloption";
1904 10 : n->args = list_make1(makeStringConst($3 == XMLOPTION_DOCUMENT ? "DOCUMENT" : "CONTENT", @3));
1905 10 : n->jumble_args = true;
1906 10 : n->location = -1;
1907 10 : $$ = n;
1908 : }
1909 : /* Special syntaxes invented by PostgreSQL: */
1910 : | TRANSACTION SNAPSHOT Sconst
1911 : {
1912 24 : VariableSetStmt *n = makeNode(VariableSetStmt);
1913 :
1914 24 : n->kind = VAR_SET_MULTI;
1915 24 : n->name = "TRANSACTION SNAPSHOT";
1916 24 : n->args = list_make1(makeStringConst($3, @3));
1917 24 : n->location = @3;
1918 24 : $$ = n;
1919 : }
1920 : ;
1921 :
1922 16707 : var_name: ColId { $$ = $1; }
1923 : | var_name '.' ColId
1924 458 : { $$ = psprintf("%s.%s", $1, $3); }
1925 : ;
1926 :
1927 13336 : var_list: var_value { $$ = list_make1($1); }
1928 450 : | var_list ',' var_value { $$ = lappend($1, $3); }
1929 : ;
1930 :
1931 : var_value: opt_boolean_or_string
1932 10345 : { $$ = makeStringConst($1, @1); }
1933 : | NumericOnly
1934 3441 : { $$ = makeAConst($1, @1); }
1935 : ;
1936 :
1937 0 : iso_level: READ UNCOMMITTED { $$ = "read uncommitted"; }
1938 644 : | READ COMMITTED { $$ = "read committed"; }
1939 1606 : | REPEATABLE READ { $$ = "repeatable read"; }
1940 1645 : | SERIALIZABLE { $$ = "serializable"; }
1941 : ;
1942 :
1943 : opt_boolean_or_string:
1944 439 : TRUE_P { $$ = "true"; }
1945 870 : | FALSE_P { $$ = "false"; }
1946 1681 : | ON { $$ = "on"; }
1947 : /*
1948 : * OFF is also accepted as a boolean value, but is handled by
1949 : * the NonReservedWord rule. The action for booleans and strings
1950 : * is the same, so we don't need to distinguish them here.
1951 : */
1952 21899 : | NonReservedWord_or_Sconst { $$ = $1; }
1953 : ;
1954 :
1955 : /* Timezone values can be:
1956 : * - a string such as 'pst8pdt'
1957 : * - an identifier such as "pst8pdt"
1958 : * - an integer or floating point number
1959 : * - a time interval per SQL99
1960 : * ColId gives reduce/reduce errors against ConstInterval and LOCAL,
1961 : * so use IDENT (meaning we reject anything that is a key word).
1962 : */
1963 : zone_value:
1964 : Sconst
1965 : {
1966 39 : $$ = makeStringConst($1, @1);
1967 : }
1968 : | IDENT
1969 : {
1970 2 : $$ = makeStringConst($1, @1);
1971 : }
1972 : | ConstInterval Sconst opt_interval
1973 : {
1974 0 : TypeName *t = $1;
1975 :
1976 0 : if ($3 != NIL)
1977 : {
1978 0 : A_Const *n = (A_Const *) linitial($3);
1979 :
1980 0 : if ((n->val.ival.ival & ~(INTERVAL_MASK(HOUR) | INTERVAL_MASK(MINUTE))) != 0)
1981 0 : ereport(ERROR,
1982 : (errcode(ERRCODE_SYNTAX_ERROR),
1983 : errmsg("time zone interval must be HOUR or HOUR TO MINUTE"),
1984 : parser_errposition(@3)));
1985 : }
1986 0 : t->typmods = $3;
1987 0 : $$ = makeStringConstCast($2, @2, t);
1988 : }
1989 : | ConstInterval '(' Iconst ')' Sconst
1990 : {
1991 0 : TypeName *t = $1;
1992 :
1993 0 : t->typmods = list_make2(makeIntConst(INTERVAL_FULL_RANGE, -1),
1994 : makeIntConst($3, @3));
1995 0 : $$ = makeStringConstCast($5, @5, t);
1996 : }
1997 16 : | NumericOnly { $$ = makeAConst($1, @1); }
1998 9 : | DEFAULT { $$ = NULL; }
1999 1 : | LOCAL { $$ = NULL; }
2000 : ;
2001 :
2002 : opt_encoding:
2003 0 : Sconst { $$ = $1; }
2004 0 : | DEFAULT { $$ = NULL; }
2005 0 : | /*EMPTY*/ { $$ = NULL; }
2006 : ;
2007 :
2008 : NonReservedWord_or_Sconst:
2009 33451 : NonReservedWord { $$ = $1; }
2010 4023 : | Sconst { $$ = $1; }
2011 : ;
2012 :
2013 : VariableResetStmt:
2014 3307 : RESET reset_rest { $$ = (Node *) $2; }
2015 : ;
2016 :
2017 : reset_rest:
2018 2673 : generic_reset { $$ = $1; }
2019 : | TIME ZONE
2020 : {
2021 9 : VariableSetStmt *n = makeNode(VariableSetStmt);
2022 :
2023 9 : n->kind = VAR_RESET;
2024 9 : n->name = "timezone";
2025 9 : n->location = -1;
2026 9 : $$ = n;
2027 : }
2028 : | TRANSACTION ISOLATION LEVEL
2029 : {
2030 0 : VariableSetStmt *n = makeNode(VariableSetStmt);
2031 :
2032 0 : n->kind = VAR_RESET;
2033 0 : n->name = "transaction_isolation";
2034 0 : n->location = -1;
2035 0 : $$ = n;
2036 : }
2037 : | SESSION AUTHORIZATION
2038 : {
2039 625 : VariableSetStmt *n = makeNode(VariableSetStmt);
2040 :
2041 625 : n->kind = VAR_RESET;
2042 625 : n->name = "session_authorization";
2043 625 : n->location = -1;
2044 625 : $$ = n;
2045 : }
2046 : ;
2047 :
2048 : generic_reset:
2049 : var_name
2050 : {
2051 2685 : VariableSetStmt *n = makeNode(VariableSetStmt);
2052 :
2053 2685 : n->kind = VAR_RESET;
2054 2685 : n->name = $1;
2055 2685 : n->location = -1;
2056 2685 : $$ = n;
2057 : }
2058 : | ALL
2059 : {
2060 17 : VariableSetStmt *n = makeNode(VariableSetStmt);
2061 :
2062 17 : n->kind = VAR_RESET_ALL;
2063 17 : n->location = -1;
2064 17 : $$ = n;
2065 : }
2066 : ;
2067 :
2068 : /* SetResetClause allows SET or RESET without LOCAL */
2069 : SetResetClause:
2070 709 : SET set_rest { $$ = $2; }
2071 21 : | VariableResetStmt { $$ = (VariableSetStmt *) $1; }
2072 : ;
2073 :
2074 : /* SetResetClause allows SET or RESET without LOCAL */
2075 : FunctionSetResetClause:
2076 88 : SET set_rest_more { $$ = $2; }
2077 8 : | VariableResetStmt { $$ = (VariableSetStmt *) $1; }
2078 : ;
2079 :
2080 :
2081 : VariableShowStmt:
2082 : SHOW var_name
2083 : {
2084 571 : VariableShowStmt *n = makeNode(VariableShowStmt);
2085 :
2086 571 : n->name = $2;
2087 571 : $$ = (Node *) n;
2088 : }
2089 : | SHOW TIME ZONE
2090 : {
2091 6 : VariableShowStmt *n = makeNode(VariableShowStmt);
2092 :
2093 6 : n->name = "timezone";
2094 6 : $$ = (Node *) n;
2095 : }
2096 : | SHOW TRANSACTION ISOLATION LEVEL
2097 : {
2098 2 : VariableShowStmt *n = makeNode(VariableShowStmt);
2099 :
2100 2 : n->name = "transaction_isolation";
2101 2 : $$ = (Node *) n;
2102 : }
2103 : | SHOW SESSION AUTHORIZATION
2104 : {
2105 0 : VariableShowStmt *n = makeNode(VariableShowStmt);
2106 :
2107 0 : n->name = "session_authorization";
2108 0 : $$ = (Node *) n;
2109 : }
2110 : | SHOW ALL
2111 : {
2112 0 : VariableShowStmt *n = makeNode(VariableShowStmt);
2113 :
2114 0 : n->name = "all";
2115 0 : $$ = (Node *) n;
2116 : }
2117 : ;
2118 :
2119 :
2120 : ConstraintsSetStmt:
2121 : SET CONSTRAINTS constraints_set_list constraints_set_mode
2122 : {
2123 72 : ConstraintsSetStmt *n = makeNode(ConstraintsSetStmt);
2124 :
2125 72 : n->constraints = $3;
2126 72 : n->deferred = $4;
2127 72 : $$ = (Node *) n;
2128 : }
2129 : ;
2130 :
2131 : constraints_set_list:
2132 40 : ALL { $$ = NIL; }
2133 32 : | qualified_name_list { $$ = $1; }
2134 : ;
2135 :
2136 : constraints_set_mode:
2137 45 : DEFERRED { $$ = true; }
2138 27 : | IMMEDIATE { $$ = false; }
2139 : ;
2140 :
2141 :
2142 : /*
2143 : * Checkpoint statement
2144 : */
2145 : CheckPointStmt:
2146 : CHECKPOINT opt_utility_option_list
2147 : {
2148 143 : CheckPointStmt *n = makeNode(CheckPointStmt);
2149 :
2150 143 : $$ = (Node *) n;
2151 143 : n->options = $2;
2152 : }
2153 : ;
2154 :
2155 :
2156 : /*****************************************************************************
2157 : *
2158 : * DISCARD { ALL | TEMP | PLANS | SEQUENCES }
2159 : *
2160 : *****************************************************************************/
2161 :
2162 : DiscardStmt:
2163 : DISCARD ALL
2164 : {
2165 4 : DiscardStmt *n = makeNode(DiscardStmt);
2166 :
2167 4 : n->target = DISCARD_ALL;
2168 4 : $$ = (Node *) n;
2169 : }
2170 : | DISCARD TEMP
2171 : {
2172 9 : DiscardStmt *n = makeNode(DiscardStmt);
2173 :
2174 9 : n->target = DISCARD_TEMP;
2175 9 : $$ = (Node *) n;
2176 : }
2177 : | DISCARD TEMPORARY
2178 : {
2179 0 : DiscardStmt *n = makeNode(DiscardStmt);
2180 :
2181 0 : n->target = DISCARD_TEMP;
2182 0 : $$ = (Node *) n;
2183 : }
2184 : | DISCARD PLANS
2185 : {
2186 3 : DiscardStmt *n = makeNode(DiscardStmt);
2187 :
2188 3 : n->target = DISCARD_PLANS;
2189 3 : $$ = (Node *) n;
2190 : }
2191 : | DISCARD SEQUENCES
2192 : {
2193 8 : DiscardStmt *n = makeNode(DiscardStmt);
2194 :
2195 8 : n->target = DISCARD_SEQUENCES;
2196 8 : $$ = (Node *) n;
2197 : }
2198 :
2199 : ;
2200 :
2201 :
2202 : /*****************************************************************************
2203 : *
2204 : * ALTER [ TABLE | INDEX | SEQUENCE | VIEW | MATERIALIZED VIEW | FOREIGN TABLE ] variations
2205 : *
2206 : * Note: we accept all subcommands for each of the variants, and sort
2207 : * out what's really legal at execution time.
2208 : *****************************************************************************/
2209 :
2210 : AlterTableStmt:
2211 : ALTER TABLE relation_expr alter_table_cmds
2212 : {
2213 17261 : AlterTableStmt *n = makeNode(AlterTableStmt);
2214 :
2215 17261 : n->relation = $3;
2216 17261 : n->cmds = $4;
2217 17261 : n->objtype = OBJECT_TABLE;
2218 17261 : n->missing_ok = false;
2219 17261 : $$ = (Node *) n;
2220 : }
2221 : | ALTER TABLE IF_P EXISTS relation_expr alter_table_cmds
2222 : {
2223 36 : AlterTableStmt *n = makeNode(AlterTableStmt);
2224 :
2225 36 : n->relation = $5;
2226 36 : n->cmds = $6;
2227 36 : n->objtype = OBJECT_TABLE;
2228 36 : n->missing_ok = true;
2229 36 : $$ = (Node *) n;
2230 : }
2231 : | ALTER TABLE relation_expr partition_cmd
2232 : {
2233 2460 : AlterTableStmt *n = makeNode(AlterTableStmt);
2234 :
2235 2460 : n->relation = $3;
2236 2460 : n->cmds = list_make1($4);
2237 2460 : n->objtype = OBJECT_TABLE;
2238 2460 : n->missing_ok = false;
2239 2460 : $$ = (Node *) n;
2240 : }
2241 : | ALTER TABLE IF_P EXISTS relation_expr partition_cmd
2242 : {
2243 0 : AlterTableStmt *n = makeNode(AlterTableStmt);
2244 :
2245 0 : n->relation = $5;
2246 0 : n->cmds = list_make1($6);
2247 0 : n->objtype = OBJECT_TABLE;
2248 0 : n->missing_ok = true;
2249 0 : $$ = (Node *) n;
2250 : }
2251 : | ALTER TABLE ALL IN_P TABLESPACE name SET TABLESPACE name opt_nowait
2252 : {
2253 : AlterTableMoveAllStmt *n =
2254 6 : makeNode(AlterTableMoveAllStmt);
2255 :
2256 6 : n->orig_tablespacename = $6;
2257 6 : n->objtype = OBJECT_TABLE;
2258 6 : n->roles = NIL;
2259 6 : n->new_tablespacename = $9;
2260 6 : n->nowait = $10;
2261 6 : $$ = (Node *) n;
2262 : }
2263 : | ALTER TABLE ALL IN_P TABLESPACE name OWNED BY role_list SET TABLESPACE name opt_nowait
2264 : {
2265 : AlterTableMoveAllStmt *n =
2266 0 : makeNode(AlterTableMoveAllStmt);
2267 :
2268 0 : n->orig_tablespacename = $6;
2269 0 : n->objtype = OBJECT_TABLE;
2270 0 : n->roles = $9;
2271 0 : n->new_tablespacename = $12;
2272 0 : n->nowait = $13;
2273 0 : $$ = (Node *) n;
2274 : }
2275 : | ALTER INDEX qualified_name alter_table_cmds
2276 : {
2277 145 : AlterTableStmt *n = makeNode(AlterTableStmt);
2278 :
2279 145 : n->relation = $3;
2280 145 : n->cmds = $4;
2281 145 : n->objtype = OBJECT_INDEX;
2282 145 : n->missing_ok = false;
2283 145 : $$ = (Node *) n;
2284 : }
2285 : | ALTER INDEX IF_P EXISTS qualified_name alter_table_cmds
2286 : {
2287 0 : AlterTableStmt *n = makeNode(AlterTableStmt);
2288 :
2289 0 : n->relation = $5;
2290 0 : n->cmds = $6;
2291 0 : n->objtype = OBJECT_INDEX;
2292 0 : n->missing_ok = true;
2293 0 : $$ = (Node *) n;
2294 : }
2295 : | ALTER INDEX qualified_name index_partition_cmd
2296 : {
2297 245 : AlterTableStmt *n = makeNode(AlterTableStmt);
2298 :
2299 245 : n->relation = $3;
2300 245 : n->cmds = list_make1($4);
2301 245 : n->objtype = OBJECT_INDEX;
2302 245 : n->missing_ok = false;
2303 245 : $$ = (Node *) n;
2304 : }
2305 : | ALTER INDEX ALL IN_P TABLESPACE name SET TABLESPACE name opt_nowait
2306 : {
2307 : AlterTableMoveAllStmt *n =
2308 3 : makeNode(AlterTableMoveAllStmt);
2309 :
2310 3 : n->orig_tablespacename = $6;
2311 3 : n->objtype = OBJECT_INDEX;
2312 3 : n->roles = NIL;
2313 3 : n->new_tablespacename = $9;
2314 3 : n->nowait = $10;
2315 3 : $$ = (Node *) n;
2316 : }
2317 : | ALTER INDEX ALL IN_P TABLESPACE name OWNED BY role_list SET TABLESPACE name opt_nowait
2318 : {
2319 : AlterTableMoveAllStmt *n =
2320 0 : makeNode(AlterTableMoveAllStmt);
2321 :
2322 0 : n->orig_tablespacename = $6;
2323 0 : n->objtype = OBJECT_INDEX;
2324 0 : n->roles = $9;
2325 0 : n->new_tablespacename = $12;
2326 0 : n->nowait = $13;
2327 0 : $$ = (Node *) n;
2328 : }
2329 : | ALTER SEQUENCE qualified_name alter_table_cmds
2330 : {
2331 51 : AlterTableStmt *n = makeNode(AlterTableStmt);
2332 :
2333 51 : n->relation = $3;
2334 51 : n->cmds = $4;
2335 51 : n->objtype = OBJECT_SEQUENCE;
2336 51 : n->missing_ok = false;
2337 51 : $$ = (Node *) n;
2338 : }
2339 : | ALTER SEQUENCE IF_P EXISTS qualified_name alter_table_cmds
2340 : {
2341 0 : AlterTableStmt *n = makeNode(AlterTableStmt);
2342 :
2343 0 : n->relation = $5;
2344 0 : n->cmds = $6;
2345 0 : n->objtype = OBJECT_SEQUENCE;
2346 0 : n->missing_ok = true;
2347 0 : $$ = (Node *) n;
2348 : }
2349 : | ALTER VIEW qualified_name alter_table_cmds
2350 : {
2351 154 : AlterTableStmt *n = makeNode(AlterTableStmt);
2352 :
2353 154 : n->relation = $3;
2354 154 : n->cmds = $4;
2355 154 : n->objtype = OBJECT_VIEW;
2356 154 : n->missing_ok = false;
2357 154 : $$ = (Node *) n;
2358 : }
2359 : | ALTER VIEW IF_P EXISTS qualified_name alter_table_cmds
2360 : {
2361 0 : AlterTableStmt *n = makeNode(AlterTableStmt);
2362 :
2363 0 : n->relation = $5;
2364 0 : n->cmds = $6;
2365 0 : n->objtype = OBJECT_VIEW;
2366 0 : n->missing_ok = true;
2367 0 : $$ = (Node *) n;
2368 : }
2369 : | ALTER MATERIALIZED VIEW qualified_name alter_table_cmds
2370 : {
2371 29 : AlterTableStmt *n = makeNode(AlterTableStmt);
2372 :
2373 29 : n->relation = $4;
2374 29 : n->cmds = $5;
2375 29 : n->objtype = OBJECT_MATVIEW;
2376 29 : n->missing_ok = false;
2377 29 : $$ = (Node *) n;
2378 : }
2379 : | ALTER MATERIALIZED VIEW IF_P EXISTS qualified_name alter_table_cmds
2380 : {
2381 0 : AlterTableStmt *n = makeNode(AlterTableStmt);
2382 :
2383 0 : n->relation = $6;
2384 0 : n->cmds = $7;
2385 0 : n->objtype = OBJECT_MATVIEW;
2386 0 : n->missing_ok = true;
2387 0 : $$ = (Node *) n;
2388 : }
2389 : | ALTER MATERIALIZED VIEW ALL IN_P TABLESPACE name SET TABLESPACE name opt_nowait
2390 : {
2391 : AlterTableMoveAllStmt *n =
2392 6 : makeNode(AlterTableMoveAllStmt);
2393 :
2394 6 : n->orig_tablespacename = $7;
2395 6 : n->objtype = OBJECT_MATVIEW;
2396 6 : n->roles = NIL;
2397 6 : n->new_tablespacename = $10;
2398 6 : n->nowait = $11;
2399 6 : $$ = (Node *) n;
2400 : }
2401 : | ALTER MATERIALIZED VIEW ALL IN_P TABLESPACE name OWNED BY role_list SET TABLESPACE name opt_nowait
2402 : {
2403 : AlterTableMoveAllStmt *n =
2404 0 : makeNode(AlterTableMoveAllStmt);
2405 :
2406 0 : n->orig_tablespacename = $7;
2407 0 : n->objtype = OBJECT_MATVIEW;
2408 0 : n->roles = $10;
2409 0 : n->new_tablespacename = $13;
2410 0 : n->nowait = $14;
2411 0 : $$ = (Node *) n;
2412 : }
2413 : | ALTER FOREIGN TABLE relation_expr alter_table_cmds
2414 : {
2415 247 : AlterTableStmt *n = makeNode(AlterTableStmt);
2416 :
2417 247 : n->relation = $4;
2418 247 : n->cmds = $5;
2419 247 : n->objtype = OBJECT_FOREIGN_TABLE;
2420 247 : n->missing_ok = false;
2421 247 : $$ = (Node *) n;
2422 : }
2423 : | ALTER FOREIGN TABLE IF_P EXISTS relation_expr alter_table_cmds
2424 : {
2425 88 : AlterTableStmt *n = makeNode(AlterTableStmt);
2426 :
2427 88 : n->relation = $6;
2428 88 : n->cmds = $7;
2429 88 : n->objtype = OBJECT_FOREIGN_TABLE;
2430 88 : n->missing_ok = true;
2431 88 : $$ = (Node *) n;
2432 : }
2433 : ;
2434 :
2435 : alter_table_cmds:
2436 18011 : alter_table_cmd { $$ = list_make1($1); }
2437 712 : | alter_table_cmds ',' alter_table_cmd { $$ = lappend($1, $3); }
2438 : ;
2439 :
2440 : partitions_list:
2441 256 : SinglePartitionSpec { $$ = list_make1($1); }
2442 472 : | partitions_list ',' SinglePartitionSpec { $$ = lappend($1, $3); }
2443 : ;
2444 :
2445 : SinglePartitionSpec:
2446 : PARTITION qualified_name PartitionBoundSpec
2447 : {
2448 728 : SinglePartitionSpec *n = makeNode(SinglePartitionSpec);
2449 :
2450 728 : n->name = $2;
2451 728 : n->bound = $3;
2452 :
2453 728 : $$ = n;
2454 : }
2455 : ;
2456 :
2457 : partition_cmd:
2458 : /* ALTER TABLE <name> ATTACH PARTITION <table_name> FOR VALUES */
2459 : ATTACH PARTITION qualified_name PartitionBoundSpec
2460 : {
2461 1628 : AlterTableCmd *n = makeNode(AlterTableCmd);
2462 1628 : PartitionCmd *cmd = makeNode(PartitionCmd);
2463 :
2464 1628 : n->subtype = AT_AttachPartition;
2465 1628 : cmd->name = $3;
2466 1628 : cmd->bound = $4;
2467 1628 : cmd->partlist = NIL;
2468 1628 : cmd->concurrent = false;
2469 1628 : n->def = (Node *) cmd;
2470 :
2471 1628 : $$ = (Node *) n;
2472 : }
2473 : /* ALTER TABLE <name> DETACH PARTITION <partition_name> [CONCURRENTLY] */
2474 : | DETACH PARTITION qualified_name opt_concurrently
2475 : {
2476 389 : AlterTableCmd *n = makeNode(AlterTableCmd);
2477 389 : PartitionCmd *cmd = makeNode(PartitionCmd);
2478 :
2479 389 : n->subtype = AT_DetachPartition;
2480 389 : cmd->name = $3;
2481 389 : cmd->bound = NULL;
2482 389 : cmd->partlist = NIL;
2483 389 : cmd->concurrent = $4;
2484 389 : n->def = (Node *) cmd;
2485 :
2486 389 : $$ = (Node *) n;
2487 : }
2488 : | DETACH PARTITION qualified_name FINALIZE
2489 : {
2490 11 : AlterTableCmd *n = makeNode(AlterTableCmd);
2491 11 : PartitionCmd *cmd = makeNode(PartitionCmd);
2492 :
2493 11 : n->subtype = AT_DetachPartitionFinalize;
2494 11 : cmd->name = $3;
2495 11 : cmd->bound = NULL;
2496 11 : cmd->partlist = NIL;
2497 11 : cmd->concurrent = false;
2498 11 : n->def = (Node *) cmd;
2499 11 : $$ = (Node *) n;
2500 : }
2501 : /* ALTER TABLE <name> SPLIT PARTITION <partition_name> INTO () */
2502 : | SPLIT PARTITION qualified_name INTO '(' partitions_list ')'
2503 : {
2504 256 : AlterTableCmd *n = makeNode(AlterTableCmd);
2505 256 : PartitionCmd *cmd = makeNode(PartitionCmd);
2506 :
2507 256 : n->subtype = AT_SplitPartition;
2508 256 : cmd->name = $3;
2509 256 : cmd->bound = NULL;
2510 256 : cmd->partlist = $6;
2511 256 : cmd->concurrent = false;
2512 256 : n->def = (Node *) cmd;
2513 256 : $$ = (Node *) n;
2514 : }
2515 : /* ALTER TABLE <name> MERGE PARTITIONS () INTO <partition_name> */
2516 : | MERGE PARTITIONS '(' qualified_name_list ')' INTO qualified_name
2517 : {
2518 176 : AlterTableCmd *n = makeNode(AlterTableCmd);
2519 176 : PartitionCmd *cmd = makeNode(PartitionCmd);
2520 :
2521 176 : n->subtype = AT_MergePartitions;
2522 176 : cmd->name = $7;
2523 176 : cmd->bound = NULL;
2524 176 : cmd->partlist = $4;
2525 176 : cmd->concurrent = false;
2526 176 : n->def = (Node *) cmd;
2527 176 : $$ = (Node *) n;
2528 : }
2529 : ;
2530 :
2531 : index_partition_cmd:
2532 : /* ALTER INDEX <name> ATTACH PARTITION <index_name> */
2533 : ATTACH PARTITION qualified_name
2534 : {
2535 245 : AlterTableCmd *n = makeNode(AlterTableCmd);
2536 245 : PartitionCmd *cmd = makeNode(PartitionCmd);
2537 :
2538 245 : n->subtype = AT_AttachPartition;
2539 245 : cmd->name = $3;
2540 245 : cmd->bound = NULL;
2541 245 : cmd->partlist = NIL;
2542 245 : cmd->concurrent = false;
2543 245 : n->def = (Node *) cmd;
2544 :
2545 245 : $$ = (Node *) n;
2546 : }
2547 : ;
2548 :
2549 : alter_table_cmd:
2550 : /* ALTER TABLE <name> ADD <coldef> */
2551 : ADD_P columnDef
2552 : {
2553 138 : AlterTableCmd *n = makeNode(AlterTableCmd);
2554 :
2555 138 : n->subtype = AT_AddColumn;
2556 138 : n->def = $2;
2557 138 : n->missing_ok = false;
2558 138 : $$ = (Node *) n;
2559 : }
2560 : /* ALTER TABLE <name> ADD IF NOT EXISTS <coldef> */
2561 : | ADD_P IF_P NOT EXISTS columnDef
2562 : {
2563 4 : AlterTableCmd *n = makeNode(AlterTableCmd);
2564 :
2565 4 : n->subtype = AT_AddColumn;
2566 4 : n->def = $5;
2567 4 : n->missing_ok = true;
2568 4 : $$ = (Node *) n;
2569 : }
2570 : /* ALTER TABLE <name> ADD COLUMN <coldef> */
2571 : | ADD_P COLUMN columnDef
2572 : {
2573 1404 : AlterTableCmd *n = makeNode(AlterTableCmd);
2574 :
2575 1404 : n->subtype = AT_AddColumn;
2576 1404 : n->def = $3;
2577 1404 : n->missing_ok = false;
2578 1404 : $$ = (Node *) n;
2579 : }
2580 : /* ALTER TABLE <name> ADD COLUMN IF NOT EXISTS <coldef> */
2581 : | ADD_P COLUMN IF_P NOT EXISTS columnDef
2582 : {
2583 48 : AlterTableCmd *n = makeNode(AlterTableCmd);
2584 :
2585 48 : n->subtype = AT_AddColumn;
2586 48 : n->def = $6;
2587 48 : n->missing_ok = true;
2588 48 : $$ = (Node *) n;
2589 : }
2590 : /* ALTER TABLE <name> ALTER [COLUMN] <colname> {SET DEFAULT <expr>|DROP DEFAULT} */
2591 : | ALTER opt_column ColId alter_column_default
2592 : {
2593 361 : AlterTableCmd *n = makeNode(AlterTableCmd);
2594 :
2595 361 : n->subtype = AT_ColumnDefault;
2596 361 : n->name = $3;
2597 361 : n->def = $4;
2598 361 : $$ = (Node *) n;
2599 : }
2600 : /* ALTER TABLE <name> ALTER [COLUMN] <colname> DROP NOT NULL */
2601 : | ALTER opt_column ColId DROP NOT NULL_P
2602 : {
2603 194 : AlterTableCmd *n = makeNode(AlterTableCmd);
2604 :
2605 194 : n->subtype = AT_DropNotNull;
2606 194 : n->name = $3;
2607 194 : $$ = (Node *) n;
2608 : }
2609 : /* ALTER TABLE <name> ALTER [COLUMN] <colname> SET NOT NULL */
2610 : | ALTER opt_column ColId SET NOT NULL_P
2611 : {
2612 289 : AlterTableCmd *n = makeNode(AlterTableCmd);
2613 :
2614 289 : n->subtype = AT_SetNotNull;
2615 289 : n->name = $3;
2616 289 : $$ = (Node *) n;
2617 : }
2618 : /* ALTER TABLE <name> ALTER [COLUMN] <colname> SET EXPRESSION AS <expr> */
2619 : | ALTER opt_column ColId SET EXPRESSION AS '(' a_expr ')'
2620 : {
2621 129 : AlterTableCmd *n = makeNode(AlterTableCmd);
2622 :
2623 129 : n->subtype = AT_SetExpression;
2624 129 : n->name = $3;
2625 129 : n->def = $8;
2626 129 : $$ = (Node *) n;
2627 : }
2628 : /* ALTER TABLE <name> ALTER [COLUMN] <colname> DROP EXPRESSION */
2629 : | ALTER opt_column ColId DROP EXPRESSION
2630 : {
2631 41 : AlterTableCmd *n = makeNode(AlterTableCmd);
2632 :
2633 41 : n->subtype = AT_DropExpression;
2634 41 : n->name = $3;
2635 41 : $$ = (Node *) n;
2636 : }
2637 : /* ALTER TABLE <name> ALTER [COLUMN] <colname> DROP EXPRESSION IF EXISTS */
2638 : | ALTER opt_column ColId DROP EXPRESSION IF_P EXISTS
2639 : {
2640 8 : AlterTableCmd *n = makeNode(AlterTableCmd);
2641 :
2642 8 : n->subtype = AT_DropExpression;
2643 8 : n->name = $3;
2644 8 : n->missing_ok = true;
2645 8 : $$ = (Node *) n;
2646 : }
2647 : /* ALTER TABLE <name> ALTER [COLUMN] <colname> SET STATISTICS */
2648 : | ALTER opt_column ColId SET STATISTICS set_statistics_value
2649 : {
2650 40 : AlterTableCmd *n = makeNode(AlterTableCmd);
2651 :
2652 40 : n->subtype = AT_SetStatistics;
2653 40 : n->name = $3;
2654 40 : n->def = $6;
2655 40 : $$ = (Node *) n;
2656 : }
2657 : /* ALTER TABLE <name> ALTER [COLUMN] <colnum> SET STATISTICS */
2658 : | ALTER opt_column Iconst SET STATISTICS set_statistics_value
2659 : {
2660 46 : AlterTableCmd *n = makeNode(AlterTableCmd);
2661 :
2662 46 : if ($3 <= 0 || $3 > PG_INT16_MAX)
2663 4 : ereport(ERROR,
2664 : (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
2665 : errmsg("column number must be in range from 1 to %d", PG_INT16_MAX),
2666 : parser_errposition(@3)));
2667 :
2668 42 : n->subtype = AT_SetStatistics;
2669 42 : n->num = (int16) $3;
2670 42 : n->def = $6;
2671 42 : $$ = (Node *) n;
2672 : }
2673 : /* ALTER TABLE <name> ALTER [COLUMN] <colname> SET ( column_parameter = value [, ... ] ) */
2674 : | ALTER opt_column ColId SET reloptions
2675 : {
2676 25 : AlterTableCmd *n = makeNode(AlterTableCmd);
2677 :
2678 25 : n->subtype = AT_SetOptions;
2679 25 : n->name = $3;
2680 25 : n->def = (Node *) $5;
2681 25 : $$ = (Node *) n;
2682 : }
2683 : /* ALTER TABLE <name> ALTER [COLUMN] <colname> RESET ( column_parameter [, ... ] ) */
2684 : | ALTER opt_column ColId RESET reloptions
2685 : {
2686 4 : AlterTableCmd *n = makeNode(AlterTableCmd);
2687 :
2688 4 : n->subtype = AT_ResetOptions;
2689 4 : n->name = $3;
2690 4 : n->def = (Node *) $5;
2691 4 : $$ = (Node *) n;
2692 : }
2693 : /* ALTER TABLE <name> ALTER [COLUMN] <colname> SET STORAGE <storagemode> */
2694 : | ALTER opt_column ColId SET column_storage
2695 : {
2696 159 : AlterTableCmd *n = makeNode(AlterTableCmd);
2697 :
2698 159 : n->subtype = AT_SetStorage;
2699 159 : n->name = $3;
2700 159 : n->def = (Node *) makeString($5);
2701 159 : $$ = (Node *) n;
2702 : }
2703 : /* ALTER TABLE <name> ALTER [COLUMN] <colname> SET COMPRESSION <cm> */
2704 : | ALTER opt_column ColId SET column_compression
2705 : {
2706 47 : AlterTableCmd *n = makeNode(AlterTableCmd);
2707 :
2708 47 : n->subtype = AT_SetCompression;
2709 47 : n->name = $3;
2710 47 : n->def = (Node *) makeString($5);
2711 47 : $$ = (Node *) n;
2712 : }
2713 : /* ALTER TABLE <name> ALTER [COLUMN] <colname> ADD GENERATED ... AS IDENTITY ... */
2714 : | ALTER opt_column ColId ADD_P GENERATED generated_when AS IDENTITY_P OptParenthesizedSeqOptList
2715 : {
2716 107 : AlterTableCmd *n = makeNode(AlterTableCmd);
2717 107 : Constraint *c = makeNode(Constraint);
2718 :
2719 107 : c->contype = CONSTR_IDENTITY;
2720 107 : c->generated_when = $6;
2721 107 : c->options = $9;
2722 107 : c->location = @5;
2723 :
2724 107 : n->subtype = AT_AddIdentity;
2725 107 : n->name = $3;
2726 107 : n->def = (Node *) c;
2727 :
2728 107 : $$ = (Node *) n;
2729 : }
2730 : /* ALTER TABLE <name> ALTER [COLUMN] <colname> SET <sequence options>/RESET */
2731 : | ALTER opt_column ColId alter_identity_column_option_list
2732 : {
2733 41 : AlterTableCmd *n = makeNode(AlterTableCmd);
2734 :
2735 41 : n->subtype = AT_SetIdentity;
2736 41 : n->name = $3;
2737 41 : n->def = (Node *) $4;
2738 41 : $$ = (Node *) n;
2739 : }
2740 : /* ALTER TABLE <name> ALTER [COLUMN] <colname> DROP IDENTITY */
2741 : | ALTER opt_column ColId DROP IDENTITY_P
2742 : {
2743 33 : AlterTableCmd *n = makeNode(AlterTableCmd);
2744 :
2745 33 : n->subtype = AT_DropIdentity;
2746 33 : n->name = $3;
2747 33 : n->missing_ok = false;
2748 33 : $$ = (Node *) n;
2749 : }
2750 : /* ALTER TABLE <name> ALTER [COLUMN] <colname> DROP IDENTITY IF EXISTS */
2751 : | ALTER opt_column ColId DROP IDENTITY_P IF_P EXISTS
2752 : {
2753 4 : AlterTableCmd *n = makeNode(AlterTableCmd);
2754 :
2755 4 : n->subtype = AT_DropIdentity;
2756 4 : n->name = $3;
2757 4 : n->missing_ok = true;
2758 4 : $$ = (Node *) n;
2759 : }
2760 : /* ALTER TABLE <name> DROP [COLUMN] IF EXISTS <colname> [RESTRICT|CASCADE] */
2761 : | DROP opt_column IF_P EXISTS ColId opt_drop_behavior
2762 : {
2763 16 : AlterTableCmd *n = makeNode(AlterTableCmd);
2764 :
2765 16 : n->subtype = AT_DropColumn;
2766 16 : n->name = $5;
2767 16 : n->behavior = $6;
2768 16 : n->missing_ok = true;
2769 16 : $$ = (Node *) n;
2770 : }
2771 : /* ALTER TABLE <name> DROP [COLUMN] <colname> [RESTRICT|CASCADE] */
2772 : | DROP opt_column ColId opt_drop_behavior
2773 : {
2774 1087 : AlterTableCmd *n = makeNode(AlterTableCmd);
2775 :
2776 1087 : n->subtype = AT_DropColumn;
2777 1087 : n->name = $3;
2778 1087 : n->behavior = $4;
2779 1087 : n->missing_ok = false;
2780 1087 : $$ = (Node *) n;
2781 : }
2782 : /*
2783 : * ALTER TABLE <name> ALTER [COLUMN] <colname> [SET DATA] TYPE <typename>
2784 : * [ USING <expression> ]
2785 : */
2786 : | ALTER opt_column ColId opt_set_data TYPE_P Typename opt_collate_clause alter_using
2787 : {
2788 757 : AlterTableCmd *n = makeNode(AlterTableCmd);
2789 757 : ColumnDef *def = makeNode(ColumnDef);
2790 :
2791 757 : n->subtype = AT_AlterColumnType;
2792 757 : n->name = $3;
2793 757 : n->def = (Node *) def;
2794 : /* We only use these fields of the ColumnDef node */
2795 757 : def->typeName = $6;
2796 757 : def->collClause = (CollateClause *) $7;
2797 757 : def->raw_default = $8;
2798 757 : def->location = @3;
2799 757 : $$ = (Node *) n;
2800 : }
2801 : /* ALTER FOREIGN TABLE <name> ALTER [COLUMN] <colname> OPTIONS */
2802 : | ALTER opt_column ColId alter_generic_options
2803 : {
2804 32 : AlterTableCmd *n = makeNode(AlterTableCmd);
2805 :
2806 32 : n->subtype = AT_AlterColumnGenericOptions;
2807 32 : n->name = $3;
2808 32 : n->def = (Node *) $4;
2809 32 : $$ = (Node *) n;
2810 : }
2811 : /* ALTER TABLE <name> ADD CONSTRAINT ... */
2812 : | ADD_P TableConstraint
2813 : {
2814 9301 : AlterTableCmd *n = makeNode(AlterTableCmd);
2815 :
2816 9301 : n->subtype = AT_AddConstraint;
2817 9301 : n->def = $2;
2818 9301 : $$ = (Node *) n;
2819 : }
2820 : /* ALTER TABLE <name> ALTER CONSTRAINT ... */
2821 : | ALTER CONSTRAINT name ConstraintAttributeSpec
2822 : {
2823 260 : AlterTableCmd *n = makeNode(AlterTableCmd);
2824 260 : ATAlterConstraint *c = makeNode(ATAlterConstraint);
2825 :
2826 260 : n->subtype = AT_AlterConstraint;
2827 260 : n->def = (Node *) c;
2828 260 : c->conname = $3;
2829 260 : if ($4 & (CAS_NOT_ENFORCED | CAS_ENFORCED))
2830 156 : c->alterEnforceability = true;
2831 260 : if ($4 & (CAS_DEFERRABLE | CAS_NOT_DEFERRABLE |
2832 : CAS_INITIALLY_DEFERRED | CAS_INITIALLY_IMMEDIATE))
2833 80 : c->alterDeferrability = true;
2834 260 : if ($4 & CAS_NO_INHERIT)
2835 20 : c->alterInheritability = true;
2836 : /* handle unsupported case with specific error message */
2837 260 : if ($4 & CAS_NOT_VALID)
2838 8 : ereport(ERROR,
2839 : errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
2840 : errmsg("constraints cannot be altered to be NOT VALID"),
2841 : parser_errposition(@4));
2842 252 : processCASbits($4, @4, "FOREIGN KEY",
2843 : &c->deferrable,
2844 : &c->initdeferred,
2845 : &c->is_enforced,
2846 : NULL,
2847 : &c->noinherit,
2848 : yyscanner);
2849 252 : $$ = (Node *) n;
2850 : }
2851 : /* ALTER TABLE <name> ALTER CONSTRAINT INHERIT */
2852 : | ALTER CONSTRAINT name INHERIT
2853 : {
2854 44 : AlterTableCmd *n = makeNode(AlterTableCmd);
2855 44 : ATAlterConstraint *c = makeNode(ATAlterConstraint);
2856 :
2857 44 : n->subtype = AT_AlterConstraint;
2858 44 : n->def = (Node *) c;
2859 44 : c->conname = $3;
2860 44 : c->alterInheritability = true;
2861 44 : c->noinherit = false;
2862 :
2863 44 : $$ = (Node *) n;
2864 : }
2865 : /* ALTER TABLE <name> VALIDATE CONSTRAINT ... */
2866 : | VALIDATE CONSTRAINT name
2867 : {
2868 275 : AlterTableCmd *n = makeNode(AlterTableCmd);
2869 :
2870 275 : n->subtype = AT_ValidateConstraint;
2871 275 : n->name = $3;
2872 275 : $$ = (Node *) n;
2873 : }
2874 : /* ALTER TABLE <name> DROP CONSTRAINT IF EXISTS <name> [RESTRICT|CASCADE] */
2875 : | DROP CONSTRAINT IF_P EXISTS name opt_drop_behavior
2876 : {
2877 12 : AlterTableCmd *n = makeNode(AlterTableCmd);
2878 :
2879 12 : n->subtype = AT_DropConstraint;
2880 12 : n->name = $5;
2881 12 : n->behavior = $6;
2882 12 : n->missing_ok = true;
2883 12 : $$ = (Node *) n;
2884 : }
2885 : /* ALTER TABLE <name> DROP CONSTRAINT <name> [RESTRICT|CASCADE] */
2886 : | DROP CONSTRAINT name opt_drop_behavior
2887 : {
2888 577 : AlterTableCmd *n = makeNode(AlterTableCmd);
2889 :
2890 577 : n->subtype = AT_DropConstraint;
2891 577 : n->name = $3;
2892 577 : n->behavior = $4;
2893 577 : n->missing_ok = false;
2894 577 : $$ = (Node *) n;
2895 : }
2896 : /* ALTER TABLE <name> SET WITHOUT OIDS, for backward compat */
2897 : | SET WITHOUT OIDS
2898 : {
2899 4 : AlterTableCmd *n = makeNode(AlterTableCmd);
2900 :
2901 4 : n->subtype = AT_DropOids;
2902 4 : $$ = (Node *) n;
2903 : }
2904 : /* ALTER TABLE <name> CLUSTER ON <indexname> */
2905 : | CLUSTER ON name
2906 : {
2907 31 : AlterTableCmd *n = makeNode(AlterTableCmd);
2908 :
2909 31 : n->subtype = AT_ClusterOn;
2910 31 : n->name = $3;
2911 31 : $$ = (Node *) n;
2912 : }
2913 : /* ALTER TABLE <name> SET WITHOUT CLUSTER */
2914 : | SET WITHOUT CLUSTER
2915 : {
2916 12 : AlterTableCmd *n = makeNode(AlterTableCmd);
2917 :
2918 12 : n->subtype = AT_DropCluster;
2919 12 : n->name = NULL;
2920 12 : $$ = (Node *) n;
2921 : }
2922 : /* ALTER TABLE <name> SET LOGGED */
2923 : | SET LOGGED
2924 : {
2925 33 : AlterTableCmd *n = makeNode(AlterTableCmd);
2926 :
2927 33 : n->subtype = AT_SetLogged;
2928 33 : $$ = (Node *) n;
2929 : }
2930 : /* ALTER TABLE <name> SET UNLOGGED */
2931 : | SET UNLOGGED
2932 : {
2933 41 : AlterTableCmd *n = makeNode(AlterTableCmd);
2934 :
2935 41 : n->subtype = AT_SetUnLogged;
2936 41 : $$ = (Node *) n;
2937 : }
2938 : /* ALTER TABLE <name> ENABLE TRIGGER <trig> */
2939 : | ENABLE_P TRIGGER name
2940 : {
2941 65 : AlterTableCmd *n = makeNode(AlterTableCmd);
2942 :
2943 65 : n->subtype = AT_EnableTrig;
2944 65 : n->name = $3;
2945 65 : $$ = (Node *) n;
2946 : }
2947 : /* ALTER TABLE <name> ENABLE ALWAYS TRIGGER <trig> */
2948 : | ENABLE_P ALWAYS TRIGGER name
2949 : {
2950 27 : AlterTableCmd *n = makeNode(AlterTableCmd);
2951 :
2952 27 : n->subtype = AT_EnableAlwaysTrig;
2953 27 : n->name = $4;
2954 27 : $$ = (Node *) n;
2955 : }
2956 : /* ALTER TABLE <name> ENABLE REPLICA TRIGGER <trig> */
2957 : | ENABLE_P REPLICA TRIGGER name
2958 : {
2959 8 : AlterTableCmd *n = makeNode(AlterTableCmd);
2960 :
2961 8 : n->subtype = AT_EnableReplicaTrig;
2962 8 : n->name = $4;
2963 8 : $$ = (Node *) n;
2964 : }
2965 : /* ALTER TABLE <name> ENABLE TRIGGER ALL */
2966 : | ENABLE_P TRIGGER ALL
2967 : {
2968 0 : AlterTableCmd *n = makeNode(AlterTableCmd);
2969 :
2970 0 : n->subtype = AT_EnableTrigAll;
2971 0 : $$ = (Node *) n;
2972 : }
2973 : /* ALTER TABLE <name> ENABLE TRIGGER USER */
2974 : | ENABLE_P TRIGGER USER
2975 : {
2976 0 : AlterTableCmd *n = makeNode(AlterTableCmd);
2977 :
2978 0 : n->subtype = AT_EnableTrigUser;
2979 0 : $$ = (Node *) n;
2980 : }
2981 : /* ALTER TABLE <name> DISABLE TRIGGER <trig> */
2982 : | DISABLE_P TRIGGER name
2983 : {
2984 75 : AlterTableCmd *n = makeNode(AlterTableCmd);
2985 :
2986 75 : n->subtype = AT_DisableTrig;
2987 75 : n->name = $3;
2988 75 : $$ = (Node *) n;
2989 : }
2990 : /* ALTER TABLE <name> DISABLE TRIGGER ALL */
2991 : | DISABLE_P TRIGGER ALL
2992 : {
2993 8 : AlterTableCmd *n = makeNode(AlterTableCmd);
2994 :
2995 8 : n->subtype = AT_DisableTrigAll;
2996 8 : $$ = (Node *) n;
2997 : }
2998 : /* ALTER TABLE <name> DISABLE TRIGGER USER */
2999 : | DISABLE_P TRIGGER USER
3000 : {
3001 8 : AlterTableCmd *n = makeNode(AlterTableCmd);
3002 :
3003 8 : n->subtype = AT_DisableTrigUser;
3004 8 : $$ = (Node *) n;
3005 : }
3006 : /* ALTER TABLE <name> ENABLE RULE <rule> */
3007 : | ENABLE_P RULE name
3008 : {
3009 5 : AlterTableCmd *n = makeNode(AlterTableCmd);
3010 :
3011 5 : n->subtype = AT_EnableRule;
3012 5 : n->name = $3;
3013 5 : $$ = (Node *) n;
3014 : }
3015 : /* ALTER TABLE <name> ENABLE ALWAYS RULE <rule> */
3016 : | ENABLE_P ALWAYS RULE name
3017 : {
3018 0 : AlterTableCmd *n = makeNode(AlterTableCmd);
3019 :
3020 0 : n->subtype = AT_EnableAlwaysRule;
3021 0 : n->name = $4;
3022 0 : $$ = (Node *) n;
3023 : }
3024 : /* ALTER TABLE <name> ENABLE REPLICA RULE <rule> */
3025 : | ENABLE_P REPLICA RULE name
3026 : {
3027 4 : AlterTableCmd *n = makeNode(AlterTableCmd);
3028 :
3029 4 : n->subtype = AT_EnableReplicaRule;
3030 4 : n->name = $4;
3031 4 : $$ = (Node *) n;
3032 : }
3033 : /* ALTER TABLE <name> DISABLE RULE <rule> */
3034 : | DISABLE_P RULE name
3035 : {
3036 20 : AlterTableCmd *n = makeNode(AlterTableCmd);
3037 :
3038 20 : n->subtype = AT_DisableRule;
3039 20 : n->name = $3;
3040 20 : $$ = (Node *) n;
3041 : }
3042 : /* ALTER TABLE <name> INHERIT <parent> */
3043 : | INHERIT qualified_name
3044 : {
3045 305 : AlterTableCmd *n = makeNode(AlterTableCmd);
3046 :
3047 305 : n->subtype = AT_AddInherit;
3048 305 : n->def = (Node *) $2;
3049 305 : $$ = (Node *) n;
3050 : }
3051 : /* ALTER TABLE <name> NO INHERIT <parent> */
3052 : | NO INHERIT qualified_name
3053 : {
3054 81 : AlterTableCmd *n = makeNode(AlterTableCmd);
3055 :
3056 81 : n->subtype = AT_DropInherit;
3057 81 : n->def = (Node *) $3;
3058 81 : $$ = (Node *) n;
3059 : }
3060 : /* ALTER TABLE <name> OF <type_name> */
3061 : | OF any_name
3062 : {
3063 42 : AlterTableCmd *n = makeNode(AlterTableCmd);
3064 42 : TypeName *def = makeTypeNameFromNameList($2);
3065 :
3066 42 : def->location = @2;
3067 42 : n->subtype = AT_AddOf;
3068 42 : n->def = (Node *) def;
3069 42 : $$ = (Node *) n;
3070 : }
3071 : /* ALTER TABLE <name> NOT OF */
3072 : | NOT OF
3073 : {
3074 4 : AlterTableCmd *n = makeNode(AlterTableCmd);
3075 :
3076 4 : n->subtype = AT_DropOf;
3077 4 : $$ = (Node *) n;
3078 : }
3079 : /* ALTER TABLE <name> OWNER TO RoleSpec */
3080 : | OWNER TO RoleSpec
3081 : {
3082 1155 : AlterTableCmd *n = makeNode(AlterTableCmd);
3083 :
3084 1155 : n->subtype = AT_ChangeOwner;
3085 1155 : n->newowner = $3;
3086 1155 : $$ = (Node *) n;
3087 : }
3088 : /* ALTER TABLE <name> SET ACCESS METHOD { <amname> | DEFAULT } */
3089 : | SET ACCESS METHOD set_access_method_name
3090 : {
3091 85 : AlterTableCmd *n = makeNode(AlterTableCmd);
3092 :
3093 85 : n->subtype = AT_SetAccessMethod;
3094 85 : n->name = $4;
3095 85 : $$ = (Node *) n;
3096 : }
3097 : /* ALTER TABLE <name> SET TABLESPACE <tablespacename> */
3098 : | SET TABLESPACE name
3099 : {
3100 71 : AlterTableCmd *n = makeNode(AlterTableCmd);
3101 :
3102 71 : n->subtype = AT_SetTableSpace;
3103 71 : n->name = $3;
3104 71 : $$ = (Node *) n;
3105 : }
3106 : /* ALTER TABLE <name> SET (...) */
3107 : | SET reloptions
3108 : {
3109 385 : AlterTableCmd *n = makeNode(AlterTableCmd);
3110 :
3111 385 : n->subtype = AT_SetRelOptions;
3112 385 : n->def = (Node *) $2;
3113 385 : $$ = (Node *) n;
3114 : }
3115 : /* ALTER TABLE <name> RESET (...) */
3116 : | RESET reloptions
3117 : {
3118 111 : AlterTableCmd *n = makeNode(AlterTableCmd);
3119 :
3120 111 : n->subtype = AT_ResetRelOptions;
3121 111 : n->def = (Node *) $2;
3122 111 : $$ = (Node *) n;
3123 : }
3124 : /* ALTER TABLE <name> REPLICA IDENTITY */
3125 : | REPLICA IDENTITY_P replica_identity
3126 : {
3127 301 : AlterTableCmd *n = makeNode(AlterTableCmd);
3128 :
3129 301 : n->subtype = AT_ReplicaIdentity;
3130 301 : n->def = $3;
3131 301 : $$ = (Node *) n;
3132 : }
3133 : /* ALTER TABLE <name> ENABLE ROW LEVEL SECURITY */
3134 : | ENABLE_P ROW LEVEL SECURITY
3135 : {
3136 240 : AlterTableCmd *n = makeNode(AlterTableCmd);
3137 :
3138 240 : n->subtype = AT_EnableRowSecurity;
3139 240 : $$ = (Node *) n;
3140 : }
3141 : /* ALTER TABLE <name> DISABLE ROW LEVEL SECURITY */
3142 : | DISABLE_P ROW LEVEL SECURITY
3143 : {
3144 6 : AlterTableCmd *n = makeNode(AlterTableCmd);
3145 :
3146 6 : n->subtype = AT_DisableRowSecurity;
3147 6 : $$ = (Node *) n;
3148 : }
3149 : /* ALTER TABLE <name> FORCE ROW LEVEL SECURITY */
3150 : | FORCE ROW LEVEL SECURITY
3151 : {
3152 70 : AlterTableCmd *n = makeNode(AlterTableCmd);
3153 :
3154 70 : n->subtype = AT_ForceRowSecurity;
3155 70 : $$ = (Node *) n;
3156 : }
3157 : /* ALTER TABLE <name> NO FORCE ROW LEVEL SECURITY */
3158 : | NO FORCE ROW LEVEL SECURITY
3159 : {
3160 20 : AlterTableCmd *n = makeNode(AlterTableCmd);
3161 :
3162 20 : n->subtype = AT_NoForceRowSecurity;
3163 20 : $$ = (Node *) n;
3164 : }
3165 : | alter_generic_options
3166 : {
3167 35 : AlterTableCmd *n = makeNode(AlterTableCmd);
3168 :
3169 35 : n->subtype = AT_GenericOptions;
3170 35 : n->def = (Node *) $1;
3171 35 : $$ = (Node *) n;
3172 : }
3173 : ;
3174 :
3175 : alter_column_default:
3176 246 : SET DEFAULT a_expr { $$ = $3; }
3177 124 : | DROP DEFAULT { $$ = NULL; }
3178 : ;
3179 :
3180 : opt_collate_clause:
3181 : COLLATE any_name
3182 : {
3183 12 : CollateClause *n = makeNode(CollateClause);
3184 :
3185 12 : n->arg = NULL;
3186 12 : n->collname = $2;
3187 12 : n->location = @1;
3188 12 : $$ = (Node *) n;
3189 : }
3190 3073 : | /* EMPTY */ { $$ = NULL; }
3191 : ;
3192 :
3193 : alter_using:
3194 119 : USING a_expr { $$ = $2; }
3195 638 : | /* EMPTY */ { $$ = NULL; }
3196 : ;
3197 :
3198 : replica_identity:
3199 : NOTHING
3200 : {
3201 29 : ReplicaIdentityStmt *n = makeNode(ReplicaIdentityStmt);
3202 :
3203 29 : n->identity_type = REPLICA_IDENTITY_NOTHING;
3204 29 : n->name = NULL;
3205 29 : $$ = (Node *) n;
3206 : }
3207 : | FULL
3208 : {
3209 98 : ReplicaIdentityStmt *n = makeNode(ReplicaIdentityStmt);
3210 :
3211 98 : n->identity_type = REPLICA_IDENTITY_FULL;
3212 98 : n->name = NULL;
3213 98 : $$ = (Node *) n;
3214 : }
3215 : | DEFAULT
3216 : {
3217 4 : ReplicaIdentityStmt *n = makeNode(ReplicaIdentityStmt);
3218 :
3219 4 : n->identity_type = REPLICA_IDENTITY_DEFAULT;
3220 4 : n->name = NULL;
3221 4 : $$ = (Node *) n;
3222 : }
3223 : | USING INDEX name
3224 : {
3225 170 : ReplicaIdentityStmt *n = makeNode(ReplicaIdentityStmt);
3226 :
3227 170 : n->identity_type = REPLICA_IDENTITY_INDEX;
3228 170 : n->name = $3;
3229 170 : $$ = (Node *) n;
3230 : }
3231 : ;
3232 :
3233 : reloptions:
3234 1812 : '(' reloption_list ')' { $$ = $2; }
3235 : ;
3236 :
3237 595 : opt_reloptions: WITH reloptions { $$ = $2; }
3238 15208 : | /* EMPTY */ { $$ = NIL; }
3239 : ;
3240 :
3241 : reloption_list:
3242 1812 : reloption_elem { $$ = list_make1($1); }
3243 172 : | reloption_list ',' reloption_elem { $$ = lappend($1, $3); }
3244 : ;
3245 :
3246 : /* This should match def_elem and also allow qualified names */
3247 : reloption_elem:
3248 : ColLabel '=' def_arg
3249 : {
3250 1569 : $$ = makeDefElem($1, (Node *) $3, @1);
3251 : }
3252 : | ColLabel
3253 : {
3254 365 : $$ = makeDefElem($1, NULL, @1);
3255 : }
3256 : | ColLabel '.' ColLabel '=' def_arg
3257 : {
3258 46 : $$ = makeDefElemExtended($1, $3, (Node *) $5,
3259 46 : DEFELEM_UNSPEC, @1);
3260 : }
3261 : | ColLabel '.' ColLabel
3262 : {
3263 4 : $$ = makeDefElemExtended($1, $3, NULL, DEFELEM_UNSPEC, @1);
3264 : }
3265 : ;
3266 :
3267 : alter_identity_column_option_list:
3268 : alter_identity_column_option
3269 41 : { $$ = list_make1($1); }
3270 : | alter_identity_column_option_list alter_identity_column_option
3271 40 : { $$ = lappend($1, $2); }
3272 : ;
3273 :
3274 : alter_identity_column_option:
3275 : RESTART
3276 : {
3277 16 : $$ = makeDefElem("restart", NULL, @1);
3278 : }
3279 : | RESTART opt_with NumericOnly
3280 : {
3281 0 : $$ = makeDefElem("restart", (Node *) $3, @1);
3282 : }
3283 : | SET SeqOptElem
3284 : {
3285 36 : if (strcmp($2->defname, "as") == 0 ||
3286 36 : strcmp($2->defname, "restart") == 0 ||
3287 36 : strcmp($2->defname, "owned_by") == 0)
3288 0 : ereport(ERROR,
3289 : (errcode(ERRCODE_SYNTAX_ERROR),
3290 : errmsg("sequence option \"%s\" not supported here", $2->defname),
3291 : parser_errposition(@2)));
3292 36 : $$ = $2;
3293 : }
3294 : | SET GENERATED generated_when
3295 : {
3296 29 : $$ = makeDefElem("generated", (Node *) makeInteger($3), @1);
3297 : }
3298 : ;
3299 :
3300 : set_statistics_value:
3301 103 : SignedIconst { $$ = (Node *) makeInteger($1); }
3302 0 : | DEFAULT { $$ = NULL; }
3303 : ;
3304 :
3305 : set_access_method_name:
3306 61 : ColId { $$ = $1; }
3307 24 : | DEFAULT { $$ = NULL; }
3308 : ;
3309 :
3310 : PartitionBoundSpec:
3311 : /* a HASH partition */
3312 : FOR VALUES WITH '(' hash_partbound ')'
3313 : {
3314 : ListCell *lc;
3315 500 : PartitionBoundSpec *n = makeNode(PartitionBoundSpec);
3316 :
3317 500 : n->strategy = PARTITION_STRATEGY_HASH;
3318 500 : n->modulus = n->remainder = -1;
3319 :
3320 1500 : foreach (lc, $5)
3321 : {
3322 1000 : DefElem *opt = lfirst_node(DefElem, lc);
3323 :
3324 1000 : if (strcmp(opt->defname, "modulus") == 0)
3325 : {
3326 500 : if (n->modulus != -1)
3327 0 : ereport(ERROR,
3328 : (errcode(ERRCODE_DUPLICATE_OBJECT),
3329 : errmsg("modulus for hash partition provided more than once"),
3330 : parser_errposition(opt->location)));
3331 500 : n->modulus = defGetInt32(opt);
3332 : }
3333 500 : else if (strcmp(opt->defname, "remainder") == 0)
3334 : {
3335 500 : if (n->remainder != -1)
3336 0 : ereport(ERROR,
3337 : (errcode(ERRCODE_DUPLICATE_OBJECT),
3338 : errmsg("remainder for hash partition provided more than once"),
3339 : parser_errposition(opt->location)));
3340 500 : n->remainder = defGetInt32(opt);
3341 : }
3342 : else
3343 0 : ereport(ERROR,
3344 : (errcode(ERRCODE_SYNTAX_ERROR),
3345 : errmsg("unrecognized hash partition bound specification \"%s\"",
3346 : opt->defname),
3347 : parser_errposition(opt->location)));
3348 : }
3349 :
3350 500 : if (n->modulus == -1)
3351 0 : ereport(ERROR,
3352 : (errcode(ERRCODE_SYNTAX_ERROR),
3353 : errmsg("modulus for hash partition must be specified"),
3354 : parser_errposition(@3)));
3355 500 : if (n->remainder == -1)
3356 0 : ereport(ERROR,
3357 : (errcode(ERRCODE_SYNTAX_ERROR),
3358 : errmsg("remainder for hash partition must be specified"),
3359 : parser_errposition(@3)));
3360 :
3361 500 : n->location = @3;
3362 :
3363 500 : $$ = n;
3364 : }
3365 :
3366 : /* a LIST partition */
3367 : | FOR VALUES IN_P '(' expr_list ')'
3368 : {
3369 3322 : PartitionBoundSpec *n = makeNode(PartitionBoundSpec);
3370 :
3371 3322 : n->strategy = PARTITION_STRATEGY_LIST;
3372 3322 : n->is_default = false;
3373 3322 : n->listdatums = $5;
3374 3322 : n->location = @3;
3375 :
3376 3322 : $$ = n;
3377 : }
3378 :
3379 : /* a RANGE partition */
3380 : | FOR VALUES FROM '(' expr_list ')' TO '(' expr_list ')'
3381 : {
3382 4425 : PartitionBoundSpec *n = makeNode(PartitionBoundSpec);
3383 :
3384 4425 : n->strategy = PARTITION_STRATEGY_RANGE;
3385 4425 : n->is_default = false;
3386 4425 : n->lowerdatums = $5;
3387 4425 : n->upperdatums = $9;
3388 4425 : n->location = @3;
3389 :
3390 4425 : $$ = n;
3391 : }
3392 :
3393 : /* a DEFAULT partition */
3394 : | DEFAULT
3395 : {
3396 548 : PartitionBoundSpec *n = makeNode(PartitionBoundSpec);
3397 :
3398 548 : n->is_default = true;
3399 548 : n->location = @1;
3400 :
3401 548 : $$ = n;
3402 : }
3403 : ;
3404 :
3405 : hash_partbound_elem:
3406 : NonReservedWord Iconst
3407 : {
3408 1000 : $$ = makeDefElem($1, (Node *) makeInteger($2), @1);
3409 : }
3410 : ;
3411 :
3412 : hash_partbound:
3413 : hash_partbound_elem
3414 : {
3415 500 : $$ = list_make1($1);
3416 : }
3417 : | hash_partbound ',' hash_partbound_elem
3418 : {
3419 500 : $$ = lappend($1, $3);
3420 : }
3421 : ;
3422 :
3423 : /*****************************************************************************
3424 : *
3425 : * ALTER TYPE
3426 : *
3427 : * really variants of the ALTER TABLE subcommands with different spellings
3428 : *****************************************************************************/
3429 :
3430 : AlterCompositeTypeStmt:
3431 : ALTER TYPE_P any_name alter_type_cmds
3432 : {
3433 137 : AlterTableStmt *n = makeNode(AlterTableStmt);
3434 :
3435 : /* can't use qualified_name, sigh */
3436 137 : n->relation = makeRangeVarFromAnyName($3, @3, yyscanner);
3437 137 : n->cmds = $4;
3438 137 : n->objtype = OBJECT_TYPE;
3439 137 : $$ = (Node *) n;
3440 : }
3441 : ;
3442 :
3443 : alter_type_cmds:
3444 137 : alter_type_cmd { $$ = list_make1($1); }
3445 8 : | alter_type_cmds ',' alter_type_cmd { $$ = lappend($1, $3); }
3446 : ;
3447 :
3448 : alter_type_cmd:
3449 : /* ALTER TYPE <name> ADD ATTRIBUTE <coldef> [RESTRICT|CASCADE] */
3450 : ADD_P ATTRIBUTE TableFuncElement opt_drop_behavior
3451 : {
3452 42 : AlterTableCmd *n = makeNode(AlterTableCmd);
3453 :
3454 42 : n->subtype = AT_AddColumn;
3455 42 : n->def = $3;
3456 42 : n->behavior = $4;
3457 42 : $$ = (Node *) n;
3458 : }
3459 : /* ALTER TYPE <name> DROP ATTRIBUTE IF EXISTS <attname> [RESTRICT|CASCADE] */
3460 : | DROP ATTRIBUTE IF_P EXISTS ColId opt_drop_behavior
3461 : {
3462 4 : AlterTableCmd *n = makeNode(AlterTableCmd);
3463 :
3464 4 : n->subtype = AT_DropColumn;
3465 4 : n->name = $5;
3466 4 : n->behavior = $6;
3467 4 : n->missing_ok = true;
3468 4 : $$ = (Node *) n;
3469 : }
3470 : /* ALTER TYPE <name> DROP ATTRIBUTE <attname> [RESTRICT|CASCADE] */
3471 : | DROP ATTRIBUTE ColId opt_drop_behavior
3472 : {
3473 50 : AlterTableCmd *n = makeNode(AlterTableCmd);
3474 :
3475 50 : n->subtype = AT_DropColumn;
3476 50 : n->name = $3;
3477 50 : n->behavior = $4;
3478 50 : n->missing_ok = false;
3479 50 : $$ = (Node *) n;
3480 : }
3481 : /* ALTER TYPE <name> ALTER ATTRIBUTE <attname> [SET DATA] TYPE <typename> [RESTRICT|CASCADE] */
3482 : | ALTER ATTRIBUTE ColId opt_set_data TYPE_P Typename opt_collate_clause opt_drop_behavior
3483 : {
3484 49 : AlterTableCmd *n = makeNode(AlterTableCmd);
3485 49 : ColumnDef *def = makeNode(ColumnDef);
3486 :
3487 49 : n->subtype = AT_AlterColumnType;
3488 49 : n->name = $3;
3489 49 : n->def = (Node *) def;
3490 49 : n->behavior = $8;
3491 : /* We only use these fields of the ColumnDef node */
3492 49 : def->typeName = $6;
3493 49 : def->collClause = (CollateClause *) $7;
3494 49 : def->raw_default = NULL;
3495 49 : def->location = @3;
3496 49 : $$ = (Node *) n;
3497 : }
3498 : ;
3499 :
3500 :
3501 : /*****************************************************************************
3502 : *
3503 : * QUERY :
3504 : * close <portalname>
3505 : *
3506 : *****************************************************************************/
3507 :
3508 : ClosePortalStmt:
3509 : CLOSE cursor_name
3510 : {
3511 1165 : ClosePortalStmt *n = makeNode(ClosePortalStmt);
3512 :
3513 1165 : n->portalname = $2;
3514 1165 : $$ = (Node *) n;
3515 : }
3516 : | CLOSE ALL
3517 : {
3518 8 : ClosePortalStmt *n = makeNode(ClosePortalStmt);
3519 :
3520 8 : n->portalname = NULL;
3521 8 : $$ = (Node *) n;
3522 : }
3523 : ;
3524 :
3525 :
3526 : /*****************************************************************************
3527 : *
3528 : * QUERY :
3529 : * COPY relname [(columnList)] FROM/TO file [WITH] [(options)]
3530 : * COPY ( query ) TO file [WITH] [(options)]
3531 : *
3532 : * where 'query' can be one of:
3533 : * { SELECT | UPDATE | INSERT | DELETE | MERGE }
3534 : *
3535 : * and 'file' can be one of:
3536 : * { PROGRAM 'command' | STDIN | STDOUT | 'filename' }
3537 : *
3538 : * In the preferred syntax the options are comma-separated
3539 : * and use generic identifiers instead of keywords. The pre-9.0
3540 : * syntax had a hard-wired, space-separated set of options.
3541 : *
3542 : * Really old syntax, from versions 7.2 and prior:
3543 : * COPY [ BINARY ] table FROM/TO file
3544 : * [ [ USING ] DELIMITERS 'delimiter' ] ]
3545 : * [ WITH NULL AS 'null string' ]
3546 : * This option placement is not supported with COPY (query...).
3547 : *
3548 : *****************************************************************************/
3549 :
3550 : CopyStmt: COPY opt_binary qualified_name opt_column_list
3551 : copy_from opt_program copy_file_name copy_delimiter opt_with
3552 : copy_options where_clause
3553 : {
3554 6370 : CopyStmt *n = makeNode(CopyStmt);
3555 :
3556 6370 : n->relation = $3;
3557 6370 : n->query = NULL;
3558 6370 : n->attlist = $4;
3559 6370 : n->is_from = $5;
3560 6370 : n->is_program = $6;
3561 6370 : n->filename = $7;
3562 6370 : n->whereClause = $11;
3563 :
3564 6370 : if (n->is_program && n->filename == NULL)
3565 0 : ereport(ERROR,
3566 : (errcode(ERRCODE_SYNTAX_ERROR),
3567 : errmsg("STDIN/STDOUT not allowed with PROGRAM"),
3568 : parser_errposition(@8)));
3569 :
3570 6370 : if (!n->is_from && n->whereClause != NULL)
3571 4 : ereport(ERROR,
3572 : (errcode(ERRCODE_SYNTAX_ERROR),
3573 : errmsg("WHERE clause not allowed with COPY TO"),
3574 : errhint("Try the COPY (SELECT ... WHERE ...) TO variant."),
3575 : parser_errposition(@11)));
3576 :
3577 6366 : n->options = NIL;
3578 : /* Concatenate user-supplied flags */
3579 6366 : if ($2)
3580 8 : n->options = lappend(n->options, $2);
3581 6366 : if ($8)
3582 0 : n->options = lappend(n->options, $8);
3583 6366 : if ($10)
3584 836 : n->options = list_concat(n->options, $10);
3585 6366 : $$ = (Node *) n;
3586 : }
3587 : | COPY '(' PreparableStmt ')' TO opt_program copy_file_name opt_with copy_options
3588 : {
3589 355 : CopyStmt *n = makeNode(CopyStmt);
3590 :
3591 355 : n->relation = NULL;
3592 355 : n->query = $3;
3593 355 : n->attlist = NIL;
3594 355 : n->is_from = false;
3595 355 : n->is_program = $6;
3596 355 : n->filename = $7;
3597 355 : n->options = $9;
3598 :
3599 355 : if (n->is_program && n->filename == NULL)
3600 0 : ereport(ERROR,
3601 : (errcode(ERRCODE_SYNTAX_ERROR),
3602 : errmsg("STDIN/STDOUT not allowed with PROGRAM"),
3603 : parser_errposition(@5)));
3604 :
3605 355 : $$ = (Node *) n;
3606 : }
3607 : ;
3608 :
3609 : copy_from:
3610 1233 : FROM { $$ = true; }
3611 5137 : | TO { $$ = false; }
3612 : ;
3613 :
3614 : opt_program:
3615 0 : PROGRAM { $$ = true; }
3616 6725 : | /* EMPTY */ { $$ = false; }
3617 : ;
3618 :
3619 : /*
3620 : * copy_file_name NULL indicates stdio is used. Whether stdin or stdout is
3621 : * used depends on the direction. (It really doesn't make sense to copy from
3622 : * stdout. We silently correct the "typo".) - AY 9/94
3623 : */
3624 : copy_file_name:
3625 306 : Sconst { $$ = $1; }
3626 977 : | STDIN { $$ = NULL; }
3627 5442 : | STDOUT { $$ = NULL; }
3628 : ;
3629 :
3630 6040 : copy_options: copy_opt_list { $$ = $1; }
3631 685 : | '(' copy_generic_opt_list ')' { $$ = $2; }
3632 : ;
3633 :
3634 : /* old COPY option syntax */
3635 : copy_opt_list:
3636 343 : copy_opt_list copy_opt_item { $$ = lappend($1, $2); }
3637 6040 : | /* EMPTY */ { $$ = NIL; }
3638 : ;
3639 :
3640 : copy_opt_item:
3641 : BINARY
3642 : {
3643 0 : $$ = makeDefElem("format", (Node *) makeString("binary"), @1);
3644 : }
3645 : | FREEZE
3646 : {
3647 32 : $$ = makeDefElem("freeze", (Node *) makeBoolean(true), @1);
3648 : }
3649 : | DELIMITER opt_as Sconst
3650 : {
3651 115 : $$ = makeDefElem("delimiter", (Node *) makeString($3), @1);
3652 : }
3653 : | NULL_P opt_as Sconst
3654 : {
3655 32 : $$ = makeDefElem("null", (Node *) makeString($3), @1);
3656 : }
3657 : | CSV
3658 : {
3659 100 : $$ = makeDefElem("format", (Node *) makeString("csv"), @1);
3660 : }
3661 : | JSON
3662 : {
3663 8 : $$ = makeDefElem("format", (Node *) makeString("json"), @1);
3664 : }
3665 : | HEADER_P
3666 : {
3667 12 : $$ = makeDefElem("header", (Node *) makeBoolean(true), @1);
3668 : }
3669 : | QUOTE opt_as Sconst
3670 : {
3671 12 : $$ = makeDefElem("quote", (Node *) makeString($3), @1);
3672 : }
3673 : | ESCAPE opt_as Sconst
3674 : {
3675 12 : $$ = makeDefElem("escape", (Node *) makeString($3), @1);
3676 : }
3677 : | FORCE QUOTE columnList
3678 : {
3679 8 : $$ = makeDefElem("force_quote", (Node *) $3, @1);
3680 : }
3681 : | FORCE QUOTE '*'
3682 : {
3683 4 : $$ = makeDefElem("force_quote", (Node *) makeNode(A_Star), @1);
3684 : }
3685 : | FORCE NOT NULL_P columnList
3686 : {
3687 0 : $$ = makeDefElem("force_not_null", (Node *) $4, @1);
3688 : }
3689 : | FORCE NOT NULL_P '*'
3690 : {
3691 0 : $$ = makeDefElem("force_not_null", (Node *) makeNode(A_Star), @1);
3692 : }
3693 : | FORCE NULL_P columnList
3694 : {
3695 0 : $$ = makeDefElem("force_null", (Node *) $3, @1);
3696 : }
3697 : | FORCE NULL_P '*'
3698 : {
3699 0 : $$ = makeDefElem("force_null", (Node *) makeNode(A_Star), @1);
3700 : }
3701 : | ENCODING Sconst
3702 : {
3703 8 : $$ = makeDefElem("encoding", (Node *) makeString($2), @1);
3704 : }
3705 : ;
3706 :
3707 : /* The following exist for backward compatibility with very old versions */
3708 :
3709 : opt_binary:
3710 : BINARY
3711 : {
3712 8 : $$ = makeDefElem("format", (Node *) makeString("binary"), @1);
3713 : }
3714 6362 : | /*EMPTY*/ { $$ = NULL; }
3715 : ;
3716 :
3717 : copy_delimiter:
3718 : opt_using DELIMITERS Sconst
3719 : {
3720 0 : $$ = makeDefElem("delimiter", (Node *) makeString($3), @2);
3721 : }
3722 6370 : | /*EMPTY*/ { $$ = NULL; }
3723 : ;
3724 :
3725 : opt_using:
3726 : USING
3727 : | /*EMPTY*/
3728 : ;
3729 :
3730 : /* new COPY option syntax */
3731 : copy_generic_opt_list:
3732 : copy_generic_opt_elem
3733 : {
3734 685 : $$ = list_make1($1);
3735 : }
3736 : | copy_generic_opt_list ',' copy_generic_opt_elem
3737 : {
3738 435 : $$ = lappend($1, $3);
3739 : }
3740 : ;
3741 :
3742 : copy_generic_opt_elem:
3743 : ColLabel copy_generic_opt_arg
3744 : {
3745 992 : $$ = makeDefElem($1, $2, @1);
3746 : }
3747 : | FORMAT_LA copy_generic_opt_arg
3748 : {
3749 128 : $$ = makeDefElem("format", $2, @1);
3750 : }
3751 : ;
3752 :
3753 : copy_generic_opt_arg:
3754 848 : opt_boolean_or_string { $$ = (Node *) makeString($1); }
3755 52 : | NumericOnly { $$ = (Node *) $1; }
3756 72 : | '*' { $$ = (Node *) makeNode(A_Star); }
3757 4 : | DEFAULT { $$ = (Node *) makeString("default"); }
3758 100 : | '(' copy_generic_opt_arg_list ')' { $$ = (Node *) $2; }
3759 44 : | /* EMPTY */ { $$ = NULL; }
3760 : ;
3761 :
3762 : copy_generic_opt_arg_list:
3763 : copy_generic_opt_arg_list_item
3764 : {
3765 100 : $$ = list_make1($1);
3766 : }
3767 : | copy_generic_opt_arg_list ',' copy_generic_opt_arg_list_item
3768 : {
3769 8 : $$ = lappend($1, $3);
3770 : }
3771 : ;
3772 :
3773 : /* beware of emitting non-string list elements here; see commands/define.c */
3774 : copy_generic_opt_arg_list_item:
3775 108 : opt_boolean_or_string { $$ = (Node *) makeString($1); }
3776 : ;
3777 :
3778 :
3779 : /*****************************************************************************
3780 : *
3781 : * QUERY :
3782 : * CREATE TABLE relname
3783 : *
3784 : *****************************************************************************/
3785 :
3786 : CreateStmt: CREATE OptTemp TABLE qualified_name '(' OptTableElementList ')'
3787 : OptInherit OptPartitionSpec table_access_method_clause OptWith
3788 : OnCommitOption OptTableSpace
3789 : {
3790 19538 : CreateStmt *n = makeNode(CreateStmt);
3791 :
3792 19538 : $4->relpersistence = $2;
3793 19538 : n->relation = $4;
3794 19538 : n->tableElts = $6;
3795 19538 : n->inhRelations = $8;
3796 19538 : n->partspec = $9;
3797 19538 : n->ofTypename = NULL;
3798 19538 : n->constraints = NIL;
3799 19538 : n->accessMethod = $10;
3800 19538 : n->options = $11;
3801 19538 : n->oncommit = $12;
3802 19538 : n->tablespacename = $13;
3803 19538 : n->if_not_exists = false;
3804 19538 : $$ = (Node *) n;
3805 : }
3806 : | CREATE OptTemp TABLE IF_P NOT EXISTS qualified_name '('
3807 : OptTableElementList ')' OptInherit OptPartitionSpec table_access_method_clause
3808 : OptWith OnCommitOption OptTableSpace
3809 : {
3810 16 : CreateStmt *n = makeNode(CreateStmt);
3811 :
3812 16 : $7->relpersistence = $2;
3813 16 : n->relation = $7;
3814 16 : n->tableElts = $9;
3815 16 : n->inhRelations = $11;
3816 16 : n->partspec = $12;
3817 16 : n->ofTypename = NULL;
3818 16 : n->constraints = NIL;
3819 16 : n->accessMethod = $13;
3820 16 : n->options = $14;
3821 16 : n->oncommit = $15;
3822 16 : n->tablespacename = $16;
3823 16 : n->if_not_exists = true;
3824 16 : $$ = (Node *) n;
3825 : }
3826 : | CREATE OptTemp TABLE qualified_name OF any_name
3827 : OptTypedTableElementList OptPartitionSpec table_access_method_clause
3828 : OptWith OnCommitOption OptTableSpace
3829 : {
3830 81 : CreateStmt *n = makeNode(CreateStmt);
3831 :
3832 81 : $4->relpersistence = $2;
3833 81 : n->relation = $4;
3834 81 : n->tableElts = $7;
3835 81 : n->inhRelations = NIL;
3836 81 : n->partspec = $8;
3837 81 : n->ofTypename = makeTypeNameFromNameList($6);
3838 81 : n->ofTypename->location = @6;
3839 81 : n->constraints = NIL;
3840 81 : n->accessMethod = $9;
3841 81 : n->options = $10;
3842 81 : n->oncommit = $11;
3843 81 : n->tablespacename = $12;
3844 81 : n->if_not_exists = false;
3845 81 : $$ = (Node *) n;
3846 : }
3847 : | CREATE OptTemp TABLE IF_P NOT EXISTS qualified_name OF any_name
3848 : OptTypedTableElementList OptPartitionSpec table_access_method_clause
3849 : OptWith OnCommitOption OptTableSpace
3850 : {
3851 4 : CreateStmt *n = makeNode(CreateStmt);
3852 :
3853 4 : $7->relpersistence = $2;
3854 4 : n->relation = $7;
3855 4 : n->tableElts = $10;
3856 4 : n->inhRelations = NIL;
3857 4 : n->partspec = $11;
3858 4 : n->ofTypename = makeTypeNameFromNameList($9);
3859 4 : n->ofTypename->location = @9;
3860 4 : n->constraints = NIL;
3861 4 : n->accessMethod = $12;
3862 4 : n->options = $13;
3863 4 : n->oncommit = $14;
3864 4 : n->tablespacename = $15;
3865 4 : n->if_not_exists = true;
3866 4 : $$ = (Node *) n;
3867 : }
3868 : | CREATE OptTemp TABLE qualified_name PARTITION OF qualified_name
3869 : OptTypedTableElementList PartitionBoundSpec OptPartitionSpec
3870 : table_access_method_clause OptWith OnCommitOption OptTableSpace
3871 : {
3872 6386 : CreateStmt *n = makeNode(CreateStmt);
3873 :
3874 6386 : $4->relpersistence = $2;
3875 6386 : n->relation = $4;
3876 6386 : n->tableElts = $8;
3877 6386 : n->inhRelations = list_make1($7);
3878 6386 : n->partbound = $9;
3879 6386 : n->partspec = $10;
3880 6386 : n->ofTypename = NULL;
3881 6386 : n->constraints = NIL;
3882 6386 : n->accessMethod = $11;
3883 6386 : n->options = $12;
3884 6386 : n->oncommit = $13;
3885 6386 : n->tablespacename = $14;
3886 6386 : n->if_not_exists = false;
3887 6386 : $$ = (Node *) n;
3888 : }
3889 : | CREATE OptTemp TABLE IF_P NOT EXISTS qualified_name PARTITION OF
3890 : qualified_name OptTypedTableElementList PartitionBoundSpec OptPartitionSpec
3891 : table_access_method_clause OptWith OnCommitOption OptTableSpace
3892 : {
3893 0 : CreateStmt *n = makeNode(CreateStmt);
3894 :
3895 0 : $7->relpersistence = $2;
3896 0 : n->relation = $7;
3897 0 : n->tableElts = $11;
3898 0 : n->inhRelations = list_make1($10);
3899 0 : n->partbound = $12;
3900 0 : n->partspec = $13;
3901 0 : n->ofTypename = NULL;
3902 0 : n->constraints = NIL;
3903 0 : n->accessMethod = $14;
3904 0 : n->options = $15;
3905 0 : n->oncommit = $16;
3906 0 : n->tablespacename = $17;
3907 0 : n->if_not_exists = true;
3908 0 : $$ = (Node *) n;
3909 : }
3910 : ;
3911 :
3912 : /*
3913 : * Redundancy here is needed to avoid shift/reduce conflicts,
3914 : * since TEMP is not a reserved word. See also OptTempTableName.
3915 : *
3916 : * NOTE: we accept both GLOBAL and LOCAL options. They currently do nothing,
3917 : * but future versions might consider GLOBAL to request SQL-spec-compliant
3918 : * temp table behavior, so warn about that. Since we have no modules the
3919 : * LOCAL keyword is really meaningless; furthermore, some other products
3920 : * implement LOCAL as meaning the same as our default temp table behavior,
3921 : * so we'll probably continue to treat LOCAL as a noise word.
3922 : */
3923 234 : OptTemp: TEMPORARY { $$ = RELPERSISTENCE_TEMP; }
3924 1980 : | TEMP { $$ = RELPERSISTENCE_TEMP; }
3925 0 : | LOCAL TEMPORARY { $$ = RELPERSISTENCE_TEMP; }
3926 0 : | LOCAL TEMP { $$ = RELPERSISTENCE_TEMP; }
3927 : | GLOBAL TEMPORARY
3928 : {
3929 0 : ereport(WARNING,
3930 : (errmsg("GLOBAL is deprecated in temporary table creation"),
3931 : parser_errposition(@1)));
3932 0 : $$ = RELPERSISTENCE_TEMP;
3933 : }
3934 : | GLOBAL TEMP
3935 : {
3936 0 : ereport(WARNING,
3937 : (errmsg("GLOBAL is deprecated in temporary table creation"),
3938 : parser_errposition(@1)));
3939 0 : $$ = RELPERSISTENCE_TEMP;
3940 : }
3941 113 : | UNLOGGED { $$ = RELPERSISTENCE_UNLOGGED; }
3942 36247 : | /*EMPTY*/ { $$ = RELPERSISTENCE_PERMANENT; }
3943 : ;
3944 :
3945 : OptTableElementList:
3946 18789 : TableElementList { $$ = $1; }
3947 1035 : | /*EMPTY*/ { $$ = NIL; }
3948 : ;
3949 :
3950 : OptTypedTableElementList:
3951 217 : '(' TypedTableElementList ')' { $$ = $2; }
3952 6311 : | /*EMPTY*/ { $$ = NIL; }
3953 : ;
3954 :
3955 : TableElementList:
3956 : TableElement
3957 : {
3958 18825 : $$ = list_make1($1);
3959 : }
3960 : | TableElementList ',' TableElement
3961 : {
3962 26938 : $$ = lappend($1, $3);
3963 : }
3964 : ;
3965 :
3966 : TypedTableElementList:
3967 : TypedTableElement
3968 : {
3969 217 : $$ = list_make1($1);
3970 : }
3971 : | TypedTableElementList ',' TypedTableElement
3972 : {
3973 45 : $$ = lappend($1, $3);
3974 : }
3975 : ;
3976 :
3977 : TableElement:
3978 43265 : columnDef { $$ = $1; }
3979 516 : | TableLikeClause { $$ = $1; }
3980 1982 : | TableConstraint { $$ = $1; }
3981 : ;
3982 :
3983 : TypedTableElement:
3984 220 : columnOptions { $$ = $1; }
3985 42 : | TableConstraint { $$ = $1; }
3986 : ;
3987 :
3988 : columnDef: ColId Typename opt_column_storage opt_column_compression create_generic_options ColQualList
3989 : {
3990 44859 : ColumnDef *n = makeNode(ColumnDef);
3991 :
3992 44859 : n->colname = $1;
3993 44859 : n->typeName = $2;
3994 44859 : n->storage_name = $3;
3995 44859 : n->compression = $4;
3996 44859 : n->inhcount = 0;
3997 44859 : n->is_local = true;
3998 44859 : n->is_not_null = false;
3999 44859 : n->is_from_type = false;
4000 44859 : n->storage = 0;
4001 44859 : n->raw_default = NULL;
4002 44859 : n->cooked_default = NULL;
4003 44859 : n->collOid = InvalidOid;
4004 44859 : n->fdwoptions = $5;
4005 44859 : SplitColQualList($6, &n->constraints, &n->collClause,
4006 : yyscanner);
4007 44859 : n->location = @1;
4008 44859 : $$ = (Node *) n;
4009 : }
4010 : ;
4011 :
4012 : columnOptions: ColId ColQualList
4013 : {
4014 91 : ColumnDef *n = makeNode(ColumnDef);
4015 :
4016 91 : n->colname = $1;
4017 91 : n->typeName = NULL;
4018 91 : n->inhcount = 0;
4019 91 : n->is_local = true;
4020 91 : n->is_not_null = false;
4021 91 : n->is_from_type = false;
4022 91 : n->storage = 0;
4023 91 : n->raw_default = NULL;
4024 91 : n->cooked_default = NULL;
4025 91 : n->collOid = InvalidOid;
4026 91 : SplitColQualList($2, &n->constraints, &n->collClause,
4027 : yyscanner);
4028 91 : n->location = @1;
4029 91 : $$ = (Node *) n;
4030 : }
4031 : | ColId WITH OPTIONS ColQualList
4032 : {
4033 129 : ColumnDef *n = makeNode(ColumnDef);
4034 :
4035 129 : n->colname = $1;
4036 129 : n->typeName = NULL;
4037 129 : n->inhcount = 0;
4038 129 : n->is_local = true;
4039 129 : n->is_not_null = false;
4040 129 : n->is_from_type = false;
4041 129 : n->storage = 0;
4042 129 : n->raw_default = NULL;
4043 129 : n->cooked_default = NULL;
4044 129 : n->collOid = InvalidOid;
4045 129 : SplitColQualList($4, &n->constraints, &n->collClause,
4046 : yyscanner);
4047 129 : n->location = @1;
4048 129 : $$ = (Node *) n;
4049 : }
4050 : ;
4051 :
4052 : column_compression:
4053 113 : COMPRESSION ColId { $$ = $2; }
4054 4 : | COMPRESSION DEFAULT { $$ = pstrdup("default"); }
4055 : ;
4056 :
4057 : opt_column_compression:
4058 70 : column_compression { $$ = $1; }
4059 44833 : | /*EMPTY*/ { $$ = NULL; }
4060 : ;
4061 :
4062 : column_storage:
4063 194 : STORAGE ColId { $$ = $2; }
4064 4 : | STORAGE DEFAULT { $$ = pstrdup("default"); }
4065 : ;
4066 :
4067 : opt_column_storage:
4068 39 : column_storage { $$ = $1; }
4069 44864 : | /*EMPTY*/ { $$ = NULL; }
4070 : ;
4071 :
4072 : ColQualList:
4073 13389 : ColQualList ColConstraint { $$ = lappend($1, $2); }
4074 46106 : | /*EMPTY*/ { $$ = NIL; }
4075 : ;
4076 :
4077 : ColConstraint:
4078 : CONSTRAINT name ColConstraintElem
4079 : {
4080 503 : Constraint *n = castNode(Constraint, $3);
4081 :
4082 503 : n->conname = $2;
4083 503 : n->location = @1;
4084 503 : $$ = (Node *) n;
4085 : }
4086 12125 : | ColConstraintElem { $$ = $1; }
4087 255 : | ConstraintAttr { $$ = $1; }
4088 : | COLLATE any_name
4089 : {
4090 : /*
4091 : * Note: the CollateClause is momentarily included in
4092 : * the list built by ColQualList, but we split it out
4093 : * again in SplitColQualList.
4094 : */
4095 506 : CollateClause *n = makeNode(CollateClause);
4096 :
4097 506 : n->arg = NULL;
4098 506 : n->collname = $2;
4099 506 : n->location = @1;
4100 506 : $$ = (Node *) n;
4101 : }
4102 : ;
4103 :
4104 : /* DEFAULT NULL is already the default for Postgres.
4105 : * But define it here and carry it forward into the system
4106 : * to make it explicit.
4107 : * - thomas 1998-09-13
4108 : *
4109 : * WITH NULL and NULL are not SQL-standard syntax elements,
4110 : * so leave them out. Use DEFAULT NULL to explicitly indicate
4111 : * that a column may have that value. WITH NULL leads to
4112 : * shift/reduce conflicts with WITH TIME ZONE anyway.
4113 : * - thomas 1999-01-08
4114 : *
4115 : * DEFAULT expression must be b_expr not a_expr to prevent shift/reduce
4116 : * conflict on NOT (since NOT might start a subsequent NOT NULL constraint,
4117 : * or be part of a_expr NOT LIKE or similar constructs).
4118 : */
4119 : ColConstraintElem:
4120 : NOT NULL_P opt_no_inherit
4121 : {
4122 4486 : Constraint *n = makeNode(Constraint);
4123 :
4124 4486 : n->contype = CONSTR_NOTNULL;
4125 4486 : n->location = @1;
4126 4486 : n->is_no_inherit = $3;
4127 4486 : n->is_enforced = true;
4128 4486 : n->skip_validation = false;
4129 4486 : n->initially_valid = true;
4130 4486 : $$ = (Node *) n;
4131 : }
4132 : | NULL_P
4133 : {
4134 19 : Constraint *n = makeNode(Constraint);
4135 :
4136 19 : n->contype = CONSTR_NULL;
4137 19 : n->location = @1;
4138 19 : $$ = (Node *) n;
4139 : }
4140 : | UNIQUE opt_unique_null_treatment opt_definition OptConsTableSpace
4141 : {
4142 302 : Constraint *n = makeNode(Constraint);
4143 :
4144 302 : n->contype = CONSTR_UNIQUE;
4145 302 : n->location = @1;
4146 302 : n->nulls_not_distinct = !$2;
4147 302 : n->keys = NULL;
4148 302 : n->options = $3;
4149 302 : n->indexname = NULL;
4150 302 : n->indexspace = $4;
4151 302 : $$ = (Node *) n;
4152 : }
4153 : | PRIMARY KEY opt_definition OptConsTableSpace
4154 : {
4155 3644 : Constraint *n = makeNode(Constraint);
4156 :
4157 3644 : n->contype = CONSTR_PRIMARY;
4158 3644 : n->location = @1;
4159 3644 : n->keys = NULL;
4160 3644 : n->options = $3;
4161 3644 : n->indexname = NULL;
4162 3644 : n->indexspace = $4;
4163 3644 : $$ = (Node *) n;
4164 : }
4165 : | CHECK '(' a_expr ')' opt_no_inherit
4166 : {
4167 761 : Constraint *n = makeNode(Constraint);
4168 :
4169 761 : n->contype = CONSTR_CHECK;
4170 761 : n->location = @1;
4171 761 : n->is_no_inherit = $5;
4172 761 : n->raw_expr = $3;
4173 761 : n->cooked_expr = NULL;
4174 761 : n->is_enforced = true;
4175 761 : n->skip_validation = false;
4176 761 : n->initially_valid = true;
4177 761 : $$ = (Node *) n;
4178 : }
4179 : | DEFAULT b_expr
4180 : {
4181 1234 : Constraint *n = makeNode(Constraint);
4182 :
4183 1234 : n->contype = CONSTR_DEFAULT;
4184 1234 : n->location = @1;
4185 1234 : n->raw_expr = $2;
4186 1234 : n->cooked_expr = NULL;
4187 1234 : $$ = (Node *) n;
4188 : }
4189 : | GENERATED generated_when AS IDENTITY_P OptParenthesizedSeqOptList
4190 : {
4191 248 : Constraint *n = makeNode(Constraint);
4192 :
4193 248 : n->contype = CONSTR_IDENTITY;
4194 248 : n->generated_when = $2;
4195 248 : n->options = $5;
4196 248 : n->location = @1;
4197 248 : $$ = (Node *) n;
4198 : }
4199 : | GENERATED generated_when AS '(' a_expr ')' opt_virtual_or_stored
4200 : {
4201 1297 : Constraint *n = makeNode(Constraint);
4202 :
4203 1297 : n->contype = CONSTR_GENERATED;
4204 1297 : n->generated_when = $2;
4205 1297 : n->raw_expr = $5;
4206 1297 : n->cooked_expr = NULL;
4207 1297 : n->generated_kind = $7;
4208 1297 : n->location = @1;
4209 :
4210 : /*
4211 : * Can't do this in the grammar because of shift/reduce
4212 : * conflicts. (IDENTITY allows both ALWAYS and BY
4213 : * DEFAULT, but generated columns only allow ALWAYS.) We
4214 : * can also give a more useful error message and location.
4215 : */
4216 1297 : if ($2 != ATTRIBUTE_IDENTITY_ALWAYS)
4217 8 : ereport(ERROR,
4218 : (errcode(ERRCODE_SYNTAX_ERROR),
4219 : errmsg("for a generated column, GENERATED ALWAYS must be specified"),
4220 : parser_errposition(@2)));
4221 :
4222 1289 : $$ = (Node *) n;
4223 : }
4224 : | REFERENCES qualified_name opt_column_list key_match key_actions
4225 : {
4226 645 : Constraint *n = makeNode(Constraint);
4227 :
4228 645 : n->contype = CONSTR_FOREIGN;
4229 645 : n->location = @1;
4230 645 : n->pktable = $2;
4231 645 : n->fk_attrs = NIL;
4232 645 : n->pk_attrs = $3;
4233 645 : n->fk_matchtype = $4;
4234 645 : n->fk_upd_action = ($5)->updateAction->action;
4235 645 : n->fk_del_action = ($5)->deleteAction->action;
4236 645 : n->fk_del_set_cols = ($5)->deleteAction->cols;
4237 645 : n->is_enforced = true;
4238 645 : n->skip_validation = false;
4239 645 : n->initially_valid = true;
4240 645 : $$ = (Node *) n;
4241 : }
4242 : ;
4243 :
4244 : opt_unique_null_treatment:
4245 8 : NULLS_P DISTINCT { $$ = true; }
4246 24 : | NULLS_P NOT DISTINCT { $$ = false; }
4247 5084 : | /*EMPTY*/ { $$ = true; }
4248 : ;
4249 :
4250 : generated_when:
4251 1563 : ALWAYS { $$ = ATTRIBUTE_IDENTITY_ALWAYS; }
4252 118 : | BY DEFAULT { $$ = ATTRIBUTE_IDENTITY_BY_DEFAULT; }
4253 : ;
4254 :
4255 : opt_virtual_or_stored:
4256 700 : STORED { $$ = ATTRIBUTE_GENERATED_STORED; }
4257 435 : | VIRTUAL { $$ = ATTRIBUTE_GENERATED_VIRTUAL; }
4258 162 : | /*EMPTY*/ { $$ = ATTRIBUTE_GENERATED_VIRTUAL; }
4259 : ;
4260 :
4261 : /*
4262 : * ConstraintAttr represents constraint attributes, which we parse as if
4263 : * they were independent constraint clauses, in order to avoid shift/reduce
4264 : * conflicts (since NOT might start either an independent NOT NULL clause
4265 : * or an attribute). parse_utilcmd.c is responsible for attaching the
4266 : * attribute information to the preceding "real" constraint node, and for
4267 : * complaining if attribute clauses appear in the wrong place or wrong
4268 : * combinations.
4269 : *
4270 : * See also ConstraintAttributeSpec, which can be used in places where
4271 : * there is no parsing conflict. (Note: currently, NOT VALID and NO INHERIT
4272 : * are allowed clauses in ConstraintAttributeSpec, but not here. Someday we
4273 : * might need to allow them here too, but for the moment it doesn't seem
4274 : * useful in the statements that use ConstraintAttr.)
4275 : */
4276 : ConstraintAttr:
4277 : DEFERRABLE
4278 : {
4279 88 : Constraint *n = makeNode(Constraint);
4280 :
4281 88 : n->contype = CONSTR_ATTR_DEFERRABLE;
4282 88 : n->location = @1;
4283 88 : $$ = (Node *) n;
4284 : }
4285 : | NOT DEFERRABLE
4286 : {
4287 4 : Constraint *n = makeNode(Constraint);
4288 :
4289 4 : n->contype = CONSTR_ATTR_NOT_DEFERRABLE;
4290 4 : n->location = @1;
4291 4 : $$ = (Node *) n;
4292 : }
4293 : | INITIALLY DEFERRED
4294 : {
4295 66 : Constraint *n = makeNode(Constraint);
4296 :
4297 66 : n->contype = CONSTR_ATTR_DEFERRED;
4298 66 : n->location = @1;
4299 66 : $$ = (Node *) n;
4300 : }
4301 : | INITIALLY IMMEDIATE
4302 : {
4303 8 : Constraint *n = makeNode(Constraint);
4304 :
4305 8 : n->contype = CONSTR_ATTR_IMMEDIATE;
4306 8 : n->location = @1;
4307 8 : $$ = (Node *) n;
4308 : }
4309 : | ENFORCED
4310 : {
4311 32 : Constraint *n = makeNode(Constraint);
4312 :
4313 32 : n->contype = CONSTR_ATTR_ENFORCED;
4314 32 : n->location = @1;
4315 32 : $$ = (Node *) n;
4316 : }
4317 : | NOT ENFORCED
4318 : {
4319 57 : Constraint *n = makeNode(Constraint);
4320 :
4321 57 : n->contype = CONSTR_ATTR_NOT_ENFORCED;
4322 57 : n->location = @1;
4323 57 : $$ = (Node *) n;
4324 : }
4325 : ;
4326 :
4327 :
4328 : TableLikeClause:
4329 : LIKE qualified_name TableLikeOptionList
4330 : {
4331 516 : TableLikeClause *n = makeNode(TableLikeClause);
4332 :
4333 516 : n->relation = $2;
4334 516 : n->options = $3;
4335 516 : n->relationOid = InvalidOid;
4336 516 : $$ = (Node *) n;
4337 : }
4338 : ;
4339 :
4340 : TableLikeOptionList:
4341 191 : TableLikeOptionList INCLUDING TableLikeOption { $$ = $1 | $3; }
4342 5 : | TableLikeOptionList EXCLUDING TableLikeOption { $$ = $1 & ~$3; }
4343 516 : | /* EMPTY */ { $$ = 0; }
4344 : ;
4345 :
4346 : TableLikeOption:
4347 20 : COMMENTS { $$ = CREATE_TABLE_LIKE_COMMENTS; }
4348 4 : | COMPRESSION { $$ = CREATE_TABLE_LIKE_COMPRESSION; }
4349 36 : | CONSTRAINTS { $$ = CREATE_TABLE_LIKE_CONSTRAINTS; }
4350 13 : | DEFAULTS { $$ = CREATE_TABLE_LIKE_DEFAULTS; }
4351 8 : | IDENTITY_P { $$ = CREATE_TABLE_LIKE_IDENTITY; }
4352 20 : | GENERATED { $$ = CREATE_TABLE_LIKE_GENERATED; }
4353 33 : | INDEXES { $$ = CREATE_TABLE_LIKE_INDEXES; }
4354 0 : | STATISTICS { $$ = CREATE_TABLE_LIKE_STATISTICS; }
4355 17 : | STORAGE { $$ = CREATE_TABLE_LIKE_STORAGE; }
4356 45 : | ALL { $$ = CREATE_TABLE_LIKE_ALL; }
4357 : ;
4358 :
4359 :
4360 : /* ConstraintElem specifies constraint syntax which is not embedded into
4361 : * a column definition. ColConstraintElem specifies the embedded form.
4362 : * - thomas 1997-12-03
4363 : */
4364 : TableConstraint:
4365 : CONSTRAINT name ConstraintElem
4366 : {
4367 2803 : Constraint *n = castNode(Constraint, $3);
4368 :
4369 2803 : n->conname = $2;
4370 2803 : n->location = @1;
4371 2803 : $$ = (Node *) n;
4372 : }
4373 8522 : | ConstraintElem { $$ = $1; }
4374 : ;
4375 :
4376 : ConstraintElem:
4377 : CHECK '(' a_expr ')' ConstraintAttributeSpec
4378 : {
4379 941 : Constraint *n = makeNode(Constraint);
4380 :
4381 941 : n->contype = CONSTR_CHECK;
4382 941 : n->location = @1;
4383 941 : n->raw_expr = $3;
4384 941 : n->cooked_expr = NULL;
4385 941 : processCASbits($5, @5, "CHECK",
4386 : NULL, NULL, &n->is_enforced, &n->skip_validation,
4387 : &n->is_no_inherit, yyscanner);
4388 941 : n->initially_valid = !n->skip_validation;
4389 941 : $$ = (Node *) n;
4390 : }
4391 : | NOT NULL_P ColId ConstraintAttributeSpec
4392 : {
4393 433 : Constraint *n = makeNode(Constraint);
4394 :
4395 433 : n->contype = CONSTR_NOTNULL;
4396 433 : n->location = @1;
4397 433 : n->keys = list_make1(makeString($3));
4398 433 : processCASbits($4, @4, "NOT NULL",
4399 : NULL, NULL, NULL, &n->skip_validation,
4400 : &n->is_no_inherit, yyscanner);
4401 433 : n->initially_valid = !n->skip_validation;
4402 433 : $$ = (Node *) n;
4403 : }
4404 : | UNIQUE opt_unique_null_treatment '(' columnList opt_without_overlaps ')' opt_c_include opt_definition OptConsTableSpace
4405 : ConstraintAttributeSpec
4406 : {
4407 393 : Constraint *n = makeNode(Constraint);
4408 :
4409 393 : n->contype = CONSTR_UNIQUE;
4410 393 : n->location = @1;
4411 393 : n->nulls_not_distinct = !$2;
4412 393 : n->keys = $4;
4413 393 : n->without_overlaps = $5;
4414 393 : n->including = $7;
4415 393 : n->options = $8;
4416 393 : n->indexname = NULL;
4417 393 : n->indexspace = $9;
4418 393 : processCASbits($10, @10, "UNIQUE",
4419 : &n->deferrable, &n->initdeferred, NULL,
4420 : NULL, NULL, yyscanner);
4421 393 : $$ = (Node *) n;
4422 : }
4423 : | UNIQUE ExistingIndex ConstraintAttributeSpec
4424 : {
4425 2941 : Constraint *n = makeNode(Constraint);
4426 :
4427 2941 : n->contype = CONSTR_UNIQUE;
4428 2941 : n->location = @1;
4429 2941 : n->keys = NIL;
4430 2941 : n->including = NIL;
4431 2941 : n->options = NIL;
4432 2941 : n->indexname = $2;
4433 2941 : n->indexspace = NULL;
4434 2941 : processCASbits($3, @3, "UNIQUE",
4435 : &n->deferrable, &n->initdeferred, NULL,
4436 : NULL, NULL, yyscanner);
4437 2941 : $$ = (Node *) n;
4438 : }
4439 : | PRIMARY KEY '(' columnList opt_without_overlaps ')' opt_c_include opt_definition OptConsTableSpace
4440 : ConstraintAttributeSpec
4441 : {
4442 1539 : Constraint *n = makeNode(Constraint);
4443 :
4444 1539 : n->contype = CONSTR_PRIMARY;
4445 1539 : n->location = @1;
4446 1539 : n->keys = $4;
4447 1539 : n->without_overlaps = $5;
4448 1539 : n->including = $7;
4449 1539 : n->options = $8;
4450 1539 : n->indexname = NULL;
4451 1539 : n->indexspace = $9;
4452 1539 : processCASbits($10, @10, "PRIMARY KEY",
4453 : &n->deferrable, &n->initdeferred, NULL,
4454 : NULL, NULL, yyscanner);
4455 1539 : $$ = (Node *) n;
4456 : }
4457 : | PRIMARY KEY ExistingIndex ConstraintAttributeSpec
4458 : {
4459 3729 : Constraint *n = makeNode(Constraint);
4460 :
4461 3729 : n->contype = CONSTR_PRIMARY;
4462 3729 : n->location = @1;
4463 3729 : n->keys = NIL;
4464 3729 : n->including = NIL;
4465 3729 : n->options = NIL;
4466 3729 : n->indexname = $3;
4467 3729 : n->indexspace = NULL;
4468 3729 : processCASbits($4, @4, "PRIMARY KEY",
4469 : &n->deferrable, &n->initdeferred, NULL,
4470 : NULL, NULL, yyscanner);
4471 3729 : $$ = (Node *) n;
4472 : }
4473 : | EXCLUDE access_method_clause '(' ExclusionConstraintList ')'
4474 : opt_c_include opt_definition OptConsTableSpace OptWhereClause
4475 : ConstraintAttributeSpec
4476 : {
4477 153 : Constraint *n = makeNode(Constraint);
4478 :
4479 153 : n->contype = CONSTR_EXCLUSION;
4480 153 : n->location = @1;
4481 153 : n->access_method = $2;
4482 153 : n->exclusions = $4;
4483 153 : n->including = $6;
4484 153 : n->options = $7;
4485 153 : n->indexname = NULL;
4486 153 : n->indexspace = $8;
4487 153 : n->where_clause = $9;
4488 153 : processCASbits($10, @10, "EXCLUDE",
4489 : &n->deferrable, &n->initdeferred, NULL,
4490 : NULL, NULL, yyscanner);
4491 153 : $$ = (Node *) n;
4492 : }
4493 : | FOREIGN KEY '(' columnList optionalPeriodName ')' REFERENCES qualified_name
4494 : opt_column_and_period_list key_match key_actions ConstraintAttributeSpec
4495 : {
4496 1196 : Constraint *n = makeNode(Constraint);
4497 :
4498 1196 : n->contype = CONSTR_FOREIGN;
4499 1196 : n->location = @1;
4500 1196 : n->pktable = $8;
4501 1196 : n->fk_attrs = $4;
4502 1196 : if ($5)
4503 : {
4504 210 : n->fk_attrs = lappend(n->fk_attrs, $5);
4505 210 : n->fk_with_period = true;
4506 : }
4507 1196 : n->pk_attrs = linitial($9);
4508 1196 : if (lsecond($9))
4509 : {
4510 112 : n->pk_attrs = lappend(n->pk_attrs, lsecond($9));
4511 112 : n->pk_with_period = true;
4512 : }
4513 1196 : n->fk_matchtype = $10;
4514 1196 : n->fk_upd_action = ($11)->updateAction->action;
4515 1196 : n->fk_del_action = ($11)->deleteAction->action;
4516 1196 : n->fk_del_set_cols = ($11)->deleteAction->cols;
4517 1196 : processCASbits($12, @12, "FOREIGN KEY",
4518 : &n->deferrable, &n->initdeferred,
4519 : &n->is_enforced, &n->skip_validation, NULL,
4520 : yyscanner);
4521 1196 : n->initially_valid = !n->skip_validation;
4522 1196 : $$ = (Node *) n;
4523 : }
4524 : ;
4525 :
4526 : /*
4527 : * DomainConstraint is separate from TableConstraint because the syntax for
4528 : * NOT NULL constraints is different. For table constraints, we need to
4529 : * accept a column name, but for domain constraints, we don't. (We could
4530 : * accept something like NOT NULL VALUE, but that seems weird.) CREATE DOMAIN
4531 : * (which uses ColQualList) has for a long time accepted NOT NULL without a
4532 : * column name, so it makes sense that ALTER DOMAIN (which uses
4533 : * DomainConstraint) does as well. None of these syntaxes are per SQL
4534 : * standard; we are just living with the bits of inconsistency that have built
4535 : * up over time.
4536 : */
4537 : DomainConstraint:
4538 : CONSTRAINT name DomainConstraintElem
4539 : {
4540 108 : Constraint *n = castNode(Constraint, $3);
4541 :
4542 108 : n->conname = $2;
4543 108 : n->location = @1;
4544 108 : $$ = (Node *) n;
4545 : }
4546 12 : | DomainConstraintElem { $$ = $1; }
4547 : ;
4548 :
4549 : DomainConstraintElem:
4550 : CHECK '(' a_expr ')' ConstraintAttributeSpec
4551 : {
4552 108 : Constraint *n = makeNode(Constraint);
4553 :
4554 108 : n->contype = CONSTR_CHECK;
4555 108 : n->location = @1;
4556 108 : n->raw_expr = $3;
4557 108 : n->cooked_expr = NULL;
4558 108 : processCASbits($5, @5, "CHECK",
4559 : NULL, NULL, NULL, &n->skip_validation,
4560 : &n->is_no_inherit, yyscanner);
4561 100 : n->is_enforced = true;
4562 100 : n->initially_valid = !n->skip_validation;
4563 100 : $$ = (Node *) n;
4564 : }
4565 : | NOT NULL_P ConstraintAttributeSpec
4566 : {
4567 20 : Constraint *n = makeNode(Constraint);
4568 :
4569 20 : n->contype = CONSTR_NOTNULL;
4570 20 : n->location = @1;
4571 20 : n->keys = list_make1(makeString("value"));
4572 : /* no NOT VALID, NO INHERIT support */
4573 20 : processCASbits($3, @3, "NOT NULL",
4574 : NULL, NULL, NULL,
4575 : NULL, NULL, yyscanner);
4576 20 : n->initially_valid = true;
4577 20 : $$ = (Node *) n;
4578 : }
4579 : ;
4580 :
4581 97 : opt_no_inherit: NO INHERIT { $$ = true; }
4582 5150 : | /* EMPTY */ { $$ = false; }
4583 : ;
4584 :
4585 : opt_without_overlaps:
4586 531 : WITHOUT OVERLAPS { $$ = true; }
4587 1401 : | /*EMPTY*/ { $$ = false; }
4588 : ;
4589 :
4590 : opt_column_list:
4591 6001 : '(' columnList ')' { $$ = $2; }
4592 22654 : | /*EMPTY*/ { $$ = NIL; }
4593 : ;
4594 :
4595 : columnList:
4596 11451 : columnElem { $$ = list_make1($1); }
4597 16262 : | columnList ',' columnElem { $$ = lappend($1, $3); }
4598 : ;
4599 :
4600 : optionalPeriodName:
4601 322 : ',' PERIOD columnElem { $$ = $3; }
4602 1567 : | /*EMPTY*/ { $$ = NULL; }
4603 : ;
4604 :
4605 : opt_column_and_period_list:
4606 689 : '(' columnList optionalPeriodName ')' { $$ = list_make2($2, $3); }
4607 511 : | /*EMPTY*/ { $$ = list_make2(NIL, NULL); }
4608 : ;
4609 :
4610 : columnElem: ColId
4611 : {
4612 28035 : $$ = (Node *) makeString($1);
4613 : }
4614 : ;
4615 :
4616 100 : opt_c_include: INCLUDE '(' columnList ')' { $$ = $3; }
4617 1985 : | /* EMPTY */ { $$ = NIL; }
4618 : ;
4619 :
4620 : key_match: MATCH FULL
4621 : {
4622 65 : $$ = FKCONSTR_MATCH_FULL;
4623 : }
4624 : | MATCH PARTIAL
4625 : {
4626 0 : ereport(ERROR,
4627 : (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
4628 : errmsg("MATCH PARTIAL not yet implemented"),
4629 : parser_errposition(@1)));
4630 : $$ = FKCONSTR_MATCH_PARTIAL;
4631 : }
4632 : | MATCH SIMPLE
4633 : {
4634 4 : $$ = FKCONSTR_MATCH_SIMPLE;
4635 : }
4636 : | /*EMPTY*/
4637 : {
4638 1776 : $$ = FKCONSTR_MATCH_SIMPLE;
4639 : }
4640 : ;
4641 :
4642 : ExclusionConstraintList:
4643 153 : ExclusionConstraintElem { $$ = list_make1($1); }
4644 : | ExclusionConstraintList ',' ExclusionConstraintElem
4645 69 : { $$ = lappend($1, $3); }
4646 : ;
4647 :
4648 : ExclusionConstraintElem: index_elem WITH any_operator
4649 : {
4650 222 : $$ = list_make2($1, $3);
4651 : }
4652 : /* allow OPERATOR() decoration for the benefit of ruleutils.c */
4653 : | index_elem WITH OPERATOR '(' any_operator ')'
4654 : {
4655 0 : $$ = list_make2($1, $5);
4656 : }
4657 : ;
4658 :
4659 : OptWhereClause:
4660 307 : WHERE '(' a_expr ')' { $$ = $3; }
4661 816 : | /*EMPTY*/ { $$ = NULL; }
4662 : ;
4663 :
4664 : key_actions:
4665 : key_update
4666 : {
4667 49 : KeyActions *n = palloc_object(KeyActions);
4668 :
4669 49 : n->updateAction = $1;
4670 49 : n->deleteAction = palloc_object(KeyAction);
4671 49 : n->deleteAction->action = FKCONSTR_ACTION_NOACTION;
4672 49 : n->deleteAction->cols = NIL;
4673 49 : $$ = n;
4674 : }
4675 : | key_delete
4676 : {
4677 93 : KeyActions *n = palloc_object(KeyActions);
4678 :
4679 93 : n->updateAction = palloc_object(KeyAction);
4680 93 : n->updateAction->action = FKCONSTR_ACTION_NOACTION;
4681 93 : n->updateAction->cols = NIL;
4682 93 : n->deleteAction = $1;
4683 93 : $$ = n;
4684 : }
4685 : | key_update key_delete
4686 : {
4687 111 : KeyActions *n = palloc_object(KeyActions);
4688 :
4689 111 : n->updateAction = $1;
4690 111 : n->deleteAction = $2;
4691 111 : $$ = n;
4692 : }
4693 : | key_delete key_update
4694 : {
4695 100 : KeyActions *n = palloc_object(KeyActions);
4696 :
4697 100 : n->updateAction = $2;
4698 100 : n->deleteAction = $1;
4699 100 : $$ = n;
4700 : }
4701 : | /*EMPTY*/
4702 : {
4703 1488 : KeyActions *n = palloc_object(KeyActions);
4704 :
4705 1488 : n->updateAction = palloc_object(KeyAction);
4706 1488 : n->updateAction->action = FKCONSTR_ACTION_NOACTION;
4707 1488 : n->updateAction->cols = NIL;
4708 1488 : n->deleteAction = palloc_object(KeyAction);
4709 1488 : n->deleteAction->action = FKCONSTR_ACTION_NOACTION;
4710 1488 : n->deleteAction->cols = NIL;
4711 1488 : $$ = n;
4712 : }
4713 : ;
4714 :
4715 : key_update: ON UPDATE key_action
4716 : {
4717 264 : if (($3)->cols)
4718 4 : ereport(ERROR,
4719 : (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
4720 : errmsg("a column list with %s is only supported for ON DELETE actions",
4721 : ($3)->action == FKCONSTR_ACTION_SETNULL ? "SET NULL" : "SET DEFAULT"),
4722 : parser_errposition(@1)));
4723 260 : $$ = $3;
4724 : }
4725 : ;
4726 :
4727 : key_delete: ON DELETE_P key_action
4728 : {
4729 304 : $$ = $3;
4730 : }
4731 : ;
4732 :
4733 : key_action:
4734 : NO ACTION
4735 : {
4736 51 : KeyAction *n = palloc_object(KeyAction);
4737 :
4738 51 : n->action = FKCONSTR_ACTION_NOACTION;
4739 51 : n->cols = NIL;
4740 51 : $$ = n;
4741 : }
4742 : | RESTRICT
4743 : {
4744 32 : KeyAction *n = palloc_object(KeyAction);
4745 :
4746 32 : n->action = FKCONSTR_ACTION_RESTRICT;
4747 32 : n->cols = NIL;
4748 32 : $$ = n;
4749 : }
4750 : | CASCADE
4751 : {
4752 293 : KeyAction *n = palloc_object(KeyAction);
4753 :
4754 293 : n->action = FKCONSTR_ACTION_CASCADE;
4755 293 : n->cols = NIL;
4756 293 : $$ = n;
4757 : }
4758 : | SET NULL_P opt_column_list
4759 : {
4760 124 : KeyAction *n = palloc_object(KeyAction);
4761 :
4762 124 : n->action = FKCONSTR_ACTION_SETNULL;
4763 124 : n->cols = $3;
4764 124 : $$ = n;
4765 : }
4766 : | SET DEFAULT opt_column_list
4767 : {
4768 68 : KeyAction *n = palloc_object(KeyAction);
4769 :
4770 68 : n->action = FKCONSTR_ACTION_SETDEFAULT;
4771 68 : n->cols = $3;
4772 68 : $$ = n;
4773 : }
4774 : ;
4775 :
4776 1375 : OptInherit: INHERITS '(' qualified_name_list ')' { $$ = $3; }
4777 18437 : | /*EMPTY*/ { $$ = NIL; }
4778 : ;
4779 :
4780 : /* Optional partition key specification */
4781 3583 : OptPartitionSpec: PartitionSpec { $$ = $1; }
4782 22450 : | /*EMPTY*/ { $$ = NULL; }
4783 : ;
4784 :
4785 : PartitionSpec: PARTITION BY ColId '(' part_params ')'
4786 : {
4787 3587 : PartitionSpec *n = makeNode(PartitionSpec);
4788 :
4789 3587 : n->strategy = parsePartitionStrategy($3, @3, yyscanner);
4790 3583 : n->partParams = $5;
4791 3583 : n->location = @1;
4792 :
4793 3583 : $$ = n;
4794 : }
4795 : ;
4796 :
4797 3587 : part_params: part_elem { $$ = list_make1($1); }
4798 322 : | part_params ',' part_elem { $$ = lappend($1, $3); }
4799 : ;
4800 :
4801 : part_elem: ColId opt_collate opt_qualified_name
4802 : {
4803 3677 : PartitionElem *n = makeNode(PartitionElem);
4804 :
4805 3677 : n->name = $1;
4806 3677 : n->expr = NULL;
4807 3677 : n->collation = $2;
4808 3677 : n->opclass = $3;
4809 3677 : n->location = @1;
4810 3677 : $$ = n;
4811 : }
4812 : | func_expr_windowless opt_collate opt_qualified_name
4813 : {
4814 94 : PartitionElem *n = makeNode(PartitionElem);
4815 :
4816 94 : n->name = NULL;
4817 94 : n->expr = $1;
4818 94 : n->collation = $2;
4819 94 : n->opclass = $3;
4820 94 : n->location = @1;
4821 94 : $$ = n;
4822 : }
4823 : | '(' a_expr ')' opt_collate opt_qualified_name
4824 : {
4825 138 : PartitionElem *n = makeNode(PartitionElem);
4826 :
4827 138 : n->name = NULL;
4828 138 : n->expr = $2;
4829 138 : n->collation = $4;
4830 138 : n->opclass = $5;
4831 138 : n->location = @1;
4832 138 : $$ = n;
4833 : }
4834 : ;
4835 :
4836 : table_access_method_clause:
4837 87 : USING name { $$ = $2; }
4838 27198 : | /*EMPTY*/ { $$ = NULL; }
4839 : ;
4840 :
4841 : /* WITHOUT OIDS is legacy only */
4842 : OptWith:
4843 585 : WITH reloptions { $$ = $2; }
4844 16 : | WITHOUT OIDS { $$ = NIL; }
4845 26315 : | /*EMPTY*/ { $$ = NIL; }
4846 : ;
4847 :
4848 43 : OnCommitOption: ON COMMIT DROP { $$ = ONCOMMIT_DROP; }
4849 69 : | ON COMMIT DELETE_P ROWS { $$ = ONCOMMIT_DELETE_ROWS; }
4850 16 : | ON COMMIT PRESERVE ROWS { $$ = ONCOMMIT_PRESERVE_ROWS; }
4851 26788 : | /*EMPTY*/ { $$ = ONCOMMIT_NOOP; }
4852 : ;
4853 :
4854 140 : OptTableSpace: TABLESPACE name { $$ = $2; }
4855 31562 : | /*EMPTY*/ { $$ = NULL; }
4856 : ;
4857 :
4858 50 : OptConsTableSpace: USING INDEX TABLESPACE name { $$ = $4; }
4859 5981 : | /*EMPTY*/ { $$ = NULL; }
4860 : ;
4861 :
4862 6670 : ExistingIndex: USING INDEX name { $$ = $3; }
4863 : ;
4864 :
4865 : /*****************************************************************************
4866 : *
4867 : * QUERY :
4868 : * CREATE STATISTICS [[IF NOT EXISTS] stats_name] [(stat types)]
4869 : * ON expression-list FROM from_list
4870 : *
4871 : * Note: the expectation here is that the clauses after ON are a subset of
4872 : * SELECT syntax, allowing for expressions and joined tables, and probably
4873 : * someday a WHERE clause. Much less than that is currently implemented,
4874 : * but the grammar accepts it and then we'll throw FEATURE_NOT_SUPPORTED
4875 : * errors as necessary at execution.
4876 : *
4877 : * Statistics name is optional unless IF NOT EXISTS is specified.
4878 : *
4879 : *****************************************************************************/
4880 :
4881 : CreateStatsStmt:
4882 : CREATE STATISTICS opt_qualified_name
4883 : opt_name_list ON stats_params FROM from_list
4884 : {
4885 640 : CreateStatsStmt *n = makeNode(CreateStatsStmt);
4886 :
4887 640 : n->defnames = $3;
4888 640 : n->stat_types = $4;
4889 640 : n->exprs = $6;
4890 640 : n->relations = $8;
4891 640 : n->stxcomment = NULL;
4892 640 : n->if_not_exists = false;
4893 640 : $$ = (Node *) n;
4894 : }
4895 : | CREATE STATISTICS IF_P NOT EXISTS any_name
4896 : opt_name_list ON stats_params FROM from_list
4897 : {
4898 8 : CreateStatsStmt *n = makeNode(CreateStatsStmt);
4899 :
4900 8 : n->defnames = $6;
4901 8 : n->stat_types = $7;
4902 8 : n->exprs = $9;
4903 8 : n->relations = $11;
4904 8 : n->stxcomment = NULL;
4905 8 : n->if_not_exists = true;
4906 8 : $$ = (Node *) n;
4907 : }
4908 : ;
4909 :
4910 : /*
4911 : * Statistics attributes can be either simple column references, or arbitrary
4912 : * expressions in parens. For compatibility with index attributes permitted
4913 : * in CREATE INDEX, we allow an expression that's just a function call to be
4914 : * written without parens.
4915 : */
4916 :
4917 656 : stats_params: stats_param { $$ = list_make1($1); }
4918 900 : | stats_params ',' stats_param { $$ = lappend($1, $3); }
4919 : ;
4920 :
4921 : stats_param: ColId
4922 : {
4923 1133 : $$ = makeNode(StatsElem);
4924 1133 : $$->name = $1;
4925 1133 : $$->expr = NULL;
4926 : }
4927 : | func_expr_windowless
4928 : {
4929 67 : $$ = makeNode(StatsElem);
4930 67 : $$->name = NULL;
4931 67 : $$->expr = $1;
4932 : }
4933 : | '(' a_expr ')'
4934 : {
4935 356 : $$ = makeNode(StatsElem);
4936 356 : $$->name = NULL;
4937 356 : $$->expr = $2;
4938 : }
4939 : ;
4940 :
4941 : /*****************************************************************************
4942 : *
4943 : * QUERY :
4944 : * ALTER STATISTICS [IF EXISTS] stats_name
4945 : * SET STATISTICS <SignedIconst>
4946 : *
4947 : *****************************************************************************/
4948 :
4949 : AlterStatsStmt:
4950 : ALTER STATISTICS any_name SET STATISTICS set_statistics_value
4951 : {
4952 13 : AlterStatsStmt *n = makeNode(AlterStatsStmt);
4953 :
4954 13 : n->defnames = $3;
4955 13 : n->missing_ok = false;
4956 13 : n->stxstattarget = $6;
4957 13 : $$ = (Node *) n;
4958 : }
4959 : | ALTER STATISTICS IF_P EXISTS any_name SET STATISTICS set_statistics_value
4960 : {
4961 4 : AlterStatsStmt *n = makeNode(AlterStatsStmt);
4962 :
4963 4 : n->defnames = $5;
4964 4 : n->missing_ok = true;
4965 4 : n->stxstattarget = $8;
4966 4 : $$ = (Node *) n;
4967 : }
4968 : ;
4969 :
4970 : /*****************************************************************************
4971 : *
4972 : * QUERY :
4973 : * CREATE TABLE relname AS SelectStmt [ WITH [NO] DATA ]
4974 : *
4975 : *
4976 : * Note: SELECT ... INTO is a now-deprecated alternative for this.
4977 : *
4978 : *****************************************************************************/
4979 :
4980 : CreateAsStmt:
4981 : CREATE OptTemp TABLE create_as_target AS SelectStmt opt_with_data
4982 : {
4983 802 : CreateTableAsStmt *ctas = makeNode(CreateTableAsStmt);
4984 :
4985 802 : ctas->query = $6;
4986 802 : ctas->into = $4;
4987 802 : ctas->objtype = OBJECT_TABLE;
4988 802 : ctas->is_select_into = false;
4989 802 : ctas->if_not_exists = false;
4990 : /* cram additional flags into the IntoClause */
4991 802 : $4->rel->relpersistence = $2;
4992 802 : $4->skipData = !($7);
4993 802 : $$ = (Node *) ctas;
4994 : }
4995 : | CREATE OptTemp TABLE IF_P NOT EXISTS create_as_target AS SelectStmt opt_with_data
4996 : {
4997 31 : CreateTableAsStmt *ctas = makeNode(CreateTableAsStmt);
4998 :
4999 31 : ctas->query = $9;
5000 31 : ctas->into = $7;
5001 31 : ctas->objtype = OBJECT_TABLE;
5002 31 : ctas->is_select_into = false;
5003 31 : ctas->if_not_exists = true;
5004 : /* cram additional flags into the IntoClause */
5005 31 : $7->rel->relpersistence = $2;
5006 31 : $7->skipData = !($10);
5007 31 : $$ = (Node *) ctas;
5008 : }
5009 : ;
5010 :
5011 : create_as_target:
5012 : qualified_name opt_column_list table_access_method_clause
5013 : OptWith OnCommitOption OptTableSpace
5014 : {
5015 891 : $$ = makeNode(IntoClause);
5016 891 : $$->rel = $1;
5017 891 : $$->colNames = $2;
5018 891 : $$->accessMethod = $3;
5019 891 : $$->options = $4;
5020 891 : $$->onCommit = $5;
5021 891 : $$->tableSpaceName = $6;
5022 891 : $$->viewQuery = NULL;
5023 891 : $$->skipData = false; /* might get changed later */
5024 : }
5025 : ;
5026 :
5027 : opt_with_data:
5028 24 : WITH DATA_P { $$ = true; }
5029 141 : | WITH NO DATA_P { $$ = false; }
5030 1265 : | /*EMPTY*/ { $$ = true; }
5031 : ;
5032 :
5033 :
5034 : /*****************************************************************************
5035 : *
5036 : * QUERY :
5037 : * CREATE MATERIALIZED VIEW relname AS SelectStmt
5038 : *
5039 : *****************************************************************************/
5040 :
5041 : CreateMatViewStmt:
5042 : CREATE OptNoLog MATERIALIZED VIEW create_mv_target AS SelectStmt opt_with_data
5043 : {
5044 336 : CreateTableAsStmt *ctas = makeNode(CreateTableAsStmt);
5045 :
5046 336 : ctas->query = $7;
5047 336 : ctas->into = $5;
5048 336 : ctas->objtype = OBJECT_MATVIEW;
5049 336 : ctas->is_select_into = false;
5050 336 : ctas->if_not_exists = false;
5051 : /* cram additional flags into the IntoClause */
5052 336 : $5->rel->relpersistence = $2;
5053 336 : $5->skipData = !($8);
5054 336 : $$ = (Node *) ctas;
5055 : }
5056 : | CREATE OptNoLog MATERIALIZED VIEW IF_P NOT EXISTS create_mv_target AS SelectStmt opt_with_data
5057 : {
5058 29 : CreateTableAsStmt *ctas = makeNode(CreateTableAsStmt);
5059 :
5060 29 : ctas->query = $10;
5061 29 : ctas->into = $8;
5062 29 : ctas->objtype = OBJECT_MATVIEW;
5063 29 : ctas->is_select_into = false;
5064 29 : ctas->if_not_exists = true;
5065 : /* cram additional flags into the IntoClause */
5066 29 : $8->rel->relpersistence = $2;
5067 29 : $8->skipData = !($11);
5068 29 : $$ = (Node *) ctas;
5069 : }
5070 : ;
5071 :
5072 : create_mv_target:
5073 : qualified_name opt_column_list table_access_method_clause opt_reloptions OptTableSpace
5074 : {
5075 365 : $$ = makeNode(IntoClause);
5076 365 : $$->rel = $1;
5077 365 : $$->colNames = $2;
5078 365 : $$->accessMethod = $3;
5079 365 : $$->options = $4;
5080 365 : $$->onCommit = ONCOMMIT_NOOP;
5081 365 : $$->tableSpaceName = $5;
5082 365 : $$->viewQuery = NULL; /* filled at analysis time */
5083 365 : $$->skipData = false; /* might get changed later */
5084 : }
5085 : ;
5086 :
5087 0 : OptNoLog: UNLOGGED { $$ = RELPERSISTENCE_UNLOGGED; }
5088 365 : | /*EMPTY*/ { $$ = RELPERSISTENCE_PERMANENT; }
5089 : ;
5090 :
5091 :
5092 : /*****************************************************************************
5093 : *
5094 : * QUERY :
5095 : * REFRESH MATERIALIZED VIEW qualified_name
5096 : *
5097 : *****************************************************************************/
5098 :
5099 : RefreshMatViewStmt:
5100 : REFRESH MATERIALIZED VIEW opt_concurrently qualified_name opt_with_data
5101 : {
5102 174 : RefreshMatViewStmt *n = makeNode(RefreshMatViewStmt);
5103 :
5104 174 : n->concurrent = $4;
5105 174 : n->relation = $5;
5106 174 : n->skipData = !($6);
5107 174 : $$ = (Node *) n;
5108 : }
5109 : ;
5110 :
5111 :
5112 : /*****************************************************************************
5113 : *
5114 : * QUERY :
5115 : * CREATE SEQUENCE seqname
5116 : * ALTER SEQUENCE seqname
5117 : *
5118 : *****************************************************************************/
5119 :
5120 : CreateSeqStmt:
5121 : CREATE OptTemp SEQUENCE qualified_name OptSeqOptList
5122 : {
5123 434 : CreateSeqStmt *n = makeNode(CreateSeqStmt);
5124 :
5125 434 : $4->relpersistence = $2;
5126 434 : n->sequence = $4;
5127 434 : n->options = $5;
5128 434 : n->ownerId = InvalidOid;
5129 434 : n->if_not_exists = false;
5130 434 : $$ = (Node *) n;
5131 : }
5132 : | CREATE OptTemp SEQUENCE IF_P NOT EXISTS qualified_name OptSeqOptList
5133 : {
5134 13 : CreateSeqStmt *n = makeNode(CreateSeqStmt);
5135 :
5136 13 : $7->relpersistence = $2;
5137 13 : n->sequence = $7;
5138 13 : n->options = $8;
5139 13 : n->ownerId = InvalidOid;
5140 13 : n->if_not_exists = true;
5141 13 : $$ = (Node *) n;
5142 : }
5143 : ;
5144 :
5145 : AlterSeqStmt:
5146 : ALTER SEQUENCE qualified_name SeqOptList
5147 : {
5148 117 : AlterSeqStmt *n = makeNode(AlterSeqStmt);
5149 :
5150 117 : n->sequence = $3;
5151 117 : n->options = $4;
5152 117 : n->missing_ok = false;
5153 117 : $$ = (Node *) n;
5154 : }
5155 : | ALTER SEQUENCE IF_P EXISTS qualified_name SeqOptList
5156 : {
5157 8 : AlterSeqStmt *n = makeNode(AlterSeqStmt);
5158 :
5159 8 : n->sequence = $5;
5160 8 : n->options = $6;
5161 8 : n->missing_ok = true;
5162 8 : $$ = (Node *) n;
5163 : }
5164 :
5165 : ;
5166 :
5167 164 : OptSeqOptList: SeqOptList { $$ = $1; }
5168 283 : | /*EMPTY*/ { $$ = NIL; }
5169 : ;
5170 :
5171 42 : OptParenthesizedSeqOptList: '(' SeqOptList ')' { $$ = $2; }
5172 313 : | /*EMPTY*/ { $$ = NIL; }
5173 : ;
5174 :
5175 331 : SeqOptList: SeqOptElem { $$ = list_make1($1); }
5176 440 : | SeqOptList SeqOptElem { $$ = lappend($1, $2); }
5177 : ;
5178 :
5179 : SeqOptElem: AS SimpleTypename
5180 : {
5181 119 : $$ = makeDefElem("as", (Node *) $2, @1);
5182 : }
5183 : | CACHE NumericOnly
5184 : {
5185 67 : $$ = makeDefElem("cache", (Node *) $2, @1);
5186 : }
5187 : | CYCLE
5188 : {
5189 22 : $$ = makeDefElem("cycle", (Node *) makeBoolean(true), @1);
5190 : }
5191 : | NO CYCLE
5192 : {
5193 9 : $$ = makeDefElem("cycle", (Node *) makeBoolean(false), @1);
5194 : }
5195 : | INCREMENT opt_by NumericOnly
5196 : {
5197 149 : $$ = makeDefElem("increment", (Node *) $3, @1);
5198 : }
5199 : | LOGGED
5200 : {
5201 1 : $$ = makeDefElem("logged", NULL, @1);
5202 : }
5203 : | MAXVALUE NumericOnly
5204 : {
5205 43 : $$ = makeDefElem("maxvalue", (Node *) $2, @1);
5206 : }
5207 : | MINVALUE NumericOnly
5208 : {
5209 43 : $$ = makeDefElem("minvalue", (Node *) $2, @1);
5210 : }
5211 : | NO MAXVALUE
5212 : {
5213 54 : $$ = makeDefElem("maxvalue", NULL, @1);
5214 : }
5215 : | NO MINVALUE
5216 : {
5217 54 : $$ = makeDefElem("minvalue", NULL, @1);
5218 : }
5219 : | OWNED BY any_name
5220 : {
5221 43 : $$ = makeDefElem("owned_by", (Node *) $3, @1);
5222 : }
5223 : | SEQUENCE NAME_P any_name
5224 : {
5225 22 : $$ = makeDefElem("sequence_name", (Node *) $3, @1);
5226 : }
5227 : | START opt_with NumericOnly
5228 : {
5229 137 : $$ = makeDefElem("start", (Node *) $3, @1);
5230 : }
5231 : | RESTART
5232 : {
5233 4 : $$ = makeDefElem("restart", NULL, @1);
5234 : }
5235 : | RESTART opt_with NumericOnly
5236 : {
5237 39 : $$ = makeDefElem("restart", (Node *) $3, @1);
5238 : }
5239 : | UNLOGGED
5240 : {
5241 1 : $$ = makeDefElem("unlogged", NULL, @1);
5242 : }
5243 : ;
5244 :
5245 : opt_by: BY
5246 : | /* EMPTY */
5247 : ;
5248 :
5249 : NumericOnly:
5250 217 : FCONST { $$ = (Node *) makeFloat($1); }
5251 0 : | '+' FCONST { $$ = (Node *) makeFloat($2); }
5252 : | '-' FCONST
5253 : {
5254 13 : Float *f = makeFloat($2);
5255 :
5256 13 : doNegateFloat(f);
5257 13 : $$ = (Node *) f;
5258 : }
5259 7359 : | SignedIconst { $$ = (Node *) makeInteger($1); }
5260 : ;
5261 :
5262 62 : NumericOnly_list: NumericOnly { $$ = list_make1($1); }
5263 4 : | NumericOnly_list ',' NumericOnly { $$ = lappend($1, $3); }
5264 : ;
5265 :
5266 : /*****************************************************************************
5267 : *
5268 : * QUERIES :
5269 : * CREATE [OR REPLACE] [TRUSTED] [PROCEDURAL] LANGUAGE ...
5270 : * DROP [PROCEDURAL] LANGUAGE ...
5271 : *
5272 : *****************************************************************************/
5273 :
5274 : CreatePLangStmt:
5275 : CREATE opt_or_replace opt_trusted opt_procedural LANGUAGE name
5276 : {
5277 : /*
5278 : * We now interpret parameterless CREATE LANGUAGE as
5279 : * CREATE EXTENSION. "OR REPLACE" is silently translated
5280 : * to "IF NOT EXISTS", which isn't quite the same, but
5281 : * seems more useful than throwing an error. We just
5282 : * ignore TRUSTED, as the previous code would have too.
5283 : */
5284 0 : CreateExtensionStmt *n = makeNode(CreateExtensionStmt);
5285 :
5286 0 : n->if_not_exists = $2;
5287 0 : n->extname = $6;
5288 0 : n->options = NIL;
5289 0 : $$ = (Node *) n;
5290 : }
5291 : | CREATE opt_or_replace opt_trusted opt_procedural LANGUAGE name
5292 : HANDLER handler_name opt_inline_handler opt_validator
5293 : {
5294 80 : CreatePLangStmt *n = makeNode(CreatePLangStmt);
5295 :
5296 80 : n->replace = $2;
5297 80 : n->plname = $6;
5298 80 : n->plhandler = $8;
5299 80 : n->plinline = $9;
5300 80 : n->plvalidator = $10;
5301 80 : n->pltrusted = $3;
5302 80 : $$ = (Node *) n;
5303 : }
5304 : ;
5305 :
5306 : opt_trusted:
5307 63 : TRUSTED { $$ = true; }
5308 22 : | /*EMPTY*/ { $$ = false; }
5309 : ;
5310 :
5311 : /* This ought to be just func_name, but that causes reduce/reduce conflicts
5312 : * (CREATE LANGUAGE is the only place where func_name isn't followed by '(').
5313 : * Work around by using simple names, instead.
5314 : */
5315 : handler_name:
5316 349 : name { $$ = list_make1(makeString($1)); }
5317 1 : | name attrs { $$ = lcons(makeString($1), $2); }
5318 : ;
5319 :
5320 : opt_inline_handler:
5321 69 : INLINE_P handler_name { $$ = $2; }
5322 11 : | /*EMPTY*/ { $$ = NIL; }
5323 : ;
5324 :
5325 : validator_clause:
5326 69 : VALIDATOR handler_name { $$ = $2; }
5327 0 : | NO VALIDATOR { $$ = NIL; }
5328 : ;
5329 :
5330 : opt_validator:
5331 69 : validator_clause { $$ = $1; }
5332 11 : | /*EMPTY*/ { $$ = NIL; }
5333 : ;
5334 :
5335 : opt_procedural:
5336 : PROCEDURAL
5337 : | /*EMPTY*/
5338 : ;
5339 :
5340 : /*****************************************************************************
5341 : *
5342 : * QUERY:
5343 : * CREATE TABLESPACE tablespace LOCATION '/path/to/tablespace/'
5344 : *
5345 : *****************************************************************************/
5346 :
5347 : CreateTableSpaceStmt: CREATE TABLESPACE name OptTableSpaceOwner LOCATION Sconst opt_reloptions
5348 : {
5349 91 : CreateTableSpaceStmt *n = makeNode(CreateTableSpaceStmt);
5350 :
5351 91 : n->tablespacename = $3;
5352 91 : n->owner = $4;
5353 91 : n->location = $6;
5354 91 : n->options = $7;
5355 91 : $$ = (Node *) n;
5356 : }
5357 : ;
5358 :
5359 23 : OptTableSpaceOwner: OWNER RoleSpec { $$ = $2; }
5360 68 : | /*EMPTY */ { $$ = NULL; }
5361 : ;
5362 :
5363 : /*****************************************************************************
5364 : *
5365 : * QUERY :
5366 : * DROP TABLESPACE <tablespace>
5367 : *
5368 : * No need for drop behaviour as we cannot implement dependencies for
5369 : * objects in other databases; we can only support RESTRICT.
5370 : *
5371 : ****************************************************************************/
5372 :
5373 : DropTableSpaceStmt: DROP TABLESPACE name
5374 : {
5375 51 : DropTableSpaceStmt *n = makeNode(DropTableSpaceStmt);
5376 :
5377 51 : n->tablespacename = $3;
5378 51 : n->missing_ok = false;
5379 51 : $$ = (Node *) n;
5380 : }
5381 : | DROP TABLESPACE IF_P EXISTS name
5382 : {
5383 0 : DropTableSpaceStmt *n = makeNode(DropTableSpaceStmt);
5384 :
5385 0 : n->tablespacename = $5;
5386 0 : n->missing_ok = true;
5387 0 : $$ = (Node *) n;
5388 : }
5389 : ;
5390 :
5391 : /*****************************************************************************
5392 : *
5393 : * QUERY:
5394 : * CREATE EXTENSION extension
5395 : * [ WITH ] [ SCHEMA schema ] [ VERSION version ]
5396 : *
5397 : *****************************************************************************/
5398 :
5399 : CreateExtensionStmt: CREATE EXTENSION name opt_with create_extension_opt_list
5400 : {
5401 303 : CreateExtensionStmt *n = makeNode(CreateExtensionStmt);
5402 :
5403 303 : n->extname = $3;
5404 303 : n->if_not_exists = false;
5405 303 : n->options = $5;
5406 303 : $$ = (Node *) n;
5407 : }
5408 : | CREATE EXTENSION IF_P NOT EXISTS name opt_with create_extension_opt_list
5409 : {
5410 10 : CreateExtensionStmt *n = makeNode(CreateExtensionStmt);
5411 :
5412 10 : n->extname = $6;
5413 10 : n->if_not_exists = true;
5414 10 : n->options = $8;
5415 10 : $$ = (Node *) n;
5416 : }
5417 : ;
5418 :
5419 : create_extension_opt_list:
5420 : create_extension_opt_list create_extension_opt_item
5421 49 : { $$ = lappend($1, $2); }
5422 : | /* EMPTY */
5423 313 : { $$ = NIL; }
5424 : ;
5425 :
5426 : create_extension_opt_item:
5427 : SCHEMA name
5428 : {
5429 23 : $$ = makeDefElem("schema", (Node *) makeString($2), @1);
5430 : }
5431 : | VERSION_P NonReservedWord_or_Sconst
5432 : {
5433 6 : $$ = makeDefElem("new_version", (Node *) makeString($2), @1);
5434 : }
5435 : | FROM NonReservedWord_or_Sconst
5436 : {
5437 0 : ereport(ERROR,
5438 : (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
5439 : errmsg("CREATE EXTENSION ... FROM is no longer supported"),
5440 : parser_errposition(@1)));
5441 : }
5442 : | CASCADE
5443 : {
5444 20 : $$ = makeDefElem("cascade", (Node *) makeBoolean(true), @1);
5445 : }
5446 : ;
5447 :
5448 : /*****************************************************************************
5449 : *
5450 : * ALTER EXTENSION name UPDATE [ TO version ]
5451 : *
5452 : *****************************************************************************/
5453 :
5454 : AlterExtensionStmt: ALTER EXTENSION name UPDATE alter_extension_opt_list
5455 : {
5456 20 : AlterExtensionStmt *n = makeNode(AlterExtensionStmt);
5457 :
5458 20 : n->extname = $3;
5459 20 : n->options = $5;
5460 20 : $$ = (Node *) n;
5461 : }
5462 : ;
5463 :
5464 : alter_extension_opt_list:
5465 : alter_extension_opt_list alter_extension_opt_item
5466 20 : { $$ = lappend($1, $2); }
5467 : | /* EMPTY */
5468 20 : { $$ = NIL; }
5469 : ;
5470 :
5471 : alter_extension_opt_item:
5472 : TO NonReservedWord_or_Sconst
5473 : {
5474 20 : $$ = makeDefElem("new_version", (Node *) makeString($2), @1);
5475 : }
5476 : ;
5477 :
5478 : /*****************************************************************************
5479 : *
5480 : * ALTER EXTENSION name ADD/DROP object-identifier
5481 : *
5482 : *****************************************************************************/
5483 :
5484 : AlterExtensionContentsStmt:
5485 : ALTER EXTENSION name add_drop object_type_name name
5486 : {
5487 9 : AlterExtensionContentsStmt *n = makeNode(AlterExtensionContentsStmt);
5488 :
5489 9 : n->extname = $3;
5490 9 : n->action = $4;
5491 9 : n->objtype = $5;
5492 9 : n->object = (Node *) makeString($6);
5493 9 : $$ = (Node *) n;
5494 : }
5495 : | ALTER EXTENSION name add_drop object_type_any_name any_name
5496 : {
5497 44 : AlterExtensionContentsStmt *n = makeNode(AlterExtensionContentsStmt);
5498 :
5499 44 : n->extname = $3;
5500 44 : n->action = $4;
5501 44 : n->objtype = $5;
5502 44 : n->object = (Node *) $6;
5503 44 : $$ = (Node *) n;
5504 : }
5505 : | ALTER EXTENSION name add_drop AGGREGATE aggregate_with_argtypes
5506 : {
5507 4 : AlterExtensionContentsStmt *n = makeNode(AlterExtensionContentsStmt);
5508 :
5509 4 : n->extname = $3;
5510 4 : n->action = $4;
5511 4 : n->objtype = OBJECT_AGGREGATE;
5512 4 : n->object = (Node *) $6;
5513 4 : $$ = (Node *) n;
5514 : }
5515 : | ALTER EXTENSION name add_drop CAST '(' Typename AS Typename ')'
5516 : {
5517 2 : AlterExtensionContentsStmt *n = makeNode(AlterExtensionContentsStmt);
5518 :
5519 2 : n->extname = $3;
5520 2 : n->action = $4;
5521 2 : n->objtype = OBJECT_CAST;
5522 2 : n->object = (Node *) list_make2($7, $9);
5523 2 : $$ = (Node *) n;
5524 : }
5525 : | ALTER EXTENSION name add_drop DOMAIN_P Typename
5526 : {
5527 0 : AlterExtensionContentsStmt *n = makeNode(AlterExtensionContentsStmt);
5528 :
5529 0 : n->extname = $3;
5530 0 : n->action = $4;
5531 0 : n->objtype = OBJECT_DOMAIN;
5532 0 : n->object = (Node *) $6;
5533 0 : $$ = (Node *) n;
5534 : }
5535 : | ALTER EXTENSION name add_drop FUNCTION function_with_argtypes
5536 : {
5537 62 : AlterExtensionContentsStmt *n = makeNode(AlterExtensionContentsStmt);
5538 :
5539 62 : n->extname = $3;
5540 62 : n->action = $4;
5541 62 : n->objtype = OBJECT_FUNCTION;
5542 62 : n->object = (Node *) $6;
5543 62 : $$ = (Node *) n;
5544 : }
5545 : | ALTER EXTENSION name add_drop OPERATOR operator_with_argtypes
5546 : {
5547 9 : AlterExtensionContentsStmt *n = makeNode(AlterExtensionContentsStmt);
5548 :
5549 9 : n->extname = $3;
5550 9 : n->action = $4;
5551 9 : n->objtype = OBJECT_OPERATOR;
5552 9 : n->object = (Node *) $6;
5553 9 : $$ = (Node *) n;
5554 : }
5555 : | ALTER EXTENSION name add_drop OPERATOR CLASS any_name USING name
5556 : {
5557 2 : AlterExtensionContentsStmt *n = makeNode(AlterExtensionContentsStmt);
5558 :
5559 2 : n->extname = $3;
5560 2 : n->action = $4;
5561 2 : n->objtype = OBJECT_OPCLASS;
5562 2 : n->object = (Node *) lcons(makeString($9), $7);
5563 2 : $$ = (Node *) n;
5564 : }
5565 : | ALTER EXTENSION name add_drop OPERATOR FAMILY any_name USING name
5566 : {
5567 2 : AlterExtensionContentsStmt *n = makeNode(AlterExtensionContentsStmt);
5568 :
5569 2 : n->extname = $3;
5570 2 : n->action = $4;
5571 2 : n->objtype = OBJECT_OPFAMILY;
5572 2 : n->object = (Node *) lcons(makeString($9), $7);
5573 2 : $$ = (Node *) n;
5574 : }
5575 : | ALTER EXTENSION name add_drop PROCEDURE function_with_argtypes
5576 : {
5577 0 : AlterExtensionContentsStmt *n = makeNode(AlterExtensionContentsStmt);
5578 :
5579 0 : n->extname = $3;
5580 0 : n->action = $4;
5581 0 : n->objtype = OBJECT_PROCEDURE;
5582 0 : n->object = (Node *) $6;
5583 0 : $$ = (Node *) n;
5584 : }
5585 : | ALTER EXTENSION name add_drop ROUTINE function_with_argtypes
5586 : {
5587 0 : AlterExtensionContentsStmt *n = makeNode(AlterExtensionContentsStmt);
5588 :
5589 0 : n->extname = $3;
5590 0 : n->action = $4;
5591 0 : n->objtype = OBJECT_ROUTINE;
5592 0 : n->object = (Node *) $6;
5593 0 : $$ = (Node *) n;
5594 : }
5595 : | ALTER EXTENSION name add_drop TRANSFORM FOR Typename LANGUAGE name
5596 : {
5597 2 : AlterExtensionContentsStmt *n = makeNode(AlterExtensionContentsStmt);
5598 :
5599 2 : n->extname = $3;
5600 2 : n->action = $4;
5601 2 : n->objtype = OBJECT_TRANSFORM;
5602 2 : n->object = (Node *) list_make2($7, makeString($9));
5603 2 : $$ = (Node *) n;
5604 : }
5605 : | ALTER EXTENSION name add_drop TYPE_P Typename
5606 : {
5607 4 : AlterExtensionContentsStmt *n = makeNode(AlterExtensionContentsStmt);
5608 :
5609 4 : n->extname = $3;
5610 4 : n->action = $4;
5611 4 : n->objtype = OBJECT_TYPE;
5612 4 : n->object = (Node *) $6;
5613 4 : $$ = (Node *) n;
5614 : }
5615 : ;
5616 :
5617 : /*****************************************************************************
5618 : *
5619 : * QUERY:
5620 : * CREATE FOREIGN DATA WRAPPER name options
5621 : *
5622 : *****************************************************************************/
5623 :
5624 : CreateFdwStmt: CREATE FOREIGN DATA_P WRAPPER name opt_fdw_options create_generic_options
5625 : {
5626 135 : CreateFdwStmt *n = makeNode(CreateFdwStmt);
5627 :
5628 135 : n->fdwname = $5;
5629 135 : n->func_options = $6;
5630 135 : n->options = $7;
5631 135 : $$ = (Node *) n;
5632 : }
5633 : ;
5634 :
5635 : fdw_option:
5636 38 : HANDLER handler_name { $$ = makeDefElem("handler", (Node *) $2, @1); }
5637 0 : | NO HANDLER { $$ = makeDefElem("handler", NULL, @1); }
5638 36 : | VALIDATOR handler_name { $$ = makeDefElem("validator", (Node *) $2, @1); }
5639 4 : | NO VALIDATOR { $$ = makeDefElem("validator", NULL, @1); }
5640 12 : | CONNECTION handler_name { $$ = makeDefElem("connection", (Node *) $2, @1); }
5641 4 : | NO CONNECTION { $$ = makeDefElem("connection", NULL, @1); }
5642 : ;
5643 :
5644 : fdw_options:
5645 80 : fdw_option { $$ = list_make1($1); }
5646 14 : | fdw_options fdw_option { $$ = lappend($1, $2); }
5647 : ;
5648 :
5649 : opt_fdw_options:
5650 36 : fdw_options { $$ = $1; }
5651 159 : | /*EMPTY*/ { $$ = NIL; }
5652 : ;
5653 :
5654 : /*****************************************************************************
5655 : *
5656 : * QUERY :
5657 : * ALTER FOREIGN DATA WRAPPER name options
5658 : *
5659 : ****************************************************************************/
5660 :
5661 : AlterFdwStmt: ALTER FOREIGN DATA_P WRAPPER name opt_fdw_options alter_generic_options
5662 : {
5663 56 : AlterFdwStmt *n = makeNode(AlterFdwStmt);
5664 :
5665 56 : n->fdwname = $5;
5666 56 : n->func_options = $6;
5667 56 : n->options = $7;
5668 56 : $$ = (Node *) n;
5669 : }
5670 : | ALTER FOREIGN DATA_P WRAPPER name fdw_options
5671 : {
5672 44 : AlterFdwStmt *n = makeNode(AlterFdwStmt);
5673 :
5674 44 : n->fdwname = $5;
5675 44 : n->func_options = $6;
5676 44 : n->options = NIL;
5677 44 : $$ = (Node *) n;
5678 : }
5679 : ;
5680 :
5681 : /* Options definition for CREATE FDW, SERVER and USER MAPPING */
5682 : create_generic_options:
5683 438 : OPTIONS '(' generic_option_list ')' { $$ = $3; }
5684 45275 : | /*EMPTY*/ { $$ = NIL; }
5685 : ;
5686 :
5687 : generic_option_list:
5688 : generic_option_elem
5689 : {
5690 438 : $$ = list_make1($1);
5691 : }
5692 : | generic_option_list ',' generic_option_elem
5693 : {
5694 294 : $$ = lappend($1, $3);
5695 : }
5696 : ;
5697 :
5698 : /* Options definition for ALTER FDW, SERVER and USER MAPPING */
5699 : alter_generic_options:
5700 294 : OPTIONS '(' alter_generic_option_list ')' { $$ = $3; }
5701 : ;
5702 :
5703 : alter_generic_option_list:
5704 : alter_generic_option_elem
5705 : {
5706 294 : $$ = list_make1($1);
5707 : }
5708 : | alter_generic_option_list ',' alter_generic_option_elem
5709 : {
5710 103 : $$ = lappend($1, $3);
5711 : }
5712 : ;
5713 :
5714 : alter_generic_option_elem:
5715 : generic_option_elem
5716 : {
5717 119 : $$ = $1;
5718 : }
5719 : | SET generic_option_elem
5720 : {
5721 73 : $$ = $2;
5722 73 : $$->defaction = DEFELEM_SET;
5723 : }
5724 : | ADD_P generic_option_elem
5725 : {
5726 129 : $$ = $2;
5727 129 : $$->defaction = DEFELEM_ADD;
5728 : }
5729 : | DROP generic_option_name
5730 : {
5731 76 : $$ = makeDefElemExtended(NULL, $2, NULL, DEFELEM_DROP, @2);
5732 : }
5733 : ;
5734 :
5735 : generic_option_elem:
5736 : generic_option_name generic_option_arg
5737 : {
5738 1053 : $$ = makeDefElem($1, $2, @1);
5739 : }
5740 : ;
5741 :
5742 : generic_option_name:
5743 1129 : ColLabel { $$ = $1; }
5744 : ;
5745 :
5746 : /* We could use def_arg here, but the spec only requires string literals */
5747 : generic_option_arg:
5748 1053 : Sconst { $$ = (Node *) makeString($1); }
5749 : ;
5750 :
5751 : /*****************************************************************************
5752 : *
5753 : * QUERY:
5754 : * CREATE SERVER name [TYPE] [VERSION] [OPTIONS]
5755 : *
5756 : *****************************************************************************/
5757 :
5758 : CreateForeignServerStmt: CREATE SERVER name opt_type opt_foreign_server_version
5759 : FOREIGN DATA_P WRAPPER name create_generic_options
5760 : {
5761 177 : CreateForeignServerStmt *n = makeNode(CreateForeignServerStmt);
5762 :
5763 177 : n->servername = $3;
5764 177 : n->servertype = $4;
5765 177 : n->version = $5;
5766 177 : n->fdwname = $9;
5767 177 : n->options = $10;
5768 177 : n->if_not_exists = false;
5769 177 : $$ = (Node *) n;
5770 : }
5771 : | CREATE SERVER IF_P NOT EXISTS name opt_type opt_foreign_server_version
5772 : FOREIGN DATA_P WRAPPER name create_generic_options
5773 : {
5774 13 : CreateForeignServerStmt *n = makeNode(CreateForeignServerStmt);
5775 :
5776 13 : n->servername = $6;
5777 13 : n->servertype = $7;
5778 13 : n->version = $8;
5779 13 : n->fdwname = $12;
5780 13 : n->options = $13;
5781 13 : n->if_not_exists = true;
5782 13 : $$ = (Node *) n;
5783 : }
5784 : ;
5785 :
5786 : opt_type:
5787 12 : TYPE_P Sconst { $$ = $2; }
5788 178 : | /*EMPTY*/ { $$ = NULL; }
5789 : ;
5790 :
5791 :
5792 : foreign_server_version:
5793 44 : VERSION_P Sconst { $$ = $2; }
5794 0 : | VERSION_P NULL_P { $$ = NULL; }
5795 : ;
5796 :
5797 : opt_foreign_server_version:
5798 12 : foreign_server_version { $$ = $1; }
5799 178 : | /*EMPTY*/ { $$ = NULL; }
5800 : ;
5801 :
5802 : /*****************************************************************************
5803 : *
5804 : * QUERY :
5805 : * ALTER SERVER name [VERSION] [OPTIONS]
5806 : *
5807 : ****************************************************************************/
5808 :
5809 : AlterForeignServerStmt: ALTER SERVER name foreign_server_version alter_generic_options
5810 : {
5811 4 : AlterForeignServerStmt *n = makeNode(AlterForeignServerStmt);
5812 :
5813 4 : n->servername = $3;
5814 4 : n->version = $4;
5815 4 : n->options = $5;
5816 4 : n->has_version = true;
5817 4 : $$ = (Node *) n;
5818 : }
5819 : | ALTER SERVER name foreign_server_version
5820 : {
5821 28 : AlterForeignServerStmt *n = makeNode(AlterForeignServerStmt);
5822 :
5823 28 : n->servername = $3;
5824 28 : n->version = $4;
5825 28 : n->has_version = true;
5826 28 : $$ = (Node *) n;
5827 : }
5828 : | ALTER SERVER name alter_generic_options
5829 : {
5830 97 : AlterForeignServerStmt *n = makeNode(AlterForeignServerStmt);
5831 :
5832 97 : n->servername = $3;
5833 97 : n->options = $4;
5834 97 : $$ = (Node *) n;
5835 : }
5836 : ;
5837 :
5838 : /*****************************************************************************
5839 : *
5840 : * QUERY:
5841 : * CREATE FOREIGN TABLE relname (...) SERVER name (...)
5842 : *
5843 : *****************************************************************************/
5844 :
5845 : CreateForeignTableStmt:
5846 : CREATE FOREIGN TABLE qualified_name
5847 : '(' OptTableElementList ')'
5848 : OptInherit SERVER name create_generic_options
5849 : {
5850 242 : CreateForeignTableStmt *n = makeNode(CreateForeignTableStmt);
5851 :
5852 242 : $4->relpersistence = RELPERSISTENCE_PERMANENT;
5853 242 : n->base.relation = $4;
5854 242 : n->base.tableElts = $6;
5855 242 : n->base.inhRelations = $8;
5856 242 : n->base.ofTypename = NULL;
5857 242 : n->base.constraints = NIL;
5858 242 : n->base.options = NIL;
5859 242 : n->base.oncommit = ONCOMMIT_NOOP;
5860 242 : n->base.tablespacename = NULL;
5861 242 : n->base.if_not_exists = false;
5862 : /* FDW-specific data */
5863 242 : n->servername = $10;
5864 242 : n->options = $11;
5865 242 : $$ = (Node *) n;
5866 : }
5867 : | CREATE FOREIGN TABLE IF_P NOT EXISTS qualified_name
5868 : '(' OptTableElementList ')'
5869 : OptInherit SERVER name create_generic_options
5870 : {
5871 0 : CreateForeignTableStmt *n = makeNode(CreateForeignTableStmt);
5872 :
5873 0 : $7->relpersistence = RELPERSISTENCE_PERMANENT;
5874 0 : n->base.relation = $7;
5875 0 : n->base.tableElts = $9;
5876 0 : n->base.inhRelations = $11;
5877 0 : n->base.ofTypename = NULL;
5878 0 : n->base.constraints = NIL;
5879 0 : n->base.options = NIL;
5880 0 : n->base.oncommit = ONCOMMIT_NOOP;
5881 0 : n->base.tablespacename = NULL;
5882 0 : n->base.if_not_exists = true;
5883 : /* FDW-specific data */
5884 0 : n->servername = $13;
5885 0 : n->options = $14;
5886 0 : $$ = (Node *) n;
5887 : }
5888 : | CREATE FOREIGN TABLE qualified_name
5889 : PARTITION OF qualified_name OptTypedTableElementList PartitionBoundSpec
5890 : SERVER name create_generic_options
5891 : {
5892 53 : CreateForeignTableStmt *n = makeNode(CreateForeignTableStmt);
5893 :
5894 53 : $4->relpersistence = RELPERSISTENCE_PERMANENT;
5895 53 : n->base.relation = $4;
5896 53 : n->base.inhRelations = list_make1($7);
5897 53 : n->base.tableElts = $8;
5898 53 : n->base.partbound = $9;
5899 53 : n->base.ofTypename = NULL;
5900 53 : n->base.constraints = NIL;
5901 53 : n->base.options = NIL;
5902 53 : n->base.oncommit = ONCOMMIT_NOOP;
5903 53 : n->base.tablespacename = NULL;
5904 53 : n->base.if_not_exists = false;
5905 : /* FDW-specific data */
5906 53 : n->servername = $11;
5907 53 : n->options = $12;
5908 53 : $$ = (Node *) n;
5909 : }
5910 : | CREATE FOREIGN TABLE IF_P NOT EXISTS qualified_name
5911 : PARTITION OF qualified_name OptTypedTableElementList PartitionBoundSpec
5912 : SERVER name create_generic_options
5913 : {
5914 0 : CreateForeignTableStmt *n = makeNode(CreateForeignTableStmt);
5915 :
5916 0 : $7->relpersistence = RELPERSISTENCE_PERMANENT;
5917 0 : n->base.relation = $7;
5918 0 : n->base.inhRelations = list_make1($10);
5919 0 : n->base.tableElts = $11;
5920 0 : n->base.partbound = $12;
5921 0 : n->base.ofTypename = NULL;
5922 0 : n->base.constraints = NIL;
5923 0 : n->base.options = NIL;
5924 0 : n->base.oncommit = ONCOMMIT_NOOP;
5925 0 : n->base.tablespacename = NULL;
5926 0 : n->base.if_not_exists = true;
5927 : /* FDW-specific data */
5928 0 : n->servername = $14;
5929 0 : n->options = $15;
5930 0 : $$ = (Node *) n;
5931 : }
5932 : ;
5933 :
5934 : /*****************************************************************************
5935 : *
5936 : * QUERY:
5937 : * IMPORT FOREIGN SCHEMA remote_schema
5938 : * [ { LIMIT TO | EXCEPT } ( table_list ) ]
5939 : * FROM SERVER server_name INTO local_schema [ OPTIONS (...) ]
5940 : *
5941 : ****************************************************************************/
5942 :
5943 : ImportForeignSchemaStmt:
5944 : IMPORT_P FOREIGN SCHEMA name import_qualification
5945 : FROM SERVER name INTO name create_generic_options
5946 : {
5947 28 : ImportForeignSchemaStmt *n = makeNode(ImportForeignSchemaStmt);
5948 :
5949 28 : n->server_name = $8;
5950 28 : n->remote_schema = $4;
5951 28 : n->local_schema = $10;
5952 28 : n->list_type = $5->type;
5953 28 : n->table_list = $5->table_names;
5954 28 : n->options = $11;
5955 28 : $$ = (Node *) n;
5956 : }
5957 : ;
5958 :
5959 : import_qualification_type:
5960 8 : LIMIT TO { $$ = FDW_IMPORT_SCHEMA_LIMIT_TO; }
5961 9 : | EXCEPT { $$ = FDW_IMPORT_SCHEMA_EXCEPT; }
5962 : ;
5963 :
5964 : import_qualification:
5965 : import_qualification_type '(' relation_expr_list ')'
5966 : {
5967 17 : ImportQual *n = palloc_object(ImportQual);
5968 :
5969 17 : n->type = $1;
5970 17 : n->table_names = $3;
5971 17 : $$ = n;
5972 : }
5973 : | /*EMPTY*/
5974 : {
5975 11 : ImportQual *n = palloc_object(ImportQual);
5976 11 : n->type = FDW_IMPORT_SCHEMA_ALL;
5977 11 : n->table_names = NIL;
5978 11 : $$ = n;
5979 : }
5980 : ;
5981 :
5982 : /*****************************************************************************
5983 : *
5984 : * QUERY:
5985 : * CREATE USER MAPPING FOR auth_ident SERVER name [OPTIONS]
5986 : *
5987 : *****************************************************************************/
5988 :
5989 : CreateUserMappingStmt: CREATE USER MAPPING FOR auth_ident SERVER name create_generic_options
5990 : {
5991 158 : CreateUserMappingStmt *n = makeNode(CreateUserMappingStmt);
5992 :
5993 158 : n->user = $5;
5994 158 : n->servername = $7;
5995 158 : n->options = $8;
5996 158 : n->if_not_exists = false;
5997 158 : $$ = (Node *) n;
5998 : }
5999 : | CREATE USER MAPPING IF_P NOT EXISTS FOR auth_ident SERVER name create_generic_options
6000 : {
6001 4 : CreateUserMappingStmt *n = makeNode(CreateUserMappingStmt);
6002 :
6003 4 : n->user = $8;
6004 4 : n->servername = $10;
6005 4 : n->options = $11;
6006 4 : n->if_not_exists = true;
6007 4 : $$ = (Node *) n;
6008 : }
6009 : ;
6010 :
6011 : /* User mapping authorization identifier */
6012 282 : auth_ident: RoleSpec { $$ = $1; }
6013 29 : | USER { $$ = makeRoleSpec(ROLESPEC_CURRENT_USER, @1); }
6014 : ;
6015 :
6016 : /*****************************************************************************
6017 : *
6018 : * QUERY :
6019 : * DROP USER MAPPING FOR auth_ident SERVER name
6020 : *
6021 : * XXX you'd think this should have a CASCADE/RESTRICT option, even if it's
6022 : * only pro forma; but the SQL standard doesn't show one.
6023 : ****************************************************************************/
6024 :
6025 : DropUserMappingStmt: DROP USER MAPPING FOR auth_ident SERVER name
6026 : {
6027 57 : DropUserMappingStmt *n = makeNode(DropUserMappingStmt);
6028 :
6029 57 : n->user = $5;
6030 57 : n->servername = $7;
6031 57 : n->missing_ok = false;
6032 57 : $$ = (Node *) n;
6033 : }
6034 : | DROP USER MAPPING IF_P EXISTS FOR auth_ident SERVER name
6035 : {
6036 22 : DropUserMappingStmt *n = makeNode(DropUserMappingStmt);
6037 :
6038 22 : n->user = $7;
6039 22 : n->servername = $9;
6040 22 : n->missing_ok = true;
6041 22 : $$ = (Node *) n;
6042 : }
6043 : ;
6044 :
6045 : /*****************************************************************************
6046 : *
6047 : * QUERY :
6048 : * ALTER USER MAPPING FOR auth_ident SERVER name OPTIONS
6049 : *
6050 : ****************************************************************************/
6051 :
6052 : AlterUserMappingStmt: ALTER USER MAPPING FOR auth_ident SERVER name alter_generic_options
6053 : {
6054 70 : AlterUserMappingStmt *n = makeNode(AlterUserMappingStmt);
6055 :
6056 70 : n->user = $5;
6057 70 : n->servername = $7;
6058 70 : n->options = $8;
6059 70 : $$ = (Node *) n;
6060 : }
6061 : ;
6062 :
6063 : /*****************************************************************************
6064 : *
6065 : * QUERIES:
6066 : * CREATE POLICY name ON table
6067 : * [AS { PERMISSIVE | RESTRICTIVE } ]
6068 : * [FOR { SELECT | INSERT | UPDATE | DELETE } ]
6069 : * [TO role, ...]
6070 : * [USING (qual)] [WITH CHECK (with check qual)]
6071 : * ALTER POLICY name ON table [TO role, ...]
6072 : * [USING (qual)] [WITH CHECK (with check qual)]
6073 : *
6074 : *****************************************************************************/
6075 :
6076 : CreatePolicyStmt:
6077 : CREATE POLICY name ON qualified_name RowSecurityDefaultPermissive
6078 : RowSecurityDefaultForCmd RowSecurityDefaultToRole
6079 : RowSecurityOptionalExpr RowSecurityOptionalWithCheck
6080 : {
6081 567 : CreatePolicyStmt *n = makeNode(CreatePolicyStmt);
6082 :
6083 567 : n->policy_name = $3;
6084 567 : n->table = $5;
6085 567 : n->permissive = $6;
6086 567 : n->cmd_name = $7;
6087 567 : n->roles = $8;
6088 567 : n->qual = $9;
6089 567 : n->with_check = $10;
6090 567 : $$ = (Node *) n;
6091 : }
6092 : ;
6093 :
6094 : AlterPolicyStmt:
6095 : ALTER POLICY name ON qualified_name RowSecurityOptionalToRole
6096 : RowSecurityOptionalExpr RowSecurityOptionalWithCheck
6097 : {
6098 56 : AlterPolicyStmt *n = makeNode(AlterPolicyStmt);
6099 :
6100 56 : n->policy_name = $3;
6101 56 : n->table = $5;
6102 56 : n->roles = $6;
6103 56 : n->qual = $7;
6104 56 : n->with_check = $8;
6105 56 : $$ = (Node *) n;
6106 : }
6107 : ;
6108 :
6109 : RowSecurityOptionalExpr:
6110 577 : USING '(' a_expr ')' { $$ = $3; }
6111 46 : | /* EMPTY */ { $$ = NULL; }
6112 : ;
6113 :
6114 : RowSecurityOptionalWithCheck:
6115 99 : WITH CHECK '(' a_expr ')' { $$ = $4; }
6116 524 : | /* EMPTY */ { $$ = NULL; }
6117 : ;
6118 :
6119 : RowSecurityDefaultToRole:
6120 117 : TO role_list { $$ = $2; }
6121 450 : | /* EMPTY */ { $$ = list_make1(makeRoleSpec(ROLESPEC_PUBLIC, -1)); }
6122 : ;
6123 :
6124 : RowSecurityOptionalToRole:
6125 8 : TO role_list { $$ = $2; }
6126 48 : | /* EMPTY */ { $$ = NULL; }
6127 : ;
6128 :
6129 : RowSecurityDefaultPermissive:
6130 : AS IDENT
6131 : {
6132 105 : if (strcmp($2, "permissive") == 0)
6133 36 : $$ = true;
6134 69 : else if (strcmp($2, "restrictive") == 0)
6135 65 : $$ = false;
6136 : else
6137 4 : ereport(ERROR,
6138 : (errcode(ERRCODE_SYNTAX_ERROR),
6139 : errmsg("unrecognized row security option \"%s\"", $2),
6140 : errhint("Only PERMISSIVE or RESTRICTIVE policies are supported currently."),
6141 : parser_errposition(@2)));
6142 :
6143 : }
6144 466 : | /* EMPTY */ { $$ = true; }
6145 : ;
6146 :
6147 : RowSecurityDefaultForCmd:
6148 253 : FOR row_security_cmd { $$ = $2; }
6149 314 : | /* EMPTY */ { $$ = "all"; }
6150 : ;
6151 :
6152 : row_security_cmd:
6153 29 : ALL { $$ = "all"; }
6154 93 : | SELECT { $$ = "select"; }
6155 37 : | INSERT { $$ = "insert"; }
6156 63 : | UPDATE { $$ = "update"; }
6157 31 : | DELETE_P { $$ = "delete"; }
6158 : ;
6159 :
6160 : /*****************************************************************************
6161 : *
6162 : * QUERY:
6163 : * CREATE ACCESS METHOD name HANDLER handler_name
6164 : *
6165 : *****************************************************************************/
6166 :
6167 : CreateAmStmt: CREATE ACCESS METHOD name TYPE_P am_type HANDLER handler_name
6168 : {
6169 46 : CreateAmStmt *n = makeNode(CreateAmStmt);
6170 :
6171 46 : n->amname = $4;
6172 46 : n->handler_name = $8;
6173 46 : n->amtype = $6;
6174 46 : $$ = (Node *) n;
6175 : }
6176 : ;
6177 :
6178 : am_type:
6179 20 : INDEX { $$ = AMTYPE_INDEX; }
6180 26 : | TABLE { $$ = AMTYPE_TABLE; }
6181 : ;
6182 :
6183 : /*****************************************************************************
6184 : *
6185 : * QUERIES :
6186 : * CREATE TRIGGER ...
6187 : *
6188 : *****************************************************************************/
6189 :
6190 : CreateTrigStmt:
6191 : CREATE opt_or_replace TRIGGER name TriggerActionTime TriggerEvents ON
6192 : qualified_name TriggerReferencing TriggerForSpec TriggerWhen
6193 : EXECUTE FUNCTION_or_PROCEDURE func_name '(' TriggerFuncArgs ')'
6194 : {
6195 2077 : CreateTrigStmt *n = makeNode(CreateTrigStmt);
6196 :
6197 2077 : n->replace = $2;
6198 2077 : n->isconstraint = false;
6199 2077 : n->trigname = $4;
6200 2077 : n->relation = $8;
6201 2077 : n->funcname = $14;
6202 2077 : n->args = $16;
6203 2077 : n->row = $10;
6204 2077 : n->timing = $5;
6205 2077 : n->events = intVal(linitial($6));
6206 2077 : n->columns = (List *) lsecond($6);
6207 2077 : n->whenClause = $11;
6208 2077 : n->transitionRels = $9;
6209 2077 : n->deferrable = false;
6210 2077 : n->initdeferred = false;
6211 2077 : n->constrrel = NULL;
6212 2077 : $$ = (Node *) n;
6213 : }
6214 : | CREATE opt_or_replace CONSTRAINT TRIGGER name AFTER TriggerEvents ON
6215 : qualified_name OptConstrFromTable ConstraintAttributeSpec
6216 : FOR EACH ROW TriggerWhen
6217 : EXECUTE FUNCTION_or_PROCEDURE func_name '(' TriggerFuncArgs ')'
6218 : {
6219 65 : CreateTrigStmt *n = makeNode(CreateTrigStmt);
6220 : bool dummy;
6221 :
6222 65 : if (($11 & CAS_NOT_VALID) != 0)
6223 4 : ereport(ERROR,
6224 : errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
6225 : errmsg("constraint triggers cannot be marked %s",
6226 : "NOT VALID"),
6227 : parser_errposition(@11));
6228 61 : if (($11 & CAS_NO_INHERIT) != 0)
6229 4 : ereport(ERROR,
6230 : errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
6231 : errmsg("constraint triggers cannot be marked %s",
6232 : "NO INHERIT"),
6233 : parser_errposition(@11));
6234 57 : if (($11 & CAS_NOT_ENFORCED) != 0)
6235 4 : ereport(ERROR,
6236 : errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
6237 : errmsg("constraint triggers cannot be marked %s",
6238 : "NOT ENFORCED"),
6239 : parser_errposition(@11));
6240 :
6241 53 : n->replace = $2;
6242 53 : if (n->replace) /* not supported, see CreateTrigger */
6243 0 : ereport(ERROR,
6244 : (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
6245 : errmsg("CREATE OR REPLACE CONSTRAINT TRIGGER is not supported"),
6246 : parser_errposition(@1)));
6247 53 : n->isconstraint = true;
6248 53 : n->trigname = $5;
6249 53 : n->relation = $9;
6250 53 : n->funcname = $18;
6251 53 : n->args = $20;
6252 53 : n->row = true;
6253 53 : n->timing = TRIGGER_TYPE_AFTER;
6254 53 : n->events = intVal(linitial($7));
6255 53 : n->columns = (List *) lsecond($7);
6256 53 : n->whenClause = $15;
6257 53 : n->transitionRels = NIL;
6258 53 : processCASbits($11, @11, "TRIGGER",
6259 : &n->deferrable, &n->initdeferred, &dummy,
6260 : NULL, NULL, yyscanner);
6261 53 : n->constrrel = $10;
6262 53 : $$ = (Node *) n;
6263 : }
6264 : ;
6265 :
6266 : TriggerActionTime:
6267 910 : BEFORE { $$ = TRIGGER_TYPE_BEFORE; }
6268 1080 : | AFTER { $$ = TRIGGER_TYPE_AFTER; }
6269 95 : | INSTEAD OF { $$ = TRIGGER_TYPE_INSTEAD; }
6270 : ;
6271 :
6272 : TriggerEvents:
6273 : TriggerOneEvent
6274 2150 : { $$ = $1; }
6275 : | TriggerEvents OR TriggerOneEvent
6276 : {
6277 727 : int events1 = intVal(linitial($1));
6278 727 : int events2 = intVal(linitial($3));
6279 727 : List *columns1 = (List *) lsecond($1);
6280 727 : List *columns2 = (List *) lsecond($3);
6281 :
6282 727 : if (events1 & events2)
6283 4 : parser_yyerror("duplicate trigger events specified");
6284 : /*
6285 : * concat'ing the columns lists loses information about
6286 : * which columns went with which event, but so long as
6287 : * only UPDATE carries columns and we disallow multiple
6288 : * UPDATE items, it doesn't matter. Command execution
6289 : * should just ignore the columns for non-UPDATE events.
6290 : */
6291 723 : $$ = list_make2(makeInteger(events1 | events2),
6292 : list_concat(columns1, columns2));
6293 : }
6294 : ;
6295 :
6296 : TriggerOneEvent:
6297 : INSERT
6298 1127 : { $$ = list_make2(makeInteger(TRIGGER_TYPE_INSERT), NIL); }
6299 : | DELETE_P
6300 581 : { $$ = list_make2(makeInteger(TRIGGER_TYPE_DELETE), NIL); }
6301 : | UPDATE
6302 1080 : { $$ = list_make2(makeInteger(TRIGGER_TYPE_UPDATE), NIL); }
6303 : | UPDATE OF columnList
6304 65 : { $$ = list_make2(makeInteger(TRIGGER_TYPE_UPDATE), $3); }
6305 : | TRUNCATE
6306 24 : { $$ = list_make2(makeInteger(TRIGGER_TYPE_TRUNCATE), NIL); }
6307 : ;
6308 :
6309 : TriggerReferencing:
6310 328 : REFERENCING TriggerTransitions { $$ = $2; }
6311 1749 : | /*EMPTY*/ { $$ = NIL; }
6312 : ;
6313 :
6314 : TriggerTransitions:
6315 328 : TriggerTransition { $$ = list_make1($1); }
6316 100 : | TriggerTransitions TriggerTransition { $$ = lappend($1, $2); }
6317 : ;
6318 :
6319 : TriggerTransition:
6320 : TransitionOldOrNew TransitionRowOrTable opt_as TransitionRelName
6321 : {
6322 428 : TriggerTransition *n = makeNode(TriggerTransition);
6323 :
6324 428 : n->name = $4;
6325 428 : n->isNew = $1;
6326 428 : n->isTable = $2;
6327 428 : $$ = (Node *) n;
6328 : }
6329 : ;
6330 :
6331 : TransitionOldOrNew:
6332 232 : NEW { $$ = true; }
6333 196 : | OLD { $$ = false; }
6334 : ;
6335 :
6336 : TransitionRowOrTable:
6337 428 : TABLE { $$ = true; }
6338 : /*
6339 : * According to the standard, lack of a keyword here implies ROW.
6340 : * Support for that would require prohibiting ROW entirely here,
6341 : * reserving the keyword ROW, and/or requiring AS (instead of
6342 : * allowing it to be optional, as the standard specifies) as the
6343 : * next token. Requiring ROW seems cleanest and easiest to
6344 : * explain.
6345 : */
6346 0 : | ROW { $$ = false; }
6347 : ;
6348 :
6349 : TransitionRelName:
6350 428 : ColId { $$ = $1; }
6351 : ;
6352 :
6353 : TriggerForSpec:
6354 : FOR TriggerForOptEach TriggerForType
6355 : {
6356 1943 : $$ = $3;
6357 : }
6358 : | /* EMPTY */
6359 : {
6360 : /*
6361 : * If ROW/STATEMENT not specified, default to
6362 : * STATEMENT, per SQL
6363 : */
6364 134 : $$ = false;
6365 : }
6366 : ;
6367 :
6368 : TriggerForOptEach:
6369 : EACH
6370 : | /*EMPTY*/
6371 : ;
6372 :
6373 : TriggerForType:
6374 1367 : ROW { $$ = true; }
6375 576 : | STATEMENT { $$ = false; }
6376 : ;
6377 :
6378 : TriggerWhen:
6379 124 : WHEN '(' a_expr ')' { $$ = $3; }
6380 2018 : | /*EMPTY*/ { $$ = NULL; }
6381 : ;
6382 :
6383 : FUNCTION_or_PROCEDURE:
6384 : FUNCTION
6385 : | PROCEDURE
6386 : ;
6387 :
6388 : TriggerFuncArgs:
6389 453 : TriggerFuncArg { $$ = list_make1($1); }
6390 162 : | TriggerFuncArgs ',' TriggerFuncArg { $$ = lappend($1, $3); }
6391 1689 : | /*EMPTY*/ { $$ = NIL; }
6392 : ;
6393 :
6394 : TriggerFuncArg:
6395 : Iconst
6396 : {
6397 51 : $$ = (Node *) makeString(psprintf("%d", $1));
6398 : }
6399 0 : | FCONST { $$ = (Node *) makeString($1); }
6400 399 : | Sconst { $$ = (Node *) makeString($1); }
6401 165 : | ColLabel { $$ = (Node *) makeString($1); }
6402 : ;
6403 :
6404 : OptConstrFromTable:
6405 8 : FROM qualified_name { $$ = $2; }
6406 57 : | /*EMPTY*/ { $$ = NULL; }
6407 : ;
6408 :
6409 : ConstraintAttributeSpec:
6410 : /*EMPTY*/
6411 11786 : { $$ = 0; }
6412 : | ConstraintAttributeSpec ConstraintAttributeElem
6413 : {
6414 : /*
6415 : * We must complain about conflicting options.
6416 : * We could, but choose not to, complain about redundant
6417 : * options (ie, where $2's bit is already set in $1).
6418 : */
6419 1240 : int newspec = $1 | $2;
6420 :
6421 : /* special message for this case */
6422 1240 : if ((newspec & (CAS_NOT_DEFERRABLE | CAS_INITIALLY_DEFERRED)) == (CAS_NOT_DEFERRABLE | CAS_INITIALLY_DEFERRED))
6423 4 : ereport(ERROR,
6424 : (errcode(ERRCODE_SYNTAX_ERROR),
6425 : errmsg("constraint declared INITIALLY DEFERRED must be DEFERRABLE"),
6426 : parser_errposition(@2)));
6427 : /* generic message for other conflicts */
6428 1236 : if ((newspec & (CAS_NOT_DEFERRABLE | CAS_DEFERRABLE)) == (CAS_NOT_DEFERRABLE | CAS_DEFERRABLE) ||
6429 1236 : (newspec & (CAS_INITIALLY_IMMEDIATE | CAS_INITIALLY_DEFERRED)) == (CAS_INITIALLY_IMMEDIATE | CAS_INITIALLY_DEFERRED) ||
6430 1236 : (newspec & (CAS_NOT_ENFORCED | CAS_ENFORCED)) == (CAS_NOT_ENFORCED | CAS_ENFORCED))
6431 4 : ereport(ERROR,
6432 : (errcode(ERRCODE_SYNTAX_ERROR),
6433 : errmsg("conflicting constraint properties"),
6434 : parser_errposition(@2)));
6435 1232 : $$ = newspec;
6436 : }
6437 : ;
6438 :
6439 : ConstraintAttributeElem:
6440 32 : NOT DEFERRABLE { $$ = CAS_NOT_DEFERRABLE; }
6441 148 : | DEFERRABLE { $$ = CAS_DEFERRABLE; }
6442 20 : | INITIALLY IMMEDIATE { $$ = CAS_INITIALLY_IMMEDIATE; }
6443 116 : | INITIALLY DEFERRED { $$ = CAS_INITIALLY_DEFERRED; }
6444 442 : | NOT VALID { $$ = CAS_NOT_VALID; }
6445 167 : | NO INHERIT { $$ = CAS_NO_INHERIT; }
6446 171 : | NOT ENFORCED { $$ = CAS_NOT_ENFORCED; }
6447 144 : | ENFORCED { $$ = CAS_ENFORCED; }
6448 : ;
6449 :
6450 :
6451 : /*****************************************************************************
6452 : *
6453 : * QUERIES :
6454 : * CREATE EVENT TRIGGER ...
6455 : * ALTER EVENT TRIGGER ...
6456 : *
6457 : *****************************************************************************/
6458 :
6459 : CreateEventTrigStmt:
6460 : CREATE EVENT TRIGGER name ON ColLabel
6461 : EXECUTE FUNCTION_or_PROCEDURE func_name '(' ')'
6462 : {
6463 63 : CreateEventTrigStmt *n = makeNode(CreateEventTrigStmt);
6464 :
6465 63 : n->trigname = $4;
6466 63 : n->eventname = $6;
6467 63 : n->whenclause = NULL;
6468 63 : n->funcname = $9;
6469 63 : $$ = (Node *) n;
6470 : }
6471 : | CREATE EVENT TRIGGER name ON ColLabel
6472 : WHEN event_trigger_when_list
6473 : EXECUTE FUNCTION_or_PROCEDURE func_name '(' ')'
6474 : {
6475 65 : CreateEventTrigStmt *n = makeNode(CreateEventTrigStmt);
6476 :
6477 65 : n->trigname = $4;
6478 65 : n->eventname = $6;
6479 65 : n->whenclause = $8;
6480 65 : n->funcname = $11;
6481 65 : $$ = (Node *) n;
6482 : }
6483 : ;
6484 :
6485 : event_trigger_when_list:
6486 : event_trigger_when_item
6487 65 : { $$ = list_make1($1); }
6488 : | event_trigger_when_list AND event_trigger_when_item
6489 4 : { $$ = lappend($1, $3); }
6490 : ;
6491 :
6492 : event_trigger_when_item:
6493 : ColId IN_P '(' event_trigger_value_list ')'
6494 69 : { $$ = makeDefElem($1, (Node *) $4, @1); }
6495 : ;
6496 :
6497 : event_trigger_value_list:
6498 : SCONST
6499 69 : { $$ = list_make1(makeString($1)); }
6500 : | event_trigger_value_list ',' SCONST
6501 44 : { $$ = lappend($1, makeString($3)); }
6502 : ;
6503 :
6504 : AlterEventTrigStmt:
6505 : ALTER EVENT TRIGGER name enable_trigger
6506 : {
6507 31 : AlterEventTrigStmt *n = makeNode(AlterEventTrigStmt);
6508 :
6509 31 : n->trigname = $4;
6510 31 : n->tgenabled = $5;
6511 31 : $$ = (Node *) n;
6512 : }
6513 : ;
6514 :
6515 : enable_trigger:
6516 4 : ENABLE_P { $$ = TRIGGER_FIRES_ON_ORIGIN; }
6517 4 : | ENABLE_P REPLICA { $$ = TRIGGER_FIRES_ON_REPLICA; }
6518 10 : | ENABLE_P ALWAYS { $$ = TRIGGER_FIRES_ALWAYS; }
6519 13 : | DISABLE_P { $$ = TRIGGER_DISABLED; }
6520 : ;
6521 :
6522 : /*****************************************************************************
6523 : *
6524 : * QUERY :
6525 : * CREATE ASSERTION ...
6526 : *
6527 : *****************************************************************************/
6528 :
6529 : CreateAssertionStmt:
6530 : CREATE ASSERTION any_name CHECK '(' a_expr ')' ConstraintAttributeSpec
6531 : {
6532 0 : ereport(ERROR,
6533 : (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
6534 : errmsg("CREATE ASSERTION is not yet implemented"),
6535 : parser_errposition(@1)));
6536 :
6537 : $$ = NULL;
6538 : }
6539 : ;
6540 :
6541 :
6542 : /*****************************************************************************
6543 : *
6544 : * QUERY :
6545 : * define (aggregate,operator,type)
6546 : *
6547 : *****************************************************************************/
6548 :
6549 : DefineStmt:
6550 : CREATE opt_or_replace AGGREGATE func_name aggr_args definition
6551 : {
6552 345 : DefineStmt *n = makeNode(DefineStmt);
6553 :
6554 345 : n->kind = OBJECT_AGGREGATE;
6555 345 : n->oldstyle = false;
6556 345 : n->replace = $2;
6557 345 : n->defnames = $4;
6558 345 : n->args = $5;
6559 345 : n->definition = $6;
6560 345 : $$ = (Node *) n;
6561 : }
6562 : | CREATE opt_or_replace AGGREGATE func_name old_aggr_definition
6563 : {
6564 : /* old-style (pre-8.2) syntax for CREATE AGGREGATE */
6565 240 : DefineStmt *n = makeNode(DefineStmt);
6566 :
6567 240 : n->kind = OBJECT_AGGREGATE;
6568 240 : n->oldstyle = true;
6569 240 : n->replace = $2;
6570 240 : n->defnames = $4;
6571 240 : n->args = NIL;
6572 240 : n->definition = $5;
6573 240 : $$ = (Node *) n;
6574 : }
6575 : | CREATE OPERATOR any_operator definition
6576 : {
6577 893 : DefineStmt *n = makeNode(DefineStmt);
6578 :
6579 893 : n->kind = OBJECT_OPERATOR;
6580 893 : n->oldstyle = false;
6581 893 : n->defnames = $3;
6582 893 : n->args = NIL;
6583 893 : n->definition = $4;
6584 893 : $$ = (Node *) n;
6585 : }
6586 : | CREATE TYPE_P any_name definition
6587 : {
6588 141 : DefineStmt *n = makeNode(DefineStmt);
6589 :
6590 141 : n->kind = OBJECT_TYPE;
6591 141 : n->oldstyle = false;
6592 141 : n->defnames = $3;
6593 141 : n->args = NIL;
6594 141 : n->definition = $4;
6595 141 : $$ = (Node *) n;
6596 : }
6597 : | CREATE TYPE_P any_name
6598 : {
6599 : /* Shell type (identified by lack of definition) */
6600 98 : DefineStmt *n = makeNode(DefineStmt);
6601 :
6602 98 : n->kind = OBJECT_TYPE;
6603 98 : n->oldstyle = false;
6604 98 : n->defnames = $3;
6605 98 : n->args = NIL;
6606 98 : n->definition = NIL;
6607 98 : $$ = (Node *) n;
6608 : }
6609 : | CREATE TYPE_P any_name AS '(' OptTableFuncElementList ')'
6610 : {
6611 2363 : CompositeTypeStmt *n = makeNode(CompositeTypeStmt);
6612 :
6613 : /* can't use qualified_name, sigh */
6614 2363 : n->typevar = makeRangeVarFromAnyName($3, @3, yyscanner);
6615 2363 : n->coldeflist = $6;
6616 2363 : $$ = (Node *) n;
6617 : }
6618 : | CREATE TYPE_P any_name AS ENUM_P '(' opt_enum_val_list ')'
6619 : {
6620 133 : CreateEnumStmt *n = makeNode(CreateEnumStmt);
6621 :
6622 133 : n->typeName = $3;
6623 133 : n->vals = $7;
6624 133 : $$ = (Node *) n;
6625 : }
6626 : | CREATE TYPE_P any_name AS RANGE definition
6627 : {
6628 136 : CreateRangeStmt *n = makeNode(CreateRangeStmt);
6629 :
6630 136 : n->typeName = $3;
6631 136 : n->params = $6;
6632 136 : $$ = (Node *) n;
6633 : }
6634 : | CREATE TEXT_P SEARCH PARSER any_name definition
6635 : {
6636 31 : DefineStmt *n = makeNode(DefineStmt);
6637 :
6638 31 : n->kind = OBJECT_TSPARSER;
6639 31 : n->args = NIL;
6640 31 : n->defnames = $5;
6641 31 : n->definition = $6;
6642 31 : $$ = (Node *) n;
6643 : }
6644 : | CREATE TEXT_P SEARCH DICTIONARY any_name definition
6645 : {
6646 1802 : DefineStmt *n = makeNode(DefineStmt);
6647 :
6648 1802 : n->kind = OBJECT_TSDICTIONARY;
6649 1802 : n->args = NIL;
6650 1802 : n->defnames = $5;
6651 1802 : n->definition = $6;
6652 1802 : $$ = (Node *) n;
6653 : }
6654 : | CREATE TEXT_P SEARCH TEMPLATE any_name definition
6655 : {
6656 87 : DefineStmt *n = makeNode(DefineStmt);
6657 :
6658 87 : n->kind = OBJECT_TSTEMPLATE;
6659 87 : n->args = NIL;
6660 87 : n->defnames = $5;
6661 87 : n->definition = $6;
6662 87 : $$ = (Node *) n;
6663 : }
6664 : | CREATE TEXT_P SEARCH CONFIGURATION any_name definition
6665 : {
6666 1766 : DefineStmt *n = makeNode(DefineStmt);
6667 :
6668 1766 : n->kind = OBJECT_TSCONFIGURATION;
6669 1766 : n->args = NIL;
6670 1766 : n->defnames = $5;
6671 1766 : n->definition = $6;
6672 1766 : $$ = (Node *) n;
6673 : }
6674 : | CREATE COLLATION any_name definition
6675 : {
6676 201 : DefineStmt *n = makeNode(DefineStmt);
6677 :
6678 201 : n->kind = OBJECT_COLLATION;
6679 201 : n->args = NIL;
6680 201 : n->defnames = $3;
6681 201 : n->definition = $4;
6682 201 : $$ = (Node *) n;
6683 : }
6684 : | CREATE COLLATION IF_P NOT EXISTS any_name definition
6685 : {
6686 9 : DefineStmt *n = makeNode(DefineStmt);
6687 :
6688 9 : n->kind = OBJECT_COLLATION;
6689 9 : n->args = NIL;
6690 9 : n->defnames = $6;
6691 9 : n->definition = $7;
6692 9 : n->if_not_exists = true;
6693 9 : $$ = (Node *) n;
6694 : }
6695 : | CREATE COLLATION any_name FROM any_name
6696 : {
6697 35 : DefineStmt *n = makeNode(DefineStmt);
6698 :
6699 35 : n->kind = OBJECT_COLLATION;
6700 35 : n->args = NIL;
6701 35 : n->defnames = $3;
6702 35 : n->definition = list_make1(makeDefElem("from", (Node *) $5, @5));
6703 35 : $$ = (Node *) n;
6704 : }
6705 : | CREATE COLLATION IF_P NOT EXISTS any_name FROM any_name
6706 : {
6707 0 : DefineStmt *n = makeNode(DefineStmt);
6708 :
6709 0 : n->kind = OBJECT_COLLATION;
6710 0 : n->args = NIL;
6711 0 : n->defnames = $6;
6712 0 : n->definition = list_make1(makeDefElem("from", (Node *) $8, @8));
6713 0 : n->if_not_exists = true;
6714 0 : $$ = (Node *) n;
6715 : }
6716 : ;
6717 :
6718 6150 : definition: '(' def_list ')' { $$ = $2; }
6719 : ;
6720 :
6721 6150 : def_list: def_elem { $$ = list_make1($1); }
6722 8506 : | def_list ',' def_elem { $$ = lappend($1, $3); }
6723 : ;
6724 :
6725 : def_elem: ColLabel '=' def_arg
6726 : {
6727 14461 : $$ = makeDefElem($1, (Node *) $3, @1);
6728 : }
6729 : | ColLabel
6730 : {
6731 195 : $$ = makeDefElem($1, NULL, @1);
6732 : }
6733 : ;
6734 :
6735 : /* Note: any simple identifier will be returned as a type name! */
6736 11695 : def_arg: func_type { $$ = (Node *) $1; }
6737 2679 : | reserved_keyword { $$ = (Node *) makeString(pstrdup($1)); }
6738 626 : | qual_all_Op { $$ = (Node *) $1; }
6739 876 : | NumericOnly { $$ = (Node *) $1; }
6740 1163 : | Sconst { $$ = (Node *) makeString($1); }
6741 133 : | NONE { $$ = (Node *) makeString(pstrdup($1)); }
6742 : ;
6743 :
6744 240 : old_aggr_definition: '(' old_aggr_list ')' { $$ = $2; }
6745 : ;
6746 :
6747 240 : old_aggr_list: old_aggr_elem { $$ = list_make1($1); }
6748 856 : | old_aggr_list ',' old_aggr_elem { $$ = lappend($1, $3); }
6749 : ;
6750 :
6751 : /*
6752 : * Must use IDENT here to avoid reduce/reduce conflicts; fortunately none of
6753 : * the item names needed in old aggregate definitions are likely to become
6754 : * SQL keywords.
6755 : */
6756 : old_aggr_elem: IDENT '=' def_arg
6757 : {
6758 1096 : $$ = makeDefElem($1, (Node *) $3, @1);
6759 : }
6760 : ;
6761 :
6762 : opt_enum_val_list:
6763 129 : enum_val_list { $$ = $1; }
6764 4 : | /*EMPTY*/ { $$ = NIL; }
6765 : ;
6766 :
6767 : enum_val_list: Sconst
6768 129 : { $$ = list_make1(makeString($1)); }
6769 : | enum_val_list ',' Sconst
6770 5263 : { $$ = lappend($1, makeString($3)); }
6771 : ;
6772 :
6773 : /*****************************************************************************
6774 : *
6775 : * ALTER TYPE enumtype ADD ...
6776 : *
6777 : *****************************************************************************/
6778 :
6779 : AlterEnumStmt:
6780 : ALTER TYPE_P any_name ADD_P VALUE_P opt_if_not_exists Sconst
6781 : {
6782 86 : AlterEnumStmt *n = makeNode(AlterEnumStmt);
6783 :
6784 86 : n->typeName = $3;
6785 86 : n->oldVal = NULL;
6786 86 : n->newVal = $7;
6787 86 : n->newValNeighbor = NULL;
6788 86 : n->newValIsAfter = true;
6789 86 : n->skipIfNewValExists = $6;
6790 86 : $$ = (Node *) n;
6791 : }
6792 : | ALTER TYPE_P any_name ADD_P VALUE_P opt_if_not_exists Sconst BEFORE Sconst
6793 : {
6794 130 : AlterEnumStmt *n = makeNode(AlterEnumStmt);
6795 :
6796 130 : n->typeName = $3;
6797 130 : n->oldVal = NULL;
6798 130 : n->newVal = $7;
6799 130 : n->newValNeighbor = $9;
6800 130 : n->newValIsAfter = false;
6801 130 : n->skipIfNewValExists = $6;
6802 130 : $$ = (Node *) n;
6803 : }
6804 : | ALTER TYPE_P any_name ADD_P VALUE_P opt_if_not_exists Sconst AFTER Sconst
6805 : {
6806 14 : AlterEnumStmt *n = makeNode(AlterEnumStmt);
6807 :
6808 14 : n->typeName = $3;
6809 14 : n->oldVal = NULL;
6810 14 : n->newVal = $7;
6811 14 : n->newValNeighbor = $9;
6812 14 : n->newValIsAfter = true;
6813 14 : n->skipIfNewValExists = $6;
6814 14 : $$ = (Node *) n;
6815 : }
6816 : | ALTER TYPE_P any_name RENAME VALUE_P Sconst TO Sconst
6817 : {
6818 16 : AlterEnumStmt *n = makeNode(AlterEnumStmt);
6819 :
6820 16 : n->typeName = $3;
6821 16 : n->oldVal = $6;
6822 16 : n->newVal = $8;
6823 16 : n->newValNeighbor = NULL;
6824 16 : n->newValIsAfter = false;
6825 16 : n->skipIfNewValExists = false;
6826 16 : $$ = (Node *) n;
6827 : }
6828 : | ALTER TYPE_P any_name DROP VALUE_P Sconst
6829 : {
6830 : /*
6831 : * The following problems must be solved before this can be
6832 : * implemented:
6833 : *
6834 : * - There must be no instance of the target value in
6835 : * any table.
6836 : *
6837 : * - The value must not appear in any catalog metadata,
6838 : * such as stored view expressions or column defaults.
6839 : *
6840 : * - The value must not appear in any non-leaf page of a
6841 : * btree (and similar issues with other index types).
6842 : * This is problematic because a value could persist
6843 : * there long after it's gone from user-visible data.
6844 : *
6845 : * - Concurrent sessions must not be able to insert the
6846 : * value while the preceding conditions are being checked.
6847 : *
6848 : * - Possibly more...
6849 : */
6850 0 : ereport(ERROR,
6851 : (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
6852 : errmsg("dropping an enum value is not implemented"),
6853 : parser_errposition(@4)));
6854 : }
6855 : ;
6856 :
6857 8 : opt_if_not_exists: IF_P NOT EXISTS { $$ = true; }
6858 222 : | /* EMPTY */ { $$ = false; }
6859 : ;
6860 :
6861 :
6862 : /*****************************************************************************
6863 : *
6864 : * QUERIES :
6865 : * CREATE OPERATOR CLASS ...
6866 : * CREATE OPERATOR FAMILY ...
6867 : * ALTER OPERATOR FAMILY ...
6868 : * DROP OPERATOR CLASS ...
6869 : * DROP OPERATOR FAMILY ...
6870 : *
6871 : *****************************************************************************/
6872 :
6873 : CreateOpClassStmt:
6874 : CREATE OPERATOR CLASS any_name opt_default FOR TYPE_P Typename
6875 : USING name opt_opfamily AS opclass_item_list
6876 : {
6877 295 : CreateOpClassStmt *n = makeNode(CreateOpClassStmt);
6878 :
6879 295 : n->opclassname = $4;
6880 295 : n->isDefault = $5;
6881 295 : n->datatype = $8;
6882 295 : n->amname = $10;
6883 295 : n->opfamilyname = $11;
6884 295 : n->items = $13;
6885 295 : $$ = (Node *) n;
6886 : }
6887 : ;
6888 :
6889 : opclass_item_list:
6890 533 : opclass_item { $$ = list_make1($1); }
6891 2994 : | opclass_item_list ',' opclass_item { $$ = lappend($1, $3); }
6892 : ;
6893 :
6894 : opclass_item:
6895 : OPERATOR Iconst any_operator opclass_purpose
6896 : {
6897 1063 : CreateOpClassItem *n = makeNode(CreateOpClassItem);
6898 1063 : ObjectWithArgs *owa = makeNode(ObjectWithArgs);
6899 :
6900 1063 : owa->objname = $3;
6901 1063 : owa->objargs = NIL;
6902 1063 : n->itemtype = OPCLASS_ITEM_OPERATOR;
6903 1063 : n->name = owa;
6904 1063 : n->number = $2;
6905 1063 : n->order_family = $4;
6906 1063 : $$ = (Node *) n;
6907 : }
6908 : | OPERATOR Iconst operator_with_argtypes opclass_purpose
6909 : {
6910 739 : CreateOpClassItem *n = makeNode(CreateOpClassItem);
6911 :
6912 739 : n->itemtype = OPCLASS_ITEM_OPERATOR;
6913 739 : n->name = $3;
6914 739 : n->number = $2;
6915 739 : n->order_family = $4;
6916 739 : $$ = (Node *) n;
6917 : }
6918 : | FUNCTION Iconst function_with_argtypes
6919 : {
6920 1419 : CreateOpClassItem *n = makeNode(CreateOpClassItem);
6921 :
6922 1419 : n->itemtype = OPCLASS_ITEM_FUNCTION;
6923 1419 : n->name = $3;
6924 1419 : n->number = $2;
6925 1419 : $$ = (Node *) n;
6926 : }
6927 : | FUNCTION Iconst '(' type_list ')' function_with_argtypes
6928 : {
6929 120 : CreateOpClassItem *n = makeNode(CreateOpClassItem);
6930 :
6931 120 : n->itemtype = OPCLASS_ITEM_FUNCTION;
6932 120 : n->name = $6;
6933 120 : n->number = $2;
6934 120 : n->class_args = $4;
6935 120 : $$ = (Node *) n;
6936 : }
6937 : | STORAGE Typename
6938 : {
6939 186 : CreateOpClassItem *n = makeNode(CreateOpClassItem);
6940 :
6941 186 : n->itemtype = OPCLASS_ITEM_STORAGETYPE;
6942 186 : n->storedtype = $2;
6943 186 : $$ = (Node *) n;
6944 : }
6945 : ;
6946 :
6947 226 : opt_default: DEFAULT { $$ = true; }
6948 111 : | /*EMPTY*/ { $$ = false; }
6949 : ;
6950 :
6951 22 : opt_opfamily: FAMILY any_name { $$ = $2; }
6952 273 : | /*EMPTY*/ { $$ = NIL; }
6953 : ;
6954 :
6955 0 : opclass_purpose: FOR SEARCH { $$ = NIL; }
6956 63 : | FOR ORDER BY any_name { $$ = $4; }
6957 1739 : | /*EMPTY*/ { $$ = NIL; }
6958 : ;
6959 :
6960 :
6961 : CreateOpFamilyStmt:
6962 : CREATE OPERATOR FAMILY any_name USING name
6963 : {
6964 95 : CreateOpFamilyStmt *n = makeNode(CreateOpFamilyStmt);
6965 :
6966 95 : n->opfamilyname = $4;
6967 95 : n->amname = $6;
6968 95 : $$ = (Node *) n;
6969 : }
6970 : ;
6971 :
6972 : AlterOpFamilyStmt:
6973 : ALTER OPERATOR FAMILY any_name USING name ADD_P opclass_item_list
6974 : {
6975 238 : AlterOpFamilyStmt *n = makeNode(AlterOpFamilyStmt);
6976 :
6977 238 : n->opfamilyname = $4;
6978 238 : n->amname = $6;
6979 238 : n->isDrop = false;
6980 238 : n->items = $8;
6981 238 : $$ = (Node *) n;
6982 : }
6983 : | ALTER OPERATOR FAMILY any_name USING name DROP opclass_drop_list
6984 : {
6985 38 : AlterOpFamilyStmt *n = makeNode(AlterOpFamilyStmt);
6986 :
6987 38 : n->opfamilyname = $4;
6988 38 : n->amname = $6;
6989 38 : n->isDrop = true;
6990 38 : n->items = $8;
6991 38 : $$ = (Node *) n;
6992 : }
6993 : ;
6994 :
6995 : opclass_drop_list:
6996 38 : opclass_drop { $$ = list_make1($1); }
6997 20 : | opclass_drop_list ',' opclass_drop { $$ = lappend($1, $3); }
6998 : ;
6999 :
7000 : opclass_drop:
7001 : OPERATOR Iconst '(' type_list ')'
7002 : {
7003 36 : CreateOpClassItem *n = makeNode(CreateOpClassItem);
7004 :
7005 36 : n->itemtype = OPCLASS_ITEM_OPERATOR;
7006 36 : n->number = $2;
7007 36 : n->class_args = $4;
7008 36 : $$ = (Node *) n;
7009 : }
7010 : | FUNCTION Iconst '(' type_list ')'
7011 : {
7012 22 : CreateOpClassItem *n = makeNode(CreateOpClassItem);
7013 :
7014 22 : n->itemtype = OPCLASS_ITEM_FUNCTION;
7015 22 : n->number = $2;
7016 22 : n->class_args = $4;
7017 22 : $$ = (Node *) n;
7018 : }
7019 : ;
7020 :
7021 :
7022 : DropOpClassStmt:
7023 : DROP OPERATOR CLASS any_name USING name opt_drop_behavior
7024 : {
7025 25 : DropStmt *n = makeNode(DropStmt);
7026 :
7027 25 : n->objects = list_make1(lcons(makeString($6), $4));
7028 25 : n->removeType = OBJECT_OPCLASS;
7029 25 : n->behavior = $7;
7030 25 : n->missing_ok = false;
7031 25 : n->concurrent = false;
7032 25 : $$ = (Node *) n;
7033 : }
7034 : | DROP OPERATOR CLASS IF_P EXISTS any_name USING name opt_drop_behavior
7035 : {
7036 12 : DropStmt *n = makeNode(DropStmt);
7037 :
7038 12 : n->objects = list_make1(lcons(makeString($8), $6));
7039 12 : n->removeType = OBJECT_OPCLASS;
7040 12 : n->behavior = $9;
7041 12 : n->missing_ok = true;
7042 12 : n->concurrent = false;
7043 12 : $$ = (Node *) n;
7044 : }
7045 : ;
7046 :
7047 : DropOpFamilyStmt:
7048 : DROP OPERATOR FAMILY any_name USING name opt_drop_behavior
7049 : {
7050 73 : DropStmt *n = makeNode(DropStmt);
7051 :
7052 73 : n->objects = list_make1(lcons(makeString($6), $4));
7053 73 : n->removeType = OBJECT_OPFAMILY;
7054 73 : n->behavior = $7;
7055 73 : n->missing_ok = false;
7056 73 : n->concurrent = false;
7057 73 : $$ = (Node *) n;
7058 : }
7059 : | DROP OPERATOR FAMILY IF_P EXISTS any_name USING name opt_drop_behavior
7060 : {
7061 12 : DropStmt *n = makeNode(DropStmt);
7062 :
7063 12 : n->objects = list_make1(lcons(makeString($8), $6));
7064 12 : n->removeType = OBJECT_OPFAMILY;
7065 12 : n->behavior = $9;
7066 12 : n->missing_ok = true;
7067 12 : n->concurrent = false;
7068 12 : $$ = (Node *) n;
7069 : }
7070 : ;
7071 :
7072 :
7073 : /*****************************************************************************
7074 : *
7075 : * QUERY:
7076 : *
7077 : * DROP OWNED BY username [, username ...] [ RESTRICT | CASCADE ]
7078 : * REASSIGN OWNED BY username [, username ...] TO username
7079 : *
7080 : *****************************************************************************/
7081 : DropOwnedStmt:
7082 : DROP OWNED BY role_list opt_drop_behavior
7083 : {
7084 94 : DropOwnedStmt *n = makeNode(DropOwnedStmt);
7085 :
7086 94 : n->roles = $4;
7087 94 : n->behavior = $5;
7088 94 : $$ = (Node *) n;
7089 : }
7090 : ;
7091 :
7092 : ReassignOwnedStmt:
7093 : REASSIGN OWNED BY role_list TO RoleSpec
7094 : {
7095 34 : ReassignOwnedStmt *n = makeNode(ReassignOwnedStmt);
7096 :
7097 34 : n->roles = $4;
7098 34 : n->newrole = $6;
7099 34 : $$ = (Node *) n;
7100 : }
7101 : ;
7102 :
7103 : /*****************************************************************************
7104 : *
7105 : * QUERY:
7106 : *
7107 : * DROP itemtype [ IF EXISTS ] itemname [, itemname ...]
7108 : * [ RESTRICT | CASCADE ]
7109 : *
7110 : *****************************************************************************/
7111 :
7112 : DropStmt: DROP object_type_any_name IF_P EXISTS any_name_list opt_drop_behavior
7113 : {
7114 757 : DropStmt *n = makeNode(DropStmt);
7115 :
7116 757 : n->removeType = $2;
7117 757 : n->missing_ok = true;
7118 757 : n->objects = $5;
7119 757 : n->behavior = $6;
7120 757 : n->concurrent = false;
7121 757 : $$ = (Node *) n;
7122 : }
7123 : | DROP object_type_any_name any_name_list opt_drop_behavior
7124 : {
7125 10949 : DropStmt *n = makeNode(DropStmt);
7126 :
7127 10949 : n->removeType = $2;
7128 10949 : n->missing_ok = false;
7129 10949 : n->objects = $3;
7130 10949 : n->behavior = $4;
7131 10949 : n->concurrent = false;
7132 10949 : $$ = (Node *) n;
7133 : }
7134 : | DROP drop_type_name IF_P EXISTS name_list opt_drop_behavior
7135 : {
7136 60 : DropStmt *n = makeNode(DropStmt);
7137 :
7138 60 : n->removeType = $2;
7139 60 : n->missing_ok = true;
7140 60 : n->objects = $5;
7141 60 : n->behavior = $6;
7142 60 : n->concurrent = false;
7143 60 : $$ = (Node *) n;
7144 : }
7145 : | DROP drop_type_name name_list opt_drop_behavior
7146 : {
7147 1031 : DropStmt *n = makeNode(DropStmt);
7148 :
7149 1031 : n->removeType = $2;
7150 1031 : n->missing_ok = false;
7151 1031 : n->objects = $3;
7152 1031 : n->behavior = $4;
7153 1031 : n->concurrent = false;
7154 1031 : $$ = (Node *) n;
7155 : }
7156 : | DROP object_type_name_on_any_name name ON any_name opt_drop_behavior
7157 : {
7158 791 : DropStmt *n = makeNode(DropStmt);
7159 :
7160 791 : n->removeType = $2;
7161 791 : n->objects = list_make1(lappend($5, makeString($3)));
7162 791 : n->behavior = $6;
7163 791 : n->missing_ok = false;
7164 791 : n->concurrent = false;
7165 791 : $$ = (Node *) n;
7166 : }
7167 : | DROP object_type_name_on_any_name IF_P EXISTS name ON any_name opt_drop_behavior
7168 : {
7169 32 : DropStmt *n = makeNode(DropStmt);
7170 :
7171 32 : n->removeType = $2;
7172 32 : n->objects = list_make1(lappend($7, makeString($5)));
7173 32 : n->behavior = $8;
7174 32 : n->missing_ok = true;
7175 32 : n->concurrent = false;
7176 32 : $$ = (Node *) n;
7177 : }
7178 : | DROP TYPE_P type_name_list opt_drop_behavior
7179 : {
7180 392 : DropStmt *n = makeNode(DropStmt);
7181 :
7182 392 : n->removeType = OBJECT_TYPE;
7183 392 : n->missing_ok = false;
7184 392 : n->objects = $3;
7185 392 : n->behavior = $4;
7186 392 : n->concurrent = false;
7187 392 : $$ = (Node *) n;
7188 : }
7189 : | DROP TYPE_P IF_P EXISTS type_name_list opt_drop_behavior
7190 : {
7191 16 : DropStmt *n = makeNode(DropStmt);
7192 :
7193 16 : n->removeType = OBJECT_TYPE;
7194 16 : n->missing_ok = true;
7195 16 : n->objects = $5;
7196 16 : n->behavior = $6;
7197 16 : n->concurrent = false;
7198 16 : $$ = (Node *) n;
7199 : }
7200 : | DROP DOMAIN_P type_name_list opt_drop_behavior
7201 : {
7202 353 : DropStmt *n = makeNode(DropStmt);
7203 :
7204 353 : n->removeType = OBJECT_DOMAIN;
7205 353 : n->missing_ok = false;
7206 353 : n->objects = $3;
7207 353 : n->behavior = $4;
7208 353 : n->concurrent = false;
7209 353 : $$ = (Node *) n;
7210 : }
7211 : | DROP DOMAIN_P IF_P EXISTS type_name_list opt_drop_behavior
7212 : {
7213 12 : DropStmt *n = makeNode(DropStmt);
7214 :
7215 12 : n->removeType = OBJECT_DOMAIN;
7216 12 : n->missing_ok = true;
7217 12 : n->objects = $5;
7218 12 : n->behavior = $6;
7219 12 : n->concurrent = false;
7220 12 : $$ = (Node *) n;
7221 : }
7222 : | DROP INDEX CONCURRENTLY any_name_list opt_drop_behavior
7223 : {
7224 91 : DropStmt *n = makeNode(DropStmt);
7225 :
7226 91 : n->removeType = OBJECT_INDEX;
7227 91 : n->missing_ok = false;
7228 91 : n->objects = $4;
7229 91 : n->behavior = $5;
7230 91 : n->concurrent = true;
7231 91 : $$ = (Node *) n;
7232 : }
7233 : | DROP INDEX CONCURRENTLY IF_P EXISTS any_name_list opt_drop_behavior
7234 : {
7235 8 : DropStmt *n = makeNode(DropStmt);
7236 :
7237 8 : n->removeType = OBJECT_INDEX;
7238 8 : n->missing_ok = true;
7239 8 : n->objects = $6;
7240 8 : n->behavior = $7;
7241 8 : n->concurrent = true;
7242 8 : $$ = (Node *) n;
7243 : }
7244 : ;
7245 :
7246 : /* object types taking any_name/any_name_list */
7247 : object_type_any_name:
7248 10028 : TABLE { $$ = OBJECT_TABLE; }
7249 133 : | SEQUENCE { $$ = OBJECT_SEQUENCE; }
7250 704 : | VIEW { $$ = OBJECT_VIEW; }
7251 81 : | MATERIALIZED VIEW { $$ = OBJECT_MATVIEW; }
7252 517 : | INDEX { $$ = OBJECT_INDEX; }
7253 117 : | FOREIGN TABLE { $$ = OBJECT_FOREIGN_TABLE; }
7254 54 : | PROPERTY GRAPH { $$ = OBJECT_PROPGRAPH; }
7255 63 : | COLLATION { $$ = OBJECT_COLLATION; }
7256 37 : | CONVERSION_P { $$ = OBJECT_CONVERSION; }
7257 156 : | STATISTICS { $$ = OBJECT_STATISTIC_EXT; }
7258 13 : | TEXT_P SEARCH PARSER { $$ = OBJECT_TSPARSER; }
7259 1724 : | TEXT_P SEARCH DICTIONARY { $$ = OBJECT_TSDICTIONARY; }
7260 68 : | TEXT_P SEARCH TEMPLATE { $$ = OBJECT_TSTEMPLATE; }
7261 1727 : | TEXT_P SEARCH CONFIGURATION { $$ = OBJECT_TSCONFIGURATION; }
7262 : ;
7263 :
7264 : /*
7265 : * object types taking name/name_list
7266 : *
7267 : * DROP handles some of them separately
7268 : */
7269 :
7270 : object_type_name:
7271 141 : drop_type_name { $$ = $1; }
7272 139 : | DATABASE { $$ = OBJECT_DATABASE; }
7273 44 : | ROLE { $$ = OBJECT_ROLE; }
7274 6 : | SUBSCRIPTION { $$ = OBJECT_SUBSCRIPTION; }
7275 0 : | TABLESPACE { $$ = OBJECT_TABLESPACE; }
7276 : ;
7277 :
7278 : drop_type_name:
7279 37 : ACCESS METHOD { $$ = OBJECT_ACCESS_METHOD; }
7280 84 : | EVENT TRIGGER { $$ = OBJECT_EVENT_TRIGGER; }
7281 100 : | EXTENSION { $$ = OBJECT_EXTENSION; }
7282 105 : | FOREIGN DATA_P WRAPPER { $$ = OBJECT_FDW; }
7283 88 : | opt_procedural LANGUAGE { $$ = OBJECT_LANGUAGE; }
7284 308 : | PUBLICATION { $$ = OBJECT_PUBLICATION; }
7285 418 : | SCHEMA { $$ = OBJECT_SCHEMA; }
7286 92 : | SERVER { $$ = OBJECT_FOREIGN_SERVER; }
7287 : ;
7288 :
7289 : /* object types attached to a table */
7290 : object_type_name_on_any_name:
7291 158 : POLICY { $$ = OBJECT_POLICY; }
7292 181 : | RULE { $$ = OBJECT_RULE; }
7293 519 : | TRIGGER { $$ = OBJECT_TRIGGER; }
7294 : ;
7295 :
7296 : any_name_list:
7297 17115 : any_name { $$ = list_make1($1); }
7298 2541 : | any_name_list ',' any_name { $$ = lappend($1, $3); }
7299 : ;
7300 :
7301 42442 : any_name: ColId { $$ = list_make1(makeString($1)); }
7302 6167 : | ColId attrs { $$ = lcons(makeString($1), $2); }
7303 : ;
7304 :
7305 : attrs: '.' attr_name
7306 76957 : { $$ = list_make1(makeString($2)); }
7307 : | attrs '.' attr_name
7308 36 : { $$ = lappend($1, makeString($3)); }
7309 : ;
7310 :
7311 : type_name_list:
7312 773 : Typename { $$ = list_make1($1); }
7313 84 : | type_name_list ',' Typename { $$ = lappend($1, $3); }
7314 : ;
7315 :
7316 : /*****************************************************************************
7317 : *
7318 : * QUERY:
7319 : * truncate table relname1, relname2, ...
7320 : *
7321 : *****************************************************************************/
7322 :
7323 : TruncateStmt:
7324 : TRUNCATE opt_table relation_expr_list opt_restart_seqs opt_drop_behavior
7325 : {
7326 1150 : TruncateStmt *n = makeNode(TruncateStmt);
7327 :
7328 1150 : n->relations = $3;
7329 1150 : n->restart_seqs = $4;
7330 1150 : n->behavior = $5;
7331 1150 : $$ = (Node *) n;
7332 : }
7333 : ;
7334 :
7335 : opt_restart_seqs:
7336 12 : CONTINUE_P IDENTITY_P { $$ = false; }
7337 15 : | RESTART IDENTITY_P { $$ = true; }
7338 1123 : | /* EMPTY */ { $$ = false; }
7339 : ;
7340 :
7341 : /*****************************************************************************
7342 : *
7343 : * COMMENT ON <object> IS <text>
7344 : *
7345 : *****************************************************************************/
7346 :
7347 : CommentStmt:
7348 : COMMENT ON object_type_any_name any_name IS comment_text
7349 : {
7350 3632 : CommentStmt *n = makeNode(CommentStmt);
7351 :
7352 3632 : n->objtype = $3;
7353 3632 : n->object = (Node *) $4;
7354 3632 : n->comment = $6;
7355 3632 : $$ = (Node *) n;
7356 : }
7357 : | COMMENT ON COLUMN any_name IS comment_text
7358 : {
7359 94 : CommentStmt *n = makeNode(CommentStmt);
7360 :
7361 94 : n->objtype = OBJECT_COLUMN;
7362 94 : n->object = (Node *) $4;
7363 94 : n->comment = $6;
7364 94 : $$ = (Node *) n;
7365 : }
7366 : | COMMENT ON object_type_name name IS comment_text
7367 : {
7368 295 : CommentStmt *n = makeNode(CommentStmt);
7369 :
7370 295 : n->objtype = $3;
7371 295 : n->object = (Node *) makeString($4);
7372 295 : n->comment = $6;
7373 295 : $$ = (Node *) n;
7374 : }
7375 : | COMMENT ON TYPE_P Typename IS comment_text
7376 : {
7377 31 : CommentStmt *n = makeNode(CommentStmt);
7378 :
7379 31 : n->objtype = OBJECT_TYPE;
7380 31 : n->object = (Node *) $4;
7381 31 : n->comment = $6;
7382 31 : $$ = (Node *) n;
7383 : }
7384 : | COMMENT ON DOMAIN_P Typename IS comment_text
7385 : {
7386 5 : CommentStmt *n = makeNode(CommentStmt);
7387 :
7388 5 : n->objtype = OBJECT_DOMAIN;
7389 5 : n->object = (Node *) $4;
7390 5 : n->comment = $6;
7391 5 : $$ = (Node *) n;
7392 : }
7393 : | COMMENT ON AGGREGATE aggregate_with_argtypes IS comment_text
7394 : {
7395 26 : CommentStmt *n = makeNode(CommentStmt);
7396 :
7397 26 : n->objtype = OBJECT_AGGREGATE;
7398 26 : n->object = (Node *) $4;
7399 26 : n->comment = $6;
7400 26 : $$ = (Node *) n;
7401 : }
7402 : | COMMENT ON FUNCTION function_with_argtypes IS comment_text
7403 : {
7404 91 : CommentStmt *n = makeNode(CommentStmt);
7405 :
7406 91 : n->objtype = OBJECT_FUNCTION;
7407 91 : n->object = (Node *) $4;
7408 91 : n->comment = $6;
7409 91 : $$ = (Node *) n;
7410 : }
7411 : | COMMENT ON OPERATOR operator_with_argtypes IS comment_text
7412 : {
7413 12 : CommentStmt *n = makeNode(CommentStmt);
7414 :
7415 12 : n->objtype = OBJECT_OPERATOR;
7416 12 : n->object = (Node *) $4;
7417 12 : n->comment = $6;
7418 12 : $$ = (Node *) n;
7419 : }
7420 : | COMMENT ON CONSTRAINT name ON any_name IS comment_text
7421 : {
7422 97 : CommentStmt *n = makeNode(CommentStmt);
7423 :
7424 97 : n->objtype = OBJECT_TABCONSTRAINT;
7425 97 : n->object = (Node *) lappend($6, makeString($4));
7426 97 : n->comment = $8;
7427 97 : $$ = (Node *) n;
7428 : }
7429 : | COMMENT ON CONSTRAINT name ON DOMAIN_P any_name IS comment_text
7430 : {
7431 31 : CommentStmt *n = makeNode(CommentStmt);
7432 :
7433 31 : n->objtype = OBJECT_DOMCONSTRAINT;
7434 : /*
7435 : * should use Typename not any_name in the production, but
7436 : * there's a shift/reduce conflict if we do that, so fix it
7437 : * up here.
7438 : */
7439 31 : n->object = (Node *) list_make2(makeTypeNameFromNameList($7), makeString($4));
7440 31 : n->comment = $9;
7441 31 : $$ = (Node *) n;
7442 : }
7443 : | COMMENT ON object_type_name_on_any_name name ON any_name IS comment_text
7444 : {
7445 27 : CommentStmt *n = makeNode(CommentStmt);
7446 :
7447 27 : n->objtype = $3;
7448 27 : n->object = (Node *) lappend($6, makeString($4));
7449 27 : n->comment = $8;
7450 27 : $$ = (Node *) n;
7451 : }
7452 : | COMMENT ON PROCEDURE function_with_argtypes IS comment_text
7453 : {
7454 0 : CommentStmt *n = makeNode(CommentStmt);
7455 :
7456 0 : n->objtype = OBJECT_PROCEDURE;
7457 0 : n->object = (Node *) $4;
7458 0 : n->comment = $6;
7459 0 : $$ = (Node *) n;
7460 : }
7461 : | COMMENT ON ROUTINE function_with_argtypes IS comment_text
7462 : {
7463 0 : CommentStmt *n = makeNode(CommentStmt);
7464 :
7465 0 : n->objtype = OBJECT_ROUTINE;
7466 0 : n->object = (Node *) $4;
7467 0 : n->comment = $6;
7468 0 : $$ = (Node *) n;
7469 : }
7470 : | COMMENT ON TRANSFORM FOR Typename LANGUAGE name IS comment_text
7471 : {
7472 7 : CommentStmt *n = makeNode(CommentStmt);
7473 :
7474 7 : n->objtype = OBJECT_TRANSFORM;
7475 7 : n->object = (Node *) list_make2($5, makeString($7));
7476 7 : n->comment = $9;
7477 7 : $$ = (Node *) n;
7478 : }
7479 : | COMMENT ON OPERATOR CLASS any_name USING name IS comment_text
7480 : {
7481 0 : CommentStmt *n = makeNode(CommentStmt);
7482 :
7483 0 : n->objtype = OBJECT_OPCLASS;
7484 0 : n->object = (Node *) lcons(makeString($7), $5);
7485 0 : n->comment = $9;
7486 0 : $$ = (Node *) n;
7487 : }
7488 : | COMMENT ON OPERATOR FAMILY any_name USING name IS comment_text
7489 : {
7490 0 : CommentStmt *n = makeNode(CommentStmt);
7491 :
7492 0 : n->objtype = OBJECT_OPFAMILY;
7493 0 : n->object = (Node *) lcons(makeString($7), $5);
7494 0 : n->comment = $9;
7495 0 : $$ = (Node *) n;
7496 : }
7497 : | COMMENT ON LARGE_P OBJECT_P NumericOnly IS comment_text
7498 : {
7499 24 : CommentStmt *n = makeNode(CommentStmt);
7500 :
7501 24 : n->objtype = OBJECT_LARGEOBJECT;
7502 24 : n->object = (Node *) $5;
7503 24 : n->comment = $7;
7504 24 : $$ = (Node *) n;
7505 : }
7506 : | COMMENT ON CAST '(' Typename AS Typename ')' IS comment_text
7507 : {
7508 0 : CommentStmt *n = makeNode(CommentStmt);
7509 :
7510 0 : n->objtype = OBJECT_CAST;
7511 0 : n->object = (Node *) list_make2($5, $7);
7512 0 : n->comment = $10;
7513 0 : $$ = (Node *) n;
7514 : }
7515 : ;
7516 :
7517 : comment_text:
7518 4299 : Sconst { $$ = $1; }
7519 73 : | NULL_P { $$ = NULL; }
7520 : ;
7521 :
7522 :
7523 : /*****************************************************************************
7524 : *
7525 : * SECURITY LABEL [FOR <provider>] ON <object> IS <label>
7526 : *
7527 : * As with COMMENT ON, <object> can refer to various types of database
7528 : * objects (e.g. TABLE, COLUMN, etc.).
7529 : *
7530 : *****************************************************************************/
7531 :
7532 : SecLabelStmt:
7533 : SECURITY LABEL opt_provider ON object_type_any_name any_name
7534 : IS security_label
7535 : {
7536 28 : SecLabelStmt *n = makeNode(SecLabelStmt);
7537 :
7538 28 : n->provider = $3;
7539 28 : n->objtype = $5;
7540 28 : n->object = (Node *) $6;
7541 28 : n->label = $8;
7542 28 : $$ = (Node *) n;
7543 : }
7544 : | SECURITY LABEL opt_provider ON COLUMN any_name
7545 : IS security_label
7546 : {
7547 2 : SecLabelStmt *n = makeNode(SecLabelStmt);
7548 :
7549 2 : n->provider = $3;
7550 2 : n->objtype = OBJECT_COLUMN;
7551 2 : n->object = (Node *) $6;
7552 2 : n->label = $8;
7553 2 : $$ = (Node *) n;
7554 : }
7555 : | SECURITY LABEL opt_provider ON object_type_name name
7556 : IS security_label
7557 : {
7558 26 : SecLabelStmt *n = makeNode(SecLabelStmt);
7559 :
7560 26 : n->provider = $3;
7561 26 : n->objtype = $5;
7562 26 : n->object = (Node *) makeString($6);
7563 26 : n->label = $8;
7564 26 : $$ = (Node *) n;
7565 : }
7566 : | SECURITY LABEL opt_provider ON TYPE_P Typename
7567 : IS security_label
7568 : {
7569 0 : SecLabelStmt *n = makeNode(SecLabelStmt);
7570 :
7571 0 : n->provider = $3;
7572 0 : n->objtype = OBJECT_TYPE;
7573 0 : n->object = (Node *) $6;
7574 0 : n->label = $8;
7575 0 : $$ = (Node *) n;
7576 : }
7577 : | SECURITY LABEL opt_provider ON DOMAIN_P Typename
7578 : IS security_label
7579 : {
7580 1 : SecLabelStmt *n = makeNode(SecLabelStmt);
7581 :
7582 1 : n->provider = $3;
7583 1 : n->objtype = OBJECT_DOMAIN;
7584 1 : n->object = (Node *) $6;
7585 1 : n->label = $8;
7586 1 : $$ = (Node *) n;
7587 : }
7588 : | SECURITY LABEL opt_provider ON AGGREGATE aggregate_with_argtypes
7589 : IS security_label
7590 : {
7591 0 : SecLabelStmt *n = makeNode(SecLabelStmt);
7592 :
7593 0 : n->provider = $3;
7594 0 : n->objtype = OBJECT_AGGREGATE;
7595 0 : n->object = (Node *) $6;
7596 0 : n->label = $8;
7597 0 : $$ = (Node *) n;
7598 : }
7599 : | SECURITY LABEL opt_provider ON FUNCTION function_with_argtypes
7600 : IS security_label
7601 : {
7602 1 : SecLabelStmt *n = makeNode(SecLabelStmt);
7603 :
7604 1 : n->provider = $3;
7605 1 : n->objtype = OBJECT_FUNCTION;
7606 1 : n->object = (Node *) $6;
7607 1 : n->label = $8;
7608 1 : $$ = (Node *) n;
7609 : }
7610 : | SECURITY LABEL opt_provider ON LARGE_P OBJECT_P NumericOnly
7611 : IS security_label
7612 : {
7613 9 : SecLabelStmt *n = makeNode(SecLabelStmt);
7614 :
7615 9 : n->provider = $3;
7616 9 : n->objtype = OBJECT_LARGEOBJECT;
7617 9 : n->object = (Node *) $7;
7618 9 : n->label = $9;
7619 9 : $$ = (Node *) n;
7620 : }
7621 : | SECURITY LABEL opt_provider ON PROCEDURE function_with_argtypes
7622 : IS security_label
7623 : {
7624 0 : SecLabelStmt *n = makeNode(SecLabelStmt);
7625 :
7626 0 : n->provider = $3;
7627 0 : n->objtype = OBJECT_PROCEDURE;
7628 0 : n->object = (Node *) $6;
7629 0 : n->label = $8;
7630 0 : $$ = (Node *) n;
7631 : }
7632 : | SECURITY LABEL opt_provider ON ROUTINE function_with_argtypes
7633 : IS security_label
7634 : {
7635 0 : SecLabelStmt *n = makeNode(SecLabelStmt);
7636 :
7637 0 : n->provider = $3;
7638 0 : n->objtype = OBJECT_ROUTINE;
7639 0 : n->object = (Node *) $6;
7640 0 : n->label = $8;
7641 0 : $$ = (Node *) n;
7642 : }
7643 : ;
7644 :
7645 16 : opt_provider: FOR NonReservedWord_or_Sconst { $$ = $2; }
7646 51 : | /* EMPTY */ { $$ = NULL; }
7647 : ;
7648 :
7649 67 : security_label: Sconst { $$ = $1; }
7650 0 : | NULL_P { $$ = NULL; }
7651 : ;
7652 :
7653 : /*****************************************************************************
7654 : *
7655 : * QUERY:
7656 : * fetch/move
7657 : *
7658 : *****************************************************************************/
7659 :
7660 : FetchStmt: FETCH fetch_args
7661 : {
7662 4376 : FetchStmt *n = (FetchStmt *) $2;
7663 :
7664 4376 : n->ismove = false;
7665 4376 : $$ = (Node *) n;
7666 : }
7667 : | MOVE fetch_args
7668 : {
7669 42 : FetchStmt *n = (FetchStmt *) $2;
7670 :
7671 42 : n->ismove = true;
7672 42 : $$ = (Node *) n;
7673 : }
7674 : ;
7675 :
7676 : fetch_args: cursor_name
7677 : {
7678 148 : FetchStmt *n = makeNode(FetchStmt);
7679 :
7680 148 : n->portalname = $1;
7681 148 : n->direction = FETCH_FORWARD;
7682 148 : n->howMany = 1;
7683 148 : n->location = -1;
7684 148 : n->direction_keyword = FETCH_KEYWORD_NONE;
7685 148 : $$ = (Node *) n;
7686 : }
7687 : | from_in cursor_name
7688 : {
7689 124 : FetchStmt *n = makeNode(FetchStmt);
7690 :
7691 124 : n->portalname = $2;
7692 124 : n->direction = FETCH_FORWARD;
7693 124 : n->howMany = 1;
7694 124 : n->location = -1;
7695 124 : n->direction_keyword = FETCH_KEYWORD_NONE;
7696 124 : $$ = (Node *) n;
7697 : }
7698 : | SignedIconst opt_from_in cursor_name
7699 : {
7700 2211 : FetchStmt *n = makeNode(FetchStmt);
7701 :
7702 2211 : n->portalname = $3;
7703 2211 : n->direction = FETCH_FORWARD;
7704 2211 : n->howMany = $1;
7705 2211 : n->location = @1;
7706 2211 : n->direction_keyword = FETCH_KEYWORD_NONE;
7707 2211 : $$ = (Node *) n;
7708 : }
7709 : | NEXT opt_from_in cursor_name
7710 : {
7711 1332 : FetchStmt *n = makeNode(FetchStmt);
7712 :
7713 1332 : n->portalname = $3;
7714 1332 : n->direction = FETCH_FORWARD;
7715 1332 : n->howMany = 1;
7716 1332 : n->location = -1;
7717 1332 : n->direction_keyword = FETCH_KEYWORD_NEXT;
7718 1332 : $$ = (Node *) n;
7719 : }
7720 : | PRIOR opt_from_in cursor_name
7721 : {
7722 21 : FetchStmt *n = makeNode(FetchStmt);
7723 :
7724 21 : n->portalname = $3;
7725 21 : n->direction = FETCH_BACKWARD;
7726 21 : n->howMany = 1;
7727 21 : n->location = -1;
7728 21 : n->direction_keyword = FETCH_KEYWORD_PRIOR;
7729 21 : $$ = (Node *) n;
7730 : }
7731 : | FIRST_P opt_from_in cursor_name
7732 : {
7733 17 : FetchStmt *n = makeNode(FetchStmt);
7734 :
7735 17 : n->portalname = $3;
7736 17 : n->direction = FETCH_ABSOLUTE;
7737 17 : n->howMany = 1;
7738 17 : n->location = -1;
7739 17 : n->direction_keyword = FETCH_KEYWORD_FIRST;
7740 17 : $$ = (Node *) n;
7741 : }
7742 : | LAST_P opt_from_in cursor_name
7743 : {
7744 13 : FetchStmt *n = makeNode(FetchStmt);
7745 :
7746 13 : n->portalname = $3;
7747 13 : n->direction = FETCH_ABSOLUTE;
7748 13 : n->howMany = -1;
7749 13 : n->location = -1;
7750 13 : n->direction_keyword = FETCH_KEYWORD_LAST;
7751 13 : $$ = (Node *) n;
7752 : }
7753 : | ABSOLUTE_P SignedIconst opt_from_in cursor_name
7754 : {
7755 59 : FetchStmt *n = makeNode(FetchStmt);
7756 :
7757 59 : n->portalname = $4;
7758 59 : n->direction = FETCH_ABSOLUTE;
7759 59 : n->howMany = $2;
7760 59 : n->location = @2;
7761 59 : n->direction_keyword = FETCH_KEYWORD_ABSOLUTE;
7762 59 : $$ = (Node *) n;
7763 : }
7764 : | RELATIVE_P SignedIconst opt_from_in cursor_name
7765 : {
7766 23 : FetchStmt *n = makeNode(FetchStmt);
7767 :
7768 23 : n->portalname = $4;
7769 23 : n->direction = FETCH_RELATIVE;
7770 23 : n->howMany = $2;
7771 23 : n->location = @2;
7772 23 : n->direction_keyword = FETCH_KEYWORD_RELATIVE;
7773 23 : $$ = (Node *) n;
7774 : }
7775 : | ALL opt_from_in cursor_name
7776 : {
7777 176 : FetchStmt *n = makeNode(FetchStmt);
7778 :
7779 176 : n->portalname = $3;
7780 176 : n->direction = FETCH_FORWARD;
7781 176 : n->howMany = FETCH_ALL;
7782 176 : n->location = -1;
7783 176 : n->direction_keyword = FETCH_KEYWORD_ALL;
7784 176 : $$ = (Node *) n;
7785 : }
7786 : | FORWARD opt_from_in cursor_name
7787 : {
7788 15 : FetchStmt *n = makeNode(FetchStmt);
7789 :
7790 15 : n->portalname = $3;
7791 15 : n->direction = FETCH_FORWARD;
7792 15 : n->howMany = 1;
7793 15 : n->location = -1;
7794 15 : n->direction_keyword = FETCH_KEYWORD_FORWARD;
7795 15 : $$ = (Node *) n;
7796 : }
7797 : | FORWARD SignedIconst opt_from_in cursor_name
7798 : {
7799 6 : FetchStmt *n = makeNode(FetchStmt);
7800 :
7801 6 : n->portalname = $4;
7802 6 : n->direction = FETCH_FORWARD;
7803 6 : n->howMany = $2;
7804 6 : n->location = @2;
7805 6 : n->direction_keyword = FETCH_KEYWORD_FORWARD;
7806 6 : $$ = (Node *) n;
7807 : }
7808 : | FORWARD ALL opt_from_in cursor_name
7809 : {
7810 10 : FetchStmt *n = makeNode(FetchStmt);
7811 :
7812 10 : n->portalname = $4;
7813 10 : n->direction = FETCH_FORWARD;
7814 10 : n->howMany = FETCH_ALL;
7815 10 : n->location = -1;
7816 10 : n->direction_keyword = FETCH_KEYWORD_FORWARD_ALL;
7817 10 : $$ = (Node *) n;
7818 : }
7819 : | BACKWARD opt_from_in cursor_name
7820 : {
7821 53 : FetchStmt *n = makeNode(FetchStmt);
7822 :
7823 53 : n->portalname = $3;
7824 53 : n->direction = FETCH_BACKWARD;
7825 53 : n->howMany = 1;
7826 53 : n->location = -1;
7827 53 : n->direction_keyword = FETCH_KEYWORD_BACKWARD;
7828 53 : $$ = (Node *) n;
7829 : }
7830 : | BACKWARD SignedIconst opt_from_in cursor_name
7831 : {
7832 149 : FetchStmt *n = makeNode(FetchStmt);
7833 :
7834 149 : n->portalname = $4;
7835 149 : n->direction = FETCH_BACKWARD;
7836 149 : n->howMany = $2;
7837 149 : n->location = @2;
7838 149 : n->direction_keyword = FETCH_KEYWORD_BACKWARD;
7839 149 : $$ = (Node *) n;
7840 : }
7841 : | BACKWARD ALL opt_from_in cursor_name
7842 : {
7843 61 : FetchStmt *n = makeNode(FetchStmt);
7844 :
7845 61 : n->portalname = $4;
7846 61 : n->direction = FETCH_BACKWARD;
7847 61 : n->howMany = FETCH_ALL;
7848 61 : n->location = -1;
7849 61 : n->direction_keyword = FETCH_KEYWORD_BACKWARD_ALL;
7850 61 : $$ = (Node *) n;
7851 : }
7852 : ;
7853 :
7854 : from_in: FROM
7855 : | IN_P
7856 : ;
7857 :
7858 : opt_from_in: from_in
7859 : | /* EMPTY */
7860 : ;
7861 :
7862 :
7863 : /*****************************************************************************
7864 : *
7865 : * GRANT and REVOKE statements
7866 : *
7867 : *****************************************************************************/
7868 :
7869 : GrantStmt: GRANT privileges ON privilege_target TO grantee_list
7870 : opt_grant_grant_option opt_granted_by
7871 : {
7872 6705 : GrantStmt *n = makeNode(GrantStmt);
7873 :
7874 6705 : n->is_grant = true;
7875 6705 : n->privileges = $2;
7876 6705 : n->targtype = ($4)->targtype;
7877 6705 : n->objtype = ($4)->objtype;
7878 6705 : n->objects = ($4)->objs;
7879 6705 : n->grantees = $6;
7880 6705 : n->grant_option = $7;
7881 6705 : n->grantor = $8;
7882 6705 : $$ = (Node *) n;
7883 : }
7884 : ;
7885 :
7886 : RevokeStmt:
7887 : REVOKE privileges ON privilege_target
7888 : FROM grantee_list opt_granted_by opt_drop_behavior
7889 : {
7890 2335 : GrantStmt *n = makeNode(GrantStmt);
7891 :
7892 2335 : n->is_grant = false;
7893 2335 : n->grant_option = false;
7894 2335 : n->privileges = $2;
7895 2335 : n->targtype = ($4)->targtype;
7896 2335 : n->objtype = ($4)->objtype;
7897 2335 : n->objects = ($4)->objs;
7898 2335 : n->grantees = $6;
7899 2335 : n->grantor = $7;
7900 2335 : n->behavior = $8;
7901 2335 : $$ = (Node *) n;
7902 : }
7903 : | REVOKE GRANT OPTION FOR privileges ON privilege_target
7904 : FROM grantee_list opt_granted_by opt_drop_behavior
7905 : {
7906 9 : GrantStmt *n = makeNode(GrantStmt);
7907 :
7908 9 : n->is_grant = false;
7909 9 : n->grant_option = true;
7910 9 : n->privileges = $5;
7911 9 : n->targtype = ($7)->targtype;
7912 9 : n->objtype = ($7)->objtype;
7913 9 : n->objects = ($7)->objs;
7914 9 : n->grantees = $9;
7915 9 : n->grantor = $10;
7916 9 : n->behavior = $11;
7917 9 : $$ = (Node *) n;
7918 : }
7919 : ;
7920 :
7921 :
7922 : /*
7923 : * Privilege names are represented as strings; the validity of the privilege
7924 : * names gets checked at execution. This is a bit annoying but we have little
7925 : * choice because of the syntactic conflict with lists of role names in
7926 : * GRANT/REVOKE. What's more, we have to call out in the "privilege"
7927 : * production any reserved keywords that need to be usable as privilege names.
7928 : */
7929 :
7930 : /* either ALL [PRIVILEGES] or a list of individual privileges */
7931 : privileges: privilege_list
7932 7481 : { $$ = $1; }
7933 : | ALL
7934 1628 : { $$ = NIL; }
7935 : | ALL PRIVILEGES
7936 69 : { $$ = NIL; }
7937 : | ALL '(' columnList ')'
7938 : {
7939 12 : AccessPriv *n = makeNode(AccessPriv);
7940 :
7941 12 : n->priv_name = NULL;
7942 12 : n->cols = $3;
7943 12 : $$ = list_make1(n);
7944 : }
7945 : | ALL PRIVILEGES '(' columnList ')'
7946 : {
7947 0 : AccessPriv *n = makeNode(AccessPriv);
7948 :
7949 0 : n->priv_name = NULL;
7950 0 : n->cols = $4;
7951 0 : $$ = list_make1(n);
7952 : }
7953 : ;
7954 :
7955 7931 : privilege_list: privilege { $$ = list_make1($1); }
7956 386 : | privilege_list ',' privilege { $$ = lappend($1, $3); }
7957 : ;
7958 :
7959 : privilege: SELECT opt_column_list
7960 : {
7961 6106 : AccessPriv *n = makeNode(AccessPriv);
7962 :
7963 6106 : n->priv_name = pstrdup($1);
7964 6106 : n->cols = $2;
7965 6106 : $$ = n;
7966 : }
7967 : | REFERENCES opt_column_list
7968 : {
7969 9 : AccessPriv *n = makeNode(AccessPriv);
7970 :
7971 9 : n->priv_name = pstrdup($1);
7972 9 : n->cols = $2;
7973 9 : $$ = n;
7974 : }
7975 : | CREATE opt_column_list
7976 : {
7977 202 : AccessPriv *n = makeNode(AccessPriv);
7978 :
7979 202 : n->priv_name = pstrdup($1);
7980 202 : n->cols = $2;
7981 202 : $$ = n;
7982 : }
7983 : | ALTER SYSTEM_P
7984 : {
7985 12 : AccessPriv *n = makeNode(AccessPriv);
7986 12 : n->priv_name = pstrdup("alter system");
7987 12 : n->cols = NIL;
7988 12 : $$ = n;
7989 : }
7990 : | ColId opt_column_list
7991 : {
7992 1988 : AccessPriv *n = makeNode(AccessPriv);
7993 :
7994 1988 : n->priv_name = $1;
7995 1988 : n->cols = $2;
7996 1988 : $$ = n;
7997 : }
7998 : ;
7999 :
8000 : parameter_name_list:
8001 : parameter_name
8002 : {
8003 38 : $$ = list_make1(makeString($1));
8004 : }
8005 : | parameter_name_list ',' parameter_name
8006 : {
8007 25 : $$ = lappend($1, makeString($3));
8008 : }
8009 : ;
8010 :
8011 : parameter_name:
8012 : ColId
8013 : {
8014 63 : $$ = $1;
8015 : }
8016 : | parameter_name '.' ColId
8017 : {
8018 16 : $$ = psprintf("%s.%s", $1, $3);
8019 : }
8020 : ;
8021 :
8022 :
8023 : /* Don't bother trying to fold the first two rules into one using
8024 : * opt_table. You're going to get conflicts.
8025 : */
8026 : privilege_target:
8027 : qualified_name_list
8028 : {
8029 7362 : PrivTarget *n = palloc_object(PrivTarget);
8030 :
8031 7362 : n->targtype = ACL_TARGET_OBJECT;
8032 7362 : n->objtype = OBJECT_TABLE;
8033 7362 : n->objs = $1;
8034 7362 : $$ = n;
8035 : }
8036 : | TABLE qualified_name_list
8037 : {
8038 237 : PrivTarget *n = palloc_object(PrivTarget);
8039 :
8040 237 : n->targtype = ACL_TARGET_OBJECT;
8041 237 : n->objtype = OBJECT_TABLE;
8042 237 : n->objs = $2;
8043 237 : $$ = n;
8044 : }
8045 : | SEQUENCE qualified_name_list
8046 : {
8047 12 : PrivTarget *n = palloc_object(PrivTarget);
8048 :
8049 12 : n->targtype = ACL_TARGET_OBJECT;
8050 12 : n->objtype = OBJECT_SEQUENCE;
8051 12 : n->objs = $2;
8052 12 : $$ = n;
8053 : }
8054 : | FOREIGN DATA_P WRAPPER name_list
8055 : {
8056 60 : PrivTarget *n = palloc_object(PrivTarget);
8057 :
8058 60 : n->targtype = ACL_TARGET_OBJECT;
8059 60 : n->objtype = OBJECT_FDW;
8060 60 : n->objs = $4;
8061 60 : $$ = n;
8062 : }
8063 : | FOREIGN SERVER name_list
8064 : {
8065 63 : PrivTarget *n = palloc_object(PrivTarget);
8066 :
8067 63 : n->targtype = ACL_TARGET_OBJECT;
8068 63 : n->objtype = OBJECT_FOREIGN_SERVER;
8069 63 : n->objs = $3;
8070 63 : $$ = n;
8071 : }
8072 : | FUNCTION function_with_argtypes_list
8073 : {
8074 511 : PrivTarget *n = palloc_object(PrivTarget);
8075 :
8076 511 : n->targtype = ACL_TARGET_OBJECT;
8077 511 : n->objtype = OBJECT_FUNCTION;
8078 511 : n->objs = $2;
8079 511 : $$ = n;
8080 : }
8081 : | PROCEDURE function_with_argtypes_list
8082 : {
8083 28 : PrivTarget *n = palloc_object(PrivTarget);
8084 :
8085 28 : n->targtype = ACL_TARGET_OBJECT;
8086 28 : n->objtype = OBJECT_PROCEDURE;
8087 28 : n->objs = $2;
8088 28 : $$ = n;
8089 : }
8090 : | ROUTINE function_with_argtypes_list
8091 : {
8092 0 : PrivTarget *n = palloc_object(PrivTarget);
8093 :
8094 0 : n->targtype = ACL_TARGET_OBJECT;
8095 0 : n->objtype = OBJECT_ROUTINE;
8096 0 : n->objs = $2;
8097 0 : $$ = n;
8098 : }
8099 : | DATABASE name_list
8100 : {
8101 220 : PrivTarget *n = palloc_object(PrivTarget);
8102 :
8103 220 : n->targtype = ACL_TARGET_OBJECT;
8104 220 : n->objtype = OBJECT_DATABASE;
8105 220 : n->objs = $2;
8106 220 : $$ = n;
8107 : }
8108 : | DOMAIN_P any_name_list
8109 : {
8110 17 : PrivTarget *n = palloc_object(PrivTarget);
8111 :
8112 17 : n->targtype = ACL_TARGET_OBJECT;
8113 17 : n->objtype = OBJECT_DOMAIN;
8114 17 : n->objs = $2;
8115 17 : $$ = n;
8116 : }
8117 : | LANGUAGE name_list
8118 : {
8119 27 : PrivTarget *n = palloc_object(PrivTarget);
8120 :
8121 27 : n->targtype = ACL_TARGET_OBJECT;
8122 27 : n->objtype = OBJECT_LANGUAGE;
8123 27 : n->objs = $2;
8124 27 : $$ = n;
8125 : }
8126 : | LARGE_P OBJECT_P NumericOnly_list
8127 : {
8128 62 : PrivTarget *n = palloc_object(PrivTarget);
8129 :
8130 62 : n->targtype = ACL_TARGET_OBJECT;
8131 62 : n->objtype = OBJECT_LARGEOBJECT;
8132 62 : n->objs = $3;
8133 62 : $$ = n;
8134 : }
8135 : | PARAMETER parameter_name_list
8136 : {
8137 38 : PrivTarget *n = palloc_object(PrivTarget);
8138 38 : n->targtype = ACL_TARGET_OBJECT;
8139 38 : n->objtype = OBJECT_PARAMETER_ACL;
8140 38 : n->objs = $2;
8141 38 : $$ = n;
8142 : }
8143 : | PROPERTY GRAPH qualified_name_list
8144 : {
8145 12 : PrivTarget *n = palloc_object(PrivTarget);
8146 :
8147 12 : n->targtype = ACL_TARGET_OBJECT;
8148 12 : n->objtype = OBJECT_PROPGRAPH;
8149 12 : n->objs = $3;
8150 12 : $$ = n;
8151 : }
8152 : | SCHEMA name_list
8153 : {
8154 307 : PrivTarget *n = palloc_object(PrivTarget);
8155 :
8156 307 : n->targtype = ACL_TARGET_OBJECT;
8157 307 : n->objtype = OBJECT_SCHEMA;
8158 307 : n->objs = $2;
8159 307 : $$ = n;
8160 : }
8161 : | TABLESPACE name_list
8162 : {
8163 3 : PrivTarget *n = palloc_object(PrivTarget);
8164 :
8165 3 : n->targtype = ACL_TARGET_OBJECT;
8166 3 : n->objtype = OBJECT_TABLESPACE;
8167 3 : n->objs = $2;
8168 3 : $$ = n;
8169 : }
8170 : | TYPE_P any_name_list
8171 : {
8172 76 : PrivTarget *n = palloc_object(PrivTarget);
8173 :
8174 76 : n->targtype = ACL_TARGET_OBJECT;
8175 76 : n->objtype = OBJECT_TYPE;
8176 76 : n->objs = $2;
8177 76 : $$ = n;
8178 : }
8179 : | ALL TABLES IN_P SCHEMA name_list
8180 : {
8181 8 : PrivTarget *n = palloc_object(PrivTarget);
8182 :
8183 8 : n->targtype = ACL_TARGET_ALL_IN_SCHEMA;
8184 8 : n->objtype = OBJECT_TABLE;
8185 8 : n->objs = $5;
8186 8 : $$ = n;
8187 : }
8188 : | ALL SEQUENCES IN_P SCHEMA name_list
8189 : {
8190 0 : PrivTarget *n = palloc_object(PrivTarget);
8191 :
8192 0 : n->targtype = ACL_TARGET_ALL_IN_SCHEMA;
8193 0 : n->objtype = OBJECT_SEQUENCE;
8194 0 : n->objs = $5;
8195 0 : $$ = n;
8196 : }
8197 : | ALL FUNCTIONS IN_P SCHEMA name_list
8198 : {
8199 4 : PrivTarget *n = palloc_object(PrivTarget);
8200 :
8201 4 : n->targtype = ACL_TARGET_ALL_IN_SCHEMA;
8202 4 : n->objtype = OBJECT_FUNCTION;
8203 4 : n->objs = $5;
8204 4 : $$ = n;
8205 : }
8206 : | ALL PROCEDURES IN_P SCHEMA name_list
8207 : {
8208 4 : PrivTarget *n = palloc_object(PrivTarget);
8209 :
8210 4 : n->targtype = ACL_TARGET_ALL_IN_SCHEMA;
8211 4 : n->objtype = OBJECT_PROCEDURE;
8212 4 : n->objs = $5;
8213 4 : $$ = n;
8214 : }
8215 : | ALL ROUTINES IN_P SCHEMA name_list
8216 : {
8217 4 : PrivTarget *n = palloc_object(PrivTarget);
8218 :
8219 4 : n->targtype = ACL_TARGET_ALL_IN_SCHEMA;
8220 4 : n->objtype = OBJECT_ROUTINE;
8221 4 : n->objs = $5;
8222 4 : $$ = n;
8223 : }
8224 : ;
8225 :
8226 :
8227 : grantee_list:
8228 9184 : grantee { $$ = list_make1($1); }
8229 70 : | grantee_list ',' grantee { $$ = lappend($1, $3); }
8230 : ;
8231 :
8232 : grantee:
8233 9238 : RoleSpec { $$ = $1; }
8234 16 : | GROUP_P RoleSpec { $$ = $2; }
8235 : ;
8236 :
8237 :
8238 : opt_grant_grant_option:
8239 77 : WITH GRANT OPTION { $$ = true; }
8240 6710 : | /*EMPTY*/ { $$ = false; }
8241 : ;
8242 :
8243 : /*****************************************************************************
8244 : *
8245 : * GRANT and REVOKE ROLE statements
8246 : *
8247 : *****************************************************************************/
8248 :
8249 : GrantRoleStmt:
8250 : GRANT privilege_list TO role_list opt_granted_by
8251 : {
8252 206 : GrantRoleStmt *n = makeNode(GrantRoleStmt);
8253 :
8254 206 : n->is_grant = true;
8255 206 : n->granted_roles = $2;
8256 206 : n->grantee_roles = $4;
8257 206 : n->opt = NIL;
8258 206 : n->grantor = $5;
8259 206 : $$ = (Node *) n;
8260 : }
8261 : | GRANT privilege_list TO role_list WITH grant_role_opt_list opt_granted_by
8262 : {
8263 133 : GrantRoleStmt *n = makeNode(GrantRoleStmt);
8264 :
8265 133 : n->is_grant = true;
8266 133 : n->granted_roles = $2;
8267 133 : n->grantee_roles = $4;
8268 133 : n->opt = $6;
8269 133 : n->grantor = $7;
8270 133 : $$ = (Node *) n;
8271 : }
8272 : ;
8273 :
8274 : RevokeRoleStmt:
8275 : REVOKE privilege_list FROM role_list opt_granted_by opt_drop_behavior
8276 : {
8277 67 : GrantRoleStmt *n = makeNode(GrantRoleStmt);
8278 :
8279 67 : n->is_grant = false;
8280 67 : n->opt = NIL;
8281 67 : n->granted_roles = $2;
8282 67 : n->grantee_roles = $4;
8283 67 : n->grantor = $5;
8284 67 : n->behavior = $6;
8285 67 : $$ = (Node *) n;
8286 : }
8287 : | REVOKE ColId OPTION FOR privilege_list FROM role_list opt_granted_by opt_drop_behavior
8288 : {
8289 44 : GrantRoleStmt *n = makeNode(GrantRoleStmt);
8290 : DefElem *opt;
8291 :
8292 44 : opt = makeDefElem(pstrdup($2),
8293 44 : (Node *) makeBoolean(false), @2);
8294 44 : n->is_grant = false;
8295 44 : n->opt = list_make1(opt);
8296 44 : n->granted_roles = $5;
8297 44 : n->grantee_roles = $7;
8298 44 : n->grantor = $8;
8299 44 : n->behavior = $9;
8300 44 : $$ = (Node *) n;
8301 : }
8302 : ;
8303 :
8304 : grant_role_opt_list:
8305 82 : grant_role_opt_list ',' grant_role_opt { $$ = lappend($1, $3); }
8306 133 : | grant_role_opt { $$ = list_make1($1); }
8307 : ;
8308 :
8309 : grant_role_opt:
8310 : ColLabel grant_role_opt_value
8311 : {
8312 215 : $$ = makeDefElem(pstrdup($1), $2, @1);
8313 : }
8314 : ;
8315 :
8316 : grant_role_opt_value:
8317 48 : OPTION { $$ = (Node *) makeBoolean(true); }
8318 89 : | TRUE_P { $$ = (Node *) makeBoolean(true); }
8319 78 : | FALSE_P { $$ = (Node *) makeBoolean(false); }
8320 : ;
8321 :
8322 108 : opt_granted_by: GRANTED BY RoleSpec { $$ = $3; }
8323 9391 : | /*EMPTY*/ { $$ = NULL; }
8324 : ;
8325 :
8326 : /*****************************************************************************
8327 : *
8328 : * ALTER DEFAULT PRIVILEGES statement
8329 : *
8330 : *****************************************************************************/
8331 :
8332 : AlterDefaultPrivilegesStmt:
8333 : ALTER DEFAULT PRIVILEGES DefACLOptionList DefACLAction
8334 : {
8335 135 : AlterDefaultPrivilegesStmt *n = makeNode(AlterDefaultPrivilegesStmt);
8336 :
8337 135 : n->options = $4;
8338 135 : n->action = (GrantStmt *) $5;
8339 135 : $$ = (Node *) n;
8340 : }
8341 : ;
8342 :
8343 : DefACLOptionList:
8344 93 : DefACLOptionList DefACLOption { $$ = lappend($1, $2); }
8345 135 : | /* EMPTY */ { $$ = NIL; }
8346 : ;
8347 :
8348 : DefACLOption:
8349 : IN_P SCHEMA name_list
8350 : {
8351 39 : $$ = makeDefElem("schemas", (Node *) $3, @1);
8352 : }
8353 : | FOR ROLE role_list
8354 : {
8355 54 : $$ = makeDefElem("roles", (Node *) $3, @1);
8356 : }
8357 : | FOR USER role_list
8358 : {
8359 0 : $$ = makeDefElem("roles", (Node *) $3, @1);
8360 : }
8361 : ;
8362 :
8363 : /*
8364 : * This should match GRANT/REVOKE, except that individual target objects
8365 : * are not mentioned and we only allow a subset of object types.
8366 : */
8367 : DefACLAction:
8368 : GRANT privileges ON defacl_privilege_target TO grantee_list
8369 : opt_grant_grant_option
8370 : {
8371 82 : GrantStmt *n = makeNode(GrantStmt);
8372 :
8373 82 : n->is_grant = true;
8374 82 : n->privileges = $2;
8375 82 : n->targtype = ACL_TARGET_DEFAULTS;
8376 82 : n->objtype = $4;
8377 82 : n->objects = NIL;
8378 82 : n->grantees = $6;
8379 82 : n->grant_option = $7;
8380 82 : $$ = (Node *) n;
8381 : }
8382 : | REVOKE privileges ON defacl_privilege_target
8383 : FROM grantee_list opt_drop_behavior
8384 : {
8385 53 : GrantStmt *n = makeNode(GrantStmt);
8386 :
8387 53 : n->is_grant = false;
8388 53 : n->grant_option = false;
8389 53 : n->privileges = $2;
8390 53 : n->targtype = ACL_TARGET_DEFAULTS;
8391 53 : n->objtype = $4;
8392 53 : n->objects = NIL;
8393 53 : n->grantees = $6;
8394 53 : n->behavior = $7;
8395 53 : $$ = (Node *) n;
8396 : }
8397 : | REVOKE GRANT OPTION FOR privileges ON defacl_privilege_target
8398 : FROM grantee_list opt_drop_behavior
8399 : {
8400 0 : GrantStmt *n = makeNode(GrantStmt);
8401 :
8402 0 : n->is_grant = false;
8403 0 : n->grant_option = true;
8404 0 : n->privileges = $5;
8405 0 : n->targtype = ACL_TARGET_DEFAULTS;
8406 0 : n->objtype = $7;
8407 0 : n->objects = NIL;
8408 0 : n->grantees = $9;
8409 0 : n->behavior = $10;
8410 0 : $$ = (Node *) n;
8411 : }
8412 : ;
8413 :
8414 : defacl_privilege_target:
8415 51 : TABLES { $$ = OBJECT_TABLE; }
8416 10 : | FUNCTIONS { $$ = OBJECT_FUNCTION; }
8417 4 : | ROUTINES { $$ = OBJECT_FUNCTION; }
8418 4 : | SEQUENCES { $$ = OBJECT_SEQUENCE; }
8419 22 : | TYPES_P { $$ = OBJECT_TYPE; }
8420 24 : | SCHEMAS { $$ = OBJECT_SCHEMA; }
8421 20 : | LARGE_P OBJECTS_P { $$ = OBJECT_LARGEOBJECT; }
8422 : ;
8423 :
8424 :
8425 : /*****************************************************************************
8426 : *
8427 : * QUERY: CREATE INDEX
8428 : *
8429 : * Note: we cannot put TABLESPACE clause after WHERE clause unless we are
8430 : * willing to make TABLESPACE a fully reserved word.
8431 : *****************************************************************************/
8432 :
8433 : IndexStmt: CREATE opt_unique INDEX opt_concurrently opt_single_name
8434 : ON relation_expr access_method_clause '(' index_params ')'
8435 : opt_include opt_unique_null_treatment opt_reloptions OptTableSpace where_clause
8436 : {
8437 4409 : IndexStmt *n = makeNode(IndexStmt);
8438 :
8439 4409 : n->unique = $2;
8440 4409 : n->concurrent = $4;
8441 4409 : n->idxname = $5;
8442 4409 : n->relation = $7;
8443 4409 : n->accessMethod = $8;
8444 4409 : n->indexParams = $10;
8445 4409 : n->indexIncludingParams = $12;
8446 4409 : n->nulls_not_distinct = !$13;
8447 4409 : n->options = $14;
8448 4409 : n->tableSpace = $15;
8449 4409 : n->whereClause = $16;
8450 4409 : n->excludeOpNames = NIL;
8451 4409 : n->idxcomment = NULL;
8452 4409 : n->indexOid = InvalidOid;
8453 4409 : n->oldNumber = InvalidRelFileNumber;
8454 4409 : n->oldCreateSubid = InvalidSubTransactionId;
8455 4409 : n->oldFirstRelfilelocatorSubid = InvalidSubTransactionId;
8456 4409 : n->primary = false;
8457 4409 : n->isconstraint = false;
8458 4409 : n->deferrable = false;
8459 4409 : n->initdeferred = false;
8460 4409 : n->transformed = false;
8461 4409 : n->if_not_exists = false;
8462 4409 : n->reset_default_tblspc = false;
8463 4409 : $$ = (Node *) n;
8464 : }
8465 : | CREATE opt_unique INDEX opt_concurrently IF_P NOT EXISTS name
8466 : ON relation_expr access_method_clause '(' index_params ')'
8467 : opt_include opt_unique_null_treatment opt_reloptions OptTableSpace where_clause
8468 : {
8469 12 : IndexStmt *n = makeNode(IndexStmt);
8470 :
8471 12 : n->unique = $2;
8472 12 : n->concurrent = $4;
8473 12 : n->idxname = $8;
8474 12 : n->relation = $10;
8475 12 : n->accessMethod = $11;
8476 12 : n->indexParams = $13;
8477 12 : n->indexIncludingParams = $15;
8478 12 : n->nulls_not_distinct = !$16;
8479 12 : n->options = $17;
8480 12 : n->tableSpace = $18;
8481 12 : n->whereClause = $19;
8482 12 : n->excludeOpNames = NIL;
8483 12 : n->idxcomment = NULL;
8484 12 : n->indexOid = InvalidOid;
8485 12 : n->oldNumber = InvalidRelFileNumber;
8486 12 : n->oldCreateSubid = InvalidSubTransactionId;
8487 12 : n->oldFirstRelfilelocatorSubid = InvalidSubTransactionId;
8488 12 : n->primary = false;
8489 12 : n->isconstraint = false;
8490 12 : n->deferrable = false;
8491 12 : n->initdeferred = false;
8492 12 : n->transformed = false;
8493 12 : n->if_not_exists = true;
8494 12 : n->reset_default_tblspc = false;
8495 12 : $$ = (Node *) n;
8496 : }
8497 : ;
8498 :
8499 : opt_unique:
8500 829 : UNIQUE { $$ = true; }
8501 3596 : | /*EMPTY*/ { $$ = false; }
8502 : ;
8503 :
8504 : access_method_clause:
8505 1846 : USING name { $$ = $2; }
8506 2728 : | /*EMPTY*/ { $$ = DEFAULT_INDEX_TYPE; }
8507 : ;
8508 :
8509 5670 : index_params: index_elem { $$ = list_make1($1); }
8510 1399 : | index_params ',' index_elem { $$ = lappend($1, $3); }
8511 : ;
8512 :
8513 :
8514 : index_elem_options:
8515 : opt_collate opt_qualified_name opt_asc_desc opt_nulls_order
8516 : {
8517 7450 : $$ = makeNode(IndexElem);
8518 7450 : $$->name = NULL;
8519 7450 : $$->expr = NULL;
8520 7450 : $$->indexcolname = NULL;
8521 7450 : $$->collation = $1;
8522 7450 : $$->opclass = $2;
8523 7450 : $$->opclassopts = NIL;
8524 7450 : $$->ordering = $3;
8525 7450 : $$->nulls_ordering = $4;
8526 : /* location will be filled in index_elem production */
8527 : }
8528 : | opt_collate any_name reloptions opt_asc_desc opt_nulls_order
8529 : {
8530 91 : $$ = makeNode(IndexElem);
8531 91 : $$->name = NULL;
8532 91 : $$->expr = NULL;
8533 91 : $$->indexcolname = NULL;
8534 91 : $$->collation = $1;
8535 91 : $$->opclass = $2;
8536 91 : $$->opclassopts = $3;
8537 91 : $$->ordering = $4;
8538 91 : $$->nulls_ordering = $5;
8539 : /* location will be filled in index_elem production */
8540 : }
8541 : ;
8542 :
8543 : /*
8544 : * Index attributes can be either simple column references, or arbitrary
8545 : * expressions in parens. For backwards-compatibility reasons, we allow
8546 : * an expression that's just a function call to be written without parens.
8547 : */
8548 : index_elem: ColId index_elem_options
8549 : {
8550 6645 : $$ = $2;
8551 6645 : $$->name = $1;
8552 6645 : $$->location = @1;
8553 : }
8554 : | func_expr_windowless index_elem_options
8555 : {
8556 552 : $$ = $2;
8557 552 : $$->expr = $1;
8558 552 : $$->location = @1;
8559 : }
8560 : | '(' a_expr ')' index_elem_options
8561 : {
8562 344 : $$ = $4;
8563 344 : $$->expr = $2;
8564 344 : $$->location = @1;
8565 : }
8566 : ;
8567 :
8568 141 : opt_include: INCLUDE '(' index_including_params ')' { $$ = $3; }
8569 4280 : | /* EMPTY */ { $$ = NIL; }
8570 : ;
8571 :
8572 141 : index_including_params: index_elem { $$ = list_make1($1); }
8573 109 : | index_including_params ',' index_elem { $$ = lappend($1, $3); }
8574 : ;
8575 :
8576 126 : opt_collate: COLLATE any_name { $$ = $2; }
8577 11324 : | /*EMPTY*/ { $$ = NIL; }
8578 : ;
8579 :
8580 :
8581 1018 : opt_asc_desc: ASC { $$ = SORTBY_ASC; }
8582 2384 : | DESC { $$ = SORTBY_DESC; }
8583 79591 : | /*EMPTY*/ { $$ = SORTBY_DEFAULT; }
8584 : ;
8585 :
8586 213 : opt_nulls_order: NULLS_LA FIRST_P { $$ = SORTBY_NULLS_FIRST; }
8587 904 : | NULLS_LA LAST_P { $$ = SORTBY_NULLS_LAST; }
8588 82018 : | /*EMPTY*/ { $$ = SORTBY_NULLS_DEFAULT; }
8589 : ;
8590 :
8591 :
8592 : /*****************************************************************************
8593 : *
8594 : * QUERY:
8595 : * create [or replace] function <fname>
8596 : * [(<type-1> { , <type-n>})]
8597 : * returns <type-r>
8598 : * as <filename or code in language as appropriate>
8599 : * language <lang> [with parameters]
8600 : *
8601 : *****************************************************************************/
8602 :
8603 : CreateFunctionStmt:
8604 : CREATE opt_or_replace FUNCTION func_name func_args_with_defaults
8605 : RETURNS func_return opt_createfunc_opt_list opt_routine_body
8606 : {
8607 12162 : CreateFunctionStmt *n = makeNode(CreateFunctionStmt);
8608 :
8609 12162 : n->is_procedure = false;
8610 12162 : n->replace = $2;
8611 12162 : n->funcname = $4;
8612 12162 : n->parameters = $5;
8613 12162 : n->returnType = $7;
8614 12162 : n->options = $8;
8615 12162 : n->sql_body = $9;
8616 12162 : $$ = (Node *) n;
8617 : }
8618 : | CREATE opt_or_replace FUNCTION func_name func_args_with_defaults
8619 : RETURNS TABLE '(' table_func_column_list ')' opt_createfunc_opt_list opt_routine_body
8620 : {
8621 146 : CreateFunctionStmt *n = makeNode(CreateFunctionStmt);
8622 :
8623 146 : n->is_procedure = false;
8624 146 : n->replace = $2;
8625 146 : n->funcname = $4;
8626 146 : n->parameters = mergeTableFuncParameters($5, $9, yyscanner);
8627 146 : n->returnType = TableFuncTypeName($9);
8628 146 : n->returnType->location = @7;
8629 146 : n->options = $11;
8630 146 : n->sql_body = $12;
8631 146 : $$ = (Node *) n;
8632 : }
8633 : | CREATE opt_or_replace FUNCTION func_name func_args_with_defaults
8634 : opt_createfunc_opt_list opt_routine_body
8635 : {
8636 301 : CreateFunctionStmt *n = makeNode(CreateFunctionStmt);
8637 :
8638 301 : n->is_procedure = false;
8639 301 : n->replace = $2;
8640 301 : n->funcname = $4;
8641 301 : n->parameters = $5;
8642 301 : n->returnType = NULL;
8643 301 : n->options = $6;
8644 301 : n->sql_body = $7;
8645 301 : $$ = (Node *) n;
8646 : }
8647 : | CREATE opt_or_replace PROCEDURE func_name func_args_with_defaults
8648 : opt_createfunc_opt_list opt_routine_body
8649 : {
8650 223 : CreateFunctionStmt *n = makeNode(CreateFunctionStmt);
8651 :
8652 223 : n->is_procedure = true;
8653 223 : n->replace = $2;
8654 223 : n->funcname = $4;
8655 223 : n->parameters = $5;
8656 223 : n->returnType = NULL;
8657 223 : n->options = $6;
8658 223 : n->sql_body = $7;
8659 223 : $$ = (Node *) n;
8660 : }
8661 : ;
8662 :
8663 : opt_or_replace:
8664 3831 : OR REPLACE { $$ = true; }
8665 12549 : | /*EMPTY*/ { $$ = false; }
8666 : ;
8667 :
8668 3913 : func_args: '(' func_args_list ')' { $$ = $2; }
8669 1185 : | '(' ')' { $$ = NIL; }
8670 : ;
8671 :
8672 : func_args_list:
8673 3913 : func_arg { $$ = list_make1($1); }
8674 3937 : | func_args_list ',' func_arg { $$ = lappend($1, $3); }
8675 : ;
8676 :
8677 : function_with_argtypes_list:
8678 2940 : function_with_argtypes { $$ = list_make1($1); }
8679 : | function_with_argtypes_list ',' function_with_argtypes
8680 56 : { $$ = lappend($1, $3); }
8681 : ;
8682 :
8683 : function_with_argtypes:
8684 : func_name func_args
8685 : {
8686 5098 : ObjectWithArgs *n = makeNode(ObjectWithArgs);
8687 :
8688 5098 : n->objname = $1;
8689 5098 : n->objargs = extractArgTypes($2);
8690 5098 : n->objfuncargs = $2;
8691 5098 : $$ = n;
8692 : }
8693 : /*
8694 : * Because of reduce/reduce conflicts, we can't use func_name
8695 : * below, but we can write it out the long way, which actually
8696 : * allows more cases.
8697 : */
8698 : | type_func_name_keyword
8699 : {
8700 0 : ObjectWithArgs *n = makeNode(ObjectWithArgs);
8701 :
8702 0 : n->objname = list_make1(makeString(pstrdup($1)));
8703 0 : n->args_unspecified = true;
8704 0 : $$ = n;
8705 : }
8706 : | ColId
8707 : {
8708 291 : ObjectWithArgs *n = makeNode(ObjectWithArgs);
8709 :
8710 291 : n->objname = list_make1(makeString($1));
8711 291 : n->args_unspecified = true;
8712 291 : $$ = n;
8713 : }
8714 : | ColId indirection
8715 : {
8716 14 : ObjectWithArgs *n = makeNode(ObjectWithArgs);
8717 :
8718 14 : n->objname = check_func_name(lcons(makeString($1), $2),
8719 : yyscanner);
8720 14 : n->args_unspecified = true;
8721 14 : $$ = n;
8722 : }
8723 : ;
8724 :
8725 : /*
8726 : * func_args_with_defaults is separate because we only want to accept
8727 : * defaults in CREATE FUNCTION, not in ALTER etc.
8728 : */
8729 : func_args_with_defaults:
8730 10093 : '(' func_args_with_defaults_list ')' { $$ = $2; }
8731 2739 : | '(' ')' { $$ = NIL; }
8732 : ;
8733 :
8734 : func_args_with_defaults_list:
8735 10093 : func_arg_with_default { $$ = list_make1($1); }
8736 : | func_args_with_defaults_list ',' func_arg_with_default
8737 14554 : { $$ = lappend($1, $3); }
8738 : ;
8739 :
8740 : /*
8741 : * The style with arg_class first is SQL99 standard, but Oracle puts
8742 : * param_name first; accept both since it's likely people will try both
8743 : * anyway. Don't bother trying to save productions by letting arg_class
8744 : * have an empty alternative ... you'll get shift/reduce conflicts.
8745 : *
8746 : * We can catch over-specified arguments here if we want to,
8747 : * but for now better to silently swallow typmod, etc.
8748 : * - thomas 2000-03-22
8749 : */
8750 : func_arg:
8751 : arg_class param_name func_type
8752 : {
8753 7203 : FunctionParameter *n = makeNode(FunctionParameter);
8754 :
8755 7203 : n->name = $2;
8756 7203 : n->argType = $3;
8757 7203 : n->mode = $1;
8758 7203 : n->defexpr = NULL;
8759 7203 : n->location = @1;
8760 7203 : $$ = n;
8761 : }
8762 : | param_name arg_class func_type
8763 : {
8764 235 : FunctionParameter *n = makeNode(FunctionParameter);
8765 :
8766 235 : n->name = $1;
8767 235 : n->argType = $3;
8768 235 : n->mode = $2;
8769 235 : n->defexpr = NULL;
8770 235 : n->location = @1;
8771 235 : $$ = n;
8772 : }
8773 : | param_name func_type
8774 : {
8775 4260 : FunctionParameter *n = makeNode(FunctionParameter);
8776 :
8777 4260 : n->name = $1;
8778 4260 : n->argType = $2;
8779 4260 : n->mode = FUNC_PARAM_DEFAULT;
8780 4260 : n->defexpr = NULL;
8781 4260 : n->location = @1;
8782 4260 : $$ = n;
8783 : }
8784 : | arg_class func_type
8785 : {
8786 201 : FunctionParameter *n = makeNode(FunctionParameter);
8787 :
8788 201 : n->name = NULL;
8789 201 : n->argType = $2;
8790 201 : n->mode = $1;
8791 201 : n->defexpr = NULL;
8792 201 : n->location = @1;
8793 201 : $$ = n;
8794 : }
8795 : | func_type
8796 : {
8797 21158 : FunctionParameter *n = makeNode(FunctionParameter);
8798 :
8799 21158 : n->name = NULL;
8800 21158 : n->argType = $1;
8801 21158 : n->mode = FUNC_PARAM_DEFAULT;
8802 21158 : n->defexpr = NULL;
8803 21158 : n->location = @1;
8804 21158 : $$ = n;
8805 : }
8806 : ;
8807 :
8808 : /* INOUT is SQL99 standard, IN OUT is for Oracle compatibility */
8809 1394 : arg_class: IN_P { $$ = FUNC_PARAM_IN; }
8810 6004 : | OUT_P { $$ = FUNC_PARAM_OUT; }
8811 120 : | INOUT { $$ = FUNC_PARAM_INOUT; }
8812 0 : | IN_P OUT_P { $$ = FUNC_PARAM_INOUT; }
8813 121 : | VARIADIC { $$ = FUNC_PARAM_VARIADIC; }
8814 : ;
8815 :
8816 : /*
8817 : * Ideally param_name should be ColId, but that causes too many conflicts.
8818 : */
8819 : param_name: type_function_name
8820 : ;
8821 :
8822 : func_return:
8823 : func_type
8824 : {
8825 : /* We can catch over-specified results here if we want to,
8826 : * but for now better to silently swallow typmod, etc.
8827 : * - thomas 2000-03-22
8828 : */
8829 12162 : $$ = $1;
8830 : }
8831 : ;
8832 :
8833 : /*
8834 : * We would like to make the %TYPE productions here be ColId attrs etc,
8835 : * but that causes reduce/reduce conflicts. type_function_name
8836 : * is next best choice.
8837 : */
8838 57776 : func_type: Typename { $$ = $1; }
8839 : | type_function_name attrs '%' TYPE_P
8840 : {
8841 12 : $$ = makeTypeNameFromNameList(lcons(makeString($1), $2));
8842 12 : $$->pct_type = true;
8843 12 : $$->location = @1;
8844 : }
8845 : | SETOF type_function_name attrs '%' TYPE_P
8846 : {
8847 4 : $$ = makeTypeNameFromNameList(lcons(makeString($2), $3));
8848 4 : $$->pct_type = true;
8849 4 : $$->setof = true;
8850 4 : $$->location = @2;
8851 : }
8852 : ;
8853 :
8854 : func_arg_with_default:
8855 : func_arg
8856 : {
8857 24096 : $$ = $1;
8858 : }
8859 : | func_arg DEFAULT a_expr
8860 : {
8861 423 : $$ = $1;
8862 423 : $$->defexpr = $3;
8863 : }
8864 : | func_arg '=' a_expr
8865 : {
8866 128 : $$ = $1;
8867 128 : $$->defexpr = $3;
8868 : }
8869 : ;
8870 :
8871 : /* Aggregate args can be most things that function args can be */
8872 : aggr_arg: func_arg
8873 : {
8874 560 : if (!($1->mode == FUNC_PARAM_DEFAULT ||
8875 36 : $1->mode == FUNC_PARAM_IN ||
8876 36 : $1->mode == FUNC_PARAM_VARIADIC))
8877 0 : ereport(ERROR,
8878 : (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
8879 : errmsg("aggregates cannot have output arguments"),
8880 : parser_errposition(@1)));
8881 560 : $$ = $1;
8882 : }
8883 : ;
8884 :
8885 : /*
8886 : * The SQL standard offers no guidance on how to declare aggregate argument
8887 : * lists, since it doesn't have CREATE AGGREGATE etc. We accept these cases:
8888 : *
8889 : * (*) - normal agg with no args
8890 : * (aggr_arg,...) - normal agg with args
8891 : * (ORDER BY aggr_arg,...) - ordered-set agg with no direct args
8892 : * (aggr_arg,... ORDER BY aggr_arg,...) - ordered-set agg with direct args
8893 : *
8894 : * The zero-argument case is spelled with '*' for consistency with COUNT(*).
8895 : *
8896 : * An additional restriction is that if the direct-args list ends in a
8897 : * VARIADIC item, the ordered-args list must contain exactly one item that
8898 : * is also VARIADIC with the same type. This allows us to collapse the two
8899 : * VARIADIC items into one, which is necessary to represent the aggregate in
8900 : * pg_proc. We check this at the grammar stage so that we can return a list
8901 : * in which the second VARIADIC item is already discarded, avoiding extra work
8902 : * in cases such as DROP AGGREGATE.
8903 : *
8904 : * The return value of this production is a two-element list, in which the
8905 : * first item is a sublist of FunctionParameter nodes (with any duplicate
8906 : * VARIADIC item already dropped, as per above) and the second is an Integer
8907 : * node, containing -1 if there was no ORDER BY and otherwise the number
8908 : * of argument declarations before the ORDER BY. (If this number is equal
8909 : * to the first sublist's length, then we dropped a duplicate VARIADIC item.)
8910 : * This representation is passed as-is to CREATE AGGREGATE; for operations
8911 : * on existing aggregates, we can just apply extractArgTypes to the first
8912 : * sublist.
8913 : */
8914 : aggr_args: '(' '*' ')'
8915 : {
8916 85 : $$ = list_make2(NIL, makeInteger(-1));
8917 : }
8918 : | '(' aggr_args_list ')'
8919 : {
8920 456 : $$ = list_make2($2, makeInteger(-1));
8921 : }
8922 : | '(' ORDER BY aggr_args_list ')'
8923 : {
8924 4 : $$ = list_make2($4, makeInteger(0));
8925 : }
8926 : | '(' aggr_args_list ORDER BY aggr_args_list ')'
8927 : {
8928 : /* this is the only case requiring consistency checking */
8929 20 : $$ = makeOrderedSetArgs($2, $5, yyscanner);
8930 : }
8931 : ;
8932 :
8933 : aggr_args_list:
8934 500 : aggr_arg { $$ = list_make1($1); }
8935 60 : | aggr_args_list ',' aggr_arg { $$ = lappend($1, $3); }
8936 : ;
8937 :
8938 : aggregate_with_argtypes:
8939 : func_name aggr_args
8940 : {
8941 220 : ObjectWithArgs *n = makeNode(ObjectWithArgs);
8942 :
8943 220 : n->objname = $1;
8944 220 : n->objargs = extractAggrArgTypes($2);
8945 220 : n->objfuncargs = (List *) linitial($2);
8946 220 : $$ = n;
8947 : }
8948 : ;
8949 :
8950 : aggregate_with_argtypes_list:
8951 69 : aggregate_with_argtypes { $$ = list_make1($1); }
8952 : | aggregate_with_argtypes_list ',' aggregate_with_argtypes
8953 0 : { $$ = lappend($1, $3); }
8954 : ;
8955 :
8956 : opt_createfunc_opt_list:
8957 : createfunc_opt_list
8958 87 : | /*EMPTY*/ { $$ = NIL; }
8959 : ;
8960 :
8961 : createfunc_opt_list:
8962 : /* Must be at least one to prevent conflict */
8963 12745 : createfunc_opt_item { $$ = list_make1($1); }
8964 30929 : | createfunc_opt_list createfunc_opt_item { $$ = lappend($1, $2); }
8965 : ;
8966 :
8967 : /*
8968 : * Options common to both CREATE FUNCTION and ALTER FUNCTION
8969 : */
8970 : common_func_opt_item:
8971 : CALLED ON NULL_P INPUT_P
8972 : {
8973 62 : $$ = makeDefElem("strict", (Node *) makeBoolean(false), @1);
8974 : }
8975 : | RETURNS NULL_P ON NULL_P INPUT_P
8976 : {
8977 508 : $$ = makeDefElem("strict", (Node *) makeBoolean(true), @1);
8978 : }
8979 : | STRICT_P
8980 : {
8981 6051 : $$ = makeDefElem("strict", (Node *) makeBoolean(true), @1);
8982 : }
8983 : | IMMUTABLE
8984 : {
8985 4904 : $$ = makeDefElem("volatility", (Node *) makeString("immutable"), @1);
8986 : }
8987 : | STABLE
8988 : {
8989 973 : $$ = makeDefElem("volatility", (Node *) makeString("stable"), @1);
8990 : }
8991 : | VOLATILE
8992 : {
8993 192 : $$ = makeDefElem("volatility", (Node *) makeString("volatile"), @1);
8994 : }
8995 : | EXTERNAL SECURITY DEFINER
8996 : {
8997 0 : $$ = makeDefElem("security", (Node *) makeBoolean(true), @1);
8998 : }
8999 : | EXTERNAL SECURITY INVOKER
9000 : {
9001 0 : $$ = makeDefElem("security", (Node *) makeBoolean(false), @1);
9002 : }
9003 : | SECURITY DEFINER
9004 : {
9005 36 : $$ = makeDefElem("security", (Node *) makeBoolean(true), @1);
9006 : }
9007 : | SECURITY INVOKER
9008 : {
9009 12 : $$ = makeDefElem("security", (Node *) makeBoolean(false), @1);
9010 : }
9011 : | LEAKPROOF
9012 : {
9013 30 : $$ = makeDefElem("leakproof", (Node *) makeBoolean(true), @1);
9014 : }
9015 : | NOT LEAKPROOF
9016 : {
9017 8 : $$ = makeDefElem("leakproof", (Node *) makeBoolean(false), @1);
9018 : }
9019 : | COST NumericOnly
9020 : {
9021 2175 : $$ = makeDefElem("cost", (Node *) $2, @1);
9022 : }
9023 : | ROWS NumericOnly
9024 : {
9025 67 : $$ = makeDefElem("rows", (Node *) $2, @1);
9026 : }
9027 : | SUPPORT any_name
9028 : {
9029 70 : $$ = makeDefElem("support", (Node *) $2, @1);
9030 : }
9031 : | FunctionSetResetClause
9032 : {
9033 : /* we abuse the normal content of a DefElem here */
9034 96 : $$ = makeDefElem("set", (Node *) $1, @1);
9035 : }
9036 : | PARALLEL ColId
9037 : {
9038 6322 : $$ = makeDefElem("parallel", (Node *) makeString($2), @1);
9039 : }
9040 : ;
9041 :
9042 : createfunc_opt_item:
9043 : AS func_as
9044 : {
9045 9574 : $$ = makeDefElem("as", (Node *) $2, @1);
9046 : }
9047 : | LANGUAGE NonReservedWord_or_Sconst
9048 : {
9049 12732 : $$ = makeDefElem("language", (Node *) makeString($2), @1);
9050 : }
9051 : | TRANSFORM transform_type_list
9052 : {
9053 59 : $$ = makeDefElem("transform", (Node *) $2, @1);
9054 : }
9055 : | WINDOW
9056 : {
9057 13 : $$ = makeDefElem("window", (Node *) makeBoolean(true), @1);
9058 : }
9059 : | common_func_opt_item
9060 : {
9061 21296 : $$ = $1;
9062 : }
9063 : ;
9064 :
9065 7778 : func_as: Sconst { $$ = list_make1(makeString($1)); }
9066 : | Sconst ',' Sconst
9067 : {
9068 1796 : $$ = list_make2(makeString($1), makeString($3));
9069 : }
9070 : ;
9071 :
9072 : ReturnStmt: RETURN a_expr
9073 : {
9074 2746 : ReturnStmt *r = makeNode(ReturnStmt);
9075 :
9076 2746 : r->returnval = (Node *) $2;
9077 2746 : $$ = (Node *) r;
9078 : }
9079 : ;
9080 :
9081 : opt_routine_body:
9082 : ReturnStmt
9083 : {
9084 2742 : $$ = $1;
9085 : }
9086 : | BEGIN_P ATOMIC routine_body_stmt_list END_P
9087 : {
9088 : /*
9089 : * A compound statement is stored as a single-item list
9090 : * containing the list of statements as its member. That
9091 : * way, the parse analysis code can tell apart an empty
9092 : * body from no body at all.
9093 : */
9094 520 : $$ = (Node *) list_make1($3);
9095 : }
9096 : | /*EMPTY*/
9097 : {
9098 9570 : $$ = NULL;
9099 : }
9100 : ;
9101 :
9102 : routine_body_stmt_list:
9103 : routine_body_stmt_list routine_body_stmt ';'
9104 : {
9105 : /* As in stmtmulti, discard empty statements */
9106 531 : if ($2 != NULL)
9107 519 : $$ = lappend($1, $2);
9108 : else
9109 12 : $$ = $1;
9110 : }
9111 : | /*EMPTY*/
9112 : {
9113 520 : $$ = NIL;
9114 : }
9115 : ;
9116 :
9117 : routine_body_stmt:
9118 : stmt
9119 : | ReturnStmt
9120 : ;
9121 :
9122 : transform_type_list:
9123 59 : FOR TYPE_P Typename { $$ = list_make1($3); }
9124 2 : | transform_type_list ',' FOR TYPE_P Typename { $$ = lappend($1, $5); }
9125 : ;
9126 :
9127 : opt_definition:
9128 465 : WITH definition { $$ = $2; }
9129 6633 : | /*EMPTY*/ { $$ = NIL; }
9130 : ;
9131 :
9132 : table_func_column: param_name func_type
9133 : {
9134 343 : FunctionParameter *n = makeNode(FunctionParameter);
9135 :
9136 343 : n->name = $1;
9137 343 : n->argType = $2;
9138 343 : n->mode = FUNC_PARAM_TABLE;
9139 343 : n->defexpr = NULL;
9140 343 : n->location = @1;
9141 343 : $$ = n;
9142 : }
9143 : ;
9144 :
9145 : table_func_column_list:
9146 : table_func_column
9147 : {
9148 146 : $$ = list_make1($1);
9149 : }
9150 : | table_func_column_list ',' table_func_column
9151 : {
9152 197 : $$ = lappend($1, $3);
9153 : }
9154 : ;
9155 :
9156 : /*****************************************************************************
9157 : * ALTER FUNCTION / ALTER PROCEDURE / ALTER ROUTINE
9158 : *
9159 : * RENAME and OWNER subcommands are already provided by the generic
9160 : * ALTER infrastructure, here we just specify alterations that can
9161 : * only be applied to functions.
9162 : *
9163 : *****************************************************************************/
9164 : AlterFunctionStmt:
9165 : ALTER FUNCTION function_with_argtypes alterfunc_opt_list opt_restrict
9166 : {
9167 196 : AlterFunctionStmt *n = makeNode(AlterFunctionStmt);
9168 :
9169 196 : n->objtype = OBJECT_FUNCTION;
9170 196 : n->func = $3;
9171 196 : n->actions = $4;
9172 196 : $$ = (Node *) n;
9173 : }
9174 : | ALTER PROCEDURE function_with_argtypes alterfunc_opt_list opt_restrict
9175 : {
9176 12 : AlterFunctionStmt *n = makeNode(AlterFunctionStmt);
9177 :
9178 12 : n->objtype = OBJECT_PROCEDURE;
9179 12 : n->func = $3;
9180 12 : n->actions = $4;
9181 12 : $$ = (Node *) n;
9182 : }
9183 : | ALTER ROUTINE function_with_argtypes alterfunc_opt_list opt_restrict
9184 : {
9185 0 : AlterFunctionStmt *n = makeNode(AlterFunctionStmt);
9186 :
9187 0 : n->objtype = OBJECT_ROUTINE;
9188 0 : n->func = $3;
9189 0 : n->actions = $4;
9190 0 : $$ = (Node *) n;
9191 : }
9192 : ;
9193 :
9194 : alterfunc_opt_list:
9195 : /* At least one option must be specified */
9196 208 : common_func_opt_item { $$ = list_make1($1); }
9197 2 : | alterfunc_opt_list common_func_opt_item { $$ = lappend($1, $2); }
9198 : ;
9199 :
9200 : /* Ignored, merely for SQL compliance */
9201 : opt_restrict:
9202 : RESTRICT
9203 : | /* EMPTY */
9204 : ;
9205 :
9206 :
9207 : /*****************************************************************************
9208 : *
9209 : * QUERY:
9210 : *
9211 : * DROP FUNCTION funcname (arg1, arg2, ...) [ RESTRICT | CASCADE ]
9212 : * DROP PROCEDURE procname (arg1, arg2, ...) [ RESTRICT | CASCADE ]
9213 : * DROP ROUTINE routname (arg1, arg2, ...) [ RESTRICT | CASCADE ]
9214 : * DROP AGGREGATE aggname (arg1, ...) [ RESTRICT | CASCADE ]
9215 : * DROP OPERATOR opname (leftoperand_typ, rightoperand_typ) [ RESTRICT | CASCADE ]
9216 : *
9217 : *****************************************************************************/
9218 :
9219 : RemoveFuncStmt:
9220 : DROP FUNCTION function_with_argtypes_list opt_drop_behavior
9221 : {
9222 2160 : DropStmt *n = makeNode(DropStmt);
9223 :
9224 2160 : n->removeType = OBJECT_FUNCTION;
9225 2160 : n->objects = $3;
9226 2160 : n->behavior = $4;
9227 2160 : n->missing_ok = false;
9228 2160 : n->concurrent = false;
9229 2160 : $$ = (Node *) n;
9230 : }
9231 : | DROP FUNCTION IF_P EXISTS function_with_argtypes_list opt_drop_behavior
9232 : {
9233 136 : DropStmt *n = makeNode(DropStmt);
9234 :
9235 136 : n->removeType = OBJECT_FUNCTION;
9236 136 : n->objects = $5;
9237 136 : n->behavior = $6;
9238 136 : n->missing_ok = true;
9239 136 : n->concurrent = false;
9240 136 : $$ = (Node *) n;
9241 : }
9242 : | DROP PROCEDURE function_with_argtypes_list opt_drop_behavior
9243 : {
9244 89 : DropStmt *n = makeNode(DropStmt);
9245 :
9246 89 : n->removeType = OBJECT_PROCEDURE;
9247 89 : n->objects = $3;
9248 89 : n->behavior = $4;
9249 89 : n->missing_ok = false;
9250 89 : n->concurrent = false;
9251 89 : $$ = (Node *) n;
9252 : }
9253 : | DROP PROCEDURE IF_P EXISTS function_with_argtypes_list opt_drop_behavior
9254 : {
9255 4 : DropStmt *n = makeNode(DropStmt);
9256 :
9257 4 : n->removeType = OBJECT_PROCEDURE;
9258 4 : n->objects = $5;
9259 4 : n->behavior = $6;
9260 4 : n->missing_ok = true;
9261 4 : n->concurrent = false;
9262 4 : $$ = (Node *) n;
9263 : }
9264 : | DROP ROUTINE function_with_argtypes_list opt_drop_behavior
9265 : {
9266 8 : DropStmt *n = makeNode(DropStmt);
9267 :
9268 8 : n->removeType = OBJECT_ROUTINE;
9269 8 : n->objects = $3;
9270 8 : n->behavior = $4;
9271 8 : n->missing_ok = false;
9272 8 : n->concurrent = false;
9273 8 : $$ = (Node *) n;
9274 : }
9275 : | DROP ROUTINE IF_P EXISTS function_with_argtypes_list opt_drop_behavior
9276 : {
9277 4 : DropStmt *n = makeNode(DropStmt);
9278 :
9279 4 : n->removeType = OBJECT_ROUTINE;
9280 4 : n->objects = $5;
9281 4 : n->behavior = $6;
9282 4 : n->missing_ok = true;
9283 4 : n->concurrent = false;
9284 4 : $$ = (Node *) n;
9285 : }
9286 : ;
9287 :
9288 : RemoveAggrStmt:
9289 : DROP AGGREGATE aggregate_with_argtypes_list opt_drop_behavior
9290 : {
9291 49 : DropStmt *n = makeNode(DropStmt);
9292 :
9293 49 : n->removeType = OBJECT_AGGREGATE;
9294 49 : n->objects = $3;
9295 49 : n->behavior = $4;
9296 49 : n->missing_ok = false;
9297 49 : n->concurrent = false;
9298 49 : $$ = (Node *) n;
9299 : }
9300 : | DROP AGGREGATE IF_P EXISTS aggregate_with_argtypes_list opt_drop_behavior
9301 : {
9302 20 : DropStmt *n = makeNode(DropStmt);
9303 :
9304 20 : n->removeType = OBJECT_AGGREGATE;
9305 20 : n->objects = $5;
9306 20 : n->behavior = $6;
9307 20 : n->missing_ok = true;
9308 20 : n->concurrent = false;
9309 20 : $$ = (Node *) n;
9310 : }
9311 : ;
9312 :
9313 : RemoveOperStmt:
9314 : DROP OPERATOR operator_with_argtypes_list opt_drop_behavior
9315 : {
9316 124 : DropStmt *n = makeNode(DropStmt);
9317 :
9318 124 : n->removeType = OBJECT_OPERATOR;
9319 124 : n->objects = $3;
9320 124 : n->behavior = $4;
9321 124 : n->missing_ok = false;
9322 124 : n->concurrent = false;
9323 124 : $$ = (Node *) n;
9324 : }
9325 : | DROP OPERATOR IF_P EXISTS operator_with_argtypes_list opt_drop_behavior
9326 : {
9327 20 : DropStmt *n = makeNode(DropStmt);
9328 :
9329 20 : n->removeType = OBJECT_OPERATOR;
9330 20 : n->objects = $5;
9331 20 : n->behavior = $6;
9332 20 : n->missing_ok = true;
9333 20 : n->concurrent = false;
9334 20 : $$ = (Node *) n;
9335 : }
9336 : ;
9337 :
9338 : oper_argtypes:
9339 : '(' Typename ')'
9340 : {
9341 8 : ereport(ERROR,
9342 : (errcode(ERRCODE_SYNTAX_ERROR),
9343 : errmsg("missing argument"),
9344 : errhint("Use NONE to denote the missing argument of a unary operator."),
9345 : parser_errposition(@3)));
9346 : }
9347 : | '(' Typename ',' Typename ')'
9348 1247 : { $$ = list_make2($2, $4); }
9349 : | '(' NONE ',' Typename ')' /* left unary */
9350 20 : { $$ = list_make2(NULL, $4); }
9351 : | '(' Typename ',' NONE ')' /* right unary */
9352 8 : { $$ = list_make2($2, NULL); }
9353 : ;
9354 :
9355 : any_operator:
9356 : all_Op
9357 13148 : { $$ = list_make1(makeString($1)); }
9358 : | ColId '.' any_operator
9359 9748 : { $$ = lcons(makeString($1), $3); }
9360 : ;
9361 :
9362 : operator_with_argtypes_list:
9363 144 : operator_with_argtypes { $$ = list_make1($1); }
9364 : | operator_with_argtypes_list ',' operator_with_argtypes
9365 0 : { $$ = lappend($1, $3); }
9366 : ;
9367 :
9368 : operator_with_argtypes:
9369 : any_operator oper_argtypes
9370 : {
9371 1275 : ObjectWithArgs *n = makeNode(ObjectWithArgs);
9372 :
9373 1275 : n->objname = $1;
9374 1275 : n->objargs = $2;
9375 1275 : $$ = n;
9376 : }
9377 : ;
9378 :
9379 : /*****************************************************************************
9380 : *
9381 : * DO <anonymous code block> [ LANGUAGE language ]
9382 : *
9383 : * We use a DefElem list for future extensibility, and to allow flexibility
9384 : * in the clause order.
9385 : *
9386 : *****************************************************************************/
9387 :
9388 : DoStmt: DO dostmt_opt_list
9389 : {
9390 668 : DoStmt *n = makeNode(DoStmt);
9391 :
9392 668 : n->args = $2;
9393 668 : $$ = (Node *) n;
9394 : }
9395 : ;
9396 :
9397 : dostmt_opt_list:
9398 668 : dostmt_opt_item { $$ = list_make1($1); }
9399 102 : | dostmt_opt_list dostmt_opt_item { $$ = lappend($1, $2); }
9400 : ;
9401 :
9402 : dostmt_opt_item:
9403 : Sconst
9404 : {
9405 668 : $$ = makeDefElem("as", (Node *) makeString($1), @1);
9406 : }
9407 : | LANGUAGE NonReservedWord_or_Sconst
9408 : {
9409 102 : $$ = makeDefElem("language", (Node *) makeString($2), @1);
9410 : }
9411 : ;
9412 :
9413 : /*****************************************************************************
9414 : *
9415 : * CREATE CAST / DROP CAST
9416 : *
9417 : *****************************************************************************/
9418 :
9419 : CreateCastStmt: CREATE CAST '(' Typename AS Typename ')'
9420 : WITH FUNCTION function_with_argtypes cast_context
9421 : {
9422 60 : CreateCastStmt *n = makeNode(CreateCastStmt);
9423 :
9424 60 : n->sourcetype = $4;
9425 60 : n->targettype = $6;
9426 60 : n->func = $10;
9427 60 : n->context = (CoercionContext) $11;
9428 60 : n->inout = false;
9429 60 : $$ = (Node *) n;
9430 : }
9431 : | CREATE CAST '(' Typename AS Typename ')'
9432 : WITHOUT FUNCTION cast_context
9433 : {
9434 97 : CreateCastStmt *n = makeNode(CreateCastStmt);
9435 :
9436 97 : n->sourcetype = $4;
9437 97 : n->targettype = $6;
9438 97 : n->func = NULL;
9439 97 : n->context = (CoercionContext) $10;
9440 97 : n->inout = false;
9441 97 : $$ = (Node *) n;
9442 : }
9443 : | CREATE CAST '(' Typename AS Typename ')'
9444 : WITH INOUT cast_context
9445 : {
9446 5 : CreateCastStmt *n = makeNode(CreateCastStmt);
9447 :
9448 5 : n->sourcetype = $4;
9449 5 : n->targettype = $6;
9450 5 : n->func = NULL;
9451 5 : n->context = (CoercionContext) $10;
9452 5 : n->inout = true;
9453 5 : $$ = (Node *) n;
9454 : }
9455 : ;
9456 :
9457 22 : cast_context: AS IMPLICIT_P { $$ = COERCION_IMPLICIT; }
9458 30 : | AS ASSIGNMENT { $$ = COERCION_ASSIGNMENT; }
9459 110 : | /*EMPTY*/ { $$ = COERCION_EXPLICIT; }
9460 : ;
9461 :
9462 :
9463 : DropCastStmt: DROP CAST opt_if_exists '(' Typename AS Typename ')' opt_drop_behavior
9464 : {
9465 40 : DropStmt *n = makeNode(DropStmt);
9466 :
9467 40 : n->removeType = OBJECT_CAST;
9468 40 : n->objects = list_make1(list_make2($5, $7));
9469 40 : n->behavior = $9;
9470 40 : n->missing_ok = $3;
9471 40 : n->concurrent = false;
9472 40 : $$ = (Node *) n;
9473 : }
9474 : ;
9475 :
9476 23 : opt_if_exists: IF_P EXISTS { $$ = true; }
9477 24 : | /*EMPTY*/ { $$ = false; }
9478 : ;
9479 :
9480 :
9481 : /*****************************************************************************
9482 : *
9483 : * CREATE PROPERTY GRAPH
9484 : * ALTER PROPERTY GRAPH
9485 : *
9486 : *****************************************************************************/
9487 :
9488 : CreatePropGraphStmt: CREATE OptTemp PROPERTY GRAPH qualified_name opt_vertex_tables_clause opt_edge_tables_clause
9489 : {
9490 201 : CreatePropGraphStmt *n = makeNode(CreatePropGraphStmt);
9491 :
9492 201 : n->pgname = $5;
9493 201 : n->pgname->relpersistence = $2;
9494 201 : n->vertex_tables = $6;
9495 201 : n->edge_tables = $7;
9496 :
9497 201 : $$ = (Node *)n;
9498 : }
9499 : ;
9500 :
9501 : opt_vertex_tables_clause:
9502 164 : vertex_tables_clause { $$ = $1; }
9503 37 : | /*EMPTY*/ { $$ = NIL; }
9504 : ;
9505 :
9506 : vertex_tables_clause:
9507 196 : vertex_synonym TABLES '(' vertex_table_list ')' { $$ = $4; }
9508 : ;
9509 :
9510 : vertex_synonym: NODE | VERTEX
9511 : ;
9512 :
9513 196 : vertex_table_list: vertex_table_definition { $$ = list_make1($1); }
9514 202 : | vertex_table_list ',' vertex_table_definition { $$ = lappend($1, $3); }
9515 : ;
9516 :
9517 : vertex_table_definition: qualified_name opt_propgraph_table_alias opt_graph_table_key_clause
9518 : opt_element_table_label_and_properties
9519 : {
9520 398 : PropGraphVertex *n = makeNode(PropGraphVertex);
9521 :
9522 398 : $1->alias = $2;
9523 398 : n->vtable = $1;
9524 398 : n->vkey = $3;
9525 398 : n->labels = $4;
9526 398 : n->location = @1;
9527 :
9528 398 : $$ = (Node *) n;
9529 : }
9530 : ;
9531 :
9532 : opt_propgraph_table_alias:
9533 : AS name
9534 : {
9535 12 : $$ = makeNode(Alias);
9536 12 : $$->aliasname = $2;
9537 : }
9538 599 : | /*EMPTY*/ { $$ = NULL; }
9539 : ;
9540 :
9541 : opt_graph_table_key_clause:
9542 479 : KEY '(' columnList ')' { $$ = $3; }
9543 132 : | /*EMPTY*/ { $$ = NIL; }
9544 : ;
9545 :
9546 : opt_edge_tables_clause:
9547 110 : edge_tables_clause { $$ = $1; }
9548 91 : | /*EMPTY*/ { $$ = NIL; }
9549 : ;
9550 :
9551 : edge_tables_clause:
9552 138 : edge_synonym TABLES '(' edge_table_list ')' { $$ = $4; }
9553 : ;
9554 :
9555 : edge_synonym: EDGE | RELATIONSHIP
9556 : ;
9557 :
9558 138 : edge_table_list: edge_table_definition { $$ = list_make1($1); }
9559 75 : | edge_table_list ',' edge_table_definition { $$ = lappend($1, $3); }
9560 : ;
9561 :
9562 : edge_table_definition: qualified_name opt_propgraph_table_alias opt_graph_table_key_clause
9563 : source_vertex_table destination_vertex_table opt_element_table_label_and_properties
9564 : {
9565 213 : PropGraphEdge *n = makeNode(PropGraphEdge);
9566 :
9567 213 : $1->alias = $2;
9568 213 : n->etable = $1;
9569 213 : n->ekey = $3;
9570 213 : n->esrckey = linitial($4);
9571 213 : n->esrcvertex = lsecond($4);
9572 213 : n->esrcvertexcols = lthird($4);
9573 213 : n->edestkey = linitial($5);
9574 213 : n->edestvertex = lsecond($5);
9575 213 : n->edestvertexcols = lthird($5);
9576 213 : n->labels = $6;
9577 213 : n->location = @1;
9578 :
9579 213 : $$ = (Node *) n;
9580 : }
9581 : ;
9582 :
9583 : source_vertex_table: SOURCE name
9584 : {
9585 16 : $$ = list_make3(NULL, $2, NULL);
9586 : }
9587 : | SOURCE KEY '(' columnList ')' REFERENCES name '(' columnList ')'
9588 : {
9589 197 : $$ = list_make3($4, $7, $9);
9590 : }
9591 : ;
9592 :
9593 : destination_vertex_table: DESTINATION name
9594 : {
9595 16 : $$ = list_make3(NULL, $2, NULL);
9596 : }
9597 : | DESTINATION KEY '(' columnList ')' REFERENCES name '(' columnList ')'
9598 : {
9599 197 : $$ = list_make3($4, $7, $9);
9600 : }
9601 : ;
9602 :
9603 : opt_element_table_label_and_properties:
9604 : element_table_properties
9605 : {
9606 77 : PropGraphLabelAndProperties *lp = makeNode(PropGraphLabelAndProperties);
9607 :
9608 77 : lp->properties = (PropGraphProperties *) $1;
9609 77 : lp->location = @1;
9610 :
9611 77 : $$ = list_make1(lp);
9612 : }
9613 : | label_and_properties_list
9614 : {
9615 228 : $$ = $1;
9616 : }
9617 : | /*EMPTY*/
9618 : {
9619 306 : PropGraphLabelAndProperties *lp = makeNode(PropGraphLabelAndProperties);
9620 306 : PropGraphProperties *pr = makeNode(PropGraphProperties);
9621 :
9622 306 : pr->all = true;
9623 306 : pr->location = -1;
9624 306 : lp->properties = pr;
9625 306 : lp->location = -1;
9626 :
9627 306 : $$ = list_make1(lp);
9628 : }
9629 : ;
9630 :
9631 : element_table_properties:
9632 : NO PROPERTIES
9633 : {
9634 5 : PropGraphProperties *pr = makeNode(PropGraphProperties);
9635 :
9636 5 : pr->properties = NIL;
9637 5 : pr->location = @1;
9638 :
9639 5 : $$ = (Node *) pr;
9640 : }
9641 : | PROPERTIES ALL COLUMNS
9642 : /*
9643 : * SQL standard also allows "PROPERTIES ARE ALL COLUMNS", but that
9644 : * would require making ARE a keyword, which seems a bit much for
9645 : * such a marginal use. Could be added later if needed.
9646 : */
9647 : {
9648 16 : PropGraphProperties *pr = makeNode(PropGraphProperties);
9649 :
9650 16 : pr->all = true;
9651 16 : pr->location = @1;
9652 :
9653 16 : $$ = (Node *) pr;
9654 : }
9655 : | PROPERTIES '(' labeled_expr_list ')'
9656 : {
9657 368 : PropGraphProperties *pr = makeNode(PropGraphProperties);
9658 :
9659 368 : pr->properties = $3;
9660 368 : pr->location = @1;
9661 :
9662 368 : $$ = (Node *) pr;
9663 : }
9664 : ;
9665 :
9666 : label_and_properties_list:
9667 : label_and_properties
9668 : {
9669 228 : $$ = list_make1($1);
9670 : }
9671 : | label_and_properties_list label_and_properties
9672 : {
9673 116 : $$ = lappend($1, $2);
9674 : }
9675 : ;
9676 :
9677 : label_and_properties:
9678 : element_table_label_clause
9679 : {
9680 60 : PropGraphLabelAndProperties *lp = makeNode(PropGraphLabelAndProperties);
9681 60 : PropGraphProperties *pr = makeNode(PropGraphProperties);
9682 :
9683 60 : pr->all = true;
9684 60 : pr->location = -1;
9685 :
9686 60 : lp->label = $1;
9687 60 : lp->properties = pr;
9688 60 : lp->location = @1;
9689 :
9690 60 : $$ = (Node *) lp;
9691 : }
9692 : | element_table_label_clause element_table_properties
9693 : {
9694 284 : PropGraphLabelAndProperties *lp = makeNode(PropGraphLabelAndProperties);
9695 :
9696 284 : lp->label = $1;
9697 284 : lp->properties = (PropGraphProperties *) $2;
9698 284 : lp->location = @1;
9699 :
9700 284 : $$ = (Node *) lp;
9701 : }
9702 : ;
9703 :
9704 : element_table_label_clause:
9705 : LABEL name
9706 : {
9707 256 : $$ = $2;
9708 : }
9709 : | DEFAULT LABEL
9710 : {
9711 88 : $$ = NULL;
9712 : }
9713 : ;
9714 :
9715 : AlterPropGraphStmt:
9716 : ALTER PROPERTY GRAPH qualified_name ADD_P vertex_tables_clause
9717 : {
9718 28 : AlterPropGraphStmt *n = makeNode(AlterPropGraphStmt);
9719 :
9720 28 : n->pgname = $4;
9721 28 : n->add_vertex_tables = $6;
9722 :
9723 28 : $$ = (Node *) n;
9724 : }
9725 : | ALTER PROPERTY GRAPH qualified_name ADD_P vertex_tables_clause ADD_P edge_tables_clause
9726 : {
9727 4 : AlterPropGraphStmt *n = makeNode(AlterPropGraphStmt);
9728 :
9729 4 : n->pgname = $4;
9730 4 : n->add_vertex_tables = $6;
9731 4 : n->add_edge_tables = $8;
9732 :
9733 4 : $$ = (Node *) n;
9734 : }
9735 : | ALTER PROPERTY GRAPH qualified_name ADD_P edge_tables_clause
9736 : {
9737 24 : AlterPropGraphStmt *n = makeNode(AlterPropGraphStmt);
9738 :
9739 24 : n->pgname = $4;
9740 24 : n->add_edge_tables = $6;
9741 :
9742 24 : $$ = (Node *) n;
9743 : }
9744 : | ALTER PROPERTY GRAPH qualified_name DROP vertex_synonym TABLES '(' name_list ')' opt_drop_behavior
9745 : {
9746 8 : AlterPropGraphStmt *n = makeNode(AlterPropGraphStmt);
9747 :
9748 8 : n->pgname = $4;
9749 8 : n->drop_vertex_tables = $9;
9750 8 : n->drop_behavior = $11;
9751 :
9752 8 : $$ = (Node *) n;
9753 : }
9754 : | ALTER PROPERTY GRAPH qualified_name DROP edge_synonym TABLES '(' name_list ')' opt_drop_behavior
9755 : {
9756 8 : AlterPropGraphStmt *n = makeNode(AlterPropGraphStmt);
9757 :
9758 8 : n->pgname = $4;
9759 8 : n->drop_edge_tables = $9;
9760 8 : n->drop_behavior = $11;
9761 :
9762 8 : $$ = (Node *) n;
9763 : }
9764 : | ALTER PROPERTY GRAPH qualified_name ALTER vertex_or_edge TABLE name
9765 : add_label_list
9766 : {
9767 24 : AlterPropGraphStmt *n = makeNode(AlterPropGraphStmt);
9768 :
9769 24 : n->pgname = $4;
9770 24 : n->element_kind = $6;
9771 24 : n->element_alias = $8;
9772 24 : n->add_labels = $9;
9773 :
9774 24 : $$ = (Node *) n;
9775 : }
9776 : | ALTER PROPERTY GRAPH qualified_name ALTER vertex_or_edge TABLE name
9777 : DROP LABEL name opt_drop_behavior
9778 : {
9779 12 : AlterPropGraphStmt *n = makeNode(AlterPropGraphStmt);
9780 :
9781 12 : n->pgname = $4;
9782 12 : n->element_kind = $6;
9783 12 : n->element_alias = $8;
9784 12 : n->drop_label = $11;
9785 12 : n->drop_behavior = $12;
9786 :
9787 12 : $$ = (Node *) n;
9788 : }
9789 : | ALTER PROPERTY GRAPH qualified_name ALTER vertex_or_edge TABLE name
9790 : ALTER LABEL name ADD_P PROPERTIES '(' labeled_expr_list ')'
9791 : {
9792 8 : AlterPropGraphStmt *n = makeNode(AlterPropGraphStmt);
9793 8 : PropGraphProperties *pr = makeNode(PropGraphProperties);
9794 :
9795 8 : n->pgname = $4;
9796 8 : n->element_kind = $6;
9797 8 : n->element_alias = $8;
9798 8 : n->alter_label = $11;
9799 :
9800 8 : pr->properties = $15;
9801 8 : pr->location = @13;
9802 8 : n->add_properties = pr;
9803 :
9804 8 : $$ = (Node *) n;
9805 : }
9806 : | ALTER PROPERTY GRAPH qualified_name ALTER vertex_or_edge TABLE name
9807 : ALTER LABEL name DROP PROPERTIES '(' name_list ')' opt_drop_behavior
9808 : {
9809 8 : AlterPropGraphStmt *n = makeNode(AlterPropGraphStmt);
9810 :
9811 8 : n->pgname = $4;
9812 8 : n->element_kind = $6;
9813 8 : n->element_alias = $8;
9814 8 : n->alter_label = $11;
9815 8 : n->drop_properties = $15;
9816 8 : n->drop_behavior = $17;
9817 :
9818 8 : $$ = (Node *) n;
9819 : }
9820 : ;
9821 :
9822 : vertex_or_edge:
9823 44 : vertex_synonym { $$ = PROPGRAPH_ELEMENT_KIND_VERTEX; }
9824 8 : | edge_synonym { $$ = PROPGRAPH_ELEMENT_KIND_EDGE; }
9825 : ;
9826 :
9827 : add_label_list:
9828 24 : add_label { $$ = list_make1($1); }
9829 4 : | add_label_list add_label { $$ = lappend($1, $2); }
9830 : ;
9831 :
9832 : add_label: ADD_P LABEL name element_table_properties
9833 : {
9834 28 : PropGraphLabelAndProperties *lp = makeNode(PropGraphLabelAndProperties);
9835 :
9836 28 : lp->label = $3;
9837 28 : lp->properties = (PropGraphProperties *) $4;
9838 28 : lp->location = @1;
9839 :
9840 28 : $$ = (Node *) lp;
9841 : }
9842 : ;
9843 :
9844 :
9845 : /*****************************************************************************
9846 : *
9847 : * CREATE TRANSFORM / DROP TRANSFORM
9848 : *
9849 : *****************************************************************************/
9850 :
9851 : CreateTransformStmt: CREATE opt_or_replace TRANSFORM FOR Typename LANGUAGE name '(' transform_element_list ')'
9852 : {
9853 26 : CreateTransformStmt *n = makeNode(CreateTransformStmt);
9854 :
9855 26 : n->replace = $2;
9856 26 : n->type_name = $5;
9857 26 : n->lang = $7;
9858 26 : n->fromsql = linitial($9);
9859 26 : n->tosql = lsecond($9);
9860 26 : $$ = (Node *) n;
9861 : }
9862 : ;
9863 :
9864 : transform_element_list: FROM SQL_P WITH FUNCTION function_with_argtypes ',' TO SQL_P WITH FUNCTION function_with_argtypes
9865 : {
9866 23 : $$ = list_make2($5, $11);
9867 : }
9868 : | TO SQL_P WITH FUNCTION function_with_argtypes ',' FROM SQL_P WITH FUNCTION function_with_argtypes
9869 : {
9870 0 : $$ = list_make2($11, $5);
9871 : }
9872 : | FROM SQL_P WITH FUNCTION function_with_argtypes
9873 : {
9874 2 : $$ = list_make2($5, NULL);
9875 : }
9876 : | TO SQL_P WITH FUNCTION function_with_argtypes
9877 : {
9878 1 : $$ = list_make2(NULL, $5);
9879 : }
9880 : ;
9881 :
9882 :
9883 : DropTransformStmt: DROP TRANSFORM opt_if_exists FOR Typename LANGUAGE name opt_drop_behavior
9884 : {
9885 7 : DropStmt *n = makeNode(DropStmt);
9886 :
9887 7 : n->removeType = OBJECT_TRANSFORM;
9888 7 : n->objects = list_make1(list_make2($5, makeString($7)));
9889 7 : n->behavior = $8;
9890 7 : n->missing_ok = $3;
9891 7 : $$ = (Node *) n;
9892 : }
9893 : ;
9894 :
9895 :
9896 : /*****************************************************************************
9897 : *
9898 : * QUERY:
9899 : *
9900 : * REINDEX [ (options) ] {INDEX | TABLE | SCHEMA} [CONCURRENTLY] <name>
9901 : * REINDEX [ (options) ] {DATABASE | SYSTEM} [CONCURRENTLY] [<name>]
9902 : *****************************************************************************/
9903 :
9904 : ReindexStmt:
9905 : REINDEX opt_utility_option_list reindex_target_relation opt_concurrently qualified_name
9906 : {
9907 583 : ReindexStmt *n = makeNode(ReindexStmt);
9908 :
9909 583 : n->kind = $3;
9910 583 : n->relation = $5;
9911 583 : n->name = NULL;
9912 583 : n->params = $2;
9913 583 : if ($4)
9914 327 : n->params = lappend(n->params,
9915 327 : makeDefElem("concurrently", NULL, @4));
9916 583 : $$ = (Node *) n;
9917 : }
9918 : | REINDEX opt_utility_option_list SCHEMA opt_concurrently name
9919 : {
9920 74 : ReindexStmt *n = makeNode(ReindexStmt);
9921 :
9922 74 : n->kind = REINDEX_OBJECT_SCHEMA;
9923 74 : n->relation = NULL;
9924 74 : n->name = $5;
9925 74 : n->params = $2;
9926 74 : if ($4)
9927 26 : n->params = lappend(n->params,
9928 26 : makeDefElem("concurrently", NULL, @4));
9929 74 : $$ = (Node *) n;
9930 : }
9931 : | REINDEX opt_utility_option_list reindex_target_all opt_concurrently opt_single_name
9932 : {
9933 37 : ReindexStmt *n = makeNode(ReindexStmt);
9934 :
9935 37 : n->kind = $3;
9936 37 : n->relation = NULL;
9937 37 : n->name = $5;
9938 37 : n->params = $2;
9939 37 : if ($4)
9940 6 : n->params = lappend(n->params,
9941 6 : makeDefElem("concurrently", NULL, @4));
9942 37 : $$ = (Node *) n;
9943 : }
9944 : ;
9945 : reindex_target_relation:
9946 258 : INDEX { $$ = REINDEX_OBJECT_INDEX; }
9947 325 : | TABLE { $$ = REINDEX_OBJECT_TABLE; }
9948 : ;
9949 : reindex_target_all:
9950 20 : SYSTEM_P { $$ = REINDEX_OBJECT_SYSTEM; }
9951 17 : | DATABASE { $$ = REINDEX_OBJECT_DATABASE; }
9952 : ;
9953 :
9954 : /*****************************************************************************
9955 : *
9956 : * ALTER TABLESPACE
9957 : *
9958 : *****************************************************************************/
9959 :
9960 : AlterTblSpcStmt:
9961 : ALTER TABLESPACE name SET reloptions
9962 : {
9963 : AlterTableSpaceOptionsStmt *n =
9964 8 : makeNode(AlterTableSpaceOptionsStmt);
9965 :
9966 8 : n->tablespacename = $3;
9967 8 : n->options = $5;
9968 8 : n->isReset = false;
9969 8 : $$ = (Node *) n;
9970 : }
9971 : | ALTER TABLESPACE name RESET reloptions
9972 : {
9973 : AlterTableSpaceOptionsStmt *n =
9974 8 : makeNode(AlterTableSpaceOptionsStmt);
9975 :
9976 8 : n->tablespacename = $3;
9977 8 : n->options = $5;
9978 8 : n->isReset = true;
9979 8 : $$ = (Node *) n;
9980 : }
9981 : ;
9982 :
9983 : /*****************************************************************************
9984 : *
9985 : * ALTER THING name RENAME TO newname
9986 : *
9987 : *****************************************************************************/
9988 :
9989 : RenameStmt: ALTER AGGREGATE aggregate_with_argtypes RENAME TO name
9990 : {
9991 28 : RenameStmt *n = makeNode(RenameStmt);
9992 :
9993 28 : n->renameType = OBJECT_AGGREGATE;
9994 28 : n->object = (Node *) $3;
9995 28 : n->newname = $6;
9996 28 : n->missing_ok = false;
9997 28 : $$ = (Node *) n;
9998 : }
9999 : | ALTER COLLATION any_name RENAME TO name
10000 : {
10001 12 : RenameStmt *n = makeNode(RenameStmt);
10002 :
10003 12 : n->renameType = OBJECT_COLLATION;
10004 12 : n->object = (Node *) $3;
10005 12 : n->newname = $6;
10006 12 : n->missing_ok = false;
10007 12 : $$ = (Node *) n;
10008 : }
10009 : | ALTER CONVERSION_P any_name RENAME TO name
10010 : {
10011 16 : RenameStmt *n = makeNode(RenameStmt);
10012 :
10013 16 : n->renameType = OBJECT_CONVERSION;
10014 16 : n->object = (Node *) $3;
10015 16 : n->newname = $6;
10016 16 : n->missing_ok = false;
10017 16 : $$ = (Node *) n;
10018 : }
10019 : | ALTER DATABASE name RENAME TO name
10020 : {
10021 9 : RenameStmt *n = makeNode(RenameStmt);
10022 :
10023 9 : n->renameType = OBJECT_DATABASE;
10024 9 : n->subname = $3;
10025 9 : n->newname = $6;
10026 9 : n->missing_ok = false;
10027 9 : $$ = (Node *) n;
10028 : }
10029 : | ALTER DOMAIN_P any_name RENAME TO name
10030 : {
10031 4 : RenameStmt *n = makeNode(RenameStmt);
10032 :
10033 4 : n->renameType = OBJECT_DOMAIN;
10034 4 : n->object = (Node *) $3;
10035 4 : n->newname = $6;
10036 4 : n->missing_ok = false;
10037 4 : $$ = (Node *) n;
10038 : }
10039 : | ALTER DOMAIN_P any_name RENAME CONSTRAINT name TO name
10040 : {
10041 4 : RenameStmt *n = makeNode(RenameStmt);
10042 :
10043 4 : n->renameType = OBJECT_DOMCONSTRAINT;
10044 4 : n->object = (Node *) $3;
10045 4 : n->subname = $6;
10046 4 : n->newname = $8;
10047 4 : $$ = (Node *) n;
10048 : }
10049 : | ALTER FOREIGN DATA_P WRAPPER name RENAME TO name
10050 : {
10051 16 : RenameStmt *n = makeNode(RenameStmt);
10052 :
10053 16 : n->renameType = OBJECT_FDW;
10054 16 : n->object = (Node *) makeString($5);
10055 16 : n->newname = $8;
10056 16 : n->missing_ok = false;
10057 16 : $$ = (Node *) n;
10058 : }
10059 : | ALTER FUNCTION function_with_argtypes RENAME TO name
10060 : {
10061 16 : RenameStmt *n = makeNode(RenameStmt);
10062 :
10063 16 : n->renameType = OBJECT_FUNCTION;
10064 16 : n->object = (Node *) $3;
10065 16 : n->newname = $6;
10066 16 : n->missing_ok = false;
10067 16 : $$ = (Node *) n;
10068 : }
10069 : | ALTER GROUP_P RoleId RENAME TO RoleId
10070 : {
10071 0 : RenameStmt *n = makeNode(RenameStmt);
10072 :
10073 0 : n->renameType = OBJECT_ROLE;
10074 0 : n->subname = $3;
10075 0 : n->newname = $6;
10076 0 : n->missing_ok = false;
10077 0 : $$ = (Node *) n;
10078 : }
10079 : | ALTER opt_procedural LANGUAGE name RENAME TO name
10080 : {
10081 12 : RenameStmt *n = makeNode(RenameStmt);
10082 :
10083 12 : n->renameType = OBJECT_LANGUAGE;
10084 12 : n->object = (Node *) makeString($4);
10085 12 : n->newname = $7;
10086 12 : n->missing_ok = false;
10087 12 : $$ = (Node *) n;
10088 : }
10089 : | ALTER OPERATOR CLASS any_name USING name RENAME TO name
10090 : {
10091 16 : RenameStmt *n = makeNode(RenameStmt);
10092 :
10093 16 : n->renameType = OBJECT_OPCLASS;
10094 16 : n->object = (Node *) lcons(makeString($6), $4);
10095 16 : n->newname = $9;
10096 16 : n->missing_ok = false;
10097 16 : $$ = (Node *) n;
10098 : }
10099 : | ALTER OPERATOR FAMILY any_name USING name RENAME TO name
10100 : {
10101 16 : RenameStmt *n = makeNode(RenameStmt);
10102 :
10103 16 : n->renameType = OBJECT_OPFAMILY;
10104 16 : n->object = (Node *) lcons(makeString($6), $4);
10105 16 : n->newname = $9;
10106 16 : n->missing_ok = false;
10107 16 : $$ = (Node *) n;
10108 : }
10109 : | ALTER POLICY name ON qualified_name RENAME TO name
10110 : {
10111 12 : RenameStmt *n = makeNode(RenameStmt);
10112 :
10113 12 : n->renameType = OBJECT_POLICY;
10114 12 : n->relation = $5;
10115 12 : n->subname = $3;
10116 12 : n->newname = $8;
10117 12 : n->missing_ok = false;
10118 12 : $$ = (Node *) n;
10119 : }
10120 : | ALTER POLICY IF_P EXISTS name ON qualified_name RENAME TO name
10121 : {
10122 0 : RenameStmt *n = makeNode(RenameStmt);
10123 :
10124 0 : n->renameType = OBJECT_POLICY;
10125 0 : n->relation = $7;
10126 0 : n->subname = $5;
10127 0 : n->newname = $10;
10128 0 : n->missing_ok = true;
10129 0 : $$ = (Node *) n;
10130 : }
10131 : | ALTER PROCEDURE function_with_argtypes RENAME TO name
10132 : {
10133 0 : RenameStmt *n = makeNode(RenameStmt);
10134 :
10135 0 : n->renameType = OBJECT_PROCEDURE;
10136 0 : n->object = (Node *) $3;
10137 0 : n->newname = $6;
10138 0 : n->missing_ok = false;
10139 0 : $$ = (Node *) n;
10140 : }
10141 : | ALTER PROPERTY GRAPH qualified_name RENAME TO name
10142 : {
10143 24 : RenameStmt *n = makeNode(RenameStmt);
10144 :
10145 24 : n->renameType = OBJECT_PROPGRAPH;
10146 24 : n->relation = $4;
10147 24 : n->newname = $7;
10148 24 : n->missing_ok = false;
10149 24 : $$ = (Node *)n;
10150 : }
10151 : | ALTER PUBLICATION name RENAME TO name
10152 : {
10153 24 : RenameStmt *n = makeNode(RenameStmt);
10154 :
10155 24 : n->renameType = OBJECT_PUBLICATION;
10156 24 : n->object = (Node *) makeString($3);
10157 24 : n->newname = $6;
10158 24 : n->missing_ok = false;
10159 24 : $$ = (Node *) n;
10160 : }
10161 : | ALTER ROUTINE function_with_argtypes RENAME TO name
10162 : {
10163 16 : RenameStmt *n = makeNode(RenameStmt);
10164 :
10165 16 : n->renameType = OBJECT_ROUTINE;
10166 16 : n->object = (Node *) $3;
10167 16 : n->newname = $6;
10168 16 : n->missing_ok = false;
10169 16 : $$ = (Node *) n;
10170 : }
10171 : | ALTER SCHEMA name RENAME TO name
10172 : {
10173 13 : RenameStmt *n = makeNode(RenameStmt);
10174 :
10175 13 : n->renameType = OBJECT_SCHEMA;
10176 13 : n->subname = $3;
10177 13 : n->newname = $6;
10178 13 : n->missing_ok = false;
10179 13 : $$ = (Node *) n;
10180 : }
10181 : | ALTER SERVER name RENAME TO name
10182 : {
10183 16 : RenameStmt *n = makeNode(RenameStmt);
10184 :
10185 16 : n->renameType = OBJECT_FOREIGN_SERVER;
10186 16 : n->object = (Node *) makeString($3);
10187 16 : n->newname = $6;
10188 16 : n->missing_ok = false;
10189 16 : $$ = (Node *) n;
10190 : }
10191 : | ALTER SUBSCRIPTION name RENAME TO name
10192 : {
10193 25 : RenameStmt *n = makeNode(RenameStmt);
10194 :
10195 25 : n->renameType = OBJECT_SUBSCRIPTION;
10196 25 : n->object = (Node *) makeString($3);
10197 25 : n->newname = $6;
10198 25 : n->missing_ok = false;
10199 25 : $$ = (Node *) n;
10200 : }
10201 : | ALTER TABLE relation_expr RENAME TO name
10202 : {
10203 174 : RenameStmt *n = makeNode(RenameStmt);
10204 :
10205 174 : n->renameType = OBJECT_TABLE;
10206 174 : n->relation = $3;
10207 174 : n->subname = NULL;
10208 174 : n->newname = $6;
10209 174 : n->missing_ok = false;
10210 174 : $$ = (Node *) n;
10211 : }
10212 : | ALTER TABLE IF_P EXISTS relation_expr RENAME TO name
10213 : {
10214 0 : RenameStmt *n = makeNode(RenameStmt);
10215 :
10216 0 : n->renameType = OBJECT_TABLE;
10217 0 : n->relation = $5;
10218 0 : n->subname = NULL;
10219 0 : n->newname = $8;
10220 0 : n->missing_ok = true;
10221 0 : $$ = (Node *) n;
10222 : }
10223 : | ALTER SEQUENCE qualified_name RENAME TO name
10224 : {
10225 1 : RenameStmt *n = makeNode(RenameStmt);
10226 :
10227 1 : n->renameType = OBJECT_SEQUENCE;
10228 1 : n->relation = $3;
10229 1 : n->subname = NULL;
10230 1 : n->newname = $6;
10231 1 : n->missing_ok = false;
10232 1 : $$ = (Node *) n;
10233 : }
10234 : | ALTER SEQUENCE IF_P EXISTS qualified_name RENAME TO name
10235 : {
10236 0 : RenameStmt *n = makeNode(RenameStmt);
10237 :
10238 0 : n->renameType = OBJECT_SEQUENCE;
10239 0 : n->relation = $5;
10240 0 : n->subname = NULL;
10241 0 : n->newname = $8;
10242 0 : n->missing_ok = true;
10243 0 : $$ = (Node *) n;
10244 : }
10245 : | ALTER VIEW qualified_name RENAME TO name
10246 : {
10247 4 : RenameStmt *n = makeNode(RenameStmt);
10248 :
10249 4 : n->renameType = OBJECT_VIEW;
10250 4 : n->relation = $3;
10251 4 : n->subname = NULL;
10252 4 : n->newname = $6;
10253 4 : n->missing_ok = false;
10254 4 : $$ = (Node *) n;
10255 : }
10256 : | ALTER VIEW IF_P EXISTS qualified_name RENAME TO name
10257 : {
10258 0 : RenameStmt *n = makeNode(RenameStmt);
10259 :
10260 0 : n->renameType = OBJECT_VIEW;
10261 0 : n->relation = $5;
10262 0 : n->subname = NULL;
10263 0 : n->newname = $8;
10264 0 : n->missing_ok = true;
10265 0 : $$ = (Node *) n;
10266 : }
10267 : | ALTER MATERIALIZED VIEW qualified_name RENAME TO name
10268 : {
10269 0 : RenameStmt *n = makeNode(RenameStmt);
10270 :
10271 0 : n->renameType = OBJECT_MATVIEW;
10272 0 : n->relation = $4;
10273 0 : n->subname = NULL;
10274 0 : n->newname = $7;
10275 0 : n->missing_ok = false;
10276 0 : $$ = (Node *) n;
10277 : }
10278 : | ALTER MATERIALIZED VIEW IF_P EXISTS qualified_name RENAME TO name
10279 : {
10280 0 : RenameStmt *n = makeNode(RenameStmt);
10281 :
10282 0 : n->renameType = OBJECT_MATVIEW;
10283 0 : n->relation = $6;
10284 0 : n->subname = NULL;
10285 0 : n->newname = $9;
10286 0 : n->missing_ok = true;
10287 0 : $$ = (Node *) n;
10288 : }
10289 : | ALTER INDEX qualified_name RENAME TO name
10290 : {
10291 108 : RenameStmt *n = makeNode(RenameStmt);
10292 :
10293 108 : n->renameType = OBJECT_INDEX;
10294 108 : n->relation = $3;
10295 108 : n->subname = NULL;
10296 108 : n->newname = $6;
10297 108 : n->missing_ok = false;
10298 108 : $$ = (Node *) n;
10299 : }
10300 : | ALTER INDEX IF_P EXISTS qualified_name RENAME TO name
10301 : {
10302 8 : RenameStmt *n = makeNode(RenameStmt);
10303 :
10304 8 : n->renameType = OBJECT_INDEX;
10305 8 : n->relation = $5;
10306 8 : n->subname = NULL;
10307 8 : n->newname = $8;
10308 8 : n->missing_ok = true;
10309 8 : $$ = (Node *) n;
10310 : }
10311 : | ALTER FOREIGN TABLE relation_expr RENAME TO name
10312 : {
10313 4 : RenameStmt *n = makeNode(RenameStmt);
10314 :
10315 4 : n->renameType = OBJECT_FOREIGN_TABLE;
10316 4 : n->relation = $4;
10317 4 : n->subname = NULL;
10318 4 : n->newname = $7;
10319 4 : n->missing_ok = false;
10320 4 : $$ = (Node *) n;
10321 : }
10322 : | ALTER FOREIGN TABLE IF_P EXISTS relation_expr RENAME TO name
10323 : {
10324 4 : RenameStmt *n = makeNode(RenameStmt);
10325 :
10326 4 : n->renameType = OBJECT_FOREIGN_TABLE;
10327 4 : n->relation = $6;
10328 4 : n->subname = NULL;
10329 4 : n->newname = $9;
10330 4 : n->missing_ok = true;
10331 4 : $$ = (Node *) n;
10332 : }
10333 : | ALTER TABLE relation_expr RENAME opt_column name TO name
10334 : {
10335 157 : RenameStmt *n = makeNode(RenameStmt);
10336 :
10337 157 : n->renameType = OBJECT_COLUMN;
10338 157 : n->relationType = OBJECT_TABLE;
10339 157 : n->relation = $3;
10340 157 : n->subname = $6;
10341 157 : n->newname = $8;
10342 157 : n->missing_ok = false;
10343 157 : $$ = (Node *) n;
10344 : }
10345 : | ALTER TABLE IF_P EXISTS relation_expr RENAME opt_column name TO name
10346 : {
10347 16 : RenameStmt *n = makeNode(RenameStmt);
10348 :
10349 16 : n->renameType = OBJECT_COLUMN;
10350 16 : n->relationType = OBJECT_TABLE;
10351 16 : n->relation = $5;
10352 16 : n->subname = $8;
10353 16 : n->newname = $10;
10354 16 : n->missing_ok = true;
10355 16 : $$ = (Node *) n;
10356 : }
10357 : | ALTER VIEW qualified_name RENAME opt_column name TO name
10358 : {
10359 12 : RenameStmt *n = makeNode(RenameStmt);
10360 :
10361 12 : n->renameType = OBJECT_COLUMN;
10362 12 : n->relationType = OBJECT_VIEW;
10363 12 : n->relation = $3;
10364 12 : n->subname = $6;
10365 12 : n->newname = $8;
10366 12 : n->missing_ok = false;
10367 12 : $$ = (Node *) n;
10368 : }
10369 : | ALTER VIEW IF_P EXISTS qualified_name RENAME opt_column name TO name
10370 : {
10371 0 : RenameStmt *n = makeNode(RenameStmt);
10372 :
10373 0 : n->renameType = OBJECT_COLUMN;
10374 0 : n->relationType = OBJECT_VIEW;
10375 0 : n->relation = $5;
10376 0 : n->subname = $8;
10377 0 : n->newname = $10;
10378 0 : n->missing_ok = true;
10379 0 : $$ = (Node *) n;
10380 : }
10381 : | ALTER MATERIALIZED VIEW qualified_name RENAME opt_column name TO name
10382 : {
10383 0 : RenameStmt *n = makeNode(RenameStmt);
10384 :
10385 0 : n->renameType = OBJECT_COLUMN;
10386 0 : n->relationType = OBJECT_MATVIEW;
10387 0 : n->relation = $4;
10388 0 : n->subname = $7;
10389 0 : n->newname = $9;
10390 0 : n->missing_ok = false;
10391 0 : $$ = (Node *) n;
10392 : }
10393 : | ALTER MATERIALIZED VIEW IF_P EXISTS qualified_name RENAME opt_column name TO name
10394 : {
10395 0 : RenameStmt *n = makeNode(RenameStmt);
10396 :
10397 0 : n->renameType = OBJECT_COLUMN;
10398 0 : n->relationType = OBJECT_MATVIEW;
10399 0 : n->relation = $6;
10400 0 : n->subname = $9;
10401 0 : n->newname = $11;
10402 0 : n->missing_ok = true;
10403 0 : $$ = (Node *) n;
10404 : }
10405 : | ALTER TABLE relation_expr RENAME CONSTRAINT name TO name
10406 : {
10407 48 : RenameStmt *n = makeNode(RenameStmt);
10408 :
10409 48 : n->renameType = OBJECT_TABCONSTRAINT;
10410 48 : n->relation = $3;
10411 48 : n->subname = $6;
10412 48 : n->newname = $8;
10413 48 : n->missing_ok = false;
10414 48 : $$ = (Node *) n;
10415 : }
10416 : | ALTER TABLE IF_P EXISTS relation_expr RENAME CONSTRAINT name TO name
10417 : {
10418 4 : RenameStmt *n = makeNode(RenameStmt);
10419 :
10420 4 : n->renameType = OBJECT_TABCONSTRAINT;
10421 4 : n->relation = $5;
10422 4 : n->subname = $8;
10423 4 : n->newname = $10;
10424 4 : n->missing_ok = true;
10425 4 : $$ = (Node *) n;
10426 : }
10427 : | ALTER FOREIGN TABLE relation_expr RENAME opt_column name TO name
10428 : {
10429 4 : RenameStmt *n = makeNode(RenameStmt);
10430 :
10431 4 : n->renameType = OBJECT_COLUMN;
10432 4 : n->relationType = OBJECT_FOREIGN_TABLE;
10433 4 : n->relation = $4;
10434 4 : n->subname = $7;
10435 4 : n->newname = $9;
10436 4 : n->missing_ok = false;
10437 4 : $$ = (Node *) n;
10438 : }
10439 : | ALTER FOREIGN TABLE IF_P EXISTS relation_expr RENAME opt_column name TO name
10440 : {
10441 4 : RenameStmt *n = makeNode(RenameStmt);
10442 :
10443 4 : n->renameType = OBJECT_COLUMN;
10444 4 : n->relationType = OBJECT_FOREIGN_TABLE;
10445 4 : n->relation = $6;
10446 4 : n->subname = $9;
10447 4 : n->newname = $11;
10448 4 : n->missing_ok = true;
10449 4 : $$ = (Node *) n;
10450 : }
10451 : | ALTER RULE name ON qualified_name RENAME TO name
10452 : {
10453 22 : RenameStmt *n = makeNode(RenameStmt);
10454 :
10455 22 : n->renameType = OBJECT_RULE;
10456 22 : n->relation = $5;
10457 22 : n->subname = $3;
10458 22 : n->newname = $8;
10459 22 : n->missing_ok = false;
10460 22 : $$ = (Node *) n;
10461 : }
10462 : | ALTER TRIGGER name ON qualified_name RENAME TO name
10463 : {
10464 26 : RenameStmt *n = makeNode(RenameStmt);
10465 :
10466 26 : n->renameType = OBJECT_TRIGGER;
10467 26 : n->relation = $5;
10468 26 : n->subname = $3;
10469 26 : n->newname = $8;
10470 26 : n->missing_ok = false;
10471 26 : $$ = (Node *) n;
10472 : }
10473 : | ALTER EVENT TRIGGER name RENAME TO name
10474 : {
10475 8 : RenameStmt *n = makeNode(RenameStmt);
10476 :
10477 8 : n->renameType = OBJECT_EVENT_TRIGGER;
10478 8 : n->object = (Node *) makeString($4);
10479 8 : n->newname = $7;
10480 8 : $$ = (Node *) n;
10481 : }
10482 : | ALTER ROLE RoleId RENAME TO RoleId
10483 : {
10484 20 : RenameStmt *n = makeNode(RenameStmt);
10485 :
10486 20 : n->renameType = OBJECT_ROLE;
10487 20 : n->subname = $3;
10488 20 : n->newname = $6;
10489 20 : n->missing_ok = false;
10490 20 : $$ = (Node *) n;
10491 : }
10492 : | ALTER USER RoleId RENAME TO RoleId
10493 : {
10494 0 : RenameStmt *n = makeNode(RenameStmt);
10495 :
10496 0 : n->renameType = OBJECT_ROLE;
10497 0 : n->subname = $3;
10498 0 : n->newname = $6;
10499 0 : n->missing_ok = false;
10500 0 : $$ = (Node *) n;
10501 : }
10502 : | ALTER TABLESPACE name RENAME TO name
10503 : {
10504 6 : RenameStmt *n = makeNode(RenameStmt);
10505 :
10506 6 : n->renameType = OBJECT_TABLESPACE;
10507 6 : n->subname = $3;
10508 6 : n->newname = $6;
10509 6 : n->missing_ok = false;
10510 6 : $$ = (Node *) n;
10511 : }
10512 : | ALTER STATISTICS any_name RENAME TO name
10513 : {
10514 20 : RenameStmt *n = makeNode(RenameStmt);
10515 :
10516 20 : n->renameType = OBJECT_STATISTIC_EXT;
10517 20 : n->object = (Node *) $3;
10518 20 : n->newname = $6;
10519 20 : n->missing_ok = false;
10520 20 : $$ = (Node *) n;
10521 : }
10522 : | ALTER TEXT_P SEARCH PARSER any_name RENAME TO name
10523 : {
10524 8 : RenameStmt *n = makeNode(RenameStmt);
10525 :
10526 8 : n->renameType = OBJECT_TSPARSER;
10527 8 : n->object = (Node *) $5;
10528 8 : n->newname = $8;
10529 8 : n->missing_ok = false;
10530 8 : $$ = (Node *) n;
10531 : }
10532 : | ALTER TEXT_P SEARCH DICTIONARY any_name RENAME TO name
10533 : {
10534 16 : RenameStmt *n = makeNode(RenameStmt);
10535 :
10536 16 : n->renameType = OBJECT_TSDICTIONARY;
10537 16 : n->object = (Node *) $5;
10538 16 : n->newname = $8;
10539 16 : n->missing_ok = false;
10540 16 : $$ = (Node *) n;
10541 : }
10542 : | ALTER TEXT_P SEARCH TEMPLATE any_name RENAME TO name
10543 : {
10544 8 : RenameStmt *n = makeNode(RenameStmt);
10545 :
10546 8 : n->renameType = OBJECT_TSTEMPLATE;
10547 8 : n->object = (Node *) $5;
10548 8 : n->newname = $8;
10549 8 : n->missing_ok = false;
10550 8 : $$ = (Node *) n;
10551 : }
10552 : | ALTER TEXT_P SEARCH CONFIGURATION any_name RENAME TO name
10553 : {
10554 16 : RenameStmt *n = makeNode(RenameStmt);
10555 :
10556 16 : n->renameType = OBJECT_TSCONFIGURATION;
10557 16 : n->object = (Node *) $5;
10558 16 : n->newname = $8;
10559 16 : n->missing_ok = false;
10560 16 : $$ = (Node *) n;
10561 : }
10562 : | ALTER TYPE_P any_name RENAME TO name
10563 : {
10564 17 : RenameStmt *n = makeNode(RenameStmt);
10565 :
10566 17 : n->renameType = OBJECT_TYPE;
10567 17 : n->object = (Node *) $3;
10568 17 : n->newname = $6;
10569 17 : n->missing_ok = false;
10570 17 : $$ = (Node *) n;
10571 : }
10572 : | ALTER TYPE_P any_name RENAME ATTRIBUTE name TO name opt_drop_behavior
10573 : {
10574 16 : RenameStmt *n = makeNode(RenameStmt);
10575 :
10576 16 : n->renameType = OBJECT_ATTRIBUTE;
10577 16 : n->relationType = OBJECT_TYPE;
10578 16 : n->relation = makeRangeVarFromAnyName($3, @3, yyscanner);
10579 16 : n->subname = $6;
10580 16 : n->newname = $8;
10581 16 : n->behavior = $9;
10582 16 : n->missing_ok = false;
10583 16 : $$ = (Node *) n;
10584 : }
10585 : ;
10586 :
10587 : opt_column: COLUMN
10588 : | /*EMPTY*/
10589 : ;
10590 :
10591 122 : opt_set_data: SET DATA_P { $$ = 1; }
10592 684 : | /*EMPTY*/ { $$ = 0; }
10593 : ;
10594 :
10595 : /*****************************************************************************
10596 : *
10597 : * ALTER THING name DEPENDS ON EXTENSION name
10598 : *
10599 : *****************************************************************************/
10600 :
10601 : AlterObjectDependsStmt:
10602 : ALTER FUNCTION function_with_argtypes opt_no DEPENDS ON EXTENSION name
10603 : {
10604 6 : AlterObjectDependsStmt *n = makeNode(AlterObjectDependsStmt);
10605 :
10606 6 : n->objectType = OBJECT_FUNCTION;
10607 6 : n->object = (Node *) $3;
10608 6 : n->extname = makeString($8);
10609 6 : n->remove = $4;
10610 6 : $$ = (Node *) n;
10611 : }
10612 : | ALTER PROCEDURE function_with_argtypes opt_no DEPENDS ON EXTENSION name
10613 : {
10614 0 : AlterObjectDependsStmt *n = makeNode(AlterObjectDependsStmt);
10615 :
10616 0 : n->objectType = OBJECT_PROCEDURE;
10617 0 : n->object = (Node *) $3;
10618 0 : n->extname = makeString($8);
10619 0 : n->remove = $4;
10620 0 : $$ = (Node *) n;
10621 : }
10622 : | ALTER ROUTINE function_with_argtypes opt_no DEPENDS ON EXTENSION name
10623 : {
10624 0 : AlterObjectDependsStmt *n = makeNode(AlterObjectDependsStmt);
10625 :
10626 0 : n->objectType = OBJECT_ROUTINE;
10627 0 : n->object = (Node *) $3;
10628 0 : n->extname = makeString($8);
10629 0 : n->remove = $4;
10630 0 : $$ = (Node *) n;
10631 : }
10632 : | ALTER TRIGGER name ON qualified_name opt_no DEPENDS ON EXTENSION name
10633 : {
10634 5 : AlterObjectDependsStmt *n = makeNode(AlterObjectDependsStmt);
10635 :
10636 5 : n->objectType = OBJECT_TRIGGER;
10637 5 : n->relation = $5;
10638 5 : n->object = (Node *) list_make1(makeString($3));
10639 5 : n->extname = makeString($10);
10640 5 : n->remove = $6;
10641 5 : $$ = (Node *) n;
10642 : }
10643 : | ALTER MATERIALIZED VIEW qualified_name opt_no DEPENDS ON EXTENSION name
10644 : {
10645 5 : AlterObjectDependsStmt *n = makeNode(AlterObjectDependsStmt);
10646 :
10647 5 : n->objectType = OBJECT_MATVIEW;
10648 5 : n->relation = $4;
10649 5 : n->extname = makeString($9);
10650 5 : n->remove = $5;
10651 5 : $$ = (Node *) n;
10652 : }
10653 : | ALTER INDEX qualified_name opt_no DEPENDS ON EXTENSION name
10654 : {
10655 7 : AlterObjectDependsStmt *n = makeNode(AlterObjectDependsStmt);
10656 :
10657 7 : n->objectType = OBJECT_INDEX;
10658 7 : n->relation = $3;
10659 7 : n->extname = makeString($8);
10660 7 : n->remove = $4;
10661 7 : $$ = (Node *) n;
10662 : }
10663 : ;
10664 :
10665 4 : opt_no: NO { $$ = true; }
10666 19 : | /* EMPTY */ { $$ = false; }
10667 : ;
10668 :
10669 : /*****************************************************************************
10670 : *
10671 : * ALTER THING name SET SCHEMA name
10672 : *
10673 : *****************************************************************************/
10674 :
10675 : AlterObjectSchemaStmt:
10676 : ALTER AGGREGATE aggregate_with_argtypes SET SCHEMA name
10677 : {
10678 16 : AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
10679 :
10680 16 : n->objectType = OBJECT_AGGREGATE;
10681 16 : n->object = (Node *) $3;
10682 16 : n->newschema = $6;
10683 16 : n->missing_ok = false;
10684 16 : $$ = (Node *) n;
10685 : }
10686 : | ALTER COLLATION any_name SET SCHEMA name
10687 : {
10688 4 : AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
10689 :
10690 4 : n->objectType = OBJECT_COLLATION;
10691 4 : n->object = (Node *) $3;
10692 4 : n->newschema = $6;
10693 4 : n->missing_ok = false;
10694 4 : $$ = (Node *) n;
10695 : }
10696 : | ALTER CONVERSION_P any_name SET SCHEMA name
10697 : {
10698 16 : AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
10699 :
10700 16 : n->objectType = OBJECT_CONVERSION;
10701 16 : n->object = (Node *) $3;
10702 16 : n->newschema = $6;
10703 16 : n->missing_ok = false;
10704 16 : $$ = (Node *) n;
10705 : }
10706 : | ALTER DOMAIN_P any_name SET SCHEMA name
10707 : {
10708 4 : AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
10709 :
10710 4 : n->objectType = OBJECT_DOMAIN;
10711 4 : n->object = (Node *) $3;
10712 4 : n->newschema = $6;
10713 4 : n->missing_ok = false;
10714 4 : $$ = (Node *) n;
10715 : }
10716 : | ALTER EXTENSION name SET SCHEMA name
10717 : {
10718 6 : AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
10719 :
10720 6 : n->objectType = OBJECT_EXTENSION;
10721 6 : n->object = (Node *) makeString($3);
10722 6 : n->newschema = $6;
10723 6 : n->missing_ok = false;
10724 6 : $$ = (Node *) n;
10725 : }
10726 : | ALTER FUNCTION function_with_argtypes SET SCHEMA name
10727 : {
10728 27 : AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
10729 :
10730 27 : n->objectType = OBJECT_FUNCTION;
10731 27 : n->object = (Node *) $3;
10732 27 : n->newschema = $6;
10733 27 : n->missing_ok = false;
10734 27 : $$ = (Node *) n;
10735 : }
10736 : | ALTER OPERATOR operator_with_argtypes SET SCHEMA name
10737 : {
10738 12 : AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
10739 :
10740 12 : n->objectType = OBJECT_OPERATOR;
10741 12 : n->object = (Node *) $3;
10742 12 : n->newschema = $6;
10743 12 : n->missing_ok = false;
10744 12 : $$ = (Node *) n;
10745 : }
10746 : | ALTER OPERATOR CLASS any_name USING name SET SCHEMA name
10747 : {
10748 16 : AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
10749 :
10750 16 : n->objectType = OBJECT_OPCLASS;
10751 16 : n->object = (Node *) lcons(makeString($6), $4);
10752 16 : n->newschema = $9;
10753 16 : n->missing_ok = false;
10754 16 : $$ = (Node *) n;
10755 : }
10756 : | ALTER OPERATOR FAMILY any_name USING name SET SCHEMA name
10757 : {
10758 16 : AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
10759 :
10760 16 : n->objectType = OBJECT_OPFAMILY;
10761 16 : n->object = (Node *) lcons(makeString($6), $4);
10762 16 : n->newschema = $9;
10763 16 : n->missing_ok = false;
10764 16 : $$ = (Node *) n;
10765 : }
10766 : | ALTER PROCEDURE function_with_argtypes SET SCHEMA name
10767 : {
10768 0 : AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
10769 :
10770 0 : n->objectType = OBJECT_PROCEDURE;
10771 0 : n->object = (Node *) $3;
10772 0 : n->newschema = $6;
10773 0 : n->missing_ok = false;
10774 0 : $$ = (Node *) n;
10775 : }
10776 : | ALTER PROPERTY GRAPH qualified_name SET SCHEMA name
10777 : {
10778 16 : AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
10779 :
10780 16 : n->objectType = OBJECT_PROPGRAPH;
10781 16 : n->relation = $4;
10782 16 : n->newschema = $7;
10783 16 : n->missing_ok = false;
10784 16 : $$ = (Node *)n;
10785 : }
10786 : | ALTER PROPERTY GRAPH IF_P EXISTS qualified_name SET SCHEMA name
10787 : {
10788 4 : AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
10789 :
10790 4 : n->objectType = OBJECT_PROPGRAPH;
10791 4 : n->relation = $6;
10792 4 : n->newschema = $9;
10793 4 : n->missing_ok = true;
10794 4 : $$ = (Node *)n;
10795 : }
10796 : | ALTER ROUTINE function_with_argtypes SET SCHEMA name
10797 : {
10798 0 : AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
10799 :
10800 0 : n->objectType = OBJECT_ROUTINE;
10801 0 : n->object = (Node *) $3;
10802 0 : n->newschema = $6;
10803 0 : n->missing_ok = false;
10804 0 : $$ = (Node *) n;
10805 : }
10806 : | ALTER TABLE relation_expr SET SCHEMA name
10807 : {
10808 43 : AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
10809 :
10810 43 : n->objectType = OBJECT_TABLE;
10811 43 : n->relation = $3;
10812 43 : n->newschema = $6;
10813 43 : n->missing_ok = false;
10814 43 : $$ = (Node *) n;
10815 : }
10816 : | ALTER TABLE IF_P EXISTS relation_expr SET SCHEMA name
10817 : {
10818 8 : AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
10819 :
10820 8 : n->objectType = OBJECT_TABLE;
10821 8 : n->relation = $5;
10822 8 : n->newschema = $8;
10823 8 : n->missing_ok = true;
10824 8 : $$ = (Node *) n;
10825 : }
10826 : | ALTER STATISTICS any_name SET SCHEMA name
10827 : {
10828 12 : AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
10829 :
10830 12 : n->objectType = OBJECT_STATISTIC_EXT;
10831 12 : n->object = (Node *) $3;
10832 12 : n->newschema = $6;
10833 12 : n->missing_ok = false;
10834 12 : $$ = (Node *) n;
10835 : }
10836 : | ALTER TEXT_P SEARCH PARSER any_name SET SCHEMA name
10837 : {
10838 12 : AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
10839 :
10840 12 : n->objectType = OBJECT_TSPARSER;
10841 12 : n->object = (Node *) $5;
10842 12 : n->newschema = $8;
10843 12 : n->missing_ok = false;
10844 12 : $$ = (Node *) n;
10845 : }
10846 : | ALTER TEXT_P SEARCH DICTIONARY any_name SET SCHEMA name
10847 : {
10848 16 : AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
10849 :
10850 16 : n->objectType = OBJECT_TSDICTIONARY;
10851 16 : n->object = (Node *) $5;
10852 16 : n->newschema = $8;
10853 16 : n->missing_ok = false;
10854 16 : $$ = (Node *) n;
10855 : }
10856 : | ALTER TEXT_P SEARCH TEMPLATE any_name SET SCHEMA name
10857 : {
10858 12 : AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
10859 :
10860 12 : n->objectType = OBJECT_TSTEMPLATE;
10861 12 : n->object = (Node *) $5;
10862 12 : n->newschema = $8;
10863 12 : n->missing_ok = false;
10864 12 : $$ = (Node *) n;
10865 : }
10866 : | ALTER TEXT_P SEARCH CONFIGURATION any_name SET SCHEMA name
10867 : {
10868 16 : AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
10869 :
10870 16 : n->objectType = OBJECT_TSCONFIGURATION;
10871 16 : n->object = (Node *) $5;
10872 16 : n->newschema = $8;
10873 16 : n->missing_ok = false;
10874 16 : $$ = (Node *) n;
10875 : }
10876 : | ALTER SEQUENCE qualified_name SET SCHEMA name
10877 : {
10878 5 : AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
10879 :
10880 5 : n->objectType = OBJECT_SEQUENCE;
10881 5 : n->relation = $3;
10882 5 : n->newschema = $6;
10883 5 : n->missing_ok = false;
10884 5 : $$ = (Node *) n;
10885 : }
10886 : | ALTER SEQUENCE IF_P EXISTS qualified_name SET SCHEMA name
10887 : {
10888 0 : AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
10889 :
10890 0 : n->objectType = OBJECT_SEQUENCE;
10891 0 : n->relation = $5;
10892 0 : n->newschema = $8;
10893 0 : n->missing_ok = true;
10894 0 : $$ = (Node *) n;
10895 : }
10896 : | ALTER VIEW qualified_name SET SCHEMA name
10897 : {
10898 0 : AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
10899 :
10900 0 : n->objectType = OBJECT_VIEW;
10901 0 : n->relation = $3;
10902 0 : n->newschema = $6;
10903 0 : n->missing_ok = false;
10904 0 : $$ = (Node *) n;
10905 : }
10906 : | ALTER VIEW IF_P EXISTS qualified_name SET SCHEMA name
10907 : {
10908 0 : AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
10909 :
10910 0 : n->objectType = OBJECT_VIEW;
10911 0 : n->relation = $5;
10912 0 : n->newschema = $8;
10913 0 : n->missing_ok = true;
10914 0 : $$ = (Node *) n;
10915 : }
10916 : | ALTER MATERIALIZED VIEW qualified_name SET SCHEMA name
10917 : {
10918 4 : AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
10919 :
10920 4 : n->objectType = OBJECT_MATVIEW;
10921 4 : n->relation = $4;
10922 4 : n->newschema = $7;
10923 4 : n->missing_ok = false;
10924 4 : $$ = (Node *) n;
10925 : }
10926 : | ALTER MATERIALIZED VIEW IF_P EXISTS qualified_name SET SCHEMA name
10927 : {
10928 0 : AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
10929 :
10930 0 : n->objectType = OBJECT_MATVIEW;
10931 0 : n->relation = $6;
10932 0 : n->newschema = $9;
10933 0 : n->missing_ok = true;
10934 0 : $$ = (Node *) n;
10935 : }
10936 : | ALTER FOREIGN TABLE relation_expr SET SCHEMA name
10937 : {
10938 4 : AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
10939 :
10940 4 : n->objectType = OBJECT_FOREIGN_TABLE;
10941 4 : n->relation = $4;
10942 4 : n->newschema = $7;
10943 4 : n->missing_ok = false;
10944 4 : $$ = (Node *) n;
10945 : }
10946 : | ALTER FOREIGN TABLE IF_P EXISTS relation_expr SET SCHEMA name
10947 : {
10948 4 : AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
10949 :
10950 4 : n->objectType = OBJECT_FOREIGN_TABLE;
10951 4 : n->relation = $6;
10952 4 : n->newschema = $9;
10953 4 : n->missing_ok = true;
10954 4 : $$ = (Node *) n;
10955 : }
10956 : | ALTER TYPE_P any_name SET SCHEMA name
10957 : {
10958 8 : AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
10959 :
10960 8 : n->objectType = OBJECT_TYPE;
10961 8 : n->object = (Node *) $3;
10962 8 : n->newschema = $6;
10963 8 : n->missing_ok = false;
10964 8 : $$ = (Node *) n;
10965 : }
10966 : ;
10967 :
10968 : /*****************************************************************************
10969 : *
10970 : * ALTER OPERATOR name SET define
10971 : *
10972 : *****************************************************************************/
10973 :
10974 : AlterOperatorStmt:
10975 : ALTER OPERATOR operator_with_argtypes SET '(' operator_def_list ')'
10976 : {
10977 332 : AlterOperatorStmt *n = makeNode(AlterOperatorStmt);
10978 :
10979 332 : n->opername = $3;
10980 332 : n->options = $6;
10981 332 : $$ = (Node *) n;
10982 : }
10983 : ;
10984 :
10985 368 : operator_def_list: operator_def_elem { $$ = list_make1($1); }
10986 261 : | operator_def_list ',' operator_def_elem { $$ = lappend($1, $3); }
10987 : ;
10988 :
10989 : operator_def_elem: ColLabel '=' NONE
10990 20 : { $$ = makeDefElem($1, NULL, @1); }
10991 : | ColLabel '=' operator_def_arg
10992 587 : { $$ = makeDefElem($1, (Node *) $3, @1); }
10993 : | ColLabel
10994 22 : { $$ = makeDefElem($1, NULL, @1); }
10995 : ;
10996 :
10997 : /* must be similar enough to def_arg to avoid reduce/reduce conflicts */
10998 : operator_def_arg:
10999 535 : func_type { $$ = (Node *) $1; }
11000 16 : | reserved_keyword { $$ = (Node *) makeString(pstrdup($1)); }
11001 36 : | qual_all_Op { $$ = (Node *) $1; }
11002 0 : | NumericOnly { $$ = (Node *) $1; }
11003 0 : | Sconst { $$ = (Node *) makeString($1); }
11004 : ;
11005 :
11006 : /*****************************************************************************
11007 : *
11008 : * ALTER TYPE name SET define
11009 : *
11010 : * We repurpose ALTER OPERATOR's version of "definition" here
11011 : *
11012 : *****************************************************************************/
11013 :
11014 : AlterTypeStmt:
11015 : ALTER TYPE_P any_name SET '(' operator_def_list ')'
11016 : {
11017 36 : AlterTypeStmt *n = makeNode(AlterTypeStmt);
11018 :
11019 36 : n->typeName = $3;
11020 36 : n->options = $6;
11021 36 : $$ = (Node *) n;
11022 : }
11023 : ;
11024 :
11025 : /*****************************************************************************
11026 : *
11027 : * ALTER THING name OWNER TO newname
11028 : *
11029 : *****************************************************************************/
11030 :
11031 : AlterOwnerStmt: ALTER AGGREGATE aggregate_with_argtypes OWNER TO RoleSpec
11032 : {
11033 76 : AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
11034 :
11035 76 : n->objectType = OBJECT_AGGREGATE;
11036 76 : n->object = (Node *) $3;
11037 76 : n->newowner = $6;
11038 76 : $$ = (Node *) n;
11039 : }
11040 : | ALTER COLLATION any_name OWNER TO RoleSpec
11041 : {
11042 11 : AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
11043 :
11044 11 : n->objectType = OBJECT_COLLATION;
11045 11 : n->object = (Node *) $3;
11046 11 : n->newowner = $6;
11047 11 : $$ = (Node *) n;
11048 : }
11049 : | ALTER CONVERSION_P any_name OWNER TO RoleSpec
11050 : {
11051 16 : AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
11052 :
11053 16 : n->objectType = OBJECT_CONVERSION;
11054 16 : n->object = (Node *) $3;
11055 16 : n->newowner = $6;
11056 16 : $$ = (Node *) n;
11057 : }
11058 : | ALTER DATABASE name OWNER TO RoleSpec
11059 : {
11060 49 : AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
11061 :
11062 49 : n->objectType = OBJECT_DATABASE;
11063 49 : n->object = (Node *) makeString($3);
11064 49 : n->newowner = $6;
11065 49 : $$ = (Node *) n;
11066 : }
11067 : | ALTER DOMAIN_P any_name OWNER TO RoleSpec
11068 : {
11069 26 : AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
11070 :
11071 26 : n->objectType = OBJECT_DOMAIN;
11072 26 : n->object = (Node *) $3;
11073 26 : n->newowner = $6;
11074 26 : $$ = (Node *) n;
11075 : }
11076 : | ALTER FUNCTION function_with_argtypes OWNER TO RoleSpec
11077 : {
11078 320 : AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
11079 :
11080 320 : n->objectType = OBJECT_FUNCTION;
11081 320 : n->object = (Node *) $3;
11082 320 : n->newowner = $6;
11083 320 : $$ = (Node *) n;
11084 : }
11085 : | ALTER opt_procedural LANGUAGE name OWNER TO RoleSpec
11086 : {
11087 83 : AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
11088 :
11089 83 : n->objectType = OBJECT_LANGUAGE;
11090 83 : n->object = (Node *) makeString($4);
11091 83 : n->newowner = $7;
11092 83 : $$ = (Node *) n;
11093 : }
11094 : | ALTER LARGE_P OBJECT_P NumericOnly OWNER TO RoleSpec
11095 : {
11096 9 : AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
11097 :
11098 9 : n->objectType = OBJECT_LARGEOBJECT;
11099 9 : n->object = (Node *) $4;
11100 9 : n->newowner = $7;
11101 9 : $$ = (Node *) n;
11102 : }
11103 : | ALTER OPERATOR operator_with_argtypes OWNER TO RoleSpec
11104 : {
11105 27 : AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
11106 :
11107 27 : n->objectType = OBJECT_OPERATOR;
11108 27 : n->object = (Node *) $3;
11109 27 : n->newowner = $6;
11110 27 : $$ = (Node *) n;
11111 : }
11112 : | ALTER OPERATOR CLASS any_name USING name OWNER TO RoleSpec
11113 : {
11114 35 : AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
11115 :
11116 35 : n->objectType = OBJECT_OPCLASS;
11117 35 : n->object = (Node *) lcons(makeString($6), $4);
11118 35 : n->newowner = $9;
11119 35 : $$ = (Node *) n;
11120 : }
11121 : | ALTER OPERATOR FAMILY any_name USING name OWNER TO RoleSpec
11122 : {
11123 39 : AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
11124 :
11125 39 : n->objectType = OBJECT_OPFAMILY;
11126 39 : n->object = (Node *) lcons(makeString($6), $4);
11127 39 : n->newowner = $9;
11128 39 : $$ = (Node *) n;
11129 : }
11130 : | ALTER PROCEDURE function_with_argtypes OWNER TO RoleSpec
11131 : {
11132 12 : AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
11133 :
11134 12 : n->objectType = OBJECT_PROCEDURE;
11135 12 : n->object = (Node *) $3;
11136 12 : n->newowner = $6;
11137 12 : $$ = (Node *) n;
11138 : }
11139 : | ALTER PROPERTY GRAPH qualified_name OWNER TO RoleSpec
11140 : {
11141 33 : AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
11142 :
11143 33 : n->objectType = OBJECT_PROPGRAPH;
11144 33 : n->relation = $4;
11145 33 : n->newowner = $7;
11146 33 : $$ = (Node *) n;
11147 : }
11148 : | ALTER ROUTINE function_with_argtypes OWNER TO RoleSpec
11149 : {
11150 0 : AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
11151 :
11152 0 : n->objectType = OBJECT_ROUTINE;
11153 0 : n->object = (Node *) $3;
11154 0 : n->newowner = $6;
11155 0 : $$ = (Node *) n;
11156 : }
11157 : | ALTER SCHEMA name OWNER TO RoleSpec
11158 : {
11159 41 : AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
11160 :
11161 41 : n->objectType = OBJECT_SCHEMA;
11162 41 : n->object = (Node *) makeString($3);
11163 41 : n->newowner = $6;
11164 41 : $$ = (Node *) n;
11165 : }
11166 : | ALTER TYPE_P any_name OWNER TO RoleSpec
11167 : {
11168 44 : AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
11169 :
11170 44 : n->objectType = OBJECT_TYPE;
11171 44 : n->object = (Node *) $3;
11172 44 : n->newowner = $6;
11173 44 : $$ = (Node *) n;
11174 : }
11175 : | ALTER TABLESPACE name OWNER TO RoleSpec
11176 : {
11177 3 : AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
11178 :
11179 3 : n->objectType = OBJECT_TABLESPACE;
11180 3 : n->object = (Node *) makeString($3);
11181 3 : n->newowner = $6;
11182 3 : $$ = (Node *) n;
11183 : }
11184 : | ALTER STATISTICS any_name OWNER TO RoleSpec
11185 : {
11186 20 : AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
11187 :
11188 20 : n->objectType = OBJECT_STATISTIC_EXT;
11189 20 : n->object = (Node *) $3;
11190 20 : n->newowner = $6;
11191 20 : $$ = (Node *) n;
11192 : }
11193 : | ALTER TEXT_P SEARCH DICTIONARY any_name OWNER TO RoleSpec
11194 : {
11195 25 : AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
11196 :
11197 25 : n->objectType = OBJECT_TSDICTIONARY;
11198 25 : n->object = (Node *) $5;
11199 25 : n->newowner = $8;
11200 25 : $$ = (Node *) n;
11201 : }
11202 : | ALTER TEXT_P SEARCH CONFIGURATION any_name OWNER TO RoleSpec
11203 : {
11204 20 : AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
11205 :
11206 20 : n->objectType = OBJECT_TSCONFIGURATION;
11207 20 : n->object = (Node *) $5;
11208 20 : n->newowner = $8;
11209 20 : $$ = (Node *) n;
11210 : }
11211 : | ALTER FOREIGN DATA_P WRAPPER name OWNER TO RoleSpec
11212 : {
11213 13 : AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
11214 :
11215 13 : n->objectType = OBJECT_FDW;
11216 13 : n->object = (Node *) makeString($5);
11217 13 : n->newowner = $8;
11218 13 : $$ = (Node *) n;
11219 : }
11220 : | ALTER SERVER name OWNER TO RoleSpec
11221 : {
11222 45 : AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
11223 :
11224 45 : n->objectType = OBJECT_FOREIGN_SERVER;
11225 45 : n->object = (Node *) makeString($3);
11226 45 : n->newowner = $6;
11227 45 : $$ = (Node *) n;
11228 : }
11229 : | ALTER EVENT TRIGGER name OWNER TO RoleSpec
11230 : {
11231 9 : AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
11232 :
11233 9 : n->objectType = OBJECT_EVENT_TRIGGER;
11234 9 : n->object = (Node *) makeString($4);
11235 9 : n->newowner = $7;
11236 9 : $$ = (Node *) n;
11237 : }
11238 : | ALTER PUBLICATION name OWNER TO RoleSpec
11239 : {
11240 26 : AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
11241 :
11242 26 : n->objectType = OBJECT_PUBLICATION;
11243 26 : n->object = (Node *) makeString($3);
11244 26 : n->newowner = $6;
11245 26 : $$ = (Node *) n;
11246 : }
11247 : | ALTER SUBSCRIPTION name OWNER TO RoleSpec
11248 : {
11249 11 : AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
11250 :
11251 11 : n->objectType = OBJECT_SUBSCRIPTION;
11252 11 : n->object = (Node *) makeString($3);
11253 11 : n->newowner = $6;
11254 11 : $$ = (Node *) n;
11255 : }
11256 : ;
11257 :
11258 :
11259 : /*****************************************************************************
11260 : *
11261 : * CREATE PUBLICATION name [WITH options]
11262 : *
11263 : * CREATE PUBLICATION FOR ALL pub_all_obj_type [, ...] [WITH options]
11264 : *
11265 : * pub_all_obj_type is one of:
11266 : *
11267 : * TABLES [EXCEPT (TABLE table [, ...] )]
11268 : * SEQUENCES
11269 : *
11270 : * CREATE PUBLICATION FOR pub_obj [, ...] [WITH options]
11271 : *
11272 : * pub_obj is one of:
11273 : *
11274 : * TABLE table [, ...]
11275 : * TABLES IN SCHEMA schema [, ...]
11276 : *
11277 : *****************************************************************************/
11278 :
11279 : CreatePublicationStmt:
11280 : CREATE PUBLICATION name opt_definition
11281 : {
11282 94 : CreatePublicationStmt *n = makeNode(CreatePublicationStmt);
11283 :
11284 94 : n->pubname = $3;
11285 94 : n->options = $4;
11286 94 : $$ = (Node *) n;
11287 : }
11288 : | CREATE PUBLICATION name FOR pub_all_obj_type_list opt_definition
11289 : {
11290 136 : CreatePublicationStmt *n = makeNode(CreatePublicationStmt);
11291 :
11292 136 : n->pubname = $3;
11293 136 : preprocess_pub_all_objtype_list($5, &n->pubobjects,
11294 : &n->for_all_tables,
11295 : &n->for_all_sequences,
11296 : yyscanner);
11297 128 : n->options = $6;
11298 128 : $$ = (Node *) n;
11299 : }
11300 : | CREATE PUBLICATION name FOR pub_obj_list opt_definition
11301 : {
11302 433 : CreatePublicationStmt *n = makeNode(CreatePublicationStmt);
11303 :
11304 433 : n->pubname = $3;
11305 433 : n->options = $6;
11306 433 : n->pubobjects = (List *) $5;
11307 433 : preprocess_pubobj_list(n->pubobjects, yyscanner);
11308 413 : $$ = (Node *) n;
11309 : }
11310 : ;
11311 :
11312 : /*
11313 : * FOR TABLE and FOR TABLES IN SCHEMA specifications
11314 : *
11315 : * This rule parses publication objects with and without keyword prefixes.
11316 : *
11317 : * The actual type of the object without keyword prefix depends on the previous
11318 : * one with keyword prefix. It will be preprocessed in preprocess_pubobj_list().
11319 : *
11320 : * For the object without keyword prefix, we cannot just use relation_expr here,
11321 : * because some extended expressions in relation_expr cannot be used as a
11322 : * schemaname and we cannot differentiate it. So, we extract the rules from
11323 : * relation_expr here.
11324 : */
11325 : PublicationObjSpec:
11326 : TABLE relation_expr opt_column_list OptWhereClause
11327 : {
11328 862 : $$ = makeNode(PublicationObjSpec);
11329 862 : $$->pubobjtype = PUBLICATIONOBJ_TABLE;
11330 862 : $$->pubtable = makeNode(PublicationTable);
11331 862 : $$->pubtable->relation = $2;
11332 862 : $$->pubtable->columns = $3;
11333 862 : $$->pubtable->whereClause = $4;
11334 : }
11335 : | TABLES IN_P SCHEMA ColId
11336 : {
11337 248 : $$ = makeNode(PublicationObjSpec);
11338 248 : $$->pubobjtype = PUBLICATIONOBJ_TABLES_IN_SCHEMA;
11339 248 : $$->name = $4;
11340 248 : $$->location = @4;
11341 : }
11342 : | TABLES IN_P SCHEMA CURRENT_SCHEMA
11343 : {
11344 12 : $$ = makeNode(PublicationObjSpec);
11345 12 : $$->pubobjtype = PUBLICATIONOBJ_TABLES_IN_CUR_SCHEMA;
11346 12 : $$->location = @4;
11347 : }
11348 : | ColId opt_column_list OptWhereClause
11349 : {
11350 83 : $$ = makeNode(PublicationObjSpec);
11351 83 : $$->pubobjtype = PUBLICATIONOBJ_CONTINUATION;
11352 : /*
11353 : * If either a row filter or column list is specified, create
11354 : * a PublicationTable object.
11355 : */
11356 83 : if ($2 || $3)
11357 : {
11358 : /*
11359 : * The OptWhereClause must be stored here but it is
11360 : * valid only for tables. For non-table objects, an
11361 : * error will be thrown later via
11362 : * preprocess_pubobj_list().
11363 : */
11364 26 : $$->pubtable = makeNode(PublicationTable);
11365 26 : $$->pubtable->relation = makeRangeVar(NULL, $1, @1);
11366 26 : $$->pubtable->columns = $2;
11367 26 : $$->pubtable->whereClause = $3;
11368 : }
11369 : else
11370 : {
11371 57 : $$->name = $1;
11372 : }
11373 83 : $$->location = @1;
11374 : }
11375 : | ColId indirection opt_column_list OptWhereClause
11376 : {
11377 21 : $$ = makeNode(PublicationObjSpec);
11378 21 : $$->pubobjtype = PUBLICATIONOBJ_CONTINUATION;
11379 21 : $$->pubtable = makeNode(PublicationTable);
11380 21 : $$->pubtable->relation = makeRangeVarFromQualifiedName($1, $2, @1, yyscanner);
11381 21 : $$->pubtable->columns = $3;
11382 21 : $$->pubtable->whereClause = $4;
11383 21 : $$->location = @1;
11384 : }
11385 : /* grammar like tablename * , ONLY tablename, ONLY ( tablename ) */
11386 : | extended_relation_expr opt_column_list OptWhereClause
11387 : {
11388 4 : $$ = makeNode(PublicationObjSpec);
11389 4 : $$->pubobjtype = PUBLICATIONOBJ_CONTINUATION;
11390 4 : $$->pubtable = makeNode(PublicationTable);
11391 4 : $$->pubtable->relation = $1;
11392 4 : $$->pubtable->columns = $2;
11393 4 : $$->pubtable->whereClause = $3;
11394 : }
11395 : | CURRENT_SCHEMA
11396 : {
11397 12 : $$ = makeNode(PublicationObjSpec);
11398 12 : $$->pubobjtype = PUBLICATIONOBJ_CONTINUATION;
11399 12 : $$->location = @1;
11400 : }
11401 : ;
11402 :
11403 : pub_obj_list: PublicationObjSpec
11404 1077 : { $$ = list_make1($1); }
11405 : | pub_obj_list ',' PublicationObjSpec
11406 165 : { $$ = lappend($1, $3); }
11407 : ;
11408 :
11409 : opt_pub_except_clause:
11410 64 : EXCEPT '(' TABLE pub_except_obj_list ')' { $$ = $4; }
11411 109 : | /*EMPTY*/ { $$ = NIL; }
11412 : ;
11413 :
11414 : PublicationAllObjSpec:
11415 : ALL TABLES opt_pub_except_clause
11416 : {
11417 173 : $$ = makeNode(PublicationAllObjSpec);
11418 173 : $$->pubobjtype = PUBLICATION_ALL_TABLES;
11419 173 : $$->except_tables = $3;
11420 173 : $$->location = @1;
11421 : }
11422 : | ALL SEQUENCES
11423 : {
11424 49 : $$ = makeNode(PublicationAllObjSpec);
11425 49 : $$->pubobjtype = PUBLICATION_ALL_SEQUENCES;
11426 49 : $$->location = @1;
11427 : }
11428 : ;
11429 :
11430 : pub_all_obj_type_list: PublicationAllObjSpec
11431 197 : { $$ = list_make1($1); }
11432 : | pub_all_obj_type_list ',' PublicationAllObjSpec
11433 25 : { $$ = lappend($1, $3); }
11434 : ;
11435 :
11436 : PublicationExceptObjSpec:
11437 : relation_expr
11438 : {
11439 91 : $$ = makeNode(PublicationObjSpec);
11440 91 : $$->pubobjtype = PUBLICATIONOBJ_EXCEPT_TABLE;
11441 91 : $$->pubtable = makeNode(PublicationTable);
11442 91 : $$->pubtable->except = true;
11443 91 : $$->pubtable->relation = $1;
11444 91 : $$->location = @1;
11445 : }
11446 : ;
11447 :
11448 : pub_except_obj_list: PublicationExceptObjSpec
11449 64 : { $$ = list_make1($1); }
11450 : | pub_except_obj_list ',' opt_table PublicationExceptObjSpec
11451 27 : { $$ = lappend($1, $4); }
11452 : ;
11453 :
11454 : /*****************************************************************************
11455 : *
11456 : * ALTER PUBLICATION name SET ( options )
11457 : *
11458 : * ALTER PUBLICATION name ADD pub_obj [, ...]
11459 : *
11460 : * ALTER PUBLICATION name DROP pub_obj [, ...]
11461 : *
11462 : * ALTER PUBLICATION name SET pub_obj [, ...]
11463 : *
11464 : * ALTER PUBLICATION name SET pub_all_obj_type [, ...]
11465 : *
11466 : * pub_obj is one of:
11467 : *
11468 : * TABLE table_name [, ...]
11469 : * TABLES IN SCHEMA schema_name [, ...]
11470 : *
11471 : * pub_all_obj_type is one of:
11472 : *
11473 : * ALL TABLES [ EXCEPT ( TABLE table_name [, ...] ) ]
11474 : * ALL SEQUENCES
11475 : *
11476 : *****************************************************************************/
11477 :
11478 : AlterPublicationStmt:
11479 : ALTER PUBLICATION name SET definition
11480 : {
11481 84 : AlterPublicationStmt *n = makeNode(AlterPublicationStmt);
11482 :
11483 84 : n->pubname = $3;
11484 84 : n->options = $5;
11485 84 : n->for_all_tables = false;
11486 84 : $$ = (Node *) n;
11487 : }
11488 : | ALTER PUBLICATION name ADD_P pub_obj_list
11489 : {
11490 233 : AlterPublicationStmt *n = makeNode(AlterPublicationStmt);
11491 :
11492 233 : n->pubname = $3;
11493 233 : n->pubobjects = $5;
11494 233 : preprocess_pubobj_list(n->pubobjects, yyscanner);
11495 229 : n->action = AP_AddObjects;
11496 229 : n->for_all_tables = false;
11497 229 : $$ = (Node *) n;
11498 : }
11499 : | ALTER PUBLICATION name SET pub_obj_list
11500 : {
11501 308 : AlterPublicationStmt *n = makeNode(AlterPublicationStmt);
11502 :
11503 308 : n->pubname = $3;
11504 308 : n->pubobjects = $5;
11505 308 : preprocess_pubobj_list(n->pubobjects, yyscanner);
11506 308 : n->action = AP_SetObjects;
11507 308 : n->for_all_tables = false;
11508 308 : $$ = (Node *) n;
11509 : }
11510 : | ALTER PUBLICATION name SET pub_all_obj_type_list
11511 : {
11512 61 : AlterPublicationStmt *n = makeNode(AlterPublicationStmt);
11513 :
11514 61 : n->pubname = $3;
11515 61 : n->action = AP_SetObjects;
11516 61 : preprocess_pub_all_objtype_list($5, &n->pubobjects,
11517 : &n->for_all_tables,
11518 : &n->for_all_sequences,
11519 : yyscanner);
11520 61 : $$ = (Node *) n;
11521 : }
11522 : | ALTER PUBLICATION name DROP pub_obj_list
11523 : {
11524 103 : AlterPublicationStmt *n = makeNode(AlterPublicationStmt);
11525 :
11526 103 : n->pubname = $3;
11527 103 : n->pubobjects = $5;
11528 103 : preprocess_pubobj_list(n->pubobjects, yyscanner);
11529 103 : n->action = AP_DropObjects;
11530 103 : n->for_all_tables = false;
11531 103 : $$ = (Node *) n;
11532 : }
11533 : ;
11534 :
11535 : /*****************************************************************************
11536 : *
11537 : * CREATE SUBSCRIPTION name ...
11538 : *
11539 : *****************************************************************************/
11540 :
11541 : CreateSubscriptionStmt:
11542 : CREATE SUBSCRIPTION name CONNECTION Sconst PUBLICATION name_list opt_definition
11543 : {
11544 : CreateSubscriptionStmt *n =
11545 286 : makeNode(CreateSubscriptionStmt);
11546 286 : n->subname = $3;
11547 286 : n->conninfo = $5;
11548 286 : n->publication = $7;
11549 286 : n->options = $8;
11550 286 : $$ = (Node *) n;
11551 : }
11552 : | CREATE SUBSCRIPTION name SERVER name PUBLICATION name_list opt_definition
11553 : {
11554 : CreateSubscriptionStmt *n =
11555 18 : makeNode(CreateSubscriptionStmt);
11556 18 : n->subname = $3;
11557 18 : n->servername = $5;
11558 18 : n->publication = $7;
11559 18 : n->options = $8;
11560 18 : $$ = (Node *) n;
11561 : }
11562 : ;
11563 :
11564 : /*****************************************************************************
11565 : *
11566 : * ALTER SUBSCRIPTION name ...
11567 : *
11568 : *****************************************************************************/
11569 :
11570 : AlterSubscriptionStmt:
11571 : ALTER SUBSCRIPTION name SET definition
11572 : {
11573 : AlterSubscriptionStmt *n =
11574 152 : makeNode(AlterSubscriptionStmt);
11575 :
11576 152 : n->kind = ALTER_SUBSCRIPTION_OPTIONS;
11577 152 : n->subname = $3;
11578 152 : n->options = $5;
11579 152 : $$ = (Node *) n;
11580 : }
11581 : | ALTER SUBSCRIPTION name CONNECTION Sconst
11582 : {
11583 : AlterSubscriptionStmt *n =
11584 17 : makeNode(AlterSubscriptionStmt);
11585 :
11586 17 : n->kind = ALTER_SUBSCRIPTION_CONNECTION;
11587 17 : n->subname = $3;
11588 17 : n->conninfo = $5;
11589 17 : $$ = (Node *) n;
11590 : }
11591 : | ALTER SUBSCRIPTION name SERVER name
11592 : {
11593 : AlterSubscriptionStmt *n =
11594 1 : makeNode(AlterSubscriptionStmt);
11595 :
11596 1 : n->kind = ALTER_SUBSCRIPTION_SERVER;
11597 1 : n->subname = $3;
11598 1 : n->servername = $5;
11599 1 : $$ = (Node *) n;
11600 : }
11601 : | ALTER SUBSCRIPTION name REFRESH PUBLICATION opt_definition
11602 : {
11603 : AlterSubscriptionStmt *n =
11604 37 : makeNode(AlterSubscriptionStmt);
11605 :
11606 37 : n->kind = ALTER_SUBSCRIPTION_REFRESH_PUBLICATION;
11607 37 : n->subname = $3;
11608 37 : n->options = $6;
11609 37 : $$ = (Node *) n;
11610 : }
11611 : | ALTER SUBSCRIPTION name REFRESH SEQUENCES
11612 : {
11613 : AlterSubscriptionStmt *n =
11614 1 : makeNode(AlterSubscriptionStmt);
11615 :
11616 1 : n->kind = ALTER_SUBSCRIPTION_REFRESH_SEQUENCES;
11617 1 : n->subname = $3;
11618 1 : $$ = (Node *) n;
11619 : }
11620 : | ALTER SUBSCRIPTION name ADD_P PUBLICATION name_list opt_definition
11621 : {
11622 : AlterSubscriptionStmt *n =
11623 18 : makeNode(AlterSubscriptionStmt);
11624 :
11625 18 : n->kind = ALTER_SUBSCRIPTION_ADD_PUBLICATION;
11626 18 : n->subname = $3;
11627 18 : n->publication = $6;
11628 18 : n->options = $7;
11629 18 : $$ = (Node *) n;
11630 : }
11631 : | ALTER SUBSCRIPTION name DROP PUBLICATION name_list opt_definition
11632 : {
11633 : AlterSubscriptionStmt *n =
11634 17 : makeNode(AlterSubscriptionStmt);
11635 :
11636 17 : n->kind = ALTER_SUBSCRIPTION_DROP_PUBLICATION;
11637 17 : n->subname = $3;
11638 17 : n->publication = $6;
11639 17 : n->options = $7;
11640 17 : $$ = (Node *) n;
11641 : }
11642 : | ALTER SUBSCRIPTION name SET PUBLICATION name_list opt_definition
11643 : {
11644 : AlterSubscriptionStmt *n =
11645 28 : makeNode(AlterSubscriptionStmt);
11646 :
11647 28 : n->kind = ALTER_SUBSCRIPTION_SET_PUBLICATION;
11648 28 : n->subname = $3;
11649 28 : n->publication = $6;
11650 28 : n->options = $7;
11651 28 : $$ = (Node *) n;
11652 : }
11653 : | ALTER SUBSCRIPTION name ENABLE_P
11654 : {
11655 : AlterSubscriptionStmt *n =
11656 34 : makeNode(AlterSubscriptionStmt);
11657 :
11658 34 : n->kind = ALTER_SUBSCRIPTION_ENABLED;
11659 34 : n->subname = $3;
11660 34 : n->options = list_make1(makeDefElem("enabled",
11661 : (Node *) makeBoolean(true), @1));
11662 34 : $$ = (Node *) n;
11663 : }
11664 : | ALTER SUBSCRIPTION name DISABLE_P
11665 : {
11666 : AlterSubscriptionStmt *n =
11667 24 : makeNode(AlterSubscriptionStmt);
11668 :
11669 24 : n->kind = ALTER_SUBSCRIPTION_ENABLED;
11670 24 : n->subname = $3;
11671 24 : n->options = list_make1(makeDefElem("enabled",
11672 : (Node *) makeBoolean(false), @1));
11673 24 : $$ = (Node *) n;
11674 : }
11675 : | ALTER SUBSCRIPTION name SKIP definition
11676 : {
11677 : AlterSubscriptionStmt *n =
11678 15 : makeNode(AlterSubscriptionStmt);
11679 :
11680 15 : n->kind = ALTER_SUBSCRIPTION_SKIP;
11681 15 : n->subname = $3;
11682 15 : n->options = $5;
11683 15 : $$ = (Node *) n;
11684 : }
11685 : ;
11686 :
11687 : /*****************************************************************************
11688 : *
11689 : * DROP SUBSCRIPTION [ IF EXISTS ] name
11690 : *
11691 : *****************************************************************************/
11692 :
11693 : DropSubscriptionStmt: DROP SUBSCRIPTION name opt_drop_behavior
11694 : {
11695 151 : DropSubscriptionStmt *n = makeNode(DropSubscriptionStmt);
11696 :
11697 151 : n->subname = $3;
11698 151 : n->missing_ok = false;
11699 151 : n->behavior = $4;
11700 151 : $$ = (Node *) n;
11701 : }
11702 : | DROP SUBSCRIPTION IF_P EXISTS name opt_drop_behavior
11703 : {
11704 4 : DropSubscriptionStmt *n = makeNode(DropSubscriptionStmt);
11705 :
11706 4 : n->subname = $5;
11707 4 : n->missing_ok = true;
11708 4 : n->behavior = $6;
11709 4 : $$ = (Node *) n;
11710 : }
11711 : ;
11712 :
11713 : /*****************************************************************************
11714 : *
11715 : * QUERY: Define Rewrite Rule
11716 : *
11717 : *****************************************************************************/
11718 :
11719 : RuleStmt: CREATE opt_or_replace RULE name AS
11720 : ON event TO qualified_name where_clause
11721 : DO opt_instead RuleActionList
11722 : {
11723 702 : RuleStmt *n = makeNode(RuleStmt);
11724 :
11725 702 : n->replace = $2;
11726 702 : n->relation = $9;
11727 702 : n->rulename = $4;
11728 702 : n->whereClause = $10;
11729 702 : n->event = $7;
11730 702 : n->instead = $12;
11731 702 : n->actions = $13;
11732 702 : $$ = (Node *) n;
11733 : }
11734 : ;
11735 :
11736 : RuleActionList:
11737 96 : NOTHING { $$ = NIL; }
11738 576 : | RuleActionStmt { $$ = list_make1($1); }
11739 30 : | '(' RuleActionMulti ')' { $$ = $2; }
11740 : ;
11741 :
11742 : /* the thrashing around here is to discard "empty" statements... */
11743 : RuleActionMulti:
11744 : RuleActionMulti ';' RuleActionStmtOrEmpty
11745 40 : { if ($3 != NULL)
11746 30 : $$ = lappend($1, $3);
11747 : else
11748 10 : $$ = $1;
11749 : }
11750 : | RuleActionStmtOrEmpty
11751 30 : { if ($1 != NULL)
11752 30 : $$ = list_make1($1);
11753 : else
11754 0 : $$ = NIL;
11755 : }
11756 : ;
11757 :
11758 : RuleActionStmt:
11759 : SelectStmt
11760 : | InsertStmt
11761 : | UpdateStmt
11762 : | DeleteStmt
11763 : | NotifyStmt
11764 : ;
11765 :
11766 : RuleActionStmtOrEmpty:
11767 60 : RuleActionStmt { $$ = $1; }
11768 10 : | /*EMPTY*/ { $$ = NULL; }
11769 : ;
11770 :
11771 12 : event: SELECT { $$ = CMD_SELECT; }
11772 266 : | UPDATE { $$ = CMD_UPDATE; }
11773 106 : | DELETE_P { $$ = CMD_DELETE; }
11774 318 : | INSERT { $$ = CMD_INSERT; }
11775 : ;
11776 :
11777 : opt_instead:
11778 491 : INSTEAD { $$ = true; }
11779 103 : | ALSO { $$ = false; }
11780 108 : | /*EMPTY*/ { $$ = false; }
11781 : ;
11782 :
11783 :
11784 : /*****************************************************************************
11785 : *
11786 : * QUERY:
11787 : * NOTIFY <identifier> can appear both in rule bodies and
11788 : * as a query-level command
11789 : *
11790 : *****************************************************************************/
11791 :
11792 : NotifyStmt: NOTIFY ColId notify_payload
11793 : {
11794 88 : NotifyStmt *n = makeNode(NotifyStmt);
11795 :
11796 88 : n->conditionname = $2;
11797 88 : n->payload = $3;
11798 88 : $$ = (Node *) n;
11799 : }
11800 : ;
11801 :
11802 : notify_payload:
11803 47 : ',' Sconst { $$ = $2; }
11804 41 : | /*EMPTY*/ { $$ = NULL; }
11805 : ;
11806 :
11807 : ListenStmt: LISTEN ColId
11808 : {
11809 60 : ListenStmt *n = makeNode(ListenStmt);
11810 :
11811 60 : n->conditionname = $2;
11812 60 : $$ = (Node *) n;
11813 : }
11814 : ;
11815 :
11816 : UnlistenStmt:
11817 : UNLISTEN ColId
11818 : {
11819 4 : UnlistenStmt *n = makeNode(UnlistenStmt);
11820 :
11821 4 : n->conditionname = $2;
11822 4 : $$ = (Node *) n;
11823 : }
11824 : | UNLISTEN '*'
11825 : {
11826 76 : UnlistenStmt *n = makeNode(UnlistenStmt);
11827 :
11828 76 : n->conditionname = NULL;
11829 76 : $$ = (Node *) n;
11830 : }
11831 : ;
11832 :
11833 :
11834 : /*****************************************************************************
11835 : *
11836 : * Transactions:
11837 : *
11838 : * BEGIN / COMMIT / ROLLBACK
11839 : * (also older versions END / ABORT)
11840 : *
11841 : *****************************************************************************/
11842 :
11843 : TransactionStmt:
11844 : ABORT_P opt_transaction opt_transaction_chain
11845 : {
11846 408 : TransactionStmt *n = makeNode(TransactionStmt);
11847 :
11848 408 : n->kind = TRANS_STMT_ROLLBACK;
11849 408 : n->options = NIL;
11850 408 : n->chain = $3;
11851 408 : n->location = -1;
11852 408 : $$ = (Node *) n;
11853 : }
11854 : | START TRANSACTION transaction_mode_list_or_empty
11855 : {
11856 862 : TransactionStmt *n = makeNode(TransactionStmt);
11857 :
11858 862 : n->kind = TRANS_STMT_START;
11859 862 : n->options = $3;
11860 862 : n->location = -1;
11861 862 : $$ = (Node *) n;
11862 : }
11863 : | COMMIT opt_transaction opt_transaction_chain
11864 : {
11865 9555 : TransactionStmt *n = makeNode(TransactionStmt);
11866 :
11867 9555 : n->kind = TRANS_STMT_COMMIT;
11868 9555 : n->options = NIL;
11869 9555 : n->chain = $3;
11870 9555 : n->location = -1;
11871 9555 : $$ = (Node *) n;
11872 : }
11873 : | ROLLBACK opt_transaction opt_transaction_chain
11874 : {
11875 1808 : TransactionStmt *n = makeNode(TransactionStmt);
11876 :
11877 1808 : n->kind = TRANS_STMT_ROLLBACK;
11878 1808 : n->options = NIL;
11879 1808 : n->chain = $3;
11880 1808 : n->location = -1;
11881 1808 : $$ = (Node *) n;
11882 : }
11883 : | SAVEPOINT ColId
11884 : {
11885 1181 : TransactionStmt *n = makeNode(TransactionStmt);
11886 :
11887 1181 : n->kind = TRANS_STMT_SAVEPOINT;
11888 1181 : n->savepoint_name = $2;
11889 1181 : n->location = @2;
11890 1181 : $$ = (Node *) n;
11891 : }
11892 : | RELEASE SAVEPOINT ColId
11893 : {
11894 134 : TransactionStmt *n = makeNode(TransactionStmt);
11895 :
11896 134 : n->kind = TRANS_STMT_RELEASE;
11897 134 : n->savepoint_name = $3;
11898 134 : n->location = @3;
11899 134 : $$ = (Node *) n;
11900 : }
11901 : | RELEASE ColId
11902 : {
11903 55 : TransactionStmt *n = makeNode(TransactionStmt);
11904 :
11905 55 : n->kind = TRANS_STMT_RELEASE;
11906 55 : n->savepoint_name = $2;
11907 55 : n->location = @2;
11908 55 : $$ = (Node *) n;
11909 : }
11910 : | ROLLBACK opt_transaction TO SAVEPOINT ColId
11911 : {
11912 163 : TransactionStmt *n = makeNode(TransactionStmt);
11913 :
11914 163 : n->kind = TRANS_STMT_ROLLBACK_TO;
11915 163 : n->savepoint_name = $5;
11916 163 : n->location = @5;
11917 163 : $$ = (Node *) n;
11918 : }
11919 : | ROLLBACK opt_transaction TO ColId
11920 : {
11921 319 : TransactionStmt *n = makeNode(TransactionStmt);
11922 :
11923 319 : n->kind = TRANS_STMT_ROLLBACK_TO;
11924 319 : n->savepoint_name = $4;
11925 319 : n->location = @4;
11926 319 : $$ = (Node *) n;
11927 : }
11928 : | PREPARE TRANSACTION Sconst
11929 : {
11930 362 : TransactionStmt *n = makeNode(TransactionStmt);
11931 :
11932 362 : n->kind = TRANS_STMT_PREPARE;
11933 362 : n->gid = $3;
11934 362 : n->location = @3;
11935 362 : $$ = (Node *) n;
11936 : }
11937 : | COMMIT PREPARED Sconst
11938 : {
11939 268 : TransactionStmt *n = makeNode(TransactionStmt);
11940 :
11941 268 : n->kind = TRANS_STMT_COMMIT_PREPARED;
11942 268 : n->gid = $3;
11943 268 : n->location = @3;
11944 268 : $$ = (Node *) n;
11945 : }
11946 : | ROLLBACK PREPARED Sconst
11947 : {
11948 47 : TransactionStmt *n = makeNode(TransactionStmt);
11949 :
11950 47 : n->kind = TRANS_STMT_ROLLBACK_PREPARED;
11951 47 : n->gid = $3;
11952 47 : n->location = @3;
11953 47 : $$ = (Node *) n;
11954 : }
11955 : ;
11956 :
11957 : TransactionStmtLegacy:
11958 : BEGIN_P opt_transaction transaction_mode_list_or_empty
11959 : {
11960 11725 : TransactionStmt *n = makeNode(TransactionStmt);
11961 :
11962 11725 : n->kind = TRANS_STMT_BEGIN;
11963 11725 : n->options = $3;
11964 11725 : n->location = -1;
11965 11725 : $$ = (Node *) n;
11966 : }
11967 : | END_P opt_transaction opt_transaction_chain
11968 : {
11969 207 : TransactionStmt *n = makeNode(TransactionStmt);
11970 :
11971 207 : n->kind = TRANS_STMT_COMMIT;
11972 207 : n->options = NIL;
11973 207 : n->chain = $3;
11974 207 : n->location = -1;
11975 207 : $$ = (Node *) n;
11976 : }
11977 : ;
11978 :
11979 : opt_transaction: WORK
11980 : | TRANSACTION
11981 : | /*EMPTY*/
11982 : ;
11983 :
11984 : transaction_mode_item:
11985 : ISOLATION LEVEL iso_level
11986 3895 : { $$ = makeDefElem("transaction_isolation",
11987 3895 : makeStringConst($3, @3), @1); }
11988 : | READ ONLY
11989 832 : { $$ = makeDefElem("transaction_read_only",
11990 832 : makeIntConst(true, @1), @1); }
11991 : | READ WRITE
11992 59 : { $$ = makeDefElem("transaction_read_only",
11993 59 : makeIntConst(false, @1), @1); }
11994 : | DEFERRABLE
11995 32 : { $$ = makeDefElem("transaction_deferrable",
11996 : makeIntConst(true, @1), @1); }
11997 : | NOT DEFERRABLE
11998 6 : { $$ = makeDefElem("transaction_deferrable",
11999 6 : makeIntConst(false, @1), @1); }
12000 : ;
12001 :
12002 : /* Syntax with commas is SQL-spec, without commas is Postgres historical */
12003 : transaction_mode_list:
12004 : transaction_mode_item
12005 4038 : { $$ = list_make1($1); }
12006 : | transaction_mode_list ',' transaction_mode_item
12007 558 : { $$ = lappend($1, $3); }
12008 : | transaction_mode_list transaction_mode_item
12009 228 : { $$ = lappend($1, $2); }
12010 : ;
12011 :
12012 : transaction_mode_list_or_empty:
12013 : transaction_mode_list
12014 : | /* EMPTY */
12015 8947 : { $$ = NIL; }
12016 : ;
12017 :
12018 : opt_transaction_chain:
12019 80 : AND CHAIN { $$ = true; }
12020 1 : | AND NO CHAIN { $$ = false; }
12021 11897 : | /* EMPTY */ { $$ = false; }
12022 : ;
12023 :
12024 :
12025 : /*****************************************************************************
12026 : *
12027 : * QUERY:
12028 : * CREATE [ OR REPLACE ] [ TEMP ] VIEW <viewname> '('target-list ')'
12029 : * AS <query> [ WITH [ CASCADED | LOCAL ] CHECK OPTION ]
12030 : *
12031 : *****************************************************************************/
12032 :
12033 : ViewStmt: CREATE OptTemp VIEW qualified_name opt_column_list opt_reloptions
12034 : AS SelectStmt opt_check_option
12035 : {
12036 10744 : ViewStmt *n = makeNode(ViewStmt);
12037 :
12038 10744 : n->view = $4;
12039 10744 : n->view->relpersistence = $2;
12040 10744 : n->aliases = $5;
12041 10744 : n->query = $8;
12042 10744 : n->replace = false;
12043 10744 : n->options = $6;
12044 10744 : n->withCheckOption = $9;
12045 10744 : $$ = (Node *) n;
12046 : }
12047 : | CREATE OR REPLACE OptTemp VIEW qualified_name opt_column_list opt_reloptions
12048 : AS SelectStmt opt_check_option
12049 : {
12050 169 : ViewStmt *n = makeNode(ViewStmt);
12051 :
12052 169 : n->view = $6;
12053 169 : n->view->relpersistence = $4;
12054 169 : n->aliases = $7;
12055 169 : n->query = $10;
12056 169 : n->replace = true;
12057 169 : n->options = $8;
12058 169 : n->withCheckOption = $11;
12059 169 : $$ = (Node *) n;
12060 : }
12061 : | CREATE OptTemp RECURSIVE VIEW qualified_name '(' columnList ')' opt_reloptions
12062 : AS SelectStmt opt_check_option
12063 : {
12064 5 : ViewStmt *n = makeNode(ViewStmt);
12065 :
12066 5 : n->view = $5;
12067 5 : n->view->relpersistence = $2;
12068 5 : n->aliases = $7;
12069 5 : n->query = makeRecursiveViewSelect(n->view->relname, n->aliases, $11);
12070 5 : n->replace = false;
12071 5 : n->options = $9;
12072 5 : n->withCheckOption = $12;
12073 5 : if (n->withCheckOption != NO_CHECK_OPTION)
12074 0 : ereport(ERROR,
12075 : (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
12076 : errmsg("WITH CHECK OPTION not supported on recursive views"),
12077 : parser_errposition(@12)));
12078 5 : $$ = (Node *) n;
12079 : }
12080 : | CREATE OR REPLACE OptTemp RECURSIVE VIEW qualified_name '(' columnList ')' opt_reloptions
12081 : AS SelectStmt opt_check_option
12082 : {
12083 4 : ViewStmt *n = makeNode(ViewStmt);
12084 :
12085 4 : n->view = $7;
12086 4 : n->view->relpersistence = $4;
12087 4 : n->aliases = $9;
12088 4 : n->query = makeRecursiveViewSelect(n->view->relname, n->aliases, $13);
12089 4 : n->replace = true;
12090 4 : n->options = $11;
12091 4 : n->withCheckOption = $14;
12092 4 : if (n->withCheckOption != NO_CHECK_OPTION)
12093 0 : ereport(ERROR,
12094 : (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
12095 : errmsg("WITH CHECK OPTION not supported on recursive views"),
12096 : parser_errposition(@14)));
12097 4 : $$ = (Node *) n;
12098 : }
12099 : ;
12100 :
12101 : opt_check_option:
12102 63 : WITH CHECK OPTION { $$ = CASCADED_CHECK_OPTION; }
12103 4 : | WITH CASCADED CHECK OPTION { $$ = CASCADED_CHECK_OPTION; }
12104 16 : | WITH LOCAL CHECK OPTION { $$ = LOCAL_CHECK_OPTION; }
12105 10839 : | /* EMPTY */ { $$ = NO_CHECK_OPTION; }
12106 : ;
12107 :
12108 : /*****************************************************************************
12109 : *
12110 : * QUERY:
12111 : * LOAD "filename"
12112 : *
12113 : *****************************************************************************/
12114 :
12115 : LoadStmt: LOAD file_name
12116 : {
12117 45 : LoadStmt *n = makeNode(LoadStmt);
12118 :
12119 45 : n->filename = $2;
12120 45 : $$ = (Node *) n;
12121 : }
12122 : ;
12123 :
12124 :
12125 : /*****************************************************************************
12126 : *
12127 : * CREATE DATABASE
12128 : *
12129 : *****************************************************************************/
12130 :
12131 : CreatedbStmt:
12132 : CREATE DATABASE name opt_with createdb_opt_list
12133 : {
12134 453 : CreatedbStmt *n = makeNode(CreatedbStmt);
12135 :
12136 453 : n->dbname = $3;
12137 453 : n->options = $5;
12138 453 : $$ = (Node *) n;
12139 : }
12140 : ;
12141 :
12142 : createdb_opt_list:
12143 372 : createdb_opt_items { $$ = $1; }
12144 123 : | /* EMPTY */ { $$ = NIL; }
12145 : ;
12146 :
12147 : createdb_opt_items:
12148 372 : createdb_opt_item { $$ = list_make1($1); }
12149 568 : | createdb_opt_items createdb_opt_item { $$ = lappend($1, $2); }
12150 : ;
12151 :
12152 : createdb_opt_item:
12153 : createdb_opt_name opt_equal NumericOnly
12154 : {
12155 156 : $$ = makeDefElem($1, $3, @1);
12156 : }
12157 : | createdb_opt_name opt_equal opt_boolean_or_string
12158 : {
12159 784 : $$ = makeDefElem($1, (Node *) makeString($3), @1);
12160 : }
12161 : | createdb_opt_name opt_equal DEFAULT
12162 : {
12163 0 : $$ = makeDefElem($1, NULL, @1);
12164 : }
12165 : ;
12166 :
12167 : /*
12168 : * Ideally we'd use ColId here, but that causes shift/reduce conflicts against
12169 : * the ALTER DATABASE SET/RESET syntaxes. Instead call out specific keywords
12170 : * we need, and allow IDENT so that database option names don't have to be
12171 : * parser keywords unless they are already keywords for other reasons.
12172 : *
12173 : * XXX this coding technique is fragile since if someone makes a formerly
12174 : * non-keyword option name into a keyword and forgets to add it here, the
12175 : * option will silently break. Best defense is to provide a regression test
12176 : * exercising every such option, at least at the syntax level.
12177 : */
12178 : createdb_opt_name:
12179 658 : IDENT { $$ = $1; }
12180 1 : | CONNECTION LIMIT { $$ = pstrdup("connection_limit"); }
12181 61 : | ENCODING { $$ = pstrdup($1); }
12182 0 : | LOCATION { $$ = pstrdup($1); }
12183 5 : | OWNER { $$ = pstrdup($1); }
12184 17 : | TABLESPACE { $$ = pstrdup($1); }
12185 198 : | TEMPLATE { $$ = pstrdup($1); }
12186 : ;
12187 :
12188 : /*
12189 : * Though the equals sign doesn't match other WITH options, pg_dump uses
12190 : * equals for backward compatibility, and it doesn't seem worth removing it.
12191 : */
12192 : opt_equal: '='
12193 : | /*EMPTY*/
12194 : ;
12195 :
12196 :
12197 : /*****************************************************************************
12198 : *
12199 : * ALTER DATABASE
12200 : *
12201 : *****************************************************************************/
12202 :
12203 : AlterDatabaseStmt:
12204 : ALTER DATABASE name WITH createdb_opt_list
12205 : {
12206 1 : AlterDatabaseStmt *n = makeNode(AlterDatabaseStmt);
12207 :
12208 1 : n->dbname = $3;
12209 1 : n->options = $5;
12210 1 : $$ = (Node *) n;
12211 : }
12212 : | ALTER DATABASE name createdb_opt_list
12213 : {
12214 41 : AlterDatabaseStmt *n = makeNode(AlterDatabaseStmt);
12215 :
12216 41 : n->dbname = $3;
12217 41 : n->options = $4;
12218 41 : $$ = (Node *) n;
12219 : }
12220 : | ALTER DATABASE name SET TABLESPACE name
12221 : {
12222 14 : AlterDatabaseStmt *n = makeNode(AlterDatabaseStmt);
12223 :
12224 14 : n->dbname = $3;
12225 14 : n->options = list_make1(makeDefElem("tablespace",
12226 : (Node *) makeString($6), @6));
12227 14 : $$ = (Node *) n;
12228 : }
12229 : | ALTER DATABASE name REFRESH COLLATION VERSION_P
12230 : {
12231 4 : AlterDatabaseRefreshCollStmt *n = makeNode(AlterDatabaseRefreshCollStmt);
12232 :
12233 4 : n->dbname = $3;
12234 4 : $$ = (Node *) n;
12235 : }
12236 : ;
12237 :
12238 : AlterDatabaseSetStmt:
12239 : ALTER DATABASE name SetResetClause
12240 : {
12241 667 : AlterDatabaseSetStmt *n = makeNode(AlterDatabaseSetStmt);
12242 :
12243 667 : n->dbname = $3;
12244 667 : n->setstmt = $4;
12245 667 : $$ = (Node *) n;
12246 : }
12247 : ;
12248 :
12249 :
12250 : /*****************************************************************************
12251 : *
12252 : * DROP DATABASE [ IF EXISTS ] dbname [ [ WITH ] ( options ) ]
12253 : *
12254 : * This is implicitly CASCADE, no need for drop behavior
12255 : *****************************************************************************/
12256 :
12257 : DropdbStmt: DROP DATABASE name
12258 : {
12259 60 : DropdbStmt *n = makeNode(DropdbStmt);
12260 :
12261 60 : n->dbname = $3;
12262 60 : n->missing_ok = false;
12263 60 : n->options = NULL;
12264 60 : $$ = (Node *) n;
12265 : }
12266 : | DROP DATABASE IF_P EXISTS name
12267 : {
12268 3 : DropdbStmt *n = makeNode(DropdbStmt);
12269 :
12270 3 : n->dbname = $5;
12271 3 : n->missing_ok = true;
12272 3 : n->options = NULL;
12273 3 : $$ = (Node *) n;
12274 : }
12275 : | DROP DATABASE name opt_with '(' drop_option_list ')'
12276 : {
12277 9 : DropdbStmt *n = makeNode(DropdbStmt);
12278 :
12279 9 : n->dbname = $3;
12280 9 : n->missing_ok = false;
12281 9 : n->options = $6;
12282 9 : $$ = (Node *) n;
12283 : }
12284 : | DROP DATABASE IF_P EXISTS name opt_with '(' drop_option_list ')'
12285 : {
12286 8 : DropdbStmt *n = makeNode(DropdbStmt);
12287 :
12288 8 : n->dbname = $5;
12289 8 : n->missing_ok = true;
12290 8 : n->options = $8;
12291 8 : $$ = (Node *) n;
12292 : }
12293 : ;
12294 :
12295 : drop_option_list:
12296 : drop_option
12297 : {
12298 17 : $$ = list_make1((Node *) $1);
12299 : }
12300 : | drop_option_list ',' drop_option
12301 : {
12302 0 : $$ = lappend($1, (Node *) $3);
12303 : }
12304 : ;
12305 :
12306 : /*
12307 : * Currently only the FORCE option is supported, but the syntax is designed
12308 : * to be extensible so that we can add more options in the future if required.
12309 : */
12310 : drop_option:
12311 : FORCE
12312 : {
12313 17 : $$ = makeDefElem("force", NULL, @1);
12314 : }
12315 : ;
12316 :
12317 : /*****************************************************************************
12318 : *
12319 : * ALTER COLLATION
12320 : *
12321 : *****************************************************************************/
12322 :
12323 : AlterCollationStmt: ALTER COLLATION any_name REFRESH VERSION_P
12324 : {
12325 4 : AlterCollationStmt *n = makeNode(AlterCollationStmt);
12326 :
12327 4 : n->collname = $3;
12328 4 : $$ = (Node *) n;
12329 : }
12330 : ;
12331 :
12332 :
12333 : /*****************************************************************************
12334 : *
12335 : * ALTER SYSTEM
12336 : *
12337 : * This is used to change configuration parameters persistently.
12338 : *****************************************************************************/
12339 :
12340 : AlterSystemStmt:
12341 : ALTER SYSTEM_P SET generic_set
12342 : {
12343 88 : AlterSystemStmt *n = makeNode(AlterSystemStmt);
12344 :
12345 88 : n->setstmt = $4;
12346 88 : $$ = (Node *) n;
12347 : }
12348 : | ALTER SYSTEM_P RESET generic_reset
12349 : {
12350 29 : AlterSystemStmt *n = makeNode(AlterSystemStmt);
12351 :
12352 29 : n->setstmt = $4;
12353 29 : $$ = (Node *) n;
12354 : }
12355 : ;
12356 :
12357 :
12358 : /*****************************************************************************
12359 : *
12360 : * Manipulate a domain
12361 : *
12362 : *****************************************************************************/
12363 :
12364 : CreateDomainStmt:
12365 : CREATE DOMAIN_P any_name opt_as Typename ColQualList
12366 : {
12367 983 : CreateDomainStmt *n = makeNode(CreateDomainStmt);
12368 :
12369 983 : n->domainname = $3;
12370 983 : n->typeName = $5;
12371 983 : SplitColQualList($6, &n->constraints, &n->collClause,
12372 : yyscanner);
12373 983 : $$ = (Node *) n;
12374 : }
12375 : ;
12376 :
12377 : AlterDomainStmt:
12378 : /* ALTER DOMAIN <domain> {SET DEFAULT <expr>|DROP DEFAULT} */
12379 : ALTER DOMAIN_P any_name alter_column_default
12380 : {
12381 9 : AlterDomainStmt *n = makeNode(AlterDomainStmt);
12382 :
12383 9 : n->subtype = AD_AlterDefault;
12384 9 : n->typeName = $3;
12385 9 : n->def = $4;
12386 9 : $$ = (Node *) n;
12387 : }
12388 : /* ALTER DOMAIN <domain> DROP NOT NULL */
12389 : | ALTER DOMAIN_P any_name DROP NOT NULL_P
12390 : {
12391 8 : AlterDomainStmt *n = makeNode(AlterDomainStmt);
12392 :
12393 8 : n->subtype = AD_DropNotNull;
12394 8 : n->typeName = $3;
12395 8 : $$ = (Node *) n;
12396 : }
12397 : /* ALTER DOMAIN <domain> SET NOT NULL */
12398 : | ALTER DOMAIN_P any_name SET NOT NULL_P
12399 : {
12400 16 : AlterDomainStmt *n = makeNode(AlterDomainStmt);
12401 :
12402 16 : n->subtype = AD_SetNotNull;
12403 16 : n->typeName = $3;
12404 16 : $$ = (Node *) n;
12405 : }
12406 : /* ALTER DOMAIN <domain> ADD CONSTRAINT ... */
12407 : | ALTER DOMAIN_P any_name ADD_P DomainConstraint
12408 : {
12409 120 : AlterDomainStmt *n = makeNode(AlterDomainStmt);
12410 :
12411 120 : n->subtype = AD_AddConstraint;
12412 120 : n->typeName = $3;
12413 120 : n->def = $5;
12414 120 : $$ = (Node *) n;
12415 : }
12416 : /* ALTER DOMAIN <domain> DROP CONSTRAINT <name> [RESTRICT|CASCADE] */
12417 : | ALTER DOMAIN_P any_name DROP CONSTRAINT name opt_drop_behavior
12418 : {
12419 36 : AlterDomainStmt *n = makeNode(AlterDomainStmt);
12420 :
12421 36 : n->subtype = AD_DropConstraint;
12422 36 : n->typeName = $3;
12423 36 : n->name = $6;
12424 36 : n->behavior = $7;
12425 36 : n->missing_ok = false;
12426 36 : $$ = (Node *) n;
12427 : }
12428 : /* ALTER DOMAIN <domain> DROP CONSTRAINT IF EXISTS <name> [RESTRICT|CASCADE] */
12429 : | ALTER DOMAIN_P any_name DROP CONSTRAINT IF_P EXISTS name opt_drop_behavior
12430 : {
12431 4 : AlterDomainStmt *n = makeNode(AlterDomainStmt);
12432 :
12433 4 : n->subtype = AD_DropConstraint;
12434 4 : n->typeName = $3;
12435 4 : n->name = $8;
12436 4 : n->behavior = $9;
12437 4 : n->missing_ok = true;
12438 4 : $$ = (Node *) n;
12439 : }
12440 : /* ALTER DOMAIN <domain> VALIDATE CONSTRAINT <name> */
12441 : | ALTER DOMAIN_P any_name VALIDATE CONSTRAINT name
12442 : {
12443 8 : AlterDomainStmt *n = makeNode(AlterDomainStmt);
12444 :
12445 8 : n->subtype = AD_ValidateConstraint;
12446 8 : n->typeName = $3;
12447 8 : n->name = $6;
12448 8 : $$ = (Node *) n;
12449 : }
12450 : ;
12451 :
12452 : opt_as: AS
12453 : | /* EMPTY */
12454 : ;
12455 :
12456 :
12457 : /*****************************************************************************
12458 : *
12459 : * Manipulate a text search dictionary or configuration
12460 : *
12461 : *****************************************************************************/
12462 :
12463 : AlterTSDictionaryStmt:
12464 : ALTER TEXT_P SEARCH DICTIONARY any_name definition
12465 : {
12466 23 : AlterTSDictionaryStmt *n = makeNode(AlterTSDictionaryStmt);
12467 :
12468 23 : n->dictname = $5;
12469 23 : n->options = $6;
12470 23 : $$ = (Node *) n;
12471 : }
12472 : ;
12473 :
12474 : AlterTSConfigurationStmt:
12475 : ALTER TEXT_P SEARCH CONFIGURATION any_name ADD_P MAPPING FOR name_list any_with any_name_list
12476 : {
12477 5200 : AlterTSConfigurationStmt *n = makeNode(AlterTSConfigurationStmt);
12478 :
12479 5200 : n->kind = ALTER_TSCONFIG_ADD_MAPPING;
12480 5200 : n->cfgname = $5;
12481 5200 : n->tokentype = $9;
12482 5200 : n->dicts = $11;
12483 5200 : n->override = false;
12484 5200 : n->replace = false;
12485 5200 : $$ = (Node *) n;
12486 : }
12487 : | ALTER TEXT_P SEARCH CONFIGURATION any_name ALTER MAPPING FOR name_list any_with any_name_list
12488 : {
12489 17 : AlterTSConfigurationStmt *n = makeNode(AlterTSConfigurationStmt);
12490 :
12491 17 : n->kind = ALTER_TSCONFIG_ALTER_MAPPING_FOR_TOKEN;
12492 17 : n->cfgname = $5;
12493 17 : n->tokentype = $9;
12494 17 : n->dicts = $11;
12495 17 : n->override = true;
12496 17 : n->replace = false;
12497 17 : $$ = (Node *) n;
12498 : }
12499 : | ALTER TEXT_P SEARCH CONFIGURATION any_name ALTER MAPPING REPLACE any_name any_with any_name
12500 : {
12501 12 : AlterTSConfigurationStmt *n = makeNode(AlterTSConfigurationStmt);
12502 :
12503 12 : n->kind = ALTER_TSCONFIG_REPLACE_DICT;
12504 12 : n->cfgname = $5;
12505 12 : n->tokentype = NIL;
12506 12 : n->dicts = list_make2($9,$11);
12507 12 : n->override = false;
12508 12 : n->replace = true;
12509 12 : $$ = (Node *) n;
12510 : }
12511 : | ALTER TEXT_P SEARCH CONFIGURATION any_name ALTER MAPPING FOR name_list REPLACE any_name any_with any_name
12512 : {
12513 0 : AlterTSConfigurationStmt *n = makeNode(AlterTSConfigurationStmt);
12514 :
12515 0 : n->kind = ALTER_TSCONFIG_REPLACE_DICT_FOR_TOKEN;
12516 0 : n->cfgname = $5;
12517 0 : n->tokentype = $9;
12518 0 : n->dicts = list_make2($11,$13);
12519 0 : n->override = false;
12520 0 : n->replace = true;
12521 0 : $$ = (Node *) n;
12522 : }
12523 : | ALTER TEXT_P SEARCH CONFIGURATION any_name DROP MAPPING FOR name_list
12524 : {
12525 13 : AlterTSConfigurationStmt *n = makeNode(AlterTSConfigurationStmt);
12526 :
12527 13 : n->kind = ALTER_TSCONFIG_DROP_MAPPING;
12528 13 : n->cfgname = $5;
12529 13 : n->tokentype = $9;
12530 13 : n->missing_ok = false;
12531 13 : $$ = (Node *) n;
12532 : }
12533 : | ALTER TEXT_P SEARCH CONFIGURATION any_name DROP MAPPING IF_P EXISTS FOR name_list
12534 : {
12535 8 : AlterTSConfigurationStmt *n = makeNode(AlterTSConfigurationStmt);
12536 :
12537 8 : n->kind = ALTER_TSCONFIG_DROP_MAPPING;
12538 8 : n->cfgname = $5;
12539 8 : n->tokentype = $11;
12540 8 : n->missing_ok = true;
12541 8 : $$ = (Node *) n;
12542 : }
12543 : ;
12544 :
12545 : /* Use this if TIME or ORDINALITY after WITH should be taken as an identifier */
12546 : any_with: WITH
12547 : | WITH_LA
12548 : ;
12549 :
12550 :
12551 : /*****************************************************************************
12552 : *
12553 : * Manipulate a conversion
12554 : *
12555 : * CREATE [DEFAULT] CONVERSION <conversion_name>
12556 : * FOR <encoding_name> TO <encoding_name> FROM <func_name>
12557 : *
12558 : *****************************************************************************/
12559 :
12560 : CreateConversionStmt:
12561 : CREATE opt_default CONVERSION_P any_name FOR Sconst
12562 : TO Sconst FROM any_name
12563 : {
12564 42 : CreateConversionStmt *n = makeNode(CreateConversionStmt);
12565 :
12566 42 : n->conversion_name = $4;
12567 42 : n->for_encoding_name = $6;
12568 42 : n->to_encoding_name = $8;
12569 42 : n->func_name = $10;
12570 42 : n->def = $2;
12571 42 : $$ = (Node *) n;
12572 : }
12573 : ;
12574 :
12575 : /*****************************************************************************
12576 : *
12577 : * QUERY:
12578 : * REPACK [ (options) ] [ <qualified_name> [ <name_list> ] [ USING INDEX <index_name> ] ]
12579 : *
12580 : * obsolete variants:
12581 : * CLUSTER (options) [ <qualified_name> [ USING <index_name> ] ]
12582 : * CLUSTER [VERBOSE] [ <qualified_name> [ USING <index_name> ] ]
12583 : * CLUSTER [VERBOSE] <index_name> ON <qualified_name> (for pre-8.3)
12584 : *
12585 : *****************************************************************************/
12586 :
12587 : RepackStmt:
12588 : REPACK opt_utility_option_list vacuum_relation USING INDEX name
12589 : {
12590 9 : RepackStmt *n = makeNode(RepackStmt);
12591 :
12592 9 : n->command = REPACK_COMMAND_REPACK;
12593 9 : n->relation = (VacuumRelation *) $3;
12594 9 : n->indexname = $6;
12595 9 : n->usingindex = true;
12596 9 : n->params = $2;
12597 9 : $$ = (Node *) n;
12598 : }
12599 : | REPACK opt_utility_option_list vacuum_relation opt_usingindex
12600 : {
12601 29 : RepackStmt *n = makeNode(RepackStmt);
12602 :
12603 29 : n->command = REPACK_COMMAND_REPACK;
12604 29 : n->relation = (VacuumRelation *) $3;
12605 29 : n->indexname = NULL;
12606 29 : n->usingindex = $4;
12607 29 : n->params = $2;
12608 29 : $$ = (Node *) n;
12609 : }
12610 : | REPACK opt_utility_option_list opt_usingindex
12611 : {
12612 4 : RepackStmt *n = makeNode(RepackStmt);
12613 :
12614 4 : n->command = REPACK_COMMAND_REPACK;
12615 4 : n->relation = NULL;
12616 4 : n->indexname = NULL;
12617 4 : n->usingindex = $3;
12618 4 : n->params = $2;
12619 4 : $$ = (Node *) n;
12620 : }
12621 : | CLUSTER '(' utility_option_list ')' qualified_name cluster_index_specification
12622 : {
12623 0 : RepackStmt *n = makeNode(RepackStmt);
12624 :
12625 0 : n->command = REPACK_COMMAND_CLUSTER;
12626 0 : n->relation = makeNode(VacuumRelation);
12627 0 : n->relation->relation = $5;
12628 0 : n->indexname = $6;
12629 0 : n->usingindex = true;
12630 0 : n->params = $3;
12631 0 : $$ = (Node *) n;
12632 : }
12633 : | CLUSTER opt_utility_option_list
12634 : {
12635 9 : RepackStmt *n = makeNode(RepackStmt);
12636 :
12637 9 : n->command = REPACK_COMMAND_CLUSTER;
12638 9 : n->relation = NULL;
12639 9 : n->indexname = NULL;
12640 9 : n->usingindex = true;
12641 9 : n->params = $2;
12642 9 : $$ = (Node *) n;
12643 : }
12644 : /* unparenthesized VERBOSE kept for pre-14 compatibility */
12645 : | CLUSTER opt_verbose qualified_name cluster_index_specification
12646 : {
12647 121 : RepackStmt *n = makeNode(RepackStmt);
12648 :
12649 121 : n->command = REPACK_COMMAND_CLUSTER;
12650 121 : n->relation = makeNode(VacuumRelation);
12651 121 : n->relation->relation = $3;
12652 121 : n->indexname = $4;
12653 121 : n->usingindex = true;
12654 121 : if ($2)
12655 0 : n->params = list_make1(makeDefElem("verbose", NULL, @2));
12656 121 : $$ = (Node *) n;
12657 : }
12658 : /* unparenthesized VERBOSE kept for pre-17 compatibility */
12659 : | CLUSTER VERBOSE
12660 : {
12661 5 : RepackStmt *n = makeNode(RepackStmt);
12662 :
12663 5 : n->command = REPACK_COMMAND_CLUSTER;
12664 5 : n->relation = NULL;
12665 5 : n->indexname = NULL;
12666 5 : n->usingindex = true;
12667 5 : n->params = list_make1(makeDefElem("verbose", NULL, @2));
12668 5 : $$ = (Node *) n;
12669 : }
12670 : /* kept for pre-8.3 compatibility */
12671 : | CLUSTER opt_verbose name ON qualified_name
12672 : {
12673 13 : RepackStmt *n = makeNode(RepackStmt);
12674 :
12675 13 : n->command = REPACK_COMMAND_CLUSTER;
12676 13 : n->relation = makeNode(VacuumRelation);
12677 13 : n->relation->relation = $5;
12678 13 : n->indexname = $3;
12679 13 : n->usingindex = true;
12680 13 : if ($2)
12681 0 : n->params = list_make1(makeDefElem("verbose", NULL, @2));
12682 13 : $$ = (Node *) n;
12683 : }
12684 : ;
12685 :
12686 : cluster_index_specification:
12687 99 : USING name { $$ = $2; }
12688 22 : | /*EMPTY*/ { $$ = NULL; }
12689 : ;
12690 :
12691 :
12692 : /*****************************************************************************
12693 : *
12694 : * QUERY:
12695 : * VACUUM
12696 : * ANALYZE
12697 : *
12698 : *****************************************************************************/
12699 :
12700 : VacuumStmt: VACUUM opt_full opt_freeze opt_verbose opt_analyze opt_vacuum_relation_list
12701 : {
12702 774 : VacuumStmt *n = makeNode(VacuumStmt);
12703 :
12704 774 : n->options = NIL;
12705 774 : if ($2)
12706 89 : n->options = lappend(n->options,
12707 89 : makeDefElem("full", NULL, @2));
12708 774 : if ($3)
12709 90 : n->options = lappend(n->options,
12710 90 : makeDefElem("freeze", NULL, @3));
12711 774 : if ($4)
12712 9 : n->options = lappend(n->options,
12713 9 : makeDefElem("verbose", NULL, @4));
12714 774 : if ($5)
12715 209 : n->options = lappend(n->options,
12716 209 : makeDefElem("analyze", NULL, @5));
12717 774 : n->rels = $6;
12718 774 : n->is_vacuumcmd = true;
12719 774 : $$ = (Node *) n;
12720 : }
12721 : | VACUUM '(' utility_option_list ')' opt_vacuum_relation_list
12722 : {
12723 5030 : VacuumStmt *n = makeNode(VacuumStmt);
12724 :
12725 5030 : n->options = $3;
12726 5030 : n->rels = $5;
12727 5030 : n->is_vacuumcmd = true;
12728 5030 : $$ = (Node *) n;
12729 : }
12730 : ;
12731 :
12732 : AnalyzeStmt: analyze_keyword opt_utility_option_list opt_vacuum_relation_list
12733 : {
12734 2899 : VacuumStmt *n = makeNode(VacuumStmt);
12735 :
12736 2899 : n->options = $2;
12737 2899 : n->rels = $3;
12738 2899 : n->is_vacuumcmd = false;
12739 2899 : $$ = (Node *) n;
12740 : }
12741 : | analyze_keyword VERBOSE opt_vacuum_relation_list
12742 : {
12743 0 : VacuumStmt *n = makeNode(VacuumStmt);
12744 :
12745 0 : n->options = list_make1(makeDefElem("verbose", NULL, @2));
12746 0 : n->rels = $3;
12747 0 : n->is_vacuumcmd = false;
12748 0 : $$ = (Node *) n;
12749 : }
12750 : ;
12751 :
12752 : analyze_keyword:
12753 : ANALYZE
12754 : | ANALYSE /* British */
12755 : ;
12756 :
12757 : opt_analyze:
12758 209 : analyze_keyword { $$ = true; }
12759 565 : | /*EMPTY*/ { $$ = false; }
12760 : ;
12761 :
12762 : opt_verbose:
12763 9 : VERBOSE { $$ = true; }
12764 2475 : | /*EMPTY*/ { $$ = false; }
12765 : ;
12766 :
12767 89 : opt_full: FULL { $$ = true; }
12768 685 : | /*EMPTY*/ { $$ = false; }
12769 : ;
12770 :
12771 90 : opt_freeze: FREEZE { $$ = true; }
12772 684 : | /*EMPTY*/ { $$ = false; }
12773 : ;
12774 :
12775 : opt_name_list:
12776 1791 : '(' name_list ')' { $$ = $2; }
12777 10501 : | /*EMPTY*/ { $$ = NIL; }
12778 : ;
12779 :
12780 : vacuum_relation:
12781 : relation_expr opt_name_list
12782 : {
12783 8654 : $$ = (Node *) makeVacuumRelation($1, InvalidOid, $2);
12784 : }
12785 : ;
12786 :
12787 : vacuum_relation_list:
12788 : vacuum_relation
12789 8495 : { $$ = list_make1($1); }
12790 : | vacuum_relation_list ',' vacuum_relation
12791 121 : { $$ = lappend($1, $3); }
12792 : ;
12793 :
12794 : opt_vacuum_relation_list:
12795 8495 : vacuum_relation_list { $$ = $1; }
12796 208 : | /*EMPTY*/ { $$ = NIL; }
12797 : ;
12798 :
12799 :
12800 : /*****************************************************************************
12801 : *
12802 : * QUERY:
12803 : * EXPLAIN [ANALYZE] [VERBOSE] query
12804 : * EXPLAIN ( options ) query
12805 : *
12806 : *****************************************************************************/
12807 :
12808 : ExplainStmt:
12809 : EXPLAIN ExplainableStmt
12810 : {
12811 4751 : ExplainStmt *n = makeNode(ExplainStmt);
12812 :
12813 4751 : n->query = $2;
12814 4751 : n->options = NIL;
12815 4751 : $$ = (Node *) n;
12816 : }
12817 : | EXPLAIN analyze_keyword opt_verbose ExplainableStmt
12818 : {
12819 1576 : ExplainStmt *n = makeNode(ExplainStmt);
12820 :
12821 1576 : n->query = $4;
12822 1576 : n->options = list_make1(makeDefElem("analyze", NULL, @2));
12823 1576 : if ($3)
12824 0 : n->options = lappend(n->options,
12825 0 : makeDefElem("verbose", NULL, @3));
12826 1576 : $$ = (Node *) n;
12827 : }
12828 : | EXPLAIN VERBOSE ExplainableStmt
12829 : {
12830 8 : ExplainStmt *n = makeNode(ExplainStmt);
12831 :
12832 8 : n->query = $3;
12833 8 : n->options = list_make1(makeDefElem("verbose", NULL, @2));
12834 8 : $$ = (Node *) n;
12835 : }
12836 : | EXPLAIN '(' utility_option_list ')' ExplainableStmt
12837 : {
12838 10019 : ExplainStmt *n = makeNode(ExplainStmt);
12839 :
12840 10019 : n->query = $5;
12841 10019 : n->options = $3;
12842 10019 : $$ = (Node *) n;
12843 : }
12844 : ;
12845 :
12846 : ExplainableStmt:
12847 : SelectStmt
12848 : | InsertStmt
12849 : | UpdateStmt
12850 : | DeleteStmt
12851 : | MergeStmt
12852 : | DeclareCursorStmt
12853 : | CreateAsStmt
12854 : | CreateMatViewStmt
12855 : | RefreshMatViewStmt
12856 : | ExecuteStmt /* by default all are $$=$1 */
12857 : ;
12858 :
12859 : /*****************************************************************************
12860 : *
12861 : * QUERY:
12862 : * PREPARE <plan_name> [(args, ...)] AS <query>
12863 : *
12864 : *****************************************************************************/
12865 :
12866 : PrepareStmt: PREPARE name prep_type_clause AS PreparableStmt
12867 : {
12868 1185 : PrepareStmt *n = makeNode(PrepareStmt);
12869 :
12870 1185 : n->name = $2;
12871 1185 : n->argtypes = $3;
12872 1185 : n->query = $5;
12873 1185 : $$ = (Node *) n;
12874 : }
12875 : ;
12876 :
12877 960 : prep_type_clause: '(' type_list ')' { $$ = $2; }
12878 237 : | /* EMPTY */ { $$ = NIL; }
12879 : ;
12880 :
12881 : PreparableStmt:
12882 : SelectStmt
12883 : | InsertStmt
12884 : | UpdateStmt
12885 : | DeleteStmt
12886 : | MergeStmt /* by default all are $$=$1 */
12887 : ;
12888 :
12889 : /*****************************************************************************
12890 : *
12891 : * EXECUTE <plan_name> [(params, ...)]
12892 : * CREATE TABLE <name> AS EXECUTE <plan_name> [(params, ...)]
12893 : *
12894 : *****************************************************************************/
12895 :
12896 : ExecuteStmt: EXECUTE name execute_param_clause
12897 : {
12898 8927 : ExecuteStmt *n = makeNode(ExecuteStmt);
12899 :
12900 8927 : n->name = $2;
12901 8927 : n->params = $3;
12902 8927 : $$ = (Node *) n;
12903 : }
12904 : | CREATE OptTemp TABLE create_as_target AS
12905 : EXECUTE name execute_param_clause opt_with_data
12906 : {
12907 50 : CreateTableAsStmt *ctas = makeNode(CreateTableAsStmt);
12908 50 : ExecuteStmt *n = makeNode(ExecuteStmt);
12909 :
12910 50 : n->name = $7;
12911 50 : n->params = $8;
12912 50 : ctas->query = (Node *) n;
12913 50 : ctas->into = $4;
12914 50 : ctas->objtype = OBJECT_TABLE;
12915 50 : ctas->is_select_into = false;
12916 50 : ctas->if_not_exists = false;
12917 : /* cram additional flags into the IntoClause */
12918 50 : $4->rel->relpersistence = $2;
12919 50 : $4->skipData = !($9);
12920 50 : $$ = (Node *) ctas;
12921 : }
12922 : | CREATE OptTemp TABLE IF_P NOT EXISTS create_as_target AS
12923 : EXECUTE name execute_param_clause opt_with_data
12924 : {
12925 8 : CreateTableAsStmt *ctas = makeNode(CreateTableAsStmt);
12926 8 : ExecuteStmt *n = makeNode(ExecuteStmt);
12927 :
12928 8 : n->name = $10;
12929 8 : n->params = $11;
12930 8 : ctas->query = (Node *) n;
12931 8 : ctas->into = $7;
12932 8 : ctas->objtype = OBJECT_TABLE;
12933 8 : ctas->is_select_into = false;
12934 8 : ctas->if_not_exists = true;
12935 : /* cram additional flags into the IntoClause */
12936 8 : $7->rel->relpersistence = $2;
12937 8 : $7->skipData = !($12);
12938 8 : $$ = (Node *) ctas;
12939 : }
12940 : ;
12941 :
12942 8053 : execute_param_clause: '(' expr_list ')' { $$ = $2; }
12943 932 : | /* EMPTY */ { $$ = NIL; }
12944 : ;
12945 :
12946 : /*****************************************************************************
12947 : *
12948 : * QUERY:
12949 : * DEALLOCATE [PREPARE] <plan_name>
12950 : *
12951 : *****************************************************************************/
12952 :
12953 : DeallocateStmt: DEALLOCATE name
12954 : {
12955 2043 : DeallocateStmt *n = makeNode(DeallocateStmt);
12956 :
12957 2043 : n->name = $2;
12958 2043 : n->isall = false;
12959 2043 : n->location = @2;
12960 2043 : $$ = (Node *) n;
12961 : }
12962 : | DEALLOCATE PREPARE name
12963 : {
12964 13 : DeallocateStmt *n = makeNode(DeallocateStmt);
12965 :
12966 13 : n->name = $3;
12967 13 : n->isall = false;
12968 13 : n->location = @3;
12969 13 : $$ = (Node *) n;
12970 : }
12971 : | DEALLOCATE ALL
12972 : {
12973 36 : DeallocateStmt *n = makeNode(DeallocateStmt);
12974 :
12975 36 : n->name = NULL;
12976 36 : n->isall = true;
12977 36 : n->location = -1;
12978 36 : $$ = (Node *) n;
12979 : }
12980 : | DEALLOCATE PREPARE ALL
12981 : {
12982 1 : DeallocateStmt *n = makeNode(DeallocateStmt);
12983 :
12984 1 : n->name = NULL;
12985 1 : n->isall = true;
12986 1 : n->location = -1;
12987 1 : $$ = (Node *) n;
12988 : }
12989 : ;
12990 :
12991 : /*****************************************************************************
12992 : *
12993 : * QUERY:
12994 : * INSERT STATEMENTS
12995 : *
12996 : *****************************************************************************/
12997 :
12998 : InsertStmt:
12999 : opt_with_clause INSERT INTO insert_target insert_rest
13000 : opt_on_conflict returning_clause
13001 : {
13002 42195 : $5->relation = $4;
13003 42195 : $5->onConflictClause = $6;
13004 42195 : $5->returningClause = $7;
13005 42195 : $5->withClause = $1;
13006 42195 : $$ = (Node *) $5;
13007 : }
13008 : ;
13009 :
13010 : /*
13011 : * Can't easily make AS optional here, because VALUES in insert_rest would
13012 : * have a shift/reduce conflict with VALUES as an optional alias. We could
13013 : * easily allow unreserved_keywords as optional aliases, but that'd be an odd
13014 : * divergence from other places. So just require AS for now.
13015 : */
13016 : insert_target:
13017 : qualified_name
13018 : {
13019 42088 : $$ = $1;
13020 : }
13021 : | qualified_name AS ColId
13022 : {
13023 111 : $1->alias = makeAlias($3, NIL);
13024 111 : $$ = $1;
13025 : }
13026 : ;
13027 :
13028 : insert_rest:
13029 : SelectStmt
13030 : {
13031 27653 : $$ = makeNode(InsertStmt);
13032 27653 : $$->cols = NIL;
13033 27653 : $$->selectStmt = $1;
13034 : }
13035 : | OVERRIDING override_kind VALUE_P SelectStmt
13036 : {
13037 64 : $$ = makeNode(InsertStmt);
13038 64 : $$->cols = NIL;
13039 64 : $$->override = $2;
13040 64 : $$->selectStmt = $4;
13041 : }
13042 : | '(' insert_column_list ')' SelectStmt
13043 : {
13044 8933 : $$ = makeNode(InsertStmt);
13045 8933 : $$->cols = $2;
13046 8933 : $$->selectStmt = $4;
13047 : }
13048 : | '(' insert_column_list ')' OVERRIDING override_kind VALUE_P SelectStmt
13049 : {
13050 0 : $$ = makeNode(InsertStmt);
13051 0 : $$->cols = $2;
13052 0 : $$->override = $5;
13053 0 : $$->selectStmt = $7;
13054 : }
13055 : | DEFAULT VALUES
13056 : {
13057 5549 : $$ = makeNode(InsertStmt);
13058 5549 : $$->cols = NIL;
13059 5549 : $$->selectStmt = NULL;
13060 : }
13061 : ;
13062 :
13063 : override_kind:
13064 44 : USER { $$ = OVERRIDING_USER_VALUE; }
13065 40 : | SYSTEM_P { $$ = OVERRIDING_SYSTEM_VALUE; }
13066 : ;
13067 :
13068 : insert_column_list:
13069 : insert_column_item
13070 9152 : { $$ = list_make1($1); }
13071 : | insert_column_list ',' insert_column_item
13072 9915 : { $$ = lappend($1, $3); }
13073 : ;
13074 :
13075 : insert_column_item:
13076 : ColId opt_indirection
13077 : {
13078 19067 : $$ = makeNode(ResTarget);
13079 19067 : $$->name = $1;
13080 19067 : $$->indirection = check_indirection($2, yyscanner);
13081 19067 : $$->val = NULL;
13082 19067 : $$->location = @1;
13083 : }
13084 : ;
13085 :
13086 : opt_on_conflict:
13087 : ON CONFLICT opt_conf_expr DO SELECT opt_for_locking_strength where_clause
13088 : {
13089 240 : $$ = makeNode(OnConflictClause);
13090 240 : $$->action = ONCONFLICT_SELECT;
13091 240 : $$->infer = $3;
13092 240 : $$->targetList = NIL;
13093 240 : $$->lockStrength = $6;
13094 240 : $$->whereClause = $7;
13095 240 : $$->location = @1;
13096 : }
13097 : |
13098 : ON CONFLICT opt_conf_expr DO UPDATE SET set_clause_list where_clause
13099 : {
13100 913 : $$ = makeNode(OnConflictClause);
13101 913 : $$->action = ONCONFLICT_UPDATE;
13102 913 : $$->infer = $3;
13103 913 : $$->targetList = $7;
13104 913 : $$->lockStrength = LCS_NONE;
13105 913 : $$->whereClause = $8;
13106 913 : $$->location = @1;
13107 : }
13108 : |
13109 : ON CONFLICT opt_conf_expr DO NOTHING
13110 : {
13111 386 : $$ = makeNode(OnConflictClause);
13112 386 : $$->action = ONCONFLICT_NOTHING;
13113 386 : $$->infer = $3;
13114 386 : $$->targetList = NIL;
13115 386 : $$->lockStrength = LCS_NONE;
13116 386 : $$->whereClause = NULL;
13117 386 : $$->location = @1;
13118 : }
13119 : | /*EMPTY*/
13120 : {
13121 40660 : $$ = NULL;
13122 : }
13123 : ;
13124 :
13125 : opt_conf_expr:
13126 : '(' index_params ')' where_clause
13127 : {
13128 1249 : $$ = makeNode(InferClause);
13129 1249 : $$->indexElems = $2;
13130 1249 : $$->whereClause = $4;
13131 1249 : $$->conname = NULL;
13132 1249 : $$->location = @1;
13133 : }
13134 : |
13135 : ON CONSTRAINT name
13136 : {
13137 138 : $$ = makeNode(InferClause);
13138 138 : $$->indexElems = NIL;
13139 138 : $$->whereClause = NULL;
13140 138 : $$->conname = $3;
13141 138 : $$->location = @1;
13142 : }
13143 : | /*EMPTY*/
13144 : {
13145 152 : $$ = NULL;
13146 : }
13147 : ;
13148 :
13149 : returning_clause:
13150 : RETURNING returning_with_clause target_list
13151 : {
13152 2336 : ReturningClause *n = makeNode(ReturningClause);
13153 :
13154 2336 : n->options = $2;
13155 2336 : n->exprs = $3;
13156 2336 : $$ = n;
13157 : }
13158 : | /* EMPTY */
13159 : {
13160 54038 : $$ = NULL;
13161 : }
13162 : ;
13163 :
13164 : returning_with_clause:
13165 48 : WITH '(' returning_options ')' { $$ = $3; }
13166 2288 : | /* EMPTY */ { $$ = NIL; }
13167 : ;
13168 :
13169 : returning_options:
13170 48 : returning_option { $$ = list_make1($1); }
13171 36 : | returning_options ',' returning_option { $$ = lappend($1, $3); }
13172 : ;
13173 :
13174 : returning_option:
13175 : returning_option_kind AS ColId
13176 : {
13177 84 : ReturningOption *n = makeNode(ReturningOption);
13178 :
13179 84 : n->option = $1;
13180 84 : n->value = $3;
13181 84 : n->location = @1;
13182 84 : $$ = (Node *) n;
13183 : }
13184 : ;
13185 :
13186 : returning_option_kind:
13187 36 : OLD { $$ = RETURNING_OPTION_OLD; }
13188 48 : | NEW { $$ = RETURNING_OPTION_NEW; }
13189 : ;
13190 :
13191 :
13192 : /*****************************************************************************
13193 : *
13194 : * QUERY:
13195 : * DELETE STATEMENTS
13196 : *
13197 : *****************************************************************************/
13198 :
13199 : DeleteStmt: opt_with_clause DELETE_P FROM relation_expr_opt_alias
13200 : using_clause where_or_current_clause returning_clause
13201 : {
13202 2978 : DeleteStmt *n = makeNode(DeleteStmt);
13203 :
13204 2978 : n->relation = $4;
13205 2978 : n->usingClause = $5;
13206 2978 : n->whereClause = $6;
13207 2978 : n->returningClause = $7;
13208 2978 : n->withClause = $1;
13209 2978 : $$ = (Node *) n;
13210 : }
13211 : | opt_with_clause DELETE_P FROM relation_expr
13212 : for_portion_of_clause for_portion_of_opt_alias
13213 : using_clause where_or_current_clause returning_clause
13214 : {
13215 425 : DeleteStmt *n = makeNode(DeleteStmt);
13216 :
13217 425 : n->relation = $4;
13218 425 : n->forPortionOf = (ForPortionOfClause *) $5;
13219 425 : n->relation->alias = $6;
13220 425 : n->usingClause = $7;
13221 425 : n->whereClause = $8;
13222 425 : n->returningClause = $9;
13223 425 : n->withClause = $1;
13224 425 : $$ = (Node *) n;
13225 : }
13226 : ;
13227 :
13228 : using_clause:
13229 72 : USING from_list { $$ = $2; }
13230 3331 : | /*EMPTY*/ { $$ = NIL; }
13231 : ;
13232 :
13233 :
13234 : /*****************************************************************************
13235 : *
13236 : * QUERY:
13237 : * LOCK TABLE
13238 : *
13239 : *****************************************************************************/
13240 :
13241 : LockStmt: LOCK_P opt_table relation_expr_list opt_lock opt_nowait
13242 : {
13243 645 : LockStmt *n = makeNode(LockStmt);
13244 :
13245 645 : n->relations = $3;
13246 645 : n->mode = $4;
13247 645 : n->nowait = $5;
13248 645 : $$ = (Node *) n;
13249 : }
13250 : ;
13251 :
13252 577 : opt_lock: IN_P lock_type MODE { $$ = $2; }
13253 68 : | /*EMPTY*/ { $$ = AccessExclusiveLock; }
13254 : ;
13255 :
13256 288 : lock_type: ACCESS SHARE { $$ = AccessShareLock; }
13257 9 : | ROW SHARE { $$ = RowShareLock; }
13258 52 : | ROW EXCLUSIVE { $$ = RowExclusiveLock; }
13259 35 : | SHARE UPDATE EXCLUSIVE { $$ = ShareUpdateExclusiveLock; }
13260 42 : | SHARE { $$ = ShareLock; }
13261 9 : | SHARE ROW EXCLUSIVE { $$ = ShareRowExclusiveLock; }
13262 63 : | EXCLUSIVE { $$ = ExclusiveLock; }
13263 79 : | ACCESS EXCLUSIVE { $$ = AccessExclusiveLock; }
13264 : ;
13265 :
13266 102 : opt_nowait: NOWAIT { $$ = true; }
13267 558 : | /*EMPTY*/ { $$ = false; }
13268 : ;
13269 :
13270 : opt_nowait_or_skip:
13271 29 : NOWAIT { $$ = LockWaitError; }
13272 96 : | SKIP LOCKED { $$ = LockWaitSkip; }
13273 4903 : | /*EMPTY*/ { $$ = LockWaitBlock; }
13274 : ;
13275 :
13276 :
13277 : /*****************************************************************************
13278 : *
13279 : * QUERY:
13280 : * UpdateStmt (UPDATE)
13281 : *
13282 : *****************************************************************************/
13283 :
13284 : UpdateStmt: opt_with_clause UPDATE relation_expr_opt_alias
13285 : SET set_clause_list
13286 : from_clause
13287 : where_or_current_clause
13288 : returning_clause
13289 : {
13290 8814 : UpdateStmt *n = makeNode(UpdateStmt);
13291 :
13292 8814 : n->relation = $3;
13293 8814 : n->targetList = $5;
13294 8814 : n->fromClause = $6;
13295 8814 : n->whereClause = $7;
13296 8814 : n->returningClause = $8;
13297 8814 : n->withClause = $1;
13298 8814 : $$ = (Node *) n;
13299 : }
13300 : | opt_with_clause UPDATE relation_expr
13301 : for_portion_of_clause for_portion_of_opt_alias
13302 : SET set_clause_list
13303 : from_clause
13304 : where_or_current_clause
13305 : returning_clause
13306 : {
13307 540 : UpdateStmt *n = makeNode(UpdateStmt);
13308 :
13309 540 : n->relation = $3;
13310 540 : n->forPortionOf = (ForPortionOfClause *) $4;
13311 540 : n->relation->alias = $5;
13312 540 : n->targetList = $7;
13313 540 : n->fromClause = $8;
13314 540 : n->whereClause = $9;
13315 540 : n->returningClause = $10;
13316 540 : n->withClause = $1;
13317 540 : $$ = (Node *) n;
13318 : }
13319 : ;
13320 :
13321 : set_clause_list:
13322 11313 : set_clause { $$ = $1; }
13323 2527 : | set_clause_list ',' set_clause { $$ = list_concat($1,$3); }
13324 : ;
13325 :
13326 : set_clause:
13327 : set_target '=' a_expr
13328 : {
13329 13719 : $1->val = (Node *) $3;
13330 13719 : $$ = list_make1($1);
13331 : }
13332 : | '(' set_target_list ')' '=' a_expr
13333 : {
13334 121 : int ncolumns = list_length($2);
13335 121 : int i = 1;
13336 : ListCell *col_cell;
13337 :
13338 : /* Create a MultiAssignRef source for each target */
13339 374 : foreach(col_cell, $2)
13340 : {
13341 253 : ResTarget *res_col = (ResTarget *) lfirst(col_cell);
13342 253 : MultiAssignRef *r = makeNode(MultiAssignRef);
13343 :
13344 253 : r->source = (Node *) $5;
13345 253 : r->colno = i;
13346 253 : r->ncolumns = ncolumns;
13347 253 : res_col->val = (Node *) r;
13348 253 : i++;
13349 : }
13350 :
13351 121 : $$ = $2;
13352 : }
13353 : ;
13354 :
13355 : set_target:
13356 : ColId opt_indirection
13357 : {
13358 13976 : $$ = makeNode(ResTarget);
13359 13976 : $$->name = $1;
13360 13976 : $$->indirection = check_indirection($2, yyscanner);
13361 13976 : $$->val = NULL; /* upper production sets this */
13362 13976 : $$->location = @1;
13363 : }
13364 : ;
13365 :
13366 : set_target_list:
13367 125 : set_target { $$ = list_make1($1); }
13368 132 : | set_target_list ',' set_target { $$ = lappend($1,$3); }
13369 : ;
13370 :
13371 :
13372 : /*****************************************************************************
13373 : *
13374 : * QUERY:
13375 : * MERGE
13376 : *
13377 : *****************************************************************************/
13378 :
13379 : MergeStmt:
13380 : opt_with_clause MERGE INTO relation_expr_opt_alias
13381 : USING table_ref
13382 : ON a_expr
13383 : merge_when_list
13384 : returning_clause
13385 : {
13386 1422 : MergeStmt *m = makeNode(MergeStmt);
13387 :
13388 1422 : m->withClause = $1;
13389 1422 : m->relation = $4;
13390 1422 : m->sourceRelation = $6;
13391 1422 : m->joinCondition = $8;
13392 1422 : m->mergeWhenClauses = $9;
13393 1422 : m->returningClause = $10;
13394 :
13395 1422 : $$ = (Node *) m;
13396 : }
13397 : ;
13398 :
13399 : merge_when_list:
13400 1422 : merge_when_clause { $$ = list_make1($1); }
13401 777 : | merge_when_list merge_when_clause { $$ = lappend($1,$2); }
13402 : ;
13403 :
13404 : /*
13405 : * A WHEN clause may be WHEN MATCHED, WHEN NOT MATCHED BY SOURCE, or WHEN NOT
13406 : * MATCHED [BY TARGET]. The first two cases match target tuples, and support
13407 : * UPDATE/DELETE/DO NOTHING actions. The third case does not match target
13408 : * tuples, and only supports INSERT/DO NOTHING actions.
13409 : */
13410 : merge_when_clause:
13411 : merge_when_tgt_matched opt_merge_when_condition THEN merge_update
13412 : {
13413 1046 : $4->matchKind = $1;
13414 1046 : $4->condition = $2;
13415 :
13416 1046 : $$ = (Node *) $4;
13417 : }
13418 : | merge_when_tgt_matched opt_merge_when_condition THEN merge_delete
13419 : {
13420 358 : $4->matchKind = $1;
13421 358 : $4->condition = $2;
13422 :
13423 358 : $$ = (Node *) $4;
13424 : }
13425 : | merge_when_tgt_not_matched opt_merge_when_condition THEN merge_insert
13426 : {
13427 732 : $4->matchKind = $1;
13428 732 : $4->condition = $2;
13429 :
13430 732 : $$ = (Node *) $4;
13431 : }
13432 : | merge_when_tgt_matched opt_merge_when_condition THEN DO NOTHING
13433 : {
13434 46 : MergeWhenClause *m = makeNode(MergeWhenClause);
13435 :
13436 46 : m->matchKind = $1;
13437 46 : m->commandType = CMD_NOTHING;
13438 46 : m->condition = $2;
13439 :
13440 46 : $$ = (Node *) m;
13441 : }
13442 : | merge_when_tgt_not_matched opt_merge_when_condition THEN DO NOTHING
13443 : {
13444 17 : MergeWhenClause *m = makeNode(MergeWhenClause);
13445 :
13446 17 : m->matchKind = $1;
13447 17 : m->commandType = CMD_NOTHING;
13448 17 : m->condition = $2;
13449 :
13450 17 : $$ = (Node *) m;
13451 : }
13452 : ;
13453 :
13454 : merge_when_tgt_matched:
13455 1340 : WHEN MATCHED { $$ = MERGE_WHEN_MATCHED; }
13456 122 : | WHEN NOT MATCHED BY SOURCE { $$ = MERGE_WHEN_NOT_MATCHED_BY_SOURCE; }
13457 : ;
13458 :
13459 : merge_when_tgt_not_matched:
13460 753 : WHEN NOT MATCHED { $$ = MERGE_WHEN_NOT_MATCHED_BY_TARGET; }
13461 12 : | WHEN NOT MATCHED BY TARGET { $$ = MERGE_WHEN_NOT_MATCHED_BY_TARGET; }
13462 : ;
13463 :
13464 : opt_merge_when_condition:
13465 545 : AND a_expr { $$ = $2; }
13466 1682 : | { $$ = NULL; }
13467 : ;
13468 :
13469 : merge_update:
13470 : UPDATE SET set_clause_list
13471 : {
13472 1046 : MergeWhenClause *n = makeNode(MergeWhenClause);
13473 1046 : n->commandType = CMD_UPDATE;
13474 1046 : n->override = OVERRIDING_NOT_SET;
13475 1046 : n->targetList = $3;
13476 1046 : n->values = NIL;
13477 :
13478 1046 : $$ = n;
13479 : }
13480 : ;
13481 :
13482 : merge_delete:
13483 : DELETE_P
13484 : {
13485 358 : MergeWhenClause *n = makeNode(MergeWhenClause);
13486 358 : n->commandType = CMD_DELETE;
13487 358 : n->override = OVERRIDING_NOT_SET;
13488 358 : n->targetList = NIL;
13489 358 : n->values = NIL;
13490 :
13491 358 : $$ = n;
13492 : }
13493 : ;
13494 :
13495 : merge_insert:
13496 : INSERT merge_values_clause
13497 : {
13498 489 : MergeWhenClause *n = makeNode(MergeWhenClause);
13499 489 : n->commandType = CMD_INSERT;
13500 489 : n->override = OVERRIDING_NOT_SET;
13501 489 : n->targetList = NIL;
13502 489 : n->values = $2;
13503 489 : $$ = n;
13504 : }
13505 : | INSERT OVERRIDING override_kind VALUE_P merge_values_clause
13506 : {
13507 0 : MergeWhenClause *n = makeNode(MergeWhenClause);
13508 0 : n->commandType = CMD_INSERT;
13509 0 : n->override = $3;
13510 0 : n->targetList = NIL;
13511 0 : n->values = $5;
13512 0 : $$ = n;
13513 : }
13514 : | INSERT '(' insert_column_list ')' merge_values_clause
13515 : {
13516 199 : MergeWhenClause *n = makeNode(MergeWhenClause);
13517 199 : n->commandType = CMD_INSERT;
13518 199 : n->override = OVERRIDING_NOT_SET;
13519 199 : n->targetList = $3;
13520 199 : n->values = $5;
13521 199 : $$ = n;
13522 : }
13523 : | INSERT '(' insert_column_list ')' OVERRIDING override_kind VALUE_P merge_values_clause
13524 : {
13525 20 : MergeWhenClause *n = makeNode(MergeWhenClause);
13526 20 : n->commandType = CMD_INSERT;
13527 20 : n->override = $6;
13528 20 : n->targetList = $3;
13529 20 : n->values = $8;
13530 20 : $$ = n;
13531 : }
13532 : | INSERT DEFAULT VALUES
13533 : {
13534 24 : MergeWhenClause *n = makeNode(MergeWhenClause);
13535 24 : n->commandType = CMD_INSERT;
13536 24 : n->override = OVERRIDING_NOT_SET;
13537 24 : n->targetList = NIL;
13538 24 : n->values = NIL;
13539 24 : $$ = n;
13540 : }
13541 : ;
13542 :
13543 : merge_values_clause:
13544 : VALUES '(' expr_list ')'
13545 : {
13546 708 : $$ = $3;
13547 : }
13548 : ;
13549 :
13550 : /*****************************************************************************
13551 : *
13552 : * QUERY:
13553 : * CURSOR STATEMENTS
13554 : *
13555 : *****************************************************************************/
13556 : DeclareCursorStmt: DECLARE cursor_name cursor_options CURSOR opt_hold FOR SelectStmt
13557 : {
13558 2735 : DeclareCursorStmt *n = makeNode(DeclareCursorStmt);
13559 :
13560 2735 : n->portalname = $2;
13561 : /* currently we always set FAST_PLAN option */
13562 2735 : n->options = $3 | $5 | CURSOR_OPT_FAST_PLAN;
13563 2735 : n->query = $7;
13564 2735 : $$ = (Node *) n;
13565 : }
13566 : ;
13567 :
13568 8494 : cursor_name: name { $$ = $1; }
13569 : ;
13570 :
13571 2735 : cursor_options: /*EMPTY*/ { $$ = 0; }
13572 18 : | cursor_options NO SCROLL { $$ = $1 | CURSOR_OPT_NO_SCROLL; }
13573 160 : | cursor_options SCROLL { $$ = $1 | CURSOR_OPT_SCROLL; }
13574 8 : | cursor_options BINARY { $$ = $1 | CURSOR_OPT_BINARY; }
13575 0 : | cursor_options ASENSITIVE { $$ = $1 | CURSOR_OPT_ASENSITIVE; }
13576 4 : | cursor_options INSENSITIVE { $$ = $1 | CURSOR_OPT_INSENSITIVE; }
13577 : ;
13578 :
13579 2668 : opt_hold: /* EMPTY */ { $$ = 0; }
13580 63 : | WITH HOLD { $$ = CURSOR_OPT_HOLD; }
13581 4 : | WITHOUT HOLD { $$ = 0; }
13582 : ;
13583 :
13584 : /*****************************************************************************
13585 : *
13586 : * QUERY:
13587 : * SELECT STATEMENTS
13588 : *
13589 : *****************************************************************************/
13590 :
13591 : /* A complete SELECT statement looks like this.
13592 : *
13593 : * The rule returns either a single SelectStmt node or a tree of them,
13594 : * representing a set-operation tree.
13595 : *
13596 : * There is an ambiguity when a sub-SELECT is within an a_expr and there
13597 : * are excess parentheses: do the parentheses belong to the sub-SELECT or
13598 : * to the surrounding a_expr? We don't really care, but bison wants to know.
13599 : * To resolve the ambiguity, we are careful to define the grammar so that
13600 : * the decision is staved off as long as possible: as long as we can keep
13601 : * absorbing parentheses into the sub-SELECT, we will do so, and only when
13602 : * it's no longer possible to do that will we decide that parens belong to
13603 : * the expression. For example, in "SELECT (((SELECT 2)) + 3)" the extra
13604 : * parentheses are treated as part of the sub-select. The necessity of doing
13605 : * it that way is shown by "SELECT (((SELECT 2)) UNION SELECT 2)". Had we
13606 : * parsed "((SELECT 2))" as an a_expr, it'd be too late to go back to the
13607 : * SELECT viewpoint when we see the UNION.
13608 : *
13609 : * This approach is implemented by defining a nonterminal select_with_parens,
13610 : * which represents a SELECT with at least one outer layer of parentheses,
13611 : * and being careful to use select_with_parens, never '(' SelectStmt ')',
13612 : * in the expression grammar. We will then have shift-reduce conflicts
13613 : * which we can resolve in favor of always treating '(' <select> ')' as
13614 : * a select_with_parens. To resolve the conflicts, the productions that
13615 : * conflict with the select_with_parens productions are manually given
13616 : * precedences lower than the precedence of ')', thereby ensuring that we
13617 : * shift ')' (and then reduce to select_with_parens) rather than trying to
13618 : * reduce the inner <select> nonterminal to something else. We use UMINUS
13619 : * precedence for this, which is a fairly arbitrary choice.
13620 : *
13621 : * To be able to define select_with_parens itself without ambiguity, we need
13622 : * a nonterminal select_no_parens that represents a SELECT structure with no
13623 : * outermost parentheses. This is a little bit tedious, but it works.
13624 : *
13625 : * In non-expression contexts, we use SelectStmt which can represent a SELECT
13626 : * with or without outer parentheses.
13627 : */
13628 :
13629 : SelectStmt: select_no_parens %prec UMINUS
13630 : | select_with_parens %prec UMINUS
13631 : ;
13632 :
13633 : select_with_parens:
13634 48035 : '(' select_no_parens ')' { $$ = $2; }
13635 104 : | '(' select_with_parens ')' { $$ = $2; }
13636 : ;
13637 :
13638 : /*
13639 : * This rule parses the equivalent of the standard's <query expression>.
13640 : * The duplicative productions are annoying, but hard to get rid of without
13641 : * creating shift/reduce conflicts.
13642 : *
13643 : * The locking clause (FOR UPDATE etc) may be before or after LIMIT/OFFSET.
13644 : * In <=7.2.X, LIMIT/OFFSET had to be after FOR UPDATE
13645 : * We now support both orderings, but prefer LIMIT/OFFSET before the locking
13646 : * clause.
13647 : * 2002-08-28 bjm
13648 : */
13649 : select_no_parens:
13650 255500 : simple_select { $$ = $1; }
13651 : | select_clause sort_clause
13652 : {
13653 49859 : insertSelectOptions((SelectStmt *) $1, $2, NIL,
13654 : NULL, NULL,
13655 : yyscanner);
13656 49859 : $$ = $1;
13657 : }
13658 : | select_clause opt_sort_clause for_locking_clause opt_select_limit
13659 : {
13660 4802 : insertSelectOptions((SelectStmt *) $1, $2, $3,
13661 4802 : $4,
13662 : NULL,
13663 : yyscanner);
13664 4802 : $$ = $1;
13665 : }
13666 : | select_clause opt_sort_clause select_limit opt_for_locking_clause
13667 : {
13668 3136 : insertSelectOptions((SelectStmt *) $1, $2, $4,
13669 3136 : $3,
13670 : NULL,
13671 : yyscanner);
13672 3128 : $$ = $1;
13673 : }
13674 : | with_clause select_clause
13675 : {
13676 1518 : insertSelectOptions((SelectStmt *) $2, NULL, NIL,
13677 : NULL,
13678 1518 : $1,
13679 : yyscanner);
13680 1518 : $$ = $2;
13681 : }
13682 : | with_clause select_clause sort_clause
13683 : {
13684 360 : insertSelectOptions((SelectStmt *) $2, $3, NIL,
13685 : NULL,
13686 360 : $1,
13687 : yyscanner);
13688 360 : $$ = $2;
13689 : }
13690 : | with_clause select_clause opt_sort_clause for_locking_clause opt_select_limit
13691 : {
13692 4 : insertSelectOptions((SelectStmt *) $2, $3, $4,
13693 4 : $5,
13694 4 : $1,
13695 : yyscanner);
13696 4 : $$ = $2;
13697 : }
13698 : | with_clause select_clause opt_sort_clause select_limit opt_for_locking_clause
13699 : {
13700 42 : insertSelectOptions((SelectStmt *) $2, $3, $5,
13701 42 : $4,
13702 42 : $1,
13703 : yyscanner);
13704 42 : $$ = $2;
13705 : }
13706 : ;
13707 :
13708 : select_clause:
13709 85698 : simple_select { $$ = $1; }
13710 379 : | select_with_parens { $$ = $1; }
13711 : ;
13712 :
13713 : /*
13714 : * This rule parses SELECT statements that can appear within set operations,
13715 : * including UNION, INTERSECT and EXCEPT. '(' and ')' can be used to specify
13716 : * the ordering of the set operations. Without '(' and ')' we want the
13717 : * operations to be ordered per the precedence specs at the head of this file.
13718 : *
13719 : * As with select_no_parens, simple_select cannot have outer parentheses,
13720 : * but can have parenthesized subclauses.
13721 : *
13722 : * It might appear that we could fold the first two alternatives into one
13723 : * by using opt_distinct_clause. However, that causes a shift/reduce conflict
13724 : * against INSERT ... SELECT ... ON CONFLICT. We avoid the ambiguity by
13725 : * requiring SELECT DISTINCT [ON] to be followed by a non-empty target_list.
13726 : *
13727 : * Note that sort clauses cannot be included at this level --- SQL requires
13728 : * SELECT foo UNION SELECT bar ORDER BY baz
13729 : * to be parsed as
13730 : * (SELECT foo UNION SELECT bar) ORDER BY baz
13731 : * not
13732 : * SELECT foo UNION (SELECT bar ORDER BY baz)
13733 : * Likewise for WITH, FOR UPDATE and LIMIT. Therefore, those clauses are
13734 : * described as part of the select_no_parens production, not simple_select.
13735 : * This does not limit functionality, because you can reintroduce these
13736 : * clauses inside parentheses.
13737 : *
13738 : * NOTE: only the leftmost component SelectStmt should have INTO.
13739 : * However, this is not checked by the grammar; parse analysis must check it.
13740 : */
13741 : simple_select:
13742 : SELECT opt_all_clause opt_target_list
13743 : into_clause from_clause where_clause
13744 : group_clause having_clause window_clause
13745 : {
13746 287339 : SelectStmt *n = makeNode(SelectStmt);
13747 :
13748 287339 : n->targetList = $3;
13749 287339 : n->intoClause = $4;
13750 287339 : n->fromClause = $5;
13751 287339 : n->whereClause = $6;
13752 287339 : n->groupClause = ($7)->list;
13753 287339 : n->groupDistinct = ($7)->distinct;
13754 287339 : n->groupByAll = ($7)->all;
13755 287339 : n->havingClause = $8;
13756 287339 : n->windowClause = $9;
13757 287339 : $$ = (Node *) n;
13758 : }
13759 : | SELECT distinct_clause target_list
13760 : into_clause from_clause where_clause
13761 : group_clause having_clause window_clause
13762 : {
13763 2483 : SelectStmt *n = makeNode(SelectStmt);
13764 :
13765 2483 : n->distinctClause = $2;
13766 2483 : n->targetList = $3;
13767 2483 : n->intoClause = $4;
13768 2483 : n->fromClause = $5;
13769 2483 : n->whereClause = $6;
13770 2483 : n->groupClause = ($7)->list;
13771 2483 : n->groupDistinct = ($7)->distinct;
13772 2483 : n->groupByAll = ($7)->all;
13773 2483 : n->havingClause = $8;
13774 2483 : n->windowClause = $9;
13775 2483 : $$ = (Node *) n;
13776 : }
13777 37949 : | values_clause { $$ = $1; }
13778 : | TABLE relation_expr
13779 : {
13780 : /* same as SELECT * FROM relation_expr */
13781 253 : ColumnRef *cr = makeNode(ColumnRef);
13782 253 : ResTarget *rt = makeNode(ResTarget);
13783 253 : SelectStmt *n = makeNode(SelectStmt);
13784 :
13785 253 : cr->fields = list_make1(makeNode(A_Star));
13786 253 : cr->location = -1;
13787 :
13788 253 : rt->name = NULL;
13789 253 : rt->indirection = NIL;
13790 253 : rt->val = (Node *) cr;
13791 253 : rt->location = -1;
13792 :
13793 253 : n->targetList = list_make1(rt);
13794 253 : n->fromClause = list_make1($2);
13795 253 : $$ = (Node *) n;
13796 : }
13797 : | select_clause UNION set_quantifier select_clause
13798 : {
13799 12650 : $$ = makeSetOp(SETOP_UNION, $3 == SET_QUANTIFIER_ALL, $1, $4);
13800 : }
13801 : | select_clause INTERSECT set_quantifier select_clause
13802 : {
13803 184 : $$ = makeSetOp(SETOP_INTERSECT, $3 == SET_QUANTIFIER_ALL, $1, $4);
13804 : }
13805 : | select_clause EXCEPT set_quantifier select_clause
13806 : {
13807 340 : $$ = makeSetOp(SETOP_EXCEPT, $3 == SET_QUANTIFIER_ALL, $1, $4);
13808 : }
13809 : ;
13810 :
13811 : /*
13812 : * SQL standard WITH clause looks like:
13813 : *
13814 : * WITH [ RECURSIVE ] <query name> [ (<column>,...) ]
13815 : * AS (query) [ SEARCH or CYCLE clause ]
13816 : *
13817 : * Recognizing WITH_LA here allows a CTE to be named TIME or ORDINALITY.
13818 : */
13819 : with_clause:
13820 : WITH cte_list
13821 : {
13822 1397 : $$ = makeNode(WithClause);
13823 1397 : $$->ctes = $2;
13824 1397 : $$->recursive = false;
13825 1397 : $$->location = @1;
13826 : }
13827 : | WITH_LA cte_list
13828 : {
13829 4 : $$ = makeNode(WithClause);
13830 4 : $$->ctes = $2;
13831 4 : $$->recursive = false;
13832 4 : $$->location = @1;
13833 : }
13834 : | WITH RECURSIVE cte_list
13835 : {
13836 829 : $$ = makeNode(WithClause);
13837 829 : $$->ctes = $3;
13838 829 : $$->recursive = true;
13839 829 : $$->location = @1;
13840 : }
13841 : ;
13842 :
13843 : cte_list:
13844 2230 : common_table_expr { $$ = list_make1($1); }
13845 740 : | cte_list ',' common_table_expr { $$ = lappend($1, $3); }
13846 : ;
13847 :
13848 : common_table_expr: name opt_name_list AS opt_materialized '(' PreparableStmt ')' opt_search_clause opt_cycle_clause
13849 : {
13850 2970 : CommonTableExpr *n = makeNode(CommonTableExpr);
13851 :
13852 2970 : n->ctename = $1;
13853 2970 : n->aliascolnames = $2;
13854 2970 : n->ctematerialized = $4;
13855 2970 : n->ctequery = $6;
13856 2970 : n->search_clause = castNode(CTESearchClause, $8);
13857 2970 : n->cycle_clause = castNode(CTECycleClause, $9);
13858 2970 : n->location = @1;
13859 2970 : $$ = (Node *) n;
13860 : }
13861 : ;
13862 :
13863 : opt_materialized:
13864 118 : MATERIALIZED { $$ = CTEMaterializeAlways; }
13865 32 : | NOT MATERIALIZED { $$ = CTEMaterializeNever; }
13866 2820 : | /*EMPTY*/ { $$ = CTEMaterializeDefault; }
13867 : ;
13868 :
13869 : opt_search_clause:
13870 : SEARCH DEPTH FIRST_P BY columnList SET ColId
13871 : {
13872 60 : CTESearchClause *n = makeNode(CTESearchClause);
13873 :
13874 60 : n->search_col_list = $5;
13875 60 : n->search_breadth_first = false;
13876 60 : n->search_seq_column = $7;
13877 60 : n->location = @1;
13878 60 : $$ = (Node *) n;
13879 : }
13880 : | SEARCH BREADTH FIRST_P BY columnList SET ColId
13881 : {
13882 24 : CTESearchClause *n = makeNode(CTESearchClause);
13883 :
13884 24 : n->search_col_list = $5;
13885 24 : n->search_breadth_first = true;
13886 24 : n->search_seq_column = $7;
13887 24 : n->location = @1;
13888 24 : $$ = (Node *) n;
13889 : }
13890 : | /*EMPTY*/
13891 : {
13892 2886 : $$ = NULL;
13893 : }
13894 : ;
13895 :
13896 : opt_cycle_clause:
13897 : CYCLE columnList SET ColId TO AexprConst DEFAULT AexprConst USING ColId
13898 : {
13899 44 : CTECycleClause *n = makeNode(CTECycleClause);
13900 :
13901 44 : n->cycle_col_list = $2;
13902 44 : n->cycle_mark_column = $4;
13903 44 : n->cycle_mark_value = $6;
13904 44 : n->cycle_mark_default = $8;
13905 44 : n->cycle_path_column = $10;
13906 44 : n->location = @1;
13907 44 : $$ = (Node *) n;
13908 : }
13909 : | CYCLE columnList SET ColId USING ColId
13910 : {
13911 40 : CTECycleClause *n = makeNode(CTECycleClause);
13912 :
13913 40 : n->cycle_col_list = $2;
13914 40 : n->cycle_mark_column = $4;
13915 40 : n->cycle_mark_value = makeBoolAConst(true, -1);
13916 40 : n->cycle_mark_default = makeBoolAConst(false, -1);
13917 40 : n->cycle_path_column = $6;
13918 40 : n->location = @1;
13919 40 : $$ = (Node *) n;
13920 : }
13921 : | /*EMPTY*/
13922 : {
13923 2886 : $$ = NULL;
13924 : }
13925 : ;
13926 :
13927 : opt_with_clause:
13928 306 : with_clause { $$ = $1; }
13929 56146 : | /*EMPTY*/ { $$ = NULL; }
13930 : ;
13931 :
13932 : into_clause:
13933 : INTO OptTempTableName
13934 : {
13935 91 : $$ = makeNode(IntoClause);
13936 91 : $$->rel = $2;
13937 91 : $$->colNames = NIL;
13938 91 : $$->options = NIL;
13939 91 : $$->onCommit = ONCOMMIT_NOOP;
13940 91 : $$->tableSpaceName = NULL;
13941 91 : $$->viewQuery = NULL;
13942 91 : $$->skipData = false;
13943 : }
13944 : | /*EMPTY*/
13945 289759 : { $$ = NULL; }
13946 : ;
13947 :
13948 : /*
13949 : * Redundancy here is needed to avoid shift/reduce conflicts,
13950 : * since TEMP is not a reserved word. See also OptTemp.
13951 : */
13952 : OptTempTableName:
13953 : TEMPORARY opt_table qualified_name
13954 : {
13955 0 : $$ = $3;
13956 0 : $$->relpersistence = RELPERSISTENCE_TEMP;
13957 : }
13958 : | TEMP opt_table qualified_name
13959 : {
13960 4 : $$ = $3;
13961 4 : $$->relpersistence = RELPERSISTENCE_TEMP;
13962 : }
13963 : | LOCAL TEMPORARY opt_table qualified_name
13964 : {
13965 0 : $$ = $4;
13966 0 : $$->relpersistence = RELPERSISTENCE_TEMP;
13967 : }
13968 : | LOCAL TEMP opt_table qualified_name
13969 : {
13970 0 : $$ = $4;
13971 0 : $$->relpersistence = RELPERSISTENCE_TEMP;
13972 : }
13973 : | GLOBAL TEMPORARY opt_table qualified_name
13974 : {
13975 0 : ereport(WARNING,
13976 : (errmsg("GLOBAL is deprecated in temporary table creation"),
13977 : parser_errposition(@1)));
13978 0 : $$ = $4;
13979 0 : $$->relpersistence = RELPERSISTENCE_TEMP;
13980 : }
13981 : | GLOBAL TEMP opt_table qualified_name
13982 : {
13983 0 : ereport(WARNING,
13984 : (errmsg("GLOBAL is deprecated in temporary table creation"),
13985 : parser_errposition(@1)));
13986 0 : $$ = $4;
13987 0 : $$->relpersistence = RELPERSISTENCE_TEMP;
13988 : }
13989 : | UNLOGGED opt_table qualified_name
13990 : {
13991 0 : $$ = $3;
13992 0 : $$->relpersistence = RELPERSISTENCE_UNLOGGED;
13993 : }
13994 : | TABLE qualified_name
13995 : {
13996 20 : $$ = $2;
13997 20 : $$->relpersistence = RELPERSISTENCE_PERMANENT;
13998 : }
13999 : | qualified_name
14000 : {
14001 67 : $$ = $1;
14002 67 : $$->relpersistence = RELPERSISTENCE_PERMANENT;
14003 : }
14004 : ;
14005 :
14006 : opt_table: TABLE
14007 : | /*EMPTY*/
14008 : ;
14009 :
14010 : set_quantifier:
14011 7339 : ALL { $$ = SET_QUANTIFIER_ALL; }
14012 25 : | DISTINCT { $$ = SET_QUANTIFIER_DISTINCT; }
14013 9178 : | /*EMPTY*/ { $$ = SET_QUANTIFIER_DEFAULT; }
14014 : ;
14015 :
14016 : /* We use (NIL) as a placeholder to indicate that all target expressions
14017 : * should be placed in the DISTINCT list during parsetree analysis.
14018 : */
14019 : distinct_clause:
14020 2326 : DISTINCT { $$ = list_make1(NIL); }
14021 161 : | DISTINCT ON '(' expr_list ')' { $$ = $4; }
14022 : ;
14023 :
14024 : opt_all_clause:
14025 : ALL
14026 : | /*EMPTY*/
14027 : ;
14028 :
14029 : opt_distinct_clause:
14030 0 : distinct_clause { $$ = $1; }
14031 25657 : | opt_all_clause { $$ = NIL; }
14032 : ;
14033 :
14034 : opt_sort_clause:
14035 5012 : sort_clause { $$ = $1; }
14036 243452 : | /*EMPTY*/ { $$ = NIL; }
14037 : ;
14038 :
14039 : sort_clause:
14040 55459 : ORDER BY sortby_list { $$ = $3; }
14041 : ;
14042 :
14043 : sortby_list:
14044 55471 : sortby { $$ = list_make1($1); }
14045 20123 : | sortby_list ',' sortby { $$ = lappend($1, $3); }
14046 : ;
14047 :
14048 : sortby: a_expr USING qual_all_Op opt_nulls_order
14049 : {
14050 142 : $$ = makeNode(SortBy);
14051 142 : $$->node = $1;
14052 142 : $$->sortby_dir = SORTBY_USING;
14053 142 : $$->sortby_nulls = $4;
14054 142 : $$->useOp = $3;
14055 142 : $$->location = @3;
14056 : }
14057 : | a_expr opt_asc_desc opt_nulls_order
14058 : {
14059 75452 : $$ = makeNode(SortBy);
14060 75452 : $$->node = $1;
14061 75452 : $$->sortby_dir = $2;
14062 75452 : $$->sortby_nulls = $3;
14063 75452 : $$->useOp = NIL;
14064 75452 : $$->location = -1; /* no operator */
14065 : }
14066 : ;
14067 :
14068 :
14069 : select_limit:
14070 : limit_clause offset_clause
14071 : {
14072 99 : $$ = $1;
14073 99 : ($$)->limitOffset = $2;
14074 99 : ($$)->offsetLoc = @2;
14075 : }
14076 : | offset_clause limit_clause
14077 : {
14078 113 : $$ = $2;
14079 113 : ($$)->limitOffset = $1;
14080 113 : ($$)->offsetLoc = @1;
14081 : }
14082 : | limit_clause
14083 : {
14084 2739 : $$ = $1;
14085 : }
14086 : | offset_clause
14087 : {
14088 322 : SelectLimit *n = palloc_object(SelectLimit);
14089 :
14090 322 : n->limitOffset = $1;
14091 322 : n->limitCount = NULL;
14092 322 : n->limitOption = LIMIT_OPTION_COUNT;
14093 322 : n->offsetLoc = @1;
14094 322 : n->countLoc = -1;
14095 322 : n->optionLoc = -1;
14096 322 : $$ = n;
14097 : }
14098 : ;
14099 :
14100 : opt_select_limit:
14101 95 : select_limit { $$ = $1; }
14102 30368 : | /* EMPTY */ { $$ = NULL; }
14103 : ;
14104 :
14105 : limit_clause:
14106 : LIMIT select_limit_value
14107 : {
14108 2890 : SelectLimit *n = palloc_object(SelectLimit);
14109 :
14110 2890 : n->limitOffset = NULL;
14111 2890 : n->limitCount = $2;
14112 2890 : n->limitOption = LIMIT_OPTION_COUNT;
14113 2890 : n->offsetLoc = -1;
14114 2890 : n->countLoc = @1;
14115 2890 : n->optionLoc = -1;
14116 2890 : $$ = n;
14117 : }
14118 : | LIMIT select_limit_value ',' select_offset_value
14119 : {
14120 : /* Disabled because it was too confusing, bjm 2002-02-18 */
14121 0 : ereport(ERROR,
14122 : (errcode(ERRCODE_SYNTAX_ERROR),
14123 : errmsg("LIMIT #,# syntax is not supported"),
14124 : errhint("Use separate LIMIT and OFFSET clauses."),
14125 : parser_errposition(@1)));
14126 : }
14127 : /* SQL:2008 syntax */
14128 : /* to avoid shift/reduce conflicts, handle the optional value with
14129 : * a separate production rather than an opt_ expression. The fact
14130 : * that ONLY is fully reserved means that this way, we defer any
14131 : * decision about what rule reduces ROW or ROWS to the point where
14132 : * we can see the ONLY token in the lookahead slot.
14133 : */
14134 : | FETCH first_or_next select_fetch_first_value row_or_rows ONLY
14135 : {
14136 15 : SelectLimit *n = palloc_object(SelectLimit);
14137 :
14138 15 : n->limitOffset = NULL;
14139 15 : n->limitCount = $3;
14140 15 : n->limitOption = LIMIT_OPTION_COUNT;
14141 15 : n->offsetLoc = -1;
14142 15 : n->countLoc = @1;
14143 15 : n->optionLoc = -1;
14144 15 : $$ = n;
14145 : }
14146 : | FETCH first_or_next select_fetch_first_value row_or_rows WITH TIES
14147 : {
14148 42 : SelectLimit *n = palloc_object(SelectLimit);
14149 :
14150 42 : n->limitOffset = NULL;
14151 42 : n->limitCount = $3;
14152 42 : n->limitOption = LIMIT_OPTION_WITH_TIES;
14153 42 : n->offsetLoc = -1;
14154 42 : n->countLoc = @1;
14155 42 : n->optionLoc = @5;
14156 42 : $$ = n;
14157 : }
14158 : | FETCH first_or_next row_or_rows ONLY
14159 : {
14160 0 : SelectLimit *n = palloc_object(SelectLimit);
14161 :
14162 0 : n->limitOffset = NULL;
14163 0 : n->limitCount = makeIntConst(1, -1);
14164 0 : n->limitOption = LIMIT_OPTION_COUNT;
14165 0 : n->offsetLoc = -1;
14166 0 : n->countLoc = @1;
14167 0 : n->optionLoc = -1;
14168 0 : $$ = n;
14169 : }
14170 : | FETCH first_or_next row_or_rows WITH TIES
14171 : {
14172 4 : SelectLimit *n = palloc_object(SelectLimit);
14173 :
14174 4 : n->limitOffset = NULL;
14175 4 : n->limitCount = makeIntConst(1, -1);
14176 4 : n->limitOption = LIMIT_OPTION_WITH_TIES;
14177 4 : n->offsetLoc = -1;
14178 4 : n->countLoc = @1;
14179 4 : n->optionLoc = @4;
14180 4 : $$ = n;
14181 : }
14182 : ;
14183 :
14184 : offset_clause:
14185 : OFFSET select_offset_value
14186 534 : { $$ = $2; }
14187 : /* SQL:2008 syntax */
14188 : | OFFSET select_fetch_first_value row_or_rows
14189 0 : { $$ = $2; }
14190 : ;
14191 :
14192 : select_limit_value:
14193 2889 : a_expr { $$ = $1; }
14194 : | ALL
14195 : {
14196 : /* LIMIT ALL is represented as a NULL constant */
14197 1 : $$ = makeNullAConst(@1);
14198 : }
14199 : ;
14200 :
14201 : select_offset_value:
14202 534 : a_expr { $$ = $1; }
14203 : ;
14204 :
14205 : /*
14206 : * Allowing full expressions without parentheses causes various parsing
14207 : * problems with the trailing ROW/ROWS key words. SQL spec only calls for
14208 : * <simple value specification>, which is either a literal or a parameter (but
14209 : * an <SQL parameter reference> could be an identifier, bringing up conflicts
14210 : * with ROW/ROWS). We solve this by leveraging the presence of ONLY (see above)
14211 : * to determine whether the expression is missing rather than trying to make it
14212 : * optional in this rule.
14213 : *
14214 : * c_expr covers almost all the spec-required cases (and more), but it doesn't
14215 : * cover signed numeric literals, which are allowed by the spec. So we include
14216 : * those here explicitly. We need FCONST as well as ICONST because values that
14217 : * don't fit in the platform's "long", but do fit in bigint, should still be
14218 : * accepted here. (This is possible in 64-bit Windows as well as all 32-bit
14219 : * builds.)
14220 : */
14221 : select_fetch_first_value:
14222 57 : c_expr { $$ = $1; }
14223 : | '+' I_or_F_const
14224 0 : { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "+", NULL, $2, @1); }
14225 : | '-' I_or_F_const
14226 0 : { $$ = doNegate($2, @1); }
14227 : ;
14228 :
14229 : I_or_F_const:
14230 0 : Iconst { $$ = makeIntConst($1,@1); }
14231 0 : | FCONST { $$ = makeFloatConst($1,@1); }
14232 : ;
14233 :
14234 : /* noise words */
14235 23 : row_or_rows: ROW { $$ = 0; }
14236 38 : | ROWS { $$ = 0; }
14237 : ;
14238 :
14239 61 : first_or_next: FIRST_P { $$ = 0; }
14240 0 : | NEXT { $$ = 0; }
14241 : ;
14242 :
14243 :
14244 : /*
14245 : * This syntax for group_clause tries to follow the spec quite closely.
14246 : * However, the spec allows only column references, not expressions,
14247 : * which introduces an ambiguity between implicit row constructors
14248 : * (a,b) and lists of column references.
14249 : *
14250 : * We handle this by using the a_expr production for what the spec calls
14251 : * <ordinary grouping set>, which in the spec represents either one column
14252 : * reference or a parenthesized list of column references. Then, we check the
14253 : * top node of the a_expr to see if it's an implicit RowExpr, and if so, just
14254 : * grab and use the list, discarding the node. (this is done in parse analysis,
14255 : * not here)
14256 : *
14257 : * (we abuse the row_format field of RowExpr to distinguish implicit and
14258 : * explicit row constructors; it's debatable if anyone sanely wants to use them
14259 : * in a group clause, but if they have a reason to, we make it possible.)
14260 : *
14261 : * Each item in the group_clause list is either an expression tree or a
14262 : * GroupingSet node of some type.
14263 : */
14264 : group_clause:
14265 : GROUP_P BY set_quantifier group_by_list
14266 : {
14267 3360 : GroupClause *n = palloc_object(GroupClause);
14268 :
14269 3360 : n->distinct = $3 == SET_QUANTIFIER_DISTINCT;
14270 3360 : n->all = false;
14271 3360 : n->list = $4;
14272 3360 : $$ = n;
14273 : }
14274 : | GROUP_P BY ALL
14275 : {
14276 44 : GroupClause *n = palloc_object(GroupClause);
14277 44 : n->distinct = false;
14278 44 : n->all = true;
14279 44 : n->list = NIL;
14280 44 : $$ = n;
14281 : }
14282 : | /*EMPTY*/
14283 : {
14284 312075 : GroupClause *n = palloc_object(GroupClause);
14285 :
14286 312075 : n->distinct = false;
14287 312075 : n->all = false;
14288 312075 : n->list = NIL;
14289 312075 : $$ = n;
14290 : }
14291 : ;
14292 :
14293 : group_by_list:
14294 3848 : group_by_item { $$ = list_make1($1); }
14295 2066 : | group_by_list ',' group_by_item { $$ = lappend($1,$3); }
14296 : ;
14297 :
14298 : group_by_item:
14299 4874 : a_expr { $$ = $1; }
14300 214 : | empty_grouping_set { $$ = $1; }
14301 122 : | cube_clause { $$ = $1; }
14302 216 : | rollup_clause { $$ = $1; }
14303 488 : | grouping_sets_clause { $$ = $1; }
14304 : ;
14305 :
14306 : empty_grouping_set:
14307 : '(' ')'
14308 : {
14309 214 : $$ = (Node *) makeGroupingSet(GROUPING_SET_EMPTY, NIL, @1);
14310 : }
14311 : ;
14312 :
14313 : /*
14314 : * These hacks rely on setting precedence of CUBE and ROLLUP below that of '(',
14315 : * so that they shift in these rules rather than reducing the conflicting
14316 : * unreserved_keyword rule.
14317 : */
14318 :
14319 : rollup_clause:
14320 : ROLLUP '(' expr_list ')'
14321 : {
14322 216 : $$ = (Node *) makeGroupingSet(GROUPING_SET_ROLLUP, $3, @1);
14323 : }
14324 : ;
14325 :
14326 : cube_clause:
14327 : CUBE '(' expr_list ')'
14328 : {
14329 122 : $$ = (Node *) makeGroupingSet(GROUPING_SET_CUBE, $3, @1);
14330 : }
14331 : ;
14332 :
14333 : grouping_sets_clause:
14334 : GROUPING SETS '(' group_by_list ')'
14335 : {
14336 488 : $$ = (Node *) makeGroupingSet(GROUPING_SET_SETS, $4, @1);
14337 : }
14338 : ;
14339 :
14340 : having_clause:
14341 512 : HAVING a_expr { $$ = $2; }
14342 314967 : | /*EMPTY*/ { $$ = NULL; }
14343 : ;
14344 :
14345 : for_locking_clause:
14346 4977 : for_locking_items { $$ = $1; }
14347 0 : | FOR READ ONLY { $$ = NIL; }
14348 : ;
14349 :
14350 : opt_for_locking_clause:
14351 171 : for_locking_clause { $$ = $1; }
14352 28664 : | /* EMPTY */ { $$ = NIL; }
14353 : ;
14354 :
14355 : for_locking_items:
14356 4977 : for_locking_item { $$ = list_make1($1); }
14357 51 : | for_locking_items for_locking_item { $$ = lappend($1, $2); }
14358 : ;
14359 :
14360 : for_locking_item:
14361 : for_locking_strength locked_rels_list opt_nowait_or_skip
14362 : {
14363 5028 : LockingClause *n = makeNode(LockingClause);
14364 :
14365 5028 : n->lockedRels = $2;
14366 5028 : n->strength = $1;
14367 5028 : n->waitPolicy = $3;
14368 5028 : $$ = (Node *) n;
14369 : }
14370 : ;
14371 :
14372 : for_locking_strength:
14373 974 : FOR UPDATE { $$ = LCS_FORUPDATE; }
14374 44 : | FOR NO KEY UPDATE { $$ = LCS_FORNOKEYUPDATE; }
14375 123 : | FOR SHARE { $$ = LCS_FORSHARE; }
14376 3965 : | FOR KEY SHARE { $$ = LCS_FORKEYSHARE; }
14377 : ;
14378 :
14379 : opt_for_locking_strength:
14380 78 : for_locking_strength { $$ = $1; }
14381 162 : | /* EMPTY */ { $$ = LCS_NONE; }
14382 : ;
14383 :
14384 : locked_rels_list:
14385 1213 : OF qualified_name_list { $$ = $2; }
14386 3815 : | /* EMPTY */ { $$ = NIL; }
14387 : ;
14388 :
14389 :
14390 : /*
14391 : * We should allow ROW '(' expr_list ')' too, but that seems to require
14392 : * making VALUES a fully reserved word, which will probably break more apps
14393 : * than allowing the noise-word is worth.
14394 : */
14395 : values_clause:
14396 : VALUES '(' expr_list ')'
14397 : {
14398 37949 : SelectStmt *n = makeNode(SelectStmt);
14399 :
14400 37949 : n->valuesLists = list_make1($3);
14401 37949 : $$ = (Node *) n;
14402 : }
14403 : | values_clause ',' '(' expr_list ')'
14404 : {
14405 17867 : SelectStmt *n = (SelectStmt *) $1;
14406 :
14407 17867 : n->valuesLists = lappend(n->valuesLists, $4);
14408 17867 : $$ = (Node *) n;
14409 : }
14410 : ;
14411 :
14412 :
14413 : /*****************************************************************************
14414 : *
14415 : * clauses common to all Optimizable Stmts:
14416 : * from_clause - allow list of both JOIN expressions and table names
14417 : * where_clause - qualifications for joins or restrictions
14418 : *
14419 : *****************************************************************************/
14420 :
14421 : from_clause:
14422 213912 : FROM from_list { $$ = $2; }
14423 110921 : | /*EMPTY*/ { $$ = NIL; }
14424 : ;
14425 :
14426 : from_list:
14427 214632 : table_ref { $$ = list_make1($1); }
14428 38955 : | from_list ',' table_ref { $$ = lappend($1, $3); }
14429 : ;
14430 :
14431 : /*
14432 : * table_ref is where an alias clause can be attached.
14433 : */
14434 : table_ref: relation_expr opt_alias_clause
14435 : {
14436 266619 : $1->alias = $2;
14437 266619 : $$ = (Node *) $1;
14438 : }
14439 : | relation_expr opt_alias_clause tablesample_clause
14440 : {
14441 170 : RangeTableSample *n = (RangeTableSample *) $3;
14442 :
14443 170 : $1->alias = $2;
14444 : /* relation_expr goes inside the RangeTableSample node */
14445 170 : n->relation = (Node *) $1;
14446 170 : $$ = (Node *) n;
14447 : }
14448 : | func_table func_alias_clause
14449 : {
14450 30241 : RangeFunction *n = (RangeFunction *) $1;
14451 :
14452 30241 : n->alias = linitial($2);
14453 30241 : n->coldeflist = lsecond($2);
14454 30241 : $$ = (Node *) n;
14455 : }
14456 : | LATERAL_P func_table func_alias_clause
14457 : {
14458 347 : RangeFunction *n = (RangeFunction *) $2;
14459 :
14460 347 : n->lateral = true;
14461 347 : n->alias = linitial($3);
14462 347 : n->coldeflist = lsecond($3);
14463 347 : $$ = (Node *) n;
14464 : }
14465 : | xmltable opt_alias_clause
14466 : {
14467 57 : RangeTableFunc *n = (RangeTableFunc *) $1;
14468 :
14469 57 : n->alias = $2;
14470 57 : $$ = (Node *) n;
14471 : }
14472 : | LATERAL_P xmltable opt_alias_clause
14473 : {
14474 93 : RangeTableFunc *n = (RangeTableFunc *) $2;
14475 :
14476 93 : n->lateral = true;
14477 93 : n->alias = $3;
14478 93 : $$ = (Node *) n;
14479 : }
14480 : | GRAPH_TABLE '(' qualified_name MATCH graph_pattern COLUMNS '(' labeled_expr_list ')' ')' opt_alias_clause
14481 : {
14482 421 : RangeGraphTable *n = makeNode(RangeGraphTable);
14483 :
14484 421 : n->graph_name = $3;
14485 421 : n->graph_pattern = castNode(GraphPattern, $5);
14486 421 : n->columns = $8;
14487 421 : n->alias = $11;
14488 421 : n->location = @1;
14489 421 : $$ = (Node *) n;
14490 : }
14491 : | select_with_parens opt_alias_clause
14492 : {
14493 12466 : RangeSubselect *n = makeNode(RangeSubselect);
14494 :
14495 12466 : n->lateral = false;
14496 12466 : n->subquery = $1;
14497 12466 : n->alias = $2;
14498 12466 : $$ = (Node *) n;
14499 : }
14500 : | LATERAL_P select_with_parens opt_alias_clause
14501 : {
14502 1229 : RangeSubselect *n = makeNode(RangeSubselect);
14503 :
14504 1229 : n->lateral = true;
14505 1229 : n->subquery = $2;
14506 1229 : n->alias = $3;
14507 1229 : $$ = (Node *) n;
14508 : }
14509 : | joined_table
14510 : {
14511 56838 : $$ = (Node *) $1;
14512 : }
14513 : | '(' joined_table ')' alias_clause
14514 : {
14515 120 : $2->alias = $4;
14516 120 : $$ = (Node *) $2;
14517 : }
14518 : | json_table opt_alias_clause
14519 : {
14520 352 : JsonTable *jt = castNode(JsonTable, $1);
14521 :
14522 352 : jt->alias = $2;
14523 352 : $$ = (Node *) jt;
14524 : }
14525 : | LATERAL_P json_table opt_alias_clause
14526 : {
14527 0 : JsonTable *jt = castNode(JsonTable, $2);
14528 :
14529 0 : jt->alias = $3;
14530 0 : jt->lateral = true;
14531 0 : $$ = (Node *) jt;
14532 : }
14533 : ;
14534 :
14535 :
14536 : /*
14537 : * It may seem silly to separate joined_table from table_ref, but there is
14538 : * method in SQL's madness: if you don't do it this way you get reduce-
14539 : * reduce conflicts, because it's not clear to the parser generator whether
14540 : * to expect alias_clause after ')' or not. For the same reason we must
14541 : * treat 'JOIN' and 'join_type JOIN' separately, rather than allowing
14542 : * join_type to expand to empty; if we try it, the parser generator can't
14543 : * figure out when to reduce an empty join_type right after table_ref.
14544 : *
14545 : * Note that a CROSS JOIN is the same as an unqualified
14546 : * INNER JOIN, and an INNER JOIN/ON has the same shape
14547 : * but a qualification expression to limit membership.
14548 : * A NATURAL JOIN implicitly matches column names between
14549 : * tables and the shape is determined by which columns are
14550 : * in common. We'll collect columns during the later transformations.
14551 : */
14552 :
14553 : joined_table:
14554 : '(' joined_table ')'
14555 : {
14556 2474 : $$ = $2;
14557 : }
14558 : | table_ref CROSS JOIN table_ref
14559 : {
14560 : /* CROSS JOIN is same as unqualified inner join */
14561 356 : JoinExpr *n = makeNode(JoinExpr);
14562 :
14563 356 : n->jointype = JOIN_INNER;
14564 356 : n->isNatural = false;
14565 356 : n->larg = $1;
14566 356 : n->rarg = $4;
14567 356 : n->usingClause = NIL;
14568 356 : n->join_using_alias = NULL;
14569 356 : n->quals = NULL;
14570 356 : $$ = n;
14571 : }
14572 : | table_ref join_type JOIN table_ref join_qual
14573 : {
14574 30202 : JoinExpr *n = makeNode(JoinExpr);
14575 :
14576 30202 : n->jointype = $2;
14577 30202 : n->isNatural = false;
14578 30202 : n->larg = $1;
14579 30202 : n->rarg = $4;
14580 30202 : if ($5 != NULL && IsA($5, List))
14581 : {
14582 : /* USING clause */
14583 350 : n->usingClause = linitial_node(List, castNode(List, $5));
14584 350 : n->join_using_alias = lsecond_node(Alias, castNode(List, $5));
14585 : }
14586 : else
14587 : {
14588 : /* ON clause */
14589 29852 : n->quals = $5;
14590 : }
14591 30202 : $$ = n;
14592 : }
14593 : | table_ref JOIN table_ref join_qual
14594 : {
14595 : /* letting join_type reduce to empty doesn't work */
14596 26220 : JoinExpr *n = makeNode(JoinExpr);
14597 :
14598 26220 : n->jointype = JOIN_INNER;
14599 26220 : n->isNatural = false;
14600 26220 : n->larg = $1;
14601 26220 : n->rarg = $3;
14602 26220 : if ($4 != NULL && IsA($4, List))
14603 : {
14604 : /* USING clause */
14605 501 : n->usingClause = linitial_node(List, castNode(List, $4));
14606 501 : n->join_using_alias = lsecond_node(Alias, castNode(List, $4));
14607 : }
14608 : else
14609 : {
14610 : /* ON clause */
14611 25719 : n->quals = $4;
14612 : }
14613 26220 : $$ = n;
14614 : }
14615 : | table_ref NATURAL join_type JOIN table_ref
14616 : {
14617 52 : JoinExpr *n = makeNode(JoinExpr);
14618 :
14619 52 : n->jointype = $3;
14620 52 : n->isNatural = true;
14621 52 : n->larg = $1;
14622 52 : n->rarg = $5;
14623 52 : n->usingClause = NIL; /* figure out which columns later... */
14624 52 : n->join_using_alias = NULL;
14625 52 : n->quals = NULL; /* fill later */
14626 52 : $$ = n;
14627 : }
14628 : | table_ref NATURAL JOIN table_ref
14629 : {
14630 : /* letting join_type reduce to empty doesn't work */
14631 128 : JoinExpr *n = makeNode(JoinExpr);
14632 :
14633 128 : n->jointype = JOIN_INNER;
14634 128 : n->isNatural = true;
14635 128 : n->larg = $1;
14636 128 : n->rarg = $4;
14637 128 : n->usingClause = NIL; /* figure out which columns later... */
14638 128 : n->join_using_alias = NULL;
14639 128 : n->quals = NULL; /* fill later */
14640 128 : $$ = n;
14641 : }
14642 : ;
14643 :
14644 : alias_clause:
14645 : AS ColId '(' name_list ')'
14646 : {
14647 4512 : $$ = makeNode(Alias);
14648 4512 : $$->aliasname = $2;
14649 4512 : $$->colnames = $4;
14650 : }
14651 : | AS ColId
14652 : {
14653 10247 : $$ = makeNode(Alias);
14654 10247 : $$->aliasname = $2;
14655 : }
14656 : | ColId '(' name_list ')'
14657 : {
14658 3852 : $$ = makeNode(Alias);
14659 3852 : $$->aliasname = $1;
14660 3852 : $$->colnames = $3;
14661 : }
14662 : | ColId
14663 : {
14664 175899 : $$ = makeNode(Alias);
14665 175899 : $$->aliasname = $1;
14666 : }
14667 : ;
14668 :
14669 176038 : opt_alias_clause: alias_clause { $$ = $1; }
14670 105369 : | /*EMPTY*/ { $$ = NULL; }
14671 : ;
14672 :
14673 : /*
14674 : * The alias clause after JOIN ... USING only accepts the AS ColId spelling,
14675 : * per SQL standard. (The grammar could parse the other variants, but they
14676 : * don't seem to be useful, and it might lead to parser problems in the
14677 : * future.)
14678 : */
14679 : opt_alias_clause_for_join_using:
14680 : AS ColId
14681 : {
14682 56 : $$ = makeNode(Alias);
14683 56 : $$->aliasname = $2;
14684 : /* the column name list will be inserted later */
14685 : }
14686 795 : | /*EMPTY*/ { $$ = NULL; }
14687 : ;
14688 :
14689 : /*
14690 : * func_alias_clause can include both an Alias and a coldeflist, so we make it
14691 : * return a 2-element list that gets disassembled by calling production.
14692 : */
14693 : func_alias_clause:
14694 : alias_clause
14695 : {
14696 18352 : $$ = list_make2($1, NIL);
14697 : }
14698 : | AS '(' TableFuncElementList ')'
14699 : {
14700 70 : $$ = list_make2(NULL, $3);
14701 : }
14702 : | AS ColId '(' TableFuncElementList ')'
14703 : {
14704 359 : Alias *a = makeNode(Alias);
14705 :
14706 359 : a->aliasname = $2;
14707 359 : $$ = list_make2(a, $4);
14708 : }
14709 : | ColId '(' TableFuncElementList ')'
14710 : {
14711 33 : Alias *a = makeNode(Alias);
14712 :
14713 33 : a->aliasname = $1;
14714 33 : $$ = list_make2(a, $3);
14715 : }
14716 : | /*EMPTY*/
14717 : {
14718 11774 : $$ = list_make2(NULL, NIL);
14719 : }
14720 : ;
14721 :
14722 679 : join_type: FULL opt_outer { $$ = JOIN_FULL; }
14723 26941 : | LEFT opt_outer { $$ = JOIN_LEFT; }
14724 252 : | RIGHT opt_outer { $$ = JOIN_RIGHT; }
14725 2382 : | INNER_P { $$ = JOIN_INNER; }
14726 : ;
14727 :
14728 : /* OUTER is just noise... */
14729 : opt_outer: OUTER_P
14730 : | /*EMPTY*/
14731 : ;
14732 :
14733 : /* JOIN qualification clauses
14734 : * Possibilities are:
14735 : * USING ( column list ) [ AS alias ]
14736 : * allows only unqualified column names,
14737 : * which must match between tables.
14738 : * ON expr allows more general qualifications.
14739 : *
14740 : * We return USING as a two-element List (the first item being a sub-List
14741 : * of the common column names, and the second either an Alias item or NULL).
14742 : * An ON-expr will not be a List, so it can be told apart that way.
14743 : */
14744 :
14745 : join_qual: USING '(' name_list ')' opt_alias_clause_for_join_using
14746 : {
14747 851 : $$ = (Node *) list_make2($3, $5);
14748 : }
14749 : | ON a_expr
14750 : {
14751 55571 : $$ = $2;
14752 : }
14753 : ;
14754 :
14755 :
14756 : relation_expr:
14757 : qualified_name
14758 : {
14759 : /* inheritance query, implicitly */
14760 320153 : $$ = $1;
14761 320153 : $$->inh = true;
14762 320153 : $$->alias = NULL;
14763 : }
14764 : | extended_relation_expr
14765 : {
14766 3717 : $$ = $1;
14767 : }
14768 : ;
14769 :
14770 : extended_relation_expr:
14771 : qualified_name '*'
14772 : {
14773 : /* inheritance query, explicitly */
14774 140 : $$ = $1;
14775 140 : $$->inh = true;
14776 140 : $$->alias = NULL;
14777 : }
14778 : | ONLY qualified_name
14779 : {
14780 : /* no inheritance */
14781 3581 : $$ = $2;
14782 3581 : $$->inh = false;
14783 3581 : $$->alias = NULL;
14784 : }
14785 : | ONLY '(' qualified_name ')'
14786 : {
14787 : /* no inheritance, SQL99-style syntax */
14788 0 : $$ = $3;
14789 0 : $$->inh = false;
14790 0 : $$->alias = NULL;
14791 : }
14792 : ;
14793 :
14794 :
14795 : relation_expr_list:
14796 1812 : relation_expr { $$ = list_make1($1); }
14797 6178 : | relation_expr_list ',' relation_expr { $$ = lappend($1, $3); }
14798 : ;
14799 :
14800 :
14801 : /*
14802 : * Given "UPDATE foo set set ...", we have to decide without looking any
14803 : * further ahead whether the first "set" is an alias or the UPDATE's SET
14804 : * keyword. Since "set" is allowed as a column name both interpretations
14805 : * are feasible. We resolve the shift/reduce conflict by giving the first
14806 : * relation_expr_opt_alias production a higher precedence than the SET token
14807 : * has, causing the parser to prefer to reduce, in effect assuming that the
14808 : * SET is not an alias.
14809 : */
14810 : relation_expr_opt_alias: relation_expr %prec UMINUS
14811 : {
14812 11702 : $$ = $1;
14813 : }
14814 : | relation_expr ColId
14815 : {
14816 1489 : Alias *alias = makeNode(Alias);
14817 :
14818 1489 : alias->aliasname = $2;
14819 1489 : $1->alias = alias;
14820 1489 : $$ = $1;
14821 : }
14822 : | relation_expr AS ColId
14823 : {
14824 59 : Alias *alias = makeNode(Alias);
14825 :
14826 59 : alias->aliasname = $3;
14827 59 : $1->alias = alias;
14828 59 : $$ = $1;
14829 : }
14830 : ;
14831 :
14832 : /*
14833 : * If an UPDATE/DELETE has FOR PORTION OF, then the relation_expr is separated
14834 : * from its potential alias by the for_portion_of_clause. So this production
14835 : * handles the potential alias in those cases. We need to solve the same
14836 : * problems as relation_expr_opt_alias, in particular resolving a shift/reduce
14837 : * conflict where "set set" could be an alias plus the SET keyword, or the SET
14838 : * keyword then a column name. As above, we force the latter interpretation by
14839 : * giving the non-alias choice a higher precedence.
14840 : */
14841 : for_portion_of_opt_alias:
14842 : AS ColId
14843 : {
14844 12 : Alias *alias = makeNode(Alias);
14845 :
14846 12 : alias->aliasname = $2;
14847 12 : $$ = alias;
14848 : }
14849 : | BareColLabel
14850 : {
14851 8 : Alias *alias = makeNode(Alias);
14852 :
14853 8 : alias->aliasname = $1;
14854 8 : $$ = alias;
14855 : }
14856 945 : | /* empty */ %prec UMINUS { $$ = NULL; }
14857 : ;
14858 :
14859 : for_portion_of_clause:
14860 : FOR PORTION OF ColId '(' a_expr ')'
14861 : {
14862 200 : ForPortionOfClause *n = makeNode(ForPortionOfClause);
14863 200 : n->range_name = $4;
14864 200 : n->location = @4;
14865 200 : n->target = $6;
14866 200 : n->target_location = @6;
14867 200 : $$ = (Node *) n;
14868 : }
14869 : | FOR PORTION OF ColId FROM a_expr TO a_expr
14870 : {
14871 765 : ForPortionOfClause *n = makeNode(ForPortionOfClause);
14872 765 : n->range_name = $4;
14873 765 : n->location = @4;
14874 765 : n->target_start = $6;
14875 765 : n->target_end = $8;
14876 765 : n->target_location = @5;
14877 765 : $$ = (Node *) n;
14878 : }
14879 : ;
14880 :
14881 : /*
14882 : * TABLESAMPLE decoration in a FROM item
14883 : */
14884 : tablesample_clause:
14885 : TABLESAMPLE func_name '(' expr_list ')' opt_repeatable_clause
14886 : {
14887 170 : RangeTableSample *n = makeNode(RangeTableSample);
14888 :
14889 : /* n->relation will be filled in later */
14890 170 : n->method = $2;
14891 170 : n->args = $4;
14892 170 : n->repeatable = $6;
14893 170 : n->location = @2;
14894 170 : $$ = (Node *) n;
14895 : }
14896 : ;
14897 :
14898 : opt_repeatable_clause:
14899 71 : REPEATABLE '(' a_expr ')' { $$ = (Node *) $3; }
14900 99 : | /*EMPTY*/ { $$ = NULL; }
14901 : ;
14902 :
14903 : /*
14904 : * func_table represents a function invocation in a FROM list. It can be
14905 : * a plain function call, like "foo(...)", or a ROWS FROM expression with
14906 : * one or more function calls, "ROWS FROM (foo(...), bar(...))",
14907 : * optionally with WITH ORDINALITY attached.
14908 : * In the ROWS FROM syntax, a column definition list can be given for each
14909 : * function, for example:
14910 : * ROWS FROM (foo() AS (foo_res_a text, foo_res_b text),
14911 : * bar() AS (bar_res_a text, bar_res_b text))
14912 : * It's also possible to attach a column definition list to the RangeFunction
14913 : * as a whole, but that's handled by the table_ref production.
14914 : */
14915 : func_table: func_expr_windowless opt_ordinality
14916 : {
14917 30504 : RangeFunction *n = makeNode(RangeFunction);
14918 :
14919 30504 : n->lateral = false;
14920 30504 : n->ordinality = $2;
14921 30504 : n->is_rowsfrom = false;
14922 30504 : n->functions = list_make1(list_make2($1, NIL));
14923 : /* alias and coldeflist are set by table_ref production */
14924 30504 : $$ = (Node *) n;
14925 : }
14926 : | ROWS FROM '(' rowsfrom_list ')' opt_ordinality
14927 : {
14928 88 : RangeFunction *n = makeNode(RangeFunction);
14929 :
14930 88 : n->lateral = false;
14931 88 : n->ordinality = $6;
14932 88 : n->is_rowsfrom = true;
14933 88 : n->functions = $4;
14934 : /* alias and coldeflist are set by table_ref production */
14935 88 : $$ = (Node *) n;
14936 : }
14937 : ;
14938 :
14939 : rowsfrom_item: func_expr_windowless opt_col_def_list
14940 212 : { $$ = list_make2($1, $2); }
14941 : ;
14942 :
14943 : rowsfrom_list:
14944 88 : rowsfrom_item { $$ = list_make1($1); }
14945 124 : | rowsfrom_list ',' rowsfrom_item { $$ = lappend($1, $3); }
14946 : ;
14947 :
14948 36 : opt_col_def_list: AS '(' TableFuncElementList ')' { $$ = $3; }
14949 176 : | /*EMPTY*/ { $$ = NIL; }
14950 : ;
14951 :
14952 617 : opt_ordinality: WITH_LA ORDINALITY { $$ = true; }
14953 29975 : | /*EMPTY*/ { $$ = false; }
14954 : ;
14955 :
14956 :
14957 : where_clause:
14958 143351 : WHERE a_expr { $$ = $2; }
14959 187607 : | /*EMPTY*/ { $$ = NULL; }
14960 : ;
14961 :
14962 : /* variant for UPDATE and DELETE */
14963 : where_or_current_clause:
14964 9244 : WHERE a_expr { $$ = $2; }
14965 : | WHERE CURRENT_P OF cursor_name
14966 : {
14967 176 : CurrentOfExpr *n = makeNode(CurrentOfExpr);
14968 :
14969 : /* cvarno is filled in by parse analysis */
14970 176 : n->cursor_name = $4;
14971 176 : n->cursor_param = 0;
14972 176 : $$ = (Node *) n;
14973 : }
14974 3337 : | /*EMPTY*/ { $$ = NULL; }
14975 : ;
14976 :
14977 :
14978 : OptTableFuncElementList:
14979 469 : TableFuncElementList { $$ = $1; }
14980 1894 : | /*EMPTY*/ { $$ = NIL; }
14981 : ;
14982 :
14983 : TableFuncElementList:
14984 : TableFuncElement
14985 : {
14986 967 : $$ = list_make1($1);
14987 : }
14988 : | TableFuncElementList ',' TableFuncElement
14989 : {
14990 1270 : $$ = lappend($1, $3);
14991 : }
14992 : ;
14993 :
14994 : TableFuncElement: ColId Typename opt_collate_clause
14995 : {
14996 2279 : ColumnDef *n = makeNode(ColumnDef);
14997 :
14998 2279 : n->colname = $1;
14999 2279 : n->typeName = $2;
15000 2279 : n->inhcount = 0;
15001 2279 : n->is_local = true;
15002 2279 : n->is_not_null = false;
15003 2279 : n->is_from_type = false;
15004 2279 : n->storage = 0;
15005 2279 : n->raw_default = NULL;
15006 2279 : n->cooked_default = NULL;
15007 2279 : n->collClause = (CollateClause *) $3;
15008 2279 : n->collOid = InvalidOid;
15009 2279 : n->constraints = NIL;
15010 2279 : n->location = @1;
15011 2279 : $$ = (Node *) n;
15012 : }
15013 : ;
15014 :
15015 : /*
15016 : * XMLTABLE
15017 : */
15018 : xmltable:
15019 : XMLTABLE '(' c_expr xmlexists_argument COLUMNS xmltable_column_list ')'
15020 : {
15021 137 : RangeTableFunc *n = makeNode(RangeTableFunc);
15022 :
15023 137 : n->rowexpr = $3;
15024 137 : n->docexpr = $4;
15025 137 : n->columns = $6;
15026 137 : n->namespaces = NIL;
15027 137 : n->location = @1;
15028 137 : $$ = (Node *) n;
15029 : }
15030 : | XMLTABLE '(' XMLNAMESPACES '(' xml_namespace_list ')' ','
15031 : c_expr xmlexists_argument COLUMNS xmltable_column_list ')'
15032 : {
15033 13 : RangeTableFunc *n = makeNode(RangeTableFunc);
15034 :
15035 13 : n->rowexpr = $8;
15036 13 : n->docexpr = $9;
15037 13 : n->columns = $11;
15038 13 : n->namespaces = $5;
15039 13 : n->location = @1;
15040 13 : $$ = (Node *) n;
15041 : }
15042 : ;
15043 :
15044 150 : xmltable_column_list: xmltable_column_el { $$ = list_make1($1); }
15045 351 : | xmltable_column_list ',' xmltable_column_el { $$ = lappend($1, $3); }
15046 : ;
15047 :
15048 : xmltable_column_el:
15049 : ColId Typename
15050 : {
15051 136 : RangeTableFuncCol *fc = makeNode(RangeTableFuncCol);
15052 :
15053 136 : fc->colname = $1;
15054 136 : fc->for_ordinality = false;
15055 136 : fc->typeName = $2;
15056 136 : fc->is_not_null = false;
15057 136 : fc->colexpr = NULL;
15058 136 : fc->coldefexpr = NULL;
15059 136 : fc->location = @1;
15060 :
15061 136 : $$ = (Node *) fc;
15062 : }
15063 : | ColId Typename xmltable_column_option_list
15064 : {
15065 324 : RangeTableFuncCol *fc = makeNode(RangeTableFuncCol);
15066 : ListCell *option;
15067 324 : bool nullability_seen = false;
15068 :
15069 324 : fc->colname = $1;
15070 324 : fc->typeName = $2;
15071 324 : fc->for_ordinality = false;
15072 324 : fc->is_not_null = false;
15073 324 : fc->colexpr = NULL;
15074 324 : fc->coldefexpr = NULL;
15075 324 : fc->location = @1;
15076 :
15077 722 : foreach(option, $3)
15078 : {
15079 398 : DefElem *defel = (DefElem *) lfirst(option);
15080 :
15081 398 : if (strcmp(defel->defname, "default") == 0)
15082 : {
15083 37 : if (fc->coldefexpr != NULL)
15084 0 : ereport(ERROR,
15085 : (errcode(ERRCODE_SYNTAX_ERROR),
15086 : errmsg("only one DEFAULT value is allowed"),
15087 : parser_errposition(defel->location)));
15088 37 : fc->coldefexpr = defel->arg;
15089 : }
15090 361 : else if (strcmp(defel->defname, "path") == 0)
15091 : {
15092 324 : if (fc->colexpr != NULL)
15093 0 : ereport(ERROR,
15094 : (errcode(ERRCODE_SYNTAX_ERROR),
15095 : errmsg("only one PATH value per column is allowed"),
15096 : parser_errposition(defel->location)));
15097 324 : fc->colexpr = defel->arg;
15098 : }
15099 37 : else if (strcmp(defel->defname, "__pg__is_not_null") == 0)
15100 : {
15101 37 : if (nullability_seen)
15102 0 : ereport(ERROR,
15103 : (errcode(ERRCODE_SYNTAX_ERROR),
15104 : errmsg("conflicting or redundant NULL / NOT NULL declarations for column \"%s\"", fc->colname),
15105 : parser_errposition(defel->location)));
15106 37 : fc->is_not_null = boolVal(defel->arg);
15107 37 : nullability_seen = true;
15108 : }
15109 : else
15110 : {
15111 0 : ereport(ERROR,
15112 : (errcode(ERRCODE_SYNTAX_ERROR),
15113 : errmsg("unrecognized column option \"%s\"",
15114 : defel->defname),
15115 : parser_errposition(defel->location)));
15116 : }
15117 : }
15118 324 : $$ = (Node *) fc;
15119 : }
15120 : | ColId FOR ORDINALITY
15121 : {
15122 41 : RangeTableFuncCol *fc = makeNode(RangeTableFuncCol);
15123 :
15124 41 : fc->colname = $1;
15125 41 : fc->for_ordinality = true;
15126 : /* other fields are ignored, initialized by makeNode */
15127 41 : fc->location = @1;
15128 :
15129 41 : $$ = (Node *) fc;
15130 : }
15131 : ;
15132 :
15133 : xmltable_column_option_list:
15134 : xmltable_column_option_el
15135 324 : { $$ = list_make1($1); }
15136 : | xmltable_column_option_list xmltable_column_option_el
15137 74 : { $$ = lappend($1, $2); }
15138 : ;
15139 :
15140 : xmltable_column_option_el:
15141 : IDENT b_expr
15142 : {
15143 4 : if (strcmp($1, "__pg__is_not_null") == 0)
15144 4 : ereport(ERROR,
15145 : (errcode(ERRCODE_SYNTAX_ERROR),
15146 : errmsg("option name \"%s\" cannot be used in XMLTABLE", $1),
15147 : parser_errposition(@1)));
15148 0 : $$ = makeDefElem($1, $2, @1);
15149 : }
15150 : | DEFAULT b_expr
15151 37 : { $$ = makeDefElem("default", $2, @1); }
15152 : | NOT NULL_P
15153 37 : { $$ = makeDefElem("__pg__is_not_null", (Node *) makeBoolean(true), @1); }
15154 : | NULL_P
15155 0 : { $$ = makeDefElem("__pg__is_not_null", (Node *) makeBoolean(false), @1); }
15156 : | PATH b_expr
15157 324 : { $$ = makeDefElem("path", $2, @1); }
15158 : ;
15159 :
15160 : xml_namespace_list:
15161 : xml_namespace_el
15162 13 : { $$ = list_make1($1); }
15163 : | xml_namespace_list ',' xml_namespace_el
15164 0 : { $$ = lappend($1, $3); }
15165 : ;
15166 :
15167 : xml_namespace_el:
15168 : b_expr AS ColLabel
15169 : {
15170 9 : $$ = makeNode(ResTarget);
15171 9 : $$->name = $3;
15172 9 : $$->indirection = NIL;
15173 9 : $$->val = $1;
15174 9 : $$->location = @1;
15175 : }
15176 : | DEFAULT b_expr
15177 : {
15178 4 : $$ = makeNode(ResTarget);
15179 4 : $$->name = NULL;
15180 4 : $$->indirection = NIL;
15181 4 : $$->val = $2;
15182 4 : $$->location = @1;
15183 : }
15184 : ;
15185 :
15186 : json_table:
15187 : JSON_TABLE '('
15188 : json_value_expr ',' a_expr json_table_path_name_opt
15189 : json_passing_clause_opt
15190 : COLUMNS '(' json_table_column_definition_list ')'
15191 : json_on_error_clause_opt
15192 : ')'
15193 : {
15194 356 : JsonTable *n = makeNode(JsonTable);
15195 : char *pathstring;
15196 :
15197 356 : n->context_item = (JsonValueExpr *) $3;
15198 356 : if (!IsA($5, A_Const) ||
15199 352 : castNode(A_Const, $5)->val.node.type != T_String)
15200 4 : ereport(ERROR,
15201 : errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
15202 : errmsg("only string constants are supported in JSON_TABLE path specification"),
15203 : parser_errposition(@5));
15204 352 : pathstring = castNode(A_Const, $5)->val.sval.sval;
15205 352 : n->pathspec = makeJsonTablePathSpec(pathstring, $6, @5, @6);
15206 352 : n->passing = $7;
15207 352 : n->columns = $10;
15208 352 : n->on_error = (JsonBehavior *) $12;
15209 352 : n->location = @1;
15210 352 : $$ = (Node *) n;
15211 : }
15212 : ;
15213 :
15214 : json_table_path_name_opt:
15215 40 : AS name { $$ = $2; }
15216 324 : | /* empty */ { $$ = NULL; }
15217 : ;
15218 :
15219 : json_table_column_definition_list:
15220 : json_table_column_definition
15221 548 : { $$ = list_make1($1); }
15222 : | json_table_column_definition_list ',' json_table_column_definition
15223 352 : { $$ = lappend($1, $3); }
15224 : ;
15225 :
15226 : json_table_column_definition:
15227 : ColId FOR ORDINALITY
15228 : {
15229 56 : JsonTableColumn *n = makeNode(JsonTableColumn);
15230 :
15231 56 : n->coltype = JTC_FOR_ORDINALITY;
15232 56 : n->name = $1;
15233 56 : n->location = @1;
15234 56 : $$ = (Node *) n;
15235 : }
15236 : | ColId Typename
15237 : json_table_column_path_clause_opt
15238 : json_wrapper_behavior
15239 : json_quotes_clause_opt
15240 : json_behavior_clause_opt
15241 : {
15242 488 : JsonTableColumn *n = makeNode(JsonTableColumn);
15243 :
15244 488 : n->coltype = JTC_REGULAR;
15245 488 : n->name = $1;
15246 488 : n->typeName = $2;
15247 488 : n->format = makeJsonFormat(JS_FORMAT_DEFAULT, JS_ENC_DEFAULT, -1);
15248 488 : n->pathspec = (JsonTablePathSpec *) $3;
15249 488 : n->wrapper = $4;
15250 488 : n->quotes = $5;
15251 488 : n->on_empty = (JsonBehavior *) linitial($6);
15252 488 : n->on_error = (JsonBehavior *) lsecond($6);
15253 488 : n->location = @1;
15254 488 : $$ = (Node *) n;
15255 : }
15256 : | ColId Typename json_format_clause
15257 : json_table_column_path_clause_opt
15258 : json_wrapper_behavior
15259 : json_quotes_clause_opt
15260 : json_behavior_clause_opt
15261 : {
15262 72 : JsonTableColumn *n = makeNode(JsonTableColumn);
15263 :
15264 72 : n->coltype = JTC_FORMATTED;
15265 72 : n->name = $1;
15266 72 : n->typeName = $2;
15267 72 : n->format = (JsonFormat *) $3;
15268 72 : n->pathspec = (JsonTablePathSpec *) $4;
15269 72 : n->wrapper = $5;
15270 72 : n->quotes = $6;
15271 72 : n->on_empty = (JsonBehavior *) linitial($7);
15272 72 : n->on_error = (JsonBehavior *) lsecond($7);
15273 72 : n->location = @1;
15274 72 : $$ = (Node *) n;
15275 : }
15276 : | ColId Typename
15277 : EXISTS json_table_column_path_clause_opt
15278 : json_on_error_clause_opt
15279 : {
15280 92 : JsonTableColumn *n = makeNode(JsonTableColumn);
15281 :
15282 92 : n->coltype = JTC_EXISTS;
15283 92 : n->name = $1;
15284 92 : n->typeName = $2;
15285 92 : n->format = makeJsonFormat(JS_FORMAT_DEFAULT, JS_ENC_DEFAULT, -1);
15286 92 : n->wrapper = JSW_NONE;
15287 92 : n->quotes = JS_QUOTES_UNSPEC;
15288 92 : n->pathspec = (JsonTablePathSpec *) $4;
15289 92 : n->on_empty = NULL;
15290 92 : n->on_error = (JsonBehavior *) $5;
15291 92 : n->location = @1;
15292 92 : $$ = (Node *) n;
15293 : }
15294 : | NESTED path_opt Sconst
15295 : COLUMNS '(' json_table_column_definition_list ')'
15296 : {
15297 96 : JsonTableColumn *n = makeNode(JsonTableColumn);
15298 :
15299 96 : n->coltype = JTC_NESTED;
15300 192 : n->pathspec = (JsonTablePathSpec *)
15301 96 : makeJsonTablePathSpec($3, NULL, @3, -1);
15302 96 : n->columns = $6;
15303 96 : n->location = @1;
15304 96 : $$ = (Node *) n;
15305 : }
15306 : | NESTED path_opt Sconst AS name
15307 : COLUMNS '(' json_table_column_definition_list ')'
15308 : {
15309 96 : JsonTableColumn *n = makeNode(JsonTableColumn);
15310 :
15311 96 : n->coltype = JTC_NESTED;
15312 192 : n->pathspec = (JsonTablePathSpec *)
15313 96 : makeJsonTablePathSpec($3, $5, @3, @5);
15314 96 : n->columns = $8;
15315 96 : n->location = @1;
15316 96 : $$ = (Node *) n;
15317 : }
15318 : ;
15319 :
15320 : path_opt:
15321 : PATH
15322 : | /* EMPTY */
15323 : ;
15324 :
15325 : json_table_column_path_clause_opt:
15326 : PATH Sconst
15327 552 : { $$ = (Node *) makeJsonTablePathSpec($2, NULL, @2, -1); }
15328 : | /* EMPTY */
15329 104 : { $$ = NULL; }
15330 : ;
15331 :
15332 : /*****************************************************************************
15333 : *
15334 : * Type syntax
15335 : * SQL introduces a large amount of type-specific syntax.
15336 : * Define individual clauses to handle these cases, and use
15337 : * the generic case to handle regular type-extensible Postgres syntax.
15338 : * - thomas 1997-10-10
15339 : *
15340 : *****************************************************************************/
15341 :
15342 : Typename: SimpleTypename opt_array_bounds
15343 : {
15344 308696 : $$ = $1;
15345 308696 : $$->arrayBounds = $2;
15346 : }
15347 : | SETOF SimpleTypename opt_array_bounds
15348 : {
15349 1034 : $$ = $2;
15350 1034 : $$->arrayBounds = $3;
15351 1034 : $$->setof = true;
15352 : }
15353 : /* SQL standard syntax, currently only one-dimensional */
15354 : | SimpleTypename ARRAY '[' Iconst ']'
15355 : {
15356 4 : $$ = $1;
15357 4 : $$->arrayBounds = list_make1(makeInteger($4));
15358 : }
15359 : | SETOF SimpleTypename ARRAY '[' Iconst ']'
15360 : {
15361 0 : $$ = $2;
15362 0 : $$->arrayBounds = list_make1(makeInteger($5));
15363 0 : $$->setof = true;
15364 : }
15365 : | SimpleTypename ARRAY
15366 : {
15367 0 : $$ = $1;
15368 0 : $$->arrayBounds = list_make1(makeInteger(-1));
15369 : }
15370 : | SETOF SimpleTypename ARRAY
15371 : {
15372 0 : $$ = $2;
15373 0 : $$->arrayBounds = list_make1(makeInteger(-1));
15374 0 : $$->setof = true;
15375 : }
15376 : ;
15377 :
15378 : opt_array_bounds:
15379 : opt_array_bounds '[' ']'
15380 8750 : { $$ = lappend($1, makeInteger(-1)); }
15381 : | opt_array_bounds '[' Iconst ']'
15382 38 : { $$ = lappend($1, makeInteger($3)); }
15383 : | /*EMPTY*/
15384 309730 : { $$ = NIL; }
15385 : ;
15386 :
15387 : SimpleTypename:
15388 244248 : GenericType { $$ = $1; }
15389 55808 : | Numeric { $$ = $1; }
15390 1275 : | Bit { $$ = $1; }
15391 2198 : | Character { $$ = $1; }
15392 3051 : | ConstDatetime { $$ = $1; }
15393 : | ConstInterval opt_interval
15394 : {
15395 2244 : $$ = $1;
15396 2244 : $$->typmods = $2;
15397 : }
15398 : | ConstInterval '(' Iconst ')'
15399 : {
15400 0 : $$ = $1;
15401 0 : $$->typmods = list_make2(makeIntConst(INTERVAL_FULL_RANGE, -1),
15402 : makeIntConst($3, @3));
15403 : }
15404 1173 : | JsonType { $$ = $1; }
15405 : ;
15406 :
15407 : /* We have a separate ConstTypename to allow defaulting fixed-length
15408 : * types such as CHAR() and BIT() to an unspecified length.
15409 : * SQL9x requires that these default to a length of one, but this
15410 : * makes no sense for constructs like CHAR 'hi' and BIT '0101',
15411 : * where there is an obvious better choice to make.
15412 : * Note that ConstInterval is not included here since it must
15413 : * be pushed up higher in the rules to accommodate the postfix
15414 : * options (e.g. INTERVAL '1' YEAR). Likewise, we have to handle
15415 : * the generic-type-name case in AexprConst to avoid premature
15416 : * reduce/reduce conflicts against function names.
15417 : */
15418 : ConstTypename:
15419 52 : Numeric { $$ = $1; }
15420 0 : | ConstBit { $$ = $1; }
15421 22 : | ConstCharacter { $$ = $1; }
15422 1793 : | ConstDatetime { $$ = $1; }
15423 176 : | JsonType { $$ = $1; }
15424 : ;
15425 :
15426 : /*
15427 : * GenericType covers all type names that don't have special syntax mandated
15428 : * by the standard, including qualified names. We also allow type modifiers.
15429 : * To avoid parsing conflicts against function invocations, the modifiers
15430 : * have to be shown as expr_list here, but parse analysis will only accept
15431 : * constants for them.
15432 : */
15433 : GenericType:
15434 : type_function_name opt_type_modifiers
15435 : {
15436 173475 : $$ = makeTypeName($1);
15437 173475 : $$->typmods = $2;
15438 173475 : $$->location = @1;
15439 : }
15440 : | type_function_name attrs opt_type_modifiers
15441 : {
15442 70773 : $$ = makeTypeNameFromNameList(lcons(makeString($1), $2));
15443 70773 : $$->typmods = $3;
15444 70773 : $$->location = @1;
15445 : }
15446 : ;
15447 :
15448 776 : opt_type_modifiers: '(' expr_list ')' { $$ = $2; }
15449 247434 : | /* EMPTY */ { $$ = NIL; }
15450 : ;
15451 :
15452 : /*
15453 : * SQL numeric data types
15454 : */
15455 : Numeric: INT_P
15456 : {
15457 25787 : $$ = SystemTypeName("int4");
15458 25787 : $$->location = @1;
15459 : }
15460 : | INTEGER
15461 : {
15462 13859 : $$ = SystemTypeName("int4");
15463 13859 : $$->location = @1;
15464 : }
15465 : | SMALLINT
15466 : {
15467 710 : $$ = SystemTypeName("int2");
15468 710 : $$->location = @1;
15469 : }
15470 : | BIGINT
15471 : {
15472 2679 : $$ = SystemTypeName("int8");
15473 2679 : $$->location = @1;
15474 : }
15475 : | REAL
15476 : {
15477 3681 : $$ = SystemTypeName("float4");
15478 3681 : $$->location = @1;
15479 : }
15480 : | FLOAT_P opt_float
15481 : {
15482 350 : $$ = $2;
15483 350 : $$->location = @1;
15484 : }
15485 : | DOUBLE_P PRECISION
15486 : {
15487 465 : $$ = SystemTypeName("float8");
15488 465 : $$->location = @1;
15489 : }
15490 : | DECIMAL_P opt_type_modifiers
15491 : {
15492 142 : $$ = SystemTypeName("numeric");
15493 142 : $$->typmods = $2;
15494 142 : $$->location = @1;
15495 : }
15496 : | DEC opt_type_modifiers
15497 : {
15498 0 : $$ = SystemTypeName("numeric");
15499 0 : $$->typmods = $2;
15500 0 : $$->location = @1;
15501 : }
15502 : | NUMERIC opt_type_modifiers
15503 : {
15504 3820 : $$ = SystemTypeName("numeric");
15505 3820 : $$->typmods = $2;
15506 3820 : $$->location = @1;
15507 : }
15508 : | BOOLEAN_P
15509 : {
15510 4367 : $$ = SystemTypeName("bool");
15511 4367 : $$->location = @1;
15512 : }
15513 : ;
15514 :
15515 : opt_float: '(' Iconst ')'
15516 : {
15517 : /*
15518 : * Check FLOAT() precision limits assuming IEEE floating
15519 : * types - thomas 1997-09-18
15520 : */
15521 1 : if ($2 < 1)
15522 0 : ereport(ERROR,
15523 : (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
15524 : errmsg("precision for type float must be at least 1 bit"),
15525 : parser_errposition(@2)));
15526 1 : else if ($2 <= 24)
15527 1 : $$ = SystemTypeName("float4");
15528 0 : else if ($2 <= 53)
15529 0 : $$ = SystemTypeName("float8");
15530 : else
15531 0 : ereport(ERROR,
15532 : (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
15533 : errmsg("precision for type float must be less than 54 bits"),
15534 : parser_errposition(@2)));
15535 : }
15536 : | /*EMPTY*/
15537 : {
15538 349 : $$ = SystemTypeName("float8");
15539 : }
15540 : ;
15541 :
15542 : /*
15543 : * SQL bit-field data types
15544 : * The following implements BIT() and BIT VARYING().
15545 : */
15546 : Bit: BitWithLength
15547 : {
15548 1146 : $$ = $1;
15549 : }
15550 : | BitWithoutLength
15551 : {
15552 129 : $$ = $1;
15553 : }
15554 : ;
15555 :
15556 : /* ConstBit is like Bit except "BIT" defaults to unspecified length */
15557 : /* See notes for ConstCharacter, which addresses same issue for "CHAR" */
15558 : ConstBit: BitWithLength
15559 : {
15560 0 : $$ = $1;
15561 : }
15562 : | BitWithoutLength
15563 : {
15564 0 : $$ = $1;
15565 0 : $$->typmods = NIL;
15566 : }
15567 : ;
15568 :
15569 : BitWithLength:
15570 : BIT opt_varying '(' expr_list ')'
15571 : {
15572 : char *typname;
15573 :
15574 1146 : typname = $2 ? "varbit" : "bit";
15575 1146 : $$ = SystemTypeName(typname);
15576 1146 : $$->typmods = $4;
15577 1146 : $$->location = @1;
15578 : }
15579 : ;
15580 :
15581 : BitWithoutLength:
15582 : BIT opt_varying
15583 : {
15584 : /* bit defaults to bit(1), varbit to no limit */
15585 129 : if ($2)
15586 : {
15587 10 : $$ = SystemTypeName("varbit");
15588 : }
15589 : else
15590 : {
15591 119 : $$ = SystemTypeName("bit");
15592 119 : $$->typmods = list_make1(makeIntConst(1, -1));
15593 : }
15594 129 : $$->location = @1;
15595 : }
15596 : ;
15597 :
15598 :
15599 : /*
15600 : * SQL character data types
15601 : * The following implements CHAR() and VARCHAR().
15602 : */
15603 : Character: CharacterWithLength
15604 : {
15605 1341 : $$ = $1;
15606 : }
15607 : | CharacterWithoutLength
15608 : {
15609 857 : $$ = $1;
15610 : }
15611 : ;
15612 :
15613 : ConstCharacter: CharacterWithLength
15614 : {
15615 8 : $$ = $1;
15616 : }
15617 : | CharacterWithoutLength
15618 : {
15619 : /* Length was not specified so allow to be unrestricted.
15620 : * This handles problems with fixed-length (bpchar) strings
15621 : * which in column definitions must default to a length
15622 : * of one, but should not be constrained if the length
15623 : * was not specified.
15624 : */
15625 14 : $$ = $1;
15626 14 : $$->typmods = NIL;
15627 : }
15628 : ;
15629 :
15630 : CharacterWithLength: character '(' Iconst ')'
15631 : {
15632 1349 : $$ = SystemTypeName($1);
15633 1349 : $$->typmods = list_make1(makeIntConst($3, @3));
15634 1349 : $$->location = @1;
15635 : }
15636 : ;
15637 :
15638 : CharacterWithoutLength: character
15639 : {
15640 871 : $$ = SystemTypeName($1);
15641 : /* char defaults to char(1), varchar to no limit */
15642 871 : if (strcmp($1, "bpchar") == 0)
15643 154 : $$->typmods = list_make1(makeIntConst(1, -1));
15644 871 : $$->location = @1;
15645 : }
15646 : ;
15647 :
15648 : character: CHARACTER opt_varying
15649 331 : { $$ = $2 ? "varchar": "bpchar"; }
15650 : | CHAR_P opt_varying
15651 745 : { $$ = $2 ? "varchar": "bpchar"; }
15652 : | VARCHAR
15653 1142 : { $$ = "varchar"; }
15654 : | NATIONAL CHARACTER opt_varying
15655 0 : { $$ = $3 ? "varchar": "bpchar"; }
15656 : | NATIONAL CHAR_P opt_varying
15657 0 : { $$ = $3 ? "varchar": "bpchar"; }
15658 : | NCHAR opt_varying
15659 2 : { $$ = $2 ? "varchar": "bpchar"; }
15660 : ;
15661 :
15662 : opt_varying:
15663 285 : VARYING { $$ = true; }
15664 2068 : | /*EMPTY*/ { $$ = false; }
15665 : ;
15666 :
15667 : /*
15668 : * SQL date/time types
15669 : */
15670 : ConstDatetime:
15671 : TIMESTAMP '(' Iconst ')' opt_timezone
15672 : {
15673 79 : if ($5)
15674 64 : $$ = SystemTypeName("timestamptz");
15675 : else
15676 15 : $$ = SystemTypeName("timestamp");
15677 79 : $$->typmods = list_make1(makeIntConst($3, @3));
15678 79 : $$->location = @1;
15679 : }
15680 : | TIMESTAMP opt_timezone
15681 : {
15682 3218 : if ($2)
15683 782 : $$ = SystemTypeName("timestamptz");
15684 : else
15685 2436 : $$ = SystemTypeName("timestamp");
15686 3218 : $$->location = @1;
15687 : }
15688 : | TIME '(' Iconst ')' opt_timezone
15689 : {
15690 14 : if ($5)
15691 5 : $$ = SystemTypeName("timetz");
15692 : else
15693 9 : $$ = SystemTypeName("time");
15694 14 : $$->typmods = list_make1(makeIntConst($3, @3));
15695 14 : $$->location = @1;
15696 : }
15697 : | TIME opt_timezone
15698 : {
15699 1533 : if ($2)
15700 226 : $$ = SystemTypeName("timetz");
15701 : else
15702 1307 : $$ = SystemTypeName("time");
15703 1533 : $$->location = @1;
15704 : }
15705 : ;
15706 :
15707 : ConstInterval:
15708 : INTERVAL
15709 : {
15710 4460 : $$ = SystemTypeName("interval");
15711 4460 : $$->location = @1;
15712 : }
15713 : ;
15714 :
15715 : opt_timezone:
15716 1077 : WITH_LA TIME ZONE { $$ = true; }
15717 376 : | WITHOUT_LA TIME ZONE { $$ = false; }
15718 3391 : | /*EMPTY*/ { $$ = false; }
15719 : ;
15720 :
15721 : /*
15722 : * We need to handle this shift/reduce conflict:
15723 : * FOR PORTION OF valid_at FROM t + INTERVAL '1' YEAR TO MONTH.
15724 : * We don't see far enough ahead to know if there is another TO coming.
15725 : * We prefer to interpret this as FROM (t + INTERVAL '1' YEAR TO MONTH),
15726 : * i.e. to shift.
15727 : * That gives the user the option of adding parentheses to get the other meaning.
15728 : * If we reduced, intervals could never have a TO.
15729 : */
15730 : opt_interval:
15731 : YEAR_P %prec IS
15732 8 : { $$ = list_make1(makeIntConst(INTERVAL_MASK(YEAR), @1)); }
15733 : | MONTH_P
15734 12 : { $$ = list_make1(makeIntConst(INTERVAL_MASK(MONTH), @1)); }
15735 : | DAY_P %prec IS
15736 12 : { $$ = list_make1(makeIntConst(INTERVAL_MASK(DAY), @1)); }
15737 : | HOUR_P %prec IS
15738 12 : { $$ = list_make1(makeIntConst(INTERVAL_MASK(HOUR), @1)); }
15739 : | MINUTE_P %prec IS
15740 8 : { $$ = list_make1(makeIntConst(INTERVAL_MASK(MINUTE), @1)); }
15741 : | interval_second
15742 24 : { $$ = $1; }
15743 : | YEAR_P TO MONTH_P
15744 : {
15745 12 : $$ = list_make1(makeIntConst(INTERVAL_MASK(YEAR) |
15746 : INTERVAL_MASK(MONTH), @1));
15747 : }
15748 : | DAY_P TO HOUR_P
15749 : {
15750 16 : $$ = list_make1(makeIntConst(INTERVAL_MASK(DAY) |
15751 : INTERVAL_MASK(HOUR), @1));
15752 : }
15753 : | DAY_P TO MINUTE_P
15754 : {
15755 16 : $$ = list_make1(makeIntConst(INTERVAL_MASK(DAY) |
15756 : INTERVAL_MASK(HOUR) |
15757 : INTERVAL_MASK(MINUTE), @1));
15758 : }
15759 : | DAY_P TO interval_second
15760 : {
15761 32 : $$ = $3;
15762 32 : linitial($$) = makeIntConst(INTERVAL_MASK(DAY) |
15763 : INTERVAL_MASK(HOUR) |
15764 : INTERVAL_MASK(MINUTE) |
15765 32 : INTERVAL_MASK(SECOND), @1);
15766 : }
15767 : | HOUR_P TO MINUTE_P
15768 : {
15769 16 : $$ = list_make1(makeIntConst(INTERVAL_MASK(HOUR) |
15770 : INTERVAL_MASK(MINUTE), @1));
15771 : }
15772 : | HOUR_P TO interval_second
15773 : {
15774 24 : $$ = $3;
15775 24 : linitial($$) = makeIntConst(INTERVAL_MASK(HOUR) |
15776 : INTERVAL_MASK(MINUTE) |
15777 24 : INTERVAL_MASK(SECOND), @1);
15778 : }
15779 : | MINUTE_P TO interval_second
15780 : {
15781 44 : $$ = $3;
15782 44 : linitial($$) = makeIntConst(INTERVAL_MASK(MINUTE) |
15783 44 : INTERVAL_MASK(SECOND), @1);
15784 : }
15785 : | /*EMPTY*/
15786 4212 : { $$ = NIL; }
15787 : ;
15788 :
15789 : interval_second:
15790 : SECOND_P
15791 : {
15792 68 : $$ = list_make1(makeIntConst(INTERVAL_MASK(SECOND), @1));
15793 : }
15794 : | SECOND_P '(' Iconst ')'
15795 : {
15796 56 : $$ = list_make2(makeIntConst(INTERVAL_MASK(SECOND), @1),
15797 : makeIntConst($3, @3));
15798 : }
15799 : ;
15800 :
15801 : JsonType:
15802 : JSON
15803 : {
15804 1349 : $$ = SystemTypeName("json");
15805 1349 : $$->location = @1;
15806 : }
15807 : ;
15808 :
15809 : /*****************************************************************************
15810 : *
15811 : * expression grammar
15812 : *
15813 : *****************************************************************************/
15814 :
15815 : /*
15816 : * General expressions
15817 : * This is the heart of the expression syntax.
15818 : *
15819 : * We have two expression types: a_expr is the unrestricted kind, and
15820 : * b_expr is a subset that must be used in some places to avoid shift/reduce
15821 : * conflicts. For example, we can't do BETWEEN as "BETWEEN a_expr AND a_expr"
15822 : * because that use of AND conflicts with AND as a boolean operator. So,
15823 : * b_expr is used in BETWEEN and we remove boolean keywords from b_expr.
15824 : *
15825 : * Note that '(' a_expr ')' is a b_expr, so an unrestricted expression can
15826 : * always be used by surrounding it with parens.
15827 : *
15828 : * c_expr is all the productions that are common to a_expr and b_expr;
15829 : * it's factored out just to eliminate redundant coding.
15830 : *
15831 : * Be careful of productions involving more than one terminal token.
15832 : * By default, bison will assign such productions the precedence of their
15833 : * last terminal, but in nearly all cases you want it to be the precedence
15834 : * of the first terminal instead; otherwise you will not get the behavior
15835 : * you expect! So we use %prec annotations freely to set precedences.
15836 : */
15837 2448941 : a_expr: c_expr { $$ = $1; }
15838 : | a_expr TYPECAST Typename
15839 147948 : { $$ = makeTypeCast($1, $3, @2); }
15840 : | a_expr COLLATE any_name
15841 : {
15842 6538 : CollateClause *n = makeNode(CollateClause);
15843 :
15844 6538 : n->arg = $1;
15845 6538 : n->collname = $3;
15846 6538 : n->location = @2;
15847 6538 : $$ = (Node *) n;
15848 : }
15849 : | a_expr AT TIME ZONE a_expr %prec AT
15850 : {
15851 272 : $$ = (Node *) makeFuncCall(SystemFuncName("timezone"),
15852 272 : list_make2($5, $1),
15853 : COERCE_SQL_SYNTAX,
15854 272 : @2);
15855 : }
15856 : | a_expr AT LOCAL %prec AT
15857 : {
15858 28 : $$ = (Node *) makeFuncCall(SystemFuncName("timezone"),
15859 28 : list_make1($1),
15860 : COERCE_SQL_SYNTAX,
15861 : -1);
15862 : }
15863 : /*
15864 : * These operators must be called out explicitly in order to make use
15865 : * of bison's automatic operator-precedence handling. All other
15866 : * operator names are handled by the generic productions using "Op",
15867 : * below; and all those operators will have the same precedence.
15868 : *
15869 : * If you add more explicitly-known operators, be sure to add them
15870 : * also to b_expr and to the MathOp list below.
15871 : */
15872 : | '+' a_expr %prec UMINUS
15873 8 : { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "+", NULL, $2, @1); }
15874 : | '-' a_expr %prec UMINUS
15875 6351 : { $$ = doNegate($2, @1); }
15876 : | a_expr '+' a_expr
15877 9550 : { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "+", $1, $3, @2); }
15878 : | a_expr '-' a_expr
15879 2843 : { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "-", $1, $3, @2); }
15880 : | a_expr '*' a_expr
15881 4156 : { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "*", $1, $3, @2); }
15882 : | a_expr '/' a_expr
15883 2190 : { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "/", $1, $3, @2); }
15884 : | a_expr '%' a_expr
15885 2012 : { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "%", $1, $3, @2); }
15886 : | a_expr '^' a_expr
15887 312 : { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "^", $1, $3, @2); }
15888 : | a_expr '<' a_expr
15889 6833 : { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "<", $1, $3, @2); }
15890 : | a_expr '>' a_expr
15891 11059 : { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, ">", $1, $3, @2); }
15892 : | a_expr '=' a_expr
15893 265091 : { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "=", $1, $3, @2); }
15894 : | a_expr LESS_EQUALS a_expr
15895 2908 : { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "<=", $1, $3, @2); }
15896 : | a_expr GREATER_EQUALS a_expr
15897 7428 : { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, ">=", $1, $3, @2); }
15898 : | a_expr NOT_EQUALS a_expr
15899 25307 : { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "<>", $1, $3, @2); }
15900 : | a_expr RIGHT_ARROW a_expr
15901 540 : { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "->", $1, $3, @2); }
15902 : | a_expr '|' a_expr
15903 57 : { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "|", $1, $3, @2); }
15904 :
15905 : | a_expr qual_Op a_expr %prec Op
15906 36830 : { $$ = (Node *) makeA_Expr(AEXPR_OP, $2, $1, $3, @2); }
15907 : | qual_Op a_expr %prec Op
15908 157 : { $$ = (Node *) makeA_Expr(AEXPR_OP, $1, NULL, $2, @1); }
15909 :
15910 : | a_expr AND a_expr
15911 157142 : { $$ = makeAndExpr($1, $3, @2); }
15912 : | a_expr OR a_expr
15913 15069 : { $$ = makeOrExpr($1, $3, @2); }
15914 : | NOT a_expr
15915 15857 : { $$ = makeNotExpr($2, @1); }
15916 : | NOT_LA a_expr %prec NOT
15917 0 : { $$ = makeNotExpr($2, @1); }
15918 :
15919 : | a_expr LIKE a_expr
15920 : {
15921 1273 : $$ = (Node *) makeSimpleA_Expr(AEXPR_LIKE, "~~",
15922 1273 : $1, $3, @2);
15923 : }
15924 : | a_expr LIKE a_expr ESCAPE a_expr %prec LIKE
15925 : {
15926 64 : FuncCall *n = makeFuncCall(SystemFuncName("like_escape"),
15927 64 : list_make2($3, $5),
15928 : COERCE_EXPLICIT_CALL,
15929 64 : @2);
15930 64 : $$ = (Node *) makeSimpleA_Expr(AEXPR_LIKE, "~~",
15931 64 : $1, (Node *) n, @2);
15932 : }
15933 : | a_expr NOT_LA LIKE a_expr %prec NOT_LA
15934 : {
15935 128 : $$ = (Node *) makeSimpleA_Expr(AEXPR_LIKE, "!~~",
15936 128 : $1, $4, @2);
15937 : }
15938 : | a_expr NOT_LA LIKE a_expr ESCAPE a_expr %prec NOT_LA
15939 : {
15940 64 : FuncCall *n = makeFuncCall(SystemFuncName("like_escape"),
15941 64 : list_make2($4, $6),
15942 : COERCE_EXPLICIT_CALL,
15943 64 : @2);
15944 64 : $$ = (Node *) makeSimpleA_Expr(AEXPR_LIKE, "!~~",
15945 64 : $1, (Node *) n, @2);
15946 : }
15947 : | a_expr ILIKE a_expr
15948 : {
15949 112 : $$ = (Node *) makeSimpleA_Expr(AEXPR_ILIKE, "~~*",
15950 112 : $1, $3, @2);
15951 : }
15952 : | a_expr ILIKE a_expr ESCAPE a_expr %prec ILIKE
15953 : {
15954 0 : FuncCall *n = makeFuncCall(SystemFuncName("like_escape"),
15955 0 : list_make2($3, $5),
15956 : COERCE_EXPLICIT_CALL,
15957 0 : @2);
15958 0 : $$ = (Node *) makeSimpleA_Expr(AEXPR_ILIKE, "~~*",
15959 0 : $1, (Node *) n, @2);
15960 : }
15961 : | a_expr NOT_LA ILIKE a_expr %prec NOT_LA
15962 : {
15963 20 : $$ = (Node *) makeSimpleA_Expr(AEXPR_ILIKE, "!~~*",
15964 20 : $1, $4, @2);
15965 : }
15966 : | a_expr NOT_LA ILIKE a_expr ESCAPE a_expr %prec NOT_LA
15967 : {
15968 0 : FuncCall *n = makeFuncCall(SystemFuncName("like_escape"),
15969 0 : list_make2($4, $6),
15970 : COERCE_EXPLICIT_CALL,
15971 0 : @2);
15972 0 : $$ = (Node *) makeSimpleA_Expr(AEXPR_ILIKE, "!~~*",
15973 0 : $1, (Node *) n, @2);
15974 : }
15975 :
15976 : | a_expr SIMILAR TO a_expr %prec SIMILAR
15977 : {
15978 58 : FuncCall *n = makeFuncCall(SystemFuncName("similar_to_escape"),
15979 58 : list_make1($4),
15980 : COERCE_EXPLICIT_CALL,
15981 58 : @2);
15982 58 : $$ = (Node *) makeSimpleA_Expr(AEXPR_SIMILAR, "~",
15983 58 : $1, (Node *) n, @2);
15984 : }
15985 : | a_expr SIMILAR TO a_expr ESCAPE a_expr %prec SIMILAR
15986 : {
15987 24 : FuncCall *n = makeFuncCall(SystemFuncName("similar_to_escape"),
15988 24 : list_make2($4, $6),
15989 : COERCE_EXPLICIT_CALL,
15990 24 : @2);
15991 24 : $$ = (Node *) makeSimpleA_Expr(AEXPR_SIMILAR, "~",
15992 24 : $1, (Node *) n, @2);
15993 : }
15994 : | a_expr NOT_LA SIMILAR TO a_expr %prec NOT_LA
15995 : {
15996 0 : FuncCall *n = makeFuncCall(SystemFuncName("similar_to_escape"),
15997 0 : list_make1($5),
15998 : COERCE_EXPLICIT_CALL,
15999 0 : @2);
16000 0 : $$ = (Node *) makeSimpleA_Expr(AEXPR_SIMILAR, "!~",
16001 0 : $1, (Node *) n, @2);
16002 : }
16003 : | a_expr NOT_LA SIMILAR TO a_expr ESCAPE a_expr %prec NOT_LA
16004 : {
16005 0 : FuncCall *n = makeFuncCall(SystemFuncName("similar_to_escape"),
16006 0 : list_make2($5, $7),
16007 : COERCE_EXPLICIT_CALL,
16008 0 : @2);
16009 0 : $$ = (Node *) makeSimpleA_Expr(AEXPR_SIMILAR, "!~",
16010 0 : $1, (Node *) n, @2);
16011 : }
16012 :
16013 : /* NullTest clause
16014 : * Define SQL-style Null test clause.
16015 : * Allow two forms described in the standard:
16016 : * a IS NULL
16017 : * a IS NOT NULL
16018 : * Allow two SQL extensions
16019 : * a ISNULL
16020 : * a NOTNULL
16021 : */
16022 : | a_expr IS NULL_P %prec IS
16023 : {
16024 3608 : NullTest *n = makeNode(NullTest);
16025 :
16026 3608 : n->arg = (Expr *) $1;
16027 3608 : n->nulltesttype = IS_NULL;
16028 3608 : n->location = @2;
16029 3608 : $$ = (Node *) n;
16030 : }
16031 : | a_expr ISNULL
16032 : {
16033 68 : NullTest *n = makeNode(NullTest);
16034 :
16035 68 : n->arg = (Expr *) $1;
16036 68 : n->nulltesttype = IS_NULL;
16037 68 : n->location = @2;
16038 68 : $$ = (Node *) n;
16039 : }
16040 : | a_expr IS NOT NULL_P %prec IS
16041 : {
16042 8536 : NullTest *n = makeNode(NullTest);
16043 :
16044 8536 : n->arg = (Expr *) $1;
16045 8536 : n->nulltesttype = IS_NOT_NULL;
16046 8536 : n->location = @2;
16047 8536 : $$ = (Node *) n;
16048 : }
16049 : | a_expr NOTNULL
16050 : {
16051 4 : NullTest *n = makeNode(NullTest);
16052 :
16053 4 : n->arg = (Expr *) $1;
16054 4 : n->nulltesttype = IS_NOT_NULL;
16055 4 : n->location = @2;
16056 4 : $$ = (Node *) n;
16057 : }
16058 : | row OVERLAPS row
16059 : {
16060 563 : if (list_length($1) != 2)
16061 0 : ereport(ERROR,
16062 : (errcode(ERRCODE_SYNTAX_ERROR),
16063 : errmsg("wrong number of parameters on left side of OVERLAPS expression"),
16064 : parser_errposition(@1)));
16065 563 : if (list_length($3) != 2)
16066 0 : ereport(ERROR,
16067 : (errcode(ERRCODE_SYNTAX_ERROR),
16068 : errmsg("wrong number of parameters on right side of OVERLAPS expression"),
16069 : parser_errposition(@3)));
16070 563 : $$ = (Node *) makeFuncCall(SystemFuncName("overlaps"),
16071 563 : list_concat($1, $3),
16072 : COERCE_SQL_SYNTAX,
16073 563 : @2);
16074 : }
16075 : | a_expr IS TRUE_P %prec IS
16076 : {
16077 322 : BooleanTest *b = makeNode(BooleanTest);
16078 :
16079 322 : b->arg = (Expr *) $1;
16080 322 : b->booltesttype = IS_TRUE;
16081 322 : b->location = @2;
16082 322 : $$ = (Node *) b;
16083 : }
16084 : | a_expr IS NOT TRUE_P %prec IS
16085 : {
16086 100 : BooleanTest *b = makeNode(BooleanTest);
16087 :
16088 100 : b->arg = (Expr *) $1;
16089 100 : b->booltesttype = IS_NOT_TRUE;
16090 100 : b->location = @2;
16091 100 : $$ = (Node *) b;
16092 : }
16093 : | a_expr IS FALSE_P %prec IS
16094 : {
16095 152 : BooleanTest *b = makeNode(BooleanTest);
16096 :
16097 152 : b->arg = (Expr *) $1;
16098 152 : b->booltesttype = IS_FALSE;
16099 152 : b->location = @2;
16100 152 : $$ = (Node *) b;
16101 : }
16102 : | a_expr IS NOT FALSE_P %prec IS
16103 : {
16104 69 : BooleanTest *b = makeNode(BooleanTest);
16105 :
16106 69 : b->arg = (Expr *) $1;
16107 69 : b->booltesttype = IS_NOT_FALSE;
16108 69 : b->location = @2;
16109 69 : $$ = (Node *) b;
16110 : }
16111 : | a_expr IS UNKNOWN %prec IS
16112 : {
16113 50 : BooleanTest *b = makeNode(BooleanTest);
16114 :
16115 50 : b->arg = (Expr *) $1;
16116 50 : b->booltesttype = IS_UNKNOWN;
16117 50 : b->location = @2;
16118 50 : $$ = (Node *) b;
16119 : }
16120 : | a_expr IS NOT UNKNOWN %prec IS
16121 : {
16122 40 : BooleanTest *b = makeNode(BooleanTest);
16123 :
16124 40 : b->arg = (Expr *) $1;
16125 40 : b->booltesttype = IS_NOT_UNKNOWN;
16126 40 : b->location = @2;
16127 40 : $$ = (Node *) b;
16128 : }
16129 : | a_expr IS DISTINCT FROM a_expr %prec IS
16130 : {
16131 783 : $$ = (Node *) makeSimpleA_Expr(AEXPR_DISTINCT, "=", $1, $5, @2);
16132 : }
16133 : | a_expr IS NOT DISTINCT FROM a_expr %prec IS
16134 : {
16135 84 : $$ = (Node *) makeSimpleA_Expr(AEXPR_NOT_DISTINCT, "=", $1, $6, @2);
16136 : }
16137 : | a_expr BETWEEN opt_asymmetric b_expr AND a_expr %prec BETWEEN
16138 : {
16139 308 : $$ = (Node *) makeSimpleA_Expr(AEXPR_BETWEEN,
16140 : "BETWEEN",
16141 308 : $1,
16142 308 : (Node *) list_make2($4, $6),
16143 308 : @2);
16144 : }
16145 : | a_expr NOT_LA BETWEEN opt_asymmetric b_expr AND a_expr %prec NOT_LA
16146 : {
16147 8 : $$ = (Node *) makeSimpleA_Expr(AEXPR_NOT_BETWEEN,
16148 : "NOT BETWEEN",
16149 8 : $1,
16150 8 : (Node *) list_make2($5, $7),
16151 8 : @2);
16152 : }
16153 : | a_expr BETWEEN SYMMETRIC b_expr AND a_expr %prec BETWEEN
16154 : {
16155 8 : $$ = (Node *) makeSimpleA_Expr(AEXPR_BETWEEN_SYM,
16156 : "BETWEEN SYMMETRIC",
16157 8 : $1,
16158 8 : (Node *) list_make2($4, $6),
16159 8 : @2);
16160 : }
16161 : | a_expr NOT_LA BETWEEN SYMMETRIC b_expr AND a_expr %prec NOT_LA
16162 : {
16163 8 : $$ = (Node *) makeSimpleA_Expr(AEXPR_NOT_BETWEEN_SYM,
16164 : "NOT BETWEEN SYMMETRIC",
16165 8 : $1,
16166 8 : (Node *) list_make2($5, $7),
16167 8 : @2);
16168 : }
16169 : | a_expr IN_P select_with_parens
16170 : {
16171 : /* generate foo = ANY (subquery) */
16172 3652 : SubLink *n = makeNode(SubLink);
16173 :
16174 3652 : n->subselect = $3;
16175 3652 : n->subLinkType = ANY_SUBLINK;
16176 3652 : n->subLinkId = 0;
16177 3652 : n->testexpr = $1;
16178 3652 : n->operName = NIL; /* show it's IN not = ANY */
16179 3652 : n->location = @2;
16180 3652 : $$ = (Node *) n;
16181 : }
16182 : | a_expr IN_P '(' expr_list ')'
16183 : {
16184 : /* generate scalar IN expression */
16185 10944 : A_Expr *n = makeSimpleA_Expr(AEXPR_IN, "=", $1, (Node *) $4, @2);
16186 :
16187 10944 : n->rexpr_list_start = @3;
16188 10944 : n->rexpr_list_end = @5;
16189 10944 : $$ = (Node *) n;
16190 : }
16191 : | a_expr NOT_LA IN_P select_with_parens %prec NOT_LA
16192 : {
16193 : /* generate NOT (foo = ANY (subquery)) */
16194 168 : SubLink *n = makeNode(SubLink);
16195 :
16196 168 : n->subselect = $4;
16197 168 : n->subLinkType = ANY_SUBLINK;
16198 168 : n->subLinkId = 0;
16199 168 : n->testexpr = $1;
16200 168 : n->operName = NIL; /* show it's IN not = ANY */
16201 168 : n->location = @2;
16202 : /* Stick a NOT on top; must have same parse location */
16203 168 : $$ = makeNotExpr((Node *) n, @2);
16204 : }
16205 : | a_expr NOT_LA IN_P '(' expr_list ')'
16206 : {
16207 : /* generate scalar NOT IN expression */
16208 1815 : A_Expr *n = makeSimpleA_Expr(AEXPR_IN, "<>", $1, (Node *) $5, @2);
16209 :
16210 1815 : n->rexpr_list_start = @4;
16211 1815 : n->rexpr_list_end = @6;
16212 1815 : $$ = (Node *) n;
16213 : }
16214 : | a_expr subquery_Op sub_type select_with_parens %prec Op
16215 : {
16216 124 : SubLink *n = makeNode(SubLink);
16217 :
16218 124 : n->subLinkType = $3;
16219 124 : n->subLinkId = 0;
16220 124 : n->testexpr = $1;
16221 124 : n->operName = $2;
16222 124 : n->subselect = $4;
16223 124 : n->location = @2;
16224 124 : $$ = (Node *) n;
16225 : }
16226 : | a_expr subquery_Op sub_type '(' a_expr ')' %prec Op
16227 : {
16228 11362 : if ($3 == ANY_SUBLINK)
16229 11157 : $$ = (Node *) makeA_Expr(AEXPR_OP_ANY, $2, $1, $5, @2);
16230 : else
16231 205 : $$ = (Node *) makeA_Expr(AEXPR_OP_ALL, $2, $1, $5, @2);
16232 : }
16233 : | UNIQUE opt_unique_null_treatment select_with_parens
16234 : {
16235 : /* Not sure how to get rid of the parentheses
16236 : * but there are lots of shift/reduce errors without them.
16237 : *
16238 : * Should be able to implement this by plopping the entire
16239 : * select into a node, then transforming the target expressions
16240 : * from whatever they are into count(*), and testing the
16241 : * entire result equal to one.
16242 : * But, will probably implement a separate node in the executor.
16243 : */
16244 0 : ereport(ERROR,
16245 : (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
16246 : errmsg("UNIQUE predicate is not yet implemented"),
16247 : parser_errposition(@1)));
16248 : }
16249 : | a_expr IS DOCUMENT_P %prec IS
16250 : {
16251 12 : $$ = makeXmlExpr(IS_DOCUMENT, NULL, NIL,
16252 12 : list_make1($1), @2);
16253 : }
16254 : | a_expr IS NOT DOCUMENT_P %prec IS
16255 : {
16256 12 : $$ = makeNotExpr(makeXmlExpr(IS_DOCUMENT, NULL, NIL,
16257 12 : list_make1($1), @2),
16258 12 : @2);
16259 : }
16260 : | a_expr IS NORMALIZED %prec IS
16261 : {
16262 8 : $$ = (Node *) makeFuncCall(SystemFuncName("is_normalized"),
16263 8 : list_make1($1),
16264 : COERCE_SQL_SYNTAX,
16265 8 : @2);
16266 : }
16267 : | a_expr IS unicode_normal_form NORMALIZED %prec IS
16268 : {
16269 48 : $$ = (Node *) makeFuncCall(SystemFuncName("is_normalized"),
16270 24 : list_make2($1, makeStringConst($3, @3)),
16271 : COERCE_SQL_SYNTAX,
16272 24 : @2);
16273 : }
16274 : | a_expr IS NOT NORMALIZED %prec IS
16275 : {
16276 0 : $$ = makeNotExpr((Node *) makeFuncCall(SystemFuncName("is_normalized"),
16277 0 : list_make1($1),
16278 : COERCE_SQL_SYNTAX,
16279 0 : @2),
16280 0 : @2);
16281 : }
16282 : | a_expr IS NOT unicode_normal_form NORMALIZED %prec IS
16283 : {
16284 0 : $$ = makeNotExpr((Node *) makeFuncCall(SystemFuncName("is_normalized"),
16285 0 : list_make2($1, makeStringConst($4, @4)),
16286 : COERCE_SQL_SYNTAX,
16287 0 : @2),
16288 0 : @2);
16289 : }
16290 : | a_expr IS json_predicate_type_constraint
16291 : json_key_uniqueness_constraint_opt %prec IS
16292 : {
16293 238 : JsonFormat *format = makeJsonFormat(JS_FORMAT_DEFAULT, JS_ENC_DEFAULT, -1);
16294 :
16295 238 : $$ = makeJsonIsPredicate($1, format, $3, $4, InvalidOid, @1);
16296 : }
16297 : /*
16298 : * Required by SQL/JSON, but there are conflicts
16299 : | a_expr
16300 : json_format_clause
16301 : IS json_predicate_type_constraint
16302 : json_key_uniqueness_constraint_opt %prec IS
16303 : {
16304 : $$ = makeJsonIsPredicate($1, $2, $4, $5, InvalidOid, @1);
16305 : }
16306 : */
16307 : | a_expr IS NOT
16308 : json_predicate_type_constraint
16309 : json_key_uniqueness_constraint_opt %prec IS
16310 : {
16311 34 : JsonFormat *format = makeJsonFormat(JS_FORMAT_DEFAULT, JS_ENC_DEFAULT, -1);
16312 :
16313 34 : $$ = makeNotExpr(makeJsonIsPredicate($1, format, $4, $5, InvalidOid, @1), @1);
16314 : }
16315 : /*
16316 : * Required by SQL/JSON, but there are conflicts
16317 : | a_expr
16318 : json_format_clause
16319 : IS NOT
16320 : json_predicate_type_constraint
16321 : json_key_uniqueness_constraint_opt %prec IS
16322 : {
16323 : $$ = makeNotExpr(makeJsonIsPredicate($1, $2, $5, $6, InvalidOid, @1), @1);
16324 : }
16325 : */
16326 : | DEFAULT
16327 : {
16328 : /*
16329 : * The SQL spec only allows DEFAULT in "contextually typed
16330 : * expressions", but for us, it's easier to allow it in
16331 : * any a_expr and then throw error during parse analysis
16332 : * if it's in an inappropriate context. This way also
16333 : * lets us say something smarter than "syntax error".
16334 : */
16335 1048 : SetToDefault *n = makeNode(SetToDefault);
16336 :
16337 : /* parse analysis will fill in the rest */
16338 1048 : n->location = @1;
16339 1048 : $$ = (Node *) n;
16340 : }
16341 : ;
16342 :
16343 : /*
16344 : * Restricted expressions
16345 : *
16346 : * b_expr is a subset of the complete expression syntax defined by a_expr.
16347 : *
16348 : * Presently, AND, NOT, IS, and IN are the a_expr keywords that would
16349 : * cause trouble in the places where b_expr is used. For simplicity, we
16350 : * just eliminate all the boolean-keyword-operator productions from b_expr.
16351 : */
16352 : b_expr: c_expr
16353 2518 : { $$ = $1; }
16354 : | b_expr TYPECAST Typename
16355 138 : { $$ = makeTypeCast($1, $3, @2); }
16356 : | '+' b_expr %prec UMINUS
16357 0 : { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "+", NULL, $2, @1); }
16358 : | '-' b_expr %prec UMINUS
16359 44 : { $$ = doNegate($2, @1); }
16360 : | b_expr '+' b_expr
16361 24 : { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "+", $1, $3, @2); }
16362 : | b_expr '-' b_expr
16363 8 : { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "-", $1, $3, @2); }
16364 : | b_expr '*' b_expr
16365 8 : { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "*", $1, $3, @2); }
16366 : | b_expr '/' b_expr
16367 0 : { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "/", $1, $3, @2); }
16368 : | b_expr '%' b_expr
16369 0 : { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "%", $1, $3, @2); }
16370 : | b_expr '^' b_expr
16371 4 : { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "^", $1, $3, @2); }
16372 : | b_expr '<' b_expr
16373 0 : { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "<", $1, $3, @2); }
16374 : | b_expr '>' b_expr
16375 0 : { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, ">", $1, $3, @2); }
16376 : | b_expr '=' b_expr
16377 0 : { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "=", $1, $3, @2); }
16378 : | b_expr LESS_EQUALS b_expr
16379 0 : { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "<=", $1, $3, @2); }
16380 : | b_expr GREATER_EQUALS b_expr
16381 0 : { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, ">=", $1, $3, @2); }
16382 : | b_expr NOT_EQUALS b_expr
16383 0 : { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "<>", $1, $3, @2); }
16384 : | b_expr RIGHT_ARROW b_expr
16385 0 : { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "->", $1, $3, @2); }
16386 : | b_expr '|' b_expr
16387 0 : { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "|", $1, $3, @2); }
16388 : | b_expr qual_Op b_expr %prec Op
16389 8 : { $$ = (Node *) makeA_Expr(AEXPR_OP, $2, $1, $3, @2); }
16390 : | qual_Op b_expr %prec Op
16391 0 : { $$ = (Node *) makeA_Expr(AEXPR_OP, $1, NULL, $2, @1); }
16392 : | b_expr IS DISTINCT FROM b_expr %prec IS
16393 : {
16394 0 : $$ = (Node *) makeSimpleA_Expr(AEXPR_DISTINCT, "=", $1, $5, @2);
16395 : }
16396 : | b_expr IS NOT DISTINCT FROM b_expr %prec IS
16397 : {
16398 0 : $$ = (Node *) makeSimpleA_Expr(AEXPR_NOT_DISTINCT, "=", $1, $6, @2);
16399 : }
16400 : | b_expr IS DOCUMENT_P %prec IS
16401 : {
16402 0 : $$ = makeXmlExpr(IS_DOCUMENT, NULL, NIL,
16403 0 : list_make1($1), @2);
16404 : }
16405 : | b_expr IS NOT DOCUMENT_P %prec IS
16406 : {
16407 0 : $$ = makeNotExpr(makeXmlExpr(IS_DOCUMENT, NULL, NIL,
16408 0 : list_make1($1), @2),
16409 0 : @2);
16410 : }
16411 : ;
16412 :
16413 : /*
16414 : * Productions that can be used in both a_expr and b_expr.
16415 : *
16416 : * Note: productions that refer recursively to a_expr or b_expr mostly
16417 : * cannot appear here. However, it's OK to refer to a_exprs that occur
16418 : * inside parentheses, such as function arguments; that cannot introduce
16419 : * ambiguity to the b_expr syntax.
16420 : */
16421 1210111 : c_expr: columnref { $$ = $1; }
16422 824009 : | AexprConst { $$ = $1; }
16423 : | PARAM opt_indirection
16424 : {
16425 26227 : ParamRef *p = makeNode(ParamRef);
16426 :
16427 26227 : p->number = $1;
16428 26227 : p->location = @1;
16429 26227 : if ($2)
16430 : {
16431 689 : A_Indirection *n = makeNode(A_Indirection);
16432 :
16433 689 : n->arg = (Node *) p;
16434 689 : n->indirection = check_indirection($2, yyscanner);
16435 689 : $$ = (Node *) n;
16436 : }
16437 : else
16438 25538 : $$ = (Node *) p;
16439 : }
16440 : | '(' a_expr ')' opt_indirection
16441 : {
16442 62988 : if ($4)
16443 : {
16444 9241 : A_Indirection *n = makeNode(A_Indirection);
16445 :
16446 9241 : n->arg = $2;
16447 9241 : n->indirection = check_indirection($4, yyscanner);
16448 9241 : $$ = (Node *) n;
16449 : }
16450 : else
16451 53747 : $$ = $2;
16452 : }
16453 : | case_expr
16454 26420 : { $$ = $1; }
16455 : | func_expr
16456 262460 : { $$ = $1; }
16457 : | select_with_parens %prec UMINUS
16458 : {
16459 17907 : SubLink *n = makeNode(SubLink);
16460 :
16461 17907 : n->subLinkType = EXPR_SUBLINK;
16462 17907 : n->subLinkId = 0;
16463 17907 : n->testexpr = NULL;
16464 17907 : n->operName = NIL;
16465 17907 : n->subselect = $1;
16466 17907 : n->location = @1;
16467 17907 : $$ = (Node *) n;
16468 : }
16469 : | select_with_parens indirection
16470 : {
16471 : /*
16472 : * Because the select_with_parens nonterminal is designed
16473 : * to "eat" as many levels of parens as possible, the
16474 : * '(' a_expr ')' opt_indirection production above will
16475 : * fail to match a sub-SELECT with indirection decoration;
16476 : * the sub-SELECT won't be regarded as an a_expr as long
16477 : * as there are parens around it. To support applying
16478 : * subscripting or field selection to a sub-SELECT result,
16479 : * we need this redundant-looking production.
16480 : */
16481 12 : SubLink *n = makeNode(SubLink);
16482 12 : A_Indirection *a = makeNode(A_Indirection);
16483 :
16484 12 : n->subLinkType = EXPR_SUBLINK;
16485 12 : n->subLinkId = 0;
16486 12 : n->testexpr = NULL;
16487 12 : n->operName = NIL;
16488 12 : n->subselect = $1;
16489 12 : n->location = @1;
16490 12 : a->arg = (Node *) n;
16491 12 : a->indirection = check_indirection($2, yyscanner);
16492 12 : $$ = (Node *) a;
16493 : }
16494 : | EXISTS select_with_parens
16495 : {
16496 6145 : SubLink *n = makeNode(SubLink);
16497 :
16498 6145 : n->subLinkType = EXISTS_SUBLINK;
16499 6145 : n->subLinkId = 0;
16500 6145 : n->testexpr = NULL;
16501 6145 : n->operName = NIL;
16502 6145 : n->subselect = $2;
16503 6145 : n->location = @1;
16504 6145 : $$ = (Node *) n;
16505 : }
16506 : | ARRAY select_with_parens
16507 : {
16508 5733 : SubLink *n = makeNode(SubLink);
16509 :
16510 5733 : n->subLinkType = ARRAY_SUBLINK;
16511 5733 : n->subLinkId = 0;
16512 5733 : n->testexpr = NULL;
16513 5733 : n->operName = NIL;
16514 5733 : n->subselect = $2;
16515 5733 : n->location = @1;
16516 5733 : $$ = (Node *) n;
16517 : }
16518 : | ARRAY array_expr
16519 : {
16520 5437 : A_ArrayExpr *n = castNode(A_ArrayExpr, $2);
16521 :
16522 : /* point outermost A_ArrayExpr to the ARRAY keyword */
16523 5437 : n->location = @1;
16524 5437 : $$ = (Node *) n;
16525 : }
16526 : | explicit_row
16527 : {
16528 2451 : RowExpr *r = makeNode(RowExpr);
16529 :
16530 2451 : r->args = $1;
16531 2451 : r->row_typeid = InvalidOid; /* not analyzed yet */
16532 2451 : r->colnames = NIL; /* to be filled in during analysis */
16533 2451 : r->row_format = COERCE_EXPLICIT_CALL; /* abuse */
16534 2451 : r->location = @1;
16535 2451 : $$ = (Node *) r;
16536 : }
16537 : | implicit_row
16538 : {
16539 1848 : RowExpr *r = makeNode(RowExpr);
16540 :
16541 1848 : r->args = $1;
16542 1848 : r->row_typeid = InvalidOid; /* not analyzed yet */
16543 1848 : r->colnames = NIL; /* to be filled in during analysis */
16544 1848 : r->row_format = COERCE_IMPLICIT_CAST; /* abuse */
16545 1848 : r->location = @1;
16546 1848 : $$ = (Node *) r;
16547 : }
16548 : | GROUPING '(' expr_list ')'
16549 : {
16550 252 : GroupingFunc *g = makeNode(GroupingFunc);
16551 :
16552 252 : g->args = $3;
16553 252 : g->location = @1;
16554 252 : $$ = (Node *) g;
16555 : }
16556 : ;
16557 :
16558 : func_application: func_name '(' ')'
16559 : {
16560 20215 : $$ = (Node *) makeFuncCall($1, NIL,
16561 : COERCE_EXPLICIT_CALL,
16562 20215 : @1);
16563 : }
16564 : | func_name '(' func_arg_list opt_sort_clause ')'
16565 : {
16566 211657 : FuncCall *n = makeFuncCall($1, $3,
16567 : COERCE_EXPLICIT_CALL,
16568 211657 : @1);
16569 :
16570 211657 : n->agg_order = $4;
16571 211657 : $$ = (Node *) n;
16572 : }
16573 : | func_name '(' VARIADIC func_arg_expr opt_sort_clause ')'
16574 : {
16575 377 : FuncCall *n = makeFuncCall($1, list_make1($4),
16576 : COERCE_EXPLICIT_CALL,
16577 377 : @1);
16578 :
16579 377 : n->func_variadic = true;
16580 377 : n->agg_order = $5;
16581 377 : $$ = (Node *) n;
16582 : }
16583 : | func_name '(' func_arg_list ',' VARIADIC func_arg_expr opt_sort_clause ')'
16584 : {
16585 112 : FuncCall *n = makeFuncCall($1, lappend($3, $6),
16586 : COERCE_EXPLICIT_CALL,
16587 112 : @1);
16588 :
16589 112 : n->func_variadic = true;
16590 112 : n->agg_order = $7;
16591 112 : $$ = (Node *) n;
16592 : }
16593 : | func_name '(' ALL func_arg_list opt_sort_clause ')'
16594 : {
16595 0 : FuncCall *n = makeFuncCall($1, $4,
16596 : COERCE_EXPLICIT_CALL,
16597 0 : @1);
16598 :
16599 0 : n->agg_order = $5;
16600 : /* Ideally we'd mark the FuncCall node to indicate
16601 : * "must be an aggregate", but there's no provision
16602 : * for that in FuncCall at the moment.
16603 : */
16604 0 : $$ = (Node *) n;
16605 : }
16606 : | func_name '(' DISTINCT func_arg_list opt_sort_clause ')'
16607 : {
16608 367 : FuncCall *n = makeFuncCall($1, $4,
16609 : COERCE_EXPLICIT_CALL,
16610 367 : @1);
16611 :
16612 367 : n->agg_order = $5;
16613 367 : n->agg_distinct = true;
16614 367 : $$ = (Node *) n;
16615 : }
16616 : | func_name '(' '*' ')'
16617 : {
16618 : /*
16619 : * We consider AGGREGATE(*) to invoke a parameterless
16620 : * aggregate. This does the right thing for COUNT(*),
16621 : * and there are no other aggregates in SQL that accept
16622 : * '*' as parameter.
16623 : *
16624 : * The FuncCall node is also marked agg_star = true,
16625 : * so that later processing can detect what the argument
16626 : * really was.
16627 : */
16628 11294 : FuncCall *n = makeFuncCall($1, NIL,
16629 : COERCE_EXPLICIT_CALL,
16630 11294 : @1);
16631 :
16632 11294 : n->agg_star = true;
16633 11294 : $$ = (Node *) n;
16634 : }
16635 : ;
16636 :
16637 :
16638 : /*
16639 : * func_expr and its cousin func_expr_windowless are split out from c_expr just
16640 : * so that we have classifications for "everything that is a function call or
16641 : * looks like one". This isn't very important, but it saves us having to
16642 : * document which variants are legal in places like "FROM function()" or the
16643 : * backwards-compatible functional-index syntax for CREATE INDEX.
16644 : * (Note that many of the special SQL functions wouldn't actually make any
16645 : * sense as functional index entries, but we ignore that consideration here.)
16646 : */
16647 : func_expr: func_application within_group_clause filter_clause null_treatment over_clause
16648 : {
16649 212642 : FuncCall *n = (FuncCall *) $1;
16650 :
16651 : /*
16652 : * The order clause for WITHIN GROUP and the one for
16653 : * plain-aggregate ORDER BY share a field, so we have to
16654 : * check here that at most one is present. We also check
16655 : * for DISTINCT and VARIADIC here to give a better error
16656 : * location. Other consistency checks are deferred to
16657 : * parse analysis.
16658 : */
16659 212642 : if ($2 != NIL)
16660 : {
16661 228 : if (n->agg_order != NIL)
16662 4 : ereport(ERROR,
16663 : (errcode(ERRCODE_SYNTAX_ERROR),
16664 : errmsg("cannot use multiple ORDER BY clauses with WITHIN GROUP"),
16665 : parser_errposition(@2)));
16666 224 : if (n->agg_distinct)
16667 0 : ereport(ERROR,
16668 : (errcode(ERRCODE_SYNTAX_ERROR),
16669 : errmsg("cannot use DISTINCT with WITHIN GROUP"),
16670 : parser_errposition(@2)));
16671 224 : if (n->func_variadic)
16672 0 : ereport(ERROR,
16673 : (errcode(ERRCODE_SYNTAX_ERROR),
16674 : errmsg("cannot use VARIADIC with WITHIN GROUP"),
16675 : parser_errposition(@2)));
16676 224 : n->agg_order = $2;
16677 224 : n->agg_within_group = true;
16678 : }
16679 212638 : n->agg_filter = $3;
16680 212638 : n->ignore_nulls = $4;
16681 212638 : n->over = $5;
16682 212638 : $$ = (Node *) n;
16683 : }
16684 : | json_aggregate_func filter_clause over_clause
16685 : {
16686 480 : JsonAggConstructor *n = IsA($1, JsonObjectAgg) ?
16687 240 : ((JsonObjectAgg *) $1)->constructor :
16688 104 : ((JsonArrayAgg *) $1)->constructor;
16689 :
16690 240 : n->agg_filter = $2;
16691 240 : n->over = $3;
16692 240 : $$ = (Node *) $1;
16693 : }
16694 : | func_expr_common_subexpr
16695 49582 : { $$ = $1; }
16696 : ;
16697 :
16698 : /*
16699 : * Like func_expr but does not accept WINDOW functions directly
16700 : * (but they can still be contained in arguments for functions etc).
16701 : * Use this when window expressions are not allowed, where needed to
16702 : * disambiguate the grammar (e.g. in CREATE INDEX).
16703 : */
16704 : func_expr_windowless:
16705 31017 : func_application { $$ = $1; }
16706 396 : | func_expr_common_subexpr { $$ = $1; }
16707 16 : | json_aggregate_func { $$ = $1; }
16708 : ;
16709 :
16710 : /*
16711 : * Special expressions that are considered to be functions.
16712 : */
16713 : func_expr_common_subexpr:
16714 : COLLATION FOR '(' a_expr ')'
16715 : {
16716 20 : $$ = (Node *) makeFuncCall(SystemFuncName("pg_collation_for"),
16717 20 : list_make1($4),
16718 : COERCE_SQL_SYNTAX,
16719 20 : @1);
16720 : }
16721 : | CURRENT_DATE
16722 : {
16723 211 : $$ = makeSQLValueFunction(SVFOP_CURRENT_DATE, -1, @1);
16724 : }
16725 : | CURRENT_TIME
16726 : {
16727 16 : $$ = makeSQLValueFunction(SVFOP_CURRENT_TIME, -1, @1);
16728 : }
16729 : | CURRENT_TIME '(' Iconst ')'
16730 : {
16731 16 : $$ = makeSQLValueFunction(SVFOP_CURRENT_TIME_N, $3, @1);
16732 : }
16733 : | CURRENT_TIMESTAMP
16734 : {
16735 153 : $$ = makeSQLValueFunction(SVFOP_CURRENT_TIMESTAMP, -1, @1);
16736 : }
16737 : | CURRENT_TIMESTAMP '(' Iconst ')'
16738 : {
16739 107 : $$ = makeSQLValueFunction(SVFOP_CURRENT_TIMESTAMP_N, $3, @1);
16740 : }
16741 : | LOCALTIME
16742 : {
16743 16 : $$ = makeSQLValueFunction(SVFOP_LOCALTIME, -1, @1);
16744 : }
16745 : | LOCALTIME '(' Iconst ')'
16746 : {
16747 16 : $$ = makeSQLValueFunction(SVFOP_LOCALTIME_N, $3, @1);
16748 : }
16749 : | LOCALTIMESTAMP
16750 : {
16751 24 : $$ = makeSQLValueFunction(SVFOP_LOCALTIMESTAMP, -1, @1);
16752 : }
16753 : | LOCALTIMESTAMP '(' Iconst ')'
16754 : {
16755 16 : $$ = makeSQLValueFunction(SVFOP_LOCALTIMESTAMP_N, $3, @1);
16756 : }
16757 : | CURRENT_ROLE
16758 : {
16759 44 : $$ = makeSQLValueFunction(SVFOP_CURRENT_ROLE, -1, @1);
16760 : }
16761 : | CURRENT_USER
16762 : {
16763 688 : $$ = makeSQLValueFunction(SVFOP_CURRENT_USER, -1, @1);
16764 : }
16765 : | SESSION_USER
16766 : {
16767 319 : $$ = makeSQLValueFunction(SVFOP_SESSION_USER, -1, @1);
16768 : }
16769 : | SYSTEM_USER
16770 : {
16771 12 : $$ = (Node *) makeFuncCall(SystemFuncName("system_user"),
16772 : NIL,
16773 : COERCE_SQL_SYNTAX,
16774 : @1);
16775 : }
16776 : | USER
16777 : {
16778 16 : $$ = makeSQLValueFunction(SVFOP_USER, -1, @1);
16779 : }
16780 : | CURRENT_CATALOG
16781 : {
16782 35 : $$ = makeSQLValueFunction(SVFOP_CURRENT_CATALOG, -1, @1);
16783 : }
16784 : | CURRENT_SCHEMA
16785 : {
16786 20 : $$ = makeSQLValueFunction(SVFOP_CURRENT_SCHEMA, -1, @1);
16787 : }
16788 : | CAST '(' a_expr AS Typename ')'
16789 40318 : { $$ = makeTypeCast($3, $5, @1); }
16790 : | EXTRACT '(' extract_list ')'
16791 : {
16792 884 : $$ = (Node *) makeFuncCall(SystemFuncName("extract"),
16793 884 : $3,
16794 : COERCE_SQL_SYNTAX,
16795 884 : @1);
16796 : }
16797 : | NORMALIZE '(' a_expr ')'
16798 : {
16799 12 : $$ = (Node *) makeFuncCall(SystemFuncName("normalize"),
16800 12 : list_make1($3),
16801 : COERCE_SQL_SYNTAX,
16802 12 : @1);
16803 : }
16804 : | NORMALIZE '(' a_expr ',' unicode_normal_form ')'
16805 : {
16806 56 : $$ = (Node *) makeFuncCall(SystemFuncName("normalize"),
16807 28 : list_make2($3, makeStringConst($5, @5)),
16808 : COERCE_SQL_SYNTAX,
16809 28 : @1);
16810 : }
16811 : | OVERLAY '(' overlay_list ')'
16812 : {
16813 54 : $$ = (Node *) makeFuncCall(SystemFuncName("overlay"),
16814 54 : $3,
16815 : COERCE_SQL_SYNTAX,
16816 54 : @1);
16817 : }
16818 : | OVERLAY '(' func_arg_list_opt ')'
16819 : {
16820 : /*
16821 : * allow functions named overlay() to be called without
16822 : * special syntax
16823 : */
16824 0 : $$ = (Node *) makeFuncCall(list_make1(makeString("overlay")),
16825 0 : $3,
16826 : COERCE_EXPLICIT_CALL,
16827 0 : @1);
16828 : }
16829 : | POSITION '(' position_list ')'
16830 : {
16831 : /*
16832 : * position(A in B) is converted to position(B, A)
16833 : *
16834 : * We deliberately don't offer a "plain syntax" option
16835 : * for position(), because the reversal of the arguments
16836 : * creates too much risk of confusion.
16837 : */
16838 261 : $$ = (Node *) makeFuncCall(SystemFuncName("position"),
16839 261 : $3,
16840 : COERCE_SQL_SYNTAX,
16841 261 : @1);
16842 : }
16843 : | SUBSTRING '(' substr_list ')'
16844 : {
16845 : /* substring(A from B for C) is converted to
16846 : * substring(A, B, C) - thomas 2000-11-28
16847 : */
16848 463 : $$ = (Node *) makeFuncCall(SystemFuncName("substring"),
16849 463 : $3,
16850 : COERCE_SQL_SYNTAX,
16851 463 : @1);
16852 : }
16853 : | SUBSTRING '(' func_arg_list_opt ')'
16854 : {
16855 : /*
16856 : * allow functions named substring() to be called without
16857 : * special syntax
16858 : */
16859 198 : $$ = (Node *) makeFuncCall(list_make1(makeString("substring")),
16860 198 : $3,
16861 : COERCE_EXPLICIT_CALL,
16862 198 : @1);
16863 : }
16864 : | TREAT '(' a_expr AS Typename ')'
16865 : {
16866 : /* TREAT(expr AS target) converts expr of a particular type to target,
16867 : * which is defined to be a subtype of the original expression.
16868 : * In SQL99, this is intended for use with structured UDTs,
16869 : * but let's make this a generally useful form allowing stronger
16870 : * coercions than are handled by implicit casting.
16871 : *
16872 : * Convert SystemTypeName() to SystemFuncName() even though
16873 : * at the moment they result in the same thing.
16874 : */
16875 0 : $$ = (Node *) makeFuncCall(SystemFuncName(strVal(llast($5->names))),
16876 0 : list_make1($3),
16877 : COERCE_EXPLICIT_CALL,
16878 0 : @1);
16879 : }
16880 : | TRIM '(' BOTH trim_list ')'
16881 : {
16882 : /* various trim expressions are defined in SQL
16883 : * - thomas 1997-07-19
16884 : */
16885 8 : $$ = (Node *) makeFuncCall(SystemFuncName("btrim"),
16886 8 : $4,
16887 : COERCE_SQL_SYNTAX,
16888 8 : @1);
16889 : }
16890 : | TRIM '(' LEADING trim_list ')'
16891 : {
16892 16 : $$ = (Node *) makeFuncCall(SystemFuncName("ltrim"),
16893 16 : $4,
16894 : COERCE_SQL_SYNTAX,
16895 16 : @1);
16896 : }
16897 : | TRIM '(' TRAILING trim_list ')'
16898 : {
16899 378 : $$ = (Node *) makeFuncCall(SystemFuncName("rtrim"),
16900 378 : $4,
16901 : COERCE_SQL_SYNTAX,
16902 378 : @1);
16903 : }
16904 : | TRIM '(' trim_list ')'
16905 : {
16906 64 : $$ = (Node *) makeFuncCall(SystemFuncName("btrim"),
16907 64 : $3,
16908 : COERCE_SQL_SYNTAX,
16909 64 : @1);
16910 : }
16911 : | NULLIF '(' a_expr ',' a_expr ')'
16912 : {
16913 339 : $$ = (Node *) makeSimpleA_Expr(AEXPR_NULLIF, "=", $3, $5, @1);
16914 : }
16915 : | COALESCE '(' expr_list ')'
16916 : {
16917 2159 : CoalesceExpr *c = makeNode(CoalesceExpr);
16918 :
16919 2159 : c->args = $3;
16920 2159 : c->location = @1;
16921 2159 : $$ = (Node *) c;
16922 : }
16923 : | GREATEST '(' expr_list ')'
16924 : {
16925 106 : MinMaxExpr *v = makeNode(MinMaxExpr);
16926 :
16927 106 : v->args = $3;
16928 106 : v->op = IS_GREATEST;
16929 106 : v->location = @1;
16930 106 : $$ = (Node *) v;
16931 : }
16932 : | LEAST '(' expr_list ')'
16933 : {
16934 100 : MinMaxExpr *v = makeNode(MinMaxExpr);
16935 :
16936 100 : v->args = $3;
16937 100 : v->op = IS_LEAST;
16938 100 : v->location = @1;
16939 100 : $$ = (Node *) v;
16940 : }
16941 : | XMLCONCAT '(' expr_list ')'
16942 : {
16943 41 : $$ = makeXmlExpr(IS_XMLCONCAT, NULL, NIL, $3, @1);
16944 : }
16945 : | XMLELEMENT '(' NAME_P ColLabel ')'
16946 : {
16947 4 : $$ = makeXmlExpr(IS_XMLELEMENT, $4, NIL, NIL, @1);
16948 : }
16949 : | XMLELEMENT '(' NAME_P ColLabel ',' xml_attributes ')'
16950 : {
16951 24 : $$ = makeXmlExpr(IS_XMLELEMENT, $4, $6, NIL, @1);
16952 : }
16953 : | XMLELEMENT '(' NAME_P ColLabel ',' expr_list ')'
16954 : {
16955 77 : $$ = makeXmlExpr(IS_XMLELEMENT, $4, NIL, $6, @1);
16956 : }
16957 : | XMLELEMENT '(' NAME_P ColLabel ',' xml_attributes ',' expr_list ')'
16958 : {
16959 13 : $$ = makeXmlExpr(IS_XMLELEMENT, $4, $6, $8, @1);
16960 : }
16961 : | XMLEXISTS '(' c_expr xmlexists_argument ')'
16962 : {
16963 : /* xmlexists(A PASSING [BY REF] B [BY REF]) is
16964 : * converted to xmlexists(A, B)*/
16965 36 : $$ = (Node *) makeFuncCall(SystemFuncName("xmlexists"),
16966 36 : list_make2($3, $4),
16967 : COERCE_SQL_SYNTAX,
16968 36 : @1);
16969 : }
16970 : | XMLFOREST '(' labeled_expr_list ')'
16971 : {
16972 21 : $$ = makeXmlExpr(IS_XMLFOREST, NULL, $3, NIL, @1);
16973 : }
16974 : | XMLPARSE '(' document_or_content a_expr xml_whitespace_option ')'
16975 : {
16976 : XmlExpr *x = (XmlExpr *)
16977 186 : makeXmlExpr(IS_XMLPARSE, NULL, NIL,
16978 93 : list_make2($4, makeBoolAConst($5, -1)),
16979 93 : @1);
16980 :
16981 93 : x->xmloption = $3;
16982 93 : $$ = (Node *) x;
16983 : }
16984 : | XMLPI '(' NAME_P ColLabel ')'
16985 : {
16986 20 : $$ = makeXmlExpr(IS_XMLPI, $4, NULL, NIL, @1);
16987 : }
16988 : | XMLPI '(' NAME_P ColLabel ',' a_expr ')'
16989 : {
16990 33 : $$ = makeXmlExpr(IS_XMLPI, $4, NULL, list_make1($6), @1);
16991 : }
16992 : | XMLROOT '(' a_expr ',' xml_root_version opt_xml_root_standalone ')'
16993 : {
16994 45 : $$ = makeXmlExpr(IS_XMLROOT, NULL, NIL,
16995 45 : list_make3($3, $5, $6), @1);
16996 : }
16997 : | XMLSERIALIZE '(' document_or_content a_expr AS SimpleTypename xml_indent_option ')'
16998 : {
16999 144 : XmlSerialize *n = makeNode(XmlSerialize);
17000 :
17001 144 : n->xmloption = $3;
17002 144 : n->expr = $4;
17003 144 : n->typeName = $6;
17004 144 : n->indent = $7;
17005 144 : n->location = @1;
17006 144 : $$ = (Node *) n;
17007 : }
17008 : | JSON_OBJECT '(' func_arg_list ')'
17009 : {
17010 : /* Support for legacy (non-standard) json_object() */
17011 60 : $$ = (Node *) makeFuncCall(SystemFuncName("json_object"),
17012 60 : $3, COERCE_EXPLICIT_CALL, @1);
17013 : }
17014 : | JSON_OBJECT '(' json_name_and_value_list
17015 : json_object_constructor_null_clause_opt
17016 : json_key_uniqueness_constraint_opt
17017 : json_returning_clause_opt ')'
17018 : {
17019 318 : JsonObjectConstructor *n = makeNode(JsonObjectConstructor);
17020 :
17021 318 : n->exprs = $3;
17022 318 : n->absent_on_null = $4;
17023 318 : n->unique = $5;
17024 318 : n->output = (JsonOutput *) $6;
17025 318 : n->location = @1;
17026 318 : $$ = (Node *) n;
17027 : }
17028 : | JSON_OBJECT '(' json_returning_clause_opt ')'
17029 : {
17030 60 : JsonObjectConstructor *n = makeNode(JsonObjectConstructor);
17031 :
17032 60 : n->exprs = NULL;
17033 60 : n->absent_on_null = false;
17034 60 : n->unique = false;
17035 60 : n->output = (JsonOutput *) $3;
17036 60 : n->location = @1;
17037 60 : $$ = (Node *) n;
17038 : }
17039 : | JSON_ARRAY '('
17040 : json_value_expr_list
17041 : json_array_constructor_null_clause_opt
17042 : json_returning_clause_opt
17043 : ')'
17044 : {
17045 168 : JsonArrayConstructor *n = makeNode(JsonArrayConstructor);
17046 :
17047 168 : n->exprs = $3;
17048 168 : n->absent_on_null = $4;
17049 168 : n->output = (JsonOutput *) $5;
17050 168 : n->location = @1;
17051 168 : $$ = (Node *) n;
17052 : }
17053 : | JSON_ARRAY '('
17054 : select_no_parens
17055 : json_format_clause_opt
17056 : /* json_array_constructor_null_clause_opt */
17057 : json_returning_clause_opt
17058 : ')'
17059 : {
17060 40 : JsonArrayQueryConstructor *n = makeNode(JsonArrayQueryConstructor);
17061 :
17062 40 : n->query = $3;
17063 40 : n->format = (JsonFormat *) $4;
17064 40 : n->absent_on_null = true; /* XXX */
17065 40 : n->output = (JsonOutput *) $5;
17066 40 : n->location = @1;
17067 40 : $$ = (Node *) n;
17068 : }
17069 : | JSON_ARRAY '('
17070 : json_returning_clause_opt
17071 : ')'
17072 : {
17073 56 : JsonArrayConstructor *n = makeNode(JsonArrayConstructor);
17074 :
17075 56 : n->exprs = NIL;
17076 56 : n->absent_on_null = true;
17077 56 : n->output = (JsonOutput *) $3;
17078 56 : n->location = @1;
17079 56 : $$ = (Node *) n;
17080 : }
17081 : | JSON '(' json_value_expr json_key_uniqueness_constraint_opt ')'
17082 : {
17083 104 : JsonParseExpr *n = makeNode(JsonParseExpr);
17084 :
17085 104 : n->expr = (JsonValueExpr *) $3;
17086 104 : n->unique_keys = $4;
17087 104 : n->output = NULL;
17088 104 : n->location = @1;
17089 104 : $$ = (Node *) n;
17090 : }
17091 : | JSON_SCALAR '(' a_expr ')'
17092 : {
17093 70 : JsonScalarExpr *n = makeNode(JsonScalarExpr);
17094 :
17095 70 : n->expr = (Expr *) $3;
17096 70 : n->output = NULL;
17097 70 : n->location = @1;
17098 70 : $$ = (Node *) n;
17099 : }
17100 : | JSON_SERIALIZE '(' json_value_expr json_returning_clause_opt ')'
17101 : {
17102 68 : JsonSerializeExpr *n = makeNode(JsonSerializeExpr);
17103 :
17104 68 : n->expr = (JsonValueExpr *) $3;
17105 68 : n->output = (JsonOutput *) $4;
17106 68 : n->location = @1;
17107 68 : $$ = (Node *) n;
17108 : }
17109 : | MERGE_ACTION '(' ')'
17110 : {
17111 142 : MergeSupportFunc *m = makeNode(MergeSupportFunc);
17112 :
17113 142 : m->msftype = TEXTOID;
17114 142 : m->location = @1;
17115 142 : $$ = (Node *) m;
17116 : }
17117 : | JSON_QUERY '('
17118 : json_value_expr ',' a_expr json_passing_clause_opt
17119 : json_returning_clause_opt
17120 : json_wrapper_behavior
17121 : json_quotes_clause_opt
17122 : json_behavior_clause_opt
17123 : ')'
17124 : {
17125 692 : JsonFuncExpr *n = makeNode(JsonFuncExpr);
17126 :
17127 692 : n->op = JSON_QUERY_OP;
17128 692 : n->context_item = (JsonValueExpr *) $3;
17129 692 : n->pathspec = $5;
17130 692 : n->passing = $6;
17131 692 : n->output = (JsonOutput *) $7;
17132 692 : n->wrapper = $8;
17133 692 : n->quotes = $9;
17134 692 : n->on_empty = (JsonBehavior *) linitial($10);
17135 692 : n->on_error = (JsonBehavior *) lsecond($10);
17136 692 : n->location = @1;
17137 692 : $$ = (Node *) n;
17138 : }
17139 : | JSON_EXISTS '('
17140 : json_value_expr ',' a_expr json_passing_clause_opt
17141 : json_on_error_clause_opt
17142 : ')'
17143 : {
17144 112 : JsonFuncExpr *n = makeNode(JsonFuncExpr);
17145 :
17146 112 : n->op = JSON_EXISTS_OP;
17147 112 : n->context_item = (JsonValueExpr *) $3;
17148 112 : n->pathspec = $5;
17149 112 : n->passing = $6;
17150 112 : n->output = NULL;
17151 112 : n->on_error = (JsonBehavior *) $7;
17152 112 : n->location = @1;
17153 112 : $$ = (Node *) n;
17154 : }
17155 : | JSON_VALUE '('
17156 : json_value_expr ',' a_expr json_passing_clause_opt
17157 : json_returning_clause_opt
17158 : json_behavior_clause_opt
17159 : ')'
17160 : {
17161 420 : JsonFuncExpr *n = makeNode(JsonFuncExpr);
17162 :
17163 420 : n->op = JSON_VALUE_OP;
17164 420 : n->context_item = (JsonValueExpr *) $3;
17165 420 : n->pathspec = $5;
17166 420 : n->passing = $6;
17167 420 : n->output = (JsonOutput *) $7;
17168 420 : n->on_empty = (JsonBehavior *) linitial($8);
17169 420 : n->on_error = (JsonBehavior *) lsecond($8);
17170 420 : n->location = @1;
17171 420 : $$ = (Node *) n;
17172 : }
17173 : ;
17174 :
17175 :
17176 : /*
17177 : * SQL/XML support
17178 : */
17179 : xml_root_version: VERSION_P a_expr
17180 16 : { $$ = $2; }
17181 : | VERSION_P NO VALUE_P
17182 29 : { $$ = makeNullAConst(-1); }
17183 : ;
17184 :
17185 : opt_xml_root_standalone: ',' STANDALONE_P YES_P
17186 17 : { $$ = makeIntConst(XML_STANDALONE_YES, -1); }
17187 : | ',' STANDALONE_P NO
17188 8 : { $$ = makeIntConst(XML_STANDALONE_NO, -1); }
17189 : | ',' STANDALONE_P NO VALUE_P
17190 8 : { $$ = makeIntConst(XML_STANDALONE_NO_VALUE, -1); }
17191 : | /*EMPTY*/
17192 12 : { $$ = makeIntConst(XML_STANDALONE_OMITTED, -1); }
17193 : ;
17194 :
17195 37 : xml_attributes: XMLATTRIBUTES '(' labeled_expr_list ')' { $$ = $3; }
17196 : ;
17197 :
17198 855 : labeled_expr_list: labeled_expr { $$ = list_make1($1); }
17199 790 : | labeled_expr_list ',' labeled_expr { $$ = lappend($1, $3); }
17200 : ;
17201 :
17202 : labeled_expr: a_expr AS ColLabel
17203 : {
17204 1025 : $$ = makeNode(ResTarget);
17205 1025 : $$->name = $3;
17206 1025 : $$->indirection = NIL;
17207 1025 : $$->val = (Node *) $1;
17208 1025 : $$->location = @1;
17209 : }
17210 : | a_expr
17211 : {
17212 620 : $$ = makeNode(ResTarget);
17213 620 : $$->name = NULL;
17214 620 : $$->indirection = NIL;
17215 620 : $$->val = (Node *) $1;
17216 620 : $$->location = @1;
17217 : }
17218 : ;
17219 :
17220 123 : document_or_content: DOCUMENT_P { $$ = XMLOPTION_DOCUMENT; }
17221 124 : | CONTENT_P { $$ = XMLOPTION_CONTENT; }
17222 : ;
17223 :
17224 93 : xml_indent_option: INDENT { $$ = true; }
17225 23 : | NO INDENT { $$ = false; }
17226 28 : | /*EMPTY*/ { $$ = false; }
17227 : ;
17228 :
17229 0 : xml_whitespace_option: PRESERVE WHITESPACE_P { $$ = true; }
17230 1 : | STRIP_P WHITESPACE_P { $$ = false; }
17231 92 : | /*EMPTY*/ { $$ = false; }
17232 : ;
17233 :
17234 : /* We allow several variants for SQL and other compatibility. */
17235 : xmlexists_argument:
17236 : PASSING c_expr
17237 : {
17238 158 : $$ = $2;
17239 : }
17240 : | PASSING c_expr xml_passing_mech
17241 : {
17242 0 : $$ = $2;
17243 : }
17244 : | PASSING xml_passing_mech c_expr
17245 : {
17246 28 : $$ = $3;
17247 : }
17248 : | PASSING xml_passing_mech c_expr xml_passing_mech
17249 : {
17250 4 : $$ = $3;
17251 : }
17252 : ;
17253 :
17254 : xml_passing_mech:
17255 : BY REF_P
17256 : | BY VALUE_P
17257 : ;
17258 :
17259 : /*****************************************************************************
17260 : *
17261 : * WAIT FOR LSN
17262 : *
17263 : *****************************************************************************/
17264 :
17265 : WaitStmt:
17266 : WAIT FOR LSN_P Sconst opt_wait_with_clause
17267 : {
17268 227 : WaitStmt *n = makeNode(WaitStmt);
17269 227 : n->lsn_literal = $4;
17270 227 : n->options = $5;
17271 227 : $$ = (Node *) n;
17272 : }
17273 : ;
17274 :
17275 : opt_wait_with_clause:
17276 216 : WITH '(' utility_option_list ')' { $$ = $3; }
17277 11 : | /*EMPTY*/ { $$ = NIL; }
17278 : ;
17279 :
17280 : /*
17281 : * Aggregate decoration clauses
17282 : */
17283 : within_group_clause:
17284 228 : WITHIN GROUP_P '(' sort_clause ')' { $$ = $4; }
17285 212418 : | /*EMPTY*/ { $$ = NIL; }
17286 : ;
17287 :
17288 : filter_clause:
17289 493 : FILTER '(' WHERE a_expr ')' { $$ = $4; }
17290 212393 : | /*EMPTY*/ { $$ = NULL; }
17291 : ;
17292 :
17293 :
17294 : /*
17295 : * Window Definitions
17296 : */
17297 : null_treatment:
17298 132 : IGNORE_P NULLS_P { $$ = PARSER_IGNORE_NULLS; }
17299 64 : | RESPECT_P NULLS_P { $$ = PARSER_RESPECT_NULLS; }
17300 212450 : | /*EMPTY*/ { $$ = NO_NULLTREATMENT; }
17301 : ;
17302 :
17303 : window_clause:
17304 406 : WINDOW window_definition_list { $$ = $2; }
17305 315073 : | /*EMPTY*/ { $$ = NIL; }
17306 : ;
17307 :
17308 : window_definition_list:
17309 406 : window_definition { $$ = list_make1($1); }
17310 : | window_definition_list ',' window_definition
17311 20 : { $$ = lappend($1, $3); }
17312 : ;
17313 :
17314 : window_definition:
17315 : ColId AS window_specification
17316 : {
17317 426 : WindowDef *n = $3;
17318 :
17319 426 : n->name = $1;
17320 426 : $$ = n;
17321 : }
17322 : ;
17323 :
17324 : over_clause: OVER window_specification
17325 1884 : { $$ = $2; }
17326 : | OVER ColId
17327 : {
17328 790 : WindowDef *n = makeNode(WindowDef);
17329 :
17330 790 : n->name = $2;
17331 790 : n->refname = NULL;
17332 790 : n->partitionClause = NIL;
17333 790 : n->orderClause = NIL;
17334 790 : n->frameOptions = FRAMEOPTION_DEFAULTS;
17335 790 : n->startOffset = NULL;
17336 790 : n->endOffset = NULL;
17337 790 : n->location = @2;
17338 790 : $$ = n;
17339 : }
17340 : | /*EMPTY*/
17341 210208 : { $$ = NULL; }
17342 : ;
17343 :
17344 : window_specification: '(' opt_existing_window_name opt_partition_clause
17345 : opt_sort_clause opt_frame_clause ')'
17346 : {
17347 2310 : WindowDef *n = makeNode(WindowDef);
17348 :
17349 2310 : n->name = NULL;
17350 2310 : n->refname = $2;
17351 2310 : n->partitionClause = $3;
17352 2310 : n->orderClause = $4;
17353 : /* copy relevant fields of opt_frame_clause */
17354 2310 : n->frameOptions = $5->frameOptions;
17355 2310 : n->startOffset = $5->startOffset;
17356 2310 : n->endOffset = $5->endOffset;
17357 2310 : n->location = @1;
17358 2310 : $$ = n;
17359 : }
17360 : ;
17361 :
17362 : /*
17363 : * If we see PARTITION, RANGE, ROWS or GROUPS as the first token after the '('
17364 : * of a window_specification, we want the assumption to be that there is
17365 : * no existing_window_name; but those keywords are unreserved and so could
17366 : * be ColIds. We fix this by making them have the same precedence as IDENT
17367 : * and giving the empty production here a slightly higher precedence, so
17368 : * that the shift/reduce conflict is resolved in favor of reducing the rule.
17369 : * These keywords are thus precluded from being an existing_window_name but
17370 : * are not reserved for any other purpose.
17371 : */
17372 36 : opt_existing_window_name: ColId { $$ = $1; }
17373 2278 : | /*EMPTY*/ %prec Op { $$ = NULL; }
17374 : ;
17375 :
17376 610 : opt_partition_clause: PARTITION BY expr_list { $$ = $3; }
17377 1700 : | /*EMPTY*/ { $$ = NIL; }
17378 : ;
17379 :
17380 : /*
17381 : * For frame clauses, we return a WindowDef, but only some fields are used:
17382 : * frameOptions, startOffset, and endOffset.
17383 : */
17384 : opt_frame_clause:
17385 : RANGE frame_extent opt_window_exclusion_clause
17386 : {
17387 530 : WindowDef *n = $2;
17388 :
17389 530 : n->frameOptions |= FRAMEOPTION_NONDEFAULT | FRAMEOPTION_RANGE;
17390 530 : n->frameOptions |= $3;
17391 530 : $$ = n;
17392 : }
17393 : | ROWS frame_extent opt_window_exclusion_clause
17394 : {
17395 462 : WindowDef *n = $2;
17396 :
17397 462 : n->frameOptions |= FRAMEOPTION_NONDEFAULT | FRAMEOPTION_ROWS;
17398 462 : n->frameOptions |= $3;
17399 462 : $$ = n;
17400 : }
17401 : | GROUPS frame_extent opt_window_exclusion_clause
17402 : {
17403 136 : WindowDef *n = $2;
17404 :
17405 136 : n->frameOptions |= FRAMEOPTION_NONDEFAULT | FRAMEOPTION_GROUPS;
17406 136 : n->frameOptions |= $3;
17407 136 : $$ = n;
17408 : }
17409 : | /*EMPTY*/
17410 : {
17411 1182 : WindowDef *n = makeNode(WindowDef);
17412 :
17413 1182 : n->frameOptions = FRAMEOPTION_DEFAULTS;
17414 1182 : n->startOffset = NULL;
17415 1182 : n->endOffset = NULL;
17416 1182 : $$ = n;
17417 : }
17418 : ;
17419 :
17420 : frame_extent: frame_bound
17421 : {
17422 8 : WindowDef *n = $1;
17423 :
17424 : /* reject invalid cases */
17425 8 : if (n->frameOptions & FRAMEOPTION_START_UNBOUNDED_FOLLOWING)
17426 0 : ereport(ERROR,
17427 : (errcode(ERRCODE_WINDOWING_ERROR),
17428 : errmsg("frame start cannot be UNBOUNDED FOLLOWING"),
17429 : parser_errposition(@1)));
17430 8 : if (n->frameOptions & FRAMEOPTION_START_OFFSET_FOLLOWING)
17431 0 : ereport(ERROR,
17432 : (errcode(ERRCODE_WINDOWING_ERROR),
17433 : errmsg("frame starting from following row cannot end with current row"),
17434 : parser_errposition(@1)));
17435 8 : n->frameOptions |= FRAMEOPTION_END_CURRENT_ROW;
17436 8 : $$ = n;
17437 : }
17438 : | BETWEEN frame_bound AND frame_bound
17439 : {
17440 1120 : WindowDef *n1 = $2;
17441 1120 : WindowDef *n2 = $4;
17442 :
17443 : /* form merged options */
17444 1120 : int frameOptions = n1->frameOptions;
17445 : /* shift converts START_ options to END_ options */
17446 1120 : frameOptions |= n2->frameOptions << 1;
17447 1120 : frameOptions |= FRAMEOPTION_BETWEEN;
17448 : /* reject invalid cases */
17449 1120 : if (frameOptions & FRAMEOPTION_START_UNBOUNDED_FOLLOWING)
17450 0 : ereport(ERROR,
17451 : (errcode(ERRCODE_WINDOWING_ERROR),
17452 : errmsg("frame start cannot be UNBOUNDED FOLLOWING"),
17453 : parser_errposition(@2)));
17454 1120 : if (frameOptions & FRAMEOPTION_END_UNBOUNDED_PRECEDING)
17455 0 : ereport(ERROR,
17456 : (errcode(ERRCODE_WINDOWING_ERROR),
17457 : errmsg("frame end cannot be UNBOUNDED PRECEDING"),
17458 : parser_errposition(@4)));
17459 1120 : if ((frameOptions & FRAMEOPTION_START_CURRENT_ROW) &&
17460 308 : (frameOptions & FRAMEOPTION_END_OFFSET_PRECEDING))
17461 0 : ereport(ERROR,
17462 : (errcode(ERRCODE_WINDOWING_ERROR),
17463 : errmsg("frame starting from current row cannot have preceding rows"),
17464 : parser_errposition(@4)));
17465 1120 : if ((frameOptions & FRAMEOPTION_START_OFFSET_FOLLOWING) &&
17466 112 : (frameOptions & (FRAMEOPTION_END_OFFSET_PRECEDING |
17467 : FRAMEOPTION_END_CURRENT_ROW)))
17468 0 : ereport(ERROR,
17469 : (errcode(ERRCODE_WINDOWING_ERROR),
17470 : errmsg("frame starting from following row cannot have preceding rows"),
17471 : parser_errposition(@4)));
17472 1120 : n1->frameOptions = frameOptions;
17473 1120 : n1->endOffset = n2->startOffset;
17474 1120 : $$ = n1;
17475 : }
17476 : ;
17477 :
17478 : /*
17479 : * This is used for both frame start and frame end, with output set up on
17480 : * the assumption it's frame start; the frame_extent productions must reject
17481 : * invalid cases.
17482 : */
17483 : frame_bound:
17484 : UNBOUNDED PRECEDING
17485 : {
17486 144 : WindowDef *n = makeNode(WindowDef);
17487 :
17488 144 : n->frameOptions = FRAMEOPTION_START_UNBOUNDED_PRECEDING;
17489 144 : n->startOffset = NULL;
17490 144 : n->endOffset = NULL;
17491 144 : $$ = n;
17492 : }
17493 : | UNBOUNDED FOLLOWING
17494 : {
17495 262 : WindowDef *n = makeNode(WindowDef);
17496 :
17497 262 : n->frameOptions = FRAMEOPTION_START_UNBOUNDED_FOLLOWING;
17498 262 : n->startOffset = NULL;
17499 262 : n->endOffset = NULL;
17500 262 : $$ = n;
17501 : }
17502 : | CURRENT_P ROW
17503 : {
17504 404 : WindowDef *n = makeNode(WindowDef);
17505 :
17506 404 : n->frameOptions = FRAMEOPTION_START_CURRENT_ROW;
17507 404 : n->startOffset = NULL;
17508 404 : n->endOffset = NULL;
17509 404 : $$ = n;
17510 : }
17511 : | a_expr PRECEDING
17512 : {
17513 636 : WindowDef *n = makeNode(WindowDef);
17514 :
17515 636 : n->frameOptions = FRAMEOPTION_START_OFFSET_PRECEDING;
17516 636 : n->startOffset = $1;
17517 636 : n->endOffset = NULL;
17518 636 : $$ = n;
17519 : }
17520 : | a_expr FOLLOWING
17521 : {
17522 802 : WindowDef *n = makeNode(WindowDef);
17523 :
17524 802 : n->frameOptions = FRAMEOPTION_START_OFFSET_FOLLOWING;
17525 802 : n->startOffset = $1;
17526 802 : n->endOffset = NULL;
17527 802 : $$ = n;
17528 : }
17529 : ;
17530 :
17531 : opt_window_exclusion_clause:
17532 64 : EXCLUDE CURRENT_P ROW { $$ = FRAMEOPTION_EXCLUDE_CURRENT_ROW; }
17533 64 : | EXCLUDE GROUP_P { $$ = FRAMEOPTION_EXCLUDE_GROUP; }
17534 100 : | EXCLUDE TIES { $$ = FRAMEOPTION_EXCLUDE_TIES; }
17535 12 : | EXCLUDE NO OTHERS { $$ = 0; }
17536 888 : | /*EMPTY*/ { $$ = 0; }
17537 : ;
17538 :
17539 :
17540 : /*
17541 : * Supporting nonterminals for expressions.
17542 : */
17543 :
17544 : /* Explicit row production.
17545 : *
17546 : * SQL99 allows an optional ROW keyword, so we can now do single-element rows
17547 : * without conflicting with the parenthesized a_expr production. Without the
17548 : * ROW keyword, there must be more than one a_expr inside the parens.
17549 : */
17550 0 : row: ROW '(' expr_list ')' { $$ = $3; }
17551 0 : | ROW '(' ')' { $$ = NIL; }
17552 1126 : | '(' expr_list ',' a_expr ')' { $$ = lappend($2, $4); }
17553 : ;
17554 :
17555 2427 : explicit_row: ROW '(' expr_list ')' { $$ = $3; }
17556 24 : | ROW '(' ')' { $$ = NIL; }
17557 : ;
17558 :
17559 1848 : implicit_row: '(' expr_list ',' a_expr ')' { $$ = lappend($2, $4); }
17560 : ;
17561 :
17562 11265 : sub_type: ANY { $$ = ANY_SUBLINK; }
17563 0 : | SOME { $$ = ANY_SUBLINK; }
17564 221 : | ALL { $$ = ALL_SUBLINK; }
17565 : ;
17566 :
17567 7607 : all_Op: Op { $$ = $1; }
17568 17636 : | MathOp { $$ = $1; }
17569 : ;
17570 :
17571 29 : MathOp: '+' { $$ = "+"; }
17572 34 : | '-' { $$ = "-"; }
17573 98 : | '*' { $$ = "*"; }
17574 0 : | '/' { $$ = "/"; }
17575 4 : | '%' { $$ = "%"; }
17576 0 : | '^' { $$ = "^"; }
17577 549 : | '<' { $$ = "<"; }
17578 482 : | '>' { $$ = ">"; }
17579 15088 : | '=' { $$ = "="; }
17580 450 : | LESS_EQUALS { $$ = "<="; }
17581 444 : | GREATER_EQUALS { $$ = ">="; }
17582 438 : | NOT_EQUALS { $$ = "<>"; }
17583 17 : | RIGHT_ARROW { $$ = "->"; }
17584 3 : | '|' { $$ = "|"; }
17585 : ;
17586 :
17587 : qual_Op: Op
17588 27501 : { $$ = list_make1(makeString($1)); }
17589 : | OPERATOR '(' any_operator ')'
17590 9498 : { $$ = $3; }
17591 : ;
17592 :
17593 : qual_all_Op:
17594 : all_Op
17595 787 : { $$ = list_make1(makeString($1)); }
17596 : | OPERATOR '(' any_operator ')'
17597 17 : { $$ = $3; }
17598 : ;
17599 :
17600 : subquery_Op:
17601 : all_Op
17602 11308 : { $$ = list_make1(makeString($1)); }
17603 : | OPERATOR '(' any_operator ')'
17604 156 : { $$ = $3; }
17605 : | LIKE
17606 16 : { $$ = list_make1(makeString("~~")); }
17607 : | NOT_LA LIKE
17608 8 : { $$ = list_make1(makeString("!~~")); }
17609 : | ILIKE
17610 8 : { $$ = list_make1(makeString("~~*")); }
17611 : | NOT_LA ILIKE
17612 0 : { $$ = list_make1(makeString("!~~*")); }
17613 : /* cannot put SIMILAR TO here, because SIMILAR TO is a hack.
17614 : * the regular expression is preprocessed by a function (similar_to_escape),
17615 : * and the ~ operator for posix regular expressions is used.
17616 : * x SIMILAR TO y -> x ~ similar_to_escape(y)
17617 : * this transformation is made on the fly by the parser upwards.
17618 : * however the SubLink structure which handles any/some/all stuff
17619 : * is not ready for such a thing.
17620 : */
17621 : ;
17622 :
17623 : expr_list: a_expr
17624 : {
17625 106903 : $$ = list_make1($1);
17626 : }
17627 : | expr_list ',' a_expr
17628 : {
17629 97434 : $$ = lappend($1, $3);
17630 : }
17631 : ;
17632 :
17633 : /* function arguments can have names */
17634 : func_arg_list: func_arg_expr
17635 : {
17636 212394 : $$ = list_make1($1);
17637 : }
17638 : | func_arg_list ',' func_arg_expr
17639 : {
17640 181371 : $$ = lappend($1, $3);
17641 : }
17642 : ;
17643 :
17644 : func_arg_expr: a_expr
17645 : {
17646 367550 : $$ = $1;
17647 : }
17648 : | param_name COLON_EQUALS a_expr
17649 : {
17650 25258 : NamedArgExpr *na = makeNode(NamedArgExpr);
17651 :
17652 25258 : na->name = $1;
17653 25258 : na->arg = (Expr *) $3;
17654 25258 : na->argnumber = -1; /* until determined */
17655 25258 : na->location = @1;
17656 25258 : $$ = (Node *) na;
17657 : }
17658 : | param_name EQUALS_GREATER a_expr
17659 : {
17660 1446 : NamedArgExpr *na = makeNode(NamedArgExpr);
17661 :
17662 1446 : na->name = $1;
17663 1446 : na->arg = (Expr *) $3;
17664 1446 : na->argnumber = -1; /* until determined */
17665 1446 : na->location = @1;
17666 1446 : $$ = (Node *) na;
17667 : }
17668 : ;
17669 :
17670 198 : func_arg_list_opt: func_arg_list { $$ = $1; }
17671 0 : | /*EMPTY*/ { $$ = NIL; }
17672 : ;
17673 :
17674 1138 : type_list: Typename { $$ = list_make1($1); }
17675 304 : | type_list ',' Typename { $$ = lappend($1, $3); }
17676 : ;
17677 :
17678 : array_expr: '[' expr_list ']'
17679 : {
17680 5571 : $$ = makeAArrayExpr($2, @1, @3);
17681 : }
17682 : | '[' array_expr_list ']'
17683 : {
17684 255 : $$ = makeAArrayExpr($2, @1, @3);
17685 : }
17686 : | '[' ']'
17687 : {
17688 74 : $$ = makeAArrayExpr(NIL, @1, @2);
17689 : }
17690 : ;
17691 :
17692 255 : array_expr_list: array_expr { $$ = list_make1($1); }
17693 208 : | array_expr_list ',' array_expr { $$ = lappend($1, $3); }
17694 : ;
17695 :
17696 :
17697 : extract_list:
17698 : extract_arg FROM a_expr
17699 : {
17700 884 : $$ = list_make2(makeStringConst($1, @1), $3);
17701 : }
17702 : ;
17703 :
17704 : /* Allow delimited string Sconst in extract_arg as an SQL extension.
17705 : * - thomas 2001-04-12
17706 : */
17707 : extract_arg:
17708 712 : IDENT { $$ = $1; }
17709 48 : | YEAR_P { $$ = "year"; }
17710 28 : | MONTH_P { $$ = "month"; }
17711 36 : | DAY_P { $$ = "day"; }
17712 20 : | HOUR_P { $$ = "hour"; }
17713 20 : | MINUTE_P { $$ = "minute"; }
17714 20 : | SECOND_P { $$ = "second"; }
17715 0 : | Sconst { $$ = $1; }
17716 : ;
17717 :
17718 : unicode_normal_form:
17719 16 : NFC { $$ = "NFC"; }
17720 12 : | NFD { $$ = "NFD"; }
17721 12 : | NFKC { $$ = "NFKC"; }
17722 12 : | NFKD { $$ = "NFKD"; }
17723 : ;
17724 :
17725 : /* OVERLAY() arguments */
17726 : overlay_list:
17727 : a_expr PLACING a_expr FROM a_expr FOR a_expr
17728 : {
17729 : /* overlay(A PLACING B FROM C FOR D) is converted to overlay(A, B, C, D) */
17730 22 : $$ = list_make4($1, $3, $5, $7);
17731 : }
17732 : | a_expr PLACING a_expr FROM a_expr
17733 : {
17734 : /* overlay(A PLACING B FROM C) is converted to overlay(A, B, C) */
17735 32 : $$ = list_make3($1, $3, $5);
17736 : }
17737 : ;
17738 :
17739 : /* position_list uses b_expr not a_expr to avoid conflict with general IN */
17740 : position_list:
17741 261 : b_expr IN_P b_expr { $$ = list_make2($3, $1); }
17742 : ;
17743 :
17744 : /*
17745 : * SUBSTRING() arguments
17746 : *
17747 : * Note that SQL:1999 has both
17748 : * text FROM int FOR int
17749 : * and
17750 : * text FROM pattern FOR escape
17751 : *
17752 : * In the parser we map them both to a call to the substring() function and
17753 : * rely on type resolution to pick the right one.
17754 : *
17755 : * In SQL:2003, the second variant was changed to
17756 : * text SIMILAR pattern ESCAPE escape
17757 : * We could in theory map that to a different function internally, but
17758 : * since we still support the SQL:1999 version, we don't. However,
17759 : * ruleutils.c will reverse-list the call in the newer style.
17760 : */
17761 : substr_list:
17762 : a_expr FROM a_expr FOR a_expr
17763 : {
17764 101 : $$ = list_make3($1, $3, $5);
17765 : }
17766 : | a_expr FOR a_expr FROM a_expr
17767 : {
17768 : /* not legal per SQL, but might as well allow it */
17769 0 : $$ = list_make3($1, $5, $3);
17770 : }
17771 : | a_expr FROM a_expr
17772 : {
17773 : /*
17774 : * Because we aren't restricting data types here, this
17775 : * syntax can end up resolving to textregexsubstr().
17776 : * We've historically allowed that to happen, so continue
17777 : * to accept it. However, ruleutils.c will reverse-list
17778 : * such a call in regular function call syntax.
17779 : */
17780 219 : $$ = list_make2($1, $3);
17781 : }
17782 : | a_expr FOR a_expr
17783 : {
17784 : /* not legal per SQL */
17785 :
17786 : /*
17787 : * Since there are no cases where this syntax allows
17788 : * a textual FOR value, we forcibly cast the argument
17789 : * to int4. The possible matches in pg_proc are
17790 : * substring(text,int4) and substring(text,text),
17791 : * and we don't want the parser to choose the latter,
17792 : * which it is likely to do if the second argument
17793 : * is unknown or doesn't have an implicit cast to int4.
17794 : */
17795 27 : $$ = list_make3($1, makeIntConst(1, -1),
17796 : makeTypeCast($3,
17797 : SystemTypeName("int4"), -1));
17798 : }
17799 : | a_expr SIMILAR a_expr ESCAPE a_expr
17800 : {
17801 116 : $$ = list_make3($1, $3, $5);
17802 : }
17803 : ;
17804 :
17805 394 : trim_list: a_expr FROM expr_list { $$ = lappend($3, $1); }
17806 16 : | FROM expr_list { $$ = $2; }
17807 56 : | expr_list { $$ = $1; }
17808 : ;
17809 :
17810 : /*
17811 : * Define SQL-style CASE clause.
17812 : * - Full specification
17813 : * CASE WHEN a = b THEN c ... ELSE d END
17814 : * - Implicit argument
17815 : * CASE a WHEN b THEN c ... ELSE d END
17816 : */
17817 : case_expr: CASE case_arg when_clause_list case_default END_P
17818 : {
17819 26420 : CaseExpr *c = makeNode(CaseExpr);
17820 :
17821 26420 : c->casetype = InvalidOid; /* not analyzed yet */
17822 26420 : c->arg = (Expr *) $2;
17823 26420 : c->args = $3;
17824 26420 : c->defresult = (Expr *) $4;
17825 26420 : c->location = @1;
17826 26420 : $$ = (Node *) c;
17827 : }
17828 : ;
17829 :
17830 : when_clause_list:
17831 : /* There must be at least one */
17832 26420 : when_clause { $$ = list_make1($1); }
17833 20282 : | when_clause_list when_clause { $$ = lappend($1, $2); }
17834 : ;
17835 :
17836 : when_clause:
17837 : WHEN a_expr THEN a_expr
17838 : {
17839 46702 : CaseWhen *w = makeNode(CaseWhen);
17840 :
17841 46702 : w->expr = (Expr *) $2;
17842 46702 : w->result = (Expr *) $4;
17843 46702 : w->location = @1;
17844 46702 : $$ = (Node *) w;
17845 : }
17846 : ;
17847 :
17848 : case_default:
17849 19876 : ELSE a_expr { $$ = $2; }
17850 6544 : | /*EMPTY*/ { $$ = NULL; }
17851 : ;
17852 :
17853 5081 : case_arg: a_expr { $$ = $1; }
17854 21339 : | /*EMPTY*/ { $$ = NULL; }
17855 : ;
17856 :
17857 : columnref: ColId
17858 : {
17859 491041 : $$ = makeColumnRef($1, NIL, @1, yyscanner);
17860 : }
17861 : | ColId indirection
17862 : {
17863 719070 : $$ = makeColumnRef($1, $2, @1, yyscanner);
17864 : }
17865 : ;
17866 :
17867 : indirection_el:
17868 : '.' attr_name
17869 : {
17870 963475 : $$ = (Node *) makeString($2);
17871 : }
17872 : | '.' '*'
17873 : {
17874 4621 : $$ = (Node *) makeNode(A_Star);
17875 : }
17876 : | '[' a_expr ']'
17877 : {
17878 8986 : A_Indices *ai = makeNode(A_Indices);
17879 :
17880 8986 : ai->is_slice = false;
17881 8986 : ai->lidx = NULL;
17882 8986 : ai->uidx = $2;
17883 8986 : $$ = (Node *) ai;
17884 : }
17885 : | '[' opt_slice_bound ':' opt_slice_bound ']'
17886 : {
17887 405 : A_Indices *ai = makeNode(A_Indices);
17888 :
17889 405 : ai->is_slice = true;
17890 405 : ai->lidx = $2;
17891 405 : ai->uidx = $4;
17892 405 : $$ = (Node *) ai;
17893 : }
17894 : ;
17895 :
17896 : opt_slice_bound:
17897 690 : a_expr { $$ = $1; }
17898 120 : | /*EMPTY*/ { $$ = NULL; }
17899 : ;
17900 :
17901 : indirection:
17902 962624 : indirection_el { $$ = list_make1($1); }
17903 2112 : | indirection indirection_el { $$ = lappend($1, $2); }
17904 : ;
17905 :
17906 : opt_indirection:
17907 126496 : /*EMPTY*/ { $$ = NIL; }
17908 12751 : | opt_indirection indirection_el { $$ = lappend($1, $2); }
17909 : ;
17910 :
17911 : opt_asymmetric: ASYMMETRIC
17912 : | /*EMPTY*/
17913 : ;
17914 :
17915 : /* SQL/JSON support */
17916 : json_passing_clause_opt:
17917 224 : PASSING json_arguments { $$ = $2; }
17918 1364 : | /*EMPTY*/ { $$ = NIL; }
17919 : ;
17920 :
17921 : json_arguments:
17922 224 : json_argument { $$ = list_make1($1); }
17923 84 : | json_arguments ',' json_argument { $$ = lappend($1, $3); }
17924 : ;
17925 :
17926 : json_argument:
17927 : json_value_expr AS ColLabel
17928 : {
17929 308 : JsonArgument *n = makeNode(JsonArgument);
17930 :
17931 308 : n->val = (JsonValueExpr *) $1;
17932 308 : n->name = $3;
17933 308 : $$ = (Node *) n;
17934 : }
17935 : ;
17936 :
17937 : /* ARRAY is a noise word */
17938 : json_wrapper_behavior:
17939 28 : WITHOUT WRAPPER { $$ = JSW_NONE; }
17940 0 : | WITHOUT ARRAY WRAPPER { $$ = JSW_NONE; }
17941 56 : | WITH WRAPPER { $$ = JSW_UNCONDITIONAL; }
17942 8 : | WITH ARRAY WRAPPER { $$ = JSW_UNCONDITIONAL; }
17943 0 : | WITH CONDITIONAL ARRAY WRAPPER { $$ = JSW_CONDITIONAL; }
17944 8 : | WITH UNCONDITIONAL ARRAY WRAPPER { $$ = JSW_UNCONDITIONAL; }
17945 24 : | WITH CONDITIONAL WRAPPER { $$ = JSW_CONDITIONAL; }
17946 4 : | WITH UNCONDITIONAL WRAPPER { $$ = JSW_UNCONDITIONAL; }
17947 1124 : | /* empty */ { $$ = JSW_UNSPEC; }
17948 : ;
17949 :
17950 : json_behavior:
17951 : DEFAULT a_expr
17952 288 : { $$ = (Node *) makeJsonBehavior(JSON_BEHAVIOR_DEFAULT, $2, @1); }
17953 : | json_behavior_type
17954 468 : { $$ = (Node *) makeJsonBehavior($1, NULL, @1); }
17955 : ;
17956 :
17957 : json_behavior_type:
17958 328 : ERROR_P { $$ = JSON_BEHAVIOR_ERROR; }
17959 20 : | NULL_P { $$ = JSON_BEHAVIOR_NULL; }
17960 20 : | TRUE_P { $$ = JSON_BEHAVIOR_TRUE; }
17961 8 : | FALSE_P { $$ = JSON_BEHAVIOR_FALSE; }
17962 8 : | UNKNOWN { $$ = JSON_BEHAVIOR_UNKNOWN; }
17963 20 : | EMPTY_P ARRAY { $$ = JSON_BEHAVIOR_EMPTY_ARRAY; }
17964 48 : | EMPTY_P OBJECT_P { $$ = JSON_BEHAVIOR_EMPTY_OBJECT; }
17965 : /* non-standard, for Oracle compatibility only */
17966 16 : | EMPTY_P { $$ = JSON_BEHAVIOR_EMPTY_ARRAY; }
17967 : ;
17968 :
17969 : json_behavior_clause_opt:
17970 : json_behavior ON EMPTY_P
17971 148 : { $$ = list_make2($1, NULL); }
17972 : | json_behavior ON ERROR_P
17973 368 : { $$ = list_make2(NULL, $1); }
17974 : | json_behavior ON EMPTY_P json_behavior ON ERROR_P
17975 68 : { $$ = list_make2($1, $4); }
17976 : | /* EMPTY */
17977 1088 : { $$ = list_make2(NULL, NULL); }
17978 : ;
17979 :
17980 : json_on_error_clause_opt:
17981 : json_behavior ON ERROR_P
17982 100 : { $$ = $1; }
17983 : | /* EMPTY */
17984 460 : { $$ = NULL; }
17985 : ;
17986 :
17987 : json_value_expr:
17988 : a_expr json_format_clause_opt
17989 : {
17990 : /* formatted_expr will be set during parse-analysis. */
17991 3070 : $$ = (Node *) makeJsonValueExpr((Expr *) $1, NULL,
17992 3070 : castNode(JsonFormat, $2));
17993 : }
17994 : ;
17995 :
17996 : json_format_clause:
17997 : FORMAT_LA JSON ENCODING name
17998 : {
17999 : int encoding;
18000 :
18001 66 : if (!pg_strcasecmp($4, "utf8"))
18002 42 : encoding = JS_ENC_UTF8;
18003 24 : else if (!pg_strcasecmp($4, "utf16"))
18004 8 : encoding = JS_ENC_UTF16;
18005 16 : else if (!pg_strcasecmp($4, "utf32"))
18006 8 : encoding = JS_ENC_UTF32;
18007 : else
18008 8 : ereport(ERROR,
18009 : (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
18010 : errmsg("unrecognized JSON encoding: %s", $4),
18011 : parser_errposition(@4)));
18012 :
18013 58 : $$ = (Node *) makeJsonFormat(JS_FORMAT_JSON, encoding, @1);
18014 : }
18015 : | FORMAT_LA JSON
18016 : {
18017 272 : $$ = (Node *) makeJsonFormat(JS_FORMAT_JSON, JS_ENC_DEFAULT, @1);
18018 : }
18019 : ;
18020 :
18021 : json_format_clause_opt:
18022 : json_format_clause
18023 : {
18024 258 : $$ = $1;
18025 : }
18026 : | /* EMPTY */
18027 : {
18028 4038 : $$ = (Node *) makeJsonFormat(JS_FORMAT_DEFAULT, JS_ENC_DEFAULT, -1);
18029 : }
18030 : ;
18031 :
18032 : json_quotes_clause_opt:
18033 8 : KEEP QUOTES ON SCALAR STRING_P { $$ = JS_QUOTES_KEEP; }
18034 60 : | KEEP QUOTES { $$ = JS_QUOTES_KEEP; }
18035 8 : | OMIT QUOTES ON SCALAR STRING_P { $$ = JS_QUOTES_OMIT; }
18036 112 : | OMIT QUOTES { $$ = JS_QUOTES_OMIT; }
18037 1064 : | /* EMPTY */ { $$ = JS_QUOTES_UNSPEC; }
18038 : ;
18039 :
18040 : json_returning_clause_opt:
18041 : RETURNING Typename json_format_clause_opt
18042 : {
18043 1186 : JsonOutput *n = makeNode(JsonOutput);
18044 :
18045 1186 : n->typeName = $2;
18046 1186 : n->returning = makeNode(JsonReturning);
18047 1186 : n->returning->format = (JsonFormat *) $3;
18048 1186 : $$ = (Node *) n;
18049 : }
18050 892 : | /* EMPTY */ { $$ = NULL; }
18051 : ;
18052 :
18053 : /*
18054 : * We must assign the only-JSON production a precedence less than IDENT in
18055 : * order to favor shifting over reduction when JSON is followed by VALUE_P,
18056 : * OBJECT_P, or SCALAR. (ARRAY doesn't need that treatment, because it's a
18057 : * fully reserved word.) Because json_predicate_type_constraint is always
18058 : * followed by json_key_uniqueness_constraint_opt, we also need the only-JSON
18059 : * production to have precedence less than WITH and WITHOUT. UNBOUNDED isn't
18060 : * really related to this syntax, but it's a convenient choice because it
18061 : * already has a precedence less than IDENT for other reasons.
18062 : */
18063 : json_predicate_type_constraint:
18064 176 : JSON %prec UNBOUNDED { $$ = JS_TYPE_ANY; }
18065 18 : | JSON VALUE_P { $$ = JS_TYPE_ANY; }
18066 26 : | JSON ARRAY { $$ = JS_TYPE_ARRAY; }
18067 26 : | JSON OBJECT_P { $$ = JS_TYPE_OBJECT; }
18068 26 : | JSON SCALAR { $$ = JS_TYPE_SCALAR; }
18069 : ;
18070 :
18071 : /*
18072 : * KEYS is a noise word here. To avoid shift/reduce conflicts, assign the
18073 : * KEYS-less productions a precedence less than IDENT (i.e., less than KEYS).
18074 : * This prevents reducing them when the next token is KEYS.
18075 : */
18076 : json_key_uniqueness_constraint_opt:
18077 98 : WITH UNIQUE KEYS { $$ = true; }
18078 66 : | WITH UNIQUE %prec UNBOUNDED { $$ = true; }
18079 28 : | WITHOUT UNIQUE KEYS { $$ = false; }
18080 10 : | WITHOUT UNIQUE %prec UNBOUNDED { $$ = false; }
18081 636 : | /* EMPTY */ %prec UNBOUNDED { $$ = false; }
18082 : ;
18083 :
18084 : json_name_and_value_list:
18085 : json_name_and_value
18086 318 : { $$ = list_make1($1); }
18087 : | json_name_and_value_list ',' json_name_and_value
18088 168 : { $$ = lappend($1, $3); }
18089 : ;
18090 :
18091 : json_name_and_value:
18092 : /* Supporting this syntax seems to require major surgery
18093 : KEY c_expr VALUE_P json_value_expr
18094 : { $$ = makeJsonKeyValue($2, $4); }
18095 : |
18096 : */
18097 : c_expr VALUE_P json_value_expr
18098 104 : { $$ = makeJsonKeyValue($1, $3); }
18099 : |
18100 : a_expr ':' json_value_expr
18101 526 : { $$ = makeJsonKeyValue($1, $3); }
18102 : ;
18103 :
18104 : /* empty means false for objects, true for arrays */
18105 : json_object_constructor_null_clause_opt:
18106 20 : NULL_P ON NULL_P { $$ = false; }
18107 80 : | ABSENT ON NULL_P { $$ = true; }
18108 362 : | /* EMPTY */ { $$ = false; }
18109 : ;
18110 :
18111 : json_array_constructor_null_clause_opt:
18112 40 : NULL_P ON NULL_P { $$ = false; }
18113 24 : | ABSENT ON NULL_P { $$ = true; }
18114 216 : | /* EMPTY */ { $$ = true; }
18115 : ;
18116 :
18117 : json_value_expr_list:
18118 168 : json_value_expr { $$ = list_make1($1); }
18119 92 : | json_value_expr_list ',' json_value_expr { $$ = lappend($1, $3);}
18120 : ;
18121 :
18122 : json_aggregate_func:
18123 : JSON_OBJECTAGG '('
18124 : json_name_and_value
18125 : json_object_constructor_null_clause_opt
18126 : json_key_uniqueness_constraint_opt
18127 : json_returning_clause_opt
18128 : ')'
18129 : {
18130 144 : JsonObjectAgg *n = makeNode(JsonObjectAgg);
18131 :
18132 144 : n->arg = (JsonKeyValue *) $3;
18133 144 : n->absent_on_null = $4;
18134 144 : n->unique = $5;
18135 144 : n->constructor = makeNode(JsonAggConstructor);
18136 144 : n->constructor->output = (JsonOutput *) $6;
18137 144 : n->constructor->agg_order = NULL;
18138 144 : n->constructor->location = @1;
18139 144 : $$ = (Node *) n;
18140 : }
18141 : | JSON_ARRAYAGG '('
18142 : json_value_expr
18143 : json_array_aggregate_order_by_clause_opt
18144 : json_array_constructor_null_clause_opt
18145 : json_returning_clause_opt
18146 : ')'
18147 : {
18148 112 : JsonArrayAgg *n = makeNode(JsonArrayAgg);
18149 :
18150 112 : n->arg = (JsonValueExpr *) $3;
18151 112 : n->absent_on_null = $5;
18152 112 : n->constructor = makeNode(JsonAggConstructor);
18153 112 : n->constructor->agg_order = $4;
18154 112 : n->constructor->output = (JsonOutput *) $6;
18155 112 : n->constructor->location = @1;
18156 112 : $$ = (Node *) n;
18157 : }
18158 : ;
18159 :
18160 : json_array_aggregate_order_by_clause_opt:
18161 12 : ORDER BY sortby_list { $$ = $3; }
18162 100 : | /* EMPTY */ { $$ = NIL; }
18163 : ;
18164 :
18165 :
18166 : /*****************************************************************************
18167 : *
18168 : * graph patterns
18169 : *
18170 : *****************************************************************************/
18171 :
18172 : graph_pattern:
18173 : path_pattern_list where_clause
18174 : {
18175 421 : GraphPattern *gp = makeNode(GraphPattern);
18176 :
18177 421 : gp->path_pattern_list = $1;
18178 421 : gp->whereClause = $2;
18179 421 : $$ = (Node *) gp;
18180 : }
18181 : ;
18182 :
18183 : path_pattern_list:
18184 421 : path_pattern { $$ = list_make1($1); }
18185 4 : | path_pattern_list ',' path_pattern { $$ = lappend($1, $3); }
18186 : ;
18187 :
18188 : path_pattern:
18189 425 : path_pattern_expression { $$ = $1; }
18190 : ;
18191 :
18192 : /*
18193 : * path pattern expression
18194 : */
18195 :
18196 : path_pattern_expression:
18197 429 : path_term { $$ = $1; }
18198 : /* | path_multiset_alternation */
18199 : /* | path_pattern_union */
18200 : ;
18201 :
18202 : path_term:
18203 433 : path_factor { $$ = list_make1($1); }
18204 850 : | path_term path_factor { $$ = lappend($1, $2); }
18205 : ;
18206 :
18207 : path_factor:
18208 : path_primary opt_graph_pattern_quantifier
18209 : {
18210 1283 : GraphElementPattern *gep = (GraphElementPattern *) $1;
18211 :
18212 1283 : gep->quantifier = $2;
18213 :
18214 1283 : $$ = (Node *) gep;
18215 : }
18216 : ;
18217 :
18218 : path_primary:
18219 : '(' opt_colid opt_is_label_expression where_clause ')'
18220 : {
18221 848 : GraphElementPattern *gep = makeNode(GraphElementPattern);
18222 :
18223 848 : gep->kind = VERTEX_PATTERN;
18224 848 : gep->variable = $2;
18225 848 : gep->labelexpr = $3;
18226 848 : gep->whereClause = $4;
18227 848 : gep->location = @1;
18228 :
18229 848 : $$ = (Node *) gep;
18230 : }
18231 : /* full edge pointing left: <-[ xxx ]- */
18232 : | '<' '-' '[' opt_colid opt_is_label_expression where_clause ']' '-'
18233 : {
18234 8 : GraphElementPattern *gep = makeNode(GraphElementPattern);
18235 :
18236 8 : gep->kind = EDGE_PATTERN_LEFT;
18237 8 : gep->variable = $4;
18238 8 : gep->labelexpr = $5;
18239 8 : gep->whereClause = $6;
18240 8 : gep->location = @1;
18241 :
18242 8 : $$ = (Node *) gep;
18243 : }
18244 : /* full edge pointing right: -[ xxx ]-> */
18245 : | '-' '[' opt_colid opt_is_label_expression where_clause ']' '-' '>'
18246 : {
18247 0 : GraphElementPattern *gep = makeNode(GraphElementPattern);
18248 :
18249 0 : gep->kind = EDGE_PATTERN_RIGHT;
18250 0 : gep->variable = $3;
18251 0 : gep->labelexpr = $4;
18252 0 : gep->whereClause = $5;
18253 0 : gep->location = @1;
18254 :
18255 0 : $$ = (Node *) gep;
18256 : }
18257 : | '-' '[' opt_colid opt_is_label_expression where_clause ']' RIGHT_ARROW
18258 : {
18259 279 : GraphElementPattern *gep = makeNode(GraphElementPattern);
18260 :
18261 279 : gep->kind = EDGE_PATTERN_RIGHT;
18262 279 : gep->variable = $3;
18263 279 : gep->labelexpr = $4;
18264 279 : gep->whereClause = $5;
18265 279 : gep->location = @1;
18266 :
18267 279 : $$ = (Node *) gep;
18268 : }
18269 : /* full edge any direction: -[ xxx ]- */
18270 : | '-' '[' opt_colid opt_is_label_expression where_clause ']' '-'
18271 : {
18272 20 : GraphElementPattern *gep = makeNode(GraphElementPattern);
18273 :
18274 20 : gep->kind = EDGE_PATTERN_ANY;
18275 20 : gep->variable = $3;
18276 20 : gep->labelexpr = $4;
18277 20 : gep->whereClause = $5;
18278 20 : gep->location = @1;
18279 :
18280 20 : $$ = (Node *) gep;
18281 : }
18282 : /* abbreviated edge patterns */
18283 : | '<' '-'
18284 : {
18285 0 : GraphElementPattern *gep = makeNode(GraphElementPattern);
18286 :
18287 0 : gep->kind = EDGE_PATTERN_LEFT;
18288 0 : gep->location = @1;
18289 :
18290 0 : $$ = (Node *) gep;
18291 : }
18292 : | '-' '>'
18293 : {
18294 0 : GraphElementPattern *gep = makeNode(GraphElementPattern);
18295 :
18296 0 : gep->kind = EDGE_PATTERN_RIGHT;
18297 0 : gep->location = @1;
18298 :
18299 0 : $$ = (Node *) gep;
18300 : }
18301 : | RIGHT_ARROW
18302 : {
18303 116 : GraphElementPattern *gep = makeNode(GraphElementPattern);
18304 :
18305 116 : gep->kind = EDGE_PATTERN_RIGHT;
18306 116 : gep->location = @1;
18307 :
18308 116 : $$ = (Node *) gep;
18309 : }
18310 : | '-'
18311 : {
18312 8 : GraphElementPattern *gep = makeNode(GraphElementPattern);
18313 :
18314 8 : gep->kind = EDGE_PATTERN_ANY;
18315 8 : gep->location = @1;
18316 :
18317 8 : $$ = (Node *) gep;
18318 : }
18319 : | '(' path_pattern_expression where_clause ')'
18320 : {
18321 4 : GraphElementPattern *gep = makeNode(GraphElementPattern);
18322 :
18323 4 : gep->kind = PAREN_EXPR;
18324 4 : gep->subexpr = $2;
18325 4 : gep->whereClause = $3;
18326 4 : gep->location = @1;
18327 :
18328 4 : $$ = (Node *) gep;
18329 : }
18330 : ;
18331 :
18332 : opt_colid:
18333 944 : ColId { $$ = $1; }
18334 215 : | /*EMPTY*/ { $$ = NULL; }
18335 : ;
18336 :
18337 : opt_is_label_expression:
18338 627 : IS label_expression { $$ = $2; }
18339 532 : | /*EMPTY*/ { $$ = NULL; }
18340 : ;
18341 :
18342 : /*
18343 : * graph pattern quantifier
18344 : */
18345 :
18346 : opt_graph_pattern_quantifier:
18347 0 : '{' Iconst '}' { $$ = list_make2_int($2, $2); }
18348 0 : | '{' ',' Iconst '}' { $$ = list_make2_int(0, $3); }
18349 4 : | '{' Iconst ',' Iconst '}' { $$ = list_make2_int($2, $4); }
18350 1279 : | /*EMPTY*/ { $$ = NULL; }
18351 : ;
18352 :
18353 : /*
18354 : * label expression
18355 : */
18356 :
18357 : label_expression:
18358 : label_term
18359 : | label_disjunction
18360 : ;
18361 :
18362 : label_disjunction:
18363 : label_expression '|' label_term
18364 56 : { $$ = makeOrExpr($1, $3, @2); }
18365 : ;
18366 :
18367 : label_term:
18368 : name
18369 683 : { $$ = makeColumnRef($1, NIL, @1, yyscanner); }
18370 : ;
18371 :
18372 :
18373 : /*****************************************************************************
18374 : *
18375 : * target list for SELECT
18376 : *
18377 : *****************************************************************************/
18378 :
18379 312676 : opt_target_list: target_list { $$ = $1; }
18380 348 : | /* EMPTY */ { $$ = NIL; }
18381 : ;
18382 :
18383 : target_list:
18384 317499 : target_el { $$ = list_make1($1); }
18385 444850 : | target_list ',' target_el { $$ = lappend($1, $3); }
18386 : ;
18387 :
18388 : target_el: a_expr AS ColLabel
18389 : {
18390 155321 : $$ = makeNode(ResTarget);
18391 155321 : $$->name = $3;
18392 155321 : $$->indirection = NIL;
18393 155321 : $$->val = (Node *) $1;
18394 155321 : $$->location = @1;
18395 : }
18396 : | a_expr BareColLabel
18397 : {
18398 2318 : $$ = makeNode(ResTarget);
18399 2318 : $$->name = $2;
18400 2318 : $$->indirection = NIL;
18401 2318 : $$->val = (Node *) $1;
18402 2318 : $$->location = @1;
18403 : }
18404 : | a_expr
18405 : {
18406 564076 : $$ = makeNode(ResTarget);
18407 564076 : $$->name = NULL;
18408 564076 : $$->indirection = NIL;
18409 564076 : $$->val = (Node *) $1;
18410 564076 : $$->location = @1;
18411 : }
18412 : | '*'
18413 : {
18414 40634 : ColumnRef *n = makeNode(ColumnRef);
18415 :
18416 40634 : n->fields = list_make1(makeNode(A_Star));
18417 40634 : n->location = @1;
18418 :
18419 40634 : $$ = makeNode(ResTarget);
18420 40634 : $$->name = NULL;
18421 40634 : $$->indirection = NIL;
18422 40634 : $$->val = (Node *) n;
18423 40634 : $$->location = @1;
18424 : }
18425 : ;
18426 :
18427 :
18428 : /*****************************************************************************
18429 : *
18430 : * Names and constants
18431 : *
18432 : *****************************************************************************/
18433 :
18434 : qualified_name_list:
18435 10419 : qualified_name { $$ = list_make1($1); }
18436 531 : | qualified_name_list ',' qualified_name { $$ = lappend($1, $3); }
18437 : ;
18438 :
18439 : /*
18440 : * The production for a qualified relation name has to exactly match the
18441 : * production for a qualified func_name, because in a FROM clause we cannot
18442 : * tell which we are parsing until we see what comes after it ('(' for a
18443 : * func_name, something else for a relation). Therefore we allow 'indirection'
18444 : * which may contain subscripts, and reject that case in the C code.
18445 : */
18446 : qualified_name:
18447 : ColId
18448 : {
18449 284227 : $$ = makeRangeVar(NULL, $1, @1);
18450 : }
18451 : | ColId indirection
18452 : {
18453 157693 : $$ = makeRangeVarFromQualifiedName($1, $2, @1, yyscanner);
18454 : }
18455 : ;
18456 :
18457 : name_list: name
18458 18465 : { $$ = list_make1(makeString($1)); }
18459 : | name_list ',' name
18460 37905 : { $$ = lappend($1, makeString($3)); }
18461 : ;
18462 :
18463 :
18464 110160 : name: ColId { $$ = $1; };
18465 :
18466 1040468 : attr_name: ColLabel { $$ = $1; };
18467 :
18468 45 : file_name: Sconst { $$ = $1; };
18469 :
18470 : /*
18471 : * The production for a qualified func_name has to exactly match the
18472 : * production for a qualified columnref, because we cannot tell which we
18473 : * are parsing until we see what comes after it ('(' or Sconst for a func_name,
18474 : * anything else for a columnref). Therefore we allow 'indirection' which
18475 : * may contain subscripts, and reject that case in the C code. (If we
18476 : * ever implement SQL99-like methods, such syntax may actually become legal!)
18477 : */
18478 : func_name: type_function_name
18479 185704 : { $$ = list_make1(makeString($1)); }
18480 : | ColId indirection
18481 : {
18482 85814 : $$ = check_func_name(lcons(makeString($1), $2),
18483 : yyscanner);
18484 : }
18485 : ;
18486 :
18487 :
18488 : /*
18489 : * Constants
18490 : */
18491 : AexprConst: Iconst
18492 : {
18493 257469 : $$ = makeIntConst($1, @1);
18494 : }
18495 : | FCONST
18496 : {
18497 7865 : $$ = makeFloatConst($1, @1);
18498 : }
18499 : | Sconst
18500 : {
18501 461488 : $$ = makeStringConst($1, @1);
18502 : }
18503 : | BCONST
18504 : {
18505 502 : $$ = makeBitStringConst($1, @1);
18506 : }
18507 : | XCONST
18508 : {
18509 : /* This is a bit constant per SQL99:
18510 : * Without Feature F511, "BIT data type",
18511 : * a <general literal> shall not be a
18512 : * <bit string literal> or a <hex string literal>.
18513 : */
18514 2217 : $$ = makeBitStringConst($1, @1);
18515 : }
18516 : | func_name Sconst
18517 : {
18518 : /* generic type 'literal' syntax */
18519 6317 : TypeName *t = makeTypeNameFromNameList($1);
18520 :
18521 6317 : t->location = @1;
18522 6317 : $$ = makeStringConstCast($2, @2, t);
18523 : }
18524 : | func_name '(' func_arg_list opt_sort_clause ')' Sconst
18525 : {
18526 : /* generic syntax with a type modifier */
18527 0 : TypeName *t = makeTypeNameFromNameList($1);
18528 : ListCell *lc;
18529 :
18530 : /*
18531 : * We must use func_arg_list and opt_sort_clause in the
18532 : * production to avoid reduce/reduce conflicts, but we
18533 : * don't actually wish to allow NamedArgExpr in this
18534 : * context, nor ORDER BY.
18535 : */
18536 0 : foreach(lc, $3)
18537 : {
18538 0 : NamedArgExpr *arg = (NamedArgExpr *) lfirst(lc);
18539 :
18540 0 : if (IsA(arg, NamedArgExpr))
18541 0 : ereport(ERROR,
18542 : (errcode(ERRCODE_SYNTAX_ERROR),
18543 : errmsg("type modifier cannot have parameter name"),
18544 : parser_errposition(arg->location)));
18545 : }
18546 0 : if ($4 != NIL)
18547 0 : ereport(ERROR,
18548 : (errcode(ERRCODE_SYNTAX_ERROR),
18549 : errmsg("type modifier cannot have ORDER BY"),
18550 : parser_errposition(@4)));
18551 :
18552 0 : t->typmods = $3;
18553 0 : t->location = @1;
18554 0 : $$ = makeStringConstCast($6, @6, t);
18555 : }
18556 : | ConstTypename Sconst
18557 : {
18558 2043 : $$ = makeStringConstCast($2, @2, $1);
18559 : }
18560 : | ConstInterval Sconst opt_interval
18561 : {
18562 2204 : TypeName *t = $1;
18563 :
18564 2204 : t->typmods = $3;
18565 2204 : $$ = makeStringConstCast($2, @2, t);
18566 : }
18567 : | ConstInterval '(' Iconst ')' Sconst
18568 : {
18569 8 : TypeName *t = $1;
18570 :
18571 8 : t->typmods = list_make2(makeIntConst(INTERVAL_FULL_RANGE, -1),
18572 : makeIntConst($3, @3));
18573 8 : $$ = makeStringConstCast($5, @5, t);
18574 : }
18575 : | TRUE_P
18576 : {
18577 19573 : $$ = makeBoolAConst(true, @1);
18578 : }
18579 : | FALSE_P
18580 : {
18581 20484 : $$ = makeBoolAConst(false, @1);
18582 : }
18583 : | NULL_P
18584 : {
18585 43927 : $$ = makeNullAConst(@1);
18586 : }
18587 : ;
18588 :
18589 273612 : Iconst: ICONST { $$ = $1; };
18590 503868 : Sconst: SCONST { $$ = $1; };
18591 :
18592 9753 : SignedIconst: Iconst { $$ = $1; }
18593 0 : | '+' Iconst { $$ = + $2; }
18594 178 : | '-' Iconst { $$ = - $2; }
18595 : ;
18596 :
18597 : /* Role specifications */
18598 : RoleId: RoleSpec
18599 : {
18600 1381 : RoleSpec *spc = (RoleSpec *) $1;
18601 :
18602 1381 : switch (spc->roletype)
18603 : {
18604 1376 : case ROLESPEC_CSTRING:
18605 1376 : $$ = spc->rolename;
18606 1376 : break;
18607 2 : case ROLESPEC_PUBLIC:
18608 2 : ereport(ERROR,
18609 : (errcode(ERRCODE_RESERVED_NAME),
18610 : errmsg("role name \"%s\" is reserved",
18611 : "public"),
18612 : parser_errposition(@1)));
18613 : break;
18614 1 : case ROLESPEC_SESSION_USER:
18615 1 : ereport(ERROR,
18616 : (errcode(ERRCODE_RESERVED_NAME),
18617 : errmsg("%s cannot be used as a role name here",
18618 : "SESSION_USER"),
18619 : parser_errposition(@1)));
18620 : break;
18621 1 : case ROLESPEC_CURRENT_USER:
18622 1 : ereport(ERROR,
18623 : (errcode(ERRCODE_RESERVED_NAME),
18624 : errmsg("%s cannot be used as a role name here",
18625 : "CURRENT_USER"),
18626 : parser_errposition(@1)));
18627 : break;
18628 1 : case ROLESPEC_CURRENT_ROLE:
18629 1 : ereport(ERROR,
18630 : (errcode(ERRCODE_RESERVED_NAME),
18631 : errmsg("%s cannot be used as a role name here",
18632 : "CURRENT_ROLE"),
18633 : parser_errposition(@1)));
18634 : break;
18635 : }
18636 : }
18637 : ;
18638 :
18639 : RoleSpec: NonReservedWord
18640 : {
18641 : /*
18642 : * "public" and "none" are not keywords, but they must
18643 : * be treated specially here.
18644 : */
18645 : RoleSpec *n;
18646 :
18647 15830 : if (strcmp($1, "public") == 0)
18648 : {
18649 7062 : n = (RoleSpec *) makeRoleSpec(ROLESPEC_PUBLIC, @1);
18650 7062 : n->roletype = ROLESPEC_PUBLIC;
18651 : }
18652 8768 : else if (strcmp($1, "none") == 0)
18653 : {
18654 13 : ereport(ERROR,
18655 : (errcode(ERRCODE_RESERVED_NAME),
18656 : errmsg("role name \"%s\" is reserved",
18657 : "none"),
18658 : parser_errposition(@1)));
18659 : }
18660 : else
18661 : {
18662 8755 : n = makeRoleSpec(ROLESPEC_CSTRING, @1);
18663 8755 : n->rolename = pstrdup($1);
18664 : }
18665 15817 : $$ = n;
18666 : }
18667 : | CURRENT_ROLE
18668 : {
18669 84 : $$ = makeRoleSpec(ROLESPEC_CURRENT_ROLE, @1);
18670 : }
18671 : | CURRENT_USER
18672 : {
18673 145 : $$ = makeRoleSpec(ROLESPEC_CURRENT_USER, @1);
18674 : }
18675 : | SESSION_USER
18676 : {
18677 18 : $$ = makeRoleSpec(ROLESPEC_SESSION_USER, @1);
18678 : }
18679 : ;
18680 :
18681 : role_list: RoleSpec
18682 2173 : { $$ = list_make1($1); }
18683 : | role_list ',' RoleSpec
18684 193 : { $$ = lappend($1, $3); }
18685 : ;
18686 :
18687 :
18688 : /*****************************************************************************
18689 : *
18690 : * PL/pgSQL extensions
18691 : *
18692 : * You'd think a PL/pgSQL "expression" should be just an a_expr, but
18693 : * historically it can include just about anything that can follow SELECT.
18694 : * Therefore the returned struct is a SelectStmt.
18695 : *****************************************************************************/
18696 :
18697 : PLpgSQL_Expr: opt_distinct_clause opt_target_list
18698 : from_clause where_clause
18699 : group_clause having_clause window_clause
18700 : opt_sort_clause opt_select_limit opt_for_locking_clause
18701 : {
18702 25657 : SelectStmt *n = makeNode(SelectStmt);
18703 :
18704 25657 : n->distinctClause = $1;
18705 25657 : n->targetList = $2;
18706 25657 : n->fromClause = $3;
18707 25657 : n->whereClause = $4;
18708 25657 : n->groupClause = ($5)->list;
18709 25657 : n->groupDistinct = ($5)->distinct;
18710 25657 : n->groupByAll = ($5)->all;
18711 25657 : n->havingClause = $6;
18712 25657 : n->windowClause = $7;
18713 25657 : n->sortClause = $8;
18714 25657 : if ($9)
18715 : {
18716 2 : n->limitOffset = $9->limitOffset;
18717 2 : n->limitCount = $9->limitCount;
18718 2 : if (!n->sortClause &&
18719 2 : $9->limitOption == LIMIT_OPTION_WITH_TIES)
18720 0 : ereport(ERROR,
18721 : (errcode(ERRCODE_SYNTAX_ERROR),
18722 : errmsg("WITH TIES cannot be specified without ORDER BY clause"),
18723 : parser_errposition($9->optionLoc)));
18724 2 : n->limitOption = $9->limitOption;
18725 : }
18726 25657 : n->lockingClause = $10;
18727 25657 : $$ = (Node *) n;
18728 : }
18729 : ;
18730 :
18731 : /*
18732 : * PL/pgSQL Assignment statement: name opt_indirection := PLpgSQL_Expr
18733 : */
18734 :
18735 : PLAssignStmt: plassign_target opt_indirection plassign_equals PLpgSQL_Expr
18736 : {
18737 4238 : PLAssignStmt *n = makeNode(PLAssignStmt);
18738 :
18739 4238 : n->name = $1;
18740 4238 : n->indirection = check_indirection($2, yyscanner);
18741 : /* nnames will be filled by calling production */
18742 4238 : n->val = (SelectStmt *) $4;
18743 4238 : n->location = @1;
18744 4238 : $$ = (Node *) n;
18745 : }
18746 : ;
18747 :
18748 4222 : plassign_target: ColId { $$ = $1; }
18749 16 : | PARAM { $$ = psprintf("$%d", $1); }
18750 : ;
18751 :
18752 : plassign_equals: COLON_EQUALS
18753 : | '='
18754 : ;
18755 :
18756 :
18757 : /*
18758 : * Name classification hierarchy.
18759 : *
18760 : * IDENT is the lexeme returned by the lexer for identifiers that match
18761 : * no known keyword. In most cases, we can accept certain keywords as
18762 : * names, not only IDENTs. We prefer to accept as many such keywords
18763 : * as possible to minimize the impact of "reserved words" on programmers.
18764 : * So, we divide names into several possible classes. The classification
18765 : * is chosen in part to make keywords acceptable as names wherever possible.
18766 : */
18767 :
18768 : /* Column identifier --- names that can be column, table, etc names.
18769 : */
18770 2235293 : ColId: IDENT { $$ = $1; }
18771 33454 : | unreserved_keyword { $$ = pstrdup($1); }
18772 3781 : | col_name_keyword { $$ = pstrdup($1); }
18773 : ;
18774 :
18775 : /* Type/function identifier --- names that can be type or function names.
18776 : */
18777 429146 : type_function_name: IDENT { $$ = $1; }
18778 39523 : | unreserved_keyword { $$ = pstrdup($1); }
18779 44 : | type_func_name_keyword { $$ = pstrdup($1); }
18780 : ;
18781 :
18782 : /* Any not-fully-reserved word --- these names can be, eg, role names.
18783 : */
18784 47939 : NonReservedWord: IDENT { $$ = $1; }
18785 20284 : | unreserved_keyword { $$ = pstrdup($1); }
18786 259 : | col_name_keyword { $$ = pstrdup($1); }
18787 3780 : | type_func_name_keyword { $$ = pstrdup($1); }
18788 : ;
18789 :
18790 : /* Column label --- allowed labels in "AS" clauses.
18791 : * This presently includes *all* Postgres keywords.
18792 : */
18793 1184567 : ColLabel: IDENT { $$ = $1; }
18794 26007 : | unreserved_keyword { $$ = pstrdup($1); }
18795 190 : | col_name_keyword { $$ = pstrdup($1); }
18796 938 : | type_func_name_keyword { $$ = pstrdup($1); }
18797 5552 : | reserved_keyword { $$ = pstrdup($1); }
18798 : ;
18799 :
18800 : /* Bare column label --- names that can be column labels without writing "AS".
18801 : * This classification is orthogonal to the other keyword categories.
18802 : */
18803 2318 : BareColLabel: IDENT { $$ = $1; }
18804 8 : | bare_label_keyword { $$ = pstrdup($1); }
18805 : ;
18806 :
18807 :
18808 : /*
18809 : * Keyword category lists. Generally, every keyword present in
18810 : * the Postgres grammar should appear in exactly one of these lists.
18811 : *
18812 : * Put a new keyword into the first list that it can go into without causing
18813 : * shift or reduce conflicts. The earlier lists define "less reserved"
18814 : * categories of keywords.
18815 : *
18816 : * Make sure that each keyword's category in kwlist.h matches where
18817 : * it is listed here. (Someday we may be able to generate these lists and
18818 : * kwlist.h's table from one source of truth.)
18819 : */
18820 :
18821 : /* "Unreserved" keywords --- available for use as any kind of name.
18822 : */
18823 : unreserved_keyword:
18824 : ABORT_P
18825 : | ABSENT
18826 : | ABSOLUTE_P
18827 : | ACCESS
18828 : | ACTION
18829 : | ADD_P
18830 : | ADMIN
18831 : | AFTER
18832 : | AGGREGATE
18833 : | ALSO
18834 : | ALTER
18835 : | ALWAYS
18836 : | ASENSITIVE
18837 : | ASSERTION
18838 : | ASSIGNMENT
18839 : | AT
18840 : | ATOMIC
18841 : | ATTACH
18842 : | ATTRIBUTE
18843 : | BACKWARD
18844 : | BEFORE
18845 : | BEGIN_P
18846 : | BREADTH
18847 : | BY
18848 : | CACHE
18849 : | CALL
18850 : | CALLED
18851 : | CASCADE
18852 : | CASCADED
18853 : | CATALOG_P
18854 : | CHAIN
18855 : | CHARACTERISTICS
18856 : | CHECKPOINT
18857 : | CLASS
18858 : | CLOSE
18859 : | CLUSTER
18860 : | COLUMNS
18861 : | COMMENT
18862 : | COMMENTS
18863 : | COMMIT
18864 : | COMMITTED
18865 : | COMPRESSION
18866 : | CONDITIONAL
18867 : | CONFIGURATION
18868 : | CONFLICT
18869 : | CONNECTION
18870 : | CONSTRAINTS
18871 : | CONTENT_P
18872 : | CONTINUE_P
18873 : | CONVERSION_P
18874 : | COPY
18875 : | COST
18876 : | CSV
18877 : | CUBE
18878 : | CURRENT_P
18879 : | CURSOR
18880 : | CYCLE
18881 : | DATA_P
18882 : | DATABASE
18883 : | DAY_P
18884 : | DEALLOCATE
18885 : | DECLARE
18886 : | DEFAULTS
18887 : | DEFERRED
18888 : | DEFINER
18889 : | DELETE_P
18890 : | DELIMITER
18891 : | DELIMITERS
18892 : | DEPENDS
18893 : | DEPTH
18894 : | DESTINATION
18895 : | DETACH
18896 : | DICTIONARY
18897 : | DISABLE_P
18898 : | DISCARD
18899 : | DOCUMENT_P
18900 : | DOMAIN_P
18901 : | DOUBLE_P
18902 : | DROP
18903 : | EACH
18904 : | EDGE
18905 : | EMPTY_P
18906 : | ENABLE_P
18907 : | ENCODING
18908 : | ENCRYPTED
18909 : | ENFORCED
18910 : | ENUM_P
18911 : | ERROR_P
18912 : | ESCAPE
18913 : | EVENT
18914 : | EXCLUDE
18915 : | EXCLUDING
18916 : | EXCLUSIVE
18917 : | EXECUTE
18918 : | EXPLAIN
18919 : | EXPRESSION
18920 : | EXTENSION
18921 : | EXTERNAL
18922 : | FAMILY
18923 : | FILTER
18924 : | FINALIZE
18925 : | FIRST_P
18926 : | FOLLOWING
18927 : | FORCE
18928 : | FORMAT
18929 : | FORWARD
18930 : | FUNCTION
18931 : | FUNCTIONS
18932 : | GENERATED
18933 : | GLOBAL
18934 : | GRANTED
18935 : | GRAPH
18936 : | GROUPS
18937 : | HANDLER
18938 : | HEADER_P
18939 : | HOLD
18940 : | HOUR_P
18941 : | IDENTITY_P
18942 : | IF_P
18943 : | IGNORE_P
18944 : | IMMEDIATE
18945 : | IMMUTABLE
18946 : | IMPLICIT_P
18947 : | IMPORT_P
18948 : | INCLUDE
18949 : | INCLUDING
18950 : | INCREMENT
18951 : | INDENT
18952 : | INDEX
18953 : | INDEXES
18954 : | INHERIT
18955 : | INHERITS
18956 : | INLINE_P
18957 : | INPUT_P
18958 : | INSENSITIVE
18959 : | INSERT
18960 : | INSTEAD
18961 : | INVOKER
18962 : | ISOLATION
18963 : | KEEP
18964 : | KEY
18965 : | KEYS
18966 : | LABEL
18967 : | LANGUAGE
18968 : | LARGE_P
18969 : | LAST_P
18970 : | LEAKPROOF
18971 : | LEVEL
18972 : | LISTEN
18973 : | LOAD
18974 : | LOCAL
18975 : | LOCATION
18976 : | LOCK_P
18977 : | LOCKED
18978 : | LOGGED
18979 : | LSN_P
18980 : | MAPPING
18981 : | MATCH
18982 : | MATCHED
18983 : | MATERIALIZED
18984 : | MAXVALUE
18985 : | MERGE
18986 : | METHOD
18987 : | MINUTE_P
18988 : | MINVALUE
18989 : | MODE
18990 : | MONTH_P
18991 : | MOVE
18992 : | NAME_P
18993 : | NAMES
18994 : | NESTED
18995 : | NEW
18996 : | NEXT
18997 : | NFC
18998 : | NFD
18999 : | NFKC
19000 : | NFKD
19001 : | NO
19002 : | NODE
19003 : | NORMALIZED
19004 : | NOTHING
19005 : | NOTIFY
19006 : | NOWAIT
19007 : | NULLS_P
19008 : | OBJECT_P
19009 : | OBJECTS_P
19010 : | OF
19011 : | OFF
19012 : | OIDS
19013 : | OLD
19014 : | OMIT
19015 : | OPERATOR
19016 : | OPTION
19017 : | OPTIONS
19018 : | ORDINALITY
19019 : | OTHERS
19020 : | OVER
19021 : | OVERRIDING
19022 : | OWNED
19023 : | OWNER
19024 : | PARALLEL
19025 : | PARAMETER
19026 : | PARSER
19027 : | PARTIAL
19028 : | PARTITION
19029 : | PARTITIONS
19030 : | PASSING
19031 : | PASSWORD
19032 : | PATH
19033 : | PERIOD
19034 : | PLAN
19035 : | PLANS
19036 : | POLICY
19037 : | PORTION
19038 : | PRECEDING
19039 : | PREPARE
19040 : | PREPARED
19041 : | PRESERVE
19042 : | PRIOR
19043 : | PRIVILEGES
19044 : | PROCEDURAL
19045 : | PROCEDURE
19046 : | PROCEDURES
19047 : | PROGRAM
19048 : | PROPERTIES
19049 : | PROPERTY
19050 : | PUBLICATION
19051 : | QUOTE
19052 : | QUOTES
19053 : | RANGE
19054 : | READ
19055 : | REASSIGN
19056 : | RECURSIVE
19057 : | REF_P
19058 : | REFERENCING
19059 : | REFRESH
19060 : | REINDEX
19061 : | RELATIONSHIP
19062 : | RELATIVE_P
19063 : | RELEASE
19064 : | RENAME
19065 : | REPACK
19066 : | REPEATABLE
19067 : | REPLACE
19068 : | REPLICA
19069 : | RESET
19070 : | RESPECT_P
19071 : | RESTART
19072 : | RESTRICT
19073 : | RETURN
19074 : | RETURNS
19075 : | REVOKE
19076 : | ROLE
19077 : | ROLLBACK
19078 : | ROLLUP
19079 : | ROUTINE
19080 : | ROUTINES
19081 : | ROWS
19082 : | RULE
19083 : | SAVEPOINT
19084 : | SCALAR
19085 : | SCHEMA
19086 : | SCHEMAS
19087 : | SCROLL
19088 : | SEARCH
19089 : | SECOND_P
19090 : | SECURITY
19091 : | SEQUENCE
19092 : | SEQUENCES
19093 : | SERIALIZABLE
19094 : | SERVER
19095 : | SESSION
19096 : | SET
19097 : | SETS
19098 : | SHARE
19099 : | SHOW
19100 : | SIMPLE
19101 : | SKIP
19102 : | SNAPSHOT
19103 : | SOURCE
19104 : | SPLIT
19105 : | SQL_P
19106 : | STABLE
19107 : | STANDALONE_P
19108 : | START
19109 : | STATEMENT
19110 : | STATISTICS
19111 : | STDIN
19112 : | STDOUT
19113 : | STORAGE
19114 : | STORED
19115 : | STRICT_P
19116 : | STRING_P
19117 : | STRIP_P
19118 : | SUBSCRIPTION
19119 : | SUPPORT
19120 : | SYSID
19121 : | SYSTEM_P
19122 : | TABLES
19123 : | TABLESPACE
19124 : | TARGET
19125 : | TEMP
19126 : | TEMPLATE
19127 : | TEMPORARY
19128 : | TEXT_P
19129 : | TIES
19130 : | TRANSACTION
19131 : | TRANSFORM
19132 : | TRIGGER
19133 : | TRUNCATE
19134 : | TRUSTED
19135 : | TYPE_P
19136 : | TYPES_P
19137 : | UESCAPE
19138 : | UNBOUNDED
19139 : | UNCOMMITTED
19140 : | UNCONDITIONAL
19141 : | UNENCRYPTED
19142 : | UNKNOWN
19143 : | UNLISTEN
19144 : | UNLOGGED
19145 : | UNTIL
19146 : | UPDATE
19147 : | VACUUM
19148 : | VALID
19149 : | VALIDATE
19150 : | VALIDATOR
19151 : | VALUE_P
19152 : | VARYING
19153 : | VERSION_P
19154 : | VERTEX
19155 : | VIEW
19156 : | VIEWS
19157 : | VIRTUAL
19158 : | VOLATILE
19159 : | WAIT
19160 : | WHITESPACE_P
19161 : | WITHIN
19162 : | WITHOUT
19163 : | WORK
19164 : | WRAPPER
19165 : | WRITE
19166 : | XML_P
19167 : | YEAR_P
19168 : | YES_P
19169 : | ZONE
19170 : ;
19171 :
19172 : /* Column identifier --- keywords that can be column, table, etc names.
19173 : *
19174 : * Many of these keywords will in fact be recognized as type or function
19175 : * names too; but they have special productions for the purpose, and so
19176 : * can't be treated as "generic" type or function names.
19177 : *
19178 : * The type names appearing here are not usable as function names
19179 : * because they can be followed by '(' in typename productions, which
19180 : * looks too much like a function call for an LR(1) parser.
19181 : */
19182 : col_name_keyword:
19183 : BETWEEN
19184 : | BIGINT
19185 : | BIT
19186 : | BOOLEAN_P
19187 : | CHAR_P
19188 : | CHARACTER
19189 : | COALESCE
19190 : | DEC
19191 : | DECIMAL_P
19192 : | EXISTS
19193 : | EXTRACT
19194 : | FLOAT_P
19195 : | GRAPH_TABLE
19196 : | GREATEST
19197 : | GROUPING
19198 : | INOUT
19199 : | INT_P
19200 : | INTEGER
19201 : | INTERVAL
19202 : | JSON
19203 : | JSON_ARRAY
19204 : | JSON_ARRAYAGG
19205 : | JSON_EXISTS
19206 : | JSON_OBJECT
19207 : | JSON_OBJECTAGG
19208 : | JSON_QUERY
19209 : | JSON_SCALAR
19210 : | JSON_SERIALIZE
19211 : | JSON_TABLE
19212 : | JSON_VALUE
19213 : | LEAST
19214 : | MERGE_ACTION
19215 : | NATIONAL
19216 : | NCHAR
19217 : | NONE
19218 : | NORMALIZE
19219 : | NULLIF
19220 : | NUMERIC
19221 : | OUT_P
19222 : | OVERLAY
19223 : | POSITION
19224 : | PRECISION
19225 : | REAL
19226 : | ROW
19227 : | SETOF
19228 : | SMALLINT
19229 : | SUBSTRING
19230 : | TIME
19231 : | TIMESTAMP
19232 : | TREAT
19233 : | TRIM
19234 : | VALUES
19235 : | VARCHAR
19236 : | XMLATTRIBUTES
19237 : | XMLCONCAT
19238 : | XMLELEMENT
19239 : | XMLEXISTS
19240 : | XMLFOREST
19241 : | XMLNAMESPACES
19242 : | XMLPARSE
19243 : | XMLPI
19244 : | XMLROOT
19245 : | XMLSERIALIZE
19246 : | XMLTABLE
19247 : ;
19248 :
19249 : /* Type/function identifier --- keywords that can be type or function names.
19250 : *
19251 : * Most of these are keywords that are used as operators in expressions;
19252 : * in general such keywords can't be column names because they would be
19253 : * ambiguous with variables, but they are unambiguous as function identifiers.
19254 : *
19255 : * Do not include POSITION, SUBSTRING, etc here since they have explicit
19256 : * productions in a_expr to support the goofy SQL9x argument syntax.
19257 : * - thomas 2000-11-28
19258 : */
19259 : type_func_name_keyword:
19260 : AUTHORIZATION
19261 : | BINARY
19262 : | COLLATION
19263 : | CONCURRENTLY
19264 : | CROSS
19265 : | CURRENT_SCHEMA
19266 : | FREEZE
19267 : | FULL
19268 : | ILIKE
19269 : | INNER_P
19270 : | IS
19271 : | ISNULL
19272 : | JOIN
19273 : | LEFT
19274 : | LIKE
19275 : | NATURAL
19276 : | NOTNULL
19277 : | OUTER_P
19278 : | OVERLAPS
19279 : | RIGHT
19280 : | SIMILAR
19281 : | TABLESAMPLE
19282 : | VERBOSE
19283 : ;
19284 :
19285 : /* Reserved keyword --- these keywords are usable only as a ColLabel.
19286 : *
19287 : * Keywords appear here if they could not be distinguished from variable,
19288 : * type, or function names in some contexts. Don't put things here unless
19289 : * forced to.
19290 : */
19291 : reserved_keyword:
19292 : ALL
19293 : | ANALYSE
19294 : | ANALYZE
19295 : | AND
19296 : | ANY
19297 : | ARRAY
19298 : | AS
19299 : | ASC
19300 : | ASYMMETRIC
19301 : | BOTH
19302 : | CASE
19303 : | CAST
19304 : | CHECK
19305 : | COLLATE
19306 : | COLUMN
19307 : | CONSTRAINT
19308 : | CREATE
19309 : | CURRENT_CATALOG
19310 : | CURRENT_DATE
19311 : | CURRENT_ROLE
19312 : | CURRENT_TIME
19313 : | CURRENT_TIMESTAMP
19314 : | CURRENT_USER
19315 : | DEFAULT
19316 : | DEFERRABLE
19317 : | DESC
19318 : | DISTINCT
19319 : | DO
19320 : | ELSE
19321 : | END_P
19322 : | EXCEPT
19323 : | FALSE_P
19324 : | FETCH
19325 : | FOR
19326 : | FOREIGN
19327 : | FROM
19328 : | GRANT
19329 : | GROUP_P
19330 : | HAVING
19331 : | IN_P
19332 : | INITIALLY
19333 : | INTERSECT
19334 : | INTO
19335 : | LATERAL_P
19336 : | LEADING
19337 : | LIMIT
19338 : | LOCALTIME
19339 : | LOCALTIMESTAMP
19340 : | NOT
19341 : | NULL_P
19342 : | OFFSET
19343 : | ON
19344 : | ONLY
19345 : | OR
19346 : | ORDER
19347 : | PLACING
19348 : | PRIMARY
19349 : | REFERENCES
19350 : | RETURNING
19351 : | SELECT
19352 : | SESSION_USER
19353 : | SOME
19354 : | SYMMETRIC
19355 : | SYSTEM_USER
19356 : | TABLE
19357 : | THEN
19358 : | TO
19359 : | TRAILING
19360 : | TRUE_P
19361 : | UNION
19362 : | UNIQUE
19363 : | USER
19364 : | USING
19365 : | VARIADIC
19366 : | WHEN
19367 : | WHERE
19368 : | WINDOW
19369 : | WITH
19370 : ;
19371 :
19372 : /*
19373 : * While all keywords can be used as column labels when preceded by AS,
19374 : * not all of them can be used as a "bare" column label without AS.
19375 : * Those that can be used as a bare label must be listed here,
19376 : * in addition to appearing in one of the category lists above.
19377 : *
19378 : * Always add a new keyword to this list if possible. Mark it BARE_LABEL
19379 : * in kwlist.h if it is included here, or AS_LABEL if it is not.
19380 : */
19381 : bare_label_keyword:
19382 : ABORT_P
19383 : | ABSENT
19384 : | ABSOLUTE_P
19385 : | ACCESS
19386 : | ACTION
19387 : | ADD_P
19388 : | ADMIN
19389 : | AFTER
19390 : | AGGREGATE
19391 : | ALL
19392 : | ALSO
19393 : | ALTER
19394 : | ALWAYS
19395 : | ANALYSE
19396 : | ANALYZE
19397 : | AND
19398 : | ANY
19399 : | ASC
19400 : | ASENSITIVE
19401 : | ASSERTION
19402 : | ASSIGNMENT
19403 : | ASYMMETRIC
19404 : | AT
19405 : | ATOMIC
19406 : | ATTACH
19407 : | ATTRIBUTE
19408 : | AUTHORIZATION
19409 : | BACKWARD
19410 : | BEFORE
19411 : | BEGIN_P
19412 : | BETWEEN
19413 : | BIGINT
19414 : | BINARY
19415 : | BIT
19416 : | BOOLEAN_P
19417 : | BOTH
19418 : | BREADTH
19419 : | BY
19420 : | CACHE
19421 : | CALL
19422 : | CALLED
19423 : | CASCADE
19424 : | CASCADED
19425 : | CASE
19426 : | CAST
19427 : | CATALOG_P
19428 : | CHAIN
19429 : | CHARACTERISTICS
19430 : | CHECK
19431 : | CHECKPOINT
19432 : | CLASS
19433 : | CLOSE
19434 : | CLUSTER
19435 : | COALESCE
19436 : | COLLATE
19437 : | COLLATION
19438 : | COLUMN
19439 : | COLUMNS
19440 : | COMMENT
19441 : | COMMENTS
19442 : | COMMIT
19443 : | COMMITTED
19444 : | COMPRESSION
19445 : | CONCURRENTLY
19446 : | CONDITIONAL
19447 : | CONFIGURATION
19448 : | CONFLICT
19449 : | CONNECTION
19450 : | CONSTRAINT
19451 : | CONSTRAINTS
19452 : | CONTENT_P
19453 : | CONTINUE_P
19454 : | CONVERSION_P
19455 : | COPY
19456 : | COST
19457 : | CROSS
19458 : | CSV
19459 : | CUBE
19460 : | CURRENT_P
19461 : | CURRENT_CATALOG
19462 : | CURRENT_DATE
19463 : | CURRENT_ROLE
19464 : | CURRENT_SCHEMA
19465 : | CURRENT_TIME
19466 : | CURRENT_TIMESTAMP
19467 : | CURRENT_USER
19468 : | CURSOR
19469 : | CYCLE
19470 : | DATA_P
19471 : | DATABASE
19472 : | DEALLOCATE
19473 : | DEC
19474 : | DECIMAL_P
19475 : | DECLARE
19476 : | DEFAULT
19477 : | DEFAULTS
19478 : | DEFERRABLE
19479 : | DEFERRED
19480 : | DEFINER
19481 : | DELETE_P
19482 : | DELIMITER
19483 : | DELIMITERS
19484 : | DEPENDS
19485 : | DEPTH
19486 : | DESC
19487 : | DESTINATION
19488 : | DETACH
19489 : | DICTIONARY
19490 : | DISABLE_P
19491 : | DISCARD
19492 : | DISTINCT
19493 : | DO
19494 : | DOCUMENT_P
19495 : | DOMAIN_P
19496 : | DOUBLE_P
19497 : | DROP
19498 : | EACH
19499 : | EDGE
19500 : | ELSE
19501 : | EMPTY_P
19502 : | ENABLE_P
19503 : | ENCODING
19504 : | ENCRYPTED
19505 : | END_P
19506 : | ENFORCED
19507 : | ENUM_P
19508 : | ERROR_P
19509 : | ESCAPE
19510 : | EVENT
19511 : | EXCLUDE
19512 : | EXCLUDING
19513 : | EXCLUSIVE
19514 : | EXECUTE
19515 : | EXISTS
19516 : | EXPLAIN
19517 : | EXPRESSION
19518 : | EXTENSION
19519 : | EXTERNAL
19520 : | EXTRACT
19521 : | FALSE_P
19522 : | FAMILY
19523 : | FINALIZE
19524 : | FIRST_P
19525 : | FLOAT_P
19526 : | FOLLOWING
19527 : | FORCE
19528 : | FOREIGN
19529 : | FORMAT
19530 : | FORWARD
19531 : | FREEZE
19532 : | FULL
19533 : | FUNCTION
19534 : | FUNCTIONS
19535 : | GENERATED
19536 : | GLOBAL
19537 : | GRANTED
19538 : | GRAPH
19539 : | GRAPH_TABLE
19540 : | GREATEST
19541 : | GROUPING
19542 : | GROUPS
19543 : | HANDLER
19544 : | HEADER_P
19545 : | HOLD
19546 : | IDENTITY_P
19547 : | IF_P
19548 : | ILIKE
19549 : | IMMEDIATE
19550 : | IMMUTABLE
19551 : | IMPLICIT_P
19552 : | IMPORT_P
19553 : | IN_P
19554 : | INCLUDE
19555 : | INCLUDING
19556 : | INCREMENT
19557 : | INDENT
19558 : | INDEX
19559 : | INDEXES
19560 : | INHERIT
19561 : | INHERITS
19562 : | INITIALLY
19563 : | INLINE_P
19564 : | INNER_P
19565 : | INOUT
19566 : | INPUT_P
19567 : | INSENSITIVE
19568 : | INSERT
19569 : | INSTEAD
19570 : | INT_P
19571 : | INTEGER
19572 : | INTERVAL
19573 : | INVOKER
19574 : | IS
19575 : | ISOLATION
19576 : | JOIN
19577 : | JSON
19578 : | JSON_ARRAY
19579 : | JSON_ARRAYAGG
19580 : | JSON_EXISTS
19581 : | JSON_OBJECT
19582 : | JSON_OBJECTAGG
19583 : | JSON_QUERY
19584 : | JSON_SCALAR
19585 : | JSON_SERIALIZE
19586 : | JSON_TABLE
19587 : | JSON_VALUE
19588 : | KEEP
19589 : | KEY
19590 : | KEYS
19591 : | LABEL
19592 : | LANGUAGE
19593 : | LARGE_P
19594 : | LAST_P
19595 : | LATERAL_P
19596 : | LEADING
19597 : | LEAKPROOF
19598 : | LEAST
19599 : | LEFT
19600 : | LEVEL
19601 : | LIKE
19602 : | LISTEN
19603 : | LOAD
19604 : | LOCAL
19605 : | LOCALTIME
19606 : | LOCALTIMESTAMP
19607 : | LOCATION
19608 : | LOCK_P
19609 : | LOCKED
19610 : | LOGGED
19611 : | LSN_P
19612 : | MAPPING
19613 : | MATCH
19614 : | MATCHED
19615 : | MATERIALIZED
19616 : | MAXVALUE
19617 : | MERGE
19618 : | MERGE_ACTION
19619 : | METHOD
19620 : | MINVALUE
19621 : | MODE
19622 : | MOVE
19623 : | NAME_P
19624 : | NAMES
19625 : | NATIONAL
19626 : | NATURAL
19627 : | NCHAR
19628 : | NESTED
19629 : | NEW
19630 : | NEXT
19631 : | NFC
19632 : | NFD
19633 : | NFKC
19634 : | NFKD
19635 : | NO
19636 : | NODE
19637 : | NONE
19638 : | NORMALIZE
19639 : | NORMALIZED
19640 : | NOT
19641 : | NOTHING
19642 : | NOTIFY
19643 : | NOWAIT
19644 : | NULL_P
19645 : | NULLIF
19646 : | NULLS_P
19647 : | NUMERIC
19648 : | OBJECT_P
19649 : | OBJECTS_P
19650 : | OF
19651 : | OFF
19652 : | OIDS
19653 : | OLD
19654 : | OMIT
19655 : | ONLY
19656 : | OPERATOR
19657 : | OPTION
19658 : | OPTIONS
19659 : | OR
19660 : | ORDINALITY
19661 : | OTHERS
19662 : | OUT_P
19663 : | OUTER_P
19664 : | OVERLAY
19665 : | OVERRIDING
19666 : | OWNED
19667 : | OWNER
19668 : | PARALLEL
19669 : | PARAMETER
19670 : | PARSER
19671 : | PARTIAL
19672 : | PARTITION
19673 : | PARTITIONS
19674 : | PASSING
19675 : | PASSWORD
19676 : | PATH
19677 : | PERIOD
19678 : | PLACING
19679 : | PLAN
19680 : | PLANS
19681 : | POLICY
19682 : | PORTION
19683 : | POSITION
19684 : | PRECEDING
19685 : | PREPARE
19686 : | PREPARED
19687 : | PRESERVE
19688 : | PRIMARY
19689 : | PRIOR
19690 : | PRIVILEGES
19691 : | PROCEDURAL
19692 : | PROCEDURE
19693 : | PROCEDURES
19694 : | PROGRAM
19695 : | PROPERTIES
19696 : | PROPERTY
19697 : | PUBLICATION
19698 : | QUOTE
19699 : | QUOTES
19700 : | RANGE
19701 : | READ
19702 : | REAL
19703 : | REASSIGN
19704 : | RECURSIVE
19705 : | REF_P
19706 : | REFERENCES
19707 : | REFERENCING
19708 : | REFRESH
19709 : | REINDEX
19710 : | RELATIONSHIP
19711 : | RELATIVE_P
19712 : | RELEASE
19713 : | RENAME
19714 : | REPACK
19715 : | REPEATABLE
19716 : | REPLACE
19717 : | REPLICA
19718 : | RESET
19719 : | RESTART
19720 : | RESTRICT
19721 : | RETURN
19722 : | RETURNS
19723 : | REVOKE
19724 : | RIGHT
19725 : | ROLE
19726 : | ROLLBACK
19727 : | ROLLUP
19728 : | ROUTINE
19729 : | ROUTINES
19730 : | ROW
19731 : | ROWS
19732 : | RULE
19733 : | SAVEPOINT
19734 : | SCALAR
19735 : | SCHEMA
19736 : | SCHEMAS
19737 : | SCROLL
19738 : | SEARCH
19739 : | SECURITY
19740 : | SELECT
19741 : | SEQUENCE
19742 : | SEQUENCES
19743 : | SERIALIZABLE
19744 : | SERVER
19745 : | SESSION
19746 : | SESSION_USER
19747 : | SET
19748 : | SETOF
19749 : | SETS
19750 : | SHARE
19751 : | SHOW
19752 : | SIMILAR
19753 : | SIMPLE
19754 : | SKIP
19755 : | SMALLINT
19756 : | SNAPSHOT
19757 : | SOME
19758 : | SOURCE
19759 : | SPLIT
19760 : | SQL_P
19761 : | STABLE
19762 : | STANDALONE_P
19763 : | START
19764 : | STATEMENT
19765 : | STATISTICS
19766 : | STDIN
19767 : | STDOUT
19768 : | STORAGE
19769 : | STORED
19770 : | STRICT_P
19771 : | STRING_P
19772 : | STRIP_P
19773 : | SUBSCRIPTION
19774 : | SUBSTRING
19775 : | SUPPORT
19776 : | SYMMETRIC
19777 : | SYSID
19778 : | SYSTEM_P
19779 : | SYSTEM_USER
19780 : | TABLE
19781 : | TABLES
19782 : | TABLESAMPLE
19783 : | TABLESPACE
19784 : | TARGET
19785 : | TEMP
19786 : | TEMPLATE
19787 : | TEMPORARY
19788 : | TEXT_P
19789 : | THEN
19790 : | TIES
19791 : | TIME
19792 : | TIMESTAMP
19793 : | TRAILING
19794 : | TRANSACTION
19795 : | TRANSFORM
19796 : | TREAT
19797 : | TRIGGER
19798 : | TRIM
19799 : | TRUE_P
19800 : | TRUNCATE
19801 : | TRUSTED
19802 : | TYPE_P
19803 : | TYPES_P
19804 : | UESCAPE
19805 : | UNBOUNDED
19806 : | UNCOMMITTED
19807 : | UNCONDITIONAL
19808 : | UNENCRYPTED
19809 : | UNIQUE
19810 : | UNKNOWN
19811 : | UNLISTEN
19812 : | UNLOGGED
19813 : | UNTIL
19814 : | UPDATE
19815 : | USER
19816 : | USING
19817 : | VACUUM
19818 : | VALID
19819 : | VALIDATE
19820 : | VALIDATOR
19821 : | VALUE_P
19822 : | VALUES
19823 : | VARCHAR
19824 : | VARIADIC
19825 : | VERBOSE
19826 : | VERSION_P
19827 : | VERTEX
19828 : | VIEW
19829 : | VIEWS
19830 : | VIRTUAL
19831 : | VOLATILE
19832 : | WAIT
19833 : | WHEN
19834 : | WHITESPACE_P
19835 : | WORK
19836 : | WRAPPER
19837 : | WRITE
19838 : | XML_P
19839 : | XMLATTRIBUTES
19840 : | XMLCONCAT
19841 : | XMLELEMENT
19842 : | XMLEXISTS
19843 : | XMLFOREST
19844 : | XMLNAMESPACES
19845 : | XMLPARSE
19846 : | XMLPI
19847 : | XMLROOT
19848 : | XMLSERIALIZE
19849 : | XMLTABLE
19850 : | YES_P
19851 : | ZONE
19852 : ;
19853 :
19854 : %%
19855 :
19856 : /*
19857 : * The signature of this function is required by bison. However, we
19858 : * ignore the passed yylloc and instead use the last token position
19859 : * available from the scanner.
19860 : */
19861 : static void
19862 477 : base_yyerror(YYLTYPE *yylloc, core_yyscan_t yyscanner, const char *msg)
19863 : {
19864 477 : parser_yyerror(msg);
19865 : }
19866 :
19867 : static RawStmt *
19868 519990 : makeRawStmt(Node *stmt, int stmt_location)
19869 : {
19870 519990 : RawStmt *rs = makeNode(RawStmt);
19871 :
19872 519990 : rs->stmt = stmt;
19873 519990 : rs->stmt_location = stmt_location;
19874 519990 : rs->stmt_len = 0; /* might get changed later */
19875 519990 : return rs;
19876 : }
19877 :
19878 : /* Adjust a RawStmt to reflect that it doesn't run to the end of the string */
19879 : static void
19880 383870 : updateRawStmtEnd(RawStmt *rs, int end_location)
19881 : {
19882 : /*
19883 : * If we already set the length, don't change it. This is for situations
19884 : * like "select foo ;; select bar" where the same statement will be last
19885 : * in the string for more than one semicolon.
19886 : */
19887 383870 : if (rs->stmt_len > 0)
19888 301 : return;
19889 :
19890 : /* OK, update length of RawStmt */
19891 383569 : rs->stmt_len = end_location - rs->stmt_location;
19892 : }
19893 :
19894 : static Node *
19895 1210803 : makeColumnRef(char *colname, List *indirection,
19896 : int location, core_yyscan_t yyscanner)
19897 : {
19898 : /*
19899 : * Generate a ColumnRef node, with an A_Indirection node added if there is
19900 : * any subscripting in the specified indirection list. However, any field
19901 : * selection at the start of the indirection list must be transposed into
19902 : * the "fields" part of the ColumnRef node.
19903 : */
19904 1210803 : ColumnRef *c = makeNode(ColumnRef);
19905 1210803 : int nfields = 0;
19906 : ListCell *l;
19907 :
19908 1210803 : c->location = location;
19909 1924984 : foreach(l, indirection)
19910 : {
19911 720977 : if (IsA(lfirst(l), A_Indices))
19912 : {
19913 6796 : A_Indirection *i = makeNode(A_Indirection);
19914 :
19915 6796 : if (nfields == 0)
19916 : {
19917 : /* easy case - all indirection goes to A_Indirection */
19918 4944 : c->fields = list_make1(makeString(colname));
19919 4944 : i->indirection = check_indirection(indirection, yyscanner);
19920 : }
19921 : else
19922 : {
19923 : /* got to split the list in two */
19924 1852 : i->indirection = check_indirection(list_copy_tail(indirection,
19925 : nfields),
19926 : yyscanner);
19927 1852 : indirection = list_truncate(indirection, nfields);
19928 1852 : c->fields = lcons(makeString(colname), indirection);
19929 : }
19930 6796 : i->arg = (Node *) c;
19931 6796 : return (Node *) i;
19932 : }
19933 714181 : else if (IsA(lfirst(l), A_Star))
19934 : {
19935 : /* We only allow '*' at the end of a ColumnRef */
19936 3673 : if (lnext(indirection, l) != NULL)
19937 0 : parser_yyerror("improper use of \"*\"");
19938 : }
19939 714181 : nfields++;
19940 : }
19941 : /* No subscripting, so all indirection gets added to field list */
19942 1204007 : c->fields = lcons(makeString(colname), indirection);
19943 1204007 : return (Node *) c;
19944 : }
19945 :
19946 : static Node *
19947 199003 : makeTypeCast(Node *arg, TypeName *typename, int location)
19948 : {
19949 199003 : TypeCast *n = makeNode(TypeCast);
19950 :
19951 199003 : n->arg = arg;
19952 199003 : n->typeName = typename;
19953 199003 : n->location = location;
19954 199003 : return (Node *) n;
19955 : }
19956 :
19957 : static Node *
19958 10572 : makeStringConstCast(char *str, int location, TypeName *typename)
19959 : {
19960 10572 : Node *s = makeStringConst(str, location);
19961 :
19962 10572 : return makeTypeCast(s, typename, -1);
19963 : }
19964 :
19965 : static Node *
19966 263912 : makeIntConst(int val, int location)
19967 : {
19968 263912 : A_Const *n = makeNode(A_Const);
19969 :
19970 263912 : n->val.ival.type = T_Integer;
19971 263912 : n->val.ival.ival = val;
19972 263912 : n->location = location;
19973 :
19974 263912 : return (Node *) n;
19975 : }
19976 :
19977 : static Node *
19978 8007 : makeFloatConst(char *str, int location)
19979 : {
19980 8007 : A_Const *n = makeNode(A_Const);
19981 :
19982 8007 : n->val.fval.type = T_Float;
19983 8007 : n->val.fval.fval = str;
19984 8007 : n->location = location;
19985 :
19986 8007 : return (Node *) n;
19987 : }
19988 :
19989 : static Node *
19990 40230 : makeBoolAConst(bool state, int location)
19991 : {
19992 40230 : A_Const *n = makeNode(A_Const);
19993 :
19994 40230 : n->val.boolval.type = T_Boolean;
19995 40230 : n->val.boolval.boolval = state;
19996 40230 : n->location = location;
19997 :
19998 40230 : return (Node *) n;
19999 : }
20000 :
20001 : static Node *
20002 2719 : makeBitStringConst(char *str, int location)
20003 : {
20004 2719 : A_Const *n = makeNode(A_Const);
20005 :
20006 2719 : n->val.bsval.type = T_BitString;
20007 2719 : n->val.bsval.bsval = str;
20008 2719 : n->location = location;
20009 :
20010 2719 : return (Node *) n;
20011 : }
20012 :
20013 : static Node *
20014 43974 : makeNullAConst(int location)
20015 : {
20016 43974 : A_Const *n = makeNode(A_Const);
20017 :
20018 43974 : n->isnull = true;
20019 43974 : n->location = location;
20020 :
20021 43974 : return (Node *) n;
20022 : }
20023 :
20024 : static Node *
20025 3457 : makeAConst(Node *v, int location)
20026 : {
20027 : Node *n;
20028 :
20029 3457 : switch (v->type)
20030 : {
20031 142 : case T_Float:
20032 142 : n = makeFloatConst(castNode(Float, v)->fval, location);
20033 142 : break;
20034 :
20035 3315 : case T_Integer:
20036 3315 : n = makeIntConst(castNode(Integer, v)->ival, location);
20037 3315 : break;
20038 :
20039 0 : default:
20040 : /* currently not used */
20041 : Assert(false);
20042 0 : n = NULL;
20043 : }
20044 :
20045 3457 : return n;
20046 : }
20047 :
20048 : /* makeRoleSpec
20049 : * Create a RoleSpec with the given type
20050 : */
20051 : static RoleSpec *
20052 16543 : makeRoleSpec(RoleSpecType type, int location)
20053 : {
20054 16543 : RoleSpec *spec = makeNode(RoleSpec);
20055 :
20056 16543 : spec->roletype = type;
20057 16543 : spec->location = location;
20058 :
20059 16543 : return spec;
20060 : }
20061 :
20062 : /* check_qualified_name --- check the result of qualified_name production
20063 : *
20064 : * It's easiest to let the grammar production for qualified_name allow
20065 : * subscripts and '*', which we then must reject here.
20066 : */
20067 : static void
20068 157714 : check_qualified_name(List *names, core_yyscan_t yyscanner)
20069 : {
20070 : ListCell *i;
20071 :
20072 315428 : foreach(i, names)
20073 : {
20074 157714 : if (!IsA(lfirst(i), String))
20075 0 : parser_yyerror("syntax error");
20076 : }
20077 157714 : }
20078 :
20079 : /* check_func_name --- check the result of func_name production
20080 : *
20081 : * It's easiest to let the grammar production for func_name allow subscripts
20082 : * and '*', which we then must reject here.
20083 : */
20084 : static List *
20085 85828 : check_func_name(List *names, core_yyscan_t yyscanner)
20086 : {
20087 : ListCell *i;
20088 :
20089 257484 : foreach(i, names)
20090 : {
20091 171656 : if (!IsA(lfirst(i), String))
20092 0 : parser_yyerror("syntax error");
20093 : }
20094 85828 : return names;
20095 : }
20096 :
20097 : /* check_indirection --- check the result of indirection production
20098 : *
20099 : * We only allow '*' at the end of the list, but it's hard to enforce that
20100 : * in the grammar, so do it here.
20101 : */
20102 : static List *
20103 54019 : check_indirection(List *indirection, core_yyscan_t yyscanner)
20104 : {
20105 : ListCell *l;
20106 :
20107 73783 : foreach(l, indirection)
20108 : {
20109 19764 : if (IsA(lfirst(l), A_Star))
20110 : {
20111 948 : if (lnext(indirection, l) != NULL)
20112 0 : parser_yyerror("improper use of \"*\"");
20113 : }
20114 : }
20115 54019 : return indirection;
20116 : }
20117 :
20118 : /* extractArgTypes()
20119 : * Given a list of FunctionParameter nodes, extract a list of just the
20120 : * argument types (TypeNames) for input parameters only. This is what
20121 : * is needed to look up an existing function, which is what is wanted by
20122 : * the productions that use this call.
20123 : */
20124 : static List *
20125 5318 : extractArgTypes(List *parameters)
20126 : {
20127 5318 : List *result = NIL;
20128 : ListCell *i;
20129 :
20130 13376 : foreach(i, parameters)
20131 : {
20132 8058 : FunctionParameter *p = (FunctionParameter *) lfirst(i);
20133 :
20134 8058 : if (p->mode != FUNC_PARAM_OUT && p->mode != FUNC_PARAM_TABLE)
20135 7971 : result = lappend(result, p->argType);
20136 : }
20137 5318 : return result;
20138 : }
20139 :
20140 : /* extractAggrArgTypes()
20141 : * As above, but work from the output of the aggr_args production.
20142 : */
20143 : static List *
20144 220 : extractAggrArgTypes(List *aggrargs)
20145 : {
20146 : Assert(list_length(aggrargs) == 2);
20147 220 : return extractArgTypes((List *) linitial(aggrargs));
20148 : }
20149 :
20150 : /* makeOrderedSetArgs()
20151 : * Build the result of the aggr_args production (which see the comments for).
20152 : * This handles only the case where both given lists are nonempty, so that
20153 : * we have to deal with multiple VARIADIC arguments.
20154 : */
20155 : static List *
20156 20 : makeOrderedSetArgs(List *directargs, List *orderedargs,
20157 : core_yyscan_t yyscanner)
20158 : {
20159 20 : FunctionParameter *lastd = (FunctionParameter *) llast(directargs);
20160 : Integer *ndirectargs;
20161 :
20162 : /* No restriction unless last direct arg is VARIADIC */
20163 20 : if (lastd->mode == FUNC_PARAM_VARIADIC)
20164 : {
20165 10 : FunctionParameter *firsto = (FunctionParameter *) linitial(orderedargs);
20166 :
20167 : /*
20168 : * We ignore the names, though the aggr_arg production allows them; it
20169 : * doesn't allow default values, so those need not be checked.
20170 : */
20171 10 : if (list_length(orderedargs) != 1 ||
20172 10 : firsto->mode != FUNC_PARAM_VARIADIC ||
20173 10 : !equal(lastd->argType, firsto->argType))
20174 0 : ereport(ERROR,
20175 : (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
20176 : errmsg("an ordered-set aggregate with a VARIADIC direct argument must have one VARIADIC aggregated argument of the same data type"),
20177 : parser_errposition(firsto->location)));
20178 :
20179 : /* OK, drop the duplicate VARIADIC argument from the internal form */
20180 10 : orderedargs = NIL;
20181 : }
20182 :
20183 : /* don't merge into the next line, as list_concat changes directargs */
20184 20 : ndirectargs = makeInteger(list_length(directargs));
20185 :
20186 20 : return list_make2(list_concat(directargs, orderedargs),
20187 : ndirectargs);
20188 : }
20189 :
20190 : /* insertSelectOptions()
20191 : * Insert ORDER BY, etc into an already-constructed SelectStmt.
20192 : *
20193 : * This routine is just to avoid duplicating code in SelectStmt productions.
20194 : */
20195 : static void
20196 59721 : insertSelectOptions(SelectStmt *stmt,
20197 : List *sortClause, List *lockingClause,
20198 : SelectLimit *limitClause,
20199 : WithClause *withClause,
20200 : core_yyscan_t yyscanner)
20201 : {
20202 : Assert(IsA(stmt, SelectStmt));
20203 :
20204 : /*
20205 : * Tests here are to reject constructs like
20206 : * (SELECT foo ORDER BY bar) ORDER BY baz
20207 : */
20208 59721 : if (sortClause)
20209 : {
20210 51945 : if (stmt->sortClause)
20211 0 : ereport(ERROR,
20212 : (errcode(ERRCODE_SYNTAX_ERROR),
20213 : errmsg("multiple ORDER BY clauses not allowed"),
20214 : parser_errposition(exprLocation((Node *) sortClause))));
20215 51945 : stmt->sortClause = sortClause;
20216 : }
20217 : /* We can handle multiple locking clauses, though */
20218 59721 : stmt->lockingClause = list_concat(stmt->lockingClause, lockingClause);
20219 59721 : if (limitClause && limitClause->limitOffset)
20220 : {
20221 534 : if (stmt->limitOffset)
20222 0 : ereport(ERROR,
20223 : (errcode(ERRCODE_SYNTAX_ERROR),
20224 : errmsg("multiple OFFSET clauses not allowed"),
20225 : parser_errposition(limitClause->offsetLoc)));
20226 534 : stmt->limitOffset = limitClause->limitOffset;
20227 : }
20228 59721 : if (limitClause && limitClause->limitCount)
20229 : {
20230 2949 : if (stmt->limitCount)
20231 0 : ereport(ERROR,
20232 : (errcode(ERRCODE_SYNTAX_ERROR),
20233 : errmsg("multiple LIMIT clauses not allowed"),
20234 : parser_errposition(limitClause->countLoc)));
20235 2949 : stmt->limitCount = limitClause->limitCount;
20236 : }
20237 59721 : if (limitClause)
20238 : {
20239 : /* If there was a conflict, we must have detected it above */
20240 : Assert(!stmt->limitOption);
20241 3271 : if (!stmt->sortClause && limitClause->limitOption == LIMIT_OPTION_WITH_TIES)
20242 4 : ereport(ERROR,
20243 : (errcode(ERRCODE_SYNTAX_ERROR),
20244 : errmsg("WITH TIES cannot be specified without ORDER BY clause"),
20245 : parser_errposition(limitClause->optionLoc)));
20246 3267 : if (limitClause->limitOption == LIMIT_OPTION_WITH_TIES && stmt->lockingClause)
20247 : {
20248 : ListCell *lc;
20249 :
20250 4 : foreach(lc, stmt->lockingClause)
20251 : {
20252 4 : LockingClause *lock = lfirst_node(LockingClause, lc);
20253 :
20254 4 : if (lock->waitPolicy == LockWaitSkip)
20255 4 : ereport(ERROR,
20256 : (errcode(ERRCODE_SYNTAX_ERROR),
20257 : errmsg("%s and %s options cannot be used together",
20258 : "SKIP LOCKED", "WITH TIES"),
20259 : parser_errposition(limitClause->optionLoc)));
20260 : }
20261 : }
20262 3263 : stmt->limitOption = limitClause->limitOption;
20263 : }
20264 59713 : if (withClause)
20265 : {
20266 1924 : if (stmt->withClause)
20267 0 : ereport(ERROR,
20268 : (errcode(ERRCODE_SYNTAX_ERROR),
20269 : errmsg("multiple WITH clauses not allowed"),
20270 : parser_errposition(exprLocation((Node *) withClause))));
20271 1924 : stmt->withClause = withClause;
20272 : }
20273 59713 : }
20274 :
20275 : static Node *
20276 13174 : makeSetOp(SetOperation op, bool all, Node *larg, Node *rarg)
20277 : {
20278 13174 : SelectStmt *n = makeNode(SelectStmt);
20279 :
20280 13174 : n->op = op;
20281 13174 : n->all = all;
20282 13174 : n->larg = (SelectStmt *) larg;
20283 13174 : n->rarg = (SelectStmt *) rarg;
20284 13174 : return (Node *) n;
20285 : }
20286 :
20287 : /* SystemFuncName()
20288 : * Build a properly-qualified reference to a built-in function.
20289 : */
20290 : List *
20291 12911 : SystemFuncName(char *name)
20292 : {
20293 12911 : return list_make2(makeString("pg_catalog"), makeString(name));
20294 : }
20295 :
20296 : /* SystemTypeName()
20297 : * Build a properly-qualified reference to a built-in type.
20298 : *
20299 : * typmod is defaulted, but may be changed afterwards by caller.
20300 : * Likewise for the location.
20301 : */
20302 : TypeName *
20303 70691 : SystemTypeName(char *name)
20304 : {
20305 70691 : return makeTypeNameFromNameList(list_make2(makeString("pg_catalog"),
20306 : makeString(name)));
20307 : }
20308 :
20309 : /* doNegate()
20310 : * Handle negation of a numeric constant.
20311 : *
20312 : * Formerly, we did this here because the optimizer couldn't cope with
20313 : * indexquals that looked like "var = -4" --- it wants "var = const"
20314 : * and a unary minus operator applied to a constant didn't qualify.
20315 : * As of Postgres 7.0, that problem doesn't exist anymore because there
20316 : * is a constant-subexpression simplifier in the optimizer. However,
20317 : * there's still a good reason for doing this here, which is that we can
20318 : * postpone committing to a particular internal representation for simple
20319 : * negative constants. It's better to leave "-123.456" in string form
20320 : * until we know what the desired type is.
20321 : */
20322 : static Node *
20323 6395 : doNegate(Node *n, int location)
20324 : {
20325 6395 : if (IsA(n, A_Const))
20326 : {
20327 5739 : A_Const *con = (A_Const *) n;
20328 :
20329 : /* report the constant's location as that of the '-' sign */
20330 5739 : con->location = location;
20331 :
20332 5739 : if (IsA(&con->val, Integer))
20333 : {
20334 5104 : con->val.ival.ival = -con->val.ival.ival;
20335 5104 : return n;
20336 : }
20337 635 : if (IsA(&con->val, Float))
20338 : {
20339 635 : doNegateFloat(&con->val.fval);
20340 635 : return n;
20341 : }
20342 : }
20343 :
20344 656 : return (Node *) makeSimpleA_Expr(AEXPR_OP, "-", NULL, n, location);
20345 : }
20346 :
20347 : static void
20348 648 : doNegateFloat(Float *v)
20349 : {
20350 648 : char *oldval = v->fval;
20351 :
20352 648 : if (*oldval == '+')
20353 0 : oldval++;
20354 648 : if (*oldval == '-')
20355 0 : v->fval = oldval + 1; /* just strip the '-' */
20356 : else
20357 648 : v->fval = psprintf("-%s", oldval);
20358 648 : }
20359 :
20360 : static Node *
20361 157142 : makeAndExpr(Node *lexpr, Node *rexpr, int location)
20362 : {
20363 : /* Flatten "a AND b AND c ..." to a single BoolExpr on sight */
20364 157142 : if (IsA(lexpr, BoolExpr))
20365 : {
20366 73956 : BoolExpr *blexpr = (BoolExpr *) lexpr;
20367 :
20368 73956 : if (blexpr->boolop == AND_EXPR)
20369 : {
20370 70114 : blexpr->args = lappend(blexpr->args, rexpr);
20371 70114 : return (Node *) blexpr;
20372 : }
20373 : }
20374 87028 : return (Node *) makeBoolExpr(AND_EXPR, list_make2(lexpr, rexpr), location);
20375 : }
20376 :
20377 : static Node *
20378 15125 : makeOrExpr(Node *lexpr, Node *rexpr, int location)
20379 : {
20380 : /* Flatten "a OR b OR c ..." to a single BoolExpr on sight */
20381 15125 : if (IsA(lexpr, BoolExpr))
20382 : {
20383 3752 : BoolExpr *blexpr = (BoolExpr *) lexpr;
20384 :
20385 3752 : if (blexpr->boolop == OR_EXPR)
20386 : {
20387 2761 : blexpr->args = lappend(blexpr->args, rexpr);
20388 2761 : return (Node *) blexpr;
20389 : }
20390 : }
20391 12364 : return (Node *) makeBoolExpr(OR_EXPR, list_make2(lexpr, rexpr), location);
20392 : }
20393 :
20394 : static Node *
20395 16071 : makeNotExpr(Node *expr, int location)
20396 : {
20397 16071 : return (Node *) makeBoolExpr(NOT_EXPR, list_make1(expr), location);
20398 : }
20399 :
20400 : static Node *
20401 5900 : makeAArrayExpr(List *elements, int location, int location_end)
20402 : {
20403 5900 : A_ArrayExpr *n = makeNode(A_ArrayExpr);
20404 :
20405 5900 : n->elements = elements;
20406 5900 : n->location = location;
20407 5900 : n->list_start = location;
20408 5900 : n->list_end = location_end;
20409 5900 : return (Node *) n;
20410 : }
20411 :
20412 : static Node *
20413 1697 : makeSQLValueFunction(SQLValueFunctionOp op, int32 typmod, int location)
20414 : {
20415 1697 : SQLValueFunction *svf = makeNode(SQLValueFunction);
20416 :
20417 1697 : svf->op = op;
20418 : /* svf->type will be filled during parse analysis */
20419 1697 : svf->typmod = typmod;
20420 1697 : svf->location = location;
20421 1697 : return (Node *) svf;
20422 : }
20423 :
20424 : static Node *
20425 395 : makeXmlExpr(XmlExprOp op, char *name, List *named_args, List *args,
20426 : int location)
20427 : {
20428 395 : XmlExpr *x = makeNode(XmlExpr);
20429 :
20430 395 : x->op = op;
20431 395 : x->name = name;
20432 :
20433 : /*
20434 : * named_args is a list of ResTarget; it'll be split apart into separate
20435 : * expression and name lists in transformXmlExpr().
20436 : */
20437 395 : x->named_args = named_args;
20438 395 : x->arg_names = NIL;
20439 395 : x->args = args;
20440 : /* xmloption, if relevant, must be filled in by caller */
20441 : /* type and typmod will be filled in during parse analysis */
20442 395 : x->type = InvalidOid; /* marks the node as not analyzed */
20443 395 : x->location = location;
20444 395 : return (Node *) x;
20445 : }
20446 :
20447 : /*
20448 : * Merge the input and output parameters of a table function.
20449 : */
20450 : static List *
20451 146 : mergeTableFuncParameters(List *func_args, List *columns, core_yyscan_t yyscanner)
20452 : {
20453 : ListCell *lc;
20454 :
20455 : /* Explicit OUT and INOUT parameters shouldn't be used in this syntax */
20456 313 : foreach(lc, func_args)
20457 : {
20458 167 : FunctionParameter *p = (FunctionParameter *) lfirst(lc);
20459 :
20460 167 : if (p->mode != FUNC_PARAM_DEFAULT &&
20461 0 : p->mode != FUNC_PARAM_IN &&
20462 0 : p->mode != FUNC_PARAM_VARIADIC)
20463 0 : ereport(ERROR,
20464 : (errcode(ERRCODE_SYNTAX_ERROR),
20465 : errmsg("OUT and INOUT arguments aren't allowed in TABLE functions"),
20466 : parser_errposition(p->location)));
20467 : }
20468 :
20469 146 : return list_concat(func_args, columns);
20470 : }
20471 :
20472 : /*
20473 : * Determine return type of a TABLE function. A single result column
20474 : * returns setof that column's type; otherwise return setof record.
20475 : */
20476 : static TypeName *
20477 146 : TableFuncTypeName(List *columns)
20478 : {
20479 : TypeName *result;
20480 :
20481 146 : if (list_length(columns) == 1)
20482 : {
20483 40 : FunctionParameter *p = (FunctionParameter *) linitial(columns);
20484 :
20485 40 : result = copyObject(p->argType);
20486 : }
20487 : else
20488 106 : result = SystemTypeName("record");
20489 :
20490 146 : result->setof = true;
20491 :
20492 146 : return result;
20493 : }
20494 :
20495 : /*
20496 : * Convert a list of (dotted) names to a RangeVar (like
20497 : * makeRangeVarFromNameList, but with position support). The
20498 : * "AnyName" refers to the any_name production in the grammar.
20499 : */
20500 : static RangeVar *
20501 2516 : makeRangeVarFromAnyName(List *names, int position, core_yyscan_t yyscanner)
20502 : {
20503 2516 : RangeVar *r = makeNode(RangeVar);
20504 :
20505 2516 : switch (list_length(names))
20506 : {
20507 2466 : case 1:
20508 2466 : r->catalogname = NULL;
20509 2466 : r->schemaname = NULL;
20510 2466 : r->relname = strVal(linitial(names));
20511 2466 : break;
20512 50 : case 2:
20513 50 : r->catalogname = NULL;
20514 50 : r->schemaname = strVal(linitial(names));
20515 50 : r->relname = strVal(lsecond(names));
20516 50 : break;
20517 0 : case 3:
20518 0 : r->catalogname = strVal(linitial(names));
20519 0 : r->schemaname = strVal(lsecond(names));
20520 0 : r->relname = strVal(lthird(names));
20521 0 : break;
20522 0 : default:
20523 0 : ereport(ERROR,
20524 : (errcode(ERRCODE_SYNTAX_ERROR),
20525 : errmsg("improper qualified name (too many dotted names): %s",
20526 : NameListToString(names)),
20527 : parser_errposition(position)));
20528 : break;
20529 : }
20530 :
20531 2516 : r->relpersistence = RELPERSISTENCE_PERMANENT;
20532 2516 : r->location = position;
20533 :
20534 2516 : return r;
20535 : }
20536 :
20537 : /*
20538 : * Convert a relation_name with name and namelist to a RangeVar using
20539 : * makeRangeVar.
20540 : */
20541 : static RangeVar *
20542 157714 : makeRangeVarFromQualifiedName(char *name, List *namelist, int location,
20543 : core_yyscan_t yyscanner)
20544 : {
20545 : RangeVar *r;
20546 :
20547 157714 : check_qualified_name(namelist, yyscanner);
20548 157714 : r = makeRangeVar(NULL, NULL, location);
20549 :
20550 157714 : switch (list_length(namelist))
20551 : {
20552 157714 : case 1:
20553 157714 : r->catalogname = NULL;
20554 157714 : r->schemaname = name;
20555 157714 : r->relname = strVal(linitial(namelist));
20556 157714 : break;
20557 0 : case 2:
20558 0 : r->catalogname = name;
20559 0 : r->schemaname = strVal(linitial(namelist));
20560 0 : r->relname = strVal(lsecond(namelist));
20561 0 : break;
20562 0 : default:
20563 0 : ereport(ERROR,
20564 : errcode(ERRCODE_SYNTAX_ERROR),
20565 : errmsg("improper qualified name (too many dotted names): %s",
20566 : NameListToString(lcons(makeString(name), namelist))),
20567 : parser_errposition(location));
20568 : break;
20569 : }
20570 :
20571 157714 : return r;
20572 : }
20573 :
20574 : /* Separate Constraint nodes from COLLATE clauses in a ColQualList */
20575 : static void
20576 46062 : SplitColQualList(List *qualList,
20577 : List **constraintList, CollateClause **collClause,
20578 : core_yyscan_t yyscanner)
20579 : {
20580 : ListCell *cell;
20581 :
20582 46062 : *collClause = NULL;
20583 59451 : foreach(cell, qualList)
20584 : {
20585 13389 : Node *n = (Node *) lfirst(cell);
20586 :
20587 13389 : if (IsA(n, Constraint))
20588 : {
20589 : /* keep it in list */
20590 12883 : continue;
20591 : }
20592 506 : if (IsA(n, CollateClause))
20593 : {
20594 506 : CollateClause *c = (CollateClause *) n;
20595 :
20596 506 : if (*collClause)
20597 0 : ereport(ERROR,
20598 : (errcode(ERRCODE_SYNTAX_ERROR),
20599 : errmsg("multiple COLLATE clauses not allowed"),
20600 : parser_errposition(c->location)));
20601 506 : *collClause = c;
20602 : }
20603 : else
20604 0 : elog(ERROR, "unexpected node type %d", (int) n->type);
20605 : /* remove non-Constraint nodes from qualList */
20606 506 : qualList = foreach_delete_current(qualList, cell);
20607 : }
20608 46062 : *constraintList = qualList;
20609 46062 : }
20610 :
20611 : /*
20612 : * Process result of ConstraintAttributeSpec, and set appropriate bool flags
20613 : * in the output command node. Pass NULL for any flags the particular
20614 : * command doesn't support.
20615 : */
20616 : static void
20617 11758 : processCASbits(int cas_bits, int location, const char *constrType,
20618 : bool *deferrable, bool *initdeferred, bool *is_enforced,
20619 : bool *not_valid, bool *no_inherit, core_yyscan_t yyscanner)
20620 : {
20621 : /* defaults */
20622 11758 : if (deferrable)
20623 10256 : *deferrable = false;
20624 11758 : if (initdeferred)
20625 10256 : *initdeferred = false;
20626 11758 : if (not_valid)
20627 2678 : *not_valid = false;
20628 11758 : if (is_enforced)
20629 2442 : *is_enforced = true;
20630 :
20631 11758 : if (cas_bits & (CAS_DEFERRABLE | CAS_INITIALLY_DEFERRED))
20632 : {
20633 168 : if (deferrable)
20634 168 : *deferrable = true;
20635 : else
20636 0 : ereport(ERROR,
20637 : (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
20638 : /* translator: %s is CHECK, UNIQUE, or similar */
20639 : errmsg("%s constraints cannot be marked DEFERRABLE",
20640 : constrType),
20641 : parser_errposition(location)));
20642 : }
20643 :
20644 11758 : if (cas_bits & CAS_INITIALLY_DEFERRED)
20645 : {
20646 112 : if (initdeferred)
20647 112 : *initdeferred = true;
20648 : else
20649 0 : ereport(ERROR,
20650 : (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
20651 : /* translator: %s is CHECK, UNIQUE, or similar */
20652 : errmsg("%s constraints cannot be marked DEFERRABLE",
20653 : constrType),
20654 : parser_errposition(location)));
20655 : }
20656 :
20657 11758 : if (cas_bits & CAS_NOT_VALID)
20658 : {
20659 430 : if (not_valid)
20660 430 : *not_valid = true;
20661 : else
20662 0 : ereport(ERROR,
20663 : (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
20664 : /* translator: %s is CHECK, UNIQUE, or similar */
20665 : errmsg("%s constraints cannot be marked NOT VALID",
20666 : constrType),
20667 : parser_errposition(location)));
20668 : }
20669 :
20670 11758 : if (cas_bits & CAS_NO_INHERIT)
20671 : {
20672 163 : if (no_inherit)
20673 163 : *no_inherit = true;
20674 : else
20675 0 : ereport(ERROR,
20676 : (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
20677 : /* translator: %s is CHECK, UNIQUE, or similar */
20678 : errmsg("%s constraints cannot be marked NO INHERIT",
20679 : constrType),
20680 : parser_errposition(location)));
20681 : }
20682 :
20683 11758 : if (cas_bits & CAS_NOT_ENFORCED)
20684 : {
20685 163 : if (is_enforced)
20686 159 : *is_enforced = false;
20687 : else
20688 4 : ereport(ERROR,
20689 : (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
20690 : /* translator: %s is CHECK, UNIQUE, or similar */
20691 : errmsg("%s constraints cannot be marked NOT ENFORCED",
20692 : constrType),
20693 : parser_errposition(location)));
20694 :
20695 : /*
20696 : * NB: The validated status is irrelevant when the constraint is set to
20697 : * NOT ENFORCED, but for consistency, it should be set accordingly.
20698 : * This ensures that if the constraint is later changed to ENFORCED, it
20699 : * will automatically be in the correct NOT VALIDATED state.
20700 : */
20701 159 : if (not_valid)
20702 103 : *not_valid = true;
20703 : }
20704 :
20705 11754 : if (cas_bits & CAS_ENFORCED)
20706 : {
20707 140 : if (is_enforced)
20708 136 : *is_enforced = true;
20709 : else
20710 4 : ereport(ERROR,
20711 : (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
20712 : /* translator: %s is CHECK, UNIQUE, or similar */
20713 : errmsg("%s constraints cannot be marked ENFORCED",
20714 : constrType),
20715 : parser_errposition(location)));
20716 : }
20717 11750 : }
20718 :
20719 : /*
20720 : * Parse a user-supplied partition strategy string into parse node
20721 : * PartitionStrategy representation, or die trying.
20722 : */
20723 : static PartitionStrategy
20724 3587 : parsePartitionStrategy(char *strategy, int location, core_yyscan_t yyscanner)
20725 : {
20726 3587 : if (pg_strcasecmp(strategy, "list") == 0)
20727 1630 : return PARTITION_STRATEGY_LIST;
20728 1957 : else if (pg_strcasecmp(strategy, "range") == 0)
20729 1774 : return PARTITION_STRATEGY_RANGE;
20730 183 : else if (pg_strcasecmp(strategy, "hash") == 0)
20731 179 : return PARTITION_STRATEGY_HASH;
20732 :
20733 4 : ereport(ERROR,
20734 : (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
20735 : errmsg("unrecognized partitioning strategy \"%s\"", strategy),
20736 : parser_errposition(location)));
20737 : return PARTITION_STRATEGY_LIST; /* keep compiler quiet */
20738 :
20739 : }
20740 :
20741 : /*
20742 : * Process all_objects_list to set all_tables and/or all_sequences.
20743 : * Also, checks if the pub_object_type has been specified more than once.
20744 : */
20745 : static void
20746 197 : preprocess_pub_all_objtype_list(List *all_objects_list, List **pubobjects,
20747 : bool *all_tables, bool *all_sequences,
20748 : core_yyscan_t yyscanner)
20749 : {
20750 197 : if (!all_objects_list)
20751 0 : return;
20752 :
20753 197 : *all_tables = false;
20754 197 : *all_sequences = false;
20755 :
20756 600 : foreach_ptr(PublicationAllObjSpec, obj, all_objects_list)
20757 : {
20758 222 : if (obj->pubobjtype == PUBLICATION_ALL_TABLES)
20759 : {
20760 173 : if (*all_tables)
20761 4 : ereport(ERROR,
20762 : errcode(ERRCODE_SYNTAX_ERROR),
20763 : errmsg("invalid publication object list"),
20764 : errdetail("ALL TABLES can be specified only once."),
20765 : parser_errposition(obj->location));
20766 :
20767 169 : *all_tables = true;
20768 169 : *pubobjects = list_concat(*pubobjects, obj->except_tables);
20769 : }
20770 49 : else if (obj->pubobjtype == PUBLICATION_ALL_SEQUENCES)
20771 : {
20772 49 : if (*all_sequences)
20773 4 : ereport(ERROR,
20774 : errcode(ERRCODE_SYNTAX_ERROR),
20775 : errmsg("invalid publication object list"),
20776 : errdetail("ALL SEQUENCES can be specified only once."),
20777 : parser_errposition(obj->location));
20778 :
20779 45 : *all_sequences = true;
20780 : }
20781 : }
20782 : }
20783 :
20784 : /*
20785 : * Process pubobjspec_list to check for errors in any of the objects and
20786 : * convert PUBLICATIONOBJ_CONTINUATION into appropriate PublicationObjSpecType.
20787 : */
20788 : static void
20789 1077 : preprocess_pubobj_list(List *pubobjspec_list, core_yyscan_t yyscanner)
20790 : {
20791 : ListCell *cell;
20792 : PublicationObjSpec *pubobj;
20793 1077 : PublicationObjSpecType prevobjtype = PUBLICATIONOBJ_CONTINUATION;
20794 :
20795 1077 : if (!pubobjspec_list)
20796 0 : return;
20797 :
20798 1077 : pubobj = (PublicationObjSpec *) linitial(pubobjspec_list);
20799 1077 : if (pubobj->pubobjtype == PUBLICATIONOBJ_CONTINUATION)
20800 8 : ereport(ERROR,
20801 : errcode(ERRCODE_SYNTAX_ERROR),
20802 : errmsg("invalid publication object list"),
20803 : errdetail("One of TABLE or TABLES IN SCHEMA must be specified before a standalone table or schema name."),
20804 : parser_errposition(pubobj->location));
20805 :
20806 2287 : foreach(cell, pubobjspec_list)
20807 : {
20808 1234 : pubobj = (PublicationObjSpec *) lfirst(cell);
20809 :
20810 1234 : if (pubobj->pubobjtype == PUBLICATIONOBJ_CONTINUATION)
20811 112 : pubobj->pubobjtype = prevobjtype;
20812 :
20813 1234 : if (pubobj->pubobjtype == PUBLICATIONOBJ_TABLE)
20814 : {
20815 : /* relation name or pubtable must be set for this type of object */
20816 938 : if (!pubobj->name && !pubobj->pubtable)
20817 4 : ereport(ERROR,
20818 : errcode(ERRCODE_SYNTAX_ERROR),
20819 : errmsg("invalid table name"),
20820 : parser_errposition(pubobj->location));
20821 :
20822 934 : if (pubobj->name)
20823 : {
20824 : /* convert it to PublicationTable */
20825 37 : PublicationTable *pubtable = makeNode(PublicationTable);
20826 :
20827 37 : pubtable->relation =
20828 37 : makeRangeVar(NULL, pubobj->name, pubobj->location);
20829 37 : pubobj->pubtable = pubtable;
20830 37 : pubobj->name = NULL;
20831 : }
20832 : }
20833 296 : else if (pubobj->pubobjtype == PUBLICATIONOBJ_TABLES_IN_SCHEMA ||
20834 16 : pubobj->pubobjtype == PUBLICATIONOBJ_TABLES_IN_CUR_SCHEMA)
20835 : {
20836 : /* WHERE clause is not allowed on a schema object */
20837 296 : if (pubobj->pubtable && pubobj->pubtable->whereClause)
20838 4 : ereport(ERROR,
20839 : errcode(ERRCODE_SYNTAX_ERROR),
20840 : errmsg("WHERE clause not allowed for schema"),
20841 : parser_errposition(pubobj->location));
20842 :
20843 : /* Column list is not allowed on a schema object */
20844 292 : if (pubobj->pubtable && pubobj->pubtable->columns)
20845 4 : ereport(ERROR,
20846 : errcode(ERRCODE_SYNTAX_ERROR),
20847 : errmsg("column specification not allowed for schema"),
20848 : parser_errposition(pubobj->location));
20849 :
20850 : /*
20851 : * We can distinguish between the different type of schema objects
20852 : * based on whether name and pubtable is set.
20853 : */
20854 288 : if (pubobj->name)
20855 268 : pubobj->pubobjtype = PUBLICATIONOBJ_TABLES_IN_SCHEMA;
20856 20 : else if (!pubobj->name && !pubobj->pubtable)
20857 16 : pubobj->pubobjtype = PUBLICATIONOBJ_TABLES_IN_CUR_SCHEMA;
20858 : else
20859 4 : ereport(ERROR,
20860 : errcode(ERRCODE_SYNTAX_ERROR),
20861 : errmsg("invalid schema name"),
20862 : parser_errposition(pubobj->location));
20863 : }
20864 :
20865 1218 : prevobjtype = pubobj->pubobjtype;
20866 : }
20867 : }
20868 :
20869 : /*----------
20870 : * Recursive view transformation
20871 : *
20872 : * Convert
20873 : *
20874 : * CREATE RECURSIVE VIEW relname (aliases) AS query
20875 : *
20876 : * to
20877 : *
20878 : * CREATE VIEW relname (aliases) AS
20879 : * WITH RECURSIVE relname (aliases) AS (query)
20880 : * SELECT aliases FROM relname
20881 : *
20882 : * Actually, just the WITH ... part, which is then inserted into the original
20883 : * view definition as the query.
20884 : * ----------
20885 : */
20886 : static Node *
20887 9 : makeRecursiveViewSelect(char *relname, List *aliases, Node *query)
20888 : {
20889 9 : SelectStmt *s = makeNode(SelectStmt);
20890 9 : WithClause *w = makeNode(WithClause);
20891 9 : CommonTableExpr *cte = makeNode(CommonTableExpr);
20892 9 : List *tl = NIL;
20893 : ListCell *lc;
20894 :
20895 : /* create common table expression */
20896 9 : cte->ctename = relname;
20897 9 : cte->aliascolnames = aliases;
20898 9 : cte->ctematerialized = CTEMaterializeDefault;
20899 9 : cte->ctequery = query;
20900 9 : cte->location = -1;
20901 :
20902 : /* create WITH clause and attach CTE */
20903 9 : w->recursive = true;
20904 9 : w->ctes = list_make1(cte);
20905 9 : w->location = -1;
20906 :
20907 : /*
20908 : * create target list for the new SELECT from the alias list of the
20909 : * recursive view specification
20910 : */
20911 18 : foreach(lc, aliases)
20912 : {
20913 9 : ResTarget *rt = makeNode(ResTarget);
20914 :
20915 9 : rt->name = NULL;
20916 9 : rt->indirection = NIL;
20917 9 : rt->val = makeColumnRef(strVal(lfirst(lc)), NIL, -1, 0);
20918 9 : rt->location = -1;
20919 :
20920 9 : tl = lappend(tl, rt);
20921 : }
20922 :
20923 : /*
20924 : * create new SELECT combining WITH clause, target list, and fake FROM
20925 : * clause
20926 : */
20927 9 : s->withClause = w;
20928 9 : s->targetList = tl;
20929 9 : s->fromClause = list_make1(makeRangeVar(NULL, relname, -1));
20930 :
20931 9 : return (Node *) s;
20932 : }
20933 :
20934 : /* parser_init()
20935 : * Initialize to parse one query string
20936 : */
20937 : void
20938 497601 : parser_init(base_yy_extra_type *yyext)
20939 : {
20940 497601 : yyext->parsetree = NIL; /* in case grammar forgets to set it */
20941 497601 : }
|