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 : List *list;
124 : } GroupClause;
125 :
126 : /* Private structs for the result of key_actions and key_action productions */
127 : typedef struct KeyAction
128 : {
129 : char action;
130 : List *cols;
131 : } KeyAction;
132 :
133 : typedef struct KeyActions
134 : {
135 : KeyAction *updateAction;
136 : KeyAction *deleteAction;
137 : } KeyActions;
138 :
139 : /* ConstraintAttributeSpec yields an integer bitmask of these flags: */
140 : #define CAS_NOT_DEFERRABLE 0x01
141 : #define CAS_DEFERRABLE 0x02
142 : #define CAS_INITIALLY_IMMEDIATE 0x04
143 : #define CAS_INITIALLY_DEFERRED 0x08
144 : #define CAS_NOT_VALID 0x10
145 : #define CAS_NO_INHERIT 0x20
146 : #define CAS_NOT_ENFORCED 0x40
147 : #define CAS_ENFORCED 0x80
148 :
149 :
150 : #define parser_yyerror(msg) scanner_yyerror(msg, yyscanner)
151 : #define parser_errposition(pos) scanner_errposition(pos, yyscanner)
152 :
153 : static void base_yyerror(YYLTYPE *yylloc, core_yyscan_t yyscanner,
154 : const char *msg);
155 : static RawStmt *makeRawStmt(Node *stmt, int stmt_location);
156 : static void updateRawStmtEnd(RawStmt *rs, int end_location);
157 : static Node *makeColumnRef(char *colname, List *indirection,
158 : int location, core_yyscan_t yyscanner);
159 : static Node *makeTypeCast(Node *arg, TypeName *typename, int location);
160 : static Node *makeStringConstCast(char *str, int location, TypeName *typename);
161 : static Node *makeIntConst(int val, int location);
162 : static Node *makeFloatConst(char *str, int location);
163 : static Node *makeBoolAConst(bool state, int location);
164 : static Node *makeBitStringConst(char *str, int location);
165 : static Node *makeNullAConst(int location);
166 : static Node *makeAConst(Node *v, int location);
167 : static RoleSpec *makeRoleSpec(RoleSpecType type, int location);
168 : static void check_qualified_name(List *names, core_yyscan_t yyscanner);
169 : static List *check_func_name(List *names, core_yyscan_t yyscanner);
170 : static List *check_indirection(List *indirection, core_yyscan_t yyscanner);
171 : static List *extractArgTypes(List *parameters);
172 : static List *extractAggrArgTypes(List *aggrargs);
173 : static List *makeOrderedSetArgs(List *directargs, List *orderedargs,
174 : core_yyscan_t yyscanner);
175 : static void insertSelectOptions(SelectStmt *stmt,
176 : List *sortClause, List *lockingClause,
177 : SelectLimit *limitClause,
178 : WithClause *withClause,
179 : core_yyscan_t yyscanner);
180 : static Node *makeSetOp(SetOperation op, bool all, Node *larg, Node *rarg);
181 : static Node *doNegate(Node *n, int location);
182 : static void doNegateFloat(Float *v);
183 : static Node *makeAndExpr(Node *lexpr, Node *rexpr, int location);
184 : static Node *makeOrExpr(Node *lexpr, Node *rexpr, int location);
185 : static Node *makeNotExpr(Node *expr, int location);
186 : static Node *makeAArrayExpr(List *elements, int location, int end_location);
187 : static Node *makeSQLValueFunction(SQLValueFunctionOp op, int32 typmod,
188 : int location);
189 : static Node *makeXmlExpr(XmlExprOp op, char *name, List *named_args,
190 : List *args, int location);
191 : static List *mergeTableFuncParameters(List *func_args, List *columns, core_yyscan_t yyscanner);
192 : static TypeName *TableFuncTypeName(List *columns);
193 : static RangeVar *makeRangeVarFromAnyName(List *names, int position, core_yyscan_t yyscanner);
194 : static RangeVar *makeRangeVarFromQualifiedName(char *name, List *namelist, int location,
195 : core_yyscan_t yyscanner);
196 : static void SplitColQualList(List *qualList,
197 : List **constraintList, CollateClause **collClause,
198 : core_yyscan_t yyscanner);
199 : static void processCASbits(int cas_bits, int location, const char *constrType,
200 : bool *deferrable, bool *initdeferred, bool *is_enforced,
201 : bool *not_valid, bool *no_inherit, core_yyscan_t yyscanner);
202 : static PartitionStrategy parsePartitionStrategy(char *strategy, int location,
203 : core_yyscan_t yyscanner);
204 : static void preprocess_pubobj_list(List *pubobjspec_list,
205 : core_yyscan_t yyscanner);
206 : static Node *makeRecursiveViewSelect(char *relname, List *aliases, Node *query);
207 :
208 : %}
209 :
210 : %pure-parser
211 : %expect 0
212 : %name-prefix="base_yy"
213 : %locations
214 :
215 : %parse-param {core_yyscan_t yyscanner}
216 : %lex-param {core_yyscan_t yyscanner}
217 :
218 : %union
219 : {
220 : core_YYSTYPE core_yystype;
221 : /* these fields must match core_YYSTYPE: */
222 : int ival;
223 : char *str;
224 : const char *keyword;
225 :
226 : char chr;
227 : bool boolean;
228 : JoinType jtype;
229 : DropBehavior dbehavior;
230 : OnCommitAction oncommit;
231 : List *list;
232 : Node *node;
233 : ObjectType objtype;
234 : TypeName *typnam;
235 : FunctionParameter *fun_param;
236 : FunctionParameterMode fun_param_mode;
237 : ObjectWithArgs *objwithargs;
238 : DefElem *defelt;
239 : SortBy *sortby;
240 : WindowDef *windef;
241 : JoinExpr *jexpr;
242 : IndexElem *ielem;
243 : StatsElem *selem;
244 : Alias *alias;
245 : RangeVar *range;
246 : IntoClause *into;
247 : WithClause *with;
248 : InferClause *infer;
249 : OnConflictClause *onconflict;
250 : A_Indices *aind;
251 : ResTarget *target;
252 : struct PrivTarget *privtarget;
253 : AccessPriv *accesspriv;
254 : struct ImportQual *importqual;
255 : InsertStmt *istmt;
256 : VariableSetStmt *vsetstmt;
257 : PartitionElem *partelem;
258 : PartitionSpec *partspec;
259 : PartitionBoundSpec *partboundspec;
260 : RoleSpec *rolespec;
261 : PublicationObjSpec *publicationobjectspec;
262 : struct SelectLimit *selectlimit;
263 : SetQuantifier setquantifier;
264 : struct GroupClause *groupclause;
265 : MergeMatchKind mergematch;
266 : MergeWhenClause *mergewhen;
267 : struct KeyActions *keyactions;
268 : struct KeyAction *keyaction;
269 : ReturningClause *retclause;
270 : ReturningOptionKind retoptionkind;
271 : }
272 :
273 : %type <node> stmt toplevel_stmt schema_stmt routine_body_stmt
274 : AlterEventTrigStmt AlterCollationStmt
275 : AlterDatabaseStmt AlterDatabaseSetStmt AlterDomainStmt AlterEnumStmt
276 : AlterFdwStmt AlterForeignServerStmt AlterGroupStmt
277 : AlterObjectDependsStmt AlterObjectSchemaStmt AlterOwnerStmt
278 : AlterOperatorStmt AlterTypeStmt AlterSeqStmt AlterSystemStmt AlterTableStmt
279 : AlterTblSpcStmt AlterExtensionStmt AlterExtensionContentsStmt
280 : AlterCompositeTypeStmt AlterUserMappingStmt
281 : AlterRoleStmt AlterRoleSetStmt AlterPolicyStmt AlterStatsStmt
282 : AlterDefaultPrivilegesStmt DefACLAction
283 : AnalyzeStmt CallStmt ClosePortalStmt ClusterStmt CommentStmt
284 : ConstraintsSetStmt CopyStmt CreateAsStmt CreateCastStmt
285 : CreateDomainStmt CreateExtensionStmt CreateGroupStmt CreateOpClassStmt
286 : CreateOpFamilyStmt AlterOpFamilyStmt CreatePLangStmt
287 : CreateSchemaStmt CreateSeqStmt CreateStmt CreateStatsStmt CreateTableSpaceStmt
288 : CreateFdwStmt CreateForeignServerStmt CreateForeignTableStmt
289 : CreateAssertionStmt CreateTransformStmt CreateTrigStmt CreateEventTrigStmt
290 : CreateUserStmt CreateUserMappingStmt CreateRoleStmt CreatePolicyStmt
291 : CreatedbStmt DeclareCursorStmt DefineStmt DeleteStmt DiscardStmt DoStmt
292 : DropOpClassStmt DropOpFamilyStmt DropStmt
293 : DropCastStmt DropRoleStmt
294 : DropdbStmt DropTableSpaceStmt
295 : DropTransformStmt
296 : DropUserMappingStmt ExplainStmt FetchStmt
297 : GrantStmt GrantRoleStmt ImportForeignSchemaStmt IndexStmt InsertStmt
298 : ListenStmt LoadStmt LockStmt MergeStmt NotifyStmt ExplainableStmt PreparableStmt
299 : CreateFunctionStmt AlterFunctionStmt ReindexStmt RemoveAggrStmt
300 : RemoveFuncStmt RemoveOperStmt RenameStmt ReturnStmt RevokeStmt RevokeRoleStmt
301 : RuleActionStmt RuleActionStmtOrEmpty RuleStmt
302 : SecLabelStmt SelectStmt TransactionStmt TransactionStmtLegacy TruncateStmt
303 : UnlistenStmt UpdateStmt VacuumStmt
304 : VariableResetStmt VariableSetStmt VariableShowStmt
305 : ViewStmt CheckPointStmt CreateConversionStmt
306 : DeallocateStmt PrepareStmt ExecuteStmt
307 : DropOwnedStmt ReassignOwnedStmt
308 : AlterTSConfigurationStmt AlterTSDictionaryStmt
309 : CreateMatViewStmt RefreshMatViewStmt CreateAmStmt
310 : CreatePublicationStmt AlterPublicationStmt
311 : CreateSubscriptionStmt AlterSubscriptionStmt DropSubscriptionStmt
312 :
313 : %type <node> select_no_parens select_with_parens select_clause
314 : simple_select values_clause
315 : PLpgSQL_Expr PLAssignStmt
316 :
317 : %type <str> opt_single_name
318 : %type <list> opt_qualified_name
319 : %type <boolean> opt_concurrently
320 : %type <dbehavior> opt_drop_behavior
321 : %type <list> opt_utility_option_list
322 : %type <list> utility_option_list
323 : %type <defelt> utility_option_elem
324 : %type <str> utility_option_name
325 : %type <node> utility_option_arg
326 :
327 : %type <node> alter_column_default opclass_item opclass_drop alter_using
328 : %type <ival> add_drop opt_asc_desc opt_nulls_order
329 :
330 : %type <node> alter_table_cmd alter_type_cmd opt_collate_clause
331 : replica_identity partition_cmd index_partition_cmd
332 : %type <list> alter_table_cmds alter_type_cmds
333 : %type <list> alter_identity_column_option_list
334 : %type <defelt> alter_identity_column_option
335 : %type <node> set_statistics_value
336 : %type <str> set_access_method_name
337 :
338 : %type <list> createdb_opt_list createdb_opt_items copy_opt_list
339 : transaction_mode_list
340 : create_extension_opt_list alter_extension_opt_list
341 : %type <defelt> createdb_opt_item copy_opt_item
342 : transaction_mode_item
343 : create_extension_opt_item alter_extension_opt_item
344 :
345 : %type <ival> opt_lock lock_type cast_context
346 : %type <defelt> drop_option
347 : %type <boolean> opt_or_replace opt_no
348 : opt_grant_grant_option
349 : opt_nowait opt_if_exists opt_with_data
350 : opt_transaction_chain
351 : %type <list> grant_role_opt_list
352 : %type <defelt> grant_role_opt
353 : %type <node> grant_role_opt_value
354 : %type <ival> opt_nowait_or_skip
355 :
356 : %type <list> OptRoleList AlterOptRoleList
357 : %type <defelt> CreateOptRoleElem AlterOptRoleElem
358 :
359 : %type <str> opt_type
360 : %type <str> foreign_server_version opt_foreign_server_version
361 : %type <str> opt_in_database
362 :
363 : %type <str> parameter_name
364 : %type <list> OptSchemaEltList parameter_name_list
365 :
366 : %type <chr> am_type
367 :
368 : %type <boolean> TriggerForSpec TriggerForType
369 : %type <ival> TriggerActionTime
370 : %type <list> TriggerEvents TriggerOneEvent
371 : %type <node> TriggerFuncArg
372 : %type <node> TriggerWhen
373 : %type <str> TransitionRelName
374 : %type <boolean> TransitionRowOrTable TransitionOldOrNew
375 : %type <node> TriggerTransition
376 :
377 : %type <list> event_trigger_when_list event_trigger_value_list
378 : %type <defelt> event_trigger_when_item
379 : %type <chr> enable_trigger
380 :
381 : %type <str> copy_file_name
382 : access_method_clause attr_name
383 : table_access_method_clause name cursor_name file_name
384 : cluster_index_specification
385 :
386 : %type <list> func_name handler_name qual_Op qual_all_Op subquery_Op
387 : opt_inline_handler opt_validator validator_clause
388 : opt_collate
389 :
390 : %type <range> qualified_name insert_target OptConstrFromTable
391 :
392 : %type <str> all_Op MathOp
393 :
394 : %type <str> row_security_cmd RowSecurityDefaultForCmd
395 : %type <boolean> RowSecurityDefaultPermissive
396 : %type <node> RowSecurityOptionalWithCheck RowSecurityOptionalExpr
397 : %type <list> RowSecurityDefaultToRole RowSecurityOptionalToRole
398 :
399 : %type <str> iso_level opt_encoding
400 : %type <rolespec> grantee
401 : %type <list> grantee_list
402 : %type <accesspriv> privilege
403 : %type <list> privileges privilege_list
404 : %type <privtarget> privilege_target
405 : %type <objwithargs> function_with_argtypes aggregate_with_argtypes operator_with_argtypes
406 : %type <list> function_with_argtypes_list aggregate_with_argtypes_list operator_with_argtypes_list
407 : %type <ival> defacl_privilege_target
408 : %type <defelt> DefACLOption
409 : %type <list> DefACLOptionList
410 : %type <ival> import_qualification_type
411 : %type <importqual> import_qualification
412 : %type <node> vacuum_relation
413 : %type <selectlimit> opt_select_limit select_limit limit_clause
414 :
415 : %type <list> parse_toplevel stmtmulti routine_body_stmt_list
416 : OptTableElementList TableElementList OptInherit definition
417 : OptTypedTableElementList TypedTableElementList
418 : reloptions opt_reloptions
419 : OptWith opt_definition func_args func_args_list
420 : func_args_with_defaults func_args_with_defaults_list
421 : aggr_args aggr_args_list
422 : func_as createfunc_opt_list opt_createfunc_opt_list alterfunc_opt_list
423 : old_aggr_definition old_aggr_list
424 : oper_argtypes RuleActionList RuleActionMulti
425 : opt_column_list columnList opt_name_list
426 : sort_clause opt_sort_clause sortby_list index_params
427 : stats_params
428 : opt_include opt_c_include index_including_params
429 : name_list role_list from_clause from_list opt_array_bounds
430 : qualified_name_list any_name any_name_list type_name_list
431 : any_operator expr_list attrs
432 : distinct_clause opt_distinct_clause
433 : target_list opt_target_list insert_column_list set_target_list
434 : merge_values_clause
435 : set_clause_list set_clause
436 : def_list operator_def_list indirection opt_indirection
437 : reloption_list TriggerFuncArgs opclass_item_list opclass_drop_list
438 : opclass_purpose opt_opfamily transaction_mode_list_or_empty
439 : OptTableFuncElementList TableFuncElementList opt_type_modifiers
440 : prep_type_clause
441 : execute_param_clause using_clause
442 : returning_with_clause returning_options
443 : opt_enum_val_list enum_val_list table_func_column_list
444 : create_generic_options alter_generic_options
445 : relation_expr_list dostmt_opt_list
446 : transform_element_list transform_type_list
447 : TriggerTransitions TriggerReferencing
448 : vacuum_relation_list opt_vacuum_relation_list
449 : drop_option_list pub_obj_list
450 :
451 : %type <retclause> returning_clause
452 : %type <node> returning_option
453 : %type <retoptionkind> returning_option_kind
454 : %type <node> opt_routine_body
455 : %type <groupclause> group_clause
456 : %type <list> group_by_list
457 : %type <node> group_by_item empty_grouping_set rollup_clause cube_clause
458 : %type <node> grouping_sets_clause
459 :
460 : %type <list> opt_fdw_options fdw_options
461 : %type <defelt> fdw_option
462 :
463 : %type <range> OptTempTableName
464 : %type <into> into_clause create_as_target create_mv_target
465 :
466 : %type <defelt> createfunc_opt_item common_func_opt_item dostmt_opt_item
467 : %type <fun_param> func_arg func_arg_with_default table_func_column aggr_arg
468 : %type <fun_param_mode> arg_class
469 : %type <typnam> func_return func_type
470 :
471 : %type <boolean> opt_trusted opt_restart_seqs
472 : %type <ival> OptTemp
473 : %type <ival> OptNoLog
474 : %type <oncommit> OnCommitOption
475 :
476 : %type <ival> for_locking_strength
477 : %type <node> for_locking_item
478 : %type <list> for_locking_clause opt_for_locking_clause for_locking_items
479 : %type <list> locked_rels_list
480 : %type <setquantifier> set_quantifier
481 :
482 : %type <node> join_qual
483 : %type <jtype> join_type
484 :
485 : %type <list> extract_list overlay_list position_list
486 : %type <list> substr_list trim_list
487 : %type <list> opt_interval interval_second
488 : %type <str> unicode_normal_form
489 :
490 : %type <boolean> opt_instead
491 : %type <boolean> opt_unique opt_verbose opt_full
492 : %type <boolean> opt_freeze opt_analyze opt_default
493 : %type <defelt> opt_binary copy_delimiter
494 :
495 : %type <boolean> copy_from opt_program
496 :
497 : %type <ival> event cursor_options opt_hold opt_set_data
498 : %type <objtype> object_type_any_name object_type_name object_type_name_on_any_name
499 : drop_type_name
500 :
501 : %type <node> fetch_args select_limit_value
502 : offset_clause select_offset_value
503 : select_fetch_first_value I_or_F_const
504 : %type <ival> row_or_rows first_or_next
505 :
506 : %type <list> OptSeqOptList SeqOptList OptParenthesizedSeqOptList
507 : %type <defelt> SeqOptElem
508 :
509 : %type <istmt> insert_rest
510 : %type <infer> opt_conf_expr
511 : %type <onconflict> opt_on_conflict
512 : %type <mergewhen> merge_insert merge_update merge_delete
513 :
514 : %type <mergematch> merge_when_tgt_matched merge_when_tgt_not_matched
515 : %type <node> merge_when_clause opt_merge_when_condition
516 : %type <list> merge_when_list
517 :
518 : %type <vsetstmt> generic_set set_rest set_rest_more generic_reset reset_rest
519 : SetResetClause FunctionSetResetClause
520 :
521 : %type <node> TableElement TypedTableElement ConstraintElem DomainConstraintElem TableFuncElement
522 : %type <node> columnDef columnOptions optionalPeriodName
523 : %type <defelt> def_elem reloption_elem old_aggr_elem operator_def_elem
524 : %type <node> def_arg columnElem where_clause where_or_current_clause
525 : a_expr b_expr c_expr AexprConst indirection_el opt_slice_bound
526 : columnref having_clause func_table xmltable array_expr
527 : OptWhereClause operator_def_arg
528 : %type <list> opt_column_and_period_list
529 : %type <list> rowsfrom_item rowsfrom_list opt_col_def_list
530 : %type <boolean> opt_ordinality opt_without_overlaps
531 : %type <list> ExclusionConstraintList ExclusionConstraintElem
532 : %type <list> func_arg_list func_arg_list_opt
533 : %type <node> func_arg_expr
534 : %type <list> row explicit_row implicit_row type_list array_expr_list
535 : %type <node> case_expr case_arg when_clause case_default
536 : %type <list> when_clause_list
537 : %type <node> opt_search_clause opt_cycle_clause
538 : %type <ival> sub_type opt_materialized
539 : %type <node> NumericOnly
540 : %type <list> NumericOnly_list
541 : %type <alias> alias_clause opt_alias_clause opt_alias_clause_for_join_using
542 : %type <list> func_alias_clause
543 : %type <sortby> sortby
544 : %type <ielem> index_elem index_elem_options
545 : %type <selem> stats_param
546 : %type <node> table_ref
547 : %type <jexpr> joined_table
548 : %type <range> relation_expr
549 : %type <range> extended_relation_expr
550 : %type <range> relation_expr_opt_alias
551 : %type <node> tablesample_clause opt_repeatable_clause
552 : %type <target> target_el set_target insert_column_item
553 :
554 : %type <str> generic_option_name
555 : %type <node> generic_option_arg
556 : %type <defelt> generic_option_elem alter_generic_option_elem
557 : %type <list> generic_option_list alter_generic_option_list
558 :
559 : %type <ival> reindex_target_relation reindex_target_all
560 :
561 : %type <node> copy_generic_opt_arg copy_generic_opt_arg_list_item
562 : %type <defelt> copy_generic_opt_elem
563 : %type <list> copy_generic_opt_list copy_generic_opt_arg_list
564 : %type <list> copy_options
565 :
566 : %type <typnam> Typename SimpleTypename ConstTypename
567 : GenericType Numeric opt_float JsonType
568 : Character ConstCharacter
569 : CharacterWithLength CharacterWithoutLength
570 : ConstDatetime ConstInterval
571 : Bit ConstBit BitWithLength BitWithoutLength
572 : %type <str> character
573 : %type <str> extract_arg
574 : %type <boolean> opt_varying opt_timezone opt_no_inherit
575 :
576 : %type <ival> Iconst SignedIconst
577 : %type <str> Sconst comment_text notify_payload
578 : %type <str> RoleId opt_boolean_or_string
579 : %type <list> var_list
580 : %type <str> ColId ColLabel BareColLabel
581 : %type <str> NonReservedWord NonReservedWord_or_Sconst
582 : %type <str> var_name type_function_name param_name
583 : %type <str> createdb_opt_name plassign_target
584 : %type <node> var_value zone_value
585 : %type <rolespec> auth_ident RoleSpec opt_granted_by
586 : %type <publicationobjectspec> PublicationObjSpec
587 :
588 : %type <keyword> unreserved_keyword type_func_name_keyword
589 : %type <keyword> col_name_keyword reserved_keyword
590 : %type <keyword> bare_label_keyword
591 :
592 : %type <node> DomainConstraint TableConstraint TableLikeClause
593 : %type <ival> TableLikeOptionList TableLikeOption
594 : %type <str> column_compression opt_column_compression column_storage opt_column_storage
595 : %type <list> ColQualList
596 : %type <node> ColConstraint ColConstraintElem ConstraintAttr
597 : %type <ival> key_match
598 : %type <keyaction> key_delete key_update key_action
599 : %type <keyactions> key_actions
600 : %type <ival> ConstraintAttributeSpec ConstraintAttributeElem
601 : %type <str> ExistingIndex
602 :
603 : %type <list> constraints_set_list
604 : %type <boolean> constraints_set_mode
605 : %type <str> OptTableSpace OptConsTableSpace
606 : %type <rolespec> OptTableSpaceOwner
607 : %type <ival> opt_check_option
608 :
609 : %type <str> opt_provider security_label
610 :
611 : %type <target> xml_attribute_el
612 : %type <list> xml_attribute_list xml_attributes
613 : %type <node> xml_root_version opt_xml_root_standalone
614 : %type <node> xmlexists_argument
615 : %type <ival> document_or_content
616 : %type <boolean> xml_indent_option xml_whitespace_option
617 : %type <list> xmltable_column_list xmltable_column_option_list
618 : %type <node> xmltable_column_el
619 : %type <defelt> xmltable_column_option_el
620 : %type <list> xml_namespace_list
621 : %type <target> xml_namespace_el
622 :
623 : %type <node> func_application func_expr_common_subexpr
624 : %type <node> func_expr func_expr_windowless
625 : %type <node> common_table_expr
626 : %type <with> with_clause opt_with_clause
627 : %type <list> cte_list
628 :
629 : %type <list> within_group_clause
630 : %type <node> filter_clause
631 : %type <list> window_clause window_definition_list opt_partition_clause
632 : %type <windef> window_definition over_clause window_specification
633 : opt_frame_clause frame_extent frame_bound
634 : %type <ival> opt_window_exclusion_clause
635 : %type <str> opt_existing_window_name
636 : %type <boolean> opt_if_not_exists
637 : %type <boolean> opt_unique_null_treatment
638 : %type <ival> generated_when override_kind opt_virtual_or_stored
639 : %type <partspec> PartitionSpec OptPartitionSpec
640 : %type <partelem> part_elem
641 : %type <list> part_params
642 : %type <partboundspec> PartitionBoundSpec
643 : %type <list> hash_partbound
644 : %type <defelt> hash_partbound_elem
645 :
646 : %type <node> json_format_clause
647 : json_format_clause_opt
648 : json_value_expr
649 : json_returning_clause_opt
650 : json_name_and_value
651 : json_aggregate_func
652 : json_argument
653 : json_behavior
654 : json_on_error_clause_opt
655 : json_table
656 : json_table_column_definition
657 : json_table_column_path_clause_opt
658 : %type <list> json_name_and_value_list
659 : json_value_expr_list
660 : json_array_aggregate_order_by_clause_opt
661 : json_arguments
662 : json_behavior_clause_opt
663 : json_passing_clause_opt
664 : json_table_column_definition_list
665 : %type <str> json_table_path_name_opt
666 : %type <ival> json_behavior_type
667 : json_predicate_type_constraint
668 : json_quotes_clause_opt
669 : json_wrapper_behavior
670 : %type <boolean> json_key_uniqueness_constraint_opt
671 : json_object_constructor_null_clause_opt
672 : json_array_constructor_null_clause_opt
673 :
674 :
675 : /*
676 : * Non-keyword token types. These are hard-wired into the "flex" lexer.
677 : * They must be listed first so that their numeric codes do not depend on
678 : * the set of keywords. PL/pgSQL depends on this so that it can share the
679 : * same lexer. If you add/change tokens here, fix PL/pgSQL to match!
680 : *
681 : * UIDENT and USCONST are reduced to IDENT and SCONST in parser.c, so that
682 : * they need no productions here; but we must assign token codes to them.
683 : *
684 : * DOT_DOT is unused in the core SQL grammar, and so will always provoke
685 : * parse errors. It is needed by PL/pgSQL.
686 : */
687 : %token <str> IDENT UIDENT FCONST SCONST USCONST BCONST XCONST Op
688 : %token <ival> ICONST PARAM
689 : %token TYPECAST DOT_DOT COLON_EQUALS EQUALS_GREATER
690 : %token LESS_EQUALS GREATER_EQUALS NOT_EQUALS
691 :
692 : /*
693 : * If you want to make any keyword changes, update the keyword table in
694 : * src/include/parser/kwlist.h and add new keywords to the appropriate one
695 : * of the reserved-or-not-so-reserved keyword lists, below; search
696 : * this file for "Keyword category lists".
697 : */
698 :
699 : /* ordinary key words in alphabetical order */
700 : %token <keyword> ABORT_P ABSENT ABSOLUTE_P ACCESS ACTION ADD_P ADMIN AFTER
701 : AGGREGATE ALL ALSO ALTER ALWAYS ANALYSE ANALYZE AND ANY ARRAY AS ASC
702 : ASENSITIVE ASSERTION ASSIGNMENT ASYMMETRIC ATOMIC AT ATTACH ATTRIBUTE AUTHORIZATION
703 :
704 : BACKWARD BEFORE BEGIN_P BETWEEN BIGINT BINARY BIT
705 : BOOLEAN_P BOTH BREADTH BY
706 :
707 : CACHE CALL CALLED CASCADE CASCADED CASE CAST CATALOG_P CHAIN CHAR_P
708 : CHARACTER CHARACTERISTICS CHECK CHECKPOINT CLASS CLOSE
709 : CLUSTER COALESCE COLLATE COLLATION COLUMN COLUMNS COMMENT COMMENTS COMMIT
710 : COMMITTED COMPRESSION CONCURRENTLY CONDITIONAL CONFIGURATION CONFLICT
711 : CONNECTION CONSTRAINT CONSTRAINTS CONTENT_P CONTINUE_P CONVERSION_P COPY
712 : COST CREATE CROSS CSV CUBE CURRENT_P
713 : CURRENT_CATALOG CURRENT_DATE CURRENT_ROLE CURRENT_SCHEMA
714 : CURRENT_TIME CURRENT_TIMESTAMP CURRENT_USER CURSOR CYCLE
715 :
716 : DATA_P DATABASE DAY_P DEALLOCATE DEC DECIMAL_P DECLARE DEFAULT DEFAULTS
717 : DEFERRABLE DEFERRED DEFINER DELETE_P DELIMITER DELIMITERS DEPENDS DEPTH DESC
718 : DETACH DICTIONARY DISABLE_P DISCARD DISTINCT DO DOCUMENT_P DOMAIN_P
719 : DOUBLE_P DROP
720 :
721 : EACH ELSE EMPTY_P ENABLE_P ENCODING ENCRYPTED END_P ENFORCED ENUM_P ERROR_P
722 : ESCAPE EVENT EXCEPT EXCLUDE EXCLUDING EXCLUSIVE EXECUTE EXISTS EXPLAIN
723 : EXPRESSION EXTENSION EXTERNAL EXTRACT
724 :
725 : FALSE_P FAMILY FETCH FILTER FINALIZE FIRST_P FLOAT_P FOLLOWING FOR
726 : FORCE FOREIGN FORMAT FORWARD FREEZE FROM FULL FUNCTION FUNCTIONS
727 :
728 : GENERATED GLOBAL GRANT GRANTED GREATEST GROUP_P GROUPING GROUPS
729 :
730 : HANDLER HAVING HEADER_P HOLD HOUR_P
731 :
732 : IDENTITY_P IF_P ILIKE IMMEDIATE IMMUTABLE IMPLICIT_P IMPORT_P IN_P INCLUDE
733 : INCLUDING INCREMENT INDENT INDEX INDEXES INHERIT INHERITS INITIALLY INLINE_P
734 : INNER_P INOUT INPUT_P INSENSITIVE INSERT INSTEAD INT_P INTEGER
735 : INTERSECT INTERVAL INTO INVOKER IS ISNULL ISOLATION
736 :
737 : JOIN JSON JSON_ARRAY JSON_ARRAYAGG JSON_EXISTS JSON_OBJECT JSON_OBJECTAGG
738 : JSON_QUERY JSON_SCALAR JSON_SERIALIZE JSON_TABLE JSON_VALUE
739 :
740 : KEEP KEY KEYS
741 :
742 : LABEL LANGUAGE LARGE_P LAST_P LATERAL_P
743 : LEADING LEAKPROOF LEAST LEFT LEVEL LIKE LIMIT LISTEN LOAD LOCAL
744 : LOCALTIME LOCALTIMESTAMP LOCATION LOCK_P LOCKED LOGGED
745 :
746 : MAPPING MATCH MATCHED MATERIALIZED MAXVALUE MERGE MERGE_ACTION METHOD
747 : MINUTE_P MINVALUE MODE MONTH_P MOVE
748 :
749 : NAME_P NAMES NATIONAL NATURAL NCHAR NESTED NEW NEXT NFC NFD NFKC NFKD NO
750 : NONE NORMALIZE NORMALIZED
751 : NOT NOTHING NOTIFY NOTNULL NOWAIT NULL_P NULLIF
752 : NULLS_P NUMERIC
753 :
754 : OBJECT_P OBJECTS_P OF OFF OFFSET OIDS OLD OMIT ON ONLY OPERATOR OPTION OPTIONS OR
755 : ORDER ORDINALITY OTHERS OUT_P OUTER_P
756 : OVER OVERLAPS OVERLAY OVERRIDING OWNED OWNER
757 :
758 : PARALLEL PARAMETER PARSER PARTIAL PARTITION PASSING PASSWORD PATH
759 : PERIOD PLACING PLAN PLANS POLICY
760 : POSITION PRECEDING PRECISION PRESERVE PREPARE PREPARED PRIMARY
761 : PRIOR PRIVILEGES PROCEDURAL PROCEDURE PROCEDURES PROGRAM PUBLICATION
762 :
763 : QUOTE QUOTES
764 :
765 : RANGE READ REAL REASSIGN RECURSIVE REF_P REFERENCES REFERENCING
766 : REFRESH REINDEX RELATIVE_P RELEASE RENAME REPEATABLE REPLACE REPLICA
767 : RESET RESTART RESTRICT RETURN RETURNING RETURNS REVOKE RIGHT ROLE ROLLBACK ROLLUP
768 : ROUTINE ROUTINES ROW ROWS RULE
769 :
770 : SAVEPOINT SCALAR SCHEMA SCHEMAS SCROLL SEARCH SECOND_P SECURITY SELECT
771 : SEQUENCE SEQUENCES
772 : SERIALIZABLE SERVER SESSION SESSION_USER SET SETS SETOF SHARE SHOW
773 : SIMILAR SIMPLE SKIP SMALLINT SNAPSHOT SOME SOURCE SQL_P STABLE STANDALONE_P
774 : START STATEMENT STATISTICS STDIN STDOUT STORAGE STORED STRICT_P STRING_P STRIP_P
775 : SUBSCRIPTION SUBSTRING SUPPORT SYMMETRIC SYSID SYSTEM_P SYSTEM_USER
776 :
777 : TABLE TABLES TABLESAMPLE TABLESPACE TARGET TEMP TEMPLATE TEMPORARY TEXT_P THEN
778 : TIES TIME TIMESTAMP TO TRAILING TRANSACTION TRANSFORM
779 : TREAT TRIGGER TRIM TRUE_P
780 : TRUNCATE TRUSTED TYPE_P TYPES_P
781 :
782 : UESCAPE UNBOUNDED UNCONDITIONAL UNCOMMITTED UNENCRYPTED UNION UNIQUE UNKNOWN
783 : UNLISTEN UNLOGGED UNTIL UPDATE USER USING
784 :
785 : VACUUM VALID VALIDATE VALIDATOR VALUE_P VALUES VARCHAR VARIADIC VARYING
786 : VERBOSE VERSION_P VIEW VIEWS VIRTUAL VOLATILE
787 :
788 : WHEN WHERE WHITESPACE_P WINDOW WITH WITHIN WITHOUT WORK WRAPPER WRITE
789 :
790 : XML_P XMLATTRIBUTES XMLCONCAT XMLELEMENT XMLEXISTS XMLFOREST XMLNAMESPACES
791 : XMLPARSE XMLPI XMLROOT XMLSERIALIZE XMLTABLE
792 :
793 : YEAR_P YES_P
794 :
795 : ZONE
796 :
797 : /*
798 : * The grammar thinks these are keywords, but they are not in the kwlist.h
799 : * list and so can never be entered directly. The filter in parser.c
800 : * creates these tokens when required (based on looking one token ahead).
801 : *
802 : * NOT_LA exists so that productions such as NOT LIKE can be given the same
803 : * precedence as LIKE; otherwise they'd effectively have the same precedence
804 : * as NOT, at least with respect to their left-hand subexpression.
805 : * FORMAT_LA, NULLS_LA, WITH_LA, and WITHOUT_LA are needed to make the grammar
806 : * LALR(1).
807 : */
808 : %token FORMAT_LA NOT_LA NULLS_LA WITH_LA WITHOUT_LA
809 :
810 : /*
811 : * The grammar likewise thinks these tokens are keywords, but they are never
812 : * generated by the scanner. Rather, they can be injected by parser.c as
813 : * the initial token of the string (using the lookahead-token mechanism
814 : * implemented there). This provides a way to tell the grammar to parse
815 : * something other than the usual list of SQL commands.
816 : */
817 : %token MODE_TYPE_NAME
818 : %token MODE_PLPGSQL_EXPR
819 : %token MODE_PLPGSQL_ASSIGN1
820 : %token MODE_PLPGSQL_ASSIGN2
821 : %token MODE_PLPGSQL_ASSIGN3
822 :
823 :
824 : /* Precedence: lowest to highest */
825 : %left UNION EXCEPT
826 : %left INTERSECT
827 : %left OR
828 : %left AND
829 : %right NOT
830 : %nonassoc IS ISNULL NOTNULL /* IS sets precedence for IS NULL, etc */
831 : %nonassoc '<' '>' '=' LESS_EQUALS GREATER_EQUALS NOT_EQUALS
832 : %nonassoc BETWEEN IN_P LIKE ILIKE SIMILAR NOT_LA
833 : %nonassoc ESCAPE /* ESCAPE must be just above LIKE/ILIKE/SIMILAR */
834 :
835 : /*
836 : * Sometimes it is necessary to assign precedence to keywords that are not
837 : * really part of the operator hierarchy, in order to resolve grammar
838 : * ambiguities. It's best to avoid doing so whenever possible, because such
839 : * assignments have global effect and may hide ambiguities besides the one
840 : * you intended to solve. (Attaching a precedence to a single rule with
841 : * %prec is far safer and should be preferred.) If you must give precedence
842 : * to a new keyword, try very hard to give it the same precedence as IDENT.
843 : * If the keyword has IDENT's precedence then it clearly acts the same as
844 : * non-keywords and other similar keywords, thus reducing the risk of
845 : * unexpected precedence effects.
846 : *
847 : * We used to need to assign IDENT an explicit precedence just less than Op,
848 : * to support target_el without AS. While that's not really necessary since
849 : * we removed postfix operators, we continue to do so because it provides a
850 : * reference point for a precedence level that we can assign to other
851 : * keywords that lack a natural precedence level.
852 : *
853 : * We need to do this for PARTITION, RANGE, ROWS, and GROUPS to support
854 : * opt_existing_window_name (see comment there).
855 : *
856 : * The frame_bound productions UNBOUNDED PRECEDING and UNBOUNDED FOLLOWING
857 : * are even messier: since UNBOUNDED is an unreserved keyword (per spec!),
858 : * there is no principled way to distinguish these from the productions
859 : * a_expr PRECEDING/FOLLOWING. We hack this up by giving UNBOUNDED slightly
860 : * lower precedence than PRECEDING and FOLLOWING. At present this doesn't
861 : * appear to cause UNBOUNDED to be treated differently from other unreserved
862 : * keywords anywhere else in the grammar, but it's definitely risky. We can
863 : * blame any funny behavior of UNBOUNDED on the SQL standard, though.
864 : *
865 : * To support CUBE and ROLLUP in GROUP BY without reserving them, we give them
866 : * an explicit priority lower than '(', so that a rule with CUBE '(' will shift
867 : * rather than reducing a conflicting rule that takes CUBE as a function name.
868 : * Using the same precedence as IDENT seems right for the reasons given above.
869 : *
870 : * SET is likewise assigned the same precedence as IDENT, to support the
871 : * relation_expr_opt_alias production (see comment there).
872 : *
873 : * KEYS, OBJECT_P, SCALAR, VALUE_P, WITH, and WITHOUT are similarly assigned
874 : * the same precedence as IDENT. This allows resolving conflicts in the
875 : * json_predicate_type_constraint and json_key_uniqueness_constraint_opt
876 : * productions (see comments there).
877 : *
878 : * Like the UNBOUNDED PRECEDING/FOLLOWING case, NESTED is assigned a lower
879 : * precedence than PATH to fix ambiguity in the json_table production.
880 : */
881 : %nonassoc UNBOUNDED NESTED /* ideally would have same precedence as IDENT */
882 : %nonassoc IDENT PARTITION RANGE ROWS GROUPS PRECEDING FOLLOWING CUBE ROLLUP
883 : SET KEYS OBJECT_P SCALAR VALUE_P WITH WITHOUT PATH
884 : %left Op OPERATOR /* multi-character ops and user-defined operators */
885 : %left '+' '-'
886 : %left '*' '/' '%'
887 : %left '^'
888 : /* Unary Operators */
889 : %left AT /* sets precedence for AT TIME ZONE, AT LOCAL */
890 : %left COLLATE
891 : %right UMINUS
892 : %left '[' ']'
893 : %left '(' ')'
894 : %left TYPECAST
895 : %left '.'
896 : /*
897 : * These might seem to be low-precedence, but actually they are not part
898 : * of the arithmetic hierarchy at all in their use as JOIN operators.
899 : * We make them high-precedence to support their use as function names.
900 : * They wouldn't be given a precedence at all, were it not that we need
901 : * left-associativity among the JOIN rules themselves.
902 : */
903 : %left JOIN CROSS LEFT FULL RIGHT INNER_P NATURAL
904 :
905 : %%
906 :
907 : /*
908 : * The target production for the whole parse.
909 : *
910 : * Ordinarily we parse a list of statements, but if we see one of the
911 : * special MODE_XXX symbols as first token, we parse something else.
912 : * The options here correspond to enum RawParseMode, which see for details.
913 : */
914 : parse_toplevel:
915 : stmtmulti
916 : {
917 709668 : pg_yyget_extra(yyscanner)->parsetree = $1;
918 : (void) yynerrs; /* suppress compiler warning */
919 : }
920 : | MODE_TYPE_NAME Typename
921 : {
922 9652 : pg_yyget_extra(yyscanner)->parsetree = list_make1($2);
923 : }
924 : | MODE_PLPGSQL_EXPR PLpgSQL_Expr
925 : {
926 32966 : pg_yyget_extra(yyscanner)->parsetree =
927 32966 : list_make1(makeRawStmt($2, @2));
928 : }
929 : | MODE_PLPGSQL_ASSIGN1 PLAssignStmt
930 : {
931 6342 : PLAssignStmt *n = (PLAssignStmt *) $2;
932 :
933 6342 : n->nnames = 1;
934 6342 : pg_yyget_extra(yyscanner)->parsetree =
935 6342 : list_make1(makeRawStmt((Node *) n, @2));
936 : }
937 : | MODE_PLPGSQL_ASSIGN2 PLAssignStmt
938 : {
939 674 : PLAssignStmt *n = (PLAssignStmt *) $2;
940 :
941 674 : n->nnames = 2;
942 674 : pg_yyget_extra(yyscanner)->parsetree =
943 674 : list_make1(makeRawStmt((Node *) n, @2));
944 : }
945 : | MODE_PLPGSQL_ASSIGN3 PLAssignStmt
946 : {
947 28 : PLAssignStmt *n = (PLAssignStmt *) $2;
948 :
949 28 : n->nnames = 3;
950 28 : pg_yyget_extra(yyscanner)->parsetree =
951 28 : list_make1(makeRawStmt((Node *) n, @2));
952 : }
953 : ;
954 :
955 : /*
956 : * At top level, we wrap each stmt with a RawStmt node carrying start location
957 : * and length of the stmt's text.
958 : * We also take care to discard empty statements entirely (which among other
959 : * things dodges the problem of assigning them a location).
960 : */
961 : stmtmulti: stmtmulti ';' toplevel_stmt
962 : {
963 578724 : if ($1 != NIL)
964 : {
965 : /* update length of previous stmt */
966 578160 : updateRawStmtEnd(llast_node(RawStmt, $1), @2);
967 : }
968 578724 : if ($3 != NULL)
969 58078 : $$ = lappend($1, makeRawStmt($3, @3));
970 : else
971 520646 : $$ = $1;
972 : }
973 : | toplevel_stmt
974 : {
975 709676 : if ($1 != NULL)
976 708362 : $$ = list_make1(makeRawStmt($1, @1));
977 : else
978 1314 : $$ = NIL;
979 : }
980 : ;
981 :
982 : /*
983 : * toplevel_stmt includes BEGIN and END. stmt does not include them, because
984 : * those words have different meanings in function bodies.
985 : */
986 : toplevel_stmt:
987 : stmt
988 : | TransactionStmtLegacy
989 : ;
990 :
991 : stmt:
992 : AlterEventTrigStmt
993 : | AlterCollationStmt
994 : | AlterDatabaseStmt
995 : | AlterDatabaseSetStmt
996 : | AlterDefaultPrivilegesStmt
997 : | AlterDomainStmt
998 : | AlterEnumStmt
999 : | AlterExtensionStmt
1000 : | AlterExtensionContentsStmt
1001 : | AlterFdwStmt
1002 : | AlterForeignServerStmt
1003 : | AlterFunctionStmt
1004 : | AlterGroupStmt
1005 : | AlterObjectDependsStmt
1006 : | AlterObjectSchemaStmt
1007 : | AlterOwnerStmt
1008 : | AlterOperatorStmt
1009 : | AlterTypeStmt
1010 : | AlterPolicyStmt
1011 : | AlterSeqStmt
1012 : | AlterSystemStmt
1013 : | AlterTableStmt
1014 : | AlterTblSpcStmt
1015 : | AlterCompositeTypeStmt
1016 : | AlterPublicationStmt
1017 : | AlterRoleSetStmt
1018 : | AlterRoleStmt
1019 : | AlterSubscriptionStmt
1020 : | AlterStatsStmt
1021 : | AlterTSConfigurationStmt
1022 : | AlterTSDictionaryStmt
1023 : | AlterUserMappingStmt
1024 : | AnalyzeStmt
1025 : | CallStmt
1026 : | CheckPointStmt
1027 : | ClosePortalStmt
1028 : | ClusterStmt
1029 : | CommentStmt
1030 : | ConstraintsSetStmt
1031 : | CopyStmt
1032 : | CreateAmStmt
1033 : | CreateAsStmt
1034 : | CreateAssertionStmt
1035 : | CreateCastStmt
1036 : | CreateConversionStmt
1037 : | CreateDomainStmt
1038 : | CreateExtensionStmt
1039 : | CreateFdwStmt
1040 : | CreateForeignServerStmt
1041 : | CreateForeignTableStmt
1042 : | CreateFunctionStmt
1043 : | CreateGroupStmt
1044 : | CreateMatViewStmt
1045 : | CreateOpClassStmt
1046 : | CreateOpFamilyStmt
1047 : | CreatePublicationStmt
1048 : | AlterOpFamilyStmt
1049 : | CreatePolicyStmt
1050 : | CreatePLangStmt
1051 : | CreateSchemaStmt
1052 : | CreateSeqStmt
1053 : | CreateStmt
1054 : | CreateSubscriptionStmt
1055 : | CreateStatsStmt
1056 : | CreateTableSpaceStmt
1057 : | CreateTransformStmt
1058 : | CreateTrigStmt
1059 : | CreateEventTrigStmt
1060 : | CreateRoleStmt
1061 : | CreateUserStmt
1062 : | CreateUserMappingStmt
1063 : | CreatedbStmt
1064 : | DeallocateStmt
1065 : | DeclareCursorStmt
1066 : | DefineStmt
1067 : | DeleteStmt
1068 : | DiscardStmt
1069 : | DoStmt
1070 : | DropCastStmt
1071 : | DropOpClassStmt
1072 : | DropOpFamilyStmt
1073 : | DropOwnedStmt
1074 : | DropStmt
1075 : | DropSubscriptionStmt
1076 : | DropTableSpaceStmt
1077 : | DropTransformStmt
1078 : | DropRoleStmt
1079 : | DropUserMappingStmt
1080 : | DropdbStmt
1081 : | ExecuteStmt
1082 : | ExplainStmt
1083 : | FetchStmt
1084 : | GrantStmt
1085 : | GrantRoleStmt
1086 : | ImportForeignSchemaStmt
1087 : | IndexStmt
1088 : | InsertStmt
1089 : | ListenStmt
1090 : | RefreshMatViewStmt
1091 : | LoadStmt
1092 : | LockStmt
1093 : | MergeStmt
1094 : | NotifyStmt
1095 : | PrepareStmt
1096 : | ReassignOwnedStmt
1097 : | ReindexStmt
1098 : | RemoveAggrStmt
1099 : | RemoveFuncStmt
1100 : | RemoveOperStmt
1101 : | RenameStmt
1102 : | RevokeStmt
1103 : | RevokeRoleStmt
1104 : | RuleStmt
1105 : | SecLabelStmt
1106 : | SelectStmt
1107 : | TransactionStmt
1108 : | TruncateStmt
1109 : | UnlistenStmt
1110 : | UpdateStmt
1111 : | VacuumStmt
1112 : | VariableResetStmt
1113 : | VariableSetStmt
1114 : | VariableShowStmt
1115 : | ViewStmt
1116 : | /*EMPTY*/
1117 521978 : { $$ = NULL; }
1118 : ;
1119 :
1120 : /*
1121 : * Generic supporting productions for DDL
1122 : */
1123 : opt_single_name:
1124 5380 : ColId { $$ = $1; }
1125 1530 : | /* EMPTY */ { $$ = NULL; }
1126 : ;
1127 :
1128 : opt_qualified_name:
1129 1828 : any_name { $$ = $1; }
1130 15176 : | /*EMPTY*/ { $$ = NIL; }
1131 : ;
1132 :
1133 : opt_concurrently:
1134 1066 : CONCURRENTLY { $$ = true; }
1135 7604 : | /*EMPTY*/ { $$ = false; }
1136 : ;
1137 :
1138 : opt_drop_behavior:
1139 1960 : CASCADE { $$ = DROP_CASCADE; }
1140 170 : | RESTRICT { $$ = DROP_RESTRICT; }
1141 38810 : | /* EMPTY */ { $$ = DROP_RESTRICT; /* default */ }
1142 : ;
1143 :
1144 : opt_utility_option_list:
1145 366 : '(' utility_option_list ')' { $$ = $2; }
1146 5702 : | /* EMPTY */ { $$ = NULL; }
1147 : ;
1148 :
1149 : utility_option_list:
1150 : utility_option_elem
1151 : {
1152 22004 : $$ = list_make1($1);
1153 : }
1154 : | utility_option_list ',' utility_option_elem
1155 : {
1156 12558 : $$ = lappend($1, $3);
1157 : }
1158 : ;
1159 :
1160 : utility_option_elem:
1161 : utility_option_name utility_option_arg
1162 : {
1163 34562 : $$ = makeDefElem($1, $2, @1);
1164 : }
1165 : ;
1166 :
1167 : utility_option_name:
1168 30768 : NonReservedWord { $$ = $1; }
1169 3652 : | analyze_keyword { $$ = "analyze"; }
1170 148 : | FORMAT_LA { $$ = "format"; }
1171 : ;
1172 :
1173 : utility_option_arg:
1174 17628 : opt_boolean_or_string { $$ = (Node *) makeString($1); }
1175 382 : | NumericOnly { $$ = (Node *) $1; }
1176 16552 : | /* EMPTY */ { $$ = NULL; }
1177 : ;
1178 :
1179 : /*****************************************************************************
1180 : *
1181 : * CALL statement
1182 : *
1183 : *****************************************************************************/
1184 :
1185 : CallStmt: CALL func_application
1186 : {
1187 628 : CallStmt *n = makeNode(CallStmt);
1188 :
1189 628 : n->funccall = castNode(FuncCall, $2);
1190 628 : $$ = (Node *) n;
1191 : }
1192 : ;
1193 :
1194 : /*****************************************************************************
1195 : *
1196 : * Create a new Postgres DBMS role
1197 : *
1198 : *****************************************************************************/
1199 :
1200 : CreateRoleStmt:
1201 : CREATE ROLE RoleId opt_with OptRoleList
1202 : {
1203 1350 : CreateRoleStmt *n = makeNode(CreateRoleStmt);
1204 :
1205 1350 : n->stmt_type = ROLESTMT_ROLE;
1206 1350 : n->role = $3;
1207 1350 : n->options = $5;
1208 1350 : $$ = (Node *) n;
1209 : }
1210 : ;
1211 :
1212 :
1213 : opt_with: WITH
1214 : | WITH_LA
1215 : | /*EMPTY*/
1216 : ;
1217 :
1218 : /*
1219 : * Options for CREATE ROLE and ALTER ROLE (also used by CREATE/ALTER USER
1220 : * for backwards compatibility). Note: the only option required by SQL99
1221 : * is "WITH ADMIN name".
1222 : */
1223 : OptRoleList:
1224 1160 : OptRoleList CreateOptRoleElem { $$ = lappend($1, $2); }
1225 1830 : | /* EMPTY */ { $$ = NIL; }
1226 : ;
1227 :
1228 : AlterOptRoleList:
1229 658 : AlterOptRoleList AlterOptRoleElem { $$ = lappend($1, $2); }
1230 418 : | /* EMPTY */ { $$ = NIL; }
1231 : ;
1232 :
1233 : AlterOptRoleElem:
1234 : PASSWORD Sconst
1235 : {
1236 188 : $$ = makeDefElem("password",
1237 188 : (Node *) makeString($2), @1);
1238 : }
1239 : | PASSWORD NULL_P
1240 : {
1241 12 : $$ = makeDefElem("password", NULL, @1);
1242 : }
1243 : | ENCRYPTED PASSWORD Sconst
1244 : {
1245 : /*
1246 : * These days, passwords are always stored in encrypted
1247 : * form, so there is no difference between PASSWORD and
1248 : * ENCRYPTED PASSWORD.
1249 : */
1250 16 : $$ = makeDefElem("password",
1251 16 : (Node *) makeString($3), @1);
1252 : }
1253 : | UNENCRYPTED PASSWORD Sconst
1254 : {
1255 0 : ereport(ERROR,
1256 : (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
1257 : errmsg("UNENCRYPTED PASSWORD is no longer supported"),
1258 : errhint("Remove UNENCRYPTED to store the password in encrypted form instead."),
1259 : parser_errposition(@1)));
1260 : }
1261 : | INHERIT
1262 : {
1263 92 : $$ = makeDefElem("inherit", (Node *) makeBoolean(true), @1);
1264 : }
1265 : | CONNECTION LIMIT SignedIconst
1266 : {
1267 24 : $$ = makeDefElem("connectionlimit", (Node *) makeInteger($3), @1);
1268 : }
1269 : | VALID UNTIL Sconst
1270 : {
1271 2 : $$ = makeDefElem("validUntil", (Node *) makeString($3), @1);
1272 : }
1273 : /* Supported but not documented for roles, for use by ALTER GROUP. */
1274 : | USER role_list
1275 : {
1276 6 : $$ = makeDefElem("rolemembers", (Node *) $2, @1);
1277 : }
1278 : | IDENT
1279 : {
1280 : /*
1281 : * We handle identifiers that aren't parser keywords with
1282 : * the following special-case codes, to avoid bloating the
1283 : * size of the main parser.
1284 : */
1285 1330 : if (strcmp($1, "superuser") == 0)
1286 192 : $$ = makeDefElem("superuser", (Node *) makeBoolean(true), @1);
1287 1138 : else if (strcmp($1, "nosuperuser") == 0)
1288 96 : $$ = makeDefElem("superuser", (Node *) makeBoolean(false), @1);
1289 1042 : else if (strcmp($1, "createrole") == 0)
1290 102 : $$ = makeDefElem("createrole", (Node *) makeBoolean(true), @1);
1291 940 : else if (strcmp($1, "nocreaterole") == 0)
1292 34 : $$ = makeDefElem("createrole", (Node *) makeBoolean(false), @1);
1293 906 : else if (strcmp($1, "replication") == 0)
1294 130 : $$ = makeDefElem("isreplication", (Node *) makeBoolean(true), @1);
1295 776 : else if (strcmp($1, "noreplication") == 0)
1296 92 : $$ = makeDefElem("isreplication", (Node *) makeBoolean(false), @1);
1297 684 : else if (strcmp($1, "createdb") == 0)
1298 92 : $$ = makeDefElem("createdb", (Node *) makeBoolean(true), @1);
1299 592 : else if (strcmp($1, "nocreatedb") == 0)
1300 42 : $$ = makeDefElem("createdb", (Node *) makeBoolean(false), @1);
1301 550 : else if (strcmp($1, "login") == 0)
1302 282 : $$ = makeDefElem("canlogin", (Node *) makeBoolean(true), @1);
1303 268 : else if (strcmp($1, "nologin") == 0)
1304 86 : $$ = makeDefElem("canlogin", (Node *) makeBoolean(false), @1);
1305 182 : else if (strcmp($1, "bypassrls") == 0)
1306 82 : $$ = makeDefElem("bypassrls", (Node *) makeBoolean(true), @1);
1307 100 : else if (strcmp($1, "nobypassrls") == 0)
1308 64 : $$ = makeDefElem("bypassrls", (Node *) makeBoolean(false), @1);
1309 36 : else if (strcmp($1, "noinherit") == 0)
1310 : {
1311 : /*
1312 : * Note that INHERIT is a keyword, so it's handled by main parser, but
1313 : * NOINHERIT is handled here.
1314 : */
1315 36 : $$ = makeDefElem("inherit", (Node *) makeBoolean(false), @1);
1316 : }
1317 : else
1318 0 : ereport(ERROR,
1319 : (errcode(ERRCODE_SYNTAX_ERROR),
1320 : errmsg("unrecognized role option \"%s\"", $1),
1321 : parser_errposition(@1)));
1322 : }
1323 : ;
1324 :
1325 : CreateOptRoleElem:
1326 1012 : AlterOptRoleElem { $$ = $1; }
1327 : /* The following are not supported by ALTER ROLE/USER/GROUP */
1328 : | SYSID Iconst
1329 : {
1330 6 : $$ = makeDefElem("sysid", (Node *) makeInteger($2), @1);
1331 : }
1332 : | ADMIN role_list
1333 : {
1334 22 : $$ = makeDefElem("adminmembers", (Node *) $2, @1);
1335 : }
1336 : | ROLE role_list
1337 : {
1338 22 : $$ = makeDefElem("rolemembers", (Node *) $2, @1);
1339 : }
1340 : | IN_P ROLE role_list
1341 : {
1342 98 : $$ = makeDefElem("addroleto", (Node *) $3, @1);
1343 : }
1344 : | IN_P GROUP_P role_list
1345 : {
1346 0 : $$ = makeDefElem("addroleto", (Node *) $3, @1);
1347 : }
1348 : ;
1349 :
1350 :
1351 : /*****************************************************************************
1352 : *
1353 : * Create a new Postgres DBMS user (role with implied login ability)
1354 : *
1355 : *****************************************************************************/
1356 :
1357 : CreateUserStmt:
1358 : CREATE USER RoleId opt_with OptRoleList
1359 : {
1360 456 : CreateRoleStmt *n = makeNode(CreateRoleStmt);
1361 :
1362 456 : n->stmt_type = ROLESTMT_USER;
1363 456 : n->role = $3;
1364 456 : n->options = $5;
1365 456 : $$ = (Node *) n;
1366 : }
1367 : ;
1368 :
1369 :
1370 : /*****************************************************************************
1371 : *
1372 : * Alter a postgresql DBMS role
1373 : *
1374 : *****************************************************************************/
1375 :
1376 : AlterRoleStmt:
1377 : ALTER ROLE RoleSpec opt_with AlterOptRoleList
1378 : {
1379 326 : AlterRoleStmt *n = makeNode(AlterRoleStmt);
1380 :
1381 326 : n->role = $3;
1382 326 : n->action = +1; /* add, if there are members */
1383 326 : n->options = $5;
1384 326 : $$ = (Node *) n;
1385 : }
1386 : | ALTER USER RoleSpec opt_with AlterOptRoleList
1387 : {
1388 92 : AlterRoleStmt *n = makeNode(AlterRoleStmt);
1389 :
1390 92 : n->role = $3;
1391 92 : n->action = +1; /* add, if there are members */
1392 92 : n->options = $5;
1393 92 : $$ = (Node *) n;
1394 : }
1395 : ;
1396 :
1397 : opt_in_database:
1398 92 : /* EMPTY */ { $$ = NULL; }
1399 4 : | IN_P DATABASE name { $$ = $3; }
1400 : ;
1401 :
1402 : AlterRoleSetStmt:
1403 : ALTER ROLE RoleSpec opt_in_database SetResetClause
1404 : {
1405 58 : AlterRoleSetStmt *n = makeNode(AlterRoleSetStmt);
1406 :
1407 58 : n->role = $3;
1408 58 : n->database = $4;
1409 58 : n->setstmt = $5;
1410 58 : $$ = (Node *) n;
1411 : }
1412 : | ALTER ROLE ALL opt_in_database SetResetClause
1413 : {
1414 4 : AlterRoleSetStmt *n = makeNode(AlterRoleSetStmt);
1415 :
1416 4 : n->role = NULL;
1417 4 : n->database = $4;
1418 4 : n->setstmt = $5;
1419 4 : $$ = (Node *) n;
1420 : }
1421 : | ALTER USER RoleSpec opt_in_database SetResetClause
1422 : {
1423 26 : AlterRoleSetStmt *n = makeNode(AlterRoleSetStmt);
1424 :
1425 26 : n->role = $3;
1426 26 : n->database = $4;
1427 26 : n->setstmt = $5;
1428 26 : $$ = (Node *) n;
1429 : }
1430 : | ALTER USER ALL opt_in_database SetResetClause
1431 : {
1432 4 : AlterRoleSetStmt *n = makeNode(AlterRoleSetStmt);
1433 :
1434 4 : n->role = NULL;
1435 4 : n->database = $4;
1436 4 : n->setstmt = $5;
1437 4 : $$ = (Node *) n;
1438 : }
1439 : ;
1440 :
1441 :
1442 : /*****************************************************************************
1443 : *
1444 : * Drop a postgresql DBMS role
1445 : *
1446 : * XXX Ideally this would have CASCADE/RESTRICT options, but a role
1447 : * might own objects in multiple databases, and there is presently no way to
1448 : * implement cascading to other databases. So we always behave as RESTRICT.
1449 : *****************************************************************************/
1450 :
1451 : DropRoleStmt:
1452 : DROP ROLE role_list
1453 : {
1454 1106 : DropRoleStmt *n = makeNode(DropRoleStmt);
1455 :
1456 1106 : n->missing_ok = false;
1457 1106 : n->roles = $3;
1458 1106 : $$ = (Node *) n;
1459 : }
1460 : | DROP ROLE IF_P EXISTS role_list
1461 : {
1462 134 : DropRoleStmt *n = makeNode(DropRoleStmt);
1463 :
1464 134 : n->missing_ok = true;
1465 134 : n->roles = $5;
1466 134 : $$ = (Node *) n;
1467 : }
1468 : | DROP USER role_list
1469 : {
1470 404 : DropRoleStmt *n = makeNode(DropRoleStmt);
1471 :
1472 404 : n->missing_ok = false;
1473 404 : n->roles = $3;
1474 404 : $$ = (Node *) n;
1475 : }
1476 : | DROP USER IF_P EXISTS role_list
1477 : {
1478 36 : DropRoleStmt *n = makeNode(DropRoleStmt);
1479 :
1480 36 : n->roles = $5;
1481 36 : n->missing_ok = true;
1482 36 : $$ = (Node *) n;
1483 : }
1484 : | DROP GROUP_P role_list
1485 : {
1486 36 : DropRoleStmt *n = makeNode(DropRoleStmt);
1487 :
1488 36 : n->missing_ok = false;
1489 36 : n->roles = $3;
1490 36 : $$ = (Node *) n;
1491 : }
1492 : | DROP GROUP_P IF_P EXISTS role_list
1493 : {
1494 6 : DropRoleStmt *n = makeNode(DropRoleStmt);
1495 :
1496 6 : n->missing_ok = true;
1497 6 : n->roles = $5;
1498 6 : $$ = (Node *) n;
1499 : }
1500 : ;
1501 :
1502 :
1503 : /*****************************************************************************
1504 : *
1505 : * Create a postgresql group (role without login ability)
1506 : *
1507 : *****************************************************************************/
1508 :
1509 : CreateGroupStmt:
1510 : CREATE GROUP_P RoleId opt_with OptRoleList
1511 : {
1512 24 : CreateRoleStmt *n = makeNode(CreateRoleStmt);
1513 :
1514 24 : n->stmt_type = ROLESTMT_GROUP;
1515 24 : n->role = $3;
1516 24 : n->options = $5;
1517 24 : $$ = (Node *) n;
1518 : }
1519 : ;
1520 :
1521 :
1522 : /*****************************************************************************
1523 : *
1524 : * Alter a postgresql group
1525 : *
1526 : *****************************************************************************/
1527 :
1528 : AlterGroupStmt:
1529 : ALTER GROUP_P RoleSpec add_drop USER role_list
1530 : {
1531 42 : AlterRoleStmt *n = makeNode(AlterRoleStmt);
1532 :
1533 42 : n->role = $3;
1534 42 : n->action = $4;
1535 42 : n->options = list_make1(makeDefElem("rolemembers",
1536 : (Node *) $6, @6));
1537 42 : $$ = (Node *) n;
1538 : }
1539 : ;
1540 :
1541 86 : add_drop: ADD_P { $$ = +1; }
1542 222 : | DROP { $$ = -1; }
1543 : ;
1544 :
1545 :
1546 : /*****************************************************************************
1547 : *
1548 : * Manipulate a schema
1549 : *
1550 : *****************************************************************************/
1551 :
1552 : CreateSchemaStmt:
1553 : CREATE SCHEMA opt_single_name AUTHORIZATION RoleSpec OptSchemaEltList
1554 : {
1555 158 : CreateSchemaStmt *n = makeNode(CreateSchemaStmt);
1556 :
1557 : /* One can omit the schema name or the authorization id. */
1558 158 : n->schemaname = $3;
1559 158 : n->authrole = $5;
1560 158 : n->schemaElts = $6;
1561 158 : n->if_not_exists = false;
1562 158 : $$ = (Node *) n;
1563 : }
1564 : | CREATE SCHEMA ColId OptSchemaEltList
1565 : {
1566 874 : CreateSchemaStmt *n = makeNode(CreateSchemaStmt);
1567 :
1568 : /* ...but not both */
1569 874 : n->schemaname = $3;
1570 874 : n->authrole = NULL;
1571 874 : n->schemaElts = $4;
1572 874 : n->if_not_exists = false;
1573 874 : $$ = (Node *) n;
1574 : }
1575 : | CREATE SCHEMA IF_P NOT EXISTS opt_single_name AUTHORIZATION RoleSpec OptSchemaEltList
1576 : {
1577 18 : CreateSchemaStmt *n = makeNode(CreateSchemaStmt);
1578 :
1579 : /* schema name can be omitted here, too */
1580 18 : n->schemaname = $6;
1581 18 : n->authrole = $8;
1582 18 : if ($9 != NIL)
1583 0 : ereport(ERROR,
1584 : (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
1585 : errmsg("CREATE SCHEMA IF NOT EXISTS cannot include schema elements"),
1586 : parser_errposition(@9)));
1587 18 : n->schemaElts = $9;
1588 18 : n->if_not_exists = true;
1589 18 : $$ = (Node *) n;
1590 : }
1591 : | CREATE SCHEMA IF_P NOT EXISTS ColId OptSchemaEltList
1592 : {
1593 34 : CreateSchemaStmt *n = makeNode(CreateSchemaStmt);
1594 :
1595 : /* ...but not here */
1596 34 : n->schemaname = $6;
1597 34 : n->authrole = NULL;
1598 34 : if ($7 != NIL)
1599 6 : ereport(ERROR,
1600 : (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
1601 : errmsg("CREATE SCHEMA IF NOT EXISTS cannot include schema elements"),
1602 : parser_errposition(@7)));
1603 28 : n->schemaElts = $7;
1604 28 : n->if_not_exists = true;
1605 28 : $$ = (Node *) n;
1606 : }
1607 : ;
1608 :
1609 : OptSchemaEltList:
1610 : OptSchemaEltList schema_stmt
1611 : {
1612 564 : $$ = lappend($1, $2);
1613 : }
1614 : | /* EMPTY */
1615 1084 : { $$ = NIL; }
1616 : ;
1617 :
1618 : /*
1619 : * schema_stmt are the ones that can show up inside a CREATE SCHEMA
1620 : * statement (in addition to by themselves).
1621 : */
1622 : schema_stmt:
1623 : CreateStmt
1624 : | IndexStmt
1625 : | CreateSeqStmt
1626 : | CreateTrigStmt
1627 : | GrantStmt
1628 : | ViewStmt
1629 : ;
1630 :
1631 :
1632 : /*****************************************************************************
1633 : *
1634 : * Set PG internal variable
1635 : * SET name TO 'var_value'
1636 : * Include SQL syntax (thomas 1997-10-22):
1637 : * SET TIME ZONE 'var_value'
1638 : *
1639 : *****************************************************************************/
1640 :
1641 : VariableSetStmt:
1642 : SET set_rest
1643 : {
1644 21470 : VariableSetStmt *n = $2;
1645 :
1646 21470 : n->is_local = false;
1647 21470 : $$ = (Node *) n;
1648 : }
1649 : | SET LOCAL set_rest
1650 : {
1651 1236 : VariableSetStmt *n = $3;
1652 :
1653 1236 : n->is_local = true;
1654 1236 : $$ = (Node *) n;
1655 : }
1656 : | SET SESSION set_rest
1657 : {
1658 84 : VariableSetStmt *n = $3;
1659 :
1660 84 : n->is_local = false;
1661 84 : $$ = (Node *) n;
1662 : }
1663 : ;
1664 :
1665 : set_rest:
1666 : TRANSACTION transaction_mode_list
1667 : {
1668 574 : VariableSetStmt *n = makeNode(VariableSetStmt);
1669 :
1670 574 : n->kind = VAR_SET_MULTI;
1671 574 : n->name = "TRANSACTION";
1672 574 : n->args = $2;
1673 574 : n->jumble_args = true;
1674 574 : n->location = -1;
1675 574 : $$ = n;
1676 : }
1677 : | SESSION CHARACTERISTICS AS TRANSACTION transaction_mode_list
1678 : {
1679 18 : VariableSetStmt *n = makeNode(VariableSetStmt);
1680 :
1681 18 : n->kind = VAR_SET_MULTI;
1682 18 : n->name = "SESSION CHARACTERISTICS";
1683 18 : n->args = $5;
1684 18 : n->jumble_args = true;
1685 18 : n->location = -1;
1686 18 : $$ = n;
1687 : }
1688 : | set_rest_more
1689 : ;
1690 :
1691 : generic_set:
1692 : var_name TO var_list
1693 : {
1694 5056 : VariableSetStmt *n = makeNode(VariableSetStmt);
1695 :
1696 5056 : n->kind = VAR_SET_VALUE;
1697 5056 : n->name = $1;
1698 5056 : n->args = $3;
1699 5056 : n->location = @3;
1700 5056 : $$ = n;
1701 : }
1702 : | var_name '=' var_list
1703 : {
1704 14794 : VariableSetStmt *n = makeNode(VariableSetStmt);
1705 :
1706 14794 : n->kind = VAR_SET_VALUE;
1707 14794 : n->name = $1;
1708 14794 : n->args = $3;
1709 14794 : n->location = @3;
1710 14794 : $$ = n;
1711 : }
1712 : | var_name TO DEFAULT
1713 : {
1714 136 : VariableSetStmt *n = makeNode(VariableSetStmt);
1715 :
1716 136 : n->kind = VAR_SET_DEFAULT;
1717 136 : n->name = $1;
1718 136 : n->location = -1;
1719 136 : $$ = n;
1720 : }
1721 : | var_name '=' DEFAULT
1722 : {
1723 10 : VariableSetStmt *n = makeNode(VariableSetStmt);
1724 :
1725 10 : n->kind = VAR_SET_DEFAULT;
1726 10 : n->name = $1;
1727 10 : n->location = -1;
1728 10 : $$ = n;
1729 : }
1730 : ;
1731 :
1732 : set_rest_more: /* Generic SET syntaxes: */
1733 19866 : generic_set {$$ = $1;}
1734 : | var_name FROM CURRENT_P
1735 : {
1736 4 : VariableSetStmt *n = makeNode(VariableSetStmt);
1737 :
1738 4 : n->kind = VAR_SET_CURRENT;
1739 4 : n->name = $1;
1740 4 : n->location = -1;
1741 4 : $$ = n;
1742 : }
1743 : /* Special syntaxes mandated by SQL standard: */
1744 : | TIME ZONE zone_value
1745 : {
1746 104 : VariableSetStmt *n = makeNode(VariableSetStmt);
1747 :
1748 104 : n->kind = VAR_SET_VALUE;
1749 104 : n->name = "timezone";
1750 104 : n->location = -1;
1751 104 : n->jumble_args = true;
1752 104 : if ($3 != NULL)
1753 88 : n->args = list_make1($3);
1754 : else
1755 16 : n->kind = VAR_SET_DEFAULT;
1756 104 : $$ = n;
1757 : }
1758 : | CATALOG_P Sconst
1759 : {
1760 0 : ereport(ERROR,
1761 : (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
1762 : errmsg("current database cannot be changed"),
1763 : parser_errposition(@2)));
1764 : $$ = NULL; /*not reached*/
1765 : }
1766 : | SCHEMA Sconst
1767 : {
1768 4 : VariableSetStmt *n = makeNode(VariableSetStmt);
1769 :
1770 4 : n->kind = VAR_SET_VALUE;
1771 4 : n->name = "search_path";
1772 4 : n->args = list_make1(makeStringConst($2, @2));
1773 4 : n->location = @2;
1774 4 : $$ = n;
1775 : }
1776 : | NAMES opt_encoding
1777 : {
1778 0 : VariableSetStmt *n = makeNode(VariableSetStmt);
1779 :
1780 0 : n->kind = VAR_SET_VALUE;
1781 0 : n->name = "client_encoding";
1782 0 : n->location = @2;
1783 0 : if ($2 != NULL)
1784 0 : n->args = list_make1(makeStringConst($2, @2));
1785 : else
1786 0 : n->kind = VAR_SET_DEFAULT;
1787 0 : $$ = n;
1788 : }
1789 : | ROLE NonReservedWord_or_Sconst
1790 : {
1791 960 : VariableSetStmt *n = makeNode(VariableSetStmt);
1792 :
1793 960 : n->kind = VAR_SET_VALUE;
1794 960 : n->name = "role";
1795 960 : n->args = list_make1(makeStringConst($2, @2));
1796 960 : n->location = @2;
1797 960 : $$ = n;
1798 : }
1799 : | SESSION AUTHORIZATION NonReservedWord_or_Sconst
1800 : {
1801 2586 : VariableSetStmt *n = makeNode(VariableSetStmt);
1802 :
1803 2586 : n->kind = VAR_SET_VALUE;
1804 2586 : n->name = "session_authorization";
1805 2586 : n->args = list_make1(makeStringConst($3, @3));
1806 2586 : n->location = @3;
1807 2586 : $$ = n;
1808 : }
1809 : | SESSION AUTHORIZATION DEFAULT
1810 : {
1811 4 : VariableSetStmt *n = makeNode(VariableSetStmt);
1812 :
1813 4 : n->kind = VAR_SET_DEFAULT;
1814 4 : n->name = "session_authorization";
1815 4 : n->location = -1;
1816 4 : $$ = n;
1817 : }
1818 : | XML_P OPTION document_or_content
1819 : {
1820 16 : VariableSetStmt *n = makeNode(VariableSetStmt);
1821 :
1822 16 : n->kind = VAR_SET_VALUE;
1823 16 : n->name = "xmloption";
1824 16 : n->args = list_make1(makeStringConst($3 == XMLOPTION_DOCUMENT ? "DOCUMENT" : "CONTENT", @3));
1825 16 : n->jumble_args = true;
1826 16 : n->location = -1;
1827 16 : $$ = n;
1828 : }
1829 : /* Special syntaxes invented by PostgreSQL: */
1830 : | TRANSACTION SNAPSHOT Sconst
1831 : {
1832 44 : VariableSetStmt *n = makeNode(VariableSetStmt);
1833 :
1834 44 : n->kind = VAR_SET_MULTI;
1835 44 : n->name = "TRANSACTION SNAPSHOT";
1836 44 : n->args = list_make1(makeStringConst($3, @3));
1837 44 : n->location = @3;
1838 44 : $$ = n;
1839 : }
1840 : ;
1841 :
1842 24646 : var_name: ColId { $$ = $1; }
1843 : | var_name '.' ColId
1844 496 : { $$ = psprintf("%s.%s", $1, $3); }
1845 : ;
1846 :
1847 19850 : var_list: var_value { $$ = list_make1($1); }
1848 182 : | var_list ',' var_value { $$ = lappend($1, $3); }
1849 : ;
1850 :
1851 : var_value: opt_boolean_or_string
1852 14830 : { $$ = makeStringConst($1, @1); }
1853 : | NumericOnly
1854 5202 : { $$ = makeAConst($1, @1); }
1855 : ;
1856 :
1857 0 : iso_level: READ UNCOMMITTED { $$ = "read uncommitted"; }
1858 908 : | READ COMMITTED { $$ = "read committed"; }
1859 2598 : | REPEATABLE READ { $$ = "repeatable read"; }
1860 3196 : | SERIALIZABLE { $$ = "serializable"; }
1861 : ;
1862 :
1863 : opt_boolean_or_string:
1864 690 : TRUE_P { $$ = "true"; }
1865 1486 : | FALSE_P { $$ = "false"; }
1866 2224 : | ON { $$ = "on"; }
1867 : /*
1868 : * OFF is also accepted as a boolean value, but is handled by
1869 : * the NonReservedWord rule. The action for booleans and strings
1870 : * is the same, so we don't need to distinguish them here.
1871 : */
1872 30400 : | NonReservedWord_or_Sconst { $$ = $1; }
1873 : ;
1874 :
1875 : /* Timezone values can be:
1876 : * - a string such as 'pst8pdt'
1877 : * - an identifier such as "pst8pdt"
1878 : * - an integer or floating point number
1879 : * - a time interval per SQL99
1880 : * ColId gives reduce/reduce errors against ConstInterval and LOCAL,
1881 : * so use IDENT (meaning we reject anything that is a key word).
1882 : */
1883 : zone_value:
1884 : Sconst
1885 : {
1886 60 : $$ = makeStringConst($1, @1);
1887 : }
1888 : | IDENT
1889 : {
1890 4 : $$ = makeStringConst($1, @1);
1891 : }
1892 : | ConstInterval Sconst opt_interval
1893 : {
1894 0 : TypeName *t = $1;
1895 :
1896 0 : if ($3 != NIL)
1897 : {
1898 0 : A_Const *n = (A_Const *) linitial($3);
1899 :
1900 0 : if ((n->val.ival.ival & ~(INTERVAL_MASK(HOUR) | INTERVAL_MASK(MINUTE))) != 0)
1901 0 : ereport(ERROR,
1902 : (errcode(ERRCODE_SYNTAX_ERROR),
1903 : errmsg("time zone interval must be HOUR or HOUR TO MINUTE"),
1904 : parser_errposition(@3)));
1905 : }
1906 0 : t->typmods = $3;
1907 0 : $$ = makeStringConstCast($2, @2, t);
1908 : }
1909 : | ConstInterval '(' Iconst ')' Sconst
1910 : {
1911 0 : TypeName *t = $1;
1912 :
1913 0 : t->typmods = list_make2(makeIntConst(INTERVAL_FULL_RANGE, -1),
1914 : makeIntConst($3, @3));
1915 0 : $$ = makeStringConstCast($5, @5, t);
1916 : }
1917 24 : | NumericOnly { $$ = makeAConst($1, @1); }
1918 14 : | DEFAULT { $$ = NULL; }
1919 2 : | LOCAL { $$ = NULL; }
1920 : ;
1921 :
1922 : opt_encoding:
1923 0 : Sconst { $$ = $1; }
1924 0 : | DEFAULT { $$ = NULL; }
1925 0 : | /*EMPTY*/ { $$ = NULL; }
1926 : ;
1927 :
1928 : NonReservedWord_or_Sconst:
1929 53946 : NonReservedWord { $$ = $1; }
1930 5556 : | Sconst { $$ = $1; }
1931 : ;
1932 :
1933 : VariableResetStmt:
1934 4558 : RESET reset_rest { $$ = (Node *) $2; }
1935 : ;
1936 :
1937 : reset_rest:
1938 3754 : generic_reset { $$ = $1; }
1939 : | TIME ZONE
1940 : {
1941 14 : VariableSetStmt *n = makeNode(VariableSetStmt);
1942 :
1943 14 : n->kind = VAR_RESET;
1944 14 : n->name = "timezone";
1945 14 : n->location = -1;
1946 14 : $$ = n;
1947 : }
1948 : | TRANSACTION ISOLATION LEVEL
1949 : {
1950 0 : VariableSetStmt *n = makeNode(VariableSetStmt);
1951 :
1952 0 : n->kind = VAR_RESET;
1953 0 : n->name = "transaction_isolation";
1954 0 : n->location = -1;
1955 0 : $$ = n;
1956 : }
1957 : | SESSION AUTHORIZATION
1958 : {
1959 790 : VariableSetStmt *n = makeNode(VariableSetStmt);
1960 :
1961 790 : n->kind = VAR_RESET;
1962 790 : n->name = "session_authorization";
1963 790 : n->location = -1;
1964 790 : $$ = n;
1965 : }
1966 : ;
1967 :
1968 : generic_reset:
1969 : var_name
1970 : {
1971 3782 : VariableSetStmt *n = makeNode(VariableSetStmt);
1972 :
1973 3782 : n->kind = VAR_RESET;
1974 3782 : n->name = $1;
1975 3782 : n->location = -1;
1976 3782 : $$ = n;
1977 : }
1978 : | ALL
1979 : {
1980 28 : VariableSetStmt *n = makeNode(VariableSetStmt);
1981 :
1982 28 : n->kind = VAR_RESET_ALL;
1983 28 : n->location = -1;
1984 28 : $$ = n;
1985 : }
1986 : ;
1987 :
1988 : /* SetResetClause allows SET or RESET without LOCAL */
1989 : SetResetClause:
1990 1256 : SET set_rest { $$ = $2; }
1991 50 : | VariableResetStmt { $$ = (VariableSetStmt *) $1; }
1992 : ;
1993 :
1994 : /* SetResetClause allows SET or RESET without LOCAL */
1995 : FunctionSetResetClause:
1996 134 : SET set_rest_more { $$ = $2; }
1997 12 : | VariableResetStmt { $$ = (VariableSetStmt *) $1; }
1998 : ;
1999 :
2000 :
2001 : VariableShowStmt:
2002 : SHOW var_name
2003 : {
2004 864 : VariableShowStmt *n = makeNode(VariableShowStmt);
2005 :
2006 864 : n->name = $2;
2007 864 : $$ = (Node *) n;
2008 : }
2009 : | SHOW TIME ZONE
2010 : {
2011 10 : VariableShowStmt *n = makeNode(VariableShowStmt);
2012 :
2013 10 : n->name = "timezone";
2014 10 : $$ = (Node *) n;
2015 : }
2016 : | SHOW TRANSACTION ISOLATION LEVEL
2017 : {
2018 4 : VariableShowStmt *n = makeNode(VariableShowStmt);
2019 :
2020 4 : n->name = "transaction_isolation";
2021 4 : $$ = (Node *) n;
2022 : }
2023 : | SHOW SESSION AUTHORIZATION
2024 : {
2025 0 : VariableShowStmt *n = makeNode(VariableShowStmt);
2026 :
2027 0 : n->name = "session_authorization";
2028 0 : $$ = (Node *) n;
2029 : }
2030 : | SHOW ALL
2031 : {
2032 0 : VariableShowStmt *n = makeNode(VariableShowStmt);
2033 :
2034 0 : n->name = "all";
2035 0 : $$ = (Node *) n;
2036 : }
2037 : ;
2038 :
2039 :
2040 : ConstraintsSetStmt:
2041 : SET CONSTRAINTS constraints_set_list constraints_set_mode
2042 : {
2043 104 : ConstraintsSetStmt *n = makeNode(ConstraintsSetStmt);
2044 :
2045 104 : n->constraints = $3;
2046 104 : n->deferred = $4;
2047 104 : $$ = (Node *) n;
2048 : }
2049 : ;
2050 :
2051 : constraints_set_list:
2052 56 : ALL { $$ = NIL; }
2053 48 : | qualified_name_list { $$ = $1; }
2054 : ;
2055 :
2056 : constraints_set_mode:
2057 68 : DEFERRED { $$ = true; }
2058 36 : | IMMEDIATE { $$ = false; }
2059 : ;
2060 :
2061 :
2062 : /*
2063 : * Checkpoint statement
2064 : */
2065 : CheckPointStmt:
2066 : CHECKPOINT opt_utility_option_list
2067 : {
2068 240 : CheckPointStmt *n = makeNode(CheckPointStmt);
2069 :
2070 240 : $$ = (Node *) n;
2071 240 : n->options = $2;
2072 : }
2073 : ;
2074 :
2075 :
2076 : /*****************************************************************************
2077 : *
2078 : * DISCARD { ALL | TEMP | PLANS | SEQUENCES }
2079 : *
2080 : *****************************************************************************/
2081 :
2082 : DiscardStmt:
2083 : DISCARD ALL
2084 : {
2085 6 : DiscardStmt *n = makeNode(DiscardStmt);
2086 :
2087 6 : n->target = DISCARD_ALL;
2088 6 : $$ = (Node *) n;
2089 : }
2090 : | DISCARD TEMP
2091 : {
2092 8 : DiscardStmt *n = makeNode(DiscardStmt);
2093 :
2094 8 : n->target = DISCARD_TEMP;
2095 8 : $$ = (Node *) n;
2096 : }
2097 : | DISCARD TEMPORARY
2098 : {
2099 0 : DiscardStmt *n = makeNode(DiscardStmt);
2100 :
2101 0 : n->target = DISCARD_TEMP;
2102 0 : $$ = (Node *) n;
2103 : }
2104 : | DISCARD PLANS
2105 : {
2106 4 : DiscardStmt *n = makeNode(DiscardStmt);
2107 :
2108 4 : n->target = DISCARD_PLANS;
2109 4 : $$ = (Node *) n;
2110 : }
2111 : | DISCARD SEQUENCES
2112 : {
2113 12 : DiscardStmt *n = makeNode(DiscardStmt);
2114 :
2115 12 : n->target = DISCARD_SEQUENCES;
2116 12 : $$ = (Node *) n;
2117 : }
2118 :
2119 : ;
2120 :
2121 :
2122 : /*****************************************************************************
2123 : *
2124 : * ALTER [ TABLE | INDEX | SEQUENCE | VIEW | MATERIALIZED VIEW | FOREIGN TABLE ] variations
2125 : *
2126 : * Note: we accept all subcommands for each of the variants, and sort
2127 : * out what's really legal at execution time.
2128 : *****************************************************************************/
2129 :
2130 : AlterTableStmt:
2131 : ALTER TABLE relation_expr alter_table_cmds
2132 : {
2133 26326 : AlterTableStmt *n = makeNode(AlterTableStmt);
2134 :
2135 26326 : n->relation = $3;
2136 26326 : n->cmds = $4;
2137 26326 : n->objtype = OBJECT_TABLE;
2138 26326 : n->missing_ok = false;
2139 26326 : $$ = (Node *) n;
2140 : }
2141 : | ALTER TABLE IF_P EXISTS relation_expr alter_table_cmds
2142 : {
2143 54 : AlterTableStmt *n = makeNode(AlterTableStmt);
2144 :
2145 54 : n->relation = $5;
2146 54 : n->cmds = $6;
2147 54 : n->objtype = OBJECT_TABLE;
2148 54 : n->missing_ok = true;
2149 54 : $$ = (Node *) n;
2150 : }
2151 : | ALTER TABLE relation_expr partition_cmd
2152 : {
2153 3052 : AlterTableStmt *n = makeNode(AlterTableStmt);
2154 :
2155 3052 : n->relation = $3;
2156 3052 : n->cmds = list_make1($4);
2157 3052 : n->objtype = OBJECT_TABLE;
2158 3052 : n->missing_ok = false;
2159 3052 : $$ = (Node *) n;
2160 : }
2161 : | ALTER TABLE IF_P EXISTS relation_expr partition_cmd
2162 : {
2163 0 : AlterTableStmt *n = makeNode(AlterTableStmt);
2164 :
2165 0 : n->relation = $5;
2166 0 : n->cmds = list_make1($6);
2167 0 : n->objtype = OBJECT_TABLE;
2168 0 : n->missing_ok = true;
2169 0 : $$ = (Node *) n;
2170 : }
2171 : | ALTER TABLE ALL IN_P TABLESPACE name SET TABLESPACE name opt_nowait
2172 : {
2173 : AlterTableMoveAllStmt *n =
2174 12 : makeNode(AlterTableMoveAllStmt);
2175 :
2176 12 : n->orig_tablespacename = $6;
2177 12 : n->objtype = OBJECT_TABLE;
2178 12 : n->roles = NIL;
2179 12 : n->new_tablespacename = $9;
2180 12 : n->nowait = $10;
2181 12 : $$ = (Node *) n;
2182 : }
2183 : | ALTER TABLE ALL IN_P TABLESPACE name OWNED BY role_list SET TABLESPACE name opt_nowait
2184 : {
2185 : AlterTableMoveAllStmt *n =
2186 0 : makeNode(AlterTableMoveAllStmt);
2187 :
2188 0 : n->orig_tablespacename = $6;
2189 0 : n->objtype = OBJECT_TABLE;
2190 0 : n->roles = $9;
2191 0 : n->new_tablespacename = $12;
2192 0 : n->nowait = $13;
2193 0 : $$ = (Node *) n;
2194 : }
2195 : | ALTER INDEX qualified_name alter_table_cmds
2196 : {
2197 228 : AlterTableStmt *n = makeNode(AlterTableStmt);
2198 :
2199 228 : n->relation = $3;
2200 228 : n->cmds = $4;
2201 228 : n->objtype = OBJECT_INDEX;
2202 228 : n->missing_ok = false;
2203 228 : $$ = (Node *) n;
2204 : }
2205 : | ALTER INDEX IF_P EXISTS qualified_name alter_table_cmds
2206 : {
2207 0 : AlterTableStmt *n = makeNode(AlterTableStmt);
2208 :
2209 0 : n->relation = $5;
2210 0 : n->cmds = $6;
2211 0 : n->objtype = OBJECT_INDEX;
2212 0 : n->missing_ok = true;
2213 0 : $$ = (Node *) n;
2214 : }
2215 : | ALTER INDEX qualified_name index_partition_cmd
2216 : {
2217 386 : AlterTableStmt *n = makeNode(AlterTableStmt);
2218 :
2219 386 : n->relation = $3;
2220 386 : n->cmds = list_make1($4);
2221 386 : n->objtype = OBJECT_INDEX;
2222 386 : n->missing_ok = false;
2223 386 : $$ = (Node *) n;
2224 : }
2225 : | ALTER INDEX ALL IN_P TABLESPACE name SET TABLESPACE name opt_nowait
2226 : {
2227 : AlterTableMoveAllStmt *n =
2228 6 : makeNode(AlterTableMoveAllStmt);
2229 :
2230 6 : n->orig_tablespacename = $6;
2231 6 : n->objtype = OBJECT_INDEX;
2232 6 : n->roles = NIL;
2233 6 : n->new_tablespacename = $9;
2234 6 : n->nowait = $10;
2235 6 : $$ = (Node *) n;
2236 : }
2237 : | ALTER INDEX ALL IN_P TABLESPACE name OWNED BY role_list SET TABLESPACE name opt_nowait
2238 : {
2239 : AlterTableMoveAllStmt *n =
2240 0 : makeNode(AlterTableMoveAllStmt);
2241 :
2242 0 : n->orig_tablespacename = $6;
2243 0 : n->objtype = OBJECT_INDEX;
2244 0 : n->roles = $9;
2245 0 : n->new_tablespacename = $12;
2246 0 : n->nowait = $13;
2247 0 : $$ = (Node *) n;
2248 : }
2249 : | ALTER SEQUENCE qualified_name alter_table_cmds
2250 : {
2251 94 : AlterTableStmt *n = makeNode(AlterTableStmt);
2252 :
2253 94 : n->relation = $3;
2254 94 : n->cmds = $4;
2255 94 : n->objtype = OBJECT_SEQUENCE;
2256 94 : n->missing_ok = false;
2257 94 : $$ = (Node *) n;
2258 : }
2259 : | ALTER SEQUENCE IF_P EXISTS qualified_name alter_table_cmds
2260 : {
2261 0 : AlterTableStmt *n = makeNode(AlterTableStmt);
2262 :
2263 0 : n->relation = $5;
2264 0 : n->cmds = $6;
2265 0 : n->objtype = OBJECT_SEQUENCE;
2266 0 : n->missing_ok = true;
2267 0 : $$ = (Node *) n;
2268 : }
2269 : | ALTER VIEW qualified_name alter_table_cmds
2270 : {
2271 254 : AlterTableStmt *n = makeNode(AlterTableStmt);
2272 :
2273 254 : n->relation = $3;
2274 254 : n->cmds = $4;
2275 254 : n->objtype = OBJECT_VIEW;
2276 254 : n->missing_ok = false;
2277 254 : $$ = (Node *) n;
2278 : }
2279 : | ALTER VIEW IF_P EXISTS qualified_name alter_table_cmds
2280 : {
2281 0 : AlterTableStmt *n = makeNode(AlterTableStmt);
2282 :
2283 0 : n->relation = $5;
2284 0 : n->cmds = $6;
2285 0 : n->objtype = OBJECT_VIEW;
2286 0 : n->missing_ok = true;
2287 0 : $$ = (Node *) n;
2288 : }
2289 : | ALTER MATERIALIZED VIEW qualified_name alter_table_cmds
2290 : {
2291 48 : AlterTableStmt *n = makeNode(AlterTableStmt);
2292 :
2293 48 : n->relation = $4;
2294 48 : n->cmds = $5;
2295 48 : n->objtype = OBJECT_MATVIEW;
2296 48 : n->missing_ok = false;
2297 48 : $$ = (Node *) n;
2298 : }
2299 : | ALTER MATERIALIZED VIEW IF_P EXISTS qualified_name alter_table_cmds
2300 : {
2301 0 : AlterTableStmt *n = makeNode(AlterTableStmt);
2302 :
2303 0 : n->relation = $6;
2304 0 : n->cmds = $7;
2305 0 : n->objtype = OBJECT_MATVIEW;
2306 0 : n->missing_ok = true;
2307 0 : $$ = (Node *) n;
2308 : }
2309 : | ALTER MATERIALIZED VIEW ALL IN_P TABLESPACE name SET TABLESPACE name opt_nowait
2310 : {
2311 : AlterTableMoveAllStmt *n =
2312 12 : makeNode(AlterTableMoveAllStmt);
2313 :
2314 12 : n->orig_tablespacename = $7;
2315 12 : n->objtype = OBJECT_MATVIEW;
2316 12 : n->roles = NIL;
2317 12 : n->new_tablespacename = $10;
2318 12 : n->nowait = $11;
2319 12 : $$ = (Node *) n;
2320 : }
2321 : | ALTER MATERIALIZED VIEW ALL IN_P TABLESPACE name OWNED BY role_list SET TABLESPACE name opt_nowait
2322 : {
2323 : AlterTableMoveAllStmt *n =
2324 0 : makeNode(AlterTableMoveAllStmt);
2325 :
2326 0 : n->orig_tablespacename = $7;
2327 0 : n->objtype = OBJECT_MATVIEW;
2328 0 : n->roles = $10;
2329 0 : n->new_tablespacename = $13;
2330 0 : n->nowait = $14;
2331 0 : $$ = (Node *) n;
2332 : }
2333 : | ALTER FOREIGN TABLE relation_expr alter_table_cmds
2334 : {
2335 378 : AlterTableStmt *n = makeNode(AlterTableStmt);
2336 :
2337 378 : n->relation = $4;
2338 378 : n->cmds = $5;
2339 378 : n->objtype = OBJECT_FOREIGN_TABLE;
2340 378 : n->missing_ok = false;
2341 378 : $$ = (Node *) n;
2342 : }
2343 : | ALTER FOREIGN TABLE IF_P EXISTS relation_expr alter_table_cmds
2344 : {
2345 108 : AlterTableStmt *n = makeNode(AlterTableStmt);
2346 :
2347 108 : n->relation = $6;
2348 108 : n->cmds = $7;
2349 108 : n->objtype = OBJECT_FOREIGN_TABLE;
2350 108 : n->missing_ok = true;
2351 108 : $$ = (Node *) n;
2352 : }
2353 : ;
2354 :
2355 : alter_table_cmds:
2356 27490 : alter_table_cmd { $$ = list_make1($1); }
2357 1020 : | alter_table_cmds ',' alter_table_cmd { $$ = lappend($1, $3); }
2358 : ;
2359 :
2360 : partition_cmd:
2361 : /* ALTER TABLE <name> ATTACH PARTITION <table_name> FOR VALUES */
2362 : ATTACH PARTITION qualified_name PartitionBoundSpec
2363 : {
2364 2430 : AlterTableCmd *n = makeNode(AlterTableCmd);
2365 2430 : PartitionCmd *cmd = makeNode(PartitionCmd);
2366 :
2367 2430 : n->subtype = AT_AttachPartition;
2368 2430 : cmd->name = $3;
2369 2430 : cmd->bound = $4;
2370 2430 : cmd->concurrent = false;
2371 2430 : n->def = (Node *) cmd;
2372 :
2373 2430 : $$ = (Node *) n;
2374 : }
2375 : /* ALTER TABLE <name> DETACH PARTITION <partition_name> [CONCURRENTLY] */
2376 : | DETACH PARTITION qualified_name opt_concurrently
2377 : {
2378 602 : AlterTableCmd *n = makeNode(AlterTableCmd);
2379 602 : PartitionCmd *cmd = makeNode(PartitionCmd);
2380 :
2381 602 : n->subtype = AT_DetachPartition;
2382 602 : cmd->name = $3;
2383 602 : cmd->bound = NULL;
2384 602 : cmd->concurrent = $4;
2385 602 : n->def = (Node *) cmd;
2386 :
2387 602 : $$ = (Node *) n;
2388 : }
2389 : | DETACH PARTITION qualified_name FINALIZE
2390 : {
2391 20 : AlterTableCmd *n = makeNode(AlterTableCmd);
2392 20 : PartitionCmd *cmd = makeNode(PartitionCmd);
2393 :
2394 20 : n->subtype = AT_DetachPartitionFinalize;
2395 20 : cmd->name = $3;
2396 20 : cmd->bound = NULL;
2397 20 : cmd->concurrent = false;
2398 20 : n->def = (Node *) cmd;
2399 20 : $$ = (Node *) n;
2400 : }
2401 : ;
2402 :
2403 : index_partition_cmd:
2404 : /* ALTER INDEX <name> ATTACH PARTITION <index_name> */
2405 : ATTACH PARTITION qualified_name
2406 : {
2407 386 : AlterTableCmd *n = makeNode(AlterTableCmd);
2408 386 : PartitionCmd *cmd = makeNode(PartitionCmd);
2409 :
2410 386 : n->subtype = AT_AttachPartition;
2411 386 : cmd->name = $3;
2412 386 : cmd->bound = NULL;
2413 386 : cmd->concurrent = false;
2414 386 : n->def = (Node *) cmd;
2415 :
2416 386 : $$ = (Node *) n;
2417 : }
2418 : ;
2419 :
2420 : alter_table_cmd:
2421 : /* ALTER TABLE <name> ADD <coldef> */
2422 : ADD_P columnDef
2423 : {
2424 192 : AlterTableCmd *n = makeNode(AlterTableCmd);
2425 :
2426 192 : n->subtype = AT_AddColumn;
2427 192 : n->def = $2;
2428 192 : n->missing_ok = false;
2429 192 : $$ = (Node *) n;
2430 : }
2431 : /* ALTER TABLE <name> ADD IF NOT EXISTS <coldef> */
2432 : | ADD_P IF_P NOT EXISTS columnDef
2433 : {
2434 0 : AlterTableCmd *n = makeNode(AlterTableCmd);
2435 :
2436 0 : n->subtype = AT_AddColumn;
2437 0 : n->def = $5;
2438 0 : n->missing_ok = true;
2439 0 : $$ = (Node *) n;
2440 : }
2441 : /* ALTER TABLE <name> ADD COLUMN <coldef> */
2442 : | ADD_P COLUMN columnDef
2443 : {
2444 1896 : AlterTableCmd *n = makeNode(AlterTableCmd);
2445 :
2446 1896 : n->subtype = AT_AddColumn;
2447 1896 : n->def = $3;
2448 1896 : n->missing_ok = false;
2449 1896 : $$ = (Node *) n;
2450 : }
2451 : /* ALTER TABLE <name> ADD COLUMN IF NOT EXISTS <coldef> */
2452 : | ADD_P COLUMN IF_P NOT EXISTS columnDef
2453 : {
2454 60 : AlterTableCmd *n = makeNode(AlterTableCmd);
2455 :
2456 60 : n->subtype = AT_AddColumn;
2457 60 : n->def = $6;
2458 60 : n->missing_ok = true;
2459 60 : $$ = (Node *) n;
2460 : }
2461 : /* ALTER TABLE <name> ALTER [COLUMN] <colname> {SET DEFAULT <expr>|DROP DEFAULT} */
2462 : | ALTER opt_column ColId alter_column_default
2463 : {
2464 550 : AlterTableCmd *n = makeNode(AlterTableCmd);
2465 :
2466 550 : n->subtype = AT_ColumnDefault;
2467 550 : n->name = $3;
2468 550 : n->def = $4;
2469 550 : $$ = (Node *) n;
2470 : }
2471 : /* ALTER TABLE <name> ALTER [COLUMN] <colname> DROP NOT NULL */
2472 : | ALTER opt_column ColId DROP NOT NULL_P
2473 : {
2474 294 : AlterTableCmd *n = makeNode(AlterTableCmd);
2475 :
2476 294 : n->subtype = AT_DropNotNull;
2477 294 : n->name = $3;
2478 294 : $$ = (Node *) n;
2479 : }
2480 : /* ALTER TABLE <name> ALTER [COLUMN] <colname> SET NOT NULL */
2481 : | ALTER opt_column ColId SET NOT NULL_P
2482 : {
2483 434 : AlterTableCmd *n = makeNode(AlterTableCmd);
2484 :
2485 434 : n->subtype = AT_SetNotNull;
2486 434 : n->name = $3;
2487 434 : $$ = (Node *) n;
2488 : }
2489 : /* ALTER TABLE <name> ALTER [COLUMN] <colname> SET EXPRESSION AS <expr> */
2490 : | ALTER opt_column ColId SET EXPRESSION AS '(' a_expr ')'
2491 : {
2492 168 : AlterTableCmd *n = makeNode(AlterTableCmd);
2493 :
2494 168 : n->subtype = AT_SetExpression;
2495 168 : n->name = $3;
2496 168 : n->def = $8;
2497 168 : $$ = (Node *) n;
2498 : }
2499 : /* ALTER TABLE <name> ALTER [COLUMN] <colname> DROP EXPRESSION */
2500 : | ALTER opt_column ColId DROP EXPRESSION
2501 : {
2502 62 : AlterTableCmd *n = makeNode(AlterTableCmd);
2503 :
2504 62 : n->subtype = AT_DropExpression;
2505 62 : n->name = $3;
2506 62 : $$ = (Node *) n;
2507 : }
2508 : /* ALTER TABLE <name> ALTER [COLUMN] <colname> DROP EXPRESSION IF EXISTS */
2509 : | ALTER opt_column ColId DROP EXPRESSION IF_P EXISTS
2510 : {
2511 12 : AlterTableCmd *n = makeNode(AlterTableCmd);
2512 :
2513 12 : n->subtype = AT_DropExpression;
2514 12 : n->name = $3;
2515 12 : n->missing_ok = true;
2516 12 : $$ = (Node *) n;
2517 : }
2518 : /* ALTER TABLE <name> ALTER [COLUMN] <colname> SET STATISTICS */
2519 : | ALTER opt_column ColId SET STATISTICS set_statistics_value
2520 : {
2521 62 : AlterTableCmd *n = makeNode(AlterTableCmd);
2522 :
2523 62 : n->subtype = AT_SetStatistics;
2524 62 : n->name = $3;
2525 62 : n->def = $6;
2526 62 : $$ = (Node *) n;
2527 : }
2528 : /* ALTER TABLE <name> ALTER [COLUMN] <colnum> SET STATISTICS */
2529 : | ALTER opt_column Iconst SET STATISTICS set_statistics_value
2530 : {
2531 70 : AlterTableCmd *n = makeNode(AlterTableCmd);
2532 :
2533 70 : if ($3 <= 0 || $3 > PG_INT16_MAX)
2534 6 : ereport(ERROR,
2535 : (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
2536 : errmsg("column number must be in range from 1 to %d", PG_INT16_MAX),
2537 : parser_errposition(@3)));
2538 :
2539 64 : n->subtype = AT_SetStatistics;
2540 64 : n->num = (int16) $3;
2541 64 : n->def = $6;
2542 64 : $$ = (Node *) n;
2543 : }
2544 : /* ALTER TABLE <name> ALTER [COLUMN] <colname> SET ( column_parameter = value [, ... ] ) */
2545 : | ALTER opt_column ColId SET reloptions
2546 : {
2547 38 : AlterTableCmd *n = makeNode(AlterTableCmd);
2548 :
2549 38 : n->subtype = AT_SetOptions;
2550 38 : n->name = $3;
2551 38 : n->def = (Node *) $5;
2552 38 : $$ = (Node *) n;
2553 : }
2554 : /* ALTER TABLE <name> ALTER [COLUMN] <colname> RESET ( column_parameter [, ... ] ) */
2555 : | ALTER opt_column ColId RESET reloptions
2556 : {
2557 6 : AlterTableCmd *n = makeNode(AlterTableCmd);
2558 :
2559 6 : n->subtype = AT_ResetOptions;
2560 6 : n->name = $3;
2561 6 : n->def = (Node *) $5;
2562 6 : $$ = (Node *) n;
2563 : }
2564 : /* ALTER TABLE <name> ALTER [COLUMN] <colname> SET STORAGE <storagemode> */
2565 : | ALTER opt_column ColId SET column_storage
2566 : {
2567 236 : AlterTableCmd *n = makeNode(AlterTableCmd);
2568 :
2569 236 : n->subtype = AT_SetStorage;
2570 236 : n->name = $3;
2571 236 : n->def = (Node *) makeString($5);
2572 236 : $$ = (Node *) n;
2573 : }
2574 : /* ALTER TABLE <name> ALTER [COLUMN] <colname> SET COMPRESSION <cm> */
2575 : | ALTER opt_column ColId SET column_compression
2576 : {
2577 78 : AlterTableCmd *n = makeNode(AlterTableCmd);
2578 :
2579 78 : n->subtype = AT_SetCompression;
2580 78 : n->name = $3;
2581 78 : n->def = (Node *) makeString($5);
2582 78 : $$ = (Node *) n;
2583 : }
2584 : /* ALTER TABLE <name> ALTER [COLUMN] <colname> ADD GENERATED ... AS IDENTITY ... */
2585 : | ALTER opt_column ColId ADD_P GENERATED generated_when AS IDENTITY_P OptParenthesizedSeqOptList
2586 : {
2587 166 : AlterTableCmd *n = makeNode(AlterTableCmd);
2588 166 : Constraint *c = makeNode(Constraint);
2589 :
2590 166 : c->contype = CONSTR_IDENTITY;
2591 166 : c->generated_when = $6;
2592 166 : c->options = $9;
2593 166 : c->location = @5;
2594 :
2595 166 : n->subtype = AT_AddIdentity;
2596 166 : n->name = $3;
2597 166 : n->def = (Node *) c;
2598 :
2599 166 : $$ = (Node *) n;
2600 : }
2601 : /* ALTER TABLE <name> ALTER [COLUMN] <colname> SET <sequence options>/RESET */
2602 : | ALTER opt_column ColId alter_identity_column_option_list
2603 : {
2604 62 : AlterTableCmd *n = makeNode(AlterTableCmd);
2605 :
2606 62 : n->subtype = AT_SetIdentity;
2607 62 : n->name = $3;
2608 62 : n->def = (Node *) $4;
2609 62 : $$ = (Node *) n;
2610 : }
2611 : /* ALTER TABLE <name> ALTER [COLUMN] <colname> DROP IDENTITY */
2612 : | ALTER opt_column ColId DROP IDENTITY_P
2613 : {
2614 50 : AlterTableCmd *n = makeNode(AlterTableCmd);
2615 :
2616 50 : n->subtype = AT_DropIdentity;
2617 50 : n->name = $3;
2618 50 : n->missing_ok = false;
2619 50 : $$ = (Node *) n;
2620 : }
2621 : /* ALTER TABLE <name> ALTER [COLUMN] <colname> DROP IDENTITY IF EXISTS */
2622 : | ALTER opt_column ColId DROP IDENTITY_P IF_P EXISTS
2623 : {
2624 6 : AlterTableCmd *n = makeNode(AlterTableCmd);
2625 :
2626 6 : n->subtype = AT_DropIdentity;
2627 6 : n->name = $3;
2628 6 : n->missing_ok = true;
2629 6 : $$ = (Node *) n;
2630 : }
2631 : /* ALTER TABLE <name> DROP [COLUMN] IF EXISTS <colname> [RESTRICT|CASCADE] */
2632 : | DROP opt_column IF_P EXISTS ColId opt_drop_behavior
2633 : {
2634 18 : AlterTableCmd *n = makeNode(AlterTableCmd);
2635 :
2636 18 : n->subtype = AT_DropColumn;
2637 18 : n->name = $5;
2638 18 : n->behavior = $6;
2639 18 : n->missing_ok = true;
2640 18 : $$ = (Node *) n;
2641 : }
2642 : /* ALTER TABLE <name> DROP [COLUMN] <colname> [RESTRICT|CASCADE] */
2643 : | DROP opt_column ColId opt_drop_behavior
2644 : {
2645 1574 : AlterTableCmd *n = makeNode(AlterTableCmd);
2646 :
2647 1574 : n->subtype = AT_DropColumn;
2648 1574 : n->name = $3;
2649 1574 : n->behavior = $4;
2650 1574 : n->missing_ok = false;
2651 1574 : $$ = (Node *) n;
2652 : }
2653 : /*
2654 : * ALTER TABLE <name> ALTER [COLUMN] <colname> [SET DATA] TYPE <typename>
2655 : * [ USING <expression> ]
2656 : */
2657 : | ALTER opt_column ColId opt_set_data TYPE_P Typename opt_collate_clause alter_using
2658 : {
2659 1024 : AlterTableCmd *n = makeNode(AlterTableCmd);
2660 1024 : ColumnDef *def = makeNode(ColumnDef);
2661 :
2662 1024 : n->subtype = AT_AlterColumnType;
2663 1024 : n->name = $3;
2664 1024 : n->def = (Node *) def;
2665 : /* We only use these fields of the ColumnDef node */
2666 1024 : def->typeName = $6;
2667 1024 : def->collClause = (CollateClause *) $7;
2668 1024 : def->raw_default = $8;
2669 1024 : def->location = @3;
2670 1024 : $$ = (Node *) n;
2671 : }
2672 : /* ALTER FOREIGN TABLE <name> ALTER [COLUMN] <colname> OPTIONS */
2673 : | ALTER opt_column ColId alter_generic_options
2674 : {
2675 50 : AlterTableCmd *n = makeNode(AlterTableCmd);
2676 :
2677 50 : n->subtype = AT_AlterColumnGenericOptions;
2678 50 : n->name = $3;
2679 50 : n->def = (Node *) $4;
2680 50 : $$ = (Node *) n;
2681 : }
2682 : /* ALTER TABLE <name> ADD CONSTRAINT ... */
2683 : | ADD_P TableConstraint
2684 : {
2685 14554 : AlterTableCmd *n = makeNode(AlterTableCmd);
2686 :
2687 14554 : n->subtype = AT_AddConstraint;
2688 14554 : n->def = $2;
2689 14554 : $$ = (Node *) n;
2690 : }
2691 : /* ALTER TABLE <name> ALTER CONSTRAINT ... */
2692 : | ALTER CONSTRAINT name ConstraintAttributeSpec
2693 : {
2694 240 : AlterTableCmd *n = makeNode(AlterTableCmd);
2695 240 : ATAlterConstraint *c = makeNode(ATAlterConstraint);
2696 :
2697 240 : n->subtype = AT_AlterConstraint;
2698 240 : n->def = (Node *) c;
2699 240 : c->conname = $3;
2700 240 : if ($4 & (CAS_NOT_ENFORCED | CAS_ENFORCED))
2701 84 : c->alterEnforceability = true;
2702 240 : if ($4 & (CAS_DEFERRABLE | CAS_NOT_DEFERRABLE |
2703 : CAS_INITIALLY_DEFERRED | CAS_INITIALLY_IMMEDIATE))
2704 120 : c->alterDeferrability = true;
2705 240 : if ($4 & CAS_NO_INHERIT)
2706 30 : c->alterInheritability = true;
2707 : /* handle unsupported case with specific error message */
2708 240 : if ($4 & CAS_NOT_VALID)
2709 12 : ereport(ERROR,
2710 : errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
2711 : errmsg("constraints cannot be altered to be NOT VALID"),
2712 : parser_errposition(@4));
2713 228 : processCASbits($4, @4, "FOREIGN KEY",
2714 : &c->deferrable,
2715 : &c->initdeferred,
2716 : &c->is_enforced,
2717 : NULL,
2718 : &c->noinherit,
2719 : yyscanner);
2720 228 : $$ = (Node *) n;
2721 : }
2722 : /* ALTER TABLE <name> ALTER CONSTRAINT INHERIT */
2723 : | ALTER CONSTRAINT name INHERIT
2724 : {
2725 66 : AlterTableCmd *n = makeNode(AlterTableCmd);
2726 66 : ATAlterConstraint *c = makeNode(ATAlterConstraint);
2727 :
2728 66 : n->subtype = AT_AlterConstraint;
2729 66 : n->def = (Node *) c;
2730 66 : c->conname = $3;
2731 66 : c->alterInheritability = true;
2732 66 : c->noinherit = false;
2733 :
2734 66 : $$ = (Node *) n;
2735 : }
2736 : /* ALTER TABLE <name> VALIDATE CONSTRAINT ... */
2737 : | VALIDATE CONSTRAINT name
2738 : {
2739 476 : AlterTableCmd *n = makeNode(AlterTableCmd);
2740 :
2741 476 : n->subtype = AT_ValidateConstraint;
2742 476 : n->name = $3;
2743 476 : $$ = (Node *) n;
2744 : }
2745 : /* ALTER TABLE <name> DROP CONSTRAINT IF EXISTS <name> [RESTRICT|CASCADE] */
2746 : | DROP CONSTRAINT IF_P EXISTS name opt_drop_behavior
2747 : {
2748 18 : AlterTableCmd *n = makeNode(AlterTableCmd);
2749 :
2750 18 : n->subtype = AT_DropConstraint;
2751 18 : n->name = $5;
2752 18 : n->behavior = $6;
2753 18 : n->missing_ok = true;
2754 18 : $$ = (Node *) n;
2755 : }
2756 : /* ALTER TABLE <name> DROP CONSTRAINT <name> [RESTRICT|CASCADE] */
2757 : | DROP CONSTRAINT name opt_drop_behavior
2758 : {
2759 818 : AlterTableCmd *n = makeNode(AlterTableCmd);
2760 :
2761 818 : n->subtype = AT_DropConstraint;
2762 818 : n->name = $3;
2763 818 : n->behavior = $4;
2764 818 : n->missing_ok = false;
2765 818 : $$ = (Node *) n;
2766 : }
2767 : /* ALTER TABLE <name> SET WITHOUT OIDS, for backward compat */
2768 : | SET WITHOUT OIDS
2769 : {
2770 6 : AlterTableCmd *n = makeNode(AlterTableCmd);
2771 :
2772 6 : n->subtype = AT_DropOids;
2773 6 : $$ = (Node *) n;
2774 : }
2775 : /* ALTER TABLE <name> CLUSTER ON <indexname> */
2776 : | CLUSTER ON name
2777 : {
2778 46 : AlterTableCmd *n = makeNode(AlterTableCmd);
2779 :
2780 46 : n->subtype = AT_ClusterOn;
2781 46 : n->name = $3;
2782 46 : $$ = (Node *) n;
2783 : }
2784 : /* ALTER TABLE <name> SET WITHOUT CLUSTER */
2785 : | SET WITHOUT CLUSTER
2786 : {
2787 18 : AlterTableCmd *n = makeNode(AlterTableCmd);
2788 :
2789 18 : n->subtype = AT_DropCluster;
2790 18 : n->name = NULL;
2791 18 : $$ = (Node *) n;
2792 : }
2793 : /* ALTER TABLE <name> SET LOGGED */
2794 : | SET LOGGED
2795 : {
2796 50 : AlterTableCmd *n = makeNode(AlterTableCmd);
2797 :
2798 50 : n->subtype = AT_SetLogged;
2799 50 : $$ = (Node *) n;
2800 : }
2801 : /* ALTER TABLE <name> SET UNLOGGED */
2802 : | SET UNLOGGED
2803 : {
2804 62 : AlterTableCmd *n = makeNode(AlterTableCmd);
2805 :
2806 62 : n->subtype = AT_SetUnLogged;
2807 62 : $$ = (Node *) n;
2808 : }
2809 : /* ALTER TABLE <name> ENABLE TRIGGER <trig> */
2810 : | ENABLE_P TRIGGER name
2811 : {
2812 122 : AlterTableCmd *n = makeNode(AlterTableCmd);
2813 :
2814 122 : n->subtype = AT_EnableTrig;
2815 122 : n->name = $3;
2816 122 : $$ = (Node *) n;
2817 : }
2818 : /* ALTER TABLE <name> ENABLE ALWAYS TRIGGER <trig> */
2819 : | ENABLE_P ALWAYS TRIGGER name
2820 : {
2821 42 : AlterTableCmd *n = makeNode(AlterTableCmd);
2822 :
2823 42 : n->subtype = AT_EnableAlwaysTrig;
2824 42 : n->name = $4;
2825 42 : $$ = (Node *) n;
2826 : }
2827 : /* ALTER TABLE <name> ENABLE REPLICA TRIGGER <trig> */
2828 : | ENABLE_P REPLICA TRIGGER name
2829 : {
2830 16 : AlterTableCmd *n = makeNode(AlterTableCmd);
2831 :
2832 16 : n->subtype = AT_EnableReplicaTrig;
2833 16 : n->name = $4;
2834 16 : $$ = (Node *) n;
2835 : }
2836 : /* ALTER TABLE <name> ENABLE TRIGGER ALL */
2837 : | ENABLE_P TRIGGER ALL
2838 : {
2839 0 : AlterTableCmd *n = makeNode(AlterTableCmd);
2840 :
2841 0 : n->subtype = AT_EnableTrigAll;
2842 0 : $$ = (Node *) n;
2843 : }
2844 : /* ALTER TABLE <name> ENABLE TRIGGER USER */
2845 : | ENABLE_P TRIGGER USER
2846 : {
2847 0 : AlterTableCmd *n = makeNode(AlterTableCmd);
2848 :
2849 0 : n->subtype = AT_EnableTrigUser;
2850 0 : $$ = (Node *) n;
2851 : }
2852 : /* ALTER TABLE <name> DISABLE TRIGGER <trig> */
2853 : | DISABLE_P TRIGGER name
2854 : {
2855 138 : AlterTableCmd *n = makeNode(AlterTableCmd);
2856 :
2857 138 : n->subtype = AT_DisableTrig;
2858 138 : n->name = $3;
2859 138 : $$ = (Node *) n;
2860 : }
2861 : /* ALTER TABLE <name> DISABLE TRIGGER ALL */
2862 : | DISABLE_P TRIGGER ALL
2863 : {
2864 12 : AlterTableCmd *n = makeNode(AlterTableCmd);
2865 :
2866 12 : n->subtype = AT_DisableTrigAll;
2867 12 : $$ = (Node *) n;
2868 : }
2869 : /* ALTER TABLE <name> DISABLE TRIGGER USER */
2870 : | DISABLE_P TRIGGER USER
2871 : {
2872 12 : AlterTableCmd *n = makeNode(AlterTableCmd);
2873 :
2874 12 : n->subtype = AT_DisableTrigUser;
2875 12 : $$ = (Node *) n;
2876 : }
2877 : /* ALTER TABLE <name> ENABLE RULE <rule> */
2878 : | ENABLE_P RULE name
2879 : {
2880 8 : AlterTableCmd *n = makeNode(AlterTableCmd);
2881 :
2882 8 : n->subtype = AT_EnableRule;
2883 8 : n->name = $3;
2884 8 : $$ = (Node *) n;
2885 : }
2886 : /* ALTER TABLE <name> ENABLE ALWAYS RULE <rule> */
2887 : | ENABLE_P ALWAYS RULE name
2888 : {
2889 0 : AlterTableCmd *n = makeNode(AlterTableCmd);
2890 :
2891 0 : n->subtype = AT_EnableAlwaysRule;
2892 0 : n->name = $4;
2893 0 : $$ = (Node *) n;
2894 : }
2895 : /* ALTER TABLE <name> ENABLE REPLICA RULE <rule> */
2896 : | ENABLE_P REPLICA RULE name
2897 : {
2898 6 : AlterTableCmd *n = makeNode(AlterTableCmd);
2899 :
2900 6 : n->subtype = AT_EnableReplicaRule;
2901 6 : n->name = $4;
2902 6 : $$ = (Node *) n;
2903 : }
2904 : /* ALTER TABLE <name> DISABLE RULE <rule> */
2905 : | DISABLE_P RULE name
2906 : {
2907 32 : AlterTableCmd *n = makeNode(AlterTableCmd);
2908 :
2909 32 : n->subtype = AT_DisableRule;
2910 32 : n->name = $3;
2911 32 : $$ = (Node *) n;
2912 : }
2913 : /* ALTER TABLE <name> INHERIT <parent> */
2914 : | INHERIT qualified_name
2915 : {
2916 462 : AlterTableCmd *n = makeNode(AlterTableCmd);
2917 :
2918 462 : n->subtype = AT_AddInherit;
2919 462 : n->def = (Node *) $2;
2920 462 : $$ = (Node *) n;
2921 : }
2922 : /* ALTER TABLE <name> NO INHERIT <parent> */
2923 : | NO INHERIT qualified_name
2924 : {
2925 94 : AlterTableCmd *n = makeNode(AlterTableCmd);
2926 :
2927 94 : n->subtype = AT_DropInherit;
2928 94 : n->def = (Node *) $3;
2929 94 : $$ = (Node *) n;
2930 : }
2931 : /* ALTER TABLE <name> OF <type_name> */
2932 : | OF any_name
2933 : {
2934 66 : AlterTableCmd *n = makeNode(AlterTableCmd);
2935 66 : TypeName *def = makeTypeNameFromNameList($2);
2936 :
2937 66 : def->location = @2;
2938 66 : n->subtype = AT_AddOf;
2939 66 : n->def = (Node *) def;
2940 66 : $$ = (Node *) n;
2941 : }
2942 : /* ALTER TABLE <name> NOT OF */
2943 : | NOT OF
2944 : {
2945 6 : AlterTableCmd *n = makeNode(AlterTableCmd);
2946 :
2947 6 : n->subtype = AT_DropOf;
2948 6 : $$ = (Node *) n;
2949 : }
2950 : /* ALTER TABLE <name> OWNER TO RoleSpec */
2951 : | OWNER TO RoleSpec
2952 : {
2953 2022 : AlterTableCmd *n = makeNode(AlterTableCmd);
2954 :
2955 2022 : n->subtype = AT_ChangeOwner;
2956 2022 : n->newowner = $3;
2957 2022 : $$ = (Node *) n;
2958 : }
2959 : /* ALTER TABLE <name> SET ACCESS METHOD { <amname> | DEFAULT } */
2960 : | SET ACCESS METHOD set_access_method_name
2961 : {
2962 128 : AlterTableCmd *n = makeNode(AlterTableCmd);
2963 :
2964 128 : n->subtype = AT_SetAccessMethod;
2965 128 : n->name = $4;
2966 128 : $$ = (Node *) n;
2967 : }
2968 : /* ALTER TABLE <name> SET TABLESPACE <tablespacename> */
2969 : | SET TABLESPACE name
2970 : {
2971 104 : AlterTableCmd *n = makeNode(AlterTableCmd);
2972 :
2973 104 : n->subtype = AT_SetTableSpace;
2974 104 : n->name = $3;
2975 104 : $$ = (Node *) n;
2976 : }
2977 : /* ALTER TABLE <name> SET (...) */
2978 : | SET reloptions
2979 : {
2980 600 : AlterTableCmd *n = makeNode(AlterTableCmd);
2981 :
2982 600 : n->subtype = AT_SetRelOptions;
2983 600 : n->def = (Node *) $2;
2984 600 : $$ = (Node *) n;
2985 : }
2986 : /* ALTER TABLE <name> RESET (...) */
2987 : | RESET reloptions
2988 : {
2989 170 : AlterTableCmd *n = makeNode(AlterTableCmd);
2990 :
2991 170 : n->subtype = AT_ResetRelOptions;
2992 170 : n->def = (Node *) $2;
2993 170 : $$ = (Node *) n;
2994 : }
2995 : /* ALTER TABLE <name> REPLICA IDENTITY */
2996 : | REPLICA IDENTITY_P replica_identity
2997 : {
2998 494 : AlterTableCmd *n = makeNode(AlterTableCmd);
2999 :
3000 494 : n->subtype = AT_ReplicaIdentity;
3001 494 : n->def = $3;
3002 494 : $$ = (Node *) n;
3003 : }
3004 : /* ALTER TABLE <name> ENABLE ROW LEVEL SECURITY */
3005 : | ENABLE_P ROW LEVEL SECURITY
3006 : {
3007 326 : AlterTableCmd *n = makeNode(AlterTableCmd);
3008 :
3009 326 : n->subtype = AT_EnableRowSecurity;
3010 326 : $$ = (Node *) n;
3011 : }
3012 : /* ALTER TABLE <name> DISABLE ROW LEVEL SECURITY */
3013 : | DISABLE_P ROW LEVEL SECURITY
3014 : {
3015 10 : AlterTableCmd *n = makeNode(AlterTableCmd);
3016 :
3017 10 : n->subtype = AT_DisableRowSecurity;
3018 10 : $$ = (Node *) n;
3019 : }
3020 : /* ALTER TABLE <name> FORCE ROW LEVEL SECURITY */
3021 : | FORCE ROW LEVEL SECURITY
3022 : {
3023 100 : AlterTableCmd *n = makeNode(AlterTableCmd);
3024 :
3025 100 : n->subtype = AT_ForceRowSecurity;
3026 100 : $$ = (Node *) n;
3027 : }
3028 : /* ALTER TABLE <name> NO FORCE ROW LEVEL SECURITY */
3029 : | NO FORCE ROW LEVEL SECURITY
3030 : {
3031 32 : AlterTableCmd *n = makeNode(AlterTableCmd);
3032 :
3033 32 : n->subtype = AT_NoForceRowSecurity;
3034 32 : $$ = (Node *) n;
3035 : }
3036 : | alter_generic_options
3037 : {
3038 64 : AlterTableCmd *n = makeNode(AlterTableCmd);
3039 :
3040 64 : n->subtype = AT_GenericOptions;
3041 64 : n->def = (Node *) $1;
3042 64 : $$ = (Node *) n;
3043 : }
3044 : ;
3045 :
3046 : alter_column_default:
3047 378 : SET DEFAULT a_expr { $$ = $3; }
3048 186 : | DROP DEFAULT { $$ = NULL; }
3049 : ;
3050 :
3051 : opt_collate_clause:
3052 : COLLATE any_name
3053 : {
3054 18 : CollateClause *n = makeNode(CollateClause);
3055 :
3056 18 : n->arg = NULL;
3057 18 : n->collname = $2;
3058 18 : n->location = @1;
3059 18 : $$ = (Node *) n;
3060 : }
3061 4728 : | /* EMPTY */ { $$ = NULL; }
3062 : ;
3063 :
3064 : alter_using:
3065 180 : USING a_expr { $$ = $2; }
3066 844 : | /* EMPTY */ { $$ = NULL; }
3067 : ;
3068 :
3069 : replica_identity:
3070 : NOTHING
3071 : {
3072 48 : ReplicaIdentityStmt *n = makeNode(ReplicaIdentityStmt);
3073 :
3074 48 : n->identity_type = REPLICA_IDENTITY_NOTHING;
3075 48 : n->name = NULL;
3076 48 : $$ = (Node *) n;
3077 : }
3078 : | FULL
3079 : {
3080 170 : ReplicaIdentityStmt *n = makeNode(ReplicaIdentityStmt);
3081 :
3082 170 : n->identity_type = REPLICA_IDENTITY_FULL;
3083 170 : n->name = NULL;
3084 170 : $$ = (Node *) n;
3085 : }
3086 : | DEFAULT
3087 : {
3088 6 : ReplicaIdentityStmt *n = makeNode(ReplicaIdentityStmt);
3089 :
3090 6 : n->identity_type = REPLICA_IDENTITY_DEFAULT;
3091 6 : n->name = NULL;
3092 6 : $$ = (Node *) n;
3093 : }
3094 : | USING INDEX name
3095 : {
3096 270 : ReplicaIdentityStmt *n = makeNode(ReplicaIdentityStmt);
3097 :
3098 270 : n->identity_type = REPLICA_IDENTITY_INDEX;
3099 270 : n->name = $3;
3100 270 : $$ = (Node *) n;
3101 : }
3102 : ;
3103 :
3104 : reloptions:
3105 2698 : '(' reloption_list ')' { $$ = $2; }
3106 : ;
3107 :
3108 964 : opt_reloptions: WITH reloptions { $$ = $2; }
3109 23392 : | /* EMPTY */ { $$ = NIL; }
3110 : ;
3111 :
3112 : reloption_list:
3113 2698 : reloption_elem { $$ = list_make1($1); }
3114 250 : | reloption_list ',' reloption_elem { $$ = lappend($1, $3); }
3115 : ;
3116 :
3117 : /* This should match def_elem and also allow qualified names */
3118 : reloption_elem:
3119 : ColLabel '=' def_arg
3120 : {
3121 2286 : $$ = makeDefElem($1, (Node *) $3, @1);
3122 : }
3123 : | ColLabel
3124 : {
3125 584 : $$ = makeDefElem($1, NULL, @1);
3126 : }
3127 : | ColLabel '.' ColLabel '=' def_arg
3128 : {
3129 72 : $$ = makeDefElemExtended($1, $3, (Node *) $5,
3130 72 : DEFELEM_UNSPEC, @1);
3131 : }
3132 : | ColLabel '.' ColLabel
3133 : {
3134 6 : $$ = makeDefElemExtended($1, $3, NULL, DEFELEM_UNSPEC, @1);
3135 : }
3136 : ;
3137 :
3138 : alter_identity_column_option_list:
3139 : alter_identity_column_option
3140 62 : { $$ = list_make1($1); }
3141 : | alter_identity_column_option_list alter_identity_column_option
3142 60 : { $$ = lappend($1, $2); }
3143 : ;
3144 :
3145 : alter_identity_column_option:
3146 : RESTART
3147 : {
3148 24 : $$ = makeDefElem("restart", NULL, @1);
3149 : }
3150 : | RESTART opt_with NumericOnly
3151 : {
3152 0 : $$ = makeDefElem("restart", (Node *) $3, @1);
3153 : }
3154 : | SET SeqOptElem
3155 : {
3156 54 : if (strcmp($2->defname, "as") == 0 ||
3157 54 : strcmp($2->defname, "restart") == 0 ||
3158 54 : strcmp($2->defname, "owned_by") == 0)
3159 0 : ereport(ERROR,
3160 : (errcode(ERRCODE_SYNTAX_ERROR),
3161 : errmsg("sequence option \"%s\" not supported here", $2->defname),
3162 : parser_errposition(@2)));
3163 54 : $$ = $2;
3164 : }
3165 : | SET GENERATED generated_when
3166 : {
3167 44 : $$ = makeDefElem("generated", (Node *) makeInteger($3), @1);
3168 : }
3169 : ;
3170 :
3171 : set_statistics_value:
3172 158 : SignedIconst { $$ = (Node *) makeInteger($1); }
3173 0 : | DEFAULT { $$ = NULL; }
3174 : ;
3175 :
3176 : set_access_method_name:
3177 92 : ColId { $$ = $1; }
3178 36 : | DEFAULT { $$ = NULL; }
3179 : ;
3180 :
3181 : PartitionBoundSpec:
3182 : /* a HASH partition */
3183 : FOR VALUES WITH '(' hash_partbound ')'
3184 : {
3185 : ListCell *lc;
3186 720 : PartitionBoundSpec *n = makeNode(PartitionBoundSpec);
3187 :
3188 720 : n->strategy = PARTITION_STRATEGY_HASH;
3189 720 : n->modulus = n->remainder = -1;
3190 :
3191 2160 : foreach (lc, $5)
3192 : {
3193 1440 : DefElem *opt = lfirst_node(DefElem, lc);
3194 :
3195 1440 : if (strcmp(opt->defname, "modulus") == 0)
3196 : {
3197 720 : if (n->modulus != -1)
3198 0 : ereport(ERROR,
3199 : (errcode(ERRCODE_DUPLICATE_OBJECT),
3200 : errmsg("modulus for hash partition provided more than once"),
3201 : parser_errposition(opt->location)));
3202 720 : n->modulus = defGetInt32(opt);
3203 : }
3204 720 : else if (strcmp(opt->defname, "remainder") == 0)
3205 : {
3206 720 : if (n->remainder != -1)
3207 0 : ereport(ERROR,
3208 : (errcode(ERRCODE_DUPLICATE_OBJECT),
3209 : errmsg("remainder for hash partition provided more than once"),
3210 : parser_errposition(opt->location)));
3211 720 : n->remainder = defGetInt32(opt);
3212 : }
3213 : else
3214 0 : ereport(ERROR,
3215 : (errcode(ERRCODE_SYNTAX_ERROR),
3216 : errmsg("unrecognized hash partition bound specification \"%s\"",
3217 : opt->defname),
3218 : parser_errposition(opt->location)));
3219 : }
3220 :
3221 720 : if (n->modulus == -1)
3222 0 : ereport(ERROR,
3223 : (errcode(ERRCODE_SYNTAX_ERROR),
3224 : errmsg("modulus for hash partition must be specified"),
3225 : parser_errposition(@3)));
3226 720 : if (n->remainder == -1)
3227 0 : ereport(ERROR,
3228 : (errcode(ERRCODE_SYNTAX_ERROR),
3229 : errmsg("remainder for hash partition must be specified"),
3230 : parser_errposition(@3)));
3231 :
3232 720 : n->location = @3;
3233 :
3234 720 : $$ = n;
3235 : }
3236 :
3237 : /* a LIST partition */
3238 : | FOR VALUES IN_P '(' expr_list ')'
3239 : {
3240 4944 : PartitionBoundSpec *n = makeNode(PartitionBoundSpec);
3241 :
3242 4944 : n->strategy = PARTITION_STRATEGY_LIST;
3243 4944 : n->is_default = false;
3244 4944 : n->listdatums = $5;
3245 4944 : n->location = @3;
3246 :
3247 4944 : $$ = n;
3248 : }
3249 :
3250 : /* a RANGE partition */
3251 : | FOR VALUES FROM '(' expr_list ')' TO '(' expr_list ')'
3252 : {
3253 4166 : PartitionBoundSpec *n = makeNode(PartitionBoundSpec);
3254 :
3255 4166 : n->strategy = PARTITION_STRATEGY_RANGE;
3256 4166 : n->is_default = false;
3257 4166 : n->lowerdatums = $5;
3258 4166 : n->upperdatums = $9;
3259 4166 : n->location = @3;
3260 :
3261 4166 : $$ = n;
3262 : }
3263 :
3264 : /* a DEFAULT partition */
3265 : | DEFAULT
3266 : {
3267 598 : PartitionBoundSpec *n = makeNode(PartitionBoundSpec);
3268 :
3269 598 : n->is_default = true;
3270 598 : n->location = @1;
3271 :
3272 598 : $$ = n;
3273 : }
3274 : ;
3275 :
3276 : hash_partbound_elem:
3277 : NonReservedWord Iconst
3278 : {
3279 1440 : $$ = makeDefElem($1, (Node *) makeInteger($2), @1);
3280 : }
3281 : ;
3282 :
3283 : hash_partbound:
3284 : hash_partbound_elem
3285 : {
3286 720 : $$ = list_make1($1);
3287 : }
3288 : | hash_partbound ',' hash_partbound_elem
3289 : {
3290 720 : $$ = lappend($1, $3);
3291 : }
3292 : ;
3293 :
3294 : /*****************************************************************************
3295 : *
3296 : * ALTER TYPE
3297 : *
3298 : * really variants of the ALTER TABLE subcommands with different spellings
3299 : *****************************************************************************/
3300 :
3301 : AlterCompositeTypeStmt:
3302 : ALTER TYPE_P any_name alter_type_cmds
3303 : {
3304 210 : AlterTableStmt *n = makeNode(AlterTableStmt);
3305 :
3306 : /* can't use qualified_name, sigh */
3307 210 : n->relation = makeRangeVarFromAnyName($3, @3, yyscanner);
3308 210 : n->cmds = $4;
3309 210 : n->objtype = OBJECT_TYPE;
3310 210 : $$ = (Node *) n;
3311 : }
3312 : ;
3313 :
3314 : alter_type_cmds:
3315 210 : alter_type_cmd { $$ = list_make1($1); }
3316 12 : | alter_type_cmds ',' alter_type_cmd { $$ = lappend($1, $3); }
3317 : ;
3318 :
3319 : alter_type_cmd:
3320 : /* ALTER TYPE <name> ADD ATTRIBUTE <coldef> [RESTRICT|CASCADE] */
3321 : ADD_P ATTRIBUTE TableFuncElement opt_drop_behavior
3322 : {
3323 64 : AlterTableCmd *n = makeNode(AlterTableCmd);
3324 :
3325 64 : n->subtype = AT_AddColumn;
3326 64 : n->def = $3;
3327 64 : n->behavior = $4;
3328 64 : $$ = (Node *) n;
3329 : }
3330 : /* ALTER TYPE <name> DROP ATTRIBUTE IF EXISTS <attname> [RESTRICT|CASCADE] */
3331 : | DROP ATTRIBUTE IF_P EXISTS ColId opt_drop_behavior
3332 : {
3333 6 : AlterTableCmd *n = makeNode(AlterTableCmd);
3334 :
3335 6 : n->subtype = AT_DropColumn;
3336 6 : n->name = $5;
3337 6 : n->behavior = $6;
3338 6 : n->missing_ok = true;
3339 6 : $$ = (Node *) n;
3340 : }
3341 : /* ALTER TYPE <name> DROP ATTRIBUTE <attname> [RESTRICT|CASCADE] */
3342 : | DROP ATTRIBUTE ColId opt_drop_behavior
3343 : {
3344 78 : AlterTableCmd *n = makeNode(AlterTableCmd);
3345 :
3346 78 : n->subtype = AT_DropColumn;
3347 78 : n->name = $3;
3348 78 : n->behavior = $4;
3349 78 : n->missing_ok = false;
3350 78 : $$ = (Node *) n;
3351 : }
3352 : /* ALTER TYPE <name> ALTER ATTRIBUTE <attname> [SET DATA] TYPE <typename> [RESTRICT|CASCADE] */
3353 : | ALTER ATTRIBUTE ColId opt_set_data TYPE_P Typename opt_collate_clause opt_drop_behavior
3354 : {
3355 74 : AlterTableCmd *n = makeNode(AlterTableCmd);
3356 74 : ColumnDef *def = makeNode(ColumnDef);
3357 :
3358 74 : n->subtype = AT_AlterColumnType;
3359 74 : n->name = $3;
3360 74 : n->def = (Node *) def;
3361 74 : n->behavior = $8;
3362 : /* We only use these fields of the ColumnDef node */
3363 74 : def->typeName = $6;
3364 74 : def->collClause = (CollateClause *) $7;
3365 74 : def->raw_default = NULL;
3366 74 : def->location = @3;
3367 74 : $$ = (Node *) n;
3368 : }
3369 : ;
3370 :
3371 :
3372 : /*****************************************************************************
3373 : *
3374 : * QUERY :
3375 : * close <portalname>
3376 : *
3377 : *****************************************************************************/
3378 :
3379 : ClosePortalStmt:
3380 : CLOSE cursor_name
3381 : {
3382 2230 : ClosePortalStmt *n = makeNode(ClosePortalStmt);
3383 :
3384 2230 : n->portalname = $2;
3385 2230 : $$ = (Node *) n;
3386 : }
3387 : | CLOSE ALL
3388 : {
3389 12 : ClosePortalStmt *n = makeNode(ClosePortalStmt);
3390 :
3391 12 : n->portalname = NULL;
3392 12 : $$ = (Node *) n;
3393 : }
3394 : ;
3395 :
3396 :
3397 : /*****************************************************************************
3398 : *
3399 : * QUERY :
3400 : * COPY relname [(columnList)] FROM/TO file [WITH] [(options)]
3401 : * COPY ( query ) TO file [WITH] [(options)]
3402 : *
3403 : * where 'query' can be one of:
3404 : * { SELECT | UPDATE | INSERT | DELETE }
3405 : *
3406 : * and 'file' can be one of:
3407 : * { PROGRAM 'command' | STDIN | STDOUT | 'filename' }
3408 : *
3409 : * In the preferred syntax the options are comma-separated
3410 : * and use generic identifiers instead of keywords. The pre-9.0
3411 : * syntax had a hard-wired, space-separated set of options.
3412 : *
3413 : * Really old syntax, from versions 7.2 and prior:
3414 : * COPY [ BINARY ] table FROM/TO file
3415 : * [ [ USING ] DELIMITERS 'delimiter' ] ]
3416 : * [ WITH NULL AS 'null string' ]
3417 : * This option placement is not supported with COPY (query...).
3418 : *
3419 : *****************************************************************************/
3420 :
3421 : CopyStmt: COPY opt_binary qualified_name opt_column_list
3422 : copy_from opt_program copy_file_name copy_delimiter opt_with
3423 : copy_options where_clause
3424 : {
3425 11048 : CopyStmt *n = makeNode(CopyStmt);
3426 :
3427 11048 : n->relation = $3;
3428 11048 : n->query = NULL;
3429 11048 : n->attlist = $4;
3430 11048 : n->is_from = $5;
3431 11048 : n->is_program = $6;
3432 11048 : n->filename = $7;
3433 11048 : n->whereClause = $11;
3434 :
3435 11048 : if (n->is_program && n->filename == NULL)
3436 0 : ereport(ERROR,
3437 : (errcode(ERRCODE_SYNTAX_ERROR),
3438 : errmsg("STDIN/STDOUT not allowed with PROGRAM"),
3439 : parser_errposition(@8)));
3440 :
3441 11048 : if (!n->is_from && n->whereClause != NULL)
3442 6 : ereport(ERROR,
3443 : (errcode(ERRCODE_SYNTAX_ERROR),
3444 : errmsg("WHERE clause not allowed with COPY TO"),
3445 : parser_errposition(@11)));
3446 :
3447 11042 : n->options = NIL;
3448 : /* Concatenate user-supplied flags */
3449 11042 : if ($2)
3450 12 : n->options = lappend(n->options, $2);
3451 11042 : if ($8)
3452 0 : n->options = lappend(n->options, $8);
3453 11042 : if ($10)
3454 968 : n->options = list_concat(n->options, $10);
3455 11042 : $$ = (Node *) n;
3456 : }
3457 : | COPY '(' PreparableStmt ')' TO opt_program copy_file_name opt_with copy_options
3458 : {
3459 536 : CopyStmt *n = makeNode(CopyStmt);
3460 :
3461 536 : n->relation = NULL;
3462 536 : n->query = $3;
3463 536 : n->attlist = NIL;
3464 536 : n->is_from = false;
3465 536 : n->is_program = $6;
3466 536 : n->filename = $7;
3467 536 : n->options = $9;
3468 :
3469 536 : if (n->is_program && n->filename == NULL)
3470 0 : ereport(ERROR,
3471 : (errcode(ERRCODE_SYNTAX_ERROR),
3472 : errmsg("STDIN/STDOUT not allowed with PROGRAM"),
3473 : parser_errposition(@5)));
3474 :
3475 536 : $$ = (Node *) n;
3476 : }
3477 : ;
3478 :
3479 : copy_from:
3480 1856 : FROM { $$ = true; }
3481 9192 : | TO { $$ = false; }
3482 : ;
3483 :
3484 : opt_program:
3485 0 : PROGRAM { $$ = true; }
3486 11584 : | /* EMPTY */ { $$ = false; }
3487 : ;
3488 :
3489 : /*
3490 : * copy_file_name NULL indicates stdio is used. Whether stdin or stdout is
3491 : * used depends on the direction. (It really doesn't make sense to copy from
3492 : * stdout. We silently correct the "typo".) - AY 9/94
3493 : */
3494 : copy_file_name:
3495 452 : Sconst { $$ = $1; }
3496 1468 : | STDIN { $$ = NULL; }
3497 9664 : | STDOUT { $$ = NULL; }
3498 : ;
3499 :
3500 10886 : copy_options: copy_opt_list { $$ = $1; }
3501 698 : | '(' copy_generic_opt_list ')' { $$ = $2; }
3502 : ;
3503 :
3504 : /* old COPY option syntax */
3505 : copy_opt_list:
3506 504 : copy_opt_list copy_opt_item { $$ = lappend($1, $2); }
3507 10886 : | /* EMPTY */ { $$ = NIL; }
3508 : ;
3509 :
3510 : copy_opt_item:
3511 : BINARY
3512 : {
3513 0 : $$ = makeDefElem("format", (Node *) makeString("binary"), @1);
3514 : }
3515 : | FREEZE
3516 : {
3517 50 : $$ = makeDefElem("freeze", (Node *) makeBoolean(true), @1);
3518 : }
3519 : | DELIMITER opt_as Sconst
3520 : {
3521 172 : $$ = makeDefElem("delimiter", (Node *) makeString($3), @1);
3522 : }
3523 : | NULL_P opt_as Sconst
3524 : {
3525 48 : $$ = makeDefElem("null", (Node *) makeString($3), @1);
3526 : }
3527 : | CSV
3528 : {
3529 150 : $$ = makeDefElem("format", (Node *) makeString("csv"), @1);
3530 : }
3531 : | HEADER_P
3532 : {
3533 18 : $$ = makeDefElem("header", (Node *) makeBoolean(true), @1);
3534 : }
3535 : | QUOTE opt_as Sconst
3536 : {
3537 18 : $$ = makeDefElem("quote", (Node *) makeString($3), @1);
3538 : }
3539 : | ESCAPE opt_as Sconst
3540 : {
3541 18 : $$ = makeDefElem("escape", (Node *) makeString($3), @1);
3542 : }
3543 : | FORCE QUOTE columnList
3544 : {
3545 12 : $$ = makeDefElem("force_quote", (Node *) $3, @1);
3546 : }
3547 : | FORCE QUOTE '*'
3548 : {
3549 6 : $$ = makeDefElem("force_quote", (Node *) makeNode(A_Star), @1);
3550 : }
3551 : | FORCE NOT NULL_P columnList
3552 : {
3553 0 : $$ = makeDefElem("force_not_null", (Node *) $4, @1);
3554 : }
3555 : | FORCE NOT NULL_P '*'
3556 : {
3557 0 : $$ = makeDefElem("force_not_null", (Node *) makeNode(A_Star), @1);
3558 : }
3559 : | FORCE NULL_P columnList
3560 : {
3561 0 : $$ = makeDefElem("force_null", (Node *) $3, @1);
3562 : }
3563 : | FORCE NULL_P '*'
3564 : {
3565 0 : $$ = makeDefElem("force_null", (Node *) makeNode(A_Star), @1);
3566 : }
3567 : | ENCODING Sconst
3568 : {
3569 12 : $$ = makeDefElem("encoding", (Node *) makeString($2), @1);
3570 : }
3571 : ;
3572 :
3573 : /* The following exist for backward compatibility with very old versions */
3574 :
3575 : opt_binary:
3576 : BINARY
3577 : {
3578 12 : $$ = makeDefElem("format", (Node *) makeString("binary"), @1);
3579 : }
3580 11036 : | /*EMPTY*/ { $$ = NULL; }
3581 : ;
3582 :
3583 : copy_delimiter:
3584 : opt_using DELIMITERS Sconst
3585 : {
3586 0 : $$ = makeDefElem("delimiter", (Node *) makeString($3), @2);
3587 : }
3588 11048 : | /*EMPTY*/ { $$ = NULL; }
3589 : ;
3590 :
3591 : opt_using:
3592 : USING
3593 : | /*EMPTY*/
3594 : ;
3595 :
3596 : /* new COPY option syntax */
3597 : copy_generic_opt_list:
3598 : copy_generic_opt_elem
3599 : {
3600 698 : $$ = list_make1($1);
3601 : }
3602 : | copy_generic_opt_list ',' copy_generic_opt_elem
3603 : {
3604 468 : $$ = lappend($1, $3);
3605 : }
3606 : ;
3607 :
3608 : copy_generic_opt_elem:
3609 : ColLabel copy_generic_opt_arg
3610 : {
3611 1166 : $$ = makeDefElem($1, $2, @1);
3612 : }
3613 : ;
3614 :
3615 : copy_generic_opt_arg:
3616 818 : opt_boolean_or_string { $$ = (Node *) makeString($1); }
3617 60 : | NumericOnly { $$ = (Node *) $1; }
3618 90 : | '*' { $$ = (Node *) makeNode(A_Star); }
3619 6 : | DEFAULT { $$ = (Node *) makeString("default"); }
3620 150 : | '(' copy_generic_opt_arg_list ')' { $$ = (Node *) $2; }
3621 42 : | /* EMPTY */ { $$ = NULL; }
3622 : ;
3623 :
3624 : copy_generic_opt_arg_list:
3625 : copy_generic_opt_arg_list_item
3626 : {
3627 150 : $$ = list_make1($1);
3628 : }
3629 : | copy_generic_opt_arg_list ',' copy_generic_opt_arg_list_item
3630 : {
3631 12 : $$ = lappend($1, $3);
3632 : }
3633 : ;
3634 :
3635 : /* beware of emitting non-string list elements here; see commands/define.c */
3636 : copy_generic_opt_arg_list_item:
3637 162 : opt_boolean_or_string { $$ = (Node *) makeString($1); }
3638 : ;
3639 :
3640 :
3641 : /*****************************************************************************
3642 : *
3643 : * QUERY :
3644 : * CREATE TABLE relname
3645 : *
3646 : *****************************************************************************/
3647 :
3648 : CreateStmt: CREATE OptTemp TABLE qualified_name '(' OptTableElementList ')'
3649 : OptInherit OptPartitionSpec table_access_method_clause OptWith
3650 : OnCommitOption OptTableSpace
3651 : {
3652 29490 : CreateStmt *n = makeNode(CreateStmt);
3653 :
3654 29490 : $4->relpersistence = $2;
3655 29490 : n->relation = $4;
3656 29490 : n->tableElts = $6;
3657 29490 : n->inhRelations = $8;
3658 29490 : n->partspec = $9;
3659 29490 : n->ofTypename = NULL;
3660 29490 : n->constraints = NIL;
3661 29490 : n->accessMethod = $10;
3662 29490 : n->options = $11;
3663 29490 : n->oncommit = $12;
3664 29490 : n->tablespacename = $13;
3665 29490 : n->if_not_exists = false;
3666 29490 : $$ = (Node *) n;
3667 : }
3668 : | CREATE OptTemp TABLE IF_P NOT EXISTS qualified_name '('
3669 : OptTableElementList ')' OptInherit OptPartitionSpec table_access_method_clause
3670 : OptWith OnCommitOption OptTableSpace
3671 : {
3672 30 : CreateStmt *n = makeNode(CreateStmt);
3673 :
3674 30 : $7->relpersistence = $2;
3675 30 : n->relation = $7;
3676 30 : n->tableElts = $9;
3677 30 : n->inhRelations = $11;
3678 30 : n->partspec = $12;
3679 30 : n->ofTypename = NULL;
3680 30 : n->constraints = NIL;
3681 30 : n->accessMethod = $13;
3682 30 : n->options = $14;
3683 30 : n->oncommit = $15;
3684 30 : n->tablespacename = $16;
3685 30 : n->if_not_exists = true;
3686 30 : $$ = (Node *) n;
3687 : }
3688 : | CREATE OptTemp TABLE qualified_name OF any_name
3689 : OptTypedTableElementList OptPartitionSpec table_access_method_clause
3690 : OptWith OnCommitOption OptTableSpace
3691 : {
3692 122 : CreateStmt *n = makeNode(CreateStmt);
3693 :
3694 122 : $4->relpersistence = $2;
3695 122 : n->relation = $4;
3696 122 : n->tableElts = $7;
3697 122 : n->inhRelations = NIL;
3698 122 : n->partspec = $8;
3699 122 : n->ofTypename = makeTypeNameFromNameList($6);
3700 122 : n->ofTypename->location = @6;
3701 122 : n->constraints = NIL;
3702 122 : n->accessMethod = $9;
3703 122 : n->options = $10;
3704 122 : n->oncommit = $11;
3705 122 : n->tablespacename = $12;
3706 122 : n->if_not_exists = false;
3707 122 : $$ = (Node *) n;
3708 : }
3709 : | CREATE OptTemp TABLE IF_P NOT EXISTS qualified_name OF any_name
3710 : OptTypedTableElementList OptPartitionSpec table_access_method_clause
3711 : OptWith OnCommitOption OptTableSpace
3712 : {
3713 6 : CreateStmt *n = makeNode(CreateStmt);
3714 :
3715 6 : $7->relpersistence = $2;
3716 6 : n->relation = $7;
3717 6 : n->tableElts = $10;
3718 6 : n->inhRelations = NIL;
3719 6 : n->partspec = $11;
3720 6 : n->ofTypename = makeTypeNameFromNameList($9);
3721 6 : n->ofTypename->location = @9;
3722 6 : n->constraints = NIL;
3723 6 : n->accessMethod = $12;
3724 6 : n->options = $13;
3725 6 : n->oncommit = $14;
3726 6 : n->tablespacename = $15;
3727 6 : n->if_not_exists = true;
3728 6 : $$ = (Node *) n;
3729 : }
3730 : | CREATE OptTemp TABLE qualified_name PARTITION OF qualified_name
3731 : OptTypedTableElementList PartitionBoundSpec OptPartitionSpec
3732 : table_access_method_clause OptWith OnCommitOption OptTableSpace
3733 : {
3734 7908 : CreateStmt *n = makeNode(CreateStmt);
3735 :
3736 7908 : $4->relpersistence = $2;
3737 7908 : n->relation = $4;
3738 7908 : n->tableElts = $8;
3739 7908 : n->inhRelations = list_make1($7);
3740 7908 : n->partbound = $9;
3741 7908 : n->partspec = $10;
3742 7908 : n->ofTypename = NULL;
3743 7908 : n->constraints = NIL;
3744 7908 : n->accessMethod = $11;
3745 7908 : n->options = $12;
3746 7908 : n->oncommit = $13;
3747 7908 : n->tablespacename = $14;
3748 7908 : n->if_not_exists = false;
3749 7908 : $$ = (Node *) n;
3750 : }
3751 : | CREATE OptTemp TABLE IF_P NOT EXISTS qualified_name PARTITION OF
3752 : qualified_name OptTypedTableElementList PartitionBoundSpec OptPartitionSpec
3753 : table_access_method_clause OptWith OnCommitOption OptTableSpace
3754 : {
3755 0 : CreateStmt *n = makeNode(CreateStmt);
3756 :
3757 0 : $7->relpersistence = $2;
3758 0 : n->relation = $7;
3759 0 : n->tableElts = $11;
3760 0 : n->inhRelations = list_make1($10);
3761 0 : n->partbound = $12;
3762 0 : n->partspec = $13;
3763 0 : n->ofTypename = NULL;
3764 0 : n->constraints = NIL;
3765 0 : n->accessMethod = $14;
3766 0 : n->options = $15;
3767 0 : n->oncommit = $16;
3768 0 : n->tablespacename = $17;
3769 0 : n->if_not_exists = true;
3770 0 : $$ = (Node *) n;
3771 : }
3772 : ;
3773 :
3774 : /*
3775 : * Redundancy here is needed to avoid shift/reduce conflicts,
3776 : * since TEMP is not a reserved word. See also OptTempTableName.
3777 : *
3778 : * NOTE: we accept both GLOBAL and LOCAL options. They currently do nothing,
3779 : * but future versions might consider GLOBAL to request SQL-spec-compliant
3780 : * temp table behavior, so warn about that. Since we have no modules the
3781 : * LOCAL keyword is really meaningless; furthermore, some other products
3782 : * implement LOCAL as meaning the same as our default temp table behavior,
3783 : * so we'll probably continue to treat LOCAL as a noise word.
3784 : */
3785 346 : OptTemp: TEMPORARY { $$ = RELPERSISTENCE_TEMP; }
3786 2732 : | TEMP { $$ = RELPERSISTENCE_TEMP; }
3787 0 : | LOCAL TEMPORARY { $$ = RELPERSISTENCE_TEMP; }
3788 0 : | LOCAL TEMP { $$ = RELPERSISTENCE_TEMP; }
3789 : | GLOBAL TEMPORARY
3790 : {
3791 0 : ereport(WARNING,
3792 : (errmsg("GLOBAL is deprecated in temporary table creation"),
3793 : parser_errposition(@1)));
3794 0 : $$ = RELPERSISTENCE_TEMP;
3795 : }
3796 : | GLOBAL TEMP
3797 : {
3798 0 : ereport(WARNING,
3799 : (errmsg("GLOBAL is deprecated in temporary table creation"),
3800 : parser_errposition(@1)));
3801 0 : $$ = RELPERSISTENCE_TEMP;
3802 : }
3803 160 : | UNLOGGED { $$ = RELPERSISTENCE_UNLOGGED; }
3804 53436 : | /*EMPTY*/ { $$ = RELPERSISTENCE_PERMANENT; }
3805 : ;
3806 :
3807 : OptTableElementList:
3808 28334 : TableElementList { $$ = $1; }
3809 1624 : | /*EMPTY*/ { $$ = NIL; }
3810 : ;
3811 :
3812 : OptTypedTableElementList:
3813 348 : '(' TypedTableElementList ')' { $$ = $2; }
3814 7784 : | /*EMPTY*/ { $$ = NIL; }
3815 : ;
3816 :
3817 : TableElementList:
3818 : TableElement
3819 : {
3820 28388 : $$ = list_make1($1);
3821 : }
3822 : | TableElementList ',' TableElement
3823 : {
3824 40150 : $$ = lappend($1, $3);
3825 : }
3826 : ;
3827 :
3828 : TypedTableElementList:
3829 : TypedTableElement
3830 : {
3831 348 : $$ = list_make1($1);
3832 : }
3833 : | TypedTableElementList ',' TypedTableElement
3834 : {
3835 68 : $$ = lappend($1, $3);
3836 : }
3837 : ;
3838 :
3839 : TableElement:
3840 65092 : columnDef { $$ = $1; }
3841 774 : | TableLikeClause { $$ = $1; }
3842 2672 : | TableConstraint { $$ = $1; }
3843 : ;
3844 :
3845 : TypedTableElement:
3846 346 : columnOptions { $$ = $1; }
3847 70 : | TableConstraint { $$ = $1; }
3848 : ;
3849 :
3850 : columnDef: ColId Typename opt_column_storage opt_column_compression create_generic_options ColQualList
3851 : {
3852 67240 : ColumnDef *n = makeNode(ColumnDef);
3853 :
3854 67240 : n->colname = $1;
3855 67240 : n->typeName = $2;
3856 67240 : n->storage_name = $3;
3857 67240 : n->compression = $4;
3858 67240 : n->inhcount = 0;
3859 67240 : n->is_local = true;
3860 67240 : n->is_not_null = false;
3861 67240 : n->is_from_type = false;
3862 67240 : n->storage = 0;
3863 67240 : n->raw_default = NULL;
3864 67240 : n->cooked_default = NULL;
3865 67240 : n->collOid = InvalidOid;
3866 67240 : n->fdwoptions = $5;
3867 67240 : SplitColQualList($6, &n->constraints, &n->collClause,
3868 : yyscanner);
3869 67240 : n->location = @1;
3870 67240 : $$ = (Node *) n;
3871 : }
3872 : ;
3873 :
3874 : columnOptions: ColId ColQualList
3875 : {
3876 138 : ColumnDef *n = makeNode(ColumnDef);
3877 :
3878 138 : n->colname = $1;
3879 138 : n->typeName = NULL;
3880 138 : n->inhcount = 0;
3881 138 : n->is_local = true;
3882 138 : n->is_not_null = false;
3883 138 : n->is_from_type = false;
3884 138 : n->storage = 0;
3885 138 : n->raw_default = NULL;
3886 138 : n->cooked_default = NULL;
3887 138 : n->collOid = InvalidOid;
3888 138 : SplitColQualList($2, &n->constraints, &n->collClause,
3889 : yyscanner);
3890 138 : n->location = @1;
3891 138 : $$ = (Node *) n;
3892 : }
3893 : | ColId WITH OPTIONS ColQualList
3894 : {
3895 208 : ColumnDef *n = makeNode(ColumnDef);
3896 :
3897 208 : n->colname = $1;
3898 208 : n->typeName = NULL;
3899 208 : n->inhcount = 0;
3900 208 : n->is_local = true;
3901 208 : n->is_not_null = false;
3902 208 : n->is_from_type = false;
3903 208 : n->storage = 0;
3904 208 : n->raw_default = NULL;
3905 208 : n->cooked_default = NULL;
3906 208 : n->collOid = InvalidOid;
3907 208 : SplitColQualList($4, &n->constraints, &n->collClause,
3908 : yyscanner);
3909 208 : n->location = @1;
3910 208 : $$ = (Node *) n;
3911 : }
3912 : ;
3913 :
3914 : column_compression:
3915 166 : COMPRESSION ColId { $$ = $2; }
3916 6 : | COMPRESSION DEFAULT { $$ = pstrdup("default"); }
3917 : ;
3918 :
3919 : opt_column_compression:
3920 94 : column_compression { $$ = $1; }
3921 67212 : | /*EMPTY*/ { $$ = NULL; }
3922 : ;
3923 :
3924 : column_storage:
3925 256 : STORAGE ColId { $$ = $2; }
3926 6 : | STORAGE DEFAULT { $$ = pstrdup("default"); }
3927 : ;
3928 :
3929 : opt_column_storage:
3930 26 : column_storage { $$ = $1; }
3931 67280 : | /*EMPTY*/ { $$ = NULL; }
3932 : ;
3933 :
3934 : ColQualList:
3935 19746 : ColQualList ColConstraint { $$ = lappend($1, $2); }
3936 69104 : | /*EMPTY*/ { $$ = NIL; }
3937 : ;
3938 :
3939 : ColConstraint:
3940 : CONSTRAINT name ColConstraintElem
3941 : {
3942 802 : Constraint *n = castNode(Constraint, $3);
3943 :
3944 802 : n->conname = $2;
3945 802 : n->location = @1;
3946 802 : $$ = (Node *) n;
3947 : }
3948 17888 : | ColConstraintElem { $$ = $1; }
3949 294 : | ConstraintAttr { $$ = $1; }
3950 : | COLLATE any_name
3951 : {
3952 : /*
3953 : * Note: the CollateClause is momentarily included in
3954 : * the list built by ColQualList, but we split it out
3955 : * again in SplitColQualList.
3956 : */
3957 762 : CollateClause *n = makeNode(CollateClause);
3958 :
3959 762 : n->arg = NULL;
3960 762 : n->collname = $2;
3961 762 : n->location = @1;
3962 762 : $$ = (Node *) n;
3963 : }
3964 : ;
3965 :
3966 : /* DEFAULT NULL is already the default for Postgres.
3967 : * But define it here and carry it forward into the system
3968 : * to make it explicit.
3969 : * - thomas 1998-09-13
3970 : *
3971 : * WITH NULL and NULL are not SQL-standard syntax elements,
3972 : * so leave them out. Use DEFAULT NULL to explicitly indicate
3973 : * that a column may have that value. WITH NULL leads to
3974 : * shift/reduce conflicts with WITH TIME ZONE anyway.
3975 : * - thomas 1999-01-08
3976 : *
3977 : * DEFAULT expression must be b_expr not a_expr to prevent shift/reduce
3978 : * conflict on NOT (since NOT might start a subsequent NOT NULL constraint,
3979 : * or be part of a_expr NOT LIKE or similar constructs).
3980 : */
3981 : ColConstraintElem:
3982 : NOT NULL_P opt_no_inherit
3983 : {
3984 6684 : Constraint *n = makeNode(Constraint);
3985 :
3986 6684 : n->contype = CONSTR_NOTNULL;
3987 6684 : n->location = @1;
3988 6684 : n->is_no_inherit = $3;
3989 6684 : n->is_enforced = true;
3990 6684 : n->skip_validation = false;
3991 6684 : n->initially_valid = true;
3992 6684 : $$ = (Node *) n;
3993 : }
3994 : | NULL_P
3995 : {
3996 30 : Constraint *n = makeNode(Constraint);
3997 :
3998 30 : n->contype = CONSTR_NULL;
3999 30 : n->location = @1;
4000 30 : $$ = (Node *) n;
4001 : }
4002 : | UNIQUE opt_unique_null_treatment opt_definition OptConsTableSpace
4003 : {
4004 444 : Constraint *n = makeNode(Constraint);
4005 :
4006 444 : n->contype = CONSTR_UNIQUE;
4007 444 : n->location = @1;
4008 444 : n->nulls_not_distinct = !$2;
4009 444 : n->keys = NULL;
4010 444 : n->options = $3;
4011 444 : n->indexname = NULL;
4012 444 : n->indexspace = $4;
4013 444 : $$ = (Node *) n;
4014 : }
4015 : | PRIMARY KEY opt_definition OptConsTableSpace
4016 : {
4017 5776 : Constraint *n = makeNode(Constraint);
4018 :
4019 5776 : n->contype = CONSTR_PRIMARY;
4020 5776 : n->location = @1;
4021 5776 : n->keys = NULL;
4022 5776 : n->options = $3;
4023 5776 : n->indexname = NULL;
4024 5776 : n->indexspace = $4;
4025 5776 : $$ = (Node *) n;
4026 : }
4027 : | CHECK '(' a_expr ')' opt_no_inherit
4028 : {
4029 1086 : Constraint *n = makeNode(Constraint);
4030 :
4031 1086 : n->contype = CONSTR_CHECK;
4032 1086 : n->location = @1;
4033 1086 : n->is_no_inherit = $5;
4034 1086 : n->raw_expr = $3;
4035 1086 : n->cooked_expr = NULL;
4036 1086 : n->is_enforced = true;
4037 1086 : n->skip_validation = false;
4038 1086 : n->initially_valid = true;
4039 1086 : $$ = (Node *) n;
4040 : }
4041 : | DEFAULT b_expr
4042 : {
4043 1814 : Constraint *n = makeNode(Constraint);
4044 :
4045 1814 : n->contype = CONSTR_DEFAULT;
4046 1814 : n->location = @1;
4047 1814 : n->raw_expr = $2;
4048 1814 : n->cooked_expr = NULL;
4049 1814 : $$ = (Node *) n;
4050 : }
4051 : | GENERATED generated_when AS IDENTITY_P OptParenthesizedSeqOptList
4052 : {
4053 332 : Constraint *n = makeNode(Constraint);
4054 :
4055 332 : n->contype = CONSTR_IDENTITY;
4056 332 : n->generated_when = $2;
4057 332 : n->options = $5;
4058 332 : n->location = @1;
4059 332 : $$ = (Node *) n;
4060 : }
4061 : | GENERATED generated_when AS '(' a_expr ')' opt_virtual_or_stored
4062 : {
4063 1708 : Constraint *n = makeNode(Constraint);
4064 :
4065 1708 : n->contype = CONSTR_GENERATED;
4066 1708 : n->generated_when = $2;
4067 1708 : n->raw_expr = $5;
4068 1708 : n->cooked_expr = NULL;
4069 1708 : n->generated_kind = $7;
4070 1708 : n->location = @1;
4071 :
4072 : /*
4073 : * Can't do this in the grammar because of shift/reduce
4074 : * conflicts. (IDENTITY allows both ALWAYS and BY
4075 : * DEFAULT, but generated columns only allow ALWAYS.) We
4076 : * can also give a more useful error message and location.
4077 : */
4078 1708 : if ($2 != ATTRIBUTE_IDENTITY_ALWAYS)
4079 12 : ereport(ERROR,
4080 : (errcode(ERRCODE_SYNTAX_ERROR),
4081 : errmsg("for a generated column, GENERATED ALWAYS must be specified"),
4082 : parser_errposition(@2)));
4083 :
4084 1696 : $$ = (Node *) n;
4085 : }
4086 : | REFERENCES qualified_name opt_column_list key_match key_actions
4087 : {
4088 828 : Constraint *n = makeNode(Constraint);
4089 :
4090 828 : n->contype = CONSTR_FOREIGN;
4091 828 : n->location = @1;
4092 828 : n->pktable = $2;
4093 828 : n->fk_attrs = NIL;
4094 828 : n->pk_attrs = $3;
4095 828 : n->fk_matchtype = $4;
4096 828 : n->fk_upd_action = ($5)->updateAction->action;
4097 828 : n->fk_del_action = ($5)->deleteAction->action;
4098 828 : n->fk_del_set_cols = ($5)->deleteAction->cols;
4099 828 : n->is_enforced = true;
4100 828 : n->skip_validation = false;
4101 828 : n->initially_valid = true;
4102 828 : $$ = (Node *) n;
4103 : }
4104 : ;
4105 :
4106 : opt_unique_null_treatment:
4107 12 : NULLS_P DISTINCT { $$ = true; }
4108 36 : | NULLS_P NOT DISTINCT { $$ = false; }
4109 7674 : | /*EMPTY*/ { $$ = true; }
4110 : ;
4111 :
4112 : generated_when:
4113 2068 : ALWAYS { $$ = ATTRIBUTE_IDENTITY_ALWAYS; }
4114 182 : | BY DEFAULT { $$ = ATTRIBUTE_IDENTITY_BY_DEFAULT; }
4115 : ;
4116 :
4117 : opt_virtual_or_stored:
4118 968 : STORED { $$ = ATTRIBUTE_GENERATED_STORED; }
4119 634 : | VIRTUAL { $$ = ATTRIBUTE_GENERATED_VIRTUAL; }
4120 106 : | /*EMPTY*/ { $$ = ATTRIBUTE_GENERATED_VIRTUAL; }
4121 : ;
4122 :
4123 : /*
4124 : * ConstraintAttr represents constraint attributes, which we parse as if
4125 : * they were independent constraint clauses, in order to avoid shift/reduce
4126 : * conflicts (since NOT might start either an independent NOT NULL clause
4127 : * or an attribute). parse_utilcmd.c is responsible for attaching the
4128 : * attribute information to the preceding "real" constraint node, and for
4129 : * complaining if attribute clauses appear in the wrong place or wrong
4130 : * combinations.
4131 : *
4132 : * See also ConstraintAttributeSpec, which can be used in places where
4133 : * there is no parsing conflict. (Note: currently, NOT VALID and NO INHERIT
4134 : * are allowed clauses in ConstraintAttributeSpec, but not here. Someday we
4135 : * might need to allow them here too, but for the moment it doesn't seem
4136 : * useful in the statements that use ConstraintAttr.)
4137 : */
4138 : ConstraintAttr:
4139 : DEFERRABLE
4140 : {
4141 102 : Constraint *n = makeNode(Constraint);
4142 :
4143 102 : n->contype = CONSTR_ATTR_DEFERRABLE;
4144 102 : n->location = @1;
4145 102 : $$ = (Node *) n;
4146 : }
4147 : | NOT DEFERRABLE
4148 : {
4149 0 : Constraint *n = makeNode(Constraint);
4150 :
4151 0 : n->contype = CONSTR_ATTR_NOT_DEFERRABLE;
4152 0 : n->location = @1;
4153 0 : $$ = (Node *) n;
4154 : }
4155 : | INITIALLY DEFERRED
4156 : {
4157 78 : Constraint *n = makeNode(Constraint);
4158 :
4159 78 : n->contype = CONSTR_ATTR_DEFERRED;
4160 78 : n->location = @1;
4161 78 : $$ = (Node *) n;
4162 : }
4163 : | INITIALLY IMMEDIATE
4164 : {
4165 6 : Constraint *n = makeNode(Constraint);
4166 :
4167 6 : n->contype = CONSTR_ATTR_IMMEDIATE;
4168 6 : n->location = @1;
4169 6 : $$ = (Node *) n;
4170 : }
4171 : | ENFORCED
4172 : {
4173 42 : Constraint *n = makeNode(Constraint);
4174 :
4175 42 : n->contype = CONSTR_ATTR_ENFORCED;
4176 42 : n->location = @1;
4177 42 : $$ = (Node *) n;
4178 : }
4179 : | NOT ENFORCED
4180 : {
4181 66 : Constraint *n = makeNode(Constraint);
4182 :
4183 66 : n->contype = CONSTR_ATTR_NOT_ENFORCED;
4184 66 : n->location = @1;
4185 66 : $$ = (Node *) n;
4186 : }
4187 : ;
4188 :
4189 :
4190 : TableLikeClause:
4191 : LIKE qualified_name TableLikeOptionList
4192 : {
4193 774 : TableLikeClause *n = makeNode(TableLikeClause);
4194 :
4195 774 : n->relation = $2;
4196 774 : n->options = $3;
4197 774 : n->relationOid = InvalidOid;
4198 774 : $$ = (Node *) n;
4199 : }
4200 : ;
4201 :
4202 : TableLikeOptionList:
4203 288 : TableLikeOptionList INCLUDING TableLikeOption { $$ = $1 | $3; }
4204 8 : | TableLikeOptionList EXCLUDING TableLikeOption { $$ = $1 & ~$3; }
4205 774 : | /* EMPTY */ { $$ = 0; }
4206 : ;
4207 :
4208 : TableLikeOption:
4209 30 : COMMENTS { $$ = CREATE_TABLE_LIKE_COMMENTS; }
4210 6 : | COMPRESSION { $$ = CREATE_TABLE_LIKE_COMPRESSION; }
4211 54 : | CONSTRAINTS { $$ = CREATE_TABLE_LIKE_CONSTRAINTS; }
4212 20 : | DEFAULTS { $$ = CREATE_TABLE_LIKE_DEFAULTS; }
4213 12 : | IDENTITY_P { $$ = CREATE_TABLE_LIKE_IDENTITY; }
4214 30 : | GENERATED { $$ = CREATE_TABLE_LIKE_GENERATED; }
4215 50 : | INDEXES { $$ = CREATE_TABLE_LIKE_INDEXES; }
4216 0 : | STATISTICS { $$ = CREATE_TABLE_LIKE_STATISTICS; }
4217 26 : | STORAGE { $$ = CREATE_TABLE_LIKE_STORAGE; }
4218 68 : | ALL { $$ = CREATE_TABLE_LIKE_ALL; }
4219 : ;
4220 :
4221 :
4222 : /* ConstraintElem specifies constraint syntax which is not embedded into
4223 : * a column definition. ColConstraintElem specifies the embedded form.
4224 : * - thomas 1997-12-03
4225 : */
4226 : TableConstraint:
4227 : CONSTRAINT name ConstraintElem
4228 : {
4229 4090 : Constraint *n = castNode(Constraint, $3);
4230 :
4231 4090 : n->conname = $2;
4232 4090 : n->location = @1;
4233 4090 : $$ = (Node *) n;
4234 : }
4235 13206 : | ConstraintElem { $$ = $1; }
4236 : ;
4237 :
4238 : ConstraintElem:
4239 : CHECK '(' a_expr ')' ConstraintAttributeSpec
4240 : {
4241 1254 : Constraint *n = makeNode(Constraint);
4242 :
4243 1254 : n->contype = CONSTR_CHECK;
4244 1254 : n->location = @1;
4245 1254 : n->raw_expr = $3;
4246 1254 : n->cooked_expr = NULL;
4247 1254 : processCASbits($5, @5, "CHECK",
4248 : NULL, NULL, &n->is_enforced, &n->skip_validation,
4249 : &n->is_no_inherit, yyscanner);
4250 1254 : n->initially_valid = !n->skip_validation;
4251 1254 : $$ = (Node *) n;
4252 : }
4253 : | NOT NULL_P ColId ConstraintAttributeSpec
4254 : {
4255 598 : Constraint *n = makeNode(Constraint);
4256 :
4257 598 : n->contype = CONSTR_NOTNULL;
4258 598 : n->location = @1;
4259 598 : n->keys = list_make1(makeString($3));
4260 598 : processCASbits($4, @4, "NOT NULL",
4261 : NULL, NULL, NULL, &n->skip_validation,
4262 : &n->is_no_inherit, yyscanner);
4263 598 : n->initially_valid = !n->skip_validation;
4264 598 : $$ = (Node *) n;
4265 : }
4266 : | UNIQUE opt_unique_null_treatment '(' columnList opt_without_overlaps ')' opt_c_include opt_definition OptConsTableSpace
4267 : ConstraintAttributeSpec
4268 : {
4269 598 : Constraint *n = makeNode(Constraint);
4270 :
4271 598 : n->contype = CONSTR_UNIQUE;
4272 598 : n->location = @1;
4273 598 : n->nulls_not_distinct = !$2;
4274 598 : n->keys = $4;
4275 598 : n->without_overlaps = $5;
4276 598 : n->including = $7;
4277 598 : n->options = $8;
4278 598 : n->indexname = NULL;
4279 598 : n->indexspace = $9;
4280 598 : processCASbits($10, @10, "UNIQUE",
4281 : &n->deferrable, &n->initdeferred, NULL,
4282 : NULL, NULL, yyscanner);
4283 598 : $$ = (Node *) n;
4284 : }
4285 : | UNIQUE ExistingIndex ConstraintAttributeSpec
4286 : {
4287 4648 : Constraint *n = makeNode(Constraint);
4288 :
4289 4648 : n->contype = CONSTR_UNIQUE;
4290 4648 : n->location = @1;
4291 4648 : n->keys = NIL;
4292 4648 : n->including = NIL;
4293 4648 : n->options = NIL;
4294 4648 : n->indexname = $2;
4295 4648 : n->indexspace = NULL;
4296 4648 : processCASbits($3, @3, "UNIQUE",
4297 : &n->deferrable, &n->initdeferred, NULL,
4298 : NULL, NULL, yyscanner);
4299 4648 : $$ = (Node *) n;
4300 : }
4301 : | PRIMARY KEY '(' columnList opt_without_overlaps ')' opt_c_include opt_definition OptConsTableSpace
4302 : ConstraintAttributeSpec
4303 : {
4304 2138 : Constraint *n = makeNode(Constraint);
4305 :
4306 2138 : n->contype = CONSTR_PRIMARY;
4307 2138 : n->location = @1;
4308 2138 : n->keys = $4;
4309 2138 : n->without_overlaps = $5;
4310 2138 : n->including = $7;
4311 2138 : n->options = $8;
4312 2138 : n->indexname = NULL;
4313 2138 : n->indexspace = $9;
4314 2138 : processCASbits($10, @10, "PRIMARY KEY",
4315 : &n->deferrable, &n->initdeferred, NULL,
4316 : NULL, NULL, yyscanner);
4317 2138 : $$ = (Node *) n;
4318 : }
4319 : | PRIMARY KEY ExistingIndex ConstraintAttributeSpec
4320 : {
4321 6018 : Constraint *n = makeNode(Constraint);
4322 :
4323 6018 : n->contype = CONSTR_PRIMARY;
4324 6018 : n->location = @1;
4325 6018 : n->keys = NIL;
4326 6018 : n->including = NIL;
4327 6018 : n->options = NIL;
4328 6018 : n->indexname = $3;
4329 6018 : n->indexspace = NULL;
4330 6018 : processCASbits($4, @4, "PRIMARY KEY",
4331 : &n->deferrable, &n->initdeferred, NULL,
4332 : NULL, NULL, yyscanner);
4333 6018 : $$ = (Node *) n;
4334 : }
4335 : | EXCLUDE access_method_clause '(' ExclusionConstraintList ')'
4336 : opt_c_include opt_definition OptConsTableSpace OptWhereClause
4337 : ConstraintAttributeSpec
4338 : {
4339 234 : Constraint *n = makeNode(Constraint);
4340 :
4341 234 : n->contype = CONSTR_EXCLUSION;
4342 234 : n->location = @1;
4343 234 : n->access_method = $2;
4344 234 : n->exclusions = $4;
4345 234 : n->including = $6;
4346 234 : n->options = $7;
4347 234 : n->indexname = NULL;
4348 234 : n->indexspace = $8;
4349 234 : n->where_clause = $9;
4350 234 : processCASbits($10, @10, "EXCLUDE",
4351 : &n->deferrable, &n->initdeferred, NULL,
4352 : NULL, NULL, yyscanner);
4353 234 : $$ = (Node *) n;
4354 : }
4355 : | FOREIGN KEY '(' columnList optionalPeriodName ')' REFERENCES qualified_name
4356 : opt_column_and_period_list key_match key_actions ConstraintAttributeSpec
4357 : {
4358 1808 : Constraint *n = makeNode(Constraint);
4359 :
4360 1808 : n->contype = CONSTR_FOREIGN;
4361 1808 : n->location = @1;
4362 1808 : n->pktable = $8;
4363 1808 : n->fk_attrs = $4;
4364 1808 : if ($5)
4365 : {
4366 290 : n->fk_attrs = lappend(n->fk_attrs, $5);
4367 290 : n->fk_with_period = true;
4368 : }
4369 1808 : n->pk_attrs = linitial($9);
4370 1808 : if (lsecond($9))
4371 : {
4372 170 : n->pk_attrs = lappend(n->pk_attrs, lsecond($9));
4373 170 : n->pk_with_period = true;
4374 : }
4375 1808 : n->fk_matchtype = $10;
4376 1808 : n->fk_upd_action = ($11)->updateAction->action;
4377 1808 : n->fk_del_action = ($11)->deleteAction->action;
4378 1808 : n->fk_del_set_cols = ($11)->deleteAction->cols;
4379 1808 : processCASbits($12, @12, "FOREIGN KEY",
4380 : &n->deferrable, &n->initdeferred,
4381 : &n->is_enforced, &n->skip_validation, NULL,
4382 : yyscanner);
4383 1808 : n->initially_valid = !n->skip_validation;
4384 1808 : $$ = (Node *) n;
4385 : }
4386 : ;
4387 :
4388 : /*
4389 : * DomainConstraint is separate from TableConstraint because the syntax for
4390 : * NOT NULL constraints is different. For table constraints, we need to
4391 : * accept a column name, but for domain constraints, we don't. (We could
4392 : * accept something like NOT NULL VALUE, but that seems weird.) CREATE DOMAIN
4393 : * (which uses ColQualList) has for a long time accepted NOT NULL without a
4394 : * column name, so it makes sense that ALTER DOMAIN (which uses
4395 : * DomainConstraint) does as well. None of these syntaxes are per SQL
4396 : * standard; we are just living with the bits of inconsistency that have built
4397 : * up over time.
4398 : */
4399 : DomainConstraint:
4400 : CONSTRAINT name DomainConstraintElem
4401 : {
4402 164 : Constraint *n = castNode(Constraint, $3);
4403 :
4404 164 : n->conname = $2;
4405 164 : n->location = @1;
4406 164 : $$ = (Node *) n;
4407 : }
4408 18 : | DomainConstraintElem { $$ = $1; }
4409 : ;
4410 :
4411 : DomainConstraintElem:
4412 : CHECK '(' a_expr ')' ConstraintAttributeSpec
4413 : {
4414 164 : Constraint *n = makeNode(Constraint);
4415 :
4416 164 : n->contype = CONSTR_CHECK;
4417 164 : n->location = @1;
4418 164 : n->raw_expr = $3;
4419 164 : n->cooked_expr = NULL;
4420 164 : processCASbits($5, @5, "CHECK",
4421 : NULL, NULL, NULL, &n->skip_validation,
4422 : &n->is_no_inherit, yyscanner);
4423 152 : n->is_enforced = true;
4424 152 : n->initially_valid = !n->skip_validation;
4425 152 : $$ = (Node *) n;
4426 : }
4427 : | NOT NULL_P ConstraintAttributeSpec
4428 : {
4429 30 : Constraint *n = makeNode(Constraint);
4430 :
4431 30 : n->contype = CONSTR_NOTNULL;
4432 30 : n->location = @1;
4433 30 : n->keys = list_make1(makeString("value"));
4434 : /* no NOT VALID, NO INHERIT support */
4435 30 : processCASbits($3, @3, "NOT NULL",
4436 : NULL, NULL, NULL,
4437 : NULL, NULL, yyscanner);
4438 30 : n->initially_valid = true;
4439 30 : $$ = (Node *) n;
4440 : }
4441 : ;
4442 :
4443 138 : opt_no_inherit: NO INHERIT { $$ = true; }
4444 7632 : | /* EMPTY */ { $$ = false; }
4445 : ;
4446 :
4447 : opt_without_overlaps:
4448 554 : WITHOUT OVERLAPS { $$ = true; }
4449 2182 : | /*EMPTY*/ { $$ = false; }
4450 : ;
4451 :
4452 : opt_column_list:
4453 10600 : '(' columnList ')' { $$ = $2; }
4454 42618 : | /*EMPTY*/ { $$ = NIL; }
4455 : ;
4456 :
4457 : columnList:
4458 16838 : columnElem { $$ = list_make1($1); }
4459 28656 : | columnList ',' columnElem { $$ = lappend($1, $3); }
4460 : ;
4461 :
4462 : optionalPeriodName:
4463 460 : ',' PERIOD columnElem { $$ = $3; }
4464 2478 : | /*EMPTY*/ { $$ = NULL; }
4465 : ;
4466 :
4467 : opt_column_and_period_list:
4468 1124 : '(' columnList optionalPeriodName ')' { $$ = list_make2($2, $3); }
4469 690 : | /*EMPTY*/ { $$ = list_make2(NIL, NULL); }
4470 : ;
4471 :
4472 : columnElem: ColId
4473 : {
4474 45954 : $$ = (Node *) makeString($1);
4475 : }
4476 : ;
4477 :
4478 168 : opt_c_include: INCLUDE '(' columnList ')' { $$ = $3; }
4479 2802 : | /* EMPTY */ { $$ = NIL; }
4480 : ;
4481 :
4482 : key_match: MATCH FULL
4483 : {
4484 98 : $$ = FKCONSTR_MATCH_FULL;
4485 : }
4486 : | MATCH PARTIAL
4487 : {
4488 0 : ereport(ERROR,
4489 : (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
4490 : errmsg("MATCH PARTIAL not yet implemented"),
4491 : parser_errposition(@1)));
4492 : $$ = FKCONSTR_MATCH_PARTIAL;
4493 : }
4494 : | MATCH SIMPLE
4495 : {
4496 6 : $$ = FKCONSTR_MATCH_SIMPLE;
4497 : }
4498 : | /*EMPTY*/
4499 : {
4500 2538 : $$ = FKCONSTR_MATCH_SIMPLE;
4501 : }
4502 : ;
4503 :
4504 : ExclusionConstraintList:
4505 234 : ExclusionConstraintElem { $$ = list_make1($1); }
4506 : | ExclusionConstraintList ',' ExclusionConstraintElem
4507 106 : { $$ = lappend($1, $3); }
4508 : ;
4509 :
4510 : ExclusionConstraintElem: index_elem WITH any_operator
4511 : {
4512 340 : $$ = list_make2($1, $3);
4513 : }
4514 : /* allow OPERATOR() decoration for the benefit of ruleutils.c */
4515 : | index_elem WITH OPERATOR '(' any_operator ')'
4516 : {
4517 0 : $$ = list_make2($1, $5);
4518 : }
4519 : ;
4520 :
4521 : OptWhereClause:
4522 464 : WHERE '(' a_expr ')' { $$ = $3; }
4523 1260 : | /*EMPTY*/ { $$ = NULL; }
4524 : ;
4525 :
4526 : key_actions:
4527 : key_update
4528 : {
4529 74 : KeyActions *n = palloc(sizeof(KeyActions));
4530 :
4531 74 : n->updateAction = $1;
4532 74 : n->deleteAction = palloc(sizeof(KeyAction));
4533 74 : n->deleteAction->action = FKCONSTR_ACTION_NOACTION;
4534 74 : n->deleteAction->cols = NIL;
4535 74 : $$ = n;
4536 : }
4537 : | key_delete
4538 : {
4539 150 : KeyActions *n = palloc(sizeof(KeyActions));
4540 :
4541 150 : n->updateAction = palloc(sizeof(KeyAction));
4542 150 : n->updateAction->action = FKCONSTR_ACTION_NOACTION;
4543 150 : n->updateAction->cols = NIL;
4544 150 : n->deleteAction = $1;
4545 150 : $$ = n;
4546 : }
4547 : | key_update key_delete
4548 : {
4549 156 : KeyActions *n = palloc(sizeof(KeyActions));
4550 :
4551 156 : n->updateAction = $1;
4552 156 : n->deleteAction = $2;
4553 156 : $$ = n;
4554 : }
4555 : | key_delete key_update
4556 : {
4557 150 : KeyActions *n = palloc(sizeof(KeyActions));
4558 :
4559 150 : n->updateAction = $2;
4560 150 : n->deleteAction = $1;
4561 150 : $$ = n;
4562 : }
4563 : | /*EMPTY*/
4564 : {
4565 2106 : KeyActions *n = palloc(sizeof(KeyActions));
4566 :
4567 2106 : n->updateAction = palloc(sizeof(KeyAction));
4568 2106 : n->updateAction->action = FKCONSTR_ACTION_NOACTION;
4569 2106 : n->updateAction->cols = NIL;
4570 2106 : n->deleteAction = palloc(sizeof(KeyAction));
4571 2106 : n->deleteAction->action = FKCONSTR_ACTION_NOACTION;
4572 2106 : n->deleteAction->cols = NIL;
4573 2106 : $$ = n;
4574 : }
4575 : ;
4576 :
4577 : key_update: ON UPDATE key_action
4578 : {
4579 386 : if (($3)->cols)
4580 6 : ereport(ERROR,
4581 : (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
4582 : errmsg("a column list with %s is only supported for ON DELETE actions",
4583 : ($3)->action == FKCONSTR_ACTION_SETNULL ? "SET NULL" : "SET DEFAULT"),
4584 : parser_errposition(@1)));
4585 380 : $$ = $3;
4586 : }
4587 : ;
4588 :
4589 : key_delete: ON DELETE_P key_action
4590 : {
4591 456 : $$ = $3;
4592 : }
4593 : ;
4594 :
4595 : key_action:
4596 : NO ACTION
4597 : {
4598 80 : KeyAction *n = palloc(sizeof(KeyAction));
4599 :
4600 80 : n->action = FKCONSTR_ACTION_NOACTION;
4601 80 : n->cols = NIL;
4602 80 : $$ = n;
4603 : }
4604 : | RESTRICT
4605 : {
4606 48 : KeyAction *n = palloc(sizeof(KeyAction));
4607 :
4608 48 : n->action = FKCONSTR_ACTION_RESTRICT;
4609 48 : n->cols = NIL;
4610 48 : $$ = n;
4611 : }
4612 : | CASCADE
4613 : {
4614 422 : KeyAction *n = palloc(sizeof(KeyAction));
4615 :
4616 422 : n->action = FKCONSTR_ACTION_CASCADE;
4617 422 : n->cols = NIL;
4618 422 : $$ = n;
4619 : }
4620 : | SET NULL_P opt_column_list
4621 : {
4622 190 : KeyAction *n = palloc(sizeof(KeyAction));
4623 :
4624 190 : n->action = FKCONSTR_ACTION_SETNULL;
4625 190 : n->cols = $3;
4626 190 : $$ = n;
4627 : }
4628 : | SET DEFAULT opt_column_list
4629 : {
4630 102 : KeyAction *n = palloc(sizeof(KeyAction));
4631 :
4632 102 : n->action = FKCONSTR_ACTION_SETDEFAULT;
4633 102 : n->cols = $3;
4634 102 : $$ = n;
4635 : }
4636 : ;
4637 :
4638 2090 : OptInherit: INHERITS '(' qualified_name_list ')' { $$ = $3; }
4639 27850 : | /*EMPTY*/ { $$ = NIL; }
4640 : ;
4641 :
4642 : /* Optional partition key specification */
4643 4990 : OptPartitionSpec: PartitionSpec { $$ = $1; }
4644 32578 : | /*EMPTY*/ { $$ = NULL; }
4645 : ;
4646 :
4647 : PartitionSpec: PARTITION BY ColId '(' part_params ')'
4648 : {
4649 4996 : PartitionSpec *n = makeNode(PartitionSpec);
4650 :
4651 4996 : n->strategy = parsePartitionStrategy($3, @3, yyscanner);
4652 4990 : n->partParams = $5;
4653 4990 : n->location = @1;
4654 :
4655 4990 : $$ = n;
4656 : }
4657 : ;
4658 :
4659 4996 : part_params: part_elem { $$ = list_make1($1); }
4660 456 : | part_params ',' part_elem { $$ = lappend($1, $3); }
4661 : ;
4662 :
4663 : part_elem: ColId opt_collate opt_qualified_name
4664 : {
4665 5148 : PartitionElem *n = makeNode(PartitionElem);
4666 :
4667 5148 : n->name = $1;
4668 5148 : n->expr = NULL;
4669 5148 : n->collation = $2;
4670 5148 : n->opclass = $3;
4671 5148 : n->location = @1;
4672 5148 : $$ = n;
4673 : }
4674 : | func_expr_windowless opt_collate opt_qualified_name
4675 : {
4676 130 : PartitionElem *n = makeNode(PartitionElem);
4677 :
4678 130 : n->name = NULL;
4679 130 : n->expr = $1;
4680 130 : n->collation = $2;
4681 130 : n->opclass = $3;
4682 130 : n->location = @1;
4683 130 : $$ = n;
4684 : }
4685 : | '(' a_expr ')' opt_collate opt_qualified_name
4686 : {
4687 174 : PartitionElem *n = makeNode(PartitionElem);
4688 :
4689 174 : n->name = NULL;
4690 174 : n->expr = $2;
4691 174 : n->collation = $4;
4692 174 : n->opclass = $5;
4693 174 : n->location = @1;
4694 174 : $$ = n;
4695 : }
4696 : ;
4697 :
4698 : table_access_method_clause:
4699 122 : USING name { $$ = $2; }
4700 39370 : | /*EMPTY*/ { $$ = NULL; }
4701 : ;
4702 :
4703 : /* WITHOUT OIDS is legacy only */
4704 : OptWith:
4705 754 : WITH reloptions { $$ = $2; }
4706 24 : | WITHOUT OIDS { $$ = NIL; }
4707 38126 : | /*EMPTY*/ { $$ = NIL; }
4708 : ;
4709 :
4710 60 : OnCommitOption: ON COMMIT DROP { $$ = ONCOMMIT_DROP; }
4711 104 : | ON COMMIT DELETE_P ROWS { $$ = ONCOMMIT_DELETE_ROWS; }
4712 24 : | ON COMMIT PRESERVE ROWS { $$ = ONCOMMIT_PRESERVE_ROWS; }
4713 38716 : | /*EMPTY*/ { $$ = ONCOMMIT_NOOP; }
4714 : ;
4715 :
4716 216 : OptTableSpace: TABLESPACE name { $$ = $2; }
4717 45950 : | /*EMPTY*/ { $$ = NULL; }
4718 : ;
4719 :
4720 66 : OptConsTableSpace: USING INDEX TABLESPACE name { $$ = $4; }
4721 9124 : | /*EMPTY*/ { $$ = NULL; }
4722 : ;
4723 :
4724 10666 : ExistingIndex: USING INDEX name { $$ = $3; }
4725 : ;
4726 :
4727 : /*****************************************************************************
4728 : *
4729 : * QUERY :
4730 : * CREATE STATISTICS [[IF NOT EXISTS] stats_name] [(stat types)]
4731 : * ON expression-list FROM from_list
4732 : *
4733 : * Note: the expectation here is that the clauses after ON are a subset of
4734 : * SELECT syntax, allowing for expressions and joined tables, and probably
4735 : * someday a WHERE clause. Much less than that is currently implemented,
4736 : * but the grammar accepts it and then we'll throw FEATURE_NOT_SUPPORTED
4737 : * errors as necessary at execution.
4738 : *
4739 : * Statistics name is optional unless IF NOT EXISTS is specified.
4740 : *
4741 : *****************************************************************************/
4742 :
4743 : CreateStatsStmt:
4744 : CREATE STATISTICS opt_qualified_name
4745 : opt_name_list ON stats_params FROM from_list
4746 : {
4747 682 : CreateStatsStmt *n = makeNode(CreateStatsStmt);
4748 :
4749 682 : n->defnames = $3;
4750 682 : n->stat_types = $4;
4751 682 : n->exprs = $6;
4752 682 : n->relations = $8;
4753 682 : n->stxcomment = NULL;
4754 682 : n->if_not_exists = false;
4755 682 : $$ = (Node *) n;
4756 : }
4757 : | CREATE STATISTICS IF_P NOT EXISTS any_name
4758 : opt_name_list ON stats_params FROM from_list
4759 : {
4760 12 : CreateStatsStmt *n = makeNode(CreateStatsStmt);
4761 :
4762 12 : n->defnames = $6;
4763 12 : n->stat_types = $7;
4764 12 : n->exprs = $9;
4765 12 : n->relations = $11;
4766 12 : n->stxcomment = NULL;
4767 12 : n->if_not_exists = true;
4768 12 : $$ = (Node *) n;
4769 : }
4770 : ;
4771 :
4772 : /*
4773 : * Statistics attributes can be either simple column references, or arbitrary
4774 : * expressions in parens. For compatibility with index attributes permitted
4775 : * in CREATE INDEX, we allow an expression that's just a function call to be
4776 : * written without parens.
4777 : */
4778 :
4779 706 : stats_params: stats_param { $$ = list_make1($1); }
4780 972 : | stats_params ',' stats_param { $$ = lappend($1, $3); }
4781 : ;
4782 :
4783 : stats_param: ColId
4784 : {
4785 1174 : $$ = makeNode(StatsElem);
4786 1174 : $$->name = $1;
4787 1174 : $$->expr = NULL;
4788 : }
4789 : | func_expr_windowless
4790 : {
4791 32 : $$ = makeNode(StatsElem);
4792 32 : $$->name = NULL;
4793 32 : $$->expr = $1;
4794 : }
4795 : | '(' a_expr ')'
4796 : {
4797 472 : $$ = makeNode(StatsElem);
4798 472 : $$->name = NULL;
4799 472 : $$->expr = $2;
4800 : }
4801 : ;
4802 :
4803 : /*****************************************************************************
4804 : *
4805 : * QUERY :
4806 : * ALTER STATISTICS [IF EXISTS] stats_name
4807 : * SET STATISTICS <SignedIconst>
4808 : *
4809 : *****************************************************************************/
4810 :
4811 : AlterStatsStmt:
4812 : ALTER STATISTICS any_name SET STATISTICS set_statistics_value
4813 : {
4814 20 : AlterStatsStmt *n = makeNode(AlterStatsStmt);
4815 :
4816 20 : n->defnames = $3;
4817 20 : n->missing_ok = false;
4818 20 : n->stxstattarget = $6;
4819 20 : $$ = (Node *) n;
4820 : }
4821 : | ALTER STATISTICS IF_P EXISTS any_name SET STATISTICS set_statistics_value
4822 : {
4823 6 : AlterStatsStmt *n = makeNode(AlterStatsStmt);
4824 :
4825 6 : n->defnames = $5;
4826 6 : n->missing_ok = true;
4827 6 : n->stxstattarget = $8;
4828 6 : $$ = (Node *) n;
4829 : }
4830 : ;
4831 :
4832 : /*****************************************************************************
4833 : *
4834 : * QUERY :
4835 : * CREATE TABLE relname AS SelectStmt [ WITH [NO] DATA ]
4836 : *
4837 : *
4838 : * Note: SELECT ... INTO is a now-deprecated alternative for this.
4839 : *
4840 : *****************************************************************************/
4841 :
4842 : CreateAsStmt:
4843 : CREATE OptTemp TABLE create_as_target AS SelectStmt opt_with_data
4844 : {
4845 1208 : CreateTableAsStmt *ctas = makeNode(CreateTableAsStmt);
4846 :
4847 1208 : ctas->query = $6;
4848 1208 : ctas->into = $4;
4849 1208 : ctas->objtype = OBJECT_TABLE;
4850 1208 : ctas->is_select_into = false;
4851 1208 : ctas->if_not_exists = false;
4852 : /* cram additional flags into the IntoClause */
4853 1208 : $4->rel->relpersistence = $2;
4854 1208 : $4->skipData = !($7);
4855 1208 : $$ = (Node *) ctas;
4856 : }
4857 : | CREATE OptTemp TABLE IF_P NOT EXISTS create_as_target AS SelectStmt opt_with_data
4858 : {
4859 52 : CreateTableAsStmt *ctas = makeNode(CreateTableAsStmt);
4860 :
4861 52 : ctas->query = $9;
4862 52 : ctas->into = $7;
4863 52 : ctas->objtype = OBJECT_TABLE;
4864 52 : ctas->is_select_into = false;
4865 52 : ctas->if_not_exists = true;
4866 : /* cram additional flags into the IntoClause */
4867 52 : $7->rel->relpersistence = $2;
4868 52 : $7->skipData = !($10);
4869 52 : $$ = (Node *) ctas;
4870 : }
4871 : ;
4872 :
4873 : create_as_target:
4874 : qualified_name opt_column_list table_access_method_clause
4875 : OptWith OnCommitOption OptTableSpace
4876 : {
4877 1348 : $$ = makeNode(IntoClause);
4878 1348 : $$->rel = $1;
4879 1348 : $$->colNames = $2;
4880 1348 : $$->accessMethod = $3;
4881 1348 : $$->options = $4;
4882 1348 : $$->onCommit = $5;
4883 1348 : $$->tableSpaceName = $6;
4884 1348 : $$->viewQuery = NULL;
4885 1348 : $$->skipData = false; /* might get changed later */
4886 : }
4887 : ;
4888 :
4889 : opt_with_data:
4890 36 : WITH DATA_P { $$ = true; }
4891 218 : | WITH NO DATA_P { $$ = false; }
4892 1944 : | /*EMPTY*/ { $$ = true; }
4893 : ;
4894 :
4895 :
4896 : /*****************************************************************************
4897 : *
4898 : * QUERY :
4899 : * CREATE MATERIALIZED VIEW relname AS SelectStmt
4900 : *
4901 : *****************************************************************************/
4902 :
4903 : CreateMatViewStmt:
4904 : CREATE OptNoLog MATERIALIZED VIEW create_mv_target AS SelectStmt opt_with_data
4905 : {
4906 534 : CreateTableAsStmt *ctas = makeNode(CreateTableAsStmt);
4907 :
4908 534 : ctas->query = $7;
4909 534 : ctas->into = $5;
4910 534 : ctas->objtype = OBJECT_MATVIEW;
4911 534 : ctas->is_select_into = false;
4912 534 : ctas->if_not_exists = false;
4913 : /* cram additional flags into the IntoClause */
4914 534 : $5->rel->relpersistence = $2;
4915 534 : $5->skipData = !($8);
4916 534 : $$ = (Node *) ctas;
4917 : }
4918 : | CREATE OptNoLog MATERIALIZED VIEW IF_P NOT EXISTS create_mv_target AS SelectStmt opt_with_data
4919 : {
4920 48 : CreateTableAsStmt *ctas = makeNode(CreateTableAsStmt);
4921 :
4922 48 : ctas->query = $10;
4923 48 : ctas->into = $8;
4924 48 : ctas->objtype = OBJECT_MATVIEW;
4925 48 : ctas->is_select_into = false;
4926 48 : ctas->if_not_exists = true;
4927 : /* cram additional flags into the IntoClause */
4928 48 : $8->rel->relpersistence = $2;
4929 48 : $8->skipData = !($11);
4930 48 : $$ = (Node *) ctas;
4931 : }
4932 : ;
4933 :
4934 : create_mv_target:
4935 : qualified_name opt_column_list table_access_method_clause opt_reloptions OptTableSpace
4936 : {
4937 582 : $$ = makeNode(IntoClause);
4938 582 : $$->rel = $1;
4939 582 : $$->colNames = $2;
4940 582 : $$->accessMethod = $3;
4941 582 : $$->options = $4;
4942 582 : $$->onCommit = ONCOMMIT_NOOP;
4943 582 : $$->tableSpaceName = $5;
4944 582 : $$->viewQuery = NULL; /* filled at analysis time */
4945 582 : $$->skipData = false; /* might get changed later */
4946 : }
4947 : ;
4948 :
4949 0 : OptNoLog: UNLOGGED { $$ = RELPERSISTENCE_UNLOGGED; }
4950 582 : | /*EMPTY*/ { $$ = RELPERSISTENCE_PERMANENT; }
4951 : ;
4952 :
4953 :
4954 : /*****************************************************************************
4955 : *
4956 : * QUERY :
4957 : * REFRESH MATERIALIZED VIEW qualified_name
4958 : *
4959 : *****************************************************************************/
4960 :
4961 : RefreshMatViewStmt:
4962 : REFRESH MATERIALIZED VIEW opt_concurrently qualified_name opt_with_data
4963 : {
4964 268 : RefreshMatViewStmt *n = makeNode(RefreshMatViewStmt);
4965 :
4966 268 : n->concurrent = $4;
4967 268 : n->relation = $5;
4968 268 : n->skipData = !($6);
4969 268 : $$ = (Node *) n;
4970 : }
4971 : ;
4972 :
4973 :
4974 : /*****************************************************************************
4975 : *
4976 : * QUERY :
4977 : * CREATE SEQUENCE seqname
4978 : * ALTER SEQUENCE seqname
4979 : *
4980 : *****************************************************************************/
4981 :
4982 : CreateSeqStmt:
4983 : CREATE OptTemp SEQUENCE qualified_name OptSeqOptList
4984 : {
4985 656 : CreateSeqStmt *n = makeNode(CreateSeqStmt);
4986 :
4987 656 : $4->relpersistence = $2;
4988 656 : n->sequence = $4;
4989 656 : n->options = $5;
4990 656 : n->ownerId = InvalidOid;
4991 656 : n->if_not_exists = false;
4992 656 : $$ = (Node *) n;
4993 : }
4994 : | CREATE OptTemp SEQUENCE IF_P NOT EXISTS qualified_name OptSeqOptList
4995 : {
4996 24 : CreateSeqStmt *n = makeNode(CreateSeqStmt);
4997 :
4998 24 : $7->relpersistence = $2;
4999 24 : n->sequence = $7;
5000 24 : n->options = $8;
5001 24 : n->ownerId = InvalidOid;
5002 24 : n->if_not_exists = true;
5003 24 : $$ = (Node *) n;
5004 : }
5005 : ;
5006 :
5007 : AlterSeqStmt:
5008 : ALTER SEQUENCE qualified_name SeqOptList
5009 : {
5010 184 : AlterSeqStmt *n = makeNode(AlterSeqStmt);
5011 :
5012 184 : n->sequence = $3;
5013 184 : n->options = $4;
5014 184 : n->missing_ok = false;
5015 184 : $$ = (Node *) n;
5016 : }
5017 : | ALTER SEQUENCE IF_P EXISTS qualified_name SeqOptList
5018 : {
5019 12 : AlterSeqStmt *n = makeNode(AlterSeqStmt);
5020 :
5021 12 : n->sequence = $5;
5022 12 : n->options = $6;
5023 12 : n->missing_ok = true;
5024 12 : $$ = (Node *) n;
5025 : }
5026 :
5027 : ;
5028 :
5029 262 : OptSeqOptList: SeqOptList { $$ = $1; }
5030 418 : | /*EMPTY*/ { $$ = NIL; }
5031 : ;
5032 :
5033 74 : OptParenthesizedSeqOptList: '(' SeqOptList ')' { $$ = $2; }
5034 424 : | /*EMPTY*/ { $$ = NIL; }
5035 : ;
5036 :
5037 532 : SeqOptList: SeqOptElem { $$ = list_make1($1); }
5038 802 : | SeqOptList SeqOptElem { $$ = lappend($1, $2); }
5039 : ;
5040 :
5041 : SeqOptElem: AS SimpleTypename
5042 : {
5043 190 : $$ = makeDefElem("as", (Node *) $2, @1);
5044 : }
5045 : | CACHE NumericOnly
5046 : {
5047 130 : $$ = makeDefElem("cache", (Node *) $2, @1);
5048 : }
5049 : | CYCLE
5050 : {
5051 34 : $$ = makeDefElem("cycle", (Node *) makeBoolean(true), @1);
5052 : }
5053 : | NO CYCLE
5054 : {
5055 14 : $$ = makeDefElem("cycle", (Node *) makeBoolean(false), @1);
5056 : }
5057 : | INCREMENT opt_by NumericOnly
5058 : {
5059 246 : $$ = makeDefElem("increment", (Node *) $3, @1);
5060 : }
5061 : | LOGGED
5062 : {
5063 2 : $$ = makeDefElem("logged", NULL, @1);
5064 : }
5065 : | MAXVALUE NumericOnly
5066 : {
5067 68 : $$ = makeDefElem("maxvalue", (Node *) $2, @1);
5068 : }
5069 : | MINVALUE NumericOnly
5070 : {
5071 68 : $$ = makeDefElem("minvalue", (Node *) $2, @1);
5072 : }
5073 : | NO MAXVALUE
5074 : {
5075 108 : $$ = makeDefElem("maxvalue", NULL, @1);
5076 : }
5077 : | NO MINVALUE
5078 : {
5079 108 : $$ = makeDefElem("minvalue", NULL, @1);
5080 : }
5081 : | OWNED BY any_name
5082 : {
5083 72 : $$ = makeDefElem("owned_by", (Node *) $3, @1);
5084 : }
5085 : | SEQUENCE NAME_P any_name
5086 : {
5087 44 : $$ = makeDefElem("sequence_name", (Node *) $3, @1);
5088 : }
5089 : | START opt_with NumericOnly
5090 : {
5091 236 : $$ = makeDefElem("start", (Node *) $3, @1);
5092 : }
5093 : | RESTART
5094 : {
5095 6 : $$ = makeDefElem("restart", NULL, @1);
5096 : }
5097 : | RESTART opt_with NumericOnly
5098 : {
5099 60 : $$ = makeDefElem("restart", (Node *) $3, @1);
5100 : }
5101 : | UNLOGGED
5102 : {
5103 2 : $$ = makeDefElem("unlogged", NULL, @1);
5104 : }
5105 : ;
5106 :
5107 : opt_by: BY
5108 : | /* EMPTY */
5109 : ;
5110 :
5111 : NumericOnly:
5112 324 : FCONST { $$ = (Node *) makeFloat($1); }
5113 0 : | '+' FCONST { $$ = (Node *) makeFloat($2); }
5114 : | '-' FCONST
5115 : {
5116 20 : Float *f = makeFloat($2);
5117 :
5118 20 : doNegateFloat(f);
5119 20 : $$ = (Node *) f;
5120 : }
5121 12790 : | SignedIconst { $$ = (Node *) makeInteger($1); }
5122 : ;
5123 :
5124 80 : NumericOnly_list: NumericOnly { $$ = list_make1($1); }
5125 6 : | NumericOnly_list ',' NumericOnly { $$ = lappend($1, $3); }
5126 : ;
5127 :
5128 : /*****************************************************************************
5129 : *
5130 : * QUERIES :
5131 : * CREATE [OR REPLACE] [TRUSTED] [PROCEDURAL] LANGUAGE ...
5132 : * DROP [PROCEDURAL] LANGUAGE ...
5133 : *
5134 : *****************************************************************************/
5135 :
5136 : CreatePLangStmt:
5137 : CREATE opt_or_replace opt_trusted opt_procedural LANGUAGE name
5138 : {
5139 : /*
5140 : * We now interpret parameterless CREATE LANGUAGE as
5141 : * CREATE EXTENSION. "OR REPLACE" is silently translated
5142 : * to "IF NOT EXISTS", which isn't quite the same, but
5143 : * seems more useful than throwing an error. We just
5144 : * ignore TRUSTED, as the previous code would have too.
5145 : */
5146 0 : CreateExtensionStmt *n = makeNode(CreateExtensionStmt);
5147 :
5148 0 : n->if_not_exists = $2;
5149 0 : n->extname = $6;
5150 0 : n->options = NIL;
5151 0 : $$ = (Node *) n;
5152 : }
5153 : | CREATE opt_or_replace opt_trusted opt_procedural LANGUAGE name
5154 : HANDLER handler_name opt_inline_handler opt_validator
5155 : {
5156 142 : CreatePLangStmt *n = makeNode(CreatePLangStmt);
5157 :
5158 142 : n->replace = $2;
5159 142 : n->plname = $6;
5160 142 : n->plhandler = $8;
5161 142 : n->plinline = $9;
5162 142 : n->plvalidator = $10;
5163 142 : n->pltrusted = $3;
5164 142 : $$ = (Node *) n;
5165 : }
5166 : ;
5167 :
5168 : opt_trusted:
5169 112 : TRUSTED { $$ = true; }
5170 38 : | /*EMPTY*/ { $$ = false; }
5171 : ;
5172 :
5173 : /* This ought to be just func_name, but that causes reduce/reduce conflicts
5174 : * (CREATE LANGUAGE is the only place where func_name isn't followed by '(').
5175 : * Work around by using simple names, instead.
5176 : */
5177 : handler_name:
5178 554 : name { $$ = list_make1(makeString($1)); }
5179 2 : | name attrs { $$ = lcons(makeString($1), $2); }
5180 : ;
5181 :
5182 : opt_inline_handler:
5183 124 : INLINE_P handler_name { $$ = $2; }
5184 18 : | /*EMPTY*/ { $$ = NIL; }
5185 : ;
5186 :
5187 : validator_clause:
5188 124 : VALIDATOR handler_name { $$ = $2; }
5189 0 : | NO VALIDATOR { $$ = NIL; }
5190 : ;
5191 :
5192 : opt_validator:
5193 124 : validator_clause { $$ = $1; }
5194 18 : | /*EMPTY*/ { $$ = NIL; }
5195 : ;
5196 :
5197 : opt_procedural:
5198 : PROCEDURAL
5199 : | /*EMPTY*/
5200 : ;
5201 :
5202 : /*****************************************************************************
5203 : *
5204 : * QUERY:
5205 : * CREATE TABLESPACE tablespace LOCATION '/path/to/tablespace/'
5206 : *
5207 : *****************************************************************************/
5208 :
5209 : CreateTableSpaceStmt: CREATE TABLESPACE name OptTableSpaceOwner LOCATION Sconst opt_reloptions
5210 : {
5211 130 : CreateTableSpaceStmt *n = makeNode(CreateTableSpaceStmt);
5212 :
5213 130 : n->tablespacename = $3;
5214 130 : n->owner = $4;
5215 130 : n->location = $6;
5216 130 : n->options = $7;
5217 130 : $$ = (Node *) n;
5218 : }
5219 : ;
5220 :
5221 10 : OptTableSpaceOwner: OWNER RoleSpec { $$ = $2; }
5222 120 : | /*EMPTY */ { $$ = NULL; }
5223 : ;
5224 :
5225 : /*****************************************************************************
5226 : *
5227 : * QUERY :
5228 : * DROP TABLESPACE <tablespace>
5229 : *
5230 : * No need for drop behaviour as we cannot implement dependencies for
5231 : * objects in other databases; we can only support RESTRICT.
5232 : *
5233 : ****************************************************************************/
5234 :
5235 : DropTableSpaceStmt: DROP TABLESPACE name
5236 : {
5237 64 : DropTableSpaceStmt *n = makeNode(DropTableSpaceStmt);
5238 :
5239 64 : n->tablespacename = $3;
5240 64 : n->missing_ok = false;
5241 64 : $$ = (Node *) n;
5242 : }
5243 : | DROP TABLESPACE IF_P EXISTS name
5244 : {
5245 0 : DropTableSpaceStmt *n = makeNode(DropTableSpaceStmt);
5246 :
5247 0 : n->tablespacename = $5;
5248 0 : n->missing_ok = true;
5249 0 : $$ = (Node *) n;
5250 : }
5251 : ;
5252 :
5253 : /*****************************************************************************
5254 : *
5255 : * QUERY:
5256 : * CREATE EXTENSION extension
5257 : * [ WITH ] [ SCHEMA schema ] [ VERSION version ]
5258 : *
5259 : *****************************************************************************/
5260 :
5261 : CreateExtensionStmt: CREATE EXTENSION name opt_with create_extension_opt_list
5262 : {
5263 524 : CreateExtensionStmt *n = makeNode(CreateExtensionStmt);
5264 :
5265 524 : n->extname = $3;
5266 524 : n->if_not_exists = false;
5267 524 : n->options = $5;
5268 524 : $$ = (Node *) n;
5269 : }
5270 : | CREATE EXTENSION IF_P NOT EXISTS name opt_with create_extension_opt_list
5271 : {
5272 18 : CreateExtensionStmt *n = makeNode(CreateExtensionStmt);
5273 :
5274 18 : n->extname = $6;
5275 18 : n->if_not_exists = true;
5276 18 : n->options = $8;
5277 18 : $$ = (Node *) n;
5278 : }
5279 : ;
5280 :
5281 : create_extension_opt_list:
5282 : create_extension_opt_list create_extension_opt_item
5283 98 : { $$ = lappend($1, $2); }
5284 : | /* EMPTY */
5285 542 : { $$ = NIL; }
5286 : ;
5287 :
5288 : create_extension_opt_item:
5289 : SCHEMA name
5290 : {
5291 46 : $$ = makeDefElem("schema", (Node *) makeString($2), @1);
5292 : }
5293 : | VERSION_P NonReservedWord_or_Sconst
5294 : {
5295 12 : $$ = makeDefElem("new_version", (Node *) makeString($2), @1);
5296 : }
5297 : | FROM NonReservedWord_or_Sconst
5298 : {
5299 0 : ereport(ERROR,
5300 : (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
5301 : errmsg("CREATE EXTENSION ... FROM is no longer supported"),
5302 : parser_errposition(@1)));
5303 : }
5304 : | CASCADE
5305 : {
5306 40 : $$ = makeDefElem("cascade", (Node *) makeBoolean(true), @1);
5307 : }
5308 : ;
5309 :
5310 : /*****************************************************************************
5311 : *
5312 : * ALTER EXTENSION name UPDATE [ TO version ]
5313 : *
5314 : *****************************************************************************/
5315 :
5316 : AlterExtensionStmt: ALTER EXTENSION name UPDATE alter_extension_opt_list
5317 : {
5318 40 : AlterExtensionStmt *n = makeNode(AlterExtensionStmt);
5319 :
5320 40 : n->extname = $3;
5321 40 : n->options = $5;
5322 40 : $$ = (Node *) n;
5323 : }
5324 : ;
5325 :
5326 : alter_extension_opt_list:
5327 : alter_extension_opt_list alter_extension_opt_item
5328 40 : { $$ = lappend($1, $2); }
5329 : | /* EMPTY */
5330 40 : { $$ = NIL; }
5331 : ;
5332 :
5333 : alter_extension_opt_item:
5334 : TO NonReservedWord_or_Sconst
5335 : {
5336 40 : $$ = makeDefElem("new_version", (Node *) makeString($2), @1);
5337 : }
5338 : ;
5339 :
5340 : /*****************************************************************************
5341 : *
5342 : * ALTER EXTENSION name ADD/DROP object-identifier
5343 : *
5344 : *****************************************************************************/
5345 :
5346 : AlterExtensionContentsStmt:
5347 : ALTER EXTENSION name add_drop object_type_name name
5348 : {
5349 18 : AlterExtensionContentsStmt *n = makeNode(AlterExtensionContentsStmt);
5350 :
5351 18 : n->extname = $3;
5352 18 : n->action = $4;
5353 18 : n->objtype = $5;
5354 18 : n->object = (Node *) makeString($6);
5355 18 : $$ = (Node *) n;
5356 : }
5357 : | ALTER EXTENSION name add_drop object_type_any_name any_name
5358 : {
5359 88 : AlterExtensionContentsStmt *n = makeNode(AlterExtensionContentsStmt);
5360 :
5361 88 : n->extname = $3;
5362 88 : n->action = $4;
5363 88 : n->objtype = $5;
5364 88 : n->object = (Node *) $6;
5365 88 : $$ = (Node *) n;
5366 : }
5367 : | ALTER EXTENSION name add_drop AGGREGATE aggregate_with_argtypes
5368 : {
5369 8 : AlterExtensionContentsStmt *n = makeNode(AlterExtensionContentsStmt);
5370 :
5371 8 : n->extname = $3;
5372 8 : n->action = $4;
5373 8 : n->objtype = OBJECT_AGGREGATE;
5374 8 : n->object = (Node *) $6;
5375 8 : $$ = (Node *) n;
5376 : }
5377 : | ALTER EXTENSION name add_drop CAST '(' Typename AS Typename ')'
5378 : {
5379 4 : AlterExtensionContentsStmt *n = makeNode(AlterExtensionContentsStmt);
5380 :
5381 4 : n->extname = $3;
5382 4 : n->action = $4;
5383 4 : n->objtype = OBJECT_CAST;
5384 4 : n->object = (Node *) list_make2($7, $9);
5385 4 : $$ = (Node *) n;
5386 : }
5387 : | ALTER EXTENSION name add_drop DOMAIN_P Typename
5388 : {
5389 0 : AlterExtensionContentsStmt *n = makeNode(AlterExtensionContentsStmt);
5390 :
5391 0 : n->extname = $3;
5392 0 : n->action = $4;
5393 0 : n->objtype = OBJECT_DOMAIN;
5394 0 : n->object = (Node *) $6;
5395 0 : $$ = (Node *) n;
5396 : }
5397 : | ALTER EXTENSION name add_drop FUNCTION function_with_argtypes
5398 : {
5399 110 : AlterExtensionContentsStmt *n = makeNode(AlterExtensionContentsStmt);
5400 :
5401 110 : n->extname = $3;
5402 110 : n->action = $4;
5403 110 : n->objtype = OBJECT_FUNCTION;
5404 110 : n->object = (Node *) $6;
5405 110 : $$ = (Node *) n;
5406 : }
5407 : | ALTER EXTENSION name add_drop OPERATOR operator_with_argtypes
5408 : {
5409 18 : AlterExtensionContentsStmt *n = makeNode(AlterExtensionContentsStmt);
5410 :
5411 18 : n->extname = $3;
5412 18 : n->action = $4;
5413 18 : n->objtype = OBJECT_OPERATOR;
5414 18 : n->object = (Node *) $6;
5415 18 : $$ = (Node *) n;
5416 : }
5417 : | ALTER EXTENSION name add_drop OPERATOR CLASS any_name USING name
5418 : {
5419 4 : AlterExtensionContentsStmt *n = makeNode(AlterExtensionContentsStmt);
5420 :
5421 4 : n->extname = $3;
5422 4 : n->action = $4;
5423 4 : n->objtype = OBJECT_OPCLASS;
5424 4 : n->object = (Node *) lcons(makeString($9), $7);
5425 4 : $$ = (Node *) n;
5426 : }
5427 : | ALTER EXTENSION name add_drop OPERATOR FAMILY any_name USING name
5428 : {
5429 4 : AlterExtensionContentsStmt *n = makeNode(AlterExtensionContentsStmt);
5430 :
5431 4 : n->extname = $3;
5432 4 : n->action = $4;
5433 4 : n->objtype = OBJECT_OPFAMILY;
5434 4 : n->object = (Node *) lcons(makeString($9), $7);
5435 4 : $$ = (Node *) n;
5436 : }
5437 : | ALTER EXTENSION name add_drop PROCEDURE function_with_argtypes
5438 : {
5439 0 : AlterExtensionContentsStmt *n = makeNode(AlterExtensionContentsStmt);
5440 :
5441 0 : n->extname = $3;
5442 0 : n->action = $4;
5443 0 : n->objtype = OBJECT_PROCEDURE;
5444 0 : n->object = (Node *) $6;
5445 0 : $$ = (Node *) n;
5446 : }
5447 : | ALTER EXTENSION name add_drop ROUTINE function_with_argtypes
5448 : {
5449 0 : AlterExtensionContentsStmt *n = makeNode(AlterExtensionContentsStmt);
5450 :
5451 0 : n->extname = $3;
5452 0 : n->action = $4;
5453 0 : n->objtype = OBJECT_ROUTINE;
5454 0 : n->object = (Node *) $6;
5455 0 : $$ = (Node *) n;
5456 : }
5457 : | ALTER EXTENSION name add_drop TRANSFORM FOR Typename LANGUAGE name
5458 : {
5459 4 : AlterExtensionContentsStmt *n = makeNode(AlterExtensionContentsStmt);
5460 :
5461 4 : n->extname = $3;
5462 4 : n->action = $4;
5463 4 : n->objtype = OBJECT_TRANSFORM;
5464 4 : n->object = (Node *) list_make2($7, makeString($9));
5465 4 : $$ = (Node *) n;
5466 : }
5467 : | ALTER EXTENSION name add_drop TYPE_P Typename
5468 : {
5469 8 : AlterExtensionContentsStmt *n = makeNode(AlterExtensionContentsStmt);
5470 :
5471 8 : n->extname = $3;
5472 8 : n->action = $4;
5473 8 : n->objtype = OBJECT_TYPE;
5474 8 : n->object = (Node *) $6;
5475 8 : $$ = (Node *) n;
5476 : }
5477 : ;
5478 :
5479 : /*****************************************************************************
5480 : *
5481 : * QUERY:
5482 : * CREATE FOREIGN DATA WRAPPER name options
5483 : *
5484 : *****************************************************************************/
5485 :
5486 : CreateFdwStmt: CREATE FOREIGN DATA_P WRAPPER name opt_fdw_options create_generic_options
5487 : {
5488 206 : CreateFdwStmt *n = makeNode(CreateFdwStmt);
5489 :
5490 206 : n->fdwname = $5;
5491 206 : n->func_options = $6;
5492 206 : n->options = $7;
5493 206 : $$ = (Node *) n;
5494 : }
5495 : ;
5496 :
5497 : fdw_option:
5498 56 : HANDLER handler_name { $$ = makeDefElem("handler", (Node *) $2, @1); }
5499 0 : | NO HANDLER { $$ = makeDefElem("handler", NULL, @1); }
5500 48 : | VALIDATOR handler_name { $$ = makeDefElem("validator", (Node *) $2, @1); }
5501 6 : | NO VALIDATOR { $$ = makeDefElem("validator", NULL, @1); }
5502 : ;
5503 :
5504 : fdw_options:
5505 90 : fdw_option { $$ = list_make1($1); }
5506 20 : | fdw_options fdw_option { $$ = lappend($1, $2); }
5507 : ;
5508 :
5509 : opt_fdw_options:
5510 54 : fdw_options { $$ = $1; }
5511 244 : | /*EMPTY*/ { $$ = NIL; }
5512 : ;
5513 :
5514 : /*****************************************************************************
5515 : *
5516 : * QUERY :
5517 : * ALTER FOREIGN DATA WRAPPER name options
5518 : *
5519 : ****************************************************************************/
5520 :
5521 : AlterFdwStmt: ALTER FOREIGN DATA_P WRAPPER name opt_fdw_options alter_generic_options
5522 : {
5523 86 : AlterFdwStmt *n = makeNode(AlterFdwStmt);
5524 :
5525 86 : n->fdwname = $5;
5526 86 : n->func_options = $6;
5527 86 : n->options = $7;
5528 86 : $$ = (Node *) n;
5529 : }
5530 : | ALTER FOREIGN DATA_P WRAPPER name fdw_options
5531 : {
5532 36 : AlterFdwStmt *n = makeNode(AlterFdwStmt);
5533 :
5534 36 : n->fdwname = $5;
5535 36 : n->func_options = $6;
5536 36 : n->options = NIL;
5537 36 : $$ = (Node *) n;
5538 : }
5539 : ;
5540 :
5541 : /* Options definition for CREATE FDW, SERVER and USER MAPPING */
5542 : create_generic_options:
5543 740 : OPTIONS '(' generic_option_list ')' { $$ = $3; }
5544 67854 : | /*EMPTY*/ { $$ = NIL; }
5545 : ;
5546 :
5547 : generic_option_list:
5548 : generic_option_elem
5549 : {
5550 740 : $$ = list_make1($1);
5551 : }
5552 : | generic_option_list ',' generic_option_elem
5553 : {
5554 480 : $$ = lappend($1, $3);
5555 : }
5556 : ;
5557 :
5558 : /* Options definition for ALTER FDW, SERVER and USER MAPPING */
5559 : alter_generic_options:
5560 508 : OPTIONS '(' alter_generic_option_list ')' { $$ = $3; }
5561 : ;
5562 :
5563 : alter_generic_option_list:
5564 : alter_generic_option_elem
5565 : {
5566 508 : $$ = list_make1($1);
5567 : }
5568 : | alter_generic_option_list ',' alter_generic_option_elem
5569 : {
5570 168 : $$ = lappend($1, $3);
5571 : }
5572 : ;
5573 :
5574 : alter_generic_option_elem:
5575 : generic_option_elem
5576 : {
5577 200 : $$ = $1;
5578 : }
5579 : | SET generic_option_elem
5580 : {
5581 128 : $$ = $2;
5582 128 : $$->defaction = DEFELEM_SET;
5583 : }
5584 : | ADD_P generic_option_elem
5585 : {
5586 220 : $$ = $2;
5587 220 : $$->defaction = DEFELEM_ADD;
5588 : }
5589 : | DROP generic_option_name
5590 : {
5591 128 : $$ = makeDefElemExtended(NULL, $2, NULL, DEFELEM_DROP, @2);
5592 : }
5593 : ;
5594 :
5595 : generic_option_elem:
5596 : generic_option_name generic_option_arg
5597 : {
5598 1768 : $$ = makeDefElem($1, $2, @1);
5599 : }
5600 : ;
5601 :
5602 : generic_option_name:
5603 1896 : ColLabel { $$ = $1; }
5604 : ;
5605 :
5606 : /* We could use def_arg here, but the spec only requires string literals */
5607 : generic_option_arg:
5608 1768 : Sconst { $$ = (Node *) makeString($1); }
5609 : ;
5610 :
5611 : /*****************************************************************************
5612 : *
5613 : * QUERY:
5614 : * CREATE SERVER name [TYPE] [VERSION] [OPTIONS]
5615 : *
5616 : *****************************************************************************/
5617 :
5618 : CreateForeignServerStmt: CREATE SERVER name opt_type opt_foreign_server_version
5619 : FOREIGN DATA_P WRAPPER name create_generic_options
5620 : {
5621 272 : CreateForeignServerStmt *n = makeNode(CreateForeignServerStmt);
5622 :
5623 272 : n->servername = $3;
5624 272 : n->servertype = $4;
5625 272 : n->version = $5;
5626 272 : n->fdwname = $9;
5627 272 : n->options = $10;
5628 272 : n->if_not_exists = false;
5629 272 : $$ = (Node *) n;
5630 : }
5631 : | CREATE SERVER IF_P NOT EXISTS name opt_type opt_foreign_server_version
5632 : FOREIGN DATA_P WRAPPER name create_generic_options
5633 : {
5634 24 : CreateForeignServerStmt *n = makeNode(CreateForeignServerStmt);
5635 :
5636 24 : n->servername = $6;
5637 24 : n->servertype = $7;
5638 24 : n->version = $8;
5639 24 : n->fdwname = $12;
5640 24 : n->options = $13;
5641 24 : n->if_not_exists = true;
5642 24 : $$ = (Node *) n;
5643 : }
5644 : ;
5645 :
5646 : opt_type:
5647 18 : TYPE_P Sconst { $$ = $2; }
5648 278 : | /*EMPTY*/ { $$ = NULL; }
5649 : ;
5650 :
5651 :
5652 : foreign_server_version:
5653 66 : VERSION_P Sconst { $$ = $2; }
5654 0 : | VERSION_P NULL_P { $$ = NULL; }
5655 : ;
5656 :
5657 : opt_foreign_server_version:
5658 18 : foreign_server_version { $$ = $1; }
5659 278 : | /*EMPTY*/ { $$ = NULL; }
5660 : ;
5661 :
5662 : /*****************************************************************************
5663 : *
5664 : * QUERY :
5665 : * ALTER SERVER name [VERSION] [OPTIONS]
5666 : *
5667 : ****************************************************************************/
5668 :
5669 : AlterForeignServerStmt: ALTER SERVER name foreign_server_version alter_generic_options
5670 : {
5671 6 : AlterForeignServerStmt *n = makeNode(AlterForeignServerStmt);
5672 :
5673 6 : n->servername = $3;
5674 6 : n->version = $4;
5675 6 : n->options = $5;
5676 6 : n->has_version = true;
5677 6 : $$ = (Node *) n;
5678 : }
5679 : | ALTER SERVER name foreign_server_version
5680 : {
5681 42 : AlterForeignServerStmt *n = makeNode(AlterForeignServerStmt);
5682 :
5683 42 : n->servername = $3;
5684 42 : n->version = $4;
5685 42 : n->has_version = true;
5686 42 : $$ = (Node *) n;
5687 : }
5688 : | ALTER SERVER name alter_generic_options
5689 : {
5690 184 : AlterForeignServerStmt *n = makeNode(AlterForeignServerStmt);
5691 :
5692 184 : n->servername = $3;
5693 184 : n->options = $4;
5694 184 : $$ = (Node *) n;
5695 : }
5696 : ;
5697 :
5698 : /*****************************************************************************
5699 : *
5700 : * QUERY:
5701 : * CREATE FOREIGN TABLE relname (...) SERVER name (...)
5702 : *
5703 : *****************************************************************************/
5704 :
5705 : CreateForeignTableStmt:
5706 : CREATE FOREIGN TABLE qualified_name
5707 : '(' OptTableElementList ')'
5708 : OptInherit SERVER name create_generic_options
5709 : {
5710 396 : CreateForeignTableStmt *n = makeNode(CreateForeignTableStmt);
5711 :
5712 396 : $4->relpersistence = RELPERSISTENCE_PERMANENT;
5713 396 : n->base.relation = $4;
5714 396 : n->base.tableElts = $6;
5715 396 : n->base.inhRelations = $8;
5716 396 : n->base.ofTypename = NULL;
5717 396 : n->base.constraints = NIL;
5718 396 : n->base.options = NIL;
5719 396 : n->base.oncommit = ONCOMMIT_NOOP;
5720 396 : n->base.tablespacename = NULL;
5721 396 : n->base.if_not_exists = false;
5722 : /* FDW-specific data */
5723 396 : n->servername = $10;
5724 396 : n->options = $11;
5725 396 : $$ = (Node *) n;
5726 : }
5727 : | CREATE FOREIGN TABLE IF_P NOT EXISTS qualified_name
5728 : '(' OptTableElementList ')'
5729 : OptInherit SERVER name create_generic_options
5730 : {
5731 0 : CreateForeignTableStmt *n = makeNode(CreateForeignTableStmt);
5732 :
5733 0 : $7->relpersistence = RELPERSISTENCE_PERMANENT;
5734 0 : n->base.relation = $7;
5735 0 : n->base.tableElts = $9;
5736 0 : n->base.inhRelations = $11;
5737 0 : n->base.ofTypename = NULL;
5738 0 : n->base.constraints = NIL;
5739 0 : n->base.options = NIL;
5740 0 : n->base.oncommit = ONCOMMIT_NOOP;
5741 0 : n->base.tablespacename = NULL;
5742 0 : n->base.if_not_exists = true;
5743 : /* FDW-specific data */
5744 0 : n->servername = $13;
5745 0 : n->options = $14;
5746 0 : $$ = (Node *) n;
5747 : }
5748 : | CREATE FOREIGN TABLE qualified_name
5749 : PARTITION OF qualified_name OptTypedTableElementList PartitionBoundSpec
5750 : SERVER name create_generic_options
5751 : {
5752 90 : CreateForeignTableStmt *n = makeNode(CreateForeignTableStmt);
5753 :
5754 90 : $4->relpersistence = RELPERSISTENCE_PERMANENT;
5755 90 : n->base.relation = $4;
5756 90 : n->base.inhRelations = list_make1($7);
5757 90 : n->base.tableElts = $8;
5758 90 : n->base.partbound = $9;
5759 90 : n->base.ofTypename = NULL;
5760 90 : n->base.constraints = NIL;
5761 90 : n->base.options = NIL;
5762 90 : n->base.oncommit = ONCOMMIT_NOOP;
5763 90 : n->base.tablespacename = NULL;
5764 90 : n->base.if_not_exists = false;
5765 : /* FDW-specific data */
5766 90 : n->servername = $11;
5767 90 : n->options = $12;
5768 90 : $$ = (Node *) n;
5769 : }
5770 : | CREATE FOREIGN TABLE IF_P NOT EXISTS qualified_name
5771 : PARTITION OF qualified_name OptTypedTableElementList PartitionBoundSpec
5772 : SERVER name create_generic_options
5773 : {
5774 0 : CreateForeignTableStmt *n = makeNode(CreateForeignTableStmt);
5775 :
5776 0 : $7->relpersistence = RELPERSISTENCE_PERMANENT;
5777 0 : n->base.relation = $7;
5778 0 : n->base.inhRelations = list_make1($10);
5779 0 : n->base.tableElts = $11;
5780 0 : n->base.partbound = $12;
5781 0 : n->base.ofTypename = NULL;
5782 0 : n->base.constraints = NIL;
5783 0 : n->base.options = NIL;
5784 0 : n->base.oncommit = ONCOMMIT_NOOP;
5785 0 : n->base.tablespacename = NULL;
5786 0 : n->base.if_not_exists = true;
5787 : /* FDW-specific data */
5788 0 : n->servername = $14;
5789 0 : n->options = $15;
5790 0 : $$ = (Node *) n;
5791 : }
5792 : ;
5793 :
5794 : /*****************************************************************************
5795 : *
5796 : * QUERY:
5797 : * IMPORT FOREIGN SCHEMA remote_schema
5798 : * [ { LIMIT TO | EXCEPT } ( table_list ) ]
5799 : * FROM SERVER server_name INTO local_schema [ OPTIONS (...) ]
5800 : *
5801 : ****************************************************************************/
5802 :
5803 : ImportForeignSchemaStmt:
5804 : IMPORT_P FOREIGN SCHEMA name import_qualification
5805 : FROM SERVER name INTO name create_generic_options
5806 : {
5807 48 : ImportForeignSchemaStmt *n = makeNode(ImportForeignSchemaStmt);
5808 :
5809 48 : n->server_name = $8;
5810 48 : n->remote_schema = $4;
5811 48 : n->local_schema = $10;
5812 48 : n->list_type = $5->type;
5813 48 : n->table_list = $5->table_names;
5814 48 : n->options = $11;
5815 48 : $$ = (Node *) n;
5816 : }
5817 : ;
5818 :
5819 : import_qualification_type:
5820 14 : LIMIT TO { $$ = FDW_IMPORT_SCHEMA_LIMIT_TO; }
5821 14 : | EXCEPT { $$ = FDW_IMPORT_SCHEMA_EXCEPT; }
5822 : ;
5823 :
5824 : import_qualification:
5825 : import_qualification_type '(' relation_expr_list ')'
5826 : {
5827 28 : ImportQual *n = (ImportQual *) palloc(sizeof(ImportQual));
5828 :
5829 28 : n->type = $1;
5830 28 : n->table_names = $3;
5831 28 : $$ = n;
5832 : }
5833 : | /*EMPTY*/
5834 : {
5835 20 : ImportQual *n = (ImportQual *) palloc(sizeof(ImportQual));
5836 20 : n->type = FDW_IMPORT_SCHEMA_ALL;
5837 20 : n->table_names = NIL;
5838 20 : $$ = n;
5839 : }
5840 : ;
5841 :
5842 : /*****************************************************************************
5843 : *
5844 : * QUERY:
5845 : * CREATE USER MAPPING FOR auth_ident SERVER name [OPTIONS]
5846 : *
5847 : *****************************************************************************/
5848 :
5849 : CreateUserMappingStmt: CREATE USER MAPPING FOR auth_ident SERVER name create_generic_options
5850 : {
5851 246 : CreateUserMappingStmt *n = makeNode(CreateUserMappingStmt);
5852 :
5853 246 : n->user = $5;
5854 246 : n->servername = $7;
5855 246 : n->options = $8;
5856 246 : n->if_not_exists = false;
5857 246 : $$ = (Node *) n;
5858 : }
5859 : | CREATE USER MAPPING IF_P NOT EXISTS FOR auth_ident SERVER name create_generic_options
5860 : {
5861 6 : CreateUserMappingStmt *n = makeNode(CreateUserMappingStmt);
5862 :
5863 6 : n->user = $8;
5864 6 : n->servername = $10;
5865 6 : n->options = $11;
5866 6 : n->if_not_exists = true;
5867 6 : $$ = (Node *) n;
5868 : }
5869 : ;
5870 :
5871 : /* User mapping authorization identifier */
5872 450 : auth_ident: RoleSpec { $$ = $1; }
5873 46 : | USER { $$ = makeRoleSpec(ROLESPEC_CURRENT_USER, @1); }
5874 : ;
5875 :
5876 : /*****************************************************************************
5877 : *
5878 : * QUERY :
5879 : * DROP USER MAPPING FOR auth_ident SERVER name
5880 : *
5881 : * XXX you'd think this should have a CASCADE/RESTRICT option, even if it's
5882 : * only pro forma; but the SQL standard doesn't show one.
5883 : ****************************************************************************/
5884 :
5885 : DropUserMappingStmt: DROP USER MAPPING FOR auth_ident SERVER name
5886 : {
5887 88 : DropUserMappingStmt *n = makeNode(DropUserMappingStmt);
5888 :
5889 88 : n->user = $5;
5890 88 : n->servername = $7;
5891 88 : n->missing_ok = false;
5892 88 : $$ = (Node *) n;
5893 : }
5894 : | DROP USER MAPPING IF_P EXISTS FOR auth_ident SERVER name
5895 : {
5896 38 : DropUserMappingStmt *n = makeNode(DropUserMappingStmt);
5897 :
5898 38 : n->user = $7;
5899 38 : n->servername = $9;
5900 38 : n->missing_ok = true;
5901 38 : $$ = (Node *) n;
5902 : }
5903 : ;
5904 :
5905 : /*****************************************************************************
5906 : *
5907 : * QUERY :
5908 : * ALTER USER MAPPING FOR auth_ident SERVER name OPTIONS
5909 : *
5910 : ****************************************************************************/
5911 :
5912 : AlterUserMappingStmt: ALTER USER MAPPING FOR auth_ident SERVER name alter_generic_options
5913 : {
5914 118 : AlterUserMappingStmt *n = makeNode(AlterUserMappingStmt);
5915 :
5916 118 : n->user = $5;
5917 118 : n->servername = $7;
5918 118 : n->options = $8;
5919 118 : $$ = (Node *) n;
5920 : }
5921 : ;
5922 :
5923 : /*****************************************************************************
5924 : *
5925 : * QUERIES:
5926 : * CREATE POLICY name ON table
5927 : * [AS { PERMISSIVE | RESTRICTIVE } ]
5928 : * [FOR { SELECT | INSERT | UPDATE | DELETE } ]
5929 : * [TO role, ...]
5930 : * [USING (qual)] [WITH CHECK (with check qual)]
5931 : * ALTER POLICY name ON table [TO role, ...]
5932 : * [USING (qual)] [WITH CHECK (with check qual)]
5933 : *
5934 : *****************************************************************************/
5935 :
5936 : CreatePolicyStmt:
5937 : CREATE POLICY name ON qualified_name RowSecurityDefaultPermissive
5938 : RowSecurityDefaultForCmd RowSecurityDefaultToRole
5939 : RowSecurityOptionalExpr RowSecurityOptionalWithCheck
5940 : {
5941 724 : CreatePolicyStmt *n = makeNode(CreatePolicyStmt);
5942 :
5943 724 : n->policy_name = $3;
5944 724 : n->table = $5;
5945 724 : n->permissive = $6;
5946 724 : n->cmd_name = $7;
5947 724 : n->roles = $8;
5948 724 : n->qual = $9;
5949 724 : n->with_check = $10;
5950 724 : $$ = (Node *) n;
5951 : }
5952 : ;
5953 :
5954 : AlterPolicyStmt:
5955 : ALTER POLICY name ON qualified_name RowSecurityOptionalToRole
5956 : RowSecurityOptionalExpr RowSecurityOptionalWithCheck
5957 : {
5958 84 : AlterPolicyStmt *n = makeNode(AlterPolicyStmt);
5959 :
5960 84 : n->policy_name = $3;
5961 84 : n->table = $5;
5962 84 : n->roles = $6;
5963 84 : n->qual = $7;
5964 84 : n->with_check = $8;
5965 84 : $$ = (Node *) n;
5966 : }
5967 : ;
5968 :
5969 : RowSecurityOptionalExpr:
5970 750 : USING '(' a_expr ')' { $$ = $3; }
5971 58 : | /* EMPTY */ { $$ = NULL; }
5972 : ;
5973 :
5974 : RowSecurityOptionalWithCheck:
5975 122 : WITH CHECK '(' a_expr ')' { $$ = $4; }
5976 686 : | /* EMPTY */ { $$ = NULL; }
5977 : ;
5978 :
5979 : RowSecurityDefaultToRole:
5980 130 : TO role_list { $$ = $2; }
5981 594 : | /* EMPTY */ { $$ = list_make1(makeRoleSpec(ROLESPEC_PUBLIC, -1)); }
5982 : ;
5983 :
5984 : RowSecurityOptionalToRole:
5985 12 : TO role_list { $$ = $2; }
5986 72 : | /* EMPTY */ { $$ = NULL; }
5987 : ;
5988 :
5989 : RowSecurityDefaultPermissive:
5990 : AS IDENT
5991 : {
5992 98 : if (strcmp($2, "permissive") == 0)
5993 24 : $$ = true;
5994 74 : else if (strcmp($2, "restrictive") == 0)
5995 68 : $$ = false;
5996 : else
5997 6 : ereport(ERROR,
5998 : (errcode(ERRCODE_SYNTAX_ERROR),
5999 : errmsg("unrecognized row security option \"%s\"", $2),
6000 : errhint("Only PERMISSIVE or RESTRICTIVE policies are supported currently."),
6001 : parser_errposition(@2)));
6002 :
6003 : }
6004 632 : | /* EMPTY */ { $$ = true; }
6005 : ;
6006 :
6007 : RowSecurityDefaultForCmd:
6008 320 : FOR row_security_cmd { $$ = $2; }
6009 404 : | /* EMPTY */ { $$ = "all"; }
6010 : ;
6011 :
6012 : row_security_cmd:
6013 44 : ALL { $$ = "all"; }
6014 112 : | SELECT { $$ = "select"; }
6015 44 : | INSERT { $$ = "insert"; }
6016 78 : | UPDATE { $$ = "update"; }
6017 42 : | DELETE_P { $$ = "delete"; }
6018 : ;
6019 :
6020 : /*****************************************************************************
6021 : *
6022 : * QUERY:
6023 : * CREATE ACCESS METHOD name HANDLER handler_name
6024 : *
6025 : *****************************************************************************/
6026 :
6027 : CreateAmStmt: CREATE ACCESS METHOD name TYPE_P am_type HANDLER handler_name
6028 : {
6029 62 : CreateAmStmt *n = makeNode(CreateAmStmt);
6030 :
6031 62 : n->amname = $4;
6032 62 : n->handler_name = $8;
6033 62 : n->amtype = $6;
6034 62 : $$ = (Node *) n;
6035 : }
6036 : ;
6037 :
6038 : am_type:
6039 34 : INDEX { $$ = AMTYPE_INDEX; }
6040 28 : | TABLE { $$ = AMTYPE_TABLE; }
6041 : ;
6042 :
6043 : /*****************************************************************************
6044 : *
6045 : * QUERIES :
6046 : * CREATE TRIGGER ...
6047 : *
6048 : *****************************************************************************/
6049 :
6050 : CreateTrigStmt:
6051 : CREATE opt_or_replace TRIGGER name TriggerActionTime TriggerEvents ON
6052 : qualified_name TriggerReferencing TriggerForSpec TriggerWhen
6053 : EXECUTE FUNCTION_or_PROCEDURE func_name '(' TriggerFuncArgs ')'
6054 : {
6055 3144 : CreateTrigStmt *n = makeNode(CreateTrigStmt);
6056 :
6057 3144 : n->replace = $2;
6058 3144 : n->isconstraint = false;
6059 3144 : n->trigname = $4;
6060 3144 : n->relation = $8;
6061 3144 : n->funcname = $14;
6062 3144 : n->args = $16;
6063 3144 : n->row = $10;
6064 3144 : n->timing = $5;
6065 3144 : n->events = intVal(linitial($6));
6066 3144 : n->columns = (List *) lsecond($6);
6067 3144 : n->whenClause = $11;
6068 3144 : n->transitionRels = $9;
6069 3144 : n->deferrable = false;
6070 3144 : n->initdeferred = false;
6071 3144 : n->constrrel = NULL;
6072 3144 : $$ = (Node *) n;
6073 : }
6074 : | CREATE opt_or_replace CONSTRAINT TRIGGER name AFTER TriggerEvents ON
6075 : qualified_name OptConstrFromTable ConstraintAttributeSpec
6076 : FOR EACH ROW TriggerWhen
6077 : EXECUTE FUNCTION_or_PROCEDURE func_name '(' TriggerFuncArgs ')'
6078 : {
6079 80 : CreateTrigStmt *n = makeNode(CreateTrigStmt);
6080 : bool dummy;
6081 :
6082 80 : if (($11 & CAS_NOT_VALID) != 0)
6083 6 : ereport(ERROR,
6084 : errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
6085 : errmsg("constraint triggers cannot be marked %s",
6086 : "NOT VALID"),
6087 : parser_errposition(@11));
6088 74 : if (($11 & CAS_NO_INHERIT) != 0)
6089 6 : ereport(ERROR,
6090 : errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
6091 : errmsg("constraint triggers cannot be marked %s",
6092 : "NO INHERIT"),
6093 : parser_errposition(@11));
6094 68 : if (($11 & CAS_NOT_ENFORCED) != 0)
6095 6 : ereport(ERROR,
6096 : errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
6097 : errmsg("constraint triggers cannot be marked %s",
6098 : "NOT ENFORCED"),
6099 : parser_errposition(@11));
6100 :
6101 62 : n->replace = $2;
6102 62 : if (n->replace) /* not supported, see CreateTrigger */
6103 0 : ereport(ERROR,
6104 : (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
6105 : errmsg("CREATE OR REPLACE CONSTRAINT TRIGGER is not supported"),
6106 : parser_errposition(@1)));
6107 62 : n->isconstraint = true;
6108 62 : n->trigname = $5;
6109 62 : n->relation = $9;
6110 62 : n->funcname = $18;
6111 62 : n->args = $20;
6112 62 : n->row = true;
6113 62 : n->timing = TRIGGER_TYPE_AFTER;
6114 62 : n->events = intVal(linitial($7));
6115 62 : n->columns = (List *) lsecond($7);
6116 62 : n->whenClause = $15;
6117 62 : n->transitionRels = NIL;
6118 62 : processCASbits($11, @11, "TRIGGER",
6119 : &n->deferrable, &n->initdeferred, &dummy,
6120 : NULL, NULL, yyscanner);
6121 62 : n->constrrel = $10;
6122 62 : $$ = (Node *) n;
6123 : }
6124 : ;
6125 :
6126 : TriggerActionTime:
6127 1412 : BEFORE { $$ = TRIGGER_TYPE_BEFORE; }
6128 1600 : | AFTER { $$ = TRIGGER_TYPE_AFTER; }
6129 144 : | INSTEAD OF { $$ = TRIGGER_TYPE_INSTEAD; }
6130 : ;
6131 :
6132 : TriggerEvents:
6133 : TriggerOneEvent
6134 3236 : { $$ = $1; }
6135 : | TriggerEvents OR TriggerOneEvent
6136 : {
6137 1132 : int events1 = intVal(linitial($1));
6138 1132 : int events2 = intVal(linitial($3));
6139 1132 : List *columns1 = (List *) lsecond($1);
6140 1132 : List *columns2 = (List *) lsecond($3);
6141 :
6142 1132 : if (events1 & events2)
6143 6 : parser_yyerror("duplicate trigger events specified");
6144 : /*
6145 : * concat'ing the columns lists loses information about
6146 : * which columns went with which event, but so long as
6147 : * only UPDATE carries columns and we disallow multiple
6148 : * UPDATE items, it doesn't matter. Command execution
6149 : * should just ignore the columns for non-UPDATE events.
6150 : */
6151 1126 : $$ = list_make2(makeInteger(events1 | events2),
6152 : list_concat(columns1, columns2));
6153 : }
6154 : ;
6155 :
6156 : TriggerOneEvent:
6157 : INSERT
6158 1650 : { $$ = list_make2(makeInteger(TRIGGER_TYPE_INSERT), NIL); }
6159 : | DELETE_P
6160 874 : { $$ = list_make2(makeInteger(TRIGGER_TYPE_DELETE), NIL); }
6161 : | UPDATE
6162 1706 : { $$ = list_make2(makeInteger(TRIGGER_TYPE_UPDATE), NIL); }
6163 : | UPDATE OF columnList
6164 100 : { $$ = list_make2(makeInteger(TRIGGER_TYPE_UPDATE), $3); }
6165 : | TRUNCATE
6166 38 : { $$ = list_make2(makeInteger(TRIGGER_TYPE_TRUNCATE), NIL); }
6167 : ;
6168 :
6169 : TriggerReferencing:
6170 464 : REFERENCING TriggerTransitions { $$ = $2; }
6171 2680 : | /*EMPTY*/ { $$ = NIL; }
6172 : ;
6173 :
6174 : TriggerTransitions:
6175 464 : TriggerTransition { $$ = list_make1($1); }
6176 142 : | TriggerTransitions TriggerTransition { $$ = lappend($1, $2); }
6177 : ;
6178 :
6179 : TriggerTransition:
6180 : TransitionOldOrNew TransitionRowOrTable opt_as TransitionRelName
6181 : {
6182 606 : TriggerTransition *n = makeNode(TriggerTransition);
6183 :
6184 606 : n->name = $4;
6185 606 : n->isNew = $1;
6186 606 : n->isTable = $2;
6187 606 : $$ = (Node *) n;
6188 : }
6189 : ;
6190 :
6191 : TransitionOldOrNew:
6192 330 : NEW { $$ = true; }
6193 276 : | OLD { $$ = false; }
6194 : ;
6195 :
6196 : TransitionRowOrTable:
6197 606 : TABLE { $$ = true; }
6198 : /*
6199 : * According to the standard, lack of a keyword here implies ROW.
6200 : * Support for that would require prohibiting ROW entirely here,
6201 : * reserving the keyword ROW, and/or requiring AS (instead of
6202 : * allowing it to be optional, as the standard specifies) as the
6203 : * next token. Requiring ROW seems cleanest and easiest to
6204 : * explain.
6205 : */
6206 0 : | ROW { $$ = false; }
6207 : ;
6208 :
6209 : TransitionRelName:
6210 606 : ColId { $$ = $1; }
6211 : ;
6212 :
6213 : TriggerForSpec:
6214 : FOR TriggerForOptEach TriggerForType
6215 : {
6216 2916 : $$ = $3;
6217 : }
6218 : | /* EMPTY */
6219 : {
6220 : /*
6221 : * If ROW/STATEMENT not specified, default to
6222 : * STATEMENT, per SQL
6223 : */
6224 228 : $$ = false;
6225 : }
6226 : ;
6227 :
6228 : TriggerForOptEach:
6229 : EACH
6230 : | /*EMPTY*/
6231 : ;
6232 :
6233 : TriggerForType:
6234 2096 : ROW { $$ = true; }
6235 820 : | STATEMENT { $$ = false; }
6236 : ;
6237 :
6238 : TriggerWhen:
6239 190 : WHEN '(' a_expr ')' { $$ = $3; }
6240 3034 : | /*EMPTY*/ { $$ = NULL; }
6241 : ;
6242 :
6243 : FUNCTION_or_PROCEDURE:
6244 : FUNCTION
6245 : | PROCEDURE
6246 : ;
6247 :
6248 : TriggerFuncArgs:
6249 546 : TriggerFuncArg { $$ = list_make1($1); }
6250 162 : | TriggerFuncArgs ',' TriggerFuncArg { $$ = lappend($1, $3); }
6251 2678 : | /*EMPTY*/ { $$ = NIL; }
6252 : ;
6253 :
6254 : TriggerFuncArg:
6255 : Iconst
6256 : {
6257 94 : $$ = (Node *) makeString(psprintf("%d", $1));
6258 : }
6259 0 : | FCONST { $$ = (Node *) makeString($1); }
6260 592 : | Sconst { $$ = (Node *) makeString($1); }
6261 22 : | ColLabel { $$ = (Node *) makeString($1); }
6262 : ;
6263 :
6264 : OptConstrFromTable:
6265 12 : FROM qualified_name { $$ = $2; }
6266 68 : | /*EMPTY*/ { $$ = NULL; }
6267 : ;
6268 :
6269 : ConstraintAttributeSpec:
6270 : /*EMPTY*/
6271 17822 : { $$ = 0; }
6272 : | ConstraintAttributeSpec ConstraintAttributeElem
6273 : {
6274 : /*
6275 : * We must complain about conflicting options.
6276 : * We could, but choose not to, complain about redundant
6277 : * options (ie, where $2's bit is already set in $1).
6278 : */
6279 1676 : int newspec = $1 | $2;
6280 :
6281 : /* special message for this case */
6282 1676 : if ((newspec & (CAS_NOT_DEFERRABLE | CAS_INITIALLY_DEFERRED)) == (CAS_NOT_DEFERRABLE | CAS_INITIALLY_DEFERRED))
6283 6 : ereport(ERROR,
6284 : (errcode(ERRCODE_SYNTAX_ERROR),
6285 : errmsg("constraint declared INITIALLY DEFERRED must be DEFERRABLE"),
6286 : parser_errposition(@2)));
6287 : /* generic message for other conflicts */
6288 1670 : if ((newspec & (CAS_NOT_DEFERRABLE | CAS_DEFERRABLE)) == (CAS_NOT_DEFERRABLE | CAS_DEFERRABLE) ||
6289 1670 : (newspec & (CAS_INITIALLY_IMMEDIATE | CAS_INITIALLY_DEFERRED)) == (CAS_INITIALLY_IMMEDIATE | CAS_INITIALLY_DEFERRED) ||
6290 1670 : (newspec & (CAS_NOT_ENFORCED | CAS_ENFORCED)) == (CAS_NOT_ENFORCED | CAS_ENFORCED))
6291 6 : ereport(ERROR,
6292 : (errcode(ERRCODE_SYNTAX_ERROR),
6293 : errmsg("conflicting constraint properties"),
6294 : parser_errposition(@2)));
6295 1664 : $$ = newspec;
6296 : }
6297 : ;
6298 :
6299 : ConstraintAttributeElem:
6300 42 : NOT DEFERRABLE { $$ = CAS_NOT_DEFERRABLE; }
6301 200 : | DEFERRABLE { $$ = CAS_DEFERRABLE; }
6302 30 : | INITIALLY IMMEDIATE { $$ = CAS_INITIALLY_IMMEDIATE; }
6303 152 : | INITIALLY DEFERRED { $$ = CAS_INITIALLY_DEFERRED; }
6304 726 : | NOT VALID { $$ = CAS_NOT_VALID; }
6305 250 : | NO INHERIT { $$ = CAS_NO_INHERIT; }
6306 168 : | NOT ENFORCED { $$ = CAS_NOT_ENFORCED; }
6307 108 : | ENFORCED { $$ = CAS_ENFORCED; }
6308 : ;
6309 :
6310 :
6311 : /*****************************************************************************
6312 : *
6313 : * QUERIES :
6314 : * CREATE EVENT TRIGGER ...
6315 : * ALTER EVENT TRIGGER ...
6316 : *
6317 : *****************************************************************************/
6318 :
6319 : CreateEventTrigStmt:
6320 : CREATE EVENT TRIGGER name ON ColLabel
6321 : EXECUTE FUNCTION_or_PROCEDURE func_name '(' ')'
6322 : {
6323 98 : CreateEventTrigStmt *n = makeNode(CreateEventTrigStmt);
6324 :
6325 98 : n->trigname = $4;
6326 98 : n->eventname = $6;
6327 98 : n->whenclause = NULL;
6328 98 : n->funcname = $9;
6329 98 : $$ = (Node *) n;
6330 : }
6331 : | CREATE EVENT TRIGGER name ON ColLabel
6332 : WHEN event_trigger_when_list
6333 : EXECUTE FUNCTION_or_PROCEDURE func_name '(' ')'
6334 : {
6335 98 : CreateEventTrigStmt *n = makeNode(CreateEventTrigStmt);
6336 :
6337 98 : n->trigname = $4;
6338 98 : n->eventname = $6;
6339 98 : n->whenclause = $8;
6340 98 : n->funcname = $11;
6341 98 : $$ = (Node *) n;
6342 : }
6343 : ;
6344 :
6345 : event_trigger_when_list:
6346 : event_trigger_when_item
6347 98 : { $$ = list_make1($1); }
6348 : | event_trigger_when_list AND event_trigger_when_item
6349 6 : { $$ = lappend($1, $3); }
6350 : ;
6351 :
6352 : event_trigger_when_item:
6353 : ColId IN_P '(' event_trigger_value_list ')'
6354 104 : { $$ = makeDefElem($1, (Node *) $4, @1); }
6355 : ;
6356 :
6357 : event_trigger_value_list:
6358 : SCONST
6359 104 : { $$ = list_make1(makeString($1)); }
6360 : | event_trigger_value_list ',' SCONST
6361 66 : { $$ = lappend($1, makeString($3)); }
6362 : ;
6363 :
6364 : AlterEventTrigStmt:
6365 : ALTER EVENT TRIGGER name enable_trigger
6366 : {
6367 48 : AlterEventTrigStmt *n = makeNode(AlterEventTrigStmt);
6368 :
6369 48 : n->trigname = $4;
6370 48 : n->tgenabled = $5;
6371 48 : $$ = (Node *) n;
6372 : }
6373 : ;
6374 :
6375 : enable_trigger:
6376 6 : ENABLE_P { $$ = TRIGGER_FIRES_ON_ORIGIN; }
6377 6 : | ENABLE_P REPLICA { $$ = TRIGGER_FIRES_ON_REPLICA; }
6378 16 : | ENABLE_P ALWAYS { $$ = TRIGGER_FIRES_ALWAYS; }
6379 20 : | DISABLE_P { $$ = TRIGGER_DISABLED; }
6380 : ;
6381 :
6382 : /*****************************************************************************
6383 : *
6384 : * QUERY :
6385 : * CREATE ASSERTION ...
6386 : *
6387 : *****************************************************************************/
6388 :
6389 : CreateAssertionStmt:
6390 : CREATE ASSERTION any_name CHECK '(' a_expr ')' ConstraintAttributeSpec
6391 : {
6392 0 : ereport(ERROR,
6393 : (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
6394 : errmsg("CREATE ASSERTION is not yet implemented"),
6395 : parser_errposition(@1)));
6396 :
6397 : $$ = NULL;
6398 : }
6399 : ;
6400 :
6401 :
6402 : /*****************************************************************************
6403 : *
6404 : * QUERY :
6405 : * define (aggregate,operator,type)
6406 : *
6407 : *****************************************************************************/
6408 :
6409 : DefineStmt:
6410 : CREATE opt_or_replace AGGREGATE func_name aggr_args definition
6411 : {
6412 544 : DefineStmt *n = makeNode(DefineStmt);
6413 :
6414 544 : n->kind = OBJECT_AGGREGATE;
6415 544 : n->oldstyle = false;
6416 544 : n->replace = $2;
6417 544 : n->defnames = $4;
6418 544 : n->args = $5;
6419 544 : n->definition = $6;
6420 544 : $$ = (Node *) n;
6421 : }
6422 : | CREATE opt_or_replace AGGREGATE func_name old_aggr_definition
6423 : {
6424 : /* old-style (pre-8.2) syntax for CREATE AGGREGATE */
6425 362 : DefineStmt *n = makeNode(DefineStmt);
6426 :
6427 362 : n->kind = OBJECT_AGGREGATE;
6428 362 : n->oldstyle = true;
6429 362 : n->replace = $2;
6430 362 : n->defnames = $4;
6431 362 : n->args = NIL;
6432 362 : n->definition = $5;
6433 362 : $$ = (Node *) n;
6434 : }
6435 : | CREATE OPERATOR any_operator definition
6436 : {
6437 1642 : DefineStmt *n = makeNode(DefineStmt);
6438 :
6439 1642 : n->kind = OBJECT_OPERATOR;
6440 1642 : n->oldstyle = false;
6441 1642 : n->defnames = $3;
6442 1642 : n->args = NIL;
6443 1642 : n->definition = $4;
6444 1642 : $$ = (Node *) n;
6445 : }
6446 : | CREATE TYPE_P any_name definition
6447 : {
6448 240 : DefineStmt *n = makeNode(DefineStmt);
6449 :
6450 240 : n->kind = OBJECT_TYPE;
6451 240 : n->oldstyle = false;
6452 240 : n->defnames = $3;
6453 240 : n->args = NIL;
6454 240 : n->definition = $4;
6455 240 : $$ = (Node *) n;
6456 : }
6457 : | CREATE TYPE_P any_name
6458 : {
6459 : /* Shell type (identified by lack of definition) */
6460 156 : DefineStmt *n = makeNode(DefineStmt);
6461 :
6462 156 : n->kind = OBJECT_TYPE;
6463 156 : n->oldstyle = false;
6464 156 : n->defnames = $3;
6465 156 : n->args = NIL;
6466 156 : n->definition = NIL;
6467 156 : $$ = (Node *) n;
6468 : }
6469 : | CREATE TYPE_P any_name AS '(' OptTableFuncElementList ')'
6470 : {
6471 4502 : CompositeTypeStmt *n = makeNode(CompositeTypeStmt);
6472 :
6473 : /* can't use qualified_name, sigh */
6474 4502 : n->typevar = makeRangeVarFromAnyName($3, @3, yyscanner);
6475 4502 : n->coldeflist = $6;
6476 4502 : $$ = (Node *) n;
6477 : }
6478 : | CREATE TYPE_P any_name AS ENUM_P '(' opt_enum_val_list ')'
6479 : {
6480 202 : CreateEnumStmt *n = makeNode(CreateEnumStmt);
6481 :
6482 202 : n->typeName = $3;
6483 202 : n->vals = $7;
6484 202 : $$ = (Node *) n;
6485 : }
6486 : | CREATE TYPE_P any_name AS RANGE definition
6487 : {
6488 184 : CreateRangeStmt *n = makeNode(CreateRangeStmt);
6489 :
6490 184 : n->typeName = $3;
6491 184 : n->params = $6;
6492 184 : $$ = (Node *) n;
6493 : }
6494 : | CREATE TEXT_P SEARCH PARSER any_name definition
6495 : {
6496 40 : DefineStmt *n = makeNode(DefineStmt);
6497 :
6498 40 : n->kind = OBJECT_TSPARSER;
6499 40 : n->args = NIL;
6500 40 : n->defnames = $5;
6501 40 : n->definition = $6;
6502 40 : $$ = (Node *) n;
6503 : }
6504 : | CREATE TEXT_P SEARCH DICTIONARY any_name definition
6505 : {
6506 2930 : DefineStmt *n = makeNode(DefineStmt);
6507 :
6508 2930 : n->kind = OBJECT_TSDICTIONARY;
6509 2930 : n->args = NIL;
6510 2930 : n->defnames = $5;
6511 2930 : n->definition = $6;
6512 2930 : $$ = (Node *) n;
6513 : }
6514 : | CREATE TEXT_P SEARCH TEMPLATE any_name definition
6515 : {
6516 140 : DefineStmt *n = makeNode(DefineStmt);
6517 :
6518 140 : n->kind = OBJECT_TSTEMPLATE;
6519 140 : n->args = NIL;
6520 140 : n->defnames = $5;
6521 140 : n->definition = $6;
6522 140 : $$ = (Node *) n;
6523 : }
6524 : | CREATE TEXT_P SEARCH CONFIGURATION any_name definition
6525 : {
6526 2872 : DefineStmt *n = makeNode(DefineStmt);
6527 :
6528 2872 : n->kind = OBJECT_TSCONFIGURATION;
6529 2872 : n->args = NIL;
6530 2872 : n->defnames = $5;
6531 2872 : n->definition = $6;
6532 2872 : $$ = (Node *) n;
6533 : }
6534 : | CREATE COLLATION any_name definition
6535 : {
6536 292 : DefineStmt *n = makeNode(DefineStmt);
6537 :
6538 292 : n->kind = OBJECT_COLLATION;
6539 292 : n->args = NIL;
6540 292 : n->defnames = $3;
6541 292 : n->definition = $4;
6542 292 : $$ = (Node *) n;
6543 : }
6544 : | CREATE COLLATION IF_P NOT EXISTS any_name definition
6545 : {
6546 18 : DefineStmt *n = makeNode(DefineStmt);
6547 :
6548 18 : n->kind = OBJECT_COLLATION;
6549 18 : n->args = NIL;
6550 18 : n->defnames = $6;
6551 18 : n->definition = $7;
6552 18 : n->if_not_exists = true;
6553 18 : $$ = (Node *) n;
6554 : }
6555 : | CREATE COLLATION any_name FROM any_name
6556 : {
6557 54 : DefineStmt *n = makeNode(DefineStmt);
6558 :
6559 54 : n->kind = OBJECT_COLLATION;
6560 54 : n->args = NIL;
6561 54 : n->defnames = $3;
6562 54 : n->definition = list_make1(makeDefElem("from", (Node *) $5, @5));
6563 54 : $$ = (Node *) n;
6564 : }
6565 : | CREATE COLLATION IF_P NOT EXISTS any_name FROM any_name
6566 : {
6567 0 : DefineStmt *n = makeNode(DefineStmt);
6568 :
6569 0 : n->kind = OBJECT_COLLATION;
6570 0 : n->args = NIL;
6571 0 : n->defnames = $6;
6572 0 : n->definition = list_make1(makeDefElem("from", (Node *) $8, @8));
6573 0 : n->if_not_exists = true;
6574 0 : $$ = (Node *) n;
6575 : }
6576 : ;
6577 :
6578 9922 : definition: '(' def_list ')' { $$ = $2; }
6579 : ;
6580 :
6581 9922 : def_list: def_elem { $$ = list_make1($1); }
6582 14802 : | def_list ',' def_elem { $$ = lappend($1, $3); }
6583 : ;
6584 :
6585 : def_elem: ColLabel '=' def_arg
6586 : {
6587 24386 : $$ = makeDefElem($1, (Node *) $3, @1);
6588 : }
6589 : | ColLabel
6590 : {
6591 338 : $$ = makeDefElem($1, NULL, @1);
6592 : }
6593 : ;
6594 :
6595 : /* Note: any simple identifier will be returned as a type name! */
6596 19726 : def_arg: func_type { $$ = (Node *) $1; }
6597 4110 : | reserved_keyword { $$ = (Node *) makeString(pstrdup($1)); }
6598 1176 : | qual_all_Op { $$ = (Node *) $1; }
6599 1318 : | NumericOnly { $$ = (Node *) $1; }
6600 1892 : | Sconst { $$ = (Node *) makeString($1); }
6601 176 : | NONE { $$ = (Node *) makeString(pstrdup($1)); }
6602 : ;
6603 :
6604 362 : old_aggr_definition: '(' old_aggr_list ')' { $$ = $2; }
6605 : ;
6606 :
6607 362 : old_aggr_list: old_aggr_elem { $$ = list_make1($1); }
6608 1292 : | old_aggr_list ',' old_aggr_elem { $$ = lappend($1, $3); }
6609 : ;
6610 :
6611 : /*
6612 : * Must use IDENT here to avoid reduce/reduce conflicts; fortunately none of
6613 : * the item names needed in old aggregate definitions are likely to become
6614 : * SQL keywords.
6615 : */
6616 : old_aggr_elem: IDENT '=' def_arg
6617 : {
6618 1654 : $$ = makeDefElem($1, (Node *) $3, @1);
6619 : }
6620 : ;
6621 :
6622 : opt_enum_val_list:
6623 194 : enum_val_list { $$ = $1; }
6624 8 : | /*EMPTY*/ { $$ = NIL; }
6625 : ;
6626 :
6627 : enum_val_list: Sconst
6628 194 : { $$ = list_make1(makeString($1)); }
6629 : | enum_val_list ',' Sconst
6630 10408 : { $$ = lappend($1, makeString($3)); }
6631 : ;
6632 :
6633 : /*****************************************************************************
6634 : *
6635 : * ALTER TYPE enumtype ADD ...
6636 : *
6637 : *****************************************************************************/
6638 :
6639 : AlterEnumStmt:
6640 : ALTER TYPE_P any_name ADD_P VALUE_P opt_if_not_exists Sconst
6641 : {
6642 154 : AlterEnumStmt *n = makeNode(AlterEnumStmt);
6643 :
6644 154 : n->typeName = $3;
6645 154 : n->oldVal = NULL;
6646 154 : n->newVal = $7;
6647 154 : n->newValNeighbor = NULL;
6648 154 : n->newValIsAfter = true;
6649 154 : n->skipIfNewValExists = $6;
6650 154 : $$ = (Node *) n;
6651 : }
6652 : | ALTER TYPE_P any_name ADD_P VALUE_P opt_if_not_exists Sconst BEFORE Sconst
6653 : {
6654 196 : AlterEnumStmt *n = makeNode(AlterEnumStmt);
6655 :
6656 196 : n->typeName = $3;
6657 196 : n->oldVal = NULL;
6658 196 : n->newVal = $7;
6659 196 : n->newValNeighbor = $9;
6660 196 : n->newValIsAfter = false;
6661 196 : n->skipIfNewValExists = $6;
6662 196 : $$ = (Node *) n;
6663 : }
6664 : | ALTER TYPE_P any_name ADD_P VALUE_P opt_if_not_exists Sconst AFTER Sconst
6665 : {
6666 22 : AlterEnumStmt *n = makeNode(AlterEnumStmt);
6667 :
6668 22 : n->typeName = $3;
6669 22 : n->oldVal = NULL;
6670 22 : n->newVal = $7;
6671 22 : n->newValNeighbor = $9;
6672 22 : n->newValIsAfter = true;
6673 22 : n->skipIfNewValExists = $6;
6674 22 : $$ = (Node *) n;
6675 : }
6676 : | ALTER TYPE_P any_name RENAME VALUE_P Sconst TO Sconst
6677 : {
6678 24 : AlterEnumStmt *n = makeNode(AlterEnumStmt);
6679 :
6680 24 : n->typeName = $3;
6681 24 : n->oldVal = $6;
6682 24 : n->newVal = $8;
6683 24 : n->newValNeighbor = NULL;
6684 24 : n->newValIsAfter = false;
6685 24 : n->skipIfNewValExists = false;
6686 24 : $$ = (Node *) n;
6687 : }
6688 : | ALTER TYPE_P any_name DROP VALUE_P Sconst
6689 : {
6690 : /*
6691 : * The following problems must be solved before this can be
6692 : * implemented:
6693 : *
6694 : * - There must be no instance of the target value in
6695 : * any table.
6696 : *
6697 : * - The value must not appear in any catalog metadata,
6698 : * such as stored view expressions or column defaults.
6699 : *
6700 : * - The value must not appear in any non-leaf page of a
6701 : * btree (and similar issues with other index types).
6702 : * This is problematic because a value could persist
6703 : * there long after it's gone from user-visible data.
6704 : *
6705 : * - Concurrent sessions must not be able to insert the
6706 : * value while the preceding conditions are being checked.
6707 : *
6708 : * - Possibly more...
6709 : */
6710 0 : ereport(ERROR,
6711 : (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
6712 : errmsg("dropping an enum value is not implemented"),
6713 : parser_errposition(@4)));
6714 : }
6715 : ;
6716 :
6717 12 : opt_if_not_exists: IF_P NOT EXISTS { $$ = true; }
6718 360 : | /* EMPTY */ { $$ = false; }
6719 : ;
6720 :
6721 :
6722 : /*****************************************************************************
6723 : *
6724 : * QUERIES :
6725 : * CREATE OPERATOR CLASS ...
6726 : * CREATE OPERATOR FAMILY ...
6727 : * ALTER OPERATOR FAMILY ...
6728 : * DROP OPERATOR CLASS ...
6729 : * DROP OPERATOR FAMILY ...
6730 : *
6731 : *****************************************************************************/
6732 :
6733 : CreateOpClassStmt:
6734 : CREATE OPERATOR CLASS any_name opt_default FOR TYPE_P Typename
6735 : USING name opt_opfamily AS opclass_item_list
6736 : {
6737 550 : CreateOpClassStmt *n = makeNode(CreateOpClassStmt);
6738 :
6739 550 : n->opclassname = $4;
6740 550 : n->isDefault = $5;
6741 550 : n->datatype = $8;
6742 550 : n->amname = $10;
6743 550 : n->opfamilyname = $11;
6744 550 : n->items = $13;
6745 550 : $$ = (Node *) n;
6746 : }
6747 : ;
6748 :
6749 : opclass_item_list:
6750 1406 : opclass_item { $$ = list_make1($1); }
6751 5388 : | opclass_item_list ',' opclass_item { $$ = lappend($1, $3); }
6752 : ;
6753 :
6754 : opclass_item:
6755 : OPERATOR Iconst any_operator opclass_purpose
6756 : {
6757 1866 : CreateOpClassItem *n = makeNode(CreateOpClassItem);
6758 1866 : ObjectWithArgs *owa = makeNode(ObjectWithArgs);
6759 :
6760 1866 : owa->objname = $3;
6761 1866 : owa->objargs = NIL;
6762 1866 : n->itemtype = OPCLASS_ITEM_OPERATOR;
6763 1866 : n->name = owa;
6764 1866 : n->number = $2;
6765 1866 : n->order_family = $4;
6766 1866 : $$ = (Node *) n;
6767 : }
6768 : | OPERATOR Iconst operator_with_argtypes opclass_purpose
6769 : {
6770 1570 : CreateOpClassItem *n = makeNode(CreateOpClassItem);
6771 :
6772 1570 : n->itemtype = OPCLASS_ITEM_OPERATOR;
6773 1570 : n->name = $3;
6774 1570 : n->number = $2;
6775 1570 : n->order_family = $4;
6776 1570 : $$ = (Node *) n;
6777 : }
6778 : | FUNCTION Iconst function_with_argtypes
6779 : {
6780 2408 : CreateOpClassItem *n = makeNode(CreateOpClassItem);
6781 :
6782 2408 : n->itemtype = OPCLASS_ITEM_FUNCTION;
6783 2408 : n->name = $3;
6784 2408 : n->number = $2;
6785 2408 : $$ = (Node *) n;
6786 : }
6787 : | FUNCTION Iconst '(' type_list ')' function_with_argtypes
6788 : {
6789 590 : CreateOpClassItem *n = makeNode(CreateOpClassItem);
6790 :
6791 590 : n->itemtype = OPCLASS_ITEM_FUNCTION;
6792 590 : n->name = $6;
6793 590 : n->number = $2;
6794 590 : n->class_args = $4;
6795 590 : $$ = (Node *) n;
6796 : }
6797 : | STORAGE Typename
6798 : {
6799 360 : CreateOpClassItem *n = makeNode(CreateOpClassItem);
6800 :
6801 360 : n->itemtype = OPCLASS_ITEM_STORAGETYPE;
6802 360 : n->storedtype = $2;
6803 360 : $$ = (Node *) n;
6804 : }
6805 : ;
6806 :
6807 452 : opt_default: DEFAULT { $$ = true; }
6808 162 : | /*EMPTY*/ { $$ = false; }
6809 : ;
6810 :
6811 44 : opt_opfamily: FAMILY any_name { $$ = $2; }
6812 506 : | /*EMPTY*/ { $$ = NIL; }
6813 : ;
6814 :
6815 0 : opclass_purpose: FOR SEARCH { $$ = NIL; }
6816 120 : | FOR ORDER BY any_name { $$ = $4; }
6817 3316 : | /*EMPTY*/ { $$ = NIL; }
6818 : ;
6819 :
6820 :
6821 : CreateOpFamilyStmt:
6822 : CREATE OPERATOR FAMILY any_name USING name
6823 : {
6824 148 : CreateOpFamilyStmt *n = makeNode(CreateOpFamilyStmt);
6825 :
6826 148 : n->opfamilyname = $4;
6827 148 : n->amname = $6;
6828 148 : $$ = (Node *) n;
6829 : }
6830 : ;
6831 :
6832 : AlterOpFamilyStmt:
6833 : ALTER OPERATOR FAMILY any_name USING name ADD_P opclass_item_list
6834 : {
6835 856 : AlterOpFamilyStmt *n = makeNode(AlterOpFamilyStmt);
6836 :
6837 856 : n->opfamilyname = $4;
6838 856 : n->amname = $6;
6839 856 : n->isDrop = false;
6840 856 : n->items = $8;
6841 856 : $$ = (Node *) n;
6842 : }
6843 : | ALTER OPERATOR FAMILY any_name USING name DROP opclass_drop_list
6844 : {
6845 64 : AlterOpFamilyStmt *n = makeNode(AlterOpFamilyStmt);
6846 :
6847 64 : n->opfamilyname = $4;
6848 64 : n->amname = $6;
6849 64 : n->isDrop = true;
6850 64 : n->items = $8;
6851 64 : $$ = (Node *) n;
6852 : }
6853 : ;
6854 :
6855 : opclass_drop_list:
6856 64 : opclass_drop { $$ = list_make1($1); }
6857 30 : | opclass_drop_list ',' opclass_drop { $$ = lappend($1, $3); }
6858 : ;
6859 :
6860 : opclass_drop:
6861 : OPERATOR Iconst '(' type_list ')'
6862 : {
6863 56 : CreateOpClassItem *n = makeNode(CreateOpClassItem);
6864 :
6865 56 : n->itemtype = OPCLASS_ITEM_OPERATOR;
6866 56 : n->number = $2;
6867 56 : n->class_args = $4;
6868 56 : $$ = (Node *) n;
6869 : }
6870 : | FUNCTION Iconst '(' type_list ')'
6871 : {
6872 38 : CreateOpClassItem *n = makeNode(CreateOpClassItem);
6873 :
6874 38 : n->itemtype = OPCLASS_ITEM_FUNCTION;
6875 38 : n->number = $2;
6876 38 : n->class_args = $4;
6877 38 : $$ = (Node *) n;
6878 : }
6879 : ;
6880 :
6881 :
6882 : DropOpClassStmt:
6883 : DROP OPERATOR CLASS any_name USING name opt_drop_behavior
6884 : {
6885 38 : DropStmt *n = makeNode(DropStmt);
6886 :
6887 38 : n->objects = list_make1(lcons(makeString($6), $4));
6888 38 : n->removeType = OBJECT_OPCLASS;
6889 38 : n->behavior = $7;
6890 38 : n->missing_ok = false;
6891 38 : n->concurrent = false;
6892 38 : $$ = (Node *) n;
6893 : }
6894 : | DROP OPERATOR CLASS IF_P EXISTS any_name USING name opt_drop_behavior
6895 : {
6896 18 : DropStmt *n = makeNode(DropStmt);
6897 :
6898 18 : n->objects = list_make1(lcons(makeString($8), $6));
6899 18 : n->removeType = OBJECT_OPCLASS;
6900 18 : n->behavior = $9;
6901 18 : n->missing_ok = true;
6902 18 : n->concurrent = false;
6903 18 : $$ = (Node *) n;
6904 : }
6905 : ;
6906 :
6907 : DropOpFamilyStmt:
6908 : DROP OPERATOR FAMILY any_name USING name opt_drop_behavior
6909 : {
6910 110 : DropStmt *n = makeNode(DropStmt);
6911 :
6912 110 : n->objects = list_make1(lcons(makeString($6), $4));
6913 110 : n->removeType = OBJECT_OPFAMILY;
6914 110 : n->behavior = $7;
6915 110 : n->missing_ok = false;
6916 110 : n->concurrent = false;
6917 110 : $$ = (Node *) n;
6918 : }
6919 : | DROP OPERATOR FAMILY IF_P EXISTS any_name USING name opt_drop_behavior
6920 : {
6921 18 : DropStmt *n = makeNode(DropStmt);
6922 :
6923 18 : n->objects = list_make1(lcons(makeString($8), $6));
6924 18 : n->removeType = OBJECT_OPFAMILY;
6925 18 : n->behavior = $9;
6926 18 : n->missing_ok = true;
6927 18 : n->concurrent = false;
6928 18 : $$ = (Node *) n;
6929 : }
6930 : ;
6931 :
6932 :
6933 : /*****************************************************************************
6934 : *
6935 : * QUERY:
6936 : *
6937 : * DROP OWNED BY username [, username ...] [ RESTRICT | CASCADE ]
6938 : * REASSIGN OWNED BY username [, username ...] TO username
6939 : *
6940 : *****************************************************************************/
6941 : DropOwnedStmt:
6942 : DROP OWNED BY role_list opt_drop_behavior
6943 : {
6944 152 : DropOwnedStmt *n = makeNode(DropOwnedStmt);
6945 :
6946 152 : n->roles = $4;
6947 152 : n->behavior = $5;
6948 152 : $$ = (Node *) n;
6949 : }
6950 : ;
6951 :
6952 : ReassignOwnedStmt:
6953 : REASSIGN OWNED BY role_list TO RoleSpec
6954 : {
6955 52 : ReassignOwnedStmt *n = makeNode(ReassignOwnedStmt);
6956 :
6957 52 : n->roles = $4;
6958 52 : n->newrole = $6;
6959 52 : $$ = (Node *) n;
6960 : }
6961 : ;
6962 :
6963 : /*****************************************************************************
6964 : *
6965 : * QUERY:
6966 : *
6967 : * DROP itemtype [ IF EXISTS ] itemname [, itemname ...]
6968 : * [ RESTRICT | CASCADE ]
6969 : *
6970 : *****************************************************************************/
6971 :
6972 : DropStmt: DROP object_type_any_name IF_P EXISTS any_name_list opt_drop_behavior
6973 : {
6974 1344 : DropStmt *n = makeNode(DropStmt);
6975 :
6976 1344 : n->removeType = $2;
6977 1344 : n->missing_ok = true;
6978 1344 : n->objects = $5;
6979 1344 : n->behavior = $6;
6980 1344 : n->concurrent = false;
6981 1344 : $$ = (Node *) n;
6982 : }
6983 : | DROP object_type_any_name any_name_list opt_drop_behavior
6984 : {
6985 16068 : DropStmt *n = makeNode(DropStmt);
6986 :
6987 16068 : n->removeType = $2;
6988 16068 : n->missing_ok = false;
6989 16068 : n->objects = $3;
6990 16068 : n->behavior = $4;
6991 16068 : n->concurrent = false;
6992 16068 : $$ = (Node *) n;
6993 : }
6994 : | DROP drop_type_name IF_P EXISTS name_list opt_drop_behavior
6995 : {
6996 78 : DropStmt *n = makeNode(DropStmt);
6997 :
6998 78 : n->removeType = $2;
6999 78 : n->missing_ok = true;
7000 78 : n->objects = $5;
7001 78 : n->behavior = $6;
7002 78 : n->concurrent = false;
7003 78 : $$ = (Node *) n;
7004 : }
7005 : | DROP drop_type_name name_list opt_drop_behavior
7006 : {
7007 1414 : DropStmt *n = makeNode(DropStmt);
7008 :
7009 1414 : n->removeType = $2;
7010 1414 : n->missing_ok = false;
7011 1414 : n->objects = $3;
7012 1414 : n->behavior = $4;
7013 1414 : n->concurrent = false;
7014 1414 : $$ = (Node *) n;
7015 : }
7016 : | DROP object_type_name_on_any_name name ON any_name opt_drop_behavior
7017 : {
7018 1130 : DropStmt *n = makeNode(DropStmt);
7019 :
7020 1130 : n->removeType = $2;
7021 1130 : n->objects = list_make1(lappend($5, makeString($3)));
7022 1130 : n->behavior = $6;
7023 1130 : n->missing_ok = false;
7024 1130 : n->concurrent = false;
7025 1130 : $$ = (Node *) n;
7026 : }
7027 : | DROP object_type_name_on_any_name IF_P EXISTS name ON any_name opt_drop_behavior
7028 : {
7029 48 : DropStmt *n = makeNode(DropStmt);
7030 :
7031 48 : n->removeType = $2;
7032 48 : n->objects = list_make1(lappend($7, makeString($5)));
7033 48 : n->behavior = $8;
7034 48 : n->missing_ok = true;
7035 48 : n->concurrent = false;
7036 48 : $$ = (Node *) n;
7037 : }
7038 : | DROP TYPE_P type_name_list opt_drop_behavior
7039 : {
7040 560 : DropStmt *n = makeNode(DropStmt);
7041 :
7042 560 : n->removeType = OBJECT_TYPE;
7043 560 : n->missing_ok = false;
7044 560 : n->objects = $3;
7045 560 : n->behavior = $4;
7046 560 : n->concurrent = false;
7047 560 : $$ = (Node *) n;
7048 : }
7049 : | DROP TYPE_P IF_P EXISTS type_name_list opt_drop_behavior
7050 : {
7051 26 : DropStmt *n = makeNode(DropStmt);
7052 :
7053 26 : n->removeType = OBJECT_TYPE;
7054 26 : n->missing_ok = true;
7055 26 : n->objects = $5;
7056 26 : n->behavior = $6;
7057 26 : n->concurrent = false;
7058 26 : $$ = (Node *) n;
7059 : }
7060 : | DROP DOMAIN_P type_name_list opt_drop_behavior
7061 : {
7062 464 : DropStmt *n = makeNode(DropStmt);
7063 :
7064 464 : n->removeType = OBJECT_DOMAIN;
7065 464 : n->missing_ok = false;
7066 464 : n->objects = $3;
7067 464 : n->behavior = $4;
7068 464 : n->concurrent = false;
7069 464 : $$ = (Node *) n;
7070 : }
7071 : | DROP DOMAIN_P IF_P EXISTS type_name_list opt_drop_behavior
7072 : {
7073 18 : DropStmt *n = makeNode(DropStmt);
7074 :
7075 18 : n->removeType = OBJECT_DOMAIN;
7076 18 : n->missing_ok = true;
7077 18 : n->objects = $5;
7078 18 : n->behavior = $6;
7079 18 : n->concurrent = false;
7080 18 : $$ = (Node *) n;
7081 : }
7082 : | DROP INDEX CONCURRENTLY any_name_list opt_drop_behavior
7083 : {
7084 172 : DropStmt *n = makeNode(DropStmt);
7085 :
7086 172 : n->removeType = OBJECT_INDEX;
7087 172 : n->missing_ok = false;
7088 172 : n->objects = $4;
7089 172 : n->behavior = $5;
7090 172 : n->concurrent = true;
7091 172 : $$ = (Node *) n;
7092 : }
7093 : | DROP INDEX CONCURRENTLY IF_P EXISTS any_name_list opt_drop_behavior
7094 : {
7095 12 : DropStmt *n = makeNode(DropStmt);
7096 :
7097 12 : n->removeType = OBJECT_INDEX;
7098 12 : n->missing_ok = true;
7099 12 : n->objects = $6;
7100 12 : n->behavior = $7;
7101 12 : n->concurrent = true;
7102 12 : $$ = (Node *) n;
7103 : }
7104 : ;
7105 :
7106 : /* object types taking any_name/any_name_list */
7107 : object_type_any_name:
7108 15008 : TABLE { $$ = OBJECT_TABLE; }
7109 192 : | SEQUENCE { $$ = OBJECT_SEQUENCE; }
7110 1040 : | VIEW { $$ = OBJECT_VIEW; }
7111 130 : | MATERIALIZED VIEW { $$ = OBJECT_MATVIEW; }
7112 778 : | INDEX { $$ = OBJECT_INDEX; }
7113 186 : | FOREIGN TABLE { $$ = OBJECT_FOREIGN_TABLE; }
7114 96 : | COLLATION { $$ = OBJECT_COLLATION; }
7115 56 : | CONVERSION_P { $$ = OBJECT_CONVERSION; }
7116 210 : | STATISTICS { $$ = OBJECT_STATISTIC_EXT; }
7117 20 : | TEXT_P SEARCH PARSER { $$ = OBJECT_TSPARSER; }
7118 2814 : | TEXT_P SEARCH DICTIONARY { $$ = OBJECT_TSDICTIONARY; }
7119 116 : | TEXT_P SEARCH TEMPLATE { $$ = OBJECT_TSTEMPLATE; }
7120 2818 : | TEXT_P SEARCH CONFIGURATION { $$ = OBJECT_TSCONFIGURATION; }
7121 : ;
7122 :
7123 : /*
7124 : * object types taking name/name_list
7125 : *
7126 : * DROP handles some of them separately
7127 : */
7128 :
7129 : object_type_name:
7130 240 : drop_type_name { $$ = $1; }
7131 238 : | DATABASE { $$ = OBJECT_DATABASE; }
7132 52 : | ROLE { $$ = OBJECT_ROLE; }
7133 10 : | SUBSCRIPTION { $$ = OBJECT_SUBSCRIPTION; }
7134 0 : | TABLESPACE { $$ = OBJECT_TABLESPACE; }
7135 : ;
7136 :
7137 : drop_type_name:
7138 46 : ACCESS METHOD { $$ = OBJECT_ACCESS_METHOD; }
7139 124 : | EVENT TRIGGER { $$ = OBJECT_EVENT_TRIGGER; }
7140 156 : | EXTENSION { $$ = OBJECT_EXTENSION; }
7141 154 : | FOREIGN DATA_P WRAPPER { $$ = OBJECT_FDW; }
7142 154 : | opt_procedural LANGUAGE { $$ = OBJECT_LANGUAGE; }
7143 378 : | PUBLICATION { $$ = OBJECT_PUBLICATION; }
7144 590 : | SCHEMA { $$ = OBJECT_SCHEMA; }
7145 130 : | SERVER { $$ = OBJECT_FOREIGN_SERVER; }
7146 : ;
7147 :
7148 : /* object types attached to a table */
7149 : object_type_name_on_any_name:
7150 164 : POLICY { $$ = OBJECT_POLICY; }
7151 268 : | RULE { $$ = OBJECT_RULE; }
7152 798 : | TRIGGER { $$ = OBJECT_TRIGGER; }
7153 : ;
7154 :
7155 : any_name_list:
7156 26278 : any_name { $$ = list_make1($1); }
7157 4186 : | any_name_list ',' any_name { $$ = lappend($1, $3); }
7158 : ;
7159 :
7160 67250 : any_name: ColId { $$ = list_make1(makeString($1)); }
7161 8946 : | ColId attrs { $$ = lcons(makeString($1), $2); }
7162 : ;
7163 :
7164 : attrs: '.' attr_name
7165 125180 : { $$ = list_make1(makeString($2)); }
7166 : | attrs '.' attr_name
7167 64 : { $$ = lappend($1, makeString($3)); }
7168 : ;
7169 :
7170 : type_name_list:
7171 1068 : Typename { $$ = list_make1($1); }
7172 96 : | type_name_list ',' Typename { $$ = lappend($1, $3); }
7173 : ;
7174 :
7175 : /*****************************************************************************
7176 : *
7177 : * QUERY:
7178 : * truncate table relname1, relname2, ...
7179 : *
7180 : *****************************************************************************/
7181 :
7182 : TruncateStmt:
7183 : TRUNCATE opt_table relation_expr_list opt_restart_seqs opt_drop_behavior
7184 : {
7185 1690 : TruncateStmt *n = makeNode(TruncateStmt);
7186 :
7187 1690 : n->relations = $3;
7188 1690 : n->restart_seqs = $4;
7189 1690 : n->behavior = $5;
7190 1690 : $$ = (Node *) n;
7191 : }
7192 : ;
7193 :
7194 : opt_restart_seqs:
7195 24 : CONTINUE_P IDENTITY_P { $$ = false; }
7196 22 : | RESTART IDENTITY_P { $$ = true; }
7197 1644 : | /* EMPTY */ { $$ = false; }
7198 : ;
7199 :
7200 : /*****************************************************************************
7201 : *
7202 : * COMMENT ON <object> IS <text>
7203 : *
7204 : *****************************************************************************/
7205 :
7206 : CommentStmt:
7207 : COMMENT ON object_type_any_name any_name IS comment_text
7208 : {
7209 5898 : CommentStmt *n = makeNode(CommentStmt);
7210 :
7211 5898 : n->objtype = $3;
7212 5898 : n->object = (Node *) $4;
7213 5898 : n->comment = $6;
7214 5898 : $$ = (Node *) n;
7215 : }
7216 : | COMMENT ON COLUMN any_name IS comment_text
7217 : {
7218 114 : CommentStmt *n = makeNode(CommentStmt);
7219 :
7220 114 : n->objtype = OBJECT_COLUMN;
7221 114 : n->object = (Node *) $4;
7222 114 : n->comment = $6;
7223 114 : $$ = (Node *) n;
7224 : }
7225 : | COMMENT ON object_type_name name IS comment_text
7226 : {
7227 478 : CommentStmt *n = makeNode(CommentStmt);
7228 :
7229 478 : n->objtype = $3;
7230 478 : n->object = (Node *) makeString($4);
7231 478 : n->comment = $6;
7232 478 : $$ = (Node *) n;
7233 : }
7234 : | COMMENT ON TYPE_P Typename IS comment_text
7235 : {
7236 56 : CommentStmt *n = makeNode(CommentStmt);
7237 :
7238 56 : n->objtype = OBJECT_TYPE;
7239 56 : n->object = (Node *) $4;
7240 56 : n->comment = $6;
7241 56 : $$ = (Node *) n;
7242 : }
7243 : | COMMENT ON DOMAIN_P Typename IS comment_text
7244 : {
7245 8 : CommentStmt *n = makeNode(CommentStmt);
7246 :
7247 8 : n->objtype = OBJECT_DOMAIN;
7248 8 : n->object = (Node *) $4;
7249 8 : n->comment = $6;
7250 8 : $$ = (Node *) n;
7251 : }
7252 : | COMMENT ON AGGREGATE aggregate_with_argtypes IS comment_text
7253 : {
7254 40 : CommentStmt *n = makeNode(CommentStmt);
7255 :
7256 40 : n->objtype = OBJECT_AGGREGATE;
7257 40 : n->object = (Node *) $4;
7258 40 : n->comment = $6;
7259 40 : $$ = (Node *) n;
7260 : }
7261 : | COMMENT ON FUNCTION function_with_argtypes IS comment_text
7262 : {
7263 170 : CommentStmt *n = makeNode(CommentStmt);
7264 :
7265 170 : n->objtype = OBJECT_FUNCTION;
7266 170 : n->object = (Node *) $4;
7267 170 : n->comment = $6;
7268 170 : $$ = (Node *) n;
7269 : }
7270 : | COMMENT ON OPERATOR operator_with_argtypes IS comment_text
7271 : {
7272 18 : CommentStmt *n = makeNode(CommentStmt);
7273 :
7274 18 : n->objtype = OBJECT_OPERATOR;
7275 18 : n->object = (Node *) $4;
7276 18 : n->comment = $6;
7277 18 : $$ = (Node *) n;
7278 : }
7279 : | COMMENT ON CONSTRAINT name ON any_name IS comment_text
7280 : {
7281 150 : CommentStmt *n = makeNode(CommentStmt);
7282 :
7283 150 : n->objtype = OBJECT_TABCONSTRAINT;
7284 150 : n->object = (Node *) lappend($6, makeString($4));
7285 150 : n->comment = $8;
7286 150 : $$ = (Node *) n;
7287 : }
7288 : | COMMENT ON CONSTRAINT name ON DOMAIN_P any_name IS comment_text
7289 : {
7290 48 : CommentStmt *n = makeNode(CommentStmt);
7291 :
7292 48 : n->objtype = OBJECT_DOMCONSTRAINT;
7293 : /*
7294 : * should use Typename not any_name in the production, but
7295 : * there's a shift/reduce conflict if we do that, so fix it
7296 : * up here.
7297 : */
7298 48 : n->object = (Node *) list_make2(makeTypeNameFromNameList($7), makeString($4));
7299 48 : n->comment = $9;
7300 48 : $$ = (Node *) n;
7301 : }
7302 : | COMMENT ON object_type_name_on_any_name name ON any_name IS comment_text
7303 : {
7304 40 : CommentStmt *n = makeNode(CommentStmt);
7305 :
7306 40 : n->objtype = $3;
7307 40 : n->object = (Node *) lappend($6, makeString($4));
7308 40 : n->comment = $8;
7309 40 : $$ = (Node *) n;
7310 : }
7311 : | COMMENT ON PROCEDURE function_with_argtypes IS comment_text
7312 : {
7313 0 : CommentStmt *n = makeNode(CommentStmt);
7314 :
7315 0 : n->objtype = OBJECT_PROCEDURE;
7316 0 : n->object = (Node *) $4;
7317 0 : n->comment = $6;
7318 0 : $$ = (Node *) n;
7319 : }
7320 : | COMMENT ON ROUTINE function_with_argtypes IS comment_text
7321 : {
7322 0 : CommentStmt *n = makeNode(CommentStmt);
7323 :
7324 0 : n->objtype = OBJECT_ROUTINE;
7325 0 : n->object = (Node *) $4;
7326 0 : n->comment = $6;
7327 0 : $$ = (Node *) n;
7328 : }
7329 : | COMMENT ON TRANSFORM FOR Typename LANGUAGE name IS comment_text
7330 : {
7331 14 : CommentStmt *n = makeNode(CommentStmt);
7332 :
7333 14 : n->objtype = OBJECT_TRANSFORM;
7334 14 : n->object = (Node *) list_make2($5, makeString($7));
7335 14 : n->comment = $9;
7336 14 : $$ = (Node *) n;
7337 : }
7338 : | COMMENT ON OPERATOR CLASS any_name USING name IS comment_text
7339 : {
7340 0 : CommentStmt *n = makeNode(CommentStmt);
7341 :
7342 0 : n->objtype = OBJECT_OPCLASS;
7343 0 : n->object = (Node *) lcons(makeString($7), $5);
7344 0 : n->comment = $9;
7345 0 : $$ = (Node *) n;
7346 : }
7347 : | COMMENT ON OPERATOR FAMILY any_name USING name IS comment_text
7348 : {
7349 0 : CommentStmt *n = makeNode(CommentStmt);
7350 :
7351 0 : n->objtype = OBJECT_OPFAMILY;
7352 0 : n->object = (Node *) lcons(makeString($7), $5);
7353 0 : n->comment = $9;
7354 0 : $$ = (Node *) n;
7355 : }
7356 : | COMMENT ON LARGE_P OBJECT_P NumericOnly IS comment_text
7357 : {
7358 24 : CommentStmt *n = makeNode(CommentStmt);
7359 :
7360 24 : n->objtype = OBJECT_LARGEOBJECT;
7361 24 : n->object = (Node *) $5;
7362 24 : n->comment = $7;
7363 24 : $$ = (Node *) n;
7364 : }
7365 : | COMMENT ON CAST '(' Typename AS Typename ')' IS comment_text
7366 : {
7367 0 : CommentStmt *n = makeNode(CommentStmt);
7368 :
7369 0 : n->objtype = OBJECT_CAST;
7370 0 : n->object = (Node *) list_make2($5, $7);
7371 0 : n->comment = $10;
7372 0 : $$ = (Node *) n;
7373 : }
7374 : ;
7375 :
7376 : comment_text:
7377 6954 : Sconst { $$ = $1; }
7378 104 : | NULL_P { $$ = NULL; }
7379 : ;
7380 :
7381 :
7382 : /*****************************************************************************
7383 : *
7384 : * SECURITY LABEL [FOR <provider>] ON <object> IS <label>
7385 : *
7386 : * As with COMMENT ON, <object> can refer to various types of database
7387 : * objects (e.g. TABLE, COLUMN, etc.).
7388 : *
7389 : *****************************************************************************/
7390 :
7391 : SecLabelStmt:
7392 : SECURITY LABEL opt_provider ON object_type_any_name any_name
7393 : IS security_label
7394 : {
7395 48 : SecLabelStmt *n = makeNode(SecLabelStmt);
7396 :
7397 48 : n->provider = $3;
7398 48 : n->objtype = $5;
7399 48 : n->object = (Node *) $6;
7400 48 : n->label = $8;
7401 48 : $$ = (Node *) n;
7402 : }
7403 : | SECURITY LABEL opt_provider ON COLUMN any_name
7404 : IS security_label
7405 : {
7406 4 : SecLabelStmt *n = makeNode(SecLabelStmt);
7407 :
7408 4 : n->provider = $3;
7409 4 : n->objtype = OBJECT_COLUMN;
7410 4 : n->object = (Node *) $6;
7411 4 : n->label = $8;
7412 4 : $$ = (Node *) n;
7413 : }
7414 : | SECURITY LABEL opt_provider ON object_type_name name
7415 : IS security_label
7416 : {
7417 44 : SecLabelStmt *n = makeNode(SecLabelStmt);
7418 :
7419 44 : n->provider = $3;
7420 44 : n->objtype = $5;
7421 44 : n->object = (Node *) makeString($6);
7422 44 : n->label = $8;
7423 44 : $$ = (Node *) n;
7424 : }
7425 : | SECURITY LABEL opt_provider ON TYPE_P Typename
7426 : IS security_label
7427 : {
7428 0 : SecLabelStmt *n = makeNode(SecLabelStmt);
7429 :
7430 0 : n->provider = $3;
7431 0 : n->objtype = OBJECT_TYPE;
7432 0 : n->object = (Node *) $6;
7433 0 : n->label = $8;
7434 0 : $$ = (Node *) n;
7435 : }
7436 : | SECURITY LABEL opt_provider ON DOMAIN_P Typename
7437 : IS security_label
7438 : {
7439 2 : SecLabelStmt *n = makeNode(SecLabelStmt);
7440 :
7441 2 : n->provider = $3;
7442 2 : n->objtype = OBJECT_DOMAIN;
7443 2 : n->object = (Node *) $6;
7444 2 : n->label = $8;
7445 2 : $$ = (Node *) n;
7446 : }
7447 : | SECURITY LABEL opt_provider ON AGGREGATE aggregate_with_argtypes
7448 : IS security_label
7449 : {
7450 0 : SecLabelStmt *n = makeNode(SecLabelStmt);
7451 :
7452 0 : n->provider = $3;
7453 0 : n->objtype = OBJECT_AGGREGATE;
7454 0 : n->object = (Node *) $6;
7455 0 : n->label = $8;
7456 0 : $$ = (Node *) n;
7457 : }
7458 : | SECURITY LABEL opt_provider ON FUNCTION function_with_argtypes
7459 : IS security_label
7460 : {
7461 2 : SecLabelStmt *n = makeNode(SecLabelStmt);
7462 :
7463 2 : n->provider = $3;
7464 2 : n->objtype = OBJECT_FUNCTION;
7465 2 : n->object = (Node *) $6;
7466 2 : n->label = $8;
7467 2 : $$ = (Node *) n;
7468 : }
7469 : | SECURITY LABEL opt_provider ON LARGE_P OBJECT_P NumericOnly
7470 : IS security_label
7471 : {
7472 0 : SecLabelStmt *n = makeNode(SecLabelStmt);
7473 :
7474 0 : n->provider = $3;
7475 0 : n->objtype = OBJECT_LARGEOBJECT;
7476 0 : n->object = (Node *) $7;
7477 0 : n->label = $9;
7478 0 : $$ = (Node *) n;
7479 : }
7480 : | SECURITY LABEL opt_provider ON PROCEDURE function_with_argtypes
7481 : IS security_label
7482 : {
7483 0 : SecLabelStmt *n = makeNode(SecLabelStmt);
7484 :
7485 0 : n->provider = $3;
7486 0 : n->objtype = OBJECT_PROCEDURE;
7487 0 : n->object = (Node *) $6;
7488 0 : n->label = $8;
7489 0 : $$ = (Node *) n;
7490 : }
7491 : | SECURITY LABEL opt_provider ON ROUTINE function_with_argtypes
7492 : IS security_label
7493 : {
7494 0 : SecLabelStmt *n = makeNode(SecLabelStmt);
7495 :
7496 0 : n->provider = $3;
7497 0 : n->objtype = OBJECT_ROUTINE;
7498 0 : n->object = (Node *) $6;
7499 0 : n->label = $8;
7500 0 : $$ = (Node *) n;
7501 : }
7502 : ;
7503 :
7504 20 : opt_provider: FOR NonReservedWord_or_Sconst { $$ = $2; }
7505 80 : | /* EMPTY */ { $$ = NULL; }
7506 : ;
7507 :
7508 100 : security_label: Sconst { $$ = $1; }
7509 0 : | NULL_P { $$ = NULL; }
7510 : ;
7511 :
7512 : /*****************************************************************************
7513 : *
7514 : * QUERY:
7515 : * fetch/move
7516 : *
7517 : *****************************************************************************/
7518 :
7519 : FetchStmt: FETCH fetch_args
7520 : {
7521 7646 : FetchStmt *n = (FetchStmt *) $2;
7522 :
7523 7646 : n->ismove = false;
7524 7646 : $$ = (Node *) n;
7525 : }
7526 : | MOVE fetch_args
7527 : {
7528 68 : FetchStmt *n = (FetchStmt *) $2;
7529 :
7530 68 : n->ismove = true;
7531 68 : $$ = (Node *) n;
7532 : }
7533 : ;
7534 :
7535 : fetch_args: cursor_name
7536 : {
7537 272 : FetchStmt *n = makeNode(FetchStmt);
7538 :
7539 272 : n->portalname = $1;
7540 272 : n->direction = FETCH_FORWARD;
7541 272 : n->howMany = 1;
7542 272 : n->location = -1;
7543 272 : n->direction_keyword = FETCH_KEYWORD_NONE;
7544 272 : $$ = (Node *) n;
7545 : }
7546 : | from_in cursor_name
7547 : {
7548 218 : FetchStmt *n = makeNode(FetchStmt);
7549 :
7550 218 : n->portalname = $2;
7551 218 : n->direction = FETCH_FORWARD;
7552 218 : n->howMany = 1;
7553 218 : n->location = -1;
7554 218 : n->direction_keyword = FETCH_KEYWORD_NONE;
7555 218 : $$ = (Node *) n;
7556 : }
7557 : | SignedIconst opt_from_in cursor_name
7558 : {
7559 4280 : FetchStmt *n = makeNode(FetchStmt);
7560 :
7561 4280 : n->portalname = $3;
7562 4280 : n->direction = FETCH_FORWARD;
7563 4280 : n->howMany = $1;
7564 4280 : n->location = @1;
7565 4280 : n->direction_keyword = FETCH_KEYWORD_NONE;
7566 4280 : $$ = (Node *) n;
7567 : }
7568 : | NEXT opt_from_in cursor_name
7569 : {
7570 2010 : FetchStmt *n = makeNode(FetchStmt);
7571 :
7572 2010 : n->portalname = $3;
7573 2010 : n->direction = FETCH_FORWARD;
7574 2010 : n->howMany = 1;
7575 2010 : n->location = -1;
7576 2010 : n->direction_keyword = FETCH_KEYWORD_NEXT;
7577 2010 : $$ = (Node *) n;
7578 : }
7579 : | PRIOR opt_from_in cursor_name
7580 : {
7581 32 : FetchStmt *n = makeNode(FetchStmt);
7582 :
7583 32 : n->portalname = $3;
7584 32 : n->direction = FETCH_BACKWARD;
7585 32 : n->howMany = 1;
7586 32 : n->location = -1;
7587 32 : n->direction_keyword = FETCH_KEYWORD_PRIOR;
7588 32 : $$ = (Node *) n;
7589 : }
7590 : | FIRST_P opt_from_in cursor_name
7591 : {
7592 26 : FetchStmt *n = makeNode(FetchStmt);
7593 :
7594 26 : n->portalname = $3;
7595 26 : n->direction = FETCH_ABSOLUTE;
7596 26 : n->howMany = 1;
7597 26 : n->location = -1;
7598 26 : n->direction_keyword = FETCH_KEYWORD_FIRST;
7599 26 : $$ = (Node *) n;
7600 : }
7601 : | LAST_P opt_from_in cursor_name
7602 : {
7603 20 : FetchStmt *n = makeNode(FetchStmt);
7604 :
7605 20 : n->portalname = $3;
7606 20 : n->direction = FETCH_ABSOLUTE;
7607 20 : n->howMany = -1;
7608 20 : n->location = -1;
7609 20 : n->direction_keyword = FETCH_KEYWORD_LAST;
7610 20 : $$ = (Node *) n;
7611 : }
7612 : | ABSOLUTE_P SignedIconst opt_from_in cursor_name
7613 : {
7614 94 : FetchStmt *n = makeNode(FetchStmt);
7615 :
7616 94 : n->portalname = $4;
7617 94 : n->direction = FETCH_ABSOLUTE;
7618 94 : n->howMany = $2;
7619 94 : n->location = @2;
7620 94 : n->direction_keyword = FETCH_KEYWORD_ABSOLUTE;
7621 94 : $$ = (Node *) n;
7622 : }
7623 : | RELATIVE_P SignedIconst opt_from_in cursor_name
7624 : {
7625 36 : FetchStmt *n = makeNode(FetchStmt);
7626 :
7627 36 : n->portalname = $4;
7628 36 : n->direction = FETCH_RELATIVE;
7629 36 : n->howMany = $2;
7630 36 : n->location = @2;
7631 36 : n->direction_keyword = FETCH_KEYWORD_RELATIVE;
7632 36 : $$ = (Node *) n;
7633 : }
7634 : | ALL opt_from_in cursor_name
7635 : {
7636 270 : FetchStmt *n = makeNode(FetchStmt);
7637 :
7638 270 : n->portalname = $3;
7639 270 : n->direction = FETCH_FORWARD;
7640 270 : n->howMany = FETCH_ALL;
7641 270 : n->location = -1;
7642 270 : n->direction_keyword = FETCH_KEYWORD_ALL;
7643 270 : $$ = (Node *) n;
7644 : }
7645 : | FORWARD opt_from_in cursor_name
7646 : {
7647 30 : FetchStmt *n = makeNode(FetchStmt);
7648 :
7649 30 : n->portalname = $3;
7650 30 : n->direction = FETCH_FORWARD;
7651 30 : n->howMany = 1;
7652 30 : n->location = -1;
7653 30 : n->direction_keyword = FETCH_KEYWORD_FORWARD;
7654 30 : $$ = (Node *) n;
7655 : }
7656 : | FORWARD SignedIconst opt_from_in cursor_name
7657 : {
7658 12 : FetchStmt *n = makeNode(FetchStmt);
7659 :
7660 12 : n->portalname = $4;
7661 12 : n->direction = FETCH_FORWARD;
7662 12 : n->howMany = $2;
7663 12 : n->location = @2;
7664 12 : n->direction_keyword = FETCH_KEYWORD_FORWARD;
7665 12 : $$ = (Node *) n;
7666 : }
7667 : | FORWARD ALL opt_from_in cursor_name
7668 : {
7669 16 : FetchStmt *n = makeNode(FetchStmt);
7670 :
7671 16 : n->portalname = $4;
7672 16 : n->direction = FETCH_FORWARD;
7673 16 : n->howMany = FETCH_ALL;
7674 16 : n->location = -1;
7675 16 : n->direction_keyword = FETCH_KEYWORD_FORWARD_ALL;
7676 16 : $$ = (Node *) n;
7677 : }
7678 : | BACKWARD opt_from_in cursor_name
7679 : {
7680 80 : FetchStmt *n = makeNode(FetchStmt);
7681 :
7682 80 : n->portalname = $3;
7683 80 : n->direction = FETCH_BACKWARD;
7684 80 : n->howMany = 1;
7685 80 : n->location = -1;
7686 80 : n->direction_keyword = FETCH_KEYWORD_BACKWARD;
7687 80 : $$ = (Node *) n;
7688 : }
7689 : | BACKWARD SignedIconst opt_from_in cursor_name
7690 : {
7691 226 : FetchStmt *n = makeNode(FetchStmt);
7692 :
7693 226 : n->portalname = $4;
7694 226 : n->direction = FETCH_BACKWARD;
7695 226 : n->howMany = $2;
7696 226 : n->location = @2;
7697 226 : n->direction_keyword = FETCH_KEYWORD_BACKWARD;
7698 226 : $$ = (Node *) n;
7699 : }
7700 : | BACKWARD ALL opt_from_in cursor_name
7701 : {
7702 92 : FetchStmt *n = makeNode(FetchStmt);
7703 :
7704 92 : n->portalname = $4;
7705 92 : n->direction = FETCH_BACKWARD;
7706 92 : n->howMany = FETCH_ALL;
7707 92 : n->location = -1;
7708 92 : n->direction_keyword = FETCH_KEYWORD_BACKWARD_ALL;
7709 92 : $$ = (Node *) n;
7710 : }
7711 : ;
7712 :
7713 : from_in: FROM
7714 : | IN_P
7715 : ;
7716 :
7717 : opt_from_in: from_in
7718 : | /* EMPTY */
7719 : ;
7720 :
7721 :
7722 : /*****************************************************************************
7723 : *
7724 : * GRANT and REVOKE statements
7725 : *
7726 : *****************************************************************************/
7727 :
7728 : GrantStmt: GRANT privileges ON privilege_target TO grantee_list
7729 : opt_grant_grant_option opt_granted_by
7730 : {
7731 11588 : GrantStmt *n = makeNode(GrantStmt);
7732 :
7733 11588 : n->is_grant = true;
7734 11588 : n->privileges = $2;
7735 11588 : n->targtype = ($4)->targtype;
7736 11588 : n->objtype = ($4)->objtype;
7737 11588 : n->objects = ($4)->objs;
7738 11588 : n->grantees = $6;
7739 11588 : n->grant_option = $7;
7740 11588 : n->grantor = $8;
7741 11588 : $$ = (Node *) n;
7742 : }
7743 : ;
7744 :
7745 : RevokeStmt:
7746 : REVOKE privileges ON privilege_target
7747 : FROM grantee_list opt_granted_by opt_drop_behavior
7748 : {
7749 10254 : GrantStmt *n = makeNode(GrantStmt);
7750 :
7751 10254 : n->is_grant = false;
7752 10254 : n->grant_option = false;
7753 10254 : n->privileges = $2;
7754 10254 : n->targtype = ($4)->targtype;
7755 10254 : n->objtype = ($4)->objtype;
7756 10254 : n->objects = ($4)->objs;
7757 10254 : n->grantees = $6;
7758 10254 : n->grantor = $7;
7759 10254 : n->behavior = $8;
7760 10254 : $$ = (Node *) n;
7761 : }
7762 : | REVOKE GRANT OPTION FOR privileges ON privilege_target
7763 : FROM grantee_list opt_granted_by opt_drop_behavior
7764 : {
7765 16 : GrantStmt *n = makeNode(GrantStmt);
7766 :
7767 16 : n->is_grant = false;
7768 16 : n->grant_option = true;
7769 16 : n->privileges = $5;
7770 16 : n->targtype = ($7)->targtype;
7771 16 : n->objtype = ($7)->objtype;
7772 16 : n->objects = ($7)->objs;
7773 16 : n->grantees = $9;
7774 16 : n->grantor = $10;
7775 16 : n->behavior = $11;
7776 16 : $$ = (Node *) n;
7777 : }
7778 : ;
7779 :
7780 :
7781 : /*
7782 : * Privilege names are represented as strings; the validity of the privilege
7783 : * names gets checked at execution. This is a bit annoying but we have little
7784 : * choice because of the syntactic conflict with lists of role names in
7785 : * GRANT/REVOKE. What's more, we have to call out in the "privilege"
7786 : * production any reserved keywords that need to be usable as privilege names.
7787 : */
7788 :
7789 : /* either ALL [PRIVILEGES] or a list of individual privileges */
7790 : privileges: privilege_list
7791 19232 : { $$ = $1; }
7792 : | ALL
7793 2690 : { $$ = NIL; }
7794 : | ALL PRIVILEGES
7795 120 : { $$ = NIL; }
7796 : | ALL '(' columnList ')'
7797 : {
7798 18 : AccessPriv *n = makeNode(AccessPriv);
7799 :
7800 18 : n->priv_name = NULL;
7801 18 : n->cols = $3;
7802 18 : $$ = list_make1(n);
7803 : }
7804 : | ALL PRIVILEGES '(' columnList ')'
7805 : {
7806 0 : AccessPriv *n = makeNode(AccessPriv);
7807 :
7808 0 : n->priv_name = NULL;
7809 0 : n->cols = $4;
7810 0 : $$ = list_make1(n);
7811 : }
7812 : ;
7813 :
7814 20154 : privilege_list: privilege { $$ = list_make1($1); }
7815 550 : | privilege_list ',' privilege { $$ = lappend($1, $3); }
7816 : ;
7817 :
7818 : privilege: SELECT opt_column_list
7819 : {
7820 9188 : AccessPriv *n = makeNode(AccessPriv);
7821 :
7822 9188 : n->priv_name = pstrdup($1);
7823 9188 : n->cols = $2;
7824 9188 : $$ = n;
7825 : }
7826 : | REFERENCES opt_column_list
7827 : {
7828 14 : AccessPriv *n = makeNode(AccessPriv);
7829 :
7830 14 : n->priv_name = pstrdup($1);
7831 14 : n->cols = $2;
7832 14 : $$ = n;
7833 : }
7834 : | CREATE opt_column_list
7835 : {
7836 290 : AccessPriv *n = makeNode(AccessPriv);
7837 :
7838 290 : n->priv_name = pstrdup($1);
7839 290 : n->cols = $2;
7840 290 : $$ = n;
7841 : }
7842 : | ALTER SYSTEM_P
7843 : {
7844 24 : AccessPriv *n = makeNode(AccessPriv);
7845 24 : n->priv_name = pstrdup("alter system");
7846 24 : n->cols = NIL;
7847 24 : $$ = n;
7848 : }
7849 : | ColId opt_column_list
7850 : {
7851 11188 : AccessPriv *n = makeNode(AccessPriv);
7852 :
7853 11188 : n->priv_name = $1;
7854 11188 : n->cols = $2;
7855 11188 : $$ = n;
7856 : }
7857 : ;
7858 :
7859 : parameter_name_list:
7860 : parameter_name
7861 : {
7862 74 : $$ = list_make1(makeString($1));
7863 : }
7864 : | parameter_name_list ',' parameter_name
7865 : {
7866 50 : $$ = lappend($1, makeString($3));
7867 : }
7868 : ;
7869 :
7870 : parameter_name:
7871 : ColId
7872 : {
7873 124 : $$ = $1;
7874 : }
7875 : | parameter_name '.' ColId
7876 : {
7877 30 : $$ = psprintf("%s.%s", $1, $3);
7878 : }
7879 : ;
7880 :
7881 :
7882 : /* Don't bother trying to fold the first two rules into one using
7883 : * opt_table. You're going to get conflicts.
7884 : */
7885 : privilege_target:
7886 : qualified_name_list
7887 : {
7888 11228 : PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
7889 :
7890 11228 : n->targtype = ACL_TARGET_OBJECT;
7891 11228 : n->objtype = OBJECT_TABLE;
7892 11228 : n->objs = $1;
7893 11228 : $$ = n;
7894 : }
7895 : | TABLE qualified_name_list
7896 : {
7897 388 : PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
7898 :
7899 388 : n->targtype = ACL_TARGET_OBJECT;
7900 388 : n->objtype = OBJECT_TABLE;
7901 388 : n->objs = $2;
7902 388 : $$ = n;
7903 : }
7904 : | SEQUENCE qualified_name_list
7905 : {
7906 22 : PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
7907 :
7908 22 : n->targtype = ACL_TARGET_OBJECT;
7909 22 : n->objtype = OBJECT_SEQUENCE;
7910 22 : n->objs = $2;
7911 22 : $$ = n;
7912 : }
7913 : | FOREIGN DATA_P WRAPPER name_list
7914 : {
7915 92 : PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
7916 :
7917 92 : n->targtype = ACL_TARGET_OBJECT;
7918 92 : n->objtype = OBJECT_FDW;
7919 92 : n->objs = $4;
7920 92 : $$ = n;
7921 : }
7922 : | FOREIGN SERVER name_list
7923 : {
7924 88 : PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
7925 :
7926 88 : n->targtype = ACL_TARGET_OBJECT;
7927 88 : n->objtype = OBJECT_FOREIGN_SERVER;
7928 88 : n->objs = $3;
7929 88 : $$ = n;
7930 : }
7931 : | FUNCTION function_with_argtypes_list
7932 : {
7933 8932 : PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
7934 :
7935 8932 : n->targtype = ACL_TARGET_OBJECT;
7936 8932 : n->objtype = OBJECT_FUNCTION;
7937 8932 : n->objs = $2;
7938 8932 : $$ = n;
7939 : }
7940 : | PROCEDURE function_with_argtypes_list
7941 : {
7942 42 : PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
7943 :
7944 42 : n->targtype = ACL_TARGET_OBJECT;
7945 42 : n->objtype = OBJECT_PROCEDURE;
7946 42 : n->objs = $2;
7947 42 : $$ = n;
7948 : }
7949 : | ROUTINE function_with_argtypes_list
7950 : {
7951 0 : PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
7952 :
7953 0 : n->targtype = ACL_TARGET_OBJECT;
7954 0 : n->objtype = OBJECT_ROUTINE;
7955 0 : n->objs = $2;
7956 0 : $$ = n;
7957 : }
7958 : | DATABASE name_list
7959 : {
7960 346 : PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
7961 :
7962 346 : n->targtype = ACL_TARGET_OBJECT;
7963 346 : n->objtype = OBJECT_DATABASE;
7964 346 : n->objs = $2;
7965 346 : $$ = n;
7966 : }
7967 : | DOMAIN_P any_name_list
7968 : {
7969 26 : PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
7970 :
7971 26 : n->targtype = ACL_TARGET_OBJECT;
7972 26 : n->objtype = OBJECT_DOMAIN;
7973 26 : n->objs = $2;
7974 26 : $$ = n;
7975 : }
7976 : | LANGUAGE name_list
7977 : {
7978 42 : PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
7979 :
7980 42 : n->targtype = ACL_TARGET_OBJECT;
7981 42 : n->objtype = OBJECT_LANGUAGE;
7982 42 : n->objs = $2;
7983 42 : $$ = n;
7984 : }
7985 : | LARGE_P OBJECT_P NumericOnly_list
7986 : {
7987 80 : PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
7988 :
7989 80 : n->targtype = ACL_TARGET_OBJECT;
7990 80 : n->objtype = OBJECT_LARGEOBJECT;
7991 80 : n->objs = $3;
7992 80 : $$ = n;
7993 : }
7994 : | PARAMETER parameter_name_list
7995 : {
7996 74 : PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
7997 74 : n->targtype = ACL_TARGET_OBJECT;
7998 74 : n->objtype = OBJECT_PARAMETER_ACL;
7999 74 : n->objs = $2;
8000 74 : $$ = n;
8001 : }
8002 : | SCHEMA name_list
8003 : {
8004 362 : PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
8005 :
8006 362 : n->targtype = ACL_TARGET_OBJECT;
8007 362 : n->objtype = OBJECT_SCHEMA;
8008 362 : n->objs = $2;
8009 362 : $$ = n;
8010 : }
8011 : | TABLESPACE name_list
8012 : {
8013 6 : PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
8014 :
8015 6 : n->targtype = ACL_TARGET_OBJECT;
8016 6 : n->objtype = OBJECT_TABLESPACE;
8017 6 : n->objs = $2;
8018 6 : $$ = n;
8019 : }
8020 : | TYPE_P any_name_list
8021 : {
8022 112 : PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
8023 :
8024 112 : n->targtype = ACL_TARGET_OBJECT;
8025 112 : n->objtype = OBJECT_TYPE;
8026 112 : n->objs = $2;
8027 112 : $$ = n;
8028 : }
8029 : | ALL TABLES IN_P SCHEMA name_list
8030 : {
8031 12 : PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
8032 :
8033 12 : n->targtype = ACL_TARGET_ALL_IN_SCHEMA;
8034 12 : n->objtype = OBJECT_TABLE;
8035 12 : n->objs = $5;
8036 12 : $$ = n;
8037 : }
8038 : | ALL SEQUENCES IN_P SCHEMA name_list
8039 : {
8040 0 : PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
8041 :
8042 0 : n->targtype = ACL_TARGET_ALL_IN_SCHEMA;
8043 0 : n->objtype = OBJECT_SEQUENCE;
8044 0 : n->objs = $5;
8045 0 : $$ = n;
8046 : }
8047 : | ALL FUNCTIONS IN_P SCHEMA name_list
8048 : {
8049 6 : PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
8050 :
8051 6 : n->targtype = ACL_TARGET_ALL_IN_SCHEMA;
8052 6 : n->objtype = OBJECT_FUNCTION;
8053 6 : n->objs = $5;
8054 6 : $$ = n;
8055 : }
8056 : | ALL PROCEDURES IN_P SCHEMA name_list
8057 : {
8058 6 : PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
8059 :
8060 6 : n->targtype = ACL_TARGET_ALL_IN_SCHEMA;
8061 6 : n->objtype = OBJECT_PROCEDURE;
8062 6 : n->objs = $5;
8063 6 : $$ = n;
8064 : }
8065 : | ALL ROUTINES IN_P SCHEMA name_list
8066 : {
8067 6 : PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
8068 :
8069 6 : n->targtype = ACL_TARGET_ALL_IN_SCHEMA;
8070 6 : n->objtype = OBJECT_ROUTINE;
8071 6 : n->objs = $5;
8072 6 : $$ = n;
8073 : }
8074 : ;
8075 :
8076 :
8077 : grantee_list:
8078 22048 : grantee { $$ = list_make1($1); }
8079 108 : | grantee_list ',' grantee { $$ = lappend($1, $3); }
8080 : ;
8081 :
8082 : grantee:
8083 22132 : RoleSpec { $$ = $1; }
8084 24 : | GROUP_P RoleSpec { $$ = $2; }
8085 : ;
8086 :
8087 :
8088 : opt_grant_grant_option:
8089 102 : WITH GRANT OPTION { $$ = true; }
8090 11610 : | /*EMPTY*/ { $$ = false; }
8091 : ;
8092 :
8093 : /*****************************************************************************
8094 : *
8095 : * GRANT and REVOKE ROLE statements
8096 : *
8097 : *****************************************************************************/
8098 :
8099 : GrantRoleStmt:
8100 : GRANT privilege_list TO role_list opt_granted_by
8101 : {
8102 588 : GrantRoleStmt *n = makeNode(GrantRoleStmt);
8103 :
8104 588 : n->is_grant = true;
8105 588 : n->granted_roles = $2;
8106 588 : n->grantee_roles = $4;
8107 588 : n->opt = NIL;
8108 588 : n->grantor = $5;
8109 588 : $$ = (Node *) n;
8110 : }
8111 : | GRANT privilege_list TO role_list WITH grant_role_opt_list opt_granted_by
8112 : {
8113 178 : GrantRoleStmt *n = makeNode(GrantRoleStmt);
8114 :
8115 178 : n->is_grant = true;
8116 178 : n->granted_roles = $2;
8117 178 : n->grantee_roles = $4;
8118 178 : n->opt = $6;
8119 178 : n->grantor = $7;
8120 178 : $$ = (Node *) n;
8121 : }
8122 : ;
8123 :
8124 : RevokeRoleStmt:
8125 : REVOKE privilege_list FROM role_list opt_granted_by opt_drop_behavior
8126 : {
8127 90 : GrantRoleStmt *n = makeNode(GrantRoleStmt);
8128 :
8129 90 : n->is_grant = false;
8130 90 : n->opt = NIL;
8131 90 : n->granted_roles = $2;
8132 90 : n->grantee_roles = $4;
8133 90 : n->grantor = $5;
8134 90 : n->behavior = $6;
8135 90 : $$ = (Node *) n;
8136 : }
8137 : | REVOKE ColId OPTION FOR privilege_list FROM role_list opt_granted_by opt_drop_behavior
8138 : {
8139 66 : GrantRoleStmt *n = makeNode(GrantRoleStmt);
8140 : DefElem *opt;
8141 :
8142 66 : opt = makeDefElem(pstrdup($2),
8143 66 : (Node *) makeBoolean(false), @2);
8144 66 : n->is_grant = false;
8145 66 : n->opt = list_make1(opt);
8146 66 : n->granted_roles = $5;
8147 66 : n->grantee_roles = $7;
8148 66 : n->grantor = $8;
8149 66 : n->behavior = $9;
8150 66 : $$ = (Node *) n;
8151 : }
8152 : ;
8153 :
8154 : grant_role_opt_list:
8155 120 : grant_role_opt_list ',' grant_role_opt { $$ = lappend($1, $3); }
8156 178 : | grant_role_opt { $$ = list_make1($1); }
8157 : ;
8158 :
8159 : grant_role_opt:
8160 : ColLabel grant_role_opt_value
8161 : {
8162 298 : $$ = makeDefElem(pstrdup($1), $2, @1);
8163 : }
8164 : ;
8165 :
8166 : grant_role_opt_value:
8167 72 : OPTION { $$ = (Node *) makeBoolean(true); }
8168 112 : | TRUE_P { $$ = (Node *) makeBoolean(true); }
8169 114 : | FALSE_P { $$ = (Node *) makeBoolean(false); }
8170 : ;
8171 :
8172 138 : opt_granted_by: GRANTED BY RoleSpec { $$ = $3; }
8173 22642 : | /*EMPTY*/ { $$ = NULL; }
8174 : ;
8175 :
8176 : /*****************************************************************************
8177 : *
8178 : * ALTER DEFAULT PRIVILEGES statement
8179 : *
8180 : *****************************************************************************/
8181 :
8182 : AlterDefaultPrivilegesStmt:
8183 : ALTER DEFAULT PRIVILEGES DefACLOptionList DefACLAction
8184 : {
8185 190 : AlterDefaultPrivilegesStmt *n = makeNode(AlterDefaultPrivilegesStmt);
8186 :
8187 190 : n->options = $4;
8188 190 : n->action = (GrantStmt *) $5;
8189 190 : $$ = (Node *) n;
8190 : }
8191 : ;
8192 :
8193 : DefACLOptionList:
8194 128 : DefACLOptionList DefACLOption { $$ = lappend($1, $2); }
8195 190 : | /* EMPTY */ { $$ = NIL; }
8196 : ;
8197 :
8198 : DefACLOption:
8199 : IN_P SCHEMA name_list
8200 : {
8201 60 : $$ = makeDefElem("schemas", (Node *) $3, @1);
8202 : }
8203 : | FOR ROLE role_list
8204 : {
8205 68 : $$ = makeDefElem("roles", (Node *) $3, @1);
8206 : }
8207 : | FOR USER role_list
8208 : {
8209 0 : $$ = makeDefElem("roles", (Node *) $3, @1);
8210 : }
8211 : ;
8212 :
8213 : /*
8214 : * This should match GRANT/REVOKE, except that individual target objects
8215 : * are not mentioned and we only allow a subset of object types.
8216 : */
8217 : DefACLAction:
8218 : GRANT privileges ON defacl_privilege_target TO grantee_list
8219 : opt_grant_grant_option
8220 : {
8221 124 : GrantStmt *n = makeNode(GrantStmt);
8222 :
8223 124 : n->is_grant = true;
8224 124 : n->privileges = $2;
8225 124 : n->targtype = ACL_TARGET_DEFAULTS;
8226 124 : n->objtype = $4;
8227 124 : n->objects = NIL;
8228 124 : n->grantees = $6;
8229 124 : n->grant_option = $7;
8230 124 : $$ = (Node *) n;
8231 : }
8232 : | REVOKE privileges ON defacl_privilege_target
8233 : FROM grantee_list opt_drop_behavior
8234 : {
8235 66 : GrantStmt *n = makeNode(GrantStmt);
8236 :
8237 66 : n->is_grant = false;
8238 66 : n->grant_option = false;
8239 66 : n->privileges = $2;
8240 66 : n->targtype = ACL_TARGET_DEFAULTS;
8241 66 : n->objtype = $4;
8242 66 : n->objects = NIL;
8243 66 : n->grantees = $6;
8244 66 : n->behavior = $7;
8245 66 : $$ = (Node *) n;
8246 : }
8247 : | REVOKE GRANT OPTION FOR privileges ON defacl_privilege_target
8248 : FROM grantee_list opt_drop_behavior
8249 : {
8250 0 : GrantStmt *n = makeNode(GrantStmt);
8251 :
8252 0 : n->is_grant = false;
8253 0 : n->grant_option = true;
8254 0 : n->privileges = $5;
8255 0 : n->targtype = ACL_TARGET_DEFAULTS;
8256 0 : n->objtype = $7;
8257 0 : n->objects = NIL;
8258 0 : n->grantees = $9;
8259 0 : n->behavior = $10;
8260 0 : $$ = (Node *) n;
8261 : }
8262 : ;
8263 :
8264 : defacl_privilege_target:
8265 78 : TABLES { $$ = OBJECT_TABLE; }
8266 16 : | FUNCTIONS { $$ = OBJECT_FUNCTION; }
8267 6 : | ROUTINES { $$ = OBJECT_FUNCTION; }
8268 6 : | SEQUENCES { $$ = OBJECT_SEQUENCE; }
8269 18 : | TYPES_P { $$ = OBJECT_TYPE; }
8270 36 : | SCHEMAS { $$ = OBJECT_SCHEMA; }
8271 30 : | LARGE_P OBJECTS_P { $$ = OBJECT_LARGEOBJECT; }
8272 : ;
8273 :
8274 :
8275 : /*****************************************************************************
8276 : *
8277 : * QUERY: CREATE INDEX
8278 : *
8279 : * Note: we cannot put TABLESPACE clause after WHERE clause unless we are
8280 : * willing to make TABLESPACE a fully reserved word.
8281 : *****************************************************************************/
8282 :
8283 : IndexStmt: CREATE opt_unique INDEX opt_concurrently opt_single_name
8284 : ON relation_expr access_method_clause '(' index_params ')'
8285 : opt_include opt_unique_null_treatment opt_reloptions OptTableSpace where_clause
8286 : {
8287 6662 : IndexStmt *n = makeNode(IndexStmt);
8288 :
8289 6662 : n->unique = $2;
8290 6662 : n->concurrent = $4;
8291 6662 : n->idxname = $5;
8292 6662 : n->relation = $7;
8293 6662 : n->accessMethod = $8;
8294 6662 : n->indexParams = $10;
8295 6662 : n->indexIncludingParams = $12;
8296 6662 : n->nulls_not_distinct = !$13;
8297 6662 : n->options = $14;
8298 6662 : n->tableSpace = $15;
8299 6662 : n->whereClause = $16;
8300 6662 : n->excludeOpNames = NIL;
8301 6662 : n->idxcomment = NULL;
8302 6662 : n->indexOid = InvalidOid;
8303 6662 : n->oldNumber = InvalidRelFileNumber;
8304 6662 : n->oldCreateSubid = InvalidSubTransactionId;
8305 6662 : n->oldFirstRelfilelocatorSubid = InvalidSubTransactionId;
8306 6662 : n->primary = false;
8307 6662 : n->isconstraint = false;
8308 6662 : n->deferrable = false;
8309 6662 : n->initdeferred = false;
8310 6662 : n->transformed = false;
8311 6662 : n->if_not_exists = false;
8312 6662 : n->reset_default_tblspc = false;
8313 6662 : $$ = (Node *) n;
8314 : }
8315 : | CREATE opt_unique INDEX opt_concurrently IF_P NOT EXISTS name
8316 : ON relation_expr access_method_clause '(' index_params ')'
8317 : opt_include opt_unique_null_treatment opt_reloptions OptTableSpace where_clause
8318 : {
8319 18 : IndexStmt *n = makeNode(IndexStmt);
8320 :
8321 18 : n->unique = $2;
8322 18 : n->concurrent = $4;
8323 18 : n->idxname = $8;
8324 18 : n->relation = $10;
8325 18 : n->accessMethod = $11;
8326 18 : n->indexParams = $13;
8327 18 : n->indexIncludingParams = $15;
8328 18 : n->nulls_not_distinct = !$16;
8329 18 : n->options = $17;
8330 18 : n->tableSpace = $18;
8331 18 : n->whereClause = $19;
8332 18 : n->excludeOpNames = NIL;
8333 18 : n->idxcomment = NULL;
8334 18 : n->indexOid = InvalidOid;
8335 18 : n->oldNumber = InvalidRelFileNumber;
8336 18 : n->oldCreateSubid = InvalidSubTransactionId;
8337 18 : n->oldFirstRelfilelocatorSubid = InvalidSubTransactionId;
8338 18 : n->primary = false;
8339 18 : n->isconstraint = false;
8340 18 : n->deferrable = false;
8341 18 : n->initdeferred = false;
8342 18 : n->transformed = false;
8343 18 : n->if_not_exists = true;
8344 18 : n->reset_default_tblspc = false;
8345 18 : $$ = (Node *) n;
8346 : }
8347 : ;
8348 :
8349 : opt_unique:
8350 1294 : UNIQUE { $$ = true; }
8351 5392 : | /*EMPTY*/ { $$ = false; }
8352 : ;
8353 :
8354 : access_method_clause:
8355 3032 : USING name { $$ = $2; }
8356 3882 : | /*EMPTY*/ { $$ = DEFAULT_INDEX_TYPE; }
8357 : ;
8358 :
8359 8106 : index_params: index_elem { $$ = list_make1($1); }
8360 2152 : | index_params ',' index_elem { $$ = lappend($1, $3); }
8361 : ;
8362 :
8363 :
8364 : index_elem_options:
8365 : opt_collate opt_qualified_name opt_asc_desc opt_nulls_order
8366 : {
8367 10840 : $$ = makeNode(IndexElem);
8368 10840 : $$->name = NULL;
8369 10840 : $$->expr = NULL;
8370 10840 : $$->indexcolname = NULL;
8371 10840 : $$->collation = $1;
8372 10840 : $$->opclass = $2;
8373 10840 : $$->opclassopts = NIL;
8374 10840 : $$->ordering = $3;
8375 10840 : $$->nulls_ordering = $4;
8376 : }
8377 : | opt_collate any_name reloptions opt_asc_desc opt_nulls_order
8378 : {
8379 142 : $$ = makeNode(IndexElem);
8380 142 : $$->name = NULL;
8381 142 : $$->expr = NULL;
8382 142 : $$->indexcolname = NULL;
8383 142 : $$->collation = $1;
8384 142 : $$->opclass = $2;
8385 142 : $$->opclassopts = $3;
8386 142 : $$->ordering = $4;
8387 142 : $$->nulls_ordering = $5;
8388 : }
8389 : ;
8390 :
8391 : /*
8392 : * Index attributes can be either simple column references, or arbitrary
8393 : * expressions in parens. For backwards-compatibility reasons, we allow
8394 : * an expression that's just a function call to be written without parens.
8395 : */
8396 : index_elem: ColId index_elem_options
8397 : {
8398 9856 : $$ = $2;
8399 9856 : $$->name = $1;
8400 : }
8401 : | func_expr_windowless index_elem_options
8402 : {
8403 610 : $$ = $2;
8404 610 : $$->expr = $1;
8405 : }
8406 : | '(' a_expr ')' index_elem_options
8407 : {
8408 516 : $$ = $4;
8409 516 : $$->expr = $2;
8410 : }
8411 : ;
8412 :
8413 218 : opt_include: INCLUDE '(' index_including_params ')' { $$ = $3; }
8414 6462 : | /* EMPTY */ { $$ = NIL; }
8415 : ;
8416 :
8417 218 : index_including_params: index_elem { $$ = list_make1($1); }
8418 166 : | index_including_params ',' index_elem { $$ = lappend($1, $3); }
8419 : ;
8420 :
8421 192 : opt_collate: COLLATE any_name { $$ = $2; }
8422 16242 : | /*EMPTY*/ { $$ = NIL; }
8423 : ;
8424 :
8425 :
8426 1820 : opt_asc_desc: ASC { $$ = SORTBY_ASC; }
8427 3552 : | DESC { $$ = SORTBY_DESC; }
8428 112624 : | /*EMPTY*/ { $$ = SORTBY_DEFAULT; }
8429 : ;
8430 :
8431 344 : opt_nulls_order: NULLS_LA FIRST_P { $$ = SORTBY_NULLS_FIRST; }
8432 1732 : | NULLS_LA LAST_P { $$ = SORTBY_NULLS_LAST; }
8433 116140 : | /*EMPTY*/ { $$ = SORTBY_NULLS_DEFAULT; }
8434 : ;
8435 :
8436 :
8437 : /*****************************************************************************
8438 : *
8439 : * QUERY:
8440 : * create [or replace] function <fname>
8441 : * [(<type-1> { , <type-n>})]
8442 : * returns <type-r>
8443 : * as <filename or code in language as appropriate>
8444 : * language <lang> [with parameters]
8445 : *
8446 : *****************************************************************************/
8447 :
8448 : CreateFunctionStmt:
8449 : CREATE opt_or_replace FUNCTION func_name func_args_with_defaults
8450 : RETURNS func_return opt_createfunc_opt_list opt_routine_body
8451 : {
8452 24314 : CreateFunctionStmt *n = makeNode(CreateFunctionStmt);
8453 :
8454 24314 : n->is_procedure = false;
8455 24314 : n->replace = $2;
8456 24314 : n->funcname = $4;
8457 24314 : n->parameters = $5;
8458 24314 : n->returnType = $7;
8459 24314 : n->options = $8;
8460 24314 : n->sql_body = $9;
8461 24314 : $$ = (Node *) n;
8462 : }
8463 : | CREATE opt_or_replace FUNCTION func_name func_args_with_defaults
8464 : RETURNS TABLE '(' table_func_column_list ')' opt_createfunc_opt_list opt_routine_body
8465 : {
8466 188 : CreateFunctionStmt *n = makeNode(CreateFunctionStmt);
8467 :
8468 188 : n->is_procedure = false;
8469 188 : n->replace = $2;
8470 188 : n->funcname = $4;
8471 188 : n->parameters = mergeTableFuncParameters($5, $9, yyscanner);
8472 188 : n->returnType = TableFuncTypeName($9);
8473 188 : n->returnType->location = @7;
8474 188 : n->options = $11;
8475 188 : n->sql_body = $12;
8476 188 : $$ = (Node *) n;
8477 : }
8478 : | CREATE opt_or_replace FUNCTION func_name func_args_with_defaults
8479 : opt_createfunc_opt_list opt_routine_body
8480 : {
8481 488 : CreateFunctionStmt *n = makeNode(CreateFunctionStmt);
8482 :
8483 488 : n->is_procedure = false;
8484 488 : n->replace = $2;
8485 488 : n->funcname = $4;
8486 488 : n->parameters = $5;
8487 488 : n->returnType = NULL;
8488 488 : n->options = $6;
8489 488 : n->sql_body = $7;
8490 488 : $$ = (Node *) n;
8491 : }
8492 : | CREATE opt_or_replace PROCEDURE func_name func_args_with_defaults
8493 : opt_createfunc_opt_list opt_routine_body
8494 : {
8495 370 : CreateFunctionStmt *n = makeNode(CreateFunctionStmt);
8496 :
8497 370 : n->is_procedure = true;
8498 370 : n->replace = $2;
8499 370 : n->funcname = $4;
8500 370 : n->parameters = $5;
8501 370 : n->returnType = NULL;
8502 370 : n->options = $6;
8503 370 : n->sql_body = $7;
8504 370 : $$ = (Node *) n;
8505 : }
8506 : ;
8507 :
8508 : opt_or_replace:
8509 9990 : OR REPLACE { $$ = true; }
8510 20804 : | /*EMPTY*/ { $$ = false; }
8511 : ;
8512 :
8513 12080 : func_args: '(' func_args_list ')' { $$ = $2; }
8514 5886 : | '(' ')' { $$ = NIL; }
8515 : ;
8516 :
8517 : func_args_list:
8518 12080 : func_arg { $$ = list_make1($1); }
8519 11258 : | func_args_list ',' func_arg { $$ = lappend($1, $3); }
8520 : ;
8521 :
8522 : function_with_argtypes_list:
8523 12680 : function_with_argtypes { $$ = list_make1($1); }
8524 : | function_with_argtypes_list ',' function_with_argtypes
8525 84 : { $$ = lappend($1, $3); }
8526 : ;
8527 :
8528 : function_with_argtypes:
8529 : func_name func_args
8530 : {
8531 17966 : ObjectWithArgs *n = makeNode(ObjectWithArgs);
8532 :
8533 17966 : n->objname = $1;
8534 17966 : n->objargs = extractArgTypes($2);
8535 17966 : n->objfuncargs = $2;
8536 17966 : $$ = n;
8537 : }
8538 : /*
8539 : * Because of reduce/reduce conflicts, we can't use func_name
8540 : * below, but we can write it out the long way, which actually
8541 : * allows more cases.
8542 : */
8543 : | type_func_name_keyword
8544 : {
8545 0 : ObjectWithArgs *n = makeNode(ObjectWithArgs);
8546 :
8547 0 : n->objname = list_make1(makeString(pstrdup($1)));
8548 0 : n->args_unspecified = true;
8549 0 : $$ = n;
8550 : }
8551 : | ColId
8552 : {
8553 352 : ObjectWithArgs *n = makeNode(ObjectWithArgs);
8554 :
8555 352 : n->objname = list_make1(makeString($1));
8556 352 : n->args_unspecified = true;
8557 352 : $$ = n;
8558 : }
8559 : | ColId indirection
8560 : {
8561 28 : ObjectWithArgs *n = makeNode(ObjectWithArgs);
8562 :
8563 28 : n->objname = check_func_name(lcons(makeString($1), $2),
8564 : yyscanner);
8565 28 : n->args_unspecified = true;
8566 28 : $$ = n;
8567 : }
8568 : ;
8569 :
8570 : /*
8571 : * func_args_with_defaults is separate because we only want to accept
8572 : * defaults in CREATE FUNCTION, not in ALTER etc.
8573 : */
8574 : func_args_with_defaults:
8575 20848 : '(' func_args_with_defaults_list ')' { $$ = $2; }
8576 4512 : | '(' ')' { $$ = NIL; }
8577 : ;
8578 :
8579 : func_args_with_defaults_list:
8580 20848 : func_arg_with_default { $$ = list_make1($1); }
8581 : | func_args_with_defaults_list ',' func_arg_with_default
8582 35746 : { $$ = lappend($1, $3); }
8583 : ;
8584 :
8585 : /*
8586 : * The style with arg_class first is SQL99 standard, but Oracle puts
8587 : * param_name first; accept both since it's likely people will try both
8588 : * anyway. Don't bother trying to save productions by letting arg_class
8589 : * have an empty alternative ... you'll get shift/reduce conflicts.
8590 : *
8591 : * We can catch over-specified arguments here if we want to,
8592 : * but for now better to silently swallow typmod, etc.
8593 : * - thomas 2000-03-22
8594 : */
8595 : func_arg:
8596 : arg_class param_name func_type
8597 : {
8598 16930 : FunctionParameter *n = makeNode(FunctionParameter);
8599 :
8600 16930 : n->name = $2;
8601 16930 : n->argType = $3;
8602 16930 : n->mode = $1;
8603 16930 : n->defexpr = NULL;
8604 16930 : n->location = @1;
8605 16930 : $$ = n;
8606 : }
8607 : | param_name arg_class func_type
8608 : {
8609 420 : FunctionParameter *n = makeNode(FunctionParameter);
8610 :
8611 420 : n->name = $1;
8612 420 : n->argType = $3;
8613 420 : n->mode = $2;
8614 420 : n->defexpr = NULL;
8615 420 : n->location = @1;
8616 420 : $$ = n;
8617 : }
8618 : | param_name func_type
8619 : {
8620 15640 : FunctionParameter *n = makeNode(FunctionParameter);
8621 :
8622 15640 : n->name = $1;
8623 15640 : n->argType = $2;
8624 15640 : n->mode = FUNC_PARAM_DEFAULT;
8625 15640 : n->defexpr = NULL;
8626 15640 : n->location = @1;
8627 15640 : $$ = n;
8628 : }
8629 : | arg_class func_type
8630 : {
8631 328 : FunctionParameter *n = makeNode(FunctionParameter);
8632 :
8633 328 : n->name = NULL;
8634 328 : n->argType = $2;
8635 328 : n->mode = $1;
8636 328 : n->defexpr = NULL;
8637 328 : n->location = @1;
8638 328 : $$ = n;
8639 : }
8640 : | func_type
8641 : {
8642 47514 : FunctionParameter *n = makeNode(FunctionParameter);
8643 :
8644 47514 : n->name = NULL;
8645 47514 : n->argType = $1;
8646 47514 : n->mode = FUNC_PARAM_DEFAULT;
8647 47514 : n->defexpr = NULL;
8648 47514 : n->location = @1;
8649 47514 : $$ = n;
8650 : }
8651 : ;
8652 :
8653 : /* INOUT is SQL99 standard, IN OUT is for Oracle compatibility */
8654 4018 : arg_class: IN_P { $$ = FUNC_PARAM_IN; }
8655 12896 : | OUT_P { $$ = FUNC_PARAM_OUT; }
8656 198 : | INOUT { $$ = FUNC_PARAM_INOUT; }
8657 0 : | IN_P OUT_P { $$ = FUNC_PARAM_INOUT; }
8658 566 : | VARIADIC { $$ = FUNC_PARAM_VARIADIC; }
8659 : ;
8660 :
8661 : /*
8662 : * Ideally param_name should be ColId, but that causes too many conflicts.
8663 : */
8664 : param_name: type_function_name
8665 : ;
8666 :
8667 : func_return:
8668 : func_type
8669 : {
8670 : /* We can catch over-specified results here if we want to,
8671 : * but for now better to silently swallow typmod, etc.
8672 : * - thomas 2000-03-22
8673 : */
8674 24314 : $$ = $1;
8675 : }
8676 : ;
8677 :
8678 : /*
8679 : * We would like to make the %TYPE productions here be ColId attrs etc,
8680 : * but that causes reduce/reduce conflicts. type_function_name
8681 : * is next best choice.
8682 : */
8683 126322 : func_type: Typename { $$ = $1; }
8684 : | type_function_name attrs '%' TYPE_P
8685 : {
8686 18 : $$ = makeTypeNameFromNameList(lcons(makeString($1), $2));
8687 18 : $$->pct_type = true;
8688 18 : $$->location = @1;
8689 : }
8690 : | SETOF type_function_name attrs '%' TYPE_P
8691 : {
8692 6 : $$ = makeTypeNameFromNameList(lcons(makeString($2), $3));
8693 6 : $$->pct_type = true;
8694 6 : $$->setof = true;
8695 6 : $$->location = @2;
8696 : }
8697 : ;
8698 :
8699 : func_arg_with_default:
8700 : func_arg
8701 : {
8702 50160 : $$ = $1;
8703 : }
8704 : | func_arg DEFAULT a_expr
8705 : {
8706 6238 : $$ = $1;
8707 6238 : $$->defexpr = $3;
8708 : }
8709 : | func_arg '=' a_expr
8710 : {
8711 196 : $$ = $1;
8712 196 : $$->defexpr = $3;
8713 : }
8714 : ;
8715 :
8716 : /* Aggregate args can be most things that function args can be */
8717 : aggr_arg: func_arg
8718 : {
8719 900 : if (!($1->mode == FUNC_PARAM_DEFAULT ||
8720 60 : $1->mode == FUNC_PARAM_IN ||
8721 60 : $1->mode == FUNC_PARAM_VARIADIC))
8722 0 : ereport(ERROR,
8723 : (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
8724 : errmsg("aggregates cannot have output arguments"),
8725 : parser_errposition(@1)));
8726 900 : $$ = $1;
8727 : }
8728 : ;
8729 :
8730 : /*
8731 : * The SQL standard offers no guidance on how to declare aggregate argument
8732 : * lists, since it doesn't have CREATE AGGREGATE etc. We accept these cases:
8733 : *
8734 : * (*) - normal agg with no args
8735 : * (aggr_arg,...) - normal agg with args
8736 : * (ORDER BY aggr_arg,...) - ordered-set agg with no direct args
8737 : * (aggr_arg,... ORDER BY aggr_arg,...) - ordered-set agg with direct args
8738 : *
8739 : * The zero-argument case is spelled with '*' for consistency with COUNT(*).
8740 : *
8741 : * An additional restriction is that if the direct-args list ends in a
8742 : * VARIADIC item, the ordered-args list must contain exactly one item that
8743 : * is also VARIADIC with the same type. This allows us to collapse the two
8744 : * VARIADIC items into one, which is necessary to represent the aggregate in
8745 : * pg_proc. We check this at the grammar stage so that we can return a list
8746 : * in which the second VARIADIC item is already discarded, avoiding extra work
8747 : * in cases such as DROP AGGREGATE.
8748 : *
8749 : * The return value of this production is a two-element list, in which the
8750 : * first item is a sublist of FunctionParameter nodes (with any duplicate
8751 : * VARIADIC item already dropped, as per above) and the second is an Integer
8752 : * node, containing -1 if there was no ORDER BY and otherwise the number
8753 : * of argument declarations before the ORDER BY. (If this number is equal
8754 : * to the first sublist's length, then we dropped a duplicate VARIADIC item.)
8755 : * This representation is passed as-is to CREATE AGGREGATE; for operations
8756 : * on existing aggregates, we can just apply extractArgTypes to the first
8757 : * sublist.
8758 : */
8759 : aggr_args: '(' '*' ')'
8760 : {
8761 136 : $$ = list_make2(NIL, makeInteger(-1));
8762 : }
8763 : | '(' aggr_args_list ')'
8764 : {
8765 732 : $$ = list_make2($2, makeInteger(-1));
8766 : }
8767 : | '(' ORDER BY aggr_args_list ')'
8768 : {
8769 6 : $$ = list_make2($4, makeInteger(0));
8770 : }
8771 : | '(' aggr_args_list ORDER BY aggr_args_list ')'
8772 : {
8773 : /* this is the only case requiring consistency checking */
8774 32 : $$ = makeOrderedSetArgs($2, $5, yyscanner);
8775 : }
8776 : ;
8777 :
8778 : aggr_args_list:
8779 802 : aggr_arg { $$ = list_make1($1); }
8780 98 : | aggr_args_list ',' aggr_arg { $$ = lappend($1, $3); }
8781 : ;
8782 :
8783 : aggregate_with_argtypes:
8784 : func_name aggr_args
8785 : {
8786 362 : ObjectWithArgs *n = makeNode(ObjectWithArgs);
8787 :
8788 362 : n->objname = $1;
8789 362 : n->objargs = extractAggrArgTypes($2);
8790 362 : n->objfuncargs = (List *) linitial($2);
8791 362 : $$ = n;
8792 : }
8793 : ;
8794 :
8795 : aggregate_with_argtypes_list:
8796 104 : aggregate_with_argtypes { $$ = list_make1($1); }
8797 : | aggregate_with_argtypes_list ',' aggregate_with_argtypes
8798 0 : { $$ = lappend($1, $3); }
8799 : ;
8800 :
8801 : opt_createfunc_opt_list:
8802 : createfunc_opt_list
8803 54 : | /*EMPTY*/ { $$ = NIL; }
8804 : ;
8805 :
8806 : createfunc_opt_list:
8807 : /* Must be at least one to prevent conflict */
8808 25306 : createfunc_opt_item { $$ = list_make1($1); }
8809 67364 : | createfunc_opt_list createfunc_opt_item { $$ = lappend($1, $2); }
8810 : ;
8811 :
8812 : /*
8813 : * Options common to both CREATE FUNCTION and ALTER FUNCTION
8814 : */
8815 : common_func_opt_item:
8816 : CALLED ON NULL_P INPUT_P
8817 : {
8818 380 : $$ = makeDefElem("strict", (Node *) makeBoolean(false), @1);
8819 : }
8820 : | RETURNS NULL_P ON NULL_P INPUT_P
8821 : {
8822 882 : $$ = makeDefElem("strict", (Node *) makeBoolean(true), @1);
8823 : }
8824 : | STRICT_P
8825 : {
8826 13760 : $$ = makeDefElem("strict", (Node *) makeBoolean(true), @1);
8827 : }
8828 : | IMMUTABLE
8829 : {
8830 10188 : $$ = makeDefElem("volatility", (Node *) makeString("immutable"), @1);
8831 : }
8832 : | STABLE
8833 : {
8834 2524 : $$ = makeDefElem("volatility", (Node *) makeString("stable"), @1);
8835 : }
8836 : | VOLATILE
8837 : {
8838 1748 : $$ = makeDefElem("volatility", (Node *) makeString("volatile"), @1);
8839 : }
8840 : | EXTERNAL SECURITY DEFINER
8841 : {
8842 0 : $$ = makeDefElem("security", (Node *) makeBoolean(true), @1);
8843 : }
8844 : | EXTERNAL SECURITY INVOKER
8845 : {
8846 0 : $$ = makeDefElem("security", (Node *) makeBoolean(false), @1);
8847 : }
8848 : | SECURITY DEFINER
8849 : {
8850 58 : $$ = makeDefElem("security", (Node *) makeBoolean(true), @1);
8851 : }
8852 : | SECURITY INVOKER
8853 : {
8854 18 : $$ = makeDefElem("security", (Node *) makeBoolean(false), @1);
8855 : }
8856 : | LEAKPROOF
8857 : {
8858 46 : $$ = makeDefElem("leakproof", (Node *) makeBoolean(true), @1);
8859 : }
8860 : | NOT LEAKPROOF
8861 : {
8862 12 : $$ = makeDefElem("leakproof", (Node *) makeBoolean(false), @1);
8863 : }
8864 : | COST NumericOnly
8865 : {
8866 4358 : $$ = makeDefElem("cost", (Node *) $2, @1);
8867 : }
8868 : | ROWS NumericOnly
8869 : {
8870 600 : $$ = makeDefElem("rows", (Node *) $2, @1);
8871 : }
8872 : | SUPPORT any_name
8873 : {
8874 114 : $$ = makeDefElem("support", (Node *) $2, @1);
8875 : }
8876 : | FunctionSetResetClause
8877 : {
8878 : /* we abuse the normal content of a DefElem here */
8879 146 : $$ = makeDefElem("set", (Node *) $1, @1);
8880 : }
8881 : | PARALLEL ColId
8882 : {
8883 14118 : $$ = makeDefElem("parallel", (Node *) makeString($2), @1);
8884 : }
8885 : ;
8886 :
8887 : createfunc_opt_item:
8888 : AS func_as
8889 : {
8890 19686 : $$ = makeDefElem("as", (Node *) $2, @1);
8891 : }
8892 : | LANGUAGE NonReservedWord_or_Sconst
8893 : {
8894 25286 : $$ = makeDefElem("language", (Node *) makeString($2), @1);
8895 : }
8896 : | TRANSFORM transform_type_list
8897 : {
8898 118 : $$ = makeDefElem("transform", (Node *) $2, @1);
8899 : }
8900 : | WINDOW
8901 : {
8902 20 : $$ = makeDefElem("window", (Node *) makeBoolean(true), @1);
8903 : }
8904 : | common_func_opt_item
8905 : {
8906 47560 : $$ = $1;
8907 : }
8908 : ;
8909 :
8910 16396 : func_as: Sconst { $$ = list_make1(makeString($1)); }
8911 : | Sconst ',' Sconst
8912 : {
8913 3290 : $$ = list_make2(makeString($1), makeString($3));
8914 : }
8915 : ;
8916 :
8917 : ReturnStmt: RETURN a_expr
8918 : {
8919 4878 : ReturnStmt *r = makeNode(ReturnStmt);
8920 :
8921 4878 : r->returnval = (Node *) $2;
8922 4878 : $$ = (Node *) r;
8923 : }
8924 : ;
8925 :
8926 : opt_routine_body:
8927 : ReturnStmt
8928 : {
8929 4872 : $$ = $1;
8930 : }
8931 : | BEGIN_P ATOMIC routine_body_stmt_list END_P
8932 : {
8933 : /*
8934 : * A compound statement is stored as a single-item list
8935 : * containing the list of statements as its member. That
8936 : * way, the parse analysis code can tell apart an empty
8937 : * body from no body at all.
8938 : */
8939 808 : $$ = (Node *) list_make1($3);
8940 : }
8941 : | /*EMPTY*/
8942 : {
8943 19680 : $$ = NULL;
8944 : }
8945 : ;
8946 :
8947 : routine_body_stmt_list:
8948 : routine_body_stmt_list routine_body_stmt ';'
8949 : {
8950 : /* As in stmtmulti, discard empty statements */
8951 824 : if ($2 != NULL)
8952 806 : $$ = lappend($1, $2);
8953 : else
8954 18 : $$ = $1;
8955 : }
8956 : | /*EMPTY*/
8957 : {
8958 808 : $$ = NIL;
8959 : }
8960 : ;
8961 :
8962 : routine_body_stmt:
8963 : stmt
8964 : | ReturnStmt
8965 : ;
8966 :
8967 : transform_type_list:
8968 118 : FOR TYPE_P Typename { $$ = list_make1($3); }
8969 4 : | transform_type_list ',' FOR TYPE_P Typename { $$ = lappend($1, $5); }
8970 : ;
8971 :
8972 : opt_definition:
8973 640 : WITH definition { $$ = $2; }
8974 10064 : | /*EMPTY*/ { $$ = NIL; }
8975 : ;
8976 :
8977 : table_func_column: param_name func_type
8978 : {
8979 442 : FunctionParameter *n = makeNode(FunctionParameter);
8980 :
8981 442 : n->name = $1;
8982 442 : n->argType = $2;
8983 442 : n->mode = FUNC_PARAM_TABLE;
8984 442 : n->defexpr = NULL;
8985 442 : n->location = @1;
8986 442 : $$ = n;
8987 : }
8988 : ;
8989 :
8990 : table_func_column_list:
8991 : table_func_column
8992 : {
8993 188 : $$ = list_make1($1);
8994 : }
8995 : | table_func_column_list ',' table_func_column
8996 : {
8997 254 : $$ = lappend($1, $3);
8998 : }
8999 : ;
9000 :
9001 : /*****************************************************************************
9002 : * ALTER FUNCTION / ALTER PROCEDURE / ALTER ROUTINE
9003 : *
9004 : * RENAME and OWNER subcommands are already provided by the generic
9005 : * ALTER infrastructure, here we just specify alterations that can
9006 : * only be applied to functions.
9007 : *
9008 : *****************************************************************************/
9009 : AlterFunctionStmt:
9010 : ALTER FUNCTION function_with_argtypes alterfunc_opt_list opt_restrict
9011 : {
9012 1370 : AlterFunctionStmt *n = makeNode(AlterFunctionStmt);
9013 :
9014 1370 : n->objtype = OBJECT_FUNCTION;
9015 1370 : n->func = $3;
9016 1370 : n->actions = $4;
9017 1370 : $$ = (Node *) n;
9018 : }
9019 : | ALTER PROCEDURE function_with_argtypes alterfunc_opt_list opt_restrict
9020 : {
9021 18 : AlterFunctionStmt *n = makeNode(AlterFunctionStmt);
9022 :
9023 18 : n->objtype = OBJECT_PROCEDURE;
9024 18 : n->func = $3;
9025 18 : n->actions = $4;
9026 18 : $$ = (Node *) n;
9027 : }
9028 : | ALTER ROUTINE function_with_argtypes alterfunc_opt_list opt_restrict
9029 : {
9030 0 : AlterFunctionStmt *n = makeNode(AlterFunctionStmt);
9031 :
9032 0 : n->objtype = OBJECT_ROUTINE;
9033 0 : n->func = $3;
9034 0 : n->actions = $4;
9035 0 : $$ = (Node *) n;
9036 : }
9037 : ;
9038 :
9039 : alterfunc_opt_list:
9040 : /* At least one option must be specified */
9041 1388 : common_func_opt_item { $$ = list_make1($1); }
9042 4 : | alterfunc_opt_list common_func_opt_item { $$ = lappend($1, $2); }
9043 : ;
9044 :
9045 : /* Ignored, merely for SQL compliance */
9046 : opt_restrict:
9047 : RESTRICT
9048 : | /* EMPTY */
9049 : ;
9050 :
9051 :
9052 : /*****************************************************************************
9053 : *
9054 : * QUERY:
9055 : *
9056 : * DROP FUNCTION funcname (arg1, arg2, ...) [ RESTRICT | CASCADE ]
9057 : * DROP PROCEDURE procname (arg1, arg2, ...) [ RESTRICT | CASCADE ]
9058 : * DROP ROUTINE routname (arg1, arg2, ...) [ RESTRICT | CASCADE ]
9059 : * DROP AGGREGATE aggname (arg1, ...) [ RESTRICT | CASCADE ]
9060 : * DROP OPERATOR opname (leftoperand_typ, rightoperand_typ) [ RESTRICT | CASCADE ]
9061 : *
9062 : *****************************************************************************/
9063 :
9064 : RemoveFuncStmt:
9065 : DROP FUNCTION function_with_argtypes_list opt_drop_behavior
9066 : {
9067 3282 : DropStmt *n = makeNode(DropStmt);
9068 :
9069 3282 : n->removeType = OBJECT_FUNCTION;
9070 3282 : n->objects = $3;
9071 3282 : n->behavior = $4;
9072 3282 : n->missing_ok = false;
9073 3282 : n->concurrent = false;
9074 3282 : $$ = (Node *) n;
9075 : }
9076 : | DROP FUNCTION IF_P EXISTS function_with_argtypes_list opt_drop_behavior
9077 : {
9078 260 : DropStmt *n = makeNode(DropStmt);
9079 :
9080 260 : n->removeType = OBJECT_FUNCTION;
9081 260 : n->objects = $5;
9082 260 : n->behavior = $6;
9083 260 : n->missing_ok = true;
9084 260 : n->concurrent = false;
9085 260 : $$ = (Node *) n;
9086 : }
9087 : | DROP PROCEDURE function_with_argtypes_list opt_drop_behavior
9088 : {
9089 140 : DropStmt *n = makeNode(DropStmt);
9090 :
9091 140 : n->removeType = OBJECT_PROCEDURE;
9092 140 : n->objects = $3;
9093 140 : n->behavior = $4;
9094 140 : n->missing_ok = false;
9095 140 : n->concurrent = false;
9096 140 : $$ = (Node *) n;
9097 : }
9098 : | DROP PROCEDURE IF_P EXISTS function_with_argtypes_list opt_drop_behavior
9099 : {
9100 6 : DropStmt *n = makeNode(DropStmt);
9101 :
9102 6 : n->removeType = OBJECT_PROCEDURE;
9103 6 : n->objects = $5;
9104 6 : n->behavior = $6;
9105 6 : n->missing_ok = true;
9106 6 : n->concurrent = false;
9107 6 : $$ = (Node *) n;
9108 : }
9109 : | DROP ROUTINE function_with_argtypes_list opt_drop_behavior
9110 : {
9111 12 : DropStmt *n = makeNode(DropStmt);
9112 :
9113 12 : n->removeType = OBJECT_ROUTINE;
9114 12 : n->objects = $3;
9115 12 : n->behavior = $4;
9116 12 : n->missing_ok = false;
9117 12 : n->concurrent = false;
9118 12 : $$ = (Node *) n;
9119 : }
9120 : | DROP ROUTINE IF_P EXISTS function_with_argtypes_list opt_drop_behavior
9121 : {
9122 6 : DropStmt *n = makeNode(DropStmt);
9123 :
9124 6 : n->removeType = OBJECT_ROUTINE;
9125 6 : n->objects = $5;
9126 6 : n->behavior = $6;
9127 6 : n->missing_ok = true;
9128 6 : n->concurrent = false;
9129 6 : $$ = (Node *) n;
9130 : }
9131 : ;
9132 :
9133 : RemoveAggrStmt:
9134 : DROP AGGREGATE aggregate_with_argtypes_list opt_drop_behavior
9135 : {
9136 74 : DropStmt *n = makeNode(DropStmt);
9137 :
9138 74 : n->removeType = OBJECT_AGGREGATE;
9139 74 : n->objects = $3;
9140 74 : n->behavior = $4;
9141 74 : n->missing_ok = false;
9142 74 : n->concurrent = false;
9143 74 : $$ = (Node *) n;
9144 : }
9145 : | DROP AGGREGATE IF_P EXISTS aggregate_with_argtypes_list opt_drop_behavior
9146 : {
9147 30 : DropStmt *n = makeNode(DropStmt);
9148 :
9149 30 : n->removeType = OBJECT_AGGREGATE;
9150 30 : n->objects = $5;
9151 30 : n->behavior = $6;
9152 30 : n->missing_ok = true;
9153 30 : n->concurrent = false;
9154 30 : $$ = (Node *) n;
9155 : }
9156 : ;
9157 :
9158 : RemoveOperStmt:
9159 : DROP OPERATOR operator_with_argtypes_list opt_drop_behavior
9160 : {
9161 200 : DropStmt *n = makeNode(DropStmt);
9162 :
9163 200 : n->removeType = OBJECT_OPERATOR;
9164 200 : n->objects = $3;
9165 200 : n->behavior = $4;
9166 200 : n->missing_ok = false;
9167 200 : n->concurrent = false;
9168 200 : $$ = (Node *) n;
9169 : }
9170 : | DROP OPERATOR IF_P EXISTS operator_with_argtypes_list opt_drop_behavior
9171 : {
9172 30 : DropStmt *n = makeNode(DropStmt);
9173 :
9174 30 : n->removeType = OBJECT_OPERATOR;
9175 30 : n->objects = $5;
9176 30 : n->behavior = $6;
9177 30 : n->missing_ok = true;
9178 30 : n->concurrent = false;
9179 30 : $$ = (Node *) n;
9180 : }
9181 : ;
9182 :
9183 : oper_argtypes:
9184 : '(' Typename ')'
9185 : {
9186 12 : ereport(ERROR,
9187 : (errcode(ERRCODE_SYNTAX_ERROR),
9188 : errmsg("missing argument"),
9189 : errhint("Use NONE to denote the missing argument of a unary operator."),
9190 : parser_errposition(@3)));
9191 : }
9192 : | '(' Typename ',' Typename ')'
9193 2464 : { $$ = list_make2($2, $4); }
9194 : | '(' NONE ',' Typename ')' /* left unary */
9195 32 : { $$ = list_make2(NULL, $4); }
9196 : | '(' Typename ',' NONE ')' /* right unary */
9197 12 : { $$ = list_make2($2, NULL); }
9198 : ;
9199 :
9200 : any_operator:
9201 : all_Op
9202 22022 : { $$ = list_make1(makeString($1)); }
9203 : | ColId '.' any_operator
9204 15772 : { $$ = lcons(makeString($1), $3); }
9205 : ;
9206 :
9207 : operator_with_argtypes_list:
9208 230 : operator_with_argtypes { $$ = list_make1($1); }
9209 : | operator_with_argtypes_list ',' operator_with_argtypes
9210 0 : { $$ = lappend($1, $3); }
9211 : ;
9212 :
9213 : operator_with_argtypes:
9214 : any_operator oper_argtypes
9215 : {
9216 2508 : ObjectWithArgs *n = makeNode(ObjectWithArgs);
9217 :
9218 2508 : n->objname = $1;
9219 2508 : n->objargs = $2;
9220 2508 : $$ = n;
9221 : }
9222 : ;
9223 :
9224 : /*****************************************************************************
9225 : *
9226 : * DO <anonymous code block> [ LANGUAGE language ]
9227 : *
9228 : * We use a DefElem list for future extensibility, and to allow flexibility
9229 : * in the clause order.
9230 : *
9231 : *****************************************************************************/
9232 :
9233 : DoStmt: DO dostmt_opt_list
9234 : {
9235 1142 : DoStmt *n = makeNode(DoStmt);
9236 :
9237 1142 : n->args = $2;
9238 1142 : $$ = (Node *) n;
9239 : }
9240 : ;
9241 :
9242 : dostmt_opt_list:
9243 1142 : dostmt_opt_item { $$ = list_make1($1); }
9244 198 : | dostmt_opt_list dostmt_opt_item { $$ = lappend($1, $2); }
9245 : ;
9246 :
9247 : dostmt_opt_item:
9248 : Sconst
9249 : {
9250 1142 : $$ = makeDefElem("as", (Node *) makeString($1), @1);
9251 : }
9252 : | LANGUAGE NonReservedWord_or_Sconst
9253 : {
9254 198 : $$ = makeDefElem("language", (Node *) makeString($2), @1);
9255 : }
9256 : ;
9257 :
9258 : /*****************************************************************************
9259 : *
9260 : * CREATE CAST / DROP CAST
9261 : *
9262 : *****************************************************************************/
9263 :
9264 : CreateCastStmt: CREATE CAST '(' Typename AS Typename ')'
9265 : WITH FUNCTION function_with_argtypes cast_context
9266 : {
9267 108 : CreateCastStmt *n = makeNode(CreateCastStmt);
9268 :
9269 108 : n->sourcetype = $4;
9270 108 : n->targettype = $6;
9271 108 : n->func = $10;
9272 108 : n->context = (CoercionContext) $11;
9273 108 : n->inout = false;
9274 108 : $$ = (Node *) n;
9275 : }
9276 : | CREATE CAST '(' Typename AS Typename ')'
9277 : WITHOUT FUNCTION cast_context
9278 : {
9279 162 : CreateCastStmt *n = makeNode(CreateCastStmt);
9280 :
9281 162 : n->sourcetype = $4;
9282 162 : n->targettype = $6;
9283 162 : n->func = NULL;
9284 162 : n->context = (CoercionContext) $10;
9285 162 : n->inout = false;
9286 162 : $$ = (Node *) n;
9287 : }
9288 : | CREATE CAST '(' Typename AS Typename ')'
9289 : WITH INOUT cast_context
9290 : {
9291 8 : CreateCastStmt *n = makeNode(CreateCastStmt);
9292 :
9293 8 : n->sourcetype = $4;
9294 8 : n->targettype = $6;
9295 8 : n->func = NULL;
9296 8 : n->context = (CoercionContext) $10;
9297 8 : n->inout = true;
9298 8 : $$ = (Node *) n;
9299 : }
9300 : ;
9301 :
9302 36 : cast_context: AS IMPLICIT_P { $$ = COERCION_IMPLICIT; }
9303 58 : | AS ASSIGNMENT { $$ = COERCION_ASSIGNMENT; }
9304 184 : | /*EMPTY*/ { $$ = COERCION_EXPLICIT; }
9305 : ;
9306 :
9307 :
9308 : DropCastStmt: DROP CAST opt_if_exists '(' Typename AS Typename ')' opt_drop_behavior
9309 : {
9310 60 : DropStmt *n = makeNode(DropStmt);
9311 :
9312 60 : n->removeType = OBJECT_CAST;
9313 60 : n->objects = list_make1(list_make2($5, $7));
9314 60 : n->behavior = $9;
9315 60 : n->missing_ok = $3;
9316 60 : n->concurrent = false;
9317 60 : $$ = (Node *) n;
9318 : }
9319 : ;
9320 :
9321 36 : opt_if_exists: IF_P EXISTS { $$ = true; }
9322 38 : | /*EMPTY*/ { $$ = false; }
9323 : ;
9324 :
9325 :
9326 : /*****************************************************************************
9327 : *
9328 : * CREATE TRANSFORM / DROP TRANSFORM
9329 : *
9330 : *****************************************************************************/
9331 :
9332 : CreateTransformStmt: CREATE opt_or_replace TRANSFORM FOR Typename LANGUAGE name '(' transform_element_list ')'
9333 : {
9334 50 : CreateTransformStmt *n = makeNode(CreateTransformStmt);
9335 :
9336 50 : n->replace = $2;
9337 50 : n->type_name = $5;
9338 50 : n->lang = $7;
9339 50 : n->fromsql = linitial($9);
9340 50 : n->tosql = lsecond($9);
9341 50 : $$ = (Node *) n;
9342 : }
9343 : ;
9344 :
9345 : transform_element_list: FROM SQL_P WITH FUNCTION function_with_argtypes ',' TO SQL_P WITH FUNCTION function_with_argtypes
9346 : {
9347 44 : $$ = list_make2($5, $11);
9348 : }
9349 : | TO SQL_P WITH FUNCTION function_with_argtypes ',' FROM SQL_P WITH FUNCTION function_with_argtypes
9350 : {
9351 0 : $$ = list_make2($11, $5);
9352 : }
9353 : | FROM SQL_P WITH FUNCTION function_with_argtypes
9354 : {
9355 4 : $$ = list_make2($5, NULL);
9356 : }
9357 : | TO SQL_P WITH FUNCTION function_with_argtypes
9358 : {
9359 2 : $$ = list_make2(NULL, $5);
9360 : }
9361 : ;
9362 :
9363 :
9364 : DropTransformStmt: DROP TRANSFORM opt_if_exists FOR Typename LANGUAGE name opt_drop_behavior
9365 : {
9366 14 : DropStmt *n = makeNode(DropStmt);
9367 :
9368 14 : n->removeType = OBJECT_TRANSFORM;
9369 14 : n->objects = list_make1(list_make2($5, makeString($7)));
9370 14 : n->behavior = $8;
9371 14 : n->missing_ok = $3;
9372 14 : $$ = (Node *) n;
9373 : }
9374 : ;
9375 :
9376 :
9377 : /*****************************************************************************
9378 : *
9379 : * QUERY:
9380 : *
9381 : * REINDEX [ (options) ] {INDEX | TABLE | SCHEMA} [CONCURRENTLY] <name>
9382 : * REINDEX [ (options) ] {DATABASE | SYSTEM} [CONCURRENTLY] [<name>]
9383 : *****************************************************************************/
9384 :
9385 : ReindexStmt:
9386 : REINDEX opt_utility_option_list reindex_target_relation opt_concurrently qualified_name
9387 : {
9388 936 : ReindexStmt *n = makeNode(ReindexStmt);
9389 :
9390 936 : n->kind = $3;
9391 936 : n->relation = $5;
9392 936 : n->name = NULL;
9393 936 : n->params = $2;
9394 936 : if ($4)
9395 532 : n->params = lappend(n->params,
9396 532 : makeDefElem("concurrently", NULL, @4));
9397 936 : $$ = (Node *) n;
9398 : }
9399 : | REINDEX opt_utility_option_list SCHEMA opt_concurrently name
9400 : {
9401 114 : ReindexStmt *n = makeNode(ReindexStmt);
9402 :
9403 114 : n->kind = REINDEX_OBJECT_SCHEMA;
9404 114 : n->relation = NULL;
9405 114 : n->name = $5;
9406 114 : n->params = $2;
9407 114 : if ($4)
9408 40 : n->params = lappend(n->params,
9409 40 : makeDefElem("concurrently", NULL, @4));
9410 114 : $$ = (Node *) n;
9411 : }
9412 : | REINDEX opt_utility_option_list reindex_target_all opt_concurrently opt_single_name
9413 : {
9414 64 : ReindexStmt *n = makeNode(ReindexStmt);
9415 :
9416 64 : n->kind = $3;
9417 64 : n->relation = NULL;
9418 64 : n->name = $5;
9419 64 : n->params = $2;
9420 64 : if ($4)
9421 10 : n->params = lappend(n->params,
9422 10 : makeDefElem("concurrently", NULL, @4));
9423 64 : $$ = (Node *) n;
9424 : }
9425 : ;
9426 : reindex_target_relation:
9427 408 : INDEX { $$ = REINDEX_OBJECT_INDEX; }
9428 528 : | TABLE { $$ = REINDEX_OBJECT_TABLE; }
9429 : ;
9430 : reindex_target_all:
9431 34 : SYSTEM_P { $$ = REINDEX_OBJECT_SYSTEM; }
9432 30 : | DATABASE { $$ = REINDEX_OBJECT_DATABASE; }
9433 : ;
9434 :
9435 : /*****************************************************************************
9436 : *
9437 : * ALTER TABLESPACE
9438 : *
9439 : *****************************************************************************/
9440 :
9441 : AlterTblSpcStmt:
9442 : ALTER TABLESPACE name SET reloptions
9443 : {
9444 : AlterTableSpaceOptionsStmt *n =
9445 12 : makeNode(AlterTableSpaceOptionsStmt);
9446 :
9447 12 : n->tablespacename = $3;
9448 12 : n->options = $5;
9449 12 : n->isReset = false;
9450 12 : $$ = (Node *) n;
9451 : }
9452 : | ALTER TABLESPACE name RESET reloptions
9453 : {
9454 : AlterTableSpaceOptionsStmt *n =
9455 12 : makeNode(AlterTableSpaceOptionsStmt);
9456 :
9457 12 : n->tablespacename = $3;
9458 12 : n->options = $5;
9459 12 : n->isReset = true;
9460 12 : $$ = (Node *) n;
9461 : }
9462 : ;
9463 :
9464 : /*****************************************************************************
9465 : *
9466 : * ALTER THING name RENAME TO newname
9467 : *
9468 : *****************************************************************************/
9469 :
9470 : RenameStmt: ALTER AGGREGATE aggregate_with_argtypes RENAME TO name
9471 : {
9472 42 : RenameStmt *n = makeNode(RenameStmt);
9473 :
9474 42 : n->renameType = OBJECT_AGGREGATE;
9475 42 : n->object = (Node *) $3;
9476 42 : n->newname = $6;
9477 42 : n->missing_ok = false;
9478 42 : $$ = (Node *) n;
9479 : }
9480 : | ALTER COLLATION any_name RENAME TO name
9481 : {
9482 18 : RenameStmt *n = makeNode(RenameStmt);
9483 :
9484 18 : n->renameType = OBJECT_COLLATION;
9485 18 : n->object = (Node *) $3;
9486 18 : n->newname = $6;
9487 18 : n->missing_ok = false;
9488 18 : $$ = (Node *) n;
9489 : }
9490 : | ALTER CONVERSION_P any_name RENAME TO name
9491 : {
9492 24 : RenameStmt *n = makeNode(RenameStmt);
9493 :
9494 24 : n->renameType = OBJECT_CONVERSION;
9495 24 : n->object = (Node *) $3;
9496 24 : n->newname = $6;
9497 24 : n->missing_ok = false;
9498 24 : $$ = (Node *) n;
9499 : }
9500 : | ALTER DATABASE name RENAME TO name
9501 : {
9502 6 : RenameStmt *n = makeNode(RenameStmt);
9503 :
9504 6 : n->renameType = OBJECT_DATABASE;
9505 6 : n->subname = $3;
9506 6 : n->newname = $6;
9507 6 : n->missing_ok = false;
9508 6 : $$ = (Node *) n;
9509 : }
9510 : | ALTER DOMAIN_P any_name RENAME TO name
9511 : {
9512 6 : RenameStmt *n = makeNode(RenameStmt);
9513 :
9514 6 : n->renameType = OBJECT_DOMAIN;
9515 6 : n->object = (Node *) $3;
9516 6 : n->newname = $6;
9517 6 : n->missing_ok = false;
9518 6 : $$ = (Node *) n;
9519 : }
9520 : | ALTER DOMAIN_P any_name RENAME CONSTRAINT name TO name
9521 : {
9522 6 : RenameStmt *n = makeNode(RenameStmt);
9523 :
9524 6 : n->renameType = OBJECT_DOMCONSTRAINT;
9525 6 : n->object = (Node *) $3;
9526 6 : n->subname = $6;
9527 6 : n->newname = $8;
9528 6 : $$ = (Node *) n;
9529 : }
9530 : | ALTER FOREIGN DATA_P WRAPPER name RENAME TO name
9531 : {
9532 24 : RenameStmt *n = makeNode(RenameStmt);
9533 :
9534 24 : n->renameType = OBJECT_FDW;
9535 24 : n->object = (Node *) makeString($5);
9536 24 : n->newname = $8;
9537 24 : n->missing_ok = false;
9538 24 : $$ = (Node *) n;
9539 : }
9540 : | ALTER FUNCTION function_with_argtypes RENAME TO name
9541 : {
9542 24 : RenameStmt *n = makeNode(RenameStmt);
9543 :
9544 24 : n->renameType = OBJECT_FUNCTION;
9545 24 : n->object = (Node *) $3;
9546 24 : n->newname = $6;
9547 24 : n->missing_ok = false;
9548 24 : $$ = (Node *) n;
9549 : }
9550 : | ALTER GROUP_P RoleId RENAME TO RoleId
9551 : {
9552 0 : RenameStmt *n = makeNode(RenameStmt);
9553 :
9554 0 : n->renameType = OBJECT_ROLE;
9555 0 : n->subname = $3;
9556 0 : n->newname = $6;
9557 0 : n->missing_ok = false;
9558 0 : $$ = (Node *) n;
9559 : }
9560 : | ALTER opt_procedural LANGUAGE name RENAME TO name
9561 : {
9562 18 : RenameStmt *n = makeNode(RenameStmt);
9563 :
9564 18 : n->renameType = OBJECT_LANGUAGE;
9565 18 : n->object = (Node *) makeString($4);
9566 18 : n->newname = $7;
9567 18 : n->missing_ok = false;
9568 18 : $$ = (Node *) n;
9569 : }
9570 : | ALTER OPERATOR CLASS any_name USING name RENAME TO name
9571 : {
9572 24 : RenameStmt *n = makeNode(RenameStmt);
9573 :
9574 24 : n->renameType = OBJECT_OPCLASS;
9575 24 : n->object = (Node *) lcons(makeString($6), $4);
9576 24 : n->newname = $9;
9577 24 : n->missing_ok = false;
9578 24 : $$ = (Node *) n;
9579 : }
9580 : | ALTER OPERATOR FAMILY any_name USING name RENAME TO name
9581 : {
9582 24 : RenameStmt *n = makeNode(RenameStmt);
9583 :
9584 24 : n->renameType = OBJECT_OPFAMILY;
9585 24 : n->object = (Node *) lcons(makeString($6), $4);
9586 24 : n->newname = $9;
9587 24 : n->missing_ok = false;
9588 24 : $$ = (Node *) n;
9589 : }
9590 : | ALTER POLICY name ON qualified_name RENAME TO name
9591 : {
9592 18 : RenameStmt *n = makeNode(RenameStmt);
9593 :
9594 18 : n->renameType = OBJECT_POLICY;
9595 18 : n->relation = $5;
9596 18 : n->subname = $3;
9597 18 : n->newname = $8;
9598 18 : n->missing_ok = false;
9599 18 : $$ = (Node *) n;
9600 : }
9601 : | ALTER POLICY IF_P EXISTS name ON qualified_name RENAME TO name
9602 : {
9603 0 : RenameStmt *n = makeNode(RenameStmt);
9604 :
9605 0 : n->renameType = OBJECT_POLICY;
9606 0 : n->relation = $7;
9607 0 : n->subname = $5;
9608 0 : n->newname = $10;
9609 0 : n->missing_ok = true;
9610 0 : $$ = (Node *) n;
9611 : }
9612 : | ALTER PROCEDURE function_with_argtypes RENAME TO name
9613 : {
9614 0 : RenameStmt *n = makeNode(RenameStmt);
9615 :
9616 0 : n->renameType = OBJECT_PROCEDURE;
9617 0 : n->object = (Node *) $3;
9618 0 : n->newname = $6;
9619 0 : n->missing_ok = false;
9620 0 : $$ = (Node *) n;
9621 : }
9622 : | ALTER PUBLICATION name RENAME TO name
9623 : {
9624 42 : RenameStmt *n = makeNode(RenameStmt);
9625 :
9626 42 : n->renameType = OBJECT_PUBLICATION;
9627 42 : n->object = (Node *) makeString($3);
9628 42 : n->newname = $6;
9629 42 : n->missing_ok = false;
9630 42 : $$ = (Node *) n;
9631 : }
9632 : | ALTER ROUTINE function_with_argtypes RENAME TO name
9633 : {
9634 24 : RenameStmt *n = makeNode(RenameStmt);
9635 :
9636 24 : n->renameType = OBJECT_ROUTINE;
9637 24 : n->object = (Node *) $3;
9638 24 : n->newname = $6;
9639 24 : n->missing_ok = false;
9640 24 : $$ = (Node *) n;
9641 : }
9642 : | ALTER SCHEMA name RENAME TO name
9643 : {
9644 20 : RenameStmt *n = makeNode(RenameStmt);
9645 :
9646 20 : n->renameType = OBJECT_SCHEMA;
9647 20 : n->subname = $3;
9648 20 : n->newname = $6;
9649 20 : n->missing_ok = false;
9650 20 : $$ = (Node *) n;
9651 : }
9652 : | ALTER SERVER name RENAME TO name
9653 : {
9654 24 : RenameStmt *n = makeNode(RenameStmt);
9655 :
9656 24 : n->renameType = OBJECT_FOREIGN_SERVER;
9657 24 : n->object = (Node *) makeString($3);
9658 24 : n->newname = $6;
9659 24 : n->missing_ok = false;
9660 24 : $$ = (Node *) n;
9661 : }
9662 : | ALTER SUBSCRIPTION name RENAME TO name
9663 : {
9664 38 : RenameStmt *n = makeNode(RenameStmt);
9665 :
9666 38 : n->renameType = OBJECT_SUBSCRIPTION;
9667 38 : n->object = (Node *) makeString($3);
9668 38 : n->newname = $6;
9669 38 : n->missing_ok = false;
9670 38 : $$ = (Node *) n;
9671 : }
9672 : | ALTER TABLE relation_expr RENAME TO name
9673 : {
9674 288 : RenameStmt *n = makeNode(RenameStmt);
9675 :
9676 288 : n->renameType = OBJECT_TABLE;
9677 288 : n->relation = $3;
9678 288 : n->subname = NULL;
9679 288 : n->newname = $6;
9680 288 : n->missing_ok = false;
9681 288 : $$ = (Node *) n;
9682 : }
9683 : | ALTER TABLE IF_P EXISTS relation_expr RENAME TO name
9684 : {
9685 0 : RenameStmt *n = makeNode(RenameStmt);
9686 :
9687 0 : n->renameType = OBJECT_TABLE;
9688 0 : n->relation = $5;
9689 0 : n->subname = NULL;
9690 0 : n->newname = $8;
9691 0 : n->missing_ok = true;
9692 0 : $$ = (Node *) n;
9693 : }
9694 : | ALTER SEQUENCE qualified_name RENAME TO name
9695 : {
9696 2 : RenameStmt *n = makeNode(RenameStmt);
9697 :
9698 2 : n->renameType = OBJECT_SEQUENCE;
9699 2 : n->relation = $3;
9700 2 : n->subname = NULL;
9701 2 : n->newname = $6;
9702 2 : n->missing_ok = false;
9703 2 : $$ = (Node *) n;
9704 : }
9705 : | ALTER SEQUENCE IF_P EXISTS qualified_name RENAME TO name
9706 : {
9707 0 : RenameStmt *n = makeNode(RenameStmt);
9708 :
9709 0 : n->renameType = OBJECT_SEQUENCE;
9710 0 : n->relation = $5;
9711 0 : n->subname = NULL;
9712 0 : n->newname = $8;
9713 0 : n->missing_ok = true;
9714 0 : $$ = (Node *) n;
9715 : }
9716 : | ALTER VIEW qualified_name RENAME TO name
9717 : {
9718 6 : RenameStmt *n = makeNode(RenameStmt);
9719 :
9720 6 : n->renameType = OBJECT_VIEW;
9721 6 : n->relation = $3;
9722 6 : n->subname = NULL;
9723 6 : n->newname = $6;
9724 6 : n->missing_ok = false;
9725 6 : $$ = (Node *) n;
9726 : }
9727 : | ALTER VIEW IF_P EXISTS qualified_name RENAME TO name
9728 : {
9729 0 : RenameStmt *n = makeNode(RenameStmt);
9730 :
9731 0 : n->renameType = OBJECT_VIEW;
9732 0 : n->relation = $5;
9733 0 : n->subname = NULL;
9734 0 : n->newname = $8;
9735 0 : n->missing_ok = true;
9736 0 : $$ = (Node *) n;
9737 : }
9738 : | ALTER MATERIALIZED VIEW qualified_name RENAME TO name
9739 : {
9740 0 : RenameStmt *n = makeNode(RenameStmt);
9741 :
9742 0 : n->renameType = OBJECT_MATVIEW;
9743 0 : n->relation = $4;
9744 0 : n->subname = NULL;
9745 0 : n->newname = $7;
9746 0 : n->missing_ok = false;
9747 0 : $$ = (Node *) n;
9748 : }
9749 : | ALTER MATERIALIZED VIEW IF_P EXISTS qualified_name RENAME TO name
9750 : {
9751 0 : RenameStmt *n = makeNode(RenameStmt);
9752 :
9753 0 : n->renameType = OBJECT_MATVIEW;
9754 0 : n->relation = $6;
9755 0 : n->subname = NULL;
9756 0 : n->newname = $9;
9757 0 : n->missing_ok = true;
9758 0 : $$ = (Node *) n;
9759 : }
9760 : | ALTER INDEX qualified_name RENAME TO name
9761 : {
9762 192 : RenameStmt *n = makeNode(RenameStmt);
9763 :
9764 192 : n->renameType = OBJECT_INDEX;
9765 192 : n->relation = $3;
9766 192 : n->subname = NULL;
9767 192 : n->newname = $6;
9768 192 : n->missing_ok = false;
9769 192 : $$ = (Node *) n;
9770 : }
9771 : | ALTER INDEX IF_P EXISTS qualified_name RENAME TO name
9772 : {
9773 12 : RenameStmt *n = makeNode(RenameStmt);
9774 :
9775 12 : n->renameType = OBJECT_INDEX;
9776 12 : n->relation = $5;
9777 12 : n->subname = NULL;
9778 12 : n->newname = $8;
9779 12 : n->missing_ok = true;
9780 12 : $$ = (Node *) n;
9781 : }
9782 : | ALTER FOREIGN TABLE relation_expr RENAME TO name
9783 : {
9784 6 : RenameStmt *n = makeNode(RenameStmt);
9785 :
9786 6 : n->renameType = OBJECT_FOREIGN_TABLE;
9787 6 : n->relation = $4;
9788 6 : n->subname = NULL;
9789 6 : n->newname = $7;
9790 6 : n->missing_ok = false;
9791 6 : $$ = (Node *) n;
9792 : }
9793 : | ALTER FOREIGN TABLE IF_P EXISTS relation_expr RENAME TO name
9794 : {
9795 6 : RenameStmt *n = makeNode(RenameStmt);
9796 :
9797 6 : n->renameType = OBJECT_FOREIGN_TABLE;
9798 6 : n->relation = $6;
9799 6 : n->subname = NULL;
9800 6 : n->newname = $9;
9801 6 : n->missing_ok = true;
9802 6 : $$ = (Node *) n;
9803 : }
9804 : | ALTER TABLE relation_expr RENAME opt_column name TO name
9805 : {
9806 238 : RenameStmt *n = makeNode(RenameStmt);
9807 :
9808 238 : n->renameType = OBJECT_COLUMN;
9809 238 : n->relationType = OBJECT_TABLE;
9810 238 : n->relation = $3;
9811 238 : n->subname = $6;
9812 238 : n->newname = $8;
9813 238 : n->missing_ok = false;
9814 238 : $$ = (Node *) n;
9815 : }
9816 : | ALTER TABLE IF_P EXISTS relation_expr RENAME opt_column name TO name
9817 : {
9818 24 : RenameStmt *n = makeNode(RenameStmt);
9819 :
9820 24 : n->renameType = OBJECT_COLUMN;
9821 24 : n->relationType = OBJECT_TABLE;
9822 24 : n->relation = $5;
9823 24 : n->subname = $8;
9824 24 : n->newname = $10;
9825 24 : n->missing_ok = true;
9826 24 : $$ = (Node *) n;
9827 : }
9828 : | ALTER VIEW qualified_name RENAME opt_column name TO name
9829 : {
9830 18 : RenameStmt *n = makeNode(RenameStmt);
9831 :
9832 18 : n->renameType = OBJECT_COLUMN;
9833 18 : n->relationType = OBJECT_VIEW;
9834 18 : n->relation = $3;
9835 18 : n->subname = $6;
9836 18 : n->newname = $8;
9837 18 : n->missing_ok = false;
9838 18 : $$ = (Node *) n;
9839 : }
9840 : | ALTER VIEW IF_P EXISTS qualified_name RENAME opt_column name TO name
9841 : {
9842 0 : RenameStmt *n = makeNode(RenameStmt);
9843 :
9844 0 : n->renameType = OBJECT_COLUMN;
9845 0 : n->relationType = OBJECT_VIEW;
9846 0 : n->relation = $5;
9847 0 : n->subname = $8;
9848 0 : n->newname = $10;
9849 0 : n->missing_ok = true;
9850 0 : $$ = (Node *) n;
9851 : }
9852 : | ALTER MATERIALIZED VIEW qualified_name RENAME opt_column name TO name
9853 : {
9854 0 : RenameStmt *n = makeNode(RenameStmt);
9855 :
9856 0 : n->renameType = OBJECT_COLUMN;
9857 0 : n->relationType = OBJECT_MATVIEW;
9858 0 : n->relation = $4;
9859 0 : n->subname = $7;
9860 0 : n->newname = $9;
9861 0 : n->missing_ok = false;
9862 0 : $$ = (Node *) n;
9863 : }
9864 : | ALTER MATERIALIZED VIEW IF_P EXISTS qualified_name RENAME opt_column name TO name
9865 : {
9866 0 : RenameStmt *n = makeNode(RenameStmt);
9867 :
9868 0 : n->renameType = OBJECT_COLUMN;
9869 0 : n->relationType = OBJECT_MATVIEW;
9870 0 : n->relation = $6;
9871 0 : n->subname = $9;
9872 0 : n->newname = $11;
9873 0 : n->missing_ok = true;
9874 0 : $$ = (Node *) n;
9875 : }
9876 : | ALTER TABLE relation_expr RENAME CONSTRAINT name TO name
9877 : {
9878 72 : RenameStmt *n = makeNode(RenameStmt);
9879 :
9880 72 : n->renameType = OBJECT_TABCONSTRAINT;
9881 72 : n->relation = $3;
9882 72 : n->subname = $6;
9883 72 : n->newname = $8;
9884 72 : n->missing_ok = false;
9885 72 : $$ = (Node *) n;
9886 : }
9887 : | ALTER TABLE IF_P EXISTS relation_expr RENAME CONSTRAINT name TO name
9888 : {
9889 6 : RenameStmt *n = makeNode(RenameStmt);
9890 :
9891 6 : n->renameType = OBJECT_TABCONSTRAINT;
9892 6 : n->relation = $5;
9893 6 : n->subname = $8;
9894 6 : n->newname = $10;
9895 6 : n->missing_ok = true;
9896 6 : $$ = (Node *) n;
9897 : }
9898 : | ALTER FOREIGN TABLE relation_expr RENAME opt_column name TO name
9899 : {
9900 6 : RenameStmt *n = makeNode(RenameStmt);
9901 :
9902 6 : n->renameType = OBJECT_COLUMN;
9903 6 : n->relationType = OBJECT_FOREIGN_TABLE;
9904 6 : n->relation = $4;
9905 6 : n->subname = $7;
9906 6 : n->newname = $9;
9907 6 : n->missing_ok = false;
9908 6 : $$ = (Node *) n;
9909 : }
9910 : | ALTER FOREIGN TABLE IF_P EXISTS relation_expr RENAME opt_column name TO name
9911 : {
9912 6 : RenameStmt *n = makeNode(RenameStmt);
9913 :
9914 6 : n->renameType = OBJECT_COLUMN;
9915 6 : n->relationType = OBJECT_FOREIGN_TABLE;
9916 6 : n->relation = $6;
9917 6 : n->subname = $9;
9918 6 : n->newname = $11;
9919 6 : n->missing_ok = true;
9920 6 : $$ = (Node *) n;
9921 : }
9922 : | ALTER RULE name ON qualified_name RENAME TO name
9923 : {
9924 34 : RenameStmt *n = makeNode(RenameStmt);
9925 :
9926 34 : n->renameType = OBJECT_RULE;
9927 34 : n->relation = $5;
9928 34 : n->subname = $3;
9929 34 : n->newname = $8;
9930 34 : n->missing_ok = false;
9931 34 : $$ = (Node *) n;
9932 : }
9933 : | ALTER TRIGGER name ON qualified_name RENAME TO name
9934 : {
9935 40 : RenameStmt *n = makeNode(RenameStmt);
9936 :
9937 40 : n->renameType = OBJECT_TRIGGER;
9938 40 : n->relation = $5;
9939 40 : n->subname = $3;
9940 40 : n->newname = $8;
9941 40 : n->missing_ok = false;
9942 40 : $$ = (Node *) n;
9943 : }
9944 : | ALTER EVENT TRIGGER name RENAME TO name
9945 : {
9946 12 : RenameStmt *n = makeNode(RenameStmt);
9947 :
9948 12 : n->renameType = OBJECT_EVENT_TRIGGER;
9949 12 : n->object = (Node *) makeString($4);
9950 12 : n->newname = $7;
9951 12 : $$ = (Node *) n;
9952 : }
9953 : | ALTER ROLE RoleId RENAME TO RoleId
9954 : {
9955 32 : RenameStmt *n = makeNode(RenameStmt);
9956 :
9957 32 : n->renameType = OBJECT_ROLE;
9958 32 : n->subname = $3;
9959 32 : n->newname = $6;
9960 32 : n->missing_ok = false;
9961 32 : $$ = (Node *) n;
9962 : }
9963 : | ALTER USER RoleId RENAME TO RoleId
9964 : {
9965 0 : RenameStmt *n = makeNode(RenameStmt);
9966 :
9967 0 : n->renameType = OBJECT_ROLE;
9968 0 : n->subname = $3;
9969 0 : n->newname = $6;
9970 0 : n->missing_ok = false;
9971 0 : $$ = (Node *) n;
9972 : }
9973 : | ALTER TABLESPACE name RENAME TO name
9974 : {
9975 6 : RenameStmt *n = makeNode(RenameStmt);
9976 :
9977 6 : n->renameType = OBJECT_TABLESPACE;
9978 6 : n->subname = $3;
9979 6 : n->newname = $6;
9980 6 : n->missing_ok = false;
9981 6 : $$ = (Node *) n;
9982 : }
9983 : | ALTER STATISTICS any_name RENAME TO name
9984 : {
9985 30 : RenameStmt *n = makeNode(RenameStmt);
9986 :
9987 30 : n->renameType = OBJECT_STATISTIC_EXT;
9988 30 : n->object = (Node *) $3;
9989 30 : n->newname = $6;
9990 30 : n->missing_ok = false;
9991 30 : $$ = (Node *) n;
9992 : }
9993 : | ALTER TEXT_P SEARCH PARSER any_name RENAME TO name
9994 : {
9995 12 : RenameStmt *n = makeNode(RenameStmt);
9996 :
9997 12 : n->renameType = OBJECT_TSPARSER;
9998 12 : n->object = (Node *) $5;
9999 12 : n->newname = $8;
10000 12 : n->missing_ok = false;
10001 12 : $$ = (Node *) n;
10002 : }
10003 : | ALTER TEXT_P SEARCH DICTIONARY any_name RENAME TO name
10004 : {
10005 24 : RenameStmt *n = makeNode(RenameStmt);
10006 :
10007 24 : n->renameType = OBJECT_TSDICTIONARY;
10008 24 : n->object = (Node *) $5;
10009 24 : n->newname = $8;
10010 24 : n->missing_ok = false;
10011 24 : $$ = (Node *) n;
10012 : }
10013 : | ALTER TEXT_P SEARCH TEMPLATE any_name RENAME TO name
10014 : {
10015 12 : RenameStmt *n = makeNode(RenameStmt);
10016 :
10017 12 : n->renameType = OBJECT_TSTEMPLATE;
10018 12 : n->object = (Node *) $5;
10019 12 : n->newname = $8;
10020 12 : n->missing_ok = false;
10021 12 : $$ = (Node *) n;
10022 : }
10023 : | ALTER TEXT_P SEARCH CONFIGURATION any_name RENAME TO name
10024 : {
10025 24 : RenameStmt *n = makeNode(RenameStmt);
10026 :
10027 24 : n->renameType = OBJECT_TSCONFIGURATION;
10028 24 : n->object = (Node *) $5;
10029 24 : n->newname = $8;
10030 24 : n->missing_ok = false;
10031 24 : $$ = (Node *) n;
10032 : }
10033 : | ALTER TYPE_P any_name RENAME TO name
10034 : {
10035 26 : RenameStmt *n = makeNode(RenameStmt);
10036 :
10037 26 : n->renameType = OBJECT_TYPE;
10038 26 : n->object = (Node *) $3;
10039 26 : n->newname = $6;
10040 26 : n->missing_ok = false;
10041 26 : $$ = (Node *) n;
10042 : }
10043 : | ALTER TYPE_P any_name RENAME ATTRIBUTE name TO name opt_drop_behavior
10044 : {
10045 24 : RenameStmt *n = makeNode(RenameStmt);
10046 :
10047 24 : n->renameType = OBJECT_ATTRIBUTE;
10048 24 : n->relationType = OBJECT_TYPE;
10049 24 : n->relation = makeRangeVarFromAnyName($3, @3, yyscanner);
10050 24 : n->subname = $6;
10051 24 : n->newname = $8;
10052 24 : n->behavior = $9;
10053 24 : n->missing_ok = false;
10054 24 : $$ = (Node *) n;
10055 : }
10056 : ;
10057 :
10058 : opt_column: COLUMN
10059 : | /*EMPTY*/
10060 : ;
10061 :
10062 184 : opt_set_data: SET DATA_P { $$ = 1; }
10063 914 : | /*EMPTY*/ { $$ = 0; }
10064 : ;
10065 :
10066 : /*****************************************************************************
10067 : *
10068 : * ALTER THING name DEPENDS ON EXTENSION name
10069 : *
10070 : *****************************************************************************/
10071 :
10072 : AlterObjectDependsStmt:
10073 : ALTER FUNCTION function_with_argtypes opt_no DEPENDS ON EXTENSION name
10074 : {
10075 12 : AlterObjectDependsStmt *n = makeNode(AlterObjectDependsStmt);
10076 :
10077 12 : n->objectType = OBJECT_FUNCTION;
10078 12 : n->object = (Node *) $3;
10079 12 : n->extname = makeString($8);
10080 12 : n->remove = $4;
10081 12 : $$ = (Node *) n;
10082 : }
10083 : | ALTER PROCEDURE function_with_argtypes opt_no DEPENDS ON EXTENSION name
10084 : {
10085 0 : AlterObjectDependsStmt *n = makeNode(AlterObjectDependsStmt);
10086 :
10087 0 : n->objectType = OBJECT_PROCEDURE;
10088 0 : n->object = (Node *) $3;
10089 0 : n->extname = makeString($8);
10090 0 : n->remove = $4;
10091 0 : $$ = (Node *) n;
10092 : }
10093 : | ALTER ROUTINE function_with_argtypes opt_no DEPENDS ON EXTENSION name
10094 : {
10095 0 : AlterObjectDependsStmt *n = makeNode(AlterObjectDependsStmt);
10096 :
10097 0 : n->objectType = OBJECT_ROUTINE;
10098 0 : n->object = (Node *) $3;
10099 0 : n->extname = makeString($8);
10100 0 : n->remove = $4;
10101 0 : $$ = (Node *) n;
10102 : }
10103 : | ALTER TRIGGER name ON qualified_name opt_no DEPENDS ON EXTENSION name
10104 : {
10105 10 : AlterObjectDependsStmt *n = makeNode(AlterObjectDependsStmt);
10106 :
10107 10 : n->objectType = OBJECT_TRIGGER;
10108 10 : n->relation = $5;
10109 10 : n->object = (Node *) list_make1(makeString($3));
10110 10 : n->extname = makeString($10);
10111 10 : n->remove = $6;
10112 10 : $$ = (Node *) n;
10113 : }
10114 : | ALTER MATERIALIZED VIEW qualified_name opt_no DEPENDS ON EXTENSION name
10115 : {
10116 10 : AlterObjectDependsStmt *n = makeNode(AlterObjectDependsStmt);
10117 :
10118 10 : n->objectType = OBJECT_MATVIEW;
10119 10 : n->relation = $4;
10120 10 : n->extname = makeString($9);
10121 10 : n->remove = $5;
10122 10 : $$ = (Node *) n;
10123 : }
10124 : | ALTER INDEX qualified_name opt_no DEPENDS ON EXTENSION name
10125 : {
10126 14 : AlterObjectDependsStmt *n = makeNode(AlterObjectDependsStmt);
10127 :
10128 14 : n->objectType = OBJECT_INDEX;
10129 14 : n->relation = $3;
10130 14 : n->extname = makeString($8);
10131 14 : n->remove = $4;
10132 14 : $$ = (Node *) n;
10133 : }
10134 : ;
10135 :
10136 8 : opt_no: NO { $$ = true; }
10137 38 : | /* EMPTY */ { $$ = false; }
10138 : ;
10139 :
10140 : /*****************************************************************************
10141 : *
10142 : * ALTER THING name SET SCHEMA name
10143 : *
10144 : *****************************************************************************/
10145 :
10146 : AlterObjectSchemaStmt:
10147 : ALTER AGGREGATE aggregate_with_argtypes SET SCHEMA name
10148 : {
10149 24 : AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
10150 :
10151 24 : n->objectType = OBJECT_AGGREGATE;
10152 24 : n->object = (Node *) $3;
10153 24 : n->newschema = $6;
10154 24 : n->missing_ok = false;
10155 24 : $$ = (Node *) n;
10156 : }
10157 : | ALTER COLLATION any_name SET SCHEMA name
10158 : {
10159 6 : AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
10160 :
10161 6 : n->objectType = OBJECT_COLLATION;
10162 6 : n->object = (Node *) $3;
10163 6 : n->newschema = $6;
10164 6 : n->missing_ok = false;
10165 6 : $$ = (Node *) n;
10166 : }
10167 : | ALTER CONVERSION_P any_name SET SCHEMA name
10168 : {
10169 24 : AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
10170 :
10171 24 : n->objectType = OBJECT_CONVERSION;
10172 24 : n->object = (Node *) $3;
10173 24 : n->newschema = $6;
10174 24 : n->missing_ok = false;
10175 24 : $$ = (Node *) n;
10176 : }
10177 : | ALTER DOMAIN_P any_name SET SCHEMA name
10178 : {
10179 6 : AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
10180 :
10181 6 : n->objectType = OBJECT_DOMAIN;
10182 6 : n->object = (Node *) $3;
10183 6 : n->newschema = $6;
10184 6 : n->missing_ok = false;
10185 6 : $$ = (Node *) n;
10186 : }
10187 : | ALTER EXTENSION name SET SCHEMA name
10188 : {
10189 12 : AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
10190 :
10191 12 : n->objectType = OBJECT_EXTENSION;
10192 12 : n->object = (Node *) makeString($3);
10193 12 : n->newschema = $6;
10194 12 : n->missing_ok = false;
10195 12 : $$ = (Node *) n;
10196 : }
10197 : | ALTER FUNCTION function_with_argtypes SET SCHEMA name
10198 : {
10199 42 : AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
10200 :
10201 42 : n->objectType = OBJECT_FUNCTION;
10202 42 : n->object = (Node *) $3;
10203 42 : n->newschema = $6;
10204 42 : n->missing_ok = false;
10205 42 : $$ = (Node *) n;
10206 : }
10207 : | ALTER OPERATOR operator_with_argtypes SET SCHEMA name
10208 : {
10209 18 : AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
10210 :
10211 18 : n->objectType = OBJECT_OPERATOR;
10212 18 : n->object = (Node *) $3;
10213 18 : n->newschema = $6;
10214 18 : n->missing_ok = false;
10215 18 : $$ = (Node *) n;
10216 : }
10217 : | ALTER OPERATOR CLASS any_name USING name SET SCHEMA name
10218 : {
10219 24 : AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
10220 :
10221 24 : n->objectType = OBJECT_OPCLASS;
10222 24 : n->object = (Node *) lcons(makeString($6), $4);
10223 24 : n->newschema = $9;
10224 24 : n->missing_ok = false;
10225 24 : $$ = (Node *) n;
10226 : }
10227 : | ALTER OPERATOR FAMILY any_name USING name SET SCHEMA name
10228 : {
10229 24 : AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
10230 :
10231 24 : n->objectType = OBJECT_OPFAMILY;
10232 24 : n->object = (Node *) lcons(makeString($6), $4);
10233 24 : n->newschema = $9;
10234 24 : n->missing_ok = false;
10235 24 : $$ = (Node *) n;
10236 : }
10237 : | ALTER PROCEDURE function_with_argtypes SET SCHEMA name
10238 : {
10239 0 : AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
10240 :
10241 0 : n->objectType = OBJECT_PROCEDURE;
10242 0 : n->object = (Node *) $3;
10243 0 : n->newschema = $6;
10244 0 : n->missing_ok = false;
10245 0 : $$ = (Node *) n;
10246 : }
10247 : | ALTER ROUTINE function_with_argtypes SET SCHEMA name
10248 : {
10249 0 : AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
10250 :
10251 0 : n->objectType = OBJECT_ROUTINE;
10252 0 : n->object = (Node *) $3;
10253 0 : n->newschema = $6;
10254 0 : n->missing_ok = false;
10255 0 : $$ = (Node *) n;
10256 : }
10257 : | ALTER TABLE relation_expr SET SCHEMA name
10258 : {
10259 66 : AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
10260 :
10261 66 : n->objectType = OBJECT_TABLE;
10262 66 : n->relation = $3;
10263 66 : n->newschema = $6;
10264 66 : n->missing_ok = false;
10265 66 : $$ = (Node *) n;
10266 : }
10267 : | ALTER TABLE IF_P EXISTS relation_expr SET SCHEMA name
10268 : {
10269 12 : AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
10270 :
10271 12 : n->objectType = OBJECT_TABLE;
10272 12 : n->relation = $5;
10273 12 : n->newschema = $8;
10274 12 : n->missing_ok = true;
10275 12 : $$ = (Node *) n;
10276 : }
10277 : | ALTER STATISTICS any_name SET SCHEMA name
10278 : {
10279 18 : AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
10280 :
10281 18 : n->objectType = OBJECT_STATISTIC_EXT;
10282 18 : n->object = (Node *) $3;
10283 18 : n->newschema = $6;
10284 18 : n->missing_ok = false;
10285 18 : $$ = (Node *) n;
10286 : }
10287 : | ALTER TEXT_P SEARCH PARSER any_name SET SCHEMA name
10288 : {
10289 18 : AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
10290 :
10291 18 : n->objectType = OBJECT_TSPARSER;
10292 18 : n->object = (Node *) $5;
10293 18 : n->newschema = $8;
10294 18 : n->missing_ok = false;
10295 18 : $$ = (Node *) n;
10296 : }
10297 : | ALTER TEXT_P SEARCH DICTIONARY any_name SET SCHEMA name
10298 : {
10299 24 : AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
10300 :
10301 24 : n->objectType = OBJECT_TSDICTIONARY;
10302 24 : n->object = (Node *) $5;
10303 24 : n->newschema = $8;
10304 24 : n->missing_ok = false;
10305 24 : $$ = (Node *) n;
10306 : }
10307 : | ALTER TEXT_P SEARCH TEMPLATE any_name SET SCHEMA name
10308 : {
10309 18 : AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
10310 :
10311 18 : n->objectType = OBJECT_TSTEMPLATE;
10312 18 : n->object = (Node *) $5;
10313 18 : n->newschema = $8;
10314 18 : n->missing_ok = false;
10315 18 : $$ = (Node *) n;
10316 : }
10317 : | ALTER TEXT_P SEARCH CONFIGURATION any_name SET SCHEMA name
10318 : {
10319 24 : AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
10320 :
10321 24 : n->objectType = OBJECT_TSCONFIGURATION;
10322 24 : n->object = (Node *) $5;
10323 24 : n->newschema = $8;
10324 24 : n->missing_ok = false;
10325 24 : $$ = (Node *) n;
10326 : }
10327 : | ALTER SEQUENCE qualified_name SET SCHEMA name
10328 : {
10329 8 : AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
10330 :
10331 8 : n->objectType = OBJECT_SEQUENCE;
10332 8 : n->relation = $3;
10333 8 : n->newschema = $6;
10334 8 : n->missing_ok = false;
10335 8 : $$ = (Node *) n;
10336 : }
10337 : | ALTER SEQUENCE IF_P EXISTS qualified_name SET SCHEMA name
10338 : {
10339 0 : AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
10340 :
10341 0 : n->objectType = OBJECT_SEQUENCE;
10342 0 : n->relation = $5;
10343 0 : n->newschema = $8;
10344 0 : n->missing_ok = true;
10345 0 : $$ = (Node *) n;
10346 : }
10347 : | ALTER VIEW qualified_name SET SCHEMA name
10348 : {
10349 0 : AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
10350 :
10351 0 : n->objectType = OBJECT_VIEW;
10352 0 : n->relation = $3;
10353 0 : n->newschema = $6;
10354 0 : n->missing_ok = false;
10355 0 : $$ = (Node *) n;
10356 : }
10357 : | ALTER VIEW IF_P EXISTS qualified_name SET SCHEMA name
10358 : {
10359 0 : AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
10360 :
10361 0 : n->objectType = OBJECT_VIEW;
10362 0 : n->relation = $5;
10363 0 : n->newschema = $8;
10364 0 : n->missing_ok = true;
10365 0 : $$ = (Node *) n;
10366 : }
10367 : | ALTER MATERIALIZED VIEW qualified_name SET SCHEMA name
10368 : {
10369 6 : AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
10370 :
10371 6 : n->objectType = OBJECT_MATVIEW;
10372 6 : n->relation = $4;
10373 6 : n->newschema = $7;
10374 6 : n->missing_ok = false;
10375 6 : $$ = (Node *) n;
10376 : }
10377 : | ALTER MATERIALIZED VIEW IF_P EXISTS qualified_name SET SCHEMA name
10378 : {
10379 0 : AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
10380 :
10381 0 : n->objectType = OBJECT_MATVIEW;
10382 0 : n->relation = $6;
10383 0 : n->newschema = $9;
10384 0 : n->missing_ok = true;
10385 0 : $$ = (Node *) n;
10386 : }
10387 : | ALTER FOREIGN TABLE relation_expr SET SCHEMA name
10388 : {
10389 6 : AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
10390 :
10391 6 : n->objectType = OBJECT_FOREIGN_TABLE;
10392 6 : n->relation = $4;
10393 6 : n->newschema = $7;
10394 6 : n->missing_ok = false;
10395 6 : $$ = (Node *) n;
10396 : }
10397 : | ALTER FOREIGN TABLE IF_P EXISTS relation_expr SET SCHEMA name
10398 : {
10399 6 : AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
10400 :
10401 6 : n->objectType = OBJECT_FOREIGN_TABLE;
10402 6 : n->relation = $6;
10403 6 : n->newschema = $9;
10404 6 : n->missing_ok = true;
10405 6 : $$ = (Node *) n;
10406 : }
10407 : | ALTER TYPE_P any_name SET SCHEMA name
10408 : {
10409 12 : AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
10410 :
10411 12 : n->objectType = OBJECT_TYPE;
10412 12 : n->object = (Node *) $3;
10413 12 : n->newschema = $6;
10414 12 : n->missing_ok = false;
10415 12 : $$ = (Node *) n;
10416 : }
10417 : ;
10418 :
10419 : /*****************************************************************************
10420 : *
10421 : * ALTER OPERATOR name SET define
10422 : *
10423 : *****************************************************************************/
10424 :
10425 : AlterOperatorStmt:
10426 : ALTER OPERATOR operator_with_argtypes SET '(' operator_def_list ')'
10427 : {
10428 608 : AlterOperatorStmt *n = makeNode(AlterOperatorStmt);
10429 :
10430 608 : n->opername = $3;
10431 608 : n->options = $6;
10432 608 : $$ = (Node *) n;
10433 : }
10434 : ;
10435 :
10436 668 : operator_def_list: operator_def_elem { $$ = list_make1($1); }
10437 506 : | operator_def_list ',' operator_def_elem { $$ = lappend($1, $3); }
10438 : ;
10439 :
10440 : operator_def_elem: ColLabel '=' NONE
10441 30 : { $$ = makeDefElem($1, NULL, @1); }
10442 : | ColLabel '=' operator_def_arg
10443 1110 : { $$ = makeDefElem($1, (Node *) $3, @1); }
10444 : | ColLabel
10445 34 : { $$ = makeDefElem($1, NULL, @1); }
10446 : ;
10447 :
10448 : /* must be similar enough to def_arg to avoid reduce/reduce conflicts */
10449 : operator_def_arg:
10450 1032 : func_type { $$ = (Node *) $1; }
10451 24 : | reserved_keyword { $$ = (Node *) makeString(pstrdup($1)); }
10452 54 : | qual_all_Op { $$ = (Node *) $1; }
10453 0 : | NumericOnly { $$ = (Node *) $1; }
10454 0 : | Sconst { $$ = (Node *) makeString($1); }
10455 : ;
10456 :
10457 : /*****************************************************************************
10458 : *
10459 : * ALTER TYPE name SET define
10460 : *
10461 : * We repurpose ALTER OPERATOR's version of "definition" here
10462 : *
10463 : *****************************************************************************/
10464 :
10465 : AlterTypeStmt:
10466 : ALTER TYPE_P any_name SET '(' operator_def_list ')'
10467 : {
10468 60 : AlterTypeStmt *n = makeNode(AlterTypeStmt);
10469 :
10470 60 : n->typeName = $3;
10471 60 : n->options = $6;
10472 60 : $$ = (Node *) n;
10473 : }
10474 : ;
10475 :
10476 : /*****************************************************************************
10477 : *
10478 : * ALTER THING name OWNER TO newname
10479 : *
10480 : *****************************************************************************/
10481 :
10482 : AlterOwnerStmt: ALTER AGGREGATE aggregate_with_argtypes OWNER TO RoleSpec
10483 : {
10484 142 : AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
10485 :
10486 142 : n->objectType = OBJECT_AGGREGATE;
10487 142 : n->object = (Node *) $3;
10488 142 : n->newowner = $6;
10489 142 : $$ = (Node *) n;
10490 : }
10491 : | ALTER COLLATION any_name OWNER TO RoleSpec
10492 : {
10493 18 : AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
10494 :
10495 18 : n->objectType = OBJECT_COLLATION;
10496 18 : n->object = (Node *) $3;
10497 18 : n->newowner = $6;
10498 18 : $$ = (Node *) n;
10499 : }
10500 : | ALTER CONVERSION_P any_name OWNER TO RoleSpec
10501 : {
10502 24 : AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
10503 :
10504 24 : n->objectType = OBJECT_CONVERSION;
10505 24 : n->object = (Node *) $3;
10506 24 : n->newowner = $6;
10507 24 : $$ = (Node *) n;
10508 : }
10509 : | ALTER DATABASE name OWNER TO RoleSpec
10510 : {
10511 86 : AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
10512 :
10513 86 : n->objectType = OBJECT_DATABASE;
10514 86 : n->object = (Node *) makeString($3);
10515 86 : n->newowner = $6;
10516 86 : $$ = (Node *) n;
10517 : }
10518 : | ALTER DOMAIN_P any_name OWNER TO RoleSpec
10519 : {
10520 48 : AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
10521 :
10522 48 : n->objectType = OBJECT_DOMAIN;
10523 48 : n->object = (Node *) $3;
10524 48 : n->newowner = $6;
10525 48 : $$ = (Node *) n;
10526 : }
10527 : | ALTER FUNCTION function_with_argtypes OWNER TO RoleSpec
10528 : {
10529 586 : AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
10530 :
10531 586 : n->objectType = OBJECT_FUNCTION;
10532 586 : n->object = (Node *) $3;
10533 586 : n->newowner = $6;
10534 586 : $$ = (Node *) n;
10535 : }
10536 : | ALTER opt_procedural LANGUAGE name OWNER TO RoleSpec
10537 : {
10538 142 : AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
10539 :
10540 142 : n->objectType = OBJECT_LANGUAGE;
10541 142 : n->object = (Node *) makeString($4);
10542 142 : n->newowner = $7;
10543 142 : $$ = (Node *) n;
10544 : }
10545 : | ALTER LARGE_P OBJECT_P NumericOnly OWNER TO RoleSpec
10546 : {
10547 6 : AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
10548 :
10549 6 : n->objectType = OBJECT_LARGEOBJECT;
10550 6 : n->object = (Node *) $4;
10551 6 : n->newowner = $7;
10552 6 : $$ = (Node *) n;
10553 : }
10554 : | ALTER OPERATOR operator_with_argtypes OWNER TO RoleSpec
10555 : {
10556 46 : AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
10557 :
10558 46 : n->objectType = OBJECT_OPERATOR;
10559 46 : n->object = (Node *) $3;
10560 46 : n->newowner = $6;
10561 46 : $$ = (Node *) n;
10562 : }
10563 : | ALTER OPERATOR CLASS any_name USING name OWNER TO RoleSpec
10564 : {
10565 54 : AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
10566 :
10567 54 : n->objectType = OBJECT_OPCLASS;
10568 54 : n->object = (Node *) lcons(makeString($6), $4);
10569 54 : n->newowner = $9;
10570 54 : $$ = (Node *) n;
10571 : }
10572 : | ALTER OPERATOR FAMILY any_name USING name OWNER TO RoleSpec
10573 : {
10574 62 : AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
10575 :
10576 62 : n->objectType = OBJECT_OPFAMILY;
10577 62 : n->object = (Node *) lcons(makeString($6), $4);
10578 62 : n->newowner = $9;
10579 62 : $$ = (Node *) n;
10580 : }
10581 : | ALTER PROCEDURE function_with_argtypes OWNER TO RoleSpec
10582 : {
10583 24 : AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
10584 :
10585 24 : n->objectType = OBJECT_PROCEDURE;
10586 24 : n->object = (Node *) $3;
10587 24 : n->newowner = $6;
10588 24 : $$ = (Node *) n;
10589 : }
10590 : | ALTER ROUTINE function_with_argtypes OWNER TO RoleSpec
10591 : {
10592 0 : AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
10593 :
10594 0 : n->objectType = OBJECT_ROUTINE;
10595 0 : n->object = (Node *) $3;
10596 0 : n->newowner = $6;
10597 0 : $$ = (Node *) n;
10598 : }
10599 : | ALTER SCHEMA name OWNER TO RoleSpec
10600 : {
10601 64 : AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
10602 :
10603 64 : n->objectType = OBJECT_SCHEMA;
10604 64 : n->object = (Node *) makeString($3);
10605 64 : n->newowner = $6;
10606 64 : $$ = (Node *) n;
10607 : }
10608 : | ALTER TYPE_P any_name OWNER TO RoleSpec
10609 : {
10610 84 : AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
10611 :
10612 84 : n->objectType = OBJECT_TYPE;
10613 84 : n->object = (Node *) $3;
10614 84 : n->newowner = $6;
10615 84 : $$ = (Node *) n;
10616 : }
10617 : | ALTER TABLESPACE name OWNER TO RoleSpec
10618 : {
10619 6 : AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
10620 :
10621 6 : n->objectType = OBJECT_TABLESPACE;
10622 6 : n->object = (Node *) makeString($3);
10623 6 : n->newowner = $6;
10624 6 : $$ = (Node *) n;
10625 : }
10626 : | ALTER STATISTICS any_name OWNER TO RoleSpec
10627 : {
10628 32 : AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
10629 :
10630 32 : n->objectType = OBJECT_STATISTIC_EXT;
10631 32 : n->object = (Node *) $3;
10632 32 : n->newowner = $6;
10633 32 : $$ = (Node *) n;
10634 : }
10635 : | ALTER TEXT_P SEARCH DICTIONARY any_name OWNER TO RoleSpec
10636 : {
10637 42 : AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
10638 :
10639 42 : n->objectType = OBJECT_TSDICTIONARY;
10640 42 : n->object = (Node *) $5;
10641 42 : n->newowner = $8;
10642 42 : $$ = (Node *) n;
10643 : }
10644 : | ALTER TEXT_P SEARCH CONFIGURATION any_name OWNER TO RoleSpec
10645 : {
10646 32 : AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
10647 :
10648 32 : n->objectType = OBJECT_TSCONFIGURATION;
10649 32 : n->object = (Node *) $5;
10650 32 : n->newowner = $8;
10651 32 : $$ = (Node *) n;
10652 : }
10653 : | ALTER FOREIGN DATA_P WRAPPER name OWNER TO RoleSpec
10654 : {
10655 20 : AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
10656 :
10657 20 : n->objectType = OBJECT_FDW;
10658 20 : n->object = (Node *) makeString($5);
10659 20 : n->newowner = $8;
10660 20 : $$ = (Node *) n;
10661 : }
10662 : | ALTER SERVER name OWNER TO RoleSpec
10663 : {
10664 68 : AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
10665 :
10666 68 : n->objectType = OBJECT_FOREIGN_SERVER;
10667 68 : n->object = (Node *) makeString($3);
10668 68 : n->newowner = $6;
10669 68 : $$ = (Node *) n;
10670 : }
10671 : | ALTER EVENT TRIGGER name OWNER TO RoleSpec
10672 : {
10673 14 : AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
10674 :
10675 14 : n->objectType = OBJECT_EVENT_TRIGGER;
10676 14 : n->object = (Node *) makeString($4);
10677 14 : n->newowner = $7;
10678 14 : $$ = (Node *) n;
10679 : }
10680 : | ALTER PUBLICATION name OWNER TO RoleSpec
10681 : {
10682 36 : AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
10683 :
10684 36 : n->objectType = OBJECT_PUBLICATION;
10685 36 : n->object = (Node *) makeString($3);
10686 36 : n->newowner = $6;
10687 36 : $$ = (Node *) n;
10688 : }
10689 : | ALTER SUBSCRIPTION name OWNER TO RoleSpec
10690 : {
10691 18 : AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
10692 :
10693 18 : n->objectType = OBJECT_SUBSCRIPTION;
10694 18 : n->object = (Node *) makeString($3);
10695 18 : n->newowner = $6;
10696 18 : $$ = (Node *) n;
10697 : }
10698 : ;
10699 :
10700 :
10701 : /*****************************************************************************
10702 : *
10703 : * CREATE PUBLICATION name [WITH options]
10704 : *
10705 : * CREATE PUBLICATION FOR ALL TABLES [WITH options]
10706 : *
10707 : * CREATE PUBLICATION FOR pub_obj [, ...] [WITH options]
10708 : *
10709 : * pub_obj is one of:
10710 : *
10711 : * TABLE table [, ...]
10712 : * TABLES IN SCHEMA schema [, ...]
10713 : *
10714 : *****************************************************************************/
10715 :
10716 : CreatePublicationStmt:
10717 : CREATE PUBLICATION name opt_definition
10718 : {
10719 146 : CreatePublicationStmt *n = makeNode(CreatePublicationStmt);
10720 :
10721 146 : n->pubname = $3;
10722 146 : n->options = $4;
10723 146 : $$ = (Node *) n;
10724 : }
10725 : | CREATE PUBLICATION name FOR ALL TABLES opt_definition
10726 : {
10727 88 : CreatePublicationStmt *n = makeNode(CreatePublicationStmt);
10728 :
10729 88 : n->pubname = $3;
10730 88 : n->options = $7;
10731 88 : n->for_all_tables = true;
10732 88 : $$ = (Node *) n;
10733 : }
10734 : | CREATE PUBLICATION name FOR pub_obj_list opt_definition
10735 : {
10736 658 : CreatePublicationStmt *n = makeNode(CreatePublicationStmt);
10737 :
10738 658 : n->pubname = $3;
10739 658 : n->options = $6;
10740 658 : n->pubobjects = (List *) $5;
10741 658 : preprocess_pubobj_list(n->pubobjects, yyscanner);
10742 628 : $$ = (Node *) n;
10743 : }
10744 : ;
10745 :
10746 : /*
10747 : * FOR TABLE and FOR TABLES IN SCHEMA specifications
10748 : *
10749 : * This rule parses publication objects with and without keyword prefixes.
10750 : *
10751 : * The actual type of the object without keyword prefix depends on the previous
10752 : * one with keyword prefix. It will be preprocessed in preprocess_pubobj_list().
10753 : *
10754 : * For the object without keyword prefix, we cannot just use relation_expr here,
10755 : * because some extended expressions in relation_expr cannot be used as a
10756 : * schemaname and we cannot differentiate it. So, we extract the rules from
10757 : * relation_expr here.
10758 : */
10759 : PublicationObjSpec:
10760 : TABLE relation_expr opt_column_list OptWhereClause
10761 : {
10762 1322 : $$ = makeNode(PublicationObjSpec);
10763 1322 : $$->pubobjtype = PUBLICATIONOBJ_TABLE;
10764 1322 : $$->pubtable = makeNode(PublicationTable);
10765 1322 : $$->pubtable->relation = $2;
10766 1322 : $$->pubtable->columns = $3;
10767 1322 : $$->pubtable->whereClause = $4;
10768 : }
10769 : | TABLES IN_P SCHEMA ColId
10770 : {
10771 372 : $$ = makeNode(PublicationObjSpec);
10772 372 : $$->pubobjtype = PUBLICATIONOBJ_TABLES_IN_SCHEMA;
10773 372 : $$->name = $4;
10774 372 : $$->location = @4;
10775 : }
10776 : | TABLES IN_P SCHEMA CURRENT_SCHEMA
10777 : {
10778 18 : $$ = makeNode(PublicationObjSpec);
10779 18 : $$->pubobjtype = PUBLICATIONOBJ_TABLES_IN_CUR_SCHEMA;
10780 18 : $$->location = @4;
10781 : }
10782 : | ColId opt_column_list OptWhereClause
10783 : {
10784 130 : $$ = makeNode(PublicationObjSpec);
10785 130 : $$->pubobjtype = PUBLICATIONOBJ_CONTINUATION;
10786 : /*
10787 : * If either a row filter or column list is specified, create
10788 : * a PublicationTable object.
10789 : */
10790 130 : if ($2 || $3)
10791 : {
10792 : /*
10793 : * The OptWhereClause must be stored here but it is
10794 : * valid only for tables. For non-table objects, an
10795 : * error will be thrown later via
10796 : * preprocess_pubobj_list().
10797 : */
10798 42 : $$->pubtable = makeNode(PublicationTable);
10799 42 : $$->pubtable->relation = makeRangeVar(NULL, $1, @1);
10800 42 : $$->pubtable->columns = $2;
10801 42 : $$->pubtable->whereClause = $3;
10802 : }
10803 : else
10804 : {
10805 88 : $$->name = $1;
10806 : }
10807 130 : $$->location = @1;
10808 : }
10809 : | ColId indirection opt_column_list OptWhereClause
10810 : {
10811 32 : $$ = makeNode(PublicationObjSpec);
10812 32 : $$->pubobjtype = PUBLICATIONOBJ_CONTINUATION;
10813 32 : $$->pubtable = makeNode(PublicationTable);
10814 32 : $$->pubtable->relation = makeRangeVarFromQualifiedName($1, $2, @1, yyscanner);
10815 32 : $$->pubtable->columns = $3;
10816 32 : $$->pubtable->whereClause = $4;
10817 32 : $$->location = @1;
10818 : }
10819 : /* grammar like tablename * , ONLY tablename, ONLY ( tablename ) */
10820 : | extended_relation_expr opt_column_list OptWhereClause
10821 : {
10822 6 : $$ = makeNode(PublicationObjSpec);
10823 6 : $$->pubobjtype = PUBLICATIONOBJ_CONTINUATION;
10824 6 : $$->pubtable = makeNode(PublicationTable);
10825 6 : $$->pubtable->relation = $1;
10826 6 : $$->pubtable->columns = $2;
10827 6 : $$->pubtable->whereClause = $3;
10828 : }
10829 : | CURRENT_SCHEMA
10830 : {
10831 18 : $$ = makeNode(PublicationObjSpec);
10832 18 : $$->pubobjtype = PUBLICATIONOBJ_CONTINUATION;
10833 18 : $$->location = @1;
10834 : }
10835 : ;
10836 :
10837 : pub_obj_list: PublicationObjSpec
10838 1644 : { $$ = list_make1($1); }
10839 : | pub_obj_list ',' PublicationObjSpec
10840 254 : { $$ = lappend($1, $3); }
10841 : ;
10842 :
10843 : /*****************************************************************************
10844 : *
10845 : * ALTER PUBLICATION name SET ( options )
10846 : *
10847 : * ALTER PUBLICATION name ADD pub_obj [, ...]
10848 : *
10849 : * ALTER PUBLICATION name DROP pub_obj [, ...]
10850 : *
10851 : * ALTER PUBLICATION name SET pub_obj [, ...]
10852 : *
10853 : * pub_obj is one of:
10854 : *
10855 : * TABLE table_name [, ...]
10856 : * TABLES IN SCHEMA schema_name [, ...]
10857 : *
10858 : *****************************************************************************/
10859 :
10860 : AlterPublicationStmt:
10861 : ALTER PUBLICATION name SET definition
10862 : {
10863 116 : AlterPublicationStmt *n = makeNode(AlterPublicationStmt);
10864 :
10865 116 : n->pubname = $3;
10866 116 : n->options = $5;
10867 116 : $$ = (Node *) n;
10868 : }
10869 : | ALTER PUBLICATION name ADD_P pub_obj_list
10870 : {
10871 368 : AlterPublicationStmt *n = makeNode(AlterPublicationStmt);
10872 :
10873 368 : n->pubname = $3;
10874 368 : n->pubobjects = $5;
10875 368 : preprocess_pubobj_list(n->pubobjects, yyscanner);
10876 362 : n->action = AP_AddObjects;
10877 362 : $$ = (Node *) n;
10878 : }
10879 : | ALTER PUBLICATION name SET pub_obj_list
10880 : {
10881 464 : AlterPublicationStmt *n = makeNode(AlterPublicationStmt);
10882 :
10883 464 : n->pubname = $3;
10884 464 : n->pubobjects = $5;
10885 464 : preprocess_pubobj_list(n->pubobjects, yyscanner);
10886 464 : n->action = AP_SetObjects;
10887 464 : $$ = (Node *) n;
10888 : }
10889 : | ALTER PUBLICATION name DROP pub_obj_list
10890 : {
10891 154 : AlterPublicationStmt *n = makeNode(AlterPublicationStmt);
10892 :
10893 154 : n->pubname = $3;
10894 154 : n->pubobjects = $5;
10895 154 : preprocess_pubobj_list(n->pubobjects, yyscanner);
10896 154 : n->action = AP_DropObjects;
10897 154 : $$ = (Node *) n;
10898 : }
10899 : ;
10900 :
10901 : /*****************************************************************************
10902 : *
10903 : * CREATE SUBSCRIPTION name ...
10904 : *
10905 : *****************************************************************************/
10906 :
10907 : CreateSubscriptionStmt:
10908 : CREATE SUBSCRIPTION name CONNECTION Sconst PUBLICATION name_list opt_definition
10909 : {
10910 : CreateSubscriptionStmt *n =
10911 466 : makeNode(CreateSubscriptionStmt);
10912 466 : n->subname = $3;
10913 466 : n->conninfo = $5;
10914 466 : n->publication = $7;
10915 466 : n->options = $8;
10916 466 : $$ = (Node *) n;
10917 : }
10918 : ;
10919 :
10920 : /*****************************************************************************
10921 : *
10922 : * ALTER SUBSCRIPTION name ...
10923 : *
10924 : *****************************************************************************/
10925 :
10926 : AlterSubscriptionStmt:
10927 : ALTER SUBSCRIPTION name SET definition
10928 : {
10929 : AlterSubscriptionStmt *n =
10930 200 : makeNode(AlterSubscriptionStmt);
10931 :
10932 200 : n->kind = ALTER_SUBSCRIPTION_OPTIONS;
10933 200 : n->subname = $3;
10934 200 : n->options = $5;
10935 200 : $$ = (Node *) n;
10936 : }
10937 : | ALTER SUBSCRIPTION name CONNECTION Sconst
10938 : {
10939 : AlterSubscriptionStmt *n =
10940 26 : makeNode(AlterSubscriptionStmt);
10941 :
10942 26 : n->kind = ALTER_SUBSCRIPTION_CONNECTION;
10943 26 : n->subname = $3;
10944 26 : n->conninfo = $5;
10945 26 : $$ = (Node *) n;
10946 : }
10947 : | ALTER SUBSCRIPTION name REFRESH PUBLICATION opt_definition
10948 : {
10949 : AlterSubscriptionStmt *n =
10950 58 : makeNode(AlterSubscriptionStmt);
10951 :
10952 58 : n->kind = ALTER_SUBSCRIPTION_REFRESH;
10953 58 : n->subname = $3;
10954 58 : n->options = $6;
10955 58 : $$ = (Node *) n;
10956 : }
10957 : | ALTER SUBSCRIPTION name ADD_P PUBLICATION name_list opt_definition
10958 : {
10959 : AlterSubscriptionStmt *n =
10960 28 : makeNode(AlterSubscriptionStmt);
10961 :
10962 28 : n->kind = ALTER_SUBSCRIPTION_ADD_PUBLICATION;
10963 28 : n->subname = $3;
10964 28 : n->publication = $6;
10965 28 : n->options = $7;
10966 28 : $$ = (Node *) n;
10967 : }
10968 : | ALTER SUBSCRIPTION name DROP PUBLICATION name_list opt_definition
10969 : {
10970 : AlterSubscriptionStmt *n =
10971 26 : makeNode(AlterSubscriptionStmt);
10972 :
10973 26 : n->kind = ALTER_SUBSCRIPTION_DROP_PUBLICATION;
10974 26 : n->subname = $3;
10975 26 : n->publication = $6;
10976 26 : n->options = $7;
10977 26 : $$ = (Node *) n;
10978 : }
10979 : | ALTER SUBSCRIPTION name SET PUBLICATION name_list opt_definition
10980 : {
10981 : AlterSubscriptionStmt *n =
10982 44 : makeNode(AlterSubscriptionStmt);
10983 :
10984 44 : n->kind = ALTER_SUBSCRIPTION_SET_PUBLICATION;
10985 44 : n->subname = $3;
10986 44 : n->publication = $6;
10987 44 : n->options = $7;
10988 44 : $$ = (Node *) n;
10989 : }
10990 : | ALTER SUBSCRIPTION name ENABLE_P
10991 : {
10992 : AlterSubscriptionStmt *n =
10993 56 : makeNode(AlterSubscriptionStmt);
10994 :
10995 56 : n->kind = ALTER_SUBSCRIPTION_ENABLED;
10996 56 : n->subname = $3;
10997 56 : n->options = list_make1(makeDefElem("enabled",
10998 : (Node *) makeBoolean(true), @1));
10999 56 : $$ = (Node *) n;
11000 : }
11001 : | ALTER SUBSCRIPTION name DISABLE_P
11002 : {
11003 : AlterSubscriptionStmt *n =
11004 40 : makeNode(AlterSubscriptionStmt);
11005 :
11006 40 : n->kind = ALTER_SUBSCRIPTION_ENABLED;
11007 40 : n->subname = $3;
11008 40 : n->options = list_make1(makeDefElem("enabled",
11009 : (Node *) makeBoolean(false), @1));
11010 40 : $$ = (Node *) n;
11011 : }
11012 : | ALTER SUBSCRIPTION name SKIP definition
11013 : {
11014 : AlterSubscriptionStmt *n =
11015 24 : makeNode(AlterSubscriptionStmt);
11016 :
11017 24 : n->kind = ALTER_SUBSCRIPTION_SKIP;
11018 24 : n->subname = $3;
11019 24 : n->options = $5;
11020 24 : $$ = (Node *) n;
11021 : }
11022 : ;
11023 :
11024 : /*****************************************************************************
11025 : *
11026 : * DROP SUBSCRIPTION [ IF EXISTS ] name
11027 : *
11028 : *****************************************************************************/
11029 :
11030 : DropSubscriptionStmt: DROP SUBSCRIPTION name opt_drop_behavior
11031 : {
11032 234 : DropSubscriptionStmt *n = makeNode(DropSubscriptionStmt);
11033 :
11034 234 : n->subname = $3;
11035 234 : n->missing_ok = false;
11036 234 : n->behavior = $4;
11037 234 : $$ = (Node *) n;
11038 : }
11039 : | DROP SUBSCRIPTION IF_P EXISTS name opt_drop_behavior
11040 : {
11041 6 : DropSubscriptionStmt *n = makeNode(DropSubscriptionStmt);
11042 :
11043 6 : n->subname = $5;
11044 6 : n->missing_ok = true;
11045 6 : n->behavior = $6;
11046 6 : $$ = (Node *) n;
11047 : }
11048 : ;
11049 :
11050 : /*****************************************************************************
11051 : *
11052 : * QUERY: Define Rewrite Rule
11053 : *
11054 : *****************************************************************************/
11055 :
11056 : RuleStmt: CREATE opt_or_replace RULE name AS
11057 : ON event TO qualified_name where_clause
11058 : DO opt_instead RuleActionList
11059 : {
11060 1092 : RuleStmt *n = makeNode(RuleStmt);
11061 :
11062 1092 : n->replace = $2;
11063 1092 : n->relation = $9;
11064 1092 : n->rulename = $4;
11065 1092 : n->whereClause = $10;
11066 1092 : n->event = $7;
11067 1092 : n->instead = $12;
11068 1092 : n->actions = $13;
11069 1092 : $$ = (Node *) n;
11070 : }
11071 : ;
11072 :
11073 : RuleActionList:
11074 162 : NOTHING { $$ = NIL; }
11075 884 : | RuleActionStmt { $$ = list_make1($1); }
11076 46 : | '(' RuleActionMulti ')' { $$ = $2; }
11077 : ;
11078 :
11079 : /* the thrashing around here is to discard "empty" statements... */
11080 : RuleActionMulti:
11081 : RuleActionMulti ';' RuleActionStmtOrEmpty
11082 62 : { if ($3 != NULL)
11083 46 : $$ = lappend($1, $3);
11084 : else
11085 16 : $$ = $1;
11086 : }
11087 : | RuleActionStmtOrEmpty
11088 46 : { if ($1 != NULL)
11089 46 : $$ = list_make1($1);
11090 : else
11091 0 : $$ = NIL;
11092 : }
11093 : ;
11094 :
11095 : RuleActionStmt:
11096 : SelectStmt
11097 : | InsertStmt
11098 : | UpdateStmt
11099 : | DeleteStmt
11100 : | NotifyStmt
11101 : ;
11102 :
11103 : RuleActionStmtOrEmpty:
11104 92 : RuleActionStmt { $$ = $1; }
11105 16 : | /*EMPTY*/ { $$ = NULL; }
11106 : ;
11107 :
11108 18 : event: SELECT { $$ = CMD_SELECT; }
11109 432 : | UPDATE { $$ = CMD_UPDATE; }
11110 164 : | DELETE_P { $$ = CMD_DELETE; }
11111 478 : | INSERT { $$ = CMD_INSERT; }
11112 : ;
11113 :
11114 : opt_instead:
11115 752 : INSTEAD { $$ = true; }
11116 156 : | ALSO { $$ = false; }
11117 184 : | /*EMPTY*/ { $$ = false; }
11118 : ;
11119 :
11120 :
11121 : /*****************************************************************************
11122 : *
11123 : * QUERY:
11124 : * NOTIFY <identifier> can appear both in rule bodies and
11125 : * as a query-level command
11126 : *
11127 : *****************************************************************************/
11128 :
11129 : NotifyStmt: NOTIFY ColId notify_payload
11130 : {
11131 128 : NotifyStmt *n = makeNode(NotifyStmt);
11132 :
11133 128 : n->conditionname = $2;
11134 128 : n->payload = $3;
11135 128 : $$ = (Node *) n;
11136 : }
11137 : ;
11138 :
11139 : notify_payload:
11140 62 : ',' Sconst { $$ = $2; }
11141 66 : | /*EMPTY*/ { $$ = NULL; }
11142 : ;
11143 :
11144 : ListenStmt: LISTEN ColId
11145 : {
11146 74 : ListenStmt *n = makeNode(ListenStmt);
11147 :
11148 74 : n->conditionname = $2;
11149 74 : $$ = (Node *) n;
11150 : }
11151 : ;
11152 :
11153 : UnlistenStmt:
11154 : UNLISTEN ColId
11155 : {
11156 6 : UnlistenStmt *n = makeNode(UnlistenStmt);
11157 :
11158 6 : n->conditionname = $2;
11159 6 : $$ = (Node *) n;
11160 : }
11161 : | UNLISTEN '*'
11162 : {
11163 32 : UnlistenStmt *n = makeNode(UnlistenStmt);
11164 :
11165 32 : n->conditionname = NULL;
11166 32 : $$ = (Node *) n;
11167 : }
11168 : ;
11169 :
11170 :
11171 : /*****************************************************************************
11172 : *
11173 : * Transactions:
11174 : *
11175 : * BEGIN / COMMIT / ROLLBACK
11176 : * (also older versions END / ABORT)
11177 : *
11178 : *****************************************************************************/
11179 :
11180 : TransactionStmt:
11181 : ABORT_P opt_transaction opt_transaction_chain
11182 : {
11183 232 : TransactionStmt *n = makeNode(TransactionStmt);
11184 :
11185 232 : n->kind = TRANS_STMT_ROLLBACK;
11186 232 : n->options = NIL;
11187 232 : n->chain = $3;
11188 232 : n->location = -1;
11189 232 : $$ = (Node *) n;
11190 : }
11191 : | START TRANSACTION transaction_mode_list_or_empty
11192 : {
11193 1638 : TransactionStmt *n = makeNode(TransactionStmt);
11194 :
11195 1638 : n->kind = TRANS_STMT_START;
11196 1638 : n->options = $3;
11197 1638 : n->location = -1;
11198 1638 : $$ = (Node *) n;
11199 : }
11200 : | COMMIT opt_transaction opt_transaction_chain
11201 : {
11202 11838 : TransactionStmt *n = makeNode(TransactionStmt);
11203 :
11204 11838 : n->kind = TRANS_STMT_COMMIT;
11205 11838 : n->options = NIL;
11206 11838 : n->chain = $3;
11207 11838 : n->location = -1;
11208 11838 : $$ = (Node *) n;
11209 : }
11210 : | ROLLBACK opt_transaction opt_transaction_chain
11211 : {
11212 2650 : TransactionStmt *n = makeNode(TransactionStmt);
11213 :
11214 2650 : n->kind = TRANS_STMT_ROLLBACK;
11215 2650 : n->options = NIL;
11216 2650 : n->chain = $3;
11217 2650 : n->location = -1;
11218 2650 : $$ = (Node *) n;
11219 : }
11220 : | SAVEPOINT ColId
11221 : {
11222 1972 : TransactionStmt *n = makeNode(TransactionStmt);
11223 :
11224 1972 : n->kind = TRANS_STMT_SAVEPOINT;
11225 1972 : n->savepoint_name = $2;
11226 1972 : n->location = @2;
11227 1972 : $$ = (Node *) n;
11228 : }
11229 : | RELEASE SAVEPOINT ColId
11230 : {
11231 208 : TransactionStmt *n = makeNode(TransactionStmt);
11232 :
11233 208 : n->kind = TRANS_STMT_RELEASE;
11234 208 : n->savepoint_name = $3;
11235 208 : n->location = @3;
11236 208 : $$ = (Node *) n;
11237 : }
11238 : | RELEASE ColId
11239 : {
11240 86 : TransactionStmt *n = makeNode(TransactionStmt);
11241 :
11242 86 : n->kind = TRANS_STMT_RELEASE;
11243 86 : n->savepoint_name = $2;
11244 86 : n->location = @2;
11245 86 : $$ = (Node *) n;
11246 : }
11247 : | ROLLBACK opt_transaction TO SAVEPOINT ColId
11248 : {
11249 228 : TransactionStmt *n = makeNode(TransactionStmt);
11250 :
11251 228 : n->kind = TRANS_STMT_ROLLBACK_TO;
11252 228 : n->savepoint_name = $5;
11253 228 : n->location = @5;
11254 228 : $$ = (Node *) n;
11255 : }
11256 : | ROLLBACK opt_transaction TO ColId
11257 : {
11258 496 : TransactionStmt *n = makeNode(TransactionStmt);
11259 :
11260 496 : n->kind = TRANS_STMT_ROLLBACK_TO;
11261 496 : n->savepoint_name = $4;
11262 496 : n->location = @4;
11263 496 : $$ = (Node *) n;
11264 : }
11265 : | PREPARE TRANSACTION Sconst
11266 : {
11267 632 : TransactionStmt *n = makeNode(TransactionStmt);
11268 :
11269 632 : n->kind = TRANS_STMT_PREPARE;
11270 632 : n->gid = $3;
11271 632 : n->location = @3;
11272 632 : $$ = (Node *) n;
11273 : }
11274 : | COMMIT PREPARED Sconst
11275 : {
11276 474 : TransactionStmt *n = makeNode(TransactionStmt);
11277 :
11278 474 : n->kind = TRANS_STMT_COMMIT_PREPARED;
11279 474 : n->gid = $3;
11280 474 : n->location = @3;
11281 474 : $$ = (Node *) n;
11282 : }
11283 : | ROLLBACK PREPARED Sconst
11284 : {
11285 72 : TransactionStmt *n = makeNode(TransactionStmt);
11286 :
11287 72 : n->kind = TRANS_STMT_ROLLBACK_PREPARED;
11288 72 : n->gid = $3;
11289 72 : n->location = @3;
11290 72 : $$ = (Node *) n;
11291 : }
11292 : ;
11293 :
11294 : TransactionStmtLegacy:
11295 : BEGIN_P opt_transaction transaction_mode_list_or_empty
11296 : {
11297 14420 : TransactionStmt *n = makeNode(TransactionStmt);
11298 :
11299 14420 : n->kind = TRANS_STMT_BEGIN;
11300 14420 : n->options = $3;
11301 14420 : n->location = -1;
11302 14420 : $$ = (Node *) n;
11303 : }
11304 : | END_P opt_transaction opt_transaction_chain
11305 : {
11306 360 : TransactionStmt *n = makeNode(TransactionStmt);
11307 :
11308 360 : n->kind = TRANS_STMT_COMMIT;
11309 360 : n->options = NIL;
11310 360 : n->chain = $3;
11311 360 : n->location = -1;
11312 360 : $$ = (Node *) n;
11313 : }
11314 : ;
11315 :
11316 : opt_transaction: WORK
11317 : | TRANSACTION
11318 : | /*EMPTY*/
11319 : ;
11320 :
11321 : transaction_mode_item:
11322 : ISOLATION LEVEL iso_level
11323 6702 : { $$ = makeDefElem("transaction_isolation",
11324 6702 : makeStringConst($3, @3), @1); }
11325 : | READ ONLY
11326 1400 : { $$ = makeDefElem("transaction_read_only",
11327 1400 : makeIntConst(true, @1), @1); }
11328 : | READ WRITE
11329 90 : { $$ = makeDefElem("transaction_read_only",
11330 90 : makeIntConst(false, @1), @1); }
11331 : | DEFERRABLE
11332 44 : { $$ = makeDefElem("transaction_deferrable",
11333 : makeIntConst(true, @1), @1); }
11334 : | NOT DEFERRABLE
11335 10 : { $$ = makeDefElem("transaction_deferrable",
11336 10 : makeIntConst(false, @1), @1); }
11337 : ;
11338 :
11339 : /* Syntax with commas is SQL-spec, without commas is Postgres historical */
11340 : transaction_mode_list:
11341 : transaction_mode_item
11342 6918 : { $$ = list_make1($1); }
11343 : | transaction_mode_list ',' transaction_mode_item
11344 932 : { $$ = lappend($1, $3); }
11345 : | transaction_mode_list transaction_mode_item
11346 396 : { $$ = lappend($1, $2); }
11347 : ;
11348 :
11349 : transaction_mode_list_or_empty:
11350 : transaction_mode_list
11351 : | /* EMPTY */
11352 9732 : { $$ = NIL; }
11353 : ;
11354 :
11355 : opt_transaction_chain:
11356 120 : AND CHAIN { $$ = true; }
11357 2 : | AND NO CHAIN { $$ = false; }
11358 14958 : | /* EMPTY */ { $$ = false; }
11359 : ;
11360 :
11361 :
11362 : /*****************************************************************************
11363 : *
11364 : * QUERY:
11365 : * CREATE [ OR REPLACE ] [ TEMP ] VIEW <viewname> '('target-list ')'
11366 : * AS <query> [ WITH [ CASCADED | LOCAL ] CHECK OPTION ]
11367 : *
11368 : *****************************************************************************/
11369 :
11370 : ViewStmt: CREATE OptTemp VIEW qualified_name opt_column_list opt_reloptions
11371 : AS SelectStmt opt_check_option
11372 : {
11373 16700 : ViewStmt *n = makeNode(ViewStmt);
11374 :
11375 16700 : n->view = $4;
11376 16700 : n->view->relpersistence = $2;
11377 16700 : n->aliases = $5;
11378 16700 : n->query = $8;
11379 16700 : n->replace = false;
11380 16700 : n->options = $6;
11381 16700 : n->withCheckOption = $9;
11382 16700 : $$ = (Node *) n;
11383 : }
11384 : | CREATE OR REPLACE OptTemp VIEW qualified_name opt_column_list opt_reloptions
11385 : AS SelectStmt opt_check_option
11386 : {
11387 244 : ViewStmt *n = makeNode(ViewStmt);
11388 :
11389 244 : n->view = $6;
11390 244 : n->view->relpersistence = $4;
11391 244 : n->aliases = $7;
11392 244 : n->query = $10;
11393 244 : n->replace = true;
11394 244 : n->options = $8;
11395 244 : n->withCheckOption = $11;
11396 244 : $$ = (Node *) n;
11397 : }
11398 : | CREATE OptTemp RECURSIVE VIEW qualified_name '(' columnList ')' opt_reloptions
11399 : AS SelectStmt opt_check_option
11400 : {
11401 8 : ViewStmt *n = makeNode(ViewStmt);
11402 :
11403 8 : n->view = $5;
11404 8 : n->view->relpersistence = $2;
11405 8 : n->aliases = $7;
11406 8 : n->query = makeRecursiveViewSelect(n->view->relname, n->aliases, $11);
11407 8 : n->replace = false;
11408 8 : n->options = $9;
11409 8 : n->withCheckOption = $12;
11410 8 : if (n->withCheckOption != NO_CHECK_OPTION)
11411 0 : ereport(ERROR,
11412 : (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
11413 : errmsg("WITH CHECK OPTION not supported on recursive views"),
11414 : parser_errposition(@12)));
11415 8 : $$ = (Node *) n;
11416 : }
11417 : | CREATE OR REPLACE OptTemp RECURSIVE VIEW qualified_name '(' columnList ')' opt_reloptions
11418 : AS SelectStmt opt_check_option
11419 : {
11420 6 : ViewStmt *n = makeNode(ViewStmt);
11421 :
11422 6 : n->view = $7;
11423 6 : n->view->relpersistence = $4;
11424 6 : n->aliases = $9;
11425 6 : n->query = makeRecursiveViewSelect(n->view->relname, n->aliases, $13);
11426 6 : n->replace = true;
11427 6 : n->options = $11;
11428 6 : n->withCheckOption = $14;
11429 6 : if (n->withCheckOption != NO_CHECK_OPTION)
11430 0 : ereport(ERROR,
11431 : (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
11432 : errmsg("WITH CHECK OPTION not supported on recursive views"),
11433 : parser_errposition(@14)));
11434 6 : $$ = (Node *) n;
11435 : }
11436 : ;
11437 :
11438 : opt_check_option:
11439 96 : WITH CHECK OPTION { $$ = CASCADED_CHECK_OPTION; }
11440 6 : | WITH CASCADED CHECK OPTION { $$ = CASCADED_CHECK_OPTION; }
11441 24 : | WITH LOCAL CHECK OPTION { $$ = LOCAL_CHECK_OPTION; }
11442 16832 : | /* EMPTY */ { $$ = NO_CHECK_OPTION; }
11443 : ;
11444 :
11445 : /*****************************************************************************
11446 : *
11447 : * QUERY:
11448 : * LOAD "filename"
11449 : *
11450 : *****************************************************************************/
11451 :
11452 : LoadStmt: LOAD file_name
11453 : {
11454 54 : LoadStmt *n = makeNode(LoadStmt);
11455 :
11456 54 : n->filename = $2;
11457 54 : $$ = (Node *) n;
11458 : }
11459 : ;
11460 :
11461 :
11462 : /*****************************************************************************
11463 : *
11464 : * CREATE DATABASE
11465 : *
11466 : *****************************************************************************/
11467 :
11468 : CreatedbStmt:
11469 : CREATE DATABASE name opt_with createdb_opt_list
11470 : {
11471 796 : CreatedbStmt *n = makeNode(CreatedbStmt);
11472 :
11473 796 : n->dbname = $3;
11474 796 : n->options = $5;
11475 796 : $$ = (Node *) n;
11476 : }
11477 : ;
11478 :
11479 : createdb_opt_list:
11480 648 : createdb_opt_items { $$ = $1; }
11481 208 : | /* EMPTY */ { $$ = NIL; }
11482 : ;
11483 :
11484 : createdb_opt_items:
11485 648 : createdb_opt_item { $$ = list_make1($1); }
11486 980 : | createdb_opt_items createdb_opt_item { $$ = lappend($1, $2); }
11487 : ;
11488 :
11489 : createdb_opt_item:
11490 : createdb_opt_name opt_equal NumericOnly
11491 : {
11492 266 : $$ = makeDefElem($1, $3, @1);
11493 : }
11494 : | createdb_opt_name opt_equal opt_boolean_or_string
11495 : {
11496 1362 : $$ = makeDefElem($1, (Node *) makeString($3), @1);
11497 : }
11498 : | createdb_opt_name opt_equal DEFAULT
11499 : {
11500 0 : $$ = makeDefElem($1, NULL, @1);
11501 : }
11502 : ;
11503 :
11504 : /*
11505 : * Ideally we'd use ColId here, but that causes shift/reduce conflicts against
11506 : * the ALTER DATABASE SET/RESET syntaxes. Instead call out specific keywords
11507 : * we need, and allow IDENT so that database option names don't have to be
11508 : * parser keywords unless they are already keywords for other reasons.
11509 : *
11510 : * XXX this coding technique is fragile since if someone makes a formerly
11511 : * non-keyword option name into a keyword and forgets to add it here, the
11512 : * option will silently break. Best defense is to provide a regression test
11513 : * exercising every such option, at least at the syntax level.
11514 : */
11515 : createdb_opt_name:
11516 1136 : IDENT { $$ = $1; }
11517 2 : | CONNECTION LIMIT { $$ = pstrdup("connection_limit"); }
11518 102 : | ENCODING { $$ = pstrdup($1); }
11519 0 : | LOCATION { $$ = pstrdup($1); }
11520 2 : | OWNER { $$ = pstrdup($1); }
11521 34 : | TABLESPACE { $$ = pstrdup($1); }
11522 352 : | TEMPLATE { $$ = pstrdup($1); }
11523 : ;
11524 :
11525 : /*
11526 : * Though the equals sign doesn't match other WITH options, pg_dump uses
11527 : * equals for backward compatibility, and it doesn't seem worth removing it.
11528 : */
11529 : opt_equal: '='
11530 : | /*EMPTY*/
11531 : ;
11532 :
11533 :
11534 : /*****************************************************************************
11535 : *
11536 : * ALTER DATABASE
11537 : *
11538 : *****************************************************************************/
11539 :
11540 : AlterDatabaseStmt:
11541 : ALTER DATABASE name WITH createdb_opt_list
11542 : {
11543 0 : AlterDatabaseStmt *n = makeNode(AlterDatabaseStmt);
11544 :
11545 0 : n->dbname = $3;
11546 0 : n->options = $5;
11547 0 : $$ = (Node *) n;
11548 : }
11549 : | ALTER DATABASE name createdb_opt_list
11550 : {
11551 60 : AlterDatabaseStmt *n = makeNode(AlterDatabaseStmt);
11552 :
11553 60 : n->dbname = $3;
11554 60 : n->options = $4;
11555 60 : $$ = (Node *) n;
11556 : }
11557 : | ALTER DATABASE name SET TABLESPACE name
11558 : {
11559 16 : AlterDatabaseStmt *n = makeNode(AlterDatabaseStmt);
11560 :
11561 16 : n->dbname = $3;
11562 16 : n->options = list_make1(makeDefElem("tablespace",
11563 : (Node *) makeString($6), @6));
11564 16 : $$ = (Node *) n;
11565 : }
11566 : | ALTER DATABASE name REFRESH COLLATION VERSION_P
11567 : {
11568 6 : AlterDatabaseRefreshCollStmt *n = makeNode(AlterDatabaseRefreshCollStmt);
11569 :
11570 6 : n->dbname = $3;
11571 6 : $$ = (Node *) n;
11572 : }
11573 : ;
11574 :
11575 : AlterDatabaseSetStmt:
11576 : ALTER DATABASE name SetResetClause
11577 : {
11578 1214 : AlterDatabaseSetStmt *n = makeNode(AlterDatabaseSetStmt);
11579 :
11580 1214 : n->dbname = $3;
11581 1214 : n->setstmt = $4;
11582 1214 : $$ = (Node *) n;
11583 : }
11584 : ;
11585 :
11586 :
11587 : /*****************************************************************************
11588 : *
11589 : * DROP DATABASE [ IF EXISTS ] dbname [ [ WITH ] ( options ) ]
11590 : *
11591 : * This is implicitly CASCADE, no need for drop behavior
11592 : *****************************************************************************/
11593 :
11594 : DropdbStmt: DROP DATABASE name
11595 : {
11596 92 : DropdbStmt *n = makeNode(DropdbStmt);
11597 :
11598 92 : n->dbname = $3;
11599 92 : n->missing_ok = false;
11600 92 : n->options = NULL;
11601 92 : $$ = (Node *) n;
11602 : }
11603 : | DROP DATABASE IF_P EXISTS name
11604 : {
11605 4 : DropdbStmt *n = makeNode(DropdbStmt);
11606 :
11607 4 : n->dbname = $5;
11608 4 : n->missing_ok = true;
11609 4 : n->options = NULL;
11610 4 : $$ = (Node *) n;
11611 : }
11612 : | DROP DATABASE name opt_with '(' drop_option_list ')'
11613 : {
11614 14 : DropdbStmt *n = makeNode(DropdbStmt);
11615 :
11616 14 : n->dbname = $3;
11617 14 : n->missing_ok = false;
11618 14 : n->options = $6;
11619 14 : $$ = (Node *) n;
11620 : }
11621 : | DROP DATABASE IF_P EXISTS name opt_with '(' drop_option_list ')'
11622 : {
11623 12 : DropdbStmt *n = makeNode(DropdbStmt);
11624 :
11625 12 : n->dbname = $5;
11626 12 : n->missing_ok = true;
11627 12 : n->options = $8;
11628 12 : $$ = (Node *) n;
11629 : }
11630 : ;
11631 :
11632 : drop_option_list:
11633 : drop_option
11634 : {
11635 26 : $$ = list_make1((Node *) $1);
11636 : }
11637 : | drop_option_list ',' drop_option
11638 : {
11639 0 : $$ = lappend($1, (Node *) $3);
11640 : }
11641 : ;
11642 :
11643 : /*
11644 : * Currently only the FORCE option is supported, but the syntax is designed
11645 : * to be extensible so that we can add more options in the future if required.
11646 : */
11647 : drop_option:
11648 : FORCE
11649 : {
11650 26 : $$ = makeDefElem("force", NULL, @1);
11651 : }
11652 : ;
11653 :
11654 : /*****************************************************************************
11655 : *
11656 : * ALTER COLLATION
11657 : *
11658 : *****************************************************************************/
11659 :
11660 : AlterCollationStmt: ALTER COLLATION any_name REFRESH VERSION_P
11661 : {
11662 6 : AlterCollationStmt *n = makeNode(AlterCollationStmt);
11663 :
11664 6 : n->collname = $3;
11665 6 : $$ = (Node *) n;
11666 : }
11667 : ;
11668 :
11669 :
11670 : /*****************************************************************************
11671 : *
11672 : * ALTER SYSTEM
11673 : *
11674 : * This is used to change configuration parameters persistently.
11675 : *****************************************************************************/
11676 :
11677 : AlterSystemStmt:
11678 : ALTER SYSTEM_P SET generic_set
11679 : {
11680 130 : AlterSystemStmt *n = makeNode(AlterSystemStmt);
11681 :
11682 130 : n->setstmt = $4;
11683 130 : $$ = (Node *) n;
11684 : }
11685 : | ALTER SYSTEM_P RESET generic_reset
11686 : {
11687 56 : AlterSystemStmt *n = makeNode(AlterSystemStmt);
11688 :
11689 56 : n->setstmt = $4;
11690 56 : $$ = (Node *) n;
11691 : }
11692 : ;
11693 :
11694 :
11695 : /*****************************************************************************
11696 : *
11697 : * Manipulate a domain
11698 : *
11699 : *****************************************************************************/
11700 :
11701 : CreateDomainStmt:
11702 : CREATE DOMAIN_P any_name opt_as Typename ColQualList
11703 : {
11704 1452 : CreateDomainStmt *n = makeNode(CreateDomainStmt);
11705 :
11706 1452 : n->domainname = $3;
11707 1452 : n->typeName = $5;
11708 1452 : SplitColQualList($6, &n->constraints, &n->collClause,
11709 : yyscanner);
11710 1452 : $$ = (Node *) n;
11711 : }
11712 : ;
11713 :
11714 : AlterDomainStmt:
11715 : /* ALTER DOMAIN <domain> {SET DEFAULT <expr>|DROP DEFAULT} */
11716 : ALTER DOMAIN_P any_name alter_column_default
11717 : {
11718 14 : AlterDomainStmt *n = makeNode(AlterDomainStmt);
11719 :
11720 14 : n->subtype = AD_AlterDefault;
11721 14 : n->typeName = $3;
11722 14 : n->def = $4;
11723 14 : $$ = (Node *) n;
11724 : }
11725 : /* ALTER DOMAIN <domain> DROP NOT NULL */
11726 : | ALTER DOMAIN_P any_name DROP NOT NULL_P
11727 : {
11728 12 : AlterDomainStmt *n = makeNode(AlterDomainStmt);
11729 :
11730 12 : n->subtype = AD_DropNotNull;
11731 12 : n->typeName = $3;
11732 12 : $$ = (Node *) n;
11733 : }
11734 : /* ALTER DOMAIN <domain> SET NOT NULL */
11735 : | ALTER DOMAIN_P any_name SET NOT NULL_P
11736 : {
11737 24 : AlterDomainStmt *n = makeNode(AlterDomainStmt);
11738 :
11739 24 : n->subtype = AD_SetNotNull;
11740 24 : n->typeName = $3;
11741 24 : $$ = (Node *) n;
11742 : }
11743 : /* ALTER DOMAIN <domain> ADD CONSTRAINT ... */
11744 : | ALTER DOMAIN_P any_name ADD_P DomainConstraint
11745 : {
11746 182 : AlterDomainStmt *n = makeNode(AlterDomainStmt);
11747 :
11748 182 : n->subtype = AD_AddConstraint;
11749 182 : n->typeName = $3;
11750 182 : n->def = $5;
11751 182 : $$ = (Node *) n;
11752 : }
11753 : /* ALTER DOMAIN <domain> DROP CONSTRAINT <name> [RESTRICT|CASCADE] */
11754 : | ALTER DOMAIN_P any_name DROP CONSTRAINT name opt_drop_behavior
11755 : {
11756 54 : AlterDomainStmt *n = makeNode(AlterDomainStmt);
11757 :
11758 54 : n->subtype = AD_DropConstraint;
11759 54 : n->typeName = $3;
11760 54 : n->name = $6;
11761 54 : n->behavior = $7;
11762 54 : n->missing_ok = false;
11763 54 : $$ = (Node *) n;
11764 : }
11765 : /* ALTER DOMAIN <domain> DROP CONSTRAINT IF EXISTS <name> [RESTRICT|CASCADE] */
11766 : | ALTER DOMAIN_P any_name DROP CONSTRAINT IF_P EXISTS name opt_drop_behavior
11767 : {
11768 6 : AlterDomainStmt *n = makeNode(AlterDomainStmt);
11769 :
11770 6 : n->subtype = AD_DropConstraint;
11771 6 : n->typeName = $3;
11772 6 : n->name = $8;
11773 6 : n->behavior = $9;
11774 6 : n->missing_ok = true;
11775 6 : $$ = (Node *) n;
11776 : }
11777 : /* ALTER DOMAIN <domain> VALIDATE CONSTRAINT <name> */
11778 : | ALTER DOMAIN_P any_name VALIDATE CONSTRAINT name
11779 : {
11780 12 : AlterDomainStmt *n = makeNode(AlterDomainStmt);
11781 :
11782 12 : n->subtype = AD_ValidateConstraint;
11783 12 : n->typeName = $3;
11784 12 : n->name = $6;
11785 12 : $$ = (Node *) n;
11786 : }
11787 : ;
11788 :
11789 : opt_as: AS
11790 : | /* EMPTY */
11791 : ;
11792 :
11793 :
11794 : /*****************************************************************************
11795 : *
11796 : * Manipulate a text search dictionary or configuration
11797 : *
11798 : *****************************************************************************/
11799 :
11800 : AlterTSDictionaryStmt:
11801 : ALTER TEXT_P SEARCH DICTIONARY any_name definition
11802 : {
11803 40 : AlterTSDictionaryStmt *n = makeNode(AlterTSDictionaryStmt);
11804 :
11805 40 : n->dictname = $5;
11806 40 : n->options = $6;
11807 40 : $$ = (Node *) n;
11808 : }
11809 : ;
11810 :
11811 : AlterTSConfigurationStmt:
11812 : ALTER TEXT_P SEARCH CONFIGURATION any_name ADD_P MAPPING FOR name_list any_with any_name_list
11813 : {
11814 8518 : AlterTSConfigurationStmt *n = makeNode(AlterTSConfigurationStmt);
11815 :
11816 8518 : n->kind = ALTER_TSCONFIG_ADD_MAPPING;
11817 8518 : n->cfgname = $5;
11818 8518 : n->tokentype = $9;
11819 8518 : n->dicts = $11;
11820 8518 : n->override = false;
11821 8518 : n->replace = false;
11822 8518 : $$ = (Node *) n;
11823 : }
11824 : | ALTER TEXT_P SEARCH CONFIGURATION any_name ALTER MAPPING FOR name_list any_with any_name_list
11825 : {
11826 26 : AlterTSConfigurationStmt *n = makeNode(AlterTSConfigurationStmt);
11827 :
11828 26 : n->kind = ALTER_TSCONFIG_ALTER_MAPPING_FOR_TOKEN;
11829 26 : n->cfgname = $5;
11830 26 : n->tokentype = $9;
11831 26 : n->dicts = $11;
11832 26 : n->override = true;
11833 26 : n->replace = false;
11834 26 : $$ = (Node *) n;
11835 : }
11836 : | ALTER TEXT_P SEARCH CONFIGURATION any_name ALTER MAPPING REPLACE any_name any_with any_name
11837 : {
11838 18 : AlterTSConfigurationStmt *n = makeNode(AlterTSConfigurationStmt);
11839 :
11840 18 : n->kind = ALTER_TSCONFIG_REPLACE_DICT;
11841 18 : n->cfgname = $5;
11842 18 : n->tokentype = NIL;
11843 18 : n->dicts = list_make2($9,$11);
11844 18 : n->override = false;
11845 18 : n->replace = true;
11846 18 : $$ = (Node *) n;
11847 : }
11848 : | ALTER TEXT_P SEARCH CONFIGURATION any_name ALTER MAPPING FOR name_list REPLACE any_name any_with any_name
11849 : {
11850 0 : AlterTSConfigurationStmt *n = makeNode(AlterTSConfigurationStmt);
11851 :
11852 0 : n->kind = ALTER_TSCONFIG_REPLACE_DICT_FOR_TOKEN;
11853 0 : n->cfgname = $5;
11854 0 : n->tokentype = $9;
11855 0 : n->dicts = list_make2($11,$13);
11856 0 : n->override = false;
11857 0 : n->replace = true;
11858 0 : $$ = (Node *) n;
11859 : }
11860 : | ALTER TEXT_P SEARCH CONFIGURATION any_name DROP MAPPING FOR name_list
11861 : {
11862 18 : AlterTSConfigurationStmt *n = makeNode(AlterTSConfigurationStmt);
11863 :
11864 18 : n->kind = ALTER_TSCONFIG_DROP_MAPPING;
11865 18 : n->cfgname = $5;
11866 18 : n->tokentype = $9;
11867 18 : n->missing_ok = false;
11868 18 : $$ = (Node *) n;
11869 : }
11870 : | ALTER TEXT_P SEARCH CONFIGURATION any_name DROP MAPPING IF_P EXISTS FOR name_list
11871 : {
11872 12 : AlterTSConfigurationStmt *n = makeNode(AlterTSConfigurationStmt);
11873 :
11874 12 : n->kind = ALTER_TSCONFIG_DROP_MAPPING;
11875 12 : n->cfgname = $5;
11876 12 : n->tokentype = $11;
11877 12 : n->missing_ok = true;
11878 12 : $$ = (Node *) n;
11879 : }
11880 : ;
11881 :
11882 : /* Use this if TIME or ORDINALITY after WITH should be taken as an identifier */
11883 : any_with: WITH
11884 : | WITH_LA
11885 : ;
11886 :
11887 :
11888 : /*****************************************************************************
11889 : *
11890 : * Manipulate a conversion
11891 : *
11892 : * CREATE [DEFAULT] CONVERSION <conversion_name>
11893 : * FOR <encoding_name> TO <encoding_name> FROM <func_name>
11894 : *
11895 : *****************************************************************************/
11896 :
11897 : CreateConversionStmt:
11898 : CREATE opt_default CONVERSION_P any_name FOR Sconst
11899 : TO Sconst FROM any_name
11900 : {
11901 64 : CreateConversionStmt *n = makeNode(CreateConversionStmt);
11902 :
11903 64 : n->conversion_name = $4;
11904 64 : n->for_encoding_name = $6;
11905 64 : n->to_encoding_name = $8;
11906 64 : n->func_name = $10;
11907 64 : n->def = $2;
11908 64 : $$ = (Node *) n;
11909 : }
11910 : ;
11911 :
11912 : /*****************************************************************************
11913 : *
11914 : * QUERY:
11915 : * CLUSTER (options) [ <qualified_name> [ USING <index_name> ] ]
11916 : * CLUSTER [VERBOSE] [ <qualified_name> [ USING <index_name> ] ]
11917 : * CLUSTER [VERBOSE] <index_name> ON <qualified_name> (for pre-8.3)
11918 : *
11919 : *****************************************************************************/
11920 :
11921 : ClusterStmt:
11922 : CLUSTER '(' utility_option_list ')' qualified_name cluster_index_specification
11923 : {
11924 0 : ClusterStmt *n = makeNode(ClusterStmt);
11925 :
11926 0 : n->relation = $5;
11927 0 : n->indexname = $6;
11928 0 : n->params = $3;
11929 0 : $$ = (Node *) n;
11930 : }
11931 : | CLUSTER opt_utility_option_list
11932 : {
11933 16 : ClusterStmt *n = makeNode(ClusterStmt);
11934 :
11935 16 : n->relation = NULL;
11936 16 : n->indexname = NULL;
11937 16 : n->params = $2;
11938 16 : $$ = (Node *) n;
11939 : }
11940 : /* unparenthesized VERBOSE kept for pre-14 compatibility */
11941 : | CLUSTER opt_verbose qualified_name cluster_index_specification
11942 : {
11943 186 : ClusterStmt *n = makeNode(ClusterStmt);
11944 :
11945 186 : n->relation = $3;
11946 186 : n->indexname = $4;
11947 186 : if ($2)
11948 0 : n->params = list_make1(makeDefElem("verbose", NULL, @2));
11949 186 : $$ = (Node *) n;
11950 : }
11951 : /* unparenthesized VERBOSE kept for pre-17 compatibility */
11952 : | CLUSTER VERBOSE
11953 : {
11954 4 : ClusterStmt *n = makeNode(ClusterStmt);
11955 :
11956 4 : n->relation = NULL;
11957 4 : n->indexname = NULL;
11958 4 : n->params = list_make1(makeDefElem("verbose", NULL, @2));
11959 4 : $$ = (Node *) n;
11960 : }
11961 : /* kept for pre-8.3 compatibility */
11962 : | CLUSTER opt_verbose name ON qualified_name
11963 : {
11964 18 : ClusterStmt *n = makeNode(ClusterStmt);
11965 :
11966 18 : n->relation = $5;
11967 18 : n->indexname = $3;
11968 18 : if ($2)
11969 0 : n->params = list_make1(makeDefElem("verbose", NULL, @2));
11970 18 : $$ = (Node *) n;
11971 : }
11972 : ;
11973 :
11974 : cluster_index_specification:
11975 156 : USING name { $$ = $2; }
11976 30 : | /*EMPTY*/ { $$ = NULL; }
11977 : ;
11978 :
11979 :
11980 : /*****************************************************************************
11981 : *
11982 : * QUERY:
11983 : * VACUUM
11984 : * ANALYZE
11985 : *
11986 : *****************************************************************************/
11987 :
11988 : VacuumStmt: VACUUM opt_full opt_freeze opt_verbose opt_analyze opt_vacuum_relation_list
11989 : {
11990 1232 : VacuumStmt *n = makeNode(VacuumStmt);
11991 :
11992 1232 : n->options = NIL;
11993 1232 : if ($2)
11994 152 : n->options = lappend(n->options,
11995 152 : makeDefElem("full", NULL, @2));
11996 1232 : if ($3)
11997 162 : n->options = lappend(n->options,
11998 162 : makeDefElem("freeze", NULL, @3));
11999 1232 : if ($4)
12000 16 : n->options = lappend(n->options,
12001 16 : makeDefElem("verbose", NULL, @4));
12002 1232 : if ($5)
12003 292 : n->options = lappend(n->options,
12004 292 : makeDefElem("analyze", NULL, @5));
12005 1232 : n->rels = $6;
12006 1232 : n->is_vacuumcmd = true;
12007 1232 : $$ = (Node *) n;
12008 : }
12009 : | VACUUM '(' utility_option_list ')' opt_vacuum_relation_list
12010 : {
12011 7648 : VacuumStmt *n = makeNode(VacuumStmt);
12012 :
12013 7648 : n->options = $3;
12014 7648 : n->rels = $5;
12015 7648 : n->is_vacuumcmd = true;
12016 7648 : $$ = (Node *) n;
12017 : }
12018 : ;
12019 :
12020 : AnalyzeStmt: analyze_keyword opt_utility_option_list opt_vacuum_relation_list
12021 : {
12022 4698 : VacuumStmt *n = makeNode(VacuumStmt);
12023 :
12024 4698 : n->options = $2;
12025 4698 : n->rels = $3;
12026 4698 : n->is_vacuumcmd = false;
12027 4698 : $$ = (Node *) n;
12028 : }
12029 : | analyze_keyword VERBOSE opt_vacuum_relation_list
12030 : {
12031 0 : VacuumStmt *n = makeNode(VacuumStmt);
12032 :
12033 0 : n->options = list_make1(makeDefElem("verbose", NULL, @2));
12034 0 : n->rels = $3;
12035 0 : n->is_vacuumcmd = false;
12036 0 : $$ = (Node *) n;
12037 : }
12038 : ;
12039 :
12040 : analyze_keyword:
12041 : ANALYZE
12042 : | ANALYSE /* British */
12043 : ;
12044 :
12045 : opt_analyze:
12046 292 : analyze_keyword { $$ = true; }
12047 940 : | /*EMPTY*/ { $$ = false; }
12048 : ;
12049 :
12050 : opt_verbose:
12051 16 : VERBOSE { $$ = true; }
12052 3724 : | /*EMPTY*/ { $$ = false; }
12053 : ;
12054 :
12055 152 : opt_full: FULL { $$ = true; }
12056 1080 : | /*EMPTY*/ { $$ = false; }
12057 : ;
12058 :
12059 162 : opt_freeze: FREEZE { $$ = true; }
12060 1070 : | /*EMPTY*/ { $$ = false; }
12061 : ;
12062 :
12063 : opt_name_list:
12064 2850 : '(' name_list ')' { $$ = $2; }
12065 15790 : | /*EMPTY*/ { $$ = NIL; }
12066 : ;
12067 :
12068 : vacuum_relation:
12069 : relation_expr opt_name_list
12070 : {
12071 13358 : $$ = (Node *) makeVacuumRelation($1, InvalidOid, $2);
12072 : }
12073 : ;
12074 :
12075 : vacuum_relation_list:
12076 : vacuum_relation
12077 13194 : { $$ = list_make1($1); }
12078 : | vacuum_relation_list ',' vacuum_relation
12079 164 : { $$ = lappend($1, $3); }
12080 : ;
12081 :
12082 : opt_vacuum_relation_list:
12083 13194 : vacuum_relation_list { $$ = $1; }
12084 384 : | /*EMPTY*/ { $$ = NIL; }
12085 : ;
12086 :
12087 :
12088 : /*****************************************************************************
12089 : *
12090 : * QUERY:
12091 : * EXPLAIN [ANALYZE] [VERBOSE] query
12092 : * EXPLAIN ( options ) query
12093 : *
12094 : *****************************************************************************/
12095 :
12096 : ExplainStmt:
12097 : EXPLAIN ExplainableStmt
12098 : {
12099 7718 : ExplainStmt *n = makeNode(ExplainStmt);
12100 :
12101 7718 : n->query = $2;
12102 7718 : n->options = NIL;
12103 7718 : $$ = (Node *) n;
12104 : }
12105 : | EXPLAIN analyze_keyword opt_verbose ExplainableStmt
12106 : {
12107 2304 : ExplainStmt *n = makeNode(ExplainStmt);
12108 :
12109 2304 : n->query = $4;
12110 2304 : n->options = list_make1(makeDefElem("analyze", NULL, @2));
12111 2304 : if ($3)
12112 0 : n->options = lappend(n->options,
12113 0 : makeDefElem("verbose", NULL, @3));
12114 2304 : $$ = (Node *) n;
12115 : }
12116 : | EXPLAIN VERBOSE ExplainableStmt
12117 : {
12118 12 : ExplainStmt *n = makeNode(ExplainStmt);
12119 :
12120 12 : n->query = $3;
12121 12 : n->options = list_make1(makeDefElem("verbose", NULL, @2));
12122 12 : $$ = (Node *) n;
12123 : }
12124 : | EXPLAIN '(' utility_option_list ')' ExplainableStmt
12125 : {
12126 13990 : ExplainStmt *n = makeNode(ExplainStmt);
12127 :
12128 13990 : n->query = $5;
12129 13990 : n->options = $3;
12130 13990 : $$ = (Node *) n;
12131 : }
12132 : ;
12133 :
12134 : ExplainableStmt:
12135 : SelectStmt
12136 : | InsertStmt
12137 : | UpdateStmt
12138 : | DeleteStmt
12139 : | MergeStmt
12140 : | DeclareCursorStmt
12141 : | CreateAsStmt
12142 : | CreateMatViewStmt
12143 : | RefreshMatViewStmt
12144 : | ExecuteStmt /* by default all are $$=$1 */
12145 : ;
12146 :
12147 : /*****************************************************************************
12148 : *
12149 : * QUERY:
12150 : * PREPARE <plan_name> [(args, ...)] AS <query>
12151 : *
12152 : *****************************************************************************/
12153 :
12154 : PrepareStmt: PREPARE name prep_type_clause AS PreparableStmt
12155 : {
12156 1958 : PrepareStmt *n = makeNode(PrepareStmt);
12157 :
12158 1958 : n->name = $2;
12159 1958 : n->argtypes = $3;
12160 1958 : n->query = $5;
12161 1958 : $$ = (Node *) n;
12162 : }
12163 : ;
12164 :
12165 1646 : prep_type_clause: '(' type_list ')' { $$ = $2; }
12166 330 : | /* EMPTY */ { $$ = NIL; }
12167 : ;
12168 :
12169 : PreparableStmt:
12170 : SelectStmt
12171 : | InsertStmt
12172 : | UpdateStmt
12173 : | DeleteStmt
12174 : | MergeStmt /* by default all are $$=$1 */
12175 : ;
12176 :
12177 : /*****************************************************************************
12178 : *
12179 : * EXECUTE <plan_name> [(params, ...)]
12180 : * CREATE TABLE <name> AS EXECUTE <plan_name> [(params, ...)]
12181 : *
12182 : *****************************************************************************/
12183 :
12184 : ExecuteStmt: EXECUTE name execute_param_clause
12185 : {
12186 16302 : ExecuteStmt *n = makeNode(ExecuteStmt);
12187 :
12188 16302 : n->name = $2;
12189 16302 : n->params = $3;
12190 16302 : $$ = (Node *) n;
12191 : }
12192 : | CREATE OptTemp TABLE create_as_target AS
12193 : EXECUTE name execute_param_clause opt_with_data
12194 : {
12195 76 : CreateTableAsStmt *ctas = makeNode(CreateTableAsStmt);
12196 76 : ExecuteStmt *n = makeNode(ExecuteStmt);
12197 :
12198 76 : n->name = $7;
12199 76 : n->params = $8;
12200 76 : ctas->query = (Node *) n;
12201 76 : ctas->into = $4;
12202 76 : ctas->objtype = OBJECT_TABLE;
12203 76 : ctas->is_select_into = false;
12204 76 : ctas->if_not_exists = false;
12205 : /* cram additional flags into the IntoClause */
12206 76 : $4->rel->relpersistence = $2;
12207 76 : $4->skipData = !($9);
12208 76 : $$ = (Node *) ctas;
12209 : }
12210 : | CREATE OptTemp TABLE IF_P NOT EXISTS create_as_target AS
12211 : EXECUTE name execute_param_clause opt_with_data
12212 : {
12213 12 : CreateTableAsStmt *ctas = makeNode(CreateTableAsStmt);
12214 12 : ExecuteStmt *n = makeNode(ExecuteStmt);
12215 :
12216 12 : n->name = $10;
12217 12 : n->params = $11;
12218 12 : ctas->query = (Node *) n;
12219 12 : ctas->into = $7;
12220 12 : ctas->objtype = OBJECT_TABLE;
12221 12 : ctas->is_select_into = false;
12222 12 : ctas->if_not_exists = true;
12223 : /* cram additional flags into the IntoClause */
12224 12 : $7->rel->relpersistence = $2;
12225 12 : $7->skipData = !($12);
12226 12 : $$ = (Node *) ctas;
12227 : }
12228 : ;
12229 :
12230 15248 : execute_param_clause: '(' expr_list ')' { $$ = $2; }
12231 1142 : | /* EMPTY */ { $$ = NIL; }
12232 : ;
12233 :
12234 : /*****************************************************************************
12235 : *
12236 : * QUERY:
12237 : * DEALLOCATE [PREPARE] <plan_name>
12238 : *
12239 : *****************************************************************************/
12240 :
12241 : DeallocateStmt: DEALLOCATE name
12242 : {
12243 3996 : DeallocateStmt *n = makeNode(DeallocateStmt);
12244 :
12245 3996 : n->name = $2;
12246 3996 : n->isall = false;
12247 3996 : n->location = @2;
12248 3996 : $$ = (Node *) n;
12249 : }
12250 : | DEALLOCATE PREPARE name
12251 : {
12252 20 : DeallocateStmt *n = makeNode(DeallocateStmt);
12253 :
12254 20 : n->name = $3;
12255 20 : n->isall = false;
12256 20 : n->location = @3;
12257 20 : $$ = (Node *) n;
12258 : }
12259 : | DEALLOCATE ALL
12260 : {
12261 70 : DeallocateStmt *n = makeNode(DeallocateStmt);
12262 :
12263 70 : n->name = NULL;
12264 70 : n->isall = true;
12265 70 : n->location = -1;
12266 70 : $$ = (Node *) n;
12267 : }
12268 : | DEALLOCATE PREPARE ALL
12269 : {
12270 2 : DeallocateStmt *n = makeNode(DeallocateStmt);
12271 :
12272 2 : n->name = NULL;
12273 2 : n->isall = true;
12274 2 : n->location = -1;
12275 2 : $$ = (Node *) n;
12276 : }
12277 : ;
12278 :
12279 : /*****************************************************************************
12280 : *
12281 : * QUERY:
12282 : * INSERT STATEMENTS
12283 : *
12284 : *****************************************************************************/
12285 :
12286 : InsertStmt:
12287 : opt_with_clause INSERT INTO insert_target insert_rest
12288 : opt_on_conflict returning_clause
12289 : {
12290 68374 : $5->relation = $4;
12291 68374 : $5->onConflictClause = $6;
12292 68374 : $5->returningClause = $7;
12293 68374 : $5->withClause = $1;
12294 68374 : $$ = (Node *) $5;
12295 : }
12296 : ;
12297 :
12298 : /*
12299 : * Can't easily make AS optional here, because VALUES in insert_rest would
12300 : * have a shift/reduce conflict with VALUES as an optional alias. We could
12301 : * easily allow unreserved_keywords as optional aliases, but that'd be an odd
12302 : * divergence from other places. So just require AS for now.
12303 : */
12304 : insert_target:
12305 : qualified_name
12306 : {
12307 68248 : $$ = $1;
12308 : }
12309 : | qualified_name AS ColId
12310 : {
12311 132 : $1->alias = makeAlias($3, NIL);
12312 132 : $$ = $1;
12313 : }
12314 : ;
12315 :
12316 : insert_rest:
12317 : SelectStmt
12318 : {
12319 43180 : $$ = makeNode(InsertStmt);
12320 43180 : $$->cols = NIL;
12321 43180 : $$->selectStmt = $1;
12322 : }
12323 : | OVERRIDING override_kind VALUE_P SelectStmt
12324 : {
12325 96 : $$ = makeNode(InsertStmt);
12326 96 : $$->cols = NIL;
12327 96 : $$->override = $2;
12328 96 : $$->selectStmt = $4;
12329 : }
12330 : | '(' insert_column_list ')' SelectStmt
12331 : {
12332 14296 : $$ = makeNode(InsertStmt);
12333 14296 : $$->cols = $2;
12334 14296 : $$->selectStmt = $4;
12335 : }
12336 : | '(' insert_column_list ')' OVERRIDING override_kind VALUE_P SelectStmt
12337 : {
12338 0 : $$ = makeNode(InsertStmt);
12339 0 : $$->cols = $2;
12340 0 : $$->override = $5;
12341 0 : $$->selectStmt = $7;
12342 : }
12343 : | DEFAULT VALUES
12344 : {
12345 10808 : $$ = makeNode(InsertStmt);
12346 10808 : $$->cols = NIL;
12347 10808 : $$->selectStmt = NULL;
12348 : }
12349 : ;
12350 :
12351 : override_kind:
12352 66 : USER { $$ = OVERRIDING_USER_VALUE; }
12353 60 : | SYSTEM_P { $$ = OVERRIDING_SYSTEM_VALUE; }
12354 : ;
12355 :
12356 : insert_column_list:
12357 : insert_column_item
12358 14624 : { $$ = list_make1($1); }
12359 : | insert_column_list ',' insert_column_item
12360 16142 : { $$ = lappend($1, $3); }
12361 : ;
12362 :
12363 : insert_column_item:
12364 : ColId opt_indirection
12365 : {
12366 30766 : $$ = makeNode(ResTarget);
12367 30766 : $$->name = $1;
12368 30766 : $$->indirection = check_indirection($2, yyscanner);
12369 30766 : $$->val = NULL;
12370 30766 : $$->location = @1;
12371 : }
12372 : ;
12373 :
12374 : opt_on_conflict:
12375 : ON CONFLICT opt_conf_expr DO UPDATE SET set_clause_list where_clause
12376 : {
12377 1302 : $$ = makeNode(OnConflictClause);
12378 1302 : $$->action = ONCONFLICT_UPDATE;
12379 1302 : $$->infer = $3;
12380 1302 : $$->targetList = $7;
12381 1302 : $$->whereClause = $8;
12382 1302 : $$->location = @1;
12383 : }
12384 : |
12385 : ON CONFLICT opt_conf_expr DO NOTHING
12386 : {
12387 550 : $$ = makeNode(OnConflictClause);
12388 550 : $$->action = ONCONFLICT_NOTHING;
12389 550 : $$->infer = $3;
12390 550 : $$->targetList = NIL;
12391 550 : $$->whereClause = NULL;
12392 550 : $$->location = @1;
12393 : }
12394 : | /*EMPTY*/
12395 : {
12396 66528 : $$ = NULL;
12397 : }
12398 : ;
12399 :
12400 : opt_conf_expr:
12401 : '(' index_params ')' where_clause
12402 : {
12403 1426 : $$ = makeNode(InferClause);
12404 1426 : $$->indexElems = $2;
12405 1426 : $$->whereClause = $4;
12406 1426 : $$->conname = NULL;
12407 1426 : $$->location = @1;
12408 : }
12409 : |
12410 : ON CONSTRAINT name
12411 : {
12412 192 : $$ = makeNode(InferClause);
12413 192 : $$->indexElems = NIL;
12414 192 : $$->whereClause = NULL;
12415 192 : $$->conname = $3;
12416 192 : $$->location = @1;
12417 : }
12418 : | /*EMPTY*/
12419 : {
12420 234 : $$ = NULL;
12421 : }
12422 : ;
12423 :
12424 : returning_clause:
12425 : RETURNING returning_with_clause target_list
12426 : {
12427 3148 : ReturningClause *n = makeNode(ReturningClause);
12428 :
12429 3148 : n->options = $2;
12430 3148 : n->exprs = $3;
12431 3148 : $$ = n;
12432 : }
12433 : | /* EMPTY */
12434 : {
12435 86064 : $$ = NULL;
12436 : }
12437 : ;
12438 :
12439 : returning_with_clause:
12440 72 : WITH '(' returning_options ')' { $$ = $3; }
12441 3076 : | /* EMPTY */ { $$ = NIL; }
12442 : ;
12443 :
12444 : returning_options:
12445 72 : returning_option { $$ = list_make1($1); }
12446 54 : | returning_options ',' returning_option { $$ = lappend($1, $3); }
12447 : ;
12448 :
12449 : returning_option:
12450 : returning_option_kind AS ColId
12451 : {
12452 126 : ReturningOption *n = makeNode(ReturningOption);
12453 :
12454 126 : n->option = $1;
12455 126 : n->value = $3;
12456 126 : n->location = @1;
12457 126 : $$ = (Node *) n;
12458 : }
12459 : ;
12460 :
12461 : returning_option_kind:
12462 54 : OLD { $$ = RETURNING_OPTION_OLD; }
12463 72 : | NEW { $$ = RETURNING_OPTION_NEW; }
12464 : ;
12465 :
12466 :
12467 : /*****************************************************************************
12468 : *
12469 : * QUERY:
12470 : * DELETE STATEMENTS
12471 : *
12472 : *****************************************************************************/
12473 :
12474 : DeleteStmt: opt_with_clause DELETE_P FROM relation_expr_opt_alias
12475 : using_clause where_or_current_clause returning_clause
12476 : {
12477 4648 : DeleteStmt *n = makeNode(DeleteStmt);
12478 :
12479 4648 : n->relation = $4;
12480 4648 : n->usingClause = $5;
12481 4648 : n->whereClause = $6;
12482 4648 : n->returningClause = $7;
12483 4648 : n->withClause = $1;
12484 4648 : $$ = (Node *) n;
12485 : }
12486 : ;
12487 :
12488 : using_clause:
12489 108 : USING from_list { $$ = $2; }
12490 4540 : | /*EMPTY*/ { $$ = NIL; }
12491 : ;
12492 :
12493 :
12494 : /*****************************************************************************
12495 : *
12496 : * QUERY:
12497 : * LOCK TABLE
12498 : *
12499 : *****************************************************************************/
12500 :
12501 : LockStmt: LOCK_P opt_table relation_expr_list opt_lock opt_nowait
12502 : {
12503 1186 : LockStmt *n = makeNode(LockStmt);
12504 :
12505 1186 : n->relations = $3;
12506 1186 : n->mode = $4;
12507 1186 : n->nowait = $5;
12508 1186 : $$ = (Node *) n;
12509 : }
12510 : ;
12511 :
12512 1078 : opt_lock: IN_P lock_type MODE { $$ = $2; }
12513 108 : | /*EMPTY*/ { $$ = AccessExclusiveLock; }
12514 : ;
12515 :
12516 588 : lock_type: ACCESS SHARE { $$ = AccessShareLock; }
12517 14 : | ROW SHARE { $$ = RowShareLock; }
12518 88 : | ROW EXCLUSIVE { $$ = RowExclusiveLock; }
12519 66 : | SHARE UPDATE EXCLUSIVE { $$ = ShareUpdateExclusiveLock; }
12520 80 : | SHARE { $$ = ShareLock; }
12521 14 : | SHARE ROW EXCLUSIVE { $$ = ShareRowExclusiveLock; }
12522 102 : | EXCLUSIVE { $$ = ExclusiveLock; }
12523 126 : | ACCESS EXCLUSIVE { $$ = AccessExclusiveLock; }
12524 : ;
12525 :
12526 334 : opt_nowait: NOWAIT { $$ = true; }
12527 882 : | /*EMPTY*/ { $$ = false; }
12528 : ;
12529 :
12530 : opt_nowait_or_skip:
12531 50 : NOWAIT { $$ = LockWaitError; }
12532 190 : | SKIP LOCKED { $$ = LockWaitSkip; }
12533 5004 : | /*EMPTY*/ { $$ = LockWaitBlock; }
12534 : ;
12535 :
12536 :
12537 : /*****************************************************************************
12538 : *
12539 : * QUERY:
12540 : * UpdateStmt (UPDATE)
12541 : *
12542 : *****************************************************************************/
12543 :
12544 : UpdateStmt: opt_with_clause UPDATE relation_expr_opt_alias
12545 : SET set_clause_list
12546 : from_clause
12547 : where_or_current_clause
12548 : returning_clause
12549 : {
12550 14108 : UpdateStmt *n = makeNode(UpdateStmt);
12551 :
12552 14108 : n->relation = $3;
12553 14108 : n->targetList = $5;
12554 14108 : n->fromClause = $6;
12555 14108 : n->whereClause = $7;
12556 14108 : n->returningClause = $8;
12557 14108 : n->withClause = $1;
12558 14108 : $$ = (Node *) n;
12559 : }
12560 : ;
12561 :
12562 : set_clause_list:
12563 16960 : set_clause { $$ = $1; }
12564 4150 : | set_clause_list ',' set_clause { $$ = list_concat($1,$3); }
12565 : ;
12566 :
12567 : set_clause:
12568 : set_target '=' a_expr
12569 : {
12570 20926 : $1->val = (Node *) $3;
12571 20926 : $$ = list_make1($1);
12572 : }
12573 : | '(' set_target_list ')' '=' a_expr
12574 : {
12575 184 : int ncolumns = list_length($2);
12576 184 : int i = 1;
12577 : ListCell *col_cell;
12578 :
12579 : /* Create a MultiAssignRef source for each target */
12580 568 : foreach(col_cell, $2)
12581 : {
12582 384 : ResTarget *res_col = (ResTarget *) lfirst(col_cell);
12583 384 : MultiAssignRef *r = makeNode(MultiAssignRef);
12584 :
12585 384 : r->source = (Node *) $5;
12586 384 : r->colno = i;
12587 384 : r->ncolumns = ncolumns;
12588 384 : res_col->val = (Node *) r;
12589 384 : i++;
12590 : }
12591 :
12592 184 : $$ = $2;
12593 : }
12594 : ;
12595 :
12596 : set_target:
12597 : ColId opt_indirection
12598 : {
12599 21316 : $$ = makeNode(ResTarget);
12600 21316 : $$->name = $1;
12601 21316 : $$->indirection = check_indirection($2, yyscanner);
12602 21316 : $$->val = NULL; /* upper production sets this */
12603 21316 : $$->location = @1;
12604 : }
12605 : ;
12606 :
12607 : set_target_list:
12608 190 : set_target { $$ = list_make1($1); }
12609 200 : | set_target_list ',' set_target { $$ = lappend($1,$3); }
12610 : ;
12611 :
12612 :
12613 : /*****************************************************************************
12614 : *
12615 : * QUERY:
12616 : * MERGE
12617 : *
12618 : *****************************************************************************/
12619 :
12620 : MergeStmt:
12621 : opt_with_clause MERGE INTO relation_expr_opt_alias
12622 : USING table_ref
12623 : ON a_expr
12624 : merge_when_list
12625 : returning_clause
12626 : {
12627 2082 : MergeStmt *m = makeNode(MergeStmt);
12628 :
12629 2082 : m->withClause = $1;
12630 2082 : m->relation = $4;
12631 2082 : m->sourceRelation = $6;
12632 2082 : m->joinCondition = $8;
12633 2082 : m->mergeWhenClauses = $9;
12634 2082 : m->returningClause = $10;
12635 :
12636 2082 : $$ = (Node *) m;
12637 : }
12638 : ;
12639 :
12640 : merge_when_list:
12641 2082 : merge_when_clause { $$ = list_make1($1); }
12642 1164 : | merge_when_list merge_when_clause { $$ = lappend($1,$2); }
12643 : ;
12644 :
12645 : /*
12646 : * A WHEN clause may be WHEN MATCHED, WHEN NOT MATCHED BY SOURCE, or WHEN NOT
12647 : * MATCHED [BY TARGET]. The first two cases match target tuples, and support
12648 : * UPDATE/DELETE/DO NOTHING actions. The third case does not match target
12649 : * tuples, and only supports INSERT/DO NOTHING actions.
12650 : */
12651 : merge_when_clause:
12652 : merge_when_tgt_matched opt_merge_when_condition THEN merge_update
12653 : {
12654 1550 : $4->matchKind = $1;
12655 1550 : $4->condition = $2;
12656 :
12657 1550 : $$ = (Node *) $4;
12658 : }
12659 : | merge_when_tgt_matched opt_merge_when_condition THEN merge_delete
12660 : {
12661 518 : $4->matchKind = $1;
12662 518 : $4->condition = $2;
12663 :
12664 518 : $$ = (Node *) $4;
12665 : }
12666 : | merge_when_tgt_not_matched opt_merge_when_condition THEN merge_insert
12667 : {
12668 1094 : $4->matchKind = $1;
12669 1094 : $4->condition = $2;
12670 :
12671 1094 : $$ = (Node *) $4;
12672 : }
12673 : | merge_when_tgt_matched opt_merge_when_condition THEN DO NOTHING
12674 : {
12675 64 : MergeWhenClause *m = makeNode(MergeWhenClause);
12676 :
12677 64 : m->matchKind = $1;
12678 64 : m->commandType = CMD_NOTHING;
12679 64 : m->condition = $2;
12680 :
12681 64 : $$ = (Node *) m;
12682 : }
12683 : | merge_when_tgt_not_matched opt_merge_when_condition THEN DO NOTHING
12684 : {
12685 20 : MergeWhenClause *m = makeNode(MergeWhenClause);
12686 :
12687 20 : m->matchKind = $1;
12688 20 : m->commandType = CMD_NOTHING;
12689 20 : m->condition = $2;
12690 :
12691 20 : $$ = (Node *) m;
12692 : }
12693 : ;
12694 :
12695 : merge_when_tgt_matched:
12696 1970 : WHEN MATCHED { $$ = MERGE_WHEN_MATCHED; }
12697 180 : | WHEN NOT MATCHED BY SOURCE { $$ = MERGE_WHEN_NOT_MATCHED_BY_SOURCE; }
12698 : ;
12699 :
12700 : merge_when_tgt_not_matched:
12701 1120 : WHEN NOT MATCHED { $$ = MERGE_WHEN_NOT_MATCHED_BY_TARGET; }
12702 18 : | WHEN NOT MATCHED BY TARGET { $$ = MERGE_WHEN_NOT_MATCHED_BY_TARGET; }
12703 : ;
12704 :
12705 : opt_merge_when_condition:
12706 808 : AND a_expr { $$ = $2; }
12707 2480 : | { $$ = NULL; }
12708 : ;
12709 :
12710 : merge_update:
12711 : UPDATE SET set_clause_list
12712 : {
12713 1550 : MergeWhenClause *n = makeNode(MergeWhenClause);
12714 1550 : n->commandType = CMD_UPDATE;
12715 1550 : n->override = OVERRIDING_NOT_SET;
12716 1550 : n->targetList = $3;
12717 1550 : n->values = NIL;
12718 :
12719 1550 : $$ = n;
12720 : }
12721 : ;
12722 :
12723 : merge_delete:
12724 : DELETE_P
12725 : {
12726 518 : MergeWhenClause *n = makeNode(MergeWhenClause);
12727 518 : n->commandType = CMD_DELETE;
12728 518 : n->override = OVERRIDING_NOT_SET;
12729 518 : n->targetList = NIL;
12730 518 : n->values = NIL;
12731 :
12732 518 : $$ = n;
12733 : }
12734 : ;
12735 :
12736 : merge_insert:
12737 : INSERT merge_values_clause
12738 : {
12739 730 : MergeWhenClause *n = makeNode(MergeWhenClause);
12740 730 : n->commandType = CMD_INSERT;
12741 730 : n->override = OVERRIDING_NOT_SET;
12742 730 : n->targetList = NIL;
12743 730 : n->values = $2;
12744 730 : $$ = n;
12745 : }
12746 : | INSERT OVERRIDING override_kind VALUE_P merge_values_clause
12747 : {
12748 0 : MergeWhenClause *n = makeNode(MergeWhenClause);
12749 0 : n->commandType = CMD_INSERT;
12750 0 : n->override = $3;
12751 0 : n->targetList = NIL;
12752 0 : n->values = $5;
12753 0 : $$ = n;
12754 : }
12755 : | INSERT '(' insert_column_list ')' merge_values_clause
12756 : {
12757 298 : MergeWhenClause *n = makeNode(MergeWhenClause);
12758 298 : n->commandType = CMD_INSERT;
12759 298 : n->override = OVERRIDING_NOT_SET;
12760 298 : n->targetList = $3;
12761 298 : n->values = $5;
12762 298 : $$ = n;
12763 : }
12764 : | INSERT '(' insert_column_list ')' OVERRIDING override_kind VALUE_P merge_values_clause
12765 : {
12766 30 : MergeWhenClause *n = makeNode(MergeWhenClause);
12767 30 : n->commandType = CMD_INSERT;
12768 30 : n->override = $6;
12769 30 : n->targetList = $3;
12770 30 : n->values = $8;
12771 30 : $$ = n;
12772 : }
12773 : | INSERT DEFAULT VALUES
12774 : {
12775 36 : MergeWhenClause *n = makeNode(MergeWhenClause);
12776 36 : n->commandType = CMD_INSERT;
12777 36 : n->override = OVERRIDING_NOT_SET;
12778 36 : n->targetList = NIL;
12779 36 : n->values = NIL;
12780 36 : $$ = n;
12781 : }
12782 : ;
12783 :
12784 : merge_values_clause:
12785 : VALUES '(' expr_list ')'
12786 : {
12787 1058 : $$ = $3;
12788 : }
12789 : ;
12790 :
12791 : /*****************************************************************************
12792 : *
12793 : * QUERY:
12794 : * CURSOR STATEMENTS
12795 : *
12796 : *****************************************************************************/
12797 : DeclareCursorStmt: DECLARE cursor_name cursor_options CURSOR opt_hold FOR SelectStmt
12798 : {
12799 4608 : DeclareCursorStmt *n = makeNode(DeclareCursorStmt);
12800 :
12801 4608 : n->portalname = $2;
12802 : /* currently we always set FAST_PLAN option */
12803 4608 : n->options = $3 | $5 | CURSOR_OPT_FAST_PLAN;
12804 4608 : n->query = $7;
12805 4608 : $$ = (Node *) n;
12806 : }
12807 : ;
12808 :
12809 14818 : cursor_name: name { $$ = $1; }
12810 : ;
12811 :
12812 4608 : cursor_options: /*EMPTY*/ { $$ = 0; }
12813 28 : | cursor_options NO SCROLL { $$ = $1 | CURSOR_OPT_NO_SCROLL; }
12814 240 : | cursor_options SCROLL { $$ = $1 | CURSOR_OPT_SCROLL; }
12815 14 : | cursor_options BINARY { $$ = $1 | CURSOR_OPT_BINARY; }
12816 0 : | cursor_options ASENSITIVE { $$ = $1 | CURSOR_OPT_ASENSITIVE; }
12817 6 : | cursor_options INSENSITIVE { $$ = $1 | CURSOR_OPT_INSENSITIVE; }
12818 : ;
12819 :
12820 4510 : opt_hold: /* EMPTY */ { $$ = 0; }
12821 92 : | WITH HOLD { $$ = CURSOR_OPT_HOLD; }
12822 6 : | WITHOUT HOLD { $$ = 0; }
12823 : ;
12824 :
12825 : /*****************************************************************************
12826 : *
12827 : * QUERY:
12828 : * SELECT STATEMENTS
12829 : *
12830 : *****************************************************************************/
12831 :
12832 : /* A complete SELECT statement looks like this.
12833 : *
12834 : * The rule returns either a single SelectStmt node or a tree of them,
12835 : * representing a set-operation tree.
12836 : *
12837 : * There is an ambiguity when a sub-SELECT is within an a_expr and there
12838 : * are excess parentheses: do the parentheses belong to the sub-SELECT or
12839 : * to the surrounding a_expr? We don't really care, but bison wants to know.
12840 : * To resolve the ambiguity, we are careful to define the grammar so that
12841 : * the decision is staved off as long as possible: as long as we can keep
12842 : * absorbing parentheses into the sub-SELECT, we will do so, and only when
12843 : * it's no longer possible to do that will we decide that parens belong to
12844 : * the expression. For example, in "SELECT (((SELECT 2)) + 3)" the extra
12845 : * parentheses are treated as part of the sub-select. The necessity of doing
12846 : * it that way is shown by "SELECT (((SELECT 2)) UNION SELECT 2)". Had we
12847 : * parsed "((SELECT 2))" as an a_expr, it'd be too late to go back to the
12848 : * SELECT viewpoint when we see the UNION.
12849 : *
12850 : * This approach is implemented by defining a nonterminal select_with_parens,
12851 : * which represents a SELECT with at least one outer layer of parentheses,
12852 : * and being careful to use select_with_parens, never '(' SelectStmt ')',
12853 : * in the expression grammar. We will then have shift-reduce conflicts
12854 : * which we can resolve in favor of always treating '(' <select> ')' as
12855 : * a select_with_parens. To resolve the conflicts, the productions that
12856 : * conflict with the select_with_parens productions are manually given
12857 : * precedences lower than the precedence of ')', thereby ensuring that we
12858 : * shift ')' (and then reduce to select_with_parens) rather than trying to
12859 : * reduce the inner <select> nonterminal to something else. We use UMINUS
12860 : * precedence for this, which is a fairly arbitrary choice.
12861 : *
12862 : * To be able to define select_with_parens itself without ambiguity, we need
12863 : * a nonterminal select_no_parens that represents a SELECT structure with no
12864 : * outermost parentheses. This is a little bit tedious, but it works.
12865 : *
12866 : * In non-expression contexts, we use SelectStmt which can represent a SELECT
12867 : * with or without outer parentheses.
12868 : */
12869 :
12870 : SelectStmt: select_no_parens %prec UMINUS
12871 : | select_with_parens %prec UMINUS
12872 : ;
12873 :
12874 : select_with_parens:
12875 64532 : '(' select_no_parens ')' { $$ = $2; }
12876 156 : | '(' select_with_parens ')' { $$ = $2; }
12877 : ;
12878 :
12879 : /*
12880 : * This rule parses the equivalent of the standard's <query expression>.
12881 : * The duplicative productions are annoying, but hard to get rid of without
12882 : * creating shift/reduce conflicts.
12883 : *
12884 : * The locking clause (FOR UPDATE etc) may be before or after LIMIT/OFFSET.
12885 : * In <=7.2.X, LIMIT/OFFSET had to be after FOR UPDATE
12886 : * We now support both orderings, but prefer LIMIT/OFFSET before the locking
12887 : * clause.
12888 : * 2002-08-28 bjm
12889 : */
12890 : select_no_parens:
12891 387376 : simple_select { $$ = $1; }
12892 : | select_clause sort_clause
12893 : {
12894 70308 : insertSelectOptions((SelectStmt *) $1, $2, NIL,
12895 : NULL, NULL,
12896 : yyscanner);
12897 70308 : $$ = $1;
12898 : }
12899 : | select_clause opt_sort_clause for_locking_clause opt_select_limit
12900 : {
12901 4796 : insertSelectOptions((SelectStmt *) $1, $2, $3,
12902 4796 : $4,
12903 : NULL,
12904 : yyscanner);
12905 4796 : $$ = $1;
12906 : }
12907 : | select_clause opt_sort_clause select_limit opt_for_locking_clause
12908 : {
12909 4902 : insertSelectOptions((SelectStmt *) $1, $2, $4,
12910 4902 : $3,
12911 : NULL,
12912 : yyscanner);
12913 4890 : $$ = $1;
12914 : }
12915 : | with_clause select_clause
12916 : {
12917 2182 : insertSelectOptions((SelectStmt *) $2, NULL, NIL,
12918 : NULL,
12919 2182 : $1,
12920 : yyscanner);
12921 2182 : $$ = $2;
12922 : }
12923 : | with_clause select_clause sort_clause
12924 : {
12925 604 : insertSelectOptions((SelectStmt *) $2, $3, NIL,
12926 : NULL,
12927 604 : $1,
12928 : yyscanner);
12929 604 : $$ = $2;
12930 : }
12931 : | with_clause select_clause opt_sort_clause for_locking_clause opt_select_limit
12932 : {
12933 6 : insertSelectOptions((SelectStmt *) $2, $3, $4,
12934 6 : $5,
12935 6 : $1,
12936 : yyscanner);
12937 6 : $$ = $2;
12938 : }
12939 : | with_clause select_clause opt_sort_clause select_limit opt_for_locking_clause
12940 : {
12941 64 : insertSelectOptions((SelectStmt *) $2, $3, $5,
12942 64 : $4,
12943 64 : $1,
12944 : yyscanner);
12945 64 : $$ = $2;
12946 : }
12947 : ;
12948 :
12949 : select_clause:
12950 120870 : simple_select { $$ = $1; }
12951 588 : | select_with_parens { $$ = $1; }
12952 : ;
12953 :
12954 : /*
12955 : * This rule parses SELECT statements that can appear within set operations,
12956 : * including UNION, INTERSECT and EXCEPT. '(' and ')' can be used to specify
12957 : * the ordering of the set operations. Without '(' and ')' we want the
12958 : * operations to be ordered per the precedence specs at the head of this file.
12959 : *
12960 : * As with select_no_parens, simple_select cannot have outer parentheses,
12961 : * but can have parenthesized subclauses.
12962 : *
12963 : * It might appear that we could fold the first two alternatives into one
12964 : * by using opt_distinct_clause. However, that causes a shift/reduce conflict
12965 : * against INSERT ... SELECT ... ON CONFLICT. We avoid the ambiguity by
12966 : * requiring SELECT DISTINCT [ON] to be followed by a non-empty target_list.
12967 : *
12968 : * Note that sort clauses cannot be included at this level --- SQL requires
12969 : * SELECT foo UNION SELECT bar ORDER BY baz
12970 : * to be parsed as
12971 : * (SELECT foo UNION SELECT bar) ORDER BY baz
12972 : * not
12973 : * SELECT foo UNION (SELECT bar ORDER BY baz)
12974 : * Likewise for WITH, FOR UPDATE and LIMIT. Therefore, those clauses are
12975 : * described as part of the select_no_parens production, not simple_select.
12976 : * This does not limit functionality, because you can reintroduce these
12977 : * clauses inside parentheses.
12978 : *
12979 : * NOTE: only the leftmost component SelectStmt should have INTO.
12980 : * However, this is not checked by the grammar; parse analysis must check it.
12981 : */
12982 : simple_select:
12983 : SELECT opt_all_clause opt_target_list
12984 : into_clause from_clause where_clause
12985 : group_clause having_clause window_clause
12986 : {
12987 426172 : SelectStmt *n = makeNode(SelectStmt);
12988 :
12989 426172 : n->targetList = $3;
12990 426172 : n->intoClause = $4;
12991 426172 : n->fromClause = $5;
12992 426172 : n->whereClause = $6;
12993 426172 : n->groupClause = ($7)->list;
12994 426172 : n->groupDistinct = ($7)->distinct;
12995 426172 : n->havingClause = $8;
12996 426172 : n->windowClause = $9;
12997 426172 : $$ = (Node *) n;
12998 : }
12999 : | SELECT distinct_clause target_list
13000 : into_clause from_clause where_clause
13001 : group_clause having_clause window_clause
13002 : {
13003 3658 : SelectStmt *n = makeNode(SelectStmt);
13004 :
13005 3658 : n->distinctClause = $2;
13006 3658 : n->targetList = $3;
13007 3658 : n->intoClause = $4;
13008 3658 : n->fromClause = $5;
13009 3658 : n->whereClause = $6;
13010 3658 : n->groupClause = ($7)->list;
13011 3658 : n->groupDistinct = ($7)->distinct;
13012 3658 : n->havingClause = $8;
13013 3658 : n->windowClause = $9;
13014 3658 : $$ = (Node *) n;
13015 : }
13016 58816 : | values_clause { $$ = $1; }
13017 : | TABLE relation_expr
13018 : {
13019 : /* same as SELECT * FROM relation_expr */
13020 308 : ColumnRef *cr = makeNode(ColumnRef);
13021 308 : ResTarget *rt = makeNode(ResTarget);
13022 308 : SelectStmt *n = makeNode(SelectStmt);
13023 :
13024 308 : cr->fields = list_make1(makeNode(A_Star));
13025 308 : cr->location = -1;
13026 :
13027 308 : rt->name = NULL;
13028 308 : rt->indirection = NIL;
13029 308 : rt->val = (Node *) cr;
13030 308 : rt->location = -1;
13031 :
13032 308 : n->targetList = list_make1(rt);
13033 308 : n->fromClause = list_make1($2);
13034 308 : $$ = (Node *) n;
13035 : }
13036 : | select_clause UNION set_quantifier select_clause
13037 : {
13038 18558 : $$ = makeSetOp(SETOP_UNION, $3 == SET_QUANTIFIER_ALL, $1, $4);
13039 : }
13040 : | select_clause INTERSECT set_quantifier select_clause
13041 : {
13042 258 : $$ = makeSetOp(SETOP_INTERSECT, $3 == SET_QUANTIFIER_ALL, $1, $4);
13043 : }
13044 : | select_clause EXCEPT set_quantifier select_clause
13045 : {
13046 476 : $$ = makeSetOp(SETOP_EXCEPT, $3 == SET_QUANTIFIER_ALL, $1, $4);
13047 : }
13048 : ;
13049 :
13050 : /*
13051 : * SQL standard WITH clause looks like:
13052 : *
13053 : * WITH [ RECURSIVE ] <query name> [ (<column>,...) ]
13054 : * AS (query) [ SEARCH or CYCLE clause ]
13055 : *
13056 : * Recognizing WITH_LA here allows a CTE to be named TIME or ORDINALITY.
13057 : */
13058 : with_clause:
13059 : WITH cte_list
13060 : {
13061 2062 : $$ = makeNode(WithClause);
13062 2062 : $$->ctes = $2;
13063 2062 : $$->recursive = false;
13064 2062 : $$->location = @1;
13065 : }
13066 : | WITH_LA cte_list
13067 : {
13068 6 : $$ = makeNode(WithClause);
13069 6 : $$->ctes = $2;
13070 6 : $$->recursive = false;
13071 6 : $$->location = @1;
13072 : }
13073 : | WITH RECURSIVE cte_list
13074 : {
13075 1238 : $$ = makeNode(WithClause);
13076 1238 : $$->ctes = $3;
13077 1238 : $$->recursive = true;
13078 1238 : $$->location = @1;
13079 : }
13080 : ;
13081 :
13082 : cte_list:
13083 3306 : common_table_expr { $$ = list_make1($1); }
13084 1252 : | cte_list ',' common_table_expr { $$ = lappend($1, $3); }
13085 : ;
13086 :
13087 : common_table_expr: name opt_name_list AS opt_materialized '(' PreparableStmt ')' opt_search_clause opt_cycle_clause
13088 : {
13089 4558 : CommonTableExpr *n = makeNode(CommonTableExpr);
13090 :
13091 4558 : n->ctename = $1;
13092 4558 : n->aliascolnames = $2;
13093 4558 : n->ctematerialized = $4;
13094 4558 : n->ctequery = $6;
13095 4558 : n->search_clause = castNode(CTESearchClause, $8);
13096 4558 : n->cycle_clause = castNode(CTECycleClause, $9);
13097 4558 : n->location = @1;
13098 4558 : $$ = (Node *) n;
13099 : }
13100 : ;
13101 :
13102 : opt_materialized:
13103 178 : MATERIALIZED { $$ = CTEMaterializeAlways; }
13104 48 : | NOT MATERIALIZED { $$ = CTEMaterializeNever; }
13105 4332 : | /*EMPTY*/ { $$ = CTEMaterializeDefault; }
13106 : ;
13107 :
13108 : opt_search_clause:
13109 : SEARCH DEPTH FIRST_P BY columnList SET ColId
13110 : {
13111 90 : CTESearchClause *n = makeNode(CTESearchClause);
13112 :
13113 90 : n->search_col_list = $5;
13114 90 : n->search_breadth_first = false;
13115 90 : n->search_seq_column = $7;
13116 90 : n->location = @1;
13117 90 : $$ = (Node *) n;
13118 : }
13119 : | SEARCH BREADTH FIRST_P BY columnList SET ColId
13120 : {
13121 36 : CTESearchClause *n = makeNode(CTESearchClause);
13122 :
13123 36 : n->search_col_list = $5;
13124 36 : n->search_breadth_first = true;
13125 36 : n->search_seq_column = $7;
13126 36 : n->location = @1;
13127 36 : $$ = (Node *) n;
13128 : }
13129 : | /*EMPTY*/
13130 : {
13131 4432 : $$ = NULL;
13132 : }
13133 : ;
13134 :
13135 : opt_cycle_clause:
13136 : CYCLE columnList SET ColId TO AexprConst DEFAULT AexprConst USING ColId
13137 : {
13138 66 : CTECycleClause *n = makeNode(CTECycleClause);
13139 :
13140 66 : n->cycle_col_list = $2;
13141 66 : n->cycle_mark_column = $4;
13142 66 : n->cycle_mark_value = $6;
13143 66 : n->cycle_mark_default = $8;
13144 66 : n->cycle_path_column = $10;
13145 66 : n->location = @1;
13146 66 : $$ = (Node *) n;
13147 : }
13148 : | CYCLE columnList SET ColId USING ColId
13149 : {
13150 60 : CTECycleClause *n = makeNode(CTECycleClause);
13151 :
13152 60 : n->cycle_col_list = $2;
13153 60 : n->cycle_mark_column = $4;
13154 60 : n->cycle_mark_value = makeBoolAConst(true, -1);
13155 60 : n->cycle_mark_default = makeBoolAConst(false, -1);
13156 60 : n->cycle_path_column = $6;
13157 60 : n->location = @1;
13158 60 : $$ = (Node *) n;
13159 : }
13160 : | /*EMPTY*/
13161 : {
13162 4432 : $$ = NULL;
13163 : }
13164 : ;
13165 :
13166 : opt_with_clause:
13167 450 : with_clause { $$ = $1; }
13168 88878 : | /*EMPTY*/ { $$ = NULL; }
13169 : ;
13170 :
13171 : into_clause:
13172 : INTO OptTempTableName
13173 : {
13174 138 : $$ = makeNode(IntoClause);
13175 138 : $$->rel = $2;
13176 138 : $$->colNames = NIL;
13177 138 : $$->options = NIL;
13178 138 : $$->onCommit = ONCOMMIT_NOOP;
13179 138 : $$->tableSpaceName = NULL;
13180 138 : $$->viewQuery = NULL;
13181 138 : $$->skipData = false;
13182 : }
13183 : | /*EMPTY*/
13184 429722 : { $$ = NULL; }
13185 : ;
13186 :
13187 : /*
13188 : * Redundancy here is needed to avoid shift/reduce conflicts,
13189 : * since TEMP is not a reserved word. See also OptTemp.
13190 : */
13191 : OptTempTableName:
13192 : TEMPORARY opt_table qualified_name
13193 : {
13194 0 : $$ = $3;
13195 0 : $$->relpersistence = RELPERSISTENCE_TEMP;
13196 : }
13197 : | TEMP opt_table qualified_name
13198 : {
13199 6 : $$ = $3;
13200 6 : $$->relpersistence = RELPERSISTENCE_TEMP;
13201 : }
13202 : | LOCAL TEMPORARY opt_table qualified_name
13203 : {
13204 0 : $$ = $4;
13205 0 : $$->relpersistence = RELPERSISTENCE_TEMP;
13206 : }
13207 : | LOCAL TEMP opt_table qualified_name
13208 : {
13209 0 : $$ = $4;
13210 0 : $$->relpersistence = RELPERSISTENCE_TEMP;
13211 : }
13212 : | GLOBAL TEMPORARY opt_table qualified_name
13213 : {
13214 0 : ereport(WARNING,
13215 : (errmsg("GLOBAL is deprecated in temporary table creation"),
13216 : parser_errposition(@1)));
13217 0 : $$ = $4;
13218 0 : $$->relpersistence = RELPERSISTENCE_TEMP;
13219 : }
13220 : | GLOBAL TEMP opt_table qualified_name
13221 : {
13222 0 : ereport(WARNING,
13223 : (errmsg("GLOBAL is deprecated in temporary table creation"),
13224 : parser_errposition(@1)));
13225 0 : $$ = $4;
13226 0 : $$->relpersistence = RELPERSISTENCE_TEMP;
13227 : }
13228 : | UNLOGGED opt_table qualified_name
13229 : {
13230 0 : $$ = $3;
13231 0 : $$->relpersistence = RELPERSISTENCE_UNLOGGED;
13232 : }
13233 : | TABLE qualified_name
13234 : {
13235 30 : $$ = $2;
13236 30 : $$->relpersistence = RELPERSISTENCE_PERMANENT;
13237 : }
13238 : | qualified_name
13239 : {
13240 102 : $$ = $1;
13241 102 : $$->relpersistence = RELPERSISTENCE_PERMANENT;
13242 : }
13243 : ;
13244 :
13245 : opt_table: TABLE
13246 : | /*EMPTY*/
13247 : ;
13248 :
13249 : set_quantifier:
13250 10752 : ALL { $$ = SET_QUANTIFIER_ALL; }
13251 32 : | DISTINCT { $$ = SET_QUANTIFIER_DISTINCT; }
13252 13144 : | /*EMPTY*/ { $$ = SET_QUANTIFIER_DEFAULT; }
13253 : ;
13254 :
13255 : /* We use (NIL) as a placeholder to indicate that all target expressions
13256 : * should be placed in the DISTINCT list during parsetree analysis.
13257 : */
13258 : distinct_clause:
13259 3404 : DISTINCT { $$ = list_make1(NIL); }
13260 260 : | DISTINCT ON '(' expr_list ')' { $$ = $4; }
13261 : ;
13262 :
13263 : opt_all_clause:
13264 : ALL
13265 : | /*EMPTY*/
13266 : ;
13267 :
13268 : opt_distinct_clause:
13269 0 : distinct_clause { $$ = $1; }
13270 40010 : | opt_all_clause { $$ = NIL; }
13271 : ;
13272 :
13273 : opt_sort_clause:
13274 7372 : sort_clause { $$ = $1; }
13275 361002 : | /*EMPTY*/ { $$ = NIL; }
13276 : ;
13277 :
13278 : sort_clause:
13279 78632 : ORDER BY sortby_list { $$ = $3; }
13280 : ;
13281 :
13282 : sortby_list:
13283 78650 : sortby { $$ = list_make1($1); }
13284 28584 : | sortby_list ',' sortby { $$ = lappend($1, $3); }
13285 : ;
13286 :
13287 : sortby: a_expr USING qual_all_Op opt_nulls_order
13288 : {
13289 220 : $$ = makeNode(SortBy);
13290 220 : $$->node = $1;
13291 220 : $$->sortby_dir = SORTBY_USING;
13292 220 : $$->sortby_nulls = $4;
13293 220 : $$->useOp = $3;
13294 220 : $$->location = @3;
13295 : }
13296 : | a_expr opt_asc_desc opt_nulls_order
13297 : {
13298 107014 : $$ = makeNode(SortBy);
13299 107014 : $$->node = $1;
13300 107014 : $$->sortby_dir = $2;
13301 107014 : $$->sortby_nulls = $3;
13302 107014 : $$->useOp = NIL;
13303 107014 : $$->location = -1; /* no operator */
13304 : }
13305 : ;
13306 :
13307 :
13308 : select_limit:
13309 : limit_clause offset_clause
13310 : {
13311 172 : $$ = $1;
13312 172 : ($$)->limitOffset = $2;
13313 172 : ($$)->offsetLoc = @2;
13314 : }
13315 : | offset_clause limit_clause
13316 : {
13317 222 : $$ = $2;
13318 222 : ($$)->limitOffset = $1;
13319 222 : ($$)->offsetLoc = @1;
13320 : }
13321 : | limit_clause
13322 : {
13323 4312 : $$ = $1;
13324 : }
13325 : | offset_clause
13326 : {
13327 450 : SelectLimit *n = (SelectLimit *) palloc(sizeof(SelectLimit));
13328 :
13329 450 : n->limitOffset = $1;
13330 450 : n->limitCount = NULL;
13331 450 : n->limitOption = LIMIT_OPTION_COUNT;
13332 450 : n->offsetLoc = @1;
13333 450 : n->countLoc = -1;
13334 450 : n->optionLoc = -1;
13335 450 : $$ = n;
13336 : }
13337 : ;
13338 :
13339 : opt_select_limit:
13340 190 : select_limit { $$ = $1; }
13341 44622 : | /* EMPTY */ { $$ = NULL; }
13342 : ;
13343 :
13344 : limit_clause:
13345 : LIMIT select_limit_value
13346 : {
13347 4610 : SelectLimit *n = (SelectLimit *) palloc(sizeof(SelectLimit));
13348 :
13349 4610 : n->limitOffset = NULL;
13350 4610 : n->limitCount = $2;
13351 4610 : n->limitOption = LIMIT_OPTION_COUNT;
13352 4610 : n->offsetLoc = -1;
13353 4610 : n->countLoc = @1;
13354 4610 : n->optionLoc = -1;
13355 4610 : $$ = n;
13356 : }
13357 : | LIMIT select_limit_value ',' select_offset_value
13358 : {
13359 : /* Disabled because it was too confusing, bjm 2002-02-18 */
13360 0 : ereport(ERROR,
13361 : (errcode(ERRCODE_SYNTAX_ERROR),
13362 : errmsg("LIMIT #,# syntax is not supported"),
13363 : errhint("Use separate LIMIT and OFFSET clauses."),
13364 : parser_errposition(@1)));
13365 : }
13366 : /* SQL:2008 syntax */
13367 : /* to avoid shift/reduce conflicts, handle the optional value with
13368 : * a separate production rather than an opt_ expression. The fact
13369 : * that ONLY is fully reserved means that this way, we defer any
13370 : * decision about what rule reduces ROW or ROWS to the point where
13371 : * we can see the ONLY token in the lookahead slot.
13372 : */
13373 : | FETCH first_or_next select_fetch_first_value row_or_rows ONLY
13374 : {
13375 24 : SelectLimit *n = (SelectLimit *) palloc(sizeof(SelectLimit));
13376 :
13377 24 : n->limitOffset = NULL;
13378 24 : n->limitCount = $3;
13379 24 : n->limitOption = LIMIT_OPTION_COUNT;
13380 24 : n->offsetLoc = -1;
13381 24 : n->countLoc = @1;
13382 24 : n->optionLoc = -1;
13383 24 : $$ = n;
13384 : }
13385 : | FETCH first_or_next select_fetch_first_value row_or_rows WITH TIES
13386 : {
13387 66 : SelectLimit *n = (SelectLimit *) palloc(sizeof(SelectLimit));
13388 :
13389 66 : n->limitOffset = NULL;
13390 66 : n->limitCount = $3;
13391 66 : n->limitOption = LIMIT_OPTION_WITH_TIES;
13392 66 : n->offsetLoc = -1;
13393 66 : n->countLoc = @1;
13394 66 : n->optionLoc = @5;
13395 66 : $$ = n;
13396 : }
13397 : | FETCH first_or_next row_or_rows ONLY
13398 : {
13399 0 : SelectLimit *n = (SelectLimit *) palloc(sizeof(SelectLimit));
13400 :
13401 0 : n->limitOffset = NULL;
13402 0 : n->limitCount = makeIntConst(1, -1);
13403 0 : n->limitOption = LIMIT_OPTION_COUNT;
13404 0 : n->offsetLoc = -1;
13405 0 : n->countLoc = @1;
13406 0 : n->optionLoc = -1;
13407 0 : $$ = n;
13408 : }
13409 : | FETCH first_or_next row_or_rows WITH TIES
13410 : {
13411 6 : SelectLimit *n = (SelectLimit *) palloc(sizeof(SelectLimit));
13412 :
13413 6 : n->limitOffset = NULL;
13414 6 : n->limitCount = makeIntConst(1, -1);
13415 6 : n->limitOption = LIMIT_OPTION_WITH_TIES;
13416 6 : n->offsetLoc = -1;
13417 6 : n->countLoc = @1;
13418 6 : n->optionLoc = @4;
13419 6 : $$ = n;
13420 : }
13421 : ;
13422 :
13423 : offset_clause:
13424 : OFFSET select_offset_value
13425 844 : { $$ = $2; }
13426 : /* SQL:2008 syntax */
13427 : | OFFSET select_fetch_first_value row_or_rows
13428 0 : { $$ = $2; }
13429 : ;
13430 :
13431 : select_limit_value:
13432 4608 : a_expr { $$ = $1; }
13433 : | ALL
13434 : {
13435 : /* LIMIT ALL is represented as a NULL constant */
13436 2 : $$ = makeNullAConst(@1);
13437 : }
13438 : ;
13439 :
13440 : select_offset_value:
13441 844 : a_expr { $$ = $1; }
13442 : ;
13443 :
13444 : /*
13445 : * Allowing full expressions without parentheses causes various parsing
13446 : * problems with the trailing ROW/ROWS key words. SQL spec only calls for
13447 : * <simple value specification>, which is either a literal or a parameter (but
13448 : * an <SQL parameter reference> could be an identifier, bringing up conflicts
13449 : * with ROW/ROWS). We solve this by leveraging the presence of ONLY (see above)
13450 : * to determine whether the expression is missing rather than trying to make it
13451 : * optional in this rule.
13452 : *
13453 : * c_expr covers almost all the spec-required cases (and more), but it doesn't
13454 : * cover signed numeric literals, which are allowed by the spec. So we include
13455 : * those here explicitly. We need FCONST as well as ICONST because values that
13456 : * don't fit in the platform's "long", but do fit in bigint, should still be
13457 : * accepted here. (This is possible in 64-bit Windows as well as all 32-bit
13458 : * builds.)
13459 : */
13460 : select_fetch_first_value:
13461 90 : c_expr { $$ = $1; }
13462 : | '+' I_or_F_const
13463 0 : { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "+", NULL, $2, @1); }
13464 : | '-' I_or_F_const
13465 0 : { $$ = doNegate($2, @1); }
13466 : ;
13467 :
13468 : I_or_F_const:
13469 0 : Iconst { $$ = makeIntConst($1,@1); }
13470 0 : | FCONST { $$ = makeFloatConst($1,@1); }
13471 : ;
13472 :
13473 : /* noise words */
13474 36 : row_or_rows: ROW { $$ = 0; }
13475 60 : | ROWS { $$ = 0; }
13476 : ;
13477 :
13478 96 : first_or_next: FIRST_P { $$ = 0; }
13479 0 : | NEXT { $$ = 0; }
13480 : ;
13481 :
13482 :
13483 : /*
13484 : * This syntax for group_clause tries to follow the spec quite closely.
13485 : * However, the spec allows only column references, not expressions,
13486 : * which introduces an ambiguity between implicit row constructors
13487 : * (a,b) and lists of column references.
13488 : *
13489 : * We handle this by using the a_expr production for what the spec calls
13490 : * <ordinary grouping set>, which in the spec represents either one column
13491 : * reference or a parenthesized list of column references. Then, we check the
13492 : * top node of the a_expr to see if it's an implicit RowExpr, and if so, just
13493 : * grab and use the list, discarding the node. (this is done in parse analysis,
13494 : * not here)
13495 : *
13496 : * (we abuse the row_format field of RowExpr to distinguish implicit and
13497 : * explicit row constructors; it's debatable if anyone sanely wants to use them
13498 : * in a group clause, but if they have a reason to, we make it possible.)
13499 : *
13500 : * Each item in the group_clause list is either an expression tree or a
13501 : * GroupingSet node of some type.
13502 : */
13503 : group_clause:
13504 : GROUP_P BY set_quantifier group_by_list
13505 : {
13506 4624 : GroupClause *n = (GroupClause *) palloc(sizeof(GroupClause));
13507 :
13508 4624 : n->distinct = $3 == SET_QUANTIFIER_DISTINCT;
13509 4624 : n->list = $4;
13510 4624 : $$ = n;
13511 : }
13512 : | /*EMPTY*/
13513 : {
13514 465216 : GroupClause *n = (GroupClause *) palloc(sizeof(GroupClause));
13515 :
13516 465216 : n->distinct = false;
13517 465216 : n->list = NIL;
13518 465216 : $$ = n;
13519 : }
13520 : ;
13521 :
13522 : group_by_list:
13523 5222 : group_by_item { $$ = list_make1($1); }
13524 3026 : | group_by_list ',' group_by_item { $$ = lappend($1,$3); }
13525 : ;
13526 :
13527 : group_by_item:
13528 6958 : a_expr { $$ = $1; }
13529 222 : | empty_grouping_set { $$ = $1; }
13530 184 : | cube_clause { $$ = $1; }
13531 286 : | rollup_clause { $$ = $1; }
13532 598 : | grouping_sets_clause { $$ = $1; }
13533 : ;
13534 :
13535 : empty_grouping_set:
13536 : '(' ')'
13537 : {
13538 222 : $$ = (Node *) makeGroupingSet(GROUPING_SET_EMPTY, NIL, @1);
13539 : }
13540 : ;
13541 :
13542 : /*
13543 : * These hacks rely on setting precedence of CUBE and ROLLUP below that of '(',
13544 : * so that they shift in these rules rather than reducing the conflicting
13545 : * unreserved_keyword rule.
13546 : */
13547 :
13548 : rollup_clause:
13549 : ROLLUP '(' expr_list ')'
13550 : {
13551 286 : $$ = (Node *) makeGroupingSet(GROUPING_SET_ROLLUP, $3, @1);
13552 : }
13553 : ;
13554 :
13555 : cube_clause:
13556 : CUBE '(' expr_list ')'
13557 : {
13558 184 : $$ = (Node *) makeGroupingSet(GROUPING_SET_CUBE, $3, @1);
13559 : }
13560 : ;
13561 :
13562 : grouping_sets_clause:
13563 : GROUPING SETS '(' group_by_list ')'
13564 : {
13565 598 : $$ = (Node *) makeGroupingSet(GROUPING_SET_SETS, $4, @1);
13566 : }
13567 : ;
13568 :
13569 : having_clause:
13570 678 : HAVING a_expr { $$ = $2; }
13571 469162 : | /*EMPTY*/ { $$ = NULL; }
13572 : ;
13573 :
13574 : for_locking_clause:
13575 5142 : for_locking_items { $$ = $1; }
13576 0 : | FOR READ ONLY { $$ = NIL; }
13577 : ;
13578 :
13579 : opt_for_locking_clause:
13580 340 : for_locking_clause { $$ = $1; }
13581 44636 : | /* EMPTY */ { $$ = NIL; }
13582 : ;
13583 :
13584 : for_locking_items:
13585 5142 : for_locking_item { $$ = list_make1($1); }
13586 102 : | for_locking_items for_locking_item { $$ = lappend($1, $2); }
13587 : ;
13588 :
13589 : for_locking_item:
13590 : for_locking_strength locked_rels_list opt_nowait_or_skip
13591 : {
13592 5244 : LockingClause *n = makeNode(LockingClause);
13593 :
13594 5244 : n->lockedRels = $2;
13595 5244 : n->strength = $1;
13596 5244 : n->waitPolicy = $3;
13597 5244 : $$ = (Node *) n;
13598 : }
13599 : ;
13600 :
13601 : for_locking_strength:
13602 1534 : FOR UPDATE { $$ = LCS_FORUPDATE; }
13603 76 : | FOR NO KEY UPDATE { $$ = LCS_FORNOKEYUPDATE; }
13604 214 : | FOR SHARE { $$ = LCS_FORSHARE; }
13605 3420 : | FOR KEY SHARE { $$ = LCS_FORKEYSHARE; }
13606 : ;
13607 :
13608 : locked_rels_list:
13609 3446 : OF qualified_name_list { $$ = $2; }
13610 1798 : | /* EMPTY */ { $$ = NIL; }
13611 : ;
13612 :
13613 :
13614 : /*
13615 : * We should allow ROW '(' expr_list ')' too, but that seems to require
13616 : * making VALUES a fully reserved word, which will probably break more apps
13617 : * than allowing the noise-word is worth.
13618 : */
13619 : values_clause:
13620 : VALUES '(' expr_list ')'
13621 : {
13622 58816 : SelectStmt *n = makeNode(SelectStmt);
13623 :
13624 58816 : n->valuesLists = list_make1($3);
13625 58816 : $$ = (Node *) n;
13626 : }
13627 : | values_clause ',' '(' expr_list ')'
13628 : {
13629 25116 : SelectStmt *n = (SelectStmt *) $1;
13630 :
13631 25116 : n->valuesLists = lappend(n->valuesLists, $4);
13632 25116 : $$ = (Node *) n;
13633 : }
13634 : ;
13635 :
13636 :
13637 : /*****************************************************************************
13638 : *
13639 : * clauses common to all Optimizable Stmts:
13640 : * from_clause - allow list of both JOIN expressions and table names
13641 : * where_clause - qualifications for joins or restrictions
13642 : *
13643 : *****************************************************************************/
13644 :
13645 : from_clause:
13646 312246 : FROM from_list { $$ = $2; }
13647 171702 : | /*EMPTY*/ { $$ = NIL; }
13648 : ;
13649 :
13650 : from_list:
13651 313048 : table_ref { $$ = list_make1($1); }
13652 61102 : | from_list ',' table_ref { $$ = lappend($1, $3); }
13653 : ;
13654 :
13655 : /*
13656 : * table_ref is where an alias clause can be attached.
13657 : */
13658 : table_ref: relation_expr opt_alias_clause
13659 : {
13660 394818 : $1->alias = $2;
13661 394818 : $$ = (Node *) $1;
13662 : }
13663 : | relation_expr opt_alias_clause tablesample_clause
13664 : {
13665 260 : RangeTableSample *n = (RangeTableSample *) $3;
13666 :
13667 260 : $1->alias = $2;
13668 : /* relation_expr goes inside the RangeTableSample node */
13669 260 : n->relation = (Node *) $1;
13670 260 : $$ = (Node *) n;
13671 : }
13672 : | func_table func_alias_clause
13673 : {
13674 46314 : RangeFunction *n = (RangeFunction *) $1;
13675 :
13676 46314 : n->alias = linitial($2);
13677 46314 : n->coldeflist = lsecond($2);
13678 46314 : $$ = (Node *) n;
13679 : }
13680 : | LATERAL_P func_table func_alias_clause
13681 : {
13682 1162 : RangeFunction *n = (RangeFunction *) $2;
13683 :
13684 1162 : n->lateral = true;
13685 1162 : n->alias = linitial($3);
13686 1162 : n->coldeflist = lsecond($3);
13687 1162 : $$ = (Node *) n;
13688 : }
13689 : | xmltable opt_alias_clause
13690 : {
13691 80 : RangeTableFunc *n = (RangeTableFunc *) $1;
13692 :
13693 80 : n->alias = $2;
13694 80 : $$ = (Node *) n;
13695 : }
13696 : | LATERAL_P xmltable opt_alias_clause
13697 : {
13698 140 : RangeTableFunc *n = (RangeTableFunc *) $2;
13699 :
13700 140 : n->lateral = true;
13701 140 : n->alias = $3;
13702 140 : $$ = (Node *) n;
13703 : }
13704 : | select_with_parens opt_alias_clause
13705 : {
13706 14060 : RangeSubselect *n = makeNode(RangeSubselect);
13707 :
13708 14060 : n->lateral = false;
13709 14060 : n->subquery = $1;
13710 14060 : n->alias = $2;
13711 14060 : $$ = (Node *) n;
13712 : }
13713 : | LATERAL_P select_with_parens opt_alias_clause
13714 : {
13715 1894 : RangeSubselect *n = makeNode(RangeSubselect);
13716 :
13717 1894 : n->lateral = true;
13718 1894 : n->subquery = $2;
13719 1894 : n->alias = $3;
13720 1894 : $$ = (Node *) n;
13721 : }
13722 : | joined_table
13723 : {
13724 82804 : $$ = (Node *) $1;
13725 : }
13726 : | '(' joined_table ')' alias_clause
13727 : {
13728 174 : $2->alias = $4;
13729 174 : $$ = (Node *) $2;
13730 : }
13731 : | json_table opt_alias_clause
13732 : {
13733 524 : JsonTable *jt = castNode(JsonTable, $1);
13734 :
13735 524 : jt->alias = $2;
13736 524 : $$ = (Node *) jt;
13737 : }
13738 : | LATERAL_P json_table opt_alias_clause
13739 : {
13740 0 : JsonTable *jt = castNode(JsonTable, $2);
13741 :
13742 0 : jt->alias = $3;
13743 0 : jt->lateral = true;
13744 0 : $$ = (Node *) jt;
13745 : }
13746 : ;
13747 :
13748 :
13749 : /*
13750 : * It may seem silly to separate joined_table from table_ref, but there is
13751 : * method in SQL's madness: if you don't do it this way you get reduce-
13752 : * reduce conflicts, because it's not clear to the parser generator whether
13753 : * to expect alias_clause after ')' or not. For the same reason we must
13754 : * treat 'JOIN' and 'join_type JOIN' separately, rather than allowing
13755 : * join_type to expand to empty; if we try it, the parser generator can't
13756 : * figure out when to reduce an empty join_type right after table_ref.
13757 : *
13758 : * Note that a CROSS JOIN is the same as an unqualified
13759 : * INNER JOIN, and an INNER JOIN/ON has the same shape
13760 : * but a qualification expression to limit membership.
13761 : * A NATURAL JOIN implicitly matches column names between
13762 : * tables and the shape is determined by which columns are
13763 : * in common. We'll collect columns during the later transformations.
13764 : */
13765 :
13766 : joined_table:
13767 : '(' joined_table ')'
13768 : {
13769 3962 : $$ = $2;
13770 : }
13771 : | table_ref CROSS JOIN table_ref
13772 : {
13773 : /* CROSS JOIN is same as unqualified inner join */
13774 502 : JoinExpr *n = makeNode(JoinExpr);
13775 :
13776 502 : n->jointype = JOIN_INNER;
13777 502 : n->isNatural = false;
13778 502 : n->larg = $1;
13779 502 : n->rarg = $4;
13780 502 : n->usingClause = NIL;
13781 502 : n->join_using_alias = NULL;
13782 502 : n->quals = NULL;
13783 502 : $$ = n;
13784 : }
13785 : | table_ref join_type JOIN table_ref join_qual
13786 : {
13787 47028 : JoinExpr *n = makeNode(JoinExpr);
13788 :
13789 47028 : n->jointype = $2;
13790 47028 : n->isNatural = false;
13791 47028 : n->larg = $1;
13792 47028 : n->rarg = $4;
13793 47028 : if ($5 != NULL && IsA($5, List))
13794 : {
13795 : /* USING clause */
13796 498 : n->usingClause = linitial_node(List, castNode(List, $5));
13797 498 : n->join_using_alias = lsecond_node(Alias, castNode(List, $5));
13798 : }
13799 : else
13800 : {
13801 : /* ON clause */
13802 46530 : n->quals = $5;
13803 : }
13804 47028 : $$ = n;
13805 : }
13806 : | table_ref JOIN table_ref join_qual
13807 : {
13808 : /* letting join_type reduce to empty doesn't work */
13809 35190 : JoinExpr *n = makeNode(JoinExpr);
13810 :
13811 35190 : n->jointype = JOIN_INNER;
13812 35190 : n->isNatural = false;
13813 35190 : n->larg = $1;
13814 35190 : n->rarg = $3;
13815 35190 : if ($4 != NULL && IsA($4, List))
13816 : {
13817 : /* USING clause */
13818 744 : n->usingClause = linitial_node(List, castNode(List, $4));
13819 744 : n->join_using_alias = lsecond_node(Alias, castNode(List, $4));
13820 : }
13821 : else
13822 : {
13823 : /* ON clause */
13824 34446 : n->quals = $4;
13825 : }
13826 35190 : $$ = n;
13827 : }
13828 : | table_ref NATURAL join_type JOIN table_ref
13829 : {
13830 78 : JoinExpr *n = makeNode(JoinExpr);
13831 :
13832 78 : n->jointype = $3;
13833 78 : n->isNatural = true;
13834 78 : n->larg = $1;
13835 78 : n->rarg = $5;
13836 78 : n->usingClause = NIL; /* figure out which columns later... */
13837 78 : n->join_using_alias = NULL;
13838 78 : n->quals = NULL; /* fill later */
13839 78 : $$ = n;
13840 : }
13841 : | table_ref NATURAL JOIN table_ref
13842 : {
13843 : /* letting join_type reduce to empty doesn't work */
13844 180 : JoinExpr *n = makeNode(JoinExpr);
13845 :
13846 180 : n->jointype = JOIN_INNER;
13847 180 : n->isNatural = true;
13848 180 : n->larg = $1;
13849 180 : n->rarg = $4;
13850 180 : n->usingClause = NIL; /* figure out which columns later... */
13851 180 : n->join_using_alias = NULL;
13852 180 : n->quals = NULL; /* fill later */
13853 180 : $$ = n;
13854 : }
13855 : ;
13856 :
13857 : alias_clause:
13858 : AS ColId '(' name_list ')'
13859 : {
13860 6614 : $$ = makeNode(Alias);
13861 6614 : $$->aliasname = $2;
13862 6614 : $$->colnames = $4;
13863 : }
13864 : | AS ColId
13865 : {
13866 10884 : $$ = makeNode(Alias);
13867 10884 : $$->aliasname = $2;
13868 : }
13869 : | ColId '(' name_list ')'
13870 : {
13871 5826 : $$ = makeNode(Alias);
13872 5826 : $$->aliasname = $1;
13873 5826 : $$->colnames = $3;
13874 : }
13875 : | ColId
13876 : {
13877 261646 : $$ = makeNode(Alias);
13878 261646 : $$->aliasname = $1;
13879 : }
13880 : ;
13881 :
13882 256256 : opt_alias_clause: alias_clause { $$ = $1; }
13883 155520 : | /*EMPTY*/ { $$ = NULL; }
13884 : ;
13885 :
13886 : /*
13887 : * The alias clause after JOIN ... USING only accepts the AS ColId spelling,
13888 : * per SQL standard. (The grammar could parse the other variants, but they
13889 : * don't seem to be useful, and it might lead to parser problems in the
13890 : * future.)
13891 : */
13892 : opt_alias_clause_for_join_using:
13893 : AS ColId
13894 : {
13895 84 : $$ = makeNode(Alias);
13896 84 : $$->aliasname = $2;
13897 : /* the column name list will be inserted later */
13898 : }
13899 1158 : | /*EMPTY*/ { $$ = NULL; }
13900 : ;
13901 :
13902 : /*
13903 : * func_alias_clause can include both an Alias and a coldeflist, so we make it
13904 : * return a 2-element list that gets disassembled by calling production.
13905 : */
13906 : func_alias_clause:
13907 : alias_clause
13908 : {
13909 28540 : $$ = list_make2($1, NIL);
13910 : }
13911 : | AS '(' TableFuncElementList ')'
13912 : {
13913 114 : $$ = list_make2(NULL, $3);
13914 : }
13915 : | AS ColId '(' TableFuncElementList ')'
13916 : {
13917 594 : Alias *a = makeNode(Alias);
13918 :
13919 594 : a->aliasname = $2;
13920 594 : $$ = list_make2(a, $4);
13921 : }
13922 : | ColId '(' TableFuncElementList ')'
13923 : {
13924 50 : Alias *a = makeNode(Alias);
13925 :
13926 50 : a->aliasname = $1;
13927 50 : $$ = list_make2(a, $3);
13928 : }
13929 : | /*EMPTY*/
13930 : {
13931 18178 : $$ = list_make2(NULL, NIL);
13932 : }
13933 : ;
13934 :
13935 1042 : join_type: FULL opt_outer { $$ = JOIN_FULL; }
13936 41726 : | LEFT opt_outer { $$ = JOIN_LEFT; }
13937 378 : | RIGHT opt_outer { $$ = JOIN_RIGHT; }
13938 3960 : | INNER_P { $$ = JOIN_INNER; }
13939 : ;
13940 :
13941 : /* OUTER is just noise... */
13942 : opt_outer: OUTER_P
13943 : | /*EMPTY*/
13944 : ;
13945 :
13946 : /* JOIN qualification clauses
13947 : * Possibilities are:
13948 : * USING ( column list ) [ AS alias ]
13949 : * allows only unqualified column names,
13950 : * which must match between tables.
13951 : * ON expr allows more general qualifications.
13952 : *
13953 : * We return USING as a two-element List (the first item being a sub-List
13954 : * of the common column names, and the second either an Alias item or NULL).
13955 : * An ON-expr will not be a List, so it can be told apart that way.
13956 : */
13957 :
13958 : join_qual: USING '(' name_list ')' opt_alias_clause_for_join_using
13959 : {
13960 1242 : $$ = (Node *) list_make2($3, $5);
13961 : }
13962 : | ON a_expr
13963 : {
13964 80976 : $$ = $2;
13965 : }
13966 : ;
13967 :
13968 :
13969 : relation_expr:
13970 : qualified_name
13971 : {
13972 : /* inheritance query, implicitly */
13973 475640 : $$ = $1;
13974 475640 : $$->inh = true;
13975 475640 : $$->alias = NULL;
13976 : }
13977 : | extended_relation_expr
13978 : {
13979 7176 : $$ = $1;
13980 : }
13981 : ;
13982 :
13983 : extended_relation_expr:
13984 : qualified_name '*'
13985 : {
13986 : /* inheritance query, explicitly */
13987 204 : $$ = $1;
13988 204 : $$->inh = true;
13989 204 : $$->alias = NULL;
13990 : }
13991 : | ONLY qualified_name
13992 : {
13993 : /* no inheritance */
13994 6978 : $$ = $2;
13995 6978 : $$->inh = false;
13996 6978 : $$->alias = NULL;
13997 : }
13998 : | ONLY '(' qualified_name ')'
13999 : {
14000 : /* no inheritance, SQL99-style syntax */
14001 0 : $$ = $3;
14002 0 : $$->inh = false;
14003 0 : $$->alias = NULL;
14004 : }
14005 : ;
14006 :
14007 :
14008 : relation_expr_list:
14009 2904 : relation_expr { $$ = list_make1($1); }
14010 11576 : | relation_expr_list ',' relation_expr { $$ = lappend($1, $3); }
14011 : ;
14012 :
14013 :
14014 : /*
14015 : * Given "UPDATE foo set set ...", we have to decide without looking any
14016 : * further ahead whether the first "set" is an alias or the UPDATE's SET
14017 : * keyword. Since "set" is allowed as a column name both interpretations
14018 : * are feasible. We resolve the shift/reduce conflict by giving the first
14019 : * relation_expr_opt_alias production a higher precedence than the SET token
14020 : * has, causing the parser to prefer to reduce, in effect assuming that the
14021 : * SET is not an alias.
14022 : */
14023 : relation_expr_opt_alias: relation_expr %prec UMINUS
14024 : {
14025 18586 : $$ = $1;
14026 : }
14027 : | relation_expr ColId
14028 : {
14029 2216 : Alias *alias = makeNode(Alias);
14030 :
14031 2216 : alias->aliasname = $2;
14032 2216 : $1->alias = alias;
14033 2216 : $$ = $1;
14034 : }
14035 : | relation_expr AS ColId
14036 : {
14037 90 : Alias *alias = makeNode(Alias);
14038 :
14039 90 : alias->aliasname = $3;
14040 90 : $1->alias = alias;
14041 90 : $$ = $1;
14042 : }
14043 : ;
14044 :
14045 : /*
14046 : * TABLESAMPLE decoration in a FROM item
14047 : */
14048 : tablesample_clause:
14049 : TABLESAMPLE func_name '(' expr_list ')' opt_repeatable_clause
14050 : {
14051 260 : RangeTableSample *n = makeNode(RangeTableSample);
14052 :
14053 : /* n->relation will be filled in later */
14054 260 : n->method = $2;
14055 260 : n->args = $4;
14056 260 : n->repeatable = $6;
14057 260 : n->location = @2;
14058 260 : $$ = (Node *) n;
14059 : }
14060 : ;
14061 :
14062 : opt_repeatable_clause:
14063 108 : REPEATABLE '(' a_expr ')' { $$ = (Node *) $3; }
14064 152 : | /*EMPTY*/ { $$ = NULL; }
14065 : ;
14066 :
14067 : /*
14068 : * func_table represents a function invocation in a FROM list. It can be
14069 : * a plain function call, like "foo(...)", or a ROWS FROM expression with
14070 : * one or more function calls, "ROWS FROM (foo(...), bar(...))",
14071 : * optionally with WITH ORDINALITY attached.
14072 : * In the ROWS FROM syntax, a column definition list can be given for each
14073 : * function, for example:
14074 : * ROWS FROM (foo() AS (foo_res_a text, foo_res_b text),
14075 : * bar() AS (bar_res_a text, bar_res_b text))
14076 : * It's also possible to attach a column definition list to the RangeFunction
14077 : * as a whole, but that's handled by the table_ref production.
14078 : */
14079 : func_table: func_expr_windowless opt_ordinality
14080 : {
14081 47350 : RangeFunction *n = makeNode(RangeFunction);
14082 :
14083 47350 : n->lateral = false;
14084 47350 : n->ordinality = $2;
14085 47350 : n->is_rowsfrom = false;
14086 47350 : n->functions = list_make1(list_make2($1, NIL));
14087 : /* alias and coldeflist are set by table_ref production */
14088 47350 : $$ = (Node *) n;
14089 : }
14090 : | ROWS FROM '(' rowsfrom_list ')' opt_ordinality
14091 : {
14092 132 : RangeFunction *n = makeNode(RangeFunction);
14093 :
14094 132 : n->lateral = false;
14095 132 : n->ordinality = $6;
14096 132 : n->is_rowsfrom = true;
14097 132 : n->functions = $4;
14098 : /* alias and coldeflist are set by table_ref production */
14099 132 : $$ = (Node *) n;
14100 : }
14101 : ;
14102 :
14103 : rowsfrom_item: func_expr_windowless opt_col_def_list
14104 318 : { $$ = list_make2($1, $2); }
14105 : ;
14106 :
14107 : rowsfrom_list:
14108 132 : rowsfrom_item { $$ = list_make1($1); }
14109 186 : | rowsfrom_list ',' rowsfrom_item { $$ = lappend($1, $3); }
14110 : ;
14111 :
14112 54 : opt_col_def_list: AS '(' TableFuncElementList ')' { $$ = $3; }
14113 264 : | /*EMPTY*/ { $$ = NIL; }
14114 : ;
14115 :
14116 914 : opt_ordinality: WITH_LA ORDINALITY { $$ = true; }
14117 46568 : | /*EMPTY*/ { $$ = false; }
14118 : ;
14119 :
14120 :
14121 : where_clause:
14122 210366 : WHERE a_expr { $$ = $2; }
14123 281022 : | /*EMPTY*/ { $$ = NULL; }
14124 : ;
14125 :
14126 : /* variant for UPDATE and DELETE */
14127 : where_or_current_clause:
14128 13422 : WHERE a_expr { $$ = $2; }
14129 : | WHERE CURRENT_P OF cursor_name
14130 : {
14131 266 : CurrentOfExpr *n = makeNode(CurrentOfExpr);
14132 :
14133 : /* cvarno is filled in by parse analysis */
14134 266 : n->cursor_name = $4;
14135 266 : n->cursor_param = 0;
14136 266 : $$ = (Node *) n;
14137 : }
14138 5068 : | /*EMPTY*/ { $$ = NULL; }
14139 : ;
14140 :
14141 :
14142 : OptTableFuncElementList:
14143 716 : TableFuncElementList { $$ = $1; }
14144 3786 : | /*EMPTY*/ { $$ = NIL; }
14145 : ;
14146 :
14147 : TableFuncElementList:
14148 : TableFuncElement
14149 : {
14150 1528 : $$ = list_make1($1);
14151 : }
14152 : | TableFuncElementList ',' TableFuncElement
14153 : {
14154 2056 : $$ = lappend($1, $3);
14155 : }
14156 : ;
14157 :
14158 : TableFuncElement: ColId Typename opt_collate_clause
14159 : {
14160 3648 : ColumnDef *n = makeNode(ColumnDef);
14161 :
14162 3648 : n->colname = $1;
14163 3648 : n->typeName = $2;
14164 3648 : n->inhcount = 0;
14165 3648 : n->is_local = true;
14166 3648 : n->is_not_null = false;
14167 3648 : n->is_from_type = false;
14168 3648 : n->storage = 0;
14169 3648 : n->raw_default = NULL;
14170 3648 : n->cooked_default = NULL;
14171 3648 : n->collClause = (CollateClause *) $3;
14172 3648 : n->collOid = InvalidOid;
14173 3648 : n->constraints = NIL;
14174 3648 : n->location = @1;
14175 3648 : $$ = (Node *) n;
14176 : }
14177 : ;
14178 :
14179 : /*
14180 : * XMLTABLE
14181 : */
14182 : xmltable:
14183 : XMLTABLE '(' c_expr xmlexists_argument COLUMNS xmltable_column_list ')'
14184 : {
14185 200 : RangeTableFunc *n = makeNode(RangeTableFunc);
14186 :
14187 200 : n->rowexpr = $3;
14188 200 : n->docexpr = $4;
14189 200 : n->columns = $6;
14190 200 : n->namespaces = NIL;
14191 200 : n->location = @1;
14192 200 : $$ = (Node *) n;
14193 : }
14194 : | XMLTABLE '(' XMLNAMESPACES '(' xml_namespace_list ')' ','
14195 : c_expr xmlexists_argument COLUMNS xmltable_column_list ')'
14196 : {
14197 20 : RangeTableFunc *n = makeNode(RangeTableFunc);
14198 :
14199 20 : n->rowexpr = $8;
14200 20 : n->docexpr = $9;
14201 20 : n->columns = $11;
14202 20 : n->namespaces = $5;
14203 20 : n->location = @1;
14204 20 : $$ = (Node *) n;
14205 : }
14206 : ;
14207 :
14208 220 : xmltable_column_list: xmltable_column_el { $$ = list_make1($1); }
14209 530 : | xmltable_column_list ',' xmltable_column_el { $$ = lappend($1, $3); }
14210 : ;
14211 :
14212 : xmltable_column_el:
14213 : ColId Typename
14214 : {
14215 198 : RangeTableFuncCol *fc = makeNode(RangeTableFuncCol);
14216 :
14217 198 : fc->colname = $1;
14218 198 : fc->for_ordinality = false;
14219 198 : fc->typeName = $2;
14220 198 : fc->is_not_null = false;
14221 198 : fc->colexpr = NULL;
14222 198 : fc->coldefexpr = NULL;
14223 198 : fc->location = @1;
14224 :
14225 198 : $$ = (Node *) fc;
14226 : }
14227 : | ColId Typename xmltable_column_option_list
14228 : {
14229 490 : RangeTableFuncCol *fc = makeNode(RangeTableFuncCol);
14230 : ListCell *option;
14231 490 : bool nullability_seen = false;
14232 :
14233 490 : fc->colname = $1;
14234 490 : fc->typeName = $2;
14235 490 : fc->for_ordinality = false;
14236 490 : fc->is_not_null = false;
14237 490 : fc->colexpr = NULL;
14238 490 : fc->coldefexpr = NULL;
14239 490 : fc->location = @1;
14240 :
14241 1092 : foreach(option, $3)
14242 : {
14243 602 : DefElem *defel = (DefElem *) lfirst(option);
14244 :
14245 602 : if (strcmp(defel->defname, "default") == 0)
14246 : {
14247 56 : if (fc->coldefexpr != NULL)
14248 0 : ereport(ERROR,
14249 : (errcode(ERRCODE_SYNTAX_ERROR),
14250 : errmsg("only one DEFAULT value is allowed"),
14251 : parser_errposition(defel->location)));
14252 56 : fc->coldefexpr = defel->arg;
14253 : }
14254 546 : else if (strcmp(defel->defname, "path") == 0)
14255 : {
14256 490 : if (fc->colexpr != NULL)
14257 0 : ereport(ERROR,
14258 : (errcode(ERRCODE_SYNTAX_ERROR),
14259 : errmsg("only one PATH value per column is allowed"),
14260 : parser_errposition(defel->location)));
14261 490 : fc->colexpr = defel->arg;
14262 : }
14263 56 : else if (strcmp(defel->defname, "__pg__is_not_null") == 0)
14264 : {
14265 56 : if (nullability_seen)
14266 0 : ereport(ERROR,
14267 : (errcode(ERRCODE_SYNTAX_ERROR),
14268 : errmsg("conflicting or redundant NULL / NOT NULL declarations for column \"%s\"", fc->colname),
14269 : parser_errposition(defel->location)));
14270 56 : fc->is_not_null = boolVal(defel->arg);
14271 56 : nullability_seen = true;
14272 : }
14273 : else
14274 : {
14275 0 : ereport(ERROR,
14276 : (errcode(ERRCODE_SYNTAX_ERROR),
14277 : errmsg("unrecognized column option \"%s\"",
14278 : defel->defname),
14279 : parser_errposition(defel->location)));
14280 : }
14281 : }
14282 490 : $$ = (Node *) fc;
14283 : }
14284 : | ColId FOR ORDINALITY
14285 : {
14286 62 : RangeTableFuncCol *fc = makeNode(RangeTableFuncCol);
14287 :
14288 62 : fc->colname = $1;
14289 62 : fc->for_ordinality = true;
14290 : /* other fields are ignored, initialized by makeNode */
14291 62 : fc->location = @1;
14292 :
14293 62 : $$ = (Node *) fc;
14294 : }
14295 : ;
14296 :
14297 : xmltable_column_option_list:
14298 : xmltable_column_option_el
14299 490 : { $$ = list_make1($1); }
14300 : | xmltable_column_option_list xmltable_column_option_el
14301 112 : { $$ = lappend($1, $2); }
14302 : ;
14303 :
14304 : xmltable_column_option_el:
14305 : IDENT b_expr
14306 : {
14307 6 : if (strcmp($1, "__pg__is_not_null") == 0)
14308 6 : ereport(ERROR,
14309 : (errcode(ERRCODE_SYNTAX_ERROR),
14310 : errmsg("option name \"%s\" cannot be used in XMLTABLE", $1),
14311 : parser_errposition(@1)));
14312 0 : $$ = makeDefElem($1, $2, @1);
14313 : }
14314 : | DEFAULT b_expr
14315 56 : { $$ = makeDefElem("default", $2, @1); }
14316 : | NOT NULL_P
14317 56 : { $$ = makeDefElem("__pg__is_not_null", (Node *) makeBoolean(true), @1); }
14318 : | NULL_P
14319 0 : { $$ = makeDefElem("__pg__is_not_null", (Node *) makeBoolean(false), @1); }
14320 : | PATH b_expr
14321 490 : { $$ = makeDefElem("path", $2, @1); }
14322 : ;
14323 :
14324 : xml_namespace_list:
14325 : xml_namespace_el
14326 20 : { $$ = list_make1($1); }
14327 : | xml_namespace_list ',' xml_namespace_el
14328 0 : { $$ = lappend($1, $3); }
14329 : ;
14330 :
14331 : xml_namespace_el:
14332 : b_expr AS ColLabel
14333 : {
14334 14 : $$ = makeNode(ResTarget);
14335 14 : $$->name = $3;
14336 14 : $$->indirection = NIL;
14337 14 : $$->val = $1;
14338 14 : $$->location = @1;
14339 : }
14340 : | DEFAULT b_expr
14341 : {
14342 6 : $$ = makeNode(ResTarget);
14343 6 : $$->name = NULL;
14344 6 : $$->indirection = NIL;
14345 6 : $$->val = $2;
14346 6 : $$->location = @1;
14347 : }
14348 : ;
14349 :
14350 : json_table:
14351 : JSON_TABLE '('
14352 : json_value_expr ',' a_expr json_table_path_name_opt
14353 : json_passing_clause_opt
14354 : COLUMNS '(' json_table_column_definition_list ')'
14355 : json_on_error_clause_opt
14356 : ')'
14357 : {
14358 530 : JsonTable *n = makeNode(JsonTable);
14359 : char *pathstring;
14360 :
14361 530 : n->context_item = (JsonValueExpr *) $3;
14362 530 : if (!IsA($5, A_Const) ||
14363 524 : castNode(A_Const, $5)->val.node.type != T_String)
14364 6 : ereport(ERROR,
14365 : errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
14366 : errmsg("only string constants are supported in JSON_TABLE path specification"),
14367 : parser_errposition(@5));
14368 524 : pathstring = castNode(A_Const, $5)->val.sval.sval;
14369 524 : n->pathspec = makeJsonTablePathSpec(pathstring, $6, @5, @6);
14370 524 : n->passing = $7;
14371 524 : n->columns = $10;
14372 524 : n->on_error = (JsonBehavior *) $12;
14373 524 : n->location = @1;
14374 524 : $$ = (Node *) n;
14375 : }
14376 : ;
14377 :
14378 : json_table_path_name_opt:
14379 62 : AS name { $$ = $2; }
14380 480 : | /* empty */ { $$ = NULL; }
14381 : ;
14382 :
14383 : json_table_column_definition_list:
14384 : json_table_column_definition
14385 820 : { $$ = list_make1($1); }
14386 : | json_table_column_definition_list ',' json_table_column_definition
14387 528 : { $$ = lappend($1, $3); }
14388 : ;
14389 :
14390 : json_table_column_definition:
14391 : ColId FOR ORDINALITY
14392 : {
14393 84 : JsonTableColumn *n = makeNode(JsonTableColumn);
14394 :
14395 84 : n->coltype = JTC_FOR_ORDINALITY;
14396 84 : n->name = $1;
14397 84 : n->location = @1;
14398 84 : $$ = (Node *) n;
14399 : }
14400 : | ColId Typename
14401 : json_table_column_path_clause_opt
14402 : json_wrapper_behavior
14403 : json_quotes_clause_opt
14404 : json_behavior_clause_opt
14405 : {
14406 728 : JsonTableColumn *n = makeNode(JsonTableColumn);
14407 :
14408 728 : n->coltype = JTC_REGULAR;
14409 728 : n->name = $1;
14410 728 : n->typeName = $2;
14411 728 : n->format = makeJsonFormat(JS_FORMAT_DEFAULT, JS_ENC_DEFAULT, -1);
14412 728 : n->pathspec = (JsonTablePathSpec *) $3;
14413 728 : n->wrapper = $4;
14414 728 : n->quotes = $5;
14415 728 : n->on_empty = (JsonBehavior *) linitial($6);
14416 728 : n->on_error = (JsonBehavior *) lsecond($6);
14417 728 : n->location = @1;
14418 728 : $$ = (Node *) n;
14419 : }
14420 : | ColId Typename json_format_clause
14421 : json_table_column_path_clause_opt
14422 : json_wrapper_behavior
14423 : json_quotes_clause_opt
14424 : json_behavior_clause_opt
14425 : {
14426 108 : JsonTableColumn *n = makeNode(JsonTableColumn);
14427 :
14428 108 : n->coltype = JTC_FORMATTED;
14429 108 : n->name = $1;
14430 108 : n->typeName = $2;
14431 108 : n->format = (JsonFormat *) $3;
14432 108 : n->pathspec = (JsonTablePathSpec *) $4;
14433 108 : n->wrapper = $5;
14434 108 : n->quotes = $6;
14435 108 : n->on_empty = (JsonBehavior *) linitial($7);
14436 108 : n->on_error = (JsonBehavior *) lsecond($7);
14437 108 : n->location = @1;
14438 108 : $$ = (Node *) n;
14439 : }
14440 : | ColId Typename
14441 : EXISTS json_table_column_path_clause_opt
14442 : json_on_error_clause_opt
14443 : {
14444 138 : JsonTableColumn *n = makeNode(JsonTableColumn);
14445 :
14446 138 : n->coltype = JTC_EXISTS;
14447 138 : n->name = $1;
14448 138 : n->typeName = $2;
14449 138 : n->format = makeJsonFormat(JS_FORMAT_DEFAULT, JS_ENC_DEFAULT, -1);
14450 138 : n->wrapper = JSW_NONE;
14451 138 : n->quotes = JS_QUOTES_UNSPEC;
14452 138 : n->pathspec = (JsonTablePathSpec *) $4;
14453 138 : n->on_empty = NULL;
14454 138 : n->on_error = (JsonBehavior *) $5;
14455 138 : n->location = @1;
14456 138 : $$ = (Node *) n;
14457 : }
14458 : | NESTED path_opt Sconst
14459 : COLUMNS '(' json_table_column_definition_list ')'
14460 : {
14461 144 : JsonTableColumn *n = makeNode(JsonTableColumn);
14462 :
14463 144 : n->coltype = JTC_NESTED;
14464 288 : n->pathspec = (JsonTablePathSpec *)
14465 144 : makeJsonTablePathSpec($3, NULL, @3, -1);
14466 144 : n->columns = $6;
14467 144 : n->location = @1;
14468 144 : $$ = (Node *) n;
14469 : }
14470 : | NESTED path_opt Sconst AS name
14471 : COLUMNS '(' json_table_column_definition_list ')'
14472 : {
14473 146 : JsonTableColumn *n = makeNode(JsonTableColumn);
14474 :
14475 146 : n->coltype = JTC_NESTED;
14476 292 : n->pathspec = (JsonTablePathSpec *)
14477 146 : makeJsonTablePathSpec($3, $5, @3, @5);
14478 146 : n->columns = $8;
14479 146 : n->location = @1;
14480 146 : $$ = (Node *) n;
14481 : }
14482 : ;
14483 :
14484 : path_opt:
14485 : PATH
14486 : | /* EMPTY */
14487 : ;
14488 :
14489 : json_table_column_path_clause_opt:
14490 : PATH Sconst
14491 828 : { $$ = (Node *) makeJsonTablePathSpec($2, NULL, @2, -1); }
14492 : | /* EMPTY */
14493 152 : { $$ = NULL; }
14494 : ;
14495 :
14496 : /*****************************************************************************
14497 : *
14498 : * Type syntax
14499 : * SQL introduces a large amount of type-specific syntax.
14500 : * Define individual clauses to handle these cases, and use
14501 : * the generic case to handle regular type-extensible Postgres syntax.
14502 : * - thomas 1997-10-10
14503 : *
14504 : *****************************************************************************/
14505 :
14506 : Typename: SimpleTypename opt_array_bounds
14507 : {
14508 518088 : $$ = $1;
14509 518088 : $$->arrayBounds = $2;
14510 : }
14511 : | SETOF SimpleTypename opt_array_bounds
14512 : {
14513 2356 : $$ = $2;
14514 2356 : $$->arrayBounds = $3;
14515 2356 : $$->setof = true;
14516 : }
14517 : /* SQL standard syntax, currently only one-dimensional */
14518 : | SimpleTypename ARRAY '[' Iconst ']'
14519 : {
14520 6 : $$ = $1;
14521 6 : $$->arrayBounds = list_make1(makeInteger($4));
14522 : }
14523 : | SETOF SimpleTypename ARRAY '[' Iconst ']'
14524 : {
14525 0 : $$ = $2;
14526 0 : $$->arrayBounds = list_make1(makeInteger($5));
14527 0 : $$->setof = true;
14528 : }
14529 : | SimpleTypename ARRAY
14530 : {
14531 0 : $$ = $1;
14532 0 : $$->arrayBounds = list_make1(makeInteger(-1));
14533 : }
14534 : | SETOF SimpleTypename ARRAY
14535 : {
14536 0 : $$ = $2;
14537 0 : $$->arrayBounds = list_make1(makeInteger(-1));
14538 0 : $$->setof = true;
14539 : }
14540 : ;
14541 :
14542 : opt_array_bounds:
14543 : opt_array_bounds '[' ']'
14544 14482 : { $$ = lappend($1, makeInteger(-1)); }
14545 : | opt_array_bounds '[' Iconst ']'
14546 62 : { $$ = lappend($1, makeInteger($3)); }
14547 : | /*EMPTY*/
14548 520444 : { $$ = NIL; }
14549 : ;
14550 :
14551 : SimpleTypename:
14552 407816 : GenericType { $$ = $1; }
14553 96984 : | Numeric { $$ = $1; }
14554 1972 : | Bit { $$ = $1; }
14555 3014 : | Character { $$ = $1; }
14556 5316 : | ConstDatetime { $$ = $1; }
14557 : | ConstInterval opt_interval
14558 : {
14559 3866 : $$ = $1;
14560 3866 : $$->typmods = $2;
14561 : }
14562 : | ConstInterval '(' Iconst ')'
14563 : {
14564 0 : $$ = $1;
14565 0 : $$->typmods = list_make2(makeIntConst(INTERVAL_FULL_RANGE, -1),
14566 : makeIntConst($3, @3));
14567 : }
14568 1890 : | JsonType { $$ = $1; }
14569 : ;
14570 :
14571 : /* We have a separate ConstTypename to allow defaulting fixed-length
14572 : * types such as CHAR() and BIT() to an unspecified length.
14573 : * SQL9x requires that these default to a length of one, but this
14574 : * makes no sense for constructs like CHAR 'hi' and BIT '0101',
14575 : * where there is an obvious better choice to make.
14576 : * Note that ConstInterval is not included here since it must
14577 : * be pushed up higher in the rules to accommodate the postfix
14578 : * options (e.g. INTERVAL '1' YEAR). Likewise, we have to handle
14579 : * the generic-type-name case in AexprConst to avoid premature
14580 : * reduce/reduce conflicts against function names.
14581 : */
14582 : ConstTypename:
14583 78 : Numeric { $$ = $1; }
14584 0 : | ConstBit { $$ = $1; }
14585 34 : | ConstCharacter { $$ = $1; }
14586 2798 : | ConstDatetime { $$ = $1; }
14587 264 : | JsonType { $$ = $1; }
14588 : ;
14589 :
14590 : /*
14591 : * GenericType covers all type names that don't have special syntax mandated
14592 : * by the standard, including qualified names. We also allow type modifiers.
14593 : * To avoid parsing conflicts against function invocations, the modifiers
14594 : * have to be shown as expr_list here, but parse analysis will only accept
14595 : * constants for them.
14596 : */
14597 : GenericType:
14598 : type_function_name opt_type_modifiers
14599 : {
14600 291608 : $$ = makeTypeName($1);
14601 291608 : $$->typmods = $2;
14602 291608 : $$->location = @1;
14603 : }
14604 : | type_function_name attrs opt_type_modifiers
14605 : {
14606 116208 : $$ = makeTypeNameFromNameList(lcons(makeString($1), $2));
14607 116208 : $$->typmods = $3;
14608 116208 : $$->location = @1;
14609 : }
14610 : ;
14611 :
14612 1350 : opt_type_modifiers: '(' expr_list ')' { $$ = $2; }
14613 412662 : | /* EMPTY */ { $$ = NIL; }
14614 : ;
14615 :
14616 : /*
14617 : * SQL numeric data types
14618 : */
14619 : Numeric: INT_P
14620 : {
14621 38442 : $$ = SystemTypeName("int4");
14622 38442 : $$->location = @1;
14623 : }
14624 : | INTEGER
14625 : {
14626 24998 : $$ = SystemTypeName("int4");
14627 24998 : $$->location = @1;
14628 : }
14629 : | SMALLINT
14630 : {
14631 1422 : $$ = SystemTypeName("int2");
14632 1422 : $$->location = @1;
14633 : }
14634 : | BIGINT
14635 : {
14636 5106 : $$ = SystemTypeName("int8");
14637 5106 : $$->location = @1;
14638 : }
14639 : | REAL
14640 : {
14641 6936 : $$ = SystemTypeName("float4");
14642 6936 : $$->location = @1;
14643 : }
14644 : | FLOAT_P opt_float
14645 : {
14646 538 : $$ = $2;
14647 538 : $$->location = @1;
14648 : }
14649 : | DOUBLE_P PRECISION
14650 : {
14651 766 : $$ = SystemTypeName("float8");
14652 766 : $$->location = @1;
14653 : }
14654 : | DECIMAL_P opt_type_modifiers
14655 : {
14656 36 : $$ = SystemTypeName("numeric");
14657 36 : $$->typmods = $2;
14658 36 : $$->location = @1;
14659 : }
14660 : | DEC opt_type_modifiers
14661 : {
14662 0 : $$ = SystemTypeName("numeric");
14663 0 : $$->typmods = $2;
14664 0 : $$->location = @1;
14665 : }
14666 : | NUMERIC opt_type_modifiers
14667 : {
14668 6160 : $$ = SystemTypeName("numeric");
14669 6160 : $$->typmods = $2;
14670 6160 : $$->location = @1;
14671 : }
14672 : | BOOLEAN_P
14673 : {
14674 12658 : $$ = SystemTypeName("bool");
14675 12658 : $$->location = @1;
14676 : }
14677 : ;
14678 :
14679 : opt_float: '(' Iconst ')'
14680 : {
14681 : /*
14682 : * Check FLOAT() precision limits assuming IEEE floating
14683 : * types - thomas 1997-09-18
14684 : */
14685 2 : if ($2 < 1)
14686 0 : ereport(ERROR,
14687 : (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
14688 : errmsg("precision for type float must be at least 1 bit"),
14689 : parser_errposition(@2)));
14690 2 : else if ($2 <= 24)
14691 2 : $$ = SystemTypeName("float4");
14692 0 : else if ($2 <= 53)
14693 0 : $$ = SystemTypeName("float8");
14694 : else
14695 0 : ereport(ERROR,
14696 : (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
14697 : errmsg("precision for type float must be less than 54 bits"),
14698 : parser_errposition(@2)));
14699 : }
14700 : | /*EMPTY*/
14701 : {
14702 536 : $$ = SystemTypeName("float8");
14703 : }
14704 : ;
14705 :
14706 : /*
14707 : * SQL bit-field data types
14708 : * The following implements BIT() and BIT VARYING().
14709 : */
14710 : Bit: BitWithLength
14711 : {
14712 1696 : $$ = $1;
14713 : }
14714 : | BitWithoutLength
14715 : {
14716 276 : $$ = $1;
14717 : }
14718 : ;
14719 :
14720 : /* ConstBit is like Bit except "BIT" defaults to unspecified length */
14721 : /* See notes for ConstCharacter, which addresses same issue for "CHAR" */
14722 : ConstBit: BitWithLength
14723 : {
14724 0 : $$ = $1;
14725 : }
14726 : | BitWithoutLength
14727 : {
14728 0 : $$ = $1;
14729 0 : $$->typmods = NIL;
14730 : }
14731 : ;
14732 :
14733 : BitWithLength:
14734 : BIT opt_varying '(' expr_list ')'
14735 : {
14736 : char *typname;
14737 :
14738 1696 : typname = $2 ? "varbit" : "bit";
14739 1696 : $$ = SystemTypeName(typname);
14740 1696 : $$->typmods = $4;
14741 1696 : $$->location = @1;
14742 : }
14743 : ;
14744 :
14745 : BitWithoutLength:
14746 : BIT opt_varying
14747 : {
14748 : /* bit defaults to bit(1), varbit to no limit */
14749 276 : if ($2)
14750 : {
14751 20 : $$ = SystemTypeName("varbit");
14752 : }
14753 : else
14754 : {
14755 256 : $$ = SystemTypeName("bit");
14756 256 : $$->typmods = list_make1(makeIntConst(1, -1));
14757 : }
14758 276 : $$->location = @1;
14759 : }
14760 : ;
14761 :
14762 :
14763 : /*
14764 : * SQL character data types
14765 : * The following implements CHAR() and VARCHAR().
14766 : */
14767 : Character: CharacterWithLength
14768 : {
14769 1724 : $$ = $1;
14770 : }
14771 : | CharacterWithoutLength
14772 : {
14773 1290 : $$ = $1;
14774 : }
14775 : ;
14776 :
14777 : ConstCharacter: CharacterWithLength
14778 : {
14779 12 : $$ = $1;
14780 : }
14781 : | CharacterWithoutLength
14782 : {
14783 : /* Length was not specified so allow to be unrestricted.
14784 : * This handles problems with fixed-length (bpchar) strings
14785 : * which in column definitions must default to a length
14786 : * of one, but should not be constrained if the length
14787 : * was not specified.
14788 : */
14789 22 : $$ = $1;
14790 22 : $$->typmods = NIL;
14791 : }
14792 : ;
14793 :
14794 : CharacterWithLength: character '(' Iconst ')'
14795 : {
14796 1736 : $$ = SystemTypeName($1);
14797 1736 : $$->typmods = list_make1(makeIntConst($3, @3));
14798 1736 : $$->location = @1;
14799 : }
14800 : ;
14801 :
14802 : CharacterWithoutLength: character
14803 : {
14804 1312 : $$ = SystemTypeName($1);
14805 : /* char defaults to char(1), varchar to no limit */
14806 1312 : if (strcmp($1, "bpchar") == 0)
14807 256 : $$->typmods = list_make1(makeIntConst(1, -1));
14808 1312 : $$->location = @1;
14809 : }
14810 : ;
14811 :
14812 : character: CHARACTER opt_varying
14813 566 : { $$ = $2 ? "varchar": "bpchar"; }
14814 : | CHAR_P opt_varying
14815 1172 : { $$ = $2 ? "varchar": "bpchar"; }
14816 : | VARCHAR
14817 1306 : { $$ = "varchar"; }
14818 : | NATIONAL CHARACTER opt_varying
14819 0 : { $$ = $3 ? "varchar": "bpchar"; }
14820 : | NATIONAL CHAR_P opt_varying
14821 0 : { $$ = $3 ? "varchar": "bpchar"; }
14822 : | NCHAR opt_varying
14823 4 : { $$ = $2 ? "varchar": "bpchar"; }
14824 : ;
14825 :
14826 : opt_varying:
14827 458 : VARYING { $$ = true; }
14828 3256 : | /*EMPTY*/ { $$ = false; }
14829 : ;
14830 :
14831 : /*
14832 : * SQL date/time types
14833 : */
14834 : ConstDatetime:
14835 : TIMESTAMP '(' Iconst ')' opt_timezone
14836 : {
14837 134 : if ($5)
14838 110 : $$ = SystemTypeName("timestamptz");
14839 : else
14840 24 : $$ = SystemTypeName("timestamp");
14841 134 : $$->typmods = list_make1(makeIntConst($3, @3));
14842 134 : $$->location = @1;
14843 : }
14844 : | TIMESTAMP opt_timezone
14845 : {
14846 5366 : if ($2)
14847 1454 : $$ = SystemTypeName("timestamptz");
14848 : else
14849 3912 : $$ = SystemTypeName("timestamp");
14850 5366 : $$->location = @1;
14851 : }
14852 : | TIME '(' Iconst ')' opt_timezone
14853 : {
14854 22 : if ($5)
14855 8 : $$ = SystemTypeName("timetz");
14856 : else
14857 14 : $$ = SystemTypeName("time");
14858 22 : $$->typmods = list_make1(makeIntConst($3, @3));
14859 22 : $$->location = @1;
14860 : }
14861 : | TIME opt_timezone
14862 : {
14863 2592 : if ($2)
14864 348 : $$ = SystemTypeName("timetz");
14865 : else
14866 2244 : $$ = SystemTypeName("time");
14867 2592 : $$->location = @1;
14868 : }
14869 : ;
14870 :
14871 : ConstInterval:
14872 : INTERVAL
14873 : {
14874 7176 : $$ = SystemTypeName("interval");
14875 7176 : $$->location = @1;
14876 : }
14877 : ;
14878 :
14879 : opt_timezone:
14880 1920 : WITH_LA TIME ZONE { $$ = true; }
14881 624 : | WITHOUT_LA TIME ZONE { $$ = false; }
14882 5570 : | /*EMPTY*/ { $$ = false; }
14883 : ;
14884 :
14885 : opt_interval:
14886 : YEAR_P
14887 12 : { $$ = list_make1(makeIntConst(INTERVAL_MASK(YEAR), @1)); }
14888 : | MONTH_P
14889 18 : { $$ = list_make1(makeIntConst(INTERVAL_MASK(MONTH), @1)); }
14890 : | DAY_P
14891 18 : { $$ = list_make1(makeIntConst(INTERVAL_MASK(DAY), @1)); }
14892 : | HOUR_P
14893 12 : { $$ = list_make1(makeIntConst(INTERVAL_MASK(HOUR), @1)); }
14894 : | MINUTE_P
14895 12 : { $$ = list_make1(makeIntConst(INTERVAL_MASK(MINUTE), @1)); }
14896 : | interval_second
14897 36 : { $$ = $1; }
14898 : | YEAR_P TO MONTH_P
14899 : {
14900 18 : $$ = list_make1(makeIntConst(INTERVAL_MASK(YEAR) |
14901 : INTERVAL_MASK(MONTH), @1));
14902 : }
14903 : | DAY_P TO HOUR_P
14904 : {
14905 24 : $$ = list_make1(makeIntConst(INTERVAL_MASK(DAY) |
14906 : INTERVAL_MASK(HOUR), @1));
14907 : }
14908 : | DAY_P TO MINUTE_P
14909 : {
14910 24 : $$ = list_make1(makeIntConst(INTERVAL_MASK(DAY) |
14911 : INTERVAL_MASK(HOUR) |
14912 : INTERVAL_MASK(MINUTE), @1));
14913 : }
14914 : | DAY_P TO interval_second
14915 : {
14916 48 : $$ = $3;
14917 48 : linitial($$) = makeIntConst(INTERVAL_MASK(DAY) |
14918 : INTERVAL_MASK(HOUR) |
14919 : INTERVAL_MASK(MINUTE) |
14920 48 : INTERVAL_MASK(SECOND), @1);
14921 : }
14922 : | HOUR_P TO MINUTE_P
14923 : {
14924 18 : $$ = list_make1(makeIntConst(INTERVAL_MASK(HOUR) |
14925 : INTERVAL_MASK(MINUTE), @1));
14926 : }
14927 : | HOUR_P TO interval_second
14928 : {
14929 36 : $$ = $3;
14930 36 : linitial($$) = makeIntConst(INTERVAL_MASK(HOUR) |
14931 : INTERVAL_MASK(MINUTE) |
14932 36 : INTERVAL_MASK(SECOND), @1);
14933 : }
14934 : | MINUTE_P TO interval_second
14935 : {
14936 66 : $$ = $3;
14937 66 : linitial($$) = makeIntConst(INTERVAL_MASK(MINUTE) |
14938 66 : INTERVAL_MASK(SECOND), @1);
14939 : }
14940 : | /*EMPTY*/
14941 6822 : { $$ = NIL; }
14942 : ;
14943 :
14944 : interval_second:
14945 : SECOND_P
14946 : {
14947 102 : $$ = list_make1(makeIntConst(INTERVAL_MASK(SECOND), @1));
14948 : }
14949 : | SECOND_P '(' Iconst ')'
14950 : {
14951 84 : $$ = list_make2(makeIntConst(INTERVAL_MASK(SECOND), @1),
14952 : makeIntConst($3, @3));
14953 : }
14954 : ;
14955 :
14956 : JsonType:
14957 : JSON
14958 : {
14959 2154 : $$ = SystemTypeName("json");
14960 2154 : $$->location = @1;
14961 : }
14962 : ;
14963 :
14964 : /*****************************************************************************
14965 : *
14966 : * expression grammar
14967 : *
14968 : *****************************************************************************/
14969 :
14970 : /*
14971 : * General expressions
14972 : * This is the heart of the expression syntax.
14973 : *
14974 : * We have two expression types: a_expr is the unrestricted kind, and
14975 : * b_expr is a subset that must be used in some places to avoid shift/reduce
14976 : * conflicts. For example, we can't do BETWEEN as "BETWEEN a_expr AND a_expr"
14977 : * because that use of AND conflicts with AND as a boolean operator. So,
14978 : * b_expr is used in BETWEEN and we remove boolean keywords from b_expr.
14979 : *
14980 : * Note that '(' a_expr ')' is a b_expr, so an unrestricted expression can
14981 : * always be used by surrounding it with parens.
14982 : *
14983 : * c_expr is all the productions that are common to a_expr and b_expr;
14984 : * it's factored out just to eliminate redundant coding.
14985 : *
14986 : * Be careful of productions involving more than one terminal token.
14987 : * By default, bison will assign such productions the precedence of their
14988 : * last terminal, but in nearly all cases you want it to be the precedence
14989 : * of the first terminal instead; otherwise you will not get the behavior
14990 : * you expect! So we use %prec annotations freely to set precedences.
14991 : */
14992 3638098 : a_expr: c_expr { $$ = $1; }
14993 : | a_expr TYPECAST Typename
14994 233854 : { $$ = makeTypeCast($1, $3, @2); }
14995 : | a_expr COLLATE any_name
14996 : {
14997 9018 : CollateClause *n = makeNode(CollateClause);
14998 :
14999 9018 : n->arg = $1;
15000 9018 : n->collname = $3;
15001 9018 : n->location = @2;
15002 9018 : $$ = (Node *) n;
15003 : }
15004 : | a_expr AT TIME ZONE a_expr %prec AT
15005 : {
15006 408 : $$ = (Node *) makeFuncCall(SystemFuncName("timezone"),
15007 408 : list_make2($5, $1),
15008 : COERCE_SQL_SYNTAX,
15009 408 : @2);
15010 : }
15011 : | a_expr AT LOCAL %prec AT
15012 : {
15013 42 : $$ = (Node *) makeFuncCall(SystemFuncName("timezone"),
15014 42 : list_make1($1),
15015 : COERCE_SQL_SYNTAX,
15016 : -1);
15017 : }
15018 : /*
15019 : * These operators must be called out explicitly in order to make use
15020 : * of bison's automatic operator-precedence handling. All other
15021 : * operator names are handled by the generic productions using "Op",
15022 : * below; and all those operators will have the same precedence.
15023 : *
15024 : * If you add more explicitly-known operators, be sure to add them
15025 : * also to b_expr and to the MathOp list below.
15026 : */
15027 : | '+' a_expr %prec UMINUS
15028 12 : { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "+", NULL, $2, @1); }
15029 : | '-' a_expr %prec UMINUS
15030 9154 : { $$ = doNegate($2, @1); }
15031 : | a_expr '+' a_expr
15032 14138 : { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "+", $1, $3, @2); }
15033 : | a_expr '-' a_expr
15034 4514 : { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "-", $1, $3, @2); }
15035 : | a_expr '*' a_expr
15036 6294 : { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "*", $1, $3, @2); }
15037 : | a_expr '/' a_expr
15038 3430 : { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "/", $1, $3, @2); }
15039 : | a_expr '%' a_expr
15040 2844 : { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "%", $1, $3, @2); }
15041 : | a_expr '^' a_expr
15042 476 : { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "^", $1, $3, @2); }
15043 : | a_expr '<' a_expr
15044 10554 : { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "<", $1, $3, @2); }
15045 : | a_expr '>' a_expr
15046 16576 : { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, ">", $1, $3, @2); }
15047 : | a_expr '=' a_expr
15048 387556 : { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "=", $1, $3, @2); }
15049 : | a_expr LESS_EQUALS a_expr
15050 5242 : { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "<=", $1, $3, @2); }
15051 : | a_expr GREATER_EQUALS a_expr
15052 7126 : { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, ">=", $1, $3, @2); }
15053 : | a_expr NOT_EQUALS a_expr
15054 39650 : { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "<>", $1, $3, @2); }
15055 :
15056 : | a_expr qual_Op a_expr %prec Op
15057 58604 : { $$ = (Node *) makeA_Expr(AEXPR_OP, $2, $1, $3, @2); }
15058 : | qual_Op a_expr %prec Op
15059 228 : { $$ = (Node *) makeA_Expr(AEXPR_OP, $1, NULL, $2, @1); }
15060 :
15061 : | a_expr AND a_expr
15062 231614 : { $$ = makeAndExpr($1, $3, @2); }
15063 : | a_expr OR a_expr
15064 15958 : { $$ = makeOrExpr($1, $3, @2); }
15065 : | NOT a_expr
15066 15998 : { $$ = makeNotExpr($2, @1); }
15067 : | NOT_LA a_expr %prec NOT
15068 0 : { $$ = makeNotExpr($2, @1); }
15069 :
15070 : | a_expr LIKE a_expr
15071 : {
15072 1966 : $$ = (Node *) makeSimpleA_Expr(AEXPR_LIKE, "~~",
15073 1966 : $1, $3, @2);
15074 : }
15075 : | a_expr LIKE a_expr ESCAPE a_expr %prec LIKE
15076 : {
15077 96 : FuncCall *n = makeFuncCall(SystemFuncName("like_escape"),
15078 96 : list_make2($3, $5),
15079 : COERCE_EXPLICIT_CALL,
15080 96 : @2);
15081 96 : $$ = (Node *) makeSimpleA_Expr(AEXPR_LIKE, "~~",
15082 96 : $1, (Node *) n, @2);
15083 : }
15084 : | a_expr NOT_LA LIKE a_expr %prec NOT_LA
15085 : {
15086 198 : $$ = (Node *) makeSimpleA_Expr(AEXPR_LIKE, "!~~",
15087 198 : $1, $4, @2);
15088 : }
15089 : | a_expr NOT_LA LIKE a_expr ESCAPE a_expr %prec NOT_LA
15090 : {
15091 96 : FuncCall *n = makeFuncCall(SystemFuncName("like_escape"),
15092 96 : list_make2($4, $6),
15093 : COERCE_EXPLICIT_CALL,
15094 96 : @2);
15095 96 : $$ = (Node *) makeSimpleA_Expr(AEXPR_LIKE, "!~~",
15096 96 : $1, (Node *) n, @2);
15097 : }
15098 : | a_expr ILIKE a_expr
15099 : {
15100 174 : $$ = (Node *) makeSimpleA_Expr(AEXPR_ILIKE, "~~*",
15101 174 : $1, $3, @2);
15102 : }
15103 : | a_expr ILIKE a_expr ESCAPE a_expr %prec ILIKE
15104 : {
15105 0 : FuncCall *n = makeFuncCall(SystemFuncName("like_escape"),
15106 0 : list_make2($3, $5),
15107 : COERCE_EXPLICIT_CALL,
15108 0 : @2);
15109 0 : $$ = (Node *) makeSimpleA_Expr(AEXPR_ILIKE, "~~*",
15110 0 : $1, (Node *) n, @2);
15111 : }
15112 : | a_expr NOT_LA ILIKE a_expr %prec NOT_LA
15113 : {
15114 30 : $$ = (Node *) makeSimpleA_Expr(AEXPR_ILIKE, "!~~*",
15115 30 : $1, $4, @2);
15116 : }
15117 : | a_expr NOT_LA ILIKE a_expr ESCAPE a_expr %prec NOT_LA
15118 : {
15119 0 : FuncCall *n = makeFuncCall(SystemFuncName("like_escape"),
15120 0 : list_make2($4, $6),
15121 : COERCE_EXPLICIT_CALL,
15122 0 : @2);
15123 0 : $$ = (Node *) makeSimpleA_Expr(AEXPR_ILIKE, "!~~*",
15124 0 : $1, (Node *) n, @2);
15125 : }
15126 :
15127 : | a_expr SIMILAR TO a_expr %prec SIMILAR
15128 : {
15129 88 : FuncCall *n = makeFuncCall(SystemFuncName("similar_to_escape"),
15130 88 : list_make1($4),
15131 : COERCE_EXPLICIT_CALL,
15132 88 : @2);
15133 88 : $$ = (Node *) makeSimpleA_Expr(AEXPR_SIMILAR, "~",
15134 88 : $1, (Node *) n, @2);
15135 : }
15136 : | a_expr SIMILAR TO a_expr ESCAPE a_expr %prec SIMILAR
15137 : {
15138 30 : FuncCall *n = makeFuncCall(SystemFuncName("similar_to_escape"),
15139 30 : list_make2($4, $6),
15140 : COERCE_EXPLICIT_CALL,
15141 30 : @2);
15142 30 : $$ = (Node *) makeSimpleA_Expr(AEXPR_SIMILAR, "~",
15143 30 : $1, (Node *) n, @2);
15144 : }
15145 : | a_expr NOT_LA SIMILAR TO a_expr %prec NOT_LA
15146 : {
15147 0 : FuncCall *n = makeFuncCall(SystemFuncName("similar_to_escape"),
15148 0 : list_make1($5),
15149 : COERCE_EXPLICIT_CALL,
15150 0 : @2);
15151 0 : $$ = (Node *) makeSimpleA_Expr(AEXPR_SIMILAR, "!~",
15152 0 : $1, (Node *) n, @2);
15153 : }
15154 : | a_expr NOT_LA SIMILAR TO a_expr ESCAPE a_expr %prec NOT_LA
15155 : {
15156 0 : FuncCall *n = makeFuncCall(SystemFuncName("similar_to_escape"),
15157 0 : list_make2($5, $7),
15158 : COERCE_EXPLICIT_CALL,
15159 0 : @2);
15160 0 : $$ = (Node *) makeSimpleA_Expr(AEXPR_SIMILAR, "!~",
15161 0 : $1, (Node *) n, @2);
15162 : }
15163 :
15164 : /* NullTest clause
15165 : * Define SQL-style Null test clause.
15166 : * Allow two forms described in the standard:
15167 : * a IS NULL
15168 : * a IS NOT NULL
15169 : * Allow two SQL extensions
15170 : * a ISNULL
15171 : * a NOTNULL
15172 : */
15173 : | a_expr IS NULL_P %prec IS
15174 : {
15175 5240 : NullTest *n = makeNode(NullTest);
15176 :
15177 5240 : n->arg = (Expr *) $1;
15178 5240 : n->nulltesttype = IS_NULL;
15179 5240 : n->location = @2;
15180 5240 : $$ = (Node *) n;
15181 : }
15182 : | a_expr ISNULL
15183 : {
15184 96 : NullTest *n = makeNode(NullTest);
15185 :
15186 96 : n->arg = (Expr *) $1;
15187 96 : n->nulltesttype = IS_NULL;
15188 96 : n->location = @2;
15189 96 : $$ = (Node *) n;
15190 : }
15191 : | a_expr IS NOT NULL_P %prec IS
15192 : {
15193 12868 : NullTest *n = makeNode(NullTest);
15194 :
15195 12868 : n->arg = (Expr *) $1;
15196 12868 : n->nulltesttype = IS_NOT_NULL;
15197 12868 : n->location = @2;
15198 12868 : $$ = (Node *) n;
15199 : }
15200 : | a_expr NOTNULL
15201 : {
15202 6 : NullTest *n = makeNode(NullTest);
15203 :
15204 6 : n->arg = (Expr *) $1;
15205 6 : n->nulltesttype = IS_NOT_NULL;
15206 6 : n->location = @2;
15207 6 : $$ = (Node *) n;
15208 : }
15209 : | row OVERLAPS row
15210 : {
15211 966 : if (list_length($1) != 2)
15212 0 : ereport(ERROR,
15213 : (errcode(ERRCODE_SYNTAX_ERROR),
15214 : errmsg("wrong number of parameters on left side of OVERLAPS expression"),
15215 : parser_errposition(@1)));
15216 966 : if (list_length($3) != 2)
15217 0 : ereport(ERROR,
15218 : (errcode(ERRCODE_SYNTAX_ERROR),
15219 : errmsg("wrong number of parameters on right side of OVERLAPS expression"),
15220 : parser_errposition(@3)));
15221 966 : $$ = (Node *) makeFuncCall(SystemFuncName("overlaps"),
15222 966 : list_concat($1, $3),
15223 : COERCE_SQL_SYNTAX,
15224 966 : @2);
15225 : }
15226 : | a_expr IS TRUE_P %prec IS
15227 : {
15228 426 : BooleanTest *b = makeNode(BooleanTest);
15229 :
15230 426 : b->arg = (Expr *) $1;
15231 426 : b->booltesttype = IS_TRUE;
15232 426 : b->location = @2;
15233 426 : $$ = (Node *) b;
15234 : }
15235 : | a_expr IS NOT TRUE_P %prec IS
15236 : {
15237 140 : BooleanTest *b = makeNode(BooleanTest);
15238 :
15239 140 : b->arg = (Expr *) $1;
15240 140 : b->booltesttype = IS_NOT_TRUE;
15241 140 : b->location = @2;
15242 140 : $$ = (Node *) b;
15243 : }
15244 : | a_expr IS FALSE_P %prec IS
15245 : {
15246 154 : BooleanTest *b = makeNode(BooleanTest);
15247 :
15248 154 : b->arg = (Expr *) $1;
15249 154 : b->booltesttype = IS_FALSE;
15250 154 : b->location = @2;
15251 154 : $$ = (Node *) b;
15252 : }
15253 : | a_expr IS NOT FALSE_P %prec IS
15254 : {
15255 92 : BooleanTest *b = makeNode(BooleanTest);
15256 :
15257 92 : b->arg = (Expr *) $1;
15258 92 : b->booltesttype = IS_NOT_FALSE;
15259 92 : b->location = @2;
15260 92 : $$ = (Node *) b;
15261 : }
15262 : | a_expr IS UNKNOWN %prec IS
15263 : {
15264 52 : BooleanTest *b = makeNode(BooleanTest);
15265 :
15266 52 : b->arg = (Expr *) $1;
15267 52 : b->booltesttype = IS_UNKNOWN;
15268 52 : b->location = @2;
15269 52 : $$ = (Node *) b;
15270 : }
15271 : | a_expr IS NOT UNKNOWN %prec IS
15272 : {
15273 48 : BooleanTest *b = makeNode(BooleanTest);
15274 :
15275 48 : b->arg = (Expr *) $1;
15276 48 : b->booltesttype = IS_NOT_UNKNOWN;
15277 48 : b->location = @2;
15278 48 : $$ = (Node *) b;
15279 : }
15280 : | a_expr IS DISTINCT FROM a_expr %prec IS
15281 : {
15282 1048 : $$ = (Node *) makeSimpleA_Expr(AEXPR_DISTINCT, "=", $1, $5, @2);
15283 : }
15284 : | a_expr IS NOT DISTINCT FROM a_expr %prec IS
15285 : {
15286 68 : $$ = (Node *) makeSimpleA_Expr(AEXPR_NOT_DISTINCT, "=", $1, $6, @2);
15287 : }
15288 : | a_expr BETWEEN opt_asymmetric b_expr AND a_expr %prec BETWEEN
15289 : {
15290 466 : $$ = (Node *) makeSimpleA_Expr(AEXPR_BETWEEN,
15291 : "BETWEEN",
15292 466 : $1,
15293 466 : (Node *) list_make2($4, $6),
15294 466 : @2);
15295 : }
15296 : | a_expr NOT_LA BETWEEN opt_asymmetric b_expr AND a_expr %prec NOT_LA
15297 : {
15298 12 : $$ = (Node *) makeSimpleA_Expr(AEXPR_NOT_BETWEEN,
15299 : "NOT BETWEEN",
15300 12 : $1,
15301 12 : (Node *) list_make2($5, $7),
15302 12 : @2);
15303 : }
15304 : | a_expr BETWEEN SYMMETRIC b_expr AND a_expr %prec BETWEEN
15305 : {
15306 12 : $$ = (Node *) makeSimpleA_Expr(AEXPR_BETWEEN_SYM,
15307 : "BETWEEN SYMMETRIC",
15308 12 : $1,
15309 12 : (Node *) list_make2($4, $6),
15310 12 : @2);
15311 : }
15312 : | a_expr NOT_LA BETWEEN SYMMETRIC b_expr AND a_expr %prec NOT_LA
15313 : {
15314 12 : $$ = (Node *) makeSimpleA_Expr(AEXPR_NOT_BETWEEN_SYM,
15315 : "NOT BETWEEN SYMMETRIC",
15316 12 : $1,
15317 12 : (Node *) list_make2($5, $7),
15318 12 : @2);
15319 : }
15320 : | a_expr IN_P select_with_parens
15321 : {
15322 : /* generate foo = ANY (subquery) */
15323 5486 : SubLink *n = makeNode(SubLink);
15324 :
15325 5486 : n->subselect = $3;
15326 5486 : n->subLinkType = ANY_SUBLINK;
15327 5486 : n->subLinkId = 0;
15328 5486 : n->testexpr = $1;
15329 5486 : n->operName = NIL; /* show it's IN not = ANY */
15330 5486 : n->location = @2;
15331 5486 : $$ = (Node *) n;
15332 : }
15333 : | a_expr IN_P '(' expr_list ')'
15334 : {
15335 : /* generate scalar IN expression */
15336 18580 : A_Expr *n = makeSimpleA_Expr(AEXPR_IN, "=", $1, (Node *) $4, @2);
15337 :
15338 18580 : n->rexpr_list_start = @3;
15339 18580 : n->rexpr_list_end = @5;
15340 18580 : $$ = (Node *) n;
15341 : }
15342 : | a_expr NOT_LA IN_P select_with_parens %prec NOT_LA
15343 : {
15344 : /* generate NOT (foo = ANY (subquery)) */
15345 120 : SubLink *n = makeNode(SubLink);
15346 :
15347 120 : n->subselect = $4;
15348 120 : n->subLinkType = ANY_SUBLINK;
15349 120 : n->subLinkId = 0;
15350 120 : n->testexpr = $1;
15351 120 : n->operName = NIL; /* show it's IN not = ANY */
15352 120 : n->location = @2;
15353 : /* Stick a NOT on top; must have same parse location */
15354 120 : $$ = makeNotExpr((Node *) n, @2);
15355 : }
15356 : | a_expr NOT_LA IN_P '(' expr_list ')'
15357 : {
15358 : /* generate scalar NOT IN expression */
15359 2658 : A_Expr *n = makeSimpleA_Expr(AEXPR_IN, "<>", $1, (Node *) $5, @2);
15360 :
15361 2658 : n->rexpr_list_start = @4;
15362 2658 : n->rexpr_list_end = @6;
15363 2658 : $$ = (Node *) n;
15364 : }
15365 : | a_expr subquery_Op sub_type select_with_parens %prec Op
15366 : {
15367 168 : SubLink *n = makeNode(SubLink);
15368 :
15369 168 : n->subLinkType = $3;
15370 168 : n->subLinkId = 0;
15371 168 : n->testexpr = $1;
15372 168 : n->operName = $2;
15373 168 : n->subselect = $4;
15374 168 : n->location = @2;
15375 168 : $$ = (Node *) n;
15376 : }
15377 : | a_expr subquery_Op sub_type '(' a_expr ')' %prec Op
15378 : {
15379 16822 : if ($3 == ANY_SUBLINK)
15380 16522 : $$ = (Node *) makeA_Expr(AEXPR_OP_ANY, $2, $1, $5, @2);
15381 : else
15382 300 : $$ = (Node *) makeA_Expr(AEXPR_OP_ALL, $2, $1, $5, @2);
15383 : }
15384 : | UNIQUE opt_unique_null_treatment select_with_parens
15385 : {
15386 : /* Not sure how to get rid of the parentheses
15387 : * but there are lots of shift/reduce errors without them.
15388 : *
15389 : * Should be able to implement this by plopping the entire
15390 : * select into a node, then transforming the target expressions
15391 : * from whatever they are into count(*), and testing the
15392 : * entire result equal to one.
15393 : * But, will probably implement a separate node in the executor.
15394 : */
15395 0 : ereport(ERROR,
15396 : (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
15397 : errmsg("UNIQUE predicate is not yet implemented"),
15398 : parser_errposition(@1)));
15399 : }
15400 : | a_expr IS DOCUMENT_P %prec IS
15401 : {
15402 18 : $$ = makeXmlExpr(IS_DOCUMENT, NULL, NIL,
15403 18 : list_make1($1), @2);
15404 : }
15405 : | a_expr IS NOT DOCUMENT_P %prec IS
15406 : {
15407 18 : $$ = makeNotExpr(makeXmlExpr(IS_DOCUMENT, NULL, NIL,
15408 18 : list_make1($1), @2),
15409 18 : @2);
15410 : }
15411 : | a_expr IS NORMALIZED %prec IS
15412 : {
15413 12 : $$ = (Node *) makeFuncCall(SystemFuncName("is_normalized"),
15414 12 : list_make1($1),
15415 : COERCE_SQL_SYNTAX,
15416 12 : @2);
15417 : }
15418 : | a_expr IS unicode_normal_form NORMALIZED %prec IS
15419 : {
15420 36 : $$ = (Node *) makeFuncCall(SystemFuncName("is_normalized"),
15421 36 : list_make2($1, makeStringConst($3, @3)),
15422 : COERCE_SQL_SYNTAX,
15423 36 : @2);
15424 : }
15425 : | a_expr IS NOT NORMALIZED %prec IS
15426 : {
15427 0 : $$ = makeNotExpr((Node *) makeFuncCall(SystemFuncName("is_normalized"),
15428 0 : list_make1($1),
15429 : COERCE_SQL_SYNTAX,
15430 0 : @2),
15431 0 : @2);
15432 : }
15433 : | a_expr IS NOT unicode_normal_form NORMALIZED %prec IS
15434 : {
15435 0 : $$ = makeNotExpr((Node *) makeFuncCall(SystemFuncName("is_normalized"),
15436 0 : list_make2($1, makeStringConst($4, @4)),
15437 : COERCE_SQL_SYNTAX,
15438 0 : @2),
15439 0 : @2);
15440 : }
15441 : | a_expr IS json_predicate_type_constraint
15442 : json_key_uniqueness_constraint_opt %prec IS
15443 : {
15444 304 : JsonFormat *format = makeJsonFormat(JS_FORMAT_DEFAULT, JS_ENC_DEFAULT, -1);
15445 :
15446 304 : $$ = makeJsonIsPredicate($1, format, $3, $4, @1);
15447 : }
15448 : /*
15449 : * Required by SQL/JSON, but there are conflicts
15450 : | a_expr
15451 : json_format_clause
15452 : IS json_predicate_type_constraint
15453 : json_key_uniqueness_constraint_opt %prec IS
15454 : {
15455 : $$ = makeJsonIsPredicate($1, $2, $4, $5, @1);
15456 : }
15457 : */
15458 : | a_expr IS NOT
15459 : json_predicate_type_constraint
15460 : json_key_uniqueness_constraint_opt %prec IS
15461 : {
15462 46 : JsonFormat *format = makeJsonFormat(JS_FORMAT_DEFAULT, JS_ENC_DEFAULT, -1);
15463 :
15464 46 : $$ = makeNotExpr(makeJsonIsPredicate($1, format, $4, $5, @1), @1);
15465 : }
15466 : /*
15467 : * Required by SQL/JSON, but there are conflicts
15468 : | a_expr
15469 : json_format_clause
15470 : IS NOT
15471 : json_predicate_type_constraint
15472 : json_key_uniqueness_constraint_opt %prec IS
15473 : {
15474 : $$ = makeNotExpr(makeJsonIsPredicate($1, $2, $5, $6, @1), @1);
15475 : }
15476 : */
15477 : | DEFAULT
15478 : {
15479 : /*
15480 : * The SQL spec only allows DEFAULT in "contextually typed
15481 : * expressions", but for us, it's easier to allow it in
15482 : * any a_expr and then throw error during parse analysis
15483 : * if it's in an inappropriate context. This way also
15484 : * lets us say something smarter than "syntax error".
15485 : */
15486 1528 : SetToDefault *n = makeNode(SetToDefault);
15487 :
15488 : /* parse analysis will fill in the rest */
15489 1528 : n->location = @1;
15490 1528 : $$ = (Node *) n;
15491 : }
15492 : ;
15493 :
15494 : /*
15495 : * Restricted expressions
15496 : *
15497 : * b_expr is a subset of the complete expression syntax defined by a_expr.
15498 : *
15499 : * Presently, AND, NOT, IS, and IN are the a_expr keywords that would
15500 : * cause trouble in the places where b_expr is used. For simplicity, we
15501 : * just eliminate all the boolean-keyword-operator productions from b_expr.
15502 : */
15503 : b_expr: c_expr
15504 3766 : { $$ = $1; }
15505 : | b_expr TYPECAST Typename
15506 212 : { $$ = makeTypeCast($1, $3, @2); }
15507 : | '+' b_expr %prec UMINUS
15508 0 : { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "+", NULL, $2, @1); }
15509 : | '-' b_expr %prec UMINUS
15510 66 : { $$ = doNegate($2, @1); }
15511 : | b_expr '+' b_expr
15512 36 : { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "+", $1, $3, @2); }
15513 : | b_expr '-' b_expr
15514 12 : { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "-", $1, $3, @2); }
15515 : | b_expr '*' b_expr
15516 12 : { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "*", $1, $3, @2); }
15517 : | b_expr '/' b_expr
15518 0 : { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "/", $1, $3, @2); }
15519 : | b_expr '%' b_expr
15520 0 : { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "%", $1, $3, @2); }
15521 : | b_expr '^' b_expr
15522 6 : { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "^", $1, $3, @2); }
15523 : | b_expr '<' b_expr
15524 0 : { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "<", $1, $3, @2); }
15525 : | b_expr '>' b_expr
15526 0 : { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, ">", $1, $3, @2); }
15527 : | b_expr '=' b_expr
15528 0 : { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "=", $1, $3, @2); }
15529 : | b_expr LESS_EQUALS b_expr
15530 0 : { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "<=", $1, $3, @2); }
15531 : | b_expr GREATER_EQUALS b_expr
15532 0 : { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, ">=", $1, $3, @2); }
15533 : | b_expr NOT_EQUALS b_expr
15534 0 : { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "<>", $1, $3, @2); }
15535 : | b_expr qual_Op b_expr %prec Op
15536 12 : { $$ = (Node *) makeA_Expr(AEXPR_OP, $2, $1, $3, @2); }
15537 : | qual_Op b_expr %prec Op
15538 0 : { $$ = (Node *) makeA_Expr(AEXPR_OP, $1, NULL, $2, @1); }
15539 : | b_expr IS DISTINCT FROM b_expr %prec IS
15540 : {
15541 0 : $$ = (Node *) makeSimpleA_Expr(AEXPR_DISTINCT, "=", $1, $5, @2);
15542 : }
15543 : | b_expr IS NOT DISTINCT FROM b_expr %prec IS
15544 : {
15545 0 : $$ = (Node *) makeSimpleA_Expr(AEXPR_NOT_DISTINCT, "=", $1, $6, @2);
15546 : }
15547 : | b_expr IS DOCUMENT_P %prec IS
15548 : {
15549 0 : $$ = makeXmlExpr(IS_DOCUMENT, NULL, NIL,
15550 0 : list_make1($1), @2);
15551 : }
15552 : | b_expr IS NOT DOCUMENT_P %prec IS
15553 : {
15554 0 : $$ = makeNotExpr(makeXmlExpr(IS_DOCUMENT, NULL, NIL,
15555 0 : list_make1($1), @2),
15556 0 : @2);
15557 : }
15558 : ;
15559 :
15560 : /*
15561 : * Productions that can be used in both a_expr and b_expr.
15562 : *
15563 : * Note: productions that refer recursively to a_expr or b_expr mostly
15564 : * cannot appear here. However, it's OK to refer to a_exprs that occur
15565 : * inside parentheses, such as function arguments; that cannot introduce
15566 : * ambiguity to the b_expr syntax.
15567 : */
15568 1794344 : c_expr: columnref { $$ = $1; }
15569 1228990 : | AexprConst { $$ = $1; }
15570 : | PARAM opt_indirection
15571 : {
15572 45944 : ParamRef *p = makeNode(ParamRef);
15573 :
15574 45944 : p->number = $1;
15575 45944 : p->location = @1;
15576 45944 : if ($2)
15577 : {
15578 1084 : A_Indirection *n = makeNode(A_Indirection);
15579 :
15580 1084 : n->arg = (Node *) p;
15581 1084 : n->indirection = check_indirection($2, yyscanner);
15582 1084 : $$ = (Node *) n;
15583 : }
15584 : else
15585 44860 : $$ = (Node *) p;
15586 : }
15587 : | '(' a_expr ')' opt_indirection
15588 : {
15589 89410 : if ($4)
15590 : {
15591 12344 : A_Indirection *n = makeNode(A_Indirection);
15592 :
15593 12344 : n->arg = $2;
15594 12344 : n->indirection = check_indirection($4, yyscanner);
15595 12344 : $$ = (Node *) n;
15596 : }
15597 : else
15598 77066 : $$ = $2;
15599 : }
15600 : | case_expr
15601 39014 : { $$ = $1; }
15602 : | func_expr
15603 388768 : { $$ = $1; }
15604 : | select_with_parens %prec UMINUS
15605 : {
15606 27360 : SubLink *n = makeNode(SubLink);
15607 :
15608 27360 : n->subLinkType = EXPR_SUBLINK;
15609 27360 : n->subLinkId = 0;
15610 27360 : n->testexpr = NULL;
15611 27360 : n->operName = NIL;
15612 27360 : n->subselect = $1;
15613 27360 : n->location = @1;
15614 27360 : $$ = (Node *) n;
15615 : }
15616 : | select_with_parens indirection
15617 : {
15618 : /*
15619 : * Because the select_with_parens nonterminal is designed
15620 : * to "eat" as many levels of parens as possible, the
15621 : * '(' a_expr ')' opt_indirection production above will
15622 : * fail to match a sub-SELECT with indirection decoration;
15623 : * the sub-SELECT won't be regarded as an a_expr as long
15624 : * as there are parens around it. To support applying
15625 : * subscripting or field selection to a sub-SELECT result,
15626 : * we need this redundant-looking production.
15627 : */
15628 18 : SubLink *n = makeNode(SubLink);
15629 18 : A_Indirection *a = makeNode(A_Indirection);
15630 :
15631 18 : n->subLinkType = EXPR_SUBLINK;
15632 18 : n->subLinkId = 0;
15633 18 : n->testexpr = NULL;
15634 18 : n->operName = NIL;
15635 18 : n->subselect = $1;
15636 18 : n->location = @1;
15637 18 : a->arg = (Node *) n;
15638 18 : a->indirection = check_indirection($2, yyscanner);
15639 18 : $$ = (Node *) a;
15640 : }
15641 : | EXISTS select_with_parens
15642 : {
15643 6060 : SubLink *n = makeNode(SubLink);
15644 :
15645 6060 : n->subLinkType = EXISTS_SUBLINK;
15646 6060 : n->subLinkId = 0;
15647 6060 : n->testexpr = NULL;
15648 6060 : n->operName = NIL;
15649 6060 : n->subselect = $2;
15650 6060 : n->location = @1;
15651 6060 : $$ = (Node *) n;
15652 : }
15653 : | ARRAY select_with_parens
15654 : {
15655 8396 : SubLink *n = makeNode(SubLink);
15656 :
15657 8396 : n->subLinkType = ARRAY_SUBLINK;
15658 8396 : n->subLinkId = 0;
15659 8396 : n->testexpr = NULL;
15660 8396 : n->operName = NIL;
15661 8396 : n->subselect = $2;
15662 8396 : n->location = @1;
15663 8396 : $$ = (Node *) n;
15664 : }
15665 : | ARRAY array_expr
15666 : {
15667 7374 : A_ArrayExpr *n = castNode(A_ArrayExpr, $2);
15668 :
15669 : /* point outermost A_ArrayExpr to the ARRAY keyword */
15670 7374 : n->location = @1;
15671 7374 : $$ = (Node *) n;
15672 : }
15673 : | explicit_row
15674 : {
15675 3816 : RowExpr *r = makeNode(RowExpr);
15676 :
15677 3816 : r->args = $1;
15678 3816 : r->row_typeid = InvalidOid; /* not analyzed yet */
15679 3816 : r->colnames = NIL; /* to be filled in during analysis */
15680 3816 : r->row_format = COERCE_EXPLICIT_CALL; /* abuse */
15681 3816 : r->location = @1;
15682 3816 : $$ = (Node *) r;
15683 : }
15684 : | implicit_row
15685 : {
15686 2682 : RowExpr *r = makeNode(RowExpr);
15687 :
15688 2682 : r->args = $1;
15689 2682 : r->row_typeid = InvalidOid; /* not analyzed yet */
15690 2682 : r->colnames = NIL; /* to be filled in during analysis */
15691 2682 : r->row_format = COERCE_IMPLICIT_CAST; /* abuse */
15692 2682 : r->location = @1;
15693 2682 : $$ = (Node *) r;
15694 : }
15695 : | GROUPING '(' expr_list ')'
15696 : {
15697 362 : GroupingFunc *g = makeNode(GroupingFunc);
15698 :
15699 362 : g->args = $3;
15700 362 : g->location = @1;
15701 362 : $$ = (Node *) g;
15702 : }
15703 : ;
15704 :
15705 : func_application: func_name '(' ')'
15706 : {
15707 32744 : $$ = (Node *) makeFuncCall($1, NIL,
15708 : COERCE_EXPLICIT_CALL,
15709 32744 : @1);
15710 : }
15711 : | func_name '(' func_arg_list opt_sort_clause ')'
15712 : {
15713 314138 : FuncCall *n = makeFuncCall($1, $3,
15714 : COERCE_EXPLICIT_CALL,
15715 314138 : @1);
15716 :
15717 314138 : n->agg_order = $4;
15718 314138 : $$ = (Node *) n;
15719 : }
15720 : | func_name '(' VARIADIC func_arg_expr opt_sort_clause ')'
15721 : {
15722 620 : FuncCall *n = makeFuncCall($1, list_make1($4),
15723 : COERCE_EXPLICIT_CALL,
15724 620 : @1);
15725 :
15726 620 : n->func_variadic = true;
15727 620 : n->agg_order = $5;
15728 620 : $$ = (Node *) n;
15729 : }
15730 : | func_name '(' func_arg_list ',' VARIADIC func_arg_expr opt_sort_clause ')'
15731 : {
15732 120 : FuncCall *n = makeFuncCall($1, lappend($3, $6),
15733 : COERCE_EXPLICIT_CALL,
15734 120 : @1);
15735 :
15736 120 : n->func_variadic = true;
15737 120 : n->agg_order = $7;
15738 120 : $$ = (Node *) n;
15739 : }
15740 : | func_name '(' ALL func_arg_list opt_sort_clause ')'
15741 : {
15742 0 : FuncCall *n = makeFuncCall($1, $4,
15743 : COERCE_EXPLICIT_CALL,
15744 0 : @1);
15745 :
15746 0 : n->agg_order = $5;
15747 : /* Ideally we'd mark the FuncCall node to indicate
15748 : * "must be an aggregate", but there's no provision
15749 : * for that in FuncCall at the moment.
15750 : */
15751 0 : $$ = (Node *) n;
15752 : }
15753 : | func_name '(' DISTINCT func_arg_list opt_sort_clause ')'
15754 : {
15755 550 : FuncCall *n = makeFuncCall($1, $4,
15756 : COERCE_EXPLICIT_CALL,
15757 550 : @1);
15758 :
15759 550 : n->agg_order = $5;
15760 550 : n->agg_distinct = true;
15761 550 : $$ = (Node *) n;
15762 : }
15763 : | func_name '(' '*' ')'
15764 : {
15765 : /*
15766 : * We consider AGGREGATE(*) to invoke a parameterless
15767 : * aggregate. This does the right thing for COUNT(*),
15768 : * and there are no other aggregates in SQL that accept
15769 : * '*' as parameter.
15770 : *
15771 : * The FuncCall node is also marked agg_star = true,
15772 : * so that later processing can detect what the argument
15773 : * really was.
15774 : */
15775 12632 : FuncCall *n = makeFuncCall($1, NIL,
15776 : COERCE_EXPLICIT_CALL,
15777 12632 : @1);
15778 :
15779 12632 : n->agg_star = true;
15780 12632 : $$ = (Node *) n;
15781 : }
15782 : ;
15783 :
15784 :
15785 : /*
15786 : * func_expr and its cousin func_expr_windowless are split out from c_expr just
15787 : * so that we have classifications for "everything that is a function call or
15788 : * looks like one". This isn't very important, but it saves us having to
15789 : * document which variants are legal in places like "FROM function()" or the
15790 : * backwards-compatible functional-index syntax for CREATE INDEX.
15791 : * (Note that many of the special SQL functions wouldn't actually make any
15792 : * sense as functional index entries, but we ignore that consideration here.)
15793 : */
15794 : func_expr: func_application within_group_clause filter_clause over_clause
15795 : {
15796 312132 : FuncCall *n = (FuncCall *) $1;
15797 :
15798 : /*
15799 : * The order clause for WITHIN GROUP and the one for
15800 : * plain-aggregate ORDER BY share a field, so we have to
15801 : * check here that at most one is present. We also check
15802 : * for DISTINCT and VARIADIC here to give a better error
15803 : * location. Other consistency checks are deferred to
15804 : * parse analysis.
15805 : */
15806 312132 : if ($2 != NIL)
15807 : {
15808 348 : if (n->agg_order != NIL)
15809 6 : ereport(ERROR,
15810 : (errcode(ERRCODE_SYNTAX_ERROR),
15811 : errmsg("cannot use multiple ORDER BY clauses with WITHIN GROUP"),
15812 : parser_errposition(@2)));
15813 342 : if (n->agg_distinct)
15814 0 : ereport(ERROR,
15815 : (errcode(ERRCODE_SYNTAX_ERROR),
15816 : errmsg("cannot use DISTINCT with WITHIN GROUP"),
15817 : parser_errposition(@2)));
15818 342 : if (n->func_variadic)
15819 0 : ereport(ERROR,
15820 : (errcode(ERRCODE_SYNTAX_ERROR),
15821 : errmsg("cannot use VARIADIC with WITHIN GROUP"),
15822 : parser_errposition(@2)));
15823 342 : n->agg_order = $2;
15824 342 : n->agg_within_group = true;
15825 : }
15826 312126 : n->agg_filter = $3;
15827 312126 : n->over = $4;
15828 312126 : $$ = (Node *) n;
15829 : }
15830 : | json_aggregate_func filter_clause over_clause
15831 : {
15832 720 : JsonAggConstructor *n = IsA($1, JsonObjectAgg) ?
15833 360 : ((JsonObjectAgg *) $1)->constructor :
15834 156 : ((JsonArrayAgg *) $1)->constructor;
15835 :
15836 360 : n->agg_filter = $2;
15837 360 : n->over = $3;
15838 360 : $$ = (Node *) $1;
15839 : }
15840 : | func_expr_common_subexpr
15841 76282 : { $$ = $1; }
15842 : ;
15843 :
15844 : /*
15845 : * Like func_expr but does not accept WINDOW functions directly
15846 : * (but they can still be contained in arguments for functions etc).
15847 : * Use this when window expressions are not allowed, where needed to
15848 : * disambiguate the grammar (e.g. in CREATE INDEX).
15849 : */
15850 : func_expr_windowless:
15851 48038 : func_application { $$ = $1; }
15852 402 : | func_expr_common_subexpr { $$ = $1; }
15853 0 : | json_aggregate_func { $$ = $1; }
15854 : ;
15855 :
15856 : /*
15857 : * Special expressions that are considered to be functions.
15858 : */
15859 : func_expr_common_subexpr:
15860 : COLLATION FOR '(' a_expr ')'
15861 : {
15862 30 : $$ = (Node *) makeFuncCall(SystemFuncName("pg_collation_for"),
15863 30 : list_make1($4),
15864 : COERCE_SQL_SYNTAX,
15865 30 : @1);
15866 : }
15867 : | CURRENT_DATE
15868 : {
15869 308 : $$ = makeSQLValueFunction(SVFOP_CURRENT_DATE, -1, @1);
15870 : }
15871 : | CURRENT_TIME
15872 : {
15873 24 : $$ = makeSQLValueFunction(SVFOP_CURRENT_TIME, -1, @1);
15874 : }
15875 : | CURRENT_TIME '(' Iconst ')'
15876 : {
15877 24 : $$ = makeSQLValueFunction(SVFOP_CURRENT_TIME_N, $3, @1);
15878 : }
15879 : | CURRENT_TIMESTAMP
15880 : {
15881 286 : $$ = makeSQLValueFunction(SVFOP_CURRENT_TIMESTAMP, -1, @1);
15882 : }
15883 : | CURRENT_TIMESTAMP '(' Iconst ')'
15884 : {
15885 174 : $$ = makeSQLValueFunction(SVFOP_CURRENT_TIMESTAMP_N, $3, @1);
15886 : }
15887 : | LOCALTIME
15888 : {
15889 24 : $$ = makeSQLValueFunction(SVFOP_LOCALTIME, -1, @1);
15890 : }
15891 : | LOCALTIME '(' Iconst ')'
15892 : {
15893 24 : $$ = makeSQLValueFunction(SVFOP_LOCALTIME_N, $3, @1);
15894 : }
15895 : | LOCALTIMESTAMP
15896 : {
15897 36 : $$ = makeSQLValueFunction(SVFOP_LOCALTIMESTAMP, -1, @1);
15898 : }
15899 : | LOCALTIMESTAMP '(' Iconst ')'
15900 : {
15901 24 : $$ = makeSQLValueFunction(SVFOP_LOCALTIMESTAMP_N, $3, @1);
15902 : }
15903 : | CURRENT_ROLE
15904 : {
15905 68 : $$ = makeSQLValueFunction(SVFOP_CURRENT_ROLE, -1, @1);
15906 : }
15907 : | CURRENT_USER
15908 : {
15909 1060 : $$ = makeSQLValueFunction(SVFOP_CURRENT_USER, -1, @1);
15910 : }
15911 : | SESSION_USER
15912 : {
15913 602 : $$ = makeSQLValueFunction(SVFOP_SESSION_USER, -1, @1);
15914 : }
15915 : | SYSTEM_USER
15916 : {
15917 20 : $$ = (Node *) makeFuncCall(SystemFuncName("system_user"),
15918 : NIL,
15919 : COERCE_SQL_SYNTAX,
15920 : @1);
15921 : }
15922 : | USER
15923 : {
15924 24 : $$ = makeSQLValueFunction(SVFOP_USER, -1, @1);
15925 : }
15926 : | CURRENT_CATALOG
15927 : {
15928 52 : $$ = makeSQLValueFunction(SVFOP_CURRENT_CATALOG, -1, @1);
15929 : }
15930 : | CURRENT_SCHEMA
15931 : {
15932 30 : $$ = makeSQLValueFunction(SVFOP_CURRENT_SCHEMA, -1, @1);
15933 : }
15934 : | CAST '(' a_expr AS Typename ')'
15935 62472 : { $$ = makeTypeCast($3, $5, @1); }
15936 : | EXTRACT '(' extract_list ')'
15937 : {
15938 1382 : $$ = (Node *) makeFuncCall(SystemFuncName("extract"),
15939 1382 : $3,
15940 : COERCE_SQL_SYNTAX,
15941 1382 : @1);
15942 : }
15943 : | NORMALIZE '(' a_expr ')'
15944 : {
15945 18 : $$ = (Node *) makeFuncCall(SystemFuncName("normalize"),
15946 18 : list_make1($3),
15947 : COERCE_SQL_SYNTAX,
15948 18 : @1);
15949 : }
15950 : | NORMALIZE '(' a_expr ',' unicode_normal_form ')'
15951 : {
15952 42 : $$ = (Node *) makeFuncCall(SystemFuncName("normalize"),
15953 42 : list_make2($3, makeStringConst($5, @5)),
15954 : COERCE_SQL_SYNTAX,
15955 42 : @1);
15956 : }
15957 : | OVERLAY '(' overlay_list ')'
15958 : {
15959 82 : $$ = (Node *) makeFuncCall(SystemFuncName("overlay"),
15960 82 : $3,
15961 : COERCE_SQL_SYNTAX,
15962 82 : @1);
15963 : }
15964 : | OVERLAY '(' func_arg_list_opt ')'
15965 : {
15966 : /*
15967 : * allow functions named overlay() to be called without
15968 : * special syntax
15969 : */
15970 0 : $$ = (Node *) makeFuncCall(list_make1(makeString("overlay")),
15971 0 : $3,
15972 : COERCE_EXPLICIT_CALL,
15973 0 : @1);
15974 : }
15975 : | POSITION '(' position_list ')'
15976 : {
15977 : /*
15978 : * position(A in B) is converted to position(B, A)
15979 : *
15980 : * We deliberately don't offer a "plain syntax" option
15981 : * for position(), because the reversal of the arguments
15982 : * creates too much risk of confusion.
15983 : */
15984 400 : $$ = (Node *) makeFuncCall(SystemFuncName("position"),
15985 400 : $3,
15986 : COERCE_SQL_SYNTAX,
15987 400 : @1);
15988 : }
15989 : | SUBSTRING '(' substr_list ')'
15990 : {
15991 : /* substring(A from B for C) is converted to
15992 : * substring(A, B, C) - thomas 2000-11-28
15993 : */
15994 710 : $$ = (Node *) makeFuncCall(SystemFuncName("substring"),
15995 710 : $3,
15996 : COERCE_SQL_SYNTAX,
15997 710 : @1);
15998 : }
15999 : | SUBSTRING '(' func_arg_list_opt ')'
16000 : {
16001 : /*
16002 : * allow functions named substring() to be called without
16003 : * special syntax
16004 : */
16005 252 : $$ = (Node *) makeFuncCall(list_make1(makeString("substring")),
16006 252 : $3,
16007 : COERCE_EXPLICIT_CALL,
16008 252 : @1);
16009 : }
16010 : | TREAT '(' a_expr AS Typename ')'
16011 : {
16012 : /* TREAT(expr AS target) converts expr of a particular type to target,
16013 : * which is defined to be a subtype of the original expression.
16014 : * In SQL99, this is intended for use with structured UDTs,
16015 : * but let's make this a generally useful form allowing stronger
16016 : * coercions than are handled by implicit casting.
16017 : *
16018 : * Convert SystemTypeName() to SystemFuncName() even though
16019 : * at the moment they result in the same thing.
16020 : */
16021 0 : $$ = (Node *) makeFuncCall(SystemFuncName(strVal(llast($5->names))),
16022 0 : list_make1($3),
16023 : COERCE_EXPLICIT_CALL,
16024 0 : @1);
16025 : }
16026 : | TRIM '(' BOTH trim_list ')'
16027 : {
16028 : /* various trim expressions are defined in SQL
16029 : * - thomas 1997-07-19
16030 : */
16031 12 : $$ = (Node *) makeFuncCall(SystemFuncName("btrim"),
16032 12 : $4,
16033 : COERCE_SQL_SYNTAX,
16034 12 : @1);
16035 : }
16036 : | TRIM '(' LEADING trim_list ')'
16037 : {
16038 24 : $$ = (Node *) makeFuncCall(SystemFuncName("ltrim"),
16039 24 : $4,
16040 : COERCE_SQL_SYNTAX,
16041 24 : @1);
16042 : }
16043 : | TRIM '(' TRAILING trim_list ')'
16044 : {
16045 580 : $$ = (Node *) makeFuncCall(SystemFuncName("rtrim"),
16046 580 : $4,
16047 : COERCE_SQL_SYNTAX,
16048 580 : @1);
16049 : }
16050 : | TRIM '(' trim_list ')'
16051 : {
16052 98 : $$ = (Node *) makeFuncCall(SystemFuncName("btrim"),
16053 98 : $3,
16054 : COERCE_SQL_SYNTAX,
16055 98 : @1);
16056 : }
16057 : | NULLIF '(' a_expr ',' a_expr ')'
16058 : {
16059 386 : $$ = (Node *) makeSimpleA_Expr(AEXPR_NULLIF, "=", $3, $5, @1);
16060 : }
16061 : | COALESCE '(' expr_list ')'
16062 : {
16063 3208 : CoalesceExpr *c = makeNode(CoalesceExpr);
16064 :
16065 3208 : c->args = $3;
16066 3208 : c->location = @1;
16067 3208 : $$ = (Node *) c;
16068 : }
16069 : | GREATEST '(' expr_list ')'
16070 : {
16071 146 : MinMaxExpr *v = makeNode(MinMaxExpr);
16072 :
16073 146 : v->args = $3;
16074 146 : v->op = IS_GREATEST;
16075 146 : v->location = @1;
16076 146 : $$ = (Node *) v;
16077 : }
16078 : | LEAST '(' expr_list ')'
16079 : {
16080 124 : MinMaxExpr *v = makeNode(MinMaxExpr);
16081 :
16082 124 : v->args = $3;
16083 124 : v->op = IS_LEAST;
16084 124 : v->location = @1;
16085 124 : $$ = (Node *) v;
16086 : }
16087 : | XMLCONCAT '(' expr_list ')'
16088 : {
16089 62 : $$ = makeXmlExpr(IS_XMLCONCAT, NULL, NIL, $3, @1);
16090 : }
16091 : | XMLELEMENT '(' NAME_P ColLabel ')'
16092 : {
16093 6 : $$ = makeXmlExpr(IS_XMLELEMENT, $4, NIL, NIL, @1);
16094 : }
16095 : | XMLELEMENT '(' NAME_P ColLabel ',' xml_attributes ')'
16096 : {
16097 36 : $$ = makeXmlExpr(IS_XMLELEMENT, $4, $6, NIL, @1);
16098 : }
16099 : | XMLELEMENT '(' NAME_P ColLabel ',' expr_list ')'
16100 : {
16101 116 : $$ = makeXmlExpr(IS_XMLELEMENT, $4, NIL, $6, @1);
16102 : }
16103 : | XMLELEMENT '(' NAME_P ColLabel ',' xml_attributes ',' expr_list ')'
16104 : {
16105 20 : $$ = makeXmlExpr(IS_XMLELEMENT, $4, $6, $8, @1);
16106 : }
16107 : | XMLEXISTS '(' c_expr xmlexists_argument ')'
16108 : {
16109 : /* xmlexists(A PASSING [BY REF] B [BY REF]) is
16110 : * converted to xmlexists(A, B)*/
16111 54 : $$ = (Node *) makeFuncCall(SystemFuncName("xmlexists"),
16112 54 : list_make2($3, $4),
16113 : COERCE_SQL_SYNTAX,
16114 54 : @1);
16115 : }
16116 : | XMLFOREST '(' xml_attribute_list ')'
16117 : {
16118 32 : $$ = makeXmlExpr(IS_XMLFOREST, NULL, $3, NIL, @1);
16119 : }
16120 : | XMLPARSE '(' document_or_content a_expr xml_whitespace_option ')'
16121 : {
16122 : XmlExpr *x = (XmlExpr *)
16123 140 : makeXmlExpr(IS_XMLPARSE, NULL, NIL,
16124 140 : list_make2($4, makeBoolAConst($5, -1)),
16125 140 : @1);
16126 :
16127 140 : x->xmloption = $3;
16128 140 : $$ = (Node *) x;
16129 : }
16130 : | XMLPI '(' NAME_P ColLabel ')'
16131 : {
16132 30 : $$ = makeXmlExpr(IS_XMLPI, $4, NULL, NIL, @1);
16133 : }
16134 : | XMLPI '(' NAME_P ColLabel ',' a_expr ')'
16135 : {
16136 50 : $$ = makeXmlExpr(IS_XMLPI, $4, NULL, list_make1($6), @1);
16137 : }
16138 : | XMLROOT '(' a_expr ',' xml_root_version opt_xml_root_standalone ')'
16139 : {
16140 68 : $$ = makeXmlExpr(IS_XMLROOT, NULL, NIL,
16141 68 : list_make3($3, $5, $6), @1);
16142 : }
16143 : | XMLSERIALIZE '(' document_or_content a_expr AS SimpleTypename xml_indent_option ')'
16144 : {
16145 218 : XmlSerialize *n = makeNode(XmlSerialize);
16146 :
16147 218 : n->xmloption = $3;
16148 218 : n->expr = $4;
16149 218 : n->typeName = $6;
16150 218 : n->indent = $7;
16151 218 : n->location = @1;
16152 218 : $$ = (Node *) n;
16153 : }
16154 : | JSON_OBJECT '(' func_arg_list ')'
16155 : {
16156 : /* Support for legacy (non-standard) json_object() */
16157 90 : $$ = (Node *) makeFuncCall(SystemFuncName("json_object"),
16158 90 : $3, COERCE_EXPLICIT_CALL, @1);
16159 : }
16160 : | JSON_OBJECT '(' json_name_and_value_list
16161 : json_object_constructor_null_clause_opt
16162 : json_key_uniqueness_constraint_opt
16163 : json_returning_clause_opt ')'
16164 : {
16165 348 : JsonObjectConstructor *n = makeNode(JsonObjectConstructor);
16166 :
16167 348 : n->exprs = $3;
16168 348 : n->absent_on_null = $4;
16169 348 : n->unique = $5;
16170 348 : n->output = (JsonOutput *) $6;
16171 348 : n->location = @1;
16172 348 : $$ = (Node *) n;
16173 : }
16174 : | JSON_OBJECT '(' json_returning_clause_opt ')'
16175 : {
16176 92 : JsonObjectConstructor *n = makeNode(JsonObjectConstructor);
16177 :
16178 92 : n->exprs = NULL;
16179 92 : n->absent_on_null = false;
16180 92 : n->unique = false;
16181 92 : n->output = (JsonOutput *) $3;
16182 92 : n->location = @1;
16183 92 : $$ = (Node *) n;
16184 : }
16185 : | JSON_ARRAY '('
16186 : json_value_expr_list
16187 : json_array_constructor_null_clause_opt
16188 : json_returning_clause_opt
16189 : ')'
16190 : {
16191 108 : JsonArrayConstructor *n = makeNode(JsonArrayConstructor);
16192 :
16193 108 : n->exprs = $3;
16194 108 : n->absent_on_null = $4;
16195 108 : n->output = (JsonOutput *) $5;
16196 108 : n->location = @1;
16197 108 : $$ = (Node *) n;
16198 : }
16199 : | JSON_ARRAY '('
16200 : select_no_parens
16201 : json_format_clause_opt
16202 : /* json_array_constructor_null_clause_opt */
16203 : json_returning_clause_opt
16204 : ')'
16205 : {
16206 60 : JsonArrayQueryConstructor *n = makeNode(JsonArrayQueryConstructor);
16207 :
16208 60 : n->query = $3;
16209 60 : n->format = (JsonFormat *) $4;
16210 60 : n->absent_on_null = true; /* XXX */
16211 60 : n->output = (JsonOutput *) $5;
16212 60 : n->location = @1;
16213 60 : $$ = (Node *) n;
16214 : }
16215 : | JSON_ARRAY '('
16216 : json_returning_clause_opt
16217 : ')'
16218 : {
16219 86 : JsonArrayConstructor *n = makeNode(JsonArrayConstructor);
16220 :
16221 86 : n->exprs = NIL;
16222 86 : n->absent_on_null = true;
16223 86 : n->output = (JsonOutput *) $3;
16224 86 : n->location = @1;
16225 86 : $$ = (Node *) n;
16226 : }
16227 : | JSON '(' json_value_expr json_key_uniqueness_constraint_opt ')'
16228 : {
16229 164 : JsonParseExpr *n = makeNode(JsonParseExpr);
16230 :
16231 164 : n->expr = (JsonValueExpr *) $3;
16232 164 : n->unique_keys = $4;
16233 164 : n->output = NULL;
16234 164 : n->location = @1;
16235 164 : $$ = (Node *) n;
16236 : }
16237 : | JSON_SCALAR '(' a_expr ')'
16238 : {
16239 112 : JsonScalarExpr *n = makeNode(JsonScalarExpr);
16240 :
16241 112 : n->expr = (Expr *) $3;
16242 112 : n->output = NULL;
16243 112 : n->location = @1;
16244 112 : $$ = (Node *) n;
16245 : }
16246 : | JSON_SERIALIZE '(' json_value_expr json_returning_clause_opt ')'
16247 : {
16248 108 : JsonSerializeExpr *n = makeNode(JsonSerializeExpr);
16249 :
16250 108 : n->expr = (JsonValueExpr *) $3;
16251 108 : n->output = (JsonOutput *) $4;
16252 108 : n->location = @1;
16253 108 : $$ = (Node *) n;
16254 : }
16255 : | MERGE_ACTION '(' ')'
16256 : {
16257 210 : MergeSupportFunc *m = makeNode(MergeSupportFunc);
16258 :
16259 210 : m->msftype = TEXTOID;
16260 210 : m->location = @1;
16261 210 : $$ = (Node *) m;
16262 : }
16263 : | JSON_QUERY '('
16264 : json_value_expr ',' a_expr json_passing_clause_opt
16265 : json_returning_clause_opt
16266 : json_wrapper_behavior
16267 : json_quotes_clause_opt
16268 : json_behavior_clause_opt
16269 : ')'
16270 : {
16271 984 : JsonFuncExpr *n = makeNode(JsonFuncExpr);
16272 :
16273 984 : n->op = JSON_QUERY_OP;
16274 984 : n->context_item = (JsonValueExpr *) $3;
16275 984 : n->pathspec = $5;
16276 984 : n->passing = $6;
16277 984 : n->output = (JsonOutput *) $7;
16278 984 : n->wrapper = $8;
16279 984 : n->quotes = $9;
16280 984 : n->on_empty = (JsonBehavior *) linitial($10);
16281 984 : n->on_error = (JsonBehavior *) lsecond($10);
16282 984 : n->location = @1;
16283 984 : $$ = (Node *) n;
16284 : }
16285 : | JSON_EXISTS '('
16286 : json_value_expr ',' a_expr json_passing_clause_opt
16287 : json_on_error_clause_opt
16288 : ')'
16289 : {
16290 168 : JsonFuncExpr *n = makeNode(JsonFuncExpr);
16291 :
16292 168 : n->op = JSON_EXISTS_OP;
16293 168 : n->context_item = (JsonValueExpr *) $3;
16294 168 : n->pathspec = $5;
16295 168 : n->passing = $6;
16296 168 : n->output = NULL;
16297 168 : n->on_error = (JsonBehavior *) $7;
16298 168 : n->location = @1;
16299 168 : $$ = (Node *) n;
16300 : }
16301 : | JSON_VALUE '('
16302 : json_value_expr ',' a_expr json_passing_clause_opt
16303 : json_returning_clause_opt
16304 : json_behavior_clause_opt
16305 : ')'
16306 : {
16307 576 : JsonFuncExpr *n = makeNode(JsonFuncExpr);
16308 :
16309 576 : n->op = JSON_VALUE_OP;
16310 576 : n->context_item = (JsonValueExpr *) $3;
16311 576 : n->pathspec = $5;
16312 576 : n->passing = $6;
16313 576 : n->output = (JsonOutput *) $7;
16314 576 : n->on_empty = (JsonBehavior *) linitial($8);
16315 576 : n->on_error = (JsonBehavior *) lsecond($8);
16316 576 : n->location = @1;
16317 576 : $$ = (Node *) n;
16318 : }
16319 : ;
16320 :
16321 :
16322 : /*
16323 : * SQL/XML support
16324 : */
16325 : xml_root_version: VERSION_P a_expr
16326 24 : { $$ = $2; }
16327 : | VERSION_P NO VALUE_P
16328 44 : { $$ = makeNullAConst(-1); }
16329 : ;
16330 :
16331 : opt_xml_root_standalone: ',' STANDALONE_P YES_P
16332 26 : { $$ = makeIntConst(XML_STANDALONE_YES, -1); }
16333 : | ',' STANDALONE_P NO
16334 12 : { $$ = makeIntConst(XML_STANDALONE_NO, -1); }
16335 : | ',' STANDALONE_P NO VALUE_P
16336 12 : { $$ = makeIntConst(XML_STANDALONE_NO_VALUE, -1); }
16337 : | /*EMPTY*/
16338 18 : { $$ = makeIntConst(XML_STANDALONE_OMITTED, -1); }
16339 : ;
16340 :
16341 56 : xml_attributes: XMLATTRIBUTES '(' xml_attribute_list ')' { $$ = $3; }
16342 : ;
16343 :
16344 88 : xml_attribute_list: xml_attribute_el { $$ = list_make1($1); }
16345 144 : | xml_attribute_list ',' xml_attribute_el { $$ = lappend($1, $3); }
16346 : ;
16347 :
16348 : xml_attribute_el: a_expr AS ColLabel
16349 : {
16350 106 : $$ = makeNode(ResTarget);
16351 106 : $$->name = $3;
16352 106 : $$->indirection = NIL;
16353 106 : $$->val = (Node *) $1;
16354 106 : $$->location = @1;
16355 : }
16356 : | a_expr
16357 : {
16358 126 : $$ = makeNode(ResTarget);
16359 126 : $$->name = NULL;
16360 126 : $$->indirection = NIL;
16361 126 : $$->val = (Node *) $1;
16362 126 : $$->location = @1;
16363 : }
16364 : ;
16365 :
16366 186 : document_or_content: DOCUMENT_P { $$ = XMLOPTION_DOCUMENT; }
16367 188 : | CONTENT_P { $$ = XMLOPTION_CONTENT; }
16368 : ;
16369 :
16370 140 : xml_indent_option: INDENT { $$ = true; }
16371 36 : | NO INDENT { $$ = false; }
16372 42 : | /*EMPTY*/ { $$ = false; }
16373 : ;
16374 :
16375 0 : xml_whitespace_option: PRESERVE WHITESPACE_P { $$ = true; }
16376 2 : | STRIP_P WHITESPACE_P { $$ = false; }
16377 138 : | /*EMPTY*/ { $$ = false; }
16378 : ;
16379 :
16380 : /* We allow several variants for SQL and other compatibility. */
16381 : xmlexists_argument:
16382 : PASSING c_expr
16383 : {
16384 232 : $$ = $2;
16385 : }
16386 : | PASSING c_expr xml_passing_mech
16387 : {
16388 0 : $$ = $2;
16389 : }
16390 : | PASSING xml_passing_mech c_expr
16391 : {
16392 42 : $$ = $3;
16393 : }
16394 : | PASSING xml_passing_mech c_expr xml_passing_mech
16395 : {
16396 6 : $$ = $3;
16397 : }
16398 : ;
16399 :
16400 : xml_passing_mech:
16401 : BY REF_P
16402 : | BY VALUE_P
16403 : ;
16404 :
16405 :
16406 : /*
16407 : * Aggregate decoration clauses
16408 : */
16409 : within_group_clause:
16410 348 : WITHIN GROUP_P '(' sort_clause ')' { $$ = $4; }
16411 311790 : | /*EMPTY*/ { $$ = NIL; }
16412 : ;
16413 :
16414 : filter_clause:
16415 862 : FILTER '(' WHERE a_expr ')' { $$ = $4; }
16416 311636 : | /*EMPTY*/ { $$ = NULL; }
16417 : ;
16418 :
16419 :
16420 : /*
16421 : * Window Definitions
16422 : */
16423 : window_clause:
16424 540 : WINDOW window_definition_list { $$ = $2; }
16425 469300 : | /*EMPTY*/ { $$ = NIL; }
16426 : ;
16427 :
16428 : window_definition_list:
16429 540 : window_definition { $$ = list_make1($1); }
16430 : | window_definition_list ',' window_definition
16431 12 : { $$ = lappend($1, $3); }
16432 : ;
16433 :
16434 : window_definition:
16435 : ColId AS window_specification
16436 : {
16437 552 : WindowDef *n = $3;
16438 :
16439 552 : n->name = $1;
16440 552 : $$ = n;
16441 : }
16442 : ;
16443 :
16444 : over_clause: OVER window_specification
16445 2616 : { $$ = $2; }
16446 : | OVER ColId
16447 : {
16448 954 : WindowDef *n = makeNode(WindowDef);
16449 :
16450 954 : n->name = $2;
16451 954 : n->refname = NULL;
16452 954 : n->partitionClause = NIL;
16453 954 : n->orderClause = NIL;
16454 954 : n->frameOptions = FRAMEOPTION_DEFAULTS;
16455 954 : n->startOffset = NULL;
16456 954 : n->endOffset = NULL;
16457 954 : n->location = @2;
16458 954 : $$ = n;
16459 : }
16460 : | /*EMPTY*/
16461 308922 : { $$ = NULL; }
16462 : ;
16463 :
16464 : window_specification: '(' opt_existing_window_name opt_partition_clause
16465 : opt_sort_clause opt_frame_clause ')'
16466 : {
16467 3168 : WindowDef *n = makeNode(WindowDef);
16468 :
16469 3168 : n->name = NULL;
16470 3168 : n->refname = $2;
16471 3168 : n->partitionClause = $3;
16472 3168 : n->orderClause = $4;
16473 : /* copy relevant fields of opt_frame_clause */
16474 3168 : n->frameOptions = $5->frameOptions;
16475 3168 : n->startOffset = $5->startOffset;
16476 3168 : n->endOffset = $5->endOffset;
16477 3168 : n->location = @1;
16478 3168 : $$ = n;
16479 : }
16480 : ;
16481 :
16482 : /*
16483 : * If we see PARTITION, RANGE, ROWS or GROUPS as the first token after the '('
16484 : * of a window_specification, we want the assumption to be that there is
16485 : * no existing_window_name; but those keywords are unreserved and so could
16486 : * be ColIds. We fix this by making them have the same precedence as IDENT
16487 : * and giving the empty production here a slightly higher precedence, so
16488 : * that the shift/reduce conflict is resolved in favor of reducing the rule.
16489 : * These keywords are thus precluded from being an existing_window_name but
16490 : * are not reserved for any other purpose.
16491 : */
16492 54 : opt_existing_window_name: ColId { $$ = $1; }
16493 3120 : | /*EMPTY*/ %prec Op { $$ = NULL; }
16494 : ;
16495 :
16496 920 : opt_partition_clause: PARTITION BY expr_list { $$ = $3; }
16497 2248 : | /*EMPTY*/ { $$ = NIL; }
16498 : ;
16499 :
16500 : /*
16501 : * For frame clauses, we return a WindowDef, but only some fields are used:
16502 : * frameOptions, startOffset, and endOffset.
16503 : */
16504 : opt_frame_clause:
16505 : RANGE frame_extent opt_window_exclusion_clause
16506 : {
16507 796 : WindowDef *n = $2;
16508 :
16509 796 : n->frameOptions |= FRAMEOPTION_NONDEFAULT | FRAMEOPTION_RANGE;
16510 796 : n->frameOptions |= $3;
16511 796 : $$ = n;
16512 : }
16513 : | ROWS frame_extent opt_window_exclusion_clause
16514 : {
16515 624 : WindowDef *n = $2;
16516 :
16517 624 : n->frameOptions |= FRAMEOPTION_NONDEFAULT | FRAMEOPTION_ROWS;
16518 624 : n->frameOptions |= $3;
16519 624 : $$ = n;
16520 : }
16521 : | GROUPS frame_extent opt_window_exclusion_clause
16522 : {
16523 204 : WindowDef *n = $2;
16524 :
16525 204 : n->frameOptions |= FRAMEOPTION_NONDEFAULT | FRAMEOPTION_GROUPS;
16526 204 : n->frameOptions |= $3;
16527 204 : $$ = n;
16528 : }
16529 : | /*EMPTY*/
16530 : {
16531 1544 : WindowDef *n = makeNode(WindowDef);
16532 :
16533 1544 : n->frameOptions = FRAMEOPTION_DEFAULTS;
16534 1544 : n->startOffset = NULL;
16535 1544 : n->endOffset = NULL;
16536 1544 : $$ = n;
16537 : }
16538 : ;
16539 :
16540 : frame_extent: frame_bound
16541 : {
16542 12 : WindowDef *n = $1;
16543 :
16544 : /* reject invalid cases */
16545 12 : if (n->frameOptions & FRAMEOPTION_START_UNBOUNDED_FOLLOWING)
16546 0 : ereport(ERROR,
16547 : (errcode(ERRCODE_WINDOWING_ERROR),
16548 : errmsg("frame start cannot be UNBOUNDED FOLLOWING"),
16549 : parser_errposition(@1)));
16550 12 : if (n->frameOptions & FRAMEOPTION_START_OFFSET_FOLLOWING)
16551 0 : ereport(ERROR,
16552 : (errcode(ERRCODE_WINDOWING_ERROR),
16553 : errmsg("frame starting from following row cannot end with current row"),
16554 : parser_errposition(@1)));
16555 12 : n->frameOptions |= FRAMEOPTION_END_CURRENT_ROW;
16556 12 : $$ = n;
16557 : }
16558 : | BETWEEN frame_bound AND frame_bound
16559 : {
16560 1612 : WindowDef *n1 = $2;
16561 1612 : WindowDef *n2 = $4;
16562 :
16563 : /* form merged options */
16564 1612 : int frameOptions = n1->frameOptions;
16565 : /* shift converts START_ options to END_ options */
16566 1612 : frameOptions |= n2->frameOptions << 1;
16567 1612 : frameOptions |= FRAMEOPTION_BETWEEN;
16568 : /* reject invalid cases */
16569 1612 : if (frameOptions & FRAMEOPTION_START_UNBOUNDED_FOLLOWING)
16570 0 : ereport(ERROR,
16571 : (errcode(ERRCODE_WINDOWING_ERROR),
16572 : errmsg("frame start cannot be UNBOUNDED FOLLOWING"),
16573 : parser_errposition(@2)));
16574 1612 : if (frameOptions & FRAMEOPTION_END_UNBOUNDED_PRECEDING)
16575 0 : ereport(ERROR,
16576 : (errcode(ERRCODE_WINDOWING_ERROR),
16577 : errmsg("frame end cannot be UNBOUNDED PRECEDING"),
16578 : parser_errposition(@4)));
16579 1612 : if ((frameOptions & FRAMEOPTION_START_CURRENT_ROW) &&
16580 460 : (frameOptions & FRAMEOPTION_END_OFFSET_PRECEDING))
16581 0 : ereport(ERROR,
16582 : (errcode(ERRCODE_WINDOWING_ERROR),
16583 : errmsg("frame starting from current row cannot have preceding rows"),
16584 : parser_errposition(@4)));
16585 1612 : if ((frameOptions & FRAMEOPTION_START_OFFSET_FOLLOWING) &&
16586 168 : (frameOptions & (FRAMEOPTION_END_OFFSET_PRECEDING |
16587 : FRAMEOPTION_END_CURRENT_ROW)))
16588 0 : ereport(ERROR,
16589 : (errcode(ERRCODE_WINDOWING_ERROR),
16590 : errmsg("frame starting from following row cannot have preceding rows"),
16591 : parser_errposition(@4)));
16592 1612 : n1->frameOptions = frameOptions;
16593 1612 : n1->endOffset = n2->startOffset;
16594 1612 : $$ = n1;
16595 : }
16596 : ;
16597 :
16598 : /*
16599 : * This is used for both frame start and frame end, with output set up on
16600 : * the assumption it's frame start; the frame_extent productions must reject
16601 : * invalid cases.
16602 : */
16603 : frame_bound:
16604 : UNBOUNDED PRECEDING
16605 : {
16606 198 : WindowDef *n = makeNode(WindowDef);
16607 :
16608 198 : n->frameOptions = FRAMEOPTION_START_UNBOUNDED_PRECEDING;
16609 198 : n->startOffset = NULL;
16610 198 : n->endOffset = NULL;
16611 198 : $$ = n;
16612 : }
16613 : | UNBOUNDED FOLLOWING
16614 : {
16615 376 : WindowDef *n = makeNode(WindowDef);
16616 :
16617 376 : n->frameOptions = FRAMEOPTION_START_UNBOUNDED_FOLLOWING;
16618 376 : n->startOffset = NULL;
16619 376 : n->endOffset = NULL;
16620 376 : $$ = n;
16621 : }
16622 : | CURRENT_P ROW
16623 : {
16624 604 : WindowDef *n = makeNode(WindowDef);
16625 :
16626 604 : n->frameOptions = FRAMEOPTION_START_CURRENT_ROW;
16627 604 : n->startOffset = NULL;
16628 604 : n->endOffset = NULL;
16629 604 : $$ = n;
16630 : }
16631 : | a_expr PRECEDING
16632 : {
16633 906 : WindowDef *n = makeNode(WindowDef);
16634 :
16635 906 : n->frameOptions = FRAMEOPTION_START_OFFSET_PRECEDING;
16636 906 : n->startOffset = $1;
16637 906 : n->endOffset = NULL;
16638 906 : $$ = n;
16639 : }
16640 : | a_expr FOLLOWING
16641 : {
16642 1152 : WindowDef *n = makeNode(WindowDef);
16643 :
16644 1152 : n->frameOptions = FRAMEOPTION_START_OFFSET_FOLLOWING;
16645 1152 : n->startOffset = $1;
16646 1152 : n->endOffset = NULL;
16647 1152 : $$ = n;
16648 : }
16649 : ;
16650 :
16651 : opt_window_exclusion_clause:
16652 84 : EXCLUDE CURRENT_P ROW { $$ = FRAMEOPTION_EXCLUDE_CURRENT_ROW; }
16653 96 : | EXCLUDE GROUP_P { $$ = FRAMEOPTION_EXCLUDE_GROUP; }
16654 150 : | EXCLUDE TIES { $$ = FRAMEOPTION_EXCLUDE_TIES; }
16655 18 : | EXCLUDE NO OTHERS { $$ = 0; }
16656 1276 : | /*EMPTY*/ { $$ = 0; }
16657 : ;
16658 :
16659 :
16660 : /*
16661 : * Supporting nonterminals for expressions.
16662 : */
16663 :
16664 : /* Explicit row production.
16665 : *
16666 : * SQL99 allows an optional ROW keyword, so we can now do single-element rows
16667 : * without conflicting with the parenthesized a_expr production. Without the
16668 : * ROW keyword, there must be more than one a_expr inside the parens.
16669 : */
16670 0 : row: ROW '(' expr_list ')' { $$ = $3; }
16671 0 : | ROW '(' ')' { $$ = NIL; }
16672 1932 : | '(' expr_list ',' a_expr ')' { $$ = lappend($2, $4); }
16673 : ;
16674 :
16675 3780 : explicit_row: ROW '(' expr_list ')' { $$ = $3; }
16676 36 : | ROW '(' ')' { $$ = NIL; }
16677 : ;
16678 :
16679 2682 : implicit_row: '(' expr_list ',' a_expr ')' { $$ = lappend($2, $4); }
16680 : ;
16681 :
16682 16666 : sub_type: ANY { $$ = ANY_SUBLINK; }
16683 0 : | SOME { $$ = ANY_SUBLINK; }
16684 324 : | ALL { $$ = ALL_SUBLINK; }
16685 : ;
16686 :
16687 11218 : all_Op: Op { $$ = $1; }
16688 28908 : | MathOp { $$ = $1; }
16689 : ;
16690 :
16691 40 : MathOp: '+' { $$ = "+"; }
16692 62 : | '-' { $$ = "-"; }
16693 118 : | '*' { $$ = "*"; }
16694 0 : | '/' { $$ = "/"; }
16695 8 : | '%' { $$ = "%"; }
16696 0 : | '^' { $$ = "^"; }
16697 978 : | '<' { $$ = "<"; }
16698 868 : | '>' { $$ = ">"; }
16699 24416 : | '=' { $$ = "="; }
16700 844 : | LESS_EQUALS { $$ = "<="; }
16701 836 : | GREATER_EQUALS { $$ = ">="; }
16702 738 : | NOT_EQUALS { $$ = "<>"; }
16703 : ;
16704 :
16705 : qual_Op: Op
16706 43524 : { $$ = list_make1(makeString($1)); }
16707 : | OPERATOR '(' any_operator ')'
16708 15326 : { $$ = $3; }
16709 : ;
16710 :
16711 : qual_all_Op:
16712 : all_Op
16713 1416 : { $$ = list_make1(makeString($1)); }
16714 : | OPERATOR '(' any_operator ')'
16715 34 : { $$ = $3; }
16716 : ;
16717 :
16718 : subquery_Op:
16719 : all_Op
16720 16688 : { $$ = list_make1(makeString($1)); }
16721 : | OPERATOR '(' any_operator ')'
16722 270 : { $$ = $3; }
16723 : | LIKE
16724 24 : { $$ = list_make1(makeString("~~")); }
16725 : | NOT_LA LIKE
16726 12 : { $$ = list_make1(makeString("!~~")); }
16727 : | ILIKE
16728 12 : { $$ = list_make1(makeString("~~*")); }
16729 : | NOT_LA ILIKE
16730 0 : { $$ = list_make1(makeString("!~~*")); }
16731 : /* cannot put SIMILAR TO here, because SIMILAR TO is a hack.
16732 : * the regular expression is preprocessed by a function (similar_to_escape),
16733 : * and the ~ operator for posix regular expressions is used.
16734 : * x SIMILAR TO y -> x ~ similar_to_escape(y)
16735 : * this transformation is made on the fly by the parser upwards.
16736 : * however the SubLink structure which handles any/some/all stuff
16737 : * is not ready for such a thing.
16738 : */
16739 : ;
16740 :
16741 : expr_list: a_expr
16742 : {
16743 160494 : $$ = list_make1($1);
16744 : }
16745 : | expr_list ',' a_expr
16746 : {
16747 144924 : $$ = lappend($1, $3);
16748 : }
16749 : ;
16750 :
16751 : /* function arguments can have names */
16752 : func_arg_list: func_arg_expr
16753 : {
16754 315150 : $$ = list_make1($1);
16755 : }
16756 : | func_arg_list ',' func_arg_expr
16757 : {
16758 279254 : $$ = lappend($1, $3);
16759 : }
16760 : ;
16761 :
16762 : func_arg_expr: a_expr
16763 : {
16764 548018 : $$ = $1;
16765 : }
16766 : | param_name COLON_EQUALS a_expr
16767 : {
16768 45514 : NamedArgExpr *na = makeNode(NamedArgExpr);
16769 :
16770 45514 : na->name = $1;
16771 45514 : na->arg = (Expr *) $3;
16772 45514 : na->argnumber = -1; /* until determined */
16773 45514 : na->location = @1;
16774 45514 : $$ = (Node *) na;
16775 : }
16776 : | param_name EQUALS_GREATER a_expr
16777 : {
16778 1612 : NamedArgExpr *na = makeNode(NamedArgExpr);
16779 :
16780 1612 : na->name = $1;
16781 1612 : na->arg = (Expr *) $3;
16782 1612 : na->argnumber = -1; /* until determined */
16783 1612 : na->location = @1;
16784 1612 : $$ = (Node *) na;
16785 : }
16786 : ;
16787 :
16788 252 : func_arg_list_opt: func_arg_list { $$ = $1; }
16789 0 : | /*EMPTY*/ { $$ = NIL; }
16790 : ;
16791 :
16792 2330 : type_list: Typename { $$ = list_make1($1); }
16793 936 : | type_list ',' Typename { $$ = lappend($1, $3); }
16794 : ;
16795 :
16796 : array_expr: '[' expr_list ']'
16797 : {
16798 7628 : $$ = makeAArrayExpr($2, @1, @3);
16799 : }
16800 : | '[' array_expr_list ']'
16801 : {
16802 412 : $$ = makeAArrayExpr($2, @1, @3);
16803 : }
16804 : | '[' ']'
16805 : {
16806 88 : $$ = makeAArrayExpr(NIL, @1, @2);
16807 : }
16808 : ;
16809 :
16810 412 : array_expr_list: array_expr { $$ = list_make1($1); }
16811 342 : | array_expr_list ',' array_expr { $$ = lappend($1, $3); }
16812 : ;
16813 :
16814 :
16815 : extract_list:
16816 : extract_arg FROM a_expr
16817 : {
16818 1382 : $$ = list_make2(makeStringConst($1, @1), $3);
16819 : }
16820 : ;
16821 :
16822 : /* Allow delimited string Sconst in extract_arg as an SQL extension.
16823 : * - thomas 2001-04-12
16824 : */
16825 : extract_arg:
16826 1124 : IDENT { $$ = $1; }
16827 72 : | YEAR_P { $$ = "year"; }
16828 42 : | MONTH_P { $$ = "month"; }
16829 54 : | DAY_P { $$ = "day"; }
16830 30 : | HOUR_P { $$ = "hour"; }
16831 30 : | MINUTE_P { $$ = "minute"; }
16832 30 : | SECOND_P { $$ = "second"; }
16833 0 : | Sconst { $$ = $1; }
16834 : ;
16835 :
16836 : unicode_normal_form:
16837 24 : NFC { $$ = "NFC"; }
16838 18 : | NFD { $$ = "NFD"; }
16839 18 : | NFKC { $$ = "NFKC"; }
16840 18 : | NFKD { $$ = "NFKD"; }
16841 : ;
16842 :
16843 : /* OVERLAY() arguments */
16844 : overlay_list:
16845 : a_expr PLACING a_expr FROM a_expr FOR a_expr
16846 : {
16847 : /* overlay(A PLACING B FROM C FOR D) is converted to overlay(A, B, C, D) */
16848 34 : $$ = list_make4($1, $3, $5, $7);
16849 : }
16850 : | a_expr PLACING a_expr FROM a_expr
16851 : {
16852 : /* overlay(A PLACING B FROM C) is converted to overlay(A, B, C) */
16853 48 : $$ = list_make3($1, $3, $5);
16854 : }
16855 : ;
16856 :
16857 : /* position_list uses b_expr not a_expr to avoid conflict with general IN */
16858 : position_list:
16859 400 : b_expr IN_P b_expr { $$ = list_make2($3, $1); }
16860 : ;
16861 :
16862 : /*
16863 : * SUBSTRING() arguments
16864 : *
16865 : * Note that SQL:1999 has both
16866 : * text FROM int FOR int
16867 : * and
16868 : * text FROM pattern FOR escape
16869 : *
16870 : * In the parser we map them both to a call to the substring() function and
16871 : * rely on type resolution to pick the right one.
16872 : *
16873 : * In SQL:2003, the second variant was changed to
16874 : * text SIMILAR pattern ESCAPE escape
16875 : * We could in theory map that to a different function internally, but
16876 : * since we still support the SQL:1999 version, we don't. However,
16877 : * ruleutils.c will reverse-list the call in the newer style.
16878 : */
16879 : substr_list:
16880 : a_expr FROM a_expr FOR a_expr
16881 : {
16882 122 : $$ = list_make3($1, $3, $5);
16883 : }
16884 : | a_expr FOR a_expr FROM a_expr
16885 : {
16886 : /* not legal per SQL, but might as well allow it */
16887 0 : $$ = list_make3($1, $5, $3);
16888 : }
16889 : | a_expr FROM a_expr
16890 : {
16891 : /*
16892 : * Because we aren't restricting data types here, this
16893 : * syntax can end up resolving to textregexsubstr().
16894 : * We've historically allowed that to happen, so continue
16895 : * to accept it. However, ruleutils.c will reverse-list
16896 : * such a call in regular function call syntax.
16897 : */
16898 370 : $$ = list_make2($1, $3);
16899 : }
16900 : | a_expr FOR a_expr
16901 : {
16902 : /* not legal per SQL */
16903 :
16904 : /*
16905 : * Since there are no cases where this syntax allows
16906 : * a textual FOR value, we forcibly cast the argument
16907 : * to int4. The possible matches in pg_proc are
16908 : * substring(text,int4) and substring(text,text),
16909 : * and we don't want the parser to choose the latter,
16910 : * which it is likely to do if the second argument
16911 : * is unknown or doesn't have an implicit cast to int4.
16912 : */
16913 36 : $$ = list_make3($1, makeIntConst(1, -1),
16914 : makeTypeCast($3,
16915 : SystemTypeName("int4"), -1));
16916 : }
16917 : | a_expr SIMILAR a_expr ESCAPE a_expr
16918 : {
16919 182 : $$ = list_make3($1, $3, $5);
16920 : }
16921 : ;
16922 :
16923 604 : trim_list: a_expr FROM expr_list { $$ = lappend($3, $1); }
16924 24 : | FROM expr_list { $$ = $2; }
16925 86 : | expr_list { $$ = $1; }
16926 : ;
16927 :
16928 : /*
16929 : * Define SQL-style CASE clause.
16930 : * - Full specification
16931 : * CASE WHEN a = b THEN c ... ELSE d END
16932 : * - Implicit argument
16933 : * CASE a WHEN b THEN c ... ELSE d END
16934 : */
16935 : case_expr: CASE case_arg when_clause_list case_default END_P
16936 : {
16937 39014 : CaseExpr *c = makeNode(CaseExpr);
16938 :
16939 39014 : c->casetype = InvalidOid; /* not analyzed yet */
16940 39014 : c->arg = (Expr *) $2;
16941 39014 : c->args = $3;
16942 39014 : c->defresult = (Expr *) $4;
16943 39014 : c->location = @1;
16944 39014 : $$ = (Node *) c;
16945 : }
16946 : ;
16947 :
16948 : when_clause_list:
16949 : /* There must be at least one */
16950 39014 : when_clause { $$ = list_make1($1); }
16951 29026 : | when_clause_list when_clause { $$ = lappend($1, $2); }
16952 : ;
16953 :
16954 : when_clause:
16955 : WHEN a_expr THEN a_expr
16956 : {
16957 68040 : CaseWhen *w = makeNode(CaseWhen);
16958 :
16959 68040 : w->expr = (Expr *) $2;
16960 68040 : w->result = (Expr *) $4;
16961 68040 : w->location = @1;
16962 68040 : $$ = (Node *) w;
16963 : }
16964 : ;
16965 :
16966 : case_default:
16967 29298 : ELSE a_expr { $$ = $2; }
16968 9716 : | /*EMPTY*/ { $$ = NULL; }
16969 : ;
16970 :
16971 6746 : case_arg: a_expr { $$ = $1; }
16972 32268 : | /*EMPTY*/ { $$ = NULL; }
16973 : ;
16974 :
16975 : columnref: ColId
16976 : {
16977 741912 : $$ = makeColumnRef($1, NIL, @1, yyscanner);
16978 : }
16979 : | ColId indirection
16980 : {
16981 1052432 : $$ = makeColumnRef($1, $2, @1, yyscanner);
16982 : }
16983 : ;
16984 :
16985 : indirection_el:
16986 : '.' attr_name
16987 : {
16988 1421856 : $$ = (Node *) makeString($2);
16989 : }
16990 : | '.' '*'
16991 : {
16992 6970 : $$ = (Node *) makeNode(A_Star);
16993 : }
16994 : | '[' a_expr ']'
16995 : {
16996 12866 : A_Indices *ai = makeNode(A_Indices);
16997 :
16998 12866 : ai->is_slice = false;
16999 12866 : ai->lidx = NULL;
17000 12866 : ai->uidx = $2;
17001 12866 : $$ = (Node *) ai;
17002 : }
17003 : | '[' opt_slice_bound ':' opt_slice_bound ']'
17004 : {
17005 588 : A_Indices *ai = makeNode(A_Indices);
17006 :
17007 588 : ai->is_slice = true;
17008 588 : ai->lidx = $2;
17009 588 : ai->uidx = $4;
17010 588 : $$ = (Node *) ai;
17011 : }
17012 : ;
17013 :
17014 : opt_slice_bound:
17015 996 : a_expr { $$ = $1; }
17016 180 : | /*EMPTY*/ { $$ = NULL; }
17017 : ;
17018 :
17019 : indirection:
17020 1421800 : indirection_el { $$ = list_make1($1); }
17021 3080 : | indirection indirection_el { $$ = lappend($1, $2); }
17022 : ;
17023 :
17024 : opt_indirection:
17025 194480 : /*EMPTY*/ { $$ = NIL; }
17026 17400 : | opt_indirection indirection_el { $$ = lappend($1, $2); }
17027 : ;
17028 :
17029 : opt_asymmetric: ASYMMETRIC
17030 : | /*EMPTY*/
17031 : ;
17032 :
17033 : /* SQL/JSON support */
17034 : json_passing_clause_opt:
17035 336 : PASSING json_arguments { $$ = $2; }
17036 1934 : | /*EMPTY*/ { $$ = NIL; }
17037 : ;
17038 :
17039 : json_arguments:
17040 336 : json_argument { $$ = list_make1($1); }
17041 126 : | json_arguments ',' json_argument { $$ = lappend($1, $3); }
17042 : ;
17043 :
17044 : json_argument:
17045 : json_value_expr AS ColLabel
17046 : {
17047 462 : JsonArgument *n = makeNode(JsonArgument);
17048 :
17049 462 : n->val = (JsonValueExpr *) $1;
17050 462 : n->name = $3;
17051 462 : $$ = (Node *) n;
17052 : }
17053 : ;
17054 :
17055 : /* ARRAY is a noise word */
17056 : json_wrapper_behavior:
17057 42 : WITHOUT WRAPPER { $$ = JSW_NONE; }
17058 0 : | WITHOUT ARRAY WRAPPER { $$ = JSW_NONE; }
17059 78 : | WITH WRAPPER { $$ = JSW_UNCONDITIONAL; }
17060 12 : | WITH ARRAY WRAPPER { $$ = JSW_UNCONDITIONAL; }
17061 0 : | WITH CONDITIONAL ARRAY WRAPPER { $$ = JSW_CONDITIONAL; }
17062 12 : | WITH UNCONDITIONAL ARRAY WRAPPER { $$ = JSW_UNCONDITIONAL; }
17063 36 : | WITH CONDITIONAL WRAPPER { $$ = JSW_CONDITIONAL; }
17064 6 : | WITH UNCONDITIONAL WRAPPER { $$ = JSW_UNCONDITIONAL; }
17065 1634 : | /* empty */ { $$ = JSW_UNSPEC; }
17066 : ;
17067 :
17068 : json_behavior:
17069 : DEFAULT a_expr
17070 384 : { $$ = (Node *) makeJsonBehavior(JSON_BEHAVIOR_DEFAULT, $2, @1); }
17071 : | json_behavior_type
17072 702 : { $$ = (Node *) makeJsonBehavior($1, NULL, @1); }
17073 : ;
17074 :
17075 : json_behavior_type:
17076 492 : ERROR_P { $$ = JSON_BEHAVIOR_ERROR; }
17077 30 : | NULL_P { $$ = JSON_BEHAVIOR_NULL; }
17078 30 : | TRUE_P { $$ = JSON_BEHAVIOR_TRUE; }
17079 12 : | FALSE_P { $$ = JSON_BEHAVIOR_FALSE; }
17080 12 : | UNKNOWN { $$ = JSON_BEHAVIOR_UNKNOWN; }
17081 30 : | EMPTY_P ARRAY { $$ = JSON_BEHAVIOR_EMPTY_ARRAY; }
17082 72 : | EMPTY_P OBJECT_P { $$ = JSON_BEHAVIOR_EMPTY_OBJECT; }
17083 : /* non-standard, for Oracle compatibility only */
17084 24 : | EMPTY_P { $$ = JSON_BEHAVIOR_EMPTY_ARRAY; }
17085 : ;
17086 :
17087 : json_behavior_clause_opt:
17088 : json_behavior ON EMPTY_P
17089 174 : { $$ = list_make2($1, NULL); }
17090 : | json_behavior ON ERROR_P
17091 552 : { $$ = list_make2(NULL, $1); }
17092 : | json_behavior ON EMPTY_P json_behavior ON ERROR_P
17093 102 : { $$ = list_make2($1, $4); }
17094 : | /* EMPTY */
17095 1568 : { $$ = list_make2(NULL, NULL); }
17096 : ;
17097 :
17098 : json_on_error_clause_opt:
17099 : json_behavior ON ERROR_P
17100 150 : { $$ = $1; }
17101 : | /* EMPTY */
17102 686 : { $$ = NULL; }
17103 : ;
17104 :
17105 : json_value_expr:
17106 : a_expr json_format_clause_opt
17107 : {
17108 : /* formatted_expr will be set during parse-analysis. */
17109 4202 : $$ = (Node *) makeJsonValueExpr((Expr *) $1, NULL,
17110 4202 : castNode(JsonFormat, $2));
17111 : }
17112 : ;
17113 :
17114 : json_format_clause:
17115 : FORMAT_LA JSON ENCODING name
17116 : {
17117 : int encoding;
17118 :
17119 100 : if (!pg_strcasecmp($4, "utf8"))
17120 64 : encoding = JS_ENC_UTF8;
17121 36 : else if (!pg_strcasecmp($4, "utf16"))
17122 12 : encoding = JS_ENC_UTF16;
17123 24 : else if (!pg_strcasecmp($4, "utf32"))
17124 12 : encoding = JS_ENC_UTF32;
17125 : else
17126 12 : ereport(ERROR,
17127 : (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
17128 : errmsg("unrecognized JSON encoding: %s", $4),
17129 : parser_errposition(@4)));
17130 :
17131 88 : $$ = (Node *) makeJsonFormat(JS_FORMAT_JSON, encoding, @1);
17132 : }
17133 : | FORMAT_LA JSON
17134 : {
17135 412 : $$ = (Node *) makeJsonFormat(JS_FORMAT_JSON, JS_ENC_DEFAULT, @1);
17136 : }
17137 : ;
17138 :
17139 : json_format_clause_opt:
17140 : json_format_clause
17141 : {
17142 392 : $$ = $1;
17143 : }
17144 : | /* EMPTY */
17145 : {
17146 5314 : $$ = (Node *) makeJsonFormat(JS_FORMAT_DEFAULT, JS_ENC_DEFAULT, -1);
17147 : }
17148 : ;
17149 :
17150 : json_quotes_clause_opt:
17151 12 : KEEP QUOTES ON SCALAR STRING_P { $$ = JS_QUOTES_KEEP; }
17152 90 : | KEEP QUOTES { $$ = JS_QUOTES_KEEP; }
17153 12 : | OMIT QUOTES ON SCALAR STRING_P { $$ = JS_QUOTES_OMIT; }
17154 168 : | OMIT QUOTES { $$ = JS_QUOTES_OMIT; }
17155 1538 : | /* EMPTY */ { $$ = JS_QUOTES_UNSPEC; }
17156 : ;
17157 :
17158 : json_returning_clause_opt:
17159 : RETURNING Typename json_format_clause_opt
17160 : {
17161 1444 : JsonOutput *n = makeNode(JsonOutput);
17162 :
17163 1444 : n->typeName = $2;
17164 1444 : n->returning = makeNode(JsonReturning);
17165 1444 : n->returning->format = (JsonFormat *) $3;
17166 1444 : $$ = (Node *) n;
17167 : }
17168 1278 : | /* EMPTY */ { $$ = NULL; }
17169 : ;
17170 :
17171 : /*
17172 : * We must assign the only-JSON production a precedence less than IDENT in
17173 : * order to favor shifting over reduction when JSON is followed by VALUE_P,
17174 : * OBJECT_P, or SCALAR. (ARRAY doesn't need that treatment, because it's a
17175 : * fully reserved word.) Because json_predicate_type_constraint is always
17176 : * followed by json_key_uniqueness_constraint_opt, we also need the only-JSON
17177 : * production to have precedence less than WITH and WITHOUT. UNBOUNDED isn't
17178 : * really related to this syntax, but it's a convenient choice because it
17179 : * already has a precedence less than IDENT for other reasons.
17180 : */
17181 : json_predicate_type_constraint:
17182 202 : JSON %prec UNBOUNDED { $$ = JS_TYPE_ANY; }
17183 28 : | JSON VALUE_P { $$ = JS_TYPE_ANY; }
17184 40 : | JSON ARRAY { $$ = JS_TYPE_ARRAY; }
17185 40 : | JSON OBJECT_P { $$ = JS_TYPE_OBJECT; }
17186 40 : | JSON SCALAR { $$ = JS_TYPE_SCALAR; }
17187 : ;
17188 :
17189 : /*
17190 : * KEYS is a noise word here. To avoid shift/reduce conflicts, assign the
17191 : * KEYS-less productions a precedence less than IDENT (i.e., less than KEYS).
17192 : * This prevents reducing them when the next token is KEYS.
17193 : */
17194 : json_key_uniqueness_constraint_opt:
17195 108 : WITH UNIQUE KEYS { $$ = true; }
17196 100 : | WITH UNIQUE %prec UNBOUNDED { $$ = true; }
17197 44 : | WITHOUT UNIQUE KEYS { $$ = false; }
17198 16 : | WITHOUT UNIQUE %prec UNBOUNDED { $$ = false; }
17199 798 : | /* EMPTY */ %prec UNBOUNDED { $$ = false; }
17200 : ;
17201 :
17202 : json_name_and_value_list:
17203 : json_name_and_value
17204 348 : { $$ = list_make1($1); }
17205 : | json_name_and_value_list ',' json_name_and_value
17206 256 : { $$ = lappend($1, $3); }
17207 : ;
17208 :
17209 : json_name_and_value:
17210 : /* Supporting this syntax seems to require major surgery
17211 : KEY c_expr VALUE_P json_value_expr
17212 : { $$ = makeJsonKeyValue($2, $4); }
17213 : |
17214 : */
17215 : c_expr VALUE_P json_value_expr
17216 24 : { $$ = makeJsonKeyValue($1, $3); }
17217 : |
17218 : a_expr ':' json_value_expr
17219 784 : { $$ = makeJsonKeyValue($1, $3); }
17220 : ;
17221 :
17222 : /* empty means false for objects, true for arrays */
17223 : json_object_constructor_null_clause_opt:
17224 30 : NULL_P ON NULL_P { $$ = false; }
17225 110 : | ABSENT ON NULL_P { $$ = true; }
17226 412 : | /* EMPTY */ { $$ = false; }
17227 : ;
17228 :
17229 : json_array_constructor_null_clause_opt:
17230 60 : NULL_P ON NULL_P { $$ = false; }
17231 36 : | ABSENT ON NULL_P { $$ = true; }
17232 168 : | /* EMPTY */ { $$ = true; }
17233 : ;
17234 :
17235 : json_value_expr_list:
17236 108 : json_value_expr { $$ = list_make1($1); }
17237 126 : | json_value_expr_list ',' json_value_expr { $$ = lappend($1, $3);}
17238 : ;
17239 :
17240 : json_aggregate_func:
17241 : JSON_OBJECTAGG '('
17242 : json_name_and_value
17243 : json_object_constructor_null_clause_opt
17244 : json_key_uniqueness_constraint_opt
17245 : json_returning_clause_opt
17246 : ')'
17247 : {
17248 204 : JsonObjectAgg *n = makeNode(JsonObjectAgg);
17249 :
17250 204 : n->arg = (JsonKeyValue *) $3;
17251 204 : n->absent_on_null = $4;
17252 204 : n->unique = $5;
17253 204 : n->constructor = makeNode(JsonAggConstructor);
17254 204 : n->constructor->output = (JsonOutput *) $6;
17255 204 : n->constructor->agg_order = NULL;
17256 204 : n->constructor->location = @1;
17257 204 : $$ = (Node *) n;
17258 : }
17259 : | JSON_ARRAYAGG '('
17260 : json_value_expr
17261 : json_array_aggregate_order_by_clause_opt
17262 : json_array_constructor_null_clause_opt
17263 : json_returning_clause_opt
17264 : ')'
17265 : {
17266 156 : JsonArrayAgg *n = makeNode(JsonArrayAgg);
17267 :
17268 156 : n->arg = (JsonValueExpr *) $3;
17269 156 : n->absent_on_null = $5;
17270 156 : n->constructor = makeNode(JsonAggConstructor);
17271 156 : n->constructor->agg_order = $4;
17272 156 : n->constructor->output = (JsonOutput *) $6;
17273 156 : n->constructor->location = @1;
17274 156 : $$ = (Node *) n;
17275 : }
17276 : ;
17277 :
17278 : json_array_aggregate_order_by_clause_opt:
17279 18 : ORDER BY sortby_list { $$ = $3; }
17280 138 : | /* EMPTY */ { $$ = NIL; }
17281 : ;
17282 :
17283 : /*****************************************************************************
17284 : *
17285 : * target list for SELECT
17286 : *
17287 : *****************************************************************************/
17288 :
17289 465666 : opt_target_list: target_list { $$ = $1; }
17290 546 : | /* EMPTY */ { $$ = NIL; }
17291 : ;
17292 :
17293 : target_list:
17294 472478 : target_el { $$ = list_make1($1); }
17295 670490 : | target_list ',' target_el { $$ = lappend($1, $3); }
17296 : ;
17297 :
17298 : target_el: a_expr AS ColLabel
17299 : {
17300 234074 : $$ = makeNode(ResTarget);
17301 234074 : $$->name = $3;
17302 234074 : $$->indirection = NIL;
17303 234074 : $$->val = (Node *) $1;
17304 234074 : $$->location = @1;
17305 : }
17306 : | a_expr BareColLabel
17307 : {
17308 3522 : $$ = makeNode(ResTarget);
17309 3522 : $$->name = $2;
17310 3522 : $$->indirection = NIL;
17311 3522 : $$->val = (Node *) $1;
17312 3522 : $$->location = @1;
17313 : }
17314 : | a_expr
17315 : {
17316 849152 : $$ = makeNode(ResTarget);
17317 849152 : $$->name = NULL;
17318 849152 : $$->indirection = NIL;
17319 849152 : $$->val = (Node *) $1;
17320 849152 : $$->location = @1;
17321 : }
17322 : | '*'
17323 : {
17324 56220 : ColumnRef *n = makeNode(ColumnRef);
17325 :
17326 56220 : n->fields = list_make1(makeNode(A_Star));
17327 56220 : n->location = @1;
17328 :
17329 56220 : $$ = makeNode(ResTarget);
17330 56220 : $$->name = NULL;
17331 56220 : $$->indirection = NIL;
17332 56220 : $$->val = (Node *) n;
17333 56220 : $$->location = @1;
17334 : }
17335 : ;
17336 :
17337 :
17338 : /*****************************************************************************
17339 : *
17340 : * Names and constants
17341 : *
17342 : *****************************************************************************/
17343 :
17344 : qualified_name_list:
17345 17222 : qualified_name { $$ = list_make1($1); }
17346 454 : | qualified_name_list ',' qualified_name { $$ = lappend($1, $3); }
17347 : ;
17348 :
17349 : /*
17350 : * The production for a qualified relation name has to exactly match the
17351 : * production for a qualified func_name, because in a FROM clause we cannot
17352 : * tell which we are parsing until we see what comes after it ('(' for a
17353 : * func_name, something else for a relation). Therefore we allow 'indirection'
17354 : * which may contain subscripts, and reject that case in the C code.
17355 : */
17356 : qualified_name:
17357 : ColId
17358 : {
17359 417998 : $$ = makeRangeVar(NULL, $1, @1);
17360 : }
17361 : | ColId indirection
17362 : {
17363 243348 : $$ = makeRangeVarFromQualifiedName($1, $2, @1, yyscanner);
17364 : }
17365 : ;
17366 :
17367 : name_list: name
17368 28188 : { $$ = list_make1(makeString($1)); }
17369 : | name_list ',' name
17370 61538 : { $$ = lappend($1, makeString($3)); }
17371 : ;
17372 :
17373 :
17374 176190 : name: ColId { $$ = $1; };
17375 :
17376 1547100 : attr_name: ColLabel { $$ = $1; };
17377 :
17378 54 : file_name: Sconst { $$ = $1; };
17379 :
17380 : /*
17381 : * The production for a qualified func_name has to exactly match the
17382 : * production for a qualified columnref, because we cannot tell which we
17383 : * are parsing until we see what comes after it ('(' or Sconst for a func_name,
17384 : * anything else for a columnref). Therefore we allow 'indirection' which
17385 : * may contain subscripts, and reject that case in the C code. (If we
17386 : * ever implement SQL99-like methods, such syntax may actually become legal!)
17387 : */
17388 : func_name: type_function_name
17389 292978 : { $$ = list_make1(makeString($1)); }
17390 : | ColId indirection
17391 : {
17392 125942 : $$ = check_func_name(lcons(makeString($1), $2),
17393 : yyscanner);
17394 : }
17395 : ;
17396 :
17397 :
17398 : /*
17399 : * Constants
17400 : */
17401 : AexprConst: Iconst
17402 : {
17403 374310 : $$ = makeIntConst($1, @1);
17404 : }
17405 : | FCONST
17406 : {
17407 11400 : $$ = makeFloatConst($1, @1);
17408 : }
17409 : | Sconst
17410 : {
17411 689414 : $$ = makeStringConst($1, @1);
17412 : }
17413 : | BCONST
17414 : {
17415 754 : $$ = makeBitStringConst($1, @1);
17416 : }
17417 : | XCONST
17418 : {
17419 : /* This is a bit constant per SQL99:
17420 : * Without Feature F511, "BIT data type",
17421 : * a <general literal> shall not be a
17422 : * <bit string literal> or a <hex string literal>.
17423 : */
17424 3302 : $$ = makeBitStringConst($1, @1);
17425 : }
17426 : | func_name Sconst
17427 : {
17428 : /* generic type 'literal' syntax */
17429 9836 : TypeName *t = makeTypeNameFromNameList($1);
17430 :
17431 9836 : t->location = @1;
17432 9836 : $$ = makeStringConstCast($2, @2, t);
17433 : }
17434 : | func_name '(' func_arg_list opt_sort_clause ')' Sconst
17435 : {
17436 : /* generic syntax with a type modifier */
17437 0 : TypeName *t = makeTypeNameFromNameList($1);
17438 : ListCell *lc;
17439 :
17440 : /*
17441 : * We must use func_arg_list and opt_sort_clause in the
17442 : * production to avoid reduce/reduce conflicts, but we
17443 : * don't actually wish to allow NamedArgExpr in this
17444 : * context, nor ORDER BY.
17445 : */
17446 0 : foreach(lc, $3)
17447 : {
17448 0 : NamedArgExpr *arg = (NamedArgExpr *) lfirst(lc);
17449 :
17450 0 : if (IsA(arg, NamedArgExpr))
17451 0 : ereport(ERROR,
17452 : (errcode(ERRCODE_SYNTAX_ERROR),
17453 : errmsg("type modifier cannot have parameter name"),
17454 : parser_errposition(arg->location)));
17455 : }
17456 0 : if ($4 != NIL)
17457 0 : ereport(ERROR,
17458 : (errcode(ERRCODE_SYNTAX_ERROR),
17459 : errmsg("type modifier cannot have ORDER BY"),
17460 : parser_errposition(@4)));
17461 :
17462 0 : t->typmods = $3;
17463 0 : t->location = @1;
17464 0 : $$ = makeStringConstCast($6, @6, t);
17465 : }
17466 : | ConstTypename Sconst
17467 : {
17468 3174 : $$ = makeStringConstCast($2, @2, $1);
17469 : }
17470 : | ConstInterval Sconst opt_interval
17471 : {
17472 3298 : TypeName *t = $1;
17473 :
17474 3298 : t->typmods = $3;
17475 3298 : $$ = makeStringConstCast($2, @2, t);
17476 : }
17477 : | ConstInterval '(' Iconst ')' Sconst
17478 : {
17479 12 : TypeName *t = $1;
17480 :
17481 12 : t->typmods = list_make2(makeIntConst(INTERVAL_FULL_RANGE, -1),
17482 : makeIntConst($3, @3));
17483 12 : $$ = makeStringConstCast($5, @5, t);
17484 : }
17485 : | TRUE_P
17486 : {
17487 31124 : $$ = makeBoolAConst(true, @1);
17488 : }
17489 : | FALSE_P
17490 : {
17491 35632 : $$ = makeBoolAConst(false, @1);
17492 : }
17493 : | NULL_P
17494 : {
17495 66866 : $$ = makeNullAConst(@1);
17496 : }
17497 : ;
17498 :
17499 402372 : Iconst: ICONST { $$ = $1; };
17500 762240 : Sconst: SCONST { $$ = $1; };
17501 :
17502 17332 : SignedIconst: Iconst { $$ = $1; }
17503 0 : | '+' Iconst { $$ = + $2; }
17504 288 : | '-' Iconst { $$ = - $2; }
17505 : ;
17506 :
17507 : /* Role specifications */
17508 : RoleId: RoleSpec
17509 : {
17510 1904 : RoleSpec *spc = (RoleSpec *) $1;
17511 :
17512 1904 : switch (spc->roletype)
17513 : {
17514 1894 : case ROLESPEC_CSTRING:
17515 1894 : $$ = spc->rolename;
17516 1894 : break;
17517 4 : case ROLESPEC_PUBLIC:
17518 4 : ereport(ERROR,
17519 : (errcode(ERRCODE_RESERVED_NAME),
17520 : errmsg("role name \"%s\" is reserved",
17521 : "public"),
17522 : parser_errposition(@1)));
17523 : break;
17524 2 : case ROLESPEC_SESSION_USER:
17525 2 : ereport(ERROR,
17526 : (errcode(ERRCODE_RESERVED_NAME),
17527 : errmsg("%s cannot be used as a role name here",
17528 : "SESSION_USER"),
17529 : parser_errposition(@1)));
17530 : break;
17531 2 : case ROLESPEC_CURRENT_USER:
17532 2 : ereport(ERROR,
17533 : (errcode(ERRCODE_RESERVED_NAME),
17534 : errmsg("%s cannot be used as a role name here",
17535 : "CURRENT_USER"),
17536 : parser_errposition(@1)));
17537 : break;
17538 2 : case ROLESPEC_CURRENT_ROLE:
17539 2 : ereport(ERROR,
17540 : (errcode(ERRCODE_RESERVED_NAME),
17541 : errmsg("%s cannot be used as a role name here",
17542 : "CURRENT_ROLE"),
17543 : parser_errposition(@1)));
17544 : break;
17545 : }
17546 : }
17547 : ;
17548 :
17549 : RoleSpec: NonReservedWord
17550 : {
17551 : /*
17552 : * "public" and "none" are not keywords, but they must
17553 : * be treated specially here.
17554 : */
17555 : RoleSpec *n;
17556 :
17557 32256 : if (strcmp($1, "public") == 0)
17558 : {
17559 17466 : n = (RoleSpec *) makeRoleSpec(ROLESPEC_PUBLIC, @1);
17560 17466 : n->roletype = ROLESPEC_PUBLIC;
17561 : }
17562 14790 : else if (strcmp($1, "none") == 0)
17563 : {
17564 26 : ereport(ERROR,
17565 : (errcode(ERRCODE_RESERVED_NAME),
17566 : errmsg("role name \"%s\" is reserved",
17567 : "none"),
17568 : parser_errposition(@1)));
17569 : }
17570 : else
17571 : {
17572 14764 : n = makeRoleSpec(ROLESPEC_CSTRING, @1);
17573 14764 : n->rolename = pstrdup($1);
17574 : }
17575 32230 : $$ = n;
17576 : }
17577 : | CURRENT_ROLE
17578 : {
17579 130 : $$ = makeRoleSpec(ROLESPEC_CURRENT_ROLE, @1);
17580 : }
17581 : | CURRENT_USER
17582 : {
17583 228 : $$ = makeRoleSpec(ROLESPEC_CURRENT_USER, @1);
17584 : }
17585 : | SESSION_USER
17586 : {
17587 36 : $$ = makeRoleSpec(ROLESPEC_SESSION_USER, @1);
17588 : }
17589 : ;
17590 :
17591 : role_list: RoleSpec
17592 3248 : { $$ = list_make1($1); }
17593 : | role_list ',' RoleSpec
17594 270 : { $$ = lappend($1, $3); }
17595 : ;
17596 :
17597 :
17598 : /*****************************************************************************
17599 : *
17600 : * PL/pgSQL extensions
17601 : *
17602 : * You'd think a PL/pgSQL "expression" should be just an a_expr, but
17603 : * historically it can include just about anything that can follow SELECT.
17604 : * Therefore the returned struct is a SelectStmt.
17605 : *****************************************************************************/
17606 :
17607 : PLpgSQL_Expr: opt_distinct_clause opt_target_list
17608 : from_clause where_clause
17609 : group_clause having_clause window_clause
17610 : opt_sort_clause opt_select_limit opt_for_locking_clause
17611 : {
17612 40010 : SelectStmt *n = makeNode(SelectStmt);
17613 :
17614 40010 : n->distinctClause = $1;
17615 40010 : n->targetList = $2;
17616 40010 : n->fromClause = $3;
17617 40010 : n->whereClause = $4;
17618 40010 : n->groupClause = ($5)->list;
17619 40010 : n->groupDistinct = ($5)->distinct;
17620 40010 : n->havingClause = $6;
17621 40010 : n->windowClause = $7;
17622 40010 : n->sortClause = $8;
17623 40010 : if ($9)
17624 : {
17625 4 : n->limitOffset = $9->limitOffset;
17626 4 : n->limitCount = $9->limitCount;
17627 4 : if (!n->sortClause &&
17628 4 : $9->limitOption == LIMIT_OPTION_WITH_TIES)
17629 0 : ereport(ERROR,
17630 : (errcode(ERRCODE_SYNTAX_ERROR),
17631 : errmsg("WITH TIES cannot be specified without ORDER BY clause"),
17632 : parser_errposition($9->optionLoc)));
17633 4 : n->limitOption = $9->limitOption;
17634 : }
17635 40010 : n->lockingClause = $10;
17636 40010 : $$ = (Node *) n;
17637 : }
17638 : ;
17639 :
17640 : /*
17641 : * PL/pgSQL Assignment statement: name opt_indirection := PLpgSQL_Expr
17642 : */
17643 :
17644 : PLAssignStmt: plassign_target opt_indirection plassign_equals PLpgSQL_Expr
17645 : {
17646 7044 : PLAssignStmt *n = makeNode(PLAssignStmt);
17647 :
17648 7044 : n->name = $1;
17649 7044 : n->indirection = check_indirection($2, yyscanner);
17650 : /* nnames will be filled by calling production */
17651 7044 : n->val = (SelectStmt *) $4;
17652 7044 : n->location = @1;
17653 7044 : $$ = (Node *) n;
17654 : }
17655 : ;
17656 :
17657 7020 : plassign_target: ColId { $$ = $1; }
17658 24 : | PARAM { $$ = psprintf("$%d", $1); }
17659 : ;
17660 :
17661 : plassign_equals: COLON_EQUALS
17662 : | '='
17663 : ;
17664 :
17665 :
17666 : /*
17667 : * Name classification hierarchy.
17668 : *
17669 : * IDENT is the lexeme returned by the lexer for identifiers that match
17670 : * no known keyword. In most cases, we can accept certain keywords as
17671 : * names, not only IDENTs. We prefer to accept as many such keywords
17672 : * as possible to minimize the impact of "reserved words" on programmers.
17673 : * So, we divide names into several possible classes. The classification
17674 : * is chosen in part to make keywords acceptable as names wherever possible.
17675 : */
17676 :
17677 : /* Column identifier --- names that can be column, table, etc names.
17678 : */
17679 3343674 : ColId: IDENT { $$ = $1; }
17680 57456 : | unreserved_keyword { $$ = pstrdup($1); }
17681 6172 : | col_name_keyword { $$ = pstrdup($1); }
17682 : ;
17683 :
17684 : /* Type/function identifier --- names that can be type or function names.
17685 : */
17686 707086 : type_function_name: IDENT { $$ = $1; }
17687 74224 : | unreserved_keyword { $$ = pstrdup($1); }
17688 66 : | type_func_name_keyword { $$ = pstrdup($1); }
17689 : ;
17690 :
17691 : /* Any not-fully-reserved word --- these names can be, eg, role names.
17692 : */
17693 82842 : NonReservedWord: IDENT { $$ = $1; }
17694 30154 : | unreserved_keyword { $$ = pstrdup($1); }
17695 178 : | col_name_keyword { $$ = pstrdup($1); }
17696 5236 : | type_func_name_keyword { $$ = pstrdup($1); }
17697 : ;
17698 :
17699 : /* Column label --- allowed labels in "AS" clauses.
17700 : * This presently includes *all* Postgres keywords.
17701 : */
17702 1765228 : ColLabel: IDENT { $$ = $1; }
17703 39724 : | unreserved_keyword { $$ = pstrdup($1); }
17704 284 : | col_name_keyword { $$ = pstrdup($1); }
17705 1778 : | type_func_name_keyword { $$ = pstrdup($1); }
17706 7508 : | reserved_keyword { $$ = pstrdup($1); }
17707 : ;
17708 :
17709 : /* Bare column label --- names that can be column labels without writing "AS".
17710 : * This classification is orthogonal to the other keyword categories.
17711 : */
17712 3508 : BareColLabel: IDENT { $$ = $1; }
17713 14 : | bare_label_keyword { $$ = pstrdup($1); }
17714 : ;
17715 :
17716 :
17717 : /*
17718 : * Keyword category lists. Generally, every keyword present in
17719 : * the Postgres grammar should appear in exactly one of these lists.
17720 : *
17721 : * Put a new keyword into the first list that it can go into without causing
17722 : * shift or reduce conflicts. The earlier lists define "less reserved"
17723 : * categories of keywords.
17724 : *
17725 : * Make sure that each keyword's category in kwlist.h matches where
17726 : * it is listed here. (Someday we may be able to generate these lists and
17727 : * kwlist.h's table from one source of truth.)
17728 : */
17729 :
17730 : /* "Unreserved" keywords --- available for use as any kind of name.
17731 : */
17732 : unreserved_keyword:
17733 : ABORT_P
17734 : | ABSENT
17735 : | ABSOLUTE_P
17736 : | ACCESS
17737 : | ACTION
17738 : | ADD_P
17739 : | ADMIN
17740 : | AFTER
17741 : | AGGREGATE
17742 : | ALSO
17743 : | ALTER
17744 : | ALWAYS
17745 : | ASENSITIVE
17746 : | ASSERTION
17747 : | ASSIGNMENT
17748 : | AT
17749 : | ATOMIC
17750 : | ATTACH
17751 : | ATTRIBUTE
17752 : | BACKWARD
17753 : | BEFORE
17754 : | BEGIN_P
17755 : | BREADTH
17756 : | BY
17757 : | CACHE
17758 : | CALL
17759 : | CALLED
17760 : | CASCADE
17761 : | CASCADED
17762 : | CATALOG_P
17763 : | CHAIN
17764 : | CHARACTERISTICS
17765 : | CHECKPOINT
17766 : | CLASS
17767 : | CLOSE
17768 : | CLUSTER
17769 : | COLUMNS
17770 : | COMMENT
17771 : | COMMENTS
17772 : | COMMIT
17773 : | COMMITTED
17774 : | COMPRESSION
17775 : | CONDITIONAL
17776 : | CONFIGURATION
17777 : | CONFLICT
17778 : | CONNECTION
17779 : | CONSTRAINTS
17780 : | CONTENT_P
17781 : | CONTINUE_P
17782 : | CONVERSION_P
17783 : | COPY
17784 : | COST
17785 : | CSV
17786 : | CUBE
17787 : | CURRENT_P
17788 : | CURSOR
17789 : | CYCLE
17790 : | DATA_P
17791 : | DATABASE
17792 : | DAY_P
17793 : | DEALLOCATE
17794 : | DECLARE
17795 : | DEFAULTS
17796 : | DEFERRED
17797 : | DEFINER
17798 : | DELETE_P
17799 : | DELIMITER
17800 : | DELIMITERS
17801 : | DEPENDS
17802 : | DEPTH
17803 : | DETACH
17804 : | DICTIONARY
17805 : | DISABLE_P
17806 : | DISCARD
17807 : | DOCUMENT_P
17808 : | DOMAIN_P
17809 : | DOUBLE_P
17810 : | DROP
17811 : | EACH
17812 : | EMPTY_P
17813 : | ENABLE_P
17814 : | ENCODING
17815 : | ENCRYPTED
17816 : | ENFORCED
17817 : | ENUM_P
17818 : | ERROR_P
17819 : | ESCAPE
17820 : | EVENT
17821 : | EXCLUDE
17822 : | EXCLUDING
17823 : | EXCLUSIVE
17824 : | EXECUTE
17825 : | EXPLAIN
17826 : | EXPRESSION
17827 : | EXTENSION
17828 : | EXTERNAL
17829 : | FAMILY
17830 : | FILTER
17831 : | FINALIZE
17832 : | FIRST_P
17833 : | FOLLOWING
17834 : | FORCE
17835 : | FORMAT
17836 : | FORWARD
17837 : | FUNCTION
17838 : | FUNCTIONS
17839 : | GENERATED
17840 : | GLOBAL
17841 : | GRANTED
17842 : | GROUPS
17843 : | HANDLER
17844 : | HEADER_P
17845 : | HOLD
17846 : | HOUR_P
17847 : | IDENTITY_P
17848 : | IF_P
17849 : | IMMEDIATE
17850 : | IMMUTABLE
17851 : | IMPLICIT_P
17852 : | IMPORT_P
17853 : | INCLUDE
17854 : | INCLUDING
17855 : | INCREMENT
17856 : | INDENT
17857 : | INDEX
17858 : | INDEXES
17859 : | INHERIT
17860 : | INHERITS
17861 : | INLINE_P
17862 : | INPUT_P
17863 : | INSENSITIVE
17864 : | INSERT
17865 : | INSTEAD
17866 : | INVOKER
17867 : | ISOLATION
17868 : | KEEP
17869 : | KEY
17870 : | KEYS
17871 : | LABEL
17872 : | LANGUAGE
17873 : | LARGE_P
17874 : | LAST_P
17875 : | LEAKPROOF
17876 : | LEVEL
17877 : | LISTEN
17878 : | LOAD
17879 : | LOCAL
17880 : | LOCATION
17881 : | LOCK_P
17882 : | LOCKED
17883 : | LOGGED
17884 : | MAPPING
17885 : | MATCH
17886 : | MATCHED
17887 : | MATERIALIZED
17888 : | MAXVALUE
17889 : | MERGE
17890 : | METHOD
17891 : | MINUTE_P
17892 : | MINVALUE
17893 : | MODE
17894 : | MONTH_P
17895 : | MOVE
17896 : | NAME_P
17897 : | NAMES
17898 : | NESTED
17899 : | NEW
17900 : | NEXT
17901 : | NFC
17902 : | NFD
17903 : | NFKC
17904 : | NFKD
17905 : | NO
17906 : | NORMALIZED
17907 : | NOTHING
17908 : | NOTIFY
17909 : | NOWAIT
17910 : | NULLS_P
17911 : | OBJECT_P
17912 : | OBJECTS_P
17913 : | OF
17914 : | OFF
17915 : | OIDS
17916 : | OLD
17917 : | OMIT
17918 : | OPERATOR
17919 : | OPTION
17920 : | OPTIONS
17921 : | ORDINALITY
17922 : | OTHERS
17923 : | OVER
17924 : | OVERRIDING
17925 : | OWNED
17926 : | OWNER
17927 : | PARALLEL
17928 : | PARAMETER
17929 : | PARSER
17930 : | PARTIAL
17931 : | PARTITION
17932 : | PASSING
17933 : | PASSWORD
17934 : | PATH
17935 : | PERIOD
17936 : | PLAN
17937 : | PLANS
17938 : | POLICY
17939 : | PRECEDING
17940 : | PREPARE
17941 : | PREPARED
17942 : | PRESERVE
17943 : | PRIOR
17944 : | PRIVILEGES
17945 : | PROCEDURAL
17946 : | PROCEDURE
17947 : | PROCEDURES
17948 : | PROGRAM
17949 : | PUBLICATION
17950 : | QUOTE
17951 : | QUOTES
17952 : | RANGE
17953 : | READ
17954 : | REASSIGN
17955 : | RECURSIVE
17956 : | REF_P
17957 : | REFERENCING
17958 : | REFRESH
17959 : | REINDEX
17960 : | RELATIVE_P
17961 : | RELEASE
17962 : | RENAME
17963 : | REPEATABLE
17964 : | REPLACE
17965 : | REPLICA
17966 : | RESET
17967 : | RESTART
17968 : | RESTRICT
17969 : | RETURN
17970 : | RETURNS
17971 : | REVOKE
17972 : | ROLE
17973 : | ROLLBACK
17974 : | ROLLUP
17975 : | ROUTINE
17976 : | ROUTINES
17977 : | ROWS
17978 : | RULE
17979 : | SAVEPOINT
17980 : | SCALAR
17981 : | SCHEMA
17982 : | SCHEMAS
17983 : | SCROLL
17984 : | SEARCH
17985 : | SECOND_P
17986 : | SECURITY
17987 : | SEQUENCE
17988 : | SEQUENCES
17989 : | SERIALIZABLE
17990 : | SERVER
17991 : | SESSION
17992 : | SET
17993 : | SETS
17994 : | SHARE
17995 : | SHOW
17996 : | SIMPLE
17997 : | SKIP
17998 : | SNAPSHOT
17999 : | SOURCE
18000 : | SQL_P
18001 : | STABLE
18002 : | STANDALONE_P
18003 : | START
18004 : | STATEMENT
18005 : | STATISTICS
18006 : | STDIN
18007 : | STDOUT
18008 : | STORAGE
18009 : | STORED
18010 : | STRICT_P
18011 : | STRING_P
18012 : | STRIP_P
18013 : | SUBSCRIPTION
18014 : | SUPPORT
18015 : | SYSID
18016 : | SYSTEM_P
18017 : | TABLES
18018 : | TABLESPACE
18019 : | TARGET
18020 : | TEMP
18021 : | TEMPLATE
18022 : | TEMPORARY
18023 : | TEXT_P
18024 : | TIES
18025 : | TRANSACTION
18026 : | TRANSFORM
18027 : | TRIGGER
18028 : | TRUNCATE
18029 : | TRUSTED
18030 : | TYPE_P
18031 : | TYPES_P
18032 : | UESCAPE
18033 : | UNBOUNDED
18034 : | UNCOMMITTED
18035 : | UNCONDITIONAL
18036 : | UNENCRYPTED
18037 : | UNKNOWN
18038 : | UNLISTEN
18039 : | UNLOGGED
18040 : | UNTIL
18041 : | UPDATE
18042 : | VACUUM
18043 : | VALID
18044 : | VALIDATE
18045 : | VALIDATOR
18046 : | VALUE_P
18047 : | VARYING
18048 : | VERSION_P
18049 : | VIEW
18050 : | VIEWS
18051 : | VIRTUAL
18052 : | VOLATILE
18053 : | WHITESPACE_P
18054 : | WITHIN
18055 : | WITHOUT
18056 : | WORK
18057 : | WRAPPER
18058 : | WRITE
18059 : | XML_P
18060 : | YEAR_P
18061 : | YES_P
18062 : | ZONE
18063 : ;
18064 :
18065 : /* Column identifier --- keywords that can be column, table, etc names.
18066 : *
18067 : * Many of these keywords will in fact be recognized as type or function
18068 : * names too; but they have special productions for the purpose, and so
18069 : * can't be treated as "generic" type or function names.
18070 : *
18071 : * The type names appearing here are not usable as function names
18072 : * because they can be followed by '(' in typename productions, which
18073 : * looks too much like a function call for an LR(1) parser.
18074 : */
18075 : col_name_keyword:
18076 : BETWEEN
18077 : | BIGINT
18078 : | BIT
18079 : | BOOLEAN_P
18080 : | CHAR_P
18081 : | CHARACTER
18082 : | COALESCE
18083 : | DEC
18084 : | DECIMAL_P
18085 : | EXISTS
18086 : | EXTRACT
18087 : | FLOAT_P
18088 : | GREATEST
18089 : | GROUPING
18090 : | INOUT
18091 : | INT_P
18092 : | INTEGER
18093 : | INTERVAL
18094 : | JSON
18095 : | JSON_ARRAY
18096 : | JSON_ARRAYAGG
18097 : | JSON_EXISTS
18098 : | JSON_OBJECT
18099 : | JSON_OBJECTAGG
18100 : | JSON_QUERY
18101 : | JSON_SCALAR
18102 : | JSON_SERIALIZE
18103 : | JSON_TABLE
18104 : | JSON_VALUE
18105 : | LEAST
18106 : | MERGE_ACTION
18107 : | NATIONAL
18108 : | NCHAR
18109 : | NONE
18110 : | NORMALIZE
18111 : | NULLIF
18112 : | NUMERIC
18113 : | OUT_P
18114 : | OVERLAY
18115 : | POSITION
18116 : | PRECISION
18117 : | REAL
18118 : | ROW
18119 : | SETOF
18120 : | SMALLINT
18121 : | SUBSTRING
18122 : | TIME
18123 : | TIMESTAMP
18124 : | TREAT
18125 : | TRIM
18126 : | VALUES
18127 : | VARCHAR
18128 : | XMLATTRIBUTES
18129 : | XMLCONCAT
18130 : | XMLELEMENT
18131 : | XMLEXISTS
18132 : | XMLFOREST
18133 : | XMLNAMESPACES
18134 : | XMLPARSE
18135 : | XMLPI
18136 : | XMLROOT
18137 : | XMLSERIALIZE
18138 : | XMLTABLE
18139 : ;
18140 :
18141 : /* Type/function identifier --- keywords that can be type or function names.
18142 : *
18143 : * Most of these are keywords that are used as operators in expressions;
18144 : * in general such keywords can't be column names because they would be
18145 : * ambiguous with variables, but they are unambiguous as function identifiers.
18146 : *
18147 : * Do not include POSITION, SUBSTRING, etc here since they have explicit
18148 : * productions in a_expr to support the goofy SQL9x argument syntax.
18149 : * - thomas 2000-11-28
18150 : */
18151 : type_func_name_keyword:
18152 : AUTHORIZATION
18153 : | BINARY
18154 : | COLLATION
18155 : | CONCURRENTLY
18156 : | CROSS
18157 : | CURRENT_SCHEMA
18158 : | FREEZE
18159 : | FULL
18160 : | ILIKE
18161 : | INNER_P
18162 : | IS
18163 : | ISNULL
18164 : | JOIN
18165 : | LEFT
18166 : | LIKE
18167 : | NATURAL
18168 : | NOTNULL
18169 : | OUTER_P
18170 : | OVERLAPS
18171 : | RIGHT
18172 : | SIMILAR
18173 : | TABLESAMPLE
18174 : | VERBOSE
18175 : ;
18176 :
18177 : /* Reserved keyword --- these keywords are usable only as a ColLabel.
18178 : *
18179 : * Keywords appear here if they could not be distinguished from variable,
18180 : * type, or function names in some contexts. Don't put things here unless
18181 : * forced to.
18182 : */
18183 : reserved_keyword:
18184 : ALL
18185 : | ANALYSE
18186 : | ANALYZE
18187 : | AND
18188 : | ANY
18189 : | ARRAY
18190 : | AS
18191 : | ASC
18192 : | ASYMMETRIC
18193 : | BOTH
18194 : | CASE
18195 : | CAST
18196 : | CHECK
18197 : | COLLATE
18198 : | COLUMN
18199 : | CONSTRAINT
18200 : | CREATE
18201 : | CURRENT_CATALOG
18202 : | CURRENT_DATE
18203 : | CURRENT_ROLE
18204 : | CURRENT_TIME
18205 : | CURRENT_TIMESTAMP
18206 : | CURRENT_USER
18207 : | DEFAULT
18208 : | DEFERRABLE
18209 : | DESC
18210 : | DISTINCT
18211 : | DO
18212 : | ELSE
18213 : | END_P
18214 : | EXCEPT
18215 : | FALSE_P
18216 : | FETCH
18217 : | FOR
18218 : | FOREIGN
18219 : | FROM
18220 : | GRANT
18221 : | GROUP_P
18222 : | HAVING
18223 : | IN_P
18224 : | INITIALLY
18225 : | INTERSECT
18226 : | INTO
18227 : | LATERAL_P
18228 : | LEADING
18229 : | LIMIT
18230 : | LOCALTIME
18231 : | LOCALTIMESTAMP
18232 : | NOT
18233 : | NULL_P
18234 : | OFFSET
18235 : | ON
18236 : | ONLY
18237 : | OR
18238 : | ORDER
18239 : | PLACING
18240 : | PRIMARY
18241 : | REFERENCES
18242 : | RETURNING
18243 : | SELECT
18244 : | SESSION_USER
18245 : | SOME
18246 : | SYMMETRIC
18247 : | SYSTEM_USER
18248 : | TABLE
18249 : | THEN
18250 : | TO
18251 : | TRAILING
18252 : | TRUE_P
18253 : | UNION
18254 : | UNIQUE
18255 : | USER
18256 : | USING
18257 : | VARIADIC
18258 : | WHEN
18259 : | WHERE
18260 : | WINDOW
18261 : | WITH
18262 : ;
18263 :
18264 : /*
18265 : * While all keywords can be used as column labels when preceded by AS,
18266 : * not all of them can be used as a "bare" column label without AS.
18267 : * Those that can be used as a bare label must be listed here,
18268 : * in addition to appearing in one of the category lists above.
18269 : *
18270 : * Always add a new keyword to this list if possible. Mark it BARE_LABEL
18271 : * in kwlist.h if it is included here, or AS_LABEL if it is not.
18272 : */
18273 : bare_label_keyword:
18274 : ABORT_P
18275 : | ABSENT
18276 : | ABSOLUTE_P
18277 : | ACCESS
18278 : | ACTION
18279 : | ADD_P
18280 : | ADMIN
18281 : | AFTER
18282 : | AGGREGATE
18283 : | ALL
18284 : | ALSO
18285 : | ALTER
18286 : | ALWAYS
18287 : | ANALYSE
18288 : | ANALYZE
18289 : | AND
18290 : | ANY
18291 : | ASC
18292 : | ASENSITIVE
18293 : | ASSERTION
18294 : | ASSIGNMENT
18295 : | ASYMMETRIC
18296 : | AT
18297 : | ATOMIC
18298 : | ATTACH
18299 : | ATTRIBUTE
18300 : | AUTHORIZATION
18301 : | BACKWARD
18302 : | BEFORE
18303 : | BEGIN_P
18304 : | BETWEEN
18305 : | BIGINT
18306 : | BINARY
18307 : | BIT
18308 : | BOOLEAN_P
18309 : | BOTH
18310 : | BREADTH
18311 : | BY
18312 : | CACHE
18313 : | CALL
18314 : | CALLED
18315 : | CASCADE
18316 : | CASCADED
18317 : | CASE
18318 : | CAST
18319 : | CATALOG_P
18320 : | CHAIN
18321 : | CHARACTERISTICS
18322 : | CHECK
18323 : | CHECKPOINT
18324 : | CLASS
18325 : | CLOSE
18326 : | CLUSTER
18327 : | COALESCE
18328 : | COLLATE
18329 : | COLLATION
18330 : | COLUMN
18331 : | COLUMNS
18332 : | COMMENT
18333 : | COMMENTS
18334 : | COMMIT
18335 : | COMMITTED
18336 : | COMPRESSION
18337 : | CONCURRENTLY
18338 : | CONDITIONAL
18339 : | CONFIGURATION
18340 : | CONFLICT
18341 : | CONNECTION
18342 : | CONSTRAINT
18343 : | CONSTRAINTS
18344 : | CONTENT_P
18345 : | CONTINUE_P
18346 : | CONVERSION_P
18347 : | COPY
18348 : | COST
18349 : | CROSS
18350 : | CSV
18351 : | CUBE
18352 : | CURRENT_P
18353 : | CURRENT_CATALOG
18354 : | CURRENT_DATE
18355 : | CURRENT_ROLE
18356 : | CURRENT_SCHEMA
18357 : | CURRENT_TIME
18358 : | CURRENT_TIMESTAMP
18359 : | CURRENT_USER
18360 : | CURSOR
18361 : | CYCLE
18362 : | DATA_P
18363 : | DATABASE
18364 : | DEALLOCATE
18365 : | DEC
18366 : | DECIMAL_P
18367 : | DECLARE
18368 : | DEFAULT
18369 : | DEFAULTS
18370 : | DEFERRABLE
18371 : | DEFERRED
18372 : | DEFINER
18373 : | DELETE_P
18374 : | DELIMITER
18375 : | DELIMITERS
18376 : | DEPENDS
18377 : | DEPTH
18378 : | DESC
18379 : | DETACH
18380 : | DICTIONARY
18381 : | DISABLE_P
18382 : | DISCARD
18383 : | DISTINCT
18384 : | DO
18385 : | DOCUMENT_P
18386 : | DOMAIN_P
18387 : | DOUBLE_P
18388 : | DROP
18389 : | EACH
18390 : | ELSE
18391 : | EMPTY_P
18392 : | ENABLE_P
18393 : | ENCODING
18394 : | ENCRYPTED
18395 : | END_P
18396 : | ENFORCED
18397 : | ENUM_P
18398 : | ERROR_P
18399 : | ESCAPE
18400 : | EVENT
18401 : | EXCLUDE
18402 : | EXCLUDING
18403 : | EXCLUSIVE
18404 : | EXECUTE
18405 : | EXISTS
18406 : | EXPLAIN
18407 : | EXPRESSION
18408 : | EXTENSION
18409 : | EXTERNAL
18410 : | EXTRACT
18411 : | FALSE_P
18412 : | FAMILY
18413 : | FINALIZE
18414 : | FIRST_P
18415 : | FLOAT_P
18416 : | FOLLOWING
18417 : | FORCE
18418 : | FOREIGN
18419 : | FORMAT
18420 : | FORWARD
18421 : | FREEZE
18422 : | FULL
18423 : | FUNCTION
18424 : | FUNCTIONS
18425 : | GENERATED
18426 : | GLOBAL
18427 : | GRANTED
18428 : | GREATEST
18429 : | GROUPING
18430 : | GROUPS
18431 : | HANDLER
18432 : | HEADER_P
18433 : | HOLD
18434 : | IDENTITY_P
18435 : | IF_P
18436 : | ILIKE
18437 : | IMMEDIATE
18438 : | IMMUTABLE
18439 : | IMPLICIT_P
18440 : | IMPORT_P
18441 : | IN_P
18442 : | INCLUDE
18443 : | INCLUDING
18444 : | INCREMENT
18445 : | INDENT
18446 : | INDEX
18447 : | INDEXES
18448 : | INHERIT
18449 : | INHERITS
18450 : | INITIALLY
18451 : | INLINE_P
18452 : | INNER_P
18453 : | INOUT
18454 : | INPUT_P
18455 : | INSENSITIVE
18456 : | INSERT
18457 : | INSTEAD
18458 : | INT_P
18459 : | INTEGER
18460 : | INTERVAL
18461 : | INVOKER
18462 : | IS
18463 : | ISOLATION
18464 : | JOIN
18465 : | JSON
18466 : | JSON_ARRAY
18467 : | JSON_ARRAYAGG
18468 : | JSON_EXISTS
18469 : | JSON_OBJECT
18470 : | JSON_OBJECTAGG
18471 : | JSON_QUERY
18472 : | JSON_SCALAR
18473 : | JSON_SERIALIZE
18474 : | JSON_TABLE
18475 : | JSON_VALUE
18476 : | KEEP
18477 : | KEY
18478 : | KEYS
18479 : | LABEL
18480 : | LANGUAGE
18481 : | LARGE_P
18482 : | LAST_P
18483 : | LATERAL_P
18484 : | LEADING
18485 : | LEAKPROOF
18486 : | LEAST
18487 : | LEFT
18488 : | LEVEL
18489 : | LIKE
18490 : | LISTEN
18491 : | LOAD
18492 : | LOCAL
18493 : | LOCALTIME
18494 : | LOCALTIMESTAMP
18495 : | LOCATION
18496 : | LOCK_P
18497 : | LOCKED
18498 : | LOGGED
18499 : | MAPPING
18500 : | MATCH
18501 : | MATCHED
18502 : | MATERIALIZED
18503 : | MAXVALUE
18504 : | MERGE
18505 : | MERGE_ACTION
18506 : | METHOD
18507 : | MINVALUE
18508 : | MODE
18509 : | MOVE
18510 : | NAME_P
18511 : | NAMES
18512 : | NATIONAL
18513 : | NATURAL
18514 : | NCHAR
18515 : | NESTED
18516 : | NEW
18517 : | NEXT
18518 : | NFC
18519 : | NFD
18520 : | NFKC
18521 : | NFKD
18522 : | NO
18523 : | NONE
18524 : | NORMALIZE
18525 : | NORMALIZED
18526 : | NOT
18527 : | NOTHING
18528 : | NOTIFY
18529 : | NOWAIT
18530 : | NULL_P
18531 : | NULLIF
18532 : | NULLS_P
18533 : | NUMERIC
18534 : | OBJECT_P
18535 : | OBJECTS_P
18536 : | OF
18537 : | OFF
18538 : | OIDS
18539 : | OLD
18540 : | OMIT
18541 : | ONLY
18542 : | OPERATOR
18543 : | OPTION
18544 : | OPTIONS
18545 : | OR
18546 : | ORDINALITY
18547 : | OTHERS
18548 : | OUT_P
18549 : | OUTER_P
18550 : | OVERLAY
18551 : | OVERRIDING
18552 : | OWNED
18553 : | OWNER
18554 : | PARALLEL
18555 : | PARAMETER
18556 : | PARSER
18557 : | PARTIAL
18558 : | PARTITION
18559 : | PASSING
18560 : | PASSWORD
18561 : | PATH
18562 : | PERIOD
18563 : | PLACING
18564 : | PLAN
18565 : | PLANS
18566 : | POLICY
18567 : | POSITION
18568 : | PRECEDING
18569 : | PREPARE
18570 : | PREPARED
18571 : | PRESERVE
18572 : | PRIMARY
18573 : | PRIOR
18574 : | PRIVILEGES
18575 : | PROCEDURAL
18576 : | PROCEDURE
18577 : | PROCEDURES
18578 : | PROGRAM
18579 : | PUBLICATION
18580 : | QUOTE
18581 : | QUOTES
18582 : | RANGE
18583 : | READ
18584 : | REAL
18585 : | REASSIGN
18586 : | RECURSIVE
18587 : | REF_P
18588 : | REFERENCES
18589 : | REFERENCING
18590 : | REFRESH
18591 : | REINDEX
18592 : | RELATIVE_P
18593 : | RELEASE
18594 : | RENAME
18595 : | REPEATABLE
18596 : | REPLACE
18597 : | REPLICA
18598 : | RESET
18599 : | RESTART
18600 : | RESTRICT
18601 : | RETURN
18602 : | RETURNS
18603 : | REVOKE
18604 : | RIGHT
18605 : | ROLE
18606 : | ROLLBACK
18607 : | ROLLUP
18608 : | ROUTINE
18609 : | ROUTINES
18610 : | ROW
18611 : | ROWS
18612 : | RULE
18613 : | SAVEPOINT
18614 : | SCALAR
18615 : | SCHEMA
18616 : | SCHEMAS
18617 : | SCROLL
18618 : | SEARCH
18619 : | SECURITY
18620 : | SELECT
18621 : | SEQUENCE
18622 : | SEQUENCES
18623 : | SERIALIZABLE
18624 : | SERVER
18625 : | SESSION
18626 : | SESSION_USER
18627 : | SET
18628 : | SETOF
18629 : | SETS
18630 : | SHARE
18631 : | SHOW
18632 : | SIMILAR
18633 : | SIMPLE
18634 : | SKIP
18635 : | SMALLINT
18636 : | SNAPSHOT
18637 : | SOME
18638 : | SOURCE
18639 : | SQL_P
18640 : | STABLE
18641 : | STANDALONE_P
18642 : | START
18643 : | STATEMENT
18644 : | STATISTICS
18645 : | STDIN
18646 : | STDOUT
18647 : | STORAGE
18648 : | STORED
18649 : | STRICT_P
18650 : | STRING_P
18651 : | STRIP_P
18652 : | SUBSCRIPTION
18653 : | SUBSTRING
18654 : | SUPPORT
18655 : | SYMMETRIC
18656 : | SYSID
18657 : | SYSTEM_P
18658 : | SYSTEM_USER
18659 : | TABLE
18660 : | TABLES
18661 : | TABLESAMPLE
18662 : | TABLESPACE
18663 : | TARGET
18664 : | TEMP
18665 : | TEMPLATE
18666 : | TEMPORARY
18667 : | TEXT_P
18668 : | THEN
18669 : | TIES
18670 : | TIME
18671 : | TIMESTAMP
18672 : | TRAILING
18673 : | TRANSACTION
18674 : | TRANSFORM
18675 : | TREAT
18676 : | TRIGGER
18677 : | TRIM
18678 : | TRUE_P
18679 : | TRUNCATE
18680 : | TRUSTED
18681 : | TYPE_P
18682 : | TYPES_P
18683 : | UESCAPE
18684 : | UNBOUNDED
18685 : | UNCOMMITTED
18686 : | UNCONDITIONAL
18687 : | UNENCRYPTED
18688 : | UNIQUE
18689 : | UNKNOWN
18690 : | UNLISTEN
18691 : | UNLOGGED
18692 : | UNTIL
18693 : | UPDATE
18694 : | USER
18695 : | USING
18696 : | VACUUM
18697 : | VALID
18698 : | VALIDATE
18699 : | VALIDATOR
18700 : | VALUE_P
18701 : | VALUES
18702 : | VARCHAR
18703 : | VARIADIC
18704 : | VERBOSE
18705 : | VERSION_P
18706 : | VIEW
18707 : | VIEWS
18708 : | VIRTUAL
18709 : | VOLATILE
18710 : | WHEN
18711 : | WHITESPACE_P
18712 : | WORK
18713 : | WRAPPER
18714 : | WRITE
18715 : | XML_P
18716 : | XMLATTRIBUTES
18717 : | XMLCONCAT
18718 : | XMLELEMENT
18719 : | XMLEXISTS
18720 : | XMLFOREST
18721 : | XMLNAMESPACES
18722 : | XMLPARSE
18723 : | XMLPI
18724 : | XMLROOT
18725 : | XMLSERIALIZE
18726 : | XMLTABLE
18727 : | YES_P
18728 : | ZONE
18729 : ;
18730 :
18731 : %%
18732 :
18733 : /*
18734 : * The signature of this function is required by bison. However, we
18735 : * ignore the passed yylloc and instead use the last token position
18736 : * available from the scanner.
18737 : */
18738 : static void
18739 696 : base_yyerror(YYLTYPE *yylloc, core_yyscan_t yyscanner, const char *msg)
18740 : {
18741 696 : parser_yyerror(msg);
18742 : }
18743 :
18744 : static RawStmt *
18745 806450 : makeRawStmt(Node *stmt, int stmt_location)
18746 : {
18747 806450 : RawStmt *rs = makeNode(RawStmt);
18748 :
18749 806450 : rs->stmt = stmt;
18750 806450 : rs->stmt_location = stmt_location;
18751 806450 : rs->stmt_len = 0; /* might get changed later */
18752 806450 : return rs;
18753 : }
18754 :
18755 : /* Adjust a RawStmt to reflect that it doesn't run to the end of the string */
18756 : static void
18757 578160 : updateRawStmtEnd(RawStmt *rs, int end_location)
18758 : {
18759 : /*
18760 : * If we already set the length, don't change it. This is for situations
18761 : * like "select foo ;; select bar" where the same statement will be last
18762 : * in the string for more than one semicolon.
18763 : */
18764 578160 : if (rs->stmt_len > 0)
18765 642 : return;
18766 :
18767 : /* OK, update length of RawStmt */
18768 577518 : rs->stmt_len = end_location - rs->stmt_location;
18769 : }
18770 :
18771 : static Node *
18772 1794358 : makeColumnRef(char *colname, List *indirection,
18773 : int location, core_yyscan_t yyscanner)
18774 : {
18775 : /*
18776 : * Generate a ColumnRef node, with an A_Indirection node added if there is
18777 : * any subscripting in the specified indirection list. However, any field
18778 : * selection at the start of the indirection list must be transposed into
18779 : * the "fields" part of the ColumnRef node.
18780 : */
18781 1794358 : ColumnRef *c = makeNode(ColumnRef);
18782 1794358 : int nfields = 0;
18783 : ListCell *l;
18784 :
18785 1794358 : c->location = location;
18786 2839700 : foreach(l, indirection)
18787 : {
18788 1055232 : if (IsA(lfirst(l), A_Indices))
18789 : {
18790 9890 : A_Indirection *i = makeNode(A_Indirection);
18791 :
18792 9890 : if (nfields == 0)
18793 : {
18794 : /* easy case - all indirection goes to A_Indirection */
18795 7176 : c->fields = list_make1(makeString(colname));
18796 7176 : i->indirection = check_indirection(indirection, yyscanner);
18797 : }
18798 : else
18799 : {
18800 : /* got to split the list in two */
18801 2714 : i->indirection = check_indirection(list_copy_tail(indirection,
18802 : nfields),
18803 : yyscanner);
18804 2714 : indirection = list_truncate(indirection, nfields);
18805 2714 : c->fields = lcons(makeString(colname), indirection);
18806 : }
18807 9890 : i->arg = (Node *) c;
18808 9890 : return (Node *) i;
18809 : }
18810 1045342 : else if (IsA(lfirst(l), A_Star))
18811 : {
18812 : /* We only allow '*' at the end of a ColumnRef */
18813 5512 : if (lnext(indirection, l) != NULL)
18814 0 : parser_yyerror("improper use of \"*\"");
18815 : }
18816 1045342 : nfields++;
18817 : }
18818 : /* No subscripting, so all indirection gets added to field list */
18819 1784468 : c->fields = lcons(makeString(colname), indirection);
18820 1784468 : return (Node *) c;
18821 : }
18822 :
18823 : static Node *
18824 312894 : makeTypeCast(Node *arg, TypeName *typename, int location)
18825 : {
18826 312894 : TypeCast *n = makeNode(TypeCast);
18827 :
18828 312894 : n->arg = arg;
18829 312894 : n->typeName = typename;
18830 312894 : n->location = location;
18831 312894 : return (Node *) n;
18832 : }
18833 :
18834 : static Node *
18835 16320 : makeStringConstCast(char *str, int location, TypeName *typename)
18836 : {
18837 16320 : Node *s = makeStringConst(str, location);
18838 :
18839 16320 : return makeTypeCast(s, typename, -1);
18840 : }
18841 :
18842 : static Node *
18843 383976 : makeIntConst(int val, int location)
18844 : {
18845 383976 : A_Const *n = makeNode(A_Const);
18846 :
18847 383976 : n->val.ival.type = T_Integer;
18848 383976 : n->val.ival.ival = val;
18849 383976 : n->location = location;
18850 :
18851 383976 : return (Node *) n;
18852 : }
18853 :
18854 : static Node *
18855 11618 : makeFloatConst(char *str, int location)
18856 : {
18857 11618 : A_Const *n = makeNode(A_Const);
18858 :
18859 11618 : n->val.fval.type = T_Float;
18860 11618 : n->val.fval.fval = str;
18861 11618 : n->location = location;
18862 :
18863 11618 : return (Node *) n;
18864 : }
18865 :
18866 : static Node *
18867 67016 : makeBoolAConst(bool state, int location)
18868 : {
18869 67016 : A_Const *n = makeNode(A_Const);
18870 :
18871 67016 : n->val.boolval.type = T_Boolean;
18872 67016 : n->val.boolval.boolval = state;
18873 67016 : n->location = location;
18874 :
18875 67016 : return (Node *) n;
18876 : }
18877 :
18878 : static Node *
18879 4056 : makeBitStringConst(char *str, int location)
18880 : {
18881 4056 : A_Const *n = makeNode(A_Const);
18882 :
18883 4056 : n->val.bsval.type = T_BitString;
18884 4056 : n->val.bsval.bsval = str;
18885 4056 : n->location = location;
18886 :
18887 4056 : return (Node *) n;
18888 : }
18889 :
18890 : static Node *
18891 66912 : makeNullAConst(int location)
18892 : {
18893 66912 : A_Const *n = makeNode(A_Const);
18894 :
18895 66912 : n->isnull = true;
18896 66912 : n->location = location;
18897 :
18898 66912 : return (Node *) n;
18899 : }
18900 :
18901 : static Node *
18902 5226 : makeAConst(Node *v, int location)
18903 : {
18904 : Node *n;
18905 :
18906 5226 : switch (v->type)
18907 : {
18908 218 : case T_Float:
18909 218 : n = makeFloatConst(castNode(Float, v)->fval, location);
18910 218 : break;
18911 :
18912 5008 : case T_Integer:
18913 5008 : n = makeIntConst(castNode(Integer, v)->ival, location);
18914 5008 : break;
18915 :
18916 0 : default:
18917 : /* currently not used */
18918 : Assert(false);
18919 0 : n = NULL;
18920 : }
18921 :
18922 5226 : return n;
18923 : }
18924 :
18925 : /* makeRoleSpec
18926 : * Create a RoleSpec with the given type
18927 : */
18928 : static RoleSpec *
18929 33264 : makeRoleSpec(RoleSpecType type, int location)
18930 : {
18931 33264 : RoleSpec *spec = makeNode(RoleSpec);
18932 :
18933 33264 : spec->roletype = type;
18934 33264 : spec->location = location;
18935 :
18936 33264 : return spec;
18937 : }
18938 :
18939 : /* check_qualified_name --- check the result of qualified_name production
18940 : *
18941 : * It's easiest to let the grammar production for qualified_name allow
18942 : * subscripts and '*', which we then must reject here.
18943 : */
18944 : static void
18945 243380 : check_qualified_name(List *names, core_yyscan_t yyscanner)
18946 : {
18947 : ListCell *i;
18948 :
18949 486760 : foreach(i, names)
18950 : {
18951 243380 : if (!IsA(lfirst(i), String))
18952 0 : parser_yyerror("syntax error");
18953 : }
18954 243380 : }
18955 :
18956 : /* check_func_name --- check the result of func_name production
18957 : *
18958 : * It's easiest to let the grammar production for func_name allow subscripts
18959 : * and '*', which we then must reject here.
18960 : */
18961 : static List *
18962 125970 : check_func_name(List *names, core_yyscan_t yyscanner)
18963 : {
18964 : ListCell *i;
18965 :
18966 377910 : foreach(i, names)
18967 : {
18968 251940 : if (!IsA(lfirst(i), String))
18969 0 : parser_yyerror("syntax error");
18970 : }
18971 125970 : return names;
18972 : }
18973 :
18974 : /* check_indirection --- check the result of indirection production
18975 : *
18976 : * We only allow '*' at the end of the list, but it's hard to enforce that
18977 : * in the grammar, so do it here.
18978 : */
18979 : static List *
18980 82462 : check_indirection(List *indirection, core_yyscan_t yyscanner)
18981 : {
18982 : ListCell *l;
18983 :
18984 110050 : foreach(l, indirection)
18985 : {
18986 27588 : if (IsA(lfirst(l), A_Star))
18987 : {
18988 1458 : if (lnext(indirection, l) != NULL)
18989 0 : parser_yyerror("improper use of \"*\"");
18990 : }
18991 : }
18992 82462 : return indirection;
18993 : }
18994 :
18995 : /* extractArgTypes()
18996 : * Given a list of FunctionParameter nodes, extract a list of just the
18997 : * argument types (TypeNames) for input parameters only. This is what
18998 : * is needed to look up an existing function, which is what is wanted by
18999 : * the productions that use this call.
19000 : */
19001 : static List *
19002 18328 : extractArgTypes(List *parameters)
19003 : {
19004 18328 : List *result = NIL;
19005 : ListCell *i;
19006 :
19007 42010 : foreach(i, parameters)
19008 : {
19009 23682 : FunctionParameter *p = (FunctionParameter *) lfirst(i);
19010 :
19011 23682 : if (p->mode != FUNC_PARAM_OUT && p->mode != FUNC_PARAM_TABLE)
19012 23526 : result = lappend(result, p->argType);
19013 : }
19014 18328 : return result;
19015 : }
19016 :
19017 : /* extractAggrArgTypes()
19018 : * As above, but work from the output of the aggr_args production.
19019 : */
19020 : static List *
19021 362 : extractAggrArgTypes(List *aggrargs)
19022 : {
19023 : Assert(list_length(aggrargs) == 2);
19024 362 : return extractArgTypes((List *) linitial(aggrargs));
19025 : }
19026 :
19027 : /* makeOrderedSetArgs()
19028 : * Build the result of the aggr_args production (which see the comments for).
19029 : * This handles only the case where both given lists are nonempty, so that
19030 : * we have to deal with multiple VARIADIC arguments.
19031 : */
19032 : static List *
19033 32 : makeOrderedSetArgs(List *directargs, List *orderedargs,
19034 : core_yyscan_t yyscanner)
19035 : {
19036 32 : FunctionParameter *lastd = (FunctionParameter *) llast(directargs);
19037 : Integer *ndirectargs;
19038 :
19039 : /* No restriction unless last direct arg is VARIADIC */
19040 32 : if (lastd->mode == FUNC_PARAM_VARIADIC)
19041 : {
19042 16 : FunctionParameter *firsto = (FunctionParameter *) linitial(orderedargs);
19043 :
19044 : /*
19045 : * We ignore the names, though the aggr_arg production allows them; it
19046 : * doesn't allow default values, so those need not be checked.
19047 : */
19048 16 : if (list_length(orderedargs) != 1 ||
19049 16 : firsto->mode != FUNC_PARAM_VARIADIC ||
19050 16 : !equal(lastd->argType, firsto->argType))
19051 0 : ereport(ERROR,
19052 : (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
19053 : errmsg("an ordered-set aggregate with a VARIADIC direct argument must have one VARIADIC aggregated argument of the same data type"),
19054 : parser_errposition(firsto->location)));
19055 :
19056 : /* OK, drop the duplicate VARIADIC argument from the internal form */
19057 16 : orderedargs = NIL;
19058 : }
19059 :
19060 : /* don't merge into the next line, as list_concat changes directargs */
19061 32 : ndirectargs = makeInteger(list_length(directargs));
19062 :
19063 32 : return list_make2(list_concat(directargs, orderedargs),
19064 : ndirectargs);
19065 : }
19066 :
19067 : /* insertSelectOptions()
19068 : * Insert ORDER BY, etc into an already-constructed SelectStmt.
19069 : *
19070 : * This routine is just to avoid duplicating code in SelectStmt productions.
19071 : */
19072 : static void
19073 82862 : insertSelectOptions(SelectStmt *stmt,
19074 : List *sortClause, List *lockingClause,
19075 : SelectLimit *limitClause,
19076 : WithClause *withClause,
19077 : core_yyscan_t yyscanner)
19078 : {
19079 : Assert(IsA(stmt, SelectStmt));
19080 :
19081 : /*
19082 : * Tests here are to reject constructs like
19083 : * (SELECT foo ORDER BY bar) ORDER BY baz
19084 : */
19085 82862 : if (sortClause)
19086 : {
19087 73496 : if (stmt->sortClause)
19088 0 : ereport(ERROR,
19089 : (errcode(ERRCODE_SYNTAX_ERROR),
19090 : errmsg("multiple ORDER BY clauses not allowed"),
19091 : parser_errposition(exprLocation((Node *) sortClause))));
19092 73496 : stmt->sortClause = sortClause;
19093 : }
19094 : /* We can handle multiple locking clauses, though */
19095 82862 : stmt->lockingClause = list_concat(stmt->lockingClause, lockingClause);
19096 82862 : if (limitClause && limitClause->limitOffset)
19097 : {
19098 844 : if (stmt->limitOffset)
19099 0 : ereport(ERROR,
19100 : (errcode(ERRCODE_SYNTAX_ERROR),
19101 : errmsg("multiple OFFSET clauses not allowed"),
19102 : parser_errposition(limitClause->offsetLoc)));
19103 844 : stmt->limitOffset = limitClause->limitOffset;
19104 : }
19105 82862 : if (limitClause && limitClause->limitCount)
19106 : {
19107 4702 : if (stmt->limitCount)
19108 0 : ereport(ERROR,
19109 : (errcode(ERRCODE_SYNTAX_ERROR),
19110 : errmsg("multiple LIMIT clauses not allowed"),
19111 : parser_errposition(limitClause->countLoc)));
19112 4702 : stmt->limitCount = limitClause->limitCount;
19113 : }
19114 82862 : if (limitClause)
19115 : {
19116 : /* If there was a conflict, we must have detected it above */
19117 : Assert(!stmt->limitOption);
19118 5152 : if (!stmt->sortClause && limitClause->limitOption == LIMIT_OPTION_WITH_TIES)
19119 6 : ereport(ERROR,
19120 : (errcode(ERRCODE_SYNTAX_ERROR),
19121 : errmsg("WITH TIES cannot be specified without ORDER BY clause"),
19122 : parser_errposition(limitClause->optionLoc)));
19123 5146 : if (limitClause->limitOption == LIMIT_OPTION_WITH_TIES && stmt->lockingClause)
19124 : {
19125 : ListCell *lc;
19126 :
19127 6 : foreach(lc, stmt->lockingClause)
19128 : {
19129 6 : LockingClause *lock = lfirst_node(LockingClause, lc);
19130 :
19131 6 : if (lock->waitPolicy == LockWaitSkip)
19132 6 : ereport(ERROR,
19133 : (errcode(ERRCODE_SYNTAX_ERROR),
19134 : errmsg("%s and %s options cannot be used together",
19135 : "SKIP LOCKED", "WITH TIES"),
19136 : parser_errposition(limitClause->optionLoc)));
19137 : }
19138 : }
19139 5140 : stmt->limitOption = limitClause->limitOption;
19140 : }
19141 82850 : if (withClause)
19142 : {
19143 2856 : if (stmt->withClause)
19144 0 : ereport(ERROR,
19145 : (errcode(ERRCODE_SYNTAX_ERROR),
19146 : errmsg("multiple WITH clauses not allowed"),
19147 : parser_errposition(exprLocation((Node *) withClause))));
19148 2856 : stmt->withClause = withClause;
19149 : }
19150 82850 : }
19151 :
19152 : static Node *
19153 19292 : makeSetOp(SetOperation op, bool all, Node *larg, Node *rarg)
19154 : {
19155 19292 : SelectStmt *n = makeNode(SelectStmt);
19156 :
19157 19292 : n->op = op;
19158 19292 : n->all = all;
19159 19292 : n->larg = (SelectStmt *) larg;
19160 19292 : n->rarg = (SelectStmt *) rarg;
19161 19292 : return (Node *) n;
19162 : }
19163 :
19164 : /* SystemFuncName()
19165 : * Build a properly-qualified reference to a built-in function.
19166 : */
19167 : List *
19168 19144 : SystemFuncName(char *name)
19169 : {
19170 19144 : return list_make2(makeString("pg_catalog"), makeString(name));
19171 : }
19172 :
19173 : /* SystemTypeName()
19174 : * Build a properly-qualified reference to a built-in type.
19175 : *
19176 : * typmod is defaulted, but may be changed afterwards by caller.
19177 : * Likewise for the location.
19178 : */
19179 : TypeName *
19180 120522 : SystemTypeName(char *name)
19181 : {
19182 120522 : return makeTypeNameFromNameList(list_make2(makeString("pg_catalog"),
19183 : makeString(name)));
19184 : }
19185 :
19186 : /* doNegate()
19187 : * Handle negation of a numeric constant.
19188 : *
19189 : * Formerly, we did this here because the optimizer couldn't cope with
19190 : * indexquals that looked like "var = -4" --- it wants "var = const"
19191 : * and a unary minus operator applied to a constant didn't qualify.
19192 : * As of Postgres 7.0, that problem doesn't exist anymore because there
19193 : * is a constant-subexpression simplifier in the optimizer. However,
19194 : * there's still a good reason for doing this here, which is that we can
19195 : * postpone committing to a particular internal representation for simple
19196 : * negative constants. It's better to leave "-123.456" in string form
19197 : * until we know what the desired type is.
19198 : */
19199 : static Node *
19200 9220 : doNegate(Node *n, int location)
19201 : {
19202 9220 : if (IsA(n, A_Const))
19203 : {
19204 8210 : A_Const *con = (A_Const *) n;
19205 :
19206 : /* report the constant's location as that of the '-' sign */
19207 8210 : con->location = location;
19208 :
19209 8210 : if (IsA(&con->val, Integer))
19210 : {
19211 7252 : con->val.ival.ival = -con->val.ival.ival;
19212 7252 : return n;
19213 : }
19214 958 : if (IsA(&con->val, Float))
19215 : {
19216 958 : doNegateFloat(&con->val.fval);
19217 958 : return n;
19218 : }
19219 : }
19220 :
19221 1010 : return (Node *) makeSimpleA_Expr(AEXPR_OP, "-", NULL, n, location);
19222 : }
19223 :
19224 : static void
19225 978 : doNegateFloat(Float *v)
19226 : {
19227 978 : char *oldval = v->fval;
19228 :
19229 978 : if (*oldval == '+')
19230 0 : oldval++;
19231 978 : if (*oldval == '-')
19232 0 : v->fval = oldval + 1; /* just strip the '-' */
19233 : else
19234 978 : v->fval = psprintf("-%s", oldval);
19235 978 : }
19236 :
19237 : static Node *
19238 231614 : makeAndExpr(Node *lexpr, Node *rexpr, int location)
19239 : {
19240 : /* Flatten "a AND b AND c ..." to a single BoolExpr on sight */
19241 231614 : if (IsA(lexpr, BoolExpr))
19242 : {
19243 110200 : BoolExpr *blexpr = (BoolExpr *) lexpr;
19244 :
19245 110200 : if (blexpr->boolop == AND_EXPR)
19246 : {
19247 107686 : blexpr->args = lappend(blexpr->args, rexpr);
19248 107686 : return (Node *) blexpr;
19249 : }
19250 : }
19251 123928 : return (Node *) makeBoolExpr(AND_EXPR, list_make2(lexpr, rexpr), location);
19252 : }
19253 :
19254 : static Node *
19255 15958 : makeOrExpr(Node *lexpr, Node *rexpr, int location)
19256 : {
19257 : /* Flatten "a OR b OR c ..." to a single BoolExpr on sight */
19258 15958 : if (IsA(lexpr, BoolExpr))
19259 : {
19260 5620 : BoolExpr *blexpr = (BoolExpr *) lexpr;
19261 :
19262 5620 : if (blexpr->boolop == OR_EXPR)
19263 : {
19264 4116 : blexpr->args = lappend(blexpr->args, rexpr);
19265 4116 : return (Node *) blexpr;
19266 : }
19267 : }
19268 11842 : return (Node *) makeBoolExpr(OR_EXPR, list_make2(lexpr, rexpr), location);
19269 : }
19270 :
19271 : static Node *
19272 16182 : makeNotExpr(Node *expr, int location)
19273 : {
19274 16182 : return (Node *) makeBoolExpr(NOT_EXPR, list_make1(expr), location);
19275 : }
19276 :
19277 : static Node *
19278 8128 : makeAArrayExpr(List *elements, int location, int location_end)
19279 : {
19280 8128 : A_ArrayExpr *n = makeNode(A_ArrayExpr);
19281 :
19282 8128 : n->elements = elements;
19283 8128 : n->location = location;
19284 8128 : n->list_start = location;
19285 8128 : n->list_end = location_end;
19286 8128 : return (Node *) n;
19287 : }
19288 :
19289 : static Node *
19290 2760 : makeSQLValueFunction(SQLValueFunctionOp op, int32 typmod, int location)
19291 : {
19292 2760 : SQLValueFunction *svf = makeNode(SQLValueFunction);
19293 :
19294 2760 : svf->op = op;
19295 : /* svf->type will be filled during parse analysis */
19296 2760 : svf->typmod = typmod;
19297 2760 : svf->location = location;
19298 2760 : return (Node *) svf;
19299 : }
19300 :
19301 : static Node *
19302 596 : makeXmlExpr(XmlExprOp op, char *name, List *named_args, List *args,
19303 : int location)
19304 : {
19305 596 : XmlExpr *x = makeNode(XmlExpr);
19306 :
19307 596 : x->op = op;
19308 596 : x->name = name;
19309 :
19310 : /*
19311 : * named_args is a list of ResTarget; it'll be split apart into separate
19312 : * expression and name lists in transformXmlExpr().
19313 : */
19314 596 : x->named_args = named_args;
19315 596 : x->arg_names = NIL;
19316 596 : x->args = args;
19317 : /* xmloption, if relevant, must be filled in by caller */
19318 : /* type and typmod will be filled in during parse analysis */
19319 596 : x->type = InvalidOid; /* marks the node as not analyzed */
19320 596 : x->location = location;
19321 596 : return (Node *) x;
19322 : }
19323 :
19324 : /*
19325 : * Merge the input and output parameters of a table function.
19326 : */
19327 : static List *
19328 188 : mergeTableFuncParameters(List *func_args, List *columns, core_yyscan_t yyscanner)
19329 : {
19330 : ListCell *lc;
19331 :
19332 : /* Explicit OUT and INOUT parameters shouldn't be used in this syntax */
19333 382 : foreach(lc, func_args)
19334 : {
19335 194 : FunctionParameter *p = (FunctionParameter *) lfirst(lc);
19336 :
19337 194 : if (p->mode != FUNC_PARAM_DEFAULT &&
19338 0 : p->mode != FUNC_PARAM_IN &&
19339 0 : p->mode != FUNC_PARAM_VARIADIC)
19340 0 : ereport(ERROR,
19341 : (errcode(ERRCODE_SYNTAX_ERROR),
19342 : errmsg("OUT and INOUT arguments aren't allowed in TABLE functions"),
19343 : parser_errposition(p->location)));
19344 : }
19345 :
19346 188 : return list_concat(func_args, columns);
19347 : }
19348 :
19349 : /*
19350 : * Determine return type of a TABLE function. A single result column
19351 : * returns setof that column's type; otherwise return setof record.
19352 : */
19353 : static TypeName *
19354 188 : TableFuncTypeName(List *columns)
19355 : {
19356 : TypeName *result;
19357 :
19358 188 : if (list_length(columns) == 1)
19359 : {
19360 62 : FunctionParameter *p = (FunctionParameter *) linitial(columns);
19361 :
19362 62 : result = copyObject(p->argType);
19363 : }
19364 : else
19365 126 : result = SystemTypeName("record");
19366 :
19367 188 : result->setof = true;
19368 :
19369 188 : return result;
19370 : }
19371 :
19372 : /*
19373 : * Convert a list of (dotted) names to a RangeVar (like
19374 : * makeRangeVarFromNameList, but with position support). The
19375 : * "AnyName" refers to the any_name production in the grammar.
19376 : */
19377 : static RangeVar *
19378 4736 : makeRangeVarFromAnyName(List *names, int position, core_yyscan_t yyscanner)
19379 : {
19380 4736 : RangeVar *r = makeNode(RangeVar);
19381 :
19382 4736 : switch (list_length(names))
19383 : {
19384 4646 : case 1:
19385 4646 : r->catalogname = NULL;
19386 4646 : r->schemaname = NULL;
19387 4646 : r->relname = strVal(linitial(names));
19388 4646 : break;
19389 90 : case 2:
19390 90 : r->catalogname = NULL;
19391 90 : r->schemaname = strVal(linitial(names));
19392 90 : r->relname = strVal(lsecond(names));
19393 90 : break;
19394 0 : case 3:
19395 0 : r->catalogname = strVal(linitial(names));
19396 0 : r->schemaname = strVal(lsecond(names));
19397 0 : r->relname = strVal(lthird(names));
19398 0 : break;
19399 0 : default:
19400 0 : ereport(ERROR,
19401 : (errcode(ERRCODE_SYNTAX_ERROR),
19402 : errmsg("improper qualified name (too many dotted names): %s",
19403 : NameListToString(names)),
19404 : parser_errposition(position)));
19405 : break;
19406 : }
19407 :
19408 4736 : r->relpersistence = RELPERSISTENCE_PERMANENT;
19409 4736 : r->location = position;
19410 :
19411 4736 : return r;
19412 : }
19413 :
19414 : /*
19415 : * Convert a relation_name with name and namelist to a RangeVar using
19416 : * makeRangeVar.
19417 : */
19418 : static RangeVar *
19419 243380 : makeRangeVarFromQualifiedName(char *name, List *namelist, int location,
19420 : core_yyscan_t yyscanner)
19421 : {
19422 : RangeVar *r;
19423 :
19424 243380 : check_qualified_name(namelist, yyscanner);
19425 243380 : r = makeRangeVar(NULL, NULL, location);
19426 :
19427 243380 : switch (list_length(namelist))
19428 : {
19429 243380 : case 1:
19430 243380 : r->catalogname = NULL;
19431 243380 : r->schemaname = name;
19432 243380 : r->relname = strVal(linitial(namelist));
19433 243380 : break;
19434 0 : case 2:
19435 0 : r->catalogname = name;
19436 0 : r->schemaname = strVal(linitial(namelist));
19437 0 : r->relname = strVal(lsecond(namelist));
19438 0 : break;
19439 0 : default:
19440 0 : ereport(ERROR,
19441 : errcode(ERRCODE_SYNTAX_ERROR),
19442 : errmsg("improper qualified name (too many dotted names): %s",
19443 : NameListToString(lcons(makeString(name), namelist))),
19444 : parser_errposition(location));
19445 : break;
19446 : }
19447 :
19448 243380 : return r;
19449 : }
19450 :
19451 : /* Separate Constraint nodes from COLLATE clauses in a ColQualList */
19452 : static void
19453 69038 : SplitColQualList(List *qualList,
19454 : List **constraintList, CollateClause **collClause,
19455 : core_yyscan_t yyscanner)
19456 : {
19457 : ListCell *cell;
19458 :
19459 69038 : *collClause = NULL;
19460 88784 : foreach(cell, qualList)
19461 : {
19462 19746 : Node *n = (Node *) lfirst(cell);
19463 :
19464 19746 : if (IsA(n, Constraint))
19465 : {
19466 : /* keep it in list */
19467 18984 : continue;
19468 : }
19469 762 : if (IsA(n, CollateClause))
19470 : {
19471 762 : CollateClause *c = (CollateClause *) n;
19472 :
19473 762 : if (*collClause)
19474 0 : ereport(ERROR,
19475 : (errcode(ERRCODE_SYNTAX_ERROR),
19476 : errmsg("multiple COLLATE clauses not allowed"),
19477 : parser_errposition(c->location)));
19478 762 : *collClause = c;
19479 : }
19480 : else
19481 0 : elog(ERROR, "unexpected node type %d", (int) n->type);
19482 : /* remove non-Constraint nodes from qualList */
19483 762 : qualList = foreach_delete_current(qualList, cell);
19484 : }
19485 69038 : *constraintList = qualList;
19486 69038 : }
19487 :
19488 : /*
19489 : * Process result of ConstraintAttributeSpec, and set appropriate bool flags
19490 : * in the output command node. Pass NULL for any flags the particular
19491 : * command doesn't support.
19492 : */
19493 : static void
19494 17780 : processCASbits(int cas_bits, int location, const char *constrType,
19495 : bool *deferrable, bool *initdeferred, bool *is_enforced,
19496 : bool *not_valid, bool *no_inherit, core_yyscan_t yyscanner)
19497 : {
19498 : /* defaults */
19499 17780 : if (deferrable)
19500 15734 : *deferrable = false;
19501 17780 : if (initdeferred)
19502 15734 : *initdeferred = false;
19503 17780 : if (not_valid)
19504 3824 : *not_valid = false;
19505 17780 : if (is_enforced)
19506 3352 : *is_enforced = true;
19507 :
19508 17780 : if (cas_bits & (CAS_DEFERRABLE | CAS_INITIALLY_DEFERRED))
19509 : {
19510 230 : if (deferrable)
19511 230 : *deferrable = true;
19512 : else
19513 0 : ereport(ERROR,
19514 : (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
19515 : /* translator: %s is CHECK, UNIQUE, or similar */
19516 : errmsg("%s constraints cannot be marked DEFERRABLE",
19517 : constrType),
19518 : parser_errposition(location)));
19519 : }
19520 :
19521 17780 : if (cas_bits & CAS_INITIALLY_DEFERRED)
19522 : {
19523 146 : if (initdeferred)
19524 146 : *initdeferred = true;
19525 : else
19526 0 : ereport(ERROR,
19527 : (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
19528 : /* translator: %s is CHECK, UNIQUE, or similar */
19529 : errmsg("%s constraints cannot be marked DEFERRABLE",
19530 : constrType),
19531 : parser_errposition(location)));
19532 : }
19533 :
19534 17780 : if (cas_bits & CAS_NOT_VALID)
19535 : {
19536 708 : if (not_valid)
19537 708 : *not_valid = true;
19538 : else
19539 0 : ereport(ERROR,
19540 : (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
19541 : /* translator: %s is CHECK, UNIQUE, or similar */
19542 : errmsg("%s constraints cannot be marked NOT VALID",
19543 : constrType),
19544 : parser_errposition(location)));
19545 : }
19546 :
19547 17780 : if (cas_bits & CAS_NO_INHERIT)
19548 : {
19549 244 : if (no_inherit)
19550 244 : *no_inherit = true;
19551 : else
19552 0 : ereport(ERROR,
19553 : (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
19554 : /* translator: %s is CHECK, UNIQUE, or similar */
19555 : errmsg("%s constraints cannot be marked NO INHERIT",
19556 : constrType),
19557 : parser_errposition(location)));
19558 : }
19559 :
19560 17780 : if (cas_bits & CAS_NOT_ENFORCED)
19561 : {
19562 156 : if (is_enforced)
19563 150 : *is_enforced = false;
19564 : else
19565 6 : ereport(ERROR,
19566 : (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
19567 : /* translator: %s is CHECK, UNIQUE, or similar */
19568 : errmsg("%s constraints cannot be marked NOT ENFORCED",
19569 : constrType),
19570 : parser_errposition(location)));
19571 :
19572 : /*
19573 : * NB: The validated status is irrelevant when the constraint is set to
19574 : * NOT ENFORCED, but for consistency, it should be set accordingly.
19575 : * This ensures that if the constraint is later changed to ENFORCED, it
19576 : * will automatically be in the correct NOT VALIDATED state.
19577 : */
19578 150 : if (not_valid)
19579 114 : *not_valid = true;
19580 : }
19581 :
19582 17774 : if (cas_bits & CAS_ENFORCED)
19583 : {
19584 102 : if (is_enforced)
19585 96 : *is_enforced = true;
19586 : else
19587 6 : ereport(ERROR,
19588 : (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
19589 : /* translator: %s is CHECK, UNIQUE, or similar */
19590 : errmsg("%s constraints cannot be marked ENFORCED",
19591 : constrType),
19592 : parser_errposition(location)));
19593 : }
19594 17768 : }
19595 :
19596 : /*
19597 : * Parse a user-supplied partition strategy string into parse node
19598 : * PartitionStrategy representation, or die trying.
19599 : */
19600 : static PartitionStrategy
19601 4996 : parsePartitionStrategy(char *strategy, int location, core_yyscan_t yyscanner)
19602 : {
19603 4996 : if (pg_strcasecmp(strategy, "list") == 0)
19604 2538 : return PARTITION_STRATEGY_LIST;
19605 2458 : else if (pg_strcasecmp(strategy, "range") == 0)
19606 2198 : return PARTITION_STRATEGY_RANGE;
19607 260 : else if (pg_strcasecmp(strategy, "hash") == 0)
19608 254 : return PARTITION_STRATEGY_HASH;
19609 :
19610 6 : ereport(ERROR,
19611 : (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
19612 : errmsg("unrecognized partitioning strategy \"%s\"", strategy),
19613 : parser_errposition(location)));
19614 : return PARTITION_STRATEGY_LIST; /* keep compiler quiet */
19615 :
19616 : }
19617 :
19618 : /*
19619 : * Process pubobjspec_list to check for errors in any of the objects and
19620 : * convert PUBLICATIONOBJ_CONTINUATION into appropriate PublicationObjSpecType.
19621 : */
19622 : static void
19623 1644 : preprocess_pubobj_list(List *pubobjspec_list, core_yyscan_t yyscanner)
19624 : {
19625 : ListCell *cell;
19626 : PublicationObjSpec *pubobj;
19627 1644 : PublicationObjSpecType prevobjtype = PUBLICATIONOBJ_CONTINUATION;
19628 :
19629 1644 : if (!pubobjspec_list)
19630 0 : return;
19631 :
19632 1644 : pubobj = (PublicationObjSpec *) linitial(pubobjspec_list);
19633 1644 : if (pubobj->pubobjtype == PUBLICATIONOBJ_CONTINUATION)
19634 12 : ereport(ERROR,
19635 : errcode(ERRCODE_SYNTAX_ERROR),
19636 : errmsg("invalid publication object list"),
19637 : errdetail("One of TABLE or TABLES IN SCHEMA must be specified before a standalone table or schema name."),
19638 : parser_errposition(pubobj->location));
19639 :
19640 3494 : foreach(cell, pubobjspec_list)
19641 : {
19642 1886 : pubobj = (PublicationObjSpec *) lfirst(cell);
19643 :
19644 1886 : if (pubobj->pubobjtype == PUBLICATIONOBJ_CONTINUATION)
19645 174 : pubobj->pubobjtype = prevobjtype;
19646 :
19647 1886 : if (pubobj->pubobjtype == PUBLICATIONOBJ_TABLE)
19648 : {
19649 : /* relation name or pubtable must be set for this type of object */
19650 1442 : if (!pubobj->name && !pubobj->pubtable)
19651 6 : ereport(ERROR,
19652 : errcode(ERRCODE_SYNTAX_ERROR),
19653 : errmsg("invalid table name"),
19654 : parser_errposition(pubobj->location));
19655 :
19656 1436 : if (pubobj->name)
19657 : {
19658 : /* convert it to PublicationTable */
19659 58 : PublicationTable *pubtable = makeNode(PublicationTable);
19660 :
19661 58 : pubtable->relation =
19662 58 : makeRangeVar(NULL, pubobj->name, pubobj->location);
19663 58 : pubobj->pubtable = pubtable;
19664 58 : pubobj->name = NULL;
19665 : }
19666 : }
19667 444 : else if (pubobj->pubobjtype == PUBLICATIONOBJ_TABLES_IN_SCHEMA ||
19668 24 : pubobj->pubobjtype == PUBLICATIONOBJ_TABLES_IN_CUR_SCHEMA)
19669 : {
19670 : /* WHERE clause is not allowed on a schema object */
19671 444 : if (pubobj->pubtable && pubobj->pubtable->whereClause)
19672 6 : ereport(ERROR,
19673 : errcode(ERRCODE_SYNTAX_ERROR),
19674 : errmsg("WHERE clause not allowed for schema"),
19675 : parser_errposition(pubobj->location));
19676 :
19677 : /* Column list is not allowed on a schema object */
19678 438 : if (pubobj->pubtable && pubobj->pubtable->columns)
19679 6 : ereport(ERROR,
19680 : errcode(ERRCODE_SYNTAX_ERROR),
19681 : errmsg("column specification not allowed for schema"),
19682 : parser_errposition(pubobj->location));
19683 :
19684 : /*
19685 : * We can distinguish between the different type of schema objects
19686 : * based on whether name and pubtable is set.
19687 : */
19688 432 : if (pubobj->name)
19689 402 : pubobj->pubobjtype = PUBLICATIONOBJ_TABLES_IN_SCHEMA;
19690 30 : else if (!pubobj->name && !pubobj->pubtable)
19691 24 : pubobj->pubobjtype = PUBLICATIONOBJ_TABLES_IN_CUR_SCHEMA;
19692 : else
19693 6 : ereport(ERROR,
19694 : errcode(ERRCODE_SYNTAX_ERROR),
19695 : errmsg("invalid schema name"),
19696 : parser_errposition(pubobj->location));
19697 : }
19698 :
19699 1862 : prevobjtype = pubobj->pubobjtype;
19700 : }
19701 : }
19702 :
19703 : /*----------
19704 : * Recursive view transformation
19705 : *
19706 : * Convert
19707 : *
19708 : * CREATE RECURSIVE VIEW relname (aliases) AS query
19709 : *
19710 : * to
19711 : *
19712 : * CREATE VIEW relname (aliases) AS
19713 : * WITH RECURSIVE relname (aliases) AS (query)
19714 : * SELECT aliases FROM relname
19715 : *
19716 : * Actually, just the WITH ... part, which is then inserted into the original
19717 : * view definition as the query.
19718 : * ----------
19719 : */
19720 : static Node *
19721 14 : makeRecursiveViewSelect(char *relname, List *aliases, Node *query)
19722 : {
19723 14 : SelectStmt *s = makeNode(SelectStmt);
19724 14 : WithClause *w = makeNode(WithClause);
19725 14 : CommonTableExpr *cte = makeNode(CommonTableExpr);
19726 14 : List *tl = NIL;
19727 : ListCell *lc;
19728 :
19729 : /* create common table expression */
19730 14 : cte->ctename = relname;
19731 14 : cte->aliascolnames = aliases;
19732 14 : cte->ctematerialized = CTEMaterializeDefault;
19733 14 : cte->ctequery = query;
19734 14 : cte->location = -1;
19735 :
19736 : /* create WITH clause and attach CTE */
19737 14 : w->recursive = true;
19738 14 : w->ctes = list_make1(cte);
19739 14 : w->location = -1;
19740 :
19741 : /*
19742 : * create target list for the new SELECT from the alias list of the
19743 : * recursive view specification
19744 : */
19745 28 : foreach(lc, aliases)
19746 : {
19747 14 : ResTarget *rt = makeNode(ResTarget);
19748 :
19749 14 : rt->name = NULL;
19750 14 : rt->indirection = NIL;
19751 14 : rt->val = makeColumnRef(strVal(lfirst(lc)), NIL, -1, 0);
19752 14 : rt->location = -1;
19753 :
19754 14 : tl = lappend(tl, rt);
19755 : }
19756 :
19757 : /*
19758 : * create new SELECT combining WITH clause, target list, and fake FROM
19759 : * clause
19760 : */
19761 14 : s->withClause = w;
19762 14 : s->targetList = tl;
19763 14 : s->fromClause = list_make1(makeRangeVar(NULL, relname, -1));
19764 :
19765 14 : return (Node *) s;
19766 : }
19767 :
19768 : /* parser_init()
19769 : * Initialize to parse one query string
19770 : */
19771 : void
19772 760488 : parser_init(base_yy_extra_type *yyext)
19773 : {
19774 760488 : yyext->parsetree = NIL; /* in case grammar forgets to set it */
19775 760488 : }
|