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 : RoleSpec *rolespec;
266 : PublicationObjSpec *publicationobjectspec;
267 : PublicationAllObjSpec *publicationallobjectspec;
268 : struct SelectLimit *selectlimit;
269 : SetQuantifier setquantifier;
270 : struct GroupClause *groupclause;
271 : MergeMatchKind mergematch;
272 : MergeWhenClause *mergewhen;
273 : struct KeyActions *keyactions;
274 : struct KeyAction *keyaction;
275 : ReturningClause *retclause;
276 : ReturningOptionKind retoptionkind;
277 : }
278 :
279 : %type <node> stmt toplevel_stmt schema_stmt routine_body_stmt
280 : AlterEventTrigStmt AlterCollationStmt
281 : AlterDatabaseStmt AlterDatabaseSetStmt AlterDomainStmt AlterEnumStmt
282 : AlterFdwStmt AlterForeignServerStmt AlterGroupStmt
283 : AlterObjectDependsStmt AlterObjectSchemaStmt AlterOwnerStmt
284 : AlterOperatorStmt AlterTypeStmt AlterSeqStmt AlterSystemStmt AlterTableStmt
285 : AlterTblSpcStmt AlterExtensionStmt AlterExtensionContentsStmt
286 : AlterCompositeTypeStmt AlterUserMappingStmt
287 : AlterRoleStmt AlterRoleSetStmt AlterPolicyStmt AlterStatsStmt
288 : AlterDefaultPrivilegesStmt DefACLAction
289 : AnalyzeStmt CallStmt ClosePortalStmt ClusterStmt CommentStmt
290 : ConstraintsSetStmt CopyStmt CreateAsStmt CreateCastStmt
291 : CreateDomainStmt CreateExtensionStmt CreateGroupStmt CreateOpClassStmt
292 : CreateOpFamilyStmt AlterOpFamilyStmt CreatePLangStmt
293 : CreateSchemaStmt CreateSeqStmt CreateStmt CreateStatsStmt CreateTableSpaceStmt
294 : CreateFdwStmt CreateForeignServerStmt CreateForeignTableStmt
295 : CreateAssertionStmt CreateTransformStmt CreateTrigStmt CreateEventTrigStmt
296 : CreateUserStmt CreateUserMappingStmt CreateRoleStmt CreatePolicyStmt
297 : CreatedbStmt DeclareCursorStmt DefineStmt DeleteStmt DiscardStmt DoStmt
298 : DropOpClassStmt DropOpFamilyStmt DropStmt
299 : DropCastStmt DropRoleStmt
300 : DropdbStmt DropTableSpaceStmt
301 : DropTransformStmt
302 : DropUserMappingStmt ExplainStmt FetchStmt
303 : GrantStmt GrantRoleStmt ImportForeignSchemaStmt IndexStmt InsertStmt
304 : ListenStmt LoadStmt LockStmt MergeStmt NotifyStmt ExplainableStmt PreparableStmt
305 : CreateFunctionStmt AlterFunctionStmt ReindexStmt RemoveAggrStmt
306 : RemoveFuncStmt RemoveOperStmt RenameStmt ReturnStmt RevokeStmt RevokeRoleStmt
307 : RuleActionStmt RuleActionStmtOrEmpty RuleStmt
308 : SecLabelStmt SelectStmt TransactionStmt TransactionStmtLegacy TruncateStmt
309 : UnlistenStmt UpdateStmt VacuumStmt
310 : VariableResetStmt VariableSetStmt VariableShowStmt
311 : ViewStmt WaitStmt CheckPointStmt CreateConversionStmt
312 : DeallocateStmt PrepareStmt ExecuteStmt
313 : DropOwnedStmt ReassignOwnedStmt
314 : AlterTSConfigurationStmt AlterTSDictionaryStmt
315 : CreateMatViewStmt RefreshMatViewStmt CreateAmStmt
316 : CreatePublicationStmt AlterPublicationStmt
317 : CreateSubscriptionStmt AlterSubscriptionStmt DropSubscriptionStmt
318 :
319 : %type <node> select_no_parens select_with_parens select_clause
320 : simple_select values_clause
321 : PLpgSQL_Expr PLAssignStmt
322 :
323 : %type <str> opt_single_name
324 : %type <list> opt_qualified_name
325 : %type <boolean> opt_concurrently
326 : %type <dbehavior> opt_drop_behavior
327 : %type <list> opt_utility_option_list
328 : %type <list> opt_wait_with_clause
329 : %type <list> utility_option_list
330 : %type <defelt> utility_option_elem
331 : %type <str> utility_option_name
332 : %type <node> utility_option_arg
333 :
334 : %type <node> alter_column_default opclass_item opclass_drop alter_using
335 : %type <ival> add_drop opt_asc_desc opt_nulls_order
336 :
337 : %type <node> alter_table_cmd alter_type_cmd opt_collate_clause
338 : replica_identity partition_cmd index_partition_cmd
339 : %type <list> alter_table_cmds alter_type_cmds
340 : %type <list> alter_identity_column_option_list
341 : %type <defelt> alter_identity_column_option
342 : %type <node> set_statistics_value
343 : %type <str> set_access_method_name
344 :
345 : %type <list> createdb_opt_list createdb_opt_items copy_opt_list
346 : transaction_mode_list
347 : create_extension_opt_list alter_extension_opt_list
348 : %type <defelt> createdb_opt_item copy_opt_item
349 : transaction_mode_item
350 : create_extension_opt_item alter_extension_opt_item
351 :
352 : %type <ival> opt_lock lock_type cast_context
353 : %type <defelt> drop_option
354 : %type <boolean> opt_or_replace opt_no
355 : opt_grant_grant_option
356 : opt_nowait opt_if_exists opt_with_data
357 : opt_transaction_chain
358 : %type <list> grant_role_opt_list
359 : %type <defelt> grant_role_opt
360 : %type <node> grant_role_opt_value
361 : %type <ival> opt_nowait_or_skip
362 :
363 : %type <list> OptRoleList AlterOptRoleList
364 : %type <defelt> CreateOptRoleElem AlterOptRoleElem
365 :
366 : %type <str> opt_type
367 : %type <str> foreign_server_version opt_foreign_server_version
368 : %type <str> opt_in_database
369 :
370 : %type <str> parameter_name
371 : %type <list> OptSchemaEltList parameter_name_list
372 :
373 : %type <chr> am_type
374 :
375 : %type <boolean> TriggerForSpec TriggerForType
376 : %type <ival> TriggerActionTime
377 : %type <list> TriggerEvents TriggerOneEvent
378 : %type <node> TriggerFuncArg
379 : %type <node> TriggerWhen
380 : %type <str> TransitionRelName
381 : %type <boolean> TransitionRowOrTable TransitionOldOrNew
382 : %type <node> TriggerTransition
383 :
384 : %type <list> event_trigger_when_list event_trigger_value_list
385 : %type <defelt> event_trigger_when_item
386 : %type <chr> enable_trigger
387 :
388 : %type <str> copy_file_name
389 : access_method_clause attr_name
390 : table_access_method_clause name cursor_name file_name
391 : cluster_index_specification
392 :
393 : %type <list> func_name handler_name qual_Op qual_all_Op subquery_Op
394 : opt_inline_handler opt_validator validator_clause
395 : opt_collate
396 :
397 : %type <range> qualified_name insert_target OptConstrFromTable
398 :
399 : %type <str> all_Op MathOp
400 :
401 : %type <str> row_security_cmd RowSecurityDefaultForCmd
402 : %type <boolean> RowSecurityDefaultPermissive
403 : %type <node> RowSecurityOptionalWithCheck RowSecurityOptionalExpr
404 : %type <list> RowSecurityDefaultToRole RowSecurityOptionalToRole
405 :
406 : %type <str> iso_level opt_encoding
407 : %type <rolespec> grantee
408 : %type <list> grantee_list
409 : %type <accesspriv> privilege
410 : %type <list> privileges privilege_list
411 : %type <privtarget> privilege_target
412 : %type <objwithargs> function_with_argtypes aggregate_with_argtypes operator_with_argtypes
413 : %type <list> function_with_argtypes_list aggregate_with_argtypes_list operator_with_argtypes_list
414 : %type <ival> defacl_privilege_target
415 : %type <defelt> DefACLOption
416 : %type <list> DefACLOptionList
417 : %type <ival> import_qualification_type
418 : %type <importqual> import_qualification
419 : %type <node> vacuum_relation
420 : %type <selectlimit> opt_select_limit select_limit limit_clause
421 :
422 : %type <list> parse_toplevel stmtmulti routine_body_stmt_list
423 : OptTableElementList TableElementList OptInherit definition
424 : OptTypedTableElementList TypedTableElementList
425 : reloptions opt_reloptions
426 : OptWith opt_definition func_args func_args_list
427 : func_args_with_defaults func_args_with_defaults_list
428 : aggr_args aggr_args_list
429 : func_as createfunc_opt_list opt_createfunc_opt_list alterfunc_opt_list
430 : old_aggr_definition old_aggr_list
431 : oper_argtypes RuleActionList RuleActionMulti
432 : opt_column_list columnList opt_name_list
433 : sort_clause opt_sort_clause sortby_list index_params
434 : stats_params
435 : opt_include opt_c_include index_including_params
436 : name_list role_list from_clause from_list opt_array_bounds
437 : qualified_name_list any_name any_name_list type_name_list
438 : any_operator expr_list attrs
439 : distinct_clause opt_distinct_clause
440 : target_list opt_target_list insert_column_list set_target_list
441 : merge_values_clause
442 : set_clause_list set_clause
443 : def_list operator_def_list indirection opt_indirection
444 : reloption_list TriggerFuncArgs opclass_item_list opclass_drop_list
445 : opclass_purpose opt_opfamily transaction_mode_list_or_empty
446 : OptTableFuncElementList TableFuncElementList opt_type_modifiers
447 : prep_type_clause
448 : execute_param_clause using_clause
449 : returning_with_clause returning_options
450 : opt_enum_val_list enum_val_list table_func_column_list
451 : create_generic_options alter_generic_options
452 : relation_expr_list dostmt_opt_list
453 : transform_element_list transform_type_list
454 : TriggerTransitions TriggerReferencing
455 : vacuum_relation_list opt_vacuum_relation_list
456 : drop_option_list pub_obj_list pub_all_obj_type_list
457 :
458 : %type <retclause> returning_clause
459 : %type <node> returning_option
460 : %type <retoptionkind> returning_option_kind
461 : %type <node> opt_routine_body
462 : %type <groupclause> group_clause
463 : %type <list> group_by_list
464 : %type <node> group_by_item empty_grouping_set rollup_clause cube_clause
465 : %type <node> grouping_sets_clause
466 :
467 : %type <list> opt_fdw_options fdw_options
468 : %type <defelt> fdw_option
469 :
470 : %type <range> OptTempTableName
471 : %type <into> into_clause create_as_target create_mv_target
472 :
473 : %type <defelt> createfunc_opt_item common_func_opt_item dostmt_opt_item
474 : %type <fun_param> func_arg func_arg_with_default table_func_column aggr_arg
475 : %type <fun_param_mode> arg_class
476 : %type <typnam> func_return func_type
477 :
478 : %type <boolean> opt_trusted opt_restart_seqs
479 : %type <ival> OptTemp
480 : %type <ival> OptNoLog
481 : %type <oncommit> OnCommitOption
482 :
483 : %type <ival> for_locking_strength
484 : %type <node> for_locking_item
485 : %type <list> for_locking_clause opt_for_locking_clause for_locking_items
486 : %type <list> locked_rels_list
487 : %type <setquantifier> set_quantifier
488 :
489 : %type <node> join_qual
490 : %type <jtype> join_type
491 :
492 : %type <list> extract_list overlay_list position_list
493 : %type <list> substr_list trim_list
494 : %type <list> opt_interval interval_second
495 : %type <str> unicode_normal_form
496 :
497 : %type <boolean> opt_instead
498 : %type <boolean> opt_unique opt_verbose opt_full
499 : %type <boolean> opt_freeze opt_analyze opt_default
500 : %type <defelt> opt_binary copy_delimiter
501 :
502 : %type <boolean> copy_from opt_program
503 :
504 : %type <ival> event cursor_options opt_hold opt_set_data
505 : %type <objtype> object_type_any_name object_type_name object_type_name_on_any_name
506 : drop_type_name
507 :
508 : %type <node> fetch_args select_limit_value
509 : offset_clause select_offset_value
510 : select_fetch_first_value I_or_F_const
511 : %type <ival> row_or_rows first_or_next
512 :
513 : %type <list> OptSeqOptList SeqOptList OptParenthesizedSeqOptList
514 : %type <defelt> SeqOptElem
515 :
516 : %type <istmt> insert_rest
517 : %type <infer> opt_conf_expr
518 : %type <onconflict> opt_on_conflict
519 : %type <mergewhen> merge_insert merge_update merge_delete
520 :
521 : %type <mergematch> merge_when_tgt_matched merge_when_tgt_not_matched
522 : %type <node> merge_when_clause opt_merge_when_condition
523 : %type <list> merge_when_list
524 :
525 : %type <vsetstmt> generic_set set_rest set_rest_more generic_reset reset_rest
526 : SetResetClause FunctionSetResetClause
527 :
528 : %type <node> TableElement TypedTableElement ConstraintElem DomainConstraintElem TableFuncElement
529 : %type <node> columnDef columnOptions optionalPeriodName
530 : %type <defelt> def_elem reloption_elem old_aggr_elem operator_def_elem
531 : %type <node> def_arg columnElem where_clause where_or_current_clause
532 : a_expr b_expr c_expr AexprConst indirection_el opt_slice_bound
533 : columnref having_clause func_table xmltable array_expr
534 : OptWhereClause operator_def_arg
535 : %type <list> opt_column_and_period_list
536 : %type <list> rowsfrom_item rowsfrom_list opt_col_def_list
537 : %type <boolean> opt_ordinality opt_without_overlaps
538 : %type <list> ExclusionConstraintList ExclusionConstraintElem
539 : %type <list> func_arg_list func_arg_list_opt
540 : %type <node> func_arg_expr
541 : %type <list> row explicit_row implicit_row type_list array_expr_list
542 : %type <node> case_expr case_arg when_clause case_default
543 : %type <list> when_clause_list
544 : %type <node> opt_search_clause opt_cycle_clause
545 : %type <ival> sub_type opt_materialized
546 : %type <node> NumericOnly
547 : %type <list> NumericOnly_list
548 : %type <alias> alias_clause opt_alias_clause opt_alias_clause_for_join_using
549 : %type <list> func_alias_clause
550 : %type <sortby> sortby
551 : %type <ielem> index_elem index_elem_options
552 : %type <selem> stats_param
553 : %type <node> table_ref
554 : %type <jexpr> joined_table
555 : %type <range> relation_expr
556 : %type <range> extended_relation_expr
557 : %type <range> relation_expr_opt_alias
558 : %type <node> tablesample_clause opt_repeatable_clause
559 : %type <target> target_el set_target insert_column_item
560 :
561 : %type <str> generic_option_name
562 : %type <node> generic_option_arg
563 : %type <defelt> generic_option_elem alter_generic_option_elem
564 : %type <list> generic_option_list alter_generic_option_list
565 :
566 : %type <ival> reindex_target_relation reindex_target_all
567 :
568 : %type <node> copy_generic_opt_arg copy_generic_opt_arg_list_item
569 : %type <defelt> copy_generic_opt_elem
570 : %type <list> copy_generic_opt_list copy_generic_opt_arg_list
571 : %type <list> copy_options
572 :
573 : %type <typnam> Typename SimpleTypename ConstTypename
574 : GenericType Numeric opt_float JsonType
575 : Character ConstCharacter
576 : CharacterWithLength CharacterWithoutLength
577 : ConstDatetime ConstInterval
578 : Bit ConstBit BitWithLength BitWithoutLength
579 : %type <str> character
580 : %type <str> extract_arg
581 : %type <boolean> opt_varying opt_timezone opt_no_inherit
582 :
583 : %type <ival> Iconst SignedIconst
584 : %type <str> Sconst comment_text notify_payload
585 : %type <str> RoleId opt_boolean_or_string
586 : %type <list> var_list
587 : %type <str> ColId ColLabel BareColLabel
588 : %type <str> NonReservedWord NonReservedWord_or_Sconst
589 : %type <str> var_name type_function_name param_name
590 : %type <str> createdb_opt_name plassign_target
591 : %type <node> var_value zone_value
592 : %type <rolespec> auth_ident RoleSpec opt_granted_by
593 : %type <publicationobjectspec> PublicationObjSpec
594 : %type <publicationallobjectspec> PublicationAllObjSpec
595 :
596 : %type <keyword> unreserved_keyword type_func_name_keyword
597 : %type <keyword> col_name_keyword reserved_keyword
598 : %type <keyword> bare_label_keyword
599 :
600 : %type <node> DomainConstraint TableConstraint TableLikeClause
601 : %type <ival> TableLikeOptionList TableLikeOption
602 : %type <str> column_compression opt_column_compression column_storage opt_column_storage
603 : %type <list> ColQualList
604 : %type <node> ColConstraint ColConstraintElem ConstraintAttr
605 : %type <ival> key_match
606 : %type <keyaction> key_delete key_update key_action
607 : %type <keyactions> key_actions
608 : %type <ival> ConstraintAttributeSpec ConstraintAttributeElem
609 : %type <str> ExistingIndex
610 :
611 : %type <list> constraints_set_list
612 : %type <boolean> constraints_set_mode
613 : %type <str> OptTableSpace OptConsTableSpace
614 : %type <rolespec> OptTableSpaceOwner
615 : %type <ival> opt_check_option
616 :
617 : %type <str> opt_provider security_label
618 :
619 : %type <target> xml_attribute_el
620 : %type <list> xml_attribute_list xml_attributes
621 : %type <node> xml_root_version opt_xml_root_standalone
622 : %type <node> xmlexists_argument
623 : %type <ival> document_or_content
624 : %type <boolean> xml_indent_option xml_whitespace_option
625 : %type <list> xmltable_column_list xmltable_column_option_list
626 : %type <node> xmltable_column_el
627 : %type <defelt> xmltable_column_option_el
628 : %type <list> xml_namespace_list
629 : %type <target> xml_namespace_el
630 :
631 : %type <node> func_application func_expr_common_subexpr
632 : %type <node> func_expr func_expr_windowless
633 : %type <node> common_table_expr
634 : %type <with> with_clause opt_with_clause
635 : %type <list> cte_list
636 :
637 : %type <list> within_group_clause
638 : %type <node> filter_clause
639 : %type <list> window_clause window_definition_list opt_partition_clause
640 : %type <windef> window_definition over_clause window_specification
641 : opt_frame_clause frame_extent frame_bound
642 : %type <ival> null_treatment opt_window_exclusion_clause
643 : %type <str> opt_existing_window_name
644 : %type <boolean> opt_if_not_exists
645 : %type <boolean> opt_unique_null_treatment
646 : %type <ival> generated_when override_kind opt_virtual_or_stored
647 : %type <partspec> PartitionSpec OptPartitionSpec
648 : %type <partelem> part_elem
649 : %type <list> part_params
650 : %type <partboundspec> PartitionBoundSpec
651 : %type <list> hash_partbound
652 : %type <defelt> hash_partbound_elem
653 :
654 : %type <node> json_format_clause
655 : json_format_clause_opt
656 : json_value_expr
657 : json_returning_clause_opt
658 : json_name_and_value
659 : json_aggregate_func
660 : json_argument
661 : json_behavior
662 : json_on_error_clause_opt
663 : json_table
664 : json_table_column_definition
665 : json_table_column_path_clause_opt
666 : %type <list> json_name_and_value_list
667 : json_value_expr_list
668 : json_array_aggregate_order_by_clause_opt
669 : json_arguments
670 : json_behavior_clause_opt
671 : json_passing_clause_opt
672 : json_table_column_definition_list
673 : %type <str> json_table_path_name_opt
674 : %type <ival> json_behavior_type
675 : json_predicate_type_constraint
676 : json_quotes_clause_opt
677 : json_wrapper_behavior
678 : %type <boolean> json_key_uniqueness_constraint_opt
679 : json_object_constructor_null_clause_opt
680 : json_array_constructor_null_clause_opt
681 :
682 : /*
683 : * Non-keyword token types. These are hard-wired into the "flex" lexer.
684 : * They must be listed first so that their numeric codes do not depend on
685 : * the set of keywords. PL/pgSQL depends on this so that it can share the
686 : * same lexer. If you add/change tokens here, fix PL/pgSQL to match!
687 : *
688 : * UIDENT and USCONST are reduced to IDENT and SCONST in parser.c, so that
689 : * they need no productions here; but we must assign token codes to them.
690 : *
691 : * DOT_DOT is unused in the core SQL grammar, and so will always provoke
692 : * parse errors. It is needed by PL/pgSQL.
693 : */
694 : %token <str> IDENT UIDENT FCONST SCONST USCONST BCONST XCONST Op
695 : %token <ival> ICONST PARAM
696 : %token TYPECAST DOT_DOT COLON_EQUALS EQUALS_GREATER
697 : %token LESS_EQUALS GREATER_EQUALS NOT_EQUALS
698 :
699 : /*
700 : * If you want to make any keyword changes, update the keyword table in
701 : * src/include/parser/kwlist.h and add new keywords to the appropriate one
702 : * of the reserved-or-not-so-reserved keyword lists, below; search
703 : * this file for "Keyword category lists".
704 : */
705 :
706 : /* ordinary key words in alphabetical order */
707 : %token <keyword> ABORT_P ABSENT ABSOLUTE_P ACCESS ACTION ADD_P ADMIN AFTER
708 : AGGREGATE ALL ALSO ALTER ALWAYS ANALYSE ANALYZE AND ANY ARRAY AS ASC
709 : ASENSITIVE ASSERTION ASSIGNMENT ASYMMETRIC ATOMIC AT ATTACH ATTRIBUTE AUTHORIZATION
710 :
711 : BACKWARD BEFORE BEGIN_P BETWEEN BIGINT BINARY BIT
712 : BOOLEAN_P BOTH BREADTH BY
713 :
714 : CACHE CALL CALLED CASCADE CASCADED CASE CAST CATALOG_P CHAIN CHAR_P
715 : CHARACTER CHARACTERISTICS CHECK CHECKPOINT CLASS CLOSE
716 : CLUSTER COALESCE COLLATE COLLATION COLUMN COLUMNS COMMENT COMMENTS COMMIT
717 : COMMITTED COMPRESSION CONCURRENTLY CONDITIONAL CONFIGURATION CONFLICT
718 : CONNECTION CONSTRAINT CONSTRAINTS CONTENT_P CONTINUE_P CONVERSION_P COPY
719 : COST CREATE CROSS CSV CUBE CURRENT_P
720 : CURRENT_CATALOG CURRENT_DATE CURRENT_ROLE CURRENT_SCHEMA
721 : CURRENT_TIME CURRENT_TIMESTAMP CURRENT_USER CURSOR CYCLE
722 :
723 : DATA_P DATABASE DAY_P DEALLOCATE DEC DECIMAL_P DECLARE DEFAULT DEFAULTS
724 : DEFERRABLE DEFERRED DEFINER DELETE_P DELIMITER DELIMITERS DEPENDS DEPTH DESC
725 : DETACH DICTIONARY DISABLE_P DISCARD DISTINCT DO DOCUMENT_P DOMAIN_P
726 : DOUBLE_P DROP
727 :
728 : EACH ELSE EMPTY_P ENABLE_P ENCODING ENCRYPTED END_P ENFORCED ENUM_P ERROR_P
729 : ESCAPE EVENT EXCEPT EXCLUDE EXCLUDING EXCLUSIVE EXECUTE EXISTS EXPLAIN
730 : EXPRESSION EXTENSION EXTERNAL EXTRACT
731 :
732 : FALSE_P FAMILY FETCH FILTER FINALIZE FIRST_P FLOAT_P FOLLOWING FOR
733 : FORCE FOREIGN FORMAT FORWARD FREEZE FROM FULL FUNCTION FUNCTIONS
734 :
735 : GENERATED GLOBAL GRANT GRANTED GREATEST GROUP_P GROUPING GROUPS
736 :
737 : HANDLER HAVING HEADER_P HOLD HOUR_P
738 :
739 : IDENTITY_P IF_P IGNORE_P ILIKE IMMEDIATE IMMUTABLE IMPLICIT_P IMPORT_P IN_P INCLUDE
740 : INCLUDING INCREMENT INDENT INDEX INDEXES INHERIT INHERITS INITIALLY INLINE_P
741 : INNER_P INOUT INPUT_P INSENSITIVE INSERT INSTEAD INT_P INTEGER
742 : INTERSECT INTERVAL INTO INVOKER IS ISNULL ISOLATION
743 :
744 : JOIN JSON JSON_ARRAY JSON_ARRAYAGG JSON_EXISTS JSON_OBJECT JSON_OBJECTAGG
745 : JSON_QUERY JSON_SCALAR JSON_SERIALIZE JSON_TABLE JSON_VALUE
746 :
747 : KEEP KEY KEYS
748 :
749 : LABEL LANGUAGE LARGE_P LAST_P LATERAL_P
750 : LEADING LEAKPROOF LEAST LEFT LEVEL LIKE LIMIT LISTEN LOAD LOCAL
751 : LOCALTIME LOCALTIMESTAMP LOCATION LOCK_P LOCKED LOGGED LSN_P
752 :
753 : MAPPING MATCH MATCHED MATERIALIZED MAXVALUE MERGE MERGE_ACTION METHOD
754 : MINUTE_P MINVALUE MODE MONTH_P MOVE
755 :
756 : NAME_P NAMES NATIONAL NATURAL NCHAR NESTED NEW NEXT NFC NFD NFKC NFKD NO
757 : NONE NORMALIZE NORMALIZED
758 : NOT NOTHING NOTIFY NOTNULL NOWAIT NULL_P NULLIF
759 : NULLS_P NUMERIC
760 :
761 : OBJECT_P OBJECTS_P OF OFF OFFSET OIDS OLD OMIT ON ONLY OPERATOR OPTION OPTIONS OR
762 : ORDER ORDINALITY OTHERS OUT_P OUTER_P
763 : OVER OVERLAPS OVERLAY OVERRIDING OWNED OWNER
764 :
765 : PARALLEL PARAMETER PARSER PARTIAL PARTITION PASSING PASSWORD PATH
766 : PERIOD PLACING PLAN PLANS POLICY
767 : POSITION PRECEDING PRECISION PRESERVE PREPARE PREPARED PRIMARY
768 : PRIOR PRIVILEGES PROCEDURAL PROCEDURE PROCEDURES PROGRAM PUBLICATION
769 :
770 : QUOTE QUOTES
771 :
772 : RANGE READ REAL REASSIGN RECURSIVE REF_P REFERENCES REFERENCING
773 : REFRESH REINDEX RELATIVE_P RELEASE RENAME REPEATABLE REPLACE REPLICA
774 : RESET RESPECT_P RESTART RESTRICT RETURN RETURNING RETURNS REVOKE RIGHT ROLE ROLLBACK ROLLUP
775 : ROUTINE ROUTINES ROW ROWS RULE
776 :
777 : SAVEPOINT SCALAR SCHEMA SCHEMAS SCROLL SEARCH SECOND_P SECURITY SELECT
778 : SEQUENCE SEQUENCES
779 : SERIALIZABLE SERVER SESSION SESSION_USER SET SETS SETOF SHARE SHOW
780 : SIMILAR SIMPLE SKIP SMALLINT SNAPSHOT SOME SOURCE SQL_P STABLE STANDALONE_P
781 : START STATEMENT STATISTICS STDIN STDOUT STORAGE STORED STRICT_P STRING_P STRIP_P
782 : SUBSCRIPTION SUBSTRING SUPPORT SYMMETRIC SYSID SYSTEM_P SYSTEM_USER
783 :
784 : TABLE TABLES TABLESAMPLE TABLESPACE TARGET TEMP TEMPLATE TEMPORARY TEXT_P THEN
785 : TIES TIME TIMESTAMP TO TRAILING TRANSACTION TRANSFORM
786 : TREAT TRIGGER TRIM TRUE_P
787 : TRUNCATE TRUSTED TYPE_P TYPES_P
788 :
789 : UESCAPE UNBOUNDED UNCONDITIONAL UNCOMMITTED UNENCRYPTED UNION UNIQUE UNKNOWN
790 : UNLISTEN UNLOGGED UNTIL UPDATE USER USING
791 :
792 : VACUUM VALID VALIDATE VALIDATOR VALUE_P VALUES VARCHAR VARIADIC VARYING
793 : VERBOSE VERSION_P VIEW VIEWS VIRTUAL VOLATILE
794 :
795 : WAIT WHEN WHERE WHITESPACE_P WINDOW WITH WITHIN WITHOUT WORK WRAPPER WRITE
796 :
797 : XML_P XMLATTRIBUTES XMLCONCAT XMLELEMENT XMLEXISTS XMLFOREST XMLNAMESPACES
798 : XMLPARSE XMLPI XMLROOT XMLSERIALIZE XMLTABLE
799 :
800 : YEAR_P YES_P
801 :
802 : ZONE
803 :
804 : /*
805 : * The grammar thinks these are keywords, but they are not in the kwlist.h
806 : * list and so can never be entered directly. The filter in parser.c
807 : * creates these tokens when required (based on looking one token ahead).
808 : *
809 : * NOT_LA exists so that productions such as NOT LIKE can be given the same
810 : * precedence as LIKE; otherwise they'd effectively have the same precedence
811 : * as NOT, at least with respect to their left-hand subexpression.
812 : * FORMAT_LA, NULLS_LA, WITH_LA, and WITHOUT_LA are needed to make the grammar
813 : * LALR(1).
814 : */
815 : %token FORMAT_LA NOT_LA NULLS_LA WITH_LA WITHOUT_LA
816 :
817 : /*
818 : * The grammar likewise thinks these tokens are keywords, but they are never
819 : * generated by the scanner. Rather, they can be injected by parser.c as
820 : * the initial token of the string (using the lookahead-token mechanism
821 : * implemented there). This provides a way to tell the grammar to parse
822 : * something other than the usual list of SQL commands.
823 : */
824 : %token MODE_TYPE_NAME
825 : %token MODE_PLPGSQL_EXPR
826 : %token MODE_PLPGSQL_ASSIGN1
827 : %token MODE_PLPGSQL_ASSIGN2
828 : %token MODE_PLPGSQL_ASSIGN3
829 :
830 :
831 : /* Precedence: lowest to highest */
832 : %left UNION EXCEPT
833 : %left INTERSECT
834 : %left OR
835 : %left AND
836 : %right NOT
837 : %nonassoc IS ISNULL NOTNULL /* IS sets precedence for IS NULL, etc */
838 : %nonassoc '<' '>' '=' LESS_EQUALS GREATER_EQUALS NOT_EQUALS
839 : %nonassoc BETWEEN IN_P LIKE ILIKE SIMILAR NOT_LA
840 : %nonassoc ESCAPE /* ESCAPE must be just above LIKE/ILIKE/SIMILAR */
841 :
842 : /*
843 : * Sometimes it is necessary to assign precedence to keywords that are not
844 : * really part of the operator hierarchy, in order to resolve grammar
845 : * ambiguities. It's best to avoid doing so whenever possible, because such
846 : * assignments have global effect and may hide ambiguities besides the one
847 : * you intended to solve. (Attaching a precedence to a single rule with
848 : * %prec is far safer and should be preferred.) If you must give precedence
849 : * to a new keyword, try very hard to give it the same precedence as IDENT.
850 : * If the keyword has IDENT's precedence then it clearly acts the same as
851 : * non-keywords and other similar keywords, thus reducing the risk of
852 : * unexpected precedence effects.
853 : *
854 : * We used to need to assign IDENT an explicit precedence just less than Op,
855 : * to support target_el without AS. While that's not really necessary since
856 : * we removed postfix operators, we continue to do so because it provides a
857 : * reference point for a precedence level that we can assign to other
858 : * keywords that lack a natural precedence level.
859 : *
860 : * We need to do this for PARTITION, RANGE, ROWS, and GROUPS to support
861 : * opt_existing_window_name (see comment there).
862 : *
863 : * The frame_bound productions UNBOUNDED PRECEDING and UNBOUNDED FOLLOWING
864 : * are even messier: since UNBOUNDED is an unreserved keyword (per spec!),
865 : * there is no principled way to distinguish these from the productions
866 : * a_expr PRECEDING/FOLLOWING. We hack this up by giving UNBOUNDED slightly
867 : * lower precedence than PRECEDING and FOLLOWING. At present this doesn't
868 : * appear to cause UNBOUNDED to be treated differently from other unreserved
869 : * keywords anywhere else in the grammar, but it's definitely risky. We can
870 : * blame any funny behavior of UNBOUNDED on the SQL standard, though.
871 : *
872 : * To support CUBE and ROLLUP in GROUP BY without reserving them, we give them
873 : * an explicit priority lower than '(', so that a rule with CUBE '(' will shift
874 : * rather than reducing a conflicting rule that takes CUBE as a function name.
875 : * Using the same precedence as IDENT seems right for the reasons given above.
876 : *
877 : * SET is likewise assigned the same precedence as IDENT, to support the
878 : * relation_expr_opt_alias production (see comment there).
879 : *
880 : * KEYS, OBJECT_P, SCALAR, VALUE_P, WITH, and WITHOUT are similarly assigned
881 : * the same precedence as IDENT. This allows resolving conflicts in the
882 : * json_predicate_type_constraint and json_key_uniqueness_constraint_opt
883 : * productions (see comments there).
884 : *
885 : * Like the UNBOUNDED PRECEDING/FOLLOWING case, NESTED is assigned a lower
886 : * precedence than PATH to fix ambiguity in the json_table production.
887 : */
888 : %nonassoc UNBOUNDED NESTED /* ideally would have same precedence as IDENT */
889 : %nonassoc IDENT PARTITION RANGE ROWS GROUPS PRECEDING FOLLOWING CUBE ROLLUP
890 : SET KEYS OBJECT_P SCALAR VALUE_P WITH WITHOUT PATH
891 : %left Op OPERATOR /* multi-character ops and user-defined operators */
892 : %left '+' '-'
893 : %left '*' '/' '%'
894 : %left '^'
895 : /* Unary Operators */
896 : %left AT /* sets precedence for AT TIME ZONE, AT LOCAL */
897 : %left COLLATE
898 : %right UMINUS
899 : %left '[' ']'
900 : %left '(' ')'
901 : %left TYPECAST
902 : %left '.'
903 : /*
904 : * These might seem to be low-precedence, but actually they are not part
905 : * of the arithmetic hierarchy at all in their use as JOIN operators.
906 : * We make them high-precedence to support their use as function names.
907 : * They wouldn't be given a precedence at all, were it not that we need
908 : * left-associativity among the JOIN rules themselves.
909 : */
910 : %left JOIN CROSS LEFT FULL RIGHT INNER_P NATURAL
911 :
912 : %%
913 :
914 : /*
915 : * The target production for the whole parse.
916 : *
917 : * Ordinarily we parse a list of statements, but if we see one of the
918 : * special MODE_XXX symbols as first token, we parse something else.
919 : * The options here correspond to enum RawParseMode, which see for details.
920 : */
921 : parse_toplevel:
922 : stmtmulti
923 : {
924 720642 : pg_yyget_extra(yyscanner)->parsetree = $1;
925 : (void) yynerrs; /* suppress compiler warning */
926 : }
927 : | MODE_TYPE_NAME Typename
928 : {
929 10214 : pg_yyget_extra(yyscanner)->parsetree = list_make1($2);
930 : }
931 : | MODE_PLPGSQL_EXPR PLpgSQL_Expr
932 : {
933 33842 : pg_yyget_extra(yyscanner)->parsetree =
934 33842 : list_make1(makeRawStmt($2, @2));
935 : }
936 : | MODE_PLPGSQL_ASSIGN1 PLAssignStmt
937 : {
938 6358 : PLAssignStmt *n = (PLAssignStmt *) $2;
939 :
940 6358 : n->nnames = 1;
941 6358 : pg_yyget_extra(yyscanner)->parsetree =
942 6358 : list_make1(makeRawStmt((Node *) n, @2));
943 : }
944 : | MODE_PLPGSQL_ASSIGN2 PLAssignStmt
945 : {
946 686 : PLAssignStmt *n = (PLAssignStmt *) $2;
947 :
948 686 : n->nnames = 2;
949 686 : pg_yyget_extra(yyscanner)->parsetree =
950 686 : list_make1(makeRawStmt((Node *) n, @2));
951 : }
952 : | MODE_PLPGSQL_ASSIGN3 PLAssignStmt
953 : {
954 28 : PLAssignStmt *n = (PLAssignStmt *) $2;
955 :
956 28 : n->nnames = 3;
957 28 : pg_yyget_extra(yyscanner)->parsetree =
958 28 : list_make1(makeRawStmt((Node *) n, @2));
959 : }
960 : ;
961 :
962 : /*
963 : * At top level, we wrap each stmt with a RawStmt node carrying start location
964 : * and length of the stmt's text.
965 : * We also take care to discard empty statements entirely (which among other
966 : * things dodges the problem of assigning them a location).
967 : */
968 : stmtmulti: stmtmulti ';' toplevel_stmt
969 : {
970 589940 : if ($1 != NIL)
971 : {
972 : /* update length of previous stmt */
973 589376 : updateRawStmtEnd(llast_node(RawStmt, $1), @2);
974 : }
975 589940 : if ($3 != NULL)
976 60160 : $$ = lappend($1, makeRawStmt($3, @3));
977 : else
978 529780 : $$ = $1;
979 : }
980 : | toplevel_stmt
981 : {
982 720650 : if ($1 != NULL)
983 719334 : $$ = list_make1(makeRawStmt($1, @1));
984 : else
985 1316 : $$ = NIL;
986 : }
987 : ;
988 :
989 : /*
990 : * toplevel_stmt includes BEGIN and END. stmt does not include them, because
991 : * those words have different meanings in function bodies.
992 : */
993 : toplevel_stmt:
994 : stmt
995 : | TransactionStmtLegacy
996 : ;
997 :
998 : stmt:
999 : AlterEventTrigStmt
1000 : | AlterCollationStmt
1001 : | AlterDatabaseStmt
1002 : | AlterDatabaseSetStmt
1003 : | AlterDefaultPrivilegesStmt
1004 : | AlterDomainStmt
1005 : | AlterEnumStmt
1006 : | AlterExtensionStmt
1007 : | AlterExtensionContentsStmt
1008 : | AlterFdwStmt
1009 : | AlterForeignServerStmt
1010 : | AlterFunctionStmt
1011 : | AlterGroupStmt
1012 : | AlterObjectDependsStmt
1013 : | AlterObjectSchemaStmt
1014 : | AlterOwnerStmt
1015 : | AlterOperatorStmt
1016 : | AlterTypeStmt
1017 : | AlterPolicyStmt
1018 : | AlterSeqStmt
1019 : | AlterSystemStmt
1020 : | AlterTableStmt
1021 : | AlterTblSpcStmt
1022 : | AlterCompositeTypeStmt
1023 : | AlterPublicationStmt
1024 : | AlterRoleSetStmt
1025 : | AlterRoleStmt
1026 : | AlterSubscriptionStmt
1027 : | AlterStatsStmt
1028 : | AlterTSConfigurationStmt
1029 : | AlterTSDictionaryStmt
1030 : | AlterUserMappingStmt
1031 : | AnalyzeStmt
1032 : | CallStmt
1033 : | CheckPointStmt
1034 : | ClosePortalStmt
1035 : | ClusterStmt
1036 : | CommentStmt
1037 : | ConstraintsSetStmt
1038 : | CopyStmt
1039 : | CreateAmStmt
1040 : | CreateAsStmt
1041 : | CreateAssertionStmt
1042 : | CreateCastStmt
1043 : | CreateConversionStmt
1044 : | CreateDomainStmt
1045 : | CreateExtensionStmt
1046 : | CreateFdwStmt
1047 : | CreateForeignServerStmt
1048 : | CreateForeignTableStmt
1049 : | CreateFunctionStmt
1050 : | CreateGroupStmt
1051 : | CreateMatViewStmt
1052 : | CreateOpClassStmt
1053 : | CreateOpFamilyStmt
1054 : | CreatePublicationStmt
1055 : | AlterOpFamilyStmt
1056 : | CreatePolicyStmt
1057 : | CreatePLangStmt
1058 : | CreateSchemaStmt
1059 : | CreateSeqStmt
1060 : | CreateStmt
1061 : | CreateSubscriptionStmt
1062 : | CreateStatsStmt
1063 : | CreateTableSpaceStmt
1064 : | CreateTransformStmt
1065 : | CreateTrigStmt
1066 : | CreateEventTrigStmt
1067 : | CreateRoleStmt
1068 : | CreateUserStmt
1069 : | CreateUserMappingStmt
1070 : | CreatedbStmt
1071 : | DeallocateStmt
1072 : | DeclareCursorStmt
1073 : | DefineStmt
1074 : | DeleteStmt
1075 : | DiscardStmt
1076 : | DoStmt
1077 : | DropCastStmt
1078 : | DropOpClassStmt
1079 : | DropOpFamilyStmt
1080 : | DropOwnedStmt
1081 : | DropStmt
1082 : | DropSubscriptionStmt
1083 : | DropTableSpaceStmt
1084 : | DropTransformStmt
1085 : | DropRoleStmt
1086 : | DropUserMappingStmt
1087 : | DropdbStmt
1088 : | ExecuteStmt
1089 : | ExplainStmt
1090 : | FetchStmt
1091 : | GrantStmt
1092 : | GrantRoleStmt
1093 : | ImportForeignSchemaStmt
1094 : | IndexStmt
1095 : | InsertStmt
1096 : | ListenStmt
1097 : | RefreshMatViewStmt
1098 : | LoadStmt
1099 : | LockStmt
1100 : | MergeStmt
1101 : | NotifyStmt
1102 : | PrepareStmt
1103 : | ReassignOwnedStmt
1104 : | ReindexStmt
1105 : | RemoveAggrStmt
1106 : | RemoveFuncStmt
1107 : | RemoveOperStmt
1108 : | RenameStmt
1109 : | RevokeStmt
1110 : | RevokeRoleStmt
1111 : | RuleStmt
1112 : | SecLabelStmt
1113 : | SelectStmt
1114 : | TransactionStmt
1115 : | TruncateStmt
1116 : | UnlistenStmt
1117 : | UpdateStmt
1118 : | VacuumStmt
1119 : | VariableResetStmt
1120 : | VariableSetStmt
1121 : | VariableShowStmt
1122 : | ViewStmt
1123 : | WaitStmt
1124 : | /*EMPTY*/
1125 531114 : { $$ = NULL; }
1126 : ;
1127 :
1128 : /*
1129 : * Generic supporting productions for DDL
1130 : */
1131 : opt_single_name:
1132 5366 : ColId { $$ = $1; }
1133 1566 : | /* EMPTY */ { $$ = NULL; }
1134 : ;
1135 :
1136 : opt_qualified_name:
1137 1960 : any_name { $$ = $1; }
1138 15478 : | /*EMPTY*/ { $$ = NIL; }
1139 : ;
1140 :
1141 : opt_concurrently:
1142 1032 : CONCURRENTLY { $$ = true; }
1143 7670 : | /*EMPTY*/ { $$ = false; }
1144 : ;
1145 :
1146 : opt_drop_behavior:
1147 2030 : CASCADE { $$ = DROP_CASCADE; }
1148 170 : | RESTRICT { $$ = DROP_RESTRICT; }
1149 39698 : | /* EMPTY */ { $$ = DROP_RESTRICT; /* default */ }
1150 : ;
1151 :
1152 : opt_utility_option_list:
1153 366 : '(' utility_option_list ')' { $$ = $2; }
1154 5948 : | /* EMPTY */ { $$ = NULL; }
1155 : ;
1156 :
1157 : utility_option_list:
1158 : utility_option_elem
1159 : {
1160 22890 : $$ = list_make1($1);
1161 : }
1162 : | utility_option_list ',' utility_option_elem
1163 : {
1164 13258 : $$ = lappend($1, $3);
1165 : }
1166 : ;
1167 :
1168 : utility_option_elem:
1169 : utility_option_name utility_option_arg
1170 : {
1171 36148 : $$ = makeDefElem($1, $2, @1);
1172 : }
1173 : ;
1174 :
1175 : utility_option_name:
1176 32348 : NonReservedWord { $$ = $1; }
1177 3658 : | analyze_keyword { $$ = "analyze"; }
1178 148 : | FORMAT_LA { $$ = "format"; }
1179 : ;
1180 :
1181 : utility_option_arg:
1182 18146 : opt_boolean_or_string { $$ = (Node *) makeString($1); }
1183 384 : | NumericOnly { $$ = (Node *) $1; }
1184 17618 : | /* EMPTY */ { $$ = NULL; }
1185 : ;
1186 :
1187 : /*****************************************************************************
1188 : *
1189 : * CALL statement
1190 : *
1191 : *****************************************************************************/
1192 :
1193 : CallStmt: CALL func_application
1194 : {
1195 628 : CallStmt *n = makeNode(CallStmt);
1196 :
1197 628 : n->funccall = castNode(FuncCall, $2);
1198 628 : $$ = (Node *) n;
1199 : }
1200 : ;
1201 :
1202 : /*****************************************************************************
1203 : *
1204 : * Create a new Postgres DBMS role
1205 : *
1206 : *****************************************************************************/
1207 :
1208 : CreateRoleStmt:
1209 : CREATE ROLE RoleId opt_with OptRoleList
1210 : {
1211 1390 : CreateRoleStmt *n = makeNode(CreateRoleStmt);
1212 :
1213 1390 : n->stmt_type = ROLESTMT_ROLE;
1214 1390 : n->role = $3;
1215 1390 : n->options = $5;
1216 1390 : $$ = (Node *) n;
1217 : }
1218 : ;
1219 :
1220 :
1221 : opt_with: WITH
1222 : | WITH_LA
1223 : | /*EMPTY*/
1224 : ;
1225 :
1226 : /*
1227 : * Options for CREATE ROLE and ALTER ROLE (also used by CREATE/ALTER USER
1228 : * for backwards compatibility). Note: the only option required by SQL99
1229 : * is "WITH ADMIN name".
1230 : */
1231 : OptRoleList:
1232 1164 : OptRoleList CreateOptRoleElem { $$ = lappend($1, $2); }
1233 1870 : | /* EMPTY */ { $$ = NIL; }
1234 : ;
1235 :
1236 : AlterOptRoleList:
1237 770 : AlterOptRoleList AlterOptRoleElem { $$ = lappend($1, $2); }
1238 434 : | /* EMPTY */ { $$ = NIL; }
1239 : ;
1240 :
1241 : AlterOptRoleElem:
1242 : PASSWORD Sconst
1243 : {
1244 188 : $$ = makeDefElem("password",
1245 188 : (Node *) makeString($2), @1);
1246 : }
1247 : | PASSWORD NULL_P
1248 : {
1249 12 : $$ = makeDefElem("password", NULL, @1);
1250 : }
1251 : | ENCRYPTED PASSWORD Sconst
1252 : {
1253 : /*
1254 : * These days, passwords are always stored in encrypted
1255 : * form, so there is no difference between PASSWORD and
1256 : * ENCRYPTED PASSWORD.
1257 : */
1258 16 : $$ = makeDefElem("password",
1259 16 : (Node *) makeString($3), @1);
1260 : }
1261 : | UNENCRYPTED PASSWORD Sconst
1262 : {
1263 0 : ereport(ERROR,
1264 : (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
1265 : errmsg("UNENCRYPTED PASSWORD is no longer supported"),
1266 : errhint("Remove UNENCRYPTED to store the password in encrypted form instead."),
1267 : parser_errposition(@1)));
1268 : }
1269 : | INHERIT
1270 : {
1271 108 : $$ = makeDefElem("inherit", (Node *) makeBoolean(true), @1);
1272 : }
1273 : | CONNECTION LIMIT SignedIconst
1274 : {
1275 24 : $$ = makeDefElem("connectionlimit", (Node *) makeInteger($3), @1);
1276 : }
1277 : | VALID UNTIL Sconst
1278 : {
1279 2 : $$ = makeDefElem("validUntil", (Node *) makeString($3), @1);
1280 : }
1281 : /* Supported but not documented for roles, for use by ALTER GROUP. */
1282 : | USER role_list
1283 : {
1284 6 : $$ = makeDefElem("rolemembers", (Node *) $2, @1);
1285 : }
1286 : | IDENT
1287 : {
1288 : /*
1289 : * We handle identifiers that aren't parser keywords with
1290 : * the following special-case codes, to avoid bloating the
1291 : * size of the main parser.
1292 : */
1293 1430 : if (strcmp($1, "superuser") == 0)
1294 192 : $$ = makeDefElem("superuser", (Node *) makeBoolean(true), @1);
1295 1238 : else if (strcmp($1, "nosuperuser") == 0)
1296 112 : $$ = makeDefElem("superuser", (Node *) makeBoolean(false), @1);
1297 1126 : else if (strcmp($1, "createrole") == 0)
1298 102 : $$ = makeDefElem("createrole", (Node *) makeBoolean(true), @1);
1299 1024 : else if (strcmp($1, "nocreaterole") == 0)
1300 50 : $$ = makeDefElem("createrole", (Node *) makeBoolean(false), @1);
1301 974 : else if (strcmp($1, "replication") == 0)
1302 130 : $$ = makeDefElem("isreplication", (Node *) makeBoolean(true), @1);
1303 844 : else if (strcmp($1, "noreplication") == 0)
1304 108 : $$ = makeDefElem("isreplication", (Node *) makeBoolean(false), @1);
1305 736 : else if (strcmp($1, "createdb") == 0)
1306 92 : $$ = makeDefElem("createdb", (Node *) makeBoolean(true), @1);
1307 644 : else if (strcmp($1, "nocreatedb") == 0)
1308 58 : $$ = makeDefElem("createdb", (Node *) makeBoolean(false), @1);
1309 586 : else if (strcmp($1, "login") == 0)
1310 286 : $$ = makeDefElem("canlogin", (Node *) makeBoolean(true), @1);
1311 300 : else if (strcmp($1, "nologin") == 0)
1312 102 : $$ = makeDefElem("canlogin", (Node *) makeBoolean(false), @1);
1313 198 : else if (strcmp($1, "bypassrls") == 0)
1314 82 : $$ = makeDefElem("bypassrls", (Node *) makeBoolean(true), @1);
1315 116 : else if (strcmp($1, "nobypassrls") == 0)
1316 80 : $$ = makeDefElem("bypassrls", (Node *) makeBoolean(false), @1);
1317 36 : else if (strcmp($1, "noinherit") == 0)
1318 : {
1319 : /*
1320 : * Note that INHERIT is a keyword, so it's handled by main parser, but
1321 : * NOINHERIT is handled here.
1322 : */
1323 36 : $$ = makeDefElem("inherit", (Node *) makeBoolean(false), @1);
1324 : }
1325 : else
1326 0 : ereport(ERROR,
1327 : (errcode(ERRCODE_SYNTAX_ERROR),
1328 : errmsg("unrecognized role option \"%s\"", $1),
1329 : parser_errposition(@1)));
1330 : }
1331 : ;
1332 :
1333 : CreateOptRoleElem:
1334 1016 : AlterOptRoleElem { $$ = $1; }
1335 : /* The following are not supported by ALTER ROLE/USER/GROUP */
1336 : | SYSID Iconst
1337 : {
1338 6 : $$ = makeDefElem("sysid", (Node *) makeInteger($2), @1);
1339 : }
1340 : | ADMIN role_list
1341 : {
1342 22 : $$ = makeDefElem("adminmembers", (Node *) $2, @1);
1343 : }
1344 : | ROLE role_list
1345 : {
1346 22 : $$ = makeDefElem("rolemembers", (Node *) $2, @1);
1347 : }
1348 : | IN_P ROLE role_list
1349 : {
1350 98 : $$ = makeDefElem("addroleto", (Node *) $3, @1);
1351 : }
1352 : | IN_P GROUP_P role_list
1353 : {
1354 0 : $$ = makeDefElem("addroleto", (Node *) $3, @1);
1355 : }
1356 : ;
1357 :
1358 :
1359 : /*****************************************************************************
1360 : *
1361 : * Create a new Postgres DBMS user (role with implied login ability)
1362 : *
1363 : *****************************************************************************/
1364 :
1365 : CreateUserStmt:
1366 : CREATE USER RoleId opt_with OptRoleList
1367 : {
1368 456 : CreateRoleStmt *n = makeNode(CreateRoleStmt);
1369 :
1370 456 : n->stmt_type = ROLESTMT_USER;
1371 456 : n->role = $3;
1372 456 : n->options = $5;
1373 456 : $$ = (Node *) n;
1374 : }
1375 : ;
1376 :
1377 :
1378 : /*****************************************************************************
1379 : *
1380 : * Alter a postgresql DBMS role
1381 : *
1382 : *****************************************************************************/
1383 :
1384 : AlterRoleStmt:
1385 : ALTER ROLE RoleSpec opt_with AlterOptRoleList
1386 : {
1387 342 : AlterRoleStmt *n = makeNode(AlterRoleStmt);
1388 :
1389 342 : n->role = $3;
1390 342 : n->action = +1; /* add, if there are members */
1391 342 : n->options = $5;
1392 342 : $$ = (Node *) n;
1393 : }
1394 : | ALTER USER RoleSpec opt_with AlterOptRoleList
1395 : {
1396 92 : AlterRoleStmt *n = makeNode(AlterRoleStmt);
1397 :
1398 92 : n->role = $3;
1399 92 : n->action = +1; /* add, if there are members */
1400 92 : n->options = $5;
1401 92 : $$ = (Node *) n;
1402 : }
1403 : ;
1404 :
1405 : opt_in_database:
1406 94 : /* EMPTY */ { $$ = NULL; }
1407 4 : | IN_P DATABASE name { $$ = $3; }
1408 : ;
1409 :
1410 : AlterRoleSetStmt:
1411 : ALTER ROLE RoleSpec opt_in_database SetResetClause
1412 : {
1413 58 : AlterRoleSetStmt *n = makeNode(AlterRoleSetStmt);
1414 :
1415 58 : n->role = $3;
1416 58 : n->database = $4;
1417 58 : n->setstmt = $5;
1418 58 : $$ = (Node *) n;
1419 : }
1420 : | ALTER ROLE ALL opt_in_database SetResetClause
1421 : {
1422 4 : AlterRoleSetStmt *n = makeNode(AlterRoleSetStmt);
1423 :
1424 4 : n->role = NULL;
1425 4 : n->database = $4;
1426 4 : n->setstmt = $5;
1427 4 : $$ = (Node *) n;
1428 : }
1429 : | ALTER USER RoleSpec opt_in_database SetResetClause
1430 : {
1431 28 : AlterRoleSetStmt *n = makeNode(AlterRoleSetStmt);
1432 :
1433 28 : n->role = $3;
1434 28 : n->database = $4;
1435 28 : n->setstmt = $5;
1436 28 : $$ = (Node *) n;
1437 : }
1438 : | ALTER USER ALL opt_in_database SetResetClause
1439 : {
1440 4 : AlterRoleSetStmt *n = makeNode(AlterRoleSetStmt);
1441 :
1442 4 : n->role = NULL;
1443 4 : n->database = $4;
1444 4 : n->setstmt = $5;
1445 4 : $$ = (Node *) n;
1446 : }
1447 : ;
1448 :
1449 :
1450 : /*****************************************************************************
1451 : *
1452 : * Drop a postgresql DBMS role
1453 : *
1454 : * XXX Ideally this would have CASCADE/RESTRICT options, but a role
1455 : * might own objects in multiple databases, and there is presently no way to
1456 : * implement cascading to other databases. So we always behave as RESTRICT.
1457 : *****************************************************************************/
1458 :
1459 : DropRoleStmt:
1460 : DROP ROLE role_list
1461 : {
1462 1106 : DropRoleStmt *n = makeNode(DropRoleStmt);
1463 :
1464 1106 : n->missing_ok = false;
1465 1106 : n->roles = $3;
1466 1106 : $$ = (Node *) n;
1467 : }
1468 : | DROP ROLE IF_P EXISTS role_list
1469 : {
1470 134 : DropRoleStmt *n = makeNode(DropRoleStmt);
1471 :
1472 134 : n->missing_ok = true;
1473 134 : n->roles = $5;
1474 134 : $$ = (Node *) n;
1475 : }
1476 : | DROP USER role_list
1477 : {
1478 406 : DropRoleStmt *n = makeNode(DropRoleStmt);
1479 :
1480 406 : n->missing_ok = false;
1481 406 : n->roles = $3;
1482 406 : $$ = (Node *) n;
1483 : }
1484 : | DROP USER IF_P EXISTS role_list
1485 : {
1486 36 : DropRoleStmt *n = makeNode(DropRoleStmt);
1487 :
1488 36 : n->roles = $5;
1489 36 : n->missing_ok = true;
1490 36 : $$ = (Node *) n;
1491 : }
1492 : | DROP GROUP_P role_list
1493 : {
1494 36 : DropRoleStmt *n = makeNode(DropRoleStmt);
1495 :
1496 36 : n->missing_ok = false;
1497 36 : n->roles = $3;
1498 36 : $$ = (Node *) n;
1499 : }
1500 : | DROP GROUP_P IF_P EXISTS role_list
1501 : {
1502 6 : DropRoleStmt *n = makeNode(DropRoleStmt);
1503 :
1504 6 : n->missing_ok = true;
1505 6 : n->roles = $5;
1506 6 : $$ = (Node *) n;
1507 : }
1508 : ;
1509 :
1510 :
1511 : /*****************************************************************************
1512 : *
1513 : * Create a postgresql group (role without login ability)
1514 : *
1515 : *****************************************************************************/
1516 :
1517 : CreateGroupStmt:
1518 : CREATE GROUP_P RoleId opt_with OptRoleList
1519 : {
1520 24 : CreateRoleStmt *n = makeNode(CreateRoleStmt);
1521 :
1522 24 : n->stmt_type = ROLESTMT_GROUP;
1523 24 : n->role = $3;
1524 24 : n->options = $5;
1525 24 : $$ = (Node *) n;
1526 : }
1527 : ;
1528 :
1529 :
1530 : /*****************************************************************************
1531 : *
1532 : * Alter a postgresql group
1533 : *
1534 : *****************************************************************************/
1535 :
1536 : AlterGroupStmt:
1537 : ALTER GROUP_P RoleSpec add_drop USER role_list
1538 : {
1539 42 : AlterRoleStmt *n = makeNode(AlterRoleStmt);
1540 :
1541 42 : n->role = $3;
1542 42 : n->action = $4;
1543 42 : n->options = list_make1(makeDefElem("rolemembers",
1544 : (Node *) $6, @6));
1545 42 : $$ = (Node *) n;
1546 : }
1547 : ;
1548 :
1549 94 : add_drop: ADD_P { $$ = +1; }
1550 224 : | DROP { $$ = -1; }
1551 : ;
1552 :
1553 :
1554 : /*****************************************************************************
1555 : *
1556 : * Manipulate a schema
1557 : *
1558 : *****************************************************************************/
1559 :
1560 : CreateSchemaStmt:
1561 : CREATE SCHEMA opt_single_name AUTHORIZATION RoleSpec OptSchemaEltList
1562 : {
1563 158 : CreateSchemaStmt *n = makeNode(CreateSchemaStmt);
1564 :
1565 : /* One can omit the schema name or the authorization id. */
1566 158 : n->schemaname = $3;
1567 158 : n->authrole = $5;
1568 158 : n->schemaElts = $6;
1569 158 : n->if_not_exists = false;
1570 158 : $$ = (Node *) n;
1571 : }
1572 : | CREATE SCHEMA ColId OptSchemaEltList
1573 : {
1574 914 : CreateSchemaStmt *n = makeNode(CreateSchemaStmt);
1575 :
1576 : /* ...but not both */
1577 914 : n->schemaname = $3;
1578 914 : n->authrole = NULL;
1579 914 : n->schemaElts = $4;
1580 914 : n->if_not_exists = false;
1581 914 : $$ = (Node *) n;
1582 : }
1583 : | CREATE SCHEMA IF_P NOT EXISTS opt_single_name AUTHORIZATION RoleSpec OptSchemaEltList
1584 : {
1585 18 : CreateSchemaStmt *n = makeNode(CreateSchemaStmt);
1586 :
1587 : /* schema name can be omitted here, too */
1588 18 : n->schemaname = $6;
1589 18 : n->authrole = $8;
1590 18 : if ($9 != NIL)
1591 0 : ereport(ERROR,
1592 : (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
1593 : errmsg("CREATE SCHEMA IF NOT EXISTS cannot include schema elements"),
1594 : parser_errposition(@9)));
1595 18 : n->schemaElts = $9;
1596 18 : n->if_not_exists = true;
1597 18 : $$ = (Node *) n;
1598 : }
1599 : | CREATE SCHEMA IF_P NOT EXISTS ColId OptSchemaEltList
1600 : {
1601 34 : CreateSchemaStmt *n = makeNode(CreateSchemaStmt);
1602 :
1603 : /* ...but not here */
1604 34 : n->schemaname = $6;
1605 34 : n->authrole = NULL;
1606 34 : if ($7 != NIL)
1607 6 : ereport(ERROR,
1608 : (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
1609 : errmsg("CREATE SCHEMA IF NOT EXISTS cannot include schema elements"),
1610 : parser_errposition(@7)));
1611 28 : n->schemaElts = $7;
1612 28 : n->if_not_exists = true;
1613 28 : $$ = (Node *) n;
1614 : }
1615 : ;
1616 :
1617 : OptSchemaEltList:
1618 : OptSchemaEltList schema_stmt
1619 : {
1620 570 : $$ = lappend($1, $2);
1621 : }
1622 : | /* EMPTY */
1623 1124 : { $$ = NIL; }
1624 : ;
1625 :
1626 : /*
1627 : * schema_stmt are the ones that can show up inside a CREATE SCHEMA
1628 : * statement (in addition to by themselves).
1629 : */
1630 : schema_stmt:
1631 : CreateStmt
1632 : | IndexStmt
1633 : | CreateSeqStmt
1634 : | CreateTrigStmt
1635 : | GrantStmt
1636 : | ViewStmt
1637 : ;
1638 :
1639 :
1640 : /*****************************************************************************
1641 : *
1642 : * Set PG internal variable
1643 : * SET name TO 'var_value'
1644 : * Include SQL syntax (thomas 1997-10-22):
1645 : * SET TIME ZONE 'var_value'
1646 : *
1647 : *****************************************************************************/
1648 :
1649 : VariableSetStmt:
1650 : SET set_rest
1651 : {
1652 21884 : VariableSetStmt *n = $2;
1653 :
1654 21884 : n->is_local = false;
1655 21884 : $$ = (Node *) n;
1656 : }
1657 : | SET LOCAL set_rest
1658 : {
1659 1284 : VariableSetStmt *n = $3;
1660 :
1661 1284 : n->is_local = true;
1662 1284 : $$ = (Node *) n;
1663 : }
1664 : | SET SESSION set_rest
1665 : {
1666 84 : VariableSetStmt *n = $3;
1667 :
1668 84 : n->is_local = false;
1669 84 : $$ = (Node *) n;
1670 : }
1671 : ;
1672 :
1673 : set_rest:
1674 : TRANSACTION transaction_mode_list
1675 : {
1676 582 : VariableSetStmt *n = makeNode(VariableSetStmt);
1677 :
1678 582 : n->kind = VAR_SET_MULTI;
1679 582 : n->name = "TRANSACTION";
1680 582 : n->args = $2;
1681 582 : n->jumble_args = true;
1682 582 : n->location = -1;
1683 582 : $$ = n;
1684 : }
1685 : | SESSION CHARACTERISTICS AS TRANSACTION transaction_mode_list
1686 : {
1687 18 : VariableSetStmt *n = makeNode(VariableSetStmt);
1688 :
1689 18 : n->kind = VAR_SET_MULTI;
1690 18 : n->name = "SESSION CHARACTERISTICS";
1691 18 : n->args = $5;
1692 18 : n->jumble_args = true;
1693 18 : n->location = -1;
1694 18 : $$ = n;
1695 : }
1696 : | set_rest_more
1697 : ;
1698 :
1699 : generic_set:
1700 : var_name TO var_list
1701 : {
1702 5230 : VariableSetStmt *n = makeNode(VariableSetStmt);
1703 :
1704 5230 : n->kind = VAR_SET_VALUE;
1705 5230 : n->name = $1;
1706 5230 : n->args = $3;
1707 5230 : n->location = @3;
1708 5230 : $$ = n;
1709 : }
1710 : | var_name '=' var_list
1711 : {
1712 15066 : VariableSetStmt *n = makeNode(VariableSetStmt);
1713 :
1714 15066 : n->kind = VAR_SET_VALUE;
1715 15066 : n->name = $1;
1716 15066 : n->args = $3;
1717 15066 : n->location = @3;
1718 15066 : $$ = n;
1719 : }
1720 : | var_name TO NULL_P
1721 : {
1722 8 : VariableSetStmt *n = makeNode(VariableSetStmt);
1723 :
1724 8 : n->kind = VAR_SET_VALUE;
1725 8 : n->name = $1;
1726 8 : n->args = list_make1(makeNullAConst(@3));
1727 8 : n->location = @3;
1728 8 : $$ = n;
1729 : }
1730 : | var_name '=' NULL_P
1731 : {
1732 18 : VariableSetStmt *n = makeNode(VariableSetStmt);
1733 :
1734 18 : n->kind = VAR_SET_VALUE;
1735 18 : n->name = $1;
1736 18 : n->args = list_make1(makeNullAConst(@3));
1737 18 : n->location = @3;
1738 18 : $$ = n;
1739 : }
1740 : | var_name TO DEFAULT
1741 : {
1742 136 : VariableSetStmt *n = makeNode(VariableSetStmt);
1743 :
1744 136 : n->kind = VAR_SET_DEFAULT;
1745 136 : n->name = $1;
1746 136 : n->location = -1;
1747 136 : $$ = n;
1748 : }
1749 : | var_name '=' DEFAULT
1750 : {
1751 10 : VariableSetStmt *n = makeNode(VariableSetStmt);
1752 :
1753 10 : n->kind = VAR_SET_DEFAULT;
1754 10 : n->name = $1;
1755 10 : n->location = -1;
1756 10 : $$ = n;
1757 : }
1758 : ;
1759 :
1760 : set_rest_more: /* Generic SET syntaxes: */
1761 20334 : generic_set {$$ = $1;}
1762 : | var_name FROM CURRENT_P
1763 : {
1764 4 : VariableSetStmt *n = makeNode(VariableSetStmt);
1765 :
1766 4 : n->kind = VAR_SET_CURRENT;
1767 4 : n->name = $1;
1768 4 : n->location = -1;
1769 4 : $$ = n;
1770 : }
1771 : /* Special syntaxes mandated by SQL standard: */
1772 : | TIME ZONE zone_value
1773 : {
1774 104 : VariableSetStmt *n = makeNode(VariableSetStmt);
1775 :
1776 104 : n->kind = VAR_SET_VALUE;
1777 104 : n->name = "timezone";
1778 104 : n->location = -1;
1779 104 : n->jumble_args = true;
1780 104 : if ($3 != NULL)
1781 88 : n->args = list_make1($3);
1782 : else
1783 16 : n->kind = VAR_SET_DEFAULT;
1784 104 : $$ = n;
1785 : }
1786 : | CATALOG_P Sconst
1787 : {
1788 0 : ereport(ERROR,
1789 : (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
1790 : errmsg("current database cannot be changed"),
1791 : parser_errposition(@2)));
1792 : $$ = NULL; /*not reached*/
1793 : }
1794 : | SCHEMA Sconst
1795 : {
1796 4 : VariableSetStmt *n = makeNode(VariableSetStmt);
1797 :
1798 4 : n->kind = VAR_SET_VALUE;
1799 4 : n->name = "search_path";
1800 4 : n->args = list_make1(makeStringConst($2, @2));
1801 4 : n->location = @2;
1802 4 : $$ = n;
1803 : }
1804 : | NAMES opt_encoding
1805 : {
1806 0 : VariableSetStmt *n = makeNode(VariableSetStmt);
1807 :
1808 0 : n->kind = VAR_SET_VALUE;
1809 0 : n->name = "client_encoding";
1810 0 : n->location = @2;
1811 0 : if ($2 != NULL)
1812 0 : n->args = list_make1(makeStringConst($2, @2));
1813 : else
1814 0 : n->kind = VAR_SET_DEFAULT;
1815 0 : $$ = n;
1816 : }
1817 : | ROLE NonReservedWord_or_Sconst
1818 : {
1819 962 : VariableSetStmt *n = makeNode(VariableSetStmt);
1820 :
1821 962 : n->kind = VAR_SET_VALUE;
1822 962 : n->name = "role";
1823 962 : n->args = list_make1(makeStringConst($2, @2));
1824 962 : n->location = @2;
1825 962 : $$ = n;
1826 : }
1827 : | SESSION AUTHORIZATION NonReservedWord_or_Sconst
1828 : {
1829 2628 : VariableSetStmt *n = makeNode(VariableSetStmt);
1830 :
1831 2628 : n->kind = VAR_SET_VALUE;
1832 2628 : n->name = "session_authorization";
1833 2628 : n->args = list_make1(makeStringConst($3, @3));
1834 2628 : n->location = @3;
1835 2628 : $$ = n;
1836 : }
1837 : | SESSION AUTHORIZATION DEFAULT
1838 : {
1839 4 : VariableSetStmt *n = makeNode(VariableSetStmt);
1840 :
1841 4 : n->kind = VAR_SET_DEFAULT;
1842 4 : n->name = "session_authorization";
1843 4 : n->location = -1;
1844 4 : $$ = n;
1845 : }
1846 : | XML_P OPTION document_or_content
1847 : {
1848 16 : VariableSetStmt *n = makeNode(VariableSetStmt);
1849 :
1850 16 : n->kind = VAR_SET_VALUE;
1851 16 : n->name = "xmloption";
1852 16 : n->args = list_make1(makeStringConst($3 == XMLOPTION_DOCUMENT ? "DOCUMENT" : "CONTENT", @3));
1853 16 : n->jumble_args = true;
1854 16 : n->location = -1;
1855 16 : $$ = n;
1856 : }
1857 : /* Special syntaxes invented by PostgreSQL: */
1858 : | TRANSACTION SNAPSHOT Sconst
1859 : {
1860 44 : VariableSetStmt *n = makeNode(VariableSetStmt);
1861 :
1862 44 : n->kind = VAR_SET_MULTI;
1863 44 : n->name = "TRANSACTION SNAPSHOT";
1864 44 : n->args = list_make1(makeStringConst($3, @3));
1865 44 : n->location = @3;
1866 44 : $$ = n;
1867 : }
1868 : ;
1869 :
1870 25330 : var_name: ColId { $$ = $1; }
1871 : | var_name '.' ColId
1872 496 : { $$ = psprintf("%s.%s", $1, $3); }
1873 : ;
1874 :
1875 20296 : var_list: var_value { $$ = list_make1($1); }
1876 200 : | var_list ',' var_value { $$ = lappend($1, $3); }
1877 : ;
1878 :
1879 : var_value: opt_boolean_or_string
1880 15118 : { $$ = makeStringConst($1, @1); }
1881 : | NumericOnly
1882 5378 : { $$ = makeAConst($1, @1); }
1883 : ;
1884 :
1885 0 : iso_level: READ UNCOMMITTED { $$ = "read uncommitted"; }
1886 1028 : | READ COMMITTED { $$ = "read committed"; }
1887 2658 : | REPEATABLE READ { $$ = "repeatable read"; }
1888 3228 : | SERIALIZABLE { $$ = "serializable"; }
1889 : ;
1890 :
1891 : opt_boolean_or_string:
1892 704 : TRUE_P { $$ = "true"; }
1893 1486 : | FALSE_P { $$ = "false"; }
1894 2270 : | ON { $$ = "on"; }
1895 : /*
1896 : * OFF is also accepted as a boolean value, but is handled by
1897 : * the NonReservedWord rule. The action for booleans and strings
1898 : * is the same, so we don't need to distinguish them here.
1899 : */
1900 31178 : | NonReservedWord_or_Sconst { $$ = $1; }
1901 : ;
1902 :
1903 : /* Timezone values can be:
1904 : * - a string such as 'pst8pdt'
1905 : * - an identifier such as "pst8pdt"
1906 : * - an integer or floating point number
1907 : * - a time interval per SQL99
1908 : * ColId gives reduce/reduce errors against ConstInterval and LOCAL,
1909 : * so use IDENT (meaning we reject anything that is a key word).
1910 : */
1911 : zone_value:
1912 : Sconst
1913 : {
1914 60 : $$ = makeStringConst($1, @1);
1915 : }
1916 : | IDENT
1917 : {
1918 4 : $$ = makeStringConst($1, @1);
1919 : }
1920 : | ConstInterval Sconst opt_interval
1921 : {
1922 0 : TypeName *t = $1;
1923 :
1924 0 : if ($3 != NIL)
1925 : {
1926 0 : A_Const *n = (A_Const *) linitial($3);
1927 :
1928 0 : if ((n->val.ival.ival & ~(INTERVAL_MASK(HOUR) | INTERVAL_MASK(MINUTE))) != 0)
1929 0 : ereport(ERROR,
1930 : (errcode(ERRCODE_SYNTAX_ERROR),
1931 : errmsg("time zone interval must be HOUR or HOUR TO MINUTE"),
1932 : parser_errposition(@3)));
1933 : }
1934 0 : t->typmods = $3;
1935 0 : $$ = makeStringConstCast($2, @2, t);
1936 : }
1937 : | ConstInterval '(' Iconst ')' Sconst
1938 : {
1939 0 : TypeName *t = $1;
1940 :
1941 0 : t->typmods = list_make2(makeIntConst(INTERVAL_FULL_RANGE, -1),
1942 : makeIntConst($3, @3));
1943 0 : $$ = makeStringConstCast($5, @5, t);
1944 : }
1945 24 : | NumericOnly { $$ = makeAConst($1, @1); }
1946 14 : | DEFAULT { $$ = NULL; }
1947 2 : | LOCAL { $$ = NULL; }
1948 : ;
1949 :
1950 : opt_encoding:
1951 0 : Sconst { $$ = $1; }
1952 0 : | DEFAULT { $$ = NULL; }
1953 0 : | /*EMPTY*/ { $$ = NULL; }
1954 : ;
1955 :
1956 : NonReservedWord_or_Sconst:
1957 55446 : NonReservedWord { $$ = $1; }
1958 5716 : | Sconst { $$ = $1; }
1959 : ;
1960 :
1961 : VariableResetStmt:
1962 4790 : RESET reset_rest { $$ = (Node *) $2; }
1963 : ;
1964 :
1965 : reset_rest:
1966 3950 : generic_reset { $$ = $1; }
1967 : | TIME ZONE
1968 : {
1969 14 : VariableSetStmt *n = makeNode(VariableSetStmt);
1970 :
1971 14 : n->kind = VAR_RESET;
1972 14 : n->name = "timezone";
1973 14 : n->location = -1;
1974 14 : $$ = n;
1975 : }
1976 : | TRANSACTION ISOLATION LEVEL
1977 : {
1978 0 : VariableSetStmt *n = makeNode(VariableSetStmt);
1979 :
1980 0 : n->kind = VAR_RESET;
1981 0 : n->name = "transaction_isolation";
1982 0 : n->location = -1;
1983 0 : $$ = n;
1984 : }
1985 : | SESSION AUTHORIZATION
1986 : {
1987 826 : VariableSetStmt *n = makeNode(VariableSetStmt);
1988 :
1989 826 : n->kind = VAR_RESET;
1990 826 : n->name = "session_authorization";
1991 826 : n->location = -1;
1992 826 : $$ = n;
1993 : }
1994 : ;
1995 :
1996 : generic_reset:
1997 : var_name
1998 : {
1999 3980 : VariableSetStmt *n = makeNode(VariableSetStmt);
2000 :
2001 3980 : n->kind = VAR_RESET;
2002 3980 : n->name = $1;
2003 3980 : n->location = -1;
2004 3980 : $$ = n;
2005 : }
2006 : | ALL
2007 : {
2008 28 : VariableSetStmt *n = makeNode(VariableSetStmt);
2009 :
2010 28 : n->kind = VAR_RESET_ALL;
2011 28 : n->location = -1;
2012 28 : $$ = n;
2013 : }
2014 : ;
2015 :
2016 : /* SetResetClause allows SET or RESET without LOCAL */
2017 : SetResetClause:
2018 1306 : SET set_rest { $$ = $2; }
2019 42 : | VariableResetStmt { $$ = (VariableSetStmt *) $1; }
2020 : ;
2021 :
2022 : /* SetResetClause allows SET or RESET without LOCAL */
2023 : FunctionSetResetClause:
2024 142 : SET set_rest_more { $$ = $2; }
2025 12 : | VariableResetStmt { $$ = (VariableSetStmt *) $1; }
2026 : ;
2027 :
2028 :
2029 : VariableShowStmt:
2030 : SHOW var_name
2031 : {
2032 878 : VariableShowStmt *n = makeNode(VariableShowStmt);
2033 :
2034 878 : n->name = $2;
2035 878 : $$ = (Node *) n;
2036 : }
2037 : | SHOW TIME ZONE
2038 : {
2039 10 : VariableShowStmt *n = makeNode(VariableShowStmt);
2040 :
2041 10 : n->name = "timezone";
2042 10 : $$ = (Node *) n;
2043 : }
2044 : | SHOW TRANSACTION ISOLATION LEVEL
2045 : {
2046 4 : VariableShowStmt *n = makeNode(VariableShowStmt);
2047 :
2048 4 : n->name = "transaction_isolation";
2049 4 : $$ = (Node *) n;
2050 : }
2051 : | SHOW SESSION AUTHORIZATION
2052 : {
2053 0 : VariableShowStmt *n = makeNode(VariableShowStmt);
2054 :
2055 0 : n->name = "session_authorization";
2056 0 : $$ = (Node *) n;
2057 : }
2058 : | SHOW ALL
2059 : {
2060 0 : VariableShowStmt *n = makeNode(VariableShowStmt);
2061 :
2062 0 : n->name = "all";
2063 0 : $$ = (Node *) n;
2064 : }
2065 : ;
2066 :
2067 :
2068 : ConstraintsSetStmt:
2069 : SET CONSTRAINTS constraints_set_list constraints_set_mode
2070 : {
2071 104 : ConstraintsSetStmt *n = makeNode(ConstraintsSetStmt);
2072 :
2073 104 : n->constraints = $3;
2074 104 : n->deferred = $4;
2075 104 : $$ = (Node *) n;
2076 : }
2077 : ;
2078 :
2079 : constraints_set_list:
2080 56 : ALL { $$ = NIL; }
2081 48 : | qualified_name_list { $$ = $1; }
2082 : ;
2083 :
2084 : constraints_set_mode:
2085 68 : DEFERRED { $$ = true; }
2086 36 : | IMMEDIATE { $$ = false; }
2087 : ;
2088 :
2089 :
2090 : /*
2091 : * Checkpoint statement
2092 : */
2093 : CheckPointStmt:
2094 : CHECKPOINT opt_utility_option_list
2095 : {
2096 244 : CheckPointStmt *n = makeNode(CheckPointStmt);
2097 :
2098 244 : $$ = (Node *) n;
2099 244 : n->options = $2;
2100 : }
2101 : ;
2102 :
2103 :
2104 : /*****************************************************************************
2105 : *
2106 : * DISCARD { ALL | TEMP | PLANS | SEQUENCES }
2107 : *
2108 : *****************************************************************************/
2109 :
2110 : DiscardStmt:
2111 : DISCARD ALL
2112 : {
2113 6 : DiscardStmt *n = makeNode(DiscardStmt);
2114 :
2115 6 : n->target = DISCARD_ALL;
2116 6 : $$ = (Node *) n;
2117 : }
2118 : | DISCARD TEMP
2119 : {
2120 14 : DiscardStmt *n = makeNode(DiscardStmt);
2121 :
2122 14 : n->target = DISCARD_TEMP;
2123 14 : $$ = (Node *) n;
2124 : }
2125 : | DISCARD TEMPORARY
2126 : {
2127 0 : DiscardStmt *n = makeNode(DiscardStmt);
2128 :
2129 0 : n->target = DISCARD_TEMP;
2130 0 : $$ = (Node *) n;
2131 : }
2132 : | DISCARD PLANS
2133 : {
2134 4 : DiscardStmt *n = makeNode(DiscardStmt);
2135 :
2136 4 : n->target = DISCARD_PLANS;
2137 4 : $$ = (Node *) n;
2138 : }
2139 : | DISCARD SEQUENCES
2140 : {
2141 12 : DiscardStmt *n = makeNode(DiscardStmt);
2142 :
2143 12 : n->target = DISCARD_SEQUENCES;
2144 12 : $$ = (Node *) n;
2145 : }
2146 :
2147 : ;
2148 :
2149 :
2150 : /*****************************************************************************
2151 : *
2152 : * ALTER [ TABLE | INDEX | SEQUENCE | VIEW | MATERIALIZED VIEW | FOREIGN TABLE ] variations
2153 : *
2154 : * Note: we accept all subcommands for each of the variants, and sort
2155 : * out what's really legal at execution time.
2156 : *****************************************************************************/
2157 :
2158 : AlterTableStmt:
2159 : ALTER TABLE relation_expr alter_table_cmds
2160 : {
2161 26542 : AlterTableStmt *n = makeNode(AlterTableStmt);
2162 :
2163 26542 : n->relation = $3;
2164 26542 : n->cmds = $4;
2165 26542 : n->objtype = OBJECT_TABLE;
2166 26542 : n->missing_ok = false;
2167 26542 : $$ = (Node *) n;
2168 : }
2169 : | ALTER TABLE IF_P EXISTS relation_expr alter_table_cmds
2170 : {
2171 54 : AlterTableStmt *n = makeNode(AlterTableStmt);
2172 :
2173 54 : n->relation = $5;
2174 54 : n->cmds = $6;
2175 54 : n->objtype = OBJECT_TABLE;
2176 54 : n->missing_ok = true;
2177 54 : $$ = (Node *) n;
2178 : }
2179 : | ALTER TABLE relation_expr partition_cmd
2180 : {
2181 3082 : AlterTableStmt *n = makeNode(AlterTableStmt);
2182 :
2183 3082 : n->relation = $3;
2184 3082 : n->cmds = list_make1($4);
2185 3082 : n->objtype = OBJECT_TABLE;
2186 3082 : n->missing_ok = false;
2187 3082 : $$ = (Node *) n;
2188 : }
2189 : | ALTER TABLE IF_P EXISTS relation_expr partition_cmd
2190 : {
2191 0 : AlterTableStmt *n = makeNode(AlterTableStmt);
2192 :
2193 0 : n->relation = $5;
2194 0 : n->cmds = list_make1($6);
2195 0 : n->objtype = OBJECT_TABLE;
2196 0 : n->missing_ok = true;
2197 0 : $$ = (Node *) n;
2198 : }
2199 : | ALTER TABLE ALL IN_P TABLESPACE name SET TABLESPACE name opt_nowait
2200 : {
2201 : AlterTableMoveAllStmt *n =
2202 12 : makeNode(AlterTableMoveAllStmt);
2203 :
2204 12 : n->orig_tablespacename = $6;
2205 12 : n->objtype = OBJECT_TABLE;
2206 12 : n->roles = NIL;
2207 12 : n->new_tablespacename = $9;
2208 12 : n->nowait = $10;
2209 12 : $$ = (Node *) n;
2210 : }
2211 : | ALTER TABLE ALL IN_P TABLESPACE name OWNED BY role_list SET TABLESPACE name opt_nowait
2212 : {
2213 : AlterTableMoveAllStmt *n =
2214 0 : makeNode(AlterTableMoveAllStmt);
2215 :
2216 0 : n->orig_tablespacename = $6;
2217 0 : n->objtype = OBJECT_TABLE;
2218 0 : n->roles = $9;
2219 0 : n->new_tablespacename = $12;
2220 0 : n->nowait = $13;
2221 0 : $$ = (Node *) n;
2222 : }
2223 : | ALTER INDEX qualified_name alter_table_cmds
2224 : {
2225 228 : AlterTableStmt *n = makeNode(AlterTableStmt);
2226 :
2227 228 : n->relation = $3;
2228 228 : n->cmds = $4;
2229 228 : n->objtype = OBJECT_INDEX;
2230 228 : n->missing_ok = false;
2231 228 : $$ = (Node *) n;
2232 : }
2233 : | ALTER INDEX IF_P EXISTS qualified_name alter_table_cmds
2234 : {
2235 0 : AlterTableStmt *n = makeNode(AlterTableStmt);
2236 :
2237 0 : n->relation = $5;
2238 0 : n->cmds = $6;
2239 0 : n->objtype = OBJECT_INDEX;
2240 0 : n->missing_ok = true;
2241 0 : $$ = (Node *) n;
2242 : }
2243 : | ALTER INDEX qualified_name index_partition_cmd
2244 : {
2245 386 : AlterTableStmt *n = makeNode(AlterTableStmt);
2246 :
2247 386 : n->relation = $3;
2248 386 : n->cmds = list_make1($4);
2249 386 : n->objtype = OBJECT_INDEX;
2250 386 : n->missing_ok = false;
2251 386 : $$ = (Node *) n;
2252 : }
2253 : | ALTER INDEX ALL IN_P TABLESPACE name SET TABLESPACE name opt_nowait
2254 : {
2255 : AlterTableMoveAllStmt *n =
2256 6 : makeNode(AlterTableMoveAllStmt);
2257 :
2258 6 : n->orig_tablespacename = $6;
2259 6 : n->objtype = OBJECT_INDEX;
2260 6 : n->roles = NIL;
2261 6 : n->new_tablespacename = $9;
2262 6 : n->nowait = $10;
2263 6 : $$ = (Node *) n;
2264 : }
2265 : | ALTER INDEX ALL IN_P TABLESPACE name OWNED BY role_list SET TABLESPACE name opt_nowait
2266 : {
2267 : AlterTableMoveAllStmt *n =
2268 0 : makeNode(AlterTableMoveAllStmt);
2269 :
2270 0 : n->orig_tablespacename = $6;
2271 0 : n->objtype = OBJECT_INDEX;
2272 0 : n->roles = $9;
2273 0 : n->new_tablespacename = $12;
2274 0 : n->nowait = $13;
2275 0 : $$ = (Node *) n;
2276 : }
2277 : | ALTER SEQUENCE qualified_name alter_table_cmds
2278 : {
2279 94 : AlterTableStmt *n = makeNode(AlterTableStmt);
2280 :
2281 94 : n->relation = $3;
2282 94 : n->cmds = $4;
2283 94 : n->objtype = OBJECT_SEQUENCE;
2284 94 : n->missing_ok = false;
2285 94 : $$ = (Node *) n;
2286 : }
2287 : | ALTER SEQUENCE IF_P EXISTS qualified_name alter_table_cmds
2288 : {
2289 0 : AlterTableStmt *n = makeNode(AlterTableStmt);
2290 :
2291 0 : n->relation = $5;
2292 0 : n->cmds = $6;
2293 0 : n->objtype = OBJECT_SEQUENCE;
2294 0 : n->missing_ok = true;
2295 0 : $$ = (Node *) n;
2296 : }
2297 : | ALTER VIEW qualified_name alter_table_cmds
2298 : {
2299 254 : AlterTableStmt *n = makeNode(AlterTableStmt);
2300 :
2301 254 : n->relation = $3;
2302 254 : n->cmds = $4;
2303 254 : n->objtype = OBJECT_VIEW;
2304 254 : n->missing_ok = false;
2305 254 : $$ = (Node *) n;
2306 : }
2307 : | ALTER VIEW IF_P EXISTS qualified_name alter_table_cmds
2308 : {
2309 0 : AlterTableStmt *n = makeNode(AlterTableStmt);
2310 :
2311 0 : n->relation = $5;
2312 0 : n->cmds = $6;
2313 0 : n->objtype = OBJECT_VIEW;
2314 0 : n->missing_ok = true;
2315 0 : $$ = (Node *) n;
2316 : }
2317 : | ALTER MATERIALIZED VIEW qualified_name alter_table_cmds
2318 : {
2319 48 : AlterTableStmt *n = makeNode(AlterTableStmt);
2320 :
2321 48 : n->relation = $4;
2322 48 : n->cmds = $5;
2323 48 : n->objtype = OBJECT_MATVIEW;
2324 48 : n->missing_ok = false;
2325 48 : $$ = (Node *) n;
2326 : }
2327 : | ALTER MATERIALIZED VIEW IF_P EXISTS qualified_name alter_table_cmds
2328 : {
2329 0 : AlterTableStmt *n = makeNode(AlterTableStmt);
2330 :
2331 0 : n->relation = $6;
2332 0 : n->cmds = $7;
2333 0 : n->objtype = OBJECT_MATVIEW;
2334 0 : n->missing_ok = true;
2335 0 : $$ = (Node *) n;
2336 : }
2337 : | ALTER MATERIALIZED VIEW ALL IN_P TABLESPACE name SET TABLESPACE name opt_nowait
2338 : {
2339 : AlterTableMoveAllStmt *n =
2340 12 : makeNode(AlterTableMoveAllStmt);
2341 :
2342 12 : n->orig_tablespacename = $7;
2343 12 : n->objtype = OBJECT_MATVIEW;
2344 12 : n->roles = NIL;
2345 12 : n->new_tablespacename = $10;
2346 12 : n->nowait = $11;
2347 12 : $$ = (Node *) n;
2348 : }
2349 : | ALTER MATERIALIZED VIEW ALL IN_P TABLESPACE name OWNED BY role_list SET TABLESPACE name opt_nowait
2350 : {
2351 : AlterTableMoveAllStmt *n =
2352 0 : makeNode(AlterTableMoveAllStmt);
2353 :
2354 0 : n->orig_tablespacename = $7;
2355 0 : n->objtype = OBJECT_MATVIEW;
2356 0 : n->roles = $10;
2357 0 : n->new_tablespacename = $13;
2358 0 : n->nowait = $14;
2359 0 : $$ = (Node *) n;
2360 : }
2361 : | ALTER FOREIGN TABLE relation_expr alter_table_cmds
2362 : {
2363 378 : AlterTableStmt *n = makeNode(AlterTableStmt);
2364 :
2365 378 : n->relation = $4;
2366 378 : n->cmds = $5;
2367 378 : n->objtype = OBJECT_FOREIGN_TABLE;
2368 378 : n->missing_ok = false;
2369 378 : $$ = (Node *) n;
2370 : }
2371 : | ALTER FOREIGN TABLE IF_P EXISTS relation_expr alter_table_cmds
2372 : {
2373 108 : AlterTableStmt *n = makeNode(AlterTableStmt);
2374 :
2375 108 : n->relation = $6;
2376 108 : n->cmds = $7;
2377 108 : n->objtype = OBJECT_FOREIGN_TABLE;
2378 108 : n->missing_ok = true;
2379 108 : $$ = (Node *) n;
2380 : }
2381 : ;
2382 :
2383 : alter_table_cmds:
2384 27706 : alter_table_cmd { $$ = list_make1($1); }
2385 1020 : | alter_table_cmds ',' alter_table_cmd { $$ = lappend($1, $3); }
2386 : ;
2387 :
2388 : partition_cmd:
2389 : /* ALTER TABLE <name> ATTACH PARTITION <table_name> FOR VALUES */
2390 : ATTACH PARTITION qualified_name PartitionBoundSpec
2391 : {
2392 2460 : AlterTableCmd *n = makeNode(AlterTableCmd);
2393 2460 : PartitionCmd *cmd = makeNode(PartitionCmd);
2394 :
2395 2460 : n->subtype = AT_AttachPartition;
2396 2460 : cmd->name = $3;
2397 2460 : cmd->bound = $4;
2398 2460 : cmd->concurrent = false;
2399 2460 : n->def = (Node *) cmd;
2400 :
2401 2460 : $$ = (Node *) n;
2402 : }
2403 : /* ALTER TABLE <name> DETACH PARTITION <partition_name> [CONCURRENTLY] */
2404 : | DETACH PARTITION qualified_name opt_concurrently
2405 : {
2406 602 : AlterTableCmd *n = makeNode(AlterTableCmd);
2407 602 : PartitionCmd *cmd = makeNode(PartitionCmd);
2408 :
2409 602 : n->subtype = AT_DetachPartition;
2410 602 : cmd->name = $3;
2411 602 : cmd->bound = NULL;
2412 602 : cmd->concurrent = $4;
2413 602 : n->def = (Node *) cmd;
2414 :
2415 602 : $$ = (Node *) n;
2416 : }
2417 : | DETACH PARTITION qualified_name FINALIZE
2418 : {
2419 20 : AlterTableCmd *n = makeNode(AlterTableCmd);
2420 20 : PartitionCmd *cmd = makeNode(PartitionCmd);
2421 :
2422 20 : n->subtype = AT_DetachPartitionFinalize;
2423 20 : cmd->name = $3;
2424 20 : cmd->bound = NULL;
2425 20 : cmd->concurrent = false;
2426 20 : n->def = (Node *) cmd;
2427 20 : $$ = (Node *) n;
2428 : }
2429 : ;
2430 :
2431 : index_partition_cmd:
2432 : /* ALTER INDEX <name> ATTACH PARTITION <index_name> */
2433 : ATTACH PARTITION qualified_name
2434 : {
2435 386 : AlterTableCmd *n = makeNode(AlterTableCmd);
2436 386 : PartitionCmd *cmd = makeNode(PartitionCmd);
2437 :
2438 386 : n->subtype = AT_AttachPartition;
2439 386 : cmd->name = $3;
2440 386 : cmd->bound = NULL;
2441 386 : cmd->concurrent = false;
2442 386 : n->def = (Node *) cmd;
2443 :
2444 386 : $$ = (Node *) n;
2445 : }
2446 : ;
2447 :
2448 : alter_table_cmd:
2449 : /* ALTER TABLE <name> ADD <coldef> */
2450 : ADD_P columnDef
2451 : {
2452 192 : AlterTableCmd *n = makeNode(AlterTableCmd);
2453 :
2454 192 : n->subtype = AT_AddColumn;
2455 192 : n->def = $2;
2456 192 : n->missing_ok = false;
2457 192 : $$ = (Node *) n;
2458 : }
2459 : /* ALTER TABLE <name> ADD IF NOT EXISTS <coldef> */
2460 : | ADD_P IF_P NOT EXISTS columnDef
2461 : {
2462 0 : AlterTableCmd *n = makeNode(AlterTableCmd);
2463 :
2464 0 : n->subtype = AT_AddColumn;
2465 0 : n->def = $5;
2466 0 : n->missing_ok = true;
2467 0 : $$ = (Node *) n;
2468 : }
2469 : /* ALTER TABLE <name> ADD COLUMN <coldef> */
2470 : | ADD_P COLUMN columnDef
2471 : {
2472 1922 : AlterTableCmd *n = makeNode(AlterTableCmd);
2473 :
2474 1922 : n->subtype = AT_AddColumn;
2475 1922 : n->def = $3;
2476 1922 : n->missing_ok = false;
2477 1922 : $$ = (Node *) n;
2478 : }
2479 : /* ALTER TABLE <name> ADD COLUMN IF NOT EXISTS <coldef> */
2480 : | ADD_P COLUMN IF_P NOT EXISTS columnDef
2481 : {
2482 60 : AlterTableCmd *n = makeNode(AlterTableCmd);
2483 :
2484 60 : n->subtype = AT_AddColumn;
2485 60 : n->def = $6;
2486 60 : n->missing_ok = true;
2487 60 : $$ = (Node *) n;
2488 : }
2489 : /* ALTER TABLE <name> ALTER [COLUMN] <colname> {SET DEFAULT <expr>|DROP DEFAULT} */
2490 : | ALTER opt_column ColId alter_column_default
2491 : {
2492 550 : AlterTableCmd *n = makeNode(AlterTableCmd);
2493 :
2494 550 : n->subtype = AT_ColumnDefault;
2495 550 : n->name = $3;
2496 550 : n->def = $4;
2497 550 : $$ = (Node *) n;
2498 : }
2499 : /* ALTER TABLE <name> ALTER [COLUMN] <colname> DROP NOT NULL */
2500 : | ALTER opt_column ColId DROP NOT NULL_P
2501 : {
2502 294 : AlterTableCmd *n = makeNode(AlterTableCmd);
2503 :
2504 294 : n->subtype = AT_DropNotNull;
2505 294 : n->name = $3;
2506 294 : $$ = (Node *) n;
2507 : }
2508 : /* ALTER TABLE <name> ALTER [COLUMN] <colname> SET NOT NULL */
2509 : | ALTER opt_column ColId SET NOT NULL_P
2510 : {
2511 440 : AlterTableCmd *n = makeNode(AlterTableCmd);
2512 :
2513 440 : n->subtype = AT_SetNotNull;
2514 440 : n->name = $3;
2515 440 : $$ = (Node *) n;
2516 : }
2517 : /* ALTER TABLE <name> ALTER [COLUMN] <colname> SET EXPRESSION AS <expr> */
2518 : | ALTER opt_column ColId SET EXPRESSION AS '(' a_expr ')'
2519 : {
2520 174 : AlterTableCmd *n = makeNode(AlterTableCmd);
2521 :
2522 174 : n->subtype = AT_SetExpression;
2523 174 : n->name = $3;
2524 174 : n->def = $8;
2525 174 : $$ = (Node *) n;
2526 : }
2527 : /* ALTER TABLE <name> ALTER [COLUMN] <colname> DROP EXPRESSION */
2528 : | ALTER opt_column ColId DROP EXPRESSION
2529 : {
2530 62 : AlterTableCmd *n = makeNode(AlterTableCmd);
2531 :
2532 62 : n->subtype = AT_DropExpression;
2533 62 : n->name = $3;
2534 62 : $$ = (Node *) n;
2535 : }
2536 : /* ALTER TABLE <name> ALTER [COLUMN] <colname> DROP EXPRESSION IF EXISTS */
2537 : | ALTER opt_column ColId DROP EXPRESSION IF_P EXISTS
2538 : {
2539 12 : AlterTableCmd *n = makeNode(AlterTableCmd);
2540 :
2541 12 : n->subtype = AT_DropExpression;
2542 12 : n->name = $3;
2543 12 : n->missing_ok = true;
2544 12 : $$ = (Node *) n;
2545 : }
2546 : /* ALTER TABLE <name> ALTER [COLUMN] <colname> SET STATISTICS */
2547 : | ALTER opt_column ColId SET STATISTICS set_statistics_value
2548 : {
2549 62 : AlterTableCmd *n = makeNode(AlterTableCmd);
2550 :
2551 62 : n->subtype = AT_SetStatistics;
2552 62 : n->name = $3;
2553 62 : n->def = $6;
2554 62 : $$ = (Node *) n;
2555 : }
2556 : /* ALTER TABLE <name> ALTER [COLUMN] <colnum> SET STATISTICS */
2557 : | ALTER opt_column Iconst SET STATISTICS set_statistics_value
2558 : {
2559 70 : AlterTableCmd *n = makeNode(AlterTableCmd);
2560 :
2561 70 : if ($3 <= 0 || $3 > PG_INT16_MAX)
2562 6 : ereport(ERROR,
2563 : (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
2564 : errmsg("column number must be in range from 1 to %d", PG_INT16_MAX),
2565 : parser_errposition(@3)));
2566 :
2567 64 : n->subtype = AT_SetStatistics;
2568 64 : n->num = (int16) $3;
2569 64 : n->def = $6;
2570 64 : $$ = (Node *) n;
2571 : }
2572 : /* ALTER TABLE <name> ALTER [COLUMN] <colname> SET ( column_parameter = value [, ... ] ) */
2573 : | ALTER opt_column ColId SET reloptions
2574 : {
2575 38 : AlterTableCmd *n = makeNode(AlterTableCmd);
2576 :
2577 38 : n->subtype = AT_SetOptions;
2578 38 : n->name = $3;
2579 38 : n->def = (Node *) $5;
2580 38 : $$ = (Node *) n;
2581 : }
2582 : /* ALTER TABLE <name> ALTER [COLUMN] <colname> RESET ( column_parameter [, ... ] ) */
2583 : | ALTER opt_column ColId RESET reloptions
2584 : {
2585 6 : AlterTableCmd *n = makeNode(AlterTableCmd);
2586 :
2587 6 : n->subtype = AT_ResetOptions;
2588 6 : n->name = $3;
2589 6 : n->def = (Node *) $5;
2590 6 : $$ = (Node *) n;
2591 : }
2592 : /* ALTER TABLE <name> ALTER [COLUMN] <colname> SET STORAGE <storagemode> */
2593 : | ALTER opt_column ColId SET column_storage
2594 : {
2595 238 : AlterTableCmd *n = makeNode(AlterTableCmd);
2596 :
2597 238 : n->subtype = AT_SetStorage;
2598 238 : n->name = $3;
2599 238 : n->def = (Node *) makeString($5);
2600 238 : $$ = (Node *) n;
2601 : }
2602 : /* ALTER TABLE <name> ALTER [COLUMN] <colname> SET COMPRESSION <cm> */
2603 : | ALTER opt_column ColId SET column_compression
2604 : {
2605 78 : AlterTableCmd *n = makeNode(AlterTableCmd);
2606 :
2607 78 : n->subtype = AT_SetCompression;
2608 78 : n->name = $3;
2609 78 : n->def = (Node *) makeString($5);
2610 78 : $$ = (Node *) n;
2611 : }
2612 : /* ALTER TABLE <name> ALTER [COLUMN] <colname> ADD GENERATED ... AS IDENTITY ... */
2613 : | ALTER opt_column ColId ADD_P GENERATED generated_when AS IDENTITY_P OptParenthesizedSeqOptList
2614 : {
2615 172 : AlterTableCmd *n = makeNode(AlterTableCmd);
2616 172 : Constraint *c = makeNode(Constraint);
2617 :
2618 172 : c->contype = CONSTR_IDENTITY;
2619 172 : c->generated_when = $6;
2620 172 : c->options = $9;
2621 172 : c->location = @5;
2622 :
2623 172 : n->subtype = AT_AddIdentity;
2624 172 : n->name = $3;
2625 172 : n->def = (Node *) c;
2626 :
2627 172 : $$ = (Node *) n;
2628 : }
2629 : /* ALTER TABLE <name> ALTER [COLUMN] <colname> SET <sequence options>/RESET */
2630 : | ALTER opt_column ColId alter_identity_column_option_list
2631 : {
2632 62 : AlterTableCmd *n = makeNode(AlterTableCmd);
2633 :
2634 62 : n->subtype = AT_SetIdentity;
2635 62 : n->name = $3;
2636 62 : n->def = (Node *) $4;
2637 62 : $$ = (Node *) n;
2638 : }
2639 : /* ALTER TABLE <name> ALTER [COLUMN] <colname> DROP IDENTITY */
2640 : | ALTER opt_column ColId DROP IDENTITY_P
2641 : {
2642 50 : AlterTableCmd *n = makeNode(AlterTableCmd);
2643 :
2644 50 : n->subtype = AT_DropIdentity;
2645 50 : n->name = $3;
2646 50 : n->missing_ok = false;
2647 50 : $$ = (Node *) n;
2648 : }
2649 : /* ALTER TABLE <name> ALTER [COLUMN] <colname> DROP IDENTITY IF EXISTS */
2650 : | ALTER opt_column ColId DROP IDENTITY_P IF_P EXISTS
2651 : {
2652 6 : AlterTableCmd *n = makeNode(AlterTableCmd);
2653 :
2654 6 : n->subtype = AT_DropIdentity;
2655 6 : n->name = $3;
2656 6 : n->missing_ok = true;
2657 6 : $$ = (Node *) n;
2658 : }
2659 : /* ALTER TABLE <name> DROP [COLUMN] IF EXISTS <colname> [RESTRICT|CASCADE] */
2660 : | DROP opt_column IF_P EXISTS ColId opt_drop_behavior
2661 : {
2662 18 : AlterTableCmd *n = makeNode(AlterTableCmd);
2663 :
2664 18 : n->subtype = AT_DropColumn;
2665 18 : n->name = $5;
2666 18 : n->behavior = $6;
2667 18 : n->missing_ok = true;
2668 18 : $$ = (Node *) n;
2669 : }
2670 : /* ALTER TABLE <name> DROP [COLUMN] <colname> [RESTRICT|CASCADE] */
2671 : | DROP opt_column ColId opt_drop_behavior
2672 : {
2673 1580 : AlterTableCmd *n = makeNode(AlterTableCmd);
2674 :
2675 1580 : n->subtype = AT_DropColumn;
2676 1580 : n->name = $3;
2677 1580 : n->behavior = $4;
2678 1580 : n->missing_ok = false;
2679 1580 : $$ = (Node *) n;
2680 : }
2681 : /*
2682 : * ALTER TABLE <name> ALTER [COLUMN] <colname> [SET DATA] TYPE <typename>
2683 : * [ USING <expression> ]
2684 : */
2685 : | ALTER opt_column ColId opt_set_data TYPE_P Typename opt_collate_clause alter_using
2686 : {
2687 1138 : AlterTableCmd *n = makeNode(AlterTableCmd);
2688 1138 : ColumnDef *def = makeNode(ColumnDef);
2689 :
2690 1138 : n->subtype = AT_AlterColumnType;
2691 1138 : n->name = $3;
2692 1138 : n->def = (Node *) def;
2693 : /* We only use these fields of the ColumnDef node */
2694 1138 : def->typeName = $6;
2695 1138 : def->collClause = (CollateClause *) $7;
2696 1138 : def->raw_default = $8;
2697 1138 : def->location = @3;
2698 1138 : $$ = (Node *) n;
2699 : }
2700 : /* ALTER FOREIGN TABLE <name> ALTER [COLUMN] <colname> OPTIONS */
2701 : | ALTER opt_column ColId alter_generic_options
2702 : {
2703 50 : AlterTableCmd *n = makeNode(AlterTableCmd);
2704 :
2705 50 : n->subtype = AT_AlterColumnGenericOptions;
2706 50 : n->name = $3;
2707 50 : n->def = (Node *) $4;
2708 50 : $$ = (Node *) n;
2709 : }
2710 : /* ALTER TABLE <name> ADD CONSTRAINT ... */
2711 : | ADD_P TableConstraint
2712 : {
2713 14560 : AlterTableCmd *n = makeNode(AlterTableCmd);
2714 :
2715 14560 : n->subtype = AT_AddConstraint;
2716 14560 : n->def = $2;
2717 14560 : $$ = (Node *) n;
2718 : }
2719 : /* ALTER TABLE <name> ALTER CONSTRAINT ... */
2720 : | ALTER CONSTRAINT name ConstraintAttributeSpec
2721 : {
2722 240 : AlterTableCmd *n = makeNode(AlterTableCmd);
2723 240 : ATAlterConstraint *c = makeNode(ATAlterConstraint);
2724 :
2725 240 : n->subtype = AT_AlterConstraint;
2726 240 : n->def = (Node *) c;
2727 240 : c->conname = $3;
2728 240 : if ($4 & (CAS_NOT_ENFORCED | CAS_ENFORCED))
2729 84 : c->alterEnforceability = true;
2730 240 : if ($4 & (CAS_DEFERRABLE | CAS_NOT_DEFERRABLE |
2731 : CAS_INITIALLY_DEFERRED | CAS_INITIALLY_IMMEDIATE))
2732 120 : c->alterDeferrability = true;
2733 240 : if ($4 & CAS_NO_INHERIT)
2734 30 : c->alterInheritability = true;
2735 : /* handle unsupported case with specific error message */
2736 240 : if ($4 & CAS_NOT_VALID)
2737 12 : ereport(ERROR,
2738 : errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
2739 : errmsg("constraints cannot be altered to be NOT VALID"),
2740 : parser_errposition(@4));
2741 228 : processCASbits($4, @4, "FOREIGN KEY",
2742 : &c->deferrable,
2743 : &c->initdeferred,
2744 : &c->is_enforced,
2745 : NULL,
2746 : &c->noinherit,
2747 : yyscanner);
2748 228 : $$ = (Node *) n;
2749 : }
2750 : /* ALTER TABLE <name> ALTER CONSTRAINT INHERIT */
2751 : | ALTER CONSTRAINT name INHERIT
2752 : {
2753 66 : AlterTableCmd *n = makeNode(AlterTableCmd);
2754 66 : ATAlterConstraint *c = makeNode(ATAlterConstraint);
2755 :
2756 66 : n->subtype = AT_AlterConstraint;
2757 66 : n->def = (Node *) c;
2758 66 : c->conname = $3;
2759 66 : c->alterInheritability = true;
2760 66 : c->noinherit = false;
2761 :
2762 66 : $$ = (Node *) n;
2763 : }
2764 : /* ALTER TABLE <name> VALIDATE CONSTRAINT ... */
2765 : | VALIDATE CONSTRAINT name
2766 : {
2767 476 : AlterTableCmd *n = makeNode(AlterTableCmd);
2768 :
2769 476 : n->subtype = AT_ValidateConstraint;
2770 476 : n->name = $3;
2771 476 : $$ = (Node *) n;
2772 : }
2773 : /* ALTER TABLE <name> DROP CONSTRAINT IF EXISTS <name> [RESTRICT|CASCADE] */
2774 : | DROP CONSTRAINT IF_P EXISTS name opt_drop_behavior
2775 : {
2776 18 : AlterTableCmd *n = makeNode(AlterTableCmd);
2777 :
2778 18 : n->subtype = AT_DropConstraint;
2779 18 : n->name = $5;
2780 18 : n->behavior = $6;
2781 18 : n->missing_ok = true;
2782 18 : $$ = (Node *) n;
2783 : }
2784 : /* ALTER TABLE <name> DROP CONSTRAINT <name> [RESTRICT|CASCADE] */
2785 : | DROP CONSTRAINT name opt_drop_behavior
2786 : {
2787 818 : AlterTableCmd *n = makeNode(AlterTableCmd);
2788 :
2789 818 : n->subtype = AT_DropConstraint;
2790 818 : n->name = $3;
2791 818 : n->behavior = $4;
2792 818 : n->missing_ok = false;
2793 818 : $$ = (Node *) n;
2794 : }
2795 : /* ALTER TABLE <name> SET WITHOUT OIDS, for backward compat */
2796 : | SET WITHOUT OIDS
2797 : {
2798 6 : AlterTableCmd *n = makeNode(AlterTableCmd);
2799 :
2800 6 : n->subtype = AT_DropOids;
2801 6 : $$ = (Node *) n;
2802 : }
2803 : /* ALTER TABLE <name> CLUSTER ON <indexname> */
2804 : | CLUSTER ON name
2805 : {
2806 46 : AlterTableCmd *n = makeNode(AlterTableCmd);
2807 :
2808 46 : n->subtype = AT_ClusterOn;
2809 46 : n->name = $3;
2810 46 : $$ = (Node *) n;
2811 : }
2812 : /* ALTER TABLE <name> SET WITHOUT CLUSTER */
2813 : | SET WITHOUT CLUSTER
2814 : {
2815 18 : AlterTableCmd *n = makeNode(AlterTableCmd);
2816 :
2817 18 : n->subtype = AT_DropCluster;
2818 18 : n->name = NULL;
2819 18 : $$ = (Node *) n;
2820 : }
2821 : /* ALTER TABLE <name> SET LOGGED */
2822 : | SET LOGGED
2823 : {
2824 50 : AlterTableCmd *n = makeNode(AlterTableCmd);
2825 :
2826 50 : n->subtype = AT_SetLogged;
2827 50 : $$ = (Node *) n;
2828 : }
2829 : /* ALTER TABLE <name> SET UNLOGGED */
2830 : | SET UNLOGGED
2831 : {
2832 62 : AlterTableCmd *n = makeNode(AlterTableCmd);
2833 :
2834 62 : n->subtype = AT_SetUnLogged;
2835 62 : $$ = (Node *) n;
2836 : }
2837 : /* ALTER TABLE <name> ENABLE TRIGGER <trig> */
2838 : | ENABLE_P TRIGGER name
2839 : {
2840 122 : AlterTableCmd *n = makeNode(AlterTableCmd);
2841 :
2842 122 : n->subtype = AT_EnableTrig;
2843 122 : n->name = $3;
2844 122 : $$ = (Node *) n;
2845 : }
2846 : /* ALTER TABLE <name> ENABLE ALWAYS TRIGGER <trig> */
2847 : | ENABLE_P ALWAYS TRIGGER name
2848 : {
2849 42 : AlterTableCmd *n = makeNode(AlterTableCmd);
2850 :
2851 42 : n->subtype = AT_EnableAlwaysTrig;
2852 42 : n->name = $4;
2853 42 : $$ = (Node *) n;
2854 : }
2855 : /* ALTER TABLE <name> ENABLE REPLICA TRIGGER <trig> */
2856 : | ENABLE_P REPLICA TRIGGER name
2857 : {
2858 16 : AlterTableCmd *n = makeNode(AlterTableCmd);
2859 :
2860 16 : n->subtype = AT_EnableReplicaTrig;
2861 16 : n->name = $4;
2862 16 : $$ = (Node *) n;
2863 : }
2864 : /* ALTER TABLE <name> ENABLE TRIGGER ALL */
2865 : | ENABLE_P TRIGGER ALL
2866 : {
2867 0 : AlterTableCmd *n = makeNode(AlterTableCmd);
2868 :
2869 0 : n->subtype = AT_EnableTrigAll;
2870 0 : $$ = (Node *) n;
2871 : }
2872 : /* ALTER TABLE <name> ENABLE TRIGGER USER */
2873 : | ENABLE_P TRIGGER USER
2874 : {
2875 0 : AlterTableCmd *n = makeNode(AlterTableCmd);
2876 :
2877 0 : n->subtype = AT_EnableTrigUser;
2878 0 : $$ = (Node *) n;
2879 : }
2880 : /* ALTER TABLE <name> DISABLE TRIGGER <trig> */
2881 : | DISABLE_P TRIGGER name
2882 : {
2883 138 : AlterTableCmd *n = makeNode(AlterTableCmd);
2884 :
2885 138 : n->subtype = AT_DisableTrig;
2886 138 : n->name = $3;
2887 138 : $$ = (Node *) n;
2888 : }
2889 : /* ALTER TABLE <name> DISABLE TRIGGER ALL */
2890 : | DISABLE_P TRIGGER ALL
2891 : {
2892 12 : AlterTableCmd *n = makeNode(AlterTableCmd);
2893 :
2894 12 : n->subtype = AT_DisableTrigAll;
2895 12 : $$ = (Node *) n;
2896 : }
2897 : /* ALTER TABLE <name> DISABLE TRIGGER USER */
2898 : | DISABLE_P TRIGGER USER
2899 : {
2900 12 : AlterTableCmd *n = makeNode(AlterTableCmd);
2901 :
2902 12 : n->subtype = AT_DisableTrigUser;
2903 12 : $$ = (Node *) n;
2904 : }
2905 : /* ALTER TABLE <name> ENABLE RULE <rule> */
2906 : | ENABLE_P RULE name
2907 : {
2908 8 : AlterTableCmd *n = makeNode(AlterTableCmd);
2909 :
2910 8 : n->subtype = AT_EnableRule;
2911 8 : n->name = $3;
2912 8 : $$ = (Node *) n;
2913 : }
2914 : /* ALTER TABLE <name> ENABLE ALWAYS RULE <rule> */
2915 : | ENABLE_P ALWAYS RULE name
2916 : {
2917 0 : AlterTableCmd *n = makeNode(AlterTableCmd);
2918 :
2919 0 : n->subtype = AT_EnableAlwaysRule;
2920 0 : n->name = $4;
2921 0 : $$ = (Node *) n;
2922 : }
2923 : /* ALTER TABLE <name> ENABLE REPLICA RULE <rule> */
2924 : | ENABLE_P REPLICA RULE name
2925 : {
2926 6 : AlterTableCmd *n = makeNode(AlterTableCmd);
2927 :
2928 6 : n->subtype = AT_EnableReplicaRule;
2929 6 : n->name = $4;
2930 6 : $$ = (Node *) n;
2931 : }
2932 : /* ALTER TABLE <name> DISABLE RULE <rule> */
2933 : | DISABLE_P RULE name
2934 : {
2935 32 : AlterTableCmd *n = makeNode(AlterTableCmd);
2936 :
2937 32 : n->subtype = AT_DisableRule;
2938 32 : n->name = $3;
2939 32 : $$ = (Node *) n;
2940 : }
2941 : /* ALTER TABLE <name> INHERIT <parent> */
2942 : | INHERIT qualified_name
2943 : {
2944 464 : AlterTableCmd *n = makeNode(AlterTableCmd);
2945 :
2946 464 : n->subtype = AT_AddInherit;
2947 464 : n->def = (Node *) $2;
2948 464 : $$ = (Node *) n;
2949 : }
2950 : /* ALTER TABLE <name> NO INHERIT <parent> */
2951 : | NO INHERIT qualified_name
2952 : {
2953 94 : AlterTableCmd *n = makeNode(AlterTableCmd);
2954 :
2955 94 : n->subtype = AT_DropInherit;
2956 94 : n->def = (Node *) $3;
2957 94 : $$ = (Node *) n;
2958 : }
2959 : /* ALTER TABLE <name> OF <type_name> */
2960 : | OF any_name
2961 : {
2962 66 : AlterTableCmd *n = makeNode(AlterTableCmd);
2963 66 : TypeName *def = makeTypeNameFromNameList($2);
2964 :
2965 66 : def->location = @2;
2966 66 : n->subtype = AT_AddOf;
2967 66 : n->def = (Node *) def;
2968 66 : $$ = (Node *) n;
2969 : }
2970 : /* ALTER TABLE <name> NOT OF */
2971 : | NOT OF
2972 : {
2973 6 : AlterTableCmd *n = makeNode(AlterTableCmd);
2974 :
2975 6 : n->subtype = AT_DropOf;
2976 6 : $$ = (Node *) n;
2977 : }
2978 : /* ALTER TABLE <name> OWNER TO RoleSpec */
2979 : | OWNER TO RoleSpec
2980 : {
2981 2030 : AlterTableCmd *n = makeNode(AlterTableCmd);
2982 :
2983 2030 : n->subtype = AT_ChangeOwner;
2984 2030 : n->newowner = $3;
2985 2030 : $$ = (Node *) n;
2986 : }
2987 : /* ALTER TABLE <name> SET ACCESS METHOD { <amname> | DEFAULT } */
2988 : | SET ACCESS METHOD set_access_method_name
2989 : {
2990 128 : AlterTableCmd *n = makeNode(AlterTableCmd);
2991 :
2992 128 : n->subtype = AT_SetAccessMethod;
2993 128 : n->name = $4;
2994 128 : $$ = (Node *) n;
2995 : }
2996 : /* ALTER TABLE <name> SET TABLESPACE <tablespacename> */
2997 : | SET TABLESPACE name
2998 : {
2999 110 : AlterTableCmd *n = makeNode(AlterTableCmd);
3000 :
3001 110 : n->subtype = AT_SetTableSpace;
3002 110 : n->name = $3;
3003 110 : $$ = (Node *) n;
3004 : }
3005 : /* ALTER TABLE <name> SET (...) */
3006 : | SET reloptions
3007 : {
3008 616 : AlterTableCmd *n = makeNode(AlterTableCmd);
3009 :
3010 616 : n->subtype = AT_SetRelOptions;
3011 616 : n->def = (Node *) $2;
3012 616 : $$ = (Node *) n;
3013 : }
3014 : /* ALTER TABLE <name> RESET (...) */
3015 : | RESET reloptions
3016 : {
3017 170 : AlterTableCmd *n = makeNode(AlterTableCmd);
3018 :
3019 170 : n->subtype = AT_ResetRelOptions;
3020 170 : n->def = (Node *) $2;
3021 170 : $$ = (Node *) n;
3022 : }
3023 : /* ALTER TABLE <name> REPLICA IDENTITY */
3024 : | REPLICA IDENTITY_P replica_identity
3025 : {
3026 494 : AlterTableCmd *n = makeNode(AlterTableCmd);
3027 :
3028 494 : n->subtype = AT_ReplicaIdentity;
3029 494 : n->def = $3;
3030 494 : $$ = (Node *) n;
3031 : }
3032 : /* ALTER TABLE <name> ENABLE ROW LEVEL SECURITY */
3033 : | ENABLE_P ROW LEVEL SECURITY
3034 : {
3035 338 : AlterTableCmd *n = makeNode(AlterTableCmd);
3036 :
3037 338 : n->subtype = AT_EnableRowSecurity;
3038 338 : $$ = (Node *) n;
3039 : }
3040 : /* ALTER TABLE <name> DISABLE ROW LEVEL SECURITY */
3041 : | DISABLE_P ROW LEVEL SECURITY
3042 : {
3043 10 : AlterTableCmd *n = makeNode(AlterTableCmd);
3044 :
3045 10 : n->subtype = AT_DisableRowSecurity;
3046 10 : $$ = (Node *) n;
3047 : }
3048 : /* ALTER TABLE <name> FORCE ROW LEVEL SECURITY */
3049 : | FORCE ROW LEVEL SECURITY
3050 : {
3051 100 : AlterTableCmd *n = makeNode(AlterTableCmd);
3052 :
3053 100 : n->subtype = AT_ForceRowSecurity;
3054 100 : $$ = (Node *) n;
3055 : }
3056 : /* ALTER TABLE <name> NO FORCE ROW LEVEL SECURITY */
3057 : | NO FORCE ROW LEVEL SECURITY
3058 : {
3059 32 : AlterTableCmd *n = makeNode(AlterTableCmd);
3060 :
3061 32 : n->subtype = AT_NoForceRowSecurity;
3062 32 : $$ = (Node *) n;
3063 : }
3064 : | alter_generic_options
3065 : {
3066 64 : AlterTableCmd *n = makeNode(AlterTableCmd);
3067 :
3068 64 : n->subtype = AT_GenericOptions;
3069 64 : n->def = (Node *) $1;
3070 64 : $$ = (Node *) n;
3071 : }
3072 : ;
3073 :
3074 : alter_column_default:
3075 378 : SET DEFAULT a_expr { $$ = $3; }
3076 186 : | DROP DEFAULT { $$ = NULL; }
3077 : ;
3078 :
3079 : opt_collate_clause:
3080 : COLLATE any_name
3081 : {
3082 18 : CollateClause *n = makeNode(CollateClause);
3083 :
3084 18 : n->arg = NULL;
3085 18 : n->collname = $2;
3086 18 : n->location = @1;
3087 18 : $$ = (Node *) n;
3088 : }
3089 4846 : | /* EMPTY */ { $$ = NULL; }
3090 : ;
3091 :
3092 : alter_using:
3093 180 : USING a_expr { $$ = $2; }
3094 958 : | /* EMPTY */ { $$ = NULL; }
3095 : ;
3096 :
3097 : replica_identity:
3098 : NOTHING
3099 : {
3100 48 : ReplicaIdentityStmt *n = makeNode(ReplicaIdentityStmt);
3101 :
3102 48 : n->identity_type = REPLICA_IDENTITY_NOTHING;
3103 48 : n->name = NULL;
3104 48 : $$ = (Node *) n;
3105 : }
3106 : | FULL
3107 : {
3108 170 : ReplicaIdentityStmt *n = makeNode(ReplicaIdentityStmt);
3109 :
3110 170 : n->identity_type = REPLICA_IDENTITY_FULL;
3111 170 : n->name = NULL;
3112 170 : $$ = (Node *) n;
3113 : }
3114 : | DEFAULT
3115 : {
3116 6 : ReplicaIdentityStmt *n = makeNode(ReplicaIdentityStmt);
3117 :
3118 6 : n->identity_type = REPLICA_IDENTITY_DEFAULT;
3119 6 : n->name = NULL;
3120 6 : $$ = (Node *) n;
3121 : }
3122 : | USING INDEX name
3123 : {
3124 270 : ReplicaIdentityStmt *n = makeNode(ReplicaIdentityStmt);
3125 :
3126 270 : n->identity_type = REPLICA_IDENTITY_INDEX;
3127 270 : n->name = $3;
3128 270 : $$ = (Node *) n;
3129 : }
3130 : ;
3131 :
3132 : reloptions:
3133 2820 : '(' reloption_list ')' { $$ = $2; }
3134 : ;
3135 :
3136 966 : opt_reloptions: WITH reloptions { $$ = $2; }
3137 23540 : | /* EMPTY */ { $$ = NIL; }
3138 : ;
3139 :
3140 : reloption_list:
3141 2820 : reloption_elem { $$ = list_make1($1); }
3142 252 : | reloption_list ',' reloption_elem { $$ = lappend($1, $3); }
3143 : ;
3144 :
3145 : /* This should match def_elem and also allow qualified names */
3146 : reloption_elem:
3147 : ColLabel '=' def_arg
3148 : {
3149 2410 : $$ = makeDefElem($1, (Node *) $3, @1);
3150 : }
3151 : | ColLabel
3152 : {
3153 584 : $$ = makeDefElem($1, NULL, @1);
3154 : }
3155 : | ColLabel '.' ColLabel '=' def_arg
3156 : {
3157 72 : $$ = makeDefElemExtended($1, $3, (Node *) $5,
3158 72 : DEFELEM_UNSPEC, @1);
3159 : }
3160 : | ColLabel '.' ColLabel
3161 : {
3162 6 : $$ = makeDefElemExtended($1, $3, NULL, DEFELEM_UNSPEC, @1);
3163 : }
3164 : ;
3165 :
3166 : alter_identity_column_option_list:
3167 : alter_identity_column_option
3168 62 : { $$ = list_make1($1); }
3169 : | alter_identity_column_option_list alter_identity_column_option
3170 60 : { $$ = lappend($1, $2); }
3171 : ;
3172 :
3173 : alter_identity_column_option:
3174 : RESTART
3175 : {
3176 24 : $$ = makeDefElem("restart", NULL, @1);
3177 : }
3178 : | RESTART opt_with NumericOnly
3179 : {
3180 0 : $$ = makeDefElem("restart", (Node *) $3, @1);
3181 : }
3182 : | SET SeqOptElem
3183 : {
3184 54 : if (strcmp($2->defname, "as") == 0 ||
3185 54 : strcmp($2->defname, "restart") == 0 ||
3186 54 : strcmp($2->defname, "owned_by") == 0)
3187 0 : ereport(ERROR,
3188 : (errcode(ERRCODE_SYNTAX_ERROR),
3189 : errmsg("sequence option \"%s\" not supported here", $2->defname),
3190 : parser_errposition(@2)));
3191 54 : $$ = $2;
3192 : }
3193 : | SET GENERATED generated_when
3194 : {
3195 44 : $$ = makeDefElem("generated", (Node *) makeInteger($3), @1);
3196 : }
3197 : ;
3198 :
3199 : set_statistics_value:
3200 158 : SignedIconst { $$ = (Node *) makeInteger($1); }
3201 0 : | DEFAULT { $$ = NULL; }
3202 : ;
3203 :
3204 : set_access_method_name:
3205 92 : ColId { $$ = $1; }
3206 36 : | DEFAULT { $$ = NULL; }
3207 : ;
3208 :
3209 : PartitionBoundSpec:
3210 : /* a HASH partition */
3211 : FOR VALUES WITH '(' hash_partbound ')'
3212 : {
3213 : ListCell *lc;
3214 732 : PartitionBoundSpec *n = makeNode(PartitionBoundSpec);
3215 :
3216 732 : n->strategy = PARTITION_STRATEGY_HASH;
3217 732 : n->modulus = n->remainder = -1;
3218 :
3219 2196 : foreach (lc, $5)
3220 : {
3221 1464 : DefElem *opt = lfirst_node(DefElem, lc);
3222 :
3223 1464 : if (strcmp(opt->defname, "modulus") == 0)
3224 : {
3225 732 : if (n->modulus != -1)
3226 0 : ereport(ERROR,
3227 : (errcode(ERRCODE_DUPLICATE_OBJECT),
3228 : errmsg("modulus for hash partition provided more than once"),
3229 : parser_errposition(opt->location)));
3230 732 : n->modulus = defGetInt32(opt);
3231 : }
3232 732 : else if (strcmp(opt->defname, "remainder") == 0)
3233 : {
3234 732 : if (n->remainder != -1)
3235 0 : ereport(ERROR,
3236 : (errcode(ERRCODE_DUPLICATE_OBJECT),
3237 : errmsg("remainder for hash partition provided more than once"),
3238 : parser_errposition(opt->location)));
3239 732 : n->remainder = defGetInt32(opt);
3240 : }
3241 : else
3242 0 : ereport(ERROR,
3243 : (errcode(ERRCODE_SYNTAX_ERROR),
3244 : errmsg("unrecognized hash partition bound specification \"%s\"",
3245 : opt->defname),
3246 : parser_errposition(opt->location)));
3247 : }
3248 :
3249 732 : if (n->modulus == -1)
3250 0 : ereport(ERROR,
3251 : (errcode(ERRCODE_SYNTAX_ERROR),
3252 : errmsg("modulus for hash partition must be specified"),
3253 : parser_errposition(@3)));
3254 732 : if (n->remainder == -1)
3255 0 : ereport(ERROR,
3256 : (errcode(ERRCODE_SYNTAX_ERROR),
3257 : errmsg("remainder for hash partition must be specified"),
3258 : parser_errposition(@3)));
3259 :
3260 732 : n->location = @3;
3261 :
3262 732 : $$ = n;
3263 : }
3264 :
3265 : /* a LIST partition */
3266 : | FOR VALUES IN_P '(' expr_list ')'
3267 : {
3268 5018 : PartitionBoundSpec *n = makeNode(PartitionBoundSpec);
3269 :
3270 5018 : n->strategy = PARTITION_STRATEGY_LIST;
3271 5018 : n->is_default = false;
3272 5018 : n->listdatums = $5;
3273 5018 : n->location = @3;
3274 :
3275 5018 : $$ = n;
3276 : }
3277 :
3278 : /* a RANGE partition */
3279 : | FOR VALUES FROM '(' expr_list ')' TO '(' expr_list ')'
3280 : {
3281 4328 : PartitionBoundSpec *n = makeNode(PartitionBoundSpec);
3282 :
3283 4328 : n->strategy = PARTITION_STRATEGY_RANGE;
3284 4328 : n->is_default = false;
3285 4328 : n->lowerdatums = $5;
3286 4328 : n->upperdatums = $9;
3287 4328 : n->location = @3;
3288 :
3289 4328 : $$ = n;
3290 : }
3291 :
3292 : /* a DEFAULT partition */
3293 : | DEFAULT
3294 : {
3295 604 : PartitionBoundSpec *n = makeNode(PartitionBoundSpec);
3296 :
3297 604 : n->is_default = true;
3298 604 : n->location = @1;
3299 :
3300 604 : $$ = n;
3301 : }
3302 : ;
3303 :
3304 : hash_partbound_elem:
3305 : NonReservedWord Iconst
3306 : {
3307 1464 : $$ = makeDefElem($1, (Node *) makeInteger($2), @1);
3308 : }
3309 : ;
3310 :
3311 : hash_partbound:
3312 : hash_partbound_elem
3313 : {
3314 732 : $$ = list_make1($1);
3315 : }
3316 : | hash_partbound ',' hash_partbound_elem
3317 : {
3318 732 : $$ = lappend($1, $3);
3319 : }
3320 : ;
3321 :
3322 : /*****************************************************************************
3323 : *
3324 : * ALTER TYPE
3325 : *
3326 : * really variants of the ALTER TABLE subcommands with different spellings
3327 : *****************************************************************************/
3328 :
3329 : AlterCompositeTypeStmt:
3330 : ALTER TYPE_P any_name alter_type_cmds
3331 : {
3332 210 : AlterTableStmt *n = makeNode(AlterTableStmt);
3333 :
3334 : /* can't use qualified_name, sigh */
3335 210 : n->relation = makeRangeVarFromAnyName($3, @3, yyscanner);
3336 210 : n->cmds = $4;
3337 210 : n->objtype = OBJECT_TYPE;
3338 210 : $$ = (Node *) n;
3339 : }
3340 : ;
3341 :
3342 : alter_type_cmds:
3343 210 : alter_type_cmd { $$ = list_make1($1); }
3344 12 : | alter_type_cmds ',' alter_type_cmd { $$ = lappend($1, $3); }
3345 : ;
3346 :
3347 : alter_type_cmd:
3348 : /* ALTER TYPE <name> ADD ATTRIBUTE <coldef> [RESTRICT|CASCADE] */
3349 : ADD_P ATTRIBUTE TableFuncElement opt_drop_behavior
3350 : {
3351 64 : AlterTableCmd *n = makeNode(AlterTableCmd);
3352 :
3353 64 : n->subtype = AT_AddColumn;
3354 64 : n->def = $3;
3355 64 : n->behavior = $4;
3356 64 : $$ = (Node *) n;
3357 : }
3358 : /* ALTER TYPE <name> DROP ATTRIBUTE IF EXISTS <attname> [RESTRICT|CASCADE] */
3359 : | DROP ATTRIBUTE IF_P EXISTS ColId opt_drop_behavior
3360 : {
3361 6 : AlterTableCmd *n = makeNode(AlterTableCmd);
3362 :
3363 6 : n->subtype = AT_DropColumn;
3364 6 : n->name = $5;
3365 6 : n->behavior = $6;
3366 6 : n->missing_ok = true;
3367 6 : $$ = (Node *) n;
3368 : }
3369 : /* ALTER TYPE <name> DROP ATTRIBUTE <attname> [RESTRICT|CASCADE] */
3370 : | DROP ATTRIBUTE ColId opt_drop_behavior
3371 : {
3372 78 : AlterTableCmd *n = makeNode(AlterTableCmd);
3373 :
3374 78 : n->subtype = AT_DropColumn;
3375 78 : n->name = $3;
3376 78 : n->behavior = $4;
3377 78 : n->missing_ok = false;
3378 78 : $$ = (Node *) n;
3379 : }
3380 : /* ALTER TYPE <name> ALTER ATTRIBUTE <attname> [SET DATA] TYPE <typename> [RESTRICT|CASCADE] */
3381 : | ALTER ATTRIBUTE ColId opt_set_data TYPE_P Typename opt_collate_clause opt_drop_behavior
3382 : {
3383 74 : AlterTableCmd *n = makeNode(AlterTableCmd);
3384 74 : ColumnDef *def = makeNode(ColumnDef);
3385 :
3386 74 : n->subtype = AT_AlterColumnType;
3387 74 : n->name = $3;
3388 74 : n->def = (Node *) def;
3389 74 : n->behavior = $8;
3390 : /* We only use these fields of the ColumnDef node */
3391 74 : def->typeName = $6;
3392 74 : def->collClause = (CollateClause *) $7;
3393 74 : def->raw_default = NULL;
3394 74 : def->location = @3;
3395 74 : $$ = (Node *) n;
3396 : }
3397 : ;
3398 :
3399 :
3400 : /*****************************************************************************
3401 : *
3402 : * QUERY :
3403 : * close <portalname>
3404 : *
3405 : *****************************************************************************/
3406 :
3407 : ClosePortalStmt:
3408 : CLOSE cursor_name
3409 : {
3410 2236 : ClosePortalStmt *n = makeNode(ClosePortalStmt);
3411 :
3412 2236 : n->portalname = $2;
3413 2236 : $$ = (Node *) n;
3414 : }
3415 : | CLOSE ALL
3416 : {
3417 12 : ClosePortalStmt *n = makeNode(ClosePortalStmt);
3418 :
3419 12 : n->portalname = NULL;
3420 12 : $$ = (Node *) n;
3421 : }
3422 : ;
3423 :
3424 :
3425 : /*****************************************************************************
3426 : *
3427 : * QUERY :
3428 : * COPY relname [(columnList)] FROM/TO file [WITH] [(options)]
3429 : * COPY ( query ) TO file [WITH] [(options)]
3430 : *
3431 : * where 'query' can be one of:
3432 : * { SELECT | UPDATE | INSERT | DELETE | MERGE }
3433 : *
3434 : * and 'file' can be one of:
3435 : * { PROGRAM 'command' | STDIN | STDOUT | 'filename' }
3436 : *
3437 : * In the preferred syntax the options are comma-separated
3438 : * and use generic identifiers instead of keywords. The pre-9.0
3439 : * syntax had a hard-wired, space-separated set of options.
3440 : *
3441 : * Really old syntax, from versions 7.2 and prior:
3442 : * COPY [ BINARY ] table FROM/TO file
3443 : * [ [ USING ] DELIMITERS 'delimiter' ] ]
3444 : * [ WITH NULL AS 'null string' ]
3445 : * This option placement is not supported with COPY (query...).
3446 : *
3447 : *****************************************************************************/
3448 :
3449 : CopyStmt: COPY opt_binary qualified_name opt_column_list
3450 : copy_from opt_program copy_file_name copy_delimiter opt_with
3451 : copy_options where_clause
3452 : {
3453 10756 : CopyStmt *n = makeNode(CopyStmt);
3454 :
3455 10756 : n->relation = $3;
3456 10756 : n->query = NULL;
3457 10756 : n->attlist = $4;
3458 10756 : n->is_from = $5;
3459 10756 : n->is_program = $6;
3460 10756 : n->filename = $7;
3461 10756 : n->whereClause = $11;
3462 :
3463 10756 : if (n->is_program && n->filename == NULL)
3464 0 : ereport(ERROR,
3465 : (errcode(ERRCODE_SYNTAX_ERROR),
3466 : errmsg("STDIN/STDOUT not allowed with PROGRAM"),
3467 : parser_errposition(@8)));
3468 :
3469 10756 : if (!n->is_from && n->whereClause != NULL)
3470 6 : ereport(ERROR,
3471 : (errcode(ERRCODE_SYNTAX_ERROR),
3472 : errmsg("WHERE clause not allowed with COPY TO"),
3473 : errhint("Try the COPY (SELECT ... WHERE ...) TO variant."),
3474 : parser_errposition(@11)));
3475 :
3476 10750 : n->options = NIL;
3477 : /* Concatenate user-supplied flags */
3478 10750 : if ($2)
3479 12 : n->options = lappend(n->options, $2);
3480 10750 : if ($8)
3481 0 : n->options = lappend(n->options, $8);
3482 10750 : if ($10)
3483 992 : n->options = list_concat(n->options, $10);
3484 10750 : $$ = (Node *) n;
3485 : }
3486 : | COPY '(' PreparableStmt ')' TO opt_program copy_file_name opt_with copy_options
3487 : {
3488 580 : CopyStmt *n = makeNode(CopyStmt);
3489 :
3490 580 : n->relation = NULL;
3491 580 : n->query = $3;
3492 580 : n->attlist = NIL;
3493 580 : n->is_from = false;
3494 580 : n->is_program = $6;
3495 580 : n->filename = $7;
3496 580 : n->options = $9;
3497 :
3498 580 : if (n->is_program && n->filename == NULL)
3499 0 : ereport(ERROR,
3500 : (errcode(ERRCODE_SYNTAX_ERROR),
3501 : errmsg("STDIN/STDOUT not allowed with PROGRAM"),
3502 : parser_errposition(@5)));
3503 :
3504 580 : $$ = (Node *) n;
3505 : }
3506 : ;
3507 :
3508 : copy_from:
3509 1882 : FROM { $$ = true; }
3510 8874 : | TO { $$ = false; }
3511 : ;
3512 :
3513 : opt_program:
3514 0 : PROGRAM { $$ = true; }
3515 11336 : | /* EMPTY */ { $$ = false; }
3516 : ;
3517 :
3518 : /*
3519 : * copy_file_name NULL indicates stdio is used. Whether stdin or stdout is
3520 : * used depends on the direction. (It really doesn't make sense to copy from
3521 : * stdout. We silently correct the "typo".) - AY 9/94
3522 : */
3523 : copy_file_name:
3524 452 : Sconst { $$ = $1; }
3525 1494 : | STDIN { $$ = NULL; }
3526 9390 : | STDOUT { $$ = NULL; }
3527 : ;
3528 :
3529 10614 : copy_options: copy_opt_list { $$ = $1; }
3530 722 : | '(' copy_generic_opt_list ')' { $$ = $2; }
3531 : ;
3532 :
3533 : /* old COPY option syntax */
3534 : copy_opt_list:
3535 504 : copy_opt_list copy_opt_item { $$ = lappend($1, $2); }
3536 10614 : | /* EMPTY */ { $$ = NIL; }
3537 : ;
3538 :
3539 : copy_opt_item:
3540 : BINARY
3541 : {
3542 0 : $$ = makeDefElem("format", (Node *) makeString("binary"), @1);
3543 : }
3544 : | FREEZE
3545 : {
3546 50 : $$ = makeDefElem("freeze", (Node *) makeBoolean(true), @1);
3547 : }
3548 : | DELIMITER opt_as Sconst
3549 : {
3550 172 : $$ = makeDefElem("delimiter", (Node *) makeString($3), @1);
3551 : }
3552 : | NULL_P opt_as Sconst
3553 : {
3554 48 : $$ = makeDefElem("null", (Node *) makeString($3), @1);
3555 : }
3556 : | CSV
3557 : {
3558 150 : $$ = makeDefElem("format", (Node *) makeString("csv"), @1);
3559 : }
3560 : | HEADER_P
3561 : {
3562 18 : $$ = makeDefElem("header", (Node *) makeBoolean(true), @1);
3563 : }
3564 : | QUOTE opt_as Sconst
3565 : {
3566 18 : $$ = makeDefElem("quote", (Node *) makeString($3), @1);
3567 : }
3568 : | ESCAPE opt_as Sconst
3569 : {
3570 18 : $$ = makeDefElem("escape", (Node *) makeString($3), @1);
3571 : }
3572 : | FORCE QUOTE columnList
3573 : {
3574 12 : $$ = makeDefElem("force_quote", (Node *) $3, @1);
3575 : }
3576 : | FORCE QUOTE '*'
3577 : {
3578 6 : $$ = makeDefElem("force_quote", (Node *) makeNode(A_Star), @1);
3579 : }
3580 : | FORCE NOT NULL_P columnList
3581 : {
3582 0 : $$ = makeDefElem("force_not_null", (Node *) $4, @1);
3583 : }
3584 : | FORCE NOT NULL_P '*'
3585 : {
3586 0 : $$ = makeDefElem("force_not_null", (Node *) makeNode(A_Star), @1);
3587 : }
3588 : | FORCE NULL_P columnList
3589 : {
3590 0 : $$ = makeDefElem("force_null", (Node *) $3, @1);
3591 : }
3592 : | FORCE NULL_P '*'
3593 : {
3594 0 : $$ = makeDefElem("force_null", (Node *) makeNode(A_Star), @1);
3595 : }
3596 : | ENCODING Sconst
3597 : {
3598 12 : $$ = makeDefElem("encoding", (Node *) makeString($2), @1);
3599 : }
3600 : ;
3601 :
3602 : /* The following exist for backward compatibility with very old versions */
3603 :
3604 : opt_binary:
3605 : BINARY
3606 : {
3607 12 : $$ = makeDefElem("format", (Node *) makeString("binary"), @1);
3608 : }
3609 10744 : | /*EMPTY*/ { $$ = NULL; }
3610 : ;
3611 :
3612 : copy_delimiter:
3613 : opt_using DELIMITERS Sconst
3614 : {
3615 0 : $$ = makeDefElem("delimiter", (Node *) makeString($3), @2);
3616 : }
3617 10756 : | /*EMPTY*/ { $$ = NULL; }
3618 : ;
3619 :
3620 : opt_using:
3621 : USING
3622 : | /*EMPTY*/
3623 : ;
3624 :
3625 : /* new COPY option syntax */
3626 : copy_generic_opt_list:
3627 : copy_generic_opt_elem
3628 : {
3629 722 : $$ = list_make1($1);
3630 : }
3631 : | copy_generic_opt_list ',' copy_generic_opt_elem
3632 : {
3633 468 : $$ = lappend($1, $3);
3634 : }
3635 : ;
3636 :
3637 : copy_generic_opt_elem:
3638 : ColLabel copy_generic_opt_arg
3639 : {
3640 1190 : $$ = makeDefElem($1, $2, @1);
3641 : }
3642 : ;
3643 :
3644 : copy_generic_opt_arg:
3645 836 : opt_boolean_or_string { $$ = (Node *) makeString($1); }
3646 60 : | NumericOnly { $$ = (Node *) $1; }
3647 90 : | '*' { $$ = (Node *) makeNode(A_Star); }
3648 6 : | DEFAULT { $$ = (Node *) makeString("default"); }
3649 150 : | '(' copy_generic_opt_arg_list ')' { $$ = (Node *) $2; }
3650 48 : | /* EMPTY */ { $$ = NULL; }
3651 : ;
3652 :
3653 : copy_generic_opt_arg_list:
3654 : copy_generic_opt_arg_list_item
3655 : {
3656 150 : $$ = list_make1($1);
3657 : }
3658 : | copy_generic_opt_arg_list ',' copy_generic_opt_arg_list_item
3659 : {
3660 12 : $$ = lappend($1, $3);
3661 : }
3662 : ;
3663 :
3664 : /* beware of emitting non-string list elements here; see commands/define.c */
3665 : copy_generic_opt_arg_list_item:
3666 162 : opt_boolean_or_string { $$ = (Node *) makeString($1); }
3667 : ;
3668 :
3669 :
3670 : /*****************************************************************************
3671 : *
3672 : * QUERY :
3673 : * CREATE TABLE relname
3674 : *
3675 : *****************************************************************************/
3676 :
3677 : CreateStmt: CREATE OptTemp TABLE qualified_name '(' OptTableElementList ')'
3678 : OptInherit OptPartitionSpec table_access_method_clause OptWith
3679 : OnCommitOption OptTableSpace
3680 : {
3681 30252 : CreateStmt *n = makeNode(CreateStmt);
3682 :
3683 30252 : $4->relpersistence = $2;
3684 30252 : n->relation = $4;
3685 30252 : n->tableElts = $6;
3686 30252 : n->inhRelations = $8;
3687 30252 : n->partspec = $9;
3688 30252 : n->ofTypename = NULL;
3689 30252 : n->constraints = NIL;
3690 30252 : n->accessMethod = $10;
3691 30252 : n->options = $11;
3692 30252 : n->oncommit = $12;
3693 30252 : n->tablespacename = $13;
3694 30252 : n->if_not_exists = false;
3695 30252 : $$ = (Node *) n;
3696 : }
3697 : | CREATE OptTemp TABLE IF_P NOT EXISTS qualified_name '('
3698 : OptTableElementList ')' OptInherit OptPartitionSpec table_access_method_clause
3699 : OptWith OnCommitOption OptTableSpace
3700 : {
3701 30 : CreateStmt *n = makeNode(CreateStmt);
3702 :
3703 30 : $7->relpersistence = $2;
3704 30 : n->relation = $7;
3705 30 : n->tableElts = $9;
3706 30 : n->inhRelations = $11;
3707 30 : n->partspec = $12;
3708 30 : n->ofTypename = NULL;
3709 30 : n->constraints = NIL;
3710 30 : n->accessMethod = $13;
3711 30 : n->options = $14;
3712 30 : n->oncommit = $15;
3713 30 : n->tablespacename = $16;
3714 30 : n->if_not_exists = true;
3715 30 : $$ = (Node *) n;
3716 : }
3717 : | CREATE OptTemp TABLE qualified_name OF any_name
3718 : OptTypedTableElementList OptPartitionSpec table_access_method_clause
3719 : OptWith OnCommitOption OptTableSpace
3720 : {
3721 122 : CreateStmt *n = makeNode(CreateStmt);
3722 :
3723 122 : $4->relpersistence = $2;
3724 122 : n->relation = $4;
3725 122 : n->tableElts = $7;
3726 122 : n->inhRelations = NIL;
3727 122 : n->partspec = $8;
3728 122 : n->ofTypename = makeTypeNameFromNameList($6);
3729 122 : n->ofTypename->location = @6;
3730 122 : n->constraints = NIL;
3731 122 : n->accessMethod = $9;
3732 122 : n->options = $10;
3733 122 : n->oncommit = $11;
3734 122 : n->tablespacename = $12;
3735 122 : n->if_not_exists = false;
3736 122 : $$ = (Node *) n;
3737 : }
3738 : | CREATE OptTemp TABLE IF_P NOT EXISTS qualified_name OF any_name
3739 : OptTypedTableElementList OptPartitionSpec table_access_method_clause
3740 : OptWith OnCommitOption OptTableSpace
3741 : {
3742 6 : CreateStmt *n = makeNode(CreateStmt);
3743 :
3744 6 : $7->relpersistence = $2;
3745 6 : n->relation = $7;
3746 6 : n->tableElts = $10;
3747 6 : n->inhRelations = NIL;
3748 6 : n->partspec = $11;
3749 6 : n->ofTypename = makeTypeNameFromNameList($9);
3750 6 : n->ofTypename->location = @9;
3751 6 : n->constraints = NIL;
3752 6 : n->accessMethod = $12;
3753 6 : n->options = $13;
3754 6 : n->oncommit = $14;
3755 6 : n->tablespacename = $15;
3756 6 : n->if_not_exists = true;
3757 6 : $$ = (Node *) n;
3758 : }
3759 : | CREATE OptTemp TABLE qualified_name PARTITION OF qualified_name
3760 : OptTypedTableElementList PartitionBoundSpec OptPartitionSpec
3761 : table_access_method_clause OptWith OnCommitOption OptTableSpace
3762 : {
3763 8132 : CreateStmt *n = makeNode(CreateStmt);
3764 :
3765 8132 : $4->relpersistence = $2;
3766 8132 : n->relation = $4;
3767 8132 : n->tableElts = $8;
3768 8132 : n->inhRelations = list_make1($7);
3769 8132 : n->partbound = $9;
3770 8132 : n->partspec = $10;
3771 8132 : n->ofTypename = NULL;
3772 8132 : n->constraints = NIL;
3773 8132 : n->accessMethod = $11;
3774 8132 : n->options = $12;
3775 8132 : n->oncommit = $13;
3776 8132 : n->tablespacename = $14;
3777 8132 : n->if_not_exists = false;
3778 8132 : $$ = (Node *) n;
3779 : }
3780 : | CREATE OptTemp TABLE IF_P NOT EXISTS qualified_name PARTITION OF
3781 : qualified_name OptTypedTableElementList PartitionBoundSpec OptPartitionSpec
3782 : table_access_method_clause OptWith OnCommitOption OptTableSpace
3783 : {
3784 0 : CreateStmt *n = makeNode(CreateStmt);
3785 :
3786 0 : $7->relpersistence = $2;
3787 0 : n->relation = $7;
3788 0 : n->tableElts = $11;
3789 0 : n->inhRelations = list_make1($10);
3790 0 : n->partbound = $12;
3791 0 : n->partspec = $13;
3792 0 : n->ofTypename = NULL;
3793 0 : n->constraints = NIL;
3794 0 : n->accessMethod = $14;
3795 0 : n->options = $15;
3796 0 : n->oncommit = $16;
3797 0 : n->tablespacename = $17;
3798 0 : n->if_not_exists = true;
3799 0 : $$ = (Node *) n;
3800 : }
3801 : ;
3802 :
3803 : /*
3804 : * Redundancy here is needed to avoid shift/reduce conflicts,
3805 : * since TEMP is not a reserved word. See also OptTempTableName.
3806 : *
3807 : * NOTE: we accept both GLOBAL and LOCAL options. They currently do nothing,
3808 : * but future versions might consider GLOBAL to request SQL-spec-compliant
3809 : * temp table behavior, so warn about that. Since we have no modules the
3810 : * LOCAL keyword is really meaningless; furthermore, some other products
3811 : * implement LOCAL as meaning the same as our default temp table behavior,
3812 : * so we'll probably continue to treat LOCAL as a noise word.
3813 : */
3814 352 : OptTemp: TEMPORARY { $$ = RELPERSISTENCE_TEMP; }
3815 2840 : | TEMP { $$ = RELPERSISTENCE_TEMP; }
3816 0 : | LOCAL TEMPORARY { $$ = RELPERSISTENCE_TEMP; }
3817 0 : | LOCAL TEMP { $$ = RELPERSISTENCE_TEMP; }
3818 : | GLOBAL TEMPORARY
3819 : {
3820 0 : ereport(WARNING,
3821 : (errmsg("GLOBAL is deprecated in temporary table creation"),
3822 : parser_errposition(@1)));
3823 0 : $$ = RELPERSISTENCE_TEMP;
3824 : }
3825 : | GLOBAL TEMP
3826 : {
3827 0 : ereport(WARNING,
3828 : (errmsg("GLOBAL is deprecated in temporary table creation"),
3829 : parser_errposition(@1)));
3830 0 : $$ = RELPERSISTENCE_TEMP;
3831 : }
3832 180 : | UNLOGGED { $$ = RELPERSISTENCE_UNLOGGED; }
3833 54478 : | /*EMPTY*/ { $$ = RELPERSISTENCE_PERMANENT; }
3834 : ;
3835 :
3836 : OptTableElementList:
3837 29076 : TableElementList { $$ = $1; }
3838 1668 : | /*EMPTY*/ { $$ = NIL; }
3839 : ;
3840 :
3841 : OptTypedTableElementList:
3842 354 : '(' TypedTableElementList ')' { $$ = $2; }
3843 8002 : | /*EMPTY*/ { $$ = NIL; }
3844 : ;
3845 :
3846 : TableElementList:
3847 : TableElement
3848 : {
3849 29130 : $$ = list_make1($1);
3850 : }
3851 : | TableElementList ',' TableElement
3852 : {
3853 41080 : $$ = lappend($1, $3);
3854 : }
3855 : ;
3856 :
3857 : TypedTableElementList:
3858 : TypedTableElement
3859 : {
3860 354 : $$ = list_make1($1);
3861 : }
3862 : | TypedTableElementList ',' TypedTableElement
3863 : {
3864 68 : $$ = lappend($1, $3);
3865 : }
3866 : ;
3867 :
3868 : TableElement:
3869 66666 : columnDef { $$ = $1; }
3870 774 : | TableLikeClause { $$ = $1; }
3871 2770 : | TableConstraint { $$ = $1; }
3872 : ;
3873 :
3874 : TypedTableElement:
3875 358 : columnOptions { $$ = $1; }
3876 64 : | TableConstraint { $$ = $1; }
3877 : ;
3878 :
3879 : columnDef: ColId Typename opt_column_storage opt_column_compression create_generic_options ColQualList
3880 : {
3881 68840 : ColumnDef *n = makeNode(ColumnDef);
3882 :
3883 68840 : n->colname = $1;
3884 68840 : n->typeName = $2;
3885 68840 : n->storage_name = $3;
3886 68840 : n->compression = $4;
3887 68840 : n->inhcount = 0;
3888 68840 : n->is_local = true;
3889 68840 : n->is_not_null = false;
3890 68840 : n->is_from_type = false;
3891 68840 : n->storage = 0;
3892 68840 : n->raw_default = NULL;
3893 68840 : n->cooked_default = NULL;
3894 68840 : n->collOid = InvalidOid;
3895 68840 : n->fdwoptions = $5;
3896 68840 : SplitColQualList($6, &n->constraints, &n->collClause,
3897 : yyscanner);
3898 68840 : n->location = @1;
3899 68840 : $$ = (Node *) n;
3900 : }
3901 : ;
3902 :
3903 : columnOptions: ColId ColQualList
3904 : {
3905 138 : ColumnDef *n = makeNode(ColumnDef);
3906 :
3907 138 : n->colname = $1;
3908 138 : n->typeName = NULL;
3909 138 : n->inhcount = 0;
3910 138 : n->is_local = true;
3911 138 : n->is_not_null = false;
3912 138 : n->is_from_type = false;
3913 138 : n->storage = 0;
3914 138 : n->raw_default = NULL;
3915 138 : n->cooked_default = NULL;
3916 138 : n->collOid = InvalidOid;
3917 138 : SplitColQualList($2, &n->constraints, &n->collClause,
3918 : yyscanner);
3919 138 : n->location = @1;
3920 138 : $$ = (Node *) n;
3921 : }
3922 : | ColId WITH OPTIONS ColQualList
3923 : {
3924 220 : ColumnDef *n = makeNode(ColumnDef);
3925 :
3926 220 : n->colname = $1;
3927 220 : n->typeName = NULL;
3928 220 : n->inhcount = 0;
3929 220 : n->is_local = true;
3930 220 : n->is_not_null = false;
3931 220 : n->is_from_type = false;
3932 220 : n->storage = 0;
3933 220 : n->raw_default = NULL;
3934 220 : n->cooked_default = NULL;
3935 220 : n->collOid = InvalidOid;
3936 220 : SplitColQualList($4, &n->constraints, &n->collClause,
3937 : yyscanner);
3938 220 : n->location = @1;
3939 220 : $$ = (Node *) n;
3940 : }
3941 : ;
3942 :
3943 : column_compression:
3944 166 : COMPRESSION ColId { $$ = $2; }
3945 6 : | COMPRESSION DEFAULT { $$ = pstrdup("default"); }
3946 : ;
3947 :
3948 : opt_column_compression:
3949 94 : column_compression { $$ = $1; }
3950 68812 : | /*EMPTY*/ { $$ = NULL; }
3951 : ;
3952 :
3953 : column_storage:
3954 258 : STORAGE ColId { $$ = $2; }
3955 6 : | STORAGE DEFAULT { $$ = pstrdup("default"); }
3956 : ;
3957 :
3958 : opt_column_storage:
3959 26 : column_storage { $$ = $1; }
3960 68880 : | /*EMPTY*/ { $$ = NULL; }
3961 : ;
3962 :
3963 : ColQualList:
3964 20350 : ColQualList ColConstraint { $$ = lappend($1, $2); }
3965 70728 : | /*EMPTY*/ { $$ = NIL; }
3966 : ;
3967 :
3968 : ColConstraint:
3969 : CONSTRAINT name ColConstraintElem
3970 : {
3971 802 : Constraint *n = castNode(Constraint, $3);
3972 :
3973 802 : n->conname = $2;
3974 802 : n->location = @1;
3975 802 : $$ = (Node *) n;
3976 : }
3977 18480 : | ColConstraintElem { $$ = $1; }
3978 294 : | ConstraintAttr { $$ = $1; }
3979 : | COLLATE any_name
3980 : {
3981 : /*
3982 : * Note: the CollateClause is momentarily included in
3983 : * the list built by ColQualList, but we split it out
3984 : * again in SplitColQualList.
3985 : */
3986 774 : CollateClause *n = makeNode(CollateClause);
3987 :
3988 774 : n->arg = NULL;
3989 774 : n->collname = $2;
3990 774 : n->location = @1;
3991 774 : $$ = (Node *) n;
3992 : }
3993 : ;
3994 :
3995 : /* DEFAULT NULL is already the default for Postgres.
3996 : * But define it here and carry it forward into the system
3997 : * to make it explicit.
3998 : * - thomas 1998-09-13
3999 : *
4000 : * WITH NULL and NULL are not SQL-standard syntax elements,
4001 : * so leave them out. Use DEFAULT NULL to explicitly indicate
4002 : * that a column may have that value. WITH NULL leads to
4003 : * shift/reduce conflicts with WITH TIME ZONE anyway.
4004 : * - thomas 1999-01-08
4005 : *
4006 : * DEFAULT expression must be b_expr not a_expr to prevent shift/reduce
4007 : * conflict on NOT (since NOT might start a subsequent NOT NULL constraint,
4008 : * or be part of a_expr NOT LIKE or similar constructs).
4009 : */
4010 : ColConstraintElem:
4011 : NOT NULL_P opt_no_inherit
4012 : {
4013 6956 : Constraint *n = makeNode(Constraint);
4014 :
4015 6956 : n->contype = CONSTR_NOTNULL;
4016 6956 : n->location = @1;
4017 6956 : n->is_no_inherit = $3;
4018 6956 : n->is_enforced = true;
4019 6956 : n->skip_validation = false;
4020 6956 : n->initially_valid = true;
4021 6956 : $$ = (Node *) n;
4022 : }
4023 : | NULL_P
4024 : {
4025 30 : Constraint *n = makeNode(Constraint);
4026 :
4027 30 : n->contype = CONSTR_NULL;
4028 30 : n->location = @1;
4029 30 : $$ = (Node *) n;
4030 : }
4031 : | UNIQUE opt_unique_null_treatment opt_definition OptConsTableSpace
4032 : {
4033 464 : Constraint *n = makeNode(Constraint);
4034 :
4035 464 : n->contype = CONSTR_UNIQUE;
4036 464 : n->location = @1;
4037 464 : n->nulls_not_distinct = !$2;
4038 464 : n->keys = NULL;
4039 464 : n->options = $3;
4040 464 : n->indexname = NULL;
4041 464 : n->indexspace = $4;
4042 464 : $$ = (Node *) n;
4043 : }
4044 : | PRIMARY KEY opt_definition OptConsTableSpace
4045 : {
4046 5918 : Constraint *n = makeNode(Constraint);
4047 :
4048 5918 : n->contype = CONSTR_PRIMARY;
4049 5918 : n->location = @1;
4050 5918 : n->keys = NULL;
4051 5918 : n->options = $3;
4052 5918 : n->indexname = NULL;
4053 5918 : n->indexspace = $4;
4054 5918 : $$ = (Node *) n;
4055 : }
4056 : | CHECK '(' a_expr ')' opt_no_inherit
4057 : {
4058 1086 : Constraint *n = makeNode(Constraint);
4059 :
4060 1086 : n->contype = CONSTR_CHECK;
4061 1086 : n->location = @1;
4062 1086 : n->is_no_inherit = $5;
4063 1086 : n->raw_expr = $3;
4064 1086 : n->cooked_expr = NULL;
4065 1086 : n->is_enforced = true;
4066 1086 : n->skip_validation = false;
4067 1086 : n->initially_valid = true;
4068 1086 : $$ = (Node *) n;
4069 : }
4070 : | DEFAULT b_expr
4071 : {
4072 1850 : Constraint *n = makeNode(Constraint);
4073 :
4074 1850 : n->contype = CONSTR_DEFAULT;
4075 1850 : n->location = @1;
4076 1850 : n->raw_expr = $2;
4077 1850 : n->cooked_expr = NULL;
4078 1850 : $$ = (Node *) n;
4079 : }
4080 : | GENERATED generated_when AS IDENTITY_P OptParenthesizedSeqOptList
4081 : {
4082 356 : Constraint *n = makeNode(Constraint);
4083 :
4084 356 : n->contype = CONSTR_IDENTITY;
4085 356 : n->generated_when = $2;
4086 356 : n->options = $5;
4087 356 : n->location = @1;
4088 356 : $$ = (Node *) n;
4089 : }
4090 : | GENERATED generated_when AS '(' a_expr ')' opt_virtual_or_stored
4091 : {
4092 1794 : Constraint *n = makeNode(Constraint);
4093 :
4094 1794 : n->contype = CONSTR_GENERATED;
4095 1794 : n->generated_when = $2;
4096 1794 : n->raw_expr = $5;
4097 1794 : n->cooked_expr = NULL;
4098 1794 : n->generated_kind = $7;
4099 1794 : n->location = @1;
4100 :
4101 : /*
4102 : * Can't do this in the grammar because of shift/reduce
4103 : * conflicts. (IDENTITY allows both ALWAYS and BY
4104 : * DEFAULT, but generated columns only allow ALWAYS.) We
4105 : * can also give a more useful error message and location.
4106 : */
4107 1794 : if ($2 != ATTRIBUTE_IDENTITY_ALWAYS)
4108 12 : ereport(ERROR,
4109 : (errcode(ERRCODE_SYNTAX_ERROR),
4110 : errmsg("for a generated column, GENERATED ALWAYS must be specified"),
4111 : parser_errposition(@2)));
4112 :
4113 1782 : $$ = (Node *) n;
4114 : }
4115 : | REFERENCES qualified_name opt_column_list key_match key_actions
4116 : {
4117 840 : Constraint *n = makeNode(Constraint);
4118 :
4119 840 : n->contype = CONSTR_FOREIGN;
4120 840 : n->location = @1;
4121 840 : n->pktable = $2;
4122 840 : n->fk_attrs = NIL;
4123 840 : n->pk_attrs = $3;
4124 840 : n->fk_matchtype = $4;
4125 840 : n->fk_upd_action = ($5)->updateAction->action;
4126 840 : n->fk_del_action = ($5)->deleteAction->action;
4127 840 : n->fk_del_set_cols = ($5)->deleteAction->cols;
4128 840 : n->is_enforced = true;
4129 840 : n->skip_validation = false;
4130 840 : n->initially_valid = true;
4131 840 : $$ = (Node *) n;
4132 : }
4133 : ;
4134 :
4135 : opt_unique_null_treatment:
4136 12 : NULLS_P DISTINCT { $$ = true; }
4137 36 : | NULLS_P NOT DISTINCT { $$ = false; }
4138 7714 : | /*EMPTY*/ { $$ = true; }
4139 : ;
4140 :
4141 : generated_when:
4142 2184 : ALWAYS { $$ = ATTRIBUTE_IDENTITY_ALWAYS; }
4143 182 : | BY DEFAULT { $$ = ATTRIBUTE_IDENTITY_BY_DEFAULT; }
4144 : ;
4145 :
4146 : opt_virtual_or_stored:
4147 1028 : STORED { $$ = ATTRIBUTE_GENERATED_STORED; }
4148 658 : | VIRTUAL { $$ = ATTRIBUTE_GENERATED_VIRTUAL; }
4149 108 : | /*EMPTY*/ { $$ = ATTRIBUTE_GENERATED_VIRTUAL; }
4150 : ;
4151 :
4152 : /*
4153 : * ConstraintAttr represents constraint attributes, which we parse as if
4154 : * they were independent constraint clauses, in order to avoid shift/reduce
4155 : * conflicts (since NOT might start either an independent NOT NULL clause
4156 : * or an attribute). parse_utilcmd.c is responsible for attaching the
4157 : * attribute information to the preceding "real" constraint node, and for
4158 : * complaining if attribute clauses appear in the wrong place or wrong
4159 : * combinations.
4160 : *
4161 : * See also ConstraintAttributeSpec, which can be used in places where
4162 : * there is no parsing conflict. (Note: currently, NOT VALID and NO INHERIT
4163 : * are allowed clauses in ConstraintAttributeSpec, but not here. Someday we
4164 : * might need to allow them here too, but for the moment it doesn't seem
4165 : * useful in the statements that use ConstraintAttr.)
4166 : */
4167 : ConstraintAttr:
4168 : DEFERRABLE
4169 : {
4170 102 : Constraint *n = makeNode(Constraint);
4171 :
4172 102 : n->contype = CONSTR_ATTR_DEFERRABLE;
4173 102 : n->location = @1;
4174 102 : $$ = (Node *) n;
4175 : }
4176 : | NOT DEFERRABLE
4177 : {
4178 0 : Constraint *n = makeNode(Constraint);
4179 :
4180 0 : n->contype = CONSTR_ATTR_NOT_DEFERRABLE;
4181 0 : n->location = @1;
4182 0 : $$ = (Node *) n;
4183 : }
4184 : | INITIALLY DEFERRED
4185 : {
4186 78 : Constraint *n = makeNode(Constraint);
4187 :
4188 78 : n->contype = CONSTR_ATTR_DEFERRED;
4189 78 : n->location = @1;
4190 78 : $$ = (Node *) n;
4191 : }
4192 : | INITIALLY IMMEDIATE
4193 : {
4194 6 : Constraint *n = makeNode(Constraint);
4195 :
4196 6 : n->contype = CONSTR_ATTR_IMMEDIATE;
4197 6 : n->location = @1;
4198 6 : $$ = (Node *) n;
4199 : }
4200 : | ENFORCED
4201 : {
4202 42 : Constraint *n = makeNode(Constraint);
4203 :
4204 42 : n->contype = CONSTR_ATTR_ENFORCED;
4205 42 : n->location = @1;
4206 42 : $$ = (Node *) n;
4207 : }
4208 : | NOT ENFORCED
4209 : {
4210 66 : Constraint *n = makeNode(Constraint);
4211 :
4212 66 : n->contype = CONSTR_ATTR_NOT_ENFORCED;
4213 66 : n->location = @1;
4214 66 : $$ = (Node *) n;
4215 : }
4216 : ;
4217 :
4218 :
4219 : TableLikeClause:
4220 : LIKE qualified_name TableLikeOptionList
4221 : {
4222 774 : TableLikeClause *n = makeNode(TableLikeClause);
4223 :
4224 774 : n->relation = $2;
4225 774 : n->options = $3;
4226 774 : n->relationOid = InvalidOid;
4227 774 : $$ = (Node *) n;
4228 : }
4229 : ;
4230 :
4231 : TableLikeOptionList:
4232 288 : TableLikeOptionList INCLUDING TableLikeOption { $$ = $1 | $3; }
4233 8 : | TableLikeOptionList EXCLUDING TableLikeOption { $$ = $1 & ~$3; }
4234 774 : | /* EMPTY */ { $$ = 0; }
4235 : ;
4236 :
4237 : TableLikeOption:
4238 30 : COMMENTS { $$ = CREATE_TABLE_LIKE_COMMENTS; }
4239 6 : | COMPRESSION { $$ = CREATE_TABLE_LIKE_COMPRESSION; }
4240 54 : | CONSTRAINTS { $$ = CREATE_TABLE_LIKE_CONSTRAINTS; }
4241 20 : | DEFAULTS { $$ = CREATE_TABLE_LIKE_DEFAULTS; }
4242 12 : | IDENTITY_P { $$ = CREATE_TABLE_LIKE_IDENTITY; }
4243 30 : | GENERATED { $$ = CREATE_TABLE_LIKE_GENERATED; }
4244 50 : | INDEXES { $$ = CREATE_TABLE_LIKE_INDEXES; }
4245 0 : | STATISTICS { $$ = CREATE_TABLE_LIKE_STATISTICS; }
4246 26 : | STORAGE { $$ = CREATE_TABLE_LIKE_STORAGE; }
4247 68 : | ALL { $$ = CREATE_TABLE_LIKE_ALL; }
4248 : ;
4249 :
4250 :
4251 : /* ConstraintElem specifies constraint syntax which is not embedded into
4252 : * a column definition. ColConstraintElem specifies the embedded form.
4253 : * - thomas 1997-12-03
4254 : */
4255 : TableConstraint:
4256 : CONSTRAINT name ConstraintElem
4257 : {
4258 4104 : Constraint *n = castNode(Constraint, $3);
4259 :
4260 4104 : n->conname = $2;
4261 4104 : n->location = @1;
4262 4104 : $$ = (Node *) n;
4263 : }
4264 13290 : | ConstraintElem { $$ = $1; }
4265 : ;
4266 :
4267 : ConstraintElem:
4268 : CHECK '(' a_expr ')' ConstraintAttributeSpec
4269 : {
4270 1268 : Constraint *n = makeNode(Constraint);
4271 :
4272 1268 : n->contype = CONSTR_CHECK;
4273 1268 : n->location = @1;
4274 1268 : n->raw_expr = $3;
4275 1268 : n->cooked_expr = NULL;
4276 1268 : processCASbits($5, @5, "CHECK",
4277 : NULL, NULL, &n->is_enforced, &n->skip_validation,
4278 : &n->is_no_inherit, yyscanner);
4279 1268 : n->initially_valid = !n->skip_validation;
4280 1268 : $$ = (Node *) n;
4281 : }
4282 : | NOT NULL_P ColId ConstraintAttributeSpec
4283 : {
4284 598 : Constraint *n = makeNode(Constraint);
4285 :
4286 598 : n->contype = CONSTR_NOTNULL;
4287 598 : n->location = @1;
4288 598 : n->keys = list_make1(makeString($3));
4289 598 : processCASbits($4, @4, "NOT NULL",
4290 : NULL, NULL, NULL, &n->skip_validation,
4291 : &n->is_no_inherit, yyscanner);
4292 598 : n->initially_valid = !n->skip_validation;
4293 598 : $$ = (Node *) n;
4294 : }
4295 : | UNIQUE opt_unique_null_treatment '(' columnList opt_without_overlaps ')' opt_c_include opt_definition OptConsTableSpace
4296 : ConstraintAttributeSpec
4297 : {
4298 598 : Constraint *n = makeNode(Constraint);
4299 :
4300 598 : n->contype = CONSTR_UNIQUE;
4301 598 : n->location = @1;
4302 598 : n->nulls_not_distinct = !$2;
4303 598 : n->keys = $4;
4304 598 : n->without_overlaps = $5;
4305 598 : n->including = $7;
4306 598 : n->options = $8;
4307 598 : n->indexname = NULL;
4308 598 : n->indexspace = $9;
4309 598 : processCASbits($10, @10, "UNIQUE",
4310 : &n->deferrable, &n->initdeferred, NULL,
4311 : NULL, NULL, yyscanner);
4312 598 : $$ = (Node *) n;
4313 : }
4314 : | UNIQUE ExistingIndex ConstraintAttributeSpec
4315 : {
4316 4648 : Constraint *n = makeNode(Constraint);
4317 :
4318 4648 : n->contype = CONSTR_UNIQUE;
4319 4648 : n->location = @1;
4320 4648 : n->keys = NIL;
4321 4648 : n->including = NIL;
4322 4648 : n->options = NIL;
4323 4648 : n->indexname = $2;
4324 4648 : n->indexspace = NULL;
4325 4648 : processCASbits($3, @3, "UNIQUE",
4326 : &n->deferrable, &n->initdeferred, NULL,
4327 : NULL, NULL, yyscanner);
4328 4648 : $$ = (Node *) n;
4329 : }
4330 : | PRIMARY KEY '(' columnList opt_without_overlaps ')' opt_c_include opt_definition OptConsTableSpace
4331 : ConstraintAttributeSpec
4332 : {
4333 2174 : Constraint *n = makeNode(Constraint);
4334 :
4335 2174 : n->contype = CONSTR_PRIMARY;
4336 2174 : n->location = @1;
4337 2174 : n->keys = $4;
4338 2174 : n->without_overlaps = $5;
4339 2174 : n->including = $7;
4340 2174 : n->options = $8;
4341 2174 : n->indexname = NULL;
4342 2174 : n->indexspace = $9;
4343 2174 : processCASbits($10, @10, "PRIMARY KEY",
4344 : &n->deferrable, &n->initdeferred, NULL,
4345 : NULL, NULL, yyscanner);
4346 2174 : $$ = (Node *) n;
4347 : }
4348 : | PRIMARY KEY ExistingIndex ConstraintAttributeSpec
4349 : {
4350 6018 : Constraint *n = makeNode(Constraint);
4351 :
4352 6018 : n->contype = CONSTR_PRIMARY;
4353 6018 : n->location = @1;
4354 6018 : n->keys = NIL;
4355 6018 : n->including = NIL;
4356 6018 : n->options = NIL;
4357 6018 : n->indexname = $3;
4358 6018 : n->indexspace = NULL;
4359 6018 : processCASbits($4, @4, "PRIMARY KEY",
4360 : &n->deferrable, &n->initdeferred, NULL,
4361 : NULL, NULL, yyscanner);
4362 6018 : $$ = (Node *) n;
4363 : }
4364 : | EXCLUDE access_method_clause '(' ExclusionConstraintList ')'
4365 : opt_c_include opt_definition OptConsTableSpace OptWhereClause
4366 : ConstraintAttributeSpec
4367 : {
4368 234 : Constraint *n = makeNode(Constraint);
4369 :
4370 234 : n->contype = CONSTR_EXCLUSION;
4371 234 : n->location = @1;
4372 234 : n->access_method = $2;
4373 234 : n->exclusions = $4;
4374 234 : n->including = $6;
4375 234 : n->options = $7;
4376 234 : n->indexname = NULL;
4377 234 : n->indexspace = $8;
4378 234 : n->where_clause = $9;
4379 234 : processCASbits($10, @10, "EXCLUDE",
4380 : &n->deferrable, &n->initdeferred, NULL,
4381 : NULL, NULL, yyscanner);
4382 234 : $$ = (Node *) n;
4383 : }
4384 : | FOREIGN KEY '(' columnList optionalPeriodName ')' REFERENCES qualified_name
4385 : opt_column_and_period_list key_match key_actions ConstraintAttributeSpec
4386 : {
4387 1856 : Constraint *n = makeNode(Constraint);
4388 :
4389 1856 : n->contype = CONSTR_FOREIGN;
4390 1856 : n->location = @1;
4391 1856 : n->pktable = $8;
4392 1856 : n->fk_attrs = $4;
4393 1856 : if ($5)
4394 : {
4395 326 : n->fk_attrs = lappend(n->fk_attrs, $5);
4396 326 : n->fk_with_period = true;
4397 : }
4398 1856 : n->pk_attrs = linitial($9);
4399 1856 : if (lsecond($9))
4400 : {
4401 170 : n->pk_attrs = lappend(n->pk_attrs, lsecond($9));
4402 170 : n->pk_with_period = true;
4403 : }
4404 1856 : n->fk_matchtype = $10;
4405 1856 : n->fk_upd_action = ($11)->updateAction->action;
4406 1856 : n->fk_del_action = ($11)->deleteAction->action;
4407 1856 : n->fk_del_set_cols = ($11)->deleteAction->cols;
4408 1856 : processCASbits($12, @12, "FOREIGN KEY",
4409 : &n->deferrable, &n->initdeferred,
4410 : &n->is_enforced, &n->skip_validation, NULL,
4411 : yyscanner);
4412 1856 : n->initially_valid = !n->skip_validation;
4413 1856 : $$ = (Node *) n;
4414 : }
4415 : ;
4416 :
4417 : /*
4418 : * DomainConstraint is separate from TableConstraint because the syntax for
4419 : * NOT NULL constraints is different. For table constraints, we need to
4420 : * accept a column name, but for domain constraints, we don't. (We could
4421 : * accept something like NOT NULL VALUE, but that seems weird.) CREATE DOMAIN
4422 : * (which uses ColQualList) has for a long time accepted NOT NULL without a
4423 : * column name, so it makes sense that ALTER DOMAIN (which uses
4424 : * DomainConstraint) does as well. None of these syntaxes are per SQL
4425 : * standard; we are just living with the bits of inconsistency that have built
4426 : * up over time.
4427 : */
4428 : DomainConstraint:
4429 : CONSTRAINT name DomainConstraintElem
4430 : {
4431 164 : Constraint *n = castNode(Constraint, $3);
4432 :
4433 164 : n->conname = $2;
4434 164 : n->location = @1;
4435 164 : $$ = (Node *) n;
4436 : }
4437 18 : | DomainConstraintElem { $$ = $1; }
4438 : ;
4439 :
4440 : DomainConstraintElem:
4441 : CHECK '(' a_expr ')' ConstraintAttributeSpec
4442 : {
4443 164 : Constraint *n = makeNode(Constraint);
4444 :
4445 164 : n->contype = CONSTR_CHECK;
4446 164 : n->location = @1;
4447 164 : n->raw_expr = $3;
4448 164 : n->cooked_expr = NULL;
4449 164 : processCASbits($5, @5, "CHECK",
4450 : NULL, NULL, NULL, &n->skip_validation,
4451 : &n->is_no_inherit, yyscanner);
4452 152 : n->is_enforced = true;
4453 152 : n->initially_valid = !n->skip_validation;
4454 152 : $$ = (Node *) n;
4455 : }
4456 : | NOT NULL_P ConstraintAttributeSpec
4457 : {
4458 30 : Constraint *n = makeNode(Constraint);
4459 :
4460 30 : n->contype = CONSTR_NOTNULL;
4461 30 : n->location = @1;
4462 30 : n->keys = list_make1(makeString("value"));
4463 : /* no NOT VALID, NO INHERIT support */
4464 30 : processCASbits($3, @3, "NOT NULL",
4465 : NULL, NULL, NULL,
4466 : NULL, NULL, yyscanner);
4467 30 : n->initially_valid = true;
4468 30 : $$ = (Node *) n;
4469 : }
4470 : ;
4471 :
4472 138 : opt_no_inherit: NO INHERIT { $$ = true; }
4473 7904 : | /* EMPTY */ { $$ = false; }
4474 : ;
4475 :
4476 : opt_without_overlaps:
4477 590 : WITHOUT OVERLAPS { $$ = true; }
4478 2182 : | /*EMPTY*/ { $$ = false; }
4479 : ;
4480 :
4481 : opt_column_list:
4482 10268 : '(' columnList ')' { $$ = $2; }
4483 43262 : | /*EMPTY*/ { $$ = NIL; }
4484 : ;
4485 :
4486 : columnList:
4487 16590 : columnElem { $$ = list_make1($1); }
4488 28566 : | columnList ',' columnElem { $$ = lappend($1, $3); }
4489 : ;
4490 :
4491 : optionalPeriodName:
4492 496 : ',' PERIOD columnElem { $$ = $3; }
4493 2490 : | /*EMPTY*/ { $$ = NULL; }
4494 : ;
4495 :
4496 : opt_column_and_period_list:
4497 1124 : '(' columnList optionalPeriodName ')' { $$ = list_make2($2, $3); }
4498 738 : | /*EMPTY*/ { $$ = list_make2(NIL, NULL); }
4499 : ;
4500 :
4501 : columnElem: ColId
4502 : {
4503 45652 : $$ = (Node *) makeString($1);
4504 : }
4505 : ;
4506 :
4507 168 : opt_c_include: INCLUDE '(' columnList ')' { $$ = $3; }
4508 2838 : | /* EMPTY */ { $$ = NIL; }
4509 : ;
4510 :
4511 : key_match: MATCH FULL
4512 : {
4513 98 : $$ = FKCONSTR_MATCH_FULL;
4514 : }
4515 : | MATCH PARTIAL
4516 : {
4517 0 : ereport(ERROR,
4518 : (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
4519 : errmsg("MATCH PARTIAL not yet implemented"),
4520 : parser_errposition(@1)));
4521 : $$ = FKCONSTR_MATCH_PARTIAL;
4522 : }
4523 : | MATCH SIMPLE
4524 : {
4525 6 : $$ = FKCONSTR_MATCH_SIMPLE;
4526 : }
4527 : | /*EMPTY*/
4528 : {
4529 2598 : $$ = FKCONSTR_MATCH_SIMPLE;
4530 : }
4531 : ;
4532 :
4533 : ExclusionConstraintList:
4534 234 : ExclusionConstraintElem { $$ = list_make1($1); }
4535 : | ExclusionConstraintList ',' ExclusionConstraintElem
4536 106 : { $$ = lappend($1, $3); }
4537 : ;
4538 :
4539 : ExclusionConstraintElem: index_elem WITH any_operator
4540 : {
4541 340 : $$ = list_make2($1, $3);
4542 : }
4543 : /* allow OPERATOR() decoration for the benefit of ruleutils.c */
4544 : | index_elem WITH OPERATOR '(' any_operator ')'
4545 : {
4546 0 : $$ = list_make2($1, $5);
4547 : }
4548 : ;
4549 :
4550 : OptWhereClause:
4551 464 : WHERE '(' a_expr ')' { $$ = $3; }
4552 1264 : | /*EMPTY*/ { $$ = NULL; }
4553 : ;
4554 :
4555 : key_actions:
4556 : key_update
4557 : {
4558 74 : KeyActions *n = palloc(sizeof(KeyActions));
4559 :
4560 74 : n->updateAction = $1;
4561 74 : n->deleteAction = palloc(sizeof(KeyAction));
4562 74 : n->deleteAction->action = FKCONSTR_ACTION_NOACTION;
4563 74 : n->deleteAction->cols = NIL;
4564 74 : $$ = n;
4565 : }
4566 : | key_delete
4567 : {
4568 150 : KeyActions *n = palloc(sizeof(KeyActions));
4569 :
4570 150 : n->updateAction = palloc(sizeof(KeyAction));
4571 150 : n->updateAction->action = FKCONSTR_ACTION_NOACTION;
4572 150 : n->updateAction->cols = NIL;
4573 150 : n->deleteAction = $1;
4574 150 : $$ = n;
4575 : }
4576 : | key_update key_delete
4577 : {
4578 168 : KeyActions *n = palloc(sizeof(KeyActions));
4579 :
4580 168 : n->updateAction = $1;
4581 168 : n->deleteAction = $2;
4582 168 : $$ = n;
4583 : }
4584 : | key_delete key_update
4585 : {
4586 150 : KeyActions *n = palloc(sizeof(KeyActions));
4587 :
4588 150 : n->updateAction = $2;
4589 150 : n->deleteAction = $1;
4590 150 : $$ = n;
4591 : }
4592 : | /*EMPTY*/
4593 : {
4594 2154 : KeyActions *n = palloc(sizeof(KeyActions));
4595 :
4596 2154 : n->updateAction = palloc(sizeof(KeyAction));
4597 2154 : n->updateAction->action = FKCONSTR_ACTION_NOACTION;
4598 2154 : n->updateAction->cols = NIL;
4599 2154 : n->deleteAction = palloc(sizeof(KeyAction));
4600 2154 : n->deleteAction->action = FKCONSTR_ACTION_NOACTION;
4601 2154 : n->deleteAction->cols = NIL;
4602 2154 : $$ = n;
4603 : }
4604 : ;
4605 :
4606 : key_update: ON UPDATE key_action
4607 : {
4608 398 : if (($3)->cols)
4609 6 : ereport(ERROR,
4610 : (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
4611 : errmsg("a column list with %s is only supported for ON DELETE actions",
4612 : ($3)->action == FKCONSTR_ACTION_SETNULL ? "SET NULL" : "SET DEFAULT"),
4613 : parser_errposition(@1)));
4614 392 : $$ = $3;
4615 : }
4616 : ;
4617 :
4618 : key_delete: ON DELETE_P key_action
4619 : {
4620 468 : $$ = $3;
4621 : }
4622 : ;
4623 :
4624 : key_action:
4625 : NO ACTION
4626 : {
4627 80 : KeyAction *n = palloc(sizeof(KeyAction));
4628 :
4629 80 : n->action = FKCONSTR_ACTION_NOACTION;
4630 80 : n->cols = NIL;
4631 80 : $$ = n;
4632 : }
4633 : | RESTRICT
4634 : {
4635 48 : KeyAction *n = palloc(sizeof(KeyAction));
4636 :
4637 48 : n->action = FKCONSTR_ACTION_RESTRICT;
4638 48 : n->cols = NIL;
4639 48 : $$ = n;
4640 : }
4641 : | CASCADE
4642 : {
4643 446 : KeyAction *n = palloc(sizeof(KeyAction));
4644 :
4645 446 : n->action = FKCONSTR_ACTION_CASCADE;
4646 446 : n->cols = NIL;
4647 446 : $$ = n;
4648 : }
4649 : | SET NULL_P opt_column_list
4650 : {
4651 190 : KeyAction *n = palloc(sizeof(KeyAction));
4652 :
4653 190 : n->action = FKCONSTR_ACTION_SETNULL;
4654 190 : n->cols = $3;
4655 190 : $$ = n;
4656 : }
4657 : | SET DEFAULT opt_column_list
4658 : {
4659 102 : KeyAction *n = palloc(sizeof(KeyAction));
4660 :
4661 102 : n->action = FKCONSTR_ACTION_SETDEFAULT;
4662 102 : n->cols = $3;
4663 102 : $$ = n;
4664 : }
4665 : ;
4666 :
4667 2132 : OptInherit: INHERITS '(' qualified_name_list ')' { $$ = $3; }
4668 28594 : | /*EMPTY*/ { $$ = NIL; }
4669 : ;
4670 :
4671 : /* Optional partition key specification */
4672 5160 : OptPartitionSpec: PartitionSpec { $$ = $1; }
4673 33394 : | /*EMPTY*/ { $$ = NULL; }
4674 : ;
4675 :
4676 : PartitionSpec: PARTITION BY ColId '(' part_params ')'
4677 : {
4678 5166 : PartitionSpec *n = makeNode(PartitionSpec);
4679 :
4680 5166 : n->strategy = parsePartitionStrategy($3, @3, yyscanner);
4681 5160 : n->partParams = $5;
4682 5160 : n->location = @1;
4683 :
4684 5160 : $$ = n;
4685 : }
4686 : ;
4687 :
4688 5166 : part_params: part_elem { $$ = list_make1($1); }
4689 456 : | part_params ',' part_elem { $$ = lappend($1, $3); }
4690 : ;
4691 :
4692 : part_elem: ColId opt_collate opt_qualified_name
4693 : {
4694 5282 : PartitionElem *n = makeNode(PartitionElem);
4695 :
4696 5282 : n->name = $1;
4697 5282 : n->expr = NULL;
4698 5282 : n->collation = $2;
4699 5282 : n->opclass = $3;
4700 5282 : n->location = @1;
4701 5282 : $$ = n;
4702 : }
4703 : | func_expr_windowless opt_collate opt_qualified_name
4704 : {
4705 130 : PartitionElem *n = makeNode(PartitionElem);
4706 :
4707 130 : n->name = NULL;
4708 130 : n->expr = $1;
4709 130 : n->collation = $2;
4710 130 : n->opclass = $3;
4711 130 : n->location = @1;
4712 130 : $$ = n;
4713 : }
4714 : | '(' a_expr ')' opt_collate opt_qualified_name
4715 : {
4716 210 : PartitionElem *n = makeNode(PartitionElem);
4717 :
4718 210 : n->name = NULL;
4719 210 : n->expr = $2;
4720 210 : n->collation = $4;
4721 210 : n->opclass = $5;
4722 210 : n->location = @1;
4723 210 : $$ = n;
4724 : }
4725 : ;
4726 :
4727 : table_access_method_clause:
4728 122 : USING name { $$ = $2; }
4729 40382 : | /*EMPTY*/ { $$ = NULL; }
4730 : ;
4731 :
4732 : /* WITHOUT OIDS is legacy only */
4733 : OptWith:
4734 858 : WITH reloptions { $$ = $2; }
4735 24 : | WITHOUT OIDS { $$ = NIL; }
4736 39028 : | /*EMPTY*/ { $$ = NIL; }
4737 : ;
4738 :
4739 60 : OnCommitOption: ON COMMIT DROP { $$ = ONCOMMIT_DROP; }
4740 104 : | ON COMMIT DELETE_P ROWS { $$ = ONCOMMIT_DELETE_ROWS; }
4741 24 : | ON COMMIT PRESERVE ROWS { $$ = ONCOMMIT_PRESERVE_ROWS; }
4742 39722 : | /*EMPTY*/ { $$ = ONCOMMIT_NOOP; }
4743 : ;
4744 :
4745 216 : OptTableSpace: TABLESPACE name { $$ = $2; }
4746 46982 : | /*EMPTY*/ { $$ = NULL; }
4747 : ;
4748 :
4749 66 : OptConsTableSpace: USING INDEX TABLESPACE name { $$ = $4; }
4750 9322 : | /*EMPTY*/ { $$ = NULL; }
4751 : ;
4752 :
4753 10666 : ExistingIndex: USING INDEX name { $$ = $3; }
4754 : ;
4755 :
4756 : /*****************************************************************************
4757 : *
4758 : * QUERY :
4759 : * CREATE STATISTICS [[IF NOT EXISTS] stats_name] [(stat types)]
4760 : * ON expression-list FROM from_list
4761 : *
4762 : * Note: the expectation here is that the clauses after ON are a subset of
4763 : * SELECT syntax, allowing for expressions and joined tables, and probably
4764 : * someday a WHERE clause. Much less than that is currently implemented,
4765 : * but the grammar accepts it and then we'll throw FEATURE_NOT_SUPPORTED
4766 : * errors as necessary at execution.
4767 : *
4768 : * Statistics name is optional unless IF NOT EXISTS is specified.
4769 : *
4770 : *****************************************************************************/
4771 :
4772 : CreateStatsStmt:
4773 : CREATE STATISTICS opt_qualified_name
4774 : opt_name_list ON stats_params FROM from_list
4775 : {
4776 832 : CreateStatsStmt *n = makeNode(CreateStatsStmt);
4777 :
4778 832 : n->defnames = $3;
4779 832 : n->stat_types = $4;
4780 832 : n->exprs = $6;
4781 832 : n->relations = $8;
4782 832 : n->stxcomment = NULL;
4783 832 : n->if_not_exists = false;
4784 832 : $$ = (Node *) n;
4785 : }
4786 : | CREATE STATISTICS IF_P NOT EXISTS any_name
4787 : opt_name_list ON stats_params FROM from_list
4788 : {
4789 12 : CreateStatsStmt *n = makeNode(CreateStatsStmt);
4790 :
4791 12 : n->defnames = $6;
4792 12 : n->stat_types = $7;
4793 12 : n->exprs = $9;
4794 12 : n->relations = $11;
4795 12 : n->stxcomment = NULL;
4796 12 : n->if_not_exists = true;
4797 12 : $$ = (Node *) n;
4798 : }
4799 : ;
4800 :
4801 : /*
4802 : * Statistics attributes can be either simple column references, or arbitrary
4803 : * expressions in parens. For compatibility with index attributes permitted
4804 : * in CREATE INDEX, we allow an expression that's just a function call to be
4805 : * written without parens.
4806 : */
4807 :
4808 856 : stats_params: stats_param { $$ = list_make1($1); }
4809 1170 : | stats_params ',' stats_param { $$ = lappend($1, $3); }
4810 : ;
4811 :
4812 : stats_param: ColId
4813 : {
4814 1516 : $$ = makeNode(StatsElem);
4815 1516 : $$->name = $1;
4816 1516 : $$->expr = NULL;
4817 : }
4818 : | func_expr_windowless
4819 : {
4820 38 : $$ = makeNode(StatsElem);
4821 38 : $$->name = NULL;
4822 38 : $$->expr = $1;
4823 : }
4824 : | '(' a_expr ')'
4825 : {
4826 472 : $$ = makeNode(StatsElem);
4827 472 : $$->name = NULL;
4828 472 : $$->expr = $2;
4829 : }
4830 : ;
4831 :
4832 : /*****************************************************************************
4833 : *
4834 : * QUERY :
4835 : * ALTER STATISTICS [IF EXISTS] stats_name
4836 : * SET STATISTICS <SignedIconst>
4837 : *
4838 : *****************************************************************************/
4839 :
4840 : AlterStatsStmt:
4841 : ALTER STATISTICS any_name SET STATISTICS set_statistics_value
4842 : {
4843 20 : AlterStatsStmt *n = makeNode(AlterStatsStmt);
4844 :
4845 20 : n->defnames = $3;
4846 20 : n->missing_ok = false;
4847 20 : n->stxstattarget = $6;
4848 20 : $$ = (Node *) n;
4849 : }
4850 : | ALTER STATISTICS IF_P EXISTS any_name SET STATISTICS set_statistics_value
4851 : {
4852 6 : AlterStatsStmt *n = makeNode(AlterStatsStmt);
4853 :
4854 6 : n->defnames = $5;
4855 6 : n->missing_ok = true;
4856 6 : n->stxstattarget = $8;
4857 6 : $$ = (Node *) n;
4858 : }
4859 : ;
4860 :
4861 : /*****************************************************************************
4862 : *
4863 : * QUERY :
4864 : * CREATE TABLE relname AS SelectStmt [ WITH [NO] DATA ]
4865 : *
4866 : *
4867 : * Note: SELECT ... INTO is a now-deprecated alternative for this.
4868 : *
4869 : *****************************************************************************/
4870 :
4871 : CreateAsStmt:
4872 : CREATE OptTemp TABLE create_as_target AS SelectStmt opt_with_data
4873 : {
4874 1228 : CreateTableAsStmt *ctas = makeNode(CreateTableAsStmt);
4875 :
4876 1228 : ctas->query = $6;
4877 1228 : ctas->into = $4;
4878 1228 : ctas->objtype = OBJECT_TABLE;
4879 1228 : ctas->is_select_into = false;
4880 1228 : ctas->if_not_exists = false;
4881 : /* cram additional flags into the IntoClause */
4882 1228 : $4->rel->relpersistence = $2;
4883 1228 : $4->skipData = !($7);
4884 1228 : $$ = (Node *) ctas;
4885 : }
4886 : | CREATE OptTemp TABLE IF_P NOT EXISTS create_as_target AS SelectStmt opt_with_data
4887 : {
4888 52 : CreateTableAsStmt *ctas = makeNode(CreateTableAsStmt);
4889 :
4890 52 : ctas->query = $9;
4891 52 : ctas->into = $7;
4892 52 : ctas->objtype = OBJECT_TABLE;
4893 52 : ctas->is_select_into = false;
4894 52 : ctas->if_not_exists = true;
4895 : /* cram additional flags into the IntoClause */
4896 52 : $7->rel->relpersistence = $2;
4897 52 : $7->skipData = !($10);
4898 52 : $$ = (Node *) ctas;
4899 : }
4900 : ;
4901 :
4902 : create_as_target:
4903 : qualified_name opt_column_list table_access_method_clause
4904 : OptWith OnCommitOption OptTableSpace
4905 : {
4906 1368 : $$ = makeNode(IntoClause);
4907 1368 : $$->rel = $1;
4908 1368 : $$->colNames = $2;
4909 1368 : $$->accessMethod = $3;
4910 1368 : $$->options = $4;
4911 1368 : $$->onCommit = $5;
4912 1368 : $$->tableSpaceName = $6;
4913 1368 : $$->viewQuery = NULL;
4914 1368 : $$->skipData = false; /* might get changed later */
4915 : }
4916 : ;
4917 :
4918 : opt_with_data:
4919 36 : WITH DATA_P { $$ = true; }
4920 218 : | WITH NO DATA_P { $$ = false; }
4921 1970 : | /*EMPTY*/ { $$ = true; }
4922 : ;
4923 :
4924 :
4925 : /*****************************************************************************
4926 : *
4927 : * QUERY :
4928 : * CREATE MATERIALIZED VIEW relname AS SelectStmt
4929 : *
4930 : *****************************************************************************/
4931 :
4932 : CreateMatViewStmt:
4933 : CREATE OptNoLog MATERIALIZED VIEW create_mv_target AS SelectStmt opt_with_data
4934 : {
4935 540 : CreateTableAsStmt *ctas = makeNode(CreateTableAsStmt);
4936 :
4937 540 : ctas->query = $7;
4938 540 : ctas->into = $5;
4939 540 : ctas->objtype = OBJECT_MATVIEW;
4940 540 : ctas->is_select_into = false;
4941 540 : ctas->if_not_exists = false;
4942 : /* cram additional flags into the IntoClause */
4943 540 : $5->rel->relpersistence = $2;
4944 540 : $5->skipData = !($8);
4945 540 : $$ = (Node *) ctas;
4946 : }
4947 : | CREATE OptNoLog MATERIALIZED VIEW IF_P NOT EXISTS create_mv_target AS SelectStmt opt_with_data
4948 : {
4949 48 : CreateTableAsStmt *ctas = makeNode(CreateTableAsStmt);
4950 :
4951 48 : ctas->query = $10;
4952 48 : ctas->into = $8;
4953 48 : ctas->objtype = OBJECT_MATVIEW;
4954 48 : ctas->is_select_into = false;
4955 48 : ctas->if_not_exists = true;
4956 : /* cram additional flags into the IntoClause */
4957 48 : $8->rel->relpersistence = $2;
4958 48 : $8->skipData = !($11);
4959 48 : $$ = (Node *) ctas;
4960 : }
4961 : ;
4962 :
4963 : create_mv_target:
4964 : qualified_name opt_column_list table_access_method_clause opt_reloptions OptTableSpace
4965 : {
4966 588 : $$ = makeNode(IntoClause);
4967 588 : $$->rel = $1;
4968 588 : $$->colNames = $2;
4969 588 : $$->accessMethod = $3;
4970 588 : $$->options = $4;
4971 588 : $$->onCommit = ONCOMMIT_NOOP;
4972 588 : $$->tableSpaceName = $5;
4973 588 : $$->viewQuery = NULL; /* filled at analysis time */
4974 588 : $$->skipData = false; /* might get changed later */
4975 : }
4976 : ;
4977 :
4978 0 : OptNoLog: UNLOGGED { $$ = RELPERSISTENCE_UNLOGGED; }
4979 588 : | /*EMPTY*/ { $$ = RELPERSISTENCE_PERMANENT; }
4980 : ;
4981 :
4982 :
4983 : /*****************************************************************************
4984 : *
4985 : * QUERY :
4986 : * REFRESH MATERIALIZED VIEW qualified_name
4987 : *
4988 : *****************************************************************************/
4989 :
4990 : RefreshMatViewStmt:
4991 : REFRESH MATERIALIZED VIEW opt_concurrently qualified_name opt_with_data
4992 : {
4993 268 : RefreshMatViewStmt *n = makeNode(RefreshMatViewStmt);
4994 :
4995 268 : n->concurrent = $4;
4996 268 : n->relation = $5;
4997 268 : n->skipData = !($6);
4998 268 : $$ = (Node *) n;
4999 : }
5000 : ;
5001 :
5002 :
5003 : /*****************************************************************************
5004 : *
5005 : * QUERY :
5006 : * CREATE SEQUENCE seqname
5007 : * ALTER SEQUENCE seqname
5008 : *
5009 : *****************************************************************************/
5010 :
5011 : CreateSeqStmt:
5012 : CREATE OptTemp SEQUENCE qualified_name OptSeqOptList
5013 : {
5014 702 : CreateSeqStmt *n = makeNode(CreateSeqStmt);
5015 :
5016 702 : $4->relpersistence = $2;
5017 702 : n->sequence = $4;
5018 702 : n->options = $5;
5019 702 : n->ownerId = InvalidOid;
5020 702 : n->if_not_exists = false;
5021 702 : $$ = (Node *) n;
5022 : }
5023 : | CREATE OptTemp SEQUENCE IF_P NOT EXISTS qualified_name OptSeqOptList
5024 : {
5025 24 : CreateSeqStmt *n = makeNode(CreateSeqStmt);
5026 :
5027 24 : $7->relpersistence = $2;
5028 24 : n->sequence = $7;
5029 24 : n->options = $8;
5030 24 : n->ownerId = InvalidOid;
5031 24 : n->if_not_exists = true;
5032 24 : $$ = (Node *) n;
5033 : }
5034 : ;
5035 :
5036 : AlterSeqStmt:
5037 : ALTER SEQUENCE qualified_name SeqOptList
5038 : {
5039 188 : AlterSeqStmt *n = makeNode(AlterSeqStmt);
5040 :
5041 188 : n->sequence = $3;
5042 188 : n->options = $4;
5043 188 : n->missing_ok = false;
5044 188 : $$ = (Node *) n;
5045 : }
5046 : | ALTER SEQUENCE IF_P EXISTS qualified_name SeqOptList
5047 : {
5048 12 : AlterSeqStmt *n = makeNode(AlterSeqStmt);
5049 :
5050 12 : n->sequence = $5;
5051 12 : n->options = $6;
5052 12 : n->missing_ok = true;
5053 12 : $$ = (Node *) n;
5054 : }
5055 :
5056 : ;
5057 :
5058 270 : OptSeqOptList: SeqOptList { $$ = $1; }
5059 456 : | /*EMPTY*/ { $$ = NIL; }
5060 : ;
5061 :
5062 74 : OptParenthesizedSeqOptList: '(' SeqOptList ')' { $$ = $2; }
5063 454 : | /*EMPTY*/ { $$ = NIL; }
5064 : ;
5065 :
5066 544 : SeqOptList: SeqOptElem { $$ = list_make1($1); }
5067 806 : | SeqOptList SeqOptElem { $$ = lappend($1, $2); }
5068 : ;
5069 :
5070 : SeqOptElem: AS SimpleTypename
5071 : {
5072 190 : $$ = makeDefElem("as", (Node *) $2, @1);
5073 : }
5074 : | CACHE NumericOnly
5075 : {
5076 130 : $$ = makeDefElem("cache", (Node *) $2, @1);
5077 : }
5078 : | CYCLE
5079 : {
5080 34 : $$ = makeDefElem("cycle", (Node *) makeBoolean(true), @1);
5081 : }
5082 : | NO CYCLE
5083 : {
5084 14 : $$ = makeDefElem("cycle", (Node *) makeBoolean(false), @1);
5085 : }
5086 : | INCREMENT opt_by NumericOnly
5087 : {
5088 258 : $$ = makeDefElem("increment", (Node *) $3, @1);
5089 : }
5090 : | LOGGED
5091 : {
5092 2 : $$ = makeDefElem("logged", NULL, @1);
5093 : }
5094 : | MAXVALUE NumericOnly
5095 : {
5096 68 : $$ = makeDefElem("maxvalue", (Node *) $2, @1);
5097 : }
5098 : | MINVALUE NumericOnly
5099 : {
5100 68 : $$ = makeDefElem("minvalue", (Node *) $2, @1);
5101 : }
5102 : | NO MAXVALUE
5103 : {
5104 108 : $$ = makeDefElem("maxvalue", NULL, @1);
5105 : }
5106 : | NO MINVALUE
5107 : {
5108 108 : $$ = makeDefElem("minvalue", NULL, @1);
5109 : }
5110 : | OWNED BY any_name
5111 : {
5112 72 : $$ = makeDefElem("owned_by", (Node *) $3, @1);
5113 : }
5114 : | SEQUENCE NAME_P any_name
5115 : {
5116 44 : $$ = makeDefElem("sequence_name", (Node *) $3, @1);
5117 : }
5118 : | START opt_with NumericOnly
5119 : {
5120 240 : $$ = makeDefElem("start", (Node *) $3, @1);
5121 : }
5122 : | RESTART
5123 : {
5124 6 : $$ = makeDefElem("restart", NULL, @1);
5125 : }
5126 : | RESTART opt_with NumericOnly
5127 : {
5128 60 : $$ = makeDefElem("restart", (Node *) $3, @1);
5129 : }
5130 : | UNLOGGED
5131 : {
5132 2 : $$ = makeDefElem("unlogged", NULL, @1);
5133 : }
5134 : ;
5135 :
5136 : opt_by: BY
5137 : | /* EMPTY */
5138 : ;
5139 :
5140 : NumericOnly:
5141 324 : FCONST { $$ = (Node *) makeFloat($1); }
5142 0 : | '+' FCONST { $$ = (Node *) makeFloat($2); }
5143 : | '-' FCONST
5144 : {
5145 20 : Float *f = makeFloat($2);
5146 :
5147 20 : doNegateFloat(f);
5148 20 : $$ = (Node *) f;
5149 : }
5150 13090 : | SignedIconst { $$ = (Node *) makeInteger($1); }
5151 : ;
5152 :
5153 90 : NumericOnly_list: NumericOnly { $$ = list_make1($1); }
5154 6 : | NumericOnly_list ',' NumericOnly { $$ = lappend($1, $3); }
5155 : ;
5156 :
5157 : /*****************************************************************************
5158 : *
5159 : * QUERIES :
5160 : * CREATE [OR REPLACE] [TRUSTED] [PROCEDURAL] LANGUAGE ...
5161 : * DROP [PROCEDURAL] LANGUAGE ...
5162 : *
5163 : *****************************************************************************/
5164 :
5165 : CreatePLangStmt:
5166 : CREATE opt_or_replace opt_trusted opt_procedural LANGUAGE name
5167 : {
5168 : /*
5169 : * We now interpret parameterless CREATE LANGUAGE as
5170 : * CREATE EXTENSION. "OR REPLACE" is silently translated
5171 : * to "IF NOT EXISTS", which isn't quite the same, but
5172 : * seems more useful than throwing an error. We just
5173 : * ignore TRUSTED, as the previous code would have too.
5174 : */
5175 0 : CreateExtensionStmt *n = makeNode(CreateExtensionStmt);
5176 :
5177 0 : n->if_not_exists = $2;
5178 0 : n->extname = $6;
5179 0 : n->options = NIL;
5180 0 : $$ = (Node *) n;
5181 : }
5182 : | CREATE opt_or_replace opt_trusted opt_procedural LANGUAGE name
5183 : HANDLER handler_name opt_inline_handler opt_validator
5184 : {
5185 142 : CreatePLangStmt *n = makeNode(CreatePLangStmt);
5186 :
5187 142 : n->replace = $2;
5188 142 : n->plname = $6;
5189 142 : n->plhandler = $8;
5190 142 : n->plinline = $9;
5191 142 : n->plvalidator = $10;
5192 142 : n->pltrusted = $3;
5193 142 : $$ = (Node *) n;
5194 : }
5195 : ;
5196 :
5197 : opt_trusted:
5198 112 : TRUSTED { $$ = true; }
5199 38 : | /*EMPTY*/ { $$ = false; }
5200 : ;
5201 :
5202 : /* This ought to be just func_name, but that causes reduce/reduce conflicts
5203 : * (CREATE LANGUAGE is the only place where func_name isn't followed by '(').
5204 : * Work around by using simple names, instead.
5205 : */
5206 : handler_name:
5207 558 : name { $$ = list_make1(makeString($1)); }
5208 2 : | name attrs { $$ = lcons(makeString($1), $2); }
5209 : ;
5210 :
5211 : opt_inline_handler:
5212 124 : INLINE_P handler_name { $$ = $2; }
5213 18 : | /*EMPTY*/ { $$ = NIL; }
5214 : ;
5215 :
5216 : validator_clause:
5217 124 : VALIDATOR handler_name { $$ = $2; }
5218 0 : | NO VALIDATOR { $$ = NIL; }
5219 : ;
5220 :
5221 : opt_validator:
5222 124 : validator_clause { $$ = $1; }
5223 18 : | /*EMPTY*/ { $$ = NIL; }
5224 : ;
5225 :
5226 : opt_procedural:
5227 : PROCEDURAL
5228 : | /*EMPTY*/
5229 : ;
5230 :
5231 : /*****************************************************************************
5232 : *
5233 : * QUERY:
5234 : * CREATE TABLESPACE tablespace LOCATION '/path/to/tablespace/'
5235 : *
5236 : *****************************************************************************/
5237 :
5238 : CreateTableSpaceStmt: CREATE TABLESPACE name OptTableSpaceOwner LOCATION Sconst opt_reloptions
5239 : {
5240 130 : CreateTableSpaceStmt *n = makeNode(CreateTableSpaceStmt);
5241 :
5242 130 : n->tablespacename = $3;
5243 130 : n->owner = $4;
5244 130 : n->location = $6;
5245 130 : n->options = $7;
5246 130 : $$ = (Node *) n;
5247 : }
5248 : ;
5249 :
5250 10 : OptTableSpaceOwner: OWNER RoleSpec { $$ = $2; }
5251 120 : | /*EMPTY */ { $$ = NULL; }
5252 : ;
5253 :
5254 : /*****************************************************************************
5255 : *
5256 : * QUERY :
5257 : * DROP TABLESPACE <tablespace>
5258 : *
5259 : * No need for drop behaviour as we cannot implement dependencies for
5260 : * objects in other databases; we can only support RESTRICT.
5261 : *
5262 : ****************************************************************************/
5263 :
5264 : DropTableSpaceStmt: DROP TABLESPACE name
5265 : {
5266 64 : DropTableSpaceStmt *n = makeNode(DropTableSpaceStmt);
5267 :
5268 64 : n->tablespacename = $3;
5269 64 : n->missing_ok = false;
5270 64 : $$ = (Node *) n;
5271 : }
5272 : | DROP TABLESPACE IF_P EXISTS name
5273 : {
5274 0 : DropTableSpaceStmt *n = makeNode(DropTableSpaceStmt);
5275 :
5276 0 : n->tablespacename = $5;
5277 0 : n->missing_ok = true;
5278 0 : $$ = (Node *) n;
5279 : }
5280 : ;
5281 :
5282 : /*****************************************************************************
5283 : *
5284 : * QUERY:
5285 : * CREATE EXTENSION extension
5286 : * [ WITH ] [ SCHEMA schema ] [ VERSION version ]
5287 : *
5288 : *****************************************************************************/
5289 :
5290 : CreateExtensionStmt: CREATE EXTENSION name opt_with create_extension_opt_list
5291 : {
5292 566 : CreateExtensionStmt *n = makeNode(CreateExtensionStmt);
5293 :
5294 566 : n->extname = $3;
5295 566 : n->if_not_exists = false;
5296 566 : n->options = $5;
5297 566 : $$ = (Node *) n;
5298 : }
5299 : | CREATE EXTENSION IF_P NOT EXISTS name opt_with create_extension_opt_list
5300 : {
5301 20 : CreateExtensionStmt *n = makeNode(CreateExtensionStmt);
5302 :
5303 20 : n->extname = $6;
5304 20 : n->if_not_exists = true;
5305 20 : n->options = $8;
5306 20 : $$ = (Node *) n;
5307 : }
5308 : ;
5309 :
5310 : create_extension_opt_list:
5311 : create_extension_opt_list create_extension_opt_item
5312 98 : { $$ = lappend($1, $2); }
5313 : | /* EMPTY */
5314 586 : { $$ = NIL; }
5315 : ;
5316 :
5317 : create_extension_opt_item:
5318 : SCHEMA name
5319 : {
5320 46 : $$ = makeDefElem("schema", (Node *) makeString($2), @1);
5321 : }
5322 : | VERSION_P NonReservedWord_or_Sconst
5323 : {
5324 12 : $$ = makeDefElem("new_version", (Node *) makeString($2), @1);
5325 : }
5326 : | FROM NonReservedWord_or_Sconst
5327 : {
5328 0 : ereport(ERROR,
5329 : (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
5330 : errmsg("CREATE EXTENSION ... FROM is no longer supported"),
5331 : parser_errposition(@1)));
5332 : }
5333 : | CASCADE
5334 : {
5335 40 : $$ = makeDefElem("cascade", (Node *) makeBoolean(true), @1);
5336 : }
5337 : ;
5338 :
5339 : /*****************************************************************************
5340 : *
5341 : * ALTER EXTENSION name UPDATE [ TO version ]
5342 : *
5343 : *****************************************************************************/
5344 :
5345 : AlterExtensionStmt: ALTER EXTENSION name UPDATE alter_extension_opt_list
5346 : {
5347 40 : AlterExtensionStmt *n = makeNode(AlterExtensionStmt);
5348 :
5349 40 : n->extname = $3;
5350 40 : n->options = $5;
5351 40 : $$ = (Node *) n;
5352 : }
5353 : ;
5354 :
5355 : alter_extension_opt_list:
5356 : alter_extension_opt_list alter_extension_opt_item
5357 40 : { $$ = lappend($1, $2); }
5358 : | /* EMPTY */
5359 40 : { $$ = NIL; }
5360 : ;
5361 :
5362 : alter_extension_opt_item:
5363 : TO NonReservedWord_or_Sconst
5364 : {
5365 40 : $$ = makeDefElem("new_version", (Node *) makeString($2), @1);
5366 : }
5367 : ;
5368 :
5369 : /*****************************************************************************
5370 : *
5371 : * ALTER EXTENSION name ADD/DROP object-identifier
5372 : *
5373 : *****************************************************************************/
5374 :
5375 : AlterExtensionContentsStmt:
5376 : ALTER EXTENSION name add_drop object_type_name name
5377 : {
5378 18 : AlterExtensionContentsStmt *n = makeNode(AlterExtensionContentsStmt);
5379 :
5380 18 : n->extname = $3;
5381 18 : n->action = $4;
5382 18 : n->objtype = $5;
5383 18 : n->object = (Node *) makeString($6);
5384 18 : $$ = (Node *) n;
5385 : }
5386 : | ALTER EXTENSION name add_drop object_type_any_name any_name
5387 : {
5388 88 : AlterExtensionContentsStmt *n = makeNode(AlterExtensionContentsStmt);
5389 :
5390 88 : n->extname = $3;
5391 88 : n->action = $4;
5392 88 : n->objtype = $5;
5393 88 : n->object = (Node *) $6;
5394 88 : $$ = (Node *) n;
5395 : }
5396 : | ALTER EXTENSION name add_drop AGGREGATE aggregate_with_argtypes
5397 : {
5398 8 : AlterExtensionContentsStmt *n = makeNode(AlterExtensionContentsStmt);
5399 :
5400 8 : n->extname = $3;
5401 8 : n->action = $4;
5402 8 : n->objtype = OBJECT_AGGREGATE;
5403 8 : n->object = (Node *) $6;
5404 8 : $$ = (Node *) n;
5405 : }
5406 : | ALTER EXTENSION name add_drop CAST '(' Typename AS Typename ')'
5407 : {
5408 4 : AlterExtensionContentsStmt *n = makeNode(AlterExtensionContentsStmt);
5409 :
5410 4 : n->extname = $3;
5411 4 : n->action = $4;
5412 4 : n->objtype = OBJECT_CAST;
5413 4 : n->object = (Node *) list_make2($7, $9);
5414 4 : $$ = (Node *) n;
5415 : }
5416 : | ALTER EXTENSION name add_drop DOMAIN_P Typename
5417 : {
5418 0 : AlterExtensionContentsStmt *n = makeNode(AlterExtensionContentsStmt);
5419 :
5420 0 : n->extname = $3;
5421 0 : n->action = $4;
5422 0 : n->objtype = OBJECT_DOMAIN;
5423 0 : n->object = (Node *) $6;
5424 0 : $$ = (Node *) n;
5425 : }
5426 : | ALTER EXTENSION name add_drop FUNCTION function_with_argtypes
5427 : {
5428 120 : AlterExtensionContentsStmt *n = makeNode(AlterExtensionContentsStmt);
5429 :
5430 120 : n->extname = $3;
5431 120 : n->action = $4;
5432 120 : n->objtype = OBJECT_FUNCTION;
5433 120 : n->object = (Node *) $6;
5434 120 : $$ = (Node *) n;
5435 : }
5436 : | ALTER EXTENSION name add_drop OPERATOR operator_with_argtypes
5437 : {
5438 18 : AlterExtensionContentsStmt *n = makeNode(AlterExtensionContentsStmt);
5439 :
5440 18 : n->extname = $3;
5441 18 : n->action = $4;
5442 18 : n->objtype = OBJECT_OPERATOR;
5443 18 : n->object = (Node *) $6;
5444 18 : $$ = (Node *) n;
5445 : }
5446 : | ALTER EXTENSION name add_drop OPERATOR CLASS any_name USING name
5447 : {
5448 4 : AlterExtensionContentsStmt *n = makeNode(AlterExtensionContentsStmt);
5449 :
5450 4 : n->extname = $3;
5451 4 : n->action = $4;
5452 4 : n->objtype = OBJECT_OPCLASS;
5453 4 : n->object = (Node *) lcons(makeString($9), $7);
5454 4 : $$ = (Node *) n;
5455 : }
5456 : | ALTER EXTENSION name add_drop OPERATOR FAMILY any_name USING name
5457 : {
5458 4 : AlterExtensionContentsStmt *n = makeNode(AlterExtensionContentsStmt);
5459 :
5460 4 : n->extname = $3;
5461 4 : n->action = $4;
5462 4 : n->objtype = OBJECT_OPFAMILY;
5463 4 : n->object = (Node *) lcons(makeString($9), $7);
5464 4 : $$ = (Node *) n;
5465 : }
5466 : | ALTER EXTENSION name add_drop PROCEDURE function_with_argtypes
5467 : {
5468 0 : AlterExtensionContentsStmt *n = makeNode(AlterExtensionContentsStmt);
5469 :
5470 0 : n->extname = $3;
5471 0 : n->action = $4;
5472 0 : n->objtype = OBJECT_PROCEDURE;
5473 0 : n->object = (Node *) $6;
5474 0 : $$ = (Node *) n;
5475 : }
5476 : | ALTER EXTENSION name add_drop ROUTINE function_with_argtypes
5477 : {
5478 0 : AlterExtensionContentsStmt *n = makeNode(AlterExtensionContentsStmt);
5479 :
5480 0 : n->extname = $3;
5481 0 : n->action = $4;
5482 0 : n->objtype = OBJECT_ROUTINE;
5483 0 : n->object = (Node *) $6;
5484 0 : $$ = (Node *) n;
5485 : }
5486 : | ALTER EXTENSION name add_drop TRANSFORM FOR Typename LANGUAGE name
5487 : {
5488 4 : AlterExtensionContentsStmt *n = makeNode(AlterExtensionContentsStmt);
5489 :
5490 4 : n->extname = $3;
5491 4 : n->action = $4;
5492 4 : n->objtype = OBJECT_TRANSFORM;
5493 4 : n->object = (Node *) list_make2($7, makeString($9));
5494 4 : $$ = (Node *) n;
5495 : }
5496 : | ALTER EXTENSION name add_drop TYPE_P Typename
5497 : {
5498 8 : AlterExtensionContentsStmt *n = makeNode(AlterExtensionContentsStmt);
5499 :
5500 8 : n->extname = $3;
5501 8 : n->action = $4;
5502 8 : n->objtype = OBJECT_TYPE;
5503 8 : n->object = (Node *) $6;
5504 8 : $$ = (Node *) n;
5505 : }
5506 : ;
5507 :
5508 : /*****************************************************************************
5509 : *
5510 : * QUERY:
5511 : * CREATE FOREIGN DATA WRAPPER name options
5512 : *
5513 : *****************************************************************************/
5514 :
5515 : CreateFdwStmt: CREATE FOREIGN DATA_P WRAPPER name opt_fdw_options create_generic_options
5516 : {
5517 208 : CreateFdwStmt *n = makeNode(CreateFdwStmt);
5518 :
5519 208 : n->fdwname = $5;
5520 208 : n->func_options = $6;
5521 208 : n->options = $7;
5522 208 : $$ = (Node *) n;
5523 : }
5524 : ;
5525 :
5526 : fdw_option:
5527 58 : HANDLER handler_name { $$ = makeDefElem("handler", (Node *) $2, @1); }
5528 0 : | NO HANDLER { $$ = makeDefElem("handler", NULL, @1); }
5529 50 : | VALIDATOR handler_name { $$ = makeDefElem("validator", (Node *) $2, @1); }
5530 6 : | NO VALIDATOR { $$ = makeDefElem("validator", NULL, @1); }
5531 : ;
5532 :
5533 : fdw_options:
5534 92 : fdw_option { $$ = list_make1($1); }
5535 22 : | fdw_options fdw_option { $$ = lappend($1, $2); }
5536 : ;
5537 :
5538 : opt_fdw_options:
5539 56 : fdw_options { $$ = $1; }
5540 244 : | /*EMPTY*/ { $$ = NIL; }
5541 : ;
5542 :
5543 : /*****************************************************************************
5544 : *
5545 : * QUERY :
5546 : * ALTER FOREIGN DATA WRAPPER name options
5547 : *
5548 : ****************************************************************************/
5549 :
5550 : AlterFdwStmt: ALTER FOREIGN DATA_P WRAPPER name opt_fdw_options alter_generic_options
5551 : {
5552 86 : AlterFdwStmt *n = makeNode(AlterFdwStmt);
5553 :
5554 86 : n->fdwname = $5;
5555 86 : n->func_options = $6;
5556 86 : n->options = $7;
5557 86 : $$ = (Node *) n;
5558 : }
5559 : | ALTER FOREIGN DATA_P WRAPPER name fdw_options
5560 : {
5561 36 : AlterFdwStmt *n = makeNode(AlterFdwStmt);
5562 :
5563 36 : n->fdwname = $5;
5564 36 : n->func_options = $6;
5565 36 : n->options = NIL;
5566 36 : $$ = (Node *) n;
5567 : }
5568 : ;
5569 :
5570 : /* Options definition for CREATE FDW, SERVER and USER MAPPING */
5571 : create_generic_options:
5572 772 : OPTIONS '(' generic_option_list ')' { $$ = $3; }
5573 69464 : | /*EMPTY*/ { $$ = NIL; }
5574 : ;
5575 :
5576 : generic_option_list:
5577 : generic_option_elem
5578 : {
5579 772 : $$ = list_make1($1);
5580 : }
5581 : | generic_option_list ',' generic_option_elem
5582 : {
5583 496 : $$ = lappend($1, $3);
5584 : }
5585 : ;
5586 :
5587 : /* Options definition for ALTER FDW, SERVER and USER MAPPING */
5588 : alter_generic_options:
5589 508 : OPTIONS '(' alter_generic_option_list ')' { $$ = $3; }
5590 : ;
5591 :
5592 : alter_generic_option_list:
5593 : alter_generic_option_elem
5594 : {
5595 508 : $$ = list_make1($1);
5596 : }
5597 : | alter_generic_option_list ',' alter_generic_option_elem
5598 : {
5599 168 : $$ = lappend($1, $3);
5600 : }
5601 : ;
5602 :
5603 : alter_generic_option_elem:
5604 : generic_option_elem
5605 : {
5606 200 : $$ = $1;
5607 : }
5608 : | SET generic_option_elem
5609 : {
5610 128 : $$ = $2;
5611 128 : $$->defaction = DEFELEM_SET;
5612 : }
5613 : | ADD_P generic_option_elem
5614 : {
5615 220 : $$ = $2;
5616 220 : $$->defaction = DEFELEM_ADD;
5617 : }
5618 : | DROP generic_option_name
5619 : {
5620 128 : $$ = makeDefElemExtended(NULL, $2, NULL, DEFELEM_DROP, @2);
5621 : }
5622 : ;
5623 :
5624 : generic_option_elem:
5625 : generic_option_name generic_option_arg
5626 : {
5627 1816 : $$ = makeDefElem($1, $2, @1);
5628 : }
5629 : ;
5630 :
5631 : generic_option_name:
5632 1944 : ColLabel { $$ = $1; }
5633 : ;
5634 :
5635 : /* We could use def_arg here, but the spec only requires string literals */
5636 : generic_option_arg:
5637 1816 : Sconst { $$ = (Node *) makeString($1); }
5638 : ;
5639 :
5640 : /*****************************************************************************
5641 : *
5642 : * QUERY:
5643 : * CREATE SERVER name [TYPE] [VERSION] [OPTIONS]
5644 : *
5645 : *****************************************************************************/
5646 :
5647 : CreateForeignServerStmt: CREATE SERVER name opt_type opt_foreign_server_version
5648 : FOREIGN DATA_P WRAPPER name create_generic_options
5649 : {
5650 280 : CreateForeignServerStmt *n = makeNode(CreateForeignServerStmt);
5651 :
5652 280 : n->servername = $3;
5653 280 : n->servertype = $4;
5654 280 : n->version = $5;
5655 280 : n->fdwname = $9;
5656 280 : n->options = $10;
5657 280 : n->if_not_exists = false;
5658 280 : $$ = (Node *) n;
5659 : }
5660 : | CREATE SERVER IF_P NOT EXISTS name opt_type opt_foreign_server_version
5661 : FOREIGN DATA_P WRAPPER name create_generic_options
5662 : {
5663 24 : CreateForeignServerStmt *n = makeNode(CreateForeignServerStmt);
5664 :
5665 24 : n->servername = $6;
5666 24 : n->servertype = $7;
5667 24 : n->version = $8;
5668 24 : n->fdwname = $12;
5669 24 : n->options = $13;
5670 24 : n->if_not_exists = true;
5671 24 : $$ = (Node *) n;
5672 : }
5673 : ;
5674 :
5675 : opt_type:
5676 18 : TYPE_P Sconst { $$ = $2; }
5677 286 : | /*EMPTY*/ { $$ = NULL; }
5678 : ;
5679 :
5680 :
5681 : foreign_server_version:
5682 66 : VERSION_P Sconst { $$ = $2; }
5683 0 : | VERSION_P NULL_P { $$ = NULL; }
5684 : ;
5685 :
5686 : opt_foreign_server_version:
5687 18 : foreign_server_version { $$ = $1; }
5688 286 : | /*EMPTY*/ { $$ = NULL; }
5689 : ;
5690 :
5691 : /*****************************************************************************
5692 : *
5693 : * QUERY :
5694 : * ALTER SERVER name [VERSION] [OPTIONS]
5695 : *
5696 : ****************************************************************************/
5697 :
5698 : AlterForeignServerStmt: ALTER SERVER name foreign_server_version alter_generic_options
5699 : {
5700 6 : AlterForeignServerStmt *n = makeNode(AlterForeignServerStmt);
5701 :
5702 6 : n->servername = $3;
5703 6 : n->version = $4;
5704 6 : n->options = $5;
5705 6 : n->has_version = true;
5706 6 : $$ = (Node *) n;
5707 : }
5708 : | ALTER SERVER name foreign_server_version
5709 : {
5710 42 : AlterForeignServerStmt *n = makeNode(AlterForeignServerStmt);
5711 :
5712 42 : n->servername = $3;
5713 42 : n->version = $4;
5714 42 : n->has_version = true;
5715 42 : $$ = (Node *) n;
5716 : }
5717 : | ALTER SERVER name alter_generic_options
5718 : {
5719 184 : AlterForeignServerStmt *n = makeNode(AlterForeignServerStmt);
5720 :
5721 184 : n->servername = $3;
5722 184 : n->options = $4;
5723 184 : $$ = (Node *) n;
5724 : }
5725 : ;
5726 :
5727 : /*****************************************************************************
5728 : *
5729 : * QUERY:
5730 : * CREATE FOREIGN TABLE relname (...) SERVER name (...)
5731 : *
5732 : *****************************************************************************/
5733 :
5734 : CreateForeignTableStmt:
5735 : CREATE FOREIGN TABLE qualified_name
5736 : '(' OptTableElementList ')'
5737 : OptInherit SERVER name create_generic_options
5738 : {
5739 420 : CreateForeignTableStmt *n = makeNode(CreateForeignTableStmt);
5740 :
5741 420 : $4->relpersistence = RELPERSISTENCE_PERMANENT;
5742 420 : n->base.relation = $4;
5743 420 : n->base.tableElts = $6;
5744 420 : n->base.inhRelations = $8;
5745 420 : n->base.ofTypename = NULL;
5746 420 : n->base.constraints = NIL;
5747 420 : n->base.options = NIL;
5748 420 : n->base.oncommit = ONCOMMIT_NOOP;
5749 420 : n->base.tablespacename = NULL;
5750 420 : n->base.if_not_exists = false;
5751 : /* FDW-specific data */
5752 420 : n->servername = $10;
5753 420 : n->options = $11;
5754 420 : $$ = (Node *) n;
5755 : }
5756 : | CREATE FOREIGN TABLE IF_P NOT EXISTS qualified_name
5757 : '(' OptTableElementList ')'
5758 : OptInherit SERVER name create_generic_options
5759 : {
5760 0 : CreateForeignTableStmt *n = makeNode(CreateForeignTableStmt);
5761 :
5762 0 : $7->relpersistence = RELPERSISTENCE_PERMANENT;
5763 0 : n->base.relation = $7;
5764 0 : n->base.tableElts = $9;
5765 0 : n->base.inhRelations = $11;
5766 0 : n->base.ofTypename = NULL;
5767 0 : n->base.constraints = NIL;
5768 0 : n->base.options = NIL;
5769 0 : n->base.oncommit = ONCOMMIT_NOOP;
5770 0 : n->base.tablespacename = NULL;
5771 0 : n->base.if_not_exists = true;
5772 : /* FDW-specific data */
5773 0 : n->servername = $13;
5774 0 : n->options = $14;
5775 0 : $$ = (Node *) n;
5776 : }
5777 : | CREATE FOREIGN TABLE qualified_name
5778 : PARTITION OF qualified_name OptTypedTableElementList PartitionBoundSpec
5779 : SERVER name create_generic_options
5780 : {
5781 90 : CreateForeignTableStmt *n = makeNode(CreateForeignTableStmt);
5782 :
5783 90 : $4->relpersistence = RELPERSISTENCE_PERMANENT;
5784 90 : n->base.relation = $4;
5785 90 : n->base.inhRelations = list_make1($7);
5786 90 : n->base.tableElts = $8;
5787 90 : n->base.partbound = $9;
5788 90 : n->base.ofTypename = NULL;
5789 90 : n->base.constraints = NIL;
5790 90 : n->base.options = NIL;
5791 90 : n->base.oncommit = ONCOMMIT_NOOP;
5792 90 : n->base.tablespacename = NULL;
5793 90 : n->base.if_not_exists = false;
5794 : /* FDW-specific data */
5795 90 : n->servername = $11;
5796 90 : n->options = $12;
5797 90 : $$ = (Node *) n;
5798 : }
5799 : | CREATE FOREIGN TABLE IF_P NOT EXISTS qualified_name
5800 : PARTITION OF qualified_name OptTypedTableElementList PartitionBoundSpec
5801 : SERVER name create_generic_options
5802 : {
5803 0 : CreateForeignTableStmt *n = makeNode(CreateForeignTableStmt);
5804 :
5805 0 : $7->relpersistence = RELPERSISTENCE_PERMANENT;
5806 0 : n->base.relation = $7;
5807 0 : n->base.inhRelations = list_make1($10);
5808 0 : n->base.tableElts = $11;
5809 0 : n->base.partbound = $12;
5810 0 : n->base.ofTypename = NULL;
5811 0 : n->base.constraints = NIL;
5812 0 : n->base.options = NIL;
5813 0 : n->base.oncommit = ONCOMMIT_NOOP;
5814 0 : n->base.tablespacename = NULL;
5815 0 : n->base.if_not_exists = true;
5816 : /* FDW-specific data */
5817 0 : n->servername = $14;
5818 0 : n->options = $15;
5819 0 : $$ = (Node *) n;
5820 : }
5821 : ;
5822 :
5823 : /*****************************************************************************
5824 : *
5825 : * QUERY:
5826 : * IMPORT FOREIGN SCHEMA remote_schema
5827 : * [ { LIMIT TO | EXCEPT } ( table_list ) ]
5828 : * FROM SERVER server_name INTO local_schema [ OPTIONS (...) ]
5829 : *
5830 : ****************************************************************************/
5831 :
5832 : ImportForeignSchemaStmt:
5833 : IMPORT_P FOREIGN SCHEMA name import_qualification
5834 : FROM SERVER name INTO name create_generic_options
5835 : {
5836 48 : ImportForeignSchemaStmt *n = makeNode(ImportForeignSchemaStmt);
5837 :
5838 48 : n->server_name = $8;
5839 48 : n->remote_schema = $4;
5840 48 : n->local_schema = $10;
5841 48 : n->list_type = $5->type;
5842 48 : n->table_list = $5->table_names;
5843 48 : n->options = $11;
5844 48 : $$ = (Node *) n;
5845 : }
5846 : ;
5847 :
5848 : import_qualification_type:
5849 14 : LIMIT TO { $$ = FDW_IMPORT_SCHEMA_LIMIT_TO; }
5850 14 : | EXCEPT { $$ = FDW_IMPORT_SCHEMA_EXCEPT; }
5851 : ;
5852 :
5853 : import_qualification:
5854 : import_qualification_type '(' relation_expr_list ')'
5855 : {
5856 28 : ImportQual *n = (ImportQual *) palloc(sizeof(ImportQual));
5857 :
5858 28 : n->type = $1;
5859 28 : n->table_names = $3;
5860 28 : $$ = n;
5861 : }
5862 : | /*EMPTY*/
5863 : {
5864 20 : ImportQual *n = (ImportQual *) palloc(sizeof(ImportQual));
5865 20 : n->type = FDW_IMPORT_SCHEMA_ALL;
5866 20 : n->table_names = NIL;
5867 20 : $$ = n;
5868 : }
5869 : ;
5870 :
5871 : /*****************************************************************************
5872 : *
5873 : * QUERY:
5874 : * CREATE USER MAPPING FOR auth_ident SERVER name [OPTIONS]
5875 : *
5876 : *****************************************************************************/
5877 :
5878 : CreateUserMappingStmt: CREATE USER MAPPING FOR auth_ident SERVER name create_generic_options
5879 : {
5880 254 : CreateUserMappingStmt *n = makeNode(CreateUserMappingStmt);
5881 :
5882 254 : n->user = $5;
5883 254 : n->servername = $7;
5884 254 : n->options = $8;
5885 254 : n->if_not_exists = false;
5886 254 : $$ = (Node *) n;
5887 : }
5888 : | CREATE USER MAPPING IF_P NOT EXISTS FOR auth_ident SERVER name create_generic_options
5889 : {
5890 6 : CreateUserMappingStmt *n = makeNode(CreateUserMappingStmt);
5891 :
5892 6 : n->user = $8;
5893 6 : n->servername = $10;
5894 6 : n->options = $11;
5895 6 : n->if_not_exists = true;
5896 6 : $$ = (Node *) n;
5897 : }
5898 : ;
5899 :
5900 : /* User mapping authorization identifier */
5901 458 : auth_ident: RoleSpec { $$ = $1; }
5902 46 : | USER { $$ = makeRoleSpec(ROLESPEC_CURRENT_USER, @1); }
5903 : ;
5904 :
5905 : /*****************************************************************************
5906 : *
5907 : * QUERY :
5908 : * DROP USER MAPPING FOR auth_ident SERVER name
5909 : *
5910 : * XXX you'd think this should have a CASCADE/RESTRICT option, even if it's
5911 : * only pro forma; but the SQL standard doesn't show one.
5912 : ****************************************************************************/
5913 :
5914 : DropUserMappingStmt: DROP USER MAPPING FOR auth_ident SERVER name
5915 : {
5916 88 : DropUserMappingStmt *n = makeNode(DropUserMappingStmt);
5917 :
5918 88 : n->user = $5;
5919 88 : n->servername = $7;
5920 88 : n->missing_ok = false;
5921 88 : $$ = (Node *) n;
5922 : }
5923 : | DROP USER MAPPING IF_P EXISTS FOR auth_ident SERVER name
5924 : {
5925 38 : DropUserMappingStmt *n = makeNode(DropUserMappingStmt);
5926 :
5927 38 : n->user = $7;
5928 38 : n->servername = $9;
5929 38 : n->missing_ok = true;
5930 38 : $$ = (Node *) n;
5931 : }
5932 : ;
5933 :
5934 : /*****************************************************************************
5935 : *
5936 : * QUERY :
5937 : * ALTER USER MAPPING FOR auth_ident SERVER name OPTIONS
5938 : *
5939 : ****************************************************************************/
5940 :
5941 : AlterUserMappingStmt: ALTER USER MAPPING FOR auth_ident SERVER name alter_generic_options
5942 : {
5943 118 : AlterUserMappingStmt *n = makeNode(AlterUserMappingStmt);
5944 :
5945 118 : n->user = $5;
5946 118 : n->servername = $7;
5947 118 : n->options = $8;
5948 118 : $$ = (Node *) n;
5949 : }
5950 : ;
5951 :
5952 : /*****************************************************************************
5953 : *
5954 : * QUERIES:
5955 : * CREATE POLICY name ON table
5956 : * [AS { PERMISSIVE | RESTRICTIVE } ]
5957 : * [FOR { SELECT | INSERT | UPDATE | DELETE } ]
5958 : * [TO role, ...]
5959 : * [USING (qual)] [WITH CHECK (with check qual)]
5960 : * ALTER POLICY name ON table [TO role, ...]
5961 : * [USING (qual)] [WITH CHECK (with check qual)]
5962 : *
5963 : *****************************************************************************/
5964 :
5965 : CreatePolicyStmt:
5966 : CREATE POLICY name ON qualified_name RowSecurityDefaultPermissive
5967 : RowSecurityDefaultForCmd RowSecurityDefaultToRole
5968 : RowSecurityOptionalExpr RowSecurityOptionalWithCheck
5969 : {
5970 772 : CreatePolicyStmt *n = makeNode(CreatePolicyStmt);
5971 :
5972 772 : n->policy_name = $3;
5973 772 : n->table = $5;
5974 772 : n->permissive = $6;
5975 772 : n->cmd_name = $7;
5976 772 : n->roles = $8;
5977 772 : n->qual = $9;
5978 772 : n->with_check = $10;
5979 772 : $$ = (Node *) n;
5980 : }
5981 : ;
5982 :
5983 : AlterPolicyStmt:
5984 : ALTER POLICY name ON qualified_name RowSecurityOptionalToRole
5985 : RowSecurityOptionalExpr RowSecurityOptionalWithCheck
5986 : {
5987 84 : AlterPolicyStmt *n = makeNode(AlterPolicyStmt);
5988 :
5989 84 : n->policy_name = $3;
5990 84 : n->table = $5;
5991 84 : n->roles = $6;
5992 84 : n->qual = $7;
5993 84 : n->with_check = $8;
5994 84 : $$ = (Node *) n;
5995 : }
5996 : ;
5997 :
5998 : RowSecurityOptionalExpr:
5999 792 : USING '(' a_expr ')' { $$ = $3; }
6000 64 : | /* EMPTY */ { $$ = NULL; }
6001 : ;
6002 :
6003 : RowSecurityOptionalWithCheck:
6004 140 : WITH CHECK '(' a_expr ')' { $$ = $4; }
6005 716 : | /* EMPTY */ { $$ = NULL; }
6006 : ;
6007 :
6008 : RowSecurityDefaultToRole:
6009 130 : TO role_list { $$ = $2; }
6010 642 : | /* EMPTY */ { $$ = list_make1(makeRoleSpec(ROLESPEC_PUBLIC, -1)); }
6011 : ;
6012 :
6013 : RowSecurityOptionalToRole:
6014 12 : TO role_list { $$ = $2; }
6015 72 : | /* EMPTY */ { $$ = NULL; }
6016 : ;
6017 :
6018 : RowSecurityDefaultPermissive:
6019 : AS IDENT
6020 : {
6021 98 : if (strcmp($2, "permissive") == 0)
6022 24 : $$ = true;
6023 74 : else if (strcmp($2, "restrictive") == 0)
6024 68 : $$ = false;
6025 : else
6026 6 : ereport(ERROR,
6027 : (errcode(ERRCODE_SYNTAX_ERROR),
6028 : errmsg("unrecognized row security option \"%s\"", $2),
6029 : errhint("Only PERMISSIVE or RESTRICTIVE policies are supported currently."),
6030 : parser_errposition(@2)));
6031 :
6032 : }
6033 680 : | /* EMPTY */ { $$ = true; }
6034 : ;
6035 :
6036 : RowSecurityDefaultForCmd:
6037 356 : FOR row_security_cmd { $$ = $2; }
6038 416 : | /* EMPTY */ { $$ = "all"; }
6039 : ;
6040 :
6041 : row_security_cmd:
6042 44 : ALL { $$ = "all"; }
6043 124 : | SELECT { $$ = "select"; }
6044 50 : | INSERT { $$ = "insert"; }
6045 90 : | UPDATE { $$ = "update"; }
6046 48 : | DELETE_P { $$ = "delete"; }
6047 : ;
6048 :
6049 : /*****************************************************************************
6050 : *
6051 : * QUERY:
6052 : * CREATE ACCESS METHOD name HANDLER handler_name
6053 : *
6054 : *****************************************************************************/
6055 :
6056 : CreateAmStmt: CREATE ACCESS METHOD name TYPE_P am_type HANDLER handler_name
6057 : {
6058 62 : CreateAmStmt *n = makeNode(CreateAmStmt);
6059 :
6060 62 : n->amname = $4;
6061 62 : n->handler_name = $8;
6062 62 : n->amtype = $6;
6063 62 : $$ = (Node *) n;
6064 : }
6065 : ;
6066 :
6067 : am_type:
6068 34 : INDEX { $$ = AMTYPE_INDEX; }
6069 28 : | TABLE { $$ = AMTYPE_TABLE; }
6070 : ;
6071 :
6072 : /*****************************************************************************
6073 : *
6074 : * QUERIES :
6075 : * CREATE TRIGGER ...
6076 : *
6077 : *****************************************************************************/
6078 :
6079 : CreateTrigStmt:
6080 : CREATE opt_or_replace TRIGGER name TriggerActionTime TriggerEvents ON
6081 : qualified_name TriggerReferencing TriggerForSpec TriggerWhen
6082 : EXECUTE FUNCTION_or_PROCEDURE func_name '(' TriggerFuncArgs ')'
6083 : {
6084 3174 : CreateTrigStmt *n = makeNode(CreateTrigStmt);
6085 :
6086 3174 : n->replace = $2;
6087 3174 : n->isconstraint = false;
6088 3174 : n->trigname = $4;
6089 3174 : n->relation = $8;
6090 3174 : n->funcname = $14;
6091 3174 : n->args = $16;
6092 3174 : n->row = $10;
6093 3174 : n->timing = $5;
6094 3174 : n->events = intVal(linitial($6));
6095 3174 : n->columns = (List *) lsecond($6);
6096 3174 : n->whenClause = $11;
6097 3174 : n->transitionRels = $9;
6098 3174 : n->deferrable = false;
6099 3174 : n->initdeferred = false;
6100 3174 : n->constrrel = NULL;
6101 3174 : $$ = (Node *) n;
6102 : }
6103 : | CREATE opt_or_replace CONSTRAINT TRIGGER name AFTER TriggerEvents ON
6104 : qualified_name OptConstrFromTable ConstraintAttributeSpec
6105 : FOR EACH ROW TriggerWhen
6106 : EXECUTE FUNCTION_or_PROCEDURE func_name '(' TriggerFuncArgs ')'
6107 : {
6108 80 : CreateTrigStmt *n = makeNode(CreateTrigStmt);
6109 : bool dummy;
6110 :
6111 80 : if (($11 & CAS_NOT_VALID) != 0)
6112 6 : ereport(ERROR,
6113 : errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
6114 : errmsg("constraint triggers cannot be marked %s",
6115 : "NOT VALID"),
6116 : parser_errposition(@11));
6117 74 : if (($11 & CAS_NO_INHERIT) != 0)
6118 6 : ereport(ERROR,
6119 : errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
6120 : errmsg("constraint triggers cannot be marked %s",
6121 : "NO INHERIT"),
6122 : parser_errposition(@11));
6123 68 : if (($11 & CAS_NOT_ENFORCED) != 0)
6124 6 : ereport(ERROR,
6125 : errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
6126 : errmsg("constraint triggers cannot be marked %s",
6127 : "NOT ENFORCED"),
6128 : parser_errposition(@11));
6129 :
6130 62 : n->replace = $2;
6131 62 : if (n->replace) /* not supported, see CreateTrigger */
6132 0 : ereport(ERROR,
6133 : (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
6134 : errmsg("CREATE OR REPLACE CONSTRAINT TRIGGER is not supported"),
6135 : parser_errposition(@1)));
6136 62 : n->isconstraint = true;
6137 62 : n->trigname = $5;
6138 62 : n->relation = $9;
6139 62 : n->funcname = $18;
6140 62 : n->args = $20;
6141 62 : n->row = true;
6142 62 : n->timing = TRIGGER_TYPE_AFTER;
6143 62 : n->events = intVal(linitial($7));
6144 62 : n->columns = (List *) lsecond($7);
6145 62 : n->whenClause = $15;
6146 62 : n->transitionRels = NIL;
6147 62 : processCASbits($11, @11, "TRIGGER",
6148 : &n->deferrable, &n->initdeferred, &dummy,
6149 : NULL, NULL, yyscanner);
6150 62 : n->constrrel = $10;
6151 62 : $$ = (Node *) n;
6152 : }
6153 : ;
6154 :
6155 : TriggerActionTime:
6156 1442 : BEFORE { $$ = TRIGGER_TYPE_BEFORE; }
6157 1600 : | AFTER { $$ = TRIGGER_TYPE_AFTER; }
6158 144 : | INSTEAD OF { $$ = TRIGGER_TYPE_INSTEAD; }
6159 : ;
6160 :
6161 : TriggerEvents:
6162 : TriggerOneEvent
6163 3266 : { $$ = $1; }
6164 : | TriggerEvents OR TriggerOneEvent
6165 : {
6166 1162 : int events1 = intVal(linitial($1));
6167 1162 : int events2 = intVal(linitial($3));
6168 1162 : List *columns1 = (List *) lsecond($1);
6169 1162 : List *columns2 = (List *) lsecond($3);
6170 :
6171 1162 : if (events1 & events2)
6172 6 : parser_yyerror("duplicate trigger events specified");
6173 : /*
6174 : * concat'ing the columns lists loses information about
6175 : * which columns went with which event, but so long as
6176 : * only UPDATE carries columns and we disallow multiple
6177 : * UPDATE items, it doesn't matter. Command execution
6178 : * should just ignore the columns for non-UPDATE events.
6179 : */
6180 1156 : $$ = list_make2(makeInteger(events1 | events2),
6181 : list_concat(columns1, columns2));
6182 : }
6183 : ;
6184 :
6185 : TriggerOneEvent:
6186 : INSERT
6187 1680 : { $$ = list_make2(makeInteger(TRIGGER_TYPE_INSERT), NIL); }
6188 : | DELETE_P
6189 886 : { $$ = list_make2(makeInteger(TRIGGER_TYPE_DELETE), NIL); }
6190 : | UPDATE
6191 1724 : { $$ = list_make2(makeInteger(TRIGGER_TYPE_UPDATE), NIL); }
6192 : | UPDATE OF columnList
6193 100 : { $$ = list_make2(makeInteger(TRIGGER_TYPE_UPDATE), $3); }
6194 : | TRUNCATE
6195 38 : { $$ = list_make2(makeInteger(TRIGGER_TYPE_TRUNCATE), NIL); }
6196 : ;
6197 :
6198 : TriggerReferencing:
6199 464 : REFERENCING TriggerTransitions { $$ = $2; }
6200 2710 : | /*EMPTY*/ { $$ = NIL; }
6201 : ;
6202 :
6203 : TriggerTransitions:
6204 464 : TriggerTransition { $$ = list_make1($1); }
6205 142 : | TriggerTransitions TriggerTransition { $$ = lappend($1, $2); }
6206 : ;
6207 :
6208 : TriggerTransition:
6209 : TransitionOldOrNew TransitionRowOrTable opt_as TransitionRelName
6210 : {
6211 606 : TriggerTransition *n = makeNode(TriggerTransition);
6212 :
6213 606 : n->name = $4;
6214 606 : n->isNew = $1;
6215 606 : n->isTable = $2;
6216 606 : $$ = (Node *) n;
6217 : }
6218 : ;
6219 :
6220 : TransitionOldOrNew:
6221 330 : NEW { $$ = true; }
6222 276 : | OLD { $$ = false; }
6223 : ;
6224 :
6225 : TransitionRowOrTable:
6226 606 : TABLE { $$ = true; }
6227 : /*
6228 : * According to the standard, lack of a keyword here implies ROW.
6229 : * Support for that would require prohibiting ROW entirely here,
6230 : * reserving the keyword ROW, and/or requiring AS (instead of
6231 : * allowing it to be optional, as the standard specifies) as the
6232 : * next token. Requiring ROW seems cleanest and easiest to
6233 : * explain.
6234 : */
6235 0 : | ROW { $$ = false; }
6236 : ;
6237 :
6238 : TransitionRelName:
6239 606 : ColId { $$ = $1; }
6240 : ;
6241 :
6242 : TriggerForSpec:
6243 : FOR TriggerForOptEach TriggerForType
6244 : {
6245 2934 : $$ = $3;
6246 : }
6247 : | /* EMPTY */
6248 : {
6249 : /*
6250 : * If ROW/STATEMENT not specified, default to
6251 : * STATEMENT, per SQL
6252 : */
6253 240 : $$ = false;
6254 : }
6255 : ;
6256 :
6257 : TriggerForOptEach:
6258 : EACH
6259 : | /*EMPTY*/
6260 : ;
6261 :
6262 : TriggerForType:
6263 2114 : ROW { $$ = true; }
6264 820 : | STATEMENT { $$ = false; }
6265 : ;
6266 :
6267 : TriggerWhen:
6268 190 : WHEN '(' a_expr ')' { $$ = $3; }
6269 3064 : | /*EMPTY*/ { $$ = NULL; }
6270 : ;
6271 :
6272 : FUNCTION_or_PROCEDURE:
6273 : FUNCTION
6274 : | PROCEDURE
6275 : ;
6276 :
6277 : TriggerFuncArgs:
6278 546 : TriggerFuncArg { $$ = list_make1($1); }
6279 162 : | TriggerFuncArgs ',' TriggerFuncArg { $$ = lappend($1, $3); }
6280 2708 : | /*EMPTY*/ { $$ = NIL; }
6281 : ;
6282 :
6283 : TriggerFuncArg:
6284 : Iconst
6285 : {
6286 94 : $$ = (Node *) makeString(psprintf("%d", $1));
6287 : }
6288 0 : | FCONST { $$ = (Node *) makeString($1); }
6289 592 : | Sconst { $$ = (Node *) makeString($1); }
6290 22 : | ColLabel { $$ = (Node *) makeString($1); }
6291 : ;
6292 :
6293 : OptConstrFromTable:
6294 12 : FROM qualified_name { $$ = $2; }
6295 68 : | /*EMPTY*/ { $$ = NULL; }
6296 : ;
6297 :
6298 : ConstraintAttributeSpec:
6299 : /*EMPTY*/
6300 17920 : { $$ = 0; }
6301 : | ConstraintAttributeSpec ConstraintAttributeElem
6302 : {
6303 : /*
6304 : * We must complain about conflicting options.
6305 : * We could, but choose not to, complain about redundant
6306 : * options (ie, where $2's bit is already set in $1).
6307 : */
6308 1682 : int newspec = $1 | $2;
6309 :
6310 : /* special message for this case */
6311 1682 : if ((newspec & (CAS_NOT_DEFERRABLE | CAS_INITIALLY_DEFERRED)) == (CAS_NOT_DEFERRABLE | CAS_INITIALLY_DEFERRED))
6312 6 : ereport(ERROR,
6313 : (errcode(ERRCODE_SYNTAX_ERROR),
6314 : errmsg("constraint declared INITIALLY DEFERRED must be DEFERRABLE"),
6315 : parser_errposition(@2)));
6316 : /* generic message for other conflicts */
6317 1676 : if ((newspec & (CAS_NOT_DEFERRABLE | CAS_DEFERRABLE)) == (CAS_NOT_DEFERRABLE | CAS_DEFERRABLE) ||
6318 1676 : (newspec & (CAS_INITIALLY_IMMEDIATE | CAS_INITIALLY_DEFERRED)) == (CAS_INITIALLY_IMMEDIATE | CAS_INITIALLY_DEFERRED) ||
6319 1676 : (newspec & (CAS_NOT_ENFORCED | CAS_ENFORCED)) == (CAS_NOT_ENFORCED | CAS_ENFORCED))
6320 6 : ereport(ERROR,
6321 : (errcode(ERRCODE_SYNTAX_ERROR),
6322 : errmsg("conflicting constraint properties"),
6323 : parser_errposition(@2)));
6324 1670 : $$ = newspec;
6325 : }
6326 : ;
6327 :
6328 : ConstraintAttributeElem:
6329 42 : NOT DEFERRABLE { $$ = CAS_NOT_DEFERRABLE; }
6330 200 : | DEFERRABLE { $$ = CAS_DEFERRABLE; }
6331 30 : | INITIALLY IMMEDIATE { $$ = CAS_INITIALLY_IMMEDIATE; }
6332 152 : | INITIALLY DEFERRED { $$ = CAS_INITIALLY_DEFERRED; }
6333 732 : | NOT VALID { $$ = CAS_NOT_VALID; }
6334 250 : | NO INHERIT { $$ = CAS_NO_INHERIT; }
6335 168 : | NOT ENFORCED { $$ = CAS_NOT_ENFORCED; }
6336 108 : | ENFORCED { $$ = CAS_ENFORCED; }
6337 : ;
6338 :
6339 :
6340 : /*****************************************************************************
6341 : *
6342 : * QUERIES :
6343 : * CREATE EVENT TRIGGER ...
6344 : * ALTER EVENT TRIGGER ...
6345 : *
6346 : *****************************************************************************/
6347 :
6348 : CreateEventTrigStmt:
6349 : CREATE EVENT TRIGGER name ON ColLabel
6350 : EXECUTE FUNCTION_or_PROCEDURE func_name '(' ')'
6351 : {
6352 102 : CreateEventTrigStmt *n = makeNode(CreateEventTrigStmt);
6353 :
6354 102 : n->trigname = $4;
6355 102 : n->eventname = $6;
6356 102 : n->whenclause = NULL;
6357 102 : n->funcname = $9;
6358 102 : $$ = (Node *) n;
6359 : }
6360 : | CREATE EVENT TRIGGER name ON ColLabel
6361 : WHEN event_trigger_when_list
6362 : EXECUTE FUNCTION_or_PROCEDURE func_name '(' ')'
6363 : {
6364 98 : CreateEventTrigStmt *n = makeNode(CreateEventTrigStmt);
6365 :
6366 98 : n->trigname = $4;
6367 98 : n->eventname = $6;
6368 98 : n->whenclause = $8;
6369 98 : n->funcname = $11;
6370 98 : $$ = (Node *) n;
6371 : }
6372 : ;
6373 :
6374 : event_trigger_when_list:
6375 : event_trigger_when_item
6376 98 : { $$ = list_make1($1); }
6377 : | event_trigger_when_list AND event_trigger_when_item
6378 6 : { $$ = lappend($1, $3); }
6379 : ;
6380 :
6381 : event_trigger_when_item:
6382 : ColId IN_P '(' event_trigger_value_list ')'
6383 104 : { $$ = makeDefElem($1, (Node *) $4, @1); }
6384 : ;
6385 :
6386 : event_trigger_value_list:
6387 : SCONST
6388 104 : { $$ = list_make1(makeString($1)); }
6389 : | event_trigger_value_list ',' SCONST
6390 66 : { $$ = lappend($1, makeString($3)); }
6391 : ;
6392 :
6393 : AlterEventTrigStmt:
6394 : ALTER EVENT TRIGGER name enable_trigger
6395 : {
6396 48 : AlterEventTrigStmt *n = makeNode(AlterEventTrigStmt);
6397 :
6398 48 : n->trigname = $4;
6399 48 : n->tgenabled = $5;
6400 48 : $$ = (Node *) n;
6401 : }
6402 : ;
6403 :
6404 : enable_trigger:
6405 6 : ENABLE_P { $$ = TRIGGER_FIRES_ON_ORIGIN; }
6406 6 : | ENABLE_P REPLICA { $$ = TRIGGER_FIRES_ON_REPLICA; }
6407 16 : | ENABLE_P ALWAYS { $$ = TRIGGER_FIRES_ALWAYS; }
6408 20 : | DISABLE_P { $$ = TRIGGER_DISABLED; }
6409 : ;
6410 :
6411 : /*****************************************************************************
6412 : *
6413 : * QUERY :
6414 : * CREATE ASSERTION ...
6415 : *
6416 : *****************************************************************************/
6417 :
6418 : CreateAssertionStmt:
6419 : CREATE ASSERTION any_name CHECK '(' a_expr ')' ConstraintAttributeSpec
6420 : {
6421 0 : ereport(ERROR,
6422 : (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
6423 : errmsg("CREATE ASSERTION is not yet implemented"),
6424 : parser_errposition(@1)));
6425 :
6426 : $$ = NULL;
6427 : }
6428 : ;
6429 :
6430 :
6431 : /*****************************************************************************
6432 : *
6433 : * QUERY :
6434 : * define (aggregate,operator,type)
6435 : *
6436 : *****************************************************************************/
6437 :
6438 : DefineStmt:
6439 : CREATE opt_or_replace AGGREGATE func_name aggr_args definition
6440 : {
6441 544 : DefineStmt *n = makeNode(DefineStmt);
6442 :
6443 544 : n->kind = OBJECT_AGGREGATE;
6444 544 : n->oldstyle = false;
6445 544 : n->replace = $2;
6446 544 : n->defnames = $4;
6447 544 : n->args = $5;
6448 544 : n->definition = $6;
6449 544 : $$ = (Node *) n;
6450 : }
6451 : | CREATE opt_or_replace AGGREGATE func_name old_aggr_definition
6452 : {
6453 : /* old-style (pre-8.2) syntax for CREATE AGGREGATE */
6454 362 : DefineStmt *n = makeNode(DefineStmt);
6455 :
6456 362 : n->kind = OBJECT_AGGREGATE;
6457 362 : n->oldstyle = true;
6458 362 : n->replace = $2;
6459 362 : n->defnames = $4;
6460 362 : n->args = NIL;
6461 362 : n->definition = $5;
6462 362 : $$ = (Node *) n;
6463 : }
6464 : | CREATE OPERATOR any_operator definition
6465 : {
6466 1642 : DefineStmt *n = makeNode(DefineStmt);
6467 :
6468 1642 : n->kind = OBJECT_OPERATOR;
6469 1642 : n->oldstyle = false;
6470 1642 : n->defnames = $3;
6471 1642 : n->args = NIL;
6472 1642 : n->definition = $4;
6473 1642 : $$ = (Node *) n;
6474 : }
6475 : | CREATE TYPE_P any_name definition
6476 : {
6477 240 : DefineStmt *n = makeNode(DefineStmt);
6478 :
6479 240 : n->kind = OBJECT_TYPE;
6480 240 : n->oldstyle = false;
6481 240 : n->defnames = $3;
6482 240 : n->args = NIL;
6483 240 : n->definition = $4;
6484 240 : $$ = (Node *) n;
6485 : }
6486 : | CREATE TYPE_P any_name
6487 : {
6488 : /* Shell type (identified by lack of definition) */
6489 156 : DefineStmt *n = makeNode(DefineStmt);
6490 :
6491 156 : n->kind = OBJECT_TYPE;
6492 156 : n->oldstyle = false;
6493 156 : n->defnames = $3;
6494 156 : n->args = NIL;
6495 156 : n->definition = NIL;
6496 156 : $$ = (Node *) n;
6497 : }
6498 : | CREATE TYPE_P any_name AS '(' OptTableFuncElementList ')'
6499 : {
6500 4502 : CompositeTypeStmt *n = makeNode(CompositeTypeStmt);
6501 :
6502 : /* can't use qualified_name, sigh */
6503 4502 : n->typevar = makeRangeVarFromAnyName($3, @3, yyscanner);
6504 4502 : n->coldeflist = $6;
6505 4502 : $$ = (Node *) n;
6506 : }
6507 : | CREATE TYPE_P any_name AS ENUM_P '(' opt_enum_val_list ')'
6508 : {
6509 208 : CreateEnumStmt *n = makeNode(CreateEnumStmt);
6510 :
6511 208 : n->typeName = $3;
6512 208 : n->vals = $7;
6513 208 : $$ = (Node *) n;
6514 : }
6515 : | CREATE TYPE_P any_name AS RANGE definition
6516 : {
6517 184 : CreateRangeStmt *n = makeNode(CreateRangeStmt);
6518 :
6519 184 : n->typeName = $3;
6520 184 : n->params = $6;
6521 184 : $$ = (Node *) n;
6522 : }
6523 : | CREATE TEXT_P SEARCH PARSER any_name definition
6524 : {
6525 40 : DefineStmt *n = makeNode(DefineStmt);
6526 :
6527 40 : n->kind = OBJECT_TSPARSER;
6528 40 : n->args = NIL;
6529 40 : n->defnames = $5;
6530 40 : n->definition = $6;
6531 40 : $$ = (Node *) n;
6532 : }
6533 : | CREATE TEXT_P SEARCH DICTIONARY any_name definition
6534 : {
6535 2930 : DefineStmt *n = makeNode(DefineStmt);
6536 :
6537 2930 : n->kind = OBJECT_TSDICTIONARY;
6538 2930 : n->args = NIL;
6539 2930 : n->defnames = $5;
6540 2930 : n->definition = $6;
6541 2930 : $$ = (Node *) n;
6542 : }
6543 : | CREATE TEXT_P SEARCH TEMPLATE any_name definition
6544 : {
6545 140 : DefineStmt *n = makeNode(DefineStmt);
6546 :
6547 140 : n->kind = OBJECT_TSTEMPLATE;
6548 140 : n->args = NIL;
6549 140 : n->defnames = $5;
6550 140 : n->definition = $6;
6551 140 : $$ = (Node *) n;
6552 : }
6553 : | CREATE TEXT_P SEARCH CONFIGURATION any_name definition
6554 : {
6555 2872 : DefineStmt *n = makeNode(DefineStmt);
6556 :
6557 2872 : n->kind = OBJECT_TSCONFIGURATION;
6558 2872 : n->args = NIL;
6559 2872 : n->defnames = $5;
6560 2872 : n->definition = $6;
6561 2872 : $$ = (Node *) n;
6562 : }
6563 : | CREATE COLLATION any_name definition
6564 : {
6565 292 : DefineStmt *n = makeNode(DefineStmt);
6566 :
6567 292 : n->kind = OBJECT_COLLATION;
6568 292 : n->args = NIL;
6569 292 : n->defnames = $3;
6570 292 : n->definition = $4;
6571 292 : $$ = (Node *) n;
6572 : }
6573 : | CREATE COLLATION IF_P NOT EXISTS any_name definition
6574 : {
6575 18 : DefineStmt *n = makeNode(DefineStmt);
6576 :
6577 18 : n->kind = OBJECT_COLLATION;
6578 18 : n->args = NIL;
6579 18 : n->defnames = $6;
6580 18 : n->definition = $7;
6581 18 : n->if_not_exists = true;
6582 18 : $$ = (Node *) n;
6583 : }
6584 : | CREATE COLLATION any_name FROM any_name
6585 : {
6586 54 : DefineStmt *n = makeNode(DefineStmt);
6587 :
6588 54 : n->kind = OBJECT_COLLATION;
6589 54 : n->args = NIL;
6590 54 : n->defnames = $3;
6591 54 : n->definition = list_make1(makeDefElem("from", (Node *) $5, @5));
6592 54 : $$ = (Node *) n;
6593 : }
6594 : | CREATE COLLATION IF_P NOT EXISTS any_name FROM any_name
6595 : {
6596 0 : DefineStmt *n = makeNode(DefineStmt);
6597 :
6598 0 : n->kind = OBJECT_COLLATION;
6599 0 : n->args = NIL;
6600 0 : n->defnames = $6;
6601 0 : n->definition = list_make1(makeDefElem("from", (Node *) $8, @8));
6602 0 : n->if_not_exists = true;
6603 0 : $$ = (Node *) n;
6604 : }
6605 : ;
6606 :
6607 9972 : definition: '(' def_list ')' { $$ = $2; }
6608 : ;
6609 :
6610 9972 : def_list: def_elem { $$ = list_make1($1); }
6611 14814 : | def_list ',' def_elem { $$ = lappend($1, $3); }
6612 : ;
6613 :
6614 : def_elem: ColLabel '=' def_arg
6615 : {
6616 24448 : $$ = makeDefElem($1, (Node *) $3, @1);
6617 : }
6618 : | ColLabel
6619 : {
6620 338 : $$ = makeDefElem($1, NULL, @1);
6621 : }
6622 : ;
6623 :
6624 : /* Note: any simple identifier will be returned as a type name! */
6625 19732 : def_arg: func_type { $$ = (Node *) $1; }
6626 4222 : | reserved_keyword { $$ = (Node *) makeString(pstrdup($1)); }
6627 1176 : | qual_all_Op { $$ = (Node *) $1; }
6628 1366 : | NumericOnly { $$ = (Node *) $1; }
6629 1906 : | Sconst { $$ = (Node *) makeString($1); }
6630 182 : | NONE { $$ = (Node *) makeString(pstrdup($1)); }
6631 : ;
6632 :
6633 362 : old_aggr_definition: '(' old_aggr_list ')' { $$ = $2; }
6634 : ;
6635 :
6636 362 : old_aggr_list: old_aggr_elem { $$ = list_make1($1); }
6637 1292 : | old_aggr_list ',' old_aggr_elem { $$ = lappend($1, $3); }
6638 : ;
6639 :
6640 : /*
6641 : * Must use IDENT here to avoid reduce/reduce conflicts; fortunately none of
6642 : * the item names needed in old aggregate definitions are likely to become
6643 : * SQL keywords.
6644 : */
6645 : old_aggr_elem: IDENT '=' def_arg
6646 : {
6647 1654 : $$ = makeDefElem($1, (Node *) $3, @1);
6648 : }
6649 : ;
6650 :
6651 : opt_enum_val_list:
6652 200 : enum_val_list { $$ = $1; }
6653 8 : | /*EMPTY*/ { $$ = NIL; }
6654 : ;
6655 :
6656 : enum_val_list: Sconst
6657 200 : { $$ = list_make1(makeString($1)); }
6658 : | enum_val_list ',' Sconst
6659 10420 : { $$ = lappend($1, makeString($3)); }
6660 : ;
6661 :
6662 : /*****************************************************************************
6663 : *
6664 : * ALTER TYPE enumtype ADD ...
6665 : *
6666 : *****************************************************************************/
6667 :
6668 : AlterEnumStmt:
6669 : ALTER TYPE_P any_name ADD_P VALUE_P opt_if_not_exists Sconst
6670 : {
6671 154 : AlterEnumStmt *n = makeNode(AlterEnumStmt);
6672 :
6673 154 : n->typeName = $3;
6674 154 : n->oldVal = NULL;
6675 154 : n->newVal = $7;
6676 154 : n->newValNeighbor = NULL;
6677 154 : n->newValIsAfter = true;
6678 154 : n->skipIfNewValExists = $6;
6679 154 : $$ = (Node *) n;
6680 : }
6681 : | ALTER TYPE_P any_name ADD_P VALUE_P opt_if_not_exists Sconst BEFORE Sconst
6682 : {
6683 196 : AlterEnumStmt *n = makeNode(AlterEnumStmt);
6684 :
6685 196 : n->typeName = $3;
6686 196 : n->oldVal = NULL;
6687 196 : n->newVal = $7;
6688 196 : n->newValNeighbor = $9;
6689 196 : n->newValIsAfter = false;
6690 196 : n->skipIfNewValExists = $6;
6691 196 : $$ = (Node *) n;
6692 : }
6693 : | ALTER TYPE_P any_name ADD_P VALUE_P opt_if_not_exists Sconst AFTER Sconst
6694 : {
6695 22 : AlterEnumStmt *n = makeNode(AlterEnumStmt);
6696 :
6697 22 : n->typeName = $3;
6698 22 : n->oldVal = NULL;
6699 22 : n->newVal = $7;
6700 22 : n->newValNeighbor = $9;
6701 22 : n->newValIsAfter = true;
6702 22 : n->skipIfNewValExists = $6;
6703 22 : $$ = (Node *) n;
6704 : }
6705 : | ALTER TYPE_P any_name RENAME VALUE_P Sconst TO Sconst
6706 : {
6707 24 : AlterEnumStmt *n = makeNode(AlterEnumStmt);
6708 :
6709 24 : n->typeName = $3;
6710 24 : n->oldVal = $6;
6711 24 : n->newVal = $8;
6712 24 : n->newValNeighbor = NULL;
6713 24 : n->newValIsAfter = false;
6714 24 : n->skipIfNewValExists = false;
6715 24 : $$ = (Node *) n;
6716 : }
6717 : | ALTER TYPE_P any_name DROP VALUE_P Sconst
6718 : {
6719 : /*
6720 : * The following problems must be solved before this can be
6721 : * implemented:
6722 : *
6723 : * - There must be no instance of the target value in
6724 : * any table.
6725 : *
6726 : * - The value must not appear in any catalog metadata,
6727 : * such as stored view expressions or column defaults.
6728 : *
6729 : * - The value must not appear in any non-leaf page of a
6730 : * btree (and similar issues with other index types).
6731 : * This is problematic because a value could persist
6732 : * there long after it's gone from user-visible data.
6733 : *
6734 : * - Concurrent sessions must not be able to insert the
6735 : * value while the preceding conditions are being checked.
6736 : *
6737 : * - Possibly more...
6738 : */
6739 0 : ereport(ERROR,
6740 : (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
6741 : errmsg("dropping an enum value is not implemented"),
6742 : parser_errposition(@4)));
6743 : }
6744 : ;
6745 :
6746 12 : opt_if_not_exists: IF_P NOT EXISTS { $$ = true; }
6747 360 : | /* EMPTY */ { $$ = false; }
6748 : ;
6749 :
6750 :
6751 : /*****************************************************************************
6752 : *
6753 : * QUERIES :
6754 : * CREATE OPERATOR CLASS ...
6755 : * CREATE OPERATOR FAMILY ...
6756 : * ALTER OPERATOR FAMILY ...
6757 : * DROP OPERATOR CLASS ...
6758 : * DROP OPERATOR FAMILY ...
6759 : *
6760 : *****************************************************************************/
6761 :
6762 : CreateOpClassStmt:
6763 : CREATE OPERATOR CLASS any_name opt_default FOR TYPE_P Typename
6764 : USING name opt_opfamily AS opclass_item_list
6765 : {
6766 556 : CreateOpClassStmt *n = makeNode(CreateOpClassStmt);
6767 :
6768 556 : n->opclassname = $4;
6769 556 : n->isDefault = $5;
6770 556 : n->datatype = $8;
6771 556 : n->amname = $10;
6772 556 : n->opfamilyname = $11;
6773 556 : n->items = $13;
6774 556 : $$ = (Node *) n;
6775 : }
6776 : ;
6777 :
6778 : opclass_item_list:
6779 1412 : opclass_item { $$ = list_make1($1); }
6780 5388 : | opclass_item_list ',' opclass_item { $$ = lappend($1, $3); }
6781 : ;
6782 :
6783 : opclass_item:
6784 : OPERATOR Iconst any_operator opclass_purpose
6785 : {
6786 1866 : CreateOpClassItem *n = makeNode(CreateOpClassItem);
6787 1866 : ObjectWithArgs *owa = makeNode(ObjectWithArgs);
6788 :
6789 1866 : owa->objname = $3;
6790 1866 : owa->objargs = NIL;
6791 1866 : n->itemtype = OPCLASS_ITEM_OPERATOR;
6792 1866 : n->name = owa;
6793 1866 : n->number = $2;
6794 1866 : n->order_family = $4;
6795 1866 : $$ = (Node *) n;
6796 : }
6797 : | OPERATOR Iconst operator_with_argtypes opclass_purpose
6798 : {
6799 1570 : CreateOpClassItem *n = makeNode(CreateOpClassItem);
6800 :
6801 1570 : n->itemtype = OPCLASS_ITEM_OPERATOR;
6802 1570 : n->name = $3;
6803 1570 : n->number = $2;
6804 1570 : n->order_family = $4;
6805 1570 : $$ = (Node *) n;
6806 : }
6807 : | FUNCTION Iconst function_with_argtypes
6808 : {
6809 2414 : CreateOpClassItem *n = makeNode(CreateOpClassItem);
6810 :
6811 2414 : n->itemtype = OPCLASS_ITEM_FUNCTION;
6812 2414 : n->name = $3;
6813 2414 : n->number = $2;
6814 2414 : $$ = (Node *) n;
6815 : }
6816 : | FUNCTION Iconst '(' type_list ')' function_with_argtypes
6817 : {
6818 590 : CreateOpClassItem *n = makeNode(CreateOpClassItem);
6819 :
6820 590 : n->itemtype = OPCLASS_ITEM_FUNCTION;
6821 590 : n->name = $6;
6822 590 : n->number = $2;
6823 590 : n->class_args = $4;
6824 590 : $$ = (Node *) n;
6825 : }
6826 : | STORAGE Typename
6827 : {
6828 360 : CreateOpClassItem *n = makeNode(CreateOpClassItem);
6829 :
6830 360 : n->itemtype = OPCLASS_ITEM_STORAGETYPE;
6831 360 : n->storedtype = $2;
6832 360 : $$ = (Node *) n;
6833 : }
6834 : ;
6835 :
6836 452 : opt_default: DEFAULT { $$ = true; }
6837 168 : | /*EMPTY*/ { $$ = false; }
6838 : ;
6839 :
6840 44 : opt_opfamily: FAMILY any_name { $$ = $2; }
6841 512 : | /*EMPTY*/ { $$ = NIL; }
6842 : ;
6843 :
6844 0 : opclass_purpose: FOR SEARCH { $$ = NIL; }
6845 120 : | FOR ORDER BY any_name { $$ = $4; }
6846 3316 : | /*EMPTY*/ { $$ = NIL; }
6847 : ;
6848 :
6849 :
6850 : CreateOpFamilyStmt:
6851 : CREATE OPERATOR FAMILY any_name USING name
6852 : {
6853 148 : CreateOpFamilyStmt *n = makeNode(CreateOpFamilyStmt);
6854 :
6855 148 : n->opfamilyname = $4;
6856 148 : n->amname = $6;
6857 148 : $$ = (Node *) n;
6858 : }
6859 : ;
6860 :
6861 : AlterOpFamilyStmt:
6862 : ALTER OPERATOR FAMILY any_name USING name ADD_P opclass_item_list
6863 : {
6864 856 : AlterOpFamilyStmt *n = makeNode(AlterOpFamilyStmt);
6865 :
6866 856 : n->opfamilyname = $4;
6867 856 : n->amname = $6;
6868 856 : n->isDrop = false;
6869 856 : n->items = $8;
6870 856 : $$ = (Node *) n;
6871 : }
6872 : | ALTER OPERATOR FAMILY any_name USING name DROP opclass_drop_list
6873 : {
6874 64 : AlterOpFamilyStmt *n = makeNode(AlterOpFamilyStmt);
6875 :
6876 64 : n->opfamilyname = $4;
6877 64 : n->amname = $6;
6878 64 : n->isDrop = true;
6879 64 : n->items = $8;
6880 64 : $$ = (Node *) n;
6881 : }
6882 : ;
6883 :
6884 : opclass_drop_list:
6885 64 : opclass_drop { $$ = list_make1($1); }
6886 30 : | opclass_drop_list ',' opclass_drop { $$ = lappend($1, $3); }
6887 : ;
6888 :
6889 : opclass_drop:
6890 : OPERATOR Iconst '(' type_list ')'
6891 : {
6892 56 : CreateOpClassItem *n = makeNode(CreateOpClassItem);
6893 :
6894 56 : n->itemtype = OPCLASS_ITEM_OPERATOR;
6895 56 : n->number = $2;
6896 56 : n->class_args = $4;
6897 56 : $$ = (Node *) n;
6898 : }
6899 : | FUNCTION Iconst '(' type_list ')'
6900 : {
6901 38 : CreateOpClassItem *n = makeNode(CreateOpClassItem);
6902 :
6903 38 : n->itemtype = OPCLASS_ITEM_FUNCTION;
6904 38 : n->number = $2;
6905 38 : n->class_args = $4;
6906 38 : $$ = (Node *) n;
6907 : }
6908 : ;
6909 :
6910 :
6911 : DropOpClassStmt:
6912 : DROP OPERATOR CLASS any_name USING name opt_drop_behavior
6913 : {
6914 38 : DropStmt *n = makeNode(DropStmt);
6915 :
6916 38 : n->objects = list_make1(lcons(makeString($6), $4));
6917 38 : n->removeType = OBJECT_OPCLASS;
6918 38 : n->behavior = $7;
6919 38 : n->missing_ok = false;
6920 38 : n->concurrent = false;
6921 38 : $$ = (Node *) n;
6922 : }
6923 : | DROP OPERATOR CLASS IF_P EXISTS any_name USING name opt_drop_behavior
6924 : {
6925 18 : DropStmt *n = makeNode(DropStmt);
6926 :
6927 18 : n->objects = list_make1(lcons(makeString($8), $6));
6928 18 : n->removeType = OBJECT_OPCLASS;
6929 18 : n->behavior = $9;
6930 18 : n->missing_ok = true;
6931 18 : n->concurrent = false;
6932 18 : $$ = (Node *) n;
6933 : }
6934 : ;
6935 :
6936 : DropOpFamilyStmt:
6937 : DROP OPERATOR FAMILY any_name USING name opt_drop_behavior
6938 : {
6939 110 : DropStmt *n = makeNode(DropStmt);
6940 :
6941 110 : n->objects = list_make1(lcons(makeString($6), $4));
6942 110 : n->removeType = OBJECT_OPFAMILY;
6943 110 : n->behavior = $7;
6944 110 : n->missing_ok = false;
6945 110 : n->concurrent = false;
6946 110 : $$ = (Node *) n;
6947 : }
6948 : | DROP OPERATOR FAMILY IF_P EXISTS any_name USING name opt_drop_behavior
6949 : {
6950 18 : DropStmt *n = makeNode(DropStmt);
6951 :
6952 18 : n->objects = list_make1(lcons(makeString($8), $6));
6953 18 : n->removeType = OBJECT_OPFAMILY;
6954 18 : n->behavior = $9;
6955 18 : n->missing_ok = true;
6956 18 : n->concurrent = false;
6957 18 : $$ = (Node *) n;
6958 : }
6959 : ;
6960 :
6961 :
6962 : /*****************************************************************************
6963 : *
6964 : * QUERY:
6965 : *
6966 : * DROP OWNED BY username [, username ...] [ RESTRICT | CASCADE ]
6967 : * REASSIGN OWNED BY username [, username ...] TO username
6968 : *
6969 : *****************************************************************************/
6970 : DropOwnedStmt:
6971 : DROP OWNED BY role_list opt_drop_behavior
6972 : {
6973 146 : DropOwnedStmt *n = makeNode(DropOwnedStmt);
6974 :
6975 146 : n->roles = $4;
6976 146 : n->behavior = $5;
6977 146 : $$ = (Node *) n;
6978 : }
6979 : ;
6980 :
6981 : ReassignOwnedStmt:
6982 : REASSIGN OWNED BY role_list TO RoleSpec
6983 : {
6984 46 : ReassignOwnedStmt *n = makeNode(ReassignOwnedStmt);
6985 :
6986 46 : n->roles = $4;
6987 46 : n->newrole = $6;
6988 46 : $$ = (Node *) n;
6989 : }
6990 : ;
6991 :
6992 : /*****************************************************************************
6993 : *
6994 : * QUERY:
6995 : *
6996 : * DROP itemtype [ IF EXISTS ] itemname [, itemname ...]
6997 : * [ RESTRICT | CASCADE ]
6998 : *
6999 : *****************************************************************************/
7000 :
7001 : DropStmt: DROP object_type_any_name IF_P EXISTS any_name_list opt_drop_behavior
7002 : {
7003 1352 : DropStmt *n = makeNode(DropStmt);
7004 :
7005 1352 : n->removeType = $2;
7006 1352 : n->missing_ok = true;
7007 1352 : n->objects = $5;
7008 1352 : n->behavior = $6;
7009 1352 : n->concurrent = false;
7010 1352 : $$ = (Node *) n;
7011 : }
7012 : | DROP object_type_any_name any_name_list opt_drop_behavior
7013 : {
7014 16542 : DropStmt *n = makeNode(DropStmt);
7015 :
7016 16542 : n->removeType = $2;
7017 16542 : n->missing_ok = false;
7018 16542 : n->objects = $3;
7019 16542 : n->behavior = $4;
7020 16542 : n->concurrent = false;
7021 16542 : $$ = (Node *) n;
7022 : }
7023 : | DROP drop_type_name IF_P EXISTS name_list opt_drop_behavior
7024 : {
7025 86 : DropStmt *n = makeNode(DropStmt);
7026 :
7027 86 : n->removeType = $2;
7028 86 : n->missing_ok = true;
7029 86 : n->objects = $5;
7030 86 : n->behavior = $6;
7031 86 : n->concurrent = false;
7032 86 : $$ = (Node *) n;
7033 : }
7034 : | DROP drop_type_name name_list opt_drop_behavior
7035 : {
7036 1528 : DropStmt *n = makeNode(DropStmt);
7037 :
7038 1528 : n->removeType = $2;
7039 1528 : n->missing_ok = false;
7040 1528 : n->objects = $3;
7041 1528 : n->behavior = $4;
7042 1528 : n->concurrent = false;
7043 1528 : $$ = (Node *) n;
7044 : }
7045 : | DROP object_type_name_on_any_name name ON any_name opt_drop_behavior
7046 : {
7047 1130 : DropStmt *n = makeNode(DropStmt);
7048 :
7049 1130 : n->removeType = $2;
7050 1130 : n->objects = list_make1(lappend($5, makeString($3)));
7051 1130 : n->behavior = $6;
7052 1130 : n->missing_ok = false;
7053 1130 : n->concurrent = false;
7054 1130 : $$ = (Node *) n;
7055 : }
7056 : | DROP object_type_name_on_any_name IF_P EXISTS name ON any_name opt_drop_behavior
7057 : {
7058 48 : DropStmt *n = makeNode(DropStmt);
7059 :
7060 48 : n->removeType = $2;
7061 48 : n->objects = list_make1(lappend($7, makeString($5)));
7062 48 : n->behavior = $8;
7063 48 : n->missing_ok = true;
7064 48 : n->concurrent = false;
7065 48 : $$ = (Node *) n;
7066 : }
7067 : | DROP TYPE_P type_name_list opt_drop_behavior
7068 : {
7069 560 : DropStmt *n = makeNode(DropStmt);
7070 :
7071 560 : n->removeType = OBJECT_TYPE;
7072 560 : n->missing_ok = false;
7073 560 : n->objects = $3;
7074 560 : n->behavior = $4;
7075 560 : n->concurrent = false;
7076 560 : $$ = (Node *) n;
7077 : }
7078 : | DROP TYPE_P IF_P EXISTS type_name_list opt_drop_behavior
7079 : {
7080 26 : DropStmt *n = makeNode(DropStmt);
7081 :
7082 26 : n->removeType = OBJECT_TYPE;
7083 26 : n->missing_ok = true;
7084 26 : n->objects = $5;
7085 26 : n->behavior = $6;
7086 26 : n->concurrent = false;
7087 26 : $$ = (Node *) n;
7088 : }
7089 : | DROP DOMAIN_P type_name_list opt_drop_behavior
7090 : {
7091 470 : DropStmt *n = makeNode(DropStmt);
7092 :
7093 470 : n->removeType = OBJECT_DOMAIN;
7094 470 : n->missing_ok = false;
7095 470 : n->objects = $3;
7096 470 : n->behavior = $4;
7097 470 : n->concurrent = false;
7098 470 : $$ = (Node *) n;
7099 : }
7100 : | DROP DOMAIN_P IF_P EXISTS type_name_list opt_drop_behavior
7101 : {
7102 18 : DropStmt *n = makeNode(DropStmt);
7103 :
7104 18 : n->removeType = OBJECT_DOMAIN;
7105 18 : n->missing_ok = true;
7106 18 : n->objects = $5;
7107 18 : n->behavior = $6;
7108 18 : n->concurrent = false;
7109 18 : $$ = (Node *) n;
7110 : }
7111 : | DROP INDEX CONCURRENTLY any_name_list opt_drop_behavior
7112 : {
7113 124 : DropStmt *n = makeNode(DropStmt);
7114 :
7115 124 : n->removeType = OBJECT_INDEX;
7116 124 : n->missing_ok = false;
7117 124 : n->objects = $4;
7118 124 : n->behavior = $5;
7119 124 : n->concurrent = true;
7120 124 : $$ = (Node *) n;
7121 : }
7122 : | DROP INDEX CONCURRENTLY IF_P EXISTS any_name_list opt_drop_behavior
7123 : {
7124 12 : DropStmt *n = makeNode(DropStmt);
7125 :
7126 12 : n->removeType = OBJECT_INDEX;
7127 12 : n->missing_ok = true;
7128 12 : n->objects = $6;
7129 12 : n->behavior = $7;
7130 12 : n->concurrent = true;
7131 12 : $$ = (Node *) n;
7132 : }
7133 : ;
7134 :
7135 : /* object types taking any_name/any_name_list */
7136 : object_type_any_name:
7137 15462 : TABLE { $$ = OBJECT_TABLE; }
7138 200 : | SEQUENCE { $$ = OBJECT_SEQUENCE; }
7139 1048 : | VIEW { $$ = OBJECT_VIEW; }
7140 130 : | MATERIALIZED VIEW { $$ = OBJECT_MATVIEW; }
7141 778 : | INDEX { $$ = OBJECT_INDEX; }
7142 186 : | FOREIGN TABLE { $$ = OBJECT_FOREIGN_TABLE; }
7143 96 : | COLLATION { $$ = OBJECT_COLLATION; }
7144 56 : | CONVERSION_P { $$ = OBJECT_CONVERSION; }
7145 222 : | STATISTICS { $$ = OBJECT_STATISTIC_EXT; }
7146 20 : | TEXT_P SEARCH PARSER { $$ = OBJECT_TSPARSER; }
7147 2814 : | TEXT_P SEARCH DICTIONARY { $$ = OBJECT_TSDICTIONARY; }
7148 116 : | TEXT_P SEARCH TEMPLATE { $$ = OBJECT_TSTEMPLATE; }
7149 2818 : | TEXT_P SEARCH CONFIGURATION { $$ = OBJECT_TSCONFIGURATION; }
7150 : ;
7151 :
7152 : /*
7153 : * object types taking name/name_list
7154 : *
7155 : * DROP handles some of them separately
7156 : */
7157 :
7158 : object_type_name:
7159 250 : drop_type_name { $$ = $1; }
7160 238 : | DATABASE { $$ = OBJECT_DATABASE; }
7161 52 : | ROLE { $$ = OBJECT_ROLE; }
7162 10 : | SUBSCRIPTION { $$ = OBJECT_SUBSCRIPTION; }
7163 0 : | TABLESPACE { $$ = OBJECT_TABLESPACE; }
7164 : ;
7165 :
7166 : drop_type_name:
7167 46 : ACCESS METHOD { $$ = OBJECT_ACCESS_METHOD; }
7168 130 : | EVENT TRIGGER { $$ = OBJECT_EVENT_TRIGGER; }
7169 198 : | EXTENSION { $$ = OBJECT_EXTENSION; }
7170 154 : | FOREIGN DATA_P WRAPPER { $$ = OBJECT_FDW; }
7171 154 : | opt_procedural LANGUAGE { $$ = OBJECT_LANGUAGE; }
7172 420 : | PUBLICATION { $$ = OBJECT_PUBLICATION; }
7173 624 : | SCHEMA { $$ = OBJECT_SCHEMA; }
7174 138 : | SERVER { $$ = OBJECT_FOREIGN_SERVER; }
7175 : ;
7176 :
7177 : /* object types attached to a table */
7178 : object_type_name_on_any_name:
7179 166 : POLICY { $$ = OBJECT_POLICY; }
7180 268 : | RULE { $$ = OBJECT_RULE; }
7181 798 : | TRIGGER { $$ = OBJECT_TRIGGER; }
7182 : ;
7183 :
7184 : any_name_list:
7185 26712 : any_name { $$ = list_make1($1); }
7186 4270 : | any_name_list ',' any_name { $$ = lappend($1, $3); }
7187 : ;
7188 :
7189 67886 : any_name: ColId { $$ = list_make1(makeString($1)); }
7190 9060 : | ColId attrs { $$ = lcons(makeString($1), $2); }
7191 : ;
7192 :
7193 : attrs: '.' attr_name
7194 125326 : { $$ = list_make1(makeString($2)); }
7195 : | attrs '.' attr_name
7196 64 : { $$ = lappend($1, makeString($3)); }
7197 : ;
7198 :
7199 : type_name_list:
7200 1074 : Typename { $$ = list_make1($1); }
7201 102 : | type_name_list ',' Typename { $$ = lappend($1, $3); }
7202 : ;
7203 :
7204 : /*****************************************************************************
7205 : *
7206 : * QUERY:
7207 : * truncate table relname1, relname2, ...
7208 : *
7209 : *****************************************************************************/
7210 :
7211 : TruncateStmt:
7212 : TRUNCATE opt_table relation_expr_list opt_restart_seqs opt_drop_behavior
7213 : {
7214 1768 : TruncateStmt *n = makeNode(TruncateStmt);
7215 :
7216 1768 : n->relations = $3;
7217 1768 : n->restart_seqs = $4;
7218 1768 : n->behavior = $5;
7219 1768 : $$ = (Node *) n;
7220 : }
7221 : ;
7222 :
7223 : opt_restart_seqs:
7224 24 : CONTINUE_P IDENTITY_P { $$ = false; }
7225 22 : | RESTART IDENTITY_P { $$ = true; }
7226 1722 : | /* EMPTY */ { $$ = false; }
7227 : ;
7228 :
7229 : /*****************************************************************************
7230 : *
7231 : * COMMENT ON <object> IS <text>
7232 : *
7233 : *****************************************************************************/
7234 :
7235 : CommentStmt:
7236 : COMMENT ON object_type_any_name any_name IS comment_text
7237 : {
7238 5898 : CommentStmt *n = makeNode(CommentStmt);
7239 :
7240 5898 : n->objtype = $3;
7241 5898 : n->object = (Node *) $4;
7242 5898 : n->comment = $6;
7243 5898 : $$ = (Node *) n;
7244 : }
7245 : | COMMENT ON COLUMN any_name IS comment_text
7246 : {
7247 114 : CommentStmt *n = makeNode(CommentStmt);
7248 :
7249 114 : n->objtype = OBJECT_COLUMN;
7250 114 : n->object = (Node *) $4;
7251 114 : n->comment = $6;
7252 114 : $$ = (Node *) n;
7253 : }
7254 : | COMMENT ON object_type_name name IS comment_text
7255 : {
7256 488 : CommentStmt *n = makeNode(CommentStmt);
7257 :
7258 488 : n->objtype = $3;
7259 488 : n->object = (Node *) makeString($4);
7260 488 : n->comment = $6;
7261 488 : $$ = (Node *) n;
7262 : }
7263 : | COMMENT ON TYPE_P Typename IS comment_text
7264 : {
7265 56 : CommentStmt *n = makeNode(CommentStmt);
7266 :
7267 56 : n->objtype = OBJECT_TYPE;
7268 56 : n->object = (Node *) $4;
7269 56 : n->comment = $6;
7270 56 : $$ = (Node *) n;
7271 : }
7272 : | COMMENT ON DOMAIN_P Typename IS comment_text
7273 : {
7274 8 : CommentStmt *n = makeNode(CommentStmt);
7275 :
7276 8 : n->objtype = OBJECT_DOMAIN;
7277 8 : n->object = (Node *) $4;
7278 8 : n->comment = $6;
7279 8 : $$ = (Node *) n;
7280 : }
7281 : | COMMENT ON AGGREGATE aggregate_with_argtypes IS comment_text
7282 : {
7283 40 : CommentStmt *n = makeNode(CommentStmt);
7284 :
7285 40 : n->objtype = OBJECT_AGGREGATE;
7286 40 : n->object = (Node *) $4;
7287 40 : n->comment = $6;
7288 40 : $$ = (Node *) n;
7289 : }
7290 : | COMMENT ON FUNCTION function_with_argtypes IS comment_text
7291 : {
7292 170 : CommentStmt *n = makeNode(CommentStmt);
7293 :
7294 170 : n->objtype = OBJECT_FUNCTION;
7295 170 : n->object = (Node *) $4;
7296 170 : n->comment = $6;
7297 170 : $$ = (Node *) n;
7298 : }
7299 : | COMMENT ON OPERATOR operator_with_argtypes IS comment_text
7300 : {
7301 18 : CommentStmt *n = makeNode(CommentStmt);
7302 :
7303 18 : n->objtype = OBJECT_OPERATOR;
7304 18 : n->object = (Node *) $4;
7305 18 : n->comment = $6;
7306 18 : $$ = (Node *) n;
7307 : }
7308 : | COMMENT ON CONSTRAINT name ON any_name IS comment_text
7309 : {
7310 150 : CommentStmt *n = makeNode(CommentStmt);
7311 :
7312 150 : n->objtype = OBJECT_TABCONSTRAINT;
7313 150 : n->object = (Node *) lappend($6, makeString($4));
7314 150 : n->comment = $8;
7315 150 : $$ = (Node *) n;
7316 : }
7317 : | COMMENT ON CONSTRAINT name ON DOMAIN_P any_name IS comment_text
7318 : {
7319 48 : CommentStmt *n = makeNode(CommentStmt);
7320 :
7321 48 : n->objtype = OBJECT_DOMCONSTRAINT;
7322 : /*
7323 : * should use Typename not any_name in the production, but
7324 : * there's a shift/reduce conflict if we do that, so fix it
7325 : * up here.
7326 : */
7327 48 : n->object = (Node *) list_make2(makeTypeNameFromNameList($7), makeString($4));
7328 48 : n->comment = $9;
7329 48 : $$ = (Node *) n;
7330 : }
7331 : | COMMENT ON object_type_name_on_any_name name ON any_name IS comment_text
7332 : {
7333 42 : CommentStmt *n = makeNode(CommentStmt);
7334 :
7335 42 : n->objtype = $3;
7336 42 : n->object = (Node *) lappend($6, makeString($4));
7337 42 : n->comment = $8;
7338 42 : $$ = (Node *) n;
7339 : }
7340 : | COMMENT ON PROCEDURE function_with_argtypes IS comment_text
7341 : {
7342 0 : CommentStmt *n = makeNode(CommentStmt);
7343 :
7344 0 : n->objtype = OBJECT_PROCEDURE;
7345 0 : n->object = (Node *) $4;
7346 0 : n->comment = $6;
7347 0 : $$ = (Node *) n;
7348 : }
7349 : | COMMENT ON ROUTINE function_with_argtypes IS comment_text
7350 : {
7351 0 : CommentStmt *n = makeNode(CommentStmt);
7352 :
7353 0 : n->objtype = OBJECT_ROUTINE;
7354 0 : n->object = (Node *) $4;
7355 0 : n->comment = $6;
7356 0 : $$ = (Node *) n;
7357 : }
7358 : | COMMENT ON TRANSFORM FOR Typename LANGUAGE name IS comment_text
7359 : {
7360 14 : CommentStmt *n = makeNode(CommentStmt);
7361 :
7362 14 : n->objtype = OBJECT_TRANSFORM;
7363 14 : n->object = (Node *) list_make2($5, makeString($7));
7364 14 : n->comment = $9;
7365 14 : $$ = (Node *) n;
7366 : }
7367 : | COMMENT ON OPERATOR CLASS any_name USING name IS comment_text
7368 : {
7369 0 : CommentStmt *n = makeNode(CommentStmt);
7370 :
7371 0 : n->objtype = OBJECT_OPCLASS;
7372 0 : n->object = (Node *) lcons(makeString($7), $5);
7373 0 : n->comment = $9;
7374 0 : $$ = (Node *) n;
7375 : }
7376 : | COMMENT ON OPERATOR FAMILY any_name USING name IS comment_text
7377 : {
7378 0 : CommentStmt *n = makeNode(CommentStmt);
7379 :
7380 0 : n->objtype = OBJECT_OPFAMILY;
7381 0 : n->object = (Node *) lcons(makeString($7), $5);
7382 0 : n->comment = $9;
7383 0 : $$ = (Node *) n;
7384 : }
7385 : | COMMENT ON LARGE_P OBJECT_P NumericOnly IS comment_text
7386 : {
7387 42 : CommentStmt *n = makeNode(CommentStmt);
7388 :
7389 42 : n->objtype = OBJECT_LARGEOBJECT;
7390 42 : n->object = (Node *) $5;
7391 42 : n->comment = $7;
7392 42 : $$ = (Node *) n;
7393 : }
7394 : | COMMENT ON CAST '(' Typename AS Typename ')' IS comment_text
7395 : {
7396 0 : CommentStmt *n = makeNode(CommentStmt);
7397 :
7398 0 : n->objtype = OBJECT_CAST;
7399 0 : n->object = (Node *) list_make2($5, $7);
7400 0 : n->comment = $10;
7401 0 : $$ = (Node *) n;
7402 : }
7403 : ;
7404 :
7405 : comment_text:
7406 6984 : Sconst { $$ = $1; }
7407 104 : | NULL_P { $$ = NULL; }
7408 : ;
7409 :
7410 :
7411 : /*****************************************************************************
7412 : *
7413 : * SECURITY LABEL [FOR <provider>] ON <object> IS <label>
7414 : *
7415 : * As with COMMENT ON, <object> can refer to various types of database
7416 : * objects (e.g. TABLE, COLUMN, etc.).
7417 : *
7418 : *****************************************************************************/
7419 :
7420 : SecLabelStmt:
7421 : SECURITY LABEL opt_provider ON object_type_any_name any_name
7422 : IS security_label
7423 : {
7424 48 : SecLabelStmt *n = makeNode(SecLabelStmt);
7425 :
7426 48 : n->provider = $3;
7427 48 : n->objtype = $5;
7428 48 : n->object = (Node *) $6;
7429 48 : n->label = $8;
7430 48 : $$ = (Node *) n;
7431 : }
7432 : | SECURITY LABEL opt_provider ON COLUMN any_name
7433 : IS security_label
7434 : {
7435 4 : SecLabelStmt *n = makeNode(SecLabelStmt);
7436 :
7437 4 : n->provider = $3;
7438 4 : n->objtype = OBJECT_COLUMN;
7439 4 : n->object = (Node *) $6;
7440 4 : n->label = $8;
7441 4 : $$ = (Node *) n;
7442 : }
7443 : | SECURITY LABEL opt_provider ON object_type_name name
7444 : IS security_label
7445 : {
7446 44 : SecLabelStmt *n = makeNode(SecLabelStmt);
7447 :
7448 44 : n->provider = $3;
7449 44 : n->objtype = $5;
7450 44 : n->object = (Node *) makeString($6);
7451 44 : n->label = $8;
7452 44 : $$ = (Node *) n;
7453 : }
7454 : | SECURITY LABEL opt_provider ON TYPE_P Typename
7455 : IS security_label
7456 : {
7457 0 : SecLabelStmt *n = makeNode(SecLabelStmt);
7458 :
7459 0 : n->provider = $3;
7460 0 : n->objtype = OBJECT_TYPE;
7461 0 : n->object = (Node *) $6;
7462 0 : n->label = $8;
7463 0 : $$ = (Node *) n;
7464 : }
7465 : | SECURITY LABEL opt_provider ON DOMAIN_P Typename
7466 : IS security_label
7467 : {
7468 2 : SecLabelStmt *n = makeNode(SecLabelStmt);
7469 :
7470 2 : n->provider = $3;
7471 2 : n->objtype = OBJECT_DOMAIN;
7472 2 : n->object = (Node *) $6;
7473 2 : n->label = $8;
7474 2 : $$ = (Node *) n;
7475 : }
7476 : | SECURITY LABEL opt_provider ON AGGREGATE aggregate_with_argtypes
7477 : IS security_label
7478 : {
7479 0 : SecLabelStmt *n = makeNode(SecLabelStmt);
7480 :
7481 0 : n->provider = $3;
7482 0 : n->objtype = OBJECT_AGGREGATE;
7483 0 : n->object = (Node *) $6;
7484 0 : n->label = $8;
7485 0 : $$ = (Node *) n;
7486 : }
7487 : | SECURITY LABEL opt_provider ON FUNCTION function_with_argtypes
7488 : IS security_label
7489 : {
7490 2 : SecLabelStmt *n = makeNode(SecLabelStmt);
7491 :
7492 2 : n->provider = $3;
7493 2 : n->objtype = OBJECT_FUNCTION;
7494 2 : n->object = (Node *) $6;
7495 2 : n->label = $8;
7496 2 : $$ = (Node *) n;
7497 : }
7498 : | SECURITY LABEL opt_provider ON LARGE_P OBJECT_P NumericOnly
7499 : IS security_label
7500 : {
7501 18 : SecLabelStmt *n = makeNode(SecLabelStmt);
7502 :
7503 18 : n->provider = $3;
7504 18 : n->objtype = OBJECT_LARGEOBJECT;
7505 18 : n->object = (Node *) $7;
7506 18 : n->label = $9;
7507 18 : $$ = (Node *) n;
7508 : }
7509 : | SECURITY LABEL opt_provider ON PROCEDURE function_with_argtypes
7510 : IS security_label
7511 : {
7512 0 : SecLabelStmt *n = makeNode(SecLabelStmt);
7513 :
7514 0 : n->provider = $3;
7515 0 : n->objtype = OBJECT_PROCEDURE;
7516 0 : n->object = (Node *) $6;
7517 0 : n->label = $8;
7518 0 : $$ = (Node *) n;
7519 : }
7520 : | SECURITY LABEL opt_provider ON ROUTINE function_with_argtypes
7521 : IS security_label
7522 : {
7523 0 : SecLabelStmt *n = makeNode(SecLabelStmt);
7524 :
7525 0 : n->provider = $3;
7526 0 : n->objtype = OBJECT_ROUTINE;
7527 0 : n->object = (Node *) $6;
7528 0 : n->label = $8;
7529 0 : $$ = (Node *) n;
7530 : }
7531 : ;
7532 :
7533 28 : opt_provider: FOR NonReservedWord_or_Sconst { $$ = $2; }
7534 90 : | /* EMPTY */ { $$ = NULL; }
7535 : ;
7536 :
7537 118 : security_label: Sconst { $$ = $1; }
7538 0 : | NULL_P { $$ = NULL; }
7539 : ;
7540 :
7541 : /*****************************************************************************
7542 : *
7543 : * QUERY:
7544 : * fetch/move
7545 : *
7546 : *****************************************************************************/
7547 :
7548 : FetchStmt: FETCH fetch_args
7549 : {
7550 7646 : FetchStmt *n = (FetchStmt *) $2;
7551 :
7552 7646 : n->ismove = false;
7553 7646 : $$ = (Node *) n;
7554 : }
7555 : | MOVE fetch_args
7556 : {
7557 68 : FetchStmt *n = (FetchStmt *) $2;
7558 :
7559 68 : n->ismove = true;
7560 68 : $$ = (Node *) n;
7561 : }
7562 : ;
7563 :
7564 : fetch_args: cursor_name
7565 : {
7566 272 : FetchStmt *n = makeNode(FetchStmt);
7567 :
7568 272 : n->portalname = $1;
7569 272 : n->direction = FETCH_FORWARD;
7570 272 : n->howMany = 1;
7571 272 : n->location = -1;
7572 272 : n->direction_keyword = FETCH_KEYWORD_NONE;
7573 272 : $$ = (Node *) n;
7574 : }
7575 : | from_in cursor_name
7576 : {
7577 218 : FetchStmt *n = makeNode(FetchStmt);
7578 :
7579 218 : n->portalname = $2;
7580 218 : n->direction = FETCH_FORWARD;
7581 218 : n->howMany = 1;
7582 218 : n->location = -1;
7583 218 : n->direction_keyword = FETCH_KEYWORD_NONE;
7584 218 : $$ = (Node *) n;
7585 : }
7586 : | SignedIconst opt_from_in cursor_name
7587 : {
7588 4280 : FetchStmt *n = makeNode(FetchStmt);
7589 :
7590 4280 : n->portalname = $3;
7591 4280 : n->direction = FETCH_FORWARD;
7592 4280 : n->howMany = $1;
7593 4280 : n->location = @1;
7594 4280 : n->direction_keyword = FETCH_KEYWORD_NONE;
7595 4280 : $$ = (Node *) n;
7596 : }
7597 : | NEXT opt_from_in cursor_name
7598 : {
7599 2010 : FetchStmt *n = makeNode(FetchStmt);
7600 :
7601 2010 : n->portalname = $3;
7602 2010 : n->direction = FETCH_FORWARD;
7603 2010 : n->howMany = 1;
7604 2010 : n->location = -1;
7605 2010 : n->direction_keyword = FETCH_KEYWORD_NEXT;
7606 2010 : $$ = (Node *) n;
7607 : }
7608 : | PRIOR opt_from_in cursor_name
7609 : {
7610 32 : FetchStmt *n = makeNode(FetchStmt);
7611 :
7612 32 : n->portalname = $3;
7613 32 : n->direction = FETCH_BACKWARD;
7614 32 : n->howMany = 1;
7615 32 : n->location = -1;
7616 32 : n->direction_keyword = FETCH_KEYWORD_PRIOR;
7617 32 : $$ = (Node *) n;
7618 : }
7619 : | FIRST_P opt_from_in cursor_name
7620 : {
7621 26 : FetchStmt *n = makeNode(FetchStmt);
7622 :
7623 26 : n->portalname = $3;
7624 26 : n->direction = FETCH_ABSOLUTE;
7625 26 : n->howMany = 1;
7626 26 : n->location = -1;
7627 26 : n->direction_keyword = FETCH_KEYWORD_FIRST;
7628 26 : $$ = (Node *) n;
7629 : }
7630 : | LAST_P opt_from_in cursor_name
7631 : {
7632 20 : FetchStmt *n = makeNode(FetchStmt);
7633 :
7634 20 : n->portalname = $3;
7635 20 : n->direction = FETCH_ABSOLUTE;
7636 20 : n->howMany = -1;
7637 20 : n->location = -1;
7638 20 : n->direction_keyword = FETCH_KEYWORD_LAST;
7639 20 : $$ = (Node *) n;
7640 : }
7641 : | ABSOLUTE_P SignedIconst opt_from_in cursor_name
7642 : {
7643 94 : FetchStmt *n = makeNode(FetchStmt);
7644 :
7645 94 : n->portalname = $4;
7646 94 : n->direction = FETCH_ABSOLUTE;
7647 94 : n->howMany = $2;
7648 94 : n->location = @2;
7649 94 : n->direction_keyword = FETCH_KEYWORD_ABSOLUTE;
7650 94 : $$ = (Node *) n;
7651 : }
7652 : | RELATIVE_P SignedIconst opt_from_in cursor_name
7653 : {
7654 36 : FetchStmt *n = makeNode(FetchStmt);
7655 :
7656 36 : n->portalname = $4;
7657 36 : n->direction = FETCH_RELATIVE;
7658 36 : n->howMany = $2;
7659 36 : n->location = @2;
7660 36 : n->direction_keyword = FETCH_KEYWORD_RELATIVE;
7661 36 : $$ = (Node *) n;
7662 : }
7663 : | ALL opt_from_in cursor_name
7664 : {
7665 270 : FetchStmt *n = makeNode(FetchStmt);
7666 :
7667 270 : n->portalname = $3;
7668 270 : n->direction = FETCH_FORWARD;
7669 270 : n->howMany = FETCH_ALL;
7670 270 : n->location = -1;
7671 270 : n->direction_keyword = FETCH_KEYWORD_ALL;
7672 270 : $$ = (Node *) n;
7673 : }
7674 : | FORWARD opt_from_in cursor_name
7675 : {
7676 30 : FetchStmt *n = makeNode(FetchStmt);
7677 :
7678 30 : n->portalname = $3;
7679 30 : n->direction = FETCH_FORWARD;
7680 30 : n->howMany = 1;
7681 30 : n->location = -1;
7682 30 : n->direction_keyword = FETCH_KEYWORD_FORWARD;
7683 30 : $$ = (Node *) n;
7684 : }
7685 : | FORWARD SignedIconst opt_from_in cursor_name
7686 : {
7687 12 : FetchStmt *n = makeNode(FetchStmt);
7688 :
7689 12 : n->portalname = $4;
7690 12 : n->direction = FETCH_FORWARD;
7691 12 : n->howMany = $2;
7692 12 : n->location = @2;
7693 12 : n->direction_keyword = FETCH_KEYWORD_FORWARD;
7694 12 : $$ = (Node *) n;
7695 : }
7696 : | FORWARD ALL opt_from_in cursor_name
7697 : {
7698 16 : FetchStmt *n = makeNode(FetchStmt);
7699 :
7700 16 : n->portalname = $4;
7701 16 : n->direction = FETCH_FORWARD;
7702 16 : n->howMany = FETCH_ALL;
7703 16 : n->location = -1;
7704 16 : n->direction_keyword = FETCH_KEYWORD_FORWARD_ALL;
7705 16 : $$ = (Node *) n;
7706 : }
7707 : | BACKWARD opt_from_in cursor_name
7708 : {
7709 80 : FetchStmt *n = makeNode(FetchStmt);
7710 :
7711 80 : n->portalname = $3;
7712 80 : n->direction = FETCH_BACKWARD;
7713 80 : n->howMany = 1;
7714 80 : n->location = -1;
7715 80 : n->direction_keyword = FETCH_KEYWORD_BACKWARD;
7716 80 : $$ = (Node *) n;
7717 : }
7718 : | BACKWARD SignedIconst opt_from_in cursor_name
7719 : {
7720 226 : FetchStmt *n = makeNode(FetchStmt);
7721 :
7722 226 : n->portalname = $4;
7723 226 : n->direction = FETCH_BACKWARD;
7724 226 : n->howMany = $2;
7725 226 : n->location = @2;
7726 226 : n->direction_keyword = FETCH_KEYWORD_BACKWARD;
7727 226 : $$ = (Node *) n;
7728 : }
7729 : | BACKWARD ALL opt_from_in cursor_name
7730 : {
7731 92 : FetchStmt *n = makeNode(FetchStmt);
7732 :
7733 92 : n->portalname = $4;
7734 92 : n->direction = FETCH_BACKWARD;
7735 92 : n->howMany = FETCH_ALL;
7736 92 : n->location = -1;
7737 92 : n->direction_keyword = FETCH_KEYWORD_BACKWARD_ALL;
7738 92 : $$ = (Node *) n;
7739 : }
7740 : ;
7741 :
7742 : from_in: FROM
7743 : | IN_P
7744 : ;
7745 :
7746 : opt_from_in: from_in
7747 : | /* EMPTY */
7748 : ;
7749 :
7750 :
7751 : /*****************************************************************************
7752 : *
7753 : * GRANT and REVOKE statements
7754 : *
7755 : *****************************************************************************/
7756 :
7757 : GrantStmt: GRANT privileges ON privilege_target TO grantee_list
7758 : opt_grant_grant_option opt_granted_by
7759 : {
7760 11814 : GrantStmt *n = makeNode(GrantStmt);
7761 :
7762 11814 : n->is_grant = true;
7763 11814 : n->privileges = $2;
7764 11814 : n->targtype = ($4)->targtype;
7765 11814 : n->objtype = ($4)->objtype;
7766 11814 : n->objects = ($4)->objs;
7767 11814 : n->grantees = $6;
7768 11814 : n->grant_option = $7;
7769 11814 : n->grantor = $8;
7770 11814 : $$ = (Node *) n;
7771 : }
7772 : ;
7773 :
7774 : RevokeStmt:
7775 : REVOKE privileges ON privilege_target
7776 : FROM grantee_list opt_granted_by opt_drop_behavior
7777 : {
7778 10438 : GrantStmt *n = makeNode(GrantStmt);
7779 :
7780 10438 : n->is_grant = false;
7781 10438 : n->grant_option = false;
7782 10438 : n->privileges = $2;
7783 10438 : n->targtype = ($4)->targtype;
7784 10438 : n->objtype = ($4)->objtype;
7785 10438 : n->objects = ($4)->objs;
7786 10438 : n->grantees = $6;
7787 10438 : n->grantor = $7;
7788 10438 : n->behavior = $8;
7789 10438 : $$ = (Node *) n;
7790 : }
7791 : | REVOKE GRANT OPTION FOR privileges ON privilege_target
7792 : FROM grantee_list opt_granted_by opt_drop_behavior
7793 : {
7794 16 : GrantStmt *n = makeNode(GrantStmt);
7795 :
7796 16 : n->is_grant = false;
7797 16 : n->grant_option = true;
7798 16 : n->privileges = $5;
7799 16 : n->targtype = ($7)->targtype;
7800 16 : n->objtype = ($7)->objtype;
7801 16 : n->objects = ($7)->objs;
7802 16 : n->grantees = $9;
7803 16 : n->grantor = $10;
7804 16 : n->behavior = $11;
7805 16 : $$ = (Node *) n;
7806 : }
7807 : ;
7808 :
7809 :
7810 : /*
7811 : * Privilege names are represented as strings; the validity of the privilege
7812 : * names gets checked at execution. This is a bit annoying but we have little
7813 : * choice because of the syntactic conflict with lists of role names in
7814 : * GRANT/REVOKE. What's more, we have to call out in the "privilege"
7815 : * production any reserved keywords that need to be usable as privilege names.
7816 : */
7817 :
7818 : /* either ALL [PRIVILEGES] or a list of individual privileges */
7819 : privileges: privilege_list
7820 19648 : { $$ = $1; }
7821 : | ALL
7822 2700 : { $$ = NIL; }
7823 : | ALL PRIVILEGES
7824 120 : { $$ = NIL; }
7825 : | ALL '(' columnList ')'
7826 : {
7827 18 : AccessPriv *n = makeNode(AccessPriv);
7828 :
7829 18 : n->priv_name = NULL;
7830 18 : n->cols = $3;
7831 18 : $$ = list_make1(n);
7832 : }
7833 : | ALL PRIVILEGES '(' columnList ')'
7834 : {
7835 0 : AccessPriv *n = makeNode(AccessPriv);
7836 :
7837 0 : n->priv_name = NULL;
7838 0 : n->cols = $4;
7839 0 : $$ = list_make1(n);
7840 : }
7841 : ;
7842 :
7843 20562 : privilege_list: privilege { $$ = list_make1($1); }
7844 580 : | privilege_list ',' privilege { $$ = lappend($1, $3); }
7845 : ;
7846 :
7847 : privilege: SELECT opt_column_list
7848 : {
7849 9544 : AccessPriv *n = makeNode(AccessPriv);
7850 :
7851 9544 : n->priv_name = pstrdup($1);
7852 9544 : n->cols = $2;
7853 9544 : $$ = n;
7854 : }
7855 : | REFERENCES opt_column_list
7856 : {
7857 14 : AccessPriv *n = makeNode(AccessPriv);
7858 :
7859 14 : n->priv_name = pstrdup($1);
7860 14 : n->cols = $2;
7861 14 : $$ = n;
7862 : }
7863 : | CREATE opt_column_list
7864 : {
7865 320 : AccessPriv *n = makeNode(AccessPriv);
7866 :
7867 320 : n->priv_name = pstrdup($1);
7868 320 : n->cols = $2;
7869 320 : $$ = n;
7870 : }
7871 : | ALTER SYSTEM_P
7872 : {
7873 24 : AccessPriv *n = makeNode(AccessPriv);
7874 24 : n->priv_name = pstrdup("alter system");
7875 24 : n->cols = NIL;
7876 24 : $$ = n;
7877 : }
7878 : | ColId opt_column_list
7879 : {
7880 11240 : AccessPriv *n = makeNode(AccessPriv);
7881 :
7882 11240 : n->priv_name = $1;
7883 11240 : n->cols = $2;
7884 11240 : $$ = n;
7885 : }
7886 : ;
7887 :
7888 : parameter_name_list:
7889 : parameter_name
7890 : {
7891 76 : $$ = list_make1(makeString($1));
7892 : }
7893 : | parameter_name_list ',' parameter_name
7894 : {
7895 50 : $$ = lappend($1, makeString($3));
7896 : }
7897 : ;
7898 :
7899 : parameter_name:
7900 : ColId
7901 : {
7902 126 : $$ = $1;
7903 : }
7904 : | parameter_name '.' ColId
7905 : {
7906 32 : $$ = psprintf("%s.%s", $1, $3);
7907 : }
7908 : ;
7909 :
7910 :
7911 : /* Don't bother trying to fold the first two rules into one using
7912 : * opt_table. You're going to get conflicts.
7913 : */
7914 : privilege_target:
7915 : qualified_name_list
7916 : {
7917 11578 : PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
7918 :
7919 11578 : n->targtype = ACL_TARGET_OBJECT;
7920 11578 : n->objtype = OBJECT_TABLE;
7921 11578 : n->objs = $1;
7922 11578 : $$ = n;
7923 : }
7924 : | TABLE qualified_name_list
7925 : {
7926 388 : PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
7927 :
7928 388 : n->targtype = ACL_TARGET_OBJECT;
7929 388 : n->objtype = OBJECT_TABLE;
7930 388 : n->objs = $2;
7931 388 : $$ = n;
7932 : }
7933 : | SEQUENCE qualified_name_list
7934 : {
7935 22 : PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
7936 :
7937 22 : n->targtype = ACL_TARGET_OBJECT;
7938 22 : n->objtype = OBJECT_SEQUENCE;
7939 22 : n->objs = $2;
7940 22 : $$ = n;
7941 : }
7942 : | FOREIGN DATA_P WRAPPER name_list
7943 : {
7944 92 : PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
7945 :
7946 92 : n->targtype = ACL_TARGET_OBJECT;
7947 92 : n->objtype = OBJECT_FDW;
7948 92 : n->objs = $4;
7949 92 : $$ = n;
7950 : }
7951 : | FOREIGN SERVER name_list
7952 : {
7953 88 : PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
7954 :
7955 88 : n->targtype = ACL_TARGET_OBJECT;
7956 88 : n->objtype = OBJECT_FOREIGN_SERVER;
7957 88 : n->objs = $3;
7958 88 : $$ = n;
7959 : }
7960 : | FUNCTION function_with_argtypes_list
7961 : {
7962 8944 : PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
7963 :
7964 8944 : n->targtype = ACL_TARGET_OBJECT;
7965 8944 : n->objtype = OBJECT_FUNCTION;
7966 8944 : n->objs = $2;
7967 8944 : $$ = n;
7968 : }
7969 : | PROCEDURE function_with_argtypes_list
7970 : {
7971 42 : PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
7972 :
7973 42 : n->targtype = ACL_TARGET_OBJECT;
7974 42 : n->objtype = OBJECT_PROCEDURE;
7975 42 : n->objs = $2;
7976 42 : $$ = n;
7977 : }
7978 : | ROUTINE function_with_argtypes_list
7979 : {
7980 0 : PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
7981 :
7982 0 : n->targtype = ACL_TARGET_OBJECT;
7983 0 : n->objtype = OBJECT_ROUTINE;
7984 0 : n->objs = $2;
7985 0 : $$ = n;
7986 : }
7987 : | DATABASE name_list
7988 : {
7989 346 : PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
7990 :
7991 346 : n->targtype = ACL_TARGET_OBJECT;
7992 346 : n->objtype = OBJECT_DATABASE;
7993 346 : n->objs = $2;
7994 346 : $$ = n;
7995 : }
7996 : | DOMAIN_P any_name_list
7997 : {
7998 26 : PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
7999 :
8000 26 : n->targtype = ACL_TARGET_OBJECT;
8001 26 : n->objtype = OBJECT_DOMAIN;
8002 26 : n->objs = $2;
8003 26 : $$ = n;
8004 : }
8005 : | LANGUAGE name_list
8006 : {
8007 42 : PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
8008 :
8009 42 : n->targtype = ACL_TARGET_OBJECT;
8010 42 : n->objtype = OBJECT_LANGUAGE;
8011 42 : n->objs = $2;
8012 42 : $$ = n;
8013 : }
8014 : | LARGE_P OBJECT_P NumericOnly_list
8015 : {
8016 90 : PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
8017 :
8018 90 : n->targtype = ACL_TARGET_OBJECT;
8019 90 : n->objtype = OBJECT_LARGEOBJECT;
8020 90 : n->objs = $3;
8021 90 : $$ = n;
8022 : }
8023 : | PARAMETER parameter_name_list
8024 : {
8025 76 : PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
8026 76 : n->targtype = ACL_TARGET_OBJECT;
8027 76 : n->objtype = OBJECT_PARAMETER_ACL;
8028 76 : n->objs = $2;
8029 76 : $$ = n;
8030 : }
8031 : | SCHEMA name_list
8032 : {
8033 398 : PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
8034 :
8035 398 : n->targtype = ACL_TARGET_OBJECT;
8036 398 : n->objtype = OBJECT_SCHEMA;
8037 398 : n->objs = $2;
8038 398 : $$ = n;
8039 : }
8040 : | TABLESPACE name_list
8041 : {
8042 6 : PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
8043 :
8044 6 : n->targtype = ACL_TARGET_OBJECT;
8045 6 : n->objtype = OBJECT_TABLESPACE;
8046 6 : n->objs = $2;
8047 6 : $$ = n;
8048 : }
8049 : | TYPE_P any_name_list
8050 : {
8051 112 : PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
8052 :
8053 112 : n->targtype = ACL_TARGET_OBJECT;
8054 112 : n->objtype = OBJECT_TYPE;
8055 112 : n->objs = $2;
8056 112 : $$ = n;
8057 : }
8058 : | ALL TABLES IN_P SCHEMA name_list
8059 : {
8060 12 : PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
8061 :
8062 12 : n->targtype = ACL_TARGET_ALL_IN_SCHEMA;
8063 12 : n->objtype = OBJECT_TABLE;
8064 12 : n->objs = $5;
8065 12 : $$ = n;
8066 : }
8067 : | ALL SEQUENCES IN_P SCHEMA name_list
8068 : {
8069 0 : PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
8070 :
8071 0 : n->targtype = ACL_TARGET_ALL_IN_SCHEMA;
8072 0 : n->objtype = OBJECT_SEQUENCE;
8073 0 : n->objs = $5;
8074 0 : $$ = n;
8075 : }
8076 : | ALL FUNCTIONS IN_P SCHEMA name_list
8077 : {
8078 6 : PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
8079 :
8080 6 : n->targtype = ACL_TARGET_ALL_IN_SCHEMA;
8081 6 : n->objtype = OBJECT_FUNCTION;
8082 6 : n->objs = $5;
8083 6 : $$ = n;
8084 : }
8085 : | ALL PROCEDURES IN_P SCHEMA name_list
8086 : {
8087 6 : PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
8088 :
8089 6 : n->targtype = ACL_TARGET_ALL_IN_SCHEMA;
8090 6 : n->objtype = OBJECT_PROCEDURE;
8091 6 : n->objs = $5;
8092 6 : $$ = n;
8093 : }
8094 : | ALL ROUTINES IN_P SCHEMA name_list
8095 : {
8096 6 : PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
8097 :
8098 6 : n->targtype = ACL_TARGET_ALL_IN_SCHEMA;
8099 6 : n->objtype = OBJECT_ROUTINE;
8100 6 : n->objs = $5;
8101 6 : $$ = n;
8102 : }
8103 : ;
8104 :
8105 :
8106 : grantee_list:
8107 22474 : grantee { $$ = list_make1($1); }
8108 108 : | grantee_list ',' grantee { $$ = lappend($1, $3); }
8109 : ;
8110 :
8111 : grantee:
8112 22558 : RoleSpec { $$ = $1; }
8113 24 : | GROUP_P RoleSpec { $$ = $2; }
8114 : ;
8115 :
8116 :
8117 : opt_grant_grant_option:
8118 102 : WITH GRANT OPTION { $$ = true; }
8119 11836 : | /*EMPTY*/ { $$ = false; }
8120 : ;
8121 :
8122 : /*****************************************************************************
8123 : *
8124 : * GRANT and REVOKE ROLE statements
8125 : *
8126 : *****************************************************************************/
8127 :
8128 : GrantRoleStmt:
8129 : GRANT privilege_list TO role_list opt_granted_by
8130 : {
8131 580 : GrantRoleStmt *n = makeNode(GrantRoleStmt);
8132 :
8133 580 : n->is_grant = true;
8134 580 : n->granted_roles = $2;
8135 580 : n->grantee_roles = $4;
8136 580 : n->opt = NIL;
8137 580 : n->grantor = $5;
8138 580 : $$ = (Node *) n;
8139 : }
8140 : | GRANT privilege_list TO role_list WITH grant_role_opt_list opt_granted_by
8141 : {
8142 178 : GrantRoleStmt *n = makeNode(GrantRoleStmt);
8143 :
8144 178 : n->is_grant = true;
8145 178 : n->granted_roles = $2;
8146 178 : n->grantee_roles = $4;
8147 178 : n->opt = $6;
8148 178 : n->grantor = $7;
8149 178 : $$ = (Node *) n;
8150 : }
8151 : ;
8152 :
8153 : RevokeRoleStmt:
8154 : REVOKE privilege_list FROM role_list opt_granted_by opt_drop_behavior
8155 : {
8156 90 : GrantRoleStmt *n = makeNode(GrantRoleStmt);
8157 :
8158 90 : n->is_grant = false;
8159 90 : n->opt = NIL;
8160 90 : n->granted_roles = $2;
8161 90 : n->grantee_roles = $4;
8162 90 : n->grantor = $5;
8163 90 : n->behavior = $6;
8164 90 : $$ = (Node *) n;
8165 : }
8166 : | REVOKE ColId OPTION FOR privilege_list FROM role_list opt_granted_by opt_drop_behavior
8167 : {
8168 66 : GrantRoleStmt *n = makeNode(GrantRoleStmt);
8169 : DefElem *opt;
8170 :
8171 66 : opt = makeDefElem(pstrdup($2),
8172 66 : (Node *) makeBoolean(false), @2);
8173 66 : n->is_grant = false;
8174 66 : n->opt = list_make1(opt);
8175 66 : n->granted_roles = $5;
8176 66 : n->grantee_roles = $7;
8177 66 : n->grantor = $8;
8178 66 : n->behavior = $9;
8179 66 : $$ = (Node *) n;
8180 : }
8181 : ;
8182 :
8183 : grant_role_opt_list:
8184 120 : grant_role_opt_list ',' grant_role_opt { $$ = lappend($1, $3); }
8185 178 : | grant_role_opt { $$ = list_make1($1); }
8186 : ;
8187 :
8188 : grant_role_opt:
8189 : ColLabel grant_role_opt_value
8190 : {
8191 298 : $$ = makeDefElem(pstrdup($1), $2, @1);
8192 : }
8193 : ;
8194 :
8195 : grant_role_opt_value:
8196 72 : OPTION { $$ = (Node *) makeBoolean(true); }
8197 112 : | TRUE_P { $$ = (Node *) makeBoolean(true); }
8198 114 : | FALSE_P { $$ = (Node *) makeBoolean(false); }
8199 : ;
8200 :
8201 138 : opt_granted_by: GRANTED BY RoleSpec { $$ = $3; }
8202 23044 : | /*EMPTY*/ { $$ = NULL; }
8203 : ;
8204 :
8205 : /*****************************************************************************
8206 : *
8207 : * ALTER DEFAULT PRIVILEGES statement
8208 : *
8209 : *****************************************************************************/
8210 :
8211 : AlterDefaultPrivilegesStmt:
8212 : ALTER DEFAULT PRIVILEGES DefACLOptionList DefACLAction
8213 : {
8214 206 : AlterDefaultPrivilegesStmt *n = makeNode(AlterDefaultPrivilegesStmt);
8215 :
8216 206 : n->options = $4;
8217 206 : n->action = (GrantStmt *) $5;
8218 206 : $$ = (Node *) n;
8219 : }
8220 : ;
8221 :
8222 : DefACLOptionList:
8223 144 : DefACLOptionList DefACLOption { $$ = lappend($1, $2); }
8224 206 : | /* EMPTY */ { $$ = NIL; }
8225 : ;
8226 :
8227 : DefACLOption:
8228 : IN_P SCHEMA name_list
8229 : {
8230 60 : $$ = makeDefElem("schemas", (Node *) $3, @1);
8231 : }
8232 : | FOR ROLE role_list
8233 : {
8234 84 : $$ = makeDefElem("roles", (Node *) $3, @1);
8235 : }
8236 : | FOR USER role_list
8237 : {
8238 0 : $$ = makeDefElem("roles", (Node *) $3, @1);
8239 : }
8240 : ;
8241 :
8242 : /*
8243 : * This should match GRANT/REVOKE, except that individual target objects
8244 : * are not mentioned and we only allow a subset of object types.
8245 : */
8246 : DefACLAction:
8247 : GRANT privileges ON defacl_privilege_target TO grantee_list
8248 : opt_grant_grant_option
8249 : {
8250 124 : GrantStmt *n = makeNode(GrantStmt);
8251 :
8252 124 : n->is_grant = true;
8253 124 : n->privileges = $2;
8254 124 : n->targtype = ACL_TARGET_DEFAULTS;
8255 124 : n->objtype = $4;
8256 124 : n->objects = NIL;
8257 124 : n->grantees = $6;
8258 124 : n->grant_option = $7;
8259 124 : $$ = (Node *) n;
8260 : }
8261 : | REVOKE privileges ON defacl_privilege_target
8262 : FROM grantee_list opt_drop_behavior
8263 : {
8264 82 : GrantStmt *n = makeNode(GrantStmt);
8265 :
8266 82 : n->is_grant = false;
8267 82 : n->grant_option = false;
8268 82 : n->privileges = $2;
8269 82 : n->targtype = ACL_TARGET_DEFAULTS;
8270 82 : n->objtype = $4;
8271 82 : n->objects = NIL;
8272 82 : n->grantees = $6;
8273 82 : n->behavior = $7;
8274 82 : $$ = (Node *) n;
8275 : }
8276 : | REVOKE GRANT OPTION FOR privileges ON defacl_privilege_target
8277 : FROM grantee_list opt_drop_behavior
8278 : {
8279 0 : GrantStmt *n = makeNode(GrantStmt);
8280 :
8281 0 : n->is_grant = false;
8282 0 : n->grant_option = true;
8283 0 : n->privileges = $5;
8284 0 : n->targtype = ACL_TARGET_DEFAULTS;
8285 0 : n->objtype = $7;
8286 0 : n->objects = NIL;
8287 0 : n->grantees = $9;
8288 0 : n->behavior = $10;
8289 0 : $$ = (Node *) n;
8290 : }
8291 : ;
8292 :
8293 : defacl_privilege_target:
8294 78 : TABLES { $$ = OBJECT_TABLE; }
8295 16 : | FUNCTIONS { $$ = OBJECT_FUNCTION; }
8296 6 : | ROUTINES { $$ = OBJECT_FUNCTION; }
8297 6 : | SEQUENCES { $$ = OBJECT_SEQUENCE; }
8298 34 : | TYPES_P { $$ = OBJECT_TYPE; }
8299 36 : | SCHEMAS { $$ = OBJECT_SCHEMA; }
8300 30 : | LARGE_P OBJECTS_P { $$ = OBJECT_LARGEOBJECT; }
8301 : ;
8302 :
8303 :
8304 : /*****************************************************************************
8305 : *
8306 : * QUERY: CREATE INDEX
8307 : *
8308 : * Note: we cannot put TABLESPACE clause after WHERE clause unless we are
8309 : * willing to make TABLESPACE a fully reserved word.
8310 : *****************************************************************************/
8311 :
8312 : IndexStmt: CREATE opt_unique INDEX opt_concurrently opt_single_name
8313 : ON relation_expr access_method_clause '(' index_params ')'
8314 : opt_include opt_unique_null_treatment opt_reloptions OptTableSpace where_clause
8315 : {
8316 6682 : IndexStmt *n = makeNode(IndexStmt);
8317 :
8318 6682 : n->unique = $2;
8319 6682 : n->concurrent = $4;
8320 6682 : n->idxname = $5;
8321 6682 : n->relation = $7;
8322 6682 : n->accessMethod = $8;
8323 6682 : n->indexParams = $10;
8324 6682 : n->indexIncludingParams = $12;
8325 6682 : n->nulls_not_distinct = !$13;
8326 6682 : n->options = $14;
8327 6682 : n->tableSpace = $15;
8328 6682 : n->whereClause = $16;
8329 6682 : n->excludeOpNames = NIL;
8330 6682 : n->idxcomment = NULL;
8331 6682 : n->indexOid = InvalidOid;
8332 6682 : n->oldNumber = InvalidRelFileNumber;
8333 6682 : n->oldCreateSubid = InvalidSubTransactionId;
8334 6682 : n->oldFirstRelfilelocatorSubid = InvalidSubTransactionId;
8335 6682 : n->primary = false;
8336 6682 : n->isconstraint = false;
8337 6682 : n->deferrable = false;
8338 6682 : n->initdeferred = false;
8339 6682 : n->transformed = false;
8340 6682 : n->if_not_exists = false;
8341 6682 : n->reset_default_tblspc = false;
8342 6682 : $$ = (Node *) n;
8343 : }
8344 : | CREATE opt_unique INDEX opt_concurrently IF_P NOT EXISTS name
8345 : ON relation_expr access_method_clause '(' index_params ')'
8346 : opt_include opt_unique_null_treatment opt_reloptions OptTableSpace where_clause
8347 : {
8348 18 : IndexStmt *n = makeNode(IndexStmt);
8349 :
8350 18 : n->unique = $2;
8351 18 : n->concurrent = $4;
8352 18 : n->idxname = $8;
8353 18 : n->relation = $10;
8354 18 : n->accessMethod = $11;
8355 18 : n->indexParams = $13;
8356 18 : n->indexIncludingParams = $15;
8357 18 : n->nulls_not_distinct = !$16;
8358 18 : n->options = $17;
8359 18 : n->tableSpace = $18;
8360 18 : n->whereClause = $19;
8361 18 : n->excludeOpNames = NIL;
8362 18 : n->idxcomment = NULL;
8363 18 : n->indexOid = InvalidOid;
8364 18 : n->oldNumber = InvalidRelFileNumber;
8365 18 : n->oldCreateSubid = InvalidSubTransactionId;
8366 18 : n->oldFirstRelfilelocatorSubid = InvalidSubTransactionId;
8367 18 : n->primary = false;
8368 18 : n->isconstraint = false;
8369 18 : n->deferrable = false;
8370 18 : n->initdeferred = false;
8371 18 : n->transformed = false;
8372 18 : n->if_not_exists = true;
8373 18 : n->reset_default_tblspc = false;
8374 18 : $$ = (Node *) n;
8375 : }
8376 : ;
8377 :
8378 : opt_unique:
8379 1300 : UNIQUE { $$ = true; }
8380 5406 : | /*EMPTY*/ { $$ = false; }
8381 : ;
8382 :
8383 : access_method_clause:
8384 3014 : USING name { $$ = $2; }
8385 3920 : | /*EMPTY*/ { $$ = DEFAULT_INDEX_TYPE; }
8386 : ;
8387 :
8388 8208 : index_params: index_elem { $$ = list_make1($1); }
8389 2164 : | index_params ',' index_elem { $$ = lappend($1, $3); }
8390 : ;
8391 :
8392 :
8393 : index_elem_options:
8394 : opt_collate opt_qualified_name opt_asc_desc opt_nulls_order
8395 : {
8396 10954 : $$ = makeNode(IndexElem);
8397 10954 : $$->name = NULL;
8398 10954 : $$->expr = NULL;
8399 10954 : $$->indexcolname = NULL;
8400 10954 : $$->collation = $1;
8401 10954 : $$->opclass = $2;
8402 10954 : $$->opclassopts = NIL;
8403 10954 : $$->ordering = $3;
8404 10954 : $$->nulls_ordering = $4;
8405 : }
8406 : | opt_collate any_name reloptions opt_asc_desc opt_nulls_order
8407 : {
8408 142 : $$ = makeNode(IndexElem);
8409 142 : $$->name = NULL;
8410 142 : $$->expr = NULL;
8411 142 : $$->indexcolname = NULL;
8412 142 : $$->collation = $1;
8413 142 : $$->opclass = $2;
8414 142 : $$->opclassopts = $3;
8415 142 : $$->ordering = $4;
8416 142 : $$->nulls_ordering = $5;
8417 : }
8418 : ;
8419 :
8420 : /*
8421 : * Index attributes can be either simple column references, or arbitrary
8422 : * expressions in parens. For backwards-compatibility reasons, we allow
8423 : * an expression that's just a function call to be written without parens.
8424 : */
8425 : index_elem: ColId index_elem_options
8426 : {
8427 9960 : $$ = $2;
8428 9960 : $$->name = $1;
8429 : }
8430 : | func_expr_windowless index_elem_options
8431 : {
8432 620 : $$ = $2;
8433 620 : $$->expr = $1;
8434 : }
8435 : | '(' a_expr ')' index_elem_options
8436 : {
8437 516 : $$ = $4;
8438 516 : $$->expr = $2;
8439 : }
8440 : ;
8441 :
8442 218 : opt_include: INCLUDE '(' index_including_params ')' { $$ = $3; }
8443 6482 : | /* EMPTY */ { $$ = NIL; }
8444 : ;
8445 :
8446 218 : index_including_params: index_elem { $$ = list_make1($1); }
8447 166 : | index_including_params ',' index_elem { $$ = lappend($1, $3); }
8448 : ;
8449 :
8450 192 : opt_collate: COLLATE any_name { $$ = $2; }
8451 16526 : | /*EMPTY*/ { $$ = NIL; }
8452 : ;
8453 :
8454 :
8455 1836 : opt_asc_desc: ASC { $$ = SORTBY_ASC; }
8456 3564 : | DESC { $$ = SORTBY_DESC; }
8457 113470 : | /*EMPTY*/ { $$ = SORTBY_DEFAULT; }
8458 : ;
8459 :
8460 344 : opt_nulls_order: NULLS_LA FIRST_P { $$ = SORTBY_NULLS_FIRST; }
8461 1746 : | NULLS_LA LAST_P { $$ = SORTBY_NULLS_LAST; }
8462 117000 : | /*EMPTY*/ { $$ = SORTBY_NULLS_DEFAULT; }
8463 : ;
8464 :
8465 :
8466 : /*****************************************************************************
8467 : *
8468 : * QUERY:
8469 : * create [or replace] function <fname>
8470 : * [(<type-1> { , <type-n>})]
8471 : * returns <type-r>
8472 : * as <filename or code in language as appropriate>
8473 : * language <lang> [with parameters]
8474 : *
8475 : *****************************************************************************/
8476 :
8477 : CreateFunctionStmt:
8478 : CREATE opt_or_replace FUNCTION func_name func_args_with_defaults
8479 : RETURNS func_return opt_createfunc_opt_list opt_routine_body
8480 : {
8481 25138 : CreateFunctionStmt *n = makeNode(CreateFunctionStmt);
8482 :
8483 25138 : n->is_procedure = false;
8484 25138 : n->replace = $2;
8485 25138 : n->funcname = $4;
8486 25138 : n->parameters = $5;
8487 25138 : n->returnType = $7;
8488 25138 : n->options = $8;
8489 25138 : n->sql_body = $9;
8490 25138 : $$ = (Node *) n;
8491 : }
8492 : | CREATE opt_or_replace FUNCTION func_name func_args_with_defaults
8493 : RETURNS TABLE '(' table_func_column_list ')' opt_createfunc_opt_list opt_routine_body
8494 : {
8495 194 : CreateFunctionStmt *n = makeNode(CreateFunctionStmt);
8496 :
8497 194 : n->is_procedure = false;
8498 194 : n->replace = $2;
8499 194 : n->funcname = $4;
8500 194 : n->parameters = mergeTableFuncParameters($5, $9, yyscanner);
8501 194 : n->returnType = TableFuncTypeName($9);
8502 194 : n->returnType->location = @7;
8503 194 : n->options = $11;
8504 194 : n->sql_body = $12;
8505 194 : $$ = (Node *) n;
8506 : }
8507 : | CREATE opt_or_replace FUNCTION func_name func_args_with_defaults
8508 : opt_createfunc_opt_list opt_routine_body
8509 : {
8510 494 : CreateFunctionStmt *n = makeNode(CreateFunctionStmt);
8511 :
8512 494 : n->is_procedure = false;
8513 494 : n->replace = $2;
8514 494 : n->funcname = $4;
8515 494 : n->parameters = $5;
8516 494 : n->returnType = NULL;
8517 494 : n->options = $6;
8518 494 : n->sql_body = $7;
8519 494 : $$ = (Node *) n;
8520 : }
8521 : | CREATE opt_or_replace PROCEDURE func_name func_args_with_defaults
8522 : opt_createfunc_opt_list opt_routine_body
8523 : {
8524 370 : CreateFunctionStmt *n = makeNode(CreateFunctionStmt);
8525 :
8526 370 : n->is_procedure = true;
8527 370 : n->replace = $2;
8528 370 : n->funcname = $4;
8529 370 : n->parameters = $5;
8530 370 : n->returnType = NULL;
8531 370 : n->options = $6;
8532 370 : n->sql_body = $7;
8533 370 : $$ = (Node *) n;
8534 : }
8535 : ;
8536 :
8537 : opt_or_replace:
8538 10118 : OR REPLACE { $$ = true; }
8539 21548 : | /*EMPTY*/ { $$ = false; }
8540 : ;
8541 :
8542 12136 : func_args: '(' func_args_list ')' { $$ = $2; }
8543 5916 : | '(' ')' { $$ = NIL; }
8544 : ;
8545 :
8546 : func_args_list:
8547 12136 : func_arg { $$ = list_make1($1); }
8548 11426 : | func_args_list ',' func_arg { $$ = lappend($1, $3); }
8549 : ;
8550 :
8551 : function_with_argtypes_list:
8552 12802 : function_with_argtypes { $$ = list_make1($1); }
8553 : | function_with_argtypes_list ',' function_with_argtypes
8554 84 : { $$ = lappend($1, $3); }
8555 : ;
8556 :
8557 : function_with_argtypes:
8558 : func_name func_args
8559 : {
8560 18052 : ObjectWithArgs *n = makeNode(ObjectWithArgs);
8561 :
8562 18052 : n->objname = $1;
8563 18052 : n->objargs = extractArgTypes($2);
8564 18052 : n->objfuncargs = $2;
8565 18052 : $$ = n;
8566 : }
8567 : /*
8568 : * Because of reduce/reduce conflicts, we can't use func_name
8569 : * below, but we can write it out the long way, which actually
8570 : * allows more cases.
8571 : */
8572 : | type_func_name_keyword
8573 : {
8574 0 : ObjectWithArgs *n = makeNode(ObjectWithArgs);
8575 :
8576 0 : n->objname = list_make1(makeString(pstrdup($1)));
8577 0 : n->args_unspecified = true;
8578 0 : $$ = n;
8579 : }
8580 : | ColId
8581 : {
8582 422 : ObjectWithArgs *n = makeNode(ObjectWithArgs);
8583 :
8584 422 : n->objname = list_make1(makeString($1));
8585 422 : n->args_unspecified = true;
8586 422 : $$ = n;
8587 : }
8588 : | ColId indirection
8589 : {
8590 28 : ObjectWithArgs *n = makeNode(ObjectWithArgs);
8591 :
8592 28 : n->objname = check_func_name(lcons(makeString($1), $2),
8593 : yyscanner);
8594 28 : n->args_unspecified = true;
8595 28 : $$ = n;
8596 : }
8597 : ;
8598 :
8599 : /*
8600 : * func_args_with_defaults is separate because we only want to accept
8601 : * defaults in CREATE FUNCTION, not in ALTER etc.
8602 : */
8603 : func_args_with_defaults:
8604 21480 : '(' func_args_with_defaults_list ')' { $$ = $2; }
8605 4716 : | '(' ')' { $$ = NIL; }
8606 : ;
8607 :
8608 : func_args_with_defaults_list:
8609 21480 : func_arg_with_default { $$ = list_make1($1); }
8610 : | func_args_with_defaults_list ',' func_arg_with_default
8611 36480 : { $$ = lappend($1, $3); }
8612 : ;
8613 :
8614 : /*
8615 : * The style with arg_class first is SQL99 standard, but Oracle puts
8616 : * param_name first; accept both since it's likely people will try both
8617 : * anyway. Don't bother trying to save productions by letting arg_class
8618 : * have an empty alternative ... you'll get shift/reduce conflicts.
8619 : *
8620 : * We can catch over-specified arguments here if we want to,
8621 : * but for now better to silently swallow typmod, etc.
8622 : * - thomas 2000-03-22
8623 : */
8624 : func_arg:
8625 : arg_class param_name func_type
8626 : {
8627 17764 : FunctionParameter *n = makeNode(FunctionParameter);
8628 :
8629 17764 : n->name = $2;
8630 17764 : n->argType = $3;
8631 17764 : n->mode = $1;
8632 17764 : n->defexpr = NULL;
8633 17764 : n->location = @1;
8634 17764 : $$ = n;
8635 : }
8636 : | param_name arg_class func_type
8637 : {
8638 420 : FunctionParameter *n = makeNode(FunctionParameter);
8639 :
8640 420 : n->name = $1;
8641 420 : n->argType = $3;
8642 420 : n->mode = $2;
8643 420 : n->defexpr = NULL;
8644 420 : n->location = @1;
8645 420 : $$ = n;
8646 : }
8647 : | param_name func_type
8648 : {
8649 15964 : FunctionParameter *n = makeNode(FunctionParameter);
8650 :
8651 15964 : n->name = $1;
8652 15964 : n->argType = $2;
8653 15964 : n->mode = FUNC_PARAM_DEFAULT;
8654 15964 : n->defexpr = NULL;
8655 15964 : n->location = @1;
8656 15964 : $$ = n;
8657 : }
8658 : | arg_class func_type
8659 : {
8660 332 : FunctionParameter *n = makeNode(FunctionParameter);
8661 :
8662 332 : n->name = NULL;
8663 332 : n->argType = $2;
8664 332 : n->mode = $1;
8665 332 : n->defexpr = NULL;
8666 332 : n->location = @1;
8667 332 : $$ = n;
8668 : }
8669 : | func_type
8670 : {
8671 47942 : FunctionParameter *n = makeNode(FunctionParameter);
8672 :
8673 47942 : n->name = NULL;
8674 47942 : n->argType = $1;
8675 47942 : n->mode = FUNC_PARAM_DEFAULT;
8676 47942 : n->defexpr = NULL;
8677 47942 : n->location = @1;
8678 47942 : $$ = n;
8679 : }
8680 : ;
8681 :
8682 : /* INOUT is SQL99 standard, IN OUT is for Oracle compatibility */
8683 4610 : arg_class: IN_P { $$ = FUNC_PARAM_IN; }
8684 13130 : | OUT_P { $$ = FUNC_PARAM_OUT; }
8685 198 : | INOUT { $$ = FUNC_PARAM_INOUT; }
8686 0 : | IN_P OUT_P { $$ = FUNC_PARAM_INOUT; }
8687 578 : | VARIADIC { $$ = FUNC_PARAM_VARIADIC; }
8688 : ;
8689 :
8690 : /*
8691 : * Ideally param_name should be ColId, but that causes too many conflicts.
8692 : */
8693 : param_name: type_function_name
8694 : ;
8695 :
8696 : func_return:
8697 : func_type
8698 : {
8699 : /* We can catch over-specified results here if we want to,
8700 : * but for now better to silently swallow typmod, etc.
8701 : * - thomas 2000-03-22
8702 : */
8703 25138 : $$ = $1;
8704 : }
8705 : ;
8706 :
8707 : /*
8708 : * We would like to make the %TYPE productions here be ColId attrs etc,
8709 : * but that causes reduce/reduce conflicts. type_function_name
8710 : * is next best choice.
8711 : */
8712 128754 : func_type: Typename { $$ = $1; }
8713 : | type_function_name attrs '%' TYPE_P
8714 : {
8715 18 : $$ = makeTypeNameFromNameList(lcons(makeString($1), $2));
8716 18 : $$->pct_type = true;
8717 18 : $$->location = @1;
8718 : }
8719 : | SETOF type_function_name attrs '%' TYPE_P
8720 : {
8721 6 : $$ = makeTypeNameFromNameList(lcons(makeString($2), $3));
8722 6 : $$->pct_type = true;
8723 6 : $$->setof = true;
8724 6 : $$->location = @2;
8725 : }
8726 : ;
8727 :
8728 : func_arg_with_default:
8729 : func_arg
8730 : {
8731 51378 : $$ = $1;
8732 : }
8733 : | func_arg DEFAULT a_expr
8734 : {
8735 6386 : $$ = $1;
8736 6386 : $$->defexpr = $3;
8737 : }
8738 : | func_arg '=' a_expr
8739 : {
8740 196 : $$ = $1;
8741 196 : $$->defexpr = $3;
8742 : }
8743 : ;
8744 :
8745 : /* Aggregate args can be most things that function args can be */
8746 : aggr_arg: func_arg
8747 : {
8748 900 : if (!($1->mode == FUNC_PARAM_DEFAULT ||
8749 60 : $1->mode == FUNC_PARAM_IN ||
8750 60 : $1->mode == FUNC_PARAM_VARIADIC))
8751 0 : ereport(ERROR,
8752 : (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
8753 : errmsg("aggregates cannot have output arguments"),
8754 : parser_errposition(@1)));
8755 900 : $$ = $1;
8756 : }
8757 : ;
8758 :
8759 : /*
8760 : * The SQL standard offers no guidance on how to declare aggregate argument
8761 : * lists, since it doesn't have CREATE AGGREGATE etc. We accept these cases:
8762 : *
8763 : * (*) - normal agg with no args
8764 : * (aggr_arg,...) - normal agg with args
8765 : * (ORDER BY aggr_arg,...) - ordered-set agg with no direct args
8766 : * (aggr_arg,... ORDER BY aggr_arg,...) - ordered-set agg with direct args
8767 : *
8768 : * The zero-argument case is spelled with '*' for consistency with COUNT(*).
8769 : *
8770 : * An additional restriction is that if the direct-args list ends in a
8771 : * VARIADIC item, the ordered-args list must contain exactly one item that
8772 : * is also VARIADIC with the same type. This allows us to collapse the two
8773 : * VARIADIC items into one, which is necessary to represent the aggregate in
8774 : * pg_proc. We check this at the grammar stage so that we can return a list
8775 : * in which the second VARIADIC item is already discarded, avoiding extra work
8776 : * in cases such as DROP AGGREGATE.
8777 : *
8778 : * The return value of this production is a two-element list, in which the
8779 : * first item is a sublist of FunctionParameter nodes (with any duplicate
8780 : * VARIADIC item already dropped, as per above) and the second is an Integer
8781 : * node, containing -1 if there was no ORDER BY and otherwise the number
8782 : * of argument declarations before the ORDER BY. (If this number is equal
8783 : * to the first sublist's length, then we dropped a duplicate VARIADIC item.)
8784 : * This representation is passed as-is to CREATE AGGREGATE; for operations
8785 : * on existing aggregates, we can just apply extractArgTypes to the first
8786 : * sublist.
8787 : */
8788 : aggr_args: '(' '*' ')'
8789 : {
8790 136 : $$ = list_make2(NIL, makeInteger(-1));
8791 : }
8792 : | '(' aggr_args_list ')'
8793 : {
8794 732 : $$ = list_make2($2, makeInteger(-1));
8795 : }
8796 : | '(' ORDER BY aggr_args_list ')'
8797 : {
8798 6 : $$ = list_make2($4, makeInteger(0));
8799 : }
8800 : | '(' aggr_args_list ORDER BY aggr_args_list ')'
8801 : {
8802 : /* this is the only case requiring consistency checking */
8803 32 : $$ = makeOrderedSetArgs($2, $5, yyscanner);
8804 : }
8805 : ;
8806 :
8807 : aggr_args_list:
8808 802 : aggr_arg { $$ = list_make1($1); }
8809 98 : | aggr_args_list ',' aggr_arg { $$ = lappend($1, $3); }
8810 : ;
8811 :
8812 : aggregate_with_argtypes:
8813 : func_name aggr_args
8814 : {
8815 362 : ObjectWithArgs *n = makeNode(ObjectWithArgs);
8816 :
8817 362 : n->objname = $1;
8818 362 : n->objargs = extractAggrArgTypes($2);
8819 362 : n->objfuncargs = (List *) linitial($2);
8820 362 : $$ = n;
8821 : }
8822 : ;
8823 :
8824 : aggregate_with_argtypes_list:
8825 104 : aggregate_with_argtypes { $$ = list_make1($1); }
8826 : | aggregate_with_argtypes_list ',' aggregate_with_argtypes
8827 0 : { $$ = lappend($1, $3); }
8828 : ;
8829 :
8830 : opt_createfunc_opt_list:
8831 : createfunc_opt_list
8832 60 : | /*EMPTY*/ { $$ = NIL; }
8833 : ;
8834 :
8835 : createfunc_opt_list:
8836 : /* Must be at least one to prevent conflict */
8837 26136 : createfunc_opt_item { $$ = list_make1($1); }
8838 69222 : | createfunc_opt_list createfunc_opt_item { $$ = lappend($1, $2); }
8839 : ;
8840 :
8841 : /*
8842 : * Options common to both CREATE FUNCTION and ALTER FUNCTION
8843 : */
8844 : common_func_opt_item:
8845 : CALLED ON NULL_P INPUT_P
8846 : {
8847 404 : $$ = makeDefElem("strict", (Node *) makeBoolean(false), @1);
8848 : }
8849 : | RETURNS NULL_P ON NULL_P INPUT_P
8850 : {
8851 884 : $$ = makeDefElem("strict", (Node *) makeBoolean(true), @1);
8852 : }
8853 : | STRICT_P
8854 : {
8855 14204 : $$ = makeDefElem("strict", (Node *) makeBoolean(true), @1);
8856 : }
8857 : | IMMUTABLE
8858 : {
8859 10202 : $$ = makeDefElem("volatility", (Node *) makeString("immutable"), @1);
8860 : }
8861 : | STABLE
8862 : {
8863 2530 : $$ = makeDefElem("volatility", (Node *) makeString("stable"), @1);
8864 : }
8865 : | VOLATILE
8866 : {
8867 1878 : $$ = makeDefElem("volatility", (Node *) makeString("volatile"), @1);
8868 : }
8869 : | EXTERNAL SECURITY DEFINER
8870 : {
8871 0 : $$ = makeDefElem("security", (Node *) makeBoolean(true), @1);
8872 : }
8873 : | EXTERNAL SECURITY INVOKER
8874 : {
8875 0 : $$ = makeDefElem("security", (Node *) makeBoolean(false), @1);
8876 : }
8877 : | SECURITY DEFINER
8878 : {
8879 58 : $$ = makeDefElem("security", (Node *) makeBoolean(true), @1);
8880 : }
8881 : | SECURITY INVOKER
8882 : {
8883 18 : $$ = makeDefElem("security", (Node *) makeBoolean(false), @1);
8884 : }
8885 : | LEAKPROOF
8886 : {
8887 46 : $$ = makeDefElem("leakproof", (Node *) makeBoolean(true), @1);
8888 : }
8889 : | NOT LEAKPROOF
8890 : {
8891 12 : $$ = makeDefElem("leakproof", (Node *) makeBoolean(false), @1);
8892 : }
8893 : | COST NumericOnly
8894 : {
8895 4360 : $$ = makeDefElem("cost", (Node *) $2, @1);
8896 : }
8897 : | ROWS NumericOnly
8898 : {
8899 600 : $$ = makeDefElem("rows", (Node *) $2, @1);
8900 : }
8901 : | SUPPORT any_name
8902 : {
8903 120 : $$ = makeDefElem("support", (Node *) $2, @1);
8904 : }
8905 : | FunctionSetResetClause
8906 : {
8907 : /* we abuse the normal content of a DefElem here */
8908 154 : $$ = makeDefElem("set", (Node *) $1, @1);
8909 : }
8910 : | PARALLEL ColId
8911 : {
8912 14518 : $$ = makeDefElem("parallel", (Node *) makeString($2), @1);
8913 : }
8914 : ;
8915 :
8916 : createfunc_opt_item:
8917 : AS func_as
8918 : {
8919 20516 : $$ = makeDefElem("as", (Node *) $2, @1);
8920 : }
8921 : | LANGUAGE NonReservedWord_or_Sconst
8922 : {
8923 26116 : $$ = makeDefElem("language", (Node *) makeString($2), @1);
8924 : }
8925 : | TRANSFORM transform_type_list
8926 : {
8927 118 : $$ = makeDefElem("transform", (Node *) $2, @1);
8928 : }
8929 : | WINDOW
8930 : {
8931 20 : $$ = makeDefElem("window", (Node *) makeBoolean(true), @1);
8932 : }
8933 : | common_func_opt_item
8934 : {
8935 48588 : $$ = $1;
8936 : }
8937 : ;
8938 :
8939 16742 : func_as: Sconst { $$ = list_make1(makeString($1)); }
8940 : | Sconst ',' Sconst
8941 : {
8942 3774 : $$ = list_make2(makeString($1), makeString($3));
8943 : }
8944 : ;
8945 :
8946 : ReturnStmt: RETURN a_expr
8947 : {
8948 4884 : ReturnStmt *r = makeNode(ReturnStmt);
8949 :
8950 4884 : r->returnval = (Node *) $2;
8951 4884 : $$ = (Node *) r;
8952 : }
8953 : ;
8954 :
8955 : opt_routine_body:
8956 : ReturnStmt
8957 : {
8958 4878 : $$ = $1;
8959 : }
8960 : | BEGIN_P ATOMIC routine_body_stmt_list END_P
8961 : {
8962 : /*
8963 : * A compound statement is stored as a single-item list
8964 : * containing the list of statements as its member. That
8965 : * way, the parse analysis code can tell apart an empty
8966 : * body from no body at all.
8967 : */
8968 808 : $$ = (Node *) list_make1($3);
8969 : }
8970 : | /*EMPTY*/
8971 : {
8972 20510 : $$ = NULL;
8973 : }
8974 : ;
8975 :
8976 : routine_body_stmt_list:
8977 : routine_body_stmt_list routine_body_stmt ';'
8978 : {
8979 : /* As in stmtmulti, discard empty statements */
8980 824 : if ($2 != NULL)
8981 806 : $$ = lappend($1, $2);
8982 : else
8983 18 : $$ = $1;
8984 : }
8985 : | /*EMPTY*/
8986 : {
8987 808 : $$ = NIL;
8988 : }
8989 : ;
8990 :
8991 : routine_body_stmt:
8992 : stmt
8993 : | ReturnStmt
8994 : ;
8995 :
8996 : transform_type_list:
8997 118 : FOR TYPE_P Typename { $$ = list_make1($3); }
8998 4 : | transform_type_list ',' FOR TYPE_P Typename { $$ = lappend($1, $5); }
8999 : ;
9000 :
9001 : opt_definition:
9002 672 : WITH definition { $$ = $2; }
9003 10320 : | /*EMPTY*/ { $$ = NIL; }
9004 : ;
9005 :
9006 : table_func_column: param_name func_type
9007 : {
9008 454 : FunctionParameter *n = makeNode(FunctionParameter);
9009 :
9010 454 : n->name = $1;
9011 454 : n->argType = $2;
9012 454 : n->mode = FUNC_PARAM_TABLE;
9013 454 : n->defexpr = NULL;
9014 454 : n->location = @1;
9015 454 : $$ = n;
9016 : }
9017 : ;
9018 :
9019 : table_func_column_list:
9020 : table_func_column
9021 : {
9022 194 : $$ = list_make1($1);
9023 : }
9024 : | table_func_column_list ',' table_func_column
9025 : {
9026 260 : $$ = lappend($1, $3);
9027 : }
9028 : ;
9029 :
9030 : /*****************************************************************************
9031 : * ALTER FUNCTION / ALTER PROCEDURE / ALTER ROUTINE
9032 : *
9033 : * RENAME and OWNER subcommands are already provided by the generic
9034 : * ALTER infrastructure, here we just specify alterations that can
9035 : * only be applied to functions.
9036 : *
9037 : *****************************************************************************/
9038 : AlterFunctionStmt:
9039 : ALTER FUNCTION function_with_argtypes alterfunc_opt_list opt_restrict
9040 : {
9041 1378 : AlterFunctionStmt *n = makeNode(AlterFunctionStmt);
9042 :
9043 1378 : n->objtype = OBJECT_FUNCTION;
9044 1378 : n->func = $3;
9045 1378 : n->actions = $4;
9046 1378 : $$ = (Node *) n;
9047 : }
9048 : | ALTER PROCEDURE function_with_argtypes alterfunc_opt_list opt_restrict
9049 : {
9050 18 : AlterFunctionStmt *n = makeNode(AlterFunctionStmt);
9051 :
9052 18 : n->objtype = OBJECT_PROCEDURE;
9053 18 : n->func = $3;
9054 18 : n->actions = $4;
9055 18 : $$ = (Node *) n;
9056 : }
9057 : | ALTER ROUTINE function_with_argtypes alterfunc_opt_list opt_restrict
9058 : {
9059 0 : AlterFunctionStmt *n = makeNode(AlterFunctionStmt);
9060 :
9061 0 : n->objtype = OBJECT_ROUTINE;
9062 0 : n->func = $3;
9063 0 : n->actions = $4;
9064 0 : $$ = (Node *) n;
9065 : }
9066 : ;
9067 :
9068 : alterfunc_opt_list:
9069 : /* At least one option must be specified */
9070 1396 : common_func_opt_item { $$ = list_make1($1); }
9071 4 : | alterfunc_opt_list common_func_opt_item { $$ = lappend($1, $2); }
9072 : ;
9073 :
9074 : /* Ignored, merely for SQL compliance */
9075 : opt_restrict:
9076 : RESTRICT
9077 : | /* EMPTY */
9078 : ;
9079 :
9080 :
9081 : /*****************************************************************************
9082 : *
9083 : * QUERY:
9084 : *
9085 : * DROP FUNCTION funcname (arg1, arg2, ...) [ RESTRICT | CASCADE ]
9086 : * DROP PROCEDURE procname (arg1, arg2, ...) [ RESTRICT | CASCADE ]
9087 : * DROP ROUTINE routname (arg1, arg2, ...) [ RESTRICT | CASCADE ]
9088 : * DROP AGGREGATE aggname (arg1, ...) [ RESTRICT | CASCADE ]
9089 : * DROP OPERATOR opname (leftoperand_typ, rightoperand_typ) [ RESTRICT | CASCADE ]
9090 : *
9091 : *****************************************************************************/
9092 :
9093 : RemoveFuncStmt:
9094 : DROP FUNCTION function_with_argtypes_list opt_drop_behavior
9095 : {
9096 3392 : DropStmt *n = makeNode(DropStmt);
9097 :
9098 3392 : n->removeType = OBJECT_FUNCTION;
9099 3392 : n->objects = $3;
9100 3392 : n->behavior = $4;
9101 3392 : n->missing_ok = false;
9102 3392 : n->concurrent = false;
9103 3392 : $$ = (Node *) n;
9104 : }
9105 : | DROP FUNCTION IF_P EXISTS function_with_argtypes_list opt_drop_behavior
9106 : {
9107 260 : DropStmt *n = makeNode(DropStmt);
9108 :
9109 260 : n->removeType = OBJECT_FUNCTION;
9110 260 : n->objects = $5;
9111 260 : n->behavior = $6;
9112 260 : n->missing_ok = true;
9113 260 : n->concurrent = false;
9114 260 : $$ = (Node *) n;
9115 : }
9116 : | DROP PROCEDURE function_with_argtypes_list opt_drop_behavior
9117 : {
9118 140 : DropStmt *n = makeNode(DropStmt);
9119 :
9120 140 : n->removeType = OBJECT_PROCEDURE;
9121 140 : n->objects = $3;
9122 140 : n->behavior = $4;
9123 140 : n->missing_ok = false;
9124 140 : n->concurrent = false;
9125 140 : $$ = (Node *) n;
9126 : }
9127 : | DROP PROCEDURE IF_P EXISTS function_with_argtypes_list opt_drop_behavior
9128 : {
9129 6 : DropStmt *n = makeNode(DropStmt);
9130 :
9131 6 : n->removeType = OBJECT_PROCEDURE;
9132 6 : n->objects = $5;
9133 6 : n->behavior = $6;
9134 6 : n->missing_ok = true;
9135 6 : n->concurrent = false;
9136 6 : $$ = (Node *) n;
9137 : }
9138 : | DROP ROUTINE function_with_argtypes_list opt_drop_behavior
9139 : {
9140 12 : DropStmt *n = makeNode(DropStmt);
9141 :
9142 12 : n->removeType = OBJECT_ROUTINE;
9143 12 : n->objects = $3;
9144 12 : n->behavior = $4;
9145 12 : n->missing_ok = false;
9146 12 : n->concurrent = false;
9147 12 : $$ = (Node *) n;
9148 : }
9149 : | DROP ROUTINE IF_P EXISTS function_with_argtypes_list opt_drop_behavior
9150 : {
9151 6 : DropStmt *n = makeNode(DropStmt);
9152 :
9153 6 : n->removeType = OBJECT_ROUTINE;
9154 6 : n->objects = $5;
9155 6 : n->behavior = $6;
9156 6 : n->missing_ok = true;
9157 6 : n->concurrent = false;
9158 6 : $$ = (Node *) n;
9159 : }
9160 : ;
9161 :
9162 : RemoveAggrStmt:
9163 : DROP AGGREGATE aggregate_with_argtypes_list opt_drop_behavior
9164 : {
9165 74 : DropStmt *n = makeNode(DropStmt);
9166 :
9167 74 : n->removeType = OBJECT_AGGREGATE;
9168 74 : n->objects = $3;
9169 74 : n->behavior = $4;
9170 74 : n->missing_ok = false;
9171 74 : n->concurrent = false;
9172 74 : $$ = (Node *) n;
9173 : }
9174 : | DROP AGGREGATE IF_P EXISTS aggregate_with_argtypes_list opt_drop_behavior
9175 : {
9176 30 : DropStmt *n = makeNode(DropStmt);
9177 :
9178 30 : n->removeType = OBJECT_AGGREGATE;
9179 30 : n->objects = $5;
9180 30 : n->behavior = $6;
9181 30 : n->missing_ok = true;
9182 30 : n->concurrent = false;
9183 30 : $$ = (Node *) n;
9184 : }
9185 : ;
9186 :
9187 : RemoveOperStmt:
9188 : DROP OPERATOR operator_with_argtypes_list opt_drop_behavior
9189 : {
9190 200 : DropStmt *n = makeNode(DropStmt);
9191 :
9192 200 : n->removeType = OBJECT_OPERATOR;
9193 200 : n->objects = $3;
9194 200 : n->behavior = $4;
9195 200 : n->missing_ok = false;
9196 200 : n->concurrent = false;
9197 200 : $$ = (Node *) n;
9198 : }
9199 : | DROP OPERATOR IF_P EXISTS operator_with_argtypes_list opt_drop_behavior
9200 : {
9201 30 : DropStmt *n = makeNode(DropStmt);
9202 :
9203 30 : n->removeType = OBJECT_OPERATOR;
9204 30 : n->objects = $5;
9205 30 : n->behavior = $6;
9206 30 : n->missing_ok = true;
9207 30 : n->concurrent = false;
9208 30 : $$ = (Node *) n;
9209 : }
9210 : ;
9211 :
9212 : oper_argtypes:
9213 : '(' Typename ')'
9214 : {
9215 12 : ereport(ERROR,
9216 : (errcode(ERRCODE_SYNTAX_ERROR),
9217 : errmsg("missing argument"),
9218 : errhint("Use NONE to denote the missing argument of a unary operator."),
9219 : parser_errposition(@3)));
9220 : }
9221 : | '(' Typename ',' Typename ')'
9222 2464 : { $$ = list_make2($2, $4); }
9223 : | '(' NONE ',' Typename ')' /* left unary */
9224 32 : { $$ = list_make2(NULL, $4); }
9225 : | '(' Typename ',' NONE ')' /* right unary */
9226 12 : { $$ = list_make2($2, NULL); }
9227 : ;
9228 :
9229 : any_operator:
9230 : all_Op
9231 22550 : { $$ = list_make1(makeString($1)); }
9232 : | ColId '.' any_operator
9233 16300 : { $$ = lcons(makeString($1), $3); }
9234 : ;
9235 :
9236 : operator_with_argtypes_list:
9237 230 : operator_with_argtypes { $$ = list_make1($1); }
9238 : | operator_with_argtypes_list ',' operator_with_argtypes
9239 0 : { $$ = lappend($1, $3); }
9240 : ;
9241 :
9242 : operator_with_argtypes:
9243 : any_operator oper_argtypes
9244 : {
9245 2508 : ObjectWithArgs *n = makeNode(ObjectWithArgs);
9246 :
9247 2508 : n->objname = $1;
9248 2508 : n->objargs = $2;
9249 2508 : $$ = n;
9250 : }
9251 : ;
9252 :
9253 : /*****************************************************************************
9254 : *
9255 : * DO <anonymous code block> [ LANGUAGE language ]
9256 : *
9257 : * We use a DefElem list for future extensibility, and to allow flexibility
9258 : * in the clause order.
9259 : *
9260 : *****************************************************************************/
9261 :
9262 : DoStmt: DO dostmt_opt_list
9263 : {
9264 1154 : DoStmt *n = makeNode(DoStmt);
9265 :
9266 1154 : n->args = $2;
9267 1154 : $$ = (Node *) n;
9268 : }
9269 : ;
9270 :
9271 : dostmt_opt_list:
9272 1154 : dostmt_opt_item { $$ = list_make1($1); }
9273 198 : | dostmt_opt_list dostmt_opt_item { $$ = lappend($1, $2); }
9274 : ;
9275 :
9276 : dostmt_opt_item:
9277 : Sconst
9278 : {
9279 1154 : $$ = makeDefElem("as", (Node *) makeString($1), @1);
9280 : }
9281 : | LANGUAGE NonReservedWord_or_Sconst
9282 : {
9283 198 : $$ = makeDefElem("language", (Node *) makeString($2), @1);
9284 : }
9285 : ;
9286 :
9287 : /*****************************************************************************
9288 : *
9289 : * CREATE CAST / DROP CAST
9290 : *
9291 : *****************************************************************************/
9292 :
9293 : CreateCastStmt: CREATE CAST '(' Typename AS Typename ')'
9294 : WITH FUNCTION function_with_argtypes cast_context
9295 : {
9296 108 : CreateCastStmt *n = makeNode(CreateCastStmt);
9297 :
9298 108 : n->sourcetype = $4;
9299 108 : n->targettype = $6;
9300 108 : n->func = $10;
9301 108 : n->context = (CoercionContext) $11;
9302 108 : n->inout = false;
9303 108 : $$ = (Node *) n;
9304 : }
9305 : | CREATE CAST '(' Typename AS Typename ')'
9306 : WITHOUT FUNCTION cast_context
9307 : {
9308 162 : CreateCastStmt *n = makeNode(CreateCastStmt);
9309 :
9310 162 : n->sourcetype = $4;
9311 162 : n->targettype = $6;
9312 162 : n->func = NULL;
9313 162 : n->context = (CoercionContext) $10;
9314 162 : n->inout = false;
9315 162 : $$ = (Node *) n;
9316 : }
9317 : | CREATE CAST '(' Typename AS Typename ')'
9318 : WITH INOUT cast_context
9319 : {
9320 8 : CreateCastStmt *n = makeNode(CreateCastStmt);
9321 :
9322 8 : n->sourcetype = $4;
9323 8 : n->targettype = $6;
9324 8 : n->func = NULL;
9325 8 : n->context = (CoercionContext) $10;
9326 8 : n->inout = true;
9327 8 : $$ = (Node *) n;
9328 : }
9329 : ;
9330 :
9331 36 : cast_context: AS IMPLICIT_P { $$ = COERCION_IMPLICIT; }
9332 58 : | AS ASSIGNMENT { $$ = COERCION_ASSIGNMENT; }
9333 184 : | /*EMPTY*/ { $$ = COERCION_EXPLICIT; }
9334 : ;
9335 :
9336 :
9337 : DropCastStmt: DROP CAST opt_if_exists '(' Typename AS Typename ')' opt_drop_behavior
9338 : {
9339 60 : DropStmt *n = makeNode(DropStmt);
9340 :
9341 60 : n->removeType = OBJECT_CAST;
9342 60 : n->objects = list_make1(list_make2($5, $7));
9343 60 : n->behavior = $9;
9344 60 : n->missing_ok = $3;
9345 60 : n->concurrent = false;
9346 60 : $$ = (Node *) n;
9347 : }
9348 : ;
9349 :
9350 36 : opt_if_exists: IF_P EXISTS { $$ = true; }
9351 38 : | /*EMPTY*/ { $$ = false; }
9352 : ;
9353 :
9354 :
9355 : /*****************************************************************************
9356 : *
9357 : * CREATE TRANSFORM / DROP TRANSFORM
9358 : *
9359 : *****************************************************************************/
9360 :
9361 : CreateTransformStmt: CREATE opt_or_replace TRANSFORM FOR Typename LANGUAGE name '(' transform_element_list ')'
9362 : {
9363 50 : CreateTransformStmt *n = makeNode(CreateTransformStmt);
9364 :
9365 50 : n->replace = $2;
9366 50 : n->type_name = $5;
9367 50 : n->lang = $7;
9368 50 : n->fromsql = linitial($9);
9369 50 : n->tosql = lsecond($9);
9370 50 : $$ = (Node *) n;
9371 : }
9372 : ;
9373 :
9374 : transform_element_list: FROM SQL_P WITH FUNCTION function_with_argtypes ',' TO SQL_P WITH FUNCTION function_with_argtypes
9375 : {
9376 44 : $$ = list_make2($5, $11);
9377 : }
9378 : | TO SQL_P WITH FUNCTION function_with_argtypes ',' FROM SQL_P WITH FUNCTION function_with_argtypes
9379 : {
9380 0 : $$ = list_make2($11, $5);
9381 : }
9382 : | FROM SQL_P WITH FUNCTION function_with_argtypes
9383 : {
9384 4 : $$ = list_make2($5, NULL);
9385 : }
9386 : | TO SQL_P WITH FUNCTION function_with_argtypes
9387 : {
9388 2 : $$ = list_make2(NULL, $5);
9389 : }
9390 : ;
9391 :
9392 :
9393 : DropTransformStmt: DROP TRANSFORM opt_if_exists FOR Typename LANGUAGE name opt_drop_behavior
9394 : {
9395 14 : DropStmt *n = makeNode(DropStmt);
9396 :
9397 14 : n->removeType = OBJECT_TRANSFORM;
9398 14 : n->objects = list_make1(list_make2($5, makeString($7)));
9399 14 : n->behavior = $8;
9400 14 : n->missing_ok = $3;
9401 14 : $$ = (Node *) n;
9402 : }
9403 : ;
9404 :
9405 :
9406 : /*****************************************************************************
9407 : *
9408 : * QUERY:
9409 : *
9410 : * REINDEX [ (options) ] {INDEX | TABLE | SCHEMA} [CONCURRENTLY] <name>
9411 : * REINDEX [ (options) ] {DATABASE | SYSTEM} [CONCURRENTLY] [<name>]
9412 : *****************************************************************************/
9413 :
9414 : ReindexStmt:
9415 : REINDEX opt_utility_option_list reindex_target_relation opt_concurrently qualified_name
9416 : {
9417 946 : ReindexStmt *n = makeNode(ReindexStmt);
9418 :
9419 946 : n->kind = $3;
9420 946 : n->relation = $5;
9421 946 : n->name = NULL;
9422 946 : n->params = $2;
9423 946 : if ($4)
9424 542 : n->params = lappend(n->params,
9425 542 : makeDefElem("concurrently", NULL, @4));
9426 946 : $$ = (Node *) n;
9427 : }
9428 : | REINDEX opt_utility_option_list SCHEMA opt_concurrently name
9429 : {
9430 114 : ReindexStmt *n = makeNode(ReindexStmt);
9431 :
9432 114 : n->kind = REINDEX_OBJECT_SCHEMA;
9433 114 : n->relation = NULL;
9434 114 : n->name = $5;
9435 114 : n->params = $2;
9436 114 : if ($4)
9437 40 : n->params = lappend(n->params,
9438 40 : makeDefElem("concurrently", NULL, @4));
9439 114 : $$ = (Node *) n;
9440 : }
9441 : | REINDEX opt_utility_option_list reindex_target_all opt_concurrently opt_single_name
9442 : {
9443 66 : ReindexStmt *n = makeNode(ReindexStmt);
9444 :
9445 66 : n->kind = $3;
9446 66 : n->relation = NULL;
9447 66 : n->name = $5;
9448 66 : n->params = $2;
9449 66 : if ($4)
9450 10 : n->params = lappend(n->params,
9451 10 : makeDefElem("concurrently", NULL, @4));
9452 66 : $$ = (Node *) n;
9453 : }
9454 : ;
9455 : reindex_target_relation:
9456 418 : INDEX { $$ = REINDEX_OBJECT_INDEX; }
9457 528 : | TABLE { $$ = REINDEX_OBJECT_TABLE; }
9458 : ;
9459 : reindex_target_all:
9460 34 : SYSTEM_P { $$ = REINDEX_OBJECT_SYSTEM; }
9461 32 : | DATABASE { $$ = REINDEX_OBJECT_DATABASE; }
9462 : ;
9463 :
9464 : /*****************************************************************************
9465 : *
9466 : * ALTER TABLESPACE
9467 : *
9468 : *****************************************************************************/
9469 :
9470 : AlterTblSpcStmt:
9471 : ALTER TABLESPACE name SET reloptions
9472 : {
9473 : AlterTableSpaceOptionsStmt *n =
9474 12 : makeNode(AlterTableSpaceOptionsStmt);
9475 :
9476 12 : n->tablespacename = $3;
9477 12 : n->options = $5;
9478 12 : n->isReset = false;
9479 12 : $$ = (Node *) n;
9480 : }
9481 : | ALTER TABLESPACE name RESET reloptions
9482 : {
9483 : AlterTableSpaceOptionsStmt *n =
9484 12 : makeNode(AlterTableSpaceOptionsStmt);
9485 :
9486 12 : n->tablespacename = $3;
9487 12 : n->options = $5;
9488 12 : n->isReset = true;
9489 12 : $$ = (Node *) n;
9490 : }
9491 : ;
9492 :
9493 : /*****************************************************************************
9494 : *
9495 : * ALTER THING name RENAME TO newname
9496 : *
9497 : *****************************************************************************/
9498 :
9499 : RenameStmt: ALTER AGGREGATE aggregate_with_argtypes RENAME TO name
9500 : {
9501 42 : RenameStmt *n = makeNode(RenameStmt);
9502 :
9503 42 : n->renameType = OBJECT_AGGREGATE;
9504 42 : n->object = (Node *) $3;
9505 42 : n->newname = $6;
9506 42 : n->missing_ok = false;
9507 42 : $$ = (Node *) n;
9508 : }
9509 : | ALTER COLLATION any_name RENAME TO name
9510 : {
9511 18 : RenameStmt *n = makeNode(RenameStmt);
9512 :
9513 18 : n->renameType = OBJECT_COLLATION;
9514 18 : n->object = (Node *) $3;
9515 18 : n->newname = $6;
9516 18 : n->missing_ok = false;
9517 18 : $$ = (Node *) n;
9518 : }
9519 : | ALTER CONVERSION_P any_name RENAME TO name
9520 : {
9521 24 : RenameStmt *n = makeNode(RenameStmt);
9522 :
9523 24 : n->renameType = OBJECT_CONVERSION;
9524 24 : n->object = (Node *) $3;
9525 24 : n->newname = $6;
9526 24 : n->missing_ok = false;
9527 24 : $$ = (Node *) n;
9528 : }
9529 : | ALTER DATABASE name RENAME TO name
9530 : {
9531 12 : RenameStmt *n = makeNode(RenameStmt);
9532 :
9533 12 : n->renameType = OBJECT_DATABASE;
9534 12 : n->subname = $3;
9535 12 : n->newname = $6;
9536 12 : n->missing_ok = false;
9537 12 : $$ = (Node *) n;
9538 : }
9539 : | ALTER DOMAIN_P any_name RENAME TO name
9540 : {
9541 6 : RenameStmt *n = makeNode(RenameStmt);
9542 :
9543 6 : n->renameType = OBJECT_DOMAIN;
9544 6 : n->object = (Node *) $3;
9545 6 : n->newname = $6;
9546 6 : n->missing_ok = false;
9547 6 : $$ = (Node *) n;
9548 : }
9549 : | ALTER DOMAIN_P any_name RENAME CONSTRAINT name TO name
9550 : {
9551 6 : RenameStmt *n = makeNode(RenameStmt);
9552 :
9553 6 : n->renameType = OBJECT_DOMCONSTRAINT;
9554 6 : n->object = (Node *) $3;
9555 6 : n->subname = $6;
9556 6 : n->newname = $8;
9557 6 : $$ = (Node *) n;
9558 : }
9559 : | ALTER FOREIGN DATA_P WRAPPER name RENAME TO name
9560 : {
9561 24 : RenameStmt *n = makeNode(RenameStmt);
9562 :
9563 24 : n->renameType = OBJECT_FDW;
9564 24 : n->object = (Node *) makeString($5);
9565 24 : n->newname = $8;
9566 24 : n->missing_ok = false;
9567 24 : $$ = (Node *) n;
9568 : }
9569 : | ALTER FUNCTION function_with_argtypes RENAME TO name
9570 : {
9571 24 : RenameStmt *n = makeNode(RenameStmt);
9572 :
9573 24 : n->renameType = OBJECT_FUNCTION;
9574 24 : n->object = (Node *) $3;
9575 24 : n->newname = $6;
9576 24 : n->missing_ok = false;
9577 24 : $$ = (Node *) n;
9578 : }
9579 : | ALTER GROUP_P RoleId RENAME TO RoleId
9580 : {
9581 0 : RenameStmt *n = makeNode(RenameStmt);
9582 :
9583 0 : n->renameType = OBJECT_ROLE;
9584 0 : n->subname = $3;
9585 0 : n->newname = $6;
9586 0 : n->missing_ok = false;
9587 0 : $$ = (Node *) n;
9588 : }
9589 : | ALTER opt_procedural LANGUAGE name RENAME TO name
9590 : {
9591 18 : RenameStmt *n = makeNode(RenameStmt);
9592 :
9593 18 : n->renameType = OBJECT_LANGUAGE;
9594 18 : n->object = (Node *) makeString($4);
9595 18 : n->newname = $7;
9596 18 : n->missing_ok = false;
9597 18 : $$ = (Node *) n;
9598 : }
9599 : | ALTER OPERATOR CLASS any_name USING name RENAME TO name
9600 : {
9601 24 : RenameStmt *n = makeNode(RenameStmt);
9602 :
9603 24 : n->renameType = OBJECT_OPCLASS;
9604 24 : n->object = (Node *) lcons(makeString($6), $4);
9605 24 : n->newname = $9;
9606 24 : n->missing_ok = false;
9607 24 : $$ = (Node *) n;
9608 : }
9609 : | ALTER OPERATOR FAMILY any_name USING name RENAME TO name
9610 : {
9611 24 : RenameStmt *n = makeNode(RenameStmt);
9612 :
9613 24 : n->renameType = OBJECT_OPFAMILY;
9614 24 : n->object = (Node *) lcons(makeString($6), $4);
9615 24 : n->newname = $9;
9616 24 : n->missing_ok = false;
9617 24 : $$ = (Node *) n;
9618 : }
9619 : | ALTER POLICY name ON qualified_name RENAME TO name
9620 : {
9621 18 : RenameStmt *n = makeNode(RenameStmt);
9622 :
9623 18 : n->renameType = OBJECT_POLICY;
9624 18 : n->relation = $5;
9625 18 : n->subname = $3;
9626 18 : n->newname = $8;
9627 18 : n->missing_ok = false;
9628 18 : $$ = (Node *) n;
9629 : }
9630 : | ALTER POLICY IF_P EXISTS name ON qualified_name RENAME TO name
9631 : {
9632 0 : RenameStmt *n = makeNode(RenameStmt);
9633 :
9634 0 : n->renameType = OBJECT_POLICY;
9635 0 : n->relation = $7;
9636 0 : n->subname = $5;
9637 0 : n->newname = $10;
9638 0 : n->missing_ok = true;
9639 0 : $$ = (Node *) n;
9640 : }
9641 : | ALTER PROCEDURE function_with_argtypes RENAME TO name
9642 : {
9643 0 : RenameStmt *n = makeNode(RenameStmt);
9644 :
9645 0 : n->renameType = OBJECT_PROCEDURE;
9646 0 : n->object = (Node *) $3;
9647 0 : n->newname = $6;
9648 0 : n->missing_ok = false;
9649 0 : $$ = (Node *) n;
9650 : }
9651 : | ALTER PUBLICATION name RENAME TO name
9652 : {
9653 42 : RenameStmt *n = makeNode(RenameStmt);
9654 :
9655 42 : n->renameType = OBJECT_PUBLICATION;
9656 42 : n->object = (Node *) makeString($3);
9657 42 : n->newname = $6;
9658 42 : n->missing_ok = false;
9659 42 : $$ = (Node *) n;
9660 : }
9661 : | ALTER ROUTINE function_with_argtypes RENAME TO name
9662 : {
9663 24 : RenameStmt *n = makeNode(RenameStmt);
9664 :
9665 24 : n->renameType = OBJECT_ROUTINE;
9666 24 : n->object = (Node *) $3;
9667 24 : n->newname = $6;
9668 24 : n->missing_ok = false;
9669 24 : $$ = (Node *) n;
9670 : }
9671 : | ALTER SCHEMA name RENAME TO name
9672 : {
9673 20 : RenameStmt *n = makeNode(RenameStmt);
9674 :
9675 20 : n->renameType = OBJECT_SCHEMA;
9676 20 : n->subname = $3;
9677 20 : n->newname = $6;
9678 20 : n->missing_ok = false;
9679 20 : $$ = (Node *) n;
9680 : }
9681 : | ALTER SERVER name RENAME TO name
9682 : {
9683 24 : RenameStmt *n = makeNode(RenameStmt);
9684 :
9685 24 : n->renameType = OBJECT_FOREIGN_SERVER;
9686 24 : n->object = (Node *) makeString($3);
9687 24 : n->newname = $6;
9688 24 : n->missing_ok = false;
9689 24 : $$ = (Node *) n;
9690 : }
9691 : | ALTER SUBSCRIPTION name RENAME TO name
9692 : {
9693 38 : RenameStmt *n = makeNode(RenameStmt);
9694 :
9695 38 : n->renameType = OBJECT_SUBSCRIPTION;
9696 38 : n->object = (Node *) makeString($3);
9697 38 : n->newname = $6;
9698 38 : n->missing_ok = false;
9699 38 : $$ = (Node *) n;
9700 : }
9701 : | ALTER TABLE relation_expr RENAME TO name
9702 : {
9703 288 : RenameStmt *n = makeNode(RenameStmt);
9704 :
9705 288 : n->renameType = OBJECT_TABLE;
9706 288 : n->relation = $3;
9707 288 : n->subname = NULL;
9708 288 : n->newname = $6;
9709 288 : n->missing_ok = false;
9710 288 : $$ = (Node *) n;
9711 : }
9712 : | ALTER TABLE IF_P EXISTS relation_expr RENAME TO name
9713 : {
9714 0 : RenameStmt *n = makeNode(RenameStmt);
9715 :
9716 0 : n->renameType = OBJECT_TABLE;
9717 0 : n->relation = $5;
9718 0 : n->subname = NULL;
9719 0 : n->newname = $8;
9720 0 : n->missing_ok = true;
9721 0 : $$ = (Node *) n;
9722 : }
9723 : | ALTER SEQUENCE qualified_name RENAME TO name
9724 : {
9725 2 : RenameStmt *n = makeNode(RenameStmt);
9726 :
9727 2 : n->renameType = OBJECT_SEQUENCE;
9728 2 : n->relation = $3;
9729 2 : n->subname = NULL;
9730 2 : n->newname = $6;
9731 2 : n->missing_ok = false;
9732 2 : $$ = (Node *) n;
9733 : }
9734 : | ALTER SEQUENCE IF_P EXISTS qualified_name RENAME TO name
9735 : {
9736 0 : RenameStmt *n = makeNode(RenameStmt);
9737 :
9738 0 : n->renameType = OBJECT_SEQUENCE;
9739 0 : n->relation = $5;
9740 0 : n->subname = NULL;
9741 0 : n->newname = $8;
9742 0 : n->missing_ok = true;
9743 0 : $$ = (Node *) n;
9744 : }
9745 : | ALTER VIEW qualified_name RENAME TO name
9746 : {
9747 6 : RenameStmt *n = makeNode(RenameStmt);
9748 :
9749 6 : n->renameType = OBJECT_VIEW;
9750 6 : n->relation = $3;
9751 6 : n->subname = NULL;
9752 6 : n->newname = $6;
9753 6 : n->missing_ok = false;
9754 6 : $$ = (Node *) n;
9755 : }
9756 : | ALTER VIEW IF_P EXISTS qualified_name RENAME TO name
9757 : {
9758 0 : RenameStmt *n = makeNode(RenameStmt);
9759 :
9760 0 : n->renameType = OBJECT_VIEW;
9761 0 : n->relation = $5;
9762 0 : n->subname = NULL;
9763 0 : n->newname = $8;
9764 0 : n->missing_ok = true;
9765 0 : $$ = (Node *) n;
9766 : }
9767 : | ALTER MATERIALIZED VIEW qualified_name RENAME TO name
9768 : {
9769 0 : RenameStmt *n = makeNode(RenameStmt);
9770 :
9771 0 : n->renameType = OBJECT_MATVIEW;
9772 0 : n->relation = $4;
9773 0 : n->subname = NULL;
9774 0 : n->newname = $7;
9775 0 : n->missing_ok = false;
9776 0 : $$ = (Node *) n;
9777 : }
9778 : | ALTER MATERIALIZED VIEW IF_P EXISTS qualified_name RENAME TO name
9779 : {
9780 0 : RenameStmt *n = makeNode(RenameStmt);
9781 :
9782 0 : n->renameType = OBJECT_MATVIEW;
9783 0 : n->relation = $6;
9784 0 : n->subname = NULL;
9785 0 : n->newname = $9;
9786 0 : n->missing_ok = true;
9787 0 : $$ = (Node *) n;
9788 : }
9789 : | ALTER INDEX qualified_name RENAME TO name
9790 : {
9791 192 : RenameStmt *n = makeNode(RenameStmt);
9792 :
9793 192 : n->renameType = OBJECT_INDEX;
9794 192 : n->relation = $3;
9795 192 : n->subname = NULL;
9796 192 : n->newname = $6;
9797 192 : n->missing_ok = false;
9798 192 : $$ = (Node *) n;
9799 : }
9800 : | ALTER INDEX IF_P EXISTS qualified_name RENAME TO name
9801 : {
9802 12 : RenameStmt *n = makeNode(RenameStmt);
9803 :
9804 12 : n->renameType = OBJECT_INDEX;
9805 12 : n->relation = $5;
9806 12 : n->subname = NULL;
9807 12 : n->newname = $8;
9808 12 : n->missing_ok = true;
9809 12 : $$ = (Node *) n;
9810 : }
9811 : | ALTER FOREIGN TABLE relation_expr RENAME TO name
9812 : {
9813 6 : RenameStmt *n = makeNode(RenameStmt);
9814 :
9815 6 : n->renameType = OBJECT_FOREIGN_TABLE;
9816 6 : n->relation = $4;
9817 6 : n->subname = NULL;
9818 6 : n->newname = $7;
9819 6 : n->missing_ok = false;
9820 6 : $$ = (Node *) n;
9821 : }
9822 : | ALTER FOREIGN TABLE IF_P EXISTS relation_expr RENAME TO name
9823 : {
9824 6 : RenameStmt *n = makeNode(RenameStmt);
9825 :
9826 6 : n->renameType = OBJECT_FOREIGN_TABLE;
9827 6 : n->relation = $6;
9828 6 : n->subname = NULL;
9829 6 : n->newname = $9;
9830 6 : n->missing_ok = true;
9831 6 : $$ = (Node *) n;
9832 : }
9833 : | ALTER TABLE relation_expr RENAME opt_column name TO name
9834 : {
9835 238 : RenameStmt *n = makeNode(RenameStmt);
9836 :
9837 238 : n->renameType = OBJECT_COLUMN;
9838 238 : n->relationType = OBJECT_TABLE;
9839 238 : n->relation = $3;
9840 238 : n->subname = $6;
9841 238 : n->newname = $8;
9842 238 : n->missing_ok = false;
9843 238 : $$ = (Node *) n;
9844 : }
9845 : | ALTER TABLE IF_P EXISTS relation_expr RENAME opt_column name TO name
9846 : {
9847 24 : RenameStmt *n = makeNode(RenameStmt);
9848 :
9849 24 : n->renameType = OBJECT_COLUMN;
9850 24 : n->relationType = OBJECT_TABLE;
9851 24 : n->relation = $5;
9852 24 : n->subname = $8;
9853 24 : n->newname = $10;
9854 24 : n->missing_ok = true;
9855 24 : $$ = (Node *) n;
9856 : }
9857 : | ALTER VIEW qualified_name RENAME opt_column name TO name
9858 : {
9859 18 : RenameStmt *n = makeNode(RenameStmt);
9860 :
9861 18 : n->renameType = OBJECT_COLUMN;
9862 18 : n->relationType = OBJECT_VIEW;
9863 18 : n->relation = $3;
9864 18 : n->subname = $6;
9865 18 : n->newname = $8;
9866 18 : n->missing_ok = false;
9867 18 : $$ = (Node *) n;
9868 : }
9869 : | ALTER VIEW IF_P EXISTS qualified_name RENAME opt_column name TO name
9870 : {
9871 0 : RenameStmt *n = makeNode(RenameStmt);
9872 :
9873 0 : n->renameType = OBJECT_COLUMN;
9874 0 : n->relationType = OBJECT_VIEW;
9875 0 : n->relation = $5;
9876 0 : n->subname = $8;
9877 0 : n->newname = $10;
9878 0 : n->missing_ok = true;
9879 0 : $$ = (Node *) n;
9880 : }
9881 : | ALTER MATERIALIZED VIEW qualified_name RENAME opt_column name TO name
9882 : {
9883 0 : RenameStmt *n = makeNode(RenameStmt);
9884 :
9885 0 : n->renameType = OBJECT_COLUMN;
9886 0 : n->relationType = OBJECT_MATVIEW;
9887 0 : n->relation = $4;
9888 0 : n->subname = $7;
9889 0 : n->newname = $9;
9890 0 : n->missing_ok = false;
9891 0 : $$ = (Node *) n;
9892 : }
9893 : | ALTER MATERIALIZED VIEW IF_P EXISTS qualified_name RENAME opt_column name TO name
9894 : {
9895 0 : RenameStmt *n = makeNode(RenameStmt);
9896 :
9897 0 : n->renameType = OBJECT_COLUMN;
9898 0 : n->relationType = OBJECT_MATVIEW;
9899 0 : n->relation = $6;
9900 0 : n->subname = $9;
9901 0 : n->newname = $11;
9902 0 : n->missing_ok = true;
9903 0 : $$ = (Node *) n;
9904 : }
9905 : | ALTER TABLE relation_expr RENAME CONSTRAINT name TO name
9906 : {
9907 72 : RenameStmt *n = makeNode(RenameStmt);
9908 :
9909 72 : n->renameType = OBJECT_TABCONSTRAINT;
9910 72 : n->relation = $3;
9911 72 : n->subname = $6;
9912 72 : n->newname = $8;
9913 72 : n->missing_ok = false;
9914 72 : $$ = (Node *) n;
9915 : }
9916 : | ALTER TABLE IF_P EXISTS relation_expr RENAME CONSTRAINT name TO name
9917 : {
9918 6 : RenameStmt *n = makeNode(RenameStmt);
9919 :
9920 6 : n->renameType = OBJECT_TABCONSTRAINT;
9921 6 : n->relation = $5;
9922 6 : n->subname = $8;
9923 6 : n->newname = $10;
9924 6 : n->missing_ok = true;
9925 6 : $$ = (Node *) n;
9926 : }
9927 : | ALTER FOREIGN TABLE relation_expr RENAME opt_column name TO name
9928 : {
9929 6 : RenameStmt *n = makeNode(RenameStmt);
9930 :
9931 6 : n->renameType = OBJECT_COLUMN;
9932 6 : n->relationType = OBJECT_FOREIGN_TABLE;
9933 6 : n->relation = $4;
9934 6 : n->subname = $7;
9935 6 : n->newname = $9;
9936 6 : n->missing_ok = false;
9937 6 : $$ = (Node *) n;
9938 : }
9939 : | ALTER FOREIGN TABLE IF_P EXISTS relation_expr RENAME opt_column name TO name
9940 : {
9941 6 : RenameStmt *n = makeNode(RenameStmt);
9942 :
9943 6 : n->renameType = OBJECT_COLUMN;
9944 6 : n->relationType = OBJECT_FOREIGN_TABLE;
9945 6 : n->relation = $6;
9946 6 : n->subname = $9;
9947 6 : n->newname = $11;
9948 6 : n->missing_ok = true;
9949 6 : $$ = (Node *) n;
9950 : }
9951 : | ALTER RULE name ON qualified_name RENAME TO name
9952 : {
9953 34 : RenameStmt *n = makeNode(RenameStmt);
9954 :
9955 34 : n->renameType = OBJECT_RULE;
9956 34 : n->relation = $5;
9957 34 : n->subname = $3;
9958 34 : n->newname = $8;
9959 34 : n->missing_ok = false;
9960 34 : $$ = (Node *) n;
9961 : }
9962 : | ALTER TRIGGER name ON qualified_name RENAME TO name
9963 : {
9964 40 : RenameStmt *n = makeNode(RenameStmt);
9965 :
9966 40 : n->renameType = OBJECT_TRIGGER;
9967 40 : n->relation = $5;
9968 40 : n->subname = $3;
9969 40 : n->newname = $8;
9970 40 : n->missing_ok = false;
9971 40 : $$ = (Node *) n;
9972 : }
9973 : | ALTER EVENT TRIGGER name RENAME TO name
9974 : {
9975 12 : RenameStmt *n = makeNode(RenameStmt);
9976 :
9977 12 : n->renameType = OBJECT_EVENT_TRIGGER;
9978 12 : n->object = (Node *) makeString($4);
9979 12 : n->newname = $7;
9980 12 : $$ = (Node *) n;
9981 : }
9982 : | ALTER ROLE RoleId RENAME TO RoleId
9983 : {
9984 32 : RenameStmt *n = makeNode(RenameStmt);
9985 :
9986 32 : n->renameType = OBJECT_ROLE;
9987 32 : n->subname = $3;
9988 32 : n->newname = $6;
9989 32 : n->missing_ok = false;
9990 32 : $$ = (Node *) n;
9991 : }
9992 : | ALTER USER RoleId RENAME TO RoleId
9993 : {
9994 0 : RenameStmt *n = makeNode(RenameStmt);
9995 :
9996 0 : n->renameType = OBJECT_ROLE;
9997 0 : n->subname = $3;
9998 0 : n->newname = $6;
9999 0 : n->missing_ok = false;
10000 0 : $$ = (Node *) n;
10001 : }
10002 : | ALTER TABLESPACE name RENAME TO name
10003 : {
10004 6 : RenameStmt *n = makeNode(RenameStmt);
10005 :
10006 6 : n->renameType = OBJECT_TABLESPACE;
10007 6 : n->subname = $3;
10008 6 : n->newname = $6;
10009 6 : n->missing_ok = false;
10010 6 : $$ = (Node *) n;
10011 : }
10012 : | ALTER STATISTICS any_name RENAME TO name
10013 : {
10014 30 : RenameStmt *n = makeNode(RenameStmt);
10015 :
10016 30 : n->renameType = OBJECT_STATISTIC_EXT;
10017 30 : n->object = (Node *) $3;
10018 30 : n->newname = $6;
10019 30 : n->missing_ok = false;
10020 30 : $$ = (Node *) n;
10021 : }
10022 : | ALTER TEXT_P SEARCH PARSER any_name RENAME TO name
10023 : {
10024 12 : RenameStmt *n = makeNode(RenameStmt);
10025 :
10026 12 : n->renameType = OBJECT_TSPARSER;
10027 12 : n->object = (Node *) $5;
10028 12 : n->newname = $8;
10029 12 : n->missing_ok = false;
10030 12 : $$ = (Node *) n;
10031 : }
10032 : | ALTER TEXT_P SEARCH DICTIONARY any_name RENAME TO name
10033 : {
10034 24 : RenameStmt *n = makeNode(RenameStmt);
10035 :
10036 24 : n->renameType = OBJECT_TSDICTIONARY;
10037 24 : n->object = (Node *) $5;
10038 24 : n->newname = $8;
10039 24 : n->missing_ok = false;
10040 24 : $$ = (Node *) n;
10041 : }
10042 : | ALTER TEXT_P SEARCH TEMPLATE any_name RENAME TO name
10043 : {
10044 12 : RenameStmt *n = makeNode(RenameStmt);
10045 :
10046 12 : n->renameType = OBJECT_TSTEMPLATE;
10047 12 : n->object = (Node *) $5;
10048 12 : n->newname = $8;
10049 12 : n->missing_ok = false;
10050 12 : $$ = (Node *) n;
10051 : }
10052 : | ALTER TEXT_P SEARCH CONFIGURATION any_name RENAME TO name
10053 : {
10054 24 : RenameStmt *n = makeNode(RenameStmt);
10055 :
10056 24 : n->renameType = OBJECT_TSCONFIGURATION;
10057 24 : n->object = (Node *) $5;
10058 24 : n->newname = $8;
10059 24 : n->missing_ok = false;
10060 24 : $$ = (Node *) n;
10061 : }
10062 : | ALTER TYPE_P any_name RENAME TO name
10063 : {
10064 26 : RenameStmt *n = makeNode(RenameStmt);
10065 :
10066 26 : n->renameType = OBJECT_TYPE;
10067 26 : n->object = (Node *) $3;
10068 26 : n->newname = $6;
10069 26 : n->missing_ok = false;
10070 26 : $$ = (Node *) n;
10071 : }
10072 : | ALTER TYPE_P any_name RENAME ATTRIBUTE name TO name opt_drop_behavior
10073 : {
10074 24 : RenameStmt *n = makeNode(RenameStmt);
10075 :
10076 24 : n->renameType = OBJECT_ATTRIBUTE;
10077 24 : n->relationType = OBJECT_TYPE;
10078 24 : n->relation = makeRangeVarFromAnyName($3, @3, yyscanner);
10079 24 : n->subname = $6;
10080 24 : n->newname = $8;
10081 24 : n->behavior = $9;
10082 24 : n->missing_ok = false;
10083 24 : $$ = (Node *) n;
10084 : }
10085 : ;
10086 :
10087 : opt_column: COLUMN
10088 : | /*EMPTY*/
10089 : ;
10090 :
10091 184 : opt_set_data: SET DATA_P { $$ = 1; }
10092 1028 : | /*EMPTY*/ { $$ = 0; }
10093 : ;
10094 :
10095 : /*****************************************************************************
10096 : *
10097 : * ALTER THING name DEPENDS ON EXTENSION name
10098 : *
10099 : *****************************************************************************/
10100 :
10101 : AlterObjectDependsStmt:
10102 : ALTER FUNCTION function_with_argtypes opt_no DEPENDS ON EXTENSION name
10103 : {
10104 12 : AlterObjectDependsStmt *n = makeNode(AlterObjectDependsStmt);
10105 :
10106 12 : n->objectType = OBJECT_FUNCTION;
10107 12 : n->object = (Node *) $3;
10108 12 : n->extname = makeString($8);
10109 12 : n->remove = $4;
10110 12 : $$ = (Node *) n;
10111 : }
10112 : | ALTER PROCEDURE function_with_argtypes opt_no DEPENDS ON EXTENSION name
10113 : {
10114 0 : AlterObjectDependsStmt *n = makeNode(AlterObjectDependsStmt);
10115 :
10116 0 : n->objectType = OBJECT_PROCEDURE;
10117 0 : n->object = (Node *) $3;
10118 0 : n->extname = makeString($8);
10119 0 : n->remove = $4;
10120 0 : $$ = (Node *) n;
10121 : }
10122 : | ALTER ROUTINE function_with_argtypes opt_no DEPENDS ON EXTENSION name
10123 : {
10124 0 : AlterObjectDependsStmt *n = makeNode(AlterObjectDependsStmt);
10125 :
10126 0 : n->objectType = OBJECT_ROUTINE;
10127 0 : n->object = (Node *) $3;
10128 0 : n->extname = makeString($8);
10129 0 : n->remove = $4;
10130 0 : $$ = (Node *) n;
10131 : }
10132 : | ALTER TRIGGER name ON qualified_name opt_no DEPENDS ON EXTENSION name
10133 : {
10134 10 : AlterObjectDependsStmt *n = makeNode(AlterObjectDependsStmt);
10135 :
10136 10 : n->objectType = OBJECT_TRIGGER;
10137 10 : n->relation = $5;
10138 10 : n->object = (Node *) list_make1(makeString($3));
10139 10 : n->extname = makeString($10);
10140 10 : n->remove = $6;
10141 10 : $$ = (Node *) n;
10142 : }
10143 : | ALTER MATERIALIZED VIEW qualified_name opt_no DEPENDS ON EXTENSION name
10144 : {
10145 10 : AlterObjectDependsStmt *n = makeNode(AlterObjectDependsStmt);
10146 :
10147 10 : n->objectType = OBJECT_MATVIEW;
10148 10 : n->relation = $4;
10149 10 : n->extname = makeString($9);
10150 10 : n->remove = $5;
10151 10 : $$ = (Node *) n;
10152 : }
10153 : | ALTER INDEX qualified_name opt_no DEPENDS ON EXTENSION name
10154 : {
10155 14 : AlterObjectDependsStmt *n = makeNode(AlterObjectDependsStmt);
10156 :
10157 14 : n->objectType = OBJECT_INDEX;
10158 14 : n->relation = $3;
10159 14 : n->extname = makeString($8);
10160 14 : n->remove = $4;
10161 14 : $$ = (Node *) n;
10162 : }
10163 : ;
10164 :
10165 8 : opt_no: NO { $$ = true; }
10166 38 : | /* EMPTY */ { $$ = false; }
10167 : ;
10168 :
10169 : /*****************************************************************************
10170 : *
10171 : * ALTER THING name SET SCHEMA name
10172 : *
10173 : *****************************************************************************/
10174 :
10175 : AlterObjectSchemaStmt:
10176 : ALTER AGGREGATE aggregate_with_argtypes SET SCHEMA name
10177 : {
10178 24 : AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
10179 :
10180 24 : n->objectType = OBJECT_AGGREGATE;
10181 24 : n->object = (Node *) $3;
10182 24 : n->newschema = $6;
10183 24 : n->missing_ok = false;
10184 24 : $$ = (Node *) n;
10185 : }
10186 : | ALTER COLLATION any_name SET SCHEMA name
10187 : {
10188 6 : AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
10189 :
10190 6 : n->objectType = OBJECT_COLLATION;
10191 6 : n->object = (Node *) $3;
10192 6 : n->newschema = $6;
10193 6 : n->missing_ok = false;
10194 6 : $$ = (Node *) n;
10195 : }
10196 : | ALTER CONVERSION_P any_name SET SCHEMA name
10197 : {
10198 24 : AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
10199 :
10200 24 : n->objectType = OBJECT_CONVERSION;
10201 24 : n->object = (Node *) $3;
10202 24 : n->newschema = $6;
10203 24 : n->missing_ok = false;
10204 24 : $$ = (Node *) n;
10205 : }
10206 : | ALTER DOMAIN_P any_name SET SCHEMA name
10207 : {
10208 6 : AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
10209 :
10210 6 : n->objectType = OBJECT_DOMAIN;
10211 6 : n->object = (Node *) $3;
10212 6 : n->newschema = $6;
10213 6 : n->missing_ok = false;
10214 6 : $$ = (Node *) n;
10215 : }
10216 : | ALTER EXTENSION name SET SCHEMA name
10217 : {
10218 12 : AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
10219 :
10220 12 : n->objectType = OBJECT_EXTENSION;
10221 12 : n->object = (Node *) makeString($3);
10222 12 : n->newschema = $6;
10223 12 : n->missing_ok = false;
10224 12 : $$ = (Node *) n;
10225 : }
10226 : | ALTER FUNCTION function_with_argtypes SET SCHEMA name
10227 : {
10228 42 : AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
10229 :
10230 42 : n->objectType = OBJECT_FUNCTION;
10231 42 : n->object = (Node *) $3;
10232 42 : n->newschema = $6;
10233 42 : n->missing_ok = false;
10234 42 : $$ = (Node *) n;
10235 : }
10236 : | ALTER OPERATOR operator_with_argtypes SET SCHEMA name
10237 : {
10238 18 : AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
10239 :
10240 18 : n->objectType = OBJECT_OPERATOR;
10241 18 : n->object = (Node *) $3;
10242 18 : n->newschema = $6;
10243 18 : n->missing_ok = false;
10244 18 : $$ = (Node *) n;
10245 : }
10246 : | ALTER OPERATOR CLASS any_name USING name SET SCHEMA name
10247 : {
10248 24 : AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
10249 :
10250 24 : n->objectType = OBJECT_OPCLASS;
10251 24 : n->object = (Node *) lcons(makeString($6), $4);
10252 24 : n->newschema = $9;
10253 24 : n->missing_ok = false;
10254 24 : $$ = (Node *) n;
10255 : }
10256 : | ALTER OPERATOR FAMILY any_name USING name SET SCHEMA name
10257 : {
10258 24 : AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
10259 :
10260 24 : n->objectType = OBJECT_OPFAMILY;
10261 24 : n->object = (Node *) lcons(makeString($6), $4);
10262 24 : n->newschema = $9;
10263 24 : n->missing_ok = false;
10264 24 : $$ = (Node *) n;
10265 : }
10266 : | ALTER PROCEDURE function_with_argtypes SET SCHEMA name
10267 : {
10268 0 : AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
10269 :
10270 0 : n->objectType = OBJECT_PROCEDURE;
10271 0 : n->object = (Node *) $3;
10272 0 : n->newschema = $6;
10273 0 : n->missing_ok = false;
10274 0 : $$ = (Node *) n;
10275 : }
10276 : | ALTER ROUTINE function_with_argtypes SET SCHEMA name
10277 : {
10278 0 : AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
10279 :
10280 0 : n->objectType = OBJECT_ROUTINE;
10281 0 : n->object = (Node *) $3;
10282 0 : n->newschema = $6;
10283 0 : n->missing_ok = false;
10284 0 : $$ = (Node *) n;
10285 : }
10286 : | ALTER TABLE relation_expr SET SCHEMA name
10287 : {
10288 66 : AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
10289 :
10290 66 : n->objectType = OBJECT_TABLE;
10291 66 : n->relation = $3;
10292 66 : n->newschema = $6;
10293 66 : n->missing_ok = false;
10294 66 : $$ = (Node *) n;
10295 : }
10296 : | ALTER TABLE IF_P EXISTS relation_expr SET SCHEMA name
10297 : {
10298 12 : AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
10299 :
10300 12 : n->objectType = OBJECT_TABLE;
10301 12 : n->relation = $5;
10302 12 : n->newschema = $8;
10303 12 : n->missing_ok = true;
10304 12 : $$ = (Node *) n;
10305 : }
10306 : | ALTER STATISTICS any_name SET SCHEMA name
10307 : {
10308 18 : AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
10309 :
10310 18 : n->objectType = OBJECT_STATISTIC_EXT;
10311 18 : n->object = (Node *) $3;
10312 18 : n->newschema = $6;
10313 18 : n->missing_ok = false;
10314 18 : $$ = (Node *) n;
10315 : }
10316 : | ALTER TEXT_P SEARCH PARSER any_name SET SCHEMA name
10317 : {
10318 18 : AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
10319 :
10320 18 : n->objectType = OBJECT_TSPARSER;
10321 18 : n->object = (Node *) $5;
10322 18 : n->newschema = $8;
10323 18 : n->missing_ok = false;
10324 18 : $$ = (Node *) n;
10325 : }
10326 : | ALTER TEXT_P SEARCH DICTIONARY any_name SET SCHEMA name
10327 : {
10328 24 : AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
10329 :
10330 24 : n->objectType = OBJECT_TSDICTIONARY;
10331 24 : n->object = (Node *) $5;
10332 24 : n->newschema = $8;
10333 24 : n->missing_ok = false;
10334 24 : $$ = (Node *) n;
10335 : }
10336 : | ALTER TEXT_P SEARCH TEMPLATE any_name SET SCHEMA name
10337 : {
10338 18 : AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
10339 :
10340 18 : n->objectType = OBJECT_TSTEMPLATE;
10341 18 : n->object = (Node *) $5;
10342 18 : n->newschema = $8;
10343 18 : n->missing_ok = false;
10344 18 : $$ = (Node *) n;
10345 : }
10346 : | ALTER TEXT_P SEARCH CONFIGURATION any_name SET SCHEMA name
10347 : {
10348 24 : AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
10349 :
10350 24 : n->objectType = OBJECT_TSCONFIGURATION;
10351 24 : n->object = (Node *) $5;
10352 24 : n->newschema = $8;
10353 24 : n->missing_ok = false;
10354 24 : $$ = (Node *) n;
10355 : }
10356 : | ALTER SEQUENCE qualified_name SET SCHEMA name
10357 : {
10358 8 : AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
10359 :
10360 8 : n->objectType = OBJECT_SEQUENCE;
10361 8 : n->relation = $3;
10362 8 : n->newschema = $6;
10363 8 : n->missing_ok = false;
10364 8 : $$ = (Node *) n;
10365 : }
10366 : | ALTER SEQUENCE IF_P EXISTS qualified_name SET SCHEMA name
10367 : {
10368 0 : AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
10369 :
10370 0 : n->objectType = OBJECT_SEQUENCE;
10371 0 : n->relation = $5;
10372 0 : n->newschema = $8;
10373 0 : n->missing_ok = true;
10374 0 : $$ = (Node *) n;
10375 : }
10376 : | ALTER VIEW qualified_name SET SCHEMA name
10377 : {
10378 0 : AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
10379 :
10380 0 : n->objectType = OBJECT_VIEW;
10381 0 : n->relation = $3;
10382 0 : n->newschema = $6;
10383 0 : n->missing_ok = false;
10384 0 : $$ = (Node *) n;
10385 : }
10386 : | ALTER VIEW IF_P EXISTS qualified_name SET SCHEMA name
10387 : {
10388 0 : AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
10389 :
10390 0 : n->objectType = OBJECT_VIEW;
10391 0 : n->relation = $5;
10392 0 : n->newschema = $8;
10393 0 : n->missing_ok = true;
10394 0 : $$ = (Node *) n;
10395 : }
10396 : | ALTER MATERIALIZED VIEW qualified_name SET SCHEMA name
10397 : {
10398 6 : AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
10399 :
10400 6 : n->objectType = OBJECT_MATVIEW;
10401 6 : n->relation = $4;
10402 6 : n->newschema = $7;
10403 6 : n->missing_ok = false;
10404 6 : $$ = (Node *) n;
10405 : }
10406 : | ALTER MATERIALIZED VIEW IF_P EXISTS qualified_name SET SCHEMA name
10407 : {
10408 0 : AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
10409 :
10410 0 : n->objectType = OBJECT_MATVIEW;
10411 0 : n->relation = $6;
10412 0 : n->newschema = $9;
10413 0 : n->missing_ok = true;
10414 0 : $$ = (Node *) n;
10415 : }
10416 : | ALTER FOREIGN TABLE relation_expr SET SCHEMA name
10417 : {
10418 6 : AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
10419 :
10420 6 : n->objectType = OBJECT_FOREIGN_TABLE;
10421 6 : n->relation = $4;
10422 6 : n->newschema = $7;
10423 6 : n->missing_ok = false;
10424 6 : $$ = (Node *) n;
10425 : }
10426 : | ALTER FOREIGN TABLE IF_P EXISTS relation_expr SET SCHEMA name
10427 : {
10428 6 : AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
10429 :
10430 6 : n->objectType = OBJECT_FOREIGN_TABLE;
10431 6 : n->relation = $6;
10432 6 : n->newschema = $9;
10433 6 : n->missing_ok = true;
10434 6 : $$ = (Node *) n;
10435 : }
10436 : | ALTER TYPE_P any_name SET SCHEMA name
10437 : {
10438 12 : AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
10439 :
10440 12 : n->objectType = OBJECT_TYPE;
10441 12 : n->object = (Node *) $3;
10442 12 : n->newschema = $6;
10443 12 : n->missing_ok = false;
10444 12 : $$ = (Node *) n;
10445 : }
10446 : ;
10447 :
10448 : /*****************************************************************************
10449 : *
10450 : * ALTER OPERATOR name SET define
10451 : *
10452 : *****************************************************************************/
10453 :
10454 : AlterOperatorStmt:
10455 : ALTER OPERATOR operator_with_argtypes SET '(' operator_def_list ')'
10456 : {
10457 608 : AlterOperatorStmt *n = makeNode(AlterOperatorStmt);
10458 :
10459 608 : n->opername = $3;
10460 608 : n->options = $6;
10461 608 : $$ = (Node *) n;
10462 : }
10463 : ;
10464 :
10465 668 : operator_def_list: operator_def_elem { $$ = list_make1($1); }
10466 506 : | operator_def_list ',' operator_def_elem { $$ = lappend($1, $3); }
10467 : ;
10468 :
10469 : operator_def_elem: ColLabel '=' NONE
10470 30 : { $$ = makeDefElem($1, NULL, @1); }
10471 : | ColLabel '=' operator_def_arg
10472 1110 : { $$ = makeDefElem($1, (Node *) $3, @1); }
10473 : | ColLabel
10474 34 : { $$ = makeDefElem($1, NULL, @1); }
10475 : ;
10476 :
10477 : /* must be similar enough to def_arg to avoid reduce/reduce conflicts */
10478 : operator_def_arg:
10479 1032 : func_type { $$ = (Node *) $1; }
10480 24 : | reserved_keyword { $$ = (Node *) makeString(pstrdup($1)); }
10481 54 : | qual_all_Op { $$ = (Node *) $1; }
10482 0 : | NumericOnly { $$ = (Node *) $1; }
10483 0 : | Sconst { $$ = (Node *) makeString($1); }
10484 : ;
10485 :
10486 : /*****************************************************************************
10487 : *
10488 : * ALTER TYPE name SET define
10489 : *
10490 : * We repurpose ALTER OPERATOR's version of "definition" here
10491 : *
10492 : *****************************************************************************/
10493 :
10494 : AlterTypeStmt:
10495 : ALTER TYPE_P any_name SET '(' operator_def_list ')'
10496 : {
10497 60 : AlterTypeStmt *n = makeNode(AlterTypeStmt);
10498 :
10499 60 : n->typeName = $3;
10500 60 : n->options = $6;
10501 60 : $$ = (Node *) n;
10502 : }
10503 : ;
10504 :
10505 : /*****************************************************************************
10506 : *
10507 : * ALTER THING name OWNER TO newname
10508 : *
10509 : *****************************************************************************/
10510 :
10511 : AlterOwnerStmt: ALTER AGGREGATE aggregate_with_argtypes OWNER TO RoleSpec
10512 : {
10513 142 : AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
10514 :
10515 142 : n->objectType = OBJECT_AGGREGATE;
10516 142 : n->object = (Node *) $3;
10517 142 : n->newowner = $6;
10518 142 : $$ = (Node *) n;
10519 : }
10520 : | ALTER COLLATION any_name OWNER TO RoleSpec
10521 : {
10522 18 : AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
10523 :
10524 18 : n->objectType = OBJECT_COLLATION;
10525 18 : n->object = (Node *) $3;
10526 18 : n->newowner = $6;
10527 18 : $$ = (Node *) n;
10528 : }
10529 : | ALTER CONVERSION_P any_name OWNER TO RoleSpec
10530 : {
10531 24 : AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
10532 :
10533 24 : n->objectType = OBJECT_CONVERSION;
10534 24 : n->object = (Node *) $3;
10535 24 : n->newowner = $6;
10536 24 : $$ = (Node *) n;
10537 : }
10538 : | ALTER DATABASE name OWNER TO RoleSpec
10539 : {
10540 86 : AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
10541 :
10542 86 : n->objectType = OBJECT_DATABASE;
10543 86 : n->object = (Node *) makeString($3);
10544 86 : n->newowner = $6;
10545 86 : $$ = (Node *) n;
10546 : }
10547 : | ALTER DOMAIN_P any_name OWNER TO RoleSpec
10548 : {
10549 48 : AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
10550 :
10551 48 : n->objectType = OBJECT_DOMAIN;
10552 48 : n->object = (Node *) $3;
10553 48 : n->newowner = $6;
10554 48 : $$ = (Node *) n;
10555 : }
10556 : | ALTER FUNCTION function_with_argtypes OWNER TO RoleSpec
10557 : {
10558 596 : AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
10559 :
10560 596 : n->objectType = OBJECT_FUNCTION;
10561 596 : n->object = (Node *) $3;
10562 596 : n->newowner = $6;
10563 596 : $$ = (Node *) n;
10564 : }
10565 : | ALTER opt_procedural LANGUAGE name OWNER TO RoleSpec
10566 : {
10567 142 : AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
10568 :
10569 142 : n->objectType = OBJECT_LANGUAGE;
10570 142 : n->object = (Node *) makeString($4);
10571 142 : n->newowner = $7;
10572 142 : $$ = (Node *) n;
10573 : }
10574 : | ALTER LARGE_P OBJECT_P NumericOnly OWNER TO RoleSpec
10575 : {
10576 16 : AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
10577 :
10578 16 : n->objectType = OBJECT_LARGEOBJECT;
10579 16 : n->object = (Node *) $4;
10580 16 : n->newowner = $7;
10581 16 : $$ = (Node *) n;
10582 : }
10583 : | ALTER OPERATOR operator_with_argtypes OWNER TO RoleSpec
10584 : {
10585 46 : AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
10586 :
10587 46 : n->objectType = OBJECT_OPERATOR;
10588 46 : n->object = (Node *) $3;
10589 46 : n->newowner = $6;
10590 46 : $$ = (Node *) n;
10591 : }
10592 : | ALTER OPERATOR CLASS any_name USING name OWNER TO RoleSpec
10593 : {
10594 54 : AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
10595 :
10596 54 : n->objectType = OBJECT_OPCLASS;
10597 54 : n->object = (Node *) lcons(makeString($6), $4);
10598 54 : n->newowner = $9;
10599 54 : $$ = (Node *) n;
10600 : }
10601 : | ALTER OPERATOR FAMILY any_name USING name OWNER TO RoleSpec
10602 : {
10603 62 : AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
10604 :
10605 62 : n->objectType = OBJECT_OPFAMILY;
10606 62 : n->object = (Node *) lcons(makeString($6), $4);
10607 62 : n->newowner = $9;
10608 62 : $$ = (Node *) n;
10609 : }
10610 : | ALTER PROCEDURE function_with_argtypes OWNER TO RoleSpec
10611 : {
10612 24 : AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
10613 :
10614 24 : n->objectType = OBJECT_PROCEDURE;
10615 24 : n->object = (Node *) $3;
10616 24 : n->newowner = $6;
10617 24 : $$ = (Node *) n;
10618 : }
10619 : | ALTER ROUTINE function_with_argtypes OWNER TO RoleSpec
10620 : {
10621 0 : AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
10622 :
10623 0 : n->objectType = OBJECT_ROUTINE;
10624 0 : n->object = (Node *) $3;
10625 0 : n->newowner = $6;
10626 0 : $$ = (Node *) n;
10627 : }
10628 : | ALTER SCHEMA name OWNER TO RoleSpec
10629 : {
10630 64 : AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
10631 :
10632 64 : n->objectType = OBJECT_SCHEMA;
10633 64 : n->object = (Node *) makeString($3);
10634 64 : n->newowner = $6;
10635 64 : $$ = (Node *) n;
10636 : }
10637 : | ALTER TYPE_P any_name OWNER TO RoleSpec
10638 : {
10639 84 : AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
10640 :
10641 84 : n->objectType = OBJECT_TYPE;
10642 84 : n->object = (Node *) $3;
10643 84 : n->newowner = $6;
10644 84 : $$ = (Node *) n;
10645 : }
10646 : | ALTER TABLESPACE name OWNER TO RoleSpec
10647 : {
10648 6 : AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
10649 :
10650 6 : n->objectType = OBJECT_TABLESPACE;
10651 6 : n->object = (Node *) makeString($3);
10652 6 : n->newowner = $6;
10653 6 : $$ = (Node *) n;
10654 : }
10655 : | ALTER STATISTICS any_name OWNER TO RoleSpec
10656 : {
10657 32 : AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
10658 :
10659 32 : n->objectType = OBJECT_STATISTIC_EXT;
10660 32 : n->object = (Node *) $3;
10661 32 : n->newowner = $6;
10662 32 : $$ = (Node *) n;
10663 : }
10664 : | ALTER TEXT_P SEARCH DICTIONARY any_name OWNER TO RoleSpec
10665 : {
10666 42 : AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
10667 :
10668 42 : n->objectType = OBJECT_TSDICTIONARY;
10669 42 : n->object = (Node *) $5;
10670 42 : n->newowner = $8;
10671 42 : $$ = (Node *) n;
10672 : }
10673 : | ALTER TEXT_P SEARCH CONFIGURATION any_name OWNER TO RoleSpec
10674 : {
10675 32 : AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
10676 :
10677 32 : n->objectType = OBJECT_TSCONFIGURATION;
10678 32 : n->object = (Node *) $5;
10679 32 : n->newowner = $8;
10680 32 : $$ = (Node *) n;
10681 : }
10682 : | ALTER FOREIGN DATA_P WRAPPER name OWNER TO RoleSpec
10683 : {
10684 20 : AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
10685 :
10686 20 : n->objectType = OBJECT_FDW;
10687 20 : n->object = (Node *) makeString($5);
10688 20 : n->newowner = $8;
10689 20 : $$ = (Node *) n;
10690 : }
10691 : | ALTER SERVER name OWNER TO RoleSpec
10692 : {
10693 68 : AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
10694 :
10695 68 : n->objectType = OBJECT_FOREIGN_SERVER;
10696 68 : n->object = (Node *) makeString($3);
10697 68 : n->newowner = $6;
10698 68 : $$ = (Node *) n;
10699 : }
10700 : | ALTER EVENT TRIGGER name OWNER TO RoleSpec
10701 : {
10702 14 : AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
10703 :
10704 14 : n->objectType = OBJECT_EVENT_TRIGGER;
10705 14 : n->object = (Node *) makeString($4);
10706 14 : n->newowner = $7;
10707 14 : $$ = (Node *) n;
10708 : }
10709 : | ALTER PUBLICATION name OWNER TO RoleSpec
10710 : {
10711 36 : AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
10712 :
10713 36 : n->objectType = OBJECT_PUBLICATION;
10714 36 : n->object = (Node *) makeString($3);
10715 36 : n->newowner = $6;
10716 36 : $$ = (Node *) n;
10717 : }
10718 : | ALTER SUBSCRIPTION name OWNER TO RoleSpec
10719 : {
10720 18 : AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
10721 :
10722 18 : n->objectType = OBJECT_SUBSCRIPTION;
10723 18 : n->object = (Node *) makeString($3);
10724 18 : n->newowner = $6;
10725 18 : $$ = (Node *) n;
10726 : }
10727 : ;
10728 :
10729 :
10730 : /*****************************************************************************
10731 : *
10732 : * CREATE PUBLICATION name [WITH options]
10733 : *
10734 : * CREATE PUBLICATION FOR ALL pub_all_obj_type [, ...] [WITH options]
10735 : *
10736 : * pub_all_obj_type is one of:
10737 : *
10738 : * TABLES
10739 : * SEQUENCES
10740 : *
10741 : * CREATE PUBLICATION FOR pub_obj [, ...] [WITH options]
10742 : *
10743 : * pub_obj is one of:
10744 : *
10745 : * TABLE table [, ...]
10746 : * TABLES IN SCHEMA schema [, ...]
10747 : *
10748 : *****************************************************************************/
10749 :
10750 : CreatePublicationStmt:
10751 : CREATE PUBLICATION name opt_definition
10752 : {
10753 146 : CreatePublicationStmt *n = makeNode(CreatePublicationStmt);
10754 :
10755 146 : n->pubname = $3;
10756 146 : n->options = $4;
10757 146 : $$ = (Node *) n;
10758 : }
10759 : | CREATE PUBLICATION name FOR pub_all_obj_type_list opt_definition
10760 : {
10761 152 : CreatePublicationStmt *n = makeNode(CreatePublicationStmt);
10762 :
10763 152 : n->pubname = $3;
10764 152 : preprocess_pub_all_objtype_list($5, &n->for_all_tables,
10765 : &n->for_all_sequences,
10766 : yyscanner);
10767 140 : n->options = $6;
10768 140 : $$ = (Node *) n;
10769 : }
10770 : | CREATE PUBLICATION name FOR pub_obj_list opt_definition
10771 : {
10772 658 : CreatePublicationStmt *n = makeNode(CreatePublicationStmt);
10773 :
10774 658 : n->pubname = $3;
10775 658 : n->options = $6;
10776 658 : n->pubobjects = (List *) $5;
10777 658 : preprocess_pubobj_list(n->pubobjects, yyscanner);
10778 628 : $$ = (Node *) n;
10779 : }
10780 : ;
10781 :
10782 : /*
10783 : * FOR TABLE and FOR TABLES IN SCHEMA specifications
10784 : *
10785 : * This rule parses publication objects with and without keyword prefixes.
10786 : *
10787 : * The actual type of the object without keyword prefix depends on the previous
10788 : * one with keyword prefix. It will be preprocessed in preprocess_pubobj_list().
10789 : *
10790 : * For the object without keyword prefix, we cannot just use relation_expr here,
10791 : * because some extended expressions in relation_expr cannot be used as a
10792 : * schemaname and we cannot differentiate it. So, we extract the rules from
10793 : * relation_expr here.
10794 : */
10795 : PublicationObjSpec:
10796 : TABLE relation_expr opt_column_list OptWhereClause
10797 : {
10798 1326 : $$ = makeNode(PublicationObjSpec);
10799 1326 : $$->pubobjtype = PUBLICATIONOBJ_TABLE;
10800 1326 : $$->pubtable = makeNode(PublicationTable);
10801 1326 : $$->pubtable->relation = $2;
10802 1326 : $$->pubtable->columns = $3;
10803 1326 : $$->pubtable->whereClause = $4;
10804 : }
10805 : | TABLES IN_P SCHEMA ColId
10806 : {
10807 372 : $$ = makeNode(PublicationObjSpec);
10808 372 : $$->pubobjtype = PUBLICATIONOBJ_TABLES_IN_SCHEMA;
10809 372 : $$->name = $4;
10810 372 : $$->location = @4;
10811 : }
10812 : | TABLES IN_P SCHEMA CURRENT_SCHEMA
10813 : {
10814 18 : $$ = makeNode(PublicationObjSpec);
10815 18 : $$->pubobjtype = PUBLICATIONOBJ_TABLES_IN_CUR_SCHEMA;
10816 18 : $$->location = @4;
10817 : }
10818 : | ColId opt_column_list OptWhereClause
10819 : {
10820 130 : $$ = makeNode(PublicationObjSpec);
10821 130 : $$->pubobjtype = PUBLICATIONOBJ_CONTINUATION;
10822 : /*
10823 : * If either a row filter or column list is specified, create
10824 : * a PublicationTable object.
10825 : */
10826 130 : if ($2 || $3)
10827 : {
10828 : /*
10829 : * The OptWhereClause must be stored here but it is
10830 : * valid only for tables. For non-table objects, an
10831 : * error will be thrown later via
10832 : * preprocess_pubobj_list().
10833 : */
10834 42 : $$->pubtable = makeNode(PublicationTable);
10835 42 : $$->pubtable->relation = makeRangeVar(NULL, $1, @1);
10836 42 : $$->pubtable->columns = $2;
10837 42 : $$->pubtable->whereClause = $3;
10838 : }
10839 : else
10840 : {
10841 88 : $$->name = $1;
10842 : }
10843 130 : $$->location = @1;
10844 : }
10845 : | ColId indirection opt_column_list OptWhereClause
10846 : {
10847 32 : $$ = makeNode(PublicationObjSpec);
10848 32 : $$->pubobjtype = PUBLICATIONOBJ_CONTINUATION;
10849 32 : $$->pubtable = makeNode(PublicationTable);
10850 32 : $$->pubtable->relation = makeRangeVarFromQualifiedName($1, $2, @1, yyscanner);
10851 32 : $$->pubtable->columns = $3;
10852 32 : $$->pubtable->whereClause = $4;
10853 32 : $$->location = @1;
10854 : }
10855 : /* grammar like tablename * , ONLY tablename, ONLY ( tablename ) */
10856 : | extended_relation_expr opt_column_list OptWhereClause
10857 : {
10858 6 : $$ = makeNode(PublicationObjSpec);
10859 6 : $$->pubobjtype = PUBLICATIONOBJ_CONTINUATION;
10860 6 : $$->pubtable = makeNode(PublicationTable);
10861 6 : $$->pubtable->relation = $1;
10862 6 : $$->pubtable->columns = $2;
10863 6 : $$->pubtable->whereClause = $3;
10864 : }
10865 : | CURRENT_SCHEMA
10866 : {
10867 18 : $$ = makeNode(PublicationObjSpec);
10868 18 : $$->pubobjtype = PUBLICATIONOBJ_CONTINUATION;
10869 18 : $$->location = @1;
10870 : }
10871 : ;
10872 :
10873 : pub_obj_list: PublicationObjSpec
10874 1648 : { $$ = list_make1($1); }
10875 : | pub_obj_list ',' PublicationObjSpec
10876 254 : { $$ = lappend($1, $3); }
10877 : ;
10878 :
10879 : PublicationAllObjSpec:
10880 : ALL TABLES
10881 : {
10882 132 : $$ = makeNode(PublicationAllObjSpec);
10883 132 : $$->pubobjtype = PUBLICATION_ALL_TABLES;
10884 132 : $$->location = @1;
10885 : }
10886 : | ALL SEQUENCES
10887 : {
10888 58 : $$ = makeNode(PublicationAllObjSpec);
10889 58 : $$->pubobjtype = PUBLICATION_ALL_SEQUENCES;
10890 58 : $$->location = @1;
10891 : }
10892 : ;
10893 :
10894 : pub_all_obj_type_list: PublicationAllObjSpec
10895 152 : { $$ = list_make1($1); }
10896 : | pub_all_obj_type_list ',' PublicationAllObjSpec
10897 38 : { $$ = lappend($1, $3); }
10898 : ;
10899 :
10900 :
10901 : /*****************************************************************************
10902 : *
10903 : * ALTER PUBLICATION name SET ( options )
10904 : *
10905 : * ALTER PUBLICATION name ADD pub_obj [, ...]
10906 : *
10907 : * ALTER PUBLICATION name DROP pub_obj [, ...]
10908 : *
10909 : * ALTER PUBLICATION name SET pub_obj [, ...]
10910 : *
10911 : * pub_obj is one of:
10912 : *
10913 : * TABLE table_name [, ...]
10914 : * TABLES IN SCHEMA schema_name [, ...]
10915 : *
10916 : *****************************************************************************/
10917 :
10918 : AlterPublicationStmt:
10919 : ALTER PUBLICATION name SET definition
10920 : {
10921 116 : AlterPublicationStmt *n = makeNode(AlterPublicationStmt);
10922 :
10923 116 : n->pubname = $3;
10924 116 : n->options = $5;
10925 116 : $$ = (Node *) n;
10926 : }
10927 : | ALTER PUBLICATION name ADD_P pub_obj_list
10928 : {
10929 370 : AlterPublicationStmt *n = makeNode(AlterPublicationStmt);
10930 :
10931 370 : n->pubname = $3;
10932 370 : n->pubobjects = $5;
10933 370 : preprocess_pubobj_list(n->pubobjects, yyscanner);
10934 364 : n->action = AP_AddObjects;
10935 364 : $$ = (Node *) n;
10936 : }
10937 : | ALTER PUBLICATION name SET pub_obj_list
10938 : {
10939 464 : AlterPublicationStmt *n = makeNode(AlterPublicationStmt);
10940 :
10941 464 : n->pubname = $3;
10942 464 : n->pubobjects = $5;
10943 464 : preprocess_pubobj_list(n->pubobjects, yyscanner);
10944 464 : n->action = AP_SetObjects;
10945 464 : $$ = (Node *) n;
10946 : }
10947 : | ALTER PUBLICATION name DROP pub_obj_list
10948 : {
10949 156 : AlterPublicationStmt *n = makeNode(AlterPublicationStmt);
10950 :
10951 156 : n->pubname = $3;
10952 156 : n->pubobjects = $5;
10953 156 : preprocess_pubobj_list(n->pubobjects, yyscanner);
10954 156 : n->action = AP_DropObjects;
10955 156 : $$ = (Node *) n;
10956 : }
10957 : ;
10958 :
10959 : /*****************************************************************************
10960 : *
10961 : * CREATE SUBSCRIPTION name ...
10962 : *
10963 : *****************************************************************************/
10964 :
10965 : CreateSubscriptionStmt:
10966 : CREATE SUBSCRIPTION name CONNECTION Sconst PUBLICATION name_list opt_definition
10967 : {
10968 : CreateSubscriptionStmt *n =
10969 482 : makeNode(CreateSubscriptionStmt);
10970 482 : n->subname = $3;
10971 482 : n->conninfo = $5;
10972 482 : n->publication = $7;
10973 482 : n->options = $8;
10974 482 : $$ = (Node *) n;
10975 : }
10976 : ;
10977 :
10978 : /*****************************************************************************
10979 : *
10980 : * ALTER SUBSCRIPTION name ...
10981 : *
10982 : *****************************************************************************/
10983 :
10984 : AlterSubscriptionStmt:
10985 : ALTER SUBSCRIPTION name SET definition
10986 : {
10987 : AlterSubscriptionStmt *n =
10988 218 : makeNode(AlterSubscriptionStmt);
10989 :
10990 218 : n->kind = ALTER_SUBSCRIPTION_OPTIONS;
10991 218 : n->subname = $3;
10992 218 : n->options = $5;
10993 218 : $$ = (Node *) n;
10994 : }
10995 : | ALTER SUBSCRIPTION name CONNECTION Sconst
10996 : {
10997 : AlterSubscriptionStmt *n =
10998 26 : makeNode(AlterSubscriptionStmt);
10999 :
11000 26 : n->kind = ALTER_SUBSCRIPTION_CONNECTION;
11001 26 : n->subname = $3;
11002 26 : n->conninfo = $5;
11003 26 : $$ = (Node *) n;
11004 : }
11005 : | ALTER SUBSCRIPTION name REFRESH PUBLICATION opt_definition
11006 : {
11007 : AlterSubscriptionStmt *n =
11008 68 : makeNode(AlterSubscriptionStmt);
11009 :
11010 68 : n->kind = ALTER_SUBSCRIPTION_REFRESH_PUBLICATION;
11011 68 : n->subname = $3;
11012 68 : n->options = $6;
11013 68 : $$ = (Node *) n;
11014 : }
11015 : | ALTER SUBSCRIPTION name REFRESH SEQUENCES
11016 : {
11017 : AlterSubscriptionStmt *n =
11018 2 : makeNode(AlterSubscriptionStmt);
11019 :
11020 2 : n->kind = ALTER_SUBSCRIPTION_REFRESH_SEQUENCES;
11021 2 : n->subname = $3;
11022 2 : $$ = (Node *) n;
11023 : }
11024 : | ALTER SUBSCRIPTION name ADD_P PUBLICATION name_list opt_definition
11025 : {
11026 : AlterSubscriptionStmt *n =
11027 28 : makeNode(AlterSubscriptionStmt);
11028 :
11029 28 : n->kind = ALTER_SUBSCRIPTION_ADD_PUBLICATION;
11030 28 : n->subname = $3;
11031 28 : n->publication = $6;
11032 28 : n->options = $7;
11033 28 : $$ = (Node *) n;
11034 : }
11035 : | ALTER SUBSCRIPTION name DROP PUBLICATION name_list opt_definition
11036 : {
11037 : AlterSubscriptionStmt *n =
11038 26 : makeNode(AlterSubscriptionStmt);
11039 :
11040 26 : n->kind = ALTER_SUBSCRIPTION_DROP_PUBLICATION;
11041 26 : n->subname = $3;
11042 26 : n->publication = $6;
11043 26 : n->options = $7;
11044 26 : $$ = (Node *) n;
11045 : }
11046 : | ALTER SUBSCRIPTION name SET PUBLICATION name_list opt_definition
11047 : {
11048 : AlterSubscriptionStmt *n =
11049 44 : makeNode(AlterSubscriptionStmt);
11050 :
11051 44 : n->kind = ALTER_SUBSCRIPTION_SET_PUBLICATION;
11052 44 : n->subname = $3;
11053 44 : n->publication = $6;
11054 44 : n->options = $7;
11055 44 : $$ = (Node *) n;
11056 : }
11057 : | ALTER SUBSCRIPTION name ENABLE_P
11058 : {
11059 : AlterSubscriptionStmt *n =
11060 60 : makeNode(AlterSubscriptionStmt);
11061 :
11062 60 : n->kind = ALTER_SUBSCRIPTION_ENABLED;
11063 60 : n->subname = $3;
11064 60 : n->options = list_make1(makeDefElem("enabled",
11065 : (Node *) makeBoolean(true), @1));
11066 60 : $$ = (Node *) n;
11067 : }
11068 : | ALTER SUBSCRIPTION name DISABLE_P
11069 : {
11070 : AlterSubscriptionStmt *n =
11071 44 : makeNode(AlterSubscriptionStmt);
11072 :
11073 44 : n->kind = ALTER_SUBSCRIPTION_ENABLED;
11074 44 : n->subname = $3;
11075 44 : n->options = list_make1(makeDefElem("enabled",
11076 : (Node *) makeBoolean(false), @1));
11077 44 : $$ = (Node *) n;
11078 : }
11079 : | ALTER SUBSCRIPTION name SKIP definition
11080 : {
11081 : AlterSubscriptionStmt *n =
11082 24 : makeNode(AlterSubscriptionStmt);
11083 :
11084 24 : n->kind = ALTER_SUBSCRIPTION_SKIP;
11085 24 : n->subname = $3;
11086 24 : n->options = $5;
11087 24 : $$ = (Node *) n;
11088 : }
11089 : ;
11090 :
11091 : /*****************************************************************************
11092 : *
11093 : * DROP SUBSCRIPTION [ IF EXISTS ] name
11094 : *
11095 : *****************************************************************************/
11096 :
11097 : DropSubscriptionStmt: DROP SUBSCRIPTION name opt_drop_behavior
11098 : {
11099 242 : DropSubscriptionStmt *n = makeNode(DropSubscriptionStmt);
11100 :
11101 242 : n->subname = $3;
11102 242 : n->missing_ok = false;
11103 242 : n->behavior = $4;
11104 242 : $$ = (Node *) n;
11105 : }
11106 : | DROP SUBSCRIPTION IF_P EXISTS name opt_drop_behavior
11107 : {
11108 6 : DropSubscriptionStmt *n = makeNode(DropSubscriptionStmt);
11109 :
11110 6 : n->subname = $5;
11111 6 : n->missing_ok = true;
11112 6 : n->behavior = $6;
11113 6 : $$ = (Node *) n;
11114 : }
11115 : ;
11116 :
11117 : /*****************************************************************************
11118 : *
11119 : * QUERY: Define Rewrite Rule
11120 : *
11121 : *****************************************************************************/
11122 :
11123 : RuleStmt: CREATE opt_or_replace RULE name AS
11124 : ON event TO qualified_name where_clause
11125 : DO opt_instead RuleActionList
11126 : {
11127 1098 : RuleStmt *n = makeNode(RuleStmt);
11128 :
11129 1098 : n->replace = $2;
11130 1098 : n->relation = $9;
11131 1098 : n->rulename = $4;
11132 1098 : n->whereClause = $10;
11133 1098 : n->event = $7;
11134 1098 : n->instead = $12;
11135 1098 : n->actions = $13;
11136 1098 : $$ = (Node *) n;
11137 : }
11138 : ;
11139 :
11140 : RuleActionList:
11141 162 : NOTHING { $$ = NIL; }
11142 890 : | RuleActionStmt { $$ = list_make1($1); }
11143 46 : | '(' RuleActionMulti ')' { $$ = $2; }
11144 : ;
11145 :
11146 : /* the thrashing around here is to discard "empty" statements... */
11147 : RuleActionMulti:
11148 : RuleActionMulti ';' RuleActionStmtOrEmpty
11149 62 : { if ($3 != NULL)
11150 46 : $$ = lappend($1, $3);
11151 : else
11152 16 : $$ = $1;
11153 : }
11154 : | RuleActionStmtOrEmpty
11155 46 : { if ($1 != NULL)
11156 46 : $$ = list_make1($1);
11157 : else
11158 0 : $$ = NIL;
11159 : }
11160 : ;
11161 :
11162 : RuleActionStmt:
11163 : SelectStmt
11164 : | InsertStmt
11165 : | UpdateStmt
11166 : | DeleteStmt
11167 : | NotifyStmt
11168 : ;
11169 :
11170 : RuleActionStmtOrEmpty:
11171 92 : RuleActionStmt { $$ = $1; }
11172 16 : | /*EMPTY*/ { $$ = NULL; }
11173 : ;
11174 :
11175 18 : event: SELECT { $$ = CMD_SELECT; }
11176 432 : | UPDATE { $$ = CMD_UPDATE; }
11177 164 : | DELETE_P { $$ = CMD_DELETE; }
11178 484 : | INSERT { $$ = CMD_INSERT; }
11179 : ;
11180 :
11181 : opt_instead:
11182 758 : INSTEAD { $$ = true; }
11183 156 : | ALSO { $$ = false; }
11184 184 : | /*EMPTY*/ { $$ = false; }
11185 : ;
11186 :
11187 :
11188 : /*****************************************************************************
11189 : *
11190 : * QUERY:
11191 : * NOTIFY <identifier> can appear both in rule bodies and
11192 : * as a query-level command
11193 : *
11194 : *****************************************************************************/
11195 :
11196 : NotifyStmt: NOTIFY ColId notify_payload
11197 : {
11198 148 : NotifyStmt *n = makeNode(NotifyStmt);
11199 :
11200 148 : n->conditionname = $2;
11201 148 : n->payload = $3;
11202 148 : $$ = (Node *) n;
11203 : }
11204 : ;
11205 :
11206 : notify_payload:
11207 82 : ',' Sconst { $$ = $2; }
11208 66 : | /*EMPTY*/ { $$ = NULL; }
11209 : ;
11210 :
11211 : ListenStmt: LISTEN ColId
11212 : {
11213 74 : ListenStmt *n = makeNode(ListenStmt);
11214 :
11215 74 : n->conditionname = $2;
11216 74 : $$ = (Node *) n;
11217 : }
11218 : ;
11219 :
11220 : UnlistenStmt:
11221 : UNLISTEN ColId
11222 : {
11223 6 : UnlistenStmt *n = makeNode(UnlistenStmt);
11224 :
11225 6 : n->conditionname = $2;
11226 6 : $$ = (Node *) n;
11227 : }
11228 : | UNLISTEN '*'
11229 : {
11230 32 : UnlistenStmt *n = makeNode(UnlistenStmt);
11231 :
11232 32 : n->conditionname = NULL;
11233 32 : $$ = (Node *) n;
11234 : }
11235 : ;
11236 :
11237 :
11238 : /*****************************************************************************
11239 : *
11240 : * Transactions:
11241 : *
11242 : * BEGIN / COMMIT / ROLLBACK
11243 : * (also older versions END / ABORT)
11244 : *
11245 : *****************************************************************************/
11246 :
11247 : TransactionStmt:
11248 : ABORT_P opt_transaction opt_transaction_chain
11249 : {
11250 232 : TransactionStmt *n = makeNode(TransactionStmt);
11251 :
11252 232 : n->kind = TRANS_STMT_ROLLBACK;
11253 232 : n->options = NIL;
11254 232 : n->chain = $3;
11255 232 : n->location = -1;
11256 232 : $$ = (Node *) n;
11257 : }
11258 : | START TRANSACTION transaction_mode_list_or_empty
11259 : {
11260 1646 : TransactionStmt *n = makeNode(TransactionStmt);
11261 :
11262 1646 : n->kind = TRANS_STMT_START;
11263 1646 : n->options = $3;
11264 1646 : n->location = -1;
11265 1646 : $$ = (Node *) n;
11266 : }
11267 : | COMMIT opt_transaction opt_transaction_chain
11268 : {
11269 12072 : TransactionStmt *n = makeNode(TransactionStmt);
11270 :
11271 12072 : n->kind = TRANS_STMT_COMMIT;
11272 12072 : n->options = NIL;
11273 12072 : n->chain = $3;
11274 12072 : n->location = -1;
11275 12072 : $$ = (Node *) n;
11276 : }
11277 : | ROLLBACK opt_transaction opt_transaction_chain
11278 : {
11279 2730 : TransactionStmt *n = makeNode(TransactionStmt);
11280 :
11281 2730 : n->kind = TRANS_STMT_ROLLBACK;
11282 2730 : n->options = NIL;
11283 2730 : n->chain = $3;
11284 2730 : n->location = -1;
11285 2730 : $$ = (Node *) n;
11286 : }
11287 : | SAVEPOINT ColId
11288 : {
11289 1972 : TransactionStmt *n = makeNode(TransactionStmt);
11290 :
11291 1972 : n->kind = TRANS_STMT_SAVEPOINT;
11292 1972 : n->savepoint_name = $2;
11293 1972 : n->location = @2;
11294 1972 : $$ = (Node *) n;
11295 : }
11296 : | RELEASE SAVEPOINT ColId
11297 : {
11298 208 : TransactionStmt *n = makeNode(TransactionStmt);
11299 :
11300 208 : n->kind = TRANS_STMT_RELEASE;
11301 208 : n->savepoint_name = $3;
11302 208 : n->location = @3;
11303 208 : $$ = (Node *) n;
11304 : }
11305 : | RELEASE ColId
11306 : {
11307 86 : TransactionStmt *n = makeNode(TransactionStmt);
11308 :
11309 86 : n->kind = TRANS_STMT_RELEASE;
11310 86 : n->savepoint_name = $2;
11311 86 : n->location = @2;
11312 86 : $$ = (Node *) n;
11313 : }
11314 : | ROLLBACK opt_transaction TO SAVEPOINT ColId
11315 : {
11316 240 : TransactionStmt *n = makeNode(TransactionStmt);
11317 :
11318 240 : n->kind = TRANS_STMT_ROLLBACK_TO;
11319 240 : n->savepoint_name = $5;
11320 240 : n->location = @5;
11321 240 : $$ = (Node *) n;
11322 : }
11323 : | ROLLBACK opt_transaction TO ColId
11324 : {
11325 496 : TransactionStmt *n = makeNode(TransactionStmt);
11326 :
11327 496 : n->kind = TRANS_STMT_ROLLBACK_TO;
11328 496 : n->savepoint_name = $4;
11329 496 : n->location = @4;
11330 496 : $$ = (Node *) n;
11331 : }
11332 : | PREPARE TRANSACTION Sconst
11333 : {
11334 668 : TransactionStmt *n = makeNode(TransactionStmt);
11335 :
11336 668 : n->kind = TRANS_STMT_PREPARE;
11337 668 : n->gid = $3;
11338 668 : n->location = @3;
11339 668 : $$ = (Node *) n;
11340 : }
11341 : | COMMIT PREPARED Sconst
11342 : {
11343 498 : TransactionStmt *n = makeNode(TransactionStmt);
11344 :
11345 498 : n->kind = TRANS_STMT_COMMIT_PREPARED;
11346 498 : n->gid = $3;
11347 498 : n->location = @3;
11348 498 : $$ = (Node *) n;
11349 : }
11350 : | ROLLBACK PREPARED Sconst
11351 : {
11352 84 : TransactionStmt *n = makeNode(TransactionStmt);
11353 :
11354 84 : n->kind = TRANS_STMT_ROLLBACK_PREPARED;
11355 84 : n->gid = $3;
11356 84 : n->location = @3;
11357 84 : $$ = (Node *) n;
11358 : }
11359 : ;
11360 :
11361 : TransactionStmtLegacy:
11362 : BEGIN_P opt_transaction transaction_mode_list_or_empty
11363 : {
11364 14790 : TransactionStmt *n = makeNode(TransactionStmt);
11365 :
11366 14790 : n->kind = TRANS_STMT_BEGIN;
11367 14790 : n->options = $3;
11368 14790 : n->location = -1;
11369 14790 : $$ = (Node *) n;
11370 : }
11371 : | END_P opt_transaction opt_transaction_chain
11372 : {
11373 370 : TransactionStmt *n = makeNode(TransactionStmt);
11374 :
11375 370 : n->kind = TRANS_STMT_COMMIT;
11376 370 : n->options = NIL;
11377 370 : n->chain = $3;
11378 370 : n->location = -1;
11379 370 : $$ = (Node *) n;
11380 : }
11381 : ;
11382 :
11383 : opt_transaction: WORK
11384 : | TRANSACTION
11385 : | /*EMPTY*/
11386 : ;
11387 :
11388 : transaction_mode_item:
11389 : ISOLATION LEVEL iso_level
11390 6914 : { $$ = makeDefElem("transaction_isolation",
11391 6914 : makeStringConst($3, @3), @1); }
11392 : | READ ONLY
11393 1418 : { $$ = makeDefElem("transaction_read_only",
11394 1418 : makeIntConst(true, @1), @1); }
11395 : | READ WRITE
11396 90 : { $$ = makeDefElem("transaction_read_only",
11397 90 : makeIntConst(false, @1), @1); }
11398 : | DEFERRABLE
11399 44 : { $$ = makeDefElem("transaction_deferrable",
11400 : makeIntConst(true, @1), @1); }
11401 : | NOT DEFERRABLE
11402 10 : { $$ = makeDefElem("transaction_deferrable",
11403 10 : makeIntConst(false, @1), @1); }
11404 : ;
11405 :
11406 : /* Syntax with commas is SQL-spec, without commas is Postgres historical */
11407 : transaction_mode_list:
11408 : transaction_mode_item
11409 7130 : { $$ = list_make1($1); }
11410 : | transaction_mode_list ',' transaction_mode_item
11411 940 : { $$ = lappend($1, $3); }
11412 : | transaction_mode_list transaction_mode_item
11413 406 : { $$ = lappend($1, $2); }
11414 : ;
11415 :
11416 : transaction_mode_list_or_empty:
11417 : transaction_mode_list
11418 : | /* EMPTY */
11419 9906 : { $$ = NIL; }
11420 : ;
11421 :
11422 : opt_transaction_chain:
11423 120 : AND CHAIN { $$ = true; }
11424 2 : | AND NO CHAIN { $$ = false; }
11425 15282 : | /* EMPTY */ { $$ = false; }
11426 : ;
11427 :
11428 :
11429 : /*****************************************************************************
11430 : *
11431 : * QUERY:
11432 : * CREATE [ OR REPLACE ] [ TEMP ] VIEW <viewname> '('target-list ')'
11433 : * AS <query> [ WITH [ CASCADED | LOCAL ] CHECK OPTION ]
11434 : *
11435 : *****************************************************************************/
11436 :
11437 : ViewStmt: CREATE OptTemp VIEW qualified_name opt_column_list opt_reloptions
11438 : AS SelectStmt opt_check_option
11439 : {
11440 16824 : ViewStmt *n = makeNode(ViewStmt);
11441 :
11442 16824 : n->view = $4;
11443 16824 : n->view->relpersistence = $2;
11444 16824 : n->aliases = $5;
11445 16824 : n->query = $8;
11446 16824 : n->replace = false;
11447 16824 : n->options = $6;
11448 16824 : n->withCheckOption = $9;
11449 16824 : $$ = (Node *) n;
11450 : }
11451 : | CREATE OR REPLACE OptTemp VIEW qualified_name opt_column_list opt_reloptions
11452 : AS SelectStmt opt_check_option
11453 : {
11454 244 : ViewStmt *n = makeNode(ViewStmt);
11455 :
11456 244 : n->view = $6;
11457 244 : n->view->relpersistence = $4;
11458 244 : n->aliases = $7;
11459 244 : n->query = $10;
11460 244 : n->replace = true;
11461 244 : n->options = $8;
11462 244 : n->withCheckOption = $11;
11463 244 : $$ = (Node *) n;
11464 : }
11465 : | CREATE OptTemp RECURSIVE VIEW qualified_name '(' columnList ')' opt_reloptions
11466 : AS SelectStmt opt_check_option
11467 : {
11468 8 : ViewStmt *n = makeNode(ViewStmt);
11469 :
11470 8 : n->view = $5;
11471 8 : n->view->relpersistence = $2;
11472 8 : n->aliases = $7;
11473 8 : n->query = makeRecursiveViewSelect(n->view->relname, n->aliases, $11);
11474 8 : n->replace = false;
11475 8 : n->options = $9;
11476 8 : n->withCheckOption = $12;
11477 8 : if (n->withCheckOption != NO_CHECK_OPTION)
11478 0 : ereport(ERROR,
11479 : (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
11480 : errmsg("WITH CHECK OPTION not supported on recursive views"),
11481 : parser_errposition(@12)));
11482 8 : $$ = (Node *) n;
11483 : }
11484 : | CREATE OR REPLACE OptTemp RECURSIVE VIEW qualified_name '(' columnList ')' opt_reloptions
11485 : AS SelectStmt opt_check_option
11486 : {
11487 6 : ViewStmt *n = makeNode(ViewStmt);
11488 :
11489 6 : n->view = $7;
11490 6 : n->view->relpersistence = $4;
11491 6 : n->aliases = $9;
11492 6 : n->query = makeRecursiveViewSelect(n->view->relname, n->aliases, $13);
11493 6 : n->replace = true;
11494 6 : n->options = $11;
11495 6 : n->withCheckOption = $14;
11496 6 : if (n->withCheckOption != NO_CHECK_OPTION)
11497 0 : ereport(ERROR,
11498 : (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
11499 : errmsg("WITH CHECK OPTION not supported on recursive views"),
11500 : parser_errposition(@14)));
11501 6 : $$ = (Node *) n;
11502 : }
11503 : ;
11504 :
11505 : opt_check_option:
11506 96 : WITH CHECK OPTION { $$ = CASCADED_CHECK_OPTION; }
11507 6 : | WITH CASCADED CHECK OPTION { $$ = CASCADED_CHECK_OPTION; }
11508 24 : | WITH LOCAL CHECK OPTION { $$ = LOCAL_CHECK_OPTION; }
11509 16956 : | /* EMPTY */ { $$ = NO_CHECK_OPTION; }
11510 : ;
11511 :
11512 : /*****************************************************************************
11513 : *
11514 : * QUERY:
11515 : * LOAD "filename"
11516 : *
11517 : *****************************************************************************/
11518 :
11519 : LoadStmt: LOAD file_name
11520 : {
11521 64 : LoadStmt *n = makeNode(LoadStmt);
11522 :
11523 64 : n->filename = $2;
11524 64 : $$ = (Node *) n;
11525 : }
11526 : ;
11527 :
11528 :
11529 : /*****************************************************************************
11530 : *
11531 : * CREATE DATABASE
11532 : *
11533 : *****************************************************************************/
11534 :
11535 : CreatedbStmt:
11536 : CREATE DATABASE name opt_with createdb_opt_list
11537 : {
11538 804 : CreatedbStmt *n = makeNode(CreatedbStmt);
11539 :
11540 804 : n->dbname = $3;
11541 804 : n->options = $5;
11542 804 : $$ = (Node *) n;
11543 : }
11544 : ;
11545 :
11546 : createdb_opt_list:
11547 658 : createdb_opt_items { $$ = $1; }
11548 208 : | /* EMPTY */ { $$ = NIL; }
11549 : ;
11550 :
11551 : createdb_opt_items:
11552 658 : createdb_opt_item { $$ = list_make1($1); }
11553 984 : | createdb_opt_items createdb_opt_item { $$ = lappend($1, $2); }
11554 : ;
11555 :
11556 : createdb_opt_item:
11557 : createdb_opt_name opt_equal NumericOnly
11558 : {
11559 266 : $$ = makeDefElem($1, $3, @1);
11560 : }
11561 : | createdb_opt_name opt_equal opt_boolean_or_string
11562 : {
11563 1376 : $$ = makeDefElem($1, (Node *) makeString($3), @1);
11564 : }
11565 : | createdb_opt_name opt_equal DEFAULT
11566 : {
11567 0 : $$ = makeDefElem($1, NULL, @1);
11568 : }
11569 : ;
11570 :
11571 : /*
11572 : * Ideally we'd use ColId here, but that causes shift/reduce conflicts against
11573 : * the ALTER DATABASE SET/RESET syntaxes. Instead call out specific keywords
11574 : * we need, and allow IDENT so that database option names don't have to be
11575 : * parser keywords unless they are already keywords for other reasons.
11576 : *
11577 : * XXX this coding technique is fragile since if someone makes a formerly
11578 : * non-keyword option name into a keyword and forgets to add it here, the
11579 : * option will silently break. Best defense is to provide a regression test
11580 : * exercising every such option, at least at the syntax level.
11581 : */
11582 : createdb_opt_name:
11583 1142 : IDENT { $$ = $1; }
11584 2 : | CONNECTION LIMIT { $$ = pstrdup("connection_limit"); }
11585 102 : | ENCODING { $$ = pstrdup($1); }
11586 0 : | LOCATION { $$ = pstrdup($1); }
11587 2 : | OWNER { $$ = pstrdup($1); }
11588 34 : | TABLESPACE { $$ = pstrdup($1); }
11589 360 : | TEMPLATE { $$ = pstrdup($1); }
11590 : ;
11591 :
11592 : /*
11593 : * Though the equals sign doesn't match other WITH options, pg_dump uses
11594 : * equals for backward compatibility, and it doesn't seem worth removing it.
11595 : */
11596 : opt_equal: '='
11597 : | /*EMPTY*/
11598 : ;
11599 :
11600 :
11601 : /*****************************************************************************
11602 : *
11603 : * ALTER DATABASE
11604 : *
11605 : *****************************************************************************/
11606 :
11607 : AlterDatabaseStmt:
11608 : ALTER DATABASE name WITH createdb_opt_list
11609 : {
11610 2 : AlterDatabaseStmt *n = makeNode(AlterDatabaseStmt);
11611 :
11612 2 : n->dbname = $3;
11613 2 : n->options = $5;
11614 2 : $$ = (Node *) n;
11615 : }
11616 : | ALTER DATABASE name createdb_opt_list
11617 : {
11618 60 : AlterDatabaseStmt *n = makeNode(AlterDatabaseStmt);
11619 :
11620 60 : n->dbname = $3;
11621 60 : n->options = $4;
11622 60 : $$ = (Node *) n;
11623 : }
11624 : | ALTER DATABASE name SET TABLESPACE name
11625 : {
11626 22 : AlterDatabaseStmt *n = makeNode(AlterDatabaseStmt);
11627 :
11628 22 : n->dbname = $3;
11629 22 : n->options = list_make1(makeDefElem("tablespace",
11630 : (Node *) makeString($6), @6));
11631 22 : $$ = (Node *) n;
11632 : }
11633 : | ALTER DATABASE name REFRESH COLLATION VERSION_P
11634 : {
11635 6 : AlterDatabaseRefreshCollStmt *n = makeNode(AlterDatabaseRefreshCollStmt);
11636 :
11637 6 : n->dbname = $3;
11638 6 : $$ = (Node *) n;
11639 : }
11640 : ;
11641 :
11642 : AlterDatabaseSetStmt:
11643 : ALTER DATABASE name SetResetClause
11644 : {
11645 1254 : AlterDatabaseSetStmt *n = makeNode(AlterDatabaseSetStmt);
11646 :
11647 1254 : n->dbname = $3;
11648 1254 : n->setstmt = $4;
11649 1254 : $$ = (Node *) n;
11650 : }
11651 : ;
11652 :
11653 :
11654 : /*****************************************************************************
11655 : *
11656 : * DROP DATABASE [ IF EXISTS ] dbname [ [ WITH ] ( options ) ]
11657 : *
11658 : * This is implicitly CASCADE, no need for drop behavior
11659 : *****************************************************************************/
11660 :
11661 : DropdbStmt: DROP DATABASE name
11662 : {
11663 94 : DropdbStmt *n = makeNode(DropdbStmt);
11664 :
11665 94 : n->dbname = $3;
11666 94 : n->missing_ok = false;
11667 94 : n->options = NULL;
11668 94 : $$ = (Node *) n;
11669 : }
11670 : | DROP DATABASE IF_P EXISTS name
11671 : {
11672 4 : DropdbStmt *n = makeNode(DropdbStmt);
11673 :
11674 4 : n->dbname = $5;
11675 4 : n->missing_ok = true;
11676 4 : n->options = NULL;
11677 4 : $$ = (Node *) n;
11678 : }
11679 : | DROP DATABASE name opt_with '(' drop_option_list ')'
11680 : {
11681 14 : DropdbStmt *n = makeNode(DropdbStmt);
11682 :
11683 14 : n->dbname = $3;
11684 14 : n->missing_ok = false;
11685 14 : n->options = $6;
11686 14 : $$ = (Node *) n;
11687 : }
11688 : | DROP DATABASE IF_P EXISTS name opt_with '(' drop_option_list ')'
11689 : {
11690 12 : DropdbStmt *n = makeNode(DropdbStmt);
11691 :
11692 12 : n->dbname = $5;
11693 12 : n->missing_ok = true;
11694 12 : n->options = $8;
11695 12 : $$ = (Node *) n;
11696 : }
11697 : ;
11698 :
11699 : drop_option_list:
11700 : drop_option
11701 : {
11702 26 : $$ = list_make1((Node *) $1);
11703 : }
11704 : | drop_option_list ',' drop_option
11705 : {
11706 0 : $$ = lappend($1, (Node *) $3);
11707 : }
11708 : ;
11709 :
11710 : /*
11711 : * Currently only the FORCE option is supported, but the syntax is designed
11712 : * to be extensible so that we can add more options in the future if required.
11713 : */
11714 : drop_option:
11715 : FORCE
11716 : {
11717 26 : $$ = makeDefElem("force", NULL, @1);
11718 : }
11719 : ;
11720 :
11721 : /*****************************************************************************
11722 : *
11723 : * ALTER COLLATION
11724 : *
11725 : *****************************************************************************/
11726 :
11727 : AlterCollationStmt: ALTER COLLATION any_name REFRESH VERSION_P
11728 : {
11729 6 : AlterCollationStmt *n = makeNode(AlterCollationStmt);
11730 :
11731 6 : n->collname = $3;
11732 6 : $$ = (Node *) n;
11733 : }
11734 : ;
11735 :
11736 :
11737 : /*****************************************************************************
11738 : *
11739 : * ALTER SYSTEM
11740 : *
11741 : * This is used to change configuration parameters persistently.
11742 : *****************************************************************************/
11743 :
11744 : AlterSystemStmt:
11745 : ALTER SYSTEM_P SET generic_set
11746 : {
11747 134 : AlterSystemStmt *n = makeNode(AlterSystemStmt);
11748 :
11749 134 : n->setstmt = $4;
11750 134 : $$ = (Node *) n;
11751 : }
11752 : | ALTER SYSTEM_P RESET generic_reset
11753 : {
11754 58 : AlterSystemStmt *n = makeNode(AlterSystemStmt);
11755 :
11756 58 : n->setstmt = $4;
11757 58 : $$ = (Node *) n;
11758 : }
11759 : ;
11760 :
11761 :
11762 : /*****************************************************************************
11763 : *
11764 : * Manipulate a domain
11765 : *
11766 : *****************************************************************************/
11767 :
11768 : CreateDomainStmt:
11769 : CREATE DOMAIN_P any_name opt_as Typename ColQualList
11770 : {
11771 1464 : CreateDomainStmt *n = makeNode(CreateDomainStmt);
11772 :
11773 1464 : n->domainname = $3;
11774 1464 : n->typeName = $5;
11775 1464 : SplitColQualList($6, &n->constraints, &n->collClause,
11776 : yyscanner);
11777 1464 : $$ = (Node *) n;
11778 : }
11779 : ;
11780 :
11781 : AlterDomainStmt:
11782 : /* ALTER DOMAIN <domain> {SET DEFAULT <expr>|DROP DEFAULT} */
11783 : ALTER DOMAIN_P any_name alter_column_default
11784 : {
11785 14 : AlterDomainStmt *n = makeNode(AlterDomainStmt);
11786 :
11787 14 : n->subtype = AD_AlterDefault;
11788 14 : n->typeName = $3;
11789 14 : n->def = $4;
11790 14 : $$ = (Node *) n;
11791 : }
11792 : /* ALTER DOMAIN <domain> DROP NOT NULL */
11793 : | ALTER DOMAIN_P any_name DROP NOT NULL_P
11794 : {
11795 12 : AlterDomainStmt *n = makeNode(AlterDomainStmt);
11796 :
11797 12 : n->subtype = AD_DropNotNull;
11798 12 : n->typeName = $3;
11799 12 : $$ = (Node *) n;
11800 : }
11801 : /* ALTER DOMAIN <domain> SET NOT NULL */
11802 : | ALTER DOMAIN_P any_name SET NOT NULL_P
11803 : {
11804 24 : AlterDomainStmt *n = makeNode(AlterDomainStmt);
11805 :
11806 24 : n->subtype = AD_SetNotNull;
11807 24 : n->typeName = $3;
11808 24 : $$ = (Node *) n;
11809 : }
11810 : /* ALTER DOMAIN <domain> ADD CONSTRAINT ... */
11811 : | ALTER DOMAIN_P any_name ADD_P DomainConstraint
11812 : {
11813 182 : AlterDomainStmt *n = makeNode(AlterDomainStmt);
11814 :
11815 182 : n->subtype = AD_AddConstraint;
11816 182 : n->typeName = $3;
11817 182 : n->def = $5;
11818 182 : $$ = (Node *) n;
11819 : }
11820 : /* ALTER DOMAIN <domain> DROP CONSTRAINT <name> [RESTRICT|CASCADE] */
11821 : | ALTER DOMAIN_P any_name DROP CONSTRAINT name opt_drop_behavior
11822 : {
11823 54 : AlterDomainStmt *n = makeNode(AlterDomainStmt);
11824 :
11825 54 : n->subtype = AD_DropConstraint;
11826 54 : n->typeName = $3;
11827 54 : n->name = $6;
11828 54 : n->behavior = $7;
11829 54 : n->missing_ok = false;
11830 54 : $$ = (Node *) n;
11831 : }
11832 : /* ALTER DOMAIN <domain> DROP CONSTRAINT IF EXISTS <name> [RESTRICT|CASCADE] */
11833 : | ALTER DOMAIN_P any_name DROP CONSTRAINT IF_P EXISTS name opt_drop_behavior
11834 : {
11835 6 : AlterDomainStmt *n = makeNode(AlterDomainStmt);
11836 :
11837 6 : n->subtype = AD_DropConstraint;
11838 6 : n->typeName = $3;
11839 6 : n->name = $8;
11840 6 : n->behavior = $9;
11841 6 : n->missing_ok = true;
11842 6 : $$ = (Node *) n;
11843 : }
11844 : /* ALTER DOMAIN <domain> VALIDATE CONSTRAINT <name> */
11845 : | ALTER DOMAIN_P any_name VALIDATE CONSTRAINT name
11846 : {
11847 12 : AlterDomainStmt *n = makeNode(AlterDomainStmt);
11848 :
11849 12 : n->subtype = AD_ValidateConstraint;
11850 12 : n->typeName = $3;
11851 12 : n->name = $6;
11852 12 : $$ = (Node *) n;
11853 : }
11854 : ;
11855 :
11856 : opt_as: AS
11857 : | /* EMPTY */
11858 : ;
11859 :
11860 :
11861 : /*****************************************************************************
11862 : *
11863 : * Manipulate a text search dictionary or configuration
11864 : *
11865 : *****************************************************************************/
11866 :
11867 : AlterTSDictionaryStmt:
11868 : ALTER TEXT_P SEARCH DICTIONARY any_name definition
11869 : {
11870 40 : AlterTSDictionaryStmt *n = makeNode(AlterTSDictionaryStmt);
11871 :
11872 40 : n->dictname = $5;
11873 40 : n->options = $6;
11874 40 : $$ = (Node *) n;
11875 : }
11876 : ;
11877 :
11878 : AlterTSConfigurationStmt:
11879 : ALTER TEXT_P SEARCH CONFIGURATION any_name ADD_P MAPPING FOR name_list any_with any_name_list
11880 : {
11881 8518 : AlterTSConfigurationStmt *n = makeNode(AlterTSConfigurationStmt);
11882 :
11883 8518 : n->kind = ALTER_TSCONFIG_ADD_MAPPING;
11884 8518 : n->cfgname = $5;
11885 8518 : n->tokentype = $9;
11886 8518 : n->dicts = $11;
11887 8518 : n->override = false;
11888 8518 : n->replace = false;
11889 8518 : $$ = (Node *) n;
11890 : }
11891 : | ALTER TEXT_P SEARCH CONFIGURATION any_name ALTER MAPPING FOR name_list any_with any_name_list
11892 : {
11893 26 : AlterTSConfigurationStmt *n = makeNode(AlterTSConfigurationStmt);
11894 :
11895 26 : n->kind = ALTER_TSCONFIG_ALTER_MAPPING_FOR_TOKEN;
11896 26 : n->cfgname = $5;
11897 26 : n->tokentype = $9;
11898 26 : n->dicts = $11;
11899 26 : n->override = true;
11900 26 : n->replace = false;
11901 26 : $$ = (Node *) n;
11902 : }
11903 : | ALTER TEXT_P SEARCH CONFIGURATION any_name ALTER MAPPING REPLACE any_name any_with any_name
11904 : {
11905 18 : AlterTSConfigurationStmt *n = makeNode(AlterTSConfigurationStmt);
11906 :
11907 18 : n->kind = ALTER_TSCONFIG_REPLACE_DICT;
11908 18 : n->cfgname = $5;
11909 18 : n->tokentype = NIL;
11910 18 : n->dicts = list_make2($9,$11);
11911 18 : n->override = false;
11912 18 : n->replace = true;
11913 18 : $$ = (Node *) n;
11914 : }
11915 : | ALTER TEXT_P SEARCH CONFIGURATION any_name ALTER MAPPING FOR name_list REPLACE any_name any_with any_name
11916 : {
11917 0 : AlterTSConfigurationStmt *n = makeNode(AlterTSConfigurationStmt);
11918 :
11919 0 : n->kind = ALTER_TSCONFIG_REPLACE_DICT_FOR_TOKEN;
11920 0 : n->cfgname = $5;
11921 0 : n->tokentype = $9;
11922 0 : n->dicts = list_make2($11,$13);
11923 0 : n->override = false;
11924 0 : n->replace = true;
11925 0 : $$ = (Node *) n;
11926 : }
11927 : | ALTER TEXT_P SEARCH CONFIGURATION any_name DROP MAPPING FOR name_list
11928 : {
11929 18 : AlterTSConfigurationStmt *n = makeNode(AlterTSConfigurationStmt);
11930 :
11931 18 : n->kind = ALTER_TSCONFIG_DROP_MAPPING;
11932 18 : n->cfgname = $5;
11933 18 : n->tokentype = $9;
11934 18 : n->missing_ok = false;
11935 18 : $$ = (Node *) n;
11936 : }
11937 : | ALTER TEXT_P SEARCH CONFIGURATION any_name DROP MAPPING IF_P EXISTS FOR name_list
11938 : {
11939 12 : AlterTSConfigurationStmt *n = makeNode(AlterTSConfigurationStmt);
11940 :
11941 12 : n->kind = ALTER_TSCONFIG_DROP_MAPPING;
11942 12 : n->cfgname = $5;
11943 12 : n->tokentype = $11;
11944 12 : n->missing_ok = true;
11945 12 : $$ = (Node *) n;
11946 : }
11947 : ;
11948 :
11949 : /* Use this if TIME or ORDINALITY after WITH should be taken as an identifier */
11950 : any_with: WITH
11951 : | WITH_LA
11952 : ;
11953 :
11954 :
11955 : /*****************************************************************************
11956 : *
11957 : * Manipulate a conversion
11958 : *
11959 : * CREATE [DEFAULT] CONVERSION <conversion_name>
11960 : * FOR <encoding_name> TO <encoding_name> FROM <func_name>
11961 : *
11962 : *****************************************************************************/
11963 :
11964 : CreateConversionStmt:
11965 : CREATE opt_default CONVERSION_P any_name FOR Sconst
11966 : TO Sconst FROM any_name
11967 : {
11968 64 : CreateConversionStmt *n = makeNode(CreateConversionStmt);
11969 :
11970 64 : n->conversion_name = $4;
11971 64 : n->for_encoding_name = $6;
11972 64 : n->to_encoding_name = $8;
11973 64 : n->func_name = $10;
11974 64 : n->def = $2;
11975 64 : $$ = (Node *) n;
11976 : }
11977 : ;
11978 :
11979 : /*****************************************************************************
11980 : *
11981 : * QUERY:
11982 : * CLUSTER (options) [ <qualified_name> [ USING <index_name> ] ]
11983 : * CLUSTER [VERBOSE] [ <qualified_name> [ USING <index_name> ] ]
11984 : * CLUSTER [VERBOSE] <index_name> ON <qualified_name> (for pre-8.3)
11985 : *
11986 : *****************************************************************************/
11987 :
11988 : ClusterStmt:
11989 : CLUSTER '(' utility_option_list ')' qualified_name cluster_index_specification
11990 : {
11991 0 : ClusterStmt *n = makeNode(ClusterStmt);
11992 :
11993 0 : n->relation = $5;
11994 0 : n->indexname = $6;
11995 0 : n->params = $3;
11996 0 : $$ = (Node *) n;
11997 : }
11998 : | CLUSTER opt_utility_option_list
11999 : {
12000 16 : ClusterStmt *n = makeNode(ClusterStmt);
12001 :
12002 16 : n->relation = NULL;
12003 16 : n->indexname = NULL;
12004 16 : n->params = $2;
12005 16 : $$ = (Node *) n;
12006 : }
12007 : /* unparenthesized VERBOSE kept for pre-14 compatibility */
12008 : | CLUSTER opt_verbose qualified_name cluster_index_specification
12009 : {
12010 190 : ClusterStmt *n = makeNode(ClusterStmt);
12011 :
12012 190 : n->relation = $3;
12013 190 : n->indexname = $4;
12014 190 : if ($2)
12015 0 : n->params = list_make1(makeDefElem("verbose", NULL, @2));
12016 190 : $$ = (Node *) n;
12017 : }
12018 : /* unparenthesized VERBOSE kept for pre-17 compatibility */
12019 : | CLUSTER VERBOSE
12020 : {
12021 2 : ClusterStmt *n = makeNode(ClusterStmt);
12022 :
12023 2 : n->relation = NULL;
12024 2 : n->indexname = NULL;
12025 2 : n->params = list_make1(makeDefElem("verbose", NULL, @2));
12026 2 : $$ = (Node *) n;
12027 : }
12028 : /* kept for pre-8.3 compatibility */
12029 : | CLUSTER opt_verbose name ON qualified_name
12030 : {
12031 20 : ClusterStmt *n = makeNode(ClusterStmt);
12032 :
12033 20 : n->relation = $5;
12034 20 : n->indexname = $3;
12035 20 : if ($2)
12036 0 : n->params = list_make1(makeDefElem("verbose", NULL, @2));
12037 20 : $$ = (Node *) n;
12038 : }
12039 : ;
12040 :
12041 : cluster_index_specification:
12042 156 : USING name { $$ = $2; }
12043 34 : | /*EMPTY*/ { $$ = NULL; }
12044 : ;
12045 :
12046 :
12047 : /*****************************************************************************
12048 : *
12049 : * QUERY:
12050 : * VACUUM
12051 : * ANALYZE
12052 : *
12053 : *****************************************************************************/
12054 :
12055 : VacuumStmt: VACUUM opt_full opt_freeze opt_verbose opt_analyze opt_vacuum_relation_list
12056 : {
12057 1248 : VacuumStmt *n = makeNode(VacuumStmt);
12058 :
12059 1248 : n->options = NIL;
12060 1248 : if ($2)
12061 152 : n->options = lappend(n->options,
12062 152 : makeDefElem("full", NULL, @2));
12063 1248 : if ($3)
12064 162 : n->options = lappend(n->options,
12065 162 : makeDefElem("freeze", NULL, @3));
12066 1248 : if ($4)
12067 16 : n->options = lappend(n->options,
12068 16 : makeDefElem("verbose", NULL, @4));
12069 1248 : if ($5)
12070 304 : n->options = lappend(n->options,
12071 304 : makeDefElem("analyze", NULL, @5));
12072 1248 : n->rels = $6;
12073 1248 : n->is_vacuumcmd = true;
12074 1248 : $$ = (Node *) n;
12075 : }
12076 : | VACUUM '(' utility_option_list ')' opt_vacuum_relation_list
12077 : {
12078 8032 : VacuumStmt *n = makeNode(VacuumStmt);
12079 :
12080 8032 : n->options = $3;
12081 8032 : n->rels = $5;
12082 8032 : n->is_vacuumcmd = true;
12083 8032 : $$ = (Node *) n;
12084 : }
12085 : ;
12086 :
12087 : AnalyzeStmt: analyze_keyword opt_utility_option_list opt_vacuum_relation_list
12088 : {
12089 4928 : VacuumStmt *n = makeNode(VacuumStmt);
12090 :
12091 4928 : n->options = $2;
12092 4928 : n->rels = $3;
12093 4928 : n->is_vacuumcmd = false;
12094 4928 : $$ = (Node *) n;
12095 : }
12096 : | analyze_keyword VERBOSE opt_vacuum_relation_list
12097 : {
12098 0 : VacuumStmt *n = makeNode(VacuumStmt);
12099 :
12100 0 : n->options = list_make1(makeDefElem("verbose", NULL, @2));
12101 0 : n->rels = $3;
12102 0 : n->is_vacuumcmd = false;
12103 0 : $$ = (Node *) n;
12104 : }
12105 : ;
12106 :
12107 : analyze_keyword:
12108 : ANALYZE
12109 : | ANALYSE /* British */
12110 : ;
12111 :
12112 : opt_analyze:
12113 304 : analyze_keyword { $$ = true; }
12114 944 : | /*EMPTY*/ { $$ = false; }
12115 : ;
12116 :
12117 : opt_verbose:
12118 16 : VERBOSE { $$ = true; }
12119 3758 : | /*EMPTY*/ { $$ = false; }
12120 : ;
12121 :
12122 152 : opt_full: FULL { $$ = true; }
12123 1096 : | /*EMPTY*/ { $$ = false; }
12124 : ;
12125 :
12126 162 : opt_freeze: FREEZE { $$ = true; }
12127 1086 : | /*EMPTY*/ { $$ = false; }
12128 : ;
12129 :
12130 : opt_name_list:
12131 2850 : '(' name_list ')' { $$ = $2; }
12132 16670 : | /*EMPTY*/ { $$ = NIL; }
12133 : ;
12134 :
12135 : vacuum_relation:
12136 : relation_expr opt_name_list
12137 : {
12138 14036 : $$ = (Node *) makeVacuumRelation($1, InvalidOid, $2);
12139 : }
12140 : ;
12141 :
12142 : vacuum_relation_list:
12143 : vacuum_relation
12144 13848 : { $$ = list_make1($1); }
12145 : | vacuum_relation_list ',' vacuum_relation
12146 188 : { $$ = lappend($1, $3); }
12147 : ;
12148 :
12149 : opt_vacuum_relation_list:
12150 13848 : vacuum_relation_list { $$ = $1; }
12151 360 : | /*EMPTY*/ { $$ = NIL; }
12152 : ;
12153 :
12154 :
12155 : /*****************************************************************************
12156 : *
12157 : * QUERY:
12158 : * EXPLAIN [ANALYZE] [VERBOSE] query
12159 : * EXPLAIN ( options ) query
12160 : *
12161 : *****************************************************************************/
12162 :
12163 : ExplainStmt:
12164 : EXPLAIN ExplainableStmt
12165 : {
12166 7786 : ExplainStmt *n = makeNode(ExplainStmt);
12167 :
12168 7786 : n->query = $2;
12169 7786 : n->options = NIL;
12170 7786 : $$ = (Node *) n;
12171 : }
12172 : | EXPLAIN analyze_keyword opt_verbose ExplainableStmt
12173 : {
12174 2316 : ExplainStmt *n = makeNode(ExplainStmt);
12175 :
12176 2316 : n->query = $4;
12177 2316 : n->options = list_make1(makeDefElem("analyze", NULL, @2));
12178 2316 : if ($3)
12179 0 : n->options = lappend(n->options,
12180 0 : makeDefElem("verbose", NULL, @3));
12181 2316 : $$ = (Node *) n;
12182 : }
12183 : | EXPLAIN VERBOSE ExplainableStmt
12184 : {
12185 12 : ExplainStmt *n = makeNode(ExplainStmt);
12186 :
12187 12 : n->query = $3;
12188 12 : n->options = list_make1(makeDefElem("verbose", NULL, @2));
12189 12 : $$ = (Node *) n;
12190 : }
12191 : | EXPLAIN '(' utility_option_list ')' ExplainableStmt
12192 : {
12193 14464 : ExplainStmt *n = makeNode(ExplainStmt);
12194 :
12195 14464 : n->query = $5;
12196 14464 : n->options = $3;
12197 14464 : $$ = (Node *) n;
12198 : }
12199 : ;
12200 :
12201 : ExplainableStmt:
12202 : SelectStmt
12203 : | InsertStmt
12204 : | UpdateStmt
12205 : | DeleteStmt
12206 : | MergeStmt
12207 : | DeclareCursorStmt
12208 : | CreateAsStmt
12209 : | CreateMatViewStmt
12210 : | RefreshMatViewStmt
12211 : | ExecuteStmt /* by default all are $$=$1 */
12212 : ;
12213 :
12214 : /*****************************************************************************
12215 : *
12216 : * QUERY:
12217 : * PREPARE <plan_name> [(args, ...)] AS <query>
12218 : *
12219 : *****************************************************************************/
12220 :
12221 : PrepareStmt: PREPARE name prep_type_clause AS PreparableStmt
12222 : {
12223 1934 : PrepareStmt *n = makeNode(PrepareStmt);
12224 :
12225 1934 : n->name = $2;
12226 1934 : n->argtypes = $3;
12227 1934 : n->query = $5;
12228 1934 : $$ = (Node *) n;
12229 : }
12230 : ;
12231 :
12232 1612 : prep_type_clause: '(' type_list ')' { $$ = $2; }
12233 340 : | /* EMPTY */ { $$ = NIL; }
12234 : ;
12235 :
12236 : PreparableStmt:
12237 : SelectStmt
12238 : | InsertStmt
12239 : | UpdateStmt
12240 : | DeleteStmt
12241 : | MergeStmt /* by default all are $$=$1 */
12242 : ;
12243 :
12244 : /*****************************************************************************
12245 : *
12246 : * EXECUTE <plan_name> [(params, ...)]
12247 : * CREATE TABLE <name> AS EXECUTE <plan_name> [(params, ...)]
12248 : *
12249 : *****************************************************************************/
12250 :
12251 : ExecuteStmt: EXECUTE name execute_param_clause
12252 : {
12253 16162 : ExecuteStmt *n = makeNode(ExecuteStmt);
12254 :
12255 16162 : n->name = $2;
12256 16162 : n->params = $3;
12257 16162 : $$ = (Node *) n;
12258 : }
12259 : | CREATE OptTemp TABLE create_as_target AS
12260 : EXECUTE name execute_param_clause opt_with_data
12261 : {
12262 76 : CreateTableAsStmt *ctas = makeNode(CreateTableAsStmt);
12263 76 : ExecuteStmt *n = makeNode(ExecuteStmt);
12264 :
12265 76 : n->name = $7;
12266 76 : n->params = $8;
12267 76 : ctas->query = (Node *) n;
12268 76 : ctas->into = $4;
12269 76 : ctas->objtype = OBJECT_TABLE;
12270 76 : ctas->is_select_into = false;
12271 76 : ctas->if_not_exists = false;
12272 : /* cram additional flags into the IntoClause */
12273 76 : $4->rel->relpersistence = $2;
12274 76 : $4->skipData = !($9);
12275 76 : $$ = (Node *) ctas;
12276 : }
12277 : | CREATE OptTemp TABLE IF_P NOT EXISTS create_as_target AS
12278 : EXECUTE name execute_param_clause opt_with_data
12279 : {
12280 12 : CreateTableAsStmt *ctas = makeNode(CreateTableAsStmt);
12281 12 : ExecuteStmt *n = makeNode(ExecuteStmt);
12282 :
12283 12 : n->name = $10;
12284 12 : n->params = $11;
12285 12 : ctas->query = (Node *) n;
12286 12 : ctas->into = $7;
12287 12 : ctas->objtype = OBJECT_TABLE;
12288 12 : ctas->is_select_into = false;
12289 12 : ctas->if_not_exists = true;
12290 : /* cram additional flags into the IntoClause */
12291 12 : $7->rel->relpersistence = $2;
12292 12 : $7->skipData = !($12);
12293 12 : $$ = (Node *) ctas;
12294 : }
12295 : ;
12296 :
12297 15088 : execute_param_clause: '(' expr_list ')' { $$ = $2; }
12298 1162 : | /* EMPTY */ { $$ = NIL; }
12299 : ;
12300 :
12301 : /*****************************************************************************
12302 : *
12303 : * QUERY:
12304 : * DEALLOCATE [PREPARE] <plan_name>
12305 : *
12306 : *****************************************************************************/
12307 :
12308 : DeallocateStmt: DEALLOCATE name
12309 : {
12310 4004 : DeallocateStmt *n = makeNode(DeallocateStmt);
12311 :
12312 4004 : n->name = $2;
12313 4004 : n->isall = false;
12314 4004 : n->location = @2;
12315 4004 : $$ = (Node *) n;
12316 : }
12317 : | DEALLOCATE PREPARE name
12318 : {
12319 20 : DeallocateStmt *n = makeNode(DeallocateStmt);
12320 :
12321 20 : n->name = $3;
12322 20 : n->isall = false;
12323 20 : n->location = @3;
12324 20 : $$ = (Node *) n;
12325 : }
12326 : | DEALLOCATE ALL
12327 : {
12328 70 : DeallocateStmt *n = makeNode(DeallocateStmt);
12329 :
12330 70 : n->name = NULL;
12331 70 : n->isall = true;
12332 70 : n->location = -1;
12333 70 : $$ = (Node *) n;
12334 : }
12335 : | DEALLOCATE PREPARE ALL
12336 : {
12337 2 : DeallocateStmt *n = makeNode(DeallocateStmt);
12338 :
12339 2 : n->name = NULL;
12340 2 : n->isall = true;
12341 2 : n->location = -1;
12342 2 : $$ = (Node *) n;
12343 : }
12344 : ;
12345 :
12346 : /*****************************************************************************
12347 : *
12348 : * QUERY:
12349 : * INSERT STATEMENTS
12350 : *
12351 : *****************************************************************************/
12352 :
12353 : InsertStmt:
12354 : opt_with_clause INSERT INTO insert_target insert_rest
12355 : opt_on_conflict returning_clause
12356 : {
12357 69308 : $5->relation = $4;
12358 69308 : $5->onConflictClause = $6;
12359 69308 : $5->returningClause = $7;
12360 69308 : $5->withClause = $1;
12361 69308 : $$ = (Node *) $5;
12362 : }
12363 : ;
12364 :
12365 : /*
12366 : * Can't easily make AS optional here, because VALUES in insert_rest would
12367 : * have a shift/reduce conflict with VALUES as an optional alias. We could
12368 : * easily allow unreserved_keywords as optional aliases, but that'd be an odd
12369 : * divergence from other places. So just require AS for now.
12370 : */
12371 : insert_target:
12372 : qualified_name
12373 : {
12374 69182 : $$ = $1;
12375 : }
12376 : | qualified_name AS ColId
12377 : {
12378 132 : $1->alias = makeAlias($3, NIL);
12379 132 : $$ = $1;
12380 : }
12381 : ;
12382 :
12383 : insert_rest:
12384 : SelectStmt
12385 : {
12386 44070 : $$ = makeNode(InsertStmt);
12387 44070 : $$->cols = NIL;
12388 44070 : $$->selectStmt = $1;
12389 : }
12390 : | OVERRIDING override_kind VALUE_P SelectStmt
12391 : {
12392 96 : $$ = makeNode(InsertStmt);
12393 96 : $$->cols = NIL;
12394 96 : $$->override = $2;
12395 96 : $$->selectStmt = $4;
12396 : }
12397 : | '(' insert_column_list ')' SelectStmt
12398 : {
12399 14316 : $$ = makeNode(InsertStmt);
12400 14316 : $$->cols = $2;
12401 14316 : $$->selectStmt = $4;
12402 : }
12403 : | '(' insert_column_list ')' OVERRIDING override_kind VALUE_P SelectStmt
12404 : {
12405 0 : $$ = makeNode(InsertStmt);
12406 0 : $$->cols = $2;
12407 0 : $$->override = $5;
12408 0 : $$->selectStmt = $7;
12409 : }
12410 : | DEFAULT VALUES
12411 : {
12412 10832 : $$ = makeNode(InsertStmt);
12413 10832 : $$->cols = NIL;
12414 10832 : $$->selectStmt = NULL;
12415 : }
12416 : ;
12417 :
12418 : override_kind:
12419 66 : USER { $$ = OVERRIDING_USER_VALUE; }
12420 60 : | SYSTEM_P { $$ = OVERRIDING_SYSTEM_VALUE; }
12421 : ;
12422 :
12423 : insert_column_list:
12424 : insert_column_item
12425 14650 : { $$ = list_make1($1); }
12426 : | insert_column_list ',' insert_column_item
12427 16220 : { $$ = lappend($1, $3); }
12428 : ;
12429 :
12430 : insert_column_item:
12431 : ColId opt_indirection
12432 : {
12433 30870 : $$ = makeNode(ResTarget);
12434 30870 : $$->name = $1;
12435 30870 : $$->indirection = check_indirection($2, yyscanner);
12436 30870 : $$->val = NULL;
12437 30870 : $$->location = @1;
12438 : }
12439 : ;
12440 :
12441 : opt_on_conflict:
12442 : ON CONFLICT opt_conf_expr DO UPDATE SET set_clause_list where_clause
12443 : {
12444 1384 : $$ = makeNode(OnConflictClause);
12445 1384 : $$->action = ONCONFLICT_UPDATE;
12446 1384 : $$->infer = $3;
12447 1384 : $$->targetList = $7;
12448 1384 : $$->whereClause = $8;
12449 1384 : $$->location = @1;
12450 : }
12451 : |
12452 : ON CONFLICT opt_conf_expr DO NOTHING
12453 : {
12454 580 : $$ = makeNode(OnConflictClause);
12455 580 : $$->action = ONCONFLICT_NOTHING;
12456 580 : $$->infer = $3;
12457 580 : $$->targetList = NIL;
12458 580 : $$->whereClause = NULL;
12459 580 : $$->location = @1;
12460 : }
12461 : | /*EMPTY*/
12462 : {
12463 67350 : $$ = NULL;
12464 : }
12465 : ;
12466 :
12467 : opt_conf_expr:
12468 : '(' index_params ')' where_clause
12469 : {
12470 1508 : $$ = makeNode(InferClause);
12471 1508 : $$->indexElems = $2;
12472 1508 : $$->whereClause = $4;
12473 1508 : $$->conname = NULL;
12474 1508 : $$->location = @1;
12475 : }
12476 : |
12477 : ON CONSTRAINT name
12478 : {
12479 204 : $$ = makeNode(InferClause);
12480 204 : $$->indexElems = NIL;
12481 204 : $$->whereClause = NULL;
12482 204 : $$->conname = $3;
12483 204 : $$->location = @1;
12484 : }
12485 : | /*EMPTY*/
12486 : {
12487 252 : $$ = NULL;
12488 : }
12489 : ;
12490 :
12491 : returning_clause:
12492 : RETURNING returning_with_clause target_list
12493 : {
12494 3262 : ReturningClause *n = makeNode(ReturningClause);
12495 :
12496 3262 : n->options = $2;
12497 3262 : n->exprs = $3;
12498 3262 : $$ = n;
12499 : }
12500 : | /* EMPTY */
12501 : {
12502 87302 : $$ = NULL;
12503 : }
12504 : ;
12505 :
12506 : returning_with_clause:
12507 72 : WITH '(' returning_options ')' { $$ = $3; }
12508 3190 : | /* EMPTY */ { $$ = NIL; }
12509 : ;
12510 :
12511 : returning_options:
12512 72 : returning_option { $$ = list_make1($1); }
12513 54 : | returning_options ',' returning_option { $$ = lappend($1, $3); }
12514 : ;
12515 :
12516 : returning_option:
12517 : returning_option_kind AS ColId
12518 : {
12519 126 : ReturningOption *n = makeNode(ReturningOption);
12520 :
12521 126 : n->option = $1;
12522 126 : n->value = $3;
12523 126 : n->location = @1;
12524 126 : $$ = (Node *) n;
12525 : }
12526 : ;
12527 :
12528 : returning_option_kind:
12529 54 : OLD { $$ = RETURNING_OPTION_OLD; }
12530 72 : | NEW { $$ = RETURNING_OPTION_NEW; }
12531 : ;
12532 :
12533 :
12534 : /*****************************************************************************
12535 : *
12536 : * QUERY:
12537 : * DELETE STATEMENTS
12538 : *
12539 : *****************************************************************************/
12540 :
12541 : DeleteStmt: opt_with_clause DELETE_P FROM relation_expr_opt_alias
12542 : using_clause where_or_current_clause returning_clause
12543 : {
12544 4700 : DeleteStmt *n = makeNode(DeleteStmt);
12545 :
12546 4700 : n->relation = $4;
12547 4700 : n->usingClause = $5;
12548 4700 : n->whereClause = $6;
12549 4700 : n->returningClause = $7;
12550 4700 : n->withClause = $1;
12551 4700 : $$ = (Node *) n;
12552 : }
12553 : ;
12554 :
12555 : using_clause:
12556 108 : USING from_list { $$ = $2; }
12557 4592 : | /*EMPTY*/ { $$ = NIL; }
12558 : ;
12559 :
12560 :
12561 : /*****************************************************************************
12562 : *
12563 : * QUERY:
12564 : * LOCK TABLE
12565 : *
12566 : *****************************************************************************/
12567 :
12568 : LockStmt: LOCK_P opt_table relation_expr_list opt_lock opt_nowait
12569 : {
12570 1046 : LockStmt *n = makeNode(LockStmt);
12571 :
12572 1046 : n->relations = $3;
12573 1046 : n->mode = $4;
12574 1046 : n->nowait = $5;
12575 1046 : $$ = (Node *) n;
12576 : }
12577 : ;
12578 :
12579 938 : opt_lock: IN_P lock_type MODE { $$ = $2; }
12580 108 : | /*EMPTY*/ { $$ = AccessExclusiveLock; }
12581 : ;
12582 :
12583 448 : lock_type: ACCESS SHARE { $$ = AccessShareLock; }
12584 14 : | ROW SHARE { $$ = RowShareLock; }
12585 88 : | ROW EXCLUSIVE { $$ = RowExclusiveLock; }
12586 66 : | SHARE UPDATE EXCLUSIVE { $$ = ShareUpdateExclusiveLock; }
12587 80 : | SHARE { $$ = ShareLock; }
12588 14 : | SHARE ROW EXCLUSIVE { $$ = ShareRowExclusiveLock; }
12589 102 : | EXCLUSIVE { $$ = ExclusiveLock; }
12590 126 : | ACCESS EXCLUSIVE { $$ = AccessExclusiveLock; }
12591 : ;
12592 :
12593 186 : opt_nowait: NOWAIT { $$ = true; }
12594 890 : | /*EMPTY*/ { $$ = false; }
12595 : ;
12596 :
12597 : opt_nowait_or_skip:
12598 50 : NOWAIT { $$ = LockWaitError; }
12599 190 : | SKIP LOCKED { $$ = LockWaitSkip; }
12600 5180 : | /*EMPTY*/ { $$ = LockWaitBlock; }
12601 : ;
12602 :
12603 :
12604 : /*****************************************************************************
12605 : *
12606 : * QUERY:
12607 : * UpdateStmt (UPDATE)
12608 : *
12609 : *****************************************************************************/
12610 :
12611 : UpdateStmt: opt_with_clause UPDATE relation_expr_opt_alias
12612 : SET set_clause_list
12613 : from_clause
12614 : where_or_current_clause
12615 : returning_clause
12616 : {
12617 14384 : UpdateStmt *n = makeNode(UpdateStmt);
12618 :
12619 14384 : n->relation = $3;
12620 14384 : n->targetList = $5;
12621 14384 : n->fromClause = $6;
12622 14384 : n->whereClause = $7;
12623 14384 : n->returningClause = $8;
12624 14384 : n->withClause = $1;
12625 14384 : $$ = (Node *) n;
12626 : }
12627 : ;
12628 :
12629 : set_clause_list:
12630 17396 : set_clause { $$ = $1; }
12631 4334 : | set_clause_list ',' set_clause { $$ = list_concat($1,$3); }
12632 : ;
12633 :
12634 : set_clause:
12635 : set_target '=' a_expr
12636 : {
12637 21546 : $1->val = (Node *) $3;
12638 21546 : $$ = list_make1($1);
12639 : }
12640 : | '(' set_target_list ')' '=' a_expr
12641 : {
12642 184 : int ncolumns = list_length($2);
12643 184 : int i = 1;
12644 : ListCell *col_cell;
12645 :
12646 : /* Create a MultiAssignRef source for each target */
12647 568 : foreach(col_cell, $2)
12648 : {
12649 384 : ResTarget *res_col = (ResTarget *) lfirst(col_cell);
12650 384 : MultiAssignRef *r = makeNode(MultiAssignRef);
12651 :
12652 384 : r->source = (Node *) $5;
12653 384 : r->colno = i;
12654 384 : r->ncolumns = ncolumns;
12655 384 : res_col->val = (Node *) r;
12656 384 : i++;
12657 : }
12658 :
12659 184 : $$ = $2;
12660 : }
12661 : ;
12662 :
12663 : set_target:
12664 : ColId opt_indirection
12665 : {
12666 21936 : $$ = makeNode(ResTarget);
12667 21936 : $$->name = $1;
12668 21936 : $$->indirection = check_indirection($2, yyscanner);
12669 21936 : $$->val = NULL; /* upper production sets this */
12670 21936 : $$->location = @1;
12671 : }
12672 : ;
12673 :
12674 : set_target_list:
12675 190 : set_target { $$ = list_make1($1); }
12676 200 : | set_target_list ',' set_target { $$ = lappend($1,$3); }
12677 : ;
12678 :
12679 :
12680 : /*****************************************************************************
12681 : *
12682 : * QUERY:
12683 : * MERGE
12684 : *
12685 : *****************************************************************************/
12686 :
12687 : MergeStmt:
12688 : opt_with_clause MERGE INTO relation_expr_opt_alias
12689 : USING table_ref
12690 : ON a_expr
12691 : merge_when_list
12692 : returning_clause
12693 : {
12694 2172 : MergeStmt *m = makeNode(MergeStmt);
12695 :
12696 2172 : m->withClause = $1;
12697 2172 : m->relation = $4;
12698 2172 : m->sourceRelation = $6;
12699 2172 : m->joinCondition = $8;
12700 2172 : m->mergeWhenClauses = $9;
12701 2172 : m->returningClause = $10;
12702 :
12703 2172 : $$ = (Node *) m;
12704 : }
12705 : ;
12706 :
12707 : merge_when_list:
12708 2172 : merge_when_clause { $$ = list_make1($1); }
12709 1218 : | merge_when_list merge_when_clause { $$ = lappend($1,$2); }
12710 : ;
12711 :
12712 : /*
12713 : * A WHEN clause may be WHEN MATCHED, WHEN NOT MATCHED BY SOURCE, or WHEN NOT
12714 : * MATCHED [BY TARGET]. The first two cases match target tuples, and support
12715 : * UPDATE/DELETE/DO NOTHING actions. The third case does not match target
12716 : * tuples, and only supports INSERT/DO NOTHING actions.
12717 : */
12718 : merge_when_clause:
12719 : merge_when_tgt_matched opt_merge_when_condition THEN merge_update
12720 : {
12721 1628 : $4->matchKind = $1;
12722 1628 : $4->condition = $2;
12723 :
12724 1628 : $$ = (Node *) $4;
12725 : }
12726 : | merge_when_tgt_matched opt_merge_when_condition THEN merge_delete
12727 : {
12728 542 : $4->matchKind = $1;
12729 542 : $4->condition = $2;
12730 :
12731 542 : $$ = (Node *) $4;
12732 : }
12733 : | merge_when_tgt_not_matched opt_merge_when_condition THEN merge_insert
12734 : {
12735 1124 : $4->matchKind = $1;
12736 1124 : $4->condition = $2;
12737 :
12738 1124 : $$ = (Node *) $4;
12739 : }
12740 : | merge_when_tgt_matched opt_merge_when_condition THEN DO NOTHING
12741 : {
12742 70 : MergeWhenClause *m = makeNode(MergeWhenClause);
12743 :
12744 70 : m->matchKind = $1;
12745 70 : m->commandType = CMD_NOTHING;
12746 70 : m->condition = $2;
12747 :
12748 70 : $$ = (Node *) m;
12749 : }
12750 : | merge_when_tgt_not_matched opt_merge_when_condition THEN DO NOTHING
12751 : {
12752 26 : MergeWhenClause *m = makeNode(MergeWhenClause);
12753 :
12754 26 : m->matchKind = $1;
12755 26 : m->commandType = CMD_NOTHING;
12756 26 : m->condition = $2;
12757 :
12758 26 : $$ = (Node *) m;
12759 : }
12760 : ;
12761 :
12762 : merge_when_tgt_matched:
12763 2072 : WHEN MATCHED { $$ = MERGE_WHEN_MATCHED; }
12764 186 : | WHEN NOT MATCHED BY SOURCE { $$ = MERGE_WHEN_NOT_MATCHED_BY_SOURCE; }
12765 : ;
12766 :
12767 : merge_when_tgt_not_matched:
12768 1156 : WHEN NOT MATCHED { $$ = MERGE_WHEN_NOT_MATCHED_BY_TARGET; }
12769 18 : | WHEN NOT MATCHED BY TARGET { $$ = MERGE_WHEN_NOT_MATCHED_BY_TARGET; }
12770 : ;
12771 :
12772 : opt_merge_when_condition:
12773 850 : AND a_expr { $$ = $2; }
12774 2582 : | { $$ = NULL; }
12775 : ;
12776 :
12777 : merge_update:
12778 : UPDATE SET set_clause_list
12779 : {
12780 1628 : MergeWhenClause *n = makeNode(MergeWhenClause);
12781 1628 : n->commandType = CMD_UPDATE;
12782 1628 : n->override = OVERRIDING_NOT_SET;
12783 1628 : n->targetList = $3;
12784 1628 : n->values = NIL;
12785 :
12786 1628 : $$ = n;
12787 : }
12788 : ;
12789 :
12790 : merge_delete:
12791 : DELETE_P
12792 : {
12793 542 : MergeWhenClause *n = makeNode(MergeWhenClause);
12794 542 : n->commandType = CMD_DELETE;
12795 542 : n->override = OVERRIDING_NOT_SET;
12796 542 : n->targetList = NIL;
12797 542 : n->values = NIL;
12798 :
12799 542 : $$ = n;
12800 : }
12801 : ;
12802 :
12803 : merge_insert:
12804 : INSERT merge_values_clause
12805 : {
12806 754 : MergeWhenClause *n = makeNode(MergeWhenClause);
12807 754 : n->commandType = CMD_INSERT;
12808 754 : n->override = OVERRIDING_NOT_SET;
12809 754 : n->targetList = NIL;
12810 754 : n->values = $2;
12811 754 : $$ = n;
12812 : }
12813 : | INSERT OVERRIDING override_kind VALUE_P merge_values_clause
12814 : {
12815 0 : MergeWhenClause *n = makeNode(MergeWhenClause);
12816 0 : n->commandType = CMD_INSERT;
12817 0 : n->override = $3;
12818 0 : n->targetList = NIL;
12819 0 : n->values = $5;
12820 0 : $$ = n;
12821 : }
12822 : | INSERT '(' insert_column_list ')' merge_values_clause
12823 : {
12824 304 : MergeWhenClause *n = makeNode(MergeWhenClause);
12825 304 : n->commandType = CMD_INSERT;
12826 304 : n->override = OVERRIDING_NOT_SET;
12827 304 : n->targetList = $3;
12828 304 : n->values = $5;
12829 304 : $$ = n;
12830 : }
12831 : | INSERT '(' insert_column_list ')' OVERRIDING override_kind VALUE_P merge_values_clause
12832 : {
12833 30 : MergeWhenClause *n = makeNode(MergeWhenClause);
12834 30 : n->commandType = CMD_INSERT;
12835 30 : n->override = $6;
12836 30 : n->targetList = $3;
12837 30 : n->values = $8;
12838 30 : $$ = n;
12839 : }
12840 : | INSERT DEFAULT VALUES
12841 : {
12842 36 : MergeWhenClause *n = makeNode(MergeWhenClause);
12843 36 : n->commandType = CMD_INSERT;
12844 36 : n->override = OVERRIDING_NOT_SET;
12845 36 : n->targetList = NIL;
12846 36 : n->values = NIL;
12847 36 : $$ = n;
12848 : }
12849 : ;
12850 :
12851 : merge_values_clause:
12852 : VALUES '(' expr_list ')'
12853 : {
12854 1088 : $$ = $3;
12855 : }
12856 : ;
12857 :
12858 : /*****************************************************************************
12859 : *
12860 : * QUERY:
12861 : * CURSOR STATEMENTS
12862 : *
12863 : *****************************************************************************/
12864 : DeclareCursorStmt: DECLARE cursor_name cursor_options CURSOR opt_hold FOR SelectStmt
12865 : {
12866 4614 : DeclareCursorStmt *n = makeNode(DeclareCursorStmt);
12867 :
12868 4614 : n->portalname = $2;
12869 : /* currently we always set FAST_PLAN option */
12870 4614 : n->options = $3 | $5 | CURSOR_OPT_FAST_PLAN;
12871 4614 : n->query = $7;
12872 4614 : $$ = (Node *) n;
12873 : }
12874 : ;
12875 :
12876 14830 : cursor_name: name { $$ = $1; }
12877 : ;
12878 :
12879 4614 : cursor_options: /*EMPTY*/ { $$ = 0; }
12880 28 : | cursor_options NO SCROLL { $$ = $1 | CURSOR_OPT_NO_SCROLL; }
12881 240 : | cursor_options SCROLL { $$ = $1 | CURSOR_OPT_SCROLL; }
12882 14 : | cursor_options BINARY { $$ = $1 | CURSOR_OPT_BINARY; }
12883 0 : | cursor_options ASENSITIVE { $$ = $1 | CURSOR_OPT_ASENSITIVE; }
12884 6 : | cursor_options INSENSITIVE { $$ = $1 | CURSOR_OPT_INSENSITIVE; }
12885 : ;
12886 :
12887 4514 : opt_hold: /* EMPTY */ { $$ = 0; }
12888 94 : | WITH HOLD { $$ = CURSOR_OPT_HOLD; }
12889 6 : | WITHOUT HOLD { $$ = 0; }
12890 : ;
12891 :
12892 : /*****************************************************************************
12893 : *
12894 : * QUERY:
12895 : * SELECT STATEMENTS
12896 : *
12897 : *****************************************************************************/
12898 :
12899 : /* A complete SELECT statement looks like this.
12900 : *
12901 : * The rule returns either a single SelectStmt node or a tree of them,
12902 : * representing a set-operation tree.
12903 : *
12904 : * There is an ambiguity when a sub-SELECT is within an a_expr and there
12905 : * are excess parentheses: do the parentheses belong to the sub-SELECT or
12906 : * to the surrounding a_expr? We don't really care, but bison wants to know.
12907 : * To resolve the ambiguity, we are careful to define the grammar so that
12908 : * the decision is staved off as long as possible: as long as we can keep
12909 : * absorbing parentheses into the sub-SELECT, we will do so, and only when
12910 : * it's no longer possible to do that will we decide that parens belong to
12911 : * the expression. For example, in "SELECT (((SELECT 2)) + 3)" the extra
12912 : * parentheses are treated as part of the sub-select. The necessity of doing
12913 : * it that way is shown by "SELECT (((SELECT 2)) UNION SELECT 2)". Had we
12914 : * parsed "((SELECT 2))" as an a_expr, it'd be too late to go back to the
12915 : * SELECT viewpoint when we see the UNION.
12916 : *
12917 : * This approach is implemented by defining a nonterminal select_with_parens,
12918 : * which represents a SELECT with at least one outer layer of parentheses,
12919 : * and being careful to use select_with_parens, never '(' SelectStmt ')',
12920 : * in the expression grammar. We will then have shift-reduce conflicts
12921 : * which we can resolve in favor of always treating '(' <select> ')' as
12922 : * a select_with_parens. To resolve the conflicts, the productions that
12923 : * conflict with the select_with_parens productions are manually given
12924 : * precedences lower than the precedence of ')', thereby ensuring that we
12925 : * shift ')' (and then reduce to select_with_parens) rather than trying to
12926 : * reduce the inner <select> nonterminal to something else. We use UMINUS
12927 : * precedence for this, which is a fairly arbitrary choice.
12928 : *
12929 : * To be able to define select_with_parens itself without ambiguity, we need
12930 : * a nonterminal select_no_parens that represents a SELECT structure with no
12931 : * outermost parentheses. This is a little bit tedious, but it works.
12932 : *
12933 : * In non-expression contexts, we use SelectStmt which can represent a SELECT
12934 : * with or without outer parentheses.
12935 : */
12936 :
12937 : SelectStmt: select_no_parens %prec UMINUS
12938 : | select_with_parens %prec UMINUS
12939 : ;
12940 :
12941 : select_with_parens:
12942 65144 : '(' select_no_parens ')' { $$ = $2; }
12943 156 : | '(' select_with_parens ')' { $$ = $2; }
12944 : ;
12945 :
12946 : /*
12947 : * This rule parses the equivalent of the standard's <query expression>.
12948 : * The duplicative productions are annoying, but hard to get rid of without
12949 : * creating shift/reduce conflicts.
12950 : *
12951 : * The locking clause (FOR UPDATE etc) may be before or after LIMIT/OFFSET.
12952 : * In <=7.2.X, LIMIT/OFFSET had to be after FOR UPDATE
12953 : * We now support both orderings, but prefer LIMIT/OFFSET before the locking
12954 : * clause.
12955 : * 2002-08-28 bjm
12956 : */
12957 : select_no_parens:
12958 394196 : simple_select { $$ = $1; }
12959 : | select_clause sort_clause
12960 : {
12961 70818 : insertSelectOptions((SelectStmt *) $1, $2, NIL,
12962 : NULL, NULL,
12963 : yyscanner);
12964 70818 : $$ = $1;
12965 : }
12966 : | select_clause opt_sort_clause for_locking_clause opt_select_limit
12967 : {
12968 4972 : insertSelectOptions((SelectStmt *) $1, $2, $3,
12969 4972 : $4,
12970 : NULL,
12971 : yyscanner);
12972 4972 : $$ = $1;
12973 : }
12974 : | select_clause opt_sort_clause select_limit opt_for_locking_clause
12975 : {
12976 4942 : insertSelectOptions((SelectStmt *) $1, $2, $4,
12977 4942 : $3,
12978 : NULL,
12979 : yyscanner);
12980 4930 : $$ = $1;
12981 : }
12982 : | with_clause select_clause
12983 : {
12984 2210 : insertSelectOptions((SelectStmt *) $2, NULL, NIL,
12985 : NULL,
12986 2210 : $1,
12987 : yyscanner);
12988 2210 : $$ = $2;
12989 : }
12990 : | with_clause select_clause sort_clause
12991 : {
12992 606 : insertSelectOptions((SelectStmt *) $2, $3, NIL,
12993 : NULL,
12994 606 : $1,
12995 : yyscanner);
12996 606 : $$ = $2;
12997 : }
12998 : | with_clause select_clause opt_sort_clause for_locking_clause opt_select_limit
12999 : {
13000 6 : insertSelectOptions((SelectStmt *) $2, $3, $4,
13001 6 : $5,
13002 6 : $1,
13003 : yyscanner);
13004 6 : $$ = $2;
13005 : }
13006 : | with_clause select_clause opt_sort_clause select_limit opt_for_locking_clause
13007 : {
13008 64 : insertSelectOptions((SelectStmt *) $2, $3, $5,
13009 64 : $4,
13010 64 : $1,
13011 : yyscanner);
13012 64 : $$ = $2;
13013 : }
13014 : ;
13015 :
13016 : select_clause:
13017 122502 : simple_select { $$ = $1; }
13018 588 : | select_with_parens { $$ = $1; }
13019 : ;
13020 :
13021 : /*
13022 : * This rule parses SELECT statements that can appear within set operations,
13023 : * including UNION, INTERSECT and EXCEPT. '(' and ')' can be used to specify
13024 : * the ordering of the set operations. Without '(' and ')' we want the
13025 : * operations to be ordered per the precedence specs at the head of this file.
13026 : *
13027 : * As with select_no_parens, simple_select cannot have outer parentheses,
13028 : * but can have parenthesized subclauses.
13029 : *
13030 : * It might appear that we could fold the first two alternatives into one
13031 : * by using opt_distinct_clause. However, that causes a shift/reduce conflict
13032 : * against INSERT ... SELECT ... ON CONFLICT. We avoid the ambiguity by
13033 : * requiring SELECT DISTINCT [ON] to be followed by a non-empty target_list.
13034 : *
13035 : * Note that sort clauses cannot be included at this level --- SQL requires
13036 : * SELECT foo UNION SELECT bar ORDER BY baz
13037 : * to be parsed as
13038 : * (SELECT foo UNION SELECT bar) ORDER BY baz
13039 : * not
13040 : * SELECT foo UNION (SELECT bar ORDER BY baz)
13041 : * Likewise for WITH, FOR UPDATE and LIMIT. Therefore, those clauses are
13042 : * described as part of the select_no_parens production, not simple_select.
13043 : * This does not limit functionality, because you can reintroduce these
13044 : * clauses inside parentheses.
13045 : *
13046 : * NOTE: only the leftmost component SelectStmt should have INTO.
13047 : * However, this is not checked by the grammar; parse analysis must check it.
13048 : */
13049 : simple_select:
13050 : SELECT opt_all_clause opt_target_list
13051 : into_clause from_clause where_clause
13052 : group_clause having_clause window_clause
13053 : {
13054 433004 : SelectStmt *n = makeNode(SelectStmt);
13055 :
13056 433002 : n->targetList = $3;
13057 433002 : n->intoClause = $4;
13058 433002 : n->fromClause = $5;
13059 433002 : n->whereClause = $6;
13060 433002 : n->groupClause = ($7)->list;
13061 433002 : n->groupDistinct = ($7)->distinct;
13062 433002 : n->groupByAll = ($7)->all;
13063 433002 : n->havingClause = $8;
13064 433002 : n->windowClause = $9;
13065 433002 : $$ = (Node *) n;
13066 : }
13067 : | SELECT distinct_clause target_list
13068 : into_clause from_clause where_clause
13069 : group_clause having_clause window_clause
13070 : {
13071 4022 : SelectStmt *n = makeNode(SelectStmt);
13072 :
13073 4022 : n->distinctClause = $2;
13074 4022 : n->targetList = $3;
13075 4022 : n->intoClause = $4;
13076 4022 : n->fromClause = $5;
13077 4022 : n->whereClause = $6;
13078 4022 : n->groupClause = ($7)->list;
13079 4022 : n->groupDistinct = ($7)->distinct;
13080 4022 : n->groupByAll = ($7)->all;
13081 4022 : n->havingClause = $8;
13082 4022 : n->windowClause = $9;
13083 4022 : $$ = (Node *) n;
13084 : }
13085 59628 : | values_clause { $$ = $1; }
13086 : | TABLE relation_expr
13087 : {
13088 : /* same as SELECT * FROM relation_expr */
13089 314 : ColumnRef *cr = makeNode(ColumnRef);
13090 314 : ResTarget *rt = makeNode(ResTarget);
13091 314 : SelectStmt *n = makeNode(SelectStmt);
13092 :
13093 314 : cr->fields = list_make1(makeNode(A_Star));
13094 314 : cr->location = -1;
13095 :
13096 314 : rt->name = NULL;
13097 314 : rt->indirection = NIL;
13098 314 : rt->val = (Node *) cr;
13099 314 : rt->location = -1;
13100 :
13101 314 : n->targetList = list_make1(rt);
13102 314 : n->fromClause = list_make1($2);
13103 314 : $$ = (Node *) n;
13104 : }
13105 : | select_clause UNION set_quantifier select_clause
13106 : {
13107 18960 : $$ = makeSetOp(SETOP_UNION, $3 == SET_QUANTIFIER_ALL, $1, $4);
13108 : }
13109 : | select_clause INTERSECT set_quantifier select_clause
13110 : {
13111 276 : $$ = makeSetOp(SETOP_INTERSECT, $3 == SET_QUANTIFIER_ALL, $1, $4);
13112 : }
13113 : | select_clause EXCEPT set_quantifier select_clause
13114 : {
13115 494 : $$ = makeSetOp(SETOP_EXCEPT, $3 == SET_QUANTIFIER_ALL, $1, $4);
13116 : }
13117 : ;
13118 :
13119 : /*
13120 : * SQL standard WITH clause looks like:
13121 : *
13122 : * WITH [ RECURSIVE ] <query name> [ (<column>,...) ]
13123 : * AS (query) [ SEARCH or CYCLE clause ]
13124 : *
13125 : * Recognizing WITH_LA here allows a CTE to be named TIME or ORDINALITY.
13126 : */
13127 : with_clause:
13128 : WITH cte_list
13129 : {
13130 2102 : $$ = makeNode(WithClause);
13131 2102 : $$->ctes = $2;
13132 2102 : $$->recursive = false;
13133 2102 : $$->location = @1;
13134 : }
13135 : | WITH_LA cte_list
13136 : {
13137 6 : $$ = makeNode(WithClause);
13138 6 : $$->ctes = $2;
13139 6 : $$->recursive = false;
13140 6 : $$->location = @1;
13141 : }
13142 : | WITH RECURSIVE cte_list
13143 : {
13144 1246 : $$ = makeNode(WithClause);
13145 1246 : $$->ctes = $3;
13146 1246 : $$->recursive = true;
13147 1246 : $$->location = @1;
13148 : }
13149 : ;
13150 :
13151 : cte_list:
13152 3354 : common_table_expr { $$ = list_make1($1); }
13153 1256 : | cte_list ',' common_table_expr { $$ = lappend($1, $3); }
13154 : ;
13155 :
13156 : common_table_expr: name opt_name_list AS opt_materialized '(' PreparableStmt ')' opt_search_clause opt_cycle_clause
13157 : {
13158 4610 : CommonTableExpr *n = makeNode(CommonTableExpr);
13159 :
13160 4610 : n->ctename = $1;
13161 4610 : n->aliascolnames = $2;
13162 4610 : n->ctematerialized = $4;
13163 4610 : n->ctequery = $6;
13164 4610 : n->search_clause = castNode(CTESearchClause, $8);
13165 4610 : n->cycle_clause = castNode(CTECycleClause, $9);
13166 4610 : n->location = @1;
13167 4610 : $$ = (Node *) n;
13168 : }
13169 : ;
13170 :
13171 : opt_materialized:
13172 178 : MATERIALIZED { $$ = CTEMaterializeAlways; }
13173 48 : | NOT MATERIALIZED { $$ = CTEMaterializeNever; }
13174 4384 : | /*EMPTY*/ { $$ = CTEMaterializeDefault; }
13175 : ;
13176 :
13177 : opt_search_clause:
13178 : SEARCH DEPTH FIRST_P BY columnList SET ColId
13179 : {
13180 90 : CTESearchClause *n = makeNode(CTESearchClause);
13181 :
13182 90 : n->search_col_list = $5;
13183 90 : n->search_breadth_first = false;
13184 90 : n->search_seq_column = $7;
13185 90 : n->location = @1;
13186 90 : $$ = (Node *) n;
13187 : }
13188 : | SEARCH BREADTH FIRST_P BY columnList SET ColId
13189 : {
13190 36 : CTESearchClause *n = makeNode(CTESearchClause);
13191 :
13192 36 : n->search_col_list = $5;
13193 36 : n->search_breadth_first = true;
13194 36 : n->search_seq_column = $7;
13195 36 : n->location = @1;
13196 36 : $$ = (Node *) n;
13197 : }
13198 : | /*EMPTY*/
13199 : {
13200 4484 : $$ = NULL;
13201 : }
13202 : ;
13203 :
13204 : opt_cycle_clause:
13205 : CYCLE columnList SET ColId TO AexprConst DEFAULT AexprConst USING ColId
13206 : {
13207 66 : CTECycleClause *n = makeNode(CTECycleClause);
13208 :
13209 66 : n->cycle_col_list = $2;
13210 66 : n->cycle_mark_column = $4;
13211 66 : n->cycle_mark_value = $6;
13212 66 : n->cycle_mark_default = $8;
13213 66 : n->cycle_path_column = $10;
13214 66 : n->location = @1;
13215 66 : $$ = (Node *) n;
13216 : }
13217 : | CYCLE columnList SET ColId USING ColId
13218 : {
13219 60 : CTECycleClause *n = makeNode(CTECycleClause);
13220 :
13221 60 : n->cycle_col_list = $2;
13222 60 : n->cycle_mark_column = $4;
13223 60 : n->cycle_mark_value = makeBoolAConst(true, -1);
13224 60 : n->cycle_mark_default = makeBoolAConst(false, -1);
13225 60 : n->cycle_path_column = $6;
13226 60 : n->location = @1;
13227 60 : $$ = (Node *) n;
13228 : }
13229 : | /*EMPTY*/
13230 : {
13231 4484 : $$ = NULL;
13232 : }
13233 : ;
13234 :
13235 : opt_with_clause:
13236 468 : with_clause { $$ = $1; }
13237 90212 : | /*EMPTY*/ { $$ = NULL; }
13238 : ;
13239 :
13240 : into_clause:
13241 : INTO OptTempTableName
13242 : {
13243 138 : $$ = makeNode(IntoClause);
13244 138 : $$->rel = $2;
13245 138 : $$->colNames = NIL;
13246 138 : $$->options = NIL;
13247 138 : $$->onCommit = ONCOMMIT_NOOP;
13248 138 : $$->tableSpaceName = NULL;
13249 138 : $$->viewQuery = NULL;
13250 138 : $$->skipData = false;
13251 : }
13252 : | /*EMPTY*/
13253 436918 : { $$ = NULL; }
13254 : ;
13255 :
13256 : /*
13257 : * Redundancy here is needed to avoid shift/reduce conflicts,
13258 : * since TEMP is not a reserved word. See also OptTemp.
13259 : */
13260 : OptTempTableName:
13261 : TEMPORARY opt_table qualified_name
13262 : {
13263 0 : $$ = $3;
13264 0 : $$->relpersistence = RELPERSISTENCE_TEMP;
13265 : }
13266 : | TEMP opt_table qualified_name
13267 : {
13268 6 : $$ = $3;
13269 6 : $$->relpersistence = RELPERSISTENCE_TEMP;
13270 : }
13271 : | LOCAL TEMPORARY opt_table qualified_name
13272 : {
13273 0 : $$ = $4;
13274 0 : $$->relpersistence = RELPERSISTENCE_TEMP;
13275 : }
13276 : | LOCAL TEMP opt_table qualified_name
13277 : {
13278 0 : $$ = $4;
13279 0 : $$->relpersistence = RELPERSISTENCE_TEMP;
13280 : }
13281 : | GLOBAL TEMPORARY opt_table qualified_name
13282 : {
13283 0 : ereport(WARNING,
13284 : (errmsg("GLOBAL is deprecated in temporary table creation"),
13285 : parser_errposition(@1)));
13286 0 : $$ = $4;
13287 0 : $$->relpersistence = RELPERSISTENCE_TEMP;
13288 : }
13289 : | GLOBAL TEMP opt_table qualified_name
13290 : {
13291 0 : ereport(WARNING,
13292 : (errmsg("GLOBAL is deprecated in temporary table creation"),
13293 : parser_errposition(@1)));
13294 0 : $$ = $4;
13295 0 : $$->relpersistence = RELPERSISTENCE_TEMP;
13296 : }
13297 : | UNLOGGED opt_table qualified_name
13298 : {
13299 0 : $$ = $3;
13300 0 : $$->relpersistence = RELPERSISTENCE_UNLOGGED;
13301 : }
13302 : | TABLE qualified_name
13303 : {
13304 30 : $$ = $2;
13305 30 : $$->relpersistence = RELPERSISTENCE_PERMANENT;
13306 : }
13307 : | qualified_name
13308 : {
13309 102 : $$ = $1;
13310 102 : $$->relpersistence = RELPERSISTENCE_PERMANENT;
13311 : }
13312 : ;
13313 :
13314 : opt_table: TABLE
13315 : | /*EMPTY*/
13316 : ;
13317 :
13318 : set_quantifier:
13319 11078 : ALL { $$ = SET_QUANTIFIER_ALL; }
13320 32 : | DISTINCT { $$ = SET_QUANTIFIER_DISTINCT; }
13321 13554 : | /*EMPTY*/ { $$ = SET_QUANTIFIER_DEFAULT; }
13322 : ;
13323 :
13324 : /* We use (NIL) as a placeholder to indicate that all target expressions
13325 : * should be placed in the DISTINCT list during parsetree analysis.
13326 : */
13327 : distinct_clause:
13328 3768 : DISTINCT { $$ = list_make1(NIL); }
13329 260 : | DISTINCT ON '(' expr_list ')' { $$ = $4; }
13330 : ;
13331 :
13332 : opt_all_clause:
13333 : ALL
13334 : | /*EMPTY*/
13335 : ;
13336 :
13337 : opt_distinct_clause:
13338 0 : distinct_clause { $$ = $1; }
13339 40914 : | opt_all_clause { $$ = NIL; }
13340 : ;
13341 :
13342 : opt_sort_clause:
13343 7518 : sort_clause { $$ = $1; }
13344 367726 : | /*EMPTY*/ { $$ = NIL; }
13345 : ;
13346 :
13347 : sort_clause:
13348 79290 : ORDER BY sortby_list { $$ = $3; }
13349 : ;
13350 :
13351 : sortby_list:
13352 79308 : sortby { $$ = list_make1($1); }
13353 28686 : | sortby_list ',' sortby { $$ = lappend($1, $3); }
13354 : ;
13355 :
13356 : sortby: a_expr USING qual_all_Op opt_nulls_order
13357 : {
13358 220 : $$ = makeNode(SortBy);
13359 220 : $$->node = $1;
13360 220 : $$->sortby_dir = SORTBY_USING;
13361 220 : $$->sortby_nulls = $4;
13362 220 : $$->useOp = $3;
13363 220 : $$->location = @3;
13364 : }
13365 : | a_expr opt_asc_desc opt_nulls_order
13366 : {
13367 107774 : $$ = makeNode(SortBy);
13368 107774 : $$->node = $1;
13369 107774 : $$->sortby_dir = $2;
13370 107774 : $$->sortby_nulls = $3;
13371 107774 : $$->useOp = NIL;
13372 107774 : $$->location = -1; /* no operator */
13373 : }
13374 : ;
13375 :
13376 :
13377 : select_limit:
13378 : limit_clause offset_clause
13379 : {
13380 172 : $$ = $1;
13381 172 : ($$)->limitOffset = $2;
13382 172 : ($$)->offsetLoc = @2;
13383 : }
13384 : | offset_clause limit_clause
13385 : {
13386 222 : $$ = $2;
13387 222 : ($$)->limitOffset = $1;
13388 222 : ($$)->offsetLoc = @1;
13389 : }
13390 : | limit_clause
13391 : {
13392 4334 : $$ = $1;
13393 : }
13394 : | offset_clause
13395 : {
13396 468 : SelectLimit *n = (SelectLimit *) palloc(sizeof(SelectLimit));
13397 :
13398 468 : n->limitOffset = $1;
13399 468 : n->limitCount = NULL;
13400 468 : n->limitOption = LIMIT_OPTION_COUNT;
13401 468 : n->offsetLoc = @1;
13402 468 : n->countLoc = -1;
13403 468 : n->optionLoc = -1;
13404 468 : $$ = n;
13405 : }
13406 : ;
13407 :
13408 : opt_select_limit:
13409 190 : select_limit { $$ = $1; }
13410 45702 : | /* EMPTY */ { $$ = NULL; }
13411 : ;
13412 :
13413 : limit_clause:
13414 : LIMIT select_limit_value
13415 : {
13416 4632 : SelectLimit *n = (SelectLimit *) palloc(sizeof(SelectLimit));
13417 :
13418 4632 : n->limitOffset = NULL;
13419 4632 : n->limitCount = $2;
13420 4632 : n->limitOption = LIMIT_OPTION_COUNT;
13421 4632 : n->offsetLoc = -1;
13422 4632 : n->countLoc = @1;
13423 4632 : n->optionLoc = -1;
13424 4632 : $$ = n;
13425 : }
13426 : | LIMIT select_limit_value ',' select_offset_value
13427 : {
13428 : /* Disabled because it was too confusing, bjm 2002-02-18 */
13429 0 : ereport(ERROR,
13430 : (errcode(ERRCODE_SYNTAX_ERROR),
13431 : errmsg("LIMIT #,# syntax is not supported"),
13432 : errhint("Use separate LIMIT and OFFSET clauses."),
13433 : parser_errposition(@1)));
13434 : }
13435 : /* SQL:2008 syntax */
13436 : /* to avoid shift/reduce conflicts, handle the optional value with
13437 : * a separate production rather than an opt_ expression. The fact
13438 : * that ONLY is fully reserved means that this way, we defer any
13439 : * decision about what rule reduces ROW or ROWS to the point where
13440 : * we can see the ONLY token in the lookahead slot.
13441 : */
13442 : | FETCH first_or_next select_fetch_first_value row_or_rows ONLY
13443 : {
13444 24 : SelectLimit *n = (SelectLimit *) palloc(sizeof(SelectLimit));
13445 :
13446 24 : n->limitOffset = NULL;
13447 24 : n->limitCount = $3;
13448 24 : n->limitOption = LIMIT_OPTION_COUNT;
13449 24 : n->offsetLoc = -1;
13450 24 : n->countLoc = @1;
13451 24 : n->optionLoc = -1;
13452 24 : $$ = n;
13453 : }
13454 : | FETCH first_or_next select_fetch_first_value row_or_rows WITH TIES
13455 : {
13456 66 : SelectLimit *n = (SelectLimit *) palloc(sizeof(SelectLimit));
13457 :
13458 66 : n->limitOffset = NULL;
13459 66 : n->limitCount = $3;
13460 66 : n->limitOption = LIMIT_OPTION_WITH_TIES;
13461 66 : n->offsetLoc = -1;
13462 66 : n->countLoc = @1;
13463 66 : n->optionLoc = @5;
13464 66 : $$ = n;
13465 : }
13466 : | FETCH first_or_next row_or_rows ONLY
13467 : {
13468 0 : SelectLimit *n = (SelectLimit *) palloc(sizeof(SelectLimit));
13469 :
13470 0 : n->limitOffset = NULL;
13471 0 : n->limitCount = makeIntConst(1, -1);
13472 0 : n->limitOption = LIMIT_OPTION_COUNT;
13473 0 : n->offsetLoc = -1;
13474 0 : n->countLoc = @1;
13475 0 : n->optionLoc = -1;
13476 0 : $$ = n;
13477 : }
13478 : | FETCH first_or_next row_or_rows WITH TIES
13479 : {
13480 6 : SelectLimit *n = (SelectLimit *) palloc(sizeof(SelectLimit));
13481 :
13482 6 : n->limitOffset = NULL;
13483 6 : n->limitCount = makeIntConst(1, -1);
13484 6 : n->limitOption = LIMIT_OPTION_WITH_TIES;
13485 6 : n->offsetLoc = -1;
13486 6 : n->countLoc = @1;
13487 6 : n->optionLoc = @4;
13488 6 : $$ = n;
13489 : }
13490 : ;
13491 :
13492 : offset_clause:
13493 : OFFSET select_offset_value
13494 862 : { $$ = $2; }
13495 : /* SQL:2008 syntax */
13496 : | OFFSET select_fetch_first_value row_or_rows
13497 0 : { $$ = $2; }
13498 : ;
13499 :
13500 : select_limit_value:
13501 4630 : a_expr { $$ = $1; }
13502 : | ALL
13503 : {
13504 : /* LIMIT ALL is represented as a NULL constant */
13505 2 : $$ = makeNullAConst(@1);
13506 : }
13507 : ;
13508 :
13509 : select_offset_value:
13510 862 : a_expr { $$ = $1; }
13511 : ;
13512 :
13513 : /*
13514 : * Allowing full expressions without parentheses causes various parsing
13515 : * problems with the trailing ROW/ROWS key words. SQL spec only calls for
13516 : * <simple value specification>, which is either a literal or a parameter (but
13517 : * an <SQL parameter reference> could be an identifier, bringing up conflicts
13518 : * with ROW/ROWS). We solve this by leveraging the presence of ONLY (see above)
13519 : * to determine whether the expression is missing rather than trying to make it
13520 : * optional in this rule.
13521 : *
13522 : * c_expr covers almost all the spec-required cases (and more), but it doesn't
13523 : * cover signed numeric literals, which are allowed by the spec. So we include
13524 : * those here explicitly. We need FCONST as well as ICONST because values that
13525 : * don't fit in the platform's "long", but do fit in bigint, should still be
13526 : * accepted here. (This is possible in 64-bit Windows as well as all 32-bit
13527 : * builds.)
13528 : */
13529 : select_fetch_first_value:
13530 90 : c_expr { $$ = $1; }
13531 : | '+' I_or_F_const
13532 0 : { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "+", NULL, $2, @1); }
13533 : | '-' I_or_F_const
13534 0 : { $$ = doNegate($2, @1); }
13535 : ;
13536 :
13537 : I_or_F_const:
13538 0 : Iconst { $$ = makeIntConst($1,@1); }
13539 0 : | FCONST { $$ = makeFloatConst($1,@1); }
13540 : ;
13541 :
13542 : /* noise words */
13543 36 : row_or_rows: ROW { $$ = 0; }
13544 60 : | ROWS { $$ = 0; }
13545 : ;
13546 :
13547 96 : first_or_next: FIRST_P { $$ = 0; }
13548 0 : | NEXT { $$ = 0; }
13549 : ;
13550 :
13551 :
13552 : /*
13553 : * This syntax for group_clause tries to follow the spec quite closely.
13554 : * However, the spec allows only column references, not expressions,
13555 : * which introduces an ambiguity between implicit row constructors
13556 : * (a,b) and lists of column references.
13557 : *
13558 : * We handle this by using the a_expr production for what the spec calls
13559 : * <ordinary grouping set>, which in the spec represents either one column
13560 : * reference or a parenthesized list of column references. Then, we check the
13561 : * top node of the a_expr to see if it's an implicit RowExpr, and if so, just
13562 : * grab and use the list, discarding the node. (this is done in parse analysis,
13563 : * not here)
13564 : *
13565 : * (we abuse the row_format field of RowExpr to distinguish implicit and
13566 : * explicit row constructors; it's debatable if anyone sanely wants to use them
13567 : * in a group clause, but if they have a reason to, we make it possible.)
13568 : *
13569 : * Each item in the group_clause list is either an expression tree or a
13570 : * GroupingSet node of some type.
13571 : */
13572 : group_clause:
13573 : GROUP_P BY set_quantifier group_by_list
13574 : {
13575 4922 : GroupClause *n = (GroupClause *) palloc(sizeof(GroupClause));
13576 :
13577 4922 : n->distinct = $3 == SET_QUANTIFIER_DISTINCT;
13578 4922 : n->all = false;
13579 4922 : n->list = $4;
13580 4922 : $$ = n;
13581 : }
13582 : | GROUP_P BY ALL
13583 : {
13584 66 : GroupClause *n = (GroupClause *) palloc(sizeof(GroupClause));
13585 66 : n->distinct = false;
13586 66 : n->all = true;
13587 66 : n->list = NIL;
13588 66 : $$ = n;
13589 : }
13590 : | /*EMPTY*/
13591 : {
13592 472952 : GroupClause *n = (GroupClause *) palloc(sizeof(GroupClause));
13593 :
13594 472950 : n->distinct = false;
13595 472950 : n->all = false;
13596 472950 : n->list = NIL;
13597 472950 : $$ = n;
13598 : }
13599 : ;
13600 :
13601 : group_by_list:
13602 5556 : group_by_item { $$ = list_make1($1); }
13603 3062 : | group_by_list ',' group_by_item { $$ = lappend($1,$3); }
13604 : ;
13605 :
13606 : group_by_item:
13607 7256 : a_expr { $$ = $1; }
13608 246 : | empty_grouping_set { $$ = $1; }
13609 184 : | cube_clause { $$ = $1; }
13610 298 : | rollup_clause { $$ = $1; }
13611 634 : | grouping_sets_clause { $$ = $1; }
13612 : ;
13613 :
13614 : empty_grouping_set:
13615 : '(' ')'
13616 : {
13617 246 : $$ = (Node *) makeGroupingSet(GROUPING_SET_EMPTY, NIL, @1);
13618 : }
13619 : ;
13620 :
13621 : /*
13622 : * These hacks rely on setting precedence of CUBE and ROLLUP below that of '(',
13623 : * so that they shift in these rules rather than reducing the conflicting
13624 : * unreserved_keyword rule.
13625 : */
13626 :
13627 : rollup_clause:
13628 : ROLLUP '(' expr_list ')'
13629 : {
13630 298 : $$ = (Node *) makeGroupingSet(GROUPING_SET_ROLLUP, $3, @1);
13631 : }
13632 : ;
13633 :
13634 : cube_clause:
13635 : CUBE '(' expr_list ')'
13636 : {
13637 184 : $$ = (Node *) makeGroupingSet(GROUPING_SET_CUBE, $3, @1);
13638 : }
13639 : ;
13640 :
13641 : grouping_sets_clause:
13642 : GROUPING SETS '(' group_by_list ')'
13643 : {
13644 634 : $$ = (Node *) makeGroupingSet(GROUPING_SET_SETS, $4, @1);
13645 : }
13646 : ;
13647 :
13648 : having_clause:
13649 788 : HAVING a_expr { $$ = $2; }
13650 477152 : | /*EMPTY*/ { $$ = NULL; }
13651 : ;
13652 :
13653 : for_locking_clause:
13654 5318 : for_locking_items { $$ = $1; }
13655 0 : | FOR READ ONLY { $$ = NIL; }
13656 : ;
13657 :
13658 : opt_for_locking_clause:
13659 340 : for_locking_clause { $$ = $1; }
13660 45580 : | /* EMPTY */ { $$ = NIL; }
13661 : ;
13662 :
13663 : for_locking_items:
13664 5318 : for_locking_item { $$ = list_make1($1); }
13665 102 : | for_locking_items for_locking_item { $$ = lappend($1, $2); }
13666 : ;
13667 :
13668 : for_locking_item:
13669 : for_locking_strength locked_rels_list opt_nowait_or_skip
13670 : {
13671 5420 : LockingClause *n = makeNode(LockingClause);
13672 :
13673 5420 : n->lockedRels = $2;
13674 5420 : n->strength = $1;
13675 5420 : n->waitPolicy = $3;
13676 5420 : $$ = (Node *) n;
13677 : }
13678 : ;
13679 :
13680 : for_locking_strength:
13681 1556 : FOR UPDATE { $$ = LCS_FORUPDATE; }
13682 82 : | FOR NO KEY UPDATE { $$ = LCS_FORNOKEYUPDATE; }
13683 220 : | FOR SHARE { $$ = LCS_FORSHARE; }
13684 3562 : | FOR KEY SHARE { $$ = LCS_FORKEYSHARE; }
13685 : ;
13686 :
13687 : locked_rels_list:
13688 3594 : OF qualified_name_list { $$ = $2; }
13689 1826 : | /* EMPTY */ { $$ = NIL; }
13690 : ;
13691 :
13692 :
13693 : /*
13694 : * We should allow ROW '(' expr_list ')' too, but that seems to require
13695 : * making VALUES a fully reserved word, which will probably break more apps
13696 : * than allowing the noise-word is worth.
13697 : */
13698 : values_clause:
13699 : VALUES '(' expr_list ')'
13700 : {
13701 59628 : SelectStmt *n = makeNode(SelectStmt);
13702 :
13703 59628 : n->valuesLists = list_make1($3);
13704 59628 : $$ = (Node *) n;
13705 : }
13706 : | values_clause ',' '(' expr_list ')'
13707 : {
13708 25248 : SelectStmt *n = (SelectStmt *) $1;
13709 :
13710 25248 : n->valuesLists = lappend(n->valuesLists, $4);
13711 25248 : $$ = (Node *) n;
13712 : }
13713 : ;
13714 :
13715 :
13716 : /*****************************************************************************
13717 : *
13718 : * clauses common to all Optimizable Stmts:
13719 : * from_clause - allow list of both JOIN expressions and table names
13720 : * where_clause - qualifications for joins or restrictions
13721 : *
13722 : *****************************************************************************/
13723 :
13724 : from_clause:
13725 316248 : FROM from_list { $$ = $2; }
13726 176076 : | /*EMPTY*/ { $$ = NIL; }
13727 : ;
13728 :
13729 : from_list:
13730 317200 : table_ref { $$ = list_make1($1); }
13731 61392 : | from_list ',' table_ref { $$ = lappend($1, $3); }
13732 : ;
13733 :
13734 : /*
13735 : * table_ref is where an alias clause can be attached.
13736 : */
13737 : table_ref: relation_expr opt_alias_clause
13738 : {
13739 398938 : $1->alias = $2;
13740 398938 : $$ = (Node *) $1;
13741 : }
13742 : | relation_expr opt_alias_clause tablesample_clause
13743 : {
13744 266 : RangeTableSample *n = (RangeTableSample *) $3;
13745 :
13746 266 : $1->alias = $2;
13747 : /* relation_expr goes inside the RangeTableSample node */
13748 266 : n->relation = (Node *) $1;
13749 266 : $$ = (Node *) n;
13750 : }
13751 : | func_table func_alias_clause
13752 : {
13753 47126 : RangeFunction *n = (RangeFunction *) $1;
13754 :
13755 47126 : n->alias = linitial($2);
13756 47126 : n->coldeflist = lsecond($2);
13757 47126 : $$ = (Node *) n;
13758 : }
13759 : | LATERAL_P func_table func_alias_clause
13760 : {
13761 1308 : RangeFunction *n = (RangeFunction *) $2;
13762 :
13763 1308 : n->lateral = true;
13764 1308 : n->alias = linitial($3);
13765 1308 : n->coldeflist = lsecond($3);
13766 1308 : $$ = (Node *) n;
13767 : }
13768 : | xmltable opt_alias_clause
13769 : {
13770 86 : RangeTableFunc *n = (RangeTableFunc *) $1;
13771 :
13772 86 : n->alias = $2;
13773 86 : $$ = (Node *) n;
13774 : }
13775 : | LATERAL_P xmltable opt_alias_clause
13776 : {
13777 140 : RangeTableFunc *n = (RangeTableFunc *) $2;
13778 :
13779 140 : n->lateral = true;
13780 140 : n->alias = $3;
13781 140 : $$ = (Node *) n;
13782 : }
13783 : | select_with_parens opt_alias_clause
13784 : {
13785 14218 : RangeSubselect *n = makeNode(RangeSubselect);
13786 :
13787 14218 : n->lateral = false;
13788 14218 : n->subquery = $1;
13789 14218 : n->alias = $2;
13790 14218 : $$ = (Node *) n;
13791 : }
13792 : | LATERAL_P select_with_parens opt_alias_clause
13793 : {
13794 1918 : RangeSubselect *n = makeNode(RangeSubselect);
13795 :
13796 1918 : n->lateral = true;
13797 1918 : n->subquery = $2;
13798 1918 : n->alias = $3;
13799 1918 : $$ = (Node *) n;
13800 : }
13801 : | joined_table
13802 : {
13803 83550 : $$ = (Node *) $1;
13804 : }
13805 : | '(' joined_table ')' alias_clause
13806 : {
13807 174 : $2->alias = $4;
13808 174 : $$ = (Node *) $2;
13809 : }
13810 : | json_table opt_alias_clause
13811 : {
13812 530 : JsonTable *jt = castNode(JsonTable, $1);
13813 :
13814 530 : jt->alias = $2;
13815 530 : $$ = (Node *) jt;
13816 : }
13817 : | LATERAL_P json_table opt_alias_clause
13818 : {
13819 0 : JsonTable *jt = castNode(JsonTable, $2);
13820 :
13821 0 : jt->alias = $3;
13822 0 : jt->lateral = true;
13823 0 : $$ = (Node *) jt;
13824 : }
13825 : ;
13826 :
13827 :
13828 : /*
13829 : * It may seem silly to separate joined_table from table_ref, but there is
13830 : * method in SQL's madness: if you don't do it this way you get reduce-
13831 : * reduce conflicts, because it's not clear to the parser generator whether
13832 : * to expect alias_clause after ')' or not. For the same reason we must
13833 : * treat 'JOIN' and 'join_type JOIN' separately, rather than allowing
13834 : * join_type to expand to empty; if we try it, the parser generator can't
13835 : * figure out when to reduce an empty join_type right after table_ref.
13836 : *
13837 : * Note that a CROSS JOIN is the same as an unqualified
13838 : * INNER JOIN, and an INNER JOIN/ON has the same shape
13839 : * but a qualification expression to limit membership.
13840 : * A NATURAL JOIN implicitly matches column names between
13841 : * tables and the shape is determined by which columns are
13842 : * in common. We'll collect columns during the later transformations.
13843 : */
13844 :
13845 : joined_table:
13846 : '(' joined_table ')'
13847 : {
13848 3980 : $$ = $2;
13849 : }
13850 : | table_ref CROSS JOIN table_ref
13851 : {
13852 : /* CROSS JOIN is same as unqualified inner join */
13853 514 : JoinExpr *n = makeNode(JoinExpr);
13854 :
13855 514 : n->jointype = JOIN_INNER;
13856 514 : n->isNatural = false;
13857 514 : n->larg = $1;
13858 514 : n->rarg = $4;
13859 514 : n->usingClause = NIL;
13860 514 : n->join_using_alias = NULL;
13861 514 : n->quals = NULL;
13862 514 : $$ = n;
13863 : }
13864 : | table_ref join_type JOIN table_ref join_qual
13865 : {
13866 47158 : JoinExpr *n = makeNode(JoinExpr);
13867 :
13868 47158 : n->jointype = $2;
13869 47158 : n->isNatural = false;
13870 47158 : n->larg = $1;
13871 47158 : n->rarg = $4;
13872 47158 : if ($5 != NULL && IsA($5, List))
13873 : {
13874 : /* USING clause */
13875 498 : n->usingClause = linitial_node(List, castNode(List, $5));
13876 498 : n->join_using_alias = lsecond_node(Alias, castNode(List, $5));
13877 : }
13878 : else
13879 : {
13880 : /* ON clause */
13881 46660 : n->quals = $5;
13882 : }
13883 47158 : $$ = n;
13884 : }
13885 : | table_ref JOIN table_ref join_qual
13886 : {
13887 : /* letting join_type reduce to empty doesn't work */
13888 35788 : JoinExpr *n = makeNode(JoinExpr);
13889 :
13890 35788 : n->jointype = JOIN_INNER;
13891 35788 : n->isNatural = false;
13892 35788 : n->larg = $1;
13893 35788 : n->rarg = $3;
13894 35788 : if ($4 != NULL && IsA($4, List))
13895 : {
13896 : /* USING clause */
13897 744 : n->usingClause = linitial_node(List, castNode(List, $4));
13898 744 : n->join_using_alias = lsecond_node(Alias, castNode(List, $4));
13899 : }
13900 : else
13901 : {
13902 : /* ON clause */
13903 35044 : n->quals = $4;
13904 : }
13905 35788 : $$ = n;
13906 : }
13907 : | table_ref NATURAL join_type JOIN table_ref
13908 : {
13909 78 : JoinExpr *n = makeNode(JoinExpr);
13910 :
13911 78 : n->jointype = $3;
13912 78 : n->isNatural = true;
13913 78 : n->larg = $1;
13914 78 : n->rarg = $5;
13915 78 : n->usingClause = NIL; /* figure out which columns later... */
13916 78 : n->join_using_alias = NULL;
13917 78 : n->quals = NULL; /* fill later */
13918 78 : $$ = n;
13919 : }
13920 : | table_ref NATURAL JOIN table_ref
13921 : {
13922 : /* letting join_type reduce to empty doesn't work */
13923 186 : JoinExpr *n = makeNode(JoinExpr);
13924 :
13925 186 : n->jointype = JOIN_INNER;
13926 186 : n->isNatural = true;
13927 186 : n->larg = $1;
13928 186 : n->rarg = $4;
13929 186 : n->usingClause = NIL; /* figure out which columns later... */
13930 186 : n->join_using_alias = NULL;
13931 186 : n->quals = NULL; /* fill later */
13932 186 : $$ = n;
13933 : }
13934 : ;
13935 :
13936 : alias_clause:
13937 : AS ColId '(' name_list ')'
13938 : {
13939 6698 : $$ = makeNode(Alias);
13940 6698 : $$->aliasname = $2;
13941 6698 : $$->colnames = $4;
13942 : }
13943 : | AS ColId
13944 : {
13945 10914 : $$ = makeNode(Alias);
13946 10914 : $$->aliasname = $2;
13947 : }
13948 : | ColId '(' name_list ')'
13949 : {
13950 5870 : $$ = makeNode(Alias);
13951 5870 : $$->aliasname = $1;
13952 5870 : $$->colnames = $3;
13953 : }
13954 : | ColId
13955 : {
13956 264144 : $$ = makeNode(Alias);
13957 264144 : $$->aliasname = $1;
13958 : }
13959 : ;
13960 :
13961 258570 : opt_alias_clause: alias_clause { $$ = $1; }
13962 157526 : | /*EMPTY*/ { $$ = NULL; }
13963 : ;
13964 :
13965 : /*
13966 : * The alias clause after JOIN ... USING only accepts the AS ColId spelling,
13967 : * per SQL standard. (The grammar could parse the other variants, but they
13968 : * don't seem to be useful, and it might lead to parser problems in the
13969 : * future.)
13970 : */
13971 : opt_alias_clause_for_join_using:
13972 : AS ColId
13973 : {
13974 84 : $$ = makeNode(Alias);
13975 84 : $$->aliasname = $2;
13976 : /* the column name list will be inserted later */
13977 : }
13978 1158 : | /*EMPTY*/ { $$ = NULL; }
13979 : ;
13980 :
13981 : /*
13982 : * func_alias_clause can include both an Alias and a coldeflist, so we make it
13983 : * return a 2-element list that gets disassembled by calling production.
13984 : */
13985 : func_alias_clause:
13986 : alias_clause
13987 : {
13988 28882 : $$ = list_make2($1, NIL);
13989 : }
13990 : | AS '(' TableFuncElementList ')'
13991 : {
13992 114 : $$ = list_make2(NULL, $3);
13993 : }
13994 : | AS ColId '(' TableFuncElementList ')'
13995 : {
13996 596 : Alias *a = makeNode(Alias);
13997 :
13998 596 : a->aliasname = $2;
13999 596 : $$ = list_make2(a, $4);
14000 : }
14001 : | ColId '(' TableFuncElementList ')'
14002 : {
14003 50 : Alias *a = makeNode(Alias);
14004 :
14005 50 : a->aliasname = $1;
14006 50 : $$ = list_make2(a, $3);
14007 : }
14008 : | /*EMPTY*/
14009 : {
14010 18792 : $$ = list_make2(NULL, NIL);
14011 : }
14012 : ;
14013 :
14014 1042 : join_type: FULL opt_outer { $$ = JOIN_FULL; }
14015 41782 : | LEFT opt_outer { $$ = JOIN_LEFT; }
14016 390 : | RIGHT opt_outer { $$ = JOIN_RIGHT; }
14017 4022 : | INNER_P { $$ = JOIN_INNER; }
14018 : ;
14019 :
14020 : /* OUTER is just noise... */
14021 : opt_outer: OUTER_P
14022 : | /*EMPTY*/
14023 : ;
14024 :
14025 : /* JOIN qualification clauses
14026 : * Possibilities are:
14027 : * USING ( column list ) [ AS alias ]
14028 : * allows only unqualified column names,
14029 : * which must match between tables.
14030 : * ON expr allows more general qualifications.
14031 : *
14032 : * We return USING as a two-element List (the first item being a sub-List
14033 : * of the common column names, and the second either an Alias item or NULL).
14034 : * An ON-expr will not be a List, so it can be told apart that way.
14035 : */
14036 :
14037 : join_qual: USING '(' name_list ')' opt_alias_clause_for_join_using
14038 : {
14039 1242 : $$ = (Node *) list_make2($3, $5);
14040 : }
14041 : | ON a_expr
14042 : {
14043 81704 : $$ = $2;
14044 : }
14045 : ;
14046 :
14047 :
14048 : relation_expr:
14049 : qualified_name
14050 : {
14051 : /* inheritance query, implicitly */
14052 480564 : $$ = $1;
14053 480564 : $$->inh = true;
14054 480564 : $$->alias = NULL;
14055 : }
14056 : | extended_relation_expr
14057 : {
14058 7310 : $$ = $1;
14059 : }
14060 : ;
14061 :
14062 : extended_relation_expr:
14063 : qualified_name '*'
14064 : {
14065 : /* inheritance query, explicitly */
14066 204 : $$ = $1;
14067 204 : $$->inh = true;
14068 204 : $$->alias = NULL;
14069 : }
14070 : | ONLY qualified_name
14071 : {
14072 : /* no inheritance */
14073 7112 : $$ = $2;
14074 7112 : $$->inh = false;
14075 7112 : $$->alias = NULL;
14076 : }
14077 : | ONLY '(' qualified_name ')'
14078 : {
14079 : /* no inheritance, SQL99-style syntax */
14080 0 : $$ = $3;
14081 0 : $$->inh = false;
14082 0 : $$->alias = NULL;
14083 : }
14084 : ;
14085 :
14086 :
14087 : relation_expr_list:
14088 2842 : relation_expr { $$ = list_make1($1); }
14089 11198 : | relation_expr_list ',' relation_expr { $$ = lappend($1, $3); }
14090 : ;
14091 :
14092 :
14093 : /*
14094 : * Given "UPDATE foo set set ...", we have to decide without looking any
14095 : * further ahead whether the first "set" is an alias or the UPDATE's SET
14096 : * keyword. Since "set" is allowed as a column name both interpretations
14097 : * are feasible. We resolve the shift/reduce conflict by giving the first
14098 : * relation_expr_opt_alias production a higher precedence than the SET token
14099 : * has, causing the parser to prefer to reduce, in effect assuming that the
14100 : * SET is not an alias.
14101 : */
14102 : relation_expr_opt_alias: relation_expr %prec UMINUS
14103 : {
14104 18916 : $$ = $1;
14105 : }
14106 : | relation_expr ColId
14107 : {
14108 2304 : Alias *alias = makeNode(Alias);
14109 :
14110 2304 : alias->aliasname = $2;
14111 2304 : $1->alias = alias;
14112 2304 : $$ = $1;
14113 : }
14114 : | relation_expr AS ColId
14115 : {
14116 90 : Alias *alias = makeNode(Alias);
14117 :
14118 90 : alias->aliasname = $3;
14119 90 : $1->alias = alias;
14120 90 : $$ = $1;
14121 : }
14122 : ;
14123 :
14124 : /*
14125 : * TABLESAMPLE decoration in a FROM item
14126 : */
14127 : tablesample_clause:
14128 : TABLESAMPLE func_name '(' expr_list ')' opt_repeatable_clause
14129 : {
14130 266 : RangeTableSample *n = makeNode(RangeTableSample);
14131 :
14132 : /* n->relation will be filled in later */
14133 266 : n->method = $2;
14134 266 : n->args = $4;
14135 266 : n->repeatable = $6;
14136 266 : n->location = @2;
14137 266 : $$ = (Node *) n;
14138 : }
14139 : ;
14140 :
14141 : opt_repeatable_clause:
14142 108 : REPEATABLE '(' a_expr ')' { $$ = (Node *) $3; }
14143 158 : | /*EMPTY*/ { $$ = NULL; }
14144 : ;
14145 :
14146 : /*
14147 : * func_table represents a function invocation in a FROM list. It can be
14148 : * a plain function call, like "foo(...)", or a ROWS FROM expression with
14149 : * one or more function calls, "ROWS FROM (foo(...), bar(...))",
14150 : * optionally with WITH ORDINALITY attached.
14151 : * In the ROWS FROM syntax, a column definition list can be given for each
14152 : * function, for example:
14153 : * ROWS FROM (foo() AS (foo_res_a text, foo_res_b text),
14154 : * bar() AS (bar_res_a text, bar_res_b text))
14155 : * It's also possible to attach a column definition list to the RangeFunction
14156 : * as a whole, but that's handled by the table_ref production.
14157 : */
14158 : func_table: func_expr_windowless opt_ordinality
14159 : {
14160 48308 : RangeFunction *n = makeNode(RangeFunction);
14161 :
14162 48308 : n->lateral = false;
14163 48308 : n->ordinality = $2;
14164 48308 : n->is_rowsfrom = false;
14165 48308 : n->functions = list_make1(list_make2($1, NIL));
14166 : /* alias and coldeflist are set by table_ref production */
14167 48308 : $$ = (Node *) n;
14168 : }
14169 : | ROWS FROM '(' rowsfrom_list ')' opt_ordinality
14170 : {
14171 132 : RangeFunction *n = makeNode(RangeFunction);
14172 :
14173 132 : n->lateral = false;
14174 132 : n->ordinality = $6;
14175 132 : n->is_rowsfrom = true;
14176 132 : n->functions = $4;
14177 : /* alias and coldeflist are set by table_ref production */
14178 132 : $$ = (Node *) n;
14179 : }
14180 : ;
14181 :
14182 : rowsfrom_item: func_expr_windowless opt_col_def_list
14183 318 : { $$ = list_make2($1, $2); }
14184 : ;
14185 :
14186 : rowsfrom_list:
14187 132 : rowsfrom_item { $$ = list_make1($1); }
14188 186 : | rowsfrom_list ',' rowsfrom_item { $$ = lappend($1, $3); }
14189 : ;
14190 :
14191 54 : opt_col_def_list: AS '(' TableFuncElementList ')' { $$ = $3; }
14192 264 : | /*EMPTY*/ { $$ = NIL; }
14193 : ;
14194 :
14195 922 : opt_ordinality: WITH_LA ORDINALITY { $$ = true; }
14196 47518 : | /*EMPTY*/ { $$ = false; }
14197 : ;
14198 :
14199 :
14200 : where_clause:
14201 212298 : WHERE a_expr { $$ = $2; }
14202 287088 : | /*EMPTY*/ { $$ = NULL; }
14203 : ;
14204 :
14205 : /* variant for UPDATE and DELETE */
14206 : where_or_current_clause:
14207 13696 : WHERE a_expr { $$ = $2; }
14208 : | WHERE CURRENT_P OF cursor_name
14209 : {
14210 266 : CurrentOfExpr *n = makeNode(CurrentOfExpr);
14211 :
14212 : /* cvarno is filled in by parse analysis */
14213 266 : n->cursor_name = $4;
14214 266 : n->cursor_param = 0;
14215 266 : $$ = (Node *) n;
14216 : }
14217 5122 : | /*EMPTY*/ { $$ = NULL; }
14218 : ;
14219 :
14220 :
14221 : OptTableFuncElementList:
14222 716 : TableFuncElementList { $$ = $1; }
14223 3786 : | /*EMPTY*/ { $$ = NIL; }
14224 : ;
14225 :
14226 : TableFuncElementList:
14227 : TableFuncElement
14228 : {
14229 1530 : $$ = list_make1($1);
14230 : }
14231 : | TableFuncElementList ',' TableFuncElement
14232 : {
14233 2058 : $$ = lappend($1, $3);
14234 : }
14235 : ;
14236 :
14237 : TableFuncElement: ColId Typename opt_collate_clause
14238 : {
14239 3652 : ColumnDef *n = makeNode(ColumnDef);
14240 :
14241 3652 : n->colname = $1;
14242 3652 : n->typeName = $2;
14243 3652 : n->inhcount = 0;
14244 3652 : n->is_local = true;
14245 3652 : n->is_not_null = false;
14246 3652 : n->is_from_type = false;
14247 3652 : n->storage = 0;
14248 3652 : n->raw_default = NULL;
14249 3652 : n->cooked_default = NULL;
14250 3652 : n->collClause = (CollateClause *) $3;
14251 3652 : n->collOid = InvalidOid;
14252 3652 : n->constraints = NIL;
14253 3652 : n->location = @1;
14254 3652 : $$ = (Node *) n;
14255 : }
14256 : ;
14257 :
14258 : /*
14259 : * XMLTABLE
14260 : */
14261 : xmltable:
14262 : XMLTABLE '(' c_expr xmlexists_argument COLUMNS xmltable_column_list ')'
14263 : {
14264 206 : RangeTableFunc *n = makeNode(RangeTableFunc);
14265 :
14266 206 : n->rowexpr = $3;
14267 206 : n->docexpr = $4;
14268 206 : n->columns = $6;
14269 206 : n->namespaces = NIL;
14270 206 : n->location = @1;
14271 206 : $$ = (Node *) n;
14272 : }
14273 : | XMLTABLE '(' XMLNAMESPACES '(' xml_namespace_list ')' ','
14274 : c_expr xmlexists_argument COLUMNS xmltable_column_list ')'
14275 : {
14276 20 : RangeTableFunc *n = makeNode(RangeTableFunc);
14277 :
14278 20 : n->rowexpr = $8;
14279 20 : n->docexpr = $9;
14280 20 : n->columns = $11;
14281 20 : n->namespaces = $5;
14282 20 : n->location = @1;
14283 20 : $$ = (Node *) n;
14284 : }
14285 : ;
14286 :
14287 226 : xmltable_column_list: xmltable_column_el { $$ = list_make1($1); }
14288 530 : | xmltable_column_list ',' xmltable_column_el { $$ = lappend($1, $3); }
14289 : ;
14290 :
14291 : xmltable_column_el:
14292 : ColId Typename
14293 : {
14294 204 : RangeTableFuncCol *fc = makeNode(RangeTableFuncCol);
14295 :
14296 204 : fc->colname = $1;
14297 204 : fc->for_ordinality = false;
14298 204 : fc->typeName = $2;
14299 204 : fc->is_not_null = false;
14300 204 : fc->colexpr = NULL;
14301 204 : fc->coldefexpr = NULL;
14302 204 : fc->location = @1;
14303 :
14304 204 : $$ = (Node *) fc;
14305 : }
14306 : | ColId Typename xmltable_column_option_list
14307 : {
14308 490 : RangeTableFuncCol *fc = makeNode(RangeTableFuncCol);
14309 : ListCell *option;
14310 490 : bool nullability_seen = false;
14311 :
14312 490 : fc->colname = $1;
14313 490 : fc->typeName = $2;
14314 490 : fc->for_ordinality = false;
14315 490 : fc->is_not_null = false;
14316 490 : fc->colexpr = NULL;
14317 490 : fc->coldefexpr = NULL;
14318 490 : fc->location = @1;
14319 :
14320 1092 : foreach(option, $3)
14321 : {
14322 602 : DefElem *defel = (DefElem *) lfirst(option);
14323 :
14324 602 : if (strcmp(defel->defname, "default") == 0)
14325 : {
14326 56 : if (fc->coldefexpr != NULL)
14327 0 : ereport(ERROR,
14328 : (errcode(ERRCODE_SYNTAX_ERROR),
14329 : errmsg("only one DEFAULT value is allowed"),
14330 : parser_errposition(defel->location)));
14331 56 : fc->coldefexpr = defel->arg;
14332 : }
14333 546 : else if (strcmp(defel->defname, "path") == 0)
14334 : {
14335 490 : if (fc->colexpr != NULL)
14336 0 : ereport(ERROR,
14337 : (errcode(ERRCODE_SYNTAX_ERROR),
14338 : errmsg("only one PATH value per column is allowed"),
14339 : parser_errposition(defel->location)));
14340 490 : fc->colexpr = defel->arg;
14341 : }
14342 56 : else if (strcmp(defel->defname, "__pg__is_not_null") == 0)
14343 : {
14344 56 : if (nullability_seen)
14345 0 : ereport(ERROR,
14346 : (errcode(ERRCODE_SYNTAX_ERROR),
14347 : errmsg("conflicting or redundant NULL / NOT NULL declarations for column \"%s\"", fc->colname),
14348 : parser_errposition(defel->location)));
14349 56 : fc->is_not_null = boolVal(defel->arg);
14350 56 : nullability_seen = true;
14351 : }
14352 : else
14353 : {
14354 0 : ereport(ERROR,
14355 : (errcode(ERRCODE_SYNTAX_ERROR),
14356 : errmsg("unrecognized column option \"%s\"",
14357 : defel->defname),
14358 : parser_errposition(defel->location)));
14359 : }
14360 : }
14361 490 : $$ = (Node *) fc;
14362 : }
14363 : | ColId FOR ORDINALITY
14364 : {
14365 62 : RangeTableFuncCol *fc = makeNode(RangeTableFuncCol);
14366 :
14367 62 : fc->colname = $1;
14368 62 : fc->for_ordinality = true;
14369 : /* other fields are ignored, initialized by makeNode */
14370 62 : fc->location = @1;
14371 :
14372 62 : $$ = (Node *) fc;
14373 : }
14374 : ;
14375 :
14376 : xmltable_column_option_list:
14377 : xmltable_column_option_el
14378 490 : { $$ = list_make1($1); }
14379 : | xmltable_column_option_list xmltable_column_option_el
14380 112 : { $$ = lappend($1, $2); }
14381 : ;
14382 :
14383 : xmltable_column_option_el:
14384 : IDENT b_expr
14385 : {
14386 6 : if (strcmp($1, "__pg__is_not_null") == 0)
14387 6 : ereport(ERROR,
14388 : (errcode(ERRCODE_SYNTAX_ERROR),
14389 : errmsg("option name \"%s\" cannot be used in XMLTABLE", $1),
14390 : parser_errposition(@1)));
14391 0 : $$ = makeDefElem($1, $2, @1);
14392 : }
14393 : | DEFAULT b_expr
14394 56 : { $$ = makeDefElem("default", $2, @1); }
14395 : | NOT NULL_P
14396 56 : { $$ = makeDefElem("__pg__is_not_null", (Node *) makeBoolean(true), @1); }
14397 : | NULL_P
14398 0 : { $$ = makeDefElem("__pg__is_not_null", (Node *) makeBoolean(false), @1); }
14399 : | PATH b_expr
14400 490 : { $$ = makeDefElem("path", $2, @1); }
14401 : ;
14402 :
14403 : xml_namespace_list:
14404 : xml_namespace_el
14405 20 : { $$ = list_make1($1); }
14406 : | xml_namespace_list ',' xml_namespace_el
14407 0 : { $$ = lappend($1, $3); }
14408 : ;
14409 :
14410 : xml_namespace_el:
14411 : b_expr AS ColLabel
14412 : {
14413 14 : $$ = makeNode(ResTarget);
14414 14 : $$->name = $3;
14415 14 : $$->indirection = NIL;
14416 14 : $$->val = $1;
14417 14 : $$->location = @1;
14418 : }
14419 : | DEFAULT b_expr
14420 : {
14421 6 : $$ = makeNode(ResTarget);
14422 6 : $$->name = NULL;
14423 6 : $$->indirection = NIL;
14424 6 : $$->val = $2;
14425 6 : $$->location = @1;
14426 : }
14427 : ;
14428 :
14429 : json_table:
14430 : JSON_TABLE '('
14431 : json_value_expr ',' a_expr json_table_path_name_opt
14432 : json_passing_clause_opt
14433 : COLUMNS '(' json_table_column_definition_list ')'
14434 : json_on_error_clause_opt
14435 : ')'
14436 : {
14437 536 : JsonTable *n = makeNode(JsonTable);
14438 : char *pathstring;
14439 :
14440 536 : n->context_item = (JsonValueExpr *) $3;
14441 536 : if (!IsA($5, A_Const) ||
14442 530 : castNode(A_Const, $5)->val.node.type != T_String)
14443 6 : ereport(ERROR,
14444 : errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
14445 : errmsg("only string constants are supported in JSON_TABLE path specification"),
14446 : parser_errposition(@5));
14447 530 : pathstring = castNode(A_Const, $5)->val.sval.sval;
14448 530 : n->pathspec = makeJsonTablePathSpec(pathstring, $6, @5, @6);
14449 530 : n->passing = $7;
14450 530 : n->columns = $10;
14451 530 : n->on_error = (JsonBehavior *) $12;
14452 530 : n->location = @1;
14453 530 : $$ = (Node *) n;
14454 : }
14455 : ;
14456 :
14457 : json_table_path_name_opt:
14458 62 : AS name { $$ = $2; }
14459 486 : | /* empty */ { $$ = NULL; }
14460 : ;
14461 :
14462 : json_table_column_definition_list:
14463 : json_table_column_definition
14464 826 : { $$ = list_make1($1); }
14465 : | json_table_column_definition_list ',' json_table_column_definition
14466 528 : { $$ = lappend($1, $3); }
14467 : ;
14468 :
14469 : json_table_column_definition:
14470 : ColId FOR ORDINALITY
14471 : {
14472 84 : JsonTableColumn *n = makeNode(JsonTableColumn);
14473 :
14474 84 : n->coltype = JTC_FOR_ORDINALITY;
14475 84 : n->name = $1;
14476 84 : n->location = @1;
14477 84 : $$ = (Node *) n;
14478 : }
14479 : | ColId Typename
14480 : json_table_column_path_clause_opt
14481 : json_wrapper_behavior
14482 : json_quotes_clause_opt
14483 : json_behavior_clause_opt
14484 : {
14485 734 : JsonTableColumn *n = makeNode(JsonTableColumn);
14486 :
14487 734 : n->coltype = JTC_REGULAR;
14488 734 : n->name = $1;
14489 734 : n->typeName = $2;
14490 734 : n->format = makeJsonFormat(JS_FORMAT_DEFAULT, JS_ENC_DEFAULT, -1);
14491 734 : n->pathspec = (JsonTablePathSpec *) $3;
14492 734 : n->wrapper = $4;
14493 734 : n->quotes = $5;
14494 734 : n->on_empty = (JsonBehavior *) linitial($6);
14495 734 : n->on_error = (JsonBehavior *) lsecond($6);
14496 734 : n->location = @1;
14497 734 : $$ = (Node *) n;
14498 : }
14499 : | ColId Typename json_format_clause
14500 : json_table_column_path_clause_opt
14501 : json_wrapper_behavior
14502 : json_quotes_clause_opt
14503 : json_behavior_clause_opt
14504 : {
14505 108 : JsonTableColumn *n = makeNode(JsonTableColumn);
14506 :
14507 108 : n->coltype = JTC_FORMATTED;
14508 108 : n->name = $1;
14509 108 : n->typeName = $2;
14510 108 : n->format = (JsonFormat *) $3;
14511 108 : n->pathspec = (JsonTablePathSpec *) $4;
14512 108 : n->wrapper = $5;
14513 108 : n->quotes = $6;
14514 108 : n->on_empty = (JsonBehavior *) linitial($7);
14515 108 : n->on_error = (JsonBehavior *) lsecond($7);
14516 108 : n->location = @1;
14517 108 : $$ = (Node *) n;
14518 : }
14519 : | ColId Typename
14520 : EXISTS json_table_column_path_clause_opt
14521 : json_on_error_clause_opt
14522 : {
14523 138 : JsonTableColumn *n = makeNode(JsonTableColumn);
14524 :
14525 138 : n->coltype = JTC_EXISTS;
14526 138 : n->name = $1;
14527 138 : n->typeName = $2;
14528 138 : n->format = makeJsonFormat(JS_FORMAT_DEFAULT, JS_ENC_DEFAULT, -1);
14529 138 : n->wrapper = JSW_NONE;
14530 138 : n->quotes = JS_QUOTES_UNSPEC;
14531 138 : n->pathspec = (JsonTablePathSpec *) $4;
14532 138 : n->on_empty = NULL;
14533 138 : n->on_error = (JsonBehavior *) $5;
14534 138 : n->location = @1;
14535 138 : $$ = (Node *) n;
14536 : }
14537 : | NESTED path_opt Sconst
14538 : COLUMNS '(' json_table_column_definition_list ')'
14539 : {
14540 144 : JsonTableColumn *n = makeNode(JsonTableColumn);
14541 :
14542 144 : n->coltype = JTC_NESTED;
14543 288 : n->pathspec = (JsonTablePathSpec *)
14544 144 : makeJsonTablePathSpec($3, NULL, @3, -1);
14545 144 : n->columns = $6;
14546 144 : n->location = @1;
14547 144 : $$ = (Node *) n;
14548 : }
14549 : | NESTED path_opt Sconst AS name
14550 : COLUMNS '(' json_table_column_definition_list ')'
14551 : {
14552 146 : JsonTableColumn *n = makeNode(JsonTableColumn);
14553 :
14554 146 : n->coltype = JTC_NESTED;
14555 292 : n->pathspec = (JsonTablePathSpec *)
14556 146 : makeJsonTablePathSpec($3, $5, @3, @5);
14557 146 : n->columns = $8;
14558 146 : n->location = @1;
14559 146 : $$ = (Node *) n;
14560 : }
14561 : ;
14562 :
14563 : path_opt:
14564 : PATH
14565 : | /* EMPTY */
14566 : ;
14567 :
14568 : json_table_column_path_clause_opt:
14569 : PATH Sconst
14570 828 : { $$ = (Node *) makeJsonTablePathSpec($2, NULL, @2, -1); }
14571 : | /* EMPTY */
14572 158 : { $$ = NULL; }
14573 : ;
14574 :
14575 : /*****************************************************************************
14576 : *
14577 : * Type syntax
14578 : * SQL introduces a large amount of type-specific syntax.
14579 : * Define individual clauses to handle these cases, and use
14580 : * the generic case to handle regular type-extensible Postgres syntax.
14581 : * - thomas 1997-10-10
14582 : *
14583 : *****************************************************************************/
14584 :
14585 : Typename: SimpleTypename opt_array_bounds
14586 : {
14587 525008 : $$ = $1;
14588 525008 : $$->arrayBounds = $2;
14589 : }
14590 : | SETOF SimpleTypename opt_array_bounds
14591 : {
14592 2424 : $$ = $2;
14593 2424 : $$->arrayBounds = $3;
14594 2424 : $$->setof = true;
14595 : }
14596 : /* SQL standard syntax, currently only one-dimensional */
14597 : | SimpleTypename ARRAY '[' Iconst ']'
14598 : {
14599 6 : $$ = $1;
14600 6 : $$->arrayBounds = list_make1(makeInteger($4));
14601 : }
14602 : | SETOF SimpleTypename ARRAY '[' Iconst ']'
14603 : {
14604 0 : $$ = $2;
14605 0 : $$->arrayBounds = list_make1(makeInteger($5));
14606 0 : $$->setof = true;
14607 : }
14608 : | SimpleTypename ARRAY
14609 : {
14610 0 : $$ = $1;
14611 0 : $$->arrayBounds = list_make1(makeInteger(-1));
14612 : }
14613 : | SETOF SimpleTypename ARRAY
14614 : {
14615 0 : $$ = $2;
14616 0 : $$->arrayBounds = list_make1(makeInteger(-1));
14617 0 : $$->setof = true;
14618 : }
14619 : ;
14620 :
14621 : opt_array_bounds:
14622 : opt_array_bounds '[' ']'
14623 14582 : { $$ = lappend($1, makeInteger(-1)); }
14624 : | opt_array_bounds '[' Iconst ']'
14625 62 : { $$ = lappend($1, makeInteger($3)); }
14626 : | /*EMPTY*/
14627 527432 : { $$ = NIL; }
14628 : ;
14629 :
14630 : SimpleTypename:
14631 412838 : GenericType { $$ = $1; }
14632 98830 : | Numeric { $$ = $1; }
14633 1972 : | Bit { $$ = $1; }
14634 3014 : | Character { $$ = $1; }
14635 5430 : | ConstDatetime { $$ = $1; }
14636 : | ConstInterval opt_interval
14637 : {
14638 3866 : $$ = $1;
14639 3866 : $$->typmods = $2;
14640 : }
14641 : | ConstInterval '(' Iconst ')'
14642 : {
14643 0 : $$ = $1;
14644 0 : $$->typmods = list_make2(makeIntConst(INTERVAL_FULL_RANGE, -1),
14645 : makeIntConst($3, @3));
14646 : }
14647 1896 : | JsonType { $$ = $1; }
14648 : ;
14649 :
14650 : /* We have a separate ConstTypename to allow defaulting fixed-length
14651 : * types such as CHAR() and BIT() to an unspecified length.
14652 : * SQL9x requires that these default to a length of one, but this
14653 : * makes no sense for constructs like CHAR 'hi' and BIT '0101',
14654 : * where there is an obvious better choice to make.
14655 : * Note that ConstInterval is not included here since it must
14656 : * be pushed up higher in the rules to accommodate the postfix
14657 : * options (e.g. INTERVAL '1' YEAR). Likewise, we have to handle
14658 : * the generic-type-name case in AexprConst to avoid premature
14659 : * reduce/reduce conflicts against function names.
14660 : */
14661 : ConstTypename:
14662 78 : Numeric { $$ = $1; }
14663 0 : | ConstBit { $$ = $1; }
14664 34 : | ConstCharacter { $$ = $1; }
14665 2800 : | ConstDatetime { $$ = $1; }
14666 264 : | JsonType { $$ = $1; }
14667 : ;
14668 :
14669 : /*
14670 : * GenericType covers all type names that don't have special syntax mandated
14671 : * by the standard, including qualified names. We also allow type modifiers.
14672 : * To avoid parsing conflicts against function invocations, the modifiers
14673 : * have to be shown as expr_list here, but parse analysis will only accept
14674 : * constants for them.
14675 : */
14676 : GenericType:
14677 : type_function_name opt_type_modifiers
14678 : {
14679 296598 : $$ = makeTypeName($1);
14680 296598 : $$->typmods = $2;
14681 296598 : $$->location = @1;
14682 : }
14683 : | type_function_name attrs opt_type_modifiers
14684 : {
14685 116240 : $$ = makeTypeNameFromNameList(lcons(makeString($1), $2));
14686 116240 : $$->typmods = $3;
14687 116240 : $$->location = @1;
14688 : }
14689 : ;
14690 :
14691 1350 : opt_type_modifiers: '(' expr_list ')' { $$ = $2; }
14692 417756 : | /* EMPTY */ { $$ = NIL; }
14693 : ;
14694 :
14695 : /*
14696 : * SQL numeric data types
14697 : */
14698 : Numeric: INT_P
14699 : {
14700 39370 : $$ = SystemTypeName("int4");
14701 39370 : $$->location = @1;
14702 : }
14703 : | INTEGER
14704 : {
14705 25472 : $$ = SystemTypeName("int4");
14706 25472 : $$->location = @1;
14707 : }
14708 : | SMALLINT
14709 : {
14710 1428 : $$ = SystemTypeName("int2");
14711 1428 : $$->location = @1;
14712 : }
14713 : | BIGINT
14714 : {
14715 5402 : $$ = SystemTypeName("int8");
14716 5402 : $$->location = @1;
14717 : }
14718 : | REAL
14719 : {
14720 6940 : $$ = SystemTypeName("float4");
14721 6940 : $$->location = @1;
14722 : }
14723 : | FLOAT_P opt_float
14724 : {
14725 538 : $$ = $2;
14726 538 : $$->location = @1;
14727 : }
14728 : | DOUBLE_P PRECISION
14729 : {
14730 784 : $$ = SystemTypeName("float8");
14731 784 : $$->location = @1;
14732 : }
14733 : | DECIMAL_P opt_type_modifiers
14734 : {
14735 36 : $$ = SystemTypeName("numeric");
14736 36 : $$->typmods = $2;
14737 36 : $$->location = @1;
14738 : }
14739 : | DEC opt_type_modifiers
14740 : {
14741 0 : $$ = SystemTypeName("numeric");
14742 0 : $$->typmods = $2;
14743 0 : $$->location = @1;
14744 : }
14745 : | NUMERIC opt_type_modifiers
14746 : {
14747 6232 : $$ = SystemTypeName("numeric");
14748 6232 : $$->typmods = $2;
14749 6232 : $$->location = @1;
14750 : }
14751 : | BOOLEAN_P
14752 : {
14753 12706 : $$ = SystemTypeName("bool");
14754 12706 : $$->location = @1;
14755 : }
14756 : ;
14757 :
14758 : opt_float: '(' Iconst ')'
14759 : {
14760 : /*
14761 : * Check FLOAT() precision limits assuming IEEE floating
14762 : * types - thomas 1997-09-18
14763 : */
14764 2 : if ($2 < 1)
14765 0 : ereport(ERROR,
14766 : (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
14767 : errmsg("precision for type float must be at least 1 bit"),
14768 : parser_errposition(@2)));
14769 2 : else if ($2 <= 24)
14770 2 : $$ = SystemTypeName("float4");
14771 0 : else if ($2 <= 53)
14772 0 : $$ = SystemTypeName("float8");
14773 : else
14774 0 : ereport(ERROR,
14775 : (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
14776 : errmsg("precision for type float must be less than 54 bits"),
14777 : parser_errposition(@2)));
14778 : }
14779 : | /*EMPTY*/
14780 : {
14781 536 : $$ = SystemTypeName("float8");
14782 : }
14783 : ;
14784 :
14785 : /*
14786 : * SQL bit-field data types
14787 : * The following implements BIT() and BIT VARYING().
14788 : */
14789 : Bit: BitWithLength
14790 : {
14791 1696 : $$ = $1;
14792 : }
14793 : | BitWithoutLength
14794 : {
14795 276 : $$ = $1;
14796 : }
14797 : ;
14798 :
14799 : /* ConstBit is like Bit except "BIT" defaults to unspecified length */
14800 : /* See notes for ConstCharacter, which addresses same issue for "CHAR" */
14801 : ConstBit: BitWithLength
14802 : {
14803 0 : $$ = $1;
14804 : }
14805 : | BitWithoutLength
14806 : {
14807 0 : $$ = $1;
14808 0 : $$->typmods = NIL;
14809 : }
14810 : ;
14811 :
14812 : BitWithLength:
14813 : BIT opt_varying '(' expr_list ')'
14814 : {
14815 : char *typname;
14816 :
14817 1696 : typname = $2 ? "varbit" : "bit";
14818 1696 : $$ = SystemTypeName(typname);
14819 1696 : $$->typmods = $4;
14820 1696 : $$->location = @1;
14821 : }
14822 : ;
14823 :
14824 : BitWithoutLength:
14825 : BIT opt_varying
14826 : {
14827 : /* bit defaults to bit(1), varbit to no limit */
14828 276 : if ($2)
14829 : {
14830 20 : $$ = SystemTypeName("varbit");
14831 : }
14832 : else
14833 : {
14834 256 : $$ = SystemTypeName("bit");
14835 256 : $$->typmods = list_make1(makeIntConst(1, -1));
14836 : }
14837 276 : $$->location = @1;
14838 : }
14839 : ;
14840 :
14841 :
14842 : /*
14843 : * SQL character data types
14844 : * The following implements CHAR() and VARCHAR().
14845 : */
14846 : Character: CharacterWithLength
14847 : {
14848 1724 : $$ = $1;
14849 : }
14850 : | CharacterWithoutLength
14851 : {
14852 1290 : $$ = $1;
14853 : }
14854 : ;
14855 :
14856 : ConstCharacter: CharacterWithLength
14857 : {
14858 12 : $$ = $1;
14859 : }
14860 : | CharacterWithoutLength
14861 : {
14862 : /* Length was not specified so allow to be unrestricted.
14863 : * This handles problems with fixed-length (bpchar) strings
14864 : * which in column definitions must default to a length
14865 : * of one, but should not be constrained if the length
14866 : * was not specified.
14867 : */
14868 22 : $$ = $1;
14869 22 : $$->typmods = NIL;
14870 : }
14871 : ;
14872 :
14873 : CharacterWithLength: character '(' Iconst ')'
14874 : {
14875 1736 : $$ = SystemTypeName($1);
14876 1736 : $$->typmods = list_make1(makeIntConst($3, @3));
14877 1736 : $$->location = @1;
14878 : }
14879 : ;
14880 :
14881 : CharacterWithoutLength: character
14882 : {
14883 1312 : $$ = SystemTypeName($1);
14884 : /* char defaults to char(1), varchar to no limit */
14885 1312 : if (strcmp($1, "bpchar") == 0)
14886 256 : $$->typmods = list_make1(makeIntConst(1, -1));
14887 1312 : $$->location = @1;
14888 : }
14889 : ;
14890 :
14891 : character: CHARACTER opt_varying
14892 566 : { $$ = $2 ? "varchar": "bpchar"; }
14893 : | CHAR_P opt_varying
14894 1172 : { $$ = $2 ? "varchar": "bpchar"; }
14895 : | VARCHAR
14896 1306 : { $$ = "varchar"; }
14897 : | NATIONAL CHARACTER opt_varying
14898 0 : { $$ = $3 ? "varchar": "bpchar"; }
14899 : | NATIONAL CHAR_P opt_varying
14900 0 : { $$ = $3 ? "varchar": "bpchar"; }
14901 : | NCHAR opt_varying
14902 4 : { $$ = $2 ? "varchar": "bpchar"; }
14903 : ;
14904 :
14905 : opt_varying:
14906 458 : VARYING { $$ = true; }
14907 3256 : | /*EMPTY*/ { $$ = false; }
14908 : ;
14909 :
14910 : /*
14911 : * SQL date/time types
14912 : */
14913 : ConstDatetime:
14914 : TIMESTAMP '(' Iconst ')' opt_timezone
14915 : {
14916 134 : if ($5)
14917 110 : $$ = SystemTypeName("timestamptz");
14918 : else
14919 24 : $$ = SystemTypeName("timestamp");
14920 134 : $$->typmods = list_make1(makeIntConst($3, @3));
14921 134 : $$->location = @1;
14922 : }
14923 : | TIMESTAMP opt_timezone
14924 : {
14925 5482 : if ($2)
14926 1454 : $$ = SystemTypeName("timestamptz");
14927 : else
14928 4028 : $$ = SystemTypeName("timestamp");
14929 5482 : $$->location = @1;
14930 : }
14931 : | TIME '(' Iconst ')' opt_timezone
14932 : {
14933 22 : if ($5)
14934 8 : $$ = SystemTypeName("timetz");
14935 : else
14936 14 : $$ = SystemTypeName("time");
14937 22 : $$->typmods = list_make1(makeIntConst($3, @3));
14938 22 : $$->location = @1;
14939 : }
14940 : | TIME opt_timezone
14941 : {
14942 2592 : if ($2)
14943 348 : $$ = SystemTypeName("timetz");
14944 : else
14945 2244 : $$ = SystemTypeName("time");
14946 2592 : $$->location = @1;
14947 : }
14948 : ;
14949 :
14950 : ConstInterval:
14951 : INTERVAL
14952 : {
14953 7176 : $$ = SystemTypeName("interval");
14954 7176 : $$->location = @1;
14955 : }
14956 : ;
14957 :
14958 : opt_timezone:
14959 1920 : WITH_LA TIME ZONE { $$ = true; }
14960 624 : | WITHOUT_LA TIME ZONE { $$ = false; }
14961 5686 : | /*EMPTY*/ { $$ = false; }
14962 : ;
14963 :
14964 : opt_interval:
14965 : YEAR_P
14966 12 : { $$ = list_make1(makeIntConst(INTERVAL_MASK(YEAR), @1)); }
14967 : | MONTH_P
14968 18 : { $$ = list_make1(makeIntConst(INTERVAL_MASK(MONTH), @1)); }
14969 : | DAY_P
14970 18 : { $$ = list_make1(makeIntConst(INTERVAL_MASK(DAY), @1)); }
14971 : | HOUR_P
14972 12 : { $$ = list_make1(makeIntConst(INTERVAL_MASK(HOUR), @1)); }
14973 : | MINUTE_P
14974 12 : { $$ = list_make1(makeIntConst(INTERVAL_MASK(MINUTE), @1)); }
14975 : | interval_second
14976 36 : { $$ = $1; }
14977 : | YEAR_P TO MONTH_P
14978 : {
14979 18 : $$ = list_make1(makeIntConst(INTERVAL_MASK(YEAR) |
14980 : INTERVAL_MASK(MONTH), @1));
14981 : }
14982 : | DAY_P TO HOUR_P
14983 : {
14984 24 : $$ = list_make1(makeIntConst(INTERVAL_MASK(DAY) |
14985 : INTERVAL_MASK(HOUR), @1));
14986 : }
14987 : | DAY_P TO MINUTE_P
14988 : {
14989 24 : $$ = list_make1(makeIntConst(INTERVAL_MASK(DAY) |
14990 : INTERVAL_MASK(HOUR) |
14991 : INTERVAL_MASK(MINUTE), @1));
14992 : }
14993 : | DAY_P TO interval_second
14994 : {
14995 48 : $$ = $3;
14996 48 : linitial($$) = makeIntConst(INTERVAL_MASK(DAY) |
14997 : INTERVAL_MASK(HOUR) |
14998 : INTERVAL_MASK(MINUTE) |
14999 48 : INTERVAL_MASK(SECOND), @1);
15000 : }
15001 : | HOUR_P TO MINUTE_P
15002 : {
15003 18 : $$ = list_make1(makeIntConst(INTERVAL_MASK(HOUR) |
15004 : INTERVAL_MASK(MINUTE), @1));
15005 : }
15006 : | HOUR_P TO interval_second
15007 : {
15008 36 : $$ = $3;
15009 36 : linitial($$) = makeIntConst(INTERVAL_MASK(HOUR) |
15010 : INTERVAL_MASK(MINUTE) |
15011 36 : INTERVAL_MASK(SECOND), @1);
15012 : }
15013 : | MINUTE_P TO interval_second
15014 : {
15015 66 : $$ = $3;
15016 66 : linitial($$) = makeIntConst(INTERVAL_MASK(MINUTE) |
15017 66 : INTERVAL_MASK(SECOND), @1);
15018 : }
15019 : | /*EMPTY*/
15020 6822 : { $$ = NIL; }
15021 : ;
15022 :
15023 : interval_second:
15024 : SECOND_P
15025 : {
15026 102 : $$ = list_make1(makeIntConst(INTERVAL_MASK(SECOND), @1));
15027 : }
15028 : | SECOND_P '(' Iconst ')'
15029 : {
15030 84 : $$ = list_make2(makeIntConst(INTERVAL_MASK(SECOND), @1),
15031 : makeIntConst($3, @3));
15032 : }
15033 : ;
15034 :
15035 : JsonType:
15036 : JSON
15037 : {
15038 2160 : $$ = SystemTypeName("json");
15039 2160 : $$->location = @1;
15040 : }
15041 : ;
15042 :
15043 : /*****************************************************************************
15044 : *
15045 : * expression grammar
15046 : *
15047 : *****************************************************************************/
15048 :
15049 : /*
15050 : * General expressions
15051 : * This is the heart of the expression syntax.
15052 : *
15053 : * We have two expression types: a_expr is the unrestricted kind, and
15054 : * b_expr is a subset that must be used in some places to avoid shift/reduce
15055 : * conflicts. For example, we can't do BETWEEN as "BETWEEN a_expr AND a_expr"
15056 : * because that use of AND conflicts with AND as a boolean operator. So,
15057 : * b_expr is used in BETWEEN and we remove boolean keywords from b_expr.
15058 : *
15059 : * Note that '(' a_expr ')' is a b_expr, so an unrestricted expression can
15060 : * always be used by surrounding it with parens.
15061 : *
15062 : * c_expr is all the productions that are common to a_expr and b_expr;
15063 : * it's factored out just to eliminate redundant coding.
15064 : *
15065 : * Be careful of productions involving more than one terminal token.
15066 : * By default, bison will assign such productions the precedence of their
15067 : * last terminal, but in nearly all cases you want it to be the precedence
15068 : * of the first terminal instead; otherwise you will not get the behavior
15069 : * you expect! So we use %prec annotations freely to set precedences.
15070 : */
15071 3678486 : a_expr: c_expr { $$ = $1; }
15072 : | a_expr TYPECAST Typename
15073 236060 : { $$ = makeTypeCast($1, $3, @2); }
15074 : | a_expr COLLATE any_name
15075 : {
15076 9074 : CollateClause *n = makeNode(CollateClause);
15077 :
15078 9074 : n->arg = $1;
15079 9074 : n->collname = $3;
15080 9074 : n->location = @2;
15081 9074 : $$ = (Node *) n;
15082 : }
15083 : | a_expr AT TIME ZONE a_expr %prec AT
15084 : {
15085 408 : $$ = (Node *) makeFuncCall(SystemFuncName("timezone"),
15086 408 : list_make2($5, $1),
15087 : COERCE_SQL_SYNTAX,
15088 408 : @2);
15089 : }
15090 : | a_expr AT LOCAL %prec AT
15091 : {
15092 42 : $$ = (Node *) makeFuncCall(SystemFuncName("timezone"),
15093 42 : list_make1($1),
15094 : COERCE_SQL_SYNTAX,
15095 : -1);
15096 : }
15097 : /*
15098 : * These operators must be called out explicitly in order to make use
15099 : * of bison's automatic operator-precedence handling. All other
15100 : * operator names are handled by the generic productions using "Op",
15101 : * below; and all those operators will have the same precedence.
15102 : *
15103 : * If you add more explicitly-known operators, be sure to add them
15104 : * also to b_expr and to the MathOp list below.
15105 : */
15106 : | '+' a_expr %prec UMINUS
15107 12 : { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "+", NULL, $2, @1); }
15108 : | '-' a_expr %prec UMINUS
15109 9220 : { $$ = doNegate($2, @1); }
15110 : | a_expr '+' a_expr
15111 14424 : { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "+", $1, $3, @2); }
15112 : | a_expr '-' a_expr
15113 4524 : { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "-", $1, $3, @2); }
15114 : | a_expr '*' a_expr
15115 6396 : { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "*", $1, $3, @2); }
15116 : | a_expr '/' a_expr
15117 3478 : { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "/", $1, $3, @2); }
15118 : | a_expr '%' a_expr
15119 2952 : { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "%", $1, $3, @2); }
15120 : | a_expr '^' a_expr
15121 476 : { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "^", $1, $3, @2); }
15122 : | a_expr '<' a_expr
15123 10644 : { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "<", $1, $3, @2); }
15124 : | a_expr '>' a_expr
15125 16712 : { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, ">", $1, $3, @2); }
15126 : | a_expr '=' a_expr
15127 389958 : { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "=", $1, $3, @2); }
15128 : | a_expr LESS_EQUALS a_expr
15129 5306 : { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "<=", $1, $3, @2); }
15130 : | a_expr GREATER_EQUALS a_expr
15131 7168 : { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, ">=", $1, $3, @2); }
15132 : | a_expr NOT_EQUALS a_expr
15133 39726 : { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "<>", $1, $3, @2); }
15134 :
15135 : | a_expr qual_Op a_expr %prec Op
15136 59644 : { $$ = (Node *) makeA_Expr(AEXPR_OP, $2, $1, $3, @2); }
15137 : | qual_Op a_expr %prec Op
15138 246 : { $$ = (Node *) makeA_Expr(AEXPR_OP, $1, NULL, $2, @1); }
15139 :
15140 : | a_expr AND a_expr
15141 232640 : { $$ = makeAndExpr($1, $3, @2); }
15142 : | a_expr OR a_expr
15143 16048 : { $$ = makeOrExpr($1, $3, @2); }
15144 : | NOT a_expr
15145 16132 : { $$ = makeNotExpr($2, @1); }
15146 : | NOT_LA a_expr %prec NOT
15147 0 : { $$ = makeNotExpr($2, @1); }
15148 :
15149 : | a_expr LIKE a_expr
15150 : {
15151 1964 : $$ = (Node *) makeSimpleA_Expr(AEXPR_LIKE, "~~",
15152 1964 : $1, $3, @2);
15153 : }
15154 : | a_expr LIKE a_expr ESCAPE a_expr %prec LIKE
15155 : {
15156 96 : FuncCall *n = makeFuncCall(SystemFuncName("like_escape"),
15157 96 : list_make2($3, $5),
15158 : COERCE_EXPLICIT_CALL,
15159 96 : @2);
15160 96 : $$ = (Node *) makeSimpleA_Expr(AEXPR_LIKE, "~~",
15161 96 : $1, (Node *) n, @2);
15162 : }
15163 : | a_expr NOT_LA LIKE a_expr %prec NOT_LA
15164 : {
15165 198 : $$ = (Node *) makeSimpleA_Expr(AEXPR_LIKE, "!~~",
15166 198 : $1, $4, @2);
15167 : }
15168 : | a_expr NOT_LA LIKE a_expr ESCAPE a_expr %prec NOT_LA
15169 : {
15170 96 : FuncCall *n = makeFuncCall(SystemFuncName("like_escape"),
15171 96 : list_make2($4, $6),
15172 : COERCE_EXPLICIT_CALL,
15173 96 : @2);
15174 96 : $$ = (Node *) makeSimpleA_Expr(AEXPR_LIKE, "!~~",
15175 96 : $1, (Node *) n, @2);
15176 : }
15177 : | a_expr ILIKE a_expr
15178 : {
15179 172 : $$ = (Node *) makeSimpleA_Expr(AEXPR_ILIKE, "~~*",
15180 172 : $1, $3, @2);
15181 : }
15182 : | a_expr ILIKE a_expr ESCAPE a_expr %prec ILIKE
15183 : {
15184 0 : FuncCall *n = makeFuncCall(SystemFuncName("like_escape"),
15185 0 : list_make2($3, $5),
15186 : COERCE_EXPLICIT_CALL,
15187 0 : @2);
15188 0 : $$ = (Node *) makeSimpleA_Expr(AEXPR_ILIKE, "~~*",
15189 0 : $1, (Node *) n, @2);
15190 : }
15191 : | a_expr NOT_LA ILIKE a_expr %prec NOT_LA
15192 : {
15193 30 : $$ = (Node *) makeSimpleA_Expr(AEXPR_ILIKE, "!~~*",
15194 30 : $1, $4, @2);
15195 : }
15196 : | a_expr NOT_LA ILIKE a_expr ESCAPE a_expr %prec NOT_LA
15197 : {
15198 0 : FuncCall *n = makeFuncCall(SystemFuncName("like_escape"),
15199 0 : list_make2($4, $6),
15200 : COERCE_EXPLICIT_CALL,
15201 0 : @2);
15202 0 : $$ = (Node *) makeSimpleA_Expr(AEXPR_ILIKE, "!~~*",
15203 0 : $1, (Node *) n, @2);
15204 : }
15205 :
15206 : | a_expr SIMILAR TO a_expr %prec SIMILAR
15207 : {
15208 88 : FuncCall *n = makeFuncCall(SystemFuncName("similar_to_escape"),
15209 88 : list_make1($4),
15210 : COERCE_EXPLICIT_CALL,
15211 88 : @2);
15212 88 : $$ = (Node *) makeSimpleA_Expr(AEXPR_SIMILAR, "~",
15213 88 : $1, (Node *) n, @2);
15214 : }
15215 : | a_expr SIMILAR TO a_expr ESCAPE a_expr %prec SIMILAR
15216 : {
15217 36 : FuncCall *n = makeFuncCall(SystemFuncName("similar_to_escape"),
15218 36 : list_make2($4, $6),
15219 : COERCE_EXPLICIT_CALL,
15220 36 : @2);
15221 36 : $$ = (Node *) makeSimpleA_Expr(AEXPR_SIMILAR, "~",
15222 36 : $1, (Node *) n, @2);
15223 : }
15224 : | a_expr NOT_LA SIMILAR TO a_expr %prec NOT_LA
15225 : {
15226 0 : FuncCall *n = makeFuncCall(SystemFuncName("similar_to_escape"),
15227 0 : list_make1($5),
15228 : COERCE_EXPLICIT_CALL,
15229 0 : @2);
15230 0 : $$ = (Node *) makeSimpleA_Expr(AEXPR_SIMILAR, "!~",
15231 0 : $1, (Node *) n, @2);
15232 : }
15233 : | a_expr NOT_LA SIMILAR TO a_expr ESCAPE a_expr %prec NOT_LA
15234 : {
15235 0 : FuncCall *n = makeFuncCall(SystemFuncName("similar_to_escape"),
15236 0 : list_make2($5, $7),
15237 : COERCE_EXPLICIT_CALL,
15238 0 : @2);
15239 0 : $$ = (Node *) makeSimpleA_Expr(AEXPR_SIMILAR, "!~",
15240 0 : $1, (Node *) n, @2);
15241 : }
15242 :
15243 : /* NullTest clause
15244 : * Define SQL-style Null test clause.
15245 : * Allow two forms described in the standard:
15246 : * a IS NULL
15247 : * a IS NOT NULL
15248 : * Allow two SQL extensions
15249 : * a ISNULL
15250 : * a NOTNULL
15251 : */
15252 : | a_expr IS NULL_P %prec IS
15253 : {
15254 5276 : NullTest *n = makeNode(NullTest);
15255 :
15256 5276 : n->arg = (Expr *) $1;
15257 5276 : n->nulltesttype = IS_NULL;
15258 5276 : n->location = @2;
15259 5276 : $$ = (Node *) n;
15260 : }
15261 : | a_expr ISNULL
15262 : {
15263 96 : NullTest *n = makeNode(NullTest);
15264 :
15265 96 : n->arg = (Expr *) $1;
15266 96 : n->nulltesttype = IS_NULL;
15267 96 : n->location = @2;
15268 96 : $$ = (Node *) n;
15269 : }
15270 : | a_expr IS NOT NULL_P %prec IS
15271 : {
15272 12992 : NullTest *n = makeNode(NullTest);
15273 :
15274 12992 : n->arg = (Expr *) $1;
15275 12992 : n->nulltesttype = IS_NOT_NULL;
15276 12992 : n->location = @2;
15277 12992 : $$ = (Node *) n;
15278 : }
15279 : | a_expr NOTNULL
15280 : {
15281 6 : NullTest *n = makeNode(NullTest);
15282 :
15283 6 : n->arg = (Expr *) $1;
15284 6 : n->nulltesttype = IS_NOT_NULL;
15285 6 : n->location = @2;
15286 6 : $$ = (Node *) n;
15287 : }
15288 : | row OVERLAPS row
15289 : {
15290 966 : if (list_length($1) != 2)
15291 0 : ereport(ERROR,
15292 : (errcode(ERRCODE_SYNTAX_ERROR),
15293 : errmsg("wrong number of parameters on left side of OVERLAPS expression"),
15294 : parser_errposition(@1)));
15295 966 : if (list_length($3) != 2)
15296 0 : ereport(ERROR,
15297 : (errcode(ERRCODE_SYNTAX_ERROR),
15298 : errmsg("wrong number of parameters on right side of OVERLAPS expression"),
15299 : parser_errposition(@3)));
15300 966 : $$ = (Node *) makeFuncCall(SystemFuncName("overlaps"),
15301 966 : list_concat($1, $3),
15302 : COERCE_SQL_SYNTAX,
15303 966 : @2);
15304 : }
15305 : | a_expr IS TRUE_P %prec IS
15306 : {
15307 434 : BooleanTest *b = makeNode(BooleanTest);
15308 :
15309 434 : b->arg = (Expr *) $1;
15310 434 : b->booltesttype = IS_TRUE;
15311 434 : b->location = @2;
15312 434 : $$ = (Node *) b;
15313 : }
15314 : | a_expr IS NOT TRUE_P %prec IS
15315 : {
15316 140 : BooleanTest *b = makeNode(BooleanTest);
15317 :
15318 140 : b->arg = (Expr *) $1;
15319 140 : b->booltesttype = IS_NOT_TRUE;
15320 140 : b->location = @2;
15321 140 : $$ = (Node *) b;
15322 : }
15323 : | a_expr IS FALSE_P %prec IS
15324 : {
15325 154 : BooleanTest *b = makeNode(BooleanTest);
15326 :
15327 154 : b->arg = (Expr *) $1;
15328 154 : b->booltesttype = IS_FALSE;
15329 154 : b->location = @2;
15330 154 : $$ = (Node *) b;
15331 : }
15332 : | a_expr IS NOT FALSE_P %prec IS
15333 : {
15334 92 : BooleanTest *b = makeNode(BooleanTest);
15335 :
15336 92 : b->arg = (Expr *) $1;
15337 92 : b->booltesttype = IS_NOT_FALSE;
15338 92 : b->location = @2;
15339 92 : $$ = (Node *) b;
15340 : }
15341 : | a_expr IS UNKNOWN %prec IS
15342 : {
15343 52 : BooleanTest *b = makeNode(BooleanTest);
15344 :
15345 52 : b->arg = (Expr *) $1;
15346 52 : b->booltesttype = IS_UNKNOWN;
15347 52 : b->location = @2;
15348 52 : $$ = (Node *) b;
15349 : }
15350 : | a_expr IS NOT UNKNOWN %prec IS
15351 : {
15352 48 : BooleanTest *b = makeNode(BooleanTest);
15353 :
15354 48 : b->arg = (Expr *) $1;
15355 48 : b->booltesttype = IS_NOT_UNKNOWN;
15356 48 : b->location = @2;
15357 48 : $$ = (Node *) b;
15358 : }
15359 : | a_expr IS DISTINCT FROM a_expr %prec IS
15360 : {
15361 1082 : $$ = (Node *) makeSimpleA_Expr(AEXPR_DISTINCT, "=", $1, $5, @2);
15362 : }
15363 : | a_expr IS NOT DISTINCT FROM a_expr %prec IS
15364 : {
15365 68 : $$ = (Node *) makeSimpleA_Expr(AEXPR_NOT_DISTINCT, "=", $1, $6, @2);
15366 : }
15367 : | a_expr BETWEEN opt_asymmetric b_expr AND a_expr %prec BETWEEN
15368 : {
15369 470 : $$ = (Node *) makeSimpleA_Expr(AEXPR_BETWEEN,
15370 : "BETWEEN",
15371 470 : $1,
15372 470 : (Node *) list_make2($4, $6),
15373 470 : @2);
15374 : }
15375 : | a_expr NOT_LA BETWEEN opt_asymmetric b_expr AND a_expr %prec NOT_LA
15376 : {
15377 12 : $$ = (Node *) makeSimpleA_Expr(AEXPR_NOT_BETWEEN,
15378 : "NOT BETWEEN",
15379 12 : $1,
15380 12 : (Node *) list_make2($5, $7),
15381 12 : @2);
15382 : }
15383 : | a_expr BETWEEN SYMMETRIC b_expr AND a_expr %prec BETWEEN
15384 : {
15385 12 : $$ = (Node *) makeSimpleA_Expr(AEXPR_BETWEEN_SYM,
15386 : "BETWEEN SYMMETRIC",
15387 12 : $1,
15388 12 : (Node *) list_make2($4, $6),
15389 12 : @2);
15390 : }
15391 : | a_expr NOT_LA BETWEEN SYMMETRIC b_expr AND a_expr %prec NOT_LA
15392 : {
15393 12 : $$ = (Node *) makeSimpleA_Expr(AEXPR_NOT_BETWEEN_SYM,
15394 : "NOT BETWEEN SYMMETRIC",
15395 12 : $1,
15396 12 : (Node *) list_make2($5, $7),
15397 12 : @2);
15398 : }
15399 : | a_expr IN_P select_with_parens
15400 : {
15401 : /* generate foo = ANY (subquery) */
15402 5572 : SubLink *n = makeNode(SubLink);
15403 :
15404 5572 : n->subselect = $3;
15405 5572 : n->subLinkType = ANY_SUBLINK;
15406 5572 : n->subLinkId = 0;
15407 5572 : n->testexpr = $1;
15408 5572 : n->operName = NIL; /* show it's IN not = ANY */
15409 5572 : n->location = @2;
15410 5572 : $$ = (Node *) n;
15411 : }
15412 : | a_expr IN_P '(' expr_list ')'
15413 : {
15414 : /* generate scalar IN expression */
15415 19040 : A_Expr *n = makeSimpleA_Expr(AEXPR_IN, "=", $1, (Node *) $4, @2);
15416 :
15417 19040 : n->rexpr_list_start = @3;
15418 19040 : n->rexpr_list_end = @5;
15419 19040 : $$ = (Node *) n;
15420 : }
15421 : | a_expr NOT_LA IN_P select_with_parens %prec NOT_LA
15422 : {
15423 : /* generate NOT (foo = ANY (subquery)) */
15424 120 : SubLink *n = makeNode(SubLink);
15425 :
15426 120 : n->subselect = $4;
15427 120 : n->subLinkType = ANY_SUBLINK;
15428 120 : n->subLinkId = 0;
15429 120 : n->testexpr = $1;
15430 120 : n->operName = NIL; /* show it's IN not = ANY */
15431 120 : n->location = @2;
15432 : /* Stick a NOT on top; must have same parse location */
15433 120 : $$ = makeNotExpr((Node *) n, @2);
15434 : }
15435 : | a_expr NOT_LA IN_P '(' expr_list ')'
15436 : {
15437 : /* generate scalar NOT IN expression */
15438 2692 : A_Expr *n = makeSimpleA_Expr(AEXPR_IN, "<>", $1, (Node *) $5, @2);
15439 :
15440 2692 : n->rexpr_list_start = @4;
15441 2692 : n->rexpr_list_end = @6;
15442 2692 : $$ = (Node *) n;
15443 : }
15444 : | a_expr subquery_Op sub_type select_with_parens %prec Op
15445 : {
15446 180 : SubLink *n = makeNode(SubLink);
15447 :
15448 180 : n->subLinkType = $3;
15449 180 : n->subLinkId = 0;
15450 180 : n->testexpr = $1;
15451 180 : n->operName = $2;
15452 180 : n->subselect = $4;
15453 180 : n->location = @2;
15454 180 : $$ = (Node *) n;
15455 : }
15456 : | a_expr subquery_Op sub_type '(' a_expr ')' %prec Op
15457 : {
15458 16838 : if ($3 == ANY_SUBLINK)
15459 16538 : $$ = (Node *) makeA_Expr(AEXPR_OP_ANY, $2, $1, $5, @2);
15460 : else
15461 300 : $$ = (Node *) makeA_Expr(AEXPR_OP_ALL, $2, $1, $5, @2);
15462 : }
15463 : | UNIQUE opt_unique_null_treatment select_with_parens
15464 : {
15465 : /* Not sure how to get rid of the parentheses
15466 : * but there are lots of shift/reduce errors without them.
15467 : *
15468 : * Should be able to implement this by plopping the entire
15469 : * select into a node, then transforming the target expressions
15470 : * from whatever they are into count(*), and testing the
15471 : * entire result equal to one.
15472 : * But, will probably implement a separate node in the executor.
15473 : */
15474 0 : ereport(ERROR,
15475 : (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
15476 : errmsg("UNIQUE predicate is not yet implemented"),
15477 : parser_errposition(@1)));
15478 : }
15479 : | a_expr IS DOCUMENT_P %prec IS
15480 : {
15481 18 : $$ = makeXmlExpr(IS_DOCUMENT, NULL, NIL,
15482 18 : list_make1($1), @2);
15483 : }
15484 : | a_expr IS NOT DOCUMENT_P %prec IS
15485 : {
15486 18 : $$ = makeNotExpr(makeXmlExpr(IS_DOCUMENT, NULL, NIL,
15487 18 : list_make1($1), @2),
15488 18 : @2);
15489 : }
15490 : | a_expr IS NORMALIZED %prec IS
15491 : {
15492 12 : $$ = (Node *) makeFuncCall(SystemFuncName("is_normalized"),
15493 12 : list_make1($1),
15494 : COERCE_SQL_SYNTAX,
15495 12 : @2);
15496 : }
15497 : | a_expr IS unicode_normal_form NORMALIZED %prec IS
15498 : {
15499 36 : $$ = (Node *) makeFuncCall(SystemFuncName("is_normalized"),
15500 36 : list_make2($1, makeStringConst($3, @3)),
15501 : COERCE_SQL_SYNTAX,
15502 36 : @2);
15503 : }
15504 : | a_expr IS NOT NORMALIZED %prec IS
15505 : {
15506 0 : $$ = makeNotExpr((Node *) makeFuncCall(SystemFuncName("is_normalized"),
15507 0 : list_make1($1),
15508 : COERCE_SQL_SYNTAX,
15509 0 : @2),
15510 0 : @2);
15511 : }
15512 : | a_expr IS NOT unicode_normal_form NORMALIZED %prec IS
15513 : {
15514 0 : $$ = makeNotExpr((Node *) makeFuncCall(SystemFuncName("is_normalized"),
15515 0 : list_make2($1, makeStringConst($4, @4)),
15516 : COERCE_SQL_SYNTAX,
15517 0 : @2),
15518 0 : @2);
15519 : }
15520 : | a_expr IS json_predicate_type_constraint
15521 : json_key_uniqueness_constraint_opt %prec IS
15522 : {
15523 304 : JsonFormat *format = makeJsonFormat(JS_FORMAT_DEFAULT, JS_ENC_DEFAULT, -1);
15524 :
15525 304 : $$ = makeJsonIsPredicate($1, format, $3, $4, @1);
15526 : }
15527 : /*
15528 : * Required by SQL/JSON, but there are conflicts
15529 : | a_expr
15530 : json_format_clause
15531 : IS json_predicate_type_constraint
15532 : json_key_uniqueness_constraint_opt %prec IS
15533 : {
15534 : $$ = makeJsonIsPredicate($1, $2, $4, $5, @1);
15535 : }
15536 : */
15537 : | a_expr IS NOT
15538 : json_predicate_type_constraint
15539 : json_key_uniqueness_constraint_opt %prec IS
15540 : {
15541 46 : JsonFormat *format = makeJsonFormat(JS_FORMAT_DEFAULT, JS_ENC_DEFAULT, -1);
15542 :
15543 46 : $$ = makeNotExpr(makeJsonIsPredicate($1, format, $4, $5, @1), @1);
15544 : }
15545 : /*
15546 : * Required by SQL/JSON, but there are conflicts
15547 : | a_expr
15548 : json_format_clause
15549 : IS NOT
15550 : json_predicate_type_constraint
15551 : json_key_uniqueness_constraint_opt %prec IS
15552 : {
15553 : $$ = makeNotExpr(makeJsonIsPredicate($1, $2, $5, $6, @1), @1);
15554 : }
15555 : */
15556 : | DEFAULT
15557 : {
15558 : /*
15559 : * The SQL spec only allows DEFAULT in "contextually typed
15560 : * expressions", but for us, it's easier to allow it in
15561 : * any a_expr and then throw error during parse analysis
15562 : * if it's in an inappropriate context. This way also
15563 : * lets us say something smarter than "syntax error".
15564 : */
15565 1522 : SetToDefault *n = makeNode(SetToDefault);
15566 :
15567 : /* parse analysis will fill in the rest */
15568 1522 : n->location = @1;
15569 1522 : $$ = (Node *) n;
15570 : }
15571 : ;
15572 :
15573 : /*
15574 : * Restricted expressions
15575 : *
15576 : * b_expr is a subset of the complete expression syntax defined by a_expr.
15577 : *
15578 : * Presently, AND, NOT, IS, and IN are the a_expr keywords that would
15579 : * cause trouble in the places where b_expr is used. For simplicity, we
15580 : * just eliminate all the boolean-keyword-operator productions from b_expr.
15581 : */
15582 : b_expr: c_expr
15583 3806 : { $$ = $1; }
15584 : | b_expr TYPECAST Typename
15585 212 : { $$ = makeTypeCast($1, $3, @2); }
15586 : | '+' b_expr %prec UMINUS
15587 0 : { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "+", NULL, $2, @1); }
15588 : | '-' b_expr %prec UMINUS
15589 66 : { $$ = doNegate($2, @1); }
15590 : | b_expr '+' b_expr
15591 36 : { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "+", $1, $3, @2); }
15592 : | b_expr '-' b_expr
15593 12 : { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "-", $1, $3, @2); }
15594 : | b_expr '*' b_expr
15595 12 : { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "*", $1, $3, @2); }
15596 : | b_expr '/' b_expr
15597 0 : { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "/", $1, $3, @2); }
15598 : | b_expr '%' b_expr
15599 0 : { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "%", $1, $3, @2); }
15600 : | b_expr '^' b_expr
15601 6 : { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "^", $1, $3, @2); }
15602 : | b_expr '<' b_expr
15603 0 : { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "<", $1, $3, @2); }
15604 : | b_expr '>' b_expr
15605 0 : { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, ">", $1, $3, @2); }
15606 : | b_expr '=' b_expr
15607 0 : { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "=", $1, $3, @2); }
15608 : | b_expr LESS_EQUALS b_expr
15609 0 : { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "<=", $1, $3, @2); }
15610 : | b_expr GREATER_EQUALS b_expr
15611 0 : { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, ">=", $1, $3, @2); }
15612 : | b_expr NOT_EQUALS b_expr
15613 0 : { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "<>", $1, $3, @2); }
15614 : | b_expr qual_Op b_expr %prec Op
15615 12 : { $$ = (Node *) makeA_Expr(AEXPR_OP, $2, $1, $3, @2); }
15616 : | qual_Op b_expr %prec Op
15617 0 : { $$ = (Node *) makeA_Expr(AEXPR_OP, $1, NULL, $2, @1); }
15618 : | b_expr IS DISTINCT FROM b_expr %prec IS
15619 : {
15620 0 : $$ = (Node *) makeSimpleA_Expr(AEXPR_DISTINCT, "=", $1, $5, @2);
15621 : }
15622 : | b_expr IS NOT DISTINCT FROM b_expr %prec IS
15623 : {
15624 0 : $$ = (Node *) makeSimpleA_Expr(AEXPR_NOT_DISTINCT, "=", $1, $6, @2);
15625 : }
15626 : | b_expr IS DOCUMENT_P %prec IS
15627 : {
15628 0 : $$ = makeXmlExpr(IS_DOCUMENT, NULL, NIL,
15629 0 : list_make1($1), @2);
15630 : }
15631 : | b_expr IS NOT DOCUMENT_P %prec IS
15632 : {
15633 0 : $$ = makeNotExpr(makeXmlExpr(IS_DOCUMENT, NULL, NIL,
15634 0 : list_make1($1), @2),
15635 0 : @2);
15636 : }
15637 : ;
15638 :
15639 : /*
15640 : * Productions that can be used in both a_expr and b_expr.
15641 : *
15642 : * Note: productions that refer recursively to a_expr or b_expr mostly
15643 : * cannot appear here. However, it's OK to refer to a_exprs that occur
15644 : * inside parentheses, such as function arguments; that cannot introduce
15645 : * ambiguity to the b_expr syntax.
15646 : */
15647 1810880 : c_expr: columnref { $$ = $1; }
15648 1244886 : | AexprConst { $$ = $1; }
15649 : | PARAM opt_indirection
15650 : {
15651 46478 : ParamRef *p = makeNode(ParamRef);
15652 :
15653 46478 : p->number = $1;
15654 46478 : p->location = @1;
15655 46478 : if ($2)
15656 : {
15657 1084 : A_Indirection *n = makeNode(A_Indirection);
15658 :
15659 1084 : n->arg = (Node *) p;
15660 1084 : n->indirection = check_indirection($2, yyscanner);
15661 1084 : $$ = (Node *) n;
15662 : }
15663 : else
15664 45394 : $$ = (Node *) p;
15665 : }
15666 : | '(' a_expr ')' opt_indirection
15667 : {
15668 90254 : if ($4)
15669 : {
15670 12374 : A_Indirection *n = makeNode(A_Indirection);
15671 :
15672 12374 : n->arg = $2;
15673 12374 : n->indirection = check_indirection($4, yyscanner);
15674 12374 : $$ = (Node *) n;
15675 : }
15676 : else
15677 77880 : $$ = $2;
15678 : }
15679 : | case_expr
15680 39138 : { $$ = $1; }
15681 : | func_expr
15682 394758 : { $$ = $1; }
15683 : | select_with_parens %prec UMINUS
15684 : {
15685 27526 : SubLink *n = makeNode(SubLink);
15686 :
15687 27526 : n->subLinkType = EXPR_SUBLINK;
15688 27526 : n->subLinkId = 0;
15689 27526 : n->testexpr = NULL;
15690 27526 : n->operName = NIL;
15691 27526 : n->subselect = $1;
15692 27526 : n->location = @1;
15693 27526 : $$ = (Node *) n;
15694 : }
15695 : | select_with_parens indirection
15696 : {
15697 : /*
15698 : * Because the select_with_parens nonterminal is designed
15699 : * to "eat" as many levels of parens as possible, the
15700 : * '(' a_expr ')' opt_indirection production above will
15701 : * fail to match a sub-SELECT with indirection decoration;
15702 : * the sub-SELECT won't be regarded as an a_expr as long
15703 : * as there are parens around it. To support applying
15704 : * subscripting or field selection to a sub-SELECT result,
15705 : * we need this redundant-looking production.
15706 : */
15707 18 : SubLink *n = makeNode(SubLink);
15708 18 : A_Indirection *a = makeNode(A_Indirection);
15709 :
15710 18 : n->subLinkType = EXPR_SUBLINK;
15711 18 : n->subLinkId = 0;
15712 18 : n->testexpr = NULL;
15713 18 : n->operName = NIL;
15714 18 : n->subselect = $1;
15715 18 : n->location = @1;
15716 18 : a->arg = (Node *) n;
15717 18 : a->indirection = check_indirection($2, yyscanner);
15718 18 : $$ = (Node *) a;
15719 : }
15720 : | EXISTS select_with_parens
15721 : {
15722 6190 : SubLink *n = makeNode(SubLink);
15723 :
15724 6190 : n->subLinkType = EXISTS_SUBLINK;
15725 6190 : n->subLinkId = 0;
15726 6190 : n->testexpr = NULL;
15727 6190 : n->operName = NIL;
15728 6190 : n->subselect = $2;
15729 6190 : n->location = @1;
15730 6190 : $$ = (Node *) n;
15731 : }
15732 : | ARRAY select_with_parens
15733 : {
15734 8432 : SubLink *n = makeNode(SubLink);
15735 :
15736 8432 : n->subLinkType = ARRAY_SUBLINK;
15737 8432 : n->subLinkId = 0;
15738 8432 : n->testexpr = NULL;
15739 8432 : n->operName = NIL;
15740 8432 : n->subselect = $2;
15741 8432 : n->location = @1;
15742 8432 : $$ = (Node *) n;
15743 : }
15744 : | ARRAY array_expr
15745 : {
15746 7494 : A_ArrayExpr *n = castNode(A_ArrayExpr, $2);
15747 :
15748 : /* point outermost A_ArrayExpr to the ARRAY keyword */
15749 7494 : n->location = @1;
15750 7494 : $$ = (Node *) n;
15751 : }
15752 : | explicit_row
15753 : {
15754 3856 : RowExpr *r = makeNode(RowExpr);
15755 :
15756 3856 : r->args = $1;
15757 3856 : r->row_typeid = InvalidOid; /* not analyzed yet */
15758 3856 : r->colnames = NIL; /* to be filled in during analysis */
15759 3856 : r->row_format = COERCE_EXPLICIT_CALL; /* abuse */
15760 3856 : r->location = @1;
15761 3856 : $$ = (Node *) r;
15762 : }
15763 : | implicit_row
15764 : {
15765 2706 : RowExpr *r = makeNode(RowExpr);
15766 :
15767 2706 : r->args = $1;
15768 2706 : r->row_typeid = InvalidOid; /* not analyzed yet */
15769 2706 : r->colnames = NIL; /* to be filled in during analysis */
15770 2706 : r->row_format = COERCE_IMPLICIT_CAST; /* abuse */
15771 2706 : r->location = @1;
15772 2706 : $$ = (Node *) r;
15773 : }
15774 : | GROUPING '(' expr_list ')'
15775 : {
15776 362 : GroupingFunc *g = makeNode(GroupingFunc);
15777 :
15778 362 : g->args = $3;
15779 362 : g->location = @1;
15780 362 : $$ = (Node *) g;
15781 : }
15782 : ;
15783 :
15784 : func_application: func_name '(' ')'
15785 : {
15786 33290 : $$ = (Node *) makeFuncCall($1, NIL,
15787 : COERCE_EXPLICIT_CALL,
15788 33292 : @1);
15789 : }
15790 : | func_name '(' func_arg_list opt_sort_clause ')'
15791 : {
15792 319600 : FuncCall *n = makeFuncCall($1, $3,
15793 : COERCE_EXPLICIT_CALL,
15794 319600 : @1);
15795 :
15796 319600 : n->agg_order = $4;
15797 319600 : $$ = (Node *) n;
15798 : }
15799 : | func_name '(' VARIADIC func_arg_expr opt_sort_clause ')'
15800 : {
15801 632 : FuncCall *n = makeFuncCall($1, list_make1($4),
15802 : COERCE_EXPLICIT_CALL,
15803 632 : @1);
15804 :
15805 632 : n->func_variadic = true;
15806 632 : n->agg_order = $5;
15807 632 : $$ = (Node *) n;
15808 : }
15809 : | func_name '(' func_arg_list ',' VARIADIC func_arg_expr opt_sort_clause ')'
15810 : {
15811 168 : FuncCall *n = makeFuncCall($1, lappend($3, $6),
15812 : COERCE_EXPLICIT_CALL,
15813 168 : @1);
15814 :
15815 168 : n->func_variadic = true;
15816 168 : n->agg_order = $7;
15817 168 : $$ = (Node *) n;
15818 : }
15819 : | func_name '(' ALL func_arg_list opt_sort_clause ')'
15820 : {
15821 0 : FuncCall *n = makeFuncCall($1, $4,
15822 : COERCE_EXPLICIT_CALL,
15823 0 : @1);
15824 :
15825 0 : n->agg_order = $5;
15826 : /* Ideally we'd mark the FuncCall node to indicate
15827 : * "must be an aggregate", but there's no provision
15828 : * for that in FuncCall at the moment.
15829 : */
15830 0 : $$ = (Node *) n;
15831 : }
15832 : | func_name '(' DISTINCT func_arg_list opt_sort_clause ')'
15833 : {
15834 556 : FuncCall *n = makeFuncCall($1, $4,
15835 : COERCE_EXPLICIT_CALL,
15836 556 : @1);
15837 :
15838 556 : n->agg_order = $5;
15839 556 : n->agg_distinct = true;
15840 556 : $$ = (Node *) n;
15841 : }
15842 : | func_name '(' '*' ')'
15843 : {
15844 : /*
15845 : * We consider AGGREGATE(*) to invoke a parameterless
15846 : * aggregate. This does the right thing for COUNT(*),
15847 : * and there are no other aggregates in SQL that accept
15848 : * '*' as parameter.
15849 : *
15850 : * The FuncCall node is also marked agg_star = true,
15851 : * so that later processing can detect what the argument
15852 : * really was.
15853 : */
15854 13384 : FuncCall *n = makeFuncCall($1, NIL,
15855 : COERCE_EXPLICIT_CALL,
15856 13384 : @1);
15857 :
15858 13384 : n->agg_star = true;
15859 13384 : $$ = (Node *) n;
15860 : }
15861 : ;
15862 :
15863 :
15864 : /*
15865 : * func_expr and its cousin func_expr_windowless are split out from c_expr just
15866 : * so that we have classifications for "everything that is a function call or
15867 : * looks like one". This isn't very important, but it saves us having to
15868 : * document which variants are legal in places like "FROM function()" or the
15869 : * backwards-compatible functional-index syntax for CREATE INDEX.
15870 : * (Note that many of the special SQL functions wouldn't actually make any
15871 : * sense as functional index entries, but we ignore that consideration here.)
15872 : */
15873 : func_expr: func_application within_group_clause filter_clause null_treatment over_clause
15874 : {
15875 317986 : FuncCall *n = (FuncCall *) $1;
15876 :
15877 : /*
15878 : * The order clause for WITHIN GROUP and the one for
15879 : * plain-aggregate ORDER BY share a field, so we have to
15880 : * check here that at most one is present. We also check
15881 : * for DISTINCT and VARIADIC here to give a better error
15882 : * location. Other consistency checks are deferred to
15883 : * parse analysis.
15884 : */
15885 317986 : if ($2 != NIL)
15886 : {
15887 348 : if (n->agg_order != NIL)
15888 6 : ereport(ERROR,
15889 : (errcode(ERRCODE_SYNTAX_ERROR),
15890 : errmsg("cannot use multiple ORDER BY clauses with WITHIN GROUP"),
15891 : parser_errposition(@2)));
15892 342 : if (n->agg_distinct)
15893 0 : ereport(ERROR,
15894 : (errcode(ERRCODE_SYNTAX_ERROR),
15895 : errmsg("cannot use DISTINCT with WITHIN GROUP"),
15896 : parser_errposition(@2)));
15897 342 : if (n->func_variadic)
15898 0 : ereport(ERROR,
15899 : (errcode(ERRCODE_SYNTAX_ERROR),
15900 : errmsg("cannot use VARIADIC with WITHIN GROUP"),
15901 : parser_errposition(@2)));
15902 342 : n->agg_order = $2;
15903 342 : n->agg_within_group = true;
15904 : }
15905 317980 : n->agg_filter = $3;
15906 317980 : n->ignore_nulls = $4;
15907 317980 : n->over = $5;
15908 317980 : $$ = (Node *) n;
15909 : }
15910 : | json_aggregate_func filter_clause over_clause
15911 : {
15912 720 : JsonAggConstructor *n = IsA($1, JsonObjectAgg) ?
15913 360 : ((JsonObjectAgg *) $1)->constructor :
15914 156 : ((JsonArrayAgg *) $1)->constructor;
15915 :
15916 360 : n->agg_filter = $2;
15917 360 : n->over = $3;
15918 360 : $$ = (Node *) $1;
15919 : }
15920 : | func_expr_common_subexpr
15921 76418 : { $$ = $1; }
15922 : ;
15923 :
15924 : /*
15925 : * Like func_expr but does not accept WINDOW functions directly
15926 : * (but they can still be contained in arguments for functions etc).
15927 : * Use this when window expressions are not allowed, where needed to
15928 : * disambiguate the grammar (e.g. in CREATE INDEX).
15929 : */
15930 : func_expr_windowless:
15931 49012 : func_application { $$ = $1; }
15932 402 : | func_expr_common_subexpr { $$ = $1; }
15933 0 : | json_aggregate_func { $$ = $1; }
15934 : ;
15935 :
15936 : /*
15937 : * Special expressions that are considered to be functions.
15938 : */
15939 : func_expr_common_subexpr:
15940 : COLLATION FOR '(' a_expr ')'
15941 : {
15942 30 : $$ = (Node *) makeFuncCall(SystemFuncName("pg_collation_for"),
15943 30 : list_make1($4),
15944 : COERCE_SQL_SYNTAX,
15945 30 : @1);
15946 : }
15947 : | CURRENT_DATE
15948 : {
15949 308 : $$ = makeSQLValueFunction(SVFOP_CURRENT_DATE, -1, @1);
15950 : }
15951 : | CURRENT_TIME
15952 : {
15953 24 : $$ = makeSQLValueFunction(SVFOP_CURRENT_TIME, -1, @1);
15954 : }
15955 : | CURRENT_TIME '(' Iconst ')'
15956 : {
15957 24 : $$ = makeSQLValueFunction(SVFOP_CURRENT_TIME_N, $3, @1);
15958 : }
15959 : | CURRENT_TIMESTAMP
15960 : {
15961 284 : $$ = makeSQLValueFunction(SVFOP_CURRENT_TIMESTAMP, -1, @1);
15962 : }
15963 : | CURRENT_TIMESTAMP '(' Iconst ')'
15964 : {
15965 174 : $$ = makeSQLValueFunction(SVFOP_CURRENT_TIMESTAMP_N, $3, @1);
15966 : }
15967 : | LOCALTIME
15968 : {
15969 24 : $$ = makeSQLValueFunction(SVFOP_LOCALTIME, -1, @1);
15970 : }
15971 : | LOCALTIME '(' Iconst ')'
15972 : {
15973 24 : $$ = makeSQLValueFunction(SVFOP_LOCALTIME_N, $3, @1);
15974 : }
15975 : | LOCALTIMESTAMP
15976 : {
15977 36 : $$ = makeSQLValueFunction(SVFOP_LOCALTIMESTAMP, -1, @1);
15978 : }
15979 : | LOCALTIMESTAMP '(' Iconst ')'
15980 : {
15981 24 : $$ = makeSQLValueFunction(SVFOP_LOCALTIMESTAMP_N, $3, @1);
15982 : }
15983 : | CURRENT_ROLE
15984 : {
15985 68 : $$ = makeSQLValueFunction(SVFOP_CURRENT_ROLE, -1, @1);
15986 : }
15987 : | CURRENT_USER
15988 : {
15989 1060 : $$ = makeSQLValueFunction(SVFOP_CURRENT_USER, -1, @1);
15990 : }
15991 : | SESSION_USER
15992 : {
15993 596 : $$ = makeSQLValueFunction(SVFOP_SESSION_USER, -1, @1);
15994 : }
15995 : | SYSTEM_USER
15996 : {
15997 20 : $$ = (Node *) makeFuncCall(SystemFuncName("system_user"),
15998 : NIL,
15999 : COERCE_SQL_SYNTAX,
16000 : @1);
16001 : }
16002 : | USER
16003 : {
16004 24 : $$ = makeSQLValueFunction(SVFOP_USER, -1, @1);
16005 : }
16006 : | CURRENT_CATALOG
16007 : {
16008 60 : $$ = makeSQLValueFunction(SVFOP_CURRENT_CATALOG, -1, @1);
16009 : }
16010 : | CURRENT_SCHEMA
16011 : {
16012 30 : $$ = makeSQLValueFunction(SVFOP_CURRENT_SCHEMA, -1, @1);
16013 : }
16014 : | CAST '(' a_expr AS Typename ')'
16015 62472 : { $$ = makeTypeCast($3, $5, @1); }
16016 : | EXTRACT '(' extract_list ')'
16017 : {
16018 1382 : $$ = (Node *) makeFuncCall(SystemFuncName("extract"),
16019 1382 : $3,
16020 : COERCE_SQL_SYNTAX,
16021 1382 : @1);
16022 : }
16023 : | NORMALIZE '(' a_expr ')'
16024 : {
16025 18 : $$ = (Node *) makeFuncCall(SystemFuncName("normalize"),
16026 18 : list_make1($3),
16027 : COERCE_SQL_SYNTAX,
16028 18 : @1);
16029 : }
16030 : | NORMALIZE '(' a_expr ',' unicode_normal_form ')'
16031 : {
16032 42 : $$ = (Node *) makeFuncCall(SystemFuncName("normalize"),
16033 42 : list_make2($3, makeStringConst($5, @5)),
16034 : COERCE_SQL_SYNTAX,
16035 42 : @1);
16036 : }
16037 : | OVERLAY '(' overlay_list ')'
16038 : {
16039 82 : $$ = (Node *) makeFuncCall(SystemFuncName("overlay"),
16040 82 : $3,
16041 : COERCE_SQL_SYNTAX,
16042 82 : @1);
16043 : }
16044 : | OVERLAY '(' func_arg_list_opt ')'
16045 : {
16046 : /*
16047 : * allow functions named overlay() to be called without
16048 : * special syntax
16049 : */
16050 0 : $$ = (Node *) makeFuncCall(list_make1(makeString("overlay")),
16051 0 : $3,
16052 : COERCE_EXPLICIT_CALL,
16053 0 : @1);
16054 : }
16055 : | POSITION '(' position_list ')'
16056 : {
16057 : /*
16058 : * position(A in B) is converted to position(B, A)
16059 : *
16060 : * We deliberately don't offer a "plain syntax" option
16061 : * for position(), because the reversal of the arguments
16062 : * creates too much risk of confusion.
16063 : */
16064 400 : $$ = (Node *) makeFuncCall(SystemFuncName("position"),
16065 400 : $3,
16066 : COERCE_SQL_SYNTAX,
16067 400 : @1);
16068 : }
16069 : | SUBSTRING '(' substr_list ')'
16070 : {
16071 : /* substring(A from B for C) is converted to
16072 : * substring(A, B, C) - thomas 2000-11-28
16073 : */
16074 710 : $$ = (Node *) makeFuncCall(SystemFuncName("substring"),
16075 710 : $3,
16076 : COERCE_SQL_SYNTAX,
16077 710 : @1);
16078 : }
16079 : | SUBSTRING '(' func_arg_list_opt ')'
16080 : {
16081 : /*
16082 : * allow functions named substring() to be called without
16083 : * special syntax
16084 : */
16085 252 : $$ = (Node *) makeFuncCall(list_make1(makeString("substring")),
16086 252 : $3,
16087 : COERCE_EXPLICIT_CALL,
16088 252 : @1);
16089 : }
16090 : | TREAT '(' a_expr AS Typename ')'
16091 : {
16092 : /* TREAT(expr AS target) converts expr of a particular type to target,
16093 : * which is defined to be a subtype of the original expression.
16094 : * In SQL99, this is intended for use with structured UDTs,
16095 : * but let's make this a generally useful form allowing stronger
16096 : * coercions than are handled by implicit casting.
16097 : *
16098 : * Convert SystemTypeName() to SystemFuncName() even though
16099 : * at the moment they result in the same thing.
16100 : */
16101 0 : $$ = (Node *) makeFuncCall(SystemFuncName(strVal(llast($5->names))),
16102 0 : list_make1($3),
16103 : COERCE_EXPLICIT_CALL,
16104 0 : @1);
16105 : }
16106 : | TRIM '(' BOTH trim_list ')'
16107 : {
16108 : /* various trim expressions are defined in SQL
16109 : * - thomas 1997-07-19
16110 : */
16111 12 : $$ = (Node *) makeFuncCall(SystemFuncName("btrim"),
16112 12 : $4,
16113 : COERCE_SQL_SYNTAX,
16114 12 : @1);
16115 : }
16116 : | TRIM '(' LEADING trim_list ')'
16117 : {
16118 24 : $$ = (Node *) makeFuncCall(SystemFuncName("ltrim"),
16119 24 : $4,
16120 : COERCE_SQL_SYNTAX,
16121 24 : @1);
16122 : }
16123 : | TRIM '(' TRAILING trim_list ')'
16124 : {
16125 582 : $$ = (Node *) makeFuncCall(SystemFuncName("rtrim"),
16126 582 : $4,
16127 : COERCE_SQL_SYNTAX,
16128 582 : @1);
16129 : }
16130 : | TRIM '(' trim_list ')'
16131 : {
16132 98 : $$ = (Node *) makeFuncCall(SystemFuncName("btrim"),
16133 98 : $3,
16134 : COERCE_SQL_SYNTAX,
16135 98 : @1);
16136 : }
16137 : | NULLIF '(' a_expr ',' a_expr ')'
16138 : {
16139 386 : $$ = (Node *) makeSimpleA_Expr(AEXPR_NULLIF, "=", $3, $5, @1);
16140 : }
16141 : | COALESCE '(' expr_list ')'
16142 : {
16143 3240 : CoalesceExpr *c = makeNode(CoalesceExpr);
16144 :
16145 3240 : c->args = $3;
16146 3240 : c->location = @1;
16147 3240 : $$ = (Node *) c;
16148 : }
16149 : | GREATEST '(' expr_list ')'
16150 : {
16151 146 : MinMaxExpr *v = makeNode(MinMaxExpr);
16152 :
16153 146 : v->args = $3;
16154 146 : v->op = IS_GREATEST;
16155 146 : v->location = @1;
16156 146 : $$ = (Node *) v;
16157 : }
16158 : | LEAST '(' expr_list ')'
16159 : {
16160 148 : MinMaxExpr *v = makeNode(MinMaxExpr);
16161 :
16162 148 : v->args = $3;
16163 148 : v->op = IS_LEAST;
16164 148 : v->location = @1;
16165 148 : $$ = (Node *) v;
16166 : }
16167 : | XMLCONCAT '(' expr_list ')'
16168 : {
16169 62 : $$ = makeXmlExpr(IS_XMLCONCAT, NULL, NIL, $3, @1);
16170 : }
16171 : | XMLELEMENT '(' NAME_P ColLabel ')'
16172 : {
16173 6 : $$ = makeXmlExpr(IS_XMLELEMENT, $4, NIL, NIL, @1);
16174 : }
16175 : | XMLELEMENT '(' NAME_P ColLabel ',' xml_attributes ')'
16176 : {
16177 36 : $$ = makeXmlExpr(IS_XMLELEMENT, $4, $6, NIL, @1);
16178 : }
16179 : | XMLELEMENT '(' NAME_P ColLabel ',' expr_list ')'
16180 : {
16181 116 : $$ = makeXmlExpr(IS_XMLELEMENT, $4, NIL, $6, @1);
16182 : }
16183 : | XMLELEMENT '(' NAME_P ColLabel ',' xml_attributes ',' expr_list ')'
16184 : {
16185 20 : $$ = makeXmlExpr(IS_XMLELEMENT, $4, $6, $8, @1);
16186 : }
16187 : | XMLEXISTS '(' c_expr xmlexists_argument ')'
16188 : {
16189 : /* xmlexists(A PASSING [BY REF] B [BY REF]) is
16190 : * converted to xmlexists(A, B)*/
16191 54 : $$ = (Node *) makeFuncCall(SystemFuncName("xmlexists"),
16192 54 : list_make2($3, $4),
16193 : COERCE_SQL_SYNTAX,
16194 54 : @1);
16195 : }
16196 : | XMLFOREST '(' xml_attribute_list ')'
16197 : {
16198 32 : $$ = makeXmlExpr(IS_XMLFOREST, NULL, $3, NIL, @1);
16199 : }
16200 : | XMLPARSE '(' document_or_content a_expr xml_whitespace_option ')'
16201 : {
16202 : XmlExpr *x = (XmlExpr *)
16203 140 : makeXmlExpr(IS_XMLPARSE, NULL, NIL,
16204 140 : list_make2($4, makeBoolAConst($5, -1)),
16205 140 : @1);
16206 :
16207 140 : x->xmloption = $3;
16208 140 : $$ = (Node *) x;
16209 : }
16210 : | XMLPI '(' NAME_P ColLabel ')'
16211 : {
16212 30 : $$ = makeXmlExpr(IS_XMLPI, $4, NULL, NIL, @1);
16213 : }
16214 : | XMLPI '(' NAME_P ColLabel ',' a_expr ')'
16215 : {
16216 50 : $$ = makeXmlExpr(IS_XMLPI, $4, NULL, list_make1($6), @1);
16217 : }
16218 : | XMLROOT '(' a_expr ',' xml_root_version opt_xml_root_standalone ')'
16219 : {
16220 68 : $$ = makeXmlExpr(IS_XMLROOT, NULL, NIL,
16221 68 : list_make3($3, $5, $6), @1);
16222 : }
16223 : | XMLSERIALIZE '(' document_or_content a_expr AS SimpleTypename xml_indent_option ')'
16224 : {
16225 218 : XmlSerialize *n = makeNode(XmlSerialize);
16226 :
16227 218 : n->xmloption = $3;
16228 218 : n->expr = $4;
16229 218 : n->typeName = $6;
16230 218 : n->indent = $7;
16231 218 : n->location = @1;
16232 218 : $$ = (Node *) n;
16233 : }
16234 : | JSON_OBJECT '(' func_arg_list ')'
16235 : {
16236 : /* Support for legacy (non-standard) json_object() */
16237 90 : $$ = (Node *) makeFuncCall(SystemFuncName("json_object"),
16238 90 : $3, COERCE_EXPLICIT_CALL, @1);
16239 : }
16240 : | JSON_OBJECT '(' json_name_and_value_list
16241 : json_object_constructor_null_clause_opt
16242 : json_key_uniqueness_constraint_opt
16243 : json_returning_clause_opt ')'
16244 : {
16245 348 : JsonObjectConstructor *n = makeNode(JsonObjectConstructor);
16246 :
16247 348 : n->exprs = $3;
16248 348 : n->absent_on_null = $4;
16249 348 : n->unique = $5;
16250 348 : n->output = (JsonOutput *) $6;
16251 348 : n->location = @1;
16252 348 : $$ = (Node *) n;
16253 : }
16254 : | JSON_OBJECT '(' json_returning_clause_opt ')'
16255 : {
16256 92 : JsonObjectConstructor *n = makeNode(JsonObjectConstructor);
16257 :
16258 92 : n->exprs = NULL;
16259 92 : n->absent_on_null = false;
16260 92 : n->unique = false;
16261 92 : n->output = (JsonOutput *) $3;
16262 92 : n->location = @1;
16263 92 : $$ = (Node *) n;
16264 : }
16265 : | JSON_ARRAY '('
16266 : json_value_expr_list
16267 : json_array_constructor_null_clause_opt
16268 : json_returning_clause_opt
16269 : ')'
16270 : {
16271 120 : JsonArrayConstructor *n = makeNode(JsonArrayConstructor);
16272 :
16273 120 : n->exprs = $3;
16274 120 : n->absent_on_null = $4;
16275 120 : n->output = (JsonOutput *) $5;
16276 120 : n->location = @1;
16277 120 : $$ = (Node *) n;
16278 : }
16279 : | JSON_ARRAY '('
16280 : select_no_parens
16281 : json_format_clause_opt
16282 : /* json_array_constructor_null_clause_opt */
16283 : json_returning_clause_opt
16284 : ')'
16285 : {
16286 60 : JsonArrayQueryConstructor *n = makeNode(JsonArrayQueryConstructor);
16287 :
16288 60 : n->query = $3;
16289 60 : n->format = (JsonFormat *) $4;
16290 60 : n->absent_on_null = true; /* XXX */
16291 60 : n->output = (JsonOutput *) $5;
16292 60 : n->location = @1;
16293 60 : $$ = (Node *) n;
16294 : }
16295 : | JSON_ARRAY '('
16296 : json_returning_clause_opt
16297 : ')'
16298 : {
16299 86 : JsonArrayConstructor *n = makeNode(JsonArrayConstructor);
16300 :
16301 86 : n->exprs = NIL;
16302 86 : n->absent_on_null = true;
16303 86 : n->output = (JsonOutput *) $3;
16304 86 : n->location = @1;
16305 86 : $$ = (Node *) n;
16306 : }
16307 : | JSON '(' json_value_expr json_key_uniqueness_constraint_opt ')'
16308 : {
16309 164 : JsonParseExpr *n = makeNode(JsonParseExpr);
16310 :
16311 164 : n->expr = (JsonValueExpr *) $3;
16312 164 : n->unique_keys = $4;
16313 164 : n->output = NULL;
16314 164 : n->location = @1;
16315 164 : $$ = (Node *) n;
16316 : }
16317 : | JSON_SCALAR '(' a_expr ')'
16318 : {
16319 112 : JsonScalarExpr *n = makeNode(JsonScalarExpr);
16320 :
16321 112 : n->expr = (Expr *) $3;
16322 112 : n->output = NULL;
16323 112 : n->location = @1;
16324 112 : $$ = (Node *) n;
16325 : }
16326 : | JSON_SERIALIZE '(' json_value_expr json_returning_clause_opt ')'
16327 : {
16328 108 : JsonSerializeExpr *n = makeNode(JsonSerializeExpr);
16329 :
16330 108 : n->expr = (JsonValueExpr *) $3;
16331 108 : n->output = (JsonOutput *) $4;
16332 108 : n->location = @1;
16333 108 : $$ = (Node *) n;
16334 : }
16335 : | MERGE_ACTION '(' ')'
16336 : {
16337 216 : MergeSupportFunc *m = makeNode(MergeSupportFunc);
16338 :
16339 216 : m->msftype = TEXTOID;
16340 216 : m->location = @1;
16341 216 : $$ = (Node *) m;
16342 : }
16343 : | JSON_QUERY '('
16344 : json_value_expr ',' a_expr json_passing_clause_opt
16345 : json_returning_clause_opt
16346 : json_wrapper_behavior
16347 : json_quotes_clause_opt
16348 : json_behavior_clause_opt
16349 : ')'
16350 : {
16351 990 : JsonFuncExpr *n = makeNode(JsonFuncExpr);
16352 :
16353 990 : n->op = JSON_QUERY_OP;
16354 990 : n->context_item = (JsonValueExpr *) $3;
16355 990 : n->pathspec = $5;
16356 990 : n->passing = $6;
16357 990 : n->output = (JsonOutput *) $7;
16358 990 : n->wrapper = $8;
16359 990 : n->quotes = $9;
16360 990 : n->on_empty = (JsonBehavior *) linitial($10);
16361 990 : n->on_error = (JsonBehavior *) lsecond($10);
16362 990 : n->location = @1;
16363 990 : $$ = (Node *) n;
16364 : }
16365 : | JSON_EXISTS '('
16366 : json_value_expr ',' a_expr json_passing_clause_opt
16367 : json_on_error_clause_opt
16368 : ')'
16369 : {
16370 168 : JsonFuncExpr *n = makeNode(JsonFuncExpr);
16371 :
16372 168 : n->op = JSON_EXISTS_OP;
16373 168 : n->context_item = (JsonValueExpr *) $3;
16374 168 : n->pathspec = $5;
16375 168 : n->passing = $6;
16376 168 : n->output = NULL;
16377 168 : n->on_error = (JsonBehavior *) $7;
16378 168 : n->location = @1;
16379 168 : $$ = (Node *) n;
16380 : }
16381 : | JSON_VALUE '('
16382 : json_value_expr ',' a_expr json_passing_clause_opt
16383 : json_returning_clause_opt
16384 : json_behavior_clause_opt
16385 : ')'
16386 : {
16387 630 : JsonFuncExpr *n = makeNode(JsonFuncExpr);
16388 :
16389 630 : n->op = JSON_VALUE_OP;
16390 630 : n->context_item = (JsonValueExpr *) $3;
16391 630 : n->pathspec = $5;
16392 630 : n->passing = $6;
16393 630 : n->output = (JsonOutput *) $7;
16394 630 : n->on_empty = (JsonBehavior *) linitial($8);
16395 630 : n->on_error = (JsonBehavior *) lsecond($8);
16396 630 : n->location = @1;
16397 630 : $$ = (Node *) n;
16398 : }
16399 : ;
16400 :
16401 :
16402 : /*
16403 : * SQL/XML support
16404 : */
16405 : xml_root_version: VERSION_P a_expr
16406 24 : { $$ = $2; }
16407 : | VERSION_P NO VALUE_P
16408 44 : { $$ = makeNullAConst(-1); }
16409 : ;
16410 :
16411 : opt_xml_root_standalone: ',' STANDALONE_P YES_P
16412 26 : { $$ = makeIntConst(XML_STANDALONE_YES, -1); }
16413 : | ',' STANDALONE_P NO
16414 12 : { $$ = makeIntConst(XML_STANDALONE_NO, -1); }
16415 : | ',' STANDALONE_P NO VALUE_P
16416 12 : { $$ = makeIntConst(XML_STANDALONE_NO_VALUE, -1); }
16417 : | /*EMPTY*/
16418 18 : { $$ = makeIntConst(XML_STANDALONE_OMITTED, -1); }
16419 : ;
16420 :
16421 56 : xml_attributes: XMLATTRIBUTES '(' xml_attribute_list ')' { $$ = $3; }
16422 : ;
16423 :
16424 88 : xml_attribute_list: xml_attribute_el { $$ = list_make1($1); }
16425 144 : | xml_attribute_list ',' xml_attribute_el { $$ = lappend($1, $3); }
16426 : ;
16427 :
16428 : xml_attribute_el: a_expr AS ColLabel
16429 : {
16430 106 : $$ = makeNode(ResTarget);
16431 106 : $$->name = $3;
16432 106 : $$->indirection = NIL;
16433 106 : $$->val = (Node *) $1;
16434 106 : $$->location = @1;
16435 : }
16436 : | a_expr
16437 : {
16438 126 : $$ = makeNode(ResTarget);
16439 126 : $$->name = NULL;
16440 126 : $$->indirection = NIL;
16441 126 : $$->val = (Node *) $1;
16442 126 : $$->location = @1;
16443 : }
16444 : ;
16445 :
16446 186 : document_or_content: DOCUMENT_P { $$ = XMLOPTION_DOCUMENT; }
16447 188 : | CONTENT_P { $$ = XMLOPTION_CONTENT; }
16448 : ;
16449 :
16450 140 : xml_indent_option: INDENT { $$ = true; }
16451 36 : | NO INDENT { $$ = false; }
16452 42 : | /*EMPTY*/ { $$ = false; }
16453 : ;
16454 :
16455 0 : xml_whitespace_option: PRESERVE WHITESPACE_P { $$ = true; }
16456 2 : | STRIP_P WHITESPACE_P { $$ = false; }
16457 138 : | /*EMPTY*/ { $$ = false; }
16458 : ;
16459 :
16460 : /* We allow several variants for SQL and other compatibility. */
16461 : xmlexists_argument:
16462 : PASSING c_expr
16463 : {
16464 238 : $$ = $2;
16465 : }
16466 : | PASSING c_expr xml_passing_mech
16467 : {
16468 0 : $$ = $2;
16469 : }
16470 : | PASSING xml_passing_mech c_expr
16471 : {
16472 42 : $$ = $3;
16473 : }
16474 : | PASSING xml_passing_mech c_expr xml_passing_mech
16475 : {
16476 6 : $$ = $3;
16477 : }
16478 : ;
16479 :
16480 : xml_passing_mech:
16481 : BY REF_P
16482 : | BY VALUE_P
16483 : ;
16484 :
16485 : /*****************************************************************************
16486 : *
16487 : * WAIT FOR LSN
16488 : *
16489 : *****************************************************************************/
16490 :
16491 : WaitStmt:
16492 : WAIT FOR LSN_P Sconst opt_wait_with_clause
16493 : {
16494 54 : WaitStmt *n = makeNode(WaitStmt);
16495 54 : n->lsn_literal = $4;
16496 54 : n->options = $5;
16497 54 : $$ = (Node *) n;
16498 : }
16499 : ;
16500 :
16501 : opt_wait_with_clause:
16502 28 : WITH '(' utility_option_list ')' { $$ = $3; }
16503 26 : | /*EMPTY*/ { $$ = NIL; }
16504 : ;
16505 :
16506 : /*
16507 : * Aggregate decoration clauses
16508 : */
16509 : within_group_clause:
16510 348 : WITHIN GROUP_P '(' sort_clause ')' { $$ = $4; }
16511 317644 : | /*EMPTY*/ { $$ = NIL; }
16512 : ;
16513 :
16514 : filter_clause:
16515 860 : FILTER '(' WHERE a_expr ')' { $$ = $4; }
16516 317492 : | /*EMPTY*/ { $$ = NULL; }
16517 : ;
16518 :
16519 :
16520 : /*
16521 : * Window Definitions
16522 : */
16523 : null_treatment:
16524 198 : IGNORE_P NULLS_P { $$ = PARSER_IGNORE_NULLS; }
16525 96 : | RESPECT_P NULLS_P { $$ = PARSER_RESPECT_NULLS; }
16526 317698 : | /*EMPTY*/ { $$ = NO_NULLTREATMENT; }
16527 : ;
16528 :
16529 : window_clause:
16530 606 : WINDOW window_definition_list { $$ = $2; }
16531 477334 : | /*EMPTY*/ { $$ = NIL; }
16532 : ;
16533 :
16534 : window_definition_list:
16535 606 : window_definition { $$ = list_make1($1); }
16536 : | window_definition_list ',' window_definition
16537 30 : { $$ = lappend($1, $3); }
16538 : ;
16539 :
16540 : window_definition:
16541 : ColId AS window_specification
16542 : {
16543 636 : WindowDef *n = $3;
16544 :
16545 636 : n->name = $1;
16546 636 : $$ = n;
16547 : }
16548 : ;
16549 :
16550 : over_clause: OVER window_specification
16551 2754 : { $$ = $2; }
16552 : | OVER ColId
16553 : {
16554 1182 : WindowDef *n = makeNode(WindowDef);
16555 :
16556 1182 : n->name = $2;
16557 1182 : n->refname = NULL;
16558 1182 : n->partitionClause = NIL;
16559 1182 : n->orderClause = NIL;
16560 1182 : n->frameOptions = FRAMEOPTION_DEFAULTS;
16561 1182 : n->startOffset = NULL;
16562 1182 : n->endOffset = NULL;
16563 1182 : n->location = @2;
16564 1182 : $$ = n;
16565 : }
16566 : | /*EMPTY*/
16567 314410 : { $$ = NULL; }
16568 : ;
16569 :
16570 : window_specification: '(' opt_existing_window_name opt_partition_clause
16571 : opt_sort_clause opt_frame_clause ')'
16572 : {
16573 3390 : WindowDef *n = makeNode(WindowDef);
16574 :
16575 3390 : n->name = NULL;
16576 3390 : n->refname = $2;
16577 3390 : n->partitionClause = $3;
16578 3390 : n->orderClause = $4;
16579 : /* copy relevant fields of opt_frame_clause */
16580 3390 : n->frameOptions = $5->frameOptions;
16581 3390 : n->startOffset = $5->startOffset;
16582 3390 : n->endOffset = $5->endOffset;
16583 3390 : n->location = @1;
16584 3390 : $$ = n;
16585 : }
16586 : ;
16587 :
16588 : /*
16589 : * If we see PARTITION, RANGE, ROWS or GROUPS as the first token after the '('
16590 : * of a window_specification, we want the assumption to be that there is
16591 : * no existing_window_name; but those keywords are unreserved and so could
16592 : * be ColIds. We fix this by making them have the same precedence as IDENT
16593 : * and giving the empty production here a slightly higher precedence, so
16594 : * that the shift/reduce conflict is resolved in favor of reducing the rule.
16595 : * These keywords are thus precluded from being an existing_window_name but
16596 : * are not reserved for any other purpose.
16597 : */
16598 54 : opt_existing_window_name: ColId { $$ = $1; }
16599 3342 : | /*EMPTY*/ %prec Op { $$ = NULL; }
16600 : ;
16601 :
16602 932 : opt_partition_clause: PARTITION BY expr_list { $$ = $3; }
16603 2458 : | /*EMPTY*/ { $$ = NIL; }
16604 : ;
16605 :
16606 : /*
16607 : * For frame clauses, we return a WindowDef, but only some fields are used:
16608 : * frameOptions, startOffset, and endOffset.
16609 : */
16610 : opt_frame_clause:
16611 : RANGE frame_extent opt_window_exclusion_clause
16612 : {
16613 796 : WindowDef *n = $2;
16614 :
16615 796 : n->frameOptions |= FRAMEOPTION_NONDEFAULT | FRAMEOPTION_RANGE;
16616 796 : n->frameOptions |= $3;
16617 796 : $$ = n;
16618 : }
16619 : | ROWS frame_extent opt_window_exclusion_clause
16620 : {
16621 690 : WindowDef *n = $2;
16622 :
16623 690 : n->frameOptions |= FRAMEOPTION_NONDEFAULT | FRAMEOPTION_ROWS;
16624 690 : n->frameOptions |= $3;
16625 690 : $$ = n;
16626 : }
16627 : | GROUPS frame_extent opt_window_exclusion_clause
16628 : {
16629 204 : WindowDef *n = $2;
16630 :
16631 204 : n->frameOptions |= FRAMEOPTION_NONDEFAULT | FRAMEOPTION_GROUPS;
16632 204 : n->frameOptions |= $3;
16633 204 : $$ = n;
16634 : }
16635 : | /*EMPTY*/
16636 : {
16637 1700 : WindowDef *n = makeNode(WindowDef);
16638 :
16639 1700 : n->frameOptions = FRAMEOPTION_DEFAULTS;
16640 1700 : n->startOffset = NULL;
16641 1700 : n->endOffset = NULL;
16642 1700 : $$ = n;
16643 : }
16644 : ;
16645 :
16646 : frame_extent: frame_bound
16647 : {
16648 12 : WindowDef *n = $1;
16649 :
16650 : /* reject invalid cases */
16651 12 : if (n->frameOptions & FRAMEOPTION_START_UNBOUNDED_FOLLOWING)
16652 0 : ereport(ERROR,
16653 : (errcode(ERRCODE_WINDOWING_ERROR),
16654 : errmsg("frame start cannot be UNBOUNDED FOLLOWING"),
16655 : parser_errposition(@1)));
16656 12 : if (n->frameOptions & FRAMEOPTION_START_OFFSET_FOLLOWING)
16657 0 : ereport(ERROR,
16658 : (errcode(ERRCODE_WINDOWING_ERROR),
16659 : errmsg("frame starting from following row cannot end with current row"),
16660 : parser_errposition(@1)));
16661 12 : n->frameOptions |= FRAMEOPTION_END_CURRENT_ROW;
16662 12 : $$ = n;
16663 : }
16664 : | BETWEEN frame_bound AND frame_bound
16665 : {
16666 1678 : WindowDef *n1 = $2;
16667 1678 : WindowDef *n2 = $4;
16668 :
16669 : /* form merged options */
16670 1678 : int frameOptions = n1->frameOptions;
16671 : /* shift converts START_ options to END_ options */
16672 1678 : frameOptions |= n2->frameOptions << 1;
16673 1678 : frameOptions |= FRAMEOPTION_BETWEEN;
16674 : /* reject invalid cases */
16675 1678 : if (frameOptions & FRAMEOPTION_START_UNBOUNDED_FOLLOWING)
16676 0 : ereport(ERROR,
16677 : (errcode(ERRCODE_WINDOWING_ERROR),
16678 : errmsg("frame start cannot be UNBOUNDED FOLLOWING"),
16679 : parser_errposition(@2)));
16680 1678 : if (frameOptions & FRAMEOPTION_END_UNBOUNDED_PRECEDING)
16681 0 : ereport(ERROR,
16682 : (errcode(ERRCODE_WINDOWING_ERROR),
16683 : errmsg("frame end cannot be UNBOUNDED PRECEDING"),
16684 : parser_errposition(@4)));
16685 1678 : if ((frameOptions & FRAMEOPTION_START_CURRENT_ROW) &&
16686 460 : (frameOptions & FRAMEOPTION_END_OFFSET_PRECEDING))
16687 0 : ereport(ERROR,
16688 : (errcode(ERRCODE_WINDOWING_ERROR),
16689 : errmsg("frame starting from current row cannot have preceding rows"),
16690 : parser_errposition(@4)));
16691 1678 : if ((frameOptions & FRAMEOPTION_START_OFFSET_FOLLOWING) &&
16692 168 : (frameOptions & (FRAMEOPTION_END_OFFSET_PRECEDING |
16693 : FRAMEOPTION_END_CURRENT_ROW)))
16694 0 : ereport(ERROR,
16695 : (errcode(ERRCODE_WINDOWING_ERROR),
16696 : errmsg("frame starting from following row cannot have preceding rows"),
16697 : parser_errposition(@4)));
16698 1678 : n1->frameOptions = frameOptions;
16699 1678 : n1->endOffset = n2->startOffset;
16700 1678 : $$ = n1;
16701 : }
16702 : ;
16703 :
16704 : /*
16705 : * This is used for both frame start and frame end, with output set up on
16706 : * the assumption it's frame start; the frame_extent productions must reject
16707 : * invalid cases.
16708 : */
16709 : frame_bound:
16710 : UNBOUNDED PRECEDING
16711 : {
16712 216 : WindowDef *n = makeNode(WindowDef);
16713 :
16714 216 : n->frameOptions = FRAMEOPTION_START_UNBOUNDED_PRECEDING;
16715 216 : n->startOffset = NULL;
16716 216 : n->endOffset = NULL;
16717 216 : $$ = n;
16718 : }
16719 : | UNBOUNDED FOLLOWING
16720 : {
16721 394 : WindowDef *n = makeNode(WindowDef);
16722 :
16723 394 : n->frameOptions = FRAMEOPTION_START_UNBOUNDED_FOLLOWING;
16724 394 : n->startOffset = NULL;
16725 394 : n->endOffset = NULL;
16726 394 : $$ = n;
16727 : }
16728 : | CURRENT_P ROW
16729 : {
16730 604 : WindowDef *n = makeNode(WindowDef);
16731 :
16732 604 : n->frameOptions = FRAMEOPTION_START_CURRENT_ROW;
16733 604 : n->startOffset = NULL;
16734 604 : n->endOffset = NULL;
16735 604 : $$ = n;
16736 : }
16737 : | a_expr PRECEDING
16738 : {
16739 954 : WindowDef *n = makeNode(WindowDef);
16740 :
16741 954 : n->frameOptions = FRAMEOPTION_START_OFFSET_PRECEDING;
16742 954 : n->startOffset = $1;
16743 954 : n->endOffset = NULL;
16744 954 : $$ = n;
16745 : }
16746 : | a_expr FOLLOWING
16747 : {
16748 1200 : WindowDef *n = makeNode(WindowDef);
16749 :
16750 1200 : n->frameOptions = FRAMEOPTION_START_OFFSET_FOLLOWING;
16751 1200 : n->startOffset = $1;
16752 1200 : n->endOffset = NULL;
16753 1200 : $$ = n;
16754 : }
16755 : ;
16756 :
16757 : opt_window_exclusion_clause:
16758 96 : EXCLUDE CURRENT_P ROW { $$ = FRAMEOPTION_EXCLUDE_CURRENT_ROW; }
16759 96 : | EXCLUDE GROUP_P { $$ = FRAMEOPTION_EXCLUDE_GROUP; }
16760 150 : | EXCLUDE TIES { $$ = FRAMEOPTION_EXCLUDE_TIES; }
16761 18 : | EXCLUDE NO OTHERS { $$ = 0; }
16762 1330 : | /*EMPTY*/ { $$ = 0; }
16763 : ;
16764 :
16765 :
16766 : /*
16767 : * Supporting nonterminals for expressions.
16768 : */
16769 :
16770 : /* Explicit row production.
16771 : *
16772 : * SQL99 allows an optional ROW keyword, so we can now do single-element rows
16773 : * without conflicting with the parenthesized a_expr production. Without the
16774 : * ROW keyword, there must be more than one a_expr inside the parens.
16775 : */
16776 0 : row: ROW '(' expr_list ')' { $$ = $3; }
16777 0 : | ROW '(' ')' { $$ = NIL; }
16778 1932 : | '(' expr_list ',' a_expr ')' { $$ = lappend($2, $4); }
16779 : ;
16780 :
16781 3820 : explicit_row: ROW '(' expr_list ')' { $$ = $3; }
16782 36 : | ROW '(' ')' { $$ = NIL; }
16783 : ;
16784 :
16785 2706 : implicit_row: '(' expr_list ',' a_expr ')' { $$ = lappend($2, $4); }
16786 : ;
16787 :
16788 16694 : sub_type: ANY { $$ = ANY_SUBLINK; }
16789 0 : | SOME { $$ = ANY_SUBLINK; }
16790 324 : | ALL { $$ = ALL_SUBLINK; }
16791 : ;
16792 :
16793 11410 : all_Op: Op { $$ = $1; }
16794 29264 : | MathOp { $$ = $1; }
16795 : ;
16796 :
16797 40 : MathOp: '+' { $$ = "+"; }
16798 66 : | '-' { $$ = "-"; }
16799 150 : | '*' { $$ = "*"; }
16800 0 : | '/' { $$ = "/"; }
16801 8 : | '%' { $$ = "%"; }
16802 0 : | '^' { $$ = "^"; }
16803 978 : | '<' { $$ = "<"; }
16804 880 : | '>' { $$ = ">"; }
16805 24672 : | '=' { $$ = "="; }
16806 844 : | LESS_EQUALS { $$ = "<="; }
16807 836 : | GREATER_EQUALS { $$ = ">="; }
16808 790 : | NOT_EQUALS { $$ = "<>"; }
16809 : ;
16810 :
16811 : qual_Op: Op
16812 44062 : { $$ = list_make1(makeString($1)); }
16813 : | OPERATOR '(' any_operator ')'
16814 15846 : { $$ = $3; }
16815 : ;
16816 :
16817 : qual_all_Op:
16818 : all_Op
16819 1416 : { $$ = list_make1(makeString($1)); }
16820 : | OPERATOR '(' any_operator ')'
16821 34 : { $$ = $3; }
16822 : ;
16823 :
16824 : subquery_Op:
16825 : all_Op
16826 16708 : { $$ = list_make1(makeString($1)); }
16827 : | OPERATOR '(' any_operator ')'
16828 278 : { $$ = $3; }
16829 : | LIKE
16830 24 : { $$ = list_make1(makeString("~~")); }
16831 : | NOT_LA LIKE
16832 12 : { $$ = list_make1(makeString("!~~")); }
16833 : | ILIKE
16834 12 : { $$ = list_make1(makeString("~~*")); }
16835 : | NOT_LA ILIKE
16836 0 : { $$ = list_make1(makeString("!~~*")); }
16837 : /* cannot put SIMILAR TO here, because SIMILAR TO is a hack.
16838 : * the regular expression is preprocessed by a function (similar_to_escape),
16839 : * and the ~ operator for posix regular expressions is used.
16840 : * x SIMILAR TO y -> x ~ similar_to_escape(y)
16841 : * this transformation is made on the fly by the parser upwards.
16842 : * however the SubLink structure which handles any/some/all stuff
16843 : * is not ready for such a thing.
16844 : */
16845 : ;
16846 :
16847 : expr_list: a_expr
16848 : {
16849 162462 : $$ = list_make1($1);
16850 : }
16851 : | expr_list ',' a_expr
16852 : {
16853 146742 : $$ = lappend($1, $3);
16854 : }
16855 : ;
16856 :
16857 : /* function arguments can have names */
16858 : func_arg_list: func_arg_expr
16859 : {
16860 320666 : $$ = list_make1($1);
16861 : }
16862 : | func_arg_list ',' func_arg_expr
16863 : {
16864 282628 : $$ = lappend($1, $3);
16865 : }
16866 : ;
16867 :
16868 : func_arg_expr: a_expr
16869 : {
16870 556894 : $$ = $1;
16871 : }
16872 : | param_name COLON_EQUALS a_expr
16873 : {
16874 45504 : NamedArgExpr *na = makeNode(NamedArgExpr);
16875 :
16876 45504 : na->name = $1;
16877 45504 : na->arg = (Expr *) $3;
16878 45504 : na->argnumber = -1; /* until determined */
16879 45504 : na->location = @1;
16880 45504 : $$ = (Node *) na;
16881 : }
16882 : | param_name EQUALS_GREATER a_expr
16883 : {
16884 1696 : NamedArgExpr *na = makeNode(NamedArgExpr);
16885 :
16886 1696 : na->name = $1;
16887 1696 : na->arg = (Expr *) $3;
16888 1696 : na->argnumber = -1; /* until determined */
16889 1696 : na->location = @1;
16890 1696 : $$ = (Node *) na;
16891 : }
16892 : ;
16893 :
16894 252 : func_arg_list_opt: func_arg_list { $$ = $1; }
16895 0 : | /*EMPTY*/ { $$ = NIL; }
16896 : ;
16897 :
16898 2296 : type_list: Typename { $$ = list_make1($1); }
16899 944 : | type_list ',' Typename { $$ = lappend($1, $3); }
16900 : ;
16901 :
16902 : array_expr: '[' expr_list ']'
16903 : {
16904 7738 : $$ = makeAArrayExpr($2, @1, @3);
16905 : }
16906 : | '[' array_expr_list ']'
16907 : {
16908 412 : $$ = makeAArrayExpr($2, @1, @3);
16909 : }
16910 : | '[' ']'
16911 : {
16912 98 : $$ = makeAArrayExpr(NIL, @1, @2);
16913 : }
16914 : ;
16915 :
16916 412 : array_expr_list: array_expr { $$ = list_make1($1); }
16917 342 : | array_expr_list ',' array_expr { $$ = lappend($1, $3); }
16918 : ;
16919 :
16920 :
16921 : extract_list:
16922 : extract_arg FROM a_expr
16923 : {
16924 1382 : $$ = list_make2(makeStringConst($1, @1), $3);
16925 : }
16926 : ;
16927 :
16928 : /* Allow delimited string Sconst in extract_arg as an SQL extension.
16929 : * - thomas 2001-04-12
16930 : */
16931 : extract_arg:
16932 1124 : IDENT { $$ = $1; }
16933 72 : | YEAR_P { $$ = "year"; }
16934 42 : | MONTH_P { $$ = "month"; }
16935 54 : | DAY_P { $$ = "day"; }
16936 30 : | HOUR_P { $$ = "hour"; }
16937 30 : | MINUTE_P { $$ = "minute"; }
16938 30 : | SECOND_P { $$ = "second"; }
16939 0 : | Sconst { $$ = $1; }
16940 : ;
16941 :
16942 : unicode_normal_form:
16943 24 : NFC { $$ = "NFC"; }
16944 18 : | NFD { $$ = "NFD"; }
16945 18 : | NFKC { $$ = "NFKC"; }
16946 18 : | NFKD { $$ = "NFKD"; }
16947 : ;
16948 :
16949 : /* OVERLAY() arguments */
16950 : overlay_list:
16951 : a_expr PLACING a_expr FROM a_expr FOR a_expr
16952 : {
16953 : /* overlay(A PLACING B FROM C FOR D) is converted to overlay(A, B, C, D) */
16954 34 : $$ = list_make4($1, $3, $5, $7);
16955 : }
16956 : | a_expr PLACING a_expr FROM a_expr
16957 : {
16958 : /* overlay(A PLACING B FROM C) is converted to overlay(A, B, C) */
16959 48 : $$ = list_make3($1, $3, $5);
16960 : }
16961 : ;
16962 :
16963 : /* position_list uses b_expr not a_expr to avoid conflict with general IN */
16964 : position_list:
16965 400 : b_expr IN_P b_expr { $$ = list_make2($3, $1); }
16966 : ;
16967 :
16968 : /*
16969 : * SUBSTRING() arguments
16970 : *
16971 : * Note that SQL:1999 has both
16972 : * text FROM int FOR int
16973 : * and
16974 : * text FROM pattern FOR escape
16975 : *
16976 : * In the parser we map them both to a call to the substring() function and
16977 : * rely on type resolution to pick the right one.
16978 : *
16979 : * In SQL:2003, the second variant was changed to
16980 : * text SIMILAR pattern ESCAPE escape
16981 : * We could in theory map that to a different function internally, but
16982 : * since we still support the SQL:1999 version, we don't. However,
16983 : * ruleutils.c will reverse-list the call in the newer style.
16984 : */
16985 : substr_list:
16986 : a_expr FROM a_expr FOR a_expr
16987 : {
16988 122 : $$ = list_make3($1, $3, $5);
16989 : }
16990 : | a_expr FOR a_expr FROM a_expr
16991 : {
16992 : /* not legal per SQL, but might as well allow it */
16993 0 : $$ = list_make3($1, $5, $3);
16994 : }
16995 : | a_expr FROM a_expr
16996 : {
16997 : /*
16998 : * Because we aren't restricting data types here, this
16999 : * syntax can end up resolving to textregexsubstr().
17000 : * We've historically allowed that to happen, so continue
17001 : * to accept it. However, ruleutils.c will reverse-list
17002 : * such a call in regular function call syntax.
17003 : */
17004 370 : $$ = list_make2($1, $3);
17005 : }
17006 : | a_expr FOR a_expr
17007 : {
17008 : /* not legal per SQL */
17009 :
17010 : /*
17011 : * Since there are no cases where this syntax allows
17012 : * a textual FOR value, we forcibly cast the argument
17013 : * to int4. The possible matches in pg_proc are
17014 : * substring(text,int4) and substring(text,text),
17015 : * and we don't want the parser to choose the latter,
17016 : * which it is likely to do if the second argument
17017 : * is unknown or doesn't have an implicit cast to int4.
17018 : */
17019 36 : $$ = list_make3($1, makeIntConst(1, -1),
17020 : makeTypeCast($3,
17021 : SystemTypeName("int4"), -1));
17022 : }
17023 : | a_expr SIMILAR a_expr ESCAPE a_expr
17024 : {
17025 182 : $$ = list_make3($1, $3, $5);
17026 : }
17027 : ;
17028 :
17029 606 : trim_list: a_expr FROM expr_list { $$ = lappend($3, $1); }
17030 24 : | FROM expr_list { $$ = $2; }
17031 86 : | expr_list { $$ = $1; }
17032 : ;
17033 :
17034 : /*
17035 : * Define SQL-style CASE clause.
17036 : * - Full specification
17037 : * CASE WHEN a = b THEN c ... ELSE d END
17038 : * - Implicit argument
17039 : * CASE a WHEN b THEN c ... ELSE d END
17040 : */
17041 : case_expr: CASE case_arg when_clause_list case_default END_P
17042 : {
17043 39138 : CaseExpr *c = makeNode(CaseExpr);
17044 :
17045 39138 : c->casetype = InvalidOid; /* not analyzed yet */
17046 39138 : c->arg = (Expr *) $2;
17047 39138 : c->args = $3;
17048 39138 : c->defresult = (Expr *) $4;
17049 39138 : c->location = @1;
17050 39138 : $$ = (Node *) c;
17051 : }
17052 : ;
17053 :
17054 : when_clause_list:
17055 : /* There must be at least one */
17056 39138 : when_clause { $$ = list_make1($1); }
17057 29034 : | when_clause_list when_clause { $$ = lappend($1, $2); }
17058 : ;
17059 :
17060 : when_clause:
17061 : WHEN a_expr THEN a_expr
17062 : {
17063 68172 : CaseWhen *w = makeNode(CaseWhen);
17064 :
17065 68172 : w->expr = (Expr *) $2;
17066 68172 : w->result = (Expr *) $4;
17067 68172 : w->location = @1;
17068 68172 : $$ = (Node *) w;
17069 : }
17070 : ;
17071 :
17072 : case_default:
17073 29386 : ELSE a_expr { $$ = $2; }
17074 9752 : | /*EMPTY*/ { $$ = NULL; }
17075 : ;
17076 :
17077 6758 : case_arg: a_expr { $$ = $1; }
17078 32380 : | /*EMPTY*/ { $$ = NULL; }
17079 : ;
17080 :
17081 : columnref: ColId
17082 : {
17083 748636 : $$ = makeColumnRef($1, NIL, @1, yyscanner);
17084 : }
17085 : | ColId indirection
17086 : {
17087 1062244 : $$ = makeColumnRef($1, $2, @1, yyscanner);
17088 : }
17089 : ;
17090 :
17091 : indirection_el:
17092 : '.' attr_name
17093 : {
17094 1432884 : $$ = (Node *) makeString($2);
17095 : }
17096 : | '.' '*'
17097 : {
17098 7052 : $$ = (Node *) makeNode(A_Star);
17099 : }
17100 : | '[' a_expr ']'
17101 : {
17102 12908 : A_Indices *ai = makeNode(A_Indices);
17103 :
17104 12908 : ai->is_slice = false;
17105 12908 : ai->lidx = NULL;
17106 12908 : ai->uidx = $2;
17107 12908 : $$ = (Node *) ai;
17108 : }
17109 : | '[' opt_slice_bound ':' opt_slice_bound ']'
17110 : {
17111 588 : A_Indices *ai = makeNode(A_Indices);
17112 :
17113 588 : ai->is_slice = true;
17114 588 : ai->lidx = $2;
17115 588 : ai->uidx = $4;
17116 588 : $$ = (Node *) ai;
17117 : }
17118 : ;
17119 :
17120 : opt_slice_bound:
17121 996 : a_expr { $$ = $1; }
17122 180 : | /*EMPTY*/ { $$ = NULL; }
17123 : ;
17124 :
17125 : indirection:
17126 1432906 : indirection_el { $$ = list_make1($1); }
17127 3084 : | indirection indirection_el { $$ = lappend($1, $2); }
17128 : ;
17129 :
17130 : opt_indirection:
17131 196610 : /*EMPTY*/ { $$ = NIL; }
17132 17442 : | opt_indirection indirection_el { $$ = lappend($1, $2); }
17133 : ;
17134 :
17135 : opt_asymmetric: ASYMMETRIC
17136 : | /*EMPTY*/
17137 : ;
17138 :
17139 : /* SQL/JSON support */
17140 : json_passing_clause_opt:
17141 336 : PASSING json_arguments { $$ = $2; }
17142 2000 : | /*EMPTY*/ { $$ = NIL; }
17143 : ;
17144 :
17145 : json_arguments:
17146 336 : json_argument { $$ = list_make1($1); }
17147 126 : | json_arguments ',' json_argument { $$ = lappend($1, $3); }
17148 : ;
17149 :
17150 : json_argument:
17151 : json_value_expr AS ColLabel
17152 : {
17153 462 : JsonArgument *n = makeNode(JsonArgument);
17154 :
17155 462 : n->val = (JsonValueExpr *) $1;
17156 462 : n->name = $3;
17157 462 : $$ = (Node *) n;
17158 : }
17159 : ;
17160 :
17161 : /* ARRAY is a noise word */
17162 : json_wrapper_behavior:
17163 42 : WITHOUT WRAPPER { $$ = JSW_NONE; }
17164 0 : | WITHOUT ARRAY WRAPPER { $$ = JSW_NONE; }
17165 84 : | WITH WRAPPER { $$ = JSW_UNCONDITIONAL; }
17166 12 : | WITH ARRAY WRAPPER { $$ = JSW_UNCONDITIONAL; }
17167 0 : | WITH CONDITIONAL ARRAY WRAPPER { $$ = JSW_CONDITIONAL; }
17168 12 : | WITH UNCONDITIONAL ARRAY WRAPPER { $$ = JSW_UNCONDITIONAL; }
17169 36 : | WITH CONDITIONAL WRAPPER { $$ = JSW_CONDITIONAL; }
17170 6 : | WITH UNCONDITIONAL WRAPPER { $$ = JSW_UNCONDITIONAL; }
17171 1640 : | /* empty */ { $$ = JSW_UNSPEC; }
17172 : ;
17173 :
17174 : json_behavior:
17175 : DEFAULT a_expr
17176 432 : { $$ = (Node *) makeJsonBehavior(JSON_BEHAVIOR_DEFAULT, $2, @1); }
17177 : | json_behavior_type
17178 702 : { $$ = (Node *) makeJsonBehavior($1, NULL, @1); }
17179 : ;
17180 :
17181 : json_behavior_type:
17182 492 : ERROR_P { $$ = JSON_BEHAVIOR_ERROR; }
17183 30 : | NULL_P { $$ = JSON_BEHAVIOR_NULL; }
17184 30 : | TRUE_P { $$ = JSON_BEHAVIOR_TRUE; }
17185 12 : | FALSE_P { $$ = JSON_BEHAVIOR_FALSE; }
17186 12 : | UNKNOWN { $$ = JSON_BEHAVIOR_UNKNOWN; }
17187 30 : | EMPTY_P ARRAY { $$ = JSON_BEHAVIOR_EMPTY_ARRAY; }
17188 72 : | EMPTY_P OBJECT_P { $$ = JSON_BEHAVIOR_EMPTY_OBJECT; }
17189 : /* non-standard, for Oracle compatibility only */
17190 24 : | EMPTY_P { $$ = JSON_BEHAVIOR_EMPTY_ARRAY; }
17191 : ;
17192 :
17193 : json_behavior_clause_opt:
17194 : json_behavior ON EMPTY_P
17195 222 : { $$ = list_make2($1, NULL); }
17196 : | json_behavior ON ERROR_P
17197 552 : { $$ = list_make2(NULL, $1); }
17198 : | json_behavior ON EMPTY_P json_behavior ON ERROR_P
17199 102 : { $$ = list_make2($1, $4); }
17200 : | /* EMPTY */
17201 1586 : { $$ = list_make2(NULL, NULL); }
17202 : ;
17203 :
17204 : json_on_error_clause_opt:
17205 : json_behavior ON ERROR_P
17206 150 : { $$ = $1; }
17207 : | /* EMPTY */
17208 692 : { $$ = NULL; }
17209 : ;
17210 :
17211 : json_value_expr:
17212 : a_expr json_format_clause_opt
17213 : {
17214 : /* formatted_expr will be set during parse-analysis. */
17215 4292 : $$ = (Node *) makeJsonValueExpr((Expr *) $1, NULL,
17216 4292 : castNode(JsonFormat, $2));
17217 : }
17218 : ;
17219 :
17220 : json_format_clause:
17221 : FORMAT_LA JSON ENCODING name
17222 : {
17223 : int encoding;
17224 :
17225 100 : if (!pg_strcasecmp($4, "utf8"))
17226 64 : encoding = JS_ENC_UTF8;
17227 36 : else if (!pg_strcasecmp($4, "utf16"))
17228 12 : encoding = JS_ENC_UTF16;
17229 24 : else if (!pg_strcasecmp($4, "utf32"))
17230 12 : encoding = JS_ENC_UTF32;
17231 : else
17232 12 : ereport(ERROR,
17233 : (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
17234 : errmsg("unrecognized JSON encoding: %s", $4),
17235 : parser_errposition(@4)));
17236 :
17237 88 : $$ = (Node *) makeJsonFormat(JS_FORMAT_JSON, encoding, @1);
17238 : }
17239 : | FORMAT_LA JSON
17240 : {
17241 412 : $$ = (Node *) makeJsonFormat(JS_FORMAT_JSON, JS_ENC_DEFAULT, @1);
17242 : }
17243 : ;
17244 :
17245 : json_format_clause_opt:
17246 : json_format_clause
17247 : {
17248 392 : $$ = $1;
17249 : }
17250 : | /* EMPTY */
17251 : {
17252 5458 : $$ = (Node *) makeJsonFormat(JS_FORMAT_DEFAULT, JS_ENC_DEFAULT, -1);
17253 : }
17254 : ;
17255 :
17256 : json_quotes_clause_opt:
17257 12 : KEEP QUOTES ON SCALAR STRING_P { $$ = JS_QUOTES_KEEP; }
17258 90 : | KEEP QUOTES { $$ = JS_QUOTES_KEEP; }
17259 12 : | OMIT QUOTES ON SCALAR STRING_P { $$ = JS_QUOTES_OMIT; }
17260 168 : | OMIT QUOTES { $$ = JS_QUOTES_OMIT; }
17261 1550 : | /* EMPTY */ { $$ = JS_QUOTES_UNSPEC; }
17262 : ;
17263 :
17264 : json_returning_clause_opt:
17265 : RETURNING Typename json_format_clause_opt
17266 : {
17267 1498 : JsonOutput *n = makeNode(JsonOutput);
17268 :
17269 1498 : n->typeName = $2;
17270 1498 : n->returning = makeNode(JsonReturning);
17271 1498 : n->returning->format = (JsonFormat *) $3;
17272 1498 : $$ = (Node *) n;
17273 : }
17274 1296 : | /* EMPTY */ { $$ = NULL; }
17275 : ;
17276 :
17277 : /*
17278 : * We must assign the only-JSON production a precedence less than IDENT in
17279 : * order to favor shifting over reduction when JSON is followed by VALUE_P,
17280 : * OBJECT_P, or SCALAR. (ARRAY doesn't need that treatment, because it's a
17281 : * fully reserved word.) Because json_predicate_type_constraint is always
17282 : * followed by json_key_uniqueness_constraint_opt, we also need the only-JSON
17283 : * production to have precedence less than WITH and WITHOUT. UNBOUNDED isn't
17284 : * really related to this syntax, but it's a convenient choice because it
17285 : * already has a precedence less than IDENT for other reasons.
17286 : */
17287 : json_predicate_type_constraint:
17288 202 : JSON %prec UNBOUNDED { $$ = JS_TYPE_ANY; }
17289 28 : | JSON VALUE_P { $$ = JS_TYPE_ANY; }
17290 40 : | JSON ARRAY { $$ = JS_TYPE_ARRAY; }
17291 40 : | JSON OBJECT_P { $$ = JS_TYPE_OBJECT; }
17292 40 : | JSON SCALAR { $$ = JS_TYPE_SCALAR; }
17293 : ;
17294 :
17295 : /*
17296 : * KEYS is a noise word here. To avoid shift/reduce conflicts, assign the
17297 : * KEYS-less productions a precedence less than IDENT (i.e., less than KEYS).
17298 : * This prevents reducing them when the next token is KEYS.
17299 : */
17300 : json_key_uniqueness_constraint_opt:
17301 108 : WITH UNIQUE KEYS { $$ = true; }
17302 100 : | WITH UNIQUE %prec UNBOUNDED { $$ = true; }
17303 44 : | WITHOUT UNIQUE KEYS { $$ = false; }
17304 16 : | WITHOUT UNIQUE %prec UNBOUNDED { $$ = false; }
17305 798 : | /* EMPTY */ %prec UNBOUNDED { $$ = false; }
17306 : ;
17307 :
17308 : json_name_and_value_list:
17309 : json_name_and_value
17310 348 : { $$ = list_make1($1); }
17311 : | json_name_and_value_list ',' json_name_and_value
17312 256 : { $$ = lappend($1, $3); }
17313 : ;
17314 :
17315 : json_name_and_value:
17316 : /* Supporting this syntax seems to require major surgery
17317 : KEY c_expr VALUE_P json_value_expr
17318 : { $$ = makeJsonKeyValue($2, $4); }
17319 : |
17320 : */
17321 : c_expr VALUE_P json_value_expr
17322 24 : { $$ = makeJsonKeyValue($1, $3); }
17323 : |
17324 : a_expr ':' json_value_expr
17325 784 : { $$ = makeJsonKeyValue($1, $3); }
17326 : ;
17327 :
17328 : /* empty means false for objects, true for arrays */
17329 : json_object_constructor_null_clause_opt:
17330 30 : NULL_P ON NULL_P { $$ = false; }
17331 110 : | ABSENT ON NULL_P { $$ = true; }
17332 412 : | /* EMPTY */ { $$ = false; }
17333 : ;
17334 :
17335 : json_array_constructor_null_clause_opt:
17336 60 : NULL_P ON NULL_P { $$ = false; }
17337 36 : | ABSENT ON NULL_P { $$ = true; }
17338 180 : | /* EMPTY */ { $$ = true; }
17339 : ;
17340 :
17341 : json_value_expr_list:
17342 120 : json_value_expr { $$ = list_make1($1); }
17343 138 : | json_value_expr_list ',' json_value_expr { $$ = lappend($1, $3);}
17344 : ;
17345 :
17346 : json_aggregate_func:
17347 : JSON_OBJECTAGG '('
17348 : json_name_and_value
17349 : json_object_constructor_null_clause_opt
17350 : json_key_uniqueness_constraint_opt
17351 : json_returning_clause_opt
17352 : ')'
17353 : {
17354 204 : JsonObjectAgg *n = makeNode(JsonObjectAgg);
17355 :
17356 204 : n->arg = (JsonKeyValue *) $3;
17357 204 : n->absent_on_null = $4;
17358 204 : n->unique = $5;
17359 204 : n->constructor = makeNode(JsonAggConstructor);
17360 204 : n->constructor->output = (JsonOutput *) $6;
17361 204 : n->constructor->agg_order = NULL;
17362 204 : n->constructor->location = @1;
17363 204 : $$ = (Node *) n;
17364 : }
17365 : | JSON_ARRAYAGG '('
17366 : json_value_expr
17367 : json_array_aggregate_order_by_clause_opt
17368 : json_array_constructor_null_clause_opt
17369 : json_returning_clause_opt
17370 : ')'
17371 : {
17372 156 : JsonArrayAgg *n = makeNode(JsonArrayAgg);
17373 :
17374 156 : n->arg = (JsonValueExpr *) $3;
17375 156 : n->absent_on_null = $5;
17376 156 : n->constructor = makeNode(JsonAggConstructor);
17377 156 : n->constructor->agg_order = $4;
17378 156 : n->constructor->output = (JsonOutput *) $6;
17379 156 : n->constructor->location = @1;
17380 156 : $$ = (Node *) n;
17381 : }
17382 : ;
17383 :
17384 : json_array_aggregate_order_by_clause_opt:
17385 18 : ORDER BY sortby_list { $$ = $3; }
17386 138 : | /* EMPTY */ { $$ = NIL; }
17387 : ;
17388 :
17389 : /*****************************************************************************
17390 : *
17391 : * target list for SELECT
17392 : *
17393 : *****************************************************************************/
17394 :
17395 473396 : opt_target_list: target_list { $$ = $1; }
17396 552 : | /* EMPTY */ { $$ = NIL; }
17397 : ;
17398 :
17399 : target_list:
17400 480686 : target_el { $$ = list_make1($1); }
17401 678372 : | target_list ',' target_el { $$ = lappend($1, $3); }
17402 : ;
17403 :
17404 : target_el: a_expr AS ColLabel
17405 : {
17406 237104 : $$ = makeNode(ResTarget);
17407 237104 : $$->name = $3;
17408 237104 : $$->indirection = NIL;
17409 237104 : $$->val = (Node *) $1;
17410 237104 : $$->location = @1;
17411 : }
17412 : | a_expr BareColLabel
17413 : {
17414 3580 : $$ = makeNode(ResTarget);
17415 3580 : $$->name = $2;
17416 3580 : $$->indirection = NIL;
17417 3580 : $$->val = (Node *) $1;
17418 3580 : $$->location = @1;
17419 : }
17420 : | a_expr
17421 : {
17422 861304 : $$ = makeNode(ResTarget);
17423 861302 : $$->name = NULL;
17424 861302 : $$->indirection = NIL;
17425 861302 : $$->val = (Node *) $1;
17426 861302 : $$->location = @1;
17427 : }
17428 : | '*'
17429 : {
17430 57070 : ColumnRef *n = makeNode(ColumnRef);
17431 :
17432 57070 : n->fields = list_make1(makeNode(A_Star));
17433 57070 : n->location = @1;
17434 :
17435 57070 : $$ = makeNode(ResTarget);
17436 57070 : $$->name = NULL;
17437 57070 : $$->indirection = NIL;
17438 57070 : $$->val = (Node *) n;
17439 57070 : $$->location = @1;
17440 : }
17441 : ;
17442 :
17443 :
17444 : /*****************************************************************************
17445 : *
17446 : * Names and constants
17447 : *
17448 : *****************************************************************************/
17449 :
17450 : qualified_name_list:
17451 17762 : qualified_name { $$ = list_make1($1); }
17452 454 : | qualified_name_list ',' qualified_name { $$ = lappend($1, $3); }
17453 : ;
17454 :
17455 : /*
17456 : * The production for a qualified relation name has to exactly match the
17457 : * production for a qualified func_name, because in a FROM clause we cannot
17458 : * tell which we are parsing until we see what comes after it ('(' for a
17459 : * func_name, something else for a relation). Therefore we allow 'indirection'
17460 : * which may contain subscripts, and reject that case in the C code.
17461 : */
17462 : qualified_name:
17463 : ColId
17464 : {
17465 425026 : $$ = makeRangeVar(NULL, $1, @1);
17466 : }
17467 : | ColId indirection
17468 : {
17469 244186 : $$ = makeRangeVarFromQualifiedName($1, $2, @1, yyscanner);
17470 : }
17471 : ;
17472 :
17473 : name_list: name
17474 28490 : { $$ = list_make1(makeString($1)); }
17475 : | name_list ',' name
17476 61618 : { $$ = lappend($1, makeString($3)); }
17477 : ;
17478 :
17479 :
17480 176916 : name: ColId { $$ = $1; };
17481 :
17482 1558274 : attr_name: ColLabel { $$ = $1; };
17483 :
17484 64 : file_name: Sconst { $$ = $1; };
17485 :
17486 : /*
17487 : * The production for a qualified func_name has to exactly match the
17488 : * production for a qualified columnref, because we cannot tell which we
17489 : * are parsing until we see what comes after it ('(' or Sconst for a func_name,
17490 : * anything else for a columnref). Therefore we allow 'indirection' which
17491 : * may contain subscripts, and reject that case in the C code. (If we
17492 : * ever implement SQL99-like methods, such syntax may actually become legal!)
17493 : */
17494 : func_name: type_function_name
17495 300324 : { $$ = list_make1(makeString($1)); }
17496 : | ColId indirection
17497 : {
17498 126398 : $$ = check_func_name(lcons(makeString($1), $2),
17499 : yyscanner);
17500 : }
17501 : ;
17502 :
17503 :
17504 : /*
17505 : * Constants
17506 : */
17507 : AexprConst: Iconst
17508 : {
17509 380478 : $$ = makeIntConst($1, @1);
17510 : }
17511 : | FCONST
17512 : {
17513 11928 : $$ = makeFloatConst($1, @1);
17514 : }
17515 : | Sconst
17516 : {
17517 697446 : $$ = makeStringConst($1, @1);
17518 : }
17519 : | BCONST
17520 : {
17521 754 : $$ = makeBitStringConst($1, @1);
17522 : }
17523 : | XCONST
17524 : {
17525 : /* This is a bit constant per SQL99:
17526 : * Without Feature F511, "BIT data type",
17527 : * a <general literal> shall not be a
17528 : * <bit string literal> or a <hex string literal>.
17529 : */
17530 3302 : $$ = makeBitStringConst($1, @1);
17531 : }
17532 : | func_name Sconst
17533 : {
17534 : /* generic type 'literal' syntax */
17535 9848 : TypeName *t = makeTypeNameFromNameList($1);
17536 :
17537 9848 : t->location = @1;
17538 9848 : $$ = makeStringConstCast($2, @2, t);
17539 : }
17540 : | func_name '(' func_arg_list opt_sort_clause ')' Sconst
17541 : {
17542 : /* generic syntax with a type modifier */
17543 0 : TypeName *t = makeTypeNameFromNameList($1);
17544 : ListCell *lc;
17545 :
17546 : /*
17547 : * We must use func_arg_list and opt_sort_clause in the
17548 : * production to avoid reduce/reduce conflicts, but we
17549 : * don't actually wish to allow NamedArgExpr in this
17550 : * context, nor ORDER BY.
17551 : */
17552 0 : foreach(lc, $3)
17553 : {
17554 0 : NamedArgExpr *arg = (NamedArgExpr *) lfirst(lc);
17555 :
17556 0 : if (IsA(arg, NamedArgExpr))
17557 0 : ereport(ERROR,
17558 : (errcode(ERRCODE_SYNTAX_ERROR),
17559 : errmsg("type modifier cannot have parameter name"),
17560 : parser_errposition(arg->location)));
17561 : }
17562 0 : if ($4 != NIL)
17563 0 : ereport(ERROR,
17564 : (errcode(ERRCODE_SYNTAX_ERROR),
17565 : errmsg("type modifier cannot have ORDER BY"),
17566 : parser_errposition(@4)));
17567 :
17568 0 : t->typmods = $3;
17569 0 : t->location = @1;
17570 0 : $$ = makeStringConstCast($6, @6, t);
17571 : }
17572 : | ConstTypename Sconst
17573 : {
17574 3176 : $$ = makeStringConstCast($2, @2, $1);
17575 : }
17576 : | ConstInterval Sconst opt_interval
17577 : {
17578 3298 : TypeName *t = $1;
17579 :
17580 3298 : t->typmods = $3;
17581 3298 : $$ = makeStringConstCast($2, @2, t);
17582 : }
17583 : | ConstInterval '(' Iconst ')' Sconst
17584 : {
17585 12 : TypeName *t = $1;
17586 :
17587 12 : t->typmods = list_make2(makeIntConst(INTERVAL_FULL_RANGE, -1),
17588 : makeIntConst($3, @3));
17589 12 : $$ = makeStringConstCast($5, @5, t);
17590 : }
17591 : | TRUE_P
17592 : {
17593 31138 : $$ = makeBoolAConst(true, @1);
17594 : }
17595 : | FALSE_P
17596 : {
17597 36012 : $$ = makeBoolAConst(false, @1);
17598 : }
17599 : | NULL_P
17600 : {
17601 67626 : $$ = makeNullAConst(@1);
17602 : }
17603 : ;
17604 :
17605 408870 : Iconst: ICONST { $$ = $1; };
17606 772072 : Sconst: SCONST { $$ = $1; };
17607 :
17608 17632 : SignedIconst: Iconst { $$ = $1; }
17609 0 : | '+' Iconst { $$ = + $2; }
17610 288 : | '-' Iconst { $$ = - $2; }
17611 : ;
17612 :
17613 : /* Role specifications */
17614 : RoleId: RoleSpec
17615 : {
17616 1944 : RoleSpec *spc = (RoleSpec *) $1;
17617 :
17618 1944 : switch (spc->roletype)
17619 : {
17620 1934 : case ROLESPEC_CSTRING:
17621 1934 : $$ = spc->rolename;
17622 1934 : break;
17623 4 : case ROLESPEC_PUBLIC:
17624 4 : ereport(ERROR,
17625 : (errcode(ERRCODE_RESERVED_NAME),
17626 : errmsg("role name \"%s\" is reserved",
17627 : "public"),
17628 : parser_errposition(@1)));
17629 : break;
17630 2 : case ROLESPEC_SESSION_USER:
17631 2 : ereport(ERROR,
17632 : (errcode(ERRCODE_RESERVED_NAME),
17633 : errmsg("%s cannot be used as a role name here",
17634 : "SESSION_USER"),
17635 : parser_errposition(@1)));
17636 : break;
17637 2 : case ROLESPEC_CURRENT_USER:
17638 2 : ereport(ERROR,
17639 : (errcode(ERRCODE_RESERVED_NAME),
17640 : errmsg("%s cannot be used as a role name here",
17641 : "CURRENT_USER"),
17642 : parser_errposition(@1)));
17643 : break;
17644 2 : case ROLESPEC_CURRENT_ROLE:
17645 2 : ereport(ERROR,
17646 : (errcode(ERRCODE_RESERVED_NAME),
17647 : errmsg("%s cannot be used as a role name here",
17648 : "CURRENT_ROLE"),
17649 : parser_errposition(@1)));
17650 : break;
17651 : }
17652 : }
17653 : ;
17654 :
17655 : RoleSpec: NonReservedWord
17656 : {
17657 : /*
17658 : * "public" and "none" are not keywords, but they must
17659 : * be treated specially here.
17660 : */
17661 : RoleSpec *n;
17662 :
17663 32768 : if (strcmp($1, "public") == 0)
17664 : {
17665 17820 : n = (RoleSpec *) makeRoleSpec(ROLESPEC_PUBLIC, @1);
17666 17820 : n->roletype = ROLESPEC_PUBLIC;
17667 : }
17668 14948 : else if (strcmp($1, "none") == 0)
17669 : {
17670 26 : ereport(ERROR,
17671 : (errcode(ERRCODE_RESERVED_NAME),
17672 : errmsg("role name \"%s\" is reserved",
17673 : "none"),
17674 : parser_errposition(@1)));
17675 : }
17676 : else
17677 : {
17678 14922 : n = makeRoleSpec(ROLESPEC_CSTRING, @1);
17679 14922 : n->rolename = pstrdup($1);
17680 : }
17681 32742 : $$ = n;
17682 : }
17683 : | CURRENT_ROLE
17684 : {
17685 130 : $$ = makeRoleSpec(ROLESPEC_CURRENT_ROLE, @1);
17686 : }
17687 : | CURRENT_USER
17688 : {
17689 228 : $$ = makeRoleSpec(ROLESPEC_CURRENT_USER, @1);
17690 : }
17691 : | SESSION_USER
17692 : {
17693 36 : $$ = makeRoleSpec(ROLESPEC_SESSION_USER, @1);
17694 : }
17695 : ;
17696 :
17697 : role_list: RoleSpec
17698 3246 : { $$ = list_make1($1); }
17699 : | role_list ',' RoleSpec
17700 270 : { $$ = lappend($1, $3); }
17701 : ;
17702 :
17703 :
17704 : /*****************************************************************************
17705 : *
17706 : * PL/pgSQL extensions
17707 : *
17708 : * You'd think a PL/pgSQL "expression" should be just an a_expr, but
17709 : * historically it can include just about anything that can follow SELECT.
17710 : * Therefore the returned struct is a SelectStmt.
17711 : *****************************************************************************/
17712 :
17713 : PLpgSQL_Expr: opt_distinct_clause opt_target_list
17714 : from_clause where_clause
17715 : group_clause having_clause window_clause
17716 : opt_sort_clause opt_select_limit opt_for_locking_clause
17717 : {
17718 40914 : SelectStmt *n = makeNode(SelectStmt);
17719 :
17720 40914 : n->distinctClause = $1;
17721 40914 : n->targetList = $2;
17722 40914 : n->fromClause = $3;
17723 40914 : n->whereClause = $4;
17724 40914 : n->groupClause = ($5)->list;
17725 40914 : n->groupDistinct = ($5)->distinct;
17726 40914 : n->groupByAll = ($5)->all;
17727 40914 : n->havingClause = $6;
17728 40914 : n->windowClause = $7;
17729 40914 : n->sortClause = $8;
17730 40914 : if ($9)
17731 : {
17732 4 : n->limitOffset = $9->limitOffset;
17733 4 : n->limitCount = $9->limitCount;
17734 4 : if (!n->sortClause &&
17735 4 : $9->limitOption == LIMIT_OPTION_WITH_TIES)
17736 0 : ereport(ERROR,
17737 : (errcode(ERRCODE_SYNTAX_ERROR),
17738 : errmsg("WITH TIES cannot be specified without ORDER BY clause"),
17739 : parser_errposition($9->optionLoc)));
17740 4 : n->limitOption = $9->limitOption;
17741 : }
17742 40914 : n->lockingClause = $10;
17743 40914 : $$ = (Node *) n;
17744 : }
17745 : ;
17746 :
17747 : /*
17748 : * PL/pgSQL Assignment statement: name opt_indirection := PLpgSQL_Expr
17749 : */
17750 :
17751 : PLAssignStmt: plassign_target opt_indirection plassign_equals PLpgSQL_Expr
17752 : {
17753 7072 : PLAssignStmt *n = makeNode(PLAssignStmt);
17754 :
17755 7072 : n->name = $1;
17756 7072 : n->indirection = check_indirection($2, yyscanner);
17757 : /* nnames will be filled by calling production */
17758 7024 : n->val = (SelectStmt *) $4;
17759 7024 : n->location = @1;
17760 7024 : $$ = (Node *) n;
17761 : }
17762 : ;
17763 :
17764 7048 : plassign_target: ColId { $$ = $1; }
17765 24 : | PARAM { $$ = psprintf("$%d", $1); }
17766 : ;
17767 :
17768 : plassign_equals: COLON_EQUALS
17769 : | '='
17770 : ;
17771 :
17772 :
17773 : /*
17774 : * Name classification hierarchy.
17775 : *
17776 : * IDENT is the lexeme returned by the lexer for identifiers that match
17777 : * no known keyword. In most cases, we can accept certain keywords as
17778 : * names, not only IDENTs. We prefer to accept as many such keywords
17779 : * as possible to minimize the impact of "reserved words" on programmers.
17780 : * So, we divide names into several possible classes. The classification
17781 : * is chosen in part to make keywords acceptable as names wherever possible.
17782 : */
17783 :
17784 : /* Column identifier --- names that can be column, table, etc names.
17785 : */
17786 3377100 : ColId: IDENT { $$ = $1; }
17787 58186 : | unreserved_keyword { $$ = pstrdup($1); }
17788 6174 : | col_name_keyword { $$ = pstrdup($1); }
17789 : ;
17790 :
17791 : /* Type/function identifier --- names that can be type or function names.
17792 : */
17793 718340 : type_function_name: IDENT { $$ = $1; }
17794 76582 : | unreserved_keyword { $$ = pstrdup($1); }
17795 66 : | type_func_name_keyword { $$ = pstrdup($1); }
17796 : ;
17797 :
17798 : /* Any not-fully-reserved word --- these names can be, eg, role names.
17799 : */
17800 85148 : NonReservedWord: IDENT { $$ = $1; }
17801 30802 : | unreserved_keyword { $$ = pstrdup($1); }
17802 178 : | col_name_keyword { $$ = pstrdup($1); }
17803 5898 : | type_func_name_keyword { $$ = pstrdup($1); }
17804 : ;
17805 :
17806 : /* Column label --- allowed labels in "AS" clauses.
17807 : * This presently includes *all* Postgres keywords.
17808 : */
17809 1779442 : ColLabel: IDENT { $$ = $1; }
17810 39960 : | unreserved_keyword { $$ = pstrdup($1); }
17811 284 : | col_name_keyword { $$ = pstrdup($1); }
17812 1772 : | type_func_name_keyword { $$ = pstrdup($1); }
17813 7530 : | reserved_keyword { $$ = pstrdup($1); }
17814 : ;
17815 :
17816 : /* Bare column label --- names that can be column labels without writing "AS".
17817 : * This classification is orthogonal to the other keyword categories.
17818 : */
17819 3566 : BareColLabel: IDENT { $$ = $1; }
17820 14 : | bare_label_keyword { $$ = pstrdup($1); }
17821 : ;
17822 :
17823 :
17824 : /*
17825 : * Keyword category lists. Generally, every keyword present in
17826 : * the Postgres grammar should appear in exactly one of these lists.
17827 : *
17828 : * Put a new keyword into the first list that it can go into without causing
17829 : * shift or reduce conflicts. The earlier lists define "less reserved"
17830 : * categories of keywords.
17831 : *
17832 : * Make sure that each keyword's category in kwlist.h matches where
17833 : * it is listed here. (Someday we may be able to generate these lists and
17834 : * kwlist.h's table from one source of truth.)
17835 : */
17836 :
17837 : /* "Unreserved" keywords --- available for use as any kind of name.
17838 : */
17839 : unreserved_keyword:
17840 : ABORT_P
17841 : | ABSENT
17842 : | ABSOLUTE_P
17843 : | ACCESS
17844 : | ACTION
17845 : | ADD_P
17846 : | ADMIN
17847 : | AFTER
17848 : | AGGREGATE
17849 : | ALSO
17850 : | ALTER
17851 : | ALWAYS
17852 : | ASENSITIVE
17853 : | ASSERTION
17854 : | ASSIGNMENT
17855 : | AT
17856 : | ATOMIC
17857 : | ATTACH
17858 : | ATTRIBUTE
17859 : | BACKWARD
17860 : | BEFORE
17861 : | BEGIN_P
17862 : | BREADTH
17863 : | BY
17864 : | CACHE
17865 : | CALL
17866 : | CALLED
17867 : | CASCADE
17868 : | CASCADED
17869 : | CATALOG_P
17870 : | CHAIN
17871 : | CHARACTERISTICS
17872 : | CHECKPOINT
17873 : | CLASS
17874 : | CLOSE
17875 : | CLUSTER
17876 : | COLUMNS
17877 : | COMMENT
17878 : | COMMENTS
17879 : | COMMIT
17880 : | COMMITTED
17881 : | COMPRESSION
17882 : | CONDITIONAL
17883 : | CONFIGURATION
17884 : | CONFLICT
17885 : | CONNECTION
17886 : | CONSTRAINTS
17887 : | CONTENT_P
17888 : | CONTINUE_P
17889 : | CONVERSION_P
17890 : | COPY
17891 : | COST
17892 : | CSV
17893 : | CUBE
17894 : | CURRENT_P
17895 : | CURSOR
17896 : | CYCLE
17897 : | DATA_P
17898 : | DATABASE
17899 : | DAY_P
17900 : | DEALLOCATE
17901 : | DECLARE
17902 : | DEFAULTS
17903 : | DEFERRED
17904 : | DEFINER
17905 : | DELETE_P
17906 : | DELIMITER
17907 : | DELIMITERS
17908 : | DEPENDS
17909 : | DEPTH
17910 : | DETACH
17911 : | DICTIONARY
17912 : | DISABLE_P
17913 : | DISCARD
17914 : | DOCUMENT_P
17915 : | DOMAIN_P
17916 : | DOUBLE_P
17917 : | DROP
17918 : | EACH
17919 : | EMPTY_P
17920 : | ENABLE_P
17921 : | ENCODING
17922 : | ENCRYPTED
17923 : | ENFORCED
17924 : | ENUM_P
17925 : | ERROR_P
17926 : | ESCAPE
17927 : | EVENT
17928 : | EXCLUDE
17929 : | EXCLUDING
17930 : | EXCLUSIVE
17931 : | EXECUTE
17932 : | EXPLAIN
17933 : | EXPRESSION
17934 : | EXTENSION
17935 : | EXTERNAL
17936 : | FAMILY
17937 : | FILTER
17938 : | FINALIZE
17939 : | FIRST_P
17940 : | FOLLOWING
17941 : | FORCE
17942 : | FORMAT
17943 : | FORWARD
17944 : | FUNCTION
17945 : | FUNCTIONS
17946 : | GENERATED
17947 : | GLOBAL
17948 : | GRANTED
17949 : | GROUPS
17950 : | HANDLER
17951 : | HEADER_P
17952 : | HOLD
17953 : | HOUR_P
17954 : | IDENTITY_P
17955 : | IF_P
17956 : | IGNORE_P
17957 : | IMMEDIATE
17958 : | IMMUTABLE
17959 : | IMPLICIT_P
17960 : | IMPORT_P
17961 : | INCLUDE
17962 : | INCLUDING
17963 : | INCREMENT
17964 : | INDENT
17965 : | INDEX
17966 : | INDEXES
17967 : | INHERIT
17968 : | INHERITS
17969 : | INLINE_P
17970 : | INPUT_P
17971 : | INSENSITIVE
17972 : | INSERT
17973 : | INSTEAD
17974 : | INVOKER
17975 : | ISOLATION
17976 : | KEEP
17977 : | KEY
17978 : | KEYS
17979 : | LABEL
17980 : | LANGUAGE
17981 : | LARGE_P
17982 : | LAST_P
17983 : | LEAKPROOF
17984 : | LEVEL
17985 : | LISTEN
17986 : | LOAD
17987 : | LOCAL
17988 : | LOCATION
17989 : | LOCK_P
17990 : | LOCKED
17991 : | LOGGED
17992 : | LSN_P
17993 : | MAPPING
17994 : | MATCH
17995 : | MATCHED
17996 : | MATERIALIZED
17997 : | MAXVALUE
17998 : | MERGE
17999 : | METHOD
18000 : | MINUTE_P
18001 : | MINVALUE
18002 : | MODE
18003 : | MONTH_P
18004 : | MOVE
18005 : | NAME_P
18006 : | NAMES
18007 : | NESTED
18008 : | NEW
18009 : | NEXT
18010 : | NFC
18011 : | NFD
18012 : | NFKC
18013 : | NFKD
18014 : | NO
18015 : | NORMALIZED
18016 : | NOTHING
18017 : | NOTIFY
18018 : | NOWAIT
18019 : | NULLS_P
18020 : | OBJECT_P
18021 : | OBJECTS_P
18022 : | OF
18023 : | OFF
18024 : | OIDS
18025 : | OLD
18026 : | OMIT
18027 : | OPERATOR
18028 : | OPTION
18029 : | OPTIONS
18030 : | ORDINALITY
18031 : | OTHERS
18032 : | OVER
18033 : | OVERRIDING
18034 : | OWNED
18035 : | OWNER
18036 : | PARALLEL
18037 : | PARAMETER
18038 : | PARSER
18039 : | PARTIAL
18040 : | PARTITION
18041 : | PASSING
18042 : | PASSWORD
18043 : | PATH
18044 : | PERIOD
18045 : | PLAN
18046 : | PLANS
18047 : | POLICY
18048 : | PRECEDING
18049 : | PREPARE
18050 : | PREPARED
18051 : | PRESERVE
18052 : | PRIOR
18053 : | PRIVILEGES
18054 : | PROCEDURAL
18055 : | PROCEDURE
18056 : | PROCEDURES
18057 : | PROGRAM
18058 : | PUBLICATION
18059 : | QUOTE
18060 : | QUOTES
18061 : | RANGE
18062 : | READ
18063 : | REASSIGN
18064 : | RECURSIVE
18065 : | REF_P
18066 : | REFERENCING
18067 : | REFRESH
18068 : | REINDEX
18069 : | RELATIVE_P
18070 : | RELEASE
18071 : | RENAME
18072 : | REPEATABLE
18073 : | REPLACE
18074 : | REPLICA
18075 : | RESET
18076 : | RESPECT_P
18077 : | RESTART
18078 : | RESTRICT
18079 : | RETURN
18080 : | RETURNS
18081 : | REVOKE
18082 : | ROLE
18083 : | ROLLBACK
18084 : | ROLLUP
18085 : | ROUTINE
18086 : | ROUTINES
18087 : | ROWS
18088 : | RULE
18089 : | SAVEPOINT
18090 : | SCALAR
18091 : | SCHEMA
18092 : | SCHEMAS
18093 : | SCROLL
18094 : | SEARCH
18095 : | SECOND_P
18096 : | SECURITY
18097 : | SEQUENCE
18098 : | SEQUENCES
18099 : | SERIALIZABLE
18100 : | SERVER
18101 : | SESSION
18102 : | SET
18103 : | SETS
18104 : | SHARE
18105 : | SHOW
18106 : | SIMPLE
18107 : | SKIP
18108 : | SNAPSHOT
18109 : | SOURCE
18110 : | SQL_P
18111 : | STABLE
18112 : | STANDALONE_P
18113 : | START
18114 : | STATEMENT
18115 : | STATISTICS
18116 : | STDIN
18117 : | STDOUT
18118 : | STORAGE
18119 : | STORED
18120 : | STRICT_P
18121 : | STRING_P
18122 : | STRIP_P
18123 : | SUBSCRIPTION
18124 : | SUPPORT
18125 : | SYSID
18126 : | SYSTEM_P
18127 : | TABLES
18128 : | TABLESPACE
18129 : | TARGET
18130 : | TEMP
18131 : | TEMPLATE
18132 : | TEMPORARY
18133 : | TEXT_P
18134 : | TIES
18135 : | TRANSACTION
18136 : | TRANSFORM
18137 : | TRIGGER
18138 : | TRUNCATE
18139 : | TRUSTED
18140 : | TYPE_P
18141 : | TYPES_P
18142 : | UESCAPE
18143 : | UNBOUNDED
18144 : | UNCOMMITTED
18145 : | UNCONDITIONAL
18146 : | UNENCRYPTED
18147 : | UNKNOWN
18148 : | UNLISTEN
18149 : | UNLOGGED
18150 : | UNTIL
18151 : | UPDATE
18152 : | VACUUM
18153 : | VALID
18154 : | VALIDATE
18155 : | VALIDATOR
18156 : | VALUE_P
18157 : | VARYING
18158 : | VERSION_P
18159 : | VIEW
18160 : | VIEWS
18161 : | VIRTUAL
18162 : | VOLATILE
18163 : | WAIT
18164 : | WHITESPACE_P
18165 : | WITHIN
18166 : | WITHOUT
18167 : | WORK
18168 : | WRAPPER
18169 : | WRITE
18170 : | XML_P
18171 : | YEAR_P
18172 : | YES_P
18173 : | ZONE
18174 : ;
18175 :
18176 : /* Column identifier --- keywords that can be column, table, etc names.
18177 : *
18178 : * Many of these keywords will in fact be recognized as type or function
18179 : * names too; but they have special productions for the purpose, and so
18180 : * can't be treated as "generic" type or function names.
18181 : *
18182 : * The type names appearing here are not usable as function names
18183 : * because they can be followed by '(' in typename productions, which
18184 : * looks too much like a function call for an LR(1) parser.
18185 : */
18186 : col_name_keyword:
18187 : BETWEEN
18188 : | BIGINT
18189 : | BIT
18190 : | BOOLEAN_P
18191 : | CHAR_P
18192 : | CHARACTER
18193 : | COALESCE
18194 : | DEC
18195 : | DECIMAL_P
18196 : | EXISTS
18197 : | EXTRACT
18198 : | FLOAT_P
18199 : | GREATEST
18200 : | GROUPING
18201 : | INOUT
18202 : | INT_P
18203 : | INTEGER
18204 : | INTERVAL
18205 : | JSON
18206 : | JSON_ARRAY
18207 : | JSON_ARRAYAGG
18208 : | JSON_EXISTS
18209 : | JSON_OBJECT
18210 : | JSON_OBJECTAGG
18211 : | JSON_QUERY
18212 : | JSON_SCALAR
18213 : | JSON_SERIALIZE
18214 : | JSON_TABLE
18215 : | JSON_VALUE
18216 : | LEAST
18217 : | MERGE_ACTION
18218 : | NATIONAL
18219 : | NCHAR
18220 : | NONE
18221 : | NORMALIZE
18222 : | NULLIF
18223 : | NUMERIC
18224 : | OUT_P
18225 : | OVERLAY
18226 : | POSITION
18227 : | PRECISION
18228 : | REAL
18229 : | ROW
18230 : | SETOF
18231 : | SMALLINT
18232 : | SUBSTRING
18233 : | TIME
18234 : | TIMESTAMP
18235 : | TREAT
18236 : | TRIM
18237 : | VALUES
18238 : | VARCHAR
18239 : | XMLATTRIBUTES
18240 : | XMLCONCAT
18241 : | XMLELEMENT
18242 : | XMLEXISTS
18243 : | XMLFOREST
18244 : | XMLNAMESPACES
18245 : | XMLPARSE
18246 : | XMLPI
18247 : | XMLROOT
18248 : | XMLSERIALIZE
18249 : | XMLTABLE
18250 : ;
18251 :
18252 : /* Type/function identifier --- keywords that can be type or function names.
18253 : *
18254 : * Most of these are keywords that are used as operators in expressions;
18255 : * in general such keywords can't be column names because they would be
18256 : * ambiguous with variables, but they are unambiguous as function identifiers.
18257 : *
18258 : * Do not include POSITION, SUBSTRING, etc here since they have explicit
18259 : * productions in a_expr to support the goofy SQL9x argument syntax.
18260 : * - thomas 2000-11-28
18261 : */
18262 : type_func_name_keyword:
18263 : AUTHORIZATION
18264 : | BINARY
18265 : | COLLATION
18266 : | CONCURRENTLY
18267 : | CROSS
18268 : | CURRENT_SCHEMA
18269 : | FREEZE
18270 : | FULL
18271 : | ILIKE
18272 : | INNER_P
18273 : | IS
18274 : | ISNULL
18275 : | JOIN
18276 : | LEFT
18277 : | LIKE
18278 : | NATURAL
18279 : | NOTNULL
18280 : | OUTER_P
18281 : | OVERLAPS
18282 : | RIGHT
18283 : | SIMILAR
18284 : | TABLESAMPLE
18285 : | VERBOSE
18286 : ;
18287 :
18288 : /* Reserved keyword --- these keywords are usable only as a ColLabel.
18289 : *
18290 : * Keywords appear here if they could not be distinguished from variable,
18291 : * type, or function names in some contexts. Don't put things here unless
18292 : * forced to.
18293 : */
18294 : reserved_keyword:
18295 : ALL
18296 : | ANALYSE
18297 : | ANALYZE
18298 : | AND
18299 : | ANY
18300 : | ARRAY
18301 : | AS
18302 : | ASC
18303 : | ASYMMETRIC
18304 : | BOTH
18305 : | CASE
18306 : | CAST
18307 : | CHECK
18308 : | COLLATE
18309 : | COLUMN
18310 : | CONSTRAINT
18311 : | CREATE
18312 : | CURRENT_CATALOG
18313 : | CURRENT_DATE
18314 : | CURRENT_ROLE
18315 : | CURRENT_TIME
18316 : | CURRENT_TIMESTAMP
18317 : | CURRENT_USER
18318 : | DEFAULT
18319 : | DEFERRABLE
18320 : | DESC
18321 : | DISTINCT
18322 : | DO
18323 : | ELSE
18324 : | END_P
18325 : | EXCEPT
18326 : | FALSE_P
18327 : | FETCH
18328 : | FOR
18329 : | FOREIGN
18330 : | FROM
18331 : | GRANT
18332 : | GROUP_P
18333 : | HAVING
18334 : | IN_P
18335 : | INITIALLY
18336 : | INTERSECT
18337 : | INTO
18338 : | LATERAL_P
18339 : | LEADING
18340 : | LIMIT
18341 : | LOCALTIME
18342 : | LOCALTIMESTAMP
18343 : | NOT
18344 : | NULL_P
18345 : | OFFSET
18346 : | ON
18347 : | ONLY
18348 : | OR
18349 : | ORDER
18350 : | PLACING
18351 : | PRIMARY
18352 : | REFERENCES
18353 : | RETURNING
18354 : | SELECT
18355 : | SESSION_USER
18356 : | SOME
18357 : | SYMMETRIC
18358 : | SYSTEM_USER
18359 : | TABLE
18360 : | THEN
18361 : | TO
18362 : | TRAILING
18363 : | TRUE_P
18364 : | UNION
18365 : | UNIQUE
18366 : | USER
18367 : | USING
18368 : | VARIADIC
18369 : | WHEN
18370 : | WHERE
18371 : | WINDOW
18372 : | WITH
18373 : ;
18374 :
18375 : /*
18376 : * While all keywords can be used as column labels when preceded by AS,
18377 : * not all of them can be used as a "bare" column label without AS.
18378 : * Those that can be used as a bare label must be listed here,
18379 : * in addition to appearing in one of the category lists above.
18380 : *
18381 : * Always add a new keyword to this list if possible. Mark it BARE_LABEL
18382 : * in kwlist.h if it is included here, or AS_LABEL if it is not.
18383 : */
18384 : bare_label_keyword:
18385 : ABORT_P
18386 : | ABSENT
18387 : | ABSOLUTE_P
18388 : | ACCESS
18389 : | ACTION
18390 : | ADD_P
18391 : | ADMIN
18392 : | AFTER
18393 : | AGGREGATE
18394 : | ALL
18395 : | ALSO
18396 : | ALTER
18397 : | ALWAYS
18398 : | ANALYSE
18399 : | ANALYZE
18400 : | AND
18401 : | ANY
18402 : | ASC
18403 : | ASENSITIVE
18404 : | ASSERTION
18405 : | ASSIGNMENT
18406 : | ASYMMETRIC
18407 : | AT
18408 : | ATOMIC
18409 : | ATTACH
18410 : | ATTRIBUTE
18411 : | AUTHORIZATION
18412 : | BACKWARD
18413 : | BEFORE
18414 : | BEGIN_P
18415 : | BETWEEN
18416 : | BIGINT
18417 : | BINARY
18418 : | BIT
18419 : | BOOLEAN_P
18420 : | BOTH
18421 : | BREADTH
18422 : | BY
18423 : | CACHE
18424 : | CALL
18425 : | CALLED
18426 : | CASCADE
18427 : | CASCADED
18428 : | CASE
18429 : | CAST
18430 : | CATALOG_P
18431 : | CHAIN
18432 : | CHARACTERISTICS
18433 : | CHECK
18434 : | CHECKPOINT
18435 : | CLASS
18436 : | CLOSE
18437 : | CLUSTER
18438 : | COALESCE
18439 : | COLLATE
18440 : | COLLATION
18441 : | COLUMN
18442 : | COLUMNS
18443 : | COMMENT
18444 : | COMMENTS
18445 : | COMMIT
18446 : | COMMITTED
18447 : | COMPRESSION
18448 : | CONCURRENTLY
18449 : | CONDITIONAL
18450 : | CONFIGURATION
18451 : | CONFLICT
18452 : | CONNECTION
18453 : | CONSTRAINT
18454 : | CONSTRAINTS
18455 : | CONTENT_P
18456 : | CONTINUE_P
18457 : | CONVERSION_P
18458 : | COPY
18459 : | COST
18460 : | CROSS
18461 : | CSV
18462 : | CUBE
18463 : | CURRENT_P
18464 : | CURRENT_CATALOG
18465 : | CURRENT_DATE
18466 : | CURRENT_ROLE
18467 : | CURRENT_SCHEMA
18468 : | CURRENT_TIME
18469 : | CURRENT_TIMESTAMP
18470 : | CURRENT_USER
18471 : | CURSOR
18472 : | CYCLE
18473 : | DATA_P
18474 : | DATABASE
18475 : | DEALLOCATE
18476 : | DEC
18477 : | DECIMAL_P
18478 : | DECLARE
18479 : | DEFAULT
18480 : | DEFAULTS
18481 : | DEFERRABLE
18482 : | DEFERRED
18483 : | DEFINER
18484 : | DELETE_P
18485 : | DELIMITER
18486 : | DELIMITERS
18487 : | DEPENDS
18488 : | DEPTH
18489 : | DESC
18490 : | DETACH
18491 : | DICTIONARY
18492 : | DISABLE_P
18493 : | DISCARD
18494 : | DISTINCT
18495 : | DO
18496 : | DOCUMENT_P
18497 : | DOMAIN_P
18498 : | DOUBLE_P
18499 : | DROP
18500 : | EACH
18501 : | ELSE
18502 : | EMPTY_P
18503 : | ENABLE_P
18504 : | ENCODING
18505 : | ENCRYPTED
18506 : | END_P
18507 : | ENFORCED
18508 : | ENUM_P
18509 : | ERROR_P
18510 : | ESCAPE
18511 : | EVENT
18512 : | EXCLUDE
18513 : | EXCLUDING
18514 : | EXCLUSIVE
18515 : | EXECUTE
18516 : | EXISTS
18517 : | EXPLAIN
18518 : | EXPRESSION
18519 : | EXTENSION
18520 : | EXTERNAL
18521 : | EXTRACT
18522 : | FALSE_P
18523 : | FAMILY
18524 : | FINALIZE
18525 : | FIRST_P
18526 : | FLOAT_P
18527 : | FOLLOWING
18528 : | FORCE
18529 : | FOREIGN
18530 : | FORMAT
18531 : | FORWARD
18532 : | FREEZE
18533 : | FULL
18534 : | FUNCTION
18535 : | FUNCTIONS
18536 : | GENERATED
18537 : | GLOBAL
18538 : | GRANTED
18539 : | GREATEST
18540 : | GROUPING
18541 : | GROUPS
18542 : | HANDLER
18543 : | HEADER_P
18544 : | HOLD
18545 : | IDENTITY_P
18546 : | IF_P
18547 : | ILIKE
18548 : | IMMEDIATE
18549 : | IMMUTABLE
18550 : | IMPLICIT_P
18551 : | IMPORT_P
18552 : | IN_P
18553 : | INCLUDE
18554 : | INCLUDING
18555 : | INCREMENT
18556 : | INDENT
18557 : | INDEX
18558 : | INDEXES
18559 : | INHERIT
18560 : | INHERITS
18561 : | INITIALLY
18562 : | INLINE_P
18563 : | INNER_P
18564 : | INOUT
18565 : | INPUT_P
18566 : | INSENSITIVE
18567 : | INSERT
18568 : | INSTEAD
18569 : | INT_P
18570 : | INTEGER
18571 : | INTERVAL
18572 : | INVOKER
18573 : | IS
18574 : | ISOLATION
18575 : | JOIN
18576 : | JSON
18577 : | JSON_ARRAY
18578 : | JSON_ARRAYAGG
18579 : | JSON_EXISTS
18580 : | JSON_OBJECT
18581 : | JSON_OBJECTAGG
18582 : | JSON_QUERY
18583 : | JSON_SCALAR
18584 : | JSON_SERIALIZE
18585 : | JSON_TABLE
18586 : | JSON_VALUE
18587 : | KEEP
18588 : | KEY
18589 : | KEYS
18590 : | LABEL
18591 : | LANGUAGE
18592 : | LARGE_P
18593 : | LAST_P
18594 : | LATERAL_P
18595 : | LEADING
18596 : | LEAKPROOF
18597 : | LEAST
18598 : | LEFT
18599 : | LEVEL
18600 : | LIKE
18601 : | LISTEN
18602 : | LOAD
18603 : | LOCAL
18604 : | LOCALTIME
18605 : | LOCALTIMESTAMP
18606 : | LOCATION
18607 : | LOCK_P
18608 : | LOCKED
18609 : | LOGGED
18610 : | LSN_P
18611 : | MAPPING
18612 : | MATCH
18613 : | MATCHED
18614 : | MATERIALIZED
18615 : | MAXVALUE
18616 : | MERGE
18617 : | MERGE_ACTION
18618 : | METHOD
18619 : | MINVALUE
18620 : | MODE
18621 : | MOVE
18622 : | NAME_P
18623 : | NAMES
18624 : | NATIONAL
18625 : | NATURAL
18626 : | NCHAR
18627 : | NESTED
18628 : | NEW
18629 : | NEXT
18630 : | NFC
18631 : | NFD
18632 : | NFKC
18633 : | NFKD
18634 : | NO
18635 : | NONE
18636 : | NORMALIZE
18637 : | NORMALIZED
18638 : | NOT
18639 : | NOTHING
18640 : | NOTIFY
18641 : | NOWAIT
18642 : | NULL_P
18643 : | NULLIF
18644 : | NULLS_P
18645 : | NUMERIC
18646 : | OBJECT_P
18647 : | OBJECTS_P
18648 : | OF
18649 : | OFF
18650 : | OIDS
18651 : | OLD
18652 : | OMIT
18653 : | ONLY
18654 : | OPERATOR
18655 : | OPTION
18656 : | OPTIONS
18657 : | OR
18658 : | ORDINALITY
18659 : | OTHERS
18660 : | OUT_P
18661 : | OUTER_P
18662 : | OVERLAY
18663 : | OVERRIDING
18664 : | OWNED
18665 : | OWNER
18666 : | PARALLEL
18667 : | PARAMETER
18668 : | PARSER
18669 : | PARTIAL
18670 : | PARTITION
18671 : | PASSING
18672 : | PASSWORD
18673 : | PATH
18674 : | PERIOD
18675 : | PLACING
18676 : | PLAN
18677 : | PLANS
18678 : | POLICY
18679 : | POSITION
18680 : | PRECEDING
18681 : | PREPARE
18682 : | PREPARED
18683 : | PRESERVE
18684 : | PRIMARY
18685 : | PRIOR
18686 : | PRIVILEGES
18687 : | PROCEDURAL
18688 : | PROCEDURE
18689 : | PROCEDURES
18690 : | PROGRAM
18691 : | PUBLICATION
18692 : | QUOTE
18693 : | QUOTES
18694 : | RANGE
18695 : | READ
18696 : | REAL
18697 : | REASSIGN
18698 : | RECURSIVE
18699 : | REF_P
18700 : | REFERENCES
18701 : | REFERENCING
18702 : | REFRESH
18703 : | REINDEX
18704 : | RELATIVE_P
18705 : | RELEASE
18706 : | RENAME
18707 : | REPEATABLE
18708 : | REPLACE
18709 : | REPLICA
18710 : | RESET
18711 : | RESTART
18712 : | RESTRICT
18713 : | RETURN
18714 : | RETURNS
18715 : | REVOKE
18716 : | RIGHT
18717 : | ROLE
18718 : | ROLLBACK
18719 : | ROLLUP
18720 : | ROUTINE
18721 : | ROUTINES
18722 : | ROW
18723 : | ROWS
18724 : | RULE
18725 : | SAVEPOINT
18726 : | SCALAR
18727 : | SCHEMA
18728 : | SCHEMAS
18729 : | SCROLL
18730 : | SEARCH
18731 : | SECURITY
18732 : | SELECT
18733 : | SEQUENCE
18734 : | SEQUENCES
18735 : | SERIALIZABLE
18736 : | SERVER
18737 : | SESSION
18738 : | SESSION_USER
18739 : | SET
18740 : | SETOF
18741 : | SETS
18742 : | SHARE
18743 : | SHOW
18744 : | SIMILAR
18745 : | SIMPLE
18746 : | SKIP
18747 : | SMALLINT
18748 : | SNAPSHOT
18749 : | SOME
18750 : | SOURCE
18751 : | SQL_P
18752 : | STABLE
18753 : | STANDALONE_P
18754 : | START
18755 : | STATEMENT
18756 : | STATISTICS
18757 : | STDIN
18758 : | STDOUT
18759 : | STORAGE
18760 : | STORED
18761 : | STRICT_P
18762 : | STRING_P
18763 : | STRIP_P
18764 : | SUBSCRIPTION
18765 : | SUBSTRING
18766 : | SUPPORT
18767 : | SYMMETRIC
18768 : | SYSID
18769 : | SYSTEM_P
18770 : | SYSTEM_USER
18771 : | TABLE
18772 : | TABLES
18773 : | TABLESAMPLE
18774 : | TABLESPACE
18775 : | TARGET
18776 : | TEMP
18777 : | TEMPLATE
18778 : | TEMPORARY
18779 : | TEXT_P
18780 : | THEN
18781 : | TIES
18782 : | TIME
18783 : | TIMESTAMP
18784 : | TRAILING
18785 : | TRANSACTION
18786 : | TRANSFORM
18787 : | TREAT
18788 : | TRIGGER
18789 : | TRIM
18790 : | TRUE_P
18791 : | TRUNCATE
18792 : | TRUSTED
18793 : | TYPE_P
18794 : | TYPES_P
18795 : | UESCAPE
18796 : | UNBOUNDED
18797 : | UNCOMMITTED
18798 : | UNCONDITIONAL
18799 : | UNENCRYPTED
18800 : | UNIQUE
18801 : | UNKNOWN
18802 : | UNLISTEN
18803 : | UNLOGGED
18804 : | UNTIL
18805 : | UPDATE
18806 : | USER
18807 : | USING
18808 : | VACUUM
18809 : | VALID
18810 : | VALIDATE
18811 : | VALIDATOR
18812 : | VALUE_P
18813 : | VALUES
18814 : | VARCHAR
18815 : | VARIADIC
18816 : | VERBOSE
18817 : | VERSION_P
18818 : | VIEW
18819 : | VIEWS
18820 : | VIRTUAL
18821 : | VOLATILE
18822 : | WAIT
18823 : | WHEN
18824 : | WHITESPACE_P
18825 : | WORK
18826 : | WRAPPER
18827 : | WRITE
18828 : | XML_P
18829 : | XMLATTRIBUTES
18830 : | XMLCONCAT
18831 : | XMLELEMENT
18832 : | XMLEXISTS
18833 : | XMLFOREST
18834 : | XMLNAMESPACES
18835 : | XMLPARSE
18836 : | XMLPI
18837 : | XMLROOT
18838 : | XMLSERIALIZE
18839 : | XMLTABLE
18840 : | YES_P
18841 : | ZONE
18842 : ;
18843 :
18844 : %%
18845 :
18846 : /*
18847 : * The signature of this function is required by bison. However, we
18848 : * ignore the passed yylloc and instead use the last token position
18849 : * available from the scanner.
18850 : */
18851 : static void
18852 706 : base_yyerror(YYLTYPE *yylloc, core_yyscan_t yyscanner, const char *msg)
18853 : {
18854 706 : parser_yyerror(msg);
18855 : }
18856 :
18857 : static RawStmt *
18858 820408 : makeRawStmt(Node *stmt, int stmt_location)
18859 : {
18860 820408 : RawStmt *rs = makeNode(RawStmt);
18861 :
18862 820408 : rs->stmt = stmt;
18863 820408 : rs->stmt_location = stmt_location;
18864 820408 : rs->stmt_len = 0; /* might get changed later */
18865 820408 : return rs;
18866 : }
18867 :
18868 : /* Adjust a RawStmt to reflect that it doesn't run to the end of the string */
18869 : static void
18870 589376 : updateRawStmtEnd(RawStmt *rs, int end_location)
18871 : {
18872 : /*
18873 : * If we already set the length, don't change it. This is for situations
18874 : * like "select foo ;; select bar" where the same statement will be last
18875 : * in the string for more than one semicolon.
18876 : */
18877 589376 : if (rs->stmt_len > 0)
18878 642 : return;
18879 :
18880 : /* OK, update length of RawStmt */
18881 588734 : rs->stmt_len = end_location - rs->stmt_location;
18882 : }
18883 :
18884 : static Node *
18885 1810894 : makeColumnRef(char *colname, List *indirection,
18886 : int location, core_yyscan_t yyscanner)
18887 : {
18888 : /*
18889 : * Generate a ColumnRef node, with an A_Indirection node added if there is
18890 : * any subscripting in the specified indirection list. However, any field
18891 : * selection at the start of the indirection list must be transposed into
18892 : * the "fields" part of the ColumnRef node.
18893 : */
18894 1810894 : ColumnRef *c = makeNode(ColumnRef);
18895 1810894 : int nfields = 0;
18896 : ListCell *l;
18897 :
18898 1810894 : c->location = location;
18899 2866010 : foreach(l, indirection)
18900 : {
18901 1065048 : if (IsA(lfirst(l), A_Indices))
18902 : {
18903 9932 : A_Indirection *i = makeNode(A_Indirection);
18904 :
18905 9932 : if (nfields == 0)
18906 : {
18907 : /* easy case - all indirection goes to A_Indirection */
18908 7214 : c->fields = list_make1(makeString(colname));
18909 7214 : i->indirection = check_indirection(indirection, yyscanner);
18910 : }
18911 : else
18912 : {
18913 : /* got to split the list in two */
18914 2718 : i->indirection = check_indirection(list_copy_tail(indirection,
18915 : nfields),
18916 : yyscanner);
18917 2718 : indirection = list_truncate(indirection, nfields);
18918 2718 : c->fields = lcons(makeString(colname), indirection);
18919 : }
18920 9932 : i->arg = (Node *) c;
18921 9932 : return (Node *) i;
18922 : }
18923 1055116 : else if (IsA(lfirst(l), A_Star))
18924 : {
18925 : /* We only allow '*' at the end of a ColumnRef */
18926 5564 : if (lnext(indirection, l) != NULL)
18927 0 : parser_yyerror("improper use of \"*\"");
18928 : }
18929 1055116 : nfields++;
18930 : }
18931 : /* No subscripting, so all indirection gets added to field list */
18932 1800962 : c->fields = lcons(makeString(colname), indirection);
18933 1800962 : return (Node *) c;
18934 : }
18935 :
18936 : static Node *
18937 315114 : makeTypeCast(Node *arg, TypeName *typename, int location)
18938 : {
18939 315114 : TypeCast *n = makeNode(TypeCast);
18940 :
18941 315114 : n->arg = arg;
18942 315114 : n->typeName = typename;
18943 315114 : n->location = location;
18944 315114 : return (Node *) n;
18945 : }
18946 :
18947 : static Node *
18948 16334 : makeStringConstCast(char *str, int location, TypeName *typename)
18949 : {
18950 16334 : Node *s = makeStringConst(str, location);
18951 :
18952 16334 : return makeTypeCast(s, typename, -1);
18953 : }
18954 :
18955 : static Node *
18956 390338 : makeIntConst(int val, int location)
18957 : {
18958 390338 : A_Const *n = makeNode(A_Const);
18959 :
18960 390338 : n->val.ival.type = T_Integer;
18961 390338 : n->val.ival.ival = val;
18962 390338 : n->location = location;
18963 :
18964 390338 : return (Node *) n;
18965 : }
18966 :
18967 : static Node *
18968 12146 : makeFloatConst(char *str, int location)
18969 : {
18970 12146 : A_Const *n = makeNode(A_Const);
18971 :
18972 12146 : n->val.fval.type = T_Float;
18973 12146 : n->val.fval.fval = str;
18974 12146 : n->location = location;
18975 :
18976 12146 : return (Node *) n;
18977 : }
18978 :
18979 : static Node *
18980 67410 : makeBoolAConst(bool state, int location)
18981 : {
18982 67410 : A_Const *n = makeNode(A_Const);
18983 :
18984 67410 : n->val.boolval.type = T_Boolean;
18985 67410 : n->val.boolval.boolval = state;
18986 67410 : n->location = location;
18987 :
18988 67410 : return (Node *) n;
18989 : }
18990 :
18991 : static Node *
18992 4056 : makeBitStringConst(char *str, int location)
18993 : {
18994 4056 : A_Const *n = makeNode(A_Const);
18995 :
18996 4056 : n->val.bsval.type = T_BitString;
18997 4056 : n->val.bsval.bsval = str;
18998 4056 : n->location = location;
18999 :
19000 4056 : return (Node *) n;
19001 : }
19002 :
19003 : static Node *
19004 67698 : makeNullAConst(int location)
19005 : {
19006 67698 : A_Const *n = makeNode(A_Const);
19007 :
19008 67698 : n->isnull = true;
19009 67698 : n->location = location;
19010 :
19011 67698 : return (Node *) n;
19012 : }
19013 :
19014 : static Node *
19015 5402 : makeAConst(Node *v, int location)
19016 : {
19017 : Node *n;
19018 :
19019 5402 : switch (v->type)
19020 : {
19021 218 : case T_Float:
19022 218 : n = makeFloatConst(castNode(Float, v)->fval, location);
19023 218 : break;
19024 :
19025 5184 : case T_Integer:
19026 5184 : n = makeIntConst(castNode(Integer, v)->ival, location);
19027 5184 : break;
19028 :
19029 0 : default:
19030 : /* currently not used */
19031 : Assert(false);
19032 0 : n = NULL;
19033 : }
19034 :
19035 5402 : return n;
19036 : }
19037 :
19038 : /* makeRoleSpec
19039 : * Create a RoleSpec with the given type
19040 : */
19041 : static RoleSpec *
19042 33824 : makeRoleSpec(RoleSpecType type, int location)
19043 : {
19044 33824 : RoleSpec *spec = makeNode(RoleSpec);
19045 :
19046 33824 : spec->roletype = type;
19047 33824 : spec->location = location;
19048 :
19049 33824 : return spec;
19050 : }
19051 :
19052 : /* check_qualified_name --- check the result of qualified_name production
19053 : *
19054 : * It's easiest to let the grammar production for qualified_name allow
19055 : * subscripts and '*', which we then must reject here.
19056 : */
19057 : static void
19058 244218 : check_qualified_name(List *names, core_yyscan_t yyscanner)
19059 : {
19060 : ListCell *i;
19061 :
19062 488436 : foreach(i, names)
19063 : {
19064 244218 : if (!IsA(lfirst(i), String))
19065 0 : parser_yyerror("syntax error");
19066 : }
19067 244218 : }
19068 :
19069 : /* check_func_name --- check the result of func_name production
19070 : *
19071 : * It's easiest to let the grammar production for func_name allow subscripts
19072 : * and '*', which we then must reject here.
19073 : */
19074 : static List *
19075 126426 : check_func_name(List *names, core_yyscan_t yyscanner)
19076 : {
19077 : ListCell *i;
19078 :
19079 379278 : foreach(i, names)
19080 : {
19081 252852 : if (!IsA(lfirst(i), String))
19082 0 : parser_yyerror("syntax error");
19083 : }
19084 126426 : return names;
19085 : }
19086 :
19087 : /* check_indirection --- check the result of indirection production
19088 : *
19089 : * We only allow '*' at the end of the list, but it's hard to enforce that
19090 : * in the grammar, so do it here.
19091 : */
19092 : static List *
19093 83286 : check_indirection(List *indirection, core_yyscan_t yyscanner)
19094 : {
19095 : ListCell *l;
19096 :
19097 110958 : foreach(l, indirection)
19098 : {
19099 27672 : if (IsA(lfirst(l), A_Star))
19100 : {
19101 1488 : if (lnext(indirection, l) != NULL)
19102 0 : parser_yyerror("improper use of \"*\"");
19103 : }
19104 : }
19105 83286 : return indirection;
19106 : }
19107 :
19108 : /* extractArgTypes()
19109 : * Given a list of FunctionParameter nodes, extract a list of just the
19110 : * argument types (TypeNames) for input parameters only. This is what
19111 : * is needed to look up an existing function, which is what is wanted by
19112 : * the productions that use this call.
19113 : */
19114 : static List *
19115 18414 : extractArgTypes(List *parameters)
19116 : {
19117 18414 : List *result = NIL;
19118 : ListCell *i;
19119 :
19120 42320 : foreach(i, parameters)
19121 : {
19122 23906 : FunctionParameter *p = (FunctionParameter *) lfirst(i);
19123 :
19124 23906 : if (p->mode != FUNC_PARAM_OUT && p->mode != FUNC_PARAM_TABLE)
19125 23750 : result = lappend(result, p->argType);
19126 : }
19127 18414 : return result;
19128 : }
19129 :
19130 : /* extractAggrArgTypes()
19131 : * As above, but work from the output of the aggr_args production.
19132 : */
19133 : static List *
19134 362 : extractAggrArgTypes(List *aggrargs)
19135 : {
19136 : Assert(list_length(aggrargs) == 2);
19137 362 : return extractArgTypes((List *) linitial(aggrargs));
19138 : }
19139 :
19140 : /* makeOrderedSetArgs()
19141 : * Build the result of the aggr_args production (which see the comments for).
19142 : * This handles only the case where both given lists are nonempty, so that
19143 : * we have to deal with multiple VARIADIC arguments.
19144 : */
19145 : static List *
19146 32 : makeOrderedSetArgs(List *directargs, List *orderedargs,
19147 : core_yyscan_t yyscanner)
19148 : {
19149 32 : FunctionParameter *lastd = (FunctionParameter *) llast(directargs);
19150 : Integer *ndirectargs;
19151 :
19152 : /* No restriction unless last direct arg is VARIADIC */
19153 32 : if (lastd->mode == FUNC_PARAM_VARIADIC)
19154 : {
19155 16 : FunctionParameter *firsto = (FunctionParameter *) linitial(orderedargs);
19156 :
19157 : /*
19158 : * We ignore the names, though the aggr_arg production allows them; it
19159 : * doesn't allow default values, so those need not be checked.
19160 : */
19161 16 : if (list_length(orderedargs) != 1 ||
19162 16 : firsto->mode != FUNC_PARAM_VARIADIC ||
19163 16 : !equal(lastd->argType, firsto->argType))
19164 0 : ereport(ERROR,
19165 : (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
19166 : errmsg("an ordered-set aggregate with a VARIADIC direct argument must have one VARIADIC aggregated argument of the same data type"),
19167 : parser_errposition(firsto->location)));
19168 :
19169 : /* OK, drop the duplicate VARIADIC argument from the internal form */
19170 16 : orderedargs = NIL;
19171 : }
19172 :
19173 : /* don't merge into the next line, as list_concat changes directargs */
19174 32 : ndirectargs = makeInteger(list_length(directargs));
19175 :
19176 32 : return list_make2(list_concat(directargs, orderedargs),
19177 : ndirectargs);
19178 : }
19179 :
19180 : /* insertSelectOptions()
19181 : * Insert ORDER BY, etc into an already-constructed SelectStmt.
19182 : *
19183 : * This routine is just to avoid duplicating code in SelectStmt productions.
19184 : */
19185 : static void
19186 83618 : insertSelectOptions(SelectStmt *stmt,
19187 : List *sortClause, List *lockingClause,
19188 : SelectLimit *limitClause,
19189 : WithClause *withClause,
19190 : core_yyscan_t yyscanner)
19191 : {
19192 : Assert(IsA(stmt, SelectStmt));
19193 :
19194 : /*
19195 : * Tests here are to reject constructs like
19196 : * (SELECT foo ORDER BY bar) ORDER BY baz
19197 : */
19198 83618 : if (sortClause)
19199 : {
19200 74038 : if (stmt->sortClause)
19201 0 : ereport(ERROR,
19202 : (errcode(ERRCODE_SYNTAX_ERROR),
19203 : errmsg("multiple ORDER BY clauses not allowed"),
19204 : parser_errposition(exprLocation((Node *) sortClause))));
19205 74038 : stmt->sortClause = sortClause;
19206 : }
19207 : /* We can handle multiple locking clauses, though */
19208 83618 : stmt->lockingClause = list_concat(stmt->lockingClause, lockingClause);
19209 83618 : if (limitClause && limitClause->limitOffset)
19210 : {
19211 862 : if (stmt->limitOffset)
19212 0 : ereport(ERROR,
19213 : (errcode(ERRCODE_SYNTAX_ERROR),
19214 : errmsg("multiple OFFSET clauses not allowed"),
19215 : parser_errposition(limitClause->offsetLoc)));
19216 862 : stmt->limitOffset = limitClause->limitOffset;
19217 : }
19218 83618 : if (limitClause && limitClause->limitCount)
19219 : {
19220 4724 : if (stmt->limitCount)
19221 0 : ereport(ERROR,
19222 : (errcode(ERRCODE_SYNTAX_ERROR),
19223 : errmsg("multiple LIMIT clauses not allowed"),
19224 : parser_errposition(limitClause->countLoc)));
19225 4724 : stmt->limitCount = limitClause->limitCount;
19226 : }
19227 83618 : if (limitClause)
19228 : {
19229 : /* If there was a conflict, we must have detected it above */
19230 : Assert(!stmt->limitOption);
19231 5192 : if (!stmt->sortClause && limitClause->limitOption == LIMIT_OPTION_WITH_TIES)
19232 6 : ereport(ERROR,
19233 : (errcode(ERRCODE_SYNTAX_ERROR),
19234 : errmsg("WITH TIES cannot be specified without ORDER BY clause"),
19235 : parser_errposition(limitClause->optionLoc)));
19236 5186 : if (limitClause->limitOption == LIMIT_OPTION_WITH_TIES && stmt->lockingClause)
19237 : {
19238 : ListCell *lc;
19239 :
19240 6 : foreach(lc, stmt->lockingClause)
19241 : {
19242 6 : LockingClause *lock = lfirst_node(LockingClause, lc);
19243 :
19244 6 : if (lock->waitPolicy == LockWaitSkip)
19245 6 : ereport(ERROR,
19246 : (errcode(ERRCODE_SYNTAX_ERROR),
19247 : errmsg("%s and %s options cannot be used together",
19248 : "SKIP LOCKED", "WITH TIES"),
19249 : parser_errposition(limitClause->optionLoc)));
19250 : }
19251 : }
19252 5180 : stmt->limitOption = limitClause->limitOption;
19253 : }
19254 83606 : if (withClause)
19255 : {
19256 2886 : if (stmt->withClause)
19257 0 : ereport(ERROR,
19258 : (errcode(ERRCODE_SYNTAX_ERROR),
19259 : errmsg("multiple WITH clauses not allowed"),
19260 : parser_errposition(exprLocation((Node *) withClause))));
19261 2886 : stmt->withClause = withClause;
19262 : }
19263 83606 : }
19264 :
19265 : static Node *
19266 19730 : makeSetOp(SetOperation op, bool all, Node *larg, Node *rarg)
19267 : {
19268 19730 : SelectStmt *n = makeNode(SelectStmt);
19269 :
19270 19730 : n->op = op;
19271 19730 : n->all = all;
19272 19730 : n->larg = (SelectStmt *) larg;
19273 19730 : n->rarg = (SelectStmt *) rarg;
19274 19730 : return (Node *) n;
19275 : }
19276 :
19277 : /* SystemFuncName()
19278 : * Build a properly-qualified reference to a built-in function.
19279 : */
19280 : List *
19281 19482 : SystemFuncName(char *name)
19282 : {
19283 19482 : return list_make2(makeString("pg_catalog"), makeString(name));
19284 : }
19285 :
19286 : /* SystemTypeName()
19287 : * Build a properly-qualified reference to a built-in type.
19288 : *
19289 : * typmod is defaulted, but may be changed afterwards by caller.
19290 : * Likewise for the location.
19291 : */
19292 : TypeName *
19293 122522 : SystemTypeName(char *name)
19294 : {
19295 122522 : return makeTypeNameFromNameList(list_make2(makeString("pg_catalog"),
19296 : makeString(name)));
19297 : }
19298 :
19299 : /* doNegate()
19300 : * Handle negation of a numeric constant.
19301 : *
19302 : * Formerly, we did this here because the optimizer couldn't cope with
19303 : * indexquals that looked like "var = -4" --- it wants "var = const"
19304 : * and a unary minus operator applied to a constant didn't qualify.
19305 : * As of Postgres 7.0, that problem doesn't exist anymore because there
19306 : * is a constant-subexpression simplifier in the optimizer. However,
19307 : * there's still a good reason for doing this here, which is that we can
19308 : * postpone committing to a particular internal representation for simple
19309 : * negative constants. It's better to leave "-123.456" in string form
19310 : * until we know what the desired type is.
19311 : */
19312 : static Node *
19313 9286 : doNegate(Node *n, int location)
19314 : {
19315 9286 : if (IsA(n, A_Const))
19316 : {
19317 8276 : A_Const *con = (A_Const *) n;
19318 :
19319 : /* report the constant's location as that of the '-' sign */
19320 8276 : con->location = location;
19321 :
19322 8276 : if (IsA(&con->val, Integer))
19323 : {
19324 7318 : con->val.ival.ival = -con->val.ival.ival;
19325 7318 : return n;
19326 : }
19327 958 : if (IsA(&con->val, Float))
19328 : {
19329 958 : doNegateFloat(&con->val.fval);
19330 958 : return n;
19331 : }
19332 : }
19333 :
19334 1010 : return (Node *) makeSimpleA_Expr(AEXPR_OP, "-", NULL, n, location);
19335 : }
19336 :
19337 : static void
19338 978 : doNegateFloat(Float *v)
19339 : {
19340 978 : char *oldval = v->fval;
19341 :
19342 978 : if (*oldval == '+')
19343 0 : oldval++;
19344 978 : if (*oldval == '-')
19345 0 : v->fval = oldval + 1; /* just strip the '-' */
19346 : else
19347 978 : v->fval = psprintf("-%s", oldval);
19348 978 : }
19349 :
19350 : static Node *
19351 232640 : makeAndExpr(Node *lexpr, Node *rexpr, int location)
19352 : {
19353 : /* Flatten "a AND b AND c ..." to a single BoolExpr on sight */
19354 232640 : if (IsA(lexpr, BoolExpr))
19355 : {
19356 110450 : BoolExpr *blexpr = (BoolExpr *) lexpr;
19357 :
19358 110450 : if (blexpr->boolop == AND_EXPR)
19359 : {
19360 107922 : blexpr->args = lappend(blexpr->args, rexpr);
19361 107922 : return (Node *) blexpr;
19362 : }
19363 : }
19364 124718 : return (Node *) makeBoolExpr(AND_EXPR, list_make2(lexpr, rexpr), location);
19365 : }
19366 :
19367 : static Node *
19368 16048 : makeOrExpr(Node *lexpr, Node *rexpr, int location)
19369 : {
19370 : /* Flatten "a OR b OR c ..." to a single BoolExpr on sight */
19371 16048 : if (IsA(lexpr, BoolExpr))
19372 : {
19373 5650 : BoolExpr *blexpr = (BoolExpr *) lexpr;
19374 :
19375 5650 : if (blexpr->boolop == OR_EXPR)
19376 : {
19377 4138 : blexpr->args = lappend(blexpr->args, rexpr);
19378 4138 : return (Node *) blexpr;
19379 : }
19380 : }
19381 11910 : return (Node *) makeBoolExpr(OR_EXPR, list_make2(lexpr, rexpr), location);
19382 : }
19383 :
19384 : static Node *
19385 16316 : makeNotExpr(Node *expr, int location)
19386 : {
19387 16316 : return (Node *) makeBoolExpr(NOT_EXPR, list_make1(expr), location);
19388 : }
19389 :
19390 : static Node *
19391 8248 : makeAArrayExpr(List *elements, int location, int location_end)
19392 : {
19393 8248 : A_ArrayExpr *n = makeNode(A_ArrayExpr);
19394 :
19395 8248 : n->elements = elements;
19396 8248 : n->location = location;
19397 8248 : n->list_start = location;
19398 8248 : n->list_end = location_end;
19399 8248 : return (Node *) n;
19400 : }
19401 :
19402 : static Node *
19403 2760 : makeSQLValueFunction(SQLValueFunctionOp op, int32 typmod, int location)
19404 : {
19405 2760 : SQLValueFunction *svf = makeNode(SQLValueFunction);
19406 :
19407 2760 : svf->op = op;
19408 : /* svf->type will be filled during parse analysis */
19409 2760 : svf->typmod = typmod;
19410 2760 : svf->location = location;
19411 2760 : return (Node *) svf;
19412 : }
19413 :
19414 : static Node *
19415 596 : makeXmlExpr(XmlExprOp op, char *name, List *named_args, List *args,
19416 : int location)
19417 : {
19418 596 : XmlExpr *x = makeNode(XmlExpr);
19419 :
19420 596 : x->op = op;
19421 596 : x->name = name;
19422 :
19423 : /*
19424 : * named_args is a list of ResTarget; it'll be split apart into separate
19425 : * expression and name lists in transformXmlExpr().
19426 : */
19427 596 : x->named_args = named_args;
19428 596 : x->arg_names = NIL;
19429 596 : x->args = args;
19430 : /* xmloption, if relevant, must be filled in by caller */
19431 : /* type and typmod will be filled in during parse analysis */
19432 596 : x->type = InvalidOid; /* marks the node as not analyzed */
19433 596 : x->location = location;
19434 596 : return (Node *) x;
19435 : }
19436 :
19437 : /*
19438 : * Merge the input and output parameters of a table function.
19439 : */
19440 : static List *
19441 194 : mergeTableFuncParameters(List *func_args, List *columns, core_yyscan_t yyscanner)
19442 : {
19443 : ListCell *lc;
19444 :
19445 : /* Explicit OUT and INOUT parameters shouldn't be used in this syntax */
19446 394 : foreach(lc, func_args)
19447 : {
19448 200 : FunctionParameter *p = (FunctionParameter *) lfirst(lc);
19449 :
19450 200 : if (p->mode != FUNC_PARAM_DEFAULT &&
19451 0 : p->mode != FUNC_PARAM_IN &&
19452 0 : p->mode != FUNC_PARAM_VARIADIC)
19453 0 : ereport(ERROR,
19454 : (errcode(ERRCODE_SYNTAX_ERROR),
19455 : errmsg("OUT and INOUT arguments aren't allowed in TABLE functions"),
19456 : parser_errposition(p->location)));
19457 : }
19458 :
19459 194 : return list_concat(func_args, columns);
19460 : }
19461 :
19462 : /*
19463 : * Determine return type of a TABLE function. A single result column
19464 : * returns setof that column's type; otherwise return setof record.
19465 : */
19466 : static TypeName *
19467 194 : TableFuncTypeName(List *columns)
19468 : {
19469 : TypeName *result;
19470 :
19471 194 : if (list_length(columns) == 1)
19472 : {
19473 62 : FunctionParameter *p = (FunctionParameter *) linitial(columns);
19474 :
19475 62 : result = copyObject(p->argType);
19476 : }
19477 : else
19478 132 : result = SystemTypeName("record");
19479 :
19480 194 : result->setof = true;
19481 :
19482 194 : return result;
19483 : }
19484 :
19485 : /*
19486 : * Convert a list of (dotted) names to a RangeVar (like
19487 : * makeRangeVarFromNameList, but with position support). The
19488 : * "AnyName" refers to the any_name production in the grammar.
19489 : */
19490 : static RangeVar *
19491 4736 : makeRangeVarFromAnyName(List *names, int position, core_yyscan_t yyscanner)
19492 : {
19493 4736 : RangeVar *r = makeNode(RangeVar);
19494 :
19495 4736 : switch (list_length(names))
19496 : {
19497 4646 : case 1:
19498 4646 : r->catalogname = NULL;
19499 4646 : r->schemaname = NULL;
19500 4646 : r->relname = strVal(linitial(names));
19501 4646 : break;
19502 90 : case 2:
19503 90 : r->catalogname = NULL;
19504 90 : r->schemaname = strVal(linitial(names));
19505 90 : r->relname = strVal(lsecond(names));
19506 90 : break;
19507 0 : case 3:
19508 0 : r->catalogname = strVal(linitial(names));
19509 0 : r->schemaname = strVal(lsecond(names));
19510 0 : r->relname = strVal(lthird(names));
19511 0 : break;
19512 0 : default:
19513 0 : ereport(ERROR,
19514 : (errcode(ERRCODE_SYNTAX_ERROR),
19515 : errmsg("improper qualified name (too many dotted names): %s",
19516 : NameListToString(names)),
19517 : parser_errposition(position)));
19518 : break;
19519 : }
19520 :
19521 4736 : r->relpersistence = RELPERSISTENCE_PERMANENT;
19522 4736 : r->location = position;
19523 :
19524 4736 : return r;
19525 : }
19526 :
19527 : /*
19528 : * Convert a relation_name with name and namelist to a RangeVar using
19529 : * makeRangeVar.
19530 : */
19531 : static RangeVar *
19532 244218 : makeRangeVarFromQualifiedName(char *name, List *namelist, int location,
19533 : core_yyscan_t yyscanner)
19534 : {
19535 : RangeVar *r;
19536 :
19537 244218 : check_qualified_name(namelist, yyscanner);
19538 244218 : r = makeRangeVar(NULL, NULL, location);
19539 :
19540 244218 : switch (list_length(namelist))
19541 : {
19542 244218 : case 1:
19543 244218 : r->catalogname = NULL;
19544 244218 : r->schemaname = name;
19545 244218 : r->relname = strVal(linitial(namelist));
19546 244218 : break;
19547 0 : case 2:
19548 0 : r->catalogname = name;
19549 0 : r->schemaname = strVal(linitial(namelist));
19550 0 : r->relname = strVal(lsecond(namelist));
19551 0 : break;
19552 0 : default:
19553 0 : ereport(ERROR,
19554 : errcode(ERRCODE_SYNTAX_ERROR),
19555 : errmsg("improper qualified name (too many dotted names): %s",
19556 : NameListToString(lcons(makeString(name), namelist))),
19557 : parser_errposition(location));
19558 : break;
19559 : }
19560 :
19561 244218 : return r;
19562 : }
19563 :
19564 : /* Separate Constraint nodes from COLLATE clauses in a ColQualList */
19565 : static void
19566 70662 : SplitColQualList(List *qualList,
19567 : List **constraintList, CollateClause **collClause,
19568 : core_yyscan_t yyscanner)
19569 : {
19570 : ListCell *cell;
19571 :
19572 70662 : *collClause = NULL;
19573 91012 : foreach(cell, qualList)
19574 : {
19575 20350 : Node *n = (Node *) lfirst(cell);
19576 :
19577 20350 : if (IsA(n, Constraint))
19578 : {
19579 : /* keep it in list */
19580 19576 : continue;
19581 : }
19582 774 : if (IsA(n, CollateClause))
19583 : {
19584 774 : CollateClause *c = (CollateClause *) n;
19585 :
19586 774 : if (*collClause)
19587 0 : ereport(ERROR,
19588 : (errcode(ERRCODE_SYNTAX_ERROR),
19589 : errmsg("multiple COLLATE clauses not allowed"),
19590 : parser_errposition(c->location)));
19591 774 : *collClause = c;
19592 : }
19593 : else
19594 0 : elog(ERROR, "unexpected node type %d", (int) n->type);
19595 : /* remove non-Constraint nodes from qualList */
19596 774 : qualList = foreach_delete_current(qualList, cell);
19597 : }
19598 70662 : *constraintList = qualList;
19599 70662 : }
19600 :
19601 : /*
19602 : * Process result of ConstraintAttributeSpec, and set appropriate bool flags
19603 : * in the output command node. Pass NULL for any flags the particular
19604 : * command doesn't support.
19605 : */
19606 : static void
19607 17878 : processCASbits(int cas_bits, int location, const char *constrType,
19608 : bool *deferrable, bool *initdeferred, bool *is_enforced,
19609 : bool *not_valid, bool *no_inherit, core_yyscan_t yyscanner)
19610 : {
19611 : /* defaults */
19612 17878 : if (deferrable)
19613 15818 : *deferrable = false;
19614 17878 : if (initdeferred)
19615 15818 : *initdeferred = false;
19616 17878 : if (not_valid)
19617 3886 : *not_valid = false;
19618 17878 : if (is_enforced)
19619 3414 : *is_enforced = true;
19620 :
19621 17878 : if (cas_bits & (CAS_DEFERRABLE | CAS_INITIALLY_DEFERRED))
19622 : {
19623 230 : if (deferrable)
19624 230 : *deferrable = true;
19625 : else
19626 0 : ereport(ERROR,
19627 : (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
19628 : /* translator: %s is CHECK, UNIQUE, or similar */
19629 : errmsg("%s constraints cannot be marked DEFERRABLE",
19630 : constrType),
19631 : parser_errposition(location)));
19632 : }
19633 :
19634 17878 : if (cas_bits & CAS_INITIALLY_DEFERRED)
19635 : {
19636 146 : if (initdeferred)
19637 146 : *initdeferred = true;
19638 : else
19639 0 : ereport(ERROR,
19640 : (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
19641 : /* translator: %s is CHECK, UNIQUE, or similar */
19642 : errmsg("%s constraints cannot be marked DEFERRABLE",
19643 : constrType),
19644 : parser_errposition(location)));
19645 : }
19646 :
19647 17878 : if (cas_bits & CAS_NOT_VALID)
19648 : {
19649 714 : if (not_valid)
19650 714 : *not_valid = true;
19651 : else
19652 0 : ereport(ERROR,
19653 : (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
19654 : /* translator: %s is CHECK, UNIQUE, or similar */
19655 : errmsg("%s constraints cannot be marked NOT VALID",
19656 : constrType),
19657 : parser_errposition(location)));
19658 : }
19659 :
19660 17878 : if (cas_bits & CAS_NO_INHERIT)
19661 : {
19662 244 : if (no_inherit)
19663 244 : *no_inherit = true;
19664 : else
19665 0 : ereport(ERROR,
19666 : (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
19667 : /* translator: %s is CHECK, UNIQUE, or similar */
19668 : errmsg("%s constraints cannot be marked NO INHERIT",
19669 : constrType),
19670 : parser_errposition(location)));
19671 : }
19672 :
19673 17878 : if (cas_bits & CAS_NOT_ENFORCED)
19674 : {
19675 156 : if (is_enforced)
19676 150 : *is_enforced = false;
19677 : else
19678 6 : ereport(ERROR,
19679 : (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
19680 : /* translator: %s is CHECK, UNIQUE, or similar */
19681 : errmsg("%s constraints cannot be marked NOT ENFORCED",
19682 : constrType),
19683 : parser_errposition(location)));
19684 :
19685 : /*
19686 : * NB: The validated status is irrelevant when the constraint is set to
19687 : * NOT ENFORCED, but for consistency, it should be set accordingly.
19688 : * This ensures that if the constraint is later changed to ENFORCED, it
19689 : * will automatically be in the correct NOT VALIDATED state.
19690 : */
19691 150 : if (not_valid)
19692 114 : *not_valid = true;
19693 : }
19694 :
19695 17872 : if (cas_bits & CAS_ENFORCED)
19696 : {
19697 102 : if (is_enforced)
19698 96 : *is_enforced = true;
19699 : else
19700 6 : ereport(ERROR,
19701 : (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
19702 : /* translator: %s is CHECK, UNIQUE, or similar */
19703 : errmsg("%s constraints cannot be marked ENFORCED",
19704 : constrType),
19705 : parser_errposition(location)));
19706 : }
19707 17866 : }
19708 :
19709 : /*
19710 : * Parse a user-supplied partition strategy string into parse node
19711 : * PartitionStrategy representation, or die trying.
19712 : */
19713 : static PartitionStrategy
19714 5166 : parsePartitionStrategy(char *strategy, int location, core_yyscan_t yyscanner)
19715 : {
19716 5166 : if (pg_strcasecmp(strategy, "list") == 0)
19717 2576 : return PARTITION_STRATEGY_LIST;
19718 2590 : else if (pg_strcasecmp(strategy, "range") == 0)
19719 2318 : return PARTITION_STRATEGY_RANGE;
19720 272 : else if (pg_strcasecmp(strategy, "hash") == 0)
19721 266 : return PARTITION_STRATEGY_HASH;
19722 :
19723 6 : ereport(ERROR,
19724 : (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
19725 : errmsg("unrecognized partitioning strategy \"%s\"", strategy),
19726 : parser_errposition(location)));
19727 : return PARTITION_STRATEGY_LIST; /* keep compiler quiet */
19728 :
19729 : }
19730 :
19731 : /*
19732 : * Process all_objects_list to set all_tables and/or all_sequences.
19733 : * Also, checks if the pub_object_type has been specified more than once.
19734 : */
19735 : static void
19736 152 : preprocess_pub_all_objtype_list(List *all_objects_list, bool *all_tables,
19737 : bool *all_sequences, core_yyscan_t yyscanner)
19738 : {
19739 152 : if (!all_objects_list)
19740 0 : return;
19741 :
19742 152 : *all_tables = false;
19743 152 : *all_sequences = false;
19744 :
19745 470 : foreach_ptr(PublicationAllObjSpec, obj, all_objects_list)
19746 : {
19747 190 : if (obj->pubobjtype == PUBLICATION_ALL_TABLES)
19748 : {
19749 132 : if (*all_tables)
19750 6 : ereport(ERROR,
19751 : errcode(ERRCODE_SYNTAX_ERROR),
19752 : errmsg("invalid publication object list"),
19753 : errdetail("ALL TABLES can be specified only once."),
19754 : parser_errposition(obj->location));
19755 :
19756 126 : *all_tables = true;
19757 : }
19758 58 : else if (obj->pubobjtype == PUBLICATION_ALL_SEQUENCES)
19759 : {
19760 58 : if (*all_sequences)
19761 6 : ereport(ERROR,
19762 : errcode(ERRCODE_SYNTAX_ERROR),
19763 : errmsg("invalid publication object list"),
19764 : errdetail("ALL SEQUENCES can be specified only once."),
19765 : parser_errposition(obj->location));
19766 :
19767 52 : *all_sequences = true;
19768 : }
19769 : }
19770 : }
19771 :
19772 : /*
19773 : * Process pubobjspec_list to check for errors in any of the objects and
19774 : * convert PUBLICATIONOBJ_CONTINUATION into appropriate PublicationObjSpecType.
19775 : */
19776 : static void
19777 1648 : preprocess_pubobj_list(List *pubobjspec_list, core_yyscan_t yyscanner)
19778 : {
19779 : ListCell *cell;
19780 : PublicationObjSpec *pubobj;
19781 1648 : PublicationObjSpecType prevobjtype = PUBLICATIONOBJ_CONTINUATION;
19782 :
19783 1648 : if (!pubobjspec_list)
19784 0 : return;
19785 :
19786 1648 : pubobj = (PublicationObjSpec *) linitial(pubobjspec_list);
19787 1648 : if (pubobj->pubobjtype == PUBLICATIONOBJ_CONTINUATION)
19788 12 : ereport(ERROR,
19789 : errcode(ERRCODE_SYNTAX_ERROR),
19790 : errmsg("invalid publication object list"),
19791 : errdetail("One of TABLE or TABLES IN SCHEMA must be specified before a standalone table or schema name."),
19792 : parser_errposition(pubobj->location));
19793 :
19794 3502 : foreach(cell, pubobjspec_list)
19795 : {
19796 1890 : pubobj = (PublicationObjSpec *) lfirst(cell);
19797 :
19798 1890 : if (pubobj->pubobjtype == PUBLICATIONOBJ_CONTINUATION)
19799 174 : pubobj->pubobjtype = prevobjtype;
19800 :
19801 1890 : if (pubobj->pubobjtype == PUBLICATIONOBJ_TABLE)
19802 : {
19803 : /* relation name or pubtable must be set for this type of object */
19804 1446 : if (!pubobj->name && !pubobj->pubtable)
19805 6 : ereport(ERROR,
19806 : errcode(ERRCODE_SYNTAX_ERROR),
19807 : errmsg("invalid table name"),
19808 : parser_errposition(pubobj->location));
19809 :
19810 1440 : if (pubobj->name)
19811 : {
19812 : /* convert it to PublicationTable */
19813 58 : PublicationTable *pubtable = makeNode(PublicationTable);
19814 :
19815 58 : pubtable->relation =
19816 58 : makeRangeVar(NULL, pubobj->name, pubobj->location);
19817 58 : pubobj->pubtable = pubtable;
19818 58 : pubobj->name = NULL;
19819 : }
19820 : }
19821 444 : else if (pubobj->pubobjtype == PUBLICATIONOBJ_TABLES_IN_SCHEMA ||
19822 24 : pubobj->pubobjtype == PUBLICATIONOBJ_TABLES_IN_CUR_SCHEMA)
19823 : {
19824 : /* WHERE clause is not allowed on a schema object */
19825 444 : if (pubobj->pubtable && pubobj->pubtable->whereClause)
19826 6 : ereport(ERROR,
19827 : errcode(ERRCODE_SYNTAX_ERROR),
19828 : errmsg("WHERE clause not allowed for schema"),
19829 : parser_errposition(pubobj->location));
19830 :
19831 : /* Column list is not allowed on a schema object */
19832 438 : if (pubobj->pubtable && pubobj->pubtable->columns)
19833 6 : ereport(ERROR,
19834 : errcode(ERRCODE_SYNTAX_ERROR),
19835 : errmsg("column specification not allowed for schema"),
19836 : parser_errposition(pubobj->location));
19837 :
19838 : /*
19839 : * We can distinguish between the different type of schema objects
19840 : * based on whether name and pubtable is set.
19841 : */
19842 432 : if (pubobj->name)
19843 402 : pubobj->pubobjtype = PUBLICATIONOBJ_TABLES_IN_SCHEMA;
19844 30 : else if (!pubobj->name && !pubobj->pubtable)
19845 24 : pubobj->pubobjtype = PUBLICATIONOBJ_TABLES_IN_CUR_SCHEMA;
19846 : else
19847 6 : ereport(ERROR,
19848 : errcode(ERRCODE_SYNTAX_ERROR),
19849 : errmsg("invalid schema name"),
19850 : parser_errposition(pubobj->location));
19851 : }
19852 :
19853 1866 : prevobjtype = pubobj->pubobjtype;
19854 : }
19855 : }
19856 :
19857 : /*----------
19858 : * Recursive view transformation
19859 : *
19860 : * Convert
19861 : *
19862 : * CREATE RECURSIVE VIEW relname (aliases) AS query
19863 : *
19864 : * to
19865 : *
19866 : * CREATE VIEW relname (aliases) AS
19867 : * WITH RECURSIVE relname (aliases) AS (query)
19868 : * SELECT aliases FROM relname
19869 : *
19870 : * Actually, just the WITH ... part, which is then inserted into the original
19871 : * view definition as the query.
19872 : * ----------
19873 : */
19874 : static Node *
19875 14 : makeRecursiveViewSelect(char *relname, List *aliases, Node *query)
19876 : {
19877 14 : SelectStmt *s = makeNode(SelectStmt);
19878 14 : WithClause *w = makeNode(WithClause);
19879 14 : CommonTableExpr *cte = makeNode(CommonTableExpr);
19880 14 : List *tl = NIL;
19881 : ListCell *lc;
19882 :
19883 : /* create common table expression */
19884 14 : cte->ctename = relname;
19885 14 : cte->aliascolnames = aliases;
19886 14 : cte->ctematerialized = CTEMaterializeDefault;
19887 14 : cte->ctequery = query;
19888 14 : cte->location = -1;
19889 :
19890 : /* create WITH clause and attach CTE */
19891 14 : w->recursive = true;
19892 14 : w->ctes = list_make1(cte);
19893 14 : w->location = -1;
19894 :
19895 : /*
19896 : * create target list for the new SELECT from the alias list of the
19897 : * recursive view specification
19898 : */
19899 28 : foreach(lc, aliases)
19900 : {
19901 14 : ResTarget *rt = makeNode(ResTarget);
19902 :
19903 14 : rt->name = NULL;
19904 14 : rt->indirection = NIL;
19905 14 : rt->val = makeColumnRef(strVal(lfirst(lc)), NIL, -1, 0);
19906 14 : rt->location = -1;
19907 :
19908 14 : tl = lappend(tl, rt);
19909 : }
19910 :
19911 : /*
19912 : * create new SELECT combining WITH clause, target list, and fake FROM
19913 : * clause
19914 : */
19915 14 : s->withClause = w;
19916 14 : s->targetList = tl;
19917 14 : s->fromClause = list_make1(makeRangeVar(NULL, relname, -1));
19918 :
19919 14 : return (Node *) s;
19920 : }
19921 :
19922 : /* parser_init()
19923 : * Initialize to parse one query string
19924 : */
19925 : void
19926 772942 : parser_init(base_yy_extra_type *yyext)
19927 : {
19928 772942 : yyext->parsetree = NIL; /* in case grammar forgets to set it */
19929 772942 : }
|