Branch data 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 : : List *list;
124 : : } GroupClause;
125 : :
126 : : /* Private structs for the result of key_actions and key_action productions */
127 : : typedef struct KeyAction
128 : : {
129 : : char action;
130 : : List *cols;
131 : : } KeyAction;
132 : :
133 : : typedef struct KeyActions
134 : : {
135 : : KeyAction *updateAction;
136 : : KeyAction *deleteAction;
137 : : } KeyActions;
138 : :
139 : : /* ConstraintAttributeSpec yields an integer bitmask of these flags: */
140 : : #define CAS_NOT_DEFERRABLE 0x01
141 : : #define CAS_DEFERRABLE 0x02
142 : : #define CAS_INITIALLY_IMMEDIATE 0x04
143 : : #define CAS_INITIALLY_DEFERRED 0x08
144 : : #define CAS_NOT_VALID 0x10
145 : : #define CAS_NO_INHERIT 0x20
146 : : #define CAS_NOT_ENFORCED 0x40
147 : : #define CAS_ENFORCED 0x80
148 : :
149 : :
150 : : #define parser_yyerror(msg) scanner_yyerror(msg, yyscanner)
151 : : #define parser_errposition(pos) scanner_errposition(pos, yyscanner)
152 : :
153 : : static void base_yyerror(YYLTYPE *yylloc, core_yyscan_t yyscanner,
154 : : const char *msg);
155 : : static RawStmt *makeRawStmt(Node *stmt, int stmt_location);
156 : : static void updateRawStmtEnd(RawStmt *rs, int end_location);
157 : : static Node *makeColumnRef(char *colname, List *indirection,
158 : : int location, core_yyscan_t yyscanner);
159 : : static Node *makeTypeCast(Node *arg, TypeName *typename, int location);
160 : : static Node *makeStringConstCast(char *str, int location, TypeName *typename);
161 : : static Node *makeIntConst(int val, int location);
162 : : static Node *makeFloatConst(char *str, int location);
163 : : static Node *makeBoolAConst(bool state, int location);
164 : : static Node *makeBitStringConst(char *str, int location);
165 : : static Node *makeNullAConst(int location);
166 : : static Node *makeAConst(Node *v, int location);
167 : : static RoleSpec *makeRoleSpec(RoleSpecType type, int location);
168 : : static void check_qualified_name(List *names, core_yyscan_t yyscanner);
169 : : static List *check_func_name(List *names, core_yyscan_t yyscanner);
170 : : static List *check_indirection(List *indirection, core_yyscan_t yyscanner);
171 : : static List *extractArgTypes(List *parameters);
172 : : static List *extractAggrArgTypes(List *aggrargs);
173 : : static List *makeOrderedSetArgs(List *directargs, List *orderedargs,
174 : : core_yyscan_t yyscanner);
175 : : static void insertSelectOptions(SelectStmt *stmt,
176 : : List *sortClause, List *lockingClause,
177 : : SelectLimit *limitClause,
178 : : WithClause *withClause,
179 : : core_yyscan_t yyscanner);
180 : : static Node *makeSetOp(SetOperation op, bool all, Node *larg, Node *rarg);
181 : : static Node *doNegate(Node *n, int location);
182 : : static void doNegateFloat(Float *v);
183 : : static Node *makeAndExpr(Node *lexpr, Node *rexpr, int location);
184 : : static Node *makeOrExpr(Node *lexpr, Node *rexpr, int location);
185 : : static Node *makeNotExpr(Node *expr, int location);
186 : : static Node *makeAArrayExpr(List *elements, int location, int location_end);
187 : : static Node *makeSQLValueFunction(SQLValueFunctionOp op, int32 typmod,
188 : : int location);
189 : : static Node *makeXmlExpr(XmlExprOp op, char *name, List *named_args,
190 : : List *args, int location);
191 : : static List *mergeTableFuncParameters(List *func_args, List *columns, core_yyscan_t yyscanner);
192 : : static TypeName *TableFuncTypeName(List *columns);
193 : : static RangeVar *makeRangeVarFromAnyName(List *names, int position, core_yyscan_t yyscanner);
194 : : static RangeVar *makeRangeVarFromQualifiedName(char *name, List *namelist, int location,
195 : : core_yyscan_t yyscanner);
196 : : static void SplitColQualList(List *qualList,
197 : : List **constraintList, CollateClause **collClause,
198 : : core_yyscan_t yyscanner);
199 : : static void processCASbits(int cas_bits, int location, const char *constrType,
200 : : bool *deferrable, bool *initdeferred, bool *is_enforced,
201 : : bool *not_valid, bool *no_inherit, core_yyscan_t yyscanner);
202 : : static PartitionStrategy parsePartitionStrategy(char *strategy, int location,
203 : : core_yyscan_t yyscanner);
204 : : static void preprocess_pub_all_objtype_list(List *all_objects_list,
205 : : List **pubobjects,
206 : : bool *all_tables,
207 : : bool *all_sequences,
208 : : core_yyscan_t yyscanner);
209 : : static void preprocess_pubobj_list(List *pubobjspec_list,
210 : : core_yyscan_t yyscanner);
211 : : static Node *makeRecursiveViewSelect(char *relname, List *aliases, Node *query);
212 : :
213 : : %}
214 : :
215 : : %pure-parser
216 : : %expect 0
217 : : %name-prefix="base_yy"
218 : : %locations
219 : :
220 : : %parse-param {core_yyscan_t yyscanner}
221 : : %lex-param {core_yyscan_t yyscanner}
222 : :
223 : : %union
224 : : {
225 : : core_YYSTYPE core_yystype;
226 : : /* these fields must match core_YYSTYPE: */
227 : : int ival;
228 : : char *str;
229 : : const char *keyword;
230 : :
231 : : char chr;
232 : : bool boolean;
233 : : JoinType jtype;
234 : : DropBehavior dbehavior;
235 : : OnCommitAction oncommit;
236 : : List *list;
237 : : Node *node;
238 : : ObjectType objtype;
239 : : TypeName *typnam;
240 : : FunctionParameter *fun_param;
241 : : FunctionParameterMode fun_param_mode;
242 : : ObjectWithArgs *objwithargs;
243 : : DefElem *defelt;
244 : : SortBy *sortby;
245 : : WindowDef *windef;
246 : : JoinExpr *jexpr;
247 : : IndexElem *ielem;
248 : : StatsElem *selem;
249 : : Alias *alias;
250 : : RangeVar *range;
251 : : IntoClause *into;
252 : : WithClause *with;
253 : : InferClause *infer;
254 : : OnConflictClause *onconflict;
255 : : A_Indices *aind;
256 : : ResTarget *target;
257 : : struct PrivTarget *privtarget;
258 : : AccessPriv *accesspriv;
259 : : struct ImportQual *importqual;
260 : : InsertStmt *istmt;
261 : : VariableSetStmt *vsetstmt;
262 : : PartitionElem *partelem;
263 : : PartitionSpec *partspec;
264 : : PartitionBoundSpec *partboundspec;
265 : : SinglePartitionSpec *singlepartspec;
266 : : RoleSpec *rolespec;
267 : : PublicationObjSpec *publicationobjectspec;
268 : : PublicationAllObjSpec *publicationallobjectspec;
269 : : struct SelectLimit *selectlimit;
270 : : SetQuantifier setquantifier;
271 : : struct GroupClause *groupclause;
272 : : MergeMatchKind mergematch;
273 : : MergeWhenClause *mergewhen;
274 : : struct KeyActions *keyactions;
275 : : struct KeyAction *keyaction;
276 : : ReturningClause *retclause;
277 : : ReturningOptionKind retoptionkind;
278 : : }
279 : :
280 : : %type <node> stmt toplevel_stmt schema_stmt routine_body_stmt
281 : : AlterEventTrigStmt AlterCollationStmt
282 : : AlterDatabaseStmt AlterDatabaseSetStmt AlterDomainStmt AlterEnumStmt
283 : : AlterFdwStmt AlterForeignServerStmt AlterGroupStmt
284 : : AlterObjectDependsStmt AlterObjectSchemaStmt AlterOwnerStmt
285 : : AlterOperatorStmt AlterTypeStmt AlterSeqStmt AlterSystemStmt AlterTableStmt
286 : : AlterTblSpcStmt AlterExtensionStmt AlterExtensionContentsStmt
287 : : AlterCompositeTypeStmt AlterUserMappingStmt
288 : : AlterRoleStmt AlterRoleSetStmt AlterPolicyStmt AlterStatsStmt
289 : : AlterDefaultPrivilegesStmt DefACLAction
290 : : AnalyzeStmt CallStmt ClosePortalStmt CommentStmt
291 : : ConstraintsSetStmt CopyStmt CreateAsStmt CreateCastStmt
292 : : CreateDomainStmt CreateExtensionStmt CreateGroupStmt CreateOpClassStmt
293 : : CreateOpFamilyStmt AlterOpFamilyStmt CreatePLangStmt
294 : : CreateSchemaStmt CreateSeqStmt CreateStmt CreateStatsStmt CreateTableSpaceStmt
295 : : CreateFdwStmt CreateForeignServerStmt CreateForeignTableStmt
296 : : CreateAssertionStmt CreateTransformStmt CreateTrigStmt CreateEventTrigStmt
297 : : CreatePropGraphStmt AlterPropGraphStmt
298 : : CreateUserStmt CreateUserMappingStmt CreateRoleStmt CreatePolicyStmt
299 : : CreatedbStmt DeclareCursorStmt DefineStmt DeleteStmt DiscardStmt DoStmt
300 : : DropOpClassStmt DropOpFamilyStmt DropStmt
301 : : DropCastStmt DropRoleStmt
302 : : DropdbStmt DropTableSpaceStmt
303 : : DropTransformStmt
304 : : DropUserMappingStmt ExplainStmt FetchStmt
305 : : GrantStmt GrantRoleStmt ImportForeignSchemaStmt IndexStmt InsertStmt
306 : : ListenStmt LoadStmt LockStmt MergeStmt NotifyStmt ExplainableStmt PreparableStmt
307 : : CreateFunctionStmt AlterFunctionStmt ReindexStmt RemoveAggrStmt
308 : : RemoveFuncStmt RemoveOperStmt RenameStmt RepackStmt ReturnStmt RevokeStmt RevokeRoleStmt
309 : : RuleActionStmt RuleActionStmtOrEmpty RuleStmt
310 : : SecLabelStmt SelectStmt TransactionStmt TransactionStmtLegacy TruncateStmt
311 : : UnlistenStmt UpdateStmt VacuumStmt
312 : : VariableResetStmt VariableSetStmt VariableShowStmt
313 : : ViewStmt WaitStmt CheckPointStmt CreateConversionStmt
314 : : DeallocateStmt PrepareStmt ExecuteStmt
315 : : DropOwnedStmt ReassignOwnedStmt
316 : : AlterTSConfigurationStmt AlterTSDictionaryStmt
317 : : CreateMatViewStmt RefreshMatViewStmt CreateAmStmt
318 : : CreatePublicationStmt AlterPublicationStmt
319 : : CreateSubscriptionStmt AlterSubscriptionStmt DropSubscriptionStmt
320 : :
321 : : %type <node> select_no_parens select_with_parens select_clause
322 : : simple_select values_clause
323 : : PLpgSQL_Expr PLAssignStmt
324 : :
325 : : %type <str> opt_single_name
326 : : %type <list> opt_qualified_name
327 : : %type <boolean> opt_concurrently opt_usingindex
328 : : %type <dbehavior> opt_drop_behavior
329 : : %type <list> opt_utility_option_list
330 : : %type <list> opt_wait_with_clause
331 : : %type <list> utility_option_list
332 : : %type <defelt> utility_option_elem
333 : : %type <str> utility_option_name
334 : : %type <node> utility_option_arg
335 : :
336 : : %type <node> alter_column_default opclass_item opclass_drop alter_using
337 : : %type <ival> add_drop opt_asc_desc opt_nulls_order
338 : :
339 : : %type <node> alter_table_cmd alter_type_cmd opt_collate_clause
340 : : replica_identity partition_cmd index_partition_cmd
341 : : %type <list> alter_table_cmds alter_type_cmds
342 : : %type <list> alter_identity_column_option_list
343 : : %type <defelt> alter_identity_column_option
344 : : %type <node> set_statistics_value
345 : : %type <str> set_access_method_name
346 : :
347 : : %type <list> createdb_opt_list createdb_opt_items copy_opt_list
348 : : transaction_mode_list
349 : : create_extension_opt_list alter_extension_opt_list
350 : : %type <defelt> createdb_opt_item copy_opt_item
351 : : transaction_mode_item
352 : : create_extension_opt_item alter_extension_opt_item
353 : :
354 : : %type <ival> opt_lock lock_type cast_context
355 : : %type <defelt> drop_option
356 : : %type <boolean> opt_or_replace opt_no
357 : : opt_grant_grant_option
358 : : opt_nowait opt_if_exists opt_with_data
359 : : opt_transaction_chain
360 : : %type <list> grant_role_opt_list
361 : : %type <defelt> grant_role_opt
362 : : %type <node> grant_role_opt_value
363 : : %type <ival> opt_nowait_or_skip
364 : :
365 : : %type <list> OptRoleList AlterOptRoleList
366 : : %type <defelt> CreateOptRoleElem AlterOptRoleElem
367 : :
368 : : %type <str> opt_type
369 : : %type <str> foreign_server_version opt_foreign_server_version
370 : : %type <str> opt_in_database
371 : :
372 : : %type <str> parameter_name
373 : : %type <list> OptSchemaEltList parameter_name_list
374 : :
375 : : %type <chr> am_type
376 : :
377 : : %type <boolean> TriggerForSpec TriggerForType
378 : : %type <ival> TriggerActionTime
379 : : %type <list> TriggerEvents TriggerOneEvent
380 : : %type <node> TriggerFuncArg
381 : : %type <node> TriggerWhen
382 : : %type <str> TransitionRelName
383 : : %type <boolean> TransitionRowOrTable TransitionOldOrNew
384 : : %type <node> TriggerTransition
385 : :
386 : : %type <list> event_trigger_when_list event_trigger_value_list
387 : : %type <defelt> event_trigger_when_item
388 : : %type <chr> enable_trigger
389 : :
390 : : %type <str> copy_file_name
391 : : access_method_clause attr_name
392 : : table_access_method_clause name cursor_name file_name
393 : : cluster_index_specification
394 : :
395 : : %type <list> func_name handler_name qual_Op qual_all_Op subquery_Op
396 : : opt_inline_handler opt_validator validator_clause
397 : : opt_collate
398 : :
399 : : %type <range> qualified_name insert_target OptConstrFromTable
400 : :
401 : : %type <str> all_Op MathOp
402 : :
403 : : %type <str> row_security_cmd RowSecurityDefaultForCmd
404 : : %type <boolean> RowSecurityDefaultPermissive
405 : : %type <node> RowSecurityOptionalWithCheck RowSecurityOptionalExpr
406 : : %type <list> RowSecurityDefaultToRole RowSecurityOptionalToRole
407 : :
408 : : %type <str> iso_level opt_encoding
409 : : %type <rolespec> grantee
410 : : %type <list> grantee_list
411 : : %type <accesspriv> privilege
412 : : %type <list> privileges privilege_list
413 : : %type <privtarget> privilege_target
414 : : %type <objwithargs> function_with_argtypes aggregate_with_argtypes operator_with_argtypes
415 : : %type <list> function_with_argtypes_list aggregate_with_argtypes_list operator_with_argtypes_list
416 : : %type <ival> defacl_privilege_target
417 : : %type <defelt> DefACLOption
418 : : %type <list> DefACLOptionList
419 : : %type <ival> import_qualification_type
420 : : %type <importqual> import_qualification
421 : : %type <node> vacuum_relation
422 : : %type <selectlimit> opt_select_limit select_limit limit_clause
423 : :
424 : : %type <list> parse_toplevel stmtmulti routine_body_stmt_list
425 : : OptTableElementList TableElementList OptInherit definition
426 : : OptTypedTableElementList TypedTableElementList
427 : : reloptions opt_reloptions
428 : : OptWith opt_definition func_args func_args_list
429 : : func_args_with_defaults func_args_with_defaults_list
430 : : aggr_args aggr_args_list
431 : : func_as createfunc_opt_list opt_createfunc_opt_list alterfunc_opt_list
432 : : old_aggr_definition old_aggr_list
433 : : oper_argtypes RuleActionList RuleActionMulti
434 : : opt_column_list columnList opt_name_list
435 : : sort_clause opt_sort_clause sortby_list index_params
436 : : stats_params
437 : : opt_include opt_c_include index_including_params
438 : : name_list role_list from_clause from_list opt_array_bounds
439 : : qualified_name_list any_name any_name_list type_name_list
440 : : any_operator expr_list attrs
441 : : distinct_clause opt_distinct_clause
442 : : target_list opt_target_list insert_column_list set_target_list
443 : : merge_values_clause
444 : : set_clause_list set_clause
445 : : def_list operator_def_list indirection opt_indirection
446 : : reloption_list TriggerFuncArgs opclass_item_list opclass_drop_list
447 : : opclass_purpose opt_opfamily transaction_mode_list_or_empty
448 : : OptTableFuncElementList TableFuncElementList opt_type_modifiers
449 : : prep_type_clause
450 : : execute_param_clause using_clause
451 : : returning_with_clause returning_options
452 : : opt_enum_val_list enum_val_list table_func_column_list
453 : : create_generic_options alter_generic_options
454 : : relation_expr_list dostmt_opt_list
455 : : transform_element_list transform_type_list
456 : : TriggerTransitions TriggerReferencing
457 : : vacuum_relation_list opt_vacuum_relation_list
458 : : drop_option_list pub_obj_list pub_all_obj_type_list
459 : : pub_except_obj_list opt_pub_except_clause
460 : :
461 : : %type <retclause> returning_clause
462 : : %type <node> returning_option
463 : : %type <retoptionkind> returning_option_kind
464 : : %type <node> opt_routine_body
465 : : %type <groupclause> group_clause
466 : : %type <list> group_by_list
467 : : %type <node> group_by_item empty_grouping_set rollup_clause cube_clause
468 : : %type <node> grouping_sets_clause
469 : :
470 : : %type <list> opt_fdw_options fdw_options
471 : : %type <defelt> fdw_option
472 : :
473 : : %type <range> OptTempTableName
474 : : %type <into> into_clause create_as_target create_mv_target
475 : :
476 : : %type <defelt> createfunc_opt_item common_func_opt_item dostmt_opt_item
477 : : %type <fun_param> func_arg func_arg_with_default table_func_column aggr_arg
478 : : %type <fun_param_mode> arg_class
479 : : %type <typnam> func_return func_type
480 : :
481 : : %type <boolean> opt_trusted opt_restart_seqs
482 : : %type <ival> OptTemp
483 : : %type <ival> OptNoLog
484 : : %type <oncommit> OnCommitOption
485 : :
486 : : %type <ival> for_locking_strength opt_for_locking_strength
487 : : %type <node> for_locking_item
488 : : %type <list> for_locking_clause opt_for_locking_clause for_locking_items
489 : : %type <list> locked_rels_list
490 : : %type <setquantifier> set_quantifier
491 : :
492 : : %type <node> join_qual
493 : : %type <jtype> join_type
494 : :
495 : : %type <list> extract_list overlay_list position_list
496 : : %type <list> substr_list trim_list
497 : : %type <list> opt_interval interval_second
498 : : %type <str> unicode_normal_form
499 : :
500 : : %type <boolean> opt_instead
501 : : %type <boolean> opt_unique opt_verbose opt_full
502 : : %type <boolean> opt_freeze opt_analyze opt_default
503 : : %type <defelt> opt_binary copy_delimiter
504 : :
505 : : %type <boolean> copy_from opt_program
506 : :
507 : : %type <ival> event cursor_options opt_hold opt_set_data
508 : : %type <objtype> object_type_any_name object_type_name object_type_name_on_any_name
509 : : drop_type_name
510 : :
511 : : %type <node> fetch_args select_limit_value
512 : : offset_clause select_offset_value
513 : : select_fetch_first_value I_or_F_const
514 : : %type <ival> row_or_rows first_or_next
515 : :
516 : : %type <list> OptSeqOptList SeqOptList OptParenthesizedSeqOptList
517 : : %type <defelt> SeqOptElem
518 : :
519 : : %type <istmt> insert_rest
520 : : %type <infer> opt_conf_expr
521 : : %type <onconflict> opt_on_conflict
522 : : %type <mergewhen> merge_insert merge_update merge_delete
523 : :
524 : : %type <mergematch> merge_when_tgt_matched merge_when_tgt_not_matched
525 : : %type <node> merge_when_clause opt_merge_when_condition
526 : : %type <list> merge_when_list
527 : :
528 : : %type <vsetstmt> generic_set set_rest set_rest_more generic_reset reset_rest
529 : : SetResetClause FunctionSetResetClause
530 : :
531 : : %type <node> TableElement TypedTableElement ConstraintElem DomainConstraintElem TableFuncElement
532 : : %type <node> columnDef columnOptions optionalPeriodName
533 : : %type <defelt> def_elem reloption_elem old_aggr_elem operator_def_elem
534 : : %type <node> def_arg columnElem where_clause where_or_current_clause
535 : : a_expr b_expr c_expr AexprConst indirection_el opt_slice_bound
536 : : columnref having_clause func_table xmltable array_expr
537 : : OptWhereClause operator_def_arg
538 : : %type <list> opt_column_and_period_list
539 : : %type <list> rowsfrom_item rowsfrom_list opt_col_def_list
540 : : %type <boolean> opt_ordinality opt_without_overlaps
541 : : %type <list> ExclusionConstraintList ExclusionConstraintElem
542 : : %type <list> func_arg_list func_arg_list_opt
543 : : %type <node> func_arg_expr
544 : : %type <list> row explicit_row implicit_row type_list array_expr_list
545 : : %type <node> case_expr case_arg when_clause case_default
546 : : %type <list> when_clause_list
547 : : %type <node> opt_search_clause opt_cycle_clause
548 : : %type <ival> sub_type opt_materialized
549 : : %type <node> NumericOnly
550 : : %type <list> NumericOnly_list
551 : : %type <alias> alias_clause opt_alias_clause opt_alias_clause_for_join_using
552 : : %type <list> func_alias_clause
553 : : %type <sortby> sortby
554 : : %type <ielem> index_elem index_elem_options
555 : : %type <selem> stats_param
556 : : %type <node> table_ref
557 : : %type <jexpr> joined_table
558 : : %type <range> relation_expr
559 : : %type <range> extended_relation_expr
560 : : %type <range> relation_expr_opt_alias
561 : : %type <alias> for_portion_of_opt_alias
562 : : %type <node> for_portion_of_clause
563 : : %type <node> tablesample_clause opt_repeatable_clause
564 : : %type <target> target_el set_target insert_column_item
565 : :
566 : : %type <str> generic_option_name
567 : : %type <node> generic_option_arg
568 : : %type <defelt> generic_option_elem alter_generic_option_elem
569 : : %type <list> generic_option_list alter_generic_option_list
570 : :
571 : : %type <ival> reindex_target_relation reindex_target_all
572 : :
573 : : %type <node> copy_generic_opt_arg copy_generic_opt_arg_list_item
574 : : %type <defelt> copy_generic_opt_elem
575 : : %type <list> copy_generic_opt_list copy_generic_opt_arg_list
576 : : %type <list> copy_options
577 : :
578 : : %type <typnam> Typename SimpleTypename ConstTypename
579 : : GenericType Numeric opt_float JsonType
580 : : Character ConstCharacter
581 : : CharacterWithLength CharacterWithoutLength
582 : : ConstDatetime ConstInterval
583 : : Bit ConstBit BitWithLength BitWithoutLength
584 : : %type <str> character
585 : : %type <str> extract_arg
586 : : %type <boolean> opt_varying opt_timezone opt_no_inherit
587 : :
588 : : %type <ival> Iconst SignedIconst
589 : : %type <str> Sconst comment_text notify_payload
590 : : %type <str> RoleId opt_boolean_or_string
591 : : %type <list> var_list
592 : : %type <str> ColId ColLabel BareColLabel
593 : : %type <str> NonReservedWord NonReservedWord_or_Sconst
594 : : %type <str> var_name type_function_name param_name
595 : : %type <str> createdb_opt_name plassign_target
596 : : %type <node> var_value zone_value
597 : : %type <rolespec> auth_ident RoleSpec opt_granted_by
598 : : %type <publicationobjectspec> PublicationObjSpec
599 : : %type <publicationobjectspec> PublicationExceptObjSpec
600 : : %type <publicationallobjectspec> PublicationAllObjSpec
601 : :
602 : : %type <keyword> unreserved_keyword type_func_name_keyword
603 : : %type <keyword> col_name_keyword reserved_keyword
604 : : %type <keyword> bare_label_keyword
605 : :
606 : : %type <node> DomainConstraint TableConstraint TableLikeClause
607 : : %type <ival> TableLikeOptionList TableLikeOption
608 : : %type <str> column_compression opt_column_compression column_storage opt_column_storage
609 : : %type <list> ColQualList
610 : : %type <node> ColConstraint ColConstraintElem ConstraintAttr
611 : : %type <ival> key_match
612 : : %type <keyaction> key_delete key_update key_action
613 : : %type <keyactions> key_actions
614 : : %type <ival> ConstraintAttributeSpec ConstraintAttributeElem
615 : : %type <str> ExistingIndex
616 : :
617 : : %type <list> constraints_set_list
618 : : %type <boolean> constraints_set_mode
619 : : %type <str> OptTableSpace OptConsTableSpace
620 : : %type <rolespec> OptTableSpaceOwner
621 : : %type <ival> opt_check_option
622 : :
623 : : %type <str> opt_provider security_label
624 : :
625 : : %type <target> labeled_expr
626 : : %type <list> labeled_expr_list xml_attributes
627 : : %type <node> xml_root_version opt_xml_root_standalone
628 : : %type <node> xmlexists_argument
629 : : %type <ival> document_or_content
630 : : %type <boolean> xml_indent_option xml_whitespace_option
631 : : %type <list> xmltable_column_list xmltable_column_option_list
632 : : %type <node> xmltable_column_el
633 : : %type <defelt> xmltable_column_option_el
634 : : %type <list> xml_namespace_list
635 : : %type <target> xml_namespace_el
636 : :
637 : : %type <node> func_application func_expr_common_subexpr
638 : : %type <node> func_expr func_expr_windowless
639 : : %type <node> common_table_expr
640 : : %type <with> with_clause opt_with_clause
641 : : %type <list> cte_list
642 : :
643 : : %type <list> within_group_clause
644 : : %type <node> filter_clause
645 : : %type <list> window_clause window_definition_list opt_partition_clause
646 : : %type <windef> window_definition over_clause window_specification
647 : : opt_frame_clause frame_extent frame_bound
648 : : %type <ival> null_treatment opt_window_exclusion_clause
649 : : %type <str> opt_existing_window_name
650 : : %type <boolean> opt_if_not_exists
651 : : %type <boolean> opt_unique_null_treatment
652 : : %type <ival> generated_when override_kind opt_virtual_or_stored
653 : : %type <partspec> PartitionSpec OptPartitionSpec
654 : : %type <partelem> part_elem
655 : : %type <list> part_params
656 : : %type <partboundspec> PartitionBoundSpec
657 : : %type <singlepartspec> SinglePartitionSpec
658 : : %type <list> partitions_list
659 : : %type <list> hash_partbound
660 : : %type <defelt> hash_partbound_elem
661 : :
662 : : %type <node> json_format_clause
663 : : json_format_clause_opt
664 : : json_value_expr
665 : : json_returning_clause_opt
666 : : json_name_and_value
667 : : json_aggregate_func
668 : : json_argument
669 : : json_behavior
670 : : json_on_error_clause_opt
671 : : json_table
672 : : json_table_column_definition
673 : : json_table_column_path_clause_opt
674 : : json_table_plan_clause_opt
675 : : json_table_plan
676 : : json_table_plan_simple
677 : : json_table_plan_outer
678 : : json_table_plan_inner
679 : : json_table_plan_union
680 : : json_table_plan_cross
681 : : json_table_plan_primary
682 : : %type <list> json_name_and_value_list
683 : : json_value_expr_list
684 : : json_array_aggregate_order_by_clause_opt
685 : : json_arguments
686 : : json_behavior_clause_opt
687 : : json_passing_clause_opt
688 : : json_table_column_definition_list
689 : : %type <str> json_table_path_name_opt
690 : : %type <ival> json_behavior_type
691 : : json_predicate_type_constraint
692 : : json_quotes_clause_opt
693 : : json_table_default_plan_choices
694 : : json_table_default_plan_inner_outer
695 : : json_table_default_plan_union_cross
696 : : json_wrapper_behavior
697 : : %type <boolean> json_key_uniqueness_constraint_opt
698 : : json_object_constructor_null_clause_opt
699 : : json_array_constructor_null_clause_opt
700 : :
701 : : %type <list> vertex_tables_clause edge_tables_clause
702 : : opt_vertex_tables_clause opt_edge_tables_clause
703 : : vertex_table_list
704 : : opt_graph_table_key_clause
705 : : edge_table_list
706 : : source_vertex_table destination_vertex_table
707 : : opt_element_table_label_and_properties
708 : : label_and_properties_list
709 : : add_label_list
710 : : %type <node> vertex_table_definition edge_table_definition
711 : : %type <alias> opt_propgraph_table_alias
712 : : %type <str> element_table_label_clause
713 : : %type <node> label_and_properties element_table_properties
714 : : add_label
715 : : %type <ival> vertex_or_edge
716 : :
717 : : %type <list> opt_graph_pattern_quantifier
718 : : path_pattern_list
719 : : path_pattern
720 : : path_pattern_expression
721 : : path_term
722 : : %type <node> graph_pattern
723 : : path_factor
724 : : path_primary
725 : : opt_is_label_expression
726 : : label_expression
727 : : label_disjunction
728 : : label_term
729 : : %type <str> opt_colid
730 : :
731 : : /*
732 : : * Non-keyword token types. These are hard-wired into the "flex" lexer.
733 : : * They must be listed first so that their numeric codes do not depend on
734 : : * the set of keywords. PL/pgSQL depends on this so that it can share the
735 : : * same lexer. If you add/change tokens here, fix PL/pgSQL to match!
736 : : *
737 : : * UIDENT and USCONST are reduced to IDENT and SCONST in parser.c, so that
738 : : * they need no productions here; but we must assign token codes to them.
739 : : *
740 : : * DOT_DOT is unused in the core SQL grammar, and so will always provoke
741 : : * parse errors. It is needed by PL/pgSQL.
742 : : */
743 : : %token <str> IDENT UIDENT FCONST SCONST USCONST BCONST XCONST Op
744 : : %token <ival> ICONST PARAM
745 : : %token TYPECAST DOT_DOT COLON_EQUALS EQUALS_GREATER
746 : : %token LESS_EQUALS GREATER_EQUALS NOT_EQUALS
747 : :
748 : : /*
749 : : * If you want to make any keyword changes, update the keyword table in
750 : : * src/include/parser/kwlist.h and add new keywords to the appropriate one
751 : : * of the reserved-or-not-so-reserved keyword lists, below; search
752 : : * this file for "Keyword category lists".
753 : : */
754 : :
755 : : /* ordinary key words in alphabetical order */
756 : : %token <keyword> ABORT_P ABSENT ABSOLUTE_P ACCESS ACTION ADD_P ADMIN AFTER
757 : : AGGREGATE ALL ALSO ALTER ALWAYS ANALYSE ANALYZE AND ANY ARRAY AS ASC
758 : : ASENSITIVE ASSERTION ASSIGNMENT ASYMMETRIC ATOMIC AT ATTACH ATTRIBUTE AUTHORIZATION
759 : :
760 : : BACKWARD BEFORE BEGIN_P BETWEEN BIGINT BINARY BIT
761 : : BOOLEAN_P BOTH BREADTH BY
762 : :
763 : : CACHE CALL CALLED CASCADE CASCADED CASE CAST CATALOG_P CHAIN CHAR_P
764 : : CHARACTER CHARACTERISTICS CHECK CHECKPOINT CLASS CLOSE
765 : : CLUSTER COALESCE COLLATE COLLATION COLUMN COLUMNS COMMENT COMMENTS COMMIT
766 : : COMMITTED COMPRESSION CONCURRENTLY CONDITIONAL CONFIGURATION CONFLICT
767 : : CONNECTION CONSTRAINT CONSTRAINTS CONTENT_P CONTINUE_P CONVERSION_P COPY
768 : : COST CREATE CROSS CSV CUBE CURRENT_P
769 : : CURRENT_CATALOG CURRENT_DATE CURRENT_ROLE CURRENT_SCHEMA
770 : : CURRENT_TIME CURRENT_TIMESTAMP CURRENT_USER CURSOR CYCLE
771 : :
772 : : DATA_P DATABASE DAY_P DEALLOCATE DEC DECIMAL_P DECLARE DEFAULT DEFAULTS
773 : : DEFERRABLE DEFERRED DEFINER DELETE_P DELIMITER DELIMITERS DEPENDS DEPTH DESC DESTINATION
774 : : DETACH DICTIONARY DISABLE_P DISCARD DISTINCT DO DOCUMENT_P DOMAIN_P
775 : : DOUBLE_P DROP
776 : :
777 : : EACH EDGE ELSE EMPTY_P ENABLE_P ENCODING ENCRYPTED END_P ENFORCED ENUM_P
778 : : ERROR_P ESCAPE EVENT EXCEPT EXCLUDE EXCLUDING EXCLUSIVE EXECUTE EXISTS
779 : : EXPLAIN EXPRESSION EXTENSION EXTERNAL EXTRACT
780 : :
781 : : FALSE_P FAMILY FETCH FILTER FINALIZE FIRST_P FLOAT_P FOLLOWING FOR
782 : : FORCE FOREIGN FORMAT FORWARD FREEZE FROM FULL FUNCTION FUNCTIONS
783 : :
784 : : GENERATED GLOBAL GRANT GRANTED GRAPH GRAPH_TABLE GREATEST GROUP_P GROUPING GROUPS
785 : :
786 : : HANDLER HAVING HEADER_P HOLD HOUR_P
787 : :
788 : : IDENTITY_P IF_P IGNORE_P ILIKE IMMEDIATE IMMUTABLE IMPLICIT_P IMPORT_P IN_P INCLUDE
789 : : INCLUDING INCREMENT INDENT INDEX INDEXES INHERIT INHERITS INITIALLY INLINE_P
790 : : INNER_P INOUT INPUT_P INSENSITIVE INSERT INSTEAD INT_P INTEGER
791 : : INTERSECT INTERVAL INTO INVOKER IS ISNULL ISOLATION
792 : :
793 : : JOIN JSON JSON_ARRAY JSON_ARRAYAGG JSON_EXISTS JSON_OBJECT JSON_OBJECTAGG
794 : : JSON_QUERY JSON_SCALAR JSON_SERIALIZE JSON_TABLE JSON_VALUE
795 : :
796 : : KEEP KEY KEYS
797 : :
798 : : LABEL LANGUAGE LARGE_P LAST_P LATERAL_P
799 : : LEADING LEAKPROOF LEAST LEFT LEVEL LIKE LIMIT LISTEN LOAD LOCAL
800 : : LOCALTIME LOCALTIMESTAMP LOCATION LOCK_P LOCKED LOGGED LSN_P
801 : :
802 : : MAPPING MATCH MATCHED MATERIALIZED MAXVALUE MERGE MERGE_ACTION METHOD
803 : : MINUTE_P MINVALUE MODE MONTH_P MOVE
804 : :
805 : : NAME_P NAMES NATIONAL NATURAL NCHAR NESTED NEW NEXT NFC NFD NFKC NFKD NO NODE
806 : : NONE NORMALIZE NORMALIZED
807 : : NOT NOTHING NOTIFY NOTNULL NOWAIT NULL_P NULLIF
808 : : NULLS_P NUMERIC
809 : :
810 : : OBJECT_P OBJECTS_P OF OFF OFFSET OIDS OLD OMIT ON ONLY OPERATOR OPTION OPTIONS OR
811 : : ORDER ORDINALITY OTHERS OUT_P OUTER_P
812 : : OVER OVERLAPS OVERLAY OVERRIDING OWNED OWNER
813 : :
814 : : PARALLEL PARAMETER PARSER PARTIAL PARTITION PARTITIONS PASSING PASSWORD PATH
815 : : PERIOD PLACING PLAN PLANS POLICY PORTION
816 : : POSITION PRECEDING PRECISION PRESERVE PREPARE PREPARED PRIMARY
817 : : PRIOR PRIVILEGES PROCEDURAL PROCEDURE PROCEDURES PROGRAM PROPERTIES PROPERTY PUBLICATION
818 : :
819 : : QUOTE QUOTES
820 : :
821 : : RANGE READ REAL REASSIGN RECURSIVE REF_P REFERENCES REFERENCING
822 : : REFRESH REINDEX RELATIONSHIP RELATIVE_P RELEASE RENAME REPACK REPEATABLE REPLACE REPLICA
823 : : RESET RESPECT_P RESTART RESTRICT RETURN RETURNING RETURNS REVOKE RIGHT ROLE ROLLBACK ROLLUP
824 : : ROUTINE ROUTINES ROW ROWS RULE
825 : :
826 : : SAVEPOINT SCALAR SCHEMA SCHEMAS SCROLL SEARCH SECOND_P SECURITY SELECT
827 : : SEQUENCE SEQUENCES
828 : : SERIALIZABLE SERVER SESSION SESSION_USER SET SETS SETOF SHARE SHOW
829 : : SIMILAR SIMPLE SKIP SMALLINT SNAPSHOT SOME SPLIT SOURCE SQL_P STABLE STANDALONE_P
830 : : START STATEMENT STATISTICS STDIN STDOUT STORAGE STORED STRICT_P STRING_P STRIP_P
831 : : SUBSCRIPTION SUBSTRING SUPPORT SYMMETRIC SYSID SYSTEM_P SYSTEM_USER
832 : :
833 : : TABLE TABLES TABLESAMPLE TABLESPACE TARGET TEMP TEMPLATE TEMPORARY TEXT_P THEN
834 : : TIES TIME TIMESTAMP TO TRAILING TRANSACTION TRANSFORM
835 : : TREAT TRIGGER TRIM TRUE_P
836 : : TRUNCATE TRUSTED TYPE_P TYPES_P
837 : :
838 : : UESCAPE UNBOUNDED UNCONDITIONAL UNCOMMITTED UNENCRYPTED UNION UNIQUE UNKNOWN
839 : : UNLISTEN UNLOGGED UNTIL UPDATE USER USING
840 : :
841 : : VACUUM VALID VALIDATE VALIDATOR VALUE_P VALUES VARCHAR VARIADIC VARYING
842 : : VERBOSE VERSION_P VERTEX VIEW VIEWS VIRTUAL VOLATILE
843 : :
844 : : WAIT WHEN WHERE WHITESPACE_P WINDOW WITH WITHIN WITHOUT WORK WRAPPER WRITE
845 : :
846 : : XML_P XMLATTRIBUTES XMLCONCAT XMLELEMENT XMLEXISTS XMLFOREST XMLNAMESPACES
847 : : XMLPARSE XMLPI XMLROOT XMLSERIALIZE XMLTABLE
848 : :
849 : : YEAR_P YES_P
850 : :
851 : : ZONE
852 : :
853 : : /*
854 : : * The grammar thinks these are keywords, but they are not in the kwlist.h
855 : : * list and so can never be entered directly. The filter in parser.c
856 : : * creates these tokens when required (based on looking one token ahead).
857 : : *
858 : : * NOT_LA exists so that productions such as NOT LIKE can be given the same
859 : : * precedence as LIKE; otherwise they'd effectively have the same precedence
860 : : * as NOT, at least with respect to their left-hand subexpression.
861 : : * FORMAT_LA, NULLS_LA, WITH_LA, and WITHOUT_LA are needed to make the grammar
862 : : * LALR(1).
863 : : */
864 : : %token FORMAT_LA NOT_LA NULLS_LA WITH_LA WITHOUT_LA
865 : :
866 : : /*
867 : : * The grammar likewise thinks these tokens are keywords, but they are never
868 : : * generated by the scanner. Rather, they can be injected by parser.c as
869 : : * the initial token of the string (using the lookahead-token mechanism
870 : : * implemented there). This provides a way to tell the grammar to parse
871 : : * something other than the usual list of SQL commands.
872 : : */
873 : : %token MODE_TYPE_NAME
874 : : %token MODE_PLPGSQL_EXPR
875 : : %token MODE_PLPGSQL_ASSIGN1
876 : : %token MODE_PLPGSQL_ASSIGN2
877 : : %token MODE_PLPGSQL_ASSIGN3
878 : :
879 : :
880 : : /* Precedence: lowest to highest */
881 : : %left UNION EXCEPT
882 : : %left INTERSECT
883 : : %left OR
884 : : %left AND
885 : : %right NOT
886 : : %nonassoc IS ISNULL NOTNULL /* IS sets precedence for IS NULL, etc */
887 : : %nonassoc '<' '>' '=' LESS_EQUALS GREATER_EQUALS NOT_EQUALS
888 : : %nonassoc BETWEEN IN_P LIKE ILIKE SIMILAR NOT_LA
889 : : %nonassoc ESCAPE /* ESCAPE must be just above LIKE/ILIKE/SIMILAR */
890 : :
891 : : /*
892 : : * Sometimes it is necessary to assign precedence to keywords that are not
893 : : * really part of the operator hierarchy, in order to resolve grammar
894 : : * ambiguities. It's best to avoid doing so whenever possible, because such
895 : : * assignments have global effect and may hide ambiguities besides the one
896 : : * you intended to solve. (Attaching a precedence to a single rule with
897 : : * %prec is far safer and should be preferred.) If you must give precedence
898 : : * to a new keyword, try very hard to give it the same precedence as IDENT.
899 : : * If the keyword has IDENT's precedence then it clearly acts the same as
900 : : * non-keywords and other similar keywords, thus reducing the risk of
901 : : * unexpected precedence effects.
902 : : *
903 : : * We used to need to assign IDENT an explicit precedence just less than Op,
904 : : * to support target_el without AS. While that's not really necessary since
905 : : * we removed postfix operators, we continue to do so because it provides a
906 : : * reference point for a precedence level that we can assign to other
907 : : * keywords that lack a natural precedence level.
908 : : *
909 : : * We need to do this for PARTITION, RANGE, ROWS, and GROUPS to support
910 : : * opt_existing_window_name (see comment there).
911 : : *
912 : : * The frame_bound productions UNBOUNDED PRECEDING and UNBOUNDED FOLLOWING
913 : : * are even messier: since UNBOUNDED is an unreserved keyword (per spec!),
914 : : * there is no principled way to distinguish these from the productions
915 : : * a_expr PRECEDING/FOLLOWING. We hack this up by giving UNBOUNDED slightly
916 : : * lower precedence than PRECEDING and FOLLOWING. At present this doesn't
917 : : * appear to cause UNBOUNDED to be treated differently from other unreserved
918 : : * keywords anywhere else in the grammar, but it's definitely risky. We can
919 : : * blame any funny behavior of UNBOUNDED on the SQL standard, though.
920 : : *
921 : : * To support CUBE and ROLLUP in GROUP BY without reserving them, we give them
922 : : * an explicit priority lower than '(', so that a rule with CUBE '(' will shift
923 : : * rather than reducing a conflicting rule that takes CUBE as a function name.
924 : : * Using the same precedence as IDENT seems right for the reasons given above.
925 : : *
926 : : * SET is likewise assigned the same precedence as IDENT, to support the
927 : : * relation_expr_opt_alias production (see comment there).
928 : : *
929 : : * KEYS, OBJECT_P, SCALAR, VALUE_P, WITH, and WITHOUT are similarly assigned
930 : : * the same precedence as IDENT. This allows resolving conflicts in the
931 : : * json_predicate_type_constraint and json_key_uniqueness_constraint_opt
932 : : * productions (see comments there).
933 : : *
934 : : * TO is assigned the same precedence as IDENT, to support the opt_interval
935 : : * production (see comment there).
936 : : *
937 : : * Like the UNBOUNDED PRECEDING/FOLLOWING case, NESTED is assigned a lower
938 : : * precedence than PATH to fix ambiguity in the json_table production.
939 : : */
940 : : %nonassoc UNBOUNDED NESTED /* ideally would have same precedence as IDENT */
941 : : %nonassoc IDENT PARTITION RANGE ROWS GROUPS PRECEDING FOLLOWING CUBE ROLLUP
942 : : SET KEYS OBJECT_P SCALAR TO USING VALUE_P WITH WITHOUT PATH
943 : : %left Op OPERATOR RIGHT_ARROW '|' /* multi-character ops and user-defined operators */
944 : : %left '+' '-'
945 : : %left '*' '/' '%'
946 : : %left '^'
947 : : /* Unary Operators */
948 : : %left AT /* sets precedence for AT TIME ZONE, AT LOCAL */
949 : : %left COLLATE
950 : : %right UMINUS
951 : : %left '[' ']'
952 : : %left '(' ')'
953 : : %left TYPECAST
954 : : %left '.'
955 : : /*
956 : : * These might seem to be low-precedence, but actually they are not part
957 : : * of the arithmetic hierarchy at all in their use as JOIN operators.
958 : : * We make them high-precedence to support their use as function names.
959 : : * They wouldn't be given a precedence at all, were it not that we need
960 : : * left-associativity among the JOIN rules themselves.
961 : : */
962 : : %left JOIN CROSS LEFT FULL RIGHT INNER_P NATURAL
963 : :
964 : : %%
965 : :
966 : : /*
967 : : * The target production for the whole parse.
968 : : *
969 : : * Ordinarily we parse a list of statements, but if we see one of the
970 : : * special MODE_XXX symbols as first token, we parse something else.
971 : : * The options here correspond to enum RawParseMode, which see for details.
972 : : */
973 : : parse_toplevel:
974 : : stmtmulti
975 : : {
976 : 468328 : pg_yyget_extra(yyscanner)->parsetree = $1;
977 : : (void) yynerrs; /* suppress compiler warning */
978 : : }
979 : : | MODE_TYPE_NAME Typename
980 : : {
981 : 6402 : pg_yyget_extra(yyscanner)->parsetree = list_make1($2);
982 : : }
983 : : | MODE_PLPGSQL_EXPR PLpgSQL_Expr
984 : : {
985 : 21732 : pg_yyget_extra(yyscanner)->parsetree =
986 : 21732 : list_make1(makeRawStmt($2, @2));
987 : : }
988 : : | MODE_PLPGSQL_ASSIGN1 PLAssignStmt
989 : : {
990 : 3813 : PLAssignStmt *n = (PLAssignStmt *) $2;
991 : :
992 : 3813 : n->nnames = 1;
993 : 3813 : pg_yyget_extra(yyscanner)->parsetree =
994 : 3813 : list_make1(makeRawStmt((Node *) n, @2));
995 : : }
996 : : | MODE_PLPGSQL_ASSIGN2 PLAssignStmt
997 : : {
998 : 439 : PLAssignStmt *n = (PLAssignStmt *) $2;
999 : :
1000 : 439 : n->nnames = 2;
1001 : 439 : pg_yyget_extra(yyscanner)->parsetree =
1002 : 439 : list_make1(makeRawStmt((Node *) n, @2));
1003 : : }
1004 : : | MODE_PLPGSQL_ASSIGN3 PLAssignStmt
1005 : : {
1006 : 14 : PLAssignStmt *n = (PLAssignStmt *) $2;
1007 : :
1008 : 14 : n->nnames = 3;
1009 : 14 : pg_yyget_extra(yyscanner)->parsetree =
1010 : 14 : list_make1(makeRawStmt((Node *) n, @2));
1011 : : }
1012 : : ;
1013 : :
1014 : : /*
1015 : : * At top level, we wrap each stmt with a RawStmt node carrying start location
1016 : : * and length of the stmt's text.
1017 : : * We also take care to discard empty statements entirely (which among other
1018 : : * things dodges the problem of assigning them a location).
1019 : : */
1020 : : stmtmulti: stmtmulti ';' toplevel_stmt
1021 : : {
1022 [ + + ]: 393106 : if ($1 != NIL)
1023 : : {
1024 : : /* update length of previous stmt */
1025 : 392462 : updateRawStmtEnd(llast_node(RawStmt, $1), @2);
1026 : : }
1027 [ + + ]: 393106 : if ($3 != NULL)
1028 : 31236 : $$ = lappend($1, makeRawStmt($3, @3));
1029 : : else
1030 : 361870 : $$ = $1;
1031 : : }
1032 : : | toplevel_stmt
1033 : : {
1034 [ + + ]: 468333 : if ($1 != NULL)
1035 : 467252 : $$ = list_make1(makeRawStmt($1, @1));
1036 : : else
1037 : 1081 : $$ = NIL;
1038 : : }
1039 : : ;
1040 : :
1041 : : /*
1042 : : * toplevel_stmt includes BEGIN and END. stmt does not include them, because
1043 : : * those words have different meanings in function bodies.
1044 : : */
1045 : : toplevel_stmt:
1046 : : stmt
1047 : : | TransactionStmtLegacy
1048 : : ;
1049 : :
1050 : : stmt:
1051 : : AlterEventTrigStmt
1052 : : | AlterCollationStmt
1053 : : | AlterDatabaseStmt
1054 : : | AlterDatabaseSetStmt
1055 : : | AlterDefaultPrivilegesStmt
1056 : : | AlterDomainStmt
1057 : : | AlterEnumStmt
1058 : : | AlterExtensionStmt
1059 : : | AlterExtensionContentsStmt
1060 : : | AlterFdwStmt
1061 : : | AlterForeignServerStmt
1062 : : | AlterFunctionStmt
1063 : : | AlterGroupStmt
1064 : : | AlterObjectDependsStmt
1065 : : | AlterObjectSchemaStmt
1066 : : | AlterOwnerStmt
1067 : : | AlterOperatorStmt
1068 : : | AlterTypeStmt
1069 : : | AlterPolicyStmt
1070 : : | AlterPropGraphStmt
1071 : : | AlterSeqStmt
1072 : : | AlterSystemStmt
1073 : : | AlterTableStmt
1074 : : | AlterTblSpcStmt
1075 : : | AlterCompositeTypeStmt
1076 : : | AlterPublicationStmt
1077 : : | AlterRoleSetStmt
1078 : : | AlterRoleStmt
1079 : : | AlterSubscriptionStmt
1080 : : | AlterStatsStmt
1081 : : | AlterTSConfigurationStmt
1082 : : | AlterTSDictionaryStmt
1083 : : | AlterUserMappingStmt
1084 : : | AnalyzeStmt
1085 : : | CallStmt
1086 : : | CheckPointStmt
1087 : : | ClosePortalStmt
1088 : : | CommentStmt
1089 : : | ConstraintsSetStmt
1090 : : | CopyStmt
1091 : : | CreateAmStmt
1092 : : | CreateAsStmt
1093 : : | CreateAssertionStmt
1094 : : | CreateCastStmt
1095 : : | CreateConversionStmt
1096 : : | CreateDomainStmt
1097 : : | CreateExtensionStmt
1098 : : | CreateFdwStmt
1099 : : | CreateForeignServerStmt
1100 : : | CreateForeignTableStmt
1101 : : | CreateFunctionStmt
1102 : : | CreateGroupStmt
1103 : : | CreateMatViewStmt
1104 : : | CreateOpClassStmt
1105 : : | CreateOpFamilyStmt
1106 : : | CreatePublicationStmt
1107 : : | AlterOpFamilyStmt
1108 : : | CreatePolicyStmt
1109 : : | CreatePLangStmt
1110 : : | CreatePropGraphStmt
1111 : : | CreateSchemaStmt
1112 : : | CreateSeqStmt
1113 : : | CreateStmt
1114 : : | CreateSubscriptionStmt
1115 : : | CreateStatsStmt
1116 : : | CreateTableSpaceStmt
1117 : : | CreateTransformStmt
1118 : : | CreateTrigStmt
1119 : : | CreateEventTrigStmt
1120 : : | CreateRoleStmt
1121 : : | CreateUserStmt
1122 : : | CreateUserMappingStmt
1123 : : | CreatedbStmt
1124 : : | DeallocateStmt
1125 : : | DeclareCursorStmt
1126 : : | DefineStmt
1127 : : | DeleteStmt
1128 : : | DiscardStmt
1129 : : | DoStmt
1130 : : | DropCastStmt
1131 : : | DropOpClassStmt
1132 : : | DropOpFamilyStmt
1133 : : | DropOwnedStmt
1134 : : | DropStmt
1135 : : | DropSubscriptionStmt
1136 : : | DropTableSpaceStmt
1137 : : | DropTransformStmt
1138 : : | DropRoleStmt
1139 : : | DropUserMappingStmt
1140 : : | DropdbStmt
1141 : : | ExecuteStmt
1142 : : | ExplainStmt
1143 : : | FetchStmt
1144 : : | GrantStmt
1145 : : | GrantRoleStmt
1146 : : | ImportForeignSchemaStmt
1147 : : | IndexStmt
1148 : : | InsertStmt
1149 : : | ListenStmt
1150 : : | RefreshMatViewStmt
1151 : : | LoadStmt
1152 : : | LockStmt
1153 : : | MergeStmt
1154 : : | NotifyStmt
1155 : : | PrepareStmt
1156 : : | ReassignOwnedStmt
1157 : : | ReindexStmt
1158 : : | RemoveAggrStmt
1159 : : | RemoveFuncStmt
1160 : : | RemoveOperStmt
1161 : : | RenameStmt
1162 : : | RepackStmt
1163 : : | RevokeStmt
1164 : : | RevokeRoleStmt
1165 : : | RuleStmt
1166 : : | SecLabelStmt
1167 : : | SelectStmt
1168 : : | TransactionStmt
1169 : : | TruncateStmt
1170 : : | UnlistenStmt
1171 : : | UpdateStmt
1172 : : | VacuumStmt
1173 : : | VariableResetStmt
1174 : : | VariableSetStmt
1175 : : | VariableShowStmt
1176 : : | ViewStmt
1177 : : | WaitStmt
1178 : : | /*EMPTY*/
1179 : 362963 : { $$ = NULL; }
1180 : : ;
1181 : :
1182 : : /*
1183 : : * Generic supporting productions for DDL
1184 : : */
1185 : : opt_single_name:
1186 : 3480 : ColId { $$ = $1; }
1187 : 1220 : | /* EMPTY */ { $$ = NULL; }
1188 : : ;
1189 : :
1190 : : opt_qualified_name:
1191 : 1389 : any_name { $$ = $1; }
1192 : 10935 : | /*EMPTY*/ { $$ = NIL; }
1193 : : ;
1194 : :
1195 : : opt_concurrently:
1196 : 673 : CONCURRENTLY { $$ = true; }
1197 : 5152 : | /*EMPTY*/ { $$ = false; }
1198 : : ;
1199 : :
1200 : : opt_usingindex:
1201 : 4 : USING INDEX { $$ = true; }
1202 : 36 : | /* EMPTY */ { $$ = false; }
1203 : : ;
1204 : :
1205 : : opt_drop_behavior:
1206 : 1415 : CASCADE { $$ = DROP_CASCADE; }
1207 : 111 : | RESTRICT { $$ = DROP_RESTRICT; }
1208 : 22511 : | /* EMPTY */ { $$ = DROP_RESTRICT; /* default */ }
1209 : : ;
1210 : :
1211 : : opt_utility_option_list:
1212 : 247 : '(' utility_option_list ')' { $$ = $2; }
1213 : 3835 : | /* EMPTY */ { $$ = NULL; }
1214 : : ;
1215 : :
1216 : : utility_option_list:
1217 : : utility_option_elem
1218 : : {
1219 : 15899 : $$ = list_make1($1);
1220 : : }
1221 : : | utility_option_list ',' utility_option_elem
1222 : : {
1223 : 9133 : $$ = lappend($1, $3);
1224 : : }
1225 : : ;
1226 : :
1227 : : utility_option_elem:
1228 : : utility_option_name utility_option_arg
1229 : : {
1230 : 25032 : $$ = makeDefElem($1, $2, @1);
1231 : : }
1232 : : ;
1233 : :
1234 : : utility_option_name:
1235 : 22512 : NonReservedWord { $$ = $1; }
1236 : 2430 : | analyze_keyword { $$ = "analyze"; }
1237 : 94 : | FORMAT_LA { $$ = "format"; }
1238 : : ;
1239 : :
1240 : : utility_option_arg:
1241 : 13212 : opt_boolean_or_string { $$ = (Node *) makeString($1); }
1242 : 220 : | NumericOnly { $$ = (Node *) $1; }
1243 : 11600 : | /* EMPTY */ { $$ = NULL; }
1244 : : ;
1245 : :
1246 : : /*****************************************************************************
1247 : : *
1248 : : * CALL statement
1249 : : *
1250 : : *****************************************************************************/
1251 : :
1252 : : CallStmt: CALL func_application
1253 : : {
1254 : 362 : CallStmt *n = makeNode(CallStmt);
1255 : :
1256 : 362 : n->funccall = castNode(FuncCall, $2);
1257 : 362 : $$ = (Node *) n;
1258 : : }
1259 : : ;
1260 : :
1261 : : /*****************************************************************************
1262 : : *
1263 : : * Create a new Postgres DBMS role
1264 : : *
1265 : : *****************************************************************************/
1266 : :
1267 : : CreateRoleStmt:
1268 : : CREATE ROLE RoleId opt_with OptRoleList
1269 : : {
1270 : 963 : CreateRoleStmt *n = makeNode(CreateRoleStmt);
1271 : :
1272 : 963 : n->stmt_type = ROLESTMT_ROLE;
1273 : 963 : n->role = $3;
1274 : 963 : n->options = $5;
1275 : 963 : $$ = (Node *) n;
1276 : : }
1277 : : ;
1278 : :
1279 : :
1280 : : opt_with: WITH
1281 : : | WITH_LA
1282 : : | /*EMPTY*/
1283 : : ;
1284 : :
1285 : : /*
1286 : : * Options for CREATE ROLE and ALTER ROLE (also used by CREATE/ALTER USER
1287 : : * for backwards compatibility). Note: the only option required by SQL99
1288 : : * is "WITH ADMIN name".
1289 : : */
1290 : : OptRoleList:
1291 : 772 : OptRoleList CreateOptRoleElem { $$ = lappend($1, $2); }
1292 : 1302 : | /* EMPTY */ { $$ = NIL; }
1293 : : ;
1294 : :
1295 : : AlterOptRoleList:
1296 : 446 : AlterOptRoleList AlterOptRoleElem { $$ = lappend($1, $2); }
1297 : 262 : | /* EMPTY */ { $$ = NIL; }
1298 : : ;
1299 : :
1300 : : AlterOptRoleElem:
1301 : : PASSWORD Sconst
1302 : : {
1303 : 119 : $$ = makeDefElem("password",
1304 : 119 : (Node *) makeString($2), @1);
1305 : : }
1306 : : | PASSWORD NULL_P
1307 : : {
1308 : 8 : $$ = makeDefElem("password", NULL, @1);
1309 : : }
1310 : : | ENCRYPTED PASSWORD Sconst
1311 : : {
1312 : : /*
1313 : : * These days, passwords are always stored in encrypted
1314 : : * form, so there is no difference between PASSWORD and
1315 : : * ENCRYPTED PASSWORD.
1316 : : */
1317 : 9 : $$ = makeDefElem("password",
1318 : 9 : (Node *) makeString($3), @1);
1319 : : }
1320 : : | UNENCRYPTED PASSWORD Sconst
1321 : : {
1322 [ # # ]: 0 : ereport(ERROR,
1323 : : (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
1324 : : errmsg("UNENCRYPTED PASSWORD is no longer supported"),
1325 : : errhint("Remove UNENCRYPTED to store the password in encrypted form instead."),
1326 : : parser_errposition(@1)));
1327 : : }
1328 : : | INHERIT
1329 : : {
1330 : 61 : $$ = makeDefElem("inherit", (Node *) makeBoolean(true), @1);
1331 : : }
1332 : : | CONNECTION LIMIT SignedIconst
1333 : : {
1334 : 17 : $$ = makeDefElem("connectionlimit", (Node *) makeInteger($3), @1);
1335 : : }
1336 : : | VALID UNTIL Sconst
1337 : : {
1338 : 5 : $$ = makeDefElem("validUntil", (Node *) makeString($3), @1);
1339 : : }
1340 : : /* Supported but not documented for roles, for use by ALTER GROUP. */
1341 : : | USER role_list
1342 : : {
1343 : 4 : $$ = makeDefElem("rolemembers", (Node *) $2, @1);
1344 : : }
1345 : : | IDENT
1346 : : {
1347 : : /*
1348 : : * We handle identifiers that aren't parser keywords with
1349 : : * the following special-case codes, to avoid bloating the
1350 : : * size of the main parser.
1351 : : */
1352 [ + + ]: 886 : if (strcmp($1, "superuser") == 0)
1353 : 114 : $$ = makeDefElem("superuser", (Node *) makeBoolean(true), @1);
1354 [ + + ]: 772 : else if (strcmp($1, "nosuperuser") == 0)
1355 : 65 : $$ = makeDefElem("superuser", (Node *) makeBoolean(false), @1);
1356 [ + + ]: 707 : else if (strcmp($1, "createrole") == 0)
1357 : 63 : $$ = makeDefElem("createrole", (Node *) makeBoolean(true), @1);
1358 [ + + ]: 644 : else if (strcmp($1, "nocreaterole") == 0)
1359 : 29 : $$ = makeDefElem("createrole", (Node *) makeBoolean(false), @1);
1360 [ + + ]: 615 : else if (strcmp($1, "replication") == 0)
1361 : 77 : $$ = makeDefElem("isreplication", (Node *) makeBoolean(true), @1);
1362 [ + + ]: 538 : else if (strcmp($1, "noreplication") == 0)
1363 : 58 : $$ = makeDefElem("isreplication", (Node *) makeBoolean(false), @1);
1364 [ + + ]: 480 : else if (strcmp($1, "createdb") == 0)
1365 : 56 : $$ = makeDefElem("createdb", (Node *) makeBoolean(true), @1);
1366 [ + + ]: 424 : else if (strcmp($1, "nocreatedb") == 0)
1367 : 34 : $$ = makeDefElem("createdb", (Node *) makeBoolean(false), @1);
1368 [ + + ]: 390 : else if (strcmp($1, "login") == 0)
1369 : 165 : $$ = makeDefElem("canlogin", (Node *) makeBoolean(true), @1);
1370 [ + + ]: 225 : else if (strcmp($1, "nologin") == 0)
1371 : 100 : $$ = makeDefElem("canlogin", (Node *) makeBoolean(false), @1);
1372 [ + + ]: 125 : else if (strcmp($1, "bypassrls") == 0)
1373 : 57 : $$ = makeDefElem("bypassrls", (Node *) makeBoolean(true), @1);
1374 [ + + ]: 68 : else if (strcmp($1, "nobypassrls") == 0)
1375 : 44 : $$ = makeDefElem("bypassrls", (Node *) makeBoolean(false), @1);
1376 [ + - ]: 24 : else if (strcmp($1, "noinherit") == 0)
1377 : : {
1378 : : /*
1379 : : * Note that INHERIT is a keyword, so it's handled by main parser, but
1380 : : * NOINHERIT is handled here.
1381 : : */
1382 : 24 : $$ = makeDefElem("inherit", (Node *) makeBoolean(false), @1);
1383 : : }
1384 : : else
1385 [ # # ]: 0 : ereport(ERROR,
1386 : : (errcode(ERRCODE_SYNTAX_ERROR),
1387 : : errmsg("unrecognized role option \"%s\"", $1),
1388 : : parser_errposition(@1)));
1389 : : }
1390 : : ;
1391 : :
1392 : : CreateOptRoleElem:
1393 : 663 : AlterOptRoleElem { $$ = $1; }
1394 : : /* The following are not supported by ALTER ROLE/USER/GROUP */
1395 : : | SYSID Iconst
1396 : : {
1397 : 4 : $$ = makeDefElem("sysid", (Node *) makeInteger($2), @1);
1398 : : }
1399 : : | ADMIN role_list
1400 : : {
1401 : 14 : $$ = makeDefElem("adminmembers", (Node *) $2, @1);
1402 : : }
1403 : : | ROLE role_list
1404 : : {
1405 : 26 : $$ = makeDefElem("rolemembers", (Node *) $2, @1);
1406 : : }
1407 : : | IN_P ROLE role_list
1408 : : {
1409 : 65 : $$ = makeDefElem("addroleto", (Node *) $3, @1);
1410 : : }
1411 : : | IN_P GROUP_P role_list
1412 : : {
1413 : 0 : $$ = makeDefElem("addroleto", (Node *) $3, @1);
1414 : : }
1415 : : ;
1416 : :
1417 : :
1418 : : /*****************************************************************************
1419 : : *
1420 : : * Create a new Postgres DBMS user (role with implied login ability)
1421 : : *
1422 : : *****************************************************************************/
1423 : :
1424 : : CreateUserStmt:
1425 : : CREATE USER RoleId opt_with OptRoleList
1426 : : {
1427 : 323 : CreateRoleStmt *n = makeNode(CreateRoleStmt);
1428 : :
1429 : 323 : n->stmt_type = ROLESTMT_USER;
1430 : 323 : n->role = $3;
1431 : 323 : n->options = $5;
1432 : 323 : $$ = (Node *) n;
1433 : : }
1434 : : ;
1435 : :
1436 : :
1437 : : /*****************************************************************************
1438 : : *
1439 : : * Alter a postgresql DBMS role
1440 : : *
1441 : : *****************************************************************************/
1442 : :
1443 : : AlterRoleStmt:
1444 : : ALTER ROLE RoleSpec opt_with AlterOptRoleList
1445 : : {
1446 : 213 : AlterRoleStmt *n = makeNode(AlterRoleStmt);
1447 : :
1448 : 213 : n->role = $3;
1449 : 213 : n->action = +1; /* add, if there are members */
1450 : 213 : n->options = $5;
1451 : 213 : $$ = (Node *) n;
1452 : : }
1453 : : | ALTER USER RoleSpec opt_with AlterOptRoleList
1454 : : {
1455 : 49 : AlterRoleStmt *n = makeNode(AlterRoleStmt);
1456 : :
1457 : 49 : n->role = $3;
1458 : 49 : n->action = +1; /* add, if there are members */
1459 : 49 : n->options = $5;
1460 : 49 : $$ = (Node *) n;
1461 : : }
1462 : : ;
1463 : :
1464 : : opt_in_database:
1465 : 50 : /* EMPTY */ { $$ = NULL; }
1466 : 4 : | IN_P DATABASE name { $$ = $3; }
1467 : : ;
1468 : :
1469 : : AlterRoleSetStmt:
1470 : : ALTER ROLE RoleSpec opt_in_database SetResetClause
1471 : : {
1472 : 34 : AlterRoleSetStmt *n = makeNode(AlterRoleSetStmt);
1473 : :
1474 : 34 : n->role = $3;
1475 : 34 : n->database = $4;
1476 : 34 : n->setstmt = $5;
1477 : 34 : $$ = (Node *) n;
1478 : : }
1479 : : | ALTER ROLE ALL opt_in_database SetResetClause
1480 : : {
1481 : 2 : AlterRoleSetStmt *n = makeNode(AlterRoleSetStmt);
1482 : :
1483 : 2 : n->role = NULL;
1484 : 2 : n->database = $4;
1485 : 2 : n->setstmt = $5;
1486 : 2 : $$ = (Node *) n;
1487 : : }
1488 : : | ALTER USER RoleSpec opt_in_database SetResetClause
1489 : : {
1490 : 14 : AlterRoleSetStmt *n = makeNode(AlterRoleSetStmt);
1491 : :
1492 : 14 : n->role = $3;
1493 : 14 : n->database = $4;
1494 : 14 : n->setstmt = $5;
1495 : 14 : $$ = (Node *) n;
1496 : : }
1497 : : | ALTER USER ALL opt_in_database SetResetClause
1498 : : {
1499 : 2 : AlterRoleSetStmt *n = makeNode(AlterRoleSetStmt);
1500 : :
1501 : 2 : n->role = NULL;
1502 : 2 : n->database = $4;
1503 : 2 : n->setstmt = $5;
1504 : 2 : $$ = (Node *) n;
1505 : : }
1506 : : ;
1507 : :
1508 : :
1509 : : /*****************************************************************************
1510 : : *
1511 : : * Drop a postgresql DBMS role
1512 : : *
1513 : : * XXX Ideally this would have CASCADE/RESTRICT options, but a role
1514 : : * might own objects in multiple databases, and there is presently no way to
1515 : : * implement cascading to other databases. So we always behave as RESTRICT.
1516 : : *****************************************************************************/
1517 : :
1518 : : DropRoleStmt:
1519 : : DROP ROLE role_list
1520 : : {
1521 : 780 : DropRoleStmt *n = makeNode(DropRoleStmt);
1522 : :
1523 : 780 : n->missing_ok = false;
1524 : 780 : n->roles = $3;
1525 : 780 : $$ = (Node *) n;
1526 : : }
1527 : : | DROP ROLE IF_P EXISTS role_list
1528 : : {
1529 : 96 : DropRoleStmt *n = makeNode(DropRoleStmt);
1530 : :
1531 : 96 : n->missing_ok = true;
1532 : 96 : n->roles = $5;
1533 : 96 : $$ = (Node *) n;
1534 : : }
1535 : : | DROP USER role_list
1536 : : {
1537 : 295 : DropRoleStmt *n = makeNode(DropRoleStmt);
1538 : :
1539 : 295 : n->missing_ok = false;
1540 : 295 : n->roles = $3;
1541 : 295 : $$ = (Node *) n;
1542 : : }
1543 : : | DROP USER IF_P EXISTS role_list
1544 : : {
1545 : 44 : DropRoleStmt *n = makeNode(DropRoleStmt);
1546 : :
1547 : 44 : n->roles = $5;
1548 : 44 : n->missing_ok = true;
1549 : 44 : $$ = (Node *) n;
1550 : : }
1551 : : | DROP GROUP_P role_list
1552 : : {
1553 : 24 : DropRoleStmt *n = makeNode(DropRoleStmt);
1554 : :
1555 : 24 : n->missing_ok = false;
1556 : 24 : n->roles = $3;
1557 : 24 : $$ = (Node *) n;
1558 : : }
1559 : : | DROP GROUP_P IF_P EXISTS role_list
1560 : : {
1561 : 4 : DropRoleStmt *n = makeNode(DropRoleStmt);
1562 : :
1563 : 4 : n->missing_ok = true;
1564 : 4 : n->roles = $5;
1565 : 4 : $$ = (Node *) n;
1566 : : }
1567 : : ;
1568 : :
1569 : :
1570 : : /*****************************************************************************
1571 : : *
1572 : : * Create a postgresql group (role without login ability)
1573 : : *
1574 : : *****************************************************************************/
1575 : :
1576 : : CreateGroupStmt:
1577 : : CREATE GROUP_P RoleId opt_with OptRoleList
1578 : : {
1579 : 16 : CreateRoleStmt *n = makeNode(CreateRoleStmt);
1580 : :
1581 : 16 : n->stmt_type = ROLESTMT_GROUP;
1582 : 16 : n->role = $3;
1583 : 16 : n->options = $5;
1584 : 16 : $$ = (Node *) n;
1585 : : }
1586 : : ;
1587 : :
1588 : :
1589 : : /*****************************************************************************
1590 : : *
1591 : : * Alter a postgresql group
1592 : : *
1593 : : *****************************************************************************/
1594 : :
1595 : : AlterGroupStmt:
1596 : : ALTER GROUP_P RoleSpec add_drop USER role_list
1597 : : {
1598 : 28 : AlterRoleStmt *n = makeNode(AlterRoleStmt);
1599 : :
1600 : 28 : n->role = $3;
1601 : 28 : n->action = $4;
1602 : 28 : n->options = list_make1(makeDefElem("rolemembers",
1603 : : (Node *) $6, @6));
1604 : 28 : $$ = (Node *) n;
1605 : : }
1606 : : ;
1607 : :
1608 : 52 : add_drop: ADD_P { $$ = +1; }
1609 : 118 : | DROP { $$ = -1; }
1610 : : ;
1611 : :
1612 : :
1613 : : /*****************************************************************************
1614 : : *
1615 : : * Manipulate a schema
1616 : : *
1617 : : *****************************************************************************/
1618 : :
1619 : : CreateSchemaStmt:
1620 : : CREATE SCHEMA opt_single_name AUTHORIZATION RoleSpec OptSchemaEltList
1621 : : {
1622 : 110 : CreateSchemaStmt *n = makeNode(CreateSchemaStmt);
1623 : :
1624 : : /* One can omit the schema name or the authorization id. */
1625 : 110 : n->schemaname = $3;
1626 : 110 : n->authrole = $5;
1627 : 110 : n->schemaElts = $6;
1628 : 110 : n->if_not_exists = false;
1629 : 110 : $$ = (Node *) n;
1630 : : }
1631 : : | CREATE SCHEMA ColId OptSchemaEltList
1632 : : {
1633 : 642 : CreateSchemaStmt *n = makeNode(CreateSchemaStmt);
1634 : :
1635 : : /* ...but not both */
1636 : 642 : n->schemaname = $3;
1637 : 642 : n->authrole = NULL;
1638 : 642 : n->schemaElts = $4;
1639 : 642 : n->if_not_exists = false;
1640 : 642 : $$ = (Node *) n;
1641 : : }
1642 : : | CREATE SCHEMA IF_P NOT EXISTS opt_single_name AUTHORIZATION RoleSpec OptSchemaEltList
1643 : : {
1644 : 9 : CreateSchemaStmt *n = makeNode(CreateSchemaStmt);
1645 : :
1646 : : /* schema name can be omitted here, too */
1647 : 9 : n->schemaname = $6;
1648 : 9 : n->authrole = $8;
1649 [ - + ]: 9 : if ($9 != NIL)
1650 [ # # ]: 0 : ereport(ERROR,
1651 : : (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
1652 : : errmsg("CREATE SCHEMA IF NOT EXISTS cannot include schema elements"),
1653 : : parser_errposition(@9)));
1654 : 9 : n->schemaElts = $9;
1655 : 9 : n->if_not_exists = true;
1656 : 9 : $$ = (Node *) n;
1657 : : }
1658 : : | CREATE SCHEMA IF_P NOT EXISTS ColId OptSchemaEltList
1659 : : {
1660 : 19 : CreateSchemaStmt *n = makeNode(CreateSchemaStmt);
1661 : :
1662 : : /* ...but not here */
1663 : 19 : n->schemaname = $6;
1664 : 19 : n->authrole = NULL;
1665 [ + + ]: 19 : if ($7 != NIL)
1666 [ + - ]: 4 : ereport(ERROR,
1667 : : (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
1668 : : errmsg("CREATE SCHEMA IF NOT EXISTS cannot include schema elements"),
1669 : : parser_errposition(@7)));
1670 : 15 : n->schemaElts = $7;
1671 : 15 : n->if_not_exists = true;
1672 : 15 : $$ = (Node *) n;
1673 : : }
1674 : : ;
1675 : :
1676 : : OptSchemaEltList:
1677 : : OptSchemaEltList schema_stmt
1678 : : {
1679 : 516 : $$ = lappend($1, $2);
1680 : : }
1681 : : | /* EMPTY */
1682 : 780 : { $$ = NIL; }
1683 : : ;
1684 : :
1685 : : /*
1686 : : * schema_stmt are the ones that can show up inside a CREATE SCHEMA
1687 : : * statement (in addition to by themselves).
1688 : : */
1689 : : schema_stmt:
1690 : : CreateStmt
1691 : : | IndexStmt
1692 : : | CreateDomainStmt
1693 : : | CreateFunctionStmt
1694 : : | CreateSeqStmt
1695 : : | CreateTrigStmt
1696 : : | DefineStmt
1697 : : | GrantStmt
1698 : : | ViewStmt
1699 : : ;
1700 : :
1701 : :
1702 : : /*****************************************************************************
1703 : : *
1704 : : * Set PG internal variable
1705 : : * SET name TO 'var_value'
1706 : : * Include SQL syntax (thomas 1997-10-22):
1707 : : * SET TIME ZONE 'var_value'
1708 : : *
1709 : : *****************************************************************************/
1710 : :
1711 : : VariableSetStmt:
1712 : : SET set_rest
1713 : : {
1714 : 14129 : VariableSetStmt *n = $2;
1715 : :
1716 : 14129 : n->is_local = false;
1717 : 14129 : $$ = (Node *) n;
1718 : : }
1719 : : | SET LOCAL set_rest
1720 : : {
1721 : 942 : VariableSetStmt *n = $3;
1722 : :
1723 : 942 : n->is_local = true;
1724 : 942 : $$ = (Node *) n;
1725 : : }
1726 : : | SET SESSION set_rest
1727 : : {
1728 : 89 : VariableSetStmt *n = $3;
1729 : :
1730 : 89 : n->is_local = false;
1731 : 89 : $$ = (Node *) n;
1732 : : }
1733 : : ;
1734 : :
1735 : : set_rest:
1736 : : TRANSACTION transaction_mode_list
1737 : : {
1738 : 318 : VariableSetStmt *n = makeNode(VariableSetStmt);
1739 : :
1740 : 318 : n->kind = VAR_SET_MULTI;
1741 : 318 : n->name = "TRANSACTION";
1742 : 318 : n->args = $2;
1743 : 318 : n->jumble_args = true;
1744 : 318 : n->location = -1;
1745 : 318 : $$ = n;
1746 : : }
1747 : : | SESSION CHARACTERISTICS AS TRANSACTION transaction_mode_list
1748 : : {
1749 : 11 : VariableSetStmt *n = makeNode(VariableSetStmt);
1750 : :
1751 : 11 : n->kind = VAR_SET_MULTI;
1752 : 11 : n->name = "SESSION CHARACTERISTICS";
1753 : 11 : n->args = $5;
1754 : 11 : n->jumble_args = true;
1755 : 11 : n->location = -1;
1756 : 11 : $$ = n;
1757 : : }
1758 : : | set_rest_more
1759 : : ;
1760 : :
1761 : : generic_set:
1762 : : var_name TO var_list
1763 : : {
1764 : 3480 : VariableSetStmt *n = makeNode(VariableSetStmt);
1765 : :
1766 : 3480 : n->kind = VAR_SET_VALUE;
1767 : 3480 : n->name = $1;
1768 : 3480 : n->args = $3;
1769 : 3480 : n->location = @3;
1770 : 3480 : $$ = n;
1771 : : }
1772 : : | var_name '=' var_list
1773 : : {
1774 : 9282 : VariableSetStmt *n = makeNode(VariableSetStmt);
1775 : :
1776 : 9282 : n->kind = VAR_SET_VALUE;
1777 : 9282 : n->name = $1;
1778 : 9282 : n->args = $3;
1779 : 9282 : n->location = @3;
1780 : 9282 : $$ = n;
1781 : : }
1782 : : | var_name TO NULL_P
1783 : : {
1784 : 5 : VariableSetStmt *n = makeNode(VariableSetStmt);
1785 : :
1786 : 5 : n->kind = VAR_SET_VALUE;
1787 : 5 : n->name = $1;
1788 : 5 : n->args = list_make1(makeNullAConst(@3));
1789 : 5 : n->location = @3;
1790 : 5 : $$ = n;
1791 : : }
1792 : : | var_name '=' NULL_P
1793 : : {
1794 : 12 : VariableSetStmt *n = makeNode(VariableSetStmt);
1795 : :
1796 : 12 : n->kind = VAR_SET_VALUE;
1797 : 12 : n->name = $1;
1798 : 12 : n->args = list_make1(makeNullAConst(@3));
1799 : 12 : n->location = @3;
1800 : 12 : $$ = n;
1801 : : }
1802 : : | var_name TO DEFAULT
1803 : : {
1804 : 90 : VariableSetStmt *n = makeNode(VariableSetStmt);
1805 : :
1806 : 90 : n->kind = VAR_SET_DEFAULT;
1807 : 90 : n->name = $1;
1808 : 90 : n->location = -1;
1809 : 90 : $$ = n;
1810 : : }
1811 : : | var_name '=' DEFAULT
1812 : : {
1813 : 6 : VariableSetStmt *n = makeNode(VariableSetStmt);
1814 : :
1815 : 6 : n->kind = VAR_SET_DEFAULT;
1816 : 6 : n->name = $1;
1817 : 6 : n->location = -1;
1818 : 6 : $$ = n;
1819 : : }
1820 : : ;
1821 : :
1822 : : set_rest_more: /* Generic SET syntaxes: */
1823 : 12785 : generic_set {$$ = $1;}
1824 : : | var_name FROM CURRENT_P
1825 : : {
1826 : 2 : VariableSetStmt *n = makeNode(VariableSetStmt);
1827 : :
1828 : 2 : n->kind = VAR_SET_CURRENT;
1829 : 2 : n->name = $1;
1830 : 2 : n->location = -1;
1831 : 2 : $$ = n;
1832 : : }
1833 : : /* Special syntaxes mandated by SQL standard: */
1834 : : | TIME ZONE zone_value
1835 : : {
1836 : 67 : VariableSetStmt *n = makeNode(VariableSetStmt);
1837 : :
1838 : 67 : n->kind = VAR_SET_VALUE;
1839 : 67 : n->name = "timezone";
1840 : 67 : n->location = -1;
1841 : 67 : n->jumble_args = true;
1842 [ + + ]: 67 : if ($3 != NULL)
1843 : 57 : n->args = list_make1($3);
1844 : : else
1845 : 10 : n->kind = VAR_SET_DEFAULT;
1846 : 67 : $$ = n;
1847 : : }
1848 : : | CATALOG_P Sconst
1849 : : {
1850 [ # # ]: 0 : ereport(ERROR,
1851 : : (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
1852 : : errmsg("current database cannot be changed"),
1853 : : parser_errposition(@2)));
1854 : : $$ = NULL; /*not reached*/
1855 : : }
1856 : : | SCHEMA Sconst
1857 : : {
1858 : 2 : VariableSetStmt *n = makeNode(VariableSetStmt);
1859 : :
1860 : 2 : n->kind = VAR_SET_VALUE;
1861 : 2 : n->name = "search_path";
1862 : 2 : n->args = list_make1(makeStringConst($2, @2));
1863 : 2 : n->location = @2;
1864 : 2 : $$ = n;
1865 : : }
1866 : : | NAMES opt_encoding
1867 : : {
1868 : 0 : VariableSetStmt *n = makeNode(VariableSetStmt);
1869 : :
1870 : 0 : n->kind = VAR_SET_VALUE;
1871 : 0 : n->name = "client_encoding";
1872 : 0 : n->location = @2;
1873 [ # # ]: 0 : if ($2 != NULL)
1874 : 0 : n->args = list_make1(makeStringConst($2, @2));
1875 : : else
1876 : 0 : n->kind = VAR_SET_DEFAULT;
1877 : 0 : $$ = n;
1878 : : }
1879 : : | ROLE NonReservedWord_or_Sconst
1880 : : {
1881 : 718 : VariableSetStmt *n = makeNode(VariableSetStmt);
1882 : :
1883 : 718 : n->kind = VAR_SET_VALUE;
1884 : 718 : n->name = "role";
1885 : 718 : n->args = list_make1(makeStringConst($2, @2));
1886 : 718 : n->location = @2;
1887 : 718 : $$ = n;
1888 : : }
1889 : : | SESSION AUTHORIZATION NonReservedWord_or_Sconst
1890 : : {
1891 : 2011 : VariableSetStmt *n = makeNode(VariableSetStmt);
1892 : :
1893 : 2011 : n->kind = VAR_SET_VALUE;
1894 : 2011 : n->name = "session_authorization";
1895 : 2011 : n->args = list_make1(makeStringConst($3, @3));
1896 : 2011 : n->location = @3;
1897 : 2011 : $$ = n;
1898 : : }
1899 : : | SESSION AUTHORIZATION DEFAULT
1900 : : {
1901 : 2 : VariableSetStmt *n = makeNode(VariableSetStmt);
1902 : :
1903 : 2 : n->kind = VAR_SET_DEFAULT;
1904 : 2 : n->name = "session_authorization";
1905 : 2 : n->location = -1;
1906 : 2 : $$ = n;
1907 : : }
1908 : : | XML_P OPTION document_or_content
1909 : : {
1910 : 10 : VariableSetStmt *n = makeNode(VariableSetStmt);
1911 : :
1912 : 10 : n->kind = VAR_SET_VALUE;
1913 : 10 : n->name = "xmloption";
1914 [ + + ]: 10 : n->args = list_make1(makeStringConst($3 == XMLOPTION_DOCUMENT ? "DOCUMENT" : "CONTENT", @3));
1915 : 10 : n->jumble_args = true;
1916 : 10 : n->location = -1;
1917 : 10 : $$ = n;
1918 : : }
1919 : : /* Special syntaxes invented by PostgreSQL: */
1920 : : | TRANSACTION SNAPSHOT Sconst
1921 : : {
1922 : 24 : VariableSetStmt *n = makeNode(VariableSetStmt);
1923 : :
1924 : 24 : n->kind = VAR_SET_MULTI;
1925 : 24 : n->name = "TRANSACTION SNAPSHOT";
1926 : 24 : n->args = list_make1(makeStringConst($3, @3));
1927 : 24 : n->location = @3;
1928 : 24 : $$ = n;
1929 : : }
1930 : : ;
1931 : :
1932 : 16188 : var_name: ColId { $$ = $1; }
1933 : : | var_name '.' ColId
1934 : 467 : { $$ = psprintf("%s.%s", $1, $3); }
1935 : : ;
1936 : :
1937 : 12762 : var_list: var_value { $$ = list_make1($1); }
1938 : 447 : | var_list ',' var_value { $$ = lappend($1, $3); }
1939 : : ;
1940 : :
1941 : : var_value: opt_boolean_or_string
1942 : 10085 : { $$ = makeStringConst($1, @1); }
1943 : : | NumericOnly
1944 : 3124 : { $$ = makeAConst($1, @1); }
1945 : : ;
1946 : :
1947 : 0 : iso_level: READ UNCOMMITTED { $$ = "read uncommitted"; }
1948 : 650 : | READ COMMITTED { $$ = "read committed"; }
1949 : 1555 : | REPEATABLE READ { $$ = "repeatable read"; }
1950 : 1645 : | SERIALIZABLE { $$ = "serializable"; }
1951 : : ;
1952 : :
1953 : : opt_boolean_or_string:
1954 : 436 : TRUE_P { $$ = "true"; }
1955 : 874 : | FALSE_P { $$ = "false"; }
1956 : 1607 : | ON { $$ = "on"; }
1957 : : /*
1958 : : * OFF is also accepted as a boolean value, but is handled by
1959 : : * the NonReservedWord rule. The action for booleans and strings
1960 : : * is the same, so we don't need to distinguish them here.
1961 : : */
1962 : 22137 : | NonReservedWord_or_Sconst { $$ = $1; }
1963 : : ;
1964 : :
1965 : : /* Timezone values can be:
1966 : : * - a string such as 'pst8pdt'
1967 : : * - an identifier such as "pst8pdt"
1968 : : * - an integer or floating point number
1969 : : * - a time interval per SQL99
1970 : : * ColId gives reduce/reduce errors against ConstInterval and LOCAL,
1971 : : * so use IDENT (meaning we reject anything that is a key word).
1972 : : */
1973 : : zone_value:
1974 : : Sconst
1975 : : {
1976 : 39 : $$ = makeStringConst($1, @1);
1977 : : }
1978 : : | IDENT
1979 : : {
1980 : 2 : $$ = makeStringConst($1, @1);
1981 : : }
1982 : : | ConstInterval Sconst opt_interval
1983 : : {
1984 : 0 : TypeName *t = $1;
1985 : :
1986 [ # # ]: 0 : if ($3 != NIL)
1987 : : {
1988 : 0 : A_Const *n = (A_Const *) linitial($3);
1989 : :
1990 [ # # ]: 0 : if ((n->val.ival.ival & ~(INTERVAL_MASK(HOUR) | INTERVAL_MASK(MINUTE))) != 0)
1991 [ # # ]: 0 : ereport(ERROR,
1992 : : (errcode(ERRCODE_SYNTAX_ERROR),
1993 : : errmsg("time zone interval must be HOUR or HOUR TO MINUTE"),
1994 : : parser_errposition(@3)));
1995 : : }
1996 : 0 : t->typmods = $3;
1997 : 0 : $$ = makeStringConstCast($2, @2, t);
1998 : : }
1999 : : | ConstInterval '(' Iconst ')' Sconst
2000 : : {
2001 : 0 : TypeName *t = $1;
2002 : :
2003 : 0 : t->typmods = list_make2(makeIntConst(INTERVAL_FULL_RANGE, -1),
2004 : : makeIntConst($3, @3));
2005 : 0 : $$ = makeStringConstCast($5, @5, t);
2006 : : }
2007 : 16 : | NumericOnly { $$ = makeAConst($1, @1); }
2008 : 9 : | DEFAULT { $$ = NULL; }
2009 : 1 : | LOCAL { $$ = NULL; }
2010 : : ;
2011 : :
2012 : : opt_encoding:
2013 : 0 : Sconst { $$ = $1; }
2014 : 0 : | DEFAULT { $$ = NULL; }
2015 : 0 : | /*EMPTY*/ { $$ = NULL; }
2016 : : ;
2017 : :
2018 : : NonReservedWord_or_Sconst:
2019 : 33901 : NonReservedWord { $$ = $1; }
2020 : 4108 : | Sconst { $$ = $1; }
2021 : : ;
2022 : :
2023 : : VariableResetStmt:
2024 : 3363 : RESET reset_rest { $$ = (Node *) $2; }
2025 : : ;
2026 : :
2027 : : reset_rest:
2028 : 2724 : generic_reset { $$ = $1; }
2029 : : | TIME ZONE
2030 : : {
2031 : 9 : VariableSetStmt *n = makeNode(VariableSetStmt);
2032 : :
2033 : 9 : n->kind = VAR_RESET;
2034 : 9 : n->name = "timezone";
2035 : 9 : n->location = -1;
2036 : 9 : $$ = n;
2037 : : }
2038 : : | TRANSACTION ISOLATION LEVEL
2039 : : {
2040 : 0 : VariableSetStmt *n = makeNode(VariableSetStmt);
2041 : :
2042 : 0 : n->kind = VAR_RESET;
2043 : 0 : n->name = "transaction_isolation";
2044 : 0 : n->location = -1;
2045 : 0 : $$ = n;
2046 : : }
2047 : : | SESSION AUTHORIZATION
2048 : : {
2049 : 630 : VariableSetStmt *n = makeNode(VariableSetStmt);
2050 : :
2051 : 630 : n->kind = VAR_RESET;
2052 : 630 : n->name = "session_authorization";
2053 : 630 : n->location = -1;
2054 : 630 : $$ = n;
2055 : : }
2056 : : ;
2057 : :
2058 : : generic_reset:
2059 : : var_name
2060 : : {
2061 : 2736 : VariableSetStmt *n = makeNode(VariableSetStmt);
2062 : :
2063 : 2736 : n->kind = VAR_RESET;
2064 : 2736 : n->name = $1;
2065 : 2736 : n->location = -1;
2066 : 2736 : $$ = n;
2067 : : }
2068 : : | ALL
2069 : : {
2070 : 17 : VariableSetStmt *n = makeNode(VariableSetStmt);
2071 : :
2072 : 17 : n->kind = VAR_RESET_ALL;
2073 : 17 : n->location = -1;
2074 : 17 : $$ = n;
2075 : : }
2076 : : ;
2077 : :
2078 : : /* SetResetClause allows SET or RESET without LOCAL */
2079 : : SetResetClause:
2080 : 701 : SET set_rest { $$ = $2; }
2081 : 21 : | VariableResetStmt { $$ = (VariableSetStmt *) $1; }
2082 : : ;
2083 : :
2084 : : /* SetResetClause allows SET or RESET without LOCAL */
2085 : : FunctionSetResetClause:
2086 : 89 : SET set_rest_more { $$ = $2; }
2087 : 8 : | VariableResetStmt { $$ = (VariableSetStmt *) $1; }
2088 : : ;
2089 : :
2090 : :
2091 : : VariableShowStmt:
2092 : : SHOW var_name
2093 : : {
2094 : 575 : VariableShowStmt *n = makeNode(VariableShowStmt);
2095 : :
2096 : 575 : n->name = $2;
2097 : 575 : $$ = (Node *) n;
2098 : : }
2099 : : | SHOW TIME ZONE
2100 : : {
2101 : 6 : VariableShowStmt *n = makeNode(VariableShowStmt);
2102 : :
2103 : 6 : n->name = "timezone";
2104 : 6 : $$ = (Node *) n;
2105 : : }
2106 : : | SHOW TRANSACTION ISOLATION LEVEL
2107 : : {
2108 : 2 : VariableShowStmt *n = makeNode(VariableShowStmt);
2109 : :
2110 : 2 : n->name = "transaction_isolation";
2111 : 2 : $$ = (Node *) n;
2112 : : }
2113 : : | SHOW SESSION AUTHORIZATION
2114 : : {
2115 : 0 : VariableShowStmt *n = makeNode(VariableShowStmt);
2116 : :
2117 : 0 : n->name = "session_authorization";
2118 : 0 : $$ = (Node *) n;
2119 : : }
2120 : : | SHOW ALL
2121 : : {
2122 : 0 : VariableShowStmt *n = makeNode(VariableShowStmt);
2123 : :
2124 : 0 : n->name = "all";
2125 : 0 : $$ = (Node *) n;
2126 : : }
2127 : : ;
2128 : :
2129 : :
2130 : : ConstraintsSetStmt:
2131 : : SET CONSTRAINTS constraints_set_list constraints_set_mode
2132 : : {
2133 : 72 : ConstraintsSetStmt *n = makeNode(ConstraintsSetStmt);
2134 : :
2135 : 72 : n->constraints = $3;
2136 : 72 : n->deferred = $4;
2137 : 72 : $$ = (Node *) n;
2138 : : }
2139 : : ;
2140 : :
2141 : : constraints_set_list:
2142 : 40 : ALL { $$ = NIL; }
2143 : 32 : | qualified_name_list { $$ = $1; }
2144 : : ;
2145 : :
2146 : : constraints_set_mode:
2147 : 45 : DEFERRED { $$ = true; }
2148 : 27 : | IMMEDIATE { $$ = false; }
2149 : : ;
2150 : :
2151 : :
2152 : : /*
2153 : : * Checkpoint statement
2154 : : */
2155 : : CheckPointStmt:
2156 : : CHECKPOINT opt_utility_option_list
2157 : : {
2158 : 142 : CheckPointStmt *n = makeNode(CheckPointStmt);
2159 : :
2160 : 142 : $$ = (Node *) n;
2161 : 142 : n->options = $2;
2162 : : }
2163 : : ;
2164 : :
2165 : :
2166 : : /*****************************************************************************
2167 : : *
2168 : : * DISCARD { ALL | TEMP | PLANS | SEQUENCES }
2169 : : *
2170 : : *****************************************************************************/
2171 : :
2172 : : DiscardStmt:
2173 : : DISCARD ALL
2174 : : {
2175 : 4 : DiscardStmt *n = makeNode(DiscardStmt);
2176 : :
2177 : 4 : n->target = DISCARD_ALL;
2178 : 4 : $$ = (Node *) n;
2179 : : }
2180 : : | DISCARD TEMP
2181 : : {
2182 : 9 : DiscardStmt *n = makeNode(DiscardStmt);
2183 : :
2184 : 9 : n->target = DISCARD_TEMP;
2185 : 9 : $$ = (Node *) n;
2186 : : }
2187 : : | DISCARD TEMPORARY
2188 : : {
2189 : 0 : DiscardStmt *n = makeNode(DiscardStmt);
2190 : :
2191 : 0 : n->target = DISCARD_TEMP;
2192 : 0 : $$ = (Node *) n;
2193 : : }
2194 : : | DISCARD PLANS
2195 : : {
2196 : 3 : DiscardStmt *n = makeNode(DiscardStmt);
2197 : :
2198 : 3 : n->target = DISCARD_PLANS;
2199 : 3 : $$ = (Node *) n;
2200 : : }
2201 : : | DISCARD SEQUENCES
2202 : : {
2203 : 8 : DiscardStmt *n = makeNode(DiscardStmt);
2204 : :
2205 : 8 : n->target = DISCARD_SEQUENCES;
2206 : 8 : $$ = (Node *) n;
2207 : : }
2208 : :
2209 : : ;
2210 : :
2211 : :
2212 : : /*****************************************************************************
2213 : : *
2214 : : * ALTER [ TABLE | INDEX | SEQUENCE | VIEW | MATERIALIZED VIEW | FOREIGN TABLE ] variations
2215 : : *
2216 : : * Note: we accept all subcommands for each of the variants, and sort
2217 : : * out what's really legal at execution time.
2218 : : *****************************************************************************/
2219 : :
2220 : : AlterTableStmt:
2221 : : ALTER TABLE relation_expr alter_table_cmds
2222 : : {
2223 : 17434 : AlterTableStmt *n = makeNode(AlterTableStmt);
2224 : :
2225 : 17434 : n->relation = $3;
2226 : 17434 : n->cmds = $4;
2227 : 17434 : n->objtype = OBJECT_TABLE;
2228 : 17434 : n->missing_ok = false;
2229 : 17434 : $$ = (Node *) n;
2230 : : }
2231 : : | ALTER TABLE IF_P EXISTS relation_expr alter_table_cmds
2232 : : {
2233 : 36 : AlterTableStmt *n = makeNode(AlterTableStmt);
2234 : :
2235 : 36 : n->relation = $5;
2236 : 36 : n->cmds = $6;
2237 : 36 : n->objtype = OBJECT_TABLE;
2238 : 36 : n->missing_ok = true;
2239 : 36 : $$ = (Node *) n;
2240 : : }
2241 : : | ALTER TABLE relation_expr partition_cmd
2242 : : {
2243 : 2534 : AlterTableStmt *n = makeNode(AlterTableStmt);
2244 : :
2245 : 2534 : n->relation = $3;
2246 : 2534 : n->cmds = list_make1($4);
2247 : 2534 : n->objtype = OBJECT_TABLE;
2248 : 2534 : n->missing_ok = false;
2249 : 2534 : $$ = (Node *) n;
2250 : : }
2251 : : | ALTER TABLE IF_P EXISTS relation_expr partition_cmd
2252 : : {
2253 : 0 : AlterTableStmt *n = makeNode(AlterTableStmt);
2254 : :
2255 : 0 : n->relation = $5;
2256 : 0 : n->cmds = list_make1($6);
2257 : 0 : n->objtype = OBJECT_TABLE;
2258 : 0 : n->missing_ok = true;
2259 : 0 : $$ = (Node *) n;
2260 : : }
2261 : : | ALTER TABLE ALL IN_P TABLESPACE name SET TABLESPACE name opt_nowait
2262 : : {
2263 : : AlterTableMoveAllStmt *n =
2264 : 7 : makeNode(AlterTableMoveAllStmt);
2265 : :
2266 : 7 : n->orig_tablespacename = $6;
2267 : 7 : n->objtype = OBJECT_TABLE;
2268 : 7 : n->roles = NIL;
2269 : 7 : n->new_tablespacename = $9;
2270 : 7 : n->nowait = $10;
2271 : 7 : $$ = (Node *) n;
2272 : : }
2273 : : | ALTER TABLE ALL IN_P TABLESPACE name OWNED BY role_list SET TABLESPACE name opt_nowait
2274 : : {
2275 : : AlterTableMoveAllStmt *n =
2276 : 0 : makeNode(AlterTableMoveAllStmt);
2277 : :
2278 : 0 : n->orig_tablespacename = $6;
2279 : 0 : n->objtype = OBJECT_TABLE;
2280 : 0 : n->roles = $9;
2281 : 0 : n->new_tablespacename = $12;
2282 : 0 : n->nowait = $13;
2283 : 0 : $$ = (Node *) n;
2284 : : }
2285 : : | ALTER INDEX qualified_name alter_table_cmds
2286 : : {
2287 : 146 : AlterTableStmt *n = makeNode(AlterTableStmt);
2288 : :
2289 : 146 : n->relation = $3;
2290 : 146 : n->cmds = $4;
2291 : 146 : n->objtype = OBJECT_INDEX;
2292 : 146 : n->missing_ok = false;
2293 : 146 : $$ = (Node *) n;
2294 : : }
2295 : : | ALTER INDEX IF_P EXISTS qualified_name alter_table_cmds
2296 : : {
2297 : 0 : AlterTableStmt *n = makeNode(AlterTableStmt);
2298 : :
2299 : 0 : n->relation = $5;
2300 : 0 : n->cmds = $6;
2301 : 0 : n->objtype = OBJECT_INDEX;
2302 : 0 : n->missing_ok = true;
2303 : 0 : $$ = (Node *) n;
2304 : : }
2305 : : | ALTER INDEX qualified_name index_partition_cmd
2306 : : {
2307 : 288 : AlterTableStmt *n = makeNode(AlterTableStmt);
2308 : :
2309 : 288 : n->relation = $3;
2310 : 288 : n->cmds = list_make1($4);
2311 : 288 : n->objtype = OBJECT_INDEX;
2312 : 288 : n->missing_ok = false;
2313 : 288 : $$ = (Node *) n;
2314 : : }
2315 : : | ALTER INDEX ALL IN_P TABLESPACE name SET TABLESPACE name opt_nowait
2316 : : {
2317 : : AlterTableMoveAllStmt *n =
2318 : 3 : makeNode(AlterTableMoveAllStmt);
2319 : :
2320 : 3 : n->orig_tablespacename = $6;
2321 : 3 : n->objtype = OBJECT_INDEX;
2322 : 3 : n->roles = NIL;
2323 : 3 : n->new_tablespacename = $9;
2324 : 3 : n->nowait = $10;
2325 : 3 : $$ = (Node *) n;
2326 : : }
2327 : : | ALTER INDEX ALL IN_P TABLESPACE name OWNED BY role_list SET TABLESPACE name opt_nowait
2328 : : {
2329 : : AlterTableMoveAllStmt *n =
2330 : 0 : makeNode(AlterTableMoveAllStmt);
2331 : :
2332 : 0 : n->orig_tablespacename = $6;
2333 : 0 : n->objtype = OBJECT_INDEX;
2334 : 0 : n->roles = $9;
2335 : 0 : n->new_tablespacename = $12;
2336 : 0 : n->nowait = $13;
2337 : 0 : $$ = (Node *) n;
2338 : : }
2339 : : | ALTER SEQUENCE qualified_name alter_table_cmds
2340 : : {
2341 : 51 : AlterTableStmt *n = makeNode(AlterTableStmt);
2342 : :
2343 : 51 : n->relation = $3;
2344 : 51 : n->cmds = $4;
2345 : 51 : n->objtype = OBJECT_SEQUENCE;
2346 : 51 : n->missing_ok = false;
2347 : 51 : $$ = (Node *) n;
2348 : : }
2349 : : | ALTER SEQUENCE IF_P EXISTS qualified_name alter_table_cmds
2350 : : {
2351 : 0 : AlterTableStmt *n = makeNode(AlterTableStmt);
2352 : :
2353 : 0 : n->relation = $5;
2354 : 0 : n->cmds = $6;
2355 : 0 : n->objtype = OBJECT_SEQUENCE;
2356 : 0 : n->missing_ok = true;
2357 : 0 : $$ = (Node *) n;
2358 : : }
2359 : : | ALTER VIEW qualified_name alter_table_cmds
2360 : : {
2361 : 154 : AlterTableStmt *n = makeNode(AlterTableStmt);
2362 : :
2363 : 154 : n->relation = $3;
2364 : 154 : n->cmds = $4;
2365 : 154 : n->objtype = OBJECT_VIEW;
2366 : 154 : n->missing_ok = false;
2367 : 154 : $$ = (Node *) n;
2368 : : }
2369 : : | ALTER VIEW IF_P EXISTS qualified_name alter_table_cmds
2370 : : {
2371 : 0 : AlterTableStmt *n = makeNode(AlterTableStmt);
2372 : :
2373 : 0 : n->relation = $5;
2374 : 0 : n->cmds = $6;
2375 : 0 : n->objtype = OBJECT_VIEW;
2376 : 0 : n->missing_ok = true;
2377 : 0 : $$ = (Node *) n;
2378 : : }
2379 : : | ALTER MATERIALIZED VIEW qualified_name alter_table_cmds
2380 : : {
2381 : 29 : AlterTableStmt *n = makeNode(AlterTableStmt);
2382 : :
2383 : 29 : n->relation = $4;
2384 : 29 : n->cmds = $5;
2385 : 29 : n->objtype = OBJECT_MATVIEW;
2386 : 29 : n->missing_ok = false;
2387 : 29 : $$ = (Node *) n;
2388 : : }
2389 : : | ALTER MATERIALIZED VIEW IF_P EXISTS qualified_name alter_table_cmds
2390 : : {
2391 : 0 : AlterTableStmt *n = makeNode(AlterTableStmt);
2392 : :
2393 : 0 : n->relation = $6;
2394 : 0 : n->cmds = $7;
2395 : 0 : n->objtype = OBJECT_MATVIEW;
2396 : 0 : n->missing_ok = true;
2397 : 0 : $$ = (Node *) n;
2398 : : }
2399 : : | ALTER MATERIALIZED VIEW ALL IN_P TABLESPACE name SET TABLESPACE name opt_nowait
2400 : : {
2401 : : AlterTableMoveAllStmt *n =
2402 : 6 : makeNode(AlterTableMoveAllStmt);
2403 : :
2404 : 6 : n->orig_tablespacename = $7;
2405 : 6 : n->objtype = OBJECT_MATVIEW;
2406 : 6 : n->roles = NIL;
2407 : 6 : n->new_tablespacename = $10;
2408 : 6 : n->nowait = $11;
2409 : 6 : $$ = (Node *) n;
2410 : : }
2411 : : | ALTER MATERIALIZED VIEW ALL IN_P TABLESPACE name OWNED BY role_list SET TABLESPACE name opt_nowait
2412 : : {
2413 : : AlterTableMoveAllStmt *n =
2414 : 0 : makeNode(AlterTableMoveAllStmt);
2415 : :
2416 : 0 : n->orig_tablespacename = $7;
2417 : 0 : n->objtype = OBJECT_MATVIEW;
2418 : 0 : n->roles = $10;
2419 : 0 : n->new_tablespacename = $13;
2420 : 0 : n->nowait = $14;
2421 : 0 : $$ = (Node *) n;
2422 : : }
2423 : : | ALTER FOREIGN TABLE relation_expr alter_table_cmds
2424 : : {
2425 : 250 : AlterTableStmt *n = makeNode(AlterTableStmt);
2426 : :
2427 : 250 : n->relation = $4;
2428 : 250 : n->cmds = $5;
2429 : 250 : n->objtype = OBJECT_FOREIGN_TABLE;
2430 : 250 : n->missing_ok = false;
2431 : 250 : $$ = (Node *) n;
2432 : : }
2433 : : | ALTER FOREIGN TABLE IF_P EXISTS relation_expr alter_table_cmds
2434 : : {
2435 : 88 : AlterTableStmt *n = makeNode(AlterTableStmt);
2436 : :
2437 : 88 : n->relation = $6;
2438 : 88 : n->cmds = $7;
2439 : 88 : n->objtype = OBJECT_FOREIGN_TABLE;
2440 : 88 : n->missing_ok = true;
2441 : 88 : $$ = (Node *) n;
2442 : : }
2443 : : ;
2444 : :
2445 : : alter_table_cmds:
2446 : 18188 : alter_table_cmd { $$ = list_make1($1); }
2447 : 713 : | alter_table_cmds ',' alter_table_cmd { $$ = lappend($1, $3); }
2448 : : ;
2449 : :
2450 : : partitions_list:
2451 : 293 : SinglePartitionSpec { $$ = list_make1($1); }
2452 : 509 : | partitions_list ',' SinglePartitionSpec { $$ = lappend($1, $3); }
2453 : : ;
2454 : :
2455 : : SinglePartitionSpec:
2456 : : PARTITION qualified_name PartitionBoundSpec
2457 : : {
2458 : 802 : SinglePartitionSpec *n = makeNode(SinglePartitionSpec);
2459 : :
2460 : 802 : n->name = $2;
2461 : 802 : n->bound = $3;
2462 : :
2463 : 802 : $$ = n;
2464 : : }
2465 : : ;
2466 : :
2467 : : partition_cmd:
2468 : : /* ALTER TABLE <name> ATTACH PARTITION <table_name> FOR VALUES */
2469 : : ATTACH PARTITION qualified_name PartitionBoundSpec
2470 : : {
2471 : 1637 : AlterTableCmd *n = makeNode(AlterTableCmd);
2472 : 1637 : PartitionCmd *cmd = makeNode(PartitionCmd);
2473 : :
2474 : 1637 : n->subtype = AT_AttachPartition;
2475 : 1637 : cmd->name = $3;
2476 : 1637 : cmd->bound = $4;
2477 : 1637 : cmd->partlist = NIL;
2478 : 1637 : cmd->concurrent = false;
2479 : 1637 : n->def = (Node *) cmd;
2480 : :
2481 : 1637 : $$ = (Node *) n;
2482 : : }
2483 : : /* ALTER TABLE <name> DETACH PARTITION <partition_name> [CONCURRENTLY] */
2484 : : | DETACH PARTITION qualified_name opt_concurrently
2485 : : {
2486 : 389 : AlterTableCmd *n = makeNode(AlterTableCmd);
2487 : 389 : PartitionCmd *cmd = makeNode(PartitionCmd);
2488 : :
2489 : 389 : n->subtype = AT_DetachPartition;
2490 : 389 : cmd->name = $3;
2491 : 389 : cmd->bound = NULL;
2492 : 389 : cmd->partlist = NIL;
2493 : 389 : cmd->concurrent = $4;
2494 : 389 : n->def = (Node *) cmd;
2495 : :
2496 : 389 : $$ = (Node *) n;
2497 : : }
2498 : : | DETACH PARTITION qualified_name FINALIZE
2499 : : {
2500 : 11 : AlterTableCmd *n = makeNode(AlterTableCmd);
2501 : 11 : PartitionCmd *cmd = makeNode(PartitionCmd);
2502 : :
2503 : 11 : n->subtype = AT_DetachPartitionFinalize;
2504 : 11 : cmd->name = $3;
2505 : 11 : cmd->bound = NULL;
2506 : 11 : cmd->partlist = NIL;
2507 : 11 : cmd->concurrent = false;
2508 : 11 : n->def = (Node *) cmd;
2509 : 11 : $$ = (Node *) n;
2510 : : }
2511 : : /* ALTER TABLE <name> SPLIT PARTITION <partition_name> INTO () */
2512 : : | SPLIT PARTITION qualified_name INTO '(' partitions_list ')'
2513 : : {
2514 : 293 : AlterTableCmd *n = makeNode(AlterTableCmd);
2515 : 293 : PartitionCmd *cmd = makeNode(PartitionCmd);
2516 : :
2517 : 293 : n->subtype = AT_SplitPartition;
2518 : 293 : cmd->name = $3;
2519 : 293 : cmd->bound = NULL;
2520 : 293 : cmd->partlist = $6;
2521 : 293 : cmd->concurrent = false;
2522 : 293 : n->def = (Node *) cmd;
2523 : 293 : $$ = (Node *) n;
2524 : : }
2525 : : /* ALTER TABLE <name> MERGE PARTITIONS () INTO <partition_name> */
2526 : : | MERGE PARTITIONS '(' qualified_name_list ')' INTO qualified_name
2527 : : {
2528 : 204 : AlterTableCmd *n = makeNode(AlterTableCmd);
2529 : 204 : PartitionCmd *cmd = makeNode(PartitionCmd);
2530 : :
2531 : 204 : n->subtype = AT_MergePartitions;
2532 : 204 : cmd->name = $7;
2533 : 204 : cmd->bound = NULL;
2534 : 204 : cmd->partlist = $4;
2535 : 204 : cmd->concurrent = false;
2536 : 204 : n->def = (Node *) cmd;
2537 : 204 : $$ = (Node *) n;
2538 : : }
2539 : : ;
2540 : :
2541 : : index_partition_cmd:
2542 : : /* ALTER INDEX <name> ATTACH PARTITION <index_name> */
2543 : : ATTACH PARTITION qualified_name
2544 : : {
2545 : 288 : AlterTableCmd *n = makeNode(AlterTableCmd);
2546 : 288 : PartitionCmd *cmd = makeNode(PartitionCmd);
2547 : :
2548 : 288 : n->subtype = AT_AttachPartition;
2549 : 288 : cmd->name = $3;
2550 : 288 : cmd->bound = NULL;
2551 : 288 : cmd->partlist = NIL;
2552 : 288 : cmd->concurrent = false;
2553 : 288 : n->def = (Node *) cmd;
2554 : :
2555 : 288 : $$ = (Node *) n;
2556 : : }
2557 : : ;
2558 : :
2559 : : alter_table_cmd:
2560 : : /* ALTER TABLE <name> ADD <coldef> */
2561 : : ADD_P columnDef
2562 : : {
2563 : 138 : AlterTableCmd *n = makeNode(AlterTableCmd);
2564 : :
2565 : 138 : n->subtype = AT_AddColumn;
2566 : 138 : n->def = $2;
2567 : 138 : n->missing_ok = false;
2568 : 138 : $$ = (Node *) n;
2569 : : }
2570 : : /* ALTER TABLE <name> ADD IF NOT EXISTS <coldef> */
2571 : : | ADD_P IF_P NOT EXISTS columnDef
2572 : : {
2573 : 4 : AlterTableCmd *n = makeNode(AlterTableCmd);
2574 : :
2575 : 4 : n->subtype = AT_AddColumn;
2576 : 4 : n->def = $5;
2577 : 4 : n->missing_ok = true;
2578 : 4 : $$ = (Node *) n;
2579 : : }
2580 : : /* ALTER TABLE <name> ADD COLUMN <coldef> */
2581 : : | ADD_P COLUMN columnDef
2582 : : {
2583 : 1397 : AlterTableCmd *n = makeNode(AlterTableCmd);
2584 : :
2585 : 1397 : n->subtype = AT_AddColumn;
2586 : 1397 : n->def = $3;
2587 : 1397 : n->missing_ok = false;
2588 : 1397 : $$ = (Node *) n;
2589 : : }
2590 : : /* ALTER TABLE <name> ADD COLUMN IF NOT EXISTS <coldef> */
2591 : : | ADD_P COLUMN IF_P NOT EXISTS columnDef
2592 : : {
2593 : 48 : AlterTableCmd *n = makeNode(AlterTableCmd);
2594 : :
2595 : 48 : n->subtype = AT_AddColumn;
2596 : 48 : n->def = $6;
2597 : 48 : n->missing_ok = true;
2598 : 48 : $$ = (Node *) n;
2599 : : }
2600 : : /* ALTER TABLE <name> ALTER [COLUMN] <colname> {SET DEFAULT <expr>|DROP DEFAULT} */
2601 : : | ALTER opt_column ColId alter_column_default
2602 : : {
2603 : 361 : AlterTableCmd *n = makeNode(AlterTableCmd);
2604 : :
2605 : 361 : n->subtype = AT_ColumnDefault;
2606 : 361 : n->name = $3;
2607 : 361 : n->def = $4;
2608 : 361 : $$ = (Node *) n;
2609 : : }
2610 : : /* ALTER TABLE <name> ALTER [COLUMN] <colname> DROP NOT NULL */
2611 : : | ALTER opt_column ColId DROP NOT NULL_P
2612 : : {
2613 : 194 : AlterTableCmd *n = makeNode(AlterTableCmd);
2614 : :
2615 : 194 : n->subtype = AT_DropNotNull;
2616 : 194 : n->name = $3;
2617 : 194 : $$ = (Node *) n;
2618 : : }
2619 : : /* ALTER TABLE <name> ALTER [COLUMN] <colname> SET NOT NULL */
2620 : : | ALTER opt_column ColId SET NOT NULL_P
2621 : : {
2622 : 289 : AlterTableCmd *n = makeNode(AlterTableCmd);
2623 : :
2624 : 289 : n->subtype = AT_SetNotNull;
2625 : 289 : n->name = $3;
2626 : 289 : $$ = (Node *) n;
2627 : : }
2628 : : /* ALTER TABLE <name> ALTER [COLUMN] <colname> SET EXPRESSION AS <expr> */
2629 : : | ALTER opt_column ColId SET EXPRESSION AS '(' a_expr ')'
2630 : : {
2631 : 153 : AlterTableCmd *n = makeNode(AlterTableCmd);
2632 : :
2633 : 153 : n->subtype = AT_SetExpression;
2634 : 153 : n->name = $3;
2635 : 153 : n->def = $8;
2636 : 153 : $$ = (Node *) n;
2637 : : }
2638 : : /* ALTER TABLE <name> ALTER [COLUMN] <colname> DROP EXPRESSION */
2639 : : | ALTER opt_column ColId DROP EXPRESSION
2640 : : {
2641 : 45 : AlterTableCmd *n = makeNode(AlterTableCmd);
2642 : :
2643 : 45 : n->subtype = AT_DropExpression;
2644 : 45 : n->name = $3;
2645 : 45 : $$ = (Node *) n;
2646 : : }
2647 : : /* ALTER TABLE <name> ALTER [COLUMN] <colname> DROP EXPRESSION IF EXISTS */
2648 : : | ALTER opt_column ColId DROP EXPRESSION IF_P EXISTS
2649 : : {
2650 : 8 : AlterTableCmd *n = makeNode(AlterTableCmd);
2651 : :
2652 : 8 : n->subtype = AT_DropExpression;
2653 : 8 : n->name = $3;
2654 : 8 : n->missing_ok = true;
2655 : 8 : $$ = (Node *) n;
2656 : : }
2657 : : /* ALTER TABLE <name> ALTER [COLUMN] <colname> SET STATISTICS */
2658 : : | ALTER opt_column ColId SET STATISTICS set_statistics_value
2659 : : {
2660 : 44 : AlterTableCmd *n = makeNode(AlterTableCmd);
2661 : :
2662 : 44 : n->subtype = AT_SetStatistics;
2663 : 44 : n->name = $3;
2664 : 44 : n->def = $6;
2665 : 44 : $$ = (Node *) n;
2666 : : }
2667 : : /* ALTER TABLE <name> ALTER [COLUMN] <colnum> SET STATISTICS */
2668 : : | ALTER opt_column Iconst SET STATISTICS set_statistics_value
2669 : : {
2670 : 46 : AlterTableCmd *n = makeNode(AlterTableCmd);
2671 : :
2672 [ + + - + ]: 46 : if ($3 <= 0 || $3 > PG_INT16_MAX)
2673 [ + - ]: 4 : ereport(ERROR,
2674 : : (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
2675 : : errmsg("column number must be in range from 1 to %d", PG_INT16_MAX),
2676 : : parser_errposition(@3)));
2677 : :
2678 : 42 : n->subtype = AT_SetStatistics;
2679 : 42 : n->num = (int16) $3;
2680 : 42 : n->def = $6;
2681 : 42 : $$ = (Node *) n;
2682 : : }
2683 : : /* ALTER TABLE <name> ALTER [COLUMN] <colname> SET ( column_parameter = value [, ... ] ) */
2684 : : | ALTER opt_column ColId SET reloptions
2685 : : {
2686 : 25 : AlterTableCmd *n = makeNode(AlterTableCmd);
2687 : :
2688 : 25 : n->subtype = AT_SetOptions;
2689 : 25 : n->name = $3;
2690 : 25 : n->def = (Node *) $5;
2691 : 25 : $$ = (Node *) n;
2692 : : }
2693 : : /* ALTER TABLE <name> ALTER [COLUMN] <colname> RESET ( column_parameter [, ... ] ) */
2694 : : | ALTER opt_column ColId RESET reloptions
2695 : : {
2696 : 4 : AlterTableCmd *n = makeNode(AlterTableCmd);
2697 : :
2698 : 4 : n->subtype = AT_ResetOptions;
2699 : 4 : n->name = $3;
2700 : 4 : n->def = (Node *) $5;
2701 : 4 : $$ = (Node *) n;
2702 : : }
2703 : : /* ALTER TABLE <name> ALTER [COLUMN] <colname> SET STORAGE <storagemode> */
2704 : : | ALTER opt_column ColId SET column_storage
2705 : : {
2706 : 168 : AlterTableCmd *n = makeNode(AlterTableCmd);
2707 : :
2708 : 168 : n->subtype = AT_SetStorage;
2709 : 168 : n->name = $3;
2710 : 168 : n->def = (Node *) makeString($5);
2711 : 168 : $$ = (Node *) n;
2712 : : }
2713 : : /* ALTER TABLE <name> ALTER [COLUMN] <colname> SET COMPRESSION <cm> */
2714 : : | ALTER opt_column ColId SET column_compression
2715 : : {
2716 : 48 : AlterTableCmd *n = makeNode(AlterTableCmd);
2717 : :
2718 : 48 : n->subtype = AT_SetCompression;
2719 : 48 : n->name = $3;
2720 : 48 : n->def = (Node *) makeString($5);
2721 : 48 : $$ = (Node *) n;
2722 : : }
2723 : : /* ALTER TABLE <name> ALTER [COLUMN] <colname> ADD GENERATED ... AS IDENTITY ... */
2724 : : | ALTER opt_column ColId ADD_P GENERATED generated_when AS IDENTITY_P OptParenthesizedSeqOptList
2725 : : {
2726 : 107 : AlterTableCmd *n = makeNode(AlterTableCmd);
2727 : 107 : Constraint *c = makeNode(Constraint);
2728 : :
2729 : 107 : c->contype = CONSTR_IDENTITY;
2730 : 107 : c->generated_when = $6;
2731 : 107 : c->options = $9;
2732 : 107 : c->location = @5;
2733 : :
2734 : 107 : n->subtype = AT_AddIdentity;
2735 : 107 : n->name = $3;
2736 : 107 : n->def = (Node *) c;
2737 : :
2738 : 107 : $$ = (Node *) n;
2739 : : }
2740 : : /* ALTER TABLE <name> ALTER [COLUMN] <colname> SET <sequence options>/RESET */
2741 : : | ALTER opt_column ColId alter_identity_column_option_list
2742 : : {
2743 : 41 : AlterTableCmd *n = makeNode(AlterTableCmd);
2744 : :
2745 : 41 : n->subtype = AT_SetIdentity;
2746 : 41 : n->name = $3;
2747 : 41 : n->def = (Node *) $4;
2748 : 41 : $$ = (Node *) n;
2749 : : }
2750 : : /* ALTER TABLE <name> ALTER [COLUMN] <colname> DROP IDENTITY */
2751 : : | ALTER opt_column ColId DROP IDENTITY_P
2752 : : {
2753 : 33 : AlterTableCmd *n = makeNode(AlterTableCmd);
2754 : :
2755 : 33 : n->subtype = AT_DropIdentity;
2756 : 33 : n->name = $3;
2757 : 33 : n->missing_ok = false;
2758 : 33 : $$ = (Node *) n;
2759 : : }
2760 : : /* ALTER TABLE <name> ALTER [COLUMN] <colname> DROP IDENTITY IF EXISTS */
2761 : : | ALTER opt_column ColId DROP IDENTITY_P IF_P EXISTS
2762 : : {
2763 : 4 : AlterTableCmd *n = makeNode(AlterTableCmd);
2764 : :
2765 : 4 : n->subtype = AT_DropIdentity;
2766 : 4 : n->name = $3;
2767 : 4 : n->missing_ok = true;
2768 : 4 : $$ = (Node *) n;
2769 : : }
2770 : : /* ALTER TABLE <name> DROP [COLUMN] IF EXISTS <colname> [RESTRICT|CASCADE] */
2771 : : | DROP opt_column IF_P EXISTS ColId opt_drop_behavior
2772 : : {
2773 : 16 : AlterTableCmd *n = makeNode(AlterTableCmd);
2774 : :
2775 : 16 : n->subtype = AT_DropColumn;
2776 : 16 : n->name = $5;
2777 : 16 : n->behavior = $6;
2778 : 16 : n->missing_ok = true;
2779 : 16 : $$ = (Node *) n;
2780 : : }
2781 : : /* ALTER TABLE <name> DROP [COLUMN] <colname> [RESTRICT|CASCADE] */
2782 : : | DROP opt_column ColId opt_drop_behavior
2783 : : {
2784 : 1097 : AlterTableCmd *n = makeNode(AlterTableCmd);
2785 : :
2786 : 1097 : n->subtype = AT_DropColumn;
2787 : 1097 : n->name = $3;
2788 : 1097 : n->behavior = $4;
2789 : 1097 : n->missing_ok = false;
2790 : 1097 : $$ = (Node *) n;
2791 : : }
2792 : : /*
2793 : : * ALTER TABLE <name> ALTER [COLUMN] <colname> [SET DATA] TYPE <typename>
2794 : : * [ USING <expression> ]
2795 : : */
2796 : : | ALTER opt_column ColId opt_set_data TYPE_P Typename opt_collate_clause alter_using
2797 : : {
2798 : 758 : AlterTableCmd *n = makeNode(AlterTableCmd);
2799 : 758 : ColumnDef *def = makeNode(ColumnDef);
2800 : :
2801 : 758 : n->subtype = AT_AlterColumnType;
2802 : 758 : n->name = $3;
2803 : 758 : n->def = (Node *) def;
2804 : : /* We only use these fields of the ColumnDef node */
2805 : 758 : def->typeName = $6;
2806 : 758 : def->collClause = (CollateClause *) $7;
2807 : 758 : def->raw_default = $8;
2808 : 758 : def->location = @3;
2809 : 758 : $$ = (Node *) n;
2810 : : }
2811 : : /* ALTER FOREIGN TABLE <name> ALTER [COLUMN] <colname> OPTIONS */
2812 : : | ALTER opt_column ColId alter_generic_options
2813 : : {
2814 : 33 : AlterTableCmd *n = makeNode(AlterTableCmd);
2815 : :
2816 : 33 : n->subtype = AT_AlterColumnGenericOptions;
2817 : 33 : n->name = $3;
2818 : 33 : n->def = (Node *) $4;
2819 : 33 : $$ = (Node *) n;
2820 : : }
2821 : : /* ALTER TABLE <name> ADD CONSTRAINT ... */
2822 : : | ADD_P TableConstraint
2823 : : {
2824 : 9345 : AlterTableCmd *n = makeNode(AlterTableCmd);
2825 : :
2826 : 9345 : n->subtype = AT_AddConstraint;
2827 : 9345 : n->def = $2;
2828 : 9345 : $$ = (Node *) n;
2829 : : }
2830 : : /* ALTER TABLE <name> ALTER CONSTRAINT ... */
2831 : : | ALTER CONSTRAINT name ConstraintAttributeSpec
2832 : : {
2833 : 304 : AlterTableCmd *n = makeNode(AlterTableCmd);
2834 : 304 : ATAlterConstraint *c = makeNode(ATAlterConstraint);
2835 : :
2836 : 304 : n->subtype = AT_AlterConstraint;
2837 : 304 : n->def = (Node *) c;
2838 : 304 : c->conname = $3;
2839 [ + + ]: 304 : if ($4 & (CAS_NOT_ENFORCED | CAS_ENFORCED))
2840 : 196 : c->alterEnforceability = true;
2841 [ + + ]: 304 : if ($4 & (CAS_DEFERRABLE | CAS_NOT_DEFERRABLE |
2842 : : CAS_INITIALLY_DEFERRED | CAS_INITIALLY_IMMEDIATE))
2843 : 80 : c->alterDeferrability = true;
2844 [ + + ]: 304 : if ($4 & CAS_NO_INHERIT)
2845 : 24 : c->alterInheritability = true;
2846 : : /* handle unsupported case with specific error message */
2847 [ + + ]: 304 : if ($4 & CAS_NOT_VALID)
2848 [ + - ]: 8 : ereport(ERROR,
2849 : : errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
2850 : : errmsg("constraints cannot be altered to be NOT VALID"),
2851 : : parser_errposition(@4));
2852 : 296 : processCASbits($4, @4, "FOREIGN KEY",
2853 : : &c->deferrable,
2854 : : &c->initdeferred,
2855 : : &c->is_enforced,
2856 : : NULL,
2857 : : &c->noinherit,
2858 : : yyscanner);
2859 : 296 : $$ = (Node *) n;
2860 : : }
2861 : : /* ALTER TABLE <name> ALTER CONSTRAINT INHERIT */
2862 : : | ALTER CONSTRAINT name INHERIT
2863 : : {
2864 : 44 : AlterTableCmd *n = makeNode(AlterTableCmd);
2865 : 44 : ATAlterConstraint *c = makeNode(ATAlterConstraint);
2866 : :
2867 : 44 : n->subtype = AT_AlterConstraint;
2868 : 44 : n->def = (Node *) c;
2869 : 44 : c->conname = $3;
2870 : 44 : c->alterInheritability = true;
2871 : 44 : c->noinherit = false;
2872 : :
2873 : 44 : $$ = (Node *) n;
2874 : : }
2875 : : /* ALTER TABLE <name> VALIDATE CONSTRAINT ... */
2876 : : | VALIDATE CONSTRAINT name
2877 : : {
2878 : 275 : AlterTableCmd *n = makeNode(AlterTableCmd);
2879 : :
2880 : 275 : n->subtype = AT_ValidateConstraint;
2881 : 275 : n->name = $3;
2882 : 275 : $$ = (Node *) n;
2883 : : }
2884 : : /* ALTER TABLE <name> DROP CONSTRAINT IF EXISTS <name> [RESTRICT|CASCADE] */
2885 : : | DROP CONSTRAINT IF_P EXISTS name opt_drop_behavior
2886 : : {
2887 : 12 : AlterTableCmd *n = makeNode(AlterTableCmd);
2888 : :
2889 : 12 : n->subtype = AT_DropConstraint;
2890 : 12 : n->name = $5;
2891 : 12 : n->behavior = $6;
2892 : 12 : n->missing_ok = true;
2893 : 12 : $$ = (Node *) n;
2894 : : }
2895 : : /* ALTER TABLE <name> DROP CONSTRAINT <name> [RESTRICT|CASCADE] */
2896 : : | DROP CONSTRAINT name opt_drop_behavior
2897 : : {
2898 : 582 : AlterTableCmd *n = makeNode(AlterTableCmd);
2899 : :
2900 : 582 : n->subtype = AT_DropConstraint;
2901 : 582 : n->name = $3;
2902 : 582 : n->behavior = $4;
2903 : 582 : n->missing_ok = false;
2904 : 582 : $$ = (Node *) n;
2905 : : }
2906 : : /* ALTER TABLE <name> SET WITHOUT OIDS, for backward compat */
2907 : : | SET WITHOUT OIDS
2908 : : {
2909 : 4 : AlterTableCmd *n = makeNode(AlterTableCmd);
2910 : :
2911 : 4 : n->subtype = AT_DropOids;
2912 : 4 : $$ = (Node *) n;
2913 : : }
2914 : : /* ALTER TABLE <name> CLUSTER ON <indexname> */
2915 : : | CLUSTER ON name
2916 : : {
2917 : 31 : AlterTableCmd *n = makeNode(AlterTableCmd);
2918 : :
2919 : 31 : n->subtype = AT_ClusterOn;
2920 : 31 : n->name = $3;
2921 : 31 : $$ = (Node *) n;
2922 : : }
2923 : : /* ALTER TABLE <name> SET WITHOUT CLUSTER */
2924 : : | SET WITHOUT CLUSTER
2925 : : {
2926 : 12 : AlterTableCmd *n = makeNode(AlterTableCmd);
2927 : :
2928 : 12 : n->subtype = AT_DropCluster;
2929 : 12 : n->name = NULL;
2930 : 12 : $$ = (Node *) n;
2931 : : }
2932 : : /* ALTER TABLE <name> SET LOGGED */
2933 : : | SET LOGGED
2934 : : {
2935 : 34 : AlterTableCmd *n = makeNode(AlterTableCmd);
2936 : :
2937 : 34 : n->subtype = AT_SetLogged;
2938 : 34 : $$ = (Node *) n;
2939 : : }
2940 : : /* ALTER TABLE <name> SET UNLOGGED */
2941 : : | SET UNLOGGED
2942 : : {
2943 : 41 : AlterTableCmd *n = makeNode(AlterTableCmd);
2944 : :
2945 : 41 : n->subtype = AT_SetUnLogged;
2946 : 41 : $$ = (Node *) n;
2947 : : }
2948 : : /* ALTER TABLE <name> ENABLE TRIGGER <trig> */
2949 : : | ENABLE_P TRIGGER name
2950 : : {
2951 : 65 : AlterTableCmd *n = makeNode(AlterTableCmd);
2952 : :
2953 : 65 : n->subtype = AT_EnableTrig;
2954 : 65 : n->name = $3;
2955 : 65 : $$ = (Node *) n;
2956 : : }
2957 : : /* ALTER TABLE <name> ENABLE ALWAYS TRIGGER <trig> */
2958 : : | ENABLE_P ALWAYS TRIGGER name
2959 : : {
2960 : 27 : AlterTableCmd *n = makeNode(AlterTableCmd);
2961 : :
2962 : 27 : n->subtype = AT_EnableAlwaysTrig;
2963 : 27 : n->name = $4;
2964 : 27 : $$ = (Node *) n;
2965 : : }
2966 : : /* ALTER TABLE <name> ENABLE REPLICA TRIGGER <trig> */
2967 : : | ENABLE_P REPLICA TRIGGER name
2968 : : {
2969 : 8 : AlterTableCmd *n = makeNode(AlterTableCmd);
2970 : :
2971 : 8 : n->subtype = AT_EnableReplicaTrig;
2972 : 8 : n->name = $4;
2973 : 8 : $$ = (Node *) n;
2974 : : }
2975 : : /* ALTER TABLE <name> ENABLE TRIGGER ALL */
2976 : : | ENABLE_P TRIGGER ALL
2977 : : {
2978 : 0 : AlterTableCmd *n = makeNode(AlterTableCmd);
2979 : :
2980 : 0 : n->subtype = AT_EnableTrigAll;
2981 : 0 : $$ = (Node *) n;
2982 : : }
2983 : : /* ALTER TABLE <name> ENABLE TRIGGER USER */
2984 : : | ENABLE_P TRIGGER USER
2985 : : {
2986 : 0 : AlterTableCmd *n = makeNode(AlterTableCmd);
2987 : :
2988 : 0 : n->subtype = AT_EnableTrigUser;
2989 : 0 : $$ = (Node *) n;
2990 : : }
2991 : : /* ALTER TABLE <name> DISABLE TRIGGER <trig> */
2992 : : | DISABLE_P TRIGGER name
2993 : : {
2994 : 75 : AlterTableCmd *n = makeNode(AlterTableCmd);
2995 : :
2996 : 75 : n->subtype = AT_DisableTrig;
2997 : 75 : n->name = $3;
2998 : 75 : $$ = (Node *) n;
2999 : : }
3000 : : /* ALTER TABLE <name> DISABLE TRIGGER ALL */
3001 : : | DISABLE_P TRIGGER ALL
3002 : : {
3003 : 8 : AlterTableCmd *n = makeNode(AlterTableCmd);
3004 : :
3005 : 8 : n->subtype = AT_DisableTrigAll;
3006 : 8 : $$ = (Node *) n;
3007 : : }
3008 : : /* ALTER TABLE <name> DISABLE TRIGGER USER */
3009 : : | DISABLE_P TRIGGER USER
3010 : : {
3011 : 8 : AlterTableCmd *n = makeNode(AlterTableCmd);
3012 : :
3013 : 8 : n->subtype = AT_DisableTrigUser;
3014 : 8 : $$ = (Node *) n;
3015 : : }
3016 : : /* ALTER TABLE <name> ENABLE RULE <rule> */
3017 : : | ENABLE_P RULE name
3018 : : {
3019 : 5 : AlterTableCmd *n = makeNode(AlterTableCmd);
3020 : :
3021 : 5 : n->subtype = AT_EnableRule;
3022 : 5 : n->name = $3;
3023 : 5 : $$ = (Node *) n;
3024 : : }
3025 : : /* ALTER TABLE <name> ENABLE ALWAYS RULE <rule> */
3026 : : | ENABLE_P ALWAYS RULE name
3027 : : {
3028 : 0 : AlterTableCmd *n = makeNode(AlterTableCmd);
3029 : :
3030 : 0 : n->subtype = AT_EnableAlwaysRule;
3031 : 0 : n->name = $4;
3032 : 0 : $$ = (Node *) n;
3033 : : }
3034 : : /* ALTER TABLE <name> ENABLE REPLICA RULE <rule> */
3035 : : | ENABLE_P REPLICA RULE name
3036 : : {
3037 : 4 : AlterTableCmd *n = makeNode(AlterTableCmd);
3038 : :
3039 : 4 : n->subtype = AT_EnableReplicaRule;
3040 : 4 : n->name = $4;
3041 : 4 : $$ = (Node *) n;
3042 : : }
3043 : : /* ALTER TABLE <name> DISABLE RULE <rule> */
3044 : : | DISABLE_P RULE name
3045 : : {
3046 : 20 : AlterTableCmd *n = makeNode(AlterTableCmd);
3047 : :
3048 : 20 : n->subtype = AT_DisableRule;
3049 : 20 : n->name = $3;
3050 : 20 : $$ = (Node *) n;
3051 : : }
3052 : : /* ALTER TABLE <name> INHERIT <parent> */
3053 : : | INHERIT qualified_name
3054 : : {
3055 : 313 : AlterTableCmd *n = makeNode(AlterTableCmd);
3056 : :
3057 : 313 : n->subtype = AT_AddInherit;
3058 : 313 : n->def = (Node *) $2;
3059 : 313 : $$ = (Node *) n;
3060 : : }
3061 : : /* ALTER TABLE <name> NO INHERIT <parent> */
3062 : : | NO INHERIT qualified_name
3063 : : {
3064 : 81 : AlterTableCmd *n = makeNode(AlterTableCmd);
3065 : :
3066 : 81 : n->subtype = AT_DropInherit;
3067 : 81 : n->def = (Node *) $3;
3068 : 81 : $$ = (Node *) n;
3069 : : }
3070 : : /* ALTER TABLE <name> OF <type_name> */
3071 : : | OF any_name
3072 : : {
3073 : 42 : AlterTableCmd *n = makeNode(AlterTableCmd);
3074 : 42 : TypeName *def = makeTypeNameFromNameList($2);
3075 : :
3076 : 42 : def->location = @2;
3077 : 42 : n->subtype = AT_AddOf;
3078 : 42 : n->def = (Node *) def;
3079 : 42 : $$ = (Node *) n;
3080 : : }
3081 : : /* ALTER TABLE <name> NOT OF */
3082 : : | NOT OF
3083 : : {
3084 : 4 : AlterTableCmd *n = makeNode(AlterTableCmd);
3085 : :
3086 : 4 : n->subtype = AT_DropOf;
3087 : 4 : $$ = (Node *) n;
3088 : : }
3089 : : /* ALTER TABLE <name> OWNER TO RoleSpec */
3090 : : | OWNER TO RoleSpec
3091 : : {
3092 : 1165 : AlterTableCmd *n = makeNode(AlterTableCmd);
3093 : :
3094 : 1165 : n->subtype = AT_ChangeOwner;
3095 : 1165 : n->newowner = $3;
3096 : 1165 : $$ = (Node *) n;
3097 : : }
3098 : : /* ALTER TABLE <name> SET ACCESS METHOD { <amname> | DEFAULT } */
3099 : : | SET ACCESS METHOD set_access_method_name
3100 : : {
3101 : 85 : AlterTableCmd *n = makeNode(AlterTableCmd);
3102 : :
3103 : 85 : n->subtype = AT_SetAccessMethod;
3104 : 85 : n->name = $4;
3105 : 85 : $$ = (Node *) n;
3106 : : }
3107 : : /* ALTER TABLE <name> SET TABLESPACE <tablespacename> */
3108 : : | SET TABLESPACE name
3109 : : {
3110 : 73 : AlterTableCmd *n = makeNode(AlterTableCmd);
3111 : :
3112 : 73 : n->subtype = AT_SetTableSpace;
3113 : 73 : n->name = $3;
3114 : 73 : $$ = (Node *) n;
3115 : : }
3116 : : /* ALTER TABLE <name> SET (...) */
3117 : : | SET reloptions
3118 : : {
3119 : 387 : AlterTableCmd *n = makeNode(AlterTableCmd);
3120 : :
3121 : 387 : n->subtype = AT_SetRelOptions;
3122 : 387 : n->def = (Node *) $2;
3123 : 387 : $$ = (Node *) n;
3124 : : }
3125 : : /* ALTER TABLE <name> RESET (...) */
3126 : : | RESET reloptions
3127 : : {
3128 : 111 : AlterTableCmd *n = makeNode(AlterTableCmd);
3129 : :
3130 : 111 : n->subtype = AT_ResetRelOptions;
3131 : 111 : n->def = (Node *) $2;
3132 : 111 : $$ = (Node *) n;
3133 : : }
3134 : : /* ALTER TABLE <name> REPLICA IDENTITY */
3135 : : | REPLICA IDENTITY_P replica_identity
3136 : : {
3137 : 306 : AlterTableCmd *n = makeNode(AlterTableCmd);
3138 : :
3139 : 306 : n->subtype = AT_ReplicaIdentity;
3140 : 306 : n->def = $3;
3141 : 306 : $$ = (Node *) n;
3142 : : }
3143 : : /* ALTER TABLE <name> ENABLE ROW LEVEL SECURITY */
3144 : : | ENABLE_P ROW LEVEL SECURITY
3145 : : {
3146 : 248 : AlterTableCmd *n = makeNode(AlterTableCmd);
3147 : :
3148 : 248 : n->subtype = AT_EnableRowSecurity;
3149 : 248 : $$ = (Node *) n;
3150 : : }
3151 : : /* ALTER TABLE <name> DISABLE ROW LEVEL SECURITY */
3152 : : | DISABLE_P ROW LEVEL SECURITY
3153 : : {
3154 : 6 : AlterTableCmd *n = makeNode(AlterTableCmd);
3155 : :
3156 : 6 : n->subtype = AT_DisableRowSecurity;
3157 : 6 : $$ = (Node *) n;
3158 : : }
3159 : : /* ALTER TABLE <name> FORCE ROW LEVEL SECURITY */
3160 : : | FORCE ROW LEVEL SECURITY
3161 : : {
3162 : 70 : AlterTableCmd *n = makeNode(AlterTableCmd);
3163 : :
3164 : 70 : n->subtype = AT_ForceRowSecurity;
3165 : 70 : $$ = (Node *) n;
3166 : : }
3167 : : /* ALTER TABLE <name> NO FORCE ROW LEVEL SECURITY */
3168 : : | NO FORCE ROW LEVEL SECURITY
3169 : : {
3170 : 20 : AlterTableCmd *n = makeNode(AlterTableCmd);
3171 : :
3172 : 20 : n->subtype = AT_NoForceRowSecurity;
3173 : 20 : $$ = (Node *) n;
3174 : : }
3175 : : | alter_generic_options
3176 : : {
3177 : 37 : AlterTableCmd *n = makeNode(AlterTableCmd);
3178 : :
3179 : 37 : n->subtype = AT_GenericOptions;
3180 : 37 : n->def = (Node *) $1;
3181 : 37 : $$ = (Node *) n;
3182 : : }
3183 : : ;
3184 : :
3185 : : alter_column_default:
3186 : 246 : SET DEFAULT a_expr { $$ = $3; }
3187 : 124 : | DROP DEFAULT { $$ = NULL; }
3188 : : ;
3189 : :
3190 : : opt_collate_clause:
3191 : : COLLATE any_name
3192 : : {
3193 : 12 : CollateClause *n = makeNode(CollateClause);
3194 : :
3195 : 12 : n->arg = NULL;
3196 : 12 : n->collname = $2;
3197 : 12 : n->location = @1;
3198 : 12 : $$ = (Node *) n;
3199 : : }
3200 : 3100 : | /* EMPTY */ { $$ = NULL; }
3201 : : ;
3202 : :
3203 : : alter_using:
3204 : 119 : USING a_expr { $$ = $2; }
3205 : 639 : | /* EMPTY */ { $$ = NULL; }
3206 : : ;
3207 : :
3208 : : replica_identity:
3209 : : NOTHING
3210 : : {
3211 : 30 : ReplicaIdentityStmt *n = makeNode(ReplicaIdentityStmt);
3212 : :
3213 : 30 : n->identity_type = REPLICA_IDENTITY_NOTHING;
3214 : 30 : n->name = NULL;
3215 : 30 : $$ = (Node *) n;
3216 : : }
3217 : : | FULL
3218 : : {
3219 : 98 : ReplicaIdentityStmt *n = makeNode(ReplicaIdentityStmt);
3220 : :
3221 : 98 : n->identity_type = REPLICA_IDENTITY_FULL;
3222 : 98 : n->name = NULL;
3223 : 98 : $$ = (Node *) n;
3224 : : }
3225 : : | DEFAULT
3226 : : {
3227 : 5 : ReplicaIdentityStmt *n = makeNode(ReplicaIdentityStmt);
3228 : :
3229 : 5 : n->identity_type = REPLICA_IDENTITY_DEFAULT;
3230 : 5 : n->name = NULL;
3231 : 5 : $$ = (Node *) n;
3232 : : }
3233 : : | USING INDEX name
3234 : : {
3235 : 173 : ReplicaIdentityStmt *n = makeNode(ReplicaIdentityStmt);
3236 : :
3237 : 173 : n->identity_type = REPLICA_IDENTITY_INDEX;
3238 : 173 : n->name = $3;
3239 : 173 : $$ = (Node *) n;
3240 : : }
3241 : : ;
3242 : :
3243 : : reloptions:
3244 : 1820 : '(' reloption_list ')' { $$ = $2; }
3245 : : ;
3246 : :
3247 : 590 : opt_reloptions: WITH reloptions { $$ = $2; }
3248 : 15438 : | /* EMPTY */ { $$ = NIL; }
3249 : : ;
3250 : :
3251 : : reloption_list:
3252 : 1820 : reloption_elem { $$ = list_make1($1); }
3253 : 163 : | reloption_list ',' reloption_elem { $$ = lappend($1, $3); }
3254 : : ;
3255 : :
3256 : : /* This should match def_elem and also allow qualified names */
3257 : : reloption_elem:
3258 : : ColLabel '=' def_arg
3259 : : {
3260 : 1568 : $$ = makeDefElem($1, (Node *) $3, @1);
3261 : : }
3262 : : | ColLabel
3263 : : {
3264 : 365 : $$ = makeDefElem($1, NULL, @1);
3265 : : }
3266 : : | ColLabel '.' ColLabel '=' def_arg
3267 : : {
3268 : 46 : $$ = makeDefElemExtended($1, $3, (Node *) $5,
3269 : 46 : DEFELEM_UNSPEC, @1);
3270 : : }
3271 : : | ColLabel '.' ColLabel
3272 : : {
3273 : 4 : $$ = makeDefElemExtended($1, $3, NULL, DEFELEM_UNSPEC, @1);
3274 : : }
3275 : : ;
3276 : :
3277 : : alter_identity_column_option_list:
3278 : : alter_identity_column_option
3279 : 41 : { $$ = list_make1($1); }
3280 : : | alter_identity_column_option_list alter_identity_column_option
3281 : 40 : { $$ = lappend($1, $2); }
3282 : : ;
3283 : :
3284 : : alter_identity_column_option:
3285 : : RESTART
3286 : : {
3287 : 16 : $$ = makeDefElem("restart", NULL, @1);
3288 : : }
3289 : : | RESTART opt_with NumericOnly
3290 : : {
3291 : 0 : $$ = makeDefElem("restart", (Node *) $3, @1);
3292 : : }
3293 : : | SET SeqOptElem
3294 : : {
3295 [ + - ]: 36 : if (strcmp($2->defname, "as") == 0 ||
3296 [ + - ]: 36 : strcmp($2->defname, "restart") == 0 ||
3297 [ - + ]: 36 : strcmp($2->defname, "owned_by") == 0)
3298 [ # # ]: 0 : ereport(ERROR,
3299 : : (errcode(ERRCODE_SYNTAX_ERROR),
3300 : : errmsg("sequence option \"%s\" not supported here", $2->defname),
3301 : : parser_errposition(@2)));
3302 : 36 : $$ = $2;
3303 : : }
3304 : : | SET GENERATED generated_when
3305 : : {
3306 : 29 : $$ = makeDefElem("generated", (Node *) makeInteger($3), @1);
3307 : : }
3308 : : ;
3309 : :
3310 : : set_statistics_value:
3311 : 105 : SignedIconst { $$ = (Node *) makeInteger($1); }
3312 : 2 : | DEFAULT { $$ = NULL; }
3313 : : ;
3314 : :
3315 : : set_access_method_name:
3316 : 61 : ColId { $$ = $1; }
3317 : 24 : | DEFAULT { $$ = NULL; }
3318 : : ;
3319 : :
3320 : : PartitionBoundSpec:
3321 : : /* a HASH partition */
3322 : : FOR VALUES WITH '(' hash_partbound ')'
3323 : : {
3324 : : ListCell *lc;
3325 : 500 : PartitionBoundSpec *n = makeNode(PartitionBoundSpec);
3326 : :
3327 : 500 : n->strategy = PARTITION_STRATEGY_HASH;
3328 : 500 : n->modulus = n->remainder = -1;
3329 : :
3330 [ + - + + : 1500 : foreach (lc, $5)
+ + ]
3331 : : {
3332 : 1000 : DefElem *opt = lfirst_node(DefElem, lc);
3333 : :
3334 [ + + ]: 1000 : if (strcmp(opt->defname, "modulus") == 0)
3335 : : {
3336 [ - + ]: 500 : if (n->modulus != -1)
3337 [ # # ]: 0 : ereport(ERROR,
3338 : : (errcode(ERRCODE_DUPLICATE_OBJECT),
3339 : : errmsg("modulus for hash partition provided more than once"),
3340 : : parser_errposition(opt->location)));
3341 : 500 : n->modulus = defGetInt32(opt);
3342 : : }
3343 [ + - ]: 500 : else if (strcmp(opt->defname, "remainder") == 0)
3344 : : {
3345 [ - + ]: 500 : if (n->remainder != -1)
3346 [ # # ]: 0 : ereport(ERROR,
3347 : : (errcode(ERRCODE_DUPLICATE_OBJECT),
3348 : : errmsg("remainder for hash partition provided more than once"),
3349 : : parser_errposition(opt->location)));
3350 : 500 : n->remainder = defGetInt32(opt);
3351 : : }
3352 : : else
3353 [ # # ]: 0 : ereport(ERROR,
3354 : : (errcode(ERRCODE_SYNTAX_ERROR),
3355 : : errmsg("unrecognized hash partition bound specification \"%s\"",
3356 : : opt->defname),
3357 : : parser_errposition(opt->location)));
3358 : : }
3359 : :
3360 [ - + ]: 500 : if (n->modulus == -1)
3361 [ # # ]: 0 : ereport(ERROR,
3362 : : (errcode(ERRCODE_SYNTAX_ERROR),
3363 : : errmsg("modulus for hash partition must be specified"),
3364 : : parser_errposition(@3)));
3365 [ - + ]: 500 : if (n->remainder == -1)
3366 [ # # ]: 0 : ereport(ERROR,
3367 : : (errcode(ERRCODE_SYNTAX_ERROR),
3368 : : errmsg("remainder for hash partition must be specified"),
3369 : : parser_errposition(@3)));
3370 : :
3371 : 500 : n->location = @3;
3372 : :
3373 : 500 : $$ = n;
3374 : : }
3375 : :
3376 : : /* a LIST partition */
3377 : : | FOR VALUES IN_P '(' expr_list ')'
3378 : : {
3379 : 3369 : PartitionBoundSpec *n = makeNode(PartitionBoundSpec);
3380 : :
3381 : 3369 : n->strategy = PARTITION_STRATEGY_LIST;
3382 : 3369 : n->is_default = false;
3383 : 3369 : n->listdatums = $5;
3384 : 3369 : n->location = @3;
3385 : :
3386 : 3369 : $$ = n;
3387 : : }
3388 : :
3389 : : /* a RANGE partition */
3390 : : | FOR VALUES FROM '(' expr_list ')' TO '(' expr_list ')'
3391 : : {
3392 : 4570 : PartitionBoundSpec *n = makeNode(PartitionBoundSpec);
3393 : :
3394 : 4570 : n->strategy = PARTITION_STRATEGY_RANGE;
3395 : 4570 : n->is_default = false;
3396 : 4570 : n->lowerdatums = $5;
3397 : 4570 : n->upperdatums = $9;
3398 : 4570 : n->location = @3;
3399 : :
3400 : 4570 : $$ = n;
3401 : : }
3402 : :
3403 : : /* a DEFAULT partition */
3404 : : | DEFAULT
3405 : : {
3406 : 572 : PartitionBoundSpec *n = makeNode(PartitionBoundSpec);
3407 : :
3408 : 572 : n->is_default = true;
3409 : 572 : n->location = @1;
3410 : :
3411 : 572 : $$ = n;
3412 : : }
3413 : : ;
3414 : :
3415 : : hash_partbound_elem:
3416 : : NonReservedWord Iconst
3417 : : {
3418 : 1000 : $$ = makeDefElem($1, (Node *) makeInteger($2), @1);
3419 : : }
3420 : : ;
3421 : :
3422 : : hash_partbound:
3423 : : hash_partbound_elem
3424 : : {
3425 : 500 : $$ = list_make1($1);
3426 : : }
3427 : : | hash_partbound ',' hash_partbound_elem
3428 : : {
3429 : 500 : $$ = lappend($1, $3);
3430 : : }
3431 : : ;
3432 : :
3433 : : /*****************************************************************************
3434 : : *
3435 : : * ALTER TYPE
3436 : : *
3437 : : * really variants of the ALTER TABLE subcommands with different spellings
3438 : : *****************************************************************************/
3439 : :
3440 : : AlterCompositeTypeStmt:
3441 : : ALTER TYPE_P any_name alter_type_cmds
3442 : : {
3443 : 141 : AlterTableStmt *n = makeNode(AlterTableStmt);
3444 : :
3445 : : /* can't use qualified_name, sigh */
3446 : 141 : n->relation = makeRangeVarFromAnyName($3, @3, yyscanner);
3447 : 141 : n->cmds = $4;
3448 : 141 : n->objtype = OBJECT_TYPE;
3449 : 141 : $$ = (Node *) n;
3450 : : }
3451 : : ;
3452 : :
3453 : : alter_type_cmds:
3454 : 141 : alter_type_cmd { $$ = list_make1($1); }
3455 : 8 : | alter_type_cmds ',' alter_type_cmd { $$ = lappend($1, $3); }
3456 : : ;
3457 : :
3458 : : alter_type_cmd:
3459 : : /* ALTER TYPE <name> ADD ATTRIBUTE <coldef> [RESTRICT|CASCADE] */
3460 : : ADD_P ATTRIBUTE TableFuncElement opt_drop_behavior
3461 : : {
3462 : 46 : AlterTableCmd *n = makeNode(AlterTableCmd);
3463 : :
3464 : 46 : n->subtype = AT_AddColumn;
3465 : 46 : n->def = $3;
3466 : 46 : n->behavior = $4;
3467 : 46 : $$ = (Node *) n;
3468 : : }
3469 : : /* ALTER TYPE <name> DROP ATTRIBUTE IF EXISTS <attname> [RESTRICT|CASCADE] */
3470 : : | DROP ATTRIBUTE IF_P EXISTS ColId opt_drop_behavior
3471 : : {
3472 : 4 : AlterTableCmd *n = makeNode(AlterTableCmd);
3473 : :
3474 : 4 : n->subtype = AT_DropColumn;
3475 : 4 : n->name = $5;
3476 : 4 : n->behavior = $6;
3477 : 4 : n->missing_ok = true;
3478 : 4 : $$ = (Node *) n;
3479 : : }
3480 : : /* ALTER TYPE <name> DROP ATTRIBUTE <attname> [RESTRICT|CASCADE] */
3481 : : | DROP ATTRIBUTE ColId opt_drop_behavior
3482 : : {
3483 : 50 : AlterTableCmd *n = makeNode(AlterTableCmd);
3484 : :
3485 : 50 : n->subtype = AT_DropColumn;
3486 : 50 : n->name = $3;
3487 : 50 : n->behavior = $4;
3488 : 50 : n->missing_ok = false;
3489 : 50 : $$ = (Node *) n;
3490 : : }
3491 : : /* ALTER TYPE <name> ALTER ATTRIBUTE <attname> [SET DATA] TYPE <typename> [RESTRICT|CASCADE] */
3492 : : | ALTER ATTRIBUTE ColId opt_set_data TYPE_P Typename opt_collate_clause opt_drop_behavior
3493 : : {
3494 : 49 : AlterTableCmd *n = makeNode(AlterTableCmd);
3495 : 49 : ColumnDef *def = makeNode(ColumnDef);
3496 : :
3497 : 49 : n->subtype = AT_AlterColumnType;
3498 : 49 : n->name = $3;
3499 : 49 : n->def = (Node *) def;
3500 : 49 : n->behavior = $8;
3501 : : /* We only use these fields of the ColumnDef node */
3502 : 49 : def->typeName = $6;
3503 : 49 : def->collClause = (CollateClause *) $7;
3504 : 49 : def->raw_default = NULL;
3505 : 49 : def->location = @3;
3506 : 49 : $$ = (Node *) n;
3507 : : }
3508 : : ;
3509 : :
3510 : :
3511 : : /*****************************************************************************
3512 : : *
3513 : : * QUERY :
3514 : : * close <portalname>
3515 : : *
3516 : : *****************************************************************************/
3517 : :
3518 : : ClosePortalStmt:
3519 : : CLOSE cursor_name
3520 : : {
3521 : 1177 : ClosePortalStmt *n = makeNode(ClosePortalStmt);
3522 : :
3523 : 1177 : n->portalname = $2;
3524 : 1177 : $$ = (Node *) n;
3525 : : }
3526 : : | CLOSE ALL
3527 : : {
3528 : 8 : ClosePortalStmt *n = makeNode(ClosePortalStmt);
3529 : :
3530 : 8 : n->portalname = NULL;
3531 : 8 : $$ = (Node *) n;
3532 : : }
3533 : : ;
3534 : :
3535 : :
3536 : : /*****************************************************************************
3537 : : *
3538 : : * QUERY :
3539 : : * COPY relname [(columnList)] FROM/TO file [WITH] [(options)]
3540 : : * COPY ( query ) TO file [WITH] [(options)]
3541 : : *
3542 : : * where 'query' can be one of:
3543 : : * { SELECT | UPDATE | INSERT | DELETE | MERGE }
3544 : : *
3545 : : * and 'file' can be one of:
3546 : : * { PROGRAM 'command' | STDIN | STDOUT | 'filename' }
3547 : : *
3548 : : * In the preferred syntax the options are comma-separated
3549 : : * and use generic identifiers instead of keywords. The pre-9.0
3550 : : * syntax had a hard-wired, space-separated set of options.
3551 : : *
3552 : : * Really old syntax, from versions 7.2 and prior:
3553 : : * COPY [ BINARY ] table FROM/TO file
3554 : : * [ [ USING ] DELIMITERS 'delimiter' ] ]
3555 : : * [ WITH NULL AS 'null string' ]
3556 : : * This option placement is not supported with COPY (query...).
3557 : : *
3558 : : *****************************************************************************/
3559 : :
3560 : : CopyStmt: COPY opt_binary qualified_name opt_column_list
3561 : : copy_from opt_program copy_file_name copy_delimiter opt_with
3562 : : copy_options where_clause
3563 : : {
3564 : 6353 : CopyStmt *n = makeNode(CopyStmt);
3565 : :
3566 : 6353 : n->relation = $3;
3567 : 6353 : n->query = NULL;
3568 : 6353 : n->attlist = $4;
3569 : 6353 : n->is_from = $5;
3570 : 6353 : n->is_program = $6;
3571 : 6353 : n->filename = $7;
3572 : 6353 : n->whereClause = $11;
3573 : :
3574 [ + + - + ]: 6353 : if (n->is_program && n->filename == NULL)
3575 [ # # ]: 0 : ereport(ERROR,
3576 : : (errcode(ERRCODE_SYNTAX_ERROR),
3577 : : errmsg("STDIN/STDOUT not allowed with PROGRAM"),
3578 : : parser_errposition(@8)));
3579 : :
3580 [ + + + + ]: 6353 : if (!n->is_from && n->whereClause != NULL)
3581 [ + - ]: 4 : ereport(ERROR,
3582 : : (errcode(ERRCODE_SYNTAX_ERROR),
3583 : : errmsg("WHERE clause not allowed with COPY TO"),
3584 : : errhint("Try the COPY (SELECT ... WHERE ...) TO variant."),
3585 : : parser_errposition(@11)));
3586 : :
3587 : 6349 : n->options = NIL;
3588 : : /* Concatenate user-supplied flags */
3589 [ + + ]: 6349 : if ($2)
3590 : 8 : n->options = lappend(n->options, $2);
3591 [ - + ]: 6349 : if ($8)
3592 : 0 : n->options = lappend(n->options, $8);
3593 [ + + ]: 6349 : if ($10)
3594 : 862 : n->options = list_concat(n->options, $10);
3595 : 6349 : $$ = (Node *) n;
3596 : : }
3597 : : | COPY '(' PreparableStmt ')' TO opt_program copy_file_name opt_with copy_options
3598 : : {
3599 : 363 : CopyStmt *n = makeNode(CopyStmt);
3600 : :
3601 : 363 : n->relation = NULL;
3602 : 363 : n->query = $3;
3603 : 363 : n->attlist = NIL;
3604 : 363 : n->is_from = false;
3605 : 363 : n->is_program = $6;
3606 : 363 : n->filename = $7;
3607 : 363 : n->options = $9;
3608 : :
3609 [ - + - - ]: 363 : if (n->is_program && n->filename == NULL)
3610 [ # # ]: 0 : ereport(ERROR,
3611 : : (errcode(ERRCODE_SYNTAX_ERROR),
3612 : : errmsg("STDIN/STDOUT not allowed with PROGRAM"),
3613 : : parser_errposition(@5)));
3614 : :
3615 : 363 : $$ = (Node *) n;
3616 : : }
3617 : : ;
3618 : :
3619 : : copy_from:
3620 : 1244 : FROM { $$ = true; }
3621 : 5109 : | TO { $$ = false; }
3622 : : ;
3623 : :
3624 : : opt_program:
3625 : 1 : PROGRAM { $$ = true; }
3626 : 6715 : | /* EMPTY */ { $$ = false; }
3627 : : ;
3628 : :
3629 : : /*
3630 : : * copy_file_name NULL indicates stdio is used. Whether stdin or stdout is
3631 : : * used depends on the direction. (It really doesn't make sense to copy from
3632 : : * stdout. We silently correct the "typo".) - AY 9/94
3633 : : */
3634 : : copy_file_name:
3635 : 317 : Sconst { $$ = $1; }
3636 : 985 : | STDIN { $$ = NULL; }
3637 : 5414 : | STDOUT { $$ = NULL; }
3638 : : ;
3639 : :
3640 : 5999 : copy_options: copy_opt_list { $$ = $1; }
3641 : 717 : | '(' copy_generic_opt_list ')' { $$ = $2; }
3642 : : ;
3643 : :
3644 : : /* old COPY option syntax */
3645 : : copy_opt_list:
3646 : 345 : copy_opt_list copy_opt_item { $$ = lappend($1, $2); }
3647 : 5999 : | /* EMPTY */ { $$ = NIL; }
3648 : : ;
3649 : :
3650 : : copy_opt_item:
3651 : : BINARY
3652 : : {
3653 : 0 : $$ = makeDefElem("format", (Node *) makeString("binary"), @1);
3654 : : }
3655 : : | FREEZE
3656 : : {
3657 : 32 : $$ = makeDefElem("freeze", (Node *) makeBoolean(true), @1);
3658 : : }
3659 : : | DELIMITER opt_as Sconst
3660 : : {
3661 : 117 : $$ = makeDefElem("delimiter", (Node *) makeString($3), @1);
3662 : : }
3663 : : | NULL_P opt_as Sconst
3664 : : {
3665 : 32 : $$ = makeDefElem("null", (Node *) makeString($3), @1);
3666 : : }
3667 : : | CSV
3668 : : {
3669 : 100 : $$ = makeDefElem("format", (Node *) makeString("csv"), @1);
3670 : : }
3671 : : | JSON
3672 : : {
3673 : 8 : $$ = makeDefElem("format", (Node *) makeString("json"), @1);
3674 : : }
3675 : : | HEADER_P
3676 : : {
3677 : 12 : $$ = makeDefElem("header", (Node *) makeBoolean(true), @1);
3678 : : }
3679 : : | QUOTE opt_as Sconst
3680 : : {
3681 : 12 : $$ = makeDefElem("quote", (Node *) makeString($3), @1);
3682 : : }
3683 : : | ESCAPE opt_as Sconst
3684 : : {
3685 : 12 : $$ = makeDefElem("escape", (Node *) makeString($3), @1);
3686 : : }
3687 : : | FORCE QUOTE columnList
3688 : : {
3689 : 8 : $$ = makeDefElem("force_quote", (Node *) $3, @1);
3690 : : }
3691 : : | FORCE QUOTE '*'
3692 : : {
3693 : 4 : $$ = makeDefElem("force_quote", (Node *) makeNode(A_Star), @1);
3694 : : }
3695 : : | FORCE NOT NULL_P columnList
3696 : : {
3697 : 0 : $$ = makeDefElem("force_not_null", (Node *) $4, @1);
3698 : : }
3699 : : | FORCE NOT NULL_P '*'
3700 : : {
3701 : 0 : $$ = makeDefElem("force_not_null", (Node *) makeNode(A_Star), @1);
3702 : : }
3703 : : | FORCE NULL_P columnList
3704 : : {
3705 : 0 : $$ = makeDefElem("force_null", (Node *) $3, @1);
3706 : : }
3707 : : | FORCE NULL_P '*'
3708 : : {
3709 : 0 : $$ = makeDefElem("force_null", (Node *) makeNode(A_Star), @1);
3710 : : }
3711 : : | ENCODING Sconst
3712 : : {
3713 : 8 : $$ = makeDefElem("encoding", (Node *) makeString($2), @1);
3714 : : }
3715 : : ;
3716 : :
3717 : : /* The following exist for backward compatibility with very old versions */
3718 : :
3719 : : opt_binary:
3720 : : BINARY
3721 : : {
3722 : 8 : $$ = makeDefElem("format", (Node *) makeString("binary"), @1);
3723 : : }
3724 : 6345 : | /*EMPTY*/ { $$ = NULL; }
3725 : : ;
3726 : :
3727 : : copy_delimiter:
3728 : : opt_using DELIMITERS Sconst
3729 : : {
3730 : 0 : $$ = makeDefElem("delimiter", (Node *) makeString($3), @2);
3731 : : }
3732 : 6353 : | /*EMPTY*/ { $$ = NULL; }
3733 : : ;
3734 : :
3735 : : opt_using:
3736 : : USING
3737 : : | /*EMPTY*/
3738 : : ;
3739 : :
3740 : : /* new COPY option syntax */
3741 : : copy_generic_opt_list:
3742 : : copy_generic_opt_elem
3743 : : {
3744 : 717 : $$ = list_make1($1);
3745 : : }
3746 : : | copy_generic_opt_list ',' copy_generic_opt_elem
3747 : : {
3748 : 439 : $$ = lappend($1, $3);
3749 : : }
3750 : : ;
3751 : :
3752 : : copy_generic_opt_elem:
3753 : : ColLabel copy_generic_opt_arg
3754 : : {
3755 : 1008 : $$ = makeDefElem($1, $2, @1);
3756 : : }
3757 : : | FORMAT_LA copy_generic_opt_arg
3758 : : {
3759 : 148 : $$ = makeDefElem("format", $2, @1);
3760 : : }
3761 : : ;
3762 : :
3763 : : copy_generic_opt_arg:
3764 : 880 : opt_boolean_or_string { $$ = (Node *) makeString($1); }
3765 : 52 : | NumericOnly { $$ = (Node *) $1; }
3766 : 72 : | '*' { $$ = (Node *) makeNode(A_Star); }
3767 : 4 : | DEFAULT { $$ = (Node *) makeString("default"); }
3768 : 100 : | '(' copy_generic_opt_arg_list ')' { $$ = (Node *) $2; }
3769 : 48 : | /* EMPTY */ { $$ = NULL; }
3770 : : ;
3771 : :
3772 : : copy_generic_opt_arg_list:
3773 : : copy_generic_opt_arg_list_item
3774 : : {
3775 : 100 : $$ = list_make1($1);
3776 : : }
3777 : : | copy_generic_opt_arg_list ',' copy_generic_opt_arg_list_item
3778 : : {
3779 : 8 : $$ = lappend($1, $3);
3780 : : }
3781 : : ;
3782 : :
3783 : : /* beware of emitting non-string list elements here; see commands/define.c */
3784 : : copy_generic_opt_arg_list_item:
3785 : 108 : opt_boolean_or_string { $$ = (Node *) makeString($1); }
3786 : : ;
3787 : :
3788 : :
3789 : : /*****************************************************************************
3790 : : *
3791 : : * QUERY :
3792 : : * CREATE TABLE relname
3793 : : *
3794 : : *****************************************************************************/
3795 : :
3796 : : CreateStmt: CREATE OptTemp TABLE qualified_name '(' OptTableElementList ')'
3797 : : OptInherit OptPartitionSpec table_access_method_clause OptWith
3798 : : OnCommitOption OptTableSpace
3799 : : {
3800 : 20014 : CreateStmt *n = makeNode(CreateStmt);
3801 : :
3802 : 20014 : $4->relpersistence = $2;
3803 : 20014 : n->relation = $4;
3804 : 20014 : n->tableElts = $6;
3805 : 20014 : n->inhRelations = $8;
3806 : 20014 : n->partspec = $9;
3807 : 20014 : n->ofTypename = NULL;
3808 : 20014 : n->constraints = NIL;
3809 : 20014 : n->accessMethod = $10;
3810 : 20014 : n->options = $11;
3811 : 20014 : n->oncommit = $12;
3812 : 20014 : n->tablespacename = $13;
3813 : 20014 : n->if_not_exists = false;
3814 : 20014 : $$ = (Node *) n;
3815 : : }
3816 : : | CREATE OptTemp TABLE IF_P NOT EXISTS qualified_name '('
3817 : : OptTableElementList ')' OptInherit OptPartitionSpec table_access_method_clause
3818 : : OptWith OnCommitOption OptTableSpace
3819 : : {
3820 : 16 : CreateStmt *n = makeNode(CreateStmt);
3821 : :
3822 : 16 : $7->relpersistence = $2;
3823 : 16 : n->relation = $7;
3824 : 16 : n->tableElts = $9;
3825 : 16 : n->inhRelations = $11;
3826 : 16 : n->partspec = $12;
3827 : 16 : n->ofTypename = NULL;
3828 : 16 : n->constraints = NIL;
3829 : 16 : n->accessMethod = $13;
3830 : 16 : n->options = $14;
3831 : 16 : n->oncommit = $15;
3832 : 16 : n->tablespacename = $16;
3833 : 16 : n->if_not_exists = true;
3834 : 16 : $$ = (Node *) n;
3835 : : }
3836 : : | CREATE OptTemp TABLE qualified_name OF any_name
3837 : : OptTypedTableElementList OptPartitionSpec table_access_method_clause
3838 : : OptWith OnCommitOption OptTableSpace
3839 : : {
3840 : 81 : CreateStmt *n = makeNode(CreateStmt);
3841 : :
3842 : 81 : $4->relpersistence = $2;
3843 : 81 : n->relation = $4;
3844 : 81 : n->tableElts = $7;
3845 : 81 : n->inhRelations = NIL;
3846 : 81 : n->partspec = $8;
3847 : 81 : n->ofTypename = makeTypeNameFromNameList($6);
3848 : 81 : n->ofTypename->location = @6;
3849 : 81 : n->constraints = NIL;
3850 : 81 : n->accessMethod = $9;
3851 : 81 : n->options = $10;
3852 : 81 : n->oncommit = $11;
3853 : 81 : n->tablespacename = $12;
3854 : 81 : n->if_not_exists = false;
3855 : 81 : $$ = (Node *) n;
3856 : : }
3857 : : | CREATE OptTemp TABLE IF_P NOT EXISTS qualified_name OF any_name
3858 : : OptTypedTableElementList OptPartitionSpec table_access_method_clause
3859 : : OptWith OnCommitOption OptTableSpace
3860 : : {
3861 : 4 : CreateStmt *n = makeNode(CreateStmt);
3862 : :
3863 : 4 : $7->relpersistence = $2;
3864 : 4 : n->relation = $7;
3865 : 4 : n->tableElts = $10;
3866 : 4 : n->inhRelations = NIL;
3867 : 4 : n->partspec = $11;
3868 : 4 : n->ofTypename = makeTypeNameFromNameList($9);
3869 : 4 : n->ofTypename->location = @9;
3870 : 4 : n->constraints = NIL;
3871 : 4 : n->accessMethod = $12;
3872 : 4 : n->options = $13;
3873 : 4 : n->oncommit = $14;
3874 : 4 : n->tablespacename = $15;
3875 : 4 : n->if_not_exists = true;
3876 : 4 : $$ = (Node *) n;
3877 : : }
3878 : : | CREATE OptTemp TABLE qualified_name PARTITION OF qualified_name
3879 : : OptTypedTableElementList PartitionBoundSpec OptPartitionSpec
3880 : : table_access_method_clause OptWith OnCommitOption OptTableSpace
3881 : : {
3882 : 6517 : CreateStmt *n = makeNode(CreateStmt);
3883 : :
3884 : 6517 : $4->relpersistence = $2;
3885 : 6517 : n->relation = $4;
3886 : 6517 : n->tableElts = $8;
3887 : 6517 : n->inhRelations = list_make1($7);
3888 : 6517 : n->partbound = $9;
3889 : 6517 : n->partspec = $10;
3890 : 6517 : n->ofTypename = NULL;
3891 : 6517 : n->constraints = NIL;
3892 : 6517 : n->accessMethod = $11;
3893 : 6517 : n->options = $12;
3894 : 6517 : n->oncommit = $13;
3895 : 6517 : n->tablespacename = $14;
3896 : 6517 : n->if_not_exists = false;
3897 : 6517 : $$ = (Node *) n;
3898 : : }
3899 : : | CREATE OptTemp TABLE IF_P NOT EXISTS qualified_name PARTITION OF
3900 : : qualified_name OptTypedTableElementList PartitionBoundSpec OptPartitionSpec
3901 : : table_access_method_clause OptWith OnCommitOption OptTableSpace
3902 : : {
3903 : 0 : CreateStmt *n = makeNode(CreateStmt);
3904 : :
3905 : 0 : $7->relpersistence = $2;
3906 : 0 : n->relation = $7;
3907 : 0 : n->tableElts = $11;
3908 : 0 : n->inhRelations = list_make1($10);
3909 : 0 : n->partbound = $12;
3910 : 0 : n->partspec = $13;
3911 : 0 : n->ofTypename = NULL;
3912 : 0 : n->constraints = NIL;
3913 : 0 : n->accessMethod = $14;
3914 : 0 : n->options = $15;
3915 : 0 : n->oncommit = $16;
3916 : 0 : n->tablespacename = $17;
3917 : 0 : n->if_not_exists = true;
3918 : 0 : $$ = (Node *) n;
3919 : : }
3920 : : ;
3921 : :
3922 : : /*
3923 : : * Redundancy here is needed to avoid shift/reduce conflicts,
3924 : : * since TEMP is not a reserved word. See also OptTempTableName.
3925 : : *
3926 : : * NOTE: we accept both GLOBAL and LOCAL options. They currently do nothing,
3927 : : * but future versions might consider GLOBAL to request SQL-spec-compliant
3928 : : * temp table behavior, so warn about that. Since we have no modules the
3929 : : * LOCAL keyword is really meaningless; furthermore, some other products
3930 : : * implement LOCAL as meaning the same as our default temp table behavior,
3931 : : * so we'll probably continue to treat LOCAL as a noise word.
3932 : : */
3933 : 243 : OptTemp: TEMPORARY { $$ = RELPERSISTENCE_TEMP; }
3934 : 2017 : | TEMP { $$ = RELPERSISTENCE_TEMP; }
3935 : 0 : | LOCAL TEMPORARY { $$ = RELPERSISTENCE_TEMP; }
3936 : 0 : | LOCAL TEMP { $$ = RELPERSISTENCE_TEMP; }
3937 : : | GLOBAL TEMPORARY
3938 : : {
3939 [ # # ]: 0 : ereport(WARNING,
3940 : : (errmsg("GLOBAL is deprecated in temporary table creation"),
3941 : : parser_errposition(@1)));
3942 : 0 : $$ = RELPERSISTENCE_TEMP;
3943 : : }
3944 : : | GLOBAL TEMP
3945 : : {
3946 [ # # ]: 0 : ereport(WARNING,
3947 : : (errmsg("GLOBAL is deprecated in temporary table creation"),
3948 : : parser_errposition(@1)));
3949 : 0 : $$ = RELPERSISTENCE_TEMP;
3950 : : }
3951 : 117 : | UNLOGGED { $$ = RELPERSISTENCE_UNLOGGED; }
3952 : 36935 : | /*EMPTY*/ { $$ = RELPERSISTENCE_PERMANENT; }
3953 : : ;
3954 : :
3955 : : OptTableElementList:
3956 : 19225 : TableElementList { $$ = $1; }
3957 : 1083 : | /*EMPTY*/ { $$ = NIL; }
3958 : : ;
3959 : :
3960 : : OptTypedTableElementList:
3961 : 217 : '(' TypedTableElementList ')' { $$ = $2; }
3962 : 6444 : | /*EMPTY*/ { $$ = NIL; }
3963 : : ;
3964 : :
3965 : : TableElementList:
3966 : : TableElement
3967 : : {
3968 : 19261 : $$ = list_make1($1);
3969 : : }
3970 : : | TableElementList ',' TableElement
3971 : : {
3972 : 27385 : $$ = lappend($1, $3);
3973 : : }
3974 : : ;
3975 : :
3976 : : TypedTableElementList:
3977 : : TypedTableElement
3978 : : {
3979 : 217 : $$ = list_make1($1);
3980 : : }
3981 : : | TypedTableElementList ',' TypedTableElement
3982 : : {
3983 : 45 : $$ = lappend($1, $3);
3984 : : }
3985 : : ;
3986 : :
3987 : : TableElement:
3988 : 44107 : columnDef { $$ = $1; }
3989 : 525 : | TableLikeClause { $$ = $1; }
3990 : 2014 : | TableConstraint { $$ = $1; }
3991 : : ;
3992 : :
3993 : : TypedTableElement:
3994 : 220 : columnOptions { $$ = $1; }
3995 : 42 : | TableConstraint { $$ = $1; }
3996 : : ;
3997 : :
3998 : : columnDef: ColId Typename opt_column_storage opt_column_compression create_generic_options ColQualList
3999 : : {
4000 : 45694 : ColumnDef *n = makeNode(ColumnDef);
4001 : :
4002 : 45694 : n->colname = $1;
4003 : 45694 : n->typeName = $2;
4004 : 45694 : n->storage_name = $3;
4005 : 45694 : n->compression = $4;
4006 : 45694 : n->inhcount = 0;
4007 : 45694 : n->is_local = true;
4008 : 45694 : n->is_not_null = false;
4009 : 45694 : n->is_from_type = false;
4010 : 45694 : n->storage = 0;
4011 : 45694 : n->raw_default = NULL;
4012 : 45694 : n->cooked_default = NULL;
4013 : 45694 : n->collOid = InvalidOid;
4014 : 45694 : n->fdwoptions = $5;
4015 : 45694 : SplitColQualList($6, &n->constraints, &n->collClause,
4016 : : yyscanner);
4017 : 45694 : n->location = @1;
4018 : 45694 : $$ = (Node *) n;
4019 : : }
4020 : : ;
4021 : :
4022 : : columnOptions: ColId ColQualList
4023 : : {
4024 : 91 : ColumnDef *n = makeNode(ColumnDef);
4025 : :
4026 : 91 : n->colname = $1;
4027 : 91 : n->typeName = NULL;
4028 : 91 : n->inhcount = 0;
4029 : 91 : n->is_local = true;
4030 : 91 : n->is_not_null = false;
4031 : 91 : n->is_from_type = false;
4032 : 91 : n->storage = 0;
4033 : 91 : n->raw_default = NULL;
4034 : 91 : n->cooked_default = NULL;
4035 : 91 : n->collOid = InvalidOid;
4036 : 91 : SplitColQualList($2, &n->constraints, &n->collClause,
4037 : : yyscanner);
4038 : 91 : n->location = @1;
4039 : 91 : $$ = (Node *) n;
4040 : : }
4041 : : | ColId WITH OPTIONS ColQualList
4042 : : {
4043 : 129 : ColumnDef *n = makeNode(ColumnDef);
4044 : :
4045 : 129 : n->colname = $1;
4046 : 129 : n->typeName = NULL;
4047 : 129 : n->inhcount = 0;
4048 : 129 : n->is_local = true;
4049 : 129 : n->is_not_null = false;
4050 : 129 : n->is_from_type = false;
4051 : 129 : n->storage = 0;
4052 : 129 : n->raw_default = NULL;
4053 : 129 : n->cooked_default = NULL;
4054 : 129 : n->collOid = InvalidOid;
4055 : 129 : SplitColQualList($4, &n->constraints, &n->collClause,
4056 : : yyscanner);
4057 : 129 : n->location = @1;
4058 : 129 : $$ = (Node *) n;
4059 : : }
4060 : : ;
4061 : :
4062 : : column_compression:
4063 : 115 : COMPRESSION ColId { $$ = $2; }
4064 : 5 : | COMPRESSION DEFAULT { $$ = pstrdup("default"); }
4065 : : ;
4066 : :
4067 : : opt_column_compression:
4068 : 72 : column_compression { $$ = $1; }
4069 : 45666 : | /*EMPTY*/ { $$ = NULL; }
4070 : : ;
4071 : :
4072 : : column_storage:
4073 : 203 : STORAGE ColId { $$ = $2; }
4074 : 4 : | STORAGE DEFAULT { $$ = pstrdup("default"); }
4075 : : ;
4076 : :
4077 : : opt_column_storage:
4078 : 39 : column_storage { $$ = $1; }
4079 : 45699 : | /*EMPTY*/ { $$ = NULL; }
4080 : : ;
4081 : :
4082 : : ColQualList:
4083 : 13650 : ColQualList ColConstraint { $$ = lappend($1, $2); }
4084 : 46959 : | /*EMPTY*/ { $$ = NIL; }
4085 : : ;
4086 : :
4087 : : ColConstraint:
4088 : : CONSTRAINT name ColConstraintElem
4089 : : {
4090 : 525 : Constraint *n = castNode(Constraint, $3);
4091 : :
4092 : 525 : n->conname = $2;
4093 : 525 : n->location = @1;
4094 : 525 : $$ = (Node *) n;
4095 : : }
4096 : 12324 : | ColConstraintElem { $$ = $1; }
4097 : 283 : | ConstraintAttr { $$ = $1; }
4098 : : | COLLATE any_name
4099 : : {
4100 : : /*
4101 : : * Note: the CollateClause is momentarily included in
4102 : : * the list built by ColQualList, but we split it out
4103 : : * again in SplitColQualList.
4104 : : */
4105 : 518 : CollateClause *n = makeNode(CollateClause);
4106 : :
4107 : 518 : n->arg = NULL;
4108 : 518 : n->collname = $2;
4109 : 518 : n->location = @1;
4110 : 518 : $$ = (Node *) n;
4111 : : }
4112 : : ;
4113 : :
4114 : : /* DEFAULT NULL is already the default for Postgres.
4115 : : * But define it here and carry it forward into the system
4116 : : * to make it explicit.
4117 : : * - thomas 1998-09-13
4118 : : *
4119 : : * WITH NULL and NULL are not SQL-standard syntax elements,
4120 : : * so leave them out. Use DEFAULT NULL to explicitly indicate
4121 : : * that a column may have that value. WITH NULL leads to
4122 : : * shift/reduce conflicts with WITH TIME ZONE anyway.
4123 : : * - thomas 1999-01-08
4124 : : *
4125 : : * DEFAULT expression must be b_expr not a_expr to prevent shift/reduce
4126 : : * conflict on NOT (since NOT might start a subsequent NOT NULL constraint,
4127 : : * or be part of a_expr NOT LIKE or similar constructs).
4128 : : */
4129 : : ColConstraintElem:
4130 : : NOT NULL_P opt_no_inherit
4131 : : {
4132 : 4531 : Constraint *n = makeNode(Constraint);
4133 : :
4134 : 4531 : n->contype = CONSTR_NOTNULL;
4135 : 4531 : n->location = @1;
4136 : 4531 : n->is_no_inherit = $3;
4137 : 4531 : n->is_enforced = true;
4138 : 4531 : n->skip_validation = false;
4139 : 4531 : n->initially_valid = true;
4140 : 4531 : $$ = (Node *) n;
4141 : : }
4142 : : | NULL_P
4143 : : {
4144 : 19 : Constraint *n = makeNode(Constraint);
4145 : :
4146 : 19 : n->contype = CONSTR_NULL;
4147 : 19 : n->location = @1;
4148 : 19 : $$ = (Node *) n;
4149 : : }
4150 : : | UNIQUE opt_unique_null_treatment opt_definition OptConsTableSpace
4151 : : {
4152 : 303 : Constraint *n = makeNode(Constraint);
4153 : :
4154 : 303 : n->contype = CONSTR_UNIQUE;
4155 : 303 : n->location = @1;
4156 : 303 : n->nulls_not_distinct = !$2;
4157 : 303 : n->keys = NULL;
4158 : 303 : n->options = $3;
4159 : 303 : n->indexname = NULL;
4160 : 303 : n->indexspace = $4;
4161 : 303 : $$ = (Node *) n;
4162 : : }
4163 : : | PRIMARY KEY opt_definition OptConsTableSpace
4164 : : {
4165 : 3708 : Constraint *n = makeNode(Constraint);
4166 : :
4167 : 3708 : n->contype = CONSTR_PRIMARY;
4168 : 3708 : n->location = @1;
4169 : 3708 : n->keys = NULL;
4170 : 3708 : n->options = $3;
4171 : 3708 : n->indexname = NULL;
4172 : 3708 : n->indexspace = $4;
4173 : 3708 : $$ = (Node *) n;
4174 : : }
4175 : : | CHECK '(' a_expr ')' opt_no_inherit
4176 : : {
4177 : 779 : Constraint *n = makeNode(Constraint);
4178 : :
4179 : 779 : n->contype = CONSTR_CHECK;
4180 : 779 : n->location = @1;
4181 : 779 : n->is_no_inherit = $5;
4182 : 779 : n->raw_expr = $3;
4183 : 779 : n->cooked_expr = NULL;
4184 : 779 : n->is_enforced = true;
4185 : 779 : n->skip_validation = false;
4186 : 779 : n->initially_valid = true;
4187 : 779 : $$ = (Node *) n;
4188 : : }
4189 : : | DEFAULT b_expr
4190 : : {
4191 : 1223 : Constraint *n = makeNode(Constraint);
4192 : :
4193 : 1223 : n->contype = CONSTR_DEFAULT;
4194 : 1223 : n->location = @1;
4195 : 1223 : n->raw_expr = $2;
4196 : 1223 : n->cooked_expr = NULL;
4197 : 1223 : $$ = (Node *) n;
4198 : : }
4199 : : | GENERATED generated_when AS IDENTITY_P OptParenthesizedSeqOptList
4200 : : {
4201 : 248 : Constraint *n = makeNode(Constraint);
4202 : :
4203 : 248 : n->contype = CONSTR_IDENTITY;
4204 : 248 : n->generated_when = $2;
4205 : 248 : n->options = $5;
4206 : 248 : n->location = @1;
4207 : 248 : $$ = (Node *) n;
4208 : : }
4209 : : | GENERATED generated_when AS '(' a_expr ')' opt_virtual_or_stored
4210 : : {
4211 : 1376 : Constraint *n = makeNode(Constraint);
4212 : :
4213 : 1376 : n->contype = CONSTR_GENERATED;
4214 : 1376 : n->generated_when = $2;
4215 : 1376 : n->raw_expr = $5;
4216 : 1376 : n->cooked_expr = NULL;
4217 : 1376 : n->generated_kind = $7;
4218 : 1376 : n->location = @1;
4219 : :
4220 : : /*
4221 : : * Can't do this in the grammar because of shift/reduce
4222 : : * conflicts. (IDENTITY allows both ALWAYS and BY
4223 : : * DEFAULT, but generated columns only allow ALWAYS.) We
4224 : : * can also give a more useful error message and location.
4225 : : */
4226 [ + + ]: 1376 : if ($2 != ATTRIBUTE_IDENTITY_ALWAYS)
4227 [ + - ]: 8 : ereport(ERROR,
4228 : : (errcode(ERRCODE_SYNTAX_ERROR),
4229 : : errmsg("for a generated column, GENERATED ALWAYS must be specified"),
4230 : : parser_errposition(@2)));
4231 : :
4232 : 1368 : $$ = (Node *) n;
4233 : : }
4234 : : | REFERENCES qualified_name opt_column_list key_match key_actions
4235 : : {
4236 : 670 : Constraint *n = makeNode(Constraint);
4237 : :
4238 : 670 : n->contype = CONSTR_FOREIGN;
4239 : 670 : n->location = @1;
4240 : 670 : n->pktable = $2;
4241 : 670 : n->fk_attrs = NIL;
4242 : 670 : n->pk_attrs = $3;
4243 : 670 : n->fk_matchtype = $4;
4244 : 670 : n->fk_upd_action = ($5)->updateAction->action;
4245 : 670 : n->fk_del_action = ($5)->deleteAction->action;
4246 : 670 : n->fk_del_set_cols = ($5)->deleteAction->cols;
4247 : 670 : n->is_enforced = true;
4248 : 670 : n->skip_validation = false;
4249 : 670 : n->initially_valid = true;
4250 : 670 : $$ = (Node *) n;
4251 : : }
4252 : : ;
4253 : :
4254 : : opt_unique_null_treatment:
4255 : 8 : NULLS_P DISTINCT { $$ = true; }
4256 : 24 : | NULLS_P NOT DISTINCT { $$ = false; }
4257 : 5230 : | /*EMPTY*/ { $$ = true; }
4258 : : ;
4259 : :
4260 : : generated_when:
4261 : 1642 : ALWAYS { $$ = ATTRIBUTE_IDENTITY_ALWAYS; }
4262 : 118 : | BY DEFAULT { $$ = ATTRIBUTE_IDENTITY_BY_DEFAULT; }
4263 : : ;
4264 : :
4265 : : opt_virtual_or_stored:
4266 : 742 : STORED { $$ = ATTRIBUTE_GENERATED_STORED; }
4267 : 463 : | VIRTUAL { $$ = ATTRIBUTE_GENERATED_VIRTUAL; }
4268 : 171 : | /*EMPTY*/ { $$ = ATTRIBUTE_GENERATED_VIRTUAL; }
4269 : : ;
4270 : :
4271 : : /*
4272 : : * ConstraintAttr represents constraint attributes, which we parse as if
4273 : : * they were independent constraint clauses, in order to avoid shift/reduce
4274 : : * conflicts (since NOT might start either an independent NOT NULL clause
4275 : : * or an attribute). parse_utilcmd.c is responsible for attaching the
4276 : : * attribute information to the preceding "real" constraint node, and for
4277 : : * complaining if attribute clauses appear in the wrong place or wrong
4278 : : * combinations.
4279 : : *
4280 : : * See also ConstraintAttributeSpec, which can be used in places where
4281 : : * there is no parsing conflict. (Note: currently, NOT VALID and NO INHERIT
4282 : : * are allowed clauses in ConstraintAttributeSpec, but not here. Someday we
4283 : : * might need to allow them here too, but for the moment it doesn't seem
4284 : : * useful in the statements that use ConstraintAttr.)
4285 : : */
4286 : : ConstraintAttr:
4287 : : DEFERRABLE
4288 : : {
4289 : 92 : Constraint *n = makeNode(Constraint);
4290 : :
4291 : 92 : n->contype = CONSTR_ATTR_DEFERRABLE;
4292 : 92 : n->location = @1;
4293 : 92 : $$ = (Node *) n;
4294 : : }
4295 : : | NOT DEFERRABLE
4296 : : {
4297 : 4 : Constraint *n = makeNode(Constraint);
4298 : :
4299 : 4 : n->contype = CONSTR_ATTR_NOT_DEFERRABLE;
4300 : 4 : n->location = @1;
4301 : 4 : $$ = (Node *) n;
4302 : : }
4303 : : | INITIALLY DEFERRED
4304 : : {
4305 : 70 : Constraint *n = makeNode(Constraint);
4306 : :
4307 : 70 : n->contype = CONSTR_ATTR_DEFERRED;
4308 : 70 : n->location = @1;
4309 : 70 : $$ = (Node *) n;
4310 : : }
4311 : : | INITIALLY IMMEDIATE
4312 : : {
4313 : 8 : Constraint *n = makeNode(Constraint);
4314 : :
4315 : 8 : n->contype = CONSTR_ATTR_IMMEDIATE;
4316 : 8 : n->location = @1;
4317 : 8 : $$ = (Node *) n;
4318 : : }
4319 : : | ENFORCED
4320 : : {
4321 : 52 : Constraint *n = makeNode(Constraint);
4322 : :
4323 : 52 : n->contype = CONSTR_ATTR_ENFORCED;
4324 : 52 : n->location = @1;
4325 : 52 : $$ = (Node *) n;
4326 : : }
4327 : : | NOT ENFORCED
4328 : : {
4329 : 57 : Constraint *n = makeNode(Constraint);
4330 : :
4331 : 57 : n->contype = CONSTR_ATTR_NOT_ENFORCED;
4332 : 57 : n->location = @1;
4333 : 57 : $$ = (Node *) n;
4334 : : }
4335 : : ;
4336 : :
4337 : :
4338 : : TableLikeClause:
4339 : : LIKE qualified_name TableLikeOptionList
4340 : : {
4341 : 525 : TableLikeClause *n = makeNode(TableLikeClause);
4342 : :
4343 : 525 : n->relation = $2;
4344 : 525 : n->options = $3;
4345 : 525 : n->relationOid = InvalidOid;
4346 : 525 : $$ = (Node *) n;
4347 : : }
4348 : : ;
4349 : :
4350 : : TableLikeOptionList:
4351 : 199 : TableLikeOptionList INCLUDING TableLikeOption { $$ = $1 | $3; }
4352 : 5 : | TableLikeOptionList EXCLUDING TableLikeOption { $$ = $1 & ~$3; }
4353 : 525 : | /* EMPTY */ { $$ = 0; }
4354 : : ;
4355 : :
4356 : : TableLikeOption:
4357 : 20 : COMMENTS { $$ = CREATE_TABLE_LIKE_COMMENTS; }
4358 : 4 : | COMPRESSION { $$ = CREATE_TABLE_LIKE_COMPRESSION; }
4359 : 36 : | CONSTRAINTS { $$ = CREATE_TABLE_LIKE_CONSTRAINTS; }
4360 : 13 : | DEFAULTS { $$ = CREATE_TABLE_LIKE_DEFAULTS; }
4361 : 8 : | IDENTITY_P { $$ = CREATE_TABLE_LIKE_IDENTITY; }
4362 : 20 : | GENERATED { $$ = CREATE_TABLE_LIKE_GENERATED; }
4363 : 33 : | INDEXES { $$ = CREATE_TABLE_LIKE_INDEXES; }
4364 : 8 : | STATISTICS { $$ = CREATE_TABLE_LIKE_STATISTICS; }
4365 : 17 : | STORAGE { $$ = CREATE_TABLE_LIKE_STORAGE; }
4366 : 45 : | ALL { $$ = CREATE_TABLE_LIKE_ALL; }
4367 : : ;
4368 : :
4369 : :
4370 : : /* ConstraintElem specifies constraint syntax which is not embedded into
4371 : : * a column definition. ColConstraintElem specifies the embedded form.
4372 : : * - thomas 1997-12-03
4373 : : */
4374 : : TableConstraint:
4375 : : CONSTRAINT name ConstraintElem
4376 : : {
4377 : 2860 : Constraint *n = castNode(Constraint, $3);
4378 : :
4379 : 2860 : n->conname = $2;
4380 : 2860 : n->location = @1;
4381 : 2860 : $$ = (Node *) n;
4382 : : }
4383 : 8541 : | ConstraintElem { $$ = $1; }
4384 : : ;
4385 : :
4386 : : ConstraintElem:
4387 : : CHECK '(' a_expr ')' ConstraintAttributeSpec
4388 : : {
4389 : 949 : Constraint *n = makeNode(Constraint);
4390 : :
4391 : 949 : n->contype = CONSTR_CHECK;
4392 : 949 : n->location = @1;
4393 : 949 : n->raw_expr = $3;
4394 : 949 : n->cooked_expr = NULL;
4395 : 949 : processCASbits($5, @5, "CHECK",
4396 : : NULL, NULL, &n->is_enforced, &n->skip_validation,
4397 : : &n->is_no_inherit, yyscanner);
4398 : 949 : n->initially_valid = !n->skip_validation;
4399 : 949 : $$ = (Node *) n;
4400 : : }
4401 : : | NOT NULL_P ColId ConstraintAttributeSpec
4402 : : {
4403 : 441 : Constraint *n = makeNode(Constraint);
4404 : :
4405 : 441 : n->contype = CONSTR_NOTNULL;
4406 : 441 : n->location = @1;
4407 : 441 : n->keys = list_make1(makeString($3));
4408 : 441 : processCASbits($4, @4, "NOT NULL",
4409 : : NULL, NULL, NULL, &n->skip_validation,
4410 : : &n->is_no_inherit, yyscanner);
4411 : 441 : n->initially_valid = !n->skip_validation;
4412 : 441 : $$ = (Node *) n;
4413 : : }
4414 : : | UNIQUE opt_unique_null_treatment '(' columnList opt_without_overlaps ')' opt_c_include opt_definition OptConsTableSpace
4415 : : ConstraintAttributeSpec
4416 : : {
4417 : 406 : Constraint *n = makeNode(Constraint);
4418 : :
4419 : 406 : n->contype = CONSTR_UNIQUE;
4420 : 406 : n->location = @1;
4421 : 406 : n->nulls_not_distinct = !$2;
4422 : 406 : n->keys = $4;
4423 : 406 : n->without_overlaps = $5;
4424 : 406 : n->including = $7;
4425 : 406 : n->options = $8;
4426 : 406 : n->indexname = NULL;
4427 : 406 : n->indexspace = $9;
4428 : 406 : processCASbits($10, @10, "UNIQUE",
4429 : : &n->deferrable, &n->initdeferred, NULL,
4430 : : NULL, NULL, yyscanner);
4431 : 406 : $$ = (Node *) n;
4432 : : }
4433 : : | UNIQUE ExistingIndex ConstraintAttributeSpec
4434 : : {
4435 : 2941 : Constraint *n = makeNode(Constraint);
4436 : :
4437 : 2941 : n->contype = CONSTR_UNIQUE;
4438 : 2941 : n->location = @1;
4439 : 2941 : n->keys = NIL;
4440 : 2941 : n->including = NIL;
4441 : 2941 : n->options = NIL;
4442 : 2941 : n->indexname = $2;
4443 : 2941 : n->indexspace = NULL;
4444 : 2941 : processCASbits($3, @3, "UNIQUE",
4445 : : &n->deferrable, &n->initdeferred, NULL,
4446 : : NULL, NULL, yyscanner);
4447 : 2941 : $$ = (Node *) n;
4448 : : }
4449 : : | PRIMARY KEY '(' columnList opt_without_overlaps ')' opt_c_include opt_definition OptConsTableSpace
4450 : : ConstraintAttributeSpec
4451 : : {
4452 : 1558 : Constraint *n = makeNode(Constraint);
4453 : :
4454 : 1558 : n->contype = CONSTR_PRIMARY;
4455 : 1558 : n->location = @1;
4456 : 1558 : n->keys = $4;
4457 : 1558 : n->without_overlaps = $5;
4458 : 1558 : n->including = $7;
4459 : 1558 : n->options = $8;
4460 : 1558 : n->indexname = NULL;
4461 : 1558 : n->indexspace = $9;
4462 : 1558 : processCASbits($10, @10, "PRIMARY KEY",
4463 : : &n->deferrable, &n->initdeferred, NULL,
4464 : : NULL, NULL, yyscanner);
4465 : 1558 : $$ = (Node *) n;
4466 : : }
4467 : : | PRIMARY KEY ExistingIndex ConstraintAttributeSpec
4468 : : {
4469 : 3729 : Constraint *n = makeNode(Constraint);
4470 : :
4471 : 3729 : n->contype = CONSTR_PRIMARY;
4472 : 3729 : n->location = @1;
4473 : 3729 : n->keys = NIL;
4474 : 3729 : n->including = NIL;
4475 : 3729 : n->options = NIL;
4476 : 3729 : n->indexname = $3;
4477 : 3729 : n->indexspace = NULL;
4478 : 3729 : processCASbits($4, @4, "PRIMARY KEY",
4479 : : &n->deferrable, &n->initdeferred, NULL,
4480 : : NULL, NULL, yyscanner);
4481 : 3729 : $$ = (Node *) n;
4482 : : }
4483 : : | EXCLUDE access_method_clause '(' ExclusionConstraintList ')'
4484 : : opt_c_include opt_definition OptConsTableSpace OptWhereClause
4485 : : ConstraintAttributeSpec
4486 : : {
4487 : 169 : Constraint *n = makeNode(Constraint);
4488 : :
4489 : 169 : n->contype = CONSTR_EXCLUSION;
4490 : 169 : n->location = @1;
4491 : 169 : n->access_method = $2;
4492 : 169 : n->exclusions = $4;
4493 : 169 : n->including = $6;
4494 : 169 : n->options = $7;
4495 : 169 : n->indexname = NULL;
4496 : 169 : n->indexspace = $8;
4497 : 169 : n->where_clause = $9;
4498 : 169 : processCASbits($10, @10, "EXCLUDE",
4499 : : &n->deferrable, &n->initdeferred, NULL,
4500 : : NULL, NULL, yyscanner);
4501 : 169 : $$ = (Node *) n;
4502 : : }
4503 : : | FOREIGN KEY '(' columnList optionalPeriodName ')' REFERENCES qualified_name
4504 : : opt_column_and_period_list key_match key_actions ConstraintAttributeSpec
4505 : : {
4506 : 1208 : Constraint *n = makeNode(Constraint);
4507 : :
4508 : 1208 : n->contype = CONSTR_FOREIGN;
4509 : 1208 : n->location = @1;
4510 : 1208 : n->pktable = $8;
4511 : 1208 : n->fk_attrs = $4;
4512 [ + + ]: 1208 : if ($5)
4513 : : {
4514 : 210 : n->fk_attrs = lappend(n->fk_attrs, $5);
4515 : 210 : n->fk_with_period = true;
4516 : : }
4517 : 1208 : n->pk_attrs = linitial($9);
4518 [ + + ]: 1208 : if (lsecond($9))
4519 : : {
4520 : 112 : n->pk_attrs = lappend(n->pk_attrs, lsecond($9));
4521 : 112 : n->pk_with_period = true;
4522 : : }
4523 : 1208 : n->fk_matchtype = $10;
4524 : 1208 : n->fk_upd_action = ($11)->updateAction->action;
4525 : 1208 : n->fk_del_action = ($11)->deleteAction->action;
4526 : 1208 : n->fk_del_set_cols = ($11)->deleteAction->cols;
4527 : 1208 : processCASbits($12, @12, "FOREIGN KEY",
4528 : : &n->deferrable, &n->initdeferred,
4529 : : &n->is_enforced, &n->skip_validation, NULL,
4530 : : yyscanner);
4531 : 1208 : n->initially_valid = !n->skip_validation;
4532 : 1208 : $$ = (Node *) n;
4533 : : }
4534 : : ;
4535 : :
4536 : : /*
4537 : : * DomainConstraint is separate from TableConstraint because the syntax for
4538 : : * NOT NULL constraints is different. For table constraints, we need to
4539 : : * accept a column name, but for domain constraints, we don't. (We could
4540 : : * accept something like NOT NULL VALUE, but that seems weird.) CREATE DOMAIN
4541 : : * (which uses ColQualList) has for a long time accepted NOT NULL without a
4542 : : * column name, so it makes sense that ALTER DOMAIN (which uses
4543 : : * DomainConstraint) does as well. None of these syntaxes are per SQL
4544 : : * standard; we are just living with the bits of inconsistency that have built
4545 : : * up over time.
4546 : : */
4547 : : DomainConstraint:
4548 : : CONSTRAINT name DomainConstraintElem
4549 : : {
4550 : 109 : Constraint *n = castNode(Constraint, $3);
4551 : :
4552 : 109 : n->conname = $2;
4553 : 109 : n->location = @1;
4554 : 109 : $$ = (Node *) n;
4555 : : }
4556 : 12 : | DomainConstraintElem { $$ = $1; }
4557 : : ;
4558 : :
4559 : : DomainConstraintElem:
4560 : : CHECK '(' a_expr ')' ConstraintAttributeSpec
4561 : : {
4562 : 109 : Constraint *n = makeNode(Constraint);
4563 : :
4564 : 109 : n->contype = CONSTR_CHECK;
4565 : 109 : n->location = @1;
4566 : 109 : n->raw_expr = $3;
4567 : 109 : n->cooked_expr = NULL;
4568 : 109 : processCASbits($5, @5, "CHECK",
4569 : : NULL, NULL, NULL, &n->skip_validation,
4570 : : &n->is_no_inherit, yyscanner);
4571 : 101 : n->is_enforced = true;
4572 : 101 : n->initially_valid = !n->skip_validation;
4573 : 101 : $$ = (Node *) n;
4574 : : }
4575 : : | NOT NULL_P ConstraintAttributeSpec
4576 : : {
4577 : 20 : Constraint *n = makeNode(Constraint);
4578 : :
4579 : 20 : n->contype = CONSTR_NOTNULL;
4580 : 20 : n->location = @1;
4581 : 20 : n->keys = list_make1(makeString("value"));
4582 : : /* no NOT VALID, NO INHERIT support */
4583 : 20 : processCASbits($3, @3, "NOT NULL",
4584 : : NULL, NULL, NULL,
4585 : : NULL, NULL, yyscanner);
4586 : 20 : n->initially_valid = true;
4587 : 20 : $$ = (Node *) n;
4588 : : }
4589 : : ;
4590 : :
4591 : 97 : opt_no_inherit: NO INHERIT { $$ = true; }
4592 : 5213 : | /* EMPTY */ { $$ = false; }
4593 : : ;
4594 : :
4595 : : opt_without_overlaps:
4596 : 545 : WITHOUT OVERLAPS { $$ = true; }
4597 : 1419 : | /*EMPTY*/ { $$ = false; }
4598 : : ;
4599 : :
4600 : : opt_column_list:
4601 : 5995 : '(' columnList ')' { $$ = $2; }
4602 : 22875 : | /*EMPTY*/ { $$ = NIL; }
4603 : : ;
4604 : :
4605 : : columnList:
4606 : 11522 : columnElem { $$ = list_make1($1); }
4607 : 16540 : | columnList ',' columnElem { $$ = lappend($1, $3); }
4608 : : ;
4609 : :
4610 : : optionalPeriodName:
4611 : 322 : ',' PERIOD columnElem { $$ = $3; }
4612 : 1591 : | /*EMPTY*/ { $$ = NULL; }
4613 : : ;
4614 : :
4615 : : opt_column_and_period_list:
4616 : 701 : '(' columnList optionalPeriodName ')' { $$ = list_make2($2, $3); }
4617 : 511 : | /*EMPTY*/ { $$ = list_make2(NIL, NULL); }
4618 : : ;
4619 : :
4620 : : columnElem: ColId
4621 : : {
4622 : 28384 : $$ = (Node *) makeString($1);
4623 : : }
4624 : : ;
4625 : :
4626 : 100 : opt_c_include: INCLUDE '(' columnList ')' { $$ = $3; }
4627 : 2033 : | /* EMPTY */ { $$ = NIL; }
4628 : : ;
4629 : :
4630 : : key_match: MATCH FULL
4631 : : {
4632 : 65 : $$ = FKCONSTR_MATCH_FULL;
4633 : : }
4634 : : | MATCH PARTIAL
4635 : : {
4636 [ # # ]: 0 : ereport(ERROR,
4637 : : (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
4638 : : errmsg("MATCH PARTIAL not yet implemented"),
4639 : : parser_errposition(@1)));
4640 : : $$ = FKCONSTR_MATCH_PARTIAL;
4641 : : }
4642 : : | MATCH SIMPLE
4643 : : {
4644 : 4 : $$ = FKCONSTR_MATCH_SIMPLE;
4645 : : }
4646 : : | /*EMPTY*/
4647 : : {
4648 : 1813 : $$ = FKCONSTR_MATCH_SIMPLE;
4649 : : }
4650 : : ;
4651 : :
4652 : : ExclusionConstraintList:
4653 : 169 : ExclusionConstraintElem { $$ = list_make1($1); }
4654 : : | ExclusionConstraintList ',' ExclusionConstraintElem
4655 : 83 : { $$ = lappend($1, $3); }
4656 : : ;
4657 : :
4658 : : ExclusionConstraintElem: index_elem WITH any_operator
4659 : : {
4660 : 252 : $$ = list_make2($1, $3);
4661 : : }
4662 : : /* allow OPERATOR() decoration for the benefit of ruleutils.c */
4663 : : | index_elem WITH OPERATOR '(' any_operator ')'
4664 : : {
4665 : 0 : $$ = list_make2($1, $5);
4666 : : }
4667 : : ;
4668 : :
4669 : : OptWhereClause:
4670 : 308 : WHERE '(' a_expr ')' { $$ = $3; }
4671 : 836 : | /*EMPTY*/ { $$ = NULL; }
4672 : : ;
4673 : :
4674 : : key_actions:
4675 : : key_update
4676 : : {
4677 : 49 : KeyActions *n = palloc_object(KeyActions);
4678 : :
4679 : 49 : n->updateAction = $1;
4680 : 49 : n->deleteAction = palloc_object(KeyAction);
4681 : 49 : n->deleteAction->action = FKCONSTR_ACTION_NOACTION;
4682 : 49 : n->deleteAction->cols = NIL;
4683 : 49 : $$ = n;
4684 : : }
4685 : : | key_delete
4686 : : {
4687 : 93 : KeyActions *n = palloc_object(KeyActions);
4688 : :
4689 : 93 : n->updateAction = palloc_object(KeyAction);
4690 : 93 : n->updateAction->action = FKCONSTR_ACTION_NOACTION;
4691 : 93 : n->updateAction->cols = NIL;
4692 : 93 : n->deleteAction = $1;
4693 : 93 : $$ = n;
4694 : : }
4695 : : | key_update key_delete
4696 : : {
4697 : 111 : KeyActions *n = palloc_object(KeyActions);
4698 : :
4699 : 111 : n->updateAction = $1;
4700 : 111 : n->deleteAction = $2;
4701 : 111 : $$ = n;
4702 : : }
4703 : : | key_delete key_update
4704 : : {
4705 : 100 : KeyActions *n = palloc_object(KeyActions);
4706 : :
4707 : 100 : n->updateAction = $2;
4708 : 100 : n->deleteAction = $1;
4709 : 100 : $$ = n;
4710 : : }
4711 : : | /*EMPTY*/
4712 : : {
4713 : 1525 : KeyActions *n = palloc_object(KeyActions);
4714 : :
4715 : 1525 : n->updateAction = palloc_object(KeyAction);
4716 : 1525 : n->updateAction->action = FKCONSTR_ACTION_NOACTION;
4717 : 1525 : n->updateAction->cols = NIL;
4718 : 1525 : n->deleteAction = palloc_object(KeyAction);
4719 : 1525 : n->deleteAction->action = FKCONSTR_ACTION_NOACTION;
4720 : 1525 : n->deleteAction->cols = NIL;
4721 : 1525 : $$ = n;
4722 : : }
4723 : : ;
4724 : :
4725 : : key_update: ON UPDATE key_action
4726 : : {
4727 [ + + ]: 264 : if (($3)->cols)
4728 [ + - + - ]: 4 : ereport(ERROR,
4729 : : (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
4730 : : errmsg("a column list with %s is only supported for ON DELETE actions",
4731 : : ($3)->action == FKCONSTR_ACTION_SETNULL ? "SET NULL" : "SET DEFAULT"),
4732 : : parser_errposition(@1)));
4733 : 260 : $$ = $3;
4734 : : }
4735 : : ;
4736 : :
4737 : : key_delete: ON DELETE_P key_action
4738 : : {
4739 : 304 : $$ = $3;
4740 : : }
4741 : : ;
4742 : :
4743 : : key_action:
4744 : : NO ACTION
4745 : : {
4746 : 51 : KeyAction *n = palloc_object(KeyAction);
4747 : :
4748 : 51 : n->action = FKCONSTR_ACTION_NOACTION;
4749 : 51 : n->cols = NIL;
4750 : 51 : $$ = n;
4751 : : }
4752 : : | RESTRICT
4753 : : {
4754 : 32 : KeyAction *n = palloc_object(KeyAction);
4755 : :
4756 : 32 : n->action = FKCONSTR_ACTION_RESTRICT;
4757 : 32 : n->cols = NIL;
4758 : 32 : $$ = n;
4759 : : }
4760 : : | CASCADE
4761 : : {
4762 : 293 : KeyAction *n = palloc_object(KeyAction);
4763 : :
4764 : 293 : n->action = FKCONSTR_ACTION_CASCADE;
4765 : 293 : n->cols = NIL;
4766 : 293 : $$ = n;
4767 : : }
4768 : : | SET NULL_P opt_column_list
4769 : : {
4770 : 124 : KeyAction *n = palloc_object(KeyAction);
4771 : :
4772 : 124 : n->action = FKCONSTR_ACTION_SETNULL;
4773 : 124 : n->cols = $3;
4774 : 124 : $$ = n;
4775 : : }
4776 : : | SET DEFAULT opt_column_list
4777 : : {
4778 : 68 : KeyAction *n = palloc_object(KeyAction);
4779 : :
4780 : 68 : n->action = FKCONSTR_ACTION_SETDEFAULT;
4781 : 68 : n->cols = $3;
4782 : 68 : $$ = n;
4783 : : }
4784 : : ;
4785 : :
4786 : 1427 : OptInherit: INHERITS '(' qualified_name_list ')' { $$ = $3; }
4787 : 18869 : | /*EMPTY*/ { $$ = NIL; }
4788 : : ;
4789 : :
4790 : : /* Optional partition key specification */
4791 : 3680 : OptPartitionSpec: PartitionSpec { $$ = $1; }
4792 : 22960 : | /*EMPTY*/ { $$ = NULL; }
4793 : : ;
4794 : :
4795 : : PartitionSpec: PARTITION BY ColId '(' part_params ')'
4796 : : {
4797 : 3684 : PartitionSpec *n = makeNode(PartitionSpec);
4798 : :
4799 : 3684 : n->strategy = parsePartitionStrategy($3, @3, yyscanner);
4800 : 3680 : n->partParams = $5;
4801 : 3680 : n->location = @1;
4802 : :
4803 : 3680 : $$ = n;
4804 : : }
4805 : : ;
4806 : :
4807 : 3684 : part_params: part_elem { $$ = list_make1($1); }
4808 : 322 : | part_params ',' part_elem { $$ = lappend($1, $3); }
4809 : : ;
4810 : :
4811 : : part_elem: ColId opt_collate opt_qualified_name
4812 : : {
4813 : 3774 : PartitionElem *n = makeNode(PartitionElem);
4814 : :
4815 : 3774 : n->name = $1;
4816 : 3774 : n->expr = NULL;
4817 : 3774 : n->collation = $2;
4818 : 3774 : n->opclass = $3;
4819 : 3774 : n->location = @1;
4820 : 3774 : $$ = n;
4821 : : }
4822 : : | func_expr_windowless opt_collate opt_qualified_name
4823 : : {
4824 : 94 : PartitionElem *n = makeNode(PartitionElem);
4825 : :
4826 : 94 : n->name = NULL;
4827 : 94 : n->expr = $1;
4828 : 94 : n->collation = $2;
4829 : 94 : n->opclass = $3;
4830 : 94 : n->location = @1;
4831 : 94 : $$ = n;
4832 : : }
4833 : : | '(' a_expr ')' opt_collate opt_qualified_name
4834 : : {
4835 : 138 : PartitionElem *n = makeNode(PartitionElem);
4836 : :
4837 : 138 : n->name = NULL;
4838 : 138 : n->expr = $2;
4839 : 138 : n->collation = $4;
4840 : 138 : n->opclass = $5;
4841 : 138 : n->location = @1;
4842 : 138 : $$ = n;
4843 : : }
4844 : : ;
4845 : :
4846 : : table_access_method_clause:
4847 : 87 : USING name { $$ = $2; }
4848 : 27820 : | /*EMPTY*/ { $$ = NULL; }
4849 : : ;
4850 : :
4851 : : /* WITHOUT OIDS is legacy only */
4852 : : OptWith:
4853 : 595 : WITH reloptions { $$ = $2; }
4854 : 16 : | WITHOUT OIDS { $$ = NIL; }
4855 : 26923 : | /*EMPTY*/ { $$ = NIL; }
4856 : : ;
4857 : :
4858 : 43 : OnCommitOption: ON COMMIT DROP { $$ = ONCOMMIT_DROP; }
4859 : 69 : | ON COMMIT DELETE_P ROWS { $$ = ONCOMMIT_DELETE_ROWS; }
4860 : 16 : | ON COMMIT PRESERVE ROWS { $$ = ONCOMMIT_PRESERVE_ROWS; }
4861 : 27406 : | /*EMPTY*/ { $$ = ONCOMMIT_NOOP; }
4862 : : ;
4863 : :
4864 : 148 : OptTableSpace: TABLESPACE name { $$ = $2; }
4865 : 32308 : | /*EMPTY*/ { $$ = NULL; }
4866 : : ;
4867 : :
4868 : 50 : OptConsTableSpace: USING INDEX TABLESPACE name { $$ = $4; }
4869 : 6094 : | /*EMPTY*/ { $$ = NULL; }
4870 : : ;
4871 : :
4872 : 6670 : ExistingIndex: USING INDEX name { $$ = $3; }
4873 : : ;
4874 : :
4875 : : /*****************************************************************************
4876 : : *
4877 : : * QUERY :
4878 : : * CREATE STATISTICS [[IF NOT EXISTS] stats_name] [(stat types)]
4879 : : * ON expression-list FROM from_list
4880 : : *
4881 : : * Note: the expectation here is that the clauses after ON are a subset of
4882 : : * SELECT syntax, allowing for expressions and joined tables, and probably
4883 : : * someday a WHERE clause. Much less than that is currently implemented,
4884 : : * but the grammar accepts it and then we'll throw FEATURE_NOT_SUPPORTED
4885 : : * errors as necessary at execution.
4886 : : *
4887 : : * Statistics name is optional unless IF NOT EXISTS is specified.
4888 : : *
4889 : : *****************************************************************************/
4890 : :
4891 : : CreateStatsStmt:
4892 : : CREATE STATISTICS opt_qualified_name
4893 : : opt_name_list ON stats_params FROM from_list
4894 : : {
4895 : 653 : CreateStatsStmt *n = makeNode(CreateStatsStmt);
4896 : :
4897 : 653 : n->defnames = $3;
4898 : 653 : n->stat_types = $4;
4899 : 653 : n->exprs = $6;
4900 : 653 : n->relations = $8;
4901 : 653 : n->stxcomment = NULL;
4902 : 653 : n->if_not_exists = false;
4903 : 653 : $$ = (Node *) n;
4904 : : }
4905 : : | CREATE STATISTICS IF_P NOT EXISTS any_name
4906 : : opt_name_list ON stats_params FROM from_list
4907 : : {
4908 : 8 : CreateStatsStmt *n = makeNode(CreateStatsStmt);
4909 : :
4910 : 8 : n->defnames = $6;
4911 : 8 : n->stat_types = $7;
4912 : 8 : n->exprs = $9;
4913 : 8 : n->relations = $11;
4914 : 8 : n->stxcomment = NULL;
4915 : 8 : n->if_not_exists = true;
4916 : 8 : $$ = (Node *) n;
4917 : : }
4918 : : ;
4919 : :
4920 : : /*
4921 : : * Statistics attributes can be either simple column references, or arbitrary
4922 : : * expressions in parens. For compatibility with index attributes permitted
4923 : : * in CREATE INDEX, we allow an expression that's just a function call to be
4924 : : * written without parens.
4925 : : */
4926 : :
4927 : 669 : stats_params: stats_param { $$ = list_make1($1); }
4928 : 913 : | stats_params ',' stats_param { $$ = lappend($1, $3); }
4929 : : ;
4930 : :
4931 : : stats_param: ColId
4932 : : {
4933 : 1159 : $$ = makeNode(StatsElem);
4934 : 1159 : $$->name = $1;
4935 : 1159 : $$->expr = NULL;
4936 : : }
4937 : : | func_expr_windowless
4938 : : {
4939 : 67 : $$ = makeNode(StatsElem);
4940 : 67 : $$->name = NULL;
4941 : 67 : $$->expr = $1;
4942 : : }
4943 : : | '(' a_expr ')'
4944 : : {
4945 : 356 : $$ = makeNode(StatsElem);
4946 : 356 : $$->name = NULL;
4947 : 356 : $$->expr = $2;
4948 : : }
4949 : : ;
4950 : :
4951 : : /*****************************************************************************
4952 : : *
4953 : : * QUERY :
4954 : : * ALTER STATISTICS [IF EXISTS] stats_name
4955 : : * SET STATISTICS <SignedIconst>
4956 : : *
4957 : : *****************************************************************************/
4958 : :
4959 : : AlterStatsStmt:
4960 : : ALTER STATISTICS any_name SET STATISTICS set_statistics_value
4961 : : {
4962 : 13 : AlterStatsStmt *n = makeNode(AlterStatsStmt);
4963 : :
4964 : 13 : n->defnames = $3;
4965 : 13 : n->missing_ok = false;
4966 : 13 : n->stxstattarget = $6;
4967 : 13 : $$ = (Node *) n;
4968 : : }
4969 : : | ALTER STATISTICS IF_P EXISTS any_name SET STATISTICS set_statistics_value
4970 : : {
4971 : 4 : AlterStatsStmt *n = makeNode(AlterStatsStmt);
4972 : :
4973 : 4 : n->defnames = $5;
4974 : 4 : n->missing_ok = true;
4975 : 4 : n->stxstattarget = $8;
4976 : 4 : $$ = (Node *) n;
4977 : : }
4978 : : ;
4979 : :
4980 : : /*****************************************************************************
4981 : : *
4982 : : * QUERY :
4983 : : * CREATE TABLE relname AS SelectStmt [ WITH [NO] DATA ]
4984 : : *
4985 : : *
4986 : : * Note: SELECT ... INTO is a now-deprecated alternative for this.
4987 : : *
4988 : : *****************************************************************************/
4989 : :
4990 : : CreateAsStmt:
4991 : : CREATE OptTemp TABLE create_as_target AS SelectStmt opt_with_data
4992 : : {
4993 : 813 : CreateTableAsStmt *ctas = makeNode(CreateTableAsStmt);
4994 : :
4995 : 813 : ctas->query = $6;
4996 : 813 : ctas->into = $4;
4997 : 813 : ctas->objtype = OBJECT_TABLE;
4998 : 813 : ctas->is_select_into = false;
4999 : 813 : ctas->if_not_exists = false;
5000 : : /* cram additional flags into the IntoClause */
5001 : 813 : $4->rel->relpersistence = $2;
5002 : 813 : $4->skipData = !($7);
5003 : 813 : $$ = (Node *) ctas;
5004 : : }
5005 : : | CREATE OptTemp TABLE IF_P NOT EXISTS create_as_target AS SelectStmt opt_with_data
5006 : : {
5007 : 31 : CreateTableAsStmt *ctas = makeNode(CreateTableAsStmt);
5008 : :
5009 : 31 : ctas->query = $9;
5010 : 31 : ctas->into = $7;
5011 : 31 : ctas->objtype = OBJECT_TABLE;
5012 : 31 : ctas->is_select_into = false;
5013 : 31 : ctas->if_not_exists = true;
5014 : : /* cram additional flags into the IntoClause */
5015 : 31 : $7->rel->relpersistence = $2;
5016 : 31 : $7->skipData = !($10);
5017 : 31 : $$ = (Node *) ctas;
5018 : : }
5019 : : ;
5020 : :
5021 : : create_as_target:
5022 : : qualified_name opt_column_list table_access_method_clause
5023 : : OptWith OnCommitOption OptTableSpace
5024 : : {
5025 : 902 : $$ = makeNode(IntoClause);
5026 : 902 : $$->rel = $1;
5027 : 902 : $$->colNames = $2;
5028 : 902 : $$->accessMethod = $3;
5029 : 902 : $$->options = $4;
5030 : 902 : $$->onCommit = $5;
5031 : 902 : $$->tableSpaceName = $6;
5032 : 902 : $$->viewQuery = NULL;
5033 : 902 : $$->skipData = false; /* might get changed later */
5034 : : }
5035 : : ;
5036 : :
5037 : : opt_with_data:
5038 : 24 : WITH DATA_P { $$ = true; }
5039 : 145 : | WITH NO DATA_P { $$ = false; }
5040 : 1276 : | /*EMPTY*/ { $$ = true; }
5041 : : ;
5042 : :
5043 : :
5044 : : /*****************************************************************************
5045 : : *
5046 : : * QUERY :
5047 : : * CREATE MATERIALIZED VIEW relname AS SelectStmt
5048 : : *
5049 : : *****************************************************************************/
5050 : :
5051 : : CreateMatViewStmt:
5052 : : CREATE OptNoLog MATERIALIZED VIEW create_mv_target AS SelectStmt opt_with_data
5053 : : {
5054 : 340 : CreateTableAsStmt *ctas = makeNode(CreateTableAsStmt);
5055 : :
5056 : 340 : ctas->query = $7;
5057 : 340 : ctas->into = $5;
5058 : 340 : ctas->objtype = OBJECT_MATVIEW;
5059 : 340 : ctas->is_select_into = false;
5060 : 340 : ctas->if_not_exists = false;
5061 : : /* cram additional flags into the IntoClause */
5062 : 340 : $5->rel->relpersistence = $2;
5063 : 340 : $5->skipData = !($8);
5064 : 340 : $$ = (Node *) ctas;
5065 : : }
5066 : : | CREATE OptNoLog MATERIALIZED VIEW IF_P NOT EXISTS create_mv_target AS SelectStmt opt_with_data
5067 : : {
5068 : 29 : CreateTableAsStmt *ctas = makeNode(CreateTableAsStmt);
5069 : :
5070 : 29 : ctas->query = $10;
5071 : 29 : ctas->into = $8;
5072 : 29 : ctas->objtype = OBJECT_MATVIEW;
5073 : 29 : ctas->is_select_into = false;
5074 : 29 : ctas->if_not_exists = true;
5075 : : /* cram additional flags into the IntoClause */
5076 : 29 : $8->rel->relpersistence = $2;
5077 : 29 : $8->skipData = !($11);
5078 : 29 : $$ = (Node *) ctas;
5079 : : }
5080 : : ;
5081 : :
5082 : : create_mv_target:
5083 : : qualified_name opt_column_list table_access_method_clause opt_reloptions OptTableSpace
5084 : : {
5085 : 369 : $$ = makeNode(IntoClause);
5086 : 369 : $$->rel = $1;
5087 : 369 : $$->colNames = $2;
5088 : 369 : $$->accessMethod = $3;
5089 : 369 : $$->options = $4;
5090 : 369 : $$->onCommit = ONCOMMIT_NOOP;
5091 : 369 : $$->tableSpaceName = $5;
5092 : 369 : $$->viewQuery = NULL; /* filled at analysis time */
5093 : 369 : $$->skipData = false; /* might get changed later */
5094 : : }
5095 : : ;
5096 : :
5097 : 0 : OptNoLog: UNLOGGED { $$ = RELPERSISTENCE_UNLOGGED; }
5098 : 369 : | /*EMPTY*/ { $$ = RELPERSISTENCE_PERMANENT; }
5099 : : ;
5100 : :
5101 : :
5102 : : /*****************************************************************************
5103 : : *
5104 : : * QUERY :
5105 : : * REFRESH MATERIALIZED VIEW qualified_name
5106 : : *
5107 : : *****************************************************************************/
5108 : :
5109 : : RefreshMatViewStmt:
5110 : : REFRESH MATERIALIZED VIEW opt_concurrently qualified_name opt_with_data
5111 : : {
5112 : 174 : RefreshMatViewStmt *n = makeNode(RefreshMatViewStmt);
5113 : :
5114 : 174 : n->concurrent = $4;
5115 : 174 : n->relation = $5;
5116 : 174 : n->skipData = !($6);
5117 : 174 : $$ = (Node *) n;
5118 : : }
5119 : : ;
5120 : :
5121 : :
5122 : : /*****************************************************************************
5123 : : *
5124 : : * QUERY :
5125 : : * CREATE SEQUENCE seqname
5126 : : * ALTER SEQUENCE seqname
5127 : : *
5128 : : *****************************************************************************/
5129 : :
5130 : : CreateSeqStmt:
5131 : : CREATE OptTemp SEQUENCE qualified_name OptSeqOptList
5132 : : {
5133 : 440 : CreateSeqStmt *n = makeNode(CreateSeqStmt);
5134 : :
5135 : 440 : $4->relpersistence = $2;
5136 : 440 : n->sequence = $4;
5137 : 440 : n->options = $5;
5138 : 440 : n->ownerId = InvalidOid;
5139 : 440 : n->if_not_exists = false;
5140 : 440 : $$ = (Node *) n;
5141 : : }
5142 : : | CREATE OptTemp SEQUENCE IF_P NOT EXISTS qualified_name OptSeqOptList
5143 : : {
5144 : 13 : CreateSeqStmt *n = makeNode(CreateSeqStmt);
5145 : :
5146 : 13 : $7->relpersistence = $2;
5147 : 13 : n->sequence = $7;
5148 : 13 : n->options = $8;
5149 : 13 : n->ownerId = InvalidOid;
5150 : 13 : n->if_not_exists = true;
5151 : 13 : $$ = (Node *) n;
5152 : : }
5153 : : ;
5154 : :
5155 : : AlterSeqStmt:
5156 : : ALTER SEQUENCE qualified_name SeqOptList
5157 : : {
5158 : 125 : AlterSeqStmt *n = makeNode(AlterSeqStmt);
5159 : :
5160 : 125 : n->sequence = $3;
5161 : 125 : n->options = $4;
5162 : 125 : n->missing_ok = false;
5163 : 125 : $$ = (Node *) n;
5164 : : }
5165 : : | ALTER SEQUENCE IF_P EXISTS qualified_name SeqOptList
5166 : : {
5167 : 8 : AlterSeqStmt *n = makeNode(AlterSeqStmt);
5168 : :
5169 : 8 : n->sequence = $5;
5170 : 8 : n->options = $6;
5171 : 8 : n->missing_ok = true;
5172 : 8 : $$ = (Node *) n;
5173 : : }
5174 : :
5175 : : ;
5176 : :
5177 : 164 : OptSeqOptList: SeqOptList { $$ = $1; }
5178 : 289 : | /*EMPTY*/ { $$ = NIL; }
5179 : : ;
5180 : :
5181 : 42 : OptParenthesizedSeqOptList: '(' SeqOptList ')' { $$ = $2; }
5182 : 313 : | /*EMPTY*/ { $$ = NIL; }
5183 : : ;
5184 : :
5185 : 339 : SeqOptList: SeqOptElem { $$ = list_make1($1); }
5186 : 441 : | SeqOptList SeqOptElem { $$ = lappend($1, $2); }
5187 : : ;
5188 : :
5189 : : SeqOptElem: AS SimpleTypename
5190 : : {
5191 : 119 : $$ = makeDefElem("as", (Node *) $2, @1);
5192 : : }
5193 : : | CACHE NumericOnly
5194 : : {
5195 : 67 : $$ = makeDefElem("cache", (Node *) $2, @1);
5196 : : }
5197 : : | CYCLE
5198 : : {
5199 : 22 : $$ = makeDefElem("cycle", (Node *) makeBoolean(true), @1);
5200 : : }
5201 : : | NO CYCLE
5202 : : {
5203 : 9 : $$ = makeDefElem("cycle", (Node *) makeBoolean(false), @1);
5204 : : }
5205 : : | INCREMENT opt_by NumericOnly
5206 : : {
5207 : 150 : $$ = makeDefElem("increment", (Node *) $3, @1);
5208 : : }
5209 : : | LOGGED
5210 : : {
5211 : 1 : $$ = makeDefElem("logged", NULL, @1);
5212 : : }
5213 : : | MAXVALUE NumericOnly
5214 : : {
5215 : 43 : $$ = makeDefElem("maxvalue", (Node *) $2, @1);
5216 : : }
5217 : : | MINVALUE NumericOnly
5218 : : {
5219 : 43 : $$ = makeDefElem("minvalue", (Node *) $2, @1);
5220 : : }
5221 : : | NO MAXVALUE
5222 : : {
5223 : 54 : $$ = makeDefElem("maxvalue", NULL, @1);
5224 : : }
5225 : : | NO MINVALUE
5226 : : {
5227 : 54 : $$ = makeDefElem("minvalue", NULL, @1);
5228 : : }
5229 : : | OWNED BY any_name
5230 : : {
5231 : 43 : $$ = makeDefElem("owned_by", (Node *) $3, @1);
5232 : : }
5233 : : | SEQUENCE NAME_P any_name
5234 : : {
5235 : 22 : $$ = makeDefElem("sequence_name", (Node *) $3, @1);
5236 : : }
5237 : : | START opt_with NumericOnly
5238 : : {
5239 : 137 : $$ = makeDefElem("start", (Node *) $3, @1);
5240 : : }
5241 : : | RESTART
5242 : : {
5243 : 4 : $$ = makeDefElem("restart", NULL, @1);
5244 : : }
5245 : : | RESTART opt_with NumericOnly
5246 : : {
5247 : 47 : $$ = makeDefElem("restart", (Node *) $3, @1);
5248 : : }
5249 : : | UNLOGGED
5250 : : {
5251 : 1 : $$ = makeDefElem("unlogged", NULL, @1);
5252 : : }
5253 : : ;
5254 : :
5255 : : opt_by: BY
5256 : : | /* EMPTY */
5257 : : ;
5258 : :
5259 : : NumericOnly:
5260 : 210 : FCONST { $$ = (Node *) makeFloat($1); }
5261 : 0 : | '+' FCONST { $$ = (Node *) makeFloat($2); }
5262 : : | '-' FCONST
5263 : : {
5264 : 13 : Float *f = makeFloat($2);
5265 : :
5266 : 13 : doNegateFloat(f);
5267 : 13 : $$ = (Node *) f;
5268 : : }
5269 : 7065 : | SignedIconst { $$ = (Node *) makeInteger($1); }
5270 : : ;
5271 : :
5272 : 62 : NumericOnly_list: NumericOnly { $$ = list_make1($1); }
5273 : 4 : | NumericOnly_list ',' NumericOnly { $$ = lappend($1, $3); }
5274 : : ;
5275 : :
5276 : : /*****************************************************************************
5277 : : *
5278 : : * QUERIES :
5279 : : * CREATE [OR REPLACE] [TRUSTED] [PROCEDURAL] LANGUAGE ...
5280 : : * DROP [PROCEDURAL] LANGUAGE ...
5281 : : *
5282 : : *****************************************************************************/
5283 : :
5284 : : CreatePLangStmt:
5285 : : CREATE opt_or_replace opt_trusted opt_procedural LANGUAGE name
5286 : : {
5287 : : /*
5288 : : * We now interpret parameterless CREATE LANGUAGE as
5289 : : * CREATE EXTENSION. "OR REPLACE" is silently translated
5290 : : * to "IF NOT EXISTS", which isn't quite the same, but
5291 : : * seems more useful than throwing an error. We just
5292 : : * ignore TRUSTED, as the previous code would have too.
5293 : : */
5294 : 0 : CreateExtensionStmt *n = makeNode(CreateExtensionStmt);
5295 : :
5296 : 0 : n->if_not_exists = $2;
5297 : 0 : n->extname = $6;
5298 : 0 : n->options = NIL;
5299 : 0 : $$ = (Node *) n;
5300 : : }
5301 : : | CREATE opt_or_replace opt_trusted opt_procedural LANGUAGE name
5302 : : HANDLER handler_name opt_inline_handler opt_validator
5303 : : {
5304 : 80 : CreatePLangStmt *n = makeNode(CreatePLangStmt);
5305 : :
5306 : 80 : n->replace = $2;
5307 : 80 : n->plname = $6;
5308 : 80 : n->plhandler = $8;
5309 : 80 : n->plinline = $9;
5310 : 80 : n->plvalidator = $10;
5311 : 80 : n->pltrusted = $3;
5312 : 80 : $$ = (Node *) n;
5313 : : }
5314 : : ;
5315 : :
5316 : : opt_trusted:
5317 : 63 : TRUSTED { $$ = true; }
5318 : 22 : | /*EMPTY*/ { $$ = false; }
5319 : : ;
5320 : :
5321 : : /* This ought to be just func_name, but that causes reduce/reduce conflicts
5322 : : * (CREATE LANGUAGE is the only place where func_name isn't followed by '(').
5323 : : * Work around by using simple names, instead.
5324 : : */
5325 : : handler_name:
5326 : 363 : name { $$ = list_make1(makeString($1)); }
5327 : 1 : | name attrs { $$ = lcons(makeString($1), $2); }
5328 : : ;
5329 : :
5330 : : opt_inline_handler:
5331 : 69 : INLINE_P handler_name { $$ = $2; }
5332 : 11 : | /*EMPTY*/ { $$ = NIL; }
5333 : : ;
5334 : :
5335 : : validator_clause:
5336 : 69 : VALIDATOR handler_name { $$ = $2; }
5337 : 0 : | NO VALIDATOR { $$ = NIL; }
5338 : : ;
5339 : :
5340 : : opt_validator:
5341 : 69 : validator_clause { $$ = $1; }
5342 : 11 : | /*EMPTY*/ { $$ = NIL; }
5343 : : ;
5344 : :
5345 : : opt_procedural:
5346 : : PROCEDURAL
5347 : : | /*EMPTY*/
5348 : : ;
5349 : :
5350 : : /*****************************************************************************
5351 : : *
5352 : : * QUERY:
5353 : : * CREATE TABLESPACE tablespace LOCATION '/path/to/tablespace/'
5354 : : *
5355 : : *****************************************************************************/
5356 : :
5357 : : CreateTableSpaceStmt: CREATE TABLESPACE name OptTableSpaceOwner LOCATION Sconst opt_reloptions
5358 : : {
5359 : 75 : CreateTableSpaceStmt *n = makeNode(CreateTableSpaceStmt);
5360 : :
5361 : 75 : n->tablespacename = $3;
5362 : 75 : n->owner = $4;
5363 : 75 : n->location = $6;
5364 : 75 : n->options = $7;
5365 : 75 : $$ = (Node *) n;
5366 : : }
5367 : : ;
5368 : :
5369 : 6 : OptTableSpaceOwner: OWNER RoleSpec { $$ = $2; }
5370 : 69 : | /*EMPTY */ { $$ = NULL; }
5371 : : ;
5372 : :
5373 : : /*****************************************************************************
5374 : : *
5375 : : * QUERY :
5376 : : * DROP TABLESPACE <tablespace>
5377 : : *
5378 : : * No need for drop behaviour as we cannot implement dependencies for
5379 : : * objects in other databases; we can only support RESTRICT.
5380 : : *
5381 : : ****************************************************************************/
5382 : :
5383 : : DropTableSpaceStmt: DROP TABLESPACE name
5384 : : {
5385 : 36 : DropTableSpaceStmt *n = makeNode(DropTableSpaceStmt);
5386 : :
5387 : 36 : n->tablespacename = $3;
5388 : 36 : n->missing_ok = false;
5389 : 36 : $$ = (Node *) n;
5390 : : }
5391 : : | DROP TABLESPACE IF_P EXISTS name
5392 : : {
5393 : 0 : DropTableSpaceStmt *n = makeNode(DropTableSpaceStmt);
5394 : :
5395 : 0 : n->tablespacename = $5;
5396 : 0 : n->missing_ok = true;
5397 : 0 : $$ = (Node *) n;
5398 : : }
5399 : : ;
5400 : :
5401 : : /*****************************************************************************
5402 : : *
5403 : : * QUERY:
5404 : : * CREATE EXTENSION extension
5405 : : * [ WITH ] [ SCHEMA schema ] [ VERSION version ]
5406 : : *
5407 : : *****************************************************************************/
5408 : :
5409 : : CreateExtensionStmt: CREATE EXTENSION name opt_with create_extension_opt_list
5410 : : {
5411 : 314 : CreateExtensionStmt *n = makeNode(CreateExtensionStmt);
5412 : :
5413 : 314 : n->extname = $3;
5414 : 314 : n->if_not_exists = false;
5415 : 314 : n->options = $5;
5416 : 314 : $$ = (Node *) n;
5417 : : }
5418 : : | CREATE EXTENSION IF_P NOT EXISTS name opt_with create_extension_opt_list
5419 : : {
5420 : 16 : CreateExtensionStmt *n = makeNode(CreateExtensionStmt);
5421 : :
5422 : 16 : n->extname = $6;
5423 : 16 : n->if_not_exists = true;
5424 : 16 : n->options = $8;
5425 : 16 : $$ = (Node *) n;
5426 : : }
5427 : : ;
5428 : :
5429 : : create_extension_opt_list:
5430 : : create_extension_opt_list create_extension_opt_item
5431 : 49 : { $$ = lappend($1, $2); }
5432 : : | /* EMPTY */
5433 : 330 : { $$ = NIL; }
5434 : : ;
5435 : :
5436 : : create_extension_opt_item:
5437 : : SCHEMA name
5438 : : {
5439 : 23 : $$ = makeDefElem("schema", (Node *) makeString($2), @1);
5440 : : }
5441 : : | VERSION_P NonReservedWord_or_Sconst
5442 : : {
5443 : 6 : $$ = makeDefElem("new_version", (Node *) makeString($2), @1);
5444 : : }
5445 : : | FROM NonReservedWord_or_Sconst
5446 : : {
5447 [ # # ]: 0 : ereport(ERROR,
5448 : : (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
5449 : : errmsg("CREATE EXTENSION ... FROM is no longer supported"),
5450 : : parser_errposition(@1)));
5451 : : }
5452 : : | CASCADE
5453 : : {
5454 : 20 : $$ = makeDefElem("cascade", (Node *) makeBoolean(true), @1);
5455 : : }
5456 : : ;
5457 : :
5458 : : /*****************************************************************************
5459 : : *
5460 : : * ALTER EXTENSION name UPDATE [ TO version ]
5461 : : *
5462 : : *****************************************************************************/
5463 : :
5464 : : AlterExtensionStmt: ALTER EXTENSION name UPDATE alter_extension_opt_list
5465 : : {
5466 : 20 : AlterExtensionStmt *n = makeNode(AlterExtensionStmt);
5467 : :
5468 : 20 : n->extname = $3;
5469 : 20 : n->options = $5;
5470 : 20 : $$ = (Node *) n;
5471 : : }
5472 : : ;
5473 : :
5474 : : alter_extension_opt_list:
5475 : : alter_extension_opt_list alter_extension_opt_item
5476 : 20 : { $$ = lappend($1, $2); }
5477 : : | /* EMPTY */
5478 : 20 : { $$ = NIL; }
5479 : : ;
5480 : :
5481 : : alter_extension_opt_item:
5482 : : TO NonReservedWord_or_Sconst
5483 : : {
5484 : 20 : $$ = makeDefElem("new_version", (Node *) makeString($2), @1);
5485 : : }
5486 : : ;
5487 : :
5488 : : /*****************************************************************************
5489 : : *
5490 : : * ALTER EXTENSION name ADD/DROP object-identifier
5491 : : *
5492 : : *****************************************************************************/
5493 : :
5494 : : AlterExtensionContentsStmt:
5495 : : ALTER EXTENSION name add_drop object_type_name name
5496 : : {
5497 : 9 : AlterExtensionContentsStmt *n = makeNode(AlterExtensionContentsStmt);
5498 : :
5499 : 9 : n->extname = $3;
5500 : 9 : n->action = $4;
5501 : 9 : n->objtype = $5;
5502 : 9 : n->object = (Node *) makeString($6);
5503 : 9 : $$ = (Node *) n;
5504 : : }
5505 : : | ALTER EXTENSION name add_drop object_type_any_name any_name
5506 : : {
5507 : 44 : AlterExtensionContentsStmt *n = makeNode(AlterExtensionContentsStmt);
5508 : :
5509 : 44 : n->extname = $3;
5510 : 44 : n->action = $4;
5511 : 44 : n->objtype = $5;
5512 : 44 : n->object = (Node *) $6;
5513 : 44 : $$ = (Node *) n;
5514 : : }
5515 : : | ALTER EXTENSION name add_drop AGGREGATE aggregate_with_argtypes
5516 : : {
5517 : 4 : AlterExtensionContentsStmt *n = makeNode(AlterExtensionContentsStmt);
5518 : :
5519 : 4 : n->extname = $3;
5520 : 4 : n->action = $4;
5521 : 4 : n->objtype = OBJECT_AGGREGATE;
5522 : 4 : n->object = (Node *) $6;
5523 : 4 : $$ = (Node *) n;
5524 : : }
5525 : : | ALTER EXTENSION name add_drop CAST '(' Typename AS Typename ')'
5526 : : {
5527 : 2 : AlterExtensionContentsStmt *n = makeNode(AlterExtensionContentsStmt);
5528 : :
5529 : 2 : n->extname = $3;
5530 : 2 : n->action = $4;
5531 : 2 : n->objtype = OBJECT_CAST;
5532 : 2 : n->object = (Node *) list_make2($7, $9);
5533 : 2 : $$ = (Node *) n;
5534 : : }
5535 : : | ALTER EXTENSION name add_drop DOMAIN_P Typename
5536 : : {
5537 : 0 : AlterExtensionContentsStmt *n = makeNode(AlterExtensionContentsStmt);
5538 : :
5539 : 0 : n->extname = $3;
5540 : 0 : n->action = $4;
5541 : 0 : n->objtype = OBJECT_DOMAIN;
5542 : 0 : n->object = (Node *) $6;
5543 : 0 : $$ = (Node *) n;
5544 : : }
5545 : : | ALTER EXTENSION name add_drop FUNCTION function_with_argtypes
5546 : : {
5547 : 64 : AlterExtensionContentsStmt *n = makeNode(AlterExtensionContentsStmt);
5548 : :
5549 : 64 : n->extname = $3;
5550 : 64 : n->action = $4;
5551 : 64 : n->objtype = OBJECT_FUNCTION;
5552 : 64 : n->object = (Node *) $6;
5553 : 64 : $$ = (Node *) n;
5554 : : }
5555 : : | ALTER EXTENSION name add_drop OPERATOR operator_with_argtypes
5556 : : {
5557 : 9 : AlterExtensionContentsStmt *n = makeNode(AlterExtensionContentsStmt);
5558 : :
5559 : 9 : n->extname = $3;
5560 : 9 : n->action = $4;
5561 : 9 : n->objtype = OBJECT_OPERATOR;
5562 : 9 : n->object = (Node *) $6;
5563 : 9 : $$ = (Node *) n;
5564 : : }
5565 : : | ALTER EXTENSION name add_drop OPERATOR CLASS 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_OPCLASS;
5572 : 2 : n->object = (Node *) lcons(makeString($9), $7);
5573 : 2 : $$ = (Node *) n;
5574 : : }
5575 : : | ALTER EXTENSION name add_drop OPERATOR FAMILY any_name USING name
5576 : : {
5577 : 2 : AlterExtensionContentsStmt *n = makeNode(AlterExtensionContentsStmt);
5578 : :
5579 : 2 : n->extname = $3;
5580 : 2 : n->action = $4;
5581 : 2 : n->objtype = OBJECT_OPFAMILY;
5582 : 2 : n->object = (Node *) lcons(makeString($9), $7);
5583 : 2 : $$ = (Node *) n;
5584 : : }
5585 : : | ALTER EXTENSION name add_drop PROCEDURE 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_PROCEDURE;
5592 : 0 : n->object = (Node *) $6;
5593 : 0 : $$ = (Node *) n;
5594 : : }
5595 : : | ALTER EXTENSION name add_drop ROUTINE function_with_argtypes
5596 : : {
5597 : 0 : AlterExtensionContentsStmt *n = makeNode(AlterExtensionContentsStmt);
5598 : :
5599 : 0 : n->extname = $3;
5600 : 0 : n->action = $4;
5601 : 0 : n->objtype = OBJECT_ROUTINE;
5602 : 0 : n->object = (Node *) $6;
5603 : 0 : $$ = (Node *) n;
5604 : : }
5605 : : | ALTER EXTENSION name add_drop TRANSFORM FOR Typename LANGUAGE name
5606 : : {
5607 : 2 : AlterExtensionContentsStmt *n = makeNode(AlterExtensionContentsStmt);
5608 : :
5609 : 2 : n->extname = $3;
5610 : 2 : n->action = $4;
5611 : 2 : n->objtype = OBJECT_TRANSFORM;
5612 : 2 : n->object = (Node *) list_make2($7, makeString($9));
5613 : 2 : $$ = (Node *) n;
5614 : : }
5615 : : | ALTER EXTENSION name add_drop TYPE_P Typename
5616 : : {
5617 : 4 : AlterExtensionContentsStmt *n = makeNode(AlterExtensionContentsStmt);
5618 : :
5619 : 4 : n->extname = $3;
5620 : 4 : n->action = $4;
5621 : 4 : n->objtype = OBJECT_TYPE;
5622 : 4 : n->object = (Node *) $6;
5623 : 4 : $$ = (Node *) n;
5624 : : }
5625 : : ;
5626 : :
5627 : : /*****************************************************************************
5628 : : *
5629 : : * QUERY:
5630 : : * CREATE FOREIGN DATA WRAPPER name options
5631 : : *
5632 : : *****************************************************************************/
5633 : :
5634 : : CreateFdwStmt: CREATE FOREIGN DATA_P WRAPPER name opt_fdw_options create_generic_options
5635 : : {
5636 : 154 : CreateFdwStmt *n = makeNode(CreateFdwStmt);
5637 : :
5638 : 154 : n->fdwname = $5;
5639 : 154 : n->func_options = $6;
5640 : 154 : n->options = $7;
5641 : 154 : $$ = (Node *) n;
5642 : : }
5643 : : ;
5644 : :
5645 : : fdw_option:
5646 : 40 : HANDLER handler_name { $$ = makeDefElem("handler", (Node *) $2, @1); }
5647 : 0 : | NO HANDLER { $$ = makeDefElem("handler", NULL, @1); }
5648 : 38 : | VALIDATOR handler_name { $$ = makeDefElem("validator", (Node *) $2, @1); }
5649 : 4 : | NO VALIDATOR { $$ = makeDefElem("validator", NULL, @1); }
5650 : 22 : | CONNECTION handler_name { $$ = makeDefElem("connection", (Node *) $2, @1); }
5651 : 4 : | NO CONNECTION { $$ = makeDefElem("connection", NULL, @1); }
5652 : : ;
5653 : :
5654 : : fdw_options:
5655 : 92 : fdw_option { $$ = list_make1($1); }
5656 : 16 : | fdw_options fdw_option { $$ = lappend($1, $2); }
5657 : : ;
5658 : :
5659 : : opt_fdw_options:
5660 : 38 : fdw_options { $$ = $1; }
5661 : 177 : | /*EMPTY*/ { $$ = NIL; }
5662 : : ;
5663 : :
5664 : : /*****************************************************************************
5665 : : *
5666 : : * QUERY :
5667 : : * ALTER FOREIGN DATA WRAPPER name options
5668 : : *
5669 : : ****************************************************************************/
5670 : :
5671 : : AlterFdwStmt: ALTER FOREIGN DATA_P WRAPPER name opt_fdw_options alter_generic_options
5672 : : {
5673 : 57 : AlterFdwStmt *n = makeNode(AlterFdwStmt);
5674 : :
5675 : 57 : n->fdwname = $5;
5676 : 57 : n->func_options = $6;
5677 : 57 : n->options = $7;
5678 : 57 : $$ = (Node *) n;
5679 : : }
5680 : : | ALTER FOREIGN DATA_P WRAPPER name fdw_options
5681 : : {
5682 : 54 : AlterFdwStmt *n = makeNode(AlterFdwStmt);
5683 : :
5684 : 54 : n->fdwname = $5;
5685 : 54 : n->func_options = $6;
5686 : 54 : n->options = NIL;
5687 : 54 : $$ = (Node *) n;
5688 : : }
5689 : : ;
5690 : :
5691 : : /* Options definition for CREATE FDW, SERVER and USER MAPPING */
5692 : : create_generic_options:
5693 : 460 : OPTIONS '(' generic_option_list ')' { $$ = $3; }
5694 : 46132 : | /*EMPTY*/ { $$ = NIL; }
5695 : : ;
5696 : :
5697 : : generic_option_list:
5698 : : generic_option_elem
5699 : : {
5700 : 460 : $$ = list_make1($1);
5701 : : }
5702 : : | generic_option_list ',' generic_option_elem
5703 : : {
5704 : 308 : $$ = lappend($1, $3);
5705 : : }
5706 : : ;
5707 : :
5708 : : /* Options definition for ALTER FDW, SERVER and USER MAPPING */
5709 : : alter_generic_options:
5710 : 300 : OPTIONS '(' alter_generic_option_list ')' { $$ = $3; }
5711 : : ;
5712 : :
5713 : : alter_generic_option_list:
5714 : : alter_generic_option_elem
5715 : : {
5716 : 300 : $$ = list_make1($1);
5717 : : }
5718 : : | alter_generic_option_list ',' alter_generic_option_elem
5719 : : {
5720 : 103 : $$ = lappend($1, $3);
5721 : : }
5722 : : ;
5723 : :
5724 : : alter_generic_option_elem:
5725 : : generic_option_elem
5726 : : {
5727 : 119 : $$ = $1;
5728 : : }
5729 : : | SET generic_option_elem
5730 : : {
5731 : 73 : $$ = $2;
5732 : 73 : $$->defaction = DEFELEM_SET;
5733 : : }
5734 : : | ADD_P generic_option_elem
5735 : : {
5736 : 135 : $$ = $2;
5737 : 135 : $$->defaction = DEFELEM_ADD;
5738 : : }
5739 : : | DROP generic_option_name
5740 : : {
5741 : 76 : $$ = makeDefElemExtended(NULL, $2, NULL, DEFELEM_DROP, @2);
5742 : : }
5743 : : ;
5744 : :
5745 : : generic_option_elem:
5746 : : generic_option_name generic_option_arg
5747 : : {
5748 : 1095 : $$ = makeDefElem($1, $2, @1);
5749 : : }
5750 : : ;
5751 : :
5752 : : generic_option_name:
5753 : 1171 : ColLabel { $$ = $1; }
5754 : : ;
5755 : :
5756 : : /* We could use def_arg here, but the spec only requires string literals */
5757 : : generic_option_arg:
5758 : 1095 : Sconst { $$ = (Node *) makeString($1); }
5759 : : ;
5760 : :
5761 : : /*****************************************************************************
5762 : : *
5763 : : * QUERY:
5764 : : * CREATE SERVER name [TYPE] [VERSION] [OPTIONS]
5765 : : *
5766 : : *****************************************************************************/
5767 : :
5768 : : CreateForeignServerStmt: CREATE SERVER name opt_type opt_foreign_server_version
5769 : : FOREIGN DATA_P WRAPPER name create_generic_options
5770 : : {
5771 : 183 : CreateForeignServerStmt *n = makeNode(CreateForeignServerStmt);
5772 : :
5773 : 183 : n->servername = $3;
5774 : 183 : n->servertype = $4;
5775 : 183 : n->version = $5;
5776 : 183 : n->fdwname = $9;
5777 : 183 : n->options = $10;
5778 : 183 : n->if_not_exists = false;
5779 : 183 : $$ = (Node *) n;
5780 : : }
5781 : : | CREATE SERVER IF_P NOT EXISTS name opt_type opt_foreign_server_version
5782 : : FOREIGN DATA_P WRAPPER name create_generic_options
5783 : : {
5784 : 13 : CreateForeignServerStmt *n = makeNode(CreateForeignServerStmt);
5785 : :
5786 : 13 : n->servername = $6;
5787 : 13 : n->servertype = $7;
5788 : 13 : n->version = $8;
5789 : 13 : n->fdwname = $12;
5790 : 13 : n->options = $13;
5791 : 13 : n->if_not_exists = true;
5792 : 13 : $$ = (Node *) n;
5793 : : }
5794 : : ;
5795 : :
5796 : : opt_type:
5797 : 12 : TYPE_P Sconst { $$ = $2; }
5798 : 184 : | /*EMPTY*/ { $$ = NULL; }
5799 : : ;
5800 : :
5801 : :
5802 : : foreign_server_version:
5803 : 44 : VERSION_P Sconst { $$ = $2; }
5804 : 0 : | VERSION_P NULL_P { $$ = NULL; }
5805 : : ;
5806 : :
5807 : : opt_foreign_server_version:
5808 : 12 : foreign_server_version { $$ = $1; }
5809 : 184 : | /*EMPTY*/ { $$ = NULL; }
5810 : : ;
5811 : :
5812 : : /*****************************************************************************
5813 : : *
5814 : : * QUERY :
5815 : : * ALTER SERVER name [VERSION] [OPTIONS]
5816 : : *
5817 : : ****************************************************************************/
5818 : :
5819 : : AlterForeignServerStmt: ALTER SERVER name foreign_server_version alter_generic_options
5820 : : {
5821 : 4 : AlterForeignServerStmt *n = makeNode(AlterForeignServerStmt);
5822 : :
5823 : 4 : n->servername = $3;
5824 : 4 : n->version = $4;
5825 : 4 : n->options = $5;
5826 : 4 : n->has_version = true;
5827 : 4 : $$ = (Node *) n;
5828 : : }
5829 : : | ALTER SERVER name foreign_server_version
5830 : : {
5831 : 28 : AlterForeignServerStmt *n = makeNode(AlterForeignServerStmt);
5832 : :
5833 : 28 : n->servername = $3;
5834 : 28 : n->version = $4;
5835 : 28 : n->has_version = true;
5836 : 28 : $$ = (Node *) n;
5837 : : }
5838 : : | ALTER SERVER name alter_generic_options
5839 : : {
5840 : 97 : AlterForeignServerStmt *n = makeNode(AlterForeignServerStmt);
5841 : :
5842 : 97 : n->servername = $3;
5843 : 97 : n->options = $4;
5844 : 97 : $$ = (Node *) n;
5845 : : }
5846 : : ;
5847 : :
5848 : : /*****************************************************************************
5849 : : *
5850 : : * QUERY:
5851 : : * CREATE FOREIGN TABLE relname (...) SERVER name (...)
5852 : : *
5853 : : *****************************************************************************/
5854 : :
5855 : : CreateForeignTableStmt:
5856 : : CREATE FOREIGN TABLE qualified_name
5857 : : '(' OptTableElementList ')'
5858 : : OptInherit SERVER name create_generic_options
5859 : : {
5860 : 250 : CreateForeignTableStmt *n = makeNode(CreateForeignTableStmt);
5861 : :
5862 : 250 : $4->relpersistence = RELPERSISTENCE_PERMANENT;
5863 : 250 : n->base.relation = $4;
5864 : 250 : n->base.tableElts = $6;
5865 : 250 : n->base.inhRelations = $8;
5866 : 250 : n->base.ofTypename = NULL;
5867 : 250 : n->base.constraints = NIL;
5868 : 250 : n->base.options = NIL;
5869 : 250 : n->base.oncommit = ONCOMMIT_NOOP;
5870 : 250 : n->base.tablespacename = NULL;
5871 : 250 : n->base.if_not_exists = false;
5872 : : /* FDW-specific data */
5873 : 250 : n->servername = $10;
5874 : 250 : n->options = $11;
5875 : 250 : $$ = (Node *) n;
5876 : : }
5877 : : | CREATE FOREIGN TABLE IF_P NOT EXISTS qualified_name
5878 : : '(' OptTableElementList ')'
5879 : : OptInherit SERVER name create_generic_options
5880 : : {
5881 : 0 : CreateForeignTableStmt *n = makeNode(CreateForeignTableStmt);
5882 : :
5883 : 0 : $7->relpersistence = RELPERSISTENCE_PERMANENT;
5884 : 0 : n->base.relation = $7;
5885 : 0 : n->base.tableElts = $9;
5886 : 0 : n->base.inhRelations = $11;
5887 : 0 : n->base.ofTypename = NULL;
5888 : 0 : n->base.constraints = NIL;
5889 : 0 : n->base.options = NIL;
5890 : 0 : n->base.oncommit = ONCOMMIT_NOOP;
5891 : 0 : n->base.tablespacename = NULL;
5892 : 0 : n->base.if_not_exists = true;
5893 : : /* FDW-specific data */
5894 : 0 : n->servername = $13;
5895 : 0 : n->options = $14;
5896 : 0 : $$ = (Node *) n;
5897 : : }
5898 : : | CREATE FOREIGN TABLE qualified_name
5899 : : PARTITION OF qualified_name OptTypedTableElementList PartitionBoundSpec
5900 : : SERVER name create_generic_options
5901 : : {
5902 : 55 : CreateForeignTableStmt *n = makeNode(CreateForeignTableStmt);
5903 : :
5904 : 55 : $4->relpersistence = RELPERSISTENCE_PERMANENT;
5905 : 55 : n->base.relation = $4;
5906 : 55 : n->base.inhRelations = list_make1($7);
5907 : 55 : n->base.tableElts = $8;
5908 : 55 : n->base.partbound = $9;
5909 : 55 : n->base.ofTypename = NULL;
5910 : 55 : n->base.constraints = NIL;
5911 : 55 : n->base.options = NIL;
5912 : 55 : n->base.oncommit = ONCOMMIT_NOOP;
5913 : 55 : n->base.tablespacename = NULL;
5914 : 55 : n->base.if_not_exists = false;
5915 : : /* FDW-specific data */
5916 : 55 : n->servername = $11;
5917 : 55 : n->options = $12;
5918 : 55 : $$ = (Node *) n;
5919 : : }
5920 : : | CREATE FOREIGN TABLE IF_P NOT EXISTS qualified_name
5921 : : PARTITION OF qualified_name OptTypedTableElementList PartitionBoundSpec
5922 : : SERVER name create_generic_options
5923 : : {
5924 : 0 : CreateForeignTableStmt *n = makeNode(CreateForeignTableStmt);
5925 : :
5926 : 0 : $7->relpersistence = RELPERSISTENCE_PERMANENT;
5927 : 0 : n->base.relation = $7;
5928 : 0 : n->base.inhRelations = list_make1($10);
5929 : 0 : n->base.tableElts = $11;
5930 : 0 : n->base.partbound = $12;
5931 : 0 : n->base.ofTypename = NULL;
5932 : 0 : n->base.constraints = NIL;
5933 : 0 : n->base.options = NIL;
5934 : 0 : n->base.oncommit = ONCOMMIT_NOOP;
5935 : 0 : n->base.tablespacename = NULL;
5936 : 0 : n->base.if_not_exists = true;
5937 : : /* FDW-specific data */
5938 : 0 : n->servername = $14;
5939 : 0 : n->options = $15;
5940 : 0 : $$ = (Node *) n;
5941 : : }
5942 : : ;
5943 : :
5944 : : /*****************************************************************************
5945 : : *
5946 : : * QUERY:
5947 : : * IMPORT FOREIGN SCHEMA remote_schema
5948 : : * [ { LIMIT TO | EXCEPT } ( table_list ) ]
5949 : : * FROM SERVER server_name INTO local_schema [ OPTIONS (...) ]
5950 : : *
5951 : : ****************************************************************************/
5952 : :
5953 : : ImportForeignSchemaStmt:
5954 : : IMPORT_P FOREIGN SCHEMA name import_qualification
5955 : : FROM SERVER name INTO name create_generic_options
5956 : : {
5957 : 28 : ImportForeignSchemaStmt *n = makeNode(ImportForeignSchemaStmt);
5958 : :
5959 : 28 : n->server_name = $8;
5960 : 28 : n->remote_schema = $4;
5961 : 28 : n->local_schema = $10;
5962 : 28 : n->list_type = $5->type;
5963 : 28 : n->table_list = $5->table_names;
5964 : 28 : n->options = $11;
5965 : 28 : $$ = (Node *) n;
5966 : : }
5967 : : ;
5968 : :
5969 : : import_qualification_type:
5970 : 8 : LIMIT TO { $$ = FDW_IMPORT_SCHEMA_LIMIT_TO; }
5971 : 9 : | EXCEPT { $$ = FDW_IMPORT_SCHEMA_EXCEPT; }
5972 : : ;
5973 : :
5974 : : import_qualification:
5975 : : import_qualification_type '(' relation_expr_list ')'
5976 : : {
5977 : 17 : ImportQual *n = palloc_object(ImportQual);
5978 : :
5979 : 17 : n->type = $1;
5980 : 17 : n->table_names = $3;
5981 : 17 : $$ = n;
5982 : : }
5983 : : | /*EMPTY*/
5984 : : {
5985 : 11 : ImportQual *n = palloc_object(ImportQual);
5986 : 11 : n->type = FDW_IMPORT_SCHEMA_ALL;
5987 : 11 : n->table_names = NIL;
5988 : 11 : $$ = n;
5989 : : }
5990 : : ;
5991 : :
5992 : : /*****************************************************************************
5993 : : *
5994 : : * QUERY:
5995 : : * CREATE USER MAPPING FOR auth_ident SERVER name [OPTIONS]
5996 : : *
5997 : : *****************************************************************************/
5998 : :
5999 : : CreateUserMappingStmt: CREATE USER MAPPING FOR auth_ident SERVER name create_generic_options
6000 : : {
6001 : 167 : CreateUserMappingStmt *n = makeNode(CreateUserMappingStmt);
6002 : :
6003 : 167 : n->user = $5;
6004 : 167 : n->servername = $7;
6005 : 167 : n->options = $8;
6006 : 167 : n->if_not_exists = false;
6007 : 167 : $$ = (Node *) n;
6008 : : }
6009 : : | CREATE USER MAPPING IF_P NOT EXISTS FOR auth_ident SERVER name create_generic_options
6010 : : {
6011 : 4 : CreateUserMappingStmt *n = makeNode(CreateUserMappingStmt);
6012 : :
6013 : 4 : n->user = $8;
6014 : 4 : n->servername = $10;
6015 : 4 : n->options = $11;
6016 : 4 : n->if_not_exists = true;
6017 : 4 : $$ = (Node *) n;
6018 : : }
6019 : : ;
6020 : :
6021 : : /* User mapping authorization identifier */
6022 : 297 : auth_ident: RoleSpec { $$ = $1; }
6023 : 29 : | USER { $$ = makeRoleSpec(ROLESPEC_CURRENT_USER, @1); }
6024 : : ;
6025 : :
6026 : : /*****************************************************************************
6027 : : *
6028 : : * QUERY :
6029 : : * DROP USER MAPPING FOR auth_ident SERVER name
6030 : : *
6031 : : * XXX you'd think this should have a CASCADE/RESTRICT option, even if it's
6032 : : * only pro forma; but the SQL standard doesn't show one.
6033 : : ****************************************************************************/
6034 : :
6035 : : DropUserMappingStmt: DROP USER MAPPING FOR auth_ident SERVER name
6036 : : {
6037 : 61 : DropUserMappingStmt *n = makeNode(DropUserMappingStmt);
6038 : :
6039 : 61 : n->user = $5;
6040 : 61 : n->servername = $7;
6041 : 61 : n->missing_ok = false;
6042 : 61 : $$ = (Node *) n;
6043 : : }
6044 : : | DROP USER MAPPING IF_P EXISTS FOR auth_ident SERVER name
6045 : : {
6046 : 22 : DropUserMappingStmt *n = makeNode(DropUserMappingStmt);
6047 : :
6048 : 22 : n->user = $7;
6049 : 22 : n->servername = $9;
6050 : 22 : n->missing_ok = true;
6051 : 22 : $$ = (Node *) n;
6052 : : }
6053 : : ;
6054 : :
6055 : : /*****************************************************************************
6056 : : *
6057 : : * QUERY :
6058 : : * ALTER USER MAPPING FOR auth_ident SERVER name OPTIONS
6059 : : *
6060 : : ****************************************************************************/
6061 : :
6062 : : AlterUserMappingStmt: ALTER USER MAPPING FOR auth_ident SERVER name alter_generic_options
6063 : : {
6064 : 72 : AlterUserMappingStmt *n = makeNode(AlterUserMappingStmt);
6065 : :
6066 : 72 : n->user = $5;
6067 : 72 : n->servername = $7;
6068 : 72 : n->options = $8;
6069 : 72 : $$ = (Node *) n;
6070 : : }
6071 : : ;
6072 : :
6073 : : /*****************************************************************************
6074 : : *
6075 : : * QUERIES:
6076 : : * CREATE POLICY name ON table
6077 : : * [AS { PERMISSIVE | RESTRICTIVE } ]
6078 : : * [FOR { SELECT | INSERT | UPDATE | DELETE } ]
6079 : : * [TO role, ...]
6080 : : * [USING (qual)] [WITH CHECK (with check qual)]
6081 : : * ALTER POLICY name ON table [TO role, ...]
6082 : : * [USING (qual)] [WITH CHECK (with check qual)]
6083 : : *
6084 : : *****************************************************************************/
6085 : :
6086 : : CreatePolicyStmt:
6087 : : CREATE POLICY name ON qualified_name RowSecurityDefaultPermissive
6088 : : RowSecurityDefaultForCmd RowSecurityDefaultToRole
6089 : : RowSecurityOptionalExpr RowSecurityOptionalWithCheck
6090 : : {
6091 : 603 : CreatePolicyStmt *n = makeNode(CreatePolicyStmt);
6092 : :
6093 : 603 : n->policy_name = $3;
6094 : 603 : n->table = $5;
6095 : 603 : n->permissive = $6;
6096 : 603 : n->cmd_name = $7;
6097 : 603 : n->roles = $8;
6098 : 603 : n->qual = $9;
6099 : 603 : n->with_check = $10;
6100 : 603 : $$ = (Node *) n;
6101 : : }
6102 : : ;
6103 : :
6104 : : AlterPolicyStmt:
6105 : : ALTER POLICY name ON qualified_name RowSecurityOptionalToRole
6106 : : RowSecurityOptionalExpr RowSecurityOptionalWithCheck
6107 : : {
6108 : 56 : AlterPolicyStmt *n = makeNode(AlterPolicyStmt);
6109 : :
6110 : 56 : n->policy_name = $3;
6111 : 56 : n->table = $5;
6112 : 56 : n->roles = $6;
6113 : 56 : n->qual = $7;
6114 : 56 : n->with_check = $8;
6115 : 56 : $$ = (Node *) n;
6116 : : }
6117 : : ;
6118 : :
6119 : : RowSecurityOptionalExpr:
6120 : 605 : USING '(' a_expr ')' { $$ = $3; }
6121 : 54 : | /* EMPTY */ { $$ = NULL; }
6122 : : ;
6123 : :
6124 : : RowSecurityOptionalWithCheck:
6125 : 115 : WITH CHECK '(' a_expr ')' { $$ = $4; }
6126 : 544 : | /* EMPTY */ { $$ = NULL; }
6127 : : ;
6128 : :
6129 : : RowSecurityDefaultToRole:
6130 : 133 : TO role_list { $$ = $2; }
6131 : 470 : | /* EMPTY */ { $$ = list_make1(makeRoleSpec(ROLESPEC_PUBLIC, -1)); }
6132 : : ;
6133 : :
6134 : : RowSecurityOptionalToRole:
6135 : 8 : TO role_list { $$ = $2; }
6136 : 48 : | /* EMPTY */ { $$ = NULL; }
6137 : : ;
6138 : :
6139 : : RowSecurityDefaultPermissive:
6140 : : AS IDENT
6141 : : {
6142 [ + + ]: 105 : if (strcmp($2, "permissive") == 0)
6143 : 36 : $$ = true;
6144 [ + + ]: 69 : else if (strcmp($2, "restrictive") == 0)
6145 : 65 : $$ = false;
6146 : : else
6147 [ + - ]: 4 : ereport(ERROR,
6148 : : (errcode(ERRCODE_SYNTAX_ERROR),
6149 : : errmsg("unrecognized row security option \"%s\"", $2),
6150 : : errhint("Only PERMISSIVE or RESTRICTIVE policies are supported currently."),
6151 : : parser_errposition(@2)));
6152 : :
6153 : : }
6154 : 502 : | /* EMPTY */ { $$ = true; }
6155 : : ;
6156 : :
6157 : : RowSecurityDefaultForCmd:
6158 : 285 : FOR row_security_cmd { $$ = $2; }
6159 : 318 : | /* EMPTY */ { $$ = "all"; }
6160 : : ;
6161 : :
6162 : : row_security_cmd:
6163 : 29 : ALL { $$ = "all"; }
6164 : 101 : | SELECT { $$ = "select"; }
6165 : 45 : | INSERT { $$ = "insert"; }
6166 : 71 : | UPDATE { $$ = "update"; }
6167 : 39 : | DELETE_P { $$ = "delete"; }
6168 : : ;
6169 : :
6170 : : /*****************************************************************************
6171 : : *
6172 : : * QUERY:
6173 : : * CREATE ACCESS METHOD name HANDLER handler_name
6174 : : *
6175 : : *****************************************************************************/
6176 : :
6177 : : CreateAmStmt: CREATE ACCESS METHOD name TYPE_P am_type HANDLER handler_name
6178 : : {
6179 : 46 : CreateAmStmt *n = makeNode(CreateAmStmt);
6180 : :
6181 : 46 : n->amname = $4;
6182 : 46 : n->handler_name = $8;
6183 : 46 : n->amtype = $6;
6184 : 46 : $$ = (Node *) n;
6185 : : }
6186 : : ;
6187 : :
6188 : : am_type:
6189 : 20 : INDEX { $$ = AMTYPE_INDEX; }
6190 : 26 : | TABLE { $$ = AMTYPE_TABLE; }
6191 : : ;
6192 : :
6193 : : /*****************************************************************************
6194 : : *
6195 : : * QUERIES :
6196 : : * CREATE TRIGGER ...
6197 : : *
6198 : : *****************************************************************************/
6199 : :
6200 : : CreateTrigStmt:
6201 : : CREATE opt_or_replace TRIGGER name TriggerActionTime TriggerEvents ON
6202 : : qualified_name TriggerReferencing TriggerForSpec TriggerWhen
6203 : : EXECUTE FUNCTION_or_PROCEDURE func_name '(' TriggerFuncArgs ')'
6204 : : {
6205 : 2127 : CreateTrigStmt *n = makeNode(CreateTrigStmt);
6206 : :
6207 : 2127 : n->replace = $2;
6208 : 2127 : n->isconstraint = false;
6209 : 2127 : n->trigname = $4;
6210 : 2127 : n->relation = $8;
6211 : 2127 : n->funcname = $14;
6212 : 2127 : n->args = $16;
6213 : 2127 : n->row = $10;
6214 : 2127 : n->timing = $5;
6215 : 2127 : n->events = intVal(linitial($6));
6216 : 2127 : n->columns = (List *) lsecond($6);
6217 : 2127 : n->whenClause = $11;
6218 : 2127 : n->transitionRels = $9;
6219 : 2127 : n->deferrable = false;
6220 : 2127 : n->initdeferred = false;
6221 : 2127 : n->constrrel = NULL;
6222 : 2127 : $$ = (Node *) n;
6223 : : }
6224 : : | CREATE opt_or_replace CONSTRAINT TRIGGER name AFTER TriggerEvents ON
6225 : : qualified_name OptConstrFromTable ConstraintAttributeSpec
6226 : : FOR EACH ROW TriggerWhen
6227 : : EXECUTE FUNCTION_or_PROCEDURE func_name '(' TriggerFuncArgs ')'
6228 : : {
6229 : 65 : CreateTrigStmt *n = makeNode(CreateTrigStmt);
6230 : : bool dummy;
6231 : :
6232 [ + + ]: 65 : if (($11 & CAS_NOT_VALID) != 0)
6233 [ + - ]: 4 : ereport(ERROR,
6234 : : errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
6235 : : errmsg("constraint triggers cannot be marked %s",
6236 : : "NOT VALID"),
6237 : : parser_errposition(@11));
6238 [ + + ]: 61 : if (($11 & CAS_NO_INHERIT) != 0)
6239 [ + - ]: 4 : ereport(ERROR,
6240 : : errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
6241 : : errmsg("constraint triggers cannot be marked %s",
6242 : : "NO INHERIT"),
6243 : : parser_errposition(@11));
6244 [ + + ]: 57 : if (($11 & CAS_NOT_ENFORCED) != 0)
6245 [ + - ]: 4 : ereport(ERROR,
6246 : : errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
6247 : : errmsg("constraint triggers cannot be marked %s",
6248 : : "NOT ENFORCED"),
6249 : : parser_errposition(@11));
6250 : :
6251 : 53 : n->replace = $2;
6252 [ - + ]: 53 : if (n->replace) /* not supported, see CreateTrigger */
6253 [ # # ]: 0 : ereport(ERROR,
6254 : : (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
6255 : : errmsg("CREATE OR REPLACE CONSTRAINT TRIGGER is not supported"),
6256 : : parser_errposition(@1)));
6257 : 53 : n->isconstraint = true;
6258 : 53 : n->trigname = $5;
6259 : 53 : n->relation = $9;
6260 : 53 : n->funcname = $18;
6261 : 53 : n->args = $20;
6262 : 53 : n->row = true;
6263 : 53 : n->timing = TRIGGER_TYPE_AFTER;
6264 : 53 : n->events = intVal(linitial($7));
6265 : 53 : n->columns = (List *) lsecond($7);
6266 : 53 : n->whenClause = $15;
6267 : 53 : n->transitionRels = NIL;
6268 : 53 : processCASbits($11, @11, "TRIGGER",
6269 : : &n->deferrable, &n->initdeferred, &dummy,
6270 : : NULL, NULL, yyscanner);
6271 : 53 : n->constrrel = $10;
6272 : 53 : $$ = (Node *) n;
6273 : : }
6274 : : ;
6275 : :
6276 : : TriggerActionTime:
6277 : 941 : BEFORE { $$ = TRIGGER_TYPE_BEFORE; }
6278 : 1083 : | AFTER { $$ = TRIGGER_TYPE_AFTER; }
6279 : 111 : | INSTEAD OF { $$ = TRIGGER_TYPE_INSTEAD; }
6280 : : ;
6281 : :
6282 : : TriggerEvents:
6283 : : TriggerOneEvent
6284 : 2200 : { $$ = $1; }
6285 : : | TriggerEvents OR TriggerOneEvent
6286 : : {
6287 : 728 : int events1 = intVal(linitial($1));
6288 : 728 : int events2 = intVal(linitial($3));
6289 : 728 : List *columns1 = (List *) lsecond($1);
6290 : 728 : List *columns2 = (List *) lsecond($3);
6291 : :
6292 [ + + ]: 728 : if (events1 & events2)
6293 : 4 : parser_yyerror("duplicate trigger events specified");
6294 : : /*
6295 : : * concat'ing the columns lists loses information about
6296 : : * which columns went with which event, but so long as
6297 : : * only UPDATE carries columns and we disallow multiple
6298 : : * UPDATE items, it doesn't matter. Command execution
6299 : : * should just ignore the columns for non-UPDATE events.
6300 : : */
6301 : 724 : $$ = list_make2(makeInteger(events1 | events2),
6302 : : list_concat(columns1, columns2));
6303 : : }
6304 : : ;
6305 : :
6306 : : TriggerOneEvent:
6307 : : INSERT
6308 : 1143 : { $$ = list_make2(makeInteger(TRIGGER_TYPE_INSERT), NIL); }
6309 : : | DELETE_P
6310 : 586 : { $$ = list_make2(makeInteger(TRIGGER_TYPE_DELETE), NIL); }
6311 : : | UPDATE
6312 : 1094 : { $$ = list_make2(makeInteger(TRIGGER_TYPE_UPDATE), NIL); }
6313 : : | UPDATE OF columnList
6314 : 81 : { $$ = list_make2(makeInteger(TRIGGER_TYPE_UPDATE), $3); }
6315 : : | TRUNCATE
6316 : 24 : { $$ = list_make2(makeInteger(TRIGGER_TYPE_TRUNCATE), NIL); }
6317 : : ;
6318 : :
6319 : : TriggerReferencing:
6320 : 328 : REFERENCING TriggerTransitions { $$ = $2; }
6321 : 1799 : | /*EMPTY*/ { $$ = NIL; }
6322 : : ;
6323 : :
6324 : : TriggerTransitions:
6325 : 328 : TriggerTransition { $$ = list_make1($1); }
6326 : 100 : | TriggerTransitions TriggerTransition { $$ = lappend($1, $2); }
6327 : : ;
6328 : :
6329 : : TriggerTransition:
6330 : : TransitionOldOrNew TransitionRowOrTable opt_as TransitionRelName
6331 : : {
6332 : 428 : TriggerTransition *n = makeNode(TriggerTransition);
6333 : :
6334 : 428 : n->name = $4;
6335 : 428 : n->isNew = $1;
6336 : 428 : n->isTable = $2;
6337 : 428 : $$ = (Node *) n;
6338 : : }
6339 : : ;
6340 : :
6341 : : TransitionOldOrNew:
6342 : 232 : NEW { $$ = true; }
6343 : 196 : | OLD { $$ = false; }
6344 : : ;
6345 : :
6346 : : TransitionRowOrTable:
6347 : 428 : TABLE { $$ = true; }
6348 : : /*
6349 : : * According to the standard, lack of a keyword here implies ROW.
6350 : : * Support for that would require prohibiting ROW entirely here,
6351 : : * reserving the keyword ROW, and/or requiring AS (instead of
6352 : : * allowing it to be optional, as the standard specifies) as the
6353 : : * next token. Requiring ROW seems cleanest and easiest to
6354 : : * explain.
6355 : : */
6356 : 0 : | ROW { $$ = false; }
6357 : : ;
6358 : :
6359 : : TransitionRelName:
6360 : 428 : ColId { $$ = $1; }
6361 : : ;
6362 : :
6363 : : TriggerForSpec:
6364 : : FOR TriggerForOptEach TriggerForType
6365 : : {
6366 : 1993 : $$ = $3;
6367 : : }
6368 : : | /* EMPTY */
6369 : : {
6370 : : /*
6371 : : * If ROW/STATEMENT not specified, default to
6372 : : * STATEMENT, per SQL
6373 : : */
6374 : 134 : $$ = false;
6375 : : }
6376 : : ;
6377 : :
6378 : : TriggerForOptEach:
6379 : : EACH
6380 : : | /*EMPTY*/
6381 : : ;
6382 : :
6383 : : TriggerForType:
6384 : 1409 : ROW { $$ = true; }
6385 : 584 : | STATEMENT { $$ = false; }
6386 : : ;
6387 : :
6388 : : TriggerWhen:
6389 : 124 : WHEN '(' a_expr ')' { $$ = $3; }
6390 : 2068 : | /*EMPTY*/ { $$ = NULL; }
6391 : : ;
6392 : :
6393 : : FUNCTION_or_PROCEDURE:
6394 : : FUNCTION
6395 : : | PROCEDURE
6396 : : ;
6397 : :
6398 : : TriggerFuncArgs:
6399 : 464 : TriggerFuncArg { $$ = list_make1($1); }
6400 : 155 : | TriggerFuncArgs ',' TriggerFuncArg { $$ = lappend($1, $3); }
6401 : 1728 : | /*EMPTY*/ { $$ = NIL; }
6402 : : ;
6403 : :
6404 : : TriggerFuncArg:
6405 : : Iconst
6406 : : {
6407 : 49 : $$ = (Node *) makeString(psprintf("%d", $1));
6408 : : }
6409 : 0 : | FCONST { $$ = (Node *) makeString($1); }
6410 : 373 : | Sconst { $$ = (Node *) makeString($1); }
6411 : 197 : | ColLabel { $$ = (Node *) makeString($1); }
6412 : : ;
6413 : :
6414 : : OptConstrFromTable:
6415 : 8 : FROM qualified_name { $$ = $2; }
6416 : 57 : | /*EMPTY*/ { $$ = NULL; }
6417 : : ;
6418 : :
6419 : : ConstraintAttributeSpec:
6420 : : /*EMPTY*/
6421 : 11907 : { $$ = 0; }
6422 : : | ConstraintAttributeSpec ConstraintAttributeElem
6423 : : {
6424 : : /*
6425 : : * We must complain about conflicting options.
6426 : : * We could, but choose not to, complain about redundant
6427 : : * options (ie, where $2's bit is already set in $1).
6428 : : */
6429 : 1290 : int newspec = $1 | $2;
6430 : :
6431 : : /* special message for this case */
6432 [ + + ]: 1290 : if ((newspec & (CAS_NOT_DEFERRABLE | CAS_INITIALLY_DEFERRED)) == (CAS_NOT_DEFERRABLE | CAS_INITIALLY_DEFERRED))
6433 [ + - ]: 4 : ereport(ERROR,
6434 : : (errcode(ERRCODE_SYNTAX_ERROR),
6435 : : errmsg("constraint declared INITIALLY DEFERRED must be DEFERRABLE"),
6436 : : parser_errposition(@2)));
6437 : : /* generic message for other conflicts */
6438 [ + - ]: 1286 : if ((newspec & (CAS_NOT_DEFERRABLE | CAS_DEFERRABLE)) == (CAS_NOT_DEFERRABLE | CAS_DEFERRABLE) ||
6439 [ + - ]: 1286 : (newspec & (CAS_INITIALLY_IMMEDIATE | CAS_INITIALLY_DEFERRED)) == (CAS_INITIALLY_IMMEDIATE | CAS_INITIALLY_DEFERRED) ||
6440 [ + + ]: 1286 : (newspec & (CAS_NOT_ENFORCED | CAS_ENFORCED)) == (CAS_NOT_ENFORCED | CAS_ENFORCED))
6441 [ + - ]: 4 : ereport(ERROR,
6442 : : (errcode(ERRCODE_SYNTAX_ERROR),
6443 : : errmsg("conflicting constraint properties"),
6444 : : parser_errposition(@2)));
6445 : 1282 : $$ = newspec;
6446 : : }
6447 : : ;
6448 : :
6449 : : ConstraintAttributeElem:
6450 : 32 : NOT DEFERRABLE { $$ = CAS_NOT_DEFERRABLE; }
6451 : 149 : | DEFERRABLE { $$ = CAS_DEFERRABLE; }
6452 : 20 : | INITIALLY IMMEDIATE { $$ = CAS_INITIALLY_IMMEDIATE; }
6453 : 116 : | INITIALLY DEFERRED { $$ = CAS_INITIALLY_DEFERRED; }
6454 : 447 : | NOT VALID { $$ = CAS_NOT_VALID; }
6455 : 171 : | NO INHERIT { $$ = CAS_NO_INHERIT; }
6456 : 211 : | NOT ENFORCED { $$ = CAS_NOT_ENFORCED; }
6457 : 144 : | ENFORCED { $$ = CAS_ENFORCED; }
6458 : : ;
6459 : :
6460 : :
6461 : : /*****************************************************************************
6462 : : *
6463 : : * QUERIES :
6464 : : * CREATE EVENT TRIGGER ...
6465 : : * ALTER EVENT TRIGGER ...
6466 : : *
6467 : : *****************************************************************************/
6468 : :
6469 : : CreateEventTrigStmt:
6470 : : CREATE EVENT TRIGGER name ON ColLabel
6471 : : EXECUTE FUNCTION_or_PROCEDURE func_name '(' ')'
6472 : : {
6473 : 64 : CreateEventTrigStmt *n = makeNode(CreateEventTrigStmt);
6474 : :
6475 : 64 : n->trigname = $4;
6476 : 64 : n->eventname = $6;
6477 : 64 : n->whenclause = NULL;
6478 : 64 : n->funcname = $9;
6479 : 64 : $$ = (Node *) n;
6480 : : }
6481 : : | CREATE EVENT TRIGGER name ON ColLabel
6482 : : WHEN event_trigger_when_list
6483 : : EXECUTE FUNCTION_or_PROCEDURE func_name '(' ')'
6484 : : {
6485 : 65 : CreateEventTrigStmt *n = makeNode(CreateEventTrigStmt);
6486 : :
6487 : 65 : n->trigname = $4;
6488 : 65 : n->eventname = $6;
6489 : 65 : n->whenclause = $8;
6490 : 65 : n->funcname = $11;
6491 : 65 : $$ = (Node *) n;
6492 : : }
6493 : : ;
6494 : :
6495 : : event_trigger_when_list:
6496 : : event_trigger_when_item
6497 : 65 : { $$ = list_make1($1); }
6498 : : | event_trigger_when_list AND event_trigger_when_item
6499 : 4 : { $$ = lappend($1, $3); }
6500 : : ;
6501 : :
6502 : : event_trigger_when_item:
6503 : : ColId IN_P '(' event_trigger_value_list ')'
6504 : 69 : { $$ = makeDefElem($1, (Node *) $4, @1); }
6505 : : ;
6506 : :
6507 : : event_trigger_value_list:
6508 : : SCONST
6509 : 69 : { $$ = list_make1(makeString($1)); }
6510 : : | event_trigger_value_list ',' SCONST
6511 : 44 : { $$ = lappend($1, makeString($3)); }
6512 : : ;
6513 : :
6514 : : AlterEventTrigStmt:
6515 : : ALTER EVENT TRIGGER name enable_trigger
6516 : : {
6517 : 32 : AlterEventTrigStmt *n = makeNode(AlterEventTrigStmt);
6518 : :
6519 : 32 : n->trigname = $4;
6520 : 32 : n->tgenabled = $5;
6521 : 32 : $$ = (Node *) n;
6522 : : }
6523 : : ;
6524 : :
6525 : : enable_trigger:
6526 : 4 : ENABLE_P { $$ = TRIGGER_FIRES_ON_ORIGIN; }
6527 : 4 : | ENABLE_P REPLICA { $$ = TRIGGER_FIRES_ON_REPLICA; }
6528 : 11 : | ENABLE_P ALWAYS { $$ = TRIGGER_FIRES_ALWAYS; }
6529 : 13 : | DISABLE_P { $$ = TRIGGER_DISABLED; }
6530 : : ;
6531 : :
6532 : : /*****************************************************************************
6533 : : *
6534 : : * QUERY :
6535 : : * CREATE ASSERTION ...
6536 : : *
6537 : : *****************************************************************************/
6538 : :
6539 : : CreateAssertionStmt:
6540 : : CREATE ASSERTION any_name CHECK '(' a_expr ')' ConstraintAttributeSpec
6541 : : {
6542 [ # # ]: 0 : ereport(ERROR,
6543 : : (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
6544 : : errmsg("CREATE ASSERTION is not yet implemented"),
6545 : : parser_errposition(@1)));
6546 : :
6547 : : $$ = NULL;
6548 : : }
6549 : : ;
6550 : :
6551 : :
6552 : : /*****************************************************************************
6553 : : *
6554 : : * QUERY :
6555 : : * define (aggregate,operator,type)
6556 : : *
6557 : : *****************************************************************************/
6558 : :
6559 : : DefineStmt:
6560 : : CREATE opt_or_replace AGGREGATE func_name aggr_args definition
6561 : : {
6562 : 345 : DefineStmt *n = makeNode(DefineStmt);
6563 : :
6564 : 345 : n->kind = OBJECT_AGGREGATE;
6565 : 345 : n->oldstyle = false;
6566 : 345 : n->replace = $2;
6567 : 345 : n->defnames = $4;
6568 : 345 : n->args = $5;
6569 : 345 : n->definition = $6;
6570 : 345 : $$ = (Node *) n;
6571 : : }
6572 : : | CREATE opt_or_replace AGGREGATE func_name old_aggr_definition
6573 : : {
6574 : : /* old-style (pre-8.2) syntax for CREATE AGGREGATE */
6575 : 240 : DefineStmt *n = makeNode(DefineStmt);
6576 : :
6577 : 240 : n->kind = OBJECT_AGGREGATE;
6578 : 240 : n->oldstyle = true;
6579 : 240 : n->replace = $2;
6580 : 240 : n->defnames = $4;
6581 : 240 : n->args = NIL;
6582 : 240 : n->definition = $5;
6583 : 240 : $$ = (Node *) n;
6584 : : }
6585 : : | CREATE OPERATOR any_operator definition
6586 : : {
6587 : 893 : DefineStmt *n = makeNode(DefineStmt);
6588 : :
6589 : 893 : n->kind = OBJECT_OPERATOR;
6590 : 893 : n->oldstyle = false;
6591 : 893 : n->defnames = $3;
6592 : 893 : n->args = NIL;
6593 : 893 : n->definition = $4;
6594 : 893 : $$ = (Node *) n;
6595 : : }
6596 : : | CREATE TYPE_P any_name definition
6597 : : {
6598 : 145 : DefineStmt *n = makeNode(DefineStmt);
6599 : :
6600 : 145 : n->kind = OBJECT_TYPE;
6601 : 145 : n->oldstyle = false;
6602 : 145 : n->defnames = $3;
6603 : 145 : n->args = NIL;
6604 : 145 : n->definition = $4;
6605 : 145 : $$ = (Node *) n;
6606 : : }
6607 : : | CREATE TYPE_P any_name
6608 : : {
6609 : : /* Shell type (identified by lack of definition) */
6610 : 98 : DefineStmt *n = makeNode(DefineStmt);
6611 : :
6612 : 98 : n->kind = OBJECT_TYPE;
6613 : 98 : n->oldstyle = false;
6614 : 98 : n->defnames = $3;
6615 : 98 : n->args = NIL;
6616 : 98 : n->definition = NIL;
6617 : 98 : $$ = (Node *) n;
6618 : : }
6619 : : | CREATE TYPE_P any_name AS '(' OptTableFuncElementList ')'
6620 : : {
6621 : 2376 : CompositeTypeStmt *n = makeNode(CompositeTypeStmt);
6622 : :
6623 : : /* can't use qualified_name, sigh */
6624 : 2376 : n->typevar = makeRangeVarFromAnyName($3, @3, yyscanner);
6625 : 2376 : n->coldeflist = $6;
6626 : 2376 : $$ = (Node *) n;
6627 : : }
6628 : : | CREATE TYPE_P any_name AS ENUM_P '(' opt_enum_val_list ')'
6629 : : {
6630 : 167 : CreateEnumStmt *n = makeNode(CreateEnumStmt);
6631 : :
6632 : 167 : n->typeName = $3;
6633 : 167 : n->vals = $7;
6634 : 167 : $$ = (Node *) n;
6635 : : }
6636 : : | CREATE TYPE_P any_name AS RANGE definition
6637 : : {
6638 : 150 : CreateRangeStmt *n = makeNode(CreateRangeStmt);
6639 : :
6640 : 150 : n->typeName = $3;
6641 : 150 : n->params = $6;
6642 : 150 : $$ = (Node *) n;
6643 : : }
6644 : : | CREATE TEXT_P SEARCH PARSER any_name definition
6645 : : {
6646 : 31 : DefineStmt *n = makeNode(DefineStmt);
6647 : :
6648 : 31 : n->kind = OBJECT_TSPARSER;
6649 : 31 : n->args = NIL;
6650 : 31 : n->defnames = $5;
6651 : 31 : n->definition = $6;
6652 : 31 : $$ = (Node *) n;
6653 : : }
6654 : : | CREATE TEXT_P SEARCH DICTIONARY any_name definition
6655 : : {
6656 : 1802 : DefineStmt *n = makeNode(DefineStmt);
6657 : :
6658 : 1802 : n->kind = OBJECT_TSDICTIONARY;
6659 : 1802 : n->args = NIL;
6660 : 1802 : n->defnames = $5;
6661 : 1802 : n->definition = $6;
6662 : 1802 : $$ = (Node *) n;
6663 : : }
6664 : : | CREATE TEXT_P SEARCH TEMPLATE any_name definition
6665 : : {
6666 : 87 : DefineStmt *n = makeNode(DefineStmt);
6667 : :
6668 : 87 : n->kind = OBJECT_TSTEMPLATE;
6669 : 87 : n->args = NIL;
6670 : 87 : n->defnames = $5;
6671 : 87 : n->definition = $6;
6672 : 87 : $$ = (Node *) n;
6673 : : }
6674 : : | CREATE TEXT_P SEARCH CONFIGURATION any_name definition
6675 : : {
6676 : 1766 : DefineStmt *n = makeNode(DefineStmt);
6677 : :
6678 : 1766 : n->kind = OBJECT_TSCONFIGURATION;
6679 : 1766 : n->args = NIL;
6680 : 1766 : n->defnames = $5;
6681 : 1766 : n->definition = $6;
6682 : 1766 : $$ = (Node *) n;
6683 : : }
6684 : : | CREATE COLLATION any_name definition
6685 : : {
6686 : 201 : DefineStmt *n = makeNode(DefineStmt);
6687 : :
6688 : 201 : n->kind = OBJECT_COLLATION;
6689 : 201 : n->args = NIL;
6690 : 201 : n->defnames = $3;
6691 : 201 : n->definition = $4;
6692 : 201 : $$ = (Node *) n;
6693 : : }
6694 : : | CREATE COLLATION IF_P NOT EXISTS any_name definition
6695 : : {
6696 : 9 : DefineStmt *n = makeNode(DefineStmt);
6697 : :
6698 : 9 : n->kind = OBJECT_COLLATION;
6699 : 9 : n->args = NIL;
6700 : 9 : n->defnames = $6;
6701 : 9 : n->definition = $7;
6702 : 9 : n->if_not_exists = true;
6703 : 9 : $$ = (Node *) n;
6704 : : }
6705 : : | CREATE COLLATION any_name FROM any_name
6706 : : {
6707 : 35 : DefineStmt *n = makeNode(DefineStmt);
6708 : :
6709 : 35 : n->kind = OBJECT_COLLATION;
6710 : 35 : n->args = NIL;
6711 : 35 : n->defnames = $3;
6712 : 35 : n->definition = list_make1(makeDefElem("from", (Node *) $5, @5));
6713 : 35 : $$ = (Node *) n;
6714 : : }
6715 : : | CREATE COLLATION IF_P NOT EXISTS any_name FROM any_name
6716 : : {
6717 : 0 : DefineStmt *n = makeNode(DefineStmt);
6718 : :
6719 : 0 : n->kind = OBJECT_COLLATION;
6720 : 0 : n->args = NIL;
6721 : 0 : n->defnames = $6;
6722 : 0 : n->definition = list_make1(makeDefElem("from", (Node *) $8, @8));
6723 : 0 : n->if_not_exists = true;
6724 : 0 : $$ = (Node *) n;
6725 : : }
6726 : : ;
6727 : :
6728 : 6244 : definition: '(' def_list ')' { $$ = $2; }
6729 : : ;
6730 : :
6731 : 6244 : def_list: def_elem { $$ = list_make1($1); }
6732 : 8557 : | def_list ',' def_elem { $$ = lappend($1, $3); }
6733 : : ;
6734 : :
6735 : : def_elem: ColLabel '=' def_arg
6736 : : {
6737 : 14606 : $$ = makeDefElem($1, (Node *) $3, @1);
6738 : : }
6739 : : | ColLabel
6740 : : {
6741 : 195 : $$ = makeDefElem($1, NULL, @1);
6742 : : }
6743 : : ;
6744 : :
6745 : : /* Note: any simple identifier will be returned as a type name! */
6746 : 11732 : def_arg: func_type { $$ = (Node *) $1; }
6747 : 2721 : | reserved_keyword { $$ = (Node *) makeString(pstrdup($1)); }
6748 : 626 : | qual_all_Op { $$ = (Node *) $1; }
6749 : 886 : | NumericOnly { $$ = (Node *) $1; }
6750 : 1196 : | Sconst { $$ = (Node *) makeString($1); }
6751 : 155 : | NONE { $$ = (Node *) makeString(pstrdup($1)); }
6752 : : ;
6753 : :
6754 : 240 : old_aggr_definition: '(' old_aggr_list ')' { $$ = $2; }
6755 : : ;
6756 : :
6757 : 240 : old_aggr_list: old_aggr_elem { $$ = list_make1($1); }
6758 : 856 : | old_aggr_list ',' old_aggr_elem { $$ = lappend($1, $3); }
6759 : : ;
6760 : :
6761 : : /*
6762 : : * Must use IDENT here to avoid reduce/reduce conflicts; fortunately none of
6763 : : * the item names needed in old aggregate definitions are likely to become
6764 : : * SQL keywords.
6765 : : */
6766 : : old_aggr_elem: IDENT '=' def_arg
6767 : : {
6768 : 1096 : $$ = makeDefElem($1, (Node *) $3, @1);
6769 : : }
6770 : : ;
6771 : :
6772 : : opt_enum_val_list:
6773 : 163 : enum_val_list { $$ = $1; }
6774 : 4 : | /*EMPTY*/ { $$ = NIL; }
6775 : : ;
6776 : :
6777 : : enum_val_list: Sconst
6778 : 163 : { $$ = list_make1(makeString($1)); }
6779 : : | enum_val_list ',' Sconst
6780 : 5297 : { $$ = lappend($1, makeString($3)); }
6781 : : ;
6782 : :
6783 : : /*****************************************************************************
6784 : : *
6785 : : * ALTER TYPE enumtype ADD ...
6786 : : *
6787 : : *****************************************************************************/
6788 : :
6789 : : AlterEnumStmt:
6790 : : ALTER TYPE_P any_name ADD_P VALUE_P opt_if_not_exists Sconst
6791 : : {
6792 : 86 : AlterEnumStmt *n = makeNode(AlterEnumStmt);
6793 : :
6794 : 86 : n->typeName = $3;
6795 : 86 : n->oldVal = NULL;
6796 : 86 : n->newVal = $7;
6797 : 86 : n->newValNeighbor = NULL;
6798 : 86 : n->newValIsAfter = true;
6799 : 86 : n->skipIfNewValExists = $6;
6800 : 86 : $$ = (Node *) n;
6801 : : }
6802 : : | ALTER TYPE_P any_name ADD_P VALUE_P opt_if_not_exists Sconst BEFORE Sconst
6803 : : {
6804 : 130 : AlterEnumStmt *n = makeNode(AlterEnumStmt);
6805 : :
6806 : 130 : n->typeName = $3;
6807 : 130 : n->oldVal = NULL;
6808 : 130 : n->newVal = $7;
6809 : 130 : n->newValNeighbor = $9;
6810 : 130 : n->newValIsAfter = false;
6811 : 130 : n->skipIfNewValExists = $6;
6812 : 130 : $$ = (Node *) n;
6813 : : }
6814 : : | ALTER TYPE_P any_name ADD_P VALUE_P opt_if_not_exists Sconst AFTER Sconst
6815 : : {
6816 : 14 : AlterEnumStmt *n = makeNode(AlterEnumStmt);
6817 : :
6818 : 14 : n->typeName = $3;
6819 : 14 : n->oldVal = NULL;
6820 : 14 : n->newVal = $7;
6821 : 14 : n->newValNeighbor = $9;
6822 : 14 : n->newValIsAfter = true;
6823 : 14 : n->skipIfNewValExists = $6;
6824 : 14 : $$ = (Node *) n;
6825 : : }
6826 : : | ALTER TYPE_P any_name RENAME VALUE_P Sconst TO Sconst
6827 : : {
6828 : 16 : AlterEnumStmt *n = makeNode(AlterEnumStmt);
6829 : :
6830 : 16 : n->typeName = $3;
6831 : 16 : n->oldVal = $6;
6832 : 16 : n->newVal = $8;
6833 : 16 : n->newValNeighbor = NULL;
6834 : 16 : n->newValIsAfter = false;
6835 : 16 : n->skipIfNewValExists = false;
6836 : 16 : $$ = (Node *) n;
6837 : : }
6838 : : | ALTER TYPE_P any_name DROP VALUE_P Sconst
6839 : : {
6840 : : /*
6841 : : * The following problems must be solved before this can be
6842 : : * implemented:
6843 : : *
6844 : : * - There must be no instance of the target value in
6845 : : * any table.
6846 : : *
6847 : : * - The value must not appear in any catalog metadata,
6848 : : * such as stored view expressions or column defaults.
6849 : : *
6850 : : * - The value must not appear in any non-leaf page of a
6851 : : * btree (and similar issues with other index types).
6852 : : * This is problematic because a value could persist
6853 : : * there long after it's gone from user-visible data.
6854 : : *
6855 : : * - Concurrent sessions must not be able to insert the
6856 : : * value while the preceding conditions are being checked.
6857 : : *
6858 : : * - Possibly more...
6859 : : */
6860 [ # # ]: 0 : ereport(ERROR,
6861 : : (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
6862 : : errmsg("dropping an enum value is not implemented"),
6863 : : parser_errposition(@4)));
6864 : : }
6865 : : ;
6866 : :
6867 : 8 : opt_if_not_exists: IF_P NOT EXISTS { $$ = true; }
6868 : 222 : | /* EMPTY */ { $$ = false; }
6869 : : ;
6870 : :
6871 : :
6872 : : /*****************************************************************************
6873 : : *
6874 : : * QUERIES :
6875 : : * CREATE OPERATOR CLASS ...
6876 : : * CREATE OPERATOR FAMILY ...
6877 : : * ALTER OPERATOR FAMILY ...
6878 : : * DROP OPERATOR CLASS ...
6879 : : * DROP OPERATOR FAMILY ...
6880 : : *
6881 : : *****************************************************************************/
6882 : :
6883 : : CreateOpClassStmt:
6884 : : CREATE OPERATOR CLASS any_name opt_default FOR TYPE_P Typename
6885 : : USING name opt_opfamily AS opclass_item_list
6886 : : {
6887 : 295 : CreateOpClassStmt *n = makeNode(CreateOpClassStmt);
6888 : :
6889 : 295 : n->opclassname = $4;
6890 : 295 : n->isDefault = $5;
6891 : 295 : n->datatype = $8;
6892 : 295 : n->amname = $10;
6893 : 295 : n->opfamilyname = $11;
6894 : 295 : n->items = $13;
6895 : 295 : $$ = (Node *) n;
6896 : : }
6897 : : ;
6898 : :
6899 : : opclass_item_list:
6900 : 533 : opclass_item { $$ = list_make1($1); }
6901 : 2994 : | opclass_item_list ',' opclass_item { $$ = lappend($1, $3); }
6902 : : ;
6903 : :
6904 : : opclass_item:
6905 : : OPERATOR Iconst any_operator opclass_purpose
6906 : : {
6907 : 1063 : CreateOpClassItem *n = makeNode(CreateOpClassItem);
6908 : 1063 : ObjectWithArgs *owa = makeNode(ObjectWithArgs);
6909 : :
6910 : 1063 : owa->objname = $3;
6911 : 1063 : owa->objargs = NIL;
6912 : 1063 : n->itemtype = OPCLASS_ITEM_OPERATOR;
6913 : 1063 : n->name = owa;
6914 : 1063 : n->number = $2;
6915 : 1063 : n->order_family = $4;
6916 : 1063 : $$ = (Node *) n;
6917 : : }
6918 : : | OPERATOR Iconst operator_with_argtypes opclass_purpose
6919 : : {
6920 : 739 : CreateOpClassItem *n = makeNode(CreateOpClassItem);
6921 : :
6922 : 739 : n->itemtype = OPCLASS_ITEM_OPERATOR;
6923 : 739 : n->name = $3;
6924 : 739 : n->number = $2;
6925 : 739 : n->order_family = $4;
6926 : 739 : $$ = (Node *) n;
6927 : : }
6928 : : | FUNCTION Iconst function_with_argtypes
6929 : : {
6930 : 1419 : CreateOpClassItem *n = makeNode(CreateOpClassItem);
6931 : :
6932 : 1419 : n->itemtype = OPCLASS_ITEM_FUNCTION;
6933 : 1419 : n->name = $3;
6934 : 1419 : n->number = $2;
6935 : 1419 : $$ = (Node *) n;
6936 : : }
6937 : : | FUNCTION Iconst '(' type_list ')' function_with_argtypes
6938 : : {
6939 : 120 : CreateOpClassItem *n = makeNode(CreateOpClassItem);
6940 : :
6941 : 120 : n->itemtype = OPCLASS_ITEM_FUNCTION;
6942 : 120 : n->name = $6;
6943 : 120 : n->number = $2;
6944 : 120 : n->class_args = $4;
6945 : 120 : $$ = (Node *) n;
6946 : : }
6947 : : | STORAGE Typename
6948 : : {
6949 : 186 : CreateOpClassItem *n = makeNode(CreateOpClassItem);
6950 : :
6951 : 186 : n->itemtype = OPCLASS_ITEM_STORAGETYPE;
6952 : 186 : n->storedtype = $2;
6953 : 186 : $$ = (Node *) n;
6954 : : }
6955 : : ;
6956 : :
6957 : 226 : opt_default: DEFAULT { $$ = true; }
6958 : 111 : | /*EMPTY*/ { $$ = false; }
6959 : : ;
6960 : :
6961 : 22 : opt_opfamily: FAMILY any_name { $$ = $2; }
6962 : 273 : | /*EMPTY*/ { $$ = NIL; }
6963 : : ;
6964 : :
6965 : 0 : opclass_purpose: FOR SEARCH { $$ = NIL; }
6966 : 63 : | FOR ORDER BY any_name { $$ = $4; }
6967 : 1739 : | /*EMPTY*/ { $$ = NIL; }
6968 : : ;
6969 : :
6970 : :
6971 : : CreateOpFamilyStmt:
6972 : : CREATE OPERATOR FAMILY any_name USING name
6973 : : {
6974 : 95 : CreateOpFamilyStmt *n = makeNode(CreateOpFamilyStmt);
6975 : :
6976 : 95 : n->opfamilyname = $4;
6977 : 95 : n->amname = $6;
6978 : 95 : $$ = (Node *) n;
6979 : : }
6980 : : ;
6981 : :
6982 : : AlterOpFamilyStmt:
6983 : : ALTER OPERATOR FAMILY any_name USING name ADD_P opclass_item_list
6984 : : {
6985 : 238 : AlterOpFamilyStmt *n = makeNode(AlterOpFamilyStmt);
6986 : :
6987 : 238 : n->opfamilyname = $4;
6988 : 238 : n->amname = $6;
6989 : 238 : n->isDrop = false;
6990 : 238 : n->items = $8;
6991 : 238 : $$ = (Node *) n;
6992 : : }
6993 : : | ALTER OPERATOR FAMILY any_name USING name DROP opclass_drop_list
6994 : : {
6995 : 38 : AlterOpFamilyStmt *n = makeNode(AlterOpFamilyStmt);
6996 : :
6997 : 38 : n->opfamilyname = $4;
6998 : 38 : n->amname = $6;
6999 : 38 : n->isDrop = true;
7000 : 38 : n->items = $8;
7001 : 38 : $$ = (Node *) n;
7002 : : }
7003 : : ;
7004 : :
7005 : : opclass_drop_list:
7006 : 38 : opclass_drop { $$ = list_make1($1); }
7007 : 20 : | opclass_drop_list ',' opclass_drop { $$ = lappend($1, $3); }
7008 : : ;
7009 : :
7010 : : opclass_drop:
7011 : : OPERATOR Iconst '(' type_list ')'
7012 : : {
7013 : 36 : CreateOpClassItem *n = makeNode(CreateOpClassItem);
7014 : :
7015 : 36 : n->itemtype = OPCLASS_ITEM_OPERATOR;
7016 : 36 : n->number = $2;
7017 : 36 : n->class_args = $4;
7018 : 36 : $$ = (Node *) n;
7019 : : }
7020 : : | FUNCTION Iconst '(' type_list ')'
7021 : : {
7022 : 22 : CreateOpClassItem *n = makeNode(CreateOpClassItem);
7023 : :
7024 : 22 : n->itemtype = OPCLASS_ITEM_FUNCTION;
7025 : 22 : n->number = $2;
7026 : 22 : n->class_args = $4;
7027 : 22 : $$ = (Node *) n;
7028 : : }
7029 : : ;
7030 : :
7031 : :
7032 : : DropOpClassStmt:
7033 : : DROP OPERATOR CLASS any_name USING name opt_drop_behavior
7034 : : {
7035 : 25 : DropStmt *n = makeNode(DropStmt);
7036 : :
7037 : 25 : n->objects = list_make1(lcons(makeString($6), $4));
7038 : 25 : n->removeType = OBJECT_OPCLASS;
7039 : 25 : n->behavior = $7;
7040 : 25 : n->missing_ok = false;
7041 : 25 : n->concurrent = false;
7042 : 25 : $$ = (Node *) n;
7043 : : }
7044 : : | DROP OPERATOR CLASS IF_P EXISTS any_name USING name opt_drop_behavior
7045 : : {
7046 : 12 : DropStmt *n = makeNode(DropStmt);
7047 : :
7048 : 12 : n->objects = list_make1(lcons(makeString($8), $6));
7049 : 12 : n->removeType = OBJECT_OPCLASS;
7050 : 12 : n->behavior = $9;
7051 : 12 : n->missing_ok = true;
7052 : 12 : n->concurrent = false;
7053 : 12 : $$ = (Node *) n;
7054 : : }
7055 : : ;
7056 : :
7057 : : DropOpFamilyStmt:
7058 : : DROP OPERATOR FAMILY any_name USING name opt_drop_behavior
7059 : : {
7060 : 73 : DropStmt *n = makeNode(DropStmt);
7061 : :
7062 : 73 : n->objects = list_make1(lcons(makeString($6), $4));
7063 : 73 : n->removeType = OBJECT_OPFAMILY;
7064 : 73 : n->behavior = $7;
7065 : 73 : n->missing_ok = false;
7066 : 73 : n->concurrent = false;
7067 : 73 : $$ = (Node *) n;
7068 : : }
7069 : : | DROP OPERATOR FAMILY IF_P EXISTS any_name USING name opt_drop_behavior
7070 : : {
7071 : 12 : DropStmt *n = makeNode(DropStmt);
7072 : :
7073 : 12 : n->objects = list_make1(lcons(makeString($8), $6));
7074 : 12 : n->removeType = OBJECT_OPFAMILY;
7075 : 12 : n->behavior = $9;
7076 : 12 : n->missing_ok = true;
7077 : 12 : n->concurrent = false;
7078 : 12 : $$ = (Node *) n;
7079 : : }
7080 : : ;
7081 : :
7082 : :
7083 : : /*****************************************************************************
7084 : : *
7085 : : * QUERY:
7086 : : *
7087 : : * DROP OWNED BY username [, username ...] [ RESTRICT | CASCADE ]
7088 : : * REASSIGN OWNED BY username [, username ...] TO username
7089 : : *
7090 : : *****************************************************************************/
7091 : : DropOwnedStmt:
7092 : : DROP OWNED BY role_list opt_drop_behavior
7093 : : {
7094 : 94 : DropOwnedStmt *n = makeNode(DropOwnedStmt);
7095 : :
7096 : 94 : n->roles = $4;
7097 : 94 : n->behavior = $5;
7098 : 94 : $$ = (Node *) n;
7099 : : }
7100 : : ;
7101 : :
7102 : : ReassignOwnedStmt:
7103 : : REASSIGN OWNED BY role_list TO RoleSpec
7104 : : {
7105 : 36 : ReassignOwnedStmt *n = makeNode(ReassignOwnedStmt);
7106 : :
7107 : 36 : n->roles = $4;
7108 : 36 : n->newrole = $6;
7109 : 36 : $$ = (Node *) n;
7110 : : }
7111 : : ;
7112 : :
7113 : : /*****************************************************************************
7114 : : *
7115 : : * QUERY:
7116 : : *
7117 : : * DROP itemtype [ IF EXISTS ] itemname [, itemname ...]
7118 : : * [ RESTRICT | CASCADE ]
7119 : : *
7120 : : *****************************************************************************/
7121 : :
7122 : : DropStmt: DROP object_type_any_name IF_P EXISTS any_name_list opt_drop_behavior
7123 : : {
7124 : 774 : DropStmt *n = makeNode(DropStmt);
7125 : :
7126 : 774 : n->removeType = $2;
7127 : 774 : n->missing_ok = true;
7128 : 774 : n->objects = $5;
7129 : 774 : n->behavior = $6;
7130 : 774 : n->concurrent = false;
7131 : 774 : $$ = (Node *) n;
7132 : : }
7133 : : | DROP object_type_any_name any_name_list opt_drop_behavior
7134 : : {
7135 : 11314 : DropStmt *n = makeNode(DropStmt);
7136 : :
7137 : 11314 : n->removeType = $2;
7138 : 11314 : n->missing_ok = false;
7139 : 11314 : n->objects = $3;
7140 : 11314 : n->behavior = $4;
7141 : 11314 : n->concurrent = false;
7142 : 11314 : $$ = (Node *) n;
7143 : : }
7144 : : | DROP drop_type_name IF_P EXISTS name_list opt_drop_behavior
7145 : : {
7146 : 128 : DropStmt *n = makeNode(DropStmt);
7147 : :
7148 : 128 : n->removeType = $2;
7149 : 128 : n->missing_ok = true;
7150 : 128 : n->objects = $5;
7151 : 128 : n->behavior = $6;
7152 : 128 : n->concurrent = false;
7153 : 128 : $$ = (Node *) n;
7154 : : }
7155 : : | DROP drop_type_name name_list opt_drop_behavior
7156 : : {
7157 : 1056 : DropStmt *n = makeNode(DropStmt);
7158 : :
7159 : 1056 : n->removeType = $2;
7160 : 1056 : n->missing_ok = false;
7161 : 1056 : n->objects = $3;
7162 : 1056 : n->behavior = $4;
7163 : 1056 : n->concurrent = false;
7164 : 1056 : $$ = (Node *) n;
7165 : : }
7166 : : | DROP object_type_name_on_any_name name ON any_name opt_drop_behavior
7167 : : {
7168 : 823 : DropStmt *n = makeNode(DropStmt);
7169 : :
7170 : 823 : n->removeType = $2;
7171 : 823 : n->objects = list_make1(lappend($5, makeString($3)));
7172 : 823 : n->behavior = $6;
7173 : 823 : n->missing_ok = false;
7174 : 823 : n->concurrent = false;
7175 : 823 : $$ = (Node *) n;
7176 : : }
7177 : : | DROP object_type_name_on_any_name IF_P EXISTS name ON any_name opt_drop_behavior
7178 : : {
7179 : 32 : DropStmt *n = makeNode(DropStmt);
7180 : :
7181 : 32 : n->removeType = $2;
7182 : 32 : n->objects = list_make1(lappend($7, makeString($5)));
7183 : 32 : n->behavior = $8;
7184 : 32 : n->missing_ok = true;
7185 : 32 : n->concurrent = false;
7186 : 32 : $$ = (Node *) n;
7187 : : }
7188 : : | DROP TYPE_P type_name_list opt_drop_behavior
7189 : : {
7190 : 412 : DropStmt *n = makeNode(DropStmt);
7191 : :
7192 : 412 : n->removeType = OBJECT_TYPE;
7193 : 412 : n->missing_ok = false;
7194 : 412 : n->objects = $3;
7195 : 412 : n->behavior = $4;
7196 : 412 : n->concurrent = false;
7197 : 412 : $$ = (Node *) n;
7198 : : }
7199 : : | DROP TYPE_P IF_P EXISTS type_name_list opt_drop_behavior
7200 : : {
7201 : 50 : DropStmt *n = makeNode(DropStmt);
7202 : :
7203 : 50 : n->removeType = OBJECT_TYPE;
7204 : 50 : n->missing_ok = true;
7205 : 50 : n->objects = $5;
7206 : 50 : n->behavior = $6;
7207 : 50 : n->concurrent = false;
7208 : 50 : $$ = (Node *) n;
7209 : : }
7210 : : | DROP DOMAIN_P type_name_list opt_drop_behavior
7211 : : {
7212 : 346 : DropStmt *n = makeNode(DropStmt);
7213 : :
7214 : 346 : n->removeType = OBJECT_DOMAIN;
7215 : 346 : n->missing_ok = false;
7216 : 346 : n->objects = $3;
7217 : 346 : n->behavior = $4;
7218 : 346 : n->concurrent = false;
7219 : 346 : $$ = (Node *) n;
7220 : : }
7221 : : | DROP DOMAIN_P IF_P EXISTS type_name_list opt_drop_behavior
7222 : : {
7223 : 46 : DropStmt *n = makeNode(DropStmt);
7224 : :
7225 : 46 : n->removeType = OBJECT_DOMAIN;
7226 : 46 : n->missing_ok = true;
7227 : 46 : n->objects = $5;
7228 : 46 : n->behavior = $6;
7229 : 46 : n->concurrent = false;
7230 : 46 : $$ = (Node *) n;
7231 : : }
7232 : : | DROP INDEX CONCURRENTLY any_name_list opt_drop_behavior
7233 : : {
7234 : 101 : DropStmt *n = makeNode(DropStmt);
7235 : :
7236 : 101 : n->removeType = OBJECT_INDEX;
7237 : 101 : n->missing_ok = false;
7238 : 101 : n->objects = $4;
7239 : 101 : n->behavior = $5;
7240 : 101 : n->concurrent = true;
7241 : 101 : $$ = (Node *) n;
7242 : : }
7243 : : | DROP INDEX CONCURRENTLY IF_P EXISTS any_name_list opt_drop_behavior
7244 : : {
7245 : 8 : DropStmt *n = makeNode(DropStmt);
7246 : :
7247 : 8 : n->removeType = OBJECT_INDEX;
7248 : 8 : n->missing_ok = true;
7249 : 8 : n->objects = $6;
7250 : 8 : n->behavior = $7;
7251 : 8 : n->concurrent = true;
7252 : 8 : $$ = (Node *) n;
7253 : : }
7254 : : ;
7255 : :
7256 : : /* object types taking any_name/any_name_list */
7257 : : object_type_any_name:
7258 : 10364 : TABLE { $$ = OBJECT_TABLE; }
7259 : 135 : | SEQUENCE { $$ = OBJECT_SEQUENCE; }
7260 : 734 : | VIEW { $$ = OBJECT_VIEW; }
7261 : 85 : | MATERIALIZED VIEW { $$ = OBJECT_MATVIEW; }
7262 : 517 : | INDEX { $$ = OBJECT_INDEX; }
7263 : 122 : | FOREIGN TABLE { $$ = OBJECT_FOREIGN_TABLE; }
7264 : 58 : | PROPERTY GRAPH { $$ = OBJECT_PROPGRAPH; }
7265 : 63 : | COLLATION { $$ = OBJECT_COLLATION; }
7266 : 37 : | CONVERSION_P { $$ = OBJECT_CONVERSION; }
7267 : 157 : | STATISTICS { $$ = OBJECT_STATISTIC_EXT; }
7268 : 13 : | TEXT_P SEARCH PARSER { $$ = OBJECT_TSPARSER; }
7269 : 1724 : | TEXT_P SEARCH DICTIONARY { $$ = OBJECT_TSDICTIONARY; }
7270 : 68 : | TEXT_P SEARCH TEMPLATE { $$ = OBJECT_TSTEMPLATE; }
7271 : 1727 : | TEXT_P SEARCH CONFIGURATION { $$ = OBJECT_TSCONFIGURATION; }
7272 : : ;
7273 : :
7274 : : /*
7275 : : * object types taking name/name_list
7276 : : *
7277 : : * DROP handles some of them separately
7278 : : */
7279 : :
7280 : : object_type_name:
7281 : 141 : drop_type_name { $$ = $1; }
7282 : 139 : | DATABASE { $$ = OBJECT_DATABASE; }
7283 : 44 : | ROLE { $$ = OBJECT_ROLE; }
7284 : 6 : | SUBSCRIPTION { $$ = OBJECT_SUBSCRIPTION; }
7285 : 0 : | TABLESPACE { $$ = OBJECT_TABLESPACE; }
7286 : : ;
7287 : :
7288 : : drop_type_name:
7289 : 37 : ACCESS METHOD { $$ = OBJECT_ACCESS_METHOD; }
7290 : 85 : | EVENT TRIGGER { $$ = OBJECT_EVENT_TRIGGER; }
7291 : 112 : | EXTENSION { $$ = OBJECT_EXTENSION; }
7292 : 124 : | FOREIGN DATA_P WRAPPER { $$ = OBJECT_FDW; }
7293 : 88 : | opt_procedural LANGUAGE { $$ = OBJECT_LANGUAGE; }
7294 : 310 : | PUBLICATION { $$ = OBJECT_PUBLICATION; }
7295 : 460 : | SCHEMA { $$ = OBJECT_SCHEMA; }
7296 : 109 : | SERVER { $$ = OBJECT_FOREIGN_SERVER; }
7297 : : ;
7298 : :
7299 : : /* object types attached to a table */
7300 : : object_type_name_on_any_name:
7301 : 158 : POLICY { $$ = OBJECT_POLICY; }
7302 : 205 : | RULE { $$ = OBJECT_RULE; }
7303 : 527 : | TRIGGER { $$ = OBJECT_TRIGGER; }
7304 : : ;
7305 : :
7306 : : any_name_list:
7307 : 17507 : any_name { $$ = list_make1($1); }
7308 : 2589 : | any_name_list ',' any_name { $$ = lappend($1, $3); }
7309 : : ;
7310 : :
7311 : 43410 : any_name: ColId { $$ = list_make1(makeString($1)); }
7312 : 6231 : | ColId attrs { $$ = lcons(makeString($1), $2); }
7313 : : ;
7314 : :
7315 : : attrs: '.' attr_name
7316 : 76310 : { $$ = list_make1(makeString($2)); }
7317 : : | attrs '.' attr_name
7318 : 36 : { $$ = lappend($1, makeString($3)); }
7319 : : ;
7320 : :
7321 : : type_name_list:
7322 : 854 : Typename { $$ = list_make1($1); }
7323 : 84 : | type_name_list ',' Typename { $$ = lappend($1, $3); }
7324 : : ;
7325 : :
7326 : : /*****************************************************************************
7327 : : *
7328 : : * QUERY:
7329 : : * truncate table relname1, relname2, ...
7330 : : *
7331 : : *****************************************************************************/
7332 : :
7333 : : TruncateStmt:
7334 : : TRUNCATE opt_table relation_expr_list opt_restart_seqs opt_drop_behavior
7335 : : {
7336 : 1191 : TruncateStmt *n = makeNode(TruncateStmt);
7337 : :
7338 : 1191 : n->relations = $3;
7339 : 1191 : n->restart_seqs = $4;
7340 : 1191 : n->behavior = $5;
7341 : 1191 : $$ = (Node *) n;
7342 : : }
7343 : : ;
7344 : :
7345 : : opt_restart_seqs:
7346 : 12 : CONTINUE_P IDENTITY_P { $$ = false; }
7347 : 15 : | RESTART IDENTITY_P { $$ = true; }
7348 : 1164 : | /* EMPTY */ { $$ = false; }
7349 : : ;
7350 : :
7351 : : /*****************************************************************************
7352 : : *
7353 : : * COMMENT ON <object> IS <text>
7354 : : *
7355 : : *****************************************************************************/
7356 : :
7357 : : CommentStmt:
7358 : : COMMENT ON object_type_any_name any_name IS comment_text
7359 : : {
7360 : 3632 : CommentStmt *n = makeNode(CommentStmt);
7361 : :
7362 : 3632 : n->objtype = $3;
7363 : 3632 : n->object = (Node *) $4;
7364 : 3632 : n->comment = $6;
7365 : 3632 : $$ = (Node *) n;
7366 : : }
7367 : : | COMMENT ON COLUMN any_name IS comment_text
7368 : : {
7369 : 94 : CommentStmt *n = makeNode(CommentStmt);
7370 : :
7371 : 94 : n->objtype = OBJECT_COLUMN;
7372 : 94 : n->object = (Node *) $4;
7373 : 94 : n->comment = $6;
7374 : 94 : $$ = (Node *) n;
7375 : : }
7376 : : | COMMENT ON object_type_name name IS comment_text
7377 : : {
7378 : 295 : CommentStmt *n = makeNode(CommentStmt);
7379 : :
7380 : 295 : n->objtype = $3;
7381 : 295 : n->object = (Node *) makeString($4);
7382 : 295 : n->comment = $6;
7383 : 295 : $$ = (Node *) n;
7384 : : }
7385 : : | COMMENT ON TYPE_P Typename IS comment_text
7386 : : {
7387 : 31 : CommentStmt *n = makeNode(CommentStmt);
7388 : :
7389 : 31 : n->objtype = OBJECT_TYPE;
7390 : 31 : n->object = (Node *) $4;
7391 : 31 : n->comment = $6;
7392 : 31 : $$ = (Node *) n;
7393 : : }
7394 : : | COMMENT ON DOMAIN_P Typename IS comment_text
7395 : : {
7396 : 5 : CommentStmt *n = makeNode(CommentStmt);
7397 : :
7398 : 5 : n->objtype = OBJECT_DOMAIN;
7399 : 5 : n->object = (Node *) $4;
7400 : 5 : n->comment = $6;
7401 : 5 : $$ = (Node *) n;
7402 : : }
7403 : : | COMMENT ON AGGREGATE aggregate_with_argtypes IS comment_text
7404 : : {
7405 : 26 : CommentStmt *n = makeNode(CommentStmt);
7406 : :
7407 : 26 : n->objtype = OBJECT_AGGREGATE;
7408 : 26 : n->object = (Node *) $4;
7409 : 26 : n->comment = $6;
7410 : 26 : $$ = (Node *) n;
7411 : : }
7412 : : | COMMENT ON FUNCTION function_with_argtypes IS comment_text
7413 : : {
7414 : 91 : CommentStmt *n = makeNode(CommentStmt);
7415 : :
7416 : 91 : n->objtype = OBJECT_FUNCTION;
7417 : 91 : n->object = (Node *) $4;
7418 : 91 : n->comment = $6;
7419 : 91 : $$ = (Node *) n;
7420 : : }
7421 : : | COMMENT ON OPERATOR operator_with_argtypes IS comment_text
7422 : : {
7423 : 12 : CommentStmt *n = makeNode(CommentStmt);
7424 : :
7425 : 12 : n->objtype = OBJECT_OPERATOR;
7426 : 12 : n->object = (Node *) $4;
7427 : 12 : n->comment = $6;
7428 : 12 : $$ = (Node *) n;
7429 : : }
7430 : : | COMMENT ON CONSTRAINT name ON any_name IS comment_text
7431 : : {
7432 : 97 : CommentStmt *n = makeNode(CommentStmt);
7433 : :
7434 : 97 : n->objtype = OBJECT_TABCONSTRAINT;
7435 : 97 : n->object = (Node *) lappend($6, makeString($4));
7436 : 97 : n->comment = $8;
7437 : 97 : $$ = (Node *) n;
7438 : : }
7439 : : | COMMENT ON CONSTRAINT name ON DOMAIN_P any_name IS comment_text
7440 : : {
7441 : 31 : CommentStmt *n = makeNode(CommentStmt);
7442 : :
7443 : 31 : n->objtype = OBJECT_DOMCONSTRAINT;
7444 : : /*
7445 : : * should use Typename not any_name in the production, but
7446 : : * there's a shift/reduce conflict if we do that, so fix it
7447 : : * up here.
7448 : : */
7449 : 31 : n->object = (Node *) list_make2(makeTypeNameFromNameList($7), makeString($4));
7450 : 31 : n->comment = $9;
7451 : 31 : $$ = (Node *) n;
7452 : : }
7453 : : | COMMENT ON object_type_name_on_any_name name ON any_name IS comment_text
7454 : : {
7455 : 27 : CommentStmt *n = makeNode(CommentStmt);
7456 : :
7457 : 27 : n->objtype = $3;
7458 : 27 : n->object = (Node *) lappend($6, makeString($4));
7459 : 27 : n->comment = $8;
7460 : 27 : $$ = (Node *) n;
7461 : : }
7462 : : | COMMENT ON PROCEDURE function_with_argtypes IS comment_text
7463 : : {
7464 : 0 : CommentStmt *n = makeNode(CommentStmt);
7465 : :
7466 : 0 : n->objtype = OBJECT_PROCEDURE;
7467 : 0 : n->object = (Node *) $4;
7468 : 0 : n->comment = $6;
7469 : 0 : $$ = (Node *) n;
7470 : : }
7471 : : | COMMENT ON ROUTINE function_with_argtypes IS comment_text
7472 : : {
7473 : 0 : CommentStmt *n = makeNode(CommentStmt);
7474 : :
7475 : 0 : n->objtype = OBJECT_ROUTINE;
7476 : 0 : n->object = (Node *) $4;
7477 : 0 : n->comment = $6;
7478 : 0 : $$ = (Node *) n;
7479 : : }
7480 : : | COMMENT ON TRANSFORM FOR Typename LANGUAGE name IS comment_text
7481 : : {
7482 : 7 : CommentStmt *n = makeNode(CommentStmt);
7483 : :
7484 : 7 : n->objtype = OBJECT_TRANSFORM;
7485 : 7 : n->object = (Node *) list_make2($5, makeString($7));
7486 : 7 : n->comment = $9;
7487 : 7 : $$ = (Node *) n;
7488 : : }
7489 : : | COMMENT ON OPERATOR CLASS any_name USING name IS comment_text
7490 : : {
7491 : 0 : CommentStmt *n = makeNode(CommentStmt);
7492 : :
7493 : 0 : n->objtype = OBJECT_OPCLASS;
7494 : 0 : n->object = (Node *) lcons(makeString($7), $5);
7495 : 0 : n->comment = $9;
7496 : 0 : $$ = (Node *) n;
7497 : : }
7498 : : | COMMENT ON OPERATOR FAMILY any_name USING name IS comment_text
7499 : : {
7500 : 0 : CommentStmt *n = makeNode(CommentStmt);
7501 : :
7502 : 0 : n->objtype = OBJECT_OPFAMILY;
7503 : 0 : n->object = (Node *) lcons(makeString($7), $5);
7504 : 0 : n->comment = $9;
7505 : 0 : $$ = (Node *) n;
7506 : : }
7507 : : | COMMENT ON LARGE_P OBJECT_P NumericOnly IS comment_text
7508 : : {
7509 : 24 : CommentStmt *n = makeNode(CommentStmt);
7510 : :
7511 : 24 : n->objtype = OBJECT_LARGEOBJECT;
7512 : 24 : n->object = (Node *) $5;
7513 : 24 : n->comment = $7;
7514 : 24 : $$ = (Node *) n;
7515 : : }
7516 : : | COMMENT ON CAST '(' Typename AS Typename ')' IS comment_text
7517 : : {
7518 : 0 : CommentStmt *n = makeNode(CommentStmt);
7519 : :
7520 : 0 : n->objtype = OBJECT_CAST;
7521 : 0 : n->object = (Node *) list_make2($5, $7);
7522 : 0 : n->comment = $10;
7523 : 0 : $$ = (Node *) n;
7524 : : }
7525 : : ;
7526 : :
7527 : : comment_text:
7528 : 4299 : Sconst { $$ = $1; }
7529 : 73 : | NULL_P { $$ = NULL; }
7530 : : ;
7531 : :
7532 : :
7533 : : /*****************************************************************************
7534 : : *
7535 : : * SECURITY LABEL [FOR <provider>] ON <object> IS <label>
7536 : : *
7537 : : * As with COMMENT ON, <object> can refer to various types of database
7538 : : * objects (e.g. TABLE, COLUMN, etc.).
7539 : : *
7540 : : *****************************************************************************/
7541 : :
7542 : : SecLabelStmt:
7543 : : SECURITY LABEL opt_provider ON object_type_any_name any_name
7544 : : IS security_label
7545 : : {
7546 : 28 : SecLabelStmt *n = makeNode(SecLabelStmt);
7547 : :
7548 : 28 : n->provider = $3;
7549 : 28 : n->objtype = $5;
7550 : 28 : n->object = (Node *) $6;
7551 : 28 : n->label = $8;
7552 : 28 : $$ = (Node *) n;
7553 : : }
7554 : : | SECURITY LABEL opt_provider ON COLUMN any_name
7555 : : IS security_label
7556 : : {
7557 : 2 : SecLabelStmt *n = makeNode(SecLabelStmt);
7558 : :
7559 : 2 : n->provider = $3;
7560 : 2 : n->objtype = OBJECT_COLUMN;
7561 : 2 : n->object = (Node *) $6;
7562 : 2 : n->label = $8;
7563 : 2 : $$ = (Node *) n;
7564 : : }
7565 : : | SECURITY LABEL opt_provider ON object_type_name name
7566 : : IS security_label
7567 : : {
7568 : 26 : SecLabelStmt *n = makeNode(SecLabelStmt);
7569 : :
7570 : 26 : n->provider = $3;
7571 : 26 : n->objtype = $5;
7572 : 26 : n->object = (Node *) makeString($6);
7573 : 26 : n->label = $8;
7574 : 26 : $$ = (Node *) n;
7575 : : }
7576 : : | SECURITY LABEL opt_provider ON TYPE_P Typename
7577 : : IS security_label
7578 : : {
7579 : 0 : SecLabelStmt *n = makeNode(SecLabelStmt);
7580 : :
7581 : 0 : n->provider = $3;
7582 : 0 : n->objtype = OBJECT_TYPE;
7583 : 0 : n->object = (Node *) $6;
7584 : 0 : n->label = $8;
7585 : 0 : $$ = (Node *) n;
7586 : : }
7587 : : | SECURITY LABEL opt_provider ON DOMAIN_P Typename
7588 : : IS security_label
7589 : : {
7590 : 1 : SecLabelStmt *n = makeNode(SecLabelStmt);
7591 : :
7592 : 1 : n->provider = $3;
7593 : 1 : n->objtype = OBJECT_DOMAIN;
7594 : 1 : n->object = (Node *) $6;
7595 : 1 : n->label = $8;
7596 : 1 : $$ = (Node *) n;
7597 : : }
7598 : : | SECURITY LABEL opt_provider ON AGGREGATE aggregate_with_argtypes
7599 : : IS security_label
7600 : : {
7601 : 0 : SecLabelStmt *n = makeNode(SecLabelStmt);
7602 : :
7603 : 0 : n->provider = $3;
7604 : 0 : n->objtype = OBJECT_AGGREGATE;
7605 : 0 : n->object = (Node *) $6;
7606 : 0 : n->label = $8;
7607 : 0 : $$ = (Node *) n;
7608 : : }
7609 : : | SECURITY LABEL opt_provider ON FUNCTION function_with_argtypes
7610 : : IS security_label
7611 : : {
7612 : 1 : SecLabelStmt *n = makeNode(SecLabelStmt);
7613 : :
7614 : 1 : n->provider = $3;
7615 : 1 : n->objtype = OBJECT_FUNCTION;
7616 : 1 : n->object = (Node *) $6;
7617 : 1 : n->label = $8;
7618 : 1 : $$ = (Node *) n;
7619 : : }
7620 : : | SECURITY LABEL opt_provider ON LARGE_P OBJECT_P NumericOnly
7621 : : IS security_label
7622 : : {
7623 : 9 : SecLabelStmt *n = makeNode(SecLabelStmt);
7624 : :
7625 : 9 : n->provider = $3;
7626 : 9 : n->objtype = OBJECT_LARGEOBJECT;
7627 : 9 : n->object = (Node *) $7;
7628 : 9 : n->label = $9;
7629 : 9 : $$ = (Node *) n;
7630 : : }
7631 : : | SECURITY LABEL opt_provider ON PROCEDURE function_with_argtypes
7632 : : IS security_label
7633 : : {
7634 : 0 : SecLabelStmt *n = makeNode(SecLabelStmt);
7635 : :
7636 : 0 : n->provider = $3;
7637 : 0 : n->objtype = OBJECT_PROCEDURE;
7638 : 0 : n->object = (Node *) $6;
7639 : 0 : n->label = $8;
7640 : 0 : $$ = (Node *) n;
7641 : : }
7642 : : | SECURITY LABEL opt_provider ON ROUTINE function_with_argtypes
7643 : : IS security_label
7644 : : {
7645 : 0 : SecLabelStmt *n = makeNode(SecLabelStmt);
7646 : :
7647 : 0 : n->provider = $3;
7648 : 0 : n->objtype = OBJECT_ROUTINE;
7649 : 0 : n->object = (Node *) $6;
7650 : 0 : n->label = $8;
7651 : 0 : $$ = (Node *) n;
7652 : : }
7653 : : ;
7654 : :
7655 : 16 : opt_provider: FOR NonReservedWord_or_Sconst { $$ = $2; }
7656 : 51 : | /* EMPTY */ { $$ = NULL; }
7657 : : ;
7658 : :
7659 : 67 : security_label: Sconst { $$ = $1; }
7660 : 0 : | NULL_P { $$ = NULL; }
7661 : : ;
7662 : :
7663 : : /*****************************************************************************
7664 : : *
7665 : : * QUERY:
7666 : : * fetch/move
7667 : : *
7668 : : *****************************************************************************/
7669 : :
7670 : : FetchStmt: FETCH fetch_args
7671 : : {
7672 : 4406 : FetchStmt *n = (FetchStmt *) $2;
7673 : :
7674 : 4406 : n->ismove = false;
7675 : 4406 : $$ = (Node *) n;
7676 : : }
7677 : : | MOVE fetch_args
7678 : : {
7679 : 42 : FetchStmt *n = (FetchStmt *) $2;
7680 : :
7681 : 42 : n->ismove = true;
7682 : 42 : $$ = (Node *) n;
7683 : : }
7684 : : ;
7685 : :
7686 : : fetch_args: cursor_name
7687 : : {
7688 : 150 : FetchStmt *n = makeNode(FetchStmt);
7689 : :
7690 : 150 : n->portalname = $1;
7691 : 150 : n->direction = FETCH_FORWARD;
7692 : 150 : n->howMany = 1;
7693 : 150 : n->location = -1;
7694 : 150 : n->direction_keyword = FETCH_KEYWORD_NONE;
7695 : 150 : $$ = (Node *) n;
7696 : : }
7697 : : | from_in cursor_name
7698 : : {
7699 : 128 : FetchStmt *n = makeNode(FetchStmt);
7700 : :
7701 : 128 : n->portalname = $2;
7702 : 128 : n->direction = FETCH_FORWARD;
7703 : 128 : n->howMany = 1;
7704 : 128 : n->location = -1;
7705 : 128 : n->direction_keyword = FETCH_KEYWORD_NONE;
7706 : 128 : $$ = (Node *) n;
7707 : : }
7708 : : | SignedIconst opt_from_in cursor_name
7709 : : {
7710 : 2227 : FetchStmt *n = makeNode(FetchStmt);
7711 : :
7712 : 2227 : n->portalname = $3;
7713 : 2227 : n->direction = FETCH_FORWARD;
7714 : 2227 : n->howMany = $1;
7715 : 2227 : n->location = @1;
7716 : 2227 : n->direction_keyword = FETCH_KEYWORD_NONE;
7717 : 2227 : $$ = (Node *) n;
7718 : : }
7719 : : | NEXT opt_from_in cursor_name
7720 : : {
7721 : 1340 : FetchStmt *n = makeNode(FetchStmt);
7722 : :
7723 : 1340 : n->portalname = $3;
7724 : 1340 : n->direction = FETCH_FORWARD;
7725 : 1340 : n->howMany = 1;
7726 : 1340 : n->location = -1;
7727 : 1340 : n->direction_keyword = FETCH_KEYWORD_NEXT;
7728 : 1340 : $$ = (Node *) n;
7729 : : }
7730 : : | PRIOR opt_from_in cursor_name
7731 : : {
7732 : 21 : FetchStmt *n = makeNode(FetchStmt);
7733 : :
7734 : 21 : n->portalname = $3;
7735 : 21 : n->direction = FETCH_BACKWARD;
7736 : 21 : n->howMany = 1;
7737 : 21 : n->location = -1;
7738 : 21 : n->direction_keyword = FETCH_KEYWORD_PRIOR;
7739 : 21 : $$ = (Node *) n;
7740 : : }
7741 : : | FIRST_P opt_from_in cursor_name
7742 : : {
7743 : 17 : FetchStmt *n = makeNode(FetchStmt);
7744 : :
7745 : 17 : n->portalname = $3;
7746 : 17 : n->direction = FETCH_ABSOLUTE;
7747 : 17 : n->howMany = 1;
7748 : 17 : n->location = -1;
7749 : 17 : n->direction_keyword = FETCH_KEYWORD_FIRST;
7750 : 17 : $$ = (Node *) n;
7751 : : }
7752 : : | LAST_P opt_from_in cursor_name
7753 : : {
7754 : 13 : FetchStmt *n = makeNode(FetchStmt);
7755 : :
7756 : 13 : n->portalname = $3;
7757 : 13 : n->direction = FETCH_ABSOLUTE;
7758 : 13 : n->howMany = -1;
7759 : 13 : n->location = -1;
7760 : 13 : n->direction_keyword = FETCH_KEYWORD_LAST;
7761 : 13 : $$ = (Node *) n;
7762 : : }
7763 : : | ABSOLUTE_P SignedIconst opt_from_in cursor_name
7764 : : {
7765 : 59 : FetchStmt *n = makeNode(FetchStmt);
7766 : :
7767 : 59 : n->portalname = $4;
7768 : 59 : n->direction = FETCH_ABSOLUTE;
7769 : 59 : n->howMany = $2;
7770 : 59 : n->location = @2;
7771 : 59 : n->direction_keyword = FETCH_KEYWORD_ABSOLUTE;
7772 : 59 : $$ = (Node *) n;
7773 : : }
7774 : : | RELATIVE_P SignedIconst opt_from_in cursor_name
7775 : : {
7776 : 23 : FetchStmt *n = makeNode(FetchStmt);
7777 : :
7778 : 23 : n->portalname = $4;
7779 : 23 : n->direction = FETCH_RELATIVE;
7780 : 23 : n->howMany = $2;
7781 : 23 : n->location = @2;
7782 : 23 : n->direction_keyword = FETCH_KEYWORD_RELATIVE;
7783 : 23 : $$ = (Node *) n;
7784 : : }
7785 : : | ALL opt_from_in cursor_name
7786 : : {
7787 : 176 : FetchStmt *n = makeNode(FetchStmt);
7788 : :
7789 : 176 : n->portalname = $3;
7790 : 176 : n->direction = FETCH_FORWARD;
7791 : 176 : n->howMany = FETCH_ALL;
7792 : 176 : n->location = -1;
7793 : 176 : n->direction_keyword = FETCH_KEYWORD_ALL;
7794 : 176 : $$ = (Node *) n;
7795 : : }
7796 : : | FORWARD opt_from_in cursor_name
7797 : : {
7798 : 15 : FetchStmt *n = makeNode(FetchStmt);
7799 : :
7800 : 15 : n->portalname = $3;
7801 : 15 : n->direction = FETCH_FORWARD;
7802 : 15 : n->howMany = 1;
7803 : 15 : n->location = -1;
7804 : 15 : n->direction_keyword = FETCH_KEYWORD_FORWARD;
7805 : 15 : $$ = (Node *) n;
7806 : : }
7807 : : | FORWARD SignedIconst opt_from_in cursor_name
7808 : : {
7809 : 6 : FetchStmt *n = makeNode(FetchStmt);
7810 : :
7811 : 6 : n->portalname = $4;
7812 : 6 : n->direction = FETCH_FORWARD;
7813 : 6 : n->howMany = $2;
7814 : 6 : n->location = @2;
7815 : 6 : n->direction_keyword = FETCH_KEYWORD_FORWARD;
7816 : 6 : $$ = (Node *) n;
7817 : : }
7818 : : | FORWARD ALL opt_from_in cursor_name
7819 : : {
7820 : 10 : FetchStmt *n = makeNode(FetchStmt);
7821 : :
7822 : 10 : n->portalname = $4;
7823 : 10 : n->direction = FETCH_FORWARD;
7824 : 10 : n->howMany = FETCH_ALL;
7825 : 10 : n->location = -1;
7826 : 10 : n->direction_keyword = FETCH_KEYWORD_FORWARD_ALL;
7827 : 10 : $$ = (Node *) n;
7828 : : }
7829 : : | BACKWARD opt_from_in cursor_name
7830 : : {
7831 : 53 : FetchStmt *n = makeNode(FetchStmt);
7832 : :
7833 : 53 : n->portalname = $3;
7834 : 53 : n->direction = FETCH_BACKWARD;
7835 : 53 : n->howMany = 1;
7836 : 53 : n->location = -1;
7837 : 53 : n->direction_keyword = FETCH_KEYWORD_BACKWARD;
7838 : 53 : $$ = (Node *) n;
7839 : : }
7840 : : | BACKWARD SignedIconst opt_from_in cursor_name
7841 : : {
7842 : 149 : FetchStmt *n = makeNode(FetchStmt);
7843 : :
7844 : 149 : n->portalname = $4;
7845 : 149 : n->direction = FETCH_BACKWARD;
7846 : 149 : n->howMany = $2;
7847 : 149 : n->location = @2;
7848 : 149 : n->direction_keyword = FETCH_KEYWORD_BACKWARD;
7849 : 149 : $$ = (Node *) n;
7850 : : }
7851 : : | BACKWARD ALL opt_from_in cursor_name
7852 : : {
7853 : 61 : FetchStmt *n = makeNode(FetchStmt);
7854 : :
7855 : 61 : n->portalname = $4;
7856 : 61 : n->direction = FETCH_BACKWARD;
7857 : 61 : n->howMany = FETCH_ALL;
7858 : 61 : n->location = -1;
7859 : 61 : n->direction_keyword = FETCH_KEYWORD_BACKWARD_ALL;
7860 : 61 : $$ = (Node *) n;
7861 : : }
7862 : : ;
7863 : :
7864 : : from_in: FROM
7865 : : | IN_P
7866 : : ;
7867 : :
7868 : : opt_from_in: from_in
7869 : : | /* EMPTY */
7870 : : ;
7871 : :
7872 : :
7873 : : /*****************************************************************************
7874 : : *
7875 : : * GRANT and REVOKE statements
7876 : : *
7877 : : *****************************************************************************/
7878 : :
7879 : : GrantStmt: GRANT privileges ON privilege_target TO grantee_list
7880 : : opt_grant_grant_option opt_granted_by
7881 : : {
7882 : 6798 : GrantStmt *n = makeNode(GrantStmt);
7883 : :
7884 : 6798 : n->is_grant = true;
7885 : 6798 : n->privileges = $2;
7886 : 6798 : n->targtype = ($4)->targtype;
7887 : 6798 : n->objtype = ($4)->objtype;
7888 : 6798 : n->objects = ($4)->objs;
7889 : 6798 : n->grantees = $6;
7890 : 6798 : n->grant_option = $7;
7891 : 6798 : n->grantor = $8;
7892 : 6798 : $$ = (Node *) n;
7893 : : }
7894 : : ;
7895 : :
7896 : : RevokeStmt:
7897 : : REVOKE privileges ON privilege_target
7898 : : FROM grantee_list opt_granted_by opt_drop_behavior
7899 : : {
7900 : 2366 : GrantStmt *n = makeNode(GrantStmt);
7901 : :
7902 : 2366 : n->is_grant = false;
7903 : 2366 : n->grant_option = false;
7904 : 2366 : n->privileges = $2;
7905 : 2366 : n->targtype = ($4)->targtype;
7906 : 2366 : n->objtype = ($4)->objtype;
7907 : 2366 : n->objects = ($4)->objs;
7908 : 2366 : n->grantees = $6;
7909 : 2366 : n->grantor = $7;
7910 : 2366 : n->behavior = $8;
7911 : 2366 : $$ = (Node *) n;
7912 : : }
7913 : : | REVOKE GRANT OPTION FOR privileges ON privilege_target
7914 : : FROM grantee_list opt_granted_by opt_drop_behavior
7915 : : {
7916 : 9 : GrantStmt *n = makeNode(GrantStmt);
7917 : :
7918 : 9 : n->is_grant = false;
7919 : 9 : n->grant_option = true;
7920 : 9 : n->privileges = $5;
7921 : 9 : n->targtype = ($7)->targtype;
7922 : 9 : n->objtype = ($7)->objtype;
7923 : 9 : n->objects = ($7)->objs;
7924 : 9 : n->grantees = $9;
7925 : 9 : n->grantor = $10;
7926 : 9 : n->behavior = $11;
7927 : 9 : $$ = (Node *) n;
7928 : : }
7929 : : ;
7930 : :
7931 : :
7932 : : /*
7933 : : * Privilege names are represented as strings; the validity of the privilege
7934 : : * names gets checked at execution. This is a bit annoying but we have little
7935 : : * choice because of the syntactic conflict with lists of role names in
7936 : : * GRANT/REVOKE. What's more, we have to call out in the "privilege"
7937 : : * production any reserved keywords that need to be usable as privilege names.
7938 : : */
7939 : :
7940 : : /* either ALL [PRIVILEGES] or a list of individual privileges */
7941 : : privileges: privilege_list
7942 : 7572 : { $$ = $1; }
7943 : : | ALL
7944 : 1662 : { $$ = NIL; }
7945 : : | ALL PRIVILEGES
7946 : 68 : { $$ = NIL; }
7947 : : | ALL '(' columnList ')'
7948 : : {
7949 : 12 : AccessPriv *n = makeNode(AccessPriv);
7950 : :
7951 : 12 : n->priv_name = NULL;
7952 : 12 : n->cols = $3;
7953 : 12 : $$ = list_make1(n);
7954 : : }
7955 : : | ALL PRIVILEGES '(' columnList ')'
7956 : : {
7957 : 0 : AccessPriv *n = makeNode(AccessPriv);
7958 : :
7959 : 0 : n->priv_name = NULL;
7960 : 0 : n->cols = $4;
7961 : 0 : $$ = list_make1(n);
7962 : : }
7963 : : ;
7964 : :
7965 : 8001 : privilege_list: privilege { $$ = list_make1($1); }
7966 : 398 : | privilege_list ',' privilege { $$ = lappend($1, $3); }
7967 : : ;
7968 : :
7969 : : privilege: SELECT opt_column_list
7970 : : {
7971 : 6117 : AccessPriv *n = makeNode(AccessPriv);
7972 : :
7973 : 6117 : n->priv_name = pstrdup($1);
7974 : 6117 : n->cols = $2;
7975 : 6117 : $$ = n;
7976 : : }
7977 : : | REFERENCES opt_column_list
7978 : : {
7979 : 9 : AccessPriv *n = makeNode(AccessPriv);
7980 : :
7981 : 9 : n->priv_name = pstrdup($1);
7982 : 9 : n->cols = $2;
7983 : 9 : $$ = n;
7984 : : }
7985 : : | CREATE opt_column_list
7986 : : {
7987 : 205 : AccessPriv *n = makeNode(AccessPriv);
7988 : :
7989 : 205 : n->priv_name = pstrdup($1);
7990 : 205 : n->cols = $2;
7991 : 205 : $$ = n;
7992 : : }
7993 : : | ALTER SYSTEM_P
7994 : : {
7995 : 12 : AccessPriv *n = makeNode(AccessPriv);
7996 : 12 : n->priv_name = pstrdup("alter system");
7997 : 12 : n->cols = NIL;
7998 : 12 : $$ = n;
7999 : : }
8000 : : | ColId opt_column_list
8001 : : {
8002 : 2056 : AccessPriv *n = makeNode(AccessPriv);
8003 : :
8004 : 2056 : n->priv_name = $1;
8005 : 2056 : n->cols = $2;
8006 : 2056 : $$ = n;
8007 : : }
8008 : : ;
8009 : :
8010 : : parameter_name_list:
8011 : : parameter_name
8012 : : {
8013 : 37 : $$ = list_make1(makeString($1));
8014 : : }
8015 : : | parameter_name_list ',' parameter_name
8016 : : {
8017 : 25 : $$ = lappend($1, makeString($3));
8018 : : }
8019 : : ;
8020 : :
8021 : : parameter_name:
8022 : : ColId
8023 : : {
8024 : 62 : $$ = $1;
8025 : : }
8026 : : | parameter_name '.' ColId
8027 : : {
8028 : 15 : $$ = psprintf("%s.%s", $1, $3);
8029 : : }
8030 : : ;
8031 : :
8032 : :
8033 : : /* Don't bother trying to fold the first two rules into one using
8034 : : * opt_table. You're going to get conflicts.
8035 : : */
8036 : : privilege_target:
8037 : : qualified_name_list
8038 : : {
8039 : 7383 : PrivTarget *n = palloc_object(PrivTarget);
8040 : :
8041 : 7383 : n->targtype = ACL_TARGET_OBJECT;
8042 : 7383 : n->objtype = OBJECT_TABLE;
8043 : 7383 : n->objs = $1;
8044 : 7383 : $$ = n;
8045 : : }
8046 : : | TABLE qualified_name_list
8047 : : {
8048 : 233 : PrivTarget *n = palloc_object(PrivTarget);
8049 : :
8050 : 233 : n->targtype = ACL_TARGET_OBJECT;
8051 : 233 : n->objtype = OBJECT_TABLE;
8052 : 233 : n->objs = $2;
8053 : 233 : $$ = n;
8054 : : }
8055 : : | SEQUENCE qualified_name_list
8056 : : {
8057 : 12 : PrivTarget *n = palloc_object(PrivTarget);
8058 : :
8059 : 12 : n->targtype = ACL_TARGET_OBJECT;
8060 : 12 : n->objtype = OBJECT_SEQUENCE;
8061 : 12 : n->objs = $2;
8062 : 12 : $$ = n;
8063 : : }
8064 : : | FOREIGN DATA_P WRAPPER name_list
8065 : : {
8066 : 60 : PrivTarget *n = palloc_object(PrivTarget);
8067 : :
8068 : 60 : n->targtype = ACL_TARGET_OBJECT;
8069 : 60 : n->objtype = OBJECT_FDW;
8070 : 60 : n->objs = $4;
8071 : 60 : $$ = n;
8072 : : }
8073 : : | FOREIGN SERVER name_list
8074 : : {
8075 : 78 : PrivTarget *n = palloc_object(PrivTarget);
8076 : :
8077 : 78 : n->targtype = ACL_TARGET_OBJECT;
8078 : 78 : n->objtype = OBJECT_FOREIGN_SERVER;
8079 : 78 : n->objs = $3;
8080 : 78 : $$ = n;
8081 : : }
8082 : : | FUNCTION function_with_argtypes_list
8083 : : {
8084 : 550 : PrivTarget *n = palloc_object(PrivTarget);
8085 : :
8086 : 550 : n->targtype = ACL_TARGET_OBJECT;
8087 : 550 : n->objtype = OBJECT_FUNCTION;
8088 : 550 : n->objs = $2;
8089 : 550 : $$ = n;
8090 : : }
8091 : : | PROCEDURE function_with_argtypes_list
8092 : : {
8093 : 28 : PrivTarget *n = palloc_object(PrivTarget);
8094 : :
8095 : 28 : n->targtype = ACL_TARGET_OBJECT;
8096 : 28 : n->objtype = OBJECT_PROCEDURE;
8097 : 28 : n->objs = $2;
8098 : 28 : $$ = n;
8099 : : }
8100 : : | ROUTINE function_with_argtypes_list
8101 : : {
8102 : 0 : PrivTarget *n = palloc_object(PrivTarget);
8103 : :
8104 : 0 : n->targtype = ACL_TARGET_OBJECT;
8105 : 0 : n->objtype = OBJECT_ROUTINE;
8106 : 0 : n->objs = $2;
8107 : 0 : $$ = n;
8108 : : }
8109 : : | DATABASE name_list
8110 : : {
8111 : 214 : PrivTarget *n = palloc_object(PrivTarget);
8112 : :
8113 : 214 : n->targtype = ACL_TARGET_OBJECT;
8114 : 214 : n->objtype = OBJECT_DATABASE;
8115 : 214 : n->objs = $2;
8116 : 214 : $$ = n;
8117 : : }
8118 : : | DOMAIN_P any_name_list
8119 : : {
8120 : 17 : PrivTarget *n = palloc_object(PrivTarget);
8121 : :
8122 : 17 : n->targtype = ACL_TARGET_OBJECT;
8123 : 17 : n->objtype = OBJECT_DOMAIN;
8124 : 17 : n->objs = $2;
8125 : 17 : $$ = n;
8126 : : }
8127 : : | LANGUAGE name_list
8128 : : {
8129 : 27 : PrivTarget *n = palloc_object(PrivTarget);
8130 : :
8131 : 27 : n->targtype = ACL_TARGET_OBJECT;
8132 : 27 : n->objtype = OBJECT_LANGUAGE;
8133 : 27 : n->objs = $2;
8134 : 27 : $$ = n;
8135 : : }
8136 : : | LARGE_P OBJECT_P NumericOnly_list
8137 : : {
8138 : 62 : PrivTarget *n = palloc_object(PrivTarget);
8139 : :
8140 : 62 : n->targtype = ACL_TARGET_OBJECT;
8141 : 62 : n->objtype = OBJECT_LARGEOBJECT;
8142 : 62 : n->objs = $3;
8143 : 62 : $$ = n;
8144 : : }
8145 : : | PARAMETER parameter_name_list
8146 : : {
8147 : 37 : PrivTarget *n = palloc_object(PrivTarget);
8148 : 37 : n->targtype = ACL_TARGET_OBJECT;
8149 : 37 : n->objtype = OBJECT_PARAMETER_ACL;
8150 : 37 : n->objs = $2;
8151 : 37 : $$ = n;
8152 : : }
8153 : : | PROPERTY GRAPH qualified_name_list
8154 : : {
8155 : 10 : PrivTarget *n = palloc_object(PrivTarget);
8156 : :
8157 : 10 : n->targtype = ACL_TARGET_OBJECT;
8158 : 10 : n->objtype = OBJECT_PROPGRAPH;
8159 : 10 : n->objs = $3;
8160 : 10 : $$ = n;
8161 : : }
8162 : : | SCHEMA name_list
8163 : : {
8164 : 368 : PrivTarget *n = palloc_object(PrivTarget);
8165 : :
8166 : 368 : n->targtype = ACL_TARGET_OBJECT;
8167 : 368 : n->objtype = OBJECT_SCHEMA;
8168 : 368 : n->objs = $2;
8169 : 368 : $$ = n;
8170 : : }
8171 : : | TABLESPACE name_list
8172 : : {
8173 : 3 : PrivTarget *n = palloc_object(PrivTarget);
8174 : :
8175 : 3 : n->targtype = ACL_TARGET_OBJECT;
8176 : 3 : n->objtype = OBJECT_TABLESPACE;
8177 : 3 : n->objs = $2;
8178 : 3 : $$ = n;
8179 : : }
8180 : : | TYPE_P any_name_list
8181 : : {
8182 : 76 : PrivTarget *n = palloc_object(PrivTarget);
8183 : :
8184 : 76 : n->targtype = ACL_TARGET_OBJECT;
8185 : 76 : n->objtype = OBJECT_TYPE;
8186 : 76 : n->objs = $2;
8187 : 76 : $$ = n;
8188 : : }
8189 : : | ALL TABLES IN_P SCHEMA name_list
8190 : : {
8191 : 8 : PrivTarget *n = palloc_object(PrivTarget);
8192 : :
8193 : 8 : n->targtype = ACL_TARGET_ALL_IN_SCHEMA;
8194 : 8 : n->objtype = OBJECT_TABLE;
8195 : 8 : n->objs = $5;
8196 : 8 : $$ = n;
8197 : : }
8198 : : | ALL SEQUENCES IN_P SCHEMA name_list
8199 : : {
8200 : 1 : PrivTarget *n = palloc_object(PrivTarget);
8201 : :
8202 : 1 : n->targtype = ACL_TARGET_ALL_IN_SCHEMA;
8203 : 1 : n->objtype = OBJECT_SEQUENCE;
8204 : 1 : n->objs = $5;
8205 : 1 : $$ = n;
8206 : : }
8207 : : | ALL FUNCTIONS IN_P SCHEMA name_list
8208 : : {
8209 : 4 : PrivTarget *n = palloc_object(PrivTarget);
8210 : :
8211 : 4 : n->targtype = ACL_TARGET_ALL_IN_SCHEMA;
8212 : 4 : n->objtype = OBJECT_FUNCTION;
8213 : 4 : n->objs = $5;
8214 : 4 : $$ = n;
8215 : : }
8216 : : | ALL PROCEDURES IN_P SCHEMA name_list
8217 : : {
8218 : 4 : PrivTarget *n = palloc_object(PrivTarget);
8219 : :
8220 : 4 : n->targtype = ACL_TARGET_ALL_IN_SCHEMA;
8221 : 4 : n->objtype = OBJECT_PROCEDURE;
8222 : 4 : n->objs = $5;
8223 : 4 : $$ = n;
8224 : : }
8225 : : | ALL ROUTINES IN_P SCHEMA name_list
8226 : : {
8227 : 4 : PrivTarget *n = palloc_object(PrivTarget);
8228 : :
8229 : 4 : n->targtype = ACL_TARGET_ALL_IN_SCHEMA;
8230 : 4 : n->objtype = OBJECT_ROUTINE;
8231 : 4 : n->objs = $5;
8232 : 4 : $$ = n;
8233 : : }
8234 : : ;
8235 : :
8236 : :
8237 : : grantee_list:
8238 : 9308 : grantee { $$ = list_make1($1); }
8239 : 71 : | grantee_list ',' grantee { $$ = lappend($1, $3); }
8240 : : ;
8241 : :
8242 : : grantee:
8243 : 9363 : RoleSpec { $$ = $1; }
8244 : 16 : | GROUP_P RoleSpec { $$ = $2; }
8245 : : ;
8246 : :
8247 : :
8248 : : opt_grant_grant_option:
8249 : 77 : WITH GRANT OPTION { $$ = true; }
8250 : 6803 : | /*EMPTY*/ { $$ = false; }
8251 : : ;
8252 : :
8253 : : /*****************************************************************************
8254 : : *
8255 : : * GRANT and REVOKE ROLE statements
8256 : : *
8257 : : *****************************************************************************/
8258 : :
8259 : : GrantRoleStmt:
8260 : : GRANT privilege_list TO role_list opt_granted_by
8261 : : {
8262 : 205 : GrantRoleStmt *n = makeNode(GrantRoleStmt);
8263 : :
8264 : 205 : n->is_grant = true;
8265 : 205 : n->granted_roles = $2;
8266 : 205 : n->grantee_roles = $4;
8267 : 205 : n->opt = NIL;
8268 : 205 : n->grantor = $5;
8269 : 205 : $$ = (Node *) n;
8270 : : }
8271 : : | GRANT privilege_list TO role_list WITH grant_role_opt_list opt_granted_by
8272 : : {
8273 : 121 : GrantRoleStmt *n = makeNode(GrantRoleStmt);
8274 : :
8275 : 121 : n->is_grant = true;
8276 : 121 : n->granted_roles = $2;
8277 : 121 : n->grantee_roles = $4;
8278 : 121 : n->opt = $6;
8279 : 121 : n->grantor = $7;
8280 : 121 : $$ = (Node *) n;
8281 : : }
8282 : : ;
8283 : :
8284 : : RevokeRoleStmt:
8285 : : REVOKE privilege_list FROM role_list opt_granted_by opt_drop_behavior
8286 : : {
8287 : 59 : GrantRoleStmt *n = makeNode(GrantRoleStmt);
8288 : :
8289 : 59 : n->is_grant = false;
8290 : 59 : n->opt = NIL;
8291 : 59 : n->granted_roles = $2;
8292 : 59 : n->grantee_roles = $4;
8293 : 59 : n->grantor = $5;
8294 : 59 : n->behavior = $6;
8295 : 59 : $$ = (Node *) n;
8296 : : }
8297 : : | REVOKE ColId OPTION FOR privilege_list FROM role_list opt_granted_by opt_drop_behavior
8298 : : {
8299 : 44 : GrantRoleStmt *n = makeNode(GrantRoleStmt);
8300 : : DefElem *opt;
8301 : :
8302 : 44 : opt = makeDefElem(pstrdup($2),
8303 : 44 : (Node *) makeBoolean(false), @2);
8304 : 44 : n->is_grant = false;
8305 : 44 : n->opt = list_make1(opt);
8306 : 44 : n->granted_roles = $5;
8307 : 44 : n->grantee_roles = $7;
8308 : 44 : n->grantor = $8;
8309 : 44 : n->behavior = $9;
8310 : 44 : $$ = (Node *) n;
8311 : : }
8312 : : ;
8313 : :
8314 : : grant_role_opt_list:
8315 : 79 : grant_role_opt_list ',' grant_role_opt { $$ = lappend($1, $3); }
8316 : 121 : | grant_role_opt { $$ = list_make1($1); }
8317 : : ;
8318 : :
8319 : : grant_role_opt:
8320 : : ColLabel grant_role_opt_value
8321 : : {
8322 : 200 : $$ = makeDefElem(pstrdup($1), $2, @1);
8323 : : }
8324 : : ;
8325 : :
8326 : : grant_role_opt_value:
8327 : 48 : OPTION { $$ = (Node *) makeBoolean(true); }
8328 : 77 : | TRUE_P { $$ = (Node *) makeBoolean(true); }
8329 : 75 : | FALSE_P { $$ = (Node *) makeBoolean(false); }
8330 : : ;
8331 : :
8332 : 108 : opt_granted_by: GRANTED BY RoleSpec { $$ = $3; }
8333 : 9494 : | /*EMPTY*/ { $$ = NULL; }
8334 : : ;
8335 : :
8336 : : /*****************************************************************************
8337 : : *
8338 : : * ALTER DEFAULT PRIVILEGES statement
8339 : : *
8340 : : *****************************************************************************/
8341 : :
8342 : : AlterDefaultPrivilegesStmt:
8343 : : ALTER DEFAULT PRIVILEGES DefACLOptionList DefACLAction
8344 : : {
8345 : 135 : AlterDefaultPrivilegesStmt *n = makeNode(AlterDefaultPrivilegesStmt);
8346 : :
8347 : 135 : n->options = $4;
8348 : 135 : n->action = (GrantStmt *) $5;
8349 : 135 : $$ = (Node *) n;
8350 : : }
8351 : : ;
8352 : :
8353 : : DefACLOptionList:
8354 : 93 : DefACLOptionList DefACLOption { $$ = lappend($1, $2); }
8355 : 135 : | /* EMPTY */ { $$ = NIL; }
8356 : : ;
8357 : :
8358 : : DefACLOption:
8359 : : IN_P SCHEMA name_list
8360 : : {
8361 : 39 : $$ = makeDefElem("schemas", (Node *) $3, @1);
8362 : : }
8363 : : | FOR ROLE role_list
8364 : : {
8365 : 54 : $$ = makeDefElem("roles", (Node *) $3, @1);
8366 : : }
8367 : : | FOR USER role_list
8368 : : {
8369 : 0 : $$ = makeDefElem("roles", (Node *) $3, @1);
8370 : : }
8371 : : ;
8372 : :
8373 : : /*
8374 : : * This should match GRANT/REVOKE, except that individual target objects
8375 : : * are not mentioned and we only allow a subset of object types.
8376 : : */
8377 : : DefACLAction:
8378 : : GRANT privileges ON defacl_privilege_target TO grantee_list
8379 : : opt_grant_grant_option
8380 : : {
8381 : 82 : GrantStmt *n = makeNode(GrantStmt);
8382 : :
8383 : 82 : n->is_grant = true;
8384 : 82 : n->privileges = $2;
8385 : 82 : n->targtype = ACL_TARGET_DEFAULTS;
8386 : 82 : n->objtype = $4;
8387 : 82 : n->objects = NIL;
8388 : 82 : n->grantees = $6;
8389 : 82 : n->grant_option = $7;
8390 : 82 : $$ = (Node *) n;
8391 : : }
8392 : : | REVOKE privileges ON defacl_privilege_target
8393 : : FROM grantee_list opt_drop_behavior
8394 : : {
8395 : 53 : GrantStmt *n = makeNode(GrantStmt);
8396 : :
8397 : 53 : n->is_grant = false;
8398 : 53 : n->grant_option = false;
8399 : 53 : n->privileges = $2;
8400 : 53 : n->targtype = ACL_TARGET_DEFAULTS;
8401 : 53 : n->objtype = $4;
8402 : 53 : n->objects = NIL;
8403 : 53 : n->grantees = $6;
8404 : 53 : n->behavior = $7;
8405 : 53 : $$ = (Node *) n;
8406 : : }
8407 : : | REVOKE GRANT OPTION FOR privileges ON defacl_privilege_target
8408 : : FROM grantee_list opt_drop_behavior
8409 : : {
8410 : 0 : GrantStmt *n = makeNode(GrantStmt);
8411 : :
8412 : 0 : n->is_grant = false;
8413 : 0 : n->grant_option = true;
8414 : 0 : n->privileges = $5;
8415 : 0 : n->targtype = ACL_TARGET_DEFAULTS;
8416 : 0 : n->objtype = $7;
8417 : 0 : n->objects = NIL;
8418 : 0 : n->grantees = $9;
8419 : 0 : n->behavior = $10;
8420 : 0 : $$ = (Node *) n;
8421 : : }
8422 : : ;
8423 : :
8424 : : defacl_privilege_target:
8425 : 51 : TABLES { $$ = OBJECT_TABLE; }
8426 : 10 : | FUNCTIONS { $$ = OBJECT_FUNCTION; }
8427 : 4 : | ROUTINES { $$ = OBJECT_FUNCTION; }
8428 : 4 : | SEQUENCES { $$ = OBJECT_SEQUENCE; }
8429 : 22 : | TYPES_P { $$ = OBJECT_TYPE; }
8430 : 24 : | SCHEMAS { $$ = OBJECT_SCHEMA; }
8431 : 20 : | LARGE_P OBJECTS_P { $$ = OBJECT_LARGEOBJECT; }
8432 : : ;
8433 : :
8434 : :
8435 : : /*****************************************************************************
8436 : : *
8437 : : * QUERY: CREATE INDEX
8438 : : *
8439 : : * Note: we cannot put TABLESPACE clause after WHERE clause unless we are
8440 : : * willing to make TABLESPACE a fully reserved word.
8441 : : *****************************************************************************/
8442 : :
8443 : : IndexStmt: CREATE opt_unique INDEX opt_concurrently opt_single_name
8444 : : ON relation_expr access_method_clause '(' index_params ')'
8445 : : opt_include opt_unique_null_treatment opt_reloptions OptTableSpace where_clause
8446 : : {
8447 : 4541 : IndexStmt *n = makeNode(IndexStmt);
8448 : :
8449 : 4541 : n->unique = $2;
8450 : 4541 : n->concurrent = $4;
8451 : 4541 : n->idxname = $5;
8452 : 4541 : n->relation = $7;
8453 : 4541 : n->accessMethod = $8;
8454 : 4541 : n->indexParams = $10;
8455 : 4541 : n->indexIncludingParams = $12;
8456 : 4541 : n->nulls_not_distinct = !$13;
8457 : 4541 : n->options = $14;
8458 : 4541 : n->tableSpace = $15;
8459 : 4541 : n->whereClause = $16;
8460 : 4541 : n->excludeOpNames = NIL;
8461 : 4541 : n->idxcomment = NULL;
8462 : 4541 : n->indexOid = InvalidOid;
8463 : 4541 : n->oldNumber = InvalidRelFileNumber;
8464 : 4541 : n->oldCreateSubid = InvalidSubTransactionId;
8465 : 4541 : n->oldFirstRelfilelocatorSubid = InvalidSubTransactionId;
8466 : 4541 : n->primary = false;
8467 : 4541 : n->isconstraint = false;
8468 : 4541 : n->deferrable = false;
8469 : 4541 : n->initdeferred = false;
8470 : 4541 : n->transformed = false;
8471 : 4541 : n->if_not_exists = false;
8472 : 4541 : n->reset_default_tblspc = false;
8473 : 4541 : $$ = (Node *) n;
8474 : : }
8475 : : | CREATE opt_unique INDEX opt_concurrently IF_P NOT EXISTS name
8476 : : ON relation_expr access_method_clause '(' index_params ')'
8477 : : opt_include opt_unique_null_treatment opt_reloptions OptTableSpace where_clause
8478 : : {
8479 : 12 : IndexStmt *n = makeNode(IndexStmt);
8480 : :
8481 : 12 : n->unique = $2;
8482 : 12 : n->concurrent = $4;
8483 : 12 : n->idxname = $8;
8484 : 12 : n->relation = $10;
8485 : 12 : n->accessMethod = $11;
8486 : 12 : n->indexParams = $13;
8487 : 12 : n->indexIncludingParams = $15;
8488 : 12 : n->nulls_not_distinct = !$16;
8489 : 12 : n->options = $17;
8490 : 12 : n->tableSpace = $18;
8491 : 12 : n->whereClause = $19;
8492 : 12 : n->excludeOpNames = NIL;
8493 : 12 : n->idxcomment = NULL;
8494 : 12 : n->indexOid = InvalidOid;
8495 : 12 : n->oldNumber = InvalidRelFileNumber;
8496 : 12 : n->oldCreateSubid = InvalidSubTransactionId;
8497 : 12 : n->oldFirstRelfilelocatorSubid = InvalidSubTransactionId;
8498 : 12 : n->primary = false;
8499 : 12 : n->isconstraint = false;
8500 : 12 : n->deferrable = false;
8501 : 12 : n->initdeferred = false;
8502 : 12 : n->transformed = false;
8503 : 12 : n->if_not_exists = true;
8504 : 12 : n->reset_default_tblspc = false;
8505 : 12 : $$ = (Node *) n;
8506 : : }
8507 : : ;
8508 : :
8509 : : opt_unique:
8510 : 837 : UNIQUE { $$ = true; }
8511 : 3720 : | /*EMPTY*/ { $$ = false; }
8512 : : ;
8513 : :
8514 : : access_method_clause:
8515 : 1906 : USING name { $$ = $2; }
8516 : 2816 : | /*EMPTY*/ { $$ = DEFAULT_INDEX_TYPE; }
8517 : : ;
8518 : :
8519 : 5824 : index_params: index_elem { $$ = list_make1($1); }
8520 : 1402 : | index_params ',' index_elem { $$ = lappend($1, $3); }
8521 : : ;
8522 : :
8523 : :
8524 : : index_elem_options:
8525 : : opt_collate opt_qualified_name opt_asc_desc opt_nulls_order
8526 : : {
8527 : 7645 : $$ = makeNode(IndexElem);
8528 : 7645 : $$->name = NULL;
8529 : 7645 : $$->expr = NULL;
8530 : 7645 : $$->indexcolname = NULL;
8531 : 7645 : $$->collation = $1;
8532 : 7645 : $$->opclass = $2;
8533 : 7645 : $$->opclassopts = NIL;
8534 : 7645 : $$->ordering = $3;
8535 : 7645 : $$->nulls_ordering = $4;
8536 : : /* location will be filled in index_elem production */
8537 : : }
8538 : : | opt_collate any_name reloptions opt_asc_desc opt_nulls_order
8539 : : {
8540 : 91 : $$ = makeNode(IndexElem);
8541 : 91 : $$->name = NULL;
8542 : 91 : $$->expr = NULL;
8543 : 91 : $$->indexcolname = NULL;
8544 : 91 : $$->collation = $1;
8545 : 91 : $$->opclass = $2;
8546 : 91 : $$->opclassopts = $3;
8547 : 91 : $$->ordering = $4;
8548 : 91 : $$->nulls_ordering = $5;
8549 : : /* location will be filled in index_elem production */
8550 : : }
8551 : : ;
8552 : :
8553 : : /*
8554 : : * Index attributes can be either simple column references, or arbitrary
8555 : : * expressions in parens. For backwards-compatibility reasons, we allow
8556 : : * an expression that's just a function call to be written without parens.
8557 : : */
8558 : : index_elem: ColId index_elem_options
8559 : : {
8560 : 6782 : $$ = $2;
8561 : 6782 : $$->name = $1;
8562 : 6782 : $$->location = @1;
8563 : : }
8564 : : | func_expr_windowless index_elem_options
8565 : : {
8566 : 555 : $$ = $2;
8567 : 555 : $$->expr = $1;
8568 : 555 : $$->location = @1;
8569 : : }
8570 : : | '(' a_expr ')' index_elem_options
8571 : : {
8572 : 399 : $$ = $4;
8573 : 399 : $$->expr = $2;
8574 : 399 : $$->location = @1;
8575 : : }
8576 : : ;
8577 : :
8578 : 149 : opt_include: INCLUDE '(' index_including_params ')' { $$ = $3; }
8579 : 4404 : | /* EMPTY */ { $$ = NIL; }
8580 : : ;
8581 : :
8582 : 149 : index_including_params: index_elem { $$ = list_make1($1); }
8583 : 109 : | index_including_params ',' index_elem { $$ = lappend($1, $3); }
8584 : : ;
8585 : :
8586 : 130 : opt_collate: COLLATE any_name { $$ = $2; }
8587 : 11612 : | /*EMPTY*/ { $$ = NIL; }
8588 : : ;
8589 : :
8590 : :
8591 : 1019 : opt_asc_desc: ASC { $$ = SORTBY_ASC; }
8592 : 2402 : | DESC { $$ = SORTBY_DESC; }
8593 : 77970 : | /*EMPTY*/ { $$ = SORTBY_DEFAULT; }
8594 : : ;
8595 : :
8596 : 215 : opt_nulls_order: NULLS_LA FIRST_P { $$ = SORTBY_NULLS_FIRST; }
8597 : 905 : | NULLS_LA LAST_P { $$ = SORTBY_NULLS_LAST; }
8598 : 80413 : | /*EMPTY*/ { $$ = SORTBY_NULLS_DEFAULT; }
8599 : : ;
8600 : :
8601 : :
8602 : : /*****************************************************************************
8603 : : *
8604 : : * QUERY:
8605 : : * create [or replace] function <fname>
8606 : : * [(<type-1> { , <type-n>})]
8607 : : * returns <type-r>
8608 : : * as <filename or code in language as appropriate>
8609 : : * language <lang> [with parameters]
8610 : : *
8611 : : *****************************************************************************/
8612 : :
8613 : : CreateFunctionStmt:
8614 : : CREATE opt_or_replace FUNCTION func_name func_args_with_defaults
8615 : : RETURNS func_return opt_createfunc_opt_list opt_routine_body
8616 : : {
8617 : 12426 : CreateFunctionStmt *n = makeNode(CreateFunctionStmt);
8618 : :
8619 : 12426 : n->is_procedure = false;
8620 : 12426 : n->replace = $2;
8621 : 12426 : n->funcname = $4;
8622 : 12426 : n->parameters = $5;
8623 : 12426 : n->returnType = $7;
8624 : 12426 : n->options = $8;
8625 : 12426 : n->sql_body = $9;
8626 : 12426 : $$ = (Node *) n;
8627 : : }
8628 : : | CREATE opt_or_replace FUNCTION func_name func_args_with_defaults
8629 : : RETURNS TABLE '(' table_func_column_list ')' opt_createfunc_opt_list opt_routine_body
8630 : : {
8631 : 146 : CreateFunctionStmt *n = makeNode(CreateFunctionStmt);
8632 : :
8633 : 146 : n->is_procedure = false;
8634 : 146 : n->replace = $2;
8635 : 146 : n->funcname = $4;
8636 : 146 : n->parameters = mergeTableFuncParameters($5, $9, yyscanner);
8637 : 146 : n->returnType = TableFuncTypeName($9);
8638 : 146 : n->returnType->location = @7;
8639 : 146 : n->options = $11;
8640 : 146 : n->sql_body = $12;
8641 : 146 : $$ = (Node *) n;
8642 : : }
8643 : : | CREATE opt_or_replace FUNCTION func_name func_args_with_defaults
8644 : : opt_createfunc_opt_list opt_routine_body
8645 : : {
8646 : 301 : CreateFunctionStmt *n = makeNode(CreateFunctionStmt);
8647 : :
8648 : 301 : n->is_procedure = false;
8649 : 301 : n->replace = $2;
8650 : 301 : n->funcname = $4;
8651 : 301 : n->parameters = $5;
8652 : 301 : n->returnType = NULL;
8653 : 301 : n->options = $6;
8654 : 301 : n->sql_body = $7;
8655 : 301 : $$ = (Node *) n;
8656 : : }
8657 : : | CREATE opt_or_replace PROCEDURE func_name func_args_with_defaults
8658 : : opt_createfunc_opt_list opt_routine_body
8659 : : {
8660 : 226 : CreateFunctionStmt *n = makeNode(CreateFunctionStmt);
8661 : :
8662 : 226 : n->is_procedure = true;
8663 : 226 : n->replace = $2;
8664 : 226 : n->funcname = $4;
8665 : 226 : n->parameters = $5;
8666 : 226 : n->returnType = NULL;
8667 : 226 : n->options = $6;
8668 : 226 : n->sql_body = $7;
8669 : 226 : $$ = (Node *) n;
8670 : : }
8671 : : ;
8672 : :
8673 : : opt_or_replace:
8674 : 3839 : OR REPLACE { $$ = true; }
8675 : 12910 : | /*EMPTY*/ { $$ = false; }
8676 : : ;
8677 : :
8678 : 3983 : func_args: '(' func_args_list ')' { $$ = $2; }
8679 : 1334 : | '(' ')' { $$ = NIL; }
8680 : : ;
8681 : :
8682 : : func_args_list:
8683 : 3983 : func_arg { $$ = list_make1($1); }
8684 : 3979 : | func_args_list ',' func_arg { $$ = lappend($1, $3); }
8685 : : ;
8686 : :
8687 : : function_with_argtypes_list:
8688 : 3161 : function_with_argtypes { $$ = list_make1($1); }
8689 : : | function_with_argtypes_list ',' function_with_argtypes
8690 : 56 : { $$ = lappend($1, $3); }
8691 : : ;
8692 : :
8693 : : function_with_argtypes:
8694 : : func_name func_args
8695 : : {
8696 : 5317 : ObjectWithArgs *n = makeNode(ObjectWithArgs);
8697 : :
8698 : 5317 : n->objname = $1;
8699 : 5317 : n->objargs = extractArgTypes($2);
8700 : 5317 : n->objfuncargs = $2;
8701 : 5317 : $$ = n;
8702 : : }
8703 : : /*
8704 : : * Because of reduce/reduce conflicts, we can't use func_name
8705 : : * below, but we can write it out the long way, which actually
8706 : : * allows more cases.
8707 : : */
8708 : : | type_func_name_keyword
8709 : : {
8710 : 0 : ObjectWithArgs *n = makeNode(ObjectWithArgs);
8711 : :
8712 : 0 : n->objname = list_make1(makeString(pstrdup($1)));
8713 : 0 : n->args_unspecified = true;
8714 : 0 : $$ = n;
8715 : : }
8716 : : | ColId
8717 : : {
8718 : 306 : ObjectWithArgs *n = makeNode(ObjectWithArgs);
8719 : :
8720 : 306 : n->objname = list_make1(makeString($1));
8721 : 306 : n->args_unspecified = true;
8722 : 306 : $$ = n;
8723 : : }
8724 : : | ColId indirection
8725 : : {
8726 : 14 : ObjectWithArgs *n = makeNode(ObjectWithArgs);
8727 : :
8728 : 14 : n->objname = check_func_name(lcons(makeString($1), $2),
8729 : : yyscanner);
8730 : 14 : n->args_unspecified = true;
8731 : 14 : $$ = n;
8732 : : }
8733 : : ;
8734 : :
8735 : : /*
8736 : : * func_args_with_defaults is separate because we only want to accept
8737 : : * defaults in CREATE FUNCTION, not in ALTER etc.
8738 : : */
8739 : : func_args_with_defaults:
8740 : 10247 : '(' func_args_with_defaults_list ')' { $$ = $2; }
8741 : 2852 : | '(' ')' { $$ = NIL; }
8742 : : ;
8743 : :
8744 : : func_args_with_defaults_list:
8745 : 10247 : func_arg_with_default { $$ = list_make1($1); }
8746 : : | func_args_with_defaults_list ',' func_arg_with_default
8747 : 14719 : { $$ = lappend($1, $3); }
8748 : : ;
8749 : :
8750 : : /*
8751 : : * The style with arg_class first is SQL99 standard, but Oracle puts
8752 : : * param_name first; accept both since it's likely people will try both
8753 : : * anyway. Don't bother trying to save productions by letting arg_class
8754 : : * have an empty alternative ... you'll get shift/reduce conflicts.
8755 : : *
8756 : : * We can catch over-specified arguments here if we want to,
8757 : : * but for now better to silently swallow typmod, etc.
8758 : : * - thomas 2000-03-22
8759 : : */
8760 : : func_arg:
8761 : : arg_class param_name func_type
8762 : : {
8763 : 7340 : FunctionParameter *n = makeNode(FunctionParameter);
8764 : :
8765 : 7340 : n->name = $2;
8766 : 7340 : n->argType = $3;
8767 : 7340 : n->mode = $1;
8768 : 7340 : n->defexpr = NULL;
8769 : 7340 : n->location = @1;
8770 : 7340 : $$ = n;
8771 : : }
8772 : : | param_name arg_class func_type
8773 : : {
8774 : 258 : FunctionParameter *n = makeNode(FunctionParameter);
8775 : :
8776 : 258 : n->name = $1;
8777 : 258 : n->argType = $3;
8778 : 258 : n->mode = $2;
8779 : 258 : n->defexpr = NULL;
8780 : 258 : n->location = @1;
8781 : 258 : $$ = n;
8782 : : }
8783 : : | param_name func_type
8784 : : {
8785 : 4351 : FunctionParameter *n = makeNode(FunctionParameter);
8786 : :
8787 : 4351 : n->name = $1;
8788 : 4351 : n->argType = $2;
8789 : 4351 : n->mode = FUNC_PARAM_DEFAULT;
8790 : 4351 : n->defexpr = NULL;
8791 : 4351 : n->location = @1;
8792 : 4351 : $$ = n;
8793 : : }
8794 : : | arg_class func_type
8795 : : {
8796 : 201 : FunctionParameter *n = makeNode(FunctionParameter);
8797 : :
8798 : 201 : n->name = NULL;
8799 : 201 : n->argType = $2;
8800 : 201 : n->mode = $1;
8801 : 201 : n->defexpr = NULL;
8802 : 201 : n->location = @1;
8803 : 201 : $$ = n;
8804 : : }
8805 : : | func_type
8806 : : {
8807 : 21338 : FunctionParameter *n = makeNode(FunctionParameter);
8808 : :
8809 : 21338 : n->name = NULL;
8810 : 21338 : n->argType = $1;
8811 : 21338 : n->mode = FUNC_PARAM_DEFAULT;
8812 : 21338 : n->defexpr = NULL;
8813 : 21338 : n->location = @1;
8814 : 21338 : $$ = n;
8815 : : }
8816 : : ;
8817 : :
8818 : : /* INOUT is SQL99 standard, IN OUT is for Oracle compatibility */
8819 : 1487 : arg_class: IN_P { $$ = FUNC_PARAM_IN; }
8820 : 6069 : | OUT_P { $$ = FUNC_PARAM_OUT; }
8821 : 122 : | INOUT { $$ = FUNC_PARAM_INOUT; }
8822 : 0 : | IN_P OUT_P { $$ = FUNC_PARAM_INOUT; }
8823 : 121 : | VARIADIC { $$ = FUNC_PARAM_VARIADIC; }
8824 : : ;
8825 : :
8826 : : /*
8827 : : * Ideally param_name should be ColId, but that causes too many conflicts.
8828 : : */
8829 : : param_name: type_function_name
8830 : : ;
8831 : :
8832 : : func_return:
8833 : : func_type
8834 : : {
8835 : : /* We can catch over-specified results here if we want to,
8836 : : * but for now better to silently swallow typmod, etc.
8837 : : * - thomas 2000-03-22
8838 : : */
8839 : 12426 : $$ = $1;
8840 : : }
8841 : : ;
8842 : :
8843 : : /*
8844 : : * We would like to make the %TYPE productions here be ColId attrs etc,
8845 : : * but that causes reduce/reduce conflicts. type_function_name
8846 : : * is next best choice.
8847 : : */
8848 : 58508 : func_type: Typename { $$ = $1; }
8849 : : | type_function_name attrs '%' TYPE_P
8850 : : {
8851 : 12 : $$ = makeTypeNameFromNameList(lcons(makeString($1), $2));
8852 : 12 : $$->pct_type = true;
8853 : 12 : $$->location = @1;
8854 : : }
8855 : : | SETOF type_function_name attrs '%' TYPE_P
8856 : : {
8857 : 4 : $$ = makeTypeNameFromNameList(lcons(makeString($2), $3));
8858 : 4 : $$->pct_type = true;
8859 : 4 : $$->setof = true;
8860 : 4 : $$->location = @2;
8861 : : }
8862 : : ;
8863 : :
8864 : : func_arg_with_default:
8865 : : func_arg
8866 : : {
8867 : 24388 : $$ = $1;
8868 : : }
8869 : : | func_arg DEFAULT a_expr
8870 : : {
8871 : 450 : $$ = $1;
8872 : 450 : $$->defexpr = $3;
8873 : : }
8874 : : | func_arg '=' a_expr
8875 : : {
8876 : 128 : $$ = $1;
8877 : 128 : $$->defexpr = $3;
8878 : : }
8879 : : ;
8880 : :
8881 : : /* Aggregate args can be most things that function args can be */
8882 : : aggr_arg: func_arg
8883 : : {
8884 [ + + ]: 560 : if (!($1->mode == FUNC_PARAM_DEFAULT ||
8885 [ + - ]: 36 : $1->mode == FUNC_PARAM_IN ||
8886 [ - + ]: 36 : $1->mode == FUNC_PARAM_VARIADIC))
8887 [ # # ]: 0 : ereport(ERROR,
8888 : : (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
8889 : : errmsg("aggregates cannot have output arguments"),
8890 : : parser_errposition(@1)));
8891 : 560 : $$ = $1;
8892 : : }
8893 : : ;
8894 : :
8895 : : /*
8896 : : * The SQL standard offers no guidance on how to declare aggregate argument
8897 : : * lists, since it doesn't have CREATE AGGREGATE etc. We accept these cases:
8898 : : *
8899 : : * (*) - normal agg with no args
8900 : : * (aggr_arg,...) - normal agg with args
8901 : : * (ORDER BY aggr_arg,...) - ordered-set agg with no direct args
8902 : : * (aggr_arg,... ORDER BY aggr_arg,...) - ordered-set agg with direct args
8903 : : *
8904 : : * The zero-argument case is spelled with '*' for consistency with COUNT(*).
8905 : : *
8906 : : * An additional restriction is that if the direct-args list ends in a
8907 : : * VARIADIC item, the ordered-args list must contain exactly one item that
8908 : : * is also VARIADIC with the same type. This allows us to collapse the two
8909 : : * VARIADIC items into one, which is necessary to represent the aggregate in
8910 : : * pg_proc. We check this at the grammar stage so that we can return a list
8911 : : * in which the second VARIADIC item is already discarded, avoiding extra work
8912 : : * in cases such as DROP AGGREGATE.
8913 : : *
8914 : : * The return value of this production is a two-element list, in which the
8915 : : * first item is a sublist of FunctionParameter nodes (with any duplicate
8916 : : * VARIADIC item already dropped, as per above) and the second is an Integer
8917 : : * node, containing -1 if there was no ORDER BY and otherwise the number
8918 : : * of argument declarations before the ORDER BY. (If this number is equal
8919 : : * to the first sublist's length, then we dropped a duplicate VARIADIC item.)
8920 : : * This representation is passed as-is to CREATE AGGREGATE; for operations
8921 : : * on existing aggregates, we can just apply extractArgTypes to the first
8922 : : * sublist.
8923 : : */
8924 : : aggr_args: '(' '*' ')'
8925 : : {
8926 : 85 : $$ = list_make2(NIL, makeInteger(-1));
8927 : : }
8928 : : | '(' aggr_args_list ')'
8929 : : {
8930 : 456 : $$ = list_make2($2, makeInteger(-1));
8931 : : }
8932 : : | '(' ORDER BY aggr_args_list ')'
8933 : : {
8934 : 4 : $$ = list_make2($4, makeInteger(0));
8935 : : }
8936 : : | '(' aggr_args_list ORDER BY aggr_args_list ')'
8937 : : {
8938 : : /* this is the only case requiring consistency checking */
8939 : 20 : $$ = makeOrderedSetArgs($2, $5, yyscanner);
8940 : : }
8941 : : ;
8942 : :
8943 : : aggr_args_list:
8944 : 500 : aggr_arg { $$ = list_make1($1); }
8945 : 60 : | aggr_args_list ',' aggr_arg { $$ = lappend($1, $3); }
8946 : : ;
8947 : :
8948 : : aggregate_with_argtypes:
8949 : : func_name aggr_args
8950 : : {
8951 : 220 : ObjectWithArgs *n = makeNode(ObjectWithArgs);
8952 : :
8953 : 220 : n->objname = $1;
8954 : 220 : n->objargs = extractAggrArgTypes($2);
8955 : 220 : n->objfuncargs = (List *) linitial($2);
8956 : 220 : $$ = n;
8957 : : }
8958 : : ;
8959 : :
8960 : : aggregate_with_argtypes_list:
8961 : 69 : aggregate_with_argtypes { $$ = list_make1($1); }
8962 : : | aggregate_with_argtypes_list ',' aggregate_with_argtypes
8963 : 0 : { $$ = lappend($1, $3); }
8964 : : ;
8965 : :
8966 : : opt_createfunc_opt_list:
8967 : : createfunc_opt_list
8968 : 87 : | /*EMPTY*/ { $$ = NIL; }
8969 : : ;
8970 : :
8971 : : createfunc_opt_list:
8972 : : /* Must be at least one to prevent conflict */
8973 : 13012 : createfunc_opt_item { $$ = list_make1($1); }
8974 : 31386 : | createfunc_opt_list createfunc_opt_item { $$ = lappend($1, $2); }
8975 : : ;
8976 : :
8977 : : /*
8978 : : * Options common to both CREATE FUNCTION and ALTER FUNCTION
8979 : : */
8980 : : common_func_opt_item:
8981 : : CALLED ON NULL_P INPUT_P
8982 : : {
8983 : 69 : $$ = makeDefElem("strict", (Node *) makeBoolean(false), @1);
8984 : : }
8985 : : | RETURNS NULL_P ON NULL_P INPUT_P
8986 : : {
8987 : 508 : $$ = makeDefElem("strict", (Node *) makeBoolean(true), @1);
8988 : : }
8989 : : | STRICT_P
8990 : : {
8991 : 6153 : $$ = makeDefElem("strict", (Node *) makeBoolean(true), @1);
8992 : : }
8993 : : | IMMUTABLE
8994 : : {
8995 : 4923 : $$ = makeDefElem("volatility", (Node *) makeString("immutable"), @1);
8996 : : }
8997 : : | STABLE
8998 : : {
8999 : 973 : $$ = makeDefElem("volatility", (Node *) makeString("stable"), @1);
9000 : : }
9001 : : | VOLATILE
9002 : : {
9003 : 203 : $$ = makeDefElem("volatility", (Node *) makeString("volatile"), @1);
9004 : : }
9005 : : | EXTERNAL SECURITY DEFINER
9006 : : {
9007 : 0 : $$ = makeDefElem("security", (Node *) makeBoolean(true), @1);
9008 : : }
9009 : : | EXTERNAL SECURITY INVOKER
9010 : : {
9011 : 0 : $$ = makeDefElem("security", (Node *) makeBoolean(false), @1);
9012 : : }
9013 : : | SECURITY DEFINER
9014 : : {
9015 : 36 : $$ = makeDefElem("security", (Node *) makeBoolean(true), @1);
9016 : : }
9017 : : | SECURITY INVOKER
9018 : : {
9019 : 12 : $$ = makeDefElem("security", (Node *) makeBoolean(false), @1);
9020 : : }
9021 : : | LEAKPROOF
9022 : : {
9023 : 30 : $$ = makeDefElem("leakproof", (Node *) makeBoolean(true), @1);
9024 : : }
9025 : : | NOT LEAKPROOF
9026 : : {
9027 : 8 : $$ = makeDefElem("leakproof", (Node *) makeBoolean(false), @1);
9028 : : }
9029 : : | COST NumericOnly
9030 : : {
9031 : 2175 : $$ = makeDefElem("cost", (Node *) $2, @1);
9032 : : }
9033 : : | ROWS NumericOnly
9034 : : {
9035 : 67 : $$ = makeDefElem("rows", (Node *) $2, @1);
9036 : : }
9037 : : | SUPPORT any_name
9038 : : {
9039 : 70 : $$ = makeDefElem("support", (Node *) $2, @1);
9040 : : }
9041 : : | FunctionSetResetClause
9042 : : {
9043 : : /* we abuse the normal content of a DefElem here */
9044 : 97 : $$ = makeDefElem("set", (Node *) $1, @1);
9045 : : }
9046 : : | PARALLEL ColId
9047 : : {
9048 : 6410 : $$ = makeDefElem("parallel", (Node *) makeString($2), @1);
9049 : : }
9050 : : ;
9051 : :
9052 : : createfunc_opt_item:
9053 : : AS func_as
9054 : : {
9055 : 9795 : $$ = makeDefElem("as", (Node *) $2, @1);
9056 : : }
9057 : : | LANGUAGE NonReservedWord_or_Sconst
9058 : : {
9059 : 12999 : $$ = makeDefElem("language", (Node *) makeString($2), @1);
9060 : : }
9061 : : | TRANSFORM transform_type_list
9062 : : {
9063 : 68 : $$ = makeDefElem("transform", (Node *) $2, @1);
9064 : : }
9065 : : | WINDOW
9066 : : {
9067 : 13 : $$ = makeDefElem("window", (Node *) makeBoolean(true), @1);
9068 : : }
9069 : : | common_func_opt_item
9070 : : {
9071 : 21523 : $$ = $1;
9072 : : }
9073 : : ;
9074 : :
9075 : 7895 : func_as: Sconst { $$ = list_make1(makeString($1)); }
9076 : : | Sconst ',' Sconst
9077 : : {
9078 : 1900 : $$ = list_make2(makeString($1), makeString($3));
9079 : : }
9080 : : ;
9081 : :
9082 : : ReturnStmt: RETURN a_expr
9083 : : {
9084 : 2784 : ReturnStmt *r = makeNode(ReturnStmt);
9085 : :
9086 : 2784 : r->returnval = (Node *) $2;
9087 : 2784 : $$ = (Node *) r;
9088 : : }
9089 : : ;
9090 : :
9091 : : opt_routine_body:
9092 : : ReturnStmt
9093 : : {
9094 : 2780 : $$ = $1;
9095 : : }
9096 : : | BEGIN_P ATOMIC routine_body_stmt_list END_P
9097 : : {
9098 : : /*
9099 : : * A compound statement is stored as a single-item list
9100 : : * containing the list of statements as its member. That
9101 : : * way, the parse analysis code can tell apart an empty
9102 : : * body from no body at all.
9103 : : */
9104 : 528 : $$ = (Node *) list_make1($3);
9105 : : }
9106 : : | /*EMPTY*/
9107 : : {
9108 : 9791 : $$ = NULL;
9109 : : }
9110 : : ;
9111 : :
9112 : : routine_body_stmt_list:
9113 : : routine_body_stmt_list routine_body_stmt ';'
9114 : : {
9115 : : /* As in stmtmulti, discard empty statements */
9116 [ + + ]: 539 : if ($2 != NULL)
9117 : 527 : $$ = lappend($1, $2);
9118 : : else
9119 : 12 : $$ = $1;
9120 : : }
9121 : : | /*EMPTY*/
9122 : : {
9123 : 528 : $$ = NIL;
9124 : : }
9125 : : ;
9126 : :
9127 : : routine_body_stmt:
9128 : : stmt
9129 : : | ReturnStmt
9130 : : ;
9131 : :
9132 : : transform_type_list:
9133 : 68 : FOR TYPE_P Typename { $$ = list_make1($3); }
9134 : 2 : | transform_type_list ',' FOR TYPE_P Typename { $$ = lappend($1, $5); }
9135 : : ;
9136 : :
9137 : : opt_definition:
9138 : 500 : WITH definition { $$ = $2; }
9139 : 6750 : | /*EMPTY*/ { $$ = NIL; }
9140 : : ;
9141 : :
9142 : : table_func_column: param_name func_type
9143 : : {
9144 : 343 : FunctionParameter *n = makeNode(FunctionParameter);
9145 : :
9146 : 343 : n->name = $1;
9147 : 343 : n->argType = $2;
9148 : 343 : n->mode = FUNC_PARAM_TABLE;
9149 : 343 : n->defexpr = NULL;
9150 : 343 : n->location = @1;
9151 : 343 : $$ = n;
9152 : : }
9153 : : ;
9154 : :
9155 : : table_func_column_list:
9156 : : table_func_column
9157 : : {
9158 : 146 : $$ = list_make1($1);
9159 : : }
9160 : : | table_func_column_list ',' table_func_column
9161 : : {
9162 : 197 : $$ = lappend($1, $3);
9163 : : }
9164 : : ;
9165 : :
9166 : : /*****************************************************************************
9167 : : * ALTER FUNCTION / ALTER PROCEDURE / ALTER ROUTINE
9168 : : *
9169 : : * RENAME and OWNER subcommands are already provided by the generic
9170 : : * ALTER infrastructure, here we just specify alterations that can
9171 : : * only be applied to functions.
9172 : : *
9173 : : *****************************************************************************/
9174 : : AlterFunctionStmt:
9175 : : ALTER FUNCTION function_with_argtypes alterfunc_opt_list opt_restrict
9176 : : {
9177 : 197 : AlterFunctionStmt *n = makeNode(AlterFunctionStmt);
9178 : :
9179 : 197 : n->objtype = OBJECT_FUNCTION;
9180 : 197 : n->func = $3;
9181 : 197 : n->actions = $4;
9182 : 197 : $$ = (Node *) n;
9183 : : }
9184 : : | ALTER PROCEDURE function_with_argtypes alterfunc_opt_list opt_restrict
9185 : : {
9186 : 12 : AlterFunctionStmt *n = makeNode(AlterFunctionStmt);
9187 : :
9188 : 12 : n->objtype = OBJECT_PROCEDURE;
9189 : 12 : n->func = $3;
9190 : 12 : n->actions = $4;
9191 : 12 : $$ = (Node *) n;
9192 : : }
9193 : : | ALTER ROUTINE function_with_argtypes alterfunc_opt_list opt_restrict
9194 : : {
9195 : 0 : AlterFunctionStmt *n = makeNode(AlterFunctionStmt);
9196 : :
9197 : 0 : n->objtype = OBJECT_ROUTINE;
9198 : 0 : n->func = $3;
9199 : 0 : n->actions = $4;
9200 : 0 : $$ = (Node *) n;
9201 : : }
9202 : : ;
9203 : :
9204 : : alterfunc_opt_list:
9205 : : /* At least one option must be specified */
9206 : 209 : common_func_opt_item { $$ = list_make1($1); }
9207 : 2 : | alterfunc_opt_list common_func_opt_item { $$ = lappend($1, $2); }
9208 : : ;
9209 : :
9210 : : /* Ignored, merely for SQL compliance */
9211 : : opt_restrict:
9212 : : RESTRICT
9213 : : | /* EMPTY */
9214 : : ;
9215 : :
9216 : :
9217 : : /*****************************************************************************
9218 : : *
9219 : : * QUERY:
9220 : : *
9221 : : * DROP FUNCTION funcname (arg1, arg2, ...) [ RESTRICT | CASCADE ]
9222 : : * DROP PROCEDURE procname (arg1, arg2, ...) [ RESTRICT | CASCADE ]
9223 : : * DROP ROUTINE routname (arg1, arg2, ...) [ RESTRICT | CASCADE ]
9224 : : * DROP AGGREGATE aggname (arg1, ...) [ RESTRICT | CASCADE ]
9225 : : * DROP OPERATOR opname (leftoperand_typ, rightoperand_typ) [ RESTRICT | CASCADE ]
9226 : : *
9227 : : *****************************************************************************/
9228 : :
9229 : : RemoveFuncStmt:
9230 : : DROP FUNCTION function_with_argtypes_list opt_drop_behavior
9231 : : {
9232 : 2222 : DropStmt *n = makeNode(DropStmt);
9233 : :
9234 : 2222 : n->removeType = OBJECT_FUNCTION;
9235 : 2222 : n->objects = $3;
9236 : 2222 : n->behavior = $4;
9237 : 2222 : n->missing_ok = false;
9238 : 2222 : n->concurrent = false;
9239 : 2222 : $$ = (Node *) n;
9240 : : }
9241 : : | DROP FUNCTION IF_P EXISTS function_with_argtypes_list opt_drop_behavior
9242 : : {
9243 : 255 : DropStmt *n = makeNode(DropStmt);
9244 : :
9245 : 255 : n->removeType = OBJECT_FUNCTION;
9246 : 255 : n->objects = $5;
9247 : 255 : n->behavior = $6;
9248 : 255 : n->missing_ok = true;
9249 : 255 : n->concurrent = false;
9250 : 255 : $$ = (Node *) n;
9251 : : }
9252 : : | DROP PROCEDURE function_with_argtypes_list opt_drop_behavior
9253 : : {
9254 : 90 : DropStmt *n = makeNode(DropStmt);
9255 : :
9256 : 90 : n->removeType = OBJECT_PROCEDURE;
9257 : 90 : n->objects = $3;
9258 : 90 : n->behavior = $4;
9259 : 90 : n->missing_ok = false;
9260 : 90 : n->concurrent = false;
9261 : 90 : $$ = (Node *) n;
9262 : : }
9263 : : | DROP PROCEDURE IF_P EXISTS function_with_argtypes_list opt_drop_behavior
9264 : : {
9265 : 4 : DropStmt *n = makeNode(DropStmt);
9266 : :
9267 : 4 : n->removeType = OBJECT_PROCEDURE;
9268 : 4 : n->objects = $5;
9269 : 4 : n->behavior = $6;
9270 : 4 : n->missing_ok = true;
9271 : 4 : n->concurrent = false;
9272 : 4 : $$ = (Node *) n;
9273 : : }
9274 : : | DROP ROUTINE function_with_argtypes_list opt_drop_behavior
9275 : : {
9276 : 8 : DropStmt *n = makeNode(DropStmt);
9277 : :
9278 : 8 : n->removeType = OBJECT_ROUTINE;
9279 : 8 : n->objects = $3;
9280 : 8 : n->behavior = $4;
9281 : 8 : n->missing_ok = false;
9282 : 8 : n->concurrent = false;
9283 : 8 : $$ = (Node *) n;
9284 : : }
9285 : : | DROP ROUTINE IF_P EXISTS function_with_argtypes_list opt_drop_behavior
9286 : : {
9287 : 4 : DropStmt *n = makeNode(DropStmt);
9288 : :
9289 : 4 : n->removeType = OBJECT_ROUTINE;
9290 : 4 : n->objects = $5;
9291 : 4 : n->behavior = $6;
9292 : 4 : n->missing_ok = true;
9293 : 4 : n->concurrent = false;
9294 : 4 : $$ = (Node *) n;
9295 : : }
9296 : : ;
9297 : :
9298 : : RemoveAggrStmt:
9299 : : DROP AGGREGATE aggregate_with_argtypes_list opt_drop_behavior
9300 : : {
9301 : 49 : DropStmt *n = makeNode(DropStmt);
9302 : :
9303 : 49 : n->removeType = OBJECT_AGGREGATE;
9304 : 49 : n->objects = $3;
9305 : 49 : n->behavior = $4;
9306 : 49 : n->missing_ok = false;
9307 : 49 : n->concurrent = false;
9308 : 49 : $$ = (Node *) n;
9309 : : }
9310 : : | DROP AGGREGATE IF_P EXISTS aggregate_with_argtypes_list opt_drop_behavior
9311 : : {
9312 : 20 : DropStmt *n = makeNode(DropStmt);
9313 : :
9314 : 20 : n->removeType = OBJECT_AGGREGATE;
9315 : 20 : n->objects = $5;
9316 : 20 : n->behavior = $6;
9317 : 20 : n->missing_ok = true;
9318 : 20 : n->concurrent = false;
9319 : 20 : $$ = (Node *) n;
9320 : : }
9321 : : ;
9322 : :
9323 : : RemoveOperStmt:
9324 : : DROP OPERATOR operator_with_argtypes_list opt_drop_behavior
9325 : : {
9326 : 124 : DropStmt *n = makeNode(DropStmt);
9327 : :
9328 : 124 : n->removeType = OBJECT_OPERATOR;
9329 : 124 : n->objects = $3;
9330 : 124 : n->behavior = $4;
9331 : 124 : n->missing_ok = false;
9332 : 124 : n->concurrent = false;
9333 : 124 : $$ = (Node *) n;
9334 : : }
9335 : : | DROP OPERATOR IF_P EXISTS operator_with_argtypes_list opt_drop_behavior
9336 : : {
9337 : 20 : DropStmt *n = makeNode(DropStmt);
9338 : :
9339 : 20 : n->removeType = OBJECT_OPERATOR;
9340 : 20 : n->objects = $5;
9341 : 20 : n->behavior = $6;
9342 : 20 : n->missing_ok = true;
9343 : 20 : n->concurrent = false;
9344 : 20 : $$ = (Node *) n;
9345 : : }
9346 : : ;
9347 : :
9348 : : oper_argtypes:
9349 : : '(' Typename ')'
9350 : : {
9351 [ + - ]: 8 : ereport(ERROR,
9352 : : (errcode(ERRCODE_SYNTAX_ERROR),
9353 : : errmsg("missing argument"),
9354 : : errhint("Use NONE to denote the missing argument of a unary operator."),
9355 : : parser_errposition(@3)));
9356 : : }
9357 : : | '(' Typename ',' Typename ')'
9358 : 1247 : { $$ = list_make2($2, $4); }
9359 : : | '(' NONE ',' Typename ')' /* left unary */
9360 : 20 : { $$ = list_make2(NULL, $4); }
9361 : : | '(' Typename ',' NONE ')' /* right unary */
9362 : 8 : { $$ = list_make2($2, NULL); }
9363 : : ;
9364 : :
9365 : : any_operator:
9366 : : all_Op
9367 : 13268 : { $$ = list_make1(makeString($1)); }
9368 : : | ColId '.' any_operator
9369 : 9838 : { $$ = lcons(makeString($1), $3); }
9370 : : ;
9371 : :
9372 : : operator_with_argtypes_list:
9373 : 144 : operator_with_argtypes { $$ = list_make1($1); }
9374 : : | operator_with_argtypes_list ',' operator_with_argtypes
9375 : 0 : { $$ = lappend($1, $3); }
9376 : : ;
9377 : :
9378 : : operator_with_argtypes:
9379 : : any_operator oper_argtypes
9380 : : {
9381 : 1275 : ObjectWithArgs *n = makeNode(ObjectWithArgs);
9382 : :
9383 : 1275 : n->objname = $1;
9384 : 1275 : n->objargs = $2;
9385 : 1275 : $$ = n;
9386 : : }
9387 : : ;
9388 : :
9389 : : /*****************************************************************************
9390 : : *
9391 : : * DO <anonymous code block> [ LANGUAGE language ]
9392 : : *
9393 : : * We use a DefElem list for future extensibility, and to allow flexibility
9394 : : * in the clause order.
9395 : : *
9396 : : *****************************************************************************/
9397 : :
9398 : : DoStmt: DO dostmt_opt_list
9399 : : {
9400 : 679 : DoStmt *n = makeNode(DoStmt);
9401 : :
9402 : 679 : n->args = $2;
9403 : 679 : $$ = (Node *) n;
9404 : : }
9405 : : ;
9406 : :
9407 : : dostmt_opt_list:
9408 : 679 : dostmt_opt_item { $$ = list_make1($1); }
9409 : 102 : | dostmt_opt_list dostmt_opt_item { $$ = lappend($1, $2); }
9410 : : ;
9411 : :
9412 : : dostmt_opt_item:
9413 : : Sconst
9414 : : {
9415 : 679 : $$ = makeDefElem("as", (Node *) makeString($1), @1);
9416 : : }
9417 : : | LANGUAGE NonReservedWord_or_Sconst
9418 : : {
9419 : 102 : $$ = makeDefElem("language", (Node *) makeString($2), @1);
9420 : : }
9421 : : ;
9422 : :
9423 : : /*****************************************************************************
9424 : : *
9425 : : * CREATE CAST / DROP CAST
9426 : : *
9427 : : *****************************************************************************/
9428 : :
9429 : : CreateCastStmt: CREATE CAST '(' Typename AS Typename ')'
9430 : : WITH FUNCTION function_with_argtypes cast_context
9431 : : {
9432 : 66 : CreateCastStmt *n = makeNode(CreateCastStmt);
9433 : :
9434 : 66 : n->sourcetype = $4;
9435 : 66 : n->targettype = $6;
9436 : 66 : n->func = $10;
9437 : 66 : n->context = (CoercionContext) $11;
9438 : 66 : n->inout = false;
9439 : 66 : $$ = (Node *) n;
9440 : : }
9441 : : | CREATE CAST '(' Typename AS Typename ')'
9442 : : WITHOUT FUNCTION cast_context
9443 : : {
9444 : 101 : CreateCastStmt *n = makeNode(CreateCastStmt);
9445 : :
9446 : 101 : n->sourcetype = $4;
9447 : 101 : n->targettype = $6;
9448 : 101 : n->func = NULL;
9449 : 101 : n->context = (CoercionContext) $10;
9450 : 101 : n->inout = false;
9451 : 101 : $$ = (Node *) n;
9452 : : }
9453 : : | CREATE CAST '(' Typename AS Typename ')'
9454 : : WITH INOUT cast_context
9455 : : {
9456 : 5 : CreateCastStmt *n = makeNode(CreateCastStmt);
9457 : :
9458 : 5 : n->sourcetype = $4;
9459 : 5 : n->targettype = $6;
9460 : 5 : n->func = NULL;
9461 : 5 : n->context = (CoercionContext) $10;
9462 : 5 : n->inout = true;
9463 : 5 : $$ = (Node *) n;
9464 : : }
9465 : : ;
9466 : :
9467 : 31 : cast_context: AS IMPLICIT_P { $$ = COERCION_IMPLICIT; }
9468 : 30 : | AS ASSIGNMENT { $$ = COERCION_ASSIGNMENT; }
9469 : 111 : | /*EMPTY*/ { $$ = COERCION_EXPLICIT; }
9470 : : ;
9471 : :
9472 : :
9473 : : DropCastStmt: DROP CAST opt_if_exists '(' Typename AS Typename ')' opt_drop_behavior
9474 : : {
9475 : 46 : DropStmt *n = makeNode(DropStmt);
9476 : :
9477 : 46 : n->removeType = OBJECT_CAST;
9478 : 46 : n->objects = list_make1(list_make2($5, $7));
9479 : 46 : n->behavior = $9;
9480 : 46 : n->missing_ok = $3;
9481 : 46 : n->concurrent = false;
9482 : 46 : $$ = (Node *) n;
9483 : : }
9484 : : ;
9485 : :
9486 : 23 : opt_if_exists: IF_P EXISTS { $$ = true; }
9487 : 30 : | /*EMPTY*/ { $$ = false; }
9488 : : ;
9489 : :
9490 : :
9491 : : /*****************************************************************************
9492 : : *
9493 : : * CREATE PROPERTY GRAPH
9494 : : * ALTER PROPERTY GRAPH
9495 : : *
9496 : : *****************************************************************************/
9497 : :
9498 : : CreatePropGraphStmt: CREATE OptTemp PROPERTY GRAPH qualified_name opt_vertex_tables_clause opt_edge_tables_clause
9499 : : {
9500 : 210 : CreatePropGraphStmt *n = makeNode(CreatePropGraphStmt);
9501 : :
9502 : 210 : n->pgname = $5;
9503 : 210 : n->pgname->relpersistence = $2;
9504 : 210 : n->vertex_tables = $6;
9505 : 210 : n->edge_tables = $7;
9506 : :
9507 : 210 : $$ = (Node *)n;
9508 : : }
9509 : : ;
9510 : :
9511 : : opt_vertex_tables_clause:
9512 : 173 : vertex_tables_clause { $$ = $1; }
9513 : 37 : | /*EMPTY*/ { $$ = NIL; }
9514 : : ;
9515 : :
9516 : : vertex_tables_clause:
9517 : 205 : vertex_synonym TABLES '(' vertex_table_list ')' { $$ = $4; }
9518 : : ;
9519 : :
9520 : : vertex_synonym: NODE | VERTEX
9521 : : ;
9522 : :
9523 : 205 : vertex_table_list: vertex_table_definition { $$ = list_make1($1); }
9524 : 206 : | vertex_table_list ',' vertex_table_definition { $$ = lappend($1, $3); }
9525 : : ;
9526 : :
9527 : : vertex_table_definition: qualified_name opt_propgraph_table_alias opt_graph_table_key_clause
9528 : : opt_element_table_label_and_properties
9529 : : {
9530 : 411 : PropGraphVertex *n = makeNode(PropGraphVertex);
9531 : :
9532 : 411 : $1->alias = $2;
9533 : 411 : n->vtable = $1;
9534 : 411 : n->vkey = $3;
9535 : 411 : n->labels = $4;
9536 : 411 : n->location = @1;
9537 : :
9538 : 411 : $$ = (Node *) n;
9539 : : }
9540 : : ;
9541 : :
9542 : : opt_propgraph_table_alias:
9543 : : AS name
9544 : : {
9545 : 12 : $$ = makeNode(Alias);
9546 : 12 : $$->aliasname = $2;
9547 : : }
9548 : 616 : | /*EMPTY*/ { $$ = NULL; }
9549 : : ;
9550 : :
9551 : : opt_graph_table_key_clause:
9552 : 484 : KEY '(' columnList ')' { $$ = $3; }
9553 : 144 : | /*EMPTY*/ { $$ = NIL; }
9554 : : ;
9555 : :
9556 : : opt_edge_tables_clause:
9557 : 114 : edge_tables_clause { $$ = $1; }
9558 : 96 : | /*EMPTY*/ { $$ = NIL; }
9559 : : ;
9560 : :
9561 : : edge_tables_clause:
9562 : 142 : edge_synonym TABLES '(' edge_table_list ')' { $$ = $4; }
9563 : : ;
9564 : :
9565 : : edge_synonym: EDGE | RELATIONSHIP
9566 : : ;
9567 : :
9568 : 142 : edge_table_list: edge_table_definition { $$ = list_make1($1); }
9569 : 75 : | edge_table_list ',' edge_table_definition { $$ = lappend($1, $3); }
9570 : : ;
9571 : :
9572 : : edge_table_definition: qualified_name opt_propgraph_table_alias opt_graph_table_key_clause
9573 : : source_vertex_table destination_vertex_table opt_element_table_label_and_properties
9574 : : {
9575 : 217 : PropGraphEdge *n = makeNode(PropGraphEdge);
9576 : :
9577 : 217 : $1->alias = $2;
9578 : 217 : n->etable = $1;
9579 : 217 : n->ekey = $3;
9580 : 217 : n->esrckey = linitial($4);
9581 : 217 : n->esrcvertex = lsecond($4);
9582 : 217 : n->esrcvertexcols = lthird($4);
9583 : 217 : n->edestkey = linitial($5);
9584 : 217 : n->edestvertex = lsecond($5);
9585 : 217 : n->edestvertexcols = lthird($5);
9586 : 217 : n->labels = $6;
9587 : 217 : n->location = @1;
9588 : :
9589 : 217 : $$ = (Node *) n;
9590 : : }
9591 : : ;
9592 : :
9593 : : source_vertex_table: SOURCE name
9594 : : {
9595 : 20 : $$ = list_make3(NULL, $2, NULL);
9596 : : }
9597 : : | SOURCE KEY '(' columnList ')' REFERENCES name '(' columnList ')'
9598 : : {
9599 : 197 : $$ = list_make3($4, $7, $9);
9600 : : }
9601 : : ;
9602 : :
9603 : : destination_vertex_table: DESTINATION name
9604 : : {
9605 : 20 : $$ = list_make3(NULL, $2, NULL);
9606 : : }
9607 : : | DESTINATION KEY '(' columnList ')' REFERENCES name '(' columnList ')'
9608 : : {
9609 : 197 : $$ = list_make3($4, $7, $9);
9610 : : }
9611 : : ;
9612 : :
9613 : : opt_element_table_label_and_properties:
9614 : : element_table_properties
9615 : : {
9616 : 77 : PropGraphLabelAndProperties *lp = makeNode(PropGraphLabelAndProperties);
9617 : :
9618 : 77 : lp->properties = (PropGraphProperties *) $1;
9619 : 77 : lp->location = @1;
9620 : :
9621 : 77 : $$ = list_make1(lp);
9622 : : }
9623 : : | label_and_properties_list
9624 : : {
9625 : 245 : $$ = $1;
9626 : : }
9627 : : | /*EMPTY*/
9628 : : {
9629 : 306 : PropGraphLabelAndProperties *lp = makeNode(PropGraphLabelAndProperties);
9630 : 306 : PropGraphProperties *pr = makeNode(PropGraphProperties);
9631 : :
9632 : 306 : pr->all = true;
9633 : 306 : pr->location = -1;
9634 : 306 : lp->properties = pr;
9635 : 306 : lp->location = -1;
9636 : :
9637 : 306 : $$ = list_make1(lp);
9638 : : }
9639 : : ;
9640 : :
9641 : : element_table_properties:
9642 : : NO PROPERTIES
9643 : : {
9644 : 5 : PropGraphProperties *pr = makeNode(PropGraphProperties);
9645 : :
9646 : 5 : pr->properties = NIL;
9647 : 5 : pr->location = @1;
9648 : :
9649 : 5 : $$ = (Node *) pr;
9650 : : }
9651 : : | PROPERTIES ALL COLUMNS
9652 : : /*
9653 : : * SQL standard also allows "PROPERTIES ARE ALL COLUMNS", but that
9654 : : * would require making ARE a keyword, which seems a bit much for
9655 : : * such a marginal use. Could be added later if needed.
9656 : : */
9657 : : {
9658 : 20 : PropGraphProperties *pr = makeNode(PropGraphProperties);
9659 : :
9660 : 20 : pr->all = true;
9661 : 20 : pr->location = @1;
9662 : :
9663 : 20 : $$ = (Node *) pr;
9664 : : }
9665 : : | PROPERTIES '(' labeled_expr_list ')'
9666 : : {
9667 : 384 : PropGraphProperties *pr = makeNode(PropGraphProperties);
9668 : :
9669 : 384 : pr->properties = $3;
9670 : 384 : pr->location = @1;
9671 : :
9672 : 384 : $$ = (Node *) pr;
9673 : : }
9674 : : ;
9675 : :
9676 : : label_and_properties_list:
9677 : : label_and_properties
9678 : : {
9679 : 245 : $$ = list_make1($1);
9680 : : }
9681 : : | label_and_properties_list label_and_properties
9682 : : {
9683 : 115 : $$ = lappend($1, $2);
9684 : : }
9685 : : ;
9686 : :
9687 : : label_and_properties:
9688 : : element_table_label_clause
9689 : : {
9690 : 60 : PropGraphLabelAndProperties *lp = makeNode(PropGraphLabelAndProperties);
9691 : 60 : PropGraphProperties *pr = makeNode(PropGraphProperties);
9692 : :
9693 : 60 : pr->all = true;
9694 : 60 : pr->location = -1;
9695 : :
9696 : 60 : lp->label = $1;
9697 : 60 : lp->properties = pr;
9698 : 60 : lp->location = @1;
9699 : :
9700 : 60 : $$ = (Node *) lp;
9701 : : }
9702 : : | element_table_label_clause element_table_properties
9703 : : {
9704 : 300 : PropGraphLabelAndProperties *lp = makeNode(PropGraphLabelAndProperties);
9705 : :
9706 : 300 : lp->label = $1;
9707 : 300 : lp->properties = (PropGraphProperties *) $2;
9708 : 300 : lp->location = @1;
9709 : :
9710 : 300 : $$ = (Node *) lp;
9711 : : }
9712 : : ;
9713 : :
9714 : : element_table_label_clause:
9715 : : LABEL name
9716 : : {
9717 : 272 : $$ = $2;
9718 : : }
9719 : : | DEFAULT LABEL
9720 : : {
9721 : 88 : $$ = NULL;
9722 : : }
9723 : : ;
9724 : :
9725 : : AlterPropGraphStmt:
9726 : : ALTER PROPERTY GRAPH qualified_name ADD_P vertex_tables_clause
9727 : : {
9728 : 28 : AlterPropGraphStmt *n = makeNode(AlterPropGraphStmt);
9729 : :
9730 : 28 : n->pgname = $4;
9731 : 28 : n->add_vertex_tables = $6;
9732 : :
9733 : 28 : $$ = (Node *) n;
9734 : : }
9735 : : | ALTER PROPERTY GRAPH qualified_name ADD_P vertex_tables_clause ADD_P edge_tables_clause
9736 : : {
9737 : 4 : AlterPropGraphStmt *n = makeNode(AlterPropGraphStmt);
9738 : :
9739 : 4 : n->pgname = $4;
9740 : 4 : n->add_vertex_tables = $6;
9741 : 4 : n->add_edge_tables = $8;
9742 : :
9743 : 4 : $$ = (Node *) n;
9744 : : }
9745 : : | ALTER PROPERTY GRAPH qualified_name ADD_P edge_tables_clause
9746 : : {
9747 : 24 : AlterPropGraphStmt *n = makeNode(AlterPropGraphStmt);
9748 : :
9749 : 24 : n->pgname = $4;
9750 : 24 : n->add_edge_tables = $6;
9751 : :
9752 : 24 : $$ = (Node *) n;
9753 : : }
9754 : : | ALTER PROPERTY GRAPH qualified_name DROP vertex_synonym TABLES '(' name_list ')' opt_drop_behavior
9755 : : {
9756 : 8 : AlterPropGraphStmt *n = makeNode(AlterPropGraphStmt);
9757 : :
9758 : 8 : n->pgname = $4;
9759 : 8 : n->drop_vertex_tables = $9;
9760 : 8 : n->drop_behavior = $11;
9761 : :
9762 : 8 : $$ = (Node *) n;
9763 : : }
9764 : : | ALTER PROPERTY GRAPH qualified_name DROP edge_synonym TABLES '(' name_list ')' opt_drop_behavior
9765 : : {
9766 : 8 : AlterPropGraphStmt *n = makeNode(AlterPropGraphStmt);
9767 : :
9768 : 8 : n->pgname = $4;
9769 : 8 : n->drop_edge_tables = $9;
9770 : 8 : n->drop_behavior = $11;
9771 : :
9772 : 8 : $$ = (Node *) n;
9773 : : }
9774 : : | ALTER PROPERTY GRAPH qualified_name ALTER vertex_or_edge TABLE name
9775 : : add_label_list
9776 : : {
9777 : 28 : AlterPropGraphStmt *n = makeNode(AlterPropGraphStmt);
9778 : :
9779 : 28 : n->pgname = $4;
9780 : 28 : n->element_kind = $6;
9781 : 28 : n->element_alias = $8;
9782 : 28 : n->add_labels = $9;
9783 : :
9784 : 28 : $$ = (Node *) n;
9785 : : }
9786 : : | ALTER PROPERTY GRAPH qualified_name ALTER vertex_or_edge TABLE name
9787 : : DROP LABEL name opt_drop_behavior
9788 : : {
9789 : 28 : AlterPropGraphStmt *n = makeNode(AlterPropGraphStmt);
9790 : :
9791 : 28 : n->pgname = $4;
9792 : 28 : n->element_kind = $6;
9793 : 28 : n->element_alias = $8;
9794 : 28 : n->drop_label = $11;
9795 : 28 : n->drop_behavior = $12;
9796 : :
9797 : 28 : $$ = (Node *) n;
9798 : : }
9799 : : | ALTER PROPERTY GRAPH qualified_name ALTER vertex_or_edge TABLE name
9800 : : ALTER LABEL name ADD_P PROPERTIES '(' labeled_expr_list ')'
9801 : : {
9802 : 8 : AlterPropGraphStmt *n = makeNode(AlterPropGraphStmt);
9803 : 8 : PropGraphProperties *pr = makeNode(PropGraphProperties);
9804 : :
9805 : 8 : n->pgname = $4;
9806 : 8 : n->element_kind = $6;
9807 : 8 : n->element_alias = $8;
9808 : 8 : n->alter_label = $11;
9809 : :
9810 : 8 : pr->properties = $15;
9811 : 8 : pr->location = @13;
9812 : 8 : n->add_properties = pr;
9813 : :
9814 : 8 : $$ = (Node *) n;
9815 : : }
9816 : : | ALTER PROPERTY GRAPH qualified_name ALTER vertex_or_edge TABLE name
9817 : : ALTER LABEL name DROP PROPERTIES '(' name_list ')' opt_drop_behavior
9818 : : {
9819 : 24 : AlterPropGraphStmt *n = makeNode(AlterPropGraphStmt);
9820 : :
9821 : 24 : n->pgname = $4;
9822 : 24 : n->element_kind = $6;
9823 : 24 : n->element_alias = $8;
9824 : 24 : n->alter_label = $11;
9825 : 24 : n->drop_properties = $15;
9826 : 24 : n->drop_behavior = $17;
9827 : :
9828 : 24 : $$ = (Node *) n;
9829 : : }
9830 : : ;
9831 : :
9832 : : vertex_or_edge:
9833 : 76 : vertex_synonym { $$ = PROPGRAPH_ELEMENT_KIND_VERTEX; }
9834 : 12 : | edge_synonym { $$ = PROPGRAPH_ELEMENT_KIND_EDGE; }
9835 : : ;
9836 : :
9837 : : add_label_list:
9838 : 28 : add_label { $$ = list_make1($1); }
9839 : 4 : | add_label_list add_label { $$ = lappend($1, $2); }
9840 : : ;
9841 : :
9842 : : add_label: ADD_P LABEL name element_table_properties
9843 : : {
9844 : 32 : PropGraphLabelAndProperties *lp = makeNode(PropGraphLabelAndProperties);
9845 : :
9846 : 32 : lp->label = $3;
9847 : 32 : lp->properties = (PropGraphProperties *) $4;
9848 : 32 : lp->location = @1;
9849 : :
9850 : 32 : $$ = (Node *) lp;
9851 : : }
9852 : : ;
9853 : :
9854 : :
9855 : : /*****************************************************************************
9856 : : *
9857 : : * CREATE TRANSFORM / DROP TRANSFORM
9858 : : *
9859 : : *****************************************************************************/
9860 : :
9861 : : CreateTransformStmt: CREATE opt_or_replace TRANSFORM FOR Typename LANGUAGE name '(' transform_element_list ')'
9862 : : {
9863 : 26 : CreateTransformStmt *n = makeNode(CreateTransformStmt);
9864 : :
9865 : 26 : n->replace = $2;
9866 : 26 : n->type_name = $5;
9867 : 26 : n->lang = $7;
9868 : 26 : n->fromsql = linitial($9);
9869 : 26 : n->tosql = lsecond($9);
9870 : 26 : $$ = (Node *) n;
9871 : : }
9872 : : ;
9873 : :
9874 : : transform_element_list: FROM SQL_P WITH FUNCTION function_with_argtypes ',' TO SQL_P WITH FUNCTION function_with_argtypes
9875 : : {
9876 : 23 : $$ = list_make2($5, $11);
9877 : : }
9878 : : | TO SQL_P WITH FUNCTION function_with_argtypes ',' FROM SQL_P WITH FUNCTION function_with_argtypes
9879 : : {
9880 : 0 : $$ = list_make2($11, $5);
9881 : : }
9882 : : | FROM SQL_P WITH FUNCTION function_with_argtypes
9883 : : {
9884 : 2 : $$ = list_make2($5, NULL);
9885 : : }
9886 : : | TO SQL_P WITH FUNCTION function_with_argtypes
9887 : : {
9888 : 1 : $$ = list_make2(NULL, $5);
9889 : : }
9890 : : ;
9891 : :
9892 : :
9893 : : DropTransformStmt: DROP TRANSFORM opt_if_exists FOR Typename LANGUAGE name opt_drop_behavior
9894 : : {
9895 : 7 : DropStmt *n = makeNode(DropStmt);
9896 : :
9897 : 7 : n->removeType = OBJECT_TRANSFORM;
9898 : 7 : n->objects = list_make1(list_make2($5, makeString($7)));
9899 : 7 : n->behavior = $8;
9900 : 7 : n->missing_ok = $3;
9901 : 7 : $$ = (Node *) n;
9902 : : }
9903 : : ;
9904 : :
9905 : :
9906 : : /*****************************************************************************
9907 : : *
9908 : : * QUERY:
9909 : : *
9910 : : * REINDEX [ (options) ] {INDEX | TABLE | SCHEMA} [CONCURRENTLY] <name>
9911 : : * REINDEX [ (options) ] {DATABASE | SYSTEM} [CONCURRENTLY] [<name>]
9912 : : *****************************************************************************/
9913 : :
9914 : : ReindexStmt:
9915 : : REINDEX opt_utility_option_list reindex_target_relation opt_concurrently qualified_name
9916 : : {
9917 : 595 : ReindexStmt *n = makeNode(ReindexStmt);
9918 : :
9919 : 595 : n->kind = $3;
9920 : 595 : n->relation = $5;
9921 : 595 : n->name = NULL;
9922 : 595 : n->params = $2;
9923 [ + + ]: 595 : if ($4)
9924 : 339 : n->params = lappend(n->params,
9925 : 339 : makeDefElem("concurrently", NULL, @4));
9926 : 595 : $$ = (Node *) n;
9927 : : }
9928 : : | REINDEX opt_utility_option_list SCHEMA opt_concurrently name
9929 : : {
9930 : 74 : ReindexStmt *n = makeNode(ReindexStmt);
9931 : :
9932 : 74 : n->kind = REINDEX_OBJECT_SCHEMA;
9933 : 74 : n->relation = NULL;
9934 : 74 : n->name = $5;
9935 : 74 : n->params = $2;
9936 [ + + ]: 74 : if ($4)
9937 : 26 : n->params = lappend(n->params,
9938 : 26 : makeDefElem("concurrently", NULL, @4));
9939 : 74 : $$ = (Node *) n;
9940 : : }
9941 : : | REINDEX opt_utility_option_list reindex_target_all opt_concurrently opt_single_name
9942 : : {
9943 : 36 : ReindexStmt *n = makeNode(ReindexStmt);
9944 : :
9945 : 36 : n->kind = $3;
9946 : 36 : n->relation = NULL;
9947 : 36 : n->name = $5;
9948 : 36 : n->params = $2;
9949 [ + + ]: 36 : if ($4)
9950 : 6 : n->params = lappend(n->params,
9951 : 6 : makeDefElem("concurrently", NULL, @4));
9952 : 36 : $$ = (Node *) n;
9953 : : }
9954 : : ;
9955 : : reindex_target_relation:
9956 : 270 : INDEX { $$ = REINDEX_OBJECT_INDEX; }
9957 : 325 : | TABLE { $$ = REINDEX_OBJECT_TABLE; }
9958 : : ;
9959 : : reindex_target_all:
9960 : 20 : SYSTEM_P { $$ = REINDEX_OBJECT_SYSTEM; }
9961 : 16 : | DATABASE { $$ = REINDEX_OBJECT_DATABASE; }
9962 : : ;
9963 : :
9964 : : /*****************************************************************************
9965 : : *
9966 : : * ALTER TABLESPACE
9967 : : *
9968 : : *****************************************************************************/
9969 : :
9970 : : AlterTblSpcStmt:
9971 : : ALTER TABLESPACE name SET reloptions
9972 : : {
9973 : : AlterTableSpaceOptionsStmt *n =
9974 : 9 : makeNode(AlterTableSpaceOptionsStmt);
9975 : :
9976 : 9 : n->tablespacename = $3;
9977 : 9 : n->options = $5;
9978 : 9 : n->isReset = false;
9979 : 9 : $$ = (Node *) n;
9980 : : }
9981 : : | ALTER TABLESPACE name RESET reloptions
9982 : : {
9983 : : AlterTableSpaceOptionsStmt *n =
9984 : 8 : makeNode(AlterTableSpaceOptionsStmt);
9985 : :
9986 : 8 : n->tablespacename = $3;
9987 : 8 : n->options = $5;
9988 : 8 : n->isReset = true;
9989 : 8 : $$ = (Node *) n;
9990 : : }
9991 : : ;
9992 : :
9993 : : /*****************************************************************************
9994 : : *
9995 : : * ALTER THING name RENAME TO newname
9996 : : *
9997 : : *****************************************************************************/
9998 : :
9999 : : RenameStmt: ALTER AGGREGATE aggregate_with_argtypes RENAME TO name
10000 : : {
10001 : 28 : RenameStmt *n = makeNode(RenameStmt);
10002 : :
10003 : 28 : n->renameType = OBJECT_AGGREGATE;
10004 : 28 : n->object = (Node *) $3;
10005 : 28 : n->newname = $6;
10006 : 28 : n->missing_ok = false;
10007 : 28 : $$ = (Node *) n;
10008 : : }
10009 : : | ALTER COLLATION any_name RENAME TO name
10010 : : {
10011 : 12 : RenameStmt *n = makeNode(RenameStmt);
10012 : :
10013 : 12 : n->renameType = OBJECT_COLLATION;
10014 : 12 : n->object = (Node *) $3;
10015 : 12 : n->newname = $6;
10016 : 12 : n->missing_ok = false;
10017 : 12 : $$ = (Node *) n;
10018 : : }
10019 : : | ALTER CONVERSION_P any_name RENAME TO name
10020 : : {
10021 : 16 : RenameStmt *n = makeNode(RenameStmt);
10022 : :
10023 : 16 : n->renameType = OBJECT_CONVERSION;
10024 : 16 : n->object = (Node *) $3;
10025 : 16 : n->newname = $6;
10026 : 16 : n->missing_ok = false;
10027 : 16 : $$ = (Node *) n;
10028 : : }
10029 : : | ALTER DATABASE name RENAME TO name
10030 : : {
10031 : 9 : RenameStmt *n = makeNode(RenameStmt);
10032 : :
10033 : 9 : n->renameType = OBJECT_DATABASE;
10034 : 9 : n->subname = $3;
10035 : 9 : n->newname = $6;
10036 : 9 : n->missing_ok = false;
10037 : 9 : $$ = (Node *) n;
10038 : : }
10039 : : | ALTER DOMAIN_P any_name RENAME TO name
10040 : : {
10041 : 4 : RenameStmt *n = makeNode(RenameStmt);
10042 : :
10043 : 4 : n->renameType = OBJECT_DOMAIN;
10044 : 4 : n->object = (Node *) $3;
10045 : 4 : n->newname = $6;
10046 : 4 : n->missing_ok = false;
10047 : 4 : $$ = (Node *) n;
10048 : : }
10049 : : | ALTER DOMAIN_P any_name RENAME CONSTRAINT name TO name
10050 : : {
10051 : 4 : RenameStmt *n = makeNode(RenameStmt);
10052 : :
10053 : 4 : n->renameType = OBJECT_DOMCONSTRAINT;
10054 : 4 : n->object = (Node *) $3;
10055 : 4 : n->subname = $6;
10056 : 4 : n->newname = $8;
10057 : 4 : $$ = (Node *) n;
10058 : : }
10059 : : | ALTER FOREIGN DATA_P WRAPPER name RENAME TO name
10060 : : {
10061 : 16 : RenameStmt *n = makeNode(RenameStmt);
10062 : :
10063 : 16 : n->renameType = OBJECT_FDW;
10064 : 16 : n->object = (Node *) makeString($5);
10065 : 16 : n->newname = $8;
10066 : 16 : n->missing_ok = false;
10067 : 16 : $$ = (Node *) n;
10068 : : }
10069 : : | ALTER FUNCTION function_with_argtypes RENAME TO name
10070 : : {
10071 : 16 : RenameStmt *n = makeNode(RenameStmt);
10072 : :
10073 : 16 : n->renameType = OBJECT_FUNCTION;
10074 : 16 : n->object = (Node *) $3;
10075 : 16 : n->newname = $6;
10076 : 16 : n->missing_ok = false;
10077 : 16 : $$ = (Node *) n;
10078 : : }
10079 : : | ALTER GROUP_P RoleId RENAME TO RoleId
10080 : : {
10081 : 0 : RenameStmt *n = makeNode(RenameStmt);
10082 : :
10083 : 0 : n->renameType = OBJECT_ROLE;
10084 : 0 : n->subname = $3;
10085 : 0 : n->newname = $6;
10086 : 0 : n->missing_ok = false;
10087 : 0 : $$ = (Node *) n;
10088 : : }
10089 : : | ALTER opt_procedural LANGUAGE name RENAME TO name
10090 : : {
10091 : 12 : RenameStmt *n = makeNode(RenameStmt);
10092 : :
10093 : 12 : n->renameType = OBJECT_LANGUAGE;
10094 : 12 : n->object = (Node *) makeString($4);
10095 : 12 : n->newname = $7;
10096 : 12 : n->missing_ok = false;
10097 : 12 : $$ = (Node *) n;
10098 : : }
10099 : : | ALTER OPERATOR CLASS any_name USING name RENAME TO name
10100 : : {
10101 : 16 : RenameStmt *n = makeNode(RenameStmt);
10102 : :
10103 : 16 : n->renameType = OBJECT_OPCLASS;
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 OPERATOR FAMILY any_name USING name RENAME TO name
10110 : : {
10111 : 16 : RenameStmt *n = makeNode(RenameStmt);
10112 : :
10113 : 16 : n->renameType = OBJECT_OPFAMILY;
10114 : 16 : n->object = (Node *) lcons(makeString($6), $4);
10115 : 16 : n->newname = $9;
10116 : 16 : n->missing_ok = false;
10117 : 16 : $$ = (Node *) n;
10118 : : }
10119 : : | ALTER POLICY name ON qualified_name RENAME TO name
10120 : : {
10121 : 12 : RenameStmt *n = makeNode(RenameStmt);
10122 : :
10123 : 12 : n->renameType = OBJECT_POLICY;
10124 : 12 : n->relation = $5;
10125 : 12 : n->subname = $3;
10126 : 12 : n->newname = $8;
10127 : 12 : n->missing_ok = false;
10128 : 12 : $$ = (Node *) n;
10129 : : }
10130 : : | ALTER POLICY IF_P EXISTS name ON qualified_name RENAME TO name
10131 : : {
10132 : 0 : RenameStmt *n = makeNode(RenameStmt);
10133 : :
10134 : 0 : n->renameType = OBJECT_POLICY;
10135 : 0 : n->relation = $7;
10136 : 0 : n->subname = $5;
10137 : 0 : n->newname = $10;
10138 : 0 : n->missing_ok = true;
10139 : 0 : $$ = (Node *) n;
10140 : : }
10141 : : | ALTER PROCEDURE function_with_argtypes RENAME TO name
10142 : : {
10143 : 0 : RenameStmt *n = makeNode(RenameStmt);
10144 : :
10145 : 0 : n->renameType = OBJECT_PROCEDURE;
10146 : 0 : n->object = (Node *) $3;
10147 : 0 : n->newname = $6;
10148 : 0 : n->missing_ok = false;
10149 : 0 : $$ = (Node *) n;
10150 : : }
10151 : : | ALTER PROPERTY GRAPH qualified_name RENAME TO name
10152 : : {
10153 : 24 : RenameStmt *n = makeNode(RenameStmt);
10154 : :
10155 : 24 : n->renameType = OBJECT_PROPGRAPH;
10156 : 24 : n->relation = $4;
10157 : 24 : n->newname = $7;
10158 : 24 : n->missing_ok = false;
10159 : 24 : $$ = (Node *)n;
10160 : : }
10161 : : | ALTER PUBLICATION name RENAME TO name
10162 : : {
10163 : 24 : RenameStmt *n = makeNode(RenameStmt);
10164 : :
10165 : 24 : n->renameType = OBJECT_PUBLICATION;
10166 : 24 : n->object = (Node *) makeString($3);
10167 : 24 : n->newname = $6;
10168 : 24 : n->missing_ok = false;
10169 : 24 : $$ = (Node *) n;
10170 : : }
10171 : : | ALTER ROUTINE function_with_argtypes RENAME TO name
10172 : : {
10173 : 16 : RenameStmt *n = makeNode(RenameStmt);
10174 : :
10175 : 16 : n->renameType = OBJECT_ROUTINE;
10176 : 16 : n->object = (Node *) $3;
10177 : 16 : n->newname = $6;
10178 : 16 : n->missing_ok = false;
10179 : 16 : $$ = (Node *) n;
10180 : : }
10181 : : | ALTER SCHEMA name RENAME TO name
10182 : : {
10183 : 13 : RenameStmt *n = makeNode(RenameStmt);
10184 : :
10185 : 13 : n->renameType = OBJECT_SCHEMA;
10186 : 13 : n->subname = $3;
10187 : 13 : n->newname = $6;
10188 : 13 : n->missing_ok = false;
10189 : 13 : $$ = (Node *) n;
10190 : : }
10191 : : | ALTER SERVER name RENAME TO name
10192 : : {
10193 : 16 : RenameStmt *n = makeNode(RenameStmt);
10194 : :
10195 : 16 : n->renameType = OBJECT_FOREIGN_SERVER;
10196 : 16 : n->object = (Node *) makeString($3);
10197 : 16 : n->newname = $6;
10198 : 16 : n->missing_ok = false;
10199 : 16 : $$ = (Node *) n;
10200 : : }
10201 : : | ALTER SUBSCRIPTION name RENAME TO name
10202 : : {
10203 : 25 : RenameStmt *n = makeNode(RenameStmt);
10204 : :
10205 : 25 : n->renameType = OBJECT_SUBSCRIPTION;
10206 : 25 : n->object = (Node *) makeString($3);
10207 : 25 : n->newname = $6;
10208 : 25 : n->missing_ok = false;
10209 : 25 : $$ = (Node *) n;
10210 : : }
10211 : : | ALTER TABLE relation_expr RENAME TO name
10212 : : {
10213 : 174 : RenameStmt *n = makeNode(RenameStmt);
10214 : :
10215 : 174 : n->renameType = OBJECT_TABLE;
10216 : 174 : n->relation = $3;
10217 : 174 : n->subname = NULL;
10218 : 174 : n->newname = $6;
10219 : 174 : n->missing_ok = false;
10220 : 174 : $$ = (Node *) n;
10221 : : }
10222 : : | ALTER TABLE IF_P EXISTS relation_expr RENAME TO name
10223 : : {
10224 : 0 : RenameStmt *n = makeNode(RenameStmt);
10225 : :
10226 : 0 : n->renameType = OBJECT_TABLE;
10227 : 0 : n->relation = $5;
10228 : 0 : n->subname = NULL;
10229 : 0 : n->newname = $8;
10230 : 0 : n->missing_ok = true;
10231 : 0 : $$ = (Node *) n;
10232 : : }
10233 : : | ALTER SEQUENCE qualified_name RENAME TO name
10234 : : {
10235 : 1 : RenameStmt *n = makeNode(RenameStmt);
10236 : :
10237 : 1 : n->renameType = OBJECT_SEQUENCE;
10238 : 1 : n->relation = $3;
10239 : 1 : n->subname = NULL;
10240 : 1 : n->newname = $6;
10241 : 1 : n->missing_ok = false;
10242 : 1 : $$ = (Node *) n;
10243 : : }
10244 : : | ALTER SEQUENCE IF_P EXISTS qualified_name RENAME TO name
10245 : : {
10246 : 0 : RenameStmt *n = makeNode(RenameStmt);
10247 : :
10248 : 0 : n->renameType = OBJECT_SEQUENCE;
10249 : 0 : n->relation = $5;
10250 : 0 : n->subname = NULL;
10251 : 0 : n->newname = $8;
10252 : 0 : n->missing_ok = true;
10253 : 0 : $$ = (Node *) n;
10254 : : }
10255 : : | ALTER VIEW qualified_name RENAME TO name
10256 : : {
10257 : 4 : RenameStmt *n = makeNode(RenameStmt);
10258 : :
10259 : 4 : n->renameType = OBJECT_VIEW;
10260 : 4 : n->relation = $3;
10261 : 4 : n->subname = NULL;
10262 : 4 : n->newname = $6;
10263 : 4 : n->missing_ok = false;
10264 : 4 : $$ = (Node *) n;
10265 : : }
10266 : : | ALTER VIEW IF_P EXISTS qualified_name RENAME TO name
10267 : : {
10268 : 0 : RenameStmt *n = makeNode(RenameStmt);
10269 : :
10270 : 0 : n->renameType = OBJECT_VIEW;
10271 : 0 : n->relation = $5;
10272 : 0 : n->subname = NULL;
10273 : 0 : n->newname = $8;
10274 : 0 : n->missing_ok = true;
10275 : 0 : $$ = (Node *) n;
10276 : : }
10277 : : | ALTER MATERIALIZED VIEW qualified_name RENAME TO name
10278 : : {
10279 : 0 : RenameStmt *n = makeNode(RenameStmt);
10280 : :
10281 : 0 : n->renameType = OBJECT_MATVIEW;
10282 : 0 : n->relation = $4;
10283 : 0 : n->subname = NULL;
10284 : 0 : n->newname = $7;
10285 : 0 : n->missing_ok = false;
10286 : 0 : $$ = (Node *) n;
10287 : : }
10288 : : | ALTER MATERIALIZED VIEW IF_P EXISTS qualified_name RENAME TO name
10289 : : {
10290 : 0 : RenameStmt *n = makeNode(RenameStmt);
10291 : :
10292 : 0 : n->renameType = OBJECT_MATVIEW;
10293 : 0 : n->relation = $6;
10294 : 0 : n->subname = NULL;
10295 : 0 : n->newname = $9;
10296 : 0 : n->missing_ok = true;
10297 : 0 : $$ = (Node *) n;
10298 : : }
10299 : : | ALTER INDEX qualified_name RENAME TO name
10300 : : {
10301 : 108 : RenameStmt *n = makeNode(RenameStmt);
10302 : :
10303 : 108 : n->renameType = OBJECT_INDEX;
10304 : 108 : n->relation = $3;
10305 : 108 : n->subname = NULL;
10306 : 108 : n->newname = $6;
10307 : 108 : n->missing_ok = false;
10308 : 108 : $$ = (Node *) n;
10309 : : }
10310 : : | ALTER INDEX IF_P EXISTS qualified_name RENAME TO name
10311 : : {
10312 : 8 : RenameStmt *n = makeNode(RenameStmt);
10313 : :
10314 : 8 : n->renameType = OBJECT_INDEX;
10315 : 8 : n->relation = $5;
10316 : 8 : n->subname = NULL;
10317 : 8 : n->newname = $8;
10318 : 8 : n->missing_ok = true;
10319 : 8 : $$ = (Node *) n;
10320 : : }
10321 : : | ALTER FOREIGN TABLE relation_expr RENAME TO name
10322 : : {
10323 : 4 : RenameStmt *n = makeNode(RenameStmt);
10324 : :
10325 : 4 : n->renameType = OBJECT_FOREIGN_TABLE;
10326 : 4 : n->relation = $4;
10327 : 4 : n->subname = NULL;
10328 : 4 : n->newname = $7;
10329 : 4 : n->missing_ok = false;
10330 : 4 : $$ = (Node *) n;
10331 : : }
10332 : : | ALTER FOREIGN TABLE IF_P EXISTS relation_expr RENAME TO name
10333 : : {
10334 : 4 : RenameStmt *n = makeNode(RenameStmt);
10335 : :
10336 : 4 : n->renameType = OBJECT_FOREIGN_TABLE;
10337 : 4 : n->relation = $6;
10338 : 4 : n->subname = NULL;
10339 : 4 : n->newname = $9;
10340 : 4 : n->missing_ok = true;
10341 : 4 : $$ = (Node *) n;
10342 : : }
10343 : : | ALTER TABLE relation_expr RENAME opt_column name TO name
10344 : : {
10345 : 162 : RenameStmt *n = makeNode(RenameStmt);
10346 : :
10347 : 162 : n->renameType = OBJECT_COLUMN;
10348 : 162 : n->relationType = OBJECT_TABLE;
10349 : 162 : n->relation = $3;
10350 : 162 : n->subname = $6;
10351 : 162 : n->newname = $8;
10352 : 162 : n->missing_ok = false;
10353 : 162 : $$ = (Node *) n;
10354 : : }
10355 : : | ALTER TABLE IF_P EXISTS relation_expr RENAME opt_column name TO name
10356 : : {
10357 : 16 : RenameStmt *n = makeNode(RenameStmt);
10358 : :
10359 : 16 : n->renameType = OBJECT_COLUMN;
10360 : 16 : n->relationType = OBJECT_TABLE;
10361 : 16 : n->relation = $5;
10362 : 16 : n->subname = $8;
10363 : 16 : n->newname = $10;
10364 : 16 : n->missing_ok = true;
10365 : 16 : $$ = (Node *) n;
10366 : : }
10367 : : | ALTER VIEW qualified_name RENAME opt_column name TO name
10368 : : {
10369 : 12 : RenameStmt *n = makeNode(RenameStmt);
10370 : :
10371 : 12 : n->renameType = OBJECT_COLUMN;
10372 : 12 : n->relationType = OBJECT_VIEW;
10373 : 12 : n->relation = $3;
10374 : 12 : n->subname = $6;
10375 : 12 : n->newname = $8;
10376 : 12 : n->missing_ok = false;
10377 : 12 : $$ = (Node *) n;
10378 : : }
10379 : : | ALTER VIEW IF_P EXISTS qualified_name RENAME opt_column name TO name
10380 : : {
10381 : 0 : RenameStmt *n = makeNode(RenameStmt);
10382 : :
10383 : 0 : n->renameType = OBJECT_COLUMN;
10384 : 0 : n->relationType = OBJECT_VIEW;
10385 : 0 : n->relation = $5;
10386 : 0 : n->subname = $8;
10387 : 0 : n->newname = $10;
10388 : 0 : n->missing_ok = true;
10389 : 0 : $$ = (Node *) n;
10390 : : }
10391 : : | ALTER MATERIALIZED VIEW qualified_name RENAME opt_column name TO name
10392 : : {
10393 : 0 : RenameStmt *n = makeNode(RenameStmt);
10394 : :
10395 : 0 : n->renameType = OBJECT_COLUMN;
10396 : 0 : n->relationType = OBJECT_MATVIEW;
10397 : 0 : n->relation = $4;
10398 : 0 : n->subname = $7;
10399 : 0 : n->newname = $9;
10400 : 0 : n->missing_ok = false;
10401 : 0 : $$ = (Node *) n;
10402 : : }
10403 : : | ALTER MATERIALIZED VIEW IF_P EXISTS qualified_name RENAME opt_column name TO name
10404 : : {
10405 : 0 : RenameStmt *n = makeNode(RenameStmt);
10406 : :
10407 : 0 : n->renameType = OBJECT_COLUMN;
10408 : 0 : n->relationType = OBJECT_MATVIEW;
10409 : 0 : n->relation = $6;
10410 : 0 : n->subname = $9;
10411 : 0 : n->newname = $11;
10412 : 0 : n->missing_ok = true;
10413 : 0 : $$ = (Node *) n;
10414 : : }
10415 : : | ALTER TABLE relation_expr RENAME CONSTRAINT name TO name
10416 : : {
10417 : 48 : RenameStmt *n = makeNode(RenameStmt);
10418 : :
10419 : 48 : n->renameType = OBJECT_TABCONSTRAINT;
10420 : 48 : n->relation = $3;
10421 : 48 : n->subname = $6;
10422 : 48 : n->newname = $8;
10423 : 48 : n->missing_ok = false;
10424 : 48 : $$ = (Node *) n;
10425 : : }
10426 : : | ALTER TABLE IF_P EXISTS relation_expr RENAME CONSTRAINT name TO name
10427 : : {
10428 : 4 : RenameStmt *n = makeNode(RenameStmt);
10429 : :
10430 : 4 : n->renameType = OBJECT_TABCONSTRAINT;
10431 : 4 : n->relation = $5;
10432 : 4 : n->subname = $8;
10433 : 4 : n->newname = $10;
10434 : 4 : n->missing_ok = true;
10435 : 4 : $$ = (Node *) n;
10436 : : }
10437 : : | ALTER FOREIGN TABLE relation_expr RENAME opt_column name TO name
10438 : : {
10439 : 4 : RenameStmt *n = makeNode(RenameStmt);
10440 : :
10441 : 4 : n->renameType = OBJECT_COLUMN;
10442 : 4 : n->relationType = OBJECT_FOREIGN_TABLE;
10443 : 4 : n->relation = $4;
10444 : 4 : n->subname = $7;
10445 : 4 : n->newname = $9;
10446 : 4 : n->missing_ok = false;
10447 : 4 : $$ = (Node *) n;
10448 : : }
10449 : : | ALTER FOREIGN TABLE IF_P EXISTS relation_expr RENAME opt_column name TO name
10450 : : {
10451 : 4 : RenameStmt *n = makeNode(RenameStmt);
10452 : :
10453 : 4 : n->renameType = OBJECT_COLUMN;
10454 : 4 : n->relationType = OBJECT_FOREIGN_TABLE;
10455 : 4 : n->relation = $6;
10456 : 4 : n->subname = $9;
10457 : 4 : n->newname = $11;
10458 : 4 : n->missing_ok = true;
10459 : 4 : $$ = (Node *) n;
10460 : : }
10461 : : | ALTER RULE name ON qualified_name RENAME TO name
10462 : : {
10463 : 30 : RenameStmt *n = makeNode(RenameStmt);
10464 : :
10465 : 30 : n->renameType = OBJECT_RULE;
10466 : 30 : n->relation = $5;
10467 : 30 : n->subname = $3;
10468 : 30 : n->newname = $8;
10469 : 30 : n->missing_ok = false;
10470 : 30 : $$ = (Node *) n;
10471 : : }
10472 : : | ALTER TRIGGER name ON qualified_name RENAME TO name
10473 : : {
10474 : 30 : RenameStmt *n = makeNode(RenameStmt);
10475 : :
10476 : 30 : n->renameType = OBJECT_TRIGGER;
10477 : 30 : n->relation = $5;
10478 : 30 : n->subname = $3;
10479 : 30 : n->newname = $8;
10480 : 30 : n->missing_ok = false;
10481 : 30 : $$ = (Node *) n;
10482 : : }
10483 : : | ALTER EVENT TRIGGER name RENAME TO name
10484 : : {
10485 : 8 : RenameStmt *n = makeNode(RenameStmt);
10486 : :
10487 : 8 : n->renameType = OBJECT_EVENT_TRIGGER;
10488 : 8 : n->object = (Node *) makeString($4);
10489 : 8 : n->newname = $7;
10490 : 8 : $$ = (Node *) n;
10491 : : }
10492 : : | ALTER ROLE RoleId RENAME TO RoleId
10493 : : {
10494 : 20 : RenameStmt *n = makeNode(RenameStmt);
10495 : :
10496 : 20 : n->renameType = OBJECT_ROLE;
10497 : 20 : n->subname = $3;
10498 : 20 : n->newname = $6;
10499 : 20 : n->missing_ok = false;
10500 : 20 : $$ = (Node *) n;
10501 : : }
10502 : : | ALTER USER RoleId RENAME TO RoleId
10503 : : {
10504 : 0 : RenameStmt *n = makeNode(RenameStmt);
10505 : :
10506 : 0 : n->renameType = OBJECT_ROLE;
10507 : 0 : n->subname = $3;
10508 : 0 : n->newname = $6;
10509 : 0 : n->missing_ok = false;
10510 : 0 : $$ = (Node *) n;
10511 : : }
10512 : : | ALTER TABLESPACE name RENAME TO name
10513 : : {
10514 : 7 : RenameStmt *n = makeNode(RenameStmt);
10515 : :
10516 : 7 : n->renameType = OBJECT_TABLESPACE;
10517 : 7 : n->subname = $3;
10518 : 7 : n->newname = $6;
10519 : 7 : n->missing_ok = false;
10520 : 7 : $$ = (Node *) n;
10521 : : }
10522 : : | ALTER STATISTICS any_name RENAME TO name
10523 : : {
10524 : 20 : RenameStmt *n = makeNode(RenameStmt);
10525 : :
10526 : 20 : n->renameType = OBJECT_STATISTIC_EXT;
10527 : 20 : n->object = (Node *) $3;
10528 : 20 : n->newname = $6;
10529 : 20 : n->missing_ok = false;
10530 : 20 : $$ = (Node *) n;
10531 : : }
10532 : : | ALTER TEXT_P SEARCH PARSER any_name RENAME TO name
10533 : : {
10534 : 8 : RenameStmt *n = makeNode(RenameStmt);
10535 : :
10536 : 8 : n->renameType = OBJECT_TSPARSER;
10537 : 8 : n->object = (Node *) $5;
10538 : 8 : n->newname = $8;
10539 : 8 : n->missing_ok = false;
10540 : 8 : $$ = (Node *) n;
10541 : : }
10542 : : | ALTER TEXT_P SEARCH DICTIONARY any_name RENAME TO name
10543 : : {
10544 : 16 : RenameStmt *n = makeNode(RenameStmt);
10545 : :
10546 : 16 : n->renameType = OBJECT_TSDICTIONARY;
10547 : 16 : n->object = (Node *) $5;
10548 : 16 : n->newname = $8;
10549 : 16 : n->missing_ok = false;
10550 : 16 : $$ = (Node *) n;
10551 : : }
10552 : : | ALTER TEXT_P SEARCH TEMPLATE any_name RENAME TO name
10553 : : {
10554 : 8 : RenameStmt *n = makeNode(RenameStmt);
10555 : :
10556 : 8 : n->renameType = OBJECT_TSTEMPLATE;
10557 : 8 : n->object = (Node *) $5;
10558 : 8 : n->newname = $8;
10559 : 8 : n->missing_ok = false;
10560 : 8 : $$ = (Node *) n;
10561 : : }
10562 : : | ALTER TEXT_P SEARCH CONFIGURATION any_name RENAME TO name
10563 : : {
10564 : 16 : RenameStmt *n = makeNode(RenameStmt);
10565 : :
10566 : 16 : n->renameType = OBJECT_TSCONFIGURATION;
10567 : 16 : n->object = (Node *) $5;
10568 : 16 : n->newname = $8;
10569 : 16 : n->missing_ok = false;
10570 : 16 : $$ = (Node *) n;
10571 : : }
10572 : : | ALTER TYPE_P any_name RENAME TO name
10573 : : {
10574 : 17 : RenameStmt *n = makeNode(RenameStmt);
10575 : :
10576 : 17 : n->renameType = OBJECT_TYPE;
10577 : 17 : n->object = (Node *) $3;
10578 : 17 : n->newname = $6;
10579 : 17 : n->missing_ok = false;
10580 : 17 : $$ = (Node *) n;
10581 : : }
10582 : : | ALTER TYPE_P any_name RENAME ATTRIBUTE name TO name opt_drop_behavior
10583 : : {
10584 : 16 : RenameStmt *n = makeNode(RenameStmt);
10585 : :
10586 : 16 : n->renameType = OBJECT_ATTRIBUTE;
10587 : 16 : n->relationType = OBJECT_TYPE;
10588 : 16 : n->relation = makeRangeVarFromAnyName($3, @3, yyscanner);
10589 : 16 : n->subname = $6;
10590 : 16 : n->newname = $8;
10591 : 16 : n->behavior = $9;
10592 : 16 : n->missing_ok = false;
10593 : 16 : $$ = (Node *) n;
10594 : : }
10595 : : ;
10596 : :
10597 : : opt_column: COLUMN
10598 : : | /*EMPTY*/
10599 : : ;
10600 : :
10601 : 122 : opt_set_data: SET DATA_P { $$ = 1; }
10602 : 685 : | /*EMPTY*/ { $$ = 0; }
10603 : : ;
10604 : :
10605 : : /*****************************************************************************
10606 : : *
10607 : : * ALTER THING name DEPENDS ON EXTENSION name
10608 : : *
10609 : : *****************************************************************************/
10610 : :
10611 : : AlterObjectDependsStmt:
10612 : : ALTER FUNCTION function_with_argtypes opt_no DEPENDS ON EXTENSION name
10613 : : {
10614 : 6 : AlterObjectDependsStmt *n = makeNode(AlterObjectDependsStmt);
10615 : :
10616 : 6 : n->objectType = OBJECT_FUNCTION;
10617 : 6 : n->object = (Node *) $3;
10618 : 6 : n->extname = makeString($8);
10619 : 6 : n->remove = $4;
10620 : 6 : $$ = (Node *) n;
10621 : : }
10622 : : | ALTER PROCEDURE function_with_argtypes opt_no DEPENDS ON EXTENSION name
10623 : : {
10624 : 0 : AlterObjectDependsStmt *n = makeNode(AlterObjectDependsStmt);
10625 : :
10626 : 0 : n->objectType = OBJECT_PROCEDURE;
10627 : 0 : n->object = (Node *) $3;
10628 : 0 : n->extname = makeString($8);
10629 : 0 : n->remove = $4;
10630 : 0 : $$ = (Node *) n;
10631 : : }
10632 : : | ALTER ROUTINE function_with_argtypes opt_no DEPENDS ON EXTENSION name
10633 : : {
10634 : 0 : AlterObjectDependsStmt *n = makeNode(AlterObjectDependsStmt);
10635 : :
10636 : 0 : n->objectType = OBJECT_ROUTINE;
10637 : 0 : n->object = (Node *) $3;
10638 : 0 : n->extname = makeString($8);
10639 : 0 : n->remove = $4;
10640 : 0 : $$ = (Node *) n;
10641 : : }
10642 : : | ALTER TRIGGER name ON qualified_name opt_no DEPENDS ON EXTENSION name
10643 : : {
10644 : 5 : AlterObjectDependsStmt *n = makeNode(AlterObjectDependsStmt);
10645 : :
10646 : 5 : n->objectType = OBJECT_TRIGGER;
10647 : 5 : n->relation = $5;
10648 : 5 : n->object = (Node *) list_make1(makeString($3));
10649 : 5 : n->extname = makeString($10);
10650 : 5 : n->remove = $6;
10651 : 5 : $$ = (Node *) n;
10652 : : }
10653 : : | ALTER MATERIALIZED VIEW qualified_name opt_no DEPENDS ON EXTENSION name
10654 : : {
10655 : 5 : AlterObjectDependsStmt *n = makeNode(AlterObjectDependsStmt);
10656 : :
10657 : 5 : n->objectType = OBJECT_MATVIEW;
10658 : 5 : n->relation = $4;
10659 : 5 : n->extname = makeString($9);
10660 : 5 : n->remove = $5;
10661 : 5 : $$ = (Node *) n;
10662 : : }
10663 : : | ALTER INDEX qualified_name opt_no DEPENDS ON EXTENSION name
10664 : : {
10665 : 19 : AlterObjectDependsStmt *n = makeNode(AlterObjectDependsStmt);
10666 : :
10667 : 19 : n->objectType = OBJECT_INDEX;
10668 : 19 : n->relation = $3;
10669 : 19 : n->extname = makeString($8);
10670 : 19 : n->remove = $4;
10671 : 19 : $$ = (Node *) n;
10672 : : }
10673 : : ;
10674 : :
10675 : 6 : opt_no: NO { $$ = true; }
10676 : 29 : | /* EMPTY */ { $$ = false; }
10677 : : ;
10678 : :
10679 : : /*****************************************************************************
10680 : : *
10681 : : * ALTER THING name SET SCHEMA name
10682 : : *
10683 : : *****************************************************************************/
10684 : :
10685 : : AlterObjectSchemaStmt:
10686 : : ALTER AGGREGATE aggregate_with_argtypes SET SCHEMA name
10687 : : {
10688 : 16 : AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
10689 : :
10690 : 16 : n->objectType = OBJECT_AGGREGATE;
10691 : 16 : n->object = (Node *) $3;
10692 : 16 : n->newschema = $6;
10693 : 16 : n->missing_ok = false;
10694 : 16 : $$ = (Node *) n;
10695 : : }
10696 : : | ALTER COLLATION any_name SET SCHEMA name
10697 : : {
10698 : 4 : AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
10699 : :
10700 : 4 : n->objectType = OBJECT_COLLATION;
10701 : 4 : n->object = (Node *) $3;
10702 : 4 : n->newschema = $6;
10703 : 4 : n->missing_ok = false;
10704 : 4 : $$ = (Node *) n;
10705 : : }
10706 : : | ALTER CONVERSION_P any_name SET SCHEMA name
10707 : : {
10708 : 16 : AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
10709 : :
10710 : 16 : n->objectType = OBJECT_CONVERSION;
10711 : 16 : n->object = (Node *) $3;
10712 : 16 : n->newschema = $6;
10713 : 16 : n->missing_ok = false;
10714 : 16 : $$ = (Node *) n;
10715 : : }
10716 : : | ALTER DOMAIN_P any_name SET SCHEMA name
10717 : : {
10718 : 4 : AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
10719 : :
10720 : 4 : n->objectType = OBJECT_DOMAIN;
10721 : 4 : n->object = (Node *) $3;
10722 : 4 : n->newschema = $6;
10723 : 4 : n->missing_ok = false;
10724 : 4 : $$ = (Node *) n;
10725 : : }
10726 : : | ALTER EXTENSION name SET SCHEMA name
10727 : : {
10728 : 6 : AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
10729 : :
10730 : 6 : n->objectType = OBJECT_EXTENSION;
10731 : 6 : n->object = (Node *) makeString($3);
10732 : 6 : n->newschema = $6;
10733 : 6 : n->missing_ok = false;
10734 : 6 : $$ = (Node *) n;
10735 : : }
10736 : : | ALTER FUNCTION function_with_argtypes SET SCHEMA name
10737 : : {
10738 : 29 : AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
10739 : :
10740 : 29 : n->objectType = OBJECT_FUNCTION;
10741 : 29 : n->object = (Node *) $3;
10742 : 29 : n->newschema = $6;
10743 : 29 : n->missing_ok = false;
10744 : 29 : $$ = (Node *) n;
10745 : : }
10746 : : | ALTER OPERATOR operator_with_argtypes SET SCHEMA name
10747 : : {
10748 : 12 : AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
10749 : :
10750 : 12 : n->objectType = OBJECT_OPERATOR;
10751 : 12 : n->object = (Node *) $3;
10752 : 12 : n->newschema = $6;
10753 : 12 : n->missing_ok = false;
10754 : 12 : $$ = (Node *) n;
10755 : : }
10756 : : | ALTER OPERATOR CLASS any_name USING name SET SCHEMA name
10757 : : {
10758 : 16 : AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
10759 : :
10760 : 16 : n->objectType = OBJECT_OPCLASS;
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 OPERATOR FAMILY any_name USING name SET SCHEMA name
10767 : : {
10768 : 16 : AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
10769 : :
10770 : 16 : n->objectType = OBJECT_OPFAMILY;
10771 : 16 : n->object = (Node *) lcons(makeString($6), $4);
10772 : 16 : n->newschema = $9;
10773 : 16 : n->missing_ok = false;
10774 : 16 : $$ = (Node *) n;
10775 : : }
10776 : : | ALTER PROCEDURE function_with_argtypes SET SCHEMA name
10777 : : {
10778 : 0 : AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
10779 : :
10780 : 0 : n->objectType = OBJECT_PROCEDURE;
10781 : 0 : n->object = (Node *) $3;
10782 : 0 : n->newschema = $6;
10783 : 0 : n->missing_ok = false;
10784 : 0 : $$ = (Node *) n;
10785 : : }
10786 : : | ALTER PROPERTY GRAPH qualified_name SET SCHEMA name
10787 : : {
10788 : 16 : AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
10789 : :
10790 : 16 : n->objectType = OBJECT_PROPGRAPH;
10791 : 16 : n->relation = $4;
10792 : 16 : n->newschema = $7;
10793 : 16 : n->missing_ok = false;
10794 : 16 : $$ = (Node *)n;
10795 : : }
10796 : : | ALTER PROPERTY GRAPH IF_P EXISTS qualified_name SET SCHEMA name
10797 : : {
10798 : 4 : AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
10799 : :
10800 : 4 : n->objectType = OBJECT_PROPGRAPH;
10801 : 4 : n->relation = $6;
10802 : 4 : n->newschema = $9;
10803 : 4 : n->missing_ok = true;
10804 : 4 : $$ = (Node *)n;
10805 : : }
10806 : : | ALTER ROUTINE function_with_argtypes SET SCHEMA name
10807 : : {
10808 : 0 : AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
10809 : :
10810 : 0 : n->objectType = OBJECT_ROUTINE;
10811 : 0 : n->object = (Node *) $3;
10812 : 0 : n->newschema = $6;
10813 : 0 : n->missing_ok = false;
10814 : 0 : $$ = (Node *) n;
10815 : : }
10816 : : | ALTER TABLE relation_expr SET SCHEMA name
10817 : : {
10818 : 51 : AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
10819 : :
10820 : 51 : n->objectType = OBJECT_TABLE;
10821 : 51 : n->relation = $3;
10822 : 51 : n->newschema = $6;
10823 : 51 : n->missing_ok = false;
10824 : 51 : $$ = (Node *) n;
10825 : : }
10826 : : | ALTER TABLE IF_P EXISTS relation_expr SET SCHEMA name
10827 : : {
10828 : 8 : AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
10829 : :
10830 : 8 : n->objectType = OBJECT_TABLE;
10831 : 8 : n->relation = $5;
10832 : 8 : n->newschema = $8;
10833 : 8 : n->missing_ok = true;
10834 : 8 : $$ = (Node *) n;
10835 : : }
10836 : : | ALTER STATISTICS any_name SET SCHEMA name
10837 : : {
10838 : 12 : AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
10839 : :
10840 : 12 : n->objectType = OBJECT_STATISTIC_EXT;
10841 : 12 : n->object = (Node *) $3;
10842 : 12 : n->newschema = $6;
10843 : 12 : n->missing_ok = false;
10844 : 12 : $$ = (Node *) n;
10845 : : }
10846 : : | ALTER TEXT_P SEARCH PARSER any_name SET SCHEMA name
10847 : : {
10848 : 12 : AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
10849 : :
10850 : 12 : n->objectType = OBJECT_TSPARSER;
10851 : 12 : n->object = (Node *) $5;
10852 : 12 : n->newschema = $8;
10853 : 12 : n->missing_ok = false;
10854 : 12 : $$ = (Node *) n;
10855 : : }
10856 : : | ALTER TEXT_P SEARCH DICTIONARY any_name SET SCHEMA name
10857 : : {
10858 : 16 : AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
10859 : :
10860 : 16 : n->objectType = OBJECT_TSDICTIONARY;
10861 : 16 : n->object = (Node *) $5;
10862 : 16 : n->newschema = $8;
10863 : 16 : n->missing_ok = false;
10864 : 16 : $$ = (Node *) n;
10865 : : }
10866 : : | ALTER TEXT_P SEARCH TEMPLATE any_name SET SCHEMA name
10867 : : {
10868 : 12 : AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
10869 : :
10870 : 12 : n->objectType = OBJECT_TSTEMPLATE;
10871 : 12 : n->object = (Node *) $5;
10872 : 12 : n->newschema = $8;
10873 : 12 : n->missing_ok = false;
10874 : 12 : $$ = (Node *) n;
10875 : : }
10876 : : | ALTER TEXT_P SEARCH CONFIGURATION any_name SET SCHEMA name
10877 : : {
10878 : 16 : AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
10879 : :
10880 : 16 : n->objectType = OBJECT_TSCONFIGURATION;
10881 : 16 : n->object = (Node *) $5;
10882 : 16 : n->newschema = $8;
10883 : 16 : n->missing_ok = false;
10884 : 16 : $$ = (Node *) n;
10885 : : }
10886 : : | ALTER SEQUENCE qualified_name SET SCHEMA name
10887 : : {
10888 : 5 : AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
10889 : :
10890 : 5 : n->objectType = OBJECT_SEQUENCE;
10891 : 5 : n->relation = $3;
10892 : 5 : n->newschema = $6;
10893 : 5 : n->missing_ok = false;
10894 : 5 : $$ = (Node *) n;
10895 : : }
10896 : : | ALTER SEQUENCE IF_P EXISTS qualified_name SET SCHEMA name
10897 : : {
10898 : 0 : AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
10899 : :
10900 : 0 : n->objectType = OBJECT_SEQUENCE;
10901 : 0 : n->relation = $5;
10902 : 0 : n->newschema = $8;
10903 : 0 : n->missing_ok = true;
10904 : 0 : $$ = (Node *) n;
10905 : : }
10906 : : | ALTER VIEW qualified_name SET SCHEMA name
10907 : : {
10908 : 0 : AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
10909 : :
10910 : 0 : n->objectType = OBJECT_VIEW;
10911 : 0 : n->relation = $3;
10912 : 0 : n->newschema = $6;
10913 : 0 : n->missing_ok = false;
10914 : 0 : $$ = (Node *) n;
10915 : : }
10916 : : | ALTER VIEW IF_P EXISTS qualified_name SET SCHEMA name
10917 : : {
10918 : 0 : AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
10919 : :
10920 : 0 : n->objectType = OBJECT_VIEW;
10921 : 0 : n->relation = $5;
10922 : 0 : n->newschema = $8;
10923 : 0 : n->missing_ok = true;
10924 : 0 : $$ = (Node *) n;
10925 : : }
10926 : : | ALTER MATERIALIZED VIEW qualified_name SET SCHEMA name
10927 : : {
10928 : 4 : AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
10929 : :
10930 : 4 : n->objectType = OBJECT_MATVIEW;
10931 : 4 : n->relation = $4;
10932 : 4 : n->newschema = $7;
10933 : 4 : n->missing_ok = false;
10934 : 4 : $$ = (Node *) n;
10935 : : }
10936 : : | ALTER MATERIALIZED VIEW IF_P EXISTS qualified_name SET SCHEMA name
10937 : : {
10938 : 0 : AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
10939 : :
10940 : 0 : n->objectType = OBJECT_MATVIEW;
10941 : 0 : n->relation = $6;
10942 : 0 : n->newschema = $9;
10943 : 0 : n->missing_ok = true;
10944 : 0 : $$ = (Node *) n;
10945 : : }
10946 : : | ALTER FOREIGN TABLE relation_expr SET SCHEMA name
10947 : : {
10948 : 4 : AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
10949 : :
10950 : 4 : n->objectType = OBJECT_FOREIGN_TABLE;
10951 : 4 : n->relation = $4;
10952 : 4 : n->newschema = $7;
10953 : 4 : n->missing_ok = false;
10954 : 4 : $$ = (Node *) n;
10955 : : }
10956 : : | ALTER FOREIGN TABLE IF_P EXISTS relation_expr SET SCHEMA name
10957 : : {
10958 : 4 : AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
10959 : :
10960 : 4 : n->objectType = OBJECT_FOREIGN_TABLE;
10961 : 4 : n->relation = $6;
10962 : 4 : n->newschema = $9;
10963 : 4 : n->missing_ok = true;
10964 : 4 : $$ = (Node *) n;
10965 : : }
10966 : : | ALTER TYPE_P any_name SET SCHEMA name
10967 : : {
10968 : 8 : AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
10969 : :
10970 : 8 : n->objectType = OBJECT_TYPE;
10971 : 8 : n->object = (Node *) $3;
10972 : 8 : n->newschema = $6;
10973 : 8 : n->missing_ok = false;
10974 : 8 : $$ = (Node *) n;
10975 : : }
10976 : : ;
10977 : :
10978 : : /*****************************************************************************
10979 : : *
10980 : : * ALTER OPERATOR name SET define
10981 : : *
10982 : : *****************************************************************************/
10983 : :
10984 : : AlterOperatorStmt:
10985 : : ALTER OPERATOR operator_with_argtypes SET '(' operator_def_list ')'
10986 : : {
10987 : 332 : AlterOperatorStmt *n = makeNode(AlterOperatorStmt);
10988 : :
10989 : 332 : n->opername = $3;
10990 : 332 : n->options = $6;
10991 : 332 : $$ = (Node *) n;
10992 : : }
10993 : : ;
10994 : :
10995 : 368 : operator_def_list: operator_def_elem { $$ = list_make1($1); }
10996 : 261 : | operator_def_list ',' operator_def_elem { $$ = lappend($1, $3); }
10997 : : ;
10998 : :
10999 : : operator_def_elem: ColLabel '=' NONE
11000 : 20 : { $$ = makeDefElem($1, NULL, @1); }
11001 : : | ColLabel '=' operator_def_arg
11002 : 587 : { $$ = makeDefElem($1, (Node *) $3, @1); }
11003 : : | ColLabel
11004 : 22 : { $$ = makeDefElem($1, NULL, @1); }
11005 : : ;
11006 : :
11007 : : /* must be similar enough to def_arg to avoid reduce/reduce conflicts */
11008 : : operator_def_arg:
11009 : 535 : func_type { $$ = (Node *) $1; }
11010 : 16 : | reserved_keyword { $$ = (Node *) makeString(pstrdup($1)); }
11011 : 36 : | qual_all_Op { $$ = (Node *) $1; }
11012 : 0 : | NumericOnly { $$ = (Node *) $1; }
11013 : 0 : | Sconst { $$ = (Node *) makeString($1); }
11014 : : ;
11015 : :
11016 : : /*****************************************************************************
11017 : : *
11018 : : * ALTER TYPE name SET define
11019 : : *
11020 : : * We repurpose ALTER OPERATOR's version of "definition" here
11021 : : *
11022 : : *****************************************************************************/
11023 : :
11024 : : AlterTypeStmt:
11025 : : ALTER TYPE_P any_name SET '(' operator_def_list ')'
11026 : : {
11027 : 36 : AlterTypeStmt *n = makeNode(AlterTypeStmt);
11028 : :
11029 : 36 : n->typeName = $3;
11030 : 36 : n->options = $6;
11031 : 36 : $$ = (Node *) n;
11032 : : }
11033 : : ;
11034 : :
11035 : : /*****************************************************************************
11036 : : *
11037 : : * ALTER THING name OWNER TO newname
11038 : : *
11039 : : *****************************************************************************/
11040 : :
11041 : : AlterOwnerStmt: ALTER AGGREGATE aggregate_with_argtypes OWNER TO RoleSpec
11042 : : {
11043 : 76 : AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
11044 : :
11045 : 76 : n->objectType = OBJECT_AGGREGATE;
11046 : 76 : n->object = (Node *) $3;
11047 : 76 : n->newowner = $6;
11048 : 76 : $$ = (Node *) n;
11049 : : }
11050 : : | ALTER COLLATION any_name OWNER TO RoleSpec
11051 : : {
11052 : 11 : AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
11053 : :
11054 : 11 : n->objectType = OBJECT_COLLATION;
11055 : 11 : n->object = (Node *) $3;
11056 : 11 : n->newowner = $6;
11057 : 11 : $$ = (Node *) n;
11058 : : }
11059 : : | ALTER CONVERSION_P any_name OWNER TO RoleSpec
11060 : : {
11061 : 16 : AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
11062 : :
11063 : 16 : n->objectType = OBJECT_CONVERSION;
11064 : 16 : n->object = (Node *) $3;
11065 : 16 : n->newowner = $6;
11066 : 16 : $$ = (Node *) n;
11067 : : }
11068 : : | ALTER DATABASE name OWNER TO RoleSpec
11069 : : {
11070 : 50 : AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
11071 : :
11072 : 50 : n->objectType = OBJECT_DATABASE;
11073 : 50 : n->object = (Node *) makeString($3);
11074 : 50 : n->newowner = $6;
11075 : 50 : $$ = (Node *) n;
11076 : : }
11077 : : | ALTER DOMAIN_P any_name OWNER TO RoleSpec
11078 : : {
11079 : 28 : AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
11080 : :
11081 : 28 : n->objectType = OBJECT_DOMAIN;
11082 : 28 : n->object = (Node *) $3;
11083 : 28 : n->newowner = $6;
11084 : 28 : $$ = (Node *) n;
11085 : : }
11086 : : | ALTER FUNCTION function_with_argtypes OWNER TO RoleSpec
11087 : : {
11088 : 322 : AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
11089 : :
11090 : 322 : n->objectType = OBJECT_FUNCTION;
11091 : 322 : n->object = (Node *) $3;
11092 : 322 : n->newowner = $6;
11093 : 322 : $$ = (Node *) n;
11094 : : }
11095 : : | ALTER opt_procedural LANGUAGE name OWNER TO RoleSpec
11096 : : {
11097 : 83 : AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
11098 : :
11099 : 83 : n->objectType = OBJECT_LANGUAGE;
11100 : 83 : n->object = (Node *) makeString($4);
11101 : 83 : n->newowner = $7;
11102 : 83 : $$ = (Node *) n;
11103 : : }
11104 : : | ALTER LARGE_P OBJECT_P NumericOnly OWNER TO RoleSpec
11105 : : {
11106 : 9 : AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
11107 : :
11108 : 9 : n->objectType = OBJECT_LARGEOBJECT;
11109 : 9 : n->object = (Node *) $4;
11110 : 9 : n->newowner = $7;
11111 : 9 : $$ = (Node *) n;
11112 : : }
11113 : : | ALTER OPERATOR operator_with_argtypes OWNER TO RoleSpec
11114 : : {
11115 : 27 : AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
11116 : :
11117 : 27 : n->objectType = OBJECT_OPERATOR;
11118 : 27 : n->object = (Node *) $3;
11119 : 27 : n->newowner = $6;
11120 : 27 : $$ = (Node *) n;
11121 : : }
11122 : : | ALTER OPERATOR CLASS any_name USING name OWNER TO RoleSpec
11123 : : {
11124 : 35 : AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
11125 : :
11126 : 35 : n->objectType = OBJECT_OPCLASS;
11127 : 35 : n->object = (Node *) lcons(makeString($6), $4);
11128 : 35 : n->newowner = $9;
11129 : 35 : $$ = (Node *) n;
11130 : : }
11131 : : | ALTER OPERATOR FAMILY any_name USING name OWNER TO RoleSpec
11132 : : {
11133 : 39 : AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
11134 : :
11135 : 39 : n->objectType = OBJECT_OPFAMILY;
11136 : 39 : n->object = (Node *) lcons(makeString($6), $4);
11137 : 39 : n->newowner = $9;
11138 : 39 : $$ = (Node *) n;
11139 : : }
11140 : : | ALTER PROCEDURE function_with_argtypes OWNER TO RoleSpec
11141 : : {
11142 : 12 : AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
11143 : :
11144 : 12 : n->objectType = OBJECT_PROCEDURE;
11145 : 12 : n->object = (Node *) $3;
11146 : 12 : n->newowner = $6;
11147 : 12 : $$ = (Node *) n;
11148 : : }
11149 : : | ALTER PROPERTY GRAPH qualified_name OWNER TO RoleSpec
11150 : : {
11151 : 34 : AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
11152 : :
11153 : 34 : n->objectType = OBJECT_PROPGRAPH;
11154 : 34 : n->relation = $4;
11155 : 34 : n->newowner = $7;
11156 : 34 : $$ = (Node *) n;
11157 : : }
11158 : : | ALTER ROUTINE function_with_argtypes OWNER TO RoleSpec
11159 : : {
11160 : 0 : AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
11161 : :
11162 : 0 : n->objectType = OBJECT_ROUTINE;
11163 : 0 : n->object = (Node *) $3;
11164 : 0 : n->newowner = $6;
11165 : 0 : $$ = (Node *) n;
11166 : : }
11167 : : | ALTER SCHEMA name OWNER TO RoleSpec
11168 : : {
11169 : 41 : AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
11170 : :
11171 : 41 : n->objectType = OBJECT_SCHEMA;
11172 : 41 : n->object = (Node *) makeString($3);
11173 : 41 : n->newowner = $6;
11174 : 41 : $$ = (Node *) n;
11175 : : }
11176 : : | ALTER TYPE_P any_name OWNER TO RoleSpec
11177 : : {
11178 : 45 : AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
11179 : :
11180 : 45 : n->objectType = OBJECT_TYPE;
11181 : 45 : n->object = (Node *) $3;
11182 : 45 : n->newowner = $6;
11183 : 45 : $$ = (Node *) n;
11184 : : }
11185 : : | ALTER TABLESPACE name OWNER TO RoleSpec
11186 : : {
11187 : 3 : AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
11188 : :
11189 : 3 : n->objectType = OBJECT_TABLESPACE;
11190 : 3 : n->object = (Node *) makeString($3);
11191 : 3 : n->newowner = $6;
11192 : 3 : $$ = (Node *) n;
11193 : : }
11194 : : | ALTER STATISTICS any_name OWNER TO RoleSpec
11195 : : {
11196 : 20 : AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
11197 : :
11198 : 20 : n->objectType = OBJECT_STATISTIC_EXT;
11199 : 20 : n->object = (Node *) $3;
11200 : 20 : n->newowner = $6;
11201 : 20 : $$ = (Node *) n;
11202 : : }
11203 : : | ALTER TEXT_P SEARCH DICTIONARY any_name OWNER TO RoleSpec
11204 : : {
11205 : 25 : AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
11206 : :
11207 : 25 : n->objectType = OBJECT_TSDICTIONARY;
11208 : 25 : n->object = (Node *) $5;
11209 : 25 : n->newowner = $8;
11210 : 25 : $$ = (Node *) n;
11211 : : }
11212 : : | ALTER TEXT_P SEARCH CONFIGURATION any_name OWNER TO RoleSpec
11213 : : {
11214 : 20 : AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
11215 : :
11216 : 20 : n->objectType = OBJECT_TSCONFIGURATION;
11217 : 20 : n->object = (Node *) $5;
11218 : 20 : n->newowner = $8;
11219 : 20 : $$ = (Node *) n;
11220 : : }
11221 : : | ALTER FOREIGN DATA_P WRAPPER name OWNER TO RoleSpec
11222 : : {
11223 : 13 : AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
11224 : :
11225 : 13 : n->objectType = OBJECT_FDW;
11226 : 13 : n->object = (Node *) makeString($5);
11227 : 13 : n->newowner = $8;
11228 : 13 : $$ = (Node *) n;
11229 : : }
11230 : : | ALTER SERVER name OWNER TO RoleSpec
11231 : : {
11232 : 45 : AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
11233 : :
11234 : 45 : n->objectType = OBJECT_FOREIGN_SERVER;
11235 : 45 : n->object = (Node *) makeString($3);
11236 : 45 : n->newowner = $6;
11237 : 45 : $$ = (Node *) n;
11238 : : }
11239 : : | ALTER EVENT TRIGGER name OWNER TO RoleSpec
11240 : : {
11241 : 9 : AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
11242 : :
11243 : 9 : n->objectType = OBJECT_EVENT_TRIGGER;
11244 : 9 : n->object = (Node *) makeString($4);
11245 : 9 : n->newowner = $7;
11246 : 9 : $$ = (Node *) n;
11247 : : }
11248 : : | ALTER PUBLICATION name OWNER TO RoleSpec
11249 : : {
11250 : 26 : AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
11251 : :
11252 : 26 : n->objectType = OBJECT_PUBLICATION;
11253 : 26 : n->object = (Node *) makeString($3);
11254 : 26 : n->newowner = $6;
11255 : 26 : $$ = (Node *) n;
11256 : : }
11257 : : | ALTER SUBSCRIPTION name OWNER TO RoleSpec
11258 : : {
11259 : 23 : AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
11260 : :
11261 : 23 : n->objectType = OBJECT_SUBSCRIPTION;
11262 : 23 : n->object = (Node *) makeString($3);
11263 : 23 : n->newowner = $6;
11264 : 23 : $$ = (Node *) n;
11265 : : }
11266 : : ;
11267 : :
11268 : :
11269 : : /*****************************************************************************
11270 : : *
11271 : : * CREATE PUBLICATION name [WITH options]
11272 : : *
11273 : : * CREATE PUBLICATION FOR ALL pub_all_obj_type [, ...] [WITH options]
11274 : : *
11275 : : * pub_all_obj_type is one of:
11276 : : *
11277 : : * TABLES [EXCEPT (TABLE table [, ...] )]
11278 : : * SEQUENCES
11279 : : *
11280 : : * CREATE PUBLICATION FOR pub_obj [, ...] [WITH options]
11281 : : *
11282 : : * pub_obj is one of:
11283 : : *
11284 : : * TABLE table [, ...]
11285 : : * TABLES IN SCHEMA schema [, ...]
11286 : : *
11287 : : *****************************************************************************/
11288 : :
11289 : : CreatePublicationStmt:
11290 : : CREATE PUBLICATION name opt_definition
11291 : : {
11292 : 94 : CreatePublicationStmt *n = makeNode(CreatePublicationStmt);
11293 : :
11294 : 94 : n->pubname = $3;
11295 : 94 : n->options = $4;
11296 : 94 : $$ = (Node *) n;
11297 : : }
11298 : : | CREATE PUBLICATION name FOR pub_all_obj_type_list opt_definition
11299 : : {
11300 : 136 : CreatePublicationStmt *n = makeNode(CreatePublicationStmt);
11301 : :
11302 : 136 : n->pubname = $3;
11303 : 136 : preprocess_pub_all_objtype_list($5, &n->pubobjects,
11304 : : &n->for_all_tables,
11305 : : &n->for_all_sequences,
11306 : : yyscanner);
11307 : 128 : n->options = $6;
11308 : 128 : $$ = (Node *) n;
11309 : : }
11310 : : | CREATE PUBLICATION name FOR pub_obj_list opt_definition
11311 : : {
11312 : 438 : CreatePublicationStmt *n = makeNode(CreatePublicationStmt);
11313 : :
11314 : 438 : n->pubname = $3;
11315 : 438 : n->options = $6;
11316 : 438 : n->pubobjects = (List *) $5;
11317 : 438 : preprocess_pubobj_list(n->pubobjects, yyscanner);
11318 : 418 : $$ = (Node *) n;
11319 : : }
11320 : : ;
11321 : :
11322 : : /*
11323 : : * FOR TABLE and FOR TABLES IN SCHEMA specifications
11324 : : *
11325 : : * This rule parses publication objects with and without keyword prefixes.
11326 : : *
11327 : : * The actual type of the object without keyword prefix depends on the previous
11328 : : * one with keyword prefix. It will be preprocessed in preprocess_pubobj_list().
11329 : : *
11330 : : * For the object without keyword prefix, we cannot just use relation_expr here,
11331 : : * because some extended expressions in relation_expr cannot be used as a
11332 : : * schemaname and we cannot differentiate it. So, we extract the rules from
11333 : : * relation_expr here.
11334 : : */
11335 : : PublicationObjSpec:
11336 : : TABLE relation_expr opt_column_list OptWhereClause
11337 : : {
11338 : 867 : $$ = makeNode(PublicationObjSpec);
11339 : 867 : $$->pubobjtype = PUBLICATIONOBJ_TABLE;
11340 : 867 : $$->pubtable = makeNode(PublicationTable);
11341 : 867 : $$->pubtable->relation = $2;
11342 : 867 : $$->pubtable->columns = $3;
11343 : 867 : $$->pubtable->whereClause = $4;
11344 : : }
11345 : : | TABLES IN_P SCHEMA ColId
11346 : : {
11347 : 248 : $$ = makeNode(PublicationObjSpec);
11348 : 248 : $$->pubobjtype = PUBLICATIONOBJ_TABLES_IN_SCHEMA;
11349 : 248 : $$->name = $4;
11350 : 248 : $$->location = @4;
11351 : : }
11352 : : | TABLES IN_P SCHEMA CURRENT_SCHEMA
11353 : : {
11354 : 12 : $$ = makeNode(PublicationObjSpec);
11355 : 12 : $$->pubobjtype = PUBLICATIONOBJ_TABLES_IN_CUR_SCHEMA;
11356 : 12 : $$->location = @4;
11357 : : }
11358 : : | ColId opt_column_list OptWhereClause
11359 : : {
11360 : 83 : $$ = makeNode(PublicationObjSpec);
11361 : 83 : $$->pubobjtype = PUBLICATIONOBJ_CONTINUATION;
11362 : : /*
11363 : : * If either a row filter or column list is specified, create
11364 : : * a PublicationTable object.
11365 : : */
11366 [ + + + + ]: 83 : if ($2 || $3)
11367 : : {
11368 : : /*
11369 : : * The OptWhereClause must be stored here but it is
11370 : : * valid only for tables. For non-table objects, an
11371 : : * error will be thrown later via
11372 : : * preprocess_pubobj_list().
11373 : : */
11374 : 26 : $$->pubtable = makeNode(PublicationTable);
11375 : 26 : $$->pubtable->relation = makeRangeVar(NULL, $1, @1);
11376 : 26 : $$->pubtable->columns = $2;
11377 : 26 : $$->pubtable->whereClause = $3;
11378 : : }
11379 : : else
11380 : : {
11381 : 57 : $$->name = $1;
11382 : : }
11383 : 83 : $$->location = @1;
11384 : : }
11385 : : | ColId indirection opt_column_list OptWhereClause
11386 : : {
11387 : 21 : $$ = makeNode(PublicationObjSpec);
11388 : 21 : $$->pubobjtype = PUBLICATIONOBJ_CONTINUATION;
11389 : 21 : $$->pubtable = makeNode(PublicationTable);
11390 : 21 : $$->pubtable->relation = makeRangeVarFromQualifiedName($1, $2, @1, yyscanner);
11391 : 21 : $$->pubtable->columns = $3;
11392 : 21 : $$->pubtable->whereClause = $4;
11393 : 21 : $$->location = @1;
11394 : : }
11395 : : /* grammar like tablename * , ONLY tablename, ONLY ( tablename ) */
11396 : : | extended_relation_expr opt_column_list OptWhereClause
11397 : : {
11398 : 4 : $$ = makeNode(PublicationObjSpec);
11399 : 4 : $$->pubobjtype = PUBLICATIONOBJ_CONTINUATION;
11400 : 4 : $$->pubtable = makeNode(PublicationTable);
11401 : 4 : $$->pubtable->relation = $1;
11402 : 4 : $$->pubtable->columns = $2;
11403 : 4 : $$->pubtable->whereClause = $3;
11404 : : }
11405 : : | CURRENT_SCHEMA
11406 : : {
11407 : 12 : $$ = makeNode(PublicationObjSpec);
11408 : 12 : $$->pubobjtype = PUBLICATIONOBJ_CONTINUATION;
11409 : 12 : $$->location = @1;
11410 : : }
11411 : : ;
11412 : :
11413 : : pub_obj_list: PublicationObjSpec
11414 : 1082 : { $$ = list_make1($1); }
11415 : : | pub_obj_list ',' PublicationObjSpec
11416 : 165 : { $$ = lappend($1, $3); }
11417 : : ;
11418 : :
11419 : : opt_pub_except_clause:
11420 : 64 : EXCEPT '(' TABLE pub_except_obj_list ')' { $$ = $4; }
11421 : 109 : | /*EMPTY*/ { $$ = NIL; }
11422 : : ;
11423 : :
11424 : : PublicationAllObjSpec:
11425 : : ALL TABLES opt_pub_except_clause
11426 : : {
11427 : 173 : $$ = makeNode(PublicationAllObjSpec);
11428 : 173 : $$->pubobjtype = PUBLICATION_ALL_TABLES;
11429 : 173 : $$->except_tables = $3;
11430 : 173 : $$->location = @1;
11431 : : }
11432 : : | ALL SEQUENCES
11433 : : {
11434 : 49 : $$ = makeNode(PublicationAllObjSpec);
11435 : 49 : $$->pubobjtype = PUBLICATION_ALL_SEQUENCES;
11436 : 49 : $$->location = @1;
11437 : : }
11438 : : ;
11439 : :
11440 : : pub_all_obj_type_list: PublicationAllObjSpec
11441 : 197 : { $$ = list_make1($1); }
11442 : : | pub_all_obj_type_list ',' PublicationAllObjSpec
11443 : 25 : { $$ = lappend($1, $3); }
11444 : : ;
11445 : :
11446 : : PublicationExceptObjSpec:
11447 : : relation_expr
11448 : : {
11449 : 91 : $$ = makeNode(PublicationObjSpec);
11450 : 91 : $$->pubobjtype = PUBLICATIONOBJ_EXCEPT_TABLE;
11451 : 91 : $$->pubtable = makeNode(PublicationTable);
11452 : 91 : $$->pubtable->except = true;
11453 : 91 : $$->pubtable->relation = $1;
11454 : 91 : $$->location = @1;
11455 : : }
11456 : : ;
11457 : :
11458 : : pub_except_obj_list: PublicationExceptObjSpec
11459 : 64 : { $$ = list_make1($1); }
11460 : : | pub_except_obj_list ',' opt_table PublicationExceptObjSpec
11461 : 27 : { $$ = lappend($1, $4); }
11462 : : ;
11463 : :
11464 : : /*****************************************************************************
11465 : : *
11466 : : * ALTER PUBLICATION name SET ( options )
11467 : : *
11468 : : * ALTER PUBLICATION name ADD pub_obj [, ...]
11469 : : *
11470 : : * ALTER PUBLICATION name DROP pub_obj [, ...]
11471 : : *
11472 : : * ALTER PUBLICATION name SET pub_obj [, ...]
11473 : : *
11474 : : * ALTER PUBLICATION name SET pub_all_obj_type [, ...]
11475 : : *
11476 : : * pub_obj is one of:
11477 : : *
11478 : : * TABLE table_name [, ...]
11479 : : * TABLES IN SCHEMA schema_name [, ...]
11480 : : *
11481 : : * pub_all_obj_type is one of:
11482 : : *
11483 : : * ALL TABLES [ EXCEPT ( TABLE table_name [, ...] ) ]
11484 : : * ALL SEQUENCES
11485 : : *
11486 : : *****************************************************************************/
11487 : :
11488 : : AlterPublicationStmt:
11489 : : ALTER PUBLICATION name SET definition
11490 : : {
11491 : 84 : AlterPublicationStmt *n = makeNode(AlterPublicationStmt);
11492 : :
11493 : 84 : n->pubname = $3;
11494 : 84 : n->options = $5;
11495 : 84 : n->for_all_tables = false;
11496 : 84 : $$ = (Node *) n;
11497 : : }
11498 : : | ALTER PUBLICATION name ADD_P pub_obj_list
11499 : : {
11500 : 233 : AlterPublicationStmt *n = makeNode(AlterPublicationStmt);
11501 : :
11502 : 233 : n->pubname = $3;
11503 : 233 : n->pubobjects = $5;
11504 : 233 : preprocess_pubobj_list(n->pubobjects, yyscanner);
11505 : 229 : n->action = AP_AddObjects;
11506 : 229 : n->for_all_tables = false;
11507 : 229 : $$ = (Node *) n;
11508 : : }
11509 : : | ALTER PUBLICATION name SET pub_obj_list
11510 : : {
11511 : 308 : AlterPublicationStmt *n = makeNode(AlterPublicationStmt);
11512 : :
11513 : 308 : n->pubname = $3;
11514 : 308 : n->pubobjects = $5;
11515 : 308 : preprocess_pubobj_list(n->pubobjects, yyscanner);
11516 : 308 : n->action = AP_SetObjects;
11517 : 308 : n->for_all_tables = false;
11518 : 308 : $$ = (Node *) n;
11519 : : }
11520 : : | ALTER PUBLICATION name SET pub_all_obj_type_list
11521 : : {
11522 : 61 : AlterPublicationStmt *n = makeNode(AlterPublicationStmt);
11523 : :
11524 : 61 : n->pubname = $3;
11525 : 61 : n->action = AP_SetObjects;
11526 : 61 : preprocess_pub_all_objtype_list($5, &n->pubobjects,
11527 : : &n->for_all_tables,
11528 : : &n->for_all_sequences,
11529 : : yyscanner);
11530 : 61 : $$ = (Node *) n;
11531 : : }
11532 : : | ALTER PUBLICATION name DROP pub_obj_list
11533 : : {
11534 : 103 : AlterPublicationStmt *n = makeNode(AlterPublicationStmt);
11535 : :
11536 : 103 : n->pubname = $3;
11537 : 103 : n->pubobjects = $5;
11538 : 103 : preprocess_pubobj_list(n->pubobjects, yyscanner);
11539 : 103 : n->action = AP_DropObjects;
11540 : 103 : n->for_all_tables = false;
11541 : 103 : $$ = (Node *) n;
11542 : : }
11543 : : ;
11544 : :
11545 : : /*****************************************************************************
11546 : : *
11547 : : * CREATE SUBSCRIPTION name ...
11548 : : *
11549 : : *****************************************************************************/
11550 : :
11551 : : CreateSubscriptionStmt:
11552 : : CREATE SUBSCRIPTION name CONNECTION Sconst PUBLICATION name_list opt_definition
11553 : : {
11554 : : CreateSubscriptionStmt *n =
11555 : 315 : makeNode(CreateSubscriptionStmt);
11556 : 315 : n->subname = $3;
11557 : 315 : n->conninfo = $5;
11558 : 315 : n->publication = $7;
11559 : 315 : n->options = $8;
11560 : 315 : $$ = (Node *) n;
11561 : : }
11562 : : | CREATE SUBSCRIPTION name SERVER name PUBLICATION name_list opt_definition
11563 : : {
11564 : : CreateSubscriptionStmt *n =
11565 : 23 : makeNode(CreateSubscriptionStmt);
11566 : 23 : n->subname = $3;
11567 : 23 : n->servername = $5;
11568 : 23 : n->publication = $7;
11569 : 23 : n->options = $8;
11570 : 23 : $$ = (Node *) n;
11571 : : }
11572 : : ;
11573 : :
11574 : : /*****************************************************************************
11575 : : *
11576 : : * ALTER SUBSCRIPTION name ...
11577 : : *
11578 : : *****************************************************************************/
11579 : :
11580 : : AlterSubscriptionStmt:
11581 : : ALTER SUBSCRIPTION name SET definition
11582 : : {
11583 : : AlterSubscriptionStmt *n =
11584 : 193 : makeNode(AlterSubscriptionStmt);
11585 : :
11586 : 193 : n->kind = ALTER_SUBSCRIPTION_OPTIONS;
11587 : 193 : n->subname = $3;
11588 : 193 : n->options = $5;
11589 : 193 : $$ = (Node *) n;
11590 : : }
11591 : : | ALTER SUBSCRIPTION name CONNECTION Sconst
11592 : : {
11593 : : AlterSubscriptionStmt *n =
11594 : 26 : makeNode(AlterSubscriptionStmt);
11595 : :
11596 : 26 : n->kind = ALTER_SUBSCRIPTION_CONNECTION;
11597 : 26 : n->subname = $3;
11598 : 26 : n->conninfo = $5;
11599 : 26 : $$ = (Node *) n;
11600 : : }
11601 : : | ALTER SUBSCRIPTION name SERVER name
11602 : : {
11603 : : AlterSubscriptionStmt *n =
11604 : 1 : makeNode(AlterSubscriptionStmt);
11605 : :
11606 : 1 : n->kind = ALTER_SUBSCRIPTION_SERVER;
11607 : 1 : n->subname = $3;
11608 : 1 : n->servername = $5;
11609 : 1 : $$ = (Node *) n;
11610 : : }
11611 : : | ALTER SUBSCRIPTION name REFRESH PUBLICATION opt_definition
11612 : : {
11613 : : AlterSubscriptionStmt *n =
11614 : 37 : makeNode(AlterSubscriptionStmt);
11615 : :
11616 : 37 : n->kind = ALTER_SUBSCRIPTION_REFRESH_PUBLICATION;
11617 : 37 : n->subname = $3;
11618 : 37 : n->options = $6;
11619 : 37 : $$ = (Node *) n;
11620 : : }
11621 : : | ALTER SUBSCRIPTION name REFRESH SEQUENCES
11622 : : {
11623 : : AlterSubscriptionStmt *n =
11624 : 5 : makeNode(AlterSubscriptionStmt);
11625 : :
11626 : 5 : n->kind = ALTER_SUBSCRIPTION_REFRESH_SEQUENCES;
11627 : 5 : n->subname = $3;
11628 : 5 : $$ = (Node *) n;
11629 : : }
11630 : : | ALTER SUBSCRIPTION name ADD_P PUBLICATION name_list opt_definition
11631 : : {
11632 : : AlterSubscriptionStmt *n =
11633 : 18 : makeNode(AlterSubscriptionStmt);
11634 : :
11635 : 18 : n->kind = ALTER_SUBSCRIPTION_ADD_PUBLICATION;
11636 : 18 : n->subname = $3;
11637 : 18 : n->publication = $6;
11638 : 18 : n->options = $7;
11639 : 18 : $$ = (Node *) n;
11640 : : }
11641 : : | ALTER SUBSCRIPTION name DROP PUBLICATION name_list opt_definition
11642 : : {
11643 : : AlterSubscriptionStmt *n =
11644 : 17 : makeNode(AlterSubscriptionStmt);
11645 : :
11646 : 17 : n->kind = ALTER_SUBSCRIPTION_DROP_PUBLICATION;
11647 : 17 : n->subname = $3;
11648 : 17 : n->publication = $6;
11649 : 17 : n->options = $7;
11650 : 17 : $$ = (Node *) n;
11651 : : }
11652 : : | ALTER SUBSCRIPTION name SET PUBLICATION name_list opt_definition
11653 : : {
11654 : : AlterSubscriptionStmt *n =
11655 : 28 : makeNode(AlterSubscriptionStmt);
11656 : :
11657 : 28 : n->kind = ALTER_SUBSCRIPTION_SET_PUBLICATION;
11658 : 28 : n->subname = $3;
11659 : 28 : n->publication = $6;
11660 : 28 : n->options = $7;
11661 : 28 : $$ = (Node *) n;
11662 : : }
11663 : : | ALTER SUBSCRIPTION name ENABLE_P
11664 : : {
11665 : : AlterSubscriptionStmt *n =
11666 : 34 : makeNode(AlterSubscriptionStmt);
11667 : :
11668 : 34 : n->kind = ALTER_SUBSCRIPTION_ENABLED;
11669 : 34 : n->subname = $3;
11670 : 34 : n->options = list_make1(makeDefElem("enabled",
11671 : : (Node *) makeBoolean(true), @1));
11672 : 34 : $$ = (Node *) n;
11673 : : }
11674 : : | ALTER SUBSCRIPTION name DISABLE_P
11675 : : {
11676 : : AlterSubscriptionStmt *n =
11677 : 45 : makeNode(AlterSubscriptionStmt);
11678 : :
11679 : 45 : n->kind = ALTER_SUBSCRIPTION_ENABLED;
11680 : 45 : n->subname = $3;
11681 : 45 : n->options = list_make1(makeDefElem("enabled",
11682 : : (Node *) makeBoolean(false), @1));
11683 : 45 : $$ = (Node *) n;
11684 : : }
11685 : : | ALTER SUBSCRIPTION name SKIP definition
11686 : : {
11687 : : AlterSubscriptionStmt *n =
11688 : 15 : makeNode(AlterSubscriptionStmt);
11689 : :
11690 : 15 : n->kind = ALTER_SUBSCRIPTION_SKIP;
11691 : 15 : n->subname = $3;
11692 : 15 : n->options = $5;
11693 : 15 : $$ = (Node *) n;
11694 : : }
11695 : : ;
11696 : :
11697 : : /*****************************************************************************
11698 : : *
11699 : : * DROP SUBSCRIPTION [ IF EXISTS ] name
11700 : : *
11701 : : *****************************************************************************/
11702 : :
11703 : : DropSubscriptionStmt: DROP SUBSCRIPTION name opt_drop_behavior
11704 : : {
11705 : 176 : DropSubscriptionStmt *n = makeNode(DropSubscriptionStmt);
11706 : :
11707 : 176 : n->subname = $3;
11708 : 176 : n->missing_ok = false;
11709 : 176 : n->behavior = $4;
11710 : 176 : $$ = (Node *) n;
11711 : : }
11712 : : | DROP SUBSCRIPTION IF_P EXISTS name opt_drop_behavior
11713 : : {
11714 : 4 : DropSubscriptionStmt *n = makeNode(DropSubscriptionStmt);
11715 : :
11716 : 4 : n->subname = $5;
11717 : 4 : n->missing_ok = true;
11718 : 4 : n->behavior = $6;
11719 : 4 : $$ = (Node *) n;
11720 : : }
11721 : : ;
11722 : :
11723 : : /*****************************************************************************
11724 : : *
11725 : : * QUERY: Define Rewrite Rule
11726 : : *
11727 : : *****************************************************************************/
11728 : :
11729 : : RuleStmt: CREATE opt_or_replace RULE name AS
11730 : : ON event TO qualified_name where_clause
11731 : : DO opt_instead RuleActionList
11732 : : {
11733 : 754 : RuleStmt *n = makeNode(RuleStmt);
11734 : :
11735 : 754 : n->replace = $2;
11736 : 754 : n->relation = $9;
11737 : 754 : n->rulename = $4;
11738 : 754 : n->whereClause = $10;
11739 : 754 : n->event = $7;
11740 : 754 : n->instead = $12;
11741 : 754 : n->actions = $13;
11742 : 754 : $$ = (Node *) n;
11743 : : }
11744 : : ;
11745 : :
11746 : : RuleActionList:
11747 : 108 : NOTHING { $$ = NIL; }
11748 : 616 : | RuleActionStmt { $$ = list_make1($1); }
11749 : 30 : | '(' RuleActionMulti ')' { $$ = $2; }
11750 : : ;
11751 : :
11752 : : /* the thrashing around here is to discard "empty" statements... */
11753 : : RuleActionMulti:
11754 : : RuleActionMulti ';' RuleActionStmtOrEmpty
11755 [ + + ]: 40 : { if ($3 != NULL)
11756 : 30 : $$ = lappend($1, $3);
11757 : : else
11758 : 10 : $$ = $1;
11759 : : }
11760 : : | RuleActionStmtOrEmpty
11761 [ + - ]: 30 : { if ($1 != NULL)
11762 : 30 : $$ = list_make1($1);
11763 : : else
11764 : 0 : $$ = NIL;
11765 : : }
11766 : : ;
11767 : :
11768 : : RuleActionStmt:
11769 : : SelectStmt
11770 : : | InsertStmt
11771 : : | UpdateStmt
11772 : : | DeleteStmt
11773 : : | NotifyStmt
11774 : : ;
11775 : :
11776 : : RuleActionStmtOrEmpty:
11777 : 60 : RuleActionStmt { $$ = $1; }
11778 : 10 : | /*EMPTY*/ { $$ = NULL; }
11779 : : ;
11780 : :
11781 : 12 : event: SELECT { $$ = CMD_SELECT; }
11782 : 290 : | UPDATE { $$ = CMD_UPDATE; }
11783 : 110 : | DELETE_P { $$ = CMD_DELETE; }
11784 : 342 : | INSERT { $$ = CMD_INSERT; }
11785 : : ;
11786 : :
11787 : : opt_instead:
11788 : 519 : INSTEAD { $$ = true; }
11789 : 127 : | ALSO { $$ = false; }
11790 : 108 : | /*EMPTY*/ { $$ = false; }
11791 : : ;
11792 : :
11793 : :
11794 : : /*****************************************************************************
11795 : : *
11796 : : * QUERY:
11797 : : * NOTIFY <identifier> can appear both in rule bodies and
11798 : : * as a query-level command
11799 : : *
11800 : : *****************************************************************************/
11801 : :
11802 : : NotifyStmt: NOTIFY ColId notify_payload
11803 : : {
11804 : 88 : NotifyStmt *n = makeNode(NotifyStmt);
11805 : :
11806 : 88 : n->conditionname = $2;
11807 : 88 : n->payload = $3;
11808 : 88 : $$ = (Node *) n;
11809 : : }
11810 : : ;
11811 : :
11812 : : notify_payload:
11813 : 47 : ',' Sconst { $$ = $2; }
11814 : 41 : | /*EMPTY*/ { $$ = NULL; }
11815 : : ;
11816 : :
11817 : : ListenStmt: LISTEN ColId
11818 : : {
11819 : 52 : ListenStmt *n = makeNode(ListenStmt);
11820 : :
11821 : 52 : n->conditionname = $2;
11822 : 52 : $$ = (Node *) n;
11823 : : }
11824 : : ;
11825 : :
11826 : : UnlistenStmt:
11827 : : UNLISTEN ColId
11828 : : {
11829 : 4 : UnlistenStmt *n = makeNode(UnlistenStmt);
11830 : :
11831 : 4 : n->conditionname = $2;
11832 : 4 : $$ = (Node *) n;
11833 : : }
11834 : : | UNLISTEN '*'
11835 : : {
11836 : 58 : UnlistenStmt *n = makeNode(UnlistenStmt);
11837 : :
11838 : 58 : n->conditionname = NULL;
11839 : 58 : $$ = (Node *) n;
11840 : : }
11841 : : ;
11842 : :
11843 : :
11844 : : /*****************************************************************************
11845 : : *
11846 : : * Transactions:
11847 : : *
11848 : : * BEGIN / COMMIT / ROLLBACK
11849 : : * (also older versions END / ABORT)
11850 : : *
11851 : : *****************************************************************************/
11852 : :
11853 : : TransactionStmt:
11854 : : ABORT_P opt_transaction opt_transaction_chain
11855 : : {
11856 : 419 : TransactionStmt *n = makeNode(TransactionStmt);
11857 : :
11858 : 419 : n->kind = TRANS_STMT_ROLLBACK;
11859 : 419 : n->options = NIL;
11860 : 419 : n->chain = $3;
11861 : 419 : n->location = -1;
11862 : 419 : $$ = (Node *) n;
11863 : : }
11864 : : | START TRANSACTION transaction_mode_list_or_empty
11865 : : {
11866 : 881 : TransactionStmt *n = makeNode(TransactionStmt);
11867 : :
11868 : 881 : n->kind = TRANS_STMT_START;
11869 : 881 : n->options = $3;
11870 : 881 : n->location = -1;
11871 : 881 : $$ = (Node *) n;
11872 : : }
11873 : : | COMMIT opt_transaction opt_transaction_chain
11874 : : {
11875 : 9593 : TransactionStmt *n = makeNode(TransactionStmt);
11876 : :
11877 : 9593 : n->kind = TRANS_STMT_COMMIT;
11878 : 9593 : n->options = NIL;
11879 : 9593 : n->chain = $3;
11880 : 9593 : n->location = -1;
11881 : 9593 : $$ = (Node *) n;
11882 : : }
11883 : : | ROLLBACK opt_transaction opt_transaction_chain
11884 : : {
11885 : 1834 : TransactionStmt *n = makeNode(TransactionStmt);
11886 : :
11887 : 1834 : n->kind = TRANS_STMT_ROLLBACK;
11888 : 1834 : n->options = NIL;
11889 : 1834 : n->chain = $3;
11890 : 1834 : n->location = -1;
11891 : 1834 : $$ = (Node *) n;
11892 : : }
11893 : : | SAVEPOINT ColId
11894 : : {
11895 : 1155 : TransactionStmt *n = makeNode(TransactionStmt);
11896 : :
11897 : 1155 : n->kind = TRANS_STMT_SAVEPOINT;
11898 : 1155 : n->savepoint_name = $2;
11899 : 1155 : n->location = @2;
11900 : 1155 : $$ = (Node *) n;
11901 : : }
11902 : : | RELEASE SAVEPOINT ColId
11903 : : {
11904 : 136 : TransactionStmt *n = makeNode(TransactionStmt);
11905 : :
11906 : 136 : n->kind = TRANS_STMT_RELEASE;
11907 : 136 : n->savepoint_name = $3;
11908 : 136 : n->location = @3;
11909 : 136 : $$ = (Node *) n;
11910 : : }
11911 : : | RELEASE ColId
11912 : : {
11913 : 56 : TransactionStmt *n = makeNode(TransactionStmt);
11914 : :
11915 : 56 : n->kind = TRANS_STMT_RELEASE;
11916 : 56 : n->savepoint_name = $2;
11917 : 56 : n->location = @2;
11918 : 56 : $$ = (Node *) n;
11919 : : }
11920 : : | ROLLBACK opt_transaction TO SAVEPOINT ColId
11921 : : {
11922 : 167 : TransactionStmt *n = makeNode(TransactionStmt);
11923 : :
11924 : 167 : n->kind = TRANS_STMT_ROLLBACK_TO;
11925 : 167 : n->savepoint_name = $5;
11926 : 167 : n->location = @5;
11927 : 167 : $$ = (Node *) n;
11928 : : }
11929 : : | ROLLBACK opt_transaction TO ColId
11930 : : {
11931 : 320 : TransactionStmt *n = makeNode(TransactionStmt);
11932 : :
11933 : 320 : n->kind = TRANS_STMT_ROLLBACK_TO;
11934 : 320 : n->savepoint_name = $4;
11935 : 320 : n->location = @4;
11936 : 320 : $$ = (Node *) n;
11937 : : }
11938 : : | PREPARE TRANSACTION Sconst
11939 : : {
11940 : 357 : TransactionStmt *n = makeNode(TransactionStmt);
11941 : :
11942 : 357 : n->kind = TRANS_STMT_PREPARE;
11943 : 357 : n->gid = $3;
11944 : 357 : n->location = @3;
11945 : 357 : $$ = (Node *) n;
11946 : : }
11947 : : | COMMIT PREPARED Sconst
11948 : : {
11949 : 263 : TransactionStmt *n = makeNode(TransactionStmt);
11950 : :
11951 : 263 : n->kind = TRANS_STMT_COMMIT_PREPARED;
11952 : 263 : n->gid = $3;
11953 : 263 : n->location = @3;
11954 : 263 : $$ = (Node *) n;
11955 : : }
11956 : : | ROLLBACK PREPARED Sconst
11957 : : {
11958 : 46 : TransactionStmt *n = makeNode(TransactionStmt);
11959 : :
11960 : 46 : n->kind = TRANS_STMT_ROLLBACK_PREPARED;
11961 : 46 : n->gid = $3;
11962 : 46 : n->location = @3;
11963 : 46 : $$ = (Node *) n;
11964 : : }
11965 : : ;
11966 : :
11967 : : TransactionStmtLegacy:
11968 : : BEGIN_P opt_transaction transaction_mode_list_or_empty
11969 : : {
11970 : 11709 : TransactionStmt *n = makeNode(TransactionStmt);
11971 : :
11972 : 11709 : n->kind = TRANS_STMT_BEGIN;
11973 : 11709 : n->options = $3;
11974 : 11709 : n->location = -1;
11975 : 11709 : $$ = (Node *) n;
11976 : : }
11977 : : | END_P opt_transaction opt_transaction_chain
11978 : : {
11979 : 207 : TransactionStmt *n = makeNode(TransactionStmt);
11980 : :
11981 : 207 : n->kind = TRANS_STMT_COMMIT;
11982 : 207 : n->options = NIL;
11983 : 207 : n->chain = $3;
11984 : 207 : n->location = -1;
11985 : 207 : $$ = (Node *) n;
11986 : : }
11987 : : ;
11988 : :
11989 : : opt_transaction: WORK
11990 : : | TRANSACTION
11991 : : | /*EMPTY*/
11992 : : ;
11993 : :
11994 : : transaction_mode_item:
11995 : : ISOLATION LEVEL iso_level
11996 : 3850 : { $$ = makeDefElem("transaction_isolation",
11997 : 3850 : makeStringConst($3, @3), @1); }
11998 : : | READ ONLY
11999 : 761 : { $$ = makeDefElem("transaction_read_only",
12000 : 761 : makeIntConst(true, @1), @1); }
12001 : : | READ WRITE
12002 : 59 : { $$ = makeDefElem("transaction_read_only",
12003 : 59 : makeIntConst(false, @1), @1); }
12004 : : | DEFERRABLE
12005 : 32 : { $$ = makeDefElem("transaction_deferrable",
12006 : : makeIntConst(true, @1), @1); }
12007 : : | NOT DEFERRABLE
12008 : 6 : { $$ = makeDefElem("transaction_deferrable",
12009 : 6 : makeIntConst(false, @1), @1); }
12010 : : ;
12011 : :
12012 : : /* Syntax with commas is SQL-spec, without commas is Postgres historical */
12013 : : transaction_mode_list:
12014 : : transaction_mode_item
12015 : 3993 : { $$ = list_make1($1); }
12016 : : | transaction_mode_list ',' transaction_mode_item
12017 : 489 : { $$ = lappend($1, $3); }
12018 : : | transaction_mode_list transaction_mode_item
12019 : 226 : { $$ = lappend($1, $2); }
12020 : : ;
12021 : :
12022 : : transaction_mode_list_or_empty:
12023 : : transaction_mode_list
12024 : : | /* EMPTY */
12025 : 8926 : { $$ = NIL; }
12026 : : ;
12027 : :
12028 : : opt_transaction_chain:
12029 : 80 : AND CHAIN { $$ = true; }
12030 : 1 : | AND NO CHAIN { $$ = false; }
12031 : 11972 : | /* EMPTY */ { $$ = false; }
12032 : : ;
12033 : :
12034 : :
12035 : : /*****************************************************************************
12036 : : *
12037 : : * QUERY:
12038 : : * CREATE [ OR REPLACE ] [ TEMP ] VIEW <viewname> '('target-list ')'
12039 : : * AS <query> [ WITH [ CASCADED | LOCAL ] CHECK OPTION ]
12040 : : *
12041 : : *****************************************************************************/
12042 : :
12043 : : ViewStmt: CREATE OptTemp VIEW qualified_name opt_column_list opt_reloptions
12044 : : AS SelectStmt opt_check_option
12045 : : {
12046 : 10841 : ViewStmt *n = makeNode(ViewStmt);
12047 : :
12048 : 10841 : n->view = $4;
12049 : 10841 : n->view->relpersistence = $2;
12050 : 10841 : n->aliases = $5;
12051 : 10841 : n->query = $8;
12052 : 10841 : n->replace = false;
12053 : 10841 : n->options = $6;
12054 : 10841 : n->withCheckOption = $9;
12055 : 10841 : $$ = (Node *) n;
12056 : : }
12057 : : | CREATE OR REPLACE OptTemp VIEW qualified_name opt_column_list opt_reloptions
12058 : : AS SelectStmt opt_check_option
12059 : : {
12060 : 177 : ViewStmt *n = makeNode(ViewStmt);
12061 : :
12062 : 177 : n->view = $6;
12063 : 177 : n->view->relpersistence = $4;
12064 : 177 : n->aliases = $7;
12065 : 177 : n->query = $10;
12066 : 177 : n->replace = true;
12067 : 177 : n->options = $8;
12068 : 177 : n->withCheckOption = $11;
12069 : 177 : $$ = (Node *) n;
12070 : : }
12071 : : | CREATE OptTemp RECURSIVE VIEW qualified_name '(' columnList ')' opt_reloptions
12072 : : AS SelectStmt opt_check_option
12073 : : {
12074 : 5 : ViewStmt *n = makeNode(ViewStmt);
12075 : :
12076 : 5 : n->view = $5;
12077 : 5 : n->view->relpersistence = $2;
12078 : 5 : n->aliases = $7;
12079 : 5 : n->query = makeRecursiveViewSelect(n->view->relname, n->aliases, $11);
12080 : 5 : n->replace = false;
12081 : 5 : n->options = $9;
12082 : 5 : n->withCheckOption = $12;
12083 [ - + ]: 5 : if (n->withCheckOption != NO_CHECK_OPTION)
12084 [ # # ]: 0 : ereport(ERROR,
12085 : : (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
12086 : : errmsg("WITH CHECK OPTION not supported on recursive views"),
12087 : : parser_errposition(@12)));
12088 : 5 : $$ = (Node *) n;
12089 : : }
12090 : : | CREATE OR REPLACE OptTemp RECURSIVE VIEW qualified_name '(' columnList ')' opt_reloptions
12091 : : AS SelectStmt opt_check_option
12092 : : {
12093 : 4 : ViewStmt *n = makeNode(ViewStmt);
12094 : :
12095 : 4 : n->view = $7;
12096 : 4 : n->view->relpersistence = $4;
12097 : 4 : n->aliases = $9;
12098 : 4 : n->query = makeRecursiveViewSelect(n->view->relname, n->aliases, $13);
12099 : 4 : n->replace = true;
12100 : 4 : n->options = $11;
12101 : 4 : n->withCheckOption = $14;
12102 [ - + ]: 4 : if (n->withCheckOption != NO_CHECK_OPTION)
12103 [ # # ]: 0 : ereport(ERROR,
12104 : : (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
12105 : : errmsg("WITH CHECK OPTION not supported on recursive views"),
12106 : : parser_errposition(@14)));
12107 : 4 : $$ = (Node *) n;
12108 : : }
12109 : : ;
12110 : :
12111 : : opt_check_option:
12112 : 63 : WITH CHECK OPTION { $$ = CASCADED_CHECK_OPTION; }
12113 : 4 : | WITH CASCADED CHECK OPTION { $$ = CASCADED_CHECK_OPTION; }
12114 : 16 : | WITH LOCAL CHECK OPTION { $$ = LOCAL_CHECK_OPTION; }
12115 : 10944 : | /* EMPTY */ { $$ = NO_CHECK_OPTION; }
12116 : : ;
12117 : :
12118 : : /*****************************************************************************
12119 : : *
12120 : : * QUERY:
12121 : : * LOAD "filename"
12122 : : *
12123 : : *****************************************************************************/
12124 : :
12125 : : LoadStmt: LOAD file_name
12126 : : {
12127 : 46 : LoadStmt *n = makeNode(LoadStmt);
12128 : :
12129 : 46 : n->filename = $2;
12130 : 46 : $$ = (Node *) n;
12131 : : }
12132 : : ;
12133 : :
12134 : :
12135 : : /*****************************************************************************
12136 : : *
12137 : : * CREATE DATABASE
12138 : : *
12139 : : *****************************************************************************/
12140 : :
12141 : : CreatedbStmt:
12142 : : CREATE DATABASE name opt_with createdb_opt_list
12143 : : {
12144 : 443 : CreatedbStmt *n = makeNode(CreatedbStmt);
12145 : :
12146 : 443 : n->dbname = $3;
12147 : 443 : n->options = $5;
12148 : 443 : $$ = (Node *) n;
12149 : : }
12150 : : ;
12151 : :
12152 : : createdb_opt_list:
12153 : 367 : createdb_opt_items { $$ = $1; }
12154 : 115 : | /* EMPTY */ { $$ = NIL; }
12155 : : ;
12156 : :
12157 : : createdb_opt_items:
12158 : 367 : createdb_opt_item { $$ = list_make1($1); }
12159 : 555 : | createdb_opt_items createdb_opt_item { $$ = lappend($1, $2); }
12160 : : ;
12161 : :
12162 : : createdb_opt_item:
12163 : : createdb_opt_name opt_equal NumericOnly
12164 : : {
12165 : 153 : $$ = makeDefElem($1, $3, @1);
12166 : : }
12167 : : | createdb_opt_name opt_equal opt_boolean_or_string
12168 : : {
12169 : 769 : $$ = makeDefElem($1, (Node *) makeString($3), @1);
12170 : : }
12171 : : | createdb_opt_name opt_equal DEFAULT
12172 : : {
12173 : 0 : $$ = makeDefElem($1, NULL, @1);
12174 : : }
12175 : : ;
12176 : :
12177 : : /*
12178 : : * Ideally we'd use ColId here, but that causes shift/reduce conflicts against
12179 : : * the ALTER DATABASE SET/RESET syntaxes. Instead call out specific keywords
12180 : : * we need, and allow IDENT so that database option names don't have to be
12181 : : * parser keywords unless they are already keywords for other reasons.
12182 : : *
12183 : : * XXX this coding technique is fragile since if someone makes a formerly
12184 : : * non-keyword option name into a keyword and forgets to add it here, the
12185 : : * option will silently break. Best defense is to provide a regression test
12186 : : * exercising every such option, at least at the syntax level.
12187 : : */
12188 : : createdb_opt_name:
12189 : 648 : IDENT { $$ = $1; }
12190 : 2 : | CONNECTION LIMIT { $$ = pstrdup("connection_limit"); }
12191 : 58 : | ENCODING { $$ = pstrdup($1); }
12192 : 0 : | LOCATION { $$ = pstrdup($1); }
12193 : 1 : | OWNER { $$ = pstrdup($1); }
12194 : 17 : | TABLESPACE { $$ = pstrdup($1); }
12195 : 196 : | TEMPLATE { $$ = pstrdup($1); }
12196 : : ;
12197 : :
12198 : : /*
12199 : : * Though the equals sign doesn't match other WITH options, pg_dump uses
12200 : : * equals for backward compatibility, and it doesn't seem worth removing it.
12201 : : */
12202 : : opt_equal: '='
12203 : : | /*EMPTY*/
12204 : : ;
12205 : :
12206 : :
12207 : : /*****************************************************************************
12208 : : *
12209 : : * ALTER DATABASE
12210 : : *
12211 : : *****************************************************************************/
12212 : :
12213 : : AlterDatabaseStmt:
12214 : : ALTER DATABASE name WITH createdb_opt_list
12215 : : {
12216 : 1 : AlterDatabaseStmt *n = makeNode(AlterDatabaseStmt);
12217 : :
12218 : 1 : n->dbname = $3;
12219 : 1 : n->options = $5;
12220 : 1 : $$ = (Node *) n;
12221 : : }
12222 : : | ALTER DATABASE name createdb_opt_list
12223 : : {
12224 : 38 : AlterDatabaseStmt *n = makeNode(AlterDatabaseStmt);
12225 : :
12226 : 38 : n->dbname = $3;
12227 : 38 : n->options = $4;
12228 : 38 : $$ = (Node *) n;
12229 : : }
12230 : : | ALTER DATABASE name SET TABLESPACE name
12231 : : {
12232 : 14 : AlterDatabaseStmt *n = makeNode(AlterDatabaseStmt);
12233 : :
12234 : 14 : n->dbname = $3;
12235 : 14 : n->options = list_make1(makeDefElem("tablespace",
12236 : : (Node *) makeString($6), @6));
12237 : 14 : $$ = (Node *) n;
12238 : : }
12239 : : | ALTER DATABASE name REFRESH COLLATION VERSION_P
12240 : : {
12241 : 4 : AlterDatabaseRefreshCollStmt *n = makeNode(AlterDatabaseRefreshCollStmt);
12242 : :
12243 : 4 : n->dbname = $3;
12244 : 4 : $$ = (Node *) n;
12245 : : }
12246 : : ;
12247 : :
12248 : : AlterDatabaseSetStmt:
12249 : : ALTER DATABASE name SetResetClause
12250 : : {
12251 : 670 : AlterDatabaseSetStmt *n = makeNode(AlterDatabaseSetStmt);
12252 : :
12253 : 670 : n->dbname = $3;
12254 : 670 : n->setstmt = $4;
12255 : 670 : $$ = (Node *) n;
12256 : : }
12257 : : ;
12258 : :
12259 : :
12260 : : /*****************************************************************************
12261 : : *
12262 : : * DROP DATABASE [ IF EXISTS ] dbname [ [ WITH ] ( options ) ]
12263 : : *
12264 : : * This is implicitly CASCADE, no need for drop behavior
12265 : : *****************************************************************************/
12266 : :
12267 : : DropdbStmt: DROP DATABASE name
12268 : : {
12269 : 53 : DropdbStmt *n = makeNode(DropdbStmt);
12270 : :
12271 : 53 : n->dbname = $3;
12272 : 53 : n->missing_ok = false;
12273 : 53 : n->options = NULL;
12274 : 53 : $$ = (Node *) n;
12275 : : }
12276 : : | DROP DATABASE IF_P EXISTS name
12277 : : {
12278 : 3 : DropdbStmt *n = makeNode(DropdbStmt);
12279 : :
12280 : 3 : n->dbname = $5;
12281 : 3 : n->missing_ok = true;
12282 : 3 : n->options = NULL;
12283 : 3 : $$ = (Node *) n;
12284 : : }
12285 : : | DROP DATABASE name opt_with '(' drop_option_list ')'
12286 : : {
12287 : 9 : DropdbStmt *n = makeNode(DropdbStmt);
12288 : :
12289 : 9 : n->dbname = $3;
12290 : 9 : n->missing_ok = false;
12291 : 9 : n->options = $6;
12292 : 9 : $$ = (Node *) n;
12293 : : }
12294 : : | DROP DATABASE IF_P EXISTS name opt_with '(' drop_option_list ')'
12295 : : {
12296 : 8 : DropdbStmt *n = makeNode(DropdbStmt);
12297 : :
12298 : 8 : n->dbname = $5;
12299 : 8 : n->missing_ok = true;
12300 : 8 : n->options = $8;
12301 : 8 : $$ = (Node *) n;
12302 : : }
12303 : : ;
12304 : :
12305 : : drop_option_list:
12306 : : drop_option
12307 : : {
12308 : 17 : $$ = list_make1((Node *) $1);
12309 : : }
12310 : : | drop_option_list ',' drop_option
12311 : : {
12312 : 0 : $$ = lappend($1, (Node *) $3);
12313 : : }
12314 : : ;
12315 : :
12316 : : /*
12317 : : * Currently only the FORCE option is supported, but the syntax is designed
12318 : : * to be extensible so that we can add more options in the future if required.
12319 : : */
12320 : : drop_option:
12321 : : FORCE
12322 : : {
12323 : 17 : $$ = makeDefElem("force", NULL, @1);
12324 : : }
12325 : : ;
12326 : :
12327 : : /*****************************************************************************
12328 : : *
12329 : : * ALTER COLLATION
12330 : : *
12331 : : *****************************************************************************/
12332 : :
12333 : : AlterCollationStmt: ALTER COLLATION any_name REFRESH VERSION_P
12334 : : {
12335 : 4 : AlterCollationStmt *n = makeNode(AlterCollationStmt);
12336 : :
12337 : 4 : n->collname = $3;
12338 : 4 : $$ = (Node *) n;
12339 : : }
12340 : : ;
12341 : :
12342 : :
12343 : : /*****************************************************************************
12344 : : *
12345 : : * ALTER SYSTEM
12346 : : *
12347 : : * This is used to change configuration parameters persistently.
12348 : : *****************************************************************************/
12349 : :
12350 : : AlterSystemStmt:
12351 : : ALTER SYSTEM_P SET generic_set
12352 : : {
12353 : 90 : AlterSystemStmt *n = makeNode(AlterSystemStmt);
12354 : :
12355 : 90 : n->setstmt = $4;
12356 : 90 : $$ = (Node *) n;
12357 : : }
12358 : : | ALTER SYSTEM_P RESET generic_reset
12359 : : {
12360 : 29 : AlterSystemStmt *n = makeNode(AlterSystemStmt);
12361 : :
12362 : 29 : n->setstmt = $4;
12363 : 29 : $$ = (Node *) n;
12364 : : }
12365 : : ;
12366 : :
12367 : :
12368 : : /*****************************************************************************
12369 : : *
12370 : : * Manipulate a domain
12371 : : *
12372 : : *****************************************************************************/
12373 : :
12374 : : CreateDomainStmt:
12375 : : CREATE DOMAIN_P any_name opt_as Typename ColQualList
12376 : : {
12377 : 1001 : CreateDomainStmt *n = makeNode(CreateDomainStmt);
12378 : :
12379 : 1001 : n->domainname = $3;
12380 : 1001 : n->typeName = $5;
12381 : 1001 : SplitColQualList($6, &n->constraints, &n->collClause,
12382 : : yyscanner);
12383 : 1001 : $$ = (Node *) n;
12384 : : }
12385 : : ;
12386 : :
12387 : : AlterDomainStmt:
12388 : : /* ALTER DOMAIN <domain> {SET DEFAULT <expr>|DROP DEFAULT} */
12389 : : ALTER DOMAIN_P any_name alter_column_default
12390 : : {
12391 : 9 : AlterDomainStmt *n = makeNode(AlterDomainStmt);
12392 : :
12393 : 9 : n->subtype = AD_AlterDefault;
12394 : 9 : n->typeName = $3;
12395 : 9 : n->def = $4;
12396 : 9 : $$ = (Node *) n;
12397 : : }
12398 : : /* ALTER DOMAIN <domain> DROP NOT NULL */
12399 : : | ALTER DOMAIN_P any_name DROP NOT NULL_P
12400 : : {
12401 : 8 : AlterDomainStmt *n = makeNode(AlterDomainStmt);
12402 : :
12403 : 8 : n->subtype = AD_DropNotNull;
12404 : 8 : n->typeName = $3;
12405 : 8 : $$ = (Node *) n;
12406 : : }
12407 : : /* ALTER DOMAIN <domain> SET NOT NULL */
12408 : : | ALTER DOMAIN_P any_name SET NOT NULL_P
12409 : : {
12410 : 16 : AlterDomainStmt *n = makeNode(AlterDomainStmt);
12411 : :
12412 : 16 : n->subtype = AD_SetNotNull;
12413 : 16 : n->typeName = $3;
12414 : 16 : $$ = (Node *) n;
12415 : : }
12416 : : /* ALTER DOMAIN <domain> ADD CONSTRAINT ... */
12417 : : | ALTER DOMAIN_P any_name ADD_P DomainConstraint
12418 : : {
12419 : 121 : AlterDomainStmt *n = makeNode(AlterDomainStmt);
12420 : :
12421 : 121 : n->subtype = AD_AddConstraint;
12422 : 121 : n->typeName = $3;
12423 : 121 : n->def = $5;
12424 : 121 : $$ = (Node *) n;
12425 : : }
12426 : : /* ALTER DOMAIN <domain> DROP CONSTRAINT <name> [RESTRICT|CASCADE] */
12427 : : | ALTER DOMAIN_P any_name DROP CONSTRAINT name opt_drop_behavior
12428 : : {
12429 : 36 : AlterDomainStmt *n = makeNode(AlterDomainStmt);
12430 : :
12431 : 36 : n->subtype = AD_DropConstraint;
12432 : 36 : n->typeName = $3;
12433 : 36 : n->name = $6;
12434 : 36 : n->behavior = $7;
12435 : 36 : n->missing_ok = false;
12436 : 36 : $$ = (Node *) n;
12437 : : }
12438 : : /* ALTER DOMAIN <domain> DROP CONSTRAINT IF EXISTS <name> [RESTRICT|CASCADE] */
12439 : : | ALTER DOMAIN_P any_name DROP CONSTRAINT IF_P EXISTS name opt_drop_behavior
12440 : : {
12441 : 4 : AlterDomainStmt *n = makeNode(AlterDomainStmt);
12442 : :
12443 : 4 : n->subtype = AD_DropConstraint;
12444 : 4 : n->typeName = $3;
12445 : 4 : n->name = $8;
12446 : 4 : n->behavior = $9;
12447 : 4 : n->missing_ok = true;
12448 : 4 : $$ = (Node *) n;
12449 : : }
12450 : : /* ALTER DOMAIN <domain> VALIDATE CONSTRAINT <name> */
12451 : : | ALTER DOMAIN_P any_name VALIDATE CONSTRAINT name
12452 : : {
12453 : 9 : AlterDomainStmt *n = makeNode(AlterDomainStmt);
12454 : :
12455 : 9 : n->subtype = AD_ValidateConstraint;
12456 : 9 : n->typeName = $3;
12457 : 9 : n->name = $6;
12458 : 9 : $$ = (Node *) n;
12459 : : }
12460 : : ;
12461 : :
12462 : : opt_as: AS
12463 : : | /* EMPTY */
12464 : : ;
12465 : :
12466 : :
12467 : : /*****************************************************************************
12468 : : *
12469 : : * Manipulate a text search dictionary or configuration
12470 : : *
12471 : : *****************************************************************************/
12472 : :
12473 : : AlterTSDictionaryStmt:
12474 : : ALTER TEXT_P SEARCH DICTIONARY any_name definition
12475 : : {
12476 : 23 : AlterTSDictionaryStmt *n = makeNode(AlterTSDictionaryStmt);
12477 : :
12478 : 23 : n->dictname = $5;
12479 : 23 : n->options = $6;
12480 : 23 : $$ = (Node *) n;
12481 : : }
12482 : : ;
12483 : :
12484 : : AlterTSConfigurationStmt:
12485 : : ALTER TEXT_P SEARCH CONFIGURATION any_name ADD_P MAPPING FOR name_list any_with any_name_list
12486 : : {
12487 : 5200 : AlterTSConfigurationStmt *n = makeNode(AlterTSConfigurationStmt);
12488 : :
12489 : 5200 : n->kind = ALTER_TSCONFIG_ADD_MAPPING;
12490 : 5200 : n->cfgname = $5;
12491 : 5200 : n->tokentype = $9;
12492 : 5200 : n->dicts = $11;
12493 : 5200 : n->override = false;
12494 : 5200 : n->replace = false;
12495 : 5200 : $$ = (Node *) n;
12496 : : }
12497 : : | ALTER TEXT_P SEARCH CONFIGURATION any_name ALTER MAPPING FOR name_list any_with any_name_list
12498 : : {
12499 : 17 : AlterTSConfigurationStmt *n = makeNode(AlterTSConfigurationStmt);
12500 : :
12501 : 17 : n->kind = ALTER_TSCONFIG_ALTER_MAPPING_FOR_TOKEN;
12502 : 17 : n->cfgname = $5;
12503 : 17 : n->tokentype = $9;
12504 : 17 : n->dicts = $11;
12505 : 17 : n->override = true;
12506 : 17 : n->replace = false;
12507 : 17 : $$ = (Node *) n;
12508 : : }
12509 : : | ALTER TEXT_P SEARCH CONFIGURATION any_name ALTER MAPPING REPLACE any_name any_with any_name
12510 : : {
12511 : 12 : AlterTSConfigurationStmt *n = makeNode(AlterTSConfigurationStmt);
12512 : :
12513 : 12 : n->kind = ALTER_TSCONFIG_REPLACE_DICT;
12514 : 12 : n->cfgname = $5;
12515 : 12 : n->tokentype = NIL;
12516 : 12 : n->dicts = list_make2($9,$11);
12517 : 12 : n->override = false;
12518 : 12 : n->replace = true;
12519 : 12 : $$ = (Node *) n;
12520 : : }
12521 : : | ALTER TEXT_P SEARCH CONFIGURATION any_name ALTER MAPPING FOR name_list REPLACE any_name any_with any_name
12522 : : {
12523 : 0 : AlterTSConfigurationStmt *n = makeNode(AlterTSConfigurationStmt);
12524 : :
12525 : 0 : n->kind = ALTER_TSCONFIG_REPLACE_DICT_FOR_TOKEN;
12526 : 0 : n->cfgname = $5;
12527 : 0 : n->tokentype = $9;
12528 : 0 : n->dicts = list_make2($11,$13);
12529 : 0 : n->override = false;
12530 : 0 : n->replace = true;
12531 : 0 : $$ = (Node *) n;
12532 : : }
12533 : : | ALTER TEXT_P SEARCH CONFIGURATION any_name DROP MAPPING FOR name_list
12534 : : {
12535 : 13 : AlterTSConfigurationStmt *n = makeNode(AlterTSConfigurationStmt);
12536 : :
12537 : 13 : n->kind = ALTER_TSCONFIG_DROP_MAPPING;
12538 : 13 : n->cfgname = $5;
12539 : 13 : n->tokentype = $9;
12540 : 13 : n->missing_ok = false;
12541 : 13 : $$ = (Node *) n;
12542 : : }
12543 : : | ALTER TEXT_P SEARCH CONFIGURATION any_name DROP MAPPING IF_P EXISTS FOR name_list
12544 : : {
12545 : 8 : AlterTSConfigurationStmt *n = makeNode(AlterTSConfigurationStmt);
12546 : :
12547 : 8 : n->kind = ALTER_TSCONFIG_DROP_MAPPING;
12548 : 8 : n->cfgname = $5;
12549 : 8 : n->tokentype = $11;
12550 : 8 : n->missing_ok = true;
12551 : 8 : $$ = (Node *) n;
12552 : : }
12553 : : ;
12554 : :
12555 : : /* Use this if TIME or ORDINALITY after WITH should be taken as an identifier */
12556 : : any_with: WITH
12557 : : | WITH_LA
12558 : : ;
12559 : :
12560 : :
12561 : : /*****************************************************************************
12562 : : *
12563 : : * Manipulate a conversion
12564 : : *
12565 : : * CREATE [DEFAULT] CONVERSION <conversion_name>
12566 : : * FOR <encoding_name> TO <encoding_name> FROM <func_name>
12567 : : *
12568 : : *****************************************************************************/
12569 : :
12570 : : CreateConversionStmt:
12571 : : CREATE opt_default CONVERSION_P any_name FOR Sconst
12572 : : TO Sconst FROM any_name
12573 : : {
12574 : 42 : CreateConversionStmt *n = makeNode(CreateConversionStmt);
12575 : :
12576 : 42 : n->conversion_name = $4;
12577 : 42 : n->for_encoding_name = $6;
12578 : 42 : n->to_encoding_name = $8;
12579 : 42 : n->func_name = $10;
12580 : 42 : n->def = $2;
12581 : 42 : $$ = (Node *) n;
12582 : : }
12583 : : ;
12584 : :
12585 : : /*****************************************************************************
12586 : : *
12587 : : * QUERY:
12588 : : * REPACK [ (options) ] [ <qualified_name> [ <name_list> ] [ USING INDEX <index_name> ] ]
12589 : : *
12590 : : * obsolete variants:
12591 : : * CLUSTER (options) [ <qualified_name> [ USING <index_name> ] ]
12592 : : * CLUSTER [VERBOSE] [ <qualified_name> [ USING <index_name> ] ]
12593 : : * CLUSTER [VERBOSE] <index_name> ON <qualified_name> (for pre-8.3)
12594 : : *
12595 : : *****************************************************************************/
12596 : :
12597 : : RepackStmt:
12598 : : REPACK opt_utility_option_list vacuum_relation USING INDEX name
12599 : : {
12600 : 19 : RepackStmt *n = makeNode(RepackStmt);
12601 : :
12602 : 19 : n->command = REPACK_COMMAND_REPACK;
12603 : 19 : n->relation = (VacuumRelation *) $3;
12604 : 19 : n->indexname = $6;
12605 : 19 : n->usingindex = true;
12606 : 19 : n->params = $2;
12607 : 19 : $$ = (Node *) n;
12608 : : }
12609 : : | REPACK opt_utility_option_list vacuum_relation opt_usingindex
12610 : : {
12611 : 36 : RepackStmt *n = makeNode(RepackStmt);
12612 : :
12613 : 36 : n->command = REPACK_COMMAND_REPACK;
12614 : 36 : n->relation = (VacuumRelation *) $3;
12615 : 36 : n->indexname = NULL;
12616 : 36 : n->usingindex = $4;
12617 : 36 : n->params = $2;
12618 : 36 : $$ = (Node *) n;
12619 : : }
12620 : : | REPACK opt_utility_option_list opt_usingindex
12621 : : {
12622 : 4 : RepackStmt *n = makeNode(RepackStmt);
12623 : :
12624 : 4 : n->command = REPACK_COMMAND_REPACK;
12625 : 4 : n->relation = NULL;
12626 : 4 : n->indexname = NULL;
12627 : 4 : n->usingindex = $3;
12628 : 4 : n->params = $2;
12629 : 4 : $$ = (Node *) n;
12630 : : }
12631 : : | CLUSTER '(' utility_option_list ')' qualified_name cluster_index_specification
12632 : : {
12633 : 0 : RepackStmt *n = makeNode(RepackStmt);
12634 : :
12635 : 0 : n->command = REPACK_COMMAND_CLUSTER;
12636 : 0 : n->relation = makeNode(VacuumRelation);
12637 : 0 : n->relation->relation = $5;
12638 : 0 : n->indexname = $6;
12639 : 0 : n->usingindex = true;
12640 : 0 : n->params = $3;
12641 : 0 : $$ = (Node *) n;
12642 : : }
12643 : : | CLUSTER opt_utility_option_list
12644 : : {
12645 : 9 : RepackStmt *n = makeNode(RepackStmt);
12646 : :
12647 : 9 : n->command = REPACK_COMMAND_CLUSTER;
12648 : 9 : n->relation = NULL;
12649 : 9 : n->indexname = NULL;
12650 : 9 : n->usingindex = true;
12651 : 9 : n->params = $2;
12652 : 9 : $$ = (Node *) n;
12653 : : }
12654 : : /* unparenthesized VERBOSE kept for pre-14 compatibility */
12655 : : | CLUSTER opt_verbose qualified_name cluster_index_specification
12656 : : {
12657 : 146 : RepackStmt *n = makeNode(RepackStmt);
12658 : :
12659 : 146 : n->command = REPACK_COMMAND_CLUSTER;
12660 : 146 : n->relation = makeNode(VacuumRelation);
12661 : 146 : n->relation->relation = $3;
12662 : 146 : n->indexname = $4;
12663 : 146 : n->usingindex = true;
12664 [ - + ]: 146 : if ($2)
12665 : 0 : n->params = list_make1(makeDefElem("verbose", NULL, @2));
12666 : 146 : $$ = (Node *) n;
12667 : : }
12668 : : /* unparenthesized VERBOSE kept for pre-17 compatibility */
12669 : : | CLUSTER VERBOSE
12670 : : {
12671 : 3 : RepackStmt *n = makeNode(RepackStmt);
12672 : :
12673 : 3 : n->command = REPACK_COMMAND_CLUSTER;
12674 : 3 : n->relation = NULL;
12675 : 3 : n->indexname = NULL;
12676 : 3 : n->usingindex = true;
12677 : 3 : n->params = list_make1(makeDefElem("verbose", NULL, @2));
12678 : 3 : $$ = (Node *) n;
12679 : : }
12680 : : /* kept for pre-8.3 compatibility */
12681 : : | CLUSTER opt_verbose name ON qualified_name
12682 : : {
12683 : 13 : RepackStmt *n = makeNode(RepackStmt);
12684 : :
12685 : 13 : n->command = REPACK_COMMAND_CLUSTER;
12686 : 13 : n->relation = makeNode(VacuumRelation);
12687 : 13 : n->relation->relation = $5;
12688 : 13 : n->indexname = $3;
12689 : 13 : n->usingindex = true;
12690 [ - + ]: 13 : if ($2)
12691 : 0 : n->params = list_make1(makeDefElem("verbose", NULL, @2));
12692 : 13 : $$ = (Node *) n;
12693 : : }
12694 : : ;
12695 : :
12696 : : cluster_index_specification:
12697 : 123 : USING name { $$ = $2; }
12698 : 23 : | /*EMPTY*/ { $$ = NULL; }
12699 : : ;
12700 : :
12701 : :
12702 : : /*****************************************************************************
12703 : : *
12704 : : * QUERY:
12705 : : * VACUUM
12706 : : * ANALYZE
12707 : : *
12708 : : *****************************************************************************/
12709 : :
12710 : : VacuumStmt: VACUUM opt_full opt_freeze opt_verbose opt_analyze opt_vacuum_relation_list
12711 : : {
12712 : 789 : VacuumStmt *n = makeNode(VacuumStmt);
12713 : :
12714 : 789 : n->options = NIL;
12715 [ + + ]: 789 : if ($2)
12716 : 93 : n->options = lappend(n->options,
12717 : 93 : makeDefElem("full", NULL, @2));
12718 [ + + ]: 789 : if ($3)
12719 : 90 : n->options = lappend(n->options,
12720 : 90 : makeDefElem("freeze", NULL, @3));
12721 [ + + ]: 789 : if ($4)
12722 : 9 : n->options = lappend(n->options,
12723 : 9 : makeDefElem("verbose", NULL, @4));
12724 [ + + ]: 789 : if ($5)
12725 : 216 : n->options = lappend(n->options,
12726 : 216 : makeDefElem("analyze", NULL, @5));
12727 : 789 : n->rels = $6;
12728 : 789 : n->is_vacuumcmd = true;
12729 : 789 : $$ = (Node *) n;
12730 : : }
12731 : : | VACUUM '(' utility_option_list ')' opt_vacuum_relation_list
12732 : : {
12733 : 5035 : VacuumStmt *n = makeNode(VacuumStmt);
12734 : :
12735 : 5035 : n->options = $3;
12736 : 5035 : n->rels = $5;
12737 : 5035 : n->is_vacuumcmd = true;
12738 : 5035 : $$ = (Node *) n;
12739 : : }
12740 : : ;
12741 : :
12742 : : AnalyzeStmt: analyze_keyword opt_utility_option_list opt_vacuum_relation_list
12743 : : {
12744 : 3167 : VacuumStmt *n = makeNode(VacuumStmt);
12745 : :
12746 : 3167 : n->options = $2;
12747 : 3167 : n->rels = $3;
12748 : 3167 : n->is_vacuumcmd = false;
12749 : 3167 : $$ = (Node *) n;
12750 : : }
12751 : : | analyze_keyword VERBOSE opt_vacuum_relation_list
12752 : : {
12753 : 7 : VacuumStmt *n = makeNode(VacuumStmt);
12754 : :
12755 : 7 : n->options = list_make1(makeDefElem("verbose", NULL, @2));
12756 : 7 : n->rels = $3;
12757 : 7 : n->is_vacuumcmd = false;
12758 : 7 : $$ = (Node *) n;
12759 : : }
12760 : : ;
12761 : :
12762 : : analyze_keyword:
12763 : : ANALYZE
12764 : : | ANALYSE /* British */
12765 : : ;
12766 : :
12767 : : opt_analyze:
12768 : 216 : analyze_keyword { $$ = true; }
12769 : 573 : | /*EMPTY*/ { $$ = false; }
12770 : : ;
12771 : :
12772 : : opt_verbose:
12773 : 9 : VERBOSE { $$ = true; }
12774 : 2515 : | /*EMPTY*/ { $$ = false; }
12775 : : ;
12776 : :
12777 : 93 : opt_full: FULL { $$ = true; }
12778 : 696 : | /*EMPTY*/ { $$ = false; }
12779 : : ;
12780 : :
12781 : 90 : opt_freeze: FREEZE { $$ = true; }
12782 : 699 : | /*EMPTY*/ { $$ = false; }
12783 : : ;
12784 : :
12785 : : opt_name_list:
12786 : 1798 : '(' name_list ')' { $$ = $2; }
12787 : 10764 : | /*EMPTY*/ { $$ = NIL; }
12788 : : ;
12789 : :
12790 : : vacuum_relation:
12791 : : relation_expr opt_name_list
12792 : : {
12793 : 8966 : $$ = (Node *) makeVacuumRelation($1, InvalidOid, $2);
12794 : : }
12795 : : ;
12796 : :
12797 : : vacuum_relation_list:
12798 : : vacuum_relation
12799 : 8790 : { $$ = list_make1($1); }
12800 : : | vacuum_relation_list ',' vacuum_relation
12801 : 121 : { $$ = lappend($1, $3); }
12802 : : ;
12803 : :
12804 : : opt_vacuum_relation_list:
12805 : 8790 : vacuum_relation_list { $$ = $1; }
12806 : 208 : | /*EMPTY*/ { $$ = NIL; }
12807 : : ;
12808 : :
12809 : :
12810 : : /*****************************************************************************
12811 : : *
12812 : : * QUERY:
12813 : : * EXPLAIN [ANALYZE] [VERBOSE] query
12814 : : * EXPLAIN ( options ) query
12815 : : *
12816 : : *****************************************************************************/
12817 : :
12818 : : ExplainStmt:
12819 : : EXPLAIN ExplainableStmt
12820 : : {
12821 : 4751 : ExplainStmt *n = makeNode(ExplainStmt);
12822 : :
12823 : 4751 : n->query = $2;
12824 : 4751 : n->options = NIL;
12825 : 4751 : $$ = (Node *) n;
12826 : : }
12827 : : | EXPLAIN analyze_keyword opt_verbose ExplainableStmt
12828 : : {
12829 : 1576 : ExplainStmt *n = makeNode(ExplainStmt);
12830 : :
12831 : 1576 : n->query = $4;
12832 : 1576 : n->options = list_make1(makeDefElem("analyze", NULL, @2));
12833 [ - + ]: 1576 : if ($3)
12834 : 0 : n->options = lappend(n->options,
12835 : 0 : makeDefElem("verbose", NULL, @3));
12836 : 1576 : $$ = (Node *) n;
12837 : : }
12838 : : | EXPLAIN VERBOSE ExplainableStmt
12839 : : {
12840 : 8 : ExplainStmt *n = makeNode(ExplainStmt);
12841 : :
12842 : 8 : n->query = $3;
12843 : 8 : n->options = list_make1(makeDefElem("verbose", NULL, @2));
12844 : 8 : $$ = (Node *) n;
12845 : : }
12846 : : | EXPLAIN '(' utility_option_list ')' ExplainableStmt
12847 : : {
12848 : 10375 : ExplainStmt *n = makeNode(ExplainStmt);
12849 : :
12850 : 10375 : n->query = $5;
12851 : 10375 : n->options = $3;
12852 : 10375 : $$ = (Node *) n;
12853 : : }
12854 : : ;
12855 : :
12856 : : ExplainableStmt:
12857 : : SelectStmt
12858 : : | InsertStmt
12859 : : | UpdateStmt
12860 : : | DeleteStmt
12861 : : | MergeStmt
12862 : : | DeclareCursorStmt
12863 : : | CreateAsStmt
12864 : : | CreateMatViewStmt
12865 : : | RefreshMatViewStmt
12866 : : | ExecuteStmt /* by default all are $$=$1 */
12867 : : ;
12868 : :
12869 : : /*****************************************************************************
12870 : : *
12871 : : * QUERY:
12872 : : * PREPARE <plan_name> [(args, ...)] AS <query>
12873 : : *
12874 : : *****************************************************************************/
12875 : :
12876 : : PrepareStmt: PREPARE name prep_type_clause AS PreparableStmt
12877 : : {
12878 : 1138 : PrepareStmt *n = makeNode(PrepareStmt);
12879 : :
12880 : 1138 : n->name = $2;
12881 : 1138 : n->argtypes = $3;
12882 : 1138 : n->query = $5;
12883 : 1138 : $$ = (Node *) n;
12884 : : }
12885 : : ;
12886 : :
12887 : 911 : prep_type_clause: '(' type_list ')' { $$ = $2; }
12888 : 239 : | /* EMPTY */ { $$ = NIL; }
12889 : : ;
12890 : :
12891 : : PreparableStmt:
12892 : : SelectStmt
12893 : : | InsertStmt
12894 : : | UpdateStmt
12895 : : | DeleteStmt
12896 : : | MergeStmt /* by default all are $$=$1 */
12897 : : ;
12898 : :
12899 : : /*****************************************************************************
12900 : : *
12901 : : * EXECUTE <plan_name> [(params, ...)]
12902 : : * CREATE TABLE <name> AS EXECUTE <plan_name> [(params, ...)]
12903 : : *
12904 : : *****************************************************************************/
12905 : :
12906 : : ExecuteStmt: EXECUTE name execute_param_clause
12907 : : {
12908 : 8972 : ExecuteStmt *n = makeNode(ExecuteStmt);
12909 : :
12910 : 8972 : n->name = $2;
12911 : 8972 : n->params = $3;
12912 : 8972 : $$ = (Node *) n;
12913 : : }
12914 : : | CREATE OptTemp TABLE create_as_target AS
12915 : : EXECUTE name execute_param_clause opt_with_data
12916 : : {
12917 : 50 : CreateTableAsStmt *ctas = makeNode(CreateTableAsStmt);
12918 : 50 : ExecuteStmt *n = makeNode(ExecuteStmt);
12919 : :
12920 : 50 : n->name = $7;
12921 : 50 : n->params = $8;
12922 : 50 : ctas->query = (Node *) n;
12923 : 50 : ctas->into = $4;
12924 : 50 : ctas->objtype = OBJECT_TABLE;
12925 : 50 : ctas->is_select_into = false;
12926 : 50 : ctas->if_not_exists = false;
12927 : : /* cram additional flags into the IntoClause */
12928 : 50 : $4->rel->relpersistence = $2;
12929 : 50 : $4->skipData = !($9);
12930 : 50 : $$ = (Node *) ctas;
12931 : : }
12932 : : | CREATE OptTemp TABLE IF_P NOT EXISTS create_as_target AS
12933 : : EXECUTE name execute_param_clause opt_with_data
12934 : : {
12935 : 8 : CreateTableAsStmt *ctas = makeNode(CreateTableAsStmt);
12936 : 8 : ExecuteStmt *n = makeNode(ExecuteStmt);
12937 : :
12938 : 8 : n->name = $10;
12939 : 8 : n->params = $11;
12940 : 8 : ctas->query = (Node *) n;
12941 : 8 : ctas->into = $7;
12942 : 8 : ctas->objtype = OBJECT_TABLE;
12943 : 8 : ctas->is_select_into = false;
12944 : 8 : ctas->if_not_exists = true;
12945 : : /* cram additional flags into the IntoClause */
12946 : 8 : $7->rel->relpersistence = $2;
12947 : 8 : $7->skipData = !($12);
12948 : 8 : $$ = (Node *) ctas;
12949 : : }
12950 : : ;
12951 : :
12952 : 8098 : execute_param_clause: '(' expr_list ')' { $$ = $2; }
12953 : 932 : | /* EMPTY */ { $$ = NIL; }
12954 : : ;
12955 : :
12956 : : /*****************************************************************************
12957 : : *
12958 : : * QUERY:
12959 : : * DEALLOCATE [PREPARE] <plan_name>
12960 : : *
12961 : : *****************************************************************************/
12962 : :
12963 : : DeallocateStmt: DEALLOCATE name
12964 : : {
12965 : 2048 : DeallocateStmt *n = makeNode(DeallocateStmt);
12966 : :
12967 : 2048 : n->name = $2;
12968 : 2048 : n->isall = false;
12969 : 2048 : n->location = @2;
12970 : 2048 : $$ = (Node *) n;
12971 : : }
12972 : : | DEALLOCATE PREPARE name
12973 : : {
12974 : 13 : DeallocateStmt *n = makeNode(DeallocateStmt);
12975 : :
12976 : 13 : n->name = $3;
12977 : 13 : n->isall = false;
12978 : 13 : n->location = @3;
12979 : 13 : $$ = (Node *) n;
12980 : : }
12981 : : | DEALLOCATE ALL
12982 : : {
12983 : 36 : DeallocateStmt *n = makeNode(DeallocateStmt);
12984 : :
12985 : 36 : n->name = NULL;
12986 : 36 : n->isall = true;
12987 : 36 : n->location = -1;
12988 : 36 : $$ = (Node *) n;
12989 : : }
12990 : : | DEALLOCATE PREPARE ALL
12991 : : {
12992 : 1 : DeallocateStmt *n = makeNode(DeallocateStmt);
12993 : :
12994 : 1 : n->name = NULL;
12995 : 1 : n->isall = true;
12996 : 1 : n->location = -1;
12997 : 1 : $$ = (Node *) n;
12998 : : }
12999 : : ;
13000 : :
13001 : : /*****************************************************************************
13002 : : *
13003 : : * QUERY:
13004 : : * INSERT STATEMENTS
13005 : : *
13006 : : *****************************************************************************/
13007 : :
13008 : : InsertStmt:
13009 : : opt_with_clause INSERT INTO insert_target insert_rest
13010 : : opt_on_conflict returning_clause
13011 : : {
13012 : 45687 : $5->relation = $4;
13013 : 45687 : $5->onConflictClause = $6;
13014 : 45687 : $5->returningClause = $7;
13015 : 45687 : $5->withClause = $1;
13016 : 45687 : $$ = (Node *) $5;
13017 : : }
13018 : : ;
13019 : :
13020 : : /*
13021 : : * Can't easily make AS optional here, because VALUES in insert_rest would
13022 : : * have a shift/reduce conflict with VALUES as an optional alias. We could
13023 : : * easily allow unreserved_keywords as optional aliases, but that'd be an odd
13024 : : * divergence from other places. So just require AS for now.
13025 : : */
13026 : : insert_target:
13027 : : qualified_name
13028 : : {
13029 : 45580 : $$ = $1;
13030 : : }
13031 : : | qualified_name AS ColId
13032 : : {
13033 : 111 : $1->alias = makeAlias($3, NIL);
13034 : 111 : $$ = $1;
13035 : : }
13036 : : ;
13037 : :
13038 : : insert_rest:
13039 : : SelectStmt
13040 : : {
13041 : 31072 : $$ = makeNode(InsertStmt);
13042 : 31072 : $$->cols = NIL;
13043 : 31072 : $$->selectStmt = $1;
13044 : : }
13045 : : | OVERRIDING override_kind VALUE_P SelectStmt
13046 : : {
13047 : 64 : $$ = makeNode(InsertStmt);
13048 : 64 : $$->cols = NIL;
13049 : 64 : $$->override = $2;
13050 : 64 : $$->selectStmt = $4;
13051 : : }
13052 : : | '(' insert_column_list ')' SelectStmt
13053 : : {
13054 : 9004 : $$ = makeNode(InsertStmt);
13055 : 9004 : $$->cols = $2;
13056 : 9004 : $$->selectStmt = $4;
13057 : : }
13058 : : | '(' insert_column_list ')' OVERRIDING override_kind VALUE_P SelectStmt
13059 : : {
13060 : 0 : $$ = makeNode(InsertStmt);
13061 : 0 : $$->cols = $2;
13062 : 0 : $$->override = $5;
13063 : 0 : $$->selectStmt = $7;
13064 : : }
13065 : : | DEFAULT VALUES
13066 : : {
13067 : 5551 : $$ = makeNode(InsertStmt);
13068 : 5551 : $$->cols = NIL;
13069 : 5551 : $$->selectStmt = NULL;
13070 : : }
13071 : : ;
13072 : :
13073 : : override_kind:
13074 : 44 : USER { $$ = OVERRIDING_USER_VALUE; }
13075 : 40 : | SYSTEM_P { $$ = OVERRIDING_SYSTEM_VALUE; }
13076 : : ;
13077 : :
13078 : : insert_column_list:
13079 : : insert_column_item
13080 : 9223 : { $$ = list_make1($1); }
13081 : : | insert_column_list ',' insert_column_item
13082 : 10021 : { $$ = lappend($1, $3); }
13083 : : ;
13084 : :
13085 : : insert_column_item:
13086 : : ColId opt_indirection
13087 : : {
13088 : 19244 : $$ = makeNode(ResTarget);
13089 : 19244 : $$->name = $1;
13090 : 19244 : $$->indirection = check_indirection($2, yyscanner);
13091 : 19244 : $$->val = NULL;
13092 : 19244 : $$->location = @1;
13093 : : }
13094 : : ;
13095 : :
13096 : : opt_on_conflict:
13097 : : ON CONFLICT opt_conf_expr DO SELECT opt_for_locking_strength where_clause
13098 : : {
13099 : 240 : $$ = makeNode(OnConflictClause);
13100 : 240 : $$->action = ONCONFLICT_SELECT;
13101 : 240 : $$->infer = $3;
13102 : 240 : $$->targetList = NIL;
13103 : 240 : $$->lockStrength = $6;
13104 : 240 : $$->whereClause = $7;
13105 : 240 : $$->location = @1;
13106 : : }
13107 : : |
13108 : : ON CONFLICT opt_conf_expr DO UPDATE SET set_clause_list where_clause
13109 : : {
13110 : 935 : $$ = makeNode(OnConflictClause);
13111 : 935 : $$->action = ONCONFLICT_UPDATE;
13112 : 935 : $$->infer = $3;
13113 : 935 : $$->targetList = $7;
13114 : 935 : $$->lockStrength = LCS_NONE;
13115 : 935 : $$->whereClause = $8;
13116 : 935 : $$->location = @1;
13117 : : }
13118 : : |
13119 : : ON CONFLICT opt_conf_expr DO NOTHING
13120 : : {
13121 : 386 : $$ = makeNode(OnConflictClause);
13122 : 386 : $$->action = ONCONFLICT_NOTHING;
13123 : 386 : $$->infer = $3;
13124 : 386 : $$->targetList = NIL;
13125 : 386 : $$->lockStrength = LCS_NONE;
13126 : 386 : $$->whereClause = NULL;
13127 : 386 : $$->location = @1;
13128 : : }
13129 : : | /*EMPTY*/
13130 : : {
13131 : 44130 : $$ = NULL;
13132 : : }
13133 : : ;
13134 : :
13135 : : opt_conf_expr:
13136 : : '(' index_params ')' where_clause
13137 : : {
13138 : 1271 : $$ = makeNode(InferClause);
13139 : 1271 : $$->indexElems = $2;
13140 : 1271 : $$->whereClause = $4;
13141 : 1271 : $$->conname = NULL;
13142 : 1271 : $$->location = @1;
13143 : : }
13144 : : |
13145 : : ON CONSTRAINT name
13146 : : {
13147 : 138 : $$ = makeNode(InferClause);
13148 : 138 : $$->indexElems = NIL;
13149 : 138 : $$->whereClause = NULL;
13150 : 138 : $$->conname = $3;
13151 : 138 : $$->location = @1;
13152 : : }
13153 : : | /*EMPTY*/
13154 : : {
13155 : 152 : $$ = NULL;
13156 : : }
13157 : : ;
13158 : :
13159 : : returning_clause:
13160 : : RETURNING returning_with_clause target_list
13161 : : {
13162 : 2414 : ReturningClause *n = makeNode(ReturningClause);
13163 : :
13164 : 2414 : n->options = $2;
13165 : 2414 : n->exprs = $3;
13166 : 2414 : $$ = n;
13167 : : }
13168 : : | /* EMPTY */
13169 : : {
13170 : 57737 : $$ = NULL;
13171 : : }
13172 : : ;
13173 : :
13174 : : returning_with_clause:
13175 : 48 : WITH '(' returning_options ')' { $$ = $3; }
13176 : 2366 : | /* EMPTY */ { $$ = NIL; }
13177 : : ;
13178 : :
13179 : : returning_options:
13180 : 48 : returning_option { $$ = list_make1($1); }
13181 : 36 : | returning_options ',' returning_option { $$ = lappend($1, $3); }
13182 : : ;
13183 : :
13184 : : returning_option:
13185 : : returning_option_kind AS ColId
13186 : : {
13187 : 84 : ReturningOption *n = makeNode(ReturningOption);
13188 : :
13189 : 84 : n->option = $1;
13190 : 84 : n->value = $3;
13191 : 84 : n->location = @1;
13192 : 84 : $$ = (Node *) n;
13193 : : }
13194 : : ;
13195 : :
13196 : : returning_option_kind:
13197 : 36 : OLD { $$ = RETURNING_OPTION_OLD; }
13198 : 48 : | NEW { $$ = RETURNING_OPTION_NEW; }
13199 : : ;
13200 : :
13201 : :
13202 : : /*****************************************************************************
13203 : : *
13204 : : * QUERY:
13205 : : * DELETE STATEMENTS
13206 : : *
13207 : : *****************************************************************************/
13208 : :
13209 : : DeleteStmt: opt_with_clause DELETE_P FROM relation_expr_opt_alias
13210 : : using_clause where_or_current_clause returning_clause
13211 : : {
13212 : 3008 : DeleteStmt *n = makeNode(DeleteStmt);
13213 : :
13214 : 3008 : n->relation = $4;
13215 : 3008 : n->usingClause = $5;
13216 : 3008 : n->whereClause = $6;
13217 : 3008 : n->returningClause = $7;
13218 : 3008 : n->withClause = $1;
13219 : 3008 : $$ = (Node *) n;
13220 : : }
13221 : : | opt_with_clause DELETE_P FROM relation_expr
13222 : : for_portion_of_clause for_portion_of_opt_alias
13223 : : using_clause where_or_current_clause returning_clause
13224 : : {
13225 : 495 : DeleteStmt *n = makeNode(DeleteStmt);
13226 : :
13227 : 495 : n->relation = $4;
13228 : 495 : n->forPortionOf = (ForPortionOfClause *) $5;
13229 : 495 : n->relation->alias = $6;
13230 : 495 : n->usingClause = $7;
13231 : 495 : n->whereClause = $8;
13232 : 495 : n->returningClause = $9;
13233 : 495 : n->withClause = $1;
13234 : 495 : $$ = (Node *) n;
13235 : : }
13236 : : ;
13237 : :
13238 : : using_clause:
13239 : 72 : USING from_list { $$ = $2; }
13240 : 3431 : | /*EMPTY*/ { $$ = NIL; }
13241 : : ;
13242 : :
13243 : :
13244 : : /*****************************************************************************
13245 : : *
13246 : : * QUERY:
13247 : : * LOCK TABLE
13248 : : *
13249 : : *****************************************************************************/
13250 : :
13251 : : LockStmt: LOCK_P opt_table relation_expr_list opt_lock opt_nowait
13252 : : {
13253 : 596 : LockStmt *n = makeNode(LockStmt);
13254 : :
13255 : 596 : n->relations = $3;
13256 : 596 : n->mode = $4;
13257 : 596 : n->nowait = $5;
13258 : 596 : $$ = (Node *) n;
13259 : : }
13260 : : ;
13261 : :
13262 : 528 : opt_lock: IN_P lock_type MODE { $$ = $2; }
13263 : 68 : | /*EMPTY*/ { $$ = AccessExclusiveLock; }
13264 : : ;
13265 : :
13266 : 239 : lock_type: ACCESS SHARE { $$ = AccessShareLock; }
13267 : 9 : | ROW SHARE { $$ = RowShareLock; }
13268 : 52 : | ROW EXCLUSIVE { $$ = RowExclusiveLock; }
13269 : 35 : | SHARE UPDATE EXCLUSIVE { $$ = ShareUpdateExclusiveLock; }
13270 : 42 : | SHARE { $$ = ShareLock; }
13271 : 9 : | SHARE ROW EXCLUSIVE { $$ = ShareRowExclusiveLock; }
13272 : 63 : | EXCLUSIVE { $$ = ExclusiveLock; }
13273 : 79 : | ACCESS EXCLUSIVE { $$ = AccessExclusiveLock; }
13274 : : ;
13275 : :
13276 : 102 : opt_nowait: NOWAIT { $$ = true; }
13277 : 510 : | /*EMPTY*/ { $$ = false; }
13278 : : ;
13279 : :
13280 : : opt_nowait_or_skip:
13281 : 29 : NOWAIT { $$ = LockWaitError; }
13282 : 96 : | SKIP LOCKED { $$ = LockWaitSkip; }
13283 : 4944 : | /*EMPTY*/ { $$ = LockWaitBlock; }
13284 : : ;
13285 : :
13286 : :
13287 : : /*****************************************************************************
13288 : : *
13289 : : * QUERY:
13290 : : * UpdateStmt (UPDATE)
13291 : : *
13292 : : *****************************************************************************/
13293 : :
13294 : : UpdateStmt: opt_with_clause UPDATE relation_expr_opt_alias
13295 : : SET set_clause_list
13296 : : from_clause
13297 : : where_or_current_clause
13298 : : returning_clause
13299 : : {
13300 : 8885 : UpdateStmt *n = makeNode(UpdateStmt);
13301 : :
13302 : 8885 : n->relation = $3;
13303 : 8885 : n->targetList = $5;
13304 : 8885 : n->fromClause = $6;
13305 : 8885 : n->whereClause = $7;
13306 : 8885 : n->returningClause = $8;
13307 : 8885 : n->withClause = $1;
13308 : 8885 : $$ = (Node *) n;
13309 : : }
13310 : : | opt_with_clause UPDATE relation_expr
13311 : : for_portion_of_clause for_portion_of_opt_alias
13312 : : SET set_clause_list
13313 : : from_clause
13314 : : where_or_current_clause
13315 : : returning_clause
13316 : : {
13317 : 646 : UpdateStmt *n = makeNode(UpdateStmt);
13318 : :
13319 : 646 : n->relation = $3;
13320 : 646 : n->forPortionOf = (ForPortionOfClause *) $4;
13321 : 646 : n->relation->alias = $5;
13322 : 646 : n->targetList = $7;
13323 : 646 : n->fromClause = $8;
13324 : 646 : n->whereClause = $9;
13325 : 646 : n->returningClause = $10;
13326 : 646 : n->withClause = $1;
13327 : 646 : $$ = (Node *) n;
13328 : : }
13329 : : ;
13330 : :
13331 : : set_clause_list:
13332 : 11521 : set_clause { $$ = $1; }
13333 : 2545 : | set_clause_list ',' set_clause { $$ = list_concat($1,$3); }
13334 : : ;
13335 : :
13336 : : set_clause:
13337 : : set_target '=' a_expr
13338 : : {
13339 : 13945 : $1->val = (Node *) $3;
13340 : 13945 : $$ = list_make1($1);
13341 : : }
13342 : : | '(' set_target_list ')' '=' a_expr
13343 : : {
13344 : 121 : int ncolumns = list_length($2);
13345 : 121 : int i = 1;
13346 : : ListCell *col_cell;
13347 : :
13348 : : /* Create a MultiAssignRef source for each target */
13349 [ + - + + : 374 : foreach(col_cell, $2)
+ + ]
13350 : : {
13351 : 253 : ResTarget *res_col = (ResTarget *) lfirst(col_cell);
13352 : 253 : MultiAssignRef *r = makeNode(MultiAssignRef);
13353 : :
13354 : 253 : r->source = (Node *) $5;
13355 : 253 : r->colno = i;
13356 : 253 : r->ncolumns = ncolumns;
13357 : 253 : res_col->val = (Node *) r;
13358 : 253 : i++;
13359 : : }
13360 : :
13361 : 121 : $$ = $2;
13362 : : }
13363 : : ;
13364 : :
13365 : : set_target:
13366 : : ColId opt_indirection
13367 : : {
13368 : 14202 : $$ = makeNode(ResTarget);
13369 : 14202 : $$->name = $1;
13370 : 14202 : $$->indirection = check_indirection($2, yyscanner);
13371 : 14202 : $$->val = NULL; /* upper production sets this */
13372 : 14202 : $$->location = @1;
13373 : : }
13374 : : ;
13375 : :
13376 : : set_target_list:
13377 : 125 : set_target { $$ = list_make1($1); }
13378 : 132 : | set_target_list ',' set_target { $$ = lappend($1,$3); }
13379 : : ;
13380 : :
13381 : :
13382 : : /*****************************************************************************
13383 : : *
13384 : : * QUERY:
13385 : : * MERGE
13386 : : *
13387 : : *****************************************************************************/
13388 : :
13389 : : MergeStmt:
13390 : : opt_with_clause MERGE INTO relation_expr_opt_alias
13391 : : USING table_ref
13392 : : ON a_expr
13393 : : merge_when_list
13394 : : returning_clause
13395 : : {
13396 : 1430 : MergeStmt *m = makeNode(MergeStmt);
13397 : :
13398 : 1430 : m->withClause = $1;
13399 : 1430 : m->relation = $4;
13400 : 1430 : m->sourceRelation = $6;
13401 : 1430 : m->joinCondition = $8;
13402 : 1430 : m->mergeWhenClauses = $9;
13403 : 1430 : m->returningClause = $10;
13404 : :
13405 : 1430 : $$ = (Node *) m;
13406 : : }
13407 : : ;
13408 : :
13409 : : merge_when_list:
13410 : 1430 : merge_when_clause { $$ = list_make1($1); }
13411 : 799 : | merge_when_list merge_when_clause { $$ = lappend($1,$2); }
13412 : : ;
13413 : :
13414 : : /*
13415 : : * A WHEN clause may be WHEN MATCHED, WHEN NOT MATCHED BY SOURCE, or WHEN NOT
13416 : : * MATCHED [BY TARGET]. The first two cases match target tuples, and support
13417 : : * UPDATE/DELETE/DO NOTHING actions. The third case does not match target
13418 : : * tuples, and only supports INSERT/DO NOTHING actions.
13419 : : */
13420 : : merge_when_clause:
13421 : : merge_when_tgt_matched opt_merge_when_condition THEN merge_update
13422 : : {
13423 : 1055 : $4->matchKind = $1;
13424 : 1055 : $4->condition = $2;
13425 : :
13426 : 1055 : $$ = (Node *) $4;
13427 : : }
13428 : : | merge_when_tgt_matched opt_merge_when_condition THEN merge_delete
13429 : : {
13430 : 375 : $4->matchKind = $1;
13431 : 375 : $4->condition = $2;
13432 : :
13433 : 375 : $$ = (Node *) $4;
13434 : : }
13435 : : | merge_when_tgt_not_matched opt_merge_when_condition THEN merge_insert
13436 : : {
13437 : 736 : $4->matchKind = $1;
13438 : 736 : $4->condition = $2;
13439 : :
13440 : 736 : $$ = (Node *) $4;
13441 : : }
13442 : : | merge_when_tgt_matched opt_merge_when_condition THEN DO NOTHING
13443 : : {
13444 : 46 : MergeWhenClause *m = makeNode(MergeWhenClause);
13445 : :
13446 : 46 : m->matchKind = $1;
13447 : 46 : m->commandType = CMD_NOTHING;
13448 : 46 : m->condition = $2;
13449 : :
13450 : 46 : $$ = (Node *) m;
13451 : : }
13452 : : | merge_when_tgt_not_matched opt_merge_when_condition THEN DO NOTHING
13453 : : {
13454 : 17 : MergeWhenClause *m = makeNode(MergeWhenClause);
13455 : :
13456 : 17 : m->matchKind = $1;
13457 : 17 : m->commandType = CMD_NOTHING;
13458 : 17 : m->condition = $2;
13459 : :
13460 : 17 : $$ = (Node *) m;
13461 : : }
13462 : : ;
13463 : :
13464 : : merge_when_tgt_matched:
13465 : 1366 : WHEN MATCHED { $$ = MERGE_WHEN_MATCHED; }
13466 : 122 : | WHEN NOT MATCHED BY SOURCE { $$ = MERGE_WHEN_NOT_MATCHED_BY_SOURCE; }
13467 : : ;
13468 : :
13469 : : merge_when_tgt_not_matched:
13470 : 757 : WHEN NOT MATCHED { $$ = MERGE_WHEN_NOT_MATCHED_BY_TARGET; }
13471 : 12 : | WHEN NOT MATCHED BY TARGET { $$ = MERGE_WHEN_NOT_MATCHED_BY_TARGET; }
13472 : : ;
13473 : :
13474 : : opt_merge_when_condition:
13475 : 566 : AND a_expr { $$ = $2; }
13476 : 1691 : | { $$ = NULL; }
13477 : : ;
13478 : :
13479 : : merge_update:
13480 : : UPDATE SET set_clause_list
13481 : : {
13482 : 1055 : MergeWhenClause *n = makeNode(MergeWhenClause);
13483 : 1055 : n->commandType = CMD_UPDATE;
13484 : 1055 : n->override = OVERRIDING_NOT_SET;
13485 : 1055 : n->targetList = $3;
13486 : 1055 : n->values = NIL;
13487 : :
13488 : 1055 : $$ = n;
13489 : : }
13490 : : ;
13491 : :
13492 : : merge_delete:
13493 : : DELETE_P
13494 : : {
13495 : 375 : MergeWhenClause *n = makeNode(MergeWhenClause);
13496 : 375 : n->commandType = CMD_DELETE;
13497 : 375 : n->override = OVERRIDING_NOT_SET;
13498 : 375 : n->targetList = NIL;
13499 : 375 : n->values = NIL;
13500 : :
13501 : 375 : $$ = n;
13502 : : }
13503 : : ;
13504 : :
13505 : : merge_insert:
13506 : : INSERT merge_values_clause
13507 : : {
13508 : 493 : MergeWhenClause *n = makeNode(MergeWhenClause);
13509 : 493 : n->commandType = CMD_INSERT;
13510 : 493 : n->override = OVERRIDING_NOT_SET;
13511 : 493 : n->targetList = NIL;
13512 : 493 : n->values = $2;
13513 : 493 : $$ = n;
13514 : : }
13515 : : | INSERT OVERRIDING override_kind VALUE_P merge_values_clause
13516 : : {
13517 : 0 : MergeWhenClause *n = makeNode(MergeWhenClause);
13518 : 0 : n->commandType = CMD_INSERT;
13519 : 0 : n->override = $3;
13520 : 0 : n->targetList = NIL;
13521 : 0 : n->values = $5;
13522 : 0 : $$ = n;
13523 : : }
13524 : : | INSERT '(' insert_column_list ')' merge_values_clause
13525 : : {
13526 : 199 : MergeWhenClause *n = makeNode(MergeWhenClause);
13527 : 199 : n->commandType = CMD_INSERT;
13528 : 199 : n->override = OVERRIDING_NOT_SET;
13529 : 199 : n->targetList = $3;
13530 : 199 : n->values = $5;
13531 : 199 : $$ = n;
13532 : : }
13533 : : | INSERT '(' insert_column_list ')' OVERRIDING override_kind VALUE_P merge_values_clause
13534 : : {
13535 : 20 : MergeWhenClause *n = makeNode(MergeWhenClause);
13536 : 20 : n->commandType = CMD_INSERT;
13537 : 20 : n->override = $6;
13538 : 20 : n->targetList = $3;
13539 : 20 : n->values = $8;
13540 : 20 : $$ = n;
13541 : : }
13542 : : | INSERT DEFAULT VALUES
13543 : : {
13544 : 24 : MergeWhenClause *n = makeNode(MergeWhenClause);
13545 : 24 : n->commandType = CMD_INSERT;
13546 : 24 : n->override = OVERRIDING_NOT_SET;
13547 : 24 : n->targetList = NIL;
13548 : 24 : n->values = NIL;
13549 : 24 : $$ = n;
13550 : : }
13551 : : ;
13552 : :
13553 : : merge_values_clause:
13554 : : VALUES '(' expr_list ')'
13555 : : {
13556 : 712 : $$ = $3;
13557 : : }
13558 : : ;
13559 : :
13560 : : /*****************************************************************************
13561 : : *
13562 : : * QUERY:
13563 : : * CURSOR STATEMENTS
13564 : : *
13565 : : *****************************************************************************/
13566 : : DeclareCursorStmt: DECLARE cursor_name cursor_options CURSOR opt_hold FOR SelectStmt
13567 : : {
13568 : 2765 : DeclareCursorStmt *n = makeNode(DeclareCursorStmt);
13569 : :
13570 : 2765 : n->portalname = $2;
13571 : : /* currently we always set FAST_PLAN option */
13572 : 2765 : n->options = $3 | $5 | CURSOR_OPT_FAST_PLAN;
13573 : 2765 : n->query = $7;
13574 : 2765 : $$ = (Node *) n;
13575 : : }
13576 : : ;
13577 : :
13578 : 8586 : cursor_name: name { $$ = $1; }
13579 : : ;
13580 : :
13581 : 2765 : cursor_options: /*EMPTY*/ { $$ = 0; }
13582 : 18 : | cursor_options NO SCROLL { $$ = $1 | CURSOR_OPT_NO_SCROLL; }
13583 : 160 : | cursor_options SCROLL { $$ = $1 | CURSOR_OPT_SCROLL; }
13584 : 8 : | cursor_options BINARY { $$ = $1 | CURSOR_OPT_BINARY; }
13585 : 0 : | cursor_options ASENSITIVE { $$ = $1 | CURSOR_OPT_ASENSITIVE; }
13586 : 4 : | cursor_options INSENSITIVE { $$ = $1 | CURSOR_OPT_INSENSITIVE; }
13587 : : ;
13588 : :
13589 : 2698 : opt_hold: /* EMPTY */ { $$ = 0; }
13590 : 63 : | WITH HOLD { $$ = CURSOR_OPT_HOLD; }
13591 : 4 : | WITHOUT HOLD { $$ = 0; }
13592 : : ;
13593 : :
13594 : : /*****************************************************************************
13595 : : *
13596 : : * QUERY:
13597 : : * SELECT STATEMENTS
13598 : : *
13599 : : *****************************************************************************/
13600 : :
13601 : : /* A complete SELECT statement looks like this.
13602 : : *
13603 : : * The rule returns either a single SelectStmt node or a tree of them,
13604 : : * representing a set-operation tree.
13605 : : *
13606 : : * There is an ambiguity when a sub-SELECT is within an a_expr and there
13607 : : * are excess parentheses: do the parentheses belong to the sub-SELECT or
13608 : : * to the surrounding a_expr? We don't really care, but bison wants to know.
13609 : : * To resolve the ambiguity, we are careful to define the grammar so that
13610 : : * the decision is staved off as long as possible: as long as we can keep
13611 : : * absorbing parentheses into the sub-SELECT, we will do so, and only when
13612 : : * it's no longer possible to do that will we decide that parens belong to
13613 : : * the expression. For example, in "SELECT (((SELECT 2)) + 3)" the extra
13614 : : * parentheses are treated as part of the sub-select. The necessity of doing
13615 : : * it that way is shown by "SELECT (((SELECT 2)) UNION SELECT 2)". Had we
13616 : : * parsed "((SELECT 2))" as an a_expr, it'd be too late to go back to the
13617 : : * SELECT viewpoint when we see the UNION.
13618 : : *
13619 : : * This approach is implemented by defining a nonterminal select_with_parens,
13620 : : * which represents a SELECT with at least one outer layer of parentheses,
13621 : : * and being careful to use select_with_parens, never '(' SelectStmt ')',
13622 : : * in the expression grammar. We will then have shift-reduce conflicts
13623 : : * which we can resolve in favor of always treating '(' <select> ')' as
13624 : : * a select_with_parens. To resolve the conflicts, the productions that
13625 : : * conflict with the select_with_parens productions are manually given
13626 : : * precedences lower than the precedence of ')', thereby ensuring that we
13627 : : * shift ')' (and then reduce to select_with_parens) rather than trying to
13628 : : * reduce the inner <select> nonterminal to something else. We use UMINUS
13629 : : * precedence for this, which is a fairly arbitrary choice.
13630 : : *
13631 : : * To be able to define select_with_parens itself without ambiguity, we need
13632 : : * a nonterminal select_no_parens that represents a SELECT structure with no
13633 : : * outermost parentheses. This is a little bit tedious, but it works.
13634 : : *
13635 : : * In non-expression contexts, we use SelectStmt which can represent a SELECT
13636 : : * with or without outer parentheses.
13637 : : */
13638 : :
13639 : : SelectStmt: select_no_parens %prec UMINUS
13640 : : | select_with_parens %prec UMINUS
13641 : : ;
13642 : :
13643 : : select_with_parens:
13644 : 49314 : '(' select_no_parens ')' { $$ = $2; }
13645 : 104 : | '(' select_with_parens ')' { $$ = $2; }
13646 : : ;
13647 : :
13648 : : /*
13649 : : * This rule parses the equivalent of the standard's <query expression>.
13650 : : * The duplicative productions are annoying, but hard to get rid of without
13651 : : * creating shift/reduce conflicts.
13652 : : *
13653 : : * The locking clause (FOR UPDATE etc) may be before or after LIMIT/OFFSET.
13654 : : * In <=7.2.X, LIMIT/OFFSET had to be after FOR UPDATE
13655 : : * We now support both orderings, but prefer LIMIT/OFFSET before the locking
13656 : : * clause.
13657 : : * 2002-08-28 bjm
13658 : : */
13659 : : select_no_parens:
13660 : 259007 : simple_select { $$ = $1; }
13661 : : | select_clause sort_clause
13662 : : {
13663 : 48897 : insertSelectOptions((SelectStmt *) $1, $2, NIL,
13664 : : NULL, NULL,
13665 : : yyscanner);
13666 : 48897 : $$ = $1;
13667 : : }
13668 : : | select_clause opt_sort_clause for_locking_clause opt_select_limit
13669 : : {
13670 : 4843 : insertSelectOptions((SelectStmt *) $1, $2, $3,
13671 : 4843 : $4,
13672 : : NULL,
13673 : : yyscanner);
13674 : 4843 : $$ = $1;
13675 : : }
13676 : : | select_clause opt_sort_clause select_limit opt_for_locking_clause
13677 : : {
13678 : 3173 : insertSelectOptions((SelectStmt *) $1, $2, $4,
13679 : 3173 : $3,
13680 : : NULL,
13681 : : yyscanner);
13682 : 3165 : $$ = $1;
13683 : : }
13684 : : | with_clause select_clause
13685 : : {
13686 : 1471 : insertSelectOptions((SelectStmt *) $2, NULL, NIL,
13687 : : NULL,
13688 : 1471 : $1,
13689 : : yyscanner);
13690 : 1471 : $$ = $2;
13691 : : }
13692 : : | with_clause select_clause sort_clause
13693 : : {
13694 : 358 : insertSelectOptions((SelectStmt *) $2, $3, NIL,
13695 : : NULL,
13696 : 358 : $1,
13697 : : yyscanner);
13698 : 358 : $$ = $2;
13699 : : }
13700 : : | with_clause select_clause opt_sort_clause for_locking_clause opt_select_limit
13701 : : {
13702 : 4 : insertSelectOptions((SelectStmt *) $2, $3, $4,
13703 : 4 : $5,
13704 : 4 : $1,
13705 : : yyscanner);
13706 : 4 : $$ = $2;
13707 : : }
13708 : : | with_clause select_clause opt_sort_clause select_limit opt_for_locking_clause
13709 : : {
13710 : 42 : insertSelectOptions((SelectStmt *) $2, $3, $5,
13711 : 42 : $4,
13712 : 42 : $1,
13713 : : yyscanner);
13714 : 42 : $$ = $2;
13715 : : }
13716 : : ;
13717 : :
13718 : : select_clause:
13719 : 84465 : simple_select { $$ = $1; }
13720 : 387 : | select_with_parens { $$ = $1; }
13721 : : ;
13722 : :
13723 : : /*
13724 : : * This rule parses SELECT statements that can appear within set operations,
13725 : : * including UNION, INTERSECT and EXCEPT. '(' and ')' can be used to specify
13726 : : * the ordering of the set operations. Without '(' and ')' we want the
13727 : : * operations to be ordered per the precedence specs at the head of this file.
13728 : : *
13729 : : * As with select_no_parens, simple_select cannot have outer parentheses,
13730 : : * but can have parenthesized subclauses.
13731 : : *
13732 : : * It might appear that we could fold the first two alternatives into one
13733 : : * by using opt_distinct_clause. However, that causes a shift/reduce conflict
13734 : : * against INSERT ... SELECT ... ON CONFLICT. We avoid the ambiguity by
13735 : : * requiring SELECT DISTINCT [ON] to be followed by a non-empty target_list.
13736 : : *
13737 : : * Note that sort clauses cannot be included at this level --- SQL requires
13738 : : * SELECT foo UNION SELECT bar ORDER BY baz
13739 : : * to be parsed as
13740 : : * (SELECT foo UNION SELECT bar) ORDER BY baz
13741 : : * not
13742 : : * SELECT foo UNION (SELECT bar ORDER BY baz)
13743 : : * Likewise for WITH, FOR UPDATE and LIMIT. Therefore, those clauses are
13744 : : * described as part of the select_no_parens production, not simple_select.
13745 : : * This does not limit functionality, because you can reintroduce these
13746 : : * clauses inside parentheses.
13747 : : *
13748 : : * NOTE: only the leftmost component SelectStmt should have INTO.
13749 : : * However, this is not checked by the grammar; parse analysis must check it.
13750 : : */
13751 : : simple_select:
13752 : : SELECT opt_all_clause opt_target_list
13753 : : into_clause from_clause where_clause
13754 : : group_clause having_clause window_clause
13755 : : {
13756 : 286234 : SelectStmt *n = makeNode(SelectStmt);
13757 : :
13758 : 286234 : n->targetList = $3;
13759 : 286234 : n->intoClause = $4;
13760 : 286234 : n->fromClause = $5;
13761 : 286234 : n->whereClause = $6;
13762 : 286234 : n->groupClause = ($7)->list;
13763 : 286234 : n->groupDistinct = ($7)->distinct;
13764 : 286234 : n->havingClause = $8;
13765 : 286234 : n->windowClause = $9;
13766 : 286234 : $$ = (Node *) n;
13767 : : }
13768 : : | SELECT distinct_clause target_list
13769 : : into_clause from_clause where_clause
13770 : : group_clause having_clause window_clause
13771 : : {
13772 : 2520 : SelectStmt *n = makeNode(SelectStmt);
13773 : :
13774 : 2520 : n->distinctClause = $2;
13775 : 2520 : n->targetList = $3;
13776 : 2520 : n->intoClause = $4;
13777 : 2520 : n->fromClause = $5;
13778 : 2520 : n->whereClause = $6;
13779 : 2520 : n->groupClause = ($7)->list;
13780 : 2520 : n->groupDistinct = ($7)->distinct;
13781 : 2520 : n->havingClause = $8;
13782 : 2520 : n->windowClause = $9;
13783 : 2520 : $$ = (Node *) n;
13784 : : }
13785 : 41433 : | values_clause { $$ = $1; }
13786 : : | TABLE relation_expr
13787 : : {
13788 : : /* same as SELECT * FROM relation_expr */
13789 : 257 : ColumnRef *cr = makeNode(ColumnRef);
13790 : 257 : ResTarget *rt = makeNode(ResTarget);
13791 : 257 : SelectStmt *n = makeNode(SelectStmt);
13792 : :
13793 : 257 : cr->fields = list_make1(makeNode(A_Star));
13794 : 257 : cr->location = -1;
13795 : :
13796 : 257 : rt->name = NULL;
13797 : 257 : rt->indirection = NIL;
13798 : 257 : rt->val = (Node *) cr;
13799 : 257 : rt->location = -1;
13800 : :
13801 : 257 : n->targetList = list_make1(rt);
13802 : 257 : n->fromClause = list_make1($2);
13803 : 257 : $$ = (Node *) n;
13804 : : }
13805 : : | select_clause UNION set_quantifier select_clause
13806 : : {
13807 : 12469 : $$ = makeSetOp(SETOP_UNION, $3 == SET_QUANTIFIER_ALL, $1, $4);
13808 : : }
13809 : : | select_clause INTERSECT set_quantifier select_clause
13810 : : {
13811 : 216 : $$ = makeSetOp(SETOP_INTERSECT, $3 == SET_QUANTIFIER_ALL, $1, $4);
13812 : : }
13813 : : | select_clause EXCEPT set_quantifier select_clause
13814 : : {
13815 : 343 : $$ = makeSetOp(SETOP_EXCEPT, $3 == SET_QUANTIFIER_ALL, $1, $4);
13816 : : }
13817 : : ;
13818 : :
13819 : : /*
13820 : : * SQL standard WITH clause looks like:
13821 : : *
13822 : : * WITH [ RECURSIVE ] <query name> [ (<column>,...) ]
13823 : : * AS (query) [ SEARCH or CYCLE clause ]
13824 : : *
13825 : : * Recognizing WITH_LA here allows a CTE to be named TIME or ORDINALITY.
13826 : : */
13827 : : with_clause:
13828 : : WITH cte_list
13829 : : {
13830 : 1416 : $$ = makeNode(WithClause);
13831 : 1416 : $$->ctes = $2;
13832 : 1416 : $$->recursive = false;
13833 : 1416 : $$->location = @1;
13834 : : }
13835 : : | WITH_LA cte_list
13836 : : {
13837 : 4 : $$ = makeNode(WithClause);
13838 : 4 : $$->ctes = $2;
13839 : 4 : $$->recursive = false;
13840 : 4 : $$->location = @1;
13841 : : }
13842 : : | WITH RECURSIVE cte_list
13843 : : {
13844 : 763 : $$ = makeNode(WithClause);
13845 : 763 : $$->ctes = $3;
13846 : 763 : $$->recursive = true;
13847 : 763 : $$->location = @1;
13848 : : }
13849 : : ;
13850 : :
13851 : : cte_list:
13852 : 2183 : common_table_expr { $$ = list_make1($1); }
13853 : 732 : | cte_list ',' common_table_expr { $$ = lappend($1, $3); }
13854 : : ;
13855 : :
13856 : : common_table_expr: name opt_name_list AS opt_materialized '(' PreparableStmt ')' opt_search_clause opt_cycle_clause
13857 : : {
13858 : 2915 : CommonTableExpr *n = makeNode(CommonTableExpr);
13859 : :
13860 : 2915 : n->ctename = $1;
13861 : 2915 : n->aliascolnames = $2;
13862 : 2915 : n->ctematerialized = $4;
13863 : 2915 : n->ctequery = $6;
13864 : 2915 : n->search_clause = castNode(CTESearchClause, $8);
13865 : 2915 : n->cycle_clause = castNode(CTECycleClause, $9);
13866 : 2915 : n->location = @1;
13867 : 2915 : $$ = (Node *) n;
13868 : : }
13869 : : ;
13870 : :
13871 : : opt_materialized:
13872 : 119 : MATERIALIZED { $$ = CTEMaterializeAlways; }
13873 : 32 : | NOT MATERIALIZED { $$ = CTEMaterializeNever; }
13874 : 2764 : | /*EMPTY*/ { $$ = CTEMaterializeDefault; }
13875 : : ;
13876 : :
13877 : : opt_search_clause:
13878 : : SEARCH DEPTH FIRST_P BY columnList SET ColId
13879 : : {
13880 : 60 : CTESearchClause *n = makeNode(CTESearchClause);
13881 : :
13882 : 60 : n->search_col_list = $5;
13883 : 60 : n->search_breadth_first = false;
13884 : 60 : n->search_seq_column = $7;
13885 : 60 : n->location = @1;
13886 : 60 : $$ = (Node *) n;
13887 : : }
13888 : : | SEARCH BREADTH FIRST_P BY columnList SET ColId
13889 : : {
13890 : 24 : CTESearchClause *n = makeNode(CTESearchClause);
13891 : :
13892 : 24 : n->search_col_list = $5;
13893 : 24 : n->search_breadth_first = true;
13894 : 24 : n->search_seq_column = $7;
13895 : 24 : n->location = @1;
13896 : 24 : $$ = (Node *) n;
13897 : : }
13898 : : | /*EMPTY*/
13899 : : {
13900 : 2831 : $$ = NULL;
13901 : : }
13902 : : ;
13903 : :
13904 : : opt_cycle_clause:
13905 : : CYCLE columnList SET ColId TO AexprConst DEFAULT AexprConst USING ColId
13906 : : {
13907 : 44 : CTECycleClause *n = makeNode(CTECycleClause);
13908 : :
13909 : 44 : n->cycle_col_list = $2;
13910 : 44 : n->cycle_mark_column = $4;
13911 : 44 : n->cycle_mark_value = $6;
13912 : 44 : n->cycle_mark_default = $8;
13913 : 44 : n->cycle_path_column = $10;
13914 : 44 : n->location = @1;
13915 : 44 : $$ = (Node *) n;
13916 : : }
13917 : : | CYCLE columnList SET ColId USING ColId
13918 : : {
13919 : 40 : CTECycleClause *n = makeNode(CTECycleClause);
13920 : :
13921 : 40 : n->cycle_col_list = $2;
13922 : 40 : n->cycle_mark_column = $4;
13923 : 40 : n->cycle_mark_value = makeBoolAConst(true, -1);
13924 : 40 : n->cycle_mark_default = makeBoolAConst(false, -1);
13925 : 40 : n->cycle_path_column = $6;
13926 : 40 : n->location = @1;
13927 : 40 : $$ = (Node *) n;
13928 : : }
13929 : : | /*EMPTY*/
13930 : : {
13931 : 2831 : $$ = NULL;
13932 : : }
13933 : : ;
13934 : :
13935 : : opt_with_clause:
13936 : 308 : with_clause { $$ = $1; }
13937 : 59921 : | /*EMPTY*/ { $$ = NULL; }
13938 : : ;
13939 : :
13940 : : into_clause:
13941 : : INTO OptTempTableName
13942 : : {
13943 : 91 : $$ = makeNode(IntoClause);
13944 : 91 : $$->rel = $2;
13945 : 91 : $$->colNames = NIL;
13946 : 91 : $$->options = NIL;
13947 : 91 : $$->onCommit = ONCOMMIT_NOOP;
13948 : 91 : $$->tableSpaceName = NULL;
13949 : 91 : $$->viewQuery = NULL;
13950 : 91 : $$->skipData = false;
13951 : : }
13952 : : | /*EMPTY*/
13953 : 288691 : { $$ = NULL; }
13954 : : ;
13955 : :
13956 : : /*
13957 : : * Redundancy here is needed to avoid shift/reduce conflicts,
13958 : : * since TEMP is not a reserved word. See also OptTemp.
13959 : : */
13960 : : OptTempTableName:
13961 : : TEMPORARY opt_table qualified_name
13962 : : {
13963 : 0 : $$ = $3;
13964 : 0 : $$->relpersistence = RELPERSISTENCE_TEMP;
13965 : : }
13966 : : | TEMP opt_table qualified_name
13967 : : {
13968 : 4 : $$ = $3;
13969 : 4 : $$->relpersistence = RELPERSISTENCE_TEMP;
13970 : : }
13971 : : | LOCAL TEMPORARY opt_table qualified_name
13972 : : {
13973 : 0 : $$ = $4;
13974 : 0 : $$->relpersistence = RELPERSISTENCE_TEMP;
13975 : : }
13976 : : | LOCAL TEMP opt_table qualified_name
13977 : : {
13978 : 0 : $$ = $4;
13979 : 0 : $$->relpersistence = RELPERSISTENCE_TEMP;
13980 : : }
13981 : : | GLOBAL TEMPORARY 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 : : | GLOBAL TEMP opt_table qualified_name
13990 : : {
13991 [ # # ]: 0 : ereport(WARNING,
13992 : : (errmsg("GLOBAL is deprecated in temporary table creation"),
13993 : : parser_errposition(@1)));
13994 : 0 : $$ = $4;
13995 : 0 : $$->relpersistence = RELPERSISTENCE_TEMP;
13996 : : }
13997 : : | UNLOGGED opt_table qualified_name
13998 : : {
13999 : 0 : $$ = $3;
14000 : 0 : $$->relpersistence = RELPERSISTENCE_UNLOGGED;
14001 : : }
14002 : : | TABLE qualified_name
14003 : : {
14004 : 20 : $$ = $2;
14005 : 20 : $$->relpersistence = RELPERSISTENCE_PERMANENT;
14006 : : }
14007 : : | qualified_name
14008 : : {
14009 : 67 : $$ = $1;
14010 : 67 : $$->relpersistence = RELPERSISTENCE_PERMANENT;
14011 : : }
14012 : : ;
14013 : :
14014 : : opt_table: TABLE
14015 : : | /*EMPTY*/
14016 : : ;
14017 : :
14018 : : set_quantifier:
14019 : 7180 : ALL { $$ = SET_QUANTIFIER_ALL; }
14020 : 25 : | DISTINCT { $$ = SET_QUANTIFIER_DISTINCT; }
14021 : 9460 : | /*EMPTY*/ { $$ = SET_QUANTIFIER_DEFAULT; }
14022 : : ;
14023 : :
14024 : : /* We use (NIL) as a placeholder to indicate that all target expressions
14025 : : * should be placed in the DISTINCT list during parsetree analysis.
14026 : : */
14027 : : distinct_clause:
14028 : 2325 : DISTINCT { $$ = list_make1(NIL); }
14029 : 199 : | DISTINCT ON '(' expr_list ')' { $$ = $4; }
14030 : : ;
14031 : :
14032 : : opt_all_clause:
14033 : : ALL
14034 : : | /*EMPTY*/
14035 : : ;
14036 : :
14037 : : opt_distinct_clause:
14038 : 0 : distinct_clause { $$ = $1; }
14039 : 25998 : | opt_all_clause { $$ = NIL; }
14040 : : ;
14041 : :
14042 : : opt_sort_clause:
14043 : 4907 : sort_clause { $$ = $1; }
14044 : 240578 : | /*EMPTY*/ { $$ = NIL; }
14045 : : ;
14046 : :
14047 : : sort_clause:
14048 : 54390 : ORDER BY sortby_list { $$ = $3; }
14049 : : ;
14050 : :
14051 : : sortby_list:
14052 : 54426 : sortby { $$ = list_make1($1); }
14053 : 19371 : | sortby_list ',' sortby { $$ = lappend($1, $3); }
14054 : : ;
14055 : :
14056 : : sortby: a_expr USING qual_all_Op opt_nulls_order
14057 : : {
14058 : 142 : $$ = makeNode(SortBy);
14059 : 142 : $$->node = $1;
14060 : 142 : $$->sortby_dir = SORTBY_USING;
14061 : 142 : $$->sortby_nulls = $4;
14062 : 142 : $$->useOp = $3;
14063 : 142 : $$->location = @3;
14064 : : }
14065 : : | a_expr opt_asc_desc opt_nulls_order
14066 : : {
14067 : 73655 : $$ = makeNode(SortBy);
14068 : 73655 : $$->node = $1;
14069 : 73655 : $$->sortby_dir = $2;
14070 : 73655 : $$->sortby_nulls = $3;
14071 : 73655 : $$->useOp = NIL;
14072 : 73655 : $$->location = -1; /* no operator */
14073 : : }
14074 : : ;
14075 : :
14076 : :
14077 : : select_limit:
14078 : : limit_clause offset_clause
14079 : : {
14080 : 99 : $$ = $1;
14081 : 99 : ($$)->limitOffset = $2;
14082 : 99 : ($$)->offsetLoc = @2;
14083 : : }
14084 : : | offset_clause limit_clause
14085 : : {
14086 : 113 : $$ = $2;
14087 : 113 : ($$)->limitOffset = $1;
14088 : 113 : ($$)->offsetLoc = @1;
14089 : : }
14090 : : | limit_clause
14091 : : {
14092 : 2760 : $$ = $1;
14093 : : }
14094 : : | offset_clause
14095 : : {
14096 : 338 : SelectLimit *n = palloc_object(SelectLimit);
14097 : :
14098 : 338 : n->limitOffset = $1;
14099 : 338 : n->limitCount = NULL;
14100 : 338 : n->limitOption = LIMIT_OPTION_COUNT;
14101 : 338 : n->offsetLoc = @1;
14102 : 338 : n->countLoc = -1;
14103 : 338 : n->optionLoc = -1;
14104 : 338 : $$ = n;
14105 : : }
14106 : : ;
14107 : :
14108 : : opt_select_limit:
14109 : 95 : select_limit { $$ = $1; }
14110 : 30750 : | /* EMPTY */ { $$ = NULL; }
14111 : : ;
14112 : :
14113 : : limit_clause:
14114 : : LIMIT select_limit_value
14115 : : {
14116 : 2911 : SelectLimit *n = palloc_object(SelectLimit);
14117 : :
14118 : 2911 : n->limitOffset = NULL;
14119 : 2911 : n->limitCount = $2;
14120 : 2911 : n->limitOption = LIMIT_OPTION_COUNT;
14121 : 2911 : n->offsetLoc = -1;
14122 : 2911 : n->countLoc = @1;
14123 : 2911 : n->optionLoc = -1;
14124 : 2911 : $$ = n;
14125 : : }
14126 : : | LIMIT select_limit_value ',' select_offset_value
14127 : : {
14128 : : /* Disabled because it was too confusing, bjm 2002-02-18 */
14129 [ # # ]: 0 : ereport(ERROR,
14130 : : (errcode(ERRCODE_SYNTAX_ERROR),
14131 : : errmsg("LIMIT #,# syntax is not supported"),
14132 : : errhint("Use separate LIMIT and OFFSET clauses."),
14133 : : parser_errposition(@1)));
14134 : : }
14135 : : /* SQL:2008 syntax */
14136 : : /* to avoid shift/reduce conflicts, handle the optional value with
14137 : : * a separate production rather than an opt_ expression. The fact
14138 : : * that ONLY is fully reserved means that this way, we defer any
14139 : : * decision about what rule reduces ROW or ROWS to the point where
14140 : : * we can see the ONLY token in the lookahead slot.
14141 : : */
14142 : : | FETCH first_or_next select_fetch_first_value row_or_rows ONLY
14143 : : {
14144 : 15 : SelectLimit *n = palloc_object(SelectLimit);
14145 : :
14146 : 15 : n->limitOffset = NULL;
14147 : 15 : n->limitCount = $3;
14148 : 15 : n->limitOption = LIMIT_OPTION_COUNT;
14149 : 15 : n->offsetLoc = -1;
14150 : 15 : n->countLoc = @1;
14151 : 15 : n->optionLoc = -1;
14152 : 15 : $$ = n;
14153 : : }
14154 : : | FETCH first_or_next select_fetch_first_value row_or_rows WITH TIES
14155 : : {
14156 : 42 : SelectLimit *n = palloc_object(SelectLimit);
14157 : :
14158 : 42 : n->limitOffset = NULL;
14159 : 42 : n->limitCount = $3;
14160 : 42 : n->limitOption = LIMIT_OPTION_WITH_TIES;
14161 : 42 : n->offsetLoc = -1;
14162 : 42 : n->countLoc = @1;
14163 : 42 : n->optionLoc = @5;
14164 : 42 : $$ = n;
14165 : : }
14166 : : | FETCH first_or_next row_or_rows ONLY
14167 : : {
14168 : 0 : SelectLimit *n = palloc_object(SelectLimit);
14169 : :
14170 : 0 : n->limitOffset = NULL;
14171 : 0 : n->limitCount = makeIntConst(1, -1);
14172 : 0 : n->limitOption = LIMIT_OPTION_COUNT;
14173 : 0 : n->offsetLoc = -1;
14174 : 0 : n->countLoc = @1;
14175 : 0 : n->optionLoc = -1;
14176 : 0 : $$ = n;
14177 : : }
14178 : : | FETCH first_or_next row_or_rows WITH TIES
14179 : : {
14180 : 4 : SelectLimit *n = palloc_object(SelectLimit);
14181 : :
14182 : 4 : n->limitOffset = NULL;
14183 : 4 : n->limitCount = makeIntConst(1, -1);
14184 : 4 : n->limitOption = LIMIT_OPTION_WITH_TIES;
14185 : 4 : n->offsetLoc = -1;
14186 : 4 : n->countLoc = @1;
14187 : 4 : n->optionLoc = @4;
14188 : 4 : $$ = n;
14189 : : }
14190 : : ;
14191 : :
14192 : : offset_clause:
14193 : : OFFSET select_offset_value
14194 : 550 : { $$ = $2; }
14195 : : /* SQL:2008 syntax */
14196 : : | OFFSET select_fetch_first_value row_or_rows
14197 : 0 : { $$ = $2; }
14198 : : ;
14199 : :
14200 : : select_limit_value:
14201 : 2910 : a_expr { $$ = $1; }
14202 : : | ALL
14203 : : {
14204 : : /* LIMIT ALL is represented as a NULL constant */
14205 : 1 : $$ = makeNullAConst(@1);
14206 : : }
14207 : : ;
14208 : :
14209 : : select_offset_value:
14210 : 550 : a_expr { $$ = $1; }
14211 : : ;
14212 : :
14213 : : /*
14214 : : * Allowing full expressions without parentheses causes various parsing
14215 : : * problems with the trailing ROW/ROWS key words. SQL spec only calls for
14216 : : * <simple value specification>, which is either a literal or a parameter (but
14217 : : * an <SQL parameter reference> could be an identifier, bringing up conflicts
14218 : : * with ROW/ROWS). We solve this by leveraging the presence of ONLY (see above)
14219 : : * to determine whether the expression is missing rather than trying to make it
14220 : : * optional in this rule.
14221 : : *
14222 : : * c_expr covers almost all the spec-required cases (and more), but it doesn't
14223 : : * cover signed numeric literals, which are allowed by the spec. So we include
14224 : : * those here explicitly. We need FCONST as well as ICONST because values that
14225 : : * don't fit in the platform's "long", but do fit in bigint, should still be
14226 : : * accepted here. (This is possible in 64-bit Windows as well as all 32-bit
14227 : : * builds.)
14228 : : */
14229 : : select_fetch_first_value:
14230 : 57 : c_expr { $$ = $1; }
14231 : : | '+' I_or_F_const
14232 : 0 : { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "+", NULL, $2, @1); }
14233 : : | '-' I_or_F_const
14234 : 0 : { $$ = doNegate($2, @1); }
14235 : : ;
14236 : :
14237 : : I_or_F_const:
14238 : 0 : Iconst { $$ = makeIntConst($1,@1); }
14239 : 0 : | FCONST { $$ = makeFloatConst($1,@1); }
14240 : : ;
14241 : :
14242 : : /* noise words */
14243 : 23 : row_or_rows: ROW { $$ = 0; }
14244 : 38 : | ROWS { $$ = 0; }
14245 : : ;
14246 : :
14247 : 61 : first_or_next: FIRST_P { $$ = 0; }
14248 : 0 : | NEXT { $$ = 0; }
14249 : : ;
14250 : :
14251 : :
14252 : : /*
14253 : : * This syntax for group_clause tries to follow the spec quite closely.
14254 : : * However, the spec allows only column references, not expressions,
14255 : : * which introduces an ambiguity between implicit row constructors
14256 : : * (a,b) and lists of column references.
14257 : : *
14258 : : * We handle this by using the a_expr production for what the spec calls
14259 : : * <ordinary grouping set>, which in the spec represents either one column
14260 : : * reference or a parenthesized list of column references. Then, we check the
14261 : : * top node of the a_expr to see if it's an implicit RowExpr, and if so, just
14262 : : * grab and use the list, discarding the node. (this is done in parse analysis,
14263 : : * not here)
14264 : : *
14265 : : * (we abuse the row_format field of RowExpr to distinguish implicit and
14266 : : * explicit row constructors; it's debatable if anyone sanely wants to use them
14267 : : * in a group clause, but if they have a reason to, we make it possible.)
14268 : : *
14269 : : * Each item in the group_clause list is either an expression tree or a
14270 : : * GroupingSet node of some type.
14271 : : */
14272 : : group_clause:
14273 : : GROUP_P BY set_quantifier group_by_list
14274 : : {
14275 : 3629 : GroupClause *n = palloc_object(GroupClause);
14276 : :
14277 : 3629 : n->distinct = $3 == SET_QUANTIFIER_DISTINCT;
14278 : 3629 : n->list = $4;
14279 : 3629 : $$ = n;
14280 : : }
14281 : : | /*EMPTY*/
14282 : : {
14283 : 311123 : GroupClause *n = palloc_object(GroupClause);
14284 : :
14285 : 311123 : n->distinct = false;
14286 : 311123 : n->list = NIL;
14287 : 311123 : $$ = n;
14288 : : }
14289 : : ;
14290 : :
14291 : : group_by_list:
14292 : 4157 : group_by_item { $$ = list_make1($1); }
14293 : 2134 : | group_by_list ',' group_by_item { $$ = lappend($1,$3); }
14294 : : ;
14295 : :
14296 : : group_by_item:
14297 : 5199 : a_expr { $$ = $1; }
14298 : 226 : | empty_grouping_set { $$ = $1; }
14299 : 122 : | cube_clause { $$ = $1; }
14300 : 216 : | rollup_clause { $$ = $1; }
14301 : 528 : | grouping_sets_clause { $$ = $1; }
14302 : : ;
14303 : :
14304 : : empty_grouping_set:
14305 : : '(' ')'
14306 : : {
14307 : 226 : $$ = (Node *) makeGroupingSet(GROUPING_SET_EMPTY, NIL, @1);
14308 : : }
14309 : : ;
14310 : :
14311 : : /*
14312 : : * These hacks rely on setting precedence of CUBE and ROLLUP below that of '(',
14313 : : * so that they shift in these rules rather than reducing the conflicting
14314 : : * unreserved_keyword rule.
14315 : : */
14316 : :
14317 : : rollup_clause:
14318 : : ROLLUP '(' expr_list ')'
14319 : : {
14320 : 216 : $$ = (Node *) makeGroupingSet(GROUPING_SET_ROLLUP, $3, @1);
14321 : : }
14322 : : ;
14323 : :
14324 : : cube_clause:
14325 : : CUBE '(' expr_list ')'
14326 : : {
14327 : 122 : $$ = (Node *) makeGroupingSet(GROUPING_SET_CUBE, $3, @1);
14328 : : }
14329 : : ;
14330 : :
14331 : : grouping_sets_clause:
14332 : : GROUPING SETS '(' group_by_list ')'
14333 : : {
14334 : 528 : $$ = (Node *) makeGroupingSet(GROUPING_SET_SETS, $4, @1);
14335 : : }
14336 : : ;
14337 : :
14338 : : having_clause:
14339 : 663 : HAVING a_expr { $$ = $2; }
14340 : 314089 : | /*EMPTY*/ { $$ = NULL; }
14341 : : ;
14342 : :
14343 : : for_locking_clause:
14344 : 5018 : for_locking_items { $$ = $1; }
14345 : 0 : | FOR READ ONLY { $$ = NIL; }
14346 : : ;
14347 : :
14348 : : opt_for_locking_clause:
14349 : 171 : for_locking_clause { $$ = $1; }
14350 : 29042 : | /* EMPTY */ { $$ = NIL; }
14351 : : ;
14352 : :
14353 : : for_locking_items:
14354 : 5018 : for_locking_item { $$ = list_make1($1); }
14355 : 51 : | for_locking_items for_locking_item { $$ = lappend($1, $2); }
14356 : : ;
14357 : :
14358 : : for_locking_item:
14359 : : for_locking_strength locked_rels_list opt_nowait_or_skip
14360 : : {
14361 : 5069 : LockingClause *n = makeNode(LockingClause);
14362 : :
14363 : 5069 : n->lockedRels = $2;
14364 : 5069 : n->strength = $1;
14365 : 5069 : n->waitPolicy = $3;
14366 : 5069 : $$ = (Node *) n;
14367 : : }
14368 : : ;
14369 : :
14370 : : for_locking_strength:
14371 : 992 : FOR UPDATE { $$ = LCS_FORUPDATE; }
14372 : 44 : | FOR NO KEY UPDATE { $$ = LCS_FORNOKEYUPDATE; }
14373 : 123 : | FOR SHARE { $$ = LCS_FORSHARE; }
14374 : 3988 : | FOR KEY SHARE { $$ = LCS_FORKEYSHARE; }
14375 : : ;
14376 : :
14377 : : opt_for_locking_strength:
14378 : 78 : for_locking_strength { $$ = $1; }
14379 : 162 : | /* EMPTY */ { $$ = LCS_NONE; }
14380 : : ;
14381 : :
14382 : : locked_rels_list:
14383 : 1240 : OF qualified_name_list { $$ = $2; }
14384 : 3829 : | /* EMPTY */ { $$ = NIL; }
14385 : : ;
14386 : :
14387 : :
14388 : : /*
14389 : : * We should allow ROW '(' expr_list ')' too, but that seems to require
14390 : : * making VALUES a fully reserved word, which will probably break more apps
14391 : : * than allowing the noise-word is worth.
14392 : : */
14393 : : values_clause:
14394 : : VALUES '(' expr_list ')'
14395 : : {
14396 : 41433 : SelectStmt *n = makeNode(SelectStmt);
14397 : :
14398 : 41433 : n->valuesLists = list_make1($3);
14399 : 41433 : $$ = (Node *) n;
14400 : : }
14401 : : | values_clause ',' '(' expr_list ')'
14402 : : {
14403 : 18134 : SelectStmt *n = (SelectStmt *) $1;
14404 : :
14405 : 18134 : n->valuesLists = lappend(n->valuesLists, $4);
14406 : 18134 : $$ = (Node *) n;
14407 : : }
14408 : : ;
14409 : :
14410 : :
14411 : : /*****************************************************************************
14412 : : *
14413 : : * clauses common to all Optimizable Stmts:
14414 : : * from_clause - allow list of both JOIN expressions and table names
14415 : : * where_clause - qualifications for joins or restrictions
14416 : : *
14417 : : *****************************************************************************/
14418 : :
14419 : : from_clause:
14420 : 212089 : FROM from_list { $$ = $2; }
14421 : 112194 : | /*EMPTY*/ { $$ = NIL; }
14422 : : ;
14423 : :
14424 : : from_list:
14425 : 212822 : table_ref { $$ = list_make1($1); }
14426 : 38237 : | from_list ',' table_ref { $$ = lappend($1, $3); }
14427 : : ;
14428 : :
14429 : : /*
14430 : : * table_ref is where an alias clause can be attached.
14431 : : */
14432 : : table_ref: relation_expr opt_alias_clause
14433 : : {
14434 : 262465 : $1->alias = $2;
14435 : 262465 : $$ = (Node *) $1;
14436 : : }
14437 : : | relation_expr opt_alias_clause tablesample_clause
14438 : : {
14439 : 172 : RangeTableSample *n = (RangeTableSample *) $3;
14440 : :
14441 : 172 : $1->alias = $2;
14442 : : /* relation_expr goes inside the RangeTableSample node */
14443 : 172 : n->relation = (Node *) $1;
14444 : 172 : $$ = (Node *) n;
14445 : : }
14446 : : | func_table func_alias_clause
14447 : : {
14448 : 29450 : RangeFunction *n = (RangeFunction *) $1;
14449 : :
14450 : 29450 : n->alias = linitial($2);
14451 : 29450 : n->coldeflist = lsecond($2);
14452 : 29450 : $$ = (Node *) n;
14453 : : }
14454 : : | LATERAL_P func_table func_alias_clause
14455 : : {
14456 : 359 : RangeFunction *n = (RangeFunction *) $2;
14457 : :
14458 : 359 : n->lateral = true;
14459 : 359 : n->alias = linitial($3);
14460 : 359 : n->coldeflist = lsecond($3);
14461 : 359 : $$ = (Node *) n;
14462 : : }
14463 : : | xmltable opt_alias_clause
14464 : : {
14465 : 57 : RangeTableFunc *n = (RangeTableFunc *) $1;
14466 : :
14467 : 57 : n->alias = $2;
14468 : 57 : $$ = (Node *) n;
14469 : : }
14470 : : | LATERAL_P xmltable opt_alias_clause
14471 : : {
14472 : 93 : RangeTableFunc *n = (RangeTableFunc *) $2;
14473 : :
14474 : 93 : n->lateral = true;
14475 : 93 : n->alias = $3;
14476 : 93 : $$ = (Node *) n;
14477 : : }
14478 : : | GRAPH_TABLE '(' qualified_name MATCH graph_pattern COLUMNS '(' labeled_expr_list ')' ')' opt_alias_clause
14479 : : {
14480 : 453 : RangeGraphTable *n = makeNode(RangeGraphTable);
14481 : :
14482 : 453 : n->graph_name = $3;
14483 : 453 : n->graph_pattern = castNode(GraphPattern, $5);
14484 : 453 : n->columns = $8;
14485 : 453 : n->alias = $11;
14486 : 453 : n->location = @1;
14487 : 453 : $$ = (Node *) n;
14488 : : }
14489 : : | select_with_parens opt_alias_clause
14490 : : {
14491 : 12922 : RangeSubselect *n = makeNode(RangeSubselect);
14492 : :
14493 : 12922 : n->lateral = false;
14494 : 12922 : n->subquery = $1;
14495 : 12922 : n->alias = $2;
14496 : 12922 : $$ = (Node *) n;
14497 : : }
14498 : : | LATERAL_P select_with_parens opt_alias_clause
14499 : : {
14500 : 1235 : RangeSubselect *n = makeNode(RangeSubselect);
14501 : :
14502 : 1235 : n->lateral = true;
14503 : 1235 : n->subquery = $2;
14504 : 1235 : n->alias = $3;
14505 : 1235 : $$ = (Node *) n;
14506 : : }
14507 : : | joined_table
14508 : : {
14509 : 55053 : $$ = (Node *) $1;
14510 : : }
14511 : : | '(' joined_table ')' alias_clause
14512 : : {
14513 : 120 : $2->alias = $4;
14514 : 120 : $$ = (Node *) $2;
14515 : : }
14516 : : | json_table opt_alias_clause
14517 : : {
14518 : 484 : JsonTable *jt = castNode(JsonTable, $1);
14519 : :
14520 : 484 : jt->alias = $2;
14521 : 484 : $$ = (Node *) jt;
14522 : : }
14523 : : | LATERAL_P json_table opt_alias_clause
14524 : : {
14525 : 0 : JsonTable *jt = castNode(JsonTable, $2);
14526 : :
14527 : 0 : jt->alias = $3;
14528 : 0 : jt->lateral = true;
14529 : 0 : $$ = (Node *) jt;
14530 : : }
14531 : : ;
14532 : :
14533 : :
14534 : : /*
14535 : : * It may seem silly to separate joined_table from table_ref, but there is
14536 : : * method in SQL's madness: if you don't do it this way you get reduce-
14537 : : * reduce conflicts, because it's not clear to the parser generator whether
14538 : : * to expect alias_clause after ')' or not. For the same reason we must
14539 : : * treat 'JOIN' and 'join_type JOIN' separately, rather than allowing
14540 : : * join_type to expand to empty; if we try it, the parser generator can't
14541 : : * figure out when to reduce an empty join_type right after table_ref.
14542 : : *
14543 : : * Note that a CROSS JOIN is the same as an unqualified
14544 : : * INNER JOIN, and an INNER JOIN/ON has the same shape
14545 : : * but a qualification expression to limit membership.
14546 : : * A NATURAL JOIN implicitly matches column names between
14547 : : * tables and the shape is determined by which columns are
14548 : : * in common. We'll collect columns during the later transformations.
14549 : : */
14550 : :
14551 : : joined_table:
14552 : : '(' joined_table ')'
14553 : : {
14554 : 2474 : $$ = $2;
14555 : : }
14556 : : | table_ref CROSS JOIN table_ref
14557 : : {
14558 : : /* CROSS JOIN is same as unqualified inner join */
14559 : 366 : JoinExpr *n = makeNode(JoinExpr);
14560 : :
14561 : 366 : n->jointype = JOIN_INNER;
14562 : 366 : n->isNatural = false;
14563 : 366 : n->larg = $1;
14564 : 366 : n->rarg = $4;
14565 : 366 : n->usingClause = NIL;
14566 : 366 : n->join_using_alias = NULL;
14567 : 366 : n->quals = NULL;
14568 : 366 : $$ = n;
14569 : : }
14570 : : | table_ref join_type JOIN table_ref join_qual
14571 : : {
14572 : 29402 : JoinExpr *n = makeNode(JoinExpr);
14573 : :
14574 : 29402 : n->jointype = $2;
14575 : 29402 : n->isNatural = false;
14576 : 29402 : n->larg = $1;
14577 : 29402 : n->rarg = $4;
14578 [ + - + + ]: 29402 : if ($5 != NULL && IsA($5, List))
14579 : : {
14580 : : /* USING clause */
14581 : 350 : n->usingClause = linitial_node(List, castNode(List, $5));
14582 : 350 : n->join_using_alias = lsecond_node(Alias, castNode(List, $5));
14583 : : }
14584 : : else
14585 : : {
14586 : : /* ON clause */
14587 : 29052 : n->quals = $5;
14588 : : }
14589 : 29402 : $$ = n;
14590 : : }
14591 : : | table_ref JOIN table_ref join_qual
14592 : : {
14593 : : /* letting join_type reduce to empty doesn't work */
14594 : 25225 : JoinExpr *n = makeNode(JoinExpr);
14595 : :
14596 : 25225 : n->jointype = JOIN_INNER;
14597 : 25225 : n->isNatural = false;
14598 : 25225 : n->larg = $1;
14599 : 25225 : n->rarg = $3;
14600 [ + - + + ]: 25225 : if ($4 != NULL && IsA($4, List))
14601 : : {
14602 : : /* USING clause */
14603 : 499 : n->usingClause = linitial_node(List, castNode(List, $4));
14604 : 499 : n->join_using_alias = lsecond_node(Alias, castNode(List, $4));
14605 : : }
14606 : : else
14607 : : {
14608 : : /* ON clause */
14609 : 24726 : n->quals = $4;
14610 : : }
14611 : 25225 : $$ = n;
14612 : : }
14613 : : | table_ref NATURAL join_type JOIN table_ref
14614 : : {
14615 : 52 : JoinExpr *n = makeNode(JoinExpr);
14616 : :
14617 : 52 : n->jointype = $3;
14618 : 52 : n->isNatural = true;
14619 : 52 : n->larg = $1;
14620 : 52 : n->rarg = $5;
14621 : 52 : n->usingClause = NIL; /* figure out which columns later... */
14622 : 52 : n->join_using_alias = NULL;
14623 : 52 : n->quals = NULL; /* fill later */
14624 : 52 : $$ = n;
14625 : : }
14626 : : | table_ref NATURAL JOIN table_ref
14627 : : {
14628 : : /* letting join_type reduce to empty doesn't work */
14629 : 128 : JoinExpr *n = makeNode(JoinExpr);
14630 : :
14631 : 128 : n->jointype = JOIN_INNER;
14632 : 128 : n->isNatural = true;
14633 : 128 : n->larg = $1;
14634 : 128 : n->rarg = $4;
14635 : 128 : n->usingClause = NIL; /* figure out which columns later... */
14636 : 128 : n->join_using_alias = NULL;
14637 : 128 : n->quals = NULL; /* fill later */
14638 : 128 : $$ = n;
14639 : : }
14640 : : ;
14641 : :
14642 : : alias_clause:
14643 : : AS ColId '(' name_list ')'
14644 : : {
14645 : 4127 : $$ = makeNode(Alias);
14646 : 4127 : $$->aliasname = $2;
14647 : 4127 : $$->colnames = $4;
14648 : : }
14649 : : | AS ColId
14650 : : {
14651 : 10300 : $$ = makeNode(Alias);
14652 : 10300 : $$->aliasname = $2;
14653 : : }
14654 : : | ColId '(' name_list ')'
14655 : : {
14656 : 3926 : $$ = makeNode(Alias);
14657 : 3926 : $$->aliasname = $1;
14658 : 3926 : $$->colnames = $3;
14659 : : }
14660 : : | ColId
14661 : : {
14662 : 174696 : $$ = makeNode(Alias);
14663 : 174696 : $$->aliasname = $1;
14664 : : }
14665 : : ;
14666 : :
14667 : 175080 : opt_alias_clause: alias_clause { $$ = $1; }
14668 : 102801 : | /*EMPTY*/ { $$ = NULL; }
14669 : : ;
14670 : :
14671 : : /*
14672 : : * The alias clause after JOIN ... USING only accepts the AS ColId spelling,
14673 : : * per SQL standard. (The grammar could parse the other variants, but they
14674 : : * don't seem to be useful, and it might lead to parser problems in the
14675 : : * future.)
14676 : : */
14677 : : opt_alias_clause_for_join_using:
14678 : : AS ColId
14679 : : {
14680 : 56 : $$ = makeNode(Alias);
14681 : 56 : $$->aliasname = $2;
14682 : : /* the column name list will be inserted later */
14683 : : }
14684 : 793 : | /*EMPTY*/ { $$ = NULL; }
14685 : : ;
14686 : :
14687 : : /*
14688 : : * func_alias_clause can include both an Alias and a coldeflist, so we make it
14689 : : * return a 2-element list that gets disassembled by calling production.
14690 : : */
14691 : : func_alias_clause:
14692 : : alias_clause
14693 : : {
14694 : 17849 : $$ = list_make2($1, NIL);
14695 : : }
14696 : : | AS '(' TableFuncElementList ')'
14697 : : {
14698 : 70 : $$ = list_make2(NULL, $3);
14699 : : }
14700 : : | AS ColId '(' TableFuncElementList ')'
14701 : : {
14702 : 360 : Alias *a = makeNode(Alias);
14703 : :
14704 : 360 : a->aliasname = $2;
14705 : 360 : $$ = list_make2(a, $4);
14706 : : }
14707 : : | ColId '(' TableFuncElementList ')'
14708 : : {
14709 : 33 : Alias *a = makeNode(Alias);
14710 : :
14711 : 33 : a->aliasname = $1;
14712 : 33 : $$ = list_make2(a, $3);
14713 : : }
14714 : : | /*EMPTY*/
14715 : : {
14716 : 11497 : $$ = list_make2(NULL, NIL);
14717 : : }
14718 : : ;
14719 : :
14720 : 687 : join_type: FULL opt_outer { $$ = JOIN_FULL; }
14721 : 26149 : | LEFT opt_outer { $$ = JOIN_LEFT; }
14722 : 252 : | RIGHT opt_outer { $$ = JOIN_RIGHT; }
14723 : 2366 : | INNER_P { $$ = JOIN_INNER; }
14724 : : ;
14725 : :
14726 : : /* OUTER is just noise... */
14727 : : opt_outer: OUTER_P
14728 : : | /*EMPTY*/
14729 : : ;
14730 : :
14731 : : /* JOIN qualification clauses
14732 : : * Possibilities are:
14733 : : * USING ( column list ) [ AS alias ]
14734 : : * allows only unqualified column names,
14735 : : * which must match between tables.
14736 : : * ON expr allows more general qualifications.
14737 : : *
14738 : : * We return USING as a two-element List (the first item being a sub-List
14739 : : * of the common column names, and the second either an Alias item or NULL).
14740 : : * An ON-expr will not be a List, so it can be told apart that way.
14741 : : */
14742 : :
14743 : : join_qual: USING '(' name_list ')' opt_alias_clause_for_join_using
14744 : : {
14745 : 849 : $$ = (Node *) list_make2($3, $5);
14746 : : }
14747 : : | ON a_expr
14748 : : {
14749 : 53778 : $$ = $2;
14750 : : }
14751 : : ;
14752 : :
14753 : :
14754 : : relation_expr:
14755 : : qualified_name
14756 : : {
14757 : : /* inheritance query, implicitly */
14758 : 316969 : $$ = $1;
14759 : 316969 : $$->inh = true;
14760 : 316969 : $$->alias = NULL;
14761 : : }
14762 : : | extended_relation_expr
14763 : : {
14764 : 3805 : $$ = $1;
14765 : : }
14766 : : ;
14767 : :
14768 : : extended_relation_expr:
14769 : : qualified_name '*'
14770 : : {
14771 : : /* inheritance query, explicitly */
14772 : 140 : $$ = $1;
14773 : 140 : $$->inh = true;
14774 : 140 : $$->alias = NULL;
14775 : : }
14776 : : | ONLY qualified_name
14777 : : {
14778 : : /* no inheritance */
14779 : 3669 : $$ = $2;
14780 : 3669 : $$->inh = false;
14781 : 3669 : $$->alias = NULL;
14782 : : }
14783 : : | ONLY '(' qualified_name ')'
14784 : : {
14785 : : /* no inheritance, SQL99-style syntax */
14786 : 0 : $$ = $3;
14787 : 0 : $$->inh = false;
14788 : 0 : $$->alias = NULL;
14789 : : }
14790 : : ;
14791 : :
14792 : :
14793 : : relation_expr_list:
14794 : 1804 : relation_expr { $$ = list_make1($1); }
14795 : 6241 : | relation_expr_list ',' relation_expr { $$ = lappend($1, $3); }
14796 : : ;
14797 : :
14798 : :
14799 : : /*
14800 : : * Given "UPDATE foo set set ...", we have to decide without looking any
14801 : : * further ahead whether the first "set" is an alias or the UPDATE's SET
14802 : : * keyword. Since "set" is allowed as a column name both interpretations
14803 : : * are feasible. We resolve the shift/reduce conflict by giving the first
14804 : : * relation_expr_opt_alias production a higher precedence than the SET token
14805 : : * has, causing the parser to prefer to reduce, in effect assuming that the
14806 : : * SET is not an alias.
14807 : : */
14808 : : relation_expr_opt_alias: relation_expr %prec UMINUS
14809 : : {
14810 : 11802 : $$ = $1;
14811 : : }
14812 : : | relation_expr ColId
14813 : : {
14814 : 1498 : Alias *alias = makeNode(Alias);
14815 : :
14816 : 1498 : alias->aliasname = $2;
14817 : 1498 : $1->alias = alias;
14818 : 1498 : $$ = $1;
14819 : : }
14820 : : | relation_expr AS ColId
14821 : : {
14822 : 59 : Alias *alias = makeNode(Alias);
14823 : :
14824 : 59 : alias->aliasname = $3;
14825 : 59 : $1->alias = alias;
14826 : 59 : $$ = $1;
14827 : : }
14828 : : ;
14829 : :
14830 : : /*
14831 : : * If an UPDATE/DELETE has FOR PORTION OF, then the relation_expr is separated
14832 : : * from its potential alias by the for_portion_of_clause. So this production
14833 : : * handles the potential alias in those cases. We need to solve the same
14834 : : * problems as relation_expr_opt_alias, in particular resolving a shift/reduce
14835 : : * conflict where "set set" could be an alias plus the SET keyword, or the SET
14836 : : * keyword then a column name. As above, we force the latter interpretation by
14837 : : * giving the non-alias choice a higher precedence.
14838 : : */
14839 : : for_portion_of_opt_alias:
14840 : : AS ColId
14841 : : {
14842 : 12 : Alias *alias = makeNode(Alias);
14843 : :
14844 : 12 : alias->aliasname = $2;
14845 : 12 : $$ = alias;
14846 : : }
14847 : : | BareColLabel
14848 : : {
14849 : 8 : Alias *alias = makeNode(Alias);
14850 : :
14851 : 8 : alias->aliasname = $1;
14852 : 8 : $$ = alias;
14853 : : }
14854 : 1121 : | /* empty */ %prec UMINUS { $$ = NULL; }
14855 : : ;
14856 : :
14857 : : for_portion_of_clause:
14858 : : FOR PORTION OF ColId '(' a_expr ')'
14859 : : {
14860 : 200 : ForPortionOfClause *n = makeNode(ForPortionOfClause);
14861 : 200 : n->range_name = $4;
14862 : 200 : n->location = @4;
14863 : 200 : n->target = $6;
14864 : 200 : n->target_location = @6;
14865 : 200 : $$ = (Node *) n;
14866 : : }
14867 : : | FOR PORTION OF ColId FROM a_expr TO a_expr
14868 : : {
14869 : 941 : ForPortionOfClause *n = makeNode(ForPortionOfClause);
14870 : 941 : n->range_name = $4;
14871 : 941 : n->location = @4;
14872 : 941 : n->target_start = $6;
14873 : 941 : n->target_end = $8;
14874 : 941 : n->target_location = @5;
14875 : 941 : $$ = (Node *) n;
14876 : : }
14877 : : ;
14878 : :
14879 : : /*
14880 : : * TABLESAMPLE decoration in a FROM item
14881 : : */
14882 : : tablesample_clause:
14883 : : TABLESAMPLE func_name '(' expr_list ')' opt_repeatable_clause
14884 : : {
14885 : 172 : RangeTableSample *n = makeNode(RangeTableSample);
14886 : :
14887 : : /* n->relation will be filled in later */
14888 : 172 : n->method = $2;
14889 : 172 : n->args = $4;
14890 : 172 : n->repeatable = $6;
14891 : 172 : n->location = @2;
14892 : 172 : $$ = (Node *) n;
14893 : : }
14894 : : ;
14895 : :
14896 : : opt_repeatable_clause:
14897 : 71 : REPEATABLE '(' a_expr ')' { $$ = (Node *) $3; }
14898 : 101 : | /*EMPTY*/ { $$ = NULL; }
14899 : : ;
14900 : :
14901 : : /*
14902 : : * func_table represents a function invocation in a FROM list. It can be
14903 : : * a plain function call, like "foo(...)", or a ROWS FROM expression with
14904 : : * one or more function calls, "ROWS FROM (foo(...), bar(...))",
14905 : : * optionally with WITH ORDINALITY attached.
14906 : : * In the ROWS FROM syntax, a column definition list can be given for each
14907 : : * function, for example:
14908 : : * ROWS FROM (foo() AS (foo_res_a text, foo_res_b text),
14909 : : * bar() AS (bar_res_a text, bar_res_b text))
14910 : : * It's also possible to attach a column definition list to the RangeFunction
14911 : : * as a whole, but that's handled by the table_ref production.
14912 : : */
14913 : : func_table: func_expr_windowless opt_ordinality
14914 : : {
14915 : 29725 : RangeFunction *n = makeNode(RangeFunction);
14916 : :
14917 : 29725 : n->lateral = false;
14918 : 29725 : n->ordinality = $2;
14919 : 29725 : n->is_rowsfrom = false;
14920 : 29725 : n->functions = list_make1(list_make2($1, NIL));
14921 : : /* alias and coldeflist are set by table_ref production */
14922 : 29725 : $$ = (Node *) n;
14923 : : }
14924 : : | ROWS FROM '(' rowsfrom_list ')' opt_ordinality
14925 : : {
14926 : 88 : RangeFunction *n = makeNode(RangeFunction);
14927 : :
14928 : 88 : n->lateral = false;
14929 : 88 : n->ordinality = $6;
14930 : 88 : n->is_rowsfrom = true;
14931 : 88 : n->functions = $4;
14932 : : /* alias and coldeflist are set by table_ref production */
14933 : 88 : $$ = (Node *) n;
14934 : : }
14935 : : ;
14936 : :
14937 : : rowsfrom_item: func_expr_windowless opt_col_def_list
14938 : 212 : { $$ = list_make2($1, $2); }
14939 : : ;
14940 : :
14941 : : rowsfrom_list:
14942 : 88 : rowsfrom_item { $$ = list_make1($1); }
14943 : 124 : | rowsfrom_list ',' rowsfrom_item { $$ = lappend($1, $3); }
14944 : : ;
14945 : :
14946 : 36 : opt_col_def_list: AS '(' TableFuncElementList ')' { $$ = $3; }
14947 : 176 : | /*EMPTY*/ { $$ = NIL; }
14948 : : ;
14949 : :
14950 : 624 : opt_ordinality: WITH_LA ORDINALITY { $$ = true; }
14951 : 29189 : | /*EMPTY*/ { $$ = false; }
14952 : : ;
14953 : :
14954 : :
14955 : : where_clause:
14956 : 142690 : WHERE a_expr { $$ = $2; }
14957 : 187848 : | /*EMPTY*/ { $$ = NULL; }
14958 : : ;
14959 : :
14960 : : /* variant for UPDATE and DELETE */
14961 : : where_or_current_clause:
14962 : 9334 : WHERE a_expr { $$ = $2; }
14963 : : | WHERE CURRENT_P OF cursor_name
14964 : : {
14965 : 196 : CurrentOfExpr *n = makeNode(CurrentOfExpr);
14966 : :
14967 : : /* cvarno is filled in by parse analysis */
14968 : 196 : n->cursor_name = $4;
14969 : 196 : n->cursor_param = 0;
14970 : 196 : $$ = (Node *) n;
14971 : : }
14972 : 3504 : | /*EMPTY*/ { $$ = NULL; }
14973 : : ;
14974 : :
14975 : :
14976 : : OptTableFuncElementList:
14977 : 482 : TableFuncElementList { $$ = $1; }
14978 : 1894 : | /*EMPTY*/ { $$ = NIL; }
14979 : : ;
14980 : :
14981 : : TableFuncElementList:
14982 : : TableFuncElement
14983 : : {
14984 : 981 : $$ = list_make1($1);
14985 : : }
14986 : : | TableFuncElementList ',' TableFuncElement
14987 : : {
14988 : 1278 : $$ = lappend($1, $3);
14989 : : }
14990 : : ;
14991 : :
14992 : : TableFuncElement: ColId Typename opt_collate_clause
14993 : : {
14994 : 2305 : ColumnDef *n = makeNode(ColumnDef);
14995 : :
14996 : 2305 : n->colname = $1;
14997 : 2305 : n->typeName = $2;
14998 : 2305 : n->inhcount = 0;
14999 : 2305 : n->is_local = true;
15000 : 2305 : n->is_not_null = false;
15001 : 2305 : n->is_from_type = false;
15002 : 2305 : n->storage = 0;
15003 : 2305 : n->raw_default = NULL;
15004 : 2305 : n->cooked_default = NULL;
15005 : 2305 : n->collClause = (CollateClause *) $3;
15006 : 2305 : n->collOid = InvalidOid;
15007 : 2305 : n->constraints = NIL;
15008 : 2305 : n->location = @1;
15009 : 2305 : $$ = (Node *) n;
15010 : : }
15011 : : ;
15012 : :
15013 : : /*
15014 : : * XMLTABLE
15015 : : */
15016 : : xmltable:
15017 : : XMLTABLE '(' c_expr xmlexists_argument COLUMNS xmltable_column_list ')'
15018 : : {
15019 : 137 : RangeTableFunc *n = makeNode(RangeTableFunc);
15020 : :
15021 : 137 : n->rowexpr = $3;
15022 : 137 : n->docexpr = $4;
15023 : 137 : n->columns = $6;
15024 : 137 : n->namespaces = NIL;
15025 : 137 : n->location = @1;
15026 : 137 : $$ = (Node *) n;
15027 : : }
15028 : : | XMLTABLE '(' XMLNAMESPACES '(' xml_namespace_list ')' ','
15029 : : c_expr xmlexists_argument COLUMNS xmltable_column_list ')'
15030 : : {
15031 : 13 : RangeTableFunc *n = makeNode(RangeTableFunc);
15032 : :
15033 : 13 : n->rowexpr = $8;
15034 : 13 : n->docexpr = $9;
15035 : 13 : n->columns = $11;
15036 : 13 : n->namespaces = $5;
15037 : 13 : n->location = @1;
15038 : 13 : $$ = (Node *) n;
15039 : : }
15040 : : ;
15041 : :
15042 : 150 : xmltable_column_list: xmltable_column_el { $$ = list_make1($1); }
15043 : 351 : | xmltable_column_list ',' xmltable_column_el { $$ = lappend($1, $3); }
15044 : : ;
15045 : :
15046 : : xmltable_column_el:
15047 : : ColId Typename
15048 : : {
15049 : 136 : RangeTableFuncCol *fc = makeNode(RangeTableFuncCol);
15050 : :
15051 : 136 : fc->colname = $1;
15052 : 136 : fc->for_ordinality = false;
15053 : 136 : fc->typeName = $2;
15054 : 136 : fc->is_not_null = false;
15055 : 136 : fc->colexpr = NULL;
15056 : 136 : fc->coldefexpr = NULL;
15057 : 136 : fc->location = @1;
15058 : :
15059 : 136 : $$ = (Node *) fc;
15060 : : }
15061 : : | ColId Typename xmltable_column_option_list
15062 : : {
15063 : 324 : RangeTableFuncCol *fc = makeNode(RangeTableFuncCol);
15064 : : ListCell *option;
15065 : 324 : bool nullability_seen = false;
15066 : :
15067 : 324 : fc->colname = $1;
15068 : 324 : fc->typeName = $2;
15069 : 324 : fc->for_ordinality = false;
15070 : 324 : fc->is_not_null = false;
15071 : 324 : fc->colexpr = NULL;
15072 : 324 : fc->coldefexpr = NULL;
15073 : 324 : fc->location = @1;
15074 : :
15075 [ + - + + : 722 : foreach(option, $3)
+ + ]
15076 : : {
15077 : 398 : DefElem *defel = (DefElem *) lfirst(option);
15078 : :
15079 [ + + ]: 398 : if (strcmp(defel->defname, "default") == 0)
15080 : : {
15081 [ - + ]: 37 : if (fc->coldefexpr != NULL)
15082 [ # # ]: 0 : ereport(ERROR,
15083 : : (errcode(ERRCODE_SYNTAX_ERROR),
15084 : : errmsg("only one DEFAULT value is allowed"),
15085 : : parser_errposition(defel->location)));
15086 : 37 : fc->coldefexpr = defel->arg;
15087 : : }
15088 [ + + ]: 361 : else if (strcmp(defel->defname, "path") == 0)
15089 : : {
15090 [ - + ]: 324 : if (fc->colexpr != NULL)
15091 [ # # ]: 0 : ereport(ERROR,
15092 : : (errcode(ERRCODE_SYNTAX_ERROR),
15093 : : errmsg("only one PATH value per column is allowed"),
15094 : : parser_errposition(defel->location)));
15095 : 324 : fc->colexpr = defel->arg;
15096 : : }
15097 [ + - ]: 37 : else if (strcmp(defel->defname, "__pg__is_not_null") == 0)
15098 : : {
15099 [ - + ]: 37 : if (nullability_seen)
15100 [ # # ]: 0 : ereport(ERROR,
15101 : : (errcode(ERRCODE_SYNTAX_ERROR),
15102 : : errmsg("conflicting or redundant NULL / NOT NULL declarations for column \"%s\"", fc->colname),
15103 : : parser_errposition(defel->location)));
15104 : 37 : fc->is_not_null = boolVal(defel->arg);
15105 : 37 : nullability_seen = true;
15106 : : }
15107 : : else
15108 : : {
15109 [ # # ]: 0 : ereport(ERROR,
15110 : : (errcode(ERRCODE_SYNTAX_ERROR),
15111 : : errmsg("unrecognized column option \"%s\"",
15112 : : defel->defname),
15113 : : parser_errposition(defel->location)));
15114 : : }
15115 : : }
15116 : 324 : $$ = (Node *) fc;
15117 : : }
15118 : : | ColId FOR ORDINALITY
15119 : : {
15120 : 41 : RangeTableFuncCol *fc = makeNode(RangeTableFuncCol);
15121 : :
15122 : 41 : fc->colname = $1;
15123 : 41 : fc->for_ordinality = true;
15124 : : /* other fields are ignored, initialized by makeNode */
15125 : 41 : fc->location = @1;
15126 : :
15127 : 41 : $$ = (Node *) fc;
15128 : : }
15129 : : ;
15130 : :
15131 : : xmltable_column_option_list:
15132 : : xmltable_column_option_el
15133 : 324 : { $$ = list_make1($1); }
15134 : : | xmltable_column_option_list xmltable_column_option_el
15135 : 74 : { $$ = lappend($1, $2); }
15136 : : ;
15137 : :
15138 : : xmltable_column_option_el:
15139 : : IDENT b_expr
15140 : : {
15141 [ + - ]: 4 : if (strcmp($1, "__pg__is_not_null") == 0)
15142 [ + - ]: 4 : ereport(ERROR,
15143 : : (errcode(ERRCODE_SYNTAX_ERROR),
15144 : : errmsg("option name \"%s\" cannot be used in XMLTABLE", $1),
15145 : : parser_errposition(@1)));
15146 : 0 : $$ = makeDefElem($1, $2, @1);
15147 : : }
15148 : : | DEFAULT b_expr
15149 : 37 : { $$ = makeDefElem("default", $2, @1); }
15150 : : | NOT NULL_P
15151 : 37 : { $$ = makeDefElem("__pg__is_not_null", (Node *) makeBoolean(true), @1); }
15152 : : | NULL_P
15153 : 0 : { $$ = makeDefElem("__pg__is_not_null", (Node *) makeBoolean(false), @1); }
15154 : : | PATH b_expr
15155 : 324 : { $$ = makeDefElem("path", $2, @1); }
15156 : : ;
15157 : :
15158 : : xml_namespace_list:
15159 : : xml_namespace_el
15160 : 13 : { $$ = list_make1($1); }
15161 : : | xml_namespace_list ',' xml_namespace_el
15162 : 0 : { $$ = lappend($1, $3); }
15163 : : ;
15164 : :
15165 : : xml_namespace_el:
15166 : : b_expr AS ColLabel
15167 : : {
15168 : 9 : $$ = makeNode(ResTarget);
15169 : 9 : $$->name = $3;
15170 : 9 : $$->indirection = NIL;
15171 : 9 : $$->val = $1;
15172 : 9 : $$->location = @1;
15173 : : }
15174 : : | DEFAULT b_expr
15175 : : {
15176 : 4 : $$ = makeNode(ResTarget);
15177 : 4 : $$->name = NULL;
15178 : 4 : $$->indirection = NIL;
15179 : 4 : $$->val = $2;
15180 : 4 : $$->location = @1;
15181 : : }
15182 : : ;
15183 : :
15184 : : json_table:
15185 : : JSON_TABLE '('
15186 : : json_value_expr ',' a_expr json_table_path_name_opt
15187 : : json_passing_clause_opt
15188 : : COLUMNS '(' json_table_column_definition_list ')'
15189 : : json_table_plan_clause_opt
15190 : : json_on_error_clause_opt
15191 : : ')'
15192 : : {
15193 : 488 : JsonTable *n = makeNode(JsonTable);
15194 : : char *pathstring;
15195 : :
15196 : 488 : n->context_item = (JsonValueExpr *) $3;
15197 [ + + ]: 488 : if (!IsA($5, A_Const) ||
15198 [ - + ]: 484 : castNode(A_Const, $5)->val.node.type != T_String)
15199 [ + - ]: 4 : ereport(ERROR,
15200 : : errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
15201 : : errmsg("only string constants are supported in"
15202 : : " JSON_TABLE path specification"),
15203 : : parser_errposition(@5));
15204 : 484 : pathstring = castNode(A_Const, $5)->val.sval.sval;
15205 : 484 : n->pathspec = makeJsonTablePathSpec(pathstring, $6, @5, @6);
15206 : 484 : n->passing = $7;
15207 : 484 : n->columns = $10;
15208 : 484 : n->planspec = (JsonTablePlanSpec *) $12;
15209 : 484 : n->on_error = (JsonBehavior *) $13;
15210 : 484 : n->location = @1;
15211 : 484 : $$ = (Node *) n;
15212 : : }
15213 : : ;
15214 : :
15215 : : json_table_path_name_opt:
15216 : 144 : AS name { $$ = $2; }
15217 : 352 : | /* empty */ { $$ = NULL; }
15218 : : ;
15219 : :
15220 : : json_table_column_definition_list:
15221 : : json_table_column_definition
15222 : 1032 : { $$ = list_make1($1); }
15223 : : | json_table_column_definition_list ',' json_table_column_definition
15224 : 688 : { $$ = lappend($1, $3); }
15225 : : ;
15226 : :
15227 : : json_table_column_definition:
15228 : : ColId FOR ORDINALITY
15229 : : {
15230 : 100 : JsonTableColumn *n = makeNode(JsonTableColumn);
15231 : :
15232 : 100 : n->coltype = JTC_FOR_ORDINALITY;
15233 : 100 : n->name = $1;
15234 : 100 : n->location = @1;
15235 : 100 : $$ = (Node *) n;
15236 : : }
15237 : : | ColId Typename
15238 : : json_table_column_path_clause_opt
15239 : : json_wrapper_behavior
15240 : : json_quotes_clause_opt
15241 : : json_behavior_clause_opt
15242 : : {
15243 : 880 : JsonTableColumn *n = makeNode(JsonTableColumn);
15244 : :
15245 : 880 : n->coltype = JTC_REGULAR;
15246 : 880 : n->name = $1;
15247 : 880 : n->typeName = $2;
15248 : 880 : n->format = makeJsonFormat(JS_FORMAT_DEFAULT, JS_ENC_DEFAULT, -1);
15249 : 880 : n->pathspec = (JsonTablePathSpec *) $3;
15250 : 880 : n->wrapper = $4;
15251 : 880 : n->quotes = $5;
15252 : 880 : n->on_empty = (JsonBehavior *) linitial($6);
15253 : 880 : n->on_error = (JsonBehavior *) lsecond($6);
15254 : 880 : n->location = @1;
15255 : 880 : $$ = (Node *) n;
15256 : : }
15257 : : | ColId Typename json_format_clause
15258 : : json_table_column_path_clause_opt
15259 : : json_wrapper_behavior
15260 : : json_quotes_clause_opt
15261 : : json_behavior_clause_opt
15262 : : {
15263 : 92 : JsonTableColumn *n = makeNode(JsonTableColumn);
15264 : :
15265 : 92 : n->coltype = JTC_FORMATTED;
15266 : 92 : n->name = $1;
15267 : 92 : n->typeName = $2;
15268 : 92 : n->format = (JsonFormat *) $3;
15269 : 92 : n->pathspec = (JsonTablePathSpec *) $4;
15270 : 92 : n->wrapper = $5;
15271 : 92 : n->quotes = $6;
15272 : 92 : n->on_empty = (JsonBehavior *) linitial($7);
15273 : 92 : n->on_error = (JsonBehavior *) lsecond($7);
15274 : 92 : n->location = @1;
15275 : 92 : $$ = (Node *) n;
15276 : : }
15277 : : | ColId Typename
15278 : : EXISTS json_table_column_path_clause_opt
15279 : : json_on_error_clause_opt
15280 : : {
15281 : 104 : JsonTableColumn *n = makeNode(JsonTableColumn);
15282 : :
15283 : 104 : n->coltype = JTC_EXISTS;
15284 : 104 : n->name = $1;
15285 : 104 : n->typeName = $2;
15286 : 104 : n->format = makeJsonFormat(JS_FORMAT_DEFAULT, JS_ENC_DEFAULT, -1);
15287 : 104 : n->wrapper = JSW_NONE;
15288 : 104 : n->quotes = JS_QUOTES_UNSPEC;
15289 : 104 : n->pathspec = (JsonTablePathSpec *) $4;
15290 : 104 : n->on_empty = NULL;
15291 : 104 : n->on_error = (JsonBehavior *) $5;
15292 : 104 : n->location = @1;
15293 : 104 : $$ = (Node *) n;
15294 : : }
15295 : : | NESTED path_opt Sconst
15296 : : COLUMNS '(' json_table_column_definition_list ')'
15297 : : {
15298 : 108 : JsonTableColumn *n = makeNode(JsonTableColumn);
15299 : :
15300 : 108 : n->coltype = JTC_NESTED;
15301 : 108 : n->pathspec = makeJsonTablePathSpec($3, NULL, @3, -1);
15302 : 108 : n->columns = $6;
15303 : 108 : n->location = @1;
15304 : 108 : $$ = (Node *) n;
15305 : : }
15306 : : | NESTED path_opt Sconst AS name
15307 : : COLUMNS '(' json_table_column_definition_list ')'
15308 : : {
15309 : 436 : JsonTableColumn *n = makeNode(JsonTableColumn);
15310 : :
15311 : 436 : n->coltype = JTC_NESTED;
15312 : 436 : n->pathspec = makeJsonTablePathSpec($3, $5, @3, @5);
15313 : 436 : n->columns = $8;
15314 : 436 : n->location = @1;
15315 : 436 : $$ = (Node *) n;
15316 : : }
15317 : : ;
15318 : :
15319 : : path_opt:
15320 : : PATH
15321 : : | /* EMPTY */
15322 : : ;
15323 : :
15324 : : json_table_column_path_clause_opt:
15325 : : PATH Sconst
15326 : 844 : { $$ = (Node *) makeJsonTablePathSpec($2, NULL, @2, -1); }
15327 : : | /* EMPTY */
15328 : 236 : { $$ = NULL; }
15329 : : ;
15330 : :
15331 : : json_table_plan_clause_opt:
15332 : : PLAN '(' json_table_plan ')'
15333 : 84 : { $$ = $3; }
15334 : : | PLAN DEFAULT '(' json_table_default_plan_choices ')'
15335 : 24 : { $$ = makeJsonTableDefaultPlan($4, @1); }
15336 : : | /* EMPTY */
15337 : 380 : { $$ = NULL; }
15338 : : ;
15339 : :
15340 : : json_table_plan:
15341 : : json_table_plan_simple
15342 : : | json_table_plan_outer
15343 : : | json_table_plan_inner
15344 : : | json_table_plan_union
15345 : : | json_table_plan_cross
15346 : : ;
15347 : :
15348 : : json_table_plan_simple:
15349 : : name
15350 : 276 : { $$ = makeJsonTableSimplePlan($1, @1); }
15351 : : ;
15352 : :
15353 : : json_table_plan_outer:
15354 : : json_table_plan_simple OUTER_P json_table_plan_primary
15355 : 68 : { $$ = makeJsonTableJoinedPlan(JSTP_JOIN_OUTER, $1, $3, @1); }
15356 : : ;
15357 : :
15358 : : json_table_plan_inner:
15359 : : json_table_plan_simple INNER_P json_table_plan_primary
15360 : 40 : { $$ = makeJsonTableJoinedPlan(JSTP_JOIN_INNER, $1, $3, @1); }
15361 : : ;
15362 : :
15363 : : json_table_plan_union:
15364 : : json_table_plan_primary UNION json_table_plan_primary
15365 : 28 : { $$ = makeJsonTableJoinedPlan(JSTP_JOIN_UNION, $1, $3, @1); }
15366 : : | json_table_plan_union UNION json_table_plan_primary
15367 : 4 : { $$ = makeJsonTableJoinedPlan(JSTP_JOIN_UNION, $1, $3, @1); }
15368 : : ;
15369 : :
15370 : : json_table_plan_cross:
15371 : : json_table_plan_primary CROSS json_table_plan_primary
15372 : 52 : { $$ = makeJsonTableJoinedPlan(JSTP_JOIN_CROSS, $1, $3, @1); }
15373 : : | json_table_plan_cross CROSS json_table_plan_primary
15374 : 0 : { $$ = makeJsonTableJoinedPlan(JSTP_JOIN_CROSS, $1, $3, @1); }
15375 : : ;
15376 : :
15377 : : json_table_plan_primary:
15378 : : json_table_plan_simple
15379 : 156 : { $$ = $1; }
15380 : : | '(' json_table_plan ')'
15381 : : {
15382 : 116 : castNode(JsonTablePlanSpec, $2)->location = @1;
15383 : 116 : $$ = $2;
15384 : : }
15385 : : ;
15386 : :
15387 : : json_table_default_plan_choices:
15388 : : json_table_default_plan_inner_outer
15389 : 4 : { $$ = $1 | JSTP_JOIN_UNION; }
15390 : : | json_table_default_plan_union_cross
15391 : 8 : { $$ = $1 | JSTP_JOIN_OUTER; }
15392 : : | json_table_default_plan_inner_outer ',' json_table_default_plan_union_cross
15393 : 8 : { $$ = $1 | $3; }
15394 : : | json_table_default_plan_union_cross ',' json_table_default_plan_inner_outer
15395 : 4 : { $$ = $1 | $3; }
15396 : : ;
15397 : :
15398 : : json_table_default_plan_inner_outer:
15399 : 8 : INNER_P { $$ = JSTP_JOIN_INNER; }
15400 : 8 : | OUTER_P { $$ = JSTP_JOIN_OUTER; }
15401 : : ;
15402 : :
15403 : : json_table_default_plan_union_cross:
15404 : 12 : UNION { $$ = JSTP_JOIN_UNION; }
15405 : 8 : | CROSS { $$ = JSTP_JOIN_CROSS; }
15406 : : ;
15407 : :
15408 : : /*****************************************************************************
15409 : : *
15410 : : * Type syntax
15411 : : * SQL introduces a large amount of type-specific syntax.
15412 : : * Define individual clauses to handle these cases, and use
15413 : : * the generic case to handle regular type-extensible Postgres syntax.
15414 : : * - thomas 1997-10-10
15415 : : *
15416 : : *****************************************************************************/
15417 : :
15418 : : Typename: SimpleTypename opt_array_bounds
15419 : : {
15420 : 309180 : $$ = $1;
15421 : 309180 : $$->arrayBounds = $2;
15422 : : }
15423 : : | SETOF SimpleTypename opt_array_bounds
15424 : : {
15425 : 1055 : $$ = $2;
15426 : 1055 : $$->arrayBounds = $3;
15427 : 1055 : $$->setof = true;
15428 : : }
15429 : : /* SQL standard syntax, currently only one-dimensional */
15430 : : | SimpleTypename ARRAY '[' Iconst ']'
15431 : : {
15432 : 4 : $$ = $1;
15433 : 4 : $$->arrayBounds = list_make1(makeInteger($4));
15434 : : }
15435 : : | SETOF SimpleTypename ARRAY '[' Iconst ']'
15436 : : {
15437 : 0 : $$ = $2;
15438 : 0 : $$->arrayBounds = list_make1(makeInteger($5));
15439 : 0 : $$->setof = true;
15440 : : }
15441 : : | SimpleTypename ARRAY
15442 : : {
15443 : 0 : $$ = $1;
15444 : 0 : $$->arrayBounds = list_make1(makeInteger(-1));
15445 : : }
15446 : : | SETOF SimpleTypename ARRAY
15447 : : {
15448 : 0 : $$ = $2;
15449 : 0 : $$->arrayBounds = list_make1(makeInteger(-1));
15450 : 0 : $$->setof = true;
15451 : : }
15452 : : ;
15453 : :
15454 : : opt_array_bounds:
15455 : : opt_array_bounds '[' ']'
15456 : 8423 : { $$ = lappend($1, makeInteger(-1)); }
15457 : : | opt_array_bounds '[' Iconst ']'
15458 : 38 : { $$ = lappend($1, makeInteger($3)); }
15459 : : | /*EMPTY*/
15460 : 310235 : { $$ = NIL; }
15461 : : ;
15462 : :
15463 : : SimpleTypename:
15464 : 243325 : GenericType { $$ = $1; }
15465 : 57154 : | Numeric { $$ = $1; }
15466 : 1283 : | Bit { $$ = $1; }
15467 : 2236 : | Character { $$ = $1; }
15468 : 3051 : | ConstDatetime { $$ = $1; }
15469 : : | ConstInterval opt_interval
15470 : : {
15471 : 2268 : $$ = $1;
15472 : 2268 : $$->typmods = $2;
15473 : : }
15474 : : | ConstInterval '(' Iconst ')'
15475 : : {
15476 : 0 : $$ = $1;
15477 : 0 : $$->typmods = list_make2(makeIntConst(INTERVAL_FULL_RANGE, -1),
15478 : : makeIntConst($3, @3));
15479 : : }
15480 : 1185 : | JsonType { $$ = $1; }
15481 : : ;
15482 : :
15483 : : /* We have a separate ConstTypename to allow defaulting fixed-length
15484 : : * types such as CHAR() and BIT() to an unspecified length.
15485 : : * SQL9x requires that these default to a length of one, but this
15486 : : * makes no sense for constructs like CHAR 'hi' and BIT '0101',
15487 : : * where there is an obvious better choice to make.
15488 : : * Note that ConstInterval is not included here since it must
15489 : : * be pushed up higher in the rules to accommodate the postfix
15490 : : * options (e.g. INTERVAL '1' YEAR). Likewise, we have to handle
15491 : : * the generic-type-name case in AexprConst to avoid premature
15492 : : * reduce/reduce conflicts against function names.
15493 : : */
15494 : : ConstTypename:
15495 : 52 : Numeric { $$ = $1; }
15496 : 0 : | ConstBit { $$ = $1; }
15497 : 22 : | ConstCharacter { $$ = $1; }
15498 : 1793 : | ConstDatetime { $$ = $1; }
15499 : 176 : | JsonType { $$ = $1; }
15500 : : ;
15501 : :
15502 : : /*
15503 : : * GenericType covers all type names that don't have special syntax mandated
15504 : : * by the standard, including qualified names. We also allow type modifiers.
15505 : : * To avoid parsing conflicts against function invocations, the modifiers
15506 : : * have to be shown as expr_list here, but parse analysis will only accept
15507 : : * constants for them.
15508 : : */
15509 : : GenericType:
15510 : : type_function_name opt_type_modifiers
15511 : : {
15512 : 173263 : $$ = makeTypeName($1);
15513 : 173263 : $$->typmods = $2;
15514 : 173263 : $$->location = @1;
15515 : : }
15516 : : | type_function_name attrs opt_type_modifiers
15517 : : {
15518 : 70062 : $$ = makeTypeNameFromNameList(lcons(makeString($1), $2));
15519 : 70062 : $$->typmods = $3;
15520 : 70062 : $$->location = @1;
15521 : : }
15522 : : ;
15523 : :
15524 : 796 : opt_type_modifiers: '(' expr_list ')' { $$ = $2; }
15525 : 246560 : | /* EMPTY */ { $$ = NIL; }
15526 : : ;
15527 : :
15528 : : /*
15529 : : * SQL numeric data types
15530 : : */
15531 : : Numeric: INT_P
15532 : : {
15533 : 26755 : $$ = SystemTypeName("int4");
15534 : 26755 : $$->location = @1;
15535 : : }
15536 : : | INTEGER
15537 : : {
15538 : 13971 : $$ = SystemTypeName("int4");
15539 : 13971 : $$->location = @1;
15540 : : }
15541 : : | SMALLINT
15542 : : {
15543 : 712 : $$ = SystemTypeName("int2");
15544 : 712 : $$->location = @1;
15545 : : }
15546 : : | BIGINT
15547 : : {
15548 : 2725 : $$ = SystemTypeName("int8");
15549 : 2725 : $$->location = @1;
15550 : : }
15551 : : | REAL
15552 : : {
15553 : 3724 : $$ = SystemTypeName("float4");
15554 : 3724 : $$->location = @1;
15555 : : }
15556 : : | FLOAT_P opt_float
15557 : : {
15558 : 358 : $$ = $2;
15559 : 358 : $$->location = @1;
15560 : : }
15561 : : | DOUBLE_P PRECISION
15562 : : {
15563 : 473 : $$ = SystemTypeName("float8");
15564 : 473 : $$->location = @1;
15565 : : }
15566 : : | DECIMAL_P opt_type_modifiers
15567 : : {
15568 : 142 : $$ = SystemTypeName("numeric");
15569 : 142 : $$->typmods = $2;
15570 : 142 : $$->location = @1;
15571 : : }
15572 : : | DEC opt_type_modifiers
15573 : : {
15574 : 0 : $$ = SystemTypeName("numeric");
15575 : 0 : $$->typmods = $2;
15576 : 0 : $$->location = @1;
15577 : : }
15578 : : | NUMERIC opt_type_modifiers
15579 : : {
15580 : 3889 : $$ = SystemTypeName("numeric");
15581 : 3889 : $$->typmods = $2;
15582 : 3889 : $$->location = @1;
15583 : : }
15584 : : | BOOLEAN_P
15585 : : {
15586 : 4457 : $$ = SystemTypeName("bool");
15587 : 4457 : $$->location = @1;
15588 : : }
15589 : : ;
15590 : :
15591 : : opt_float: '(' Iconst ')'
15592 : : {
15593 : : /*
15594 : : * Check FLOAT() precision limits assuming IEEE floating
15595 : : * types - thomas 1997-09-18
15596 : : */
15597 [ - + ]: 1 : if ($2 < 1)
15598 [ # # ]: 0 : ereport(ERROR,
15599 : : (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
15600 : : errmsg("precision for type float must be at least 1 bit"),
15601 : : parser_errposition(@2)));
15602 [ + - ]: 1 : else if ($2 <= 24)
15603 : 1 : $$ = SystemTypeName("float4");
15604 [ # # ]: 0 : else if ($2 <= 53)
15605 : 0 : $$ = SystemTypeName("float8");
15606 : : else
15607 [ # # ]: 0 : ereport(ERROR,
15608 : : (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
15609 : : errmsg("precision for type float must be less than 54 bits"),
15610 : : parser_errposition(@2)));
15611 : : }
15612 : : | /*EMPTY*/
15613 : : {
15614 : 357 : $$ = SystemTypeName("float8");
15615 : : }
15616 : : ;
15617 : :
15618 : : /*
15619 : : * SQL bit-field data types
15620 : : * The following implements BIT() and BIT VARYING().
15621 : : */
15622 : : Bit: BitWithLength
15623 : : {
15624 : 1154 : $$ = $1;
15625 : : }
15626 : : | BitWithoutLength
15627 : : {
15628 : 129 : $$ = $1;
15629 : : }
15630 : : ;
15631 : :
15632 : : /* ConstBit is like Bit except "BIT" defaults to unspecified length */
15633 : : /* See notes for ConstCharacter, which addresses same issue for "CHAR" */
15634 : : ConstBit: BitWithLength
15635 : : {
15636 : 0 : $$ = $1;
15637 : : }
15638 : : | BitWithoutLength
15639 : : {
15640 : 0 : $$ = $1;
15641 : 0 : $$->typmods = NIL;
15642 : : }
15643 : : ;
15644 : :
15645 : : BitWithLength:
15646 : : BIT opt_varying '(' expr_list ')'
15647 : : {
15648 : : char *typname;
15649 : :
15650 [ + + ]: 1154 : typname = $2 ? "varbit" : "bit";
15651 : 1154 : $$ = SystemTypeName(typname);
15652 : 1154 : $$->typmods = $4;
15653 : 1154 : $$->location = @1;
15654 : : }
15655 : : ;
15656 : :
15657 : : BitWithoutLength:
15658 : : BIT opt_varying
15659 : : {
15660 : : /* bit defaults to bit(1), varbit to no limit */
15661 [ + + ]: 129 : if ($2)
15662 : : {
15663 : 10 : $$ = SystemTypeName("varbit");
15664 : : }
15665 : : else
15666 : : {
15667 : 119 : $$ = SystemTypeName("bit");
15668 : 119 : $$->typmods = list_make1(makeIntConst(1, -1));
15669 : : }
15670 : 129 : $$->location = @1;
15671 : : }
15672 : : ;
15673 : :
15674 : :
15675 : : /*
15676 : : * SQL character data types
15677 : : * The following implements CHAR() and VARCHAR().
15678 : : */
15679 : : Character: CharacterWithLength
15680 : : {
15681 : 1377 : $$ = $1;
15682 : : }
15683 : : | CharacterWithoutLength
15684 : : {
15685 : 859 : $$ = $1;
15686 : : }
15687 : : ;
15688 : :
15689 : : ConstCharacter: CharacterWithLength
15690 : : {
15691 : 8 : $$ = $1;
15692 : : }
15693 : : | CharacterWithoutLength
15694 : : {
15695 : : /* Length was not specified so allow to be unrestricted.
15696 : : * This handles problems with fixed-length (bpchar) strings
15697 : : * which in column definitions must default to a length
15698 : : * of one, but should not be constrained if the length
15699 : : * was not specified.
15700 : : */
15701 : 14 : $$ = $1;
15702 : 14 : $$->typmods = NIL;
15703 : : }
15704 : : ;
15705 : :
15706 : : CharacterWithLength: character '(' Iconst ')'
15707 : : {
15708 : 1385 : $$ = SystemTypeName($1);
15709 : 1385 : $$->typmods = list_make1(makeIntConst($3, @3));
15710 : 1385 : $$->location = @1;
15711 : : }
15712 : : ;
15713 : :
15714 : : CharacterWithoutLength: character
15715 : : {
15716 : 873 : $$ = SystemTypeName($1);
15717 : : /* char defaults to char(1), varchar to no limit */
15718 [ + + ]: 873 : if (strcmp($1, "bpchar") == 0)
15719 : 154 : $$->typmods = list_make1(makeIntConst(1, -1));
15720 : 873 : $$->location = @1;
15721 : : }
15722 : : ;
15723 : :
15724 : : character: CHARACTER opt_varying
15725 [ + + ]: 343 : { $$ = $2 ? "varchar": "bpchar"; }
15726 : : | CHAR_P opt_varying
15727 [ - + ]: 745 : { $$ = $2 ? "varchar": "bpchar"; }
15728 : : | VARCHAR
15729 : 1168 : { $$ = "varchar"; }
15730 : : | NATIONAL CHARACTER opt_varying
15731 [ # # ]: 0 : { $$ = $3 ? "varchar": "bpchar"; }
15732 : : | NATIONAL CHAR_P opt_varying
15733 [ # # ]: 0 : { $$ = $3 ? "varchar": "bpchar"; }
15734 : : | NCHAR opt_varying
15735 [ - + ]: 2 : { $$ = $2 ? "varchar": "bpchar"; }
15736 : : ;
15737 : :
15738 : : opt_varying:
15739 : 289 : VARYING { $$ = true; }
15740 : 2084 : | /*EMPTY*/ { $$ = false; }
15741 : : ;
15742 : :
15743 : : /*
15744 : : * SQL date/time types
15745 : : */
15746 : : ConstDatetime:
15747 : : TIMESTAMP '(' Iconst ')' opt_timezone
15748 : : {
15749 [ + + ]: 79 : if ($5)
15750 : 64 : $$ = SystemTypeName("timestamptz");
15751 : : else
15752 : 15 : $$ = SystemTypeName("timestamp");
15753 : 79 : $$->typmods = list_make1(makeIntConst($3, @3));
15754 : 79 : $$->location = @1;
15755 : : }
15756 : : | TIMESTAMP opt_timezone
15757 : : {
15758 [ + + ]: 3218 : if ($2)
15759 : 782 : $$ = SystemTypeName("timestamptz");
15760 : : else
15761 : 2436 : $$ = SystemTypeName("timestamp");
15762 : 3218 : $$->location = @1;
15763 : : }
15764 : : | TIME '(' Iconst ')' opt_timezone
15765 : : {
15766 [ + + ]: 14 : if ($5)
15767 : 5 : $$ = SystemTypeName("timetz");
15768 : : else
15769 : 9 : $$ = SystemTypeName("time");
15770 : 14 : $$->typmods = list_make1(makeIntConst($3, @3));
15771 : 14 : $$->location = @1;
15772 : : }
15773 : : | TIME opt_timezone
15774 : : {
15775 [ + + ]: 1533 : if ($2)
15776 : 226 : $$ = SystemTypeName("timetz");
15777 : : else
15778 : 1307 : $$ = SystemTypeName("time");
15779 : 1533 : $$->location = @1;
15780 : : }
15781 : : ;
15782 : :
15783 : : ConstInterval:
15784 : : INTERVAL
15785 : : {
15786 : 4484 : $$ = SystemTypeName("interval");
15787 : 4484 : $$->location = @1;
15788 : : }
15789 : : ;
15790 : :
15791 : : opt_timezone:
15792 : 1077 : WITH_LA TIME ZONE { $$ = true; }
15793 : 376 : | WITHOUT_LA TIME ZONE { $$ = false; }
15794 : 3391 : | /*EMPTY*/ { $$ = false; }
15795 : : ;
15796 : :
15797 : : /*
15798 : : * We need to handle this shift/reduce conflict:
15799 : : * FOR PORTION OF valid_at FROM t + INTERVAL '1' YEAR TO MONTH.
15800 : : * We don't see far enough ahead to know if there is another TO coming.
15801 : : * We prefer to interpret this as FROM (t + INTERVAL '1' YEAR TO MONTH),
15802 : : * i.e. to shift.
15803 : : * That gives the user the option of adding parentheses to get the other meaning.
15804 : : * If we reduced, intervals could never have a TO.
15805 : : */
15806 : : opt_interval:
15807 : : YEAR_P %prec IS
15808 : 8 : { $$ = list_make1(makeIntConst(INTERVAL_MASK(YEAR), @1)); }
15809 : : | MONTH_P
15810 : 12 : { $$ = list_make1(makeIntConst(INTERVAL_MASK(MONTH), @1)); }
15811 : : | DAY_P %prec IS
15812 : 12 : { $$ = list_make1(makeIntConst(INTERVAL_MASK(DAY), @1)); }
15813 : : | HOUR_P %prec IS
15814 : 12 : { $$ = list_make1(makeIntConst(INTERVAL_MASK(HOUR), @1)); }
15815 : : | MINUTE_P %prec IS
15816 : 8 : { $$ = list_make1(makeIntConst(INTERVAL_MASK(MINUTE), @1)); }
15817 : : | interval_second
15818 : 24 : { $$ = $1; }
15819 : : | YEAR_P TO MONTH_P
15820 : : {
15821 : 12 : $$ = list_make1(makeIntConst(INTERVAL_MASK(YEAR) |
15822 : : INTERVAL_MASK(MONTH), @1));
15823 : : }
15824 : : | DAY_P TO HOUR_P
15825 : : {
15826 : 16 : $$ = list_make1(makeIntConst(INTERVAL_MASK(DAY) |
15827 : : INTERVAL_MASK(HOUR), @1));
15828 : : }
15829 : : | DAY_P TO MINUTE_P
15830 : : {
15831 : 16 : $$ = list_make1(makeIntConst(INTERVAL_MASK(DAY) |
15832 : : INTERVAL_MASK(HOUR) |
15833 : : INTERVAL_MASK(MINUTE), @1));
15834 : : }
15835 : : | DAY_P TO interval_second
15836 : : {
15837 : 32 : $$ = $3;
15838 : 32 : linitial($$) = makeIntConst(INTERVAL_MASK(DAY) |
15839 : : INTERVAL_MASK(HOUR) |
15840 : : INTERVAL_MASK(MINUTE) |
15841 : 32 : INTERVAL_MASK(SECOND), @1);
15842 : : }
15843 : : | HOUR_P TO MINUTE_P
15844 : : {
15845 : 16 : $$ = list_make1(makeIntConst(INTERVAL_MASK(HOUR) |
15846 : : INTERVAL_MASK(MINUTE), @1));
15847 : : }
15848 : : | HOUR_P TO interval_second
15849 : : {
15850 : 24 : $$ = $3;
15851 : 24 : linitial($$) = makeIntConst(INTERVAL_MASK(HOUR) |
15852 : : INTERVAL_MASK(MINUTE) |
15853 : 24 : INTERVAL_MASK(SECOND), @1);
15854 : : }
15855 : : | MINUTE_P TO interval_second
15856 : : {
15857 : 44 : $$ = $3;
15858 : 44 : linitial($$) = makeIntConst(INTERVAL_MASK(MINUTE) |
15859 : 44 : INTERVAL_MASK(SECOND), @1);
15860 : : }
15861 : : | /*EMPTY*/
15862 : 4236 : { $$ = NIL; }
15863 : : ;
15864 : :
15865 : : interval_second:
15866 : : SECOND_P
15867 : : {
15868 : 68 : $$ = list_make1(makeIntConst(INTERVAL_MASK(SECOND), @1));
15869 : : }
15870 : : | SECOND_P '(' Iconst ')'
15871 : : {
15872 : 56 : $$ = list_make2(makeIntConst(INTERVAL_MASK(SECOND), @1),
15873 : : makeIntConst($3, @3));
15874 : : }
15875 : : ;
15876 : :
15877 : : JsonType:
15878 : : JSON
15879 : : {
15880 : 1361 : $$ = SystemTypeName("json");
15881 : 1361 : $$->location = @1;
15882 : : }
15883 : : ;
15884 : :
15885 : : /*****************************************************************************
15886 : : *
15887 : : * expression grammar
15888 : : *
15889 : : *****************************************************************************/
15890 : :
15891 : : /*
15892 : : * General expressions
15893 : : * This is the heart of the expression syntax.
15894 : : *
15895 : : * We have two expression types: a_expr is the unrestricted kind, and
15896 : : * b_expr is a subset that must be used in some places to avoid shift/reduce
15897 : : * conflicts. For example, we can't do BETWEEN as "BETWEEN a_expr AND a_expr"
15898 : : * because that use of AND conflicts with AND as a boolean operator. So,
15899 : : * b_expr is used in BETWEEN and we remove boolean keywords from b_expr.
15900 : : *
15901 : : * Note that '(' a_expr ')' is a b_expr, so an unrestricted expression can
15902 : : * always be used by surrounding it with parens.
15903 : : *
15904 : : * c_expr is all the productions that are common to a_expr and b_expr;
15905 : : * it's factored out just to eliminate redundant coding.
15906 : : *
15907 : : * Be careful of productions involving more than one terminal token.
15908 : : * By default, bison will assign such productions the precedence of their
15909 : : * last terminal, but in nearly all cases you want it to be the precedence
15910 : : * of the first terminal instead; otherwise you will not get the behavior
15911 : : * you expect! So we use %prec annotations freely to set precedences.
15912 : : */
15913 : 2412710 : a_expr: c_expr { $$ = $1; }
15914 : : | a_expr TYPECAST Typename
15915 : 146202 : { $$ = makeTypeCast($1, $3, @2); }
15916 : : | a_expr COLLATE any_name
15917 : : {
15918 : 6969 : CollateClause *n = makeNode(CollateClause);
15919 : :
15920 : 6969 : n->arg = $1;
15921 : 6969 : n->collname = $3;
15922 : 6969 : n->location = @2;
15923 : 6969 : $$ = (Node *) n;
15924 : : }
15925 : : | a_expr AT TIME ZONE a_expr %prec AT
15926 : : {
15927 : 272 : $$ = (Node *) makeFuncCall(SystemFuncName("timezone"),
15928 : 272 : list_make2($5, $1),
15929 : : COERCE_SQL_SYNTAX,
15930 : 272 : @2);
15931 : : }
15932 : : | a_expr AT LOCAL %prec AT
15933 : : {
15934 : 28 : $$ = (Node *) makeFuncCall(SystemFuncName("timezone"),
15935 : 28 : list_make1($1),
15936 : : COERCE_SQL_SYNTAX,
15937 : : -1);
15938 : : }
15939 : : /*
15940 : : * These operators must be called out explicitly in order to make use
15941 : : * of bison's automatic operator-precedence handling. All other
15942 : : * operator names are handled by the generic productions using "Op",
15943 : : * below; and all those operators will have the same precedence.
15944 : : *
15945 : : * If you add more explicitly-known operators, be sure to add them
15946 : : * also to b_expr and to the MathOp list below.
15947 : : */
15948 : : | '+' a_expr %prec UMINUS
15949 : 8 : { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "+", NULL, $2, @1); }
15950 : : | '-' a_expr %prec UMINUS
15951 : 6465 : { $$ = doNegate($2, @1); }
15952 : : | a_expr '+' a_expr
15953 : 9649 : { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "+", $1, $3, @2); }
15954 : : | a_expr '-' a_expr
15955 : 2882 : { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "-", $1, $3, @2); }
15956 : : | a_expr '*' a_expr
15957 : 4265 : { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "*", $1, $3, @2); }
15958 : : | a_expr '/' a_expr
15959 : 2240 : { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "/", $1, $3, @2); }
15960 : : | a_expr '%' a_expr
15961 : 2068 : { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "%", $1, $3, @2); }
15962 : : | a_expr '^' a_expr
15963 : 312 : { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "^", $1, $3, @2); }
15964 : : | a_expr '<' a_expr
15965 : 6918 : { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "<", $1, $3, @2); }
15966 : : | a_expr '>' a_expr
15967 : 10952 : { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, ">", $1, $3, @2); }
15968 : : | a_expr '=' a_expr
15969 : 262395 : { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "=", $1, $3, @2); }
15970 : : | a_expr LESS_EQUALS a_expr
15971 : 2956 : { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "<=", $1, $3, @2); }
15972 : : | a_expr GREATER_EQUALS a_expr
15973 : 7315 : { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, ">=", $1, $3, @2); }
15974 : : | a_expr NOT_EQUALS a_expr
15975 : 24096 : { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "<>", $1, $3, @2); }
15976 : : | RIGHT_ARROW a_expr
15977 : 0 : { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "->", NULL, $2, @1); }
15978 : : | '|' a_expr
15979 : 0 : { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "|", NULL, $2, @1); }
15980 : : | a_expr RIGHT_ARROW a_expr
15981 : 540 : { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "->", $1, $3, @2); }
15982 : : | a_expr '|' a_expr
15983 : 57 : { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "|", $1, $3, @2); }
15984 : :
15985 : : | a_expr qual_Op a_expr %prec Op
15986 : 36696 : { $$ = (Node *) makeA_Expr(AEXPR_OP, $2, $1, $3, @2); }
15987 : : | qual_Op a_expr %prec Op
15988 : 157 : { $$ = (Node *) makeA_Expr(AEXPR_OP, $1, NULL, $2, @1); }
15989 : :
15990 : : | a_expr AND a_expr
15991 : 156276 : { $$ = makeAndExpr($1, $3, @2); }
15992 : : | a_expr OR a_expr
15993 : 14549 : { $$ = makeOrExpr($1, $3, @2); }
15994 : : | NOT a_expr
15995 : 17593 : { $$ = makeNotExpr($2, @1); }
15996 : : | NOT_LA a_expr %prec NOT
15997 : 0 : { $$ = makeNotExpr($2, @1); }
15998 : :
15999 : : | a_expr LIKE a_expr
16000 : : {
16001 : 1333 : $$ = (Node *) makeSimpleA_Expr(AEXPR_LIKE, "~~",
16002 : 1333 : $1, $3, @2);
16003 : : }
16004 : : | a_expr LIKE a_expr ESCAPE a_expr %prec LIKE
16005 : : {
16006 : 80 : FuncCall *n = makeFuncCall(SystemFuncName("like_escape"),
16007 : 80 : list_make2($3, $5),
16008 : : COERCE_EXPLICIT_CALL,
16009 : 80 : @2);
16010 : 80 : $$ = (Node *) makeSimpleA_Expr(AEXPR_LIKE, "~~",
16011 : 80 : $1, (Node *) n, @2);
16012 : : }
16013 : : | a_expr NOT_LA LIKE a_expr %prec NOT_LA
16014 : : {
16015 : 128 : $$ = (Node *) makeSimpleA_Expr(AEXPR_LIKE, "!~~",
16016 : 128 : $1, $4, @2);
16017 : : }
16018 : : | a_expr NOT_LA LIKE a_expr ESCAPE a_expr %prec NOT_LA
16019 : : {
16020 : 64 : FuncCall *n = makeFuncCall(SystemFuncName("like_escape"),
16021 : 64 : list_make2($4, $6),
16022 : : COERCE_EXPLICIT_CALL,
16023 : 64 : @2);
16024 : 64 : $$ = (Node *) makeSimpleA_Expr(AEXPR_LIKE, "!~~",
16025 : 64 : $1, (Node *) n, @2);
16026 : : }
16027 : : | a_expr ILIKE a_expr
16028 : : {
16029 : 116 : $$ = (Node *) makeSimpleA_Expr(AEXPR_ILIKE, "~~*",
16030 : 116 : $1, $3, @2);
16031 : : }
16032 : : | a_expr ILIKE a_expr ESCAPE a_expr %prec ILIKE
16033 : : {
16034 : 0 : FuncCall *n = makeFuncCall(SystemFuncName("like_escape"),
16035 : 0 : list_make2($3, $5),
16036 : : COERCE_EXPLICIT_CALL,
16037 : 0 : @2);
16038 : 0 : $$ = (Node *) makeSimpleA_Expr(AEXPR_ILIKE, "~~*",
16039 : 0 : $1, (Node *) n, @2);
16040 : : }
16041 : : | a_expr NOT_LA ILIKE a_expr %prec NOT_LA
16042 : : {
16043 : 20 : $$ = (Node *) makeSimpleA_Expr(AEXPR_ILIKE, "!~~*",
16044 : 20 : $1, $4, @2);
16045 : : }
16046 : : | a_expr NOT_LA ILIKE a_expr ESCAPE a_expr %prec NOT_LA
16047 : : {
16048 : 0 : FuncCall *n = makeFuncCall(SystemFuncName("like_escape"),
16049 : 0 : list_make2($4, $6),
16050 : : COERCE_EXPLICIT_CALL,
16051 : 0 : @2);
16052 : 0 : $$ = (Node *) makeSimpleA_Expr(AEXPR_ILIKE, "!~~*",
16053 : 0 : $1, (Node *) n, @2);
16054 : : }
16055 : :
16056 : : | a_expr SIMILAR TO a_expr %prec SIMILAR
16057 : : {
16058 : 58 : FuncCall *n = makeFuncCall(SystemFuncName("similar_to_escape"),
16059 : 58 : list_make1($4),
16060 : : COERCE_EXPLICIT_CALL,
16061 : 58 : @2);
16062 : 58 : $$ = (Node *) makeSimpleA_Expr(AEXPR_SIMILAR, "~",
16063 : 58 : $1, (Node *) n, @2);
16064 : : }
16065 : : | a_expr SIMILAR TO a_expr ESCAPE a_expr %prec SIMILAR
16066 : : {
16067 : 24 : FuncCall *n = makeFuncCall(SystemFuncName("similar_to_escape"),
16068 : 24 : list_make2($4, $6),
16069 : : COERCE_EXPLICIT_CALL,
16070 : 24 : @2);
16071 : 24 : $$ = (Node *) makeSimpleA_Expr(AEXPR_SIMILAR, "~",
16072 : 24 : $1, (Node *) n, @2);
16073 : : }
16074 : : | a_expr NOT_LA SIMILAR TO a_expr %prec NOT_LA
16075 : : {
16076 : 0 : FuncCall *n = makeFuncCall(SystemFuncName("similar_to_escape"),
16077 : 0 : list_make1($5),
16078 : : COERCE_EXPLICIT_CALL,
16079 : 0 : @2);
16080 : 0 : $$ = (Node *) makeSimpleA_Expr(AEXPR_SIMILAR, "!~",
16081 : 0 : $1, (Node *) n, @2);
16082 : : }
16083 : : | a_expr NOT_LA SIMILAR TO a_expr ESCAPE a_expr %prec NOT_LA
16084 : : {
16085 : 0 : FuncCall *n = makeFuncCall(SystemFuncName("similar_to_escape"),
16086 : 0 : list_make2($5, $7),
16087 : : COERCE_EXPLICIT_CALL,
16088 : 0 : @2);
16089 : 0 : $$ = (Node *) makeSimpleA_Expr(AEXPR_SIMILAR, "!~",
16090 : 0 : $1, (Node *) n, @2);
16091 : : }
16092 : :
16093 : : /* NullTest clause
16094 : : * Define SQL-style Null test clause.
16095 : : * Allow two forms described in the standard:
16096 : : * a IS NULL
16097 : : * a IS NOT NULL
16098 : : * Allow two SQL extensions
16099 : : * a ISNULL
16100 : : * a NOTNULL
16101 : : */
16102 : : | a_expr IS NULL_P %prec IS
16103 : : {
16104 : 3653 : NullTest *n = makeNode(NullTest);
16105 : :
16106 : 3653 : n->arg = (Expr *) $1;
16107 : 3653 : n->nulltesttype = IS_NULL;
16108 : 3653 : n->location = @2;
16109 : 3653 : $$ = (Node *) n;
16110 : : }
16111 : : | a_expr ISNULL
16112 : : {
16113 : 68 : NullTest *n = makeNode(NullTest);
16114 : :
16115 : 68 : n->arg = (Expr *) $1;
16116 : 68 : n->nulltesttype = IS_NULL;
16117 : 68 : n->location = @2;
16118 : 68 : $$ = (Node *) n;
16119 : : }
16120 : : | a_expr IS NOT NULL_P %prec IS
16121 : : {
16122 : 8217 : NullTest *n = makeNode(NullTest);
16123 : :
16124 : 8217 : n->arg = (Expr *) $1;
16125 : 8217 : n->nulltesttype = IS_NOT_NULL;
16126 : 8217 : n->location = @2;
16127 : 8217 : $$ = (Node *) n;
16128 : : }
16129 : : | a_expr NOTNULL
16130 : : {
16131 : 4 : NullTest *n = makeNode(NullTest);
16132 : :
16133 : 4 : n->arg = (Expr *) $1;
16134 : 4 : n->nulltesttype = IS_NOT_NULL;
16135 : 4 : n->location = @2;
16136 : 4 : $$ = (Node *) n;
16137 : : }
16138 : : | row OVERLAPS row
16139 : : {
16140 [ - + ]: 563 : if (list_length($1) != 2)
16141 [ # # ]: 0 : ereport(ERROR,
16142 : : (errcode(ERRCODE_SYNTAX_ERROR),
16143 : : errmsg("wrong number of parameters on left side of OVERLAPS expression"),
16144 : : parser_errposition(@1)));
16145 [ - + ]: 563 : if (list_length($3) != 2)
16146 [ # # ]: 0 : ereport(ERROR,
16147 : : (errcode(ERRCODE_SYNTAX_ERROR),
16148 : : errmsg("wrong number of parameters on right side of OVERLAPS expression"),
16149 : : parser_errposition(@3)));
16150 : 563 : $$ = (Node *) makeFuncCall(SystemFuncName("overlaps"),
16151 : 563 : list_concat($1, $3),
16152 : : COERCE_SQL_SYNTAX,
16153 : 563 : @2);
16154 : : }
16155 : : | a_expr IS TRUE_P %prec IS
16156 : : {
16157 : 261 : BooleanTest *b = makeNode(BooleanTest);
16158 : :
16159 : 261 : b->arg = (Expr *) $1;
16160 : 261 : b->booltesttype = IS_TRUE;
16161 : 261 : b->location = @2;
16162 : 261 : $$ = (Node *) b;
16163 : : }
16164 : : | a_expr IS NOT TRUE_P %prec IS
16165 : : {
16166 : 100 : BooleanTest *b = makeNode(BooleanTest);
16167 : :
16168 : 100 : b->arg = (Expr *) $1;
16169 : 100 : b->booltesttype = IS_NOT_TRUE;
16170 : 100 : b->location = @2;
16171 : 100 : $$ = (Node *) b;
16172 : : }
16173 : : | a_expr IS FALSE_P %prec IS
16174 : : {
16175 : 148 : BooleanTest *b = makeNode(BooleanTest);
16176 : :
16177 : 148 : b->arg = (Expr *) $1;
16178 : 148 : b->booltesttype = IS_FALSE;
16179 : 148 : b->location = @2;
16180 : 148 : $$ = (Node *) b;
16181 : : }
16182 : : | a_expr IS NOT FALSE_P %prec IS
16183 : : {
16184 : 70 : BooleanTest *b = makeNode(BooleanTest);
16185 : :
16186 : 70 : b->arg = (Expr *) $1;
16187 : 70 : b->booltesttype = IS_NOT_FALSE;
16188 : 70 : b->location = @2;
16189 : 70 : $$ = (Node *) b;
16190 : : }
16191 : : | a_expr IS UNKNOWN %prec IS
16192 : : {
16193 : 50 : BooleanTest *b = makeNode(BooleanTest);
16194 : :
16195 : 50 : b->arg = (Expr *) $1;
16196 : 50 : b->booltesttype = IS_UNKNOWN;
16197 : 50 : b->location = @2;
16198 : 50 : $$ = (Node *) b;
16199 : : }
16200 : : | a_expr IS NOT UNKNOWN %prec IS
16201 : : {
16202 : 40 : BooleanTest *b = makeNode(BooleanTest);
16203 : :
16204 : 40 : b->arg = (Expr *) $1;
16205 : 40 : b->booltesttype = IS_NOT_UNKNOWN;
16206 : 40 : b->location = @2;
16207 : 40 : $$ = (Node *) b;
16208 : : }
16209 : : | a_expr IS DISTINCT FROM a_expr %prec IS
16210 : : {
16211 : 650 : $$ = (Node *) makeSimpleA_Expr(AEXPR_DISTINCT, "=", $1, $5, @2);
16212 : : }
16213 : : | a_expr IS NOT DISTINCT FROM a_expr %prec IS
16214 : : {
16215 : 84 : $$ = (Node *) makeSimpleA_Expr(AEXPR_NOT_DISTINCT, "=", $1, $6, @2);
16216 : : }
16217 : : | a_expr BETWEEN opt_asymmetric b_expr AND a_expr %prec BETWEEN
16218 : : {
16219 : 310 : $$ = (Node *) makeSimpleA_Expr(AEXPR_BETWEEN,
16220 : : "BETWEEN",
16221 : 310 : $1,
16222 : 310 : (Node *) list_make2($4, $6),
16223 : 310 : @2);
16224 : : }
16225 : : | a_expr NOT_LA BETWEEN opt_asymmetric b_expr AND a_expr %prec NOT_LA
16226 : : {
16227 : 8 : $$ = (Node *) makeSimpleA_Expr(AEXPR_NOT_BETWEEN,
16228 : : "NOT BETWEEN",
16229 : 8 : $1,
16230 : 8 : (Node *) list_make2($5, $7),
16231 : 8 : @2);
16232 : : }
16233 : : | a_expr BETWEEN SYMMETRIC b_expr AND a_expr %prec BETWEEN
16234 : : {
16235 : 8 : $$ = (Node *) makeSimpleA_Expr(AEXPR_BETWEEN_SYM,
16236 : : "BETWEEN SYMMETRIC",
16237 : 8 : $1,
16238 : 8 : (Node *) list_make2($4, $6),
16239 : 8 : @2);
16240 : : }
16241 : : | a_expr NOT_LA BETWEEN SYMMETRIC b_expr AND a_expr %prec NOT_LA
16242 : : {
16243 : 8 : $$ = (Node *) makeSimpleA_Expr(AEXPR_NOT_BETWEEN_SYM,
16244 : : "NOT BETWEEN SYMMETRIC",
16245 : 8 : $1,
16246 : 8 : (Node *) list_make2($5, $7),
16247 : 8 : @2);
16248 : : }
16249 : : | a_expr IN_P select_with_parens
16250 : : {
16251 : : /* generate foo = ANY (subquery) */
16252 : 3661 : SubLink *n = makeNode(SubLink);
16253 : :
16254 : 3661 : n->subselect = $3;
16255 : 3661 : n->subLinkType = ANY_SUBLINK;
16256 : 3661 : n->subLinkId = 0;
16257 : 3661 : n->testexpr = $1;
16258 : 3661 : n->operName = NIL; /* show it's IN not = ANY */
16259 : 3661 : n->location = @2;
16260 : 3661 : $$ = (Node *) n;
16261 : : }
16262 : : | a_expr IN_P '(' expr_list ')'
16263 : : {
16264 : : /* generate scalar IN expression */
16265 : 10683 : A_Expr *n = makeSimpleA_Expr(AEXPR_IN, "=", $1, (Node *) $4, @2);
16266 : :
16267 : 10683 : n->rexpr_list_start = @3;
16268 : 10683 : n->rexpr_list_end = @5;
16269 : 10683 : $$ = (Node *) n;
16270 : : }
16271 : : | a_expr NOT_LA IN_P select_with_parens %prec NOT_LA
16272 : : {
16273 : : /* generate NOT (foo = ANY (subquery)) */
16274 : 176 : SubLink *n = makeNode(SubLink);
16275 : :
16276 : 176 : n->subselect = $4;
16277 : 176 : n->subLinkType = ANY_SUBLINK;
16278 : 176 : n->subLinkId = 0;
16279 : 176 : n->testexpr = $1;
16280 : 176 : n->operName = NIL; /* show it's IN not = ANY */
16281 : 176 : n->location = @2;
16282 : : /* Stick a NOT on top; must have same parse location */
16283 : 176 : $$ = makeNotExpr((Node *) n, @2);
16284 : : }
16285 : : | a_expr NOT_LA IN_P '(' expr_list ')'
16286 : : {
16287 : : /* generate scalar NOT IN expression */
16288 : 1660 : A_Expr *n = makeSimpleA_Expr(AEXPR_IN, "<>", $1, (Node *) $5, @2);
16289 : :
16290 : 1660 : n->rexpr_list_start = @4;
16291 : 1660 : n->rexpr_list_end = @6;
16292 : 1660 : $$ = (Node *) n;
16293 : : }
16294 : : | a_expr subquery_Op sub_type select_with_parens %prec Op
16295 : : {
16296 : 124 : SubLink *n = makeNode(SubLink);
16297 : :
16298 : 124 : n->subLinkType = $3;
16299 : 124 : n->subLinkId = 0;
16300 : 124 : n->testexpr = $1;
16301 : 124 : n->operName = $2;
16302 : 124 : n->subselect = $4;
16303 : 124 : n->location = @2;
16304 : 124 : $$ = (Node *) n;
16305 : : }
16306 : : | a_expr subquery_Op sub_type '(' a_expr ')' %prec Op
16307 : : {
16308 [ + + ]: 11178 : if ($3 == ANY_SUBLINK)
16309 : 10973 : $$ = (Node *) makeA_Expr(AEXPR_OP_ANY, $2, $1, $5, @2);
16310 : : else
16311 : 205 : $$ = (Node *) makeA_Expr(AEXPR_OP_ALL, $2, $1, $5, @2);
16312 : : }
16313 : : | UNIQUE opt_unique_null_treatment select_with_parens
16314 : : {
16315 : : /* Not sure how to get rid of the parentheses
16316 : : * but there are lots of shift/reduce errors without them.
16317 : : *
16318 : : * Should be able to implement this by plopping the entire
16319 : : * select into a node, then transforming the target expressions
16320 : : * from whatever they are into count(*), and testing the
16321 : : * entire result equal to one.
16322 : : * But, will probably implement a separate node in the executor.
16323 : : */
16324 [ # # ]: 0 : ereport(ERROR,
16325 : : (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
16326 : : errmsg("UNIQUE predicate is not yet implemented"),
16327 : : parser_errposition(@1)));
16328 : : }
16329 : : | a_expr IS DOCUMENT_P %prec IS
16330 : : {
16331 : 12 : $$ = makeXmlExpr(IS_DOCUMENT, NULL, NIL,
16332 : 12 : list_make1($1), @2);
16333 : : }
16334 : : | a_expr IS NOT DOCUMENT_P %prec IS
16335 : : {
16336 : 12 : $$ = makeNotExpr(makeXmlExpr(IS_DOCUMENT, NULL, NIL,
16337 : 12 : list_make1($1), @2),
16338 : 12 : @2);
16339 : : }
16340 : : | a_expr IS NORMALIZED %prec IS
16341 : : {
16342 : 8 : $$ = (Node *) makeFuncCall(SystemFuncName("is_normalized"),
16343 : 8 : list_make1($1),
16344 : : COERCE_SQL_SYNTAX,
16345 : 8 : @2);
16346 : : }
16347 : : | a_expr IS unicode_normal_form NORMALIZED %prec IS
16348 : : {
16349 : 48 : $$ = (Node *) makeFuncCall(SystemFuncName("is_normalized"),
16350 : 24 : list_make2($1, makeStringConst($3, @3)),
16351 : : COERCE_SQL_SYNTAX,
16352 : 24 : @2);
16353 : : }
16354 : : | a_expr IS NOT NORMALIZED %prec IS
16355 : : {
16356 : 0 : $$ = makeNotExpr((Node *) makeFuncCall(SystemFuncName("is_normalized"),
16357 : 0 : list_make1($1),
16358 : : COERCE_SQL_SYNTAX,
16359 : 0 : @2),
16360 : 0 : @2);
16361 : : }
16362 : : | a_expr IS NOT unicode_normal_form NORMALIZED %prec IS
16363 : : {
16364 : 0 : $$ = makeNotExpr((Node *) makeFuncCall(SystemFuncName("is_normalized"),
16365 : 0 : list_make2($1, makeStringConst($4, @4)),
16366 : : COERCE_SQL_SYNTAX,
16367 : 0 : @2),
16368 : 0 : @2);
16369 : : }
16370 : : | a_expr IS json_predicate_type_constraint
16371 : : json_key_uniqueness_constraint_opt %prec IS
16372 : : {
16373 : 246 : JsonFormat *format = makeJsonFormat(JS_FORMAT_DEFAULT, JS_ENC_DEFAULT, -1);
16374 : :
16375 : 246 : $$ = makeJsonIsPredicate($1, format, $3, $4, InvalidOid, @1);
16376 : : }
16377 : : /*
16378 : : * Required by SQL/JSON, but there are conflicts
16379 : : | a_expr
16380 : : json_format_clause
16381 : : IS json_predicate_type_constraint
16382 : : json_key_uniqueness_constraint_opt %prec IS
16383 : : {
16384 : : $$ = makeJsonIsPredicate($1, $2, $4, $5, InvalidOid, @1);
16385 : : }
16386 : : */
16387 : : | a_expr IS NOT
16388 : : json_predicate_type_constraint
16389 : : json_key_uniqueness_constraint_opt %prec IS
16390 : : {
16391 : 34 : JsonFormat *format = makeJsonFormat(JS_FORMAT_DEFAULT, JS_ENC_DEFAULT, -1);
16392 : :
16393 : 34 : $$ = makeNotExpr(makeJsonIsPredicate($1, format, $4, $5, InvalidOid, @1), @1);
16394 : : }
16395 : : /*
16396 : : * Required by SQL/JSON, but there are conflicts
16397 : : | a_expr
16398 : : json_format_clause
16399 : : IS NOT
16400 : : json_predicate_type_constraint
16401 : : json_key_uniqueness_constraint_opt %prec IS
16402 : : {
16403 : : $$ = makeNotExpr(makeJsonIsPredicate($1, $2, $5, $6, InvalidOid, @1), @1);
16404 : : }
16405 : : */
16406 : : | DEFAULT
16407 : : {
16408 : : /*
16409 : : * The SQL spec only allows DEFAULT in "contextually typed
16410 : : * expressions", but for us, it's easier to allow it in
16411 : : * any a_expr and then throw error during parse analysis
16412 : : * if it's in an inappropriate context. This way also
16413 : : * lets us say something smarter than "syntax error".
16414 : : */
16415 : 1058 : SetToDefault *n = makeNode(SetToDefault);
16416 : :
16417 : : /* parse analysis will fill in the rest */
16418 : 1058 : n->location = @1;
16419 : 1058 : $$ = (Node *) n;
16420 : : }
16421 : : ;
16422 : :
16423 : : /*
16424 : : * Restricted expressions
16425 : : *
16426 : : * b_expr is a subset of the complete expression syntax defined by a_expr.
16427 : : *
16428 : : * Presently, AND, NOT, IS, and IN are the a_expr keywords that would
16429 : : * cause trouble in the places where b_expr is used. For simplicity, we
16430 : : * just eliminate all the boolean-keyword-operator productions from b_expr.
16431 : : */
16432 : : b_expr: c_expr
16433 : 2543 : { $$ = $1; }
16434 : : | b_expr TYPECAST Typename
16435 : 154 : { $$ = makeTypeCast($1, $3, @2); }
16436 : : | '+' b_expr %prec UMINUS
16437 : 0 : { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "+", NULL, $2, @1); }
16438 : : | '-' b_expr %prec UMINUS
16439 : 44 : { $$ = doNegate($2, @1); }
16440 : : | b_expr '+' b_expr
16441 : 24 : { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "+", $1, $3, @2); }
16442 : : | b_expr '-' b_expr
16443 : 10 : { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "-", $1, $3, @2); }
16444 : : | b_expr '*' b_expr
16445 : 8 : { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "*", $1, $3, @2); }
16446 : : | b_expr '/' b_expr
16447 : 0 : { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "/", $1, $3, @2); }
16448 : : | b_expr '%' b_expr
16449 : 0 : { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "%", $1, $3, @2); }
16450 : : | b_expr '^' b_expr
16451 : 4 : { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "^", $1, $3, @2); }
16452 : : | b_expr '<' b_expr
16453 : 0 : { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "<", $1, $3, @2); }
16454 : : | b_expr '>' b_expr
16455 : 0 : { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, ">", $1, $3, @2); }
16456 : : | b_expr '=' b_expr
16457 : 0 : { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "=", $1, $3, @2); }
16458 : : | b_expr LESS_EQUALS b_expr
16459 : 0 : { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "<=", $1, $3, @2); }
16460 : : | b_expr GREATER_EQUALS b_expr
16461 : 0 : { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, ">=", $1, $3, @2); }
16462 : : | b_expr NOT_EQUALS b_expr
16463 : 0 : { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "<>", $1, $3, @2); }
16464 : : | RIGHT_ARROW b_expr
16465 : 0 : { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "->", NULL, $2, @1); }
16466 : : | '|' b_expr
16467 : 0 : { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "|", NULL, $2, @1); }
16468 : : | b_expr RIGHT_ARROW b_expr
16469 : 0 : { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "->", $1, $3, @2); }
16470 : : | b_expr '|' b_expr
16471 : 0 : { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "|", $1, $3, @2); }
16472 : : | b_expr qual_Op b_expr %prec Op
16473 : 8 : { $$ = (Node *) makeA_Expr(AEXPR_OP, $2, $1, $3, @2); }
16474 : : | qual_Op b_expr %prec Op
16475 : 0 : { $$ = (Node *) makeA_Expr(AEXPR_OP, $1, NULL, $2, @1); }
16476 : : | b_expr IS DISTINCT FROM b_expr %prec IS
16477 : : {
16478 : 0 : $$ = (Node *) makeSimpleA_Expr(AEXPR_DISTINCT, "=", $1, $5, @2);
16479 : : }
16480 : : | b_expr IS NOT DISTINCT FROM b_expr %prec IS
16481 : : {
16482 : 0 : $$ = (Node *) makeSimpleA_Expr(AEXPR_NOT_DISTINCT, "=", $1, $6, @2);
16483 : : }
16484 : : | b_expr IS DOCUMENT_P %prec IS
16485 : : {
16486 : 0 : $$ = makeXmlExpr(IS_DOCUMENT, NULL, NIL,
16487 : 0 : list_make1($1), @2);
16488 : : }
16489 : : | b_expr IS NOT DOCUMENT_P %prec IS
16490 : : {
16491 : 0 : $$ = makeNotExpr(makeXmlExpr(IS_DOCUMENT, NULL, NIL,
16492 : 0 : list_make1($1), @2),
16493 : 0 : @2);
16494 : : }
16495 : : ;
16496 : :
16497 : : /*
16498 : : * Productions that can be used in both a_expr and b_expr.
16499 : : *
16500 : : * Note: productions that refer recursively to a_expr or b_expr mostly
16501 : : * cannot appear here. However, it's OK to refer to a_exprs that occur
16502 : : * inside parentheses, such as function arguments; that cannot introduce
16503 : : * ambiguity to the b_expr syntax.
16504 : : */
16505 : 1174195 : c_expr: columnref { $$ = $1; }
16506 : 827479 : | AexprConst { $$ = $1; }
16507 : : | PARAM opt_indirection
16508 : : {
16509 : 26541 : ParamRef *p = makeNode(ParamRef);
16510 : :
16511 : 26541 : p->number = $1;
16512 : 26541 : p->location = @1;
16513 [ + + ]: 26541 : if ($2)
16514 : : {
16515 : 705 : A_Indirection *n = makeNode(A_Indirection);
16516 : :
16517 : 705 : n->arg = (Node *) p;
16518 : 705 : n->indirection = check_indirection($2, yyscanner);
16519 : 705 : $$ = (Node *) n;
16520 : : }
16521 : : else
16522 : 25836 : $$ = (Node *) p;
16523 : : }
16524 : : | '(' a_expr ')' opt_indirection
16525 : : {
16526 [ + + ]: 60955 : if ($4)
16527 : : {
16528 : 9261 : A_Indirection *n = makeNode(A_Indirection);
16529 : :
16530 : 9261 : n->arg = $2;
16531 : 9261 : n->indirection = check_indirection($4, yyscanner);
16532 : 9261 : $$ = (Node *) n;
16533 : : }
16534 : : else
16535 : 51694 : $$ = $2;
16536 : : }
16537 : : | case_expr
16538 : 25694 : { $$ = $1; }
16539 : : | func_expr
16540 : 260189 : { $$ = $1; }
16541 : : | select_with_parens %prec UMINUS
16542 : : {
16543 : 16955 : SubLink *n = makeNode(SubLink);
16544 : :
16545 : 16955 : n->subLinkType = EXPR_SUBLINK;
16546 : 16955 : n->subLinkId = 0;
16547 : 16955 : n->testexpr = NULL;
16548 : 16955 : n->operName = NIL;
16549 : 16955 : n->subselect = $1;
16550 : 16955 : n->location = @1;
16551 : 16955 : $$ = (Node *) n;
16552 : : }
16553 : : | select_with_parens indirection
16554 : : {
16555 : : /*
16556 : : * Because the select_with_parens nonterminal is designed
16557 : : * to "eat" as many levels of parens as possible, the
16558 : : * '(' a_expr ')' opt_indirection production above will
16559 : : * fail to match a sub-SELECT with indirection decoration;
16560 : : * the sub-SELECT won't be regarded as an a_expr as long
16561 : : * as there are parens around it. To support applying
16562 : : * subscripting or field selection to a sub-SELECT result,
16563 : : * we need this redundant-looking production.
16564 : : */
16565 : 12 : SubLink *n = makeNode(SubLink);
16566 : 12 : A_Indirection *a = makeNode(A_Indirection);
16567 : :
16568 : 12 : n->subLinkType = EXPR_SUBLINK;
16569 : 12 : n->subLinkId = 0;
16570 : 12 : n->testexpr = NULL;
16571 : 12 : n->operName = NIL;
16572 : 12 : n->subselect = $1;
16573 : 12 : n->location = @1;
16574 : 12 : a->arg = (Node *) n;
16575 : 12 : a->indirection = check_indirection($2, yyscanner);
16576 : 12 : $$ = (Node *) a;
16577 : : }
16578 : : | EXISTS select_with_parens
16579 : : {
16580 : 8223 : SubLink *n = makeNode(SubLink);
16581 : :
16582 : 8223 : n->subLinkType = EXISTS_SUBLINK;
16583 : 8223 : n->subLinkId = 0;
16584 : 8223 : n->testexpr = NULL;
16585 : 8223 : n->operName = NIL;
16586 : 8223 : n->subselect = $2;
16587 : 8223 : n->location = @1;
16588 : 8223 : $$ = (Node *) n;
16589 : : }
16590 : : | ARRAY select_with_parens
16591 : : {
16592 : 5400 : SubLink *n = makeNode(SubLink);
16593 : :
16594 : 5400 : n->subLinkType = ARRAY_SUBLINK;
16595 : 5400 : n->subLinkId = 0;
16596 : 5400 : n->testexpr = NULL;
16597 : 5400 : n->operName = NIL;
16598 : 5400 : n->subselect = $2;
16599 : 5400 : n->location = @1;
16600 : 5400 : $$ = (Node *) n;
16601 : : }
16602 : : | ARRAY array_expr
16603 : : {
16604 : 5388 : A_ArrayExpr *n = castNode(A_ArrayExpr, $2);
16605 : :
16606 : : /* point outermost A_ArrayExpr to the ARRAY keyword */
16607 : 5388 : n->location = @1;
16608 : 5388 : $$ = (Node *) n;
16609 : : }
16610 : : | explicit_row
16611 : : {
16612 : 2663 : RowExpr *r = makeNode(RowExpr);
16613 : :
16614 : 2663 : r->args = $1;
16615 : 2663 : r->row_typeid = InvalidOid; /* not analyzed yet */
16616 : 2663 : r->colnames = NIL; /* to be filled in during analysis */
16617 : 2663 : r->row_format = COERCE_EXPLICIT_CALL; /* abuse */
16618 : 2663 : r->location = @1;
16619 : 2663 : $$ = (Node *) r;
16620 : : }
16621 : : | implicit_row
16622 : : {
16623 : 1848 : RowExpr *r = makeNode(RowExpr);
16624 : :
16625 : 1848 : r->args = $1;
16626 : 1848 : r->row_typeid = InvalidOid; /* not analyzed yet */
16627 : 1848 : r->colnames = NIL; /* to be filled in during analysis */
16628 : 1848 : r->row_format = COERCE_IMPLICIT_CAST; /* abuse */
16629 : 1848 : r->location = @1;
16630 : 1848 : $$ = (Node *) r;
16631 : : }
16632 : : | GROUPING '(' expr_list ')'
16633 : : {
16634 : 252 : GroupingFunc *g = makeNode(GroupingFunc);
16635 : :
16636 : 252 : g->args = $3;
16637 : 252 : g->location = @1;
16638 : 252 : $$ = (Node *) g;
16639 : : }
16640 : : ;
16641 : :
16642 : : func_application: func_name '(' ')'
16643 : : {
16644 : 20220 : $$ = (Node *) makeFuncCall($1, NIL,
16645 : : COERCE_EXPLICIT_CALL,
16646 : 20220 : @1);
16647 : : }
16648 : : | func_name '(' func_arg_list opt_sort_clause ')'
16649 : : {
16650 : 208125 : FuncCall *n = makeFuncCall($1, $3,
16651 : : COERCE_EXPLICIT_CALL,
16652 : 208125 : @1);
16653 : :
16654 : 208125 : n->agg_order = $4;
16655 : 208125 : $$ = (Node *) n;
16656 : : }
16657 : : | func_name '(' VARIADIC func_arg_expr opt_sort_clause ')'
16658 : : {
16659 : 377 : FuncCall *n = makeFuncCall($1, list_make1($4),
16660 : : COERCE_EXPLICIT_CALL,
16661 : 377 : @1);
16662 : :
16663 : 377 : n->func_variadic = true;
16664 : 377 : n->agg_order = $5;
16665 : 377 : $$ = (Node *) n;
16666 : : }
16667 : : | func_name '(' func_arg_list ',' VARIADIC func_arg_expr opt_sort_clause ')'
16668 : : {
16669 : 116 : FuncCall *n = makeFuncCall($1, lappend($3, $6),
16670 : : COERCE_EXPLICIT_CALL,
16671 : 116 : @1);
16672 : :
16673 : 116 : n->func_variadic = true;
16674 : 116 : n->agg_order = $7;
16675 : 116 : $$ = (Node *) n;
16676 : : }
16677 : : | func_name '(' ALL func_arg_list opt_sort_clause ')'
16678 : : {
16679 : 0 : FuncCall *n = makeFuncCall($1, $4,
16680 : : COERCE_EXPLICIT_CALL,
16681 : 0 : @1);
16682 : :
16683 : 0 : n->agg_order = $5;
16684 : : /* Ideally we'd mark the FuncCall node to indicate
16685 : : * "must be an aggregate", but there's no provision
16686 : : * for that in FuncCall at the moment.
16687 : : */
16688 : 0 : $$ = (Node *) n;
16689 : : }
16690 : : | func_name '(' DISTINCT func_arg_list opt_sort_clause ')'
16691 : : {
16692 : 369 : FuncCall *n = makeFuncCall($1, $4,
16693 : : COERCE_EXPLICIT_CALL,
16694 : 369 : @1);
16695 : :
16696 : 369 : n->agg_order = $5;
16697 : 369 : n->agg_distinct = true;
16698 : 369 : $$ = (Node *) n;
16699 : : }
16700 : : | func_name '(' '*' ')'
16701 : : {
16702 : : /*
16703 : : * We consider AGGREGATE(*) to invoke a parameterless
16704 : : * aggregate. This does the right thing for COUNT(*),
16705 : : * and there are no other aggregates in SQL that accept
16706 : : * '*' as parameter.
16707 : : *
16708 : : * The FuncCall node is also marked agg_star = true,
16709 : : * so that later processing can detect what the argument
16710 : : * really was.
16711 : : */
16712 : 11558 : FuncCall *n = makeFuncCall($1, NIL,
16713 : : COERCE_EXPLICIT_CALL,
16714 : 11558 : @1);
16715 : :
16716 : 11558 : n->agg_star = true;
16717 : 11558 : $$ = (Node *) n;
16718 : : }
16719 : : ;
16720 : :
16721 : :
16722 : : /*
16723 : : * func_expr and its cousin func_expr_windowless are split out from c_expr just
16724 : : * so that we have classifications for "everything that is a function call or
16725 : : * looks like one". This isn't very important, but it saves us having to
16726 : : * document which variants are legal in places like "FROM function()" or the
16727 : : * backwards-compatible functional-index syntax for CREATE INDEX.
16728 : : * (Note that many of the special SQL functions wouldn't actually make any
16729 : : * sense as functional index entries, but we ignore that consideration here.)
16730 : : */
16731 : : func_expr: func_application within_group_clause filter_clause null_treatment over_clause
16732 : : {
16733 : 210158 : FuncCall *n = (FuncCall *) $1;
16734 : :
16735 : : /*
16736 : : * The order clause for WITHIN GROUP and the one for
16737 : : * plain-aggregate ORDER BY share a field, so we have to
16738 : : * check here that at most one is present. We also check
16739 : : * for DISTINCT and VARIADIC here to give a better error
16740 : : * location. Other consistency checks are deferred to
16741 : : * parse analysis.
16742 : : */
16743 [ + + ]: 210158 : if ($2 != NIL)
16744 : : {
16745 [ + + ]: 228 : if (n->agg_order != NIL)
16746 [ + - ]: 4 : ereport(ERROR,
16747 : : (errcode(ERRCODE_SYNTAX_ERROR),
16748 : : errmsg("cannot use multiple ORDER BY clauses with WITHIN GROUP"),
16749 : : parser_errposition(@2)));
16750 [ - + ]: 224 : if (n->agg_distinct)
16751 [ # # ]: 0 : ereport(ERROR,
16752 : : (errcode(ERRCODE_SYNTAX_ERROR),
16753 : : errmsg("cannot use DISTINCT with WITHIN GROUP"),
16754 : : parser_errposition(@2)));
16755 [ - + ]: 224 : if (n->func_variadic)
16756 [ # # ]: 0 : ereport(ERROR,
16757 : : (errcode(ERRCODE_SYNTAX_ERROR),
16758 : : errmsg("cannot use VARIADIC with WITHIN GROUP"),
16759 : : parser_errposition(@2)));
16760 : 224 : n->agg_order = $2;
16761 : 224 : n->agg_within_group = true;
16762 : : }
16763 : 210154 : n->agg_filter = $3;
16764 : 210154 : n->ignore_nulls = $4;
16765 : 210154 : n->over = $5;
16766 : 210154 : $$ = (Node *) n;
16767 : : }
16768 : : | json_aggregate_func filter_clause over_clause
16769 : : {
16770 : 584 : JsonAggConstructor *n = IsA($1, JsonObjectAgg) ?
16771 [ + + ]: 292 : ((JsonObjectAgg *) $1)->constructor :
16772 : 140 : ((JsonArrayAgg *) $1)->constructor;
16773 : :
16774 : 292 : n->agg_filter = $2;
16775 : 292 : n->over = $3;
16776 : 292 : $$ = (Node *) $1;
16777 : : }
16778 : : | func_expr_common_subexpr
16779 : 49743 : { $$ = $1; }
16780 : : ;
16781 : :
16782 : : /*
16783 : : * Like func_expr but does not accept WINDOW functions directly
16784 : : * (but they can still be contained in arguments for functions etc).
16785 : : * Use this when window expressions are not allowed, where needed to
16786 : : * disambiguate the grammar (e.g. in CREATE INDEX).
16787 : : */
16788 : : func_expr_windowless:
16789 : 30241 : func_application { $$ = $1; }
16790 : 396 : | func_expr_common_subexpr { $$ = $1; }
16791 : 16 : | json_aggregate_func { $$ = $1; }
16792 : : ;
16793 : :
16794 : : /*
16795 : : * Special expressions that are considered to be functions.
16796 : : */
16797 : : func_expr_common_subexpr:
16798 : : COLLATION FOR '(' a_expr ')'
16799 : : {
16800 : 20 : $$ = (Node *) makeFuncCall(SystemFuncName("pg_collation_for"),
16801 : 20 : list_make1($4),
16802 : : COERCE_SQL_SYNTAX,
16803 : 20 : @1);
16804 : : }
16805 : : | CURRENT_DATE
16806 : : {
16807 : 211 : $$ = makeSQLValueFunction(SVFOP_CURRENT_DATE, -1, @1);
16808 : : }
16809 : : | CURRENT_TIME
16810 : : {
16811 : 16 : $$ = makeSQLValueFunction(SVFOP_CURRENT_TIME, -1, @1);
16812 : : }
16813 : : | CURRENT_TIME '(' Iconst ')'
16814 : : {
16815 : 16 : $$ = makeSQLValueFunction(SVFOP_CURRENT_TIME_N, $3, @1);
16816 : : }
16817 : : | CURRENT_TIMESTAMP
16818 : : {
16819 : 153 : $$ = makeSQLValueFunction(SVFOP_CURRENT_TIMESTAMP, -1, @1);
16820 : : }
16821 : : | CURRENT_TIMESTAMP '(' Iconst ')'
16822 : : {
16823 : 107 : $$ = makeSQLValueFunction(SVFOP_CURRENT_TIMESTAMP_N, $3, @1);
16824 : : }
16825 : : | LOCALTIME
16826 : : {
16827 : 16 : $$ = makeSQLValueFunction(SVFOP_LOCALTIME, -1, @1);
16828 : : }
16829 : : | LOCALTIME '(' Iconst ')'
16830 : : {
16831 : 16 : $$ = makeSQLValueFunction(SVFOP_LOCALTIME_N, $3, @1);
16832 : : }
16833 : : | LOCALTIMESTAMP
16834 : : {
16835 : 24 : $$ = makeSQLValueFunction(SVFOP_LOCALTIMESTAMP, -1, @1);
16836 : : }
16837 : : | LOCALTIMESTAMP '(' Iconst ')'
16838 : : {
16839 : 16 : $$ = makeSQLValueFunction(SVFOP_LOCALTIMESTAMP_N, $3, @1);
16840 : : }
16841 : : | CURRENT_ROLE
16842 : : {
16843 : 44 : $$ = makeSQLValueFunction(SVFOP_CURRENT_ROLE, -1, @1);
16844 : : }
16845 : : | CURRENT_USER
16846 : : {
16847 : 678 : $$ = makeSQLValueFunction(SVFOP_CURRENT_USER, -1, @1);
16848 : : }
16849 : : | SESSION_USER
16850 : : {
16851 : 315 : $$ = makeSQLValueFunction(SVFOP_SESSION_USER, -1, @1);
16852 : : }
16853 : : | SYSTEM_USER
16854 : : {
16855 : 12 : $$ = (Node *) makeFuncCall(SystemFuncName("system_user"),
16856 : : NIL,
16857 : : COERCE_SQL_SYNTAX,
16858 : : @1);
16859 : : }
16860 : : | USER
16861 : : {
16862 : 16 : $$ = makeSQLValueFunction(SVFOP_USER, -1, @1);
16863 : : }
16864 : : | CURRENT_CATALOG
16865 : : {
16866 : 35 : $$ = makeSQLValueFunction(SVFOP_CURRENT_CATALOG, -1, @1);
16867 : : }
16868 : : | CURRENT_SCHEMA
16869 : : {
16870 : 20 : $$ = makeSQLValueFunction(SVFOP_CURRENT_SCHEMA, -1, @1);
16871 : : }
16872 : : | CAST '(' a_expr AS Typename ')'
16873 : 40318 : { $$ = makeTypeCast($3, $5, @1); }
16874 : : | EXTRACT '(' extract_list ')'
16875 : : {
16876 : 884 : $$ = (Node *) makeFuncCall(SystemFuncName("extract"),
16877 : 884 : $3,
16878 : : COERCE_SQL_SYNTAX,
16879 : 884 : @1);
16880 : : }
16881 : : | NORMALIZE '(' a_expr ')'
16882 : : {
16883 : 12 : $$ = (Node *) makeFuncCall(SystemFuncName("normalize"),
16884 : 12 : list_make1($3),
16885 : : COERCE_SQL_SYNTAX,
16886 : 12 : @1);
16887 : : }
16888 : : | NORMALIZE '(' a_expr ',' unicode_normal_form ')'
16889 : : {
16890 : 152 : $$ = (Node *) makeFuncCall(SystemFuncName("normalize"),
16891 : 76 : list_make2($3, makeStringConst($5, @5)),
16892 : : COERCE_SQL_SYNTAX,
16893 : 76 : @1);
16894 : : }
16895 : : | OVERLAY '(' overlay_list ')'
16896 : : {
16897 : 54 : $$ = (Node *) makeFuncCall(SystemFuncName("overlay"),
16898 : 54 : $3,
16899 : : COERCE_SQL_SYNTAX,
16900 : 54 : @1);
16901 : : }
16902 : : | OVERLAY '(' func_arg_list_opt ')'
16903 : : {
16904 : : /*
16905 : : * allow functions named overlay() to be called without
16906 : : * special syntax
16907 : : */
16908 : 0 : $$ = (Node *) makeFuncCall(list_make1(makeString("overlay")),
16909 : 0 : $3,
16910 : : COERCE_EXPLICIT_CALL,
16911 : 0 : @1);
16912 : : }
16913 : : | POSITION '(' position_list ')'
16914 : : {
16915 : : /*
16916 : : * position(A in B) is converted to position(B, A)
16917 : : *
16918 : : * We deliberately don't offer a "plain syntax" option
16919 : : * for position(), because the reversal of the arguments
16920 : : * creates too much risk of confusion.
16921 : : */
16922 : 277 : $$ = (Node *) makeFuncCall(SystemFuncName("position"),
16923 : 277 : $3,
16924 : : COERCE_SQL_SYNTAX,
16925 : 277 : @1);
16926 : : }
16927 : : | SUBSTRING '(' substr_list ')'
16928 : : {
16929 : : /* substring(A from B for C) is converted to
16930 : : * substring(A, B, C) - thomas 2000-11-28
16931 : : */
16932 : 467 : $$ = (Node *) makeFuncCall(SystemFuncName("substring"),
16933 : 467 : $3,
16934 : : COERCE_SQL_SYNTAX,
16935 : 467 : @1);
16936 : : }
16937 : : | SUBSTRING '(' func_arg_list_opt ')'
16938 : : {
16939 : : /*
16940 : : * allow functions named substring() to be called without
16941 : : * special syntax
16942 : : */
16943 : 198 : $$ = (Node *) makeFuncCall(list_make1(makeString("substring")),
16944 : 198 : $3,
16945 : : COERCE_EXPLICIT_CALL,
16946 : 198 : @1);
16947 : : }
16948 : : | TREAT '(' a_expr AS Typename ')'
16949 : : {
16950 : : /* TREAT(expr AS target) converts expr of a particular type to target,
16951 : : * which is defined to be a subtype of the original expression.
16952 : : * In SQL99, this is intended for use with structured UDTs,
16953 : : * but let's make this a generally useful form allowing stronger
16954 : : * coercions than are handled by implicit casting.
16955 : : *
16956 : : * Convert SystemTypeName() to SystemFuncName() even though
16957 : : * at the moment they result in the same thing.
16958 : : */
16959 : 0 : $$ = (Node *) makeFuncCall(SystemFuncName(strVal(llast($5->names))),
16960 : 0 : list_make1($3),
16961 : : COERCE_EXPLICIT_CALL,
16962 : 0 : @1);
16963 : : }
16964 : : | TRIM '(' BOTH trim_list ')'
16965 : : {
16966 : : /* various trim expressions are defined in SQL
16967 : : * - thomas 1997-07-19
16968 : : */
16969 : 8 : $$ = (Node *) makeFuncCall(SystemFuncName("btrim"),
16970 : 8 : $4,
16971 : : COERCE_SQL_SYNTAX,
16972 : 8 : @1);
16973 : : }
16974 : : | TRIM '(' LEADING trim_list ')'
16975 : : {
16976 : 16 : $$ = (Node *) makeFuncCall(SystemFuncName("ltrim"),
16977 : 16 : $4,
16978 : : COERCE_SQL_SYNTAX,
16979 : 16 : @1);
16980 : : }
16981 : : | TRIM '(' TRAILING trim_list ')'
16982 : : {
16983 : 378 : $$ = (Node *) makeFuncCall(SystemFuncName("rtrim"),
16984 : 378 : $4,
16985 : : COERCE_SQL_SYNTAX,
16986 : 378 : @1);
16987 : : }
16988 : : | TRIM '(' trim_list ')'
16989 : : {
16990 : 64 : $$ = (Node *) makeFuncCall(SystemFuncName("btrim"),
16991 : 64 : $3,
16992 : : COERCE_SQL_SYNTAX,
16993 : 64 : @1);
16994 : : }
16995 : : | NULLIF '(' a_expr ',' a_expr ')'
16996 : : {
16997 : 342 : $$ = (Node *) makeSimpleA_Expr(AEXPR_NULLIF, "=", $3, $5, @1);
16998 : : }
16999 : : | COALESCE '(' expr_list ')'
17000 : : {
17001 : 2183 : CoalesceExpr *c = makeNode(CoalesceExpr);
17002 : :
17003 : 2183 : c->args = $3;
17004 : 2183 : c->location = @1;
17005 : 2183 : $$ = (Node *) c;
17006 : : }
17007 : : | GREATEST '(' expr_list ')'
17008 : : {
17009 : 106 : MinMaxExpr *v = makeNode(MinMaxExpr);
17010 : :
17011 : 106 : v->args = $3;
17012 : 106 : v->op = IS_GREATEST;
17013 : 106 : v->location = @1;
17014 : 106 : $$ = (Node *) v;
17015 : : }
17016 : : | LEAST '(' expr_list ')'
17017 : : {
17018 : 100 : MinMaxExpr *v = makeNode(MinMaxExpr);
17019 : :
17020 : 100 : v->args = $3;
17021 : 100 : v->op = IS_LEAST;
17022 : 100 : v->location = @1;
17023 : 100 : $$ = (Node *) v;
17024 : : }
17025 : : | XMLCONCAT '(' expr_list ')'
17026 : : {
17027 : 41 : $$ = makeXmlExpr(IS_XMLCONCAT, NULL, NIL, $3, @1);
17028 : : }
17029 : : | XMLELEMENT '(' NAME_P ColLabel ')'
17030 : : {
17031 : 4 : $$ = makeXmlExpr(IS_XMLELEMENT, $4, NIL, NIL, @1);
17032 : : }
17033 : : | XMLELEMENT '(' NAME_P ColLabel ',' xml_attributes ')'
17034 : : {
17035 : 24 : $$ = makeXmlExpr(IS_XMLELEMENT, $4, $6, NIL, @1);
17036 : : }
17037 : : | XMLELEMENT '(' NAME_P ColLabel ',' expr_list ')'
17038 : : {
17039 : 77 : $$ = makeXmlExpr(IS_XMLELEMENT, $4, NIL, $6, @1);
17040 : : }
17041 : : | XMLELEMENT '(' NAME_P ColLabel ',' xml_attributes ',' expr_list ')'
17042 : : {
17043 : 13 : $$ = makeXmlExpr(IS_XMLELEMENT, $4, $6, $8, @1);
17044 : : }
17045 : : | XMLEXISTS '(' c_expr xmlexists_argument ')'
17046 : : {
17047 : : /* xmlexists(A PASSING [BY REF] B [BY REF]) is
17048 : : * converted to xmlexists(A, B)*/
17049 : 36 : $$ = (Node *) makeFuncCall(SystemFuncName("xmlexists"),
17050 : 36 : list_make2($3, $4),
17051 : : COERCE_SQL_SYNTAX,
17052 : 36 : @1);
17053 : : }
17054 : : | XMLFOREST '(' labeled_expr_list ')'
17055 : : {
17056 : 21 : $$ = makeXmlExpr(IS_XMLFOREST, NULL, $3, NIL, @1);
17057 : : }
17058 : : | XMLPARSE '(' document_or_content a_expr xml_whitespace_option ')'
17059 : : {
17060 : : XmlExpr *x = (XmlExpr *)
17061 : 186 : makeXmlExpr(IS_XMLPARSE, NULL, NIL,
17062 : 93 : list_make2($4, makeBoolAConst($5, -1)),
17063 : 93 : @1);
17064 : :
17065 : 93 : x->xmloption = $3;
17066 : 93 : $$ = (Node *) x;
17067 : : }
17068 : : | XMLPI '(' NAME_P ColLabel ')'
17069 : : {
17070 : 20 : $$ = makeXmlExpr(IS_XMLPI, $4, NULL, NIL, @1);
17071 : : }
17072 : : | XMLPI '(' NAME_P ColLabel ',' a_expr ')'
17073 : : {
17074 : 33 : $$ = makeXmlExpr(IS_XMLPI, $4, NULL, list_make1($6), @1);
17075 : : }
17076 : : | XMLROOT '(' a_expr ',' xml_root_version opt_xml_root_standalone ')'
17077 : : {
17078 : 45 : $$ = makeXmlExpr(IS_XMLROOT, NULL, NIL,
17079 : 45 : list_make3($3, $5, $6), @1);
17080 : : }
17081 : : | XMLSERIALIZE '(' document_or_content a_expr AS SimpleTypename xml_indent_option ')'
17082 : : {
17083 : 144 : XmlSerialize *n = makeNode(XmlSerialize);
17084 : :
17085 : 144 : n->xmloption = $3;
17086 : 144 : n->expr = $4;
17087 : 144 : n->typeName = $6;
17088 : 144 : n->indent = $7;
17089 : 144 : n->location = @1;
17090 : 144 : $$ = (Node *) n;
17091 : : }
17092 : : | JSON_OBJECT '(' func_arg_list ')'
17093 : : {
17094 : : /* Support for legacy (non-standard) json_object() */
17095 : 60 : $$ = (Node *) makeFuncCall(SystemFuncName("json_object"),
17096 : 60 : $3, COERCE_EXPLICIT_CALL, @1);
17097 : : }
17098 : : | JSON_OBJECT '(' json_name_and_value_list
17099 : : json_object_constructor_null_clause_opt
17100 : : json_key_uniqueness_constraint_opt
17101 : : json_returning_clause_opt ')'
17102 : : {
17103 : 318 : JsonObjectConstructor *n = makeNode(JsonObjectConstructor);
17104 : :
17105 : 318 : n->exprs = $3;
17106 : 318 : n->absent_on_null = $4;
17107 : 318 : n->unique = $5;
17108 : 318 : n->output = (JsonOutput *) $6;
17109 : 318 : n->location = @1;
17110 : 318 : $$ = (Node *) n;
17111 : : }
17112 : : | JSON_OBJECT '(' json_returning_clause_opt ')'
17113 : : {
17114 : 60 : JsonObjectConstructor *n = makeNode(JsonObjectConstructor);
17115 : :
17116 : 60 : n->exprs = NULL;
17117 : 60 : n->absent_on_null = false;
17118 : 60 : n->unique = false;
17119 : 60 : n->output = (JsonOutput *) $3;
17120 : 60 : n->location = @1;
17121 : 60 : $$ = (Node *) n;
17122 : : }
17123 : : | JSON_ARRAY '('
17124 : : json_value_expr_list
17125 : : json_array_constructor_null_clause_opt
17126 : : json_returning_clause_opt
17127 : : ')'
17128 : : {
17129 : 168 : JsonArrayConstructor *n = makeNode(JsonArrayConstructor);
17130 : :
17131 : 168 : n->exprs = $3;
17132 : 168 : n->absent_on_null = $4;
17133 : 168 : n->output = (JsonOutput *) $5;
17134 : 168 : n->location = @1;
17135 : 168 : $$ = (Node *) n;
17136 : : }
17137 : : | JSON_ARRAY '('
17138 : : select_no_parens
17139 : : json_format_clause_opt
17140 : : /* json_array_constructor_null_clause_opt */
17141 : : json_returning_clause_opt
17142 : : ')'
17143 : : {
17144 : 92 : JsonArrayQueryConstructor *n = makeNode(JsonArrayQueryConstructor);
17145 : :
17146 : 92 : n->query = $3;
17147 : 92 : n->format = (JsonFormat *) $4;
17148 : 92 : n->absent_on_null = true; /* XXX */
17149 : 92 : n->output = (JsonOutput *) $5;
17150 : 92 : n->location = @1;
17151 : 92 : $$ = (Node *) n;
17152 : : }
17153 : : | JSON_ARRAY '('
17154 : : json_returning_clause_opt
17155 : : ')'
17156 : : {
17157 : 56 : JsonArrayConstructor *n = makeNode(JsonArrayConstructor);
17158 : :
17159 : 56 : n->exprs = NIL;
17160 : 56 : n->absent_on_null = true;
17161 : 56 : n->output = (JsonOutput *) $3;
17162 : 56 : n->location = @1;
17163 : 56 : $$ = (Node *) n;
17164 : : }
17165 : : | JSON '(' json_value_expr json_key_uniqueness_constraint_opt ')'
17166 : : {
17167 : 108 : JsonParseExpr *n = makeNode(JsonParseExpr);
17168 : :
17169 : 108 : n->expr = (JsonValueExpr *) $3;
17170 : 108 : n->unique_keys = $4;
17171 : 108 : n->output = NULL;
17172 : 108 : n->location = @1;
17173 : 108 : $$ = (Node *) n;
17174 : : }
17175 : : | JSON_SCALAR '(' a_expr ')'
17176 : : {
17177 : 70 : JsonScalarExpr *n = makeNode(JsonScalarExpr);
17178 : :
17179 : 70 : n->expr = (Expr *) $3;
17180 : 70 : n->output = NULL;
17181 : 70 : n->location = @1;
17182 : 70 : $$ = (Node *) n;
17183 : : }
17184 : : | JSON_SERIALIZE '(' json_value_expr json_returning_clause_opt ')'
17185 : : {
17186 : 68 : JsonSerializeExpr *n = makeNode(JsonSerializeExpr);
17187 : :
17188 : 68 : n->expr = (JsonValueExpr *) $3;
17189 : 68 : n->output = (JsonOutput *) $4;
17190 : 68 : n->location = @1;
17191 : 68 : $$ = (Node *) n;
17192 : : }
17193 : : | MERGE_ACTION '(' ')'
17194 : : {
17195 : 146 : MergeSupportFunc *m = makeNode(MergeSupportFunc);
17196 : :
17197 : 146 : m->msftype = TEXTOID;
17198 : 146 : m->location = @1;
17199 : 146 : $$ = (Node *) m;
17200 : : }
17201 : : | JSON_QUERY '('
17202 : : json_value_expr ',' a_expr json_passing_clause_opt
17203 : : json_returning_clause_opt
17204 : : json_wrapper_behavior
17205 : : json_quotes_clause_opt
17206 : : json_behavior_clause_opt
17207 : : ')'
17208 : : {
17209 : 692 : JsonFuncExpr *n = makeNode(JsonFuncExpr);
17210 : :
17211 : 692 : n->op = JSON_QUERY_OP;
17212 : 692 : n->context_item = (JsonValueExpr *) $3;
17213 : 692 : n->pathspec = $5;
17214 : 692 : n->passing = $6;
17215 : 692 : n->output = (JsonOutput *) $7;
17216 : 692 : n->wrapper = $8;
17217 : 692 : n->quotes = $9;
17218 : 692 : n->on_empty = (JsonBehavior *) linitial($10);
17219 : 692 : n->on_error = (JsonBehavior *) lsecond($10);
17220 : 692 : n->location = @1;
17221 : 692 : $$ = (Node *) n;
17222 : : }
17223 : : | JSON_EXISTS '('
17224 : : json_value_expr ',' a_expr json_passing_clause_opt
17225 : : json_on_error_clause_opt
17226 : : ')'
17227 : : {
17228 : 112 : JsonFuncExpr *n = makeNode(JsonFuncExpr);
17229 : :
17230 : 112 : n->op = JSON_EXISTS_OP;
17231 : 112 : n->context_item = (JsonValueExpr *) $3;
17232 : 112 : n->pathspec = $5;
17233 : 112 : n->passing = $6;
17234 : 112 : n->output = NULL;
17235 : 112 : n->on_error = (JsonBehavior *) $7;
17236 : 112 : n->location = @1;
17237 : 112 : $$ = (Node *) n;
17238 : : }
17239 : : | JSON_VALUE '('
17240 : : json_value_expr ',' a_expr json_passing_clause_opt
17241 : : json_returning_clause_opt
17242 : : json_behavior_clause_opt
17243 : : ')'
17244 : : {
17245 : 440 : JsonFuncExpr *n = makeNode(JsonFuncExpr);
17246 : :
17247 : 440 : n->op = JSON_VALUE_OP;
17248 : 440 : n->context_item = (JsonValueExpr *) $3;
17249 : 440 : n->pathspec = $5;
17250 : 440 : n->passing = $6;
17251 : 440 : n->output = (JsonOutput *) $7;
17252 : 440 : n->on_empty = (JsonBehavior *) linitial($8);
17253 : 440 : n->on_error = (JsonBehavior *) lsecond($8);
17254 : 440 : n->location = @1;
17255 : 440 : $$ = (Node *) n;
17256 : : }
17257 : : ;
17258 : :
17259 : :
17260 : : /*
17261 : : * SQL/XML support
17262 : : */
17263 : : xml_root_version: VERSION_P a_expr
17264 : 16 : { $$ = $2; }
17265 : : | VERSION_P NO VALUE_P
17266 : 29 : { $$ = makeNullAConst(-1); }
17267 : : ;
17268 : :
17269 : : opt_xml_root_standalone: ',' STANDALONE_P YES_P
17270 : 17 : { $$ = makeIntConst(XML_STANDALONE_YES, -1); }
17271 : : | ',' STANDALONE_P NO
17272 : 8 : { $$ = makeIntConst(XML_STANDALONE_NO, -1); }
17273 : : | ',' STANDALONE_P NO VALUE_P
17274 : 8 : { $$ = makeIntConst(XML_STANDALONE_NO_VALUE, -1); }
17275 : : | /*EMPTY*/
17276 : 12 : { $$ = makeIntConst(XML_STANDALONE_OMITTED, -1); }
17277 : : ;
17278 : :
17279 : 37 : xml_attributes: XMLATTRIBUTES '(' labeled_expr_list ')' { $$ = $3; }
17280 : : ;
17281 : :
17282 : 903 : labeled_expr_list: labeled_expr { $$ = list_make1($1); }
17283 : 851 : | labeled_expr_list ',' labeled_expr { $$ = lappend($1, $3); }
17284 : : ;
17285 : :
17286 : : labeled_expr: a_expr AS ColLabel
17287 : : {
17288 : 1090 : $$ = makeNode(ResTarget);
17289 : 1090 : $$->name = $3;
17290 : 1090 : $$->indirection = NIL;
17291 : 1090 : $$->val = (Node *) $1;
17292 : 1090 : $$->location = @1;
17293 : : }
17294 : : | a_expr
17295 : : {
17296 : 664 : $$ = makeNode(ResTarget);
17297 : 664 : $$->name = NULL;
17298 : 664 : $$->indirection = NIL;
17299 : 664 : $$->val = (Node *) $1;
17300 : 664 : $$->location = @1;
17301 : : }
17302 : : ;
17303 : :
17304 : 123 : document_or_content: DOCUMENT_P { $$ = XMLOPTION_DOCUMENT; }
17305 : 124 : | CONTENT_P { $$ = XMLOPTION_CONTENT; }
17306 : : ;
17307 : :
17308 : 93 : xml_indent_option: INDENT { $$ = true; }
17309 : 23 : | NO INDENT { $$ = false; }
17310 : 28 : | /*EMPTY*/ { $$ = false; }
17311 : : ;
17312 : :
17313 : 0 : xml_whitespace_option: PRESERVE WHITESPACE_P { $$ = true; }
17314 : 1 : | STRIP_P WHITESPACE_P { $$ = false; }
17315 : 92 : | /*EMPTY*/ { $$ = false; }
17316 : : ;
17317 : :
17318 : : /* We allow several variants for SQL and other compatibility. */
17319 : : xmlexists_argument:
17320 : : PASSING c_expr
17321 : : {
17322 : 158 : $$ = $2;
17323 : : }
17324 : : | PASSING c_expr xml_passing_mech
17325 : : {
17326 : 0 : $$ = $2;
17327 : : }
17328 : : | PASSING xml_passing_mech c_expr
17329 : : {
17330 : 28 : $$ = $3;
17331 : : }
17332 : : | PASSING xml_passing_mech c_expr xml_passing_mech
17333 : : {
17334 : 4 : $$ = $3;
17335 : : }
17336 : : ;
17337 : :
17338 : : xml_passing_mech:
17339 : : BY REF_P
17340 : : | BY VALUE_P
17341 : : ;
17342 : :
17343 : : /*****************************************************************************
17344 : : *
17345 : : * WAIT FOR LSN
17346 : : *
17347 : : *****************************************************************************/
17348 : :
17349 : : WaitStmt:
17350 : : WAIT FOR LSN_P Sconst opt_wait_with_clause
17351 : : {
17352 : 255 : WaitStmt *n = makeNode(WaitStmt);
17353 : 255 : n->lsn_literal = $4;
17354 : 255 : n->options = $5;
17355 : 255 : $$ = (Node *) n;
17356 : : }
17357 : : ;
17358 : :
17359 : : opt_wait_with_clause:
17360 : 242 : WITH '(' utility_option_list ')' { $$ = $3; }
17361 : 13 : | /*EMPTY*/ { $$ = NIL; }
17362 : : ;
17363 : :
17364 : : /*
17365 : : * Aggregate decoration clauses
17366 : : */
17367 : : within_group_clause:
17368 : 228 : WITHIN GROUP_P '(' sort_clause ')' { $$ = $4; }
17369 : 209934 : | /*EMPTY*/ { $$ = NIL; }
17370 : : ;
17371 : :
17372 : : filter_clause:
17373 : 497 : FILTER '(' WHERE a_expr ')' { $$ = $4; }
17374 : 209957 : | /*EMPTY*/ { $$ = NULL; }
17375 : : ;
17376 : :
17377 : :
17378 : : /*
17379 : : * Window Definitions
17380 : : */
17381 : : null_treatment:
17382 : 156 : IGNORE_P NULLS_P { $$ = PARSER_IGNORE_NULLS; }
17383 : 64 : | RESPECT_P NULLS_P { $$ = PARSER_RESPECT_NULLS; }
17384 : 209942 : | /*EMPTY*/ { $$ = NO_NULLTREATMENT; }
17385 : : ;
17386 : :
17387 : : window_clause:
17388 : 406 : WINDOW window_definition_list { $$ = $2; }
17389 : 314346 : | /*EMPTY*/ { $$ = NIL; }
17390 : : ;
17391 : :
17392 : : window_definition_list:
17393 : 406 : window_definition { $$ = list_make1($1); }
17394 : : | window_definition_list ',' window_definition
17395 : 20 : { $$ = lappend($1, $3); }
17396 : : ;
17397 : :
17398 : : window_definition:
17399 : : ColId AS window_specification
17400 : : {
17401 : 426 : WindowDef *n = $3;
17402 : :
17403 : 426 : n->name = $1;
17404 : 426 : $$ = n;
17405 : : }
17406 : : ;
17407 : :
17408 : : over_clause: OVER window_specification
17409 : 2012 : { $$ = $2; }
17410 : : | OVER ColId
17411 : : {
17412 : 790 : WindowDef *n = makeNode(WindowDef);
17413 : :
17414 : 790 : n->name = $2;
17415 : 790 : n->refname = NULL;
17416 : 790 : n->partitionClause = NIL;
17417 : 790 : n->orderClause = NIL;
17418 : 790 : n->frameOptions = FRAMEOPTION_DEFAULTS;
17419 : 790 : n->startOffset = NULL;
17420 : 790 : n->endOffset = NULL;
17421 : 790 : n->location = @2;
17422 : 790 : $$ = n;
17423 : : }
17424 : : | /*EMPTY*/
17425 : 207648 : { $$ = NULL; }
17426 : : ;
17427 : :
17428 : : window_specification: '(' opt_existing_window_name opt_partition_clause
17429 : : opt_sort_clause opt_frame_clause ')'
17430 : : {
17431 : 2438 : WindowDef *n = makeNode(WindowDef);
17432 : :
17433 : 2438 : n->name = NULL;
17434 : 2438 : n->refname = $2;
17435 : 2438 : n->partitionClause = $3;
17436 : 2438 : n->orderClause = $4;
17437 : : /* copy relevant fields of opt_frame_clause */
17438 : 2438 : n->frameOptions = $5->frameOptions;
17439 : 2438 : n->startOffset = $5->startOffset;
17440 : 2438 : n->endOffset = $5->endOffset;
17441 : 2438 : n->location = @1;
17442 : 2438 : $$ = n;
17443 : : }
17444 : : ;
17445 : :
17446 : : /*
17447 : : * If we see PARTITION, RANGE, ROWS or GROUPS as the first token after the '('
17448 : : * of a window_specification, we want the assumption to be that there is
17449 : : * no existing_window_name; but those keywords are unreserved and so could
17450 : : * be ColIds. We fix this by making them have the same precedence as IDENT
17451 : : * and giving the empty production here a slightly higher precedence, so
17452 : : * that the shift/reduce conflict is resolved in favor of reducing the rule.
17453 : : * These keywords are thus precluded from being an existing_window_name but
17454 : : * are not reserved for any other purpose.
17455 : : */
17456 : 36 : opt_existing_window_name: ColId { $$ = $1; }
17457 : 2406 : | /*EMPTY*/ %prec Op { $$ = NULL; }
17458 : : ;
17459 : :
17460 : 630 : opt_partition_clause: PARTITION BY expr_list { $$ = $3; }
17461 : 1808 : | /*EMPTY*/ { $$ = NIL; }
17462 : : ;
17463 : :
17464 : : /*
17465 : : * For frame clauses, we return a WindowDef, but only some fields are used:
17466 : : * frameOptions, startOffset, and endOffset.
17467 : : */
17468 : : opt_frame_clause:
17469 : : RANGE frame_extent opt_window_exclusion_clause
17470 : : {
17471 : 542 : WindowDef *n = $2;
17472 : :
17473 : 542 : n->frameOptions |= FRAMEOPTION_NONDEFAULT | FRAMEOPTION_RANGE;
17474 : 542 : n->frameOptions |= $3;
17475 : 542 : $$ = n;
17476 : : }
17477 : : | ROWS frame_extent opt_window_exclusion_clause
17478 : : {
17479 : 510 : WindowDef *n = $2;
17480 : :
17481 : 510 : n->frameOptions |= FRAMEOPTION_NONDEFAULT | FRAMEOPTION_ROWS;
17482 : 510 : n->frameOptions |= $3;
17483 : 510 : $$ = n;
17484 : : }
17485 : : | GROUPS frame_extent opt_window_exclusion_clause
17486 : : {
17487 : 156 : WindowDef *n = $2;
17488 : :
17489 : 156 : n->frameOptions |= FRAMEOPTION_NONDEFAULT | FRAMEOPTION_GROUPS;
17490 : 156 : n->frameOptions |= $3;
17491 : 156 : $$ = n;
17492 : : }
17493 : : | /*EMPTY*/
17494 : : {
17495 : 1230 : WindowDef *n = makeNode(WindowDef);
17496 : :
17497 : 1230 : n->frameOptions = FRAMEOPTION_DEFAULTS;
17498 : 1230 : n->startOffset = NULL;
17499 : 1230 : n->endOffset = NULL;
17500 : 1230 : $$ = n;
17501 : : }
17502 : : ;
17503 : :
17504 : : frame_extent: frame_bound
17505 : : {
17506 : 8 : WindowDef *n = $1;
17507 : :
17508 : : /* reject invalid cases */
17509 [ - + ]: 8 : if (n->frameOptions & FRAMEOPTION_START_UNBOUNDED_FOLLOWING)
17510 [ # # ]: 0 : ereport(ERROR,
17511 : : (errcode(ERRCODE_WINDOWING_ERROR),
17512 : : errmsg("frame start cannot be UNBOUNDED FOLLOWING"),
17513 : : parser_errposition(@1)));
17514 [ - + ]: 8 : if (n->frameOptions & FRAMEOPTION_START_OFFSET_FOLLOWING)
17515 [ # # ]: 0 : ereport(ERROR,
17516 : : (errcode(ERRCODE_WINDOWING_ERROR),
17517 : : errmsg("frame starting from following row cannot end with current row"),
17518 : : parser_errposition(@1)));
17519 : 8 : n->frameOptions |= FRAMEOPTION_END_CURRENT_ROW;
17520 : 8 : $$ = n;
17521 : : }
17522 : : | BETWEEN frame_bound AND frame_bound
17523 : : {
17524 : 1200 : WindowDef *n1 = $2;
17525 : 1200 : WindowDef *n2 = $4;
17526 : :
17527 : : /* form merged options */
17528 : 1200 : int frameOptions = n1->frameOptions;
17529 : : /* shift converts START_ options to END_ options */
17530 : 1200 : frameOptions |= n2->frameOptions << 1;
17531 : 1200 : frameOptions |= FRAMEOPTION_BETWEEN;
17532 : : /* reject invalid cases */
17533 [ - + ]: 1200 : if (frameOptions & FRAMEOPTION_START_UNBOUNDED_FOLLOWING)
17534 [ # # ]: 0 : ereport(ERROR,
17535 : : (errcode(ERRCODE_WINDOWING_ERROR),
17536 : : errmsg("frame start cannot be UNBOUNDED FOLLOWING"),
17537 : : parser_errposition(@2)));
17538 [ - + ]: 1200 : if (frameOptions & FRAMEOPTION_END_UNBOUNDED_PRECEDING)
17539 [ # # ]: 0 : ereport(ERROR,
17540 : : (errcode(ERRCODE_WINDOWING_ERROR),
17541 : : errmsg("frame end cannot be UNBOUNDED PRECEDING"),
17542 : : parser_errposition(@4)));
17543 [ + + ]: 1200 : if ((frameOptions & FRAMEOPTION_START_CURRENT_ROW) &&
17544 [ - + ]: 332 : (frameOptions & FRAMEOPTION_END_OFFSET_PRECEDING))
17545 [ # # ]: 0 : ereport(ERROR,
17546 : : (errcode(ERRCODE_WINDOWING_ERROR),
17547 : : errmsg("frame starting from current row cannot have preceding rows"),
17548 : : parser_errposition(@4)));
17549 [ + + ]: 1200 : if ((frameOptions & FRAMEOPTION_START_OFFSET_FOLLOWING) &&
17550 [ - + ]: 120 : (frameOptions & (FRAMEOPTION_END_OFFSET_PRECEDING |
17551 : : FRAMEOPTION_END_CURRENT_ROW)))
17552 [ # # ]: 0 : ereport(ERROR,
17553 : : (errcode(ERRCODE_WINDOWING_ERROR),
17554 : : errmsg("frame starting from following row cannot have preceding rows"),
17555 : : parser_errposition(@4)));
17556 : 1200 : n1->frameOptions = frameOptions;
17557 : 1200 : n1->endOffset = n2->startOffset;
17558 : 1200 : $$ = n1;
17559 : : }
17560 : : ;
17561 : :
17562 : : /*
17563 : : * This is used for both frame start and frame end, with output set up on
17564 : : * the assumption it's frame start; the frame_extent productions must reject
17565 : : * invalid cases.
17566 : : */
17567 : : frame_bound:
17568 : : UNBOUNDED PRECEDING
17569 : : {
17570 : 192 : WindowDef *n = makeNode(WindowDef);
17571 : :
17572 : 192 : n->frameOptions = FRAMEOPTION_START_UNBOUNDED_PRECEDING;
17573 : 192 : n->startOffset = NULL;
17574 : 192 : n->endOffset = NULL;
17575 : 192 : $$ = n;
17576 : : }
17577 : : | UNBOUNDED FOLLOWING
17578 : : {
17579 : 266 : WindowDef *n = makeNode(WindowDef);
17580 : :
17581 : 266 : n->frameOptions = FRAMEOPTION_START_UNBOUNDED_FOLLOWING;
17582 : 266 : n->startOffset = NULL;
17583 : 266 : n->endOffset = NULL;
17584 : 266 : $$ = n;
17585 : : }
17586 : : | CURRENT_P ROW
17587 : : {
17588 : 456 : WindowDef *n = makeNode(WindowDef);
17589 : :
17590 : 456 : n->frameOptions = FRAMEOPTION_START_CURRENT_ROW;
17591 : 456 : n->startOffset = NULL;
17592 : 456 : n->endOffset = NULL;
17593 : 456 : $$ = n;
17594 : : }
17595 : : | a_expr PRECEDING
17596 : : {
17597 : 664 : WindowDef *n = makeNode(WindowDef);
17598 : :
17599 : 664 : n->frameOptions = FRAMEOPTION_START_OFFSET_PRECEDING;
17600 : 664 : n->startOffset = $1;
17601 : 664 : n->endOffset = NULL;
17602 : 664 : $$ = n;
17603 : : }
17604 : : | a_expr FOLLOWING
17605 : : {
17606 : 830 : WindowDef *n = makeNode(WindowDef);
17607 : :
17608 : 830 : n->frameOptions = FRAMEOPTION_START_OFFSET_FOLLOWING;
17609 : 830 : n->startOffset = $1;
17610 : 830 : n->endOffset = NULL;
17611 : 830 : $$ = n;
17612 : : }
17613 : : ;
17614 : :
17615 : : opt_window_exclusion_clause:
17616 : 92 : EXCLUDE CURRENT_P ROW { $$ = FRAMEOPTION_EXCLUDE_CURRENT_ROW; }
17617 : 72 : | EXCLUDE GROUP_P { $$ = FRAMEOPTION_EXCLUDE_GROUP; }
17618 : 108 : | EXCLUDE TIES { $$ = FRAMEOPTION_EXCLUDE_TIES; }
17619 : 12 : | EXCLUDE NO OTHERS { $$ = 0; }
17620 : 924 : | /*EMPTY*/ { $$ = 0; }
17621 : : ;
17622 : :
17623 : :
17624 : : /*
17625 : : * Supporting nonterminals for expressions.
17626 : : */
17627 : :
17628 : : /* Explicit row production.
17629 : : *
17630 : : * SQL99 allows an optional ROW keyword, so we can now do single-element rows
17631 : : * without conflicting with the parenthesized a_expr production. Without the
17632 : : * ROW keyword, there must be more than one a_expr inside the parens.
17633 : : */
17634 : 0 : row: ROW '(' expr_list ')' { $$ = $3; }
17635 : 0 : | ROW '(' ')' { $$ = NIL; }
17636 : 1126 : | '(' expr_list ',' a_expr ')' { $$ = lappend($2, $4); }
17637 : : ;
17638 : :
17639 : 2639 : explicit_row: ROW '(' expr_list ')' { $$ = $3; }
17640 : 24 : | ROW '(' ')' { $$ = NIL; }
17641 : : ;
17642 : :
17643 : 1848 : implicit_row: '(' expr_list ',' a_expr ')' { $$ = lappend($2, $4); }
17644 : : ;
17645 : :
17646 : 11081 : sub_type: ANY { $$ = ANY_SUBLINK; }
17647 : 0 : | SOME { $$ = ANY_SUBLINK; }
17648 : 221 : | ALL { $$ = ALL_SUBLINK; }
17649 : : ;
17650 : :
17651 : 7688 : all_Op: Op { $$ = $1; }
17652 : 17488 : | MathOp { $$ = $1; }
17653 : : ;
17654 : :
17655 : 29 : MathOp: '+' { $$ = "+"; }
17656 : 34 : | '-' { $$ = "-"; }
17657 : 99 : | '*' { $$ = "*"; }
17658 : 0 : | '/' { $$ = "/"; }
17659 : 4 : | '%' { $$ = "%"; }
17660 : 0 : | '^' { $$ = "^"; }
17661 : 549 : | '<' { $$ = "<"; }
17662 : 482 : | '>' { $$ = ">"; }
17663 : 14936 : | '=' { $$ = "="; }
17664 : 450 : | LESS_EQUALS { $$ = "<="; }
17665 : 444 : | GREATER_EQUALS { $$ = ">="; }
17666 : 441 : | NOT_EQUALS { $$ = "<>"; }
17667 : 17 : | RIGHT_ARROW { $$ = "->"; }
17668 : 3 : | '|' { $$ = "|"; }
17669 : : ;
17670 : :
17671 : : qual_Op: Op
17672 : 27280 : { $$ = list_make1(makeString($1)); }
17673 : : | OPERATOR '(' any_operator ')'
17674 : 9585 : { $$ = $3; }
17675 : : ;
17676 : :
17677 : : qual_all_Op:
17678 : : all_Op
17679 : 787 : { $$ = list_make1(makeString($1)); }
17680 : : | OPERATOR '(' any_operator ')'
17681 : 17 : { $$ = $3; }
17682 : : ;
17683 : :
17684 : : subquery_Op:
17685 : : all_Op
17686 : 11121 : { $$ = list_make1(makeString($1)); }
17687 : : | OPERATOR '(' any_operator ')'
17688 : 159 : { $$ = $3; }
17689 : : | LIKE
17690 : 16 : { $$ = list_make1(makeString("~~")); }
17691 : : | NOT_LA LIKE
17692 : 8 : { $$ = list_make1(makeString("!~~")); }
17693 : : | ILIKE
17694 : 8 : { $$ = list_make1(makeString("~~*")); }
17695 : : | NOT_LA ILIKE
17696 : 0 : { $$ = list_make1(makeString("!~~*")); }
17697 : : /* cannot put SIMILAR TO here, because SIMILAR TO is a hack.
17698 : : * the regular expression is preprocessed by a function (similar_to_escape),
17699 : : * and the ~ operator for posix regular expressions is used.
17700 : : * x SIMILAR TO y -> x ~ similar_to_escape(y)
17701 : : * this transformation is made on the fly by the parser upwards.
17702 : : * however the SubLink structure which handles any/some/all stuff
17703 : : * is not ready for such a thing.
17704 : : */
17705 : : ;
17706 : :
17707 : : expr_list: a_expr
17708 : : {
17709 : 110899 : $$ = list_make1($1);
17710 : : }
17711 : : | expr_list ',' a_expr
17712 : : {
17713 : 100594 : $$ = lappend($1, $3);
17714 : : }
17715 : : ;
17716 : :
17717 : : /* function arguments can have names */
17718 : : func_arg_list: func_arg_expr
17719 : : {
17720 : 208868 : $$ = list_make1($1);
17721 : : }
17722 : : | func_arg_list ',' func_arg_expr
17723 : : {
17724 : 179480 : $$ = lappend($1, $3);
17725 : : }
17726 : : ;
17727 : :
17728 : : func_arg_expr: a_expr
17729 : : {
17730 : 363311 : $$ = $1;
17731 : : }
17732 : : | param_name COLON_EQUALS a_expr
17733 : : {
17734 : 24070 : NamedArgExpr *na = makeNode(NamedArgExpr);
17735 : :
17736 : 24070 : na->name = $1;
17737 : 24070 : na->arg = (Expr *) $3;
17738 : 24070 : na->argnumber = -1; /* until determined */
17739 : 24070 : na->location = @1;
17740 : 24070 : $$ = (Node *) na;
17741 : : }
17742 : : | param_name EQUALS_GREATER a_expr
17743 : : {
17744 : 1460 : NamedArgExpr *na = makeNode(NamedArgExpr);
17745 : :
17746 : 1460 : na->name = $1;
17747 : 1460 : na->arg = (Expr *) $3;
17748 : 1460 : na->argnumber = -1; /* until determined */
17749 : 1460 : na->location = @1;
17750 : 1460 : $$ = (Node *) na;
17751 : : }
17752 : : ;
17753 : :
17754 : 198 : func_arg_list_opt: func_arg_list { $$ = $1; }
17755 : 0 : | /*EMPTY*/ { $$ = NIL; }
17756 : : ;
17757 : :
17758 : 1089 : type_list: Typename { $$ = list_make1($1); }
17759 : 307 : | type_list ',' Typename { $$ = lappend($1, $3); }
17760 : : ;
17761 : :
17762 : : array_expr: '[' expr_list ']'
17763 : : {
17764 : 5522 : $$ = makeAArrayExpr($2, @1, @3);
17765 : : }
17766 : : | '[' array_expr_list ']'
17767 : : {
17768 : 255 : $$ = makeAArrayExpr($2, @1, @3);
17769 : : }
17770 : : | '[' ']'
17771 : : {
17772 : 74 : $$ = makeAArrayExpr(NIL, @1, @2);
17773 : : }
17774 : : ;
17775 : :
17776 : 255 : array_expr_list: array_expr { $$ = list_make1($1); }
17777 : 208 : | array_expr_list ',' array_expr { $$ = lappend($1, $3); }
17778 : : ;
17779 : :
17780 : :
17781 : : extract_list:
17782 : : extract_arg FROM a_expr
17783 : : {
17784 : 884 : $$ = list_make2(makeStringConst($1, @1), $3);
17785 : : }
17786 : : ;
17787 : :
17788 : : /* Allow delimited string Sconst in extract_arg as an SQL extension.
17789 : : * - thomas 2001-04-12
17790 : : */
17791 : : extract_arg:
17792 : 712 : IDENT { $$ = $1; }
17793 : 48 : | YEAR_P { $$ = "year"; }
17794 : 28 : | MONTH_P { $$ = "month"; }
17795 : 36 : | DAY_P { $$ = "day"; }
17796 : 20 : | HOUR_P { $$ = "hour"; }
17797 : 20 : | MINUTE_P { $$ = "minute"; }
17798 : 20 : | SECOND_P { $$ = "second"; }
17799 : 0 : | Sconst { $$ = $1; }
17800 : : ;
17801 : :
17802 : : unicode_normal_form:
17803 : 52 : NFC { $$ = "NFC"; }
17804 : 24 : | NFD { $$ = "NFD"; }
17805 : 12 : | NFKC { $$ = "NFKC"; }
17806 : 12 : | NFKD { $$ = "NFKD"; }
17807 : : ;
17808 : :
17809 : : /* OVERLAY() arguments */
17810 : : overlay_list:
17811 : : a_expr PLACING a_expr FROM a_expr FOR a_expr
17812 : : {
17813 : : /* overlay(A PLACING B FROM C FOR D) is converted to overlay(A, B, C, D) */
17814 : 22 : $$ = list_make4($1, $3, $5, $7);
17815 : : }
17816 : : | a_expr PLACING a_expr FROM a_expr
17817 : : {
17818 : : /* overlay(A PLACING B FROM C) is converted to overlay(A, B, C) */
17819 : 32 : $$ = list_make3($1, $3, $5);
17820 : : }
17821 : : ;
17822 : :
17823 : : /* position_list uses b_expr not a_expr to avoid conflict with general IN */
17824 : : position_list:
17825 : 277 : b_expr IN_P b_expr { $$ = list_make2($3, $1); }
17826 : : ;
17827 : :
17828 : : /*
17829 : : * SUBSTRING() arguments
17830 : : *
17831 : : * Note that SQL:1999 has both
17832 : : * text FROM int FOR int
17833 : : * and
17834 : : * text FROM pattern FOR escape
17835 : : *
17836 : : * In the parser we map them both to a call to the substring() function and
17837 : : * rely on type resolution to pick the right one.
17838 : : *
17839 : : * In SQL:2003, the second variant was changed to
17840 : : * text SIMILAR pattern ESCAPE escape
17841 : : * We could in theory map that to a different function internally, but
17842 : : * since we still support the SQL:1999 version, we don't. However,
17843 : : * ruleutils.c will reverse-list the call in the newer style.
17844 : : */
17845 : : substr_list:
17846 : : a_expr FROM a_expr FOR a_expr
17847 : : {
17848 : 101 : $$ = list_make3($1, $3, $5);
17849 : : }
17850 : : | a_expr FOR a_expr FROM a_expr
17851 : : {
17852 : : /* not legal per SQL, but might as well allow it */
17853 : 0 : $$ = list_make3($1, $5, $3);
17854 : : }
17855 : : | a_expr FROM a_expr
17856 : : {
17857 : : /*
17858 : : * Because we aren't restricting data types here, this
17859 : : * syntax can end up resolving to textregexsubstr().
17860 : : * We've historically allowed that to happen, so continue
17861 : : * to accept it. However, ruleutils.c will reverse-list
17862 : : * such a call in regular function call syntax.
17863 : : */
17864 : 219 : $$ = list_make2($1, $3);
17865 : : }
17866 : : | a_expr FOR a_expr
17867 : : {
17868 : : /* not legal per SQL */
17869 : :
17870 : : /*
17871 : : * Since there are no cases where this syntax allows
17872 : : * a textual FOR value, we forcibly cast the argument
17873 : : * to int4. The possible matches in pg_proc are
17874 : : * substring(text,int4) and substring(text,text),
17875 : : * and we don't want the parser to choose the latter,
17876 : : * which it is likely to do if the second argument
17877 : : * is unknown or doesn't have an implicit cast to int4.
17878 : : */
17879 : 31 : $$ = list_make3($1, makeIntConst(1, -1),
17880 : : makeTypeCast($3,
17881 : : SystemTypeName("int4"), -1));
17882 : : }
17883 : : | a_expr SIMILAR a_expr ESCAPE a_expr
17884 : : {
17885 : 116 : $$ = list_make3($1, $3, $5);
17886 : : }
17887 : : ;
17888 : :
17889 : 394 : trim_list: a_expr FROM expr_list { $$ = lappend($3, $1); }
17890 : 16 : | FROM expr_list { $$ = $2; }
17891 : 56 : | expr_list { $$ = $1; }
17892 : : ;
17893 : :
17894 : : /*
17895 : : * Define SQL-style CASE clause.
17896 : : * - Full specification
17897 : : * CASE WHEN a = b THEN c ... ELSE d END
17898 : : * - Implicit argument
17899 : : * CASE a WHEN b THEN c ... ELSE d END
17900 : : */
17901 : : case_expr: CASE case_arg when_clause_list case_default END_P
17902 : : {
17903 : 25694 : CaseExpr *c = makeNode(CaseExpr);
17904 : :
17905 : 25694 : c->casetype = InvalidOid; /* not analyzed yet */
17906 : 25694 : c->arg = (Expr *) $2;
17907 : 25694 : c->args = $3;
17908 : 25694 : c->defresult = (Expr *) $4;
17909 : 25694 : c->location = @1;
17910 : 25694 : $$ = (Node *) c;
17911 : : }
17912 : : ;
17913 : :
17914 : : when_clause_list:
17915 : : /* There must be at least one */
17916 : 25694 : when_clause { $$ = list_make1($1); }
17917 : 20449 : | when_clause_list when_clause { $$ = lappend($1, $2); }
17918 : : ;
17919 : :
17920 : : when_clause:
17921 : : WHEN a_expr THEN a_expr
17922 : : {
17923 : 46143 : CaseWhen *w = makeNode(CaseWhen);
17924 : :
17925 : 46143 : w->expr = (Expr *) $2;
17926 : 46143 : w->result = (Expr *) $4;
17927 : 46143 : w->location = @1;
17928 : 46143 : $$ = (Node *) w;
17929 : : }
17930 : : ;
17931 : :
17932 : : case_default:
17933 : 19142 : ELSE a_expr { $$ = $2; }
17934 : 6552 : | /*EMPTY*/ { $$ = NULL; }
17935 : : ;
17936 : :
17937 : 5168 : case_arg: a_expr { $$ = $1; }
17938 : 20526 : | /*EMPTY*/ { $$ = NULL; }
17939 : : ;
17940 : :
17941 : : columnref: ColId
17942 : : {
17943 : 470093 : $$ = makeColumnRef($1, NIL, @1, yyscanner);
17944 : : }
17945 : : | ColId indirection
17946 : : {
17947 : 704102 : $$ = makeColumnRef($1, $2, @1, yyscanner);
17948 : : }
17949 : : ;
17950 : :
17951 : : indirection_el:
17952 : : '.' attr_name
17953 : : {
17954 : 954587 : $$ = (Node *) makeString($2);
17955 : : }
17956 : : | '.' '*'
17957 : : {
17958 : 4715 : $$ = (Node *) makeNode(A_Star);
17959 : : }
17960 : : | '[' a_expr ']'
17961 : : {
17962 : 8892 : A_Indices *ai = makeNode(A_Indices);
17963 : :
17964 : 8892 : ai->is_slice = false;
17965 : 8892 : ai->lidx = NULL;
17966 : 8892 : ai->uidx = $2;
17967 : 8892 : $$ = (Node *) ai;
17968 : : }
17969 : : | '[' opt_slice_bound ':' opt_slice_bound ']'
17970 : : {
17971 : 405 : A_Indices *ai = makeNode(A_Indices);
17972 : :
17973 : 405 : ai->is_slice = true;
17974 : 405 : ai->lidx = $2;
17975 : 405 : ai->uidx = $4;
17976 : 405 : $$ = (Node *) ai;
17977 : : }
17978 : : ;
17979 : :
17980 : : opt_slice_bound:
17981 : 690 : a_expr { $$ = $1; }
17982 : 120 : | /*EMPTY*/ { $$ = NULL; }
17983 : : ;
17984 : :
17985 : : indirection:
17986 : 953684 : indirection_el { $$ = list_make1($1); }
17987 : 2112 : | indirection indirection_el { $$ = lappend($1, $2); }
17988 : : ;
17989 : :
17990 : : opt_indirection:
17991 : 125208 : /*EMPTY*/ { $$ = NIL; }
17992 : 12803 : | opt_indirection indirection_el { $$ = lappend($1, $2); }
17993 : : ;
17994 : :
17995 : : opt_asymmetric: ASYMMETRIC
17996 : : | /*EMPTY*/
17997 : : ;
17998 : :
17999 : : /* SQL/JSON support */
18000 : : json_passing_clause_opt:
18001 : 228 : PASSING json_arguments { $$ = $2; }
18002 : 1512 : | /*EMPTY*/ { $$ = NIL; }
18003 : : ;
18004 : :
18005 : : json_arguments:
18006 : 228 : json_argument { $$ = list_make1($1); }
18007 : 88 : | json_arguments ',' json_argument { $$ = lappend($1, $3); }
18008 : : ;
18009 : :
18010 : : json_argument:
18011 : : json_value_expr AS ColLabel
18012 : : {
18013 : 316 : JsonArgument *n = makeNode(JsonArgument);
18014 : :
18015 : 316 : n->val = (JsonValueExpr *) $1;
18016 : 316 : n->name = $3;
18017 : 316 : $$ = (Node *) n;
18018 : : }
18019 : : ;
18020 : :
18021 : : /* ARRAY is a noise word */
18022 : : json_wrapper_behavior:
18023 : 28 : WITHOUT WRAPPER { $$ = JSW_NONE; }
18024 : 0 : | WITHOUT ARRAY WRAPPER { $$ = JSW_NONE; }
18025 : 56 : | WITH WRAPPER { $$ = JSW_UNCONDITIONAL; }
18026 : 8 : | WITH ARRAY WRAPPER { $$ = JSW_UNCONDITIONAL; }
18027 : 0 : | WITH CONDITIONAL ARRAY WRAPPER { $$ = JSW_CONDITIONAL; }
18028 : 8 : | WITH UNCONDITIONAL ARRAY WRAPPER { $$ = JSW_UNCONDITIONAL; }
18029 : 24 : | WITH CONDITIONAL WRAPPER { $$ = JSW_CONDITIONAL; }
18030 : 8 : | WITH UNCONDITIONAL WRAPPER { $$ = JSW_UNCONDITIONAL; }
18031 : 1532 : | /* empty */ { $$ = JSW_UNSPEC; }
18032 : : ;
18033 : :
18034 : : json_behavior:
18035 : : DEFAULT a_expr
18036 : 360 : { $$ = (Node *) makeJsonBehavior(JSON_BEHAVIOR_DEFAULT, $2, @1); }
18037 : : | json_behavior_type
18038 : 488 : { $$ = (Node *) makeJsonBehavior($1, NULL, @1); }
18039 : : ;
18040 : :
18041 : : json_behavior_type:
18042 : 340 : ERROR_P { $$ = JSON_BEHAVIOR_ERROR; }
18043 : 20 : | NULL_P { $$ = JSON_BEHAVIOR_NULL; }
18044 : 24 : | TRUE_P { $$ = JSON_BEHAVIOR_TRUE; }
18045 : 8 : | FALSE_P { $$ = JSON_BEHAVIOR_FALSE; }
18046 : 12 : | UNKNOWN { $$ = JSON_BEHAVIOR_UNKNOWN; }
18047 : 20 : | EMPTY_P ARRAY { $$ = JSON_BEHAVIOR_EMPTY_ARRAY; }
18048 : 48 : | EMPTY_P OBJECT_P { $$ = JSON_BEHAVIOR_EMPTY_OBJECT; }
18049 : : /* non-standard, for Oracle compatibility only */
18050 : 16 : | EMPTY_P { $$ = JSON_BEHAVIOR_EMPTY_ARRAY; }
18051 : : ;
18052 : :
18053 : : json_behavior_clause_opt:
18054 : : json_behavior ON EMPTY_P
18055 : 220 : { $$ = list_make2($1, NULL); }
18056 : : | json_behavior ON ERROR_P
18057 : 372 : { $$ = list_make2(NULL, $1); }
18058 : : | json_behavior ON EMPTY_P json_behavior ON ERROR_P
18059 : 68 : { $$ = list_make2($1, $4); }
18060 : : | /* EMPTY */
18061 : 1444 : { $$ = list_make2(NULL, NULL); }
18062 : : ;
18063 : :
18064 : : json_on_error_clause_opt:
18065 : : json_behavior ON ERROR_P
18066 : 116 : { $$ = $1; }
18067 : : | /* EMPTY */
18068 : 588 : { $$ = NULL; }
18069 : : ;
18070 : :
18071 : : json_value_expr:
18072 : : a_expr json_format_clause_opt
18073 : : {
18074 : : /* formatted_expr will be set during parse-analysis. */
18075 : 3286 : $$ = (Node *) makeJsonValueExpr((Expr *) $1, NULL,
18076 : 3286 : castNode(JsonFormat, $2));
18077 : : }
18078 : : ;
18079 : :
18080 : : json_format_clause:
18081 : : FORMAT_LA JSON ENCODING name
18082 : : {
18083 : : int encoding;
18084 : :
18085 [ + + ]: 66 : if (!pg_strcasecmp($4, "utf8"))
18086 : 42 : encoding = JS_ENC_UTF8;
18087 [ + + ]: 24 : else if (!pg_strcasecmp($4, "utf16"))
18088 : 8 : encoding = JS_ENC_UTF16;
18089 [ + + ]: 16 : else if (!pg_strcasecmp($4, "utf32"))
18090 : 8 : encoding = JS_ENC_UTF32;
18091 : : else
18092 [ + - ]: 8 : ereport(ERROR,
18093 : : (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
18094 : : errmsg("unrecognized JSON encoding: %s", $4),
18095 : : parser_errposition(@4)));
18096 : :
18097 : 58 : $$ = (Node *) makeJsonFormat(JS_FORMAT_JSON, encoding, @1);
18098 : : }
18099 : : | FORMAT_LA JSON
18100 : : {
18101 : 292 : $$ = (Node *) makeJsonFormat(JS_FORMAT_JSON, JS_ENC_DEFAULT, @1);
18102 : : }
18103 : : ;
18104 : :
18105 : : json_format_clause_opt:
18106 : : json_format_clause
18107 : : {
18108 : 258 : $$ = $1;
18109 : : }
18110 : : | /* EMPTY */
18111 : : {
18112 : 4422 : $$ = (Node *) makeJsonFormat(JS_FORMAT_DEFAULT, JS_ENC_DEFAULT, -1);
18113 : : }
18114 : : ;
18115 : :
18116 : : json_quotes_clause_opt:
18117 : 8 : KEEP QUOTES ON SCALAR STRING_P { $$ = JS_QUOTES_KEEP; }
18118 : 60 : | KEEP QUOTES { $$ = JS_QUOTES_KEEP; }
18119 : 8 : | OMIT QUOTES ON SCALAR STRING_P { $$ = JS_QUOTES_OMIT; }
18120 : 120 : | OMIT QUOTES { $$ = JS_QUOTES_OMIT; }
18121 : 1468 : | /* EMPTY */ { $$ = JS_QUOTES_UNSPEC; }
18122 : : ;
18123 : :
18124 : : json_returning_clause_opt:
18125 : : RETURNING Typename json_format_clause_opt
18126 : : {
18127 : 1302 : JsonOutput *n = makeNode(JsonOutput);
18128 : :
18129 : 1302 : n->typeName = $2;
18130 : 1302 : n->returning = makeNode(JsonReturning);
18131 : 1302 : n->returning->format = (JsonFormat *) $3;
18132 : 1302 : $$ = (Node *) n;
18133 : : }
18134 : 900 : | /* EMPTY */ { $$ = NULL; }
18135 : : ;
18136 : :
18137 : : /*
18138 : : * We must assign the only-JSON production a precedence less than IDENT in
18139 : : * order to favor shifting over reduction when JSON is followed by VALUE_P,
18140 : : * OBJECT_P, or SCALAR. (ARRAY doesn't need that treatment, because it's a
18141 : : * fully reserved word.) Because json_predicate_type_constraint is always
18142 : : * followed by json_key_uniqueness_constraint_opt, we also need the only-JSON
18143 : : * production to have precedence less than WITH and WITHOUT. UNBOUNDED isn't
18144 : : * really related to this syntax, but it's a convenient choice because it
18145 : : * already has a precedence less than IDENT for other reasons.
18146 : : */
18147 : : json_predicate_type_constraint:
18148 : 184 : JSON %prec UNBOUNDED { $$ = JS_TYPE_ANY; }
18149 : 18 : | JSON VALUE_P { $$ = JS_TYPE_ANY; }
18150 : 26 : | JSON ARRAY { $$ = JS_TYPE_ARRAY; }
18151 : 26 : | JSON OBJECT_P { $$ = JS_TYPE_OBJECT; }
18152 : 26 : | JSON SCALAR { $$ = JS_TYPE_SCALAR; }
18153 : : ;
18154 : :
18155 : : /*
18156 : : * KEYS is a noise word here. To avoid shift/reduce conflicts, assign the
18157 : : * KEYS-less productions a precedence less than IDENT (i.e., less than KEYS).
18158 : : * This prevents reducing them when the next token is KEYS.
18159 : : */
18160 : : json_key_uniqueness_constraint_opt:
18161 : 102 : WITH UNIQUE KEYS { $$ = true; }
18162 : 74 : | WITH UNIQUE %prec UNBOUNDED { $$ = true; }
18163 : 28 : | WITHOUT UNIQUE KEYS { $$ = false; }
18164 : 10 : | WITHOUT UNIQUE %prec UNBOUNDED { $$ = false; }
18165 : 652 : | /* EMPTY */ %prec UNBOUNDED { $$ = false; }
18166 : : ;
18167 : :
18168 : : json_name_and_value_list:
18169 : : json_name_and_value
18170 : 318 : { $$ = list_make1($1); }
18171 : : | json_name_and_value_list ',' json_name_and_value
18172 : 168 : { $$ = lappend($1, $3); }
18173 : : ;
18174 : :
18175 : : json_name_and_value:
18176 : : /* Supporting this syntax seems to require major surgery
18177 : : KEY c_expr VALUE_P json_value_expr
18178 : : { $$ = makeJsonKeyValue($2, $4); }
18179 : : |
18180 : : */
18181 : : c_expr VALUE_P json_value_expr
18182 : 104 : { $$ = makeJsonKeyValue($1, $3); }
18183 : : |
18184 : : a_expr ':' json_value_expr
18185 : 542 : { $$ = makeJsonKeyValue($1, $3); }
18186 : : ;
18187 : :
18188 : : /* empty means false for objects, true for arrays */
18189 : : json_object_constructor_null_clause_opt:
18190 : 20 : NULL_P ON NULL_P { $$ = false; }
18191 : 88 : | ABSENT ON NULL_P { $$ = true; }
18192 : 370 : | /* EMPTY */ { $$ = false; }
18193 : : ;
18194 : :
18195 : : json_array_constructor_null_clause_opt:
18196 : 56 : NULL_P ON NULL_P { $$ = false; }
18197 : 24 : | ABSENT ON NULL_P { $$ = true; }
18198 : 236 : | /* EMPTY */ { $$ = true; }
18199 : : ;
18200 : :
18201 : : json_value_expr_list:
18202 : 168 : json_value_expr { $$ = list_make1($1); }
18203 : 92 : | json_value_expr_list ',' json_value_expr { $$ = lappend($1, $3);}
18204 : : ;
18205 : :
18206 : : json_aggregate_func:
18207 : : JSON_OBJECTAGG '('
18208 : : json_name_and_value
18209 : : json_object_constructor_null_clause_opt
18210 : : json_key_uniqueness_constraint_opt
18211 : : json_returning_clause_opt
18212 : : ')'
18213 : : {
18214 : 160 : JsonObjectAgg *n = makeNode(JsonObjectAgg);
18215 : :
18216 : 160 : n->arg = (JsonKeyValue *) $3;
18217 : 160 : n->absent_on_null = $4;
18218 : 160 : n->unique = $5;
18219 : 160 : n->constructor = makeNode(JsonAggConstructor);
18220 : 160 : n->constructor->output = (JsonOutput *) $6;
18221 : 160 : n->constructor->agg_order = NULL;
18222 : 160 : n->constructor->location = @1;
18223 : 160 : $$ = (Node *) n;
18224 : : }
18225 : : | JSON_ARRAYAGG '('
18226 : : json_value_expr
18227 : : json_array_aggregate_order_by_clause_opt
18228 : : json_array_constructor_null_clause_opt
18229 : : json_returning_clause_opt
18230 : : ')'
18231 : : {
18232 : 148 : JsonArrayAgg *n = makeNode(JsonArrayAgg);
18233 : :
18234 : 148 : n->arg = (JsonValueExpr *) $3;
18235 : 148 : n->absent_on_null = $5;
18236 : 148 : n->constructor = makeNode(JsonAggConstructor);
18237 : 148 : n->constructor->agg_order = $4;
18238 : 148 : n->constructor->output = (JsonOutput *) $6;
18239 : 148 : n->constructor->location = @1;
18240 : 148 : $$ = (Node *) n;
18241 : : }
18242 : : ;
18243 : :
18244 : : json_array_aggregate_order_by_clause_opt:
18245 : 36 : ORDER BY sortby_list { $$ = $3; }
18246 : 112 : | /* EMPTY */ { $$ = NIL; }
18247 : : ;
18248 : :
18249 : :
18250 : : /*****************************************************************************
18251 : : *
18252 : : * graph patterns
18253 : : *
18254 : : *****************************************************************************/
18255 : :
18256 : : graph_pattern:
18257 : : path_pattern_list where_clause
18258 : : {
18259 : 453 : GraphPattern *gp = makeNode(GraphPattern);
18260 : :
18261 : 453 : gp->path_pattern_list = $1;
18262 : 453 : gp->whereClause = $2;
18263 : 453 : $$ = (Node *) gp;
18264 : : }
18265 : : ;
18266 : :
18267 : : path_pattern_list:
18268 : 453 : path_pattern { $$ = list_make1($1); }
18269 : 4 : | path_pattern_list ',' path_pattern { $$ = lappend($1, $3); }
18270 : : ;
18271 : :
18272 : : path_pattern:
18273 : 457 : path_pattern_expression { $$ = $1; }
18274 : : ;
18275 : :
18276 : : /*
18277 : : * path pattern expression
18278 : : */
18279 : :
18280 : : path_pattern_expression:
18281 : 461 : path_term { $$ = $1; }
18282 : : /* | path_multiset_alternation */
18283 : : /* | path_pattern_union */
18284 : : ;
18285 : :
18286 : : path_term:
18287 : 465 : path_factor { $$ = list_make1($1); }
18288 : 882 : | path_term path_factor { $$ = lappend($1, $2); }
18289 : : ;
18290 : :
18291 : : path_factor:
18292 : : path_primary opt_graph_pattern_quantifier
18293 : : {
18294 : 1347 : GraphElementPattern *gep = (GraphElementPattern *) $1;
18295 : :
18296 : 1347 : gep->quantifier = $2;
18297 : :
18298 : 1347 : $$ = (Node *) gep;
18299 : : }
18300 : : ;
18301 : :
18302 : : path_primary:
18303 : : '(' opt_colid opt_is_label_expression where_clause ')'
18304 : : {
18305 : 896 : GraphElementPattern *gep = makeNode(GraphElementPattern);
18306 : :
18307 : 896 : gep->kind = VERTEX_PATTERN;
18308 : 896 : gep->variable = $2;
18309 : 896 : gep->labelexpr = $3;
18310 : 896 : gep->whereClause = $4;
18311 : 896 : gep->location = @1;
18312 : :
18313 : 896 : $$ = (Node *) gep;
18314 : : }
18315 : : /* full edge pointing left: <-[ xxx ]- */
18316 : : | '<' '-' '[' opt_colid opt_is_label_expression where_clause ']' '-'
18317 : : {
18318 : 8 : GraphElementPattern *gep = makeNode(GraphElementPattern);
18319 : :
18320 : 8 : gep->kind = EDGE_PATTERN_LEFT;
18321 : 8 : gep->variable = $4;
18322 : 8 : gep->labelexpr = $5;
18323 : 8 : gep->whereClause = $6;
18324 : 8 : gep->location = @1;
18325 : :
18326 : 8 : $$ = (Node *) gep;
18327 : : }
18328 : : /* full edge pointing right: -[ xxx ]-> */
18329 : : | '-' '[' opt_colid opt_is_label_expression where_clause ']' '-' '>'
18330 : : {
18331 : 0 : GraphElementPattern *gep = makeNode(GraphElementPattern);
18332 : :
18333 : 0 : gep->kind = EDGE_PATTERN_RIGHT;
18334 : 0 : gep->variable = $3;
18335 : 0 : gep->labelexpr = $4;
18336 : 0 : gep->whereClause = $5;
18337 : 0 : gep->location = @1;
18338 : :
18339 : 0 : $$ = (Node *) gep;
18340 : : }
18341 : : | '-' '[' opt_colid opt_is_label_expression where_clause ']' RIGHT_ARROW
18342 : : {
18343 : 295 : GraphElementPattern *gep = makeNode(GraphElementPattern);
18344 : :
18345 : 295 : gep->kind = EDGE_PATTERN_RIGHT;
18346 : 295 : gep->variable = $3;
18347 : 295 : gep->labelexpr = $4;
18348 : 295 : gep->whereClause = $5;
18349 : 295 : gep->location = @1;
18350 : :
18351 : 295 : $$ = (Node *) gep;
18352 : : }
18353 : : /* full edge any direction: -[ xxx ]- */
18354 : : | '-' '[' opt_colid opt_is_label_expression where_clause ']' '-'
18355 : : {
18356 : 20 : GraphElementPattern *gep = makeNode(GraphElementPattern);
18357 : :
18358 : 20 : gep->kind = EDGE_PATTERN_ANY;
18359 : 20 : gep->variable = $3;
18360 : 20 : gep->labelexpr = $4;
18361 : 20 : gep->whereClause = $5;
18362 : 20 : gep->location = @1;
18363 : :
18364 : 20 : $$ = (Node *) gep;
18365 : : }
18366 : : /* abbreviated edge patterns */
18367 : : | '<' '-'
18368 : : {
18369 : 0 : GraphElementPattern *gep = makeNode(GraphElementPattern);
18370 : :
18371 : 0 : gep->kind = EDGE_PATTERN_LEFT;
18372 : 0 : gep->location = @1;
18373 : :
18374 : 0 : $$ = (Node *) gep;
18375 : : }
18376 : : | '-' '>'
18377 : : {
18378 : 0 : GraphElementPattern *gep = makeNode(GraphElementPattern);
18379 : :
18380 : 0 : gep->kind = EDGE_PATTERN_RIGHT;
18381 : 0 : gep->location = @1;
18382 : :
18383 : 0 : $$ = (Node *) gep;
18384 : : }
18385 : : | RIGHT_ARROW
18386 : : {
18387 : 116 : GraphElementPattern *gep = makeNode(GraphElementPattern);
18388 : :
18389 : 116 : gep->kind = EDGE_PATTERN_RIGHT;
18390 : 116 : gep->location = @1;
18391 : :
18392 : 116 : $$ = (Node *) gep;
18393 : : }
18394 : : | '-'
18395 : : {
18396 : 8 : GraphElementPattern *gep = makeNode(GraphElementPattern);
18397 : :
18398 : 8 : gep->kind = EDGE_PATTERN_ANY;
18399 : 8 : gep->location = @1;
18400 : :
18401 : 8 : $$ = (Node *) gep;
18402 : : }
18403 : : | '(' path_pattern_expression where_clause ')'
18404 : : {
18405 : 4 : GraphElementPattern *gep = makeNode(GraphElementPattern);
18406 : :
18407 : 4 : gep->kind = PAREN_EXPR;
18408 : 4 : gep->subexpr = $2;
18409 : 4 : gep->whereClause = $3;
18410 : 4 : gep->location = @1;
18411 : :
18412 : 4 : $$ = (Node *) gep;
18413 : : }
18414 : : ;
18415 : :
18416 : : opt_colid:
18417 : 1000 : ColId { $$ = $1; }
18418 : 223 : | /*EMPTY*/ { $$ = NULL; }
18419 : : ;
18420 : :
18421 : : opt_is_label_expression:
18422 : 691 : IS label_expression { $$ = $2; }
18423 : 532 : | /*EMPTY*/ { $$ = NULL; }
18424 : : ;
18425 : :
18426 : : /*
18427 : : * graph pattern quantifier
18428 : : */
18429 : :
18430 : : opt_graph_pattern_quantifier:
18431 : 0 : '{' Iconst '}' { $$ = list_make2_int($2, $2); }
18432 : 0 : | '{' ',' Iconst '}' { $$ = list_make2_int(0, $3); }
18433 : 4 : | '{' Iconst ',' Iconst '}' { $$ = list_make2_int($2, $4); }
18434 : 1343 : | /*EMPTY*/ { $$ = NULL; }
18435 : : ;
18436 : :
18437 : : /*
18438 : : * label expression
18439 : : */
18440 : :
18441 : : label_expression:
18442 : : label_term
18443 : : | label_disjunction
18444 : : ;
18445 : :
18446 : : label_disjunction:
18447 : : label_expression '|' label_term
18448 : 64 : { $$ = makeOrExpr($1, $3, @2); }
18449 : : ;
18450 : :
18451 : : label_term:
18452 : : name
18453 : 755 : { $$ = makeColumnRef($1, NIL, @1, yyscanner); }
18454 : : ;
18455 : :
18456 : :
18457 : : /*****************************************************************************
18458 : : *
18459 : : * target list for SELECT
18460 : : *
18461 : : *****************************************************************************/
18462 : :
18463 : 311893 : opt_target_list: target_list { $$ = $1; }
18464 : 367 : | /* EMPTY */ { $$ = NIL; }
18465 : : ;
18466 : :
18467 : : target_list:
18468 : 316831 : target_el { $$ = list_make1($1); }
18469 : 419539 : | target_list ',' target_el { $$ = lappend($1, $3); }
18470 : : ;
18471 : :
18472 : : target_el: a_expr AS ColLabel
18473 : : {
18474 : 150154 : $$ = makeNode(ResTarget);
18475 : 150154 : $$->name = $3;
18476 : 150154 : $$->indirection = NIL;
18477 : 150154 : $$->val = (Node *) $1;
18478 : 150154 : $$->location = @1;
18479 : : }
18480 : : | a_expr BareColLabel
18481 : : {
18482 : 2290 : $$ = makeNode(ResTarget);
18483 : 2290 : $$->name = $2;
18484 : 2290 : $$->indirection = NIL;
18485 : 2290 : $$->val = (Node *) $1;
18486 : 2290 : $$->location = @1;
18487 : : }
18488 : : | a_expr
18489 : : {
18490 : 542638 : $$ = makeNode(ResTarget);
18491 : 542638 : $$->name = NULL;
18492 : 542638 : $$->indirection = NIL;
18493 : 542638 : $$->val = (Node *) $1;
18494 : 542638 : $$->location = @1;
18495 : : }
18496 : : | '*'
18497 : : {
18498 : 41288 : ColumnRef *n = makeNode(ColumnRef);
18499 : :
18500 : 41288 : n->fields = list_make1(makeNode(A_Star));
18501 : 41288 : n->location = @1;
18502 : :
18503 : 41288 : $$ = makeNode(ResTarget);
18504 : 41288 : $$->name = NULL;
18505 : 41288 : $$->indirection = NIL;
18506 : 41288 : $$->val = (Node *) n;
18507 : 41288 : $$->location = @1;
18508 : : }
18509 : : ;
18510 : :
18511 : :
18512 : : /*****************************************************************************
18513 : : *
18514 : : * Names and constants
18515 : : *
18516 : : *****************************************************************************/
18517 : :
18518 : : qualified_name_list:
18519 : 10541 : qualified_name { $$ = list_make1($1); }
18520 : 571 : | qualified_name_list ',' qualified_name { $$ = lappend($1, $3); }
18521 : : ;
18522 : :
18523 : : /*
18524 : : * The production for a qualified relation name has to exactly match the
18525 : : * production for a qualified func_name, because in a FROM clause we cannot
18526 : : * tell which we are parsing until we see what comes after it ('(' for a
18527 : : * func_name, something else for a relation). Therefore we allow 'indirection'
18528 : : * which may contain subscripts, and reject that case in the C code.
18529 : : */
18530 : : qualified_name:
18531 : : ColId
18532 : : {
18533 : 282810 : $$ = makeRangeVar(NULL, $1, @1);
18534 : : }
18535 : : | ColId indirection
18536 : : {
18537 : 161118 : $$ = makeRangeVarFromQualifiedName($1, $2, @1, yyscanner);
18538 : : }
18539 : : ;
18540 : :
18541 : : name_list: name
18542 : 18373 : { $$ = list_make1(makeString($1)); }
18543 : : | name_list ',' name
18544 : 37920 : { $$ = lappend($1, makeString($3)); }
18545 : : ;
18546 : :
18547 : :
18548 : 111684 : name: ColId { $$ = $1; };
18549 : :
18550 : 1030933 : attr_name: ColLabel { $$ = $1; };
18551 : :
18552 : 46 : file_name: Sconst { $$ = $1; };
18553 : :
18554 : : /*
18555 : : * The production for a qualified func_name has to exactly match the
18556 : : * production for a qualified columnref, because we cannot tell which we
18557 : : * are parsing until we see what comes after it ('(' or Sconst for a func_name,
18558 : : * anything else for a columnref). Therefore we allow 'indirection' which
18559 : : * may contain subscripts, and reject that case in the C code. (If we
18560 : : * ever implement SQL99-like methods, such syntax may actually become legal!)
18561 : : */
18562 : : func_name: type_function_name
18563 : 180495 : { $$ = list_make1(makeString($1)); }
18564 : : | ColId indirection
18565 : : {
18566 : 88417 : $$ = check_func_name(lcons(makeString($1), $2),
18567 : : yyscanner);
18568 : : }
18569 : : ;
18570 : :
18571 : :
18572 : : /*
18573 : : * Constants
18574 : : */
18575 : : AexprConst: Iconst
18576 : : {
18577 : 265105 : $$ = makeIntConst($1, @1);
18578 : : }
18579 : : | FCONST
18580 : : {
18581 : 8173 : $$ = makeFloatConst($1, @1);
18582 : : }
18583 : : | Sconst
18584 : : {
18585 : 457829 : $$ = makeStringConst($1, @1);
18586 : : }
18587 : : | BCONST
18588 : : {
18589 : 510 : $$ = makeBitStringConst($1, @1);
18590 : : }
18591 : : | XCONST
18592 : : {
18593 : : /* This is a bit constant per SQL99:
18594 : : * Without Feature F511, "BIT data type",
18595 : : * a <general literal> shall not be a
18596 : : * <bit string literal> or a <hex string literal>.
18597 : : */
18598 : 2217 : $$ = makeBitStringConst($1, @1);
18599 : : }
18600 : : | func_name Sconst
18601 : : {
18602 : : /* generic type 'literal' syntax */
18603 : 6429 : TypeName *t = makeTypeNameFromNameList($1);
18604 : :
18605 : 6429 : t->location = @1;
18606 : 6429 : $$ = makeStringConstCast($2, @2, t);
18607 : : }
18608 : : | func_name '(' func_arg_list opt_sort_clause ')' Sconst
18609 : : {
18610 : : /* generic syntax with a type modifier */
18611 : 0 : TypeName *t = makeTypeNameFromNameList($1);
18612 : : ListCell *lc;
18613 : :
18614 : : /*
18615 : : * We must use func_arg_list and opt_sort_clause in the
18616 : : * production to avoid reduce/reduce conflicts, but we
18617 : : * don't actually wish to allow NamedArgExpr in this
18618 : : * context, nor ORDER BY.
18619 : : */
18620 [ # # # # : 0 : foreach(lc, $3)
# # ]
18621 : : {
18622 : 0 : NamedArgExpr *arg = (NamedArgExpr *) lfirst(lc);
18623 : :
18624 [ # # ]: 0 : if (IsA(arg, NamedArgExpr))
18625 [ # # ]: 0 : ereport(ERROR,
18626 : : (errcode(ERRCODE_SYNTAX_ERROR),
18627 : : errmsg("type modifier cannot have parameter name"),
18628 : : parser_errposition(arg->location)));
18629 : : }
18630 [ # # ]: 0 : if ($4 != NIL)
18631 [ # # ]: 0 : ereport(ERROR,
18632 : : (errcode(ERRCODE_SYNTAX_ERROR),
18633 : : errmsg("type modifier cannot have ORDER BY"),
18634 : : parser_errposition(@4)));
18635 : :
18636 : 0 : t->typmods = $3;
18637 : 0 : t->location = @1;
18638 : 0 : $$ = makeStringConstCast($6, @6, t);
18639 : : }
18640 : : | ConstTypename Sconst
18641 : : {
18642 : 2043 : $$ = makeStringConstCast($2, @2, $1);
18643 : : }
18644 : : | ConstInterval Sconst opt_interval
18645 : : {
18646 : 2204 : TypeName *t = $1;
18647 : :
18648 : 2204 : t->typmods = $3;
18649 : 2204 : $$ = makeStringConstCast($2, @2, t);
18650 : : }
18651 : : | ConstInterval '(' Iconst ')' Sconst
18652 : : {
18653 : 8 : TypeName *t = $1;
18654 : :
18655 : 8 : t->typmods = list_make2(makeIntConst(INTERVAL_FULL_RANGE, -1),
18656 : : makeIntConst($3, @3));
18657 : 8 : $$ = makeStringConstCast($5, @5, t);
18658 : : }
18659 : : | TRUE_P
18660 : : {
18661 : 19675 : $$ = makeBoolAConst(true, @1);
18662 : : }
18663 : : | FALSE_P
18664 : : {
18665 : 19723 : $$ = makeBoolAConst(false, @1);
18666 : : }
18667 : : | NULL_P
18668 : : {
18669 : 43651 : $$ = makeNullAConst(@1);
18670 : : }
18671 : : ;
18672 : :
18673 : 281002 : Iconst: ICONST { $$ = $1; };
18674 : 501553 : Sconst: SCONST { $$ = $1; };
18675 : :
18676 : 9463 : SignedIconst: Iconst { $$ = $1; }
18677 : 0 : | '+' Iconst { $$ = + $2; }
18678 : 188 : | '-' Iconst { $$ = - $2; }
18679 : : ;
18680 : :
18681 : : /* Role specifications */
18682 : : RoleId: RoleSpec
18683 : : {
18684 : 1347 : RoleSpec *spc = (RoleSpec *) $1;
18685 : :
18686 [ + + + + : 1347 : switch (spc->roletype)
+ - ]
18687 : : {
18688 : 1342 : case ROLESPEC_CSTRING:
18689 : 1342 : $$ = spc->rolename;
18690 : 1342 : break;
18691 : 2 : case ROLESPEC_PUBLIC:
18692 [ + - ]: 2 : ereport(ERROR,
18693 : : (errcode(ERRCODE_RESERVED_NAME),
18694 : : errmsg("role name \"%s\" is reserved",
18695 : : "public"),
18696 : : parser_errposition(@1)));
18697 : : break;
18698 : 1 : case ROLESPEC_SESSION_USER:
18699 [ + - ]: 1 : ereport(ERROR,
18700 : : (errcode(ERRCODE_RESERVED_NAME),
18701 : : errmsg("%s cannot be used as a role name here",
18702 : : "SESSION_USER"),
18703 : : parser_errposition(@1)));
18704 : : break;
18705 : 1 : case ROLESPEC_CURRENT_USER:
18706 [ + - ]: 1 : ereport(ERROR,
18707 : : (errcode(ERRCODE_RESERVED_NAME),
18708 : : errmsg("%s cannot be used as a role name here",
18709 : : "CURRENT_USER"),
18710 : : parser_errposition(@1)));
18711 : : break;
18712 : 1 : case ROLESPEC_CURRENT_ROLE:
18713 [ + - ]: 1 : ereport(ERROR,
18714 : : (errcode(ERRCODE_RESERVED_NAME),
18715 : : errmsg("%s cannot be used as a role name here",
18716 : : "CURRENT_ROLE"),
18717 : : parser_errposition(@1)));
18718 : : break;
18719 : : }
18720 : : }
18721 : : ;
18722 : :
18723 : : RoleSpec: NonReservedWord
18724 : : {
18725 : : /*
18726 : : * "public" and "none" are not keywords, but they must
18727 : : * be treated specially here.
18728 : : */
18729 : : RoleSpec *n;
18730 : :
18731 [ + + ]: 15899 : if (strcmp($1, "public") == 0)
18732 : : {
18733 : 7143 : n = (RoleSpec *) makeRoleSpec(ROLESPEC_PUBLIC, @1);
18734 : 7143 : n->roletype = ROLESPEC_PUBLIC;
18735 : : }
18736 [ + + ]: 8756 : else if (strcmp($1, "none") == 0)
18737 : : {
18738 [ + - ]: 13 : ereport(ERROR,
18739 : : (errcode(ERRCODE_RESERVED_NAME),
18740 : : errmsg("role name \"%s\" is reserved",
18741 : : "none"),
18742 : : parser_errposition(@1)));
18743 : : }
18744 : : else
18745 : : {
18746 : 8743 : n = makeRoleSpec(ROLESPEC_CSTRING, @1);
18747 : 8743 : n->rolename = pstrdup($1);
18748 : : }
18749 : 15886 : $$ = n;
18750 : : }
18751 : : | CURRENT_ROLE
18752 : : {
18753 : 84 : $$ = makeRoleSpec(ROLESPEC_CURRENT_ROLE, @1);
18754 : : }
18755 : : | CURRENT_USER
18756 : : {
18757 : 146 : $$ = makeRoleSpec(ROLESPEC_CURRENT_USER, @1);
18758 : : }
18759 : : | SESSION_USER
18760 : : {
18761 : 18 : $$ = makeRoleSpec(ROLESPEC_SESSION_USER, @1);
18762 : : }
18763 : : ;
18764 : :
18765 : : role_list: RoleSpec
18766 : 2134 : { $$ = list_make1($1); }
18767 : : | role_list ',' RoleSpec
18768 : 193 : { $$ = lappend($1, $3); }
18769 : : ;
18770 : :
18771 : :
18772 : : /*****************************************************************************
18773 : : *
18774 : : * PL/pgSQL extensions
18775 : : *
18776 : : * You'd think a PL/pgSQL "expression" should be just an a_expr, but
18777 : : * historically it can include just about anything that can follow SELECT.
18778 : : * Therefore the returned struct is a SelectStmt.
18779 : : *****************************************************************************/
18780 : :
18781 : : PLpgSQL_Expr: opt_distinct_clause opt_target_list
18782 : : from_clause where_clause
18783 : : group_clause having_clause window_clause
18784 : : opt_sort_clause opt_select_limit opt_for_locking_clause
18785 : : {
18786 : 25998 : SelectStmt *n = makeNode(SelectStmt);
18787 : :
18788 : 25998 : n->distinctClause = $1;
18789 : 25998 : n->targetList = $2;
18790 : 25998 : n->fromClause = $3;
18791 : 25998 : n->whereClause = $4;
18792 : 25998 : n->groupClause = ($5)->list;
18793 : 25998 : n->groupDistinct = ($5)->distinct;
18794 : 25998 : n->havingClause = $6;
18795 : 25998 : n->windowClause = $7;
18796 : 25998 : n->sortClause = $8;
18797 [ + + ]: 25998 : if ($9)
18798 : : {
18799 : 2 : n->limitOffset = $9->limitOffset;
18800 : 2 : n->limitCount = $9->limitCount;
18801 [ + - ]: 2 : if (!n->sortClause &&
18802 [ - + ]: 2 : $9->limitOption == LIMIT_OPTION_WITH_TIES)
18803 [ # # ]: 0 : ereport(ERROR,
18804 : : (errcode(ERRCODE_SYNTAX_ERROR),
18805 : : errmsg("WITH TIES cannot be specified without ORDER BY clause"),
18806 : : parser_errposition($9->optionLoc)));
18807 : 2 : n->limitOption = $9->limitOption;
18808 : : }
18809 : 25998 : n->lockingClause = $10;
18810 : 25998 : $$ = (Node *) n;
18811 : : }
18812 : : ;
18813 : :
18814 : : /*
18815 : : * PL/pgSQL Assignment statement: name opt_indirection := PLpgSQL_Expr
18816 : : */
18817 : :
18818 : : PLAssignStmt: plassign_target opt_indirection plassign_equals PLpgSQL_Expr
18819 : : {
18820 : 4266 : PLAssignStmt *n = makeNode(PLAssignStmt);
18821 : :
18822 : 4266 : n->name = $1;
18823 : 4266 : n->indirection = check_indirection($2, yyscanner);
18824 : : /* nnames will be filled by calling production */
18825 : 4266 : n->val = (SelectStmt *) $4;
18826 : 4266 : n->location = @1;
18827 : 4266 : $$ = (Node *) n;
18828 : : }
18829 : : ;
18830 : :
18831 : 4250 : plassign_target: ColId { $$ = $1; }
18832 : 16 : | PARAM { $$ = psprintf("$%d", $1); }
18833 : : ;
18834 : :
18835 : : plassign_equals: COLON_EQUALS
18836 : : | '='
18837 : : ;
18838 : :
18839 : :
18840 : : /*
18841 : : * Name classification hierarchy.
18842 : : *
18843 : : * IDENT is the lexeme returned by the lexer for identifiers that match
18844 : : * no known keyword. In most cases, we can accept certain keywords as
18845 : : * names, not only IDENTs. We prefer to accept as many such keywords
18846 : : * as possible to minimize the impact of "reserved words" on programmers.
18847 : : * So, we divide names into several possible classes. The classification
18848 : : * is chosen in part to make keywords acceptable as names wherever possible.
18849 : : */
18850 : :
18851 : : /* Column identifier --- names that can be column, table, etc names.
18852 : : */
18853 : 2208160 : ColId: IDENT { $$ = $1; }
18854 : 32997 : | unreserved_keyword { $$ = pstrdup($1); }
18855 : 3781 : | col_name_keyword { $$ = pstrdup($1); }
18856 : : ;
18857 : :
18858 : : /* Type/function identifier --- names that can be type or function names.
18859 : : */
18860 : 422061 : type_function_name: IDENT { $$ = $1; }
18861 : 39553 : | unreserved_keyword { $$ = pstrdup($1); }
18862 : 44 : | type_func_name_keyword { $$ = pstrdup($1); }
18863 : : ;
18864 : :
18865 : : /* Any not-fully-reserved word --- these names can be, eg, role names.
18866 : : */
18867 : 48562 : NonReservedWord: IDENT { $$ = $1; }
18868 : 20614 : | unreserved_keyword { $$ = pstrdup($1); }
18869 : 280 : | col_name_keyword { $$ = pstrdup($1); }
18870 : 3856 : | type_func_name_keyword { $$ = pstrdup($1); }
18871 : : ;
18872 : :
18873 : : /* Column label --- allowed labels in "AS" clauses.
18874 : : * This presently includes *all* Postgres keywords.
18875 : : */
18876 : 1170094 : ColLabel: IDENT { $$ = $1; }
18877 : 26011 : | unreserved_keyword { $$ = pstrdup($1); }
18878 : 190 : | col_name_keyword { $$ = pstrdup($1); }
18879 : 944 : | type_func_name_keyword { $$ = pstrdup($1); }
18880 : 5606 : | reserved_keyword { $$ = pstrdup($1); }
18881 : : ;
18882 : :
18883 : : /* Bare column label --- names that can be column labels without writing "AS".
18884 : : * This classification is orthogonal to the other keyword categories.
18885 : : */
18886 : 2290 : BareColLabel: IDENT { $$ = $1; }
18887 : 8 : | bare_label_keyword { $$ = pstrdup($1); }
18888 : : ;
18889 : :
18890 : :
18891 : : /*
18892 : : * Keyword category lists. Generally, every keyword present in
18893 : : * the Postgres grammar should appear in exactly one of these lists.
18894 : : *
18895 : : * Put a new keyword into the first list that it can go into without causing
18896 : : * shift or reduce conflicts. The earlier lists define "less reserved"
18897 : : * categories of keywords.
18898 : : *
18899 : : * Make sure that each keyword's category in kwlist.h matches where
18900 : : * it is listed here. (Someday we may be able to generate these lists and
18901 : : * kwlist.h's table from one source of truth.)
18902 : : */
18903 : :
18904 : : /* "Unreserved" keywords --- available for use as any kind of name.
18905 : : */
18906 : : unreserved_keyword:
18907 : : ABORT_P
18908 : : | ABSENT
18909 : : | ABSOLUTE_P
18910 : : | ACCESS
18911 : : | ACTION
18912 : : | ADD_P
18913 : : | ADMIN
18914 : : | AFTER
18915 : : | AGGREGATE
18916 : : | ALSO
18917 : : | ALTER
18918 : : | ALWAYS
18919 : : | ASENSITIVE
18920 : : | ASSERTION
18921 : : | ASSIGNMENT
18922 : : | AT
18923 : : | ATOMIC
18924 : : | ATTACH
18925 : : | ATTRIBUTE
18926 : : | BACKWARD
18927 : : | BEFORE
18928 : : | BEGIN_P
18929 : : | BREADTH
18930 : : | BY
18931 : : | CACHE
18932 : : | CALL
18933 : : | CALLED
18934 : : | CASCADE
18935 : : | CASCADED
18936 : : | CATALOG_P
18937 : : | CHAIN
18938 : : | CHARACTERISTICS
18939 : : | CHECKPOINT
18940 : : | CLASS
18941 : : | CLOSE
18942 : : | CLUSTER
18943 : : | COLUMNS
18944 : : | COMMENT
18945 : : | COMMENTS
18946 : : | COMMIT
18947 : : | COMMITTED
18948 : : | COMPRESSION
18949 : : | CONDITIONAL
18950 : : | CONFIGURATION
18951 : : | CONFLICT
18952 : : | CONNECTION
18953 : : | CONSTRAINTS
18954 : : | CONTENT_P
18955 : : | CONTINUE_P
18956 : : | CONVERSION_P
18957 : : | COPY
18958 : : | COST
18959 : : | CSV
18960 : : | CUBE
18961 : : | CURRENT_P
18962 : : | CURSOR
18963 : : | CYCLE
18964 : : | DATA_P
18965 : : | DATABASE
18966 : : | DAY_P
18967 : : | DEALLOCATE
18968 : : | DECLARE
18969 : : | DEFAULTS
18970 : : | DEFERRED
18971 : : | DEFINER
18972 : : | DELETE_P
18973 : : | DELIMITER
18974 : : | DELIMITERS
18975 : : | DEPENDS
18976 : : | DEPTH
18977 : : | DESTINATION
18978 : : | DETACH
18979 : : | DICTIONARY
18980 : : | DISABLE_P
18981 : : | DISCARD
18982 : : | DOCUMENT_P
18983 : : | DOMAIN_P
18984 : : | DOUBLE_P
18985 : : | DROP
18986 : : | EACH
18987 : : | EDGE
18988 : : | EMPTY_P
18989 : : | ENABLE_P
18990 : : | ENCODING
18991 : : | ENCRYPTED
18992 : : | ENFORCED
18993 : : | ENUM_P
18994 : : | ERROR_P
18995 : : | ESCAPE
18996 : : | EVENT
18997 : : | EXCLUDE
18998 : : | EXCLUDING
18999 : : | EXCLUSIVE
19000 : : | EXECUTE
19001 : : | EXPLAIN
19002 : : | EXPRESSION
19003 : : | EXTENSION
19004 : : | EXTERNAL
19005 : : | FAMILY
19006 : : | FILTER
19007 : : | FINALIZE
19008 : : | FIRST_P
19009 : : | FOLLOWING
19010 : : | FORCE
19011 : : | FORMAT
19012 : : | FORWARD
19013 : : | FUNCTION
19014 : : | FUNCTIONS
19015 : : | GENERATED
19016 : : | GLOBAL
19017 : : | GRANTED
19018 : : | GRAPH
19019 : : | GROUPS
19020 : : | HANDLER
19021 : : | HEADER_P
19022 : : | HOLD
19023 : : | HOUR_P
19024 : : | IDENTITY_P
19025 : : | IF_P
19026 : : | IGNORE_P
19027 : : | IMMEDIATE
19028 : : | IMMUTABLE
19029 : : | IMPLICIT_P
19030 : : | IMPORT_P
19031 : : | INCLUDE
19032 : : | INCLUDING
19033 : : | INCREMENT
19034 : : | INDENT
19035 : : | INDEX
19036 : : | INDEXES
19037 : : | INHERIT
19038 : : | INHERITS
19039 : : | INLINE_P
19040 : : | INPUT_P
19041 : : | INSENSITIVE
19042 : : | INSERT
19043 : : | INSTEAD
19044 : : | INVOKER
19045 : : | ISOLATION
19046 : : | KEEP
19047 : : | KEY
19048 : : | KEYS
19049 : : | LABEL
19050 : : | LANGUAGE
19051 : : | LARGE_P
19052 : : | LAST_P
19053 : : | LEAKPROOF
19054 : : | LEVEL
19055 : : | LISTEN
19056 : : | LOAD
19057 : : | LOCAL
19058 : : | LOCATION
19059 : : | LOCK_P
19060 : : | LOCKED
19061 : : | LOGGED
19062 : : | LSN_P
19063 : : | MAPPING
19064 : : | MATCH
19065 : : | MATCHED
19066 : : | MATERIALIZED
19067 : : | MAXVALUE
19068 : : | MERGE
19069 : : | METHOD
19070 : : | MINUTE_P
19071 : : | MINVALUE
19072 : : | MODE
19073 : : | MONTH_P
19074 : : | MOVE
19075 : : | NAME_P
19076 : : | NAMES
19077 : : | NESTED
19078 : : | NEW
19079 : : | NEXT
19080 : : | NFC
19081 : : | NFD
19082 : : | NFKC
19083 : : | NFKD
19084 : : | NO
19085 : : | NODE
19086 : : | NORMALIZED
19087 : : | NOTHING
19088 : : | NOTIFY
19089 : : | NOWAIT
19090 : : | NULLS_P
19091 : : | OBJECT_P
19092 : : | OBJECTS_P
19093 : : | OF
19094 : : | OFF
19095 : : | OIDS
19096 : : | OLD
19097 : : | OMIT
19098 : : | OPERATOR
19099 : : | OPTION
19100 : : | OPTIONS
19101 : : | ORDINALITY
19102 : : | OTHERS
19103 : : | OVER
19104 : : | OVERRIDING
19105 : : | OWNED
19106 : : | OWNER
19107 : : | PARALLEL
19108 : : | PARAMETER
19109 : : | PARSER
19110 : : | PARTIAL
19111 : : | PARTITION
19112 : : | PARTITIONS
19113 : : | PASSING
19114 : : | PASSWORD
19115 : : | PATH
19116 : : | PERIOD
19117 : : | PLAN
19118 : : | PLANS
19119 : : | POLICY
19120 : : | PORTION
19121 : : | PRECEDING
19122 : : | PREPARE
19123 : : | PREPARED
19124 : : | PRESERVE
19125 : : | PRIOR
19126 : : | PRIVILEGES
19127 : : | PROCEDURAL
19128 : : | PROCEDURE
19129 : : | PROCEDURES
19130 : : | PROGRAM
19131 : : | PROPERTIES
19132 : : | PROPERTY
19133 : : | PUBLICATION
19134 : : | QUOTE
19135 : : | QUOTES
19136 : : | RANGE
19137 : : | READ
19138 : : | REASSIGN
19139 : : | RECURSIVE
19140 : : | REF_P
19141 : : | REFERENCING
19142 : : | REFRESH
19143 : : | REINDEX
19144 : : | RELATIONSHIP
19145 : : | RELATIVE_P
19146 : : | RELEASE
19147 : : | RENAME
19148 : : | REPACK
19149 : : | REPEATABLE
19150 : : | REPLACE
19151 : : | REPLICA
19152 : : | RESET
19153 : : | RESPECT_P
19154 : : | RESTART
19155 : : | RESTRICT
19156 : : | RETURN
19157 : : | RETURNS
19158 : : | REVOKE
19159 : : | ROLE
19160 : : | ROLLBACK
19161 : : | ROLLUP
19162 : : | ROUTINE
19163 : : | ROUTINES
19164 : : | ROWS
19165 : : | RULE
19166 : : | SAVEPOINT
19167 : : | SCALAR
19168 : : | SCHEMA
19169 : : | SCHEMAS
19170 : : | SCROLL
19171 : : | SEARCH
19172 : : | SECOND_P
19173 : : | SECURITY
19174 : : | SEQUENCE
19175 : : | SEQUENCES
19176 : : | SERIALIZABLE
19177 : : | SERVER
19178 : : | SESSION
19179 : : | SET
19180 : : | SETS
19181 : : | SHARE
19182 : : | SHOW
19183 : : | SIMPLE
19184 : : | SKIP
19185 : : | SNAPSHOT
19186 : : | SOURCE
19187 : : | SPLIT
19188 : : | SQL_P
19189 : : | STABLE
19190 : : | STANDALONE_P
19191 : : | START
19192 : : | STATEMENT
19193 : : | STATISTICS
19194 : : | STDIN
19195 : : | STDOUT
19196 : : | STORAGE
19197 : : | STORED
19198 : : | STRICT_P
19199 : : | STRING_P
19200 : : | STRIP_P
19201 : : | SUBSCRIPTION
19202 : : | SUPPORT
19203 : : | SYSID
19204 : : | SYSTEM_P
19205 : : | TABLES
19206 : : | TABLESPACE
19207 : : | TARGET
19208 : : | TEMP
19209 : : | TEMPLATE
19210 : : | TEMPORARY
19211 : : | TEXT_P
19212 : : | TIES
19213 : : | TRANSACTION
19214 : : | TRANSFORM
19215 : : | TRIGGER
19216 : : | TRUNCATE
19217 : : | TRUSTED
19218 : : | TYPE_P
19219 : : | TYPES_P
19220 : : | UESCAPE
19221 : : | UNBOUNDED
19222 : : | UNCOMMITTED
19223 : : | UNCONDITIONAL
19224 : : | UNENCRYPTED
19225 : : | UNKNOWN
19226 : : | UNLISTEN
19227 : : | UNLOGGED
19228 : : | UNTIL
19229 : : | UPDATE
19230 : : | VACUUM
19231 : : | VALID
19232 : : | VALIDATE
19233 : : | VALIDATOR
19234 : : | VALUE_P
19235 : : | VARYING
19236 : : | VERSION_P
19237 : : | VERTEX
19238 : : | VIEW
19239 : : | VIEWS
19240 : : | VIRTUAL
19241 : : | VOLATILE
19242 : : | WAIT
19243 : : | WHITESPACE_P
19244 : : | WITHIN
19245 : : | WITHOUT
19246 : : | WORK
19247 : : | WRAPPER
19248 : : | WRITE
19249 : : | XML_P
19250 : : | YEAR_P
19251 : : | YES_P
19252 : : | ZONE
19253 : : ;
19254 : :
19255 : : /* Column identifier --- keywords that can be column, table, etc names.
19256 : : *
19257 : : * Many of these keywords will in fact be recognized as type or function
19258 : : * names too; but they have special productions for the purpose, and so
19259 : : * can't be treated as "generic" type or function names.
19260 : : *
19261 : : * The type names appearing here are not usable as function names
19262 : : * because they can be followed by '(' in typename productions, which
19263 : : * looks too much like a function call for an LR(1) parser.
19264 : : */
19265 : : col_name_keyword:
19266 : : BETWEEN
19267 : : | BIGINT
19268 : : | BIT
19269 : : | BOOLEAN_P
19270 : : | CHAR_P
19271 : : | CHARACTER
19272 : : | COALESCE
19273 : : | DEC
19274 : : | DECIMAL_P
19275 : : | EXISTS
19276 : : | EXTRACT
19277 : : | FLOAT_P
19278 : : | GRAPH_TABLE
19279 : : | GREATEST
19280 : : | GROUPING
19281 : : | INOUT
19282 : : | INT_P
19283 : : | INTEGER
19284 : : | INTERVAL
19285 : : | JSON
19286 : : | JSON_ARRAY
19287 : : | JSON_ARRAYAGG
19288 : : | JSON_EXISTS
19289 : : | JSON_OBJECT
19290 : : | JSON_OBJECTAGG
19291 : : | JSON_QUERY
19292 : : | JSON_SCALAR
19293 : : | JSON_SERIALIZE
19294 : : | JSON_TABLE
19295 : : | JSON_VALUE
19296 : : | LEAST
19297 : : | MERGE_ACTION
19298 : : | NATIONAL
19299 : : | NCHAR
19300 : : | NONE
19301 : : | NORMALIZE
19302 : : | NULLIF
19303 : : | NUMERIC
19304 : : | OUT_P
19305 : : | OVERLAY
19306 : : | POSITION
19307 : : | PRECISION
19308 : : | REAL
19309 : : | ROW
19310 : : | SETOF
19311 : : | SMALLINT
19312 : : | SUBSTRING
19313 : : | TIME
19314 : : | TIMESTAMP
19315 : : | TREAT
19316 : : | TRIM
19317 : : | VALUES
19318 : : | VARCHAR
19319 : : | XMLATTRIBUTES
19320 : : | XMLCONCAT
19321 : : | XMLELEMENT
19322 : : | XMLEXISTS
19323 : : | XMLFOREST
19324 : : | XMLNAMESPACES
19325 : : | XMLPARSE
19326 : : | XMLPI
19327 : : | XMLROOT
19328 : : | XMLSERIALIZE
19329 : : | XMLTABLE
19330 : : ;
19331 : :
19332 : : /* Type/function identifier --- keywords that can be type or function names.
19333 : : *
19334 : : * Most of these are keywords that are used as operators in expressions;
19335 : : * in general such keywords can't be column names because they would be
19336 : : * ambiguous with variables, but they are unambiguous as function identifiers.
19337 : : *
19338 : : * Do not include POSITION, SUBSTRING, etc here since they have explicit
19339 : : * productions in a_expr to support the goofy SQL9x argument syntax.
19340 : : * - thomas 2000-11-28
19341 : : */
19342 : : type_func_name_keyword:
19343 : : AUTHORIZATION
19344 : : | BINARY
19345 : : | COLLATION
19346 : : | CONCURRENTLY
19347 : : | CROSS
19348 : : | CURRENT_SCHEMA
19349 : : | FREEZE
19350 : : | FULL
19351 : : | ILIKE
19352 : : | INNER_P
19353 : : | IS
19354 : : | ISNULL
19355 : : | JOIN
19356 : : | LEFT
19357 : : | LIKE
19358 : : | NATURAL
19359 : : | NOTNULL
19360 : : | OUTER_P
19361 : : | OVERLAPS
19362 : : | RIGHT
19363 : : | SIMILAR
19364 : : | TABLESAMPLE
19365 : : | VERBOSE
19366 : : ;
19367 : :
19368 : : /* Reserved keyword --- these keywords are usable only as a ColLabel.
19369 : : *
19370 : : * Keywords appear here if they could not be distinguished from variable,
19371 : : * type, or function names in some contexts. Don't put things here unless
19372 : : * forced to.
19373 : : */
19374 : : reserved_keyword:
19375 : : ALL
19376 : : | ANALYSE
19377 : : | ANALYZE
19378 : : | AND
19379 : : | ANY
19380 : : | ARRAY
19381 : : | AS
19382 : : | ASC
19383 : : | ASYMMETRIC
19384 : : | BOTH
19385 : : | CASE
19386 : : | CAST
19387 : : | CHECK
19388 : : | COLLATE
19389 : : | COLUMN
19390 : : | CONSTRAINT
19391 : : | CREATE
19392 : : | CURRENT_CATALOG
19393 : : | CURRENT_DATE
19394 : : | CURRENT_ROLE
19395 : : | CURRENT_TIME
19396 : : | CURRENT_TIMESTAMP
19397 : : | CURRENT_USER
19398 : : | DEFAULT
19399 : : | DEFERRABLE
19400 : : | DESC
19401 : : | DISTINCT
19402 : : | DO
19403 : : | ELSE
19404 : : | END_P
19405 : : | EXCEPT
19406 : : | FALSE_P
19407 : : | FETCH
19408 : : | FOR
19409 : : | FOREIGN
19410 : : | FROM
19411 : : | GRANT
19412 : : | GROUP_P
19413 : : | HAVING
19414 : : | IN_P
19415 : : | INITIALLY
19416 : : | INTERSECT
19417 : : | INTO
19418 : : | LATERAL_P
19419 : : | LEADING
19420 : : | LIMIT
19421 : : | LOCALTIME
19422 : : | LOCALTIMESTAMP
19423 : : | NOT
19424 : : | NULL_P
19425 : : | OFFSET
19426 : : | ON
19427 : : | ONLY
19428 : : | OR
19429 : : | ORDER
19430 : : | PLACING
19431 : : | PRIMARY
19432 : : | REFERENCES
19433 : : | RETURNING
19434 : : | SELECT
19435 : : | SESSION_USER
19436 : : | SOME
19437 : : | SYMMETRIC
19438 : : | SYSTEM_USER
19439 : : | TABLE
19440 : : | THEN
19441 : : | TO
19442 : : | TRAILING
19443 : : | TRUE_P
19444 : : | UNION
19445 : : | UNIQUE
19446 : : | USER
19447 : : | USING
19448 : : | VARIADIC
19449 : : | WHEN
19450 : : | WHERE
19451 : : | WINDOW
19452 : : | WITH
19453 : : ;
19454 : :
19455 : : /*
19456 : : * While all keywords can be used as column labels when preceded by AS,
19457 : : * not all of them can be used as a "bare" column label without AS.
19458 : : * Those that can be used as a bare label must be listed here,
19459 : : * in addition to appearing in one of the category lists above.
19460 : : *
19461 : : * Always add a new keyword to this list if possible. Mark it BARE_LABEL
19462 : : * in kwlist.h if it is included here, or AS_LABEL if it is not.
19463 : : */
19464 : : bare_label_keyword:
19465 : : ABORT_P
19466 : : | ABSENT
19467 : : | ABSOLUTE_P
19468 : : | ACCESS
19469 : : | ACTION
19470 : : | ADD_P
19471 : : | ADMIN
19472 : : | AFTER
19473 : : | AGGREGATE
19474 : : | ALL
19475 : : | ALSO
19476 : : | ALTER
19477 : : | ALWAYS
19478 : : | ANALYSE
19479 : : | ANALYZE
19480 : : | AND
19481 : : | ANY
19482 : : | ASC
19483 : : | ASENSITIVE
19484 : : | ASSERTION
19485 : : | ASSIGNMENT
19486 : : | ASYMMETRIC
19487 : : | AT
19488 : : | ATOMIC
19489 : : | ATTACH
19490 : : | ATTRIBUTE
19491 : : | AUTHORIZATION
19492 : : | BACKWARD
19493 : : | BEFORE
19494 : : | BEGIN_P
19495 : : | BETWEEN
19496 : : | BIGINT
19497 : : | BINARY
19498 : : | BIT
19499 : : | BOOLEAN_P
19500 : : | BOTH
19501 : : | BREADTH
19502 : : | BY
19503 : : | CACHE
19504 : : | CALL
19505 : : | CALLED
19506 : : | CASCADE
19507 : : | CASCADED
19508 : : | CASE
19509 : : | CAST
19510 : : | CATALOG_P
19511 : : | CHAIN
19512 : : | CHARACTERISTICS
19513 : : | CHECK
19514 : : | CHECKPOINT
19515 : : | CLASS
19516 : : | CLOSE
19517 : : | CLUSTER
19518 : : | COALESCE
19519 : : | COLLATE
19520 : : | COLLATION
19521 : : | COLUMN
19522 : : | COLUMNS
19523 : : | COMMENT
19524 : : | COMMENTS
19525 : : | COMMIT
19526 : : | COMMITTED
19527 : : | COMPRESSION
19528 : : | CONCURRENTLY
19529 : : | CONDITIONAL
19530 : : | CONFIGURATION
19531 : : | CONFLICT
19532 : : | CONNECTION
19533 : : | CONSTRAINT
19534 : : | CONSTRAINTS
19535 : : | CONTENT_P
19536 : : | CONTINUE_P
19537 : : | CONVERSION_P
19538 : : | COPY
19539 : : | COST
19540 : : | CROSS
19541 : : | CSV
19542 : : | CUBE
19543 : : | CURRENT_P
19544 : : | CURRENT_CATALOG
19545 : : | CURRENT_DATE
19546 : : | CURRENT_ROLE
19547 : : | CURRENT_SCHEMA
19548 : : | CURRENT_TIME
19549 : : | CURRENT_TIMESTAMP
19550 : : | CURRENT_USER
19551 : : | CURSOR
19552 : : | CYCLE
19553 : : | DATA_P
19554 : : | DATABASE
19555 : : | DEALLOCATE
19556 : : | DEC
19557 : : | DECIMAL_P
19558 : : | DECLARE
19559 : : | DEFAULT
19560 : : | DEFAULTS
19561 : : | DEFERRABLE
19562 : : | DEFERRED
19563 : : | DEFINER
19564 : : | DELETE_P
19565 : : | DELIMITER
19566 : : | DELIMITERS
19567 : : | DEPENDS
19568 : : | DEPTH
19569 : : | DESC
19570 : : | DESTINATION
19571 : : | DETACH
19572 : : | DICTIONARY
19573 : : | DISABLE_P
19574 : : | DISCARD
19575 : : | DISTINCT
19576 : : | DO
19577 : : | DOCUMENT_P
19578 : : | DOMAIN_P
19579 : : | DOUBLE_P
19580 : : | DROP
19581 : : | EACH
19582 : : | EDGE
19583 : : | ELSE
19584 : : | EMPTY_P
19585 : : | ENABLE_P
19586 : : | ENCODING
19587 : : | ENCRYPTED
19588 : : | END_P
19589 : : | ENFORCED
19590 : : | ENUM_P
19591 : : | ERROR_P
19592 : : | ESCAPE
19593 : : | EVENT
19594 : : | EXCLUDE
19595 : : | EXCLUDING
19596 : : | EXCLUSIVE
19597 : : | EXECUTE
19598 : : | EXISTS
19599 : : | EXPLAIN
19600 : : | EXPRESSION
19601 : : | EXTENSION
19602 : : | EXTERNAL
19603 : : | EXTRACT
19604 : : | FALSE_P
19605 : : | FAMILY
19606 : : | FINALIZE
19607 : : | FIRST_P
19608 : : | FLOAT_P
19609 : : | FOLLOWING
19610 : : | FORCE
19611 : : | FOREIGN
19612 : : | FORMAT
19613 : : | FORWARD
19614 : : | FREEZE
19615 : : | FULL
19616 : : | FUNCTION
19617 : : | FUNCTIONS
19618 : : | GENERATED
19619 : : | GLOBAL
19620 : : | GRANTED
19621 : : | GRAPH
19622 : : | GRAPH_TABLE
19623 : : | GREATEST
19624 : : | GROUPING
19625 : : | GROUPS
19626 : : | HANDLER
19627 : : | HEADER_P
19628 : : | HOLD
19629 : : | IDENTITY_P
19630 : : | IF_P
19631 : : | ILIKE
19632 : : | IMMEDIATE
19633 : : | IMMUTABLE
19634 : : | IMPLICIT_P
19635 : : | IMPORT_P
19636 : : | IN_P
19637 : : | INCLUDE
19638 : : | INCLUDING
19639 : : | INCREMENT
19640 : : | INDENT
19641 : : | INDEX
19642 : : | INDEXES
19643 : : | INHERIT
19644 : : | INHERITS
19645 : : | INITIALLY
19646 : : | INLINE_P
19647 : : | INNER_P
19648 : : | INOUT
19649 : : | INPUT_P
19650 : : | INSENSITIVE
19651 : : | INSERT
19652 : : | INSTEAD
19653 : : | INT_P
19654 : : | INTEGER
19655 : : | INTERVAL
19656 : : | INVOKER
19657 : : | IS
19658 : : | ISOLATION
19659 : : | JOIN
19660 : : | JSON
19661 : : | JSON_ARRAY
19662 : : | JSON_ARRAYAGG
19663 : : | JSON_EXISTS
19664 : : | JSON_OBJECT
19665 : : | JSON_OBJECTAGG
19666 : : | JSON_QUERY
19667 : : | JSON_SCALAR
19668 : : | JSON_SERIALIZE
19669 : : | JSON_TABLE
19670 : : | JSON_VALUE
19671 : : | KEEP
19672 : : | KEY
19673 : : | KEYS
19674 : : | LABEL
19675 : : | LANGUAGE
19676 : : | LARGE_P
19677 : : | LAST_P
19678 : : | LATERAL_P
19679 : : | LEADING
19680 : : | LEAKPROOF
19681 : : | LEAST
19682 : : | LEFT
19683 : : | LEVEL
19684 : : | LIKE
19685 : : | LISTEN
19686 : : | LOAD
19687 : : | LOCAL
19688 : : | LOCALTIME
19689 : : | LOCALTIMESTAMP
19690 : : | LOCATION
19691 : : | LOCK_P
19692 : : | LOCKED
19693 : : | LOGGED
19694 : : | LSN_P
19695 : : | MAPPING
19696 : : | MATCH
19697 : : | MATCHED
19698 : : | MATERIALIZED
19699 : : | MAXVALUE
19700 : : | MERGE
19701 : : | MERGE_ACTION
19702 : : | METHOD
19703 : : | MINVALUE
19704 : : | MODE
19705 : : | MOVE
19706 : : | NAME_P
19707 : : | NAMES
19708 : : | NATIONAL
19709 : : | NATURAL
19710 : : | NCHAR
19711 : : | NESTED
19712 : : | NEW
19713 : : | NEXT
19714 : : | NFC
19715 : : | NFD
19716 : : | NFKC
19717 : : | NFKD
19718 : : | NO
19719 : : | NODE
19720 : : | NONE
19721 : : | NORMALIZE
19722 : : | NORMALIZED
19723 : : | NOT
19724 : : | NOTHING
19725 : : | NOTIFY
19726 : : | NOWAIT
19727 : : | NULL_P
19728 : : | NULLIF
19729 : : | NULLS_P
19730 : : | NUMERIC
19731 : : | OBJECT_P
19732 : : | OBJECTS_P
19733 : : | OF
19734 : : | OFF
19735 : : | OIDS
19736 : : | OLD
19737 : : | OMIT
19738 : : | ONLY
19739 : : | OPERATOR
19740 : : | OPTION
19741 : : | OPTIONS
19742 : : | OR
19743 : : | ORDINALITY
19744 : : | OTHERS
19745 : : | OUT_P
19746 : : | OUTER_P
19747 : : | OVERLAY
19748 : : | OVERRIDING
19749 : : | OWNED
19750 : : | OWNER
19751 : : | PARALLEL
19752 : : | PARAMETER
19753 : : | PARSER
19754 : : | PARTIAL
19755 : : | PARTITION
19756 : : | PARTITIONS
19757 : : | PASSING
19758 : : | PASSWORD
19759 : : | PATH
19760 : : | PERIOD
19761 : : | PLACING
19762 : : | PLAN
19763 : : | PLANS
19764 : : | POLICY
19765 : : | PORTION
19766 : : | POSITION
19767 : : | PRECEDING
19768 : : | PREPARE
19769 : : | PREPARED
19770 : : | PRESERVE
19771 : : | PRIMARY
19772 : : | PRIOR
19773 : : | PRIVILEGES
19774 : : | PROCEDURAL
19775 : : | PROCEDURE
19776 : : | PROCEDURES
19777 : : | PROGRAM
19778 : : | PROPERTIES
19779 : : | PROPERTY
19780 : : | PUBLICATION
19781 : : | QUOTE
19782 : : | QUOTES
19783 : : | RANGE
19784 : : | READ
19785 : : | REAL
19786 : : | REASSIGN
19787 : : | RECURSIVE
19788 : : | REF_P
19789 : : | REFERENCES
19790 : : | REFERENCING
19791 : : | REFRESH
19792 : : | REINDEX
19793 : : | RELATIONSHIP
19794 : : | RELATIVE_P
19795 : : | RELEASE
19796 : : | RENAME
19797 : : | REPACK
19798 : : | REPEATABLE
19799 : : | REPLACE
19800 : : | REPLICA
19801 : : | RESET
19802 : : | RESTART
19803 : : | RESTRICT
19804 : : | RETURN
19805 : : | RETURNS
19806 : : | REVOKE
19807 : : | RIGHT
19808 : : | ROLE
19809 : : | ROLLBACK
19810 : : | ROLLUP
19811 : : | ROUTINE
19812 : : | ROUTINES
19813 : : | ROW
19814 : : | ROWS
19815 : : | RULE
19816 : : | SAVEPOINT
19817 : : | SCALAR
19818 : : | SCHEMA
19819 : : | SCHEMAS
19820 : : | SCROLL
19821 : : | SEARCH
19822 : : | SECURITY
19823 : : | SELECT
19824 : : | SEQUENCE
19825 : : | SEQUENCES
19826 : : | SERIALIZABLE
19827 : : | SERVER
19828 : : | SESSION
19829 : : | SESSION_USER
19830 : : | SET
19831 : : | SETOF
19832 : : | SETS
19833 : : | SHARE
19834 : : | SHOW
19835 : : | SIMILAR
19836 : : | SIMPLE
19837 : : | SKIP
19838 : : | SMALLINT
19839 : : | SNAPSHOT
19840 : : | SOME
19841 : : | SOURCE
19842 : : | SPLIT
19843 : : | SQL_P
19844 : : | STABLE
19845 : : | STANDALONE_P
19846 : : | START
19847 : : | STATEMENT
19848 : : | STATISTICS
19849 : : | STDIN
19850 : : | STDOUT
19851 : : | STORAGE
19852 : : | STORED
19853 : : | STRICT_P
19854 : : | STRING_P
19855 : : | STRIP_P
19856 : : | SUBSCRIPTION
19857 : : | SUBSTRING
19858 : : | SUPPORT
19859 : : | SYMMETRIC
19860 : : | SYSID
19861 : : | SYSTEM_P
19862 : : | SYSTEM_USER
19863 : : | TABLE
19864 : : | TABLES
19865 : : | TABLESAMPLE
19866 : : | TABLESPACE
19867 : : | TARGET
19868 : : | TEMP
19869 : : | TEMPLATE
19870 : : | TEMPORARY
19871 : : | TEXT_P
19872 : : | THEN
19873 : : | TIES
19874 : : | TIME
19875 : : | TIMESTAMP
19876 : : | TRAILING
19877 : : | TRANSACTION
19878 : : | TRANSFORM
19879 : : | TREAT
19880 : : | TRIGGER
19881 : : | TRIM
19882 : : | TRUE_P
19883 : : | TRUNCATE
19884 : : | TRUSTED
19885 : : | TYPE_P
19886 : : | TYPES_P
19887 : : | UESCAPE
19888 : : | UNBOUNDED
19889 : : | UNCOMMITTED
19890 : : | UNCONDITIONAL
19891 : : | UNENCRYPTED
19892 : : | UNIQUE
19893 : : | UNKNOWN
19894 : : | UNLISTEN
19895 : : | UNLOGGED
19896 : : | UNTIL
19897 : : | UPDATE
19898 : : | USER
19899 : : | USING
19900 : : | VACUUM
19901 : : | VALID
19902 : : | VALIDATE
19903 : : | VALIDATOR
19904 : : | VALUE_P
19905 : : | VALUES
19906 : : | VARCHAR
19907 : : | VARIADIC
19908 : : | VERBOSE
19909 : : | VERSION_P
19910 : : | VERTEX
19911 : : | VIEW
19912 : : | VIEWS
19913 : : | VIRTUAL
19914 : : | VOLATILE
19915 : : | WAIT
19916 : : | WHEN
19917 : : | WHITESPACE_P
19918 : : | WORK
19919 : : | WRAPPER
19920 : : | WRITE
19921 : : | XML_P
19922 : : | XMLATTRIBUTES
19923 : : | XMLCONCAT
19924 : : | XMLELEMENT
19925 : : | XMLEXISTS
19926 : : | XMLFOREST
19927 : : | XMLNAMESPACES
19928 : : | XMLPARSE
19929 : : | XMLPI
19930 : : | XMLROOT
19931 : : | XMLSERIALIZE
19932 : : | XMLTABLE
19933 : : | YES_P
19934 : : | ZONE
19935 : : ;
19936 : :
19937 : : %%
19938 : :
19939 : : /*
19940 : : * The signature of this function is required by bison. However, we
19941 : : * ignore the passed yylloc and instead use the last token position
19942 : : * available from the scanner.
19943 : : */
19944 : : static void
19945 : 477 : base_yyerror(YYLTYPE *yylloc, core_yyscan_t yyscanner, const char *msg)
19946 : : {
19947 : 477 : parser_yyerror(msg);
19948 : : }
19949 : :
19950 : : static RawStmt *
19951 : 524486 : makeRawStmt(Node *stmt, int stmt_location)
19952 : : {
19953 : 524486 : RawStmt *rs = makeNode(RawStmt);
19954 : :
19955 : 524486 : rs->stmt = stmt;
19956 : 524486 : rs->stmt_location = stmt_location;
19957 : 524486 : rs->stmt_len = 0; /* might get changed later */
19958 : 524486 : return rs;
19959 : : }
19960 : :
19961 : : /* Adjust a RawStmt to reflect that it doesn't run to the end of the string */
19962 : : static void
19963 : 392462 : updateRawStmtEnd(RawStmt *rs, int end_location)
19964 : : {
19965 : : /*
19966 : : * If we already set the length, don't change it. This is for situations
19967 : : * like "select foo ;; select bar" where the same statement will be last
19968 : : * in the string for more than one semicolon.
19969 : : */
19970 [ + + ]: 392462 : if (rs->stmt_len > 0)
19971 : 301 : return;
19972 : :
19973 : : /* OK, update length of RawStmt */
19974 : 392161 : rs->stmt_len = end_location - rs->stmt_location;
19975 : : }
19976 : :
19977 : : static Node *
19978 : 1174959 : makeColumnRef(char *colname, List *indirection,
19979 : : int location, core_yyscan_t yyscanner)
19980 : : {
19981 : : /*
19982 : : * Generate a ColumnRef node, with an A_Indirection node added if there is
19983 : : * any subscripting in the specified indirection list. However, any field
19984 : : * selection at the start of the indirection list must be transposed into
19985 : : * the "fields" part of the ColumnRef node.
19986 : : */
19987 : 1174959 : ColumnRef *c = makeNode(ColumnRef);
19988 : 1174959 : int nfields = 0;
19989 : : ListCell *l;
19990 : :
19991 : 1174959 : c->location = location;
19992 [ + + + + : 1874270 : foreach(l, indirection)
+ + ]
19993 : : {
19994 [ + + ]: 706009 : if (IsA(lfirst(l), A_Indices))
19995 : : {
19996 : 6698 : A_Indirection *i = makeNode(A_Indirection);
19997 : :
19998 [ + + ]: 6698 : if (nfields == 0)
19999 : : {
20000 : : /* easy case - all indirection goes to A_Indirection */
20001 : 4846 : c->fields = list_make1(makeString(colname));
20002 : 4846 : i->indirection = check_indirection(indirection, yyscanner);
20003 : : }
20004 : : else
20005 : : {
20006 : : /* got to split the list in two */
20007 : 1852 : i->indirection = check_indirection(list_copy_tail(indirection,
20008 : : nfields),
20009 : : yyscanner);
20010 : 1852 : indirection = list_truncate(indirection, nfields);
20011 : 1852 : c->fields = lcons(makeString(colname), indirection);
20012 : : }
20013 : 6698 : i->arg = (Node *) c;
20014 : 6698 : return (Node *) i;
20015 : : }
20016 [ + + ]: 699311 : else if (IsA(lfirst(l), A_Star))
20017 : : {
20018 : : /* We only allow '*' at the end of a ColumnRef */
20019 [ - + ]: 3775 : if (lnext(indirection, l) != NULL)
20020 : 0 : parser_yyerror("improper use of \"*\"");
20021 : : }
20022 : 699311 : nfields++;
20023 : : }
20024 : : /* No subscripting, so all indirection gets added to field list */
20025 : 1168261 : c->fields = lcons(makeString(colname), indirection);
20026 : 1168261 : return (Node *) c;
20027 : : }
20028 : :
20029 : : static Node *
20030 : 197389 : makeTypeCast(Node *arg, TypeName *typename, int location)
20031 : : {
20032 : 197389 : TypeCast *n = makeNode(TypeCast);
20033 : :
20034 : 197389 : n->arg = arg;
20035 : 197389 : n->typeName = typename;
20036 : 197389 : n->location = location;
20037 : 197389 : return (Node *) n;
20038 : : }
20039 : :
20040 : : static Node *
20041 : 10684 : makeStringConstCast(char *str, int location, TypeName *typename)
20042 : : {
20043 : 10684 : Node *s = makeStringConst(str, location);
20044 : :
20045 : 10684 : return makeTypeCast(s, typename, -1);
20046 : : }
20047 : :
20048 : : static Node *
20049 : 271206 : makeIntConst(int val, int location)
20050 : : {
20051 : 271206 : A_Const *n = makeNode(A_Const);
20052 : :
20053 : 271206 : n->val.ival.type = T_Integer;
20054 : 271206 : n->val.ival.ival = val;
20055 : 271206 : n->location = location;
20056 : :
20057 : 271206 : return (Node *) n;
20058 : : }
20059 : :
20060 : : static Node *
20061 : 8309 : makeFloatConst(char *str, int location)
20062 : : {
20063 : 8309 : A_Const *n = makeNode(A_Const);
20064 : :
20065 : 8309 : n->val.fval.type = T_Float;
20066 : 8309 : n->val.fval.fval = str;
20067 : 8309 : n->location = location;
20068 : :
20069 : 8309 : return (Node *) n;
20070 : : }
20071 : :
20072 : : static Node *
20073 : 39571 : makeBoolAConst(bool state, int location)
20074 : : {
20075 : 39571 : A_Const *n = makeNode(A_Const);
20076 : :
20077 : 39571 : n->val.boolval.type = T_Boolean;
20078 : 39571 : n->val.boolval.boolval = state;
20079 : 39571 : n->location = location;
20080 : :
20081 : 39571 : return (Node *) n;
20082 : : }
20083 : :
20084 : : static Node *
20085 : 2727 : makeBitStringConst(char *str, int location)
20086 : : {
20087 : 2727 : A_Const *n = makeNode(A_Const);
20088 : :
20089 : 2727 : n->val.bsval.type = T_BitString;
20090 : 2727 : n->val.bsval.bsval = str;
20091 : 2727 : n->location = location;
20092 : :
20093 : 2727 : return (Node *) n;
20094 : : }
20095 : :
20096 : : static Node *
20097 : 43698 : makeNullAConst(int location)
20098 : : {
20099 : 43698 : A_Const *n = makeNode(A_Const);
20100 : :
20101 : 43698 : n->isnull = true;
20102 : 43698 : n->location = location;
20103 : :
20104 : 43698 : return (Node *) n;
20105 : : }
20106 : :
20107 : : static Node *
20108 : 3140 : makeAConst(Node *v, int location)
20109 : : {
20110 : : Node *n;
20111 : :
20112 [ + + - ]: 3140 : switch (v->type)
20113 : : {
20114 : 136 : case T_Float:
20115 : 136 : n = makeFloatConst(castNode(Float, v)->fval, location);
20116 : 136 : break;
20117 : :
20118 : 3004 : case T_Integer:
20119 : 3004 : n = makeIntConst(castNode(Integer, v)->ival, location);
20120 : 3004 : break;
20121 : :
20122 : 0 : default:
20123 : : /* currently not used */
20124 : : Assert(false);
20125 : 0 : n = NULL;
20126 : : }
20127 : :
20128 : 3140 : return n;
20129 : : }
20130 : :
20131 : : /* makeRoleSpec
20132 : : * Create a RoleSpec with the given type
20133 : : */
20134 : : static RoleSpec *
20135 : 16633 : makeRoleSpec(RoleSpecType type, int location)
20136 : : {
20137 : 16633 : RoleSpec *spec = makeNode(RoleSpec);
20138 : :
20139 : 16633 : spec->roletype = type;
20140 : 16633 : spec->location = location;
20141 : :
20142 : 16633 : return spec;
20143 : : }
20144 : :
20145 : : /* check_qualified_name --- check the result of qualified_name production
20146 : : *
20147 : : * It's easiest to let the grammar production for qualified_name allow
20148 : : * subscripts and '*', which we then must reject here.
20149 : : */
20150 : : static void
20151 : 161139 : check_qualified_name(List *names, core_yyscan_t yyscanner)
20152 : : {
20153 : : ListCell *i;
20154 : :
20155 [ + - + + : 322278 : foreach(i, names)
+ + ]
20156 : : {
20157 [ - + ]: 161139 : if (!IsA(lfirst(i), String))
20158 : 0 : parser_yyerror("syntax error");
20159 : : }
20160 : 161139 : }
20161 : :
20162 : : /* check_func_name --- check the result of func_name production
20163 : : *
20164 : : * It's easiest to let the grammar production for func_name allow subscripts
20165 : : * and '*', which we then must reject here.
20166 : : */
20167 : : static List *
20168 : 88431 : check_func_name(List *names, core_yyscan_t yyscanner)
20169 : : {
20170 : : ListCell *i;
20171 : :
20172 [ + - + + : 265293 : foreach(i, names)
+ + ]
20173 : : {
20174 [ - + ]: 176862 : if (!IsA(lfirst(i), String))
20175 : 0 : parser_yyerror("syntax error");
20176 : : }
20177 : 88431 : return names;
20178 : : }
20179 : :
20180 : : /* check_indirection --- check the result of indirection production
20181 : : *
20182 : : * We only allow '*' at the end of the list, but it's hard to enforce that
20183 : : * in the grammar, so do it here.
20184 : : */
20185 : : static List *
20186 : 54388 : check_indirection(List *indirection, core_yyscan_t yyscanner)
20187 : : {
20188 : : ListCell *l;
20189 : :
20190 [ + + + + : 74106 : foreach(l, indirection)
+ + ]
20191 : : {
20192 [ + + ]: 19718 : if (IsA(lfirst(l), A_Star))
20193 : : {
20194 [ - + ]: 940 : if (lnext(indirection, l) != NULL)
20195 : 0 : parser_yyerror("improper use of \"*\"");
20196 : : }
20197 : : }
20198 : 54388 : return indirection;
20199 : : }
20200 : :
20201 : : /* extractArgTypes()
20202 : : * Given a list of FunctionParameter nodes, extract a list of just the
20203 : : * argument types (TypeNames) for input parameters only. This is what
20204 : : * is needed to look up an existing function, which is what is wanted by
20205 : : * the productions that use this call.
20206 : : */
20207 : : static List *
20208 : 5537 : extractArgTypes(List *parameters)
20209 : : {
20210 : 5537 : List *result = NIL;
20211 : : ListCell *i;
20212 : :
20213 [ + + + + : 13707 : foreach(i, parameters)
+ + ]
20214 : : {
20215 : 8170 : FunctionParameter *p = (FunctionParameter *) lfirst(i);
20216 : :
20217 [ + + + - ]: 8170 : if (p->mode != FUNC_PARAM_OUT && p->mode != FUNC_PARAM_TABLE)
20218 : 8083 : result = lappend(result, p->argType);
20219 : : }
20220 : 5537 : return result;
20221 : : }
20222 : :
20223 : : /* extractAggrArgTypes()
20224 : : * As above, but work from the output of the aggr_args production.
20225 : : */
20226 : : static List *
20227 : 220 : extractAggrArgTypes(List *aggrargs)
20228 : : {
20229 : : Assert(list_length(aggrargs) == 2);
20230 : 220 : return extractArgTypes((List *) linitial(aggrargs));
20231 : : }
20232 : :
20233 : : /* makeOrderedSetArgs()
20234 : : * Build the result of the aggr_args production (which see the comments for).
20235 : : * This handles only the case where both given lists are nonempty, so that
20236 : : * we have to deal with multiple VARIADIC arguments.
20237 : : */
20238 : : static List *
20239 : 20 : makeOrderedSetArgs(List *directargs, List *orderedargs,
20240 : : core_yyscan_t yyscanner)
20241 : : {
20242 : 20 : FunctionParameter *lastd = (FunctionParameter *) llast(directargs);
20243 : : Integer *ndirectargs;
20244 : :
20245 : : /* No restriction unless last direct arg is VARIADIC */
20246 [ + + ]: 20 : if (lastd->mode == FUNC_PARAM_VARIADIC)
20247 : : {
20248 : 10 : FunctionParameter *firsto = (FunctionParameter *) linitial(orderedargs);
20249 : :
20250 : : /*
20251 : : * We ignore the names, though the aggr_arg production allows them; it
20252 : : * doesn't allow default values, so those need not be checked.
20253 : : */
20254 [ + - ]: 10 : if (list_length(orderedargs) != 1 ||
20255 [ + - ]: 10 : firsto->mode != FUNC_PARAM_VARIADIC ||
20256 [ - + ]: 10 : !equal(lastd->argType, firsto->argType))
20257 [ # # ]: 0 : ereport(ERROR,
20258 : : (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
20259 : : errmsg("an ordered-set aggregate with a VARIADIC direct argument must have one VARIADIC aggregated argument of the same data type"),
20260 : : parser_errposition(firsto->location)));
20261 : :
20262 : : /* OK, drop the duplicate VARIADIC argument from the internal form */
20263 : 10 : orderedargs = NIL;
20264 : : }
20265 : :
20266 : : /* don't merge into the next line, as list_concat changes directargs */
20267 : 20 : ndirectargs = makeInteger(list_length(directargs));
20268 : :
20269 : 20 : return list_make2(list_concat(directargs, orderedargs),
20270 : : ndirectargs);
20271 : : }
20272 : :
20273 : : /* insertSelectOptions()
20274 : : * Insert ORDER BY, etc into an already-constructed SelectStmt.
20275 : : *
20276 : : * This routine is just to avoid duplicating code in SelectStmt productions.
20277 : : */
20278 : : static void
20279 : 58788 : insertSelectOptions(SelectStmt *stmt,
20280 : : List *sortClause, List *lockingClause,
20281 : : SelectLimit *limitClause,
20282 : : WithClause *withClause,
20283 : : core_yyscan_t yyscanner)
20284 : : {
20285 : : Assert(IsA(stmt, SelectStmt));
20286 : :
20287 : : /*
20288 : : * Tests here are to reject constructs like
20289 : : * (SELECT foo ORDER BY bar) ORDER BY baz
20290 : : */
20291 [ + + ]: 58788 : if (sortClause)
20292 : : {
20293 [ - + ]: 50994 : if (stmt->sortClause)
20294 [ # # ]: 0 : ereport(ERROR,
20295 : : (errcode(ERRCODE_SYNTAX_ERROR),
20296 : : errmsg("multiple ORDER BY clauses not allowed"),
20297 : : parser_errposition(exprLocation((Node *) sortClause))));
20298 : 50994 : stmt->sortClause = sortClause;
20299 : : }
20300 : : /* We can handle multiple locking clauses, though */
20301 : 58788 : stmt->lockingClause = list_concat(stmt->lockingClause, lockingClause);
20302 [ + + + + ]: 58788 : if (limitClause && limitClause->limitOffset)
20303 : : {
20304 [ - + ]: 550 : if (stmt->limitOffset)
20305 [ # # ]: 0 : ereport(ERROR,
20306 : : (errcode(ERRCODE_SYNTAX_ERROR),
20307 : : errmsg("multiple OFFSET clauses not allowed"),
20308 : : parser_errposition(limitClause->offsetLoc)));
20309 : 550 : stmt->limitOffset = limitClause->limitOffset;
20310 : : }
20311 [ + + + + ]: 58788 : if (limitClause && limitClause->limitCount)
20312 : : {
20313 [ - + ]: 2970 : if (stmt->limitCount)
20314 [ # # ]: 0 : ereport(ERROR,
20315 : : (errcode(ERRCODE_SYNTAX_ERROR),
20316 : : errmsg("multiple LIMIT clauses not allowed"),
20317 : : parser_errposition(limitClause->countLoc)));
20318 : 2970 : stmt->limitCount = limitClause->limitCount;
20319 : : }
20320 [ + + ]: 58788 : if (limitClause)
20321 : : {
20322 : : /* If there was a conflict, we must have detected it above */
20323 : : Assert(!stmt->limitOption);
20324 [ + + + + ]: 3308 : if (!stmt->sortClause && limitClause->limitOption == LIMIT_OPTION_WITH_TIES)
20325 [ + - ]: 4 : ereport(ERROR,
20326 : : (errcode(ERRCODE_SYNTAX_ERROR),
20327 : : errmsg("WITH TIES cannot be specified without ORDER BY clause"),
20328 : : parser_errposition(limitClause->optionLoc)));
20329 [ + + + + ]: 3304 : if (limitClause->limitOption == LIMIT_OPTION_WITH_TIES && stmt->lockingClause)
20330 : : {
20331 : : ListCell *lc;
20332 : :
20333 [ + - + - : 4 : foreach(lc, stmt->lockingClause)
+ - ]
20334 : : {
20335 : 4 : LockingClause *lock = lfirst_node(LockingClause, lc);
20336 : :
20337 [ + - ]: 4 : if (lock->waitPolicy == LockWaitSkip)
20338 [ + - ]: 4 : ereport(ERROR,
20339 : : (errcode(ERRCODE_SYNTAX_ERROR),
20340 : : errmsg("%s and %s options cannot be used together",
20341 : : "SKIP LOCKED", "WITH TIES"),
20342 : : parser_errposition(limitClause->optionLoc)));
20343 : : }
20344 : : }
20345 : 3300 : stmt->limitOption = limitClause->limitOption;
20346 : : }
20347 [ + + ]: 58780 : if (withClause)
20348 : : {
20349 [ - + ]: 1875 : if (stmt->withClause)
20350 [ # # ]: 0 : ereport(ERROR,
20351 : : (errcode(ERRCODE_SYNTAX_ERROR),
20352 : : errmsg("multiple WITH clauses not allowed"),
20353 : : parser_errposition(exprLocation((Node *) withClause))));
20354 : 1875 : stmt->withClause = withClause;
20355 : : }
20356 : 58780 : }
20357 : :
20358 : : static Node *
20359 : 13028 : makeSetOp(SetOperation op, bool all, Node *larg, Node *rarg)
20360 : : {
20361 : 13028 : SelectStmt *n = makeNode(SelectStmt);
20362 : :
20363 : 13028 : n->op = op;
20364 : 13028 : n->all = all;
20365 : 13028 : n->larg = (SelectStmt *) larg;
20366 : 13028 : n->rarg = (SelectStmt *) rarg;
20367 : 13028 : return (Node *) n;
20368 : : }
20369 : :
20370 : : /* SystemFuncName()
20371 : : * Build a properly-qualified reference to a built-in function.
20372 : : */
20373 : : List *
20374 : 13133 : SystemFuncName(char *name)
20375 : : {
20376 : 13133 : return list_make2(makeString("pg_catalog"), makeString(name));
20377 : : }
20378 : :
20379 : : /* SystemTypeName()
20380 : : * Build a properly-qualified reference to a built-in type.
20381 : : *
20382 : : * typmod is defaulted, but may be changed afterwards by caller.
20383 : : * Likewise for the location.
20384 : : */
20385 : : TypeName *
20386 : 72124 : SystemTypeName(char *name)
20387 : : {
20388 : 72124 : return makeTypeNameFromNameList(list_make2(makeString("pg_catalog"),
20389 : : makeString(name)));
20390 : : }
20391 : :
20392 : : /* doNegate()
20393 : : * Handle negation of a numeric constant.
20394 : : *
20395 : : * Formerly, we did this here because the optimizer couldn't cope with
20396 : : * indexquals that looked like "var = -4" --- it wants "var = const"
20397 : : * and a unary minus operator applied to a constant didn't qualify.
20398 : : * As of Postgres 7.0, that problem doesn't exist anymore because there
20399 : : * is a constant-subexpression simplifier in the optimizer. However,
20400 : : * there's still a good reason for doing this here, which is that we can
20401 : : * postpone committing to a particular internal representation for simple
20402 : : * negative constants. It's better to leave "-123.456" in string form
20403 : : * until we know what the desired type is.
20404 : : */
20405 : : static Node *
20406 : 6509 : doNegate(Node *n, int location)
20407 : : {
20408 [ + + ]: 6509 : if (IsA(n, A_Const))
20409 : : {
20410 : 5853 : A_Const *con = (A_Const *) n;
20411 : :
20412 : : /* report the constant's location as that of the '-' sign */
20413 : 5853 : con->location = location;
20414 : :
20415 [ + + ]: 5853 : if (IsA(&con->val, Integer))
20416 : : {
20417 : 5205 : con->val.ival.ival = -con->val.ival.ival;
20418 : 5205 : return n;
20419 : : }
20420 [ + - ]: 648 : if (IsA(&con->val, Float))
20421 : : {
20422 : 648 : doNegateFloat(&con->val.fval);
20423 : 648 : return n;
20424 : : }
20425 : : }
20426 : :
20427 : 656 : return (Node *) makeSimpleA_Expr(AEXPR_OP, "-", NULL, n, location);
20428 : : }
20429 : :
20430 : : static void
20431 : 661 : doNegateFloat(Float *v)
20432 : : {
20433 : 661 : char *oldval = v->fval;
20434 : :
20435 [ - + ]: 661 : if (*oldval == '+')
20436 : 0 : oldval++;
20437 [ - + ]: 661 : if (*oldval == '-')
20438 : 0 : v->fval = oldval + 1; /* just strip the '-' */
20439 : : else
20440 : 661 : v->fval = psprintf("-%s", oldval);
20441 : 661 : }
20442 : :
20443 : : static Node *
20444 : 156276 : makeAndExpr(Node *lexpr, Node *rexpr, int location)
20445 : : {
20446 : : /* Flatten "a AND b AND c ..." to a single BoolExpr on sight */
20447 [ + + ]: 156276 : if (IsA(lexpr, BoolExpr))
20448 : : {
20449 : 73811 : BoolExpr *blexpr = (BoolExpr *) lexpr;
20450 : :
20451 [ + + ]: 73811 : if (blexpr->boolop == AND_EXPR)
20452 : : {
20453 : 70103 : blexpr->args = lappend(blexpr->args, rexpr);
20454 : 70103 : return (Node *) blexpr;
20455 : : }
20456 : : }
20457 : 86173 : return (Node *) makeBoolExpr(AND_EXPR, list_make2(lexpr, rexpr), location);
20458 : : }
20459 : :
20460 : : static Node *
20461 : 14613 : makeOrExpr(Node *lexpr, Node *rexpr, int location)
20462 : : {
20463 : : /* Flatten "a OR b OR c ..." to a single BoolExpr on sight */
20464 [ + + ]: 14613 : if (IsA(lexpr, BoolExpr))
20465 : : {
20466 : 3550 : BoolExpr *blexpr = (BoolExpr *) lexpr;
20467 : :
20468 [ + + ]: 3550 : if (blexpr->boolop == OR_EXPR)
20469 : : {
20470 : 2621 : blexpr->args = lappend(blexpr->args, rexpr);
20471 : 2621 : return (Node *) blexpr;
20472 : : }
20473 : : }
20474 : 11992 : return (Node *) makeBoolExpr(OR_EXPR, list_make2(lexpr, rexpr), location);
20475 : : }
20476 : :
20477 : : static Node *
20478 : 17815 : makeNotExpr(Node *expr, int location)
20479 : : {
20480 : 17815 : return (Node *) makeBoolExpr(NOT_EXPR, list_make1(expr), location);
20481 : : }
20482 : :
20483 : : static Node *
20484 : 5851 : makeAArrayExpr(List *elements, int location, int location_end)
20485 : : {
20486 : 5851 : A_ArrayExpr *n = makeNode(A_ArrayExpr);
20487 : :
20488 : 5851 : n->elements = elements;
20489 : 5851 : n->location = location;
20490 : 5851 : n->list_start = location;
20491 : 5851 : n->list_end = location_end;
20492 : 5851 : return (Node *) n;
20493 : : }
20494 : :
20495 : : static Node *
20496 : 1683 : makeSQLValueFunction(SQLValueFunctionOp op, int32 typmod, int location)
20497 : : {
20498 : 1683 : SQLValueFunction *svf = makeNode(SQLValueFunction);
20499 : :
20500 : 1683 : svf->op = op;
20501 : : /* svf->type will be filled during parse analysis */
20502 : 1683 : svf->typmod = typmod;
20503 : 1683 : svf->location = location;
20504 : 1683 : return (Node *) svf;
20505 : : }
20506 : :
20507 : : static Node *
20508 : 395 : makeXmlExpr(XmlExprOp op, char *name, List *named_args, List *args,
20509 : : int location)
20510 : : {
20511 : 395 : XmlExpr *x = makeNode(XmlExpr);
20512 : :
20513 : 395 : x->op = op;
20514 : 395 : x->name = name;
20515 : :
20516 : : /*
20517 : : * named_args is a list of ResTarget; it'll be split apart into separate
20518 : : * expression and name lists in transformXmlExpr().
20519 : : */
20520 : 395 : x->named_args = named_args;
20521 : 395 : x->arg_names = NIL;
20522 : 395 : x->args = args;
20523 : : /* xmloption, if relevant, must be filled in by caller */
20524 : : /* type and typmod will be filled in during parse analysis */
20525 : 395 : x->type = InvalidOid; /* marks the node as not analyzed */
20526 : 395 : x->location = location;
20527 : 395 : return (Node *) x;
20528 : : }
20529 : :
20530 : : /*
20531 : : * Merge the input and output parameters of a table function.
20532 : : */
20533 : : static List *
20534 : 146 : mergeTableFuncParameters(List *func_args, List *columns, core_yyscan_t yyscanner)
20535 : : {
20536 : : ListCell *lc;
20537 : :
20538 : : /* Explicit OUT and INOUT parameters shouldn't be used in this syntax */
20539 [ + + + + : 313 : foreach(lc, func_args)
+ + ]
20540 : : {
20541 : 167 : FunctionParameter *p = (FunctionParameter *) lfirst(lc);
20542 : :
20543 [ - + ]: 167 : if (p->mode != FUNC_PARAM_DEFAULT &&
20544 [ # # ]: 0 : p->mode != FUNC_PARAM_IN &&
20545 [ # # ]: 0 : p->mode != FUNC_PARAM_VARIADIC)
20546 [ # # ]: 0 : ereport(ERROR,
20547 : : (errcode(ERRCODE_SYNTAX_ERROR),
20548 : : errmsg("OUT and INOUT arguments aren't allowed in TABLE functions"),
20549 : : parser_errposition(p->location)));
20550 : : }
20551 : :
20552 : 146 : return list_concat(func_args, columns);
20553 : : }
20554 : :
20555 : : /*
20556 : : * Determine return type of a TABLE function. A single result column
20557 : : * returns setof that column's type; otherwise return setof record.
20558 : : */
20559 : : static TypeName *
20560 : 146 : TableFuncTypeName(List *columns)
20561 : : {
20562 : : TypeName *result;
20563 : :
20564 [ + + ]: 146 : if (list_length(columns) == 1)
20565 : : {
20566 : 40 : FunctionParameter *p = (FunctionParameter *) linitial(columns);
20567 : :
20568 : 40 : result = copyObject(p->argType);
20569 : : }
20570 : : else
20571 : 106 : result = SystemTypeName("record");
20572 : :
20573 : 146 : result->setof = true;
20574 : :
20575 : 146 : return result;
20576 : : }
20577 : :
20578 : : /*
20579 : : * Convert a list of (dotted) names to a RangeVar (like
20580 : : * makeRangeVarFromNameList, but with position support). The
20581 : : * "AnyName" refers to the any_name production in the grammar.
20582 : : */
20583 : : static RangeVar *
20584 : 2533 : makeRangeVarFromAnyName(List *names, int position, core_yyscan_t yyscanner)
20585 : : {
20586 : 2533 : RangeVar *r = makeNode(RangeVar);
20587 : :
20588 [ + + - - ]: 2533 : switch (list_length(names))
20589 : : {
20590 : 2483 : case 1:
20591 : 2483 : r->catalogname = NULL;
20592 : 2483 : r->schemaname = NULL;
20593 : 2483 : r->relname = strVal(linitial(names));
20594 : 2483 : break;
20595 : 50 : case 2:
20596 : 50 : r->catalogname = NULL;
20597 : 50 : r->schemaname = strVal(linitial(names));
20598 : 50 : r->relname = strVal(lsecond(names));
20599 : 50 : break;
20600 : 0 : case 3:
20601 : 0 : r->catalogname = strVal(linitial(names));
20602 : 0 : r->schemaname = strVal(lsecond(names));
20603 : 0 : r->relname = strVal(lthird(names));
20604 : 0 : break;
20605 : 0 : default:
20606 [ # # ]: 0 : ereport(ERROR,
20607 : : (errcode(ERRCODE_SYNTAX_ERROR),
20608 : : errmsg("improper qualified name (too many dotted names): %s",
20609 : : NameListToString(names)),
20610 : : parser_errposition(position)));
20611 : : break;
20612 : : }
20613 : :
20614 : 2533 : r->relpersistence = RELPERSISTENCE_PERMANENT;
20615 : 2533 : r->location = position;
20616 : :
20617 : 2533 : return r;
20618 : : }
20619 : :
20620 : : /*
20621 : : * Convert a relation_name with name and namelist to a RangeVar using
20622 : : * makeRangeVar.
20623 : : */
20624 : : static RangeVar *
20625 : 161139 : makeRangeVarFromQualifiedName(char *name, List *namelist, int location,
20626 : : core_yyscan_t yyscanner)
20627 : : {
20628 : : RangeVar *r;
20629 : :
20630 : 161139 : check_qualified_name(namelist, yyscanner);
20631 : 161139 : r = makeRangeVar(NULL, NULL, location);
20632 : :
20633 [ + - - ]: 161139 : switch (list_length(namelist))
20634 : : {
20635 : 161139 : case 1:
20636 : 161139 : r->catalogname = NULL;
20637 : 161139 : r->schemaname = name;
20638 : 161139 : r->relname = strVal(linitial(namelist));
20639 : 161139 : break;
20640 : 0 : case 2:
20641 : 0 : r->catalogname = name;
20642 : 0 : r->schemaname = strVal(linitial(namelist));
20643 : 0 : r->relname = strVal(lsecond(namelist));
20644 : 0 : break;
20645 : 0 : default:
20646 [ # # ]: 0 : ereport(ERROR,
20647 : : errcode(ERRCODE_SYNTAX_ERROR),
20648 : : errmsg("improper qualified name (too many dotted names): %s",
20649 : : NameListToString(lcons(makeString(name), namelist))),
20650 : : parser_errposition(location));
20651 : : break;
20652 : : }
20653 : :
20654 : 161139 : return r;
20655 : : }
20656 : :
20657 : : /* Separate Constraint nodes from COLLATE clauses in a ColQualList */
20658 : : static void
20659 : 46915 : SplitColQualList(List *qualList,
20660 : : List **constraintList, CollateClause **collClause,
20661 : : core_yyscan_t yyscanner)
20662 : : {
20663 : : ListCell *cell;
20664 : :
20665 : 46915 : *collClause = NULL;
20666 [ + + + + : 60565 : foreach(cell, qualList)
+ + ]
20667 : : {
20668 : 13650 : Node *n = (Node *) lfirst(cell);
20669 : :
20670 [ + + ]: 13650 : if (IsA(n, Constraint))
20671 : : {
20672 : : /* keep it in list */
20673 : 13132 : continue;
20674 : : }
20675 [ + - ]: 518 : if (IsA(n, CollateClause))
20676 : : {
20677 : 518 : CollateClause *c = (CollateClause *) n;
20678 : :
20679 [ - + ]: 518 : if (*collClause)
20680 [ # # ]: 0 : ereport(ERROR,
20681 : : (errcode(ERRCODE_SYNTAX_ERROR),
20682 : : errmsg("multiple COLLATE clauses not allowed"),
20683 : : parser_errposition(c->location)));
20684 : 518 : *collClause = c;
20685 : : }
20686 : : else
20687 [ # # ]: 0 : elog(ERROR, "unexpected node type %d", (int) n->type);
20688 : : /* remove non-Constraint nodes from qualList */
20689 : 518 : qualList = foreach_delete_current(qualList, cell);
20690 : : }
20691 : 46915 : *constraintList = qualList;
20692 : 46915 : }
20693 : :
20694 : : /*
20695 : : * Process result of ConstraintAttributeSpec, and set appropriate bool flags
20696 : : * in the output command node. Pass NULL for any flags the particular
20697 : : * command doesn't support.
20698 : : */
20699 : : static void
20700 : 11879 : processCASbits(int cas_bits, int location, const char *constrType,
20701 : : bool *deferrable, bool *initdeferred, bool *is_enforced,
20702 : : bool *not_valid, bool *no_inherit, core_yyscan_t yyscanner)
20703 : : {
20704 : : /* defaults */
20705 [ + + ]: 11879 : if (deferrable)
20706 : 10360 : *deferrable = false;
20707 [ + + ]: 11879 : if (initdeferred)
20708 : 10360 : *initdeferred = false;
20709 [ + + ]: 11879 : if (not_valid)
20710 : 2707 : *not_valid = false;
20711 [ + + ]: 11879 : if (is_enforced)
20712 : 2506 : *is_enforced = true;
20713 : :
20714 [ + + ]: 11879 : if (cas_bits & (CAS_DEFERRABLE | CAS_INITIALLY_DEFERRED))
20715 : : {
20716 [ + - ]: 169 : if (deferrable)
20717 : 169 : *deferrable = true;
20718 : : else
20719 [ # # ]: 0 : ereport(ERROR,
20720 : : (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
20721 : : /* translator: %s is CHECK, UNIQUE, or similar */
20722 : : errmsg("%s constraints cannot be marked DEFERRABLE",
20723 : : constrType),
20724 : : parser_errposition(location)));
20725 : : }
20726 : :
20727 [ + + ]: 11879 : if (cas_bits & CAS_INITIALLY_DEFERRED)
20728 : : {
20729 [ + - ]: 112 : if (initdeferred)
20730 : 112 : *initdeferred = true;
20731 : : else
20732 [ # # ]: 0 : ereport(ERROR,
20733 : : (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
20734 : : /* translator: %s is CHECK, UNIQUE, or similar */
20735 : : errmsg("%s constraints cannot be marked DEFERRABLE",
20736 : : constrType),
20737 : : parser_errposition(location)));
20738 : : }
20739 : :
20740 [ + + ]: 11879 : if (cas_bits & CAS_NOT_VALID)
20741 : : {
20742 [ + - ]: 435 : if (not_valid)
20743 : 435 : *not_valid = true;
20744 : : else
20745 [ # # ]: 0 : ereport(ERROR,
20746 : : (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
20747 : : /* translator: %s is CHECK, UNIQUE, or similar */
20748 : : errmsg("%s constraints cannot be marked NOT VALID",
20749 : : constrType),
20750 : : parser_errposition(location)));
20751 : : }
20752 : :
20753 [ + + ]: 11879 : if (cas_bits & CAS_NO_INHERIT)
20754 : : {
20755 [ + - ]: 167 : if (no_inherit)
20756 : 167 : *no_inherit = true;
20757 : : else
20758 [ # # ]: 0 : ereport(ERROR,
20759 : : (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
20760 : : /* translator: %s is CHECK, UNIQUE, or similar */
20761 : : errmsg("%s constraints cannot be marked NO INHERIT",
20762 : : constrType),
20763 : : parser_errposition(location)));
20764 : : }
20765 : :
20766 [ + + ]: 11879 : if (cas_bits & CAS_NOT_ENFORCED)
20767 : : {
20768 [ + + ]: 203 : if (is_enforced)
20769 : 199 : *is_enforced = false;
20770 : : else
20771 [ + - ]: 4 : ereport(ERROR,
20772 : : (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
20773 : : /* translator: %s is CHECK, UNIQUE, or similar */
20774 : : errmsg("%s constraints cannot be marked NOT ENFORCED",
20775 : : constrType),
20776 : : parser_errposition(location)));
20777 : :
20778 : : /*
20779 : : * NB: The validated status is irrelevant when the constraint is set to
20780 : : * NOT ENFORCED, but for consistency, it should be set accordingly.
20781 : : * This ensures that if the constraint is later changed to ENFORCED, it
20782 : : * will automatically be in the correct NOT VALIDATED state.
20783 : : */
20784 [ + + ]: 199 : if (not_valid)
20785 : 103 : *not_valid = true;
20786 : : }
20787 : :
20788 [ + + ]: 11875 : if (cas_bits & CAS_ENFORCED)
20789 : : {
20790 [ + + ]: 140 : if (is_enforced)
20791 : 136 : *is_enforced = true;
20792 : : else
20793 [ + - ]: 4 : ereport(ERROR,
20794 : : (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
20795 : : /* translator: %s is CHECK, UNIQUE, or similar */
20796 : : errmsg("%s constraints cannot be marked ENFORCED",
20797 : : constrType),
20798 : : parser_errposition(location)));
20799 : : }
20800 : 11871 : }
20801 : :
20802 : : /*
20803 : : * Parse a user-supplied partition strategy string into parse node
20804 : : * PartitionStrategy representation, or die trying.
20805 : : */
20806 : : static PartitionStrategy
20807 : 3684 : parsePartitionStrategy(char *strategy, int location, core_yyscan_t yyscanner)
20808 : : {
20809 [ + + ]: 3684 : if (pg_strcasecmp(strategy, "list") == 0)
20810 : 1658 : return PARTITION_STRATEGY_LIST;
20811 [ + + ]: 2026 : else if (pg_strcasecmp(strategy, "range") == 0)
20812 : 1843 : return PARTITION_STRATEGY_RANGE;
20813 [ + + ]: 183 : else if (pg_strcasecmp(strategy, "hash") == 0)
20814 : 179 : return PARTITION_STRATEGY_HASH;
20815 : :
20816 [ + - ]: 4 : ereport(ERROR,
20817 : : (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
20818 : : errmsg("unrecognized partitioning strategy \"%s\"", strategy),
20819 : : parser_errposition(location)));
20820 : : return PARTITION_STRATEGY_LIST; /* keep compiler quiet */
20821 : :
20822 : : }
20823 : :
20824 : : /*
20825 : : * Process all_objects_list to set all_tables and/or all_sequences.
20826 : : * Also, checks if the pub_object_type has been specified more than once.
20827 : : */
20828 : : static void
20829 : 197 : preprocess_pub_all_objtype_list(List *all_objects_list, List **pubobjects,
20830 : : bool *all_tables, bool *all_sequences,
20831 : : core_yyscan_t yyscanner)
20832 : : {
20833 [ - + ]: 197 : if (!all_objects_list)
20834 : 0 : return;
20835 : :
20836 : 197 : *all_tables = false;
20837 : 197 : *all_sequences = false;
20838 : :
20839 [ + - + + : 600 : foreach_ptr(PublicationAllObjSpec, obj, all_objects_list)
+ + ]
20840 : : {
20841 [ + + ]: 222 : if (obj->pubobjtype == PUBLICATION_ALL_TABLES)
20842 : : {
20843 [ + + ]: 173 : if (*all_tables)
20844 [ + - ]: 4 : ereport(ERROR,
20845 : : errcode(ERRCODE_SYNTAX_ERROR),
20846 : : errmsg("invalid publication object list"),
20847 : : errdetail("ALL TABLES can be specified only once."),
20848 : : parser_errposition(obj->location));
20849 : :
20850 : 169 : *all_tables = true;
20851 : 169 : *pubobjects = list_concat(*pubobjects, obj->except_tables);
20852 : : }
20853 [ + - ]: 49 : else if (obj->pubobjtype == PUBLICATION_ALL_SEQUENCES)
20854 : : {
20855 [ + + ]: 49 : if (*all_sequences)
20856 [ + - ]: 4 : ereport(ERROR,
20857 : : errcode(ERRCODE_SYNTAX_ERROR),
20858 : : errmsg("invalid publication object list"),
20859 : : errdetail("ALL SEQUENCES can be specified only once."),
20860 : : parser_errposition(obj->location));
20861 : :
20862 : 45 : *all_sequences = true;
20863 : : }
20864 : : }
20865 : : }
20866 : :
20867 : : /*
20868 : : * Process pubobjspec_list to check for errors in any of the objects and
20869 : : * convert PUBLICATIONOBJ_CONTINUATION into appropriate PublicationObjSpecType.
20870 : : */
20871 : : static void
20872 : 1082 : preprocess_pubobj_list(List *pubobjspec_list, core_yyscan_t yyscanner)
20873 : : {
20874 : : ListCell *cell;
20875 : : PublicationObjSpec *pubobj;
20876 : 1082 : PublicationObjSpecType prevobjtype = PUBLICATIONOBJ_CONTINUATION;
20877 : :
20878 [ - + ]: 1082 : if (!pubobjspec_list)
20879 : 0 : return;
20880 : :
20881 : 1082 : pubobj = (PublicationObjSpec *) linitial(pubobjspec_list);
20882 [ + + ]: 1082 : if (pubobj->pubobjtype == PUBLICATIONOBJ_CONTINUATION)
20883 [ + - ]: 8 : ereport(ERROR,
20884 : : errcode(ERRCODE_SYNTAX_ERROR),
20885 : : errmsg("invalid publication object list"),
20886 : : errdetail("One of TABLE or TABLES IN SCHEMA must be specified before a standalone table or schema name."),
20887 : : parser_errposition(pubobj->location));
20888 : :
20889 [ + - + + : 2297 : foreach(cell, pubobjspec_list)
+ + ]
20890 : : {
20891 : 1239 : pubobj = (PublicationObjSpec *) lfirst(cell);
20892 : :
20893 [ + + ]: 1239 : if (pubobj->pubobjtype == PUBLICATIONOBJ_CONTINUATION)
20894 : 112 : pubobj->pubobjtype = prevobjtype;
20895 : :
20896 [ + + ]: 1239 : if (pubobj->pubobjtype == PUBLICATIONOBJ_TABLE)
20897 : : {
20898 : : /* relation name or pubtable must be set for this type of object */
20899 [ + + + + ]: 943 : if (!pubobj->name && !pubobj->pubtable)
20900 [ + - ]: 4 : ereport(ERROR,
20901 : : errcode(ERRCODE_SYNTAX_ERROR),
20902 : : errmsg("invalid table name"),
20903 : : parser_errposition(pubobj->location));
20904 : :
20905 [ + + ]: 939 : if (pubobj->name)
20906 : : {
20907 : : /* convert it to PublicationTable */
20908 : 37 : PublicationTable *pubtable = makeNode(PublicationTable);
20909 : :
20910 : 37 : pubtable->relation =
20911 : 37 : makeRangeVar(NULL, pubobj->name, pubobj->location);
20912 : 37 : pubobj->pubtable = pubtable;
20913 : 37 : pubobj->name = NULL;
20914 : : }
20915 : : }
20916 [ + + ]: 296 : else if (pubobj->pubobjtype == PUBLICATIONOBJ_TABLES_IN_SCHEMA ||
20917 [ + - ]: 16 : pubobj->pubobjtype == PUBLICATIONOBJ_TABLES_IN_CUR_SCHEMA)
20918 : : {
20919 : : /* WHERE clause is not allowed on a schema object */
20920 [ + + + + ]: 296 : if (pubobj->pubtable && pubobj->pubtable->whereClause)
20921 [ + - ]: 4 : ereport(ERROR,
20922 : : errcode(ERRCODE_SYNTAX_ERROR),
20923 : : errmsg("WHERE clause not allowed for schema"),
20924 : : parser_errposition(pubobj->location));
20925 : :
20926 : : /* Column list is not allowed on a schema object */
20927 [ + + + + ]: 292 : if (pubobj->pubtable && pubobj->pubtable->columns)
20928 [ + - ]: 4 : ereport(ERROR,
20929 : : errcode(ERRCODE_SYNTAX_ERROR),
20930 : : errmsg("column specification not allowed for schema"),
20931 : : parser_errposition(pubobj->location));
20932 : :
20933 : : /*
20934 : : * We can distinguish between the different type of schema objects
20935 : : * based on whether name and pubtable is set.
20936 : : */
20937 [ + + ]: 288 : if (pubobj->name)
20938 : 268 : pubobj->pubobjtype = PUBLICATIONOBJ_TABLES_IN_SCHEMA;
20939 [ + - + + ]: 20 : else if (!pubobj->name && !pubobj->pubtable)
20940 : 16 : pubobj->pubobjtype = PUBLICATIONOBJ_TABLES_IN_CUR_SCHEMA;
20941 : : else
20942 [ + - ]: 4 : ereport(ERROR,
20943 : : errcode(ERRCODE_SYNTAX_ERROR),
20944 : : errmsg("invalid schema name"),
20945 : : parser_errposition(pubobj->location));
20946 : : }
20947 : :
20948 : 1223 : prevobjtype = pubobj->pubobjtype;
20949 : : }
20950 : : }
20951 : :
20952 : : /*----------
20953 : : * Recursive view transformation
20954 : : *
20955 : : * Convert
20956 : : *
20957 : : * CREATE RECURSIVE VIEW relname (aliases) AS query
20958 : : *
20959 : : * to
20960 : : *
20961 : : * CREATE VIEW relname (aliases) AS
20962 : : * WITH RECURSIVE relname (aliases) AS (query)
20963 : : * SELECT aliases FROM relname
20964 : : *
20965 : : * Actually, just the WITH ... part, which is then inserted into the original
20966 : : * view definition as the query.
20967 : : * ----------
20968 : : */
20969 : : static Node *
20970 : 9 : makeRecursiveViewSelect(char *relname, List *aliases, Node *query)
20971 : : {
20972 : 9 : SelectStmt *s = makeNode(SelectStmt);
20973 : 9 : WithClause *w = makeNode(WithClause);
20974 : 9 : CommonTableExpr *cte = makeNode(CommonTableExpr);
20975 : 9 : List *tl = NIL;
20976 : : ListCell *lc;
20977 : :
20978 : : /* create common table expression */
20979 : 9 : cte->ctename = relname;
20980 : 9 : cte->aliascolnames = aliases;
20981 : 9 : cte->ctematerialized = CTEMaterializeDefault;
20982 : 9 : cte->ctequery = query;
20983 : 9 : cte->location = -1;
20984 : :
20985 : : /* create WITH clause and attach CTE */
20986 : 9 : w->recursive = true;
20987 : 9 : w->ctes = list_make1(cte);
20988 : 9 : w->location = -1;
20989 : :
20990 : : /*
20991 : : * create target list for the new SELECT from the alias list of the
20992 : : * recursive view specification
20993 : : */
20994 [ + - + + : 18 : foreach(lc, aliases)
+ + ]
20995 : : {
20996 : 9 : ResTarget *rt = makeNode(ResTarget);
20997 : :
20998 : 9 : rt->name = NULL;
20999 : 9 : rt->indirection = NIL;
21000 : 9 : rt->val = makeColumnRef(strVal(lfirst(lc)), NIL, -1, 0);
21001 : 9 : rt->location = -1;
21002 : :
21003 : 9 : tl = lappend(tl, rt);
21004 : : }
21005 : :
21006 : : /*
21007 : : * create new SELECT combining WITH clause, target list, and fake FROM
21008 : : * clause
21009 : : */
21010 : 9 : s->withClause = w;
21011 : 9 : s->targetList = tl;
21012 : 9 : s->fromClause = list_make1(makeRangeVar(NULL, relname, -1));
21013 : :
21014 : 9 : return (Node *) s;
21015 : : }
21016 : :
21017 : : /* parser_init()
21018 : : * Initialize to parse one query string
21019 : : */
21020 : : void
21021 : 501486 : parser_init(base_yy_extra_type *yyext)
21022 : : {
21023 : 501486 : yyext->parsetree = NIL; /* in case grammar forgets to set it */
21024 : 501486 : }
|