Line data Source code
1 : %{
2 :
3 : /*#define YYDEBUG 1*/
4 : /*-------------------------------------------------------------------------
5 : *
6 : * gram.y
7 : * POSTGRESQL BISON rules/actions
8 : *
9 : * Portions Copyright (c) 1996-2025, PostgreSQL Global Development Group
10 : * Portions Copyright (c) 1994, Regents of the University of California
11 : *
12 : *
13 : * IDENTIFICATION
14 : * src/backend/parser/gram.y
15 : *
16 : * HISTORY
17 : * AUTHOR DATE MAJOR EVENT
18 : * Andrew Yu Sept, 1994 POSTQUEL to SQL conversion
19 : * Andrew Yu Oct, 1994 lispy code conversion
20 : *
21 : * NOTES
22 : * CAPITALS are used to represent terminal symbols.
23 : * non-capitals are used to represent non-terminals.
24 : *
25 : * In general, nothing in this file should initiate database accesses
26 : * nor depend on changeable state (such as SET variables). If you do
27 : * database accesses, your code will fail when we have aborted the
28 : * current transaction and are just parsing commands to find the next
29 : * ROLLBACK or COMMIT. If you make use of SET variables, then you
30 : * will do the wrong thing in multi-query strings like this:
31 : * SET constraint_exclusion TO off; SELECT * FROM foo;
32 : * because the entire string is parsed by gram.y before the SET gets
33 : * executed. Anything that depends on the database or changeable state
34 : * should be handled during parse analysis so that it happens at the
35 : * right time not the wrong time.
36 : *
37 : * WARNINGS
38 : * If you use a list, make sure the datum is a node so that the printing
39 : * routines work.
40 : *
41 : * Sometimes we assign constants to makeStrings. Make sure we don't free
42 : * those.
43 : *
44 : *-------------------------------------------------------------------------
45 : */
46 : #include "postgres.h"
47 :
48 : #include <ctype.h>
49 : #include <limits.h>
50 :
51 : #include "catalog/index.h"
52 : #include "catalog/namespace.h"
53 : #include "catalog/pg_am.h"
54 : #include "catalog/pg_trigger.h"
55 : #include "commands/defrem.h"
56 : #include "commands/trigger.h"
57 : #include "gramparse.h"
58 : #include "nodes/makefuncs.h"
59 : #include "nodes/nodeFuncs.h"
60 : #include "parser/parser.h"
61 : #include "utils/datetime.h"
62 : #include "utils/xml.h"
63 :
64 :
65 : /*
66 : * Location tracking support. Unlike bison's default, we only want
67 : * to track the start position not the end position of each nonterminal.
68 : * Nonterminals that reduce to empty receive position "-1". Since a
69 : * production's leading RHS nonterminal(s) may have reduced to empty,
70 : * we have to scan to find the first one that's not -1.
71 : */
72 : #define YYLLOC_DEFAULT(Current, Rhs, N) \
73 : do { \
74 : (Current) = (-1); \
75 : for (int _i = 1; _i <= (N); _i++) \
76 : { \
77 : if ((Rhs)[_i] >= 0) \
78 : { \
79 : (Current) = (Rhs)[_i]; \
80 : break; \
81 : } \
82 : } \
83 : } while (0)
84 :
85 : /*
86 : * Bison doesn't allocate anything that needs to live across parser calls,
87 : * so we can easily have it use palloc instead of malloc. This prevents
88 : * memory leaks if we error out during parsing.
89 : */
90 : #define YYMALLOC palloc
91 : #define YYFREE pfree
92 :
93 : /* Private struct for the result of privilege_target production */
94 : typedef struct PrivTarget
95 : {
96 : GrantTargetType targtype;
97 : ObjectType objtype;
98 : List *objs;
99 : } PrivTarget;
100 :
101 : /* Private struct for the result of import_qualification production */
102 : typedef struct ImportQual
103 : {
104 : ImportForeignSchemaType type;
105 : List *table_names;
106 : } ImportQual;
107 :
108 : /* Private struct for the result of select_limit & limit_clause productions */
109 : typedef struct SelectLimit
110 : {
111 : Node *limitOffset;
112 : Node *limitCount;
113 : LimitOption limitOption; /* indicates presence of WITH TIES */
114 : ParseLoc offsetLoc; /* location of OFFSET token, if present */
115 : ParseLoc countLoc; /* location of LIMIT/FETCH token, if present */
116 : ParseLoc optionLoc; /* location of WITH TIES, if present */
117 : } SelectLimit;
118 :
119 : /* Private struct for the result of group_clause production */
120 : typedef struct GroupClause
121 : {
122 : bool distinct;
123 : bool all;
124 : List *list;
125 : } GroupClause;
126 :
127 : /* Private structs for the result of key_actions and key_action productions */
128 : typedef struct KeyAction
129 : {
130 : char action;
131 : List *cols;
132 : } KeyAction;
133 :
134 : typedef struct KeyActions
135 : {
136 : KeyAction *updateAction;
137 : KeyAction *deleteAction;
138 : } KeyActions;
139 :
140 : /* ConstraintAttributeSpec yields an integer bitmask of these flags: */
141 : #define CAS_NOT_DEFERRABLE 0x01
142 : #define CAS_DEFERRABLE 0x02
143 : #define CAS_INITIALLY_IMMEDIATE 0x04
144 : #define CAS_INITIALLY_DEFERRED 0x08
145 : #define CAS_NOT_VALID 0x10
146 : #define CAS_NO_INHERIT 0x20
147 : #define CAS_NOT_ENFORCED 0x40
148 : #define CAS_ENFORCED 0x80
149 :
150 :
151 : #define parser_yyerror(msg) scanner_yyerror(msg, yyscanner)
152 : #define parser_errposition(pos) scanner_errposition(pos, yyscanner)
153 :
154 : static void base_yyerror(YYLTYPE *yylloc, core_yyscan_t yyscanner,
155 : const char *msg);
156 : static RawStmt *makeRawStmt(Node *stmt, int stmt_location);
157 : static void updateRawStmtEnd(RawStmt *rs, int end_location);
158 : static Node *makeColumnRef(char *colname, List *indirection,
159 : int location, core_yyscan_t yyscanner);
160 : static Node *makeTypeCast(Node *arg, TypeName *typename, int location);
161 : static Node *makeStringConstCast(char *str, int location, TypeName *typename);
162 : static Node *makeIntConst(int val, int location);
163 : static Node *makeFloatConst(char *str, int location);
164 : static Node *makeBoolAConst(bool state, int location);
165 : static Node *makeBitStringConst(char *str, int location);
166 : static Node *makeNullAConst(int location);
167 : static Node *makeAConst(Node *v, int location);
168 : static RoleSpec *makeRoleSpec(RoleSpecType type, int location);
169 : static void check_qualified_name(List *names, core_yyscan_t yyscanner);
170 : static List *check_func_name(List *names, core_yyscan_t yyscanner);
171 : static List *check_indirection(List *indirection, core_yyscan_t yyscanner);
172 : static List *extractArgTypes(List *parameters);
173 : static List *extractAggrArgTypes(List *aggrargs);
174 : static List *makeOrderedSetArgs(List *directargs, List *orderedargs,
175 : core_yyscan_t yyscanner);
176 : static void insertSelectOptions(SelectStmt *stmt,
177 : List *sortClause, List *lockingClause,
178 : SelectLimit *limitClause,
179 : WithClause *withClause,
180 : core_yyscan_t yyscanner);
181 : static Node *makeSetOp(SetOperation op, bool all, Node *larg, Node *rarg);
182 : static Node *doNegate(Node *n, int location);
183 : static void doNegateFloat(Float *v);
184 : static Node *makeAndExpr(Node *lexpr, Node *rexpr, int location);
185 : static Node *makeOrExpr(Node *lexpr, Node *rexpr, int location);
186 : static Node *makeNotExpr(Node *expr, int location);
187 : static Node *makeAArrayExpr(List *elements, int location, int end_location);
188 : static Node *makeSQLValueFunction(SQLValueFunctionOp op, int32 typmod,
189 : int location);
190 : static Node *makeXmlExpr(XmlExprOp op, char *name, List *named_args,
191 : List *args, int location);
192 : static List *mergeTableFuncParameters(List *func_args, List *columns, core_yyscan_t yyscanner);
193 : static TypeName *TableFuncTypeName(List *columns);
194 : static RangeVar *makeRangeVarFromAnyName(List *names, int position, core_yyscan_t yyscanner);
195 : static RangeVar *makeRangeVarFromQualifiedName(char *name, List *namelist, int location,
196 : core_yyscan_t yyscanner);
197 : static void SplitColQualList(List *qualList,
198 : List **constraintList, CollateClause **collClause,
199 : core_yyscan_t yyscanner);
200 : static void processCASbits(int cas_bits, int location, const char *constrType,
201 : bool *deferrable, bool *initdeferred, bool *is_enforced,
202 : bool *not_valid, bool *no_inherit, core_yyscan_t yyscanner);
203 : static PartitionStrategy parsePartitionStrategy(char *strategy, int location,
204 : core_yyscan_t yyscanner);
205 : static void preprocess_pub_all_objtype_list(List *all_objects_list,
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 ClusterStmt 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 : CreateUserStmt CreateUserMappingStmt CreateRoleStmt CreatePolicyStmt
298 : CreatedbStmt DeclareCursorStmt DefineStmt DeleteStmt DiscardStmt DoStmt
299 : DropOpClassStmt DropOpFamilyStmt DropStmt
300 : DropCastStmt DropRoleStmt
301 : DropdbStmt DropTableSpaceStmt
302 : DropTransformStmt
303 : DropUserMappingStmt ExplainStmt FetchStmt
304 : GrantStmt GrantRoleStmt ImportForeignSchemaStmt IndexStmt InsertStmt
305 : ListenStmt LoadStmt LockStmt MergeStmt NotifyStmt ExplainableStmt PreparableStmt
306 : CreateFunctionStmt AlterFunctionStmt ReindexStmt RemoveAggrStmt
307 : RemoveFuncStmt RemoveOperStmt RenameStmt ReturnStmt RevokeStmt RevokeRoleStmt
308 : RuleActionStmt RuleActionStmtOrEmpty RuleStmt
309 : SecLabelStmt SelectStmt TransactionStmt TransactionStmtLegacy TruncateStmt
310 : UnlistenStmt UpdateStmt VacuumStmt
311 : VariableResetStmt VariableSetStmt VariableShowStmt
312 : ViewStmt WaitStmt CheckPointStmt CreateConversionStmt
313 : DeallocateStmt PrepareStmt ExecuteStmt
314 : DropOwnedStmt ReassignOwnedStmt
315 : AlterTSConfigurationStmt AlterTSDictionaryStmt
316 : CreateMatViewStmt RefreshMatViewStmt CreateAmStmt
317 : CreatePublicationStmt AlterPublicationStmt
318 : CreateSubscriptionStmt AlterSubscriptionStmt DropSubscriptionStmt
319 :
320 : %type <node> select_no_parens select_with_parens select_clause
321 : simple_select values_clause
322 : PLpgSQL_Expr PLAssignStmt
323 :
324 : %type <str> opt_single_name
325 : %type <list> opt_qualified_name
326 : %type <boolean> opt_concurrently
327 : %type <dbehavior> opt_drop_behavior
328 : %type <list> opt_utility_option_list
329 : %type <list> opt_wait_with_clause
330 : %type <list> utility_option_list
331 : %type <defelt> utility_option_elem
332 : %type <str> utility_option_name
333 : %type <node> utility_option_arg
334 :
335 : %type <node> alter_column_default opclass_item opclass_drop alter_using
336 : %type <ival> add_drop opt_asc_desc opt_nulls_order
337 :
338 : %type <node> alter_table_cmd alter_type_cmd opt_collate_clause
339 : replica_identity partition_cmd index_partition_cmd
340 : %type <list> alter_table_cmds alter_type_cmds
341 : %type <list> alter_identity_column_option_list
342 : %type <defelt> alter_identity_column_option
343 : %type <node> set_statistics_value
344 : %type <str> set_access_method_name
345 :
346 : %type <list> createdb_opt_list createdb_opt_items copy_opt_list
347 : transaction_mode_list
348 : create_extension_opt_list alter_extension_opt_list
349 : %type <defelt> createdb_opt_item copy_opt_item
350 : transaction_mode_item
351 : create_extension_opt_item alter_extension_opt_item
352 :
353 : %type <ival> opt_lock lock_type cast_context
354 : %type <defelt> drop_option
355 : %type <boolean> opt_or_replace opt_no
356 : opt_grant_grant_option
357 : opt_nowait opt_if_exists opt_with_data
358 : opt_transaction_chain
359 : %type <list> grant_role_opt_list
360 : %type <defelt> grant_role_opt
361 : %type <node> grant_role_opt_value
362 : %type <ival> opt_nowait_or_skip
363 :
364 : %type <list> OptRoleList AlterOptRoleList
365 : %type <defelt> CreateOptRoleElem AlterOptRoleElem
366 :
367 : %type <str> opt_type
368 : %type <str> foreign_server_version opt_foreign_server_version
369 : %type <str> opt_in_database
370 :
371 : %type <str> parameter_name
372 : %type <list> OptSchemaEltList parameter_name_list
373 :
374 : %type <chr> am_type
375 :
376 : %type <boolean> TriggerForSpec TriggerForType
377 : %type <ival> TriggerActionTime
378 : %type <list> TriggerEvents TriggerOneEvent
379 : %type <node> TriggerFuncArg
380 : %type <node> TriggerWhen
381 : %type <str> TransitionRelName
382 : %type <boolean> TransitionRowOrTable TransitionOldOrNew
383 : %type <node> TriggerTransition
384 :
385 : %type <list> event_trigger_when_list event_trigger_value_list
386 : %type <defelt> event_trigger_when_item
387 : %type <chr> enable_trigger
388 :
389 : %type <str> copy_file_name
390 : access_method_clause attr_name
391 : table_access_method_clause name cursor_name file_name
392 : cluster_index_specification
393 :
394 : %type <list> func_name handler_name qual_Op qual_all_Op subquery_Op
395 : opt_inline_handler opt_validator validator_clause
396 : opt_collate
397 :
398 : %type <range> qualified_name insert_target OptConstrFromTable
399 :
400 : %type <str> all_Op MathOp
401 :
402 : %type <str> row_security_cmd RowSecurityDefaultForCmd
403 : %type <boolean> RowSecurityDefaultPermissive
404 : %type <node> RowSecurityOptionalWithCheck RowSecurityOptionalExpr
405 : %type <list> RowSecurityDefaultToRole RowSecurityOptionalToRole
406 :
407 : %type <str> iso_level opt_encoding
408 : %type <rolespec> grantee
409 : %type <list> grantee_list
410 : %type <accesspriv> privilege
411 : %type <list> privileges privilege_list
412 : %type <privtarget> privilege_target
413 : %type <objwithargs> function_with_argtypes aggregate_with_argtypes operator_with_argtypes
414 : %type <list> function_with_argtypes_list aggregate_with_argtypes_list operator_with_argtypes_list
415 : %type <ival> defacl_privilege_target
416 : %type <defelt> DefACLOption
417 : %type <list> DefACLOptionList
418 : %type <ival> import_qualification_type
419 : %type <importqual> import_qualification
420 : %type <node> vacuum_relation
421 : %type <selectlimit> opt_select_limit select_limit limit_clause
422 :
423 : %type <list> parse_toplevel stmtmulti routine_body_stmt_list
424 : OptTableElementList TableElementList OptInherit definition
425 : OptTypedTableElementList TypedTableElementList
426 : reloptions opt_reloptions
427 : OptWith opt_definition func_args func_args_list
428 : func_args_with_defaults func_args_with_defaults_list
429 : aggr_args aggr_args_list
430 : func_as createfunc_opt_list opt_createfunc_opt_list alterfunc_opt_list
431 : old_aggr_definition old_aggr_list
432 : oper_argtypes RuleActionList RuleActionMulti
433 : opt_column_list columnList opt_name_list
434 : sort_clause opt_sort_clause sortby_list index_params
435 : stats_params
436 : opt_include opt_c_include index_including_params
437 : name_list role_list from_clause from_list opt_array_bounds
438 : qualified_name_list any_name any_name_list type_name_list
439 : any_operator expr_list attrs
440 : distinct_clause opt_distinct_clause
441 : target_list opt_target_list insert_column_list set_target_list
442 : merge_values_clause
443 : set_clause_list set_clause
444 : def_list operator_def_list indirection opt_indirection
445 : reloption_list TriggerFuncArgs opclass_item_list opclass_drop_list
446 : opclass_purpose opt_opfamily transaction_mode_list_or_empty
447 : OptTableFuncElementList TableFuncElementList opt_type_modifiers
448 : prep_type_clause
449 : execute_param_clause using_clause
450 : returning_with_clause returning_options
451 : opt_enum_val_list enum_val_list table_func_column_list
452 : create_generic_options alter_generic_options
453 : relation_expr_list dostmt_opt_list
454 : transform_element_list transform_type_list
455 : TriggerTransitions TriggerReferencing
456 : vacuum_relation_list opt_vacuum_relation_list
457 : drop_option_list pub_obj_list pub_all_obj_type_list
458 :
459 : %type <retclause> returning_clause
460 : %type <node> returning_option
461 : %type <retoptionkind> returning_option_kind
462 : %type <node> opt_routine_body
463 : %type <groupclause> group_clause
464 : %type <list> group_by_list
465 : %type <node> group_by_item empty_grouping_set rollup_clause cube_clause
466 : %type <node> grouping_sets_clause
467 :
468 : %type <list> opt_fdw_options fdw_options
469 : %type <defelt> fdw_option
470 :
471 : %type <range> OptTempTableName
472 : %type <into> into_clause create_as_target create_mv_target
473 :
474 : %type <defelt> createfunc_opt_item common_func_opt_item dostmt_opt_item
475 : %type <fun_param> func_arg func_arg_with_default table_func_column aggr_arg
476 : %type <fun_param_mode> arg_class
477 : %type <typnam> func_return func_type
478 :
479 : %type <boolean> opt_trusted opt_restart_seqs
480 : %type <ival> OptTemp
481 : %type <ival> OptNoLog
482 : %type <oncommit> OnCommitOption
483 :
484 : %type <ival> for_locking_strength
485 : %type <node> for_locking_item
486 : %type <list> for_locking_clause opt_for_locking_clause for_locking_items
487 : %type <list> locked_rels_list
488 : %type <setquantifier> set_quantifier
489 :
490 : %type <node> join_qual
491 : %type <jtype> join_type
492 :
493 : %type <list> extract_list overlay_list position_list
494 : %type <list> substr_list trim_list
495 : %type <list> opt_interval interval_second
496 : %type <str> unicode_normal_form
497 :
498 : %type <boolean> opt_instead
499 : %type <boolean> opt_unique opt_verbose opt_full
500 : %type <boolean> opt_freeze opt_analyze opt_default
501 : %type <defelt> opt_binary copy_delimiter
502 :
503 : %type <boolean> copy_from opt_program
504 :
505 : %type <ival> event cursor_options opt_hold opt_set_data
506 : %type <objtype> object_type_any_name object_type_name object_type_name_on_any_name
507 : drop_type_name
508 :
509 : %type <node> fetch_args select_limit_value
510 : offset_clause select_offset_value
511 : select_fetch_first_value I_or_F_const
512 : %type <ival> row_or_rows first_or_next
513 :
514 : %type <list> OptSeqOptList SeqOptList OptParenthesizedSeqOptList
515 : %type <defelt> SeqOptElem
516 :
517 : %type <istmt> insert_rest
518 : %type <infer> opt_conf_expr
519 : %type <onconflict> opt_on_conflict
520 : %type <mergewhen> merge_insert merge_update merge_delete
521 :
522 : %type <mergematch> merge_when_tgt_matched merge_when_tgt_not_matched
523 : %type <node> merge_when_clause opt_merge_when_condition
524 : %type <list> merge_when_list
525 :
526 : %type <vsetstmt> generic_set set_rest set_rest_more generic_reset reset_rest
527 : SetResetClause FunctionSetResetClause
528 :
529 : %type <node> TableElement TypedTableElement ConstraintElem DomainConstraintElem TableFuncElement
530 : %type <node> columnDef columnOptions optionalPeriodName
531 : %type <defelt> def_elem reloption_elem old_aggr_elem operator_def_elem
532 : %type <node> def_arg columnElem where_clause where_or_current_clause
533 : a_expr b_expr c_expr AexprConst indirection_el opt_slice_bound
534 : columnref having_clause func_table xmltable array_expr
535 : OptWhereClause operator_def_arg
536 : %type <list> opt_column_and_period_list
537 : %type <list> rowsfrom_item rowsfrom_list opt_col_def_list
538 : %type <boolean> opt_ordinality opt_without_overlaps
539 : %type <list> ExclusionConstraintList ExclusionConstraintElem
540 : %type <list> func_arg_list func_arg_list_opt
541 : %type <node> func_arg_expr
542 : %type <list> row explicit_row implicit_row type_list array_expr_list
543 : %type <node> case_expr case_arg when_clause case_default
544 : %type <list> when_clause_list
545 : %type <node> opt_search_clause opt_cycle_clause
546 : %type <ival> sub_type opt_materialized
547 : %type <node> NumericOnly
548 : %type <list> NumericOnly_list
549 : %type <alias> alias_clause opt_alias_clause opt_alias_clause_for_join_using
550 : %type <list> func_alias_clause
551 : %type <sortby> sortby
552 : %type <ielem> index_elem index_elem_options
553 : %type <selem> stats_param
554 : %type <node> table_ref
555 : %type <jexpr> joined_table
556 : %type <range> relation_expr
557 : %type <range> extended_relation_expr
558 : %type <range> relation_expr_opt_alias
559 : %type <node> tablesample_clause opt_repeatable_clause
560 : %type <target> target_el set_target insert_column_item
561 :
562 : %type <str> generic_option_name
563 : %type <node> generic_option_arg
564 : %type <defelt> generic_option_elem alter_generic_option_elem
565 : %type <list> generic_option_list alter_generic_option_list
566 :
567 : %type <ival> reindex_target_relation reindex_target_all
568 :
569 : %type <node> copy_generic_opt_arg copy_generic_opt_arg_list_item
570 : %type <defelt> copy_generic_opt_elem
571 : %type <list> copy_generic_opt_list copy_generic_opt_arg_list
572 : %type <list> copy_options
573 :
574 : %type <typnam> Typename SimpleTypename ConstTypename
575 : GenericType Numeric opt_float JsonType
576 : Character ConstCharacter
577 : CharacterWithLength CharacterWithoutLength
578 : ConstDatetime ConstInterval
579 : Bit ConstBit BitWithLength BitWithoutLength
580 : %type <str> character
581 : %type <str> extract_arg
582 : %type <boolean> opt_varying opt_timezone opt_no_inherit
583 :
584 : %type <ival> Iconst SignedIconst
585 : %type <str> Sconst comment_text notify_payload
586 : %type <str> RoleId opt_boolean_or_string
587 : %type <list> var_list
588 : %type <str> ColId ColLabel BareColLabel
589 : %type <str> NonReservedWord NonReservedWord_or_Sconst
590 : %type <str> var_name type_function_name param_name
591 : %type <str> createdb_opt_name plassign_target
592 : %type <node> var_value zone_value
593 : %type <rolespec> auth_ident RoleSpec opt_granted_by
594 : %type <publicationobjectspec> PublicationObjSpec
595 : %type <publicationallobjectspec> PublicationAllObjSpec
596 :
597 : %type <keyword> unreserved_keyword type_func_name_keyword
598 : %type <keyword> col_name_keyword reserved_keyword
599 : %type <keyword> bare_label_keyword
600 :
601 : %type <node> DomainConstraint TableConstraint TableLikeClause
602 : %type <ival> TableLikeOptionList TableLikeOption
603 : %type <str> column_compression opt_column_compression column_storage opt_column_storage
604 : %type <list> ColQualList
605 : %type <node> ColConstraint ColConstraintElem ConstraintAttr
606 : %type <ival> key_match
607 : %type <keyaction> key_delete key_update key_action
608 : %type <keyactions> key_actions
609 : %type <ival> ConstraintAttributeSpec ConstraintAttributeElem
610 : %type <str> ExistingIndex
611 :
612 : %type <list> constraints_set_list
613 : %type <boolean> constraints_set_mode
614 : %type <str> OptTableSpace OptConsTableSpace
615 : %type <rolespec> OptTableSpaceOwner
616 : %type <ival> opt_check_option
617 :
618 : %type <str> opt_provider security_label
619 :
620 : %type <target> xml_attribute_el
621 : %type <list> xml_attribute_list xml_attributes
622 : %type <node> xml_root_version opt_xml_root_standalone
623 : %type <node> xmlexists_argument
624 : %type <ival> document_or_content
625 : %type <boolean> xml_indent_option xml_whitespace_option
626 : %type <list> xmltable_column_list xmltable_column_option_list
627 : %type <node> xmltable_column_el
628 : %type <defelt> xmltable_column_option_el
629 : %type <list> xml_namespace_list
630 : %type <target> xml_namespace_el
631 :
632 : %type <node> func_application func_expr_common_subexpr
633 : %type <node> func_expr func_expr_windowless
634 : %type <node> common_table_expr
635 : %type <with> with_clause opt_with_clause
636 : %type <list> cte_list
637 :
638 : %type <list> within_group_clause
639 : %type <node> filter_clause
640 : %type <list> window_clause window_definition_list opt_partition_clause
641 : %type <windef> window_definition over_clause window_specification
642 : opt_frame_clause frame_extent frame_bound
643 : %type <ival> null_treatment opt_window_exclusion_clause
644 : %type <str> opt_existing_window_name
645 : %type <boolean> opt_if_not_exists
646 : %type <boolean> opt_unique_null_treatment
647 : %type <ival> generated_when override_kind opt_virtual_or_stored
648 : %type <partspec> PartitionSpec OptPartitionSpec
649 : %type <partelem> part_elem
650 : %type <list> part_params
651 : %type <partboundspec> PartitionBoundSpec
652 : %type <singlepartspec> SinglePartitionSpec
653 : %type <list> partitions_list
654 : %type <list> hash_partbound
655 : %type <defelt> hash_partbound_elem
656 :
657 : %type <node> json_format_clause
658 : json_format_clause_opt
659 : json_value_expr
660 : json_returning_clause_opt
661 : json_name_and_value
662 : json_aggregate_func
663 : json_argument
664 : json_behavior
665 : json_on_error_clause_opt
666 : json_table
667 : json_table_column_definition
668 : json_table_column_path_clause_opt
669 : %type <list> json_name_and_value_list
670 : json_value_expr_list
671 : json_array_aggregate_order_by_clause_opt
672 : json_arguments
673 : json_behavior_clause_opt
674 : json_passing_clause_opt
675 : json_table_column_definition_list
676 : %type <str> json_table_path_name_opt
677 : %type <ival> json_behavior_type
678 : json_predicate_type_constraint
679 : json_quotes_clause_opt
680 : json_wrapper_behavior
681 : %type <boolean> json_key_uniqueness_constraint_opt
682 : json_object_constructor_null_clause_opt
683 : json_array_constructor_null_clause_opt
684 :
685 : /*
686 : * Non-keyword token types. These are hard-wired into the "flex" lexer.
687 : * They must be listed first so that their numeric codes do not depend on
688 : * the set of keywords. PL/pgSQL depends on this so that it can share the
689 : * same lexer. If you add/change tokens here, fix PL/pgSQL to match!
690 : *
691 : * UIDENT and USCONST are reduced to IDENT and SCONST in parser.c, so that
692 : * they need no productions here; but we must assign token codes to them.
693 : *
694 : * DOT_DOT is unused in the core SQL grammar, and so will always provoke
695 : * parse errors. It is needed by PL/pgSQL.
696 : */
697 : %token <str> IDENT UIDENT FCONST SCONST USCONST BCONST XCONST Op
698 : %token <ival> ICONST PARAM
699 : %token TYPECAST DOT_DOT COLON_EQUALS EQUALS_GREATER
700 : %token LESS_EQUALS GREATER_EQUALS NOT_EQUALS
701 :
702 : /*
703 : * If you want to make any keyword changes, update the keyword table in
704 : * src/include/parser/kwlist.h and add new keywords to the appropriate one
705 : * of the reserved-or-not-so-reserved keyword lists, below; search
706 : * this file for "Keyword category lists".
707 : */
708 :
709 : /* ordinary key words in alphabetical order */
710 : %token <keyword> ABORT_P ABSENT ABSOLUTE_P ACCESS ACTION ADD_P ADMIN AFTER
711 : AGGREGATE ALL ALSO ALTER ALWAYS ANALYSE ANALYZE AND ANY ARRAY AS ASC
712 : ASENSITIVE ASSERTION ASSIGNMENT ASYMMETRIC ATOMIC AT ATTACH ATTRIBUTE AUTHORIZATION
713 :
714 : BACKWARD BEFORE BEGIN_P BETWEEN BIGINT BINARY BIT
715 : BOOLEAN_P BOTH BREADTH BY
716 :
717 : CACHE CALL CALLED CASCADE CASCADED CASE CAST CATALOG_P CHAIN CHAR_P
718 : CHARACTER CHARACTERISTICS CHECK CHECKPOINT CLASS CLOSE
719 : CLUSTER COALESCE COLLATE COLLATION COLUMN COLUMNS COMMENT COMMENTS COMMIT
720 : COMMITTED COMPRESSION CONCURRENTLY CONDITIONAL CONFIGURATION CONFLICT
721 : CONNECTION CONSTRAINT CONSTRAINTS CONTENT_P CONTINUE_P CONVERSION_P COPY
722 : COST CREATE CROSS CSV CUBE CURRENT_P
723 : CURRENT_CATALOG CURRENT_DATE CURRENT_ROLE CURRENT_SCHEMA
724 : CURRENT_TIME CURRENT_TIMESTAMP CURRENT_USER CURSOR CYCLE
725 :
726 : DATA_P DATABASE DAY_P DEALLOCATE DEC DECIMAL_P DECLARE DEFAULT DEFAULTS
727 : DEFERRABLE DEFERRED DEFINER DELETE_P DELIMITER DELIMITERS DEPENDS DEPTH DESC
728 : DETACH DICTIONARY DISABLE_P DISCARD DISTINCT DO DOCUMENT_P DOMAIN_P
729 : DOUBLE_P DROP
730 :
731 : EACH ELSE EMPTY_P ENABLE_P ENCODING ENCRYPTED END_P ENFORCED ENUM_P ERROR_P
732 : ESCAPE EVENT EXCEPT EXCLUDE EXCLUDING EXCLUSIVE EXECUTE EXISTS EXPLAIN
733 : EXPRESSION EXTENSION EXTERNAL EXTRACT
734 :
735 : FALSE_P FAMILY FETCH FILTER FINALIZE FIRST_P FLOAT_P FOLLOWING FOR
736 : FORCE FOREIGN FORMAT FORWARD FREEZE FROM FULL FUNCTION FUNCTIONS
737 :
738 : GENERATED GLOBAL GRANT GRANTED GREATEST GROUP_P GROUPING GROUPS
739 :
740 : HANDLER HAVING HEADER_P HOLD HOUR_P
741 :
742 : IDENTITY_P IF_P IGNORE_P ILIKE IMMEDIATE IMMUTABLE IMPLICIT_P IMPORT_P IN_P INCLUDE
743 : INCLUDING INCREMENT INDENT INDEX INDEXES INHERIT INHERITS INITIALLY INLINE_P
744 : INNER_P INOUT INPUT_P INSENSITIVE INSERT INSTEAD INT_P INTEGER
745 : INTERSECT INTERVAL INTO INVOKER IS ISNULL ISOLATION
746 :
747 : JOIN JSON JSON_ARRAY JSON_ARRAYAGG JSON_EXISTS JSON_OBJECT JSON_OBJECTAGG
748 : JSON_QUERY JSON_SCALAR JSON_SERIALIZE JSON_TABLE JSON_VALUE
749 :
750 : KEEP KEY KEYS
751 :
752 : LABEL LANGUAGE LARGE_P LAST_P LATERAL_P
753 : LEADING LEAKPROOF LEAST LEFT LEVEL LIKE LIMIT LISTEN LOAD LOCAL
754 : LOCALTIME LOCALTIMESTAMP LOCATION LOCK_P LOCKED LOGGED LSN_P
755 :
756 : MAPPING MATCH MATCHED MATERIALIZED MAXVALUE MERGE MERGE_ACTION METHOD
757 : MINUTE_P MINVALUE MODE MONTH_P MOVE
758 :
759 : NAME_P NAMES NATIONAL NATURAL NCHAR NESTED NEW NEXT NFC NFD NFKC NFKD NO
760 : NONE NORMALIZE NORMALIZED
761 : NOT NOTHING NOTIFY NOTNULL NOWAIT NULL_P NULLIF
762 : NULLS_P NUMERIC
763 :
764 : OBJECT_P OBJECTS_P OF OFF OFFSET OIDS OLD OMIT ON ONLY OPERATOR OPTION OPTIONS OR
765 : ORDER ORDINALITY OTHERS OUT_P OUTER_P
766 : OVER OVERLAPS OVERLAY OVERRIDING OWNED OWNER
767 :
768 : PARALLEL PARAMETER PARSER PARTIAL PARTITION PARTITIONS PASSING PASSWORD PATH
769 : PERIOD PLACING PLAN PLANS POLICY
770 : POSITION PRECEDING PRECISION PRESERVE PREPARE PREPARED PRIMARY
771 : PRIOR PRIVILEGES PROCEDURAL PROCEDURE PROCEDURES PROGRAM PUBLICATION
772 :
773 : QUOTE QUOTES
774 :
775 : RANGE READ REAL REASSIGN RECURSIVE REF_P REFERENCES REFERENCING
776 : REFRESH REINDEX RELATIVE_P RELEASE RENAME REPEATABLE REPLACE REPLICA
777 : RESET RESPECT_P RESTART RESTRICT RETURN RETURNING RETURNS REVOKE RIGHT ROLE ROLLBACK ROLLUP
778 : ROUTINE ROUTINES ROW ROWS RULE
779 :
780 : SAVEPOINT SCALAR SCHEMA SCHEMAS SCROLL SEARCH SECOND_P SECURITY SELECT
781 : SEQUENCE SEQUENCES
782 : SERIALIZABLE SERVER SESSION SESSION_USER SET SETS SETOF SHARE SHOW
783 : SIMILAR SIMPLE SKIP SMALLINT SNAPSHOT SOME SPLIT SOURCE SQL_P STABLE STANDALONE_P
784 : START STATEMENT STATISTICS STDIN STDOUT STORAGE STORED STRICT_P STRING_P STRIP_P
785 : SUBSCRIPTION SUBSTRING SUPPORT SYMMETRIC SYSID SYSTEM_P SYSTEM_USER
786 :
787 : TABLE TABLES TABLESAMPLE TABLESPACE TARGET TEMP TEMPLATE TEMPORARY TEXT_P THEN
788 : TIES TIME TIMESTAMP TO TRAILING TRANSACTION TRANSFORM
789 : TREAT TRIGGER TRIM TRUE_P
790 : TRUNCATE TRUSTED TYPE_P TYPES_P
791 :
792 : UESCAPE UNBOUNDED UNCONDITIONAL UNCOMMITTED UNENCRYPTED UNION UNIQUE UNKNOWN
793 : UNLISTEN UNLOGGED UNTIL UPDATE USER USING
794 :
795 : VACUUM VALID VALIDATE VALIDATOR VALUE_P VALUES VARCHAR VARIADIC VARYING
796 : VERBOSE VERSION_P VIEW VIEWS VIRTUAL VOLATILE
797 :
798 : WAIT WHEN WHERE WHITESPACE_P WINDOW WITH WITHIN WITHOUT WORK WRAPPER WRITE
799 :
800 : XML_P XMLATTRIBUTES XMLCONCAT XMLELEMENT XMLEXISTS XMLFOREST XMLNAMESPACES
801 : XMLPARSE XMLPI XMLROOT XMLSERIALIZE XMLTABLE
802 :
803 : YEAR_P YES_P
804 :
805 : ZONE
806 :
807 : /*
808 : * The grammar thinks these are keywords, but they are not in the kwlist.h
809 : * list and so can never be entered directly. The filter in parser.c
810 : * creates these tokens when required (based on looking one token ahead).
811 : *
812 : * NOT_LA exists so that productions such as NOT LIKE can be given the same
813 : * precedence as LIKE; otherwise they'd effectively have the same precedence
814 : * as NOT, at least with respect to their left-hand subexpression.
815 : * FORMAT_LA, NULLS_LA, WITH_LA, and WITHOUT_LA are needed to make the grammar
816 : * LALR(1).
817 : */
818 : %token FORMAT_LA NOT_LA NULLS_LA WITH_LA WITHOUT_LA
819 :
820 : /*
821 : * The grammar likewise thinks these tokens are keywords, but they are never
822 : * generated by the scanner. Rather, they can be injected by parser.c as
823 : * the initial token of the string (using the lookahead-token mechanism
824 : * implemented there). This provides a way to tell the grammar to parse
825 : * something other than the usual list of SQL commands.
826 : */
827 : %token MODE_TYPE_NAME
828 : %token MODE_PLPGSQL_EXPR
829 : %token MODE_PLPGSQL_ASSIGN1
830 : %token MODE_PLPGSQL_ASSIGN2
831 : %token MODE_PLPGSQL_ASSIGN3
832 :
833 :
834 : /* Precedence: lowest to highest */
835 : %left UNION EXCEPT
836 : %left INTERSECT
837 : %left OR
838 : %left AND
839 : %right NOT
840 : %nonassoc IS ISNULL NOTNULL /* IS sets precedence for IS NULL, etc */
841 : %nonassoc '<' '>' '=' LESS_EQUALS GREATER_EQUALS NOT_EQUALS
842 : %nonassoc BETWEEN IN_P LIKE ILIKE SIMILAR NOT_LA
843 : %nonassoc ESCAPE /* ESCAPE must be just above LIKE/ILIKE/SIMILAR */
844 :
845 : /*
846 : * Sometimes it is necessary to assign precedence to keywords that are not
847 : * really part of the operator hierarchy, in order to resolve grammar
848 : * ambiguities. It's best to avoid doing so whenever possible, because such
849 : * assignments have global effect and may hide ambiguities besides the one
850 : * you intended to solve. (Attaching a precedence to a single rule with
851 : * %prec is far safer and should be preferred.) If you must give precedence
852 : * to a new keyword, try very hard to give it the same precedence as IDENT.
853 : * If the keyword has IDENT's precedence then it clearly acts the same as
854 : * non-keywords and other similar keywords, thus reducing the risk of
855 : * unexpected precedence effects.
856 : *
857 : * We used to need to assign IDENT an explicit precedence just less than Op,
858 : * to support target_el without AS. While that's not really necessary since
859 : * we removed postfix operators, we continue to do so because it provides a
860 : * reference point for a precedence level that we can assign to other
861 : * keywords that lack a natural precedence level.
862 : *
863 : * We need to do this for PARTITION, RANGE, ROWS, and GROUPS to support
864 : * opt_existing_window_name (see comment there).
865 : *
866 : * The frame_bound productions UNBOUNDED PRECEDING and UNBOUNDED FOLLOWING
867 : * are even messier: since UNBOUNDED is an unreserved keyword (per spec!),
868 : * there is no principled way to distinguish these from the productions
869 : * a_expr PRECEDING/FOLLOWING. We hack this up by giving UNBOUNDED slightly
870 : * lower precedence than PRECEDING and FOLLOWING. At present this doesn't
871 : * appear to cause UNBOUNDED to be treated differently from other unreserved
872 : * keywords anywhere else in the grammar, but it's definitely risky. We can
873 : * blame any funny behavior of UNBOUNDED on the SQL standard, though.
874 : *
875 : * To support CUBE and ROLLUP in GROUP BY without reserving them, we give them
876 : * an explicit priority lower than '(', so that a rule with CUBE '(' will shift
877 : * rather than reducing a conflicting rule that takes CUBE as a function name.
878 : * Using the same precedence as IDENT seems right for the reasons given above.
879 : *
880 : * SET is likewise assigned the same precedence as IDENT, to support the
881 : * relation_expr_opt_alias production (see comment there).
882 : *
883 : * KEYS, OBJECT_P, SCALAR, VALUE_P, WITH, and WITHOUT are similarly assigned
884 : * the same precedence as IDENT. This allows resolving conflicts in the
885 : * json_predicate_type_constraint and json_key_uniqueness_constraint_opt
886 : * productions (see comments there).
887 : *
888 : * Like the UNBOUNDED PRECEDING/FOLLOWING case, NESTED is assigned a lower
889 : * precedence than PATH to fix ambiguity in the json_table production.
890 : */
891 : %nonassoc UNBOUNDED NESTED /* ideally would have same precedence as IDENT */
892 : %nonassoc IDENT PARTITION RANGE ROWS GROUPS PRECEDING FOLLOWING CUBE ROLLUP
893 : SET KEYS OBJECT_P SCALAR VALUE_P WITH WITHOUT PATH
894 : %left Op OPERATOR /* multi-character ops and user-defined operators */
895 : %left '+' '-'
896 : %left '*' '/' '%'
897 : %left '^'
898 : /* Unary Operators */
899 : %left AT /* sets precedence for AT TIME ZONE, AT LOCAL */
900 : %left COLLATE
901 : %right UMINUS
902 : %left '[' ']'
903 : %left '(' ')'
904 : %left TYPECAST
905 : %left '.'
906 : /*
907 : * These might seem to be low-precedence, but actually they are not part
908 : * of the arithmetic hierarchy at all in their use as JOIN operators.
909 : * We make them high-precedence to support their use as function names.
910 : * They wouldn't be given a precedence at all, were it not that we need
911 : * left-associativity among the JOIN rules themselves.
912 : */
913 : %left JOIN CROSS LEFT FULL RIGHT INNER_P NATURAL
914 :
915 : %%
916 :
917 : /*
918 : * The target production for the whole parse.
919 : *
920 : * Ordinarily we parse a list of statements, but if we see one of the
921 : * special MODE_XXX symbols as first token, we parse something else.
922 : * The options here correspond to enum RawParseMode, which see for details.
923 : */
924 : parse_toplevel:
925 : stmtmulti
926 : {
927 748180 : pg_yyget_extra(yyscanner)->parsetree = $1;
928 : (void) yynerrs; /* suppress compiler warning */
929 : }
930 : | MODE_TYPE_NAME Typename
931 : {
932 10226 : pg_yyget_extra(yyscanner)->parsetree = list_make1($2);
933 : }
934 : | MODE_PLPGSQL_EXPR PLpgSQL_Expr
935 : {
936 34290 : pg_yyget_extra(yyscanner)->parsetree =
937 34290 : list_make1(makeRawStmt($2, @2));
938 : }
939 : | MODE_PLPGSQL_ASSIGN1 PLAssignStmt
940 : {
941 6380 : PLAssignStmt *n = (PLAssignStmt *) $2;
942 :
943 6380 : n->nnames = 1;
944 6380 : pg_yyget_extra(yyscanner)->parsetree =
945 6380 : list_make1(makeRawStmt((Node *) n, @2));
946 : }
947 : | MODE_PLPGSQL_ASSIGN2 PLAssignStmt
948 : {
949 686 : PLAssignStmt *n = (PLAssignStmt *) $2;
950 :
951 686 : n->nnames = 2;
952 686 : pg_yyget_extra(yyscanner)->parsetree =
953 686 : list_make1(makeRawStmt((Node *) n, @2));
954 : }
955 : | MODE_PLPGSQL_ASSIGN3 PLAssignStmt
956 : {
957 28 : PLAssignStmt *n = (PLAssignStmt *) $2;
958 :
959 28 : n->nnames = 3;
960 28 : pg_yyget_extra(yyscanner)->parsetree =
961 28 : list_make1(makeRawStmt((Node *) n, @2));
962 : }
963 : ;
964 :
965 : /*
966 : * At top level, we wrap each stmt with a RawStmt node carrying start location
967 : * and length of the stmt's text.
968 : * We also take care to discard empty statements entirely (which among other
969 : * things dodges the problem of assigning them a location).
970 : */
971 : stmtmulti: stmtmulti ';' toplevel_stmt
972 : {
973 616832 : if ($1 != NIL)
974 : {
975 : /* update length of previous stmt */
976 615802 : updateRawStmtEnd(llast_node(RawStmt, $1), @2);
977 : }
978 616832 : if ($3 != NULL)
979 60238 : $$ = lappend($1, makeRawStmt($3, @3));
980 : else
981 556594 : $$ = $1;
982 : }
983 : | toplevel_stmt
984 : {
985 748188 : if ($1 != NULL)
986 746366 : $$ = list_make1(makeRawStmt($1, @1));
987 : else
988 1822 : $$ = NIL;
989 : }
990 : ;
991 :
992 : /*
993 : * toplevel_stmt includes BEGIN and END. stmt does not include them, because
994 : * those words have different meanings in function bodies.
995 : */
996 : toplevel_stmt:
997 : stmt
998 : | TransactionStmtLegacy
999 : ;
1000 :
1001 : stmt:
1002 : AlterEventTrigStmt
1003 : | AlterCollationStmt
1004 : | AlterDatabaseStmt
1005 : | AlterDatabaseSetStmt
1006 : | AlterDefaultPrivilegesStmt
1007 : | AlterDomainStmt
1008 : | AlterEnumStmt
1009 : | AlterExtensionStmt
1010 : | AlterExtensionContentsStmt
1011 : | AlterFdwStmt
1012 : | AlterForeignServerStmt
1013 : | AlterFunctionStmt
1014 : | AlterGroupStmt
1015 : | AlterObjectDependsStmt
1016 : | AlterObjectSchemaStmt
1017 : | AlterOwnerStmt
1018 : | AlterOperatorStmt
1019 : | AlterTypeStmt
1020 : | AlterPolicyStmt
1021 : | AlterSeqStmt
1022 : | AlterSystemStmt
1023 : | AlterTableStmt
1024 : | AlterTblSpcStmt
1025 : | AlterCompositeTypeStmt
1026 : | AlterPublicationStmt
1027 : | AlterRoleSetStmt
1028 : | AlterRoleStmt
1029 : | AlterSubscriptionStmt
1030 : | AlterStatsStmt
1031 : | AlterTSConfigurationStmt
1032 : | AlterTSDictionaryStmt
1033 : | AlterUserMappingStmt
1034 : | AnalyzeStmt
1035 : | CallStmt
1036 : | CheckPointStmt
1037 : | ClosePortalStmt
1038 : | ClusterStmt
1039 : | CommentStmt
1040 : | ConstraintsSetStmt
1041 : | CopyStmt
1042 : | CreateAmStmt
1043 : | CreateAsStmt
1044 : | CreateAssertionStmt
1045 : | CreateCastStmt
1046 : | CreateConversionStmt
1047 : | CreateDomainStmt
1048 : | CreateExtensionStmt
1049 : | CreateFdwStmt
1050 : | CreateForeignServerStmt
1051 : | CreateForeignTableStmt
1052 : | CreateFunctionStmt
1053 : | CreateGroupStmt
1054 : | CreateMatViewStmt
1055 : | CreateOpClassStmt
1056 : | CreateOpFamilyStmt
1057 : | CreatePublicationStmt
1058 : | AlterOpFamilyStmt
1059 : | CreatePolicyStmt
1060 : | CreatePLangStmt
1061 : | CreateSchemaStmt
1062 : | CreateSeqStmt
1063 : | CreateStmt
1064 : | CreateSubscriptionStmt
1065 : | CreateStatsStmt
1066 : | CreateTableSpaceStmt
1067 : | CreateTransformStmt
1068 : | CreateTrigStmt
1069 : | CreateEventTrigStmt
1070 : | CreateRoleStmt
1071 : | CreateUserStmt
1072 : | CreateUserMappingStmt
1073 : | CreatedbStmt
1074 : | DeallocateStmt
1075 : | DeclareCursorStmt
1076 : | DefineStmt
1077 : | DeleteStmt
1078 : | DiscardStmt
1079 : | DoStmt
1080 : | DropCastStmt
1081 : | DropOpClassStmt
1082 : | DropOpFamilyStmt
1083 : | DropOwnedStmt
1084 : | DropStmt
1085 : | DropSubscriptionStmt
1086 : | DropTableSpaceStmt
1087 : | DropTransformStmt
1088 : | DropRoleStmt
1089 : | DropUserMappingStmt
1090 : | DropdbStmt
1091 : | ExecuteStmt
1092 : | ExplainStmt
1093 : | FetchStmt
1094 : | GrantStmt
1095 : | GrantRoleStmt
1096 : | ImportForeignSchemaStmt
1097 : | IndexStmt
1098 : | InsertStmt
1099 : | ListenStmt
1100 : | RefreshMatViewStmt
1101 : | LoadStmt
1102 : | LockStmt
1103 : | MergeStmt
1104 : | NotifyStmt
1105 : | PrepareStmt
1106 : | ReassignOwnedStmt
1107 : | ReindexStmt
1108 : | RemoveAggrStmt
1109 : | RemoveFuncStmt
1110 : | RemoveOperStmt
1111 : | RenameStmt
1112 : | RevokeStmt
1113 : | RevokeRoleStmt
1114 : | RuleStmt
1115 : | SecLabelStmt
1116 : | SelectStmt
1117 : | TransactionStmt
1118 : | TruncateStmt
1119 : | UnlistenStmt
1120 : | UpdateStmt
1121 : | VacuumStmt
1122 : | VariableResetStmt
1123 : | VariableSetStmt
1124 : | VariableShowStmt
1125 : | ViewStmt
1126 : | WaitStmt
1127 : | /*EMPTY*/
1128 558434 : { $$ = NULL; }
1129 : ;
1130 :
1131 : /*
1132 : * Generic supporting productions for DDL
1133 : */
1134 : opt_single_name:
1135 5438 : ColId { $$ = $1; }
1136 1578 : | /* EMPTY */ { $$ = NULL; }
1137 : ;
1138 :
1139 : opt_qualified_name:
1140 1990 : any_name { $$ = $1; }
1141 16012 : | /*EMPTY*/ { $$ = NIL; }
1142 : ;
1143 :
1144 : opt_concurrently:
1145 1010 : CONCURRENTLY { $$ = true; }
1146 7758 : | /*EMPTY*/ { $$ = false; }
1147 : ;
1148 :
1149 : opt_drop_behavior:
1150 2074 : CASCADE { $$ = DROP_CASCADE; }
1151 170 : | RESTRICT { $$ = DROP_RESTRICT; }
1152 40448 : | /* EMPTY */ { $$ = DROP_RESTRICT; /* default */ }
1153 : ;
1154 :
1155 : opt_utility_option_list:
1156 366 : '(' utility_option_list ')' { $$ = $2; }
1157 5936 : | /* EMPTY */ { $$ = NULL; }
1158 : ;
1159 :
1160 : utility_option_list:
1161 : utility_option_elem
1162 : {
1163 23514 : $$ = list_make1($1);
1164 : }
1165 : | utility_option_list ',' utility_option_elem
1166 : {
1167 13666 : $$ = lappend($1, $3);
1168 : }
1169 : ;
1170 :
1171 : utility_option_elem:
1172 : utility_option_name utility_option_arg
1173 : {
1174 37180 : $$ = makeDefElem($1, $2, @1);
1175 : }
1176 : ;
1177 :
1178 : utility_option_name:
1179 33108 : NonReservedWord { $$ = $1; }
1180 3930 : | analyze_keyword { $$ = "analyze"; }
1181 148 : | FORMAT_LA { $$ = "format"; }
1182 : ;
1183 :
1184 : utility_option_arg:
1185 18356 : opt_boolean_or_string { $$ = (Node *) makeString($1); }
1186 384 : | NumericOnly { $$ = (Node *) $1; }
1187 18440 : | /* EMPTY */ { $$ = NULL; }
1188 : ;
1189 :
1190 : /*****************************************************************************
1191 : *
1192 : * CALL statement
1193 : *
1194 : *****************************************************************************/
1195 :
1196 : CallStmt: CALL func_application
1197 : {
1198 628 : CallStmt *n = makeNode(CallStmt);
1199 :
1200 628 : n->funccall = castNode(FuncCall, $2);
1201 628 : $$ = (Node *) n;
1202 : }
1203 : ;
1204 :
1205 : /*****************************************************************************
1206 : *
1207 : * Create a new Postgres DBMS role
1208 : *
1209 : *****************************************************************************/
1210 :
1211 : CreateRoleStmt:
1212 : CREATE ROLE RoleId opt_with OptRoleList
1213 : {
1214 1416 : CreateRoleStmt *n = makeNode(CreateRoleStmt);
1215 :
1216 1416 : n->stmt_type = ROLESTMT_ROLE;
1217 1416 : n->role = $3;
1218 1416 : n->options = $5;
1219 1416 : $$ = (Node *) n;
1220 : }
1221 : ;
1222 :
1223 :
1224 : opt_with: WITH
1225 : | WITH_LA
1226 : | /*EMPTY*/
1227 : ;
1228 :
1229 : /*
1230 : * Options for CREATE ROLE and ALTER ROLE (also used by CREATE/ALTER USER
1231 : * for backwards compatibility). Note: the only option required by SQL99
1232 : * is "WITH ADMIN name".
1233 : */
1234 : OptRoleList:
1235 1180 : OptRoleList CreateOptRoleElem { $$ = lappend($1, $2); }
1236 1896 : | /* EMPTY */ { $$ = NIL; }
1237 : ;
1238 :
1239 : AlterOptRoleList:
1240 784 : AlterOptRoleList AlterOptRoleElem { $$ = lappend($1, $2); }
1241 436 : | /* EMPTY */ { $$ = NIL; }
1242 : ;
1243 :
1244 : AlterOptRoleElem:
1245 : PASSWORD Sconst
1246 : {
1247 188 : $$ = makeDefElem("password",
1248 188 : (Node *) makeString($2), @1);
1249 : }
1250 : | PASSWORD NULL_P
1251 : {
1252 12 : $$ = makeDefElem("password", NULL, @1);
1253 : }
1254 : | ENCRYPTED PASSWORD Sconst
1255 : {
1256 : /*
1257 : * These days, passwords are always stored in encrypted
1258 : * form, so there is no difference between PASSWORD and
1259 : * ENCRYPTED PASSWORD.
1260 : */
1261 16 : $$ = makeDefElem("password",
1262 16 : (Node *) makeString($3), @1);
1263 : }
1264 : | UNENCRYPTED PASSWORD Sconst
1265 : {
1266 0 : ereport(ERROR,
1267 : (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
1268 : errmsg("UNENCRYPTED PASSWORD is no longer supported"),
1269 : errhint("Remove UNENCRYPTED to store the password in encrypted form instead."),
1270 : parser_errposition(@1)));
1271 : }
1272 : | INHERIT
1273 : {
1274 112 : $$ = makeDefElem("inherit", (Node *) makeBoolean(true), @1);
1275 : }
1276 : | CONNECTION LIMIT SignedIconst
1277 : {
1278 24 : $$ = makeDefElem("connectionlimit", (Node *) makeInteger($3), @1);
1279 : }
1280 : | VALID UNTIL Sconst
1281 : {
1282 2 : $$ = makeDefElem("validUntil", (Node *) makeString($3), @1);
1283 : }
1284 : /* Supported but not documented for roles, for use by ALTER GROUP. */
1285 : | USER role_list
1286 : {
1287 6 : $$ = makeDefElem("rolemembers", (Node *) $2, @1);
1288 : }
1289 : | IDENT
1290 : {
1291 : /*
1292 : * We handle identifiers that aren't parser keywords with
1293 : * the following special-case codes, to avoid bloating the
1294 : * size of the main parser.
1295 : */
1296 1454 : if (strcmp($1, "superuser") == 0)
1297 194 : $$ = makeDefElem("superuser", (Node *) makeBoolean(true), @1);
1298 1260 : else if (strcmp($1, "nosuperuser") == 0)
1299 114 : $$ = makeDefElem("superuser", (Node *) makeBoolean(false), @1);
1300 1146 : else if (strcmp($1, "createrole") == 0)
1301 104 : $$ = makeDefElem("createrole", (Node *) makeBoolean(true), @1);
1302 1042 : else if (strcmp($1, "nocreaterole") == 0)
1303 52 : $$ = makeDefElem("createrole", (Node *) makeBoolean(false), @1);
1304 990 : else if (strcmp($1, "replication") == 0)
1305 132 : $$ = makeDefElem("isreplication", (Node *) makeBoolean(true), @1);
1306 858 : else if (strcmp($1, "noreplication") == 0)
1307 110 : $$ = makeDefElem("isreplication", (Node *) makeBoolean(false), @1);
1308 748 : else if (strcmp($1, "createdb") == 0)
1309 94 : $$ = makeDefElem("createdb", (Node *) makeBoolean(true), @1);
1310 654 : else if (strcmp($1, "nocreatedb") == 0)
1311 60 : $$ = makeDefElem("createdb", (Node *) makeBoolean(false), @1);
1312 594 : else if (strcmp($1, "login") == 0)
1313 290 : $$ = makeDefElem("canlogin", (Node *) makeBoolean(true), @1);
1314 304 : else if (strcmp($1, "nologin") == 0)
1315 102 : $$ = makeDefElem("canlogin", (Node *) makeBoolean(false), @1);
1316 202 : else if (strcmp($1, "bypassrls") == 0)
1317 84 : $$ = makeDefElem("bypassrls", (Node *) makeBoolean(true), @1);
1318 118 : else if (strcmp($1, "nobypassrls") == 0)
1319 82 : $$ = makeDefElem("bypassrls", (Node *) makeBoolean(false), @1);
1320 36 : else if (strcmp($1, "noinherit") == 0)
1321 : {
1322 : /*
1323 : * Note that INHERIT is a keyword, so it's handled by main parser, but
1324 : * NOINHERIT is handled here.
1325 : */
1326 36 : $$ = makeDefElem("inherit", (Node *) makeBoolean(false), @1);
1327 : }
1328 : else
1329 0 : ereport(ERROR,
1330 : (errcode(ERRCODE_SYNTAX_ERROR),
1331 : errmsg("unrecognized role option \"%s\"", $1),
1332 : parser_errposition(@1)));
1333 : }
1334 : ;
1335 :
1336 : CreateOptRoleElem:
1337 1030 : AlterOptRoleElem { $$ = $1; }
1338 : /* The following are not supported by ALTER ROLE/USER/GROUP */
1339 : | SYSID Iconst
1340 : {
1341 6 : $$ = makeDefElem("sysid", (Node *) makeInteger($2), @1);
1342 : }
1343 : | ADMIN role_list
1344 : {
1345 22 : $$ = makeDefElem("adminmembers", (Node *) $2, @1);
1346 : }
1347 : | ROLE role_list
1348 : {
1349 22 : $$ = makeDefElem("rolemembers", (Node *) $2, @1);
1350 : }
1351 : | IN_P ROLE role_list
1352 : {
1353 100 : $$ = makeDefElem("addroleto", (Node *) $3, @1);
1354 : }
1355 : | IN_P GROUP_P role_list
1356 : {
1357 0 : $$ = makeDefElem("addroleto", (Node *) $3, @1);
1358 : }
1359 : ;
1360 :
1361 :
1362 : /*****************************************************************************
1363 : *
1364 : * Create a new Postgres DBMS user (role with implied login ability)
1365 : *
1366 : *****************************************************************************/
1367 :
1368 : CreateUserStmt:
1369 : CREATE USER RoleId opt_with OptRoleList
1370 : {
1371 456 : CreateRoleStmt *n = makeNode(CreateRoleStmt);
1372 :
1373 456 : n->stmt_type = ROLESTMT_USER;
1374 456 : n->role = $3;
1375 456 : n->options = $5;
1376 456 : $$ = (Node *) n;
1377 : }
1378 : ;
1379 :
1380 :
1381 : /*****************************************************************************
1382 : *
1383 : * Alter a postgresql DBMS role
1384 : *
1385 : *****************************************************************************/
1386 :
1387 : AlterRoleStmt:
1388 : ALTER ROLE RoleSpec opt_with AlterOptRoleList
1389 : {
1390 344 : AlterRoleStmt *n = makeNode(AlterRoleStmt);
1391 :
1392 344 : n->role = $3;
1393 344 : n->action = +1; /* add, if there are members */
1394 344 : n->options = $5;
1395 344 : $$ = (Node *) n;
1396 : }
1397 : | ALTER USER RoleSpec opt_with AlterOptRoleList
1398 : {
1399 92 : AlterRoleStmt *n = makeNode(AlterRoleStmt);
1400 :
1401 92 : n->role = $3;
1402 92 : n->action = +1; /* add, if there are members */
1403 92 : n->options = $5;
1404 92 : $$ = (Node *) n;
1405 : }
1406 : ;
1407 :
1408 : opt_in_database:
1409 94 : /* EMPTY */ { $$ = NULL; }
1410 4 : | IN_P DATABASE name { $$ = $3; }
1411 : ;
1412 :
1413 : AlterRoleSetStmt:
1414 : ALTER ROLE RoleSpec opt_in_database SetResetClause
1415 : {
1416 58 : AlterRoleSetStmt *n = makeNode(AlterRoleSetStmt);
1417 :
1418 58 : n->role = $3;
1419 58 : n->database = $4;
1420 58 : n->setstmt = $5;
1421 58 : $$ = (Node *) n;
1422 : }
1423 : | ALTER ROLE ALL opt_in_database SetResetClause
1424 : {
1425 4 : AlterRoleSetStmt *n = makeNode(AlterRoleSetStmt);
1426 :
1427 4 : n->role = NULL;
1428 4 : n->database = $4;
1429 4 : n->setstmt = $5;
1430 4 : $$ = (Node *) n;
1431 : }
1432 : | ALTER USER RoleSpec opt_in_database SetResetClause
1433 : {
1434 28 : AlterRoleSetStmt *n = makeNode(AlterRoleSetStmt);
1435 :
1436 28 : n->role = $3;
1437 28 : n->database = $4;
1438 28 : n->setstmt = $5;
1439 28 : $$ = (Node *) n;
1440 : }
1441 : | ALTER USER ALL opt_in_database SetResetClause
1442 : {
1443 4 : AlterRoleSetStmt *n = makeNode(AlterRoleSetStmt);
1444 :
1445 4 : n->role = NULL;
1446 4 : n->database = $4;
1447 4 : n->setstmt = $5;
1448 4 : $$ = (Node *) n;
1449 : }
1450 : ;
1451 :
1452 :
1453 : /*****************************************************************************
1454 : *
1455 : * Drop a postgresql DBMS role
1456 : *
1457 : * XXX Ideally this would have CASCADE/RESTRICT options, but a role
1458 : * might own objects in multiple databases, and there is presently no way to
1459 : * implement cascading to other databases. So we always behave as RESTRICT.
1460 : *****************************************************************************/
1461 :
1462 : DropRoleStmt:
1463 : DROP ROLE role_list
1464 : {
1465 1130 : DropRoleStmt *n = makeNode(DropRoleStmt);
1466 :
1467 1130 : n->missing_ok = false;
1468 1130 : n->roles = $3;
1469 1130 : $$ = (Node *) n;
1470 : }
1471 : | DROP ROLE IF_P EXISTS role_list
1472 : {
1473 134 : DropRoleStmt *n = makeNode(DropRoleStmt);
1474 :
1475 134 : n->missing_ok = true;
1476 134 : n->roles = $5;
1477 134 : $$ = (Node *) n;
1478 : }
1479 : | DROP USER role_list
1480 : {
1481 404 : DropRoleStmt *n = makeNode(DropRoleStmt);
1482 :
1483 404 : n->missing_ok = false;
1484 404 : n->roles = $3;
1485 404 : $$ = (Node *) n;
1486 : }
1487 : | DROP USER IF_P EXISTS role_list
1488 : {
1489 36 : DropRoleStmt *n = makeNode(DropRoleStmt);
1490 :
1491 36 : n->roles = $5;
1492 36 : n->missing_ok = true;
1493 36 : $$ = (Node *) n;
1494 : }
1495 : | DROP GROUP_P role_list
1496 : {
1497 36 : DropRoleStmt *n = makeNode(DropRoleStmt);
1498 :
1499 36 : n->missing_ok = false;
1500 36 : n->roles = $3;
1501 36 : $$ = (Node *) n;
1502 : }
1503 : | DROP GROUP_P IF_P EXISTS role_list
1504 : {
1505 6 : DropRoleStmt *n = makeNode(DropRoleStmt);
1506 :
1507 6 : n->missing_ok = true;
1508 6 : n->roles = $5;
1509 6 : $$ = (Node *) n;
1510 : }
1511 : ;
1512 :
1513 :
1514 : /*****************************************************************************
1515 : *
1516 : * Create a postgresql group (role without login ability)
1517 : *
1518 : *****************************************************************************/
1519 :
1520 : CreateGroupStmt:
1521 : CREATE GROUP_P RoleId opt_with OptRoleList
1522 : {
1523 24 : CreateRoleStmt *n = makeNode(CreateRoleStmt);
1524 :
1525 24 : n->stmt_type = ROLESTMT_GROUP;
1526 24 : n->role = $3;
1527 24 : n->options = $5;
1528 24 : $$ = (Node *) n;
1529 : }
1530 : ;
1531 :
1532 :
1533 : /*****************************************************************************
1534 : *
1535 : * Alter a postgresql group
1536 : *
1537 : *****************************************************************************/
1538 :
1539 : AlterGroupStmt:
1540 : ALTER GROUP_P RoleSpec add_drop USER role_list
1541 : {
1542 42 : AlterRoleStmt *n = makeNode(AlterRoleStmt);
1543 :
1544 42 : n->role = $3;
1545 42 : n->action = $4;
1546 42 : n->options = list_make1(makeDefElem("rolemembers",
1547 : (Node *) $6, @6));
1548 42 : $$ = (Node *) n;
1549 : }
1550 : ;
1551 :
1552 94 : add_drop: ADD_P { $$ = +1; }
1553 224 : | DROP { $$ = -1; }
1554 : ;
1555 :
1556 :
1557 : /*****************************************************************************
1558 : *
1559 : * Manipulate a schema
1560 : *
1561 : *****************************************************************************/
1562 :
1563 : CreateSchemaStmt:
1564 : CREATE SCHEMA opt_single_name AUTHORIZATION RoleSpec OptSchemaEltList
1565 : {
1566 158 : CreateSchemaStmt *n = makeNode(CreateSchemaStmt);
1567 :
1568 : /* One can omit the schema name or the authorization id. */
1569 158 : n->schemaname = $3;
1570 158 : n->authrole = $5;
1571 158 : n->schemaElts = $6;
1572 158 : n->if_not_exists = false;
1573 158 : $$ = (Node *) n;
1574 : }
1575 : | CREATE SCHEMA ColId OptSchemaEltList
1576 : {
1577 918 : CreateSchemaStmt *n = makeNode(CreateSchemaStmt);
1578 :
1579 : /* ...but not both */
1580 918 : n->schemaname = $3;
1581 918 : n->authrole = NULL;
1582 918 : n->schemaElts = $4;
1583 918 : n->if_not_exists = false;
1584 918 : $$ = (Node *) n;
1585 : }
1586 : | CREATE SCHEMA IF_P NOT EXISTS opt_single_name AUTHORIZATION RoleSpec OptSchemaEltList
1587 : {
1588 18 : CreateSchemaStmt *n = makeNode(CreateSchemaStmt);
1589 :
1590 : /* schema name can be omitted here, too */
1591 18 : n->schemaname = $6;
1592 18 : n->authrole = $8;
1593 18 : if ($9 != NIL)
1594 0 : ereport(ERROR,
1595 : (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
1596 : errmsg("CREATE SCHEMA IF NOT EXISTS cannot include schema elements"),
1597 : parser_errposition(@9)));
1598 18 : n->schemaElts = $9;
1599 18 : n->if_not_exists = true;
1600 18 : $$ = (Node *) n;
1601 : }
1602 : | CREATE SCHEMA IF_P NOT EXISTS ColId OptSchemaEltList
1603 : {
1604 34 : CreateSchemaStmt *n = makeNode(CreateSchemaStmt);
1605 :
1606 : /* ...but not here */
1607 34 : n->schemaname = $6;
1608 34 : n->authrole = NULL;
1609 34 : if ($7 != NIL)
1610 6 : ereport(ERROR,
1611 : (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
1612 : errmsg("CREATE SCHEMA IF NOT EXISTS cannot include schema elements"),
1613 : parser_errposition(@7)));
1614 28 : n->schemaElts = $7;
1615 28 : n->if_not_exists = true;
1616 28 : $$ = (Node *) n;
1617 : }
1618 : ;
1619 :
1620 : OptSchemaEltList:
1621 : OptSchemaEltList schema_stmt
1622 : {
1623 570 : $$ = lappend($1, $2);
1624 : }
1625 : | /* EMPTY */
1626 1128 : { $$ = NIL; }
1627 : ;
1628 :
1629 : /*
1630 : * schema_stmt are the ones that can show up inside a CREATE SCHEMA
1631 : * statement (in addition to by themselves).
1632 : */
1633 : schema_stmt:
1634 : CreateStmt
1635 : | IndexStmt
1636 : | CreateSeqStmt
1637 : | CreateTrigStmt
1638 : | GrantStmt
1639 : | ViewStmt
1640 : ;
1641 :
1642 :
1643 : /*****************************************************************************
1644 : *
1645 : * Set PG internal variable
1646 : * SET name TO 'var_value'
1647 : * Include SQL syntax (thomas 1997-10-22):
1648 : * SET TIME ZONE 'var_value'
1649 : *
1650 : *****************************************************************************/
1651 :
1652 : VariableSetStmt:
1653 : SET set_rest
1654 : {
1655 22346 : VariableSetStmt *n = $2;
1656 :
1657 22346 : n->is_local = false;
1658 22346 : $$ = (Node *) n;
1659 : }
1660 : | SET LOCAL set_rest
1661 : {
1662 1290 : VariableSetStmt *n = $3;
1663 :
1664 1290 : n->is_local = true;
1665 1290 : $$ = (Node *) n;
1666 : }
1667 : | SET SESSION set_rest
1668 : {
1669 84 : VariableSetStmt *n = $3;
1670 :
1671 84 : n->is_local = false;
1672 84 : $$ = (Node *) n;
1673 : }
1674 : ;
1675 :
1676 : set_rest:
1677 : TRANSACTION transaction_mode_list
1678 : {
1679 586 : VariableSetStmt *n = makeNode(VariableSetStmt);
1680 :
1681 586 : n->kind = VAR_SET_MULTI;
1682 586 : n->name = "TRANSACTION";
1683 586 : n->args = $2;
1684 586 : n->jumble_args = true;
1685 586 : n->location = -1;
1686 586 : $$ = n;
1687 : }
1688 : | SESSION CHARACTERISTICS AS TRANSACTION transaction_mode_list
1689 : {
1690 18 : VariableSetStmt *n = makeNode(VariableSetStmt);
1691 :
1692 18 : n->kind = VAR_SET_MULTI;
1693 18 : n->name = "SESSION CHARACTERISTICS";
1694 18 : n->args = $5;
1695 18 : n->jumble_args = true;
1696 18 : n->location = -1;
1697 18 : $$ = n;
1698 : }
1699 : | set_rest_more
1700 : ;
1701 :
1702 : generic_set:
1703 : var_name TO var_list
1704 : {
1705 5240 : VariableSetStmt *n = makeNode(VariableSetStmt);
1706 :
1707 5240 : n->kind = VAR_SET_VALUE;
1708 5240 : n->name = $1;
1709 5240 : n->args = $3;
1710 5240 : n->location = @3;
1711 5240 : $$ = n;
1712 : }
1713 : | var_name '=' var_list
1714 : {
1715 15456 : VariableSetStmt *n = makeNode(VariableSetStmt);
1716 :
1717 15456 : n->kind = VAR_SET_VALUE;
1718 15456 : n->name = $1;
1719 15456 : n->args = $3;
1720 15456 : n->location = @3;
1721 15456 : $$ = n;
1722 : }
1723 : | var_name TO NULL_P
1724 : {
1725 8 : VariableSetStmt *n = makeNode(VariableSetStmt);
1726 :
1727 8 : n->kind = VAR_SET_VALUE;
1728 8 : n->name = $1;
1729 8 : n->args = list_make1(makeNullAConst(@3));
1730 8 : n->location = @3;
1731 8 : $$ = n;
1732 : }
1733 : | var_name '=' NULL_P
1734 : {
1735 18 : VariableSetStmt *n = makeNode(VariableSetStmt);
1736 :
1737 18 : n->kind = VAR_SET_VALUE;
1738 18 : n->name = $1;
1739 18 : n->args = list_make1(makeNullAConst(@3));
1740 18 : n->location = @3;
1741 18 : $$ = n;
1742 : }
1743 : | var_name TO DEFAULT
1744 : {
1745 136 : VariableSetStmt *n = makeNode(VariableSetStmt);
1746 :
1747 136 : n->kind = VAR_SET_DEFAULT;
1748 136 : n->name = $1;
1749 136 : n->location = -1;
1750 136 : $$ = n;
1751 : }
1752 : | var_name '=' DEFAULT
1753 : {
1754 10 : VariableSetStmt *n = makeNode(VariableSetStmt);
1755 :
1756 10 : n->kind = VAR_SET_DEFAULT;
1757 10 : n->name = $1;
1758 10 : n->location = -1;
1759 10 : $$ = n;
1760 : }
1761 : ;
1762 :
1763 : set_rest_more: /* Generic SET syntaxes: */
1764 20734 : generic_set {$$ = $1;}
1765 : | var_name FROM CURRENT_P
1766 : {
1767 4 : VariableSetStmt *n = makeNode(VariableSetStmt);
1768 :
1769 4 : n->kind = VAR_SET_CURRENT;
1770 4 : n->name = $1;
1771 4 : n->location = -1;
1772 4 : $$ = n;
1773 : }
1774 : /* Special syntaxes mandated by SQL standard: */
1775 : | TIME ZONE zone_value
1776 : {
1777 104 : VariableSetStmt *n = makeNode(VariableSetStmt);
1778 :
1779 104 : n->kind = VAR_SET_VALUE;
1780 104 : n->name = "timezone";
1781 104 : n->location = -1;
1782 104 : n->jumble_args = true;
1783 104 : if ($3 != NULL)
1784 88 : n->args = list_make1($3);
1785 : else
1786 16 : n->kind = VAR_SET_DEFAULT;
1787 104 : $$ = n;
1788 : }
1789 : | CATALOG_P Sconst
1790 : {
1791 0 : ereport(ERROR,
1792 : (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
1793 : errmsg("current database cannot be changed"),
1794 : parser_errposition(@2)));
1795 : $$ = NULL; /*not reached*/
1796 : }
1797 : | SCHEMA Sconst
1798 : {
1799 4 : VariableSetStmt *n = makeNode(VariableSetStmt);
1800 :
1801 4 : n->kind = VAR_SET_VALUE;
1802 4 : n->name = "search_path";
1803 4 : n->args = list_make1(makeStringConst($2, @2));
1804 4 : n->location = @2;
1805 4 : $$ = n;
1806 : }
1807 : | NAMES opt_encoding
1808 : {
1809 0 : VariableSetStmt *n = makeNode(VariableSetStmt);
1810 :
1811 0 : n->kind = VAR_SET_VALUE;
1812 0 : n->name = "client_encoding";
1813 0 : n->location = @2;
1814 0 : if ($2 != NULL)
1815 0 : n->args = list_make1(makeStringConst($2, @2));
1816 : else
1817 0 : n->kind = VAR_SET_DEFAULT;
1818 0 : $$ = n;
1819 : }
1820 : | ROLE NonReservedWord_or_Sconst
1821 : {
1822 960 : VariableSetStmt *n = makeNode(VariableSetStmt);
1823 :
1824 960 : n->kind = VAR_SET_VALUE;
1825 960 : n->name = "role";
1826 960 : n->args = list_make1(makeStringConst($2, @2));
1827 960 : n->location = @2;
1828 960 : $$ = n;
1829 : }
1830 : | SESSION AUTHORIZATION NonReservedWord_or_Sconst
1831 : {
1832 2694 : VariableSetStmt *n = makeNode(VariableSetStmt);
1833 :
1834 2694 : n->kind = VAR_SET_VALUE;
1835 2694 : n->name = "session_authorization";
1836 2694 : n->args = list_make1(makeStringConst($3, @3));
1837 2694 : n->location = @3;
1838 2694 : $$ = n;
1839 : }
1840 : | SESSION AUTHORIZATION DEFAULT
1841 : {
1842 4 : VariableSetStmt *n = makeNode(VariableSetStmt);
1843 :
1844 4 : n->kind = VAR_SET_DEFAULT;
1845 4 : n->name = "session_authorization";
1846 4 : n->location = -1;
1847 4 : $$ = n;
1848 : }
1849 : | XML_P OPTION document_or_content
1850 : {
1851 16 : VariableSetStmt *n = makeNode(VariableSetStmt);
1852 :
1853 16 : n->kind = VAR_SET_VALUE;
1854 16 : n->name = "xmloption";
1855 16 : n->args = list_make1(makeStringConst($3 == XMLOPTION_DOCUMENT ? "DOCUMENT" : "CONTENT", @3));
1856 16 : n->jumble_args = true;
1857 16 : n->location = -1;
1858 16 : $$ = n;
1859 : }
1860 : /* Special syntaxes invented by PostgreSQL: */
1861 : | TRANSACTION SNAPSHOT Sconst
1862 : {
1863 44 : VariableSetStmt *n = makeNode(VariableSetStmt);
1864 :
1865 44 : n->kind = VAR_SET_MULTI;
1866 44 : n->name = "TRANSACTION SNAPSHOT";
1867 44 : n->args = list_make1(makeStringConst($3, @3));
1868 44 : n->location = @3;
1869 44 : $$ = n;
1870 : }
1871 : ;
1872 :
1873 25794 : var_name: ColId { $$ = $1; }
1874 : | var_name '.' ColId
1875 496 : { $$ = psprintf("%s.%s", $1, $3); }
1876 : ;
1877 :
1878 20696 : var_list: var_value { $$ = list_make1($1); }
1879 302 : | var_list ',' var_value { $$ = lappend($1, $3); }
1880 : ;
1881 :
1882 : var_value: opt_boolean_or_string
1883 15552 : { $$ = makeStringConst($1, @1); }
1884 : | NumericOnly
1885 5446 : { $$ = makeAConst($1, @1); }
1886 : ;
1887 :
1888 0 : iso_level: READ UNCOMMITTED { $$ = "read uncommitted"; }
1889 1028 : | READ COMMITTED { $$ = "read committed"; }
1890 2686 : | REPEATABLE READ { $$ = "repeatable read"; }
1891 3252 : | SERIALIZABLE { $$ = "serializable"; }
1892 : ;
1893 :
1894 : opt_boolean_or_string:
1895 716 : TRUE_P { $$ = "true"; }
1896 1508 : | FALSE_P { $$ = "false"; }
1897 2284 : | ON { $$ = "on"; }
1898 : /*
1899 : * OFF is also accepted as a boolean value, but is handled by
1900 : * the NonReservedWord rule. The action for booleans and strings
1901 : * is the same, so we don't need to distinguish them here.
1902 : */
1903 31812 : | NonReservedWord_or_Sconst { $$ = $1; }
1904 : ;
1905 :
1906 : /* Timezone values can be:
1907 : * - a string such as 'pst8pdt'
1908 : * - an identifier such as "pst8pdt"
1909 : * - an integer or floating point number
1910 : * - a time interval per SQL99
1911 : * ColId gives reduce/reduce errors against ConstInterval and LOCAL,
1912 : * so use IDENT (meaning we reject anything that is a key word).
1913 : */
1914 : zone_value:
1915 : Sconst
1916 : {
1917 60 : $$ = makeStringConst($1, @1);
1918 : }
1919 : | IDENT
1920 : {
1921 4 : $$ = makeStringConst($1, @1);
1922 : }
1923 : | ConstInterval Sconst opt_interval
1924 : {
1925 0 : TypeName *t = $1;
1926 :
1927 0 : if ($3 != NIL)
1928 : {
1929 0 : A_Const *n = (A_Const *) linitial($3);
1930 :
1931 0 : if ((n->val.ival.ival & ~(INTERVAL_MASK(HOUR) | INTERVAL_MASK(MINUTE))) != 0)
1932 0 : ereport(ERROR,
1933 : (errcode(ERRCODE_SYNTAX_ERROR),
1934 : errmsg("time zone interval must be HOUR or HOUR TO MINUTE"),
1935 : parser_errposition(@3)));
1936 : }
1937 0 : t->typmods = $3;
1938 0 : $$ = makeStringConstCast($2, @2, t);
1939 : }
1940 : | ConstInterval '(' Iconst ')' Sconst
1941 : {
1942 0 : TypeName *t = $1;
1943 :
1944 0 : t->typmods = list_make2(makeIntConst(INTERVAL_FULL_RANGE, -1),
1945 : makeIntConst($3, @3));
1946 0 : $$ = makeStringConstCast($5, @5, t);
1947 : }
1948 24 : | NumericOnly { $$ = makeAConst($1, @1); }
1949 14 : | DEFAULT { $$ = NULL; }
1950 2 : | LOCAL { $$ = NULL; }
1951 : ;
1952 :
1953 : opt_encoding:
1954 0 : Sconst { $$ = $1; }
1955 0 : | DEFAULT { $$ = NULL; }
1956 0 : | /*EMPTY*/ { $$ = NULL; }
1957 : ;
1958 :
1959 : NonReservedWord_or_Sconst:
1960 55812 : NonReservedWord { $$ = $1; }
1961 5794 : | Sconst { $$ = $1; }
1962 : ;
1963 :
1964 : VariableResetStmt:
1965 4902 : RESET reset_rest { $$ = (Node *) $2; }
1966 : ;
1967 :
1968 : reset_rest:
1969 4008 : generic_reset { $$ = $1; }
1970 : | TIME ZONE
1971 : {
1972 14 : VariableSetStmt *n = makeNode(VariableSetStmt);
1973 :
1974 14 : n->kind = VAR_RESET;
1975 14 : n->name = "timezone";
1976 14 : n->location = -1;
1977 14 : $$ = n;
1978 : }
1979 : | TRANSACTION ISOLATION LEVEL
1980 : {
1981 0 : VariableSetStmt *n = makeNode(VariableSetStmt);
1982 :
1983 0 : n->kind = VAR_RESET;
1984 0 : n->name = "transaction_isolation";
1985 0 : n->location = -1;
1986 0 : $$ = n;
1987 : }
1988 : | SESSION AUTHORIZATION
1989 : {
1990 880 : VariableSetStmt *n = makeNode(VariableSetStmt);
1991 :
1992 880 : n->kind = VAR_RESET;
1993 880 : n->name = "session_authorization";
1994 880 : n->location = -1;
1995 880 : $$ = n;
1996 : }
1997 : ;
1998 :
1999 : generic_reset:
2000 : var_name
2001 : {
2002 4038 : VariableSetStmt *n = makeNode(VariableSetStmt);
2003 :
2004 4038 : n->kind = VAR_RESET;
2005 4038 : n->name = $1;
2006 4038 : n->location = -1;
2007 4038 : $$ = n;
2008 : }
2009 : | ALL
2010 : {
2011 28 : VariableSetStmt *n = makeNode(VariableSetStmt);
2012 :
2013 28 : n->kind = VAR_RESET_ALL;
2014 28 : n->location = -1;
2015 28 : $$ = n;
2016 : }
2017 : ;
2018 :
2019 : /* SetResetClause allows SET or RESET without LOCAL */
2020 : SetResetClause:
2021 1306 : SET set_rest { $$ = $2; }
2022 42 : | VariableResetStmt { $$ = (VariableSetStmt *) $1; }
2023 : ;
2024 :
2025 : /* SetResetClause allows SET or RESET without LOCAL */
2026 : FunctionSetResetClause:
2027 142 : SET set_rest_more { $$ = $2; }
2028 12 : | VariableResetStmt { $$ = (VariableSetStmt *) $1; }
2029 : ;
2030 :
2031 :
2032 : VariableShowStmt:
2033 : SHOW var_name
2034 : {
2035 884 : VariableShowStmt *n = makeNode(VariableShowStmt);
2036 :
2037 884 : n->name = $2;
2038 884 : $$ = (Node *) n;
2039 : }
2040 : | SHOW TIME ZONE
2041 : {
2042 10 : VariableShowStmt *n = makeNode(VariableShowStmt);
2043 :
2044 10 : n->name = "timezone";
2045 10 : $$ = (Node *) n;
2046 : }
2047 : | SHOW TRANSACTION ISOLATION LEVEL
2048 : {
2049 4 : VariableShowStmt *n = makeNode(VariableShowStmt);
2050 :
2051 4 : n->name = "transaction_isolation";
2052 4 : $$ = (Node *) n;
2053 : }
2054 : | SHOW SESSION AUTHORIZATION
2055 : {
2056 0 : VariableShowStmt *n = makeNode(VariableShowStmt);
2057 :
2058 0 : n->name = "session_authorization";
2059 0 : $$ = (Node *) n;
2060 : }
2061 : | SHOW ALL
2062 : {
2063 0 : VariableShowStmt *n = makeNode(VariableShowStmt);
2064 :
2065 0 : n->name = "all";
2066 0 : $$ = (Node *) n;
2067 : }
2068 : ;
2069 :
2070 :
2071 : ConstraintsSetStmt:
2072 : SET CONSTRAINTS constraints_set_list constraints_set_mode
2073 : {
2074 104 : ConstraintsSetStmt *n = makeNode(ConstraintsSetStmt);
2075 :
2076 104 : n->constraints = $3;
2077 104 : n->deferred = $4;
2078 104 : $$ = (Node *) n;
2079 : }
2080 : ;
2081 :
2082 : constraints_set_list:
2083 56 : ALL { $$ = NIL; }
2084 48 : | qualified_name_list { $$ = $1; }
2085 : ;
2086 :
2087 : constraints_set_mode:
2088 68 : DEFERRED { $$ = true; }
2089 36 : | IMMEDIATE { $$ = false; }
2090 : ;
2091 :
2092 :
2093 : /*
2094 : * Checkpoint statement
2095 : */
2096 : CheckPointStmt:
2097 : CHECKPOINT opt_utility_option_list
2098 : {
2099 250 : CheckPointStmt *n = makeNode(CheckPointStmt);
2100 :
2101 250 : $$ = (Node *) n;
2102 250 : n->options = $2;
2103 : }
2104 : ;
2105 :
2106 :
2107 : /*****************************************************************************
2108 : *
2109 : * DISCARD { ALL | TEMP | PLANS | SEQUENCES }
2110 : *
2111 : *****************************************************************************/
2112 :
2113 : DiscardStmt:
2114 : DISCARD ALL
2115 : {
2116 6 : DiscardStmt *n = makeNode(DiscardStmt);
2117 :
2118 6 : n->target = DISCARD_ALL;
2119 6 : $$ = (Node *) n;
2120 : }
2121 : | DISCARD TEMP
2122 : {
2123 14 : DiscardStmt *n = makeNode(DiscardStmt);
2124 :
2125 14 : n->target = DISCARD_TEMP;
2126 14 : $$ = (Node *) n;
2127 : }
2128 : | DISCARD TEMPORARY
2129 : {
2130 0 : DiscardStmt *n = makeNode(DiscardStmt);
2131 :
2132 0 : n->target = DISCARD_TEMP;
2133 0 : $$ = (Node *) n;
2134 : }
2135 : | DISCARD PLANS
2136 : {
2137 4 : DiscardStmt *n = makeNode(DiscardStmt);
2138 :
2139 4 : n->target = DISCARD_PLANS;
2140 4 : $$ = (Node *) n;
2141 : }
2142 : | DISCARD SEQUENCES
2143 : {
2144 12 : DiscardStmt *n = makeNode(DiscardStmt);
2145 :
2146 12 : n->target = DISCARD_SEQUENCES;
2147 12 : $$ = (Node *) n;
2148 : }
2149 :
2150 : ;
2151 :
2152 :
2153 : /*****************************************************************************
2154 : *
2155 : * ALTER [ TABLE | INDEX | SEQUENCE | VIEW | MATERIALIZED VIEW | FOREIGN TABLE ] variations
2156 : *
2157 : * Note: we accept all subcommands for each of the variants, and sort
2158 : * out what's really legal at execution time.
2159 : *****************************************************************************/
2160 :
2161 : AlterTableStmt:
2162 : ALTER TABLE relation_expr alter_table_cmds
2163 : {
2164 26940 : AlterTableStmt *n = makeNode(AlterTableStmt);
2165 :
2166 26940 : n->relation = $3;
2167 26940 : n->cmds = $4;
2168 26940 : n->objtype = OBJECT_TABLE;
2169 26940 : n->missing_ok = false;
2170 26940 : $$ = (Node *) n;
2171 : }
2172 : | ALTER TABLE IF_P EXISTS relation_expr alter_table_cmds
2173 : {
2174 54 : AlterTableStmt *n = makeNode(AlterTableStmt);
2175 :
2176 54 : n->relation = $5;
2177 54 : n->cmds = $6;
2178 54 : n->objtype = OBJECT_TABLE;
2179 54 : n->missing_ok = true;
2180 54 : $$ = (Node *) n;
2181 : }
2182 : | ALTER TABLE relation_expr partition_cmd
2183 : {
2184 3848 : AlterTableStmt *n = makeNode(AlterTableStmt);
2185 :
2186 3848 : n->relation = $3;
2187 3848 : n->cmds = list_make1($4);
2188 3848 : n->objtype = OBJECT_TABLE;
2189 3848 : n->missing_ok = false;
2190 3848 : $$ = (Node *) n;
2191 : }
2192 : | ALTER TABLE IF_P EXISTS relation_expr partition_cmd
2193 : {
2194 0 : AlterTableStmt *n = makeNode(AlterTableStmt);
2195 :
2196 0 : n->relation = $5;
2197 0 : n->cmds = list_make1($6);
2198 0 : n->objtype = OBJECT_TABLE;
2199 0 : n->missing_ok = true;
2200 0 : $$ = (Node *) n;
2201 : }
2202 : | ALTER TABLE ALL IN_P TABLESPACE name SET TABLESPACE name opt_nowait
2203 : {
2204 : AlterTableMoveAllStmt *n =
2205 12 : makeNode(AlterTableMoveAllStmt);
2206 :
2207 12 : n->orig_tablespacename = $6;
2208 12 : n->objtype = OBJECT_TABLE;
2209 12 : n->roles = NIL;
2210 12 : n->new_tablespacename = $9;
2211 12 : n->nowait = $10;
2212 12 : $$ = (Node *) n;
2213 : }
2214 : | ALTER TABLE ALL IN_P TABLESPACE name OWNED BY role_list SET TABLESPACE name opt_nowait
2215 : {
2216 : AlterTableMoveAllStmt *n =
2217 0 : makeNode(AlterTableMoveAllStmt);
2218 :
2219 0 : n->orig_tablespacename = $6;
2220 0 : n->objtype = OBJECT_TABLE;
2221 0 : n->roles = $9;
2222 0 : n->new_tablespacename = $12;
2223 0 : n->nowait = $13;
2224 0 : $$ = (Node *) n;
2225 : }
2226 : | ALTER INDEX qualified_name alter_table_cmds
2227 : {
2228 228 : AlterTableStmt *n = makeNode(AlterTableStmt);
2229 :
2230 228 : n->relation = $3;
2231 228 : n->cmds = $4;
2232 228 : n->objtype = OBJECT_INDEX;
2233 228 : n->missing_ok = false;
2234 228 : $$ = (Node *) n;
2235 : }
2236 : | ALTER INDEX IF_P EXISTS qualified_name alter_table_cmds
2237 : {
2238 0 : AlterTableStmt *n = makeNode(AlterTableStmt);
2239 :
2240 0 : n->relation = $5;
2241 0 : n->cmds = $6;
2242 0 : n->objtype = OBJECT_INDEX;
2243 0 : n->missing_ok = true;
2244 0 : $$ = (Node *) n;
2245 : }
2246 : | ALTER INDEX qualified_name index_partition_cmd
2247 : {
2248 390 : AlterTableStmt *n = makeNode(AlterTableStmt);
2249 :
2250 390 : n->relation = $3;
2251 390 : n->cmds = list_make1($4);
2252 390 : n->objtype = OBJECT_INDEX;
2253 390 : n->missing_ok = false;
2254 390 : $$ = (Node *) n;
2255 : }
2256 : | ALTER INDEX ALL IN_P TABLESPACE name SET TABLESPACE name opt_nowait
2257 : {
2258 : AlterTableMoveAllStmt *n =
2259 6 : makeNode(AlterTableMoveAllStmt);
2260 :
2261 6 : n->orig_tablespacename = $6;
2262 6 : n->objtype = OBJECT_INDEX;
2263 6 : n->roles = NIL;
2264 6 : n->new_tablespacename = $9;
2265 6 : n->nowait = $10;
2266 6 : $$ = (Node *) n;
2267 : }
2268 : | ALTER INDEX ALL IN_P TABLESPACE name OWNED BY role_list SET TABLESPACE name opt_nowait
2269 : {
2270 : AlterTableMoveAllStmt *n =
2271 0 : makeNode(AlterTableMoveAllStmt);
2272 :
2273 0 : n->orig_tablespacename = $6;
2274 0 : n->objtype = OBJECT_INDEX;
2275 0 : n->roles = $9;
2276 0 : n->new_tablespacename = $12;
2277 0 : n->nowait = $13;
2278 0 : $$ = (Node *) n;
2279 : }
2280 : | ALTER SEQUENCE qualified_name alter_table_cmds
2281 : {
2282 94 : AlterTableStmt *n = makeNode(AlterTableStmt);
2283 :
2284 94 : n->relation = $3;
2285 94 : n->cmds = $4;
2286 94 : n->objtype = OBJECT_SEQUENCE;
2287 94 : n->missing_ok = false;
2288 94 : $$ = (Node *) n;
2289 : }
2290 : | ALTER SEQUENCE IF_P EXISTS qualified_name alter_table_cmds
2291 : {
2292 0 : AlterTableStmt *n = makeNode(AlterTableStmt);
2293 :
2294 0 : n->relation = $5;
2295 0 : n->cmds = $6;
2296 0 : n->objtype = OBJECT_SEQUENCE;
2297 0 : n->missing_ok = true;
2298 0 : $$ = (Node *) n;
2299 : }
2300 : | ALTER VIEW qualified_name alter_table_cmds
2301 : {
2302 254 : AlterTableStmt *n = makeNode(AlterTableStmt);
2303 :
2304 254 : n->relation = $3;
2305 254 : n->cmds = $4;
2306 254 : n->objtype = OBJECT_VIEW;
2307 254 : n->missing_ok = false;
2308 254 : $$ = (Node *) n;
2309 : }
2310 : | ALTER VIEW IF_P EXISTS qualified_name alter_table_cmds
2311 : {
2312 0 : AlterTableStmt *n = makeNode(AlterTableStmt);
2313 :
2314 0 : n->relation = $5;
2315 0 : n->cmds = $6;
2316 0 : n->objtype = OBJECT_VIEW;
2317 0 : n->missing_ok = true;
2318 0 : $$ = (Node *) n;
2319 : }
2320 : | ALTER MATERIALIZED VIEW qualified_name alter_table_cmds
2321 : {
2322 48 : AlterTableStmt *n = makeNode(AlterTableStmt);
2323 :
2324 48 : n->relation = $4;
2325 48 : n->cmds = $5;
2326 48 : n->objtype = OBJECT_MATVIEW;
2327 48 : n->missing_ok = false;
2328 48 : $$ = (Node *) n;
2329 : }
2330 : | ALTER MATERIALIZED VIEW IF_P EXISTS qualified_name alter_table_cmds
2331 : {
2332 0 : AlterTableStmt *n = makeNode(AlterTableStmt);
2333 :
2334 0 : n->relation = $6;
2335 0 : n->cmds = $7;
2336 0 : n->objtype = OBJECT_MATVIEW;
2337 0 : n->missing_ok = true;
2338 0 : $$ = (Node *) n;
2339 : }
2340 : | ALTER MATERIALIZED VIEW ALL IN_P TABLESPACE name SET TABLESPACE name opt_nowait
2341 : {
2342 : AlterTableMoveAllStmt *n =
2343 12 : makeNode(AlterTableMoveAllStmt);
2344 :
2345 12 : n->orig_tablespacename = $7;
2346 12 : n->objtype = OBJECT_MATVIEW;
2347 12 : n->roles = NIL;
2348 12 : n->new_tablespacename = $10;
2349 12 : n->nowait = $11;
2350 12 : $$ = (Node *) n;
2351 : }
2352 : | ALTER MATERIALIZED VIEW ALL IN_P TABLESPACE name OWNED BY role_list SET TABLESPACE name opt_nowait
2353 : {
2354 : AlterTableMoveAllStmt *n =
2355 0 : makeNode(AlterTableMoveAllStmt);
2356 :
2357 0 : n->orig_tablespacename = $7;
2358 0 : n->objtype = OBJECT_MATVIEW;
2359 0 : n->roles = $10;
2360 0 : n->new_tablespacename = $13;
2361 0 : n->nowait = $14;
2362 0 : $$ = (Node *) n;
2363 : }
2364 : | ALTER FOREIGN TABLE relation_expr alter_table_cmds
2365 : {
2366 378 : AlterTableStmt *n = makeNode(AlterTableStmt);
2367 :
2368 378 : n->relation = $4;
2369 378 : n->cmds = $5;
2370 378 : n->objtype = OBJECT_FOREIGN_TABLE;
2371 378 : n->missing_ok = false;
2372 378 : $$ = (Node *) n;
2373 : }
2374 : | ALTER FOREIGN TABLE IF_P EXISTS relation_expr alter_table_cmds
2375 : {
2376 108 : AlterTableStmt *n = makeNode(AlterTableStmt);
2377 :
2378 108 : n->relation = $6;
2379 108 : n->cmds = $7;
2380 108 : n->objtype = OBJECT_FOREIGN_TABLE;
2381 108 : n->missing_ok = true;
2382 108 : $$ = (Node *) n;
2383 : }
2384 : ;
2385 :
2386 : alter_table_cmds:
2387 28104 : alter_table_cmd { $$ = list_make1($1); }
2388 1020 : | alter_table_cmds ',' alter_table_cmd { $$ = lappend($1, $3); }
2389 : ;
2390 :
2391 : partitions_list:
2392 390 : SinglePartitionSpec { $$ = list_make1($1); }
2393 714 : | partitions_list ',' SinglePartitionSpec { $$ = lappend($1, $3); }
2394 : ;
2395 :
2396 : SinglePartitionSpec:
2397 : PARTITION qualified_name PartitionBoundSpec
2398 : {
2399 1104 : SinglePartitionSpec *n = makeNode(SinglePartitionSpec);
2400 :
2401 1104 : n->name = $2;
2402 1104 : n->bound = $3;
2403 :
2404 1104 : $$ = n;
2405 : }
2406 : ;
2407 :
2408 : partition_cmd:
2409 : /* ALTER TABLE <name> ATTACH PARTITION <table_name> FOR VALUES */
2410 : ATTACH PARTITION qualified_name PartitionBoundSpec
2411 : {
2412 2560 : AlterTableCmd *n = makeNode(AlterTableCmd);
2413 2560 : PartitionCmd *cmd = makeNode(PartitionCmd);
2414 :
2415 2560 : n->subtype = AT_AttachPartition;
2416 2560 : cmd->name = $3;
2417 2560 : cmd->bound = $4;
2418 2560 : cmd->partlist = NIL;
2419 2560 : cmd->concurrent = false;
2420 2560 : n->def = (Node *) cmd;
2421 :
2422 2560 : $$ = (Node *) n;
2423 : }
2424 : /* ALTER TABLE <name> DETACH PARTITION <partition_name> [CONCURRENTLY] */
2425 : | DETACH PARTITION qualified_name opt_concurrently
2426 : {
2427 608 : AlterTableCmd *n = makeNode(AlterTableCmd);
2428 608 : PartitionCmd *cmd = makeNode(PartitionCmd);
2429 :
2430 608 : n->subtype = AT_DetachPartition;
2431 608 : cmd->name = $3;
2432 608 : cmd->bound = NULL;
2433 608 : cmd->partlist = NIL;
2434 608 : cmd->concurrent = $4;
2435 608 : n->def = (Node *) cmd;
2436 :
2437 608 : $$ = (Node *) n;
2438 : }
2439 : | DETACH PARTITION qualified_name FINALIZE
2440 : {
2441 20 : AlterTableCmd *n = makeNode(AlterTableCmd);
2442 20 : PartitionCmd *cmd = makeNode(PartitionCmd);
2443 :
2444 20 : n->subtype = AT_DetachPartitionFinalize;
2445 20 : cmd->name = $3;
2446 20 : cmd->bound = NULL;
2447 20 : cmd->partlist = NIL;
2448 20 : cmd->concurrent = false;
2449 20 : n->def = (Node *) cmd;
2450 20 : $$ = (Node *) n;
2451 : }
2452 : /* ALTER TABLE <name> SPLIT PARTITION <partition_name> INTO () */
2453 : | SPLIT PARTITION qualified_name INTO '(' partitions_list ')'
2454 : {
2455 390 : AlterTableCmd *n = makeNode(AlterTableCmd);
2456 390 : PartitionCmd *cmd = makeNode(PartitionCmd);
2457 :
2458 390 : n->subtype = AT_SplitPartition;
2459 390 : cmd->name = $3;
2460 390 : cmd->bound = NULL;
2461 390 : cmd->partlist = $6;
2462 390 : cmd->concurrent = false;
2463 390 : n->def = (Node *) cmd;
2464 390 : $$ = (Node *) n;
2465 : }
2466 : /* ALTER TABLE <name> MERGE PARTITIONS () INTO <partition_name> */
2467 : | MERGE PARTITIONS '(' qualified_name_list ')' INTO qualified_name
2468 : {
2469 270 : AlterTableCmd *n = makeNode(AlterTableCmd);
2470 270 : PartitionCmd *cmd = makeNode(PartitionCmd);
2471 :
2472 270 : n->subtype = AT_MergePartitions;
2473 270 : cmd->name = $7;
2474 270 : cmd->bound = NULL;
2475 270 : cmd->partlist = $4;
2476 270 : cmd->concurrent = false;
2477 270 : n->def = (Node *) cmd;
2478 270 : $$ = (Node *) n;
2479 : }
2480 : ;
2481 :
2482 : index_partition_cmd:
2483 : /* ALTER INDEX <name> ATTACH PARTITION <index_name> */
2484 : ATTACH PARTITION qualified_name
2485 : {
2486 390 : AlterTableCmd *n = makeNode(AlterTableCmd);
2487 390 : PartitionCmd *cmd = makeNode(PartitionCmd);
2488 :
2489 390 : n->subtype = AT_AttachPartition;
2490 390 : cmd->name = $3;
2491 390 : cmd->bound = NULL;
2492 390 : cmd->partlist = NIL;
2493 390 : cmd->concurrent = false;
2494 390 : n->def = (Node *) cmd;
2495 :
2496 390 : $$ = (Node *) n;
2497 : }
2498 : ;
2499 :
2500 : alter_table_cmd:
2501 : /* ALTER TABLE <name> ADD <coldef> */
2502 : ADD_P columnDef
2503 : {
2504 192 : AlterTableCmd *n = makeNode(AlterTableCmd);
2505 :
2506 192 : n->subtype = AT_AddColumn;
2507 192 : n->def = $2;
2508 192 : n->missing_ok = false;
2509 192 : $$ = (Node *) n;
2510 : }
2511 : /* ALTER TABLE <name> ADD IF NOT EXISTS <coldef> */
2512 : | ADD_P IF_P NOT EXISTS columnDef
2513 : {
2514 0 : AlterTableCmd *n = makeNode(AlterTableCmd);
2515 :
2516 0 : n->subtype = AT_AddColumn;
2517 0 : n->def = $5;
2518 0 : n->missing_ok = true;
2519 0 : $$ = (Node *) n;
2520 : }
2521 : /* ALTER TABLE <name> ADD COLUMN <coldef> */
2522 : | ADD_P COLUMN columnDef
2523 : {
2524 1922 : AlterTableCmd *n = makeNode(AlterTableCmd);
2525 :
2526 1922 : n->subtype = AT_AddColumn;
2527 1922 : n->def = $3;
2528 1922 : n->missing_ok = false;
2529 1922 : $$ = (Node *) n;
2530 : }
2531 : /* ALTER TABLE <name> ADD COLUMN IF NOT EXISTS <coldef> */
2532 : | ADD_P COLUMN IF_P NOT EXISTS columnDef
2533 : {
2534 60 : AlterTableCmd *n = makeNode(AlterTableCmd);
2535 :
2536 60 : n->subtype = AT_AddColumn;
2537 60 : n->def = $6;
2538 60 : n->missing_ok = true;
2539 60 : $$ = (Node *) n;
2540 : }
2541 : /* ALTER TABLE <name> ALTER [COLUMN] <colname> {SET DEFAULT <expr>|DROP DEFAULT} */
2542 : | ALTER opt_column ColId alter_column_default
2543 : {
2544 550 : AlterTableCmd *n = makeNode(AlterTableCmd);
2545 :
2546 550 : n->subtype = AT_ColumnDefault;
2547 550 : n->name = $3;
2548 550 : n->def = $4;
2549 550 : $$ = (Node *) n;
2550 : }
2551 : /* ALTER TABLE <name> ALTER [COLUMN] <colname> DROP NOT NULL */
2552 : | ALTER opt_column ColId DROP NOT NULL_P
2553 : {
2554 294 : AlterTableCmd *n = makeNode(AlterTableCmd);
2555 :
2556 294 : n->subtype = AT_DropNotNull;
2557 294 : n->name = $3;
2558 294 : $$ = (Node *) n;
2559 : }
2560 : /* ALTER TABLE <name> ALTER [COLUMN] <colname> SET NOT NULL */
2561 : | ALTER opt_column ColId SET NOT NULL_P
2562 : {
2563 440 : AlterTableCmd *n = makeNode(AlterTableCmd);
2564 :
2565 440 : n->subtype = AT_SetNotNull;
2566 440 : n->name = $3;
2567 440 : $$ = (Node *) n;
2568 : }
2569 : /* ALTER TABLE <name> ALTER [COLUMN] <colname> SET EXPRESSION AS <expr> */
2570 : | ALTER opt_column ColId SET EXPRESSION AS '(' a_expr ')'
2571 : {
2572 176 : AlterTableCmd *n = makeNode(AlterTableCmd);
2573 :
2574 176 : n->subtype = AT_SetExpression;
2575 176 : n->name = $3;
2576 176 : n->def = $8;
2577 176 : $$ = (Node *) n;
2578 : }
2579 : /* ALTER TABLE <name> ALTER [COLUMN] <colname> DROP EXPRESSION */
2580 : | ALTER opt_column ColId DROP EXPRESSION
2581 : {
2582 62 : AlterTableCmd *n = makeNode(AlterTableCmd);
2583 :
2584 62 : n->subtype = AT_DropExpression;
2585 62 : n->name = $3;
2586 62 : $$ = (Node *) n;
2587 : }
2588 : /* ALTER TABLE <name> ALTER [COLUMN] <colname> DROP EXPRESSION IF EXISTS */
2589 : | ALTER opt_column ColId DROP EXPRESSION IF_P EXISTS
2590 : {
2591 12 : AlterTableCmd *n = makeNode(AlterTableCmd);
2592 :
2593 12 : n->subtype = AT_DropExpression;
2594 12 : n->name = $3;
2595 12 : n->missing_ok = true;
2596 12 : $$ = (Node *) n;
2597 : }
2598 : /* ALTER TABLE <name> ALTER [COLUMN] <colname> SET STATISTICS */
2599 : | ALTER opt_column ColId SET STATISTICS set_statistics_value
2600 : {
2601 62 : AlterTableCmd *n = makeNode(AlterTableCmd);
2602 :
2603 62 : n->subtype = AT_SetStatistics;
2604 62 : n->name = $3;
2605 62 : n->def = $6;
2606 62 : $$ = (Node *) n;
2607 : }
2608 : /* ALTER TABLE <name> ALTER [COLUMN] <colnum> SET STATISTICS */
2609 : | ALTER opt_column Iconst SET STATISTICS set_statistics_value
2610 : {
2611 70 : AlterTableCmd *n = makeNode(AlterTableCmd);
2612 :
2613 70 : if ($3 <= 0 || $3 > PG_INT16_MAX)
2614 6 : ereport(ERROR,
2615 : (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
2616 : errmsg("column number must be in range from 1 to %d", PG_INT16_MAX),
2617 : parser_errposition(@3)));
2618 :
2619 64 : n->subtype = AT_SetStatistics;
2620 64 : n->num = (int16) $3;
2621 64 : n->def = $6;
2622 64 : $$ = (Node *) n;
2623 : }
2624 : /* ALTER TABLE <name> ALTER [COLUMN] <colname> SET ( column_parameter = value [, ... ] ) */
2625 : | ALTER opt_column ColId SET reloptions
2626 : {
2627 38 : AlterTableCmd *n = makeNode(AlterTableCmd);
2628 :
2629 38 : n->subtype = AT_SetOptions;
2630 38 : n->name = $3;
2631 38 : n->def = (Node *) $5;
2632 38 : $$ = (Node *) n;
2633 : }
2634 : /* ALTER TABLE <name> ALTER [COLUMN] <colname> RESET ( column_parameter [, ... ] ) */
2635 : | ALTER opt_column ColId RESET reloptions
2636 : {
2637 6 : AlterTableCmd *n = makeNode(AlterTableCmd);
2638 :
2639 6 : n->subtype = AT_ResetOptions;
2640 6 : n->name = $3;
2641 6 : n->def = (Node *) $5;
2642 6 : $$ = (Node *) n;
2643 : }
2644 : /* ALTER TABLE <name> ALTER [COLUMN] <colname> SET STORAGE <storagemode> */
2645 : | ALTER opt_column ColId SET column_storage
2646 : {
2647 238 : AlterTableCmd *n = makeNode(AlterTableCmd);
2648 :
2649 238 : n->subtype = AT_SetStorage;
2650 238 : n->name = $3;
2651 238 : n->def = (Node *) makeString($5);
2652 238 : $$ = (Node *) n;
2653 : }
2654 : /* ALTER TABLE <name> ALTER [COLUMN] <colname> SET COMPRESSION <cm> */
2655 : | ALTER opt_column ColId SET column_compression
2656 : {
2657 78 : AlterTableCmd *n = makeNode(AlterTableCmd);
2658 :
2659 78 : n->subtype = AT_SetCompression;
2660 78 : n->name = $3;
2661 78 : n->def = (Node *) makeString($5);
2662 78 : $$ = (Node *) n;
2663 : }
2664 : /* ALTER TABLE <name> ALTER [COLUMN] <colname> ADD GENERATED ... AS IDENTITY ... */
2665 : | ALTER opt_column ColId ADD_P GENERATED generated_when AS IDENTITY_P OptParenthesizedSeqOptList
2666 : {
2667 172 : AlterTableCmd *n = makeNode(AlterTableCmd);
2668 172 : Constraint *c = makeNode(Constraint);
2669 :
2670 172 : c->contype = CONSTR_IDENTITY;
2671 172 : c->generated_when = $6;
2672 172 : c->options = $9;
2673 172 : c->location = @5;
2674 :
2675 172 : n->subtype = AT_AddIdentity;
2676 172 : n->name = $3;
2677 172 : n->def = (Node *) c;
2678 :
2679 172 : $$ = (Node *) n;
2680 : }
2681 : /* ALTER TABLE <name> ALTER [COLUMN] <colname> SET <sequence options>/RESET */
2682 : | ALTER opt_column ColId alter_identity_column_option_list
2683 : {
2684 62 : AlterTableCmd *n = makeNode(AlterTableCmd);
2685 :
2686 62 : n->subtype = AT_SetIdentity;
2687 62 : n->name = $3;
2688 62 : n->def = (Node *) $4;
2689 62 : $$ = (Node *) n;
2690 : }
2691 : /* ALTER TABLE <name> ALTER [COLUMN] <colname> DROP IDENTITY */
2692 : | ALTER opt_column ColId DROP IDENTITY_P
2693 : {
2694 50 : AlterTableCmd *n = makeNode(AlterTableCmd);
2695 :
2696 50 : n->subtype = AT_DropIdentity;
2697 50 : n->name = $3;
2698 50 : n->missing_ok = false;
2699 50 : $$ = (Node *) n;
2700 : }
2701 : /* ALTER TABLE <name> ALTER [COLUMN] <colname> DROP IDENTITY IF EXISTS */
2702 : | ALTER opt_column ColId DROP IDENTITY_P IF_P EXISTS
2703 : {
2704 6 : AlterTableCmd *n = makeNode(AlterTableCmd);
2705 :
2706 6 : n->subtype = AT_DropIdentity;
2707 6 : n->name = $3;
2708 6 : n->missing_ok = true;
2709 6 : $$ = (Node *) n;
2710 : }
2711 : /* ALTER TABLE <name> DROP [COLUMN] IF EXISTS <colname> [RESTRICT|CASCADE] */
2712 : | DROP opt_column IF_P EXISTS ColId opt_drop_behavior
2713 : {
2714 18 : AlterTableCmd *n = makeNode(AlterTableCmd);
2715 :
2716 18 : n->subtype = AT_DropColumn;
2717 18 : n->name = $5;
2718 18 : n->behavior = $6;
2719 18 : n->missing_ok = true;
2720 18 : $$ = (Node *) n;
2721 : }
2722 : /* ALTER TABLE <name> DROP [COLUMN] <colname> [RESTRICT|CASCADE] */
2723 : | DROP opt_column ColId opt_drop_behavior
2724 : {
2725 1616 : AlterTableCmd *n = makeNode(AlterTableCmd);
2726 :
2727 1616 : n->subtype = AT_DropColumn;
2728 1616 : n->name = $3;
2729 1616 : n->behavior = $4;
2730 1616 : n->missing_ok = false;
2731 1616 : $$ = (Node *) n;
2732 : }
2733 : /*
2734 : * ALTER TABLE <name> ALTER [COLUMN] <colname> [SET DATA] TYPE <typename>
2735 : * [ USING <expression> ]
2736 : */
2737 : | ALTER opt_column ColId opt_set_data TYPE_P Typename opt_collate_clause alter_using
2738 : {
2739 1138 : AlterTableCmd *n = makeNode(AlterTableCmd);
2740 1138 : ColumnDef *def = makeNode(ColumnDef);
2741 :
2742 1138 : n->subtype = AT_AlterColumnType;
2743 1138 : n->name = $3;
2744 1138 : n->def = (Node *) def;
2745 : /* We only use these fields of the ColumnDef node */
2746 1138 : def->typeName = $6;
2747 1138 : def->collClause = (CollateClause *) $7;
2748 1138 : def->raw_default = $8;
2749 1138 : def->location = @3;
2750 1138 : $$ = (Node *) n;
2751 : }
2752 : /* ALTER FOREIGN TABLE <name> ALTER [COLUMN] <colname> OPTIONS */
2753 : | ALTER opt_column ColId alter_generic_options
2754 : {
2755 50 : AlterTableCmd *n = makeNode(AlterTableCmd);
2756 :
2757 50 : n->subtype = AT_AlterColumnGenericOptions;
2758 50 : n->name = $3;
2759 50 : n->def = (Node *) $4;
2760 50 : $$ = (Node *) n;
2761 : }
2762 : /* ALTER TABLE <name> ADD CONSTRAINT ... */
2763 : | ADD_P TableConstraint
2764 : {
2765 14872 : AlterTableCmd *n = makeNode(AlterTableCmd);
2766 :
2767 14872 : n->subtype = AT_AddConstraint;
2768 14872 : n->def = $2;
2769 14872 : $$ = (Node *) n;
2770 : }
2771 : /* ALTER TABLE <name> ALTER CONSTRAINT ... */
2772 : | ALTER CONSTRAINT name ConstraintAttributeSpec
2773 : {
2774 246 : AlterTableCmd *n = makeNode(AlterTableCmd);
2775 246 : ATAlterConstraint *c = makeNode(ATAlterConstraint);
2776 :
2777 246 : n->subtype = AT_AlterConstraint;
2778 246 : n->def = (Node *) c;
2779 246 : c->conname = $3;
2780 246 : if ($4 & (CAS_NOT_ENFORCED | CAS_ENFORCED))
2781 90 : c->alterEnforceability = true;
2782 246 : if ($4 & (CAS_DEFERRABLE | CAS_NOT_DEFERRABLE |
2783 : CAS_INITIALLY_DEFERRED | CAS_INITIALLY_IMMEDIATE))
2784 120 : c->alterDeferrability = true;
2785 246 : if ($4 & CAS_NO_INHERIT)
2786 30 : c->alterInheritability = true;
2787 : /* handle unsupported case with specific error message */
2788 246 : if ($4 & CAS_NOT_VALID)
2789 12 : ereport(ERROR,
2790 : errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
2791 : errmsg("constraints cannot be altered to be NOT VALID"),
2792 : parser_errposition(@4));
2793 234 : processCASbits($4, @4, "FOREIGN KEY",
2794 : &c->deferrable,
2795 : &c->initdeferred,
2796 : &c->is_enforced,
2797 : NULL,
2798 : &c->noinherit,
2799 : yyscanner);
2800 234 : $$ = (Node *) n;
2801 : }
2802 : /* ALTER TABLE <name> ALTER CONSTRAINT INHERIT */
2803 : | ALTER CONSTRAINT name INHERIT
2804 : {
2805 66 : AlterTableCmd *n = makeNode(AlterTableCmd);
2806 66 : ATAlterConstraint *c = makeNode(ATAlterConstraint);
2807 :
2808 66 : n->subtype = AT_AlterConstraint;
2809 66 : n->def = (Node *) c;
2810 66 : c->conname = $3;
2811 66 : c->alterInheritability = true;
2812 66 : c->noinherit = false;
2813 :
2814 66 : $$ = (Node *) n;
2815 : }
2816 : /* ALTER TABLE <name> VALIDATE CONSTRAINT ... */
2817 : | VALIDATE CONSTRAINT name
2818 : {
2819 482 : AlterTableCmd *n = makeNode(AlterTableCmd);
2820 :
2821 482 : n->subtype = AT_ValidateConstraint;
2822 482 : n->name = $3;
2823 482 : $$ = (Node *) n;
2824 : }
2825 : /* ALTER TABLE <name> DROP CONSTRAINT IF EXISTS <name> [RESTRICT|CASCADE] */
2826 : | DROP CONSTRAINT IF_P EXISTS name opt_drop_behavior
2827 : {
2828 18 : AlterTableCmd *n = makeNode(AlterTableCmd);
2829 :
2830 18 : n->subtype = AT_DropConstraint;
2831 18 : n->name = $5;
2832 18 : n->behavior = $6;
2833 18 : n->missing_ok = true;
2834 18 : $$ = (Node *) n;
2835 : }
2836 : /* ALTER TABLE <name> DROP CONSTRAINT <name> [RESTRICT|CASCADE] */
2837 : | DROP CONSTRAINT name opt_drop_behavior
2838 : {
2839 818 : AlterTableCmd *n = makeNode(AlterTableCmd);
2840 :
2841 818 : n->subtype = AT_DropConstraint;
2842 818 : n->name = $3;
2843 818 : n->behavior = $4;
2844 818 : n->missing_ok = false;
2845 818 : $$ = (Node *) n;
2846 : }
2847 : /* ALTER TABLE <name> SET WITHOUT OIDS, for backward compat */
2848 : | SET WITHOUT OIDS
2849 : {
2850 6 : AlterTableCmd *n = makeNode(AlterTableCmd);
2851 :
2852 6 : n->subtype = AT_DropOids;
2853 6 : $$ = (Node *) n;
2854 : }
2855 : /* ALTER TABLE <name> CLUSTER ON <indexname> */
2856 : | CLUSTER ON name
2857 : {
2858 46 : AlterTableCmd *n = makeNode(AlterTableCmd);
2859 :
2860 46 : n->subtype = AT_ClusterOn;
2861 46 : n->name = $3;
2862 46 : $$ = (Node *) n;
2863 : }
2864 : /* ALTER TABLE <name> SET WITHOUT CLUSTER */
2865 : | SET WITHOUT CLUSTER
2866 : {
2867 18 : AlterTableCmd *n = makeNode(AlterTableCmd);
2868 :
2869 18 : n->subtype = AT_DropCluster;
2870 18 : n->name = NULL;
2871 18 : $$ = (Node *) n;
2872 : }
2873 : /* ALTER TABLE <name> SET LOGGED */
2874 : | SET LOGGED
2875 : {
2876 50 : AlterTableCmd *n = makeNode(AlterTableCmd);
2877 :
2878 50 : n->subtype = AT_SetLogged;
2879 50 : $$ = (Node *) n;
2880 : }
2881 : /* ALTER TABLE <name> SET UNLOGGED */
2882 : | SET UNLOGGED
2883 : {
2884 62 : AlterTableCmd *n = makeNode(AlterTableCmd);
2885 :
2886 62 : n->subtype = AT_SetUnLogged;
2887 62 : $$ = (Node *) n;
2888 : }
2889 : /* ALTER TABLE <name> ENABLE TRIGGER <trig> */
2890 : | ENABLE_P TRIGGER name
2891 : {
2892 122 : AlterTableCmd *n = makeNode(AlterTableCmd);
2893 :
2894 122 : n->subtype = AT_EnableTrig;
2895 122 : n->name = $3;
2896 122 : $$ = (Node *) n;
2897 : }
2898 : /* ALTER TABLE <name> ENABLE ALWAYS TRIGGER <trig> */
2899 : | ENABLE_P ALWAYS TRIGGER name
2900 : {
2901 42 : AlterTableCmd *n = makeNode(AlterTableCmd);
2902 :
2903 42 : n->subtype = AT_EnableAlwaysTrig;
2904 42 : n->name = $4;
2905 42 : $$ = (Node *) n;
2906 : }
2907 : /* ALTER TABLE <name> ENABLE REPLICA TRIGGER <trig> */
2908 : | ENABLE_P REPLICA TRIGGER name
2909 : {
2910 16 : AlterTableCmd *n = makeNode(AlterTableCmd);
2911 :
2912 16 : n->subtype = AT_EnableReplicaTrig;
2913 16 : n->name = $4;
2914 16 : $$ = (Node *) n;
2915 : }
2916 : /* ALTER TABLE <name> ENABLE TRIGGER ALL */
2917 : | ENABLE_P TRIGGER ALL
2918 : {
2919 0 : AlterTableCmd *n = makeNode(AlterTableCmd);
2920 :
2921 0 : n->subtype = AT_EnableTrigAll;
2922 0 : $$ = (Node *) n;
2923 : }
2924 : /* ALTER TABLE <name> ENABLE TRIGGER USER */
2925 : | ENABLE_P TRIGGER USER
2926 : {
2927 0 : AlterTableCmd *n = makeNode(AlterTableCmd);
2928 :
2929 0 : n->subtype = AT_EnableTrigUser;
2930 0 : $$ = (Node *) n;
2931 : }
2932 : /* ALTER TABLE <name> DISABLE TRIGGER <trig> */
2933 : | DISABLE_P TRIGGER name
2934 : {
2935 138 : AlterTableCmd *n = makeNode(AlterTableCmd);
2936 :
2937 138 : n->subtype = AT_DisableTrig;
2938 138 : n->name = $3;
2939 138 : $$ = (Node *) n;
2940 : }
2941 : /* ALTER TABLE <name> DISABLE TRIGGER ALL */
2942 : | DISABLE_P TRIGGER ALL
2943 : {
2944 12 : AlterTableCmd *n = makeNode(AlterTableCmd);
2945 :
2946 12 : n->subtype = AT_DisableTrigAll;
2947 12 : $$ = (Node *) n;
2948 : }
2949 : /* ALTER TABLE <name> DISABLE TRIGGER USER */
2950 : | DISABLE_P TRIGGER USER
2951 : {
2952 12 : AlterTableCmd *n = makeNode(AlterTableCmd);
2953 :
2954 12 : n->subtype = AT_DisableTrigUser;
2955 12 : $$ = (Node *) n;
2956 : }
2957 : /* ALTER TABLE <name> ENABLE RULE <rule> */
2958 : | ENABLE_P RULE name
2959 : {
2960 8 : AlterTableCmd *n = makeNode(AlterTableCmd);
2961 :
2962 8 : n->subtype = AT_EnableRule;
2963 8 : n->name = $3;
2964 8 : $$ = (Node *) n;
2965 : }
2966 : /* ALTER TABLE <name> ENABLE ALWAYS RULE <rule> */
2967 : | ENABLE_P ALWAYS RULE name
2968 : {
2969 0 : AlterTableCmd *n = makeNode(AlterTableCmd);
2970 :
2971 0 : n->subtype = AT_EnableAlwaysRule;
2972 0 : n->name = $4;
2973 0 : $$ = (Node *) n;
2974 : }
2975 : /* ALTER TABLE <name> ENABLE REPLICA RULE <rule> */
2976 : | ENABLE_P REPLICA RULE name
2977 : {
2978 6 : AlterTableCmd *n = makeNode(AlterTableCmd);
2979 :
2980 6 : n->subtype = AT_EnableReplicaRule;
2981 6 : n->name = $4;
2982 6 : $$ = (Node *) n;
2983 : }
2984 : /* ALTER TABLE <name> DISABLE RULE <rule> */
2985 : | DISABLE_P RULE name
2986 : {
2987 32 : AlterTableCmd *n = makeNode(AlterTableCmd);
2988 :
2989 32 : n->subtype = AT_DisableRule;
2990 32 : n->name = $3;
2991 32 : $$ = (Node *) n;
2992 : }
2993 : /* ALTER TABLE <name> INHERIT <parent> */
2994 : | INHERIT qualified_name
2995 : {
2996 464 : AlterTableCmd *n = makeNode(AlterTableCmd);
2997 :
2998 464 : n->subtype = AT_AddInherit;
2999 464 : n->def = (Node *) $2;
3000 464 : $$ = (Node *) n;
3001 : }
3002 : /* ALTER TABLE <name> NO INHERIT <parent> */
3003 : | NO INHERIT qualified_name
3004 : {
3005 94 : AlterTableCmd *n = makeNode(AlterTableCmd);
3006 :
3007 94 : n->subtype = AT_DropInherit;
3008 94 : n->def = (Node *) $3;
3009 94 : $$ = (Node *) n;
3010 : }
3011 : /* ALTER TABLE <name> OF <type_name> */
3012 : | OF any_name
3013 : {
3014 66 : AlterTableCmd *n = makeNode(AlterTableCmd);
3015 66 : TypeName *def = makeTypeNameFromNameList($2);
3016 :
3017 66 : def->location = @2;
3018 66 : n->subtype = AT_AddOf;
3019 66 : n->def = (Node *) def;
3020 66 : $$ = (Node *) n;
3021 : }
3022 : /* ALTER TABLE <name> NOT OF */
3023 : | NOT OF
3024 : {
3025 6 : AlterTableCmd *n = makeNode(AlterTableCmd);
3026 :
3027 6 : n->subtype = AT_DropOf;
3028 6 : $$ = (Node *) n;
3029 : }
3030 : /* ALTER TABLE <name> OWNER TO RoleSpec */
3031 : | OWNER TO RoleSpec
3032 : {
3033 2082 : AlterTableCmd *n = makeNode(AlterTableCmd);
3034 :
3035 2082 : n->subtype = AT_ChangeOwner;
3036 2082 : n->newowner = $3;
3037 2082 : $$ = (Node *) n;
3038 : }
3039 : /* ALTER TABLE <name> SET ACCESS METHOD { <amname> | DEFAULT } */
3040 : | SET ACCESS METHOD set_access_method_name
3041 : {
3042 128 : AlterTableCmd *n = makeNode(AlterTableCmd);
3043 :
3044 128 : n->subtype = AT_SetAccessMethod;
3045 128 : n->name = $4;
3046 128 : $$ = (Node *) n;
3047 : }
3048 : /* ALTER TABLE <name> SET TABLESPACE <tablespacename> */
3049 : | SET TABLESPACE name
3050 : {
3051 110 : AlterTableCmd *n = makeNode(AlterTableCmd);
3052 :
3053 110 : n->subtype = AT_SetTableSpace;
3054 110 : n->name = $3;
3055 110 : $$ = (Node *) n;
3056 : }
3057 : /* ALTER TABLE <name> SET (...) */
3058 : | SET reloptions
3059 : {
3060 600 : AlterTableCmd *n = makeNode(AlterTableCmd);
3061 :
3062 600 : n->subtype = AT_SetRelOptions;
3063 600 : n->def = (Node *) $2;
3064 600 : $$ = (Node *) n;
3065 : }
3066 : /* ALTER TABLE <name> RESET (...) */
3067 : | RESET reloptions
3068 : {
3069 170 : AlterTableCmd *n = makeNode(AlterTableCmd);
3070 :
3071 170 : n->subtype = AT_ResetRelOptions;
3072 170 : n->def = (Node *) $2;
3073 170 : $$ = (Node *) n;
3074 : }
3075 : /* ALTER TABLE <name> REPLICA IDENTITY */
3076 : | REPLICA IDENTITY_P replica_identity
3077 : {
3078 494 : AlterTableCmd *n = makeNode(AlterTableCmd);
3079 :
3080 494 : n->subtype = AT_ReplicaIdentity;
3081 494 : n->def = $3;
3082 494 : $$ = (Node *) n;
3083 : }
3084 : /* ALTER TABLE <name> ENABLE ROW LEVEL SECURITY */
3085 : | ENABLE_P ROW LEVEL SECURITY
3086 : {
3087 338 : AlterTableCmd *n = makeNode(AlterTableCmd);
3088 :
3089 338 : n->subtype = AT_EnableRowSecurity;
3090 338 : $$ = (Node *) n;
3091 : }
3092 : /* ALTER TABLE <name> DISABLE ROW LEVEL SECURITY */
3093 : | DISABLE_P ROW LEVEL SECURITY
3094 : {
3095 10 : AlterTableCmd *n = makeNode(AlterTableCmd);
3096 :
3097 10 : n->subtype = AT_DisableRowSecurity;
3098 10 : $$ = (Node *) n;
3099 : }
3100 : /* ALTER TABLE <name> FORCE ROW LEVEL SECURITY */
3101 : | FORCE ROW LEVEL SECURITY
3102 : {
3103 100 : AlterTableCmd *n = makeNode(AlterTableCmd);
3104 :
3105 100 : n->subtype = AT_ForceRowSecurity;
3106 100 : $$ = (Node *) n;
3107 : }
3108 : /* ALTER TABLE <name> NO FORCE ROW LEVEL SECURITY */
3109 : | NO FORCE ROW LEVEL SECURITY
3110 : {
3111 32 : AlterTableCmd *n = makeNode(AlterTableCmd);
3112 :
3113 32 : n->subtype = AT_NoForceRowSecurity;
3114 32 : $$ = (Node *) n;
3115 : }
3116 : | alter_generic_options
3117 : {
3118 64 : AlterTableCmd *n = makeNode(AlterTableCmd);
3119 :
3120 64 : n->subtype = AT_GenericOptions;
3121 64 : n->def = (Node *) $1;
3122 64 : $$ = (Node *) n;
3123 : }
3124 : ;
3125 :
3126 : alter_column_default:
3127 378 : SET DEFAULT a_expr { $$ = $3; }
3128 186 : | DROP DEFAULT { $$ = NULL; }
3129 : ;
3130 :
3131 : opt_collate_clause:
3132 : COLLATE any_name
3133 : {
3134 18 : CollateClause *n = makeNode(CollateClause);
3135 :
3136 18 : n->arg = NULL;
3137 18 : n->collname = $2;
3138 18 : n->location = @1;
3139 18 : $$ = (Node *) n;
3140 : }
3141 4846 : | /* EMPTY */ { $$ = NULL; }
3142 : ;
3143 :
3144 : alter_using:
3145 180 : USING a_expr { $$ = $2; }
3146 958 : | /* EMPTY */ { $$ = NULL; }
3147 : ;
3148 :
3149 : replica_identity:
3150 : NOTHING
3151 : {
3152 48 : ReplicaIdentityStmt *n = makeNode(ReplicaIdentityStmt);
3153 :
3154 48 : n->identity_type = REPLICA_IDENTITY_NOTHING;
3155 48 : n->name = NULL;
3156 48 : $$ = (Node *) n;
3157 : }
3158 : | FULL
3159 : {
3160 170 : ReplicaIdentityStmt *n = makeNode(ReplicaIdentityStmt);
3161 :
3162 170 : n->identity_type = REPLICA_IDENTITY_FULL;
3163 170 : n->name = NULL;
3164 170 : $$ = (Node *) n;
3165 : }
3166 : | DEFAULT
3167 : {
3168 6 : ReplicaIdentityStmt *n = makeNode(ReplicaIdentityStmt);
3169 :
3170 6 : n->identity_type = REPLICA_IDENTITY_DEFAULT;
3171 6 : n->name = NULL;
3172 6 : $$ = (Node *) n;
3173 : }
3174 : | USING INDEX name
3175 : {
3176 270 : ReplicaIdentityStmt *n = makeNode(ReplicaIdentityStmt);
3177 :
3178 270 : n->identity_type = REPLICA_IDENTITY_INDEX;
3179 270 : n->name = $3;
3180 270 : $$ = (Node *) n;
3181 : }
3182 : ;
3183 :
3184 : reloptions:
3185 2814 : '(' reloption_list ')' { $$ = $2; }
3186 : ;
3187 :
3188 972 : opt_reloptions: WITH reloptions { $$ = $2; }
3189 23920 : | /* EMPTY */ { $$ = NIL; }
3190 : ;
3191 :
3192 : reloption_list:
3193 2814 : reloption_elem { $$ = list_make1($1); }
3194 252 : | reloption_list ',' reloption_elem { $$ = lappend($1, $3); }
3195 : ;
3196 :
3197 : /* This should match def_elem and also allow qualified names */
3198 : reloption_elem:
3199 : ColLabel '=' def_arg
3200 : {
3201 2398 : $$ = makeDefElem($1, (Node *) $3, @1);
3202 : }
3203 : | ColLabel
3204 : {
3205 590 : $$ = makeDefElem($1, NULL, @1);
3206 : }
3207 : | ColLabel '.' ColLabel '=' def_arg
3208 : {
3209 72 : $$ = makeDefElemExtended($1, $3, (Node *) $5,
3210 72 : DEFELEM_UNSPEC, @1);
3211 : }
3212 : | ColLabel '.' ColLabel
3213 : {
3214 6 : $$ = makeDefElemExtended($1, $3, NULL, DEFELEM_UNSPEC, @1);
3215 : }
3216 : ;
3217 :
3218 : alter_identity_column_option_list:
3219 : alter_identity_column_option
3220 62 : { $$ = list_make1($1); }
3221 : | alter_identity_column_option_list alter_identity_column_option
3222 60 : { $$ = lappend($1, $2); }
3223 : ;
3224 :
3225 : alter_identity_column_option:
3226 : RESTART
3227 : {
3228 24 : $$ = makeDefElem("restart", NULL, @1);
3229 : }
3230 : | RESTART opt_with NumericOnly
3231 : {
3232 0 : $$ = makeDefElem("restart", (Node *) $3, @1);
3233 : }
3234 : | SET SeqOptElem
3235 : {
3236 54 : if (strcmp($2->defname, "as") == 0 ||
3237 54 : strcmp($2->defname, "restart") == 0 ||
3238 54 : strcmp($2->defname, "owned_by") == 0)
3239 0 : ereport(ERROR,
3240 : (errcode(ERRCODE_SYNTAX_ERROR),
3241 : errmsg("sequence option \"%s\" not supported here", $2->defname),
3242 : parser_errposition(@2)));
3243 54 : $$ = $2;
3244 : }
3245 : | SET GENERATED generated_when
3246 : {
3247 44 : $$ = makeDefElem("generated", (Node *) makeInteger($3), @1);
3248 : }
3249 : ;
3250 :
3251 : set_statistics_value:
3252 158 : SignedIconst { $$ = (Node *) makeInteger($1); }
3253 0 : | DEFAULT { $$ = NULL; }
3254 : ;
3255 :
3256 : set_access_method_name:
3257 92 : ColId { $$ = $1; }
3258 36 : | DEFAULT { $$ = NULL; }
3259 : ;
3260 :
3261 : PartitionBoundSpec:
3262 : /* a HASH partition */
3263 : FOR VALUES WITH '(' hash_partbound ')'
3264 : {
3265 : ListCell *lc;
3266 774 : PartitionBoundSpec *n = makeNode(PartitionBoundSpec);
3267 :
3268 774 : n->strategy = PARTITION_STRATEGY_HASH;
3269 774 : n->modulus = n->remainder = -1;
3270 :
3271 2322 : foreach (lc, $5)
3272 : {
3273 1548 : DefElem *opt = lfirst_node(DefElem, lc);
3274 :
3275 1548 : if (strcmp(opt->defname, "modulus") == 0)
3276 : {
3277 774 : if (n->modulus != -1)
3278 0 : ereport(ERROR,
3279 : (errcode(ERRCODE_DUPLICATE_OBJECT),
3280 : errmsg("modulus for hash partition provided more than once"),
3281 : parser_errposition(opt->location)));
3282 774 : n->modulus = defGetInt32(opt);
3283 : }
3284 774 : else if (strcmp(opt->defname, "remainder") == 0)
3285 : {
3286 774 : if (n->remainder != -1)
3287 0 : ereport(ERROR,
3288 : (errcode(ERRCODE_DUPLICATE_OBJECT),
3289 : errmsg("remainder for hash partition provided more than once"),
3290 : parser_errposition(opt->location)));
3291 774 : n->remainder = defGetInt32(opt);
3292 : }
3293 : else
3294 0 : ereport(ERROR,
3295 : (errcode(ERRCODE_SYNTAX_ERROR),
3296 : errmsg("unrecognized hash partition bound specification \"%s\"",
3297 : opt->defname),
3298 : parser_errposition(opt->location)));
3299 : }
3300 :
3301 774 : if (n->modulus == -1)
3302 0 : ereport(ERROR,
3303 : (errcode(ERRCODE_SYNTAX_ERROR),
3304 : errmsg("modulus for hash partition must be specified"),
3305 : parser_errposition(@3)));
3306 774 : if (n->remainder == -1)
3307 0 : ereport(ERROR,
3308 : (errcode(ERRCODE_SYNTAX_ERROR),
3309 : errmsg("remainder for hash partition must be specified"),
3310 : parser_errposition(@3)));
3311 :
3312 774 : n->location = @3;
3313 :
3314 774 : $$ = n;
3315 : }
3316 :
3317 : /* a LIST partition */
3318 : | FOR VALUES IN_P '(' expr_list ')'
3319 : {
3320 5300 : PartitionBoundSpec *n = makeNode(PartitionBoundSpec);
3321 :
3322 5300 : n->strategy = PARTITION_STRATEGY_LIST;
3323 5300 : n->is_default = false;
3324 5300 : n->listdatums = $5;
3325 5300 : n->location = @3;
3326 :
3327 5300 : $$ = n;
3328 : }
3329 :
3330 : /* a RANGE partition */
3331 : | FOR VALUES FROM '(' expr_list ')' TO '(' expr_list ')'
3332 : {
3333 5912 : PartitionBoundSpec *n = makeNode(PartitionBoundSpec);
3334 :
3335 5912 : n->strategy = PARTITION_STRATEGY_RANGE;
3336 5912 : n->is_default = false;
3337 5912 : n->lowerdatums = $5;
3338 5912 : n->upperdatums = $9;
3339 5912 : n->location = @3;
3340 :
3341 5912 : $$ = n;
3342 : }
3343 :
3344 : /* a DEFAULT partition */
3345 : | DEFAULT
3346 : {
3347 846 : PartitionBoundSpec *n = makeNode(PartitionBoundSpec);
3348 :
3349 846 : n->is_default = true;
3350 846 : n->location = @1;
3351 :
3352 846 : $$ = n;
3353 : }
3354 : ;
3355 :
3356 : hash_partbound_elem:
3357 : NonReservedWord Iconst
3358 : {
3359 1548 : $$ = makeDefElem($1, (Node *) makeInteger($2), @1);
3360 : }
3361 : ;
3362 :
3363 : hash_partbound:
3364 : hash_partbound_elem
3365 : {
3366 774 : $$ = list_make1($1);
3367 : }
3368 : | hash_partbound ',' hash_partbound_elem
3369 : {
3370 774 : $$ = lappend($1, $3);
3371 : }
3372 : ;
3373 :
3374 : /*****************************************************************************
3375 : *
3376 : * ALTER TYPE
3377 : *
3378 : * really variants of the ALTER TABLE subcommands with different spellings
3379 : *****************************************************************************/
3380 :
3381 : AlterCompositeTypeStmt:
3382 : ALTER TYPE_P any_name alter_type_cmds
3383 : {
3384 210 : AlterTableStmt *n = makeNode(AlterTableStmt);
3385 :
3386 : /* can't use qualified_name, sigh */
3387 210 : n->relation = makeRangeVarFromAnyName($3, @3, yyscanner);
3388 210 : n->cmds = $4;
3389 210 : n->objtype = OBJECT_TYPE;
3390 210 : $$ = (Node *) n;
3391 : }
3392 : ;
3393 :
3394 : alter_type_cmds:
3395 210 : alter_type_cmd { $$ = list_make1($1); }
3396 12 : | alter_type_cmds ',' alter_type_cmd { $$ = lappend($1, $3); }
3397 : ;
3398 :
3399 : alter_type_cmd:
3400 : /* ALTER TYPE <name> ADD ATTRIBUTE <coldef> [RESTRICT|CASCADE] */
3401 : ADD_P ATTRIBUTE TableFuncElement opt_drop_behavior
3402 : {
3403 64 : AlterTableCmd *n = makeNode(AlterTableCmd);
3404 :
3405 64 : n->subtype = AT_AddColumn;
3406 64 : n->def = $3;
3407 64 : n->behavior = $4;
3408 64 : $$ = (Node *) n;
3409 : }
3410 : /* ALTER TYPE <name> DROP ATTRIBUTE IF EXISTS <attname> [RESTRICT|CASCADE] */
3411 : | DROP ATTRIBUTE IF_P EXISTS ColId opt_drop_behavior
3412 : {
3413 6 : AlterTableCmd *n = makeNode(AlterTableCmd);
3414 :
3415 6 : n->subtype = AT_DropColumn;
3416 6 : n->name = $5;
3417 6 : n->behavior = $6;
3418 6 : n->missing_ok = true;
3419 6 : $$ = (Node *) n;
3420 : }
3421 : /* ALTER TYPE <name> DROP ATTRIBUTE <attname> [RESTRICT|CASCADE] */
3422 : | DROP ATTRIBUTE ColId opt_drop_behavior
3423 : {
3424 78 : AlterTableCmd *n = makeNode(AlterTableCmd);
3425 :
3426 78 : n->subtype = AT_DropColumn;
3427 78 : n->name = $3;
3428 78 : n->behavior = $4;
3429 78 : n->missing_ok = false;
3430 78 : $$ = (Node *) n;
3431 : }
3432 : /* ALTER TYPE <name> ALTER ATTRIBUTE <attname> [SET DATA] TYPE <typename> [RESTRICT|CASCADE] */
3433 : | ALTER ATTRIBUTE ColId opt_set_data TYPE_P Typename opt_collate_clause opt_drop_behavior
3434 : {
3435 74 : AlterTableCmd *n = makeNode(AlterTableCmd);
3436 74 : ColumnDef *def = makeNode(ColumnDef);
3437 :
3438 74 : n->subtype = AT_AlterColumnType;
3439 74 : n->name = $3;
3440 74 : n->def = (Node *) def;
3441 74 : n->behavior = $8;
3442 : /* We only use these fields of the ColumnDef node */
3443 74 : def->typeName = $6;
3444 74 : def->collClause = (CollateClause *) $7;
3445 74 : def->raw_default = NULL;
3446 74 : def->location = @3;
3447 74 : $$ = (Node *) n;
3448 : }
3449 : ;
3450 :
3451 :
3452 : /*****************************************************************************
3453 : *
3454 : * QUERY :
3455 : * close <portalname>
3456 : *
3457 : *****************************************************************************/
3458 :
3459 : ClosePortalStmt:
3460 : CLOSE cursor_name
3461 : {
3462 2236 : ClosePortalStmt *n = makeNode(ClosePortalStmt);
3463 :
3464 2236 : n->portalname = $2;
3465 2236 : $$ = (Node *) n;
3466 : }
3467 : | CLOSE ALL
3468 : {
3469 12 : ClosePortalStmt *n = makeNode(ClosePortalStmt);
3470 :
3471 12 : n->portalname = NULL;
3472 12 : $$ = (Node *) n;
3473 : }
3474 : ;
3475 :
3476 :
3477 : /*****************************************************************************
3478 : *
3479 : * QUERY :
3480 : * COPY relname [(columnList)] FROM/TO file [WITH] [(options)]
3481 : * COPY ( query ) TO file [WITH] [(options)]
3482 : *
3483 : * where 'query' can be one of:
3484 : * { SELECT | UPDATE | INSERT | DELETE | MERGE }
3485 : *
3486 : * and 'file' can be one of:
3487 : * { PROGRAM 'command' | STDIN | STDOUT | 'filename' }
3488 : *
3489 : * In the preferred syntax the options are comma-separated
3490 : * and use generic identifiers instead of keywords. The pre-9.0
3491 : * syntax had a hard-wired, space-separated set of options.
3492 : *
3493 : * Really old syntax, from versions 7.2 and prior:
3494 : * COPY [ BINARY ] table FROM/TO file
3495 : * [ [ USING ] DELIMITERS 'delimiter' ] ]
3496 : * [ WITH NULL AS 'null string' ]
3497 : * This option placement is not supported with COPY (query...).
3498 : *
3499 : *****************************************************************************/
3500 :
3501 : CopyStmt: COPY opt_binary qualified_name opt_column_list
3502 : copy_from opt_program copy_file_name copy_delimiter opt_with
3503 : copy_options where_clause
3504 : {
3505 10778 : CopyStmt *n = makeNode(CopyStmt);
3506 :
3507 10778 : n->relation = $3;
3508 10778 : n->query = NULL;
3509 10778 : n->attlist = $4;
3510 10778 : n->is_from = $5;
3511 10778 : n->is_program = $6;
3512 10778 : n->filename = $7;
3513 10778 : n->whereClause = $11;
3514 :
3515 10778 : if (n->is_program && n->filename == NULL)
3516 0 : ereport(ERROR,
3517 : (errcode(ERRCODE_SYNTAX_ERROR),
3518 : errmsg("STDIN/STDOUT not allowed with PROGRAM"),
3519 : parser_errposition(@8)));
3520 :
3521 10778 : if (!n->is_from && n->whereClause != NULL)
3522 6 : ereport(ERROR,
3523 : (errcode(ERRCODE_SYNTAX_ERROR),
3524 : errmsg("WHERE clause not allowed with COPY TO"),
3525 : errhint("Try the COPY (SELECT ... WHERE ...) TO variant."),
3526 : parser_errposition(@11)));
3527 :
3528 10772 : n->options = NIL;
3529 : /* Concatenate user-supplied flags */
3530 10772 : if ($2)
3531 12 : n->options = lappend(n->options, $2);
3532 10772 : if ($8)
3533 0 : n->options = lappend(n->options, $8);
3534 10772 : if ($10)
3535 992 : n->options = list_concat(n->options, $10);
3536 10772 : $$ = (Node *) n;
3537 : }
3538 : | COPY '(' PreparableStmt ')' TO opt_program copy_file_name opt_with copy_options
3539 : {
3540 588 : CopyStmt *n = makeNode(CopyStmt);
3541 :
3542 588 : n->relation = NULL;
3543 588 : n->query = $3;
3544 588 : n->attlist = NIL;
3545 588 : n->is_from = false;
3546 588 : n->is_program = $6;
3547 588 : n->filename = $7;
3548 588 : n->options = $9;
3549 :
3550 588 : if (n->is_program && n->filename == NULL)
3551 0 : ereport(ERROR,
3552 : (errcode(ERRCODE_SYNTAX_ERROR),
3553 : errmsg("STDIN/STDOUT not allowed with PROGRAM"),
3554 : parser_errposition(@5)));
3555 :
3556 588 : $$ = (Node *) n;
3557 : }
3558 : ;
3559 :
3560 : copy_from:
3561 1892 : FROM { $$ = true; }
3562 8886 : | TO { $$ = false; }
3563 : ;
3564 :
3565 : opt_program:
3566 0 : PROGRAM { $$ = true; }
3567 11366 : | /* EMPTY */ { $$ = false; }
3568 : ;
3569 :
3570 : /*
3571 : * copy_file_name NULL indicates stdio is used. Whether stdin or stdout is
3572 : * used depends on the direction. (It really doesn't make sense to copy from
3573 : * stdout. We silently correct the "typo".) - AY 9/94
3574 : */
3575 : copy_file_name:
3576 454 : Sconst { $$ = $1; }
3577 1502 : | STDIN { $$ = NULL; }
3578 9410 : | STDOUT { $$ = NULL; }
3579 : ;
3580 :
3581 10644 : copy_options: copy_opt_list { $$ = $1; }
3582 722 : | '(' copy_generic_opt_list ')' { $$ = $2; }
3583 : ;
3584 :
3585 : /* old COPY option syntax */
3586 : copy_opt_list:
3587 504 : copy_opt_list copy_opt_item { $$ = lappend($1, $2); }
3588 10644 : | /* EMPTY */ { $$ = NIL; }
3589 : ;
3590 :
3591 : copy_opt_item:
3592 : BINARY
3593 : {
3594 0 : $$ = makeDefElem("format", (Node *) makeString("binary"), @1);
3595 : }
3596 : | FREEZE
3597 : {
3598 50 : $$ = makeDefElem("freeze", (Node *) makeBoolean(true), @1);
3599 : }
3600 : | DELIMITER opt_as Sconst
3601 : {
3602 172 : $$ = makeDefElem("delimiter", (Node *) makeString($3), @1);
3603 : }
3604 : | NULL_P opt_as Sconst
3605 : {
3606 48 : $$ = makeDefElem("null", (Node *) makeString($3), @1);
3607 : }
3608 : | CSV
3609 : {
3610 150 : $$ = makeDefElem("format", (Node *) makeString("csv"), @1);
3611 : }
3612 : | HEADER_P
3613 : {
3614 18 : $$ = makeDefElem("header", (Node *) makeBoolean(true), @1);
3615 : }
3616 : | QUOTE opt_as Sconst
3617 : {
3618 18 : $$ = makeDefElem("quote", (Node *) makeString($3), @1);
3619 : }
3620 : | ESCAPE opt_as Sconst
3621 : {
3622 18 : $$ = makeDefElem("escape", (Node *) makeString($3), @1);
3623 : }
3624 : | FORCE QUOTE columnList
3625 : {
3626 12 : $$ = makeDefElem("force_quote", (Node *) $3, @1);
3627 : }
3628 : | FORCE QUOTE '*'
3629 : {
3630 6 : $$ = makeDefElem("force_quote", (Node *) makeNode(A_Star), @1);
3631 : }
3632 : | FORCE NOT NULL_P columnList
3633 : {
3634 0 : $$ = makeDefElem("force_not_null", (Node *) $4, @1);
3635 : }
3636 : | FORCE NOT NULL_P '*'
3637 : {
3638 0 : $$ = makeDefElem("force_not_null", (Node *) makeNode(A_Star), @1);
3639 : }
3640 : | FORCE NULL_P columnList
3641 : {
3642 0 : $$ = makeDefElem("force_null", (Node *) $3, @1);
3643 : }
3644 : | FORCE NULL_P '*'
3645 : {
3646 0 : $$ = makeDefElem("force_null", (Node *) makeNode(A_Star), @1);
3647 : }
3648 : | ENCODING Sconst
3649 : {
3650 12 : $$ = makeDefElem("encoding", (Node *) makeString($2), @1);
3651 : }
3652 : ;
3653 :
3654 : /* The following exist for backward compatibility with very old versions */
3655 :
3656 : opt_binary:
3657 : BINARY
3658 : {
3659 12 : $$ = makeDefElem("format", (Node *) makeString("binary"), @1);
3660 : }
3661 10766 : | /*EMPTY*/ { $$ = NULL; }
3662 : ;
3663 :
3664 : copy_delimiter:
3665 : opt_using DELIMITERS Sconst
3666 : {
3667 0 : $$ = makeDefElem("delimiter", (Node *) makeString($3), @2);
3668 : }
3669 10778 : | /*EMPTY*/ { $$ = NULL; }
3670 : ;
3671 :
3672 : opt_using:
3673 : USING
3674 : | /*EMPTY*/
3675 : ;
3676 :
3677 : /* new COPY option syntax */
3678 : copy_generic_opt_list:
3679 : copy_generic_opt_elem
3680 : {
3681 722 : $$ = list_make1($1);
3682 : }
3683 : | copy_generic_opt_list ',' copy_generic_opt_elem
3684 : {
3685 468 : $$ = lappend($1, $3);
3686 : }
3687 : ;
3688 :
3689 : copy_generic_opt_elem:
3690 : ColLabel copy_generic_opt_arg
3691 : {
3692 1190 : $$ = makeDefElem($1, $2, @1);
3693 : }
3694 : ;
3695 :
3696 : copy_generic_opt_arg:
3697 836 : opt_boolean_or_string { $$ = (Node *) makeString($1); }
3698 60 : | NumericOnly { $$ = (Node *) $1; }
3699 90 : | '*' { $$ = (Node *) makeNode(A_Star); }
3700 6 : | DEFAULT { $$ = (Node *) makeString("default"); }
3701 150 : | '(' copy_generic_opt_arg_list ')' { $$ = (Node *) $2; }
3702 48 : | /* EMPTY */ { $$ = NULL; }
3703 : ;
3704 :
3705 : copy_generic_opt_arg_list:
3706 : copy_generic_opt_arg_list_item
3707 : {
3708 150 : $$ = list_make1($1);
3709 : }
3710 : | copy_generic_opt_arg_list ',' copy_generic_opt_arg_list_item
3711 : {
3712 12 : $$ = lappend($1, $3);
3713 : }
3714 : ;
3715 :
3716 : /* beware of emitting non-string list elements here; see commands/define.c */
3717 : copy_generic_opt_arg_list_item:
3718 162 : opt_boolean_or_string { $$ = (Node *) makeString($1); }
3719 : ;
3720 :
3721 :
3722 : /*****************************************************************************
3723 : *
3724 : * QUERY :
3725 : * CREATE TABLE relname
3726 : *
3727 : *****************************************************************************/
3728 :
3729 : CreateStmt: CREATE OptTemp TABLE qualified_name '(' OptTableElementList ')'
3730 : OptInherit OptPartitionSpec table_access_method_clause OptWith
3731 : OnCommitOption OptTableSpace
3732 : {
3733 30826 : CreateStmt *n = makeNode(CreateStmt);
3734 :
3735 30826 : $4->relpersistence = $2;
3736 30826 : n->relation = $4;
3737 30826 : n->tableElts = $6;
3738 30826 : n->inhRelations = $8;
3739 30826 : n->partspec = $9;
3740 30826 : n->ofTypename = NULL;
3741 30826 : n->constraints = NIL;
3742 30826 : n->accessMethod = $10;
3743 30826 : n->options = $11;
3744 30826 : n->oncommit = $12;
3745 30826 : n->tablespacename = $13;
3746 30826 : n->if_not_exists = false;
3747 30826 : $$ = (Node *) n;
3748 : }
3749 : | CREATE OptTemp TABLE IF_P NOT EXISTS qualified_name '('
3750 : OptTableElementList ')' OptInherit OptPartitionSpec table_access_method_clause
3751 : OptWith OnCommitOption OptTableSpace
3752 : {
3753 30 : CreateStmt *n = makeNode(CreateStmt);
3754 :
3755 30 : $7->relpersistence = $2;
3756 30 : n->relation = $7;
3757 30 : n->tableElts = $9;
3758 30 : n->inhRelations = $11;
3759 30 : n->partspec = $12;
3760 30 : n->ofTypename = NULL;
3761 30 : n->constraints = NIL;
3762 30 : n->accessMethod = $13;
3763 30 : n->options = $14;
3764 30 : n->oncommit = $15;
3765 30 : n->tablespacename = $16;
3766 30 : n->if_not_exists = true;
3767 30 : $$ = (Node *) n;
3768 : }
3769 : | CREATE OptTemp TABLE qualified_name OF any_name
3770 : OptTypedTableElementList OptPartitionSpec table_access_method_clause
3771 : OptWith OnCommitOption OptTableSpace
3772 : {
3773 122 : CreateStmt *n = makeNode(CreateStmt);
3774 :
3775 122 : $4->relpersistence = $2;
3776 122 : n->relation = $4;
3777 122 : n->tableElts = $7;
3778 122 : n->inhRelations = NIL;
3779 122 : n->partspec = $8;
3780 122 : n->ofTypename = makeTypeNameFromNameList($6);
3781 122 : n->ofTypename->location = @6;
3782 122 : n->constraints = NIL;
3783 122 : n->accessMethod = $9;
3784 122 : n->options = $10;
3785 122 : n->oncommit = $11;
3786 122 : n->tablespacename = $12;
3787 122 : n->if_not_exists = false;
3788 122 : $$ = (Node *) n;
3789 : }
3790 : | CREATE OptTemp TABLE IF_P NOT EXISTS qualified_name OF any_name
3791 : OptTypedTableElementList OptPartitionSpec table_access_method_clause
3792 : OptWith OnCommitOption OptTableSpace
3793 : {
3794 6 : CreateStmt *n = makeNode(CreateStmt);
3795 :
3796 6 : $7->relpersistence = $2;
3797 6 : n->relation = $7;
3798 6 : n->tableElts = $10;
3799 6 : n->inhRelations = NIL;
3800 6 : n->partspec = $11;
3801 6 : n->ofTypename = makeTypeNameFromNameList($9);
3802 6 : n->ofTypename->location = @9;
3803 6 : n->constraints = NIL;
3804 6 : n->accessMethod = $12;
3805 6 : n->options = $13;
3806 6 : n->oncommit = $14;
3807 6 : n->tablespacename = $15;
3808 6 : n->if_not_exists = true;
3809 6 : $$ = (Node *) n;
3810 : }
3811 : | CREATE OptTemp TABLE qualified_name PARTITION OF qualified_name
3812 : OptTypedTableElementList PartitionBoundSpec OptPartitionSpec
3813 : table_access_method_clause OptWith OnCommitOption OptTableSpace
3814 : {
3815 9078 : CreateStmt *n = makeNode(CreateStmt);
3816 :
3817 9078 : $4->relpersistence = $2;
3818 9078 : n->relation = $4;
3819 9078 : n->tableElts = $8;
3820 9078 : n->inhRelations = list_make1($7);
3821 9078 : n->partbound = $9;
3822 9078 : n->partspec = $10;
3823 9078 : n->ofTypename = NULL;
3824 9078 : n->constraints = NIL;
3825 9078 : n->accessMethod = $11;
3826 9078 : n->options = $12;
3827 9078 : n->oncommit = $13;
3828 9078 : n->tablespacename = $14;
3829 9078 : n->if_not_exists = false;
3830 9078 : $$ = (Node *) n;
3831 : }
3832 : | CREATE OptTemp TABLE IF_P NOT EXISTS qualified_name PARTITION OF
3833 : qualified_name OptTypedTableElementList PartitionBoundSpec OptPartitionSpec
3834 : table_access_method_clause OptWith OnCommitOption OptTableSpace
3835 : {
3836 0 : CreateStmt *n = makeNode(CreateStmt);
3837 :
3838 0 : $7->relpersistence = $2;
3839 0 : n->relation = $7;
3840 0 : n->tableElts = $11;
3841 0 : n->inhRelations = list_make1($10);
3842 0 : n->partbound = $12;
3843 0 : n->partspec = $13;
3844 0 : n->ofTypename = NULL;
3845 0 : n->constraints = NIL;
3846 0 : n->accessMethod = $14;
3847 0 : n->options = $15;
3848 0 : n->oncommit = $16;
3849 0 : n->tablespacename = $17;
3850 0 : n->if_not_exists = true;
3851 0 : $$ = (Node *) n;
3852 : }
3853 : ;
3854 :
3855 : /*
3856 : * Redundancy here is needed to avoid shift/reduce conflicts,
3857 : * since TEMP is not a reserved word. See also OptTempTableName.
3858 : *
3859 : * NOTE: we accept both GLOBAL and LOCAL options. They currently do nothing,
3860 : * but future versions might consider GLOBAL to request SQL-spec-compliant
3861 : * temp table behavior, so warn about that. Since we have no modules the
3862 : * LOCAL keyword is really meaningless; furthermore, some other products
3863 : * implement LOCAL as meaning the same as our default temp table behavior,
3864 : * so we'll probably continue to treat LOCAL as a noise word.
3865 : */
3866 352 : OptTemp: TEMPORARY { $$ = RELPERSISTENCE_TEMP; }
3867 2894 : | TEMP { $$ = RELPERSISTENCE_TEMP; }
3868 0 : | LOCAL TEMPORARY { $$ = RELPERSISTENCE_TEMP; }
3869 0 : | LOCAL TEMP { $$ = RELPERSISTENCE_TEMP; }
3870 : | GLOBAL TEMPORARY
3871 : {
3872 0 : ereport(WARNING,
3873 : (errmsg("GLOBAL is deprecated in temporary table creation"),
3874 : parser_errposition(@1)));
3875 0 : $$ = RELPERSISTENCE_TEMP;
3876 : }
3877 : | GLOBAL TEMP
3878 : {
3879 0 : ereport(WARNING,
3880 : (errmsg("GLOBAL is deprecated in temporary table creation"),
3881 : parser_errposition(@1)));
3882 0 : $$ = RELPERSISTENCE_TEMP;
3883 : }
3884 162 : | UNLOGGED { $$ = RELPERSISTENCE_UNLOGGED; }
3885 56262 : | /*EMPTY*/ { $$ = RELPERSISTENCE_PERMANENT; }
3886 : ;
3887 :
3888 : OptTableElementList:
3889 29650 : TableElementList { $$ = $1; }
3890 1668 : | /*EMPTY*/ { $$ = NIL; }
3891 : ;
3892 :
3893 : OptTypedTableElementList:
3894 354 : '(' TypedTableElementList ')' { $$ = $2; }
3895 8948 : | /*EMPTY*/ { $$ = NIL; }
3896 : ;
3897 :
3898 : TableElementList:
3899 : TableElement
3900 : {
3901 29704 : $$ = list_make1($1);
3902 : }
3903 : | TableElementList ',' TableElement
3904 : {
3905 41886 : $$ = lappend($1, $3);
3906 : }
3907 : ;
3908 :
3909 : TypedTableElementList:
3910 : TypedTableElement
3911 : {
3912 354 : $$ = list_make1($1);
3913 : }
3914 : | TypedTableElementList ',' TypedTableElement
3915 : {
3916 68 : $$ = lappend($1, $3);
3917 : }
3918 : ;
3919 :
3920 : TableElement:
3921 68028 : columnDef { $$ = $1; }
3922 786 : | TableLikeClause { $$ = $1; }
3923 2776 : | TableConstraint { $$ = $1; }
3924 : ;
3925 :
3926 : TypedTableElement:
3927 358 : columnOptions { $$ = $1; }
3928 64 : | TableConstraint { $$ = $1; }
3929 : ;
3930 :
3931 : columnDef: ColId Typename opt_column_storage opt_column_compression create_generic_options ColQualList
3932 : {
3933 70202 : ColumnDef *n = makeNode(ColumnDef);
3934 :
3935 70202 : n->colname = $1;
3936 70202 : n->typeName = $2;
3937 70202 : n->storage_name = $3;
3938 70202 : n->compression = $4;
3939 70202 : n->inhcount = 0;
3940 70202 : n->is_local = true;
3941 70202 : n->is_not_null = false;
3942 70202 : n->is_from_type = false;
3943 70202 : n->storage = 0;
3944 70202 : n->raw_default = NULL;
3945 70202 : n->cooked_default = NULL;
3946 70202 : n->collOid = InvalidOid;
3947 70202 : n->fdwoptions = $5;
3948 70202 : SplitColQualList($6, &n->constraints, &n->collClause,
3949 : yyscanner);
3950 70202 : n->location = @1;
3951 70202 : $$ = (Node *) n;
3952 : }
3953 : ;
3954 :
3955 : columnOptions: ColId ColQualList
3956 : {
3957 138 : ColumnDef *n = makeNode(ColumnDef);
3958 :
3959 138 : n->colname = $1;
3960 138 : n->typeName = NULL;
3961 138 : n->inhcount = 0;
3962 138 : n->is_local = true;
3963 138 : n->is_not_null = false;
3964 138 : n->is_from_type = false;
3965 138 : n->storage = 0;
3966 138 : n->raw_default = NULL;
3967 138 : n->cooked_default = NULL;
3968 138 : n->collOid = InvalidOid;
3969 138 : SplitColQualList($2, &n->constraints, &n->collClause,
3970 : yyscanner);
3971 138 : n->location = @1;
3972 138 : $$ = (Node *) n;
3973 : }
3974 : | ColId WITH OPTIONS ColQualList
3975 : {
3976 220 : ColumnDef *n = makeNode(ColumnDef);
3977 :
3978 220 : n->colname = $1;
3979 220 : n->typeName = NULL;
3980 220 : n->inhcount = 0;
3981 220 : n->is_local = true;
3982 220 : n->is_not_null = false;
3983 220 : n->is_from_type = false;
3984 220 : n->storage = 0;
3985 220 : n->raw_default = NULL;
3986 220 : n->cooked_default = NULL;
3987 220 : n->collOid = InvalidOid;
3988 220 : SplitColQualList($4, &n->constraints, &n->collClause,
3989 : yyscanner);
3990 220 : n->location = @1;
3991 220 : $$ = (Node *) n;
3992 : }
3993 : ;
3994 :
3995 : column_compression:
3996 178 : COMPRESSION ColId { $$ = $2; }
3997 6 : | COMPRESSION DEFAULT { $$ = pstrdup("default"); }
3998 : ;
3999 :
4000 : opt_column_compression:
4001 106 : column_compression { $$ = $1; }
4002 70162 : | /*EMPTY*/ { $$ = NULL; }
4003 : ;
4004 :
4005 : column_storage:
4006 288 : STORAGE ColId { $$ = $2; }
4007 6 : | STORAGE DEFAULT { $$ = pstrdup("default"); }
4008 : ;
4009 :
4010 : opt_column_storage:
4011 56 : column_storage { $$ = $1; }
4012 70212 : | /*EMPTY*/ { $$ = NULL; }
4013 : ;
4014 :
4015 : ColQualList:
4016 20674 : ColQualList ColConstraint { $$ = lappend($1, $2); }
4017 72100 : | /*EMPTY*/ { $$ = NIL; }
4018 : ;
4019 :
4020 : ColConstraint:
4021 : CONSTRAINT name ColConstraintElem
4022 : {
4023 810 : Constraint *n = castNode(Constraint, $3);
4024 :
4025 810 : n->conname = $2;
4026 810 : n->location = @1;
4027 810 : $$ = (Node *) n;
4028 : }
4029 18792 : | ColConstraintElem { $$ = $1; }
4030 294 : | ConstraintAttr { $$ = $1; }
4031 : | COLLATE any_name
4032 : {
4033 : /*
4034 : * Note: the CollateClause is momentarily included in
4035 : * the list built by ColQualList, but we split it out
4036 : * again in SplitColQualList.
4037 : */
4038 778 : CollateClause *n = makeNode(CollateClause);
4039 :
4040 778 : n->arg = NULL;
4041 778 : n->collname = $2;
4042 778 : n->location = @1;
4043 778 : $$ = (Node *) n;
4044 : }
4045 : ;
4046 :
4047 : /* DEFAULT NULL is already the default for Postgres.
4048 : * But define it here and carry it forward into the system
4049 : * to make it explicit.
4050 : * - thomas 1998-09-13
4051 : *
4052 : * WITH NULL and NULL are not SQL-standard syntax elements,
4053 : * so leave them out. Use DEFAULT NULL to explicitly indicate
4054 : * that a column may have that value. WITH NULL leads to
4055 : * shift/reduce conflicts with WITH TIME ZONE anyway.
4056 : * - thomas 1999-01-08
4057 : *
4058 : * DEFAULT expression must be b_expr not a_expr to prevent shift/reduce
4059 : * conflict on NOT (since NOT might start a subsequent NOT NULL constraint,
4060 : * or be part of a_expr NOT LIKE or similar constructs).
4061 : */
4062 : ColConstraintElem:
4063 : NOT NULL_P opt_no_inherit
4064 : {
4065 7018 : Constraint *n = makeNode(Constraint);
4066 :
4067 7018 : n->contype = CONSTR_NOTNULL;
4068 7018 : n->location = @1;
4069 7018 : n->is_no_inherit = $3;
4070 7018 : n->is_enforced = true;
4071 7018 : n->skip_validation = false;
4072 7018 : n->initially_valid = true;
4073 7018 : $$ = (Node *) n;
4074 : }
4075 : | NULL_P
4076 : {
4077 30 : Constraint *n = makeNode(Constraint);
4078 :
4079 30 : n->contype = CONSTR_NULL;
4080 30 : n->location = @1;
4081 30 : $$ = (Node *) n;
4082 : }
4083 : | UNIQUE opt_unique_null_treatment opt_definition OptConsTableSpace
4084 : {
4085 466 : Constraint *n = makeNode(Constraint);
4086 :
4087 466 : n->contype = CONSTR_UNIQUE;
4088 466 : n->location = @1;
4089 466 : n->nulls_not_distinct = !$2;
4090 466 : n->keys = NULL;
4091 466 : n->options = $3;
4092 466 : n->indexname = NULL;
4093 466 : n->indexspace = $4;
4094 466 : $$ = (Node *) n;
4095 : }
4096 : | PRIMARY KEY opt_definition OptConsTableSpace
4097 : {
4098 6002 : Constraint *n = makeNode(Constraint);
4099 :
4100 6002 : n->contype = CONSTR_PRIMARY;
4101 6002 : n->location = @1;
4102 6002 : n->keys = NULL;
4103 6002 : n->options = $3;
4104 6002 : n->indexname = NULL;
4105 6002 : n->indexspace = $4;
4106 6002 : $$ = (Node *) n;
4107 : }
4108 : | CHECK '(' a_expr ')' opt_no_inherit
4109 : {
4110 1096 : Constraint *n = makeNode(Constraint);
4111 :
4112 1096 : n->contype = CONSTR_CHECK;
4113 1096 : n->location = @1;
4114 1096 : n->is_no_inherit = $5;
4115 1096 : n->raw_expr = $3;
4116 1096 : n->cooked_expr = NULL;
4117 1096 : n->is_enforced = true;
4118 1096 : n->skip_validation = false;
4119 1096 : n->initially_valid = true;
4120 1096 : $$ = (Node *) n;
4121 : }
4122 : | DEFAULT b_expr
4123 : {
4124 1906 : Constraint *n = makeNode(Constraint);
4125 :
4126 1906 : n->contype = CONSTR_DEFAULT;
4127 1906 : n->location = @1;
4128 1906 : n->raw_expr = $2;
4129 1906 : n->cooked_expr = NULL;
4130 1906 : $$ = (Node *) n;
4131 : }
4132 : | GENERATED generated_when AS IDENTITY_P OptParenthesizedSeqOptList
4133 : {
4134 372 : Constraint *n = makeNode(Constraint);
4135 :
4136 372 : n->contype = CONSTR_IDENTITY;
4137 372 : n->generated_when = $2;
4138 372 : n->options = $5;
4139 372 : n->location = @1;
4140 372 : $$ = (Node *) n;
4141 : }
4142 : | GENERATED generated_when AS '(' a_expr ')' opt_virtual_or_stored
4143 : {
4144 1872 : Constraint *n = makeNode(Constraint);
4145 :
4146 1872 : n->contype = CONSTR_GENERATED;
4147 1872 : n->generated_when = $2;
4148 1872 : n->raw_expr = $5;
4149 1872 : n->cooked_expr = NULL;
4150 1872 : n->generated_kind = $7;
4151 1872 : n->location = @1;
4152 :
4153 : /*
4154 : * Can't do this in the grammar because of shift/reduce
4155 : * conflicts. (IDENTITY allows both ALWAYS and BY
4156 : * DEFAULT, but generated columns only allow ALWAYS.) We
4157 : * can also give a more useful error message and location.
4158 : */
4159 1872 : if ($2 != ATTRIBUTE_IDENTITY_ALWAYS)
4160 12 : ereport(ERROR,
4161 : (errcode(ERRCODE_SYNTAX_ERROR),
4162 : errmsg("for a generated column, GENERATED ALWAYS must be specified"),
4163 : parser_errposition(@2)));
4164 :
4165 1860 : $$ = (Node *) n;
4166 : }
4167 : | REFERENCES qualified_name opt_column_list key_match key_actions
4168 : {
4169 852 : Constraint *n = makeNode(Constraint);
4170 :
4171 852 : n->contype = CONSTR_FOREIGN;
4172 852 : n->location = @1;
4173 852 : n->pktable = $2;
4174 852 : n->fk_attrs = NIL;
4175 852 : n->pk_attrs = $3;
4176 852 : n->fk_matchtype = $4;
4177 852 : n->fk_upd_action = ($5)->updateAction->action;
4178 852 : n->fk_del_action = ($5)->deleteAction->action;
4179 852 : n->fk_del_set_cols = ($5)->deleteAction->cols;
4180 852 : n->is_enforced = true;
4181 852 : n->skip_validation = false;
4182 852 : n->initially_valid = true;
4183 852 : $$ = (Node *) n;
4184 : }
4185 : ;
4186 :
4187 : opt_unique_null_treatment:
4188 12 : NULLS_P DISTINCT { $$ = true; }
4189 36 : | NULLS_P NOT DISTINCT { $$ = false; }
4190 7802 : | /*EMPTY*/ { $$ = true; }
4191 : ;
4192 :
4193 : generated_when:
4194 2278 : ALWAYS { $$ = ATTRIBUTE_IDENTITY_ALWAYS; }
4195 182 : | BY DEFAULT { $$ = ATTRIBUTE_IDENTITY_BY_DEFAULT; }
4196 : ;
4197 :
4198 : opt_virtual_or_stored:
4199 1088 : STORED { $$ = ATTRIBUTE_GENERATED_STORED; }
4200 658 : | VIRTUAL { $$ = ATTRIBUTE_GENERATED_VIRTUAL; }
4201 126 : | /*EMPTY*/ { $$ = ATTRIBUTE_GENERATED_VIRTUAL; }
4202 : ;
4203 :
4204 : /*
4205 : * ConstraintAttr represents constraint attributes, which we parse as if
4206 : * they were independent constraint clauses, in order to avoid shift/reduce
4207 : * conflicts (since NOT might start either an independent NOT NULL clause
4208 : * or an attribute). parse_utilcmd.c is responsible for attaching the
4209 : * attribute information to the preceding "real" constraint node, and for
4210 : * complaining if attribute clauses appear in the wrong place or wrong
4211 : * combinations.
4212 : *
4213 : * See also ConstraintAttributeSpec, which can be used in places where
4214 : * there is no parsing conflict. (Note: currently, NOT VALID and NO INHERIT
4215 : * are allowed clauses in ConstraintAttributeSpec, but not here. Someday we
4216 : * might need to allow them here too, but for the moment it doesn't seem
4217 : * useful in the statements that use ConstraintAttr.)
4218 : */
4219 : ConstraintAttr:
4220 : DEFERRABLE
4221 : {
4222 102 : Constraint *n = makeNode(Constraint);
4223 :
4224 102 : n->contype = CONSTR_ATTR_DEFERRABLE;
4225 102 : n->location = @1;
4226 102 : $$ = (Node *) n;
4227 : }
4228 : | NOT DEFERRABLE
4229 : {
4230 0 : Constraint *n = makeNode(Constraint);
4231 :
4232 0 : n->contype = CONSTR_ATTR_NOT_DEFERRABLE;
4233 0 : n->location = @1;
4234 0 : $$ = (Node *) n;
4235 : }
4236 : | INITIALLY DEFERRED
4237 : {
4238 78 : Constraint *n = makeNode(Constraint);
4239 :
4240 78 : n->contype = CONSTR_ATTR_DEFERRED;
4241 78 : n->location = @1;
4242 78 : $$ = (Node *) n;
4243 : }
4244 : | INITIALLY IMMEDIATE
4245 : {
4246 6 : Constraint *n = makeNode(Constraint);
4247 :
4248 6 : n->contype = CONSTR_ATTR_IMMEDIATE;
4249 6 : n->location = @1;
4250 6 : $$ = (Node *) n;
4251 : }
4252 : | ENFORCED
4253 : {
4254 42 : Constraint *n = makeNode(Constraint);
4255 :
4256 42 : n->contype = CONSTR_ATTR_ENFORCED;
4257 42 : n->location = @1;
4258 42 : $$ = (Node *) n;
4259 : }
4260 : | NOT ENFORCED
4261 : {
4262 66 : Constraint *n = makeNode(Constraint);
4263 :
4264 66 : n->contype = CONSTR_ATTR_NOT_ENFORCED;
4265 66 : n->location = @1;
4266 66 : $$ = (Node *) n;
4267 : }
4268 : ;
4269 :
4270 :
4271 : TableLikeClause:
4272 : LIKE qualified_name TableLikeOptionList
4273 : {
4274 786 : TableLikeClause *n = makeNode(TableLikeClause);
4275 :
4276 786 : n->relation = $2;
4277 786 : n->options = $3;
4278 786 : n->relationOid = InvalidOid;
4279 786 : $$ = (Node *) n;
4280 : }
4281 : ;
4282 :
4283 : TableLikeOptionList:
4284 288 : TableLikeOptionList INCLUDING TableLikeOption { $$ = $1 | $3; }
4285 8 : | TableLikeOptionList EXCLUDING TableLikeOption { $$ = $1 & ~$3; }
4286 786 : | /* EMPTY */ { $$ = 0; }
4287 : ;
4288 :
4289 : TableLikeOption:
4290 30 : COMMENTS { $$ = CREATE_TABLE_LIKE_COMMENTS; }
4291 6 : | COMPRESSION { $$ = CREATE_TABLE_LIKE_COMPRESSION; }
4292 54 : | CONSTRAINTS { $$ = CREATE_TABLE_LIKE_CONSTRAINTS; }
4293 20 : | DEFAULTS { $$ = CREATE_TABLE_LIKE_DEFAULTS; }
4294 12 : | IDENTITY_P { $$ = CREATE_TABLE_LIKE_IDENTITY; }
4295 30 : | GENERATED { $$ = CREATE_TABLE_LIKE_GENERATED; }
4296 50 : | INDEXES { $$ = CREATE_TABLE_LIKE_INDEXES; }
4297 0 : | STATISTICS { $$ = CREATE_TABLE_LIKE_STATISTICS; }
4298 26 : | STORAGE { $$ = CREATE_TABLE_LIKE_STORAGE; }
4299 68 : | ALL { $$ = CREATE_TABLE_LIKE_ALL; }
4300 : ;
4301 :
4302 :
4303 : /* ConstraintElem specifies constraint syntax which is not embedded into
4304 : * a column definition. ColConstraintElem specifies the embedded form.
4305 : * - thomas 1997-12-03
4306 : */
4307 : TableConstraint:
4308 : CONSTRAINT name ConstraintElem
4309 : {
4310 4184 : Constraint *n = castNode(Constraint, $3);
4311 :
4312 4184 : n->conname = $2;
4313 4184 : n->location = @1;
4314 4184 : $$ = (Node *) n;
4315 : }
4316 13528 : | ConstraintElem { $$ = $1; }
4317 : ;
4318 :
4319 : ConstraintElem:
4320 : CHECK '(' a_expr ')' ConstraintAttributeSpec
4321 : {
4322 1328 : Constraint *n = makeNode(Constraint);
4323 :
4324 1328 : n->contype = CONSTR_CHECK;
4325 1328 : n->location = @1;
4326 1328 : n->raw_expr = $3;
4327 1328 : n->cooked_expr = NULL;
4328 1328 : processCASbits($5, @5, "CHECK",
4329 : NULL, NULL, &n->is_enforced, &n->skip_validation,
4330 : &n->is_no_inherit, yyscanner);
4331 1328 : n->initially_valid = !n->skip_validation;
4332 1328 : $$ = (Node *) n;
4333 : }
4334 : | NOT NULL_P ColId ConstraintAttributeSpec
4335 : {
4336 610 : Constraint *n = makeNode(Constraint);
4337 :
4338 610 : n->contype = CONSTR_NOTNULL;
4339 610 : n->location = @1;
4340 610 : n->keys = list_make1(makeString($3));
4341 610 : processCASbits($4, @4, "NOT NULL",
4342 : NULL, NULL, NULL, &n->skip_validation,
4343 : &n->is_no_inherit, yyscanner);
4344 610 : n->initially_valid = !n->skip_validation;
4345 610 : $$ = (Node *) n;
4346 : }
4347 : | UNIQUE opt_unique_null_treatment '(' columnList opt_without_overlaps ')' opt_c_include opt_definition OptConsTableSpace
4348 : ConstraintAttributeSpec
4349 : {
4350 598 : Constraint *n = makeNode(Constraint);
4351 :
4352 598 : n->contype = CONSTR_UNIQUE;
4353 598 : n->location = @1;
4354 598 : n->nulls_not_distinct = !$2;
4355 598 : n->keys = $4;
4356 598 : n->without_overlaps = $5;
4357 598 : n->including = $7;
4358 598 : n->options = $8;
4359 598 : n->indexname = NULL;
4360 598 : n->indexspace = $9;
4361 598 : processCASbits($10, @10, "UNIQUE",
4362 : &n->deferrable, &n->initdeferred, NULL,
4363 : NULL, NULL, yyscanner);
4364 598 : $$ = (Node *) n;
4365 : }
4366 : | UNIQUE ExistingIndex ConstraintAttributeSpec
4367 : {
4368 4744 : Constraint *n = makeNode(Constraint);
4369 :
4370 4744 : n->contype = CONSTR_UNIQUE;
4371 4744 : n->location = @1;
4372 4744 : n->keys = NIL;
4373 4744 : n->including = NIL;
4374 4744 : n->options = NIL;
4375 4744 : n->indexname = $2;
4376 4744 : n->indexspace = NULL;
4377 4744 : processCASbits($3, @3, "UNIQUE",
4378 : &n->deferrable, &n->initdeferred, NULL,
4379 : NULL, NULL, yyscanner);
4380 4744 : $$ = (Node *) n;
4381 : }
4382 : | PRIMARY KEY '(' columnList opt_without_overlaps ')' opt_c_include opt_definition OptConsTableSpace
4383 : ConstraintAttributeSpec
4384 : {
4385 2188 : Constraint *n = makeNode(Constraint);
4386 :
4387 2188 : n->contype = CONSTR_PRIMARY;
4388 2188 : n->location = @1;
4389 2188 : n->keys = $4;
4390 2188 : n->without_overlaps = $5;
4391 2188 : n->including = $7;
4392 2188 : n->options = $8;
4393 2188 : n->indexname = NULL;
4394 2188 : n->indexspace = $9;
4395 2188 : processCASbits($10, @10, "PRIMARY KEY",
4396 : &n->deferrable, &n->initdeferred, NULL,
4397 : NULL, NULL, yyscanner);
4398 2188 : $$ = (Node *) n;
4399 : }
4400 : | PRIMARY KEY ExistingIndex ConstraintAttributeSpec
4401 : {
4402 6142 : Constraint *n = makeNode(Constraint);
4403 :
4404 6142 : n->contype = CONSTR_PRIMARY;
4405 6142 : n->location = @1;
4406 6142 : n->keys = NIL;
4407 6142 : n->including = NIL;
4408 6142 : n->options = NIL;
4409 6142 : n->indexname = $3;
4410 6142 : n->indexspace = NULL;
4411 6142 : processCASbits($4, @4, "PRIMARY KEY",
4412 : &n->deferrable, &n->initdeferred, NULL,
4413 : NULL, NULL, yyscanner);
4414 6142 : $$ = (Node *) n;
4415 : }
4416 : | EXCLUDE access_method_clause '(' ExclusionConstraintList ')'
4417 : opt_c_include opt_definition OptConsTableSpace OptWhereClause
4418 : ConstraintAttributeSpec
4419 : {
4420 234 : Constraint *n = makeNode(Constraint);
4421 :
4422 234 : n->contype = CONSTR_EXCLUSION;
4423 234 : n->location = @1;
4424 234 : n->access_method = $2;
4425 234 : n->exclusions = $4;
4426 234 : n->including = $6;
4427 234 : n->options = $7;
4428 234 : n->indexname = NULL;
4429 234 : n->indexspace = $8;
4430 234 : n->where_clause = $9;
4431 234 : processCASbits($10, @10, "EXCLUDE",
4432 : &n->deferrable, &n->initdeferred, NULL,
4433 : NULL, NULL, yyscanner);
4434 234 : $$ = (Node *) n;
4435 : }
4436 : | FOREIGN KEY '(' columnList optionalPeriodName ')' REFERENCES qualified_name
4437 : opt_column_and_period_list key_match key_actions ConstraintAttributeSpec
4438 : {
4439 1868 : Constraint *n = makeNode(Constraint);
4440 :
4441 1868 : n->contype = CONSTR_FOREIGN;
4442 1868 : n->location = @1;
4443 1868 : n->pktable = $8;
4444 1868 : n->fk_attrs = $4;
4445 1868 : if ($5)
4446 : {
4447 326 : n->fk_attrs = lappend(n->fk_attrs, $5);
4448 326 : n->fk_with_period = true;
4449 : }
4450 1868 : n->pk_attrs = linitial($9);
4451 1868 : if (lsecond($9))
4452 : {
4453 170 : n->pk_attrs = lappend(n->pk_attrs, lsecond($9));
4454 170 : n->pk_with_period = true;
4455 : }
4456 1868 : n->fk_matchtype = $10;
4457 1868 : n->fk_upd_action = ($11)->updateAction->action;
4458 1868 : n->fk_del_action = ($11)->deleteAction->action;
4459 1868 : n->fk_del_set_cols = ($11)->deleteAction->cols;
4460 1868 : processCASbits($12, @12, "FOREIGN KEY",
4461 : &n->deferrable, &n->initdeferred,
4462 : &n->is_enforced, &n->skip_validation, NULL,
4463 : yyscanner);
4464 1868 : n->initially_valid = !n->skip_validation;
4465 1868 : $$ = (Node *) n;
4466 : }
4467 : ;
4468 :
4469 : /*
4470 : * DomainConstraint is separate from TableConstraint because the syntax for
4471 : * NOT NULL constraints is different. For table constraints, we need to
4472 : * accept a column name, but for domain constraints, we don't. (We could
4473 : * accept something like NOT NULL VALUE, but that seems weird.) CREATE DOMAIN
4474 : * (which uses ColQualList) has for a long time accepted NOT NULL without a
4475 : * column name, so it makes sense that ALTER DOMAIN (which uses
4476 : * DomainConstraint) does as well. None of these syntaxes are per SQL
4477 : * standard; we are just living with the bits of inconsistency that have built
4478 : * up over time.
4479 : */
4480 : DomainConstraint:
4481 : CONSTRAINT name DomainConstraintElem
4482 : {
4483 164 : Constraint *n = castNode(Constraint, $3);
4484 :
4485 164 : n->conname = $2;
4486 164 : n->location = @1;
4487 164 : $$ = (Node *) n;
4488 : }
4489 18 : | DomainConstraintElem { $$ = $1; }
4490 : ;
4491 :
4492 : DomainConstraintElem:
4493 : CHECK '(' a_expr ')' ConstraintAttributeSpec
4494 : {
4495 164 : Constraint *n = makeNode(Constraint);
4496 :
4497 164 : n->contype = CONSTR_CHECK;
4498 164 : n->location = @1;
4499 164 : n->raw_expr = $3;
4500 164 : n->cooked_expr = NULL;
4501 164 : processCASbits($5, @5, "CHECK",
4502 : NULL, NULL, NULL, &n->skip_validation,
4503 : &n->is_no_inherit, yyscanner);
4504 152 : n->is_enforced = true;
4505 152 : n->initially_valid = !n->skip_validation;
4506 152 : $$ = (Node *) n;
4507 : }
4508 : | NOT NULL_P ConstraintAttributeSpec
4509 : {
4510 30 : Constraint *n = makeNode(Constraint);
4511 :
4512 30 : n->contype = CONSTR_NOTNULL;
4513 30 : n->location = @1;
4514 30 : n->keys = list_make1(makeString("value"));
4515 : /* no NOT VALID, NO INHERIT support */
4516 30 : processCASbits($3, @3, "NOT NULL",
4517 : NULL, NULL, NULL,
4518 : NULL, NULL, yyscanner);
4519 30 : n->initially_valid = true;
4520 30 : $$ = (Node *) n;
4521 : }
4522 : ;
4523 :
4524 138 : opt_no_inherit: NO INHERIT { $$ = true; }
4525 7976 : | /* EMPTY */ { $$ = false; }
4526 : ;
4527 :
4528 : opt_without_overlaps:
4529 590 : WITHOUT OVERLAPS { $$ = true; }
4530 2196 : | /*EMPTY*/ { $$ = false; }
4531 : ;
4532 :
4533 : opt_column_list:
4534 10304 : '(' columnList ')' { $$ = $2; }
4535 43916 : | /*EMPTY*/ { $$ = NIL; }
4536 : ;
4537 :
4538 : columnList:
4539 16652 : columnElem { $$ = list_make1($1); }
4540 28646 : | columnList ',' columnElem { $$ = lappend($1, $3); }
4541 : ;
4542 :
4543 : optionalPeriodName:
4544 496 : ',' PERIOD columnElem { $$ = $3; }
4545 2502 : | /*EMPTY*/ { $$ = NULL; }
4546 : ;
4547 :
4548 : opt_column_and_period_list:
4549 1124 : '(' columnList optionalPeriodName ')' { $$ = list_make2($2, $3); }
4550 750 : | /*EMPTY*/ { $$ = list_make2(NIL, NULL); }
4551 : ;
4552 :
4553 : columnElem: ColId
4554 : {
4555 45794 : $$ = (Node *) makeString($1);
4556 : }
4557 : ;
4558 :
4559 168 : opt_c_include: INCLUDE '(' columnList ')' { $$ = $3; }
4560 2852 : | /* EMPTY */ { $$ = NIL; }
4561 : ;
4562 :
4563 : key_match: MATCH FULL
4564 : {
4565 98 : $$ = FKCONSTR_MATCH_FULL;
4566 : }
4567 : | MATCH PARTIAL
4568 : {
4569 0 : ereport(ERROR,
4570 : (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
4571 : errmsg("MATCH PARTIAL not yet implemented"),
4572 : parser_errposition(@1)));
4573 : $$ = FKCONSTR_MATCH_PARTIAL;
4574 : }
4575 : | MATCH SIMPLE
4576 : {
4577 6 : $$ = FKCONSTR_MATCH_SIMPLE;
4578 : }
4579 : | /*EMPTY*/
4580 : {
4581 2622 : $$ = FKCONSTR_MATCH_SIMPLE;
4582 : }
4583 : ;
4584 :
4585 : ExclusionConstraintList:
4586 234 : ExclusionConstraintElem { $$ = list_make1($1); }
4587 : | ExclusionConstraintList ',' ExclusionConstraintElem
4588 106 : { $$ = lappend($1, $3); }
4589 : ;
4590 :
4591 : ExclusionConstraintElem: index_elem WITH any_operator
4592 : {
4593 340 : $$ = list_make2($1, $3);
4594 : }
4595 : /* allow OPERATOR() decoration for the benefit of ruleutils.c */
4596 : | index_elem WITH OPERATOR '(' any_operator ')'
4597 : {
4598 0 : $$ = list_make2($1, $5);
4599 : }
4600 : ;
4601 :
4602 : OptWhereClause:
4603 464 : WHERE '(' a_expr ')' { $$ = $3; }
4604 1268 : | /*EMPTY*/ { $$ = NULL; }
4605 : ;
4606 :
4607 : key_actions:
4608 : key_update
4609 : {
4610 74 : KeyActions *n = palloc_object(KeyActions);
4611 :
4612 74 : n->updateAction = $1;
4613 74 : n->deleteAction = palloc_object(KeyAction);
4614 74 : n->deleteAction->action = FKCONSTR_ACTION_NOACTION;
4615 74 : n->deleteAction->cols = NIL;
4616 74 : $$ = n;
4617 : }
4618 : | key_delete
4619 : {
4620 150 : KeyActions *n = palloc_object(KeyActions);
4621 :
4622 150 : n->updateAction = palloc_object(KeyAction);
4623 150 : n->updateAction->action = FKCONSTR_ACTION_NOACTION;
4624 150 : n->updateAction->cols = NIL;
4625 150 : n->deleteAction = $1;
4626 150 : $$ = n;
4627 : }
4628 : | key_update key_delete
4629 : {
4630 168 : KeyActions *n = palloc_object(KeyActions);
4631 :
4632 168 : n->updateAction = $1;
4633 168 : n->deleteAction = $2;
4634 168 : $$ = n;
4635 : }
4636 : | key_delete key_update
4637 : {
4638 150 : KeyActions *n = palloc_object(KeyActions);
4639 :
4640 150 : n->updateAction = $2;
4641 150 : n->deleteAction = $1;
4642 150 : $$ = n;
4643 : }
4644 : | /*EMPTY*/
4645 : {
4646 2178 : KeyActions *n = palloc_object(KeyActions);
4647 :
4648 2178 : n->updateAction = palloc_object(KeyAction);
4649 2178 : n->updateAction->action = FKCONSTR_ACTION_NOACTION;
4650 2178 : n->updateAction->cols = NIL;
4651 2178 : n->deleteAction = palloc_object(KeyAction);
4652 2178 : n->deleteAction->action = FKCONSTR_ACTION_NOACTION;
4653 2178 : n->deleteAction->cols = NIL;
4654 2178 : $$ = n;
4655 : }
4656 : ;
4657 :
4658 : key_update: ON UPDATE key_action
4659 : {
4660 398 : if (($3)->cols)
4661 6 : ereport(ERROR,
4662 : (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
4663 : errmsg("a column list with %s is only supported for ON DELETE actions",
4664 : ($3)->action == FKCONSTR_ACTION_SETNULL ? "SET NULL" : "SET DEFAULT"),
4665 : parser_errposition(@1)));
4666 392 : $$ = $3;
4667 : }
4668 : ;
4669 :
4670 : key_delete: ON DELETE_P key_action
4671 : {
4672 468 : $$ = $3;
4673 : }
4674 : ;
4675 :
4676 : key_action:
4677 : NO ACTION
4678 : {
4679 80 : KeyAction *n = palloc_object(KeyAction);
4680 :
4681 80 : n->action = FKCONSTR_ACTION_NOACTION;
4682 80 : n->cols = NIL;
4683 80 : $$ = n;
4684 : }
4685 : | RESTRICT
4686 : {
4687 48 : KeyAction *n = palloc_object(KeyAction);
4688 :
4689 48 : n->action = FKCONSTR_ACTION_RESTRICT;
4690 48 : n->cols = NIL;
4691 48 : $$ = n;
4692 : }
4693 : | CASCADE
4694 : {
4695 446 : KeyAction *n = palloc_object(KeyAction);
4696 :
4697 446 : n->action = FKCONSTR_ACTION_CASCADE;
4698 446 : n->cols = NIL;
4699 446 : $$ = n;
4700 : }
4701 : | SET NULL_P opt_column_list
4702 : {
4703 190 : KeyAction *n = palloc_object(KeyAction);
4704 :
4705 190 : n->action = FKCONSTR_ACTION_SETNULL;
4706 190 : n->cols = $3;
4707 190 : $$ = n;
4708 : }
4709 : | SET DEFAULT opt_column_list
4710 : {
4711 102 : KeyAction *n = palloc_object(KeyAction);
4712 :
4713 102 : n->action = FKCONSTR_ACTION_SETDEFAULT;
4714 102 : n->cols = $3;
4715 102 : $$ = n;
4716 : }
4717 : ;
4718 :
4719 2132 : OptInherit: INHERITS '(' qualified_name_list ')' { $$ = $3; }
4720 29168 : | /*EMPTY*/ { $$ = NIL; }
4721 : ;
4722 :
4723 : /* Optional partition key specification */
4724 5592 : OptPartitionSpec: PartitionSpec { $$ = $1; }
4725 34482 : | /*EMPTY*/ { $$ = NULL; }
4726 : ;
4727 :
4728 : PartitionSpec: PARTITION BY ColId '(' part_params ')'
4729 : {
4730 5598 : PartitionSpec *n = makeNode(PartitionSpec);
4731 :
4732 5598 : n->strategy = parsePartitionStrategy($3, @3, yyscanner);
4733 5592 : n->partParams = $5;
4734 5592 : n->location = @1;
4735 :
4736 5592 : $$ = n;
4737 : }
4738 : ;
4739 :
4740 5598 : part_params: part_elem { $$ = list_make1($1); }
4741 486 : | part_params ',' part_elem { $$ = lappend($1, $3); }
4742 : ;
4743 :
4744 : part_elem: ColId opt_collate opt_qualified_name
4745 : {
4746 5732 : PartitionElem *n = makeNode(PartitionElem);
4747 :
4748 5732 : n->name = $1;
4749 5732 : n->expr = NULL;
4750 5732 : n->collation = $2;
4751 5732 : n->opclass = $3;
4752 5732 : n->location = @1;
4753 5732 : $$ = n;
4754 : }
4755 : | func_expr_windowless opt_collate opt_qualified_name
4756 : {
4757 142 : PartitionElem *n = makeNode(PartitionElem);
4758 :
4759 142 : n->name = NULL;
4760 142 : n->expr = $1;
4761 142 : n->collation = $2;
4762 142 : n->opclass = $3;
4763 142 : n->location = @1;
4764 142 : $$ = n;
4765 : }
4766 : | '(' a_expr ')' opt_collate opt_qualified_name
4767 : {
4768 210 : PartitionElem *n = makeNode(PartitionElem);
4769 :
4770 210 : n->name = NULL;
4771 210 : n->expr = $2;
4772 210 : n->collation = $4;
4773 210 : n->opclass = $5;
4774 210 : n->location = @1;
4775 210 : $$ = n;
4776 : }
4777 : ;
4778 :
4779 : table_access_method_clause:
4780 134 : USING name { $$ = $2; }
4781 41890 : | /*EMPTY*/ { $$ = NULL; }
4782 : ;
4783 :
4784 : /* WITHOUT OIDS is legacy only */
4785 : OptWith:
4786 856 : WITH reloptions { $$ = $2; }
4787 24 : | WITHOUT OIDS { $$ = NIL; }
4788 40550 : | /*EMPTY*/ { $$ = NIL; }
4789 : ;
4790 :
4791 66 : OnCommitOption: ON COMMIT DROP { $$ = ONCOMMIT_DROP; }
4792 104 : | ON COMMIT DELETE_P ROWS { $$ = ONCOMMIT_DELETE_ROWS; }
4793 24 : | ON COMMIT PRESERVE ROWS { $$ = ONCOMMIT_PRESERVE_ROWS; }
4794 41236 : | /*EMPTY*/ { $$ = ONCOMMIT_NOOP; }
4795 : ;
4796 :
4797 228 : OptTableSpace: TABLESPACE name { $$ = $2; }
4798 48576 : | /*EMPTY*/ { $$ = NULL; }
4799 : ;
4800 :
4801 78 : OptConsTableSpace: USING INDEX TABLESPACE name { $$ = $4; }
4802 9410 : | /*EMPTY*/ { $$ = NULL; }
4803 : ;
4804 :
4805 10886 : ExistingIndex: USING INDEX name { $$ = $3; }
4806 : ;
4807 :
4808 : /*****************************************************************************
4809 : *
4810 : * QUERY :
4811 : * CREATE STATISTICS [[IF NOT EXISTS] stats_name] [(stat types)]
4812 : * ON expression-list FROM from_list
4813 : *
4814 : * Note: the expectation here is that the clauses after ON are a subset of
4815 : * SELECT syntax, allowing for expressions and joined tables, and probably
4816 : * someday a WHERE clause. Much less than that is currently implemented,
4817 : * but the grammar accepts it and then we'll throw FEATURE_NOT_SUPPORTED
4818 : * errors as necessary at execution.
4819 : *
4820 : * Statistics name is optional unless IF NOT EXISTS is specified.
4821 : *
4822 : *****************************************************************************/
4823 :
4824 : CreateStatsStmt:
4825 : CREATE STATISTICS opt_qualified_name
4826 : opt_name_list ON stats_params FROM from_list
4827 : {
4828 862 : CreateStatsStmt *n = makeNode(CreateStatsStmt);
4829 :
4830 862 : n->defnames = $3;
4831 862 : n->stat_types = $4;
4832 862 : n->exprs = $6;
4833 862 : n->relations = $8;
4834 862 : n->stxcomment = NULL;
4835 862 : n->if_not_exists = false;
4836 862 : $$ = (Node *) n;
4837 : }
4838 : | CREATE STATISTICS IF_P NOT EXISTS any_name
4839 : opt_name_list ON stats_params FROM from_list
4840 : {
4841 12 : CreateStatsStmt *n = makeNode(CreateStatsStmt);
4842 :
4843 12 : n->defnames = $6;
4844 12 : n->stat_types = $7;
4845 12 : n->exprs = $9;
4846 12 : n->relations = $11;
4847 12 : n->stxcomment = NULL;
4848 12 : n->if_not_exists = true;
4849 12 : $$ = (Node *) n;
4850 : }
4851 : ;
4852 :
4853 : /*
4854 : * Statistics attributes can be either simple column references, or arbitrary
4855 : * expressions in parens. For compatibility with index attributes permitted
4856 : * in CREATE INDEX, we allow an expression that's just a function call to be
4857 : * written without parens.
4858 : */
4859 :
4860 886 : stats_params: stats_param { $$ = list_make1($1); }
4861 1200 : | stats_params ',' stats_param { $$ = lappend($1, $3); }
4862 : ;
4863 :
4864 : stats_param: ColId
4865 : {
4866 1576 : $$ = makeNode(StatsElem);
4867 1576 : $$->name = $1;
4868 1576 : $$->expr = NULL;
4869 : }
4870 : | func_expr_windowless
4871 : {
4872 38 : $$ = makeNode(StatsElem);
4873 38 : $$->name = NULL;
4874 38 : $$->expr = $1;
4875 : }
4876 : | '(' a_expr ')'
4877 : {
4878 472 : $$ = makeNode(StatsElem);
4879 472 : $$->name = NULL;
4880 472 : $$->expr = $2;
4881 : }
4882 : ;
4883 :
4884 : /*****************************************************************************
4885 : *
4886 : * QUERY :
4887 : * ALTER STATISTICS [IF EXISTS] stats_name
4888 : * SET STATISTICS <SignedIconst>
4889 : *
4890 : *****************************************************************************/
4891 :
4892 : AlterStatsStmt:
4893 : ALTER STATISTICS any_name SET STATISTICS set_statistics_value
4894 : {
4895 20 : AlterStatsStmt *n = makeNode(AlterStatsStmt);
4896 :
4897 20 : n->defnames = $3;
4898 20 : n->missing_ok = false;
4899 20 : n->stxstattarget = $6;
4900 20 : $$ = (Node *) n;
4901 : }
4902 : | ALTER STATISTICS IF_P EXISTS any_name SET STATISTICS set_statistics_value
4903 : {
4904 6 : AlterStatsStmt *n = makeNode(AlterStatsStmt);
4905 :
4906 6 : n->defnames = $5;
4907 6 : n->missing_ok = true;
4908 6 : n->stxstattarget = $8;
4909 6 : $$ = (Node *) n;
4910 : }
4911 : ;
4912 :
4913 : /*****************************************************************************
4914 : *
4915 : * QUERY :
4916 : * CREATE TABLE relname AS SelectStmt [ WITH [NO] DATA ]
4917 : *
4918 : *
4919 : * Note: SELECT ... INTO is a now-deprecated alternative for this.
4920 : *
4921 : *****************************************************************************/
4922 :
4923 : CreateAsStmt:
4924 : CREATE OptTemp TABLE create_as_target AS SelectStmt opt_with_data
4925 : {
4926 1228 : CreateTableAsStmt *ctas = makeNode(CreateTableAsStmt);
4927 :
4928 1228 : ctas->query = $6;
4929 1228 : ctas->into = $4;
4930 1228 : ctas->objtype = OBJECT_TABLE;
4931 1228 : ctas->is_select_into = false;
4932 1228 : ctas->if_not_exists = false;
4933 : /* cram additional flags into the IntoClause */
4934 1228 : $4->rel->relpersistence = $2;
4935 1228 : $4->skipData = !($7);
4936 1228 : $$ = (Node *) ctas;
4937 : }
4938 : | CREATE OptTemp TABLE IF_P NOT EXISTS create_as_target AS SelectStmt opt_with_data
4939 : {
4940 52 : CreateTableAsStmt *ctas = makeNode(CreateTableAsStmt);
4941 :
4942 52 : ctas->query = $9;
4943 52 : ctas->into = $7;
4944 52 : ctas->objtype = OBJECT_TABLE;
4945 52 : ctas->is_select_into = false;
4946 52 : ctas->if_not_exists = true;
4947 : /* cram additional flags into the IntoClause */
4948 52 : $7->rel->relpersistence = $2;
4949 52 : $7->skipData = !($10);
4950 52 : $$ = (Node *) ctas;
4951 : }
4952 : ;
4953 :
4954 : create_as_target:
4955 : qualified_name opt_column_list table_access_method_clause
4956 : OptWith OnCommitOption OptTableSpace
4957 : {
4958 1368 : $$ = makeNode(IntoClause);
4959 1368 : $$->rel = $1;
4960 1368 : $$->colNames = $2;
4961 1368 : $$->accessMethod = $3;
4962 1368 : $$->options = $4;
4963 1368 : $$->onCommit = $5;
4964 1368 : $$->tableSpaceName = $6;
4965 1368 : $$->viewQuery = NULL;
4966 1368 : $$->skipData = false; /* might get changed later */
4967 : }
4968 : ;
4969 :
4970 : opt_with_data:
4971 36 : WITH DATA_P { $$ = true; }
4972 218 : | WITH NO DATA_P { $$ = false; }
4973 1970 : | /*EMPTY*/ { $$ = true; }
4974 : ;
4975 :
4976 :
4977 : /*****************************************************************************
4978 : *
4979 : * QUERY :
4980 : * CREATE MATERIALIZED VIEW relname AS SelectStmt
4981 : *
4982 : *****************************************************************************/
4983 :
4984 : CreateMatViewStmt:
4985 : CREATE OptNoLog MATERIALIZED VIEW create_mv_target AS SelectStmt opt_with_data
4986 : {
4987 540 : CreateTableAsStmt *ctas = makeNode(CreateTableAsStmt);
4988 :
4989 540 : ctas->query = $7;
4990 540 : ctas->into = $5;
4991 540 : ctas->objtype = OBJECT_MATVIEW;
4992 540 : ctas->is_select_into = false;
4993 540 : ctas->if_not_exists = false;
4994 : /* cram additional flags into the IntoClause */
4995 540 : $5->rel->relpersistence = $2;
4996 540 : $5->skipData = !($8);
4997 540 : $$ = (Node *) ctas;
4998 : }
4999 : | CREATE OptNoLog MATERIALIZED VIEW IF_P NOT EXISTS create_mv_target AS SelectStmt opt_with_data
5000 : {
5001 48 : CreateTableAsStmt *ctas = makeNode(CreateTableAsStmt);
5002 :
5003 48 : ctas->query = $10;
5004 48 : ctas->into = $8;
5005 48 : ctas->objtype = OBJECT_MATVIEW;
5006 48 : ctas->is_select_into = false;
5007 48 : ctas->if_not_exists = true;
5008 : /* cram additional flags into the IntoClause */
5009 48 : $8->rel->relpersistence = $2;
5010 48 : $8->skipData = !($11);
5011 48 : $$ = (Node *) ctas;
5012 : }
5013 : ;
5014 :
5015 : create_mv_target:
5016 : qualified_name opt_column_list table_access_method_clause opt_reloptions OptTableSpace
5017 : {
5018 588 : $$ = makeNode(IntoClause);
5019 588 : $$->rel = $1;
5020 588 : $$->colNames = $2;
5021 588 : $$->accessMethod = $3;
5022 588 : $$->options = $4;
5023 588 : $$->onCommit = ONCOMMIT_NOOP;
5024 588 : $$->tableSpaceName = $5;
5025 588 : $$->viewQuery = NULL; /* filled at analysis time */
5026 588 : $$->skipData = false; /* might get changed later */
5027 : }
5028 : ;
5029 :
5030 0 : OptNoLog: UNLOGGED { $$ = RELPERSISTENCE_UNLOGGED; }
5031 588 : | /*EMPTY*/ { $$ = RELPERSISTENCE_PERMANENT; }
5032 : ;
5033 :
5034 :
5035 : /*****************************************************************************
5036 : *
5037 : * QUERY :
5038 : * REFRESH MATERIALIZED VIEW qualified_name
5039 : *
5040 : *****************************************************************************/
5041 :
5042 : RefreshMatViewStmt:
5043 : REFRESH MATERIALIZED VIEW opt_concurrently qualified_name opt_with_data
5044 : {
5045 268 : RefreshMatViewStmt *n = makeNode(RefreshMatViewStmt);
5046 :
5047 268 : n->concurrent = $4;
5048 268 : n->relation = $5;
5049 268 : n->skipData = !($6);
5050 268 : $$ = (Node *) n;
5051 : }
5052 : ;
5053 :
5054 :
5055 : /*****************************************************************************
5056 : *
5057 : * QUERY :
5058 : * CREATE SEQUENCE seqname
5059 : * ALTER SEQUENCE seqname
5060 : *
5061 : *****************************************************************************/
5062 :
5063 : CreateSeqStmt:
5064 : CREATE OptTemp SEQUENCE qualified_name OptSeqOptList
5065 : {
5066 702 : CreateSeqStmt *n = makeNode(CreateSeqStmt);
5067 :
5068 702 : $4->relpersistence = $2;
5069 702 : n->sequence = $4;
5070 702 : n->options = $5;
5071 702 : n->ownerId = InvalidOid;
5072 702 : n->if_not_exists = false;
5073 702 : $$ = (Node *) n;
5074 : }
5075 : | CREATE OptTemp SEQUENCE IF_P NOT EXISTS qualified_name OptSeqOptList
5076 : {
5077 24 : CreateSeqStmt *n = makeNode(CreateSeqStmt);
5078 :
5079 24 : $7->relpersistence = $2;
5080 24 : n->sequence = $7;
5081 24 : n->options = $8;
5082 24 : n->ownerId = InvalidOid;
5083 24 : n->if_not_exists = true;
5084 24 : $$ = (Node *) n;
5085 : }
5086 : ;
5087 :
5088 : AlterSeqStmt:
5089 : ALTER SEQUENCE qualified_name SeqOptList
5090 : {
5091 188 : AlterSeqStmt *n = makeNode(AlterSeqStmt);
5092 :
5093 188 : n->sequence = $3;
5094 188 : n->options = $4;
5095 188 : n->missing_ok = false;
5096 188 : $$ = (Node *) n;
5097 : }
5098 : | ALTER SEQUENCE IF_P EXISTS qualified_name SeqOptList
5099 : {
5100 12 : AlterSeqStmt *n = makeNode(AlterSeqStmt);
5101 :
5102 12 : n->sequence = $5;
5103 12 : n->options = $6;
5104 12 : n->missing_ok = true;
5105 12 : $$ = (Node *) n;
5106 : }
5107 :
5108 : ;
5109 :
5110 270 : OptSeqOptList: SeqOptList { $$ = $1; }
5111 456 : | /*EMPTY*/ { $$ = NIL; }
5112 : ;
5113 :
5114 74 : OptParenthesizedSeqOptList: '(' SeqOptList ')' { $$ = $2; }
5115 470 : | /*EMPTY*/ { $$ = NIL; }
5116 : ;
5117 :
5118 544 : SeqOptList: SeqOptElem { $$ = list_make1($1); }
5119 806 : | SeqOptList SeqOptElem { $$ = lappend($1, $2); }
5120 : ;
5121 :
5122 : SeqOptElem: AS SimpleTypename
5123 : {
5124 190 : $$ = makeDefElem("as", (Node *) $2, @1);
5125 : }
5126 : | CACHE NumericOnly
5127 : {
5128 130 : $$ = makeDefElem("cache", (Node *) $2, @1);
5129 : }
5130 : | CYCLE
5131 : {
5132 34 : $$ = makeDefElem("cycle", (Node *) makeBoolean(true), @1);
5133 : }
5134 : | NO CYCLE
5135 : {
5136 14 : $$ = makeDefElem("cycle", (Node *) makeBoolean(false), @1);
5137 : }
5138 : | INCREMENT opt_by NumericOnly
5139 : {
5140 258 : $$ = makeDefElem("increment", (Node *) $3, @1);
5141 : }
5142 : | LOGGED
5143 : {
5144 2 : $$ = makeDefElem("logged", NULL, @1);
5145 : }
5146 : | MAXVALUE NumericOnly
5147 : {
5148 68 : $$ = makeDefElem("maxvalue", (Node *) $2, @1);
5149 : }
5150 : | MINVALUE NumericOnly
5151 : {
5152 68 : $$ = makeDefElem("minvalue", (Node *) $2, @1);
5153 : }
5154 : | NO MAXVALUE
5155 : {
5156 108 : $$ = makeDefElem("maxvalue", NULL, @1);
5157 : }
5158 : | NO MINVALUE
5159 : {
5160 108 : $$ = makeDefElem("minvalue", NULL, @1);
5161 : }
5162 : | OWNED BY any_name
5163 : {
5164 72 : $$ = makeDefElem("owned_by", (Node *) $3, @1);
5165 : }
5166 : | SEQUENCE NAME_P any_name
5167 : {
5168 44 : $$ = makeDefElem("sequence_name", (Node *) $3, @1);
5169 : }
5170 : | START opt_with NumericOnly
5171 : {
5172 240 : $$ = makeDefElem("start", (Node *) $3, @1);
5173 : }
5174 : | RESTART
5175 : {
5176 6 : $$ = makeDefElem("restart", NULL, @1);
5177 : }
5178 : | RESTART opt_with NumericOnly
5179 : {
5180 60 : $$ = makeDefElem("restart", (Node *) $3, @1);
5181 : }
5182 : | UNLOGGED
5183 : {
5184 2 : $$ = makeDefElem("unlogged", NULL, @1);
5185 : }
5186 : ;
5187 :
5188 : opt_by: BY
5189 : | /* EMPTY */
5190 : ;
5191 :
5192 : NumericOnly:
5193 324 : FCONST { $$ = (Node *) makeFloat($1); }
5194 0 : | '+' FCONST { $$ = (Node *) makeFloat($2); }
5195 : | '-' FCONST
5196 : {
5197 20 : Float *f = makeFloat($2);
5198 :
5199 20 : doNegateFloat(f);
5200 20 : $$ = (Node *) f;
5201 : }
5202 13252 : | SignedIconst { $$ = (Node *) makeInteger($1); }
5203 : ;
5204 :
5205 90 : NumericOnly_list: NumericOnly { $$ = list_make1($1); }
5206 6 : | NumericOnly_list ',' NumericOnly { $$ = lappend($1, $3); }
5207 : ;
5208 :
5209 : /*****************************************************************************
5210 : *
5211 : * QUERIES :
5212 : * CREATE [OR REPLACE] [TRUSTED] [PROCEDURAL] LANGUAGE ...
5213 : * DROP [PROCEDURAL] LANGUAGE ...
5214 : *
5215 : *****************************************************************************/
5216 :
5217 : CreatePLangStmt:
5218 : CREATE opt_or_replace opt_trusted opt_procedural LANGUAGE name
5219 : {
5220 : /*
5221 : * We now interpret parameterless CREATE LANGUAGE as
5222 : * CREATE EXTENSION. "OR REPLACE" is silently translated
5223 : * to "IF NOT EXISTS", which isn't quite the same, but
5224 : * seems more useful than throwing an error. We just
5225 : * ignore TRUSTED, as the previous code would have too.
5226 : */
5227 0 : CreateExtensionStmt *n = makeNode(CreateExtensionStmt);
5228 :
5229 0 : n->if_not_exists = $2;
5230 0 : n->extname = $6;
5231 0 : n->options = NIL;
5232 0 : $$ = (Node *) n;
5233 : }
5234 : | CREATE opt_or_replace opt_trusted opt_procedural LANGUAGE name
5235 : HANDLER handler_name opt_inline_handler opt_validator
5236 : {
5237 144 : CreatePLangStmt *n = makeNode(CreatePLangStmt);
5238 :
5239 144 : n->replace = $2;
5240 144 : n->plname = $6;
5241 144 : n->plhandler = $8;
5242 144 : n->plinline = $9;
5243 144 : n->plvalidator = $10;
5244 144 : n->pltrusted = $3;
5245 144 : $$ = (Node *) n;
5246 : }
5247 : ;
5248 :
5249 : opt_trusted:
5250 114 : TRUSTED { $$ = true; }
5251 38 : | /*EMPTY*/ { $$ = false; }
5252 : ;
5253 :
5254 : /* This ought to be just func_name, but that causes reduce/reduce conflicts
5255 : * (CREATE LANGUAGE is the only place where func_name isn't followed by '(').
5256 : * Work around by using simple names, instead.
5257 : */
5258 : handler_name:
5259 576 : name { $$ = list_make1(makeString($1)); }
5260 2 : | name attrs { $$ = lcons(makeString($1), $2); }
5261 : ;
5262 :
5263 : opt_inline_handler:
5264 126 : INLINE_P handler_name { $$ = $2; }
5265 18 : | /*EMPTY*/ { $$ = NIL; }
5266 : ;
5267 :
5268 : validator_clause:
5269 126 : VALIDATOR handler_name { $$ = $2; }
5270 0 : | NO VALIDATOR { $$ = NIL; }
5271 : ;
5272 :
5273 : opt_validator:
5274 126 : validator_clause { $$ = $1; }
5275 18 : | /*EMPTY*/ { $$ = NIL; }
5276 : ;
5277 :
5278 : opt_procedural:
5279 : PROCEDURAL
5280 : | /*EMPTY*/
5281 : ;
5282 :
5283 : /*****************************************************************************
5284 : *
5285 : * QUERY:
5286 : * CREATE TABLESPACE tablespace LOCATION '/path/to/tablespace/'
5287 : *
5288 : *****************************************************************************/
5289 :
5290 : CreateTableSpaceStmt: CREATE TABLESPACE name OptTableSpaceOwner LOCATION Sconst opt_reloptions
5291 : {
5292 130 : CreateTableSpaceStmt *n = makeNode(CreateTableSpaceStmt);
5293 :
5294 130 : n->tablespacename = $3;
5295 130 : n->owner = $4;
5296 130 : n->location = $6;
5297 130 : n->options = $7;
5298 130 : $$ = (Node *) n;
5299 : }
5300 : ;
5301 :
5302 10 : OptTableSpaceOwner: OWNER RoleSpec { $$ = $2; }
5303 120 : | /*EMPTY */ { $$ = NULL; }
5304 : ;
5305 :
5306 : /*****************************************************************************
5307 : *
5308 : * QUERY :
5309 : * DROP TABLESPACE <tablespace>
5310 : *
5311 : * No need for drop behaviour as we cannot implement dependencies for
5312 : * objects in other databases; we can only support RESTRICT.
5313 : *
5314 : ****************************************************************************/
5315 :
5316 : DropTableSpaceStmt: DROP TABLESPACE name
5317 : {
5318 64 : DropTableSpaceStmt *n = makeNode(DropTableSpaceStmt);
5319 :
5320 64 : n->tablespacename = $3;
5321 64 : n->missing_ok = false;
5322 64 : $$ = (Node *) n;
5323 : }
5324 : | DROP TABLESPACE IF_P EXISTS name
5325 : {
5326 0 : DropTableSpaceStmt *n = makeNode(DropTableSpaceStmt);
5327 :
5328 0 : n->tablespacename = $5;
5329 0 : n->missing_ok = true;
5330 0 : $$ = (Node *) n;
5331 : }
5332 : ;
5333 :
5334 : /*****************************************************************************
5335 : *
5336 : * QUERY:
5337 : * CREATE EXTENSION extension
5338 : * [ WITH ] [ SCHEMA schema ] [ VERSION version ]
5339 : *
5340 : *****************************************************************************/
5341 :
5342 : CreateExtensionStmt: CREATE EXTENSION name opt_with create_extension_opt_list
5343 : {
5344 556 : CreateExtensionStmt *n = makeNode(CreateExtensionStmt);
5345 :
5346 556 : n->extname = $3;
5347 556 : n->if_not_exists = false;
5348 556 : n->options = $5;
5349 556 : $$ = (Node *) n;
5350 : }
5351 : | CREATE EXTENSION IF_P NOT EXISTS name opt_with create_extension_opt_list
5352 : {
5353 20 : CreateExtensionStmt *n = makeNode(CreateExtensionStmt);
5354 :
5355 20 : n->extname = $6;
5356 20 : n->if_not_exists = true;
5357 20 : n->options = $8;
5358 20 : $$ = (Node *) n;
5359 : }
5360 : ;
5361 :
5362 : create_extension_opt_list:
5363 : create_extension_opt_list create_extension_opt_item
5364 98 : { $$ = lappend($1, $2); }
5365 : | /* EMPTY */
5366 576 : { $$ = NIL; }
5367 : ;
5368 :
5369 : create_extension_opt_item:
5370 : SCHEMA name
5371 : {
5372 46 : $$ = makeDefElem("schema", (Node *) makeString($2), @1);
5373 : }
5374 : | VERSION_P NonReservedWord_or_Sconst
5375 : {
5376 12 : $$ = makeDefElem("new_version", (Node *) makeString($2), @1);
5377 : }
5378 : | FROM NonReservedWord_or_Sconst
5379 : {
5380 0 : ereport(ERROR,
5381 : (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
5382 : errmsg("CREATE EXTENSION ... FROM is no longer supported"),
5383 : parser_errposition(@1)));
5384 : }
5385 : | CASCADE
5386 : {
5387 40 : $$ = makeDefElem("cascade", (Node *) makeBoolean(true), @1);
5388 : }
5389 : ;
5390 :
5391 : /*****************************************************************************
5392 : *
5393 : * ALTER EXTENSION name UPDATE [ TO version ]
5394 : *
5395 : *****************************************************************************/
5396 :
5397 : AlterExtensionStmt: ALTER EXTENSION name UPDATE alter_extension_opt_list
5398 : {
5399 40 : AlterExtensionStmt *n = makeNode(AlterExtensionStmt);
5400 :
5401 40 : n->extname = $3;
5402 40 : n->options = $5;
5403 40 : $$ = (Node *) n;
5404 : }
5405 : ;
5406 :
5407 : alter_extension_opt_list:
5408 : alter_extension_opt_list alter_extension_opt_item
5409 40 : { $$ = lappend($1, $2); }
5410 : | /* EMPTY */
5411 40 : { $$ = NIL; }
5412 : ;
5413 :
5414 : alter_extension_opt_item:
5415 : TO NonReservedWord_or_Sconst
5416 : {
5417 40 : $$ = makeDefElem("new_version", (Node *) makeString($2), @1);
5418 : }
5419 : ;
5420 :
5421 : /*****************************************************************************
5422 : *
5423 : * ALTER EXTENSION name ADD/DROP object-identifier
5424 : *
5425 : *****************************************************************************/
5426 :
5427 : AlterExtensionContentsStmt:
5428 : ALTER EXTENSION name add_drop object_type_name name
5429 : {
5430 18 : AlterExtensionContentsStmt *n = makeNode(AlterExtensionContentsStmt);
5431 :
5432 18 : n->extname = $3;
5433 18 : n->action = $4;
5434 18 : n->objtype = $5;
5435 18 : n->object = (Node *) makeString($6);
5436 18 : $$ = (Node *) n;
5437 : }
5438 : | ALTER EXTENSION name add_drop object_type_any_name any_name
5439 : {
5440 88 : AlterExtensionContentsStmt *n = makeNode(AlterExtensionContentsStmt);
5441 :
5442 88 : n->extname = $3;
5443 88 : n->action = $4;
5444 88 : n->objtype = $5;
5445 88 : n->object = (Node *) $6;
5446 88 : $$ = (Node *) n;
5447 : }
5448 : | ALTER EXTENSION name add_drop AGGREGATE aggregate_with_argtypes
5449 : {
5450 8 : AlterExtensionContentsStmt *n = makeNode(AlterExtensionContentsStmt);
5451 :
5452 8 : n->extname = $3;
5453 8 : n->action = $4;
5454 8 : n->objtype = OBJECT_AGGREGATE;
5455 8 : n->object = (Node *) $6;
5456 8 : $$ = (Node *) n;
5457 : }
5458 : | ALTER EXTENSION name add_drop CAST '(' Typename AS Typename ')'
5459 : {
5460 4 : AlterExtensionContentsStmt *n = makeNode(AlterExtensionContentsStmt);
5461 :
5462 4 : n->extname = $3;
5463 4 : n->action = $4;
5464 4 : n->objtype = OBJECT_CAST;
5465 4 : n->object = (Node *) list_make2($7, $9);
5466 4 : $$ = (Node *) n;
5467 : }
5468 : | ALTER EXTENSION name add_drop DOMAIN_P Typename
5469 : {
5470 0 : AlterExtensionContentsStmt *n = makeNode(AlterExtensionContentsStmt);
5471 :
5472 0 : n->extname = $3;
5473 0 : n->action = $4;
5474 0 : n->objtype = OBJECT_DOMAIN;
5475 0 : n->object = (Node *) $6;
5476 0 : $$ = (Node *) n;
5477 : }
5478 : | ALTER EXTENSION name add_drop FUNCTION function_with_argtypes
5479 : {
5480 120 : AlterExtensionContentsStmt *n = makeNode(AlterExtensionContentsStmt);
5481 :
5482 120 : n->extname = $3;
5483 120 : n->action = $4;
5484 120 : n->objtype = OBJECT_FUNCTION;
5485 120 : n->object = (Node *) $6;
5486 120 : $$ = (Node *) n;
5487 : }
5488 : | ALTER EXTENSION name add_drop OPERATOR operator_with_argtypes
5489 : {
5490 18 : AlterExtensionContentsStmt *n = makeNode(AlterExtensionContentsStmt);
5491 :
5492 18 : n->extname = $3;
5493 18 : n->action = $4;
5494 18 : n->objtype = OBJECT_OPERATOR;
5495 18 : n->object = (Node *) $6;
5496 18 : $$ = (Node *) n;
5497 : }
5498 : | ALTER EXTENSION name add_drop OPERATOR CLASS any_name USING name
5499 : {
5500 4 : AlterExtensionContentsStmt *n = makeNode(AlterExtensionContentsStmt);
5501 :
5502 4 : n->extname = $3;
5503 4 : n->action = $4;
5504 4 : n->objtype = OBJECT_OPCLASS;
5505 4 : n->object = (Node *) lcons(makeString($9), $7);
5506 4 : $$ = (Node *) n;
5507 : }
5508 : | ALTER EXTENSION name add_drop OPERATOR FAMILY any_name USING name
5509 : {
5510 4 : AlterExtensionContentsStmt *n = makeNode(AlterExtensionContentsStmt);
5511 :
5512 4 : n->extname = $3;
5513 4 : n->action = $4;
5514 4 : n->objtype = OBJECT_OPFAMILY;
5515 4 : n->object = (Node *) lcons(makeString($9), $7);
5516 4 : $$ = (Node *) n;
5517 : }
5518 : | ALTER EXTENSION name add_drop PROCEDURE function_with_argtypes
5519 : {
5520 0 : AlterExtensionContentsStmt *n = makeNode(AlterExtensionContentsStmt);
5521 :
5522 0 : n->extname = $3;
5523 0 : n->action = $4;
5524 0 : n->objtype = OBJECT_PROCEDURE;
5525 0 : n->object = (Node *) $6;
5526 0 : $$ = (Node *) n;
5527 : }
5528 : | ALTER EXTENSION name add_drop ROUTINE function_with_argtypes
5529 : {
5530 0 : AlterExtensionContentsStmt *n = makeNode(AlterExtensionContentsStmt);
5531 :
5532 0 : n->extname = $3;
5533 0 : n->action = $4;
5534 0 : n->objtype = OBJECT_ROUTINE;
5535 0 : n->object = (Node *) $6;
5536 0 : $$ = (Node *) n;
5537 : }
5538 : | ALTER EXTENSION name add_drop TRANSFORM FOR Typename LANGUAGE name
5539 : {
5540 4 : AlterExtensionContentsStmt *n = makeNode(AlterExtensionContentsStmt);
5541 :
5542 4 : n->extname = $3;
5543 4 : n->action = $4;
5544 4 : n->objtype = OBJECT_TRANSFORM;
5545 4 : n->object = (Node *) list_make2($7, makeString($9));
5546 4 : $$ = (Node *) n;
5547 : }
5548 : | ALTER EXTENSION name add_drop TYPE_P Typename
5549 : {
5550 8 : AlterExtensionContentsStmt *n = makeNode(AlterExtensionContentsStmt);
5551 :
5552 8 : n->extname = $3;
5553 8 : n->action = $4;
5554 8 : n->objtype = OBJECT_TYPE;
5555 8 : n->object = (Node *) $6;
5556 8 : $$ = (Node *) n;
5557 : }
5558 : ;
5559 :
5560 : /*****************************************************************************
5561 : *
5562 : * QUERY:
5563 : * CREATE FOREIGN DATA WRAPPER name options
5564 : *
5565 : *****************************************************************************/
5566 :
5567 : CreateFdwStmt: CREATE FOREIGN DATA_P WRAPPER name opt_fdw_options create_generic_options
5568 : {
5569 208 : CreateFdwStmt *n = makeNode(CreateFdwStmt);
5570 :
5571 208 : n->fdwname = $5;
5572 208 : n->func_options = $6;
5573 208 : n->options = $7;
5574 208 : $$ = (Node *) n;
5575 : }
5576 : ;
5577 :
5578 : fdw_option:
5579 58 : HANDLER handler_name { $$ = makeDefElem("handler", (Node *) $2, @1); }
5580 0 : | NO HANDLER { $$ = makeDefElem("handler", NULL, @1); }
5581 50 : | VALIDATOR handler_name { $$ = makeDefElem("validator", (Node *) $2, @1); }
5582 6 : | NO VALIDATOR { $$ = makeDefElem("validator", NULL, @1); }
5583 : ;
5584 :
5585 : fdw_options:
5586 92 : fdw_option { $$ = list_make1($1); }
5587 22 : | fdw_options fdw_option { $$ = lappend($1, $2); }
5588 : ;
5589 :
5590 : opt_fdw_options:
5591 56 : fdw_options { $$ = $1; }
5592 244 : | /*EMPTY*/ { $$ = NIL; }
5593 : ;
5594 :
5595 : /*****************************************************************************
5596 : *
5597 : * QUERY :
5598 : * ALTER FOREIGN DATA WRAPPER name options
5599 : *
5600 : ****************************************************************************/
5601 :
5602 : AlterFdwStmt: ALTER FOREIGN DATA_P WRAPPER name opt_fdw_options alter_generic_options
5603 : {
5604 86 : AlterFdwStmt *n = makeNode(AlterFdwStmt);
5605 :
5606 86 : n->fdwname = $5;
5607 86 : n->func_options = $6;
5608 86 : n->options = $7;
5609 86 : $$ = (Node *) n;
5610 : }
5611 : | ALTER FOREIGN DATA_P WRAPPER name fdw_options
5612 : {
5613 36 : AlterFdwStmt *n = makeNode(AlterFdwStmt);
5614 :
5615 36 : n->fdwname = $5;
5616 36 : n->func_options = $6;
5617 36 : n->options = NIL;
5618 36 : $$ = (Node *) n;
5619 : }
5620 : ;
5621 :
5622 : /* Options definition for CREATE FDW, SERVER and USER MAPPING */
5623 : create_generic_options:
5624 772 : OPTIONS '(' generic_option_list ')' { $$ = $3; }
5625 70826 : | /*EMPTY*/ { $$ = NIL; }
5626 : ;
5627 :
5628 : generic_option_list:
5629 : generic_option_elem
5630 : {
5631 772 : $$ = list_make1($1);
5632 : }
5633 : | generic_option_list ',' generic_option_elem
5634 : {
5635 496 : $$ = lappend($1, $3);
5636 : }
5637 : ;
5638 :
5639 : /* Options definition for ALTER FDW, SERVER and USER MAPPING */
5640 : alter_generic_options:
5641 508 : OPTIONS '(' alter_generic_option_list ')' { $$ = $3; }
5642 : ;
5643 :
5644 : alter_generic_option_list:
5645 : alter_generic_option_elem
5646 : {
5647 508 : $$ = list_make1($1);
5648 : }
5649 : | alter_generic_option_list ',' alter_generic_option_elem
5650 : {
5651 168 : $$ = lappend($1, $3);
5652 : }
5653 : ;
5654 :
5655 : alter_generic_option_elem:
5656 : generic_option_elem
5657 : {
5658 200 : $$ = $1;
5659 : }
5660 : | SET generic_option_elem
5661 : {
5662 128 : $$ = $2;
5663 128 : $$->defaction = DEFELEM_SET;
5664 : }
5665 : | ADD_P generic_option_elem
5666 : {
5667 220 : $$ = $2;
5668 220 : $$->defaction = DEFELEM_ADD;
5669 : }
5670 : | DROP generic_option_name
5671 : {
5672 128 : $$ = makeDefElemExtended(NULL, $2, NULL, DEFELEM_DROP, @2);
5673 : }
5674 : ;
5675 :
5676 : generic_option_elem:
5677 : generic_option_name generic_option_arg
5678 : {
5679 1816 : $$ = makeDefElem($1, $2, @1);
5680 : }
5681 : ;
5682 :
5683 : generic_option_name:
5684 1944 : ColLabel { $$ = $1; }
5685 : ;
5686 :
5687 : /* We could use def_arg here, but the spec only requires string literals */
5688 : generic_option_arg:
5689 1816 : Sconst { $$ = (Node *) makeString($1); }
5690 : ;
5691 :
5692 : /*****************************************************************************
5693 : *
5694 : * QUERY:
5695 : * CREATE SERVER name [TYPE] [VERSION] [OPTIONS]
5696 : *
5697 : *****************************************************************************/
5698 :
5699 : CreateForeignServerStmt: CREATE SERVER name opt_type opt_foreign_server_version
5700 : FOREIGN DATA_P WRAPPER name create_generic_options
5701 : {
5702 280 : CreateForeignServerStmt *n = makeNode(CreateForeignServerStmt);
5703 :
5704 280 : n->servername = $3;
5705 280 : n->servertype = $4;
5706 280 : n->version = $5;
5707 280 : n->fdwname = $9;
5708 280 : n->options = $10;
5709 280 : n->if_not_exists = false;
5710 280 : $$ = (Node *) n;
5711 : }
5712 : | CREATE SERVER IF_P NOT EXISTS name opt_type opt_foreign_server_version
5713 : FOREIGN DATA_P WRAPPER name create_generic_options
5714 : {
5715 24 : CreateForeignServerStmt *n = makeNode(CreateForeignServerStmt);
5716 :
5717 24 : n->servername = $6;
5718 24 : n->servertype = $7;
5719 24 : n->version = $8;
5720 24 : n->fdwname = $12;
5721 24 : n->options = $13;
5722 24 : n->if_not_exists = true;
5723 24 : $$ = (Node *) n;
5724 : }
5725 : ;
5726 :
5727 : opt_type:
5728 18 : TYPE_P Sconst { $$ = $2; }
5729 286 : | /*EMPTY*/ { $$ = NULL; }
5730 : ;
5731 :
5732 :
5733 : foreign_server_version:
5734 66 : VERSION_P Sconst { $$ = $2; }
5735 0 : | VERSION_P NULL_P { $$ = NULL; }
5736 : ;
5737 :
5738 : opt_foreign_server_version:
5739 18 : foreign_server_version { $$ = $1; }
5740 286 : | /*EMPTY*/ { $$ = NULL; }
5741 : ;
5742 :
5743 : /*****************************************************************************
5744 : *
5745 : * QUERY :
5746 : * ALTER SERVER name [VERSION] [OPTIONS]
5747 : *
5748 : ****************************************************************************/
5749 :
5750 : AlterForeignServerStmt: ALTER SERVER name foreign_server_version alter_generic_options
5751 : {
5752 6 : AlterForeignServerStmt *n = makeNode(AlterForeignServerStmt);
5753 :
5754 6 : n->servername = $3;
5755 6 : n->version = $4;
5756 6 : n->options = $5;
5757 6 : n->has_version = true;
5758 6 : $$ = (Node *) n;
5759 : }
5760 : | ALTER SERVER name foreign_server_version
5761 : {
5762 42 : AlterForeignServerStmt *n = makeNode(AlterForeignServerStmt);
5763 :
5764 42 : n->servername = $3;
5765 42 : n->version = $4;
5766 42 : n->has_version = true;
5767 42 : $$ = (Node *) n;
5768 : }
5769 : | ALTER SERVER name alter_generic_options
5770 : {
5771 184 : AlterForeignServerStmt *n = makeNode(AlterForeignServerStmt);
5772 :
5773 184 : n->servername = $3;
5774 184 : n->options = $4;
5775 184 : $$ = (Node *) n;
5776 : }
5777 : ;
5778 :
5779 : /*****************************************************************************
5780 : *
5781 : * QUERY:
5782 : * CREATE FOREIGN TABLE relname (...) SERVER name (...)
5783 : *
5784 : *****************************************************************************/
5785 :
5786 : CreateForeignTableStmt:
5787 : CREATE FOREIGN TABLE qualified_name
5788 : '(' OptTableElementList ')'
5789 : OptInherit SERVER name create_generic_options
5790 : {
5791 420 : CreateForeignTableStmt *n = makeNode(CreateForeignTableStmt);
5792 :
5793 420 : $4->relpersistence = RELPERSISTENCE_PERMANENT;
5794 420 : n->base.relation = $4;
5795 420 : n->base.tableElts = $6;
5796 420 : n->base.inhRelations = $8;
5797 420 : n->base.ofTypename = NULL;
5798 420 : n->base.constraints = NIL;
5799 420 : n->base.options = NIL;
5800 420 : n->base.oncommit = ONCOMMIT_NOOP;
5801 420 : n->base.tablespacename = NULL;
5802 420 : n->base.if_not_exists = false;
5803 : /* FDW-specific data */
5804 420 : n->servername = $10;
5805 420 : n->options = $11;
5806 420 : $$ = (Node *) n;
5807 : }
5808 : | CREATE FOREIGN TABLE IF_P NOT EXISTS qualified_name
5809 : '(' OptTableElementList ')'
5810 : OptInherit SERVER name create_generic_options
5811 : {
5812 0 : CreateForeignTableStmt *n = makeNode(CreateForeignTableStmt);
5813 :
5814 0 : $7->relpersistence = RELPERSISTENCE_PERMANENT;
5815 0 : n->base.relation = $7;
5816 0 : n->base.tableElts = $9;
5817 0 : n->base.inhRelations = $11;
5818 0 : n->base.ofTypename = NULL;
5819 0 : n->base.constraints = NIL;
5820 0 : n->base.options = NIL;
5821 0 : n->base.oncommit = ONCOMMIT_NOOP;
5822 0 : n->base.tablespacename = NULL;
5823 0 : n->base.if_not_exists = true;
5824 : /* FDW-specific data */
5825 0 : n->servername = $13;
5826 0 : n->options = $14;
5827 0 : $$ = (Node *) n;
5828 : }
5829 : | CREATE FOREIGN TABLE qualified_name
5830 : PARTITION OF qualified_name OptTypedTableElementList PartitionBoundSpec
5831 : SERVER name create_generic_options
5832 : {
5833 90 : CreateForeignTableStmt *n = makeNode(CreateForeignTableStmt);
5834 :
5835 90 : $4->relpersistence = RELPERSISTENCE_PERMANENT;
5836 90 : n->base.relation = $4;
5837 90 : n->base.inhRelations = list_make1($7);
5838 90 : n->base.tableElts = $8;
5839 90 : n->base.partbound = $9;
5840 90 : n->base.ofTypename = NULL;
5841 90 : n->base.constraints = NIL;
5842 90 : n->base.options = NIL;
5843 90 : n->base.oncommit = ONCOMMIT_NOOP;
5844 90 : n->base.tablespacename = NULL;
5845 90 : n->base.if_not_exists = false;
5846 : /* FDW-specific data */
5847 90 : n->servername = $11;
5848 90 : n->options = $12;
5849 90 : $$ = (Node *) n;
5850 : }
5851 : | CREATE FOREIGN TABLE IF_P NOT EXISTS qualified_name
5852 : PARTITION OF qualified_name OptTypedTableElementList PartitionBoundSpec
5853 : SERVER name create_generic_options
5854 : {
5855 0 : CreateForeignTableStmt *n = makeNode(CreateForeignTableStmt);
5856 :
5857 0 : $7->relpersistence = RELPERSISTENCE_PERMANENT;
5858 0 : n->base.relation = $7;
5859 0 : n->base.inhRelations = list_make1($10);
5860 0 : n->base.tableElts = $11;
5861 0 : n->base.partbound = $12;
5862 0 : n->base.ofTypename = NULL;
5863 0 : n->base.constraints = NIL;
5864 0 : n->base.options = NIL;
5865 0 : n->base.oncommit = ONCOMMIT_NOOP;
5866 0 : n->base.tablespacename = NULL;
5867 0 : n->base.if_not_exists = true;
5868 : /* FDW-specific data */
5869 0 : n->servername = $14;
5870 0 : n->options = $15;
5871 0 : $$ = (Node *) n;
5872 : }
5873 : ;
5874 :
5875 : /*****************************************************************************
5876 : *
5877 : * QUERY:
5878 : * IMPORT FOREIGN SCHEMA remote_schema
5879 : * [ { LIMIT TO | EXCEPT } ( table_list ) ]
5880 : * FROM SERVER server_name INTO local_schema [ OPTIONS (...) ]
5881 : *
5882 : ****************************************************************************/
5883 :
5884 : ImportForeignSchemaStmt:
5885 : IMPORT_P FOREIGN SCHEMA name import_qualification
5886 : FROM SERVER name INTO name create_generic_options
5887 : {
5888 48 : ImportForeignSchemaStmt *n = makeNode(ImportForeignSchemaStmt);
5889 :
5890 48 : n->server_name = $8;
5891 48 : n->remote_schema = $4;
5892 48 : n->local_schema = $10;
5893 48 : n->list_type = $5->type;
5894 48 : n->table_list = $5->table_names;
5895 48 : n->options = $11;
5896 48 : $$ = (Node *) n;
5897 : }
5898 : ;
5899 :
5900 : import_qualification_type:
5901 14 : LIMIT TO { $$ = FDW_IMPORT_SCHEMA_LIMIT_TO; }
5902 14 : | EXCEPT { $$ = FDW_IMPORT_SCHEMA_EXCEPT; }
5903 : ;
5904 :
5905 : import_qualification:
5906 : import_qualification_type '(' relation_expr_list ')'
5907 : {
5908 28 : ImportQual *n = palloc_object(ImportQual);
5909 :
5910 28 : n->type = $1;
5911 28 : n->table_names = $3;
5912 28 : $$ = n;
5913 : }
5914 : | /*EMPTY*/
5915 : {
5916 20 : ImportQual *n = palloc_object(ImportQual);
5917 20 : n->type = FDW_IMPORT_SCHEMA_ALL;
5918 20 : n->table_names = NIL;
5919 20 : $$ = n;
5920 : }
5921 : ;
5922 :
5923 : /*****************************************************************************
5924 : *
5925 : * QUERY:
5926 : * CREATE USER MAPPING FOR auth_ident SERVER name [OPTIONS]
5927 : *
5928 : *****************************************************************************/
5929 :
5930 : CreateUserMappingStmt: CREATE USER MAPPING FOR auth_ident SERVER name create_generic_options
5931 : {
5932 254 : CreateUserMappingStmt *n = makeNode(CreateUserMappingStmt);
5933 :
5934 254 : n->user = $5;
5935 254 : n->servername = $7;
5936 254 : n->options = $8;
5937 254 : n->if_not_exists = false;
5938 254 : $$ = (Node *) n;
5939 : }
5940 : | CREATE USER MAPPING IF_P NOT EXISTS FOR auth_ident SERVER name create_generic_options
5941 : {
5942 6 : CreateUserMappingStmt *n = makeNode(CreateUserMappingStmt);
5943 :
5944 6 : n->user = $8;
5945 6 : n->servername = $10;
5946 6 : n->options = $11;
5947 6 : n->if_not_exists = true;
5948 6 : $$ = (Node *) n;
5949 : }
5950 : ;
5951 :
5952 : /* User mapping authorization identifier */
5953 458 : auth_ident: RoleSpec { $$ = $1; }
5954 46 : | USER { $$ = makeRoleSpec(ROLESPEC_CURRENT_USER, @1); }
5955 : ;
5956 :
5957 : /*****************************************************************************
5958 : *
5959 : * QUERY :
5960 : * DROP USER MAPPING FOR auth_ident SERVER name
5961 : *
5962 : * XXX you'd think this should have a CASCADE/RESTRICT option, even if it's
5963 : * only pro forma; but the SQL standard doesn't show one.
5964 : ****************************************************************************/
5965 :
5966 : DropUserMappingStmt: DROP USER MAPPING FOR auth_ident SERVER name
5967 : {
5968 88 : DropUserMappingStmt *n = makeNode(DropUserMappingStmt);
5969 :
5970 88 : n->user = $5;
5971 88 : n->servername = $7;
5972 88 : n->missing_ok = false;
5973 88 : $$ = (Node *) n;
5974 : }
5975 : | DROP USER MAPPING IF_P EXISTS FOR auth_ident SERVER name
5976 : {
5977 38 : DropUserMappingStmt *n = makeNode(DropUserMappingStmt);
5978 :
5979 38 : n->user = $7;
5980 38 : n->servername = $9;
5981 38 : n->missing_ok = true;
5982 38 : $$ = (Node *) n;
5983 : }
5984 : ;
5985 :
5986 : /*****************************************************************************
5987 : *
5988 : * QUERY :
5989 : * ALTER USER MAPPING FOR auth_ident SERVER name OPTIONS
5990 : *
5991 : ****************************************************************************/
5992 :
5993 : AlterUserMappingStmt: ALTER USER MAPPING FOR auth_ident SERVER name alter_generic_options
5994 : {
5995 118 : AlterUserMappingStmt *n = makeNode(AlterUserMappingStmt);
5996 :
5997 118 : n->user = $5;
5998 118 : n->servername = $7;
5999 118 : n->options = $8;
6000 118 : $$ = (Node *) n;
6001 : }
6002 : ;
6003 :
6004 : /*****************************************************************************
6005 : *
6006 : * QUERIES:
6007 : * CREATE POLICY name ON table
6008 : * [AS { PERMISSIVE | RESTRICTIVE } ]
6009 : * [FOR { SELECT | INSERT | UPDATE | DELETE } ]
6010 : * [TO role, ...]
6011 : * [USING (qual)] [WITH CHECK (with check qual)]
6012 : * ALTER POLICY name ON table [TO role, ...]
6013 : * [USING (qual)] [WITH CHECK (with check qual)]
6014 : *
6015 : *****************************************************************************/
6016 :
6017 : CreatePolicyStmt:
6018 : CREATE POLICY name ON qualified_name RowSecurityDefaultPermissive
6019 : RowSecurityDefaultForCmd RowSecurityDefaultToRole
6020 : RowSecurityOptionalExpr RowSecurityOptionalWithCheck
6021 : {
6022 772 : CreatePolicyStmt *n = makeNode(CreatePolicyStmt);
6023 :
6024 772 : n->policy_name = $3;
6025 772 : n->table = $5;
6026 772 : n->permissive = $6;
6027 772 : n->cmd_name = $7;
6028 772 : n->roles = $8;
6029 772 : n->qual = $9;
6030 772 : n->with_check = $10;
6031 772 : $$ = (Node *) n;
6032 : }
6033 : ;
6034 :
6035 : AlterPolicyStmt:
6036 : ALTER POLICY name ON qualified_name RowSecurityOptionalToRole
6037 : RowSecurityOptionalExpr RowSecurityOptionalWithCheck
6038 : {
6039 84 : AlterPolicyStmt *n = makeNode(AlterPolicyStmt);
6040 :
6041 84 : n->policy_name = $3;
6042 84 : n->table = $5;
6043 84 : n->roles = $6;
6044 84 : n->qual = $7;
6045 84 : n->with_check = $8;
6046 84 : $$ = (Node *) n;
6047 : }
6048 : ;
6049 :
6050 : RowSecurityOptionalExpr:
6051 792 : USING '(' a_expr ')' { $$ = $3; }
6052 64 : | /* EMPTY */ { $$ = NULL; }
6053 : ;
6054 :
6055 : RowSecurityOptionalWithCheck:
6056 140 : WITH CHECK '(' a_expr ')' { $$ = $4; }
6057 716 : | /* EMPTY */ { $$ = NULL; }
6058 : ;
6059 :
6060 : RowSecurityDefaultToRole:
6061 130 : TO role_list { $$ = $2; }
6062 642 : | /* EMPTY */ { $$ = list_make1(makeRoleSpec(ROLESPEC_PUBLIC, -1)); }
6063 : ;
6064 :
6065 : RowSecurityOptionalToRole:
6066 12 : TO role_list { $$ = $2; }
6067 72 : | /* EMPTY */ { $$ = NULL; }
6068 : ;
6069 :
6070 : RowSecurityDefaultPermissive:
6071 : AS IDENT
6072 : {
6073 98 : if (strcmp($2, "permissive") == 0)
6074 24 : $$ = true;
6075 74 : else if (strcmp($2, "restrictive") == 0)
6076 68 : $$ = false;
6077 : else
6078 6 : ereport(ERROR,
6079 : (errcode(ERRCODE_SYNTAX_ERROR),
6080 : errmsg("unrecognized row security option \"%s\"", $2),
6081 : errhint("Only PERMISSIVE or RESTRICTIVE policies are supported currently."),
6082 : parser_errposition(@2)));
6083 :
6084 : }
6085 680 : | /* EMPTY */ { $$ = true; }
6086 : ;
6087 :
6088 : RowSecurityDefaultForCmd:
6089 356 : FOR row_security_cmd { $$ = $2; }
6090 416 : | /* EMPTY */ { $$ = "all"; }
6091 : ;
6092 :
6093 : row_security_cmd:
6094 44 : ALL { $$ = "all"; }
6095 124 : | SELECT { $$ = "select"; }
6096 50 : | INSERT { $$ = "insert"; }
6097 90 : | UPDATE { $$ = "update"; }
6098 48 : | DELETE_P { $$ = "delete"; }
6099 : ;
6100 :
6101 : /*****************************************************************************
6102 : *
6103 : * QUERY:
6104 : * CREATE ACCESS METHOD name HANDLER handler_name
6105 : *
6106 : *****************************************************************************/
6107 :
6108 : CreateAmStmt: CREATE ACCESS METHOD name TYPE_P am_type HANDLER handler_name
6109 : {
6110 74 : CreateAmStmt *n = makeNode(CreateAmStmt);
6111 :
6112 74 : n->amname = $4;
6113 74 : n->handler_name = $8;
6114 74 : n->amtype = $6;
6115 74 : $$ = (Node *) n;
6116 : }
6117 : ;
6118 :
6119 : am_type:
6120 34 : INDEX { $$ = AMTYPE_INDEX; }
6121 40 : | TABLE { $$ = AMTYPE_TABLE; }
6122 : ;
6123 :
6124 : /*****************************************************************************
6125 : *
6126 : * QUERIES :
6127 : * CREATE TRIGGER ...
6128 : *
6129 : *****************************************************************************/
6130 :
6131 : CreateTrigStmt:
6132 : CREATE opt_or_replace TRIGGER name TriggerActionTime TriggerEvents ON
6133 : qualified_name TriggerReferencing TriggerForSpec TriggerWhen
6134 : EXECUTE FUNCTION_or_PROCEDURE func_name '(' TriggerFuncArgs ')'
6135 : {
6136 3228 : CreateTrigStmt *n = makeNode(CreateTrigStmt);
6137 :
6138 3228 : n->replace = $2;
6139 3228 : n->isconstraint = false;
6140 3228 : n->trigname = $4;
6141 3228 : n->relation = $8;
6142 3228 : n->funcname = $14;
6143 3228 : n->args = $16;
6144 3228 : n->row = $10;
6145 3228 : n->timing = $5;
6146 3228 : n->events = intVal(linitial($6));
6147 3228 : n->columns = (List *) lsecond($6);
6148 3228 : n->whenClause = $11;
6149 3228 : n->transitionRels = $9;
6150 3228 : n->deferrable = false;
6151 3228 : n->initdeferred = false;
6152 3228 : n->constrrel = NULL;
6153 3228 : $$ = (Node *) n;
6154 : }
6155 : | CREATE opt_or_replace CONSTRAINT TRIGGER name AFTER TriggerEvents ON
6156 : qualified_name OptConstrFromTable ConstraintAttributeSpec
6157 : FOR EACH ROW TriggerWhen
6158 : EXECUTE FUNCTION_or_PROCEDURE func_name '(' TriggerFuncArgs ')'
6159 : {
6160 80 : CreateTrigStmt *n = makeNode(CreateTrigStmt);
6161 : bool dummy;
6162 :
6163 80 : if (($11 & CAS_NOT_VALID) != 0)
6164 6 : ereport(ERROR,
6165 : errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
6166 : errmsg("constraint triggers cannot be marked %s",
6167 : "NOT VALID"),
6168 : parser_errposition(@11));
6169 74 : if (($11 & CAS_NO_INHERIT) != 0)
6170 6 : ereport(ERROR,
6171 : errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
6172 : errmsg("constraint triggers cannot be marked %s",
6173 : "NO INHERIT"),
6174 : parser_errposition(@11));
6175 68 : if (($11 & CAS_NOT_ENFORCED) != 0)
6176 6 : ereport(ERROR,
6177 : errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
6178 : errmsg("constraint triggers cannot be marked %s",
6179 : "NOT ENFORCED"),
6180 : parser_errposition(@11));
6181 :
6182 62 : n->replace = $2;
6183 62 : if (n->replace) /* not supported, see CreateTrigger */
6184 0 : ereport(ERROR,
6185 : (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
6186 : errmsg("CREATE OR REPLACE CONSTRAINT TRIGGER is not supported"),
6187 : parser_errposition(@1)));
6188 62 : n->isconstraint = true;
6189 62 : n->trigname = $5;
6190 62 : n->relation = $9;
6191 62 : n->funcname = $18;
6192 62 : n->args = $20;
6193 62 : n->row = true;
6194 62 : n->timing = TRIGGER_TYPE_AFTER;
6195 62 : n->events = intVal(linitial($7));
6196 62 : n->columns = (List *) lsecond($7);
6197 62 : n->whenClause = $15;
6198 62 : n->transitionRels = NIL;
6199 62 : processCASbits($11, @11, "TRIGGER",
6200 : &n->deferrable, &n->initdeferred, &dummy,
6201 : NULL, NULL, yyscanner);
6202 62 : n->constrrel = $10;
6203 62 : $$ = (Node *) n;
6204 : }
6205 : ;
6206 :
6207 : TriggerActionTime:
6208 1472 : BEFORE { $$ = TRIGGER_TYPE_BEFORE; }
6209 1624 : | AFTER { $$ = TRIGGER_TYPE_AFTER; }
6210 144 : | INSTEAD OF { $$ = TRIGGER_TYPE_INSTEAD; }
6211 : ;
6212 :
6213 : TriggerEvents:
6214 : TriggerOneEvent
6215 3320 : { $$ = $1; }
6216 : | TriggerEvents OR TriggerOneEvent
6217 : {
6218 1162 : int events1 = intVal(linitial($1));
6219 1162 : int events2 = intVal(linitial($3));
6220 1162 : List *columns1 = (List *) lsecond($1);
6221 1162 : List *columns2 = (List *) lsecond($3);
6222 :
6223 1162 : if (events1 & events2)
6224 6 : parser_yyerror("duplicate trigger events specified");
6225 : /*
6226 : * concat'ing the columns lists loses information about
6227 : * which columns went with which event, but so long as
6228 : * only UPDATE carries columns and we disallow multiple
6229 : * UPDATE items, it doesn't matter. Command execution
6230 : * should just ignore the columns for non-UPDATE events.
6231 : */
6232 1156 : $$ = list_make2(makeInteger(events1 | events2),
6233 : list_concat(columns1, columns2));
6234 : }
6235 : ;
6236 :
6237 : TriggerOneEvent:
6238 : INSERT
6239 1734 : { $$ = list_make2(makeInteger(TRIGGER_TYPE_INSERT), NIL); }
6240 : | DELETE_P
6241 886 : { $$ = list_make2(makeInteger(TRIGGER_TYPE_DELETE), NIL); }
6242 : | UPDATE
6243 1724 : { $$ = list_make2(makeInteger(TRIGGER_TYPE_UPDATE), NIL); }
6244 : | UPDATE OF columnList
6245 100 : { $$ = list_make2(makeInteger(TRIGGER_TYPE_UPDATE), $3); }
6246 : | TRUNCATE
6247 38 : { $$ = list_make2(makeInteger(TRIGGER_TYPE_TRUNCATE), NIL); }
6248 : ;
6249 :
6250 : TriggerReferencing:
6251 464 : REFERENCING TriggerTransitions { $$ = $2; }
6252 2764 : | /*EMPTY*/ { $$ = NIL; }
6253 : ;
6254 :
6255 : TriggerTransitions:
6256 464 : TriggerTransition { $$ = list_make1($1); }
6257 142 : | TriggerTransitions TriggerTransition { $$ = lappend($1, $2); }
6258 : ;
6259 :
6260 : TriggerTransition:
6261 : TransitionOldOrNew TransitionRowOrTable opt_as TransitionRelName
6262 : {
6263 606 : TriggerTransition *n = makeNode(TriggerTransition);
6264 :
6265 606 : n->name = $4;
6266 606 : n->isNew = $1;
6267 606 : n->isTable = $2;
6268 606 : $$ = (Node *) n;
6269 : }
6270 : ;
6271 :
6272 : TransitionOldOrNew:
6273 330 : NEW { $$ = true; }
6274 276 : | OLD { $$ = false; }
6275 : ;
6276 :
6277 : TransitionRowOrTable:
6278 606 : TABLE { $$ = true; }
6279 : /*
6280 : * According to the standard, lack of a keyword here implies ROW.
6281 : * Support for that would require prohibiting ROW entirely here,
6282 : * reserving the keyword ROW, and/or requiring AS (instead of
6283 : * allowing it to be optional, as the standard specifies) as the
6284 : * next token. Requiring ROW seems cleanest and easiest to
6285 : * explain.
6286 : */
6287 0 : | ROW { $$ = false; }
6288 : ;
6289 :
6290 : TransitionRelName:
6291 606 : ColId { $$ = $1; }
6292 : ;
6293 :
6294 : TriggerForSpec:
6295 : FOR TriggerForOptEach TriggerForType
6296 : {
6297 2988 : $$ = $3;
6298 : }
6299 : | /* EMPTY */
6300 : {
6301 : /*
6302 : * If ROW/STATEMENT not specified, default to
6303 : * STATEMENT, per SQL
6304 : */
6305 240 : $$ = false;
6306 : }
6307 : ;
6308 :
6309 : TriggerForOptEach:
6310 : EACH
6311 : | /*EMPTY*/
6312 : ;
6313 :
6314 : TriggerForType:
6315 2156 : ROW { $$ = true; }
6316 832 : | STATEMENT { $$ = false; }
6317 : ;
6318 :
6319 : TriggerWhen:
6320 190 : WHEN '(' a_expr ')' { $$ = $3; }
6321 3118 : | /*EMPTY*/ { $$ = NULL; }
6322 : ;
6323 :
6324 : FUNCTION_or_PROCEDURE:
6325 : FUNCTION
6326 : | PROCEDURE
6327 : ;
6328 :
6329 : TriggerFuncArgs:
6330 600 : TriggerFuncArg { $$ = list_make1($1); }
6331 162 : | TriggerFuncArgs ',' TriggerFuncArg { $$ = lappend($1, $3); }
6332 2708 : | /*EMPTY*/ { $$ = NIL; }
6333 : ;
6334 :
6335 : TriggerFuncArg:
6336 : Iconst
6337 : {
6338 94 : $$ = (Node *) makeString(psprintf("%d", $1));
6339 : }
6340 0 : | FCONST { $$ = (Node *) makeString($1); }
6341 646 : | Sconst { $$ = (Node *) makeString($1); }
6342 22 : | ColLabel { $$ = (Node *) makeString($1); }
6343 : ;
6344 :
6345 : OptConstrFromTable:
6346 12 : FROM qualified_name { $$ = $2; }
6347 68 : | /*EMPTY*/ { $$ = NULL; }
6348 : ;
6349 :
6350 : ConstraintAttributeSpec:
6351 : /*EMPTY*/
6352 18244 : { $$ = 0; }
6353 : | ConstraintAttributeSpec ConstraintAttributeElem
6354 : {
6355 : /*
6356 : * We must complain about conflicting options.
6357 : * We could, but choose not to, complain about redundant
6358 : * options (ie, where $2's bit is already set in $1).
6359 : */
6360 1736 : int newspec = $1 | $2;
6361 :
6362 : /* special message for this case */
6363 1736 : if ((newspec & (CAS_NOT_DEFERRABLE | CAS_INITIALLY_DEFERRED)) == (CAS_NOT_DEFERRABLE | CAS_INITIALLY_DEFERRED))
6364 6 : ereport(ERROR,
6365 : (errcode(ERRCODE_SYNTAX_ERROR),
6366 : errmsg("constraint declared INITIALLY DEFERRED must be DEFERRABLE"),
6367 : parser_errposition(@2)));
6368 : /* generic message for other conflicts */
6369 1730 : if ((newspec & (CAS_NOT_DEFERRABLE | CAS_DEFERRABLE)) == (CAS_NOT_DEFERRABLE | CAS_DEFERRABLE) ||
6370 1730 : (newspec & (CAS_INITIALLY_IMMEDIATE | CAS_INITIALLY_DEFERRED)) == (CAS_INITIALLY_IMMEDIATE | CAS_INITIALLY_DEFERRED) ||
6371 1730 : (newspec & (CAS_NOT_ENFORCED | CAS_ENFORCED)) == (CAS_NOT_ENFORCED | CAS_ENFORCED))
6372 6 : ereport(ERROR,
6373 : (errcode(ERRCODE_SYNTAX_ERROR),
6374 : errmsg("conflicting constraint properties"),
6375 : parser_errposition(@2)));
6376 1724 : $$ = newspec;
6377 : }
6378 : ;
6379 :
6380 : ConstraintAttributeElem:
6381 42 : NOT DEFERRABLE { $$ = CAS_NOT_DEFERRABLE; }
6382 200 : | DEFERRABLE { $$ = CAS_DEFERRABLE; }
6383 30 : | INITIALLY IMMEDIATE { $$ = CAS_INITIALLY_IMMEDIATE; }
6384 152 : | INITIALLY DEFERRED { $$ = CAS_INITIALLY_DEFERRED; }
6385 762 : | NOT VALID { $$ = CAS_NOT_VALID; }
6386 250 : | NO INHERIT { $$ = CAS_NO_INHERIT; }
6387 186 : | NOT ENFORCED { $$ = CAS_NOT_ENFORCED; }
6388 114 : | ENFORCED { $$ = CAS_ENFORCED; }
6389 : ;
6390 :
6391 :
6392 : /*****************************************************************************
6393 : *
6394 : * QUERIES :
6395 : * CREATE EVENT TRIGGER ...
6396 : * ALTER EVENT TRIGGER ...
6397 : *
6398 : *****************************************************************************/
6399 :
6400 : CreateEventTrigStmt:
6401 : CREATE EVENT TRIGGER name ON ColLabel
6402 : EXECUTE FUNCTION_or_PROCEDURE func_name '(' ')'
6403 : {
6404 102 : CreateEventTrigStmt *n = makeNode(CreateEventTrigStmt);
6405 :
6406 102 : n->trigname = $4;
6407 102 : n->eventname = $6;
6408 102 : n->whenclause = NULL;
6409 102 : n->funcname = $9;
6410 102 : $$ = (Node *) n;
6411 : }
6412 : | CREATE EVENT TRIGGER name ON ColLabel
6413 : WHEN event_trigger_when_list
6414 : EXECUTE FUNCTION_or_PROCEDURE func_name '(' ')'
6415 : {
6416 98 : CreateEventTrigStmt *n = makeNode(CreateEventTrigStmt);
6417 :
6418 98 : n->trigname = $4;
6419 98 : n->eventname = $6;
6420 98 : n->whenclause = $8;
6421 98 : n->funcname = $11;
6422 98 : $$ = (Node *) n;
6423 : }
6424 : ;
6425 :
6426 : event_trigger_when_list:
6427 : event_trigger_when_item
6428 98 : { $$ = list_make1($1); }
6429 : | event_trigger_when_list AND event_trigger_when_item
6430 6 : { $$ = lappend($1, $3); }
6431 : ;
6432 :
6433 : event_trigger_when_item:
6434 : ColId IN_P '(' event_trigger_value_list ')'
6435 104 : { $$ = makeDefElem($1, (Node *) $4, @1); }
6436 : ;
6437 :
6438 : event_trigger_value_list:
6439 : SCONST
6440 104 : { $$ = list_make1(makeString($1)); }
6441 : | event_trigger_value_list ',' SCONST
6442 66 : { $$ = lappend($1, makeString($3)); }
6443 : ;
6444 :
6445 : AlterEventTrigStmt:
6446 : ALTER EVENT TRIGGER name enable_trigger
6447 : {
6448 48 : AlterEventTrigStmt *n = makeNode(AlterEventTrigStmt);
6449 :
6450 48 : n->trigname = $4;
6451 48 : n->tgenabled = $5;
6452 48 : $$ = (Node *) n;
6453 : }
6454 : ;
6455 :
6456 : enable_trigger:
6457 6 : ENABLE_P { $$ = TRIGGER_FIRES_ON_ORIGIN; }
6458 6 : | ENABLE_P REPLICA { $$ = TRIGGER_FIRES_ON_REPLICA; }
6459 16 : | ENABLE_P ALWAYS { $$ = TRIGGER_FIRES_ALWAYS; }
6460 20 : | DISABLE_P { $$ = TRIGGER_DISABLED; }
6461 : ;
6462 :
6463 : /*****************************************************************************
6464 : *
6465 : * QUERY :
6466 : * CREATE ASSERTION ...
6467 : *
6468 : *****************************************************************************/
6469 :
6470 : CreateAssertionStmt:
6471 : CREATE ASSERTION any_name CHECK '(' a_expr ')' ConstraintAttributeSpec
6472 : {
6473 0 : ereport(ERROR,
6474 : (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
6475 : errmsg("CREATE ASSERTION is not yet implemented"),
6476 : parser_errposition(@1)));
6477 :
6478 : $$ = NULL;
6479 : }
6480 : ;
6481 :
6482 :
6483 : /*****************************************************************************
6484 : *
6485 : * QUERY :
6486 : * define (aggregate,operator,type)
6487 : *
6488 : *****************************************************************************/
6489 :
6490 : DefineStmt:
6491 : CREATE opt_or_replace AGGREGATE func_name aggr_args definition
6492 : {
6493 544 : DefineStmt *n = makeNode(DefineStmt);
6494 :
6495 544 : n->kind = OBJECT_AGGREGATE;
6496 544 : n->oldstyle = false;
6497 544 : n->replace = $2;
6498 544 : n->defnames = $4;
6499 544 : n->args = $5;
6500 544 : n->definition = $6;
6501 544 : $$ = (Node *) n;
6502 : }
6503 : | CREATE opt_or_replace AGGREGATE func_name old_aggr_definition
6504 : {
6505 : /* old-style (pre-8.2) syntax for CREATE AGGREGATE */
6506 362 : DefineStmt *n = makeNode(DefineStmt);
6507 :
6508 362 : n->kind = OBJECT_AGGREGATE;
6509 362 : n->oldstyle = true;
6510 362 : n->replace = $2;
6511 362 : n->defnames = $4;
6512 362 : n->args = NIL;
6513 362 : n->definition = $5;
6514 362 : $$ = (Node *) n;
6515 : }
6516 : | CREATE OPERATOR any_operator definition
6517 : {
6518 1642 : DefineStmt *n = makeNode(DefineStmt);
6519 :
6520 1642 : n->kind = OBJECT_OPERATOR;
6521 1642 : n->oldstyle = false;
6522 1642 : n->defnames = $3;
6523 1642 : n->args = NIL;
6524 1642 : n->definition = $4;
6525 1642 : $$ = (Node *) n;
6526 : }
6527 : | CREATE TYPE_P any_name definition
6528 : {
6529 240 : DefineStmt *n = makeNode(DefineStmt);
6530 :
6531 240 : n->kind = OBJECT_TYPE;
6532 240 : n->oldstyle = false;
6533 240 : n->defnames = $3;
6534 240 : n->args = NIL;
6535 240 : n->definition = $4;
6536 240 : $$ = (Node *) n;
6537 : }
6538 : | CREATE TYPE_P any_name
6539 : {
6540 : /* Shell type (identified by lack of definition) */
6541 156 : DefineStmt *n = makeNode(DefineStmt);
6542 :
6543 156 : n->kind = OBJECT_TYPE;
6544 156 : n->oldstyle = false;
6545 156 : n->defnames = $3;
6546 156 : n->args = NIL;
6547 156 : n->definition = NIL;
6548 156 : $$ = (Node *) n;
6549 : }
6550 : | CREATE TYPE_P any_name AS '(' OptTableFuncElementList ')'
6551 : {
6552 4502 : CompositeTypeStmt *n = makeNode(CompositeTypeStmt);
6553 :
6554 : /* can't use qualified_name, sigh */
6555 4502 : n->typevar = makeRangeVarFromAnyName($3, @3, yyscanner);
6556 4502 : n->coldeflist = $6;
6557 4502 : $$ = (Node *) n;
6558 : }
6559 : | CREATE TYPE_P any_name AS ENUM_P '(' opt_enum_val_list ')'
6560 : {
6561 208 : CreateEnumStmt *n = makeNode(CreateEnumStmt);
6562 :
6563 208 : n->typeName = $3;
6564 208 : n->vals = $7;
6565 208 : $$ = (Node *) n;
6566 : }
6567 : | CREATE TYPE_P any_name AS RANGE definition
6568 : {
6569 184 : CreateRangeStmt *n = makeNode(CreateRangeStmt);
6570 :
6571 184 : n->typeName = $3;
6572 184 : n->params = $6;
6573 184 : $$ = (Node *) n;
6574 : }
6575 : | CREATE TEXT_P SEARCH PARSER any_name definition
6576 : {
6577 40 : DefineStmt *n = makeNode(DefineStmt);
6578 :
6579 40 : n->kind = OBJECT_TSPARSER;
6580 40 : n->args = NIL;
6581 40 : n->defnames = $5;
6582 40 : n->definition = $6;
6583 40 : $$ = (Node *) n;
6584 : }
6585 : | CREATE TEXT_P SEARCH DICTIONARY any_name definition
6586 : {
6587 2988 : DefineStmt *n = makeNode(DefineStmt);
6588 :
6589 2988 : n->kind = OBJECT_TSDICTIONARY;
6590 2988 : n->args = NIL;
6591 2988 : n->defnames = $5;
6592 2988 : n->definition = $6;
6593 2988 : $$ = (Node *) n;
6594 : }
6595 : | CREATE TEXT_P SEARCH TEMPLATE any_name definition
6596 : {
6597 142 : DefineStmt *n = makeNode(DefineStmt);
6598 :
6599 142 : n->kind = OBJECT_TSTEMPLATE;
6600 142 : n->args = NIL;
6601 142 : n->defnames = $5;
6602 142 : n->definition = $6;
6603 142 : $$ = (Node *) n;
6604 : }
6605 : | CREATE TEXT_P SEARCH CONFIGURATION any_name definition
6606 : {
6607 2930 : DefineStmt *n = makeNode(DefineStmt);
6608 :
6609 2930 : n->kind = OBJECT_TSCONFIGURATION;
6610 2930 : n->args = NIL;
6611 2930 : n->defnames = $5;
6612 2930 : n->definition = $6;
6613 2930 : $$ = (Node *) n;
6614 : }
6615 : | CREATE COLLATION any_name definition
6616 : {
6617 292 : DefineStmt *n = makeNode(DefineStmt);
6618 :
6619 292 : n->kind = OBJECT_COLLATION;
6620 292 : n->args = NIL;
6621 292 : n->defnames = $3;
6622 292 : n->definition = $4;
6623 292 : $$ = (Node *) n;
6624 : }
6625 : | CREATE COLLATION IF_P NOT EXISTS any_name definition
6626 : {
6627 18 : DefineStmt *n = makeNode(DefineStmt);
6628 :
6629 18 : n->kind = OBJECT_COLLATION;
6630 18 : n->args = NIL;
6631 18 : n->defnames = $6;
6632 18 : n->definition = $7;
6633 18 : n->if_not_exists = true;
6634 18 : $$ = (Node *) n;
6635 : }
6636 : | CREATE COLLATION any_name FROM any_name
6637 : {
6638 54 : DefineStmt *n = makeNode(DefineStmt);
6639 :
6640 54 : n->kind = OBJECT_COLLATION;
6641 54 : n->args = NIL;
6642 54 : n->defnames = $3;
6643 54 : n->definition = list_make1(makeDefElem("from", (Node *) $5, @5));
6644 54 : $$ = (Node *) n;
6645 : }
6646 : | CREATE COLLATION IF_P NOT EXISTS any_name FROM any_name
6647 : {
6648 0 : DefineStmt *n = makeNode(DefineStmt);
6649 :
6650 0 : n->kind = OBJECT_COLLATION;
6651 0 : n->args = NIL;
6652 0 : n->defnames = $6;
6653 0 : n->definition = list_make1(makeDefElem("from", (Node *) $8, @8));
6654 0 : n->if_not_exists = true;
6655 0 : $$ = (Node *) n;
6656 : }
6657 : ;
6658 :
6659 10092 : definition: '(' def_list ')' { $$ = $2; }
6660 : ;
6661 :
6662 10092 : def_list: def_elem { $$ = list_make1($1); }
6663 14908 : | def_list ',' def_elem { $$ = lappend($1, $3); }
6664 : ;
6665 :
6666 : def_elem: ColLabel '=' def_arg
6667 : {
6668 24662 : $$ = makeDefElem($1, (Node *) $3, @1);
6669 : }
6670 : | ColLabel
6671 : {
6672 338 : $$ = makeDefElem($1, NULL, @1);
6673 : }
6674 : ;
6675 :
6676 : /* Note: any simple identifier will be returned as a type name! */
6677 19884 : def_arg: func_type { $$ = (Node *) $1; }
6678 4286 : | reserved_keyword { $$ = (Node *) makeString(pstrdup($1)); }
6679 1176 : | qual_all_Op { $$ = (Node *) $1; }
6680 1350 : | NumericOnly { $$ = (Node *) $1; }
6681 1908 : | Sconst { $$ = (Node *) makeString($1); }
6682 182 : | NONE { $$ = (Node *) makeString(pstrdup($1)); }
6683 : ;
6684 :
6685 362 : old_aggr_definition: '(' old_aggr_list ')' { $$ = $2; }
6686 : ;
6687 :
6688 362 : old_aggr_list: old_aggr_elem { $$ = list_make1($1); }
6689 1292 : | old_aggr_list ',' old_aggr_elem { $$ = lappend($1, $3); }
6690 : ;
6691 :
6692 : /*
6693 : * Must use IDENT here to avoid reduce/reduce conflicts; fortunately none of
6694 : * the item names needed in old aggregate definitions are likely to become
6695 : * SQL keywords.
6696 : */
6697 : old_aggr_elem: IDENT '=' def_arg
6698 : {
6699 1654 : $$ = makeDefElem($1, (Node *) $3, @1);
6700 : }
6701 : ;
6702 :
6703 : opt_enum_val_list:
6704 200 : enum_val_list { $$ = $1; }
6705 8 : | /*EMPTY*/ { $$ = NIL; }
6706 : ;
6707 :
6708 : enum_val_list: Sconst
6709 200 : { $$ = list_make1(makeString($1)); }
6710 : | enum_val_list ',' Sconst
6711 10420 : { $$ = lappend($1, makeString($3)); }
6712 : ;
6713 :
6714 : /*****************************************************************************
6715 : *
6716 : * ALTER TYPE enumtype ADD ...
6717 : *
6718 : *****************************************************************************/
6719 :
6720 : AlterEnumStmt:
6721 : ALTER TYPE_P any_name ADD_P VALUE_P opt_if_not_exists Sconst
6722 : {
6723 154 : AlterEnumStmt *n = makeNode(AlterEnumStmt);
6724 :
6725 154 : n->typeName = $3;
6726 154 : n->oldVal = NULL;
6727 154 : n->newVal = $7;
6728 154 : n->newValNeighbor = NULL;
6729 154 : n->newValIsAfter = true;
6730 154 : n->skipIfNewValExists = $6;
6731 154 : $$ = (Node *) n;
6732 : }
6733 : | ALTER TYPE_P any_name ADD_P VALUE_P opt_if_not_exists Sconst BEFORE Sconst
6734 : {
6735 196 : AlterEnumStmt *n = makeNode(AlterEnumStmt);
6736 :
6737 196 : n->typeName = $3;
6738 196 : n->oldVal = NULL;
6739 196 : n->newVal = $7;
6740 196 : n->newValNeighbor = $9;
6741 196 : n->newValIsAfter = false;
6742 196 : n->skipIfNewValExists = $6;
6743 196 : $$ = (Node *) n;
6744 : }
6745 : | ALTER TYPE_P any_name ADD_P VALUE_P opt_if_not_exists Sconst AFTER Sconst
6746 : {
6747 22 : AlterEnumStmt *n = makeNode(AlterEnumStmt);
6748 :
6749 22 : n->typeName = $3;
6750 22 : n->oldVal = NULL;
6751 22 : n->newVal = $7;
6752 22 : n->newValNeighbor = $9;
6753 22 : n->newValIsAfter = true;
6754 22 : n->skipIfNewValExists = $6;
6755 22 : $$ = (Node *) n;
6756 : }
6757 : | ALTER TYPE_P any_name RENAME VALUE_P Sconst TO Sconst
6758 : {
6759 24 : AlterEnumStmt *n = makeNode(AlterEnumStmt);
6760 :
6761 24 : n->typeName = $3;
6762 24 : n->oldVal = $6;
6763 24 : n->newVal = $8;
6764 24 : n->newValNeighbor = NULL;
6765 24 : n->newValIsAfter = false;
6766 24 : n->skipIfNewValExists = false;
6767 24 : $$ = (Node *) n;
6768 : }
6769 : | ALTER TYPE_P any_name DROP VALUE_P Sconst
6770 : {
6771 : /*
6772 : * The following problems must be solved before this can be
6773 : * implemented:
6774 : *
6775 : * - There must be no instance of the target value in
6776 : * any table.
6777 : *
6778 : * - The value must not appear in any catalog metadata,
6779 : * such as stored view expressions or column defaults.
6780 : *
6781 : * - The value must not appear in any non-leaf page of a
6782 : * btree (and similar issues with other index types).
6783 : * This is problematic because a value could persist
6784 : * there long after it's gone from user-visible data.
6785 : *
6786 : * - Concurrent sessions must not be able to insert the
6787 : * value while the preceding conditions are being checked.
6788 : *
6789 : * - Possibly more...
6790 : */
6791 0 : ereport(ERROR,
6792 : (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
6793 : errmsg("dropping an enum value is not implemented"),
6794 : parser_errposition(@4)));
6795 : }
6796 : ;
6797 :
6798 12 : opt_if_not_exists: IF_P NOT EXISTS { $$ = true; }
6799 360 : | /* EMPTY */ { $$ = false; }
6800 : ;
6801 :
6802 :
6803 : /*****************************************************************************
6804 : *
6805 : * QUERIES :
6806 : * CREATE OPERATOR CLASS ...
6807 : * CREATE OPERATOR FAMILY ...
6808 : * ALTER OPERATOR FAMILY ...
6809 : * DROP OPERATOR CLASS ...
6810 : * DROP OPERATOR FAMILY ...
6811 : *
6812 : *****************************************************************************/
6813 :
6814 : CreateOpClassStmt:
6815 : CREATE OPERATOR CLASS any_name opt_default FOR TYPE_P Typename
6816 : USING name opt_opfamily AS opclass_item_list
6817 : {
6818 556 : CreateOpClassStmt *n = makeNode(CreateOpClassStmt);
6819 :
6820 556 : n->opclassname = $4;
6821 556 : n->isDefault = $5;
6822 556 : n->datatype = $8;
6823 556 : n->amname = $10;
6824 556 : n->opfamilyname = $11;
6825 556 : n->items = $13;
6826 556 : $$ = (Node *) n;
6827 : }
6828 : ;
6829 :
6830 : opclass_item_list:
6831 1412 : opclass_item { $$ = list_make1($1); }
6832 5388 : | opclass_item_list ',' opclass_item { $$ = lappend($1, $3); }
6833 : ;
6834 :
6835 : opclass_item:
6836 : OPERATOR Iconst any_operator opclass_purpose
6837 : {
6838 1866 : CreateOpClassItem *n = makeNode(CreateOpClassItem);
6839 1866 : ObjectWithArgs *owa = makeNode(ObjectWithArgs);
6840 :
6841 1866 : owa->objname = $3;
6842 1866 : owa->objargs = NIL;
6843 1866 : n->itemtype = OPCLASS_ITEM_OPERATOR;
6844 1866 : n->name = owa;
6845 1866 : n->number = $2;
6846 1866 : n->order_family = $4;
6847 1866 : $$ = (Node *) n;
6848 : }
6849 : | OPERATOR Iconst operator_with_argtypes opclass_purpose
6850 : {
6851 1570 : CreateOpClassItem *n = makeNode(CreateOpClassItem);
6852 :
6853 1570 : n->itemtype = OPCLASS_ITEM_OPERATOR;
6854 1570 : n->name = $3;
6855 1570 : n->number = $2;
6856 1570 : n->order_family = $4;
6857 1570 : $$ = (Node *) n;
6858 : }
6859 : | FUNCTION Iconst function_with_argtypes
6860 : {
6861 2414 : CreateOpClassItem *n = makeNode(CreateOpClassItem);
6862 :
6863 2414 : n->itemtype = OPCLASS_ITEM_FUNCTION;
6864 2414 : n->name = $3;
6865 2414 : n->number = $2;
6866 2414 : $$ = (Node *) n;
6867 : }
6868 : | FUNCTION Iconst '(' type_list ')' function_with_argtypes
6869 : {
6870 590 : CreateOpClassItem *n = makeNode(CreateOpClassItem);
6871 :
6872 590 : n->itemtype = OPCLASS_ITEM_FUNCTION;
6873 590 : n->name = $6;
6874 590 : n->number = $2;
6875 590 : n->class_args = $4;
6876 590 : $$ = (Node *) n;
6877 : }
6878 : | STORAGE Typename
6879 : {
6880 360 : CreateOpClassItem *n = makeNode(CreateOpClassItem);
6881 :
6882 360 : n->itemtype = OPCLASS_ITEM_STORAGETYPE;
6883 360 : n->storedtype = $2;
6884 360 : $$ = (Node *) n;
6885 : }
6886 : ;
6887 :
6888 452 : opt_default: DEFAULT { $$ = true; }
6889 168 : | /*EMPTY*/ { $$ = false; }
6890 : ;
6891 :
6892 44 : opt_opfamily: FAMILY any_name { $$ = $2; }
6893 512 : | /*EMPTY*/ { $$ = NIL; }
6894 : ;
6895 :
6896 0 : opclass_purpose: FOR SEARCH { $$ = NIL; }
6897 120 : | FOR ORDER BY any_name { $$ = $4; }
6898 3316 : | /*EMPTY*/ { $$ = NIL; }
6899 : ;
6900 :
6901 :
6902 : CreateOpFamilyStmt:
6903 : CREATE OPERATOR FAMILY any_name USING name
6904 : {
6905 148 : CreateOpFamilyStmt *n = makeNode(CreateOpFamilyStmt);
6906 :
6907 148 : n->opfamilyname = $4;
6908 148 : n->amname = $6;
6909 148 : $$ = (Node *) n;
6910 : }
6911 : ;
6912 :
6913 : AlterOpFamilyStmt:
6914 : ALTER OPERATOR FAMILY any_name USING name ADD_P opclass_item_list
6915 : {
6916 856 : AlterOpFamilyStmt *n = makeNode(AlterOpFamilyStmt);
6917 :
6918 856 : n->opfamilyname = $4;
6919 856 : n->amname = $6;
6920 856 : n->isDrop = false;
6921 856 : n->items = $8;
6922 856 : $$ = (Node *) n;
6923 : }
6924 : | ALTER OPERATOR FAMILY any_name USING name DROP opclass_drop_list
6925 : {
6926 64 : AlterOpFamilyStmt *n = makeNode(AlterOpFamilyStmt);
6927 :
6928 64 : n->opfamilyname = $4;
6929 64 : n->amname = $6;
6930 64 : n->isDrop = true;
6931 64 : n->items = $8;
6932 64 : $$ = (Node *) n;
6933 : }
6934 : ;
6935 :
6936 : opclass_drop_list:
6937 64 : opclass_drop { $$ = list_make1($1); }
6938 30 : | opclass_drop_list ',' opclass_drop { $$ = lappend($1, $3); }
6939 : ;
6940 :
6941 : opclass_drop:
6942 : OPERATOR Iconst '(' type_list ')'
6943 : {
6944 56 : CreateOpClassItem *n = makeNode(CreateOpClassItem);
6945 :
6946 56 : n->itemtype = OPCLASS_ITEM_OPERATOR;
6947 56 : n->number = $2;
6948 56 : n->class_args = $4;
6949 56 : $$ = (Node *) n;
6950 : }
6951 : | FUNCTION Iconst '(' type_list ')'
6952 : {
6953 38 : CreateOpClassItem *n = makeNode(CreateOpClassItem);
6954 :
6955 38 : n->itemtype = OPCLASS_ITEM_FUNCTION;
6956 38 : n->number = $2;
6957 38 : n->class_args = $4;
6958 38 : $$ = (Node *) n;
6959 : }
6960 : ;
6961 :
6962 :
6963 : DropOpClassStmt:
6964 : DROP OPERATOR CLASS any_name USING name opt_drop_behavior
6965 : {
6966 38 : DropStmt *n = makeNode(DropStmt);
6967 :
6968 38 : n->objects = list_make1(lcons(makeString($6), $4));
6969 38 : n->removeType = OBJECT_OPCLASS;
6970 38 : n->behavior = $7;
6971 38 : n->missing_ok = false;
6972 38 : n->concurrent = false;
6973 38 : $$ = (Node *) n;
6974 : }
6975 : | DROP OPERATOR CLASS IF_P EXISTS any_name USING name opt_drop_behavior
6976 : {
6977 18 : DropStmt *n = makeNode(DropStmt);
6978 :
6979 18 : n->objects = list_make1(lcons(makeString($8), $6));
6980 18 : n->removeType = OBJECT_OPCLASS;
6981 18 : n->behavior = $9;
6982 18 : n->missing_ok = true;
6983 18 : n->concurrent = false;
6984 18 : $$ = (Node *) n;
6985 : }
6986 : ;
6987 :
6988 : DropOpFamilyStmt:
6989 : DROP OPERATOR FAMILY any_name USING name opt_drop_behavior
6990 : {
6991 110 : DropStmt *n = makeNode(DropStmt);
6992 :
6993 110 : n->objects = list_make1(lcons(makeString($6), $4));
6994 110 : n->removeType = OBJECT_OPFAMILY;
6995 110 : n->behavior = $7;
6996 110 : n->missing_ok = false;
6997 110 : n->concurrent = false;
6998 110 : $$ = (Node *) n;
6999 : }
7000 : | DROP OPERATOR FAMILY IF_P EXISTS any_name USING name opt_drop_behavior
7001 : {
7002 18 : DropStmt *n = makeNode(DropStmt);
7003 :
7004 18 : n->objects = list_make1(lcons(makeString($8), $6));
7005 18 : n->removeType = OBJECT_OPFAMILY;
7006 18 : n->behavior = $9;
7007 18 : n->missing_ok = true;
7008 18 : n->concurrent = false;
7009 18 : $$ = (Node *) n;
7010 : }
7011 : ;
7012 :
7013 :
7014 : /*****************************************************************************
7015 : *
7016 : * QUERY:
7017 : *
7018 : * DROP OWNED BY username [, username ...] [ RESTRICT | CASCADE ]
7019 : * REASSIGN OWNED BY username [, username ...] TO username
7020 : *
7021 : *****************************************************************************/
7022 : DropOwnedStmt:
7023 : DROP OWNED BY role_list opt_drop_behavior
7024 : {
7025 146 : DropOwnedStmt *n = makeNode(DropOwnedStmt);
7026 :
7027 146 : n->roles = $4;
7028 146 : n->behavior = $5;
7029 146 : $$ = (Node *) n;
7030 : }
7031 : ;
7032 :
7033 : ReassignOwnedStmt:
7034 : REASSIGN OWNED BY role_list TO RoleSpec
7035 : {
7036 46 : ReassignOwnedStmt *n = makeNode(ReassignOwnedStmt);
7037 :
7038 46 : n->roles = $4;
7039 46 : n->newrole = $6;
7040 46 : $$ = (Node *) n;
7041 : }
7042 : ;
7043 :
7044 : /*****************************************************************************
7045 : *
7046 : * QUERY:
7047 : *
7048 : * DROP itemtype [ IF EXISTS ] itemname [, itemname ...]
7049 : * [ RESTRICT | CASCADE ]
7050 : *
7051 : *****************************************************************************/
7052 :
7053 : DropStmt: DROP object_type_any_name IF_P EXISTS any_name_list opt_drop_behavior
7054 : {
7055 1396 : DropStmt *n = makeNode(DropStmt);
7056 :
7057 1396 : n->removeType = $2;
7058 1396 : n->missing_ok = true;
7059 1396 : n->objects = $5;
7060 1396 : n->behavior = $6;
7061 1396 : n->concurrent = false;
7062 1396 : $$ = (Node *) n;
7063 : }
7064 : | DROP object_type_any_name any_name_list opt_drop_behavior
7065 : {
7066 17004 : DropStmt *n = makeNode(DropStmt);
7067 :
7068 17004 : n->removeType = $2;
7069 17004 : n->missing_ok = false;
7070 17004 : n->objects = $3;
7071 17004 : n->behavior = $4;
7072 17004 : n->concurrent = false;
7073 17004 : $$ = (Node *) n;
7074 : }
7075 : | DROP drop_type_name IF_P EXISTS name_list opt_drop_behavior
7076 : {
7077 86 : DropStmt *n = makeNode(DropStmt);
7078 :
7079 86 : n->removeType = $2;
7080 86 : n->missing_ok = true;
7081 86 : n->objects = $5;
7082 86 : n->behavior = $6;
7083 86 : n->concurrent = false;
7084 86 : $$ = (Node *) n;
7085 : }
7086 : | DROP drop_type_name name_list opt_drop_behavior
7087 : {
7088 1526 : DropStmt *n = makeNode(DropStmt);
7089 :
7090 1526 : n->removeType = $2;
7091 1526 : n->missing_ok = false;
7092 1526 : n->objects = $3;
7093 1526 : n->behavior = $4;
7094 1526 : n->concurrent = false;
7095 1526 : $$ = (Node *) n;
7096 : }
7097 : | DROP object_type_name_on_any_name name ON any_name opt_drop_behavior
7098 : {
7099 1130 : DropStmt *n = makeNode(DropStmt);
7100 :
7101 1130 : n->removeType = $2;
7102 1130 : n->objects = list_make1(lappend($5, makeString($3)));
7103 1130 : n->behavior = $6;
7104 1130 : n->missing_ok = false;
7105 1130 : n->concurrent = false;
7106 1130 : $$ = (Node *) n;
7107 : }
7108 : | DROP object_type_name_on_any_name IF_P EXISTS name ON any_name opt_drop_behavior
7109 : {
7110 48 : DropStmt *n = makeNode(DropStmt);
7111 :
7112 48 : n->removeType = $2;
7113 48 : n->objects = list_make1(lappend($7, makeString($5)));
7114 48 : n->behavior = $8;
7115 48 : n->missing_ok = true;
7116 48 : n->concurrent = false;
7117 48 : $$ = (Node *) n;
7118 : }
7119 : | DROP TYPE_P type_name_list opt_drop_behavior
7120 : {
7121 560 : DropStmt *n = makeNode(DropStmt);
7122 :
7123 560 : n->removeType = OBJECT_TYPE;
7124 560 : n->missing_ok = false;
7125 560 : n->objects = $3;
7126 560 : n->behavior = $4;
7127 560 : n->concurrent = false;
7128 560 : $$ = (Node *) n;
7129 : }
7130 : | DROP TYPE_P IF_P EXISTS type_name_list opt_drop_behavior
7131 : {
7132 26 : DropStmt *n = makeNode(DropStmt);
7133 :
7134 26 : n->removeType = OBJECT_TYPE;
7135 26 : n->missing_ok = true;
7136 26 : n->objects = $5;
7137 26 : n->behavior = $6;
7138 26 : n->concurrent = false;
7139 26 : $$ = (Node *) n;
7140 : }
7141 : | DROP DOMAIN_P type_name_list opt_drop_behavior
7142 : {
7143 470 : DropStmt *n = makeNode(DropStmt);
7144 :
7145 470 : n->removeType = OBJECT_DOMAIN;
7146 470 : n->missing_ok = false;
7147 470 : n->objects = $3;
7148 470 : n->behavior = $4;
7149 470 : n->concurrent = false;
7150 470 : $$ = (Node *) n;
7151 : }
7152 : | DROP DOMAIN_P IF_P EXISTS type_name_list opt_drop_behavior
7153 : {
7154 18 : DropStmt *n = makeNode(DropStmt);
7155 :
7156 18 : n->removeType = OBJECT_DOMAIN;
7157 18 : n->missing_ok = true;
7158 18 : n->objects = $5;
7159 18 : n->behavior = $6;
7160 18 : n->concurrent = false;
7161 18 : $$ = (Node *) n;
7162 : }
7163 : | DROP INDEX CONCURRENTLY any_name_list opt_drop_behavior
7164 : {
7165 128 : DropStmt *n = makeNode(DropStmt);
7166 :
7167 128 : n->removeType = OBJECT_INDEX;
7168 128 : n->missing_ok = false;
7169 128 : n->objects = $4;
7170 128 : n->behavior = $5;
7171 128 : n->concurrent = true;
7172 128 : $$ = (Node *) n;
7173 : }
7174 : | DROP INDEX CONCURRENTLY IF_P EXISTS any_name_list opt_drop_behavior
7175 : {
7176 12 : DropStmt *n = makeNode(DropStmt);
7177 :
7178 12 : n->removeType = OBJECT_INDEX;
7179 12 : n->missing_ok = true;
7180 12 : n->objects = $6;
7181 12 : n->behavior = $7;
7182 12 : n->concurrent = true;
7183 12 : $$ = (Node *) n;
7184 : }
7185 : ;
7186 :
7187 : /* object types taking any_name/any_name_list */
7188 : object_type_any_name:
7189 15962 : TABLE { $$ = OBJECT_TABLE; }
7190 200 : | SEQUENCE { $$ = OBJECT_SEQUENCE; }
7191 1054 : | VIEW { $$ = OBJECT_VIEW; }
7192 130 : | MATERIALIZED VIEW { $$ = OBJECT_MATVIEW; }
7193 778 : | INDEX { $$ = OBJECT_INDEX; }
7194 186 : | FOREIGN TABLE { $$ = OBJECT_FOREIGN_TABLE; }
7195 96 : | COLLATION { $$ = OBJECT_COLLATION; }
7196 56 : | CONVERSION_P { $$ = OBJECT_CONVERSION; }
7197 222 : | STATISTICS { $$ = OBJECT_STATISTIC_EXT; }
7198 20 : | TEXT_P SEARCH PARSER { $$ = OBJECT_TSPARSER; }
7199 2872 : | TEXT_P SEARCH DICTIONARY { $$ = OBJECT_TSDICTIONARY; }
7200 118 : | TEXT_P SEARCH TEMPLATE { $$ = OBJECT_TSTEMPLATE; }
7201 2876 : | TEXT_P SEARCH CONFIGURATION { $$ = OBJECT_TSCONFIGURATION; }
7202 : ;
7203 :
7204 : /*
7205 : * object types taking name/name_list
7206 : *
7207 : * DROP handles some of them separately
7208 : */
7209 :
7210 : object_type_name:
7211 256 : drop_type_name { $$ = $1; }
7212 246 : | DATABASE { $$ = OBJECT_DATABASE; }
7213 52 : | ROLE { $$ = OBJECT_ROLE; }
7214 10 : | SUBSCRIPTION { $$ = OBJECT_SUBSCRIPTION; }
7215 0 : | TABLESPACE { $$ = OBJECT_TABLESPACE; }
7216 : ;
7217 :
7218 : drop_type_name:
7219 58 : ACCESS METHOD { $$ = OBJECT_ACCESS_METHOD; }
7220 128 : | EVENT TRIGGER { $$ = OBJECT_EVENT_TRIGGER; }
7221 184 : | EXTENSION { $$ = OBJECT_EXTENSION; }
7222 154 : | FOREIGN DATA_P WRAPPER { $$ = OBJECT_FDW; }
7223 156 : | opt_procedural LANGUAGE { $$ = OBJECT_LANGUAGE; }
7224 420 : | PUBLICATION { $$ = OBJECT_PUBLICATION; }
7225 630 : | SCHEMA { $$ = OBJECT_SCHEMA; }
7226 138 : | SERVER { $$ = OBJECT_FOREIGN_SERVER; }
7227 : ;
7228 :
7229 : /* object types attached to a table */
7230 : object_type_name_on_any_name:
7231 166 : POLICY { $$ = OBJECT_POLICY; }
7232 268 : | RULE { $$ = OBJECT_RULE; }
7233 798 : | TRIGGER { $$ = OBJECT_TRIGGER; }
7234 : ;
7235 :
7236 : any_name_list:
7237 27396 : any_name { $$ = list_make1($1); }
7238 4270 : | any_name_list ',' any_name { $$ = lappend($1, $3); }
7239 : ;
7240 :
7241 69338 : any_name: ColId { $$ = list_make1(makeString($1)); }
7242 9200 : | ColId attrs { $$ = lcons(makeString($1), $2); }
7243 : ;
7244 :
7245 : attrs: '.' attr_name
7246 126984 : { $$ = list_make1(makeString($2)); }
7247 : | attrs '.' attr_name
7248 64 : { $$ = lappend($1, makeString($3)); }
7249 : ;
7250 :
7251 : type_name_list:
7252 1074 : Typename { $$ = list_make1($1); }
7253 102 : | type_name_list ',' Typename { $$ = lappend($1, $3); }
7254 : ;
7255 :
7256 : /*****************************************************************************
7257 : *
7258 : * QUERY:
7259 : * truncate table relname1, relname2, ...
7260 : *
7261 : *****************************************************************************/
7262 :
7263 : TruncateStmt:
7264 : TRUNCATE opt_table relation_expr_list opt_restart_seqs opt_drop_behavior
7265 : {
7266 1778 : TruncateStmt *n = makeNode(TruncateStmt);
7267 :
7268 1778 : n->relations = $3;
7269 1778 : n->restart_seqs = $4;
7270 1778 : n->behavior = $5;
7271 1778 : $$ = (Node *) n;
7272 : }
7273 : ;
7274 :
7275 : opt_restart_seqs:
7276 24 : CONTINUE_P IDENTITY_P { $$ = false; }
7277 22 : | RESTART IDENTITY_P { $$ = true; }
7278 1732 : | /* EMPTY */ { $$ = false; }
7279 : ;
7280 :
7281 : /*****************************************************************************
7282 : *
7283 : * COMMENT ON <object> IS <text>
7284 : *
7285 : *****************************************************************************/
7286 :
7287 : CommentStmt:
7288 : COMMENT ON object_type_any_name any_name IS comment_text
7289 : {
7290 6016 : CommentStmt *n = makeNode(CommentStmt);
7291 :
7292 6016 : n->objtype = $3;
7293 6016 : n->object = (Node *) $4;
7294 6016 : n->comment = $6;
7295 6016 : $$ = (Node *) n;
7296 : }
7297 : | COMMENT ON COLUMN any_name IS comment_text
7298 : {
7299 144 : CommentStmt *n = makeNode(CommentStmt);
7300 :
7301 144 : n->objtype = OBJECT_COLUMN;
7302 144 : n->object = (Node *) $4;
7303 144 : n->comment = $6;
7304 144 : $$ = (Node *) n;
7305 : }
7306 : | COMMENT ON object_type_name name IS comment_text
7307 : {
7308 502 : CommentStmt *n = makeNode(CommentStmt);
7309 :
7310 502 : n->objtype = $3;
7311 502 : n->object = (Node *) makeString($4);
7312 502 : n->comment = $6;
7313 502 : $$ = (Node *) n;
7314 : }
7315 : | COMMENT ON TYPE_P Typename IS comment_text
7316 : {
7317 56 : CommentStmt *n = makeNode(CommentStmt);
7318 :
7319 56 : n->objtype = OBJECT_TYPE;
7320 56 : n->object = (Node *) $4;
7321 56 : n->comment = $6;
7322 56 : $$ = (Node *) n;
7323 : }
7324 : | COMMENT ON DOMAIN_P Typename IS comment_text
7325 : {
7326 8 : CommentStmt *n = makeNode(CommentStmt);
7327 :
7328 8 : n->objtype = OBJECT_DOMAIN;
7329 8 : n->object = (Node *) $4;
7330 8 : n->comment = $6;
7331 8 : $$ = (Node *) n;
7332 : }
7333 : | COMMENT ON AGGREGATE aggregate_with_argtypes IS comment_text
7334 : {
7335 40 : CommentStmt *n = makeNode(CommentStmt);
7336 :
7337 40 : n->objtype = OBJECT_AGGREGATE;
7338 40 : n->object = (Node *) $4;
7339 40 : n->comment = $6;
7340 40 : $$ = (Node *) n;
7341 : }
7342 : | COMMENT ON FUNCTION function_with_argtypes IS comment_text
7343 : {
7344 170 : CommentStmt *n = makeNode(CommentStmt);
7345 :
7346 170 : n->objtype = OBJECT_FUNCTION;
7347 170 : n->object = (Node *) $4;
7348 170 : n->comment = $6;
7349 170 : $$ = (Node *) n;
7350 : }
7351 : | COMMENT ON OPERATOR operator_with_argtypes IS comment_text
7352 : {
7353 18 : CommentStmt *n = makeNode(CommentStmt);
7354 :
7355 18 : n->objtype = OBJECT_OPERATOR;
7356 18 : n->object = (Node *) $4;
7357 18 : n->comment = $6;
7358 18 : $$ = (Node *) n;
7359 : }
7360 : | COMMENT ON CONSTRAINT name ON any_name IS comment_text
7361 : {
7362 150 : CommentStmt *n = makeNode(CommentStmt);
7363 :
7364 150 : n->objtype = OBJECT_TABCONSTRAINT;
7365 150 : n->object = (Node *) lappend($6, makeString($4));
7366 150 : n->comment = $8;
7367 150 : $$ = (Node *) n;
7368 : }
7369 : | COMMENT ON CONSTRAINT name ON DOMAIN_P any_name IS comment_text
7370 : {
7371 48 : CommentStmt *n = makeNode(CommentStmt);
7372 :
7373 48 : n->objtype = OBJECT_DOMCONSTRAINT;
7374 : /*
7375 : * should use Typename not any_name in the production, but
7376 : * there's a shift/reduce conflict if we do that, so fix it
7377 : * up here.
7378 : */
7379 48 : n->object = (Node *) list_make2(makeTypeNameFromNameList($7), makeString($4));
7380 48 : n->comment = $9;
7381 48 : $$ = (Node *) n;
7382 : }
7383 : | COMMENT ON object_type_name_on_any_name name ON any_name IS comment_text
7384 : {
7385 42 : CommentStmt *n = makeNode(CommentStmt);
7386 :
7387 42 : n->objtype = $3;
7388 42 : n->object = (Node *) lappend($6, makeString($4));
7389 42 : n->comment = $8;
7390 42 : $$ = (Node *) n;
7391 : }
7392 : | COMMENT ON PROCEDURE function_with_argtypes IS comment_text
7393 : {
7394 0 : CommentStmt *n = makeNode(CommentStmt);
7395 :
7396 0 : n->objtype = OBJECT_PROCEDURE;
7397 0 : n->object = (Node *) $4;
7398 0 : n->comment = $6;
7399 0 : $$ = (Node *) n;
7400 : }
7401 : | COMMENT ON ROUTINE function_with_argtypes IS comment_text
7402 : {
7403 0 : CommentStmt *n = makeNode(CommentStmt);
7404 :
7405 0 : n->objtype = OBJECT_ROUTINE;
7406 0 : n->object = (Node *) $4;
7407 0 : n->comment = $6;
7408 0 : $$ = (Node *) n;
7409 : }
7410 : | COMMENT ON TRANSFORM FOR Typename LANGUAGE name IS comment_text
7411 : {
7412 14 : CommentStmt *n = makeNode(CommentStmt);
7413 :
7414 14 : n->objtype = OBJECT_TRANSFORM;
7415 14 : n->object = (Node *) list_make2($5, makeString($7));
7416 14 : n->comment = $9;
7417 14 : $$ = (Node *) n;
7418 : }
7419 : | COMMENT ON OPERATOR CLASS any_name USING name IS comment_text
7420 : {
7421 0 : CommentStmt *n = makeNode(CommentStmt);
7422 :
7423 0 : n->objtype = OBJECT_OPCLASS;
7424 0 : n->object = (Node *) lcons(makeString($7), $5);
7425 0 : n->comment = $9;
7426 0 : $$ = (Node *) n;
7427 : }
7428 : | COMMENT ON OPERATOR FAMILY any_name USING name IS comment_text
7429 : {
7430 0 : CommentStmt *n = makeNode(CommentStmt);
7431 :
7432 0 : n->objtype = OBJECT_OPFAMILY;
7433 0 : n->object = (Node *) lcons(makeString($7), $5);
7434 0 : n->comment = $9;
7435 0 : $$ = (Node *) n;
7436 : }
7437 : | COMMENT ON LARGE_P OBJECT_P NumericOnly IS comment_text
7438 : {
7439 42 : CommentStmt *n = makeNode(CommentStmt);
7440 :
7441 42 : n->objtype = OBJECT_LARGEOBJECT;
7442 42 : n->object = (Node *) $5;
7443 42 : n->comment = $7;
7444 42 : $$ = (Node *) n;
7445 : }
7446 : | COMMENT ON CAST '(' Typename AS Typename ')' IS comment_text
7447 : {
7448 0 : CommentStmt *n = makeNode(CommentStmt);
7449 :
7450 0 : n->objtype = OBJECT_CAST;
7451 0 : n->object = (Node *) list_make2($5, $7);
7452 0 : n->comment = $10;
7453 0 : $$ = (Node *) n;
7454 : }
7455 : ;
7456 :
7457 : comment_text:
7458 7146 : Sconst { $$ = $1; }
7459 104 : | NULL_P { $$ = NULL; }
7460 : ;
7461 :
7462 :
7463 : /*****************************************************************************
7464 : *
7465 : * SECURITY LABEL [FOR <provider>] ON <object> IS <label>
7466 : *
7467 : * As with COMMENT ON, <object> can refer to various types of database
7468 : * objects (e.g. TABLE, COLUMN, etc.).
7469 : *
7470 : *****************************************************************************/
7471 :
7472 : SecLabelStmt:
7473 : SECURITY LABEL opt_provider ON object_type_any_name any_name
7474 : IS security_label
7475 : {
7476 48 : SecLabelStmt *n = makeNode(SecLabelStmt);
7477 :
7478 48 : n->provider = $3;
7479 48 : n->objtype = $5;
7480 48 : n->object = (Node *) $6;
7481 48 : n->label = $8;
7482 48 : $$ = (Node *) n;
7483 : }
7484 : | SECURITY LABEL opt_provider ON COLUMN any_name
7485 : IS security_label
7486 : {
7487 4 : SecLabelStmt *n = makeNode(SecLabelStmt);
7488 :
7489 4 : n->provider = $3;
7490 4 : n->objtype = OBJECT_COLUMN;
7491 4 : n->object = (Node *) $6;
7492 4 : n->label = $8;
7493 4 : $$ = (Node *) n;
7494 : }
7495 : | SECURITY LABEL opt_provider ON object_type_name name
7496 : IS security_label
7497 : {
7498 44 : SecLabelStmt *n = makeNode(SecLabelStmt);
7499 :
7500 44 : n->provider = $3;
7501 44 : n->objtype = $5;
7502 44 : n->object = (Node *) makeString($6);
7503 44 : n->label = $8;
7504 44 : $$ = (Node *) n;
7505 : }
7506 : | SECURITY LABEL opt_provider ON TYPE_P Typename
7507 : IS security_label
7508 : {
7509 0 : SecLabelStmt *n = makeNode(SecLabelStmt);
7510 :
7511 0 : n->provider = $3;
7512 0 : n->objtype = OBJECT_TYPE;
7513 0 : n->object = (Node *) $6;
7514 0 : n->label = $8;
7515 0 : $$ = (Node *) n;
7516 : }
7517 : | SECURITY LABEL opt_provider ON DOMAIN_P Typename
7518 : IS security_label
7519 : {
7520 2 : SecLabelStmt *n = makeNode(SecLabelStmt);
7521 :
7522 2 : n->provider = $3;
7523 2 : n->objtype = OBJECT_DOMAIN;
7524 2 : n->object = (Node *) $6;
7525 2 : n->label = $8;
7526 2 : $$ = (Node *) n;
7527 : }
7528 : | SECURITY LABEL opt_provider ON AGGREGATE aggregate_with_argtypes
7529 : IS security_label
7530 : {
7531 0 : SecLabelStmt *n = makeNode(SecLabelStmt);
7532 :
7533 0 : n->provider = $3;
7534 0 : n->objtype = OBJECT_AGGREGATE;
7535 0 : n->object = (Node *) $6;
7536 0 : n->label = $8;
7537 0 : $$ = (Node *) n;
7538 : }
7539 : | SECURITY LABEL opt_provider ON FUNCTION function_with_argtypes
7540 : IS security_label
7541 : {
7542 2 : SecLabelStmt *n = makeNode(SecLabelStmt);
7543 :
7544 2 : n->provider = $3;
7545 2 : n->objtype = OBJECT_FUNCTION;
7546 2 : n->object = (Node *) $6;
7547 2 : n->label = $8;
7548 2 : $$ = (Node *) n;
7549 : }
7550 : | SECURITY LABEL opt_provider ON LARGE_P OBJECT_P NumericOnly
7551 : IS security_label
7552 : {
7553 18 : SecLabelStmt *n = makeNode(SecLabelStmt);
7554 :
7555 18 : n->provider = $3;
7556 18 : n->objtype = OBJECT_LARGEOBJECT;
7557 18 : n->object = (Node *) $7;
7558 18 : n->label = $9;
7559 18 : $$ = (Node *) n;
7560 : }
7561 : | SECURITY LABEL opt_provider ON PROCEDURE function_with_argtypes
7562 : IS security_label
7563 : {
7564 0 : SecLabelStmt *n = makeNode(SecLabelStmt);
7565 :
7566 0 : n->provider = $3;
7567 0 : n->objtype = OBJECT_PROCEDURE;
7568 0 : n->object = (Node *) $6;
7569 0 : n->label = $8;
7570 0 : $$ = (Node *) n;
7571 : }
7572 : | SECURITY LABEL opt_provider ON ROUTINE function_with_argtypes
7573 : IS security_label
7574 : {
7575 0 : SecLabelStmt *n = makeNode(SecLabelStmt);
7576 :
7577 0 : n->provider = $3;
7578 0 : n->objtype = OBJECT_ROUTINE;
7579 0 : n->object = (Node *) $6;
7580 0 : n->label = $8;
7581 0 : $$ = (Node *) n;
7582 : }
7583 : ;
7584 :
7585 28 : opt_provider: FOR NonReservedWord_or_Sconst { $$ = $2; }
7586 90 : | /* EMPTY */ { $$ = NULL; }
7587 : ;
7588 :
7589 118 : security_label: Sconst { $$ = $1; }
7590 0 : | NULL_P { $$ = NULL; }
7591 : ;
7592 :
7593 : /*****************************************************************************
7594 : *
7595 : * QUERY:
7596 : * fetch/move
7597 : *
7598 : *****************************************************************************/
7599 :
7600 : FetchStmt: FETCH fetch_args
7601 : {
7602 7648 : FetchStmt *n = (FetchStmt *) $2;
7603 :
7604 7648 : n->ismove = false;
7605 7648 : $$ = (Node *) n;
7606 : }
7607 : | MOVE fetch_args
7608 : {
7609 68 : FetchStmt *n = (FetchStmt *) $2;
7610 :
7611 68 : n->ismove = true;
7612 68 : $$ = (Node *) n;
7613 : }
7614 : ;
7615 :
7616 : fetch_args: cursor_name
7617 : {
7618 272 : FetchStmt *n = makeNode(FetchStmt);
7619 :
7620 272 : n->portalname = $1;
7621 272 : n->direction = FETCH_FORWARD;
7622 272 : n->howMany = 1;
7623 272 : n->location = -1;
7624 272 : n->direction_keyword = FETCH_KEYWORD_NONE;
7625 272 : $$ = (Node *) n;
7626 : }
7627 : | from_in cursor_name
7628 : {
7629 218 : FetchStmt *n = makeNode(FetchStmt);
7630 :
7631 218 : n->portalname = $2;
7632 218 : n->direction = FETCH_FORWARD;
7633 218 : n->howMany = 1;
7634 218 : n->location = -1;
7635 218 : n->direction_keyword = FETCH_KEYWORD_NONE;
7636 218 : $$ = (Node *) n;
7637 : }
7638 : | SignedIconst opt_from_in cursor_name
7639 : {
7640 4282 : FetchStmt *n = makeNode(FetchStmt);
7641 :
7642 4282 : n->portalname = $3;
7643 4282 : n->direction = FETCH_FORWARD;
7644 4282 : n->howMany = $1;
7645 4282 : n->location = @1;
7646 4282 : n->direction_keyword = FETCH_KEYWORD_NONE;
7647 4282 : $$ = (Node *) n;
7648 : }
7649 : | NEXT opt_from_in cursor_name
7650 : {
7651 2010 : FetchStmt *n = makeNode(FetchStmt);
7652 :
7653 2010 : n->portalname = $3;
7654 2010 : n->direction = FETCH_FORWARD;
7655 2010 : n->howMany = 1;
7656 2010 : n->location = -1;
7657 2010 : n->direction_keyword = FETCH_KEYWORD_NEXT;
7658 2010 : $$ = (Node *) n;
7659 : }
7660 : | PRIOR opt_from_in cursor_name
7661 : {
7662 32 : FetchStmt *n = makeNode(FetchStmt);
7663 :
7664 32 : n->portalname = $3;
7665 32 : n->direction = FETCH_BACKWARD;
7666 32 : n->howMany = 1;
7667 32 : n->location = -1;
7668 32 : n->direction_keyword = FETCH_KEYWORD_PRIOR;
7669 32 : $$ = (Node *) n;
7670 : }
7671 : | FIRST_P opt_from_in cursor_name
7672 : {
7673 26 : FetchStmt *n = makeNode(FetchStmt);
7674 :
7675 26 : n->portalname = $3;
7676 26 : n->direction = FETCH_ABSOLUTE;
7677 26 : n->howMany = 1;
7678 26 : n->location = -1;
7679 26 : n->direction_keyword = FETCH_KEYWORD_FIRST;
7680 26 : $$ = (Node *) n;
7681 : }
7682 : | LAST_P opt_from_in cursor_name
7683 : {
7684 20 : FetchStmt *n = makeNode(FetchStmt);
7685 :
7686 20 : n->portalname = $3;
7687 20 : n->direction = FETCH_ABSOLUTE;
7688 20 : n->howMany = -1;
7689 20 : n->location = -1;
7690 20 : n->direction_keyword = FETCH_KEYWORD_LAST;
7691 20 : $$ = (Node *) n;
7692 : }
7693 : | ABSOLUTE_P SignedIconst opt_from_in cursor_name
7694 : {
7695 94 : FetchStmt *n = makeNode(FetchStmt);
7696 :
7697 94 : n->portalname = $4;
7698 94 : n->direction = FETCH_ABSOLUTE;
7699 94 : n->howMany = $2;
7700 94 : n->location = @2;
7701 94 : n->direction_keyword = FETCH_KEYWORD_ABSOLUTE;
7702 94 : $$ = (Node *) n;
7703 : }
7704 : | RELATIVE_P SignedIconst opt_from_in cursor_name
7705 : {
7706 36 : FetchStmt *n = makeNode(FetchStmt);
7707 :
7708 36 : n->portalname = $4;
7709 36 : n->direction = FETCH_RELATIVE;
7710 36 : n->howMany = $2;
7711 36 : n->location = @2;
7712 36 : n->direction_keyword = FETCH_KEYWORD_RELATIVE;
7713 36 : $$ = (Node *) n;
7714 : }
7715 : | ALL opt_from_in cursor_name
7716 : {
7717 270 : FetchStmt *n = makeNode(FetchStmt);
7718 :
7719 270 : n->portalname = $3;
7720 270 : n->direction = FETCH_FORWARD;
7721 270 : n->howMany = FETCH_ALL;
7722 270 : n->location = -1;
7723 270 : n->direction_keyword = FETCH_KEYWORD_ALL;
7724 270 : $$ = (Node *) n;
7725 : }
7726 : | FORWARD opt_from_in cursor_name
7727 : {
7728 30 : FetchStmt *n = makeNode(FetchStmt);
7729 :
7730 30 : n->portalname = $3;
7731 30 : n->direction = FETCH_FORWARD;
7732 30 : n->howMany = 1;
7733 30 : n->location = -1;
7734 30 : n->direction_keyword = FETCH_KEYWORD_FORWARD;
7735 30 : $$ = (Node *) n;
7736 : }
7737 : | FORWARD SignedIconst opt_from_in cursor_name
7738 : {
7739 12 : FetchStmt *n = makeNode(FetchStmt);
7740 :
7741 12 : n->portalname = $4;
7742 12 : n->direction = FETCH_FORWARD;
7743 12 : n->howMany = $2;
7744 12 : n->location = @2;
7745 12 : n->direction_keyword = FETCH_KEYWORD_FORWARD;
7746 12 : $$ = (Node *) n;
7747 : }
7748 : | FORWARD ALL opt_from_in cursor_name
7749 : {
7750 16 : FetchStmt *n = makeNode(FetchStmt);
7751 :
7752 16 : n->portalname = $4;
7753 16 : n->direction = FETCH_FORWARD;
7754 16 : n->howMany = FETCH_ALL;
7755 16 : n->location = -1;
7756 16 : n->direction_keyword = FETCH_KEYWORD_FORWARD_ALL;
7757 16 : $$ = (Node *) n;
7758 : }
7759 : | BACKWARD opt_from_in cursor_name
7760 : {
7761 80 : FetchStmt *n = makeNode(FetchStmt);
7762 :
7763 80 : n->portalname = $3;
7764 80 : n->direction = FETCH_BACKWARD;
7765 80 : n->howMany = 1;
7766 80 : n->location = -1;
7767 80 : n->direction_keyword = FETCH_KEYWORD_BACKWARD;
7768 80 : $$ = (Node *) n;
7769 : }
7770 : | BACKWARD SignedIconst opt_from_in cursor_name
7771 : {
7772 226 : FetchStmt *n = makeNode(FetchStmt);
7773 :
7774 226 : n->portalname = $4;
7775 226 : n->direction = FETCH_BACKWARD;
7776 226 : n->howMany = $2;
7777 226 : n->location = @2;
7778 226 : n->direction_keyword = FETCH_KEYWORD_BACKWARD;
7779 226 : $$ = (Node *) n;
7780 : }
7781 : | BACKWARD ALL opt_from_in cursor_name
7782 : {
7783 92 : FetchStmt *n = makeNode(FetchStmt);
7784 :
7785 92 : n->portalname = $4;
7786 92 : n->direction = FETCH_BACKWARD;
7787 92 : n->howMany = FETCH_ALL;
7788 92 : n->location = -1;
7789 92 : n->direction_keyword = FETCH_KEYWORD_BACKWARD_ALL;
7790 92 : $$ = (Node *) n;
7791 : }
7792 : ;
7793 :
7794 : from_in: FROM
7795 : | IN_P
7796 : ;
7797 :
7798 : opt_from_in: from_in
7799 : | /* EMPTY */
7800 : ;
7801 :
7802 :
7803 : /*****************************************************************************
7804 : *
7805 : * GRANT and REVOKE statements
7806 : *
7807 : *****************************************************************************/
7808 :
7809 : GrantStmt: GRANT privileges ON privilege_target TO grantee_list
7810 : opt_grant_grant_option opt_granted_by
7811 : {
7812 12026 : GrantStmt *n = makeNode(GrantStmt);
7813 :
7814 12026 : n->is_grant = true;
7815 12026 : n->privileges = $2;
7816 12026 : n->targtype = ($4)->targtype;
7817 12026 : n->objtype = ($4)->objtype;
7818 12026 : n->objects = ($4)->objs;
7819 12026 : n->grantees = $6;
7820 12026 : n->grant_option = $7;
7821 12026 : n->grantor = $8;
7822 12026 : $$ = (Node *) n;
7823 : }
7824 : ;
7825 :
7826 : RevokeStmt:
7827 : REVOKE privileges ON privilege_target
7828 : FROM grantee_list opt_granted_by opt_drop_behavior
7829 : {
7830 10646 : GrantStmt *n = makeNode(GrantStmt);
7831 :
7832 10646 : n->is_grant = false;
7833 10646 : n->grant_option = false;
7834 10646 : n->privileges = $2;
7835 10646 : n->targtype = ($4)->targtype;
7836 10646 : n->objtype = ($4)->objtype;
7837 10646 : n->objects = ($4)->objs;
7838 10646 : n->grantees = $6;
7839 10646 : n->grantor = $7;
7840 10646 : n->behavior = $8;
7841 10646 : $$ = (Node *) n;
7842 : }
7843 : | REVOKE GRANT OPTION FOR privileges ON privilege_target
7844 : FROM grantee_list opt_granted_by opt_drop_behavior
7845 : {
7846 16 : GrantStmt *n = makeNode(GrantStmt);
7847 :
7848 16 : n->is_grant = false;
7849 16 : n->grant_option = true;
7850 16 : n->privileges = $5;
7851 16 : n->targtype = ($7)->targtype;
7852 16 : n->objtype = ($7)->objtype;
7853 16 : n->objects = ($7)->objs;
7854 16 : n->grantees = $9;
7855 16 : n->grantor = $10;
7856 16 : n->behavior = $11;
7857 16 : $$ = (Node *) n;
7858 : }
7859 : ;
7860 :
7861 :
7862 : /*
7863 : * Privilege names are represented as strings; the validity of the privilege
7864 : * names gets checked at execution. This is a bit annoying but we have little
7865 : * choice because of the syntactic conflict with lists of role names in
7866 : * GRANT/REVOKE. What's more, we have to call out in the "privilege"
7867 : * production any reserved keywords that need to be usable as privilege names.
7868 : */
7869 :
7870 : /* either ALL [PRIVILEGES] or a list of individual privileges */
7871 : privileges: privilege_list
7872 19986 : { $$ = $1; }
7873 : | ALL
7874 2782 : { $$ = NIL; }
7875 : | ALL PRIVILEGES
7876 120 : { $$ = NIL; }
7877 : | ALL '(' columnList ')'
7878 : {
7879 18 : AccessPriv *n = makeNode(AccessPriv);
7880 :
7881 18 : n->priv_name = NULL;
7882 18 : n->cols = $3;
7883 18 : $$ = list_make1(n);
7884 : }
7885 : | ALL PRIVILEGES '(' columnList ')'
7886 : {
7887 0 : AccessPriv *n = makeNode(AccessPriv);
7888 :
7889 0 : n->priv_name = NULL;
7890 0 : n->cols = $4;
7891 0 : $$ = list_make1(n);
7892 : }
7893 : ;
7894 :
7895 20906 : privilege_list: privilege { $$ = list_make1($1); }
7896 588 : | privilege_list ',' privilege { $$ = lappend($1, $3); }
7897 : ;
7898 :
7899 : privilege: SELECT opt_column_list
7900 : {
7901 9706 : AccessPriv *n = makeNode(AccessPriv);
7902 :
7903 9706 : n->priv_name = pstrdup($1);
7904 9706 : n->cols = $2;
7905 9706 : $$ = n;
7906 : }
7907 : | REFERENCES opt_column_list
7908 : {
7909 14 : AccessPriv *n = makeNode(AccessPriv);
7910 :
7911 14 : n->priv_name = pstrdup($1);
7912 14 : n->cols = $2;
7913 14 : $$ = n;
7914 : }
7915 : | CREATE opt_column_list
7916 : {
7917 324 : AccessPriv *n = makeNode(AccessPriv);
7918 :
7919 324 : n->priv_name = pstrdup($1);
7920 324 : n->cols = $2;
7921 324 : $$ = n;
7922 : }
7923 : | ALTER SYSTEM_P
7924 : {
7925 24 : AccessPriv *n = makeNode(AccessPriv);
7926 24 : n->priv_name = pstrdup("alter system");
7927 24 : n->cols = NIL;
7928 24 : $$ = n;
7929 : }
7930 : | ColId opt_column_list
7931 : {
7932 11426 : AccessPriv *n = makeNode(AccessPriv);
7933 :
7934 11426 : n->priv_name = $1;
7935 11426 : n->cols = $2;
7936 11426 : $$ = n;
7937 : }
7938 : ;
7939 :
7940 : parameter_name_list:
7941 : parameter_name
7942 : {
7943 74 : $$ = list_make1(makeString($1));
7944 : }
7945 : | parameter_name_list ',' parameter_name
7946 : {
7947 50 : $$ = lappend($1, makeString($3));
7948 : }
7949 : ;
7950 :
7951 : parameter_name:
7952 : ColId
7953 : {
7954 124 : $$ = $1;
7955 : }
7956 : | parameter_name '.' ColId
7957 : {
7958 30 : $$ = psprintf("%s.%s", $1, $3);
7959 : }
7960 : ;
7961 :
7962 :
7963 : /* Don't bother trying to fold the first two rules into one using
7964 : * opt_table. You're going to get conflicts.
7965 : */
7966 : privilege_target:
7967 : qualified_name_list
7968 : {
7969 11770 : PrivTarget *n = palloc_object(PrivTarget);
7970 :
7971 11770 : n->targtype = ACL_TARGET_OBJECT;
7972 11770 : n->objtype = OBJECT_TABLE;
7973 11770 : n->objs = $1;
7974 11770 : $$ = n;
7975 : }
7976 : | TABLE qualified_name_list
7977 : {
7978 392 : PrivTarget *n = palloc_object(PrivTarget);
7979 :
7980 392 : n->targtype = ACL_TARGET_OBJECT;
7981 392 : n->objtype = OBJECT_TABLE;
7982 392 : n->objs = $2;
7983 392 : $$ = n;
7984 : }
7985 : | SEQUENCE qualified_name_list
7986 : {
7987 22 : PrivTarget *n = palloc_object(PrivTarget);
7988 :
7989 22 : n->targtype = ACL_TARGET_OBJECT;
7990 22 : n->objtype = OBJECT_SEQUENCE;
7991 22 : n->objs = $2;
7992 22 : $$ = n;
7993 : }
7994 : | FOREIGN DATA_P WRAPPER name_list
7995 : {
7996 92 : PrivTarget *n = palloc_object(PrivTarget);
7997 :
7998 92 : n->targtype = ACL_TARGET_OBJECT;
7999 92 : n->objtype = OBJECT_FDW;
8000 92 : n->objs = $4;
8001 92 : $$ = n;
8002 : }
8003 : | FOREIGN SERVER name_list
8004 : {
8005 88 : PrivTarget *n = palloc_object(PrivTarget);
8006 :
8007 88 : n->targtype = ACL_TARGET_OBJECT;
8008 88 : n->objtype = OBJECT_FOREIGN_SERVER;
8009 88 : n->objs = $3;
8010 88 : $$ = n;
8011 : }
8012 : | FUNCTION function_with_argtypes_list
8013 : {
8014 9110 : PrivTarget *n = palloc_object(PrivTarget);
8015 :
8016 9110 : n->targtype = ACL_TARGET_OBJECT;
8017 9110 : n->objtype = OBJECT_FUNCTION;
8018 9110 : n->objs = $2;
8019 9110 : $$ = n;
8020 : }
8021 : | PROCEDURE function_with_argtypes_list
8022 : {
8023 42 : PrivTarget *n = palloc_object(PrivTarget);
8024 :
8025 42 : n->targtype = ACL_TARGET_OBJECT;
8026 42 : n->objtype = OBJECT_PROCEDURE;
8027 42 : n->objs = $2;
8028 42 : $$ = n;
8029 : }
8030 : | ROUTINE function_with_argtypes_list
8031 : {
8032 0 : PrivTarget *n = palloc_object(PrivTarget);
8033 :
8034 0 : n->targtype = ACL_TARGET_OBJECT;
8035 0 : n->objtype = OBJECT_ROUTINE;
8036 0 : n->objs = $2;
8037 0 : $$ = n;
8038 : }
8039 : | DATABASE name_list
8040 : {
8041 354 : PrivTarget *n = palloc_object(PrivTarget);
8042 :
8043 354 : n->targtype = ACL_TARGET_OBJECT;
8044 354 : n->objtype = OBJECT_DATABASE;
8045 354 : n->objs = $2;
8046 354 : $$ = n;
8047 : }
8048 : | DOMAIN_P any_name_list
8049 : {
8050 26 : PrivTarget *n = palloc_object(PrivTarget);
8051 :
8052 26 : n->targtype = ACL_TARGET_OBJECT;
8053 26 : n->objtype = OBJECT_DOMAIN;
8054 26 : n->objs = $2;
8055 26 : $$ = n;
8056 : }
8057 : | LANGUAGE name_list
8058 : {
8059 42 : PrivTarget *n = palloc_object(PrivTarget);
8060 :
8061 42 : n->targtype = ACL_TARGET_OBJECT;
8062 42 : n->objtype = OBJECT_LANGUAGE;
8063 42 : n->objs = $2;
8064 42 : $$ = n;
8065 : }
8066 : | LARGE_P OBJECT_P NumericOnly_list
8067 : {
8068 90 : PrivTarget *n = palloc_object(PrivTarget);
8069 :
8070 90 : n->targtype = ACL_TARGET_OBJECT;
8071 90 : n->objtype = OBJECT_LARGEOBJECT;
8072 90 : n->objs = $3;
8073 90 : $$ = n;
8074 : }
8075 : | PARAMETER parameter_name_list
8076 : {
8077 74 : PrivTarget *n = palloc_object(PrivTarget);
8078 74 : n->targtype = ACL_TARGET_OBJECT;
8079 74 : n->objtype = OBJECT_PARAMETER_ACL;
8080 74 : n->objs = $2;
8081 74 : $$ = n;
8082 : }
8083 : | SCHEMA name_list
8084 : {
8085 450 : PrivTarget *n = palloc_object(PrivTarget);
8086 :
8087 450 : n->targtype = ACL_TARGET_OBJECT;
8088 450 : n->objtype = OBJECT_SCHEMA;
8089 450 : n->objs = $2;
8090 450 : $$ = n;
8091 : }
8092 : | TABLESPACE name_list
8093 : {
8094 6 : PrivTarget *n = palloc_object(PrivTarget);
8095 :
8096 6 : n->targtype = ACL_TARGET_OBJECT;
8097 6 : n->objtype = OBJECT_TABLESPACE;
8098 6 : n->objs = $2;
8099 6 : $$ = n;
8100 : }
8101 : | TYPE_P any_name_list
8102 : {
8103 112 : PrivTarget *n = palloc_object(PrivTarget);
8104 :
8105 112 : n->targtype = ACL_TARGET_OBJECT;
8106 112 : n->objtype = OBJECT_TYPE;
8107 112 : n->objs = $2;
8108 112 : $$ = n;
8109 : }
8110 : | ALL TABLES IN_P SCHEMA name_list
8111 : {
8112 12 : PrivTarget *n = palloc_object(PrivTarget);
8113 :
8114 12 : n->targtype = ACL_TARGET_ALL_IN_SCHEMA;
8115 12 : n->objtype = OBJECT_TABLE;
8116 12 : n->objs = $5;
8117 12 : $$ = n;
8118 : }
8119 : | ALL SEQUENCES IN_P SCHEMA name_list
8120 : {
8121 0 : PrivTarget *n = palloc_object(PrivTarget);
8122 :
8123 0 : n->targtype = ACL_TARGET_ALL_IN_SCHEMA;
8124 0 : n->objtype = OBJECT_SEQUENCE;
8125 0 : n->objs = $5;
8126 0 : $$ = n;
8127 : }
8128 : | ALL FUNCTIONS IN_P SCHEMA name_list
8129 : {
8130 6 : PrivTarget *n = palloc_object(PrivTarget);
8131 :
8132 6 : n->targtype = ACL_TARGET_ALL_IN_SCHEMA;
8133 6 : n->objtype = OBJECT_FUNCTION;
8134 6 : n->objs = $5;
8135 6 : $$ = n;
8136 : }
8137 : | ALL PROCEDURES IN_P SCHEMA name_list
8138 : {
8139 6 : PrivTarget *n = palloc_object(PrivTarget);
8140 :
8141 6 : n->targtype = ACL_TARGET_ALL_IN_SCHEMA;
8142 6 : n->objtype = OBJECT_PROCEDURE;
8143 6 : n->objs = $5;
8144 6 : $$ = n;
8145 : }
8146 : | ALL ROUTINES IN_P SCHEMA name_list
8147 : {
8148 6 : PrivTarget *n = palloc_object(PrivTarget);
8149 :
8150 6 : n->targtype = ACL_TARGET_ALL_IN_SCHEMA;
8151 6 : n->objtype = OBJECT_ROUTINE;
8152 6 : n->objs = $5;
8153 6 : $$ = n;
8154 : }
8155 : ;
8156 :
8157 :
8158 : grantee_list:
8159 22894 : grantee { $$ = list_make1($1); }
8160 108 : | grantee_list ',' grantee { $$ = lappend($1, $3); }
8161 : ;
8162 :
8163 : grantee:
8164 22978 : RoleSpec { $$ = $1; }
8165 24 : | GROUP_P RoleSpec { $$ = $2; }
8166 : ;
8167 :
8168 :
8169 : opt_grant_grant_option:
8170 102 : WITH GRANT OPTION { $$ = true; }
8171 12048 : | /*EMPTY*/ { $$ = false; }
8172 : ;
8173 :
8174 : /*****************************************************************************
8175 : *
8176 : * GRANT and REVOKE ROLE statements
8177 : *
8178 : *****************************************************************************/
8179 :
8180 : GrantRoleStmt:
8181 : GRANT privilege_list TO role_list opt_granted_by
8182 : {
8183 586 : GrantRoleStmt *n = makeNode(GrantRoleStmt);
8184 :
8185 586 : n->is_grant = true;
8186 586 : n->granted_roles = $2;
8187 586 : n->grantee_roles = $4;
8188 586 : n->opt = NIL;
8189 586 : n->grantor = $5;
8190 586 : $$ = (Node *) n;
8191 : }
8192 : | GRANT privilege_list TO role_list WITH grant_role_opt_list opt_granted_by
8193 : {
8194 178 : GrantRoleStmt *n = makeNode(GrantRoleStmt);
8195 :
8196 178 : n->is_grant = true;
8197 178 : n->granted_roles = $2;
8198 178 : n->grantee_roles = $4;
8199 178 : n->opt = $6;
8200 178 : n->grantor = $7;
8201 178 : $$ = (Node *) n;
8202 : }
8203 : ;
8204 :
8205 : RevokeRoleStmt:
8206 : REVOKE privilege_list FROM role_list opt_granted_by opt_drop_behavior
8207 : {
8208 90 : GrantRoleStmt *n = makeNode(GrantRoleStmt);
8209 :
8210 90 : n->is_grant = false;
8211 90 : n->opt = NIL;
8212 90 : n->granted_roles = $2;
8213 90 : n->grantee_roles = $4;
8214 90 : n->grantor = $5;
8215 90 : n->behavior = $6;
8216 90 : $$ = (Node *) n;
8217 : }
8218 : | REVOKE ColId OPTION FOR privilege_list FROM role_list opt_granted_by opt_drop_behavior
8219 : {
8220 66 : GrantRoleStmt *n = makeNode(GrantRoleStmt);
8221 : DefElem *opt;
8222 :
8223 66 : opt = makeDefElem(pstrdup($2),
8224 66 : (Node *) makeBoolean(false), @2);
8225 66 : n->is_grant = false;
8226 66 : n->opt = list_make1(opt);
8227 66 : n->granted_roles = $5;
8228 66 : n->grantee_roles = $7;
8229 66 : n->grantor = $8;
8230 66 : n->behavior = $9;
8231 66 : $$ = (Node *) n;
8232 : }
8233 : ;
8234 :
8235 : grant_role_opt_list:
8236 120 : grant_role_opt_list ',' grant_role_opt { $$ = lappend($1, $3); }
8237 178 : | grant_role_opt { $$ = list_make1($1); }
8238 : ;
8239 :
8240 : grant_role_opt:
8241 : ColLabel grant_role_opt_value
8242 : {
8243 298 : $$ = makeDefElem(pstrdup($1), $2, @1);
8244 : }
8245 : ;
8246 :
8247 : grant_role_opt_value:
8248 72 : OPTION { $$ = (Node *) makeBoolean(true); }
8249 112 : | TRUE_P { $$ = (Node *) makeBoolean(true); }
8250 114 : | FALSE_P { $$ = (Node *) makeBoolean(false); }
8251 : ;
8252 :
8253 138 : opt_granted_by: GRANTED BY RoleSpec { $$ = $3; }
8254 23470 : | /*EMPTY*/ { $$ = NULL; }
8255 : ;
8256 :
8257 : /*****************************************************************************
8258 : *
8259 : * ALTER DEFAULT PRIVILEGES statement
8260 : *
8261 : *****************************************************************************/
8262 :
8263 : AlterDefaultPrivilegesStmt:
8264 : ALTER DEFAULT PRIVILEGES DefACLOptionList DefACLAction
8265 : {
8266 206 : AlterDefaultPrivilegesStmt *n = makeNode(AlterDefaultPrivilegesStmt);
8267 :
8268 206 : n->options = $4;
8269 206 : n->action = (GrantStmt *) $5;
8270 206 : $$ = (Node *) n;
8271 : }
8272 : ;
8273 :
8274 : DefACLOptionList:
8275 144 : DefACLOptionList DefACLOption { $$ = lappend($1, $2); }
8276 206 : | /* EMPTY */ { $$ = NIL; }
8277 : ;
8278 :
8279 : DefACLOption:
8280 : IN_P SCHEMA name_list
8281 : {
8282 60 : $$ = makeDefElem("schemas", (Node *) $3, @1);
8283 : }
8284 : | FOR ROLE role_list
8285 : {
8286 84 : $$ = makeDefElem("roles", (Node *) $3, @1);
8287 : }
8288 : | FOR USER role_list
8289 : {
8290 0 : $$ = makeDefElem("roles", (Node *) $3, @1);
8291 : }
8292 : ;
8293 :
8294 : /*
8295 : * This should match GRANT/REVOKE, except that individual target objects
8296 : * are not mentioned and we only allow a subset of object types.
8297 : */
8298 : DefACLAction:
8299 : GRANT privileges ON defacl_privilege_target TO grantee_list
8300 : opt_grant_grant_option
8301 : {
8302 124 : GrantStmt *n = makeNode(GrantStmt);
8303 :
8304 124 : n->is_grant = true;
8305 124 : n->privileges = $2;
8306 124 : n->targtype = ACL_TARGET_DEFAULTS;
8307 124 : n->objtype = $4;
8308 124 : n->objects = NIL;
8309 124 : n->grantees = $6;
8310 124 : n->grant_option = $7;
8311 124 : $$ = (Node *) n;
8312 : }
8313 : | REVOKE privileges ON defacl_privilege_target
8314 : FROM grantee_list opt_drop_behavior
8315 : {
8316 82 : GrantStmt *n = makeNode(GrantStmt);
8317 :
8318 82 : n->is_grant = false;
8319 82 : n->grant_option = false;
8320 82 : n->privileges = $2;
8321 82 : n->targtype = ACL_TARGET_DEFAULTS;
8322 82 : n->objtype = $4;
8323 82 : n->objects = NIL;
8324 82 : n->grantees = $6;
8325 82 : n->behavior = $7;
8326 82 : $$ = (Node *) n;
8327 : }
8328 : | REVOKE GRANT OPTION FOR privileges ON defacl_privilege_target
8329 : FROM grantee_list opt_drop_behavior
8330 : {
8331 0 : GrantStmt *n = makeNode(GrantStmt);
8332 :
8333 0 : n->is_grant = false;
8334 0 : n->grant_option = true;
8335 0 : n->privileges = $5;
8336 0 : n->targtype = ACL_TARGET_DEFAULTS;
8337 0 : n->objtype = $7;
8338 0 : n->objects = NIL;
8339 0 : n->grantees = $9;
8340 0 : n->behavior = $10;
8341 0 : $$ = (Node *) n;
8342 : }
8343 : ;
8344 :
8345 : defacl_privilege_target:
8346 78 : TABLES { $$ = OBJECT_TABLE; }
8347 16 : | FUNCTIONS { $$ = OBJECT_FUNCTION; }
8348 6 : | ROUTINES { $$ = OBJECT_FUNCTION; }
8349 6 : | SEQUENCES { $$ = OBJECT_SEQUENCE; }
8350 34 : | TYPES_P { $$ = OBJECT_TYPE; }
8351 36 : | SCHEMAS { $$ = OBJECT_SCHEMA; }
8352 30 : | LARGE_P OBJECTS_P { $$ = OBJECT_LARGEOBJECT; }
8353 : ;
8354 :
8355 :
8356 : /*****************************************************************************
8357 : *
8358 : * QUERY: CREATE INDEX
8359 : *
8360 : * Note: we cannot put TABLESPACE clause after WHERE clause unless we are
8361 : * willing to make TABLESPACE a fully reserved word.
8362 : *****************************************************************************/
8363 :
8364 : IndexStmt: CREATE opt_unique INDEX opt_concurrently opt_single_name
8365 : ON relation_expr access_method_clause '(' index_params ')'
8366 : opt_include opt_unique_null_treatment opt_reloptions OptTableSpace where_clause
8367 : {
8368 6768 : IndexStmt *n = makeNode(IndexStmt);
8369 :
8370 6768 : n->unique = $2;
8371 6768 : n->concurrent = $4;
8372 6768 : n->idxname = $5;
8373 6768 : n->relation = $7;
8374 6768 : n->accessMethod = $8;
8375 6768 : n->indexParams = $10;
8376 6768 : n->indexIncludingParams = $12;
8377 6768 : n->nulls_not_distinct = !$13;
8378 6768 : n->options = $14;
8379 6768 : n->tableSpace = $15;
8380 6768 : n->whereClause = $16;
8381 6768 : n->excludeOpNames = NIL;
8382 6768 : n->idxcomment = NULL;
8383 6768 : n->indexOid = InvalidOid;
8384 6768 : n->oldNumber = InvalidRelFileNumber;
8385 6768 : n->oldCreateSubid = InvalidSubTransactionId;
8386 6768 : n->oldFirstRelfilelocatorSubid = InvalidSubTransactionId;
8387 6768 : n->primary = false;
8388 6768 : n->isconstraint = false;
8389 6768 : n->deferrable = false;
8390 6768 : n->initdeferred = false;
8391 6768 : n->transformed = false;
8392 6768 : n->if_not_exists = false;
8393 6768 : n->reset_default_tblspc = false;
8394 6768 : $$ = (Node *) n;
8395 : }
8396 : | CREATE opt_unique INDEX opt_concurrently IF_P NOT EXISTS name
8397 : ON relation_expr access_method_clause '(' index_params ')'
8398 : opt_include opt_unique_null_treatment opt_reloptions OptTableSpace where_clause
8399 : {
8400 18 : IndexStmt *n = makeNode(IndexStmt);
8401 :
8402 18 : n->unique = $2;
8403 18 : n->concurrent = $4;
8404 18 : n->idxname = $8;
8405 18 : n->relation = $10;
8406 18 : n->accessMethod = $11;
8407 18 : n->indexParams = $13;
8408 18 : n->indexIncludingParams = $15;
8409 18 : n->nulls_not_distinct = !$16;
8410 18 : n->options = $17;
8411 18 : n->tableSpace = $18;
8412 18 : n->whereClause = $19;
8413 18 : n->excludeOpNames = NIL;
8414 18 : n->idxcomment = NULL;
8415 18 : n->indexOid = InvalidOid;
8416 18 : n->oldNumber = InvalidRelFileNumber;
8417 18 : n->oldCreateSubid = InvalidSubTransactionId;
8418 18 : n->oldFirstRelfilelocatorSubid = InvalidSubTransactionId;
8419 18 : n->primary = false;
8420 18 : n->isconstraint = false;
8421 18 : n->deferrable = false;
8422 18 : n->initdeferred = false;
8423 18 : n->transformed = false;
8424 18 : n->if_not_exists = true;
8425 18 : n->reset_default_tblspc = false;
8426 18 : $$ = (Node *) n;
8427 : }
8428 : ;
8429 :
8430 : opt_unique:
8431 1302 : UNIQUE { $$ = true; }
8432 5490 : | /*EMPTY*/ { $$ = false; }
8433 : ;
8434 :
8435 : access_method_clause:
8436 3068 : USING name { $$ = $2; }
8437 3952 : | /*EMPTY*/ { $$ = DEFAULT_INDEX_TYPE; }
8438 : ;
8439 :
8440 8286 : index_params: index_elem { $$ = list_make1($1); }
8441 2164 : | index_params ',' index_elem { $$ = lappend($1, $3); }
8442 : ;
8443 :
8444 :
8445 : index_elem_options:
8446 : opt_collate opt_qualified_name opt_asc_desc opt_nulls_order
8447 : {
8448 11026 : $$ = makeNode(IndexElem);
8449 11026 : $$->name = NULL;
8450 11026 : $$->expr = NULL;
8451 11026 : $$->indexcolname = NULL;
8452 11026 : $$->collation = $1;
8453 11026 : $$->opclass = $2;
8454 11026 : $$->opclassopts = NIL;
8455 11026 : $$->ordering = $3;
8456 11026 : $$->nulls_ordering = $4;
8457 : }
8458 : | opt_collate any_name reloptions opt_asc_desc opt_nulls_order
8459 : {
8460 148 : $$ = makeNode(IndexElem);
8461 148 : $$->name = NULL;
8462 148 : $$->expr = NULL;
8463 148 : $$->indexcolname = NULL;
8464 148 : $$->collation = $1;
8465 148 : $$->opclass = $2;
8466 148 : $$->opclassopts = $3;
8467 148 : $$->ordering = $4;
8468 148 : $$->nulls_ordering = $5;
8469 : }
8470 : ;
8471 :
8472 : /*
8473 : * Index attributes can be either simple column references, or arbitrary
8474 : * expressions in parens. For backwards-compatibility reasons, we allow
8475 : * an expression that's just a function call to be written without parens.
8476 : */
8477 : index_elem: ColId index_elem_options
8478 : {
8479 10034 : $$ = $2;
8480 10034 : $$->name = $1;
8481 : }
8482 : | func_expr_windowless index_elem_options
8483 : {
8484 618 : $$ = $2;
8485 618 : $$->expr = $1;
8486 : }
8487 : | '(' a_expr ')' index_elem_options
8488 : {
8489 522 : $$ = $4;
8490 522 : $$->expr = $2;
8491 : }
8492 : ;
8493 :
8494 218 : opt_include: INCLUDE '(' index_including_params ')' { $$ = $3; }
8495 6568 : | /* EMPTY */ { $$ = NIL; }
8496 : ;
8497 :
8498 218 : index_including_params: index_elem { $$ = list_make1($1); }
8499 166 : | index_including_params ',' index_elem { $$ = lappend($1, $3); }
8500 : ;
8501 :
8502 192 : opt_collate: COLLATE any_name { $$ = $2; }
8503 17066 : | /*EMPTY*/ { $$ = NIL; }
8504 : ;
8505 :
8506 :
8507 1844 : opt_asc_desc: ASC { $$ = SORTBY_ASC; }
8508 3672 : | DESC { $$ = SORTBY_DESC; }
8509 115564 : | /*EMPTY*/ { $$ = SORTBY_DEFAULT; }
8510 : ;
8511 :
8512 342 : opt_nulls_order: NULLS_LA FIRST_P { $$ = SORTBY_NULLS_FIRST; }
8513 1754 : | NULLS_LA LAST_P { $$ = SORTBY_NULLS_LAST; }
8514 119204 : | /*EMPTY*/ { $$ = SORTBY_NULLS_DEFAULT; }
8515 : ;
8516 :
8517 :
8518 : /*****************************************************************************
8519 : *
8520 : * QUERY:
8521 : * create [or replace] function <fname>
8522 : * [(<type-1> { , <type-n>})]
8523 : * returns <type-r>
8524 : * as <filename or code in language as appropriate>
8525 : * language <lang> [with parameters]
8526 : *
8527 : *****************************************************************************/
8528 :
8529 : CreateFunctionStmt:
8530 : CREATE opt_or_replace FUNCTION func_name func_args_with_defaults
8531 : RETURNS func_return opt_createfunc_opt_list opt_routine_body
8532 : {
8533 24884 : CreateFunctionStmt *n = makeNode(CreateFunctionStmt);
8534 :
8535 24884 : n->is_procedure = false;
8536 24884 : n->replace = $2;
8537 24884 : n->funcname = $4;
8538 24884 : n->parameters = $5;
8539 24884 : n->returnType = $7;
8540 24884 : n->options = $8;
8541 24884 : n->sql_body = $9;
8542 24884 : $$ = (Node *) n;
8543 : }
8544 : | CREATE opt_or_replace FUNCTION func_name func_args_with_defaults
8545 : RETURNS TABLE '(' table_func_column_list ')' opt_createfunc_opt_list opt_routine_body
8546 : {
8547 194 : CreateFunctionStmt *n = makeNode(CreateFunctionStmt);
8548 :
8549 194 : n->is_procedure = false;
8550 194 : n->replace = $2;
8551 194 : n->funcname = $4;
8552 194 : n->parameters = mergeTableFuncParameters($5, $9, yyscanner);
8553 194 : n->returnType = TableFuncTypeName($9);
8554 194 : n->returnType->location = @7;
8555 194 : n->options = $11;
8556 194 : n->sql_body = $12;
8557 194 : $$ = (Node *) n;
8558 : }
8559 : | CREATE opt_or_replace FUNCTION func_name func_args_with_defaults
8560 : opt_createfunc_opt_list opt_routine_body
8561 : {
8562 494 : CreateFunctionStmt *n = makeNode(CreateFunctionStmt);
8563 :
8564 494 : n->is_procedure = false;
8565 494 : n->replace = $2;
8566 494 : n->funcname = $4;
8567 494 : n->parameters = $5;
8568 494 : n->returnType = NULL;
8569 494 : n->options = $6;
8570 494 : n->sql_body = $7;
8571 494 : $$ = (Node *) n;
8572 : }
8573 : | CREATE opt_or_replace PROCEDURE func_name func_args_with_defaults
8574 : opt_createfunc_opt_list opt_routine_body
8575 : {
8576 370 : CreateFunctionStmt *n = makeNode(CreateFunctionStmt);
8577 :
8578 370 : n->is_procedure = true;
8579 370 : n->replace = $2;
8580 370 : n->funcname = $4;
8581 370 : n->parameters = $5;
8582 370 : n->returnType = NULL;
8583 370 : n->options = $6;
8584 370 : n->sql_body = $7;
8585 370 : $$ = (Node *) n;
8586 : }
8587 : ;
8588 :
8589 : opt_or_replace:
8590 10314 : OR REPLACE { $$ = true; }
8591 21158 : | /*EMPTY*/ { $$ = false; }
8592 : ;
8593 :
8594 12226 : func_args: '(' func_args_list ')' { $$ = $2; }
8595 6024 : | '(' ')' { $$ = NIL; }
8596 : ;
8597 :
8598 : func_args_list:
8599 12226 : func_arg { $$ = list_make1($1); }
8600 11476 : | func_args_list ',' func_arg { $$ = lappend($1, $3); }
8601 : ;
8602 :
8603 : function_with_argtypes_list:
8604 12998 : function_with_argtypes { $$ = list_make1($1); }
8605 : | function_with_argtypes_list ',' function_with_argtypes
8606 84 : { $$ = lappend($1, $3); }
8607 : ;
8608 :
8609 : function_with_argtypes:
8610 : func_name func_args
8611 : {
8612 18250 : ObjectWithArgs *n = makeNode(ObjectWithArgs);
8613 :
8614 18250 : n->objname = $1;
8615 18250 : n->objargs = extractArgTypes($2);
8616 18250 : n->objfuncargs = $2;
8617 18250 : $$ = n;
8618 : }
8619 : /*
8620 : * Because of reduce/reduce conflicts, we can't use func_name
8621 : * below, but we can write it out the long way, which actually
8622 : * allows more cases.
8623 : */
8624 : | type_func_name_keyword
8625 : {
8626 0 : ObjectWithArgs *n = makeNode(ObjectWithArgs);
8627 :
8628 0 : n->objname = list_make1(makeString(pstrdup($1)));
8629 0 : n->args_unspecified = true;
8630 0 : $$ = n;
8631 : }
8632 : | ColId
8633 : {
8634 422 : ObjectWithArgs *n = makeNode(ObjectWithArgs);
8635 :
8636 422 : n->objname = list_make1(makeString($1));
8637 422 : n->args_unspecified = true;
8638 422 : $$ = n;
8639 : }
8640 : | ColId indirection
8641 : {
8642 28 : ObjectWithArgs *n = makeNode(ObjectWithArgs);
8643 :
8644 28 : n->objname = check_func_name(lcons(makeString($1), $2),
8645 : yyscanner);
8646 28 : n->args_unspecified = true;
8647 28 : $$ = n;
8648 : }
8649 : ;
8650 :
8651 : /*
8652 : * func_args_with_defaults is separate because we only want to accept
8653 : * defaults in CREATE FUNCTION, not in ALTER etc.
8654 : */
8655 : func_args_with_defaults:
8656 21376 : '(' func_args_with_defaults_list ')' { $$ = $2; }
8657 4566 : | '(' ')' { $$ = NIL; }
8658 : ;
8659 :
8660 : func_args_with_defaults_list:
8661 21376 : func_arg_with_default { $$ = list_make1($1); }
8662 : | func_args_with_defaults_list ',' func_arg_with_default
8663 36376 : { $$ = lappend($1, $3); }
8664 : ;
8665 :
8666 : /*
8667 : * The style with arg_class first is SQL99 standard, but Oracle puts
8668 : * param_name first; accept both since it's likely people will try both
8669 : * anyway. Don't bother trying to save productions by letting arg_class
8670 : * have an empty alternative ... you'll get shift/reduce conflicts.
8671 : *
8672 : * We can catch over-specified arguments here if we want to,
8673 : * but for now better to silently swallow typmod, etc.
8674 : * - thomas 2000-03-22
8675 : */
8676 : func_arg:
8677 : arg_class param_name func_type
8678 : {
8679 17124 : FunctionParameter *n = makeNode(FunctionParameter);
8680 :
8681 17124 : n->name = $2;
8682 17124 : n->argType = $3;
8683 17124 : n->mode = $1;
8684 17124 : n->defexpr = NULL;
8685 17124 : n->location = @1;
8686 17124 : $$ = n;
8687 : }
8688 : | param_name arg_class func_type
8689 : {
8690 420 : FunctionParameter *n = makeNode(FunctionParameter);
8691 :
8692 420 : n->name = $1;
8693 420 : n->argType = $3;
8694 420 : n->mode = $2;
8695 420 : n->defexpr = NULL;
8696 420 : n->location = @1;
8697 420 : $$ = n;
8698 : }
8699 : | param_name func_type
8700 : {
8701 16168 : FunctionParameter *n = makeNode(FunctionParameter);
8702 :
8703 16168 : n->name = $1;
8704 16168 : n->argType = $2;
8705 16168 : n->mode = FUNC_PARAM_DEFAULT;
8706 16168 : n->defexpr = NULL;
8707 16168 : n->location = @1;
8708 16168 : $$ = n;
8709 : }
8710 : | arg_class func_type
8711 : {
8712 334 : FunctionParameter *n = makeNode(FunctionParameter);
8713 :
8714 334 : n->name = NULL;
8715 334 : n->argType = $2;
8716 334 : n->mode = $1;
8717 334 : n->defexpr = NULL;
8718 334 : n->location = @1;
8719 334 : $$ = n;
8720 : }
8721 : | func_type
8722 : {
8723 48308 : FunctionParameter *n = makeNode(FunctionParameter);
8724 :
8725 48308 : n->name = NULL;
8726 48308 : n->argType = $1;
8727 48308 : n->mode = FUNC_PARAM_DEFAULT;
8728 48308 : n->defexpr = NULL;
8729 48308 : n->location = @1;
8730 48308 : $$ = n;
8731 : }
8732 : ;
8733 :
8734 : /* INOUT is SQL99 standard, IN OUT is for Oracle compatibility */
8735 4366 : arg_class: IN_P { $$ = FUNC_PARAM_IN; }
8736 12726 : | OUT_P { $$ = FUNC_PARAM_OUT; }
8737 200 : | INOUT { $$ = FUNC_PARAM_INOUT; }
8738 0 : | IN_P OUT_P { $$ = FUNC_PARAM_INOUT; }
8739 586 : | VARIADIC { $$ = FUNC_PARAM_VARIADIC; }
8740 : ;
8741 :
8742 : /*
8743 : * Ideally param_name should be ColId, but that causes too many conflicts.
8744 : */
8745 : param_name: type_function_name
8746 : ;
8747 :
8748 : func_return:
8749 : func_type
8750 : {
8751 : /* We can catch over-specified results here if we want to,
8752 : * but for now better to silently swallow typmod, etc.
8753 : * - thomas 2000-03-22
8754 : */
8755 24884 : $$ = $1;
8756 : }
8757 : ;
8758 :
8759 : /*
8760 : * We would like to make the %TYPE productions here be ColId attrs etc,
8761 : * but that causes reduce/reduce conflicts. type_function_name
8762 : * is next best choice.
8763 : */
8764 128584 : func_type: Typename { $$ = $1; }
8765 : | type_function_name attrs '%' TYPE_P
8766 : {
8767 18 : $$ = makeTypeNameFromNameList(lcons(makeString($1), $2));
8768 18 : $$->pct_type = true;
8769 18 : $$->location = @1;
8770 : }
8771 : | SETOF type_function_name attrs '%' TYPE_P
8772 : {
8773 6 : $$ = makeTypeNameFromNameList(lcons(makeString($2), $3));
8774 6 : $$->pct_type = true;
8775 6 : $$->setof = true;
8776 6 : $$->location = @2;
8777 : }
8778 : ;
8779 :
8780 : func_arg_with_default:
8781 : func_arg
8782 : {
8783 51084 : $$ = $1;
8784 : }
8785 : | func_arg DEFAULT a_expr
8786 : {
8787 6472 : $$ = $1;
8788 6472 : $$->defexpr = $3;
8789 : }
8790 : | func_arg '=' a_expr
8791 : {
8792 196 : $$ = $1;
8793 196 : $$->defexpr = $3;
8794 : }
8795 : ;
8796 :
8797 : /* Aggregate args can be most things that function args can be */
8798 : aggr_arg: func_arg
8799 : {
8800 900 : if (!($1->mode == FUNC_PARAM_DEFAULT ||
8801 60 : $1->mode == FUNC_PARAM_IN ||
8802 60 : $1->mode == FUNC_PARAM_VARIADIC))
8803 0 : ereport(ERROR,
8804 : (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
8805 : errmsg("aggregates cannot have output arguments"),
8806 : parser_errposition(@1)));
8807 900 : $$ = $1;
8808 : }
8809 : ;
8810 :
8811 : /*
8812 : * The SQL standard offers no guidance on how to declare aggregate argument
8813 : * lists, since it doesn't have CREATE AGGREGATE etc. We accept these cases:
8814 : *
8815 : * (*) - normal agg with no args
8816 : * (aggr_arg,...) - normal agg with args
8817 : * (ORDER BY aggr_arg,...) - ordered-set agg with no direct args
8818 : * (aggr_arg,... ORDER BY aggr_arg,...) - ordered-set agg with direct args
8819 : *
8820 : * The zero-argument case is spelled with '*' for consistency with COUNT(*).
8821 : *
8822 : * An additional restriction is that if the direct-args list ends in a
8823 : * VARIADIC item, the ordered-args list must contain exactly one item that
8824 : * is also VARIADIC with the same type. This allows us to collapse the two
8825 : * VARIADIC items into one, which is necessary to represent the aggregate in
8826 : * pg_proc. We check this at the grammar stage so that we can return a list
8827 : * in which the second VARIADIC item is already discarded, avoiding extra work
8828 : * in cases such as DROP AGGREGATE.
8829 : *
8830 : * The return value of this production is a two-element list, in which the
8831 : * first item is a sublist of FunctionParameter nodes (with any duplicate
8832 : * VARIADIC item already dropped, as per above) and the second is an Integer
8833 : * node, containing -1 if there was no ORDER BY and otherwise the number
8834 : * of argument declarations before the ORDER BY. (If this number is equal
8835 : * to the first sublist's length, then we dropped a duplicate VARIADIC item.)
8836 : * This representation is passed as-is to CREATE AGGREGATE; for operations
8837 : * on existing aggregates, we can just apply extractArgTypes to the first
8838 : * sublist.
8839 : */
8840 : aggr_args: '(' '*' ')'
8841 : {
8842 136 : $$ = list_make2(NIL, makeInteger(-1));
8843 : }
8844 : | '(' aggr_args_list ')'
8845 : {
8846 732 : $$ = list_make2($2, makeInteger(-1));
8847 : }
8848 : | '(' ORDER BY aggr_args_list ')'
8849 : {
8850 6 : $$ = list_make2($4, makeInteger(0));
8851 : }
8852 : | '(' aggr_args_list ORDER BY aggr_args_list ')'
8853 : {
8854 : /* this is the only case requiring consistency checking */
8855 32 : $$ = makeOrderedSetArgs($2, $5, yyscanner);
8856 : }
8857 : ;
8858 :
8859 : aggr_args_list:
8860 802 : aggr_arg { $$ = list_make1($1); }
8861 98 : | aggr_args_list ',' aggr_arg { $$ = lappend($1, $3); }
8862 : ;
8863 :
8864 : aggregate_with_argtypes:
8865 : func_name aggr_args
8866 : {
8867 362 : ObjectWithArgs *n = makeNode(ObjectWithArgs);
8868 :
8869 362 : n->objname = $1;
8870 362 : n->objargs = extractAggrArgTypes($2);
8871 362 : n->objfuncargs = (List *) linitial($2);
8872 362 : $$ = n;
8873 : }
8874 : ;
8875 :
8876 : aggregate_with_argtypes_list:
8877 104 : aggregate_with_argtypes { $$ = list_make1($1); }
8878 : | aggregate_with_argtypes_list ',' aggregate_with_argtypes
8879 0 : { $$ = lappend($1, $3); }
8880 : ;
8881 :
8882 : opt_createfunc_opt_list:
8883 : createfunc_opt_list
8884 60 : | /*EMPTY*/ { $$ = NIL; }
8885 : ;
8886 :
8887 : createfunc_opt_list:
8888 : /* Must be at least one to prevent conflict */
8889 25882 : createfunc_opt_item { $$ = list_make1($1); }
8890 68896 : | createfunc_opt_list createfunc_opt_item { $$ = lappend($1, $2); }
8891 : ;
8892 :
8893 : /*
8894 : * Options common to both CREATE FUNCTION and ALTER FUNCTION
8895 : */
8896 : common_func_opt_item:
8897 : CALLED ON NULL_P INPUT_P
8898 : {
8899 394 : $$ = makeDefElem("strict", (Node *) makeBoolean(false), @1);
8900 : }
8901 : | RETURNS NULL_P ON NULL_P INPUT_P
8902 : {
8903 902 : $$ = makeDefElem("strict", (Node *) makeBoolean(true), @1);
8904 : }
8905 : | STRICT_P
8906 : {
8907 13920 : $$ = makeDefElem("strict", (Node *) makeBoolean(true), @1);
8908 : }
8909 : | IMMUTABLE
8910 : {
8911 10312 : $$ = makeDefElem("volatility", (Node *) makeString("immutable"), @1);
8912 : }
8913 : | STABLE
8914 : {
8915 2576 : $$ = makeDefElem("volatility", (Node *) makeString("stable"), @1);
8916 : }
8917 : | VOLATILE
8918 : {
8919 1894 : $$ = makeDefElem("volatility", (Node *) makeString("volatile"), @1);
8920 : }
8921 : | EXTERNAL SECURITY DEFINER
8922 : {
8923 0 : $$ = makeDefElem("security", (Node *) makeBoolean(true), @1);
8924 : }
8925 : | EXTERNAL SECURITY INVOKER
8926 : {
8927 0 : $$ = makeDefElem("security", (Node *) makeBoolean(false), @1);
8928 : }
8929 : | SECURITY DEFINER
8930 : {
8931 58 : $$ = makeDefElem("security", (Node *) makeBoolean(true), @1);
8932 : }
8933 : | SECURITY INVOKER
8934 : {
8935 18 : $$ = makeDefElem("security", (Node *) makeBoolean(false), @1);
8936 : }
8937 : | LEAKPROOF
8938 : {
8939 46 : $$ = makeDefElem("leakproof", (Node *) makeBoolean(true), @1);
8940 : }
8941 : | NOT LEAKPROOF
8942 : {
8943 12 : $$ = makeDefElem("leakproof", (Node *) makeBoolean(false), @1);
8944 : }
8945 : | COST NumericOnly
8946 : {
8947 4450 : $$ = makeDefElem("cost", (Node *) $2, @1);
8948 : }
8949 : | ROWS NumericOnly
8950 : {
8951 612 : $$ = makeDefElem("rows", (Node *) $2, @1);
8952 : }
8953 : | SUPPORT any_name
8954 : {
8955 122 : $$ = makeDefElem("support", (Node *) $2, @1);
8956 : }
8957 : | FunctionSetResetClause
8958 : {
8959 : /* we abuse the normal content of a DefElem here */
8960 154 : $$ = makeDefElem("set", (Node *) $1, @1);
8961 : }
8962 : | PARALLEL ColId
8963 : {
8964 14558 : $$ = makeDefElem("parallel", (Node *) makeString($2), @1);
8965 : }
8966 : ;
8967 :
8968 : createfunc_opt_item:
8969 : AS func_as
8970 : {
8971 20150 : $$ = makeDefElem("as", (Node *) $2, @1);
8972 : }
8973 : | LANGUAGE NonReservedWord_or_Sconst
8974 : {
8975 25862 : $$ = makeDefElem("language", (Node *) makeString($2), @1);
8976 : }
8977 : | TRANSFORM transform_type_list
8978 : {
8979 118 : $$ = makeDefElem("transform", (Node *) $2, @1);
8980 : }
8981 : | WINDOW
8982 : {
8983 20 : $$ = makeDefElem("window", (Node *) makeBoolean(true), @1);
8984 : }
8985 : | common_func_opt_item
8986 : {
8987 48628 : $$ = $1;
8988 : }
8989 : ;
8990 :
8991 16844 : func_as: Sconst { $$ = list_make1(makeString($1)); }
8992 : | Sconst ',' Sconst
8993 : {
8994 3306 : $$ = list_make2(makeString($1), makeString($3));
8995 : }
8996 : ;
8997 :
8998 : ReturnStmt: RETURN a_expr
8999 : {
9000 4982 : ReturnStmt *r = makeNode(ReturnStmt);
9001 :
9002 4982 : r->returnval = (Node *) $2;
9003 4982 : $$ = (Node *) r;
9004 : }
9005 : ;
9006 :
9007 : opt_routine_body:
9008 : ReturnStmt
9009 : {
9010 4976 : $$ = $1;
9011 : }
9012 : | BEGIN_P ATOMIC routine_body_stmt_list END_P
9013 : {
9014 : /*
9015 : * A compound statement is stored as a single-item list
9016 : * containing the list of statements as its member. That
9017 : * way, the parse analysis code can tell apart an empty
9018 : * body from no body at all.
9019 : */
9020 822 : $$ = (Node *) list_make1($3);
9021 : }
9022 : | /*EMPTY*/
9023 : {
9024 20144 : $$ = NULL;
9025 : }
9026 : ;
9027 :
9028 : routine_body_stmt_list:
9029 : routine_body_stmt_list routine_body_stmt ';'
9030 : {
9031 : /* As in stmtmulti, discard empty statements */
9032 838 : if ($2 != NULL)
9033 820 : $$ = lappend($1, $2);
9034 : else
9035 18 : $$ = $1;
9036 : }
9037 : | /*EMPTY*/
9038 : {
9039 822 : $$ = NIL;
9040 : }
9041 : ;
9042 :
9043 : routine_body_stmt:
9044 : stmt
9045 : | ReturnStmt
9046 : ;
9047 :
9048 : transform_type_list:
9049 118 : FOR TYPE_P Typename { $$ = list_make1($3); }
9050 4 : | transform_type_list ',' FOR TYPE_P Typename { $$ = lappend($1, $5); }
9051 : ;
9052 :
9053 : opt_definition:
9054 674 : WITH definition { $$ = $2; }
9055 10420 : | /*EMPTY*/ { $$ = NIL; }
9056 : ;
9057 :
9058 : table_func_column: param_name func_type
9059 : {
9060 454 : FunctionParameter *n = makeNode(FunctionParameter);
9061 :
9062 454 : n->name = $1;
9063 454 : n->argType = $2;
9064 454 : n->mode = FUNC_PARAM_TABLE;
9065 454 : n->defexpr = NULL;
9066 454 : n->location = @1;
9067 454 : $$ = n;
9068 : }
9069 : ;
9070 :
9071 : table_func_column_list:
9072 : table_func_column
9073 : {
9074 194 : $$ = list_make1($1);
9075 : }
9076 : | table_func_column_list ',' table_func_column
9077 : {
9078 260 : $$ = lappend($1, $3);
9079 : }
9080 : ;
9081 :
9082 : /*****************************************************************************
9083 : * ALTER FUNCTION / ALTER PROCEDURE / ALTER ROUTINE
9084 : *
9085 : * RENAME and OWNER subcommands are already provided by the generic
9086 : * ALTER infrastructure, here we just specify alterations that can
9087 : * only be applied to functions.
9088 : *
9089 : *****************************************************************************/
9090 : AlterFunctionStmt:
9091 : ALTER FUNCTION function_with_argtypes alterfunc_opt_list opt_restrict
9092 : {
9093 1378 : AlterFunctionStmt *n = makeNode(AlterFunctionStmt);
9094 :
9095 1378 : n->objtype = OBJECT_FUNCTION;
9096 1378 : n->func = $3;
9097 1378 : n->actions = $4;
9098 1378 : $$ = (Node *) n;
9099 : }
9100 : | ALTER PROCEDURE function_with_argtypes alterfunc_opt_list opt_restrict
9101 : {
9102 18 : AlterFunctionStmt *n = makeNode(AlterFunctionStmt);
9103 :
9104 18 : n->objtype = OBJECT_PROCEDURE;
9105 18 : n->func = $3;
9106 18 : n->actions = $4;
9107 18 : $$ = (Node *) n;
9108 : }
9109 : | ALTER ROUTINE function_with_argtypes alterfunc_opt_list opt_restrict
9110 : {
9111 0 : AlterFunctionStmt *n = makeNode(AlterFunctionStmt);
9112 :
9113 0 : n->objtype = OBJECT_ROUTINE;
9114 0 : n->func = $3;
9115 0 : n->actions = $4;
9116 0 : $$ = (Node *) n;
9117 : }
9118 : ;
9119 :
9120 : alterfunc_opt_list:
9121 : /* At least one option must be specified */
9122 1396 : common_func_opt_item { $$ = list_make1($1); }
9123 4 : | alterfunc_opt_list common_func_opt_item { $$ = lappend($1, $2); }
9124 : ;
9125 :
9126 : /* Ignored, merely for SQL compliance */
9127 : opt_restrict:
9128 : RESTRICT
9129 : | /* EMPTY */
9130 : ;
9131 :
9132 :
9133 : /*****************************************************************************
9134 : *
9135 : * QUERY:
9136 : *
9137 : * DROP FUNCTION funcname (arg1, arg2, ...) [ RESTRICT | CASCADE ]
9138 : * DROP PROCEDURE procname (arg1, arg2, ...) [ RESTRICT | CASCADE ]
9139 : * DROP ROUTINE routname (arg1, arg2, ...) [ RESTRICT | CASCADE ]
9140 : * DROP AGGREGATE aggname (arg1, ...) [ RESTRICT | CASCADE ]
9141 : * DROP OPERATOR opname (leftoperand_typ, rightoperand_typ) [ RESTRICT | CASCADE ]
9142 : *
9143 : *****************************************************************************/
9144 :
9145 : RemoveFuncStmt:
9146 : DROP FUNCTION function_with_argtypes_list opt_drop_behavior
9147 : {
9148 3422 : DropStmt *n = makeNode(DropStmt);
9149 :
9150 3422 : n->removeType = OBJECT_FUNCTION;
9151 3422 : n->objects = $3;
9152 3422 : n->behavior = $4;
9153 3422 : n->missing_ok = false;
9154 3422 : n->concurrent = false;
9155 3422 : $$ = (Node *) n;
9156 : }
9157 : | DROP FUNCTION IF_P EXISTS function_with_argtypes_list opt_drop_behavior
9158 : {
9159 260 : DropStmt *n = makeNode(DropStmt);
9160 :
9161 260 : n->removeType = OBJECT_FUNCTION;
9162 260 : n->objects = $5;
9163 260 : n->behavior = $6;
9164 260 : n->missing_ok = true;
9165 260 : n->concurrent = false;
9166 260 : $$ = (Node *) n;
9167 : }
9168 : | DROP PROCEDURE function_with_argtypes_list opt_drop_behavior
9169 : {
9170 140 : DropStmt *n = makeNode(DropStmt);
9171 :
9172 140 : n->removeType = OBJECT_PROCEDURE;
9173 140 : n->objects = $3;
9174 140 : n->behavior = $4;
9175 140 : n->missing_ok = false;
9176 140 : n->concurrent = false;
9177 140 : $$ = (Node *) n;
9178 : }
9179 : | DROP PROCEDURE IF_P EXISTS function_with_argtypes_list opt_drop_behavior
9180 : {
9181 6 : DropStmt *n = makeNode(DropStmt);
9182 :
9183 6 : n->removeType = OBJECT_PROCEDURE;
9184 6 : n->objects = $5;
9185 6 : n->behavior = $6;
9186 6 : n->missing_ok = true;
9187 6 : n->concurrent = false;
9188 6 : $$ = (Node *) n;
9189 : }
9190 : | DROP ROUTINE function_with_argtypes_list opt_drop_behavior
9191 : {
9192 12 : DropStmt *n = makeNode(DropStmt);
9193 :
9194 12 : n->removeType = OBJECT_ROUTINE;
9195 12 : n->objects = $3;
9196 12 : n->behavior = $4;
9197 12 : n->missing_ok = false;
9198 12 : n->concurrent = false;
9199 12 : $$ = (Node *) n;
9200 : }
9201 : | DROP ROUTINE IF_P EXISTS function_with_argtypes_list opt_drop_behavior
9202 : {
9203 6 : DropStmt *n = makeNode(DropStmt);
9204 :
9205 6 : n->removeType = OBJECT_ROUTINE;
9206 6 : n->objects = $5;
9207 6 : n->behavior = $6;
9208 6 : n->missing_ok = true;
9209 6 : n->concurrent = false;
9210 6 : $$ = (Node *) n;
9211 : }
9212 : ;
9213 :
9214 : RemoveAggrStmt:
9215 : DROP AGGREGATE aggregate_with_argtypes_list opt_drop_behavior
9216 : {
9217 74 : DropStmt *n = makeNode(DropStmt);
9218 :
9219 74 : n->removeType = OBJECT_AGGREGATE;
9220 74 : n->objects = $3;
9221 74 : n->behavior = $4;
9222 74 : n->missing_ok = false;
9223 74 : n->concurrent = false;
9224 74 : $$ = (Node *) n;
9225 : }
9226 : | DROP AGGREGATE IF_P EXISTS aggregate_with_argtypes_list opt_drop_behavior
9227 : {
9228 30 : DropStmt *n = makeNode(DropStmt);
9229 :
9230 30 : n->removeType = OBJECT_AGGREGATE;
9231 30 : n->objects = $5;
9232 30 : n->behavior = $6;
9233 30 : n->missing_ok = true;
9234 30 : n->concurrent = false;
9235 30 : $$ = (Node *) n;
9236 : }
9237 : ;
9238 :
9239 : RemoveOperStmt:
9240 : DROP OPERATOR operator_with_argtypes_list opt_drop_behavior
9241 : {
9242 200 : DropStmt *n = makeNode(DropStmt);
9243 :
9244 200 : n->removeType = OBJECT_OPERATOR;
9245 200 : n->objects = $3;
9246 200 : n->behavior = $4;
9247 200 : n->missing_ok = false;
9248 200 : n->concurrent = false;
9249 200 : $$ = (Node *) n;
9250 : }
9251 : | DROP OPERATOR IF_P EXISTS operator_with_argtypes_list opt_drop_behavior
9252 : {
9253 30 : DropStmt *n = makeNode(DropStmt);
9254 :
9255 30 : n->removeType = OBJECT_OPERATOR;
9256 30 : n->objects = $5;
9257 30 : n->behavior = $6;
9258 30 : n->missing_ok = true;
9259 30 : n->concurrent = false;
9260 30 : $$ = (Node *) n;
9261 : }
9262 : ;
9263 :
9264 : oper_argtypes:
9265 : '(' Typename ')'
9266 : {
9267 12 : ereport(ERROR,
9268 : (errcode(ERRCODE_SYNTAX_ERROR),
9269 : errmsg("missing argument"),
9270 : errhint("Use NONE to denote the missing argument of a unary operator."),
9271 : parser_errposition(@3)));
9272 : }
9273 : | '(' Typename ',' Typename ')'
9274 2464 : { $$ = list_make2($2, $4); }
9275 : | '(' NONE ',' Typename ')' /* left unary */
9276 32 : { $$ = list_make2(NULL, $4); }
9277 : | '(' Typename ',' NONE ')' /* right unary */
9278 12 : { $$ = list_make2($2, NULL); }
9279 : ;
9280 :
9281 : any_operator:
9282 : all_Op
9283 22754 : { $$ = list_make1(makeString($1)); }
9284 : | ColId '.' any_operator
9285 16504 : { $$ = lcons(makeString($1), $3); }
9286 : ;
9287 :
9288 : operator_with_argtypes_list:
9289 230 : operator_with_argtypes { $$ = list_make1($1); }
9290 : | operator_with_argtypes_list ',' operator_with_argtypes
9291 0 : { $$ = lappend($1, $3); }
9292 : ;
9293 :
9294 : operator_with_argtypes:
9295 : any_operator oper_argtypes
9296 : {
9297 2508 : ObjectWithArgs *n = makeNode(ObjectWithArgs);
9298 :
9299 2508 : n->objname = $1;
9300 2508 : n->objargs = $2;
9301 2508 : $$ = n;
9302 : }
9303 : ;
9304 :
9305 : /*****************************************************************************
9306 : *
9307 : * DO <anonymous code block> [ LANGUAGE language ]
9308 : *
9309 : * We use a DefElem list for future extensibility, and to allow flexibility
9310 : * in the clause order.
9311 : *
9312 : *****************************************************************************/
9313 :
9314 : DoStmt: DO dostmt_opt_list
9315 : {
9316 1160 : DoStmt *n = makeNode(DoStmt);
9317 :
9318 1160 : n->args = $2;
9319 1160 : $$ = (Node *) n;
9320 : }
9321 : ;
9322 :
9323 : dostmt_opt_list:
9324 1160 : dostmt_opt_item { $$ = list_make1($1); }
9325 198 : | dostmt_opt_list dostmt_opt_item { $$ = lappend($1, $2); }
9326 : ;
9327 :
9328 : dostmt_opt_item:
9329 : Sconst
9330 : {
9331 1160 : $$ = makeDefElem("as", (Node *) makeString($1), @1);
9332 : }
9333 : | LANGUAGE NonReservedWord_or_Sconst
9334 : {
9335 198 : $$ = makeDefElem("language", (Node *) makeString($2), @1);
9336 : }
9337 : ;
9338 :
9339 : /*****************************************************************************
9340 : *
9341 : * CREATE CAST / DROP CAST
9342 : *
9343 : *****************************************************************************/
9344 :
9345 : CreateCastStmt: CREATE CAST '(' Typename AS Typename ')'
9346 : WITH FUNCTION function_with_argtypes cast_context
9347 : {
9348 108 : CreateCastStmt *n = makeNode(CreateCastStmt);
9349 :
9350 108 : n->sourcetype = $4;
9351 108 : n->targettype = $6;
9352 108 : n->func = $10;
9353 108 : n->context = (CoercionContext) $11;
9354 108 : n->inout = false;
9355 108 : $$ = (Node *) n;
9356 : }
9357 : | CREATE CAST '(' Typename AS Typename ')'
9358 : WITHOUT FUNCTION cast_context
9359 : {
9360 162 : CreateCastStmt *n = makeNode(CreateCastStmt);
9361 :
9362 162 : n->sourcetype = $4;
9363 162 : n->targettype = $6;
9364 162 : n->func = NULL;
9365 162 : n->context = (CoercionContext) $10;
9366 162 : n->inout = false;
9367 162 : $$ = (Node *) n;
9368 : }
9369 : | CREATE CAST '(' Typename AS Typename ')'
9370 : WITH INOUT cast_context
9371 : {
9372 8 : CreateCastStmt *n = makeNode(CreateCastStmt);
9373 :
9374 8 : n->sourcetype = $4;
9375 8 : n->targettype = $6;
9376 8 : n->func = NULL;
9377 8 : n->context = (CoercionContext) $10;
9378 8 : n->inout = true;
9379 8 : $$ = (Node *) n;
9380 : }
9381 : ;
9382 :
9383 36 : cast_context: AS IMPLICIT_P { $$ = COERCION_IMPLICIT; }
9384 58 : | AS ASSIGNMENT { $$ = COERCION_ASSIGNMENT; }
9385 184 : | /*EMPTY*/ { $$ = COERCION_EXPLICIT; }
9386 : ;
9387 :
9388 :
9389 : DropCastStmt: DROP CAST opt_if_exists '(' Typename AS Typename ')' opt_drop_behavior
9390 : {
9391 60 : DropStmt *n = makeNode(DropStmt);
9392 :
9393 60 : n->removeType = OBJECT_CAST;
9394 60 : n->objects = list_make1(list_make2($5, $7));
9395 60 : n->behavior = $9;
9396 60 : n->missing_ok = $3;
9397 60 : n->concurrent = false;
9398 60 : $$ = (Node *) n;
9399 : }
9400 : ;
9401 :
9402 36 : opt_if_exists: IF_P EXISTS { $$ = true; }
9403 38 : | /*EMPTY*/ { $$ = false; }
9404 : ;
9405 :
9406 :
9407 : /*****************************************************************************
9408 : *
9409 : * CREATE TRANSFORM / DROP TRANSFORM
9410 : *
9411 : *****************************************************************************/
9412 :
9413 : CreateTransformStmt: CREATE opt_or_replace TRANSFORM FOR Typename LANGUAGE name '(' transform_element_list ')'
9414 : {
9415 50 : CreateTransformStmt *n = makeNode(CreateTransformStmt);
9416 :
9417 50 : n->replace = $2;
9418 50 : n->type_name = $5;
9419 50 : n->lang = $7;
9420 50 : n->fromsql = linitial($9);
9421 50 : n->tosql = lsecond($9);
9422 50 : $$ = (Node *) n;
9423 : }
9424 : ;
9425 :
9426 : transform_element_list: FROM SQL_P WITH FUNCTION function_with_argtypes ',' TO SQL_P WITH FUNCTION function_with_argtypes
9427 : {
9428 44 : $$ = list_make2($5, $11);
9429 : }
9430 : | TO SQL_P WITH FUNCTION function_with_argtypes ',' FROM SQL_P WITH FUNCTION function_with_argtypes
9431 : {
9432 0 : $$ = list_make2($11, $5);
9433 : }
9434 : | FROM SQL_P WITH FUNCTION function_with_argtypes
9435 : {
9436 4 : $$ = list_make2($5, NULL);
9437 : }
9438 : | TO SQL_P WITH FUNCTION function_with_argtypes
9439 : {
9440 2 : $$ = list_make2(NULL, $5);
9441 : }
9442 : ;
9443 :
9444 :
9445 : DropTransformStmt: DROP TRANSFORM opt_if_exists FOR Typename LANGUAGE name opt_drop_behavior
9446 : {
9447 14 : DropStmt *n = makeNode(DropStmt);
9448 :
9449 14 : n->removeType = OBJECT_TRANSFORM;
9450 14 : n->objects = list_make1(list_make2($5, makeString($7)));
9451 14 : n->behavior = $8;
9452 14 : n->missing_ok = $3;
9453 14 : $$ = (Node *) n;
9454 : }
9455 : ;
9456 :
9457 :
9458 : /*****************************************************************************
9459 : *
9460 : * QUERY:
9461 : *
9462 : * REINDEX [ (options) ] {INDEX | TABLE | SCHEMA} [CONCURRENTLY] <name>
9463 : * REINDEX [ (options) ] {DATABASE | SYSTEM} [CONCURRENTLY] [<name>]
9464 : *****************************************************************************/
9465 :
9466 : ReindexStmt:
9467 : REINDEX opt_utility_option_list reindex_target_relation opt_concurrently qualified_name
9468 : {
9469 922 : ReindexStmt *n = makeNode(ReindexStmt);
9470 :
9471 922 : n->kind = $3;
9472 922 : n->relation = $5;
9473 922 : n->name = NULL;
9474 922 : n->params = $2;
9475 922 : if ($4)
9476 518 : n->params = lappend(n->params,
9477 518 : makeDefElem("concurrently", NULL, @4));
9478 922 : $$ = (Node *) n;
9479 : }
9480 : | REINDEX opt_utility_option_list SCHEMA opt_concurrently name
9481 : {
9482 114 : ReindexStmt *n = makeNode(ReindexStmt);
9483 :
9484 114 : n->kind = REINDEX_OBJECT_SCHEMA;
9485 114 : n->relation = NULL;
9486 114 : n->name = $5;
9487 114 : n->params = $2;
9488 114 : if ($4)
9489 40 : n->params = lappend(n->params,
9490 40 : makeDefElem("concurrently", NULL, @4));
9491 114 : $$ = (Node *) n;
9492 : }
9493 : | REINDEX opt_utility_option_list reindex_target_all opt_concurrently opt_single_name
9494 : {
9495 64 : ReindexStmt *n = makeNode(ReindexStmt);
9496 :
9497 64 : n->kind = $3;
9498 64 : n->relation = NULL;
9499 64 : n->name = $5;
9500 64 : n->params = $2;
9501 64 : if ($4)
9502 10 : n->params = lappend(n->params,
9503 10 : makeDefElem("concurrently", NULL, @4));
9504 64 : $$ = (Node *) n;
9505 : }
9506 : ;
9507 : reindex_target_relation:
9508 394 : INDEX { $$ = REINDEX_OBJECT_INDEX; }
9509 528 : | TABLE { $$ = REINDEX_OBJECT_TABLE; }
9510 : ;
9511 : reindex_target_all:
9512 34 : SYSTEM_P { $$ = REINDEX_OBJECT_SYSTEM; }
9513 30 : | DATABASE { $$ = REINDEX_OBJECT_DATABASE; }
9514 : ;
9515 :
9516 : /*****************************************************************************
9517 : *
9518 : * ALTER TABLESPACE
9519 : *
9520 : *****************************************************************************/
9521 :
9522 : AlterTblSpcStmt:
9523 : ALTER TABLESPACE name SET reloptions
9524 : {
9525 : AlterTableSpaceOptionsStmt *n =
9526 12 : makeNode(AlterTableSpaceOptionsStmt);
9527 :
9528 12 : n->tablespacename = $3;
9529 12 : n->options = $5;
9530 12 : n->isReset = false;
9531 12 : $$ = (Node *) n;
9532 : }
9533 : | ALTER TABLESPACE name RESET reloptions
9534 : {
9535 : AlterTableSpaceOptionsStmt *n =
9536 12 : makeNode(AlterTableSpaceOptionsStmt);
9537 :
9538 12 : n->tablespacename = $3;
9539 12 : n->options = $5;
9540 12 : n->isReset = true;
9541 12 : $$ = (Node *) n;
9542 : }
9543 : ;
9544 :
9545 : /*****************************************************************************
9546 : *
9547 : * ALTER THING name RENAME TO newname
9548 : *
9549 : *****************************************************************************/
9550 :
9551 : RenameStmt: ALTER AGGREGATE aggregate_with_argtypes RENAME TO name
9552 : {
9553 42 : RenameStmt *n = makeNode(RenameStmt);
9554 :
9555 42 : n->renameType = OBJECT_AGGREGATE;
9556 42 : n->object = (Node *) $3;
9557 42 : n->newname = $6;
9558 42 : n->missing_ok = false;
9559 42 : $$ = (Node *) n;
9560 : }
9561 : | ALTER COLLATION any_name RENAME TO name
9562 : {
9563 18 : RenameStmt *n = makeNode(RenameStmt);
9564 :
9565 18 : n->renameType = OBJECT_COLLATION;
9566 18 : n->object = (Node *) $3;
9567 18 : n->newname = $6;
9568 18 : n->missing_ok = false;
9569 18 : $$ = (Node *) n;
9570 : }
9571 : | ALTER CONVERSION_P any_name RENAME TO name
9572 : {
9573 24 : RenameStmt *n = makeNode(RenameStmt);
9574 :
9575 24 : n->renameType = OBJECT_CONVERSION;
9576 24 : n->object = (Node *) $3;
9577 24 : n->newname = $6;
9578 24 : n->missing_ok = false;
9579 24 : $$ = (Node *) n;
9580 : }
9581 : | ALTER DATABASE name RENAME TO name
9582 : {
9583 12 : RenameStmt *n = makeNode(RenameStmt);
9584 :
9585 12 : n->renameType = OBJECT_DATABASE;
9586 12 : n->subname = $3;
9587 12 : n->newname = $6;
9588 12 : n->missing_ok = false;
9589 12 : $$ = (Node *) n;
9590 : }
9591 : | ALTER DOMAIN_P any_name RENAME TO name
9592 : {
9593 6 : RenameStmt *n = makeNode(RenameStmt);
9594 :
9595 6 : n->renameType = OBJECT_DOMAIN;
9596 6 : n->object = (Node *) $3;
9597 6 : n->newname = $6;
9598 6 : n->missing_ok = false;
9599 6 : $$ = (Node *) n;
9600 : }
9601 : | ALTER DOMAIN_P any_name RENAME CONSTRAINT name TO name
9602 : {
9603 6 : RenameStmt *n = makeNode(RenameStmt);
9604 :
9605 6 : n->renameType = OBJECT_DOMCONSTRAINT;
9606 6 : n->object = (Node *) $3;
9607 6 : n->subname = $6;
9608 6 : n->newname = $8;
9609 6 : $$ = (Node *) n;
9610 : }
9611 : | ALTER FOREIGN DATA_P WRAPPER name RENAME TO name
9612 : {
9613 24 : RenameStmt *n = makeNode(RenameStmt);
9614 :
9615 24 : n->renameType = OBJECT_FDW;
9616 24 : n->object = (Node *) makeString($5);
9617 24 : n->newname = $8;
9618 24 : n->missing_ok = false;
9619 24 : $$ = (Node *) n;
9620 : }
9621 : | ALTER FUNCTION function_with_argtypes RENAME TO name
9622 : {
9623 24 : RenameStmt *n = makeNode(RenameStmt);
9624 :
9625 24 : n->renameType = OBJECT_FUNCTION;
9626 24 : n->object = (Node *) $3;
9627 24 : n->newname = $6;
9628 24 : n->missing_ok = false;
9629 24 : $$ = (Node *) n;
9630 : }
9631 : | ALTER GROUP_P RoleId RENAME TO RoleId
9632 : {
9633 0 : RenameStmt *n = makeNode(RenameStmt);
9634 :
9635 0 : n->renameType = OBJECT_ROLE;
9636 0 : n->subname = $3;
9637 0 : n->newname = $6;
9638 0 : n->missing_ok = false;
9639 0 : $$ = (Node *) n;
9640 : }
9641 : | ALTER opt_procedural LANGUAGE name RENAME TO name
9642 : {
9643 18 : RenameStmt *n = makeNode(RenameStmt);
9644 :
9645 18 : n->renameType = OBJECT_LANGUAGE;
9646 18 : n->object = (Node *) makeString($4);
9647 18 : n->newname = $7;
9648 18 : n->missing_ok = false;
9649 18 : $$ = (Node *) n;
9650 : }
9651 : | ALTER OPERATOR CLASS any_name USING name RENAME TO name
9652 : {
9653 24 : RenameStmt *n = makeNode(RenameStmt);
9654 :
9655 24 : n->renameType = OBJECT_OPCLASS;
9656 24 : n->object = (Node *) lcons(makeString($6), $4);
9657 24 : n->newname = $9;
9658 24 : n->missing_ok = false;
9659 24 : $$ = (Node *) n;
9660 : }
9661 : | ALTER OPERATOR FAMILY any_name USING name RENAME TO name
9662 : {
9663 24 : RenameStmt *n = makeNode(RenameStmt);
9664 :
9665 24 : n->renameType = OBJECT_OPFAMILY;
9666 24 : n->object = (Node *) lcons(makeString($6), $4);
9667 24 : n->newname = $9;
9668 24 : n->missing_ok = false;
9669 24 : $$ = (Node *) n;
9670 : }
9671 : | ALTER POLICY name ON qualified_name RENAME TO name
9672 : {
9673 18 : RenameStmt *n = makeNode(RenameStmt);
9674 :
9675 18 : n->renameType = OBJECT_POLICY;
9676 18 : n->relation = $5;
9677 18 : n->subname = $3;
9678 18 : n->newname = $8;
9679 18 : n->missing_ok = false;
9680 18 : $$ = (Node *) n;
9681 : }
9682 : | ALTER POLICY IF_P EXISTS name ON qualified_name RENAME TO name
9683 : {
9684 0 : RenameStmt *n = makeNode(RenameStmt);
9685 :
9686 0 : n->renameType = OBJECT_POLICY;
9687 0 : n->relation = $7;
9688 0 : n->subname = $5;
9689 0 : n->newname = $10;
9690 0 : n->missing_ok = true;
9691 0 : $$ = (Node *) n;
9692 : }
9693 : | ALTER PROCEDURE function_with_argtypes RENAME TO name
9694 : {
9695 0 : RenameStmt *n = makeNode(RenameStmt);
9696 :
9697 0 : n->renameType = OBJECT_PROCEDURE;
9698 0 : n->object = (Node *) $3;
9699 0 : n->newname = $6;
9700 0 : n->missing_ok = false;
9701 0 : $$ = (Node *) n;
9702 : }
9703 : | ALTER PUBLICATION name RENAME TO name
9704 : {
9705 42 : RenameStmt *n = makeNode(RenameStmt);
9706 :
9707 42 : n->renameType = OBJECT_PUBLICATION;
9708 42 : n->object = (Node *) makeString($3);
9709 42 : n->newname = $6;
9710 42 : n->missing_ok = false;
9711 42 : $$ = (Node *) n;
9712 : }
9713 : | ALTER ROUTINE function_with_argtypes RENAME TO name
9714 : {
9715 24 : RenameStmt *n = makeNode(RenameStmt);
9716 :
9717 24 : n->renameType = OBJECT_ROUTINE;
9718 24 : n->object = (Node *) $3;
9719 24 : n->newname = $6;
9720 24 : n->missing_ok = false;
9721 24 : $$ = (Node *) n;
9722 : }
9723 : | ALTER SCHEMA name RENAME TO name
9724 : {
9725 20 : RenameStmt *n = makeNode(RenameStmt);
9726 :
9727 20 : n->renameType = OBJECT_SCHEMA;
9728 20 : n->subname = $3;
9729 20 : n->newname = $6;
9730 20 : n->missing_ok = false;
9731 20 : $$ = (Node *) n;
9732 : }
9733 : | ALTER SERVER name RENAME TO name
9734 : {
9735 24 : RenameStmt *n = makeNode(RenameStmt);
9736 :
9737 24 : n->renameType = OBJECT_FOREIGN_SERVER;
9738 24 : n->object = (Node *) makeString($3);
9739 24 : n->newname = $6;
9740 24 : n->missing_ok = false;
9741 24 : $$ = (Node *) n;
9742 : }
9743 : | ALTER SUBSCRIPTION name RENAME TO name
9744 : {
9745 38 : RenameStmt *n = makeNode(RenameStmt);
9746 :
9747 38 : n->renameType = OBJECT_SUBSCRIPTION;
9748 38 : n->object = (Node *) makeString($3);
9749 38 : n->newname = $6;
9750 38 : n->missing_ok = false;
9751 38 : $$ = (Node *) n;
9752 : }
9753 : | ALTER TABLE relation_expr RENAME TO name
9754 : {
9755 288 : RenameStmt *n = makeNode(RenameStmt);
9756 :
9757 288 : n->renameType = OBJECT_TABLE;
9758 288 : n->relation = $3;
9759 288 : n->subname = NULL;
9760 288 : n->newname = $6;
9761 288 : n->missing_ok = false;
9762 288 : $$ = (Node *) n;
9763 : }
9764 : | ALTER TABLE IF_P EXISTS relation_expr RENAME TO name
9765 : {
9766 0 : RenameStmt *n = makeNode(RenameStmt);
9767 :
9768 0 : n->renameType = OBJECT_TABLE;
9769 0 : n->relation = $5;
9770 0 : n->subname = NULL;
9771 0 : n->newname = $8;
9772 0 : n->missing_ok = true;
9773 0 : $$ = (Node *) n;
9774 : }
9775 : | ALTER SEQUENCE qualified_name RENAME TO name
9776 : {
9777 2 : RenameStmt *n = makeNode(RenameStmt);
9778 :
9779 2 : n->renameType = OBJECT_SEQUENCE;
9780 2 : n->relation = $3;
9781 2 : n->subname = NULL;
9782 2 : n->newname = $6;
9783 2 : n->missing_ok = false;
9784 2 : $$ = (Node *) n;
9785 : }
9786 : | ALTER SEQUENCE IF_P EXISTS qualified_name RENAME TO name
9787 : {
9788 0 : RenameStmt *n = makeNode(RenameStmt);
9789 :
9790 0 : n->renameType = OBJECT_SEQUENCE;
9791 0 : n->relation = $5;
9792 0 : n->subname = NULL;
9793 0 : n->newname = $8;
9794 0 : n->missing_ok = true;
9795 0 : $$ = (Node *) n;
9796 : }
9797 : | ALTER VIEW qualified_name RENAME TO name
9798 : {
9799 6 : RenameStmt *n = makeNode(RenameStmt);
9800 :
9801 6 : n->renameType = OBJECT_VIEW;
9802 6 : n->relation = $3;
9803 6 : n->subname = NULL;
9804 6 : n->newname = $6;
9805 6 : n->missing_ok = false;
9806 6 : $$ = (Node *) n;
9807 : }
9808 : | ALTER VIEW IF_P EXISTS qualified_name RENAME TO name
9809 : {
9810 0 : RenameStmt *n = makeNode(RenameStmt);
9811 :
9812 0 : n->renameType = OBJECT_VIEW;
9813 0 : n->relation = $5;
9814 0 : n->subname = NULL;
9815 0 : n->newname = $8;
9816 0 : n->missing_ok = true;
9817 0 : $$ = (Node *) n;
9818 : }
9819 : | ALTER MATERIALIZED VIEW qualified_name RENAME TO name
9820 : {
9821 0 : RenameStmt *n = makeNode(RenameStmt);
9822 :
9823 0 : n->renameType = OBJECT_MATVIEW;
9824 0 : n->relation = $4;
9825 0 : n->subname = NULL;
9826 0 : n->newname = $7;
9827 0 : n->missing_ok = false;
9828 0 : $$ = (Node *) n;
9829 : }
9830 : | ALTER MATERIALIZED VIEW IF_P EXISTS qualified_name RENAME TO name
9831 : {
9832 0 : RenameStmt *n = makeNode(RenameStmt);
9833 :
9834 0 : n->renameType = OBJECT_MATVIEW;
9835 0 : n->relation = $6;
9836 0 : n->subname = NULL;
9837 0 : n->newname = $9;
9838 0 : n->missing_ok = true;
9839 0 : $$ = (Node *) n;
9840 : }
9841 : | ALTER INDEX qualified_name RENAME TO name
9842 : {
9843 192 : RenameStmt *n = makeNode(RenameStmt);
9844 :
9845 192 : n->renameType = OBJECT_INDEX;
9846 192 : n->relation = $3;
9847 192 : n->subname = NULL;
9848 192 : n->newname = $6;
9849 192 : n->missing_ok = false;
9850 192 : $$ = (Node *) n;
9851 : }
9852 : | ALTER INDEX IF_P EXISTS qualified_name RENAME TO name
9853 : {
9854 12 : RenameStmt *n = makeNode(RenameStmt);
9855 :
9856 12 : n->renameType = OBJECT_INDEX;
9857 12 : n->relation = $5;
9858 12 : n->subname = NULL;
9859 12 : n->newname = $8;
9860 12 : n->missing_ok = true;
9861 12 : $$ = (Node *) n;
9862 : }
9863 : | ALTER FOREIGN TABLE relation_expr RENAME TO name
9864 : {
9865 6 : RenameStmt *n = makeNode(RenameStmt);
9866 :
9867 6 : n->renameType = OBJECT_FOREIGN_TABLE;
9868 6 : n->relation = $4;
9869 6 : n->subname = NULL;
9870 6 : n->newname = $7;
9871 6 : n->missing_ok = false;
9872 6 : $$ = (Node *) n;
9873 : }
9874 : | ALTER FOREIGN TABLE IF_P EXISTS relation_expr RENAME TO name
9875 : {
9876 6 : RenameStmt *n = makeNode(RenameStmt);
9877 :
9878 6 : n->renameType = OBJECT_FOREIGN_TABLE;
9879 6 : n->relation = $6;
9880 6 : n->subname = NULL;
9881 6 : n->newname = $9;
9882 6 : n->missing_ok = true;
9883 6 : $$ = (Node *) n;
9884 : }
9885 : | ALTER TABLE relation_expr RENAME opt_column name TO name
9886 : {
9887 238 : RenameStmt *n = makeNode(RenameStmt);
9888 :
9889 238 : n->renameType = OBJECT_COLUMN;
9890 238 : n->relationType = OBJECT_TABLE;
9891 238 : n->relation = $3;
9892 238 : n->subname = $6;
9893 238 : n->newname = $8;
9894 238 : n->missing_ok = false;
9895 238 : $$ = (Node *) n;
9896 : }
9897 : | ALTER TABLE IF_P EXISTS relation_expr RENAME opt_column name TO name
9898 : {
9899 24 : RenameStmt *n = makeNode(RenameStmt);
9900 :
9901 24 : n->renameType = OBJECT_COLUMN;
9902 24 : n->relationType = OBJECT_TABLE;
9903 24 : n->relation = $5;
9904 24 : n->subname = $8;
9905 24 : n->newname = $10;
9906 24 : n->missing_ok = true;
9907 24 : $$ = (Node *) n;
9908 : }
9909 : | ALTER VIEW qualified_name RENAME opt_column name TO name
9910 : {
9911 18 : RenameStmt *n = makeNode(RenameStmt);
9912 :
9913 18 : n->renameType = OBJECT_COLUMN;
9914 18 : n->relationType = OBJECT_VIEW;
9915 18 : n->relation = $3;
9916 18 : n->subname = $6;
9917 18 : n->newname = $8;
9918 18 : n->missing_ok = false;
9919 18 : $$ = (Node *) n;
9920 : }
9921 : | ALTER VIEW IF_P EXISTS qualified_name RENAME opt_column name TO name
9922 : {
9923 0 : RenameStmt *n = makeNode(RenameStmt);
9924 :
9925 0 : n->renameType = OBJECT_COLUMN;
9926 0 : n->relationType = OBJECT_VIEW;
9927 0 : n->relation = $5;
9928 0 : n->subname = $8;
9929 0 : n->newname = $10;
9930 0 : n->missing_ok = true;
9931 0 : $$ = (Node *) n;
9932 : }
9933 : | ALTER MATERIALIZED VIEW qualified_name RENAME opt_column name TO name
9934 : {
9935 0 : RenameStmt *n = makeNode(RenameStmt);
9936 :
9937 0 : n->renameType = OBJECT_COLUMN;
9938 0 : n->relationType = OBJECT_MATVIEW;
9939 0 : n->relation = $4;
9940 0 : n->subname = $7;
9941 0 : n->newname = $9;
9942 0 : n->missing_ok = false;
9943 0 : $$ = (Node *) n;
9944 : }
9945 : | ALTER MATERIALIZED VIEW IF_P EXISTS qualified_name RENAME opt_column name TO name
9946 : {
9947 0 : RenameStmt *n = makeNode(RenameStmt);
9948 :
9949 0 : n->renameType = OBJECT_COLUMN;
9950 0 : n->relationType = OBJECT_MATVIEW;
9951 0 : n->relation = $6;
9952 0 : n->subname = $9;
9953 0 : n->newname = $11;
9954 0 : n->missing_ok = true;
9955 0 : $$ = (Node *) n;
9956 : }
9957 : | ALTER TABLE relation_expr RENAME CONSTRAINT name TO name
9958 : {
9959 72 : RenameStmt *n = makeNode(RenameStmt);
9960 :
9961 72 : n->renameType = OBJECT_TABCONSTRAINT;
9962 72 : n->relation = $3;
9963 72 : n->subname = $6;
9964 72 : n->newname = $8;
9965 72 : n->missing_ok = false;
9966 72 : $$ = (Node *) n;
9967 : }
9968 : | ALTER TABLE IF_P EXISTS relation_expr RENAME CONSTRAINT name TO name
9969 : {
9970 6 : RenameStmt *n = makeNode(RenameStmt);
9971 :
9972 6 : n->renameType = OBJECT_TABCONSTRAINT;
9973 6 : n->relation = $5;
9974 6 : n->subname = $8;
9975 6 : n->newname = $10;
9976 6 : n->missing_ok = true;
9977 6 : $$ = (Node *) n;
9978 : }
9979 : | ALTER FOREIGN TABLE relation_expr RENAME opt_column name TO name
9980 : {
9981 6 : RenameStmt *n = makeNode(RenameStmt);
9982 :
9983 6 : n->renameType = OBJECT_COLUMN;
9984 6 : n->relationType = OBJECT_FOREIGN_TABLE;
9985 6 : n->relation = $4;
9986 6 : n->subname = $7;
9987 6 : n->newname = $9;
9988 6 : n->missing_ok = false;
9989 6 : $$ = (Node *) n;
9990 : }
9991 : | ALTER FOREIGN TABLE IF_P EXISTS relation_expr RENAME opt_column name TO name
9992 : {
9993 6 : RenameStmt *n = makeNode(RenameStmt);
9994 :
9995 6 : n->renameType = OBJECT_COLUMN;
9996 6 : n->relationType = OBJECT_FOREIGN_TABLE;
9997 6 : n->relation = $6;
9998 6 : n->subname = $9;
9999 6 : n->newname = $11;
10000 6 : n->missing_ok = true;
10001 6 : $$ = (Node *) n;
10002 : }
10003 : | ALTER RULE name ON qualified_name RENAME TO name
10004 : {
10005 34 : RenameStmt *n = makeNode(RenameStmt);
10006 :
10007 34 : n->renameType = OBJECT_RULE;
10008 34 : n->relation = $5;
10009 34 : n->subname = $3;
10010 34 : n->newname = $8;
10011 34 : n->missing_ok = false;
10012 34 : $$ = (Node *) n;
10013 : }
10014 : | ALTER TRIGGER name ON qualified_name RENAME TO name
10015 : {
10016 40 : RenameStmt *n = makeNode(RenameStmt);
10017 :
10018 40 : n->renameType = OBJECT_TRIGGER;
10019 40 : n->relation = $5;
10020 40 : n->subname = $3;
10021 40 : n->newname = $8;
10022 40 : n->missing_ok = false;
10023 40 : $$ = (Node *) n;
10024 : }
10025 : | ALTER EVENT TRIGGER name RENAME TO name
10026 : {
10027 12 : RenameStmt *n = makeNode(RenameStmt);
10028 :
10029 12 : n->renameType = OBJECT_EVENT_TRIGGER;
10030 12 : n->object = (Node *) makeString($4);
10031 12 : n->newname = $7;
10032 12 : $$ = (Node *) n;
10033 : }
10034 : | ALTER ROLE RoleId RENAME TO RoleId
10035 : {
10036 32 : RenameStmt *n = makeNode(RenameStmt);
10037 :
10038 32 : n->renameType = OBJECT_ROLE;
10039 32 : n->subname = $3;
10040 32 : n->newname = $6;
10041 32 : n->missing_ok = false;
10042 32 : $$ = (Node *) n;
10043 : }
10044 : | ALTER USER RoleId RENAME TO RoleId
10045 : {
10046 0 : RenameStmt *n = makeNode(RenameStmt);
10047 :
10048 0 : n->renameType = OBJECT_ROLE;
10049 0 : n->subname = $3;
10050 0 : n->newname = $6;
10051 0 : n->missing_ok = false;
10052 0 : $$ = (Node *) n;
10053 : }
10054 : | ALTER TABLESPACE name RENAME TO name
10055 : {
10056 6 : RenameStmt *n = makeNode(RenameStmt);
10057 :
10058 6 : n->renameType = OBJECT_TABLESPACE;
10059 6 : n->subname = $3;
10060 6 : n->newname = $6;
10061 6 : n->missing_ok = false;
10062 6 : $$ = (Node *) n;
10063 : }
10064 : | ALTER STATISTICS any_name RENAME TO name
10065 : {
10066 30 : RenameStmt *n = makeNode(RenameStmt);
10067 :
10068 30 : n->renameType = OBJECT_STATISTIC_EXT;
10069 30 : n->object = (Node *) $3;
10070 30 : n->newname = $6;
10071 30 : n->missing_ok = false;
10072 30 : $$ = (Node *) n;
10073 : }
10074 : | ALTER TEXT_P SEARCH PARSER any_name RENAME TO name
10075 : {
10076 12 : RenameStmt *n = makeNode(RenameStmt);
10077 :
10078 12 : n->renameType = OBJECT_TSPARSER;
10079 12 : n->object = (Node *) $5;
10080 12 : n->newname = $8;
10081 12 : n->missing_ok = false;
10082 12 : $$ = (Node *) n;
10083 : }
10084 : | ALTER TEXT_P SEARCH DICTIONARY any_name RENAME TO name
10085 : {
10086 24 : RenameStmt *n = makeNode(RenameStmt);
10087 :
10088 24 : n->renameType = OBJECT_TSDICTIONARY;
10089 24 : n->object = (Node *) $5;
10090 24 : n->newname = $8;
10091 24 : n->missing_ok = false;
10092 24 : $$ = (Node *) n;
10093 : }
10094 : | ALTER TEXT_P SEARCH TEMPLATE any_name RENAME TO name
10095 : {
10096 12 : RenameStmt *n = makeNode(RenameStmt);
10097 :
10098 12 : n->renameType = OBJECT_TSTEMPLATE;
10099 12 : n->object = (Node *) $5;
10100 12 : n->newname = $8;
10101 12 : n->missing_ok = false;
10102 12 : $$ = (Node *) n;
10103 : }
10104 : | ALTER TEXT_P SEARCH CONFIGURATION any_name RENAME TO name
10105 : {
10106 24 : RenameStmt *n = makeNode(RenameStmt);
10107 :
10108 24 : n->renameType = OBJECT_TSCONFIGURATION;
10109 24 : n->object = (Node *) $5;
10110 24 : n->newname = $8;
10111 24 : n->missing_ok = false;
10112 24 : $$ = (Node *) n;
10113 : }
10114 : | ALTER TYPE_P any_name RENAME TO name
10115 : {
10116 26 : RenameStmt *n = makeNode(RenameStmt);
10117 :
10118 26 : n->renameType = OBJECT_TYPE;
10119 26 : n->object = (Node *) $3;
10120 26 : n->newname = $6;
10121 26 : n->missing_ok = false;
10122 26 : $$ = (Node *) n;
10123 : }
10124 : | ALTER TYPE_P any_name RENAME ATTRIBUTE name TO name opt_drop_behavior
10125 : {
10126 24 : RenameStmt *n = makeNode(RenameStmt);
10127 :
10128 24 : n->renameType = OBJECT_ATTRIBUTE;
10129 24 : n->relationType = OBJECT_TYPE;
10130 24 : n->relation = makeRangeVarFromAnyName($3, @3, yyscanner);
10131 24 : n->subname = $6;
10132 24 : n->newname = $8;
10133 24 : n->behavior = $9;
10134 24 : n->missing_ok = false;
10135 24 : $$ = (Node *) n;
10136 : }
10137 : ;
10138 :
10139 : opt_column: COLUMN
10140 : | /*EMPTY*/
10141 : ;
10142 :
10143 184 : opt_set_data: SET DATA_P { $$ = 1; }
10144 1028 : | /*EMPTY*/ { $$ = 0; }
10145 : ;
10146 :
10147 : /*****************************************************************************
10148 : *
10149 : * ALTER THING name DEPENDS ON EXTENSION name
10150 : *
10151 : *****************************************************************************/
10152 :
10153 : AlterObjectDependsStmt:
10154 : ALTER FUNCTION function_with_argtypes opt_no DEPENDS ON EXTENSION name
10155 : {
10156 12 : AlterObjectDependsStmt *n = makeNode(AlterObjectDependsStmt);
10157 :
10158 12 : n->objectType = OBJECT_FUNCTION;
10159 12 : n->object = (Node *) $3;
10160 12 : n->extname = makeString($8);
10161 12 : n->remove = $4;
10162 12 : $$ = (Node *) n;
10163 : }
10164 : | ALTER PROCEDURE function_with_argtypes opt_no DEPENDS ON EXTENSION name
10165 : {
10166 0 : AlterObjectDependsStmt *n = makeNode(AlterObjectDependsStmt);
10167 :
10168 0 : n->objectType = OBJECT_PROCEDURE;
10169 0 : n->object = (Node *) $3;
10170 0 : n->extname = makeString($8);
10171 0 : n->remove = $4;
10172 0 : $$ = (Node *) n;
10173 : }
10174 : | ALTER ROUTINE function_with_argtypes opt_no DEPENDS ON EXTENSION name
10175 : {
10176 0 : AlterObjectDependsStmt *n = makeNode(AlterObjectDependsStmt);
10177 :
10178 0 : n->objectType = OBJECT_ROUTINE;
10179 0 : n->object = (Node *) $3;
10180 0 : n->extname = makeString($8);
10181 0 : n->remove = $4;
10182 0 : $$ = (Node *) n;
10183 : }
10184 : | ALTER TRIGGER name ON qualified_name opt_no DEPENDS ON EXTENSION name
10185 : {
10186 10 : AlterObjectDependsStmt *n = makeNode(AlterObjectDependsStmt);
10187 :
10188 10 : n->objectType = OBJECT_TRIGGER;
10189 10 : n->relation = $5;
10190 10 : n->object = (Node *) list_make1(makeString($3));
10191 10 : n->extname = makeString($10);
10192 10 : n->remove = $6;
10193 10 : $$ = (Node *) n;
10194 : }
10195 : | ALTER MATERIALIZED VIEW qualified_name opt_no DEPENDS ON EXTENSION name
10196 : {
10197 10 : AlterObjectDependsStmt *n = makeNode(AlterObjectDependsStmt);
10198 :
10199 10 : n->objectType = OBJECT_MATVIEW;
10200 10 : n->relation = $4;
10201 10 : n->extname = makeString($9);
10202 10 : n->remove = $5;
10203 10 : $$ = (Node *) n;
10204 : }
10205 : | ALTER INDEX qualified_name opt_no DEPENDS ON EXTENSION name
10206 : {
10207 14 : AlterObjectDependsStmt *n = makeNode(AlterObjectDependsStmt);
10208 :
10209 14 : n->objectType = OBJECT_INDEX;
10210 14 : n->relation = $3;
10211 14 : n->extname = makeString($8);
10212 14 : n->remove = $4;
10213 14 : $$ = (Node *) n;
10214 : }
10215 : ;
10216 :
10217 8 : opt_no: NO { $$ = true; }
10218 38 : | /* EMPTY */ { $$ = false; }
10219 : ;
10220 :
10221 : /*****************************************************************************
10222 : *
10223 : * ALTER THING name SET SCHEMA name
10224 : *
10225 : *****************************************************************************/
10226 :
10227 : AlterObjectSchemaStmt:
10228 : ALTER AGGREGATE aggregate_with_argtypes SET SCHEMA name
10229 : {
10230 24 : AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
10231 :
10232 24 : n->objectType = OBJECT_AGGREGATE;
10233 24 : n->object = (Node *) $3;
10234 24 : n->newschema = $6;
10235 24 : n->missing_ok = false;
10236 24 : $$ = (Node *) n;
10237 : }
10238 : | ALTER COLLATION any_name SET SCHEMA name
10239 : {
10240 6 : AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
10241 :
10242 6 : n->objectType = OBJECT_COLLATION;
10243 6 : n->object = (Node *) $3;
10244 6 : n->newschema = $6;
10245 6 : n->missing_ok = false;
10246 6 : $$ = (Node *) n;
10247 : }
10248 : | ALTER CONVERSION_P any_name SET SCHEMA name
10249 : {
10250 24 : AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
10251 :
10252 24 : n->objectType = OBJECT_CONVERSION;
10253 24 : n->object = (Node *) $3;
10254 24 : n->newschema = $6;
10255 24 : n->missing_ok = false;
10256 24 : $$ = (Node *) n;
10257 : }
10258 : | ALTER DOMAIN_P any_name SET SCHEMA name
10259 : {
10260 6 : AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
10261 :
10262 6 : n->objectType = OBJECT_DOMAIN;
10263 6 : n->object = (Node *) $3;
10264 6 : n->newschema = $6;
10265 6 : n->missing_ok = false;
10266 6 : $$ = (Node *) n;
10267 : }
10268 : | ALTER EXTENSION name SET SCHEMA name
10269 : {
10270 12 : AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
10271 :
10272 12 : n->objectType = OBJECT_EXTENSION;
10273 12 : n->object = (Node *) makeString($3);
10274 12 : n->newschema = $6;
10275 12 : n->missing_ok = false;
10276 12 : $$ = (Node *) n;
10277 : }
10278 : | ALTER FUNCTION function_with_argtypes SET SCHEMA name
10279 : {
10280 42 : AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
10281 :
10282 42 : n->objectType = OBJECT_FUNCTION;
10283 42 : n->object = (Node *) $3;
10284 42 : n->newschema = $6;
10285 42 : n->missing_ok = false;
10286 42 : $$ = (Node *) n;
10287 : }
10288 : | ALTER OPERATOR operator_with_argtypes SET SCHEMA name
10289 : {
10290 18 : AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
10291 :
10292 18 : n->objectType = OBJECT_OPERATOR;
10293 18 : n->object = (Node *) $3;
10294 18 : n->newschema = $6;
10295 18 : n->missing_ok = false;
10296 18 : $$ = (Node *) n;
10297 : }
10298 : | ALTER OPERATOR CLASS any_name USING name SET SCHEMA name
10299 : {
10300 24 : AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
10301 :
10302 24 : n->objectType = OBJECT_OPCLASS;
10303 24 : n->object = (Node *) lcons(makeString($6), $4);
10304 24 : n->newschema = $9;
10305 24 : n->missing_ok = false;
10306 24 : $$ = (Node *) n;
10307 : }
10308 : | ALTER OPERATOR FAMILY any_name USING name SET SCHEMA name
10309 : {
10310 24 : AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
10311 :
10312 24 : n->objectType = OBJECT_OPFAMILY;
10313 24 : n->object = (Node *) lcons(makeString($6), $4);
10314 24 : n->newschema = $9;
10315 24 : n->missing_ok = false;
10316 24 : $$ = (Node *) n;
10317 : }
10318 : | ALTER PROCEDURE function_with_argtypes SET SCHEMA name
10319 : {
10320 0 : AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
10321 :
10322 0 : n->objectType = OBJECT_PROCEDURE;
10323 0 : n->object = (Node *) $3;
10324 0 : n->newschema = $6;
10325 0 : n->missing_ok = false;
10326 0 : $$ = (Node *) n;
10327 : }
10328 : | ALTER ROUTINE function_with_argtypes SET SCHEMA name
10329 : {
10330 0 : AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
10331 :
10332 0 : n->objectType = OBJECT_ROUTINE;
10333 0 : n->object = (Node *) $3;
10334 0 : n->newschema = $6;
10335 0 : n->missing_ok = false;
10336 0 : $$ = (Node *) n;
10337 : }
10338 : | ALTER TABLE relation_expr SET SCHEMA name
10339 : {
10340 66 : AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
10341 :
10342 66 : n->objectType = OBJECT_TABLE;
10343 66 : n->relation = $3;
10344 66 : n->newschema = $6;
10345 66 : n->missing_ok = false;
10346 66 : $$ = (Node *) n;
10347 : }
10348 : | ALTER TABLE IF_P EXISTS relation_expr SET SCHEMA name
10349 : {
10350 12 : AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
10351 :
10352 12 : n->objectType = OBJECT_TABLE;
10353 12 : n->relation = $5;
10354 12 : n->newschema = $8;
10355 12 : n->missing_ok = true;
10356 12 : $$ = (Node *) n;
10357 : }
10358 : | ALTER STATISTICS any_name SET SCHEMA name
10359 : {
10360 18 : AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
10361 :
10362 18 : n->objectType = OBJECT_STATISTIC_EXT;
10363 18 : n->object = (Node *) $3;
10364 18 : n->newschema = $6;
10365 18 : n->missing_ok = false;
10366 18 : $$ = (Node *) n;
10367 : }
10368 : | ALTER TEXT_P SEARCH PARSER any_name SET SCHEMA name
10369 : {
10370 18 : AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
10371 :
10372 18 : n->objectType = OBJECT_TSPARSER;
10373 18 : n->object = (Node *) $5;
10374 18 : n->newschema = $8;
10375 18 : n->missing_ok = false;
10376 18 : $$ = (Node *) n;
10377 : }
10378 : | ALTER TEXT_P SEARCH DICTIONARY any_name SET SCHEMA name
10379 : {
10380 24 : AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
10381 :
10382 24 : n->objectType = OBJECT_TSDICTIONARY;
10383 24 : n->object = (Node *) $5;
10384 24 : n->newschema = $8;
10385 24 : n->missing_ok = false;
10386 24 : $$ = (Node *) n;
10387 : }
10388 : | ALTER TEXT_P SEARCH TEMPLATE any_name SET SCHEMA name
10389 : {
10390 18 : AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
10391 :
10392 18 : n->objectType = OBJECT_TSTEMPLATE;
10393 18 : n->object = (Node *) $5;
10394 18 : n->newschema = $8;
10395 18 : n->missing_ok = false;
10396 18 : $$ = (Node *) n;
10397 : }
10398 : | ALTER TEXT_P SEARCH CONFIGURATION any_name SET SCHEMA name
10399 : {
10400 24 : AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
10401 :
10402 24 : n->objectType = OBJECT_TSCONFIGURATION;
10403 24 : n->object = (Node *) $5;
10404 24 : n->newschema = $8;
10405 24 : n->missing_ok = false;
10406 24 : $$ = (Node *) n;
10407 : }
10408 : | ALTER SEQUENCE qualified_name SET SCHEMA name
10409 : {
10410 8 : AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
10411 :
10412 8 : n->objectType = OBJECT_SEQUENCE;
10413 8 : n->relation = $3;
10414 8 : n->newschema = $6;
10415 8 : n->missing_ok = false;
10416 8 : $$ = (Node *) n;
10417 : }
10418 : | ALTER SEQUENCE IF_P EXISTS qualified_name SET SCHEMA name
10419 : {
10420 0 : AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
10421 :
10422 0 : n->objectType = OBJECT_SEQUENCE;
10423 0 : n->relation = $5;
10424 0 : n->newschema = $8;
10425 0 : n->missing_ok = true;
10426 0 : $$ = (Node *) n;
10427 : }
10428 : | ALTER VIEW qualified_name SET SCHEMA name
10429 : {
10430 0 : AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
10431 :
10432 0 : n->objectType = OBJECT_VIEW;
10433 0 : n->relation = $3;
10434 0 : n->newschema = $6;
10435 0 : n->missing_ok = false;
10436 0 : $$ = (Node *) n;
10437 : }
10438 : | ALTER VIEW IF_P EXISTS qualified_name SET SCHEMA name
10439 : {
10440 0 : AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
10441 :
10442 0 : n->objectType = OBJECT_VIEW;
10443 0 : n->relation = $5;
10444 0 : n->newschema = $8;
10445 0 : n->missing_ok = true;
10446 0 : $$ = (Node *) n;
10447 : }
10448 : | ALTER MATERIALIZED VIEW qualified_name SET SCHEMA name
10449 : {
10450 6 : AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
10451 :
10452 6 : n->objectType = OBJECT_MATVIEW;
10453 6 : n->relation = $4;
10454 6 : n->newschema = $7;
10455 6 : n->missing_ok = false;
10456 6 : $$ = (Node *) n;
10457 : }
10458 : | ALTER MATERIALIZED VIEW IF_P EXISTS qualified_name SET SCHEMA name
10459 : {
10460 0 : AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
10461 :
10462 0 : n->objectType = OBJECT_MATVIEW;
10463 0 : n->relation = $6;
10464 0 : n->newschema = $9;
10465 0 : n->missing_ok = true;
10466 0 : $$ = (Node *) n;
10467 : }
10468 : | ALTER FOREIGN TABLE relation_expr SET SCHEMA name
10469 : {
10470 6 : AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
10471 :
10472 6 : n->objectType = OBJECT_FOREIGN_TABLE;
10473 6 : n->relation = $4;
10474 6 : n->newschema = $7;
10475 6 : n->missing_ok = false;
10476 6 : $$ = (Node *) n;
10477 : }
10478 : | ALTER FOREIGN TABLE IF_P EXISTS relation_expr SET SCHEMA name
10479 : {
10480 6 : AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
10481 :
10482 6 : n->objectType = OBJECT_FOREIGN_TABLE;
10483 6 : n->relation = $6;
10484 6 : n->newschema = $9;
10485 6 : n->missing_ok = true;
10486 6 : $$ = (Node *) n;
10487 : }
10488 : | ALTER TYPE_P any_name SET SCHEMA name
10489 : {
10490 12 : AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
10491 :
10492 12 : n->objectType = OBJECT_TYPE;
10493 12 : n->object = (Node *) $3;
10494 12 : n->newschema = $6;
10495 12 : n->missing_ok = false;
10496 12 : $$ = (Node *) n;
10497 : }
10498 : ;
10499 :
10500 : /*****************************************************************************
10501 : *
10502 : * ALTER OPERATOR name SET define
10503 : *
10504 : *****************************************************************************/
10505 :
10506 : AlterOperatorStmt:
10507 : ALTER OPERATOR operator_with_argtypes SET '(' operator_def_list ')'
10508 : {
10509 608 : AlterOperatorStmt *n = makeNode(AlterOperatorStmt);
10510 :
10511 608 : n->opername = $3;
10512 608 : n->options = $6;
10513 608 : $$ = (Node *) n;
10514 : }
10515 : ;
10516 :
10517 668 : operator_def_list: operator_def_elem { $$ = list_make1($1); }
10518 506 : | operator_def_list ',' operator_def_elem { $$ = lappend($1, $3); }
10519 : ;
10520 :
10521 : operator_def_elem: ColLabel '=' NONE
10522 30 : { $$ = makeDefElem($1, NULL, @1); }
10523 : | ColLabel '=' operator_def_arg
10524 1110 : { $$ = makeDefElem($1, (Node *) $3, @1); }
10525 : | ColLabel
10526 34 : { $$ = makeDefElem($1, NULL, @1); }
10527 : ;
10528 :
10529 : /* must be similar enough to def_arg to avoid reduce/reduce conflicts */
10530 : operator_def_arg:
10531 1032 : func_type { $$ = (Node *) $1; }
10532 24 : | reserved_keyword { $$ = (Node *) makeString(pstrdup($1)); }
10533 54 : | qual_all_Op { $$ = (Node *) $1; }
10534 0 : | NumericOnly { $$ = (Node *) $1; }
10535 0 : | Sconst { $$ = (Node *) makeString($1); }
10536 : ;
10537 :
10538 : /*****************************************************************************
10539 : *
10540 : * ALTER TYPE name SET define
10541 : *
10542 : * We repurpose ALTER OPERATOR's version of "definition" here
10543 : *
10544 : *****************************************************************************/
10545 :
10546 : AlterTypeStmt:
10547 : ALTER TYPE_P any_name SET '(' operator_def_list ')'
10548 : {
10549 60 : AlterTypeStmt *n = makeNode(AlterTypeStmt);
10550 :
10551 60 : n->typeName = $3;
10552 60 : n->options = $6;
10553 60 : $$ = (Node *) n;
10554 : }
10555 : ;
10556 :
10557 : /*****************************************************************************
10558 : *
10559 : * ALTER THING name OWNER TO newname
10560 : *
10561 : *****************************************************************************/
10562 :
10563 : AlterOwnerStmt: ALTER AGGREGATE aggregate_with_argtypes OWNER TO RoleSpec
10564 : {
10565 142 : AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
10566 :
10567 142 : n->objectType = OBJECT_AGGREGATE;
10568 142 : n->object = (Node *) $3;
10569 142 : n->newowner = $6;
10570 142 : $$ = (Node *) n;
10571 : }
10572 : | ALTER COLLATION any_name OWNER TO RoleSpec
10573 : {
10574 18 : AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
10575 :
10576 18 : n->objectType = OBJECT_COLLATION;
10577 18 : n->object = (Node *) $3;
10578 18 : n->newowner = $6;
10579 18 : $$ = (Node *) n;
10580 : }
10581 : | ALTER CONVERSION_P any_name OWNER TO RoleSpec
10582 : {
10583 24 : AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
10584 :
10585 24 : n->objectType = OBJECT_CONVERSION;
10586 24 : n->object = (Node *) $3;
10587 24 : n->newowner = $6;
10588 24 : $$ = (Node *) n;
10589 : }
10590 : | ALTER DATABASE name OWNER TO RoleSpec
10591 : {
10592 90 : AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
10593 :
10594 90 : n->objectType = OBJECT_DATABASE;
10595 90 : n->object = (Node *) makeString($3);
10596 90 : n->newowner = $6;
10597 90 : $$ = (Node *) n;
10598 : }
10599 : | ALTER DOMAIN_P any_name OWNER TO RoleSpec
10600 : {
10601 48 : AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
10602 :
10603 48 : n->objectType = OBJECT_DOMAIN;
10604 48 : n->object = (Node *) $3;
10605 48 : n->newowner = $6;
10606 48 : $$ = (Node *) n;
10607 : }
10608 : | ALTER FUNCTION function_with_argtypes OWNER TO RoleSpec
10609 : {
10610 598 : AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
10611 :
10612 598 : n->objectType = OBJECT_FUNCTION;
10613 598 : n->object = (Node *) $3;
10614 598 : n->newowner = $6;
10615 598 : $$ = (Node *) n;
10616 : }
10617 : | ALTER opt_procedural LANGUAGE name OWNER TO RoleSpec
10618 : {
10619 144 : AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
10620 :
10621 144 : n->objectType = OBJECT_LANGUAGE;
10622 144 : n->object = (Node *) makeString($4);
10623 144 : n->newowner = $7;
10624 144 : $$ = (Node *) n;
10625 : }
10626 : | ALTER LARGE_P OBJECT_P NumericOnly OWNER TO RoleSpec
10627 : {
10628 16 : AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
10629 :
10630 16 : n->objectType = OBJECT_LARGEOBJECT;
10631 16 : n->object = (Node *) $4;
10632 16 : n->newowner = $7;
10633 16 : $$ = (Node *) n;
10634 : }
10635 : | ALTER OPERATOR operator_with_argtypes OWNER TO RoleSpec
10636 : {
10637 46 : AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
10638 :
10639 46 : n->objectType = OBJECT_OPERATOR;
10640 46 : n->object = (Node *) $3;
10641 46 : n->newowner = $6;
10642 46 : $$ = (Node *) n;
10643 : }
10644 : | ALTER OPERATOR CLASS any_name USING name OWNER TO RoleSpec
10645 : {
10646 54 : AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
10647 :
10648 54 : n->objectType = OBJECT_OPCLASS;
10649 54 : n->object = (Node *) lcons(makeString($6), $4);
10650 54 : n->newowner = $9;
10651 54 : $$ = (Node *) n;
10652 : }
10653 : | ALTER OPERATOR FAMILY any_name USING name OWNER TO RoleSpec
10654 : {
10655 62 : AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
10656 :
10657 62 : n->objectType = OBJECT_OPFAMILY;
10658 62 : n->object = (Node *) lcons(makeString($6), $4);
10659 62 : n->newowner = $9;
10660 62 : $$ = (Node *) n;
10661 : }
10662 : | ALTER PROCEDURE function_with_argtypes OWNER TO RoleSpec
10663 : {
10664 24 : AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
10665 :
10666 24 : n->objectType = OBJECT_PROCEDURE;
10667 24 : n->object = (Node *) $3;
10668 24 : n->newowner = $6;
10669 24 : $$ = (Node *) n;
10670 : }
10671 : | ALTER ROUTINE function_with_argtypes OWNER TO RoleSpec
10672 : {
10673 0 : AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
10674 :
10675 0 : n->objectType = OBJECT_ROUTINE;
10676 0 : n->object = (Node *) $3;
10677 0 : n->newowner = $6;
10678 0 : $$ = (Node *) n;
10679 : }
10680 : | ALTER SCHEMA name OWNER TO RoleSpec
10681 : {
10682 64 : AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
10683 :
10684 64 : n->objectType = OBJECT_SCHEMA;
10685 64 : n->object = (Node *) makeString($3);
10686 64 : n->newowner = $6;
10687 64 : $$ = (Node *) n;
10688 : }
10689 : | ALTER TYPE_P any_name OWNER TO RoleSpec
10690 : {
10691 84 : AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
10692 :
10693 84 : n->objectType = OBJECT_TYPE;
10694 84 : n->object = (Node *) $3;
10695 84 : n->newowner = $6;
10696 84 : $$ = (Node *) n;
10697 : }
10698 : | ALTER TABLESPACE name OWNER TO RoleSpec
10699 : {
10700 6 : AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
10701 :
10702 6 : n->objectType = OBJECT_TABLESPACE;
10703 6 : n->object = (Node *) makeString($3);
10704 6 : n->newowner = $6;
10705 6 : $$ = (Node *) n;
10706 : }
10707 : | ALTER STATISTICS any_name OWNER TO RoleSpec
10708 : {
10709 32 : AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
10710 :
10711 32 : n->objectType = OBJECT_STATISTIC_EXT;
10712 32 : n->object = (Node *) $3;
10713 32 : n->newowner = $6;
10714 32 : $$ = (Node *) n;
10715 : }
10716 : | ALTER TEXT_P SEARCH DICTIONARY any_name OWNER TO RoleSpec
10717 : {
10718 42 : AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
10719 :
10720 42 : n->objectType = OBJECT_TSDICTIONARY;
10721 42 : n->object = (Node *) $5;
10722 42 : n->newowner = $8;
10723 42 : $$ = (Node *) n;
10724 : }
10725 : | ALTER TEXT_P SEARCH CONFIGURATION any_name OWNER TO RoleSpec
10726 : {
10727 32 : AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
10728 :
10729 32 : n->objectType = OBJECT_TSCONFIGURATION;
10730 32 : n->object = (Node *) $5;
10731 32 : n->newowner = $8;
10732 32 : $$ = (Node *) n;
10733 : }
10734 : | ALTER FOREIGN DATA_P WRAPPER name OWNER TO RoleSpec
10735 : {
10736 20 : AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
10737 :
10738 20 : n->objectType = OBJECT_FDW;
10739 20 : n->object = (Node *) makeString($5);
10740 20 : n->newowner = $8;
10741 20 : $$ = (Node *) n;
10742 : }
10743 : | ALTER SERVER name OWNER TO RoleSpec
10744 : {
10745 68 : AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
10746 :
10747 68 : n->objectType = OBJECT_FOREIGN_SERVER;
10748 68 : n->object = (Node *) makeString($3);
10749 68 : n->newowner = $6;
10750 68 : $$ = (Node *) n;
10751 : }
10752 : | ALTER EVENT TRIGGER name OWNER TO RoleSpec
10753 : {
10754 14 : AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
10755 :
10756 14 : n->objectType = OBJECT_EVENT_TRIGGER;
10757 14 : n->object = (Node *) makeString($4);
10758 14 : n->newowner = $7;
10759 14 : $$ = (Node *) n;
10760 : }
10761 : | ALTER PUBLICATION name OWNER TO RoleSpec
10762 : {
10763 36 : AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
10764 :
10765 36 : n->objectType = OBJECT_PUBLICATION;
10766 36 : n->object = (Node *) makeString($3);
10767 36 : n->newowner = $6;
10768 36 : $$ = (Node *) n;
10769 : }
10770 : | ALTER SUBSCRIPTION name OWNER TO RoleSpec
10771 : {
10772 18 : AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
10773 :
10774 18 : n->objectType = OBJECT_SUBSCRIPTION;
10775 18 : n->object = (Node *) makeString($3);
10776 18 : n->newowner = $6;
10777 18 : $$ = (Node *) n;
10778 : }
10779 : ;
10780 :
10781 :
10782 : /*****************************************************************************
10783 : *
10784 : * CREATE PUBLICATION name [WITH options]
10785 : *
10786 : * CREATE PUBLICATION FOR ALL pub_all_obj_type [, ...] [WITH options]
10787 : *
10788 : * pub_all_obj_type is one of:
10789 : *
10790 : * TABLES
10791 : * SEQUENCES
10792 : *
10793 : * CREATE PUBLICATION FOR pub_obj [, ...] [WITH options]
10794 : *
10795 : * pub_obj is one of:
10796 : *
10797 : * TABLE table [, ...]
10798 : * TABLES IN SCHEMA schema [, ...]
10799 : *
10800 : *****************************************************************************/
10801 :
10802 : CreatePublicationStmt:
10803 : CREATE PUBLICATION name opt_definition
10804 : {
10805 146 : CreatePublicationStmt *n = makeNode(CreatePublicationStmt);
10806 :
10807 146 : n->pubname = $3;
10808 146 : n->options = $4;
10809 146 : $$ = (Node *) n;
10810 : }
10811 : | CREATE PUBLICATION name FOR pub_all_obj_type_list opt_definition
10812 : {
10813 150 : CreatePublicationStmt *n = makeNode(CreatePublicationStmt);
10814 :
10815 150 : n->pubname = $3;
10816 150 : preprocess_pub_all_objtype_list($5, &n->for_all_tables,
10817 : &n->for_all_sequences,
10818 : yyscanner);
10819 138 : n->options = $6;
10820 138 : $$ = (Node *) n;
10821 : }
10822 : | CREATE PUBLICATION name FOR pub_obj_list opt_definition
10823 : {
10824 660 : CreatePublicationStmt *n = makeNode(CreatePublicationStmt);
10825 :
10826 660 : n->pubname = $3;
10827 660 : n->options = $6;
10828 660 : n->pubobjects = (List *) $5;
10829 660 : preprocess_pubobj_list(n->pubobjects, yyscanner);
10830 630 : $$ = (Node *) n;
10831 : }
10832 : ;
10833 :
10834 : /*
10835 : * FOR TABLE and FOR TABLES IN SCHEMA specifications
10836 : *
10837 : * This rule parses publication objects with and without keyword prefixes.
10838 : *
10839 : * The actual type of the object without keyword prefix depends on the previous
10840 : * one with keyword prefix. It will be preprocessed in preprocess_pubobj_list().
10841 : *
10842 : * For the object without keyword prefix, we cannot just use relation_expr here,
10843 : * because some extended expressions in relation_expr cannot be used as a
10844 : * schemaname and we cannot differentiate it. So, we extract the rules from
10845 : * relation_expr here.
10846 : */
10847 : PublicationObjSpec:
10848 : TABLE relation_expr opt_column_list OptWhereClause
10849 : {
10850 1328 : $$ = makeNode(PublicationObjSpec);
10851 1328 : $$->pubobjtype = PUBLICATIONOBJ_TABLE;
10852 1328 : $$->pubtable = makeNode(PublicationTable);
10853 1328 : $$->pubtable->relation = $2;
10854 1328 : $$->pubtable->columns = $3;
10855 1328 : $$->pubtable->whereClause = $4;
10856 : }
10857 : | TABLES IN_P SCHEMA ColId
10858 : {
10859 372 : $$ = makeNode(PublicationObjSpec);
10860 372 : $$->pubobjtype = PUBLICATIONOBJ_TABLES_IN_SCHEMA;
10861 372 : $$->name = $4;
10862 372 : $$->location = @4;
10863 : }
10864 : | TABLES IN_P SCHEMA CURRENT_SCHEMA
10865 : {
10866 18 : $$ = makeNode(PublicationObjSpec);
10867 18 : $$->pubobjtype = PUBLICATIONOBJ_TABLES_IN_CUR_SCHEMA;
10868 18 : $$->location = @4;
10869 : }
10870 : | ColId opt_column_list OptWhereClause
10871 : {
10872 132 : $$ = makeNode(PublicationObjSpec);
10873 132 : $$->pubobjtype = PUBLICATIONOBJ_CONTINUATION;
10874 : /*
10875 : * If either a row filter or column list is specified, create
10876 : * a PublicationTable object.
10877 : */
10878 132 : if ($2 || $3)
10879 : {
10880 : /*
10881 : * The OptWhereClause must be stored here but it is
10882 : * valid only for tables. For non-table objects, an
10883 : * error will be thrown later via
10884 : * preprocess_pubobj_list().
10885 : */
10886 42 : $$->pubtable = makeNode(PublicationTable);
10887 42 : $$->pubtable->relation = makeRangeVar(NULL, $1, @1);
10888 42 : $$->pubtable->columns = $2;
10889 42 : $$->pubtable->whereClause = $3;
10890 : }
10891 : else
10892 : {
10893 90 : $$->name = $1;
10894 : }
10895 132 : $$->location = @1;
10896 : }
10897 : | ColId indirection opt_column_list OptWhereClause
10898 : {
10899 32 : $$ = makeNode(PublicationObjSpec);
10900 32 : $$->pubobjtype = PUBLICATIONOBJ_CONTINUATION;
10901 32 : $$->pubtable = makeNode(PublicationTable);
10902 32 : $$->pubtable->relation = makeRangeVarFromQualifiedName($1, $2, @1, yyscanner);
10903 32 : $$->pubtable->columns = $3;
10904 32 : $$->pubtable->whereClause = $4;
10905 32 : $$->location = @1;
10906 : }
10907 : /* grammar like tablename * , ONLY tablename, ONLY ( tablename ) */
10908 : | extended_relation_expr opt_column_list OptWhereClause
10909 : {
10910 6 : $$ = makeNode(PublicationObjSpec);
10911 6 : $$->pubobjtype = PUBLICATIONOBJ_CONTINUATION;
10912 6 : $$->pubtable = makeNode(PublicationTable);
10913 6 : $$->pubtable->relation = $1;
10914 6 : $$->pubtable->columns = $2;
10915 6 : $$->pubtable->whereClause = $3;
10916 : }
10917 : | CURRENT_SCHEMA
10918 : {
10919 18 : $$ = makeNode(PublicationObjSpec);
10920 18 : $$->pubobjtype = PUBLICATIONOBJ_CONTINUATION;
10921 18 : $$->location = @1;
10922 : }
10923 : ;
10924 :
10925 : pub_obj_list: PublicationObjSpec
10926 1650 : { $$ = list_make1($1); }
10927 : | pub_obj_list ',' PublicationObjSpec
10928 256 : { $$ = lappend($1, $3); }
10929 : ;
10930 :
10931 : PublicationAllObjSpec:
10932 : ALL TABLES
10933 : {
10934 130 : $$ = makeNode(PublicationAllObjSpec);
10935 130 : $$->pubobjtype = PUBLICATION_ALL_TABLES;
10936 130 : $$->location = @1;
10937 : }
10938 : | ALL SEQUENCES
10939 : {
10940 58 : $$ = makeNode(PublicationAllObjSpec);
10941 58 : $$->pubobjtype = PUBLICATION_ALL_SEQUENCES;
10942 58 : $$->location = @1;
10943 : }
10944 : ;
10945 :
10946 : pub_all_obj_type_list: PublicationAllObjSpec
10947 150 : { $$ = list_make1($1); }
10948 : | pub_all_obj_type_list ',' PublicationAllObjSpec
10949 38 : { $$ = lappend($1, $3); }
10950 : ;
10951 :
10952 :
10953 : /*****************************************************************************
10954 : *
10955 : * ALTER PUBLICATION name SET ( options )
10956 : *
10957 : * ALTER PUBLICATION name ADD pub_obj [, ...]
10958 : *
10959 : * ALTER PUBLICATION name DROP pub_obj [, ...]
10960 : *
10961 : * ALTER PUBLICATION name SET pub_obj [, ...]
10962 : *
10963 : * pub_obj is one of:
10964 : *
10965 : * TABLE table_name [, ...]
10966 : * TABLES IN SCHEMA schema_name [, ...]
10967 : *
10968 : *****************************************************************************/
10969 :
10970 : AlterPublicationStmt:
10971 : ALTER PUBLICATION name SET definition
10972 : {
10973 116 : AlterPublicationStmt *n = makeNode(AlterPublicationStmt);
10974 :
10975 116 : n->pubname = $3;
10976 116 : n->options = $5;
10977 116 : $$ = (Node *) n;
10978 : }
10979 : | ALTER PUBLICATION name ADD_P pub_obj_list
10980 : {
10981 370 : AlterPublicationStmt *n = makeNode(AlterPublicationStmt);
10982 :
10983 370 : n->pubname = $3;
10984 370 : n->pubobjects = $5;
10985 370 : preprocess_pubobj_list(n->pubobjects, yyscanner);
10986 364 : n->action = AP_AddObjects;
10987 364 : $$ = (Node *) n;
10988 : }
10989 : | ALTER PUBLICATION name SET pub_obj_list
10990 : {
10991 464 : AlterPublicationStmt *n = makeNode(AlterPublicationStmt);
10992 :
10993 464 : n->pubname = $3;
10994 464 : n->pubobjects = $5;
10995 464 : preprocess_pubobj_list(n->pubobjects, yyscanner);
10996 464 : n->action = AP_SetObjects;
10997 464 : $$ = (Node *) n;
10998 : }
10999 : | ALTER PUBLICATION name DROP pub_obj_list
11000 : {
11001 156 : AlterPublicationStmt *n = makeNode(AlterPublicationStmt);
11002 :
11003 156 : n->pubname = $3;
11004 156 : n->pubobjects = $5;
11005 156 : preprocess_pubobj_list(n->pubobjects, yyscanner);
11006 156 : n->action = AP_DropObjects;
11007 156 : $$ = (Node *) n;
11008 : }
11009 : ;
11010 :
11011 : /*****************************************************************************
11012 : *
11013 : * CREATE SUBSCRIPTION name ...
11014 : *
11015 : *****************************************************************************/
11016 :
11017 : CreateSubscriptionStmt:
11018 : CREATE SUBSCRIPTION name CONNECTION Sconst PUBLICATION name_list opt_definition
11019 : {
11020 : CreateSubscriptionStmt *n =
11021 484 : makeNode(CreateSubscriptionStmt);
11022 484 : n->subname = $3;
11023 484 : n->conninfo = $5;
11024 484 : n->publication = $7;
11025 484 : n->options = $8;
11026 484 : $$ = (Node *) n;
11027 : }
11028 : ;
11029 :
11030 : /*****************************************************************************
11031 : *
11032 : * ALTER SUBSCRIPTION name ...
11033 : *
11034 : *****************************************************************************/
11035 :
11036 : AlterSubscriptionStmt:
11037 : ALTER SUBSCRIPTION name SET definition
11038 : {
11039 : AlterSubscriptionStmt *n =
11040 218 : makeNode(AlterSubscriptionStmt);
11041 :
11042 218 : n->kind = ALTER_SUBSCRIPTION_OPTIONS;
11043 218 : n->subname = $3;
11044 218 : n->options = $5;
11045 218 : $$ = (Node *) n;
11046 : }
11047 : | ALTER SUBSCRIPTION name CONNECTION Sconst
11048 : {
11049 : AlterSubscriptionStmt *n =
11050 26 : makeNode(AlterSubscriptionStmt);
11051 :
11052 26 : n->kind = ALTER_SUBSCRIPTION_CONNECTION;
11053 26 : n->subname = $3;
11054 26 : n->conninfo = $5;
11055 26 : $$ = (Node *) n;
11056 : }
11057 : | ALTER SUBSCRIPTION name REFRESH PUBLICATION opt_definition
11058 : {
11059 : AlterSubscriptionStmt *n =
11060 68 : makeNode(AlterSubscriptionStmt);
11061 :
11062 68 : n->kind = ALTER_SUBSCRIPTION_REFRESH_PUBLICATION;
11063 68 : n->subname = $3;
11064 68 : n->options = $6;
11065 68 : $$ = (Node *) n;
11066 : }
11067 : | ALTER SUBSCRIPTION name REFRESH SEQUENCES
11068 : {
11069 : AlterSubscriptionStmt *n =
11070 2 : makeNode(AlterSubscriptionStmt);
11071 :
11072 2 : n->kind = ALTER_SUBSCRIPTION_REFRESH_SEQUENCES;
11073 2 : n->subname = $3;
11074 2 : $$ = (Node *) n;
11075 : }
11076 : | ALTER SUBSCRIPTION name ADD_P PUBLICATION name_list opt_definition
11077 : {
11078 : AlterSubscriptionStmt *n =
11079 28 : makeNode(AlterSubscriptionStmt);
11080 :
11081 28 : n->kind = ALTER_SUBSCRIPTION_ADD_PUBLICATION;
11082 28 : n->subname = $3;
11083 28 : n->publication = $6;
11084 28 : n->options = $7;
11085 28 : $$ = (Node *) n;
11086 : }
11087 : | ALTER SUBSCRIPTION name DROP PUBLICATION name_list opt_definition
11088 : {
11089 : AlterSubscriptionStmt *n =
11090 26 : makeNode(AlterSubscriptionStmt);
11091 :
11092 26 : n->kind = ALTER_SUBSCRIPTION_DROP_PUBLICATION;
11093 26 : n->subname = $3;
11094 26 : n->publication = $6;
11095 26 : n->options = $7;
11096 26 : $$ = (Node *) n;
11097 : }
11098 : | ALTER SUBSCRIPTION name SET PUBLICATION name_list opt_definition
11099 : {
11100 : AlterSubscriptionStmt *n =
11101 44 : makeNode(AlterSubscriptionStmt);
11102 :
11103 44 : n->kind = ALTER_SUBSCRIPTION_SET_PUBLICATION;
11104 44 : n->subname = $3;
11105 44 : n->publication = $6;
11106 44 : n->options = $7;
11107 44 : $$ = (Node *) n;
11108 : }
11109 : | ALTER SUBSCRIPTION name ENABLE_P
11110 : {
11111 : AlterSubscriptionStmt *n =
11112 62 : makeNode(AlterSubscriptionStmt);
11113 :
11114 62 : n->kind = ALTER_SUBSCRIPTION_ENABLED;
11115 62 : n->subname = $3;
11116 62 : n->options = list_make1(makeDefElem("enabled",
11117 : (Node *) makeBoolean(true), @1));
11118 62 : $$ = (Node *) n;
11119 : }
11120 : | ALTER SUBSCRIPTION name DISABLE_P
11121 : {
11122 : AlterSubscriptionStmt *n =
11123 44 : makeNode(AlterSubscriptionStmt);
11124 :
11125 44 : n->kind = ALTER_SUBSCRIPTION_ENABLED;
11126 44 : n->subname = $3;
11127 44 : n->options = list_make1(makeDefElem("enabled",
11128 : (Node *) makeBoolean(false), @1));
11129 44 : $$ = (Node *) n;
11130 : }
11131 : | ALTER SUBSCRIPTION name SKIP definition
11132 : {
11133 : AlterSubscriptionStmt *n =
11134 24 : makeNode(AlterSubscriptionStmt);
11135 :
11136 24 : n->kind = ALTER_SUBSCRIPTION_SKIP;
11137 24 : n->subname = $3;
11138 24 : n->options = $5;
11139 24 : $$ = (Node *) n;
11140 : }
11141 : ;
11142 :
11143 : /*****************************************************************************
11144 : *
11145 : * DROP SUBSCRIPTION [ IF EXISTS ] name
11146 : *
11147 : *****************************************************************************/
11148 :
11149 : DropSubscriptionStmt: DROP SUBSCRIPTION name opt_drop_behavior
11150 : {
11151 244 : DropSubscriptionStmt *n = makeNode(DropSubscriptionStmt);
11152 :
11153 244 : n->subname = $3;
11154 244 : n->missing_ok = false;
11155 244 : n->behavior = $4;
11156 244 : $$ = (Node *) n;
11157 : }
11158 : | DROP SUBSCRIPTION IF_P EXISTS name opt_drop_behavior
11159 : {
11160 6 : DropSubscriptionStmt *n = makeNode(DropSubscriptionStmt);
11161 :
11162 6 : n->subname = $5;
11163 6 : n->missing_ok = true;
11164 6 : n->behavior = $6;
11165 6 : $$ = (Node *) n;
11166 : }
11167 : ;
11168 :
11169 : /*****************************************************************************
11170 : *
11171 : * QUERY: Define Rewrite Rule
11172 : *
11173 : *****************************************************************************/
11174 :
11175 : RuleStmt: CREATE opt_or_replace RULE name AS
11176 : ON event TO qualified_name where_clause
11177 : DO opt_instead RuleActionList
11178 : {
11179 1102 : RuleStmt *n = makeNode(RuleStmt);
11180 :
11181 1102 : n->replace = $2;
11182 1102 : n->relation = $9;
11183 1102 : n->rulename = $4;
11184 1102 : n->whereClause = $10;
11185 1102 : n->event = $7;
11186 1102 : n->instead = $12;
11187 1102 : n->actions = $13;
11188 1102 : $$ = (Node *) n;
11189 : }
11190 : ;
11191 :
11192 : RuleActionList:
11193 164 : NOTHING { $$ = NIL; }
11194 892 : | RuleActionStmt { $$ = list_make1($1); }
11195 46 : | '(' RuleActionMulti ')' { $$ = $2; }
11196 : ;
11197 :
11198 : /* the thrashing around here is to discard "empty" statements... */
11199 : RuleActionMulti:
11200 : RuleActionMulti ';' RuleActionStmtOrEmpty
11201 62 : { if ($3 != NULL)
11202 46 : $$ = lappend($1, $3);
11203 : else
11204 16 : $$ = $1;
11205 : }
11206 : | RuleActionStmtOrEmpty
11207 46 : { if ($1 != NULL)
11208 46 : $$ = list_make1($1);
11209 : else
11210 0 : $$ = NIL;
11211 : }
11212 : ;
11213 :
11214 : RuleActionStmt:
11215 : SelectStmt
11216 : | InsertStmt
11217 : | UpdateStmt
11218 : | DeleteStmt
11219 : | NotifyStmt
11220 : ;
11221 :
11222 : RuleActionStmtOrEmpty:
11223 92 : RuleActionStmt { $$ = $1; }
11224 16 : | /*EMPTY*/ { $$ = NULL; }
11225 : ;
11226 :
11227 18 : event: SELECT { $$ = CMD_SELECT; }
11228 436 : | UPDATE { $$ = CMD_UPDATE; }
11229 164 : | DELETE_P { $$ = CMD_DELETE; }
11230 484 : | INSERT { $$ = CMD_INSERT; }
11231 : ;
11232 :
11233 : opt_instead:
11234 760 : INSTEAD { $$ = true; }
11235 156 : | ALSO { $$ = false; }
11236 186 : | /*EMPTY*/ { $$ = false; }
11237 : ;
11238 :
11239 :
11240 : /*****************************************************************************
11241 : *
11242 : * QUERY:
11243 : * NOTIFY <identifier> can appear both in rule bodies and
11244 : * as a query-level command
11245 : *
11246 : *****************************************************************************/
11247 :
11248 : NotifyStmt: NOTIFY ColId notify_payload
11249 : {
11250 148 : NotifyStmt *n = makeNode(NotifyStmt);
11251 :
11252 148 : n->conditionname = $2;
11253 148 : n->payload = $3;
11254 148 : $$ = (Node *) n;
11255 : }
11256 : ;
11257 :
11258 : notify_payload:
11259 82 : ',' Sconst { $$ = $2; }
11260 66 : | /*EMPTY*/ { $$ = NULL; }
11261 : ;
11262 :
11263 : ListenStmt: LISTEN ColId
11264 : {
11265 74 : ListenStmt *n = makeNode(ListenStmt);
11266 :
11267 74 : n->conditionname = $2;
11268 74 : $$ = (Node *) n;
11269 : }
11270 : ;
11271 :
11272 : UnlistenStmt:
11273 : UNLISTEN ColId
11274 : {
11275 6 : UnlistenStmt *n = makeNode(UnlistenStmt);
11276 :
11277 6 : n->conditionname = $2;
11278 6 : $$ = (Node *) n;
11279 : }
11280 : | UNLISTEN '*'
11281 : {
11282 32 : UnlistenStmt *n = makeNode(UnlistenStmt);
11283 :
11284 32 : n->conditionname = NULL;
11285 32 : $$ = (Node *) n;
11286 : }
11287 : ;
11288 :
11289 :
11290 : /*****************************************************************************
11291 : *
11292 : * Transactions:
11293 : *
11294 : * BEGIN / COMMIT / ROLLBACK
11295 : * (also older versions END / ABORT)
11296 : *
11297 : *****************************************************************************/
11298 :
11299 : TransactionStmt:
11300 : ABORT_P opt_transaction opt_transaction_chain
11301 : {
11302 782 : TransactionStmt *n = makeNode(TransactionStmt);
11303 :
11304 782 : n->kind = TRANS_STMT_ROLLBACK;
11305 782 : n->options = NIL;
11306 782 : n->chain = $3;
11307 782 : n->location = -1;
11308 782 : $$ = (Node *) n;
11309 : }
11310 : | START TRANSACTION transaction_mode_list_or_empty
11311 : {
11312 1646 : TransactionStmt *n = makeNode(TransactionStmt);
11313 :
11314 1646 : n->kind = TRANS_STMT_START;
11315 1646 : n->options = $3;
11316 1646 : n->location = -1;
11317 1646 : $$ = (Node *) n;
11318 : }
11319 : | COMMIT opt_transaction opt_transaction_chain
11320 : {
11321 17690 : TransactionStmt *n = makeNode(TransactionStmt);
11322 :
11323 17690 : n->kind = TRANS_STMT_COMMIT;
11324 17690 : n->options = NIL;
11325 17690 : n->chain = $3;
11326 17690 : n->location = -1;
11327 17690 : $$ = (Node *) n;
11328 : }
11329 : | ROLLBACK opt_transaction opt_transaction_chain
11330 : {
11331 2748 : TransactionStmt *n = makeNode(TransactionStmt);
11332 :
11333 2748 : n->kind = TRANS_STMT_ROLLBACK;
11334 2748 : n->options = NIL;
11335 2748 : n->chain = $3;
11336 2748 : n->location = -1;
11337 2748 : $$ = (Node *) n;
11338 : }
11339 : | SAVEPOINT ColId
11340 : {
11341 1996 : TransactionStmt *n = makeNode(TransactionStmt);
11342 :
11343 1996 : n->kind = TRANS_STMT_SAVEPOINT;
11344 1996 : n->savepoint_name = $2;
11345 1996 : n->location = @2;
11346 1996 : $$ = (Node *) n;
11347 : }
11348 : | RELEASE SAVEPOINT ColId
11349 : {
11350 208 : TransactionStmt *n = makeNode(TransactionStmt);
11351 :
11352 208 : n->kind = TRANS_STMT_RELEASE;
11353 208 : n->savepoint_name = $3;
11354 208 : n->location = @3;
11355 208 : $$ = (Node *) n;
11356 : }
11357 : | RELEASE ColId
11358 : {
11359 86 : TransactionStmt *n = makeNode(TransactionStmt);
11360 :
11361 86 : n->kind = TRANS_STMT_RELEASE;
11362 86 : n->savepoint_name = $2;
11363 86 : n->location = @2;
11364 86 : $$ = (Node *) n;
11365 : }
11366 : | ROLLBACK opt_transaction TO SAVEPOINT ColId
11367 : {
11368 246 : TransactionStmt *n = makeNode(TransactionStmt);
11369 :
11370 246 : n->kind = TRANS_STMT_ROLLBACK_TO;
11371 246 : n->savepoint_name = $5;
11372 246 : n->location = @5;
11373 246 : $$ = (Node *) n;
11374 : }
11375 : | ROLLBACK opt_transaction TO ColId
11376 : {
11377 496 : TransactionStmt *n = makeNode(TransactionStmt);
11378 :
11379 496 : n->kind = TRANS_STMT_ROLLBACK_TO;
11380 496 : n->savepoint_name = $4;
11381 496 : n->location = @4;
11382 496 : $$ = (Node *) n;
11383 : }
11384 : | PREPARE TRANSACTION Sconst
11385 : {
11386 680 : TransactionStmt *n = makeNode(TransactionStmt);
11387 :
11388 680 : n->kind = TRANS_STMT_PREPARE;
11389 680 : n->gid = $3;
11390 680 : n->location = @3;
11391 680 : $$ = (Node *) n;
11392 : }
11393 : | COMMIT PREPARED Sconst
11394 : {
11395 514 : TransactionStmt *n = makeNode(TransactionStmt);
11396 :
11397 514 : n->kind = TRANS_STMT_COMMIT_PREPARED;
11398 514 : n->gid = $3;
11399 514 : n->location = @3;
11400 514 : $$ = (Node *) n;
11401 : }
11402 : | ROLLBACK PREPARED Sconst
11403 : {
11404 86 : TransactionStmt *n = makeNode(TransactionStmt);
11405 :
11406 86 : n->kind = TRANS_STMT_ROLLBACK_PREPARED;
11407 86 : n->gid = $3;
11408 86 : n->location = @3;
11409 86 : $$ = (Node *) n;
11410 : }
11411 : ;
11412 :
11413 : TransactionStmtLegacy:
11414 : BEGIN_P opt_transaction transaction_mode_list_or_empty
11415 : {
11416 21032 : TransactionStmt *n = makeNode(TransactionStmt);
11417 :
11418 21032 : n->kind = TRANS_STMT_BEGIN;
11419 21032 : n->options = $3;
11420 21032 : n->location = -1;
11421 21032 : $$ = (Node *) n;
11422 : }
11423 : | END_P opt_transaction opt_transaction_chain
11424 : {
11425 370 : TransactionStmt *n = makeNode(TransactionStmt);
11426 :
11427 370 : n->kind = TRANS_STMT_COMMIT;
11428 370 : n->options = NIL;
11429 370 : n->chain = $3;
11430 370 : n->location = -1;
11431 370 : $$ = (Node *) n;
11432 : }
11433 : ;
11434 :
11435 : opt_transaction: WORK
11436 : | TRANSACTION
11437 : | /*EMPTY*/
11438 : ;
11439 :
11440 : transaction_mode_item:
11441 : ISOLATION LEVEL iso_level
11442 6966 : { $$ = makeDefElem("transaction_isolation",
11443 6966 : makeStringConst($3, @3), @1); }
11444 : | READ ONLY
11445 1422 : { $$ = makeDefElem("transaction_read_only",
11446 1422 : makeIntConst(true, @1), @1); }
11447 : | READ WRITE
11448 90 : { $$ = makeDefElem("transaction_read_only",
11449 90 : makeIntConst(false, @1), @1); }
11450 : | DEFERRABLE
11451 44 : { $$ = makeDefElem("transaction_deferrable",
11452 : makeIntConst(true, @1), @1); }
11453 : | NOT DEFERRABLE
11454 10 : { $$ = makeDefElem("transaction_deferrable",
11455 10 : makeIntConst(false, @1), @1); }
11456 : ;
11457 :
11458 : /* Syntax with commas is SQL-spec, without commas is Postgres historical */
11459 : transaction_mode_list:
11460 : transaction_mode_item
11461 7182 : { $$ = list_make1($1); }
11462 : | transaction_mode_list ',' transaction_mode_item
11463 944 : { $$ = lappend($1, $3); }
11464 : | transaction_mode_list transaction_mode_item
11465 406 : { $$ = lappend($1, $2); }
11466 : ;
11467 :
11468 : transaction_mode_list_or_empty:
11469 : transaction_mode_list
11470 : | /* EMPTY */
11471 16100 : { $$ = NIL; }
11472 : ;
11473 :
11474 : opt_transaction_chain:
11475 120 : AND CHAIN { $$ = true; }
11476 2 : | AND NO CHAIN { $$ = false; }
11477 21468 : | /* EMPTY */ { $$ = false; }
11478 : ;
11479 :
11480 :
11481 : /*****************************************************************************
11482 : *
11483 : * QUERY:
11484 : * CREATE [ OR REPLACE ] [ TEMP ] VIEW <viewname> '('target-list ')'
11485 : * AS <query> [ WITH [ CASCADED | LOCAL ] CHECK OPTION ]
11486 : *
11487 : *****************************************************************************/
11488 :
11489 : ViewStmt: CREATE OptTemp VIEW qualified_name opt_column_list opt_reloptions
11490 : AS SelectStmt opt_check_option
11491 : {
11492 17124 : ViewStmt *n = makeNode(ViewStmt);
11493 :
11494 17124 : n->view = $4;
11495 17124 : n->view->relpersistence = $2;
11496 17124 : n->aliases = $5;
11497 17124 : n->query = $8;
11498 17124 : n->replace = false;
11499 17124 : n->options = $6;
11500 17124 : n->withCheckOption = $9;
11501 17124 : $$ = (Node *) n;
11502 : }
11503 : | CREATE OR REPLACE OptTemp VIEW qualified_name opt_column_list opt_reloptions
11504 : AS SelectStmt opt_check_option
11505 : {
11506 244 : ViewStmt *n = makeNode(ViewStmt);
11507 :
11508 244 : n->view = $6;
11509 244 : n->view->relpersistence = $4;
11510 244 : n->aliases = $7;
11511 244 : n->query = $10;
11512 244 : n->replace = true;
11513 244 : n->options = $8;
11514 244 : n->withCheckOption = $11;
11515 244 : $$ = (Node *) n;
11516 : }
11517 : | CREATE OptTemp RECURSIVE VIEW qualified_name '(' columnList ')' opt_reloptions
11518 : AS SelectStmt opt_check_option
11519 : {
11520 8 : ViewStmt *n = makeNode(ViewStmt);
11521 :
11522 8 : n->view = $5;
11523 8 : n->view->relpersistence = $2;
11524 8 : n->aliases = $7;
11525 8 : n->query = makeRecursiveViewSelect(n->view->relname, n->aliases, $11);
11526 8 : n->replace = false;
11527 8 : n->options = $9;
11528 8 : n->withCheckOption = $12;
11529 8 : if (n->withCheckOption != NO_CHECK_OPTION)
11530 0 : ereport(ERROR,
11531 : (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
11532 : errmsg("WITH CHECK OPTION not supported on recursive views"),
11533 : parser_errposition(@12)));
11534 8 : $$ = (Node *) n;
11535 : }
11536 : | CREATE OR REPLACE OptTemp RECURSIVE VIEW qualified_name '(' columnList ')' opt_reloptions
11537 : AS SelectStmt opt_check_option
11538 : {
11539 6 : ViewStmt *n = makeNode(ViewStmt);
11540 :
11541 6 : n->view = $7;
11542 6 : n->view->relpersistence = $4;
11543 6 : n->aliases = $9;
11544 6 : n->query = makeRecursiveViewSelect(n->view->relname, n->aliases, $13);
11545 6 : n->replace = true;
11546 6 : n->options = $11;
11547 6 : n->withCheckOption = $14;
11548 6 : if (n->withCheckOption != NO_CHECK_OPTION)
11549 0 : ereport(ERROR,
11550 : (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
11551 : errmsg("WITH CHECK OPTION not supported on recursive views"),
11552 : parser_errposition(@14)));
11553 6 : $$ = (Node *) n;
11554 : }
11555 : ;
11556 :
11557 : opt_check_option:
11558 96 : WITH CHECK OPTION { $$ = CASCADED_CHECK_OPTION; }
11559 6 : | WITH CASCADED CHECK OPTION { $$ = CASCADED_CHECK_OPTION; }
11560 24 : | WITH LOCAL CHECK OPTION { $$ = LOCAL_CHECK_OPTION; }
11561 17256 : | /* EMPTY */ { $$ = NO_CHECK_OPTION; }
11562 : ;
11563 :
11564 : /*****************************************************************************
11565 : *
11566 : * QUERY:
11567 : * LOAD "filename"
11568 : *
11569 : *****************************************************************************/
11570 :
11571 : LoadStmt: LOAD file_name
11572 : {
11573 64 : LoadStmt *n = makeNode(LoadStmt);
11574 :
11575 64 : n->filename = $2;
11576 64 : $$ = (Node *) n;
11577 : }
11578 : ;
11579 :
11580 :
11581 : /*****************************************************************************
11582 : *
11583 : * CREATE DATABASE
11584 : *
11585 : *****************************************************************************/
11586 :
11587 : CreatedbStmt:
11588 : CREATE DATABASE name opt_with createdb_opt_list
11589 : {
11590 814 : CreatedbStmt *n = makeNode(CreatedbStmt);
11591 :
11592 814 : n->dbname = $3;
11593 814 : n->options = $5;
11594 814 : $$ = (Node *) n;
11595 : }
11596 : ;
11597 :
11598 : createdb_opt_list:
11599 672 : createdb_opt_items { $$ = $1; }
11600 210 : | /* EMPTY */ { $$ = NIL; }
11601 : ;
11602 :
11603 : createdb_opt_items:
11604 672 : createdb_opt_item { $$ = list_make1($1); }
11605 1016 : | createdb_opt_items createdb_opt_item { $$ = lappend($1, $2); }
11606 : ;
11607 :
11608 : createdb_opt_item:
11609 : createdb_opt_name opt_equal NumericOnly
11610 : {
11611 274 : $$ = makeDefElem($1, $3, @1);
11612 : }
11613 : | createdb_opt_name opt_equal opt_boolean_or_string
11614 : {
11615 1414 : $$ = makeDefElem($1, (Node *) makeString($3), @1);
11616 : }
11617 : | createdb_opt_name opt_equal DEFAULT
11618 : {
11619 0 : $$ = makeDefElem($1, NULL, @1);
11620 : }
11621 : ;
11622 :
11623 : /*
11624 : * Ideally we'd use ColId here, but that causes shift/reduce conflicts against
11625 : * the ALTER DATABASE SET/RESET syntaxes. Instead call out specific keywords
11626 : * we need, and allow IDENT so that database option names don't have to be
11627 : * parser keywords unless they are already keywords for other reasons.
11628 : *
11629 : * XXX this coding technique is fragile since if someone makes a formerly
11630 : * non-keyword option name into a keyword and forgets to add it here, the
11631 : * option will silently break. Best defense is to provide a regression test
11632 : * exercising every such option, at least at the syntax level.
11633 : */
11634 : createdb_opt_name:
11635 1180 : IDENT { $$ = $1; }
11636 2 : | CONNECTION LIMIT { $$ = pstrdup("connection_limit"); }
11637 106 : | ENCODING { $$ = pstrdup($1); }
11638 0 : | LOCATION { $$ = pstrdup($1); }
11639 2 : | OWNER { $$ = pstrdup($1); }
11640 34 : | TABLESPACE { $$ = pstrdup($1); }
11641 364 : | TEMPLATE { $$ = pstrdup($1); }
11642 : ;
11643 :
11644 : /*
11645 : * Though the equals sign doesn't match other WITH options, pg_dump uses
11646 : * equals for backward compatibility, and it doesn't seem worth removing it.
11647 : */
11648 : opt_equal: '='
11649 : | /*EMPTY*/
11650 : ;
11651 :
11652 :
11653 : /*****************************************************************************
11654 : *
11655 : * ALTER DATABASE
11656 : *
11657 : *****************************************************************************/
11658 :
11659 : AlterDatabaseStmt:
11660 : ALTER DATABASE name WITH createdb_opt_list
11661 : {
11662 2 : AlterDatabaseStmt *n = makeNode(AlterDatabaseStmt);
11663 :
11664 2 : n->dbname = $3;
11665 2 : n->options = $5;
11666 2 : $$ = (Node *) n;
11667 : }
11668 : | ALTER DATABASE name createdb_opt_list
11669 : {
11670 66 : AlterDatabaseStmt *n = makeNode(AlterDatabaseStmt);
11671 :
11672 66 : n->dbname = $3;
11673 66 : n->options = $4;
11674 66 : $$ = (Node *) n;
11675 : }
11676 : | ALTER DATABASE name SET TABLESPACE name
11677 : {
11678 22 : AlterDatabaseStmt *n = makeNode(AlterDatabaseStmt);
11679 :
11680 22 : n->dbname = $3;
11681 22 : n->options = list_make1(makeDefElem("tablespace",
11682 : (Node *) makeString($6), @6));
11683 22 : $$ = (Node *) n;
11684 : }
11685 : | ALTER DATABASE name REFRESH COLLATION VERSION_P
11686 : {
11687 6 : AlterDatabaseRefreshCollStmt *n = makeNode(AlterDatabaseRefreshCollStmt);
11688 :
11689 6 : n->dbname = $3;
11690 6 : $$ = (Node *) n;
11691 : }
11692 : ;
11693 :
11694 : AlterDatabaseSetStmt:
11695 : ALTER DATABASE name SetResetClause
11696 : {
11697 1254 : AlterDatabaseSetStmt *n = makeNode(AlterDatabaseSetStmt);
11698 :
11699 1254 : n->dbname = $3;
11700 1254 : n->setstmt = $4;
11701 1254 : $$ = (Node *) n;
11702 : }
11703 : ;
11704 :
11705 :
11706 : /*****************************************************************************
11707 : *
11708 : * DROP DATABASE [ IF EXISTS ] dbname [ [ WITH ] ( options ) ]
11709 : *
11710 : * This is implicitly CASCADE, no need for drop behavior
11711 : *****************************************************************************/
11712 :
11713 : DropdbStmt: DROP DATABASE name
11714 : {
11715 98 : DropdbStmt *n = makeNode(DropdbStmt);
11716 :
11717 98 : n->dbname = $3;
11718 98 : n->missing_ok = false;
11719 98 : n->options = NULL;
11720 98 : $$ = (Node *) n;
11721 : }
11722 : | DROP DATABASE IF_P EXISTS name
11723 : {
11724 4 : DropdbStmt *n = makeNode(DropdbStmt);
11725 :
11726 4 : n->dbname = $5;
11727 4 : n->missing_ok = true;
11728 4 : n->options = NULL;
11729 4 : $$ = (Node *) n;
11730 : }
11731 : | DROP DATABASE name opt_with '(' drop_option_list ')'
11732 : {
11733 14 : DropdbStmt *n = makeNode(DropdbStmt);
11734 :
11735 14 : n->dbname = $3;
11736 14 : n->missing_ok = false;
11737 14 : n->options = $6;
11738 14 : $$ = (Node *) n;
11739 : }
11740 : | DROP DATABASE IF_P EXISTS name opt_with '(' drop_option_list ')'
11741 : {
11742 12 : DropdbStmt *n = makeNode(DropdbStmt);
11743 :
11744 12 : n->dbname = $5;
11745 12 : n->missing_ok = true;
11746 12 : n->options = $8;
11747 12 : $$ = (Node *) n;
11748 : }
11749 : ;
11750 :
11751 : drop_option_list:
11752 : drop_option
11753 : {
11754 26 : $$ = list_make1((Node *) $1);
11755 : }
11756 : | drop_option_list ',' drop_option
11757 : {
11758 0 : $$ = lappend($1, (Node *) $3);
11759 : }
11760 : ;
11761 :
11762 : /*
11763 : * Currently only the FORCE option is supported, but the syntax is designed
11764 : * to be extensible so that we can add more options in the future if required.
11765 : */
11766 : drop_option:
11767 : FORCE
11768 : {
11769 26 : $$ = makeDefElem("force", NULL, @1);
11770 : }
11771 : ;
11772 :
11773 : /*****************************************************************************
11774 : *
11775 : * ALTER COLLATION
11776 : *
11777 : *****************************************************************************/
11778 :
11779 : AlterCollationStmt: ALTER COLLATION any_name REFRESH VERSION_P
11780 : {
11781 6 : AlterCollationStmt *n = makeNode(AlterCollationStmt);
11782 :
11783 6 : n->collname = $3;
11784 6 : $$ = (Node *) n;
11785 : }
11786 : ;
11787 :
11788 :
11789 : /*****************************************************************************
11790 : *
11791 : * ALTER SYSTEM
11792 : *
11793 : * This is used to change configuration parameters persistently.
11794 : *****************************************************************************/
11795 :
11796 : AlterSystemStmt:
11797 : ALTER SYSTEM_P SET generic_set
11798 : {
11799 134 : AlterSystemStmt *n = makeNode(AlterSystemStmt);
11800 :
11801 134 : n->setstmt = $4;
11802 134 : $$ = (Node *) n;
11803 : }
11804 : | ALTER SYSTEM_P RESET generic_reset
11805 : {
11806 58 : AlterSystemStmt *n = makeNode(AlterSystemStmt);
11807 :
11808 58 : n->setstmt = $4;
11809 58 : $$ = (Node *) n;
11810 : }
11811 : ;
11812 :
11813 :
11814 : /*****************************************************************************
11815 : *
11816 : * Manipulate a domain
11817 : *
11818 : *****************************************************************************/
11819 :
11820 : CreateDomainStmt:
11821 : CREATE DOMAIN_P any_name opt_as Typename ColQualList
11822 : {
11823 1474 : CreateDomainStmt *n = makeNode(CreateDomainStmt);
11824 :
11825 1474 : n->domainname = $3;
11826 1474 : n->typeName = $5;
11827 1474 : SplitColQualList($6, &n->constraints, &n->collClause,
11828 : yyscanner);
11829 1474 : $$ = (Node *) n;
11830 : }
11831 : ;
11832 :
11833 : AlterDomainStmt:
11834 : /* ALTER DOMAIN <domain> {SET DEFAULT <expr>|DROP DEFAULT} */
11835 : ALTER DOMAIN_P any_name alter_column_default
11836 : {
11837 14 : AlterDomainStmt *n = makeNode(AlterDomainStmt);
11838 :
11839 14 : n->subtype = AD_AlterDefault;
11840 14 : n->typeName = $3;
11841 14 : n->def = $4;
11842 14 : $$ = (Node *) n;
11843 : }
11844 : /* ALTER DOMAIN <domain> DROP NOT NULL */
11845 : | ALTER DOMAIN_P any_name DROP NOT NULL_P
11846 : {
11847 12 : AlterDomainStmt *n = makeNode(AlterDomainStmt);
11848 :
11849 12 : n->subtype = AD_DropNotNull;
11850 12 : n->typeName = $3;
11851 12 : $$ = (Node *) n;
11852 : }
11853 : /* ALTER DOMAIN <domain> SET NOT NULL */
11854 : | ALTER DOMAIN_P any_name SET NOT NULL_P
11855 : {
11856 24 : AlterDomainStmt *n = makeNode(AlterDomainStmt);
11857 :
11858 24 : n->subtype = AD_SetNotNull;
11859 24 : n->typeName = $3;
11860 24 : $$ = (Node *) n;
11861 : }
11862 : /* ALTER DOMAIN <domain> ADD CONSTRAINT ... */
11863 : | ALTER DOMAIN_P any_name ADD_P DomainConstraint
11864 : {
11865 182 : AlterDomainStmt *n = makeNode(AlterDomainStmt);
11866 :
11867 182 : n->subtype = AD_AddConstraint;
11868 182 : n->typeName = $3;
11869 182 : n->def = $5;
11870 182 : $$ = (Node *) n;
11871 : }
11872 : /* ALTER DOMAIN <domain> DROP CONSTRAINT <name> [RESTRICT|CASCADE] */
11873 : | ALTER DOMAIN_P any_name DROP CONSTRAINT name opt_drop_behavior
11874 : {
11875 54 : AlterDomainStmt *n = makeNode(AlterDomainStmt);
11876 :
11877 54 : n->subtype = AD_DropConstraint;
11878 54 : n->typeName = $3;
11879 54 : n->name = $6;
11880 54 : n->behavior = $7;
11881 54 : n->missing_ok = false;
11882 54 : $$ = (Node *) n;
11883 : }
11884 : /* ALTER DOMAIN <domain> DROP CONSTRAINT IF EXISTS <name> [RESTRICT|CASCADE] */
11885 : | ALTER DOMAIN_P any_name DROP CONSTRAINT IF_P EXISTS name opt_drop_behavior
11886 : {
11887 6 : AlterDomainStmt *n = makeNode(AlterDomainStmt);
11888 :
11889 6 : n->subtype = AD_DropConstraint;
11890 6 : n->typeName = $3;
11891 6 : n->name = $8;
11892 6 : n->behavior = $9;
11893 6 : n->missing_ok = true;
11894 6 : $$ = (Node *) n;
11895 : }
11896 : /* ALTER DOMAIN <domain> VALIDATE CONSTRAINT <name> */
11897 : | ALTER DOMAIN_P any_name VALIDATE CONSTRAINT name
11898 : {
11899 12 : AlterDomainStmt *n = makeNode(AlterDomainStmt);
11900 :
11901 12 : n->subtype = AD_ValidateConstraint;
11902 12 : n->typeName = $3;
11903 12 : n->name = $6;
11904 12 : $$ = (Node *) n;
11905 : }
11906 : ;
11907 :
11908 : opt_as: AS
11909 : | /* EMPTY */
11910 : ;
11911 :
11912 :
11913 : /*****************************************************************************
11914 : *
11915 : * Manipulate a text search dictionary or configuration
11916 : *
11917 : *****************************************************************************/
11918 :
11919 : AlterTSDictionaryStmt:
11920 : ALTER TEXT_P SEARCH DICTIONARY any_name definition
11921 : {
11922 40 : AlterTSDictionaryStmt *n = makeNode(AlterTSDictionaryStmt);
11923 :
11924 40 : n->dictname = $5;
11925 40 : n->options = $6;
11926 40 : $$ = (Node *) n;
11927 : }
11928 : ;
11929 :
11930 : AlterTSConfigurationStmt:
11931 : ALTER TEXT_P SEARCH CONFIGURATION any_name ADD_P MAPPING FOR name_list any_with any_name_list
11932 : {
11933 8692 : AlterTSConfigurationStmt *n = makeNode(AlterTSConfigurationStmt);
11934 :
11935 8692 : n->kind = ALTER_TSCONFIG_ADD_MAPPING;
11936 8692 : n->cfgname = $5;
11937 8692 : n->tokentype = $9;
11938 8692 : n->dicts = $11;
11939 8692 : n->override = false;
11940 8692 : n->replace = false;
11941 8692 : $$ = (Node *) n;
11942 : }
11943 : | ALTER TEXT_P SEARCH CONFIGURATION any_name ALTER MAPPING FOR name_list any_with any_name_list
11944 : {
11945 26 : AlterTSConfigurationStmt *n = makeNode(AlterTSConfigurationStmt);
11946 :
11947 26 : n->kind = ALTER_TSCONFIG_ALTER_MAPPING_FOR_TOKEN;
11948 26 : n->cfgname = $5;
11949 26 : n->tokentype = $9;
11950 26 : n->dicts = $11;
11951 26 : n->override = true;
11952 26 : n->replace = false;
11953 26 : $$ = (Node *) n;
11954 : }
11955 : | ALTER TEXT_P SEARCH CONFIGURATION any_name ALTER MAPPING REPLACE any_name any_with any_name
11956 : {
11957 18 : AlterTSConfigurationStmt *n = makeNode(AlterTSConfigurationStmt);
11958 :
11959 18 : n->kind = ALTER_TSCONFIG_REPLACE_DICT;
11960 18 : n->cfgname = $5;
11961 18 : n->tokentype = NIL;
11962 18 : n->dicts = list_make2($9,$11);
11963 18 : n->override = false;
11964 18 : n->replace = true;
11965 18 : $$ = (Node *) n;
11966 : }
11967 : | ALTER TEXT_P SEARCH CONFIGURATION any_name ALTER MAPPING FOR name_list REPLACE any_name any_with any_name
11968 : {
11969 0 : AlterTSConfigurationStmt *n = makeNode(AlterTSConfigurationStmt);
11970 :
11971 0 : n->kind = ALTER_TSCONFIG_REPLACE_DICT_FOR_TOKEN;
11972 0 : n->cfgname = $5;
11973 0 : n->tokentype = $9;
11974 0 : n->dicts = list_make2($11,$13);
11975 0 : n->override = false;
11976 0 : n->replace = true;
11977 0 : $$ = (Node *) n;
11978 : }
11979 : | ALTER TEXT_P SEARCH CONFIGURATION any_name DROP MAPPING FOR name_list
11980 : {
11981 18 : AlterTSConfigurationStmt *n = makeNode(AlterTSConfigurationStmt);
11982 :
11983 18 : n->kind = ALTER_TSCONFIG_DROP_MAPPING;
11984 18 : n->cfgname = $5;
11985 18 : n->tokentype = $9;
11986 18 : n->missing_ok = false;
11987 18 : $$ = (Node *) n;
11988 : }
11989 : | ALTER TEXT_P SEARCH CONFIGURATION any_name DROP MAPPING IF_P EXISTS FOR name_list
11990 : {
11991 12 : AlterTSConfigurationStmt *n = makeNode(AlterTSConfigurationStmt);
11992 :
11993 12 : n->kind = ALTER_TSCONFIG_DROP_MAPPING;
11994 12 : n->cfgname = $5;
11995 12 : n->tokentype = $11;
11996 12 : n->missing_ok = true;
11997 12 : $$ = (Node *) n;
11998 : }
11999 : ;
12000 :
12001 : /* Use this if TIME or ORDINALITY after WITH should be taken as an identifier */
12002 : any_with: WITH
12003 : | WITH_LA
12004 : ;
12005 :
12006 :
12007 : /*****************************************************************************
12008 : *
12009 : * Manipulate a conversion
12010 : *
12011 : * CREATE [DEFAULT] CONVERSION <conversion_name>
12012 : * FOR <encoding_name> TO <encoding_name> FROM <func_name>
12013 : *
12014 : *****************************************************************************/
12015 :
12016 : CreateConversionStmt:
12017 : CREATE opt_default CONVERSION_P any_name FOR Sconst
12018 : TO Sconst FROM any_name
12019 : {
12020 64 : CreateConversionStmt *n = makeNode(CreateConversionStmt);
12021 :
12022 64 : n->conversion_name = $4;
12023 64 : n->for_encoding_name = $6;
12024 64 : n->to_encoding_name = $8;
12025 64 : n->func_name = $10;
12026 64 : n->def = $2;
12027 64 : $$ = (Node *) n;
12028 : }
12029 : ;
12030 :
12031 : /*****************************************************************************
12032 : *
12033 : * QUERY:
12034 : * CLUSTER (options) [ <qualified_name> [ USING <index_name> ] ]
12035 : * CLUSTER [VERBOSE] [ <qualified_name> [ USING <index_name> ] ]
12036 : * CLUSTER [VERBOSE] <index_name> ON <qualified_name> (for pre-8.3)
12037 : *
12038 : *****************************************************************************/
12039 :
12040 : ClusterStmt:
12041 : CLUSTER '(' utility_option_list ')' qualified_name cluster_index_specification
12042 : {
12043 0 : ClusterStmt *n = makeNode(ClusterStmt);
12044 :
12045 0 : n->relation = $5;
12046 0 : n->indexname = $6;
12047 0 : n->params = $3;
12048 0 : $$ = (Node *) n;
12049 : }
12050 : | CLUSTER opt_utility_option_list
12051 : {
12052 16 : ClusterStmt *n = makeNode(ClusterStmt);
12053 :
12054 16 : n->relation = NULL;
12055 16 : n->indexname = NULL;
12056 16 : n->params = $2;
12057 16 : $$ = (Node *) n;
12058 : }
12059 : /* unparenthesized VERBOSE kept for pre-14 compatibility */
12060 : | CLUSTER opt_verbose qualified_name cluster_index_specification
12061 : {
12062 190 : ClusterStmt *n = makeNode(ClusterStmt);
12063 :
12064 190 : n->relation = $3;
12065 190 : n->indexname = $4;
12066 190 : if ($2)
12067 0 : n->params = list_make1(makeDefElem("verbose", NULL, @2));
12068 190 : $$ = (Node *) n;
12069 : }
12070 : /* unparenthesized VERBOSE kept for pre-17 compatibility */
12071 : | CLUSTER VERBOSE
12072 : {
12073 6 : ClusterStmt *n = makeNode(ClusterStmt);
12074 :
12075 6 : n->relation = NULL;
12076 6 : n->indexname = NULL;
12077 6 : n->params = list_make1(makeDefElem("verbose", NULL, @2));
12078 6 : $$ = (Node *) n;
12079 : }
12080 : /* kept for pre-8.3 compatibility */
12081 : | CLUSTER opt_verbose name ON qualified_name
12082 : {
12083 20 : ClusterStmt *n = makeNode(ClusterStmt);
12084 :
12085 20 : n->relation = $5;
12086 20 : n->indexname = $3;
12087 20 : if ($2)
12088 0 : n->params = list_make1(makeDefElem("verbose", NULL, @2));
12089 20 : $$ = (Node *) n;
12090 : }
12091 : ;
12092 :
12093 : cluster_index_specification:
12094 156 : USING name { $$ = $2; }
12095 34 : | /*EMPTY*/ { $$ = NULL; }
12096 : ;
12097 :
12098 :
12099 : /*****************************************************************************
12100 : *
12101 : * QUERY:
12102 : * VACUUM
12103 : * ANALYZE
12104 : *
12105 : *****************************************************************************/
12106 :
12107 : VacuumStmt: VACUUM opt_full opt_freeze opt_verbose opt_analyze opt_vacuum_relation_list
12108 : {
12109 1256 : VacuumStmt *n = makeNode(VacuumStmt);
12110 :
12111 1256 : n->options = NIL;
12112 1256 : if ($2)
12113 152 : n->options = lappend(n->options,
12114 152 : makeDefElem("full", NULL, @2));
12115 1256 : if ($3)
12116 164 : n->options = lappend(n->options,
12117 164 : makeDefElem("freeze", NULL, @3));
12118 1256 : if ($4)
12119 16 : n->options = lappend(n->options,
12120 16 : makeDefElem("verbose", NULL, @4));
12121 1256 : if ($5)
12122 304 : n->options = lappend(n->options,
12123 304 : makeDefElem("analyze", NULL, @5));
12124 1256 : n->rels = $6;
12125 1256 : n->is_vacuumcmd = true;
12126 1256 : $$ = (Node *) n;
12127 : }
12128 : | VACUUM '(' utility_option_list ')' opt_vacuum_relation_list
12129 : {
12130 8446 : VacuumStmt *n = makeNode(VacuumStmt);
12131 :
12132 8446 : n->options = $3;
12133 8446 : n->rels = $5;
12134 8446 : n->is_vacuumcmd = true;
12135 8446 : $$ = (Node *) n;
12136 : }
12137 : ;
12138 :
12139 : AnalyzeStmt: analyze_keyword opt_utility_option_list opt_vacuum_relation_list
12140 : {
12141 4936 : VacuumStmt *n = makeNode(VacuumStmt);
12142 :
12143 4936 : n->options = $2;
12144 4936 : n->rels = $3;
12145 4936 : n->is_vacuumcmd = false;
12146 4936 : $$ = (Node *) n;
12147 : }
12148 : | analyze_keyword VERBOSE opt_vacuum_relation_list
12149 : {
12150 0 : VacuumStmt *n = makeNode(VacuumStmt);
12151 :
12152 0 : n->options = list_make1(makeDefElem("verbose", NULL, @2));
12153 0 : n->rels = $3;
12154 0 : n->is_vacuumcmd = false;
12155 0 : $$ = (Node *) n;
12156 : }
12157 : ;
12158 :
12159 : analyze_keyword:
12160 : ANALYZE
12161 : | ANALYSE /* British */
12162 : ;
12163 :
12164 : opt_analyze:
12165 304 : analyze_keyword { $$ = true; }
12166 952 : | /*EMPTY*/ { $$ = false; }
12167 : ;
12168 :
12169 : opt_verbose:
12170 16 : VERBOSE { $$ = true; }
12171 3766 : | /*EMPTY*/ { $$ = false; }
12172 : ;
12173 :
12174 152 : opt_full: FULL { $$ = true; }
12175 1104 : | /*EMPTY*/ { $$ = false; }
12176 : ;
12177 :
12178 164 : opt_freeze: FREEZE { $$ = true; }
12179 1092 : | /*EMPTY*/ { $$ = false; }
12180 : ;
12181 :
12182 : opt_name_list:
12183 2926 : '(' name_list ')' { $$ = $2; }
12184 17108 : | /*EMPTY*/ { $$ = NIL; }
12185 : ;
12186 :
12187 : vacuum_relation:
12188 : relation_expr opt_name_list
12189 : {
12190 14456 : $$ = (Node *) makeVacuumRelation($1, InvalidOid, $2);
12191 : }
12192 : ;
12193 :
12194 : vacuum_relation_list:
12195 : vacuum_relation
12196 14268 : { $$ = list_make1($1); }
12197 : | vacuum_relation_list ',' vacuum_relation
12198 188 : { $$ = lappend($1, $3); }
12199 : ;
12200 :
12201 : opt_vacuum_relation_list:
12202 14268 : vacuum_relation_list { $$ = $1; }
12203 370 : | /*EMPTY*/ { $$ = NIL; }
12204 : ;
12205 :
12206 :
12207 : /*****************************************************************************
12208 : *
12209 : * QUERY:
12210 : * EXPLAIN [ANALYZE] [VERBOSE] query
12211 : * EXPLAIN ( options ) query
12212 : *
12213 : *****************************************************************************/
12214 :
12215 : ExplainStmt:
12216 : EXPLAIN ExplainableStmt
12217 : {
12218 7786 : ExplainStmt *n = makeNode(ExplainStmt);
12219 :
12220 7786 : n->query = $2;
12221 7786 : n->options = NIL;
12222 7786 : $$ = (Node *) n;
12223 : }
12224 : | EXPLAIN analyze_keyword opt_verbose ExplainableStmt
12225 : {
12226 2316 : ExplainStmt *n = makeNode(ExplainStmt);
12227 :
12228 2316 : n->query = $4;
12229 2316 : n->options = list_make1(makeDefElem("analyze", NULL, @2));
12230 2316 : if ($3)
12231 0 : n->options = lappend(n->options,
12232 0 : makeDefElem("verbose", NULL, @3));
12233 2316 : $$ = (Node *) n;
12234 : }
12235 : | EXPLAIN VERBOSE ExplainableStmt
12236 : {
12237 12 : ExplainStmt *n = makeNode(ExplainStmt);
12238 :
12239 12 : n->query = $3;
12240 12 : n->options = list_make1(makeDefElem("verbose", NULL, @2));
12241 12 : $$ = (Node *) n;
12242 : }
12243 : | EXPLAIN '(' utility_option_list ')' ExplainableStmt
12244 : {
12245 14674 : ExplainStmt *n = makeNode(ExplainStmt);
12246 :
12247 14674 : n->query = $5;
12248 14674 : n->options = $3;
12249 14674 : $$ = (Node *) n;
12250 : }
12251 : ;
12252 :
12253 : ExplainableStmt:
12254 : SelectStmt
12255 : | InsertStmt
12256 : | UpdateStmt
12257 : | DeleteStmt
12258 : | MergeStmt
12259 : | DeclareCursorStmt
12260 : | CreateAsStmt
12261 : | CreateMatViewStmt
12262 : | RefreshMatViewStmt
12263 : | ExecuteStmt /* by default all are $$=$1 */
12264 : ;
12265 :
12266 : /*****************************************************************************
12267 : *
12268 : * QUERY:
12269 : * PREPARE <plan_name> [(args, ...)] AS <query>
12270 : *
12271 : *****************************************************************************/
12272 :
12273 : PrepareStmt: PREPARE name prep_type_clause AS PreparableStmt
12274 : {
12275 1946 : PrepareStmt *n = makeNode(PrepareStmt);
12276 :
12277 1946 : n->name = $2;
12278 1946 : n->argtypes = $3;
12279 1946 : n->query = $5;
12280 1946 : $$ = (Node *) n;
12281 : }
12282 : ;
12283 :
12284 1624 : prep_type_clause: '(' type_list ')' { $$ = $2; }
12285 340 : | /* EMPTY */ { $$ = NIL; }
12286 : ;
12287 :
12288 : PreparableStmt:
12289 : SelectStmt
12290 : | InsertStmt
12291 : | UpdateStmt
12292 : | DeleteStmt
12293 : | MergeStmt /* by default all are $$=$1 */
12294 : ;
12295 :
12296 : /*****************************************************************************
12297 : *
12298 : * EXECUTE <plan_name> [(params, ...)]
12299 : * CREATE TABLE <name> AS EXECUTE <plan_name> [(params, ...)]
12300 : *
12301 : *****************************************************************************/
12302 :
12303 : ExecuteStmt: EXECUTE name execute_param_clause
12304 : {
12305 16252 : ExecuteStmt *n = makeNode(ExecuteStmt);
12306 :
12307 16252 : n->name = $2;
12308 16252 : n->params = $3;
12309 16252 : $$ = (Node *) n;
12310 : }
12311 : | CREATE OptTemp TABLE create_as_target AS
12312 : EXECUTE name execute_param_clause opt_with_data
12313 : {
12314 76 : CreateTableAsStmt *ctas = makeNode(CreateTableAsStmt);
12315 76 : ExecuteStmt *n = makeNode(ExecuteStmt);
12316 :
12317 76 : n->name = $7;
12318 76 : n->params = $8;
12319 76 : ctas->query = (Node *) n;
12320 76 : ctas->into = $4;
12321 76 : ctas->objtype = OBJECT_TABLE;
12322 76 : ctas->is_select_into = false;
12323 76 : ctas->if_not_exists = false;
12324 : /* cram additional flags into the IntoClause */
12325 76 : $4->rel->relpersistence = $2;
12326 76 : $4->skipData = !($9);
12327 76 : $$ = (Node *) ctas;
12328 : }
12329 : | CREATE OptTemp TABLE IF_P NOT EXISTS create_as_target AS
12330 : EXECUTE name execute_param_clause opt_with_data
12331 : {
12332 12 : CreateTableAsStmt *ctas = makeNode(CreateTableAsStmt);
12333 12 : ExecuteStmt *n = makeNode(ExecuteStmt);
12334 :
12335 12 : n->name = $10;
12336 12 : n->params = $11;
12337 12 : ctas->query = (Node *) n;
12338 12 : ctas->into = $7;
12339 12 : ctas->objtype = OBJECT_TABLE;
12340 12 : ctas->is_select_into = false;
12341 12 : ctas->if_not_exists = true;
12342 : /* cram additional flags into the IntoClause */
12343 12 : $7->rel->relpersistence = $2;
12344 12 : $7->skipData = !($12);
12345 12 : $$ = (Node *) ctas;
12346 : }
12347 : ;
12348 :
12349 15178 : execute_param_clause: '(' expr_list ')' { $$ = $2; }
12350 1162 : | /* EMPTY */ { $$ = NIL; }
12351 : ;
12352 :
12353 : /*****************************************************************************
12354 : *
12355 : * QUERY:
12356 : * DEALLOCATE [PREPARE] <plan_name>
12357 : *
12358 : *****************************************************************************/
12359 :
12360 : DeallocateStmt: DEALLOCATE name
12361 : {
12362 4010 : DeallocateStmt *n = makeNode(DeallocateStmt);
12363 :
12364 4010 : n->name = $2;
12365 4010 : n->isall = false;
12366 4010 : n->location = @2;
12367 4010 : $$ = (Node *) n;
12368 : }
12369 : | DEALLOCATE PREPARE name
12370 : {
12371 20 : DeallocateStmt *n = makeNode(DeallocateStmt);
12372 :
12373 20 : n->name = $3;
12374 20 : n->isall = false;
12375 20 : n->location = @3;
12376 20 : $$ = (Node *) n;
12377 : }
12378 : | DEALLOCATE ALL
12379 : {
12380 70 : DeallocateStmt *n = makeNode(DeallocateStmt);
12381 :
12382 70 : n->name = NULL;
12383 70 : n->isall = true;
12384 70 : n->location = -1;
12385 70 : $$ = (Node *) n;
12386 : }
12387 : | DEALLOCATE PREPARE ALL
12388 : {
12389 2 : DeallocateStmt *n = makeNode(DeallocateStmt);
12390 :
12391 2 : n->name = NULL;
12392 2 : n->isall = true;
12393 2 : n->location = -1;
12394 2 : $$ = (Node *) n;
12395 : }
12396 : ;
12397 :
12398 : /*****************************************************************************
12399 : *
12400 : * QUERY:
12401 : * INSERT STATEMENTS
12402 : *
12403 : *****************************************************************************/
12404 :
12405 : InsertStmt:
12406 : opt_with_clause INSERT INTO insert_target insert_rest
12407 : opt_on_conflict returning_clause
12408 : {
12409 70024 : $5->relation = $4;
12410 70024 : $5->onConflictClause = $6;
12411 70024 : $5->returningClause = $7;
12412 70024 : $5->withClause = $1;
12413 70024 : $$ = (Node *) $5;
12414 : }
12415 : ;
12416 :
12417 : /*
12418 : * Can't easily make AS optional here, because VALUES in insert_rest would
12419 : * have a shift/reduce conflict with VALUES as an optional alias. We could
12420 : * easily allow unreserved_keywords as optional aliases, but that'd be an odd
12421 : * divergence from other places. So just require AS for now.
12422 : */
12423 : insert_target:
12424 : qualified_name
12425 : {
12426 69898 : $$ = $1;
12427 : }
12428 : | qualified_name AS ColId
12429 : {
12430 132 : $1->alias = makeAlias($3, NIL);
12431 132 : $$ = $1;
12432 : }
12433 : ;
12434 :
12435 : insert_rest:
12436 : SelectStmt
12437 : {
12438 44678 : $$ = makeNode(InsertStmt);
12439 44678 : $$->cols = NIL;
12440 44678 : $$->selectStmt = $1;
12441 : }
12442 : | OVERRIDING override_kind VALUE_P SelectStmt
12443 : {
12444 96 : $$ = makeNode(InsertStmt);
12445 96 : $$->cols = NIL;
12446 96 : $$->override = $2;
12447 96 : $$->selectStmt = $4;
12448 : }
12449 : | '(' insert_column_list ')' SelectStmt
12450 : {
12451 14424 : $$ = makeNode(InsertStmt);
12452 14424 : $$->cols = $2;
12453 14424 : $$->selectStmt = $4;
12454 : }
12455 : | '(' insert_column_list ')' OVERRIDING override_kind VALUE_P SelectStmt
12456 : {
12457 0 : $$ = makeNode(InsertStmt);
12458 0 : $$->cols = $2;
12459 0 : $$->override = $5;
12460 0 : $$->selectStmt = $7;
12461 : }
12462 : | DEFAULT VALUES
12463 : {
12464 10832 : $$ = makeNode(InsertStmt);
12465 10832 : $$->cols = NIL;
12466 10832 : $$->selectStmt = NULL;
12467 : }
12468 : ;
12469 :
12470 : override_kind:
12471 66 : USER { $$ = OVERRIDING_USER_VALUE; }
12472 60 : | SYSTEM_P { $$ = OVERRIDING_SYSTEM_VALUE; }
12473 : ;
12474 :
12475 : insert_column_list:
12476 : insert_column_item
12477 14758 : { $$ = list_make1($1); }
12478 : | insert_column_list ',' insert_column_item
12479 16480 : { $$ = lappend($1, $3); }
12480 : ;
12481 :
12482 : insert_column_item:
12483 : ColId opt_indirection
12484 : {
12485 31238 : $$ = makeNode(ResTarget);
12486 31238 : $$->name = $1;
12487 31238 : $$->indirection = check_indirection($2, yyscanner);
12488 31238 : $$->val = NULL;
12489 31238 : $$->location = @1;
12490 : }
12491 : ;
12492 :
12493 : opt_on_conflict:
12494 : ON CONFLICT opt_conf_expr DO UPDATE SET set_clause_list where_clause
12495 : {
12496 1340 : $$ = makeNode(OnConflictClause);
12497 1340 : $$->action = ONCONFLICT_UPDATE;
12498 1340 : $$->infer = $3;
12499 1340 : $$->targetList = $7;
12500 1340 : $$->whereClause = $8;
12501 1340 : $$->location = @1;
12502 : }
12503 : |
12504 : ON CONFLICT opt_conf_expr DO NOTHING
12505 : {
12506 604 : $$ = makeNode(OnConflictClause);
12507 604 : $$->action = ONCONFLICT_NOTHING;
12508 604 : $$->infer = $3;
12509 604 : $$->targetList = NIL;
12510 604 : $$->whereClause = NULL;
12511 604 : $$->location = @1;
12512 : }
12513 : | /*EMPTY*/
12514 : {
12515 68086 : $$ = NULL;
12516 : }
12517 : ;
12518 :
12519 : opt_conf_expr:
12520 : '(' index_params ')' where_clause
12521 : {
12522 1500 : $$ = makeNode(InferClause);
12523 1500 : $$->indexElems = $2;
12524 1500 : $$->whereClause = $4;
12525 1500 : $$->conname = NULL;
12526 1500 : $$->location = @1;
12527 : }
12528 : |
12529 : ON CONSTRAINT name
12530 : {
12531 192 : $$ = makeNode(InferClause);
12532 192 : $$->indexElems = NIL;
12533 192 : $$->whereClause = NULL;
12534 192 : $$->conname = $3;
12535 192 : $$->location = @1;
12536 : }
12537 : | /*EMPTY*/
12538 : {
12539 252 : $$ = NULL;
12540 : }
12541 : ;
12542 :
12543 : returning_clause:
12544 : RETURNING returning_with_clause target_list
12545 : {
12546 3266 : ReturningClause *n = makeNode(ReturningClause);
12547 :
12548 3266 : n->options = $2;
12549 3266 : n->exprs = $3;
12550 3266 : $$ = n;
12551 : }
12552 : | /* EMPTY */
12553 : {
12554 88558 : $$ = NULL;
12555 : }
12556 : ;
12557 :
12558 : returning_with_clause:
12559 72 : WITH '(' returning_options ')' { $$ = $3; }
12560 3194 : | /* EMPTY */ { $$ = NIL; }
12561 : ;
12562 :
12563 : returning_options:
12564 72 : returning_option { $$ = list_make1($1); }
12565 54 : | returning_options ',' returning_option { $$ = lappend($1, $3); }
12566 : ;
12567 :
12568 : returning_option:
12569 : returning_option_kind AS ColId
12570 : {
12571 126 : ReturningOption *n = makeNode(ReturningOption);
12572 :
12573 126 : n->option = $1;
12574 126 : n->value = $3;
12575 126 : n->location = @1;
12576 126 : $$ = (Node *) n;
12577 : }
12578 : ;
12579 :
12580 : returning_option_kind:
12581 54 : OLD { $$ = RETURNING_OPTION_OLD; }
12582 72 : | NEW { $$ = RETURNING_OPTION_NEW; }
12583 : ;
12584 :
12585 :
12586 : /*****************************************************************************
12587 : *
12588 : * QUERY:
12589 : * DELETE STATEMENTS
12590 : *
12591 : *****************************************************************************/
12592 :
12593 : DeleteStmt: opt_with_clause DELETE_P FROM relation_expr_opt_alias
12594 : using_clause where_or_current_clause returning_clause
12595 : {
12596 4698 : DeleteStmt *n = makeNode(DeleteStmt);
12597 :
12598 4698 : n->relation = $4;
12599 4698 : n->usingClause = $5;
12600 4698 : n->whereClause = $6;
12601 4698 : n->returningClause = $7;
12602 4698 : n->withClause = $1;
12603 4698 : $$ = (Node *) n;
12604 : }
12605 : ;
12606 :
12607 : using_clause:
12608 108 : USING from_list { $$ = $2; }
12609 4590 : | /*EMPTY*/ { $$ = NIL; }
12610 : ;
12611 :
12612 :
12613 : /*****************************************************************************
12614 : *
12615 : * QUERY:
12616 : * LOCK TABLE
12617 : *
12618 : *****************************************************************************/
12619 :
12620 : LockStmt: LOCK_P opt_table relation_expr_list opt_lock opt_nowait
12621 : {
12622 1048 : LockStmt *n = makeNode(LockStmt);
12623 :
12624 1048 : n->relations = $3;
12625 1048 : n->mode = $4;
12626 1048 : n->nowait = $5;
12627 1048 : $$ = (Node *) n;
12628 : }
12629 : ;
12630 :
12631 940 : opt_lock: IN_P lock_type MODE { $$ = $2; }
12632 108 : | /*EMPTY*/ { $$ = AccessExclusiveLock; }
12633 : ;
12634 :
12635 450 : lock_type: ACCESS SHARE { $$ = AccessShareLock; }
12636 14 : | ROW SHARE { $$ = RowShareLock; }
12637 88 : | ROW EXCLUSIVE { $$ = RowExclusiveLock; }
12638 66 : | SHARE UPDATE EXCLUSIVE { $$ = ShareUpdateExclusiveLock; }
12639 80 : | SHARE { $$ = ShareLock; }
12640 14 : | SHARE ROW EXCLUSIVE { $$ = ShareRowExclusiveLock; }
12641 102 : | EXCLUSIVE { $$ = ExclusiveLock; }
12642 126 : | ACCESS EXCLUSIVE { $$ = AccessExclusiveLock; }
12643 : ;
12644 :
12645 186 : opt_nowait: NOWAIT { $$ = true; }
12646 892 : | /*EMPTY*/ { $$ = false; }
12647 : ;
12648 :
12649 : opt_nowait_or_skip:
12650 50 : NOWAIT { $$ = LockWaitError; }
12651 190 : | SKIP LOCKED { $$ = LockWaitSkip; }
12652 10708 : | /*EMPTY*/ { $$ = LockWaitBlock; }
12653 : ;
12654 :
12655 :
12656 : /*****************************************************************************
12657 : *
12658 : * QUERY:
12659 : * UpdateStmt (UPDATE)
12660 : *
12661 : *****************************************************************************/
12662 :
12663 : UpdateStmt: opt_with_clause UPDATE relation_expr_opt_alias
12664 : SET set_clause_list
12665 : from_clause
12666 : where_or_current_clause
12667 : returning_clause
12668 : {
12669 14930 : UpdateStmt *n = makeNode(UpdateStmt);
12670 :
12671 14930 : n->relation = $3;
12672 14930 : n->targetList = $5;
12673 14930 : n->fromClause = $6;
12674 14930 : n->whereClause = $7;
12675 14930 : n->returningClause = $8;
12676 14930 : n->withClause = $1;
12677 14930 : $$ = (Node *) n;
12678 : }
12679 : ;
12680 :
12681 : set_clause_list:
12682 17898 : set_clause { $$ = $1; }
12683 4378 : | set_clause_list ',' set_clause { $$ = list_concat($1,$3); }
12684 : ;
12685 :
12686 : set_clause:
12687 : set_target '=' a_expr
12688 : {
12689 22092 : $1->val = (Node *) $3;
12690 22092 : $$ = list_make1($1);
12691 : }
12692 : | '(' set_target_list ')' '=' a_expr
12693 : {
12694 184 : int ncolumns = list_length($2);
12695 184 : int i = 1;
12696 : ListCell *col_cell;
12697 :
12698 : /* Create a MultiAssignRef source for each target */
12699 568 : foreach(col_cell, $2)
12700 : {
12701 384 : ResTarget *res_col = (ResTarget *) lfirst(col_cell);
12702 384 : MultiAssignRef *r = makeNode(MultiAssignRef);
12703 :
12704 384 : r->source = (Node *) $5;
12705 384 : r->colno = i;
12706 384 : r->ncolumns = ncolumns;
12707 384 : res_col->val = (Node *) r;
12708 384 : i++;
12709 : }
12710 :
12711 184 : $$ = $2;
12712 : }
12713 : ;
12714 :
12715 : set_target:
12716 : ColId opt_indirection
12717 : {
12718 22482 : $$ = makeNode(ResTarget);
12719 22482 : $$->name = $1;
12720 22482 : $$->indirection = check_indirection($2, yyscanner);
12721 22482 : $$->val = NULL; /* upper production sets this */
12722 22482 : $$->location = @1;
12723 : }
12724 : ;
12725 :
12726 : set_target_list:
12727 190 : set_target { $$ = list_make1($1); }
12728 200 : | set_target_list ',' set_target { $$ = lappend($1,$3); }
12729 : ;
12730 :
12731 :
12732 : /*****************************************************************************
12733 : *
12734 : * QUERY:
12735 : * MERGE
12736 : *
12737 : *****************************************************************************/
12738 :
12739 : MergeStmt:
12740 : opt_with_clause MERGE INTO relation_expr_opt_alias
12741 : USING table_ref
12742 : ON a_expr
12743 : merge_when_list
12744 : returning_clause
12745 : {
12746 2172 : MergeStmt *m = makeNode(MergeStmt);
12747 :
12748 2172 : m->withClause = $1;
12749 2172 : m->relation = $4;
12750 2172 : m->sourceRelation = $6;
12751 2172 : m->joinCondition = $8;
12752 2172 : m->mergeWhenClauses = $9;
12753 2172 : m->returningClause = $10;
12754 :
12755 2172 : $$ = (Node *) m;
12756 : }
12757 : ;
12758 :
12759 : merge_when_list:
12760 2172 : merge_when_clause { $$ = list_make1($1); }
12761 1218 : | merge_when_list merge_when_clause { $$ = lappend($1,$2); }
12762 : ;
12763 :
12764 : /*
12765 : * A WHEN clause may be WHEN MATCHED, WHEN NOT MATCHED BY SOURCE, or WHEN NOT
12766 : * MATCHED [BY TARGET]. The first two cases match target tuples, and support
12767 : * UPDATE/DELETE/DO NOTHING actions. The third case does not match target
12768 : * tuples, and only supports INSERT/DO NOTHING actions.
12769 : */
12770 : merge_when_clause:
12771 : merge_when_tgt_matched opt_merge_when_condition THEN merge_update
12772 : {
12773 1628 : $4->matchKind = $1;
12774 1628 : $4->condition = $2;
12775 :
12776 1628 : $$ = (Node *) $4;
12777 : }
12778 : | merge_when_tgt_matched opt_merge_when_condition THEN merge_delete
12779 : {
12780 542 : $4->matchKind = $1;
12781 542 : $4->condition = $2;
12782 :
12783 542 : $$ = (Node *) $4;
12784 : }
12785 : | merge_when_tgt_not_matched opt_merge_when_condition THEN merge_insert
12786 : {
12787 1124 : $4->matchKind = $1;
12788 1124 : $4->condition = $2;
12789 :
12790 1124 : $$ = (Node *) $4;
12791 : }
12792 : | merge_when_tgt_matched opt_merge_when_condition THEN DO NOTHING
12793 : {
12794 70 : MergeWhenClause *m = makeNode(MergeWhenClause);
12795 :
12796 70 : m->matchKind = $1;
12797 70 : m->commandType = CMD_NOTHING;
12798 70 : m->condition = $2;
12799 :
12800 70 : $$ = (Node *) m;
12801 : }
12802 : | merge_when_tgt_not_matched opt_merge_when_condition THEN DO NOTHING
12803 : {
12804 26 : MergeWhenClause *m = makeNode(MergeWhenClause);
12805 :
12806 26 : m->matchKind = $1;
12807 26 : m->commandType = CMD_NOTHING;
12808 26 : m->condition = $2;
12809 :
12810 26 : $$ = (Node *) m;
12811 : }
12812 : ;
12813 :
12814 : merge_when_tgt_matched:
12815 2072 : WHEN MATCHED { $$ = MERGE_WHEN_MATCHED; }
12816 186 : | WHEN NOT MATCHED BY SOURCE { $$ = MERGE_WHEN_NOT_MATCHED_BY_SOURCE; }
12817 : ;
12818 :
12819 : merge_when_tgt_not_matched:
12820 1156 : WHEN NOT MATCHED { $$ = MERGE_WHEN_NOT_MATCHED_BY_TARGET; }
12821 18 : | WHEN NOT MATCHED BY TARGET { $$ = MERGE_WHEN_NOT_MATCHED_BY_TARGET; }
12822 : ;
12823 :
12824 : opt_merge_when_condition:
12825 850 : AND a_expr { $$ = $2; }
12826 2582 : | { $$ = NULL; }
12827 : ;
12828 :
12829 : merge_update:
12830 : UPDATE SET set_clause_list
12831 : {
12832 1628 : MergeWhenClause *n = makeNode(MergeWhenClause);
12833 1628 : n->commandType = CMD_UPDATE;
12834 1628 : n->override = OVERRIDING_NOT_SET;
12835 1628 : n->targetList = $3;
12836 1628 : n->values = NIL;
12837 :
12838 1628 : $$ = n;
12839 : }
12840 : ;
12841 :
12842 : merge_delete:
12843 : DELETE_P
12844 : {
12845 542 : MergeWhenClause *n = makeNode(MergeWhenClause);
12846 542 : n->commandType = CMD_DELETE;
12847 542 : n->override = OVERRIDING_NOT_SET;
12848 542 : n->targetList = NIL;
12849 542 : n->values = NIL;
12850 :
12851 542 : $$ = n;
12852 : }
12853 : ;
12854 :
12855 : merge_insert:
12856 : INSERT merge_values_clause
12857 : {
12858 754 : MergeWhenClause *n = makeNode(MergeWhenClause);
12859 754 : n->commandType = CMD_INSERT;
12860 754 : n->override = OVERRIDING_NOT_SET;
12861 754 : n->targetList = NIL;
12862 754 : n->values = $2;
12863 754 : $$ = n;
12864 : }
12865 : | INSERT OVERRIDING override_kind VALUE_P merge_values_clause
12866 : {
12867 0 : MergeWhenClause *n = makeNode(MergeWhenClause);
12868 0 : n->commandType = CMD_INSERT;
12869 0 : n->override = $3;
12870 0 : n->targetList = NIL;
12871 0 : n->values = $5;
12872 0 : $$ = n;
12873 : }
12874 : | INSERT '(' insert_column_list ')' merge_values_clause
12875 : {
12876 304 : MergeWhenClause *n = makeNode(MergeWhenClause);
12877 304 : n->commandType = CMD_INSERT;
12878 304 : n->override = OVERRIDING_NOT_SET;
12879 304 : n->targetList = $3;
12880 304 : n->values = $5;
12881 304 : $$ = n;
12882 : }
12883 : | INSERT '(' insert_column_list ')' OVERRIDING override_kind VALUE_P merge_values_clause
12884 : {
12885 30 : MergeWhenClause *n = makeNode(MergeWhenClause);
12886 30 : n->commandType = CMD_INSERT;
12887 30 : n->override = $6;
12888 30 : n->targetList = $3;
12889 30 : n->values = $8;
12890 30 : $$ = n;
12891 : }
12892 : | INSERT DEFAULT VALUES
12893 : {
12894 36 : MergeWhenClause *n = makeNode(MergeWhenClause);
12895 36 : n->commandType = CMD_INSERT;
12896 36 : n->override = OVERRIDING_NOT_SET;
12897 36 : n->targetList = NIL;
12898 36 : n->values = NIL;
12899 36 : $$ = n;
12900 : }
12901 : ;
12902 :
12903 : merge_values_clause:
12904 : VALUES '(' expr_list ')'
12905 : {
12906 1088 : $$ = $3;
12907 : }
12908 : ;
12909 :
12910 : /*****************************************************************************
12911 : *
12912 : * QUERY:
12913 : * CURSOR STATEMENTS
12914 : *
12915 : *****************************************************************************/
12916 : DeclareCursorStmt: DECLARE cursor_name cursor_options CURSOR opt_hold FOR SelectStmt
12917 : {
12918 4614 : DeclareCursorStmt *n = makeNode(DeclareCursorStmt);
12919 :
12920 4614 : n->portalname = $2;
12921 : /* currently we always set FAST_PLAN option */
12922 4614 : n->options = $3 | $5 | CURSOR_OPT_FAST_PLAN;
12923 4614 : n->query = $7;
12924 4614 : $$ = (Node *) n;
12925 : }
12926 : ;
12927 :
12928 14832 : cursor_name: name { $$ = $1; }
12929 : ;
12930 :
12931 4614 : cursor_options: /*EMPTY*/ { $$ = 0; }
12932 28 : | cursor_options NO SCROLL { $$ = $1 | CURSOR_OPT_NO_SCROLL; }
12933 240 : | cursor_options SCROLL { $$ = $1 | CURSOR_OPT_SCROLL; }
12934 14 : | cursor_options BINARY { $$ = $1 | CURSOR_OPT_BINARY; }
12935 0 : | cursor_options ASENSITIVE { $$ = $1 | CURSOR_OPT_ASENSITIVE; }
12936 6 : | cursor_options INSENSITIVE { $$ = $1 | CURSOR_OPT_INSENSITIVE; }
12937 : ;
12938 :
12939 4514 : opt_hold: /* EMPTY */ { $$ = 0; }
12940 94 : | WITH HOLD { $$ = CURSOR_OPT_HOLD; }
12941 6 : | WITHOUT HOLD { $$ = 0; }
12942 : ;
12943 :
12944 : /*****************************************************************************
12945 : *
12946 : * QUERY:
12947 : * SELECT STATEMENTS
12948 : *
12949 : *****************************************************************************/
12950 :
12951 : /* A complete SELECT statement looks like this.
12952 : *
12953 : * The rule returns either a single SelectStmt node or a tree of them,
12954 : * representing a set-operation tree.
12955 : *
12956 : * There is an ambiguity when a sub-SELECT is within an a_expr and there
12957 : * are excess parentheses: do the parentheses belong to the sub-SELECT or
12958 : * to the surrounding a_expr? We don't really care, but bison wants to know.
12959 : * To resolve the ambiguity, we are careful to define the grammar so that
12960 : * the decision is staved off as long as possible: as long as we can keep
12961 : * absorbing parentheses into the sub-SELECT, we will do so, and only when
12962 : * it's no longer possible to do that will we decide that parens belong to
12963 : * the expression. For example, in "SELECT (((SELECT 2)) + 3)" the extra
12964 : * parentheses are treated as part of the sub-select. The necessity of doing
12965 : * it that way is shown by "SELECT (((SELECT 2)) UNION SELECT 2)". Had we
12966 : * parsed "((SELECT 2))" as an a_expr, it'd be too late to go back to the
12967 : * SELECT viewpoint when we see the UNION.
12968 : *
12969 : * This approach is implemented by defining a nonterminal select_with_parens,
12970 : * which represents a SELECT with at least one outer layer of parentheses,
12971 : * and being careful to use select_with_parens, never '(' SelectStmt ')',
12972 : * in the expression grammar. We will then have shift-reduce conflicts
12973 : * which we can resolve in favor of always treating '(' <select> ')' as
12974 : * a select_with_parens. To resolve the conflicts, the productions that
12975 : * conflict with the select_with_parens productions are manually given
12976 : * precedences lower than the precedence of ')', thereby ensuring that we
12977 : * shift ')' (and then reduce to select_with_parens) rather than trying to
12978 : * reduce the inner <select> nonterminal to something else. We use UMINUS
12979 : * precedence for this, which is a fairly arbitrary choice.
12980 : *
12981 : * To be able to define select_with_parens itself without ambiguity, we need
12982 : * a nonterminal select_no_parens that represents a SELECT structure with no
12983 : * outermost parentheses. This is a little bit tedious, but it works.
12984 : *
12985 : * In non-expression contexts, we use SelectStmt which can represent a SELECT
12986 : * with or without outer parentheses.
12987 : */
12988 :
12989 : SelectStmt: select_no_parens %prec UMINUS
12990 : | select_with_parens %prec UMINUS
12991 : ;
12992 :
12993 : select_with_parens:
12994 71592 : '(' select_no_parens ')' { $$ = $2; }
12995 156 : | '(' select_with_parens ')' { $$ = $2; }
12996 : ;
12997 :
12998 : /*
12999 : * This rule parses the equivalent of the standard's <query expression>.
13000 : * The duplicative productions are annoying, but hard to get rid of without
13001 : * creating shift/reduce conflicts.
13002 : *
13003 : * The locking clause (FOR UPDATE etc) may be before or after LIMIT/OFFSET.
13004 : * In <=7.2.X, LIMIT/OFFSET had to be after FOR UPDATE
13005 : * We now support both orderings, but prefer LIMIT/OFFSET before the locking
13006 : * clause.
13007 : * 2002-08-28 bjm
13008 : */
13009 : select_no_parens:
13010 402588 : simple_select { $$ = $1; }
13011 : | select_clause sort_clause
13012 : {
13013 72184 : insertSelectOptions((SelectStmt *) $1, $2, NIL,
13014 : NULL, NULL,
13015 : yyscanner);
13016 72184 : $$ = $1;
13017 : }
13018 : | select_clause opt_sort_clause for_locking_clause opt_select_limit
13019 : {
13020 10500 : insertSelectOptions((SelectStmt *) $1, $2, $3,
13021 10500 : $4,
13022 : NULL,
13023 : yyscanner);
13024 10500 : $$ = $1;
13025 : }
13026 : | select_clause opt_sort_clause select_limit opt_for_locking_clause
13027 : {
13028 4964 : insertSelectOptions((SelectStmt *) $1, $2, $4,
13029 4964 : $3,
13030 : NULL,
13031 : yyscanner);
13032 4952 : $$ = $1;
13033 : }
13034 : | with_clause select_clause
13035 : {
13036 2226 : insertSelectOptions((SelectStmt *) $2, NULL, NIL,
13037 : NULL,
13038 2226 : $1,
13039 : yyscanner);
13040 2226 : $$ = $2;
13041 : }
13042 : | with_clause select_clause sort_clause
13043 : {
13044 622 : insertSelectOptions((SelectStmt *) $2, $3, NIL,
13045 : NULL,
13046 622 : $1,
13047 : yyscanner);
13048 622 : $$ = $2;
13049 : }
13050 : | with_clause select_clause opt_sort_clause for_locking_clause opt_select_limit
13051 : {
13052 6 : insertSelectOptions((SelectStmt *) $2, $3, $4,
13053 6 : $5,
13054 6 : $1,
13055 : yyscanner);
13056 6 : $$ = $2;
13057 : }
13058 : | with_clause select_clause opt_sort_clause select_limit opt_for_locking_clause
13059 : {
13060 64 : insertSelectOptions((SelectStmt *) $2, $3, $5,
13061 64 : $4,
13062 64 : $1,
13063 : yyscanner);
13064 64 : $$ = $2;
13065 : }
13066 : ;
13067 :
13068 : select_clause:
13069 130236 : simple_select { $$ = $1; }
13070 590 : | select_with_parens { $$ = $1; }
13071 : ;
13072 :
13073 : /*
13074 : * This rule parses SELECT statements that can appear within set operations,
13075 : * including UNION, INTERSECT and EXCEPT. '(' and ')' can be used to specify
13076 : * the ordering of the set operations. Without '(' and ')' we want the
13077 : * operations to be ordered per the precedence specs at the head of this file.
13078 : *
13079 : * As with select_no_parens, simple_select cannot have outer parentheses,
13080 : * but can have parenthesized subclauses.
13081 : *
13082 : * It might appear that we could fold the first two alternatives into one
13083 : * by using opt_distinct_clause. However, that causes a shift/reduce conflict
13084 : * against INSERT ... SELECT ... ON CONFLICT. We avoid the ambiguity by
13085 : * requiring SELECT DISTINCT [ON] to be followed by a non-empty target_list.
13086 : *
13087 : * Note that sort clauses cannot be included at this level --- SQL requires
13088 : * SELECT foo UNION SELECT bar ORDER BY baz
13089 : * to be parsed as
13090 : * (SELECT foo UNION SELECT bar) ORDER BY baz
13091 : * not
13092 : * SELECT foo UNION (SELECT bar ORDER BY baz)
13093 : * Likewise for WITH, FOR UPDATE and LIMIT. Therefore, those clauses are
13094 : * described as part of the select_no_parens production, not simple_select.
13095 : * This does not limit functionality, because you can reintroduce these
13096 : * clauses inside parentheses.
13097 : *
13098 : * NOTE: only the leftmost component SelectStmt should have INTO.
13099 : * However, this is not checked by the grammar; parse analysis must check it.
13100 : */
13101 : simple_select:
13102 : SELECT opt_all_clause opt_target_list
13103 : into_clause from_clause where_clause
13104 : group_clause having_clause window_clause
13105 : {
13106 447910 : SelectStmt *n = makeNode(SelectStmt);
13107 :
13108 447910 : n->targetList = $3;
13109 447910 : n->intoClause = $4;
13110 447910 : n->fromClause = $5;
13111 447910 : n->whereClause = $6;
13112 447910 : n->groupClause = ($7)->list;
13113 447910 : n->groupDistinct = ($7)->distinct;
13114 447910 : n->groupByAll = ($7)->all;
13115 447910 : n->havingClause = $8;
13116 447910 : n->windowClause = $9;
13117 447910 : $$ = (Node *) n;
13118 : }
13119 : | SELECT distinct_clause target_list
13120 : into_clause from_clause where_clause
13121 : group_clause having_clause window_clause
13122 : {
13123 4064 : SelectStmt *n = makeNode(SelectStmt);
13124 :
13125 4064 : n->distinctClause = $2;
13126 4064 : n->targetList = $3;
13127 4064 : n->intoClause = $4;
13128 4064 : n->fromClause = $5;
13129 4064 : n->whereClause = $6;
13130 4064 : n->groupClause = ($7)->list;
13131 4064 : n->groupDistinct = ($7)->distinct;
13132 4064 : n->groupByAll = ($7)->all;
13133 4064 : n->havingClause = $8;
13134 4064 : n->windowClause = $9;
13135 4064 : $$ = (Node *) n;
13136 : }
13137 60412 : | values_clause { $$ = $1; }
13138 : | TABLE relation_expr
13139 : {
13140 : /* same as SELECT * FROM relation_expr */
13141 314 : ColumnRef *cr = makeNode(ColumnRef);
13142 314 : ResTarget *rt = makeNode(ResTarget);
13143 314 : SelectStmt *n = makeNode(SelectStmt);
13144 :
13145 314 : cr->fields = list_make1(makeNode(A_Star));
13146 314 : cr->location = -1;
13147 :
13148 314 : rt->name = NULL;
13149 314 : rt->indirection = NIL;
13150 314 : rt->val = (Node *) cr;
13151 314 : rt->location = -1;
13152 :
13153 314 : n->targetList = list_make1(rt);
13154 314 : n->fromClause = list_make1($2);
13155 314 : $$ = (Node *) n;
13156 : }
13157 : | select_clause UNION set_quantifier select_clause
13158 : {
13159 19354 : $$ = makeSetOp(SETOP_UNION, $3 == SET_QUANTIFIER_ALL, $1, $4);
13160 : }
13161 : | select_clause INTERSECT set_quantifier select_clause
13162 : {
13163 276 : $$ = makeSetOp(SETOP_INTERSECT, $3 == SET_QUANTIFIER_ALL, $1, $4);
13164 : }
13165 : | select_clause EXCEPT set_quantifier select_clause
13166 : {
13167 494 : $$ = makeSetOp(SETOP_EXCEPT, $3 == SET_QUANTIFIER_ALL, $1, $4);
13168 : }
13169 : ;
13170 :
13171 : /*
13172 : * SQL standard WITH clause looks like:
13173 : *
13174 : * WITH [ RECURSIVE ] <query name> [ (<column>,...) ]
13175 : * AS (query) [ SEARCH or CYCLE clause ]
13176 : *
13177 : * Recognizing WITH_LA here allows a CTE to be named TIME or ORDINALITY.
13178 : */
13179 : with_clause:
13180 : WITH cte_list
13181 : {
13182 2128 : $$ = makeNode(WithClause);
13183 2128 : $$->ctes = $2;
13184 2128 : $$->recursive = false;
13185 2128 : $$->location = @1;
13186 : }
13187 : | WITH_LA cte_list
13188 : {
13189 6 : $$ = makeNode(WithClause);
13190 6 : $$->ctes = $2;
13191 6 : $$->recursive = false;
13192 6 : $$->location = @1;
13193 : }
13194 : | WITH RECURSIVE cte_list
13195 : {
13196 1254 : $$ = makeNode(WithClause);
13197 1254 : $$->ctes = $3;
13198 1254 : $$->recursive = true;
13199 1254 : $$->location = @1;
13200 : }
13201 : ;
13202 :
13203 : cte_list:
13204 3388 : common_table_expr { $$ = list_make1($1); }
13205 1286 : | cte_list ',' common_table_expr { $$ = lappend($1, $3); }
13206 : ;
13207 :
13208 : common_table_expr: name opt_name_list AS opt_materialized '(' PreparableStmt ')' opt_search_clause opt_cycle_clause
13209 : {
13210 4674 : CommonTableExpr *n = makeNode(CommonTableExpr);
13211 :
13212 4674 : n->ctename = $1;
13213 4674 : n->aliascolnames = $2;
13214 4674 : n->ctematerialized = $4;
13215 4674 : n->ctequery = $6;
13216 4674 : n->search_clause = castNode(CTESearchClause, $8);
13217 4674 : n->cycle_clause = castNode(CTECycleClause, $9);
13218 4674 : n->location = @1;
13219 4674 : $$ = (Node *) n;
13220 : }
13221 : ;
13222 :
13223 : opt_materialized:
13224 178 : MATERIALIZED { $$ = CTEMaterializeAlways; }
13225 48 : | NOT MATERIALIZED { $$ = CTEMaterializeNever; }
13226 4448 : | /*EMPTY*/ { $$ = CTEMaterializeDefault; }
13227 : ;
13228 :
13229 : opt_search_clause:
13230 : SEARCH DEPTH FIRST_P BY columnList SET ColId
13231 : {
13232 90 : CTESearchClause *n = makeNode(CTESearchClause);
13233 :
13234 90 : n->search_col_list = $5;
13235 90 : n->search_breadth_first = false;
13236 90 : n->search_seq_column = $7;
13237 90 : n->location = @1;
13238 90 : $$ = (Node *) n;
13239 : }
13240 : | SEARCH BREADTH FIRST_P BY columnList SET ColId
13241 : {
13242 36 : CTESearchClause *n = makeNode(CTESearchClause);
13243 :
13244 36 : n->search_col_list = $5;
13245 36 : n->search_breadth_first = true;
13246 36 : n->search_seq_column = $7;
13247 36 : n->location = @1;
13248 36 : $$ = (Node *) n;
13249 : }
13250 : | /*EMPTY*/
13251 : {
13252 4548 : $$ = NULL;
13253 : }
13254 : ;
13255 :
13256 : opt_cycle_clause:
13257 : CYCLE columnList SET ColId TO AexprConst DEFAULT AexprConst USING ColId
13258 : {
13259 66 : CTECycleClause *n = makeNode(CTECycleClause);
13260 :
13261 66 : n->cycle_col_list = $2;
13262 66 : n->cycle_mark_column = $4;
13263 66 : n->cycle_mark_value = $6;
13264 66 : n->cycle_mark_default = $8;
13265 66 : n->cycle_path_column = $10;
13266 66 : n->location = @1;
13267 66 : $$ = (Node *) n;
13268 : }
13269 : | CYCLE columnList SET ColId USING ColId
13270 : {
13271 60 : CTECycleClause *n = makeNode(CTECycleClause);
13272 :
13273 60 : n->cycle_col_list = $2;
13274 60 : n->cycle_mark_column = $4;
13275 60 : n->cycle_mark_value = makeBoolAConst(true, -1);
13276 60 : n->cycle_mark_default = makeBoolAConst(false, -1);
13277 60 : n->cycle_path_column = $6;
13278 60 : n->location = @1;
13279 60 : $$ = (Node *) n;
13280 : }
13281 : | /*EMPTY*/
13282 : {
13283 4548 : $$ = NULL;
13284 : }
13285 : ;
13286 :
13287 : opt_with_clause:
13288 470 : with_clause { $$ = $1; }
13289 91470 : | /*EMPTY*/ { $$ = NULL; }
13290 : ;
13291 :
13292 : into_clause:
13293 : INTO OptTempTableName
13294 : {
13295 138 : $$ = makeNode(IntoClause);
13296 138 : $$->rel = $2;
13297 138 : $$->colNames = NIL;
13298 138 : $$->options = NIL;
13299 138 : $$->onCommit = ONCOMMIT_NOOP;
13300 138 : $$->tableSpaceName = NULL;
13301 138 : $$->viewQuery = NULL;
13302 138 : $$->skipData = false;
13303 : }
13304 : | /*EMPTY*/
13305 451866 : { $$ = NULL; }
13306 : ;
13307 :
13308 : /*
13309 : * Redundancy here is needed to avoid shift/reduce conflicts,
13310 : * since TEMP is not a reserved word. See also OptTemp.
13311 : */
13312 : OptTempTableName:
13313 : TEMPORARY opt_table qualified_name
13314 : {
13315 0 : $$ = $3;
13316 0 : $$->relpersistence = RELPERSISTENCE_TEMP;
13317 : }
13318 : | TEMP opt_table qualified_name
13319 : {
13320 6 : $$ = $3;
13321 6 : $$->relpersistence = RELPERSISTENCE_TEMP;
13322 : }
13323 : | LOCAL TEMPORARY opt_table qualified_name
13324 : {
13325 0 : $$ = $4;
13326 0 : $$->relpersistence = RELPERSISTENCE_TEMP;
13327 : }
13328 : | LOCAL TEMP opt_table qualified_name
13329 : {
13330 0 : $$ = $4;
13331 0 : $$->relpersistence = RELPERSISTENCE_TEMP;
13332 : }
13333 : | GLOBAL TEMPORARY opt_table qualified_name
13334 : {
13335 0 : ereport(WARNING,
13336 : (errmsg("GLOBAL is deprecated in temporary table creation"),
13337 : parser_errposition(@1)));
13338 0 : $$ = $4;
13339 0 : $$->relpersistence = RELPERSISTENCE_TEMP;
13340 : }
13341 : | GLOBAL TEMP opt_table qualified_name
13342 : {
13343 0 : ereport(WARNING,
13344 : (errmsg("GLOBAL is deprecated in temporary table creation"),
13345 : parser_errposition(@1)));
13346 0 : $$ = $4;
13347 0 : $$->relpersistence = RELPERSISTENCE_TEMP;
13348 : }
13349 : | UNLOGGED opt_table qualified_name
13350 : {
13351 0 : $$ = $3;
13352 0 : $$->relpersistence = RELPERSISTENCE_UNLOGGED;
13353 : }
13354 : | TABLE qualified_name
13355 : {
13356 30 : $$ = $2;
13357 30 : $$->relpersistence = RELPERSISTENCE_PERMANENT;
13358 : }
13359 : | qualified_name
13360 : {
13361 102 : $$ = $1;
13362 102 : $$->relpersistence = RELPERSISTENCE_PERMANENT;
13363 : }
13364 : ;
13365 :
13366 : opt_table: TABLE
13367 : | /*EMPTY*/
13368 : ;
13369 :
13370 : set_quantifier:
13371 11308 : ALL { $$ = SET_QUANTIFIER_ALL; }
13372 38 : | DISTINCT { $$ = SET_QUANTIFIER_DISTINCT; }
13373 13760 : | /*EMPTY*/ { $$ = SET_QUANTIFIER_DEFAULT; }
13374 : ;
13375 :
13376 : /* We use (NIL) as a placeholder to indicate that all target expressions
13377 : * should be placed in the DISTINCT list during parsetree analysis.
13378 : */
13379 : distinct_clause:
13380 3812 : DISTINCT { $$ = list_make1(NIL); }
13381 258 : | DISTINCT ON '(' expr_list ')' { $$ = $4; }
13382 : ;
13383 :
13384 : opt_all_clause:
13385 : ALL
13386 : | /*EMPTY*/
13387 : ;
13388 :
13389 : opt_distinct_clause:
13390 0 : distinct_clause { $$ = $1; }
13391 41384 : | opt_all_clause { $$ = NIL; }
13392 : ;
13393 :
13394 : opt_sort_clause:
13395 7586 : sort_clause { $$ = $1; }
13396 377096 : | /*EMPTY*/ { $$ = NIL; }
13397 : ;
13398 :
13399 : sort_clause:
13400 80740 : ORDER BY sortby_list { $$ = $3; }
13401 : ;
13402 :
13403 : sortby_list:
13404 80758 : sortby { $$ = list_make1($1); }
13405 29368 : | sortby_list ',' sortby { $$ = lappend($1, $3); }
13406 : ;
13407 :
13408 : sortby: a_expr USING qual_all_Op opt_nulls_order
13409 : {
13410 220 : $$ = makeNode(SortBy);
13411 220 : $$->node = $1;
13412 220 : $$->sortby_dir = SORTBY_USING;
13413 220 : $$->sortby_nulls = $4;
13414 220 : $$->useOp = $3;
13415 220 : $$->location = @3;
13416 : }
13417 : | a_expr opt_asc_desc opt_nulls_order
13418 : {
13419 109906 : $$ = makeNode(SortBy);
13420 109906 : $$->node = $1;
13421 109906 : $$->sortby_dir = $2;
13422 109906 : $$->sortby_nulls = $3;
13423 109906 : $$->useOp = NIL;
13424 109906 : $$->location = -1; /* no operator */
13425 : }
13426 : ;
13427 :
13428 :
13429 : select_limit:
13430 : limit_clause offset_clause
13431 : {
13432 172 : $$ = $1;
13433 172 : ($$)->limitOffset = $2;
13434 172 : ($$)->offsetLoc = @2;
13435 : }
13436 : | offset_clause limit_clause
13437 : {
13438 222 : $$ = $2;
13439 222 : ($$)->limitOffset = $1;
13440 222 : ($$)->offsetLoc = @1;
13441 : }
13442 : | limit_clause
13443 : {
13444 4356 : $$ = $1;
13445 : }
13446 : | offset_clause
13447 : {
13448 468 : SelectLimit *n = palloc_object(SelectLimit);
13449 :
13450 468 : n->limitOffset = $1;
13451 468 : n->limitCount = NULL;
13452 468 : n->limitOption = LIMIT_OPTION_COUNT;
13453 468 : n->offsetLoc = @1;
13454 468 : n->countLoc = -1;
13455 468 : n->optionLoc = -1;
13456 468 : $$ = n;
13457 : }
13458 : ;
13459 :
13460 : opt_select_limit:
13461 190 : select_limit { $$ = $1; }
13462 51700 : | /* EMPTY */ { $$ = NULL; }
13463 : ;
13464 :
13465 : limit_clause:
13466 : LIMIT select_limit_value
13467 : {
13468 4654 : SelectLimit *n = palloc_object(SelectLimit);
13469 :
13470 4654 : n->limitOffset = NULL;
13471 4654 : n->limitCount = $2;
13472 4654 : n->limitOption = LIMIT_OPTION_COUNT;
13473 4654 : n->offsetLoc = -1;
13474 4654 : n->countLoc = @1;
13475 4654 : n->optionLoc = -1;
13476 4654 : $$ = n;
13477 : }
13478 : | LIMIT select_limit_value ',' select_offset_value
13479 : {
13480 : /* Disabled because it was too confusing, bjm 2002-02-18 */
13481 0 : ereport(ERROR,
13482 : (errcode(ERRCODE_SYNTAX_ERROR),
13483 : errmsg("LIMIT #,# syntax is not supported"),
13484 : errhint("Use separate LIMIT and OFFSET clauses."),
13485 : parser_errposition(@1)));
13486 : }
13487 : /* SQL:2008 syntax */
13488 : /* to avoid shift/reduce conflicts, handle the optional value with
13489 : * a separate production rather than an opt_ expression. The fact
13490 : * that ONLY is fully reserved means that this way, we defer any
13491 : * decision about what rule reduces ROW or ROWS to the point where
13492 : * we can see the ONLY token in the lookahead slot.
13493 : */
13494 : | FETCH first_or_next select_fetch_first_value row_or_rows ONLY
13495 : {
13496 24 : SelectLimit *n = palloc_object(SelectLimit);
13497 :
13498 24 : n->limitOffset = NULL;
13499 24 : n->limitCount = $3;
13500 24 : n->limitOption = LIMIT_OPTION_COUNT;
13501 24 : n->offsetLoc = -1;
13502 24 : n->countLoc = @1;
13503 24 : n->optionLoc = -1;
13504 24 : $$ = n;
13505 : }
13506 : | FETCH first_or_next select_fetch_first_value row_or_rows WITH TIES
13507 : {
13508 66 : SelectLimit *n = palloc_object(SelectLimit);
13509 :
13510 66 : n->limitOffset = NULL;
13511 66 : n->limitCount = $3;
13512 66 : n->limitOption = LIMIT_OPTION_WITH_TIES;
13513 66 : n->offsetLoc = -1;
13514 66 : n->countLoc = @1;
13515 66 : n->optionLoc = @5;
13516 66 : $$ = n;
13517 : }
13518 : | FETCH first_or_next row_or_rows ONLY
13519 : {
13520 0 : SelectLimit *n = palloc_object(SelectLimit);
13521 :
13522 0 : n->limitOffset = NULL;
13523 0 : n->limitCount = makeIntConst(1, -1);
13524 0 : n->limitOption = LIMIT_OPTION_COUNT;
13525 0 : n->offsetLoc = -1;
13526 0 : n->countLoc = @1;
13527 0 : n->optionLoc = -1;
13528 0 : $$ = n;
13529 : }
13530 : | FETCH first_or_next row_or_rows WITH TIES
13531 : {
13532 6 : SelectLimit *n = palloc_object(SelectLimit);
13533 :
13534 6 : n->limitOffset = NULL;
13535 6 : n->limitCount = makeIntConst(1, -1);
13536 6 : n->limitOption = LIMIT_OPTION_WITH_TIES;
13537 6 : n->offsetLoc = -1;
13538 6 : n->countLoc = @1;
13539 6 : n->optionLoc = @4;
13540 6 : $$ = n;
13541 : }
13542 : ;
13543 :
13544 : offset_clause:
13545 : OFFSET select_offset_value
13546 862 : { $$ = $2; }
13547 : /* SQL:2008 syntax */
13548 : | OFFSET select_fetch_first_value row_or_rows
13549 0 : { $$ = $2; }
13550 : ;
13551 :
13552 : select_limit_value:
13553 4652 : a_expr { $$ = $1; }
13554 : | ALL
13555 : {
13556 : /* LIMIT ALL is represented as a NULL constant */
13557 2 : $$ = makeNullAConst(@1);
13558 : }
13559 : ;
13560 :
13561 : select_offset_value:
13562 862 : a_expr { $$ = $1; }
13563 : ;
13564 :
13565 : /*
13566 : * Allowing full expressions without parentheses causes various parsing
13567 : * problems with the trailing ROW/ROWS key words. SQL spec only calls for
13568 : * <simple value specification>, which is either a literal or a parameter (but
13569 : * an <SQL parameter reference> could be an identifier, bringing up conflicts
13570 : * with ROW/ROWS). We solve this by leveraging the presence of ONLY (see above)
13571 : * to determine whether the expression is missing rather than trying to make it
13572 : * optional in this rule.
13573 : *
13574 : * c_expr covers almost all the spec-required cases (and more), but it doesn't
13575 : * cover signed numeric literals, which are allowed by the spec. So we include
13576 : * those here explicitly. We need FCONST as well as ICONST because values that
13577 : * don't fit in the platform's "long", but do fit in bigint, should still be
13578 : * accepted here. (This is possible in 64-bit Windows as well as all 32-bit
13579 : * builds.)
13580 : */
13581 : select_fetch_first_value:
13582 90 : c_expr { $$ = $1; }
13583 : | '+' I_or_F_const
13584 0 : { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "+", NULL, $2, @1); }
13585 : | '-' I_or_F_const
13586 0 : { $$ = doNegate($2, @1); }
13587 : ;
13588 :
13589 : I_or_F_const:
13590 0 : Iconst { $$ = makeIntConst($1,@1); }
13591 0 : | FCONST { $$ = makeFloatConst($1,@1); }
13592 : ;
13593 :
13594 : /* noise words */
13595 36 : row_or_rows: ROW { $$ = 0; }
13596 60 : | ROWS { $$ = 0; }
13597 : ;
13598 :
13599 96 : first_or_next: FIRST_P { $$ = 0; }
13600 0 : | NEXT { $$ = 0; }
13601 : ;
13602 :
13603 :
13604 : /*
13605 : * This syntax for group_clause tries to follow the spec quite closely.
13606 : * However, the spec allows only column references, not expressions,
13607 : * which introduces an ambiguity between implicit row constructors
13608 : * (a,b) and lists of column references.
13609 : *
13610 : * We handle this by using the a_expr production for what the spec calls
13611 : * <ordinary grouping set>, which in the spec represents either one column
13612 : * reference or a parenthesized list of column references. Then, we check the
13613 : * top node of the a_expr to see if it's an implicit RowExpr, and if so, just
13614 : * grab and use the list, discarding the node. (this is done in parse analysis,
13615 : * not here)
13616 : *
13617 : * (we abuse the row_format field of RowExpr to distinguish implicit and
13618 : * explicit row constructors; it's debatable if anyone sanely wants to use them
13619 : * in a group clause, but if they have a reason to, we make it possible.)
13620 : *
13621 : * Each item in the group_clause list is either an expression tree or a
13622 : * GroupingSet node of some type.
13623 : */
13624 : group_clause:
13625 : GROUP_P BY set_quantifier group_by_list
13626 : {
13627 4970 : GroupClause *n = palloc_object(GroupClause);
13628 :
13629 4970 : n->distinct = $3 == SET_QUANTIFIER_DISTINCT;
13630 4970 : n->all = false;
13631 4970 : n->list = $4;
13632 4970 : $$ = n;
13633 : }
13634 : | GROUP_P BY ALL
13635 : {
13636 66 : GroupClause *n = palloc_object(GroupClause);
13637 66 : n->distinct = false;
13638 66 : n->all = true;
13639 66 : n->list = NIL;
13640 66 : $$ = n;
13641 : }
13642 : | /*EMPTY*/
13643 : {
13644 488322 : GroupClause *n = palloc_object(GroupClause);
13645 :
13646 488322 : n->distinct = false;
13647 488322 : n->all = false;
13648 488322 : n->list = NIL;
13649 488322 : $$ = n;
13650 : }
13651 : ;
13652 :
13653 : group_by_list:
13654 5646 : group_by_item { $$ = list_make1($1); }
13655 3106 : | group_by_list ',' group_by_item { $$ = lappend($1,$3); }
13656 : ;
13657 :
13658 : group_by_item:
13659 7282 : a_expr { $$ = $1; }
13660 306 : | empty_grouping_set { $$ = $1; }
13661 184 : | cube_clause { $$ = $1; }
13662 304 : | rollup_clause { $$ = $1; }
13663 676 : | grouping_sets_clause { $$ = $1; }
13664 : ;
13665 :
13666 : empty_grouping_set:
13667 : '(' ')'
13668 : {
13669 306 : $$ = (Node *) makeGroupingSet(GROUPING_SET_EMPTY, NIL, @1);
13670 : }
13671 : ;
13672 :
13673 : /*
13674 : * These hacks rely on setting precedence of CUBE and ROLLUP below that of '(',
13675 : * so that they shift in these rules rather than reducing the conflicting
13676 : * unreserved_keyword rule.
13677 : */
13678 :
13679 : rollup_clause:
13680 : ROLLUP '(' expr_list ')'
13681 : {
13682 304 : $$ = (Node *) makeGroupingSet(GROUPING_SET_ROLLUP, $3, @1);
13683 : }
13684 : ;
13685 :
13686 : cube_clause:
13687 : CUBE '(' expr_list ')'
13688 : {
13689 184 : $$ = (Node *) makeGroupingSet(GROUPING_SET_CUBE, $3, @1);
13690 : }
13691 : ;
13692 :
13693 : grouping_sets_clause:
13694 : GROUPING SETS '(' group_by_list ')'
13695 : {
13696 676 : $$ = (Node *) makeGroupingSet(GROUPING_SET_SETS, $4, @1);
13697 : }
13698 : ;
13699 :
13700 : having_clause:
13701 786 : HAVING a_expr { $$ = $2; }
13702 492572 : | /*EMPTY*/ { $$ = NULL; }
13703 : ;
13704 :
13705 : for_locking_clause:
13706 10846 : for_locking_items { $$ = $1; }
13707 0 : | FOR READ ONLY { $$ = NIL; }
13708 : ;
13709 :
13710 : opt_for_locking_clause:
13711 340 : for_locking_clause { $$ = $1; }
13712 46072 : | /* EMPTY */ { $$ = NIL; }
13713 : ;
13714 :
13715 : for_locking_items:
13716 10846 : for_locking_item { $$ = list_make1($1); }
13717 102 : | for_locking_items for_locking_item { $$ = lappend($1, $2); }
13718 : ;
13719 :
13720 : for_locking_item:
13721 : for_locking_strength locked_rels_list opt_nowait_or_skip
13722 : {
13723 10948 : LockingClause *n = makeNode(LockingClause);
13724 :
13725 10948 : n->lockedRels = $2;
13726 10948 : n->strength = $1;
13727 10948 : n->waitPolicy = $3;
13728 10948 : $$ = (Node *) n;
13729 : }
13730 : ;
13731 :
13732 : for_locking_strength:
13733 1562 : FOR UPDATE { $$ = LCS_FORUPDATE; }
13734 82 : | FOR NO KEY UPDATE { $$ = LCS_FORNOKEYUPDATE; }
13735 220 : | FOR SHARE { $$ = LCS_FORSHARE; }
13736 9084 : | FOR KEY SHARE { $$ = LCS_FORKEYSHARE; }
13737 : ;
13738 :
13739 : locked_rels_list:
13740 3578 : OF qualified_name_list { $$ = $2; }
13741 7370 : | /* EMPTY */ { $$ = NIL; }
13742 : ;
13743 :
13744 :
13745 : /*
13746 : * We should allow ROW '(' expr_list ')' too, but that seems to require
13747 : * making VALUES a fully reserved word, which will probably break more apps
13748 : * than allowing the noise-word is worth.
13749 : */
13750 : values_clause:
13751 : VALUES '(' expr_list ')'
13752 : {
13753 60412 : SelectStmt *n = makeNode(SelectStmt);
13754 :
13755 60412 : n->valuesLists = list_make1($3);
13756 60412 : $$ = (Node *) n;
13757 : }
13758 : | values_clause ',' '(' expr_list ')'
13759 : {
13760 26464 : SelectStmt *n = (SelectStmt *) $1;
13761 :
13762 26464 : n->valuesLists = lappend(n->valuesLists, $4);
13763 26464 : $$ = (Node *) n;
13764 : }
13765 : ;
13766 :
13767 :
13768 : /*****************************************************************************
13769 : *
13770 : * clauses common to all Optimizable Stmts:
13771 : * from_clause - allow list of both JOIN expressions and table names
13772 : * where_clause - qualifications for joins or restrictions
13773 : *
13774 : *****************************************************************************/
13775 :
13776 : from_clause:
13777 331018 : FROM from_list { $$ = $2; }
13778 177270 : | /*EMPTY*/ { $$ = NIL; }
13779 : ;
13780 :
13781 : from_list:
13782 332000 : table_ref { $$ = list_make1($1); }
13783 62050 : | from_list ',' table_ref { $$ = lappend($1, $3); }
13784 : ;
13785 :
13786 : /*
13787 : * table_ref is where an alias clause can be attached.
13788 : */
13789 : table_ref: relation_expr opt_alias_clause
13790 : {
13791 409724 : $1->alias = $2;
13792 409724 : $$ = (Node *) $1;
13793 : }
13794 : | relation_expr opt_alias_clause tablesample_clause
13795 : {
13796 266 : RangeTableSample *n = (RangeTableSample *) $3;
13797 :
13798 266 : $1->alias = $2;
13799 : /* relation_expr goes inside the RangeTableSample node */
13800 266 : n->relation = (Node *) $1;
13801 266 : $$ = (Node *) n;
13802 : }
13803 : | func_table func_alias_clause
13804 : {
13805 47438 : RangeFunction *n = (RangeFunction *) $1;
13806 :
13807 47438 : n->alias = linitial($2);
13808 47438 : n->coldeflist = lsecond($2);
13809 47438 : $$ = (Node *) n;
13810 : }
13811 : | LATERAL_P func_table func_alias_clause
13812 : {
13813 1322 : RangeFunction *n = (RangeFunction *) $2;
13814 :
13815 1322 : n->lateral = true;
13816 1322 : n->alias = linitial($3);
13817 1322 : n->coldeflist = lsecond($3);
13818 1322 : $$ = (Node *) n;
13819 : }
13820 : | xmltable opt_alias_clause
13821 : {
13822 86 : RangeTableFunc *n = (RangeTableFunc *) $1;
13823 :
13824 86 : n->alias = $2;
13825 86 : $$ = (Node *) n;
13826 : }
13827 : | LATERAL_P xmltable opt_alias_clause
13828 : {
13829 140 : RangeTableFunc *n = (RangeTableFunc *) $2;
13830 :
13831 140 : n->lateral = true;
13832 140 : n->alias = $3;
13833 140 : $$ = (Node *) n;
13834 : }
13835 : | select_with_parens opt_alias_clause
13836 : {
13837 19880 : RangeSubselect *n = makeNode(RangeSubselect);
13838 :
13839 19880 : n->lateral = false;
13840 19880 : n->subquery = $1;
13841 19880 : n->alias = $2;
13842 19880 : $$ = (Node *) n;
13843 : }
13844 : | LATERAL_P select_with_parens opt_alias_clause
13845 : {
13846 1936 : RangeSubselect *n = makeNode(RangeSubselect);
13847 :
13848 1936 : n->lateral = true;
13849 1936 : n->subquery = $2;
13850 1936 : n->alias = $3;
13851 1936 : $$ = (Node *) n;
13852 : }
13853 : | joined_table
13854 : {
13855 84884 : $$ = (Node *) $1;
13856 : }
13857 : | '(' joined_table ')' alias_clause
13858 : {
13859 174 : $2->alias = $4;
13860 174 : $$ = (Node *) $2;
13861 : }
13862 : | json_table opt_alias_clause
13863 : {
13864 530 : JsonTable *jt = castNode(JsonTable, $1);
13865 :
13866 530 : jt->alias = $2;
13867 530 : $$ = (Node *) jt;
13868 : }
13869 : | LATERAL_P json_table opt_alias_clause
13870 : {
13871 0 : JsonTable *jt = castNode(JsonTable, $2);
13872 :
13873 0 : jt->alias = $3;
13874 0 : jt->lateral = true;
13875 0 : $$ = (Node *) jt;
13876 : }
13877 : ;
13878 :
13879 :
13880 : /*
13881 : * It may seem silly to separate joined_table from table_ref, but there is
13882 : * method in SQL's madness: if you don't do it this way you get reduce-
13883 : * reduce conflicts, because it's not clear to the parser generator whether
13884 : * to expect alias_clause after ')' or not. For the same reason we must
13885 : * treat 'JOIN' and 'join_type JOIN' separately, rather than allowing
13886 : * join_type to expand to empty; if we try it, the parser generator can't
13887 : * figure out when to reduce an empty join_type right after table_ref.
13888 : *
13889 : * Note that a CROSS JOIN is the same as an unqualified
13890 : * INNER JOIN, and an INNER JOIN/ON has the same shape
13891 : * but a qualification expression to limit membership.
13892 : * A NATURAL JOIN implicitly matches column names between
13893 : * tables and the shape is determined by which columns are
13894 : * in common. We'll collect columns during the later transformations.
13895 : */
13896 :
13897 : joined_table:
13898 : '(' joined_table ')'
13899 : {
13900 4024 : $$ = $2;
13901 : }
13902 : | table_ref CROSS JOIN table_ref
13903 : {
13904 : /* CROSS JOIN is same as unqualified inner join */
13905 524 : JoinExpr *n = makeNode(JoinExpr);
13906 :
13907 524 : n->jointype = JOIN_INNER;
13908 524 : n->isNatural = false;
13909 524 : n->larg = $1;
13910 524 : n->rarg = $4;
13911 524 : n->usingClause = NIL;
13912 524 : n->join_using_alias = NULL;
13913 524 : n->quals = NULL;
13914 524 : $$ = n;
13915 : }
13916 : | table_ref join_type JOIN table_ref join_qual
13917 : {
13918 47772 : JoinExpr *n = makeNode(JoinExpr);
13919 :
13920 47772 : n->jointype = $2;
13921 47772 : n->isNatural = false;
13922 47772 : n->larg = $1;
13923 47772 : n->rarg = $4;
13924 47772 : if ($5 != NULL && IsA($5, List))
13925 : {
13926 : /* USING clause */
13927 498 : n->usingClause = linitial_node(List, castNode(List, $5));
13928 498 : n->join_using_alias = lsecond_node(Alias, castNode(List, $5));
13929 : }
13930 : else
13931 : {
13932 : /* ON clause */
13933 47274 : n->quals = $5;
13934 : }
13935 47772 : $$ = n;
13936 : }
13937 : | table_ref JOIN table_ref join_qual
13938 : {
13939 : /* letting join_type reduce to empty doesn't work */
13940 36498 : JoinExpr *n = makeNode(JoinExpr);
13941 :
13942 36498 : n->jointype = JOIN_INNER;
13943 36498 : n->isNatural = false;
13944 36498 : n->larg = $1;
13945 36498 : n->rarg = $3;
13946 36498 : if ($4 != NULL && IsA($4, List))
13947 : {
13948 : /* USING clause */
13949 744 : n->usingClause = linitial_node(List, castNode(List, $4));
13950 744 : n->join_using_alias = lsecond_node(Alias, castNode(List, $4));
13951 : }
13952 : else
13953 : {
13954 : /* ON clause */
13955 35754 : n->quals = $4;
13956 : }
13957 36498 : $$ = n;
13958 : }
13959 : | table_ref NATURAL join_type JOIN table_ref
13960 : {
13961 78 : JoinExpr *n = makeNode(JoinExpr);
13962 :
13963 78 : n->jointype = $3;
13964 78 : n->isNatural = true;
13965 78 : n->larg = $1;
13966 78 : n->rarg = $5;
13967 78 : n->usingClause = NIL; /* figure out which columns later... */
13968 78 : n->join_using_alias = NULL;
13969 78 : n->quals = NULL; /* fill later */
13970 78 : $$ = n;
13971 : }
13972 : | table_ref NATURAL JOIN table_ref
13973 : {
13974 : /* letting join_type reduce to empty doesn't work */
13975 186 : JoinExpr *n = makeNode(JoinExpr);
13976 :
13977 186 : n->jointype = JOIN_INNER;
13978 186 : n->isNatural = true;
13979 186 : n->larg = $1;
13980 186 : n->rarg = $4;
13981 186 : n->usingClause = NIL; /* figure out which columns later... */
13982 186 : n->join_using_alias = NULL;
13983 186 : n->quals = NULL; /* fill later */
13984 186 : $$ = n;
13985 : }
13986 : ;
13987 :
13988 : alias_clause:
13989 : AS ColId '(' name_list ')'
13990 : {
13991 6800 : $$ = makeNode(Alias);
13992 6800 : $$->aliasname = $2;
13993 6800 : $$->colnames = $4;
13994 : }
13995 : | AS ColId
13996 : {
13997 16576 : $$ = makeNode(Alias);
13998 16576 : $$->aliasname = $2;
13999 : }
14000 : | ColId '(' name_list ')'
14001 : {
14002 5886 : $$ = makeNode(Alias);
14003 5886 : $$->aliasname = $1;
14004 5886 : $$->colnames = $3;
14005 : }
14006 : | ColId
14007 : {
14008 267468 : $$ = makeNode(Alias);
14009 267468 : $$->aliasname = $1;
14010 : }
14011 : ;
14012 :
14013 267534 : opt_alias_clause: alias_clause { $$ = $1; }
14014 165028 : | /*EMPTY*/ { $$ = NULL; }
14015 : ;
14016 :
14017 : /*
14018 : * The alias clause after JOIN ... USING only accepts the AS ColId spelling,
14019 : * per SQL standard. (The grammar could parse the other variants, but they
14020 : * don't seem to be useful, and it might lead to parser problems in the
14021 : * future.)
14022 : */
14023 : opt_alias_clause_for_join_using:
14024 : AS ColId
14025 : {
14026 84 : $$ = makeNode(Alias);
14027 84 : $$->aliasname = $2;
14028 : /* the column name list will be inserted later */
14029 : }
14030 1158 : | /*EMPTY*/ { $$ = NULL; }
14031 : ;
14032 :
14033 : /*
14034 : * func_alias_clause can include both an Alias and a coldeflist, so we make it
14035 : * return a 2-element list that gets disassembled by calling production.
14036 : */
14037 : func_alias_clause:
14038 : alias_clause
14039 : {
14040 29022 : $$ = list_make2($1, NIL);
14041 : }
14042 : | AS '(' TableFuncElementList ')'
14043 : {
14044 114 : $$ = list_make2(NULL, $3);
14045 : }
14046 : | AS ColId '(' TableFuncElementList ')'
14047 : {
14048 596 : Alias *a = makeNode(Alias);
14049 :
14050 596 : a->aliasname = $2;
14051 596 : $$ = list_make2(a, $4);
14052 : }
14053 : | ColId '(' TableFuncElementList ')'
14054 : {
14055 50 : Alias *a = makeNode(Alias);
14056 :
14057 50 : a->aliasname = $1;
14058 50 : $$ = list_make2(a, $3);
14059 : }
14060 : | /*EMPTY*/
14061 : {
14062 18978 : $$ = list_make2(NULL, NIL);
14063 : }
14064 : ;
14065 :
14066 1042 : join_type: FULL opt_outer { $$ = JOIN_FULL; }
14067 42392 : | LEFT opt_outer { $$ = JOIN_LEFT; }
14068 390 : | RIGHT opt_outer { $$ = JOIN_RIGHT; }
14069 4026 : | INNER_P { $$ = JOIN_INNER; }
14070 : ;
14071 :
14072 : /* OUTER is just noise... */
14073 : opt_outer: OUTER_P
14074 : | /*EMPTY*/
14075 : ;
14076 :
14077 : /* JOIN qualification clauses
14078 : * Possibilities are:
14079 : * USING ( column list ) [ AS alias ]
14080 : * allows only unqualified column names,
14081 : * which must match between tables.
14082 : * ON expr allows more general qualifications.
14083 : *
14084 : * We return USING as a two-element List (the first item being a sub-List
14085 : * of the common column names, and the second either an Alias item or NULL).
14086 : * An ON-expr will not be a List, so it can be told apart that way.
14087 : */
14088 :
14089 : join_qual: USING '(' name_list ')' opt_alias_clause_for_join_using
14090 : {
14091 1242 : $$ = (Node *) list_make2($3, $5);
14092 : }
14093 : | ON a_expr
14094 : {
14095 83028 : $$ = $2;
14096 : }
14097 : ;
14098 :
14099 :
14100 : relation_expr:
14101 : qualified_name
14102 : {
14103 : /* inheritance query, implicitly */
14104 493602 : $$ = $1;
14105 493602 : $$->inh = true;
14106 493602 : $$->alias = NULL;
14107 : }
14108 : | extended_relation_expr
14109 : {
14110 7318 : $$ = $1;
14111 : }
14112 : ;
14113 :
14114 : extended_relation_expr:
14115 : qualified_name '*'
14116 : {
14117 : /* inheritance query, explicitly */
14118 204 : $$ = $1;
14119 204 : $$->inh = true;
14120 204 : $$->alias = NULL;
14121 : }
14122 : | ONLY qualified_name
14123 : {
14124 : /* no inheritance */
14125 7120 : $$ = $2;
14126 7120 : $$->inh = false;
14127 7120 : $$->alias = NULL;
14128 : }
14129 : | ONLY '(' qualified_name ')'
14130 : {
14131 : /* no inheritance, SQL99-style syntax */
14132 0 : $$ = $3;
14133 0 : $$->inh = false;
14134 0 : $$->alias = NULL;
14135 : }
14136 : ;
14137 :
14138 :
14139 : relation_expr_list:
14140 2854 : relation_expr { $$ = list_make1($1); }
14141 11230 : | relation_expr_list ',' relation_expr { $$ = lappend($1, $3); }
14142 : ;
14143 :
14144 :
14145 : /*
14146 : * Given "UPDATE foo set set ...", we have to decide without looking any
14147 : * further ahead whether the first "set" is an alias or the UPDATE's SET
14148 : * keyword. Since "set" is allowed as a column name both interpretations
14149 : * are feasible. We resolve the shift/reduce conflict by giving the first
14150 : * relation_expr_opt_alias production a higher precedence than the SET token
14151 : * has, causing the parser to prefer to reduce, in effect assuming that the
14152 : * SET is not an alias.
14153 : */
14154 : relation_expr_opt_alias: relation_expr %prec UMINUS
14155 : {
14156 19460 : $$ = $1;
14157 : }
14158 : | relation_expr ColId
14159 : {
14160 2304 : Alias *alias = makeNode(Alias);
14161 :
14162 2304 : alias->aliasname = $2;
14163 2304 : $1->alias = alias;
14164 2304 : $$ = $1;
14165 : }
14166 : | relation_expr AS ColId
14167 : {
14168 90 : Alias *alias = makeNode(Alias);
14169 :
14170 90 : alias->aliasname = $3;
14171 90 : $1->alias = alias;
14172 90 : $$ = $1;
14173 : }
14174 : ;
14175 :
14176 : /*
14177 : * TABLESAMPLE decoration in a FROM item
14178 : */
14179 : tablesample_clause:
14180 : TABLESAMPLE func_name '(' expr_list ')' opt_repeatable_clause
14181 : {
14182 266 : RangeTableSample *n = makeNode(RangeTableSample);
14183 :
14184 : /* n->relation will be filled in later */
14185 266 : n->method = $2;
14186 266 : n->args = $4;
14187 266 : n->repeatable = $6;
14188 266 : n->location = @2;
14189 266 : $$ = (Node *) n;
14190 : }
14191 : ;
14192 :
14193 : opt_repeatable_clause:
14194 108 : REPEATABLE '(' a_expr ')' { $$ = (Node *) $3; }
14195 158 : | /*EMPTY*/ { $$ = NULL; }
14196 : ;
14197 :
14198 : /*
14199 : * func_table represents a function invocation in a FROM list. It can be
14200 : * a plain function call, like "foo(...)", or a ROWS FROM expression with
14201 : * one or more function calls, "ROWS FROM (foo(...), bar(...))",
14202 : * optionally with WITH ORDINALITY attached.
14203 : * In the ROWS FROM syntax, a column definition list can be given for each
14204 : * function, for example:
14205 : * ROWS FROM (foo() AS (foo_res_a text, foo_res_b text),
14206 : * bar() AS (bar_res_a text, bar_res_b text))
14207 : * It's also possible to attach a column definition list to the RangeFunction
14208 : * as a whole, but that's handled by the table_ref production.
14209 : */
14210 : func_table: func_expr_windowless opt_ordinality
14211 : {
14212 48634 : RangeFunction *n = makeNode(RangeFunction);
14213 :
14214 48634 : n->lateral = false;
14215 48634 : n->ordinality = $2;
14216 48634 : n->is_rowsfrom = false;
14217 48634 : n->functions = list_make1(list_make2($1, NIL));
14218 : /* alias and coldeflist are set by table_ref production */
14219 48634 : $$ = (Node *) n;
14220 : }
14221 : | ROWS FROM '(' rowsfrom_list ')' opt_ordinality
14222 : {
14223 132 : RangeFunction *n = makeNode(RangeFunction);
14224 :
14225 132 : n->lateral = false;
14226 132 : n->ordinality = $6;
14227 132 : n->is_rowsfrom = true;
14228 132 : n->functions = $4;
14229 : /* alias and coldeflist are set by table_ref production */
14230 132 : $$ = (Node *) n;
14231 : }
14232 : ;
14233 :
14234 : rowsfrom_item: func_expr_windowless opt_col_def_list
14235 318 : { $$ = list_make2($1, $2); }
14236 : ;
14237 :
14238 : rowsfrom_list:
14239 132 : rowsfrom_item { $$ = list_make1($1); }
14240 186 : | rowsfrom_list ',' rowsfrom_item { $$ = lappend($1, $3); }
14241 : ;
14242 :
14243 54 : opt_col_def_list: AS '(' TableFuncElementList ')' { $$ = $3; }
14244 264 : | /*EMPTY*/ { $$ = NIL; }
14245 : ;
14246 :
14247 956 : opt_ordinality: WITH_LA ORDINALITY { $$ = true; }
14248 47810 : | /*EMPTY*/ { $$ = false; }
14249 : ;
14250 :
14251 :
14252 : where_clause:
14253 220622 : WHERE a_expr { $$ = $2; }
14254 294242 : | /*EMPTY*/ { $$ = NULL; }
14255 : ;
14256 :
14257 : /* variant for UPDATE and DELETE */
14258 : where_or_current_clause:
14259 14252 : WHERE a_expr { $$ = $2; }
14260 : | WHERE CURRENT_P OF cursor_name
14261 : {
14262 266 : CurrentOfExpr *n = makeNode(CurrentOfExpr);
14263 :
14264 : /* cvarno is filled in by parse analysis */
14265 266 : n->cursor_name = $4;
14266 266 : n->cursor_param = 0;
14267 266 : $$ = (Node *) n;
14268 : }
14269 5110 : | /*EMPTY*/ { $$ = NULL; }
14270 : ;
14271 :
14272 :
14273 : OptTableFuncElementList:
14274 716 : TableFuncElementList { $$ = $1; }
14275 3786 : | /*EMPTY*/ { $$ = NIL; }
14276 : ;
14277 :
14278 : TableFuncElementList:
14279 : TableFuncElement
14280 : {
14281 1530 : $$ = list_make1($1);
14282 : }
14283 : | TableFuncElementList ',' TableFuncElement
14284 : {
14285 2058 : $$ = lappend($1, $3);
14286 : }
14287 : ;
14288 :
14289 : TableFuncElement: ColId Typename opt_collate_clause
14290 : {
14291 3652 : ColumnDef *n = makeNode(ColumnDef);
14292 :
14293 3652 : n->colname = $1;
14294 3652 : n->typeName = $2;
14295 3652 : n->inhcount = 0;
14296 3652 : n->is_local = true;
14297 3652 : n->is_not_null = false;
14298 3652 : n->is_from_type = false;
14299 3652 : n->storage = 0;
14300 3652 : n->raw_default = NULL;
14301 3652 : n->cooked_default = NULL;
14302 3652 : n->collClause = (CollateClause *) $3;
14303 3652 : n->collOid = InvalidOid;
14304 3652 : n->constraints = NIL;
14305 3652 : n->location = @1;
14306 3652 : $$ = (Node *) n;
14307 : }
14308 : ;
14309 :
14310 : /*
14311 : * XMLTABLE
14312 : */
14313 : xmltable:
14314 : XMLTABLE '(' c_expr xmlexists_argument COLUMNS xmltable_column_list ')'
14315 : {
14316 206 : RangeTableFunc *n = makeNode(RangeTableFunc);
14317 :
14318 206 : n->rowexpr = $3;
14319 206 : n->docexpr = $4;
14320 206 : n->columns = $6;
14321 206 : n->namespaces = NIL;
14322 206 : n->location = @1;
14323 206 : $$ = (Node *) n;
14324 : }
14325 : | XMLTABLE '(' XMLNAMESPACES '(' xml_namespace_list ')' ','
14326 : c_expr xmlexists_argument COLUMNS xmltable_column_list ')'
14327 : {
14328 20 : RangeTableFunc *n = makeNode(RangeTableFunc);
14329 :
14330 20 : n->rowexpr = $8;
14331 20 : n->docexpr = $9;
14332 20 : n->columns = $11;
14333 20 : n->namespaces = $5;
14334 20 : n->location = @1;
14335 20 : $$ = (Node *) n;
14336 : }
14337 : ;
14338 :
14339 226 : xmltable_column_list: xmltable_column_el { $$ = list_make1($1); }
14340 530 : | xmltable_column_list ',' xmltable_column_el { $$ = lappend($1, $3); }
14341 : ;
14342 :
14343 : xmltable_column_el:
14344 : ColId Typename
14345 : {
14346 204 : RangeTableFuncCol *fc = makeNode(RangeTableFuncCol);
14347 :
14348 204 : fc->colname = $1;
14349 204 : fc->for_ordinality = false;
14350 204 : fc->typeName = $2;
14351 204 : fc->is_not_null = false;
14352 204 : fc->colexpr = NULL;
14353 204 : fc->coldefexpr = NULL;
14354 204 : fc->location = @1;
14355 :
14356 204 : $$ = (Node *) fc;
14357 : }
14358 : | ColId Typename xmltable_column_option_list
14359 : {
14360 490 : RangeTableFuncCol *fc = makeNode(RangeTableFuncCol);
14361 : ListCell *option;
14362 490 : bool nullability_seen = false;
14363 :
14364 490 : fc->colname = $1;
14365 490 : fc->typeName = $2;
14366 490 : fc->for_ordinality = false;
14367 490 : fc->is_not_null = false;
14368 490 : fc->colexpr = NULL;
14369 490 : fc->coldefexpr = NULL;
14370 490 : fc->location = @1;
14371 :
14372 1092 : foreach(option, $3)
14373 : {
14374 602 : DefElem *defel = (DefElem *) lfirst(option);
14375 :
14376 602 : if (strcmp(defel->defname, "default") == 0)
14377 : {
14378 56 : if (fc->coldefexpr != NULL)
14379 0 : ereport(ERROR,
14380 : (errcode(ERRCODE_SYNTAX_ERROR),
14381 : errmsg("only one DEFAULT value is allowed"),
14382 : parser_errposition(defel->location)));
14383 56 : fc->coldefexpr = defel->arg;
14384 : }
14385 546 : else if (strcmp(defel->defname, "path") == 0)
14386 : {
14387 490 : if (fc->colexpr != NULL)
14388 0 : ereport(ERROR,
14389 : (errcode(ERRCODE_SYNTAX_ERROR),
14390 : errmsg("only one PATH value per column is allowed"),
14391 : parser_errposition(defel->location)));
14392 490 : fc->colexpr = defel->arg;
14393 : }
14394 56 : else if (strcmp(defel->defname, "__pg__is_not_null") == 0)
14395 : {
14396 56 : if (nullability_seen)
14397 0 : ereport(ERROR,
14398 : (errcode(ERRCODE_SYNTAX_ERROR),
14399 : errmsg("conflicting or redundant NULL / NOT NULL declarations for column \"%s\"", fc->colname),
14400 : parser_errposition(defel->location)));
14401 56 : fc->is_not_null = boolVal(defel->arg);
14402 56 : nullability_seen = true;
14403 : }
14404 : else
14405 : {
14406 0 : ereport(ERROR,
14407 : (errcode(ERRCODE_SYNTAX_ERROR),
14408 : errmsg("unrecognized column option \"%s\"",
14409 : defel->defname),
14410 : parser_errposition(defel->location)));
14411 : }
14412 : }
14413 490 : $$ = (Node *) fc;
14414 : }
14415 : | ColId FOR ORDINALITY
14416 : {
14417 62 : RangeTableFuncCol *fc = makeNode(RangeTableFuncCol);
14418 :
14419 62 : fc->colname = $1;
14420 62 : fc->for_ordinality = true;
14421 : /* other fields are ignored, initialized by makeNode */
14422 62 : fc->location = @1;
14423 :
14424 62 : $$ = (Node *) fc;
14425 : }
14426 : ;
14427 :
14428 : xmltable_column_option_list:
14429 : xmltable_column_option_el
14430 490 : { $$ = list_make1($1); }
14431 : | xmltable_column_option_list xmltable_column_option_el
14432 112 : { $$ = lappend($1, $2); }
14433 : ;
14434 :
14435 : xmltable_column_option_el:
14436 : IDENT b_expr
14437 : {
14438 6 : if (strcmp($1, "__pg__is_not_null") == 0)
14439 6 : ereport(ERROR,
14440 : (errcode(ERRCODE_SYNTAX_ERROR),
14441 : errmsg("option name \"%s\" cannot be used in XMLTABLE", $1),
14442 : parser_errposition(@1)));
14443 0 : $$ = makeDefElem($1, $2, @1);
14444 : }
14445 : | DEFAULT b_expr
14446 56 : { $$ = makeDefElem("default", $2, @1); }
14447 : | NOT NULL_P
14448 56 : { $$ = makeDefElem("__pg__is_not_null", (Node *) makeBoolean(true), @1); }
14449 : | NULL_P
14450 0 : { $$ = makeDefElem("__pg__is_not_null", (Node *) makeBoolean(false), @1); }
14451 : | PATH b_expr
14452 490 : { $$ = makeDefElem("path", $2, @1); }
14453 : ;
14454 :
14455 : xml_namespace_list:
14456 : xml_namespace_el
14457 20 : { $$ = list_make1($1); }
14458 : | xml_namespace_list ',' xml_namespace_el
14459 0 : { $$ = lappend($1, $3); }
14460 : ;
14461 :
14462 : xml_namespace_el:
14463 : b_expr AS ColLabel
14464 : {
14465 14 : $$ = makeNode(ResTarget);
14466 14 : $$->name = $3;
14467 14 : $$->indirection = NIL;
14468 14 : $$->val = $1;
14469 14 : $$->location = @1;
14470 : }
14471 : | DEFAULT b_expr
14472 : {
14473 6 : $$ = makeNode(ResTarget);
14474 6 : $$->name = NULL;
14475 6 : $$->indirection = NIL;
14476 6 : $$->val = $2;
14477 6 : $$->location = @1;
14478 : }
14479 : ;
14480 :
14481 : json_table:
14482 : JSON_TABLE '('
14483 : json_value_expr ',' a_expr json_table_path_name_opt
14484 : json_passing_clause_opt
14485 : COLUMNS '(' json_table_column_definition_list ')'
14486 : json_on_error_clause_opt
14487 : ')'
14488 : {
14489 536 : JsonTable *n = makeNode(JsonTable);
14490 : char *pathstring;
14491 :
14492 536 : n->context_item = (JsonValueExpr *) $3;
14493 536 : if (!IsA($5, A_Const) ||
14494 530 : castNode(A_Const, $5)->val.node.type != T_String)
14495 6 : ereport(ERROR,
14496 : errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
14497 : errmsg("only string constants are supported in JSON_TABLE path specification"),
14498 : parser_errposition(@5));
14499 530 : pathstring = castNode(A_Const, $5)->val.sval.sval;
14500 530 : n->pathspec = makeJsonTablePathSpec(pathstring, $6, @5, @6);
14501 530 : n->passing = $7;
14502 530 : n->columns = $10;
14503 530 : n->on_error = (JsonBehavior *) $12;
14504 530 : n->location = @1;
14505 530 : $$ = (Node *) n;
14506 : }
14507 : ;
14508 :
14509 : json_table_path_name_opt:
14510 62 : AS name { $$ = $2; }
14511 486 : | /* empty */ { $$ = NULL; }
14512 : ;
14513 :
14514 : json_table_column_definition_list:
14515 : json_table_column_definition
14516 826 : { $$ = list_make1($1); }
14517 : | json_table_column_definition_list ',' json_table_column_definition
14518 528 : { $$ = lappend($1, $3); }
14519 : ;
14520 :
14521 : json_table_column_definition:
14522 : ColId FOR ORDINALITY
14523 : {
14524 84 : JsonTableColumn *n = makeNode(JsonTableColumn);
14525 :
14526 84 : n->coltype = JTC_FOR_ORDINALITY;
14527 84 : n->name = $1;
14528 84 : n->location = @1;
14529 84 : $$ = (Node *) n;
14530 : }
14531 : | ColId Typename
14532 : json_table_column_path_clause_opt
14533 : json_wrapper_behavior
14534 : json_quotes_clause_opt
14535 : json_behavior_clause_opt
14536 : {
14537 734 : JsonTableColumn *n = makeNode(JsonTableColumn);
14538 :
14539 734 : n->coltype = JTC_REGULAR;
14540 734 : n->name = $1;
14541 734 : n->typeName = $2;
14542 734 : n->format = makeJsonFormat(JS_FORMAT_DEFAULT, JS_ENC_DEFAULT, -1);
14543 734 : n->pathspec = (JsonTablePathSpec *) $3;
14544 734 : n->wrapper = $4;
14545 734 : n->quotes = $5;
14546 734 : n->on_empty = (JsonBehavior *) linitial($6);
14547 734 : n->on_error = (JsonBehavior *) lsecond($6);
14548 734 : n->location = @1;
14549 734 : $$ = (Node *) n;
14550 : }
14551 : | ColId Typename json_format_clause
14552 : json_table_column_path_clause_opt
14553 : json_wrapper_behavior
14554 : json_quotes_clause_opt
14555 : json_behavior_clause_opt
14556 : {
14557 108 : JsonTableColumn *n = makeNode(JsonTableColumn);
14558 :
14559 108 : n->coltype = JTC_FORMATTED;
14560 108 : n->name = $1;
14561 108 : n->typeName = $2;
14562 108 : n->format = (JsonFormat *) $3;
14563 108 : n->pathspec = (JsonTablePathSpec *) $4;
14564 108 : n->wrapper = $5;
14565 108 : n->quotes = $6;
14566 108 : n->on_empty = (JsonBehavior *) linitial($7);
14567 108 : n->on_error = (JsonBehavior *) lsecond($7);
14568 108 : n->location = @1;
14569 108 : $$ = (Node *) n;
14570 : }
14571 : | ColId Typename
14572 : EXISTS json_table_column_path_clause_opt
14573 : json_on_error_clause_opt
14574 : {
14575 138 : JsonTableColumn *n = makeNode(JsonTableColumn);
14576 :
14577 138 : n->coltype = JTC_EXISTS;
14578 138 : n->name = $1;
14579 138 : n->typeName = $2;
14580 138 : n->format = makeJsonFormat(JS_FORMAT_DEFAULT, JS_ENC_DEFAULT, -1);
14581 138 : n->wrapper = JSW_NONE;
14582 138 : n->quotes = JS_QUOTES_UNSPEC;
14583 138 : n->pathspec = (JsonTablePathSpec *) $4;
14584 138 : n->on_empty = NULL;
14585 138 : n->on_error = (JsonBehavior *) $5;
14586 138 : n->location = @1;
14587 138 : $$ = (Node *) n;
14588 : }
14589 : | NESTED path_opt Sconst
14590 : COLUMNS '(' json_table_column_definition_list ')'
14591 : {
14592 144 : JsonTableColumn *n = makeNode(JsonTableColumn);
14593 :
14594 144 : n->coltype = JTC_NESTED;
14595 288 : n->pathspec = (JsonTablePathSpec *)
14596 144 : makeJsonTablePathSpec($3, NULL, @3, -1);
14597 144 : n->columns = $6;
14598 144 : n->location = @1;
14599 144 : $$ = (Node *) n;
14600 : }
14601 : | NESTED path_opt Sconst AS name
14602 : COLUMNS '(' json_table_column_definition_list ')'
14603 : {
14604 146 : JsonTableColumn *n = makeNode(JsonTableColumn);
14605 :
14606 146 : n->coltype = JTC_NESTED;
14607 292 : n->pathspec = (JsonTablePathSpec *)
14608 146 : makeJsonTablePathSpec($3, $5, @3, @5);
14609 146 : n->columns = $8;
14610 146 : n->location = @1;
14611 146 : $$ = (Node *) n;
14612 : }
14613 : ;
14614 :
14615 : path_opt:
14616 : PATH
14617 : | /* EMPTY */
14618 : ;
14619 :
14620 : json_table_column_path_clause_opt:
14621 : PATH Sconst
14622 828 : { $$ = (Node *) makeJsonTablePathSpec($2, NULL, @2, -1); }
14623 : | /* EMPTY */
14624 158 : { $$ = NULL; }
14625 : ;
14626 :
14627 : /*****************************************************************************
14628 : *
14629 : * Type syntax
14630 : * SQL introduces a large amount of type-specific syntax.
14631 : * Define individual clauses to handle these cases, and use
14632 : * the generic case to handle regular type-extensible Postgres syntax.
14633 : * - thomas 1997-10-10
14634 : *
14635 : *****************************************************************************/
14636 :
14637 : Typename: SimpleTypename opt_array_bounds
14638 : {
14639 530112 : $$ = $1;
14640 530112 : $$->arrayBounds = $2;
14641 : }
14642 : | SETOF SimpleTypename opt_array_bounds
14643 : {
14644 2430 : $$ = $2;
14645 2430 : $$->arrayBounds = $3;
14646 2430 : $$->setof = true;
14647 : }
14648 : /* SQL standard syntax, currently only one-dimensional */
14649 : | SimpleTypename ARRAY '[' Iconst ']'
14650 : {
14651 6 : $$ = $1;
14652 6 : $$->arrayBounds = list_make1(makeInteger($4));
14653 : }
14654 : | SETOF SimpleTypename ARRAY '[' Iconst ']'
14655 : {
14656 0 : $$ = $2;
14657 0 : $$->arrayBounds = list_make1(makeInteger($5));
14658 0 : $$->setof = true;
14659 : }
14660 : | SimpleTypename ARRAY
14661 : {
14662 0 : $$ = $1;
14663 0 : $$->arrayBounds = list_make1(makeInteger(-1));
14664 : }
14665 : | SETOF SimpleTypename ARRAY
14666 : {
14667 0 : $$ = $2;
14668 0 : $$->arrayBounds = list_make1(makeInteger(-1));
14669 0 : $$->setof = true;
14670 : }
14671 : ;
14672 :
14673 : opt_array_bounds:
14674 : opt_array_bounds '[' ']'
14675 14724 : { $$ = lappend($1, makeInteger(-1)); }
14676 : | opt_array_bounds '[' Iconst ']'
14677 62 : { $$ = lappend($1, makeInteger($3)); }
14678 : | /*EMPTY*/
14679 532542 : { $$ = NIL; }
14680 : ;
14681 :
14682 : SimpleTypename:
14683 416660 : GenericType { $$ = $1; }
14684 99766 : | Numeric { $$ = $1; }
14685 1974 : | Bit { $$ = $1; }
14686 3276 : | Character { $$ = $1; }
14687 5468 : | ConstDatetime { $$ = $1; }
14688 : | ConstInterval opt_interval
14689 : {
14690 3908 : $$ = $1;
14691 3908 : $$->typmods = $2;
14692 : }
14693 : | ConstInterval '(' Iconst ')'
14694 : {
14695 0 : $$ = $1;
14696 0 : $$->typmods = list_make2(makeIntConst(INTERVAL_FULL_RANGE, -1),
14697 : makeIntConst($3, @3));
14698 : }
14699 1904 : | JsonType { $$ = $1; }
14700 : ;
14701 :
14702 : /* We have a separate ConstTypename to allow defaulting fixed-length
14703 : * types such as CHAR() and BIT() to an unspecified length.
14704 : * SQL9x requires that these default to a length of one, but this
14705 : * makes no sense for constructs like CHAR 'hi' and BIT '0101',
14706 : * where there is an obvious better choice to make.
14707 : * Note that ConstInterval is not included here since it must
14708 : * be pushed up higher in the rules to accommodate the postfix
14709 : * options (e.g. INTERVAL '1' YEAR). Likewise, we have to handle
14710 : * the generic-type-name case in AexprConst to avoid premature
14711 : * reduce/reduce conflicts against function names.
14712 : */
14713 : ConstTypename:
14714 78 : Numeric { $$ = $1; }
14715 0 : | ConstBit { $$ = $1; }
14716 34 : | ConstCharacter { $$ = $1; }
14717 2800 : | ConstDatetime { $$ = $1; }
14718 264 : | JsonType { $$ = $1; }
14719 : ;
14720 :
14721 : /*
14722 : * GenericType covers all type names that don't have special syntax mandated
14723 : * by the standard, including qualified names. We also allow type modifiers.
14724 : * To avoid parsing conflicts against function invocations, the modifiers
14725 : * have to be shown as expr_list here, but parse analysis will only accept
14726 : * constants for them.
14727 : */
14728 : GenericType:
14729 : type_function_name opt_type_modifiers
14730 : {
14731 298902 : $$ = makeTypeName($1);
14732 298902 : $$->typmods = $2;
14733 298902 : $$->location = @1;
14734 : }
14735 : | type_function_name attrs opt_type_modifiers
14736 : {
14737 117758 : $$ = makeTypeNameFromNameList(lcons(makeString($1), $2));
14738 117758 : $$->typmods = $3;
14739 117758 : $$->location = @1;
14740 : }
14741 : ;
14742 :
14743 1350 : opt_type_modifiers: '(' expr_list ')' { $$ = $2; }
14744 421602 : | /* EMPTY */ { $$ = NIL; }
14745 : ;
14746 :
14747 : /*
14748 : * SQL numeric data types
14749 : */
14750 : Numeric: INT_P
14751 : {
14752 40146 : $$ = SystemTypeName("int4");
14753 40146 : $$->location = @1;
14754 : }
14755 : | INTEGER
14756 : {
14757 25576 : $$ = SystemTypeName("int4");
14758 25576 : $$->location = @1;
14759 : }
14760 : | SMALLINT
14761 : {
14762 1430 : $$ = SystemTypeName("int2");
14763 1430 : $$->location = @1;
14764 : }
14765 : | BIGINT
14766 : {
14767 5300 : $$ = SystemTypeName("int8");
14768 5300 : $$->location = @1;
14769 : }
14770 : | REAL
14771 : {
14772 6946 : $$ = SystemTypeName("float4");
14773 6946 : $$->location = @1;
14774 : }
14775 : | FLOAT_P opt_float
14776 : {
14777 538 : $$ = $2;
14778 538 : $$->location = @1;
14779 : }
14780 : | DOUBLE_P PRECISION
14781 : {
14782 792 : $$ = SystemTypeName("float8");
14783 792 : $$->location = @1;
14784 : }
14785 : | DECIMAL_P opt_type_modifiers
14786 : {
14787 36 : $$ = SystemTypeName("numeric");
14788 36 : $$->typmods = $2;
14789 36 : $$->location = @1;
14790 : }
14791 : | DEC opt_type_modifiers
14792 : {
14793 0 : $$ = SystemTypeName("numeric");
14794 0 : $$->typmods = $2;
14795 0 : $$->location = @1;
14796 : }
14797 : | NUMERIC opt_type_modifiers
14798 : {
14799 6256 : $$ = SystemTypeName("numeric");
14800 6256 : $$->typmods = $2;
14801 6256 : $$->location = @1;
14802 : }
14803 : | BOOLEAN_P
14804 : {
14805 12824 : $$ = SystemTypeName("bool");
14806 12824 : $$->location = @1;
14807 : }
14808 : ;
14809 :
14810 : opt_float: '(' Iconst ')'
14811 : {
14812 : /*
14813 : * Check FLOAT() precision limits assuming IEEE floating
14814 : * types - thomas 1997-09-18
14815 : */
14816 2 : if ($2 < 1)
14817 0 : ereport(ERROR,
14818 : (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
14819 : errmsg("precision for type float must be at least 1 bit"),
14820 : parser_errposition(@2)));
14821 2 : else if ($2 <= 24)
14822 2 : $$ = SystemTypeName("float4");
14823 0 : else if ($2 <= 53)
14824 0 : $$ = SystemTypeName("float8");
14825 : else
14826 0 : ereport(ERROR,
14827 : (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
14828 : errmsg("precision for type float must be less than 54 bits"),
14829 : parser_errposition(@2)));
14830 : }
14831 : | /*EMPTY*/
14832 : {
14833 536 : $$ = SystemTypeName("float8");
14834 : }
14835 : ;
14836 :
14837 : /*
14838 : * SQL bit-field data types
14839 : * The following implements BIT() and BIT VARYING().
14840 : */
14841 : Bit: BitWithLength
14842 : {
14843 1696 : $$ = $1;
14844 : }
14845 : | BitWithoutLength
14846 : {
14847 278 : $$ = $1;
14848 : }
14849 : ;
14850 :
14851 : /* ConstBit is like Bit except "BIT" defaults to unspecified length */
14852 : /* See notes for ConstCharacter, which addresses same issue for "CHAR" */
14853 : ConstBit: BitWithLength
14854 : {
14855 0 : $$ = $1;
14856 : }
14857 : | BitWithoutLength
14858 : {
14859 0 : $$ = $1;
14860 0 : $$->typmods = NIL;
14861 : }
14862 : ;
14863 :
14864 : BitWithLength:
14865 : BIT opt_varying '(' expr_list ')'
14866 : {
14867 : char *typname;
14868 :
14869 1696 : typname = $2 ? "varbit" : "bit";
14870 1696 : $$ = SystemTypeName(typname);
14871 1696 : $$->typmods = $4;
14872 1696 : $$->location = @1;
14873 : }
14874 : ;
14875 :
14876 : BitWithoutLength:
14877 : BIT opt_varying
14878 : {
14879 : /* bit defaults to bit(1), varbit to no limit */
14880 278 : if ($2)
14881 : {
14882 20 : $$ = SystemTypeName("varbit");
14883 : }
14884 : else
14885 : {
14886 258 : $$ = SystemTypeName("bit");
14887 258 : $$->typmods = list_make1(makeIntConst(1, -1));
14888 : }
14889 278 : $$->location = @1;
14890 : }
14891 : ;
14892 :
14893 :
14894 : /*
14895 : * SQL character data types
14896 : * The following implements CHAR() and VARCHAR().
14897 : */
14898 : Character: CharacterWithLength
14899 : {
14900 1984 : $$ = $1;
14901 : }
14902 : | CharacterWithoutLength
14903 : {
14904 1292 : $$ = $1;
14905 : }
14906 : ;
14907 :
14908 : ConstCharacter: CharacterWithLength
14909 : {
14910 12 : $$ = $1;
14911 : }
14912 : | CharacterWithoutLength
14913 : {
14914 : /* Length was not specified so allow to be unrestricted.
14915 : * This handles problems with fixed-length (bpchar) strings
14916 : * which in column definitions must default to a length
14917 : * of one, but should not be constrained if the length
14918 : * was not specified.
14919 : */
14920 22 : $$ = $1;
14921 22 : $$->typmods = NIL;
14922 : }
14923 : ;
14924 :
14925 : CharacterWithLength: character '(' Iconst ')'
14926 : {
14927 1996 : $$ = SystemTypeName($1);
14928 1996 : $$->typmods = list_make1(makeIntConst($3, @3));
14929 1996 : $$->location = @1;
14930 : }
14931 : ;
14932 :
14933 : CharacterWithoutLength: character
14934 : {
14935 1314 : $$ = SystemTypeName($1);
14936 : /* char defaults to char(1), varchar to no limit */
14937 1314 : if (strcmp($1, "bpchar") == 0)
14938 256 : $$->typmods = list_make1(makeIntConst(1, -1));
14939 1314 : $$->location = @1;
14940 : }
14941 : ;
14942 :
14943 : character: CHARACTER opt_varying
14944 570 : { $$ = $2 ? "varchar": "bpchar"; }
14945 : | CHAR_P opt_varying
14946 1172 : { $$ = $2 ? "varchar": "bpchar"; }
14947 : | VARCHAR
14948 1564 : { $$ = "varchar"; }
14949 : | NATIONAL CHARACTER opt_varying
14950 0 : { $$ = $3 ? "varchar": "bpchar"; }
14951 : | NATIONAL CHAR_P opt_varying
14952 0 : { $$ = $3 ? "varchar": "bpchar"; }
14953 : | NCHAR opt_varying
14954 4 : { $$ = $2 ? "varchar": "bpchar"; }
14955 : ;
14956 :
14957 : opt_varying:
14958 462 : VARYING { $$ = true; }
14959 3258 : | /*EMPTY*/ { $$ = false; }
14960 : ;
14961 :
14962 : /*
14963 : * SQL date/time types
14964 : */
14965 : ConstDatetime:
14966 : TIMESTAMP '(' Iconst ')' opt_timezone
14967 : {
14968 136 : if ($5)
14969 112 : $$ = SystemTypeName("timestamptz");
14970 : else
14971 24 : $$ = SystemTypeName("timestamp");
14972 136 : $$->typmods = list_make1(makeIntConst($3, @3));
14973 136 : $$->location = @1;
14974 : }
14975 : | TIMESTAMP opt_timezone
14976 : {
14977 5494 : if ($2)
14978 1458 : $$ = SystemTypeName("timestamptz");
14979 : else
14980 4036 : $$ = SystemTypeName("timestamp");
14981 5494 : $$->location = @1;
14982 : }
14983 : | TIME '(' Iconst ')' opt_timezone
14984 : {
14985 22 : if ($5)
14986 8 : $$ = SystemTypeName("timetz");
14987 : else
14988 14 : $$ = SystemTypeName("time");
14989 22 : $$->typmods = list_make1(makeIntConst($3, @3));
14990 22 : $$->location = @1;
14991 : }
14992 : | TIME opt_timezone
14993 : {
14994 2616 : if ($2)
14995 348 : $$ = SystemTypeName("timetz");
14996 : else
14997 2268 : $$ = SystemTypeName("time");
14998 2616 : $$->location = @1;
14999 : }
15000 : ;
15001 :
15002 : ConstInterval:
15003 : INTERVAL
15004 : {
15005 7218 : $$ = SystemTypeName("interval");
15006 7218 : $$->location = @1;
15007 : }
15008 : ;
15009 :
15010 : opt_timezone:
15011 1926 : WITH_LA TIME ZONE { $$ = true; }
15012 624 : | WITHOUT_LA TIME ZONE { $$ = false; }
15013 5718 : | /*EMPTY*/ { $$ = false; }
15014 : ;
15015 :
15016 : opt_interval:
15017 : YEAR_P
15018 12 : { $$ = list_make1(makeIntConst(INTERVAL_MASK(YEAR), @1)); }
15019 : | MONTH_P
15020 18 : { $$ = list_make1(makeIntConst(INTERVAL_MASK(MONTH), @1)); }
15021 : | DAY_P
15022 18 : { $$ = list_make1(makeIntConst(INTERVAL_MASK(DAY), @1)); }
15023 : | HOUR_P
15024 12 : { $$ = list_make1(makeIntConst(INTERVAL_MASK(HOUR), @1)); }
15025 : | MINUTE_P
15026 12 : { $$ = list_make1(makeIntConst(INTERVAL_MASK(MINUTE), @1)); }
15027 : | interval_second
15028 36 : { $$ = $1; }
15029 : | YEAR_P TO MONTH_P
15030 : {
15031 18 : $$ = list_make1(makeIntConst(INTERVAL_MASK(YEAR) |
15032 : INTERVAL_MASK(MONTH), @1));
15033 : }
15034 : | DAY_P TO HOUR_P
15035 : {
15036 24 : $$ = list_make1(makeIntConst(INTERVAL_MASK(DAY) |
15037 : INTERVAL_MASK(HOUR), @1));
15038 : }
15039 : | DAY_P TO MINUTE_P
15040 : {
15041 24 : $$ = list_make1(makeIntConst(INTERVAL_MASK(DAY) |
15042 : INTERVAL_MASK(HOUR) |
15043 : INTERVAL_MASK(MINUTE), @1));
15044 : }
15045 : | DAY_P TO interval_second
15046 : {
15047 48 : $$ = $3;
15048 48 : linitial($$) = makeIntConst(INTERVAL_MASK(DAY) |
15049 : INTERVAL_MASK(HOUR) |
15050 : INTERVAL_MASK(MINUTE) |
15051 48 : INTERVAL_MASK(SECOND), @1);
15052 : }
15053 : | HOUR_P TO MINUTE_P
15054 : {
15055 18 : $$ = list_make1(makeIntConst(INTERVAL_MASK(HOUR) |
15056 : INTERVAL_MASK(MINUTE), @1));
15057 : }
15058 : | HOUR_P TO interval_second
15059 : {
15060 36 : $$ = $3;
15061 36 : linitial($$) = makeIntConst(INTERVAL_MASK(HOUR) |
15062 : INTERVAL_MASK(MINUTE) |
15063 36 : INTERVAL_MASK(SECOND), @1);
15064 : }
15065 : | MINUTE_P TO interval_second
15066 : {
15067 66 : $$ = $3;
15068 66 : linitial($$) = makeIntConst(INTERVAL_MASK(MINUTE) |
15069 66 : INTERVAL_MASK(SECOND), @1);
15070 : }
15071 : | /*EMPTY*/
15072 6864 : { $$ = NIL; }
15073 : ;
15074 :
15075 : interval_second:
15076 : SECOND_P
15077 : {
15078 102 : $$ = list_make1(makeIntConst(INTERVAL_MASK(SECOND), @1));
15079 : }
15080 : | SECOND_P '(' Iconst ')'
15081 : {
15082 84 : $$ = list_make2(makeIntConst(INTERVAL_MASK(SECOND), @1),
15083 : makeIntConst($3, @3));
15084 : }
15085 : ;
15086 :
15087 : JsonType:
15088 : JSON
15089 : {
15090 2168 : $$ = SystemTypeName("json");
15091 2168 : $$->location = @1;
15092 : }
15093 : ;
15094 :
15095 : /*****************************************************************************
15096 : *
15097 : * expression grammar
15098 : *
15099 : *****************************************************************************/
15100 :
15101 : /*
15102 : * General expressions
15103 : * This is the heart of the expression syntax.
15104 : *
15105 : * We have two expression types: a_expr is the unrestricted kind, and
15106 : * b_expr is a subset that must be used in some places to avoid shift/reduce
15107 : * conflicts. For example, we can't do BETWEEN as "BETWEEN a_expr AND a_expr"
15108 : * because that use of AND conflicts with AND as a boolean operator. So,
15109 : * b_expr is used in BETWEEN and we remove boolean keywords from b_expr.
15110 : *
15111 : * Note that '(' a_expr ')' is a b_expr, so an unrestricted expression can
15112 : * always be used by surrounding it with parens.
15113 : *
15114 : * c_expr is all the productions that are common to a_expr and b_expr;
15115 : * it's factored out just to eliminate redundant coding.
15116 : *
15117 : * Be careful of productions involving more than one terminal token.
15118 : * By default, bison will assign such productions the precedence of their
15119 : * last terminal, but in nearly all cases you want it to be the precedence
15120 : * of the first terminal instead; otherwise you will not get the behavior
15121 : * you expect! So we use %prec annotations freely to set precedences.
15122 : */
15123 3756288 : a_expr: c_expr { $$ = $1; }
15124 : | a_expr TYPECAST Typename
15125 238656 : { $$ = makeTypeCast($1, $3, @2); }
15126 : | a_expr COLLATE any_name
15127 : {
15128 9490 : CollateClause *n = makeNode(CollateClause);
15129 :
15130 9490 : n->arg = $1;
15131 9490 : n->collname = $3;
15132 9490 : n->location = @2;
15133 9490 : $$ = (Node *) n;
15134 : }
15135 : | a_expr AT TIME ZONE a_expr %prec AT
15136 : {
15137 408 : $$ = (Node *) makeFuncCall(SystemFuncName("timezone"),
15138 408 : list_make2($5, $1),
15139 : COERCE_SQL_SYNTAX,
15140 408 : @2);
15141 : }
15142 : | a_expr AT LOCAL %prec AT
15143 : {
15144 42 : $$ = (Node *) makeFuncCall(SystemFuncName("timezone"),
15145 42 : list_make1($1),
15146 : COERCE_SQL_SYNTAX,
15147 : -1);
15148 : }
15149 : /*
15150 : * These operators must be called out explicitly in order to make use
15151 : * of bison's automatic operator-precedence handling. All other
15152 : * operator names are handled by the generic productions using "Op",
15153 : * below; and all those operators will have the same precedence.
15154 : *
15155 : * If you add more explicitly-known operators, be sure to add them
15156 : * also to b_expr and to the MathOp list below.
15157 : */
15158 : | '+' a_expr %prec UMINUS
15159 12 : { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "+", NULL, $2, @1); }
15160 : | '-' a_expr %prec UMINUS
15161 9332 : { $$ = doNegate($2, @1); }
15162 : | a_expr '+' a_expr
15163 14994 : { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "+", $1, $3, @2); }
15164 : | a_expr '-' a_expr
15165 4544 : { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "-", $1, $3, @2); }
15166 : | a_expr '*' a_expr
15167 6446 : { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "*", $1, $3, @2); }
15168 : | a_expr '/' a_expr
15169 3482 : { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "/", $1, $3, @2); }
15170 : | a_expr '%' a_expr
15171 3414 : { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "%", $1, $3, @2); }
15172 : | a_expr '^' a_expr
15173 478 : { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "^", $1, $3, @2); }
15174 : | a_expr '<' a_expr
15175 10674 : { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "<", $1, $3, @2); }
15176 : | a_expr '>' a_expr
15177 17012 : { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, ">", $1, $3, @2); }
15178 : | a_expr '=' a_expr
15179 396184 : { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "=", $1, $3, @2); }
15180 : | a_expr LESS_EQUALS a_expr
15181 5552 : { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "<=", $1, $3, @2); }
15182 : | a_expr GREATER_EQUALS a_expr
15183 12726 : { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, ">=", $1, $3, @2); }
15184 : | a_expr NOT_EQUALS a_expr
15185 39964 : { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "<>", $1, $3, @2); }
15186 :
15187 : | a_expr qual_Op a_expr %prec Op
15188 60132 : { $$ = (Node *) makeA_Expr(AEXPR_OP, $2, $1, $3, @2); }
15189 : | qual_Op a_expr %prec Op
15190 246 : { $$ = (Node *) makeA_Expr(AEXPR_OP, $1, NULL, $2, @1); }
15191 :
15192 : | a_expr AND a_expr
15193 236004 : { $$ = makeAndExpr($1, $3, @2); }
15194 : | a_expr OR a_expr
15195 16292 : { $$ = makeOrExpr($1, $3, @2); }
15196 : | NOT a_expr
15197 16382 : { $$ = makeNotExpr($2, @1); }
15198 : | NOT_LA a_expr %prec NOT
15199 0 : { $$ = makeNotExpr($2, @1); }
15200 :
15201 : | a_expr LIKE a_expr
15202 : {
15203 1968 : $$ = (Node *) makeSimpleA_Expr(AEXPR_LIKE, "~~",
15204 1968 : $1, $3, @2);
15205 : }
15206 : | a_expr LIKE a_expr ESCAPE a_expr %prec LIKE
15207 : {
15208 96 : FuncCall *n = makeFuncCall(SystemFuncName("like_escape"),
15209 96 : list_make2($3, $5),
15210 : COERCE_EXPLICIT_CALL,
15211 96 : @2);
15212 96 : $$ = (Node *) makeSimpleA_Expr(AEXPR_LIKE, "~~",
15213 96 : $1, (Node *) n, @2);
15214 : }
15215 : | a_expr NOT_LA LIKE a_expr %prec NOT_LA
15216 : {
15217 198 : $$ = (Node *) makeSimpleA_Expr(AEXPR_LIKE, "!~~",
15218 198 : $1, $4, @2);
15219 : }
15220 : | a_expr NOT_LA LIKE a_expr ESCAPE a_expr %prec NOT_LA
15221 : {
15222 96 : FuncCall *n = makeFuncCall(SystemFuncName("like_escape"),
15223 96 : list_make2($4, $6),
15224 : COERCE_EXPLICIT_CALL,
15225 96 : @2);
15226 96 : $$ = (Node *) makeSimpleA_Expr(AEXPR_LIKE, "!~~",
15227 96 : $1, (Node *) n, @2);
15228 : }
15229 : | a_expr ILIKE a_expr
15230 : {
15231 172 : $$ = (Node *) makeSimpleA_Expr(AEXPR_ILIKE, "~~*",
15232 172 : $1, $3, @2);
15233 : }
15234 : | a_expr ILIKE a_expr ESCAPE a_expr %prec ILIKE
15235 : {
15236 0 : FuncCall *n = makeFuncCall(SystemFuncName("like_escape"),
15237 0 : list_make2($3, $5),
15238 : COERCE_EXPLICIT_CALL,
15239 0 : @2);
15240 0 : $$ = (Node *) makeSimpleA_Expr(AEXPR_ILIKE, "~~*",
15241 0 : $1, (Node *) n, @2);
15242 : }
15243 : | a_expr NOT_LA ILIKE a_expr %prec NOT_LA
15244 : {
15245 30 : $$ = (Node *) makeSimpleA_Expr(AEXPR_ILIKE, "!~~*",
15246 30 : $1, $4, @2);
15247 : }
15248 : | a_expr NOT_LA ILIKE a_expr ESCAPE a_expr %prec NOT_LA
15249 : {
15250 0 : FuncCall *n = makeFuncCall(SystemFuncName("like_escape"),
15251 0 : list_make2($4, $6),
15252 : COERCE_EXPLICIT_CALL,
15253 0 : @2);
15254 0 : $$ = (Node *) makeSimpleA_Expr(AEXPR_ILIKE, "!~~*",
15255 0 : $1, (Node *) n, @2);
15256 : }
15257 :
15258 : | a_expr SIMILAR TO a_expr %prec SIMILAR
15259 : {
15260 88 : FuncCall *n = makeFuncCall(SystemFuncName("similar_to_escape"),
15261 88 : list_make1($4),
15262 : COERCE_EXPLICIT_CALL,
15263 88 : @2);
15264 88 : $$ = (Node *) makeSimpleA_Expr(AEXPR_SIMILAR, "~",
15265 88 : $1, (Node *) n, @2);
15266 : }
15267 : | a_expr SIMILAR TO a_expr ESCAPE a_expr %prec SIMILAR
15268 : {
15269 36 : FuncCall *n = makeFuncCall(SystemFuncName("similar_to_escape"),
15270 36 : list_make2($4, $6),
15271 : COERCE_EXPLICIT_CALL,
15272 36 : @2);
15273 36 : $$ = (Node *) makeSimpleA_Expr(AEXPR_SIMILAR, "~",
15274 36 : $1, (Node *) n, @2);
15275 : }
15276 : | a_expr NOT_LA SIMILAR TO a_expr %prec NOT_LA
15277 : {
15278 0 : FuncCall *n = makeFuncCall(SystemFuncName("similar_to_escape"),
15279 0 : list_make1($5),
15280 : COERCE_EXPLICIT_CALL,
15281 0 : @2);
15282 0 : $$ = (Node *) makeSimpleA_Expr(AEXPR_SIMILAR, "!~",
15283 0 : $1, (Node *) n, @2);
15284 : }
15285 : | a_expr NOT_LA SIMILAR TO a_expr ESCAPE a_expr %prec NOT_LA
15286 : {
15287 0 : FuncCall *n = makeFuncCall(SystemFuncName("similar_to_escape"),
15288 0 : list_make2($5, $7),
15289 : COERCE_EXPLICIT_CALL,
15290 0 : @2);
15291 0 : $$ = (Node *) makeSimpleA_Expr(AEXPR_SIMILAR, "!~",
15292 0 : $1, (Node *) n, @2);
15293 : }
15294 :
15295 : /* NullTest clause
15296 : * Define SQL-style Null test clause.
15297 : * Allow two forms described in the standard:
15298 : * a IS NULL
15299 : * a IS NOT NULL
15300 : * Allow two SQL extensions
15301 : * a ISNULL
15302 : * a NOTNULL
15303 : */
15304 : | a_expr IS NULL_P %prec IS
15305 : {
15306 5380 : NullTest *n = makeNode(NullTest);
15307 :
15308 5380 : n->arg = (Expr *) $1;
15309 5380 : n->nulltesttype = IS_NULL;
15310 5380 : n->location = @2;
15311 5380 : $$ = (Node *) n;
15312 : }
15313 : | a_expr ISNULL
15314 : {
15315 96 : NullTest *n = makeNode(NullTest);
15316 :
15317 96 : n->arg = (Expr *) $1;
15318 96 : n->nulltesttype = IS_NULL;
15319 96 : n->location = @2;
15320 96 : $$ = (Node *) n;
15321 : }
15322 : | a_expr IS NOT NULL_P %prec IS
15323 : {
15324 13232 : NullTest *n = makeNode(NullTest);
15325 :
15326 13232 : n->arg = (Expr *) $1;
15327 13232 : n->nulltesttype = IS_NOT_NULL;
15328 13232 : n->location = @2;
15329 13232 : $$ = (Node *) n;
15330 : }
15331 : | a_expr NOTNULL
15332 : {
15333 6 : NullTest *n = makeNode(NullTest);
15334 :
15335 6 : n->arg = (Expr *) $1;
15336 6 : n->nulltesttype = IS_NOT_NULL;
15337 6 : n->location = @2;
15338 6 : $$ = (Node *) n;
15339 : }
15340 : | row OVERLAPS row
15341 : {
15342 984 : if (list_length($1) != 2)
15343 0 : ereport(ERROR,
15344 : (errcode(ERRCODE_SYNTAX_ERROR),
15345 : errmsg("wrong number of parameters on left side of OVERLAPS expression"),
15346 : parser_errposition(@1)));
15347 984 : if (list_length($3) != 2)
15348 0 : ereport(ERROR,
15349 : (errcode(ERRCODE_SYNTAX_ERROR),
15350 : errmsg("wrong number of parameters on right side of OVERLAPS expression"),
15351 : parser_errposition(@3)));
15352 984 : $$ = (Node *) makeFuncCall(SystemFuncName("overlaps"),
15353 984 : list_concat($1, $3),
15354 : COERCE_SQL_SYNTAX,
15355 984 : @2);
15356 : }
15357 : | a_expr IS TRUE_P %prec IS
15358 : {
15359 456 : BooleanTest *b = makeNode(BooleanTest);
15360 :
15361 456 : b->arg = (Expr *) $1;
15362 456 : b->booltesttype = IS_TRUE;
15363 456 : b->location = @2;
15364 456 : $$ = (Node *) b;
15365 : }
15366 : | a_expr IS NOT TRUE_P %prec IS
15367 : {
15368 140 : BooleanTest *b = makeNode(BooleanTest);
15369 :
15370 140 : b->arg = (Expr *) $1;
15371 140 : b->booltesttype = IS_NOT_TRUE;
15372 140 : b->location = @2;
15373 140 : $$ = (Node *) b;
15374 : }
15375 : | a_expr IS FALSE_P %prec IS
15376 : {
15377 158 : BooleanTest *b = makeNode(BooleanTest);
15378 :
15379 158 : b->arg = (Expr *) $1;
15380 158 : b->booltesttype = IS_FALSE;
15381 158 : b->location = @2;
15382 158 : $$ = (Node *) b;
15383 : }
15384 : | a_expr IS NOT FALSE_P %prec IS
15385 : {
15386 92 : BooleanTest *b = makeNode(BooleanTest);
15387 :
15388 92 : b->arg = (Expr *) $1;
15389 92 : b->booltesttype = IS_NOT_FALSE;
15390 92 : b->location = @2;
15391 92 : $$ = (Node *) b;
15392 : }
15393 : | a_expr IS UNKNOWN %prec IS
15394 : {
15395 52 : BooleanTest *b = makeNode(BooleanTest);
15396 :
15397 52 : b->arg = (Expr *) $1;
15398 52 : b->booltesttype = IS_UNKNOWN;
15399 52 : b->location = @2;
15400 52 : $$ = (Node *) b;
15401 : }
15402 : | a_expr IS NOT UNKNOWN %prec IS
15403 : {
15404 48 : BooleanTest *b = makeNode(BooleanTest);
15405 :
15406 48 : b->arg = (Expr *) $1;
15407 48 : b->booltesttype = IS_NOT_UNKNOWN;
15408 48 : b->location = @2;
15409 48 : $$ = (Node *) b;
15410 : }
15411 : | a_expr IS DISTINCT FROM a_expr %prec IS
15412 : {
15413 1098 : $$ = (Node *) makeSimpleA_Expr(AEXPR_DISTINCT, "=", $1, $5, @2);
15414 : }
15415 : | a_expr IS NOT DISTINCT FROM a_expr %prec IS
15416 : {
15417 68 : $$ = (Node *) makeSimpleA_Expr(AEXPR_NOT_DISTINCT, "=", $1, $6, @2);
15418 : }
15419 : | a_expr BETWEEN opt_asymmetric b_expr AND a_expr %prec BETWEEN
15420 : {
15421 470 : $$ = (Node *) makeSimpleA_Expr(AEXPR_BETWEEN,
15422 : "BETWEEN",
15423 470 : $1,
15424 470 : (Node *) list_make2($4, $6),
15425 470 : @2);
15426 : }
15427 : | a_expr NOT_LA BETWEEN opt_asymmetric b_expr AND a_expr %prec NOT_LA
15428 : {
15429 12 : $$ = (Node *) makeSimpleA_Expr(AEXPR_NOT_BETWEEN,
15430 : "NOT BETWEEN",
15431 12 : $1,
15432 12 : (Node *) list_make2($5, $7),
15433 12 : @2);
15434 : }
15435 : | a_expr BETWEEN SYMMETRIC b_expr AND a_expr %prec BETWEEN
15436 : {
15437 12 : $$ = (Node *) makeSimpleA_Expr(AEXPR_BETWEEN_SYM,
15438 : "BETWEEN SYMMETRIC",
15439 12 : $1,
15440 12 : (Node *) list_make2($4, $6),
15441 12 : @2);
15442 : }
15443 : | a_expr NOT_LA BETWEEN SYMMETRIC b_expr AND a_expr %prec NOT_LA
15444 : {
15445 12 : $$ = (Node *) makeSimpleA_Expr(AEXPR_NOT_BETWEEN_SYM,
15446 : "NOT BETWEEN SYMMETRIC",
15447 12 : $1,
15448 12 : (Node *) list_make2($5, $7),
15449 12 : @2);
15450 : }
15451 : | a_expr IN_P select_with_parens
15452 : {
15453 : /* generate foo = ANY (subquery) */
15454 5726 : SubLink *n = makeNode(SubLink);
15455 :
15456 5726 : n->subselect = $3;
15457 5726 : n->subLinkType = ANY_SUBLINK;
15458 5726 : n->subLinkId = 0;
15459 5726 : n->testexpr = $1;
15460 5726 : n->operName = NIL; /* show it's IN not = ANY */
15461 5726 : n->location = @2;
15462 5726 : $$ = (Node *) n;
15463 : }
15464 : | a_expr IN_P '(' expr_list ')'
15465 : {
15466 : /* generate scalar IN expression */
15467 19656 : A_Expr *n = makeSimpleA_Expr(AEXPR_IN, "=", $1, (Node *) $4, @2);
15468 :
15469 19656 : n->rexpr_list_start = @3;
15470 19656 : n->rexpr_list_end = @5;
15471 19656 : $$ = (Node *) n;
15472 : }
15473 : | a_expr NOT_LA IN_P select_with_parens %prec NOT_LA
15474 : {
15475 : /* generate NOT (foo = ANY (subquery)) */
15476 120 : SubLink *n = makeNode(SubLink);
15477 :
15478 120 : n->subselect = $4;
15479 120 : n->subLinkType = ANY_SUBLINK;
15480 120 : n->subLinkId = 0;
15481 120 : n->testexpr = $1;
15482 120 : n->operName = NIL; /* show it's IN not = ANY */
15483 120 : n->location = @2;
15484 : /* Stick a NOT on top; must have same parse location */
15485 120 : $$ = makeNotExpr((Node *) n, @2);
15486 : }
15487 : | a_expr NOT_LA IN_P '(' expr_list ')'
15488 : {
15489 : /* generate scalar NOT IN expression */
15490 2754 : A_Expr *n = makeSimpleA_Expr(AEXPR_IN, "<>", $1, (Node *) $5, @2);
15491 :
15492 2754 : n->rexpr_list_start = @4;
15493 2754 : n->rexpr_list_end = @6;
15494 2754 : $$ = (Node *) n;
15495 : }
15496 : | a_expr subquery_Op sub_type select_with_parens %prec Op
15497 : {
15498 180 : SubLink *n = makeNode(SubLink);
15499 :
15500 180 : n->subLinkType = $3;
15501 180 : n->subLinkId = 0;
15502 180 : n->testexpr = $1;
15503 180 : n->operName = $2;
15504 180 : n->subselect = $4;
15505 180 : n->location = @2;
15506 180 : $$ = (Node *) n;
15507 : }
15508 : | a_expr subquery_Op sub_type '(' a_expr ')' %prec Op
15509 : {
15510 17192 : if ($3 == ANY_SUBLINK)
15511 16892 : $$ = (Node *) makeA_Expr(AEXPR_OP_ANY, $2, $1, $5, @2);
15512 : else
15513 300 : $$ = (Node *) makeA_Expr(AEXPR_OP_ALL, $2, $1, $5, @2);
15514 : }
15515 : | UNIQUE opt_unique_null_treatment select_with_parens
15516 : {
15517 : /* Not sure how to get rid of the parentheses
15518 : * but there are lots of shift/reduce errors without them.
15519 : *
15520 : * Should be able to implement this by plopping the entire
15521 : * select into a node, then transforming the target expressions
15522 : * from whatever they are into count(*), and testing the
15523 : * entire result equal to one.
15524 : * But, will probably implement a separate node in the executor.
15525 : */
15526 0 : ereport(ERROR,
15527 : (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
15528 : errmsg("UNIQUE predicate is not yet implemented"),
15529 : parser_errposition(@1)));
15530 : }
15531 : | a_expr IS DOCUMENT_P %prec IS
15532 : {
15533 18 : $$ = makeXmlExpr(IS_DOCUMENT, NULL, NIL,
15534 18 : list_make1($1), @2);
15535 : }
15536 : | a_expr IS NOT DOCUMENT_P %prec IS
15537 : {
15538 18 : $$ = makeNotExpr(makeXmlExpr(IS_DOCUMENT, NULL, NIL,
15539 18 : list_make1($1), @2),
15540 18 : @2);
15541 : }
15542 : | a_expr IS NORMALIZED %prec IS
15543 : {
15544 12 : $$ = (Node *) makeFuncCall(SystemFuncName("is_normalized"),
15545 12 : list_make1($1),
15546 : COERCE_SQL_SYNTAX,
15547 12 : @2);
15548 : }
15549 : | a_expr IS unicode_normal_form NORMALIZED %prec IS
15550 : {
15551 36 : $$ = (Node *) makeFuncCall(SystemFuncName("is_normalized"),
15552 36 : list_make2($1, makeStringConst($3, @3)),
15553 : COERCE_SQL_SYNTAX,
15554 36 : @2);
15555 : }
15556 : | a_expr IS NOT NORMALIZED %prec IS
15557 : {
15558 0 : $$ = makeNotExpr((Node *) makeFuncCall(SystemFuncName("is_normalized"),
15559 0 : list_make1($1),
15560 : COERCE_SQL_SYNTAX,
15561 0 : @2),
15562 0 : @2);
15563 : }
15564 : | a_expr IS NOT unicode_normal_form NORMALIZED %prec IS
15565 : {
15566 0 : $$ = makeNotExpr((Node *) makeFuncCall(SystemFuncName("is_normalized"),
15567 0 : list_make2($1, makeStringConst($4, @4)),
15568 : COERCE_SQL_SYNTAX,
15569 0 : @2),
15570 0 : @2);
15571 : }
15572 : | a_expr IS json_predicate_type_constraint
15573 : json_key_uniqueness_constraint_opt %prec IS
15574 : {
15575 304 : JsonFormat *format = makeJsonFormat(JS_FORMAT_DEFAULT, JS_ENC_DEFAULT, -1);
15576 :
15577 304 : $$ = makeJsonIsPredicate($1, format, $3, $4, @1);
15578 : }
15579 : /*
15580 : * Required by SQL/JSON, but there are conflicts
15581 : | a_expr
15582 : json_format_clause
15583 : IS json_predicate_type_constraint
15584 : json_key_uniqueness_constraint_opt %prec IS
15585 : {
15586 : $$ = makeJsonIsPredicate($1, $2, $4, $5, @1);
15587 : }
15588 : */
15589 : | a_expr IS NOT
15590 : json_predicate_type_constraint
15591 : json_key_uniqueness_constraint_opt %prec IS
15592 : {
15593 46 : JsonFormat *format = makeJsonFormat(JS_FORMAT_DEFAULT, JS_ENC_DEFAULT, -1);
15594 :
15595 46 : $$ = makeNotExpr(makeJsonIsPredicate($1, format, $4, $5, @1), @1);
15596 : }
15597 : /*
15598 : * Required by SQL/JSON, but there are conflicts
15599 : | a_expr
15600 : json_format_clause
15601 : IS NOT
15602 : json_predicate_type_constraint
15603 : json_key_uniqueness_constraint_opt %prec IS
15604 : {
15605 : $$ = makeNotExpr(makeJsonIsPredicate($1, $2, $5, $6, @1), @1);
15606 : }
15607 : */
15608 : | DEFAULT
15609 : {
15610 : /*
15611 : * The SQL spec only allows DEFAULT in "contextually typed
15612 : * expressions", but for us, it's easier to allow it in
15613 : * any a_expr and then throw error during parse analysis
15614 : * if it's in an inappropriate context. This way also
15615 : * lets us say something smarter than "syntax error".
15616 : */
15617 1566 : SetToDefault *n = makeNode(SetToDefault);
15618 :
15619 : /* parse analysis will fill in the rest */
15620 1566 : n->location = @1;
15621 1566 : $$ = (Node *) n;
15622 : }
15623 : ;
15624 :
15625 : /*
15626 : * Restricted expressions
15627 : *
15628 : * b_expr is a subset of the complete expression syntax defined by a_expr.
15629 : *
15630 : * Presently, AND, NOT, IS, and IN are the a_expr keywords that would
15631 : * cause trouble in the places where b_expr is used. For simplicity, we
15632 : * just eliminate all the boolean-keyword-operator productions from b_expr.
15633 : */
15634 : b_expr: c_expr
15635 3866 : { $$ = $1; }
15636 : | b_expr TYPECAST Typename
15637 212 : { $$ = makeTypeCast($1, $3, @2); }
15638 : | '+' b_expr %prec UMINUS
15639 0 : { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "+", NULL, $2, @1); }
15640 : | '-' b_expr %prec UMINUS
15641 66 : { $$ = doNegate($2, @1); }
15642 : | b_expr '+' b_expr
15643 36 : { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "+", $1, $3, @2); }
15644 : | b_expr '-' b_expr
15645 12 : { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "-", $1, $3, @2); }
15646 : | b_expr '*' b_expr
15647 12 : { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "*", $1, $3, @2); }
15648 : | b_expr '/' b_expr
15649 0 : { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "/", $1, $3, @2); }
15650 : | b_expr '%' b_expr
15651 0 : { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "%", $1, $3, @2); }
15652 : | b_expr '^' b_expr
15653 6 : { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "^", $1, $3, @2); }
15654 : | b_expr '<' b_expr
15655 0 : { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "<", $1, $3, @2); }
15656 : | b_expr '>' b_expr
15657 0 : { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, ">", $1, $3, @2); }
15658 : | b_expr '=' b_expr
15659 0 : { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "=", $1, $3, @2); }
15660 : | b_expr LESS_EQUALS b_expr
15661 0 : { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "<=", $1, $3, @2); }
15662 : | b_expr GREATER_EQUALS b_expr
15663 0 : { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, ">=", $1, $3, @2); }
15664 : | b_expr NOT_EQUALS b_expr
15665 0 : { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "<>", $1, $3, @2); }
15666 : | b_expr qual_Op b_expr %prec Op
15667 12 : { $$ = (Node *) makeA_Expr(AEXPR_OP, $2, $1, $3, @2); }
15668 : | qual_Op b_expr %prec Op
15669 0 : { $$ = (Node *) makeA_Expr(AEXPR_OP, $1, NULL, $2, @1); }
15670 : | b_expr IS DISTINCT FROM b_expr %prec IS
15671 : {
15672 0 : $$ = (Node *) makeSimpleA_Expr(AEXPR_DISTINCT, "=", $1, $5, @2);
15673 : }
15674 : | b_expr IS NOT DISTINCT FROM b_expr %prec IS
15675 : {
15676 0 : $$ = (Node *) makeSimpleA_Expr(AEXPR_NOT_DISTINCT, "=", $1, $6, @2);
15677 : }
15678 : | b_expr IS DOCUMENT_P %prec IS
15679 : {
15680 0 : $$ = makeXmlExpr(IS_DOCUMENT, NULL, NIL,
15681 0 : list_make1($1), @2);
15682 : }
15683 : | b_expr IS NOT DOCUMENT_P %prec IS
15684 : {
15685 0 : $$ = makeNotExpr(makeXmlExpr(IS_DOCUMENT, NULL, NIL,
15686 0 : list_make1($1), @2),
15687 0 : @2);
15688 : }
15689 : ;
15690 :
15691 : /*
15692 : * Productions that can be used in both a_expr and b_expr.
15693 : *
15694 : * Note: productions that refer recursively to a_expr or b_expr mostly
15695 : * cannot appear here. However, it's OK to refer to a_exprs that occur
15696 : * inside parentheses, such as function arguments; that cannot introduce
15697 : * ambiguity to the b_expr syntax.
15698 : */
15699 1843280 : c_expr: columnref { $$ = $1; }
15700 1276870 : | AexprConst { $$ = $1; }
15701 : | PARAM opt_indirection
15702 : {
15703 46762 : ParamRef *p = makeNode(ParamRef);
15704 :
15705 46762 : p->number = $1;
15706 46762 : p->location = @1;
15707 46762 : if ($2)
15708 : {
15709 1096 : A_Indirection *n = makeNode(A_Indirection);
15710 :
15711 1096 : n->arg = (Node *) p;
15712 1096 : n->indirection = check_indirection($2, yyscanner);
15713 1096 : $$ = (Node *) n;
15714 : }
15715 : else
15716 45666 : $$ = (Node *) p;
15717 : }
15718 : | '(' a_expr ')' opt_indirection
15719 : {
15720 91462 : if ($4)
15721 : {
15722 12596 : A_Indirection *n = makeNode(A_Indirection);
15723 :
15724 12596 : n->arg = $2;
15725 12596 : n->indirection = check_indirection($4, yyscanner);
15726 12596 : $$ = (Node *) n;
15727 : }
15728 : else
15729 78866 : $$ = $2;
15730 : }
15731 : | case_expr
15732 40216 : { $$ = $1; }
15733 : | func_expr
15734 405014 : { $$ = $1; }
15735 : | select_with_parens %prec UMINUS
15736 : {
15737 27904 : SubLink *n = makeNode(SubLink);
15738 :
15739 27904 : n->subLinkType = EXPR_SUBLINK;
15740 27904 : n->subLinkId = 0;
15741 27904 : n->testexpr = NULL;
15742 27904 : n->operName = NIL;
15743 27904 : n->subselect = $1;
15744 27904 : n->location = @1;
15745 27904 : $$ = (Node *) n;
15746 : }
15747 : | select_with_parens indirection
15748 : {
15749 : /*
15750 : * Because the select_with_parens nonterminal is designed
15751 : * to "eat" as many levels of parens as possible, the
15752 : * '(' a_expr ')' opt_indirection production above will
15753 : * fail to match a sub-SELECT with indirection decoration;
15754 : * the sub-SELECT won't be regarded as an a_expr as long
15755 : * as there are parens around it. To support applying
15756 : * subscripting or field selection to a sub-SELECT result,
15757 : * we need this redundant-looking production.
15758 : */
15759 18 : SubLink *n = makeNode(SubLink);
15760 18 : A_Indirection *a = makeNode(A_Indirection);
15761 :
15762 18 : n->subLinkType = EXPR_SUBLINK;
15763 18 : n->subLinkId = 0;
15764 18 : n->testexpr = NULL;
15765 18 : n->operName = NIL;
15766 18 : n->subselect = $1;
15767 18 : n->location = @1;
15768 18 : a->arg = (Node *) n;
15769 18 : a->indirection = check_indirection($2, yyscanner);
15770 18 : $$ = (Node *) a;
15771 : }
15772 : | EXISTS select_with_parens
15773 : {
15774 6254 : SubLink *n = makeNode(SubLink);
15775 :
15776 6254 : n->subLinkType = EXISTS_SUBLINK;
15777 6254 : n->subLinkId = 0;
15778 6254 : n->testexpr = NULL;
15779 6254 : n->operName = NIL;
15780 6254 : n->subselect = $2;
15781 6254 : n->location = @1;
15782 6254 : $$ = (Node *) n;
15783 : }
15784 : | ARRAY select_with_parens
15785 : {
15786 8602 : SubLink *n = makeNode(SubLink);
15787 :
15788 8602 : n->subLinkType = ARRAY_SUBLINK;
15789 8602 : n->subLinkId = 0;
15790 8602 : n->testexpr = NULL;
15791 8602 : n->operName = NIL;
15792 8602 : n->subselect = $2;
15793 8602 : n->location = @1;
15794 8602 : $$ = (Node *) n;
15795 : }
15796 : | ARRAY array_expr
15797 : {
15798 7512 : A_ArrayExpr *n = castNode(A_ArrayExpr, $2);
15799 :
15800 : /* point outermost A_ArrayExpr to the ARRAY keyword */
15801 7512 : n->location = @1;
15802 7512 : $$ = (Node *) n;
15803 : }
15804 : | explicit_row
15805 : {
15806 3856 : RowExpr *r = makeNode(RowExpr);
15807 :
15808 3856 : r->args = $1;
15809 3856 : r->row_typeid = InvalidOid; /* not analyzed yet */
15810 3856 : r->colnames = NIL; /* to be filled in during analysis */
15811 3856 : r->row_format = COERCE_EXPLICIT_CALL; /* abuse */
15812 3856 : r->location = @1;
15813 3856 : $$ = (Node *) r;
15814 : }
15815 : | implicit_row
15816 : {
15817 2728 : RowExpr *r = makeNode(RowExpr);
15818 :
15819 2728 : r->args = $1;
15820 2728 : r->row_typeid = InvalidOid; /* not analyzed yet */
15821 2728 : r->colnames = NIL; /* to be filled in during analysis */
15822 2728 : r->row_format = COERCE_IMPLICIT_CAST; /* abuse */
15823 2728 : r->location = @1;
15824 2728 : $$ = (Node *) r;
15825 : }
15826 : | GROUPING '(' expr_list ')'
15827 : {
15828 362 : GroupingFunc *g = makeNode(GroupingFunc);
15829 :
15830 362 : g->args = $3;
15831 362 : g->location = @1;
15832 362 : $$ = (Node *) g;
15833 : }
15834 : ;
15835 :
15836 : func_application: func_name '(' ')'
15837 : {
15838 33492 : $$ = (Node *) makeFuncCall($1, NIL,
15839 : COERCE_EXPLICIT_CALL,
15840 33492 : @1);
15841 : }
15842 : | func_name '(' func_arg_list opt_sort_clause ')'
15843 : {
15844 323002 : FuncCall *n = makeFuncCall($1, $3,
15845 : COERCE_EXPLICIT_CALL,
15846 323002 : @1);
15847 :
15848 323002 : n->agg_order = $4;
15849 323002 : $$ = (Node *) n;
15850 : }
15851 : | func_name '(' VARIADIC func_arg_expr opt_sort_clause ')'
15852 : {
15853 634 : FuncCall *n = makeFuncCall($1, list_make1($4),
15854 : COERCE_EXPLICIT_CALL,
15855 634 : @1);
15856 :
15857 634 : n->func_variadic = true;
15858 634 : n->agg_order = $5;
15859 634 : $$ = (Node *) n;
15860 : }
15861 : | func_name '(' func_arg_list ',' VARIADIC func_arg_expr opt_sort_clause ')'
15862 : {
15863 168 : FuncCall *n = makeFuncCall($1, lappend($3, $6),
15864 : COERCE_EXPLICIT_CALL,
15865 168 : @1);
15866 :
15867 168 : n->func_variadic = true;
15868 168 : n->agg_order = $7;
15869 168 : $$ = (Node *) n;
15870 : }
15871 : | func_name '(' ALL func_arg_list opt_sort_clause ')'
15872 : {
15873 0 : FuncCall *n = makeFuncCall($1, $4,
15874 : COERCE_EXPLICIT_CALL,
15875 0 : @1);
15876 :
15877 0 : n->agg_order = $5;
15878 : /* Ideally we'd mark the FuncCall node to indicate
15879 : * "must be an aggregate", but there's no provision
15880 : * for that in FuncCall at the moment.
15881 : */
15882 0 : $$ = (Node *) n;
15883 : }
15884 : | func_name '(' DISTINCT func_arg_list opt_sort_clause ')'
15885 : {
15886 556 : FuncCall *n = makeFuncCall($1, $4,
15887 : COERCE_EXPLICIT_CALL,
15888 556 : @1);
15889 :
15890 556 : n->agg_order = $5;
15891 556 : n->agg_distinct = true;
15892 556 : $$ = (Node *) n;
15893 : }
15894 : | func_name '(' '*' ')'
15895 : {
15896 : /*
15897 : * We consider AGGREGATE(*) to invoke a parameterless
15898 : * aggregate. This does the right thing for COUNT(*),
15899 : * and there are no other aggregates in SQL that accept
15900 : * '*' as parameter.
15901 : *
15902 : * The FuncCall node is also marked agg_star = true,
15903 : * so that later processing can detect what the argument
15904 : * really was.
15905 : */
15906 18948 : FuncCall *n = makeFuncCall($1, NIL,
15907 : COERCE_EXPLICIT_CALL,
15908 18948 : @1);
15909 :
15910 18948 : n->agg_star = true;
15911 18948 : $$ = (Node *) n;
15912 : }
15913 : ;
15914 :
15915 :
15916 : /*
15917 : * func_expr and its cousin func_expr_windowless are split out from c_expr just
15918 : * so that we have classifications for "everything that is a function call or
15919 : * looks like one". This isn't very important, but it saves us having to
15920 : * document which variants are legal in places like "FROM function()" or the
15921 : * backwards-compatible functional-index syntax for CREATE INDEX.
15922 : * (Note that many of the special SQL functions wouldn't actually make any
15923 : * sense as functional index entries, but we ignore that consideration here.)
15924 : */
15925 : func_expr: func_application within_group_clause filter_clause null_treatment over_clause
15926 : {
15927 326818 : FuncCall *n = (FuncCall *) $1;
15928 :
15929 : /*
15930 : * The order clause for WITHIN GROUP and the one for
15931 : * plain-aggregate ORDER BY share a field, so we have to
15932 : * check here that at most one is present. We also check
15933 : * for DISTINCT and VARIADIC here to give a better error
15934 : * location. Other consistency checks are deferred to
15935 : * parse analysis.
15936 : */
15937 326818 : if ($2 != NIL)
15938 : {
15939 348 : if (n->agg_order != NIL)
15940 6 : ereport(ERROR,
15941 : (errcode(ERRCODE_SYNTAX_ERROR),
15942 : errmsg("cannot use multiple ORDER BY clauses with WITHIN GROUP"),
15943 : parser_errposition(@2)));
15944 342 : if (n->agg_distinct)
15945 0 : ereport(ERROR,
15946 : (errcode(ERRCODE_SYNTAX_ERROR),
15947 : errmsg("cannot use DISTINCT with WITHIN GROUP"),
15948 : parser_errposition(@2)));
15949 342 : if (n->func_variadic)
15950 0 : ereport(ERROR,
15951 : (errcode(ERRCODE_SYNTAX_ERROR),
15952 : errmsg("cannot use VARIADIC with WITHIN GROUP"),
15953 : parser_errposition(@2)));
15954 342 : n->agg_order = $2;
15955 342 : n->agg_within_group = true;
15956 : }
15957 326812 : n->agg_filter = $3;
15958 326812 : n->ignore_nulls = $4;
15959 326812 : n->over = $5;
15960 326812 : $$ = (Node *) n;
15961 : }
15962 : | json_aggregate_func filter_clause over_clause
15963 : {
15964 720 : JsonAggConstructor *n = IsA($1, JsonObjectAgg) ?
15965 360 : ((JsonObjectAgg *) $1)->constructor :
15966 156 : ((JsonArrayAgg *) $1)->constructor;
15967 :
15968 360 : n->agg_filter = $2;
15969 360 : n->over = $3;
15970 360 : $$ = (Node *) $1;
15971 : }
15972 : | func_expr_common_subexpr
15973 77842 : { $$ = $1; }
15974 : ;
15975 :
15976 : /*
15977 : * Like func_expr but does not accept WINDOW functions directly
15978 : * (but they can still be contained in arguments for functions etc).
15979 : * Use this when window expressions are not allowed, where needed to
15980 : * disambiguate the grammar (e.g. in CREATE INDEX).
15981 : */
15982 : func_expr_windowless:
15983 49348 : func_application { $$ = $1; }
15984 402 : | func_expr_common_subexpr { $$ = $1; }
15985 0 : | json_aggregate_func { $$ = $1; }
15986 : ;
15987 :
15988 : /*
15989 : * Special expressions that are considered to be functions.
15990 : */
15991 : func_expr_common_subexpr:
15992 : COLLATION FOR '(' a_expr ')'
15993 : {
15994 30 : $$ = (Node *) makeFuncCall(SystemFuncName("pg_collation_for"),
15995 30 : list_make1($4),
15996 : COERCE_SQL_SYNTAX,
15997 30 : @1);
15998 : }
15999 : | CURRENT_DATE
16000 : {
16001 312 : $$ = makeSQLValueFunction(SVFOP_CURRENT_DATE, -1, @1);
16002 : }
16003 : | CURRENT_TIME
16004 : {
16005 24 : $$ = makeSQLValueFunction(SVFOP_CURRENT_TIME, -1, @1);
16006 : }
16007 : | CURRENT_TIME '(' Iconst ')'
16008 : {
16009 24 : $$ = makeSQLValueFunction(SVFOP_CURRENT_TIME_N, $3, @1);
16010 : }
16011 : | CURRENT_TIMESTAMP
16012 : {
16013 286 : $$ = makeSQLValueFunction(SVFOP_CURRENT_TIMESTAMP, -1, @1);
16014 : }
16015 : | CURRENT_TIMESTAMP '(' Iconst ')'
16016 : {
16017 176 : $$ = makeSQLValueFunction(SVFOP_CURRENT_TIMESTAMP_N, $3, @1);
16018 : }
16019 : | LOCALTIME
16020 : {
16021 24 : $$ = makeSQLValueFunction(SVFOP_LOCALTIME, -1, @1);
16022 : }
16023 : | LOCALTIME '(' Iconst ')'
16024 : {
16025 24 : $$ = makeSQLValueFunction(SVFOP_LOCALTIME_N, $3, @1);
16026 : }
16027 : | LOCALTIMESTAMP
16028 : {
16029 36 : $$ = makeSQLValueFunction(SVFOP_LOCALTIMESTAMP, -1, @1);
16030 : }
16031 : | LOCALTIMESTAMP '(' Iconst ')'
16032 : {
16033 24 : $$ = makeSQLValueFunction(SVFOP_LOCALTIMESTAMP_N, $3, @1);
16034 : }
16035 : | CURRENT_ROLE
16036 : {
16037 68 : $$ = makeSQLValueFunction(SVFOP_CURRENT_ROLE, -1, @1);
16038 : }
16039 : | CURRENT_USER
16040 : {
16041 1086 : $$ = makeSQLValueFunction(SVFOP_CURRENT_USER, -1, @1);
16042 : }
16043 : | SESSION_USER
16044 : {
16045 590 : $$ = makeSQLValueFunction(SVFOP_SESSION_USER, -1, @1);
16046 : }
16047 : | SYSTEM_USER
16048 : {
16049 20 : $$ = (Node *) makeFuncCall(SystemFuncName("system_user"),
16050 : NIL,
16051 : COERCE_SQL_SYNTAX,
16052 : @1);
16053 : }
16054 : | USER
16055 : {
16056 24 : $$ = makeSQLValueFunction(SVFOP_USER, -1, @1);
16057 : }
16058 : | CURRENT_CATALOG
16059 : {
16060 60 : $$ = makeSQLValueFunction(SVFOP_CURRENT_CATALOG, -1, @1);
16061 : }
16062 : | CURRENT_SCHEMA
16063 : {
16064 30 : $$ = makeSQLValueFunction(SVFOP_CURRENT_SCHEMA, -1, @1);
16065 : }
16066 : | CAST '(' a_expr AS Typename ')'
16067 63758 : { $$ = makeTypeCast($3, $5, @1); }
16068 : | EXTRACT '(' extract_list ')'
16069 : {
16070 1390 : $$ = (Node *) makeFuncCall(SystemFuncName("extract"),
16071 1390 : $3,
16072 : COERCE_SQL_SYNTAX,
16073 1390 : @1);
16074 : }
16075 : | NORMALIZE '(' a_expr ')'
16076 : {
16077 18 : $$ = (Node *) makeFuncCall(SystemFuncName("normalize"),
16078 18 : list_make1($3),
16079 : COERCE_SQL_SYNTAX,
16080 18 : @1);
16081 : }
16082 : | NORMALIZE '(' a_expr ',' unicode_normal_form ')'
16083 : {
16084 42 : $$ = (Node *) makeFuncCall(SystemFuncName("normalize"),
16085 42 : list_make2($3, makeStringConst($5, @5)),
16086 : COERCE_SQL_SYNTAX,
16087 42 : @1);
16088 : }
16089 : | OVERLAY '(' overlay_list ')'
16090 : {
16091 82 : $$ = (Node *) makeFuncCall(SystemFuncName("overlay"),
16092 82 : $3,
16093 : COERCE_SQL_SYNTAX,
16094 82 : @1);
16095 : }
16096 : | OVERLAY '(' func_arg_list_opt ')'
16097 : {
16098 : /*
16099 : * allow functions named overlay() to be called without
16100 : * special syntax
16101 : */
16102 0 : $$ = (Node *) makeFuncCall(list_make1(makeString("overlay")),
16103 0 : $3,
16104 : COERCE_EXPLICIT_CALL,
16105 0 : @1);
16106 : }
16107 : | POSITION '(' position_list ')'
16108 : {
16109 : /*
16110 : * position(A in B) is converted to position(B, A)
16111 : *
16112 : * We deliberately don't offer a "plain syntax" option
16113 : * for position(), because the reversal of the arguments
16114 : * creates too much risk of confusion.
16115 : */
16116 402 : $$ = (Node *) makeFuncCall(SystemFuncName("position"),
16117 402 : $3,
16118 : COERCE_SQL_SYNTAX,
16119 402 : @1);
16120 : }
16121 : | SUBSTRING '(' substr_list ')'
16122 : {
16123 : /* substring(A from B for C) is converted to
16124 : * substring(A, B, C) - thomas 2000-11-28
16125 : */
16126 718 : $$ = (Node *) makeFuncCall(SystemFuncName("substring"),
16127 718 : $3,
16128 : COERCE_SQL_SYNTAX,
16129 718 : @1);
16130 : }
16131 : | SUBSTRING '(' func_arg_list_opt ')'
16132 : {
16133 : /*
16134 : * allow functions named substring() to be called without
16135 : * special syntax
16136 : */
16137 254 : $$ = (Node *) makeFuncCall(list_make1(makeString("substring")),
16138 254 : $3,
16139 : COERCE_EXPLICIT_CALL,
16140 254 : @1);
16141 : }
16142 : | TREAT '(' a_expr AS Typename ')'
16143 : {
16144 : /* TREAT(expr AS target) converts expr of a particular type to target,
16145 : * which is defined to be a subtype of the original expression.
16146 : * In SQL99, this is intended for use with structured UDTs,
16147 : * but let's make this a generally useful form allowing stronger
16148 : * coercions than are handled by implicit casting.
16149 : *
16150 : * Convert SystemTypeName() to SystemFuncName() even though
16151 : * at the moment they result in the same thing.
16152 : */
16153 0 : $$ = (Node *) makeFuncCall(SystemFuncName(strVal(llast($5->names))),
16154 0 : list_make1($3),
16155 : COERCE_EXPLICIT_CALL,
16156 0 : @1);
16157 : }
16158 : | TRIM '(' BOTH trim_list ')'
16159 : {
16160 : /* various trim expressions are defined in SQL
16161 : * - thomas 1997-07-19
16162 : */
16163 12 : $$ = (Node *) makeFuncCall(SystemFuncName("btrim"),
16164 12 : $4,
16165 : COERCE_SQL_SYNTAX,
16166 12 : @1);
16167 : }
16168 : | TRIM '(' LEADING trim_list ')'
16169 : {
16170 24 : $$ = (Node *) makeFuncCall(SystemFuncName("ltrim"),
16171 24 : $4,
16172 : COERCE_SQL_SYNTAX,
16173 24 : @1);
16174 : }
16175 : | TRIM '(' TRAILING trim_list ')'
16176 : {
16177 584 : $$ = (Node *) makeFuncCall(SystemFuncName("rtrim"),
16178 584 : $4,
16179 : COERCE_SQL_SYNTAX,
16180 584 : @1);
16181 : }
16182 : | TRIM '(' trim_list ')'
16183 : {
16184 98 : $$ = (Node *) makeFuncCall(SystemFuncName("btrim"),
16185 98 : $3,
16186 : COERCE_SQL_SYNTAX,
16187 98 : @1);
16188 : }
16189 : | NULLIF '(' a_expr ',' a_expr ')'
16190 : {
16191 388 : $$ = (Node *) makeSimpleA_Expr(AEXPR_NULLIF, "=", $3, $5, @1);
16192 : }
16193 : | COALESCE '(' expr_list ')'
16194 : {
16195 3314 : CoalesceExpr *c = makeNode(CoalesceExpr);
16196 :
16197 3314 : c->args = $3;
16198 3314 : c->location = @1;
16199 3314 : $$ = (Node *) c;
16200 : }
16201 : | GREATEST '(' expr_list ')'
16202 : {
16203 158 : MinMaxExpr *v = makeNode(MinMaxExpr);
16204 :
16205 158 : v->args = $3;
16206 158 : v->op = IS_GREATEST;
16207 158 : v->location = @1;
16208 158 : $$ = (Node *) v;
16209 : }
16210 : | LEAST '(' expr_list ')'
16211 : {
16212 148 : MinMaxExpr *v = makeNode(MinMaxExpr);
16213 :
16214 148 : v->args = $3;
16215 148 : v->op = IS_LEAST;
16216 148 : v->location = @1;
16217 148 : $$ = (Node *) v;
16218 : }
16219 : | XMLCONCAT '(' expr_list ')'
16220 : {
16221 62 : $$ = makeXmlExpr(IS_XMLCONCAT, NULL, NIL, $3, @1);
16222 : }
16223 : | XMLELEMENT '(' NAME_P ColLabel ')'
16224 : {
16225 6 : $$ = makeXmlExpr(IS_XMLELEMENT, $4, NIL, NIL, @1);
16226 : }
16227 : | XMLELEMENT '(' NAME_P ColLabel ',' xml_attributes ')'
16228 : {
16229 36 : $$ = makeXmlExpr(IS_XMLELEMENT, $4, $6, NIL, @1);
16230 : }
16231 : | XMLELEMENT '(' NAME_P ColLabel ',' expr_list ')'
16232 : {
16233 116 : $$ = makeXmlExpr(IS_XMLELEMENT, $4, NIL, $6, @1);
16234 : }
16235 : | XMLELEMENT '(' NAME_P ColLabel ',' xml_attributes ',' expr_list ')'
16236 : {
16237 20 : $$ = makeXmlExpr(IS_XMLELEMENT, $4, $6, $8, @1);
16238 : }
16239 : | XMLEXISTS '(' c_expr xmlexists_argument ')'
16240 : {
16241 : /* xmlexists(A PASSING [BY REF] B [BY REF]) is
16242 : * converted to xmlexists(A, B)*/
16243 54 : $$ = (Node *) makeFuncCall(SystemFuncName("xmlexists"),
16244 54 : list_make2($3, $4),
16245 : COERCE_SQL_SYNTAX,
16246 54 : @1);
16247 : }
16248 : | XMLFOREST '(' xml_attribute_list ')'
16249 : {
16250 32 : $$ = makeXmlExpr(IS_XMLFOREST, NULL, $3, NIL, @1);
16251 : }
16252 : | XMLPARSE '(' document_or_content a_expr xml_whitespace_option ')'
16253 : {
16254 : XmlExpr *x = (XmlExpr *)
16255 140 : makeXmlExpr(IS_XMLPARSE, NULL, NIL,
16256 140 : list_make2($4, makeBoolAConst($5, -1)),
16257 140 : @1);
16258 :
16259 140 : x->xmloption = $3;
16260 140 : $$ = (Node *) x;
16261 : }
16262 : | XMLPI '(' NAME_P ColLabel ')'
16263 : {
16264 30 : $$ = makeXmlExpr(IS_XMLPI, $4, NULL, NIL, @1);
16265 : }
16266 : | XMLPI '(' NAME_P ColLabel ',' a_expr ')'
16267 : {
16268 50 : $$ = makeXmlExpr(IS_XMLPI, $4, NULL, list_make1($6), @1);
16269 : }
16270 : | XMLROOT '(' a_expr ',' xml_root_version opt_xml_root_standalone ')'
16271 : {
16272 68 : $$ = makeXmlExpr(IS_XMLROOT, NULL, NIL,
16273 68 : list_make3($3, $5, $6), @1);
16274 : }
16275 : | XMLSERIALIZE '(' document_or_content a_expr AS SimpleTypename xml_indent_option ')'
16276 : {
16277 218 : XmlSerialize *n = makeNode(XmlSerialize);
16278 :
16279 218 : n->xmloption = $3;
16280 218 : n->expr = $4;
16281 218 : n->typeName = $6;
16282 218 : n->indent = $7;
16283 218 : n->location = @1;
16284 218 : $$ = (Node *) n;
16285 : }
16286 : | JSON_OBJECT '(' func_arg_list ')'
16287 : {
16288 : /* Support for legacy (non-standard) json_object() */
16289 90 : $$ = (Node *) makeFuncCall(SystemFuncName("json_object"),
16290 90 : $3, COERCE_EXPLICIT_CALL, @1);
16291 : }
16292 : | JSON_OBJECT '(' json_name_and_value_list
16293 : json_object_constructor_null_clause_opt
16294 : json_key_uniqueness_constraint_opt
16295 : json_returning_clause_opt ')'
16296 : {
16297 348 : JsonObjectConstructor *n = makeNode(JsonObjectConstructor);
16298 :
16299 348 : n->exprs = $3;
16300 348 : n->absent_on_null = $4;
16301 348 : n->unique = $5;
16302 348 : n->output = (JsonOutput *) $6;
16303 348 : n->location = @1;
16304 348 : $$ = (Node *) n;
16305 : }
16306 : | JSON_OBJECT '(' json_returning_clause_opt ')'
16307 : {
16308 92 : JsonObjectConstructor *n = makeNode(JsonObjectConstructor);
16309 :
16310 92 : n->exprs = NULL;
16311 92 : n->absent_on_null = false;
16312 92 : n->unique = false;
16313 92 : n->output = (JsonOutput *) $3;
16314 92 : n->location = @1;
16315 92 : $$ = (Node *) n;
16316 : }
16317 : | JSON_ARRAY '('
16318 : json_value_expr_list
16319 : json_array_constructor_null_clause_opt
16320 : json_returning_clause_opt
16321 : ')'
16322 : {
16323 120 : JsonArrayConstructor *n = makeNode(JsonArrayConstructor);
16324 :
16325 120 : n->exprs = $3;
16326 120 : n->absent_on_null = $4;
16327 120 : n->output = (JsonOutput *) $5;
16328 120 : n->location = @1;
16329 120 : $$ = (Node *) n;
16330 : }
16331 : | JSON_ARRAY '('
16332 : select_no_parens
16333 : json_format_clause_opt
16334 : /* json_array_constructor_null_clause_opt */
16335 : json_returning_clause_opt
16336 : ')'
16337 : {
16338 60 : JsonArrayQueryConstructor *n = makeNode(JsonArrayQueryConstructor);
16339 :
16340 60 : n->query = $3;
16341 60 : n->format = (JsonFormat *) $4;
16342 60 : n->absent_on_null = true; /* XXX */
16343 60 : n->output = (JsonOutput *) $5;
16344 60 : n->location = @1;
16345 60 : $$ = (Node *) n;
16346 : }
16347 : | JSON_ARRAY '('
16348 : json_returning_clause_opt
16349 : ')'
16350 : {
16351 86 : JsonArrayConstructor *n = makeNode(JsonArrayConstructor);
16352 :
16353 86 : n->exprs = NIL;
16354 86 : n->absent_on_null = true;
16355 86 : n->output = (JsonOutput *) $3;
16356 86 : n->location = @1;
16357 86 : $$ = (Node *) n;
16358 : }
16359 : | JSON '(' json_value_expr json_key_uniqueness_constraint_opt ')'
16360 : {
16361 164 : JsonParseExpr *n = makeNode(JsonParseExpr);
16362 :
16363 164 : n->expr = (JsonValueExpr *) $3;
16364 164 : n->unique_keys = $4;
16365 164 : n->output = NULL;
16366 164 : n->location = @1;
16367 164 : $$ = (Node *) n;
16368 : }
16369 : | JSON_SCALAR '(' a_expr ')'
16370 : {
16371 112 : JsonScalarExpr *n = makeNode(JsonScalarExpr);
16372 :
16373 112 : n->expr = (Expr *) $3;
16374 112 : n->output = NULL;
16375 112 : n->location = @1;
16376 112 : $$ = (Node *) n;
16377 : }
16378 : | JSON_SERIALIZE '(' json_value_expr json_returning_clause_opt ')'
16379 : {
16380 108 : JsonSerializeExpr *n = makeNode(JsonSerializeExpr);
16381 :
16382 108 : n->expr = (JsonValueExpr *) $3;
16383 108 : n->output = (JsonOutput *) $4;
16384 108 : n->location = @1;
16385 108 : $$ = (Node *) n;
16386 : }
16387 : | MERGE_ACTION '(' ')'
16388 : {
16389 216 : MergeSupportFunc *m = makeNode(MergeSupportFunc);
16390 :
16391 216 : m->msftype = TEXTOID;
16392 216 : m->location = @1;
16393 216 : $$ = (Node *) m;
16394 : }
16395 : | JSON_QUERY '('
16396 : json_value_expr ',' a_expr json_passing_clause_opt
16397 : json_returning_clause_opt
16398 : json_wrapper_behavior
16399 : json_quotes_clause_opt
16400 : json_behavior_clause_opt
16401 : ')'
16402 : {
16403 990 : JsonFuncExpr *n = makeNode(JsonFuncExpr);
16404 :
16405 990 : n->op = JSON_QUERY_OP;
16406 990 : n->context_item = (JsonValueExpr *) $3;
16407 990 : n->pathspec = $5;
16408 990 : n->passing = $6;
16409 990 : n->output = (JsonOutput *) $7;
16410 990 : n->wrapper = $8;
16411 990 : n->quotes = $9;
16412 990 : n->on_empty = (JsonBehavior *) linitial($10);
16413 990 : n->on_error = (JsonBehavior *) lsecond($10);
16414 990 : n->location = @1;
16415 990 : $$ = (Node *) n;
16416 : }
16417 : | JSON_EXISTS '('
16418 : json_value_expr ',' a_expr json_passing_clause_opt
16419 : json_on_error_clause_opt
16420 : ')'
16421 : {
16422 168 : JsonFuncExpr *n = makeNode(JsonFuncExpr);
16423 :
16424 168 : n->op = JSON_EXISTS_OP;
16425 168 : n->context_item = (JsonValueExpr *) $3;
16426 168 : n->pathspec = $5;
16427 168 : n->passing = $6;
16428 168 : n->output = NULL;
16429 168 : n->on_error = (JsonBehavior *) $7;
16430 168 : n->location = @1;
16431 168 : $$ = (Node *) n;
16432 : }
16433 : | JSON_VALUE '('
16434 : json_value_expr ',' a_expr json_passing_clause_opt
16435 : json_returning_clause_opt
16436 : json_behavior_clause_opt
16437 : ')'
16438 : {
16439 630 : JsonFuncExpr *n = makeNode(JsonFuncExpr);
16440 :
16441 630 : n->op = JSON_VALUE_OP;
16442 630 : n->context_item = (JsonValueExpr *) $3;
16443 630 : n->pathspec = $5;
16444 630 : n->passing = $6;
16445 630 : n->output = (JsonOutput *) $7;
16446 630 : n->on_empty = (JsonBehavior *) linitial($8);
16447 630 : n->on_error = (JsonBehavior *) lsecond($8);
16448 630 : n->location = @1;
16449 630 : $$ = (Node *) n;
16450 : }
16451 : ;
16452 :
16453 :
16454 : /*
16455 : * SQL/XML support
16456 : */
16457 : xml_root_version: VERSION_P a_expr
16458 24 : { $$ = $2; }
16459 : | VERSION_P NO VALUE_P
16460 44 : { $$ = makeNullAConst(-1); }
16461 : ;
16462 :
16463 : opt_xml_root_standalone: ',' STANDALONE_P YES_P
16464 26 : { $$ = makeIntConst(XML_STANDALONE_YES, -1); }
16465 : | ',' STANDALONE_P NO
16466 12 : { $$ = makeIntConst(XML_STANDALONE_NO, -1); }
16467 : | ',' STANDALONE_P NO VALUE_P
16468 12 : { $$ = makeIntConst(XML_STANDALONE_NO_VALUE, -1); }
16469 : | /*EMPTY*/
16470 18 : { $$ = makeIntConst(XML_STANDALONE_OMITTED, -1); }
16471 : ;
16472 :
16473 56 : xml_attributes: XMLATTRIBUTES '(' xml_attribute_list ')' { $$ = $3; }
16474 : ;
16475 :
16476 88 : xml_attribute_list: xml_attribute_el { $$ = list_make1($1); }
16477 144 : | xml_attribute_list ',' xml_attribute_el { $$ = lappend($1, $3); }
16478 : ;
16479 :
16480 : xml_attribute_el: a_expr AS ColLabel
16481 : {
16482 106 : $$ = makeNode(ResTarget);
16483 106 : $$->name = $3;
16484 106 : $$->indirection = NIL;
16485 106 : $$->val = (Node *) $1;
16486 106 : $$->location = @1;
16487 : }
16488 : | a_expr
16489 : {
16490 126 : $$ = makeNode(ResTarget);
16491 126 : $$->name = NULL;
16492 126 : $$->indirection = NIL;
16493 126 : $$->val = (Node *) $1;
16494 126 : $$->location = @1;
16495 : }
16496 : ;
16497 :
16498 186 : document_or_content: DOCUMENT_P { $$ = XMLOPTION_DOCUMENT; }
16499 188 : | CONTENT_P { $$ = XMLOPTION_CONTENT; }
16500 : ;
16501 :
16502 140 : xml_indent_option: INDENT { $$ = true; }
16503 36 : | NO INDENT { $$ = false; }
16504 42 : | /*EMPTY*/ { $$ = false; }
16505 : ;
16506 :
16507 0 : xml_whitespace_option: PRESERVE WHITESPACE_P { $$ = true; }
16508 2 : | STRIP_P WHITESPACE_P { $$ = false; }
16509 138 : | /*EMPTY*/ { $$ = false; }
16510 : ;
16511 :
16512 : /* We allow several variants for SQL and other compatibility. */
16513 : xmlexists_argument:
16514 : PASSING c_expr
16515 : {
16516 238 : $$ = $2;
16517 : }
16518 : | PASSING c_expr xml_passing_mech
16519 : {
16520 0 : $$ = $2;
16521 : }
16522 : | PASSING xml_passing_mech c_expr
16523 : {
16524 42 : $$ = $3;
16525 : }
16526 : | PASSING xml_passing_mech c_expr xml_passing_mech
16527 : {
16528 6 : $$ = $3;
16529 : }
16530 : ;
16531 :
16532 : xml_passing_mech:
16533 : BY REF_P
16534 : | BY VALUE_P
16535 : ;
16536 :
16537 : /*****************************************************************************
16538 : *
16539 : * WAIT FOR LSN
16540 : *
16541 : *****************************************************************************/
16542 :
16543 : WaitStmt:
16544 : WAIT FOR LSN_P Sconst opt_wait_with_clause
16545 : {
16546 54 : WaitStmt *n = makeNode(WaitStmt);
16547 54 : n->lsn_literal = $4;
16548 54 : n->options = $5;
16549 54 : $$ = (Node *) n;
16550 : }
16551 : ;
16552 :
16553 : opt_wait_with_clause:
16554 28 : WITH '(' utility_option_list ')' { $$ = $3; }
16555 26 : | /*EMPTY*/ { $$ = NIL; }
16556 : ;
16557 :
16558 : /*
16559 : * Aggregate decoration clauses
16560 : */
16561 : within_group_clause:
16562 348 : WITHIN GROUP_P '(' sort_clause ')' { $$ = $4; }
16563 326476 : | /*EMPTY*/ { $$ = NIL; }
16564 : ;
16565 :
16566 : filter_clause:
16567 862 : FILTER '(' WHERE a_expr ')' { $$ = $4; }
16568 326322 : | /*EMPTY*/ { $$ = NULL; }
16569 : ;
16570 :
16571 :
16572 : /*
16573 : * Window Definitions
16574 : */
16575 : null_treatment:
16576 198 : IGNORE_P NULLS_P { $$ = PARSER_IGNORE_NULLS; }
16577 96 : | RESPECT_P NULLS_P { $$ = PARSER_RESPECT_NULLS; }
16578 326530 : | /*EMPTY*/ { $$ = NO_NULLTREATMENT; }
16579 : ;
16580 :
16581 : window_clause:
16582 606 : WINDOW window_definition_list { $$ = $2; }
16583 492752 : | /*EMPTY*/ { $$ = NIL; }
16584 : ;
16585 :
16586 : window_definition_list:
16587 606 : window_definition { $$ = list_make1($1); }
16588 : | window_definition_list ',' window_definition
16589 30 : { $$ = lappend($1, $3); }
16590 : ;
16591 :
16592 : window_definition:
16593 : ColId AS window_specification
16594 : {
16595 636 : WindowDef *n = $3;
16596 :
16597 636 : n->name = $1;
16598 636 : $$ = n;
16599 : }
16600 : ;
16601 :
16602 : over_clause: OVER window_specification
16603 2768 : { $$ = $2; }
16604 : | OVER ColId
16605 : {
16606 1182 : WindowDef *n = makeNode(WindowDef);
16607 :
16608 1182 : n->name = $2;
16609 1182 : n->refname = NULL;
16610 1182 : n->partitionClause = NIL;
16611 1182 : n->orderClause = NIL;
16612 1182 : n->frameOptions = FRAMEOPTION_DEFAULTS;
16613 1182 : n->startOffset = NULL;
16614 1182 : n->endOffset = NULL;
16615 1182 : n->location = @2;
16616 1182 : $$ = n;
16617 : }
16618 : | /*EMPTY*/
16619 323228 : { $$ = NULL; }
16620 : ;
16621 :
16622 : window_specification: '(' opt_existing_window_name opt_partition_clause
16623 : opt_sort_clause opt_frame_clause ')'
16624 : {
16625 3404 : WindowDef *n = makeNode(WindowDef);
16626 :
16627 3404 : n->name = NULL;
16628 3404 : n->refname = $2;
16629 3404 : n->partitionClause = $3;
16630 3404 : n->orderClause = $4;
16631 : /* copy relevant fields of opt_frame_clause */
16632 3404 : n->frameOptions = $5->frameOptions;
16633 3404 : n->startOffset = $5->startOffset;
16634 3404 : n->endOffset = $5->endOffset;
16635 3404 : n->location = @1;
16636 3404 : $$ = n;
16637 : }
16638 : ;
16639 :
16640 : /*
16641 : * If we see PARTITION, RANGE, ROWS or GROUPS as the first token after the '('
16642 : * of a window_specification, we want the assumption to be that there is
16643 : * no existing_window_name; but those keywords are unreserved and so could
16644 : * be ColIds. We fix this by making them have the same precedence as IDENT
16645 : * and giving the empty production here a slightly higher precedence, so
16646 : * that the shift/reduce conflict is resolved in favor of reducing the rule.
16647 : * These keywords are thus precluded from being an existing_window_name but
16648 : * are not reserved for any other purpose.
16649 : */
16650 54 : opt_existing_window_name: ColId { $$ = $1; }
16651 3356 : | /*EMPTY*/ %prec Op { $$ = NULL; }
16652 : ;
16653 :
16654 934 : opt_partition_clause: PARTITION BY expr_list { $$ = $3; }
16655 2470 : | /*EMPTY*/ { $$ = NIL; }
16656 : ;
16657 :
16658 : /*
16659 : * For frame clauses, we return a WindowDef, but only some fields are used:
16660 : * frameOptions, startOffset, and endOffset.
16661 : */
16662 : opt_frame_clause:
16663 : RANGE frame_extent opt_window_exclusion_clause
16664 : {
16665 796 : WindowDef *n = $2;
16666 :
16667 796 : n->frameOptions |= FRAMEOPTION_NONDEFAULT | FRAMEOPTION_RANGE;
16668 796 : n->frameOptions |= $3;
16669 796 : $$ = n;
16670 : }
16671 : | ROWS frame_extent opt_window_exclusion_clause
16672 : {
16673 690 : WindowDef *n = $2;
16674 :
16675 690 : n->frameOptions |= FRAMEOPTION_NONDEFAULT | FRAMEOPTION_ROWS;
16676 690 : n->frameOptions |= $3;
16677 690 : $$ = n;
16678 : }
16679 : | GROUPS frame_extent opt_window_exclusion_clause
16680 : {
16681 204 : WindowDef *n = $2;
16682 :
16683 204 : n->frameOptions |= FRAMEOPTION_NONDEFAULT | FRAMEOPTION_GROUPS;
16684 204 : n->frameOptions |= $3;
16685 204 : $$ = n;
16686 : }
16687 : | /*EMPTY*/
16688 : {
16689 1714 : WindowDef *n = makeNode(WindowDef);
16690 :
16691 1714 : n->frameOptions = FRAMEOPTION_DEFAULTS;
16692 1714 : n->startOffset = NULL;
16693 1714 : n->endOffset = NULL;
16694 1714 : $$ = n;
16695 : }
16696 : ;
16697 :
16698 : frame_extent: frame_bound
16699 : {
16700 12 : WindowDef *n = $1;
16701 :
16702 : /* reject invalid cases */
16703 12 : if (n->frameOptions & FRAMEOPTION_START_UNBOUNDED_FOLLOWING)
16704 0 : ereport(ERROR,
16705 : (errcode(ERRCODE_WINDOWING_ERROR),
16706 : errmsg("frame start cannot be UNBOUNDED FOLLOWING"),
16707 : parser_errposition(@1)));
16708 12 : if (n->frameOptions & FRAMEOPTION_START_OFFSET_FOLLOWING)
16709 0 : ereport(ERROR,
16710 : (errcode(ERRCODE_WINDOWING_ERROR),
16711 : errmsg("frame starting from following row cannot end with current row"),
16712 : parser_errposition(@1)));
16713 12 : n->frameOptions |= FRAMEOPTION_END_CURRENT_ROW;
16714 12 : $$ = n;
16715 : }
16716 : | BETWEEN frame_bound AND frame_bound
16717 : {
16718 1678 : WindowDef *n1 = $2;
16719 1678 : WindowDef *n2 = $4;
16720 :
16721 : /* form merged options */
16722 1678 : int frameOptions = n1->frameOptions;
16723 : /* shift converts START_ options to END_ options */
16724 1678 : frameOptions |= n2->frameOptions << 1;
16725 1678 : frameOptions |= FRAMEOPTION_BETWEEN;
16726 : /* reject invalid cases */
16727 1678 : if (frameOptions & FRAMEOPTION_START_UNBOUNDED_FOLLOWING)
16728 0 : ereport(ERROR,
16729 : (errcode(ERRCODE_WINDOWING_ERROR),
16730 : errmsg("frame start cannot be UNBOUNDED FOLLOWING"),
16731 : parser_errposition(@2)));
16732 1678 : if (frameOptions & FRAMEOPTION_END_UNBOUNDED_PRECEDING)
16733 0 : ereport(ERROR,
16734 : (errcode(ERRCODE_WINDOWING_ERROR),
16735 : errmsg("frame end cannot be UNBOUNDED PRECEDING"),
16736 : parser_errposition(@4)));
16737 1678 : if ((frameOptions & FRAMEOPTION_START_CURRENT_ROW) &&
16738 460 : (frameOptions & FRAMEOPTION_END_OFFSET_PRECEDING))
16739 0 : ereport(ERROR,
16740 : (errcode(ERRCODE_WINDOWING_ERROR),
16741 : errmsg("frame starting from current row cannot have preceding rows"),
16742 : parser_errposition(@4)));
16743 1678 : if ((frameOptions & FRAMEOPTION_START_OFFSET_FOLLOWING) &&
16744 168 : (frameOptions & (FRAMEOPTION_END_OFFSET_PRECEDING |
16745 : FRAMEOPTION_END_CURRENT_ROW)))
16746 0 : ereport(ERROR,
16747 : (errcode(ERRCODE_WINDOWING_ERROR),
16748 : errmsg("frame starting from following row cannot have preceding rows"),
16749 : parser_errposition(@4)));
16750 1678 : n1->frameOptions = frameOptions;
16751 1678 : n1->endOffset = n2->startOffset;
16752 1678 : $$ = n1;
16753 : }
16754 : ;
16755 :
16756 : /*
16757 : * This is used for both frame start and frame end, with output set up on
16758 : * the assumption it's frame start; the frame_extent productions must reject
16759 : * invalid cases.
16760 : */
16761 : frame_bound:
16762 : UNBOUNDED PRECEDING
16763 : {
16764 216 : WindowDef *n = makeNode(WindowDef);
16765 :
16766 216 : n->frameOptions = FRAMEOPTION_START_UNBOUNDED_PRECEDING;
16767 216 : n->startOffset = NULL;
16768 216 : n->endOffset = NULL;
16769 216 : $$ = n;
16770 : }
16771 : | UNBOUNDED FOLLOWING
16772 : {
16773 394 : WindowDef *n = makeNode(WindowDef);
16774 :
16775 394 : n->frameOptions = FRAMEOPTION_START_UNBOUNDED_FOLLOWING;
16776 394 : n->startOffset = NULL;
16777 394 : n->endOffset = NULL;
16778 394 : $$ = n;
16779 : }
16780 : | CURRENT_P ROW
16781 : {
16782 604 : WindowDef *n = makeNode(WindowDef);
16783 :
16784 604 : n->frameOptions = FRAMEOPTION_START_CURRENT_ROW;
16785 604 : n->startOffset = NULL;
16786 604 : n->endOffset = NULL;
16787 604 : $$ = n;
16788 : }
16789 : | a_expr PRECEDING
16790 : {
16791 954 : WindowDef *n = makeNode(WindowDef);
16792 :
16793 954 : n->frameOptions = FRAMEOPTION_START_OFFSET_PRECEDING;
16794 954 : n->startOffset = $1;
16795 954 : n->endOffset = NULL;
16796 954 : $$ = n;
16797 : }
16798 : | a_expr FOLLOWING
16799 : {
16800 1200 : WindowDef *n = makeNode(WindowDef);
16801 :
16802 1200 : n->frameOptions = FRAMEOPTION_START_OFFSET_FOLLOWING;
16803 1200 : n->startOffset = $1;
16804 1200 : n->endOffset = NULL;
16805 1200 : $$ = n;
16806 : }
16807 : ;
16808 :
16809 : opt_window_exclusion_clause:
16810 96 : EXCLUDE CURRENT_P ROW { $$ = FRAMEOPTION_EXCLUDE_CURRENT_ROW; }
16811 96 : | EXCLUDE GROUP_P { $$ = FRAMEOPTION_EXCLUDE_GROUP; }
16812 150 : | EXCLUDE TIES { $$ = FRAMEOPTION_EXCLUDE_TIES; }
16813 18 : | EXCLUDE NO OTHERS { $$ = 0; }
16814 1330 : | /*EMPTY*/ { $$ = 0; }
16815 : ;
16816 :
16817 :
16818 : /*
16819 : * Supporting nonterminals for expressions.
16820 : */
16821 :
16822 : /* Explicit row production.
16823 : *
16824 : * SQL99 allows an optional ROW keyword, so we can now do single-element rows
16825 : * without conflicting with the parenthesized a_expr production. Without the
16826 : * ROW keyword, there must be more than one a_expr inside the parens.
16827 : */
16828 0 : row: ROW '(' expr_list ')' { $$ = $3; }
16829 0 : | ROW '(' ')' { $$ = NIL; }
16830 1968 : | '(' expr_list ',' a_expr ')' { $$ = lappend($2, $4); }
16831 : ;
16832 :
16833 3820 : explicit_row: ROW '(' expr_list ')' { $$ = $3; }
16834 36 : | ROW '(' ')' { $$ = NIL; }
16835 : ;
16836 :
16837 2728 : implicit_row: '(' expr_list ',' a_expr ')' { $$ = lappend($2, $4); }
16838 : ;
16839 :
16840 17048 : sub_type: ANY { $$ = ANY_SUBLINK; }
16841 0 : | SOME { $$ = ANY_SUBLINK; }
16842 324 : | ALL { $$ = ALL_SUBLINK; }
16843 : ;
16844 :
16845 11516 : all_Op: Op { $$ = $1; }
16846 29708 : | MathOp { $$ = $1; }
16847 : ;
16848 :
16849 40 : MathOp: '+' { $$ = "+"; }
16850 68 : | '-' { $$ = "-"; }
16851 150 : | '*' { $$ = "*"; }
16852 0 : | '/' { $$ = "/"; }
16853 8 : | '%' { $$ = "%"; }
16854 0 : | '^' { $$ = "^"; }
16855 978 : | '<' { $$ = "<"; }
16856 886 : | '>' { $$ = ">"; }
16857 25094 : | '=' { $$ = "="; }
16858 844 : | LESS_EQUALS { $$ = "<="; }
16859 836 : | GREATER_EQUALS { $$ = ">="; }
16860 804 : | NOT_EQUALS { $$ = "<>"; }
16861 : ;
16862 :
16863 : qual_Op: Op
16864 44354 : { $$ = list_make1(makeString($1)); }
16865 : | OPERATOR '(' any_operator ')'
16866 16042 : { $$ = $3; }
16867 : ;
16868 :
16869 : qual_all_Op:
16870 : all_Op
16871 1416 : { $$ = list_make1(makeString($1)); }
16872 : | OPERATOR '(' any_operator ')'
16873 34 : { $$ = $3; }
16874 : ;
16875 :
16876 : subquery_Op:
16877 : all_Op
16878 17054 : { $$ = list_make1(makeString($1)); }
16879 : | OPERATOR '(' any_operator ')'
16880 286 : { $$ = $3; }
16881 : | LIKE
16882 24 : { $$ = list_make1(makeString("~~")); }
16883 : | NOT_LA LIKE
16884 12 : { $$ = list_make1(makeString("!~~")); }
16885 : | ILIKE
16886 12 : { $$ = list_make1(makeString("~~*")); }
16887 : | NOT_LA ILIKE
16888 0 : { $$ = list_make1(makeString("!~~*")); }
16889 : /* cannot put SIMILAR TO here, because SIMILAR TO is a hack.
16890 : * the regular expression is preprocessed by a function (similar_to_escape),
16891 : * and the ~ operator for posix regular expressions is used.
16892 : * x SIMILAR TO y -> x ~ similar_to_escape(y)
16893 : * this transformation is made on the fly by the parser upwards.
16894 : * however the SubLink structure which handles any/some/all stuff
16895 : * is not ready for such a thing.
16896 : */
16897 : ;
16898 :
16899 : expr_list: a_expr
16900 : {
16901 168850 : $$ = list_make1($1);
16902 : }
16903 : | expr_list ',' a_expr
16904 : {
16905 153166 : $$ = lappend($1, $3);
16906 : }
16907 : ;
16908 :
16909 : /* function arguments can have names */
16910 : func_arg_list: func_arg_expr
16911 : {
16912 324070 : $$ = list_make1($1);
16913 : }
16914 : | func_arg_list ',' func_arg_expr
16915 : {
16916 284784 : $$ = lappend($1, $3);
16917 : }
16918 : ;
16919 :
16920 : func_arg_expr: a_expr
16921 : {
16922 563332 : $$ = $1;
16923 : }
16924 : | param_name COLON_EQUALS a_expr
16925 : {
16926 44626 : NamedArgExpr *na = makeNode(NamedArgExpr);
16927 :
16928 44626 : na->name = $1;
16929 44626 : na->arg = (Expr *) $3;
16930 44626 : na->argnumber = -1; /* until determined */
16931 44626 : na->location = @1;
16932 44626 : $$ = (Node *) na;
16933 : }
16934 : | param_name EQUALS_GREATER a_expr
16935 : {
16936 1698 : NamedArgExpr *na = makeNode(NamedArgExpr);
16937 :
16938 1698 : na->name = $1;
16939 1698 : na->arg = (Expr *) $3;
16940 1698 : na->argnumber = -1; /* until determined */
16941 1698 : na->location = @1;
16942 1698 : $$ = (Node *) na;
16943 : }
16944 : ;
16945 :
16946 254 : func_arg_list_opt: func_arg_list { $$ = $1; }
16947 0 : | /*EMPTY*/ { $$ = NIL; }
16948 : ;
16949 :
16950 2308 : type_list: Typename { $$ = list_make1($1); }
16951 946 : | type_list ',' Typename { $$ = lappend($1, $3); }
16952 : ;
16953 :
16954 : array_expr: '[' expr_list ']'
16955 : {
16956 7756 : $$ = makeAArrayExpr($2, @1, @3);
16957 : }
16958 : | '[' array_expr_list ']'
16959 : {
16960 412 : $$ = makeAArrayExpr($2, @1, @3);
16961 : }
16962 : | '[' ']'
16963 : {
16964 98 : $$ = makeAArrayExpr(NIL, @1, @2);
16965 : }
16966 : ;
16967 :
16968 412 : array_expr_list: array_expr { $$ = list_make1($1); }
16969 342 : | array_expr_list ',' array_expr { $$ = lappend($1, $3); }
16970 : ;
16971 :
16972 :
16973 : extract_list:
16974 : extract_arg FROM a_expr
16975 : {
16976 1390 : $$ = list_make2(makeStringConst($1, @1), $3);
16977 : }
16978 : ;
16979 :
16980 : /* Allow delimited string Sconst in extract_arg as an SQL extension.
16981 : * - thomas 2001-04-12
16982 : */
16983 : extract_arg:
16984 1132 : IDENT { $$ = $1; }
16985 72 : | YEAR_P { $$ = "year"; }
16986 42 : | MONTH_P { $$ = "month"; }
16987 54 : | DAY_P { $$ = "day"; }
16988 30 : | HOUR_P { $$ = "hour"; }
16989 30 : | MINUTE_P { $$ = "minute"; }
16990 30 : | SECOND_P { $$ = "second"; }
16991 0 : | Sconst { $$ = $1; }
16992 : ;
16993 :
16994 : unicode_normal_form:
16995 24 : NFC { $$ = "NFC"; }
16996 18 : | NFD { $$ = "NFD"; }
16997 18 : | NFKC { $$ = "NFKC"; }
16998 18 : | NFKD { $$ = "NFKD"; }
16999 : ;
17000 :
17001 : /* OVERLAY() arguments */
17002 : overlay_list:
17003 : a_expr PLACING a_expr FROM a_expr FOR a_expr
17004 : {
17005 : /* overlay(A PLACING B FROM C FOR D) is converted to overlay(A, B, C, D) */
17006 34 : $$ = list_make4($1, $3, $5, $7);
17007 : }
17008 : | a_expr PLACING a_expr FROM a_expr
17009 : {
17010 : /* overlay(A PLACING B FROM C) is converted to overlay(A, B, C) */
17011 48 : $$ = list_make3($1, $3, $5);
17012 : }
17013 : ;
17014 :
17015 : /* position_list uses b_expr not a_expr to avoid conflict with general IN */
17016 : position_list:
17017 402 : b_expr IN_P b_expr { $$ = list_make2($3, $1); }
17018 : ;
17019 :
17020 : /*
17021 : * SUBSTRING() arguments
17022 : *
17023 : * Note that SQL:1999 has both
17024 : * text FROM int FOR int
17025 : * and
17026 : * text FROM pattern FOR escape
17027 : *
17028 : * In the parser we map them both to a call to the substring() function and
17029 : * rely on type resolution to pick the right one.
17030 : *
17031 : * In SQL:2003, the second variant was changed to
17032 : * text SIMILAR pattern ESCAPE escape
17033 : * We could in theory map that to a different function internally, but
17034 : * since we still support the SQL:1999 version, we don't. However,
17035 : * ruleutils.c will reverse-list the call in the newer style.
17036 : */
17037 : substr_list:
17038 : a_expr FROM a_expr FOR a_expr
17039 : {
17040 122 : $$ = list_make3($1, $3, $5);
17041 : }
17042 : | a_expr FOR a_expr FROM a_expr
17043 : {
17044 : /* not legal per SQL, but might as well allow it */
17045 0 : $$ = list_make3($1, $5, $3);
17046 : }
17047 : | a_expr FROM a_expr
17048 : {
17049 : /*
17050 : * Because we aren't restricting data types here, this
17051 : * syntax can end up resolving to textregexsubstr().
17052 : * We've historically allowed that to happen, so continue
17053 : * to accept it. However, ruleutils.c will reverse-list
17054 : * such a call in regular function call syntax.
17055 : */
17056 376 : $$ = list_make2($1, $3);
17057 : }
17058 : | a_expr FOR a_expr
17059 : {
17060 : /* not legal per SQL */
17061 :
17062 : /*
17063 : * Since there are no cases where this syntax allows
17064 : * a textual FOR value, we forcibly cast the argument
17065 : * to int4. The possible matches in pg_proc are
17066 : * substring(text,int4) and substring(text,text),
17067 : * and we don't want the parser to choose the latter,
17068 : * which it is likely to do if the second argument
17069 : * is unknown or doesn't have an implicit cast to int4.
17070 : */
17071 36 : $$ = list_make3($1, makeIntConst(1, -1),
17072 : makeTypeCast($3,
17073 : SystemTypeName("int4"), -1));
17074 : }
17075 : | a_expr SIMILAR a_expr ESCAPE a_expr
17076 : {
17077 184 : $$ = list_make3($1, $3, $5);
17078 : }
17079 : ;
17080 :
17081 608 : trim_list: a_expr FROM expr_list { $$ = lappend($3, $1); }
17082 24 : | FROM expr_list { $$ = $2; }
17083 86 : | expr_list { $$ = $1; }
17084 : ;
17085 :
17086 : /*
17087 : * Define SQL-style CASE clause.
17088 : * - Full specification
17089 : * CASE WHEN a = b THEN c ... ELSE d END
17090 : * - Implicit argument
17091 : * CASE a WHEN b THEN c ... ELSE d END
17092 : */
17093 : case_expr: CASE case_arg when_clause_list case_default END_P
17094 : {
17095 40216 : CaseExpr *c = makeNode(CaseExpr);
17096 :
17097 40216 : c->casetype = InvalidOid; /* not analyzed yet */
17098 40216 : c->arg = (Expr *) $2;
17099 40216 : c->args = $3;
17100 40216 : c->defresult = (Expr *) $4;
17101 40216 : c->location = @1;
17102 40216 : $$ = (Node *) c;
17103 : }
17104 : ;
17105 :
17106 : when_clause_list:
17107 : /* There must be at least one */
17108 40216 : when_clause { $$ = list_make1($1); }
17109 30330 : | when_clause_list when_clause { $$ = lappend($1, $2); }
17110 : ;
17111 :
17112 : when_clause:
17113 : WHEN a_expr THEN a_expr
17114 : {
17115 70546 : CaseWhen *w = makeNode(CaseWhen);
17116 :
17117 70546 : w->expr = (Expr *) $2;
17118 70546 : w->result = (Expr *) $4;
17119 70546 : w->location = @1;
17120 70546 : $$ = (Node *) w;
17121 : }
17122 : ;
17123 :
17124 : case_default:
17125 30228 : ELSE a_expr { $$ = $2; }
17126 9988 : | /*EMPTY*/ { $$ = NULL; }
17127 : ;
17128 :
17129 7208 : case_arg: a_expr { $$ = $1; }
17130 33008 : | /*EMPTY*/ { $$ = NULL; }
17131 : ;
17132 :
17133 : columnref: ColId
17134 : {
17135 764788 : $$ = makeColumnRef($1, NIL, @1, yyscanner);
17136 : }
17137 : | ColId indirection
17138 : {
17139 1078492 : $$ = makeColumnRef($1, $2, @1, yyscanner);
17140 : }
17141 : ;
17142 :
17143 : indirection_el:
17144 : '.' attr_name
17145 : {
17146 1454874 : $$ = (Node *) makeString($2);
17147 : }
17148 : | '.' '*'
17149 : {
17150 7126 : $$ = (Node *) makeNode(A_Star);
17151 : }
17152 : | '[' a_expr ']'
17153 : {
17154 13190 : A_Indices *ai = makeNode(A_Indices);
17155 :
17156 13190 : ai->is_slice = false;
17157 13190 : ai->lidx = NULL;
17158 13190 : ai->uidx = $2;
17159 13190 : $$ = (Node *) ai;
17160 : }
17161 : | '[' opt_slice_bound ':' opt_slice_bound ']'
17162 : {
17163 588 : A_Indices *ai = makeNode(A_Indices);
17164 :
17165 588 : ai->is_slice = true;
17166 588 : ai->lidx = $2;
17167 588 : ai->uidx = $4;
17168 588 : $$ = (Node *) ai;
17169 : }
17170 : ;
17171 :
17172 : opt_slice_bound:
17173 996 : a_expr { $$ = $1; }
17174 180 : | /*EMPTY*/ { $$ = NULL; }
17175 : ;
17176 :
17177 : indirection:
17178 1454934 : indirection_el { $$ = list_make1($1); }
17179 3158 : | indirection indirection_el { $$ = lappend($1, $2); }
17180 : ;
17181 :
17182 : opt_indirection:
17183 199038 : /*EMPTY*/ { $$ = NIL; }
17184 17686 : | opt_indirection indirection_el { $$ = lappend($1, $2); }
17185 : ;
17186 :
17187 : opt_asymmetric: ASYMMETRIC
17188 : | /*EMPTY*/
17189 : ;
17190 :
17191 : /* SQL/JSON support */
17192 : json_passing_clause_opt:
17193 336 : PASSING json_arguments { $$ = $2; }
17194 2000 : | /*EMPTY*/ { $$ = NIL; }
17195 : ;
17196 :
17197 : json_arguments:
17198 336 : json_argument { $$ = list_make1($1); }
17199 126 : | json_arguments ',' json_argument { $$ = lappend($1, $3); }
17200 : ;
17201 :
17202 : json_argument:
17203 : json_value_expr AS ColLabel
17204 : {
17205 462 : JsonArgument *n = makeNode(JsonArgument);
17206 :
17207 462 : n->val = (JsonValueExpr *) $1;
17208 462 : n->name = $3;
17209 462 : $$ = (Node *) n;
17210 : }
17211 : ;
17212 :
17213 : /* ARRAY is a noise word */
17214 : json_wrapper_behavior:
17215 42 : WITHOUT WRAPPER { $$ = JSW_NONE; }
17216 0 : | WITHOUT ARRAY WRAPPER { $$ = JSW_NONE; }
17217 84 : | WITH WRAPPER { $$ = JSW_UNCONDITIONAL; }
17218 12 : | WITH ARRAY WRAPPER { $$ = JSW_UNCONDITIONAL; }
17219 0 : | WITH CONDITIONAL ARRAY WRAPPER { $$ = JSW_CONDITIONAL; }
17220 12 : | WITH UNCONDITIONAL ARRAY WRAPPER { $$ = JSW_UNCONDITIONAL; }
17221 36 : | WITH CONDITIONAL WRAPPER { $$ = JSW_CONDITIONAL; }
17222 6 : | WITH UNCONDITIONAL WRAPPER { $$ = JSW_UNCONDITIONAL; }
17223 1640 : | /* empty */ { $$ = JSW_UNSPEC; }
17224 : ;
17225 :
17226 : json_behavior:
17227 : DEFAULT a_expr
17228 432 : { $$ = (Node *) makeJsonBehavior(JSON_BEHAVIOR_DEFAULT, $2, @1); }
17229 : | json_behavior_type
17230 702 : { $$ = (Node *) makeJsonBehavior($1, NULL, @1); }
17231 : ;
17232 :
17233 : json_behavior_type:
17234 492 : ERROR_P { $$ = JSON_BEHAVIOR_ERROR; }
17235 30 : | NULL_P { $$ = JSON_BEHAVIOR_NULL; }
17236 30 : | TRUE_P { $$ = JSON_BEHAVIOR_TRUE; }
17237 12 : | FALSE_P { $$ = JSON_BEHAVIOR_FALSE; }
17238 12 : | UNKNOWN { $$ = JSON_BEHAVIOR_UNKNOWN; }
17239 30 : | EMPTY_P ARRAY { $$ = JSON_BEHAVIOR_EMPTY_ARRAY; }
17240 72 : | EMPTY_P OBJECT_P { $$ = JSON_BEHAVIOR_EMPTY_OBJECT; }
17241 : /* non-standard, for Oracle compatibility only */
17242 24 : | EMPTY_P { $$ = JSON_BEHAVIOR_EMPTY_ARRAY; }
17243 : ;
17244 :
17245 : json_behavior_clause_opt:
17246 : json_behavior ON EMPTY_P
17247 222 : { $$ = list_make2($1, NULL); }
17248 : | json_behavior ON ERROR_P
17249 552 : { $$ = list_make2(NULL, $1); }
17250 : | json_behavior ON EMPTY_P json_behavior ON ERROR_P
17251 102 : { $$ = list_make2($1, $4); }
17252 : | /* EMPTY */
17253 1586 : { $$ = list_make2(NULL, NULL); }
17254 : ;
17255 :
17256 : json_on_error_clause_opt:
17257 : json_behavior ON ERROR_P
17258 150 : { $$ = $1; }
17259 : | /* EMPTY */
17260 692 : { $$ = NULL; }
17261 : ;
17262 :
17263 : json_value_expr:
17264 : a_expr json_format_clause_opt
17265 : {
17266 : /* formatted_expr will be set during parse-analysis. */
17267 4292 : $$ = (Node *) makeJsonValueExpr((Expr *) $1, NULL,
17268 4292 : castNode(JsonFormat, $2));
17269 : }
17270 : ;
17271 :
17272 : json_format_clause:
17273 : FORMAT_LA JSON ENCODING name
17274 : {
17275 : int encoding;
17276 :
17277 100 : if (!pg_strcasecmp($4, "utf8"))
17278 64 : encoding = JS_ENC_UTF8;
17279 36 : else if (!pg_strcasecmp($4, "utf16"))
17280 12 : encoding = JS_ENC_UTF16;
17281 24 : else if (!pg_strcasecmp($4, "utf32"))
17282 12 : encoding = JS_ENC_UTF32;
17283 : else
17284 12 : ereport(ERROR,
17285 : (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
17286 : errmsg("unrecognized JSON encoding: %s", $4),
17287 : parser_errposition(@4)));
17288 :
17289 88 : $$ = (Node *) makeJsonFormat(JS_FORMAT_JSON, encoding, @1);
17290 : }
17291 : | FORMAT_LA JSON
17292 : {
17293 412 : $$ = (Node *) makeJsonFormat(JS_FORMAT_JSON, JS_ENC_DEFAULT, @1);
17294 : }
17295 : ;
17296 :
17297 : json_format_clause_opt:
17298 : json_format_clause
17299 : {
17300 392 : $$ = $1;
17301 : }
17302 : | /* EMPTY */
17303 : {
17304 5458 : $$ = (Node *) makeJsonFormat(JS_FORMAT_DEFAULT, JS_ENC_DEFAULT, -1);
17305 : }
17306 : ;
17307 :
17308 : json_quotes_clause_opt:
17309 12 : KEEP QUOTES ON SCALAR STRING_P { $$ = JS_QUOTES_KEEP; }
17310 90 : | KEEP QUOTES { $$ = JS_QUOTES_KEEP; }
17311 12 : | OMIT QUOTES ON SCALAR STRING_P { $$ = JS_QUOTES_OMIT; }
17312 168 : | OMIT QUOTES { $$ = JS_QUOTES_OMIT; }
17313 1550 : | /* EMPTY */ { $$ = JS_QUOTES_UNSPEC; }
17314 : ;
17315 :
17316 : json_returning_clause_opt:
17317 : RETURNING Typename json_format_clause_opt
17318 : {
17319 1498 : JsonOutput *n = makeNode(JsonOutput);
17320 :
17321 1498 : n->typeName = $2;
17322 1498 : n->returning = makeNode(JsonReturning);
17323 1498 : n->returning->format = (JsonFormat *) $3;
17324 1498 : $$ = (Node *) n;
17325 : }
17326 1296 : | /* EMPTY */ { $$ = NULL; }
17327 : ;
17328 :
17329 : /*
17330 : * We must assign the only-JSON production a precedence less than IDENT in
17331 : * order to favor shifting over reduction when JSON is followed by VALUE_P,
17332 : * OBJECT_P, or SCALAR. (ARRAY doesn't need that treatment, because it's a
17333 : * fully reserved word.) Because json_predicate_type_constraint is always
17334 : * followed by json_key_uniqueness_constraint_opt, we also need the only-JSON
17335 : * production to have precedence less than WITH and WITHOUT. UNBOUNDED isn't
17336 : * really related to this syntax, but it's a convenient choice because it
17337 : * already has a precedence less than IDENT for other reasons.
17338 : */
17339 : json_predicate_type_constraint:
17340 202 : JSON %prec UNBOUNDED { $$ = JS_TYPE_ANY; }
17341 28 : | JSON VALUE_P { $$ = JS_TYPE_ANY; }
17342 40 : | JSON ARRAY { $$ = JS_TYPE_ARRAY; }
17343 40 : | JSON OBJECT_P { $$ = JS_TYPE_OBJECT; }
17344 40 : | JSON SCALAR { $$ = JS_TYPE_SCALAR; }
17345 : ;
17346 :
17347 : /*
17348 : * KEYS is a noise word here. To avoid shift/reduce conflicts, assign the
17349 : * KEYS-less productions a precedence less than IDENT (i.e., less than KEYS).
17350 : * This prevents reducing them when the next token is KEYS.
17351 : */
17352 : json_key_uniqueness_constraint_opt:
17353 108 : WITH UNIQUE KEYS { $$ = true; }
17354 100 : | WITH UNIQUE %prec UNBOUNDED { $$ = true; }
17355 44 : | WITHOUT UNIQUE KEYS { $$ = false; }
17356 16 : | WITHOUT UNIQUE %prec UNBOUNDED { $$ = false; }
17357 798 : | /* EMPTY */ %prec UNBOUNDED { $$ = false; }
17358 : ;
17359 :
17360 : json_name_and_value_list:
17361 : json_name_and_value
17362 348 : { $$ = list_make1($1); }
17363 : | json_name_and_value_list ',' json_name_and_value
17364 256 : { $$ = lappend($1, $3); }
17365 : ;
17366 :
17367 : json_name_and_value:
17368 : /* Supporting this syntax seems to require major surgery
17369 : KEY c_expr VALUE_P json_value_expr
17370 : { $$ = makeJsonKeyValue($2, $4); }
17371 : |
17372 : */
17373 : c_expr VALUE_P json_value_expr
17374 24 : { $$ = makeJsonKeyValue($1, $3); }
17375 : |
17376 : a_expr ':' json_value_expr
17377 784 : { $$ = makeJsonKeyValue($1, $3); }
17378 : ;
17379 :
17380 : /* empty means false for objects, true for arrays */
17381 : json_object_constructor_null_clause_opt:
17382 30 : NULL_P ON NULL_P { $$ = false; }
17383 110 : | ABSENT ON NULL_P { $$ = true; }
17384 412 : | /* EMPTY */ { $$ = false; }
17385 : ;
17386 :
17387 : json_array_constructor_null_clause_opt:
17388 60 : NULL_P ON NULL_P { $$ = false; }
17389 36 : | ABSENT ON NULL_P { $$ = true; }
17390 180 : | /* EMPTY */ { $$ = true; }
17391 : ;
17392 :
17393 : json_value_expr_list:
17394 120 : json_value_expr { $$ = list_make1($1); }
17395 138 : | json_value_expr_list ',' json_value_expr { $$ = lappend($1, $3);}
17396 : ;
17397 :
17398 : json_aggregate_func:
17399 : JSON_OBJECTAGG '('
17400 : json_name_and_value
17401 : json_object_constructor_null_clause_opt
17402 : json_key_uniqueness_constraint_opt
17403 : json_returning_clause_opt
17404 : ')'
17405 : {
17406 204 : JsonObjectAgg *n = makeNode(JsonObjectAgg);
17407 :
17408 204 : n->arg = (JsonKeyValue *) $3;
17409 204 : n->absent_on_null = $4;
17410 204 : n->unique = $5;
17411 204 : n->constructor = makeNode(JsonAggConstructor);
17412 204 : n->constructor->output = (JsonOutput *) $6;
17413 204 : n->constructor->agg_order = NULL;
17414 204 : n->constructor->location = @1;
17415 204 : $$ = (Node *) n;
17416 : }
17417 : | JSON_ARRAYAGG '('
17418 : json_value_expr
17419 : json_array_aggregate_order_by_clause_opt
17420 : json_array_constructor_null_clause_opt
17421 : json_returning_clause_opt
17422 : ')'
17423 : {
17424 156 : JsonArrayAgg *n = makeNode(JsonArrayAgg);
17425 :
17426 156 : n->arg = (JsonValueExpr *) $3;
17427 156 : n->absent_on_null = $5;
17428 156 : n->constructor = makeNode(JsonAggConstructor);
17429 156 : n->constructor->agg_order = $4;
17430 156 : n->constructor->output = (JsonOutput *) $6;
17431 156 : n->constructor->location = @1;
17432 156 : $$ = (Node *) n;
17433 : }
17434 : ;
17435 :
17436 : json_array_aggregate_order_by_clause_opt:
17437 18 : ORDER BY sortby_list { $$ = $3; }
17438 138 : | /* EMPTY */ { $$ = NIL; }
17439 : ;
17440 :
17441 : /*****************************************************************************
17442 : *
17443 : * target list for SELECT
17444 : *
17445 : *****************************************************************************/
17446 :
17447 488756 : opt_target_list: target_list { $$ = $1; }
17448 568 : | /* EMPTY */ { $$ = NIL; }
17449 : ;
17450 :
17451 : target_list:
17452 496092 : target_el { $$ = list_make1($1); }
17453 688306 : | target_list ',' target_el { $$ = lappend($1, $3); }
17454 : ;
17455 :
17456 : target_el: a_expr AS ColLabel
17457 : {
17458 241130 : $$ = makeNode(ResTarget);
17459 241130 : $$->name = $3;
17460 241130 : $$->indirection = NIL;
17461 241130 : $$->val = (Node *) $1;
17462 241130 : $$->location = @1;
17463 : }
17464 : | a_expr BareColLabel
17465 : {
17466 3586 : $$ = makeNode(ResTarget);
17467 3586 : $$->name = $2;
17468 3586 : $$->indirection = NIL;
17469 3586 : $$->val = (Node *) $1;
17470 3586 : $$->location = @1;
17471 : }
17472 : | a_expr
17473 : {
17474 876410 : $$ = makeNode(ResTarget);
17475 876410 : $$->name = NULL;
17476 876410 : $$->indirection = NIL;
17477 876410 : $$->val = (Node *) $1;
17478 876410 : $$->location = @1;
17479 : }
17480 : | '*'
17481 : {
17482 63272 : ColumnRef *n = makeNode(ColumnRef);
17483 :
17484 63272 : n->fields = list_make1(makeNode(A_Star));
17485 63272 : n->location = @1;
17486 :
17487 63272 : $$ = makeNode(ResTarget);
17488 63272 : $$->name = NULL;
17489 63272 : $$->indirection = NIL;
17490 63272 : $$->val = (Node *) n;
17491 63272 : $$->location = @1;
17492 : }
17493 : ;
17494 :
17495 :
17496 : /*****************************************************************************
17497 : *
17498 : * Names and constants
17499 : *
17500 : *****************************************************************************/
17501 :
17502 : qualified_name_list:
17503 18212 : qualified_name { $$ = list_make1($1); }
17504 808 : | qualified_name_list ',' qualified_name { $$ = lappend($1, $3); }
17505 : ;
17506 :
17507 : /*
17508 : * The production for a qualified relation name has to exactly match the
17509 : * production for a qualified func_name, because in a FROM clause we cannot
17510 : * tell which we are parsing until we see what comes after it ('(' for a
17511 : * func_name, something else for a relation). Therefore we allow 'indirection'
17512 : * which may contain subscripts, and reject that case in the C code.
17513 : */
17514 : qualified_name:
17515 : ColId
17516 : {
17517 440610 : $$ = makeRangeVar(NULL, $1, @1);
17518 : }
17519 : | ColId indirection
17520 : {
17521 247904 : $$ = makeRangeVarFromQualifiedName($1, $2, @1, yyscanner);
17522 : }
17523 : ;
17524 :
17525 : name_list: name
17526 28918 : { $$ = list_make1(makeString($1)); }
17527 : | name_list ',' name
17528 62810 : { $$ = lappend($1, makeString($3)); }
17529 : ;
17530 :
17531 :
17532 179234 : name: ColId { $$ = $1; };
17533 :
17534 1581922 : attr_name: ColLabel { $$ = $1; };
17535 :
17536 64 : file_name: Sconst { $$ = $1; };
17537 :
17538 : /*
17539 : * The production for a qualified func_name has to exactly match the
17540 : * production for a qualified columnref, because we cannot tell which we
17541 : * are parsing until we see what comes after it ('(' or Sconst for a func_name,
17542 : * anything else for a columnref). Therefore we allow 'indirection' which
17543 : * may contain subscripts, and reject that case in the C code. (If we
17544 : * ever implement SQL99-like methods, such syntax may actually become legal!)
17545 : */
17546 : func_name: type_function_name
17547 307428 : { $$ = list_make1(makeString($1)); }
17548 : | ColId indirection
17549 : {
17550 128460 : $$ = check_func_name(lcons(makeString($1), $2),
17551 : yyscanner);
17552 : }
17553 : ;
17554 :
17555 :
17556 : /*
17557 : * Constants
17558 : */
17559 : AexprConst: Iconst
17560 : {
17561 395764 : $$ = makeIntConst($1, @1);
17562 : }
17563 : | FCONST
17564 : {
17565 12046 : $$ = makeFloatConst($1, @1);
17566 : }
17567 : | Sconst
17568 : {
17569 712296 : $$ = makeStringConst($1, @1);
17570 : }
17571 : | BCONST
17572 : {
17573 754 : $$ = makeBitStringConst($1, @1);
17574 : }
17575 : | XCONST
17576 : {
17577 : /* This is a bit constant per SQL99:
17578 : * Without Feature F511, "BIT data type",
17579 : * a <general literal> shall not be a
17580 : * <bit string literal> or a <hex string literal>.
17581 : */
17582 3302 : $$ = makeBitStringConst($1, @1);
17583 : }
17584 : | func_name Sconst
17585 : {
17586 : /* generic type 'literal' syntax */
17587 9848 : TypeName *t = makeTypeNameFromNameList($1);
17588 :
17589 9848 : t->location = @1;
17590 9848 : $$ = makeStringConstCast($2, @2, t);
17591 : }
17592 : | func_name '(' func_arg_list opt_sort_clause ')' Sconst
17593 : {
17594 : /* generic syntax with a type modifier */
17595 0 : TypeName *t = makeTypeNameFromNameList($1);
17596 : ListCell *lc;
17597 :
17598 : /*
17599 : * We must use func_arg_list and opt_sort_clause in the
17600 : * production to avoid reduce/reduce conflicts, but we
17601 : * don't actually wish to allow NamedArgExpr in this
17602 : * context, nor ORDER BY.
17603 : */
17604 0 : foreach(lc, $3)
17605 : {
17606 0 : NamedArgExpr *arg = (NamedArgExpr *) lfirst(lc);
17607 :
17608 0 : if (IsA(arg, NamedArgExpr))
17609 0 : ereport(ERROR,
17610 : (errcode(ERRCODE_SYNTAX_ERROR),
17611 : errmsg("type modifier cannot have parameter name"),
17612 : parser_errposition(arg->location)));
17613 : }
17614 0 : if ($4 != NIL)
17615 0 : ereport(ERROR,
17616 : (errcode(ERRCODE_SYNTAX_ERROR),
17617 : errmsg("type modifier cannot have ORDER BY"),
17618 : parser_errposition(@4)));
17619 :
17620 0 : t->typmods = $3;
17621 0 : t->location = @1;
17622 0 : $$ = makeStringConstCast($6, @6, t);
17623 : }
17624 : | ConstTypename Sconst
17625 : {
17626 3176 : $$ = makeStringConstCast($2, @2, $1);
17627 : }
17628 : | ConstInterval Sconst opt_interval
17629 : {
17630 3298 : TypeName *t = $1;
17631 :
17632 3298 : t->typmods = $3;
17633 3298 : $$ = makeStringConstCast($2, @2, t);
17634 : }
17635 : | ConstInterval '(' Iconst ')' Sconst
17636 : {
17637 12 : TypeName *t = $1;
17638 :
17639 12 : t->typmods = list_make2(makeIntConst(INTERVAL_FULL_RANGE, -1),
17640 : makeIntConst($3, @3));
17641 12 : $$ = makeStringConstCast($5, @5, t);
17642 : }
17643 : | TRUE_P
17644 : {
17645 31272 : $$ = makeBoolAConst(true, @1);
17646 : }
17647 : | FALSE_P
17648 : {
17649 36114 : $$ = makeBoolAConst(false, @1);
17650 : }
17651 : | NULL_P
17652 : {
17653 69120 : $$ = makeNullAConst(@1);
17654 : }
17655 : ;
17656 :
17657 424668 : Iconst: ICONST { $$ = $1; };
17658 786424 : Sconst: SCONST { $$ = $1; };
17659 :
17660 17796 : SignedIconst: Iconst { $$ = $1; }
17661 0 : | '+' Iconst { $$ = + $2; }
17662 288 : | '-' Iconst { $$ = - $2; }
17663 : ;
17664 :
17665 : /* Role specifications */
17666 : RoleId: RoleSpec
17667 : {
17668 1970 : RoleSpec *spc = (RoleSpec *) $1;
17669 :
17670 1970 : switch (spc->roletype)
17671 : {
17672 1960 : case ROLESPEC_CSTRING:
17673 1960 : $$ = spc->rolename;
17674 1960 : break;
17675 4 : case ROLESPEC_PUBLIC:
17676 4 : ereport(ERROR,
17677 : (errcode(ERRCODE_RESERVED_NAME),
17678 : errmsg("role name \"%s\" is reserved",
17679 : "public"),
17680 : parser_errposition(@1)));
17681 : break;
17682 2 : case ROLESPEC_SESSION_USER:
17683 2 : ereport(ERROR,
17684 : (errcode(ERRCODE_RESERVED_NAME),
17685 : errmsg("%s cannot be used as a role name here",
17686 : "SESSION_USER"),
17687 : parser_errposition(@1)));
17688 : break;
17689 2 : case ROLESPEC_CURRENT_USER:
17690 2 : ereport(ERROR,
17691 : (errcode(ERRCODE_RESERVED_NAME),
17692 : errmsg("%s cannot be used as a role name here",
17693 : "CURRENT_USER"),
17694 : parser_errposition(@1)));
17695 : break;
17696 2 : case ROLESPEC_CURRENT_ROLE:
17697 2 : ereport(ERROR,
17698 : (errcode(ERRCODE_RESERVED_NAME),
17699 : errmsg("%s cannot be used as a role name here",
17700 : "CURRENT_ROLE"),
17701 : parser_errposition(@1)));
17702 : break;
17703 : }
17704 : }
17705 : ;
17706 :
17707 : RoleSpec: NonReservedWord
17708 : {
17709 : /*
17710 : * "public" and "none" are not keywords, but they must
17711 : * be treated specially here.
17712 : */
17713 : RoleSpec *n;
17714 :
17715 33306 : if (strcmp($1, "public") == 0)
17716 : {
17717 18152 : n = (RoleSpec *) makeRoleSpec(ROLESPEC_PUBLIC, @1);
17718 18152 : n->roletype = ROLESPEC_PUBLIC;
17719 : }
17720 15154 : else if (strcmp($1, "none") == 0)
17721 : {
17722 26 : ereport(ERROR,
17723 : (errcode(ERRCODE_RESERVED_NAME),
17724 : errmsg("role name \"%s\" is reserved",
17725 : "none"),
17726 : parser_errposition(@1)));
17727 : }
17728 : else
17729 : {
17730 15128 : n = makeRoleSpec(ROLESPEC_CSTRING, @1);
17731 15128 : n->rolename = pstrdup($1);
17732 : }
17733 33280 : $$ = n;
17734 : }
17735 : | CURRENT_ROLE
17736 : {
17737 130 : $$ = makeRoleSpec(ROLESPEC_CURRENT_ROLE, @1);
17738 : }
17739 : | CURRENT_USER
17740 : {
17741 228 : $$ = makeRoleSpec(ROLESPEC_CURRENT_USER, @1);
17742 : }
17743 : | SESSION_USER
17744 : {
17745 36 : $$ = makeRoleSpec(ROLESPEC_SESSION_USER, @1);
17746 : }
17747 : ;
17748 :
17749 : role_list: RoleSpec
17750 3276 : { $$ = list_make1($1); }
17751 : | role_list ',' RoleSpec
17752 270 : { $$ = lappend($1, $3); }
17753 : ;
17754 :
17755 :
17756 : /*****************************************************************************
17757 : *
17758 : * PL/pgSQL extensions
17759 : *
17760 : * You'd think a PL/pgSQL "expression" should be just an a_expr, but
17761 : * historically it can include just about anything that can follow SELECT.
17762 : * Therefore the returned struct is a SelectStmt.
17763 : *****************************************************************************/
17764 :
17765 : PLpgSQL_Expr: opt_distinct_clause opt_target_list
17766 : from_clause where_clause
17767 : group_clause having_clause window_clause
17768 : opt_sort_clause opt_select_limit opt_for_locking_clause
17769 : {
17770 41384 : SelectStmt *n = makeNode(SelectStmt);
17771 :
17772 41384 : n->distinctClause = $1;
17773 41384 : n->targetList = $2;
17774 41384 : n->fromClause = $3;
17775 41384 : n->whereClause = $4;
17776 41384 : n->groupClause = ($5)->list;
17777 41384 : n->groupDistinct = ($5)->distinct;
17778 41384 : n->groupByAll = ($5)->all;
17779 41384 : n->havingClause = $6;
17780 41384 : n->windowClause = $7;
17781 41384 : n->sortClause = $8;
17782 41384 : if ($9)
17783 : {
17784 4 : n->limitOffset = $9->limitOffset;
17785 4 : n->limitCount = $9->limitCount;
17786 4 : if (!n->sortClause &&
17787 4 : $9->limitOption == LIMIT_OPTION_WITH_TIES)
17788 0 : ereport(ERROR,
17789 : (errcode(ERRCODE_SYNTAX_ERROR),
17790 : errmsg("WITH TIES cannot be specified without ORDER BY clause"),
17791 : parser_errposition($9->optionLoc)));
17792 4 : n->limitOption = $9->limitOption;
17793 : }
17794 41384 : n->lockingClause = $10;
17795 41384 : $$ = (Node *) n;
17796 : }
17797 : ;
17798 :
17799 : /*
17800 : * PL/pgSQL Assignment statement: name opt_indirection := PLpgSQL_Expr
17801 : */
17802 :
17803 : PLAssignStmt: plassign_target opt_indirection plassign_equals PLpgSQL_Expr
17804 : {
17805 7094 : PLAssignStmt *n = makeNode(PLAssignStmt);
17806 :
17807 7094 : n->name = $1;
17808 7094 : n->indirection = check_indirection($2, yyscanner);
17809 : /* nnames will be filled by calling production */
17810 7094 : n->val = (SelectStmt *) $4;
17811 7094 : n->location = @1;
17812 7094 : $$ = (Node *) n;
17813 : }
17814 : ;
17815 :
17816 7070 : plassign_target: ColId { $$ = $1; }
17817 24 : | PARAM { $$ = psprintf("$%d", $1); }
17818 : ;
17819 :
17820 : plassign_equals: COLON_EQUALS
17821 : | '='
17822 : ;
17823 :
17824 :
17825 : /*
17826 : * Name classification hierarchy.
17827 : *
17828 : * IDENT is the lexeme returned by the lexer for identifiers that match
17829 : * no known keyword. In most cases, we can accept certain keywords as
17830 : * names, not only IDENTs. We prefer to accept as many such keywords
17831 : * as possible to minimize the impact of "reserved words" on programmers.
17832 : * So, we divide names into several possible classes. The classification
17833 : * is chosen in part to make keywords acceptable as names wherever possible.
17834 : */
17835 :
17836 : /* Column identifier --- names that can be column, table, etc names.
17837 : */
17838 3447300 : ColId: IDENT { $$ = $1; }
17839 59192 : | unreserved_keyword { $$ = pstrdup($1); }
17840 6292 : | col_name_keyword { $$ = pstrdup($1); }
17841 : ;
17842 :
17843 : /* Type/function identifier --- names that can be type or function names.
17844 : */
17845 727770 : type_function_name: IDENT { $$ = $1; }
17846 76766 : | unreserved_keyword { $$ = pstrdup($1); }
17847 66 : | type_func_name_keyword { $$ = pstrdup($1); }
17848 : ;
17849 :
17850 : /* Any not-fully-reserved word --- these names can be, eg, role names.
17851 : */
17852 86288 : NonReservedWord: IDENT { $$ = $1; }
17853 31232 : | unreserved_keyword { $$ = pstrdup($1); }
17854 220 : | col_name_keyword { $$ = pstrdup($1); }
17855 6034 : | type_func_name_keyword { $$ = pstrdup($1); }
17856 : ;
17857 :
17858 : /* Column label --- allowed labels in "AS" clauses.
17859 : * This presently includes *all* Postgres keywords.
17860 : */
17861 1806462 : ColLabel: IDENT { $$ = $1; }
17862 40714 : | unreserved_keyword { $$ = pstrdup($1); }
17863 284 : | col_name_keyword { $$ = pstrdup($1); }
17864 1772 : | type_func_name_keyword { $$ = pstrdup($1); }
17865 7638 : | reserved_keyword { $$ = pstrdup($1); }
17866 : ;
17867 :
17868 : /* Bare column label --- names that can be column labels without writing "AS".
17869 : * This classification is orthogonal to the other keyword categories.
17870 : */
17871 3572 : BareColLabel: IDENT { $$ = $1; }
17872 14 : | bare_label_keyword { $$ = pstrdup($1); }
17873 : ;
17874 :
17875 :
17876 : /*
17877 : * Keyword category lists. Generally, every keyword present in
17878 : * the Postgres grammar should appear in exactly one of these lists.
17879 : *
17880 : * Put a new keyword into the first list that it can go into without causing
17881 : * shift or reduce conflicts. The earlier lists define "less reserved"
17882 : * categories of keywords.
17883 : *
17884 : * Make sure that each keyword's category in kwlist.h matches where
17885 : * it is listed here. (Someday we may be able to generate these lists and
17886 : * kwlist.h's table from one source of truth.)
17887 : */
17888 :
17889 : /* "Unreserved" keywords --- available for use as any kind of name.
17890 : */
17891 : unreserved_keyword:
17892 : ABORT_P
17893 : | ABSENT
17894 : | ABSOLUTE_P
17895 : | ACCESS
17896 : | ACTION
17897 : | ADD_P
17898 : | ADMIN
17899 : | AFTER
17900 : | AGGREGATE
17901 : | ALSO
17902 : | ALTER
17903 : | ALWAYS
17904 : | ASENSITIVE
17905 : | ASSERTION
17906 : | ASSIGNMENT
17907 : | AT
17908 : | ATOMIC
17909 : | ATTACH
17910 : | ATTRIBUTE
17911 : | BACKWARD
17912 : | BEFORE
17913 : | BEGIN_P
17914 : | BREADTH
17915 : | BY
17916 : | CACHE
17917 : | CALL
17918 : | CALLED
17919 : | CASCADE
17920 : | CASCADED
17921 : | CATALOG_P
17922 : | CHAIN
17923 : | CHARACTERISTICS
17924 : | CHECKPOINT
17925 : | CLASS
17926 : | CLOSE
17927 : | CLUSTER
17928 : | COLUMNS
17929 : | COMMENT
17930 : | COMMENTS
17931 : | COMMIT
17932 : | COMMITTED
17933 : | COMPRESSION
17934 : | CONDITIONAL
17935 : | CONFIGURATION
17936 : | CONFLICT
17937 : | CONNECTION
17938 : | CONSTRAINTS
17939 : | CONTENT_P
17940 : | CONTINUE_P
17941 : | CONVERSION_P
17942 : | COPY
17943 : | COST
17944 : | CSV
17945 : | CUBE
17946 : | CURRENT_P
17947 : | CURSOR
17948 : | CYCLE
17949 : | DATA_P
17950 : | DATABASE
17951 : | DAY_P
17952 : | DEALLOCATE
17953 : | DECLARE
17954 : | DEFAULTS
17955 : | DEFERRED
17956 : | DEFINER
17957 : | DELETE_P
17958 : | DELIMITER
17959 : | DELIMITERS
17960 : | DEPENDS
17961 : | DEPTH
17962 : | DETACH
17963 : | DICTIONARY
17964 : | DISABLE_P
17965 : | DISCARD
17966 : | DOCUMENT_P
17967 : | DOMAIN_P
17968 : | DOUBLE_P
17969 : | DROP
17970 : | EACH
17971 : | EMPTY_P
17972 : | ENABLE_P
17973 : | ENCODING
17974 : | ENCRYPTED
17975 : | ENFORCED
17976 : | ENUM_P
17977 : | ERROR_P
17978 : | ESCAPE
17979 : | EVENT
17980 : | EXCLUDE
17981 : | EXCLUDING
17982 : | EXCLUSIVE
17983 : | EXECUTE
17984 : | EXPLAIN
17985 : | EXPRESSION
17986 : | EXTENSION
17987 : | EXTERNAL
17988 : | FAMILY
17989 : | FILTER
17990 : | FINALIZE
17991 : | FIRST_P
17992 : | FOLLOWING
17993 : | FORCE
17994 : | FORMAT
17995 : | FORWARD
17996 : | FUNCTION
17997 : | FUNCTIONS
17998 : | GENERATED
17999 : | GLOBAL
18000 : | GRANTED
18001 : | GROUPS
18002 : | HANDLER
18003 : | HEADER_P
18004 : | HOLD
18005 : | HOUR_P
18006 : | IDENTITY_P
18007 : | IF_P
18008 : | IGNORE_P
18009 : | IMMEDIATE
18010 : | IMMUTABLE
18011 : | IMPLICIT_P
18012 : | IMPORT_P
18013 : | INCLUDE
18014 : | INCLUDING
18015 : | INCREMENT
18016 : | INDENT
18017 : | INDEX
18018 : | INDEXES
18019 : | INHERIT
18020 : | INHERITS
18021 : | INLINE_P
18022 : | INPUT_P
18023 : | INSENSITIVE
18024 : | INSERT
18025 : | INSTEAD
18026 : | INVOKER
18027 : | ISOLATION
18028 : | KEEP
18029 : | KEY
18030 : | KEYS
18031 : | LABEL
18032 : | LANGUAGE
18033 : | LARGE_P
18034 : | LAST_P
18035 : | LEAKPROOF
18036 : | LEVEL
18037 : | LISTEN
18038 : | LOAD
18039 : | LOCAL
18040 : | LOCATION
18041 : | LOCK_P
18042 : | LOCKED
18043 : | LOGGED
18044 : | LSN_P
18045 : | MAPPING
18046 : | MATCH
18047 : | MATCHED
18048 : | MATERIALIZED
18049 : | MAXVALUE
18050 : | MERGE
18051 : | METHOD
18052 : | MINUTE_P
18053 : | MINVALUE
18054 : | MODE
18055 : | MONTH_P
18056 : | MOVE
18057 : | NAME_P
18058 : | NAMES
18059 : | NESTED
18060 : | NEW
18061 : | NEXT
18062 : | NFC
18063 : | NFD
18064 : | NFKC
18065 : | NFKD
18066 : | NO
18067 : | NORMALIZED
18068 : | NOTHING
18069 : | NOTIFY
18070 : | NOWAIT
18071 : | NULLS_P
18072 : | OBJECT_P
18073 : | OBJECTS_P
18074 : | OF
18075 : | OFF
18076 : | OIDS
18077 : | OLD
18078 : | OMIT
18079 : | OPERATOR
18080 : | OPTION
18081 : | OPTIONS
18082 : | ORDINALITY
18083 : | OTHERS
18084 : | OVER
18085 : | OVERRIDING
18086 : | OWNED
18087 : | OWNER
18088 : | PARALLEL
18089 : | PARAMETER
18090 : | PARSER
18091 : | PARTIAL
18092 : | PARTITION
18093 : | PARTITIONS
18094 : | PASSING
18095 : | PASSWORD
18096 : | PATH
18097 : | PERIOD
18098 : | PLAN
18099 : | PLANS
18100 : | POLICY
18101 : | PRECEDING
18102 : | PREPARE
18103 : | PREPARED
18104 : | PRESERVE
18105 : | PRIOR
18106 : | PRIVILEGES
18107 : | PROCEDURAL
18108 : | PROCEDURE
18109 : | PROCEDURES
18110 : | PROGRAM
18111 : | PUBLICATION
18112 : | QUOTE
18113 : | QUOTES
18114 : | RANGE
18115 : | READ
18116 : | REASSIGN
18117 : | RECURSIVE
18118 : | REF_P
18119 : | REFERENCING
18120 : | REFRESH
18121 : | REINDEX
18122 : | RELATIVE_P
18123 : | RELEASE
18124 : | RENAME
18125 : | REPEATABLE
18126 : | REPLACE
18127 : | REPLICA
18128 : | RESET
18129 : | RESPECT_P
18130 : | RESTART
18131 : | RESTRICT
18132 : | RETURN
18133 : | RETURNS
18134 : | REVOKE
18135 : | ROLE
18136 : | ROLLBACK
18137 : | ROLLUP
18138 : | ROUTINE
18139 : | ROUTINES
18140 : | ROWS
18141 : | RULE
18142 : | SAVEPOINT
18143 : | SCALAR
18144 : | SCHEMA
18145 : | SCHEMAS
18146 : | SCROLL
18147 : | SEARCH
18148 : | SECOND_P
18149 : | SECURITY
18150 : | SEQUENCE
18151 : | SEQUENCES
18152 : | SERIALIZABLE
18153 : | SERVER
18154 : | SESSION
18155 : | SET
18156 : | SETS
18157 : | SHARE
18158 : | SHOW
18159 : | SIMPLE
18160 : | SKIP
18161 : | SNAPSHOT
18162 : | SOURCE
18163 : | SPLIT
18164 : | SQL_P
18165 : | STABLE
18166 : | STANDALONE_P
18167 : | START
18168 : | STATEMENT
18169 : | STATISTICS
18170 : | STDIN
18171 : | STDOUT
18172 : | STORAGE
18173 : | STORED
18174 : | STRICT_P
18175 : | STRING_P
18176 : | STRIP_P
18177 : | SUBSCRIPTION
18178 : | SUPPORT
18179 : | SYSID
18180 : | SYSTEM_P
18181 : | TABLES
18182 : | TABLESPACE
18183 : | TARGET
18184 : | TEMP
18185 : | TEMPLATE
18186 : | TEMPORARY
18187 : | TEXT_P
18188 : | TIES
18189 : | TRANSACTION
18190 : | TRANSFORM
18191 : | TRIGGER
18192 : | TRUNCATE
18193 : | TRUSTED
18194 : | TYPE_P
18195 : | TYPES_P
18196 : | UESCAPE
18197 : | UNBOUNDED
18198 : | UNCOMMITTED
18199 : | UNCONDITIONAL
18200 : | UNENCRYPTED
18201 : | UNKNOWN
18202 : | UNLISTEN
18203 : | UNLOGGED
18204 : | UNTIL
18205 : | UPDATE
18206 : | VACUUM
18207 : | VALID
18208 : | VALIDATE
18209 : | VALIDATOR
18210 : | VALUE_P
18211 : | VARYING
18212 : | VERSION_P
18213 : | VIEW
18214 : | VIEWS
18215 : | VIRTUAL
18216 : | VOLATILE
18217 : | WAIT
18218 : | WHITESPACE_P
18219 : | WITHIN
18220 : | WITHOUT
18221 : | WORK
18222 : | WRAPPER
18223 : | WRITE
18224 : | XML_P
18225 : | YEAR_P
18226 : | YES_P
18227 : | ZONE
18228 : ;
18229 :
18230 : /* Column identifier --- keywords that can be column, table, etc names.
18231 : *
18232 : * Many of these keywords will in fact be recognized as type or function
18233 : * names too; but they have special productions for the purpose, and so
18234 : * can't be treated as "generic" type or function names.
18235 : *
18236 : * The type names appearing here are not usable as function names
18237 : * because they can be followed by '(' in typename productions, which
18238 : * looks too much like a function call for an LR(1) parser.
18239 : */
18240 : col_name_keyword:
18241 : BETWEEN
18242 : | BIGINT
18243 : | BIT
18244 : | BOOLEAN_P
18245 : | CHAR_P
18246 : | CHARACTER
18247 : | COALESCE
18248 : | DEC
18249 : | DECIMAL_P
18250 : | EXISTS
18251 : | EXTRACT
18252 : | FLOAT_P
18253 : | GREATEST
18254 : | GROUPING
18255 : | INOUT
18256 : | INT_P
18257 : | INTEGER
18258 : | INTERVAL
18259 : | JSON
18260 : | JSON_ARRAY
18261 : | JSON_ARRAYAGG
18262 : | JSON_EXISTS
18263 : | JSON_OBJECT
18264 : | JSON_OBJECTAGG
18265 : | JSON_QUERY
18266 : | JSON_SCALAR
18267 : | JSON_SERIALIZE
18268 : | JSON_TABLE
18269 : | JSON_VALUE
18270 : | LEAST
18271 : | MERGE_ACTION
18272 : | NATIONAL
18273 : | NCHAR
18274 : | NONE
18275 : | NORMALIZE
18276 : | NULLIF
18277 : | NUMERIC
18278 : | OUT_P
18279 : | OVERLAY
18280 : | POSITION
18281 : | PRECISION
18282 : | REAL
18283 : | ROW
18284 : | SETOF
18285 : | SMALLINT
18286 : | SUBSTRING
18287 : | TIME
18288 : | TIMESTAMP
18289 : | TREAT
18290 : | TRIM
18291 : | VALUES
18292 : | VARCHAR
18293 : | XMLATTRIBUTES
18294 : | XMLCONCAT
18295 : | XMLELEMENT
18296 : | XMLEXISTS
18297 : | XMLFOREST
18298 : | XMLNAMESPACES
18299 : | XMLPARSE
18300 : | XMLPI
18301 : | XMLROOT
18302 : | XMLSERIALIZE
18303 : | XMLTABLE
18304 : ;
18305 :
18306 : /* Type/function identifier --- keywords that can be type or function names.
18307 : *
18308 : * Most of these are keywords that are used as operators in expressions;
18309 : * in general such keywords can't be column names because they would be
18310 : * ambiguous with variables, but they are unambiguous as function identifiers.
18311 : *
18312 : * Do not include POSITION, SUBSTRING, etc here since they have explicit
18313 : * productions in a_expr to support the goofy SQL9x argument syntax.
18314 : * - thomas 2000-11-28
18315 : */
18316 : type_func_name_keyword:
18317 : AUTHORIZATION
18318 : | BINARY
18319 : | COLLATION
18320 : | CONCURRENTLY
18321 : | CROSS
18322 : | CURRENT_SCHEMA
18323 : | FREEZE
18324 : | FULL
18325 : | ILIKE
18326 : | INNER_P
18327 : | IS
18328 : | ISNULL
18329 : | JOIN
18330 : | LEFT
18331 : | LIKE
18332 : | NATURAL
18333 : | NOTNULL
18334 : | OUTER_P
18335 : | OVERLAPS
18336 : | RIGHT
18337 : | SIMILAR
18338 : | TABLESAMPLE
18339 : | VERBOSE
18340 : ;
18341 :
18342 : /* Reserved keyword --- these keywords are usable only as a ColLabel.
18343 : *
18344 : * Keywords appear here if they could not be distinguished from variable,
18345 : * type, or function names in some contexts. Don't put things here unless
18346 : * forced to.
18347 : */
18348 : reserved_keyword:
18349 : ALL
18350 : | ANALYSE
18351 : | ANALYZE
18352 : | AND
18353 : | ANY
18354 : | ARRAY
18355 : | AS
18356 : | ASC
18357 : | ASYMMETRIC
18358 : | BOTH
18359 : | CASE
18360 : | CAST
18361 : | CHECK
18362 : | COLLATE
18363 : | COLUMN
18364 : | CONSTRAINT
18365 : | CREATE
18366 : | CURRENT_CATALOG
18367 : | CURRENT_DATE
18368 : | CURRENT_ROLE
18369 : | CURRENT_TIME
18370 : | CURRENT_TIMESTAMP
18371 : | CURRENT_USER
18372 : | DEFAULT
18373 : | DEFERRABLE
18374 : | DESC
18375 : | DISTINCT
18376 : | DO
18377 : | ELSE
18378 : | END_P
18379 : | EXCEPT
18380 : | FALSE_P
18381 : | FETCH
18382 : | FOR
18383 : | FOREIGN
18384 : | FROM
18385 : | GRANT
18386 : | GROUP_P
18387 : | HAVING
18388 : | IN_P
18389 : | INITIALLY
18390 : | INTERSECT
18391 : | INTO
18392 : | LATERAL_P
18393 : | LEADING
18394 : | LIMIT
18395 : | LOCALTIME
18396 : | LOCALTIMESTAMP
18397 : | NOT
18398 : | NULL_P
18399 : | OFFSET
18400 : | ON
18401 : | ONLY
18402 : | OR
18403 : | ORDER
18404 : | PLACING
18405 : | PRIMARY
18406 : | REFERENCES
18407 : | RETURNING
18408 : | SELECT
18409 : | SESSION_USER
18410 : | SOME
18411 : | SYMMETRIC
18412 : | SYSTEM_USER
18413 : | TABLE
18414 : | THEN
18415 : | TO
18416 : | TRAILING
18417 : | TRUE_P
18418 : | UNION
18419 : | UNIQUE
18420 : | USER
18421 : | USING
18422 : | VARIADIC
18423 : | WHEN
18424 : | WHERE
18425 : | WINDOW
18426 : | WITH
18427 : ;
18428 :
18429 : /*
18430 : * While all keywords can be used as column labels when preceded by AS,
18431 : * not all of them can be used as a "bare" column label without AS.
18432 : * Those that can be used as a bare label must be listed here,
18433 : * in addition to appearing in one of the category lists above.
18434 : *
18435 : * Always add a new keyword to this list if possible. Mark it BARE_LABEL
18436 : * in kwlist.h if it is included here, or AS_LABEL if it is not.
18437 : */
18438 : bare_label_keyword:
18439 : ABORT_P
18440 : | ABSENT
18441 : | ABSOLUTE_P
18442 : | ACCESS
18443 : | ACTION
18444 : | ADD_P
18445 : | ADMIN
18446 : | AFTER
18447 : | AGGREGATE
18448 : | ALL
18449 : | ALSO
18450 : | ALTER
18451 : | ALWAYS
18452 : | ANALYSE
18453 : | ANALYZE
18454 : | AND
18455 : | ANY
18456 : | ASC
18457 : | ASENSITIVE
18458 : | ASSERTION
18459 : | ASSIGNMENT
18460 : | ASYMMETRIC
18461 : | AT
18462 : | ATOMIC
18463 : | ATTACH
18464 : | ATTRIBUTE
18465 : | AUTHORIZATION
18466 : | BACKWARD
18467 : | BEFORE
18468 : | BEGIN_P
18469 : | BETWEEN
18470 : | BIGINT
18471 : | BINARY
18472 : | BIT
18473 : | BOOLEAN_P
18474 : | BOTH
18475 : | BREADTH
18476 : | BY
18477 : | CACHE
18478 : | CALL
18479 : | CALLED
18480 : | CASCADE
18481 : | CASCADED
18482 : | CASE
18483 : | CAST
18484 : | CATALOG_P
18485 : | CHAIN
18486 : | CHARACTERISTICS
18487 : | CHECK
18488 : | CHECKPOINT
18489 : | CLASS
18490 : | CLOSE
18491 : | CLUSTER
18492 : | COALESCE
18493 : | COLLATE
18494 : | COLLATION
18495 : | COLUMN
18496 : | COLUMNS
18497 : | COMMENT
18498 : | COMMENTS
18499 : | COMMIT
18500 : | COMMITTED
18501 : | COMPRESSION
18502 : | CONCURRENTLY
18503 : | CONDITIONAL
18504 : | CONFIGURATION
18505 : | CONFLICT
18506 : | CONNECTION
18507 : | CONSTRAINT
18508 : | CONSTRAINTS
18509 : | CONTENT_P
18510 : | CONTINUE_P
18511 : | CONVERSION_P
18512 : | COPY
18513 : | COST
18514 : | CROSS
18515 : | CSV
18516 : | CUBE
18517 : | CURRENT_P
18518 : | CURRENT_CATALOG
18519 : | CURRENT_DATE
18520 : | CURRENT_ROLE
18521 : | CURRENT_SCHEMA
18522 : | CURRENT_TIME
18523 : | CURRENT_TIMESTAMP
18524 : | CURRENT_USER
18525 : | CURSOR
18526 : | CYCLE
18527 : | DATA_P
18528 : | DATABASE
18529 : | DEALLOCATE
18530 : | DEC
18531 : | DECIMAL_P
18532 : | DECLARE
18533 : | DEFAULT
18534 : | DEFAULTS
18535 : | DEFERRABLE
18536 : | DEFERRED
18537 : | DEFINER
18538 : | DELETE_P
18539 : | DELIMITER
18540 : | DELIMITERS
18541 : | DEPENDS
18542 : | DEPTH
18543 : | DESC
18544 : | DETACH
18545 : | DICTIONARY
18546 : | DISABLE_P
18547 : | DISCARD
18548 : | DISTINCT
18549 : | DO
18550 : | DOCUMENT_P
18551 : | DOMAIN_P
18552 : | DOUBLE_P
18553 : | DROP
18554 : | EACH
18555 : | ELSE
18556 : | EMPTY_P
18557 : | ENABLE_P
18558 : | ENCODING
18559 : | ENCRYPTED
18560 : | END_P
18561 : | ENFORCED
18562 : | ENUM_P
18563 : | ERROR_P
18564 : | ESCAPE
18565 : | EVENT
18566 : | EXCLUDE
18567 : | EXCLUDING
18568 : | EXCLUSIVE
18569 : | EXECUTE
18570 : | EXISTS
18571 : | EXPLAIN
18572 : | EXPRESSION
18573 : | EXTENSION
18574 : | EXTERNAL
18575 : | EXTRACT
18576 : | FALSE_P
18577 : | FAMILY
18578 : | FINALIZE
18579 : | FIRST_P
18580 : | FLOAT_P
18581 : | FOLLOWING
18582 : | FORCE
18583 : | FOREIGN
18584 : | FORMAT
18585 : | FORWARD
18586 : | FREEZE
18587 : | FULL
18588 : | FUNCTION
18589 : | FUNCTIONS
18590 : | GENERATED
18591 : | GLOBAL
18592 : | GRANTED
18593 : | GREATEST
18594 : | GROUPING
18595 : | GROUPS
18596 : | HANDLER
18597 : | HEADER_P
18598 : | HOLD
18599 : | IDENTITY_P
18600 : | IF_P
18601 : | ILIKE
18602 : | IMMEDIATE
18603 : | IMMUTABLE
18604 : | IMPLICIT_P
18605 : | IMPORT_P
18606 : | IN_P
18607 : | INCLUDE
18608 : | INCLUDING
18609 : | INCREMENT
18610 : | INDENT
18611 : | INDEX
18612 : | INDEXES
18613 : | INHERIT
18614 : | INHERITS
18615 : | INITIALLY
18616 : | INLINE_P
18617 : | INNER_P
18618 : | INOUT
18619 : | INPUT_P
18620 : | INSENSITIVE
18621 : | INSERT
18622 : | INSTEAD
18623 : | INT_P
18624 : | INTEGER
18625 : | INTERVAL
18626 : | INVOKER
18627 : | IS
18628 : | ISOLATION
18629 : | JOIN
18630 : | JSON
18631 : | JSON_ARRAY
18632 : | JSON_ARRAYAGG
18633 : | JSON_EXISTS
18634 : | JSON_OBJECT
18635 : | JSON_OBJECTAGG
18636 : | JSON_QUERY
18637 : | JSON_SCALAR
18638 : | JSON_SERIALIZE
18639 : | JSON_TABLE
18640 : | JSON_VALUE
18641 : | KEEP
18642 : | KEY
18643 : | KEYS
18644 : | LABEL
18645 : | LANGUAGE
18646 : | LARGE_P
18647 : | LAST_P
18648 : | LATERAL_P
18649 : | LEADING
18650 : | LEAKPROOF
18651 : | LEAST
18652 : | LEFT
18653 : | LEVEL
18654 : | LIKE
18655 : | LISTEN
18656 : | LOAD
18657 : | LOCAL
18658 : | LOCALTIME
18659 : | LOCALTIMESTAMP
18660 : | LOCATION
18661 : | LOCK_P
18662 : | LOCKED
18663 : | LOGGED
18664 : | LSN_P
18665 : | MAPPING
18666 : | MATCH
18667 : | MATCHED
18668 : | MATERIALIZED
18669 : | MAXVALUE
18670 : | MERGE
18671 : | MERGE_ACTION
18672 : | METHOD
18673 : | MINVALUE
18674 : | MODE
18675 : | MOVE
18676 : | NAME_P
18677 : | NAMES
18678 : | NATIONAL
18679 : | NATURAL
18680 : | NCHAR
18681 : | NESTED
18682 : | NEW
18683 : | NEXT
18684 : | NFC
18685 : | NFD
18686 : | NFKC
18687 : | NFKD
18688 : | NO
18689 : | NONE
18690 : | NORMALIZE
18691 : | NORMALIZED
18692 : | NOT
18693 : | NOTHING
18694 : | NOTIFY
18695 : | NOWAIT
18696 : | NULL_P
18697 : | NULLIF
18698 : | NULLS_P
18699 : | NUMERIC
18700 : | OBJECT_P
18701 : | OBJECTS_P
18702 : | OF
18703 : | OFF
18704 : | OIDS
18705 : | OLD
18706 : | OMIT
18707 : | ONLY
18708 : | OPERATOR
18709 : | OPTION
18710 : | OPTIONS
18711 : | OR
18712 : | ORDINALITY
18713 : | OTHERS
18714 : | OUT_P
18715 : | OUTER_P
18716 : | OVERLAY
18717 : | OVERRIDING
18718 : | OWNED
18719 : | OWNER
18720 : | PARALLEL
18721 : | PARAMETER
18722 : | PARSER
18723 : | PARTIAL
18724 : | PARTITION
18725 : | PARTITIONS
18726 : | PASSING
18727 : | PASSWORD
18728 : | PATH
18729 : | PERIOD
18730 : | PLACING
18731 : | PLAN
18732 : | PLANS
18733 : | POLICY
18734 : | POSITION
18735 : | PRECEDING
18736 : | PREPARE
18737 : | PREPARED
18738 : | PRESERVE
18739 : | PRIMARY
18740 : | PRIOR
18741 : | PRIVILEGES
18742 : | PROCEDURAL
18743 : | PROCEDURE
18744 : | PROCEDURES
18745 : | PROGRAM
18746 : | PUBLICATION
18747 : | QUOTE
18748 : | QUOTES
18749 : | RANGE
18750 : | READ
18751 : | REAL
18752 : | REASSIGN
18753 : | RECURSIVE
18754 : | REF_P
18755 : | REFERENCES
18756 : | REFERENCING
18757 : | REFRESH
18758 : | REINDEX
18759 : | RELATIVE_P
18760 : | RELEASE
18761 : | RENAME
18762 : | REPEATABLE
18763 : | REPLACE
18764 : | REPLICA
18765 : | RESET
18766 : | RESTART
18767 : | RESTRICT
18768 : | RETURN
18769 : | RETURNS
18770 : | REVOKE
18771 : | RIGHT
18772 : | ROLE
18773 : | ROLLBACK
18774 : | ROLLUP
18775 : | ROUTINE
18776 : | ROUTINES
18777 : | ROW
18778 : | ROWS
18779 : | RULE
18780 : | SAVEPOINT
18781 : | SCALAR
18782 : | SCHEMA
18783 : | SCHEMAS
18784 : | SCROLL
18785 : | SEARCH
18786 : | SECURITY
18787 : | SELECT
18788 : | SEQUENCE
18789 : | SEQUENCES
18790 : | SERIALIZABLE
18791 : | SERVER
18792 : | SESSION
18793 : | SESSION_USER
18794 : | SET
18795 : | SETOF
18796 : | SETS
18797 : | SHARE
18798 : | SHOW
18799 : | SIMILAR
18800 : | SIMPLE
18801 : | SKIP
18802 : | SMALLINT
18803 : | SNAPSHOT
18804 : | SOME
18805 : | SOURCE
18806 : | SPLIT
18807 : | SQL_P
18808 : | STABLE
18809 : | STANDALONE_P
18810 : | START
18811 : | STATEMENT
18812 : | STATISTICS
18813 : | STDIN
18814 : | STDOUT
18815 : | STORAGE
18816 : | STORED
18817 : | STRICT_P
18818 : | STRING_P
18819 : | STRIP_P
18820 : | SUBSCRIPTION
18821 : | SUBSTRING
18822 : | SUPPORT
18823 : | SYMMETRIC
18824 : | SYSID
18825 : | SYSTEM_P
18826 : | SYSTEM_USER
18827 : | TABLE
18828 : | TABLES
18829 : | TABLESAMPLE
18830 : | TABLESPACE
18831 : | TARGET
18832 : | TEMP
18833 : | TEMPLATE
18834 : | TEMPORARY
18835 : | TEXT_P
18836 : | THEN
18837 : | TIES
18838 : | TIME
18839 : | TIMESTAMP
18840 : | TRAILING
18841 : | TRANSACTION
18842 : | TRANSFORM
18843 : | TREAT
18844 : | TRIGGER
18845 : | TRIM
18846 : | TRUE_P
18847 : | TRUNCATE
18848 : | TRUSTED
18849 : | TYPE_P
18850 : | TYPES_P
18851 : | UESCAPE
18852 : | UNBOUNDED
18853 : | UNCOMMITTED
18854 : | UNCONDITIONAL
18855 : | UNENCRYPTED
18856 : | UNIQUE
18857 : | UNKNOWN
18858 : | UNLISTEN
18859 : | UNLOGGED
18860 : | UNTIL
18861 : | UPDATE
18862 : | USER
18863 : | USING
18864 : | VACUUM
18865 : | VALID
18866 : | VALIDATE
18867 : | VALIDATOR
18868 : | VALUE_P
18869 : | VALUES
18870 : | VARCHAR
18871 : | VARIADIC
18872 : | VERBOSE
18873 : | VERSION_P
18874 : | VIEW
18875 : | VIEWS
18876 : | VIRTUAL
18877 : | VOLATILE
18878 : | WAIT
18879 : | WHEN
18880 : | WHITESPACE_P
18881 : | WORK
18882 : | WRAPPER
18883 : | WRITE
18884 : | XML_P
18885 : | XMLATTRIBUTES
18886 : | XMLCONCAT
18887 : | XMLELEMENT
18888 : | XMLEXISTS
18889 : | XMLFOREST
18890 : | XMLNAMESPACES
18891 : | XMLPARSE
18892 : | XMLPI
18893 : | XMLROOT
18894 : | XMLSERIALIZE
18895 : | XMLTABLE
18896 : | YES_P
18897 : | ZONE
18898 : ;
18899 :
18900 : %%
18901 :
18902 : /*
18903 : * The signature of this function is required by bison. However, we
18904 : * ignore the passed yylloc and instead use the last token position
18905 : * available from the scanner.
18906 : */
18907 : static void
18908 706 : base_yyerror(YYLTYPE *yylloc, core_yyscan_t yyscanner, const char *msg)
18909 : {
18910 706 : parser_yyerror(msg);
18911 : }
18912 :
18913 : static RawStmt *
18914 847988 : makeRawStmt(Node *stmt, int stmt_location)
18915 : {
18916 847988 : RawStmt *rs = makeNode(RawStmt);
18917 :
18918 847988 : rs->stmt = stmt;
18919 847988 : rs->stmt_location = stmt_location;
18920 847988 : rs->stmt_len = 0; /* might get changed later */
18921 847988 : return rs;
18922 : }
18923 :
18924 : /* Adjust a RawStmt to reflect that it doesn't run to the end of the string */
18925 : static void
18926 615802 : updateRawStmtEnd(RawStmt *rs, int end_location)
18927 : {
18928 : /*
18929 : * If we already set the length, don't change it. This is for situations
18930 : * like "select foo ;; select bar" where the same statement will be last
18931 : * in the string for more than one semicolon.
18932 : */
18933 615802 : if (rs->stmt_len > 0)
18934 674 : return;
18935 :
18936 : /* OK, update length of RawStmt */
18937 615128 : rs->stmt_len = end_location - rs->stmt_location;
18938 : }
18939 :
18940 : static Node *
18941 1843294 : makeColumnRef(char *colname, List *indirection,
18942 : int location, core_yyscan_t yyscanner)
18943 : {
18944 : /*
18945 : * Generate a ColumnRef node, with an A_Indirection node added if there is
18946 : * any subscripting in the specified indirection list. However, any field
18947 : * selection at the start of the indirection list must be transposed into
18948 : * the "fields" part of the ColumnRef node.
18949 : */
18950 1843294 : ColumnRef *c = makeNode(ColumnRef);
18951 1843294 : int nfields = 0;
18952 : ListCell *l;
18953 :
18954 1843294 : c->location = location;
18955 2914462 : foreach(l, indirection)
18956 : {
18957 1081370 : if (IsA(lfirst(l), A_Indices))
18958 : {
18959 10202 : A_Indirection *i = makeNode(A_Indirection);
18960 :
18961 10202 : if (nfields == 0)
18962 : {
18963 : /* easy case - all indirection goes to A_Indirection */
18964 7410 : c->fields = list_make1(makeString(colname));
18965 7410 : i->indirection = check_indirection(indirection, yyscanner);
18966 : }
18967 : else
18968 : {
18969 : /* got to split the list in two */
18970 2792 : i->indirection = check_indirection(list_copy_tail(indirection,
18971 : nfields),
18972 : yyscanner);
18973 2792 : indirection = list_truncate(indirection, nfields);
18974 2792 : c->fields = lcons(makeString(colname), indirection);
18975 : }
18976 10202 : i->arg = (Node *) c;
18977 10202 : return (Node *) i;
18978 : }
18979 1071168 : else if (IsA(lfirst(l), A_Star))
18980 : {
18981 : /* We only allow '*' at the end of a ColumnRef */
18982 5618 : if (lnext(indirection, l) != NULL)
18983 0 : parser_yyerror("improper use of \"*\"");
18984 : }
18985 1071168 : nfields++;
18986 : }
18987 : /* No subscripting, so all indirection gets added to field list */
18988 1833092 : c->fields = lcons(makeString(colname), indirection);
18989 1833092 : return (Node *) c;
18990 : }
18991 :
18992 : static Node *
18993 318996 : makeTypeCast(Node *arg, TypeName *typename, int location)
18994 : {
18995 318996 : TypeCast *n = makeNode(TypeCast);
18996 :
18997 318996 : n->arg = arg;
18998 318996 : n->typeName = typename;
18999 318996 : n->location = location;
19000 318996 : return (Node *) n;
19001 : }
19002 :
19003 : static Node *
19004 16334 : makeStringConstCast(char *str, int location, TypeName *typename)
19005 : {
19006 16334 : Node *s = makeStringConst(str, location);
19007 :
19008 16334 : return makeTypeCast(s, typename, -1);
19009 : }
19010 :
19011 : static Node *
19012 405960 : makeIntConst(int val, int location)
19013 : {
19014 405960 : A_Const *n = makeNode(A_Const);
19015 :
19016 405960 : n->val.ival.type = T_Integer;
19017 405960 : n->val.ival.ival = val;
19018 405960 : n->location = location;
19019 :
19020 405960 : return (Node *) n;
19021 : }
19022 :
19023 : static Node *
19024 12264 : makeFloatConst(char *str, int location)
19025 : {
19026 12264 : A_Const *n = makeNode(A_Const);
19027 :
19028 12264 : n->val.fval.type = T_Float;
19029 12264 : n->val.fval.fval = str;
19030 12264 : n->location = location;
19031 :
19032 12264 : return (Node *) n;
19033 : }
19034 :
19035 : static Node *
19036 67646 : makeBoolAConst(bool state, int location)
19037 : {
19038 67646 : A_Const *n = makeNode(A_Const);
19039 :
19040 67646 : n->val.boolval.type = T_Boolean;
19041 67646 : n->val.boolval.boolval = state;
19042 67646 : n->location = location;
19043 :
19044 67646 : return (Node *) n;
19045 : }
19046 :
19047 : static Node *
19048 4056 : makeBitStringConst(char *str, int location)
19049 : {
19050 4056 : A_Const *n = makeNode(A_Const);
19051 :
19052 4056 : n->val.bsval.type = T_BitString;
19053 4056 : n->val.bsval.bsval = str;
19054 4056 : n->location = location;
19055 :
19056 4056 : return (Node *) n;
19057 : }
19058 :
19059 : static Node *
19060 69192 : makeNullAConst(int location)
19061 : {
19062 69192 : A_Const *n = makeNode(A_Const);
19063 :
19064 69192 : n->isnull = true;
19065 69192 : n->location = location;
19066 :
19067 69192 : return (Node *) n;
19068 : }
19069 :
19070 : static Node *
19071 5470 : makeAConst(Node *v, int location)
19072 : {
19073 : Node *n;
19074 :
19075 5470 : switch (v->type)
19076 : {
19077 218 : case T_Float:
19078 218 : n = makeFloatConst(castNode(Float, v)->fval, location);
19079 218 : break;
19080 :
19081 5252 : case T_Integer:
19082 5252 : n = makeIntConst(castNode(Integer, v)->ival, location);
19083 5252 : break;
19084 :
19085 0 : default:
19086 : /* currently not used */
19087 : Assert(false);
19088 0 : n = NULL;
19089 : }
19090 :
19091 5470 : return n;
19092 : }
19093 :
19094 : /* makeRoleSpec
19095 : * Create a RoleSpec with the given type
19096 : */
19097 : static RoleSpec *
19098 34362 : makeRoleSpec(RoleSpecType type, int location)
19099 : {
19100 34362 : RoleSpec *spec = makeNode(RoleSpec);
19101 :
19102 34362 : spec->roletype = type;
19103 34362 : spec->location = location;
19104 :
19105 34362 : return spec;
19106 : }
19107 :
19108 : /* check_qualified_name --- check the result of qualified_name production
19109 : *
19110 : * It's easiest to let the grammar production for qualified_name allow
19111 : * subscripts and '*', which we then must reject here.
19112 : */
19113 : static void
19114 247936 : check_qualified_name(List *names, core_yyscan_t yyscanner)
19115 : {
19116 : ListCell *i;
19117 :
19118 495872 : foreach(i, names)
19119 : {
19120 247936 : if (!IsA(lfirst(i), String))
19121 0 : parser_yyerror("syntax error");
19122 : }
19123 247936 : }
19124 :
19125 : /* check_func_name --- check the result of func_name production
19126 : *
19127 : * It's easiest to let the grammar production for func_name allow subscripts
19128 : * and '*', which we then must reject here.
19129 : */
19130 : static List *
19131 128488 : check_func_name(List *names, core_yyscan_t yyscanner)
19132 : {
19133 : ListCell *i;
19134 :
19135 385464 : foreach(i, names)
19136 : {
19137 256976 : if (!IsA(lfirst(i), String))
19138 0 : parser_yyerror("syntax error");
19139 : }
19140 128488 : return names;
19141 : }
19142 :
19143 : /* check_indirection --- check the result of indirection production
19144 : *
19145 : * We only allow '*' at the end of the list, but it's hard to enforce that
19146 : * in the grammar, so do it here.
19147 : */
19148 : static List *
19149 84726 : check_indirection(List *indirection, core_yyscan_t yyscanner)
19150 : {
19151 : ListCell *l;
19152 :
19153 112912 : foreach(l, indirection)
19154 : {
19155 28186 : if (IsA(lfirst(l), A_Star))
19156 : {
19157 1508 : if (lnext(indirection, l) != NULL)
19158 0 : parser_yyerror("improper use of \"*\"");
19159 : }
19160 : }
19161 84726 : return indirection;
19162 : }
19163 :
19164 : /* extractArgTypes()
19165 : * Given a list of FunctionParameter nodes, extract a list of just the
19166 : * argument types (TypeNames) for input parameters only. This is what
19167 : * is needed to look up an existing function, which is what is wanted by
19168 : * the productions that use this call.
19169 : */
19170 : static List *
19171 18612 : extractArgTypes(List *parameters)
19172 : {
19173 18612 : List *result = NIL;
19174 : ListCell *i;
19175 :
19176 42658 : foreach(i, parameters)
19177 : {
19178 24046 : FunctionParameter *p = (FunctionParameter *) lfirst(i);
19179 :
19180 24046 : if (p->mode != FUNC_PARAM_OUT && p->mode != FUNC_PARAM_TABLE)
19181 23890 : result = lappend(result, p->argType);
19182 : }
19183 18612 : return result;
19184 : }
19185 :
19186 : /* extractAggrArgTypes()
19187 : * As above, but work from the output of the aggr_args production.
19188 : */
19189 : static List *
19190 362 : extractAggrArgTypes(List *aggrargs)
19191 : {
19192 : Assert(list_length(aggrargs) == 2);
19193 362 : return extractArgTypes((List *) linitial(aggrargs));
19194 : }
19195 :
19196 : /* makeOrderedSetArgs()
19197 : * Build the result of the aggr_args production (which see the comments for).
19198 : * This handles only the case where both given lists are nonempty, so that
19199 : * we have to deal with multiple VARIADIC arguments.
19200 : */
19201 : static List *
19202 32 : makeOrderedSetArgs(List *directargs, List *orderedargs,
19203 : core_yyscan_t yyscanner)
19204 : {
19205 32 : FunctionParameter *lastd = (FunctionParameter *) llast(directargs);
19206 : Integer *ndirectargs;
19207 :
19208 : /* No restriction unless last direct arg is VARIADIC */
19209 32 : if (lastd->mode == FUNC_PARAM_VARIADIC)
19210 : {
19211 16 : FunctionParameter *firsto = (FunctionParameter *) linitial(orderedargs);
19212 :
19213 : /*
19214 : * We ignore the names, though the aggr_arg production allows them; it
19215 : * doesn't allow default values, so those need not be checked.
19216 : */
19217 16 : if (list_length(orderedargs) != 1 ||
19218 16 : firsto->mode != FUNC_PARAM_VARIADIC ||
19219 16 : !equal(lastd->argType, firsto->argType))
19220 0 : ereport(ERROR,
19221 : (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
19222 : errmsg("an ordered-set aggregate with a VARIADIC direct argument must have one VARIADIC aggregated argument of the same data type"),
19223 : parser_errposition(firsto->location)));
19224 :
19225 : /* OK, drop the duplicate VARIADIC argument from the internal form */
19226 16 : orderedargs = NIL;
19227 : }
19228 :
19229 : /* don't merge into the next line, as list_concat changes directargs */
19230 32 : ndirectargs = makeInteger(list_length(directargs));
19231 :
19232 32 : return list_make2(list_concat(directargs, orderedargs),
19233 : ndirectargs);
19234 : }
19235 :
19236 : /* insertSelectOptions()
19237 : * Insert ORDER BY, etc into an already-constructed SelectStmt.
19238 : *
19239 : * This routine is just to avoid duplicating code in SelectStmt productions.
19240 : */
19241 : static void
19242 90566 : insertSelectOptions(SelectStmt *stmt,
19243 : List *sortClause, List *lockingClause,
19244 : SelectLimit *limitClause,
19245 : WithClause *withClause,
19246 : core_yyscan_t yyscanner)
19247 : {
19248 : Assert(IsA(stmt, SelectStmt));
19249 :
19250 : /*
19251 : * Tests here are to reject constructs like
19252 : * (SELECT foo ORDER BY bar) ORDER BY baz
19253 : */
19254 90566 : if (sortClause)
19255 : {
19256 75458 : if (stmt->sortClause)
19257 0 : ereport(ERROR,
19258 : (errcode(ERRCODE_SYNTAX_ERROR),
19259 : errmsg("multiple ORDER BY clauses not allowed"),
19260 : parser_errposition(exprLocation((Node *) sortClause))));
19261 75458 : stmt->sortClause = sortClause;
19262 : }
19263 : /* We can handle multiple locking clauses, though */
19264 90566 : stmt->lockingClause = list_concat(stmt->lockingClause, lockingClause);
19265 90566 : if (limitClause && limitClause->limitOffset)
19266 : {
19267 862 : if (stmt->limitOffset)
19268 0 : ereport(ERROR,
19269 : (errcode(ERRCODE_SYNTAX_ERROR),
19270 : errmsg("multiple OFFSET clauses not allowed"),
19271 : parser_errposition(limitClause->offsetLoc)));
19272 862 : stmt->limitOffset = limitClause->limitOffset;
19273 : }
19274 90566 : if (limitClause && limitClause->limitCount)
19275 : {
19276 4746 : if (stmt->limitCount)
19277 0 : ereport(ERROR,
19278 : (errcode(ERRCODE_SYNTAX_ERROR),
19279 : errmsg("multiple LIMIT clauses not allowed"),
19280 : parser_errposition(limitClause->countLoc)));
19281 4746 : stmt->limitCount = limitClause->limitCount;
19282 : }
19283 90566 : if (limitClause)
19284 : {
19285 : /* If there was a conflict, we must have detected it above */
19286 : Assert(!stmt->limitOption);
19287 5214 : if (!stmt->sortClause && limitClause->limitOption == LIMIT_OPTION_WITH_TIES)
19288 6 : ereport(ERROR,
19289 : (errcode(ERRCODE_SYNTAX_ERROR),
19290 : errmsg("WITH TIES cannot be specified without ORDER BY clause"),
19291 : parser_errposition(limitClause->optionLoc)));
19292 5208 : if (limitClause->limitOption == LIMIT_OPTION_WITH_TIES && stmt->lockingClause)
19293 : {
19294 : ListCell *lc;
19295 :
19296 6 : foreach(lc, stmt->lockingClause)
19297 : {
19298 6 : LockingClause *lock = lfirst_node(LockingClause, lc);
19299 :
19300 6 : if (lock->waitPolicy == LockWaitSkip)
19301 6 : ereport(ERROR,
19302 : (errcode(ERRCODE_SYNTAX_ERROR),
19303 : errmsg("%s and %s options cannot be used together",
19304 : "SKIP LOCKED", "WITH TIES"),
19305 : parser_errposition(limitClause->optionLoc)));
19306 : }
19307 : }
19308 5202 : stmt->limitOption = limitClause->limitOption;
19309 : }
19310 90554 : if (withClause)
19311 : {
19312 2918 : if (stmt->withClause)
19313 0 : ereport(ERROR,
19314 : (errcode(ERRCODE_SYNTAX_ERROR),
19315 : errmsg("multiple WITH clauses not allowed"),
19316 : parser_errposition(exprLocation((Node *) withClause))));
19317 2918 : stmt->withClause = withClause;
19318 : }
19319 90554 : }
19320 :
19321 : static Node *
19322 20124 : makeSetOp(SetOperation op, bool all, Node *larg, Node *rarg)
19323 : {
19324 20124 : SelectStmt *n = makeNode(SelectStmt);
19325 :
19326 20124 : n->op = op;
19327 20124 : n->all = all;
19328 20124 : n->larg = (SelectStmt *) larg;
19329 20124 : n->rarg = (SelectStmt *) rarg;
19330 20124 : return (Node *) n;
19331 : }
19332 :
19333 : /* SystemFuncName()
19334 : * Build a properly-qualified reference to a built-in function.
19335 : */
19336 : List *
19337 19818 : SystemFuncName(char *name)
19338 : {
19339 19818 : return list_make2(makeString("pg_catalog"), makeString(name));
19340 : }
19341 :
19342 : /* SystemTypeName()
19343 : * Build a properly-qualified reference to a built-in type.
19344 : *
19345 : * typmod is defaulted, but may be changed afterwards by caller.
19346 : * Likewise for the location.
19347 : */
19348 : TypeName *
19349 123816 : SystemTypeName(char *name)
19350 : {
19351 123816 : return makeTypeNameFromNameList(list_make2(makeString("pg_catalog"),
19352 : makeString(name)));
19353 : }
19354 :
19355 : /* doNegate()
19356 : * Handle negation of a numeric constant.
19357 : *
19358 : * Formerly, we did this here because the optimizer couldn't cope with
19359 : * indexquals that looked like "var = -4" --- it wants "var = const"
19360 : * and a unary minus operator applied to a constant didn't qualify.
19361 : * As of Postgres 7.0, that problem doesn't exist anymore because there
19362 : * is a constant-subexpression simplifier in the optimizer. However,
19363 : * there's still a good reason for doing this here, which is that we can
19364 : * postpone committing to a particular internal representation for simple
19365 : * negative constants. It's better to leave "-123.456" in string form
19366 : * until we know what the desired type is.
19367 : */
19368 : static Node *
19369 9398 : doNegate(Node *n, int location)
19370 : {
19371 9398 : if (IsA(n, A_Const))
19372 : {
19373 8388 : A_Const *con = (A_Const *) n;
19374 :
19375 : /* report the constant's location as that of the '-' sign */
19376 8388 : con->location = location;
19377 :
19378 8388 : if (IsA(&con->val, Integer))
19379 : {
19380 7430 : con->val.ival.ival = -con->val.ival.ival;
19381 7430 : return n;
19382 : }
19383 958 : if (IsA(&con->val, Float))
19384 : {
19385 958 : doNegateFloat(&con->val.fval);
19386 958 : return n;
19387 : }
19388 : }
19389 :
19390 1010 : return (Node *) makeSimpleA_Expr(AEXPR_OP, "-", NULL, n, location);
19391 : }
19392 :
19393 : static void
19394 978 : doNegateFloat(Float *v)
19395 : {
19396 978 : char *oldval = v->fval;
19397 :
19398 978 : if (*oldval == '+')
19399 0 : oldval++;
19400 978 : if (*oldval == '-')
19401 0 : v->fval = oldval + 1; /* just strip the '-' */
19402 : else
19403 978 : v->fval = psprintf("-%s", oldval);
19404 978 : }
19405 :
19406 : static Node *
19407 236004 : makeAndExpr(Node *lexpr, Node *rexpr, int location)
19408 : {
19409 : /* Flatten "a AND b AND c ..." to a single BoolExpr on sight */
19410 236004 : if (IsA(lexpr, BoolExpr))
19411 : {
19412 111850 : BoolExpr *blexpr = (BoolExpr *) lexpr;
19413 :
19414 111850 : if (blexpr->boolop == AND_EXPR)
19415 : {
19416 109302 : blexpr->args = lappend(blexpr->args, rexpr);
19417 109302 : return (Node *) blexpr;
19418 : }
19419 : }
19420 126702 : return (Node *) makeBoolExpr(AND_EXPR, list_make2(lexpr, rexpr), location);
19421 : }
19422 :
19423 : static Node *
19424 16292 : makeOrExpr(Node *lexpr, Node *rexpr, int location)
19425 : {
19426 : /* Flatten "a OR b OR c ..." to a single BoolExpr on sight */
19427 16292 : if (IsA(lexpr, BoolExpr))
19428 : {
19429 5756 : BoolExpr *blexpr = (BoolExpr *) lexpr;
19430 :
19431 5756 : if (blexpr->boolop == OR_EXPR)
19432 : {
19433 4192 : blexpr->args = lappend(blexpr->args, rexpr);
19434 4192 : return (Node *) blexpr;
19435 : }
19436 : }
19437 12100 : return (Node *) makeBoolExpr(OR_EXPR, list_make2(lexpr, rexpr), location);
19438 : }
19439 :
19440 : static Node *
19441 16566 : makeNotExpr(Node *expr, int location)
19442 : {
19443 16566 : return (Node *) makeBoolExpr(NOT_EXPR, list_make1(expr), location);
19444 : }
19445 :
19446 : static Node *
19447 8266 : makeAArrayExpr(List *elements, int location, int location_end)
19448 : {
19449 8266 : A_ArrayExpr *n = makeNode(A_ArrayExpr);
19450 :
19451 8266 : n->elements = elements;
19452 8266 : n->location = location;
19453 8266 : n->list_start = location;
19454 8266 : n->list_end = location_end;
19455 8266 : return (Node *) n;
19456 : }
19457 :
19458 : static Node *
19459 2788 : makeSQLValueFunction(SQLValueFunctionOp op, int32 typmod, int location)
19460 : {
19461 2788 : SQLValueFunction *svf = makeNode(SQLValueFunction);
19462 :
19463 2788 : svf->op = op;
19464 : /* svf->type will be filled during parse analysis */
19465 2788 : svf->typmod = typmod;
19466 2788 : svf->location = location;
19467 2788 : return (Node *) svf;
19468 : }
19469 :
19470 : static Node *
19471 596 : makeXmlExpr(XmlExprOp op, char *name, List *named_args, List *args,
19472 : int location)
19473 : {
19474 596 : XmlExpr *x = makeNode(XmlExpr);
19475 :
19476 596 : x->op = op;
19477 596 : x->name = name;
19478 :
19479 : /*
19480 : * named_args is a list of ResTarget; it'll be split apart into separate
19481 : * expression and name lists in transformXmlExpr().
19482 : */
19483 596 : x->named_args = named_args;
19484 596 : x->arg_names = NIL;
19485 596 : x->args = args;
19486 : /* xmloption, if relevant, must be filled in by caller */
19487 : /* type and typmod will be filled in during parse analysis */
19488 596 : x->type = InvalidOid; /* marks the node as not analyzed */
19489 596 : x->location = location;
19490 596 : return (Node *) x;
19491 : }
19492 :
19493 : /*
19494 : * Merge the input and output parameters of a table function.
19495 : */
19496 : static List *
19497 194 : mergeTableFuncParameters(List *func_args, List *columns, core_yyscan_t yyscanner)
19498 : {
19499 : ListCell *lc;
19500 :
19501 : /* Explicit OUT and INOUT parameters shouldn't be used in this syntax */
19502 394 : foreach(lc, func_args)
19503 : {
19504 200 : FunctionParameter *p = (FunctionParameter *) lfirst(lc);
19505 :
19506 200 : if (p->mode != FUNC_PARAM_DEFAULT &&
19507 0 : p->mode != FUNC_PARAM_IN &&
19508 0 : p->mode != FUNC_PARAM_VARIADIC)
19509 0 : ereport(ERROR,
19510 : (errcode(ERRCODE_SYNTAX_ERROR),
19511 : errmsg("OUT and INOUT arguments aren't allowed in TABLE functions"),
19512 : parser_errposition(p->location)));
19513 : }
19514 :
19515 194 : return list_concat(func_args, columns);
19516 : }
19517 :
19518 : /*
19519 : * Determine return type of a TABLE function. A single result column
19520 : * returns setof that column's type; otherwise return setof record.
19521 : */
19522 : static TypeName *
19523 194 : TableFuncTypeName(List *columns)
19524 : {
19525 : TypeName *result;
19526 :
19527 194 : if (list_length(columns) == 1)
19528 : {
19529 62 : FunctionParameter *p = (FunctionParameter *) linitial(columns);
19530 :
19531 62 : result = copyObject(p->argType);
19532 : }
19533 : else
19534 132 : result = SystemTypeName("record");
19535 :
19536 194 : result->setof = true;
19537 :
19538 194 : return result;
19539 : }
19540 :
19541 : /*
19542 : * Convert a list of (dotted) names to a RangeVar (like
19543 : * makeRangeVarFromNameList, but with position support). The
19544 : * "AnyName" refers to the any_name production in the grammar.
19545 : */
19546 : static RangeVar *
19547 4736 : makeRangeVarFromAnyName(List *names, int position, core_yyscan_t yyscanner)
19548 : {
19549 4736 : RangeVar *r = makeNode(RangeVar);
19550 :
19551 4736 : switch (list_length(names))
19552 : {
19553 4646 : case 1:
19554 4646 : r->catalogname = NULL;
19555 4646 : r->schemaname = NULL;
19556 4646 : r->relname = strVal(linitial(names));
19557 4646 : break;
19558 90 : case 2:
19559 90 : r->catalogname = NULL;
19560 90 : r->schemaname = strVal(linitial(names));
19561 90 : r->relname = strVal(lsecond(names));
19562 90 : break;
19563 0 : case 3:
19564 0 : r->catalogname = strVal(linitial(names));
19565 0 : r->schemaname = strVal(lsecond(names));
19566 0 : r->relname = strVal(lthird(names));
19567 0 : break;
19568 0 : default:
19569 0 : ereport(ERROR,
19570 : (errcode(ERRCODE_SYNTAX_ERROR),
19571 : errmsg("improper qualified name (too many dotted names): %s",
19572 : NameListToString(names)),
19573 : parser_errposition(position)));
19574 : break;
19575 : }
19576 :
19577 4736 : r->relpersistence = RELPERSISTENCE_PERMANENT;
19578 4736 : r->location = position;
19579 :
19580 4736 : return r;
19581 : }
19582 :
19583 : /*
19584 : * Convert a relation_name with name and namelist to a RangeVar using
19585 : * makeRangeVar.
19586 : */
19587 : static RangeVar *
19588 247936 : makeRangeVarFromQualifiedName(char *name, List *namelist, int location,
19589 : core_yyscan_t yyscanner)
19590 : {
19591 : RangeVar *r;
19592 :
19593 247936 : check_qualified_name(namelist, yyscanner);
19594 247936 : r = makeRangeVar(NULL, NULL, location);
19595 :
19596 247936 : switch (list_length(namelist))
19597 : {
19598 247936 : case 1:
19599 247936 : r->catalogname = NULL;
19600 247936 : r->schemaname = name;
19601 247936 : r->relname = strVal(linitial(namelist));
19602 247936 : break;
19603 0 : case 2:
19604 0 : r->catalogname = name;
19605 0 : r->schemaname = strVal(linitial(namelist));
19606 0 : r->relname = strVal(lsecond(namelist));
19607 0 : break;
19608 0 : default:
19609 0 : ereport(ERROR,
19610 : errcode(ERRCODE_SYNTAX_ERROR),
19611 : errmsg("improper qualified name (too many dotted names): %s",
19612 : NameListToString(lcons(makeString(name), namelist))),
19613 : parser_errposition(location));
19614 : break;
19615 : }
19616 :
19617 247936 : return r;
19618 : }
19619 :
19620 : /* Separate Constraint nodes from COLLATE clauses in a ColQualList */
19621 : static void
19622 72034 : SplitColQualList(List *qualList,
19623 : List **constraintList, CollateClause **collClause,
19624 : core_yyscan_t yyscanner)
19625 : {
19626 : ListCell *cell;
19627 :
19628 72034 : *collClause = NULL;
19629 92708 : foreach(cell, qualList)
19630 : {
19631 20674 : Node *n = (Node *) lfirst(cell);
19632 :
19633 20674 : if (IsA(n, Constraint))
19634 : {
19635 : /* keep it in list */
19636 19896 : continue;
19637 : }
19638 778 : if (IsA(n, CollateClause))
19639 : {
19640 778 : CollateClause *c = (CollateClause *) n;
19641 :
19642 778 : if (*collClause)
19643 0 : ereport(ERROR,
19644 : (errcode(ERRCODE_SYNTAX_ERROR),
19645 : errmsg("multiple COLLATE clauses not allowed"),
19646 : parser_errposition(c->location)));
19647 778 : *collClause = c;
19648 : }
19649 : else
19650 0 : elog(ERROR, "unexpected node type %d", (int) n->type);
19651 : /* remove non-Constraint nodes from qualList */
19652 778 : qualList = foreach_delete_current(qualList, cell);
19653 : }
19654 72034 : *constraintList = qualList;
19655 72034 : }
19656 :
19657 : /*
19658 : * Process result of ConstraintAttributeSpec, and set appropriate bool flags
19659 : * in the output command node. Pass NULL for any flags the particular
19660 : * command doesn't support.
19661 : */
19662 : static void
19663 18202 : processCASbits(int cas_bits, int location, const char *constrType,
19664 : bool *deferrable, bool *initdeferred, bool *is_enforced,
19665 : bool *not_valid, bool *no_inherit, core_yyscan_t yyscanner)
19666 : {
19667 : /* defaults */
19668 18202 : if (deferrable)
19669 16070 : *deferrable = false;
19670 18202 : if (initdeferred)
19671 16070 : *initdeferred = false;
19672 18202 : if (not_valid)
19673 3970 : *not_valid = false;
19674 18202 : if (is_enforced)
19675 3492 : *is_enforced = true;
19676 :
19677 18202 : if (cas_bits & (CAS_DEFERRABLE | CAS_INITIALLY_DEFERRED))
19678 : {
19679 230 : if (deferrable)
19680 230 : *deferrable = true;
19681 : else
19682 0 : ereport(ERROR,
19683 : (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
19684 : /* translator: %s is CHECK, UNIQUE, or similar */
19685 : errmsg("%s constraints cannot be marked DEFERRABLE",
19686 : constrType),
19687 : parser_errposition(location)));
19688 : }
19689 :
19690 18202 : if (cas_bits & CAS_INITIALLY_DEFERRED)
19691 : {
19692 146 : if (initdeferred)
19693 146 : *initdeferred = true;
19694 : else
19695 0 : ereport(ERROR,
19696 : (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
19697 : /* translator: %s is CHECK, UNIQUE, or similar */
19698 : errmsg("%s constraints cannot be marked DEFERRABLE",
19699 : constrType),
19700 : parser_errposition(location)));
19701 : }
19702 :
19703 18202 : if (cas_bits & CAS_NOT_VALID)
19704 : {
19705 744 : if (not_valid)
19706 744 : *not_valid = true;
19707 : else
19708 0 : ereport(ERROR,
19709 : (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
19710 : /* translator: %s is CHECK, UNIQUE, or similar */
19711 : errmsg("%s constraints cannot be marked NOT VALID",
19712 : constrType),
19713 : parser_errposition(location)));
19714 : }
19715 :
19716 18202 : if (cas_bits & CAS_NO_INHERIT)
19717 : {
19718 244 : if (no_inherit)
19719 244 : *no_inherit = true;
19720 : else
19721 0 : ereport(ERROR,
19722 : (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
19723 : /* translator: %s is CHECK, UNIQUE, or similar */
19724 : errmsg("%s constraints cannot be marked NO INHERIT",
19725 : constrType),
19726 : parser_errposition(location)));
19727 : }
19728 :
19729 18202 : if (cas_bits & CAS_NOT_ENFORCED)
19730 : {
19731 174 : if (is_enforced)
19732 168 : *is_enforced = false;
19733 : else
19734 6 : ereport(ERROR,
19735 : (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
19736 : /* translator: %s is CHECK, UNIQUE, or similar */
19737 : errmsg("%s constraints cannot be marked NOT ENFORCED",
19738 : constrType),
19739 : parser_errposition(location)));
19740 :
19741 : /*
19742 : * NB: The validated status is irrelevant when the constraint is set to
19743 : * NOT ENFORCED, but for consistency, it should be set accordingly.
19744 : * This ensures that if the constraint is later changed to ENFORCED, it
19745 : * will automatically be in the correct NOT VALIDATED state.
19746 : */
19747 168 : if (not_valid)
19748 132 : *not_valid = true;
19749 : }
19750 :
19751 18196 : if (cas_bits & CAS_ENFORCED)
19752 : {
19753 108 : if (is_enforced)
19754 102 : *is_enforced = true;
19755 : else
19756 6 : ereport(ERROR,
19757 : (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
19758 : /* translator: %s is CHECK, UNIQUE, or similar */
19759 : errmsg("%s constraints cannot be marked ENFORCED",
19760 : constrType),
19761 : parser_errposition(location)));
19762 : }
19763 18190 : }
19764 :
19765 : /*
19766 : * Parse a user-supplied partition strategy string into parse node
19767 : * PartitionStrategy representation, or die trying.
19768 : */
19769 : static PartitionStrategy
19770 5598 : parsePartitionStrategy(char *strategy, int location, core_yyscan_t yyscanner)
19771 : {
19772 5598 : if (pg_strcasecmp(strategy, "list") == 0)
19773 2624 : return PARTITION_STRATEGY_LIST;
19774 2974 : else if (pg_strcasecmp(strategy, "range") == 0)
19775 2690 : return PARTITION_STRATEGY_RANGE;
19776 284 : else if (pg_strcasecmp(strategy, "hash") == 0)
19777 278 : return PARTITION_STRATEGY_HASH;
19778 :
19779 6 : ereport(ERROR,
19780 : (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
19781 : errmsg("unrecognized partitioning strategy \"%s\"", strategy),
19782 : parser_errposition(location)));
19783 : return PARTITION_STRATEGY_LIST; /* keep compiler quiet */
19784 :
19785 : }
19786 :
19787 : /*
19788 : * Process all_objects_list to set all_tables and/or all_sequences.
19789 : * Also, checks if the pub_object_type has been specified more than once.
19790 : */
19791 : static void
19792 150 : preprocess_pub_all_objtype_list(List *all_objects_list, bool *all_tables,
19793 : bool *all_sequences, core_yyscan_t yyscanner)
19794 : {
19795 150 : if (!all_objects_list)
19796 0 : return;
19797 :
19798 150 : *all_tables = false;
19799 150 : *all_sequences = false;
19800 :
19801 464 : foreach_ptr(PublicationAllObjSpec, obj, all_objects_list)
19802 : {
19803 188 : if (obj->pubobjtype == PUBLICATION_ALL_TABLES)
19804 : {
19805 130 : if (*all_tables)
19806 6 : ereport(ERROR,
19807 : errcode(ERRCODE_SYNTAX_ERROR),
19808 : errmsg("invalid publication object list"),
19809 : errdetail("ALL TABLES can be specified only once."),
19810 : parser_errposition(obj->location));
19811 :
19812 124 : *all_tables = true;
19813 : }
19814 58 : else if (obj->pubobjtype == PUBLICATION_ALL_SEQUENCES)
19815 : {
19816 58 : if (*all_sequences)
19817 6 : ereport(ERROR,
19818 : errcode(ERRCODE_SYNTAX_ERROR),
19819 : errmsg("invalid publication object list"),
19820 : errdetail("ALL SEQUENCES can be specified only once."),
19821 : parser_errposition(obj->location));
19822 :
19823 52 : *all_sequences = true;
19824 : }
19825 : }
19826 : }
19827 :
19828 : /*
19829 : * Process pubobjspec_list to check for errors in any of the objects and
19830 : * convert PUBLICATIONOBJ_CONTINUATION into appropriate PublicationObjSpecType.
19831 : */
19832 : static void
19833 1650 : preprocess_pubobj_list(List *pubobjspec_list, core_yyscan_t yyscanner)
19834 : {
19835 : ListCell *cell;
19836 : PublicationObjSpec *pubobj;
19837 1650 : PublicationObjSpecType prevobjtype = PUBLICATIONOBJ_CONTINUATION;
19838 :
19839 1650 : if (!pubobjspec_list)
19840 0 : return;
19841 :
19842 1650 : pubobj = (PublicationObjSpec *) linitial(pubobjspec_list);
19843 1650 : if (pubobj->pubobjtype == PUBLICATIONOBJ_CONTINUATION)
19844 12 : ereport(ERROR,
19845 : errcode(ERRCODE_SYNTAX_ERROR),
19846 : errmsg("invalid publication object list"),
19847 : errdetail("One of TABLE or TABLES IN SCHEMA must be specified before a standalone table or schema name."),
19848 : parser_errposition(pubobj->location));
19849 :
19850 3508 : foreach(cell, pubobjspec_list)
19851 : {
19852 1894 : pubobj = (PublicationObjSpec *) lfirst(cell);
19853 :
19854 1894 : if (pubobj->pubobjtype == PUBLICATIONOBJ_CONTINUATION)
19855 176 : pubobj->pubobjtype = prevobjtype;
19856 :
19857 1894 : if (pubobj->pubobjtype == PUBLICATIONOBJ_TABLE)
19858 : {
19859 : /* relation name or pubtable must be set for this type of object */
19860 1450 : if (!pubobj->name && !pubobj->pubtable)
19861 6 : ereport(ERROR,
19862 : errcode(ERRCODE_SYNTAX_ERROR),
19863 : errmsg("invalid table name"),
19864 : parser_errposition(pubobj->location));
19865 :
19866 1444 : if (pubobj->name)
19867 : {
19868 : /* convert it to PublicationTable */
19869 60 : PublicationTable *pubtable = makeNode(PublicationTable);
19870 :
19871 60 : pubtable->relation =
19872 60 : makeRangeVar(NULL, pubobj->name, pubobj->location);
19873 60 : pubobj->pubtable = pubtable;
19874 60 : pubobj->name = NULL;
19875 : }
19876 : }
19877 444 : else if (pubobj->pubobjtype == PUBLICATIONOBJ_TABLES_IN_SCHEMA ||
19878 24 : pubobj->pubobjtype == PUBLICATIONOBJ_TABLES_IN_CUR_SCHEMA)
19879 : {
19880 : /* WHERE clause is not allowed on a schema object */
19881 444 : if (pubobj->pubtable && pubobj->pubtable->whereClause)
19882 6 : ereport(ERROR,
19883 : errcode(ERRCODE_SYNTAX_ERROR),
19884 : errmsg("WHERE clause not allowed for schema"),
19885 : parser_errposition(pubobj->location));
19886 :
19887 : /* Column list is not allowed on a schema object */
19888 438 : if (pubobj->pubtable && pubobj->pubtable->columns)
19889 6 : ereport(ERROR,
19890 : errcode(ERRCODE_SYNTAX_ERROR),
19891 : errmsg("column specification not allowed for schema"),
19892 : parser_errposition(pubobj->location));
19893 :
19894 : /*
19895 : * We can distinguish between the different type of schema objects
19896 : * based on whether name and pubtable is set.
19897 : */
19898 432 : if (pubobj->name)
19899 402 : pubobj->pubobjtype = PUBLICATIONOBJ_TABLES_IN_SCHEMA;
19900 30 : else if (!pubobj->name && !pubobj->pubtable)
19901 24 : pubobj->pubobjtype = PUBLICATIONOBJ_TABLES_IN_CUR_SCHEMA;
19902 : else
19903 6 : ereport(ERROR,
19904 : errcode(ERRCODE_SYNTAX_ERROR),
19905 : errmsg("invalid schema name"),
19906 : parser_errposition(pubobj->location));
19907 : }
19908 :
19909 1870 : prevobjtype = pubobj->pubobjtype;
19910 : }
19911 : }
19912 :
19913 : /*----------
19914 : * Recursive view transformation
19915 : *
19916 : * Convert
19917 : *
19918 : * CREATE RECURSIVE VIEW relname (aliases) AS query
19919 : *
19920 : * to
19921 : *
19922 : * CREATE VIEW relname (aliases) AS
19923 : * WITH RECURSIVE relname (aliases) AS (query)
19924 : * SELECT aliases FROM relname
19925 : *
19926 : * Actually, just the WITH ... part, which is then inserted into the original
19927 : * view definition as the query.
19928 : * ----------
19929 : */
19930 : static Node *
19931 14 : makeRecursiveViewSelect(char *relname, List *aliases, Node *query)
19932 : {
19933 14 : SelectStmt *s = makeNode(SelectStmt);
19934 14 : WithClause *w = makeNode(WithClause);
19935 14 : CommonTableExpr *cte = makeNode(CommonTableExpr);
19936 14 : List *tl = NIL;
19937 : ListCell *lc;
19938 :
19939 : /* create common table expression */
19940 14 : cte->ctename = relname;
19941 14 : cte->aliascolnames = aliases;
19942 14 : cte->ctematerialized = CTEMaterializeDefault;
19943 14 : cte->ctequery = query;
19944 14 : cte->location = -1;
19945 :
19946 : /* create WITH clause and attach CTE */
19947 14 : w->recursive = true;
19948 14 : w->ctes = list_make1(cte);
19949 14 : w->location = -1;
19950 :
19951 : /*
19952 : * create target list for the new SELECT from the alias list of the
19953 : * recursive view specification
19954 : */
19955 28 : foreach(lc, aliases)
19956 : {
19957 14 : ResTarget *rt = makeNode(ResTarget);
19958 :
19959 14 : rt->name = NULL;
19960 14 : rt->indirection = NIL;
19961 14 : rt->val = makeColumnRef(strVal(lfirst(lc)), NIL, -1, 0);
19962 14 : rt->location = -1;
19963 :
19964 14 : tl = lappend(tl, rt);
19965 : }
19966 :
19967 : /*
19968 : * create new SELECT combining WITH clause, target list, and fake FROM
19969 : * clause
19970 : */
19971 14 : s->withClause = w;
19972 14 : s->targetList = tl;
19973 14 : s->fromClause = list_make1(makeRangeVar(NULL, relname, -1));
19974 :
19975 14 : return (Node *) s;
19976 : }
19977 :
19978 : /* parser_init()
19979 : * Initialize to parse one query string
19980 : */
19981 : void
19982 800964 : parser_init(base_yy_extra_type *yyext)
19983 : {
19984 800964 : yyext->parsetree = NIL; /* in case grammar forgets to set it */
19985 800964 : }
|