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-2024, 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 :
147 :
148 : #define parser_yyerror(msg) scanner_yyerror(msg, yyscanner)
149 : #define parser_errposition(pos) scanner_errposition(pos, yyscanner)
150 :
151 : static void base_yyerror(YYLTYPE *yylloc, core_yyscan_t yyscanner,
152 : const char *msg);
153 : static RawStmt *makeRawStmt(Node *stmt, int stmt_location);
154 : static void updateRawStmtEnd(RawStmt *rs, int end_location);
155 : static void updatePreparableStmtEnd(Node *n, int end_location);
156 : static Node *makeColumnRef(char *colname, List *indirection,
157 : int location, core_yyscan_t yyscanner);
158 : static Node *makeTypeCast(Node *arg, TypeName *typename, int location);
159 : static Node *makeStringConstCast(char *str, int location, TypeName *typename);
160 : static Node *makeIntConst(int val, int location);
161 : static Node *makeFloatConst(char *str, int location);
162 : static Node *makeBoolAConst(bool state, int location);
163 : static Node *makeBitStringConst(char *str, int location);
164 : static Node *makeNullAConst(int location);
165 : static Node *makeAConst(Node *v, int location);
166 : static RoleSpec *makeRoleSpec(RoleSpecType type, int location);
167 : static void check_qualified_name(List *names, core_yyscan_t yyscanner);
168 : static List *check_func_name(List *names, core_yyscan_t yyscanner);
169 : static List *check_indirection(List *indirection, core_yyscan_t yyscanner);
170 : static List *extractArgTypes(List *parameters);
171 : static List *extractAggrArgTypes(List *aggrargs);
172 : static List *makeOrderedSetArgs(List *directargs, List *orderedargs,
173 : core_yyscan_t yyscanner);
174 : static void insertSelectOptions(SelectStmt *stmt,
175 : List *sortClause, List *lockingClause,
176 : SelectLimit *limitClause,
177 : WithClause *withClause,
178 : core_yyscan_t yyscanner);
179 : static Node *makeSetOp(SetOperation op, bool all, Node *larg, Node *rarg, int location);
180 : static Node *doNegate(Node *n, int location);
181 : static void doNegateFloat(Float *v);
182 : static Node *makeAndExpr(Node *lexpr, Node *rexpr, int location);
183 : static Node *makeOrExpr(Node *lexpr, Node *rexpr, int location);
184 : static Node *makeNotExpr(Node *expr, int location);
185 : static Node *makeAArrayExpr(List *elements, int location);
186 : static Node *makeSQLValueFunction(SQLValueFunctionOp op, int32 typmod,
187 : int location);
188 : static Node *makeXmlExpr(XmlExprOp op, char *name, List *named_args,
189 : List *args, int location);
190 : static List *mergeTableFuncParameters(List *func_args, List *columns, core_yyscan_t yyscanner);
191 : static TypeName *TableFuncTypeName(List *columns);
192 : static RangeVar *makeRangeVarFromAnyName(List *names, int position, core_yyscan_t yyscanner);
193 : static RangeVar *makeRangeVarFromQualifiedName(char *name, List *namelist, int location,
194 : core_yyscan_t yyscanner);
195 : static void SplitColQualList(List *qualList,
196 : List **constraintList, CollateClause **collClause,
197 : core_yyscan_t yyscanner);
198 : static void processCASbits(int cas_bits, int location, const char *constrType,
199 : bool *deferrable, bool *initdeferred, bool *not_valid,
200 : bool *no_inherit, core_yyscan_t yyscanner);
201 : static PartitionStrategy parsePartitionStrategy(char *strategy, int location,
202 : core_yyscan_t yyscanner);
203 : static void preprocess_pubobj_list(List *pubobjspec_list,
204 : core_yyscan_t yyscanner);
205 : static Node *makeRecursiveViewSelect(char *relname, List *aliases, Node *query);
206 :
207 : %}
208 :
209 : %pure-parser
210 : %expect 0
211 : %name-prefix="base_yy"
212 : %locations
213 :
214 : %parse-param {core_yyscan_t yyscanner}
215 : %lex-param {core_yyscan_t yyscanner}
216 :
217 : %union
218 : {
219 : core_YYSTYPE core_yystype;
220 : /* these fields must match core_YYSTYPE: */
221 : int ival;
222 : char *str;
223 : const char *keyword;
224 :
225 : char chr;
226 : bool boolean;
227 : JoinType jtype;
228 : DropBehavior dbehavior;
229 : OnCommitAction oncommit;
230 : List *list;
231 : Node *node;
232 : ObjectType objtype;
233 : TypeName *typnam;
234 : FunctionParameter *fun_param;
235 : FunctionParameterMode fun_param_mode;
236 : ObjectWithArgs *objwithargs;
237 : DefElem *defelt;
238 : SortBy *sortby;
239 : WindowDef *windef;
240 : JoinExpr *jexpr;
241 : IndexElem *ielem;
242 : StatsElem *selem;
243 : Alias *alias;
244 : RangeVar *range;
245 : IntoClause *into;
246 : WithClause *with;
247 : InferClause *infer;
248 : OnConflictClause *onconflict;
249 : A_Indices *aind;
250 : ResTarget *target;
251 : struct PrivTarget *privtarget;
252 : AccessPriv *accesspriv;
253 : struct ImportQual *importqual;
254 : InsertStmt *istmt;
255 : VariableSetStmt *vsetstmt;
256 : PartitionElem *partelem;
257 : PartitionSpec *partspec;
258 : PartitionBoundSpec *partboundspec;
259 : RoleSpec *rolespec;
260 : PublicationObjSpec *publicationobjectspec;
261 : struct SelectLimit *selectlimit;
262 : SetQuantifier setquantifier;
263 : struct GroupClause *groupclause;
264 : MergeMatchKind mergematch;
265 : MergeWhenClause *mergewhen;
266 : struct KeyActions *keyactions;
267 : struct KeyAction *keyaction;
268 : }
269 :
270 : %type <node> stmt toplevel_stmt schema_stmt routine_body_stmt
271 : AlterEventTrigStmt AlterCollationStmt
272 : AlterDatabaseStmt AlterDatabaseSetStmt AlterDomainStmt AlterEnumStmt
273 : AlterFdwStmt AlterForeignServerStmt AlterGroupStmt
274 : AlterObjectDependsStmt AlterObjectSchemaStmt AlterOwnerStmt
275 : AlterOperatorStmt AlterTypeStmt AlterSeqStmt AlterSystemStmt AlterTableStmt
276 : AlterTblSpcStmt AlterExtensionStmt AlterExtensionContentsStmt
277 : AlterCompositeTypeStmt AlterUserMappingStmt
278 : AlterRoleStmt AlterRoleSetStmt AlterPolicyStmt AlterStatsStmt
279 : AlterDefaultPrivilegesStmt DefACLAction
280 : AnalyzeStmt CallStmt ClosePortalStmt ClusterStmt CommentStmt
281 : ConstraintsSetStmt CopyStmt CreateAsStmt CreateCastStmt
282 : CreateDomainStmt CreateExtensionStmt CreateGroupStmt CreateOpClassStmt
283 : CreateOpFamilyStmt AlterOpFamilyStmt CreatePLangStmt
284 : CreateSchemaStmt CreateSeqStmt CreateStmt CreateStatsStmt CreateTableSpaceStmt
285 : CreateFdwStmt CreateForeignServerStmt CreateForeignTableStmt
286 : CreateAssertionStmt CreateTransformStmt CreateTrigStmt CreateEventTrigStmt
287 : CreateUserStmt CreateUserMappingStmt CreateRoleStmt CreatePolicyStmt
288 : CreatedbStmt DeclareCursorStmt DefineStmt DeleteStmt DiscardStmt DoStmt
289 : DropOpClassStmt DropOpFamilyStmt DropStmt
290 : DropCastStmt DropRoleStmt
291 : DropdbStmt DropTableSpaceStmt
292 : DropTransformStmt
293 : DropUserMappingStmt ExplainStmt FetchStmt
294 : GrantStmt GrantRoleStmt ImportForeignSchemaStmt IndexStmt InsertStmt
295 : ListenStmt LoadStmt LockStmt MergeStmt NotifyStmt ExplainableStmt PreparableStmt
296 : CreateFunctionStmt AlterFunctionStmt ReindexStmt RemoveAggrStmt
297 : RemoveFuncStmt RemoveOperStmt RenameStmt ReturnStmt RevokeStmt RevokeRoleStmt
298 : RuleActionStmt RuleActionStmtOrEmpty RuleStmt
299 : SecLabelStmt SelectStmt TransactionStmt TransactionStmtLegacy TruncateStmt
300 : UnlistenStmt UpdateStmt VacuumStmt
301 : VariableResetStmt VariableSetStmt VariableShowStmt
302 : ViewStmt CheckPointStmt CreateConversionStmt
303 : DeallocateStmt PrepareStmt ExecuteStmt
304 : DropOwnedStmt ReassignOwnedStmt
305 : AlterTSConfigurationStmt AlterTSDictionaryStmt
306 : CreateMatViewStmt RefreshMatViewStmt CreateAmStmt
307 : CreatePublicationStmt AlterPublicationStmt
308 : CreateSubscriptionStmt AlterSubscriptionStmt DropSubscriptionStmt
309 :
310 : %type <node> select_no_parens select_with_parens select_clause
311 : simple_select values_clause
312 : PLpgSQL_Expr PLAssignStmt
313 :
314 : %type <str> opt_single_name
315 : %type <list> opt_qualified_name
316 : %type <boolean> opt_concurrently
317 : %type <dbehavior> opt_drop_behavior
318 :
319 : %type <node> alter_column_default opclass_item opclass_drop alter_using
320 : %type <ival> add_drop opt_asc_desc opt_nulls_order
321 :
322 : %type <node> alter_table_cmd alter_type_cmd opt_collate_clause
323 : replica_identity partition_cmd index_partition_cmd
324 : %type <list> alter_table_cmds alter_type_cmds
325 : %type <list> alter_identity_column_option_list
326 : %type <defelt> alter_identity_column_option
327 : %type <node> set_statistics_value
328 : %type <str> set_access_method_name
329 :
330 : %type <list> createdb_opt_list createdb_opt_items copy_opt_list
331 : transaction_mode_list
332 : create_extension_opt_list alter_extension_opt_list
333 : %type <defelt> createdb_opt_item copy_opt_item
334 : transaction_mode_item
335 : create_extension_opt_item alter_extension_opt_item
336 :
337 : %type <ival> opt_lock lock_type cast_context
338 : %type <str> utility_option_name
339 : %type <defelt> utility_option_elem
340 : %type <list> utility_option_list
341 : %type <node> utility_option_arg
342 : %type <defelt> drop_option
343 : %type <boolean> opt_or_replace opt_no
344 : opt_grant_grant_option
345 : opt_nowait opt_if_exists opt_with_data
346 : opt_transaction_chain
347 : %type <list> grant_role_opt_list
348 : %type <defelt> grant_role_opt
349 : %type <node> grant_role_opt_value
350 : %type <ival> opt_nowait_or_skip
351 :
352 : %type <list> OptRoleList AlterOptRoleList
353 : %type <defelt> CreateOptRoleElem AlterOptRoleElem
354 :
355 : %type <str> opt_type
356 : %type <str> foreign_server_version opt_foreign_server_version
357 : %type <str> opt_in_database
358 :
359 : %type <str> parameter_name
360 : %type <list> OptSchemaEltList parameter_name_list
361 :
362 : %type <chr> am_type
363 :
364 : %type <boolean> TriggerForSpec TriggerForType
365 : %type <ival> TriggerActionTime
366 : %type <list> TriggerEvents TriggerOneEvent
367 : %type <node> TriggerFuncArg
368 : %type <node> TriggerWhen
369 : %type <str> TransitionRelName
370 : %type <boolean> TransitionRowOrTable TransitionOldOrNew
371 : %type <node> TriggerTransition
372 :
373 : %type <list> event_trigger_when_list event_trigger_value_list
374 : %type <defelt> event_trigger_when_item
375 : %type <chr> enable_trigger
376 :
377 : %type <str> copy_file_name
378 : access_method_clause attr_name
379 : table_access_method_clause name cursor_name file_name
380 : cluster_index_specification
381 :
382 : %type <list> func_name handler_name qual_Op qual_all_Op subquery_Op
383 : opt_inline_handler opt_validator validator_clause
384 : opt_collate
385 :
386 : %type <range> qualified_name insert_target OptConstrFromTable
387 :
388 : %type <str> all_Op MathOp
389 :
390 : %type <str> row_security_cmd RowSecurityDefaultForCmd
391 : %type <boolean> RowSecurityDefaultPermissive
392 : %type <node> RowSecurityOptionalWithCheck RowSecurityOptionalExpr
393 : %type <list> RowSecurityDefaultToRole RowSecurityOptionalToRole
394 :
395 : %type <str> iso_level opt_encoding
396 : %type <rolespec> grantee
397 : %type <list> grantee_list
398 : %type <accesspriv> privilege
399 : %type <list> privileges privilege_list
400 : %type <privtarget> privilege_target
401 : %type <objwithargs> function_with_argtypes aggregate_with_argtypes operator_with_argtypes
402 : %type <list> function_with_argtypes_list aggregate_with_argtypes_list operator_with_argtypes_list
403 : %type <ival> defacl_privilege_target
404 : %type <defelt> DefACLOption
405 : %type <list> DefACLOptionList
406 : %type <ival> import_qualification_type
407 : %type <importqual> import_qualification
408 : %type <node> vacuum_relation
409 : %type <selectlimit> opt_select_limit select_limit limit_clause
410 :
411 : %type <list> parse_toplevel stmtmulti routine_body_stmt_list
412 : OptTableElementList TableElementList OptInherit definition
413 : OptTypedTableElementList TypedTableElementList
414 : reloptions opt_reloptions
415 : OptWith opt_definition func_args func_args_list
416 : func_args_with_defaults func_args_with_defaults_list
417 : aggr_args aggr_args_list
418 : func_as createfunc_opt_list opt_createfunc_opt_list alterfunc_opt_list
419 : old_aggr_definition old_aggr_list
420 : oper_argtypes RuleActionList RuleActionMulti
421 : opt_column_list columnList opt_name_list
422 : sort_clause opt_sort_clause sortby_list index_params
423 : stats_params
424 : opt_include opt_c_include index_including_params
425 : name_list role_list from_clause from_list opt_array_bounds
426 : qualified_name_list any_name any_name_list type_name_list
427 : any_operator expr_list attrs
428 : distinct_clause opt_distinct_clause
429 : target_list opt_target_list insert_column_list set_target_list
430 : merge_values_clause
431 : set_clause_list set_clause
432 : def_list operator_def_list indirection opt_indirection
433 : reloption_list TriggerFuncArgs opclass_item_list opclass_drop_list
434 : opclass_purpose opt_opfamily transaction_mode_list_or_empty
435 : OptTableFuncElementList TableFuncElementList opt_type_modifiers
436 : prep_type_clause
437 : execute_param_clause using_clause returning_clause
438 : opt_enum_val_list enum_val_list table_func_column_list
439 : create_generic_options alter_generic_options
440 : relation_expr_list dostmt_opt_list
441 : transform_element_list transform_type_list
442 : TriggerTransitions TriggerReferencing
443 : vacuum_relation_list opt_vacuum_relation_list
444 : drop_option_list pub_obj_list
445 :
446 : %type <node> opt_routine_body
447 : %type <groupclause> group_clause
448 : %type <list> group_by_list
449 : %type <node> group_by_item empty_grouping_set rollup_clause cube_clause
450 : %type <node> grouping_sets_clause
451 :
452 : %type <list> opt_fdw_options fdw_options
453 : %type <defelt> fdw_option
454 :
455 : %type <range> OptTempTableName
456 : %type <into> into_clause create_as_target create_mv_target
457 :
458 : %type <defelt> createfunc_opt_item common_func_opt_item dostmt_opt_item
459 : %type <fun_param> func_arg func_arg_with_default table_func_column aggr_arg
460 : %type <fun_param_mode> arg_class
461 : %type <typnam> func_return func_type
462 :
463 : %type <boolean> opt_trusted opt_restart_seqs
464 : %type <ival> OptTemp
465 : %type <ival> OptNoLog
466 : %type <oncommit> OnCommitOption
467 :
468 : %type <ival> for_locking_strength
469 : %type <node> for_locking_item
470 : %type <list> for_locking_clause opt_for_locking_clause for_locking_items
471 : %type <list> locked_rels_list
472 : %type <setquantifier> set_quantifier
473 :
474 : %type <node> join_qual
475 : %type <jtype> join_type
476 :
477 : %type <list> extract_list overlay_list position_list
478 : %type <list> substr_list trim_list
479 : %type <list> opt_interval interval_second
480 : %type <str> unicode_normal_form
481 :
482 : %type <boolean> opt_instead
483 : %type <boolean> opt_unique opt_verbose opt_full
484 : %type <boolean> opt_freeze opt_analyze opt_default
485 : %type <defelt> opt_binary copy_delimiter
486 :
487 : %type <boolean> copy_from opt_program
488 :
489 : %type <ival> event cursor_options opt_hold opt_set_data
490 : %type <objtype> object_type_any_name object_type_name object_type_name_on_any_name
491 : drop_type_name
492 :
493 : %type <node> fetch_args select_limit_value
494 : offset_clause select_offset_value
495 : select_fetch_first_value I_or_F_const
496 : %type <ival> row_or_rows first_or_next
497 :
498 : %type <list> OptSeqOptList SeqOptList OptParenthesizedSeqOptList
499 : %type <defelt> SeqOptElem
500 :
501 : %type <istmt> insert_rest
502 : %type <infer> opt_conf_expr
503 : %type <onconflict> opt_on_conflict
504 : %type <mergewhen> merge_insert merge_update merge_delete
505 :
506 : %type <mergematch> merge_when_tgt_matched merge_when_tgt_not_matched
507 : %type <node> merge_when_clause opt_merge_when_condition
508 : %type <list> merge_when_list
509 :
510 : %type <vsetstmt> generic_set set_rest set_rest_more generic_reset reset_rest
511 : SetResetClause FunctionSetResetClause
512 :
513 : %type <node> TableElement TypedTableElement ConstraintElem DomainConstraintElem TableFuncElement
514 : %type <node> columnDef columnOptions optionalPeriodName
515 : %type <defelt> def_elem reloption_elem old_aggr_elem operator_def_elem
516 : %type <node> def_arg columnElem where_clause where_or_current_clause
517 : a_expr b_expr c_expr AexprConst indirection_el opt_slice_bound
518 : columnref in_expr having_clause func_table xmltable array_expr
519 : OptWhereClause operator_def_arg
520 : %type <list> opt_column_and_period_list
521 : %type <list> rowsfrom_item rowsfrom_list opt_col_def_list
522 : %type <boolean> opt_ordinality opt_without_overlaps
523 : %type <list> ExclusionConstraintList ExclusionConstraintElem
524 : %type <list> func_arg_list func_arg_list_opt
525 : %type <node> func_arg_expr
526 : %type <list> row explicit_row implicit_row type_list array_expr_list
527 : %type <node> case_expr case_arg when_clause case_default
528 : %type <list> when_clause_list
529 : %type <node> opt_search_clause opt_cycle_clause
530 : %type <ival> sub_type opt_materialized
531 : %type <node> NumericOnly
532 : %type <list> NumericOnly_list
533 : %type <alias> alias_clause opt_alias_clause opt_alias_clause_for_join_using
534 : %type <list> func_alias_clause
535 : %type <sortby> sortby
536 : %type <ielem> index_elem index_elem_options
537 : %type <selem> stats_param
538 : %type <node> table_ref
539 : %type <jexpr> joined_table
540 : %type <range> relation_expr
541 : %type <range> extended_relation_expr
542 : %type <range> relation_expr_opt_alias
543 : %type <node> tablesample_clause opt_repeatable_clause
544 : %type <target> target_el set_target insert_column_item
545 :
546 : %type <str> generic_option_name
547 : %type <node> generic_option_arg
548 : %type <defelt> generic_option_elem alter_generic_option_elem
549 : %type <list> generic_option_list alter_generic_option_list
550 :
551 : %type <ival> reindex_target_relation reindex_target_all
552 : %type <list> opt_reindex_option_list
553 :
554 : %type <node> copy_generic_opt_arg copy_generic_opt_arg_list_item
555 : %type <defelt> copy_generic_opt_elem
556 : %type <list> copy_generic_opt_list copy_generic_opt_arg_list
557 : %type <list> copy_options
558 :
559 : %type <typnam> Typename SimpleTypename ConstTypename
560 : GenericType Numeric opt_float JsonType
561 : Character ConstCharacter
562 : CharacterWithLength CharacterWithoutLength
563 : ConstDatetime ConstInterval
564 : Bit ConstBit BitWithLength BitWithoutLength
565 : %type <str> character
566 : %type <str> extract_arg
567 : %type <boolean> opt_varying opt_timezone opt_no_inherit
568 :
569 : %type <ival> Iconst SignedIconst
570 : %type <str> Sconst comment_text notify_payload
571 : %type <str> RoleId opt_boolean_or_string
572 : %type <list> var_list
573 : %type <str> ColId ColLabel BareColLabel
574 : %type <str> NonReservedWord NonReservedWord_or_Sconst
575 : %type <str> var_name type_function_name param_name
576 : %type <str> createdb_opt_name plassign_target
577 : %type <node> var_value zone_value
578 : %type <rolespec> auth_ident RoleSpec opt_granted_by
579 : %type <publicationobjectspec> PublicationObjSpec
580 :
581 : %type <keyword> unreserved_keyword type_func_name_keyword
582 : %type <keyword> col_name_keyword reserved_keyword
583 : %type <keyword> bare_label_keyword
584 :
585 : %type <node> DomainConstraint TableConstraint TableLikeClause
586 : %type <ival> TableLikeOptionList TableLikeOption
587 : %type <str> column_compression opt_column_compression column_storage opt_column_storage
588 : %type <list> ColQualList
589 : %type <node> ColConstraint ColConstraintElem ConstraintAttr
590 : %type <ival> key_match
591 : %type <keyaction> key_delete key_update key_action
592 : %type <keyactions> key_actions
593 : %type <ival> ConstraintAttributeSpec ConstraintAttributeElem
594 : %type <str> ExistingIndex
595 :
596 : %type <list> constraints_set_list
597 : %type <boolean> constraints_set_mode
598 : %type <str> OptTableSpace OptConsTableSpace
599 : %type <rolespec> OptTableSpaceOwner
600 : %type <ival> opt_check_option
601 :
602 : %type <str> opt_provider security_label
603 :
604 : %type <target> xml_attribute_el
605 : %type <list> xml_attribute_list xml_attributes
606 : %type <node> xml_root_version opt_xml_root_standalone
607 : %type <node> xmlexists_argument
608 : %type <ival> document_or_content
609 : %type <boolean> xml_indent_option xml_whitespace_option
610 : %type <list> xmltable_column_list xmltable_column_option_list
611 : %type <node> xmltable_column_el
612 : %type <defelt> xmltable_column_option_el
613 : %type <list> xml_namespace_list
614 : %type <target> xml_namespace_el
615 :
616 : %type <node> func_application func_expr_common_subexpr
617 : %type <node> func_expr func_expr_windowless
618 : %type <node> common_table_expr
619 : %type <with> with_clause opt_with_clause
620 : %type <list> cte_list
621 :
622 : %type <list> within_group_clause
623 : %type <node> filter_clause
624 : %type <list> window_clause window_definition_list opt_partition_clause
625 : %type <windef> window_definition over_clause window_specification
626 : opt_frame_clause frame_extent frame_bound
627 : %type <ival> opt_window_exclusion_clause
628 : %type <str> opt_existing_window_name
629 : %type <boolean> opt_if_not_exists
630 : %type <boolean> opt_unique_null_treatment
631 : %type <ival> generated_when override_kind
632 : %type <partspec> PartitionSpec OptPartitionSpec
633 : %type <partelem> part_elem
634 : %type <list> part_params
635 : %type <partboundspec> PartitionBoundSpec
636 : %type <list> hash_partbound
637 : %type <defelt> hash_partbound_elem
638 :
639 : %type <node> json_format_clause
640 : json_format_clause_opt
641 : json_value_expr
642 : json_returning_clause_opt
643 : json_name_and_value
644 : json_aggregate_func
645 : json_argument
646 : json_behavior
647 : json_on_error_clause_opt
648 : json_table
649 : json_table_column_definition
650 : json_table_column_path_clause_opt
651 : %type <list> json_name_and_value_list
652 : json_value_expr_list
653 : json_array_aggregate_order_by_clause_opt
654 : json_arguments
655 : json_behavior_clause_opt
656 : json_passing_clause_opt
657 : json_table_column_definition_list
658 : %type <str> json_table_path_name_opt
659 : %type <ival> json_behavior_type
660 : json_predicate_type_constraint
661 : json_quotes_clause_opt
662 : json_wrapper_behavior
663 : %type <boolean> json_key_uniqueness_constraint_opt
664 : json_object_constructor_null_clause_opt
665 : json_array_constructor_null_clause_opt
666 :
667 :
668 : /*
669 : * Non-keyword token types. These are hard-wired into the "flex" lexer.
670 : * They must be listed first so that their numeric codes do not depend on
671 : * the set of keywords. PL/pgSQL depends on this so that it can share the
672 : * same lexer. If you add/change tokens here, fix PL/pgSQL to match!
673 : *
674 : * UIDENT and USCONST are reduced to IDENT and SCONST in parser.c, so that
675 : * they need no productions here; but we must assign token codes to them.
676 : *
677 : * DOT_DOT is unused in the core SQL grammar, and so will always provoke
678 : * parse errors. It is needed by PL/pgSQL.
679 : */
680 : %token <str> IDENT UIDENT FCONST SCONST USCONST BCONST XCONST Op
681 : %token <ival> ICONST PARAM
682 : %token TYPECAST DOT_DOT COLON_EQUALS EQUALS_GREATER
683 : %token LESS_EQUALS GREATER_EQUALS NOT_EQUALS
684 :
685 : /*
686 : * If you want to make any keyword changes, update the keyword table in
687 : * src/include/parser/kwlist.h and add new keywords to the appropriate one
688 : * of the reserved-or-not-so-reserved keyword lists, below; search
689 : * this file for "Keyword category lists".
690 : */
691 :
692 : /* ordinary key words in alphabetical order */
693 : %token <keyword> ABORT_P ABSENT ABSOLUTE_P ACCESS ACTION ADD_P ADMIN AFTER
694 : AGGREGATE ALL ALSO ALTER ALWAYS ANALYSE ANALYZE AND ANY ARRAY AS ASC
695 : ASENSITIVE ASSERTION ASSIGNMENT ASYMMETRIC ATOMIC AT ATTACH ATTRIBUTE AUTHORIZATION
696 :
697 : BACKWARD BEFORE BEGIN_P BETWEEN BIGINT BINARY BIT
698 : BOOLEAN_P BOTH BREADTH BY
699 :
700 : CACHE CALL CALLED CASCADE CASCADED CASE CAST CATALOG_P CHAIN CHAR_P
701 : CHARACTER CHARACTERISTICS CHECK CHECKPOINT CLASS CLOSE
702 : CLUSTER COALESCE COLLATE COLLATION COLUMN COLUMNS COMMENT COMMENTS COMMIT
703 : COMMITTED COMPRESSION CONCURRENTLY CONDITIONAL CONFIGURATION CONFLICT
704 : CONNECTION CONSTRAINT CONSTRAINTS CONTENT_P CONTINUE_P CONVERSION_P COPY
705 : COST CREATE CROSS CSV CUBE CURRENT_P
706 : CURRENT_CATALOG CURRENT_DATE CURRENT_ROLE CURRENT_SCHEMA
707 : CURRENT_TIME CURRENT_TIMESTAMP CURRENT_USER CURSOR CYCLE
708 :
709 : DATA_P DATABASE DAY_P DEALLOCATE DEC DECIMAL_P DECLARE DEFAULT DEFAULTS
710 : DEFERRABLE DEFERRED DEFINER DELETE_P DELIMITER DELIMITERS DEPENDS DEPTH DESC
711 : DETACH DICTIONARY DISABLE_P DISCARD DISTINCT DO DOCUMENT_P DOMAIN_P
712 : DOUBLE_P DROP
713 :
714 : EACH ELSE EMPTY_P ENABLE_P ENCODING ENCRYPTED END_P ENUM_P ERROR_P ESCAPE
715 : EVENT EXCEPT EXCLUDE EXCLUDING EXCLUSIVE EXECUTE EXISTS EXPLAIN EXPRESSION
716 : EXTENSION EXTERNAL EXTRACT
717 :
718 : FALSE_P FAMILY FETCH FILTER FINALIZE FIRST_P FLOAT_P FOLLOWING FOR
719 : FORCE FOREIGN FORMAT FORWARD FREEZE FROM FULL FUNCTION FUNCTIONS
720 :
721 : GENERATED GLOBAL GRANT GRANTED GREATEST GROUP_P GROUPING GROUPS
722 :
723 : HANDLER HAVING HEADER_P HOLD HOUR_P
724 :
725 : IDENTITY_P IF_P ILIKE IMMEDIATE IMMUTABLE IMPLICIT_P IMPORT_P IN_P INCLUDE
726 : INCLUDING INCREMENT INDENT INDEX INDEXES INHERIT INHERITS INITIALLY INLINE_P
727 : INNER_P INOUT INPUT_P INSENSITIVE INSERT INSTEAD INT_P INTEGER
728 : INTERSECT INTERVAL INTO INVOKER IS ISNULL ISOLATION
729 :
730 : JOIN JSON JSON_ARRAY JSON_ARRAYAGG JSON_EXISTS JSON_OBJECT JSON_OBJECTAGG
731 : JSON_QUERY JSON_SCALAR JSON_SERIALIZE JSON_TABLE JSON_VALUE
732 :
733 : KEEP KEY KEYS
734 :
735 : LABEL LANGUAGE LARGE_P LAST_P LATERAL_P
736 : LEADING LEAKPROOF LEAST LEFT LEVEL LIKE LIMIT LISTEN LOAD LOCAL
737 : LOCALTIME LOCALTIMESTAMP LOCATION LOCK_P LOCKED LOGGED
738 :
739 : MAPPING MATCH MATCHED MATERIALIZED MAXVALUE MERGE MERGE_ACTION METHOD
740 : MINUTE_P MINVALUE MODE MONTH_P MOVE
741 :
742 : NAME_P NAMES NATIONAL NATURAL NCHAR NESTED NEW NEXT NFC NFD NFKC NFKD NO
743 : NONE NORMALIZE NORMALIZED
744 : NOT NOTHING NOTIFY NOTNULL NOWAIT NULL_P NULLIF
745 : NULLS_P NUMERIC
746 :
747 : OBJECT_P OF OFF OFFSET OIDS OLD OMIT ON ONLY OPERATOR OPTION OPTIONS OR
748 : ORDER ORDINALITY OTHERS OUT_P OUTER_P
749 : OVER OVERLAPS OVERLAY OVERRIDING OWNED OWNER
750 :
751 : PARALLEL PARAMETER PARSER PARTIAL PARTITION PASSING PASSWORD PATH
752 : PERIOD PLACING PLAN PLANS POLICY
753 : POSITION PRECEDING PRECISION PRESERVE PREPARE PREPARED PRIMARY
754 : PRIOR PRIVILEGES PROCEDURAL PROCEDURE PROCEDURES PROGRAM PUBLICATION
755 :
756 : QUOTE QUOTES
757 :
758 : RANGE READ REAL REASSIGN RECURSIVE REF_P REFERENCES REFERENCING
759 : REFRESH REINDEX RELATIVE_P RELEASE RENAME REPEATABLE REPLACE REPLICA
760 : RESET RESTART RESTRICT RETURN RETURNING RETURNS REVOKE RIGHT ROLE ROLLBACK ROLLUP
761 : ROUTINE ROUTINES ROW ROWS RULE
762 :
763 : SAVEPOINT SCALAR SCHEMA SCHEMAS SCROLL SEARCH SECOND_P SECURITY SELECT
764 : SEQUENCE SEQUENCES
765 : SERIALIZABLE SERVER SESSION SESSION_USER SET SETS SETOF SHARE SHOW
766 : SIMILAR SIMPLE SKIP SMALLINT SNAPSHOT SOME SOURCE SQL_P STABLE STANDALONE_P
767 : START STATEMENT STATISTICS STDIN STDOUT STORAGE STORED STRICT_P STRING_P STRIP_P
768 : SUBSCRIPTION SUBSTRING SUPPORT SYMMETRIC SYSID SYSTEM_P SYSTEM_USER
769 :
770 : TABLE TABLES TABLESAMPLE TABLESPACE TARGET TEMP TEMPLATE TEMPORARY TEXT_P THEN
771 : TIES TIME TIMESTAMP TO TRAILING TRANSACTION TRANSFORM
772 : TREAT TRIGGER TRIM TRUE_P
773 : TRUNCATE TRUSTED TYPE_P TYPES_P
774 :
775 : UESCAPE UNBOUNDED UNCONDITIONAL UNCOMMITTED UNENCRYPTED UNION UNIQUE UNKNOWN
776 : UNLISTEN UNLOGGED UNTIL UPDATE USER USING
777 :
778 : VACUUM VALID VALIDATE VALIDATOR VALUE_P VALUES VARCHAR VARIADIC VARYING
779 : VERBOSE VERSION_P VIEW VIEWS VOLATILE
780 :
781 : WHEN WHERE WHITESPACE_P WINDOW WITH WITHIN WITHOUT WORK WRAPPER WRITE
782 :
783 : XML_P XMLATTRIBUTES XMLCONCAT XMLELEMENT XMLEXISTS XMLFOREST XMLNAMESPACES
784 : XMLPARSE XMLPI XMLROOT XMLSERIALIZE XMLTABLE
785 :
786 : YEAR_P YES_P
787 :
788 : ZONE
789 :
790 : /*
791 : * The grammar thinks these are keywords, but they are not in the kwlist.h
792 : * list and so can never be entered directly. The filter in parser.c
793 : * creates these tokens when required (based on looking one token ahead).
794 : *
795 : * NOT_LA exists so that productions such as NOT LIKE can be given the same
796 : * precedence as LIKE; otherwise they'd effectively have the same precedence
797 : * as NOT, at least with respect to their left-hand subexpression.
798 : * FORMAT_LA, NULLS_LA, WITH_LA, and WITHOUT_LA are needed to make the grammar
799 : * LALR(1).
800 : */
801 : %token FORMAT_LA NOT_LA NULLS_LA WITH_LA WITHOUT_LA
802 :
803 : /*
804 : * The grammar likewise thinks these tokens are keywords, but they are never
805 : * generated by the scanner. Rather, they can be injected by parser.c as
806 : * the initial token of the string (using the lookahead-token mechanism
807 : * implemented there). This provides a way to tell the grammar to parse
808 : * something other than the usual list of SQL commands.
809 : */
810 : %token MODE_TYPE_NAME
811 : %token MODE_PLPGSQL_EXPR
812 : %token MODE_PLPGSQL_ASSIGN1
813 : %token MODE_PLPGSQL_ASSIGN2
814 : %token MODE_PLPGSQL_ASSIGN3
815 :
816 :
817 : /* Precedence: lowest to highest */
818 : %left UNION EXCEPT
819 : %left INTERSECT
820 : %left OR
821 : %left AND
822 : %right NOT
823 : %nonassoc IS ISNULL NOTNULL /* IS sets precedence for IS NULL, etc */
824 : %nonassoc '<' '>' '=' LESS_EQUALS GREATER_EQUALS NOT_EQUALS
825 : %nonassoc BETWEEN IN_P LIKE ILIKE SIMILAR NOT_LA
826 : %nonassoc ESCAPE /* ESCAPE must be just above LIKE/ILIKE/SIMILAR */
827 :
828 : /*
829 : * Sometimes it is necessary to assign precedence to keywords that are not
830 : * really part of the operator hierarchy, in order to resolve grammar
831 : * ambiguities. It's best to avoid doing so whenever possible, because such
832 : * assignments have global effect and may hide ambiguities besides the one
833 : * you intended to solve. (Attaching a precedence to a single rule with
834 : * %prec is far safer and should be preferred.) If you must give precedence
835 : * to a new keyword, try very hard to give it the same precedence as IDENT.
836 : * If the keyword has IDENT's precedence then it clearly acts the same as
837 : * non-keywords and other similar keywords, thus reducing the risk of
838 : * unexpected precedence effects.
839 : *
840 : * We used to need to assign IDENT an explicit precedence just less than Op,
841 : * to support target_el without AS. While that's not really necessary since
842 : * we removed postfix operators, we continue to do so because it provides a
843 : * reference point for a precedence level that we can assign to other
844 : * keywords that lack a natural precedence level.
845 : *
846 : * We need to do this for PARTITION, RANGE, ROWS, and GROUPS to support
847 : * opt_existing_window_name (see comment there).
848 : *
849 : * The frame_bound productions UNBOUNDED PRECEDING and UNBOUNDED FOLLOWING
850 : * are even messier: since UNBOUNDED is an unreserved keyword (per spec!),
851 : * there is no principled way to distinguish these from the productions
852 : * a_expr PRECEDING/FOLLOWING. We hack this up by giving UNBOUNDED slightly
853 : * lower precedence than PRECEDING and FOLLOWING. At present this doesn't
854 : * appear to cause UNBOUNDED to be treated differently from other unreserved
855 : * keywords anywhere else in the grammar, but it's definitely risky. We can
856 : * blame any funny behavior of UNBOUNDED on the SQL standard, though.
857 : *
858 : * To support CUBE and ROLLUP in GROUP BY without reserving them, we give them
859 : * an explicit priority lower than '(', so that a rule with CUBE '(' will shift
860 : * rather than reducing a conflicting rule that takes CUBE as a function name.
861 : * Using the same precedence as IDENT seems right for the reasons given above.
862 : *
863 : * SET is likewise assigned the same precedence as IDENT, to support the
864 : * relation_expr_opt_alias production (see comment there).
865 : *
866 : * KEYS, OBJECT_P, SCALAR, VALUE_P, WITH, and WITHOUT are similarly assigned
867 : * the same precedence as IDENT. This allows resolving conflicts in the
868 : * json_predicate_type_constraint and json_key_uniqueness_constraint_opt
869 : * productions (see comments there).
870 : *
871 : * Like the UNBOUNDED PRECEDING/FOLLOWING case, NESTED is assigned a lower
872 : * precedence than PATH to fix ambiguity in the json_table production.
873 : */
874 : %nonassoc UNBOUNDED NESTED /* ideally would have same precedence as IDENT */
875 : %nonassoc IDENT PARTITION RANGE ROWS GROUPS PRECEDING FOLLOWING CUBE ROLLUP
876 : SET KEYS OBJECT_P SCALAR VALUE_P WITH WITHOUT PATH
877 : %left Op OPERATOR /* multi-character ops and user-defined operators */
878 : %left '+' '-'
879 : %left '*' '/' '%'
880 : %left '^'
881 : /* Unary Operators */
882 : %left AT /* sets precedence for AT TIME ZONE, AT LOCAL */
883 : %left COLLATE
884 : %right UMINUS
885 : %left '[' ']'
886 : %left '(' ')'
887 : %left TYPECAST
888 : %left '.'
889 : /*
890 : * These might seem to be low-precedence, but actually they are not part
891 : * of the arithmetic hierarchy at all in their use as JOIN operators.
892 : * We make them high-precedence to support their use as function names.
893 : * They wouldn't be given a precedence at all, were it not that we need
894 : * left-associativity among the JOIN rules themselves.
895 : */
896 : %left JOIN CROSS LEFT FULL RIGHT INNER_P NATURAL
897 :
898 : %%
899 :
900 : /*
901 : * The target production for the whole parse.
902 : *
903 : * Ordinarily we parse a list of statements, but if we see one of the
904 : * special MODE_XXX symbols as first token, we parse something else.
905 : * The options here correspond to enum RawParseMode, which see for details.
906 : */
907 : parse_toplevel:
908 : stmtmulti
909 : {
910 708886 : pg_yyget_extra(yyscanner)->parsetree = $1;
911 : (void) yynerrs; /* suppress compiler warning */
912 : }
913 : | MODE_TYPE_NAME Typename
914 : {
915 9538 : pg_yyget_extra(yyscanner)->parsetree = list_make1($2);
916 : }
917 : | MODE_PLPGSQL_EXPR PLpgSQL_Expr
918 : {
919 32444 : pg_yyget_extra(yyscanner)->parsetree =
920 32444 : list_make1(makeRawStmt($2, @2));
921 : }
922 : | MODE_PLPGSQL_ASSIGN1 PLAssignStmt
923 : {
924 6202 : PLAssignStmt *n = (PLAssignStmt *) $2;
925 :
926 6202 : n->nnames = 1;
927 6202 : pg_yyget_extra(yyscanner)->parsetree =
928 6202 : list_make1(makeRawStmt((Node *) n, @2));
929 : }
930 : | MODE_PLPGSQL_ASSIGN2 PLAssignStmt
931 : {
932 620 : PLAssignStmt *n = (PLAssignStmt *) $2;
933 :
934 620 : n->nnames = 2;
935 620 : pg_yyget_extra(yyscanner)->parsetree =
936 620 : list_make1(makeRawStmt((Node *) n, @2));
937 : }
938 : | MODE_PLPGSQL_ASSIGN3 PLAssignStmt
939 : {
940 28 : PLAssignStmt *n = (PLAssignStmt *) $2;
941 :
942 28 : n->nnames = 3;
943 28 : pg_yyget_extra(yyscanner)->parsetree =
944 28 : list_make1(makeRawStmt((Node *) n, @2));
945 : }
946 : ;
947 :
948 : /*
949 : * At top level, we wrap each stmt with a RawStmt node carrying start location
950 : * and length of the stmt's text.
951 : * We also take care to discard empty statements entirely (which among other
952 : * things dodges the problem of assigning them a location).
953 : */
954 : stmtmulti: stmtmulti ';' toplevel_stmt
955 : {
956 563200 : if ($1 != NIL)
957 : {
958 : /* update length of previous stmt */
959 563104 : updateRawStmtEnd(llast_node(RawStmt, $1), @2);
960 : }
961 563200 : if ($3 != NULL)
962 49678 : $$ = lappend($1, makeRawStmt($3, @3));
963 : else
964 513522 : $$ = $1;
965 : }
966 : | toplevel_stmt
967 : {
968 708894 : if ($1 != NULL)
969 708416 : $$ = list_make1(makeRawStmt($1, @1));
970 : else
971 478 : $$ = NIL;
972 : }
973 : ;
974 :
975 : /*
976 : * toplevel_stmt includes BEGIN and END. stmt does not include them, because
977 : * those words have different meanings in function bodies.
978 : */
979 : toplevel_stmt:
980 : stmt
981 : | TransactionStmtLegacy
982 : ;
983 :
984 : stmt:
985 : AlterEventTrigStmt
986 : | AlterCollationStmt
987 : | AlterDatabaseStmt
988 : | AlterDatabaseSetStmt
989 : | AlterDefaultPrivilegesStmt
990 : | AlterDomainStmt
991 : | AlterEnumStmt
992 : | AlterExtensionStmt
993 : | AlterExtensionContentsStmt
994 : | AlterFdwStmt
995 : | AlterForeignServerStmt
996 : | AlterFunctionStmt
997 : | AlterGroupStmt
998 : | AlterObjectDependsStmt
999 : | AlterObjectSchemaStmt
1000 : | AlterOwnerStmt
1001 : | AlterOperatorStmt
1002 : | AlterTypeStmt
1003 : | AlterPolicyStmt
1004 : | AlterSeqStmt
1005 : | AlterSystemStmt
1006 : | AlterTableStmt
1007 : | AlterTblSpcStmt
1008 : | AlterCompositeTypeStmt
1009 : | AlterPublicationStmt
1010 : | AlterRoleSetStmt
1011 : | AlterRoleStmt
1012 : | AlterSubscriptionStmt
1013 : | AlterStatsStmt
1014 : | AlterTSConfigurationStmt
1015 : | AlterTSDictionaryStmt
1016 : | AlterUserMappingStmt
1017 : | AnalyzeStmt
1018 : | CallStmt
1019 : | CheckPointStmt
1020 : | ClosePortalStmt
1021 : | ClusterStmt
1022 : | CommentStmt
1023 : | ConstraintsSetStmt
1024 : | CopyStmt
1025 : | CreateAmStmt
1026 : | CreateAsStmt
1027 : | CreateAssertionStmt
1028 : | CreateCastStmt
1029 : | CreateConversionStmt
1030 : | CreateDomainStmt
1031 : | CreateExtensionStmt
1032 : | CreateFdwStmt
1033 : | CreateForeignServerStmt
1034 : | CreateForeignTableStmt
1035 : | CreateFunctionStmt
1036 : | CreateGroupStmt
1037 : | CreateMatViewStmt
1038 : | CreateOpClassStmt
1039 : | CreateOpFamilyStmt
1040 : | CreatePublicationStmt
1041 : | AlterOpFamilyStmt
1042 : | CreatePolicyStmt
1043 : | CreatePLangStmt
1044 : | CreateSchemaStmt
1045 : | CreateSeqStmt
1046 : | CreateStmt
1047 : | CreateSubscriptionStmt
1048 : | CreateStatsStmt
1049 : | CreateTableSpaceStmt
1050 : | CreateTransformStmt
1051 : | CreateTrigStmt
1052 : | CreateEventTrigStmt
1053 : | CreateRoleStmt
1054 : | CreateUserStmt
1055 : | CreateUserMappingStmt
1056 : | CreatedbStmt
1057 : | DeallocateStmt
1058 : | DeclareCursorStmt
1059 : | DefineStmt
1060 : | DeleteStmt
1061 : | DiscardStmt
1062 : | DoStmt
1063 : | DropCastStmt
1064 : | DropOpClassStmt
1065 : | DropOpFamilyStmt
1066 : | DropOwnedStmt
1067 : | DropStmt
1068 : | DropSubscriptionStmt
1069 : | DropTableSpaceStmt
1070 : | DropTransformStmt
1071 : | DropRoleStmt
1072 : | DropUserMappingStmt
1073 : | DropdbStmt
1074 : | ExecuteStmt
1075 : | ExplainStmt
1076 : | FetchStmt
1077 : | GrantStmt
1078 : | GrantRoleStmt
1079 : | ImportForeignSchemaStmt
1080 : | IndexStmt
1081 : | InsertStmt
1082 : | ListenStmt
1083 : | RefreshMatViewStmt
1084 : | LoadStmt
1085 : | LockStmt
1086 : | MergeStmt
1087 : | NotifyStmt
1088 : | PrepareStmt
1089 : | ReassignOwnedStmt
1090 : | ReindexStmt
1091 : | RemoveAggrStmt
1092 : | RemoveFuncStmt
1093 : | RemoveOperStmt
1094 : | RenameStmt
1095 : | RevokeStmt
1096 : | RevokeRoleStmt
1097 : | RuleStmt
1098 : | SecLabelStmt
1099 : | SelectStmt
1100 : | TransactionStmt
1101 : | TruncateStmt
1102 : | UnlistenStmt
1103 : | UpdateStmt
1104 : | VacuumStmt
1105 : | VariableResetStmt
1106 : | VariableSetStmt
1107 : | VariableShowStmt
1108 : | ViewStmt
1109 : | /*EMPTY*/
1110 514018 : { $$ = NULL; }
1111 : ;
1112 :
1113 : /*
1114 : * Generic supporting productions for DDL
1115 : */
1116 : opt_single_name:
1117 5130 : ColId { $$ = $1; }
1118 1454 : | /* EMPTY */ { $$ = NULL; }
1119 : ;
1120 :
1121 : opt_qualified_name:
1122 1710 : any_name { $$ = $1; }
1123 14576 : | /*EMPTY*/ { $$ = NIL; }
1124 : ;
1125 :
1126 : opt_concurrently:
1127 986 : CONCURRENTLY { $$ = true; }
1128 7290 : | /*EMPTY*/ { $$ = false; }
1129 : ;
1130 :
1131 : opt_drop_behavior:
1132 1882 : CASCADE { $$ = DROP_CASCADE; }
1133 170 : | RESTRICT { $$ = DROP_RESTRICT; }
1134 36088 : | /* EMPTY */ { $$ = DROP_RESTRICT; /* default */ }
1135 : ;
1136 :
1137 : /*****************************************************************************
1138 : *
1139 : * CALL statement
1140 : *
1141 : *****************************************************************************/
1142 :
1143 : CallStmt: CALL func_application
1144 : {
1145 602 : CallStmt *n = makeNode(CallStmt);
1146 :
1147 602 : n->funccall = castNode(FuncCall, $2);
1148 602 : $$ = (Node *) n;
1149 : }
1150 : ;
1151 :
1152 : /*****************************************************************************
1153 : *
1154 : * Create a new Postgres DBMS role
1155 : *
1156 : *****************************************************************************/
1157 :
1158 : CreateRoleStmt:
1159 : CREATE ROLE RoleId opt_with OptRoleList
1160 : {
1161 1286 : CreateRoleStmt *n = makeNode(CreateRoleStmt);
1162 :
1163 1286 : n->stmt_type = ROLESTMT_ROLE;
1164 1286 : n->role = $3;
1165 1286 : n->options = $5;
1166 1286 : $$ = (Node *) n;
1167 : }
1168 : ;
1169 :
1170 :
1171 : opt_with: WITH
1172 : | WITH_LA
1173 : | /*EMPTY*/
1174 : ;
1175 :
1176 : /*
1177 : * Options for CREATE ROLE and ALTER ROLE (also used by CREATE/ALTER USER
1178 : * for backwards compatibility). Note: the only option required by SQL99
1179 : * is "WITH ADMIN name".
1180 : */
1181 : OptRoleList:
1182 1170 : OptRoleList CreateOptRoleElem { $$ = lappend($1, $2); }
1183 1752 : | /* EMPTY */ { $$ = NIL; }
1184 : ;
1185 :
1186 : AlterOptRoleList:
1187 580 : AlterOptRoleList AlterOptRoleElem { $$ = lappend($1, $2); }
1188 400 : | /* EMPTY */ { $$ = NIL; }
1189 : ;
1190 :
1191 : AlterOptRoleElem:
1192 : PASSWORD Sconst
1193 : {
1194 174 : $$ = makeDefElem("password",
1195 174 : (Node *) makeString($2), @1);
1196 : }
1197 : | PASSWORD NULL_P
1198 : {
1199 12 : $$ = makeDefElem("password", NULL, @1);
1200 : }
1201 : | ENCRYPTED PASSWORD Sconst
1202 : {
1203 : /*
1204 : * These days, passwords are always stored in encrypted
1205 : * form, so there is no difference between PASSWORD and
1206 : * ENCRYPTED PASSWORD.
1207 : */
1208 16 : $$ = makeDefElem("password",
1209 16 : (Node *) makeString($3), @1);
1210 : }
1211 : | UNENCRYPTED PASSWORD Sconst
1212 : {
1213 0 : ereport(ERROR,
1214 : (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
1215 : errmsg("UNENCRYPTED PASSWORD is no longer supported"),
1216 : errhint("Remove UNENCRYPTED to store the password in encrypted form instead."),
1217 : parser_errposition(@1)));
1218 : }
1219 : | INHERIT
1220 : {
1221 86 : $$ = makeDefElem("inherit", (Node *) makeBoolean(true), @1);
1222 : }
1223 : | CONNECTION LIMIT SignedIconst
1224 : {
1225 24 : $$ = makeDefElem("connectionlimit", (Node *) makeInteger($3), @1);
1226 : }
1227 : | VALID UNTIL Sconst
1228 : {
1229 2 : $$ = makeDefElem("validUntil", (Node *) makeString($3), @1);
1230 : }
1231 : /* Supported but not documented for roles, for use by ALTER GROUP. */
1232 : | USER role_list
1233 : {
1234 6 : $$ = makeDefElem("rolemembers", (Node *) $2, @1);
1235 : }
1236 : | IDENT
1237 : {
1238 : /*
1239 : * We handle identifiers that aren't parser keywords with
1240 : * the following special-case codes, to avoid bloating the
1241 : * size of the main parser.
1242 : */
1243 1286 : if (strcmp($1, "superuser") == 0)
1244 180 : $$ = makeDefElem("superuser", (Node *) makeBoolean(true), @1);
1245 1106 : else if (strcmp($1, "nosuperuser") == 0)
1246 100 : $$ = makeDefElem("superuser", (Node *) makeBoolean(false), @1);
1247 1006 : else if (strcmp($1, "createrole") == 0)
1248 92 : $$ = makeDefElem("createrole", (Node *) makeBoolean(true), @1);
1249 914 : else if (strcmp($1, "nocreaterole") == 0)
1250 38 : $$ = makeDefElem("createrole", (Node *) makeBoolean(false), @1);
1251 876 : else if (strcmp($1, "replication") == 0)
1252 120 : $$ = makeDefElem("isreplication", (Node *) makeBoolean(true), @1);
1253 756 : else if (strcmp($1, "noreplication") == 0)
1254 96 : $$ = makeDefElem("isreplication", (Node *) makeBoolean(false), @1);
1255 660 : else if (strcmp($1, "createdb") == 0)
1256 82 : $$ = makeDefElem("createdb", (Node *) makeBoolean(true), @1);
1257 578 : else if (strcmp($1, "nocreatedb") == 0)
1258 46 : $$ = makeDefElem("createdb", (Node *) makeBoolean(false), @1);
1259 532 : else if (strcmp($1, "login") == 0)
1260 270 : $$ = makeDefElem("canlogin", (Node *) makeBoolean(true), @1);
1261 262 : else if (strcmp($1, "nologin") == 0)
1262 86 : $$ = makeDefElem("canlogin", (Node *) makeBoolean(false), @1);
1263 176 : else if (strcmp($1, "bypassrls") == 0)
1264 72 : $$ = makeDefElem("bypassrls", (Node *) makeBoolean(true), @1);
1265 104 : else if (strcmp($1, "nobypassrls") == 0)
1266 68 : $$ = makeDefElem("bypassrls", (Node *) makeBoolean(false), @1);
1267 36 : else if (strcmp($1, "noinherit") == 0)
1268 : {
1269 : /*
1270 : * Note that INHERIT is a keyword, so it's handled by main parser, but
1271 : * NOINHERIT is handled here.
1272 : */
1273 36 : $$ = makeDefElem("inherit", (Node *) makeBoolean(false), @1);
1274 : }
1275 : else
1276 0 : ereport(ERROR,
1277 : (errcode(ERRCODE_SYNTAX_ERROR),
1278 : errmsg("unrecognized role option \"%s\"", $1),
1279 : parser_errposition(@1)));
1280 : }
1281 : ;
1282 :
1283 : CreateOptRoleElem:
1284 1026 : AlterOptRoleElem { $$ = $1; }
1285 : /* The following are not supported by ALTER ROLE/USER/GROUP */
1286 : | SYSID Iconst
1287 : {
1288 6 : $$ = makeDefElem("sysid", (Node *) makeInteger($2), @1);
1289 : }
1290 : | ADMIN role_list
1291 : {
1292 22 : $$ = makeDefElem("adminmembers", (Node *) $2, @1);
1293 : }
1294 : | ROLE role_list
1295 : {
1296 16 : $$ = makeDefElem("rolemembers", (Node *) $2, @1);
1297 : }
1298 : | IN_P ROLE role_list
1299 : {
1300 100 : $$ = makeDefElem("addroleto", (Node *) $3, @1);
1301 : }
1302 : | IN_P GROUP_P role_list
1303 : {
1304 0 : $$ = makeDefElem("addroleto", (Node *) $3, @1);
1305 : }
1306 : ;
1307 :
1308 :
1309 : /*****************************************************************************
1310 : *
1311 : * Create a new Postgres DBMS user (role with implied login ability)
1312 : *
1313 : *****************************************************************************/
1314 :
1315 : CreateUserStmt:
1316 : CREATE USER RoleId opt_with OptRoleList
1317 : {
1318 442 : CreateRoleStmt *n = makeNode(CreateRoleStmt);
1319 :
1320 442 : n->stmt_type = ROLESTMT_USER;
1321 442 : n->role = $3;
1322 442 : n->options = $5;
1323 442 : $$ = (Node *) n;
1324 : }
1325 : ;
1326 :
1327 :
1328 : /*****************************************************************************
1329 : *
1330 : * Alter a postgresql DBMS role
1331 : *
1332 : *****************************************************************************/
1333 :
1334 : AlterRoleStmt:
1335 : ALTER ROLE RoleSpec opt_with AlterOptRoleList
1336 : {
1337 312 : AlterRoleStmt *n = makeNode(AlterRoleStmt);
1338 :
1339 312 : n->role = $3;
1340 312 : n->action = +1; /* add, if there are members */
1341 312 : n->options = $5;
1342 312 : $$ = (Node *) n;
1343 : }
1344 : | ALTER USER RoleSpec opt_with AlterOptRoleList
1345 : {
1346 88 : AlterRoleStmt *n = makeNode(AlterRoleStmt);
1347 :
1348 88 : n->role = $3;
1349 88 : n->action = +1; /* add, if there are members */
1350 88 : n->options = $5;
1351 88 : $$ = (Node *) n;
1352 : }
1353 : ;
1354 :
1355 : opt_in_database:
1356 86 : /* EMPTY */ { $$ = NULL; }
1357 0 : | IN_P DATABASE name { $$ = $3; }
1358 : ;
1359 :
1360 : AlterRoleSetStmt:
1361 : ALTER ROLE RoleSpec opt_in_database SetResetClause
1362 : {
1363 48 : AlterRoleSetStmt *n = makeNode(AlterRoleSetStmt);
1364 :
1365 48 : n->role = $3;
1366 48 : n->database = $4;
1367 48 : n->setstmt = $5;
1368 48 : $$ = (Node *) n;
1369 : }
1370 : | ALTER ROLE ALL opt_in_database SetResetClause
1371 : {
1372 4 : AlterRoleSetStmt *n = makeNode(AlterRoleSetStmt);
1373 :
1374 4 : n->role = NULL;
1375 4 : n->database = $4;
1376 4 : n->setstmt = $5;
1377 4 : $$ = (Node *) n;
1378 : }
1379 : | ALTER USER RoleSpec opt_in_database SetResetClause
1380 : {
1381 26 : AlterRoleSetStmt *n = makeNode(AlterRoleSetStmt);
1382 :
1383 26 : n->role = $3;
1384 26 : n->database = $4;
1385 26 : n->setstmt = $5;
1386 26 : $$ = (Node *) n;
1387 : }
1388 : | ALTER USER ALL opt_in_database SetResetClause
1389 : {
1390 4 : AlterRoleSetStmt *n = makeNode(AlterRoleSetStmt);
1391 :
1392 4 : n->role = NULL;
1393 4 : n->database = $4;
1394 4 : n->setstmt = $5;
1395 4 : $$ = (Node *) n;
1396 : }
1397 : ;
1398 :
1399 :
1400 : /*****************************************************************************
1401 : *
1402 : * Drop a postgresql DBMS role
1403 : *
1404 : * XXX Ideally this would have CASCADE/RESTRICT options, but a role
1405 : * might own objects in multiple databases, and there is presently no way to
1406 : * implement cascading to other databases. So we always behave as RESTRICT.
1407 : *****************************************************************************/
1408 :
1409 : DropRoleStmt:
1410 : DROP ROLE role_list
1411 : {
1412 1060 : DropRoleStmt *n = makeNode(DropRoleStmt);
1413 :
1414 1060 : n->missing_ok = false;
1415 1060 : n->roles = $3;
1416 1060 : $$ = (Node *) n;
1417 : }
1418 : | DROP ROLE IF_P EXISTS role_list
1419 : {
1420 134 : DropRoleStmt *n = makeNode(DropRoleStmt);
1421 :
1422 134 : n->missing_ok = true;
1423 134 : n->roles = $5;
1424 134 : $$ = (Node *) n;
1425 : }
1426 : | DROP USER role_list
1427 : {
1428 398 : DropRoleStmt *n = makeNode(DropRoleStmt);
1429 :
1430 398 : n->missing_ok = false;
1431 398 : n->roles = $3;
1432 398 : $$ = (Node *) n;
1433 : }
1434 : | DROP USER IF_P EXISTS role_list
1435 : {
1436 36 : DropRoleStmt *n = makeNode(DropRoleStmt);
1437 :
1438 36 : n->roles = $5;
1439 36 : n->missing_ok = true;
1440 36 : $$ = (Node *) n;
1441 : }
1442 : | DROP GROUP_P role_list
1443 : {
1444 36 : DropRoleStmt *n = makeNode(DropRoleStmt);
1445 :
1446 36 : n->missing_ok = false;
1447 36 : n->roles = $3;
1448 36 : $$ = (Node *) n;
1449 : }
1450 : | DROP GROUP_P IF_P EXISTS role_list
1451 : {
1452 6 : DropRoleStmt *n = makeNode(DropRoleStmt);
1453 :
1454 6 : n->missing_ok = true;
1455 6 : n->roles = $5;
1456 6 : $$ = (Node *) n;
1457 : }
1458 : ;
1459 :
1460 :
1461 : /*****************************************************************************
1462 : *
1463 : * Create a postgresql group (role without login ability)
1464 : *
1465 : *****************************************************************************/
1466 :
1467 : CreateGroupStmt:
1468 : CREATE GROUP_P RoleId opt_with OptRoleList
1469 : {
1470 24 : CreateRoleStmt *n = makeNode(CreateRoleStmt);
1471 :
1472 24 : n->stmt_type = ROLESTMT_GROUP;
1473 24 : n->role = $3;
1474 24 : n->options = $5;
1475 24 : $$ = (Node *) n;
1476 : }
1477 : ;
1478 :
1479 :
1480 : /*****************************************************************************
1481 : *
1482 : * Alter a postgresql group
1483 : *
1484 : *****************************************************************************/
1485 :
1486 : AlterGroupStmt:
1487 : ALTER GROUP_P RoleSpec add_drop USER role_list
1488 : {
1489 30 : AlterRoleStmt *n = makeNode(AlterRoleStmt);
1490 :
1491 30 : n->role = $3;
1492 30 : n->action = $4;
1493 30 : n->options = list_make1(makeDefElem("rolemembers",
1494 : (Node *) $6, @6));
1495 30 : $$ = (Node *) n;
1496 : }
1497 : ;
1498 :
1499 80 : add_drop: ADD_P { $$ = +1; }
1500 172 : | DROP { $$ = -1; }
1501 : ;
1502 :
1503 :
1504 : /*****************************************************************************
1505 : *
1506 : * Manipulate a schema
1507 : *
1508 : *****************************************************************************/
1509 :
1510 : CreateSchemaStmt:
1511 : CREATE SCHEMA opt_single_name AUTHORIZATION RoleSpec OptSchemaEltList
1512 : {
1513 158 : CreateSchemaStmt *n = makeNode(CreateSchemaStmt);
1514 :
1515 : /* One can omit the schema name or the authorization id. */
1516 158 : n->schemaname = $3;
1517 158 : n->authrole = $5;
1518 158 : n->schemaElts = $6;
1519 158 : n->if_not_exists = false;
1520 158 : $$ = (Node *) n;
1521 : }
1522 : | CREATE SCHEMA ColId OptSchemaEltList
1523 : {
1524 814 : CreateSchemaStmt *n = makeNode(CreateSchemaStmt);
1525 :
1526 : /* ...but not both */
1527 814 : n->schemaname = $3;
1528 814 : n->authrole = NULL;
1529 814 : n->schemaElts = $4;
1530 814 : n->if_not_exists = false;
1531 814 : $$ = (Node *) n;
1532 : }
1533 : | CREATE SCHEMA IF_P NOT EXISTS opt_single_name AUTHORIZATION RoleSpec OptSchemaEltList
1534 : {
1535 18 : CreateSchemaStmt *n = makeNode(CreateSchemaStmt);
1536 :
1537 : /* schema name can be omitted here, too */
1538 18 : n->schemaname = $6;
1539 18 : n->authrole = $8;
1540 18 : if ($9 != NIL)
1541 0 : ereport(ERROR,
1542 : (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
1543 : errmsg("CREATE SCHEMA IF NOT EXISTS cannot include schema elements"),
1544 : parser_errposition(@9)));
1545 18 : n->schemaElts = $9;
1546 18 : n->if_not_exists = true;
1547 18 : $$ = (Node *) n;
1548 : }
1549 : | CREATE SCHEMA IF_P NOT EXISTS ColId OptSchemaEltList
1550 : {
1551 34 : CreateSchemaStmt *n = makeNode(CreateSchemaStmt);
1552 :
1553 : /* ...but not here */
1554 34 : n->schemaname = $6;
1555 34 : n->authrole = NULL;
1556 34 : if ($7 != NIL)
1557 6 : ereport(ERROR,
1558 : (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
1559 : errmsg("CREATE SCHEMA IF NOT EXISTS cannot include schema elements"),
1560 : parser_errposition(@7)));
1561 28 : n->schemaElts = $7;
1562 28 : n->if_not_exists = true;
1563 28 : $$ = (Node *) n;
1564 : }
1565 : ;
1566 :
1567 : OptSchemaEltList:
1568 : OptSchemaEltList schema_stmt
1569 : {
1570 546 : $$ = lappend($1, $2);
1571 : }
1572 : | /* EMPTY */
1573 1024 : { $$ = NIL; }
1574 : ;
1575 :
1576 : /*
1577 : * schema_stmt are the ones that can show up inside a CREATE SCHEMA
1578 : * statement (in addition to by themselves).
1579 : */
1580 : schema_stmt:
1581 : CreateStmt
1582 : | IndexStmt
1583 : | CreateSeqStmt
1584 : | CreateTrigStmt
1585 : | GrantStmt
1586 : | ViewStmt
1587 : ;
1588 :
1589 :
1590 : /*****************************************************************************
1591 : *
1592 : * Set PG internal variable
1593 : * SET name TO 'var_value'
1594 : * Include SQL syntax (thomas 1997-10-22):
1595 : * SET TIME ZONE 'var_value'
1596 : *
1597 : *****************************************************************************/
1598 :
1599 : VariableSetStmt:
1600 : SET set_rest
1601 : {
1602 18966 : VariableSetStmt *n = $2;
1603 :
1604 18966 : n->is_local = false;
1605 18966 : $$ = (Node *) n;
1606 : }
1607 : | SET LOCAL set_rest
1608 : {
1609 1184 : VariableSetStmt *n = $3;
1610 :
1611 1184 : n->is_local = true;
1612 1184 : $$ = (Node *) n;
1613 : }
1614 : | SET SESSION set_rest
1615 : {
1616 84 : VariableSetStmt *n = $3;
1617 :
1618 84 : n->is_local = false;
1619 84 : $$ = (Node *) n;
1620 : }
1621 : ;
1622 :
1623 : set_rest:
1624 : TRANSACTION transaction_mode_list
1625 : {
1626 520 : VariableSetStmt *n = makeNode(VariableSetStmt);
1627 :
1628 520 : n->kind = VAR_SET_MULTI;
1629 520 : n->name = "TRANSACTION";
1630 520 : n->args = $2;
1631 520 : n->jumble_args = true;
1632 520 : n->location = -1;
1633 520 : $$ = n;
1634 : }
1635 : | SESSION CHARACTERISTICS AS TRANSACTION transaction_mode_list
1636 : {
1637 18 : VariableSetStmt *n = makeNode(VariableSetStmt);
1638 :
1639 18 : n->kind = VAR_SET_MULTI;
1640 18 : n->name = "SESSION CHARACTERISTICS";
1641 18 : n->args = $5;
1642 18 : n->jumble_args = true;
1643 18 : n->location = -1;
1644 18 : $$ = n;
1645 : }
1646 : | set_rest_more
1647 : ;
1648 :
1649 : generic_set:
1650 : var_name TO var_list
1651 : {
1652 4554 : VariableSetStmt *n = makeNode(VariableSetStmt);
1653 :
1654 4554 : n->kind = VAR_SET_VALUE;
1655 4554 : n->name = $1;
1656 4554 : n->args = $3;
1657 4554 : n->location = @3;
1658 4554 : $$ = n;
1659 : }
1660 : | var_name '=' var_list
1661 : {
1662 12796 : VariableSetStmt *n = makeNode(VariableSetStmt);
1663 :
1664 12796 : n->kind = VAR_SET_VALUE;
1665 12796 : n->name = $1;
1666 12796 : n->args = $3;
1667 12796 : n->location = @3;
1668 12796 : $$ = n;
1669 : }
1670 : | var_name TO DEFAULT
1671 : {
1672 130 : VariableSetStmt *n = makeNode(VariableSetStmt);
1673 :
1674 130 : n->kind = VAR_SET_DEFAULT;
1675 130 : n->name = $1;
1676 130 : n->location = -1;
1677 130 : $$ = n;
1678 : }
1679 : | var_name '=' DEFAULT
1680 : {
1681 10 : VariableSetStmt *n = makeNode(VariableSetStmt);
1682 :
1683 10 : n->kind = VAR_SET_DEFAULT;
1684 10 : n->name = $1;
1685 10 : n->location = -1;
1686 10 : $$ = n;
1687 : }
1688 : ;
1689 :
1690 : set_rest_more: /* Generic SET syntaxes: */
1691 17378 : generic_set {$$ = $1;}
1692 : | var_name FROM CURRENT_P
1693 : {
1694 4 : VariableSetStmt *n = makeNode(VariableSetStmt);
1695 :
1696 4 : n->kind = VAR_SET_CURRENT;
1697 4 : n->name = $1;
1698 4 : n->location = -1;
1699 4 : $$ = n;
1700 : }
1701 : /* Special syntaxes mandated by SQL standard: */
1702 : | TIME ZONE zone_value
1703 : {
1704 104 : VariableSetStmt *n = makeNode(VariableSetStmt);
1705 :
1706 104 : n->kind = VAR_SET_VALUE;
1707 104 : n->name = "timezone";
1708 104 : n->location = -1;
1709 104 : n->jumble_args = true;
1710 104 : if ($3 != NULL)
1711 88 : n->args = list_make1($3);
1712 : else
1713 16 : n->kind = VAR_SET_DEFAULT;
1714 104 : $$ = n;
1715 : }
1716 : | CATALOG_P Sconst
1717 : {
1718 0 : ereport(ERROR,
1719 : (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
1720 : errmsg("current database cannot be changed"),
1721 : parser_errposition(@2)));
1722 : $$ = NULL; /*not reached*/
1723 : }
1724 : | SCHEMA Sconst
1725 : {
1726 4 : VariableSetStmt *n = makeNode(VariableSetStmt);
1727 :
1728 4 : n->kind = VAR_SET_VALUE;
1729 4 : n->name = "search_path";
1730 4 : n->args = list_make1(makeStringConst($2, @2));
1731 4 : n->location = @2;
1732 4 : $$ = n;
1733 : }
1734 : | NAMES opt_encoding
1735 : {
1736 0 : VariableSetStmt *n = makeNode(VariableSetStmt);
1737 :
1738 0 : n->kind = VAR_SET_VALUE;
1739 0 : n->name = "client_encoding";
1740 0 : n->location = @2;
1741 0 : if ($2 != NULL)
1742 0 : n->args = list_make1(makeStringConst($2, @2));
1743 : else
1744 0 : n->kind = VAR_SET_DEFAULT;
1745 0 : $$ = n;
1746 : }
1747 : | ROLE NonReservedWord_or_Sconst
1748 : {
1749 904 : VariableSetStmt *n = makeNode(VariableSetStmt);
1750 :
1751 904 : n->kind = VAR_SET_VALUE;
1752 904 : n->name = "role";
1753 904 : n->args = list_make1(makeStringConst($2, @2));
1754 904 : n->location = @2;
1755 904 : $$ = n;
1756 : }
1757 : | SESSION AUTHORIZATION NonReservedWord_or_Sconst
1758 : {
1759 2538 : VariableSetStmt *n = makeNode(VariableSetStmt);
1760 :
1761 2538 : n->kind = VAR_SET_VALUE;
1762 2538 : n->name = "session_authorization";
1763 2538 : n->args = list_make1(makeStringConst($3, @3));
1764 2538 : n->location = @3;
1765 2538 : $$ = n;
1766 : }
1767 : | SESSION AUTHORIZATION DEFAULT
1768 : {
1769 4 : VariableSetStmt *n = makeNode(VariableSetStmt);
1770 :
1771 4 : n->kind = VAR_SET_DEFAULT;
1772 4 : n->name = "session_authorization";
1773 4 : n->location = -1;
1774 4 : $$ = n;
1775 : }
1776 : | XML_P OPTION document_or_content
1777 : {
1778 16 : VariableSetStmt *n = makeNode(VariableSetStmt);
1779 :
1780 16 : n->kind = VAR_SET_VALUE;
1781 16 : n->name = "xmloption";
1782 16 : n->args = list_make1(makeStringConst($3 == XMLOPTION_DOCUMENT ? "DOCUMENT" : "CONTENT", @3));
1783 16 : n->jumble_args = true;
1784 16 : n->location = -1;
1785 16 : $$ = n;
1786 : }
1787 : /* Special syntaxes invented by PostgreSQL: */
1788 : | TRANSACTION SNAPSHOT Sconst
1789 : {
1790 44 : VariableSetStmt *n = makeNode(VariableSetStmt);
1791 :
1792 44 : n->kind = VAR_SET_MULTI;
1793 44 : n->name = "TRANSACTION SNAPSHOT";
1794 44 : n->args = list_make1(makeStringConst($3, @3));
1795 44 : n->location = @3;
1796 44 : $$ = n;
1797 : }
1798 : ;
1799 :
1800 21718 : var_name: ColId { $$ = $1; }
1801 : | var_name '.' ColId
1802 456 : { $$ = psprintf("%s.%s", $1, $3); }
1803 : ;
1804 :
1805 17350 : var_list: var_value { $$ = list_make1($1); }
1806 166 : | var_list ',' var_value { $$ = lappend($1, $3); }
1807 : ;
1808 :
1809 : var_value: opt_boolean_or_string
1810 13132 : { $$ = makeStringConst($1, @1); }
1811 : | NumericOnly
1812 4384 : { $$ = makeAConst($1, @1); }
1813 : ;
1814 :
1815 0 : iso_level: READ UNCOMMITTED { $$ = "read uncommitted"; }
1816 908 : | READ COMMITTED { $$ = "read committed"; }
1817 2448 : | REPEATABLE READ { $$ = "repeatable read"; }
1818 3196 : | SERIALIZABLE { $$ = "serializable"; }
1819 : ;
1820 :
1821 : opt_boolean_or_string:
1822 580 : TRUE_P { $$ = "true"; }
1823 1294 : | FALSE_P { $$ = "false"; }
1824 2014 : | ON { $$ = "on"; }
1825 : /*
1826 : * OFF is also accepted as a boolean value, but is handled by
1827 : * the NonReservedWord rule. The action for booleans and strings
1828 : * is the same, so we don't need to distinguish them here.
1829 : */
1830 26066 : | NonReservedWord_or_Sconst { $$ = $1; }
1831 : ;
1832 :
1833 : /* Timezone values can be:
1834 : * - a string such as 'pst8pdt'
1835 : * - an identifier such as "pst8pdt"
1836 : * - an integer or floating point number
1837 : * - a time interval per SQL99
1838 : * ColId gives reduce/reduce errors against ConstInterval and LOCAL,
1839 : * so use IDENT (meaning we reject anything that is a key word).
1840 : */
1841 : zone_value:
1842 : Sconst
1843 : {
1844 60 : $$ = makeStringConst($1, @1);
1845 : }
1846 : | IDENT
1847 : {
1848 4 : $$ = makeStringConst($1, @1);
1849 : }
1850 : | ConstInterval Sconst opt_interval
1851 : {
1852 0 : TypeName *t = $1;
1853 :
1854 0 : if ($3 != NIL)
1855 : {
1856 0 : A_Const *n = (A_Const *) linitial($3);
1857 :
1858 0 : if ((n->val.ival.ival & ~(INTERVAL_MASK(HOUR) | INTERVAL_MASK(MINUTE))) != 0)
1859 0 : ereport(ERROR,
1860 : (errcode(ERRCODE_SYNTAX_ERROR),
1861 : errmsg("time zone interval must be HOUR or HOUR TO MINUTE"),
1862 : parser_errposition(@3)));
1863 : }
1864 0 : t->typmods = $3;
1865 0 : $$ = makeStringConstCast($2, @2, t);
1866 : }
1867 : | ConstInterval '(' Iconst ')' Sconst
1868 : {
1869 0 : TypeName *t = $1;
1870 :
1871 0 : t->typmods = list_make2(makeIntConst(INTERVAL_FULL_RANGE, -1),
1872 : makeIntConst($3, @3));
1873 0 : $$ = makeStringConstCast($5, @5, t);
1874 : }
1875 24 : | NumericOnly { $$ = makeAConst($1, @1); }
1876 14 : | DEFAULT { $$ = NULL; }
1877 2 : | LOCAL { $$ = NULL; }
1878 : ;
1879 :
1880 : opt_encoding:
1881 0 : Sconst { $$ = $1; }
1882 0 : | DEFAULT { $$ = NULL; }
1883 0 : | /*EMPTY*/ { $$ = NULL; }
1884 : ;
1885 :
1886 : NonReservedWord_or_Sconst:
1887 47012 : NonReservedWord { $$ = $1; }
1888 4952 : | Sconst { $$ = $1; }
1889 : ;
1890 :
1891 : VariableResetStmt:
1892 4136 : RESET reset_rest { $$ = (Node *) $2; }
1893 : ;
1894 :
1895 : reset_rest:
1896 3358 : generic_reset { $$ = $1; }
1897 : | TIME ZONE
1898 : {
1899 14 : VariableSetStmt *n = makeNode(VariableSetStmt);
1900 :
1901 14 : n->kind = VAR_RESET;
1902 14 : n->name = "timezone";
1903 14 : n->location = -1;
1904 14 : $$ = n;
1905 : }
1906 : | TRANSACTION ISOLATION LEVEL
1907 : {
1908 0 : VariableSetStmt *n = makeNode(VariableSetStmt);
1909 :
1910 0 : n->kind = VAR_RESET;
1911 0 : n->name = "transaction_isolation";
1912 0 : n->location = -1;
1913 0 : $$ = n;
1914 : }
1915 : | SESSION AUTHORIZATION
1916 : {
1917 764 : VariableSetStmt *n = makeNode(VariableSetStmt);
1918 :
1919 764 : n->kind = VAR_RESET;
1920 764 : n->name = "session_authorization";
1921 764 : n->location = -1;
1922 764 : $$ = n;
1923 : }
1924 : ;
1925 :
1926 : generic_reset:
1927 : var_name
1928 : {
1929 3394 : VariableSetStmt *n = makeNode(VariableSetStmt);
1930 :
1931 3394 : n->kind = VAR_RESET;
1932 3394 : n->name = $1;
1933 3394 : n->location = -1;
1934 3394 : $$ = n;
1935 : }
1936 : | ALL
1937 : {
1938 18 : VariableSetStmt *n = makeNode(VariableSetStmt);
1939 :
1940 18 : n->kind = VAR_RESET_ALL;
1941 18 : n->location = -1;
1942 18 : $$ = n;
1943 : }
1944 : ;
1945 :
1946 : /* SetResetClause allows SET or RESET without LOCAL */
1947 : SetResetClause:
1948 1172 : SET set_rest { $$ = $2; }
1949 40 : | VariableResetStmt { $$ = (VariableSetStmt *) $1; }
1950 : ;
1951 :
1952 : /* SetResetClause allows SET or RESET without LOCAL */
1953 : FunctionSetResetClause:
1954 128 : SET set_rest_more { $$ = $2; }
1955 12 : | VariableResetStmt { $$ = (VariableSetStmt *) $1; }
1956 : ;
1957 :
1958 :
1959 : VariableShowStmt:
1960 : SHOW var_name
1961 : {
1962 830 : VariableShowStmt *n = makeNode(VariableShowStmt);
1963 :
1964 830 : n->name = $2;
1965 830 : $$ = (Node *) n;
1966 : }
1967 : | SHOW TIME ZONE
1968 : {
1969 10 : VariableShowStmt *n = makeNode(VariableShowStmt);
1970 :
1971 10 : n->name = "timezone";
1972 10 : $$ = (Node *) n;
1973 : }
1974 : | SHOW TRANSACTION ISOLATION LEVEL
1975 : {
1976 4 : VariableShowStmt *n = makeNode(VariableShowStmt);
1977 :
1978 4 : n->name = "transaction_isolation";
1979 4 : $$ = (Node *) n;
1980 : }
1981 : | SHOW SESSION AUTHORIZATION
1982 : {
1983 0 : VariableShowStmt *n = makeNode(VariableShowStmt);
1984 :
1985 0 : n->name = "session_authorization";
1986 0 : $$ = (Node *) n;
1987 : }
1988 : | SHOW ALL
1989 : {
1990 0 : VariableShowStmt *n = makeNode(VariableShowStmt);
1991 :
1992 0 : n->name = "all";
1993 0 : $$ = (Node *) n;
1994 : }
1995 : ;
1996 :
1997 :
1998 : ConstraintsSetStmt:
1999 : SET CONSTRAINTS constraints_set_list constraints_set_mode
2000 : {
2001 104 : ConstraintsSetStmt *n = makeNode(ConstraintsSetStmt);
2002 :
2003 104 : n->constraints = $3;
2004 104 : n->deferred = $4;
2005 104 : $$ = (Node *) n;
2006 : }
2007 : ;
2008 :
2009 : constraints_set_list:
2010 56 : ALL { $$ = NIL; }
2011 48 : | qualified_name_list { $$ = $1; }
2012 : ;
2013 :
2014 : constraints_set_mode:
2015 68 : DEFERRED { $$ = true; }
2016 36 : | IMMEDIATE { $$ = false; }
2017 : ;
2018 :
2019 :
2020 : /*
2021 : * Checkpoint statement
2022 : */
2023 : CheckPointStmt:
2024 : CHECKPOINT
2025 : {
2026 204 : CheckPointStmt *n = makeNode(CheckPointStmt);
2027 :
2028 204 : $$ = (Node *) n;
2029 : }
2030 : ;
2031 :
2032 :
2033 : /*****************************************************************************
2034 : *
2035 : * DISCARD { ALL | TEMP | PLANS | SEQUENCES }
2036 : *
2037 : *****************************************************************************/
2038 :
2039 : DiscardStmt:
2040 : DISCARD ALL
2041 : {
2042 6 : DiscardStmt *n = makeNode(DiscardStmt);
2043 :
2044 6 : n->target = DISCARD_ALL;
2045 6 : $$ = (Node *) n;
2046 : }
2047 : | DISCARD TEMP
2048 : {
2049 8 : DiscardStmt *n = makeNode(DiscardStmt);
2050 :
2051 8 : n->target = DISCARD_TEMP;
2052 8 : $$ = (Node *) n;
2053 : }
2054 : | DISCARD TEMPORARY
2055 : {
2056 0 : DiscardStmt *n = makeNode(DiscardStmt);
2057 :
2058 0 : n->target = DISCARD_TEMP;
2059 0 : $$ = (Node *) n;
2060 : }
2061 : | DISCARD PLANS
2062 : {
2063 4 : DiscardStmt *n = makeNode(DiscardStmt);
2064 :
2065 4 : n->target = DISCARD_PLANS;
2066 4 : $$ = (Node *) n;
2067 : }
2068 : | DISCARD SEQUENCES
2069 : {
2070 12 : DiscardStmt *n = makeNode(DiscardStmt);
2071 :
2072 12 : n->target = DISCARD_SEQUENCES;
2073 12 : $$ = (Node *) n;
2074 : }
2075 :
2076 : ;
2077 :
2078 :
2079 : /*****************************************************************************
2080 : *
2081 : * ALTER [ TABLE | INDEX | SEQUENCE | VIEW | MATERIALIZED VIEW | FOREIGN TABLE ] variations
2082 : *
2083 : * Note: we accept all subcommands for each of the variants, and sort
2084 : * out what's really legal at execution time.
2085 : *****************************************************************************/
2086 :
2087 : AlterTableStmt:
2088 : ALTER TABLE relation_expr alter_table_cmds
2089 : {
2090 23524 : AlterTableStmt *n = makeNode(AlterTableStmt);
2091 :
2092 23524 : n->relation = $3;
2093 23524 : n->cmds = $4;
2094 23524 : n->objtype = OBJECT_TABLE;
2095 23524 : n->missing_ok = false;
2096 23524 : $$ = (Node *) n;
2097 : }
2098 : | ALTER TABLE IF_P EXISTS relation_expr alter_table_cmds
2099 : {
2100 54 : AlterTableStmt *n = makeNode(AlterTableStmt);
2101 :
2102 54 : n->relation = $5;
2103 54 : n->cmds = $6;
2104 54 : n->objtype = OBJECT_TABLE;
2105 54 : n->missing_ok = true;
2106 54 : $$ = (Node *) n;
2107 : }
2108 : | ALTER TABLE relation_expr partition_cmd
2109 : {
2110 2818 : AlterTableStmt *n = makeNode(AlterTableStmt);
2111 :
2112 2818 : n->relation = $3;
2113 2818 : n->cmds = list_make1($4);
2114 2818 : n->objtype = OBJECT_TABLE;
2115 2818 : n->missing_ok = false;
2116 2818 : $$ = (Node *) n;
2117 : }
2118 : | ALTER TABLE IF_P EXISTS relation_expr partition_cmd
2119 : {
2120 0 : AlterTableStmt *n = makeNode(AlterTableStmt);
2121 :
2122 0 : n->relation = $5;
2123 0 : n->cmds = list_make1($6);
2124 0 : n->objtype = OBJECT_TABLE;
2125 0 : n->missing_ok = true;
2126 0 : $$ = (Node *) n;
2127 : }
2128 : | ALTER TABLE ALL IN_P TABLESPACE name SET TABLESPACE name opt_nowait
2129 : {
2130 : AlterTableMoveAllStmt *n =
2131 12 : makeNode(AlterTableMoveAllStmt);
2132 :
2133 12 : n->orig_tablespacename = $6;
2134 12 : n->objtype = OBJECT_TABLE;
2135 12 : n->roles = NIL;
2136 12 : n->new_tablespacename = $9;
2137 12 : n->nowait = $10;
2138 12 : $$ = (Node *) n;
2139 : }
2140 : | ALTER TABLE ALL IN_P TABLESPACE name OWNED BY role_list SET TABLESPACE name opt_nowait
2141 : {
2142 : AlterTableMoveAllStmt *n =
2143 0 : makeNode(AlterTableMoveAllStmt);
2144 :
2145 0 : n->orig_tablespacename = $6;
2146 0 : n->objtype = OBJECT_TABLE;
2147 0 : n->roles = $9;
2148 0 : n->new_tablespacename = $12;
2149 0 : n->nowait = $13;
2150 0 : $$ = (Node *) n;
2151 : }
2152 : | ALTER INDEX qualified_name alter_table_cmds
2153 : {
2154 226 : AlterTableStmt *n = makeNode(AlterTableStmt);
2155 :
2156 226 : n->relation = $3;
2157 226 : n->cmds = $4;
2158 226 : n->objtype = OBJECT_INDEX;
2159 226 : n->missing_ok = false;
2160 226 : $$ = (Node *) n;
2161 : }
2162 : | ALTER INDEX IF_P EXISTS qualified_name alter_table_cmds
2163 : {
2164 0 : AlterTableStmt *n = makeNode(AlterTableStmt);
2165 :
2166 0 : n->relation = $5;
2167 0 : n->cmds = $6;
2168 0 : n->objtype = OBJECT_INDEX;
2169 0 : n->missing_ok = true;
2170 0 : $$ = (Node *) n;
2171 : }
2172 : | ALTER INDEX qualified_name index_partition_cmd
2173 : {
2174 398 : AlterTableStmt *n = makeNode(AlterTableStmt);
2175 :
2176 398 : n->relation = $3;
2177 398 : n->cmds = list_make1($4);
2178 398 : n->objtype = OBJECT_INDEX;
2179 398 : n->missing_ok = false;
2180 398 : $$ = (Node *) n;
2181 : }
2182 : | ALTER INDEX ALL IN_P TABLESPACE name SET TABLESPACE name opt_nowait
2183 : {
2184 : AlterTableMoveAllStmt *n =
2185 6 : makeNode(AlterTableMoveAllStmt);
2186 :
2187 6 : n->orig_tablespacename = $6;
2188 6 : n->objtype = OBJECT_INDEX;
2189 6 : n->roles = NIL;
2190 6 : n->new_tablespacename = $9;
2191 6 : n->nowait = $10;
2192 6 : $$ = (Node *) n;
2193 : }
2194 : | ALTER INDEX ALL IN_P TABLESPACE name OWNED BY role_list SET TABLESPACE name opt_nowait
2195 : {
2196 : AlterTableMoveAllStmt *n =
2197 0 : makeNode(AlterTableMoveAllStmt);
2198 :
2199 0 : n->orig_tablespacename = $6;
2200 0 : n->objtype = OBJECT_INDEX;
2201 0 : n->roles = $9;
2202 0 : n->new_tablespacename = $12;
2203 0 : n->nowait = $13;
2204 0 : $$ = (Node *) n;
2205 : }
2206 : | ALTER SEQUENCE qualified_name alter_table_cmds
2207 : {
2208 76 : AlterTableStmt *n = makeNode(AlterTableStmt);
2209 :
2210 76 : n->relation = $3;
2211 76 : n->cmds = $4;
2212 76 : n->objtype = OBJECT_SEQUENCE;
2213 76 : n->missing_ok = false;
2214 76 : $$ = (Node *) n;
2215 : }
2216 : | ALTER SEQUENCE IF_P EXISTS qualified_name alter_table_cmds
2217 : {
2218 0 : AlterTableStmt *n = makeNode(AlterTableStmt);
2219 :
2220 0 : n->relation = $5;
2221 0 : n->cmds = $6;
2222 0 : n->objtype = OBJECT_SEQUENCE;
2223 0 : n->missing_ok = true;
2224 0 : $$ = (Node *) n;
2225 : }
2226 : | ALTER VIEW qualified_name alter_table_cmds
2227 : {
2228 242 : AlterTableStmt *n = makeNode(AlterTableStmt);
2229 :
2230 242 : n->relation = $3;
2231 242 : n->cmds = $4;
2232 242 : n->objtype = OBJECT_VIEW;
2233 242 : n->missing_ok = false;
2234 242 : $$ = (Node *) n;
2235 : }
2236 : | ALTER VIEW IF_P EXISTS qualified_name alter_table_cmds
2237 : {
2238 0 : AlterTableStmt *n = makeNode(AlterTableStmt);
2239 :
2240 0 : n->relation = $5;
2241 0 : n->cmds = $6;
2242 0 : n->objtype = OBJECT_VIEW;
2243 0 : n->missing_ok = true;
2244 0 : $$ = (Node *) n;
2245 : }
2246 : | ALTER MATERIALIZED VIEW qualified_name alter_table_cmds
2247 : {
2248 48 : AlterTableStmt *n = makeNode(AlterTableStmt);
2249 :
2250 48 : n->relation = $4;
2251 48 : n->cmds = $5;
2252 48 : n->objtype = OBJECT_MATVIEW;
2253 48 : n->missing_ok = false;
2254 48 : $$ = (Node *) n;
2255 : }
2256 : | ALTER MATERIALIZED VIEW IF_P EXISTS qualified_name alter_table_cmds
2257 : {
2258 0 : AlterTableStmt *n = makeNode(AlterTableStmt);
2259 :
2260 0 : n->relation = $6;
2261 0 : n->cmds = $7;
2262 0 : n->objtype = OBJECT_MATVIEW;
2263 0 : n->missing_ok = true;
2264 0 : $$ = (Node *) n;
2265 : }
2266 : | ALTER MATERIALIZED VIEW ALL IN_P TABLESPACE name SET TABLESPACE name opt_nowait
2267 : {
2268 : AlterTableMoveAllStmt *n =
2269 12 : makeNode(AlterTableMoveAllStmt);
2270 :
2271 12 : n->orig_tablespacename = $7;
2272 12 : n->objtype = OBJECT_MATVIEW;
2273 12 : n->roles = NIL;
2274 12 : n->new_tablespacename = $10;
2275 12 : n->nowait = $11;
2276 12 : $$ = (Node *) n;
2277 : }
2278 : | ALTER MATERIALIZED VIEW ALL IN_P TABLESPACE name OWNED BY role_list SET TABLESPACE name opt_nowait
2279 : {
2280 : AlterTableMoveAllStmt *n =
2281 0 : makeNode(AlterTableMoveAllStmt);
2282 :
2283 0 : n->orig_tablespacename = $7;
2284 0 : n->objtype = OBJECT_MATVIEW;
2285 0 : n->roles = $10;
2286 0 : n->new_tablespacename = $13;
2287 0 : n->nowait = $14;
2288 0 : $$ = (Node *) n;
2289 : }
2290 : | ALTER FOREIGN TABLE relation_expr alter_table_cmds
2291 : {
2292 374 : AlterTableStmt *n = makeNode(AlterTableStmt);
2293 :
2294 374 : n->relation = $4;
2295 374 : n->cmds = $5;
2296 374 : n->objtype = OBJECT_FOREIGN_TABLE;
2297 374 : n->missing_ok = false;
2298 374 : $$ = (Node *) n;
2299 : }
2300 : | ALTER FOREIGN TABLE IF_P EXISTS relation_expr alter_table_cmds
2301 : {
2302 108 : AlterTableStmt *n = makeNode(AlterTableStmt);
2303 :
2304 108 : n->relation = $6;
2305 108 : n->cmds = $7;
2306 108 : n->objtype = OBJECT_FOREIGN_TABLE;
2307 108 : n->missing_ok = true;
2308 108 : $$ = (Node *) n;
2309 : }
2310 : ;
2311 :
2312 : alter_table_cmds:
2313 24652 : alter_table_cmd { $$ = list_make1($1); }
2314 942 : | alter_table_cmds ',' alter_table_cmd { $$ = lappend($1, $3); }
2315 : ;
2316 :
2317 : partition_cmd:
2318 : /* ALTER TABLE <name> ATTACH PARTITION <table_name> FOR VALUES */
2319 : ATTACH PARTITION qualified_name PartitionBoundSpec
2320 : {
2321 2228 : AlterTableCmd *n = makeNode(AlterTableCmd);
2322 2228 : PartitionCmd *cmd = makeNode(PartitionCmd);
2323 :
2324 2228 : n->subtype = AT_AttachPartition;
2325 2228 : cmd->name = $3;
2326 2228 : cmd->bound = $4;
2327 2228 : cmd->concurrent = false;
2328 2228 : n->def = (Node *) cmd;
2329 :
2330 2228 : $$ = (Node *) n;
2331 : }
2332 : /* ALTER TABLE <name> DETACH PARTITION <partition_name> [CONCURRENTLY] */
2333 : | DETACH PARTITION qualified_name opt_concurrently
2334 : {
2335 570 : AlterTableCmd *n = makeNode(AlterTableCmd);
2336 570 : PartitionCmd *cmd = makeNode(PartitionCmd);
2337 :
2338 570 : n->subtype = AT_DetachPartition;
2339 570 : cmd->name = $3;
2340 570 : cmd->bound = NULL;
2341 570 : cmd->concurrent = $4;
2342 570 : n->def = (Node *) cmd;
2343 :
2344 570 : $$ = (Node *) n;
2345 : }
2346 : | DETACH PARTITION qualified_name FINALIZE
2347 : {
2348 20 : AlterTableCmd *n = makeNode(AlterTableCmd);
2349 20 : PartitionCmd *cmd = makeNode(PartitionCmd);
2350 :
2351 20 : n->subtype = AT_DetachPartitionFinalize;
2352 20 : cmd->name = $3;
2353 20 : cmd->bound = NULL;
2354 20 : cmd->concurrent = false;
2355 20 : n->def = (Node *) cmd;
2356 20 : $$ = (Node *) n;
2357 : }
2358 : ;
2359 :
2360 : index_partition_cmd:
2361 : /* ALTER INDEX <name> ATTACH PARTITION <index_name> */
2362 : ATTACH PARTITION qualified_name
2363 : {
2364 398 : AlterTableCmd *n = makeNode(AlterTableCmd);
2365 398 : PartitionCmd *cmd = makeNode(PartitionCmd);
2366 :
2367 398 : n->subtype = AT_AttachPartition;
2368 398 : cmd->name = $3;
2369 398 : cmd->bound = NULL;
2370 398 : cmd->concurrent = false;
2371 398 : n->def = (Node *) cmd;
2372 :
2373 398 : $$ = (Node *) n;
2374 : }
2375 : ;
2376 :
2377 : alter_table_cmd:
2378 : /* ALTER TABLE <name> ADD <coldef> */
2379 : ADD_P columnDef
2380 : {
2381 168 : AlterTableCmd *n = makeNode(AlterTableCmd);
2382 :
2383 168 : n->subtype = AT_AddColumn;
2384 168 : n->def = $2;
2385 168 : n->missing_ok = false;
2386 168 : $$ = (Node *) n;
2387 : }
2388 : /* ALTER TABLE <name> ADD IF NOT EXISTS <coldef> */
2389 : | ADD_P IF_P NOT EXISTS columnDef
2390 : {
2391 0 : AlterTableCmd *n = makeNode(AlterTableCmd);
2392 :
2393 0 : n->subtype = AT_AddColumn;
2394 0 : n->def = $5;
2395 0 : n->missing_ok = true;
2396 0 : $$ = (Node *) n;
2397 : }
2398 : /* ALTER TABLE <name> ADD COLUMN <coldef> */
2399 : | ADD_P COLUMN columnDef
2400 : {
2401 1734 : AlterTableCmd *n = makeNode(AlterTableCmd);
2402 :
2403 1734 : n->subtype = AT_AddColumn;
2404 1734 : n->def = $3;
2405 1734 : n->missing_ok = false;
2406 1734 : $$ = (Node *) n;
2407 : }
2408 : /* ALTER TABLE <name> ADD COLUMN IF NOT EXISTS <coldef> */
2409 : | ADD_P COLUMN IF_P NOT EXISTS columnDef
2410 : {
2411 60 : AlterTableCmd *n = makeNode(AlterTableCmd);
2412 :
2413 60 : n->subtype = AT_AddColumn;
2414 60 : n->def = $6;
2415 60 : n->missing_ok = true;
2416 60 : $$ = (Node *) n;
2417 : }
2418 : /* ALTER TABLE <name> ALTER [COLUMN] <colname> {SET DEFAULT <expr>|DROP DEFAULT} */
2419 : | ALTER opt_column ColId alter_column_default
2420 : {
2421 528 : AlterTableCmd *n = makeNode(AlterTableCmd);
2422 :
2423 528 : n->subtype = AT_ColumnDefault;
2424 528 : n->name = $3;
2425 528 : n->def = $4;
2426 528 : $$ = (Node *) n;
2427 : }
2428 : /* ALTER TABLE <name> ALTER [COLUMN] <colname> DROP NOT NULL */
2429 : | ALTER opt_column ColId DROP NOT NULL_P
2430 : {
2431 276 : AlterTableCmd *n = makeNode(AlterTableCmd);
2432 :
2433 276 : n->subtype = AT_DropNotNull;
2434 276 : n->name = $3;
2435 276 : $$ = (Node *) n;
2436 : }
2437 : /* ALTER TABLE <name> ALTER [COLUMN] <colname> SET NOT NULL */
2438 : | ALTER opt_column ColId SET NOT NULL_P
2439 : {
2440 398 : AlterTableCmd *n = makeNode(AlterTableCmd);
2441 :
2442 398 : n->subtype = AT_SetNotNull;
2443 398 : n->name = $3;
2444 398 : $$ = (Node *) n;
2445 : }
2446 : /* ALTER TABLE <name> ALTER [COLUMN] <colname> SET EXPRESSION AS <expr> */
2447 : | ALTER opt_column ColId SET EXPRESSION AS '(' a_expr ')'
2448 : {
2449 66 : AlterTableCmd *n = makeNode(AlterTableCmd);
2450 :
2451 66 : n->subtype = AT_SetExpression;
2452 66 : n->name = $3;
2453 66 : n->def = $8;
2454 66 : $$ = (Node *) n;
2455 : }
2456 : /* ALTER TABLE <name> ALTER [COLUMN] <colname> DROP EXPRESSION */
2457 : | ALTER opt_column ColId DROP EXPRESSION
2458 : {
2459 32 : AlterTableCmd *n = makeNode(AlterTableCmd);
2460 :
2461 32 : n->subtype = AT_DropExpression;
2462 32 : n->name = $3;
2463 32 : $$ = (Node *) n;
2464 : }
2465 : /* ALTER TABLE <name> ALTER [COLUMN] <colname> DROP EXPRESSION IF EXISTS */
2466 : | ALTER opt_column ColId DROP EXPRESSION IF_P EXISTS
2467 : {
2468 6 : AlterTableCmd *n = makeNode(AlterTableCmd);
2469 :
2470 6 : n->subtype = AT_DropExpression;
2471 6 : n->name = $3;
2472 6 : n->missing_ok = true;
2473 6 : $$ = (Node *) n;
2474 : }
2475 : /* ALTER TABLE <name> ALTER [COLUMN] <colname> SET STATISTICS */
2476 : | ALTER opt_column ColId SET STATISTICS set_statistics_value
2477 : {
2478 62 : AlterTableCmd *n = makeNode(AlterTableCmd);
2479 :
2480 62 : n->subtype = AT_SetStatistics;
2481 62 : n->name = $3;
2482 62 : n->def = $6;
2483 62 : $$ = (Node *) n;
2484 : }
2485 : /* ALTER TABLE <name> ALTER [COLUMN] <colnum> SET STATISTICS */
2486 : | ALTER opt_column Iconst SET STATISTICS set_statistics_value
2487 : {
2488 70 : AlterTableCmd *n = makeNode(AlterTableCmd);
2489 :
2490 70 : if ($3 <= 0 || $3 > PG_INT16_MAX)
2491 6 : ereport(ERROR,
2492 : (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
2493 : errmsg("column number must be in range from 1 to %d", PG_INT16_MAX),
2494 : parser_errposition(@3)));
2495 :
2496 64 : n->subtype = AT_SetStatistics;
2497 64 : n->num = (int16) $3;
2498 64 : n->def = $6;
2499 64 : $$ = (Node *) n;
2500 : }
2501 : /* ALTER TABLE <name> ALTER [COLUMN] <colname> SET ( column_parameter = value [, ... ] ) */
2502 : | ALTER opt_column ColId SET reloptions
2503 : {
2504 38 : AlterTableCmd *n = makeNode(AlterTableCmd);
2505 :
2506 38 : n->subtype = AT_SetOptions;
2507 38 : n->name = $3;
2508 38 : n->def = (Node *) $5;
2509 38 : $$ = (Node *) n;
2510 : }
2511 : /* ALTER TABLE <name> ALTER [COLUMN] <colname> RESET ( column_parameter [, ... ] ) */
2512 : | ALTER opt_column ColId RESET reloptions
2513 : {
2514 6 : AlterTableCmd *n = makeNode(AlterTableCmd);
2515 :
2516 6 : n->subtype = AT_ResetOptions;
2517 6 : n->name = $3;
2518 6 : n->def = (Node *) $5;
2519 6 : $$ = (Node *) n;
2520 : }
2521 : /* ALTER TABLE <name> ALTER [COLUMN] <colname> SET STORAGE <storagemode> */
2522 : | ALTER opt_column ColId SET column_storage
2523 : {
2524 212 : AlterTableCmd *n = makeNode(AlterTableCmd);
2525 :
2526 212 : n->subtype = AT_SetStorage;
2527 212 : n->name = $3;
2528 212 : n->def = (Node *) makeString($5);
2529 212 : $$ = (Node *) n;
2530 : }
2531 : /* ALTER TABLE <name> ALTER [COLUMN] <colname> SET COMPRESSION <cm> */
2532 : | ALTER opt_column ColId SET column_compression
2533 : {
2534 68 : AlterTableCmd *n = makeNode(AlterTableCmd);
2535 :
2536 68 : n->subtype = AT_SetCompression;
2537 68 : n->name = $3;
2538 68 : n->def = (Node *) makeString($5);
2539 68 : $$ = (Node *) n;
2540 : }
2541 : /* ALTER TABLE <name> ALTER [COLUMN] <colname> ADD GENERATED ... AS IDENTITY ... */
2542 : | ALTER opt_column ColId ADD_P GENERATED generated_when AS IDENTITY_P OptParenthesizedSeqOptList
2543 : {
2544 160 : AlterTableCmd *n = makeNode(AlterTableCmd);
2545 160 : Constraint *c = makeNode(Constraint);
2546 :
2547 160 : c->contype = CONSTR_IDENTITY;
2548 160 : c->generated_when = $6;
2549 160 : c->options = $9;
2550 160 : c->location = @5;
2551 :
2552 160 : n->subtype = AT_AddIdentity;
2553 160 : n->name = $3;
2554 160 : n->def = (Node *) c;
2555 :
2556 160 : $$ = (Node *) n;
2557 : }
2558 : /* ALTER TABLE <name> ALTER [COLUMN] <colname> SET <sequence options>/RESET */
2559 : | ALTER opt_column ColId alter_identity_column_option_list
2560 : {
2561 62 : AlterTableCmd *n = makeNode(AlterTableCmd);
2562 :
2563 62 : n->subtype = AT_SetIdentity;
2564 62 : n->name = $3;
2565 62 : n->def = (Node *) $4;
2566 62 : $$ = (Node *) n;
2567 : }
2568 : /* ALTER TABLE <name> ALTER [COLUMN] <colname> DROP IDENTITY */
2569 : | ALTER opt_column ColId DROP IDENTITY_P
2570 : {
2571 50 : AlterTableCmd *n = makeNode(AlterTableCmd);
2572 :
2573 50 : n->subtype = AT_DropIdentity;
2574 50 : n->name = $3;
2575 50 : n->missing_ok = false;
2576 50 : $$ = (Node *) n;
2577 : }
2578 : /* ALTER TABLE <name> ALTER [COLUMN] <colname> DROP IDENTITY IF EXISTS */
2579 : | ALTER opt_column ColId DROP IDENTITY_P IF_P EXISTS
2580 : {
2581 6 : AlterTableCmd *n = makeNode(AlterTableCmd);
2582 :
2583 6 : n->subtype = AT_DropIdentity;
2584 6 : n->name = $3;
2585 6 : n->missing_ok = true;
2586 6 : $$ = (Node *) n;
2587 : }
2588 : /* ALTER TABLE <name> DROP [COLUMN] IF EXISTS <colname> [RESTRICT|CASCADE] */
2589 : | DROP opt_column IF_P EXISTS ColId opt_drop_behavior
2590 : {
2591 18 : AlterTableCmd *n = makeNode(AlterTableCmd);
2592 :
2593 18 : n->subtype = AT_DropColumn;
2594 18 : n->name = $5;
2595 18 : n->behavior = $6;
2596 18 : n->missing_ok = true;
2597 18 : $$ = (Node *) n;
2598 : }
2599 : /* ALTER TABLE <name> DROP [COLUMN] <colname> [RESTRICT|CASCADE] */
2600 : | DROP opt_column ColId opt_drop_behavior
2601 : {
2602 1522 : AlterTableCmd *n = makeNode(AlterTableCmd);
2603 :
2604 1522 : n->subtype = AT_DropColumn;
2605 1522 : n->name = $3;
2606 1522 : n->behavior = $4;
2607 1522 : n->missing_ok = false;
2608 1522 : $$ = (Node *) n;
2609 : }
2610 : /*
2611 : * ALTER TABLE <name> ALTER [COLUMN] <colname> [SET DATA] TYPE <typename>
2612 : * [ USING <expression> ]
2613 : */
2614 : | ALTER opt_column ColId opt_set_data TYPE_P Typename opt_collate_clause alter_using
2615 : {
2616 856 : AlterTableCmd *n = makeNode(AlterTableCmd);
2617 856 : ColumnDef *def = makeNode(ColumnDef);
2618 :
2619 856 : n->subtype = AT_AlterColumnType;
2620 856 : n->name = $3;
2621 856 : n->def = (Node *) def;
2622 : /* We only use these fields of the ColumnDef node */
2623 856 : def->typeName = $6;
2624 856 : def->collClause = (CollateClause *) $7;
2625 856 : def->raw_default = $8;
2626 856 : def->location = @3;
2627 856 : $$ = (Node *) n;
2628 : }
2629 : /* ALTER FOREIGN TABLE <name> ALTER [COLUMN] <colname> OPTIONS */
2630 : | ALTER opt_column ColId alter_generic_options
2631 : {
2632 50 : AlterTableCmd *n = makeNode(AlterTableCmd);
2633 :
2634 50 : n->subtype = AT_AlterColumnGenericOptions;
2635 50 : n->name = $3;
2636 50 : n->def = (Node *) $4;
2637 50 : $$ = (Node *) n;
2638 : }
2639 : /* ALTER TABLE <name> ADD CONSTRAINT ... */
2640 : | ADD_P TableConstraint
2641 : {
2642 13010 : AlterTableCmd *n = makeNode(AlterTableCmd);
2643 :
2644 13010 : n->subtype = AT_AddConstraint;
2645 13010 : n->def = $2;
2646 13010 : $$ = (Node *) n;
2647 : }
2648 : /* ALTER TABLE <name> ALTER CONSTRAINT ... */
2649 : | ALTER CONSTRAINT name ConstraintAttributeSpec
2650 : {
2651 132 : AlterTableCmd *n = makeNode(AlterTableCmd);
2652 132 : Constraint *c = makeNode(Constraint);
2653 :
2654 132 : n->subtype = AT_AlterConstraint;
2655 132 : n->def = (Node *) c;
2656 132 : c->contype = CONSTR_FOREIGN; /* others not supported, yet */
2657 132 : c->conname = $3;
2658 132 : processCASbits($4, @4, "ALTER CONSTRAINT statement",
2659 : &c->deferrable,
2660 : &c->initdeferred,
2661 : NULL, NULL, yyscanner);
2662 132 : $$ = (Node *) n;
2663 : }
2664 : /* ALTER TABLE <name> VALIDATE CONSTRAINT ... */
2665 : | VALIDATE CONSTRAINT name
2666 : {
2667 388 : AlterTableCmd *n = makeNode(AlterTableCmd);
2668 :
2669 388 : n->subtype = AT_ValidateConstraint;
2670 388 : n->name = $3;
2671 388 : $$ = (Node *) n;
2672 : }
2673 : /* ALTER TABLE <name> DROP CONSTRAINT IF EXISTS <name> [RESTRICT|CASCADE] */
2674 : | DROP CONSTRAINT IF_P EXISTS name opt_drop_behavior
2675 : {
2676 18 : AlterTableCmd *n = makeNode(AlterTableCmd);
2677 :
2678 18 : n->subtype = AT_DropConstraint;
2679 18 : n->name = $5;
2680 18 : n->behavior = $6;
2681 18 : n->missing_ok = true;
2682 18 : $$ = (Node *) n;
2683 : }
2684 : /* ALTER TABLE <name> DROP CONSTRAINT <name> [RESTRICT|CASCADE] */
2685 : | DROP CONSTRAINT name opt_drop_behavior
2686 : {
2687 822 : AlterTableCmd *n = makeNode(AlterTableCmd);
2688 :
2689 822 : n->subtype = AT_DropConstraint;
2690 822 : n->name = $3;
2691 822 : n->behavior = $4;
2692 822 : n->missing_ok = false;
2693 822 : $$ = (Node *) n;
2694 : }
2695 : /* ALTER TABLE <name> SET WITHOUT OIDS, for backward compat */
2696 : | SET WITHOUT OIDS
2697 : {
2698 6 : AlterTableCmd *n = makeNode(AlterTableCmd);
2699 :
2700 6 : n->subtype = AT_DropOids;
2701 6 : $$ = (Node *) n;
2702 : }
2703 : /* ALTER TABLE <name> CLUSTER ON <indexname> */
2704 : | CLUSTER ON name
2705 : {
2706 46 : AlterTableCmd *n = makeNode(AlterTableCmd);
2707 :
2708 46 : n->subtype = AT_ClusterOn;
2709 46 : n->name = $3;
2710 46 : $$ = (Node *) n;
2711 : }
2712 : /* ALTER TABLE <name> SET WITHOUT CLUSTER */
2713 : | SET WITHOUT CLUSTER
2714 : {
2715 18 : AlterTableCmd *n = makeNode(AlterTableCmd);
2716 :
2717 18 : n->subtype = AT_DropCluster;
2718 18 : n->name = NULL;
2719 18 : $$ = (Node *) n;
2720 : }
2721 : /* ALTER TABLE <name> SET LOGGED */
2722 : | SET LOGGED
2723 : {
2724 50 : AlterTableCmd *n = makeNode(AlterTableCmd);
2725 :
2726 50 : n->subtype = AT_SetLogged;
2727 50 : $$ = (Node *) n;
2728 : }
2729 : /* ALTER TABLE <name> SET UNLOGGED */
2730 : | SET UNLOGGED
2731 : {
2732 62 : AlterTableCmd *n = makeNode(AlterTableCmd);
2733 :
2734 62 : n->subtype = AT_SetUnLogged;
2735 62 : $$ = (Node *) n;
2736 : }
2737 : /* ALTER TABLE <name> ENABLE TRIGGER <trig> */
2738 : | ENABLE_P TRIGGER name
2739 : {
2740 122 : AlterTableCmd *n = makeNode(AlterTableCmd);
2741 :
2742 122 : n->subtype = AT_EnableTrig;
2743 122 : n->name = $3;
2744 122 : $$ = (Node *) n;
2745 : }
2746 : /* ALTER TABLE <name> ENABLE ALWAYS TRIGGER <trig> */
2747 : | ENABLE_P ALWAYS TRIGGER name
2748 : {
2749 40 : AlterTableCmd *n = makeNode(AlterTableCmd);
2750 :
2751 40 : n->subtype = AT_EnableAlwaysTrig;
2752 40 : n->name = $4;
2753 40 : $$ = (Node *) n;
2754 : }
2755 : /* ALTER TABLE <name> ENABLE REPLICA TRIGGER <trig> */
2756 : | ENABLE_P REPLICA TRIGGER name
2757 : {
2758 16 : AlterTableCmd *n = makeNode(AlterTableCmd);
2759 :
2760 16 : n->subtype = AT_EnableReplicaTrig;
2761 16 : n->name = $4;
2762 16 : $$ = (Node *) n;
2763 : }
2764 : /* ALTER TABLE <name> ENABLE TRIGGER ALL */
2765 : | ENABLE_P TRIGGER ALL
2766 : {
2767 0 : AlterTableCmd *n = makeNode(AlterTableCmd);
2768 :
2769 0 : n->subtype = AT_EnableTrigAll;
2770 0 : $$ = (Node *) n;
2771 : }
2772 : /* ALTER TABLE <name> ENABLE TRIGGER USER */
2773 : | ENABLE_P TRIGGER USER
2774 : {
2775 0 : AlterTableCmd *n = makeNode(AlterTableCmd);
2776 :
2777 0 : n->subtype = AT_EnableTrigUser;
2778 0 : $$ = (Node *) n;
2779 : }
2780 : /* ALTER TABLE <name> DISABLE TRIGGER <trig> */
2781 : | DISABLE_P TRIGGER name
2782 : {
2783 138 : AlterTableCmd *n = makeNode(AlterTableCmd);
2784 :
2785 138 : n->subtype = AT_DisableTrig;
2786 138 : n->name = $3;
2787 138 : $$ = (Node *) n;
2788 : }
2789 : /* ALTER TABLE <name> DISABLE TRIGGER ALL */
2790 : | DISABLE_P TRIGGER ALL
2791 : {
2792 12 : AlterTableCmd *n = makeNode(AlterTableCmd);
2793 :
2794 12 : n->subtype = AT_DisableTrigAll;
2795 12 : $$ = (Node *) n;
2796 : }
2797 : /* ALTER TABLE <name> DISABLE TRIGGER USER */
2798 : | DISABLE_P TRIGGER USER
2799 : {
2800 12 : AlterTableCmd *n = makeNode(AlterTableCmd);
2801 :
2802 12 : n->subtype = AT_DisableTrigUser;
2803 12 : $$ = (Node *) n;
2804 : }
2805 : /* ALTER TABLE <name> ENABLE RULE <rule> */
2806 : | ENABLE_P RULE name
2807 : {
2808 8 : AlterTableCmd *n = makeNode(AlterTableCmd);
2809 :
2810 8 : n->subtype = AT_EnableRule;
2811 8 : n->name = $3;
2812 8 : $$ = (Node *) n;
2813 : }
2814 : /* ALTER TABLE <name> ENABLE ALWAYS RULE <rule> */
2815 : | ENABLE_P ALWAYS RULE name
2816 : {
2817 0 : AlterTableCmd *n = makeNode(AlterTableCmd);
2818 :
2819 0 : n->subtype = AT_EnableAlwaysRule;
2820 0 : n->name = $4;
2821 0 : $$ = (Node *) n;
2822 : }
2823 : /* ALTER TABLE <name> ENABLE REPLICA RULE <rule> */
2824 : | ENABLE_P REPLICA RULE name
2825 : {
2826 6 : AlterTableCmd *n = makeNode(AlterTableCmd);
2827 :
2828 6 : n->subtype = AT_EnableReplicaRule;
2829 6 : n->name = $4;
2830 6 : $$ = (Node *) n;
2831 : }
2832 : /* ALTER TABLE <name> DISABLE RULE <rule> */
2833 : | DISABLE_P RULE name
2834 : {
2835 32 : AlterTableCmd *n = makeNode(AlterTableCmd);
2836 :
2837 32 : n->subtype = AT_DisableRule;
2838 32 : n->name = $3;
2839 32 : $$ = (Node *) n;
2840 : }
2841 : /* ALTER TABLE <name> INHERIT <parent> */
2842 : | INHERIT qualified_name
2843 : {
2844 334 : AlterTableCmd *n = makeNode(AlterTableCmd);
2845 :
2846 334 : n->subtype = AT_AddInherit;
2847 334 : n->def = (Node *) $2;
2848 334 : $$ = (Node *) n;
2849 : }
2850 : /* ALTER TABLE <name> NO INHERIT <parent> */
2851 : | NO INHERIT qualified_name
2852 : {
2853 86 : AlterTableCmd *n = makeNode(AlterTableCmd);
2854 :
2855 86 : n->subtype = AT_DropInherit;
2856 86 : n->def = (Node *) $3;
2857 86 : $$ = (Node *) n;
2858 : }
2859 : /* ALTER TABLE <name> OF <type_name> */
2860 : | OF any_name
2861 : {
2862 66 : AlterTableCmd *n = makeNode(AlterTableCmd);
2863 66 : TypeName *def = makeTypeNameFromNameList($2);
2864 :
2865 66 : def->location = @2;
2866 66 : n->subtype = AT_AddOf;
2867 66 : n->def = (Node *) def;
2868 66 : $$ = (Node *) n;
2869 : }
2870 : /* ALTER TABLE <name> NOT OF */
2871 : | NOT OF
2872 : {
2873 6 : AlterTableCmd *n = makeNode(AlterTableCmd);
2874 :
2875 6 : n->subtype = AT_DropOf;
2876 6 : $$ = (Node *) n;
2877 : }
2878 : /* ALTER TABLE <name> OWNER TO RoleSpec */
2879 : | OWNER TO RoleSpec
2880 : {
2881 1818 : AlterTableCmd *n = makeNode(AlterTableCmd);
2882 :
2883 1818 : n->subtype = AT_ChangeOwner;
2884 1818 : n->newowner = $3;
2885 1818 : $$ = (Node *) n;
2886 : }
2887 : /* ALTER TABLE <name> SET ACCESS METHOD { <amname> | DEFAULT } */
2888 : | SET ACCESS METHOD set_access_method_name
2889 : {
2890 128 : AlterTableCmd *n = makeNode(AlterTableCmd);
2891 :
2892 128 : n->subtype = AT_SetAccessMethod;
2893 128 : n->name = $4;
2894 128 : $$ = (Node *) n;
2895 : }
2896 : /* ALTER TABLE <name> SET TABLESPACE <tablespacename> */
2897 : | SET TABLESPACE name
2898 : {
2899 104 : AlterTableCmd *n = makeNode(AlterTableCmd);
2900 :
2901 104 : n->subtype = AT_SetTableSpace;
2902 104 : n->name = $3;
2903 104 : $$ = (Node *) n;
2904 : }
2905 : /* ALTER TABLE <name> SET (...) */
2906 : | SET reloptions
2907 : {
2908 588 : AlterTableCmd *n = makeNode(AlterTableCmd);
2909 :
2910 588 : n->subtype = AT_SetRelOptions;
2911 588 : n->def = (Node *) $2;
2912 588 : $$ = (Node *) n;
2913 : }
2914 : /* ALTER TABLE <name> RESET (...) */
2915 : | RESET reloptions
2916 : {
2917 164 : AlterTableCmd *n = makeNode(AlterTableCmd);
2918 :
2919 164 : n->subtype = AT_ResetRelOptions;
2920 164 : n->def = (Node *) $2;
2921 164 : $$ = (Node *) n;
2922 : }
2923 : /* ALTER TABLE <name> REPLICA IDENTITY */
2924 : | REPLICA IDENTITY_P replica_identity
2925 : {
2926 442 : AlterTableCmd *n = makeNode(AlterTableCmd);
2927 :
2928 442 : n->subtype = AT_ReplicaIdentity;
2929 442 : n->def = $3;
2930 442 : $$ = (Node *) n;
2931 : }
2932 : /* ALTER TABLE <name> ENABLE ROW LEVEL SECURITY */
2933 : | ENABLE_P ROW LEVEL SECURITY
2934 : {
2935 284 : AlterTableCmd *n = makeNode(AlterTableCmd);
2936 :
2937 284 : n->subtype = AT_EnableRowSecurity;
2938 284 : $$ = (Node *) n;
2939 : }
2940 : /* ALTER TABLE <name> DISABLE ROW LEVEL SECURITY */
2941 : | DISABLE_P ROW LEVEL SECURITY
2942 : {
2943 10 : AlterTableCmd *n = makeNode(AlterTableCmd);
2944 :
2945 10 : n->subtype = AT_DisableRowSecurity;
2946 10 : $$ = (Node *) n;
2947 : }
2948 : /* ALTER TABLE <name> FORCE ROW LEVEL SECURITY */
2949 : | FORCE ROW LEVEL SECURITY
2950 : {
2951 88 : AlterTableCmd *n = makeNode(AlterTableCmd);
2952 :
2953 88 : n->subtype = AT_ForceRowSecurity;
2954 88 : $$ = (Node *) n;
2955 : }
2956 : /* ALTER TABLE <name> NO FORCE ROW LEVEL SECURITY */
2957 : | NO FORCE ROW LEVEL SECURITY
2958 : {
2959 32 : AlterTableCmd *n = makeNode(AlterTableCmd);
2960 :
2961 32 : n->subtype = AT_NoForceRowSecurity;
2962 32 : $$ = (Node *) n;
2963 : }
2964 : | alter_generic_options
2965 : {
2966 64 : AlterTableCmd *n = makeNode(AlterTableCmd);
2967 :
2968 64 : n->subtype = AT_GenericOptions;
2969 64 : n->def = (Node *) $1;
2970 64 : $$ = (Node *) n;
2971 : }
2972 : ;
2973 :
2974 : alter_column_default:
2975 362 : SET DEFAULT a_expr { $$ = $3; }
2976 180 : | DROP DEFAULT { $$ = NULL; }
2977 : ;
2978 :
2979 : opt_collate_clause:
2980 : COLLATE any_name
2981 : {
2982 12 : CollateClause *n = makeNode(CollateClause);
2983 :
2984 12 : n->arg = NULL;
2985 12 : n->collname = $2;
2986 12 : n->location = @1;
2987 12 : $$ = (Node *) n;
2988 : }
2989 4484 : | /* EMPTY */ { $$ = NULL; }
2990 : ;
2991 :
2992 : alter_using:
2993 168 : USING a_expr { $$ = $2; }
2994 688 : | /* EMPTY */ { $$ = NULL; }
2995 : ;
2996 :
2997 : replica_identity:
2998 : NOTHING
2999 : {
3000 36 : ReplicaIdentityStmt *n = makeNode(ReplicaIdentityStmt);
3001 :
3002 36 : n->identity_type = REPLICA_IDENTITY_NOTHING;
3003 36 : n->name = NULL;
3004 36 : $$ = (Node *) n;
3005 : }
3006 : | FULL
3007 : {
3008 144 : ReplicaIdentityStmt *n = makeNode(ReplicaIdentityStmt);
3009 :
3010 144 : n->identity_type = REPLICA_IDENTITY_FULL;
3011 144 : n->name = NULL;
3012 144 : $$ = (Node *) n;
3013 : }
3014 : | DEFAULT
3015 : {
3016 6 : ReplicaIdentityStmt *n = makeNode(ReplicaIdentityStmt);
3017 :
3018 6 : n->identity_type = REPLICA_IDENTITY_DEFAULT;
3019 6 : n->name = NULL;
3020 6 : $$ = (Node *) n;
3021 : }
3022 : | USING INDEX name
3023 : {
3024 256 : ReplicaIdentityStmt *n = makeNode(ReplicaIdentityStmt);
3025 :
3026 256 : n->identity_type = REPLICA_IDENTITY_INDEX;
3027 256 : n->name = $3;
3028 256 : $$ = (Node *) n;
3029 : }
3030 : ;
3031 :
3032 : reloptions:
3033 2554 : '(' reloption_list ')' { $$ = $2; }
3034 : ;
3035 :
3036 934 : opt_reloptions: WITH reloptions { $$ = $2; }
3037 21254 : | /* EMPTY */ { $$ = NIL; }
3038 : ;
3039 :
3040 : reloption_list:
3041 2554 : reloption_elem { $$ = list_make1($1); }
3042 220 : | reloption_list ',' reloption_elem { $$ = lappend($1, $3); }
3043 : ;
3044 :
3045 : /* This should match def_elem and also allow qualified names */
3046 : reloption_elem:
3047 : ColLabel '=' def_arg
3048 : {
3049 2158 : $$ = makeDefElem($1, (Node *) $3, @1);
3050 : }
3051 : | ColLabel
3052 : {
3053 548 : $$ = makeDefElem($1, NULL, @1);
3054 : }
3055 : | ColLabel '.' ColLabel '=' def_arg
3056 : {
3057 62 : $$ = makeDefElemExtended($1, $3, (Node *) $5,
3058 62 : DEFELEM_UNSPEC, @1);
3059 : }
3060 : | ColLabel '.' ColLabel
3061 : {
3062 6 : $$ = makeDefElemExtended($1, $3, NULL, DEFELEM_UNSPEC, @1);
3063 : }
3064 : ;
3065 :
3066 : alter_identity_column_option_list:
3067 : alter_identity_column_option
3068 62 : { $$ = list_make1($1); }
3069 : | alter_identity_column_option_list alter_identity_column_option
3070 60 : { $$ = lappend($1, $2); }
3071 : ;
3072 :
3073 : alter_identity_column_option:
3074 : RESTART
3075 : {
3076 24 : $$ = makeDefElem("restart", NULL, @1);
3077 : }
3078 : | RESTART opt_with NumericOnly
3079 : {
3080 0 : $$ = makeDefElem("restart", (Node *) $3, @1);
3081 : }
3082 : | SET SeqOptElem
3083 : {
3084 54 : if (strcmp($2->defname, "as") == 0 ||
3085 54 : strcmp($2->defname, "restart") == 0 ||
3086 54 : strcmp($2->defname, "owned_by") == 0)
3087 0 : ereport(ERROR,
3088 : (errcode(ERRCODE_SYNTAX_ERROR),
3089 : errmsg("sequence option \"%s\" not supported here", $2->defname),
3090 : parser_errposition(@2)));
3091 54 : $$ = $2;
3092 : }
3093 : | SET GENERATED generated_when
3094 : {
3095 44 : $$ = makeDefElem("generated", (Node *) makeInteger($3), @1);
3096 : }
3097 : ;
3098 :
3099 : set_statistics_value:
3100 158 : SignedIconst { $$ = (Node *) makeInteger($1); }
3101 0 : | DEFAULT { $$ = NULL; }
3102 : ;
3103 :
3104 : set_access_method_name:
3105 92 : ColId { $$ = $1; }
3106 36 : | DEFAULT { $$ = NULL; }
3107 : ;
3108 :
3109 : PartitionBoundSpec:
3110 : /* a HASH partition */
3111 : FOR VALUES WITH '(' hash_partbound ')'
3112 : {
3113 : ListCell *lc;
3114 704 : PartitionBoundSpec *n = makeNode(PartitionBoundSpec);
3115 :
3116 704 : n->strategy = PARTITION_STRATEGY_HASH;
3117 704 : n->modulus = n->remainder = -1;
3118 :
3119 2112 : foreach (lc, $5)
3120 : {
3121 1408 : DefElem *opt = lfirst_node(DefElem, lc);
3122 :
3123 1408 : if (strcmp(opt->defname, "modulus") == 0)
3124 : {
3125 704 : if (n->modulus != -1)
3126 0 : ereport(ERROR,
3127 : (errcode(ERRCODE_DUPLICATE_OBJECT),
3128 : errmsg("modulus for hash partition provided more than once"),
3129 : parser_errposition(opt->location)));
3130 704 : n->modulus = defGetInt32(opt);
3131 : }
3132 704 : else if (strcmp(opt->defname, "remainder") == 0)
3133 : {
3134 704 : if (n->remainder != -1)
3135 0 : ereport(ERROR,
3136 : (errcode(ERRCODE_DUPLICATE_OBJECT),
3137 : errmsg("remainder for hash partition provided more than once"),
3138 : parser_errposition(opt->location)));
3139 704 : n->remainder = defGetInt32(opt);
3140 : }
3141 : else
3142 0 : ereport(ERROR,
3143 : (errcode(ERRCODE_SYNTAX_ERROR),
3144 : errmsg("unrecognized hash partition bound specification \"%s\"",
3145 : opt->defname),
3146 : parser_errposition(opt->location)));
3147 : }
3148 :
3149 704 : if (n->modulus == -1)
3150 0 : ereport(ERROR,
3151 : (errcode(ERRCODE_SYNTAX_ERROR),
3152 : errmsg("modulus for hash partition must be specified"),
3153 : parser_errposition(@3)));
3154 704 : if (n->remainder == -1)
3155 0 : ereport(ERROR,
3156 : (errcode(ERRCODE_SYNTAX_ERROR),
3157 : errmsg("remainder for hash partition must be specified"),
3158 : parser_errposition(@3)));
3159 :
3160 704 : n->location = @3;
3161 :
3162 704 : $$ = n;
3163 : }
3164 :
3165 : /* a LIST partition */
3166 : | FOR VALUES IN_P '(' expr_list ')'
3167 : {
3168 4778 : PartitionBoundSpec *n = makeNode(PartitionBoundSpec);
3169 :
3170 4778 : n->strategy = PARTITION_STRATEGY_LIST;
3171 4778 : n->is_default = false;
3172 4778 : n->listdatums = $5;
3173 4778 : n->location = @3;
3174 :
3175 4778 : $$ = n;
3176 : }
3177 :
3178 : /* a RANGE partition */
3179 : | FOR VALUES FROM '(' expr_list ')' TO '(' expr_list ')'
3180 : {
3181 3934 : PartitionBoundSpec *n = makeNode(PartitionBoundSpec);
3182 :
3183 3934 : n->strategy = PARTITION_STRATEGY_RANGE;
3184 3934 : n->is_default = false;
3185 3934 : n->lowerdatums = $5;
3186 3934 : n->upperdatums = $9;
3187 3934 : n->location = @3;
3188 :
3189 3934 : $$ = n;
3190 : }
3191 :
3192 : /* a DEFAULT partition */
3193 : | DEFAULT
3194 : {
3195 590 : PartitionBoundSpec *n = makeNode(PartitionBoundSpec);
3196 :
3197 590 : n->is_default = true;
3198 590 : n->location = @1;
3199 :
3200 590 : $$ = n;
3201 : }
3202 : ;
3203 :
3204 : hash_partbound_elem:
3205 : NonReservedWord Iconst
3206 : {
3207 1408 : $$ = makeDefElem($1, (Node *) makeInteger($2), @1);
3208 : }
3209 : ;
3210 :
3211 : hash_partbound:
3212 : hash_partbound_elem
3213 : {
3214 704 : $$ = list_make1($1);
3215 : }
3216 : | hash_partbound ',' hash_partbound_elem
3217 : {
3218 704 : $$ = lappend($1, $3);
3219 : }
3220 : ;
3221 :
3222 : /*****************************************************************************
3223 : *
3224 : * ALTER TYPE
3225 : *
3226 : * really variants of the ALTER TABLE subcommands with different spellings
3227 : *****************************************************************************/
3228 :
3229 : AlterCompositeTypeStmt:
3230 : ALTER TYPE_P any_name alter_type_cmds
3231 : {
3232 208 : AlterTableStmt *n = makeNode(AlterTableStmt);
3233 :
3234 : /* can't use qualified_name, sigh */
3235 208 : n->relation = makeRangeVarFromAnyName($3, @3, yyscanner);
3236 208 : n->cmds = $4;
3237 208 : n->objtype = OBJECT_TYPE;
3238 208 : $$ = (Node *) n;
3239 : }
3240 : ;
3241 :
3242 : alter_type_cmds:
3243 208 : alter_type_cmd { $$ = list_make1($1); }
3244 12 : | alter_type_cmds ',' alter_type_cmd { $$ = lappend($1, $3); }
3245 : ;
3246 :
3247 : alter_type_cmd:
3248 : /* ALTER TYPE <name> ADD ATTRIBUTE <coldef> [RESTRICT|CASCADE] */
3249 : ADD_P ATTRIBUTE TableFuncElement opt_drop_behavior
3250 : {
3251 64 : AlterTableCmd *n = makeNode(AlterTableCmd);
3252 :
3253 64 : n->subtype = AT_AddColumn;
3254 64 : n->def = $3;
3255 64 : n->behavior = $4;
3256 64 : $$ = (Node *) n;
3257 : }
3258 : /* ALTER TYPE <name> DROP ATTRIBUTE IF EXISTS <attname> [RESTRICT|CASCADE] */
3259 : | DROP ATTRIBUTE IF_P EXISTS ColId opt_drop_behavior
3260 : {
3261 6 : AlterTableCmd *n = makeNode(AlterTableCmd);
3262 :
3263 6 : n->subtype = AT_DropColumn;
3264 6 : n->name = $5;
3265 6 : n->behavior = $6;
3266 6 : n->missing_ok = true;
3267 6 : $$ = (Node *) n;
3268 : }
3269 : /* ALTER TYPE <name> DROP ATTRIBUTE <attname> [RESTRICT|CASCADE] */
3270 : | DROP ATTRIBUTE ColId opt_drop_behavior
3271 : {
3272 76 : AlterTableCmd *n = makeNode(AlterTableCmd);
3273 :
3274 76 : n->subtype = AT_DropColumn;
3275 76 : n->name = $3;
3276 76 : n->behavior = $4;
3277 76 : n->missing_ok = false;
3278 76 : $$ = (Node *) n;
3279 : }
3280 : /* ALTER TYPE <name> ALTER ATTRIBUTE <attname> [SET DATA] TYPE <typename> [RESTRICT|CASCADE] */
3281 : | ALTER ATTRIBUTE ColId opt_set_data TYPE_P Typename opt_collate_clause opt_drop_behavior
3282 : {
3283 74 : AlterTableCmd *n = makeNode(AlterTableCmd);
3284 74 : ColumnDef *def = makeNode(ColumnDef);
3285 :
3286 74 : n->subtype = AT_AlterColumnType;
3287 74 : n->name = $3;
3288 74 : n->def = (Node *) def;
3289 74 : n->behavior = $8;
3290 : /* We only use these fields of the ColumnDef node */
3291 74 : def->typeName = $6;
3292 74 : def->collClause = (CollateClause *) $7;
3293 74 : def->raw_default = NULL;
3294 74 : def->location = @3;
3295 74 : $$ = (Node *) n;
3296 : }
3297 : ;
3298 :
3299 :
3300 : /*****************************************************************************
3301 : *
3302 : * QUERY :
3303 : * close <portalname>
3304 : *
3305 : *****************************************************************************/
3306 :
3307 : ClosePortalStmt:
3308 : CLOSE cursor_name
3309 : {
3310 2172 : ClosePortalStmt *n = makeNode(ClosePortalStmt);
3311 :
3312 2172 : n->portalname = $2;
3313 2172 : $$ = (Node *) n;
3314 : }
3315 : | CLOSE ALL
3316 : {
3317 12 : ClosePortalStmt *n = makeNode(ClosePortalStmt);
3318 :
3319 12 : n->portalname = NULL;
3320 12 : $$ = (Node *) n;
3321 : }
3322 : ;
3323 :
3324 :
3325 : /*****************************************************************************
3326 : *
3327 : * QUERY :
3328 : * COPY relname [(columnList)] FROM/TO file [WITH] [(options)]
3329 : * COPY ( query ) TO file [WITH] [(options)]
3330 : *
3331 : * where 'query' can be one of:
3332 : * { SELECT | UPDATE | INSERT | DELETE }
3333 : *
3334 : * and 'file' can be one of:
3335 : * { PROGRAM 'command' | STDIN | STDOUT | 'filename' }
3336 : *
3337 : * In the preferred syntax the options are comma-separated
3338 : * and use generic identifiers instead of keywords. The pre-9.0
3339 : * syntax had a hard-wired, space-separated set of options.
3340 : *
3341 : * Really old syntax, from versions 7.2 and prior:
3342 : * COPY [ BINARY ] table FROM/TO file
3343 : * [ [ USING ] DELIMITERS 'delimiter' ] ]
3344 : * [ WITH NULL AS 'null string' ]
3345 : * This option placement is not supported with COPY (query...).
3346 : *
3347 : *****************************************************************************/
3348 :
3349 : CopyStmt: COPY opt_binary qualified_name opt_column_list
3350 : copy_from opt_program copy_file_name copy_delimiter opt_with
3351 : copy_options where_clause
3352 : {
3353 9418 : CopyStmt *n = makeNode(CopyStmt);
3354 :
3355 9418 : n->relation = $3;
3356 9418 : n->query = NULL;
3357 9418 : n->attlist = $4;
3358 9418 : n->is_from = $5;
3359 9418 : n->is_program = $6;
3360 9418 : n->filename = $7;
3361 9418 : n->whereClause = $11;
3362 :
3363 9418 : if (n->is_program && n->filename == NULL)
3364 0 : ereport(ERROR,
3365 : (errcode(ERRCODE_SYNTAX_ERROR),
3366 : errmsg("STDIN/STDOUT not allowed with PROGRAM"),
3367 : parser_errposition(@8)));
3368 :
3369 9418 : if (!n->is_from && n->whereClause != NULL)
3370 6 : ereport(ERROR,
3371 : (errcode(ERRCODE_SYNTAX_ERROR),
3372 : errmsg("WHERE clause not allowed with COPY TO"),
3373 : parser_errposition(@11)));
3374 :
3375 9412 : n->options = NIL;
3376 : /* Concatenate user-supplied flags */
3377 9412 : if ($2)
3378 12 : n->options = lappend(n->options, $2);
3379 9412 : if ($8)
3380 0 : n->options = lappend(n->options, $8);
3381 9412 : if ($10)
3382 878 : n->options = list_concat(n->options, $10);
3383 9412 : $$ = (Node *) n;
3384 : }
3385 : | COPY '(' PreparableStmt ')' TO opt_program copy_file_name opt_with copy_options
3386 : {
3387 436 : CopyStmt *n = makeNode(CopyStmt);
3388 :
3389 436 : updatePreparableStmtEnd($3, @4);
3390 436 : n->relation = NULL;
3391 436 : n->query = $3;
3392 436 : n->attlist = NIL;
3393 436 : n->is_from = false;
3394 436 : n->is_program = $6;
3395 436 : n->filename = $7;
3396 436 : n->options = $9;
3397 :
3398 436 : if (n->is_program && n->filename == NULL)
3399 0 : ereport(ERROR,
3400 : (errcode(ERRCODE_SYNTAX_ERROR),
3401 : errmsg("STDIN/STDOUT not allowed with PROGRAM"),
3402 : parser_errposition(@5)));
3403 :
3404 436 : $$ = (Node *) n;
3405 : }
3406 : ;
3407 :
3408 : copy_from:
3409 1636 : FROM { $$ = true; }
3410 7782 : | TO { $$ = false; }
3411 : ;
3412 :
3413 : opt_program:
3414 0 : PROGRAM { $$ = true; }
3415 9854 : | /* EMPTY */ { $$ = false; }
3416 : ;
3417 :
3418 : /*
3419 : * copy_file_name NULL indicates stdio is used. Whether stdin or stdout is
3420 : * used depends on the direction. (It really doesn't make sense to copy from
3421 : * stdout. We silently correct the "typo".) - AY 9/94
3422 : */
3423 : copy_file_name:
3424 394 : Sconst { $$ = $1; }
3425 1282 : | STDIN { $$ = NULL; }
3426 8178 : | STDOUT { $$ = NULL; }
3427 : ;
3428 :
3429 9270 : copy_options: copy_opt_list { $$ = $1; }
3430 584 : | '(' copy_generic_opt_list ')' { $$ = $2; }
3431 : ;
3432 :
3433 : /* old COPY option syntax */
3434 : copy_opt_list:
3435 504 : copy_opt_list copy_opt_item { $$ = lappend($1, $2); }
3436 9270 : | /* EMPTY */ { $$ = NIL; }
3437 : ;
3438 :
3439 : copy_opt_item:
3440 : BINARY
3441 : {
3442 0 : $$ = makeDefElem("format", (Node *) makeString("binary"), @1);
3443 : }
3444 : | FREEZE
3445 : {
3446 50 : $$ = makeDefElem("freeze", (Node *) makeBoolean(true), @1);
3447 : }
3448 : | DELIMITER opt_as Sconst
3449 : {
3450 172 : $$ = makeDefElem("delimiter", (Node *) makeString($3), @1);
3451 : }
3452 : | NULL_P opt_as Sconst
3453 : {
3454 48 : $$ = makeDefElem("null", (Node *) makeString($3), @1);
3455 : }
3456 : | CSV
3457 : {
3458 150 : $$ = makeDefElem("format", (Node *) makeString("csv"), @1);
3459 : }
3460 : | HEADER_P
3461 : {
3462 18 : $$ = makeDefElem("header", (Node *) makeBoolean(true), @1);
3463 : }
3464 : | QUOTE opt_as Sconst
3465 : {
3466 18 : $$ = makeDefElem("quote", (Node *) makeString($3), @1);
3467 : }
3468 : | ESCAPE opt_as Sconst
3469 : {
3470 18 : $$ = makeDefElem("escape", (Node *) makeString($3), @1);
3471 : }
3472 : | FORCE QUOTE columnList
3473 : {
3474 12 : $$ = makeDefElem("force_quote", (Node *) $3, @1);
3475 : }
3476 : | FORCE QUOTE '*'
3477 : {
3478 6 : $$ = makeDefElem("force_quote", (Node *) makeNode(A_Star), @1);
3479 : }
3480 : | FORCE NOT NULL_P columnList
3481 : {
3482 0 : $$ = makeDefElem("force_not_null", (Node *) $4, @1);
3483 : }
3484 : | FORCE NOT NULL_P '*'
3485 : {
3486 0 : $$ = makeDefElem("force_not_null", (Node *) makeNode(A_Star), @1);
3487 : }
3488 : | FORCE NULL_P columnList
3489 : {
3490 0 : $$ = makeDefElem("force_null", (Node *) $3, @1);
3491 : }
3492 : | FORCE NULL_P '*'
3493 : {
3494 0 : $$ = makeDefElem("force_null", (Node *) makeNode(A_Star), @1);
3495 : }
3496 : | ENCODING Sconst
3497 : {
3498 12 : $$ = makeDefElem("encoding", (Node *) makeString($2), @1);
3499 : }
3500 : ;
3501 :
3502 : /* The following exist for backward compatibility with very old versions */
3503 :
3504 : opt_binary:
3505 : BINARY
3506 : {
3507 12 : $$ = makeDefElem("format", (Node *) makeString("binary"), @1);
3508 : }
3509 9406 : | /*EMPTY*/ { $$ = NULL; }
3510 : ;
3511 :
3512 : copy_delimiter:
3513 : opt_using DELIMITERS Sconst
3514 : {
3515 0 : $$ = makeDefElem("delimiter", (Node *) makeString($3), @2);
3516 : }
3517 9418 : | /*EMPTY*/ { $$ = NULL; }
3518 : ;
3519 :
3520 : opt_using:
3521 : USING
3522 : | /*EMPTY*/
3523 : ;
3524 :
3525 : /* new COPY option syntax */
3526 : copy_generic_opt_list:
3527 : copy_generic_opt_elem
3528 : {
3529 584 : $$ = list_make1($1);
3530 : }
3531 : | copy_generic_opt_list ',' copy_generic_opt_elem
3532 : {
3533 426 : $$ = lappend($1, $3);
3534 : }
3535 : ;
3536 :
3537 : copy_generic_opt_elem:
3538 : ColLabel copy_generic_opt_arg
3539 : {
3540 1010 : $$ = makeDefElem($1, $2, @1);
3541 : }
3542 : ;
3543 :
3544 : copy_generic_opt_arg:
3545 722 : opt_boolean_or_string { $$ = (Node *) makeString($1); }
3546 24 : | NumericOnly { $$ = (Node *) $1; }
3547 90 : | '*' { $$ = (Node *) makeNode(A_Star); }
3548 6 : | DEFAULT { $$ = (Node *) makeString("default"); }
3549 150 : | '(' copy_generic_opt_arg_list ')' { $$ = (Node *) $2; }
3550 18 : | /* EMPTY */ { $$ = NULL; }
3551 : ;
3552 :
3553 : copy_generic_opt_arg_list:
3554 : copy_generic_opt_arg_list_item
3555 : {
3556 150 : $$ = list_make1($1);
3557 : }
3558 : | copy_generic_opt_arg_list ',' copy_generic_opt_arg_list_item
3559 : {
3560 12 : $$ = lappend($1, $3);
3561 : }
3562 : ;
3563 :
3564 : /* beware of emitting non-string list elements here; see commands/define.c */
3565 : copy_generic_opt_arg_list_item:
3566 162 : opt_boolean_or_string { $$ = (Node *) makeString($1); }
3567 : ;
3568 :
3569 :
3570 : /*****************************************************************************
3571 : *
3572 : * QUERY :
3573 : * CREATE TABLE relname
3574 : *
3575 : *****************************************************************************/
3576 :
3577 : CreateStmt: CREATE OptTemp TABLE qualified_name '(' OptTableElementList ')'
3578 : OptInherit OptPartitionSpec table_access_method_clause OptWith
3579 : OnCommitOption OptTableSpace
3580 : {
3581 27382 : CreateStmt *n = makeNode(CreateStmt);
3582 :
3583 27382 : $4->relpersistence = $2;
3584 27382 : n->relation = $4;
3585 27382 : n->tableElts = $6;
3586 27382 : n->inhRelations = $8;
3587 27382 : n->partspec = $9;
3588 27382 : n->ofTypename = NULL;
3589 27382 : n->constraints = NIL;
3590 27382 : n->accessMethod = $10;
3591 27382 : n->options = $11;
3592 27382 : n->oncommit = $12;
3593 27382 : n->tablespacename = $13;
3594 27382 : n->if_not_exists = false;
3595 27382 : $$ = (Node *) n;
3596 : }
3597 : | CREATE OptTemp TABLE IF_P NOT EXISTS qualified_name '('
3598 : OptTableElementList ')' OptInherit OptPartitionSpec table_access_method_clause
3599 : OptWith OnCommitOption OptTableSpace
3600 : {
3601 30 : CreateStmt *n = makeNode(CreateStmt);
3602 :
3603 30 : $7->relpersistence = $2;
3604 30 : n->relation = $7;
3605 30 : n->tableElts = $9;
3606 30 : n->inhRelations = $11;
3607 30 : n->partspec = $12;
3608 30 : n->ofTypename = NULL;
3609 30 : n->constraints = NIL;
3610 30 : n->accessMethod = $13;
3611 30 : n->options = $14;
3612 30 : n->oncommit = $15;
3613 30 : n->tablespacename = $16;
3614 30 : n->if_not_exists = true;
3615 30 : $$ = (Node *) n;
3616 : }
3617 : | CREATE OptTemp TABLE qualified_name OF any_name
3618 : OptTypedTableElementList OptPartitionSpec table_access_method_clause
3619 : OptWith OnCommitOption OptTableSpace
3620 : {
3621 116 : CreateStmt *n = makeNode(CreateStmt);
3622 :
3623 116 : $4->relpersistence = $2;
3624 116 : n->relation = $4;
3625 116 : n->tableElts = $7;
3626 116 : n->inhRelations = NIL;
3627 116 : n->partspec = $8;
3628 116 : n->ofTypename = makeTypeNameFromNameList($6);
3629 116 : n->ofTypename->location = @6;
3630 116 : n->constraints = NIL;
3631 116 : n->accessMethod = $9;
3632 116 : n->options = $10;
3633 116 : n->oncommit = $11;
3634 116 : n->tablespacename = $12;
3635 116 : n->if_not_exists = false;
3636 116 : $$ = (Node *) n;
3637 : }
3638 : | CREATE OptTemp TABLE IF_P NOT EXISTS qualified_name OF any_name
3639 : OptTypedTableElementList OptPartitionSpec table_access_method_clause
3640 : OptWith OnCommitOption OptTableSpace
3641 : {
3642 6 : CreateStmt *n = makeNode(CreateStmt);
3643 :
3644 6 : $7->relpersistence = $2;
3645 6 : n->relation = $7;
3646 6 : n->tableElts = $10;
3647 6 : n->inhRelations = NIL;
3648 6 : n->partspec = $11;
3649 6 : n->ofTypename = makeTypeNameFromNameList($9);
3650 6 : n->ofTypename->location = @9;
3651 6 : n->constraints = NIL;
3652 6 : n->accessMethod = $12;
3653 6 : n->options = $13;
3654 6 : n->oncommit = $14;
3655 6 : n->tablespacename = $15;
3656 6 : n->if_not_exists = true;
3657 6 : $$ = (Node *) n;
3658 : }
3659 : | CREATE OptTemp TABLE qualified_name PARTITION OF qualified_name
3660 : OptTypedTableElementList PartitionBoundSpec OptPartitionSpec
3661 : table_access_method_clause OptWith OnCommitOption OptTableSpace
3662 : {
3663 7688 : CreateStmt *n = makeNode(CreateStmt);
3664 :
3665 7688 : $4->relpersistence = $2;
3666 7688 : n->relation = $4;
3667 7688 : n->tableElts = $8;
3668 7688 : n->inhRelations = list_make1($7);
3669 7688 : n->partbound = $9;
3670 7688 : n->partspec = $10;
3671 7688 : n->ofTypename = NULL;
3672 7688 : n->constraints = NIL;
3673 7688 : n->accessMethod = $11;
3674 7688 : n->options = $12;
3675 7688 : n->oncommit = $13;
3676 7688 : n->tablespacename = $14;
3677 7688 : n->if_not_exists = false;
3678 7688 : $$ = (Node *) n;
3679 : }
3680 : | CREATE OptTemp TABLE IF_P NOT EXISTS qualified_name PARTITION OF
3681 : qualified_name OptTypedTableElementList PartitionBoundSpec OptPartitionSpec
3682 : table_access_method_clause OptWith OnCommitOption OptTableSpace
3683 : {
3684 0 : CreateStmt *n = makeNode(CreateStmt);
3685 :
3686 0 : $7->relpersistence = $2;
3687 0 : n->relation = $7;
3688 0 : n->tableElts = $11;
3689 0 : n->inhRelations = list_make1($10);
3690 0 : n->partbound = $12;
3691 0 : n->partspec = $13;
3692 0 : n->ofTypename = NULL;
3693 0 : n->constraints = NIL;
3694 0 : n->accessMethod = $14;
3695 0 : n->options = $15;
3696 0 : n->oncommit = $16;
3697 0 : n->tablespacename = $17;
3698 0 : n->if_not_exists = true;
3699 0 : $$ = (Node *) n;
3700 : }
3701 : ;
3702 :
3703 : /*
3704 : * Redundancy here is needed to avoid shift/reduce conflicts,
3705 : * since TEMP is not a reserved word. See also OptTempTableName.
3706 : *
3707 : * NOTE: we accept both GLOBAL and LOCAL options. They currently do nothing,
3708 : * but future versions might consider GLOBAL to request SQL-spec-compliant
3709 : * temp table behavior, so warn about that. Since we have no modules the
3710 : * LOCAL keyword is really meaningless; furthermore, some other products
3711 : * implement LOCAL as meaning the same as our default temp table behavior,
3712 : * so we'll probably continue to treat LOCAL as a noise word.
3713 : */
3714 306 : OptTemp: TEMPORARY { $$ = RELPERSISTENCE_TEMP; }
3715 2654 : | TEMP { $$ = RELPERSISTENCE_TEMP; }
3716 0 : | LOCAL TEMPORARY { $$ = RELPERSISTENCE_TEMP; }
3717 0 : | LOCAL TEMP { $$ = RELPERSISTENCE_TEMP; }
3718 : | GLOBAL TEMPORARY
3719 : {
3720 0 : ereport(WARNING,
3721 : (errmsg("GLOBAL is deprecated in temporary table creation"),
3722 : parser_errposition(@1)));
3723 0 : $$ = RELPERSISTENCE_TEMP;
3724 : }
3725 : | GLOBAL TEMP
3726 : {
3727 0 : ereport(WARNING,
3728 : (errmsg("GLOBAL is deprecated in temporary table creation"),
3729 : parser_errposition(@1)));
3730 0 : $$ = RELPERSISTENCE_TEMP;
3731 : }
3732 152 : | UNLOGGED { $$ = RELPERSISTENCE_UNLOGGED; }
3733 49332 : | /*EMPTY*/ { $$ = RELPERSISTENCE_PERMANENT; }
3734 : ;
3735 :
3736 : OptTableElementList:
3737 26356 : TableElementList { $$ = $1; }
3738 1458 : | /*EMPTY*/ { $$ = NIL; }
3739 : ;
3740 :
3741 : OptTypedTableElementList:
3742 306 : '(' TypedTableElementList ')' { $$ = $2; }
3743 7600 : | /*EMPTY*/ { $$ = NIL; }
3744 : ;
3745 :
3746 : TableElementList:
3747 : TableElement
3748 : {
3749 26404 : $$ = list_make1($1);
3750 : }
3751 : | TableElementList ',' TableElement
3752 : {
3753 38054 : $$ = lappend($1, $3);
3754 : }
3755 : ;
3756 :
3757 : TypedTableElementList:
3758 : TypedTableElement
3759 : {
3760 306 : $$ = list_make1($1);
3761 : }
3762 : | TypedTableElementList ',' TypedTableElement
3763 : {
3764 68 : $$ = lappend($1, $3);
3765 : }
3766 : ;
3767 :
3768 : TableElement:
3769 61170 : columnDef { $$ = $1; }
3770 750 : | TableLikeClause { $$ = $1; }
3771 2538 : | TableConstraint { $$ = $1; }
3772 : ;
3773 :
3774 : TypedTableElement:
3775 304 : columnOptions { $$ = $1; }
3776 70 : | TableConstraint { $$ = $1; }
3777 : ;
3778 :
3779 : columnDef: ColId Typename opt_column_storage opt_column_compression create_generic_options ColQualList
3780 : {
3781 63132 : ColumnDef *n = makeNode(ColumnDef);
3782 :
3783 63132 : n->colname = $1;
3784 63132 : n->typeName = $2;
3785 63132 : n->storage_name = $3;
3786 63132 : n->compression = $4;
3787 63132 : n->inhcount = 0;
3788 63132 : n->is_local = true;
3789 63132 : n->is_not_null = false;
3790 63132 : n->is_from_type = false;
3791 63132 : n->storage = 0;
3792 63132 : n->raw_default = NULL;
3793 63132 : n->cooked_default = NULL;
3794 63132 : n->collOid = InvalidOid;
3795 63132 : n->fdwoptions = $5;
3796 63132 : SplitColQualList($6, &n->constraints, &n->collClause,
3797 : yyscanner);
3798 63132 : n->location = @1;
3799 63132 : $$ = (Node *) n;
3800 : }
3801 : ;
3802 :
3803 : columnOptions: ColId ColQualList
3804 : {
3805 120 : ColumnDef *n = makeNode(ColumnDef);
3806 :
3807 120 : n->colname = $1;
3808 120 : n->typeName = NULL;
3809 120 : n->inhcount = 0;
3810 120 : n->is_local = true;
3811 120 : n->is_not_null = false;
3812 120 : n->is_from_type = false;
3813 120 : n->storage = 0;
3814 120 : n->raw_default = NULL;
3815 120 : n->cooked_default = NULL;
3816 120 : n->collOid = InvalidOid;
3817 120 : SplitColQualList($2, &n->constraints, &n->collClause,
3818 : yyscanner);
3819 120 : n->location = @1;
3820 120 : $$ = (Node *) n;
3821 : }
3822 : | ColId WITH OPTIONS ColQualList
3823 : {
3824 184 : ColumnDef *n = makeNode(ColumnDef);
3825 :
3826 184 : n->colname = $1;
3827 184 : n->typeName = NULL;
3828 184 : n->inhcount = 0;
3829 184 : n->is_local = true;
3830 184 : n->is_not_null = false;
3831 184 : n->is_from_type = false;
3832 184 : n->storage = 0;
3833 184 : n->raw_default = NULL;
3834 184 : n->cooked_default = NULL;
3835 184 : n->collOid = InvalidOid;
3836 184 : SplitColQualList($4, &n->constraints, &n->collClause,
3837 : yyscanner);
3838 184 : n->location = @1;
3839 184 : $$ = (Node *) n;
3840 : }
3841 : ;
3842 :
3843 : column_compression:
3844 138 : COMPRESSION ColId { $$ = $2; }
3845 6 : | COMPRESSION DEFAULT { $$ = pstrdup("default"); }
3846 : ;
3847 :
3848 : opt_column_compression:
3849 76 : column_compression { $$ = $1; }
3850 63116 : | /*EMPTY*/ { $$ = NULL; }
3851 : ;
3852 :
3853 : column_storage:
3854 226 : STORAGE ColId { $$ = $2; }
3855 6 : | STORAGE DEFAULT { $$ = pstrdup("default"); }
3856 : ;
3857 :
3858 : opt_column_storage:
3859 20 : column_storage { $$ = $1; }
3860 63172 : | /*EMPTY*/ { $$ = NULL; }
3861 : ;
3862 :
3863 : ColQualList:
3864 17432 : ColQualList ColConstraint { $$ = lappend($1, $2); }
3865 64740 : | /*EMPTY*/ { $$ = NIL; }
3866 : ;
3867 :
3868 : ColConstraint:
3869 : CONSTRAINT name ColConstraintElem
3870 : {
3871 644 : Constraint *n = castNode(Constraint, $3);
3872 :
3873 644 : n->conname = $2;
3874 644 : n->location = @1;
3875 644 : $$ = (Node *) n;
3876 : }
3877 15926 : | ColConstraintElem { $$ = $1; }
3878 180 : | ConstraintAttr { $$ = $1; }
3879 : | COLLATE any_name
3880 : {
3881 : /*
3882 : * Note: the CollateClause is momentarily included in
3883 : * the list built by ColQualList, but we split it out
3884 : * again in SplitColQualList.
3885 : */
3886 682 : CollateClause *n = makeNode(CollateClause);
3887 :
3888 682 : n->arg = NULL;
3889 682 : n->collname = $2;
3890 682 : n->location = @1;
3891 682 : $$ = (Node *) n;
3892 : }
3893 : ;
3894 :
3895 : /* DEFAULT NULL is already the default for Postgres.
3896 : * But define it here and carry it forward into the system
3897 : * to make it explicit.
3898 : * - thomas 1998-09-13
3899 : *
3900 : * WITH NULL and NULL are not SQL-standard syntax elements,
3901 : * so leave them out. Use DEFAULT NULL to explicitly indicate
3902 : * that a column may have that value. WITH NULL leads to
3903 : * shift/reduce conflicts with WITH TIME ZONE anyway.
3904 : * - thomas 1999-01-08
3905 : *
3906 : * DEFAULT expression must be b_expr not a_expr to prevent shift/reduce
3907 : * conflict on NOT (since NOT might start a subsequent NOT NULL constraint,
3908 : * or be part of a_expr NOT LIKE or similar constructs).
3909 : */
3910 : ColConstraintElem:
3911 : NOT NULL_P opt_no_inherit
3912 : {
3913 6244 : Constraint *n = makeNode(Constraint);
3914 :
3915 6244 : n->contype = CONSTR_NOTNULL;
3916 6244 : n->location = @1;
3917 6244 : n->is_no_inherit = $3;
3918 6244 : n->skip_validation = false;
3919 6244 : n->initially_valid = true;
3920 6244 : $$ = (Node *) n;
3921 : }
3922 : | NULL_P
3923 : {
3924 24 : Constraint *n = makeNode(Constraint);
3925 :
3926 24 : n->contype = CONSTR_NULL;
3927 24 : n->location = @1;
3928 24 : $$ = (Node *) n;
3929 : }
3930 : | UNIQUE opt_unique_null_treatment opt_definition OptConsTableSpace
3931 : {
3932 392 : Constraint *n = makeNode(Constraint);
3933 :
3934 392 : n->contype = CONSTR_UNIQUE;
3935 392 : n->location = @1;
3936 392 : n->nulls_not_distinct = !$2;
3937 392 : n->keys = NULL;
3938 392 : n->options = $3;
3939 392 : n->indexname = NULL;
3940 392 : n->indexspace = $4;
3941 392 : $$ = (Node *) n;
3942 : }
3943 : | PRIMARY KEY opt_definition OptConsTableSpace
3944 : {
3945 5406 : Constraint *n = makeNode(Constraint);
3946 :
3947 5406 : n->contype = CONSTR_PRIMARY;
3948 5406 : n->location = @1;
3949 5406 : n->keys = NULL;
3950 5406 : n->options = $3;
3951 5406 : n->indexname = NULL;
3952 5406 : n->indexspace = $4;
3953 5406 : $$ = (Node *) n;
3954 : }
3955 : | CHECK '(' a_expr ')' opt_no_inherit
3956 : {
3957 916 : Constraint *n = makeNode(Constraint);
3958 :
3959 916 : n->contype = CONSTR_CHECK;
3960 916 : n->location = @1;
3961 916 : n->is_no_inherit = $5;
3962 916 : n->raw_expr = $3;
3963 916 : n->cooked_expr = NULL;
3964 916 : n->skip_validation = false;
3965 916 : n->initially_valid = true;
3966 916 : $$ = (Node *) n;
3967 : }
3968 : | DEFAULT b_expr
3969 : {
3970 1650 : Constraint *n = makeNode(Constraint);
3971 :
3972 1650 : n->contype = CONSTR_DEFAULT;
3973 1650 : n->location = @1;
3974 1650 : n->raw_expr = $2;
3975 1650 : n->cooked_expr = NULL;
3976 1650 : $$ = (Node *) n;
3977 : }
3978 : | GENERATED generated_when AS IDENTITY_P OptParenthesizedSeqOptList
3979 : {
3980 296 : Constraint *n = makeNode(Constraint);
3981 :
3982 296 : n->contype = CONSTR_IDENTITY;
3983 296 : n->generated_when = $2;
3984 296 : n->options = $5;
3985 296 : n->location = @1;
3986 296 : $$ = (Node *) n;
3987 : }
3988 : | GENERATED generated_when AS '(' a_expr ')' STORED
3989 : {
3990 886 : Constraint *n = makeNode(Constraint);
3991 :
3992 886 : n->contype = CONSTR_GENERATED;
3993 886 : n->generated_when = $2;
3994 886 : n->raw_expr = $5;
3995 886 : n->cooked_expr = NULL;
3996 886 : n->location = @1;
3997 :
3998 : /*
3999 : * Can't do this in the grammar because of shift/reduce
4000 : * conflicts. (IDENTITY allows both ALWAYS and BY
4001 : * DEFAULT, but generated columns only allow ALWAYS.) We
4002 : * can also give a more useful error message and location.
4003 : */
4004 886 : if ($2 != ATTRIBUTE_IDENTITY_ALWAYS)
4005 6 : ereport(ERROR,
4006 : (errcode(ERRCODE_SYNTAX_ERROR),
4007 : errmsg("for a generated column, GENERATED ALWAYS must be specified"),
4008 : parser_errposition(@2)));
4009 :
4010 880 : $$ = (Node *) n;
4011 : }
4012 : | REFERENCES qualified_name opt_column_list key_match key_actions
4013 : {
4014 762 : Constraint *n = makeNode(Constraint);
4015 :
4016 762 : n->contype = CONSTR_FOREIGN;
4017 762 : n->location = @1;
4018 762 : n->pktable = $2;
4019 762 : n->fk_attrs = NIL;
4020 762 : n->pk_attrs = $3;
4021 762 : n->fk_matchtype = $4;
4022 762 : n->fk_upd_action = ($5)->updateAction->action;
4023 762 : n->fk_del_action = ($5)->deleteAction->action;
4024 762 : n->fk_del_set_cols = ($5)->deleteAction->cols;
4025 762 : n->skip_validation = false;
4026 762 : n->initially_valid = true;
4027 762 : $$ = (Node *) n;
4028 : }
4029 : ;
4030 :
4031 : opt_unique_null_treatment:
4032 12 : NULLS_P DISTINCT { $$ = true; }
4033 30 : | NULLS_P NOT DISTINCT { $$ = false; }
4034 7294 : | /*EMPTY*/ { $$ = true; }
4035 : ;
4036 :
4037 : generated_when:
4038 1216 : ALWAYS { $$ = ATTRIBUTE_IDENTITY_ALWAYS; }
4039 170 : | BY DEFAULT { $$ = ATTRIBUTE_IDENTITY_BY_DEFAULT; }
4040 : ;
4041 :
4042 : /*
4043 : * ConstraintAttr represents constraint attributes, which we parse as if
4044 : * they were independent constraint clauses, in order to avoid shift/reduce
4045 : * conflicts (since NOT might start either an independent NOT NULL clause
4046 : * or an attribute). parse_utilcmd.c is responsible for attaching the
4047 : * attribute information to the preceding "real" constraint node, and for
4048 : * complaining if attribute clauses appear in the wrong place or wrong
4049 : * combinations.
4050 : *
4051 : * See also ConstraintAttributeSpec, which can be used in places where
4052 : * there is no parsing conflict. (Note: currently, NOT VALID and NO INHERIT
4053 : * are allowed clauses in ConstraintAttributeSpec, but not here. Someday we
4054 : * might need to allow them here too, but for the moment it doesn't seem
4055 : * useful in the statements that use ConstraintAttr.)
4056 : */
4057 : ConstraintAttr:
4058 : DEFERRABLE
4059 : {
4060 96 : Constraint *n = makeNode(Constraint);
4061 :
4062 96 : n->contype = CONSTR_ATTR_DEFERRABLE;
4063 96 : n->location = @1;
4064 96 : $$ = (Node *) n;
4065 : }
4066 : | NOT DEFERRABLE
4067 : {
4068 0 : Constraint *n = makeNode(Constraint);
4069 :
4070 0 : n->contype = CONSTR_ATTR_NOT_DEFERRABLE;
4071 0 : n->location = @1;
4072 0 : $$ = (Node *) n;
4073 : }
4074 : | INITIALLY DEFERRED
4075 : {
4076 78 : Constraint *n = makeNode(Constraint);
4077 :
4078 78 : n->contype = CONSTR_ATTR_DEFERRED;
4079 78 : n->location = @1;
4080 78 : $$ = (Node *) n;
4081 : }
4082 : | INITIALLY IMMEDIATE
4083 : {
4084 6 : Constraint *n = makeNode(Constraint);
4085 :
4086 6 : n->contype = CONSTR_ATTR_IMMEDIATE;
4087 6 : n->location = @1;
4088 6 : $$ = (Node *) n;
4089 : }
4090 : ;
4091 :
4092 :
4093 : TableLikeClause:
4094 : LIKE qualified_name TableLikeOptionList
4095 : {
4096 750 : TableLikeClause *n = makeNode(TableLikeClause);
4097 :
4098 750 : n->relation = $2;
4099 750 : n->options = $3;
4100 750 : n->relationOid = InvalidOid;
4101 750 : $$ = (Node *) n;
4102 : }
4103 : ;
4104 :
4105 : TableLikeOptionList:
4106 270 : TableLikeOptionList INCLUDING TableLikeOption { $$ = $1 | $3; }
4107 2 : | TableLikeOptionList EXCLUDING TableLikeOption { $$ = $1 & ~$3; }
4108 750 : | /* EMPTY */ { $$ = 0; }
4109 : ;
4110 :
4111 : TableLikeOption:
4112 24 : COMMENTS { $$ = CREATE_TABLE_LIKE_COMMENTS; }
4113 6 : | COMPRESSION { $$ = CREATE_TABLE_LIKE_COMPRESSION; }
4114 54 : | CONSTRAINTS { $$ = CREATE_TABLE_LIKE_CONSTRAINTS; }
4115 20 : | DEFAULTS { $$ = CREATE_TABLE_LIKE_DEFAULTS; }
4116 12 : | IDENTITY_P { $$ = CREATE_TABLE_LIKE_IDENTITY; }
4117 24 : | GENERATED { $$ = CREATE_TABLE_LIKE_GENERATED; }
4118 50 : | INDEXES { $$ = CREATE_TABLE_LIKE_INDEXES; }
4119 0 : | STATISTICS { $$ = CREATE_TABLE_LIKE_STATISTICS; }
4120 26 : | STORAGE { $$ = CREATE_TABLE_LIKE_STORAGE; }
4121 56 : | ALL { $$ = CREATE_TABLE_LIKE_ALL; }
4122 : ;
4123 :
4124 :
4125 : /* ConstraintElem specifies constraint syntax which is not embedded into
4126 : * a column definition. ColConstraintElem specifies the embedded form.
4127 : * - thomas 1997-12-03
4128 : */
4129 : TableConstraint:
4130 : CONSTRAINT name ConstraintElem
4131 : {
4132 3684 : Constraint *n = castNode(Constraint, $3);
4133 :
4134 3684 : n->conname = $2;
4135 3684 : n->location = @1;
4136 3684 : $$ = (Node *) n;
4137 : }
4138 11934 : | ConstraintElem { $$ = $1; }
4139 : ;
4140 :
4141 : ConstraintElem:
4142 : CHECK '(' a_expr ')' ConstraintAttributeSpec
4143 : {
4144 1062 : Constraint *n = makeNode(Constraint);
4145 :
4146 1062 : n->contype = CONSTR_CHECK;
4147 1062 : n->location = @1;
4148 1062 : n->raw_expr = $3;
4149 1062 : n->cooked_expr = NULL;
4150 1062 : processCASbits($5, @5, "CHECK",
4151 : NULL, NULL, &n->skip_validation,
4152 : &n->is_no_inherit, yyscanner);
4153 1062 : n->initially_valid = !n->skip_validation;
4154 1062 : $$ = (Node *) n;
4155 : }
4156 : | NOT NULL_P ColId ConstraintAttributeSpec
4157 : {
4158 386 : Constraint *n = makeNode(Constraint);
4159 :
4160 386 : n->contype = CONSTR_NOTNULL;
4161 386 : n->location = @1;
4162 386 : n->keys = list_make1(makeString($3));
4163 : /* no NOT VALID support yet */
4164 386 : processCASbits($4, @4, "NOT NULL",
4165 : NULL, NULL, NULL,
4166 : &n->is_no_inherit, yyscanner);
4167 386 : n->initially_valid = true;
4168 386 : $$ = (Node *) n;
4169 : }
4170 : | UNIQUE opt_unique_null_treatment '(' columnList opt_without_overlaps ')' opt_c_include opt_definition OptConsTableSpace
4171 : ConstraintAttributeSpec
4172 : {
4173 594 : Constraint *n = makeNode(Constraint);
4174 :
4175 594 : n->contype = CONSTR_UNIQUE;
4176 594 : n->location = @1;
4177 594 : n->nulls_not_distinct = !$2;
4178 594 : n->keys = $4;
4179 594 : n->without_overlaps = $5;
4180 594 : n->including = $7;
4181 594 : n->options = $8;
4182 594 : n->indexname = NULL;
4183 594 : n->indexspace = $9;
4184 594 : processCASbits($10, @10, "UNIQUE",
4185 : &n->deferrable, &n->initdeferred, NULL,
4186 : NULL, yyscanner);
4187 594 : $$ = (Node *) n;
4188 : }
4189 : | UNIQUE ExistingIndex ConstraintAttributeSpec
4190 : {
4191 4168 : Constraint *n = makeNode(Constraint);
4192 :
4193 4168 : n->contype = CONSTR_UNIQUE;
4194 4168 : n->location = @1;
4195 4168 : n->keys = NIL;
4196 4168 : n->including = NIL;
4197 4168 : n->options = NIL;
4198 4168 : n->indexname = $2;
4199 4168 : n->indexspace = NULL;
4200 4168 : processCASbits($3, @3, "UNIQUE",
4201 : &n->deferrable, &n->initdeferred, NULL,
4202 : NULL, yyscanner);
4203 4168 : $$ = (Node *) n;
4204 : }
4205 : | PRIMARY KEY '(' columnList opt_without_overlaps ')' opt_c_include opt_definition OptConsTableSpace
4206 : ConstraintAttributeSpec
4207 : {
4208 2026 : Constraint *n = makeNode(Constraint);
4209 :
4210 2026 : n->contype = CONSTR_PRIMARY;
4211 2026 : n->location = @1;
4212 2026 : n->keys = $4;
4213 2026 : n->without_overlaps = $5;
4214 2026 : n->including = $7;
4215 2026 : n->options = $8;
4216 2026 : n->indexname = NULL;
4217 2026 : n->indexspace = $9;
4218 2026 : processCASbits($10, @10, "PRIMARY KEY",
4219 : &n->deferrable, &n->initdeferred, NULL,
4220 : NULL, yyscanner);
4221 2026 : $$ = (Node *) n;
4222 : }
4223 : | PRIMARY KEY ExistingIndex ConstraintAttributeSpec
4224 : {
4225 5398 : Constraint *n = makeNode(Constraint);
4226 :
4227 5398 : n->contype = CONSTR_PRIMARY;
4228 5398 : n->location = @1;
4229 5398 : n->keys = NIL;
4230 5398 : n->including = NIL;
4231 5398 : n->options = NIL;
4232 5398 : n->indexname = $3;
4233 5398 : n->indexspace = NULL;
4234 5398 : processCASbits($4, @4, "PRIMARY KEY",
4235 : &n->deferrable, &n->initdeferred, NULL,
4236 : NULL, yyscanner);
4237 5398 : $$ = (Node *) n;
4238 : }
4239 : | EXCLUDE access_method_clause '(' ExclusionConstraintList ')'
4240 : opt_c_include opt_definition OptConsTableSpace OptWhereClause
4241 : ConstraintAttributeSpec
4242 : {
4243 234 : Constraint *n = makeNode(Constraint);
4244 :
4245 234 : n->contype = CONSTR_EXCLUSION;
4246 234 : n->location = @1;
4247 234 : n->access_method = $2;
4248 234 : n->exclusions = $4;
4249 234 : n->including = $6;
4250 234 : n->options = $7;
4251 234 : n->indexname = NULL;
4252 234 : n->indexspace = $8;
4253 234 : n->where_clause = $9;
4254 234 : processCASbits($10, @10, "EXCLUDE",
4255 : &n->deferrable, &n->initdeferred, NULL,
4256 : NULL, yyscanner);
4257 234 : $$ = (Node *) n;
4258 : }
4259 : | FOREIGN KEY '(' columnList optionalPeriodName ')' REFERENCES qualified_name
4260 : opt_column_and_period_list key_match key_actions ConstraintAttributeSpec
4261 : {
4262 1750 : Constraint *n = makeNode(Constraint);
4263 :
4264 1750 : n->contype = CONSTR_FOREIGN;
4265 1750 : n->location = @1;
4266 1750 : n->pktable = $8;
4267 1750 : n->fk_attrs = $4;
4268 1750 : if ($5)
4269 : {
4270 310 : n->fk_attrs = lappend(n->fk_attrs, $5);
4271 310 : n->fk_with_period = true;
4272 : }
4273 1750 : n->pk_attrs = linitial($9);
4274 1750 : if (lsecond($9))
4275 : {
4276 178 : n->pk_attrs = lappend(n->pk_attrs, lsecond($9));
4277 178 : n->pk_with_period = true;
4278 : }
4279 1750 : n->fk_matchtype = $10;
4280 1750 : n->fk_upd_action = ($11)->updateAction->action;
4281 1750 : n->fk_del_action = ($11)->deleteAction->action;
4282 1750 : n->fk_del_set_cols = ($11)->deleteAction->cols;
4283 1750 : processCASbits($12, @12, "FOREIGN KEY",
4284 : &n->deferrable, &n->initdeferred,
4285 : &n->skip_validation, NULL,
4286 : yyscanner);
4287 1750 : n->initially_valid = !n->skip_validation;
4288 1750 : $$ = (Node *) n;
4289 : }
4290 : ;
4291 :
4292 : /*
4293 : * DomainConstraint is separate from TableConstraint because the syntax for
4294 : * NOT NULL constraints is different. For table constraints, we need to
4295 : * accept a column name, but for domain constraints, we don't. (We could
4296 : * accept something like NOT NULL VALUE, but that seems weird.) CREATE DOMAIN
4297 : * (which uses ColQualList) has for a long time accepted NOT NULL without a
4298 : * column name, so it makes sense that ALTER DOMAIN (which uses
4299 : * DomainConstraint) does as well. None of these syntaxes are per SQL
4300 : * standard; we are just living with the bits of inconsistency that have built
4301 : * up over time.
4302 : */
4303 : DomainConstraint:
4304 : CONSTRAINT name DomainConstraintElem
4305 : {
4306 150 : Constraint *n = castNode(Constraint, $3);
4307 :
4308 150 : n->conname = $2;
4309 150 : n->location = @1;
4310 150 : $$ = (Node *) n;
4311 : }
4312 18 : | DomainConstraintElem { $$ = $1; }
4313 : ;
4314 :
4315 : DomainConstraintElem:
4316 : CHECK '(' a_expr ')' ConstraintAttributeSpec
4317 : {
4318 144 : Constraint *n = makeNode(Constraint);
4319 :
4320 144 : n->contype = CONSTR_CHECK;
4321 144 : n->location = @1;
4322 144 : n->raw_expr = $3;
4323 144 : n->cooked_expr = NULL;
4324 144 : processCASbits($5, @5, "CHECK",
4325 : NULL, NULL, &n->skip_validation,
4326 : &n->is_no_inherit, yyscanner);
4327 144 : n->initially_valid = !n->skip_validation;
4328 144 : $$ = (Node *) n;
4329 : }
4330 : | NOT NULL_P ConstraintAttributeSpec
4331 : {
4332 24 : Constraint *n = makeNode(Constraint);
4333 :
4334 24 : n->contype = CONSTR_NOTNULL;
4335 24 : n->location = @1;
4336 24 : n->keys = list_make1(makeString("value"));
4337 : /* no NOT VALID, NO INHERIT support */
4338 24 : processCASbits($3, @3, "NOT NULL",
4339 : NULL, NULL, NULL,
4340 : NULL, yyscanner);
4341 24 : n->initially_valid = true;
4342 24 : $$ = (Node *) n;
4343 : }
4344 : ;
4345 :
4346 102 : opt_no_inherit: NO INHERIT { $$ = true; }
4347 7058 : | /* EMPTY */ { $$ = false; }
4348 : ;
4349 :
4350 : opt_without_overlaps:
4351 522 : WITHOUT OVERLAPS { $$ = true; }
4352 2098 : | /*EMPTY*/ { $$ = false; }
4353 : ;
4354 :
4355 : opt_column_list:
4356 9000 : '(' columnList ')' { $$ = $2; }
4357 38186 : | /*EMPTY*/ { $$ = NIL; }
4358 : ;
4359 :
4360 : columnList:
4361 15066 : columnElem { $$ = list_make1($1); }
4362 26962 : | columnList ',' columnElem { $$ = lappend($1, $3); }
4363 : ;
4364 :
4365 : optionalPeriodName:
4366 488 : ',' PERIOD columnElem { $$ = $3; }
4367 2400 : | /*EMPTY*/ { $$ = NULL; }
4368 : ;
4369 :
4370 : opt_column_and_period_list:
4371 1132 : '(' columnList optionalPeriodName ')' { $$ = list_make2($2, $3); }
4372 624 : | /*EMPTY*/ { $$ = list_make2(NIL, NULL); }
4373 : ;
4374 :
4375 : columnElem: ColId
4376 : {
4377 42516 : $$ = (Node *) makeString($1);
4378 : }
4379 : ;
4380 :
4381 168 : opt_c_include: INCLUDE '(' columnList ')' { $$ = $3; }
4382 2686 : | /* EMPTY */ { $$ = NIL; }
4383 : ;
4384 :
4385 : key_match: MATCH FULL
4386 : {
4387 98 : $$ = FKCONSTR_MATCH_FULL;
4388 : }
4389 : | MATCH PARTIAL
4390 : {
4391 0 : ereport(ERROR,
4392 : (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
4393 : errmsg("MATCH PARTIAL not yet implemented"),
4394 : parser_errposition(@1)));
4395 : $$ = FKCONSTR_MATCH_PARTIAL;
4396 : }
4397 : | MATCH SIMPLE
4398 : {
4399 6 : $$ = FKCONSTR_MATCH_SIMPLE;
4400 : }
4401 : | /*EMPTY*/
4402 : {
4403 2414 : $$ = FKCONSTR_MATCH_SIMPLE;
4404 : }
4405 : ;
4406 :
4407 : ExclusionConstraintList:
4408 234 : ExclusionConstraintElem { $$ = list_make1($1); }
4409 : | ExclusionConstraintList ',' ExclusionConstraintElem
4410 106 : { $$ = lappend($1, $3); }
4411 : ;
4412 :
4413 : ExclusionConstraintElem: index_elem WITH any_operator
4414 : {
4415 340 : $$ = list_make2($1, $3);
4416 : }
4417 : /* allow OPERATOR() decoration for the benefit of ruleutils.c */
4418 : | index_elem WITH OPERATOR '(' any_operator ')'
4419 : {
4420 0 : $$ = list_make2($1, $5);
4421 : }
4422 : ;
4423 :
4424 : OptWhereClause:
4425 426 : WHERE '(' a_expr ')' { $$ = $3; }
4426 1190 : | /*EMPTY*/ { $$ = NULL; }
4427 : ;
4428 :
4429 : key_actions:
4430 : key_update
4431 : {
4432 50 : KeyActions *n = palloc(sizeof(KeyActions));
4433 :
4434 50 : n->updateAction = $1;
4435 50 : n->deleteAction = palloc(sizeof(KeyAction));
4436 50 : n->deleteAction->action = FKCONSTR_ACTION_NOACTION;
4437 50 : n->deleteAction->cols = NIL;
4438 50 : $$ = n;
4439 : }
4440 : | key_delete
4441 : {
4442 166 : KeyActions *n = palloc(sizeof(KeyActions));
4443 :
4444 166 : n->updateAction = palloc(sizeof(KeyAction));
4445 166 : n->updateAction->action = FKCONSTR_ACTION_NOACTION;
4446 166 : n->updateAction->cols = NIL;
4447 166 : n->deleteAction = $1;
4448 166 : $$ = n;
4449 : }
4450 : | key_update key_delete
4451 : {
4452 150 : KeyActions *n = palloc(sizeof(KeyActions));
4453 :
4454 150 : n->updateAction = $1;
4455 150 : n->deleteAction = $2;
4456 150 : $$ = n;
4457 : }
4458 : | key_delete key_update
4459 : {
4460 150 : KeyActions *n = palloc(sizeof(KeyActions));
4461 :
4462 150 : n->updateAction = $2;
4463 150 : n->deleteAction = $1;
4464 150 : $$ = n;
4465 : }
4466 : | /*EMPTY*/
4467 : {
4468 1996 : KeyActions *n = palloc(sizeof(KeyActions));
4469 :
4470 1996 : n->updateAction = palloc(sizeof(KeyAction));
4471 1996 : n->updateAction->action = FKCONSTR_ACTION_NOACTION;
4472 1996 : n->updateAction->cols = NIL;
4473 1996 : n->deleteAction = palloc(sizeof(KeyAction));
4474 1996 : n->deleteAction->action = FKCONSTR_ACTION_NOACTION;
4475 1996 : n->deleteAction->cols = NIL;
4476 1996 : $$ = n;
4477 : }
4478 : ;
4479 :
4480 : key_update: ON UPDATE key_action
4481 : {
4482 356 : if (($3)->cols)
4483 6 : ereport(ERROR,
4484 : (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
4485 : errmsg("a column list with %s is only supported for ON DELETE actions",
4486 : ($3)->action == FKCONSTR_ACTION_SETNULL ? "SET NULL" : "SET DEFAULT"),
4487 : parser_errposition(@1)));
4488 350 : $$ = $3;
4489 : }
4490 : ;
4491 :
4492 : key_delete: ON DELETE_P key_action
4493 : {
4494 466 : $$ = $3;
4495 : }
4496 : ;
4497 :
4498 : key_action:
4499 : NO ACTION
4500 : {
4501 74 : KeyAction *n = palloc(sizeof(KeyAction));
4502 :
4503 74 : n->action = FKCONSTR_ACTION_NOACTION;
4504 74 : n->cols = NIL;
4505 74 : $$ = n;
4506 : }
4507 : | RESTRICT
4508 : {
4509 64 : KeyAction *n = palloc(sizeof(KeyAction));
4510 :
4511 64 : n->action = FKCONSTR_ACTION_RESTRICT;
4512 64 : n->cols = NIL;
4513 64 : $$ = n;
4514 : }
4515 : | CASCADE
4516 : {
4517 398 : KeyAction *n = palloc(sizeof(KeyAction));
4518 :
4519 398 : n->action = FKCONSTR_ACTION_CASCADE;
4520 398 : n->cols = NIL;
4521 398 : $$ = n;
4522 : }
4523 : | SET NULL_P opt_column_list
4524 : {
4525 184 : KeyAction *n = palloc(sizeof(KeyAction));
4526 :
4527 184 : n->action = FKCONSTR_ACTION_SETNULL;
4528 184 : n->cols = $3;
4529 184 : $$ = n;
4530 : }
4531 : | SET DEFAULT opt_column_list
4532 : {
4533 102 : KeyAction *n = palloc(sizeof(KeyAction));
4534 :
4535 102 : n->action = FKCONSTR_ACTION_SETDEFAULT;
4536 102 : n->cols = $3;
4537 102 : $$ = n;
4538 : }
4539 : ;
4540 :
4541 1866 : OptInherit: INHERITS '(' qualified_name_list ')' { $$ = $3; }
4542 25930 : | /*EMPTY*/ { $$ = NIL; }
4543 : ;
4544 :
4545 : /* Optional partition key specification */
4546 4802 : OptPartitionSpec: PartitionSpec { $$ = $1; }
4547 30432 : | /*EMPTY*/ { $$ = NULL; }
4548 : ;
4549 :
4550 : PartitionSpec: PARTITION BY ColId '(' part_params ')'
4551 : {
4552 4808 : PartitionSpec *n = makeNode(PartitionSpec);
4553 :
4554 4808 : n->strategy = parsePartitionStrategy($3, @3, yyscanner);
4555 4802 : n->partParams = $5;
4556 4802 : n->location = @1;
4557 :
4558 4802 : $$ = n;
4559 : }
4560 : ;
4561 :
4562 4808 : part_params: part_elem { $$ = list_make1($1); }
4563 438 : | part_params ',' part_elem { $$ = lappend($1, $3); }
4564 : ;
4565 :
4566 : part_elem: ColId opt_collate opt_qualified_name
4567 : {
4568 4948 : PartitionElem *n = makeNode(PartitionElem);
4569 :
4570 4948 : n->name = $1;
4571 4948 : n->expr = NULL;
4572 4948 : n->collation = $2;
4573 4948 : n->opclass = $3;
4574 4948 : n->location = @1;
4575 4948 : $$ = n;
4576 : }
4577 : | func_expr_windowless opt_collate opt_qualified_name
4578 : {
4579 130 : PartitionElem *n = makeNode(PartitionElem);
4580 :
4581 130 : n->name = NULL;
4582 130 : n->expr = $1;
4583 130 : n->collation = $2;
4584 130 : n->opclass = $3;
4585 130 : n->location = @1;
4586 130 : $$ = n;
4587 : }
4588 : | '(' a_expr ')' opt_collate opt_qualified_name
4589 : {
4590 168 : PartitionElem *n = makeNode(PartitionElem);
4591 :
4592 168 : n->name = NULL;
4593 168 : n->expr = $2;
4594 168 : n->collation = $4;
4595 168 : n->opclass = $5;
4596 168 : n->location = @1;
4597 168 : $$ = n;
4598 : }
4599 : ;
4600 :
4601 : table_access_method_clause:
4602 122 : USING name { $$ = $2; }
4603 36950 : | /*EMPTY*/ { $$ = NULL; }
4604 : ;
4605 :
4606 : /* WITHOUT OIDS is legacy only */
4607 : OptWith:
4608 658 : WITH reloptions { $$ = $2; }
4609 24 : | WITHOUT OIDS { $$ = NIL; }
4610 35822 : | /*EMPTY*/ { $$ = NIL; }
4611 : ;
4612 :
4613 56 : OnCommitOption: ON COMMIT DROP { $$ = ONCOMMIT_DROP; }
4614 98 : | ON COMMIT DELETE_P ROWS { $$ = ONCOMMIT_DELETE_ROWS; }
4615 24 : | ON COMMIT PRESERVE ROWS { $$ = ONCOMMIT_PRESERVE_ROWS; }
4616 36326 : | /*EMPTY*/ { $$ = ONCOMMIT_NOOP; }
4617 : ;
4618 :
4619 206 : OptTableSpace: TABLESPACE name { $$ = $2; }
4620 43210 : | /*EMPTY*/ { $$ = NULL; }
4621 : ;
4622 :
4623 66 : OptConsTableSpace: USING INDEX TABLESPACE name { $$ = $4; }
4624 8586 : | /*EMPTY*/ { $$ = NULL; }
4625 : ;
4626 :
4627 9566 : ExistingIndex: USING INDEX name { $$ = $3; }
4628 : ;
4629 :
4630 : /*****************************************************************************
4631 : *
4632 : * QUERY :
4633 : * CREATE STATISTICS [[IF NOT EXISTS] stats_name] [(stat types)]
4634 : * ON expression-list FROM from_list
4635 : *
4636 : * Note: the expectation here is that the clauses after ON are a subset of
4637 : * SELECT syntax, allowing for expressions and joined tables, and probably
4638 : * someday a WHERE clause. Much less than that is currently implemented,
4639 : * but the grammar accepts it and then we'll throw FEATURE_NOT_SUPPORTED
4640 : * errors as necessary at execution.
4641 : *
4642 : * Statistics name is optional unless IF NOT EXISTS is specified.
4643 : *
4644 : *****************************************************************************/
4645 :
4646 : CreateStatsStmt:
4647 : CREATE STATISTICS opt_qualified_name
4648 : opt_name_list ON stats_params FROM from_list
4649 : {
4650 566 : CreateStatsStmt *n = makeNode(CreateStatsStmt);
4651 :
4652 566 : n->defnames = $3;
4653 566 : n->stat_types = $4;
4654 566 : n->exprs = $6;
4655 566 : n->relations = $8;
4656 566 : n->stxcomment = NULL;
4657 566 : n->if_not_exists = false;
4658 566 : $$ = (Node *) n;
4659 : }
4660 : | CREATE STATISTICS IF_P NOT EXISTS any_name
4661 : opt_name_list ON stats_params FROM from_list
4662 : {
4663 12 : CreateStatsStmt *n = makeNode(CreateStatsStmt);
4664 :
4665 12 : n->defnames = $6;
4666 12 : n->stat_types = $7;
4667 12 : n->exprs = $9;
4668 12 : n->relations = $11;
4669 12 : n->stxcomment = NULL;
4670 12 : n->if_not_exists = true;
4671 12 : $$ = (Node *) n;
4672 : }
4673 : ;
4674 :
4675 : /*
4676 : * Statistics attributes can be either simple column references, or arbitrary
4677 : * expressions in parens. For compatibility with index attributes permitted
4678 : * in CREATE INDEX, we allow an expression that's just a function call to be
4679 : * written without parens.
4680 : */
4681 :
4682 590 : stats_params: stats_param { $$ = list_make1($1); }
4683 934 : | stats_params ',' stats_param { $$ = lappend($1, $3); }
4684 : ;
4685 :
4686 : stats_param: ColId
4687 : {
4688 1074 : $$ = makeNode(StatsElem);
4689 1074 : $$->name = $1;
4690 1074 : $$->expr = NULL;
4691 : }
4692 : | func_expr_windowless
4693 : {
4694 32 : $$ = makeNode(StatsElem);
4695 32 : $$->name = NULL;
4696 32 : $$->expr = $1;
4697 : }
4698 : | '(' a_expr ')'
4699 : {
4700 418 : $$ = makeNode(StatsElem);
4701 418 : $$->name = NULL;
4702 418 : $$->expr = $2;
4703 : }
4704 : ;
4705 :
4706 : /*****************************************************************************
4707 : *
4708 : * QUERY :
4709 : * ALTER STATISTICS [IF EXISTS] stats_name
4710 : * SET STATISTICS <SignedIconst>
4711 : *
4712 : *****************************************************************************/
4713 :
4714 : AlterStatsStmt:
4715 : ALTER STATISTICS any_name SET STATISTICS set_statistics_value
4716 : {
4717 20 : AlterStatsStmt *n = makeNode(AlterStatsStmt);
4718 :
4719 20 : n->defnames = $3;
4720 20 : n->missing_ok = false;
4721 20 : n->stxstattarget = $6;
4722 20 : $$ = (Node *) n;
4723 : }
4724 : | ALTER STATISTICS IF_P EXISTS any_name SET STATISTICS set_statistics_value
4725 : {
4726 6 : AlterStatsStmt *n = makeNode(AlterStatsStmt);
4727 :
4728 6 : n->defnames = $5;
4729 6 : n->missing_ok = true;
4730 6 : n->stxstattarget = $8;
4731 6 : $$ = (Node *) n;
4732 : }
4733 : ;
4734 :
4735 : /*****************************************************************************
4736 : *
4737 : * QUERY :
4738 : * CREATE TABLE relname AS SelectStmt [ WITH [NO] DATA ]
4739 : *
4740 : *
4741 : * Note: SELECT ... INTO is a now-deprecated alternative for this.
4742 : *
4743 : *****************************************************************************/
4744 :
4745 : CreateAsStmt:
4746 : CREATE OptTemp TABLE create_as_target AS SelectStmt opt_with_data
4747 : {
4748 1142 : CreateTableAsStmt *ctas = makeNode(CreateTableAsStmt);
4749 :
4750 1142 : ctas->query = $6;
4751 1142 : ctas->into = $4;
4752 1142 : ctas->objtype = OBJECT_TABLE;
4753 1142 : ctas->is_select_into = false;
4754 1142 : ctas->if_not_exists = false;
4755 : /* cram additional flags into the IntoClause */
4756 1142 : $4->rel->relpersistence = $2;
4757 1142 : $4->skipData = !($7);
4758 1142 : $$ = (Node *) ctas;
4759 : }
4760 : | CREATE OptTemp TABLE IF_P NOT EXISTS create_as_target AS SelectStmt opt_with_data
4761 : {
4762 52 : CreateTableAsStmt *ctas = makeNode(CreateTableAsStmt);
4763 :
4764 52 : ctas->query = $9;
4765 52 : ctas->into = $7;
4766 52 : ctas->objtype = OBJECT_TABLE;
4767 52 : ctas->is_select_into = false;
4768 52 : ctas->if_not_exists = true;
4769 : /* cram additional flags into the IntoClause */
4770 52 : $7->rel->relpersistence = $2;
4771 52 : $7->skipData = !($10);
4772 52 : $$ = (Node *) ctas;
4773 : }
4774 : ;
4775 :
4776 : create_as_target:
4777 : qualified_name opt_column_list table_access_method_clause
4778 : OptWith OnCommitOption OptTableSpace
4779 : {
4780 1282 : $$ = makeNode(IntoClause);
4781 1282 : $$->rel = $1;
4782 1282 : $$->colNames = $2;
4783 1282 : $$->accessMethod = $3;
4784 1282 : $$->options = $4;
4785 1282 : $$->onCommit = $5;
4786 1282 : $$->tableSpaceName = $6;
4787 1282 : $$->viewQuery = NULL;
4788 1282 : $$->skipData = false; /* might get changed later */
4789 : }
4790 : ;
4791 :
4792 : opt_with_data:
4793 36 : WITH DATA_P { $$ = true; }
4794 212 : | WITH NO DATA_P { $$ = false; }
4795 1858 : | /*EMPTY*/ { $$ = true; }
4796 : ;
4797 :
4798 :
4799 : /*****************************************************************************
4800 : *
4801 : * QUERY :
4802 : * CREATE MATERIALIZED VIEW relname AS SelectStmt
4803 : *
4804 : *****************************************************************************/
4805 :
4806 : CreateMatViewStmt:
4807 : CREATE OptNoLog MATERIALIZED VIEW create_mv_target AS SelectStmt opt_with_data
4808 : {
4809 514 : CreateTableAsStmt *ctas = makeNode(CreateTableAsStmt);
4810 :
4811 514 : ctas->query = $7;
4812 514 : ctas->into = $5;
4813 514 : ctas->objtype = OBJECT_MATVIEW;
4814 514 : ctas->is_select_into = false;
4815 514 : ctas->if_not_exists = false;
4816 : /* cram additional flags into the IntoClause */
4817 514 : $5->rel->relpersistence = $2;
4818 514 : $5->skipData = !($8);
4819 514 : $$ = (Node *) ctas;
4820 : }
4821 : | CREATE OptNoLog MATERIALIZED VIEW IF_P NOT EXISTS create_mv_target AS SelectStmt opt_with_data
4822 : {
4823 48 : CreateTableAsStmt *ctas = makeNode(CreateTableAsStmt);
4824 :
4825 48 : ctas->query = $10;
4826 48 : ctas->into = $8;
4827 48 : ctas->objtype = OBJECT_MATVIEW;
4828 48 : ctas->is_select_into = false;
4829 48 : ctas->if_not_exists = true;
4830 : /* cram additional flags into the IntoClause */
4831 48 : $8->rel->relpersistence = $2;
4832 48 : $8->skipData = !($11);
4833 48 : $$ = (Node *) ctas;
4834 : }
4835 : ;
4836 :
4837 : create_mv_target:
4838 : qualified_name opt_column_list table_access_method_clause opt_reloptions OptTableSpace
4839 : {
4840 562 : $$ = makeNode(IntoClause);
4841 562 : $$->rel = $1;
4842 562 : $$->colNames = $2;
4843 562 : $$->accessMethod = $3;
4844 562 : $$->options = $4;
4845 562 : $$->onCommit = ONCOMMIT_NOOP;
4846 562 : $$->tableSpaceName = $5;
4847 562 : $$->viewQuery = NULL; /* filled at analysis time */
4848 562 : $$->skipData = false; /* might get changed later */
4849 : }
4850 : ;
4851 :
4852 0 : OptNoLog: UNLOGGED { $$ = RELPERSISTENCE_UNLOGGED; }
4853 562 : | /*EMPTY*/ { $$ = RELPERSISTENCE_PERMANENT; }
4854 : ;
4855 :
4856 :
4857 : /*****************************************************************************
4858 : *
4859 : * QUERY :
4860 : * REFRESH MATERIALIZED VIEW qualified_name
4861 : *
4862 : *****************************************************************************/
4863 :
4864 : RefreshMatViewStmt:
4865 : REFRESH MATERIALIZED VIEW opt_concurrently qualified_name opt_with_data
4866 : {
4867 262 : RefreshMatViewStmt *n = makeNode(RefreshMatViewStmt);
4868 :
4869 262 : n->concurrent = $4;
4870 262 : n->relation = $5;
4871 262 : n->skipData = !($6);
4872 262 : $$ = (Node *) n;
4873 : }
4874 : ;
4875 :
4876 :
4877 : /*****************************************************************************
4878 : *
4879 : * QUERY :
4880 : * CREATE SEQUENCE seqname
4881 : * ALTER SEQUENCE seqname
4882 : *
4883 : *****************************************************************************/
4884 :
4885 : CreateSeqStmt:
4886 : CREATE OptTemp SEQUENCE qualified_name OptSeqOptList
4887 : {
4888 632 : CreateSeqStmt *n = makeNode(CreateSeqStmt);
4889 :
4890 632 : $4->relpersistence = $2;
4891 632 : n->sequence = $4;
4892 632 : n->options = $5;
4893 632 : n->ownerId = InvalidOid;
4894 632 : n->if_not_exists = false;
4895 632 : $$ = (Node *) n;
4896 : }
4897 : | CREATE OptTemp SEQUENCE IF_P NOT EXISTS qualified_name OptSeqOptList
4898 : {
4899 24 : CreateSeqStmt *n = makeNode(CreateSeqStmt);
4900 :
4901 24 : $7->relpersistence = $2;
4902 24 : n->sequence = $7;
4903 24 : n->options = $8;
4904 24 : n->ownerId = InvalidOid;
4905 24 : n->if_not_exists = true;
4906 24 : $$ = (Node *) n;
4907 : }
4908 : ;
4909 :
4910 : AlterSeqStmt:
4911 : ALTER SEQUENCE qualified_name SeqOptList
4912 : {
4913 174 : AlterSeqStmt *n = makeNode(AlterSeqStmt);
4914 :
4915 174 : n->sequence = $3;
4916 174 : n->options = $4;
4917 174 : n->missing_ok = false;
4918 174 : $$ = (Node *) n;
4919 : }
4920 : | ALTER SEQUENCE IF_P EXISTS qualified_name SeqOptList
4921 : {
4922 12 : AlterSeqStmt *n = makeNode(AlterSeqStmt);
4923 :
4924 12 : n->sequence = $5;
4925 12 : n->options = $6;
4926 12 : n->missing_ok = true;
4927 12 : $$ = (Node *) n;
4928 : }
4929 :
4930 : ;
4931 :
4932 238 : OptSeqOptList: SeqOptList { $$ = $1; }
4933 418 : | /*EMPTY*/ { $$ = NIL; }
4934 : ;
4935 :
4936 74 : OptParenthesizedSeqOptList: '(' SeqOptList ')' { $$ = $2; }
4937 382 : | /*EMPTY*/ { $$ = NIL; }
4938 : ;
4939 :
4940 498 : SeqOptList: SeqOptElem { $$ = list_make1($1); }
4941 728 : | SeqOptList SeqOptElem { $$ = lappend($1, $2); }
4942 : ;
4943 :
4944 : SeqOptElem: AS SimpleTypename
4945 : {
4946 180 : $$ = makeDefElem("as", (Node *) $2, @1);
4947 : }
4948 : | CACHE NumericOnly
4949 : {
4950 112 : $$ = makeDefElem("cache", (Node *) $2, @1);
4951 : }
4952 : | CYCLE
4953 : {
4954 34 : $$ = makeDefElem("cycle", (Node *) makeBoolean(true), @1);
4955 : }
4956 : | NO CYCLE
4957 : {
4958 14 : $$ = makeDefElem("cycle", (Node *) makeBoolean(false), @1);
4959 : }
4960 : | INCREMENT opt_by NumericOnly
4961 : {
4962 232 : $$ = makeDefElem("increment", (Node *) $3, @1);
4963 : }
4964 : | LOGGED
4965 : {
4966 2 : $$ = makeDefElem("logged", NULL, @1);
4967 : }
4968 : | MAXVALUE NumericOnly
4969 : {
4970 68 : $$ = makeDefElem("maxvalue", (Node *) $2, @1);
4971 : }
4972 : | MINVALUE NumericOnly
4973 : {
4974 72 : $$ = makeDefElem("minvalue", (Node *) $2, @1);
4975 : }
4976 : | NO MAXVALUE
4977 : {
4978 90 : $$ = makeDefElem("maxvalue", NULL, @1);
4979 : }
4980 : | NO MINVALUE
4981 : {
4982 90 : $$ = makeDefElem("minvalue", NULL, @1);
4983 : }
4984 : | OWNED BY any_name
4985 : {
4986 62 : $$ = makeDefElem("owned_by", (Node *) $3, @1);
4987 : }
4988 : | SEQUENCE NAME_P any_name
4989 : {
4990 44 : $$ = makeDefElem("sequence_name", (Node *) $3, @1);
4991 : }
4992 : | START opt_with NumericOnly
4993 : {
4994 212 : $$ = makeDefElem("start", (Node *) $3, @1);
4995 : }
4996 : | RESTART
4997 : {
4998 6 : $$ = makeDefElem("restart", NULL, @1);
4999 : }
5000 : | RESTART opt_with NumericOnly
5001 : {
5002 60 : $$ = makeDefElem("restart", (Node *) $3, @1);
5003 : }
5004 : | UNLOGGED
5005 : {
5006 2 : $$ = makeDefElem("unlogged", NULL, @1);
5007 : }
5008 : ;
5009 :
5010 : opt_by: BY
5011 : | /* EMPTY */
5012 : ;
5013 :
5014 : NumericOnly:
5015 318 : FCONST { $$ = (Node *) makeFloat($1); }
5016 0 : | '+' FCONST { $$ = (Node *) makeFloat($2); }
5017 : | '-' FCONST
5018 : {
5019 20 : Float *f = makeFloat($2);
5020 :
5021 20 : doNegateFloat(f);
5022 20 : $$ = (Node *) f;
5023 : }
5024 11284 : | SignedIconst { $$ = (Node *) makeInteger($1); }
5025 : ;
5026 :
5027 80 : NumericOnly_list: NumericOnly { $$ = list_make1($1); }
5028 6 : | NumericOnly_list ',' NumericOnly { $$ = lappend($1, $3); }
5029 : ;
5030 :
5031 : /*****************************************************************************
5032 : *
5033 : * QUERIES :
5034 : * CREATE [OR REPLACE] [TRUSTED] [PROCEDURAL] LANGUAGE ...
5035 : * DROP [PROCEDURAL] LANGUAGE ...
5036 : *
5037 : *****************************************************************************/
5038 :
5039 : CreatePLangStmt:
5040 : CREATE opt_or_replace opt_trusted opt_procedural LANGUAGE name
5041 : {
5042 : /*
5043 : * We now interpret parameterless CREATE LANGUAGE as
5044 : * CREATE EXTENSION. "OR REPLACE" is silently translated
5045 : * to "IF NOT EXISTS", which isn't quite the same, but
5046 : * seems more useful than throwing an error. We just
5047 : * ignore TRUSTED, as the previous code would have too.
5048 : */
5049 0 : CreateExtensionStmt *n = makeNode(CreateExtensionStmt);
5050 :
5051 0 : n->if_not_exists = $2;
5052 0 : n->extname = $6;
5053 0 : n->options = NIL;
5054 0 : $$ = (Node *) n;
5055 : }
5056 : | CREATE opt_or_replace opt_trusted opt_procedural LANGUAGE name
5057 : HANDLER handler_name opt_inline_handler opt_validator
5058 : {
5059 132 : CreatePLangStmt *n = makeNode(CreatePLangStmt);
5060 :
5061 132 : n->replace = $2;
5062 132 : n->plname = $6;
5063 132 : n->plhandler = $8;
5064 132 : n->plinline = $9;
5065 132 : n->plvalidator = $10;
5066 132 : n->pltrusted = $3;
5067 132 : $$ = (Node *) n;
5068 : }
5069 : ;
5070 :
5071 : opt_trusted:
5072 102 : TRUSTED { $$ = true; }
5073 38 : | /*EMPTY*/ { $$ = false; }
5074 : ;
5075 :
5076 : /* This ought to be just func_name, but that causes reduce/reduce conflicts
5077 : * (CREATE LANGUAGE is the only place where func_name isn't followed by '(').
5078 : * Work around by using simple names, instead.
5079 : */
5080 : handler_name:
5081 518 : name { $$ = list_make1(makeString($1)); }
5082 2 : | name attrs { $$ = lcons(makeString($1), $2); }
5083 : ;
5084 :
5085 : opt_inline_handler:
5086 114 : INLINE_P handler_name { $$ = $2; }
5087 18 : | /*EMPTY*/ { $$ = NIL; }
5088 : ;
5089 :
5090 : validator_clause:
5091 114 : VALIDATOR handler_name { $$ = $2; }
5092 0 : | NO VALIDATOR { $$ = NIL; }
5093 : ;
5094 :
5095 : opt_validator:
5096 114 : validator_clause { $$ = $1; }
5097 18 : | /*EMPTY*/ { $$ = NIL; }
5098 : ;
5099 :
5100 : opt_procedural:
5101 : PROCEDURAL
5102 : | /*EMPTY*/
5103 : ;
5104 :
5105 : /*****************************************************************************
5106 : *
5107 : * QUERY:
5108 : * CREATE TABLESPACE tablespace LOCATION '/path/to/tablespace/'
5109 : *
5110 : *****************************************************************************/
5111 :
5112 : CreateTableSpaceStmt: CREATE TABLESPACE name OptTableSpaceOwner LOCATION Sconst opt_reloptions
5113 : {
5114 112 : CreateTableSpaceStmt *n = makeNode(CreateTableSpaceStmt);
5115 :
5116 112 : n->tablespacename = $3;
5117 112 : n->owner = $4;
5118 112 : n->location = $6;
5119 112 : n->options = $7;
5120 112 : $$ = (Node *) n;
5121 : }
5122 : ;
5123 :
5124 2 : OptTableSpaceOwner: OWNER RoleSpec { $$ = $2; }
5125 110 : | /*EMPTY */ { $$ = NULL; }
5126 : ;
5127 :
5128 : /*****************************************************************************
5129 : *
5130 : * QUERY :
5131 : * DROP TABLESPACE <tablespace>
5132 : *
5133 : * No need for drop behaviour as we cannot implement dependencies for
5134 : * objects in other databases; we can only support RESTRICT.
5135 : *
5136 : ****************************************************************************/
5137 :
5138 : DropTableSpaceStmt: DROP TABLESPACE name
5139 : {
5140 64 : DropTableSpaceStmt *n = makeNode(DropTableSpaceStmt);
5141 :
5142 64 : n->tablespacename = $3;
5143 64 : n->missing_ok = false;
5144 64 : $$ = (Node *) n;
5145 : }
5146 : | DROP TABLESPACE IF_P EXISTS name
5147 : {
5148 0 : DropTableSpaceStmt *n = makeNode(DropTableSpaceStmt);
5149 :
5150 0 : n->tablespacename = $5;
5151 0 : n->missing_ok = true;
5152 0 : $$ = (Node *) n;
5153 : }
5154 : ;
5155 :
5156 : /*****************************************************************************
5157 : *
5158 : * QUERY:
5159 : * CREATE EXTENSION extension
5160 : * [ WITH ] [ SCHEMA schema ] [ VERSION version ]
5161 : *
5162 : *****************************************************************************/
5163 :
5164 : CreateExtensionStmt: CREATE EXTENSION name opt_with create_extension_opt_list
5165 : {
5166 458 : CreateExtensionStmt *n = makeNode(CreateExtensionStmt);
5167 :
5168 458 : n->extname = $3;
5169 458 : n->if_not_exists = false;
5170 458 : n->options = $5;
5171 458 : $$ = (Node *) n;
5172 : }
5173 : | CREATE EXTENSION IF_P NOT EXISTS name opt_with create_extension_opt_list
5174 : {
5175 14 : CreateExtensionStmt *n = makeNode(CreateExtensionStmt);
5176 :
5177 14 : n->extname = $6;
5178 14 : n->if_not_exists = true;
5179 14 : n->options = $8;
5180 14 : $$ = (Node *) n;
5181 : }
5182 : ;
5183 :
5184 : create_extension_opt_list:
5185 : create_extension_opt_list create_extension_opt_item
5186 98 : { $$ = lappend($1, $2); }
5187 : | /* EMPTY */
5188 472 : { $$ = NIL; }
5189 : ;
5190 :
5191 : create_extension_opt_item:
5192 : SCHEMA name
5193 : {
5194 46 : $$ = makeDefElem("schema", (Node *) makeString($2), @1);
5195 : }
5196 : | VERSION_P NonReservedWord_or_Sconst
5197 : {
5198 12 : $$ = makeDefElem("new_version", (Node *) makeString($2), @1);
5199 : }
5200 : | FROM NonReservedWord_or_Sconst
5201 : {
5202 0 : ereport(ERROR,
5203 : (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
5204 : errmsg("CREATE EXTENSION ... FROM is no longer supported"),
5205 : parser_errposition(@1)));
5206 : }
5207 : | CASCADE
5208 : {
5209 40 : $$ = makeDefElem("cascade", (Node *) makeBoolean(true), @1);
5210 : }
5211 : ;
5212 :
5213 : /*****************************************************************************
5214 : *
5215 : * ALTER EXTENSION name UPDATE [ TO version ]
5216 : *
5217 : *****************************************************************************/
5218 :
5219 : AlterExtensionStmt: ALTER EXTENSION name UPDATE alter_extension_opt_list
5220 : {
5221 34 : AlterExtensionStmt *n = makeNode(AlterExtensionStmt);
5222 :
5223 34 : n->extname = $3;
5224 34 : n->options = $5;
5225 34 : $$ = (Node *) n;
5226 : }
5227 : ;
5228 :
5229 : alter_extension_opt_list:
5230 : alter_extension_opt_list alter_extension_opt_item
5231 34 : { $$ = lappend($1, $2); }
5232 : | /* EMPTY */
5233 34 : { $$ = NIL; }
5234 : ;
5235 :
5236 : alter_extension_opt_item:
5237 : TO NonReservedWord_or_Sconst
5238 : {
5239 34 : $$ = makeDefElem("new_version", (Node *) makeString($2), @1);
5240 : }
5241 : ;
5242 :
5243 : /*****************************************************************************
5244 : *
5245 : * ALTER EXTENSION name ADD/DROP object-identifier
5246 : *
5247 : *****************************************************************************/
5248 :
5249 : AlterExtensionContentsStmt:
5250 : ALTER EXTENSION name add_drop object_type_name name
5251 : {
5252 18 : AlterExtensionContentsStmt *n = makeNode(AlterExtensionContentsStmt);
5253 :
5254 18 : n->extname = $3;
5255 18 : n->action = $4;
5256 18 : n->objtype = $5;
5257 18 : n->object = (Node *) makeString($6);
5258 18 : $$ = (Node *) n;
5259 : }
5260 : | ALTER EXTENSION name add_drop object_type_any_name any_name
5261 : {
5262 68 : AlterExtensionContentsStmt *n = makeNode(AlterExtensionContentsStmt);
5263 :
5264 68 : n->extname = $3;
5265 68 : n->action = $4;
5266 68 : n->objtype = $5;
5267 68 : n->object = (Node *) $6;
5268 68 : $$ = (Node *) n;
5269 : }
5270 : | ALTER EXTENSION name add_drop AGGREGATE aggregate_with_argtypes
5271 : {
5272 8 : AlterExtensionContentsStmt *n = makeNode(AlterExtensionContentsStmt);
5273 :
5274 8 : n->extname = $3;
5275 8 : n->action = $4;
5276 8 : n->objtype = OBJECT_AGGREGATE;
5277 8 : n->object = (Node *) $6;
5278 8 : $$ = (Node *) n;
5279 : }
5280 : | ALTER EXTENSION name add_drop CAST '(' Typename AS Typename ')'
5281 : {
5282 4 : AlterExtensionContentsStmt *n = makeNode(AlterExtensionContentsStmt);
5283 :
5284 4 : n->extname = $3;
5285 4 : n->action = $4;
5286 4 : n->objtype = OBJECT_CAST;
5287 4 : n->object = (Node *) list_make2($7, $9);
5288 4 : $$ = (Node *) n;
5289 : }
5290 : | ALTER EXTENSION name add_drop DOMAIN_P Typename
5291 : {
5292 0 : AlterExtensionContentsStmt *n = makeNode(AlterExtensionContentsStmt);
5293 :
5294 0 : n->extname = $3;
5295 0 : n->action = $4;
5296 0 : n->objtype = OBJECT_DOMAIN;
5297 0 : n->object = (Node *) $6;
5298 0 : $$ = (Node *) n;
5299 : }
5300 : | ALTER EXTENSION name add_drop FUNCTION function_with_argtypes
5301 : {
5302 86 : AlterExtensionContentsStmt *n = makeNode(AlterExtensionContentsStmt);
5303 :
5304 86 : n->extname = $3;
5305 86 : n->action = $4;
5306 86 : n->objtype = OBJECT_FUNCTION;
5307 86 : n->object = (Node *) $6;
5308 86 : $$ = (Node *) n;
5309 : }
5310 : | ALTER EXTENSION name add_drop OPERATOR operator_with_argtypes
5311 : {
5312 18 : AlterExtensionContentsStmt *n = makeNode(AlterExtensionContentsStmt);
5313 :
5314 18 : n->extname = $3;
5315 18 : n->action = $4;
5316 18 : n->objtype = OBJECT_OPERATOR;
5317 18 : n->object = (Node *) $6;
5318 18 : $$ = (Node *) n;
5319 : }
5320 : | ALTER EXTENSION name add_drop OPERATOR CLASS any_name USING name
5321 : {
5322 4 : AlterExtensionContentsStmt *n = makeNode(AlterExtensionContentsStmt);
5323 :
5324 4 : n->extname = $3;
5325 4 : n->action = $4;
5326 4 : n->objtype = OBJECT_OPCLASS;
5327 4 : n->object = (Node *) lcons(makeString($9), $7);
5328 4 : $$ = (Node *) n;
5329 : }
5330 : | ALTER EXTENSION name add_drop OPERATOR FAMILY any_name USING name
5331 : {
5332 4 : AlterExtensionContentsStmt *n = makeNode(AlterExtensionContentsStmt);
5333 :
5334 4 : n->extname = $3;
5335 4 : n->action = $4;
5336 4 : n->objtype = OBJECT_OPFAMILY;
5337 4 : n->object = (Node *) lcons(makeString($9), $7);
5338 4 : $$ = (Node *) n;
5339 : }
5340 : | ALTER EXTENSION name add_drop PROCEDURE function_with_argtypes
5341 : {
5342 0 : AlterExtensionContentsStmt *n = makeNode(AlterExtensionContentsStmt);
5343 :
5344 0 : n->extname = $3;
5345 0 : n->action = $4;
5346 0 : n->objtype = OBJECT_PROCEDURE;
5347 0 : n->object = (Node *) $6;
5348 0 : $$ = (Node *) n;
5349 : }
5350 : | ALTER EXTENSION name add_drop ROUTINE function_with_argtypes
5351 : {
5352 0 : AlterExtensionContentsStmt *n = makeNode(AlterExtensionContentsStmt);
5353 :
5354 0 : n->extname = $3;
5355 0 : n->action = $4;
5356 0 : n->objtype = OBJECT_ROUTINE;
5357 0 : n->object = (Node *) $6;
5358 0 : $$ = (Node *) n;
5359 : }
5360 : | ALTER EXTENSION name add_drop TRANSFORM FOR Typename LANGUAGE name
5361 : {
5362 4 : AlterExtensionContentsStmt *n = makeNode(AlterExtensionContentsStmt);
5363 :
5364 4 : n->extname = $3;
5365 4 : n->action = $4;
5366 4 : n->objtype = OBJECT_TRANSFORM;
5367 4 : n->object = (Node *) list_make2($7, makeString($9));
5368 4 : $$ = (Node *) n;
5369 : }
5370 : | ALTER EXTENSION name add_drop TYPE_P Typename
5371 : {
5372 8 : AlterExtensionContentsStmt *n = makeNode(AlterExtensionContentsStmt);
5373 :
5374 8 : n->extname = $3;
5375 8 : n->action = $4;
5376 8 : n->objtype = OBJECT_TYPE;
5377 8 : n->object = (Node *) $6;
5378 8 : $$ = (Node *) n;
5379 : }
5380 : ;
5381 :
5382 : /*****************************************************************************
5383 : *
5384 : * QUERY:
5385 : * CREATE FOREIGN DATA WRAPPER name options
5386 : *
5387 : *****************************************************************************/
5388 :
5389 : CreateFdwStmt: CREATE FOREIGN DATA_P WRAPPER name opt_fdw_options create_generic_options
5390 : {
5391 190 : CreateFdwStmt *n = makeNode(CreateFdwStmt);
5392 :
5393 190 : n->fdwname = $5;
5394 190 : n->func_options = $6;
5395 190 : n->options = $7;
5396 190 : $$ = (Node *) n;
5397 : }
5398 : ;
5399 :
5400 : fdw_option:
5401 54 : HANDLER handler_name { $$ = makeDefElem("handler", (Node *) $2, @1); }
5402 0 : | NO HANDLER { $$ = makeDefElem("handler", NULL, @1); }
5403 44 : | VALIDATOR handler_name { $$ = makeDefElem("validator", (Node *) $2, @1); }
5404 6 : | NO VALIDATOR { $$ = makeDefElem("validator", NULL, @1); }
5405 : ;
5406 :
5407 : fdw_options:
5408 86 : fdw_option { $$ = list_make1($1); }
5409 18 : | fdw_options fdw_option { $$ = lappend($1, $2); }
5410 : ;
5411 :
5412 : opt_fdw_options:
5413 50 : fdw_options { $$ = $1; }
5414 232 : | /*EMPTY*/ { $$ = NIL; }
5415 : ;
5416 :
5417 : /*****************************************************************************
5418 : *
5419 : * QUERY :
5420 : * ALTER FOREIGN DATA WRAPPER name options
5421 : *
5422 : ****************************************************************************/
5423 :
5424 : AlterFdwStmt: ALTER FOREIGN DATA_P WRAPPER name opt_fdw_options alter_generic_options
5425 : {
5426 86 : AlterFdwStmt *n = makeNode(AlterFdwStmt);
5427 :
5428 86 : n->fdwname = $5;
5429 86 : n->func_options = $6;
5430 86 : n->options = $7;
5431 86 : $$ = (Node *) n;
5432 : }
5433 : | ALTER FOREIGN DATA_P WRAPPER name fdw_options
5434 : {
5435 36 : AlterFdwStmt *n = makeNode(AlterFdwStmt);
5436 :
5437 36 : n->fdwname = $5;
5438 36 : n->func_options = $6;
5439 36 : n->options = NIL;
5440 36 : $$ = (Node *) n;
5441 : }
5442 : ;
5443 :
5444 : /* Options definition for CREATE FDW, SERVER and USER MAPPING */
5445 : create_generic_options:
5446 688 : OPTIONS '(' generic_option_list ')' { $$ = $3; }
5447 63698 : | /*EMPTY*/ { $$ = NIL; }
5448 : ;
5449 :
5450 : generic_option_list:
5451 : generic_option_elem
5452 : {
5453 688 : $$ = list_make1($1);
5454 : }
5455 : | generic_option_list ',' generic_option_elem
5456 : {
5457 430 : $$ = lappend($1, $3);
5458 : }
5459 : ;
5460 :
5461 : /* Options definition for ALTER FDW, SERVER and USER MAPPING */
5462 : alter_generic_options:
5463 488 : OPTIONS '(' alter_generic_option_list ')' { $$ = $3; }
5464 : ;
5465 :
5466 : alter_generic_option_list:
5467 : alter_generic_option_elem
5468 : {
5469 488 : $$ = list_make1($1);
5470 : }
5471 : | alter_generic_option_list ',' alter_generic_option_elem
5472 : {
5473 168 : $$ = lappend($1, $3);
5474 : }
5475 : ;
5476 :
5477 : alter_generic_option_elem:
5478 : generic_option_elem
5479 : {
5480 200 : $$ = $1;
5481 : }
5482 : | SET generic_option_elem
5483 : {
5484 128 : $$ = $2;
5485 128 : $$->defaction = DEFELEM_SET;
5486 : }
5487 : | ADD_P generic_option_elem
5488 : {
5489 202 : $$ = $2;
5490 202 : $$->defaction = DEFELEM_ADD;
5491 : }
5492 : | DROP generic_option_name
5493 : {
5494 126 : $$ = makeDefElemExtended(NULL, $2, NULL, DEFELEM_DROP, @2);
5495 : }
5496 : ;
5497 :
5498 : generic_option_elem:
5499 : generic_option_name generic_option_arg
5500 : {
5501 1648 : $$ = makeDefElem($1, $2, @1);
5502 : }
5503 : ;
5504 :
5505 : generic_option_name:
5506 1774 : ColLabel { $$ = $1; }
5507 : ;
5508 :
5509 : /* We could use def_arg here, but the spec only requires string literals */
5510 : generic_option_arg:
5511 1648 : Sconst { $$ = (Node *) makeString($1); }
5512 : ;
5513 :
5514 : /*****************************************************************************
5515 : *
5516 : * QUERY:
5517 : * CREATE SERVER name [TYPE] [VERSION] [OPTIONS]
5518 : *
5519 : *****************************************************************************/
5520 :
5521 : CreateForeignServerStmt: CREATE SERVER name opt_type opt_foreign_server_version
5522 : FOREIGN DATA_P WRAPPER name create_generic_options
5523 : {
5524 248 : CreateForeignServerStmt *n = makeNode(CreateForeignServerStmt);
5525 :
5526 248 : n->servername = $3;
5527 248 : n->servertype = $4;
5528 248 : n->version = $5;
5529 248 : n->fdwname = $9;
5530 248 : n->options = $10;
5531 248 : n->if_not_exists = false;
5532 248 : $$ = (Node *) n;
5533 : }
5534 : | CREATE SERVER IF_P NOT EXISTS name opt_type opt_foreign_server_version
5535 : FOREIGN DATA_P WRAPPER name create_generic_options
5536 : {
5537 24 : CreateForeignServerStmt *n = makeNode(CreateForeignServerStmt);
5538 :
5539 24 : n->servername = $6;
5540 24 : n->servertype = $7;
5541 24 : n->version = $8;
5542 24 : n->fdwname = $12;
5543 24 : n->options = $13;
5544 24 : n->if_not_exists = true;
5545 24 : $$ = (Node *) n;
5546 : }
5547 : ;
5548 :
5549 : opt_type:
5550 18 : TYPE_P Sconst { $$ = $2; }
5551 254 : | /*EMPTY*/ { $$ = NULL; }
5552 : ;
5553 :
5554 :
5555 : foreign_server_version:
5556 66 : VERSION_P Sconst { $$ = $2; }
5557 0 : | VERSION_P NULL_P { $$ = NULL; }
5558 : ;
5559 :
5560 : opt_foreign_server_version:
5561 18 : foreign_server_version { $$ = $1; }
5562 254 : | /*EMPTY*/ { $$ = NULL; }
5563 : ;
5564 :
5565 : /*****************************************************************************
5566 : *
5567 : * QUERY :
5568 : * ALTER SERVER name [VERSION] [OPTIONS]
5569 : *
5570 : ****************************************************************************/
5571 :
5572 : AlterForeignServerStmt: ALTER SERVER name foreign_server_version alter_generic_options
5573 : {
5574 6 : AlterForeignServerStmt *n = makeNode(AlterForeignServerStmt);
5575 :
5576 6 : n->servername = $3;
5577 6 : n->version = $4;
5578 6 : n->options = $5;
5579 6 : n->has_version = true;
5580 6 : $$ = (Node *) n;
5581 : }
5582 : | ALTER SERVER name foreign_server_version
5583 : {
5584 42 : AlterForeignServerStmt *n = makeNode(AlterForeignServerStmt);
5585 :
5586 42 : n->servername = $3;
5587 42 : n->version = $4;
5588 42 : n->has_version = true;
5589 42 : $$ = (Node *) n;
5590 : }
5591 : | ALTER SERVER name alter_generic_options
5592 : {
5593 172 : AlterForeignServerStmt *n = makeNode(AlterForeignServerStmt);
5594 :
5595 172 : n->servername = $3;
5596 172 : n->options = $4;
5597 172 : $$ = (Node *) n;
5598 : }
5599 : ;
5600 :
5601 : /*****************************************************************************
5602 : *
5603 : * QUERY:
5604 : * CREATE FOREIGN TABLE relname (...) SERVER name (...)
5605 : *
5606 : *****************************************************************************/
5607 :
5608 : CreateForeignTableStmt:
5609 : CREATE FOREIGN TABLE qualified_name
5610 : '(' OptTableElementList ')'
5611 : OptInherit SERVER name create_generic_options
5612 : {
5613 360 : CreateForeignTableStmt *n = makeNode(CreateForeignTableStmt);
5614 :
5615 360 : $4->relpersistence = RELPERSISTENCE_PERMANENT;
5616 360 : n->base.relation = $4;
5617 360 : n->base.tableElts = $6;
5618 360 : n->base.inhRelations = $8;
5619 360 : n->base.ofTypename = NULL;
5620 360 : n->base.constraints = NIL;
5621 360 : n->base.options = NIL;
5622 360 : n->base.oncommit = ONCOMMIT_NOOP;
5623 360 : n->base.tablespacename = NULL;
5624 360 : n->base.if_not_exists = false;
5625 : /* FDW-specific data */
5626 360 : n->servername = $10;
5627 360 : n->options = $11;
5628 360 : $$ = (Node *) n;
5629 : }
5630 : | CREATE FOREIGN TABLE IF_P NOT EXISTS qualified_name
5631 : '(' OptTableElementList ')'
5632 : OptInherit SERVER name create_generic_options
5633 : {
5634 0 : CreateForeignTableStmt *n = makeNode(CreateForeignTableStmt);
5635 :
5636 0 : $7->relpersistence = RELPERSISTENCE_PERMANENT;
5637 0 : n->base.relation = $7;
5638 0 : n->base.tableElts = $9;
5639 0 : n->base.inhRelations = $11;
5640 0 : n->base.ofTypename = NULL;
5641 0 : n->base.constraints = NIL;
5642 0 : n->base.options = NIL;
5643 0 : n->base.oncommit = ONCOMMIT_NOOP;
5644 0 : n->base.tablespacename = NULL;
5645 0 : n->base.if_not_exists = true;
5646 : /* FDW-specific data */
5647 0 : n->servername = $13;
5648 0 : n->options = $14;
5649 0 : $$ = (Node *) n;
5650 : }
5651 : | CREATE FOREIGN TABLE qualified_name
5652 : PARTITION OF qualified_name OptTypedTableElementList PartitionBoundSpec
5653 : SERVER name create_generic_options
5654 : {
5655 90 : CreateForeignTableStmt *n = makeNode(CreateForeignTableStmt);
5656 :
5657 90 : $4->relpersistence = RELPERSISTENCE_PERMANENT;
5658 90 : n->base.relation = $4;
5659 90 : n->base.inhRelations = list_make1($7);
5660 90 : n->base.tableElts = $8;
5661 90 : n->base.partbound = $9;
5662 90 : n->base.ofTypename = NULL;
5663 90 : n->base.constraints = NIL;
5664 90 : n->base.options = NIL;
5665 90 : n->base.oncommit = ONCOMMIT_NOOP;
5666 90 : n->base.tablespacename = NULL;
5667 90 : n->base.if_not_exists = false;
5668 : /* FDW-specific data */
5669 90 : n->servername = $11;
5670 90 : n->options = $12;
5671 90 : $$ = (Node *) n;
5672 : }
5673 : | CREATE FOREIGN TABLE IF_P NOT EXISTS qualified_name
5674 : PARTITION OF qualified_name OptTypedTableElementList PartitionBoundSpec
5675 : SERVER name create_generic_options
5676 : {
5677 0 : CreateForeignTableStmt *n = makeNode(CreateForeignTableStmt);
5678 :
5679 0 : $7->relpersistence = RELPERSISTENCE_PERMANENT;
5680 0 : n->base.relation = $7;
5681 0 : n->base.inhRelations = list_make1($10);
5682 0 : n->base.tableElts = $11;
5683 0 : n->base.partbound = $12;
5684 0 : n->base.ofTypename = NULL;
5685 0 : n->base.constraints = NIL;
5686 0 : n->base.options = NIL;
5687 0 : n->base.oncommit = ONCOMMIT_NOOP;
5688 0 : n->base.tablespacename = NULL;
5689 0 : n->base.if_not_exists = true;
5690 : /* FDW-specific data */
5691 0 : n->servername = $14;
5692 0 : n->options = $15;
5693 0 : $$ = (Node *) n;
5694 : }
5695 : ;
5696 :
5697 : /*****************************************************************************
5698 : *
5699 : * QUERY:
5700 : * IMPORT FOREIGN SCHEMA remote_schema
5701 : * [ { LIMIT TO | EXCEPT } ( table_list ) ]
5702 : * FROM SERVER server_name INTO local_schema [ OPTIONS (...) ]
5703 : *
5704 : ****************************************************************************/
5705 :
5706 : ImportForeignSchemaStmt:
5707 : IMPORT_P FOREIGN SCHEMA name import_qualification
5708 : FROM SERVER name INTO name create_generic_options
5709 : {
5710 44 : ImportForeignSchemaStmt *n = makeNode(ImportForeignSchemaStmt);
5711 :
5712 44 : n->server_name = $8;
5713 44 : n->remote_schema = $4;
5714 44 : n->local_schema = $10;
5715 44 : n->list_type = $5->type;
5716 44 : n->table_list = $5->table_names;
5717 44 : n->options = $11;
5718 44 : $$ = (Node *) n;
5719 : }
5720 : ;
5721 :
5722 : import_qualification_type:
5723 10 : LIMIT TO { $$ = FDW_IMPORT_SCHEMA_LIMIT_TO; }
5724 14 : | EXCEPT { $$ = FDW_IMPORT_SCHEMA_EXCEPT; }
5725 : ;
5726 :
5727 : import_qualification:
5728 : import_qualification_type '(' relation_expr_list ')'
5729 : {
5730 24 : ImportQual *n = (ImportQual *) palloc(sizeof(ImportQual));
5731 :
5732 24 : n->type = $1;
5733 24 : n->table_names = $3;
5734 24 : $$ = n;
5735 : }
5736 : | /*EMPTY*/
5737 : {
5738 20 : ImportQual *n = (ImportQual *) palloc(sizeof(ImportQual));
5739 20 : n->type = FDW_IMPORT_SCHEMA_ALL;
5740 20 : n->table_names = NIL;
5741 20 : $$ = n;
5742 : }
5743 : ;
5744 :
5745 : /*****************************************************************************
5746 : *
5747 : * QUERY:
5748 : * CREATE USER MAPPING FOR auth_ident SERVER name [OPTIONS]
5749 : *
5750 : *****************************************************************************/
5751 :
5752 : CreateUserMappingStmt: CREATE USER MAPPING FOR auth_ident SERVER name create_generic_options
5753 : {
5754 232 : CreateUserMappingStmt *n = makeNode(CreateUserMappingStmt);
5755 :
5756 232 : n->user = $5;
5757 232 : n->servername = $7;
5758 232 : n->options = $8;
5759 232 : n->if_not_exists = false;
5760 232 : $$ = (Node *) n;
5761 : }
5762 : | CREATE USER MAPPING IF_P NOT EXISTS FOR auth_ident SERVER name create_generic_options
5763 : {
5764 6 : CreateUserMappingStmt *n = makeNode(CreateUserMappingStmt);
5765 :
5766 6 : n->user = $8;
5767 6 : n->servername = $10;
5768 6 : n->options = $11;
5769 6 : n->if_not_exists = true;
5770 6 : $$ = (Node *) n;
5771 : }
5772 : ;
5773 :
5774 : /* User mapping authorization identifier */
5775 428 : auth_ident: RoleSpec { $$ = $1; }
5776 46 : | USER { $$ = makeRoleSpec(ROLESPEC_CURRENT_USER, @1); }
5777 : ;
5778 :
5779 : /*****************************************************************************
5780 : *
5781 : * QUERY :
5782 : * DROP USER MAPPING FOR auth_ident SERVER name
5783 : *
5784 : * XXX you'd think this should have a CASCADE/RESTRICT option, even if it's
5785 : * only pro forma; but the SQL standard doesn't show one.
5786 : ****************************************************************************/
5787 :
5788 : DropUserMappingStmt: DROP USER MAPPING FOR auth_ident SERVER name
5789 : {
5790 88 : DropUserMappingStmt *n = makeNode(DropUserMappingStmt);
5791 :
5792 88 : n->user = $5;
5793 88 : n->servername = $7;
5794 88 : n->missing_ok = false;
5795 88 : $$ = (Node *) n;
5796 : }
5797 : | DROP USER MAPPING IF_P EXISTS FOR auth_ident SERVER name
5798 : {
5799 38 : DropUserMappingStmt *n = makeNode(DropUserMappingStmt);
5800 :
5801 38 : n->user = $7;
5802 38 : n->servername = $9;
5803 38 : n->missing_ok = true;
5804 38 : $$ = (Node *) n;
5805 : }
5806 : ;
5807 :
5808 : /*****************************************************************************
5809 : *
5810 : * QUERY :
5811 : * ALTER USER MAPPING FOR auth_ident SERVER name OPTIONS
5812 : *
5813 : ****************************************************************************/
5814 :
5815 : AlterUserMappingStmt: ALTER USER MAPPING FOR auth_ident SERVER name alter_generic_options
5816 : {
5817 110 : AlterUserMappingStmt *n = makeNode(AlterUserMappingStmt);
5818 :
5819 110 : n->user = $5;
5820 110 : n->servername = $7;
5821 110 : n->options = $8;
5822 110 : $$ = (Node *) n;
5823 : }
5824 : ;
5825 :
5826 : /*****************************************************************************
5827 : *
5828 : * QUERIES:
5829 : * CREATE POLICY name ON table
5830 : * [AS { PERMISSIVE | RESTRICTIVE } ]
5831 : * [FOR { SELECT | INSERT | UPDATE | DELETE } ]
5832 : * [TO role, ...]
5833 : * [USING (qual)] [WITH CHECK (with check qual)]
5834 : * ALTER POLICY name ON table [TO role, ...]
5835 : * [USING (qual)] [WITH CHECK (with check qual)]
5836 : *
5837 : *****************************************************************************/
5838 :
5839 : CreatePolicyStmt:
5840 : CREATE POLICY name ON qualified_name RowSecurityDefaultPermissive
5841 : RowSecurityDefaultForCmd RowSecurityDefaultToRole
5842 : RowSecurityOptionalExpr RowSecurityOptionalWithCheck
5843 : {
5844 658 : CreatePolicyStmt *n = makeNode(CreatePolicyStmt);
5845 :
5846 658 : n->policy_name = $3;
5847 658 : n->table = $5;
5848 658 : n->permissive = $6;
5849 658 : n->cmd_name = $7;
5850 658 : n->roles = $8;
5851 658 : n->qual = $9;
5852 658 : n->with_check = $10;
5853 658 : $$ = (Node *) n;
5854 : }
5855 : ;
5856 :
5857 : AlterPolicyStmt:
5858 : ALTER POLICY name ON qualified_name RowSecurityOptionalToRole
5859 : RowSecurityOptionalExpr RowSecurityOptionalWithCheck
5860 : {
5861 84 : AlterPolicyStmt *n = makeNode(AlterPolicyStmt);
5862 :
5863 84 : n->policy_name = $3;
5864 84 : n->table = $5;
5865 84 : n->roles = $6;
5866 84 : n->qual = $7;
5867 84 : n->with_check = $8;
5868 84 : $$ = (Node *) n;
5869 : }
5870 : ;
5871 :
5872 : RowSecurityOptionalExpr:
5873 684 : USING '(' a_expr ')' { $$ = $3; }
5874 58 : | /* EMPTY */ { $$ = NULL; }
5875 : ;
5876 :
5877 : RowSecurityOptionalWithCheck:
5878 122 : WITH CHECK '(' a_expr ')' { $$ = $4; }
5879 620 : | /* EMPTY */ { $$ = NULL; }
5880 : ;
5881 :
5882 : RowSecurityDefaultToRole:
5883 124 : TO role_list { $$ = $2; }
5884 534 : | /* EMPTY */ { $$ = list_make1(makeRoleSpec(ROLESPEC_PUBLIC, -1)); }
5885 : ;
5886 :
5887 : RowSecurityOptionalToRole:
5888 12 : TO role_list { $$ = $2; }
5889 72 : | /* EMPTY */ { $$ = NULL; }
5890 : ;
5891 :
5892 : RowSecurityDefaultPermissive:
5893 : AS IDENT
5894 : {
5895 86 : if (strcmp($2, "permissive") == 0)
5896 24 : $$ = true;
5897 62 : else if (strcmp($2, "restrictive") == 0)
5898 56 : $$ = false;
5899 : else
5900 6 : ereport(ERROR,
5901 : (errcode(ERRCODE_SYNTAX_ERROR),
5902 : errmsg("unrecognized row security option \"%s\"", $2),
5903 : errhint("Only PERMISSIVE or RESTRICTIVE policies are supported currently."),
5904 : parser_errposition(@2)));
5905 :
5906 : }
5907 578 : | /* EMPTY */ { $$ = true; }
5908 : ;
5909 :
5910 : RowSecurityDefaultForCmd:
5911 314 : FOR row_security_cmd { $$ = $2; }
5912 344 : | /* EMPTY */ { $$ = "all"; }
5913 : ;
5914 :
5915 : row_security_cmd:
5916 44 : ALL { $$ = "all"; }
5917 106 : | SELECT { $$ = "select"; }
5918 44 : | INSERT { $$ = "insert"; }
5919 78 : | UPDATE { $$ = "update"; }
5920 42 : | DELETE_P { $$ = "delete"; }
5921 : ;
5922 :
5923 : /*****************************************************************************
5924 : *
5925 : * QUERY:
5926 : * CREATE ACCESS METHOD name HANDLER handler_name
5927 : *
5928 : *****************************************************************************/
5929 :
5930 : CreateAmStmt: CREATE ACCESS METHOD name TYPE_P am_type HANDLER handler_name
5931 : {
5932 62 : CreateAmStmt *n = makeNode(CreateAmStmt);
5933 :
5934 62 : n->amname = $4;
5935 62 : n->handler_name = $8;
5936 62 : n->amtype = $6;
5937 62 : $$ = (Node *) n;
5938 : }
5939 : ;
5940 :
5941 : am_type:
5942 34 : INDEX { $$ = AMTYPE_INDEX; }
5943 28 : | TABLE { $$ = AMTYPE_TABLE; }
5944 : ;
5945 :
5946 : /*****************************************************************************
5947 : *
5948 : * QUERIES :
5949 : * CREATE TRIGGER ...
5950 : *
5951 : *****************************************************************************/
5952 :
5953 : CreateTrigStmt:
5954 : CREATE opt_or_replace TRIGGER name TriggerActionTime TriggerEvents ON
5955 : qualified_name TriggerReferencing TriggerForSpec TriggerWhen
5956 : EXECUTE FUNCTION_or_PROCEDURE func_name '(' TriggerFuncArgs ')'
5957 : {
5958 3052 : CreateTrigStmt *n = makeNode(CreateTrigStmt);
5959 :
5960 3052 : n->replace = $2;
5961 3052 : n->isconstraint = false;
5962 3052 : n->trigname = $4;
5963 3052 : n->relation = $8;
5964 3052 : n->funcname = $14;
5965 3052 : n->args = $16;
5966 3052 : n->row = $10;
5967 3052 : n->timing = $5;
5968 3052 : n->events = intVal(linitial($6));
5969 3052 : n->columns = (List *) lsecond($6);
5970 3052 : n->whenClause = $11;
5971 3052 : n->transitionRels = $9;
5972 3052 : n->deferrable = false;
5973 3052 : n->initdeferred = false;
5974 3052 : n->constrrel = NULL;
5975 3052 : $$ = (Node *) n;
5976 : }
5977 : | CREATE opt_or_replace CONSTRAINT TRIGGER name AFTER TriggerEvents ON
5978 : qualified_name OptConstrFromTable ConstraintAttributeSpec
5979 : FOR EACH ROW TriggerWhen
5980 : EXECUTE FUNCTION_or_PROCEDURE func_name '(' TriggerFuncArgs ')'
5981 : {
5982 54 : CreateTrigStmt *n = makeNode(CreateTrigStmt);
5983 :
5984 54 : n->replace = $2;
5985 54 : if (n->replace) /* not supported, see CreateTrigger */
5986 0 : ereport(ERROR,
5987 : (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
5988 : errmsg("CREATE OR REPLACE CONSTRAINT TRIGGER is not supported"),
5989 : parser_errposition(@1)));
5990 54 : n->isconstraint = true;
5991 54 : n->trigname = $5;
5992 54 : n->relation = $9;
5993 54 : n->funcname = $18;
5994 54 : n->args = $20;
5995 54 : n->row = true;
5996 54 : n->timing = TRIGGER_TYPE_AFTER;
5997 54 : n->events = intVal(linitial($7));
5998 54 : n->columns = (List *) lsecond($7);
5999 54 : n->whenClause = $15;
6000 54 : n->transitionRels = NIL;
6001 54 : processCASbits($11, @11, "TRIGGER",
6002 : &n->deferrable, &n->initdeferred, NULL,
6003 : NULL, yyscanner);
6004 54 : n->constrrel = $10;
6005 54 : $$ = (Node *) n;
6006 : }
6007 : ;
6008 :
6009 : TriggerActionTime:
6010 1392 : BEFORE { $$ = TRIGGER_TYPE_BEFORE; }
6011 1534 : | AFTER { $$ = TRIGGER_TYPE_AFTER; }
6012 138 : | INSTEAD OF { $$ = TRIGGER_TYPE_INSTEAD; }
6013 : ;
6014 :
6015 : TriggerEvents:
6016 : TriggerOneEvent
6017 3118 : { $$ = $1; }
6018 : | TriggerEvents OR TriggerOneEvent
6019 : {
6020 1078 : int events1 = intVal(linitial($1));
6021 1078 : int events2 = intVal(linitial($3));
6022 1078 : List *columns1 = (List *) lsecond($1);
6023 1078 : List *columns2 = (List *) lsecond($3);
6024 :
6025 1078 : if (events1 & events2)
6026 6 : parser_yyerror("duplicate trigger events specified");
6027 : /*
6028 : * concat'ing the columns lists loses information about
6029 : * which columns went with which event, but so long as
6030 : * only UPDATE carries columns and we disallow multiple
6031 : * UPDATE items, it doesn't matter. Command execution
6032 : * should just ignore the columns for non-UPDATE events.
6033 : */
6034 1072 : $$ = list_make2(makeInteger(events1 | events2),
6035 : list_concat(columns1, columns2));
6036 : }
6037 : ;
6038 :
6039 : TriggerOneEvent:
6040 : INSERT
6041 1552 : { $$ = list_make2(makeInteger(TRIGGER_TYPE_INSERT), NIL); }
6042 : | DELETE_P
6043 864 : { $$ = list_make2(makeInteger(TRIGGER_TYPE_DELETE), NIL); }
6044 : | UPDATE
6045 1648 : { $$ = list_make2(makeInteger(TRIGGER_TYPE_UPDATE), NIL); }
6046 : | UPDATE OF columnList
6047 94 : { $$ = list_make2(makeInteger(TRIGGER_TYPE_UPDATE), $3); }
6048 : | TRUNCATE
6049 38 : { $$ = list_make2(makeInteger(TRIGGER_TYPE_TRUNCATE), NIL); }
6050 : ;
6051 :
6052 : TriggerReferencing:
6053 424 : REFERENCING TriggerTransitions { $$ = $2; }
6054 2628 : | /*EMPTY*/ { $$ = NIL; }
6055 : ;
6056 :
6057 : TriggerTransitions:
6058 424 : TriggerTransition { $$ = list_make1($1); }
6059 138 : | TriggerTransitions TriggerTransition { $$ = lappend($1, $2); }
6060 : ;
6061 :
6062 : TriggerTransition:
6063 : TransitionOldOrNew TransitionRowOrTable opt_as TransitionRelName
6064 : {
6065 562 : TriggerTransition *n = makeNode(TriggerTransition);
6066 :
6067 562 : n->name = $4;
6068 562 : n->isNew = $1;
6069 562 : n->isTable = $2;
6070 562 : $$ = (Node *) n;
6071 : }
6072 : ;
6073 :
6074 : TransitionOldOrNew:
6075 306 : NEW { $$ = true; }
6076 256 : | OLD { $$ = false; }
6077 : ;
6078 :
6079 : TransitionRowOrTable:
6080 562 : TABLE { $$ = true; }
6081 : /*
6082 : * According to the standard, lack of a keyword here implies ROW.
6083 : * Support for that would require prohibiting ROW entirely here,
6084 : * reserving the keyword ROW, and/or requiring AS (instead of
6085 : * allowing it to be optional, as the standard specifies) as the
6086 : * next token. Requiring ROW seems cleanest and easiest to
6087 : * explain.
6088 : */
6089 0 : | ROW { $$ = false; }
6090 : ;
6091 :
6092 : TransitionRelName:
6093 562 : ColId { $$ = $1; }
6094 : ;
6095 :
6096 : TriggerForSpec:
6097 : FOR TriggerForOptEach TriggerForType
6098 : {
6099 2824 : $$ = $3;
6100 : }
6101 : | /* EMPTY */
6102 : {
6103 : /*
6104 : * If ROW/STATEMENT not specified, default to
6105 : * STATEMENT, per SQL
6106 : */
6107 228 : $$ = false;
6108 : }
6109 : ;
6110 :
6111 : TriggerForOptEach:
6112 : EACH
6113 : | /*EMPTY*/
6114 : ;
6115 :
6116 : TriggerForType:
6117 2044 : ROW { $$ = true; }
6118 780 : | STATEMENT { $$ = false; }
6119 : ;
6120 :
6121 : TriggerWhen:
6122 152 : WHEN '(' a_expr ')' { $$ = $3; }
6123 2954 : | /*EMPTY*/ { $$ = NULL; }
6124 : ;
6125 :
6126 : FUNCTION_or_PROCEDURE:
6127 : FUNCTION
6128 : | PROCEDURE
6129 : ;
6130 :
6131 : TriggerFuncArgs:
6132 574 : TriggerFuncArg { $$ = list_make1($1); }
6133 264 : | TriggerFuncArgs ',' TriggerFuncArg { $$ = lappend($1, $3); }
6134 2532 : | /*EMPTY*/ { $$ = NIL; }
6135 : ;
6136 :
6137 : TriggerFuncArg:
6138 : Iconst
6139 : {
6140 102 : $$ = (Node *) makeString(psprintf("%d", $1));
6141 : }
6142 0 : | FCONST { $$ = (Node *) makeString($1); }
6143 696 : | Sconst { $$ = (Node *) makeString($1); }
6144 40 : | ColLabel { $$ = (Node *) makeString($1); }
6145 : ;
6146 :
6147 : OptConstrFromTable:
6148 12 : FROM qualified_name { $$ = $2; }
6149 42 : | /*EMPTY*/ { $$ = NULL; }
6150 : ;
6151 :
6152 : ConstraintAttributeSpec:
6153 : /*EMPTY*/
6154 15978 : { $$ = 0; }
6155 : | ConstraintAttributeSpec ConstraintAttributeElem
6156 : {
6157 : /*
6158 : * We must complain about conflicting options.
6159 : * We could, but choose not to, complain about redundant
6160 : * options (ie, where $2's bit is already set in $1).
6161 : */
6162 1144 : int newspec = $1 | $2;
6163 :
6164 : /* special message for this case */
6165 1144 : if ((newspec & (CAS_NOT_DEFERRABLE | CAS_INITIALLY_DEFERRED)) == (CAS_NOT_DEFERRABLE | CAS_INITIALLY_DEFERRED))
6166 6 : ereport(ERROR,
6167 : (errcode(ERRCODE_SYNTAX_ERROR),
6168 : errmsg("constraint declared INITIALLY DEFERRED must be DEFERRABLE"),
6169 : parser_errposition(@2)));
6170 : /* generic message for other conflicts */
6171 1138 : if ((newspec & (CAS_NOT_DEFERRABLE | CAS_DEFERRABLE)) == (CAS_NOT_DEFERRABLE | CAS_DEFERRABLE) ||
6172 1138 : (newspec & (CAS_INITIALLY_IMMEDIATE | CAS_INITIALLY_DEFERRED)) == (CAS_INITIALLY_IMMEDIATE | CAS_INITIALLY_DEFERRED))
6173 0 : ereport(ERROR,
6174 : (errcode(ERRCODE_SYNTAX_ERROR),
6175 : errmsg("conflicting constraint properties"),
6176 : parser_errposition(@2)));
6177 1138 : $$ = newspec;
6178 : }
6179 : ;
6180 :
6181 : ConstraintAttributeElem:
6182 36 : NOT DEFERRABLE { $$ = CAS_NOT_DEFERRABLE; }
6183 210 : | DEFERRABLE { $$ = CAS_DEFERRABLE; }
6184 30 : | INITIALLY IMMEDIATE { $$ = CAS_INITIALLY_IMMEDIATE; }
6185 162 : | INITIALLY DEFERRED { $$ = CAS_INITIALLY_DEFERRED; }
6186 516 : | NOT VALID { $$ = CAS_NOT_VALID; }
6187 190 : | NO INHERIT { $$ = CAS_NO_INHERIT; }
6188 : ;
6189 :
6190 :
6191 : /*****************************************************************************
6192 : *
6193 : * QUERIES :
6194 : * CREATE EVENT TRIGGER ...
6195 : * ALTER EVENT TRIGGER ...
6196 : *
6197 : *****************************************************************************/
6198 :
6199 : CreateEventTrigStmt:
6200 : CREATE EVENT TRIGGER name ON ColLabel
6201 : EXECUTE FUNCTION_or_PROCEDURE func_name '(' ')'
6202 : {
6203 98 : CreateEventTrigStmt *n = makeNode(CreateEventTrigStmt);
6204 :
6205 98 : n->trigname = $4;
6206 98 : n->eventname = $6;
6207 98 : n->whenclause = NULL;
6208 98 : n->funcname = $9;
6209 98 : $$ = (Node *) n;
6210 : }
6211 : | CREATE EVENT TRIGGER name ON ColLabel
6212 : WHEN event_trigger_when_list
6213 : EXECUTE FUNCTION_or_PROCEDURE func_name '(' ')'
6214 : {
6215 98 : CreateEventTrigStmt *n = makeNode(CreateEventTrigStmt);
6216 :
6217 98 : n->trigname = $4;
6218 98 : n->eventname = $6;
6219 98 : n->whenclause = $8;
6220 98 : n->funcname = $11;
6221 98 : $$ = (Node *) n;
6222 : }
6223 : ;
6224 :
6225 : event_trigger_when_list:
6226 : event_trigger_when_item
6227 98 : { $$ = list_make1($1); }
6228 : | event_trigger_when_list AND event_trigger_when_item
6229 6 : { $$ = lappend($1, $3); }
6230 : ;
6231 :
6232 : event_trigger_when_item:
6233 : ColId IN_P '(' event_trigger_value_list ')'
6234 104 : { $$ = makeDefElem($1, (Node *) $4, @1); }
6235 : ;
6236 :
6237 : event_trigger_value_list:
6238 : SCONST
6239 104 : { $$ = list_make1(makeString($1)); }
6240 : | event_trigger_value_list ',' SCONST
6241 66 : { $$ = lappend($1, makeString($3)); }
6242 : ;
6243 :
6244 : AlterEventTrigStmt:
6245 : ALTER EVENT TRIGGER name enable_trigger
6246 : {
6247 48 : AlterEventTrigStmt *n = makeNode(AlterEventTrigStmt);
6248 :
6249 48 : n->trigname = $4;
6250 48 : n->tgenabled = $5;
6251 48 : $$ = (Node *) n;
6252 : }
6253 : ;
6254 :
6255 : enable_trigger:
6256 6 : ENABLE_P { $$ = TRIGGER_FIRES_ON_ORIGIN; }
6257 6 : | ENABLE_P REPLICA { $$ = TRIGGER_FIRES_ON_REPLICA; }
6258 16 : | ENABLE_P ALWAYS { $$ = TRIGGER_FIRES_ALWAYS; }
6259 20 : | DISABLE_P { $$ = TRIGGER_DISABLED; }
6260 : ;
6261 :
6262 : /*****************************************************************************
6263 : *
6264 : * QUERY :
6265 : * CREATE ASSERTION ...
6266 : *
6267 : *****************************************************************************/
6268 :
6269 : CreateAssertionStmt:
6270 : CREATE ASSERTION any_name CHECK '(' a_expr ')' ConstraintAttributeSpec
6271 : {
6272 0 : ereport(ERROR,
6273 : (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
6274 : errmsg("CREATE ASSERTION is not yet implemented"),
6275 : parser_errposition(@1)));
6276 :
6277 : $$ = NULL;
6278 : }
6279 : ;
6280 :
6281 :
6282 : /*****************************************************************************
6283 : *
6284 : * QUERY :
6285 : * define (aggregate,operator,type)
6286 : *
6287 : *****************************************************************************/
6288 :
6289 : DefineStmt:
6290 : CREATE opt_or_replace AGGREGATE func_name aggr_args definition
6291 : {
6292 544 : DefineStmt *n = makeNode(DefineStmt);
6293 :
6294 544 : n->kind = OBJECT_AGGREGATE;
6295 544 : n->oldstyle = false;
6296 544 : n->replace = $2;
6297 544 : n->defnames = $4;
6298 544 : n->args = $5;
6299 544 : n->definition = $6;
6300 544 : $$ = (Node *) n;
6301 : }
6302 : | CREATE opt_or_replace AGGREGATE func_name old_aggr_definition
6303 : {
6304 : /* old-style (pre-8.2) syntax for CREATE AGGREGATE */
6305 362 : DefineStmt *n = makeNode(DefineStmt);
6306 :
6307 362 : n->kind = OBJECT_AGGREGATE;
6308 362 : n->oldstyle = true;
6309 362 : n->replace = $2;
6310 362 : n->defnames = $4;
6311 362 : n->args = NIL;
6312 362 : n->definition = $5;
6313 362 : $$ = (Node *) n;
6314 : }
6315 : | CREATE OPERATOR any_operator definition
6316 : {
6317 1586 : DefineStmt *n = makeNode(DefineStmt);
6318 :
6319 1586 : n->kind = OBJECT_OPERATOR;
6320 1586 : n->oldstyle = false;
6321 1586 : n->defnames = $3;
6322 1586 : n->args = NIL;
6323 1586 : n->definition = $4;
6324 1586 : $$ = (Node *) n;
6325 : }
6326 : | CREATE TYPE_P any_name definition
6327 : {
6328 208 : DefineStmt *n = makeNode(DefineStmt);
6329 :
6330 208 : n->kind = OBJECT_TYPE;
6331 208 : n->oldstyle = false;
6332 208 : n->defnames = $3;
6333 208 : n->args = NIL;
6334 208 : n->definition = $4;
6335 208 : $$ = (Node *) n;
6336 : }
6337 : | CREATE TYPE_P any_name
6338 : {
6339 : /* Shell type (identified by lack of definition) */
6340 154 : DefineStmt *n = makeNode(DefineStmt);
6341 :
6342 154 : n->kind = OBJECT_TYPE;
6343 154 : n->oldstyle = false;
6344 154 : n->defnames = $3;
6345 154 : n->args = NIL;
6346 154 : n->definition = NIL;
6347 154 : $$ = (Node *) n;
6348 : }
6349 : | CREATE TYPE_P any_name AS '(' OptTableFuncElementList ')'
6350 : {
6351 3486 : CompositeTypeStmt *n = makeNode(CompositeTypeStmt);
6352 :
6353 : /* can't use qualified_name, sigh */
6354 3486 : n->typevar = makeRangeVarFromAnyName($3, @3, yyscanner);
6355 3486 : n->coldeflist = $6;
6356 3486 : $$ = (Node *) n;
6357 : }
6358 : | CREATE TYPE_P any_name AS ENUM_P '(' opt_enum_val_list ')'
6359 : {
6360 194 : CreateEnumStmt *n = makeNode(CreateEnumStmt);
6361 :
6362 194 : n->typeName = $3;
6363 194 : n->vals = $7;
6364 194 : $$ = (Node *) n;
6365 : }
6366 : | CREATE TYPE_P any_name AS RANGE definition
6367 : {
6368 168 : CreateRangeStmt *n = makeNode(CreateRangeStmt);
6369 :
6370 168 : n->typeName = $3;
6371 168 : n->params = $6;
6372 168 : $$ = (Node *) n;
6373 : }
6374 : | CREATE TEXT_P SEARCH PARSER any_name definition
6375 : {
6376 40 : DefineStmt *n = makeNode(DefineStmt);
6377 :
6378 40 : n->kind = OBJECT_TSPARSER;
6379 40 : n->args = NIL;
6380 40 : n->defnames = $5;
6381 40 : n->definition = $6;
6382 40 : $$ = (Node *) n;
6383 : }
6384 : | CREATE TEXT_P SEARCH DICTIONARY any_name definition
6385 : {
6386 2554 : DefineStmt *n = makeNode(DefineStmt);
6387 :
6388 2554 : n->kind = OBJECT_TSDICTIONARY;
6389 2554 : n->args = NIL;
6390 2554 : n->defnames = $5;
6391 2554 : n->definition = $6;
6392 2554 : $$ = (Node *) n;
6393 : }
6394 : | CREATE TEXT_P SEARCH TEMPLATE any_name definition
6395 : {
6396 130 : DefineStmt *n = makeNode(DefineStmt);
6397 :
6398 130 : n->kind = OBJECT_TSTEMPLATE;
6399 130 : n->args = NIL;
6400 130 : n->defnames = $5;
6401 130 : n->definition = $6;
6402 130 : $$ = (Node *) n;
6403 : }
6404 : | CREATE TEXT_P SEARCH CONFIGURATION any_name definition
6405 : {
6406 2496 : DefineStmt *n = makeNode(DefineStmt);
6407 :
6408 2496 : n->kind = OBJECT_TSCONFIGURATION;
6409 2496 : n->args = NIL;
6410 2496 : n->defnames = $5;
6411 2496 : n->definition = $6;
6412 2496 : $$ = (Node *) n;
6413 : }
6414 : | CREATE COLLATION any_name definition
6415 : {
6416 278 : DefineStmt *n = makeNode(DefineStmt);
6417 :
6418 278 : n->kind = OBJECT_COLLATION;
6419 278 : n->args = NIL;
6420 278 : n->defnames = $3;
6421 278 : n->definition = $4;
6422 278 : $$ = (Node *) n;
6423 : }
6424 : | CREATE COLLATION IF_P NOT EXISTS any_name definition
6425 : {
6426 18 : DefineStmt *n = makeNode(DefineStmt);
6427 :
6428 18 : n->kind = OBJECT_COLLATION;
6429 18 : n->args = NIL;
6430 18 : n->defnames = $6;
6431 18 : n->definition = $7;
6432 18 : n->if_not_exists = true;
6433 18 : $$ = (Node *) n;
6434 : }
6435 : | CREATE COLLATION any_name FROM any_name
6436 : {
6437 54 : DefineStmt *n = makeNode(DefineStmt);
6438 :
6439 54 : n->kind = OBJECT_COLLATION;
6440 54 : n->args = NIL;
6441 54 : n->defnames = $3;
6442 54 : n->definition = list_make1(makeDefElem("from", (Node *) $5, @5));
6443 54 : $$ = (Node *) n;
6444 : }
6445 : | CREATE COLLATION IF_P NOT EXISTS any_name FROM any_name
6446 : {
6447 0 : DefineStmt *n = makeNode(DefineStmt);
6448 :
6449 0 : n->kind = OBJECT_COLLATION;
6450 0 : n->args = NIL;
6451 0 : n->defnames = $6;
6452 0 : n->definition = list_make1(makeDefElem("from", (Node *) $8, @8));
6453 0 : n->if_not_exists = true;
6454 0 : $$ = (Node *) n;
6455 : }
6456 : ;
6457 :
6458 8968 : definition: '(' def_list ')' { $$ = $2; }
6459 : ;
6460 :
6461 8968 : def_list: def_elem { $$ = list_make1($1); }
6462 13976 : | def_list ',' def_elem { $$ = lappend($1, $3); }
6463 : ;
6464 :
6465 : def_elem: ColLabel '=' def_arg
6466 : {
6467 22614 : $$ = makeDefElem($1, (Node *) $3, @1);
6468 : }
6469 : | ColLabel
6470 : {
6471 330 : $$ = makeDefElem($1, NULL, @1);
6472 : }
6473 : ;
6474 :
6475 : /* Note: any simple identifier will be returned as a type name! */
6476 18436 : def_arg: func_type { $$ = (Node *) $1; }
6477 3620 : | reserved_keyword { $$ = (Node *) makeString(pstrdup($1)); }
6478 1174 : | qual_all_Op { $$ = (Node *) $1; }
6479 1294 : | NumericOnly { $$ = (Node *) $1; }
6480 1832 : | Sconst { $$ = (Node *) makeString($1); }
6481 132 : | NONE { $$ = (Node *) makeString(pstrdup($1)); }
6482 : ;
6483 :
6484 362 : old_aggr_definition: '(' old_aggr_list ')' { $$ = $2; }
6485 : ;
6486 :
6487 362 : old_aggr_list: old_aggr_elem { $$ = list_make1($1); }
6488 1292 : | old_aggr_list ',' old_aggr_elem { $$ = lappend($1, $3); }
6489 : ;
6490 :
6491 : /*
6492 : * Must use IDENT here to avoid reduce/reduce conflicts; fortunately none of
6493 : * the item names needed in old aggregate definitions are likely to become
6494 : * SQL keywords.
6495 : */
6496 : old_aggr_elem: IDENT '=' def_arg
6497 : {
6498 1654 : $$ = makeDefElem($1, (Node *) $3, @1);
6499 : }
6500 : ;
6501 :
6502 : opt_enum_val_list:
6503 186 : enum_val_list { $$ = $1; }
6504 8 : | /*EMPTY*/ { $$ = NIL; }
6505 : ;
6506 :
6507 : enum_val_list: Sconst
6508 186 : { $$ = list_make1(makeString($1)); }
6509 : | enum_val_list ',' Sconst
6510 10394 : { $$ = lappend($1, makeString($3)); }
6511 : ;
6512 :
6513 : /*****************************************************************************
6514 : *
6515 : * ALTER TYPE enumtype ADD ...
6516 : *
6517 : *****************************************************************************/
6518 :
6519 : AlterEnumStmt:
6520 : ALTER TYPE_P any_name ADD_P VALUE_P opt_if_not_exists Sconst
6521 : {
6522 154 : AlterEnumStmt *n = makeNode(AlterEnumStmt);
6523 :
6524 154 : n->typeName = $3;
6525 154 : n->oldVal = NULL;
6526 154 : n->newVal = $7;
6527 154 : n->newValNeighbor = NULL;
6528 154 : n->newValIsAfter = true;
6529 154 : n->skipIfNewValExists = $6;
6530 154 : $$ = (Node *) n;
6531 : }
6532 : | ALTER TYPE_P any_name ADD_P VALUE_P opt_if_not_exists Sconst BEFORE Sconst
6533 : {
6534 194 : AlterEnumStmt *n = makeNode(AlterEnumStmt);
6535 :
6536 194 : n->typeName = $3;
6537 194 : n->oldVal = NULL;
6538 194 : n->newVal = $7;
6539 194 : n->newValNeighbor = $9;
6540 194 : n->newValIsAfter = false;
6541 194 : n->skipIfNewValExists = $6;
6542 194 : $$ = (Node *) n;
6543 : }
6544 : | ALTER TYPE_P any_name ADD_P VALUE_P opt_if_not_exists Sconst AFTER Sconst
6545 : {
6546 22 : AlterEnumStmt *n = makeNode(AlterEnumStmt);
6547 :
6548 22 : n->typeName = $3;
6549 22 : n->oldVal = NULL;
6550 22 : n->newVal = $7;
6551 22 : n->newValNeighbor = $9;
6552 22 : n->newValIsAfter = true;
6553 22 : n->skipIfNewValExists = $6;
6554 22 : $$ = (Node *) n;
6555 : }
6556 : | ALTER TYPE_P any_name RENAME VALUE_P Sconst TO Sconst
6557 : {
6558 24 : AlterEnumStmt *n = makeNode(AlterEnumStmt);
6559 :
6560 24 : n->typeName = $3;
6561 24 : n->oldVal = $6;
6562 24 : n->newVal = $8;
6563 24 : n->newValNeighbor = NULL;
6564 24 : n->newValIsAfter = false;
6565 24 : n->skipIfNewValExists = false;
6566 24 : $$ = (Node *) n;
6567 : }
6568 : | ALTER TYPE_P any_name DROP VALUE_P Sconst
6569 : {
6570 : /*
6571 : * The following problems must be solved before this can be
6572 : * implemented:
6573 : *
6574 : * - There must be no instance of the target value in
6575 : * any table.
6576 : *
6577 : * - The value must not appear in any catalog metadata,
6578 : * such as stored view expressions or column defaults.
6579 : *
6580 : * - The value must not appear in any non-leaf page of a
6581 : * btree (and similar issues with other index types).
6582 : * This is problematic because a value could persist
6583 : * there long after it's gone from user-visible data.
6584 : *
6585 : * - Concurrent sessions must not be able to insert the
6586 : * value while the preceding conditions are being checked.
6587 : *
6588 : * - Possibly more...
6589 : */
6590 0 : ereport(ERROR,
6591 : (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
6592 : errmsg("dropping an enum value is not implemented"),
6593 : parser_errposition(@4)));
6594 : }
6595 : ;
6596 :
6597 12 : opt_if_not_exists: IF_P NOT EXISTS { $$ = true; }
6598 358 : | /* EMPTY */ { $$ = false; }
6599 : ;
6600 :
6601 :
6602 : /*****************************************************************************
6603 : *
6604 : * QUERIES :
6605 : * CREATE OPERATOR CLASS ...
6606 : * CREATE OPERATOR FAMILY ...
6607 : * ALTER OPERATOR FAMILY ...
6608 : * DROP OPERATOR CLASS ...
6609 : * DROP OPERATOR FAMILY ...
6610 : *
6611 : *****************************************************************************/
6612 :
6613 : CreateOpClassStmt:
6614 : CREATE OPERATOR CLASS any_name opt_default FOR TYPE_P Typename
6615 : USING name opt_opfamily AS opclass_item_list
6616 : {
6617 388 : CreateOpClassStmt *n = makeNode(CreateOpClassStmt);
6618 :
6619 388 : n->opclassname = $4;
6620 388 : n->isDefault = $5;
6621 388 : n->datatype = $8;
6622 388 : n->amname = $10;
6623 388 : n->opfamilyname = $11;
6624 388 : n->items = $13;
6625 388 : $$ = (Node *) n;
6626 : }
6627 : ;
6628 :
6629 : opclass_item_list:
6630 838 : opclass_item { $$ = list_make1($1); }
6631 3088 : | opclass_item_list ',' opclass_item { $$ = lappend($1, $3); }
6632 : ;
6633 :
6634 : opclass_item:
6635 : OPERATOR Iconst any_operator opclass_purpose
6636 : {
6637 1092 : CreateOpClassItem *n = makeNode(CreateOpClassItem);
6638 1092 : ObjectWithArgs *owa = makeNode(ObjectWithArgs);
6639 :
6640 1092 : owa->objname = $3;
6641 1092 : owa->objargs = NIL;
6642 1092 : n->itemtype = OPCLASS_ITEM_OPERATOR;
6643 1092 : n->name = owa;
6644 1092 : n->number = $2;
6645 1092 : n->order_family = $4;
6646 1092 : $$ = (Node *) n;
6647 : }
6648 : | OPERATOR Iconst operator_with_argtypes opclass_purpose
6649 : {
6650 1062 : CreateOpClassItem *n = makeNode(CreateOpClassItem);
6651 :
6652 1062 : n->itemtype = OPCLASS_ITEM_OPERATOR;
6653 1062 : n->name = $3;
6654 1062 : n->number = $2;
6655 1062 : n->order_family = $4;
6656 1062 : $$ = (Node *) n;
6657 : }
6658 : | FUNCTION Iconst function_with_argtypes
6659 : {
6660 1386 : CreateOpClassItem *n = makeNode(CreateOpClassItem);
6661 :
6662 1386 : n->itemtype = OPCLASS_ITEM_FUNCTION;
6663 1386 : n->name = $3;
6664 1386 : n->number = $2;
6665 1386 : $$ = (Node *) n;
6666 : }
6667 : | FUNCTION Iconst '(' type_list ')' function_with_argtypes
6668 : {
6669 188 : CreateOpClassItem *n = makeNode(CreateOpClassItem);
6670 :
6671 188 : n->itemtype = OPCLASS_ITEM_FUNCTION;
6672 188 : n->name = $6;
6673 188 : n->number = $2;
6674 188 : n->class_args = $4;
6675 188 : $$ = (Node *) n;
6676 : }
6677 : | STORAGE Typename
6678 : {
6679 198 : CreateOpClassItem *n = makeNode(CreateOpClassItem);
6680 :
6681 198 : n->itemtype = OPCLASS_ITEM_STORAGETYPE;
6682 198 : n->storedtype = $2;
6683 198 : $$ = (Node *) n;
6684 : }
6685 : ;
6686 :
6687 290 : opt_default: DEFAULT { $$ = true; }
6688 162 : | /*EMPTY*/ { $$ = false; }
6689 : ;
6690 :
6691 44 : opt_opfamily: FAMILY any_name { $$ = $2; }
6692 344 : | /*EMPTY*/ { $$ = NIL; }
6693 : ;
6694 :
6695 0 : opclass_purpose: FOR SEARCH { $$ = NIL; }
6696 72 : | FOR ORDER BY any_name { $$ = $4; }
6697 2082 : | /*EMPTY*/ { $$ = NIL; }
6698 : ;
6699 :
6700 :
6701 : CreateOpFamilyStmt:
6702 : CREATE OPERATOR FAMILY any_name USING name
6703 : {
6704 148 : CreateOpFamilyStmt *n = makeNode(CreateOpFamilyStmt);
6705 :
6706 148 : n->opfamilyname = $4;
6707 148 : n->amname = $6;
6708 148 : $$ = (Node *) n;
6709 : }
6710 : ;
6711 :
6712 : AlterOpFamilyStmt:
6713 : ALTER OPERATOR FAMILY any_name USING name ADD_P opclass_item_list
6714 : {
6715 450 : AlterOpFamilyStmt *n = makeNode(AlterOpFamilyStmt);
6716 :
6717 450 : n->opfamilyname = $4;
6718 450 : n->amname = $6;
6719 450 : n->isDrop = false;
6720 450 : n->items = $8;
6721 450 : $$ = (Node *) n;
6722 : }
6723 : | ALTER OPERATOR FAMILY any_name USING name DROP opclass_drop_list
6724 : {
6725 64 : AlterOpFamilyStmt *n = makeNode(AlterOpFamilyStmt);
6726 :
6727 64 : n->opfamilyname = $4;
6728 64 : n->amname = $6;
6729 64 : n->isDrop = true;
6730 64 : n->items = $8;
6731 64 : $$ = (Node *) n;
6732 : }
6733 : ;
6734 :
6735 : opclass_drop_list:
6736 64 : opclass_drop { $$ = list_make1($1); }
6737 30 : | opclass_drop_list ',' opclass_drop { $$ = lappend($1, $3); }
6738 : ;
6739 :
6740 : opclass_drop:
6741 : OPERATOR Iconst '(' type_list ')'
6742 : {
6743 56 : CreateOpClassItem *n = makeNode(CreateOpClassItem);
6744 :
6745 56 : n->itemtype = OPCLASS_ITEM_OPERATOR;
6746 56 : n->number = $2;
6747 56 : n->class_args = $4;
6748 56 : $$ = (Node *) n;
6749 : }
6750 : | FUNCTION Iconst '(' type_list ')'
6751 : {
6752 38 : CreateOpClassItem *n = makeNode(CreateOpClassItem);
6753 :
6754 38 : n->itemtype = OPCLASS_ITEM_FUNCTION;
6755 38 : n->number = $2;
6756 38 : n->class_args = $4;
6757 38 : $$ = (Node *) n;
6758 : }
6759 : ;
6760 :
6761 :
6762 : DropOpClassStmt:
6763 : DROP OPERATOR CLASS any_name USING name opt_drop_behavior
6764 : {
6765 38 : DropStmt *n = makeNode(DropStmt);
6766 :
6767 38 : n->objects = list_make1(lcons(makeString($6), $4));
6768 38 : n->removeType = OBJECT_OPCLASS;
6769 38 : n->behavior = $7;
6770 38 : n->missing_ok = false;
6771 38 : n->concurrent = false;
6772 38 : $$ = (Node *) n;
6773 : }
6774 : | DROP OPERATOR CLASS IF_P EXISTS any_name USING name opt_drop_behavior
6775 : {
6776 18 : DropStmt *n = makeNode(DropStmt);
6777 :
6778 18 : n->objects = list_make1(lcons(makeString($8), $6));
6779 18 : n->removeType = OBJECT_OPCLASS;
6780 18 : n->behavior = $9;
6781 18 : n->missing_ok = true;
6782 18 : n->concurrent = false;
6783 18 : $$ = (Node *) n;
6784 : }
6785 : ;
6786 :
6787 : DropOpFamilyStmt:
6788 : DROP OPERATOR FAMILY any_name USING name opt_drop_behavior
6789 : {
6790 110 : DropStmt *n = makeNode(DropStmt);
6791 :
6792 110 : n->objects = list_make1(lcons(makeString($6), $4));
6793 110 : n->removeType = OBJECT_OPFAMILY;
6794 110 : n->behavior = $7;
6795 110 : n->missing_ok = false;
6796 110 : n->concurrent = false;
6797 110 : $$ = (Node *) n;
6798 : }
6799 : | DROP OPERATOR FAMILY IF_P EXISTS any_name USING name opt_drop_behavior
6800 : {
6801 18 : DropStmt *n = makeNode(DropStmt);
6802 :
6803 18 : n->objects = list_make1(lcons(makeString($8), $6));
6804 18 : n->removeType = OBJECT_OPFAMILY;
6805 18 : n->behavior = $9;
6806 18 : n->missing_ok = true;
6807 18 : n->concurrent = false;
6808 18 : $$ = (Node *) n;
6809 : }
6810 : ;
6811 :
6812 :
6813 : /*****************************************************************************
6814 : *
6815 : * QUERY:
6816 : *
6817 : * DROP OWNED BY username [, username ...] [ RESTRICT | CASCADE ]
6818 : * REASSIGN OWNED BY username [, username ...] TO username
6819 : *
6820 : *****************************************************************************/
6821 : DropOwnedStmt:
6822 : DROP OWNED BY role_list opt_drop_behavior
6823 : {
6824 148 : DropOwnedStmt *n = makeNode(DropOwnedStmt);
6825 :
6826 148 : n->roles = $4;
6827 148 : n->behavior = $5;
6828 148 : $$ = (Node *) n;
6829 : }
6830 : ;
6831 :
6832 : ReassignOwnedStmt:
6833 : REASSIGN OWNED BY role_list TO RoleSpec
6834 : {
6835 40 : ReassignOwnedStmt *n = makeNode(ReassignOwnedStmt);
6836 :
6837 40 : n->roles = $4;
6838 40 : n->newrole = $6;
6839 40 : $$ = (Node *) n;
6840 : }
6841 : ;
6842 :
6843 : /*****************************************************************************
6844 : *
6845 : * QUERY:
6846 : *
6847 : * DROP itemtype [ IF EXISTS ] itemname [, itemname ...]
6848 : * [ RESTRICT | CASCADE ]
6849 : *
6850 : *****************************************************************************/
6851 :
6852 : DropStmt: DROP object_type_any_name IF_P EXISTS any_name_list opt_drop_behavior
6853 : {
6854 1256 : DropStmt *n = makeNode(DropStmt);
6855 :
6856 1256 : n->removeType = $2;
6857 1256 : n->missing_ok = true;
6858 1256 : n->objects = $5;
6859 1256 : n->behavior = $6;
6860 1256 : n->concurrent = false;
6861 1256 : $$ = (Node *) n;
6862 : }
6863 : | DROP object_type_any_name any_name_list opt_drop_behavior
6864 : {
6865 15296 : DropStmt *n = makeNode(DropStmt);
6866 :
6867 15296 : n->removeType = $2;
6868 15296 : n->missing_ok = false;
6869 15296 : n->objects = $3;
6870 15296 : n->behavior = $4;
6871 15296 : n->concurrent = false;
6872 15296 : $$ = (Node *) n;
6873 : }
6874 : | DROP drop_type_name IF_P EXISTS name_list opt_drop_behavior
6875 : {
6876 78 : DropStmt *n = makeNode(DropStmt);
6877 :
6878 78 : n->removeType = $2;
6879 78 : n->missing_ok = true;
6880 78 : n->objects = $5;
6881 78 : n->behavior = $6;
6882 78 : n->concurrent = false;
6883 78 : $$ = (Node *) n;
6884 : }
6885 : | DROP drop_type_name name_list opt_drop_behavior
6886 : {
6887 1314 : DropStmt *n = makeNode(DropStmt);
6888 :
6889 1314 : n->removeType = $2;
6890 1314 : n->missing_ok = false;
6891 1314 : n->objects = $3;
6892 1314 : n->behavior = $4;
6893 1314 : n->concurrent = false;
6894 1314 : $$ = (Node *) n;
6895 : }
6896 : | DROP object_type_name_on_any_name name ON any_name opt_drop_behavior
6897 : {
6898 1074 : DropStmt *n = makeNode(DropStmt);
6899 :
6900 1074 : n->removeType = $2;
6901 1074 : n->objects = list_make1(lappend($5, makeString($3)));
6902 1074 : n->behavior = $6;
6903 1074 : n->missing_ok = false;
6904 1074 : n->concurrent = false;
6905 1074 : $$ = (Node *) n;
6906 : }
6907 : | DROP object_type_name_on_any_name IF_P EXISTS name ON any_name opt_drop_behavior
6908 : {
6909 48 : DropStmt *n = makeNode(DropStmt);
6910 :
6911 48 : n->removeType = $2;
6912 48 : n->objects = list_make1(lappend($7, makeString($5)));
6913 48 : n->behavior = $8;
6914 48 : n->missing_ok = true;
6915 48 : n->concurrent = false;
6916 48 : $$ = (Node *) n;
6917 : }
6918 : | DROP TYPE_P type_name_list opt_drop_behavior
6919 : {
6920 536 : DropStmt *n = makeNode(DropStmt);
6921 :
6922 536 : n->removeType = OBJECT_TYPE;
6923 536 : n->missing_ok = false;
6924 536 : n->objects = $3;
6925 536 : n->behavior = $4;
6926 536 : n->concurrent = false;
6927 536 : $$ = (Node *) n;
6928 : }
6929 : | DROP TYPE_P IF_P EXISTS type_name_list opt_drop_behavior
6930 : {
6931 22 : DropStmt *n = makeNode(DropStmt);
6932 :
6933 22 : n->removeType = OBJECT_TYPE;
6934 22 : n->missing_ok = true;
6935 22 : n->objects = $5;
6936 22 : n->behavior = $6;
6937 22 : n->concurrent = false;
6938 22 : $$ = (Node *) n;
6939 : }
6940 : | DROP DOMAIN_P type_name_list opt_drop_behavior
6941 : {
6942 434 : DropStmt *n = makeNode(DropStmt);
6943 :
6944 434 : n->removeType = OBJECT_DOMAIN;
6945 434 : n->missing_ok = false;
6946 434 : n->objects = $3;
6947 434 : n->behavior = $4;
6948 434 : n->concurrent = false;
6949 434 : $$ = (Node *) n;
6950 : }
6951 : | DROP DOMAIN_P IF_P EXISTS type_name_list opt_drop_behavior
6952 : {
6953 18 : DropStmt *n = makeNode(DropStmt);
6954 :
6955 18 : n->removeType = OBJECT_DOMAIN;
6956 18 : n->missing_ok = true;
6957 18 : n->objects = $5;
6958 18 : n->behavior = $6;
6959 18 : n->concurrent = false;
6960 18 : $$ = (Node *) n;
6961 : }
6962 : | DROP INDEX CONCURRENTLY any_name_list opt_drop_behavior
6963 : {
6964 120 : DropStmt *n = makeNode(DropStmt);
6965 :
6966 120 : n->removeType = OBJECT_INDEX;
6967 120 : n->missing_ok = false;
6968 120 : n->objects = $4;
6969 120 : n->behavior = $5;
6970 120 : n->concurrent = true;
6971 120 : $$ = (Node *) n;
6972 : }
6973 : | DROP INDEX CONCURRENTLY IF_P EXISTS any_name_list opt_drop_behavior
6974 : {
6975 12 : DropStmt *n = makeNode(DropStmt);
6976 :
6977 12 : n->removeType = OBJECT_INDEX;
6978 12 : n->missing_ok = true;
6979 12 : n->objects = $6;
6980 12 : n->behavior = $7;
6981 12 : n->concurrent = true;
6982 12 : $$ = (Node *) n;
6983 : }
6984 : ;
6985 :
6986 : /* object types taking any_name/any_name_list */
6987 : object_type_any_name:
6988 14256 : TABLE { $$ = OBJECT_TABLE; }
6989 198 : | SEQUENCE { $$ = OBJECT_SEQUENCE; }
6990 980 : | VIEW { $$ = OBJECT_VIEW; }
6991 124 : | MATERIALIZED VIEW { $$ = OBJECT_MATVIEW; }
6992 742 : | INDEX { $$ = OBJECT_INDEX; }
6993 172 : | FOREIGN TABLE { $$ = OBJECT_FOREIGN_TABLE; }
6994 96 : | COLLATION { $$ = OBJECT_COLLATION; }
6995 56 : | CONVERSION_P { $$ = OBJECT_CONVERSION; }
6996 192 : | STATISTICS { $$ = OBJECT_STATISTIC_EXT; }
6997 20 : | TEXT_P SEARCH PARSER { $$ = OBJECT_TSPARSER; }
6998 2438 : | TEXT_P SEARCH DICTIONARY { $$ = OBJECT_TSDICTIONARY; }
6999 106 : | TEXT_P SEARCH TEMPLATE { $$ = OBJECT_TSTEMPLATE; }
7000 2442 : | TEXT_P SEARCH CONFIGURATION { $$ = OBJECT_TSCONFIGURATION; }
7001 : ;
7002 :
7003 : /*
7004 : * object types taking name/name_list
7005 : *
7006 : * DROP handles some of them separately
7007 : */
7008 :
7009 : object_type_name:
7010 194 : drop_type_name { $$ = $1; }
7011 198 : | DATABASE { $$ = OBJECT_DATABASE; }
7012 52 : | ROLE { $$ = OBJECT_ROLE; }
7013 10 : | SUBSCRIPTION { $$ = OBJECT_SUBSCRIPTION; }
7014 0 : | TABLESPACE { $$ = OBJECT_TABLESPACE; }
7015 : ;
7016 :
7017 : drop_type_name:
7018 46 : ACCESS METHOD { $$ = OBJECT_ACCESS_METHOD; }
7019 126 : | EVENT TRIGGER { $$ = OBJECT_EVENT_TRIGGER; }
7020 134 : | EXTENSION { $$ = OBJECT_EXTENSION; }
7021 148 : | FOREIGN DATA_P WRAPPER { $$ = OBJECT_FDW; }
7022 144 : | opt_procedural LANGUAGE { $$ = OBJECT_LANGUAGE; }
7023 314 : | PUBLICATION { $$ = OBJECT_PUBLICATION; }
7024 544 : | SCHEMA { $$ = OBJECT_SCHEMA; }
7025 130 : | SERVER { $$ = OBJECT_FOREIGN_SERVER; }
7026 : ;
7027 :
7028 : /* object types attached to a table */
7029 : object_type_name_on_any_name:
7030 164 : POLICY { $$ = OBJECT_POLICY; }
7031 250 : | RULE { $$ = OBJECT_RULE; }
7032 760 : | TRIGGER { $$ = OBJECT_TRIGGER; }
7033 : ;
7034 :
7035 : any_name_list:
7036 24238 : any_name { $$ = list_make1($1); }
7037 3936 : | any_name_list ',' any_name { $$ = lappend($1, $3); }
7038 : ;
7039 :
7040 59608 : any_name: ColId { $$ = list_make1(makeString($1)); }
7041 8520 : | ColId attrs { $$ = lcons(makeString($1), $2); }
7042 : ;
7043 :
7044 : attrs: '.' attr_name
7045 110318 : { $$ = list_make1(makeString($2)); }
7046 : | attrs '.' attr_name
7047 54 : { $$ = lappend($1, makeString($3)); }
7048 : ;
7049 :
7050 : type_name_list:
7051 1010 : Typename { $$ = list_make1($1); }
7052 96 : | type_name_list ',' Typename { $$ = lappend($1, $3); }
7053 : ;
7054 :
7055 : /*****************************************************************************
7056 : *
7057 : * QUERY:
7058 : * truncate table relname1, relname2, ...
7059 : *
7060 : *****************************************************************************/
7061 :
7062 : TruncateStmt:
7063 : TRUNCATE opt_table relation_expr_list opt_restart_seqs opt_drop_behavior
7064 : {
7065 1606 : TruncateStmt *n = makeNode(TruncateStmt);
7066 :
7067 1606 : n->relations = $3;
7068 1606 : n->restart_seqs = $4;
7069 1606 : n->behavior = $5;
7070 1606 : $$ = (Node *) n;
7071 : }
7072 : ;
7073 :
7074 : opt_restart_seqs:
7075 24 : CONTINUE_P IDENTITY_P { $$ = false; }
7076 24 : | RESTART IDENTITY_P { $$ = true; }
7077 1558 : | /* EMPTY */ { $$ = false; }
7078 : ;
7079 :
7080 : /*****************************************************************************
7081 : *
7082 : * COMMENT ON <object> IS <text>
7083 : *
7084 : *****************************************************************************/
7085 :
7086 : CommentStmt:
7087 : COMMENT ON object_type_any_name any_name IS comment_text
7088 : {
7089 5136 : CommentStmt *n = makeNode(CommentStmt);
7090 :
7091 5136 : n->objtype = $3;
7092 5136 : n->object = (Node *) $4;
7093 5136 : n->comment = $6;
7094 5136 : $$ = (Node *) n;
7095 : }
7096 : | COMMENT ON COLUMN any_name IS comment_text
7097 : {
7098 108 : CommentStmt *n = makeNode(CommentStmt);
7099 :
7100 108 : n->objtype = OBJECT_COLUMN;
7101 108 : n->object = (Node *) $4;
7102 108 : n->comment = $6;
7103 108 : $$ = (Node *) n;
7104 : }
7105 : | COMMENT ON object_type_name name IS comment_text
7106 : {
7107 392 : CommentStmt *n = makeNode(CommentStmt);
7108 :
7109 392 : n->objtype = $3;
7110 392 : n->object = (Node *) makeString($4);
7111 392 : n->comment = $6;
7112 392 : $$ = (Node *) n;
7113 : }
7114 : | COMMENT ON TYPE_P Typename IS comment_text
7115 : {
7116 56 : CommentStmt *n = makeNode(CommentStmt);
7117 :
7118 56 : n->objtype = OBJECT_TYPE;
7119 56 : n->object = (Node *) $4;
7120 56 : n->comment = $6;
7121 56 : $$ = (Node *) n;
7122 : }
7123 : | COMMENT ON DOMAIN_P Typename IS comment_text
7124 : {
7125 8 : CommentStmt *n = makeNode(CommentStmt);
7126 :
7127 8 : n->objtype = OBJECT_DOMAIN;
7128 8 : n->object = (Node *) $4;
7129 8 : n->comment = $6;
7130 8 : $$ = (Node *) n;
7131 : }
7132 : | COMMENT ON AGGREGATE aggregate_with_argtypes IS comment_text
7133 : {
7134 40 : CommentStmt *n = makeNode(CommentStmt);
7135 :
7136 40 : n->objtype = OBJECT_AGGREGATE;
7137 40 : n->object = (Node *) $4;
7138 40 : n->comment = $6;
7139 40 : $$ = (Node *) n;
7140 : }
7141 : | COMMENT ON FUNCTION function_with_argtypes IS comment_text
7142 : {
7143 170 : CommentStmt *n = makeNode(CommentStmt);
7144 :
7145 170 : n->objtype = OBJECT_FUNCTION;
7146 170 : n->object = (Node *) $4;
7147 170 : n->comment = $6;
7148 170 : $$ = (Node *) n;
7149 : }
7150 : | COMMENT ON OPERATOR operator_with_argtypes IS comment_text
7151 : {
7152 18 : CommentStmt *n = makeNode(CommentStmt);
7153 :
7154 18 : n->objtype = OBJECT_OPERATOR;
7155 18 : n->object = (Node *) $4;
7156 18 : n->comment = $6;
7157 18 : $$ = (Node *) n;
7158 : }
7159 : | COMMENT ON CONSTRAINT name ON any_name IS comment_text
7160 : {
7161 110 : CommentStmt *n = makeNode(CommentStmt);
7162 :
7163 110 : n->objtype = OBJECT_TABCONSTRAINT;
7164 110 : n->object = (Node *) lappend($6, makeString($4));
7165 110 : n->comment = $8;
7166 110 : $$ = (Node *) n;
7167 : }
7168 : | COMMENT ON CONSTRAINT name ON DOMAIN_P any_name IS comment_text
7169 : {
7170 38 : CommentStmt *n = makeNode(CommentStmt);
7171 :
7172 38 : n->objtype = OBJECT_DOMCONSTRAINT;
7173 : /*
7174 : * should use Typename not any_name in the production, but
7175 : * there's a shift/reduce conflict if we do that, so fix it
7176 : * up here.
7177 : */
7178 38 : n->object = (Node *) list_make2(makeTypeNameFromNameList($7), makeString($4));
7179 38 : n->comment = $9;
7180 38 : $$ = (Node *) n;
7181 : }
7182 : | COMMENT ON object_type_name_on_any_name name ON any_name IS comment_text
7183 : {
7184 40 : CommentStmt *n = makeNode(CommentStmt);
7185 :
7186 40 : n->objtype = $3;
7187 40 : n->object = (Node *) lappend($6, makeString($4));
7188 40 : n->comment = $8;
7189 40 : $$ = (Node *) n;
7190 : }
7191 : | COMMENT ON PROCEDURE function_with_argtypes IS comment_text
7192 : {
7193 0 : CommentStmt *n = makeNode(CommentStmt);
7194 :
7195 0 : n->objtype = OBJECT_PROCEDURE;
7196 0 : n->object = (Node *) $4;
7197 0 : n->comment = $6;
7198 0 : $$ = (Node *) n;
7199 : }
7200 : | COMMENT ON ROUTINE function_with_argtypes IS comment_text
7201 : {
7202 0 : CommentStmt *n = makeNode(CommentStmt);
7203 :
7204 0 : n->objtype = OBJECT_ROUTINE;
7205 0 : n->object = (Node *) $4;
7206 0 : n->comment = $6;
7207 0 : $$ = (Node *) n;
7208 : }
7209 : | COMMENT ON TRANSFORM FOR Typename LANGUAGE name IS comment_text
7210 : {
7211 14 : CommentStmt *n = makeNode(CommentStmt);
7212 :
7213 14 : n->objtype = OBJECT_TRANSFORM;
7214 14 : n->object = (Node *) list_make2($5, makeString($7));
7215 14 : n->comment = $9;
7216 14 : $$ = (Node *) n;
7217 : }
7218 : | COMMENT ON OPERATOR CLASS any_name USING name IS comment_text
7219 : {
7220 0 : CommentStmt *n = makeNode(CommentStmt);
7221 :
7222 0 : n->objtype = OBJECT_OPCLASS;
7223 0 : n->object = (Node *) lcons(makeString($7), $5);
7224 0 : n->comment = $9;
7225 0 : $$ = (Node *) n;
7226 : }
7227 : | COMMENT ON OPERATOR FAMILY any_name USING name IS comment_text
7228 : {
7229 0 : CommentStmt *n = makeNode(CommentStmt);
7230 :
7231 0 : n->objtype = OBJECT_OPFAMILY;
7232 0 : n->object = (Node *) lcons(makeString($7), $5);
7233 0 : n->comment = $9;
7234 0 : $$ = (Node *) n;
7235 : }
7236 : | COMMENT ON LARGE_P OBJECT_P NumericOnly IS comment_text
7237 : {
7238 24 : CommentStmt *n = makeNode(CommentStmt);
7239 :
7240 24 : n->objtype = OBJECT_LARGEOBJECT;
7241 24 : n->object = (Node *) $5;
7242 24 : n->comment = $7;
7243 24 : $$ = (Node *) n;
7244 : }
7245 : | COMMENT ON CAST '(' Typename AS Typename ')' IS comment_text
7246 : {
7247 0 : CommentStmt *n = makeNode(CommentStmt);
7248 :
7249 0 : n->objtype = OBJECT_CAST;
7250 0 : n->object = (Node *) list_make2($5, $7);
7251 0 : n->comment = $10;
7252 0 : $$ = (Node *) n;
7253 : }
7254 : ;
7255 :
7256 : comment_text:
7257 6050 : Sconst { $$ = $1; }
7258 104 : | NULL_P { $$ = NULL; }
7259 : ;
7260 :
7261 :
7262 : /*****************************************************************************
7263 : *
7264 : * SECURITY LABEL [FOR <provider>] ON <object> IS <label>
7265 : *
7266 : * As with COMMENT ON, <object> can refer to various types of database
7267 : * objects (e.g. TABLE, COLUMN, etc.).
7268 : *
7269 : *****************************************************************************/
7270 :
7271 : SecLabelStmt:
7272 : SECURITY LABEL opt_provider ON object_type_any_name any_name
7273 : IS security_label
7274 : {
7275 48 : SecLabelStmt *n = makeNode(SecLabelStmt);
7276 :
7277 48 : n->provider = $3;
7278 48 : n->objtype = $5;
7279 48 : n->object = (Node *) $6;
7280 48 : n->label = $8;
7281 48 : $$ = (Node *) n;
7282 : }
7283 : | SECURITY LABEL opt_provider ON COLUMN any_name
7284 : IS security_label
7285 : {
7286 4 : SecLabelStmt *n = makeNode(SecLabelStmt);
7287 :
7288 4 : n->provider = $3;
7289 4 : n->objtype = OBJECT_COLUMN;
7290 4 : n->object = (Node *) $6;
7291 4 : n->label = $8;
7292 4 : $$ = (Node *) n;
7293 : }
7294 : | SECURITY LABEL opt_provider ON object_type_name name
7295 : IS security_label
7296 : {
7297 44 : SecLabelStmt *n = makeNode(SecLabelStmt);
7298 :
7299 44 : n->provider = $3;
7300 44 : n->objtype = $5;
7301 44 : n->object = (Node *) makeString($6);
7302 44 : n->label = $8;
7303 44 : $$ = (Node *) n;
7304 : }
7305 : | SECURITY LABEL opt_provider ON TYPE_P Typename
7306 : IS security_label
7307 : {
7308 0 : SecLabelStmt *n = makeNode(SecLabelStmt);
7309 :
7310 0 : n->provider = $3;
7311 0 : n->objtype = OBJECT_TYPE;
7312 0 : n->object = (Node *) $6;
7313 0 : n->label = $8;
7314 0 : $$ = (Node *) n;
7315 : }
7316 : | SECURITY LABEL opt_provider ON DOMAIN_P Typename
7317 : IS security_label
7318 : {
7319 2 : SecLabelStmt *n = makeNode(SecLabelStmt);
7320 :
7321 2 : n->provider = $3;
7322 2 : n->objtype = OBJECT_DOMAIN;
7323 2 : n->object = (Node *) $6;
7324 2 : n->label = $8;
7325 2 : $$ = (Node *) n;
7326 : }
7327 : | SECURITY LABEL opt_provider ON AGGREGATE aggregate_with_argtypes
7328 : IS security_label
7329 : {
7330 0 : SecLabelStmt *n = makeNode(SecLabelStmt);
7331 :
7332 0 : n->provider = $3;
7333 0 : n->objtype = OBJECT_AGGREGATE;
7334 0 : n->object = (Node *) $6;
7335 0 : n->label = $8;
7336 0 : $$ = (Node *) n;
7337 : }
7338 : | SECURITY LABEL opt_provider ON FUNCTION function_with_argtypes
7339 : IS security_label
7340 : {
7341 2 : SecLabelStmt *n = makeNode(SecLabelStmt);
7342 :
7343 2 : n->provider = $3;
7344 2 : n->objtype = OBJECT_FUNCTION;
7345 2 : n->object = (Node *) $6;
7346 2 : n->label = $8;
7347 2 : $$ = (Node *) n;
7348 : }
7349 : | SECURITY LABEL opt_provider ON LARGE_P OBJECT_P NumericOnly
7350 : IS security_label
7351 : {
7352 0 : SecLabelStmt *n = makeNode(SecLabelStmt);
7353 :
7354 0 : n->provider = $3;
7355 0 : n->objtype = OBJECT_LARGEOBJECT;
7356 0 : n->object = (Node *) $7;
7357 0 : n->label = $9;
7358 0 : $$ = (Node *) n;
7359 : }
7360 : | SECURITY LABEL opt_provider ON PROCEDURE function_with_argtypes
7361 : IS security_label
7362 : {
7363 0 : SecLabelStmt *n = makeNode(SecLabelStmt);
7364 :
7365 0 : n->provider = $3;
7366 0 : n->objtype = OBJECT_PROCEDURE;
7367 0 : n->object = (Node *) $6;
7368 0 : n->label = $8;
7369 0 : $$ = (Node *) n;
7370 : }
7371 : | SECURITY LABEL opt_provider ON ROUTINE function_with_argtypes
7372 : IS security_label
7373 : {
7374 0 : SecLabelStmt *n = makeNode(SecLabelStmt);
7375 :
7376 0 : n->provider = $3;
7377 0 : n->objtype = OBJECT_ROUTINE;
7378 0 : n->object = (Node *) $6;
7379 0 : n->label = $8;
7380 0 : $$ = (Node *) n;
7381 : }
7382 : ;
7383 :
7384 20 : opt_provider: FOR NonReservedWord_or_Sconst { $$ = $2; }
7385 80 : | /* EMPTY */ { $$ = NULL; }
7386 : ;
7387 :
7388 100 : security_label: Sconst { $$ = $1; }
7389 0 : | NULL_P { $$ = NULL; }
7390 : ;
7391 :
7392 : /*****************************************************************************
7393 : *
7394 : * QUERY:
7395 : * fetch/move
7396 : *
7397 : *****************************************************************************/
7398 :
7399 : FetchStmt: FETCH fetch_args
7400 : {
7401 5674 : FetchStmt *n = (FetchStmt *) $2;
7402 :
7403 5674 : n->ismove = false;
7404 5674 : $$ = (Node *) n;
7405 : }
7406 : | MOVE fetch_args
7407 : {
7408 68 : FetchStmt *n = (FetchStmt *) $2;
7409 :
7410 68 : n->ismove = true;
7411 68 : $$ = (Node *) n;
7412 : }
7413 : ;
7414 :
7415 : fetch_args: cursor_name
7416 : {
7417 266 : FetchStmt *n = makeNode(FetchStmt);
7418 :
7419 266 : n->portalname = $1;
7420 266 : n->direction = FETCH_FORWARD;
7421 266 : n->howMany = 1;
7422 266 : $$ = (Node *) n;
7423 : }
7424 : | from_in cursor_name
7425 : {
7426 216 : FetchStmt *n = makeNode(FetchStmt);
7427 :
7428 216 : n->portalname = $2;
7429 216 : n->direction = FETCH_FORWARD;
7430 216 : n->howMany = 1;
7431 216 : $$ = (Node *) n;
7432 : }
7433 : | NEXT opt_from_in cursor_name
7434 : {
7435 262 : FetchStmt *n = makeNode(FetchStmt);
7436 :
7437 262 : n->portalname = $3;
7438 262 : n->direction = FETCH_FORWARD;
7439 262 : n->howMany = 1;
7440 262 : $$ = (Node *) n;
7441 : }
7442 : | PRIOR opt_from_in cursor_name
7443 : {
7444 30 : FetchStmt *n = makeNode(FetchStmt);
7445 :
7446 30 : n->portalname = $3;
7447 30 : n->direction = FETCH_BACKWARD;
7448 30 : n->howMany = 1;
7449 30 : $$ = (Node *) n;
7450 : }
7451 : | FIRST_P opt_from_in cursor_name
7452 : {
7453 24 : FetchStmt *n = makeNode(FetchStmt);
7454 :
7455 24 : n->portalname = $3;
7456 24 : n->direction = FETCH_ABSOLUTE;
7457 24 : n->howMany = 1;
7458 24 : $$ = (Node *) n;
7459 : }
7460 : | LAST_P opt_from_in cursor_name
7461 : {
7462 18 : FetchStmt *n = makeNode(FetchStmt);
7463 :
7464 18 : n->portalname = $3;
7465 18 : n->direction = FETCH_ABSOLUTE;
7466 18 : n->howMany = -1;
7467 18 : $$ = (Node *) n;
7468 : }
7469 : | ABSOLUTE_P SignedIconst opt_from_in cursor_name
7470 : {
7471 88 : FetchStmt *n = makeNode(FetchStmt);
7472 :
7473 88 : n->portalname = $4;
7474 88 : n->direction = FETCH_ABSOLUTE;
7475 88 : n->howMany = $2;
7476 88 : $$ = (Node *) n;
7477 : }
7478 : | RELATIVE_P SignedIconst opt_from_in cursor_name
7479 : {
7480 30 : FetchStmt *n = makeNode(FetchStmt);
7481 :
7482 30 : n->portalname = $4;
7483 30 : n->direction = FETCH_RELATIVE;
7484 30 : n->howMany = $2;
7485 30 : $$ = (Node *) n;
7486 : }
7487 : | SignedIconst opt_from_in cursor_name
7488 : {
7489 4106 : FetchStmt *n = makeNode(FetchStmt);
7490 :
7491 4106 : n->portalname = $3;
7492 4106 : n->direction = FETCH_FORWARD;
7493 4106 : n->howMany = $1;
7494 4106 : $$ = (Node *) n;
7495 : }
7496 : | ALL opt_from_in cursor_name
7497 : {
7498 266 : FetchStmt *n = makeNode(FetchStmt);
7499 :
7500 266 : n->portalname = $3;
7501 266 : n->direction = FETCH_FORWARD;
7502 266 : n->howMany = FETCH_ALL;
7503 266 : $$ = (Node *) n;
7504 : }
7505 : | FORWARD opt_from_in cursor_name
7506 : {
7507 28 : FetchStmt *n = makeNode(FetchStmt);
7508 :
7509 28 : n->portalname = $3;
7510 28 : n->direction = FETCH_FORWARD;
7511 28 : n->howMany = 1;
7512 28 : $$ = (Node *) n;
7513 : }
7514 : | FORWARD SignedIconst opt_from_in cursor_name
7515 : {
7516 6 : FetchStmt *n = makeNode(FetchStmt);
7517 :
7518 6 : n->portalname = $4;
7519 6 : n->direction = FETCH_FORWARD;
7520 6 : n->howMany = $2;
7521 6 : $$ = (Node *) n;
7522 : }
7523 : | FORWARD ALL opt_from_in cursor_name
7524 : {
7525 14 : FetchStmt *n = makeNode(FetchStmt);
7526 :
7527 14 : n->portalname = $4;
7528 14 : n->direction = FETCH_FORWARD;
7529 14 : n->howMany = FETCH_ALL;
7530 14 : $$ = (Node *) n;
7531 : }
7532 : | BACKWARD opt_from_in cursor_name
7533 : {
7534 78 : FetchStmt *n = makeNode(FetchStmt);
7535 :
7536 78 : n->portalname = $3;
7537 78 : n->direction = FETCH_BACKWARD;
7538 78 : n->howMany = 1;
7539 78 : $$ = (Node *) n;
7540 : }
7541 : | BACKWARD SignedIconst opt_from_in cursor_name
7542 : {
7543 220 : FetchStmt *n = makeNode(FetchStmt);
7544 :
7545 220 : n->portalname = $4;
7546 220 : n->direction = FETCH_BACKWARD;
7547 220 : n->howMany = $2;
7548 220 : $$ = (Node *) n;
7549 : }
7550 : | BACKWARD ALL opt_from_in cursor_name
7551 : {
7552 90 : FetchStmt *n = makeNode(FetchStmt);
7553 :
7554 90 : n->portalname = $4;
7555 90 : n->direction = FETCH_BACKWARD;
7556 90 : n->howMany = FETCH_ALL;
7557 90 : $$ = (Node *) n;
7558 : }
7559 : ;
7560 :
7561 : from_in: FROM
7562 : | IN_P
7563 : ;
7564 :
7565 : opt_from_in: from_in
7566 : | /* EMPTY */
7567 : ;
7568 :
7569 :
7570 : /*****************************************************************************
7571 : *
7572 : * GRANT and REVOKE statements
7573 : *
7574 : *****************************************************************************/
7575 :
7576 : GrantStmt: GRANT privileges ON privilege_target TO grantee_list
7577 : opt_grant_grant_option opt_granted_by
7578 : {
7579 10194 : GrantStmt *n = makeNode(GrantStmt);
7580 :
7581 10194 : n->is_grant = true;
7582 10194 : n->privileges = $2;
7583 10194 : n->targtype = ($4)->targtype;
7584 10194 : n->objtype = ($4)->objtype;
7585 10194 : n->objects = ($4)->objs;
7586 10194 : n->grantees = $6;
7587 10194 : n->grant_option = $7;
7588 10194 : n->grantor = $8;
7589 10194 : $$ = (Node *) n;
7590 : }
7591 : ;
7592 :
7593 : RevokeStmt:
7594 : REVOKE privileges ON privilege_target
7595 : FROM grantee_list opt_granted_by opt_drop_behavior
7596 : {
7597 8888 : GrantStmt *n = makeNode(GrantStmt);
7598 :
7599 8888 : n->is_grant = false;
7600 8888 : n->grant_option = false;
7601 8888 : n->privileges = $2;
7602 8888 : n->targtype = ($4)->targtype;
7603 8888 : n->objtype = ($4)->objtype;
7604 8888 : n->objects = ($4)->objs;
7605 8888 : n->grantees = $6;
7606 8888 : n->grantor = $7;
7607 8888 : n->behavior = $8;
7608 8888 : $$ = (Node *) n;
7609 : }
7610 : | REVOKE GRANT OPTION FOR privileges ON privilege_target
7611 : FROM grantee_list opt_granted_by opt_drop_behavior
7612 : {
7613 16 : GrantStmt *n = makeNode(GrantStmt);
7614 :
7615 16 : n->is_grant = false;
7616 16 : n->grant_option = true;
7617 16 : n->privileges = $5;
7618 16 : n->targtype = ($7)->targtype;
7619 16 : n->objtype = ($7)->objtype;
7620 16 : n->objects = ($7)->objs;
7621 16 : n->grantees = $9;
7622 16 : n->grantor = $10;
7623 16 : n->behavior = $11;
7624 16 : $$ = (Node *) n;
7625 : }
7626 : ;
7627 :
7628 :
7629 : /*
7630 : * Privilege names are represented as strings; the validity of the privilege
7631 : * names gets checked at execution. This is a bit annoying but we have little
7632 : * choice because of the syntactic conflict with lists of role names in
7633 : * GRANT/REVOKE. What's more, we have to call out in the "privilege"
7634 : * production any reserved keywords that need to be usable as privilege names.
7635 : */
7636 :
7637 : /* either ALL [PRIVILEGES] or a list of individual privileges */
7638 : privileges: privilege_list
7639 16972 : { $$ = $1; }
7640 : | ALL
7641 2160 : { $$ = NIL; }
7642 : | ALL PRIVILEGES
7643 120 : { $$ = NIL; }
7644 : | ALL '(' columnList ')'
7645 : {
7646 18 : AccessPriv *n = makeNode(AccessPriv);
7647 :
7648 18 : n->priv_name = NULL;
7649 18 : n->cols = $3;
7650 18 : $$ = list_make1(n);
7651 : }
7652 : | ALL PRIVILEGES '(' columnList ')'
7653 : {
7654 0 : AccessPriv *n = makeNode(AccessPriv);
7655 :
7656 0 : n->priv_name = NULL;
7657 0 : n->cols = $4;
7658 0 : $$ = list_make1(n);
7659 : }
7660 : ;
7661 :
7662 17894 : privilege_list: privilege { $$ = list_make1($1); }
7663 474 : | privilege_list ',' privilege { $$ = lappend($1, $3); }
7664 : ;
7665 :
7666 : privilege: SELECT opt_column_list
7667 : {
7668 8474 : AccessPriv *n = makeNode(AccessPriv);
7669 :
7670 8474 : n->priv_name = pstrdup($1);
7671 8474 : n->cols = $2;
7672 8474 : $$ = n;
7673 : }
7674 : | REFERENCES opt_column_list
7675 : {
7676 14 : AccessPriv *n = makeNode(AccessPriv);
7677 :
7678 14 : n->priv_name = pstrdup($1);
7679 14 : n->cols = $2;
7680 14 : $$ = n;
7681 : }
7682 : | CREATE opt_column_list
7683 : {
7684 270 : AccessPriv *n = makeNode(AccessPriv);
7685 :
7686 270 : n->priv_name = pstrdup($1);
7687 270 : n->cols = $2;
7688 270 : $$ = n;
7689 : }
7690 : | ALTER SYSTEM_P
7691 : {
7692 24 : AccessPriv *n = makeNode(AccessPriv);
7693 24 : n->priv_name = pstrdup("alter system");
7694 24 : n->cols = NIL;
7695 24 : $$ = n;
7696 : }
7697 : | ColId opt_column_list
7698 : {
7699 9586 : AccessPriv *n = makeNode(AccessPriv);
7700 :
7701 9586 : n->priv_name = $1;
7702 9586 : n->cols = $2;
7703 9586 : $$ = n;
7704 : }
7705 : ;
7706 :
7707 : parameter_name_list:
7708 : parameter_name
7709 : {
7710 74 : $$ = list_make1(makeString($1));
7711 : }
7712 : | parameter_name_list ',' parameter_name
7713 : {
7714 50 : $$ = lappend($1, makeString($3));
7715 : }
7716 : ;
7717 :
7718 : parameter_name:
7719 : ColId
7720 : {
7721 124 : $$ = $1;
7722 : }
7723 : | parameter_name '.' ColId
7724 : {
7725 30 : $$ = psprintf("%s.%s", $1, $3);
7726 : }
7727 : ;
7728 :
7729 :
7730 : /* Don't bother trying to fold the first two rules into one using
7731 : * opt_table. You're going to get conflicts.
7732 : */
7733 : privilege_target:
7734 : qualified_name_list
7735 : {
7736 10104 : PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
7737 :
7738 10104 : n->targtype = ACL_TARGET_OBJECT;
7739 10104 : n->objtype = OBJECT_TABLE;
7740 10104 : n->objs = $1;
7741 10104 : $$ = n;
7742 : }
7743 : | TABLE qualified_name_list
7744 : {
7745 368 : PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
7746 :
7747 368 : n->targtype = ACL_TARGET_OBJECT;
7748 368 : n->objtype = OBJECT_TABLE;
7749 368 : n->objs = $2;
7750 368 : $$ = n;
7751 : }
7752 : | SEQUENCE qualified_name_list
7753 : {
7754 22 : PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
7755 :
7756 22 : n->targtype = ACL_TARGET_OBJECT;
7757 22 : n->objtype = OBJECT_SEQUENCE;
7758 22 : n->objs = $2;
7759 22 : $$ = n;
7760 : }
7761 : | FOREIGN DATA_P WRAPPER name_list
7762 : {
7763 92 : PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
7764 :
7765 92 : n->targtype = ACL_TARGET_OBJECT;
7766 92 : n->objtype = OBJECT_FDW;
7767 92 : n->objs = $4;
7768 92 : $$ = n;
7769 : }
7770 : | FOREIGN SERVER name_list
7771 : {
7772 76 : PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
7773 :
7774 76 : n->targtype = ACL_TARGET_OBJECT;
7775 76 : n->objtype = OBJECT_FOREIGN_SERVER;
7776 76 : n->objs = $3;
7777 76 : $$ = n;
7778 : }
7779 : | FUNCTION function_with_argtypes_list
7780 : {
7781 7426 : PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
7782 :
7783 7426 : n->targtype = ACL_TARGET_OBJECT;
7784 7426 : n->objtype = OBJECT_FUNCTION;
7785 7426 : n->objs = $2;
7786 7426 : $$ = n;
7787 : }
7788 : | PROCEDURE function_with_argtypes_list
7789 : {
7790 42 : PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
7791 :
7792 42 : n->targtype = ACL_TARGET_OBJECT;
7793 42 : n->objtype = OBJECT_PROCEDURE;
7794 42 : n->objs = $2;
7795 42 : $$ = n;
7796 : }
7797 : | ROUTINE function_with_argtypes_list
7798 : {
7799 0 : PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
7800 :
7801 0 : n->targtype = ACL_TARGET_OBJECT;
7802 0 : n->objtype = OBJECT_ROUTINE;
7803 0 : n->objs = $2;
7804 0 : $$ = n;
7805 : }
7806 : | DATABASE name_list
7807 : {
7808 302 : PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
7809 :
7810 302 : n->targtype = ACL_TARGET_OBJECT;
7811 302 : n->objtype = OBJECT_DATABASE;
7812 302 : n->objs = $2;
7813 302 : $$ = n;
7814 : }
7815 : | DOMAIN_P any_name_list
7816 : {
7817 26 : PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
7818 :
7819 26 : n->targtype = ACL_TARGET_OBJECT;
7820 26 : n->objtype = OBJECT_DOMAIN;
7821 26 : n->objs = $2;
7822 26 : $$ = n;
7823 : }
7824 : | LANGUAGE name_list
7825 : {
7826 42 : PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
7827 :
7828 42 : n->targtype = ACL_TARGET_OBJECT;
7829 42 : n->objtype = OBJECT_LANGUAGE;
7830 42 : n->objs = $2;
7831 42 : $$ = n;
7832 : }
7833 : | LARGE_P OBJECT_P NumericOnly_list
7834 : {
7835 80 : PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
7836 :
7837 80 : n->targtype = ACL_TARGET_OBJECT;
7838 80 : n->objtype = OBJECT_LARGEOBJECT;
7839 80 : n->objs = $3;
7840 80 : $$ = n;
7841 : }
7842 : | PARAMETER parameter_name_list
7843 : {
7844 74 : PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
7845 74 : n->targtype = ACL_TARGET_OBJECT;
7846 74 : n->objtype = OBJECT_PARAMETER_ACL;
7847 74 : n->objs = $2;
7848 74 : $$ = n;
7849 : }
7850 : | SCHEMA name_list
7851 : {
7852 314 : PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
7853 :
7854 314 : n->targtype = ACL_TARGET_OBJECT;
7855 314 : n->objtype = OBJECT_SCHEMA;
7856 314 : n->objs = $2;
7857 314 : $$ = n;
7858 : }
7859 : | TABLESPACE name_list
7860 : {
7861 0 : PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
7862 :
7863 0 : n->targtype = ACL_TARGET_OBJECT;
7864 0 : n->objtype = OBJECT_TABLESPACE;
7865 0 : n->objs = $2;
7866 0 : $$ = n;
7867 : }
7868 : | TYPE_P any_name_list
7869 : {
7870 112 : PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
7871 :
7872 112 : n->targtype = ACL_TARGET_OBJECT;
7873 112 : n->objtype = OBJECT_TYPE;
7874 112 : n->objs = $2;
7875 112 : $$ = n;
7876 : }
7877 : | ALL TABLES IN_P SCHEMA name_list
7878 : {
7879 12 : PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
7880 :
7881 12 : n->targtype = ACL_TARGET_ALL_IN_SCHEMA;
7882 12 : n->objtype = OBJECT_TABLE;
7883 12 : n->objs = $5;
7884 12 : $$ = n;
7885 : }
7886 : | ALL SEQUENCES IN_P SCHEMA name_list
7887 : {
7888 0 : PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
7889 :
7890 0 : n->targtype = ACL_TARGET_ALL_IN_SCHEMA;
7891 0 : n->objtype = OBJECT_SEQUENCE;
7892 0 : n->objs = $5;
7893 0 : $$ = n;
7894 : }
7895 : | ALL FUNCTIONS IN_P SCHEMA name_list
7896 : {
7897 6 : PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
7898 :
7899 6 : n->targtype = ACL_TARGET_ALL_IN_SCHEMA;
7900 6 : n->objtype = OBJECT_FUNCTION;
7901 6 : n->objs = $5;
7902 6 : $$ = n;
7903 : }
7904 : | ALL PROCEDURES IN_P SCHEMA name_list
7905 : {
7906 6 : PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
7907 :
7908 6 : n->targtype = ACL_TARGET_ALL_IN_SCHEMA;
7909 6 : n->objtype = OBJECT_PROCEDURE;
7910 6 : n->objs = $5;
7911 6 : $$ = n;
7912 : }
7913 : | ALL ROUTINES IN_P SCHEMA name_list
7914 : {
7915 6 : PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
7916 :
7917 6 : n->targtype = ACL_TARGET_ALL_IN_SCHEMA;
7918 6 : n->objtype = OBJECT_ROUTINE;
7919 6 : n->objs = $5;
7920 6 : $$ = n;
7921 : }
7922 : ;
7923 :
7924 :
7925 : grantee_list:
7926 19258 : grantee { $$ = list_make1($1); }
7927 108 : | grantee_list ',' grantee { $$ = lappend($1, $3); }
7928 : ;
7929 :
7930 : grantee:
7931 19342 : RoleSpec { $$ = $1; }
7932 24 : | GROUP_P RoleSpec { $$ = $2; }
7933 : ;
7934 :
7935 :
7936 : opt_grant_grant_option:
7937 90 : WITH GRANT OPTION { $$ = true; }
7938 10204 : | /*EMPTY*/ { $$ = false; }
7939 : ;
7940 :
7941 : /*****************************************************************************
7942 : *
7943 : * GRANT and REVOKE ROLE statements
7944 : *
7945 : *****************************************************************************/
7946 :
7947 : GrantRoleStmt:
7948 : GRANT privilege_list TO role_list opt_granted_by
7949 : {
7950 588 : GrantRoleStmt *n = makeNode(GrantRoleStmt);
7951 :
7952 588 : n->is_grant = true;
7953 588 : n->granted_roles = $2;
7954 588 : n->grantee_roles = $4;
7955 588 : n->opt = NIL;
7956 588 : n->grantor = $5;
7957 588 : $$ = (Node *) n;
7958 : }
7959 : | GRANT privilege_list TO role_list WITH grant_role_opt_list opt_granted_by
7960 : {
7961 178 : GrantRoleStmt *n = makeNode(GrantRoleStmt);
7962 :
7963 178 : n->is_grant = true;
7964 178 : n->granted_roles = $2;
7965 178 : n->grantee_roles = $4;
7966 178 : n->opt = $6;
7967 178 : n->grantor = $7;
7968 178 : $$ = (Node *) n;
7969 : }
7970 : ;
7971 :
7972 : RevokeRoleStmt:
7973 : REVOKE privilege_list FROM role_list opt_granted_by opt_drop_behavior
7974 : {
7975 90 : GrantRoleStmt *n = makeNode(GrantRoleStmt);
7976 :
7977 90 : n->is_grant = false;
7978 90 : n->opt = NIL;
7979 90 : n->granted_roles = $2;
7980 90 : n->grantee_roles = $4;
7981 90 : n->grantor = $5;
7982 90 : n->behavior = $6;
7983 90 : $$ = (Node *) n;
7984 : }
7985 : | REVOKE ColId OPTION FOR privilege_list FROM role_list opt_granted_by opt_drop_behavior
7986 : {
7987 66 : GrantRoleStmt *n = makeNode(GrantRoleStmt);
7988 : DefElem *opt;
7989 :
7990 66 : opt = makeDefElem(pstrdup($2),
7991 66 : (Node *) makeBoolean(false), @2);
7992 66 : n->is_grant = false;
7993 66 : n->opt = list_make1(opt);
7994 66 : n->granted_roles = $5;
7995 66 : n->grantee_roles = $7;
7996 66 : n->grantor = $8;
7997 66 : n->behavior = $9;
7998 66 : $$ = (Node *) n;
7999 : }
8000 : ;
8001 :
8002 : grant_role_opt_list:
8003 120 : grant_role_opt_list ',' grant_role_opt { $$ = lappend($1, $3); }
8004 178 : | grant_role_opt { $$ = list_make1($1); }
8005 : ;
8006 :
8007 : grant_role_opt:
8008 : ColLabel grant_role_opt_value
8009 : {
8010 298 : $$ = makeDefElem(pstrdup($1), $2, @1);
8011 : }
8012 : ;
8013 :
8014 : grant_role_opt_value:
8015 72 : OPTION { $$ = (Node *) makeBoolean(true); }
8016 112 : | TRUE_P { $$ = (Node *) makeBoolean(true); }
8017 114 : | FALSE_P { $$ = (Node *) makeBoolean(false); }
8018 : ;
8019 :
8020 138 : opt_granted_by: GRANTED BY RoleSpec { $$ = $3; }
8021 19882 : | /*EMPTY*/ { $$ = NULL; }
8022 : ;
8023 :
8024 : /*****************************************************************************
8025 : *
8026 : * ALTER DEFAULT PRIVILEGES statement
8027 : *
8028 : *****************************************************************************/
8029 :
8030 : AlterDefaultPrivilegesStmt:
8031 : ALTER DEFAULT PRIVILEGES DefACLOptionList DefACLAction
8032 : {
8033 160 : AlterDefaultPrivilegesStmt *n = makeNode(AlterDefaultPrivilegesStmt);
8034 :
8035 160 : n->options = $4;
8036 160 : n->action = (GrantStmt *) $5;
8037 160 : $$ = (Node *) n;
8038 : }
8039 : ;
8040 :
8041 : DefACLOptionList:
8042 122 : DefACLOptionList DefACLOption { $$ = lappend($1, $2); }
8043 160 : | /* EMPTY */ { $$ = NIL; }
8044 : ;
8045 :
8046 : DefACLOption:
8047 : IN_P SCHEMA name_list
8048 : {
8049 54 : $$ = makeDefElem("schemas", (Node *) $3, @1);
8050 : }
8051 : | FOR ROLE role_list
8052 : {
8053 68 : $$ = makeDefElem("roles", (Node *) $3, @1);
8054 : }
8055 : | FOR USER role_list
8056 : {
8057 0 : $$ = makeDefElem("roles", (Node *) $3, @1);
8058 : }
8059 : ;
8060 :
8061 : /*
8062 : * This should match GRANT/REVOKE, except that individual target objects
8063 : * are not mentioned and we only allow a subset of object types.
8064 : */
8065 : DefACLAction:
8066 : GRANT privileges ON defacl_privilege_target TO grantee_list
8067 : opt_grant_grant_option
8068 : {
8069 100 : GrantStmt *n = makeNode(GrantStmt);
8070 :
8071 100 : n->is_grant = true;
8072 100 : n->privileges = $2;
8073 100 : n->targtype = ACL_TARGET_DEFAULTS;
8074 100 : n->objtype = $4;
8075 100 : n->objects = NIL;
8076 100 : n->grantees = $6;
8077 100 : n->grant_option = $7;
8078 100 : $$ = (Node *) n;
8079 : }
8080 : | REVOKE privileges ON defacl_privilege_target
8081 : FROM grantee_list opt_drop_behavior
8082 : {
8083 60 : GrantStmt *n = makeNode(GrantStmt);
8084 :
8085 60 : n->is_grant = false;
8086 60 : n->grant_option = false;
8087 60 : n->privileges = $2;
8088 60 : n->targtype = ACL_TARGET_DEFAULTS;
8089 60 : n->objtype = $4;
8090 60 : n->objects = NIL;
8091 60 : n->grantees = $6;
8092 60 : n->behavior = $7;
8093 60 : $$ = (Node *) n;
8094 : }
8095 : | REVOKE GRANT OPTION FOR privileges ON defacl_privilege_target
8096 : FROM grantee_list opt_drop_behavior
8097 : {
8098 0 : GrantStmt *n = makeNode(GrantStmt);
8099 :
8100 0 : n->is_grant = false;
8101 0 : n->grant_option = true;
8102 0 : n->privileges = $5;
8103 0 : n->targtype = ACL_TARGET_DEFAULTS;
8104 0 : n->objtype = $7;
8105 0 : n->objects = NIL;
8106 0 : n->grantees = $9;
8107 0 : n->behavior = $10;
8108 0 : $$ = (Node *) n;
8109 : }
8110 : ;
8111 :
8112 : defacl_privilege_target:
8113 78 : TABLES { $$ = OBJECT_TABLE; }
8114 16 : | FUNCTIONS { $$ = OBJECT_FUNCTION; }
8115 6 : | ROUTINES { $$ = OBJECT_FUNCTION; }
8116 6 : | SEQUENCES { $$ = OBJECT_SEQUENCE; }
8117 18 : | TYPES_P { $$ = OBJECT_TYPE; }
8118 36 : | SCHEMAS { $$ = OBJECT_SCHEMA; }
8119 : ;
8120 :
8121 :
8122 : /*****************************************************************************
8123 : *
8124 : * QUERY: CREATE INDEX
8125 : *
8126 : * Note: we cannot put TABLESPACE clause after WHERE clause unless we are
8127 : * willing to make TABLESPACE a fully reserved word.
8128 : *****************************************************************************/
8129 :
8130 : IndexStmt: CREATE opt_unique INDEX opt_concurrently opt_single_name
8131 : ON relation_expr access_method_clause '(' index_params ')'
8132 : opt_include opt_unique_null_treatment opt_reloptions OptTableSpace where_clause
8133 : {
8134 6332 : IndexStmt *n = makeNode(IndexStmt);
8135 :
8136 6332 : n->unique = $2;
8137 6332 : n->concurrent = $4;
8138 6332 : n->idxname = $5;
8139 6332 : n->relation = $7;
8140 6332 : n->accessMethod = $8;
8141 6332 : n->indexParams = $10;
8142 6332 : n->indexIncludingParams = $12;
8143 6332 : n->nulls_not_distinct = !$13;
8144 6332 : n->options = $14;
8145 6332 : n->tableSpace = $15;
8146 6332 : n->whereClause = $16;
8147 6332 : n->excludeOpNames = NIL;
8148 6332 : n->idxcomment = NULL;
8149 6332 : n->indexOid = InvalidOid;
8150 6332 : n->oldNumber = InvalidRelFileNumber;
8151 6332 : n->oldCreateSubid = InvalidSubTransactionId;
8152 6332 : n->oldFirstRelfilelocatorSubid = InvalidSubTransactionId;
8153 6332 : n->primary = false;
8154 6332 : n->isconstraint = false;
8155 6332 : n->deferrable = false;
8156 6332 : n->initdeferred = false;
8157 6332 : n->transformed = false;
8158 6332 : n->if_not_exists = false;
8159 6332 : n->reset_default_tblspc = false;
8160 6332 : $$ = (Node *) n;
8161 : }
8162 : | CREATE opt_unique INDEX opt_concurrently IF_P NOT EXISTS name
8163 : ON relation_expr access_method_clause '(' index_params ')'
8164 : opt_include opt_unique_null_treatment opt_reloptions OptTableSpace where_clause
8165 : {
8166 18 : IndexStmt *n = makeNode(IndexStmt);
8167 :
8168 18 : n->unique = $2;
8169 18 : n->concurrent = $4;
8170 18 : n->idxname = $8;
8171 18 : n->relation = $10;
8172 18 : n->accessMethod = $11;
8173 18 : n->indexParams = $13;
8174 18 : n->indexIncludingParams = $15;
8175 18 : n->nulls_not_distinct = !$16;
8176 18 : n->options = $17;
8177 18 : n->tableSpace = $18;
8178 18 : n->whereClause = $19;
8179 18 : n->excludeOpNames = NIL;
8180 18 : n->idxcomment = NULL;
8181 18 : n->indexOid = InvalidOid;
8182 18 : n->oldNumber = InvalidRelFileNumber;
8183 18 : n->oldCreateSubid = InvalidSubTransactionId;
8184 18 : n->oldFirstRelfilelocatorSubid = InvalidSubTransactionId;
8185 18 : n->primary = false;
8186 18 : n->isconstraint = false;
8187 18 : n->deferrable = false;
8188 18 : n->initdeferred = false;
8189 18 : n->transformed = false;
8190 18 : n->if_not_exists = true;
8191 18 : n->reset_default_tblspc = false;
8192 18 : $$ = (Node *) n;
8193 : }
8194 : ;
8195 :
8196 : opt_unique:
8197 1224 : UNIQUE { $$ = true; }
8198 5132 : | /*EMPTY*/ { $$ = false; }
8199 : ;
8200 :
8201 : access_method_clause:
8202 2904 : USING name { $$ = $2; }
8203 3680 : | /*EMPTY*/ { $$ = DEFAULT_INDEX_TYPE; }
8204 : ;
8205 :
8206 7768 : index_params: index_elem { $$ = list_make1($1); }
8207 2094 : | index_params ',' index_elem { $$ = lappend($1, $3); }
8208 : ;
8209 :
8210 :
8211 : index_elem_options:
8212 : opt_collate opt_qualified_name opt_asc_desc opt_nulls_order
8213 : {
8214 10444 : $$ = makeNode(IndexElem);
8215 10444 : $$->name = NULL;
8216 10444 : $$->expr = NULL;
8217 10444 : $$->indexcolname = NULL;
8218 10444 : $$->collation = $1;
8219 10444 : $$->opclass = $2;
8220 10444 : $$->opclassopts = NIL;
8221 10444 : $$->ordering = $3;
8222 10444 : $$->nulls_ordering = $4;
8223 : }
8224 : | opt_collate any_name reloptions opt_asc_desc opt_nulls_order
8225 : {
8226 142 : $$ = makeNode(IndexElem);
8227 142 : $$->name = NULL;
8228 142 : $$->expr = NULL;
8229 142 : $$->indexcolname = NULL;
8230 142 : $$->collation = $1;
8231 142 : $$->opclass = $2;
8232 142 : $$->opclassopts = $3;
8233 142 : $$->ordering = $4;
8234 142 : $$->nulls_ordering = $5;
8235 : }
8236 : ;
8237 :
8238 : /*
8239 : * Index attributes can be either simple column references, or arbitrary
8240 : * expressions in parens. For backwards-compatibility reasons, we allow
8241 : * an expression that's just a function call to be written without parens.
8242 : */
8243 : index_elem: ColId index_elem_options
8244 : {
8245 9514 : $$ = $2;
8246 9514 : $$->name = $1;
8247 : }
8248 : | func_expr_windowless index_elem_options
8249 : {
8250 608 : $$ = $2;
8251 608 : $$->expr = $1;
8252 : }
8253 : | '(' a_expr ')' index_elem_options
8254 : {
8255 464 : $$ = $4;
8256 464 : $$->expr = $2;
8257 : }
8258 : ;
8259 :
8260 218 : opt_include: INCLUDE '(' index_including_params ')' { $$ = $3; }
8261 6132 : | /* EMPTY */ { $$ = NIL; }
8262 : ;
8263 :
8264 218 : index_including_params: index_elem { $$ = list_make1($1); }
8265 166 : | index_including_params ',' index_elem { $$ = lappend($1, $3); }
8266 : ;
8267 :
8268 192 : opt_collate: COLLATE any_name { $$ = $2; }
8269 15640 : | /*EMPTY*/ { $$ = NIL; }
8270 : ;
8271 :
8272 :
8273 1752 : opt_asc_desc: ASC { $$ = SORTBY_ASC; }
8274 2814 : | DESC { $$ = SORTBY_DESC; }
8275 98690 : | /*EMPTY*/ { $$ = SORTBY_DEFAULT; }
8276 : ;
8277 :
8278 346 : opt_nulls_order: NULLS_LA FIRST_P { $$ = SORTBY_NULLS_FIRST; }
8279 1686 : | NULLS_LA LAST_P { $$ = SORTBY_NULLS_LAST; }
8280 101444 : | /*EMPTY*/ { $$ = SORTBY_NULLS_DEFAULT; }
8281 : ;
8282 :
8283 :
8284 : /*****************************************************************************
8285 : *
8286 : * QUERY:
8287 : * create [or replace] function <fname>
8288 : * [(<type-1> { , <type-n>})]
8289 : * returns <type-r>
8290 : * as <filename or code in language as appropriate>
8291 : * language <lang> [with parameters]
8292 : *
8293 : *****************************************************************************/
8294 :
8295 : CreateFunctionStmt:
8296 : CREATE opt_or_replace FUNCTION func_name func_args_with_defaults
8297 : RETURNS func_return opt_createfunc_opt_list opt_routine_body
8298 : {
8299 21234 : CreateFunctionStmt *n = makeNode(CreateFunctionStmt);
8300 :
8301 21234 : n->is_procedure = false;
8302 21234 : n->replace = $2;
8303 21234 : n->funcname = $4;
8304 21234 : n->parameters = $5;
8305 21234 : n->returnType = $7;
8306 21234 : n->options = $8;
8307 21234 : n->sql_body = $9;
8308 21234 : $$ = (Node *) n;
8309 : }
8310 : | CREATE opt_or_replace FUNCTION func_name func_args_with_defaults
8311 : RETURNS TABLE '(' table_func_column_list ')' opt_createfunc_opt_list opt_routine_body
8312 : {
8313 188 : CreateFunctionStmt *n = makeNode(CreateFunctionStmt);
8314 :
8315 188 : n->is_procedure = false;
8316 188 : n->replace = $2;
8317 188 : n->funcname = $4;
8318 188 : n->parameters = mergeTableFuncParameters($5, $9, yyscanner);
8319 188 : n->returnType = TableFuncTypeName($9);
8320 188 : n->returnType->location = @7;
8321 188 : n->options = $11;
8322 188 : n->sql_body = $12;
8323 188 : $$ = (Node *) n;
8324 : }
8325 : | CREATE opt_or_replace FUNCTION func_name func_args_with_defaults
8326 : opt_createfunc_opt_list opt_routine_body
8327 : {
8328 476 : CreateFunctionStmt *n = makeNode(CreateFunctionStmt);
8329 :
8330 476 : n->is_procedure = false;
8331 476 : n->replace = $2;
8332 476 : n->funcname = $4;
8333 476 : n->parameters = $5;
8334 476 : n->returnType = NULL;
8335 476 : n->options = $6;
8336 476 : n->sql_body = $7;
8337 476 : $$ = (Node *) n;
8338 : }
8339 : | CREATE opt_or_replace PROCEDURE func_name func_args_with_defaults
8340 : opt_createfunc_opt_list opt_routine_body
8341 : {
8342 362 : CreateFunctionStmt *n = makeNode(CreateFunctionStmt);
8343 :
8344 362 : n->is_procedure = true;
8345 362 : n->replace = $2;
8346 362 : n->funcname = $4;
8347 362 : n->parameters = $5;
8348 362 : n->returnType = NULL;
8349 362 : n->options = $6;
8350 362 : n->sql_body = $7;
8351 362 : $$ = (Node *) n;
8352 : }
8353 : ;
8354 :
8355 : opt_or_replace:
8356 9032 : OR REPLACE { $$ = true; }
8357 18496 : | /*EMPTY*/ { $$ = false; }
8358 : ;
8359 :
8360 9260 : func_args: '(' func_args_list ')' { $$ = $2; }
8361 4892 : | '(' ')' { $$ = NIL; }
8362 : ;
8363 :
8364 : func_args_list:
8365 9260 : func_arg { $$ = list_make1($1); }
8366 7788 : | func_args_list ',' func_arg { $$ = lappend($1, $3); }
8367 : ;
8368 :
8369 : function_with_argtypes_list:
8370 11064 : function_with_argtypes { $$ = list_make1($1); }
8371 : | function_with_argtypes_list ',' function_with_argtypes
8372 78 : { $$ = lappend($1, $3); }
8373 : ;
8374 :
8375 : function_with_argtypes:
8376 : func_name func_args
8377 : {
8378 14152 : ObjectWithArgs *n = makeNode(ObjectWithArgs);
8379 :
8380 14152 : n->objname = $1;
8381 14152 : n->objargs = extractArgTypes($2);
8382 14152 : n->objfuncargs = $2;
8383 14152 : $$ = n;
8384 : }
8385 : /*
8386 : * Because of reduce/reduce conflicts, we can't use func_name
8387 : * below, but we can write it out the long way, which actually
8388 : * allows more cases.
8389 : */
8390 : | type_func_name_keyword
8391 : {
8392 0 : ObjectWithArgs *n = makeNode(ObjectWithArgs);
8393 :
8394 0 : n->objname = list_make1(makeString(pstrdup($1)));
8395 0 : n->args_unspecified = true;
8396 0 : $$ = n;
8397 : }
8398 : | ColId
8399 : {
8400 322 : ObjectWithArgs *n = makeNode(ObjectWithArgs);
8401 :
8402 322 : n->objname = list_make1(makeString($1));
8403 322 : n->args_unspecified = true;
8404 322 : $$ = n;
8405 : }
8406 : | ColId indirection
8407 : {
8408 28 : ObjectWithArgs *n = makeNode(ObjectWithArgs);
8409 :
8410 28 : n->objname = check_func_name(lcons(makeString($1), $2),
8411 : yyscanner);
8412 28 : n->args_unspecified = true;
8413 28 : $$ = n;
8414 : }
8415 : ;
8416 :
8417 : /*
8418 : * func_args_with_defaults is separate because we only want to accept
8419 : * defaults in CREATE FUNCTION, not in ALTER etc.
8420 : */
8421 : func_args_with_defaults:
8422 18072 : '(' func_args_with_defaults_list ')' { $$ = $2; }
8423 4188 : | '(' ')' { $$ = NIL; }
8424 : ;
8425 :
8426 : func_args_with_defaults_list:
8427 18072 : func_arg_with_default { $$ = list_make1($1); }
8428 : | func_args_with_defaults_list ',' func_arg_with_default
8429 31360 : { $$ = lappend($1, $3); }
8430 : ;
8431 :
8432 : /*
8433 : * The style with arg_class first is SQL99 standard, but Oracle puts
8434 : * param_name first; accept both since it's likely people will try both
8435 : * anyway. Don't bother trying to save productions by letting arg_class
8436 : * have an empty alternative ... you'll get shift/reduce conflicts.
8437 : *
8438 : * We can catch over-specified arguments here if we want to,
8439 : * but for now better to silently swallow typmod, etc.
8440 : * - thomas 2000-03-22
8441 : */
8442 : func_arg:
8443 : arg_class param_name func_type
8444 : {
8445 14084 : FunctionParameter *n = makeNode(FunctionParameter);
8446 :
8447 14084 : n->name = $2;
8448 14084 : n->argType = $3;
8449 14084 : n->mode = $1;
8450 14084 : n->defexpr = NULL;
8451 14084 : n->location = @1;
8452 14084 : $$ = n;
8453 : }
8454 : | param_name arg_class func_type
8455 : {
8456 412 : FunctionParameter *n = makeNode(FunctionParameter);
8457 :
8458 412 : n->name = $1;
8459 412 : n->argType = $3;
8460 412 : n->mode = $2;
8461 412 : n->defexpr = NULL;
8462 412 : n->location = @1;
8463 412 : $$ = n;
8464 : }
8465 : | param_name func_type
8466 : {
8467 15420 : FunctionParameter *n = makeNode(FunctionParameter);
8468 :
8469 15420 : n->name = $1;
8470 15420 : n->argType = $2;
8471 15420 : n->mode = FUNC_PARAM_DEFAULT;
8472 15420 : n->defexpr = NULL;
8473 15420 : n->location = @1;
8474 15420 : $$ = n;
8475 : }
8476 : | arg_class func_type
8477 : {
8478 314 : FunctionParameter *n = makeNode(FunctionParameter);
8479 :
8480 314 : n->name = NULL;
8481 314 : n->argType = $2;
8482 314 : n->mode = $1;
8483 314 : n->defexpr = NULL;
8484 314 : n->location = @1;
8485 314 : $$ = n;
8486 : }
8487 : | func_type
8488 : {
8489 37150 : FunctionParameter *n = makeNode(FunctionParameter);
8490 :
8491 37150 : n->name = NULL;
8492 37150 : n->argType = $1;
8493 37150 : n->mode = FUNC_PARAM_DEFAULT;
8494 37150 : n->defexpr = NULL;
8495 37150 : n->location = @1;
8496 37150 : $$ = n;
8497 : }
8498 : ;
8499 :
8500 : /* INOUT is SQL99 standard, IN OUT is for Oracle compatibility */
8501 3376 : arg_class: IN_P { $$ = FUNC_PARAM_IN; }
8502 10710 : | OUT_P { $$ = FUNC_PARAM_OUT; }
8503 198 : | INOUT { $$ = FUNC_PARAM_INOUT; }
8504 0 : | IN_P OUT_P { $$ = FUNC_PARAM_INOUT; }
8505 526 : | VARIADIC { $$ = FUNC_PARAM_VARIADIC; }
8506 : ;
8507 :
8508 : /*
8509 : * Ideally param_name should be ColId, but that causes too many conflicts.
8510 : */
8511 : param_name: type_function_name
8512 : ;
8513 :
8514 : func_return:
8515 : func_type
8516 : {
8517 : /* We can catch over-specified results here if we want to,
8518 : * but for now better to silently swallow typmod, etc.
8519 : * - thomas 2000-03-22
8520 : */
8521 21234 : $$ = $1;
8522 : }
8523 : ;
8524 :
8525 : /*
8526 : * We would like to make the %TYPE productions here be ColId attrs etc,
8527 : * but that causes reduce/reduce conflicts. type_function_name
8528 : * is next best choice.
8529 : */
8530 108464 : func_type: Typename { $$ = $1; }
8531 : | type_function_name attrs '%' TYPE_P
8532 : {
8533 18 : $$ = makeTypeNameFromNameList(lcons(makeString($1), $2));
8534 18 : $$->pct_type = true;
8535 18 : $$->location = @1;
8536 : }
8537 : | SETOF type_function_name attrs '%' TYPE_P
8538 : {
8539 6 : $$ = makeTypeNameFromNameList(lcons(makeString($2), $3));
8540 6 : $$->pct_type = true;
8541 6 : $$->setof = true;
8542 6 : $$->location = @2;
8543 : }
8544 : ;
8545 :
8546 : func_arg_with_default:
8547 : func_arg
8548 : {
8549 42604 : $$ = $1;
8550 : }
8551 : | func_arg DEFAULT a_expr
8552 : {
8553 6632 : $$ = $1;
8554 6632 : $$->defexpr = $3;
8555 : }
8556 : | func_arg '=' a_expr
8557 : {
8558 196 : $$ = $1;
8559 196 : $$->defexpr = $3;
8560 : }
8561 : ;
8562 :
8563 : /* Aggregate args can be most things that function args can be */
8564 : aggr_arg: func_arg
8565 : {
8566 900 : if (!($1->mode == FUNC_PARAM_DEFAULT ||
8567 60 : $1->mode == FUNC_PARAM_IN ||
8568 60 : $1->mode == FUNC_PARAM_VARIADIC))
8569 0 : ereport(ERROR,
8570 : (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
8571 : errmsg("aggregates cannot have output arguments"),
8572 : parser_errposition(@1)));
8573 900 : $$ = $1;
8574 : }
8575 : ;
8576 :
8577 : /*
8578 : * The SQL standard offers no guidance on how to declare aggregate argument
8579 : * lists, since it doesn't have CREATE AGGREGATE etc. We accept these cases:
8580 : *
8581 : * (*) - normal agg with no args
8582 : * (aggr_arg,...) - normal agg with args
8583 : * (ORDER BY aggr_arg,...) - ordered-set agg with no direct args
8584 : * (aggr_arg,... ORDER BY aggr_arg,...) - ordered-set agg with direct args
8585 : *
8586 : * The zero-argument case is spelled with '*' for consistency with COUNT(*).
8587 : *
8588 : * An additional restriction is that if the direct-args list ends in a
8589 : * VARIADIC item, the ordered-args list must contain exactly one item that
8590 : * is also VARIADIC with the same type. This allows us to collapse the two
8591 : * VARIADIC items into one, which is necessary to represent the aggregate in
8592 : * pg_proc. We check this at the grammar stage so that we can return a list
8593 : * in which the second VARIADIC item is already discarded, avoiding extra work
8594 : * in cases such as DROP AGGREGATE.
8595 : *
8596 : * The return value of this production is a two-element list, in which the
8597 : * first item is a sublist of FunctionParameter nodes (with any duplicate
8598 : * VARIADIC item already dropped, as per above) and the second is an Integer
8599 : * node, containing -1 if there was no ORDER BY and otherwise the number
8600 : * of argument declarations before the ORDER BY. (If this number is equal
8601 : * to the first sublist's length, then we dropped a duplicate VARIADIC item.)
8602 : * This representation is passed as-is to CREATE AGGREGATE; for operations
8603 : * on existing aggregates, we can just apply extractArgTypes to the first
8604 : * sublist.
8605 : */
8606 : aggr_args: '(' '*' ')'
8607 : {
8608 136 : $$ = list_make2(NIL, makeInteger(-1));
8609 : }
8610 : | '(' aggr_args_list ')'
8611 : {
8612 732 : $$ = list_make2($2, makeInteger(-1));
8613 : }
8614 : | '(' ORDER BY aggr_args_list ')'
8615 : {
8616 6 : $$ = list_make2($4, makeInteger(0));
8617 : }
8618 : | '(' aggr_args_list ORDER BY aggr_args_list ')'
8619 : {
8620 : /* this is the only case requiring consistency checking */
8621 32 : $$ = makeOrderedSetArgs($2, $5, yyscanner);
8622 : }
8623 : ;
8624 :
8625 : aggr_args_list:
8626 802 : aggr_arg { $$ = list_make1($1); }
8627 98 : | aggr_args_list ',' aggr_arg { $$ = lappend($1, $3); }
8628 : ;
8629 :
8630 : aggregate_with_argtypes:
8631 : func_name aggr_args
8632 : {
8633 362 : ObjectWithArgs *n = makeNode(ObjectWithArgs);
8634 :
8635 362 : n->objname = $1;
8636 362 : n->objargs = extractAggrArgTypes($2);
8637 362 : n->objfuncargs = (List *) linitial($2);
8638 362 : $$ = n;
8639 : }
8640 : ;
8641 :
8642 : aggregate_with_argtypes_list:
8643 104 : aggregate_with_argtypes { $$ = list_make1($1); }
8644 : | aggregate_with_argtypes_list ',' aggregate_with_argtypes
8645 0 : { $$ = lappend($1, $3); }
8646 : ;
8647 :
8648 : opt_createfunc_opt_list:
8649 : createfunc_opt_list
8650 48 : | /*EMPTY*/ { $$ = NIL; }
8651 : ;
8652 :
8653 : createfunc_opt_list:
8654 : /* Must be at least one to prevent conflict */
8655 22212 : createfunc_opt_item { $$ = list_make1($1); }
8656 57962 : | createfunc_opt_list createfunc_opt_item { $$ = lappend($1, $2); }
8657 : ;
8658 :
8659 : /*
8660 : * Options common to both CREATE FUNCTION and ALTER FUNCTION
8661 : */
8662 : common_func_opt_item:
8663 : CALLED ON NULL_P INPUT_P
8664 : {
8665 460 : $$ = makeDefElem("strict", (Node *) makeBoolean(false), @1);
8666 : }
8667 : | RETURNS NULL_P ON NULL_P INPUT_P
8668 : {
8669 792 : $$ = makeDefElem("strict", (Node *) makeBoolean(true), @1);
8670 : }
8671 : | STRICT_P
8672 : {
8673 11180 : $$ = makeDefElem("strict", (Node *) makeBoolean(true), @1);
8674 : }
8675 : | IMMUTABLE
8676 : {
8677 8498 : $$ = makeDefElem("volatility", (Node *) makeString("immutable"), @1);
8678 : }
8679 : | STABLE
8680 : {
8681 2100 : $$ = makeDefElem("volatility", (Node *) makeString("stable"), @1);
8682 : }
8683 : | VOLATILE
8684 : {
8685 1672 : $$ = makeDefElem("volatility", (Node *) makeString("volatile"), @1);
8686 : }
8687 : | EXTERNAL SECURITY DEFINER
8688 : {
8689 0 : $$ = makeDefElem("security", (Node *) makeBoolean(true), @1);
8690 : }
8691 : | EXTERNAL SECURITY INVOKER
8692 : {
8693 0 : $$ = makeDefElem("security", (Node *) makeBoolean(false), @1);
8694 : }
8695 : | SECURITY DEFINER
8696 : {
8697 48 : $$ = makeDefElem("security", (Node *) makeBoolean(true), @1);
8698 : }
8699 : | SECURITY INVOKER
8700 : {
8701 12 : $$ = makeDefElem("security", (Node *) makeBoolean(false), @1);
8702 : }
8703 : | LEAKPROOF
8704 : {
8705 46 : $$ = makeDefElem("leakproof", (Node *) makeBoolean(true), @1);
8706 : }
8707 : | NOT LEAKPROOF
8708 : {
8709 12 : $$ = makeDefElem("leakproof", (Node *) makeBoolean(false), @1);
8710 : }
8711 : | COST NumericOnly
8712 : {
8713 3908 : $$ = makeDefElem("cost", (Node *) $2, @1);
8714 : }
8715 : | ROWS NumericOnly
8716 : {
8717 532 : $$ = makeDefElem("rows", (Node *) $2, @1);
8718 : }
8719 : | SUPPORT any_name
8720 : {
8721 104 : $$ = makeDefElem("support", (Node *) $2, @1);
8722 : }
8723 : | FunctionSetResetClause
8724 : {
8725 : /* we abuse the normal content of a DefElem here */
8726 140 : $$ = makeDefElem("set", (Node *) $1, @1);
8727 : }
8728 : | PARALLEL ColId
8729 : {
8730 11716 : $$ = makeDefElem("parallel", (Node *) makeString($2), @1);
8731 : }
8732 : ;
8733 :
8734 : createfunc_opt_item:
8735 : AS func_as
8736 : {
8737 17256 : $$ = makeDefElem("as", (Node *) $2, @1);
8738 : }
8739 : | LANGUAGE NonReservedWord_or_Sconst
8740 : {
8741 22192 : $$ = makeDefElem("language", (Node *) makeString($2), @1);
8742 : }
8743 : | TRANSFORM transform_type_list
8744 : {
8745 118 : $$ = makeDefElem("transform", (Node *) $2, @1);
8746 : }
8747 : | WINDOW
8748 : {
8749 20 : $$ = makeDefElem("window", (Node *) makeBoolean(true), @1);
8750 : }
8751 : | common_func_opt_item
8752 : {
8753 40588 : $$ = $1;
8754 : }
8755 : ;
8756 :
8757 14562 : func_as: Sconst { $$ = list_make1(makeString($1)); }
8758 : | Sconst ',' Sconst
8759 : {
8760 2694 : $$ = list_make2(makeString($1), makeString($3));
8761 : }
8762 : ;
8763 :
8764 : ReturnStmt: RETURN a_expr
8765 : {
8766 4310 : ReturnStmt *r = makeNode(ReturnStmt);
8767 :
8768 4310 : r->returnval = (Node *) $2;
8769 4310 : $$ = (Node *) r;
8770 : }
8771 : ;
8772 :
8773 : opt_routine_body:
8774 : ReturnStmt
8775 : {
8776 4304 : $$ = $1;
8777 : }
8778 : | BEGIN_P ATOMIC routine_body_stmt_list END_P
8779 : {
8780 : /*
8781 : * A compound statement is stored as a single-item list
8782 : * containing the list of statements as its member. That
8783 : * way, the parse analysis code can tell apart an empty
8784 : * body from no body at all.
8785 : */
8786 706 : $$ = (Node *) list_make1($3);
8787 : }
8788 : | /*EMPTY*/
8789 : {
8790 17250 : $$ = NULL;
8791 : }
8792 : ;
8793 :
8794 : routine_body_stmt_list:
8795 : routine_body_stmt_list routine_body_stmt ';'
8796 : {
8797 : /* As in stmtmulti, discard empty statements */
8798 722 : if ($2 != NULL)
8799 704 : $$ = lappend($1, $2);
8800 : else
8801 18 : $$ = $1;
8802 : }
8803 : | /*EMPTY*/
8804 : {
8805 706 : $$ = NIL;
8806 : }
8807 : ;
8808 :
8809 : routine_body_stmt:
8810 : stmt
8811 : | ReturnStmt
8812 : ;
8813 :
8814 : transform_type_list:
8815 118 : FOR TYPE_P Typename { $$ = list_make1($3); }
8816 4 : | transform_type_list ',' FOR TYPE_P Typename { $$ = lappend($1, $5); }
8817 : ;
8818 :
8819 : opt_definition:
8820 582 : WITH definition { $$ = $2; }
8821 9410 : | /*EMPTY*/ { $$ = NIL; }
8822 : ;
8823 :
8824 : table_func_column: param_name func_type
8825 : {
8826 406 : FunctionParameter *n = makeNode(FunctionParameter);
8827 :
8828 406 : n->name = $1;
8829 406 : n->argType = $2;
8830 406 : n->mode = FUNC_PARAM_TABLE;
8831 406 : n->defexpr = NULL;
8832 406 : n->location = @1;
8833 406 : $$ = n;
8834 : }
8835 : ;
8836 :
8837 : table_func_column_list:
8838 : table_func_column
8839 : {
8840 188 : $$ = list_make1($1);
8841 : }
8842 : | table_func_column_list ',' table_func_column
8843 : {
8844 218 : $$ = lappend($1, $3);
8845 : }
8846 : ;
8847 :
8848 : /*****************************************************************************
8849 : * ALTER FUNCTION / ALTER PROCEDURE / ALTER ROUTINE
8850 : *
8851 : * RENAME and OWNER subcommands are already provided by the generic
8852 : * ALTER infrastructure, here we just specify alterations that can
8853 : * only be applied to functions.
8854 : *
8855 : *****************************************************************************/
8856 : AlterFunctionStmt:
8857 : ALTER FUNCTION function_with_argtypes alterfunc_opt_list opt_restrict
8858 : {
8859 614 : AlterFunctionStmt *n = makeNode(AlterFunctionStmt);
8860 :
8861 614 : n->objtype = OBJECT_FUNCTION;
8862 614 : n->func = $3;
8863 614 : n->actions = $4;
8864 614 : $$ = (Node *) n;
8865 : }
8866 : | ALTER PROCEDURE function_with_argtypes alterfunc_opt_list opt_restrict
8867 : {
8868 18 : AlterFunctionStmt *n = makeNode(AlterFunctionStmt);
8869 :
8870 18 : n->objtype = OBJECT_PROCEDURE;
8871 18 : n->func = $3;
8872 18 : n->actions = $4;
8873 18 : $$ = (Node *) n;
8874 : }
8875 : | ALTER ROUTINE function_with_argtypes alterfunc_opt_list opt_restrict
8876 : {
8877 0 : AlterFunctionStmt *n = makeNode(AlterFunctionStmt);
8878 :
8879 0 : n->objtype = OBJECT_ROUTINE;
8880 0 : n->func = $3;
8881 0 : n->actions = $4;
8882 0 : $$ = (Node *) n;
8883 : }
8884 : ;
8885 :
8886 : alterfunc_opt_list:
8887 : /* At least one option must be specified */
8888 632 : common_func_opt_item { $$ = list_make1($1); }
8889 0 : | alterfunc_opt_list common_func_opt_item { $$ = lappend($1, $2); }
8890 : ;
8891 :
8892 : /* Ignored, merely for SQL compliance */
8893 : opt_restrict:
8894 : RESTRICT
8895 : | /* EMPTY */
8896 : ;
8897 :
8898 :
8899 : /*****************************************************************************
8900 : *
8901 : * QUERY:
8902 : *
8903 : * DROP FUNCTION funcname (arg1, arg2, ...) [ RESTRICT | CASCADE ]
8904 : * DROP PROCEDURE procname (arg1, arg2, ...) [ RESTRICT | CASCADE ]
8905 : * DROP ROUTINE routname (arg1, arg2, ...) [ RESTRICT | CASCADE ]
8906 : * DROP AGGREGATE aggname (arg1, ...) [ RESTRICT | CASCADE ]
8907 : * DROP OPERATOR opname (leftoperand_typ, rightoperand_typ) [ RESTRICT | CASCADE ]
8908 : *
8909 : *****************************************************************************/
8910 :
8911 : RemoveFuncStmt:
8912 : DROP FUNCTION function_with_argtypes_list opt_drop_behavior
8913 : {
8914 3174 : DropStmt *n = makeNode(DropStmt);
8915 :
8916 3174 : n->removeType = OBJECT_FUNCTION;
8917 3174 : n->objects = $3;
8918 3174 : n->behavior = $4;
8919 3174 : n->missing_ok = false;
8920 3174 : n->concurrent = false;
8921 3174 : $$ = (Node *) n;
8922 : }
8923 : | DROP FUNCTION IF_P EXISTS function_with_argtypes_list opt_drop_behavior
8924 : {
8925 260 : DropStmt *n = makeNode(DropStmt);
8926 :
8927 260 : n->removeType = OBJECT_FUNCTION;
8928 260 : n->objects = $5;
8929 260 : n->behavior = $6;
8930 260 : n->missing_ok = true;
8931 260 : n->concurrent = false;
8932 260 : $$ = (Node *) n;
8933 : }
8934 : | DROP PROCEDURE function_with_argtypes_list opt_drop_behavior
8935 : {
8936 138 : DropStmt *n = makeNode(DropStmt);
8937 :
8938 138 : n->removeType = OBJECT_PROCEDURE;
8939 138 : n->objects = $3;
8940 138 : n->behavior = $4;
8941 138 : n->missing_ok = false;
8942 138 : n->concurrent = false;
8943 138 : $$ = (Node *) n;
8944 : }
8945 : | DROP PROCEDURE IF_P EXISTS function_with_argtypes_list opt_drop_behavior
8946 : {
8947 6 : DropStmt *n = makeNode(DropStmt);
8948 :
8949 6 : n->removeType = OBJECT_PROCEDURE;
8950 6 : n->objects = $5;
8951 6 : n->behavior = $6;
8952 6 : n->missing_ok = true;
8953 6 : n->concurrent = false;
8954 6 : $$ = (Node *) n;
8955 : }
8956 : | DROP ROUTINE function_with_argtypes_list opt_drop_behavior
8957 : {
8958 12 : DropStmt *n = makeNode(DropStmt);
8959 :
8960 12 : n->removeType = OBJECT_ROUTINE;
8961 12 : n->objects = $3;
8962 12 : n->behavior = $4;
8963 12 : n->missing_ok = false;
8964 12 : n->concurrent = false;
8965 12 : $$ = (Node *) n;
8966 : }
8967 : | DROP ROUTINE IF_P EXISTS function_with_argtypes_list opt_drop_behavior
8968 : {
8969 6 : DropStmt *n = makeNode(DropStmt);
8970 :
8971 6 : n->removeType = OBJECT_ROUTINE;
8972 6 : n->objects = $5;
8973 6 : n->behavior = $6;
8974 6 : n->missing_ok = true;
8975 6 : n->concurrent = false;
8976 6 : $$ = (Node *) n;
8977 : }
8978 : ;
8979 :
8980 : RemoveAggrStmt:
8981 : DROP AGGREGATE aggregate_with_argtypes_list opt_drop_behavior
8982 : {
8983 74 : DropStmt *n = makeNode(DropStmt);
8984 :
8985 74 : n->removeType = OBJECT_AGGREGATE;
8986 74 : n->objects = $3;
8987 74 : n->behavior = $4;
8988 74 : n->missing_ok = false;
8989 74 : n->concurrent = false;
8990 74 : $$ = (Node *) n;
8991 : }
8992 : | DROP AGGREGATE IF_P EXISTS aggregate_with_argtypes_list opt_drop_behavior
8993 : {
8994 30 : DropStmt *n = makeNode(DropStmt);
8995 :
8996 30 : n->removeType = OBJECT_AGGREGATE;
8997 30 : n->objects = $5;
8998 30 : n->behavior = $6;
8999 30 : n->missing_ok = true;
9000 30 : n->concurrent = false;
9001 30 : $$ = (Node *) n;
9002 : }
9003 : ;
9004 :
9005 : RemoveOperStmt:
9006 : DROP OPERATOR operator_with_argtypes_list opt_drop_behavior
9007 : {
9008 194 : DropStmt *n = makeNode(DropStmt);
9009 :
9010 194 : n->removeType = OBJECT_OPERATOR;
9011 194 : n->objects = $3;
9012 194 : n->behavior = $4;
9013 194 : n->missing_ok = false;
9014 194 : n->concurrent = false;
9015 194 : $$ = (Node *) n;
9016 : }
9017 : | DROP OPERATOR IF_P EXISTS operator_with_argtypes_list opt_drop_behavior
9018 : {
9019 30 : DropStmt *n = makeNode(DropStmt);
9020 :
9021 30 : n->removeType = OBJECT_OPERATOR;
9022 30 : n->objects = $5;
9023 30 : n->behavior = $6;
9024 30 : n->missing_ok = true;
9025 30 : n->concurrent = false;
9026 30 : $$ = (Node *) n;
9027 : }
9028 : ;
9029 :
9030 : oper_argtypes:
9031 : '(' Typename ')'
9032 : {
9033 12 : ereport(ERROR,
9034 : (errcode(ERRCODE_SYNTAX_ERROR),
9035 : errmsg("missing argument"),
9036 : errhint("Use NONE to denote the missing argument of a unary operator."),
9037 : parser_errposition(@3)));
9038 : }
9039 : | '(' Typename ',' Typename ')'
9040 1950 : { $$ = list_make2($2, $4); }
9041 : | '(' NONE ',' Typename ')' /* left unary */
9042 32 : { $$ = list_make2(NULL, $4); }
9043 : | '(' Typename ',' NONE ')' /* right unary */
9044 12 : { $$ = list_make2($2, NULL); }
9045 : ;
9046 :
9047 : any_operator:
9048 : all_Op
9049 19712 : { $$ = list_make1(makeString($1)); }
9050 : | ColId '.' any_operator
9051 14806 : { $$ = lcons(makeString($1), $3); }
9052 : ;
9053 :
9054 : operator_with_argtypes_list:
9055 224 : operator_with_argtypes { $$ = list_make1($1); }
9056 : | operator_with_argtypes_list ',' operator_with_argtypes
9057 0 : { $$ = lappend($1, $3); }
9058 : ;
9059 :
9060 : operator_with_argtypes:
9061 : any_operator oper_argtypes
9062 : {
9063 1994 : ObjectWithArgs *n = makeNode(ObjectWithArgs);
9064 :
9065 1994 : n->objname = $1;
9066 1994 : n->objargs = $2;
9067 1994 : $$ = n;
9068 : }
9069 : ;
9070 :
9071 : /*****************************************************************************
9072 : *
9073 : * DO <anonymous code block> [ LANGUAGE language ]
9074 : *
9075 : * We use a DefElem list for future extensibility, and to allow flexibility
9076 : * in the clause order.
9077 : *
9078 : *****************************************************************************/
9079 :
9080 : DoStmt: DO dostmt_opt_list
9081 : {
9082 1122 : DoStmt *n = makeNode(DoStmt);
9083 :
9084 1122 : n->args = $2;
9085 1122 : $$ = (Node *) n;
9086 : }
9087 : ;
9088 :
9089 : dostmt_opt_list:
9090 1122 : dostmt_opt_item { $$ = list_make1($1); }
9091 198 : | dostmt_opt_list dostmt_opt_item { $$ = lappend($1, $2); }
9092 : ;
9093 :
9094 : dostmt_opt_item:
9095 : Sconst
9096 : {
9097 1122 : $$ = makeDefElem("as", (Node *) makeString($1), @1);
9098 : }
9099 : | LANGUAGE NonReservedWord_or_Sconst
9100 : {
9101 198 : $$ = makeDefElem("language", (Node *) makeString($2), @1);
9102 : }
9103 : ;
9104 :
9105 : /*****************************************************************************
9106 : *
9107 : * CREATE CAST / DROP CAST
9108 : *
9109 : *****************************************************************************/
9110 :
9111 : CreateCastStmt: CREATE CAST '(' Typename AS Typename ')'
9112 : WITH FUNCTION function_with_argtypes cast_context
9113 : {
9114 102 : CreateCastStmt *n = makeNode(CreateCastStmt);
9115 :
9116 102 : n->sourcetype = $4;
9117 102 : n->targettype = $6;
9118 102 : n->func = $10;
9119 102 : n->context = (CoercionContext) $11;
9120 102 : n->inout = false;
9121 102 : $$ = (Node *) n;
9122 : }
9123 : | CREATE CAST '(' Typename AS Typename ')'
9124 : WITHOUT FUNCTION cast_context
9125 : {
9126 162 : CreateCastStmt *n = makeNode(CreateCastStmt);
9127 :
9128 162 : n->sourcetype = $4;
9129 162 : n->targettype = $6;
9130 162 : n->func = NULL;
9131 162 : n->context = (CoercionContext) $10;
9132 162 : n->inout = false;
9133 162 : $$ = (Node *) n;
9134 : }
9135 : | CREATE CAST '(' Typename AS Typename ')'
9136 : WITH INOUT cast_context
9137 : {
9138 6 : CreateCastStmt *n = makeNode(CreateCastStmt);
9139 :
9140 6 : n->sourcetype = $4;
9141 6 : n->targettype = $6;
9142 6 : n->func = NULL;
9143 6 : n->context = (CoercionContext) $10;
9144 6 : n->inout = true;
9145 6 : $$ = (Node *) n;
9146 : }
9147 : ;
9148 :
9149 30 : cast_context: AS IMPLICIT_P { $$ = COERCION_IMPLICIT; }
9150 58 : | AS ASSIGNMENT { $$ = COERCION_ASSIGNMENT; }
9151 182 : | /*EMPTY*/ { $$ = COERCION_EXPLICIT; }
9152 : ;
9153 :
9154 :
9155 : DropCastStmt: DROP CAST opt_if_exists '(' Typename AS Typename ')' opt_drop_behavior
9156 : {
9157 54 : DropStmt *n = makeNode(DropStmt);
9158 :
9159 54 : n->removeType = OBJECT_CAST;
9160 54 : n->objects = list_make1(list_make2($5, $7));
9161 54 : n->behavior = $9;
9162 54 : n->missing_ok = $3;
9163 54 : n->concurrent = false;
9164 54 : $$ = (Node *) n;
9165 : }
9166 : ;
9167 :
9168 36 : opt_if_exists: IF_P EXISTS { $$ = true; }
9169 32 : | /*EMPTY*/ { $$ = false; }
9170 : ;
9171 :
9172 :
9173 : /*****************************************************************************
9174 : *
9175 : * CREATE TRANSFORM / DROP TRANSFORM
9176 : *
9177 : *****************************************************************************/
9178 :
9179 : CreateTransformStmt: CREATE opt_or_replace TRANSFORM FOR Typename LANGUAGE name '(' transform_element_list ')'
9180 : {
9181 50 : CreateTransformStmt *n = makeNode(CreateTransformStmt);
9182 :
9183 50 : n->replace = $2;
9184 50 : n->type_name = $5;
9185 50 : n->lang = $7;
9186 50 : n->fromsql = linitial($9);
9187 50 : n->tosql = lsecond($9);
9188 50 : $$ = (Node *) n;
9189 : }
9190 : ;
9191 :
9192 : transform_element_list: FROM SQL_P WITH FUNCTION function_with_argtypes ',' TO SQL_P WITH FUNCTION function_with_argtypes
9193 : {
9194 44 : $$ = list_make2($5, $11);
9195 : }
9196 : | TO SQL_P WITH FUNCTION function_with_argtypes ',' FROM SQL_P WITH FUNCTION function_with_argtypes
9197 : {
9198 0 : $$ = list_make2($11, $5);
9199 : }
9200 : | FROM SQL_P WITH FUNCTION function_with_argtypes
9201 : {
9202 4 : $$ = list_make2($5, NULL);
9203 : }
9204 : | TO SQL_P WITH FUNCTION function_with_argtypes
9205 : {
9206 2 : $$ = list_make2(NULL, $5);
9207 : }
9208 : ;
9209 :
9210 :
9211 : DropTransformStmt: DROP TRANSFORM opt_if_exists FOR Typename LANGUAGE name opt_drop_behavior
9212 : {
9213 14 : DropStmt *n = makeNode(DropStmt);
9214 :
9215 14 : n->removeType = OBJECT_TRANSFORM;
9216 14 : n->objects = list_make1(list_make2($5, makeString($7)));
9217 14 : n->behavior = $8;
9218 14 : n->missing_ok = $3;
9219 14 : $$ = (Node *) n;
9220 : }
9221 : ;
9222 :
9223 :
9224 : /*****************************************************************************
9225 : *
9226 : * QUERY:
9227 : *
9228 : * REINDEX [ (options) ] {INDEX | TABLE | SCHEMA} [CONCURRENTLY] <name>
9229 : * REINDEX [ (options) ] {DATABASE | SYSTEM} [CONCURRENTLY] [<name>]
9230 : *****************************************************************************/
9231 :
9232 : ReindexStmt:
9233 : REINDEX opt_reindex_option_list reindex_target_relation opt_concurrently qualified_name
9234 : {
9235 906 : ReindexStmt *n = makeNode(ReindexStmt);
9236 :
9237 906 : n->kind = $3;
9238 906 : n->relation = $5;
9239 906 : n->name = NULL;
9240 906 : n->params = $2;
9241 906 : if ($4)
9242 506 : n->params = lappend(n->params,
9243 506 : makeDefElem("concurrently", NULL, @4));
9244 906 : $$ = (Node *) n;
9245 : }
9246 : | REINDEX opt_reindex_option_list SCHEMA opt_concurrently name
9247 : {
9248 114 : ReindexStmt *n = makeNode(ReindexStmt);
9249 :
9250 114 : n->kind = REINDEX_OBJECT_SCHEMA;
9251 114 : n->relation = NULL;
9252 114 : n->name = $5;
9253 114 : n->params = $2;
9254 114 : if ($4)
9255 40 : n->params = lappend(n->params,
9256 40 : makeDefElem("concurrently", NULL, @4));
9257 114 : $$ = (Node *) n;
9258 : }
9259 : | REINDEX opt_reindex_option_list reindex_target_all opt_concurrently opt_single_name
9260 : {
9261 68 : ReindexStmt *n = makeNode(ReindexStmt);
9262 :
9263 68 : n->kind = $3;
9264 68 : n->relation = NULL;
9265 68 : n->name = $5;
9266 68 : n->params = $2;
9267 68 : if ($4)
9268 10 : n->params = lappend(n->params,
9269 10 : makeDefElem("concurrently", NULL, @4));
9270 68 : $$ = (Node *) n;
9271 : }
9272 : ;
9273 : reindex_target_relation:
9274 394 : INDEX { $$ = REINDEX_OBJECT_INDEX; }
9275 512 : | TABLE { $$ = REINDEX_OBJECT_TABLE; }
9276 : ;
9277 : reindex_target_all:
9278 34 : SYSTEM_P { $$ = REINDEX_OBJECT_SYSTEM; }
9279 34 : | DATABASE { $$ = REINDEX_OBJECT_DATABASE; }
9280 : ;
9281 : opt_reindex_option_list:
9282 156 : '(' utility_option_list ')' { $$ = $2; }
9283 932 : | /* EMPTY */ { $$ = NULL; }
9284 : ;
9285 :
9286 : /*****************************************************************************
9287 : *
9288 : * ALTER TABLESPACE
9289 : *
9290 : *****************************************************************************/
9291 :
9292 : AlterTblSpcStmt:
9293 : ALTER TABLESPACE name SET reloptions
9294 : {
9295 : AlterTableSpaceOptionsStmt *n =
9296 12 : makeNode(AlterTableSpaceOptionsStmt);
9297 :
9298 12 : n->tablespacename = $3;
9299 12 : n->options = $5;
9300 12 : n->isReset = false;
9301 12 : $$ = (Node *) n;
9302 : }
9303 : | ALTER TABLESPACE name RESET reloptions
9304 : {
9305 : AlterTableSpaceOptionsStmt *n =
9306 12 : makeNode(AlterTableSpaceOptionsStmt);
9307 :
9308 12 : n->tablespacename = $3;
9309 12 : n->options = $5;
9310 12 : n->isReset = true;
9311 12 : $$ = (Node *) n;
9312 : }
9313 : ;
9314 :
9315 : /*****************************************************************************
9316 : *
9317 : * ALTER THING name RENAME TO newname
9318 : *
9319 : *****************************************************************************/
9320 :
9321 : RenameStmt: ALTER AGGREGATE aggregate_with_argtypes RENAME TO name
9322 : {
9323 42 : RenameStmt *n = makeNode(RenameStmt);
9324 :
9325 42 : n->renameType = OBJECT_AGGREGATE;
9326 42 : n->object = (Node *) $3;
9327 42 : n->newname = $6;
9328 42 : n->missing_ok = false;
9329 42 : $$ = (Node *) n;
9330 : }
9331 : | ALTER COLLATION any_name RENAME TO name
9332 : {
9333 18 : RenameStmt *n = makeNode(RenameStmt);
9334 :
9335 18 : n->renameType = OBJECT_COLLATION;
9336 18 : n->object = (Node *) $3;
9337 18 : n->newname = $6;
9338 18 : n->missing_ok = false;
9339 18 : $$ = (Node *) n;
9340 : }
9341 : | ALTER CONVERSION_P any_name RENAME TO name
9342 : {
9343 24 : RenameStmt *n = makeNode(RenameStmt);
9344 :
9345 24 : n->renameType = OBJECT_CONVERSION;
9346 24 : n->object = (Node *) $3;
9347 24 : n->newname = $6;
9348 24 : n->missing_ok = false;
9349 24 : $$ = (Node *) n;
9350 : }
9351 : | ALTER DATABASE name RENAME TO name
9352 : {
9353 6 : RenameStmt *n = makeNode(RenameStmt);
9354 :
9355 6 : n->renameType = OBJECT_DATABASE;
9356 6 : n->subname = $3;
9357 6 : n->newname = $6;
9358 6 : n->missing_ok = false;
9359 6 : $$ = (Node *) n;
9360 : }
9361 : | ALTER DOMAIN_P any_name RENAME TO name
9362 : {
9363 6 : RenameStmt *n = makeNode(RenameStmt);
9364 :
9365 6 : n->renameType = OBJECT_DOMAIN;
9366 6 : n->object = (Node *) $3;
9367 6 : n->newname = $6;
9368 6 : n->missing_ok = false;
9369 6 : $$ = (Node *) n;
9370 : }
9371 : | ALTER DOMAIN_P any_name RENAME CONSTRAINT name TO name
9372 : {
9373 6 : RenameStmt *n = makeNode(RenameStmt);
9374 :
9375 6 : n->renameType = OBJECT_DOMCONSTRAINT;
9376 6 : n->object = (Node *) $3;
9377 6 : n->subname = $6;
9378 6 : n->newname = $8;
9379 6 : $$ = (Node *) n;
9380 : }
9381 : | ALTER FOREIGN DATA_P WRAPPER name RENAME TO name
9382 : {
9383 24 : RenameStmt *n = makeNode(RenameStmt);
9384 :
9385 24 : n->renameType = OBJECT_FDW;
9386 24 : n->object = (Node *) makeString($5);
9387 24 : n->newname = $8;
9388 24 : n->missing_ok = false;
9389 24 : $$ = (Node *) n;
9390 : }
9391 : | ALTER FUNCTION function_with_argtypes RENAME TO name
9392 : {
9393 24 : RenameStmt *n = makeNode(RenameStmt);
9394 :
9395 24 : n->renameType = OBJECT_FUNCTION;
9396 24 : n->object = (Node *) $3;
9397 24 : n->newname = $6;
9398 24 : n->missing_ok = false;
9399 24 : $$ = (Node *) n;
9400 : }
9401 : | ALTER GROUP_P RoleId RENAME TO RoleId
9402 : {
9403 0 : RenameStmt *n = makeNode(RenameStmt);
9404 :
9405 0 : n->renameType = OBJECT_ROLE;
9406 0 : n->subname = $3;
9407 0 : n->newname = $6;
9408 0 : n->missing_ok = false;
9409 0 : $$ = (Node *) n;
9410 : }
9411 : | ALTER opt_procedural LANGUAGE name RENAME TO name
9412 : {
9413 18 : RenameStmt *n = makeNode(RenameStmt);
9414 :
9415 18 : n->renameType = OBJECT_LANGUAGE;
9416 18 : n->object = (Node *) makeString($4);
9417 18 : n->newname = $7;
9418 18 : n->missing_ok = false;
9419 18 : $$ = (Node *) n;
9420 : }
9421 : | ALTER OPERATOR CLASS any_name USING name RENAME TO name
9422 : {
9423 24 : RenameStmt *n = makeNode(RenameStmt);
9424 :
9425 24 : n->renameType = OBJECT_OPCLASS;
9426 24 : n->object = (Node *) lcons(makeString($6), $4);
9427 24 : n->newname = $9;
9428 24 : n->missing_ok = false;
9429 24 : $$ = (Node *) n;
9430 : }
9431 : | ALTER OPERATOR FAMILY any_name USING name RENAME TO name
9432 : {
9433 24 : RenameStmt *n = makeNode(RenameStmt);
9434 :
9435 24 : n->renameType = OBJECT_OPFAMILY;
9436 24 : n->object = (Node *) lcons(makeString($6), $4);
9437 24 : n->newname = $9;
9438 24 : n->missing_ok = false;
9439 24 : $$ = (Node *) n;
9440 : }
9441 : | ALTER POLICY name ON qualified_name RENAME TO name
9442 : {
9443 18 : RenameStmt *n = makeNode(RenameStmt);
9444 :
9445 18 : n->renameType = OBJECT_POLICY;
9446 18 : n->relation = $5;
9447 18 : n->subname = $3;
9448 18 : n->newname = $8;
9449 18 : n->missing_ok = false;
9450 18 : $$ = (Node *) n;
9451 : }
9452 : | ALTER POLICY IF_P EXISTS name ON qualified_name RENAME TO name
9453 : {
9454 0 : RenameStmt *n = makeNode(RenameStmt);
9455 :
9456 0 : n->renameType = OBJECT_POLICY;
9457 0 : n->relation = $7;
9458 0 : n->subname = $5;
9459 0 : n->newname = $10;
9460 0 : n->missing_ok = true;
9461 0 : $$ = (Node *) n;
9462 : }
9463 : | ALTER PROCEDURE function_with_argtypes RENAME TO name
9464 : {
9465 0 : RenameStmt *n = makeNode(RenameStmt);
9466 :
9467 0 : n->renameType = OBJECT_PROCEDURE;
9468 0 : n->object = (Node *) $3;
9469 0 : n->newname = $6;
9470 0 : n->missing_ok = false;
9471 0 : $$ = (Node *) n;
9472 : }
9473 : | ALTER PUBLICATION name RENAME TO name
9474 : {
9475 18 : RenameStmt *n = makeNode(RenameStmt);
9476 :
9477 18 : n->renameType = OBJECT_PUBLICATION;
9478 18 : n->object = (Node *) makeString($3);
9479 18 : n->newname = $6;
9480 18 : n->missing_ok = false;
9481 18 : $$ = (Node *) n;
9482 : }
9483 : | ALTER ROUTINE function_with_argtypes RENAME TO name
9484 : {
9485 24 : RenameStmt *n = makeNode(RenameStmt);
9486 :
9487 24 : n->renameType = OBJECT_ROUTINE;
9488 24 : n->object = (Node *) $3;
9489 24 : n->newname = $6;
9490 24 : n->missing_ok = false;
9491 24 : $$ = (Node *) n;
9492 : }
9493 : | ALTER SCHEMA name RENAME TO name
9494 : {
9495 20 : RenameStmt *n = makeNode(RenameStmt);
9496 :
9497 20 : n->renameType = OBJECT_SCHEMA;
9498 20 : n->subname = $3;
9499 20 : n->newname = $6;
9500 20 : n->missing_ok = false;
9501 20 : $$ = (Node *) n;
9502 : }
9503 : | ALTER SERVER name RENAME TO name
9504 : {
9505 24 : RenameStmt *n = makeNode(RenameStmt);
9506 :
9507 24 : n->renameType = OBJECT_FOREIGN_SERVER;
9508 24 : n->object = (Node *) makeString($3);
9509 24 : n->newname = $6;
9510 24 : n->missing_ok = false;
9511 24 : $$ = (Node *) n;
9512 : }
9513 : | ALTER SUBSCRIPTION name RENAME TO name
9514 : {
9515 38 : RenameStmt *n = makeNode(RenameStmt);
9516 :
9517 38 : n->renameType = OBJECT_SUBSCRIPTION;
9518 38 : n->object = (Node *) makeString($3);
9519 38 : n->newname = $6;
9520 38 : n->missing_ok = false;
9521 38 : $$ = (Node *) n;
9522 : }
9523 : | ALTER TABLE relation_expr RENAME TO name
9524 : {
9525 286 : RenameStmt *n = makeNode(RenameStmt);
9526 :
9527 286 : n->renameType = OBJECT_TABLE;
9528 286 : n->relation = $3;
9529 286 : n->subname = NULL;
9530 286 : n->newname = $6;
9531 286 : n->missing_ok = false;
9532 286 : $$ = (Node *) n;
9533 : }
9534 : | ALTER TABLE IF_P EXISTS relation_expr RENAME TO name
9535 : {
9536 0 : RenameStmt *n = makeNode(RenameStmt);
9537 :
9538 0 : n->renameType = OBJECT_TABLE;
9539 0 : n->relation = $5;
9540 0 : n->subname = NULL;
9541 0 : n->newname = $8;
9542 0 : n->missing_ok = true;
9543 0 : $$ = (Node *) n;
9544 : }
9545 : | ALTER SEQUENCE qualified_name RENAME TO name
9546 : {
9547 2 : RenameStmt *n = makeNode(RenameStmt);
9548 :
9549 2 : n->renameType = OBJECT_SEQUENCE;
9550 2 : n->relation = $3;
9551 2 : n->subname = NULL;
9552 2 : n->newname = $6;
9553 2 : n->missing_ok = false;
9554 2 : $$ = (Node *) n;
9555 : }
9556 : | ALTER SEQUENCE IF_P EXISTS qualified_name RENAME TO name
9557 : {
9558 0 : RenameStmt *n = makeNode(RenameStmt);
9559 :
9560 0 : n->renameType = OBJECT_SEQUENCE;
9561 0 : n->relation = $5;
9562 0 : n->subname = NULL;
9563 0 : n->newname = $8;
9564 0 : n->missing_ok = true;
9565 0 : $$ = (Node *) n;
9566 : }
9567 : | ALTER VIEW qualified_name RENAME TO name
9568 : {
9569 6 : RenameStmt *n = makeNode(RenameStmt);
9570 :
9571 6 : n->renameType = OBJECT_VIEW;
9572 6 : n->relation = $3;
9573 6 : n->subname = NULL;
9574 6 : n->newname = $6;
9575 6 : n->missing_ok = false;
9576 6 : $$ = (Node *) n;
9577 : }
9578 : | ALTER VIEW IF_P EXISTS qualified_name RENAME TO name
9579 : {
9580 0 : RenameStmt *n = makeNode(RenameStmt);
9581 :
9582 0 : n->renameType = OBJECT_VIEW;
9583 0 : n->relation = $5;
9584 0 : n->subname = NULL;
9585 0 : n->newname = $8;
9586 0 : n->missing_ok = true;
9587 0 : $$ = (Node *) n;
9588 : }
9589 : | ALTER MATERIALIZED VIEW qualified_name RENAME TO name
9590 : {
9591 0 : RenameStmt *n = makeNode(RenameStmt);
9592 :
9593 0 : n->renameType = OBJECT_MATVIEW;
9594 0 : n->relation = $4;
9595 0 : n->subname = NULL;
9596 0 : n->newname = $7;
9597 0 : n->missing_ok = false;
9598 0 : $$ = (Node *) n;
9599 : }
9600 : | ALTER MATERIALIZED VIEW IF_P EXISTS qualified_name RENAME TO name
9601 : {
9602 0 : RenameStmt *n = makeNode(RenameStmt);
9603 :
9604 0 : n->renameType = OBJECT_MATVIEW;
9605 0 : n->relation = $6;
9606 0 : n->subname = NULL;
9607 0 : n->newname = $9;
9608 0 : n->missing_ok = true;
9609 0 : $$ = (Node *) n;
9610 : }
9611 : | ALTER INDEX qualified_name RENAME TO name
9612 : {
9613 192 : RenameStmt *n = makeNode(RenameStmt);
9614 :
9615 192 : n->renameType = OBJECT_INDEX;
9616 192 : n->relation = $3;
9617 192 : n->subname = NULL;
9618 192 : n->newname = $6;
9619 192 : n->missing_ok = false;
9620 192 : $$ = (Node *) n;
9621 : }
9622 : | ALTER INDEX IF_P EXISTS qualified_name RENAME TO name
9623 : {
9624 12 : RenameStmt *n = makeNode(RenameStmt);
9625 :
9626 12 : n->renameType = OBJECT_INDEX;
9627 12 : n->relation = $5;
9628 12 : n->subname = NULL;
9629 12 : n->newname = $8;
9630 12 : n->missing_ok = true;
9631 12 : $$ = (Node *) n;
9632 : }
9633 : | ALTER FOREIGN TABLE relation_expr RENAME TO name
9634 : {
9635 6 : RenameStmt *n = makeNode(RenameStmt);
9636 :
9637 6 : n->renameType = OBJECT_FOREIGN_TABLE;
9638 6 : n->relation = $4;
9639 6 : n->subname = NULL;
9640 6 : n->newname = $7;
9641 6 : n->missing_ok = false;
9642 6 : $$ = (Node *) n;
9643 : }
9644 : | ALTER FOREIGN TABLE IF_P EXISTS relation_expr RENAME TO name
9645 : {
9646 6 : RenameStmt *n = makeNode(RenameStmt);
9647 :
9648 6 : n->renameType = OBJECT_FOREIGN_TABLE;
9649 6 : n->relation = $6;
9650 6 : n->subname = NULL;
9651 6 : n->newname = $9;
9652 6 : n->missing_ok = true;
9653 6 : $$ = (Node *) n;
9654 : }
9655 : | ALTER TABLE relation_expr RENAME opt_column name TO name
9656 : {
9657 238 : RenameStmt *n = makeNode(RenameStmt);
9658 :
9659 238 : n->renameType = OBJECT_COLUMN;
9660 238 : n->relationType = OBJECT_TABLE;
9661 238 : n->relation = $3;
9662 238 : n->subname = $6;
9663 238 : n->newname = $8;
9664 238 : n->missing_ok = false;
9665 238 : $$ = (Node *) n;
9666 : }
9667 : | ALTER TABLE IF_P EXISTS relation_expr RENAME opt_column name TO name
9668 : {
9669 24 : RenameStmt *n = makeNode(RenameStmt);
9670 :
9671 24 : n->renameType = OBJECT_COLUMN;
9672 24 : n->relationType = OBJECT_TABLE;
9673 24 : n->relation = $5;
9674 24 : n->subname = $8;
9675 24 : n->newname = $10;
9676 24 : n->missing_ok = true;
9677 24 : $$ = (Node *) n;
9678 : }
9679 : | ALTER VIEW qualified_name RENAME opt_column name TO name
9680 : {
9681 18 : RenameStmt *n = makeNode(RenameStmt);
9682 :
9683 18 : n->renameType = OBJECT_COLUMN;
9684 18 : n->relationType = OBJECT_VIEW;
9685 18 : n->relation = $3;
9686 18 : n->subname = $6;
9687 18 : n->newname = $8;
9688 18 : n->missing_ok = false;
9689 18 : $$ = (Node *) n;
9690 : }
9691 : | ALTER VIEW IF_P EXISTS qualified_name RENAME opt_column name TO name
9692 : {
9693 0 : RenameStmt *n = makeNode(RenameStmt);
9694 :
9695 0 : n->renameType = OBJECT_COLUMN;
9696 0 : n->relationType = OBJECT_VIEW;
9697 0 : n->relation = $5;
9698 0 : n->subname = $8;
9699 0 : n->newname = $10;
9700 0 : n->missing_ok = true;
9701 0 : $$ = (Node *) n;
9702 : }
9703 : | ALTER MATERIALIZED VIEW qualified_name RENAME opt_column name TO name
9704 : {
9705 0 : RenameStmt *n = makeNode(RenameStmt);
9706 :
9707 0 : n->renameType = OBJECT_COLUMN;
9708 0 : n->relationType = OBJECT_MATVIEW;
9709 0 : n->relation = $4;
9710 0 : n->subname = $7;
9711 0 : n->newname = $9;
9712 0 : n->missing_ok = false;
9713 0 : $$ = (Node *) n;
9714 : }
9715 : | ALTER MATERIALIZED VIEW IF_P EXISTS qualified_name RENAME opt_column name TO name
9716 : {
9717 0 : RenameStmt *n = makeNode(RenameStmt);
9718 :
9719 0 : n->renameType = OBJECT_COLUMN;
9720 0 : n->relationType = OBJECT_MATVIEW;
9721 0 : n->relation = $6;
9722 0 : n->subname = $9;
9723 0 : n->newname = $11;
9724 0 : n->missing_ok = true;
9725 0 : $$ = (Node *) n;
9726 : }
9727 : | ALTER TABLE relation_expr RENAME CONSTRAINT name TO name
9728 : {
9729 72 : RenameStmt *n = makeNode(RenameStmt);
9730 :
9731 72 : n->renameType = OBJECT_TABCONSTRAINT;
9732 72 : n->relation = $3;
9733 72 : n->subname = $6;
9734 72 : n->newname = $8;
9735 72 : n->missing_ok = false;
9736 72 : $$ = (Node *) n;
9737 : }
9738 : | ALTER TABLE IF_P EXISTS relation_expr RENAME CONSTRAINT name TO name
9739 : {
9740 6 : RenameStmt *n = makeNode(RenameStmt);
9741 :
9742 6 : n->renameType = OBJECT_TABCONSTRAINT;
9743 6 : n->relation = $5;
9744 6 : n->subname = $8;
9745 6 : n->newname = $10;
9746 6 : n->missing_ok = true;
9747 6 : $$ = (Node *) n;
9748 : }
9749 : | ALTER FOREIGN TABLE relation_expr RENAME opt_column name TO name
9750 : {
9751 6 : RenameStmt *n = makeNode(RenameStmt);
9752 :
9753 6 : n->renameType = OBJECT_COLUMN;
9754 6 : n->relationType = OBJECT_FOREIGN_TABLE;
9755 6 : n->relation = $4;
9756 6 : n->subname = $7;
9757 6 : n->newname = $9;
9758 6 : n->missing_ok = false;
9759 6 : $$ = (Node *) n;
9760 : }
9761 : | ALTER FOREIGN TABLE IF_P EXISTS relation_expr RENAME opt_column name TO name
9762 : {
9763 6 : RenameStmt *n = makeNode(RenameStmt);
9764 :
9765 6 : n->renameType = OBJECT_COLUMN;
9766 6 : n->relationType = OBJECT_FOREIGN_TABLE;
9767 6 : n->relation = $6;
9768 6 : n->subname = $9;
9769 6 : n->newname = $11;
9770 6 : n->missing_ok = true;
9771 6 : $$ = (Node *) n;
9772 : }
9773 : | ALTER RULE name ON qualified_name RENAME TO name
9774 : {
9775 34 : RenameStmt *n = makeNode(RenameStmt);
9776 :
9777 34 : n->renameType = OBJECT_RULE;
9778 34 : n->relation = $5;
9779 34 : n->subname = $3;
9780 34 : n->newname = $8;
9781 34 : n->missing_ok = false;
9782 34 : $$ = (Node *) n;
9783 : }
9784 : | ALTER TRIGGER name ON qualified_name RENAME TO name
9785 : {
9786 40 : RenameStmt *n = makeNode(RenameStmt);
9787 :
9788 40 : n->renameType = OBJECT_TRIGGER;
9789 40 : n->relation = $5;
9790 40 : n->subname = $3;
9791 40 : n->newname = $8;
9792 40 : n->missing_ok = false;
9793 40 : $$ = (Node *) n;
9794 : }
9795 : | ALTER EVENT TRIGGER name RENAME TO name
9796 : {
9797 12 : RenameStmt *n = makeNode(RenameStmt);
9798 :
9799 12 : n->renameType = OBJECT_EVENT_TRIGGER;
9800 12 : n->object = (Node *) makeString($4);
9801 12 : n->newname = $7;
9802 12 : $$ = (Node *) n;
9803 : }
9804 : | ALTER ROLE RoleId RENAME TO RoleId
9805 : {
9806 30 : RenameStmt *n = makeNode(RenameStmt);
9807 :
9808 30 : n->renameType = OBJECT_ROLE;
9809 30 : n->subname = $3;
9810 30 : n->newname = $6;
9811 30 : n->missing_ok = false;
9812 30 : $$ = (Node *) n;
9813 : }
9814 : | ALTER USER RoleId RENAME TO RoleId
9815 : {
9816 0 : RenameStmt *n = makeNode(RenameStmt);
9817 :
9818 0 : n->renameType = OBJECT_ROLE;
9819 0 : n->subname = $3;
9820 0 : n->newname = $6;
9821 0 : n->missing_ok = false;
9822 0 : $$ = (Node *) n;
9823 : }
9824 : | ALTER TABLESPACE name RENAME TO name
9825 : {
9826 6 : RenameStmt *n = makeNode(RenameStmt);
9827 :
9828 6 : n->renameType = OBJECT_TABLESPACE;
9829 6 : n->subname = $3;
9830 6 : n->newname = $6;
9831 6 : n->missing_ok = false;
9832 6 : $$ = (Node *) n;
9833 : }
9834 : | ALTER STATISTICS any_name RENAME TO name
9835 : {
9836 30 : RenameStmt *n = makeNode(RenameStmt);
9837 :
9838 30 : n->renameType = OBJECT_STATISTIC_EXT;
9839 30 : n->object = (Node *) $3;
9840 30 : n->newname = $6;
9841 30 : n->missing_ok = false;
9842 30 : $$ = (Node *) n;
9843 : }
9844 : | ALTER TEXT_P SEARCH PARSER any_name RENAME TO name
9845 : {
9846 12 : RenameStmt *n = makeNode(RenameStmt);
9847 :
9848 12 : n->renameType = OBJECT_TSPARSER;
9849 12 : n->object = (Node *) $5;
9850 12 : n->newname = $8;
9851 12 : n->missing_ok = false;
9852 12 : $$ = (Node *) n;
9853 : }
9854 : | ALTER TEXT_P SEARCH DICTIONARY any_name RENAME TO name
9855 : {
9856 24 : RenameStmt *n = makeNode(RenameStmt);
9857 :
9858 24 : n->renameType = OBJECT_TSDICTIONARY;
9859 24 : n->object = (Node *) $5;
9860 24 : n->newname = $8;
9861 24 : n->missing_ok = false;
9862 24 : $$ = (Node *) n;
9863 : }
9864 : | ALTER TEXT_P SEARCH TEMPLATE any_name RENAME TO name
9865 : {
9866 12 : RenameStmt *n = makeNode(RenameStmt);
9867 :
9868 12 : n->renameType = OBJECT_TSTEMPLATE;
9869 12 : n->object = (Node *) $5;
9870 12 : n->newname = $8;
9871 12 : n->missing_ok = false;
9872 12 : $$ = (Node *) n;
9873 : }
9874 : | ALTER TEXT_P SEARCH CONFIGURATION any_name RENAME TO name
9875 : {
9876 24 : RenameStmt *n = makeNode(RenameStmt);
9877 :
9878 24 : n->renameType = OBJECT_TSCONFIGURATION;
9879 24 : n->object = (Node *) $5;
9880 24 : n->newname = $8;
9881 24 : n->missing_ok = false;
9882 24 : $$ = (Node *) n;
9883 : }
9884 : | ALTER TYPE_P any_name RENAME TO name
9885 : {
9886 26 : RenameStmt *n = makeNode(RenameStmt);
9887 :
9888 26 : n->renameType = OBJECT_TYPE;
9889 26 : n->object = (Node *) $3;
9890 26 : n->newname = $6;
9891 26 : n->missing_ok = false;
9892 26 : $$ = (Node *) n;
9893 : }
9894 : | ALTER TYPE_P any_name RENAME ATTRIBUTE name TO name opt_drop_behavior
9895 : {
9896 24 : RenameStmt *n = makeNode(RenameStmt);
9897 :
9898 24 : n->renameType = OBJECT_ATTRIBUTE;
9899 24 : n->relationType = OBJECT_TYPE;
9900 24 : n->relation = makeRangeVarFromAnyName($3, @3, yyscanner);
9901 24 : n->subname = $6;
9902 24 : n->newname = $8;
9903 24 : n->behavior = $9;
9904 24 : n->missing_ok = false;
9905 24 : $$ = (Node *) n;
9906 : }
9907 : ;
9908 :
9909 : opt_column: COLUMN
9910 : | /*EMPTY*/
9911 : ;
9912 :
9913 154 : opt_set_data: SET DATA_P { $$ = 1; }
9914 776 : | /*EMPTY*/ { $$ = 0; }
9915 : ;
9916 :
9917 : /*****************************************************************************
9918 : *
9919 : * ALTER THING name DEPENDS ON EXTENSION name
9920 : *
9921 : *****************************************************************************/
9922 :
9923 : AlterObjectDependsStmt:
9924 : ALTER FUNCTION function_with_argtypes opt_no DEPENDS ON EXTENSION name
9925 : {
9926 12 : AlterObjectDependsStmt *n = makeNode(AlterObjectDependsStmt);
9927 :
9928 12 : n->objectType = OBJECT_FUNCTION;
9929 12 : n->object = (Node *) $3;
9930 12 : n->extname = makeString($8);
9931 12 : n->remove = $4;
9932 12 : $$ = (Node *) n;
9933 : }
9934 : | ALTER PROCEDURE function_with_argtypes opt_no DEPENDS ON EXTENSION name
9935 : {
9936 0 : AlterObjectDependsStmt *n = makeNode(AlterObjectDependsStmt);
9937 :
9938 0 : n->objectType = OBJECT_PROCEDURE;
9939 0 : n->object = (Node *) $3;
9940 0 : n->extname = makeString($8);
9941 0 : n->remove = $4;
9942 0 : $$ = (Node *) n;
9943 : }
9944 : | ALTER ROUTINE function_with_argtypes opt_no DEPENDS ON EXTENSION name
9945 : {
9946 0 : AlterObjectDependsStmt *n = makeNode(AlterObjectDependsStmt);
9947 :
9948 0 : n->objectType = OBJECT_ROUTINE;
9949 0 : n->object = (Node *) $3;
9950 0 : n->extname = makeString($8);
9951 0 : n->remove = $4;
9952 0 : $$ = (Node *) n;
9953 : }
9954 : | ALTER TRIGGER name ON qualified_name opt_no DEPENDS ON EXTENSION name
9955 : {
9956 10 : AlterObjectDependsStmt *n = makeNode(AlterObjectDependsStmt);
9957 :
9958 10 : n->objectType = OBJECT_TRIGGER;
9959 10 : n->relation = $5;
9960 10 : n->object = (Node *) list_make1(makeString($3));
9961 10 : n->extname = makeString($10);
9962 10 : n->remove = $6;
9963 10 : $$ = (Node *) n;
9964 : }
9965 : | ALTER MATERIALIZED VIEW qualified_name opt_no DEPENDS ON EXTENSION name
9966 : {
9967 10 : AlterObjectDependsStmt *n = makeNode(AlterObjectDependsStmt);
9968 :
9969 10 : n->objectType = OBJECT_MATVIEW;
9970 10 : n->relation = $4;
9971 10 : n->extname = makeString($9);
9972 10 : n->remove = $5;
9973 10 : $$ = (Node *) n;
9974 : }
9975 : | ALTER INDEX qualified_name opt_no DEPENDS ON EXTENSION name
9976 : {
9977 14 : AlterObjectDependsStmt *n = makeNode(AlterObjectDependsStmt);
9978 :
9979 14 : n->objectType = OBJECT_INDEX;
9980 14 : n->relation = $3;
9981 14 : n->extname = makeString($8);
9982 14 : n->remove = $4;
9983 14 : $$ = (Node *) n;
9984 : }
9985 : ;
9986 :
9987 8 : opt_no: NO { $$ = true; }
9988 38 : | /* EMPTY */ { $$ = false; }
9989 : ;
9990 :
9991 : /*****************************************************************************
9992 : *
9993 : * ALTER THING name SET SCHEMA name
9994 : *
9995 : *****************************************************************************/
9996 :
9997 : AlterObjectSchemaStmt:
9998 : ALTER AGGREGATE aggregate_with_argtypes SET SCHEMA name
9999 : {
10000 24 : AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
10001 :
10002 24 : n->objectType = OBJECT_AGGREGATE;
10003 24 : n->object = (Node *) $3;
10004 24 : n->newschema = $6;
10005 24 : n->missing_ok = false;
10006 24 : $$ = (Node *) n;
10007 : }
10008 : | ALTER COLLATION any_name SET SCHEMA name
10009 : {
10010 6 : AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
10011 :
10012 6 : n->objectType = OBJECT_COLLATION;
10013 6 : n->object = (Node *) $3;
10014 6 : n->newschema = $6;
10015 6 : n->missing_ok = false;
10016 6 : $$ = (Node *) n;
10017 : }
10018 : | ALTER CONVERSION_P any_name SET SCHEMA name
10019 : {
10020 24 : AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
10021 :
10022 24 : n->objectType = OBJECT_CONVERSION;
10023 24 : n->object = (Node *) $3;
10024 24 : n->newschema = $6;
10025 24 : n->missing_ok = false;
10026 24 : $$ = (Node *) n;
10027 : }
10028 : | ALTER DOMAIN_P any_name SET SCHEMA name
10029 : {
10030 6 : AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
10031 :
10032 6 : n->objectType = OBJECT_DOMAIN;
10033 6 : n->object = (Node *) $3;
10034 6 : n->newschema = $6;
10035 6 : n->missing_ok = false;
10036 6 : $$ = (Node *) n;
10037 : }
10038 : | ALTER EXTENSION name SET SCHEMA name
10039 : {
10040 12 : AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
10041 :
10042 12 : n->objectType = OBJECT_EXTENSION;
10043 12 : n->object = (Node *) makeString($3);
10044 12 : n->newschema = $6;
10045 12 : n->missing_ok = false;
10046 12 : $$ = (Node *) n;
10047 : }
10048 : | ALTER FUNCTION function_with_argtypes SET SCHEMA name
10049 : {
10050 42 : AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
10051 :
10052 42 : n->objectType = OBJECT_FUNCTION;
10053 42 : n->object = (Node *) $3;
10054 42 : n->newschema = $6;
10055 42 : n->missing_ok = false;
10056 42 : $$ = (Node *) n;
10057 : }
10058 : | ALTER OPERATOR operator_with_argtypes SET SCHEMA name
10059 : {
10060 18 : AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
10061 :
10062 18 : n->objectType = OBJECT_OPERATOR;
10063 18 : n->object = (Node *) $3;
10064 18 : n->newschema = $6;
10065 18 : n->missing_ok = false;
10066 18 : $$ = (Node *) n;
10067 : }
10068 : | ALTER OPERATOR CLASS any_name USING name SET SCHEMA name
10069 : {
10070 24 : AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
10071 :
10072 24 : n->objectType = OBJECT_OPCLASS;
10073 24 : n->object = (Node *) lcons(makeString($6), $4);
10074 24 : n->newschema = $9;
10075 24 : n->missing_ok = false;
10076 24 : $$ = (Node *) n;
10077 : }
10078 : | ALTER OPERATOR FAMILY any_name USING name SET SCHEMA name
10079 : {
10080 24 : AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
10081 :
10082 24 : n->objectType = OBJECT_OPFAMILY;
10083 24 : n->object = (Node *) lcons(makeString($6), $4);
10084 24 : n->newschema = $9;
10085 24 : n->missing_ok = false;
10086 24 : $$ = (Node *) n;
10087 : }
10088 : | ALTER PROCEDURE function_with_argtypes SET SCHEMA name
10089 : {
10090 0 : AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
10091 :
10092 0 : n->objectType = OBJECT_PROCEDURE;
10093 0 : n->object = (Node *) $3;
10094 0 : n->newschema = $6;
10095 0 : n->missing_ok = false;
10096 0 : $$ = (Node *) n;
10097 : }
10098 : | ALTER ROUTINE function_with_argtypes SET SCHEMA name
10099 : {
10100 0 : AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
10101 :
10102 0 : n->objectType = OBJECT_ROUTINE;
10103 0 : n->object = (Node *) $3;
10104 0 : n->newschema = $6;
10105 0 : n->missing_ok = false;
10106 0 : $$ = (Node *) n;
10107 : }
10108 : | ALTER TABLE relation_expr SET SCHEMA name
10109 : {
10110 66 : AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
10111 :
10112 66 : n->objectType = OBJECT_TABLE;
10113 66 : n->relation = $3;
10114 66 : n->newschema = $6;
10115 66 : n->missing_ok = false;
10116 66 : $$ = (Node *) n;
10117 : }
10118 : | ALTER TABLE IF_P EXISTS relation_expr SET SCHEMA name
10119 : {
10120 12 : AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
10121 :
10122 12 : n->objectType = OBJECT_TABLE;
10123 12 : n->relation = $5;
10124 12 : n->newschema = $8;
10125 12 : n->missing_ok = true;
10126 12 : $$ = (Node *) n;
10127 : }
10128 : | ALTER STATISTICS any_name SET SCHEMA name
10129 : {
10130 18 : AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
10131 :
10132 18 : n->objectType = OBJECT_STATISTIC_EXT;
10133 18 : n->object = (Node *) $3;
10134 18 : n->newschema = $6;
10135 18 : n->missing_ok = false;
10136 18 : $$ = (Node *) n;
10137 : }
10138 : | ALTER TEXT_P SEARCH PARSER any_name SET SCHEMA name
10139 : {
10140 18 : AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
10141 :
10142 18 : n->objectType = OBJECT_TSPARSER;
10143 18 : n->object = (Node *) $5;
10144 18 : n->newschema = $8;
10145 18 : n->missing_ok = false;
10146 18 : $$ = (Node *) n;
10147 : }
10148 : | ALTER TEXT_P SEARCH DICTIONARY any_name SET SCHEMA name
10149 : {
10150 24 : AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
10151 :
10152 24 : n->objectType = OBJECT_TSDICTIONARY;
10153 24 : n->object = (Node *) $5;
10154 24 : n->newschema = $8;
10155 24 : n->missing_ok = false;
10156 24 : $$ = (Node *) n;
10157 : }
10158 : | ALTER TEXT_P SEARCH TEMPLATE any_name SET SCHEMA name
10159 : {
10160 18 : AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
10161 :
10162 18 : n->objectType = OBJECT_TSTEMPLATE;
10163 18 : n->object = (Node *) $5;
10164 18 : n->newschema = $8;
10165 18 : n->missing_ok = false;
10166 18 : $$ = (Node *) n;
10167 : }
10168 : | ALTER TEXT_P SEARCH CONFIGURATION any_name SET SCHEMA name
10169 : {
10170 24 : AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
10171 :
10172 24 : n->objectType = OBJECT_TSCONFIGURATION;
10173 24 : n->object = (Node *) $5;
10174 24 : n->newschema = $8;
10175 24 : n->missing_ok = false;
10176 24 : $$ = (Node *) n;
10177 : }
10178 : | ALTER SEQUENCE qualified_name SET SCHEMA name
10179 : {
10180 8 : AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
10181 :
10182 8 : n->objectType = OBJECT_SEQUENCE;
10183 8 : n->relation = $3;
10184 8 : n->newschema = $6;
10185 8 : n->missing_ok = false;
10186 8 : $$ = (Node *) n;
10187 : }
10188 : | ALTER SEQUENCE IF_P EXISTS qualified_name SET SCHEMA name
10189 : {
10190 0 : AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
10191 :
10192 0 : n->objectType = OBJECT_SEQUENCE;
10193 0 : n->relation = $5;
10194 0 : n->newschema = $8;
10195 0 : n->missing_ok = true;
10196 0 : $$ = (Node *) n;
10197 : }
10198 : | ALTER VIEW qualified_name SET SCHEMA name
10199 : {
10200 0 : AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
10201 :
10202 0 : n->objectType = OBJECT_VIEW;
10203 0 : n->relation = $3;
10204 0 : n->newschema = $6;
10205 0 : n->missing_ok = false;
10206 0 : $$ = (Node *) n;
10207 : }
10208 : | ALTER VIEW IF_P EXISTS qualified_name SET SCHEMA name
10209 : {
10210 0 : AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
10211 :
10212 0 : n->objectType = OBJECT_VIEW;
10213 0 : n->relation = $5;
10214 0 : n->newschema = $8;
10215 0 : n->missing_ok = true;
10216 0 : $$ = (Node *) n;
10217 : }
10218 : | ALTER MATERIALIZED VIEW qualified_name SET SCHEMA name
10219 : {
10220 6 : AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
10221 :
10222 6 : n->objectType = OBJECT_MATVIEW;
10223 6 : n->relation = $4;
10224 6 : n->newschema = $7;
10225 6 : n->missing_ok = false;
10226 6 : $$ = (Node *) n;
10227 : }
10228 : | ALTER MATERIALIZED VIEW IF_P EXISTS qualified_name SET SCHEMA name
10229 : {
10230 0 : AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
10231 :
10232 0 : n->objectType = OBJECT_MATVIEW;
10233 0 : n->relation = $6;
10234 0 : n->newschema = $9;
10235 0 : n->missing_ok = true;
10236 0 : $$ = (Node *) n;
10237 : }
10238 : | ALTER FOREIGN TABLE relation_expr SET SCHEMA name
10239 : {
10240 6 : AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
10241 :
10242 6 : n->objectType = OBJECT_FOREIGN_TABLE;
10243 6 : n->relation = $4;
10244 6 : n->newschema = $7;
10245 6 : n->missing_ok = false;
10246 6 : $$ = (Node *) n;
10247 : }
10248 : | ALTER FOREIGN TABLE IF_P EXISTS relation_expr SET SCHEMA name
10249 : {
10250 6 : AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
10251 :
10252 6 : n->objectType = OBJECT_FOREIGN_TABLE;
10253 6 : n->relation = $6;
10254 6 : n->newschema = $9;
10255 6 : n->missing_ok = true;
10256 6 : $$ = (Node *) n;
10257 : }
10258 : | ALTER TYPE_P any_name SET SCHEMA name
10259 : {
10260 12 : AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
10261 :
10262 12 : n->objectType = OBJECT_TYPE;
10263 12 : n->object = (Node *) $3;
10264 12 : n->newschema = $6;
10265 12 : n->missing_ok = false;
10266 12 : $$ = (Node *) n;
10267 : }
10268 : ;
10269 :
10270 : /*****************************************************************************
10271 : *
10272 : * ALTER OPERATOR name SET define
10273 : *
10274 : *****************************************************************************/
10275 :
10276 : AlterOperatorStmt:
10277 : ALTER OPERATOR operator_with_argtypes SET '(' operator_def_list ')'
10278 : {
10279 608 : AlterOperatorStmt *n = makeNode(AlterOperatorStmt);
10280 :
10281 608 : n->opername = $3;
10282 608 : n->options = $6;
10283 608 : $$ = (Node *) n;
10284 : }
10285 : ;
10286 :
10287 668 : operator_def_list: operator_def_elem { $$ = list_make1($1); }
10288 506 : | operator_def_list ',' operator_def_elem { $$ = lappend($1, $3); }
10289 : ;
10290 :
10291 : operator_def_elem: ColLabel '=' NONE
10292 30 : { $$ = makeDefElem($1, NULL, @1); }
10293 : | ColLabel '=' operator_def_arg
10294 1110 : { $$ = makeDefElem($1, (Node *) $3, @1); }
10295 : | ColLabel
10296 34 : { $$ = makeDefElem($1, NULL, @1); }
10297 : ;
10298 :
10299 : /* must be similar enough to def_arg to avoid reduce/reduce conflicts */
10300 : operator_def_arg:
10301 1032 : func_type { $$ = (Node *) $1; }
10302 24 : | reserved_keyword { $$ = (Node *) makeString(pstrdup($1)); }
10303 54 : | qual_all_Op { $$ = (Node *) $1; }
10304 0 : | NumericOnly { $$ = (Node *) $1; }
10305 0 : | Sconst { $$ = (Node *) makeString($1); }
10306 : ;
10307 :
10308 : /*****************************************************************************
10309 : *
10310 : * ALTER TYPE name SET define
10311 : *
10312 : * We repurpose ALTER OPERATOR's version of "definition" here
10313 : *
10314 : *****************************************************************************/
10315 :
10316 : AlterTypeStmt:
10317 : ALTER TYPE_P any_name SET '(' operator_def_list ')'
10318 : {
10319 60 : AlterTypeStmt *n = makeNode(AlterTypeStmt);
10320 :
10321 60 : n->typeName = $3;
10322 60 : n->options = $6;
10323 60 : $$ = (Node *) n;
10324 : }
10325 : ;
10326 :
10327 : /*****************************************************************************
10328 : *
10329 : * ALTER THING name OWNER TO newname
10330 : *
10331 : *****************************************************************************/
10332 :
10333 : AlterOwnerStmt: ALTER AGGREGATE aggregate_with_argtypes OWNER TO RoleSpec
10334 : {
10335 142 : AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
10336 :
10337 142 : n->objectType = OBJECT_AGGREGATE;
10338 142 : n->object = (Node *) $3;
10339 142 : n->newowner = $6;
10340 142 : $$ = (Node *) n;
10341 : }
10342 : | ALTER COLLATION any_name OWNER TO RoleSpec
10343 : {
10344 16 : AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
10345 :
10346 16 : n->objectType = OBJECT_COLLATION;
10347 16 : n->object = (Node *) $3;
10348 16 : n->newowner = $6;
10349 16 : $$ = (Node *) n;
10350 : }
10351 : | ALTER CONVERSION_P any_name OWNER TO RoleSpec
10352 : {
10353 24 : AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
10354 :
10355 24 : n->objectType = OBJECT_CONVERSION;
10356 24 : n->object = (Node *) $3;
10357 24 : n->newowner = $6;
10358 24 : $$ = (Node *) n;
10359 : }
10360 : | ALTER DATABASE name OWNER TO RoleSpec
10361 : {
10362 44 : AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
10363 :
10364 44 : n->objectType = OBJECT_DATABASE;
10365 44 : n->object = (Node *) makeString($3);
10366 44 : n->newowner = $6;
10367 44 : $$ = (Node *) n;
10368 : }
10369 : | ALTER DOMAIN_P any_name OWNER TO RoleSpec
10370 : {
10371 40 : AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
10372 :
10373 40 : n->objectType = OBJECT_DOMAIN;
10374 40 : n->object = (Node *) $3;
10375 40 : n->newowner = $6;
10376 40 : $$ = (Node *) n;
10377 : }
10378 : | ALTER FUNCTION function_with_argtypes OWNER TO RoleSpec
10379 : {
10380 574 : AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
10381 :
10382 574 : n->objectType = OBJECT_FUNCTION;
10383 574 : n->object = (Node *) $3;
10384 574 : n->newowner = $6;
10385 574 : $$ = (Node *) n;
10386 : }
10387 : | ALTER opt_procedural LANGUAGE name OWNER TO RoleSpec
10388 : {
10389 132 : AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
10390 :
10391 132 : n->objectType = OBJECT_LANGUAGE;
10392 132 : n->object = (Node *) makeString($4);
10393 132 : n->newowner = $7;
10394 132 : $$ = (Node *) n;
10395 : }
10396 : | ALTER LARGE_P OBJECT_P NumericOnly OWNER TO RoleSpec
10397 : {
10398 12 : AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
10399 :
10400 12 : n->objectType = OBJECT_LARGEOBJECT;
10401 12 : n->object = (Node *) $4;
10402 12 : n->newowner = $7;
10403 12 : $$ = (Node *) n;
10404 : }
10405 : | ALTER OPERATOR operator_with_argtypes OWNER TO RoleSpec
10406 : {
10407 46 : AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
10408 :
10409 46 : n->objectType = OBJECT_OPERATOR;
10410 46 : n->object = (Node *) $3;
10411 46 : n->newowner = $6;
10412 46 : $$ = (Node *) n;
10413 : }
10414 : | ALTER OPERATOR CLASS any_name USING name OWNER TO RoleSpec
10415 : {
10416 54 : AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
10417 :
10418 54 : n->objectType = OBJECT_OPCLASS;
10419 54 : n->object = (Node *) lcons(makeString($6), $4);
10420 54 : n->newowner = $9;
10421 54 : $$ = (Node *) n;
10422 : }
10423 : | ALTER OPERATOR FAMILY any_name USING name OWNER TO RoleSpec
10424 : {
10425 62 : AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
10426 :
10427 62 : n->objectType = OBJECT_OPFAMILY;
10428 62 : n->object = (Node *) lcons(makeString($6), $4);
10429 62 : n->newowner = $9;
10430 62 : $$ = (Node *) n;
10431 : }
10432 : | ALTER PROCEDURE function_with_argtypes OWNER TO RoleSpec
10433 : {
10434 24 : AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
10435 :
10436 24 : n->objectType = OBJECT_PROCEDURE;
10437 24 : n->object = (Node *) $3;
10438 24 : n->newowner = $6;
10439 24 : $$ = (Node *) n;
10440 : }
10441 : | ALTER ROUTINE function_with_argtypes OWNER TO RoleSpec
10442 : {
10443 0 : AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
10444 :
10445 0 : n->objectType = OBJECT_ROUTINE;
10446 0 : n->object = (Node *) $3;
10447 0 : n->newowner = $6;
10448 0 : $$ = (Node *) n;
10449 : }
10450 : | ALTER SCHEMA name OWNER TO RoleSpec
10451 : {
10452 54 : AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
10453 :
10454 54 : n->objectType = OBJECT_SCHEMA;
10455 54 : n->object = (Node *) makeString($3);
10456 54 : n->newowner = $6;
10457 54 : $$ = (Node *) n;
10458 : }
10459 : | ALTER TYPE_P any_name OWNER TO RoleSpec
10460 : {
10461 80 : AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
10462 :
10463 80 : n->objectType = OBJECT_TYPE;
10464 80 : n->object = (Node *) $3;
10465 80 : n->newowner = $6;
10466 80 : $$ = (Node *) n;
10467 : }
10468 : | ALTER TABLESPACE name OWNER TO RoleSpec
10469 : {
10470 6 : AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
10471 :
10472 6 : n->objectType = OBJECT_TABLESPACE;
10473 6 : n->object = (Node *) makeString($3);
10474 6 : n->newowner = $6;
10475 6 : $$ = (Node *) n;
10476 : }
10477 : | ALTER STATISTICS any_name OWNER TO RoleSpec
10478 : {
10479 32 : AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
10480 :
10481 32 : n->objectType = OBJECT_STATISTIC_EXT;
10482 32 : n->object = (Node *) $3;
10483 32 : n->newowner = $6;
10484 32 : $$ = (Node *) n;
10485 : }
10486 : | ALTER TEXT_P SEARCH DICTIONARY any_name OWNER TO RoleSpec
10487 : {
10488 42 : AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
10489 :
10490 42 : n->objectType = OBJECT_TSDICTIONARY;
10491 42 : n->object = (Node *) $5;
10492 42 : n->newowner = $8;
10493 42 : $$ = (Node *) n;
10494 : }
10495 : | ALTER TEXT_P SEARCH CONFIGURATION any_name OWNER TO RoleSpec
10496 : {
10497 32 : AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
10498 :
10499 32 : n->objectType = OBJECT_TSCONFIGURATION;
10500 32 : n->object = (Node *) $5;
10501 32 : n->newowner = $8;
10502 32 : $$ = (Node *) n;
10503 : }
10504 : | ALTER FOREIGN DATA_P WRAPPER name OWNER TO RoleSpec
10505 : {
10506 20 : AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
10507 :
10508 20 : n->objectType = OBJECT_FDW;
10509 20 : n->object = (Node *) makeString($5);
10510 20 : n->newowner = $8;
10511 20 : $$ = (Node *) n;
10512 : }
10513 : | ALTER SERVER name OWNER TO RoleSpec
10514 : {
10515 68 : AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
10516 :
10517 68 : n->objectType = OBJECT_FOREIGN_SERVER;
10518 68 : n->object = (Node *) makeString($3);
10519 68 : n->newowner = $6;
10520 68 : $$ = (Node *) n;
10521 : }
10522 : | ALTER EVENT TRIGGER name OWNER TO RoleSpec
10523 : {
10524 14 : AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
10525 :
10526 14 : n->objectType = OBJECT_EVENT_TRIGGER;
10527 14 : n->object = (Node *) makeString($4);
10528 14 : n->newowner = $7;
10529 14 : $$ = (Node *) n;
10530 : }
10531 : | ALTER PUBLICATION name OWNER TO RoleSpec
10532 : {
10533 26 : AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
10534 :
10535 26 : n->objectType = OBJECT_PUBLICATION;
10536 26 : n->object = (Node *) makeString($3);
10537 26 : n->newowner = $6;
10538 26 : $$ = (Node *) n;
10539 : }
10540 : | ALTER SUBSCRIPTION name OWNER TO RoleSpec
10541 : {
10542 18 : AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
10543 :
10544 18 : n->objectType = OBJECT_SUBSCRIPTION;
10545 18 : n->object = (Node *) makeString($3);
10546 18 : n->newowner = $6;
10547 18 : $$ = (Node *) n;
10548 : }
10549 : ;
10550 :
10551 :
10552 : /*****************************************************************************
10553 : *
10554 : * CREATE PUBLICATION name [WITH options]
10555 : *
10556 : * CREATE PUBLICATION FOR ALL TABLES [WITH options]
10557 : *
10558 : * CREATE PUBLICATION FOR pub_obj [, ...] [WITH options]
10559 : *
10560 : * pub_obj is one of:
10561 : *
10562 : * TABLE table [, ...]
10563 : * TABLES IN SCHEMA schema [, ...]
10564 : *
10565 : *****************************************************************************/
10566 :
10567 : CreatePublicationStmt:
10568 : CREATE PUBLICATION name opt_definition
10569 : {
10570 122 : CreatePublicationStmt *n = makeNode(CreatePublicationStmt);
10571 :
10572 122 : n->pubname = $3;
10573 122 : n->options = $4;
10574 122 : $$ = (Node *) n;
10575 : }
10576 : | CREATE PUBLICATION name FOR ALL TABLES opt_definition
10577 : {
10578 74 : CreatePublicationStmt *n = makeNode(CreatePublicationStmt);
10579 :
10580 74 : n->pubname = $3;
10581 74 : n->options = $7;
10582 74 : n->for_all_tables = true;
10583 74 : $$ = (Node *) n;
10584 : }
10585 : | CREATE PUBLICATION name FOR pub_obj_list opt_definition
10586 : {
10587 570 : CreatePublicationStmt *n = makeNode(CreatePublicationStmt);
10588 :
10589 570 : n->pubname = $3;
10590 570 : n->options = $6;
10591 570 : n->pubobjects = (List *) $5;
10592 570 : preprocess_pubobj_list(n->pubobjects, yyscanner);
10593 540 : $$ = (Node *) n;
10594 : }
10595 : ;
10596 :
10597 : /*
10598 : * FOR TABLE and FOR TABLES IN SCHEMA specifications
10599 : *
10600 : * This rule parses publication objects with and without keyword prefixes.
10601 : *
10602 : * The actual type of the object without keyword prefix depends on the previous
10603 : * one with keyword prefix. It will be preprocessed in preprocess_pubobj_list().
10604 : *
10605 : * For the object without keyword prefix, we cannot just use relation_expr here,
10606 : * because some extended expressions in relation_expr cannot be used as a
10607 : * schemaname and we cannot differentiate it. So, we extract the rules from
10608 : * relation_expr here.
10609 : */
10610 : PublicationObjSpec:
10611 : TABLE relation_expr opt_column_list OptWhereClause
10612 : {
10613 1214 : $$ = makeNode(PublicationObjSpec);
10614 1214 : $$->pubobjtype = PUBLICATIONOBJ_TABLE;
10615 1214 : $$->pubtable = makeNode(PublicationTable);
10616 1214 : $$->pubtable->relation = $2;
10617 1214 : $$->pubtable->columns = $3;
10618 1214 : $$->pubtable->whereClause = $4;
10619 : }
10620 : | TABLES IN_P SCHEMA ColId
10621 : {
10622 332 : $$ = makeNode(PublicationObjSpec);
10623 332 : $$->pubobjtype = PUBLICATIONOBJ_TABLES_IN_SCHEMA;
10624 332 : $$->name = $4;
10625 332 : $$->location = @4;
10626 : }
10627 : | TABLES IN_P SCHEMA CURRENT_SCHEMA
10628 : {
10629 18 : $$ = makeNode(PublicationObjSpec);
10630 18 : $$->pubobjtype = PUBLICATIONOBJ_TABLES_IN_CUR_SCHEMA;
10631 18 : $$->location = @4;
10632 : }
10633 : | ColId opt_column_list OptWhereClause
10634 : {
10635 130 : $$ = makeNode(PublicationObjSpec);
10636 130 : $$->pubobjtype = PUBLICATIONOBJ_CONTINUATION;
10637 : /*
10638 : * If either a row filter or column list is specified, create
10639 : * a PublicationTable object.
10640 : */
10641 130 : if ($2 || $3)
10642 : {
10643 : /*
10644 : * The OptWhereClause must be stored here but it is
10645 : * valid only for tables. For non-table objects, an
10646 : * error will be thrown later via
10647 : * preprocess_pubobj_list().
10648 : */
10649 42 : $$->pubtable = makeNode(PublicationTable);
10650 42 : $$->pubtable->relation = makeRangeVar(NULL, $1, @1);
10651 42 : $$->pubtable->columns = $2;
10652 42 : $$->pubtable->whereClause = $3;
10653 : }
10654 : else
10655 : {
10656 88 : $$->name = $1;
10657 : }
10658 130 : $$->location = @1;
10659 : }
10660 : | ColId indirection opt_column_list OptWhereClause
10661 : {
10662 32 : $$ = makeNode(PublicationObjSpec);
10663 32 : $$->pubobjtype = PUBLICATIONOBJ_CONTINUATION;
10664 32 : $$->pubtable = makeNode(PublicationTable);
10665 32 : $$->pubtable->relation = makeRangeVarFromQualifiedName($1, $2, @1, yyscanner);
10666 32 : $$->pubtable->columns = $3;
10667 32 : $$->pubtable->whereClause = $4;
10668 32 : $$->location = @1;
10669 : }
10670 : /* grammar like tablename * , ONLY tablename, ONLY ( tablename ) */
10671 : | extended_relation_expr opt_column_list OptWhereClause
10672 : {
10673 6 : $$ = makeNode(PublicationObjSpec);
10674 6 : $$->pubobjtype = PUBLICATIONOBJ_CONTINUATION;
10675 6 : $$->pubtable = makeNode(PublicationTable);
10676 6 : $$->pubtable->relation = $1;
10677 6 : $$->pubtable->columns = $2;
10678 6 : $$->pubtable->whereClause = $3;
10679 : }
10680 : | CURRENT_SCHEMA
10681 : {
10682 18 : $$ = makeNode(PublicationObjSpec);
10683 18 : $$->pubobjtype = PUBLICATIONOBJ_CONTINUATION;
10684 18 : $$->location = @1;
10685 : }
10686 : ;
10687 :
10688 : pub_obj_list: PublicationObjSpec
10689 1526 : { $$ = list_make1($1); }
10690 : | pub_obj_list ',' PublicationObjSpec
10691 224 : { $$ = lappend($1, $3); }
10692 : ;
10693 :
10694 : /*****************************************************************************
10695 : *
10696 : * ALTER PUBLICATION name SET ( options )
10697 : *
10698 : * ALTER PUBLICATION name ADD pub_obj [, ...]
10699 : *
10700 : * ALTER PUBLICATION name DROP pub_obj [, ...]
10701 : *
10702 : * ALTER PUBLICATION name SET pub_obj [, ...]
10703 : *
10704 : * pub_obj is one of:
10705 : *
10706 : * TABLE table_name [, ...]
10707 : * TABLES IN SCHEMA schema_name [, ...]
10708 : *
10709 : *****************************************************************************/
10710 :
10711 : AlterPublicationStmt:
10712 : ALTER PUBLICATION name SET definition
10713 : {
10714 116 : AlterPublicationStmt *n = makeNode(AlterPublicationStmt);
10715 :
10716 116 : n->pubname = $3;
10717 116 : n->options = $5;
10718 116 : $$ = (Node *) n;
10719 : }
10720 : | ALTER PUBLICATION name ADD_P pub_obj_list
10721 : {
10722 338 : AlterPublicationStmt *n = makeNode(AlterPublicationStmt);
10723 :
10724 338 : n->pubname = $3;
10725 338 : n->pubobjects = $5;
10726 338 : preprocess_pubobj_list(n->pubobjects, yyscanner);
10727 332 : n->action = AP_AddObjects;
10728 332 : $$ = (Node *) n;
10729 : }
10730 : | ALTER PUBLICATION name SET pub_obj_list
10731 : {
10732 464 : AlterPublicationStmt *n = makeNode(AlterPublicationStmt);
10733 :
10734 464 : n->pubname = $3;
10735 464 : n->pubobjects = $5;
10736 464 : preprocess_pubobj_list(n->pubobjects, yyscanner);
10737 464 : n->action = AP_SetObjects;
10738 464 : $$ = (Node *) n;
10739 : }
10740 : | ALTER PUBLICATION name DROP pub_obj_list
10741 : {
10742 154 : AlterPublicationStmt *n = makeNode(AlterPublicationStmt);
10743 :
10744 154 : n->pubname = $3;
10745 154 : n->pubobjects = $5;
10746 154 : preprocess_pubobj_list(n->pubobjects, yyscanner);
10747 154 : n->action = AP_DropObjects;
10748 154 : $$ = (Node *) n;
10749 : }
10750 : ;
10751 :
10752 : /*****************************************************************************
10753 : *
10754 : * CREATE SUBSCRIPTION name ...
10755 : *
10756 : *****************************************************************************/
10757 :
10758 : CreateSubscriptionStmt:
10759 : CREATE SUBSCRIPTION name CONNECTION Sconst PUBLICATION name_list opt_definition
10760 : {
10761 : CreateSubscriptionStmt *n =
10762 426 : makeNode(CreateSubscriptionStmt);
10763 426 : n->subname = $3;
10764 426 : n->conninfo = $5;
10765 426 : n->publication = $7;
10766 426 : n->options = $8;
10767 426 : $$ = (Node *) n;
10768 : }
10769 : ;
10770 :
10771 : /*****************************************************************************
10772 : *
10773 : * ALTER SUBSCRIPTION name ...
10774 : *
10775 : *****************************************************************************/
10776 :
10777 : AlterSubscriptionStmt:
10778 : ALTER SUBSCRIPTION name SET definition
10779 : {
10780 : AlterSubscriptionStmt *n =
10781 184 : makeNode(AlterSubscriptionStmt);
10782 :
10783 184 : n->kind = ALTER_SUBSCRIPTION_OPTIONS;
10784 184 : n->subname = $3;
10785 184 : n->options = $5;
10786 184 : $$ = (Node *) n;
10787 : }
10788 : | ALTER SUBSCRIPTION name CONNECTION Sconst
10789 : {
10790 : AlterSubscriptionStmt *n =
10791 26 : makeNode(AlterSubscriptionStmt);
10792 :
10793 26 : n->kind = ALTER_SUBSCRIPTION_CONNECTION;
10794 26 : n->subname = $3;
10795 26 : n->conninfo = $5;
10796 26 : $$ = (Node *) n;
10797 : }
10798 : | ALTER SUBSCRIPTION name REFRESH PUBLICATION opt_definition
10799 : {
10800 : AlterSubscriptionStmt *n =
10801 54 : makeNode(AlterSubscriptionStmt);
10802 :
10803 54 : n->kind = ALTER_SUBSCRIPTION_REFRESH;
10804 54 : n->subname = $3;
10805 54 : n->options = $6;
10806 54 : $$ = (Node *) n;
10807 : }
10808 : | ALTER SUBSCRIPTION name ADD_P PUBLICATION name_list opt_definition
10809 : {
10810 : AlterSubscriptionStmt *n =
10811 28 : makeNode(AlterSubscriptionStmt);
10812 :
10813 28 : n->kind = ALTER_SUBSCRIPTION_ADD_PUBLICATION;
10814 28 : n->subname = $3;
10815 28 : n->publication = $6;
10816 28 : n->options = $7;
10817 28 : $$ = (Node *) n;
10818 : }
10819 : | ALTER SUBSCRIPTION name DROP PUBLICATION name_list opt_definition
10820 : {
10821 : AlterSubscriptionStmt *n =
10822 26 : makeNode(AlterSubscriptionStmt);
10823 :
10824 26 : n->kind = ALTER_SUBSCRIPTION_DROP_PUBLICATION;
10825 26 : n->subname = $3;
10826 26 : n->publication = $6;
10827 26 : n->options = $7;
10828 26 : $$ = (Node *) n;
10829 : }
10830 : | ALTER SUBSCRIPTION name SET PUBLICATION name_list opt_definition
10831 : {
10832 : AlterSubscriptionStmt *n =
10833 40 : makeNode(AlterSubscriptionStmt);
10834 :
10835 40 : n->kind = ALTER_SUBSCRIPTION_SET_PUBLICATION;
10836 40 : n->subname = $3;
10837 40 : n->publication = $6;
10838 40 : n->options = $7;
10839 40 : $$ = (Node *) n;
10840 : }
10841 : | ALTER SUBSCRIPTION name ENABLE_P
10842 : {
10843 : AlterSubscriptionStmt *n =
10844 48 : makeNode(AlterSubscriptionStmt);
10845 :
10846 48 : n->kind = ALTER_SUBSCRIPTION_ENABLED;
10847 48 : n->subname = $3;
10848 48 : n->options = list_make1(makeDefElem("enabled",
10849 : (Node *) makeBoolean(true), @1));
10850 48 : $$ = (Node *) n;
10851 : }
10852 : | ALTER SUBSCRIPTION name DISABLE_P
10853 : {
10854 : AlterSubscriptionStmt *n =
10855 32 : makeNode(AlterSubscriptionStmt);
10856 :
10857 32 : n->kind = ALTER_SUBSCRIPTION_ENABLED;
10858 32 : n->subname = $3;
10859 32 : n->options = list_make1(makeDefElem("enabled",
10860 : (Node *) makeBoolean(false), @1));
10861 32 : $$ = (Node *) n;
10862 : }
10863 : | ALTER SUBSCRIPTION name SKIP definition
10864 : {
10865 : AlterSubscriptionStmt *n =
10866 24 : makeNode(AlterSubscriptionStmt);
10867 :
10868 24 : n->kind = ALTER_SUBSCRIPTION_SKIP;
10869 24 : n->subname = $3;
10870 24 : n->options = $5;
10871 24 : $$ = (Node *) n;
10872 : }
10873 : ;
10874 :
10875 : /*****************************************************************************
10876 : *
10877 : * DROP SUBSCRIPTION [ IF EXISTS ] name
10878 : *
10879 : *****************************************************************************/
10880 :
10881 : DropSubscriptionStmt: DROP SUBSCRIPTION name opt_drop_behavior
10882 : {
10883 198 : DropSubscriptionStmt *n = makeNode(DropSubscriptionStmt);
10884 :
10885 198 : n->subname = $3;
10886 198 : n->missing_ok = false;
10887 198 : n->behavior = $4;
10888 198 : $$ = (Node *) n;
10889 : }
10890 : | DROP SUBSCRIPTION IF_P EXISTS name opt_drop_behavior
10891 : {
10892 6 : DropSubscriptionStmt *n = makeNode(DropSubscriptionStmt);
10893 :
10894 6 : n->subname = $5;
10895 6 : n->missing_ok = true;
10896 6 : n->behavior = $6;
10897 6 : $$ = (Node *) n;
10898 : }
10899 : ;
10900 :
10901 : /*****************************************************************************
10902 : *
10903 : * QUERY: Define Rewrite Rule
10904 : *
10905 : *****************************************************************************/
10906 :
10907 : RuleStmt: CREATE opt_or_replace RULE name AS
10908 : ON event TO qualified_name where_clause
10909 : DO opt_instead RuleActionList
10910 : {
10911 1054 : RuleStmt *n = makeNode(RuleStmt);
10912 :
10913 1054 : n->replace = $2;
10914 1054 : n->relation = $9;
10915 1054 : n->rulename = $4;
10916 1054 : n->whereClause = $10;
10917 1054 : n->event = $7;
10918 1054 : n->instead = $12;
10919 1054 : n->actions = $13;
10920 1054 : $$ = (Node *) n;
10921 : }
10922 : ;
10923 :
10924 : RuleActionList:
10925 152 : NOTHING { $$ = NIL; }
10926 856 : | RuleActionStmt { $$ = list_make1($1); }
10927 46 : | '(' RuleActionMulti ')' { $$ = $2; }
10928 : ;
10929 :
10930 : /* the thrashing around here is to discard "empty" statements... */
10931 : RuleActionMulti:
10932 : RuleActionMulti ';' RuleActionStmtOrEmpty
10933 62 : { if ($3 != NULL)
10934 46 : $$ = lappend($1, $3);
10935 : else
10936 16 : $$ = $1;
10937 : }
10938 : | RuleActionStmtOrEmpty
10939 46 : { if ($1 != NULL)
10940 46 : $$ = list_make1($1);
10941 : else
10942 0 : $$ = NIL;
10943 : }
10944 : ;
10945 :
10946 : RuleActionStmt:
10947 : SelectStmt
10948 : | InsertStmt
10949 : | UpdateStmt
10950 : | DeleteStmt
10951 : | NotifyStmt
10952 : ;
10953 :
10954 : RuleActionStmtOrEmpty:
10955 92 : RuleActionStmt { $$ = $1; }
10956 16 : | /*EMPTY*/ { $$ = NULL; }
10957 : ;
10958 :
10959 18 : event: SELECT { $$ = CMD_SELECT; }
10960 406 : | UPDATE { $$ = CMD_UPDATE; }
10961 152 : | DELETE_P { $$ = CMD_DELETE; }
10962 478 : | INSERT { $$ = CMD_INSERT; }
10963 : ;
10964 :
10965 : opt_instead:
10966 724 : INSTEAD { $$ = true; }
10967 156 : | ALSO { $$ = false; }
10968 174 : | /*EMPTY*/ { $$ = false; }
10969 : ;
10970 :
10971 :
10972 : /*****************************************************************************
10973 : *
10974 : * QUERY:
10975 : * NOTIFY <identifier> can appear both in rule bodies and
10976 : * as a query-level command
10977 : *
10978 : *****************************************************************************/
10979 :
10980 : NotifyStmt: NOTIFY ColId notify_payload
10981 : {
10982 128 : NotifyStmt *n = makeNode(NotifyStmt);
10983 :
10984 128 : n->conditionname = $2;
10985 128 : n->payload = $3;
10986 128 : $$ = (Node *) n;
10987 : }
10988 : ;
10989 :
10990 : notify_payload:
10991 62 : ',' Sconst { $$ = $2; }
10992 66 : | /*EMPTY*/ { $$ = NULL; }
10993 : ;
10994 :
10995 : ListenStmt: LISTEN ColId
10996 : {
10997 74 : ListenStmt *n = makeNode(ListenStmt);
10998 :
10999 74 : n->conditionname = $2;
11000 74 : $$ = (Node *) n;
11001 : }
11002 : ;
11003 :
11004 : UnlistenStmt:
11005 : UNLISTEN ColId
11006 : {
11007 6 : UnlistenStmt *n = makeNode(UnlistenStmt);
11008 :
11009 6 : n->conditionname = $2;
11010 6 : $$ = (Node *) n;
11011 : }
11012 : | UNLISTEN '*'
11013 : {
11014 32 : UnlistenStmt *n = makeNode(UnlistenStmt);
11015 :
11016 32 : n->conditionname = NULL;
11017 32 : $$ = (Node *) n;
11018 : }
11019 : ;
11020 :
11021 :
11022 : /*****************************************************************************
11023 : *
11024 : * Transactions:
11025 : *
11026 : * BEGIN / COMMIT / ROLLBACK
11027 : * (also older versions END / ABORT)
11028 : *
11029 : *****************************************************************************/
11030 :
11031 : TransactionStmt:
11032 : ABORT_P opt_transaction opt_transaction_chain
11033 : {
11034 210 : TransactionStmt *n = makeNode(TransactionStmt);
11035 :
11036 210 : n->kind = TRANS_STMT_ROLLBACK;
11037 210 : n->options = NIL;
11038 210 : n->chain = $3;
11039 210 : n->location = -1;
11040 210 : $$ = (Node *) n;
11041 : }
11042 : | START TRANSACTION transaction_mode_list_or_empty
11043 : {
11044 1586 : TransactionStmt *n = makeNode(TransactionStmt);
11045 :
11046 1586 : n->kind = TRANS_STMT_START;
11047 1586 : n->options = $3;
11048 1586 : n->location = -1;
11049 1586 : $$ = (Node *) n;
11050 : }
11051 : | COMMIT opt_transaction opt_transaction_chain
11052 : {
11053 11496 : TransactionStmt *n = makeNode(TransactionStmt);
11054 :
11055 11496 : n->kind = TRANS_STMT_COMMIT;
11056 11496 : n->options = NIL;
11057 11496 : n->chain = $3;
11058 11496 : n->location = -1;
11059 11496 : $$ = (Node *) n;
11060 : }
11061 : | ROLLBACK opt_transaction opt_transaction_chain
11062 : {
11063 2506 : TransactionStmt *n = makeNode(TransactionStmt);
11064 :
11065 2506 : n->kind = TRANS_STMT_ROLLBACK;
11066 2506 : n->options = NIL;
11067 2506 : n->chain = $3;
11068 2506 : n->location = -1;
11069 2506 : $$ = (Node *) n;
11070 : }
11071 : | SAVEPOINT ColId
11072 : {
11073 1998 : TransactionStmt *n = makeNode(TransactionStmt);
11074 :
11075 1998 : n->kind = TRANS_STMT_SAVEPOINT;
11076 1998 : n->savepoint_name = $2;
11077 1998 : n->location = @2;
11078 1998 : $$ = (Node *) n;
11079 : }
11080 : | RELEASE SAVEPOINT ColId
11081 : {
11082 208 : TransactionStmt *n = makeNode(TransactionStmt);
11083 :
11084 208 : n->kind = TRANS_STMT_RELEASE;
11085 208 : n->savepoint_name = $3;
11086 208 : n->location = @3;
11087 208 : $$ = (Node *) n;
11088 : }
11089 : | RELEASE ColId
11090 : {
11091 86 : TransactionStmt *n = makeNode(TransactionStmt);
11092 :
11093 86 : n->kind = TRANS_STMT_RELEASE;
11094 86 : n->savepoint_name = $2;
11095 86 : n->location = @2;
11096 86 : $$ = (Node *) n;
11097 : }
11098 : | ROLLBACK opt_transaction TO SAVEPOINT ColId
11099 : {
11100 218 : TransactionStmt *n = makeNode(TransactionStmt);
11101 :
11102 218 : n->kind = TRANS_STMT_ROLLBACK_TO;
11103 218 : n->savepoint_name = $5;
11104 218 : n->location = @5;
11105 218 : $$ = (Node *) n;
11106 : }
11107 : | ROLLBACK opt_transaction TO ColId
11108 : {
11109 496 : TransactionStmt *n = makeNode(TransactionStmt);
11110 :
11111 496 : n->kind = TRANS_STMT_ROLLBACK_TO;
11112 496 : n->savepoint_name = $4;
11113 496 : n->location = @4;
11114 496 : $$ = (Node *) n;
11115 : }
11116 : | PREPARE TRANSACTION Sconst
11117 : {
11118 800 : TransactionStmt *n = makeNode(TransactionStmt);
11119 :
11120 800 : n->kind = TRANS_STMT_PREPARE;
11121 800 : n->gid = $3;
11122 800 : n->location = @3;
11123 800 : $$ = (Node *) n;
11124 : }
11125 : | COMMIT PREPARED Sconst
11126 : {
11127 648 : TransactionStmt *n = makeNode(TransactionStmt);
11128 :
11129 648 : n->kind = TRANS_STMT_COMMIT_PREPARED;
11130 648 : n->gid = $3;
11131 648 : n->location = @3;
11132 648 : $$ = (Node *) n;
11133 : }
11134 : | ROLLBACK PREPARED Sconst
11135 : {
11136 74 : TransactionStmt *n = makeNode(TransactionStmt);
11137 :
11138 74 : n->kind = TRANS_STMT_ROLLBACK_PREPARED;
11139 74 : n->gid = $3;
11140 74 : n->location = @3;
11141 74 : $$ = (Node *) n;
11142 : }
11143 : ;
11144 :
11145 : TransactionStmtLegacy:
11146 : BEGIN_P opt_transaction transaction_mode_list_or_empty
11147 : {
11148 14074 : TransactionStmt *n = makeNode(TransactionStmt);
11149 :
11150 14074 : n->kind = TRANS_STMT_BEGIN;
11151 14074 : n->options = $3;
11152 14074 : n->location = -1;
11153 14074 : $$ = (Node *) n;
11154 : }
11155 : | END_P opt_transaction opt_transaction_chain
11156 : {
11157 360 : TransactionStmt *n = makeNode(TransactionStmt);
11158 :
11159 360 : n->kind = TRANS_STMT_COMMIT;
11160 360 : n->options = NIL;
11161 360 : n->chain = $3;
11162 360 : n->location = -1;
11163 360 : $$ = (Node *) n;
11164 : }
11165 : ;
11166 :
11167 : opt_transaction: WORK
11168 : | TRANSACTION
11169 : | /*EMPTY*/
11170 : ;
11171 :
11172 : transaction_mode_item:
11173 : ISOLATION LEVEL iso_level
11174 6552 : { $$ = makeDefElem("transaction_isolation",
11175 6552 : makeStringConst($3, @3), @1); }
11176 : | READ ONLY
11177 1304 : { $$ = makeDefElem("transaction_read_only",
11178 1304 : makeIntConst(true, @1), @1); }
11179 : | READ WRITE
11180 90 : { $$ = makeDefElem("transaction_read_only",
11181 90 : makeIntConst(false, @1), @1); }
11182 : | DEFERRABLE
11183 44 : { $$ = makeDefElem("transaction_deferrable",
11184 : makeIntConst(true, @1), @1); }
11185 : | NOT DEFERRABLE
11186 10 : { $$ = makeDefElem("transaction_deferrable",
11187 10 : makeIntConst(false, @1), @1); }
11188 : ;
11189 :
11190 : /* Syntax with commas is SQL-spec, without commas is Postgres historical */
11191 : transaction_mode_list:
11192 : transaction_mode_item
11193 6768 : { $$ = list_make1($1); }
11194 : | transaction_mode_list ',' transaction_mode_item
11195 878 : { $$ = lappend($1, $3); }
11196 : | transaction_mode_list transaction_mode_item
11197 354 : { $$ = lappend($1, $2); }
11198 : ;
11199 :
11200 : transaction_mode_list_or_empty:
11201 : transaction_mode_list
11202 : | /* EMPTY */
11203 9430 : { $$ = NIL; }
11204 : ;
11205 :
11206 : opt_transaction_chain:
11207 120 : AND CHAIN { $$ = true; }
11208 2 : | AND NO CHAIN { $$ = false; }
11209 14450 : | /* EMPTY */ { $$ = false; }
11210 : ;
11211 :
11212 :
11213 : /*****************************************************************************
11214 : *
11215 : * QUERY:
11216 : * CREATE [ OR REPLACE ] [ TEMP ] VIEW <viewname> '('target-list ')'
11217 : * AS <query> [ WITH [ CASCADED | LOCAL ] CHECK OPTION ]
11218 : *
11219 : *****************************************************************************/
11220 :
11221 : ViewStmt: CREATE OptTemp VIEW qualified_name opt_column_list opt_reloptions
11222 : AS SelectStmt opt_check_option
11223 : {
11224 14900 : ViewStmt *n = makeNode(ViewStmt);
11225 :
11226 14900 : n->view = $4;
11227 14900 : n->view->relpersistence = $2;
11228 14900 : n->aliases = $5;
11229 14900 : n->query = $8;
11230 14900 : n->replace = false;
11231 14900 : n->options = $6;
11232 14900 : n->withCheckOption = $9;
11233 14900 : $$ = (Node *) n;
11234 : }
11235 : | CREATE OR REPLACE OptTemp VIEW qualified_name opt_column_list opt_reloptions
11236 : AS SelectStmt opt_check_option
11237 : {
11238 244 : ViewStmt *n = makeNode(ViewStmt);
11239 :
11240 244 : n->view = $6;
11241 244 : n->view->relpersistence = $4;
11242 244 : n->aliases = $7;
11243 244 : n->query = $10;
11244 244 : n->replace = true;
11245 244 : n->options = $8;
11246 244 : n->withCheckOption = $11;
11247 244 : $$ = (Node *) n;
11248 : }
11249 : | CREATE OptTemp RECURSIVE VIEW qualified_name '(' columnList ')' opt_reloptions
11250 : AS SelectStmt opt_check_option
11251 : {
11252 8 : ViewStmt *n = makeNode(ViewStmt);
11253 :
11254 8 : n->view = $5;
11255 8 : n->view->relpersistence = $2;
11256 8 : n->aliases = $7;
11257 8 : n->query = makeRecursiveViewSelect(n->view->relname, n->aliases, $11);
11258 8 : n->replace = false;
11259 8 : n->options = $9;
11260 8 : n->withCheckOption = $12;
11261 8 : if (n->withCheckOption != NO_CHECK_OPTION)
11262 0 : ereport(ERROR,
11263 : (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
11264 : errmsg("WITH CHECK OPTION not supported on recursive views"),
11265 : parser_errposition(@12)));
11266 8 : $$ = (Node *) n;
11267 : }
11268 : | CREATE OR REPLACE OptTemp RECURSIVE VIEW qualified_name '(' columnList ')' opt_reloptions
11269 : AS SelectStmt opt_check_option
11270 : {
11271 6 : ViewStmt *n = makeNode(ViewStmt);
11272 :
11273 6 : n->view = $7;
11274 6 : n->view->relpersistence = $4;
11275 6 : n->aliases = $9;
11276 6 : n->query = makeRecursiveViewSelect(n->view->relname, n->aliases, $13);
11277 6 : n->replace = true;
11278 6 : n->options = $11;
11279 6 : n->withCheckOption = $14;
11280 6 : if (n->withCheckOption != NO_CHECK_OPTION)
11281 0 : ereport(ERROR,
11282 : (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
11283 : errmsg("WITH CHECK OPTION not supported on recursive views"),
11284 : parser_errposition(@14)));
11285 6 : $$ = (Node *) n;
11286 : }
11287 : ;
11288 :
11289 : opt_check_option:
11290 90 : WITH CHECK OPTION { $$ = CASCADED_CHECK_OPTION; }
11291 6 : | WITH CASCADED CHECK OPTION { $$ = CASCADED_CHECK_OPTION; }
11292 24 : | WITH LOCAL CHECK OPTION { $$ = LOCAL_CHECK_OPTION; }
11293 15038 : | /* EMPTY */ { $$ = NO_CHECK_OPTION; }
11294 : ;
11295 :
11296 : /*****************************************************************************
11297 : *
11298 : * QUERY:
11299 : * LOAD "filename"
11300 : *
11301 : *****************************************************************************/
11302 :
11303 : LoadStmt: LOAD file_name
11304 : {
11305 58 : LoadStmt *n = makeNode(LoadStmt);
11306 :
11307 58 : n->filename = $2;
11308 58 : $$ = (Node *) n;
11309 : }
11310 : ;
11311 :
11312 :
11313 : /*****************************************************************************
11314 : *
11315 : * CREATE DATABASE
11316 : *
11317 : *****************************************************************************/
11318 :
11319 : CreatedbStmt:
11320 : CREATE DATABASE name opt_with createdb_opt_list
11321 : {
11322 678 : CreatedbStmt *n = makeNode(CreatedbStmt);
11323 :
11324 678 : n->dbname = $3;
11325 678 : n->options = $5;
11326 678 : $$ = (Node *) n;
11327 : }
11328 : ;
11329 :
11330 : createdb_opt_list:
11331 532 : createdb_opt_items { $$ = $1; }
11332 176 : | /* EMPTY */ { $$ = NIL; }
11333 : ;
11334 :
11335 : createdb_opt_items:
11336 532 : createdb_opt_item { $$ = list_make1($1); }
11337 716 : | createdb_opt_items createdb_opt_item { $$ = lappend($1, $2); }
11338 : ;
11339 :
11340 : createdb_opt_item:
11341 : createdb_opt_name opt_equal NumericOnly
11342 : {
11343 210 : $$ = makeDefElem($1, $3, @1);
11344 : }
11345 : | createdb_opt_name opt_equal opt_boolean_or_string
11346 : {
11347 1038 : $$ = makeDefElem($1, (Node *) makeString($3), @1);
11348 : }
11349 : | createdb_opt_name opt_equal DEFAULT
11350 : {
11351 0 : $$ = makeDefElem($1, NULL, @1);
11352 : }
11353 : ;
11354 :
11355 : /*
11356 : * Ideally we'd use ColId here, but that causes shift/reduce conflicts against
11357 : * the ALTER DATABASE SET/RESET syntaxes. Instead call out specific keywords
11358 : * we need, and allow IDENT so that database option names don't have to be
11359 : * parser keywords unless they are already keywords for other reasons.
11360 : *
11361 : * XXX this coding technique is fragile since if someone makes a formerly
11362 : * non-keyword option name into a keyword and forgets to add it here, the
11363 : * option will silently break. Best defense is to provide a regression test
11364 : * exercising every such option, at least at the syntax level.
11365 : */
11366 : createdb_opt_name:
11367 866 : IDENT { $$ = $1; }
11368 2 : | CONNECTION LIMIT { $$ = pstrdup("connection_limit"); }
11369 66 : | ENCODING { $$ = pstrdup($1); }
11370 0 : | LOCATION { $$ = pstrdup($1); }
11371 2 : | OWNER { $$ = pstrdup($1); }
11372 16 : | TABLESPACE { $$ = pstrdup($1); }
11373 296 : | TEMPLATE { $$ = pstrdup($1); }
11374 : ;
11375 :
11376 : /*
11377 : * Though the equals sign doesn't match other WITH options, pg_dump uses
11378 : * equals for backward compatibility, and it doesn't seem worth removing it.
11379 : */
11380 : opt_equal: '='
11381 : | /*EMPTY*/
11382 : ;
11383 :
11384 :
11385 : /*****************************************************************************
11386 : *
11387 : * ALTER DATABASE
11388 : *
11389 : *****************************************************************************/
11390 :
11391 : AlterDatabaseStmt:
11392 : ALTER DATABASE name WITH createdb_opt_list
11393 : {
11394 0 : AlterDatabaseStmt *n = makeNode(AlterDatabaseStmt);
11395 :
11396 0 : n->dbname = $3;
11397 0 : n->options = $5;
11398 0 : $$ = (Node *) n;
11399 : }
11400 : | ALTER DATABASE name createdb_opt_list
11401 : {
11402 30 : AlterDatabaseStmt *n = makeNode(AlterDatabaseStmt);
11403 :
11404 30 : n->dbname = $3;
11405 30 : n->options = $4;
11406 30 : $$ = (Node *) n;
11407 : }
11408 : | ALTER DATABASE name SET TABLESPACE name
11409 : {
11410 16 : AlterDatabaseStmt *n = makeNode(AlterDatabaseStmt);
11411 :
11412 16 : n->dbname = $3;
11413 16 : n->options = list_make1(makeDefElem("tablespace",
11414 : (Node *) makeString($6), @6));
11415 16 : $$ = (Node *) n;
11416 : }
11417 : | ALTER DATABASE name REFRESH COLLATION VERSION_P
11418 : {
11419 6 : AlterDatabaseRefreshCollStmt *n = makeNode(AlterDatabaseRefreshCollStmt);
11420 :
11421 6 : n->dbname = $3;
11422 6 : $$ = (Node *) n;
11423 : }
11424 : ;
11425 :
11426 : AlterDatabaseSetStmt:
11427 : ALTER DATABASE name SetResetClause
11428 : {
11429 1130 : AlterDatabaseSetStmt *n = makeNode(AlterDatabaseSetStmt);
11430 :
11431 1130 : n->dbname = $3;
11432 1130 : n->setstmt = $4;
11433 1130 : $$ = (Node *) n;
11434 : }
11435 : ;
11436 :
11437 :
11438 : /*****************************************************************************
11439 : *
11440 : * DROP DATABASE [ IF EXISTS ] dbname [ [ WITH ] ( options ) ]
11441 : *
11442 : * This is implicitly CASCADE, no need for drop behavior
11443 : *****************************************************************************/
11444 :
11445 : DropdbStmt: DROP DATABASE name
11446 : {
11447 72 : DropdbStmt *n = makeNode(DropdbStmt);
11448 :
11449 72 : n->dbname = $3;
11450 72 : n->missing_ok = false;
11451 72 : n->options = NULL;
11452 72 : $$ = (Node *) n;
11453 : }
11454 : | DROP DATABASE IF_P EXISTS name
11455 : {
11456 4 : DropdbStmt *n = makeNode(DropdbStmt);
11457 :
11458 4 : n->dbname = $5;
11459 4 : n->missing_ok = true;
11460 4 : n->options = NULL;
11461 4 : $$ = (Node *) n;
11462 : }
11463 : | DROP DATABASE name opt_with '(' drop_option_list ')'
11464 : {
11465 14 : DropdbStmt *n = makeNode(DropdbStmt);
11466 :
11467 14 : n->dbname = $3;
11468 14 : n->missing_ok = false;
11469 14 : n->options = $6;
11470 14 : $$ = (Node *) n;
11471 : }
11472 : | DROP DATABASE IF_P EXISTS name opt_with '(' drop_option_list ')'
11473 : {
11474 12 : DropdbStmt *n = makeNode(DropdbStmt);
11475 :
11476 12 : n->dbname = $5;
11477 12 : n->missing_ok = true;
11478 12 : n->options = $8;
11479 12 : $$ = (Node *) n;
11480 : }
11481 : ;
11482 :
11483 : drop_option_list:
11484 : drop_option
11485 : {
11486 26 : $$ = list_make1((Node *) $1);
11487 : }
11488 : | drop_option_list ',' drop_option
11489 : {
11490 0 : $$ = lappend($1, (Node *) $3);
11491 : }
11492 : ;
11493 :
11494 : /*
11495 : * Currently only the FORCE option is supported, but the syntax is designed
11496 : * to be extensible so that we can add more options in the future if required.
11497 : */
11498 : drop_option:
11499 : FORCE
11500 : {
11501 26 : $$ = makeDefElem("force", NULL, @1);
11502 : }
11503 : ;
11504 :
11505 : /*****************************************************************************
11506 : *
11507 : * ALTER COLLATION
11508 : *
11509 : *****************************************************************************/
11510 :
11511 : AlterCollationStmt: ALTER COLLATION any_name REFRESH VERSION_P
11512 : {
11513 6 : AlterCollationStmt *n = makeNode(AlterCollationStmt);
11514 :
11515 6 : n->collname = $3;
11516 6 : $$ = (Node *) n;
11517 : }
11518 : ;
11519 :
11520 :
11521 : /*****************************************************************************
11522 : *
11523 : * ALTER SYSTEM
11524 : *
11525 : * This is used to change configuration parameters persistently.
11526 : *****************************************************************************/
11527 :
11528 : AlterSystemStmt:
11529 : ALTER SYSTEM_P SET generic_set
11530 : {
11531 112 : AlterSystemStmt *n = makeNode(AlterSystemStmt);
11532 :
11533 112 : n->setstmt = $4;
11534 112 : $$ = (Node *) n;
11535 : }
11536 : | ALTER SYSTEM_P RESET generic_reset
11537 : {
11538 54 : AlterSystemStmt *n = makeNode(AlterSystemStmt);
11539 :
11540 54 : n->setstmt = $4;
11541 54 : $$ = (Node *) n;
11542 : }
11543 : ;
11544 :
11545 :
11546 : /*****************************************************************************
11547 : *
11548 : * Manipulate a domain
11549 : *
11550 : *****************************************************************************/
11551 :
11552 : CreateDomainStmt:
11553 : CREATE DOMAIN_P any_name opt_as Typename ColQualList
11554 : {
11555 1244 : CreateDomainStmt *n = makeNode(CreateDomainStmt);
11556 :
11557 1244 : n->domainname = $3;
11558 1244 : n->typeName = $5;
11559 1244 : SplitColQualList($6, &n->constraints, &n->collClause,
11560 : yyscanner);
11561 1244 : $$ = (Node *) n;
11562 : }
11563 : ;
11564 :
11565 : AlterDomainStmt:
11566 : /* ALTER DOMAIN <domain> {SET DEFAULT <expr>|DROP DEFAULT} */
11567 : ALTER DOMAIN_P any_name alter_column_default
11568 : {
11569 14 : AlterDomainStmt *n = makeNode(AlterDomainStmt);
11570 :
11571 14 : n->subtype = 'T';
11572 14 : n->typeName = $3;
11573 14 : n->def = $4;
11574 14 : $$ = (Node *) n;
11575 : }
11576 : /* ALTER DOMAIN <domain> DROP NOT NULL */
11577 : | ALTER DOMAIN_P any_name DROP NOT NULL_P
11578 : {
11579 12 : AlterDomainStmt *n = makeNode(AlterDomainStmt);
11580 :
11581 12 : n->subtype = 'N';
11582 12 : n->typeName = $3;
11583 12 : $$ = (Node *) n;
11584 : }
11585 : /* ALTER DOMAIN <domain> SET NOT NULL */
11586 : | ALTER DOMAIN_P any_name SET NOT NULL_P
11587 : {
11588 24 : AlterDomainStmt *n = makeNode(AlterDomainStmt);
11589 :
11590 24 : n->subtype = 'O';
11591 24 : n->typeName = $3;
11592 24 : $$ = (Node *) n;
11593 : }
11594 : /* ALTER DOMAIN <domain> ADD CONSTRAINT ... */
11595 : | ALTER DOMAIN_P any_name ADD_P DomainConstraint
11596 : {
11597 168 : AlterDomainStmt *n = makeNode(AlterDomainStmt);
11598 :
11599 168 : n->subtype = 'C';
11600 168 : n->typeName = $3;
11601 168 : n->def = $5;
11602 168 : $$ = (Node *) n;
11603 : }
11604 : /* ALTER DOMAIN <domain> DROP CONSTRAINT <name> [RESTRICT|CASCADE] */
11605 : | ALTER DOMAIN_P any_name DROP CONSTRAINT name opt_drop_behavior
11606 : {
11607 48 : AlterDomainStmt *n = makeNode(AlterDomainStmt);
11608 :
11609 48 : n->subtype = 'X';
11610 48 : n->typeName = $3;
11611 48 : n->name = $6;
11612 48 : n->behavior = $7;
11613 48 : n->missing_ok = false;
11614 48 : $$ = (Node *) n;
11615 : }
11616 : /* ALTER DOMAIN <domain> DROP CONSTRAINT IF EXISTS <name> [RESTRICT|CASCADE] */
11617 : | ALTER DOMAIN_P any_name DROP CONSTRAINT IF_P EXISTS name opt_drop_behavior
11618 : {
11619 6 : AlterDomainStmt *n = makeNode(AlterDomainStmt);
11620 :
11621 6 : n->subtype = 'X';
11622 6 : n->typeName = $3;
11623 6 : n->name = $8;
11624 6 : n->behavior = $9;
11625 6 : n->missing_ok = true;
11626 6 : $$ = (Node *) n;
11627 : }
11628 : /* ALTER DOMAIN <domain> VALIDATE CONSTRAINT <name> */
11629 : | ALTER DOMAIN_P any_name VALIDATE CONSTRAINT name
11630 : {
11631 12 : AlterDomainStmt *n = makeNode(AlterDomainStmt);
11632 :
11633 12 : n->subtype = 'V';
11634 12 : n->typeName = $3;
11635 12 : n->name = $6;
11636 12 : $$ = (Node *) n;
11637 : }
11638 : ;
11639 :
11640 : opt_as: AS
11641 : | /* EMPTY */
11642 : ;
11643 :
11644 :
11645 : /*****************************************************************************
11646 : *
11647 : * Manipulate a text search dictionary or configuration
11648 : *
11649 : *****************************************************************************/
11650 :
11651 : AlterTSDictionaryStmt:
11652 : ALTER TEXT_P SEARCH DICTIONARY any_name definition
11653 : {
11654 40 : AlterTSDictionaryStmt *n = makeNode(AlterTSDictionaryStmt);
11655 :
11656 40 : n->dictname = $5;
11657 40 : n->options = $6;
11658 40 : $$ = (Node *) n;
11659 : }
11660 : ;
11661 :
11662 : AlterTSConfigurationStmt:
11663 : ALTER TEXT_P SEARCH CONFIGURATION any_name ADD_P MAPPING FOR name_list any_with any_name_list
11664 : {
11665 7390 : AlterTSConfigurationStmt *n = makeNode(AlterTSConfigurationStmt);
11666 :
11667 7390 : n->kind = ALTER_TSCONFIG_ADD_MAPPING;
11668 7390 : n->cfgname = $5;
11669 7390 : n->tokentype = $9;
11670 7390 : n->dicts = $11;
11671 7390 : n->override = false;
11672 7390 : n->replace = false;
11673 7390 : $$ = (Node *) n;
11674 : }
11675 : | ALTER TEXT_P SEARCH CONFIGURATION any_name ALTER MAPPING FOR name_list any_with any_name_list
11676 : {
11677 26 : AlterTSConfigurationStmt *n = makeNode(AlterTSConfigurationStmt);
11678 :
11679 26 : n->kind = ALTER_TSCONFIG_ALTER_MAPPING_FOR_TOKEN;
11680 26 : n->cfgname = $5;
11681 26 : n->tokentype = $9;
11682 26 : n->dicts = $11;
11683 26 : n->override = true;
11684 26 : n->replace = false;
11685 26 : $$ = (Node *) n;
11686 : }
11687 : | ALTER TEXT_P SEARCH CONFIGURATION any_name ALTER MAPPING REPLACE any_name any_with any_name
11688 : {
11689 18 : AlterTSConfigurationStmt *n = makeNode(AlterTSConfigurationStmt);
11690 :
11691 18 : n->kind = ALTER_TSCONFIG_REPLACE_DICT;
11692 18 : n->cfgname = $5;
11693 18 : n->tokentype = NIL;
11694 18 : n->dicts = list_make2($9,$11);
11695 18 : n->override = false;
11696 18 : n->replace = true;
11697 18 : $$ = (Node *) n;
11698 : }
11699 : | ALTER TEXT_P SEARCH CONFIGURATION any_name ALTER MAPPING FOR name_list REPLACE any_name any_with any_name
11700 : {
11701 0 : AlterTSConfigurationStmt *n = makeNode(AlterTSConfigurationStmt);
11702 :
11703 0 : n->kind = ALTER_TSCONFIG_REPLACE_DICT_FOR_TOKEN;
11704 0 : n->cfgname = $5;
11705 0 : n->tokentype = $9;
11706 0 : n->dicts = list_make2($11,$13);
11707 0 : n->override = false;
11708 0 : n->replace = true;
11709 0 : $$ = (Node *) n;
11710 : }
11711 : | ALTER TEXT_P SEARCH CONFIGURATION any_name DROP MAPPING FOR name_list
11712 : {
11713 18 : AlterTSConfigurationStmt *n = makeNode(AlterTSConfigurationStmt);
11714 :
11715 18 : n->kind = ALTER_TSCONFIG_DROP_MAPPING;
11716 18 : n->cfgname = $5;
11717 18 : n->tokentype = $9;
11718 18 : n->missing_ok = false;
11719 18 : $$ = (Node *) n;
11720 : }
11721 : | ALTER TEXT_P SEARCH CONFIGURATION any_name DROP MAPPING IF_P EXISTS FOR name_list
11722 : {
11723 12 : AlterTSConfigurationStmt *n = makeNode(AlterTSConfigurationStmt);
11724 :
11725 12 : n->kind = ALTER_TSCONFIG_DROP_MAPPING;
11726 12 : n->cfgname = $5;
11727 12 : n->tokentype = $11;
11728 12 : n->missing_ok = true;
11729 12 : $$ = (Node *) n;
11730 : }
11731 : ;
11732 :
11733 : /* Use this if TIME or ORDINALITY after WITH should be taken as an identifier */
11734 : any_with: WITH
11735 : | WITH_LA
11736 : ;
11737 :
11738 :
11739 : /*****************************************************************************
11740 : *
11741 : * Manipulate a conversion
11742 : *
11743 : * CREATE [DEFAULT] CONVERSION <conversion_name>
11744 : * FOR <encoding_name> TO <encoding_name> FROM <func_name>
11745 : *
11746 : *****************************************************************************/
11747 :
11748 : CreateConversionStmt:
11749 : CREATE opt_default CONVERSION_P any_name FOR Sconst
11750 : TO Sconst FROM any_name
11751 : {
11752 64 : CreateConversionStmt *n = makeNode(CreateConversionStmt);
11753 :
11754 64 : n->conversion_name = $4;
11755 64 : n->for_encoding_name = $6;
11756 64 : n->to_encoding_name = $8;
11757 64 : n->func_name = $10;
11758 64 : n->def = $2;
11759 64 : $$ = (Node *) n;
11760 : }
11761 : ;
11762 :
11763 : /*****************************************************************************
11764 : *
11765 : * QUERY:
11766 : * CLUSTER (options) [ <qualified_name> [ USING <index_name> ] ]
11767 : * CLUSTER [VERBOSE] [ <qualified_name> [ USING <index_name> ] ]
11768 : * CLUSTER [VERBOSE] <index_name> ON <qualified_name> (for pre-8.3)
11769 : *
11770 : *****************************************************************************/
11771 :
11772 : ClusterStmt:
11773 : CLUSTER '(' utility_option_list ')' qualified_name cluster_index_specification
11774 : {
11775 0 : ClusterStmt *n = makeNode(ClusterStmt);
11776 :
11777 0 : n->relation = $5;
11778 0 : n->indexname = $6;
11779 0 : n->params = $3;
11780 0 : $$ = (Node *) n;
11781 : }
11782 : | CLUSTER '(' utility_option_list ')'
11783 : {
11784 0 : ClusterStmt *n = makeNode(ClusterStmt);
11785 :
11786 0 : n->relation = NULL;
11787 0 : n->indexname = NULL;
11788 0 : n->params = $3;
11789 0 : $$ = (Node *) n;
11790 : }
11791 : /* unparenthesized VERBOSE kept for pre-14 compatibility */
11792 : | CLUSTER opt_verbose qualified_name cluster_index_specification
11793 : {
11794 190 : ClusterStmt *n = makeNode(ClusterStmt);
11795 :
11796 190 : n->relation = $3;
11797 190 : n->indexname = $4;
11798 190 : n->params = NIL;
11799 190 : if ($2)
11800 0 : n->params = lappend(n->params, makeDefElem("verbose", NULL, @2));
11801 190 : $$ = (Node *) n;
11802 : }
11803 : /* unparenthesized VERBOSE kept for pre-17 compatibility */
11804 : | CLUSTER opt_verbose
11805 : {
11806 28 : ClusterStmt *n = makeNode(ClusterStmt);
11807 :
11808 28 : n->relation = NULL;
11809 28 : n->indexname = NULL;
11810 28 : n->params = NIL;
11811 28 : if ($2)
11812 12 : n->params = lappend(n->params, makeDefElem("verbose", NULL, @2));
11813 28 : $$ = (Node *) n;
11814 : }
11815 : /* kept for pre-8.3 compatibility */
11816 : | CLUSTER opt_verbose name ON qualified_name
11817 : {
11818 18 : ClusterStmt *n = makeNode(ClusterStmt);
11819 :
11820 18 : n->relation = $5;
11821 18 : n->indexname = $3;
11822 18 : n->params = NIL;
11823 18 : if ($2)
11824 0 : n->params = lappend(n->params, makeDefElem("verbose", NULL, @2));
11825 18 : $$ = (Node *) n;
11826 : }
11827 : ;
11828 :
11829 : cluster_index_specification:
11830 156 : USING name { $$ = $2; }
11831 34 : | /*EMPTY*/ { $$ = NULL; }
11832 : ;
11833 :
11834 :
11835 : /*****************************************************************************
11836 : *
11837 : * QUERY:
11838 : * VACUUM
11839 : * ANALYZE
11840 : *
11841 : *****************************************************************************/
11842 :
11843 : VacuumStmt: VACUUM opt_full opt_freeze opt_verbose opt_analyze opt_vacuum_relation_list
11844 : {
11845 1142 : VacuumStmt *n = makeNode(VacuumStmt);
11846 :
11847 1142 : n->options = NIL;
11848 1142 : if ($2)
11849 130 : n->options = lappend(n->options,
11850 130 : makeDefElem("full", NULL, @2));
11851 1142 : if ($3)
11852 152 : n->options = lappend(n->options,
11853 152 : makeDefElem("freeze", NULL, @3));
11854 1142 : if ($4)
11855 18 : n->options = lappend(n->options,
11856 18 : makeDefElem("verbose", NULL, @4));
11857 1142 : if ($5)
11858 272 : n->options = lappend(n->options,
11859 272 : makeDefElem("analyze", NULL, @5));
11860 1142 : n->rels = $6;
11861 1142 : n->is_vacuumcmd = true;
11862 1142 : $$ = (Node *) n;
11863 : }
11864 : | VACUUM '(' utility_option_list ')' opt_vacuum_relation_list
11865 : {
11866 4964 : VacuumStmt *n = makeNode(VacuumStmt);
11867 :
11868 4964 : n->options = $3;
11869 4964 : n->rels = $5;
11870 4964 : n->is_vacuumcmd = true;
11871 4964 : $$ = (Node *) n;
11872 : }
11873 : ;
11874 :
11875 : AnalyzeStmt: analyze_keyword opt_verbose opt_vacuum_relation_list
11876 : {
11877 4376 : VacuumStmt *n = makeNode(VacuumStmt);
11878 :
11879 4376 : n->options = NIL;
11880 4376 : if ($2)
11881 0 : n->options = lappend(n->options,
11882 0 : makeDefElem("verbose", NULL, @2));
11883 4376 : n->rels = $3;
11884 4376 : n->is_vacuumcmd = false;
11885 4376 : $$ = (Node *) n;
11886 : }
11887 : | analyze_keyword '(' utility_option_list ')' opt_vacuum_relation_list
11888 : {
11889 186 : VacuumStmt *n = makeNode(VacuumStmt);
11890 :
11891 186 : n->options = $3;
11892 186 : n->rels = $5;
11893 186 : n->is_vacuumcmd = false;
11894 186 : $$ = (Node *) n;
11895 : }
11896 : ;
11897 :
11898 : utility_option_list:
11899 : utility_option_elem
11900 : {
11901 17712 : $$ = list_make1($1);
11902 : }
11903 : | utility_option_list ',' utility_option_elem
11904 : {
11905 8346 : $$ = lappend($1, $3);
11906 : }
11907 : ;
11908 :
11909 : analyze_keyword:
11910 : ANALYZE
11911 : | ANALYSE /* British */
11912 : ;
11913 :
11914 : utility_option_elem:
11915 : utility_option_name utility_option_arg
11916 : {
11917 26058 : $$ = makeDefElem($1, $2, @1);
11918 : }
11919 : ;
11920 :
11921 : utility_option_name:
11922 23718 : NonReservedWord { $$ = $1; }
11923 2198 : | analyze_keyword { $$ = "analyze"; }
11924 148 : | FORMAT_LA { $$ = "format"; }
11925 : ;
11926 :
11927 : utility_option_arg:
11928 14900 : opt_boolean_or_string { $$ = (Node *) makeString($1); }
11929 368 : | NumericOnly { $$ = (Node *) $1; }
11930 10790 : | /* EMPTY */ { $$ = NULL; }
11931 : ;
11932 :
11933 : opt_analyze:
11934 272 : analyze_keyword { $$ = true; }
11935 870 : | /*EMPTY*/ { $$ = false; }
11936 : ;
11937 :
11938 : opt_verbose:
11939 30 : VERBOSE { $$ = true; }
11940 8016 : | /*EMPTY*/ { $$ = false; }
11941 : ;
11942 :
11943 130 : opt_full: FULL { $$ = true; }
11944 1012 : | /*EMPTY*/ { $$ = false; }
11945 : ;
11946 :
11947 152 : opt_freeze: FREEZE { $$ = true; }
11948 990 : | /*EMPTY*/ { $$ = false; }
11949 : ;
11950 :
11951 : opt_name_list:
11952 2462 : '(' name_list ')' { $$ = $2; }
11953 12568 : | /*EMPTY*/ { $$ = NIL; }
11954 : ;
11955 :
11956 : vacuum_relation:
11957 : relation_expr opt_name_list
11958 : {
11959 10500 : $$ = (Node *) makeVacuumRelation($1, InvalidOid, $2);
11960 : }
11961 : ;
11962 :
11963 : vacuum_relation_list:
11964 : vacuum_relation
11965 10352 : { $$ = list_make1($1); }
11966 : | vacuum_relation_list ',' vacuum_relation
11967 148 : { $$ = lappend($1, $3); }
11968 : ;
11969 :
11970 : opt_vacuum_relation_list:
11971 10352 : vacuum_relation_list { $$ = $1; }
11972 316 : | /*EMPTY*/ { $$ = NIL; }
11973 : ;
11974 :
11975 :
11976 : /*****************************************************************************
11977 : *
11978 : * QUERY:
11979 : * EXPLAIN [ANALYZE] [VERBOSE] query
11980 : * EXPLAIN ( options ) query
11981 : *
11982 : *****************************************************************************/
11983 :
11984 : ExplainStmt:
11985 : EXPLAIN ExplainableStmt
11986 : {
11987 7602 : ExplainStmt *n = makeNode(ExplainStmt);
11988 :
11989 7602 : n->query = $2;
11990 7602 : n->options = NIL;
11991 7602 : $$ = (Node *) n;
11992 : }
11993 : | EXPLAIN analyze_keyword opt_verbose ExplainableStmt
11994 : {
11995 2292 : ExplainStmt *n = makeNode(ExplainStmt);
11996 :
11997 2292 : n->query = $4;
11998 2292 : n->options = list_make1(makeDefElem("analyze", NULL, @2));
11999 2292 : if ($3)
12000 0 : n->options = lappend(n->options,
12001 0 : makeDefElem("verbose", NULL, @3));
12002 2292 : $$ = (Node *) n;
12003 : }
12004 : | EXPLAIN VERBOSE ExplainableStmt
12005 : {
12006 0 : ExplainStmt *n = makeNode(ExplainStmt);
12007 :
12008 0 : n->query = $3;
12009 0 : n->options = list_make1(makeDefElem("verbose", NULL, @2));
12010 0 : $$ = (Node *) n;
12011 : }
12012 : | EXPLAIN '(' utility_option_list ')' ExplainableStmt
12013 : {
12014 12406 : ExplainStmt *n = makeNode(ExplainStmt);
12015 :
12016 12406 : n->query = $5;
12017 12406 : n->options = $3;
12018 12406 : $$ = (Node *) n;
12019 : }
12020 : ;
12021 :
12022 : ExplainableStmt:
12023 : SelectStmt
12024 : | InsertStmt
12025 : | UpdateStmt
12026 : | DeleteStmt
12027 : | MergeStmt
12028 : | DeclareCursorStmt
12029 : | CreateAsStmt
12030 : | CreateMatViewStmt
12031 : | RefreshMatViewStmt
12032 : | ExecuteStmt /* by default all are $$=$1 */
12033 : ;
12034 :
12035 : /*****************************************************************************
12036 : *
12037 : * QUERY:
12038 : * PREPARE <plan_name> [(args, ...)] AS <query>
12039 : *
12040 : *****************************************************************************/
12041 :
12042 : PrepareStmt: PREPARE name prep_type_clause AS PreparableStmt
12043 : {
12044 1720 : PrepareStmt *n = makeNode(PrepareStmt);
12045 :
12046 1720 : n->name = $2;
12047 1720 : n->argtypes = $3;
12048 1720 : n->query = $5;
12049 1720 : $$ = (Node *) n;
12050 : }
12051 : ;
12052 :
12053 1418 : prep_type_clause: '(' type_list ')' { $$ = $2; }
12054 320 : | /* EMPTY */ { $$ = NIL; }
12055 : ;
12056 :
12057 : PreparableStmt:
12058 : SelectStmt
12059 : | InsertStmt
12060 : | UpdateStmt
12061 : | DeleteStmt
12062 : | MergeStmt /* by default all are $$=$1 */
12063 : ;
12064 :
12065 : /*****************************************************************************
12066 : *
12067 : * EXECUTE <plan_name> [(params, ...)]
12068 : * CREATE TABLE <name> AS EXECUTE <plan_name> [(params, ...)]
12069 : *
12070 : *****************************************************************************/
12071 :
12072 : ExecuteStmt: EXECUTE name execute_param_clause
12073 : {
12074 15338 : ExecuteStmt *n = makeNode(ExecuteStmt);
12075 :
12076 15338 : n->name = $2;
12077 15338 : n->params = $3;
12078 15338 : $$ = (Node *) n;
12079 : }
12080 : | CREATE OptTemp TABLE create_as_target AS
12081 : EXECUTE name execute_param_clause opt_with_data
12082 : {
12083 76 : CreateTableAsStmt *ctas = makeNode(CreateTableAsStmt);
12084 76 : ExecuteStmt *n = makeNode(ExecuteStmt);
12085 :
12086 76 : n->name = $7;
12087 76 : n->params = $8;
12088 76 : ctas->query = (Node *) n;
12089 76 : ctas->into = $4;
12090 76 : ctas->objtype = OBJECT_TABLE;
12091 76 : ctas->is_select_into = false;
12092 76 : ctas->if_not_exists = false;
12093 : /* cram additional flags into the IntoClause */
12094 76 : $4->rel->relpersistence = $2;
12095 76 : $4->skipData = !($9);
12096 76 : $$ = (Node *) ctas;
12097 : }
12098 : | CREATE OptTemp TABLE IF_P NOT EXISTS create_as_target AS
12099 : EXECUTE name execute_param_clause opt_with_data
12100 : {
12101 12 : CreateTableAsStmt *ctas = makeNode(CreateTableAsStmt);
12102 12 : ExecuteStmt *n = makeNode(ExecuteStmt);
12103 :
12104 12 : n->name = $10;
12105 12 : n->params = $11;
12106 12 : ctas->query = (Node *) n;
12107 12 : ctas->into = $7;
12108 12 : ctas->objtype = OBJECT_TABLE;
12109 12 : ctas->is_select_into = false;
12110 12 : ctas->if_not_exists = true;
12111 : /* cram additional flags into the IntoClause */
12112 12 : $7->rel->relpersistence = $2;
12113 12 : $7->skipData = !($12);
12114 12 : $$ = (Node *) ctas;
12115 : }
12116 : ;
12117 :
12118 14284 : execute_param_clause: '(' expr_list ')' { $$ = $2; }
12119 1142 : | /* EMPTY */ { $$ = NIL; }
12120 : ;
12121 :
12122 : /*****************************************************************************
12123 : *
12124 : * QUERY:
12125 : * DEALLOCATE [PREPARE] <plan_name>
12126 : *
12127 : *****************************************************************************/
12128 :
12129 : DeallocateStmt: DEALLOCATE name
12130 : {
12131 3966 : DeallocateStmt *n = makeNode(DeallocateStmt);
12132 :
12133 3966 : n->name = $2;
12134 3966 : n->isall = false;
12135 3966 : n->location = @2;
12136 3966 : $$ = (Node *) n;
12137 : }
12138 : | DEALLOCATE PREPARE name
12139 : {
12140 20 : DeallocateStmt *n = makeNode(DeallocateStmt);
12141 :
12142 20 : n->name = $3;
12143 20 : n->isall = false;
12144 20 : n->location = @3;
12145 20 : $$ = (Node *) n;
12146 : }
12147 : | DEALLOCATE ALL
12148 : {
12149 48 : DeallocateStmt *n = makeNode(DeallocateStmt);
12150 :
12151 48 : n->name = NULL;
12152 48 : n->isall = true;
12153 48 : n->location = -1;
12154 48 : $$ = (Node *) n;
12155 : }
12156 : | DEALLOCATE PREPARE ALL
12157 : {
12158 2 : DeallocateStmt *n = makeNode(DeallocateStmt);
12159 :
12160 2 : n->name = NULL;
12161 2 : n->isall = true;
12162 2 : n->location = -1;
12163 2 : $$ = (Node *) n;
12164 : }
12165 : ;
12166 :
12167 : /*****************************************************************************
12168 : *
12169 : * QUERY:
12170 : * INSERT STATEMENTS
12171 : *
12172 : *****************************************************************************/
12173 :
12174 : InsertStmt:
12175 : opt_with_clause INSERT INTO insert_target insert_rest
12176 : opt_on_conflict returning_clause
12177 : {
12178 72904 : $5->relation = $4;
12179 72904 : $5->onConflictClause = $6;
12180 72904 : $5->returningList = $7;
12181 72904 : $5->withClause = $1;
12182 72904 : $5->stmt_location = @$;
12183 72904 : $$ = (Node *) $5;
12184 : }
12185 : ;
12186 :
12187 : /*
12188 : * Can't easily make AS optional here, because VALUES in insert_rest would
12189 : * have a shift/reduce conflict with VALUES as an optional alias. We could
12190 : * easily allow unreserved_keywords as optional aliases, but that'd be an odd
12191 : * divergence from other places. So just require AS for now.
12192 : */
12193 : insert_target:
12194 : qualified_name
12195 : {
12196 72772 : $$ = $1;
12197 : }
12198 : | qualified_name AS ColId
12199 : {
12200 132 : $1->alias = makeAlias($3, NIL);
12201 132 : $$ = $1;
12202 : }
12203 : ;
12204 :
12205 : insert_rest:
12206 : SelectStmt
12207 : {
12208 48140 : $$ = makeNode(InsertStmt);
12209 48140 : $$->cols = NIL;
12210 48140 : $$->selectStmt = $1;
12211 : }
12212 : | OVERRIDING override_kind VALUE_P SelectStmt
12213 : {
12214 96 : $$ = makeNode(InsertStmt);
12215 96 : $$->cols = NIL;
12216 96 : $$->override = $2;
12217 96 : $$->selectStmt = $4;
12218 : }
12219 : | '(' insert_column_list ')' SelectStmt
12220 : {
12221 13884 : $$ = makeNode(InsertStmt);
12222 13884 : $$->cols = $2;
12223 13884 : $$->selectStmt = $4;
12224 : }
12225 : | '(' insert_column_list ')' OVERRIDING override_kind VALUE_P SelectStmt
12226 : {
12227 0 : $$ = makeNode(InsertStmt);
12228 0 : $$->cols = $2;
12229 0 : $$->override = $5;
12230 0 : $$->selectStmt = $7;
12231 : }
12232 : | DEFAULT VALUES
12233 : {
12234 10784 : $$ = makeNode(InsertStmt);
12235 10784 : $$->cols = NIL;
12236 10784 : $$->selectStmt = NULL;
12237 : }
12238 : ;
12239 :
12240 : override_kind:
12241 66 : USER { $$ = OVERRIDING_USER_VALUE; }
12242 60 : | SYSTEM_P { $$ = OVERRIDING_SYSTEM_VALUE; }
12243 : ;
12244 :
12245 : insert_column_list:
12246 : insert_column_item
12247 14182 : { $$ = list_make1($1); }
12248 : | insert_column_list ',' insert_column_item
12249 15600 : { $$ = lappend($1, $3); }
12250 : ;
12251 :
12252 : insert_column_item:
12253 : ColId opt_indirection
12254 : {
12255 29782 : $$ = makeNode(ResTarget);
12256 29782 : $$->name = $1;
12257 29782 : $$->indirection = check_indirection($2, yyscanner);
12258 29782 : $$->val = NULL;
12259 29782 : $$->location = @1;
12260 : }
12261 : ;
12262 :
12263 : opt_on_conflict:
12264 : ON CONFLICT opt_conf_expr DO UPDATE SET set_clause_list where_clause
12265 : {
12266 1294 : $$ = makeNode(OnConflictClause);
12267 1294 : $$->action = ONCONFLICT_UPDATE;
12268 1294 : $$->infer = $3;
12269 1294 : $$->targetList = $7;
12270 1294 : $$->whereClause = $8;
12271 1294 : $$->location = @1;
12272 : }
12273 : |
12274 : ON CONFLICT opt_conf_expr DO NOTHING
12275 : {
12276 550 : $$ = makeNode(OnConflictClause);
12277 550 : $$->action = ONCONFLICT_NOTHING;
12278 550 : $$->infer = $3;
12279 550 : $$->targetList = NIL;
12280 550 : $$->whereClause = NULL;
12281 550 : $$->location = @1;
12282 : }
12283 : | /*EMPTY*/
12284 : {
12285 71060 : $$ = NULL;
12286 : }
12287 : ;
12288 :
12289 : opt_conf_expr:
12290 : '(' index_params ')' where_clause
12291 : {
12292 1418 : $$ = makeNode(InferClause);
12293 1418 : $$->indexElems = $2;
12294 1418 : $$->whereClause = $4;
12295 1418 : $$->conname = NULL;
12296 1418 : $$->location = @1;
12297 : }
12298 : |
12299 : ON CONSTRAINT name
12300 : {
12301 192 : $$ = makeNode(InferClause);
12302 192 : $$->indexElems = NIL;
12303 192 : $$->whereClause = NULL;
12304 192 : $$->conname = $3;
12305 192 : $$->location = @1;
12306 : }
12307 : | /*EMPTY*/
12308 : {
12309 234 : $$ = NULL;
12310 : }
12311 : ;
12312 :
12313 : returning_clause:
12314 2698 : RETURNING target_list { $$ = $2; }
12315 89914 : | /* EMPTY */ { $$ = NIL; }
12316 : ;
12317 :
12318 :
12319 : /*****************************************************************************
12320 : *
12321 : * QUERY:
12322 : * DELETE STATEMENTS
12323 : *
12324 : *****************************************************************************/
12325 :
12326 : DeleteStmt: opt_with_clause DELETE_P FROM relation_expr_opt_alias
12327 : using_clause where_or_current_clause returning_clause
12328 : {
12329 4564 : DeleteStmt *n = makeNode(DeleteStmt);
12330 :
12331 4564 : n->relation = $4;
12332 4564 : n->usingClause = $5;
12333 4564 : n->whereClause = $6;
12334 4564 : n->returningList = $7;
12335 4564 : n->withClause = $1;
12336 4564 : n->stmt_location = @$;
12337 4564 : $$ = (Node *) n;
12338 : }
12339 : ;
12340 :
12341 : using_clause:
12342 108 : USING from_list { $$ = $2; }
12343 4456 : | /*EMPTY*/ { $$ = NIL; }
12344 : ;
12345 :
12346 :
12347 : /*****************************************************************************
12348 : *
12349 : * QUERY:
12350 : * LOCK TABLE
12351 : *
12352 : *****************************************************************************/
12353 :
12354 : LockStmt: LOCK_P opt_table relation_expr_list opt_lock opt_nowait
12355 : {
12356 1084 : LockStmt *n = makeNode(LockStmt);
12357 :
12358 1084 : n->relations = $3;
12359 1084 : n->mode = $4;
12360 1084 : n->nowait = $5;
12361 1084 : $$ = (Node *) n;
12362 : }
12363 : ;
12364 :
12365 992 : opt_lock: IN_P lock_type MODE { $$ = $2; }
12366 92 : | /*EMPTY*/ { $$ = AccessExclusiveLock; }
12367 : ;
12368 :
12369 502 : lock_type: ACCESS SHARE { $$ = AccessShareLock; }
12370 14 : | ROW SHARE { $$ = RowShareLock; }
12371 88 : | ROW EXCLUSIVE { $$ = RowExclusiveLock; }
12372 66 : | SHARE UPDATE EXCLUSIVE { $$ = ShareUpdateExclusiveLock; }
12373 80 : | SHARE { $$ = ShareLock; }
12374 14 : | SHARE ROW EXCLUSIVE { $$ = ShareRowExclusiveLock; }
12375 102 : | EXCLUSIVE { $$ = ExclusiveLock; }
12376 126 : | ACCESS EXCLUSIVE { $$ = AccessExclusiveLock; }
12377 : ;
12378 :
12379 286 : opt_nowait: NOWAIT { $$ = true; }
12380 828 : | /*EMPTY*/ { $$ = false; }
12381 : ;
12382 :
12383 : opt_nowait_or_skip:
12384 50 : NOWAIT { $$ = LockWaitError; }
12385 190 : | SKIP LOCKED { $$ = LockWaitSkip; }
12386 4982 : | /*EMPTY*/ { $$ = LockWaitBlock; }
12387 : ;
12388 :
12389 :
12390 : /*****************************************************************************
12391 : *
12392 : * QUERY:
12393 : * UpdateStmt (UPDATE)
12394 : *
12395 : *****************************************************************************/
12396 :
12397 : UpdateStmt: opt_with_clause UPDATE relation_expr_opt_alias
12398 : SET set_clause_list
12399 : from_clause
12400 : where_or_current_clause
12401 : returning_clause
12402 : {
12403 13164 : UpdateStmt *n = makeNode(UpdateStmt);
12404 :
12405 13164 : n->relation = $3;
12406 13164 : n->targetList = $5;
12407 13164 : n->fromClause = $6;
12408 13164 : n->whereClause = $7;
12409 13164 : n->returningList = $8;
12410 13164 : n->withClause = $1;
12411 13164 : n->stmt_location = @$;
12412 13164 : $$ = (Node *) n;
12413 : }
12414 : ;
12415 :
12416 : set_clause_list:
12417 16002 : set_clause { $$ = $1; }
12418 3638 : | set_clause_list ',' set_clause { $$ = list_concat($1,$3); }
12419 : ;
12420 :
12421 : set_clause:
12422 : set_target '=' a_expr
12423 : {
12424 19456 : $1->val = (Node *) $3;
12425 19456 : $$ = list_make1($1);
12426 : }
12427 : | '(' set_target_list ')' '=' a_expr
12428 : {
12429 184 : int ncolumns = list_length($2);
12430 184 : int i = 1;
12431 : ListCell *col_cell;
12432 :
12433 : /* Create a MultiAssignRef source for each target */
12434 568 : foreach(col_cell, $2)
12435 : {
12436 384 : ResTarget *res_col = (ResTarget *) lfirst(col_cell);
12437 384 : MultiAssignRef *r = makeNode(MultiAssignRef);
12438 :
12439 384 : r->source = (Node *) $5;
12440 384 : r->colno = i;
12441 384 : r->ncolumns = ncolumns;
12442 384 : res_col->val = (Node *) r;
12443 384 : i++;
12444 : }
12445 :
12446 184 : $$ = $2;
12447 : }
12448 : ;
12449 :
12450 : set_target:
12451 : ColId opt_indirection
12452 : {
12453 19846 : $$ = makeNode(ResTarget);
12454 19846 : $$->name = $1;
12455 19846 : $$->indirection = check_indirection($2, yyscanner);
12456 19846 : $$->val = NULL; /* upper production sets this */
12457 19846 : $$->location = @1;
12458 : }
12459 : ;
12460 :
12461 : set_target_list:
12462 190 : set_target { $$ = list_make1($1); }
12463 200 : | set_target_list ',' set_target { $$ = lappend($1,$3); }
12464 : ;
12465 :
12466 :
12467 : /*****************************************************************************
12468 : *
12469 : * QUERY:
12470 : * MERGE
12471 : *
12472 : *****************************************************************************/
12473 :
12474 : MergeStmt:
12475 : opt_with_clause MERGE INTO relation_expr_opt_alias
12476 : USING table_ref
12477 : ON a_expr
12478 : merge_when_list
12479 : returning_clause
12480 : {
12481 1980 : MergeStmt *m = makeNode(MergeStmt);
12482 :
12483 1980 : m->withClause = $1;
12484 1980 : m->relation = $4;
12485 1980 : m->sourceRelation = $6;
12486 1980 : m->joinCondition = $8;
12487 1980 : m->mergeWhenClauses = $9;
12488 1980 : m->returningList = $10;
12489 1980 : m->stmt_location = @$;
12490 :
12491 1980 : $$ = (Node *) m;
12492 : }
12493 : ;
12494 :
12495 : merge_when_list:
12496 1980 : merge_when_clause { $$ = list_make1($1); }
12497 1152 : | merge_when_list merge_when_clause { $$ = lappend($1,$2); }
12498 : ;
12499 :
12500 : /*
12501 : * A WHEN clause may be WHEN MATCHED, WHEN NOT MATCHED BY SOURCE, or WHEN NOT
12502 : * MATCHED [BY TARGET]. The first two cases match target tuples, and support
12503 : * UPDATE/DELETE/DO NOTHING actions. The third case does not match target
12504 : * tuples, and only supports INSERT/DO NOTHING actions.
12505 : */
12506 : merge_when_clause:
12507 : merge_when_tgt_matched opt_merge_when_condition THEN merge_update
12508 : {
12509 1544 : $4->matchKind = $1;
12510 1544 : $4->condition = $2;
12511 :
12512 1544 : $$ = (Node *) $4;
12513 : }
12514 : | merge_when_tgt_matched opt_merge_when_condition THEN merge_delete
12515 : {
12516 482 : $4->matchKind = $1;
12517 482 : $4->condition = $2;
12518 :
12519 482 : $$ = (Node *) $4;
12520 : }
12521 : | merge_when_tgt_not_matched opt_merge_when_condition THEN merge_insert
12522 : {
12523 1028 : $4->matchKind = $1;
12524 1028 : $4->condition = $2;
12525 :
12526 1028 : $$ = (Node *) $4;
12527 : }
12528 : | merge_when_tgt_matched opt_merge_when_condition THEN DO NOTHING
12529 : {
12530 58 : MergeWhenClause *m = makeNode(MergeWhenClause);
12531 :
12532 58 : m->matchKind = $1;
12533 58 : m->commandType = CMD_NOTHING;
12534 58 : m->condition = $2;
12535 :
12536 58 : $$ = (Node *) m;
12537 : }
12538 : | merge_when_tgt_not_matched opt_merge_when_condition THEN DO NOTHING
12539 : {
12540 20 : MergeWhenClause *m = makeNode(MergeWhenClause);
12541 :
12542 20 : m->matchKind = $1;
12543 20 : m->commandType = CMD_NOTHING;
12544 20 : m->condition = $2;
12545 :
12546 20 : $$ = (Node *) m;
12547 : }
12548 : ;
12549 :
12550 : merge_when_tgt_matched:
12551 1922 : WHEN MATCHED { $$ = MERGE_WHEN_MATCHED; }
12552 180 : | WHEN NOT MATCHED BY SOURCE { $$ = MERGE_WHEN_NOT_MATCHED_BY_SOURCE; }
12553 : ;
12554 :
12555 : merge_when_tgt_not_matched:
12556 1054 : WHEN NOT MATCHED { $$ = MERGE_WHEN_NOT_MATCHED_BY_TARGET; }
12557 18 : | WHEN NOT MATCHED BY TARGET { $$ = MERGE_WHEN_NOT_MATCHED_BY_TARGET; }
12558 : ;
12559 :
12560 : opt_merge_when_condition:
12561 808 : AND a_expr { $$ = $2; }
12562 2366 : | { $$ = NULL; }
12563 : ;
12564 :
12565 : merge_update:
12566 : UPDATE SET set_clause_list
12567 : {
12568 1544 : MergeWhenClause *n = makeNode(MergeWhenClause);
12569 1544 : n->commandType = CMD_UPDATE;
12570 1544 : n->override = OVERRIDING_NOT_SET;
12571 1544 : n->targetList = $3;
12572 1544 : n->values = NIL;
12573 :
12574 1544 : $$ = n;
12575 : }
12576 : ;
12577 :
12578 : merge_delete:
12579 : DELETE_P
12580 : {
12581 482 : MergeWhenClause *n = makeNode(MergeWhenClause);
12582 482 : n->commandType = CMD_DELETE;
12583 482 : n->override = OVERRIDING_NOT_SET;
12584 482 : n->targetList = NIL;
12585 482 : n->values = NIL;
12586 :
12587 482 : $$ = n;
12588 : }
12589 : ;
12590 :
12591 : merge_insert:
12592 : INSERT merge_values_clause
12593 : {
12594 694 : MergeWhenClause *n = makeNode(MergeWhenClause);
12595 694 : n->commandType = CMD_INSERT;
12596 694 : n->override = OVERRIDING_NOT_SET;
12597 694 : n->targetList = NIL;
12598 694 : n->values = $2;
12599 694 : $$ = n;
12600 : }
12601 : | INSERT OVERRIDING override_kind VALUE_P merge_values_clause
12602 : {
12603 0 : MergeWhenClause *n = makeNode(MergeWhenClause);
12604 0 : n->commandType = CMD_INSERT;
12605 0 : n->override = $3;
12606 0 : n->targetList = NIL;
12607 0 : n->values = $5;
12608 0 : $$ = n;
12609 : }
12610 : | INSERT '(' insert_column_list ')' merge_values_clause
12611 : {
12612 268 : MergeWhenClause *n = makeNode(MergeWhenClause);
12613 268 : n->commandType = CMD_INSERT;
12614 268 : n->override = OVERRIDING_NOT_SET;
12615 268 : n->targetList = $3;
12616 268 : n->values = $5;
12617 268 : $$ = n;
12618 : }
12619 : | INSERT '(' insert_column_list ')' OVERRIDING override_kind VALUE_P merge_values_clause
12620 : {
12621 30 : MergeWhenClause *n = makeNode(MergeWhenClause);
12622 30 : n->commandType = CMD_INSERT;
12623 30 : n->override = $6;
12624 30 : n->targetList = $3;
12625 30 : n->values = $8;
12626 30 : $$ = n;
12627 : }
12628 : | INSERT DEFAULT VALUES
12629 : {
12630 36 : MergeWhenClause *n = makeNode(MergeWhenClause);
12631 36 : n->commandType = CMD_INSERT;
12632 36 : n->override = OVERRIDING_NOT_SET;
12633 36 : n->targetList = NIL;
12634 36 : n->values = NIL;
12635 36 : $$ = n;
12636 : }
12637 : ;
12638 :
12639 : merge_values_clause:
12640 : VALUES '(' expr_list ')'
12641 : {
12642 992 : $$ = $3;
12643 : }
12644 : ;
12645 :
12646 : /*****************************************************************************
12647 : *
12648 : * QUERY:
12649 : * CURSOR STATEMENTS
12650 : *
12651 : *****************************************************************************/
12652 : DeclareCursorStmt: DECLARE cursor_name cursor_options CURSOR opt_hold FOR SelectStmt
12653 : {
12654 2800 : DeclareCursorStmt *n = makeNode(DeclareCursorStmt);
12655 :
12656 2800 : n->portalname = $2;
12657 : /* currently we always set FAST_PLAN option */
12658 2800 : n->options = $3 | $5 | CURSOR_OPT_FAST_PLAN;
12659 2800 : n->query = $7;
12660 2800 : $$ = (Node *) n;
12661 : }
12662 : ;
12663 :
12664 10980 : cursor_name: name { $$ = $1; }
12665 : ;
12666 :
12667 2800 : cursor_options: /*EMPTY*/ { $$ = 0; }
12668 24 : | cursor_options NO SCROLL { $$ = $1 | CURSOR_OPT_NO_SCROLL; }
12669 240 : | cursor_options SCROLL { $$ = $1 | CURSOR_OPT_SCROLL; }
12670 14 : | cursor_options BINARY { $$ = $1 | CURSOR_OPT_BINARY; }
12671 0 : | cursor_options ASENSITIVE { $$ = $1 | CURSOR_OPT_ASENSITIVE; }
12672 6 : | cursor_options INSENSITIVE { $$ = $1 | CURSOR_OPT_INSENSITIVE; }
12673 : ;
12674 :
12675 2702 : opt_hold: /* EMPTY */ { $$ = 0; }
12676 92 : | WITH HOLD { $$ = CURSOR_OPT_HOLD; }
12677 6 : | WITHOUT HOLD { $$ = 0; }
12678 : ;
12679 :
12680 : /*****************************************************************************
12681 : *
12682 : * QUERY:
12683 : * SELECT STATEMENTS
12684 : *
12685 : *****************************************************************************/
12686 :
12687 : /* A complete SELECT statement looks like this.
12688 : *
12689 : * The rule returns either a single SelectStmt node or a tree of them,
12690 : * representing a set-operation tree.
12691 : *
12692 : * There is an ambiguity when a sub-SELECT is within an a_expr and there
12693 : * are excess parentheses: do the parentheses belong to the sub-SELECT or
12694 : * to the surrounding a_expr? We don't really care, but bison wants to know.
12695 : * To resolve the ambiguity, we are careful to define the grammar so that
12696 : * the decision is staved off as long as possible: as long as we can keep
12697 : * absorbing parentheses into the sub-SELECT, we will do so, and only when
12698 : * it's no longer possible to do that will we decide that parens belong to
12699 : * the expression. For example, in "SELECT (((SELECT 2)) + 3)" the extra
12700 : * parentheses are treated as part of the sub-select. The necessity of doing
12701 : * it that way is shown by "SELECT (((SELECT 2)) UNION SELECT 2)". Had we
12702 : * parsed "((SELECT 2))" as an a_expr, it'd be too late to go back to the
12703 : * SELECT viewpoint when we see the UNION.
12704 : *
12705 : * This approach is implemented by defining a nonterminal select_with_parens,
12706 : * which represents a SELECT with at least one outer layer of parentheses,
12707 : * and being careful to use select_with_parens, never '(' SelectStmt ')',
12708 : * in the expression grammar. We will then have shift-reduce conflicts
12709 : * which we can resolve in favor of always treating '(' <select> ')' as
12710 : * a select_with_parens. To resolve the conflicts, the productions that
12711 : * conflict with the select_with_parens productions are manually given
12712 : * precedences lower than the precedence of ')', thereby ensuring that we
12713 : * shift ')' (and then reduce to select_with_parens) rather than trying to
12714 : * reduce the inner <select> nonterminal to something else. We use UMINUS
12715 : * precedence for this, which is a fairly arbitrary choice.
12716 : *
12717 : * To be able to define select_with_parens itself without ambiguity, we need
12718 : * a nonterminal select_no_parens that represents a SELECT structure with no
12719 : * outermost parentheses. This is a little bit tedious, but it works.
12720 : *
12721 : * In non-expression contexts, we use SelectStmt which can represent a SELECT
12722 : * with or without outer parentheses.
12723 : */
12724 :
12725 : SelectStmt: select_no_parens %prec UMINUS
12726 : | select_with_parens %prec UMINUS
12727 : ;
12728 :
12729 : select_with_parens:
12730 : '(' select_no_parens ')'
12731 : {
12732 55608 : SelectStmt *n = (SelectStmt *) $2;
12733 :
12734 : /*
12735 : * As SelectStmt's location starts at the SELECT keyword,
12736 : * we need to track the length of the SelectStmt within
12737 : * parentheses to be able to extract the relevant part
12738 : * of the query. Without this, the RawStmt's length would
12739 : * be used and would include the closing parenthesis.
12740 : */
12741 55608 : n->stmt_len = @3 - @2;
12742 55608 : $$ = $2;
12743 : }
12744 150 : | '(' select_with_parens ')' { $$ = $2; }
12745 : ;
12746 :
12747 : /*
12748 : * This rule parses the equivalent of the standard's <query expression>.
12749 : * The duplicative productions are annoying, but hard to get rid of without
12750 : * creating shift/reduce conflicts.
12751 : *
12752 : * The locking clause (FOR UPDATE etc) may be before or after LIMIT/OFFSET.
12753 : * In <=7.2.X, LIMIT/OFFSET had to be after FOR UPDATE
12754 : * We now support both orderings, but prefer LIMIT/OFFSET before the locking
12755 : * clause.
12756 : * 2002-08-28 bjm
12757 : */
12758 : select_no_parens:
12759 412838 : simple_select { $$ = $1; }
12760 : | select_clause sort_clause
12761 : {
12762 59880 : insertSelectOptions((SelectStmt *) $1, $2, NIL,
12763 : NULL, NULL,
12764 : yyscanner);
12765 59880 : $$ = $1;
12766 : }
12767 : | select_clause opt_sort_clause for_locking_clause opt_select_limit
12768 : {
12769 4778 : insertSelectOptions((SelectStmt *) $1, $2, $3,
12770 4778 : $4,
12771 : NULL,
12772 : yyscanner);
12773 4778 : $$ = $1;
12774 : }
12775 : | select_clause opt_sort_clause select_limit opt_for_locking_clause
12776 : {
12777 4662 : insertSelectOptions((SelectStmt *) $1, $2, $4,
12778 4662 : $3,
12779 : NULL,
12780 : yyscanner);
12781 4650 : $$ = $1;
12782 : }
12783 : | with_clause select_clause
12784 : {
12785 1946 : insertSelectOptions((SelectStmt *) $2, NULL, NIL,
12786 : NULL,
12787 1946 : $1,
12788 : yyscanner);
12789 1946 : $$ = $2;
12790 : }
12791 : | with_clause select_clause sort_clause
12792 : {
12793 472 : insertSelectOptions((SelectStmt *) $2, $3, NIL,
12794 : NULL,
12795 472 : $1,
12796 : yyscanner);
12797 472 : $$ = $2;
12798 : }
12799 : | with_clause select_clause opt_sort_clause for_locking_clause opt_select_limit
12800 : {
12801 6 : insertSelectOptions((SelectStmt *) $2, $3, $4,
12802 6 : $5,
12803 6 : $1,
12804 : yyscanner);
12805 6 : $$ = $2;
12806 : }
12807 : | with_clause select_clause opt_sort_clause select_limit opt_for_locking_clause
12808 : {
12809 64 : insertSelectOptions((SelectStmt *) $2, $3, $5,
12810 64 : $4,
12811 64 : $1,
12812 : yyscanner);
12813 64 : $$ = $2;
12814 : }
12815 : ;
12816 :
12817 : select_clause:
12818 100942 : simple_select { $$ = $1; }
12819 486 : | select_with_parens { $$ = $1; }
12820 : ;
12821 :
12822 : /*
12823 : * This rule parses SELECT statements that can appear within set operations,
12824 : * including UNION, INTERSECT and EXCEPT. '(' and ')' can be used to specify
12825 : * the ordering of the set operations. Without '(' and ')' we want the
12826 : * operations to be ordered per the precedence specs at the head of this file.
12827 : *
12828 : * As with select_no_parens, simple_select cannot have outer parentheses,
12829 : * but can have parenthesized subclauses.
12830 : *
12831 : * It might appear that we could fold the first two alternatives into one
12832 : * by using opt_distinct_clause. However, that causes a shift/reduce conflict
12833 : * against INSERT ... SELECT ... ON CONFLICT. We avoid the ambiguity by
12834 : * requiring SELECT DISTINCT [ON] to be followed by a non-empty target_list.
12835 : *
12836 : * Note that sort clauses cannot be included at this level --- SQL requires
12837 : * SELECT foo UNION SELECT bar ORDER BY baz
12838 : * to be parsed as
12839 : * (SELECT foo UNION SELECT bar) ORDER BY baz
12840 : * not
12841 : * SELECT foo UNION (SELECT bar ORDER BY baz)
12842 : * Likewise for WITH, FOR UPDATE and LIMIT. Therefore, those clauses are
12843 : * described as part of the select_no_parens production, not simple_select.
12844 : * This does not limit functionality, because you can reintroduce these
12845 : * clauses inside parentheses.
12846 : *
12847 : * NOTE: only the leftmost component SelectStmt should have INTO.
12848 : * However, this is not checked by the grammar; parse analysis must check it.
12849 : */
12850 : simple_select:
12851 : SELECT opt_all_clause opt_target_list
12852 : into_clause from_clause where_clause
12853 : group_clause having_clause window_clause
12854 : {
12855 434556 : SelectStmt *n = makeNode(SelectStmt);
12856 :
12857 434556 : n->targetList = $3;
12858 434556 : n->intoClause = $4;
12859 434556 : n->fromClause = $5;
12860 434556 : n->whereClause = $6;
12861 434556 : n->groupClause = ($7)->list;
12862 434556 : n->groupDistinct = ($7)->distinct;
12863 434556 : n->havingClause = $8;
12864 434556 : n->windowClause = $9;
12865 434556 : n->stmt_location = @1;
12866 434556 : $$ = (Node *) n;
12867 : }
12868 : | SELECT distinct_clause target_list
12869 : into_clause from_clause where_clause
12870 : group_clause having_clause window_clause
12871 : {
12872 3200 : SelectStmt *n = makeNode(SelectStmt);
12873 :
12874 3200 : n->distinctClause = $2;
12875 3200 : n->targetList = $3;
12876 3200 : n->intoClause = $4;
12877 3200 : n->fromClause = $5;
12878 3200 : n->whereClause = $6;
12879 3200 : n->groupClause = ($7)->list;
12880 3200 : n->groupDistinct = ($7)->distinct;
12881 3200 : n->havingClause = $8;
12882 3200 : n->windowClause = $9;
12883 3200 : n->stmt_location = @1;
12884 3200 : $$ = (Node *) n;
12885 : }
12886 60966 : | values_clause { $$ = $1; }
12887 : | TABLE relation_expr
12888 : {
12889 : /* same as SELECT * FROM relation_expr */
12890 254 : ColumnRef *cr = makeNode(ColumnRef);
12891 254 : ResTarget *rt = makeNode(ResTarget);
12892 254 : SelectStmt *n = makeNode(SelectStmt);
12893 :
12894 254 : cr->fields = list_make1(makeNode(A_Star));
12895 254 : cr->location = -1;
12896 :
12897 254 : rt->name = NULL;
12898 254 : rt->indirection = NIL;
12899 254 : rt->val = (Node *) cr;
12900 254 : rt->location = -1;
12901 :
12902 254 : n->targetList = list_make1(rt);
12903 254 : n->fromClause = list_make1($2);
12904 254 : n->stmt_location = @1;
12905 254 : $$ = (Node *) n;
12906 : }
12907 : | select_clause UNION set_quantifier select_clause
12908 : {
12909 14082 : $$ = makeSetOp(SETOP_UNION, $3 == SET_QUANTIFIER_ALL, $1, $4, @1);
12910 : }
12911 : | select_clause INTERSECT set_quantifier select_clause
12912 : {
12913 240 : $$ = makeSetOp(SETOP_INTERSECT, $3 == SET_QUANTIFIER_ALL, $1, $4, @1);
12914 : }
12915 : | select_clause EXCEPT set_quantifier select_clause
12916 : {
12917 482 : $$ = makeSetOp(SETOP_EXCEPT, $3 == SET_QUANTIFIER_ALL, $1, $4, @1);
12918 : }
12919 : ;
12920 :
12921 : /*
12922 : * SQL standard WITH clause looks like:
12923 : *
12924 : * WITH [ RECURSIVE ] <query name> [ (<column>,...) ]
12925 : * AS (query) [ SEARCH or CYCLE clause ]
12926 : *
12927 : * Recognizing WITH_LA here allows a CTE to be named TIME or ORDINALITY.
12928 : */
12929 : with_clause:
12930 : WITH cte_list
12931 : {
12932 1766 : $$ = makeNode(WithClause);
12933 1766 : $$->ctes = $2;
12934 1766 : $$->recursive = false;
12935 1766 : $$->location = @1;
12936 : }
12937 : | WITH_LA cte_list
12938 : {
12939 6 : $$ = makeNode(WithClause);
12940 6 : $$->ctes = $2;
12941 6 : $$->recursive = false;
12942 6 : $$->location = @1;
12943 : }
12944 : | WITH RECURSIVE cte_list
12945 : {
12946 1120 : $$ = makeNode(WithClause);
12947 1120 : $$->ctes = $3;
12948 1120 : $$->recursive = true;
12949 1120 : $$->location = @1;
12950 : }
12951 : ;
12952 :
12953 : cte_list:
12954 2892 : common_table_expr { $$ = list_make1($1); }
12955 1030 : | cte_list ',' common_table_expr { $$ = lappend($1, $3); }
12956 : ;
12957 :
12958 : common_table_expr: name opt_name_list AS opt_materialized '(' PreparableStmt ')' opt_search_clause opt_cycle_clause
12959 : {
12960 3922 : CommonTableExpr *n = makeNode(CommonTableExpr);
12961 :
12962 3922 : n->ctename = $1;
12963 3922 : n->aliascolnames = $2;
12964 3922 : n->ctematerialized = $4;
12965 3922 : n->ctequery = $6;
12966 3922 : n->search_clause = castNode(CTESearchClause, $8);
12967 3922 : n->cycle_clause = castNode(CTECycleClause, $9);
12968 3922 : n->location = @1;
12969 3922 : $$ = (Node *) n;
12970 : }
12971 : ;
12972 :
12973 : opt_materialized:
12974 178 : MATERIALIZED { $$ = CTEMaterializeAlways; }
12975 48 : | NOT MATERIALIZED { $$ = CTEMaterializeNever; }
12976 3696 : | /*EMPTY*/ { $$ = CTEMaterializeDefault; }
12977 : ;
12978 :
12979 : opt_search_clause:
12980 : SEARCH DEPTH FIRST_P BY columnList SET ColId
12981 : {
12982 90 : CTESearchClause *n = makeNode(CTESearchClause);
12983 :
12984 90 : n->search_col_list = $5;
12985 90 : n->search_breadth_first = false;
12986 90 : n->search_seq_column = $7;
12987 90 : n->location = @1;
12988 90 : $$ = (Node *) n;
12989 : }
12990 : | SEARCH BREADTH FIRST_P BY columnList SET ColId
12991 : {
12992 36 : CTESearchClause *n = makeNode(CTESearchClause);
12993 :
12994 36 : n->search_col_list = $5;
12995 36 : n->search_breadth_first = true;
12996 36 : n->search_seq_column = $7;
12997 36 : n->location = @1;
12998 36 : $$ = (Node *) n;
12999 : }
13000 : | /*EMPTY*/
13001 : {
13002 3796 : $$ = NULL;
13003 : }
13004 : ;
13005 :
13006 : opt_cycle_clause:
13007 : CYCLE columnList SET ColId TO AexprConst DEFAULT AexprConst USING ColId
13008 : {
13009 66 : CTECycleClause *n = makeNode(CTECycleClause);
13010 :
13011 66 : n->cycle_col_list = $2;
13012 66 : n->cycle_mark_column = $4;
13013 66 : n->cycle_mark_value = $6;
13014 66 : n->cycle_mark_default = $8;
13015 66 : n->cycle_path_column = $10;
13016 66 : n->location = @1;
13017 66 : $$ = (Node *) n;
13018 : }
13019 : | CYCLE columnList SET ColId USING ColId
13020 : {
13021 60 : CTECycleClause *n = makeNode(CTECycleClause);
13022 :
13023 60 : n->cycle_col_list = $2;
13024 60 : n->cycle_mark_column = $4;
13025 60 : n->cycle_mark_value = makeBoolAConst(true, -1);
13026 60 : n->cycle_mark_default = makeBoolAConst(false, -1);
13027 60 : n->cycle_path_column = $6;
13028 60 : n->location = @1;
13029 60 : $$ = (Node *) n;
13030 : }
13031 : | /*EMPTY*/
13032 : {
13033 3796 : $$ = NULL;
13034 : }
13035 : ;
13036 :
13037 : opt_with_clause:
13038 404 : with_clause { $$ = $1; }
13039 92318 : | /*EMPTY*/ { $$ = NULL; }
13040 : ;
13041 :
13042 : into_clause:
13043 : INTO OptTempTableName
13044 : {
13045 132 : $$ = makeNode(IntoClause);
13046 132 : $$->rel = $2;
13047 132 : $$->colNames = NIL;
13048 132 : $$->options = NIL;
13049 132 : $$->onCommit = ONCOMMIT_NOOP;
13050 132 : $$->tableSpaceName = NULL;
13051 132 : $$->viewQuery = NULL;
13052 132 : $$->skipData = false;
13053 : }
13054 : | /*EMPTY*/
13055 437648 : { $$ = NULL; }
13056 : ;
13057 :
13058 : /*
13059 : * Redundancy here is needed to avoid shift/reduce conflicts,
13060 : * since TEMP is not a reserved word. See also OptTemp.
13061 : */
13062 : OptTempTableName:
13063 : TEMPORARY opt_table qualified_name
13064 : {
13065 0 : $$ = $3;
13066 0 : $$->relpersistence = RELPERSISTENCE_TEMP;
13067 : }
13068 : | TEMP opt_table qualified_name
13069 : {
13070 6 : $$ = $3;
13071 6 : $$->relpersistence = RELPERSISTENCE_TEMP;
13072 : }
13073 : | LOCAL TEMPORARY opt_table qualified_name
13074 : {
13075 0 : $$ = $4;
13076 0 : $$->relpersistence = RELPERSISTENCE_TEMP;
13077 : }
13078 : | LOCAL TEMP opt_table qualified_name
13079 : {
13080 0 : $$ = $4;
13081 0 : $$->relpersistence = RELPERSISTENCE_TEMP;
13082 : }
13083 : | GLOBAL TEMPORARY opt_table qualified_name
13084 : {
13085 0 : ereport(WARNING,
13086 : (errmsg("GLOBAL is deprecated in temporary table creation"),
13087 : parser_errposition(@1)));
13088 0 : $$ = $4;
13089 0 : $$->relpersistence = RELPERSISTENCE_TEMP;
13090 : }
13091 : | GLOBAL TEMP opt_table qualified_name
13092 : {
13093 0 : ereport(WARNING,
13094 : (errmsg("GLOBAL is deprecated in temporary table creation"),
13095 : parser_errposition(@1)));
13096 0 : $$ = $4;
13097 0 : $$->relpersistence = RELPERSISTENCE_TEMP;
13098 : }
13099 : | UNLOGGED opt_table qualified_name
13100 : {
13101 0 : $$ = $3;
13102 0 : $$->relpersistence = RELPERSISTENCE_UNLOGGED;
13103 : }
13104 : | TABLE qualified_name
13105 : {
13106 30 : $$ = $2;
13107 30 : $$->relpersistence = RELPERSISTENCE_PERMANENT;
13108 : }
13109 : | qualified_name
13110 : {
13111 96 : $$ = $1;
13112 96 : $$->relpersistence = RELPERSISTENCE_PERMANENT;
13113 : }
13114 : ;
13115 :
13116 : opt_table: TABLE
13117 : | /*EMPTY*/
13118 : ;
13119 :
13120 : set_quantifier:
13121 6866 : ALL { $$ = SET_QUANTIFIER_ALL; }
13122 32 : | DISTINCT { $$ = SET_QUANTIFIER_DISTINCT; }
13123 12414 : | /*EMPTY*/ { $$ = SET_QUANTIFIER_DEFAULT; }
13124 : ;
13125 :
13126 : /* We use (NIL) as a placeholder to indicate that all target expressions
13127 : * should be placed in the DISTINCT list during parsetree analysis.
13128 : */
13129 : distinct_clause:
13130 3004 : DISTINCT { $$ = list_make1(NIL); }
13131 202 : | DISTINCT ON '(' expr_list ')' { $$ = $4; }
13132 : ;
13133 :
13134 : opt_all_clause:
13135 : ALL
13136 : | /*EMPTY*/
13137 : ;
13138 :
13139 : opt_distinct_clause:
13140 0 : distinct_clause { $$ = $1; }
13141 39294 : | opt_all_clause { $$ = NIL; }
13142 : ;
13143 :
13144 : opt_sort_clause:
13145 6634 : sort_clause { $$ = $1; }
13146 348590 : | /*EMPTY*/ { $$ = NIL; }
13147 : ;
13148 :
13149 : sort_clause:
13150 67334 : ORDER BY sortby_list { $$ = $3; }
13151 : ;
13152 :
13153 : sortby_list:
13154 67352 : sortby { $$ = list_make1($1); }
13155 25538 : | sortby_list ',' sortby { $$ = lappend($1, $3); }
13156 : ;
13157 :
13158 : sortby: a_expr USING qual_all_Op opt_nulls_order
13159 : {
13160 220 : $$ = makeNode(SortBy);
13161 220 : $$->node = $1;
13162 220 : $$->sortby_dir = SORTBY_USING;
13163 220 : $$->sortby_nulls = $4;
13164 220 : $$->useOp = $3;
13165 220 : $$->location = @3;
13166 : }
13167 : | a_expr opt_asc_desc opt_nulls_order
13168 : {
13169 92670 : $$ = makeNode(SortBy);
13170 92670 : $$->node = $1;
13171 92670 : $$->sortby_dir = $2;
13172 92670 : $$->sortby_nulls = $3;
13173 92670 : $$->useOp = NIL;
13174 92670 : $$->location = -1; /* no operator */
13175 : }
13176 : ;
13177 :
13178 :
13179 : select_limit:
13180 : limit_clause offset_clause
13181 : {
13182 168 : $$ = $1;
13183 168 : ($$)->limitOffset = $2;
13184 168 : ($$)->offsetLoc = @2;
13185 : }
13186 : | offset_clause limit_clause
13187 : {
13188 214 : $$ = $2;
13189 214 : ($$)->limitOffset = $1;
13190 214 : ($$)->offsetLoc = @1;
13191 : }
13192 : | limit_clause
13193 : {
13194 4160 : $$ = $1;
13195 : }
13196 : | offset_clause
13197 : {
13198 374 : SelectLimit *n = (SelectLimit *) palloc(sizeof(SelectLimit));
13199 :
13200 374 : n->limitOffset = $1;
13201 374 : n->limitCount = NULL;
13202 374 : n->limitOption = LIMIT_OPTION_COUNT;
13203 374 : n->offsetLoc = @1;
13204 374 : n->countLoc = -1;
13205 374 : n->optionLoc = -1;
13206 374 : $$ = n;
13207 : }
13208 : ;
13209 :
13210 : opt_select_limit:
13211 190 : select_limit { $$ = $1; }
13212 43888 : | /* EMPTY */ { $$ = NULL; }
13213 : ;
13214 :
13215 : limit_clause:
13216 : LIMIT select_limit_value
13217 : {
13218 4458 : SelectLimit *n = (SelectLimit *) palloc(sizeof(SelectLimit));
13219 :
13220 4458 : n->limitOffset = NULL;
13221 4458 : n->limitCount = $2;
13222 4458 : n->limitOption = LIMIT_OPTION_COUNT;
13223 4458 : n->offsetLoc = -1;
13224 4458 : n->countLoc = @1;
13225 4458 : n->optionLoc = -1;
13226 4458 : $$ = n;
13227 : }
13228 : | LIMIT select_limit_value ',' select_offset_value
13229 : {
13230 : /* Disabled because it was too confusing, bjm 2002-02-18 */
13231 0 : ereport(ERROR,
13232 : (errcode(ERRCODE_SYNTAX_ERROR),
13233 : errmsg("LIMIT #,# syntax is not supported"),
13234 : errhint("Use separate LIMIT and OFFSET clauses."),
13235 : parser_errposition(@1)));
13236 : }
13237 : /* SQL:2008 syntax */
13238 : /* to avoid shift/reduce conflicts, handle the optional value with
13239 : * a separate production rather than an opt_ expression. The fact
13240 : * that ONLY is fully reserved means that this way, we defer any
13241 : * decision about what rule reduces ROW or ROWS to the point where
13242 : * we can see the ONLY token in the lookahead slot.
13243 : */
13244 : | FETCH first_or_next select_fetch_first_value row_or_rows ONLY
13245 : {
13246 20 : SelectLimit *n = (SelectLimit *) palloc(sizeof(SelectLimit));
13247 :
13248 20 : n->limitOffset = NULL;
13249 20 : n->limitCount = $3;
13250 20 : n->limitOption = LIMIT_OPTION_COUNT;
13251 20 : n->offsetLoc = -1;
13252 20 : n->countLoc = @1;
13253 20 : n->optionLoc = -1;
13254 20 : $$ = n;
13255 : }
13256 : | FETCH first_or_next select_fetch_first_value row_or_rows WITH TIES
13257 : {
13258 58 : SelectLimit *n = (SelectLimit *) palloc(sizeof(SelectLimit));
13259 :
13260 58 : n->limitOffset = NULL;
13261 58 : n->limitCount = $3;
13262 58 : n->limitOption = LIMIT_OPTION_WITH_TIES;
13263 58 : n->offsetLoc = -1;
13264 58 : n->countLoc = @1;
13265 58 : n->optionLoc = @5;
13266 58 : $$ = n;
13267 : }
13268 : | FETCH first_or_next row_or_rows ONLY
13269 : {
13270 0 : SelectLimit *n = (SelectLimit *) palloc(sizeof(SelectLimit));
13271 :
13272 0 : n->limitOffset = NULL;
13273 0 : n->limitCount = makeIntConst(1, -1);
13274 0 : n->limitOption = LIMIT_OPTION_COUNT;
13275 0 : n->offsetLoc = -1;
13276 0 : n->countLoc = @1;
13277 0 : n->optionLoc = -1;
13278 0 : $$ = n;
13279 : }
13280 : | FETCH first_or_next row_or_rows WITH TIES
13281 : {
13282 6 : SelectLimit *n = (SelectLimit *) palloc(sizeof(SelectLimit));
13283 :
13284 6 : n->limitOffset = NULL;
13285 6 : n->limitCount = makeIntConst(1, -1);
13286 6 : n->limitOption = LIMIT_OPTION_WITH_TIES;
13287 6 : n->offsetLoc = -1;
13288 6 : n->countLoc = @1;
13289 6 : n->optionLoc = @4;
13290 6 : $$ = n;
13291 : }
13292 : ;
13293 :
13294 : offset_clause:
13295 : OFFSET select_offset_value
13296 756 : { $$ = $2; }
13297 : /* SQL:2008 syntax */
13298 : | OFFSET select_fetch_first_value row_or_rows
13299 0 : { $$ = $2; }
13300 : ;
13301 :
13302 : select_limit_value:
13303 4456 : a_expr { $$ = $1; }
13304 : | ALL
13305 : {
13306 : /* LIMIT ALL is represented as a NULL constant */
13307 2 : $$ = makeNullAConst(@1);
13308 : }
13309 : ;
13310 :
13311 : select_offset_value:
13312 756 : a_expr { $$ = $1; }
13313 : ;
13314 :
13315 : /*
13316 : * Allowing full expressions without parentheses causes various parsing
13317 : * problems with the trailing ROW/ROWS key words. SQL spec only calls for
13318 : * <simple value specification>, which is either a literal or a parameter (but
13319 : * an <SQL parameter reference> could be an identifier, bringing up conflicts
13320 : * with ROW/ROWS). We solve this by leveraging the presence of ONLY (see above)
13321 : * to determine whether the expression is missing rather than trying to make it
13322 : * optional in this rule.
13323 : *
13324 : * c_expr covers almost all the spec-required cases (and more), but it doesn't
13325 : * cover signed numeric literals, which are allowed by the spec. So we include
13326 : * those here explicitly. We need FCONST as well as ICONST because values that
13327 : * don't fit in the platform's "long", but do fit in bigint, should still be
13328 : * accepted here. (This is possible in 64-bit Windows as well as all 32-bit
13329 : * builds.)
13330 : */
13331 : select_fetch_first_value:
13332 78 : c_expr { $$ = $1; }
13333 : | '+' I_or_F_const
13334 0 : { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "+", NULL, $2, @1); }
13335 : | '-' I_or_F_const
13336 0 : { $$ = doNegate($2, @1); }
13337 : ;
13338 :
13339 : I_or_F_const:
13340 0 : Iconst { $$ = makeIntConst($1,@1); }
13341 0 : | FCONST { $$ = makeFloatConst($1,@1); }
13342 : ;
13343 :
13344 : /* noise words */
13345 32 : row_or_rows: ROW { $$ = 0; }
13346 52 : | ROWS { $$ = 0; }
13347 : ;
13348 :
13349 84 : first_or_next: FIRST_P { $$ = 0; }
13350 0 : | NEXT { $$ = 0; }
13351 : ;
13352 :
13353 :
13354 : /*
13355 : * This syntax for group_clause tries to follow the spec quite closely.
13356 : * However, the spec allows only column references, not expressions,
13357 : * which introduces an ambiguity between implicit row constructors
13358 : * (a,b) and lists of column references.
13359 : *
13360 : * We handle this by using the a_expr production for what the spec calls
13361 : * <ordinary grouping set>, which in the spec represents either one column
13362 : * reference or a parenthesized list of column references. Then, we check the
13363 : * top node of the a_expr to see if it's an implicit RowExpr, and if so, just
13364 : * grab and use the list, discarding the node. (this is done in parse analysis,
13365 : * not here)
13366 : *
13367 : * (we abuse the row_format field of RowExpr to distinguish implicit and
13368 : * explicit row constructors; it's debatable if anyone sanely wants to use them
13369 : * in a group clause, but if they have a reason to, we make it possible.)
13370 : *
13371 : * Each item in the group_clause list is either an expression tree or a
13372 : * GroupingSet node of some type.
13373 : */
13374 : group_clause:
13375 : GROUP_P BY set_quantifier group_by_list
13376 : {
13377 4496 : GroupClause *n = (GroupClause *) palloc(sizeof(GroupClause));
13378 :
13379 4496 : n->distinct = $3 == SET_QUANTIFIER_DISTINCT;
13380 4496 : n->list = $4;
13381 4496 : $$ = n;
13382 : }
13383 : | /*EMPTY*/
13384 : {
13385 472554 : GroupClause *n = (GroupClause *) palloc(sizeof(GroupClause));
13386 :
13387 472554 : n->distinct = false;
13388 472554 : n->list = NIL;
13389 472554 : $$ = n;
13390 : }
13391 : ;
13392 :
13393 : group_by_list:
13394 5070 : group_by_item { $$ = list_make1($1); }
13395 2872 : | group_by_list ',' group_by_item { $$ = lappend($1,$3); }
13396 : ;
13397 :
13398 : group_by_item:
13399 6676 : a_expr { $$ = $1; }
13400 222 : | empty_grouping_set { $$ = $1; }
13401 184 : | cube_clause { $$ = $1; }
13402 286 : | rollup_clause { $$ = $1; }
13403 574 : | grouping_sets_clause { $$ = $1; }
13404 : ;
13405 :
13406 : empty_grouping_set:
13407 : '(' ')'
13408 : {
13409 222 : $$ = (Node *) makeGroupingSet(GROUPING_SET_EMPTY, NIL, @1);
13410 : }
13411 : ;
13412 :
13413 : /*
13414 : * These hacks rely on setting precedence of CUBE and ROLLUP below that of '(',
13415 : * so that they shift in these rules rather than reducing the conflicting
13416 : * unreserved_keyword rule.
13417 : */
13418 :
13419 : rollup_clause:
13420 : ROLLUP '(' expr_list ')'
13421 : {
13422 286 : $$ = (Node *) makeGroupingSet(GROUPING_SET_ROLLUP, $3, @1);
13423 : }
13424 : ;
13425 :
13426 : cube_clause:
13427 : CUBE '(' expr_list ')'
13428 : {
13429 184 : $$ = (Node *) makeGroupingSet(GROUPING_SET_CUBE, $3, @1);
13430 : }
13431 : ;
13432 :
13433 : grouping_sets_clause:
13434 : GROUPING SETS '(' group_by_list ')'
13435 : {
13436 574 : $$ = (Node *) makeGroupingSet(GROUPING_SET_SETS, $4, @1);
13437 : }
13438 : ;
13439 :
13440 : having_clause:
13441 834 : HAVING a_expr { $$ = $2; }
13442 476216 : | /*EMPTY*/ { $$ = NULL; }
13443 : ;
13444 :
13445 : for_locking_clause:
13446 5124 : for_locking_items { $$ = $1; }
13447 0 : | FOR READ ONLY { $$ = NIL; }
13448 : ;
13449 :
13450 : opt_for_locking_clause:
13451 340 : for_locking_clause { $$ = $1; }
13452 43680 : | /* EMPTY */ { $$ = NIL; }
13453 : ;
13454 :
13455 : for_locking_items:
13456 5124 : for_locking_item { $$ = list_make1($1); }
13457 98 : | for_locking_items for_locking_item { $$ = lappend($1, $2); }
13458 : ;
13459 :
13460 : for_locking_item:
13461 : for_locking_strength locked_rels_list opt_nowait_or_skip
13462 : {
13463 5222 : LockingClause *n = makeNode(LockingClause);
13464 :
13465 5222 : n->lockedRels = $2;
13466 5222 : n->strength = $1;
13467 5222 : n->waitPolicy = $3;
13468 5222 : $$ = (Node *) n;
13469 : }
13470 : ;
13471 :
13472 : for_locking_strength:
13473 1460 : FOR UPDATE { $$ = LCS_FORUPDATE; }
13474 76 : | FOR NO KEY UPDATE { $$ = LCS_FORNOKEYUPDATE; }
13475 214 : | FOR SHARE { $$ = LCS_FORSHARE; }
13476 3472 : | FOR KEY SHARE { $$ = LCS_FORKEYSHARE; }
13477 : ;
13478 :
13479 : locked_rels_list:
13480 3470 : OF qualified_name_list { $$ = $2; }
13481 1752 : | /* EMPTY */ { $$ = NIL; }
13482 : ;
13483 :
13484 :
13485 : /*
13486 : * We should allow ROW '(' expr_list ')' too, but that seems to require
13487 : * making VALUES a fully reserved word, which will probably break more apps
13488 : * than allowing the noise-word is worth.
13489 : */
13490 : values_clause:
13491 : VALUES '(' expr_list ')'
13492 : {
13493 60966 : SelectStmt *n = makeNode(SelectStmt);
13494 :
13495 60966 : n->stmt_location = @1;
13496 60966 : n->valuesLists = list_make1($3);
13497 60966 : $$ = (Node *) n;
13498 : }
13499 : | values_clause ',' '(' expr_list ')'
13500 : {
13501 24624 : SelectStmt *n = (SelectStmt *) $1;
13502 :
13503 24624 : n->valuesLists = lappend(n->valuesLists, $4);
13504 24624 : $$ = (Node *) n;
13505 : }
13506 : ;
13507 :
13508 :
13509 : /*****************************************************************************
13510 : *
13511 : * clauses common to all Optimizable Stmts:
13512 : * from_clause - allow list of both JOIN expressions and table names
13513 : * where_clause - qualifications for joins or restrictions
13514 : *
13515 : *****************************************************************************/
13516 :
13517 : from_clause:
13518 285318 : FROM from_list { $$ = $2; }
13519 204896 : | /*EMPTY*/ { $$ = NIL; }
13520 : ;
13521 :
13522 : from_list:
13523 286004 : table_ref { $$ = list_make1($1); }
13524 56250 : | from_list ',' table_ref { $$ = lappend($1, $3); }
13525 : ;
13526 :
13527 : /*
13528 : * table_ref is where an alias clause can be attached.
13529 : */
13530 : table_ref: relation_expr opt_alias_clause
13531 : {
13532 360998 : $1->alias = $2;
13533 360998 : $$ = (Node *) $1;
13534 : }
13535 : | relation_expr opt_alias_clause tablesample_clause
13536 : {
13537 254 : RangeTableSample *n = (RangeTableSample *) $3;
13538 :
13539 254 : $1->alias = $2;
13540 : /* relation_expr goes inside the RangeTableSample node */
13541 254 : n->relation = (Node *) $1;
13542 254 : $$ = (Node *) n;
13543 : }
13544 : | func_table func_alias_clause
13545 : {
13546 41672 : RangeFunction *n = (RangeFunction *) $1;
13547 :
13548 41672 : n->alias = linitial($2);
13549 41672 : n->coldeflist = lsecond($2);
13550 41672 : $$ = (Node *) n;
13551 : }
13552 : | LATERAL_P func_table func_alias_clause
13553 : {
13554 1034 : RangeFunction *n = (RangeFunction *) $2;
13555 :
13556 1034 : n->lateral = true;
13557 1034 : n->alias = linitial($3);
13558 1034 : n->coldeflist = lsecond($3);
13559 1034 : $$ = (Node *) n;
13560 : }
13561 : | xmltable opt_alias_clause
13562 : {
13563 80 : RangeTableFunc *n = (RangeTableFunc *) $1;
13564 :
13565 80 : n->alias = $2;
13566 80 : $$ = (Node *) n;
13567 : }
13568 : | LATERAL_P xmltable opt_alias_clause
13569 : {
13570 140 : RangeTableFunc *n = (RangeTableFunc *) $2;
13571 :
13572 140 : n->lateral = true;
13573 140 : n->alias = $3;
13574 140 : $$ = (Node *) n;
13575 : }
13576 : | select_with_parens opt_alias_clause
13577 : {
13578 13078 : RangeSubselect *n = makeNode(RangeSubselect);
13579 :
13580 13078 : n->lateral = false;
13581 13078 : n->subquery = $1;
13582 13078 : n->alias = $2;
13583 13078 : $$ = (Node *) n;
13584 : }
13585 : | LATERAL_P select_with_parens opt_alias_clause
13586 : {
13587 1440 : RangeSubselect *n = makeNode(RangeSubselect);
13588 :
13589 1440 : n->lateral = true;
13590 1440 : n->subquery = $2;
13591 1440 : n->alias = $3;
13592 1440 : $$ = (Node *) n;
13593 : }
13594 : | joined_table
13595 : {
13596 74770 : $$ = (Node *) $1;
13597 : }
13598 : | '(' joined_table ')' alias_clause
13599 : {
13600 174 : $2->alias = $4;
13601 174 : $$ = (Node *) $2;
13602 : }
13603 : | json_table opt_alias_clause
13604 : {
13605 524 : JsonTable *jt = castNode(JsonTable, $1);
13606 :
13607 524 : jt->alias = $2;
13608 524 : $$ = (Node *) jt;
13609 : }
13610 : | LATERAL_P json_table opt_alias_clause
13611 : {
13612 0 : JsonTable *jt = castNode(JsonTable, $2);
13613 :
13614 0 : jt->alias = $3;
13615 0 : jt->lateral = true;
13616 0 : $$ = (Node *) jt;
13617 : }
13618 : ;
13619 :
13620 :
13621 : /*
13622 : * It may seem silly to separate joined_table from table_ref, but there is
13623 : * method in SQL's madness: if you don't do it this way you get reduce-
13624 : * reduce conflicts, because it's not clear to the parser generator whether
13625 : * to expect alias_clause after ')' or not. For the same reason we must
13626 : * treat 'JOIN' and 'join_type JOIN' separately, rather than allowing
13627 : * join_type to expand to empty; if we try it, the parser generator can't
13628 : * figure out when to reduce an empty join_type right after table_ref.
13629 : *
13630 : * Note that a CROSS JOIN is the same as an unqualified
13631 : * INNER JOIN, and an INNER JOIN/ON has the same shape
13632 : * but a qualification expression to limit membership.
13633 : * A NATURAL JOIN implicitly matches column names between
13634 : * tables and the shape is determined by which columns are
13635 : * in common. We'll collect columns during the later transformations.
13636 : */
13637 :
13638 : joined_table:
13639 : '(' joined_table ')'
13640 : {
13641 3570 : $$ = $2;
13642 : }
13643 : | table_ref CROSS JOIN table_ref
13644 : {
13645 : /* CROSS JOIN is same as unqualified inner join */
13646 310 : JoinExpr *n = makeNode(JoinExpr);
13647 :
13648 310 : n->jointype = JOIN_INNER;
13649 310 : n->isNatural = false;
13650 310 : n->larg = $1;
13651 310 : n->rarg = $4;
13652 310 : n->usingClause = NIL;
13653 310 : n->join_using_alias = NULL;
13654 310 : n->quals = NULL;
13655 310 : $$ = n;
13656 : }
13657 : | table_ref join_type JOIN table_ref join_qual
13658 : {
13659 42846 : JoinExpr *n = makeNode(JoinExpr);
13660 :
13661 42846 : n->jointype = $2;
13662 42846 : n->isNatural = false;
13663 42846 : n->larg = $1;
13664 42846 : n->rarg = $4;
13665 42846 : if ($5 != NULL && IsA($5, List))
13666 : {
13667 : /* USING clause */
13668 486 : n->usingClause = linitial_node(List, castNode(List, $5));
13669 486 : n->join_using_alias = lsecond_node(Alias, castNode(List, $5));
13670 : }
13671 : else
13672 : {
13673 : /* ON clause */
13674 42360 : n->quals = $5;
13675 : }
13676 42846 : $$ = n;
13677 : }
13678 : | table_ref JOIN table_ref join_qual
13679 : {
13680 : /* letting join_type reduce to empty doesn't work */
13681 31530 : JoinExpr *n = makeNode(JoinExpr);
13682 :
13683 31530 : n->jointype = JOIN_INNER;
13684 31530 : n->isNatural = false;
13685 31530 : n->larg = $1;
13686 31530 : n->rarg = $3;
13687 31530 : if ($4 != NULL && IsA($4, List))
13688 : {
13689 : /* USING clause */
13690 708 : n->usingClause = linitial_node(List, castNode(List, $4));
13691 708 : n->join_using_alias = lsecond_node(Alias, castNode(List, $4));
13692 : }
13693 : else
13694 : {
13695 : /* ON clause */
13696 30822 : n->quals = $4;
13697 : }
13698 31530 : $$ = n;
13699 : }
13700 : | table_ref NATURAL join_type JOIN table_ref
13701 : {
13702 78 : JoinExpr *n = makeNode(JoinExpr);
13703 :
13704 78 : n->jointype = $3;
13705 78 : n->isNatural = true;
13706 78 : n->larg = $1;
13707 78 : n->rarg = $5;
13708 78 : n->usingClause = NIL; /* figure out which columns later... */
13709 78 : n->join_using_alias = NULL;
13710 78 : n->quals = NULL; /* fill later */
13711 78 : $$ = n;
13712 : }
13713 : | table_ref NATURAL JOIN table_ref
13714 : {
13715 : /* letting join_type reduce to empty doesn't work */
13716 180 : JoinExpr *n = makeNode(JoinExpr);
13717 :
13718 180 : n->jointype = JOIN_INNER;
13719 180 : n->isNatural = true;
13720 180 : n->larg = $1;
13721 180 : n->rarg = $4;
13722 180 : n->usingClause = NIL; /* figure out which columns later... */
13723 180 : n->join_using_alias = NULL;
13724 180 : n->quals = NULL; /* fill later */
13725 180 : $$ = n;
13726 : }
13727 : ;
13728 :
13729 : alias_clause:
13730 : AS ColId '(' name_list ')'
13731 : {
13732 5700 : $$ = makeNode(Alias);
13733 5700 : $$->aliasname = $2;
13734 5700 : $$->colnames = $4;
13735 : }
13736 : | AS ColId
13737 : {
13738 10130 : $$ = makeNode(Alias);
13739 10130 : $$->aliasname = $2;
13740 : }
13741 : | ColId '(' name_list ')'
13742 : {
13743 5608 : $$ = makeNode(Alias);
13744 5608 : $$->aliasname = $1;
13745 5608 : $$->colnames = $3;
13746 : }
13747 : | ColId
13748 : {
13749 238818 : $$ = makeNode(Alias);
13750 238818 : $$->aliasname = $1;
13751 : }
13752 : ;
13753 :
13754 231588 : opt_alias_clause: alias_clause { $$ = $1; }
13755 144926 : | /*EMPTY*/ { $$ = NULL; }
13756 : ;
13757 :
13758 : /*
13759 : * The alias clause after JOIN ... USING only accepts the AS ColId spelling,
13760 : * per SQL standard. (The grammar could parse the other variants, but they
13761 : * don't seem to be useful, and it might lead to parser problems in the
13762 : * future.)
13763 : */
13764 : opt_alias_clause_for_join_using:
13765 : AS ColId
13766 : {
13767 84 : $$ = makeNode(Alias);
13768 84 : $$->aliasname = $2;
13769 : /* the column name list will be inserted later */
13770 : }
13771 1110 : | /*EMPTY*/ { $$ = NULL; }
13772 : ;
13773 :
13774 : /*
13775 : * func_alias_clause can include both an Alias and a coldeflist, so we make it
13776 : * return a 2-element list that gets disassembled by calling production.
13777 : */
13778 : func_alias_clause:
13779 : alias_clause
13780 : {
13781 28494 : $$ = list_make2($1, NIL);
13782 : }
13783 : | AS '(' TableFuncElementList ')'
13784 : {
13785 114 : $$ = list_make2(NULL, $3);
13786 : }
13787 : | AS ColId '(' TableFuncElementList ')'
13788 : {
13789 586 : Alias *a = makeNode(Alias);
13790 :
13791 586 : a->aliasname = $2;
13792 586 : $$ = list_make2(a, $4);
13793 : }
13794 : | ColId '(' TableFuncElementList ')'
13795 : {
13796 50 : Alias *a = makeNode(Alias);
13797 :
13798 50 : a->aliasname = $1;
13799 50 : $$ = list_make2(a, $3);
13800 : }
13801 : | /*EMPTY*/
13802 : {
13803 13462 : $$ = list_make2(NULL, NIL);
13804 : }
13805 : ;
13806 :
13807 1018 : join_type: FULL opt_outer { $$ = JOIN_FULL; }
13808 37794 : | LEFT opt_outer { $$ = JOIN_LEFT; }
13809 356 : | RIGHT opt_outer { $$ = JOIN_RIGHT; }
13810 3756 : | INNER_P { $$ = JOIN_INNER; }
13811 : ;
13812 :
13813 : /* OUTER is just noise... */
13814 : opt_outer: OUTER_P
13815 : | /*EMPTY*/
13816 : ;
13817 :
13818 : /* JOIN qualification clauses
13819 : * Possibilities are:
13820 : * USING ( column list ) [ AS alias ]
13821 : * allows only unqualified column names,
13822 : * which must match between tables.
13823 : * ON expr allows more general qualifications.
13824 : *
13825 : * We return USING as a two-element List (the first item being a sub-List
13826 : * of the common column names, and the second either an Alias item or NULL).
13827 : * An ON-expr will not be a List, so it can be told apart that way.
13828 : */
13829 :
13830 : join_qual: USING '(' name_list ')' opt_alias_clause_for_join_using
13831 : {
13832 1194 : $$ = (Node *) list_make2($3, $5);
13833 : }
13834 : | ON a_expr
13835 : {
13836 73182 : $$ = $2;
13837 : }
13838 : ;
13839 :
13840 :
13841 : relation_expr:
13842 : qualified_name
13843 : {
13844 : /* inheritance query, implicitly */
13845 432606 : $$ = $1;
13846 432606 : $$->inh = true;
13847 432606 : $$->alias = NULL;
13848 : }
13849 : | extended_relation_expr
13850 : {
13851 6878 : $$ = $1;
13852 : }
13853 : ;
13854 :
13855 : extended_relation_expr:
13856 : qualified_name '*'
13857 : {
13858 : /* inheritance query, explicitly */
13859 204 : $$ = $1;
13860 204 : $$->inh = true;
13861 204 : $$->alias = NULL;
13862 : }
13863 : | ONLY qualified_name
13864 : {
13865 : /* no inheritance */
13866 6680 : $$ = $2;
13867 6680 : $$->inh = false;
13868 6680 : $$->alias = NULL;
13869 : }
13870 : | ONLY '(' qualified_name ')'
13871 : {
13872 : /* no inheritance, SQL99-style syntax */
13873 0 : $$ = $3;
13874 0 : $$->inh = false;
13875 0 : $$->alias = NULL;
13876 : }
13877 : ;
13878 :
13879 :
13880 : relation_expr_list:
13881 2714 : relation_expr { $$ = list_make1($1); }
13882 9800 : | relation_expr_list ',' relation_expr { $$ = lappend($1, $3); }
13883 : ;
13884 :
13885 :
13886 : /*
13887 : * Given "UPDATE foo set set ...", we have to decide without looking any
13888 : * further ahead whether the first "set" is an alias or the UPDATE's SET
13889 : * keyword. Since "set" is allowed as a column name both interpretations
13890 : * are feasible. We resolve the shift/reduce conflict by giving the first
13891 : * relation_expr_opt_alias production a higher precedence than the SET token
13892 : * has, causing the parser to prefer to reduce, in effect assuming that the
13893 : * SET is not an alias.
13894 : */
13895 : relation_expr_opt_alias: relation_expr %prec UMINUS
13896 : {
13897 17564 : $$ = $1;
13898 : }
13899 : | relation_expr ColId
13900 : {
13901 2108 : Alias *alias = makeNode(Alias);
13902 :
13903 2108 : alias->aliasname = $2;
13904 2108 : $1->alias = alias;
13905 2108 : $$ = $1;
13906 : }
13907 : | relation_expr AS ColId
13908 : {
13909 90 : Alias *alias = makeNode(Alias);
13910 :
13911 90 : alias->aliasname = $3;
13912 90 : $1->alias = alias;
13913 90 : $$ = $1;
13914 : }
13915 : ;
13916 :
13917 : /*
13918 : * TABLESAMPLE decoration in a FROM item
13919 : */
13920 : tablesample_clause:
13921 : TABLESAMPLE func_name '(' expr_list ')' opt_repeatable_clause
13922 : {
13923 254 : RangeTableSample *n = makeNode(RangeTableSample);
13924 :
13925 : /* n->relation will be filled in later */
13926 254 : n->method = $2;
13927 254 : n->args = $4;
13928 254 : n->repeatable = $6;
13929 254 : n->location = @2;
13930 254 : $$ = (Node *) n;
13931 : }
13932 : ;
13933 :
13934 : opt_repeatable_clause:
13935 108 : REPEATABLE '(' a_expr ')' { $$ = (Node *) $3; }
13936 146 : | /*EMPTY*/ { $$ = NULL; }
13937 : ;
13938 :
13939 : /*
13940 : * func_table represents a function invocation in a FROM list. It can be
13941 : * a plain function call, like "foo(...)", or a ROWS FROM expression with
13942 : * one or more function calls, "ROWS FROM (foo(...), bar(...))",
13943 : * optionally with WITH ORDINALITY attached.
13944 : * In the ROWS FROM syntax, a column definition list can be given for each
13945 : * function, for example:
13946 : * ROWS FROM (foo() AS (foo_res_a text, foo_res_b text),
13947 : * bar() AS (bar_res_a text, bar_res_b text))
13948 : * It's also possible to attach a column definition list to the RangeFunction
13949 : * as a whole, but that's handled by the table_ref production.
13950 : */
13951 : func_table: func_expr_windowless opt_ordinality
13952 : {
13953 42580 : RangeFunction *n = makeNode(RangeFunction);
13954 :
13955 42580 : n->lateral = false;
13956 42580 : n->ordinality = $2;
13957 42580 : n->is_rowsfrom = false;
13958 42580 : n->functions = list_make1(list_make2($1, NIL));
13959 : /* alias and coldeflist are set by table_ref production */
13960 42580 : $$ = (Node *) n;
13961 : }
13962 : | ROWS FROM '(' rowsfrom_list ')' opt_ordinality
13963 : {
13964 132 : RangeFunction *n = makeNode(RangeFunction);
13965 :
13966 132 : n->lateral = false;
13967 132 : n->ordinality = $6;
13968 132 : n->is_rowsfrom = true;
13969 132 : n->functions = $4;
13970 : /* alias and coldeflist are set by table_ref production */
13971 132 : $$ = (Node *) n;
13972 : }
13973 : ;
13974 :
13975 : rowsfrom_item: func_expr_windowless opt_col_def_list
13976 318 : { $$ = list_make2($1, $2); }
13977 : ;
13978 :
13979 : rowsfrom_list:
13980 132 : rowsfrom_item { $$ = list_make1($1); }
13981 186 : | rowsfrom_list ',' rowsfrom_item { $$ = lappend($1, $3); }
13982 : ;
13983 :
13984 54 : opt_col_def_list: AS '(' TableFuncElementList ')' { $$ = $3; }
13985 264 : | /*EMPTY*/ { $$ = NIL; }
13986 : ;
13987 :
13988 784 : opt_ordinality: WITH_LA ORDINALITY { $$ = true; }
13989 41928 : | /*EMPTY*/ { $$ = false; }
13990 : ;
13991 :
13992 :
13993 : where_clause:
13994 192344 : WHERE a_expr { $$ = $2; }
13995 304240 : | /*EMPTY*/ { $$ = NULL; }
13996 : ;
13997 :
13998 : /* variant for UPDATE and DELETE */
13999 : where_or_current_clause:
14000 12624 : WHERE a_expr { $$ = $2; }
14001 : | WHERE CURRENT_P OF cursor_name
14002 : {
14003 266 : CurrentOfExpr *n = makeNode(CurrentOfExpr);
14004 :
14005 : /* cvarno is filled in by parse analysis */
14006 266 : n->cursor_name = $4;
14007 266 : n->cursor_param = 0;
14008 266 : $$ = (Node *) n;
14009 : }
14010 4838 : | /*EMPTY*/ { $$ = NULL; }
14011 : ;
14012 :
14013 :
14014 : OptTableFuncElementList:
14015 694 : TableFuncElementList { $$ = $1; }
14016 2792 : | /*EMPTY*/ { $$ = NIL; }
14017 : ;
14018 :
14019 : TableFuncElementList:
14020 : TableFuncElement
14021 : {
14022 1498 : $$ = list_make1($1);
14023 : }
14024 : | TableFuncElementList ',' TableFuncElement
14025 : {
14026 2004 : $$ = lappend($1, $3);
14027 : }
14028 : ;
14029 :
14030 : TableFuncElement: ColId Typename opt_collate_clause
14031 : {
14032 3566 : ColumnDef *n = makeNode(ColumnDef);
14033 :
14034 3566 : n->colname = $1;
14035 3566 : n->typeName = $2;
14036 3566 : n->inhcount = 0;
14037 3566 : n->is_local = true;
14038 3566 : n->is_not_null = false;
14039 3566 : n->is_from_type = false;
14040 3566 : n->storage = 0;
14041 3566 : n->raw_default = NULL;
14042 3566 : n->cooked_default = NULL;
14043 3566 : n->collClause = (CollateClause *) $3;
14044 3566 : n->collOid = InvalidOid;
14045 3566 : n->constraints = NIL;
14046 3566 : n->location = @1;
14047 3566 : $$ = (Node *) n;
14048 : }
14049 : ;
14050 :
14051 : /*
14052 : * XMLTABLE
14053 : */
14054 : xmltable:
14055 : XMLTABLE '(' c_expr xmlexists_argument COLUMNS xmltable_column_list ')'
14056 : {
14057 200 : RangeTableFunc *n = makeNode(RangeTableFunc);
14058 :
14059 200 : n->rowexpr = $3;
14060 200 : n->docexpr = $4;
14061 200 : n->columns = $6;
14062 200 : n->namespaces = NIL;
14063 200 : n->location = @1;
14064 200 : $$ = (Node *) n;
14065 : }
14066 : | XMLTABLE '(' XMLNAMESPACES '(' xml_namespace_list ')' ','
14067 : c_expr xmlexists_argument COLUMNS xmltable_column_list ')'
14068 : {
14069 20 : RangeTableFunc *n = makeNode(RangeTableFunc);
14070 :
14071 20 : n->rowexpr = $8;
14072 20 : n->docexpr = $9;
14073 20 : n->columns = $11;
14074 20 : n->namespaces = $5;
14075 20 : n->location = @1;
14076 20 : $$ = (Node *) n;
14077 : }
14078 : ;
14079 :
14080 220 : xmltable_column_list: xmltable_column_el { $$ = list_make1($1); }
14081 530 : | xmltable_column_list ',' xmltable_column_el { $$ = lappend($1, $3); }
14082 : ;
14083 :
14084 : xmltable_column_el:
14085 : ColId Typename
14086 : {
14087 198 : RangeTableFuncCol *fc = makeNode(RangeTableFuncCol);
14088 :
14089 198 : fc->colname = $1;
14090 198 : fc->for_ordinality = false;
14091 198 : fc->typeName = $2;
14092 198 : fc->is_not_null = false;
14093 198 : fc->colexpr = NULL;
14094 198 : fc->coldefexpr = NULL;
14095 198 : fc->location = @1;
14096 :
14097 198 : $$ = (Node *) fc;
14098 : }
14099 : | ColId Typename xmltable_column_option_list
14100 : {
14101 490 : RangeTableFuncCol *fc = makeNode(RangeTableFuncCol);
14102 : ListCell *option;
14103 490 : bool nullability_seen = false;
14104 :
14105 490 : fc->colname = $1;
14106 490 : fc->typeName = $2;
14107 490 : fc->for_ordinality = false;
14108 490 : fc->is_not_null = false;
14109 490 : fc->colexpr = NULL;
14110 490 : fc->coldefexpr = NULL;
14111 490 : fc->location = @1;
14112 :
14113 1092 : foreach(option, $3)
14114 : {
14115 602 : DefElem *defel = (DefElem *) lfirst(option);
14116 :
14117 602 : if (strcmp(defel->defname, "default") == 0)
14118 : {
14119 56 : if (fc->coldefexpr != NULL)
14120 0 : ereport(ERROR,
14121 : (errcode(ERRCODE_SYNTAX_ERROR),
14122 : errmsg("only one DEFAULT value is allowed"),
14123 : parser_errposition(defel->location)));
14124 56 : fc->coldefexpr = defel->arg;
14125 : }
14126 546 : else if (strcmp(defel->defname, "path") == 0)
14127 : {
14128 490 : if (fc->colexpr != NULL)
14129 0 : ereport(ERROR,
14130 : (errcode(ERRCODE_SYNTAX_ERROR),
14131 : errmsg("only one PATH value per column is allowed"),
14132 : parser_errposition(defel->location)));
14133 490 : fc->colexpr = defel->arg;
14134 : }
14135 56 : else if (strcmp(defel->defname, "is_not_null") == 0)
14136 : {
14137 56 : if (nullability_seen)
14138 0 : ereport(ERROR,
14139 : (errcode(ERRCODE_SYNTAX_ERROR),
14140 : errmsg("conflicting or redundant NULL / NOT NULL declarations for column \"%s\"", fc->colname),
14141 : parser_errposition(defel->location)));
14142 56 : fc->is_not_null = boolVal(defel->arg);
14143 56 : nullability_seen = true;
14144 : }
14145 : else
14146 : {
14147 0 : ereport(ERROR,
14148 : (errcode(ERRCODE_SYNTAX_ERROR),
14149 : errmsg("unrecognized column option \"%s\"",
14150 : defel->defname),
14151 : parser_errposition(defel->location)));
14152 : }
14153 : }
14154 490 : $$ = (Node *) fc;
14155 : }
14156 : | ColId FOR ORDINALITY
14157 : {
14158 62 : RangeTableFuncCol *fc = makeNode(RangeTableFuncCol);
14159 :
14160 62 : fc->colname = $1;
14161 62 : fc->for_ordinality = true;
14162 : /* other fields are ignored, initialized by makeNode */
14163 62 : fc->location = @1;
14164 :
14165 62 : $$ = (Node *) fc;
14166 : }
14167 : ;
14168 :
14169 : xmltable_column_option_list:
14170 : xmltable_column_option_el
14171 490 : { $$ = list_make1($1); }
14172 : | xmltable_column_option_list xmltable_column_option_el
14173 112 : { $$ = lappend($1, $2); }
14174 : ;
14175 :
14176 : xmltable_column_option_el:
14177 : IDENT b_expr
14178 0 : { $$ = makeDefElem($1, $2, @1); }
14179 : | DEFAULT b_expr
14180 56 : { $$ = makeDefElem("default", $2, @1); }
14181 : | NOT NULL_P
14182 56 : { $$ = makeDefElem("is_not_null", (Node *) makeBoolean(true), @1); }
14183 : | NULL_P
14184 0 : { $$ = makeDefElem("is_not_null", (Node *) makeBoolean(false), @1); }
14185 : | PATH b_expr
14186 490 : { $$ = makeDefElem("path", $2, @1); }
14187 : ;
14188 :
14189 : xml_namespace_list:
14190 : xml_namespace_el
14191 20 : { $$ = list_make1($1); }
14192 : | xml_namespace_list ',' xml_namespace_el
14193 0 : { $$ = lappend($1, $3); }
14194 : ;
14195 :
14196 : xml_namespace_el:
14197 : b_expr AS ColLabel
14198 : {
14199 14 : $$ = makeNode(ResTarget);
14200 14 : $$->name = $3;
14201 14 : $$->indirection = NIL;
14202 14 : $$->val = $1;
14203 14 : $$->location = @1;
14204 : }
14205 : | DEFAULT b_expr
14206 : {
14207 6 : $$ = makeNode(ResTarget);
14208 6 : $$->name = NULL;
14209 6 : $$->indirection = NIL;
14210 6 : $$->val = $2;
14211 6 : $$->location = @1;
14212 : }
14213 : ;
14214 :
14215 : json_table:
14216 : JSON_TABLE '('
14217 : json_value_expr ',' a_expr json_table_path_name_opt
14218 : json_passing_clause_opt
14219 : COLUMNS '(' json_table_column_definition_list ')'
14220 : json_on_error_clause_opt
14221 : ')'
14222 : {
14223 530 : JsonTable *n = makeNode(JsonTable);
14224 : char *pathstring;
14225 :
14226 530 : n->context_item = (JsonValueExpr *) $3;
14227 530 : if (!IsA($5, A_Const) ||
14228 524 : castNode(A_Const, $5)->val.node.type != T_String)
14229 6 : ereport(ERROR,
14230 : errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
14231 : errmsg("only string constants are supported in JSON_TABLE path specification"),
14232 : parser_errposition(@5));
14233 524 : pathstring = castNode(A_Const, $5)->val.sval.sval;
14234 524 : n->pathspec = makeJsonTablePathSpec(pathstring, $6, @5, @6);
14235 524 : n->passing = $7;
14236 524 : n->columns = $10;
14237 524 : n->on_error = (JsonBehavior *) $12;
14238 524 : n->location = @1;
14239 524 : $$ = (Node *) n;
14240 : }
14241 : ;
14242 :
14243 : json_table_path_name_opt:
14244 62 : AS name { $$ = $2; }
14245 480 : | /* empty */ { $$ = NULL; }
14246 : ;
14247 :
14248 : json_table_column_definition_list:
14249 : json_table_column_definition
14250 820 : { $$ = list_make1($1); }
14251 : | json_table_column_definition_list ',' json_table_column_definition
14252 528 : { $$ = lappend($1, $3); }
14253 : ;
14254 :
14255 : json_table_column_definition:
14256 : ColId FOR ORDINALITY
14257 : {
14258 84 : JsonTableColumn *n = makeNode(JsonTableColumn);
14259 :
14260 84 : n->coltype = JTC_FOR_ORDINALITY;
14261 84 : n->name = $1;
14262 84 : n->location = @1;
14263 84 : $$ = (Node *) n;
14264 : }
14265 : | ColId Typename
14266 : json_table_column_path_clause_opt
14267 : json_wrapper_behavior
14268 : json_quotes_clause_opt
14269 : json_behavior_clause_opt
14270 : {
14271 728 : JsonTableColumn *n = makeNode(JsonTableColumn);
14272 :
14273 728 : n->coltype = JTC_REGULAR;
14274 728 : n->name = $1;
14275 728 : n->typeName = $2;
14276 728 : n->format = makeJsonFormat(JS_FORMAT_DEFAULT, JS_ENC_DEFAULT, -1);
14277 728 : n->pathspec = (JsonTablePathSpec *) $3;
14278 728 : n->wrapper = $4;
14279 728 : n->quotes = $5;
14280 728 : n->on_empty = (JsonBehavior *) linitial($6);
14281 728 : n->on_error = (JsonBehavior *) lsecond($6);
14282 728 : n->location = @1;
14283 728 : $$ = (Node *) n;
14284 : }
14285 : | ColId Typename json_format_clause
14286 : json_table_column_path_clause_opt
14287 : json_wrapper_behavior
14288 : json_quotes_clause_opt
14289 : json_behavior_clause_opt
14290 : {
14291 108 : JsonTableColumn *n = makeNode(JsonTableColumn);
14292 :
14293 108 : n->coltype = JTC_FORMATTED;
14294 108 : n->name = $1;
14295 108 : n->typeName = $2;
14296 108 : n->format = (JsonFormat *) $3;
14297 108 : n->pathspec = (JsonTablePathSpec *) $4;
14298 108 : n->wrapper = $5;
14299 108 : n->quotes = $6;
14300 108 : n->on_empty = (JsonBehavior *) linitial($7);
14301 108 : n->on_error = (JsonBehavior *) lsecond($7);
14302 108 : n->location = @1;
14303 108 : $$ = (Node *) n;
14304 : }
14305 : | ColId Typename
14306 : EXISTS json_table_column_path_clause_opt
14307 : json_on_error_clause_opt
14308 : {
14309 138 : JsonTableColumn *n = makeNode(JsonTableColumn);
14310 :
14311 138 : n->coltype = JTC_EXISTS;
14312 138 : n->name = $1;
14313 138 : n->typeName = $2;
14314 138 : n->format = makeJsonFormat(JS_FORMAT_DEFAULT, JS_ENC_DEFAULT, -1);
14315 138 : n->wrapper = JSW_NONE;
14316 138 : n->quotes = JS_QUOTES_UNSPEC;
14317 138 : n->pathspec = (JsonTablePathSpec *) $4;
14318 138 : n->on_empty = NULL;
14319 138 : n->on_error = (JsonBehavior *) $5;
14320 138 : n->location = @1;
14321 138 : $$ = (Node *) n;
14322 : }
14323 : | NESTED path_opt Sconst
14324 : COLUMNS '(' json_table_column_definition_list ')'
14325 : {
14326 144 : JsonTableColumn *n = makeNode(JsonTableColumn);
14327 :
14328 144 : n->coltype = JTC_NESTED;
14329 288 : n->pathspec = (JsonTablePathSpec *)
14330 144 : makeJsonTablePathSpec($3, NULL, @3, -1);
14331 144 : n->columns = $6;
14332 144 : n->location = @1;
14333 144 : $$ = (Node *) n;
14334 : }
14335 : | NESTED path_opt Sconst AS name
14336 : COLUMNS '(' json_table_column_definition_list ')'
14337 : {
14338 146 : JsonTableColumn *n = makeNode(JsonTableColumn);
14339 :
14340 146 : n->coltype = JTC_NESTED;
14341 292 : n->pathspec = (JsonTablePathSpec *)
14342 146 : makeJsonTablePathSpec($3, $5, @3, @5);
14343 146 : n->columns = $8;
14344 146 : n->location = @1;
14345 146 : $$ = (Node *) n;
14346 : }
14347 : ;
14348 :
14349 : path_opt:
14350 : PATH
14351 : | /* EMPTY */
14352 : ;
14353 :
14354 : json_table_column_path_clause_opt:
14355 : PATH Sconst
14356 828 : { $$ = (Node *) makeJsonTablePathSpec($2, NULL, @2, -1); }
14357 : | /* EMPTY */
14358 152 : { $$ = NULL; }
14359 : ;
14360 :
14361 : /*****************************************************************************
14362 : *
14363 : * Type syntax
14364 : * SQL introduces a large amount of type-specific syntax.
14365 : * Define individual clauses to handle these cases, and use
14366 : * the generic case to handle regular type-extensible Postgres syntax.
14367 : * - thomas 1997-10-10
14368 : *
14369 : *****************************************************************************/
14370 :
14371 : Typename: SimpleTypename opt_array_bounds
14372 : {
14373 449398 : $$ = $1;
14374 449398 : $$->arrayBounds = $2;
14375 : }
14376 : | SETOF SimpleTypename opt_array_bounds
14377 : {
14378 2072 : $$ = $2;
14379 2072 : $$->arrayBounds = $3;
14380 2072 : $$->setof = true;
14381 : }
14382 : /* SQL standard syntax, currently only one-dimensional */
14383 : | SimpleTypename ARRAY '[' Iconst ']'
14384 : {
14385 6 : $$ = $1;
14386 6 : $$->arrayBounds = list_make1(makeInteger($4));
14387 : }
14388 : | SETOF SimpleTypename ARRAY '[' Iconst ']'
14389 : {
14390 0 : $$ = $2;
14391 0 : $$->arrayBounds = list_make1(makeInteger($5));
14392 0 : $$->setof = true;
14393 : }
14394 : | SimpleTypename ARRAY
14395 : {
14396 0 : $$ = $1;
14397 0 : $$->arrayBounds = list_make1(makeInteger(-1));
14398 : }
14399 : | SETOF SimpleTypename ARRAY
14400 : {
14401 0 : $$ = $2;
14402 0 : $$->arrayBounds = list_make1(makeInteger(-1));
14403 0 : $$->setof = true;
14404 : }
14405 : ;
14406 :
14407 : opt_array_bounds:
14408 : opt_array_bounds '[' ']'
14409 12314 : { $$ = lappend($1, makeInteger(-1)); }
14410 : | opt_array_bounds '[' Iconst ']'
14411 62 : { $$ = lappend($1, makeInteger($3)); }
14412 : | /*EMPTY*/
14413 451470 : { $$ = NIL; }
14414 : ;
14415 :
14416 : SimpleTypename:
14417 363012 : GenericType { $$ = $1; }
14418 74268 : | Numeric { $$ = $1; }
14419 1894 : | Bit { $$ = $1; }
14420 2906 : | Character { $$ = $1; }
14421 4600 : | ConstDatetime { $$ = $1; }
14422 : | ConstInterval opt_interval
14423 : {
14424 3518 : $$ = $1;
14425 3518 : $$->typmods = $2;
14426 : }
14427 : | ConstInterval '(' Iconst ')'
14428 : {
14429 0 : $$ = $1;
14430 0 : $$->typmods = list_make2(makeIntConst(INTERVAL_FULL_RANGE, -1),
14431 : makeIntConst($3, @3));
14432 : }
14433 1660 : | JsonType { $$ = $1; }
14434 : ;
14435 :
14436 : /* We have a separate ConstTypename to allow defaulting fixed-length
14437 : * types such as CHAR() and BIT() to an unspecified length.
14438 : * SQL9x requires that these default to a length of one, but this
14439 : * makes no sense for constructs like CHAR 'hi' and BIT '0101',
14440 : * where there is an obvious better choice to make.
14441 : * Note that ConstInterval is not included here since it must
14442 : * be pushed up higher in the rules to accommodate the postfix
14443 : * options (e.g. INTERVAL '1' YEAR). Likewise, we have to handle
14444 : * the generic-type-name case in AexprConst to avoid premature
14445 : * reduce/reduce conflicts against function names.
14446 : */
14447 : ConstTypename:
14448 78 : Numeric { $$ = $1; }
14449 0 : | ConstBit { $$ = $1; }
14450 34 : | ConstCharacter { $$ = $1; }
14451 2720 : | ConstDatetime { $$ = $1; }
14452 264 : | JsonType { $$ = $1; }
14453 : ;
14454 :
14455 : /*
14456 : * GenericType covers all type names that don't have special syntax mandated
14457 : * by the standard, including qualified names. We also allow type modifiers.
14458 : * To avoid parsing conflicts against function invocations, the modifiers
14459 : * have to be shown as expr_list here, but parse analysis will only accept
14460 : * constants for them.
14461 : */
14462 : GenericType:
14463 : type_function_name opt_type_modifiers
14464 : {
14465 261240 : $$ = makeTypeName($1);
14466 261240 : $$->typmods = $2;
14467 261240 : $$->location = @1;
14468 : }
14469 : | type_function_name attrs opt_type_modifiers
14470 : {
14471 101772 : $$ = makeTypeNameFromNameList(lcons(makeString($1), $2));
14472 101772 : $$->typmods = $3;
14473 101772 : $$->location = @1;
14474 : }
14475 : ;
14476 :
14477 1348 : opt_type_modifiers: '(' expr_list ')' { $$ = $2; }
14478 367570 : | /* EMPTY */ { $$ = NIL; }
14479 : ;
14480 :
14481 : /*
14482 : * SQL numeric data types
14483 : */
14484 : Numeric: INT_P
14485 : {
14486 35108 : $$ = SystemTypeName("int4");
14487 35108 : $$->location = @1;
14488 : }
14489 : | INTEGER
14490 : {
14491 14136 : $$ = SystemTypeName("int4");
14492 14136 : $$->location = @1;
14493 : }
14494 : | SMALLINT
14495 : {
14496 1138 : $$ = SystemTypeName("int2");
14497 1138 : $$->location = @1;
14498 : }
14499 : | BIGINT
14500 : {
14501 4452 : $$ = SystemTypeName("int8");
14502 4452 : $$->location = @1;
14503 : }
14504 : | REAL
14505 : {
14506 1938 : $$ = SystemTypeName("float4");
14507 1938 : $$->location = @1;
14508 : }
14509 : | FLOAT_P opt_float
14510 : {
14511 500 : $$ = $2;
14512 500 : $$->location = @1;
14513 : }
14514 : | DOUBLE_P PRECISION
14515 : {
14516 514 : $$ = SystemTypeName("float8");
14517 514 : $$->location = @1;
14518 : }
14519 : | DECIMAL_P opt_type_modifiers
14520 : {
14521 36 : $$ = SystemTypeName("numeric");
14522 36 : $$->typmods = $2;
14523 36 : $$->location = @1;
14524 : }
14525 : | DEC opt_type_modifiers
14526 : {
14527 0 : $$ = SystemTypeName("numeric");
14528 0 : $$->typmods = $2;
14529 0 : $$->location = @1;
14530 : }
14531 : | NUMERIC opt_type_modifiers
14532 : {
14533 5870 : $$ = SystemTypeName("numeric");
14534 5870 : $$->typmods = $2;
14535 5870 : $$->location = @1;
14536 : }
14537 : | BOOLEAN_P
14538 : {
14539 10654 : $$ = SystemTypeName("bool");
14540 10654 : $$->location = @1;
14541 : }
14542 : ;
14543 :
14544 : opt_float: '(' Iconst ')'
14545 : {
14546 : /*
14547 : * Check FLOAT() precision limits assuming IEEE floating
14548 : * types - thomas 1997-09-18
14549 : */
14550 2 : if ($2 < 1)
14551 0 : ereport(ERROR,
14552 : (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
14553 : errmsg("precision for type float must be at least 1 bit"),
14554 : parser_errposition(@2)));
14555 2 : else if ($2 <= 24)
14556 2 : $$ = SystemTypeName("float4");
14557 0 : else if ($2 <= 53)
14558 0 : $$ = SystemTypeName("float8");
14559 : else
14560 0 : ereport(ERROR,
14561 : (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
14562 : errmsg("precision for type float must be less than 54 bits"),
14563 : parser_errposition(@2)));
14564 : }
14565 : | /*EMPTY*/
14566 : {
14567 498 : $$ = SystemTypeName("float8");
14568 : }
14569 : ;
14570 :
14571 : /*
14572 : * SQL bit-field data types
14573 : * The following implements BIT() and BIT VARYING().
14574 : */
14575 : Bit: BitWithLength
14576 : {
14577 1696 : $$ = $1;
14578 : }
14579 : | BitWithoutLength
14580 : {
14581 198 : $$ = $1;
14582 : }
14583 : ;
14584 :
14585 : /* ConstBit is like Bit except "BIT" defaults to unspecified length */
14586 : /* See notes for ConstCharacter, which addresses same issue for "CHAR" */
14587 : ConstBit: BitWithLength
14588 : {
14589 0 : $$ = $1;
14590 : }
14591 : | BitWithoutLength
14592 : {
14593 0 : $$ = $1;
14594 0 : $$->typmods = NIL;
14595 : }
14596 : ;
14597 :
14598 : BitWithLength:
14599 : BIT opt_varying '(' expr_list ')'
14600 : {
14601 : char *typname;
14602 :
14603 1696 : typname = $2 ? "varbit" : "bit";
14604 1696 : $$ = SystemTypeName(typname);
14605 1696 : $$->typmods = $4;
14606 1696 : $$->location = @1;
14607 : }
14608 : ;
14609 :
14610 : BitWithoutLength:
14611 : BIT opt_varying
14612 : {
14613 : /* bit defaults to bit(1), varbit to no limit */
14614 198 : if ($2)
14615 : {
14616 20 : $$ = SystemTypeName("varbit");
14617 : }
14618 : else
14619 : {
14620 178 : $$ = SystemTypeName("bit");
14621 178 : $$->typmods = list_make1(makeIntConst(1, -1));
14622 : }
14623 198 : $$->location = @1;
14624 : }
14625 : ;
14626 :
14627 :
14628 : /*
14629 : * SQL character data types
14630 : * The following implements CHAR() and VARCHAR().
14631 : */
14632 : Character: CharacterWithLength
14633 : {
14634 1700 : $$ = $1;
14635 : }
14636 : | CharacterWithoutLength
14637 : {
14638 1206 : $$ = $1;
14639 : }
14640 : ;
14641 :
14642 : ConstCharacter: CharacterWithLength
14643 : {
14644 12 : $$ = $1;
14645 : }
14646 : | CharacterWithoutLength
14647 : {
14648 : /* Length was not specified so allow to be unrestricted.
14649 : * This handles problems with fixed-length (bpchar) strings
14650 : * which in column definitions must default to a length
14651 : * of one, but should not be constrained if the length
14652 : * was not specified.
14653 : */
14654 22 : $$ = $1;
14655 22 : $$->typmods = NIL;
14656 : }
14657 : ;
14658 :
14659 : CharacterWithLength: character '(' Iconst ')'
14660 : {
14661 1712 : $$ = SystemTypeName($1);
14662 1712 : $$->typmods = list_make1(makeIntConst($3, @3));
14663 1712 : $$->location = @1;
14664 : }
14665 : ;
14666 :
14667 : CharacterWithoutLength: character
14668 : {
14669 1228 : $$ = SystemTypeName($1);
14670 : /* char defaults to char(1), varchar to no limit */
14671 1228 : if (strcmp($1, "bpchar") == 0)
14672 252 : $$->typmods = list_make1(makeIntConst(1, -1));
14673 1228 : $$->location = @1;
14674 : }
14675 : ;
14676 :
14677 : character: CHARACTER opt_varying
14678 522 : { $$ = $2 ? "varchar": "bpchar"; }
14679 : | CHAR_P opt_varying
14680 1164 : { $$ = $2 ? "varchar": "bpchar"; }
14681 : | VARCHAR
14682 1250 : { $$ = "varchar"; }
14683 : | NATIONAL CHARACTER opt_varying
14684 0 : { $$ = $3 ? "varchar": "bpchar"; }
14685 : | NATIONAL CHAR_P opt_varying
14686 0 : { $$ = $3 ? "varchar": "bpchar"; }
14687 : | NCHAR opt_varying
14688 4 : { $$ = $2 ? "varchar": "bpchar"; }
14689 : ;
14690 :
14691 : opt_varying:
14692 418 : VARYING { $$ = true; }
14693 3166 : | /*EMPTY*/ { $$ = false; }
14694 : ;
14695 :
14696 : /*
14697 : * SQL date/time types
14698 : */
14699 : ConstDatetime:
14700 : TIMESTAMP '(' Iconst ')' opt_timezone
14701 : {
14702 124 : if ($5)
14703 100 : $$ = SystemTypeName("timestamptz");
14704 : else
14705 24 : $$ = SystemTypeName("timestamp");
14706 124 : $$->typmods = list_make1(makeIntConst($3, @3));
14707 124 : $$->location = @1;
14708 : }
14709 : | TIMESTAMP opt_timezone
14710 : {
14711 4822 : if ($2)
14712 1340 : $$ = SystemTypeName("timestamptz");
14713 : else
14714 3482 : $$ = SystemTypeName("timestamp");
14715 4822 : $$->location = @1;
14716 : }
14717 : | TIME '(' Iconst ')' opt_timezone
14718 : {
14719 22 : if ($5)
14720 8 : $$ = SystemTypeName("timetz");
14721 : else
14722 14 : $$ = SystemTypeName("time");
14723 22 : $$->typmods = list_make1(makeIntConst($3, @3));
14724 22 : $$->location = @1;
14725 : }
14726 : | TIME opt_timezone
14727 : {
14728 2352 : if ($2)
14729 344 : $$ = SystemTypeName("timetz");
14730 : else
14731 2008 : $$ = SystemTypeName("time");
14732 2352 : $$->location = @1;
14733 : }
14734 : ;
14735 :
14736 : ConstInterval:
14737 : INTERVAL
14738 : {
14739 6822 : $$ = SystemTypeName("interval");
14740 6822 : $$->location = @1;
14741 : }
14742 : ;
14743 :
14744 : opt_timezone:
14745 1792 : WITH_LA TIME ZONE { $$ = true; }
14746 592 : | WITHOUT_LA TIME ZONE { $$ = false; }
14747 4936 : | /*EMPTY*/ { $$ = false; }
14748 : ;
14749 :
14750 : opt_interval:
14751 : YEAR_P
14752 12 : { $$ = list_make1(makeIntConst(INTERVAL_MASK(YEAR), @1)); }
14753 : | MONTH_P
14754 18 : { $$ = list_make1(makeIntConst(INTERVAL_MASK(MONTH), @1)); }
14755 : | DAY_P
14756 18 : { $$ = list_make1(makeIntConst(INTERVAL_MASK(DAY), @1)); }
14757 : | HOUR_P
14758 12 : { $$ = list_make1(makeIntConst(INTERVAL_MASK(HOUR), @1)); }
14759 : | MINUTE_P
14760 12 : { $$ = list_make1(makeIntConst(INTERVAL_MASK(MINUTE), @1)); }
14761 : | interval_second
14762 36 : { $$ = $1; }
14763 : | YEAR_P TO MONTH_P
14764 : {
14765 18 : $$ = list_make1(makeIntConst(INTERVAL_MASK(YEAR) |
14766 : INTERVAL_MASK(MONTH), @1));
14767 : }
14768 : | DAY_P TO HOUR_P
14769 : {
14770 24 : $$ = list_make1(makeIntConst(INTERVAL_MASK(DAY) |
14771 : INTERVAL_MASK(HOUR), @1));
14772 : }
14773 : | DAY_P TO MINUTE_P
14774 : {
14775 24 : $$ = list_make1(makeIntConst(INTERVAL_MASK(DAY) |
14776 : INTERVAL_MASK(HOUR) |
14777 : INTERVAL_MASK(MINUTE), @1));
14778 : }
14779 : | DAY_P TO interval_second
14780 : {
14781 48 : $$ = $3;
14782 48 : linitial($$) = makeIntConst(INTERVAL_MASK(DAY) |
14783 : INTERVAL_MASK(HOUR) |
14784 : INTERVAL_MASK(MINUTE) |
14785 48 : INTERVAL_MASK(SECOND), @1);
14786 : }
14787 : | HOUR_P TO MINUTE_P
14788 : {
14789 18 : $$ = list_make1(makeIntConst(INTERVAL_MASK(HOUR) |
14790 : INTERVAL_MASK(MINUTE), @1));
14791 : }
14792 : | HOUR_P TO interval_second
14793 : {
14794 36 : $$ = $3;
14795 36 : linitial($$) = makeIntConst(INTERVAL_MASK(HOUR) |
14796 : INTERVAL_MASK(MINUTE) |
14797 36 : INTERVAL_MASK(SECOND), @1);
14798 : }
14799 : | MINUTE_P TO interval_second
14800 : {
14801 66 : $$ = $3;
14802 66 : linitial($$) = makeIntConst(INTERVAL_MASK(MINUTE) |
14803 66 : INTERVAL_MASK(SECOND), @1);
14804 : }
14805 : | /*EMPTY*/
14806 6468 : { $$ = NIL; }
14807 : ;
14808 :
14809 : interval_second:
14810 : SECOND_P
14811 : {
14812 102 : $$ = list_make1(makeIntConst(INTERVAL_MASK(SECOND), @1));
14813 : }
14814 : | SECOND_P '(' Iconst ')'
14815 : {
14816 84 : $$ = list_make2(makeIntConst(INTERVAL_MASK(SECOND), @1),
14817 : makeIntConst($3, @3));
14818 : }
14819 : ;
14820 :
14821 : JsonType:
14822 : JSON
14823 : {
14824 1924 : $$ = SystemTypeName("json");
14825 1924 : $$->location = @1;
14826 : }
14827 : ;
14828 :
14829 : /*****************************************************************************
14830 : *
14831 : * expression grammar
14832 : *
14833 : *****************************************************************************/
14834 :
14835 : /*
14836 : * General expressions
14837 : * This is the heart of the expression syntax.
14838 : *
14839 : * We have two expression types: a_expr is the unrestricted kind, and
14840 : * b_expr is a subset that must be used in some places to avoid shift/reduce
14841 : * conflicts. For example, we can't do BETWEEN as "BETWEEN a_expr AND a_expr"
14842 : * because that use of AND conflicts with AND as a boolean operator. So,
14843 : * b_expr is used in BETWEEN and we remove boolean keywords from b_expr.
14844 : *
14845 : * Note that '(' a_expr ')' is a b_expr, so an unrestricted expression can
14846 : * always be used by surrounding it with parens.
14847 : *
14848 : * c_expr is all the productions that are common to a_expr and b_expr;
14849 : * it's factored out just to eliminate redundant coding.
14850 : *
14851 : * Be careful of productions involving more than one terminal token.
14852 : * By default, bison will assign such productions the precedence of their
14853 : * last terminal, but in nearly all cases you want it to be the precedence
14854 : * of the first terminal instead; otherwise you will not get the behavior
14855 : * you expect! So we use %prec annotations freely to set precedences.
14856 : */
14857 3492544 : a_expr: c_expr { $$ = $1; }
14858 : | a_expr TYPECAST Typename
14859 196550 : { $$ = makeTypeCast($1, $3, @2); }
14860 : | a_expr COLLATE any_name
14861 : {
14862 8216 : CollateClause *n = makeNode(CollateClause);
14863 :
14864 8216 : n->arg = $1;
14865 8216 : n->collname = $3;
14866 8216 : n->location = @2;
14867 8216 : $$ = (Node *) n;
14868 : }
14869 : | a_expr AT TIME ZONE a_expr %prec AT
14870 : {
14871 396 : $$ = (Node *) makeFuncCall(SystemFuncName("timezone"),
14872 396 : list_make2($5, $1),
14873 : COERCE_SQL_SYNTAX,
14874 396 : @2);
14875 : }
14876 : | a_expr AT LOCAL %prec AT
14877 : {
14878 42 : $$ = (Node *) makeFuncCall(SystemFuncName("timezone"),
14879 42 : list_make1($1),
14880 : COERCE_SQL_SYNTAX,
14881 : -1);
14882 : }
14883 : /*
14884 : * These operators must be called out explicitly in order to make use
14885 : * of bison's automatic operator-precedence handling. All other
14886 : * operator names are handled by the generic productions using "Op",
14887 : * below; and all those operators will have the same precedence.
14888 : *
14889 : * If you add more explicitly-known operators, be sure to add them
14890 : * also to b_expr and to the MathOp list below.
14891 : */
14892 : | '+' a_expr %prec UMINUS
14893 12 : { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "+", NULL, $2, @1); }
14894 : | '-' a_expr %prec UMINUS
14895 27844 : { $$ = doNegate($2, @1); }
14896 : | a_expr '+' a_expr
14897 13492 : { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "+", $1, $3, @2); }
14898 : | a_expr '-' a_expr
14899 6154 : { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "-", $1, $3, @2); }
14900 : | a_expr '*' a_expr
14901 8516 : { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "*", $1, $3, @2); }
14902 : | a_expr '/' a_expr
14903 3756 : { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "/", $1, $3, @2); }
14904 : | a_expr '%' a_expr
14905 2708 : { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "%", $1, $3, @2); }
14906 : | a_expr '^' a_expr
14907 466 : { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "^", $1, $3, @2); }
14908 : | a_expr '<' a_expr
14909 23092 : { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "<", $1, $3, @2); }
14910 : | a_expr '>' a_expr
14911 32700 : { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, ">", $1, $3, @2); }
14912 : | a_expr '=' a_expr
14913 361748 : { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "=", $1, $3, @2); }
14914 : | a_expr LESS_EQUALS a_expr
14915 4882 : { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "<=", $1, $3, @2); }
14916 : | a_expr GREATER_EQUALS a_expr
14917 4876 : { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, ">=", $1, $3, @2); }
14918 : | a_expr NOT_EQUALS a_expr
14919 37728 : { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "<>", $1, $3, @2); }
14920 :
14921 : | a_expr qual_Op a_expr %prec Op
14922 55448 : { $$ = (Node *) makeA_Expr(AEXPR_OP, $2, $1, $3, @2); }
14923 : | qual_Op a_expr %prec Op
14924 192 : { $$ = (Node *) makeA_Expr(AEXPR_OP, $1, NULL, $2, @1); }
14925 :
14926 : | a_expr AND a_expr
14927 209604 : { $$ = makeAndExpr($1, $3, @2); }
14928 : | a_expr OR a_expr
14929 15438 : { $$ = makeOrExpr($1, $3, @2); }
14930 : | NOT a_expr
14931 14018 : { $$ = makeNotExpr($2, @1); }
14932 : | NOT_LA a_expr %prec NOT
14933 0 : { $$ = makeNotExpr($2, @1); }
14934 :
14935 : | a_expr LIKE a_expr
14936 : {
14937 1790 : $$ = (Node *) makeSimpleA_Expr(AEXPR_LIKE, "~~",
14938 1790 : $1, $3, @2);
14939 : }
14940 : | a_expr LIKE a_expr ESCAPE a_expr %prec LIKE
14941 : {
14942 96 : FuncCall *n = makeFuncCall(SystemFuncName("like_escape"),
14943 96 : list_make2($3, $5),
14944 : COERCE_EXPLICIT_CALL,
14945 96 : @2);
14946 96 : $$ = (Node *) makeSimpleA_Expr(AEXPR_LIKE, "~~",
14947 96 : $1, (Node *) n, @2);
14948 : }
14949 : | a_expr NOT_LA LIKE a_expr %prec NOT_LA
14950 : {
14951 198 : $$ = (Node *) makeSimpleA_Expr(AEXPR_LIKE, "!~~",
14952 198 : $1, $4, @2);
14953 : }
14954 : | a_expr NOT_LA LIKE a_expr ESCAPE a_expr %prec NOT_LA
14955 : {
14956 96 : FuncCall *n = makeFuncCall(SystemFuncName("like_escape"),
14957 96 : list_make2($4, $6),
14958 : COERCE_EXPLICIT_CALL,
14959 96 : @2);
14960 96 : $$ = (Node *) makeSimpleA_Expr(AEXPR_LIKE, "!~~",
14961 96 : $1, (Node *) n, @2);
14962 : }
14963 : | a_expr ILIKE a_expr
14964 : {
14965 172 : $$ = (Node *) makeSimpleA_Expr(AEXPR_ILIKE, "~~*",
14966 172 : $1, $3, @2);
14967 : }
14968 : | a_expr ILIKE a_expr ESCAPE a_expr %prec ILIKE
14969 : {
14970 0 : FuncCall *n = makeFuncCall(SystemFuncName("like_escape"),
14971 0 : list_make2($3, $5),
14972 : COERCE_EXPLICIT_CALL,
14973 0 : @2);
14974 0 : $$ = (Node *) makeSimpleA_Expr(AEXPR_ILIKE, "~~*",
14975 0 : $1, (Node *) n, @2);
14976 : }
14977 : | a_expr NOT_LA ILIKE a_expr %prec NOT_LA
14978 : {
14979 30 : $$ = (Node *) makeSimpleA_Expr(AEXPR_ILIKE, "!~~*",
14980 30 : $1, $4, @2);
14981 : }
14982 : | a_expr NOT_LA ILIKE a_expr ESCAPE a_expr %prec NOT_LA
14983 : {
14984 0 : FuncCall *n = makeFuncCall(SystemFuncName("like_escape"),
14985 0 : list_make2($4, $6),
14986 : COERCE_EXPLICIT_CALL,
14987 0 : @2);
14988 0 : $$ = (Node *) makeSimpleA_Expr(AEXPR_ILIKE, "!~~*",
14989 0 : $1, (Node *) n, @2);
14990 : }
14991 :
14992 : | a_expr SIMILAR TO a_expr %prec SIMILAR
14993 : {
14994 40 : FuncCall *n = makeFuncCall(SystemFuncName("similar_to_escape"),
14995 40 : list_make1($4),
14996 : COERCE_EXPLICIT_CALL,
14997 40 : @2);
14998 40 : $$ = (Node *) makeSimpleA_Expr(AEXPR_SIMILAR, "~",
14999 40 : $1, (Node *) n, @2);
15000 : }
15001 : | a_expr SIMILAR TO a_expr ESCAPE a_expr %prec SIMILAR
15002 : {
15003 30 : FuncCall *n = makeFuncCall(SystemFuncName("similar_to_escape"),
15004 30 : list_make2($4, $6),
15005 : COERCE_EXPLICIT_CALL,
15006 30 : @2);
15007 30 : $$ = (Node *) makeSimpleA_Expr(AEXPR_SIMILAR, "~",
15008 30 : $1, (Node *) n, @2);
15009 : }
15010 : | a_expr NOT_LA SIMILAR TO a_expr %prec NOT_LA
15011 : {
15012 0 : FuncCall *n = makeFuncCall(SystemFuncName("similar_to_escape"),
15013 0 : list_make1($5),
15014 : COERCE_EXPLICIT_CALL,
15015 0 : @2);
15016 0 : $$ = (Node *) makeSimpleA_Expr(AEXPR_SIMILAR, "!~",
15017 0 : $1, (Node *) n, @2);
15018 : }
15019 : | a_expr NOT_LA SIMILAR TO a_expr ESCAPE a_expr %prec NOT_LA
15020 : {
15021 0 : FuncCall *n = makeFuncCall(SystemFuncName("similar_to_escape"),
15022 0 : list_make2($5, $7),
15023 : COERCE_EXPLICIT_CALL,
15024 0 : @2);
15025 0 : $$ = (Node *) makeSimpleA_Expr(AEXPR_SIMILAR, "!~",
15026 0 : $1, (Node *) n, @2);
15027 : }
15028 :
15029 : /* NullTest clause
15030 : * Define SQL-style Null test clause.
15031 : * Allow two forms described in the standard:
15032 : * a IS NULL
15033 : * a IS NOT NULL
15034 : * Allow two SQL extensions
15035 : * a ISNULL
15036 : * a NOTNULL
15037 : */
15038 : | a_expr IS NULL_P %prec IS
15039 : {
15040 4944 : NullTest *n = makeNode(NullTest);
15041 :
15042 4944 : n->arg = (Expr *) $1;
15043 4944 : n->nulltesttype = IS_NULL;
15044 4944 : n->location = @2;
15045 4944 : $$ = (Node *) n;
15046 : }
15047 : | a_expr ISNULL
15048 : {
15049 96 : NullTest *n = makeNode(NullTest);
15050 :
15051 96 : n->arg = (Expr *) $1;
15052 96 : n->nulltesttype = IS_NULL;
15053 96 : n->location = @2;
15054 96 : $$ = (Node *) n;
15055 : }
15056 : | a_expr IS NOT NULL_P %prec IS
15057 : {
15058 10950 : NullTest *n = makeNode(NullTest);
15059 :
15060 10950 : n->arg = (Expr *) $1;
15061 10950 : n->nulltesttype = IS_NOT_NULL;
15062 10950 : n->location = @2;
15063 10950 : $$ = (Node *) n;
15064 : }
15065 : | a_expr NOTNULL
15066 : {
15067 6 : NullTest *n = makeNode(NullTest);
15068 :
15069 6 : n->arg = (Expr *) $1;
15070 6 : n->nulltesttype = IS_NOT_NULL;
15071 6 : n->location = @2;
15072 6 : $$ = (Node *) n;
15073 : }
15074 : | row OVERLAPS row
15075 : {
15076 876 : if (list_length($1) != 2)
15077 0 : ereport(ERROR,
15078 : (errcode(ERRCODE_SYNTAX_ERROR),
15079 : errmsg("wrong number of parameters on left side of OVERLAPS expression"),
15080 : parser_errposition(@1)));
15081 876 : if (list_length($3) != 2)
15082 0 : ereport(ERROR,
15083 : (errcode(ERRCODE_SYNTAX_ERROR),
15084 : errmsg("wrong number of parameters on right side of OVERLAPS expression"),
15085 : parser_errposition(@3)));
15086 876 : $$ = (Node *) makeFuncCall(SystemFuncName("overlaps"),
15087 876 : list_concat($1, $3),
15088 : COERCE_SQL_SYNTAX,
15089 876 : @2);
15090 : }
15091 : | a_expr IS TRUE_P %prec IS
15092 : {
15093 372 : BooleanTest *b = makeNode(BooleanTest);
15094 :
15095 372 : b->arg = (Expr *) $1;
15096 372 : b->booltesttype = IS_TRUE;
15097 372 : b->location = @2;
15098 372 : $$ = (Node *) b;
15099 : }
15100 : | a_expr IS NOT TRUE_P %prec IS
15101 : {
15102 140 : BooleanTest *b = makeNode(BooleanTest);
15103 :
15104 140 : b->arg = (Expr *) $1;
15105 140 : b->booltesttype = IS_NOT_TRUE;
15106 140 : b->location = @2;
15107 140 : $$ = (Node *) b;
15108 : }
15109 : | a_expr IS FALSE_P %prec IS
15110 : {
15111 102 : BooleanTest *b = makeNode(BooleanTest);
15112 :
15113 102 : b->arg = (Expr *) $1;
15114 102 : b->booltesttype = IS_FALSE;
15115 102 : b->location = @2;
15116 102 : $$ = (Node *) b;
15117 : }
15118 : | a_expr IS NOT FALSE_P %prec IS
15119 : {
15120 92 : BooleanTest *b = makeNode(BooleanTest);
15121 :
15122 92 : b->arg = (Expr *) $1;
15123 92 : b->booltesttype = IS_NOT_FALSE;
15124 92 : b->location = @2;
15125 92 : $$ = (Node *) b;
15126 : }
15127 : | a_expr IS UNKNOWN %prec IS
15128 : {
15129 52 : BooleanTest *b = makeNode(BooleanTest);
15130 :
15131 52 : b->arg = (Expr *) $1;
15132 52 : b->booltesttype = IS_UNKNOWN;
15133 52 : b->location = @2;
15134 52 : $$ = (Node *) b;
15135 : }
15136 : | a_expr IS NOT UNKNOWN %prec IS
15137 : {
15138 48 : BooleanTest *b = makeNode(BooleanTest);
15139 :
15140 48 : b->arg = (Expr *) $1;
15141 48 : b->booltesttype = IS_NOT_UNKNOWN;
15142 48 : b->location = @2;
15143 48 : $$ = (Node *) b;
15144 : }
15145 : | a_expr IS DISTINCT FROM a_expr %prec IS
15146 : {
15147 872 : $$ = (Node *) makeSimpleA_Expr(AEXPR_DISTINCT, "=", $1, $5, @2);
15148 : }
15149 : | a_expr IS NOT DISTINCT FROM a_expr %prec IS
15150 : {
15151 68 : $$ = (Node *) makeSimpleA_Expr(AEXPR_NOT_DISTINCT, "=", $1, $6, @2);
15152 : }
15153 : | a_expr BETWEEN opt_asymmetric b_expr AND a_expr %prec BETWEEN
15154 : {
15155 466 : $$ = (Node *) makeSimpleA_Expr(AEXPR_BETWEEN,
15156 : "BETWEEN",
15157 466 : $1,
15158 466 : (Node *) list_make2($4, $6),
15159 466 : @2);
15160 : }
15161 : | a_expr NOT_LA BETWEEN opt_asymmetric b_expr AND a_expr %prec NOT_LA
15162 : {
15163 12 : $$ = (Node *) makeSimpleA_Expr(AEXPR_NOT_BETWEEN,
15164 : "NOT BETWEEN",
15165 12 : $1,
15166 12 : (Node *) list_make2($5, $7),
15167 12 : @2);
15168 : }
15169 : | a_expr BETWEEN SYMMETRIC b_expr AND a_expr %prec BETWEEN
15170 : {
15171 12 : $$ = (Node *) makeSimpleA_Expr(AEXPR_BETWEEN_SYM,
15172 : "BETWEEN SYMMETRIC",
15173 12 : $1,
15174 12 : (Node *) list_make2($4, $6),
15175 12 : @2);
15176 : }
15177 : | a_expr NOT_LA BETWEEN SYMMETRIC b_expr AND a_expr %prec NOT_LA
15178 : {
15179 12 : $$ = (Node *) makeSimpleA_Expr(AEXPR_NOT_BETWEEN_SYM,
15180 : "NOT BETWEEN SYMMETRIC",
15181 12 : $1,
15182 12 : (Node *) list_make2($5, $7),
15183 12 : @2);
15184 : }
15185 : | a_expr IN_P in_expr
15186 : {
15187 : /* in_expr returns a SubLink or a list of a_exprs */
15188 18558 : if (IsA($3, SubLink))
15189 : {
15190 : /* generate foo = ANY (subquery) */
15191 2394 : SubLink *n = (SubLink *) $3;
15192 :
15193 2394 : n->subLinkType = ANY_SUBLINK;
15194 2394 : n->subLinkId = 0;
15195 2394 : n->testexpr = $1;
15196 2394 : n->operName = NIL; /* show it's IN not = ANY */
15197 2394 : n->location = @2;
15198 2394 : $$ = (Node *) n;
15199 : }
15200 : else
15201 : {
15202 : /* generate scalar IN expression */
15203 16164 : $$ = (Node *) makeSimpleA_Expr(AEXPR_IN, "=", $1, $3, @2);
15204 : }
15205 : }
15206 : | a_expr NOT_LA IN_P in_expr %prec NOT_LA
15207 : {
15208 : /* in_expr returns a SubLink or a list of a_exprs */
15209 4984 : if (IsA($4, SubLink))
15210 : {
15211 : /* generate NOT (foo = ANY (subquery)) */
15212 : /* Make an = ANY node */
15213 120 : SubLink *n = (SubLink *) $4;
15214 :
15215 120 : n->subLinkType = ANY_SUBLINK;
15216 120 : n->subLinkId = 0;
15217 120 : n->testexpr = $1;
15218 120 : n->operName = NIL; /* show it's IN not = ANY */
15219 120 : n->location = @2;
15220 : /* Stick a NOT on top; must have same parse location */
15221 120 : $$ = makeNotExpr((Node *) n, @2);
15222 : }
15223 : else
15224 : {
15225 : /* generate scalar NOT IN expression */
15226 4864 : $$ = (Node *) makeSimpleA_Expr(AEXPR_IN, "<>", $1, $4, @2);
15227 : }
15228 : }
15229 : | a_expr subquery_Op sub_type select_with_parens %prec Op
15230 : {
15231 166 : SubLink *n = makeNode(SubLink);
15232 :
15233 166 : n->subLinkType = $3;
15234 166 : n->subLinkId = 0;
15235 166 : n->testexpr = $1;
15236 166 : n->operName = $2;
15237 166 : n->subselect = $4;
15238 166 : n->location = @2;
15239 166 : $$ = (Node *) n;
15240 : }
15241 : | a_expr subquery_Op sub_type '(' a_expr ')' %prec Op
15242 : {
15243 15262 : if ($3 == ANY_SUBLINK)
15244 14962 : $$ = (Node *) makeA_Expr(AEXPR_OP_ANY, $2, $1, $5, @2);
15245 : else
15246 300 : $$ = (Node *) makeA_Expr(AEXPR_OP_ALL, $2, $1, $5, @2);
15247 : }
15248 : | UNIQUE opt_unique_null_treatment select_with_parens
15249 : {
15250 : /* Not sure how to get rid of the parentheses
15251 : * but there are lots of shift/reduce errors without them.
15252 : *
15253 : * Should be able to implement this by plopping the entire
15254 : * select into a node, then transforming the target expressions
15255 : * from whatever they are into count(*), and testing the
15256 : * entire result equal to one.
15257 : * But, will probably implement a separate node in the executor.
15258 : */
15259 0 : ereport(ERROR,
15260 : (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
15261 : errmsg("UNIQUE predicate is not yet implemented"),
15262 : parser_errposition(@1)));
15263 : }
15264 : | a_expr IS DOCUMENT_P %prec IS
15265 : {
15266 18 : $$ = makeXmlExpr(IS_DOCUMENT, NULL, NIL,
15267 18 : list_make1($1), @2);
15268 : }
15269 : | a_expr IS NOT DOCUMENT_P %prec IS
15270 : {
15271 18 : $$ = makeNotExpr(makeXmlExpr(IS_DOCUMENT, NULL, NIL,
15272 18 : list_make1($1), @2),
15273 18 : @2);
15274 : }
15275 : | a_expr IS NORMALIZED %prec IS
15276 : {
15277 12 : $$ = (Node *) makeFuncCall(SystemFuncName("is_normalized"),
15278 12 : list_make1($1),
15279 : COERCE_SQL_SYNTAX,
15280 12 : @2);
15281 : }
15282 : | a_expr IS unicode_normal_form NORMALIZED %prec IS
15283 : {
15284 36 : $$ = (Node *) makeFuncCall(SystemFuncName("is_normalized"),
15285 36 : list_make2($1, makeStringConst($3, @3)),
15286 : COERCE_SQL_SYNTAX,
15287 36 : @2);
15288 : }
15289 : | a_expr IS NOT NORMALIZED %prec IS
15290 : {
15291 0 : $$ = makeNotExpr((Node *) makeFuncCall(SystemFuncName("is_normalized"),
15292 0 : list_make1($1),
15293 : COERCE_SQL_SYNTAX,
15294 0 : @2),
15295 0 : @2);
15296 : }
15297 : | a_expr IS NOT unicode_normal_form NORMALIZED %prec IS
15298 : {
15299 0 : $$ = makeNotExpr((Node *) makeFuncCall(SystemFuncName("is_normalized"),
15300 0 : list_make2($1, makeStringConst($4, @4)),
15301 : COERCE_SQL_SYNTAX,
15302 0 : @2),
15303 0 : @2);
15304 : }
15305 : | a_expr IS json_predicate_type_constraint
15306 : json_key_uniqueness_constraint_opt %prec IS
15307 : {
15308 304 : JsonFormat *format = makeJsonFormat(JS_FORMAT_DEFAULT, JS_ENC_DEFAULT, -1);
15309 :
15310 304 : $$ = makeJsonIsPredicate($1, format, $3, $4, @1);
15311 : }
15312 : /*
15313 : * Required by SQL/JSON, but there are conflicts
15314 : | a_expr
15315 : json_format_clause
15316 : IS json_predicate_type_constraint
15317 : json_key_uniqueness_constraint_opt %prec IS
15318 : {
15319 : $$ = makeJsonIsPredicate($1, $2, $4, $5, @1);
15320 : }
15321 : */
15322 : | a_expr IS NOT
15323 : json_predicate_type_constraint
15324 : json_key_uniqueness_constraint_opt %prec IS
15325 : {
15326 46 : JsonFormat *format = makeJsonFormat(JS_FORMAT_DEFAULT, JS_ENC_DEFAULT, -1);
15327 :
15328 46 : $$ = makeNotExpr(makeJsonIsPredicate($1, format, $4, $5, @1), @1);
15329 : }
15330 : /*
15331 : * Required by SQL/JSON, but there are conflicts
15332 : | a_expr
15333 : json_format_clause
15334 : IS NOT
15335 : json_predicate_type_constraint
15336 : json_key_uniqueness_constraint_opt %prec IS
15337 : {
15338 : $$ = makeNotExpr(makeJsonIsPredicate($1, $2, $5, $6, @1), @1);
15339 : }
15340 : */
15341 : | DEFAULT
15342 : {
15343 : /*
15344 : * The SQL spec only allows DEFAULT in "contextually typed
15345 : * expressions", but for us, it's easier to allow it in
15346 : * any a_expr and then throw error during parse analysis
15347 : * if it's in an inappropriate context. This way also
15348 : * lets us say something smarter than "syntax error".
15349 : */
15350 1410 : SetToDefault *n = makeNode(SetToDefault);
15351 :
15352 : /* parse analysis will fill in the rest */
15353 1410 : n->location = @1;
15354 1410 : $$ = (Node *) n;
15355 : }
15356 : ;
15357 :
15358 : /*
15359 : * Restricted expressions
15360 : *
15361 : * b_expr is a subset of the complete expression syntax defined by a_expr.
15362 : *
15363 : * Presently, AND, NOT, IS, and IN are the a_expr keywords that would
15364 : * cause trouble in the places where b_expr is used. For simplicity, we
15365 : * just eliminate all the boolean-keyword-operator productions from b_expr.
15366 : */
15367 : b_expr: c_expr
15368 3510 : { $$ = $1; }
15369 : | b_expr TYPECAST Typename
15370 134 : { $$ = makeTypeCast($1, $3, @2); }
15371 : | '+' b_expr %prec UMINUS
15372 0 : { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "+", NULL, $2, @1); }
15373 : | '-' b_expr %prec UMINUS
15374 66 : { $$ = doNegate($2, @1); }
15375 : | b_expr '+' b_expr
15376 30 : { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "+", $1, $3, @2); }
15377 : | b_expr '-' b_expr
15378 12 : { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "-", $1, $3, @2); }
15379 : | b_expr '*' b_expr
15380 12 : { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "*", $1, $3, @2); }
15381 : | b_expr '/' b_expr
15382 0 : { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "/", $1, $3, @2); }
15383 : | b_expr '%' b_expr
15384 0 : { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "%", $1, $3, @2); }
15385 : | b_expr '^' b_expr
15386 6 : { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "^", $1, $3, @2); }
15387 : | b_expr '<' b_expr
15388 0 : { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "<", $1, $3, @2); }
15389 : | b_expr '>' b_expr
15390 0 : { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, ">", $1, $3, @2); }
15391 : | b_expr '=' b_expr
15392 0 : { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "=", $1, $3, @2); }
15393 : | b_expr LESS_EQUALS b_expr
15394 0 : { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "<=", $1, $3, @2); }
15395 : | b_expr GREATER_EQUALS b_expr
15396 0 : { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, ">=", $1, $3, @2); }
15397 : | b_expr NOT_EQUALS b_expr
15398 0 : { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "<>", $1, $3, @2); }
15399 : | b_expr qual_Op b_expr %prec Op
15400 12 : { $$ = (Node *) makeA_Expr(AEXPR_OP, $2, $1, $3, @2); }
15401 : | qual_Op b_expr %prec Op
15402 0 : { $$ = (Node *) makeA_Expr(AEXPR_OP, $1, NULL, $2, @1); }
15403 : | b_expr IS DISTINCT FROM b_expr %prec IS
15404 : {
15405 0 : $$ = (Node *) makeSimpleA_Expr(AEXPR_DISTINCT, "=", $1, $5, @2);
15406 : }
15407 : | b_expr IS NOT DISTINCT FROM b_expr %prec IS
15408 : {
15409 0 : $$ = (Node *) makeSimpleA_Expr(AEXPR_NOT_DISTINCT, "=", $1, $6, @2);
15410 : }
15411 : | b_expr IS DOCUMENT_P %prec IS
15412 : {
15413 0 : $$ = makeXmlExpr(IS_DOCUMENT, NULL, NIL,
15414 0 : list_make1($1), @2);
15415 : }
15416 : | b_expr IS NOT DOCUMENT_P %prec IS
15417 : {
15418 0 : $$ = makeNotExpr(makeXmlExpr(IS_DOCUMENT, NULL, NIL,
15419 0 : list_make1($1), @2),
15420 0 : @2);
15421 : }
15422 : ;
15423 :
15424 : /*
15425 : * Productions that can be used in both a_expr and b_expr.
15426 : *
15427 : * Note: productions that refer recursively to a_expr or b_expr mostly
15428 : * cannot appear here. However, it's OK to refer to a_exprs that occur
15429 : * inside parentheses, such as function arguments; that cannot introduce
15430 : * ambiguity to the b_expr syntax.
15431 : */
15432 1608056 : c_expr: columnref { $$ = $1; }
15433 1161090 : | AexprConst { $$ = $1; }
15434 : | PARAM opt_indirection
15435 : {
15436 148398 : ParamRef *p = makeNode(ParamRef);
15437 :
15438 148398 : p->number = $1;
15439 148398 : p->location = @1;
15440 148398 : if ($2)
15441 : {
15442 1198 : A_Indirection *n = makeNode(A_Indirection);
15443 :
15444 1198 : n->arg = (Node *) p;
15445 1198 : n->indirection = check_indirection($2, yyscanner);
15446 1198 : $$ = (Node *) n;
15447 : }
15448 : else
15449 147200 : $$ = (Node *) p;
15450 : }
15451 : | '(' a_expr ')' opt_indirection
15452 : {
15453 83870 : if ($4)
15454 : {
15455 11122 : A_Indirection *n = makeNode(A_Indirection);
15456 :
15457 11122 : n->arg = $2;
15458 11122 : n->indirection = check_indirection($4, yyscanner);
15459 11122 : $$ = (Node *) n;
15460 : }
15461 : else
15462 72748 : $$ = $2;
15463 : }
15464 : | case_expr
15465 54806 : { $$ = $1; }
15466 : | func_expr
15467 389272 : { $$ = $1; }
15468 : | select_with_parens %prec UMINUS
15469 : {
15470 24618 : SubLink *n = makeNode(SubLink);
15471 :
15472 24618 : n->subLinkType = EXPR_SUBLINK;
15473 24618 : n->subLinkId = 0;
15474 24618 : n->testexpr = NULL;
15475 24618 : n->operName = NIL;
15476 24618 : n->subselect = $1;
15477 24618 : n->location = @1;
15478 24618 : $$ = (Node *) n;
15479 : }
15480 : | select_with_parens indirection
15481 : {
15482 : /*
15483 : * Because the select_with_parens nonterminal is designed
15484 : * to "eat" as many levels of parens as possible, the
15485 : * '(' a_expr ')' opt_indirection production above will
15486 : * fail to match a sub-SELECT with indirection decoration;
15487 : * the sub-SELECT won't be regarded as an a_expr as long
15488 : * as there are parens around it. To support applying
15489 : * subscripting or field selection to a sub-SELECT result,
15490 : * we need this redundant-looking production.
15491 : */
15492 18 : SubLink *n = makeNode(SubLink);
15493 18 : A_Indirection *a = makeNode(A_Indirection);
15494 :
15495 18 : n->subLinkType = EXPR_SUBLINK;
15496 18 : n->subLinkId = 0;
15497 18 : n->testexpr = NULL;
15498 18 : n->operName = NIL;
15499 18 : n->subselect = $1;
15500 18 : n->location = @1;
15501 18 : a->arg = (Node *) n;
15502 18 : a->indirection = check_indirection($2, yyscanner);
15503 18 : $$ = (Node *) a;
15504 : }
15505 : | EXISTS select_with_parens
15506 : {
15507 5252 : SubLink *n = makeNode(SubLink);
15508 :
15509 5252 : n->subLinkType = EXISTS_SUBLINK;
15510 5252 : n->subLinkId = 0;
15511 5252 : n->testexpr = NULL;
15512 5252 : n->operName = NIL;
15513 5252 : n->subselect = $2;
15514 5252 : n->location = @1;
15515 5252 : $$ = (Node *) n;
15516 : }
15517 : | ARRAY select_with_parens
15518 : {
15519 7666 : SubLink *n = makeNode(SubLink);
15520 :
15521 7666 : n->subLinkType = ARRAY_SUBLINK;
15522 7666 : n->subLinkId = 0;
15523 7666 : n->testexpr = NULL;
15524 7666 : n->operName = NIL;
15525 7666 : n->subselect = $2;
15526 7666 : n->location = @1;
15527 7666 : $$ = (Node *) n;
15528 : }
15529 : | ARRAY array_expr
15530 : {
15531 7140 : A_ArrayExpr *n = castNode(A_ArrayExpr, $2);
15532 :
15533 : /* point outermost A_ArrayExpr to the ARRAY keyword */
15534 7140 : n->location = @1;
15535 7140 : $$ = (Node *) n;
15536 : }
15537 : | explicit_row
15538 : {
15539 3844 : RowExpr *r = makeNode(RowExpr);
15540 :
15541 3844 : r->args = $1;
15542 3844 : r->row_typeid = InvalidOid; /* not analyzed yet */
15543 3844 : r->colnames = NIL; /* to be filled in during analysis */
15544 3844 : r->row_format = COERCE_EXPLICIT_CALL; /* abuse */
15545 3844 : r->location = @1;
15546 3844 : $$ = (Node *) r;
15547 : }
15548 : | implicit_row
15549 : {
15550 2312 : RowExpr *r = makeNode(RowExpr);
15551 :
15552 2312 : r->args = $1;
15553 2312 : r->row_typeid = InvalidOid; /* not analyzed yet */
15554 2312 : r->colnames = NIL; /* to be filled in during analysis */
15555 2312 : r->row_format = COERCE_IMPLICIT_CAST; /* abuse */
15556 2312 : r->location = @1;
15557 2312 : $$ = (Node *) r;
15558 : }
15559 : | GROUPING '(' expr_list ')'
15560 : {
15561 362 : GroupingFunc *g = makeNode(GroupingFunc);
15562 :
15563 362 : g->args = $3;
15564 362 : g->location = @1;
15565 362 : $$ = (Node *) g;
15566 : }
15567 : ;
15568 :
15569 : func_application: func_name '(' ')'
15570 : {
15571 48348 : $$ = (Node *) makeFuncCall($1, NIL,
15572 : COERCE_EXPLICIT_CALL,
15573 48348 : @1);
15574 : }
15575 : | func_name '(' func_arg_list opt_sort_clause ')'
15576 : {
15577 302144 : FuncCall *n = makeFuncCall($1, $3,
15578 : COERCE_EXPLICIT_CALL,
15579 302144 : @1);
15580 :
15581 302144 : n->agg_order = $4;
15582 302144 : $$ = (Node *) n;
15583 : }
15584 : | func_name '(' VARIADIC func_arg_expr opt_sort_clause ')'
15585 : {
15586 584 : FuncCall *n = makeFuncCall($1, list_make1($4),
15587 : COERCE_EXPLICIT_CALL,
15588 584 : @1);
15589 :
15590 584 : n->func_variadic = true;
15591 584 : n->agg_order = $5;
15592 584 : $$ = (Node *) n;
15593 : }
15594 : | func_name '(' func_arg_list ',' VARIADIC func_arg_expr opt_sort_clause ')'
15595 : {
15596 120 : FuncCall *n = makeFuncCall($1, lappend($3, $6),
15597 : COERCE_EXPLICIT_CALL,
15598 120 : @1);
15599 :
15600 120 : n->func_variadic = true;
15601 120 : n->agg_order = $7;
15602 120 : $$ = (Node *) n;
15603 : }
15604 : | func_name '(' ALL func_arg_list opt_sort_clause ')'
15605 : {
15606 0 : FuncCall *n = makeFuncCall($1, $4,
15607 : COERCE_EXPLICIT_CALL,
15608 0 : @1);
15609 :
15610 0 : n->agg_order = $5;
15611 : /* Ideally we'd mark the FuncCall node to indicate
15612 : * "must be an aggregate", but there's no provision
15613 : * for that in FuncCall at the moment.
15614 : */
15615 0 : $$ = (Node *) n;
15616 : }
15617 : | func_name '(' DISTINCT func_arg_list opt_sort_clause ')'
15618 : {
15619 526 : FuncCall *n = makeFuncCall($1, $4,
15620 : COERCE_EXPLICIT_CALL,
15621 526 : @1);
15622 :
15623 526 : n->agg_order = $5;
15624 526 : n->agg_distinct = true;
15625 526 : $$ = (Node *) n;
15626 : }
15627 : | func_name '(' '*' ')'
15628 : {
15629 : /*
15630 : * We consider AGGREGATE(*) to invoke a parameterless
15631 : * aggregate. This does the right thing for COUNT(*),
15632 : * and there are no other aggregates in SQL that accept
15633 : * '*' as parameter.
15634 : *
15635 : * The FuncCall node is also marked agg_star = true,
15636 : * so that later processing can detect what the argument
15637 : * really was.
15638 : */
15639 12038 : FuncCall *n = makeFuncCall($1, NIL,
15640 : COERCE_EXPLICIT_CALL,
15641 12038 : @1);
15642 :
15643 12038 : n->agg_star = true;
15644 12038 : $$ = (Node *) n;
15645 : }
15646 : ;
15647 :
15648 :
15649 : /*
15650 : * func_expr and its cousin func_expr_windowless are split out from c_expr just
15651 : * so that we have classifications for "everything that is a function call or
15652 : * looks like one". This isn't very important, but it saves us having to
15653 : * document which variants are legal in places like "FROM function()" or the
15654 : * backwards-compatible functional-index syntax for CREATE INDEX.
15655 : * (Note that many of the special SQL functions wouldn't actually make any
15656 : * sense as functional index entries, but we ignore that consideration here.)
15657 : */
15658 : func_expr: func_application within_group_clause filter_clause over_clause
15659 : {
15660 319886 : FuncCall *n = (FuncCall *) $1;
15661 :
15662 : /*
15663 : * The order clause for WITHIN GROUP and the one for
15664 : * plain-aggregate ORDER BY share a field, so we have to
15665 : * check here that at most one is present. We also check
15666 : * for DISTINCT and VARIADIC here to give a better error
15667 : * location. Other consistency checks are deferred to
15668 : * parse analysis.
15669 : */
15670 319886 : if ($2 != NIL)
15671 : {
15672 348 : if (n->agg_order != NIL)
15673 6 : ereport(ERROR,
15674 : (errcode(ERRCODE_SYNTAX_ERROR),
15675 : errmsg("cannot use multiple ORDER BY clauses with WITHIN GROUP"),
15676 : parser_errposition(@2)));
15677 342 : if (n->agg_distinct)
15678 0 : ereport(ERROR,
15679 : (errcode(ERRCODE_SYNTAX_ERROR),
15680 : errmsg("cannot use DISTINCT with WITHIN GROUP"),
15681 : parser_errposition(@2)));
15682 342 : if (n->func_variadic)
15683 0 : ereport(ERROR,
15684 : (errcode(ERRCODE_SYNTAX_ERROR),
15685 : errmsg("cannot use VARIADIC with WITHIN GROUP"),
15686 : parser_errposition(@2)));
15687 342 : n->agg_order = $2;
15688 342 : n->agg_within_group = true;
15689 : }
15690 319880 : n->agg_filter = $3;
15691 319880 : n->over = $4;
15692 319880 : $$ = (Node *) n;
15693 : }
15694 : | json_aggregate_func filter_clause over_clause
15695 : {
15696 720 : JsonAggConstructor *n = IsA($1, JsonObjectAgg) ?
15697 360 : ((JsonObjectAgg *) $1)->constructor :
15698 156 : ((JsonArrayAgg *) $1)->constructor;
15699 :
15700 360 : n->agg_filter = $2;
15701 360 : n->over = $3;
15702 360 : $$ = (Node *) $1;
15703 : }
15704 : | func_expr_common_subexpr
15705 69032 : { $$ = $1; }
15706 : ;
15707 :
15708 : /*
15709 : * Like func_expr but does not accept WINDOW functions directly
15710 : * (but they can still be contained in arguments for functions etc).
15711 : * Use this when window expressions are not allowed, where needed to
15712 : * disambiguate the grammar (e.g. in CREATE INDEX).
15713 : */
15714 : func_expr_windowless:
15715 43266 : func_application { $$ = $1; }
15716 402 : | func_expr_common_subexpr { $$ = $1; }
15717 0 : | json_aggregate_func { $$ = $1; }
15718 : ;
15719 :
15720 : /*
15721 : * Special expressions that are considered to be functions.
15722 : */
15723 : func_expr_common_subexpr:
15724 : COLLATION FOR '(' a_expr ')'
15725 : {
15726 30 : $$ = (Node *) makeFuncCall(SystemFuncName("pg_collation_for"),
15727 30 : list_make1($4),
15728 : COERCE_SQL_SYNTAX,
15729 30 : @1);
15730 : }
15731 : | CURRENT_DATE
15732 : {
15733 288 : $$ = makeSQLValueFunction(SVFOP_CURRENT_DATE, -1, @1);
15734 : }
15735 : | CURRENT_TIME
15736 : {
15737 24 : $$ = makeSQLValueFunction(SVFOP_CURRENT_TIME, -1, @1);
15738 : }
15739 : | CURRENT_TIME '(' Iconst ')'
15740 : {
15741 24 : $$ = makeSQLValueFunction(SVFOP_CURRENT_TIME_N, $3, @1);
15742 : }
15743 : | CURRENT_TIMESTAMP
15744 : {
15745 288 : $$ = makeSQLValueFunction(SVFOP_CURRENT_TIMESTAMP, -1, @1);
15746 : }
15747 : | CURRENT_TIMESTAMP '(' Iconst ')'
15748 : {
15749 116 : $$ = makeSQLValueFunction(SVFOP_CURRENT_TIMESTAMP_N, $3, @1);
15750 : }
15751 : | LOCALTIME
15752 : {
15753 24 : $$ = makeSQLValueFunction(SVFOP_LOCALTIME, -1, @1);
15754 : }
15755 : | LOCALTIME '(' Iconst ')'
15756 : {
15757 24 : $$ = makeSQLValueFunction(SVFOP_LOCALTIME_N, $3, @1);
15758 : }
15759 : | LOCALTIMESTAMP
15760 : {
15761 36 : $$ = makeSQLValueFunction(SVFOP_LOCALTIMESTAMP, -1, @1);
15762 : }
15763 : | LOCALTIMESTAMP '(' Iconst ')'
15764 : {
15765 24 : $$ = makeSQLValueFunction(SVFOP_LOCALTIMESTAMP_N, $3, @1);
15766 : }
15767 : | CURRENT_ROLE
15768 : {
15769 116 : $$ = makeSQLValueFunction(SVFOP_CURRENT_ROLE, -1, @1);
15770 : }
15771 : | CURRENT_USER
15772 : {
15773 980 : $$ = makeSQLValueFunction(SVFOP_CURRENT_USER, -1, @1);
15774 : }
15775 : | SESSION_USER
15776 : {
15777 620 : $$ = makeSQLValueFunction(SVFOP_SESSION_USER, -1, @1);
15778 : }
15779 : | SYSTEM_USER
15780 : {
15781 20 : $$ = (Node *) makeFuncCall(SystemFuncName("system_user"),
15782 : NIL,
15783 : COERCE_SQL_SYNTAX,
15784 : @1);
15785 : }
15786 : | USER
15787 : {
15788 24 : $$ = makeSQLValueFunction(SVFOP_USER, -1, @1);
15789 : }
15790 : | CURRENT_CATALOG
15791 : {
15792 36 : $$ = makeSQLValueFunction(SVFOP_CURRENT_CATALOG, -1, @1);
15793 : }
15794 : | CURRENT_SCHEMA
15795 : {
15796 30 : $$ = makeSQLValueFunction(SVFOP_CURRENT_SCHEMA, -1, @1);
15797 : }
15798 : | CAST '(' a_expr AS Typename ')'
15799 56042 : { $$ = makeTypeCast($3, $5, @1); }
15800 : | EXTRACT '(' extract_list ')'
15801 : {
15802 1282 : $$ = (Node *) makeFuncCall(SystemFuncName("extract"),
15803 1282 : $3,
15804 : COERCE_SQL_SYNTAX,
15805 1282 : @1);
15806 : }
15807 : | NORMALIZE '(' a_expr ')'
15808 : {
15809 18 : $$ = (Node *) makeFuncCall(SystemFuncName("normalize"),
15810 18 : list_make1($3),
15811 : COERCE_SQL_SYNTAX,
15812 18 : @1);
15813 : }
15814 : | NORMALIZE '(' a_expr ',' unicode_normal_form ')'
15815 : {
15816 36 : $$ = (Node *) makeFuncCall(SystemFuncName("normalize"),
15817 36 : list_make2($3, makeStringConst($5, @5)),
15818 : COERCE_SQL_SYNTAX,
15819 36 : @1);
15820 : }
15821 : | OVERLAY '(' overlay_list ')'
15822 : {
15823 82 : $$ = (Node *) makeFuncCall(SystemFuncName("overlay"),
15824 82 : $3,
15825 : COERCE_SQL_SYNTAX,
15826 82 : @1);
15827 : }
15828 : | OVERLAY '(' func_arg_list_opt ')'
15829 : {
15830 : /*
15831 : * allow functions named overlay() to be called without
15832 : * special syntax
15833 : */
15834 0 : $$ = (Node *) makeFuncCall(list_make1(makeString("overlay")),
15835 0 : $3,
15836 : COERCE_EXPLICIT_CALL,
15837 0 : @1);
15838 : }
15839 : | POSITION '(' position_list ')'
15840 : {
15841 : /*
15842 : * position(A in B) is converted to position(B, A)
15843 : *
15844 : * We deliberately don't offer a "plain syntax" option
15845 : * for position(), because the reversal of the arguments
15846 : * creates too much risk of confusion.
15847 : */
15848 360 : $$ = (Node *) makeFuncCall(SystemFuncName("position"),
15849 360 : $3,
15850 : COERCE_SQL_SYNTAX,
15851 360 : @1);
15852 : }
15853 : | SUBSTRING '(' substr_list ')'
15854 : {
15855 : /* substring(A from B for C) is converted to
15856 : * substring(A, B, C) - thomas 2000-11-28
15857 : */
15858 670 : $$ = (Node *) makeFuncCall(SystemFuncName("substring"),
15859 670 : $3,
15860 : COERCE_SQL_SYNTAX,
15861 670 : @1);
15862 : }
15863 : | SUBSTRING '(' func_arg_list_opt ')'
15864 : {
15865 : /*
15866 : * allow functions named substring() to be called without
15867 : * special syntax
15868 : */
15869 198 : $$ = (Node *) makeFuncCall(list_make1(makeString("substring")),
15870 198 : $3,
15871 : COERCE_EXPLICIT_CALL,
15872 198 : @1);
15873 : }
15874 : | TREAT '(' a_expr AS Typename ')'
15875 : {
15876 : /* TREAT(expr AS target) converts expr of a particular type to target,
15877 : * which is defined to be a subtype of the original expression.
15878 : * In SQL99, this is intended for use with structured UDTs,
15879 : * but let's make this a generally useful form allowing stronger
15880 : * coercions than are handled by implicit casting.
15881 : *
15882 : * Convert SystemTypeName() to SystemFuncName() even though
15883 : * at the moment they result in the same thing.
15884 : */
15885 0 : $$ = (Node *) makeFuncCall(SystemFuncName(strVal(llast($5->names))),
15886 0 : list_make1($3),
15887 : COERCE_EXPLICIT_CALL,
15888 0 : @1);
15889 : }
15890 : | TRIM '(' BOTH trim_list ')'
15891 : {
15892 : /* various trim expressions are defined in SQL
15893 : * - thomas 1997-07-19
15894 : */
15895 12 : $$ = (Node *) makeFuncCall(SystemFuncName("btrim"),
15896 12 : $4,
15897 : COERCE_SQL_SYNTAX,
15898 12 : @1);
15899 : }
15900 : | TRIM '(' LEADING trim_list ')'
15901 : {
15902 24 : $$ = (Node *) makeFuncCall(SystemFuncName("ltrim"),
15903 24 : $4,
15904 : COERCE_SQL_SYNTAX,
15905 24 : @1);
15906 : }
15907 : | TRIM '(' TRAILING trim_list ')'
15908 : {
15909 564 : $$ = (Node *) makeFuncCall(SystemFuncName("rtrim"),
15910 564 : $4,
15911 : COERCE_SQL_SYNTAX,
15912 564 : @1);
15913 : }
15914 : | TRIM '(' trim_list ')'
15915 : {
15916 98 : $$ = (Node *) makeFuncCall(SystemFuncName("btrim"),
15917 98 : $3,
15918 : COERCE_SQL_SYNTAX,
15919 98 : @1);
15920 : }
15921 : | NULLIF '(' a_expr ',' a_expr ')'
15922 : {
15923 252 : $$ = (Node *) makeSimpleA_Expr(AEXPR_NULLIF, "=", $3, $5, @1);
15924 : }
15925 : | COALESCE '(' expr_list ')'
15926 : {
15927 2948 : CoalesceExpr *c = makeNode(CoalesceExpr);
15928 :
15929 2948 : c->args = $3;
15930 2948 : c->location = @1;
15931 2948 : $$ = (Node *) c;
15932 : }
15933 : | GREATEST '(' expr_list ')'
15934 : {
15935 140 : MinMaxExpr *v = makeNode(MinMaxExpr);
15936 :
15937 140 : v->args = $3;
15938 140 : v->op = IS_GREATEST;
15939 140 : v->location = @1;
15940 140 : $$ = (Node *) v;
15941 : }
15942 : | LEAST '(' expr_list ')'
15943 : {
15944 142 : MinMaxExpr *v = makeNode(MinMaxExpr);
15945 :
15946 142 : v->args = $3;
15947 142 : v->op = IS_LEAST;
15948 142 : v->location = @1;
15949 142 : $$ = (Node *) v;
15950 : }
15951 : | XMLCONCAT '(' expr_list ')'
15952 : {
15953 62 : $$ = makeXmlExpr(IS_XMLCONCAT, NULL, NIL, $3, @1);
15954 : }
15955 : | XMLELEMENT '(' NAME_P ColLabel ')'
15956 : {
15957 6 : $$ = makeXmlExpr(IS_XMLELEMENT, $4, NIL, NIL, @1);
15958 : }
15959 : | XMLELEMENT '(' NAME_P ColLabel ',' xml_attributes ')'
15960 : {
15961 36 : $$ = makeXmlExpr(IS_XMLELEMENT, $4, $6, NIL, @1);
15962 : }
15963 : | XMLELEMENT '(' NAME_P ColLabel ',' expr_list ')'
15964 : {
15965 116 : $$ = makeXmlExpr(IS_XMLELEMENT, $4, NIL, $6, @1);
15966 : }
15967 : | XMLELEMENT '(' NAME_P ColLabel ',' xml_attributes ',' expr_list ')'
15968 : {
15969 20 : $$ = makeXmlExpr(IS_XMLELEMENT, $4, $6, $8, @1);
15970 : }
15971 : | XMLEXISTS '(' c_expr xmlexists_argument ')'
15972 : {
15973 : /* xmlexists(A PASSING [BY REF] B [BY REF]) is
15974 : * converted to xmlexists(A, B)*/
15975 54 : $$ = (Node *) makeFuncCall(SystemFuncName("xmlexists"),
15976 54 : list_make2($3, $4),
15977 : COERCE_SQL_SYNTAX,
15978 54 : @1);
15979 : }
15980 : | XMLFOREST '(' xml_attribute_list ')'
15981 : {
15982 32 : $$ = makeXmlExpr(IS_XMLFOREST, NULL, $3, NIL, @1);
15983 : }
15984 : | XMLPARSE '(' document_or_content a_expr xml_whitespace_option ')'
15985 : {
15986 : XmlExpr *x = (XmlExpr *)
15987 140 : makeXmlExpr(IS_XMLPARSE, NULL, NIL,
15988 140 : list_make2($4, makeBoolAConst($5, -1)),
15989 140 : @1);
15990 :
15991 140 : x->xmloption = $3;
15992 140 : $$ = (Node *) x;
15993 : }
15994 : | XMLPI '(' NAME_P ColLabel ')'
15995 : {
15996 30 : $$ = makeXmlExpr(IS_XMLPI, $4, NULL, NIL, @1);
15997 : }
15998 : | XMLPI '(' NAME_P ColLabel ',' a_expr ')'
15999 : {
16000 50 : $$ = makeXmlExpr(IS_XMLPI, $4, NULL, list_make1($6), @1);
16001 : }
16002 : | XMLROOT '(' a_expr ',' xml_root_version opt_xml_root_standalone ')'
16003 : {
16004 68 : $$ = makeXmlExpr(IS_XMLROOT, NULL, NIL,
16005 68 : list_make3($3, $5, $6), @1);
16006 : }
16007 : | XMLSERIALIZE '(' document_or_content a_expr AS SimpleTypename xml_indent_option ')'
16008 : {
16009 202 : XmlSerialize *n = makeNode(XmlSerialize);
16010 :
16011 202 : n->xmloption = $3;
16012 202 : n->expr = $4;
16013 202 : n->typeName = $6;
16014 202 : n->indent = $7;
16015 202 : n->location = @1;
16016 202 : $$ = (Node *) n;
16017 : }
16018 : | JSON_OBJECT '(' func_arg_list ')'
16019 : {
16020 : /* Support for legacy (non-standard) json_object() */
16021 90 : $$ = (Node *) makeFuncCall(SystemFuncName("json_object"),
16022 90 : $3, COERCE_EXPLICIT_CALL, @1);
16023 : }
16024 : | JSON_OBJECT '(' json_name_and_value_list
16025 : json_object_constructor_null_clause_opt
16026 : json_key_uniqueness_constraint_opt
16027 : json_returning_clause_opt ')'
16028 : {
16029 342 : JsonObjectConstructor *n = makeNode(JsonObjectConstructor);
16030 :
16031 342 : n->exprs = $3;
16032 342 : n->absent_on_null = $4;
16033 342 : n->unique = $5;
16034 342 : n->output = (JsonOutput *) $6;
16035 342 : n->location = @1;
16036 342 : $$ = (Node *) n;
16037 : }
16038 : | JSON_OBJECT '(' json_returning_clause_opt ')'
16039 : {
16040 92 : JsonObjectConstructor *n = makeNode(JsonObjectConstructor);
16041 :
16042 92 : n->exprs = NULL;
16043 92 : n->absent_on_null = false;
16044 92 : n->unique = false;
16045 92 : n->output = (JsonOutput *) $3;
16046 92 : n->location = @1;
16047 92 : $$ = (Node *) n;
16048 : }
16049 : | JSON_ARRAY '('
16050 : json_value_expr_list
16051 : json_array_constructor_null_clause_opt
16052 : json_returning_clause_opt
16053 : ')'
16054 : {
16055 108 : JsonArrayConstructor *n = makeNode(JsonArrayConstructor);
16056 :
16057 108 : n->exprs = $3;
16058 108 : n->absent_on_null = $4;
16059 108 : n->output = (JsonOutput *) $5;
16060 108 : n->location = @1;
16061 108 : $$ = (Node *) n;
16062 : }
16063 : | JSON_ARRAY '('
16064 : select_no_parens
16065 : json_format_clause_opt
16066 : /* json_array_constructor_null_clause_opt */
16067 : json_returning_clause_opt
16068 : ')'
16069 : {
16070 54 : JsonArrayQueryConstructor *n = makeNode(JsonArrayQueryConstructor);
16071 :
16072 54 : n->query = $3;
16073 54 : n->format = (JsonFormat *) $4;
16074 54 : n->absent_on_null = true; /* XXX */
16075 54 : n->output = (JsonOutput *) $5;
16076 54 : n->location = @1;
16077 54 : $$ = (Node *) n;
16078 : }
16079 : | JSON_ARRAY '('
16080 : json_returning_clause_opt
16081 : ')'
16082 : {
16083 86 : JsonArrayConstructor *n = makeNode(JsonArrayConstructor);
16084 :
16085 86 : n->exprs = NIL;
16086 86 : n->absent_on_null = true;
16087 86 : n->output = (JsonOutput *) $3;
16088 86 : n->location = @1;
16089 86 : $$ = (Node *) n;
16090 : }
16091 : | JSON '(' json_value_expr json_key_uniqueness_constraint_opt ')'
16092 : {
16093 164 : JsonParseExpr *n = makeNode(JsonParseExpr);
16094 :
16095 164 : n->expr = (JsonValueExpr *) $3;
16096 164 : n->unique_keys = $4;
16097 164 : n->output = NULL;
16098 164 : n->location = @1;
16099 164 : $$ = (Node *) n;
16100 : }
16101 : | JSON_SCALAR '(' a_expr ')'
16102 : {
16103 112 : JsonScalarExpr *n = makeNode(JsonScalarExpr);
16104 :
16105 112 : n->expr = (Expr *) $3;
16106 112 : n->output = NULL;
16107 112 : n->location = @1;
16108 112 : $$ = (Node *) n;
16109 : }
16110 : | JSON_SERIALIZE '(' json_value_expr json_returning_clause_opt ')'
16111 : {
16112 108 : JsonSerializeExpr *n = makeNode(JsonSerializeExpr);
16113 :
16114 108 : n->expr = (JsonValueExpr *) $3;
16115 108 : n->output = (JsonOutput *) $4;
16116 108 : n->location = @1;
16117 108 : $$ = (Node *) n;
16118 : }
16119 : | MERGE_ACTION '(' ')'
16120 : {
16121 180 : MergeSupportFunc *m = makeNode(MergeSupportFunc);
16122 :
16123 180 : m->msftype = TEXTOID;
16124 180 : m->location = @1;
16125 180 : $$ = (Node *) m;
16126 : }
16127 : | JSON_QUERY '('
16128 : json_value_expr ',' a_expr json_passing_clause_opt
16129 : json_returning_clause_opt
16130 : json_wrapper_behavior
16131 : json_quotes_clause_opt
16132 : json_behavior_clause_opt
16133 : ')'
16134 : {
16135 966 : JsonFuncExpr *n = makeNode(JsonFuncExpr);
16136 :
16137 966 : n->op = JSON_QUERY_OP;
16138 966 : n->context_item = (JsonValueExpr *) $3;
16139 966 : n->pathspec = $5;
16140 966 : n->passing = $6;
16141 966 : n->output = (JsonOutput *) $7;
16142 966 : n->wrapper = $8;
16143 966 : n->quotes = $9;
16144 966 : n->on_empty = (JsonBehavior *) linitial($10);
16145 966 : n->on_error = (JsonBehavior *) lsecond($10);
16146 966 : n->location = @1;
16147 966 : $$ = (Node *) n;
16148 : }
16149 : | JSON_EXISTS '('
16150 : json_value_expr ',' a_expr json_passing_clause_opt
16151 : json_on_error_clause_opt
16152 : ')'
16153 : {
16154 168 : JsonFuncExpr *n = makeNode(JsonFuncExpr);
16155 :
16156 168 : n->op = JSON_EXISTS_OP;
16157 168 : n->context_item = (JsonValueExpr *) $3;
16158 168 : n->pathspec = $5;
16159 168 : n->passing = $6;
16160 168 : n->output = NULL;
16161 168 : n->on_error = (JsonBehavior *) $7;
16162 168 : n->location = @1;
16163 168 : $$ = (Node *) n;
16164 : }
16165 : | JSON_VALUE '('
16166 : json_value_expr ',' a_expr json_passing_clause_opt
16167 : json_returning_clause_opt
16168 : json_behavior_clause_opt
16169 : ')'
16170 : {
16171 576 : JsonFuncExpr *n = makeNode(JsonFuncExpr);
16172 :
16173 576 : n->op = JSON_VALUE_OP;
16174 576 : n->context_item = (JsonValueExpr *) $3;
16175 576 : n->pathspec = $5;
16176 576 : n->passing = $6;
16177 576 : n->output = (JsonOutput *) $7;
16178 576 : n->on_empty = (JsonBehavior *) linitial($8);
16179 576 : n->on_error = (JsonBehavior *) lsecond($8);
16180 576 : n->location = @1;
16181 576 : $$ = (Node *) n;
16182 : }
16183 : ;
16184 :
16185 :
16186 : /*
16187 : * SQL/XML support
16188 : */
16189 : xml_root_version: VERSION_P a_expr
16190 24 : { $$ = $2; }
16191 : | VERSION_P NO VALUE_P
16192 44 : { $$ = makeNullAConst(-1); }
16193 : ;
16194 :
16195 : opt_xml_root_standalone: ',' STANDALONE_P YES_P
16196 26 : { $$ = makeIntConst(XML_STANDALONE_YES, -1); }
16197 : | ',' STANDALONE_P NO
16198 12 : { $$ = makeIntConst(XML_STANDALONE_NO, -1); }
16199 : | ',' STANDALONE_P NO VALUE_P
16200 12 : { $$ = makeIntConst(XML_STANDALONE_NO_VALUE, -1); }
16201 : | /*EMPTY*/
16202 18 : { $$ = makeIntConst(XML_STANDALONE_OMITTED, -1); }
16203 : ;
16204 :
16205 56 : xml_attributes: XMLATTRIBUTES '(' xml_attribute_list ')' { $$ = $3; }
16206 : ;
16207 :
16208 88 : xml_attribute_list: xml_attribute_el { $$ = list_make1($1); }
16209 144 : | xml_attribute_list ',' xml_attribute_el { $$ = lappend($1, $3); }
16210 : ;
16211 :
16212 : xml_attribute_el: a_expr AS ColLabel
16213 : {
16214 106 : $$ = makeNode(ResTarget);
16215 106 : $$->name = $3;
16216 106 : $$->indirection = NIL;
16217 106 : $$->val = (Node *) $1;
16218 106 : $$->location = @1;
16219 : }
16220 : | a_expr
16221 : {
16222 126 : $$ = makeNode(ResTarget);
16223 126 : $$->name = NULL;
16224 126 : $$->indirection = NIL;
16225 126 : $$->val = (Node *) $1;
16226 126 : $$->location = @1;
16227 : }
16228 : ;
16229 :
16230 170 : document_or_content: DOCUMENT_P { $$ = XMLOPTION_DOCUMENT; }
16231 188 : | CONTENT_P { $$ = XMLOPTION_CONTENT; }
16232 : ;
16233 :
16234 132 : xml_indent_option: INDENT { $$ = true; }
16235 24 : | NO INDENT { $$ = false; }
16236 46 : | /*EMPTY*/ { $$ = false; }
16237 : ;
16238 :
16239 0 : xml_whitespace_option: PRESERVE WHITESPACE_P { $$ = true; }
16240 2 : | STRIP_P WHITESPACE_P { $$ = false; }
16241 138 : | /*EMPTY*/ { $$ = false; }
16242 : ;
16243 :
16244 : /* We allow several variants for SQL and other compatibility. */
16245 : xmlexists_argument:
16246 : PASSING c_expr
16247 : {
16248 226 : $$ = $2;
16249 : }
16250 : | PASSING c_expr xml_passing_mech
16251 : {
16252 0 : $$ = $2;
16253 : }
16254 : | PASSING xml_passing_mech c_expr
16255 : {
16256 42 : $$ = $3;
16257 : }
16258 : | PASSING xml_passing_mech c_expr xml_passing_mech
16259 : {
16260 6 : $$ = $3;
16261 : }
16262 : ;
16263 :
16264 : xml_passing_mech:
16265 : BY REF_P
16266 : | BY VALUE_P
16267 : ;
16268 :
16269 :
16270 : /*
16271 : * Aggregate decoration clauses
16272 : */
16273 : within_group_clause:
16274 348 : WITHIN GROUP_P '(' sort_clause ')' { $$ = $4; }
16275 319544 : | /*EMPTY*/ { $$ = NIL; }
16276 : ;
16277 :
16278 : filter_clause:
16279 836 : FILTER '(' WHERE a_expr ')' { $$ = $4; }
16280 319416 : | /*EMPTY*/ { $$ = NULL; }
16281 : ;
16282 :
16283 :
16284 : /*
16285 : * Window Definitions
16286 : */
16287 : window_clause:
16288 528 : WINDOW window_definition_list { $$ = $2; }
16289 476522 : | /*EMPTY*/ { $$ = NIL; }
16290 : ;
16291 :
16292 : window_definition_list:
16293 528 : window_definition { $$ = list_make1($1); }
16294 : | window_definition_list ',' window_definition
16295 12 : { $$ = lappend($1, $3); }
16296 : ;
16297 :
16298 : window_definition:
16299 : ColId AS window_specification
16300 : {
16301 540 : WindowDef *n = $3;
16302 :
16303 540 : n->name = $1;
16304 540 : $$ = n;
16305 : }
16306 : ;
16307 :
16308 : over_clause: OVER window_specification
16309 2506 : { $$ = $2; }
16310 : | OVER ColId
16311 : {
16312 942 : WindowDef *n = makeNode(WindowDef);
16313 :
16314 942 : n->name = $2;
16315 942 : n->refname = NULL;
16316 942 : n->partitionClause = NIL;
16317 942 : n->orderClause = NIL;
16318 942 : n->frameOptions = FRAMEOPTION_DEFAULTS;
16319 942 : n->startOffset = NULL;
16320 942 : n->endOffset = NULL;
16321 942 : n->location = @2;
16322 942 : $$ = n;
16323 : }
16324 : | /*EMPTY*/
16325 316798 : { $$ = NULL; }
16326 : ;
16327 :
16328 : window_specification: '(' opt_existing_window_name opt_partition_clause
16329 : opt_sort_clause opt_frame_clause ')'
16330 : {
16331 3046 : WindowDef *n = makeNode(WindowDef);
16332 :
16333 3046 : n->name = NULL;
16334 3046 : n->refname = $2;
16335 3046 : n->partitionClause = $3;
16336 3046 : n->orderClause = $4;
16337 : /* copy relevant fields of opt_frame_clause */
16338 3046 : n->frameOptions = $5->frameOptions;
16339 3046 : n->startOffset = $5->startOffset;
16340 3046 : n->endOffset = $5->endOffset;
16341 3046 : n->location = @1;
16342 3046 : $$ = n;
16343 : }
16344 : ;
16345 :
16346 : /*
16347 : * If we see PARTITION, RANGE, ROWS or GROUPS as the first token after the '('
16348 : * of a window_specification, we want the assumption to be that there is
16349 : * no existing_window_name; but those keywords are unreserved and so could
16350 : * be ColIds. We fix this by making them have the same precedence as IDENT
16351 : * and giving the empty production here a slightly higher precedence, so
16352 : * that the shift/reduce conflict is resolved in favor of reducing the rule.
16353 : * These keywords are thus precluded from being an existing_window_name but
16354 : * are not reserved for any other purpose.
16355 : */
16356 30 : opt_existing_window_name: ColId { $$ = $1; }
16357 3022 : | /*EMPTY*/ %prec Op { $$ = NULL; }
16358 : ;
16359 :
16360 838 : opt_partition_clause: PARTITION BY expr_list { $$ = $3; }
16361 2208 : | /*EMPTY*/ { $$ = NIL; }
16362 : ;
16363 :
16364 : /*
16365 : * For frame clauses, we return a WindowDef, but only some fields are used:
16366 : * frameOptions, startOffset, and endOffset.
16367 : */
16368 : opt_frame_clause:
16369 : RANGE frame_extent opt_window_exclusion_clause
16370 : {
16371 796 : WindowDef *n = $2;
16372 :
16373 796 : n->frameOptions |= FRAMEOPTION_NONDEFAULT | FRAMEOPTION_RANGE;
16374 796 : n->frameOptions |= $3;
16375 796 : $$ = n;
16376 : }
16377 : | ROWS frame_extent opt_window_exclusion_clause
16378 : {
16379 618 : WindowDef *n = $2;
16380 :
16381 618 : n->frameOptions |= FRAMEOPTION_NONDEFAULT | FRAMEOPTION_ROWS;
16382 618 : n->frameOptions |= $3;
16383 618 : $$ = n;
16384 : }
16385 : | GROUPS frame_extent opt_window_exclusion_clause
16386 : {
16387 204 : WindowDef *n = $2;
16388 :
16389 204 : n->frameOptions |= FRAMEOPTION_NONDEFAULT | FRAMEOPTION_GROUPS;
16390 204 : n->frameOptions |= $3;
16391 204 : $$ = n;
16392 : }
16393 : | /*EMPTY*/
16394 : {
16395 1428 : WindowDef *n = makeNode(WindowDef);
16396 :
16397 1428 : n->frameOptions = FRAMEOPTION_DEFAULTS;
16398 1428 : n->startOffset = NULL;
16399 1428 : n->endOffset = NULL;
16400 1428 : $$ = n;
16401 : }
16402 : ;
16403 :
16404 : frame_extent: frame_bound
16405 : {
16406 6 : WindowDef *n = $1;
16407 :
16408 : /* reject invalid cases */
16409 6 : if (n->frameOptions & FRAMEOPTION_START_UNBOUNDED_FOLLOWING)
16410 0 : ereport(ERROR,
16411 : (errcode(ERRCODE_WINDOWING_ERROR),
16412 : errmsg("frame start cannot be UNBOUNDED FOLLOWING"),
16413 : parser_errposition(@1)));
16414 6 : if (n->frameOptions & FRAMEOPTION_START_OFFSET_FOLLOWING)
16415 0 : ereport(ERROR,
16416 : (errcode(ERRCODE_WINDOWING_ERROR),
16417 : errmsg("frame starting from following row cannot end with current row"),
16418 : parser_errposition(@1)));
16419 6 : n->frameOptions |= FRAMEOPTION_END_CURRENT_ROW;
16420 6 : $$ = n;
16421 : }
16422 : | BETWEEN frame_bound AND frame_bound
16423 : {
16424 1612 : WindowDef *n1 = $2;
16425 1612 : WindowDef *n2 = $4;
16426 :
16427 : /* form merged options */
16428 1612 : int frameOptions = n1->frameOptions;
16429 : /* shift converts START_ options to END_ options */
16430 1612 : frameOptions |= n2->frameOptions << 1;
16431 1612 : frameOptions |= FRAMEOPTION_BETWEEN;
16432 : /* reject invalid cases */
16433 1612 : if (frameOptions & FRAMEOPTION_START_UNBOUNDED_FOLLOWING)
16434 0 : ereport(ERROR,
16435 : (errcode(ERRCODE_WINDOWING_ERROR),
16436 : errmsg("frame start cannot be UNBOUNDED FOLLOWING"),
16437 : parser_errposition(@2)));
16438 1612 : if (frameOptions & FRAMEOPTION_END_UNBOUNDED_PRECEDING)
16439 0 : ereport(ERROR,
16440 : (errcode(ERRCODE_WINDOWING_ERROR),
16441 : errmsg("frame end cannot be UNBOUNDED PRECEDING"),
16442 : parser_errposition(@4)));
16443 1612 : if ((frameOptions & FRAMEOPTION_START_CURRENT_ROW) &&
16444 460 : (frameOptions & FRAMEOPTION_END_OFFSET_PRECEDING))
16445 0 : ereport(ERROR,
16446 : (errcode(ERRCODE_WINDOWING_ERROR),
16447 : errmsg("frame starting from current row cannot have preceding rows"),
16448 : parser_errposition(@4)));
16449 1612 : if ((frameOptions & FRAMEOPTION_START_OFFSET_FOLLOWING) &&
16450 168 : (frameOptions & (FRAMEOPTION_END_OFFSET_PRECEDING |
16451 : FRAMEOPTION_END_CURRENT_ROW)))
16452 0 : ereport(ERROR,
16453 : (errcode(ERRCODE_WINDOWING_ERROR),
16454 : errmsg("frame starting from following row cannot have preceding rows"),
16455 : parser_errposition(@4)));
16456 1612 : n1->frameOptions = frameOptions;
16457 1612 : n1->endOffset = n2->startOffset;
16458 1612 : $$ = n1;
16459 : }
16460 : ;
16461 :
16462 : /*
16463 : * This is used for both frame start and frame end, with output set up on
16464 : * the assumption it's frame start; the frame_extent productions must reject
16465 : * invalid cases.
16466 : */
16467 : frame_bound:
16468 : UNBOUNDED PRECEDING
16469 : {
16470 198 : WindowDef *n = makeNode(WindowDef);
16471 :
16472 198 : n->frameOptions = FRAMEOPTION_START_UNBOUNDED_PRECEDING;
16473 198 : n->startOffset = NULL;
16474 198 : n->endOffset = NULL;
16475 198 : $$ = n;
16476 : }
16477 : | UNBOUNDED FOLLOWING
16478 : {
16479 376 : WindowDef *n = makeNode(WindowDef);
16480 :
16481 376 : n->frameOptions = FRAMEOPTION_START_UNBOUNDED_FOLLOWING;
16482 376 : n->startOffset = NULL;
16483 376 : n->endOffset = NULL;
16484 376 : $$ = n;
16485 : }
16486 : | CURRENT_P ROW
16487 : {
16488 604 : WindowDef *n = makeNode(WindowDef);
16489 :
16490 604 : n->frameOptions = FRAMEOPTION_START_CURRENT_ROW;
16491 604 : n->startOffset = NULL;
16492 604 : n->endOffset = NULL;
16493 604 : $$ = n;
16494 : }
16495 : | a_expr PRECEDING
16496 : {
16497 900 : WindowDef *n = makeNode(WindowDef);
16498 :
16499 900 : n->frameOptions = FRAMEOPTION_START_OFFSET_PRECEDING;
16500 900 : n->startOffset = $1;
16501 900 : n->endOffset = NULL;
16502 900 : $$ = n;
16503 : }
16504 : | a_expr FOLLOWING
16505 : {
16506 1152 : WindowDef *n = makeNode(WindowDef);
16507 :
16508 1152 : n->frameOptions = FRAMEOPTION_START_OFFSET_FOLLOWING;
16509 1152 : n->startOffset = $1;
16510 1152 : n->endOffset = NULL;
16511 1152 : $$ = n;
16512 : }
16513 : ;
16514 :
16515 : opt_window_exclusion_clause:
16516 84 : EXCLUDE CURRENT_P ROW { $$ = FRAMEOPTION_EXCLUDE_CURRENT_ROW; }
16517 96 : | EXCLUDE GROUP_P { $$ = FRAMEOPTION_EXCLUDE_GROUP; }
16518 150 : | EXCLUDE TIES { $$ = FRAMEOPTION_EXCLUDE_TIES; }
16519 18 : | EXCLUDE NO OTHERS { $$ = 0; }
16520 1270 : | /*EMPTY*/ { $$ = 0; }
16521 : ;
16522 :
16523 :
16524 : /*
16525 : * Supporting nonterminals for expressions.
16526 : */
16527 :
16528 : /* Explicit row production.
16529 : *
16530 : * SQL99 allows an optional ROW keyword, so we can now do single-element rows
16531 : * without conflicting with the parenthesized a_expr production. Without the
16532 : * ROW keyword, there must be more than one a_expr inside the parens.
16533 : */
16534 0 : row: ROW '(' expr_list ')' { $$ = $3; }
16535 0 : | ROW '(' ')' { $$ = NIL; }
16536 1752 : | '(' expr_list ',' a_expr ')' { $$ = lappend($2, $4); }
16537 : ;
16538 :
16539 3814 : explicit_row: ROW '(' expr_list ')' { $$ = $3; }
16540 30 : | ROW '(' ')' { $$ = NIL; }
16541 : ;
16542 :
16543 2312 : implicit_row: '(' expr_list ',' a_expr ')' { $$ = lappend($2, $4); }
16544 : ;
16545 :
16546 15104 : sub_type: ANY { $$ = ANY_SUBLINK; }
16547 0 : | SOME { $$ = ANY_SUBLINK; }
16548 324 : | ALL { $$ = ALL_SUBLINK; }
16549 : ;
16550 :
16551 10962 : all_Op: Op { $$ = $1; }
16552 25324 : | MathOp { $$ = $1; }
16553 : ;
16554 :
16555 40 : MathOp: '+' { $$ = "+"; }
16556 46 : | '-' { $$ = "-"; }
16557 12 : | '*' { $$ = "*"; }
16558 0 : | '/' { $$ = "/"; }
16559 8 : | '%' { $$ = "%"; }
16560 0 : | '^' { $$ = "^"; }
16561 752 : | '<' { $$ = "<"; }
16562 594 : | '>' { $$ = ">"; }
16563 22064 : | '=' { $$ = "="; }
16564 618 : | LESS_EQUALS { $$ = "<="; }
16565 610 : | GREATER_EQUALS { $$ = ">="; }
16566 580 : | NOT_EQUALS { $$ = "<>"; }
16567 : ;
16568 :
16569 : qual_Op: Op
16570 41264 : { $$ = list_make1(makeString($1)); }
16571 : | OPERATOR '(' any_operator ')'
16572 14394 : { $$ = $3; }
16573 : ;
16574 :
16575 : qual_all_Op:
16576 : all_Op
16577 1414 : { $$ = list_make1(makeString($1)); }
16578 : | OPERATOR '(' any_operator ')'
16579 34 : { $$ = $3; }
16580 : ;
16581 :
16582 : subquery_Op:
16583 : all_Op
16584 15160 : { $$ = list_make1(makeString($1)); }
16585 : | OPERATOR '(' any_operator ')'
16586 236 : { $$ = $3; }
16587 : | LIKE
16588 24 : { $$ = list_make1(makeString("~~")); }
16589 : | NOT_LA LIKE
16590 12 : { $$ = list_make1(makeString("!~~")); }
16591 : | ILIKE
16592 12 : { $$ = list_make1(makeString("~~*")); }
16593 : | NOT_LA ILIKE
16594 0 : { $$ = list_make1(makeString("!~~*")); }
16595 : /* cannot put SIMILAR TO here, because SIMILAR TO is a hack.
16596 : * the regular expression is preprocessed by a function (similar_to_escape),
16597 : * and the ~ operator for posix regular expressions is used.
16598 : * x SIMILAR TO y -> x ~ similar_to_escape(y)
16599 : * this transformation is made on the fly by the parser upwards.
16600 : * however the SubLink structure which handles any/some/all stuff
16601 : * is not ready for such a thing.
16602 : */
16603 : ;
16604 :
16605 : expr_list: a_expr
16606 : {
16607 159108 : $$ = list_make1($1);
16608 : }
16609 : | expr_list ',' a_expr
16610 : {
16611 143952 : $$ = lappend($1, $3);
16612 : }
16613 : ;
16614 :
16615 : /* function arguments can have names */
16616 : func_arg_list: func_arg_expr
16617 : {
16618 303078 : $$ = list_make1($1);
16619 : }
16620 : | func_arg_list ',' func_arg_expr
16621 : {
16622 220426 : $$ = lappend($1, $3);
16623 : }
16624 : ;
16625 :
16626 : func_arg_expr: a_expr
16627 : {
16628 475912 : $$ = $1;
16629 : }
16630 : | param_name COLON_EQUALS a_expr
16631 : {
16632 45778 : NamedArgExpr *na = makeNode(NamedArgExpr);
16633 :
16634 45778 : na->name = $1;
16635 45778 : na->arg = (Expr *) $3;
16636 45778 : na->argnumber = -1; /* until determined */
16637 45778 : na->location = @1;
16638 45778 : $$ = (Node *) na;
16639 : }
16640 : | param_name EQUALS_GREATER a_expr
16641 : {
16642 2518 : NamedArgExpr *na = makeNode(NamedArgExpr);
16643 :
16644 2518 : na->name = $1;
16645 2518 : na->arg = (Expr *) $3;
16646 2518 : na->argnumber = -1; /* until determined */
16647 2518 : na->location = @1;
16648 2518 : $$ = (Node *) na;
16649 : }
16650 : ;
16651 :
16652 198 : func_arg_list_opt: func_arg_list { $$ = $1; }
16653 0 : | /*EMPTY*/ { $$ = NIL; }
16654 : ;
16655 :
16656 1700 : type_list: Typename { $$ = list_make1($1); }
16657 392 : | type_list ',' Typename { $$ = lappend($1, $3); }
16658 : ;
16659 :
16660 : array_expr: '[' expr_list ']'
16661 : {
16662 7382 : $$ = makeAArrayExpr($2, @1);
16663 : }
16664 : | '[' array_expr_list ']'
16665 : {
16666 406 : $$ = makeAArrayExpr($2, @1);
16667 : }
16668 : | '[' ']'
16669 : {
16670 88 : $$ = makeAArrayExpr(NIL, @1);
16671 : }
16672 : ;
16673 :
16674 406 : array_expr_list: array_expr { $$ = list_make1($1); }
16675 330 : | array_expr_list ',' array_expr { $$ = lappend($1, $3); }
16676 : ;
16677 :
16678 :
16679 : extract_list:
16680 : extract_arg FROM a_expr
16681 : {
16682 1282 : $$ = list_make2(makeStringConst($1, @1), $3);
16683 : }
16684 : ;
16685 :
16686 : /* Allow delimited string Sconst in extract_arg as an SQL extension.
16687 : * - thomas 2001-04-12
16688 : */
16689 : extract_arg:
16690 1036 : IDENT { $$ = $1; }
16691 60 : | YEAR_P { $$ = "year"; }
16692 42 : | MONTH_P { $$ = "month"; }
16693 54 : | DAY_P { $$ = "day"; }
16694 30 : | HOUR_P { $$ = "hour"; }
16695 30 : | MINUTE_P { $$ = "minute"; }
16696 30 : | SECOND_P { $$ = "second"; }
16697 0 : | Sconst { $$ = $1; }
16698 : ;
16699 :
16700 : unicode_normal_form:
16701 24 : NFC { $$ = "NFC"; }
16702 12 : | NFD { $$ = "NFD"; }
16703 18 : | NFKC { $$ = "NFKC"; }
16704 18 : | NFKD { $$ = "NFKD"; }
16705 : ;
16706 :
16707 : /* OVERLAY() arguments */
16708 : overlay_list:
16709 : a_expr PLACING a_expr FROM a_expr FOR a_expr
16710 : {
16711 : /* overlay(A PLACING B FROM C FOR D) is converted to overlay(A, B, C, D) */
16712 34 : $$ = list_make4($1, $3, $5, $7);
16713 : }
16714 : | a_expr PLACING a_expr FROM a_expr
16715 : {
16716 : /* overlay(A PLACING B FROM C) is converted to overlay(A, B, C) */
16717 48 : $$ = list_make3($1, $3, $5);
16718 : }
16719 : ;
16720 :
16721 : /* position_list uses b_expr not a_expr to avoid conflict with general IN */
16722 : position_list:
16723 360 : b_expr IN_P b_expr { $$ = list_make2($3, $1); }
16724 : ;
16725 :
16726 : /*
16727 : * SUBSTRING() arguments
16728 : *
16729 : * Note that SQL:1999 has both
16730 : * text FROM int FOR int
16731 : * and
16732 : * text FROM pattern FOR escape
16733 : *
16734 : * In the parser we map them both to a call to the substring() function and
16735 : * rely on type resolution to pick the right one.
16736 : *
16737 : * In SQL:2003, the second variant was changed to
16738 : * text SIMILAR pattern ESCAPE escape
16739 : * We could in theory map that to a different function internally, but
16740 : * since we still support the SQL:1999 version, we don't. However,
16741 : * ruleutils.c will reverse-list the call in the newer style.
16742 : */
16743 : substr_list:
16744 : a_expr FROM a_expr FOR a_expr
16745 : {
16746 122 : $$ = list_make3($1, $3, $5);
16747 : }
16748 : | a_expr FOR a_expr FROM a_expr
16749 : {
16750 : /* not legal per SQL, but might as well allow it */
16751 0 : $$ = list_make3($1, $5, $3);
16752 : }
16753 : | a_expr FROM a_expr
16754 : {
16755 : /*
16756 : * Because we aren't restricting data types here, this
16757 : * syntax can end up resolving to textregexsubstr().
16758 : * We've historically allowed that to happen, so continue
16759 : * to accept it. However, ruleutils.c will reverse-list
16760 : * such a call in regular function call syntax.
16761 : */
16762 340 : $$ = list_make2($1, $3);
16763 : }
16764 : | a_expr FOR a_expr
16765 : {
16766 : /* not legal per SQL */
16767 :
16768 : /*
16769 : * Since there are no cases where this syntax allows
16770 : * a textual FOR value, we forcibly cast the argument
16771 : * to int4. The possible matches in pg_proc are
16772 : * substring(text,int4) and substring(text,text),
16773 : * and we don't want the parser to choose the latter,
16774 : * which it is likely to do if the second argument
16775 : * is unknown or doesn't have an implicit cast to int4.
16776 : */
16777 36 : $$ = list_make3($1, makeIntConst(1, -1),
16778 : makeTypeCast($3,
16779 : SystemTypeName("int4"), -1));
16780 : }
16781 : | a_expr SIMILAR a_expr ESCAPE a_expr
16782 : {
16783 172 : $$ = list_make3($1, $3, $5);
16784 : }
16785 : ;
16786 :
16787 588 : trim_list: a_expr FROM expr_list { $$ = lappend($3, $1); }
16788 24 : | FROM expr_list { $$ = $2; }
16789 86 : | expr_list { $$ = $1; }
16790 : ;
16791 :
16792 : in_expr: select_with_parens
16793 : {
16794 2514 : SubLink *n = makeNode(SubLink);
16795 :
16796 2514 : n->subselect = $1;
16797 : /* other fields will be filled later */
16798 2514 : $$ = (Node *) n;
16799 : }
16800 21028 : | '(' expr_list ')' { $$ = (Node *) $2; }
16801 : ;
16802 :
16803 : /*
16804 : * Define SQL-style CASE clause.
16805 : * - Full specification
16806 : * CASE WHEN a = b THEN c ... ELSE d END
16807 : * - Implicit argument
16808 : * CASE a WHEN b THEN c ... ELSE d END
16809 : */
16810 : case_expr: CASE case_arg when_clause_list case_default END_P
16811 : {
16812 54806 : CaseExpr *c = makeNode(CaseExpr);
16813 :
16814 54806 : c->casetype = InvalidOid; /* not analyzed yet */
16815 54806 : c->arg = (Expr *) $2;
16816 54806 : c->args = $3;
16817 54806 : c->defresult = (Expr *) $4;
16818 54806 : c->location = @1;
16819 54806 : $$ = (Node *) c;
16820 : }
16821 : ;
16822 :
16823 : when_clause_list:
16824 : /* There must be at least one */
16825 54806 : when_clause { $$ = list_make1($1); }
16826 43314 : | when_clause_list when_clause { $$ = lappend($1, $2); }
16827 : ;
16828 :
16829 : when_clause:
16830 : WHEN a_expr THEN a_expr
16831 : {
16832 98120 : CaseWhen *w = makeNode(CaseWhen);
16833 :
16834 98120 : w->expr = (Expr *) $2;
16835 98120 : w->result = (Expr *) $4;
16836 98120 : w->location = @1;
16837 98120 : $$ = (Node *) w;
16838 : }
16839 : ;
16840 :
16841 : case_default:
16842 46366 : ELSE a_expr { $$ = $2; }
16843 8440 : | /*EMPTY*/ { $$ = NULL; }
16844 : ;
16845 :
16846 5772 : case_arg: a_expr { $$ = $1; }
16847 49034 : | /*EMPTY*/ { $$ = NULL; }
16848 : ;
16849 :
16850 : columnref: ColId
16851 : {
16852 657726 : $$ = makeColumnRef($1, NIL, @1, yyscanner);
16853 : }
16854 : | ColId indirection
16855 : {
16856 950330 : $$ = makeColumnRef($1, $2, @1, yyscanner);
16857 : }
16858 : ;
16859 :
16860 : indirection_el:
16861 : '.' attr_name
16862 : {
16863 1287110 : $$ = (Node *) makeString($2);
16864 : }
16865 : | '.' '*'
16866 : {
16867 6014 : $$ = (Node *) makeNode(A_Star);
16868 : }
16869 : | '[' a_expr ']'
16870 : {
16871 12206 : A_Indices *ai = makeNode(A_Indices);
16872 :
16873 12206 : ai->is_slice = false;
16874 12206 : ai->lidx = NULL;
16875 12206 : ai->uidx = $2;
16876 12206 : $$ = (Node *) ai;
16877 : }
16878 : | '[' opt_slice_bound ':' opt_slice_bound ']'
16879 : {
16880 570 : A_Indices *ai = makeNode(A_Indices);
16881 :
16882 570 : ai->is_slice = true;
16883 570 : ai->lidx = $2;
16884 570 : ai->uidx = $4;
16885 570 : $$ = (Node *) ai;
16886 : }
16887 : ;
16888 :
16889 : opt_slice_bound:
16890 960 : a_expr { $$ = $1; }
16891 180 : | /*EMPTY*/ { $$ = NULL; }
16892 : ;
16893 :
16894 : indirection:
16895 1286756 : indirection_el { $$ = list_make1($1); }
16896 2956 : | indirection indirection_el { $$ = lappend($1, $2); }
16897 : ;
16898 :
16899 : opt_indirection:
16900 288746 : /*EMPTY*/ { $$ = NIL; }
16901 16188 : | opt_indirection indirection_el { $$ = lappend($1, $2); }
16902 : ;
16903 :
16904 : opt_asymmetric: ASYMMETRIC
16905 : | /*EMPTY*/
16906 : ;
16907 :
16908 : /* SQL/JSON support */
16909 : json_passing_clause_opt:
16910 318 : PASSING json_arguments { $$ = $2; }
16911 1934 : | /*EMPTY*/ { $$ = NIL; }
16912 : ;
16913 :
16914 : json_arguments:
16915 318 : json_argument { $$ = list_make1($1); }
16916 126 : | json_arguments ',' json_argument { $$ = lappend($1, $3); }
16917 : ;
16918 :
16919 : json_argument:
16920 : json_value_expr AS ColLabel
16921 : {
16922 444 : JsonArgument *n = makeNode(JsonArgument);
16923 :
16924 444 : n->val = (JsonValueExpr *) $1;
16925 444 : n->name = $3;
16926 444 : $$ = (Node *) n;
16927 : }
16928 : ;
16929 :
16930 : /* ARRAY is a noise word */
16931 : json_wrapper_behavior:
16932 42 : WITHOUT WRAPPER { $$ = JSW_NONE; }
16933 0 : | WITHOUT ARRAY WRAPPER { $$ = JSW_NONE; }
16934 78 : | WITH WRAPPER { $$ = JSW_UNCONDITIONAL; }
16935 12 : | WITH ARRAY WRAPPER { $$ = JSW_UNCONDITIONAL; }
16936 0 : | WITH CONDITIONAL ARRAY WRAPPER { $$ = JSW_CONDITIONAL; }
16937 12 : | WITH UNCONDITIONAL ARRAY WRAPPER { $$ = JSW_UNCONDITIONAL; }
16938 36 : | WITH CONDITIONAL WRAPPER { $$ = JSW_CONDITIONAL; }
16939 6 : | WITH UNCONDITIONAL WRAPPER { $$ = JSW_UNCONDITIONAL; }
16940 1616 : | /* empty */ { $$ = JSW_UNSPEC; }
16941 : ;
16942 :
16943 : json_behavior:
16944 : DEFAULT a_expr
16945 384 : { $$ = (Node *) makeJsonBehavior(JSON_BEHAVIOR_DEFAULT, $2, @1); }
16946 : | json_behavior_type
16947 702 : { $$ = (Node *) makeJsonBehavior($1, NULL, @1); }
16948 : ;
16949 :
16950 : json_behavior_type:
16951 492 : ERROR_P { $$ = JSON_BEHAVIOR_ERROR; }
16952 30 : | NULL_P { $$ = JSON_BEHAVIOR_NULL; }
16953 30 : | TRUE_P { $$ = JSON_BEHAVIOR_TRUE; }
16954 12 : | FALSE_P { $$ = JSON_BEHAVIOR_FALSE; }
16955 12 : | UNKNOWN { $$ = JSON_BEHAVIOR_UNKNOWN; }
16956 30 : | EMPTY_P ARRAY { $$ = JSON_BEHAVIOR_EMPTY_ARRAY; }
16957 72 : | EMPTY_P OBJECT_P { $$ = JSON_BEHAVIOR_EMPTY_OBJECT; }
16958 : /* non-standard, for Oracle compatibility only */
16959 24 : | EMPTY_P { $$ = JSON_BEHAVIOR_EMPTY_ARRAY; }
16960 : ;
16961 :
16962 : json_behavior_clause_opt:
16963 : json_behavior ON EMPTY_P
16964 174 : { $$ = list_make2($1, NULL); }
16965 : | json_behavior ON ERROR_P
16966 552 : { $$ = list_make2(NULL, $1); }
16967 : | json_behavior ON EMPTY_P json_behavior ON ERROR_P
16968 102 : { $$ = list_make2($1, $4); }
16969 : | /* EMPTY */
16970 1550 : { $$ = list_make2(NULL, NULL); }
16971 : ;
16972 :
16973 : json_on_error_clause_opt:
16974 : json_behavior ON ERROR_P
16975 150 : { $$ = $1; }
16976 : | /* EMPTY */
16977 686 : { $$ = NULL; }
16978 : ;
16979 :
16980 : json_value_expr:
16981 : a_expr json_format_clause_opt
16982 : {
16983 : /* formatted_expr will be set during parse-analysis. */
16984 4160 : $$ = (Node *) makeJsonValueExpr((Expr *) $1, NULL,
16985 4160 : castNode(JsonFormat, $2));
16986 : }
16987 : ;
16988 :
16989 : json_format_clause:
16990 : FORMAT_LA JSON ENCODING name
16991 : {
16992 : int encoding;
16993 :
16994 100 : if (!pg_strcasecmp($4, "utf8"))
16995 64 : encoding = JS_ENC_UTF8;
16996 36 : else if (!pg_strcasecmp($4, "utf16"))
16997 12 : encoding = JS_ENC_UTF16;
16998 24 : else if (!pg_strcasecmp($4, "utf32"))
16999 12 : encoding = JS_ENC_UTF32;
17000 : else
17001 12 : ereport(ERROR,
17002 : (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
17003 : errmsg("unrecognized JSON encoding: %s", $4),
17004 : parser_errposition(@4)));
17005 :
17006 88 : $$ = (Node *) makeJsonFormat(JS_FORMAT_JSON, encoding, @1);
17007 : }
17008 : | FORMAT_LA JSON
17009 : {
17010 412 : $$ = (Node *) makeJsonFormat(JS_FORMAT_JSON, JS_ENC_DEFAULT, @1);
17011 : }
17012 : ;
17013 :
17014 : json_format_clause_opt:
17015 : json_format_clause
17016 : {
17017 392 : $$ = $1;
17018 : }
17019 : | /* EMPTY */
17020 : {
17021 5266 : $$ = (Node *) makeJsonFormat(JS_FORMAT_DEFAULT, JS_ENC_DEFAULT, -1);
17022 : }
17023 : ;
17024 :
17025 : json_quotes_clause_opt:
17026 12 : KEEP QUOTES ON SCALAR STRING_P { $$ = JS_QUOTES_KEEP; }
17027 90 : | KEEP QUOTES { $$ = JS_QUOTES_KEEP; }
17028 12 : | OMIT QUOTES ON SCALAR STRING_P { $$ = JS_QUOTES_OMIT; }
17029 168 : | OMIT QUOTES { $$ = JS_QUOTES_OMIT; }
17030 1520 : | /* EMPTY */ { $$ = JS_QUOTES_UNSPEC; }
17031 : ;
17032 :
17033 : json_returning_clause_opt:
17034 : RETURNING Typename json_format_clause_opt
17035 : {
17036 1444 : JsonOutput *n = makeNode(JsonOutput);
17037 :
17038 1444 : n->typeName = $2;
17039 1444 : n->returning = makeNode(JsonReturning);
17040 1444 : n->returning->format = (JsonFormat *) $3;
17041 1444 : $$ = (Node *) n;
17042 : }
17043 1248 : | /* EMPTY */ { $$ = NULL; }
17044 : ;
17045 :
17046 : /*
17047 : * We must assign the only-JSON production a precedence less than IDENT in
17048 : * order to favor shifting over reduction when JSON is followed by VALUE_P,
17049 : * OBJECT_P, or SCALAR. (ARRAY doesn't need that treatment, because it's a
17050 : * fully reserved word.) Because json_predicate_type_constraint is always
17051 : * followed by json_key_uniqueness_constraint_opt, we also need the only-JSON
17052 : * production to have precedence less than WITH and WITHOUT. UNBOUNDED isn't
17053 : * really related to this syntax, but it's a convenient choice because it
17054 : * already has a precedence less than IDENT for other reasons.
17055 : */
17056 : json_predicate_type_constraint:
17057 202 : JSON %prec UNBOUNDED { $$ = JS_TYPE_ANY; }
17058 28 : | JSON VALUE_P { $$ = JS_TYPE_ANY; }
17059 40 : | JSON ARRAY { $$ = JS_TYPE_ARRAY; }
17060 40 : | JSON OBJECT_P { $$ = JS_TYPE_OBJECT; }
17061 40 : | JSON SCALAR { $$ = JS_TYPE_SCALAR; }
17062 : ;
17063 :
17064 : /*
17065 : * KEYS is a noise word here. To avoid shift/reduce conflicts, assign the
17066 : * KEYS-less productions a precedence less than IDENT (i.e., less than KEYS).
17067 : * This prevents reducing them when the next token is KEYS.
17068 : */
17069 : json_key_uniqueness_constraint_opt:
17070 108 : WITH UNIQUE KEYS { $$ = true; }
17071 100 : | WITH UNIQUE %prec UNBOUNDED { $$ = true; }
17072 44 : | WITHOUT UNIQUE KEYS { $$ = false; }
17073 16 : | WITHOUT UNIQUE %prec UNBOUNDED { $$ = false; }
17074 792 : | /* EMPTY */ %prec UNBOUNDED { $$ = false; }
17075 : ;
17076 :
17077 : json_name_and_value_list:
17078 : json_name_and_value
17079 342 : { $$ = list_make1($1); }
17080 : | json_name_and_value_list ',' json_name_and_value
17081 256 : { $$ = lappend($1, $3); }
17082 : ;
17083 :
17084 : json_name_and_value:
17085 : /* Supporting this syntax seems to require major surgery
17086 : KEY c_expr VALUE_P json_value_expr
17087 : { $$ = makeJsonKeyValue($2, $4); }
17088 : |
17089 : */
17090 : c_expr VALUE_P json_value_expr
17091 24 : { $$ = makeJsonKeyValue($1, $3); }
17092 : |
17093 : a_expr ':' json_value_expr
17094 778 : { $$ = makeJsonKeyValue($1, $3); }
17095 : ;
17096 :
17097 : /* empty means false for objects, true for arrays */
17098 : json_object_constructor_null_clause_opt:
17099 30 : NULL_P ON NULL_P { $$ = false; }
17100 110 : | ABSENT ON NULL_P { $$ = true; }
17101 406 : | /* EMPTY */ { $$ = false; }
17102 : ;
17103 :
17104 : json_array_constructor_null_clause_opt:
17105 60 : NULL_P ON NULL_P { $$ = false; }
17106 36 : | ABSENT ON NULL_P { $$ = true; }
17107 168 : | /* EMPTY */ { $$ = true; }
17108 : ;
17109 :
17110 : json_value_expr_list:
17111 108 : json_value_expr { $$ = list_make1($1); }
17112 126 : | json_value_expr_list ',' json_value_expr { $$ = lappend($1, $3);}
17113 : ;
17114 :
17115 : json_aggregate_func:
17116 : JSON_OBJECTAGG '('
17117 : json_name_and_value
17118 : json_object_constructor_null_clause_opt
17119 : json_key_uniqueness_constraint_opt
17120 : json_returning_clause_opt
17121 : ')'
17122 : {
17123 204 : JsonObjectAgg *n = makeNode(JsonObjectAgg);
17124 :
17125 204 : n->arg = (JsonKeyValue *) $3;
17126 204 : n->absent_on_null = $4;
17127 204 : n->unique = $5;
17128 204 : n->constructor = makeNode(JsonAggConstructor);
17129 204 : n->constructor->output = (JsonOutput *) $6;
17130 204 : n->constructor->agg_order = NULL;
17131 204 : n->constructor->location = @1;
17132 204 : $$ = (Node *) n;
17133 : }
17134 : | JSON_ARRAYAGG '('
17135 : json_value_expr
17136 : json_array_aggregate_order_by_clause_opt
17137 : json_array_constructor_null_clause_opt
17138 : json_returning_clause_opt
17139 : ')'
17140 : {
17141 156 : JsonArrayAgg *n = makeNode(JsonArrayAgg);
17142 :
17143 156 : n->arg = (JsonValueExpr *) $3;
17144 156 : n->absent_on_null = $5;
17145 156 : n->constructor = makeNode(JsonAggConstructor);
17146 156 : n->constructor->agg_order = $4;
17147 156 : n->constructor->output = (JsonOutput *) $6;
17148 156 : n->constructor->location = @1;
17149 156 : $$ = (Node *) n;
17150 : }
17151 : ;
17152 :
17153 : json_array_aggregate_order_by_clause_opt:
17154 18 : ORDER BY sortby_list { $$ = $3; }
17155 138 : | /* EMPTY */ { $$ = NIL; }
17156 : ;
17157 :
17158 : /*****************************************************************************
17159 : *
17160 : * target list for SELECT
17161 : *
17162 : *****************************************************************************/
17163 :
17164 473562 : opt_target_list: target_list { $$ = $1; }
17165 312 : | /* EMPTY */ { $$ = NIL; }
17166 : ;
17167 :
17168 : target_list:
17169 479466 : target_el { $$ = list_make1($1); }
17170 592578 : | target_list ',' target_el { $$ = lappend($1, $3); }
17171 : ;
17172 :
17173 : target_el: a_expr AS ColLabel
17174 : {
17175 199910 : $$ = makeNode(ResTarget);
17176 199910 : $$->name = $3;
17177 199910 : $$->indirection = NIL;
17178 199910 : $$->val = (Node *) $1;
17179 199910 : $$->location = @1;
17180 : }
17181 : | a_expr BareColLabel
17182 : {
17183 3158 : $$ = makeNode(ResTarget);
17184 3158 : $$->name = $2;
17185 3158 : $$->indirection = NIL;
17186 3158 : $$->val = (Node *) $1;
17187 3158 : $$->location = @1;
17188 : }
17189 : | a_expr
17190 : {
17191 819368 : $$ = makeNode(ResTarget);
17192 819368 : $$->name = NULL;
17193 819368 : $$->indirection = NIL;
17194 819368 : $$->val = (Node *) $1;
17195 819368 : $$->location = @1;
17196 : }
17197 : | '*'
17198 : {
17199 49608 : ColumnRef *n = makeNode(ColumnRef);
17200 :
17201 49608 : n->fields = list_make1(makeNode(A_Star));
17202 49608 : n->location = @1;
17203 :
17204 49608 : $$ = makeNode(ResTarget);
17205 49608 : $$->name = NULL;
17206 49608 : $$->indirection = NIL;
17207 49608 : $$->val = (Node *) n;
17208 49608 : $$->location = @1;
17209 : }
17210 : ;
17211 :
17212 :
17213 : /*****************************************************************************
17214 : *
17215 : * Names and constants
17216 : *
17217 : *****************************************************************************/
17218 :
17219 : qualified_name_list:
17220 15878 : qualified_name { $$ = list_make1($1); }
17221 386 : | qualified_name_list ',' qualified_name { $$ = lappend($1, $3); }
17222 : ;
17223 :
17224 : /*
17225 : * The production for a qualified relation name has to exactly match the
17226 : * production for a qualified func_name, because in a FROM clause we cannot
17227 : * tell which we are parsing until we see what comes after it ('(' for a
17228 : * func_name, something else for a relation). Therefore we allow 'indirection'
17229 : * which may contain subscripts, and reject that case in the C code.
17230 : */
17231 : qualified_name:
17232 : ColId
17233 : {
17234 391456 : $$ = makeRangeVar(NULL, $1, @1);
17235 : }
17236 : | ColId indirection
17237 : {
17238 222738 : $$ = makeRangeVarFromQualifiedName($1, $2, @1, yyscanner);
17239 : }
17240 : ;
17241 :
17242 : name_list: name
17243 25232 : { $$ = list_make1(makeString($1)); }
17244 : | name_list ',' name
17245 53800 : { $$ = lappend($1, makeString($3)); }
17246 : ;
17247 :
17248 :
17249 155714 : name: ColId { $$ = $1; };
17250 :
17251 1397482 : attr_name: ColLabel { $$ = $1; };
17252 :
17253 58 : file_name: Sconst { $$ = $1; };
17254 :
17255 : /*
17256 : * The production for a qualified func_name has to exactly match the
17257 : * production for a qualified columnref, because we cannot tell which we
17258 : * are parsing until we see what comes after it ('(' or Sconst for a func_name,
17259 : * anything else for a columnref). Therefore we allow 'indirection' which
17260 : * may contain subscripts, and reject that case in the C code. (If we
17261 : * ever implement SQL99-like methods, such syntax may actually become legal!)
17262 : */
17263 : func_name: type_function_name
17264 301136 : { $$ = list_make1(makeString($1)); }
17265 : | ColId indirection
17266 : {
17267 113610 : $$ = check_func_name(lcons(makeString($1), $2),
17268 : yyscanner);
17269 : }
17270 : ;
17271 :
17272 :
17273 : /*
17274 : * Constants
17275 : */
17276 : AexprConst: Iconst
17277 : {
17278 427080 : $$ = makeIntConst($1, @1);
17279 : }
17280 : | FCONST
17281 : {
17282 11654 : $$ = makeFloatConst($1, @1);
17283 : }
17284 : | Sconst
17285 : {
17286 585730 : $$ = makeStringConst($1, @1);
17287 : }
17288 : | BCONST
17289 : {
17290 754 : $$ = makeBitStringConst($1, @1);
17291 : }
17292 : | XCONST
17293 : {
17294 : /* This is a bit constant per SQL99:
17295 : * Without Feature F511, "BIT data type",
17296 : * a <general literal> shall not be a
17297 : * <bit string literal> or a <hex string literal>.
17298 : */
17299 3302 : $$ = makeBitStringConst($1, @1);
17300 : }
17301 : | func_name Sconst
17302 : {
17303 : /* generic type 'literal' syntax */
17304 9744 : TypeName *t = makeTypeNameFromNameList($1);
17305 :
17306 9744 : t->location = @1;
17307 9744 : $$ = makeStringConstCast($2, @2, t);
17308 : }
17309 : | func_name '(' func_arg_list opt_sort_clause ')' Sconst
17310 : {
17311 : /* generic syntax with a type modifier */
17312 0 : TypeName *t = makeTypeNameFromNameList($1);
17313 : ListCell *lc;
17314 :
17315 : /*
17316 : * We must use func_arg_list and opt_sort_clause in the
17317 : * production to avoid reduce/reduce conflicts, but we
17318 : * don't actually wish to allow NamedArgExpr in this
17319 : * context, nor ORDER BY.
17320 : */
17321 0 : foreach(lc, $3)
17322 : {
17323 0 : NamedArgExpr *arg = (NamedArgExpr *) lfirst(lc);
17324 :
17325 0 : if (IsA(arg, NamedArgExpr))
17326 0 : ereport(ERROR,
17327 : (errcode(ERRCODE_SYNTAX_ERROR),
17328 : errmsg("type modifier cannot have parameter name"),
17329 : parser_errposition(arg->location)));
17330 : }
17331 0 : if ($4 != NIL)
17332 0 : ereport(ERROR,
17333 : (errcode(ERRCODE_SYNTAX_ERROR),
17334 : errmsg("type modifier cannot have ORDER BY"),
17335 : parser_errposition(@4)));
17336 :
17337 0 : t->typmods = $3;
17338 0 : t->location = @1;
17339 0 : $$ = makeStringConstCast($6, @6, t);
17340 : }
17341 : | ConstTypename Sconst
17342 : {
17343 3096 : $$ = makeStringConstCast($2, @2, $1);
17344 : }
17345 : | ConstInterval Sconst opt_interval
17346 : {
17347 3292 : TypeName *t = $1;
17348 :
17349 3292 : t->typmods = $3;
17350 3292 : $$ = makeStringConstCast($2, @2, t);
17351 : }
17352 : | ConstInterval '(' Iconst ')' Sconst
17353 : {
17354 12 : TypeName *t = $1;
17355 :
17356 12 : t->typmods = list_make2(makeIntConst(INTERVAL_FULL_RANGE, -1),
17357 : makeIntConst($3, @3));
17358 12 : $$ = makeStringConstCast($5, @5, t);
17359 : }
17360 : | TRUE_P
17361 : {
17362 22772 : $$ = makeBoolAConst(true, @1);
17363 : }
17364 : | FALSE_P
17365 : {
17366 32034 : $$ = makeBoolAConst(false, @1);
17367 : }
17368 : | NULL_P
17369 : {
17370 61752 : $$ = makeNullAConst(@1);
17371 : }
17372 : ;
17373 :
17374 450616 : Iconst: ICONST { $$ = $1; };
17375 653942 : Sconst: SCONST { $$ = $1; };
17376 :
17377 15650 : SignedIconst: Iconst { $$ = $1; }
17378 0 : | '+' Iconst { $$ = + $2; }
17379 266 : | '-' Iconst { $$ = - $2; }
17380 : ;
17381 :
17382 : /* Role specifications */
17383 : RoleId: RoleSpec
17384 : {
17385 1822 : RoleSpec *spc = (RoleSpec *) $1;
17386 :
17387 1822 : switch (spc->roletype)
17388 : {
17389 1812 : case ROLESPEC_CSTRING:
17390 1812 : $$ = spc->rolename;
17391 1812 : break;
17392 4 : case ROLESPEC_PUBLIC:
17393 4 : ereport(ERROR,
17394 : (errcode(ERRCODE_RESERVED_NAME),
17395 : errmsg("role name \"%s\" is reserved",
17396 : "public"),
17397 : parser_errposition(@1)));
17398 : break;
17399 2 : case ROLESPEC_SESSION_USER:
17400 2 : ereport(ERROR,
17401 : (errcode(ERRCODE_RESERVED_NAME),
17402 : errmsg("%s cannot be used as a role name here",
17403 : "SESSION_USER"),
17404 : parser_errposition(@1)));
17405 : break;
17406 2 : case ROLESPEC_CURRENT_USER:
17407 2 : ereport(ERROR,
17408 : (errcode(ERRCODE_RESERVED_NAME),
17409 : errmsg("%s cannot be used as a role name here",
17410 : "CURRENT_USER"),
17411 : parser_errposition(@1)));
17412 : break;
17413 2 : case ROLESPEC_CURRENT_ROLE:
17414 2 : ereport(ERROR,
17415 : (errcode(ERRCODE_RESERVED_NAME),
17416 : errmsg("%s cannot be used as a role name here",
17417 : "CURRENT_ROLE"),
17418 : parser_errposition(@1)));
17419 : break;
17420 : }
17421 1812 : }
17422 : ;
17423 :
17424 : RoleSpec: NonReservedWord
17425 : {
17426 : /*
17427 : * "public" and "none" are not keywords, but they must
17428 : * be treated specially here.
17429 : */
17430 : RoleSpec *n;
17431 :
17432 28904 : if (strcmp($1, "public") == 0)
17433 : {
17434 15552 : n = (RoleSpec *) makeRoleSpec(ROLESPEC_PUBLIC, @1);
17435 15552 : n->roletype = ROLESPEC_PUBLIC;
17436 : }
17437 13352 : else if (strcmp($1, "none") == 0)
17438 : {
17439 26 : ereport(ERROR,
17440 : (errcode(ERRCODE_RESERVED_NAME),
17441 : errmsg("role name \"%s\" is reserved",
17442 : "none"),
17443 : parser_errposition(@1)));
17444 : }
17445 : else
17446 : {
17447 13326 : n = makeRoleSpec(ROLESPEC_CSTRING, @1);
17448 13326 : n->rolename = pstrdup($1);
17449 : }
17450 28878 : $$ = n;
17451 : }
17452 : | CURRENT_ROLE
17453 : {
17454 130 : $$ = makeRoleSpec(ROLESPEC_CURRENT_ROLE, @1);
17455 : }
17456 : | CURRENT_USER
17457 : {
17458 228 : $$ = makeRoleSpec(ROLESPEC_CURRENT_USER, @1);
17459 : }
17460 : | SESSION_USER
17461 : {
17462 36 : $$ = makeRoleSpec(ROLESPEC_SESSION_USER, @1);
17463 : }
17464 : ;
17465 :
17466 : role_list: RoleSpec
17467 3158 : { $$ = list_make1($1); }
17468 : | role_list ',' RoleSpec
17469 258 : { $$ = lappend($1, $3); }
17470 : ;
17471 :
17472 :
17473 : /*****************************************************************************
17474 : *
17475 : * PL/pgSQL extensions
17476 : *
17477 : * You'd think a PL/pgSQL "expression" should be just an a_expr, but
17478 : * historically it can include just about anything that can follow SELECT.
17479 : * Therefore the returned struct is a SelectStmt.
17480 : *****************************************************************************/
17481 :
17482 : PLpgSQL_Expr: opt_distinct_clause opt_target_list
17483 : from_clause where_clause
17484 : group_clause having_clause window_clause
17485 : opt_sort_clause opt_select_limit opt_for_locking_clause
17486 : {
17487 39294 : SelectStmt *n = makeNode(SelectStmt);
17488 :
17489 39294 : n->distinctClause = $1;
17490 39294 : n->targetList = $2;
17491 39294 : n->fromClause = $3;
17492 39294 : n->whereClause = $4;
17493 39294 : n->groupClause = ($5)->list;
17494 39294 : n->groupDistinct = ($5)->distinct;
17495 39294 : n->havingClause = $6;
17496 39294 : n->windowClause = $7;
17497 39294 : n->sortClause = $8;
17498 39294 : if ($9)
17499 : {
17500 4 : n->limitOffset = $9->limitOffset;
17501 4 : n->limitCount = $9->limitCount;
17502 4 : if (!n->sortClause &&
17503 4 : $9->limitOption == LIMIT_OPTION_WITH_TIES)
17504 0 : ereport(ERROR,
17505 : (errcode(ERRCODE_SYNTAX_ERROR),
17506 : errmsg("WITH TIES cannot be specified without ORDER BY clause"),
17507 : parser_errposition($9->optionLoc)));
17508 4 : n->limitOption = $9->limitOption;
17509 : }
17510 39294 : n->lockingClause = $10;
17511 39294 : $$ = (Node *) n;
17512 : }
17513 : ;
17514 :
17515 : /*
17516 : * PL/pgSQL Assignment statement: name opt_indirection := PLpgSQL_Expr
17517 : */
17518 :
17519 : PLAssignStmt: plassign_target opt_indirection plassign_equals PLpgSQL_Expr
17520 : {
17521 6850 : PLAssignStmt *n = makeNode(PLAssignStmt);
17522 :
17523 6850 : n->name = $1;
17524 6850 : n->indirection = check_indirection($2, yyscanner);
17525 : /* nnames will be filled by calling production */
17526 6850 : n->val = (SelectStmt *) $4;
17527 6850 : n->location = @1;
17528 6850 : $$ = (Node *) n;
17529 : }
17530 : ;
17531 :
17532 6826 : plassign_target: ColId { $$ = $1; }
17533 24 : | PARAM { $$ = psprintf("$%d", $1); }
17534 : ;
17535 :
17536 : plassign_equals: COLON_EQUALS
17537 : | '='
17538 : ;
17539 :
17540 :
17541 : /*
17542 : * Name classification hierarchy.
17543 : *
17544 : * IDENT is the lexeme returned by the lexer for identifiers that match
17545 : * no known keyword. In most cases, we can accept certain keywords as
17546 : * names, not only IDENTs. We prefer to accept as many such keywords
17547 : * as possible to minimize the impact of "reserved words" on programmers.
17548 : * So, we divide names into several possible classes. The classification
17549 : * is chosen in part to make keywords acceptable as names wherever possible.
17550 : */
17551 :
17552 : /* Column identifier --- names that can be column, table, etc names.
17553 : */
17554 3030598 : ColId: IDENT { $$ = $1; }
17555 51736 : | unreserved_keyword { $$ = pstrdup($1); }
17556 5396 : | col_name_keyword { $$ = pstrdup($1); }
17557 : ;
17558 :
17559 : /* Type/function identifier --- names that can be type or function names.
17560 : */
17561 672084 : type_function_name: IDENT { $$ = $1; }
17562 70646 : | unreserved_keyword { $$ = pstrdup($1); }
17563 60 : | type_func_name_keyword { $$ = pstrdup($1); }
17564 : ;
17565 :
17566 : /* Any not-fully-reserved word --- these names can be, eg, role names.
17567 : */
17568 71062 : NonReservedWord: IDENT { $$ = $1; }
17569 26222 : | unreserved_keyword { $$ = pstrdup($1); }
17570 176 : | col_name_keyword { $$ = pstrdup($1); }
17571 3582 : | type_func_name_keyword { $$ = pstrdup($1); }
17572 : ;
17573 :
17574 : /* Column label --- allowed labels in "AS" clauses.
17575 : * This presently includes *all* Postgres keywords.
17576 : */
17577 1583156 : ColLabel: IDENT { $$ = $1; }
17578 36104 : | unreserved_keyword { $$ = pstrdup($1); }
17579 272 : | col_name_keyword { $$ = pstrdup($1); }
17580 1762 : | type_func_name_keyword { $$ = pstrdup($1); }
17581 7204 : | reserved_keyword { $$ = pstrdup($1); }
17582 : ;
17583 :
17584 : /* Bare column label --- names that can be column labels without writing "AS".
17585 : * This classification is orthogonal to the other keyword categories.
17586 : */
17587 3152 : BareColLabel: IDENT { $$ = $1; }
17588 6 : | bare_label_keyword { $$ = pstrdup($1); }
17589 : ;
17590 :
17591 :
17592 : /*
17593 : * Keyword category lists. Generally, every keyword present in
17594 : * the Postgres grammar should appear in exactly one of these lists.
17595 : *
17596 : * Put a new keyword into the first list that it can go into without causing
17597 : * shift or reduce conflicts. The earlier lists define "less reserved"
17598 : * categories of keywords.
17599 : *
17600 : * Make sure that each keyword's category in kwlist.h matches where
17601 : * it is listed here. (Someday we may be able to generate these lists and
17602 : * kwlist.h's table from one source of truth.)
17603 : */
17604 :
17605 : /* "Unreserved" keywords --- available for use as any kind of name.
17606 : */
17607 : unreserved_keyword:
17608 : ABORT_P
17609 : | ABSENT
17610 : | ABSOLUTE_P
17611 : | ACCESS
17612 : | ACTION
17613 : | ADD_P
17614 : | ADMIN
17615 : | AFTER
17616 : | AGGREGATE
17617 : | ALSO
17618 : | ALTER
17619 : | ALWAYS
17620 : | ASENSITIVE
17621 : | ASSERTION
17622 : | ASSIGNMENT
17623 : | AT
17624 : | ATOMIC
17625 : | ATTACH
17626 : | ATTRIBUTE
17627 : | BACKWARD
17628 : | BEFORE
17629 : | BEGIN_P
17630 : | BREADTH
17631 : | BY
17632 : | CACHE
17633 : | CALL
17634 : | CALLED
17635 : | CASCADE
17636 : | CASCADED
17637 : | CATALOG_P
17638 : | CHAIN
17639 : | CHARACTERISTICS
17640 : | CHECKPOINT
17641 : | CLASS
17642 : | CLOSE
17643 : | CLUSTER
17644 : | COLUMNS
17645 : | COMMENT
17646 : | COMMENTS
17647 : | COMMIT
17648 : | COMMITTED
17649 : | COMPRESSION
17650 : | CONDITIONAL
17651 : | CONFIGURATION
17652 : | CONFLICT
17653 : | CONNECTION
17654 : | CONSTRAINTS
17655 : | CONTENT_P
17656 : | CONTINUE_P
17657 : | CONVERSION_P
17658 : | COPY
17659 : | COST
17660 : | CSV
17661 : | CUBE
17662 : | CURRENT_P
17663 : | CURSOR
17664 : | CYCLE
17665 : | DATA_P
17666 : | DATABASE
17667 : | DAY_P
17668 : | DEALLOCATE
17669 : | DECLARE
17670 : | DEFAULTS
17671 : | DEFERRED
17672 : | DEFINER
17673 : | DELETE_P
17674 : | DELIMITER
17675 : | DELIMITERS
17676 : | DEPENDS
17677 : | DEPTH
17678 : | DETACH
17679 : | DICTIONARY
17680 : | DISABLE_P
17681 : | DISCARD
17682 : | DOCUMENT_P
17683 : | DOMAIN_P
17684 : | DOUBLE_P
17685 : | DROP
17686 : | EACH
17687 : | EMPTY_P
17688 : | ENABLE_P
17689 : | ENCODING
17690 : | ENCRYPTED
17691 : | ENUM_P
17692 : | ERROR_P
17693 : | ESCAPE
17694 : | EVENT
17695 : | EXCLUDE
17696 : | EXCLUDING
17697 : | EXCLUSIVE
17698 : | EXECUTE
17699 : | EXPLAIN
17700 : | EXPRESSION
17701 : | EXTENSION
17702 : | EXTERNAL
17703 : | FAMILY
17704 : | FILTER
17705 : | FINALIZE
17706 : | FIRST_P
17707 : | FOLLOWING
17708 : | FORCE
17709 : | FORMAT
17710 : | FORWARD
17711 : | FUNCTION
17712 : | FUNCTIONS
17713 : | GENERATED
17714 : | GLOBAL
17715 : | GRANTED
17716 : | GROUPS
17717 : | HANDLER
17718 : | HEADER_P
17719 : | HOLD
17720 : | HOUR_P
17721 : | IDENTITY_P
17722 : | IF_P
17723 : | IMMEDIATE
17724 : | IMMUTABLE
17725 : | IMPLICIT_P
17726 : | IMPORT_P
17727 : | INCLUDE
17728 : | INCLUDING
17729 : | INCREMENT
17730 : | INDENT
17731 : | INDEX
17732 : | INDEXES
17733 : | INHERIT
17734 : | INHERITS
17735 : | INLINE_P
17736 : | INPUT_P
17737 : | INSENSITIVE
17738 : | INSERT
17739 : | INSTEAD
17740 : | INVOKER
17741 : | ISOLATION
17742 : | KEEP
17743 : | KEY
17744 : | KEYS
17745 : | LABEL
17746 : | LANGUAGE
17747 : | LARGE_P
17748 : | LAST_P
17749 : | LEAKPROOF
17750 : | LEVEL
17751 : | LISTEN
17752 : | LOAD
17753 : | LOCAL
17754 : | LOCATION
17755 : | LOCK_P
17756 : | LOCKED
17757 : | LOGGED
17758 : | MAPPING
17759 : | MATCH
17760 : | MATCHED
17761 : | MATERIALIZED
17762 : | MAXVALUE
17763 : | MERGE
17764 : | METHOD
17765 : | MINUTE_P
17766 : | MINVALUE
17767 : | MODE
17768 : | MONTH_P
17769 : | MOVE
17770 : | NAME_P
17771 : | NAMES
17772 : | NESTED
17773 : | NEW
17774 : | NEXT
17775 : | NFC
17776 : | NFD
17777 : | NFKC
17778 : | NFKD
17779 : | NO
17780 : | NORMALIZED
17781 : | NOTHING
17782 : | NOTIFY
17783 : | NOWAIT
17784 : | NULLS_P
17785 : | OBJECT_P
17786 : | OF
17787 : | OFF
17788 : | OIDS
17789 : | OLD
17790 : | OMIT
17791 : | OPERATOR
17792 : | OPTION
17793 : | OPTIONS
17794 : | ORDINALITY
17795 : | OTHERS
17796 : | OVER
17797 : | OVERRIDING
17798 : | OWNED
17799 : | OWNER
17800 : | PARALLEL
17801 : | PARAMETER
17802 : | PARSER
17803 : | PARTIAL
17804 : | PARTITION
17805 : | PASSING
17806 : | PASSWORD
17807 : | PATH
17808 : | PERIOD
17809 : | PLAN
17810 : | PLANS
17811 : | POLICY
17812 : | PRECEDING
17813 : | PREPARE
17814 : | PREPARED
17815 : | PRESERVE
17816 : | PRIOR
17817 : | PRIVILEGES
17818 : | PROCEDURAL
17819 : | PROCEDURE
17820 : | PROCEDURES
17821 : | PROGRAM
17822 : | PUBLICATION
17823 : | QUOTE
17824 : | QUOTES
17825 : | RANGE
17826 : | READ
17827 : | REASSIGN
17828 : | RECURSIVE
17829 : | REF_P
17830 : | REFERENCING
17831 : | REFRESH
17832 : | REINDEX
17833 : | RELATIVE_P
17834 : | RELEASE
17835 : | RENAME
17836 : | REPEATABLE
17837 : | REPLACE
17838 : | REPLICA
17839 : | RESET
17840 : | RESTART
17841 : | RESTRICT
17842 : | RETURN
17843 : | RETURNS
17844 : | REVOKE
17845 : | ROLE
17846 : | ROLLBACK
17847 : | ROLLUP
17848 : | ROUTINE
17849 : | ROUTINES
17850 : | ROWS
17851 : | RULE
17852 : | SAVEPOINT
17853 : | SCALAR
17854 : | SCHEMA
17855 : | SCHEMAS
17856 : | SCROLL
17857 : | SEARCH
17858 : | SECOND_P
17859 : | SECURITY
17860 : | SEQUENCE
17861 : | SEQUENCES
17862 : | SERIALIZABLE
17863 : | SERVER
17864 : | SESSION
17865 : | SET
17866 : | SETS
17867 : | SHARE
17868 : | SHOW
17869 : | SIMPLE
17870 : | SKIP
17871 : | SNAPSHOT
17872 : | SOURCE
17873 : | SQL_P
17874 : | STABLE
17875 : | STANDALONE_P
17876 : | START
17877 : | STATEMENT
17878 : | STATISTICS
17879 : | STDIN
17880 : | STDOUT
17881 : | STORAGE
17882 : | STORED
17883 : | STRICT_P
17884 : | STRING_P
17885 : | STRIP_P
17886 : | SUBSCRIPTION
17887 : | SUPPORT
17888 : | SYSID
17889 : | SYSTEM_P
17890 : | TABLES
17891 : | TABLESPACE
17892 : | TARGET
17893 : | TEMP
17894 : | TEMPLATE
17895 : | TEMPORARY
17896 : | TEXT_P
17897 : | TIES
17898 : | TRANSACTION
17899 : | TRANSFORM
17900 : | TRIGGER
17901 : | TRUNCATE
17902 : | TRUSTED
17903 : | TYPE_P
17904 : | TYPES_P
17905 : | UESCAPE
17906 : | UNBOUNDED
17907 : | UNCOMMITTED
17908 : | UNCONDITIONAL
17909 : | UNENCRYPTED
17910 : | UNKNOWN
17911 : | UNLISTEN
17912 : | UNLOGGED
17913 : | UNTIL
17914 : | UPDATE
17915 : | VACUUM
17916 : | VALID
17917 : | VALIDATE
17918 : | VALIDATOR
17919 : | VALUE_P
17920 : | VARYING
17921 : | VERSION_P
17922 : | VIEW
17923 : | VIEWS
17924 : | VOLATILE
17925 : | WHITESPACE_P
17926 : | WITHIN
17927 : | WITHOUT
17928 : | WORK
17929 : | WRAPPER
17930 : | WRITE
17931 : | XML_P
17932 : | YEAR_P
17933 : | YES_P
17934 : | ZONE
17935 : ;
17936 :
17937 : /* Column identifier --- keywords that can be column, table, etc names.
17938 : *
17939 : * Many of these keywords will in fact be recognized as type or function
17940 : * names too; but they have special productions for the purpose, and so
17941 : * can't be treated as "generic" type or function names.
17942 : *
17943 : * The type names appearing here are not usable as function names
17944 : * because they can be followed by '(' in typename productions, which
17945 : * looks too much like a function call for an LR(1) parser.
17946 : */
17947 : col_name_keyword:
17948 : BETWEEN
17949 : | BIGINT
17950 : | BIT
17951 : | BOOLEAN_P
17952 : | CHAR_P
17953 : | CHARACTER
17954 : | COALESCE
17955 : | DEC
17956 : | DECIMAL_P
17957 : | EXISTS
17958 : | EXTRACT
17959 : | FLOAT_P
17960 : | GREATEST
17961 : | GROUPING
17962 : | INOUT
17963 : | INT_P
17964 : | INTEGER
17965 : | INTERVAL
17966 : | JSON
17967 : | JSON_ARRAY
17968 : | JSON_ARRAYAGG
17969 : | JSON_EXISTS
17970 : | JSON_OBJECT
17971 : | JSON_OBJECTAGG
17972 : | JSON_QUERY
17973 : | JSON_SCALAR
17974 : | JSON_SERIALIZE
17975 : | JSON_TABLE
17976 : | JSON_VALUE
17977 : | LEAST
17978 : | MERGE_ACTION
17979 : | NATIONAL
17980 : | NCHAR
17981 : | NONE
17982 : | NORMALIZE
17983 : | NULLIF
17984 : | NUMERIC
17985 : | OUT_P
17986 : | OVERLAY
17987 : | POSITION
17988 : | PRECISION
17989 : | REAL
17990 : | ROW
17991 : | SETOF
17992 : | SMALLINT
17993 : | SUBSTRING
17994 : | TIME
17995 : | TIMESTAMP
17996 : | TREAT
17997 : | TRIM
17998 : | VALUES
17999 : | VARCHAR
18000 : | XMLATTRIBUTES
18001 : | XMLCONCAT
18002 : | XMLELEMENT
18003 : | XMLEXISTS
18004 : | XMLFOREST
18005 : | XMLNAMESPACES
18006 : | XMLPARSE
18007 : | XMLPI
18008 : | XMLROOT
18009 : | XMLSERIALIZE
18010 : | XMLTABLE
18011 : ;
18012 :
18013 : /* Type/function identifier --- keywords that can be type or function names.
18014 : *
18015 : * Most of these are keywords that are used as operators in expressions;
18016 : * in general such keywords can't be column names because they would be
18017 : * ambiguous with variables, but they are unambiguous as function identifiers.
18018 : *
18019 : * Do not include POSITION, SUBSTRING, etc here since they have explicit
18020 : * productions in a_expr to support the goofy SQL9x argument syntax.
18021 : * - thomas 2000-11-28
18022 : */
18023 : type_func_name_keyword:
18024 : AUTHORIZATION
18025 : | BINARY
18026 : | COLLATION
18027 : | CONCURRENTLY
18028 : | CROSS
18029 : | CURRENT_SCHEMA
18030 : | FREEZE
18031 : | FULL
18032 : | ILIKE
18033 : | INNER_P
18034 : | IS
18035 : | ISNULL
18036 : | JOIN
18037 : | LEFT
18038 : | LIKE
18039 : | NATURAL
18040 : | NOTNULL
18041 : | OUTER_P
18042 : | OVERLAPS
18043 : | RIGHT
18044 : | SIMILAR
18045 : | TABLESAMPLE
18046 : | VERBOSE
18047 : ;
18048 :
18049 : /* Reserved keyword --- these keywords are usable only as a ColLabel.
18050 : *
18051 : * Keywords appear here if they could not be distinguished from variable,
18052 : * type, or function names in some contexts. Don't put things here unless
18053 : * forced to.
18054 : */
18055 : reserved_keyword:
18056 : ALL
18057 : | ANALYSE
18058 : | ANALYZE
18059 : | AND
18060 : | ANY
18061 : | ARRAY
18062 : | AS
18063 : | ASC
18064 : | ASYMMETRIC
18065 : | BOTH
18066 : | CASE
18067 : | CAST
18068 : | CHECK
18069 : | COLLATE
18070 : | COLUMN
18071 : | CONSTRAINT
18072 : | CREATE
18073 : | CURRENT_CATALOG
18074 : | CURRENT_DATE
18075 : | CURRENT_ROLE
18076 : | CURRENT_TIME
18077 : | CURRENT_TIMESTAMP
18078 : | CURRENT_USER
18079 : | DEFAULT
18080 : | DEFERRABLE
18081 : | DESC
18082 : | DISTINCT
18083 : | DO
18084 : | ELSE
18085 : | END_P
18086 : | EXCEPT
18087 : | FALSE_P
18088 : | FETCH
18089 : | FOR
18090 : | FOREIGN
18091 : | FROM
18092 : | GRANT
18093 : | GROUP_P
18094 : | HAVING
18095 : | IN_P
18096 : | INITIALLY
18097 : | INTERSECT
18098 : | INTO
18099 : | LATERAL_P
18100 : | LEADING
18101 : | LIMIT
18102 : | LOCALTIME
18103 : | LOCALTIMESTAMP
18104 : | NOT
18105 : | NULL_P
18106 : | OFFSET
18107 : | ON
18108 : | ONLY
18109 : | OR
18110 : | ORDER
18111 : | PLACING
18112 : | PRIMARY
18113 : | REFERENCES
18114 : | RETURNING
18115 : | SELECT
18116 : | SESSION_USER
18117 : | SOME
18118 : | SYMMETRIC
18119 : | SYSTEM_USER
18120 : | TABLE
18121 : | THEN
18122 : | TO
18123 : | TRAILING
18124 : | TRUE_P
18125 : | UNION
18126 : | UNIQUE
18127 : | USER
18128 : | USING
18129 : | VARIADIC
18130 : | WHEN
18131 : | WHERE
18132 : | WINDOW
18133 : | WITH
18134 : ;
18135 :
18136 : /*
18137 : * While all keywords can be used as column labels when preceded by AS,
18138 : * not all of them can be used as a "bare" column label without AS.
18139 : * Those that can be used as a bare label must be listed here,
18140 : * in addition to appearing in one of the category lists above.
18141 : *
18142 : * Always add a new keyword to this list if possible. Mark it BARE_LABEL
18143 : * in kwlist.h if it is included here, or AS_LABEL if it is not.
18144 : */
18145 : bare_label_keyword:
18146 : ABORT_P
18147 : | ABSENT
18148 : | ABSOLUTE_P
18149 : | ACCESS
18150 : | ACTION
18151 : | ADD_P
18152 : | ADMIN
18153 : | AFTER
18154 : | AGGREGATE
18155 : | ALL
18156 : | ALSO
18157 : | ALTER
18158 : | ALWAYS
18159 : | ANALYSE
18160 : | ANALYZE
18161 : | AND
18162 : | ANY
18163 : | ASC
18164 : | ASENSITIVE
18165 : | ASSERTION
18166 : | ASSIGNMENT
18167 : | ASYMMETRIC
18168 : | AT
18169 : | ATOMIC
18170 : | ATTACH
18171 : | ATTRIBUTE
18172 : | AUTHORIZATION
18173 : | BACKWARD
18174 : | BEFORE
18175 : | BEGIN_P
18176 : | BETWEEN
18177 : | BIGINT
18178 : | BINARY
18179 : | BIT
18180 : | BOOLEAN_P
18181 : | BOTH
18182 : | BREADTH
18183 : | BY
18184 : | CACHE
18185 : | CALL
18186 : | CALLED
18187 : | CASCADE
18188 : | CASCADED
18189 : | CASE
18190 : | CAST
18191 : | CATALOG_P
18192 : | CHAIN
18193 : | CHARACTERISTICS
18194 : | CHECK
18195 : | CHECKPOINT
18196 : | CLASS
18197 : | CLOSE
18198 : | CLUSTER
18199 : | COALESCE
18200 : | COLLATE
18201 : | COLLATION
18202 : | COLUMN
18203 : | COLUMNS
18204 : | COMMENT
18205 : | COMMENTS
18206 : | COMMIT
18207 : | COMMITTED
18208 : | COMPRESSION
18209 : | CONCURRENTLY
18210 : | CONDITIONAL
18211 : | CONFIGURATION
18212 : | CONFLICT
18213 : | CONNECTION
18214 : | CONSTRAINT
18215 : | CONSTRAINTS
18216 : | CONTENT_P
18217 : | CONTINUE_P
18218 : | CONVERSION_P
18219 : | COPY
18220 : | COST
18221 : | CROSS
18222 : | CSV
18223 : | CUBE
18224 : | CURRENT_P
18225 : | CURRENT_CATALOG
18226 : | CURRENT_DATE
18227 : | CURRENT_ROLE
18228 : | CURRENT_SCHEMA
18229 : | CURRENT_TIME
18230 : | CURRENT_TIMESTAMP
18231 : | CURRENT_USER
18232 : | CURSOR
18233 : | CYCLE
18234 : | DATA_P
18235 : | DATABASE
18236 : | DEALLOCATE
18237 : | DEC
18238 : | DECIMAL_P
18239 : | DECLARE
18240 : | DEFAULT
18241 : | DEFAULTS
18242 : | DEFERRABLE
18243 : | DEFERRED
18244 : | DEFINER
18245 : | DELETE_P
18246 : | DELIMITER
18247 : | DELIMITERS
18248 : | DEPENDS
18249 : | DEPTH
18250 : | DESC
18251 : | DETACH
18252 : | DICTIONARY
18253 : | DISABLE_P
18254 : | DISCARD
18255 : | DISTINCT
18256 : | DO
18257 : | DOCUMENT_P
18258 : | DOMAIN_P
18259 : | DOUBLE_P
18260 : | DROP
18261 : | EACH
18262 : | ELSE
18263 : | EMPTY_P
18264 : | ENABLE_P
18265 : | ENCODING
18266 : | ENCRYPTED
18267 : | END_P
18268 : | ENUM_P
18269 : | ERROR_P
18270 : | ESCAPE
18271 : | EVENT
18272 : | EXCLUDE
18273 : | EXCLUDING
18274 : | EXCLUSIVE
18275 : | EXECUTE
18276 : | EXISTS
18277 : | EXPLAIN
18278 : | EXPRESSION
18279 : | EXTENSION
18280 : | EXTERNAL
18281 : | EXTRACT
18282 : | FALSE_P
18283 : | FAMILY
18284 : | FINALIZE
18285 : | FIRST_P
18286 : | FLOAT_P
18287 : | FOLLOWING
18288 : | FORCE
18289 : | FOREIGN
18290 : | FORMAT
18291 : | FORWARD
18292 : | FREEZE
18293 : | FULL
18294 : | FUNCTION
18295 : | FUNCTIONS
18296 : | GENERATED
18297 : | GLOBAL
18298 : | GRANTED
18299 : | GREATEST
18300 : | GROUPING
18301 : | GROUPS
18302 : | HANDLER
18303 : | HEADER_P
18304 : | HOLD
18305 : | IDENTITY_P
18306 : | IF_P
18307 : | ILIKE
18308 : | IMMEDIATE
18309 : | IMMUTABLE
18310 : | IMPLICIT_P
18311 : | IMPORT_P
18312 : | IN_P
18313 : | INCLUDE
18314 : | INCLUDING
18315 : | INCREMENT
18316 : | INDENT
18317 : | INDEX
18318 : | INDEXES
18319 : | INHERIT
18320 : | INHERITS
18321 : | INITIALLY
18322 : | INLINE_P
18323 : | INNER_P
18324 : | INOUT
18325 : | INPUT_P
18326 : | INSENSITIVE
18327 : | INSERT
18328 : | INSTEAD
18329 : | INT_P
18330 : | INTEGER
18331 : | INTERVAL
18332 : | INVOKER
18333 : | IS
18334 : | ISOLATION
18335 : | JOIN
18336 : | JSON
18337 : | JSON_ARRAY
18338 : | JSON_ARRAYAGG
18339 : | JSON_EXISTS
18340 : | JSON_OBJECT
18341 : | JSON_OBJECTAGG
18342 : | JSON_QUERY
18343 : | JSON_SCALAR
18344 : | JSON_SERIALIZE
18345 : | JSON_TABLE
18346 : | JSON_VALUE
18347 : | KEEP
18348 : | KEY
18349 : | KEYS
18350 : | LABEL
18351 : | LANGUAGE
18352 : | LARGE_P
18353 : | LAST_P
18354 : | LATERAL_P
18355 : | LEADING
18356 : | LEAKPROOF
18357 : | LEAST
18358 : | LEFT
18359 : | LEVEL
18360 : | LIKE
18361 : | LISTEN
18362 : | LOAD
18363 : | LOCAL
18364 : | LOCALTIME
18365 : | LOCALTIMESTAMP
18366 : | LOCATION
18367 : | LOCK_P
18368 : | LOCKED
18369 : | LOGGED
18370 : | MAPPING
18371 : | MATCH
18372 : | MATCHED
18373 : | MATERIALIZED
18374 : | MAXVALUE
18375 : | MERGE
18376 : | MERGE_ACTION
18377 : | METHOD
18378 : | MINVALUE
18379 : | MODE
18380 : | MOVE
18381 : | NAME_P
18382 : | NAMES
18383 : | NATIONAL
18384 : | NATURAL
18385 : | NCHAR
18386 : | NESTED
18387 : | NEW
18388 : | NEXT
18389 : | NFC
18390 : | NFD
18391 : | NFKC
18392 : | NFKD
18393 : | NO
18394 : | NONE
18395 : | NORMALIZE
18396 : | NORMALIZED
18397 : | NOT
18398 : | NOTHING
18399 : | NOTIFY
18400 : | NOWAIT
18401 : | NULL_P
18402 : | NULLIF
18403 : | NULLS_P
18404 : | NUMERIC
18405 : | OBJECT_P
18406 : | OF
18407 : | OFF
18408 : | OIDS
18409 : | OLD
18410 : | OMIT
18411 : | ONLY
18412 : | OPERATOR
18413 : | OPTION
18414 : | OPTIONS
18415 : | OR
18416 : | ORDINALITY
18417 : | OTHERS
18418 : | OUT_P
18419 : | OUTER_P
18420 : | OVERLAY
18421 : | OVERRIDING
18422 : | OWNED
18423 : | OWNER
18424 : | PARALLEL
18425 : | PARAMETER
18426 : | PARSER
18427 : | PARTIAL
18428 : | PARTITION
18429 : | PASSING
18430 : | PASSWORD
18431 : | PATH
18432 : | PERIOD
18433 : | PLACING
18434 : | PLAN
18435 : | PLANS
18436 : | POLICY
18437 : | POSITION
18438 : | PRECEDING
18439 : | PREPARE
18440 : | PREPARED
18441 : | PRESERVE
18442 : | PRIMARY
18443 : | PRIOR
18444 : | PRIVILEGES
18445 : | PROCEDURAL
18446 : | PROCEDURE
18447 : | PROCEDURES
18448 : | PROGRAM
18449 : | PUBLICATION
18450 : | QUOTE
18451 : | QUOTES
18452 : | RANGE
18453 : | READ
18454 : | REAL
18455 : | REASSIGN
18456 : | RECURSIVE
18457 : | REF_P
18458 : | REFERENCES
18459 : | REFERENCING
18460 : | REFRESH
18461 : | REINDEX
18462 : | RELATIVE_P
18463 : | RELEASE
18464 : | RENAME
18465 : | REPEATABLE
18466 : | REPLACE
18467 : | REPLICA
18468 : | RESET
18469 : | RESTART
18470 : | RESTRICT
18471 : | RETURN
18472 : | RETURNS
18473 : | REVOKE
18474 : | RIGHT
18475 : | ROLE
18476 : | ROLLBACK
18477 : | ROLLUP
18478 : | ROUTINE
18479 : | ROUTINES
18480 : | ROW
18481 : | ROWS
18482 : | RULE
18483 : | SAVEPOINT
18484 : | SCALAR
18485 : | SCHEMA
18486 : | SCHEMAS
18487 : | SCROLL
18488 : | SEARCH
18489 : | SECURITY
18490 : | SELECT
18491 : | SEQUENCE
18492 : | SEQUENCES
18493 : | SERIALIZABLE
18494 : | SERVER
18495 : | SESSION
18496 : | SESSION_USER
18497 : | SET
18498 : | SETOF
18499 : | SETS
18500 : | SHARE
18501 : | SHOW
18502 : | SIMILAR
18503 : | SIMPLE
18504 : | SKIP
18505 : | SMALLINT
18506 : | SNAPSHOT
18507 : | SOME
18508 : | SOURCE
18509 : | SQL_P
18510 : | STABLE
18511 : | STANDALONE_P
18512 : | START
18513 : | STATEMENT
18514 : | STATISTICS
18515 : | STDIN
18516 : | STDOUT
18517 : | STORAGE
18518 : | STORED
18519 : | STRICT_P
18520 : | STRING_P
18521 : | STRIP_P
18522 : | SUBSCRIPTION
18523 : | SUBSTRING
18524 : | SUPPORT
18525 : | SYMMETRIC
18526 : | SYSID
18527 : | SYSTEM_P
18528 : | SYSTEM_USER
18529 : | TABLE
18530 : | TABLES
18531 : | TABLESAMPLE
18532 : | TABLESPACE
18533 : | TARGET
18534 : | TEMP
18535 : | TEMPLATE
18536 : | TEMPORARY
18537 : | TEXT_P
18538 : | THEN
18539 : | TIES
18540 : | TIME
18541 : | TIMESTAMP
18542 : | TRAILING
18543 : | TRANSACTION
18544 : | TRANSFORM
18545 : | TREAT
18546 : | TRIGGER
18547 : | TRIM
18548 : | TRUE_P
18549 : | TRUNCATE
18550 : | TRUSTED
18551 : | TYPE_P
18552 : | TYPES_P
18553 : | UESCAPE
18554 : | UNBOUNDED
18555 : | UNCOMMITTED
18556 : | UNCONDITIONAL
18557 : | UNENCRYPTED
18558 : | UNIQUE
18559 : | UNKNOWN
18560 : | UNLISTEN
18561 : | UNLOGGED
18562 : | UNTIL
18563 : | UPDATE
18564 : | USER
18565 : | USING
18566 : | VACUUM
18567 : | VALID
18568 : | VALIDATE
18569 : | VALIDATOR
18570 : | VALUE_P
18571 : | VALUES
18572 : | VARCHAR
18573 : | VARIADIC
18574 : | VERBOSE
18575 : | VERSION_P
18576 : | VIEW
18577 : | VIEWS
18578 : | VOLATILE
18579 : | WHEN
18580 : | WHITESPACE_P
18581 : | WORK
18582 : | WRAPPER
18583 : | WRITE
18584 : | XML_P
18585 : | XMLATTRIBUTES
18586 : | XMLCONCAT
18587 : | XMLELEMENT
18588 : | XMLEXISTS
18589 : | XMLFOREST
18590 : | XMLNAMESPACES
18591 : | XMLPARSE
18592 : | XMLPI
18593 : | XMLROOT
18594 : | XMLSERIALIZE
18595 : | XMLTABLE
18596 : | YES_P
18597 : | ZONE
18598 : ;
18599 :
18600 : %%
18601 :
18602 : /*
18603 : * The signature of this function is required by bison. However, we
18604 : * ignore the passed yylloc and instead use the last token position
18605 : * available from the scanner.
18606 : */
18607 : static void
18608 696 : base_yyerror(YYLTYPE *yylloc, core_yyscan_t yyscanner, const char *msg)
18609 : {
18610 696 : parser_yyerror(msg);
18611 : }
18612 :
18613 : static RawStmt *
18614 797388 : makeRawStmt(Node *stmt, int stmt_location)
18615 : {
18616 797388 : RawStmt *rs = makeNode(RawStmt);
18617 :
18618 797388 : rs->stmt = stmt;
18619 797388 : rs->stmt_location = stmt_location;
18620 797388 : rs->stmt_len = 0; /* might get changed later */
18621 797388 : return rs;
18622 : }
18623 :
18624 : /* Adjust a RawStmt to reflect that it doesn't run to the end of the string */
18625 : static void
18626 563104 : updateRawStmtEnd(RawStmt *rs, int end_location)
18627 : {
18628 : /*
18629 : * If we already set the length, don't change it. This is for situations
18630 : * like "select foo ;; select bar" where the same statement will be last
18631 : * in the string for more than one semicolon.
18632 : */
18633 563104 : if (rs->stmt_len > 0)
18634 302 : return;
18635 :
18636 : /* OK, update length of RawStmt */
18637 562802 : rs->stmt_len = end_location - rs->stmt_location;
18638 : }
18639 :
18640 : /*
18641 : * Adjust a PreparableStmt to reflect that it doesn't run to the end of the
18642 : * string.
18643 : */
18644 : static void
18645 436 : updatePreparableStmtEnd(Node *n, int end_location)
18646 : {
18647 436 : if (IsA(n, SelectStmt))
18648 : {
18649 248 : SelectStmt *stmt = (SelectStmt *)n;
18650 :
18651 248 : stmt->stmt_len = end_location - stmt->stmt_location;
18652 : }
18653 188 : else if (IsA(n, InsertStmt))
18654 : {
18655 62 : InsertStmt *stmt = (InsertStmt *)n;
18656 :
18657 62 : stmt->stmt_len = end_location - stmt->stmt_location;
18658 : }
18659 126 : else if (IsA(n, UpdateStmt))
18660 : {
18661 56 : UpdateStmt *stmt = (UpdateStmt *)n;
18662 :
18663 56 : stmt->stmt_len = end_location - stmt->stmt_location;
18664 : }
18665 70 : else if (IsA(n, DeleteStmt))
18666 : {
18667 54 : DeleteStmt *stmt = (DeleteStmt *)n;
18668 :
18669 54 : stmt->stmt_len = end_location - stmt->stmt_location;
18670 : }
18671 16 : else if (IsA(n, MergeStmt))
18672 : {
18673 16 : MergeStmt *stmt = (MergeStmt *)n;
18674 :
18675 16 : stmt->stmt_len = end_location - stmt->stmt_location;
18676 : }
18677 : else
18678 0 : elog(ERROR, "unexpected node type %d", (int) n->type);
18679 436 : }
18680 :
18681 : static Node *
18682 1608070 : makeColumnRef(char *colname, List *indirection,
18683 : int location, core_yyscan_t yyscanner)
18684 : {
18685 : /*
18686 : * Generate a ColumnRef node, with an A_Indirection node added if there
18687 : * is any subscripting in the specified indirection list. However,
18688 : * any field selection at the start of the indirection list must be
18689 : * transposed into the "fields" part of the ColumnRef node.
18690 : */
18691 1608070 : ColumnRef *c = makeNode(ColumnRef);
18692 1608070 : int nfields = 0;
18693 : ListCell *l;
18694 :
18695 1608070 : c->location = location;
18696 2551862 : foreach(l, indirection)
18697 : {
18698 953012 : if (IsA(lfirst(l), A_Indices))
18699 : {
18700 9220 : A_Indirection *i = makeNode(A_Indirection);
18701 :
18702 9220 : if (nfields == 0)
18703 : {
18704 : /* easy case - all indirection goes to A_Indirection */
18705 6618 : c->fields = list_make1(makeString(colname));
18706 6618 : i->indirection = check_indirection(indirection, yyscanner);
18707 : }
18708 : else
18709 : {
18710 : /* got to split the list in two */
18711 2602 : i->indirection = check_indirection(list_copy_tail(indirection,
18712 : nfields),
18713 : yyscanner);
18714 2602 : indirection = list_truncate(indirection, nfields);
18715 2602 : c->fields = lcons(makeString(colname), indirection);
18716 : }
18717 9220 : i->arg = (Node *) c;
18718 9220 : return (Node *) i;
18719 : }
18720 943792 : else if (IsA(lfirst(l), A_Star))
18721 : {
18722 : /* We only allow '*' at the end of a ColumnRef */
18723 4682 : if (lnext(indirection, l) != NULL)
18724 0 : parser_yyerror("improper use of \"*\"");
18725 : }
18726 943792 : nfields++;
18727 : }
18728 : /* No subscripting, so all indirection gets added to field list */
18729 1598850 : c->fields = lcons(makeString(colname), indirection);
18730 1598850 : return (Node *) c;
18731 : }
18732 :
18733 : static Node *
18734 268906 : makeTypeCast(Node *arg, TypeName *typename, int location)
18735 : {
18736 268906 : TypeCast *n = makeNode(TypeCast);
18737 :
18738 268906 : n->arg = arg;
18739 268906 : n->typeName = typename;
18740 268906 : n->location = location;
18741 268906 : return (Node *) n;
18742 : }
18743 :
18744 : static Node *
18745 16144 : makeStringConstCast(char *str, int location, TypeName *typename)
18746 : {
18747 16144 : Node *s = makeStringConst(str, location);
18748 :
18749 16144 : return makeTypeCast(s, typename, -1);
18750 : }
18751 :
18752 : static Node *
18753 435716 : makeIntConst(int val, int location)
18754 : {
18755 435716 : A_Const *n = makeNode(A_Const);
18756 :
18757 435716 : n->val.ival.type = T_Integer;
18758 435716 : n->val.ival.ival = val;
18759 435716 : n->location = location;
18760 :
18761 435716 : return (Node *) n;
18762 : }
18763 :
18764 : static Node *
18765 11872 : makeFloatConst(char *str, int location)
18766 : {
18767 11872 : A_Const *n = makeNode(A_Const);
18768 :
18769 11872 : n->val.fval.type = T_Float;
18770 11872 : n->val.fval.fval = str;
18771 11872 : n->location = location;
18772 :
18773 11872 : return (Node *) n;
18774 : }
18775 :
18776 : static Node *
18777 55066 : makeBoolAConst(bool state, int location)
18778 : {
18779 55066 : A_Const *n = makeNode(A_Const);
18780 :
18781 55066 : n->val.boolval.type = T_Boolean;
18782 55066 : n->val.boolval.boolval = state;
18783 55066 : n->location = location;
18784 :
18785 55066 : return (Node *) n;
18786 : }
18787 :
18788 : static Node *
18789 4056 : makeBitStringConst(char *str, int location)
18790 : {
18791 4056 : A_Const *n = makeNode(A_Const);
18792 :
18793 4056 : n->val.bsval.type = T_BitString;
18794 4056 : n->val.bsval.bsval = str;
18795 4056 : n->location = location;
18796 :
18797 4056 : return (Node *) n;
18798 : }
18799 :
18800 : static Node *
18801 61798 : makeNullAConst(int location)
18802 : {
18803 61798 : A_Const *n = makeNode(A_Const);
18804 :
18805 61798 : n->isnull = true;
18806 61798 : n->location = location;
18807 :
18808 61798 : return (Node *) n;
18809 : }
18810 :
18811 : static Node *
18812 4408 : makeAConst(Node *v, int location)
18813 : {
18814 : Node *n;
18815 :
18816 4408 : switch (v->type)
18817 : {
18818 218 : case T_Float:
18819 218 : n = makeFloatConst(castNode(Float, v)->fval, location);
18820 218 : break;
18821 :
18822 4190 : case T_Integer:
18823 4190 : n = makeIntConst(castNode(Integer, v)->ival, location);
18824 4190 : break;
18825 :
18826 0 : default:
18827 : /* currently not used */
18828 : Assert(false);
18829 0 : n = NULL;
18830 : }
18831 :
18832 4408 : return n;
18833 : }
18834 :
18835 : /* makeRoleSpec
18836 : * Create a RoleSpec with the given type
18837 : */
18838 : static RoleSpec *
18839 29852 : makeRoleSpec(RoleSpecType type, int location)
18840 : {
18841 29852 : RoleSpec *spec = makeNode(RoleSpec);
18842 :
18843 29852 : spec->roletype = type;
18844 29852 : spec->location = location;
18845 :
18846 29852 : return spec;
18847 : }
18848 :
18849 : /* check_qualified_name --- check the result of qualified_name production
18850 : *
18851 : * It's easiest to let the grammar production for qualified_name allow
18852 : * subscripts and '*', which we then must reject here.
18853 : */
18854 : static void
18855 222770 : check_qualified_name(List *names, core_yyscan_t yyscanner)
18856 : {
18857 : ListCell *i;
18858 :
18859 445540 : foreach(i, names)
18860 : {
18861 222770 : if (!IsA(lfirst(i), String))
18862 0 : parser_yyerror("syntax error");
18863 : }
18864 222770 : }
18865 :
18866 : /* check_func_name --- check the result of func_name production
18867 : *
18868 : * It's easiest to let the grammar production for func_name allow subscripts
18869 : * and '*', which we then must reject here.
18870 : */
18871 : static List *
18872 113638 : check_func_name(List *names, core_yyscan_t yyscanner)
18873 : {
18874 : ListCell *i;
18875 :
18876 340914 : foreach(i, names)
18877 : {
18878 227276 : if (!IsA(lfirst(i), String))
18879 0 : parser_yyerror("syntax error");
18880 : }
18881 113638 : return names;
18882 : }
18883 :
18884 : /* check_indirection --- check the result of indirection production
18885 : *
18886 : * We only allow '*' at the end of the list, but it's hard to enforce that
18887 : * in the grammar, so do it here.
18888 : */
18889 : static List *
18890 78036 : check_indirection(List *indirection, core_yyscan_t yyscanner)
18891 : {
18892 : ListCell *l;
18893 :
18894 103736 : foreach(l, indirection)
18895 : {
18896 25700 : if (IsA(lfirst(l), A_Star))
18897 : {
18898 1332 : if (lnext(indirection, l) != NULL)
18899 0 : parser_yyerror("improper use of \"*\"");
18900 : }
18901 : }
18902 78036 : return indirection;
18903 : }
18904 :
18905 : /* extractArgTypes()
18906 : * Given a list of FunctionParameter nodes, extract a list of just the
18907 : * argument types (TypeNames) for input parameters only. This is what
18908 : * is needed to look up an existing function, which is what is wanted by
18909 : * the productions that use this call.
18910 : */
18911 : static List *
18912 14514 : extractArgTypes(List *parameters)
18913 : {
18914 14514 : List *result = NIL;
18915 : ListCell *i;
18916 :
18917 31906 : foreach(i, parameters)
18918 : {
18919 17392 : FunctionParameter *p = (FunctionParameter *) lfirst(i);
18920 :
18921 17392 : if (p->mode != FUNC_PARAM_OUT && p->mode != FUNC_PARAM_TABLE)
18922 17236 : result = lappend(result, p->argType);
18923 : }
18924 14514 : return result;
18925 : }
18926 :
18927 : /* extractAggrArgTypes()
18928 : * As above, but work from the output of the aggr_args production.
18929 : */
18930 : static List *
18931 362 : extractAggrArgTypes(List *aggrargs)
18932 : {
18933 : Assert(list_length(aggrargs) == 2);
18934 362 : return extractArgTypes((List *) linitial(aggrargs));
18935 : }
18936 :
18937 : /* makeOrderedSetArgs()
18938 : * Build the result of the aggr_args production (which see the comments for).
18939 : * This handles only the case where both given lists are nonempty, so that
18940 : * we have to deal with multiple VARIADIC arguments.
18941 : */
18942 : static List *
18943 32 : makeOrderedSetArgs(List *directargs, List *orderedargs,
18944 : core_yyscan_t yyscanner)
18945 : {
18946 32 : FunctionParameter *lastd = (FunctionParameter *) llast(directargs);
18947 : Integer *ndirectargs;
18948 :
18949 : /* No restriction unless last direct arg is VARIADIC */
18950 32 : if (lastd->mode == FUNC_PARAM_VARIADIC)
18951 : {
18952 16 : FunctionParameter *firsto = (FunctionParameter *) linitial(orderedargs);
18953 :
18954 : /*
18955 : * We ignore the names, though the aggr_arg production allows them;
18956 : * it doesn't allow default values, so those need not be checked.
18957 : */
18958 16 : if (list_length(orderedargs) != 1 ||
18959 16 : firsto->mode != FUNC_PARAM_VARIADIC ||
18960 16 : !equal(lastd->argType, firsto->argType))
18961 0 : ereport(ERROR,
18962 : (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
18963 : errmsg("an ordered-set aggregate with a VARIADIC direct argument must have one VARIADIC aggregated argument of the same data type"),
18964 : parser_errposition(firsto->location)));
18965 :
18966 : /* OK, drop the duplicate VARIADIC argument from the internal form */
18967 16 : orderedargs = NIL;
18968 : }
18969 :
18970 : /* don't merge into the next line, as list_concat changes directargs */
18971 32 : ndirectargs = makeInteger(list_length(directargs));
18972 :
18973 32 : return list_make2(list_concat(directargs, orderedargs),
18974 : ndirectargs);
18975 : }
18976 :
18977 : /* insertSelectOptions()
18978 : * Insert ORDER BY, etc into an already-constructed SelectStmt.
18979 : *
18980 : * This routine is just to avoid duplicating code in SelectStmt productions.
18981 : */
18982 : static void
18983 71808 : insertSelectOptions(SelectStmt *stmt,
18984 : List *sortClause, List *lockingClause,
18985 : SelectLimit *limitClause,
18986 : WithClause *withClause,
18987 : core_yyscan_t yyscanner)
18988 : {
18989 : Assert(IsA(stmt, SelectStmt));
18990 :
18991 : /*
18992 : * Tests here are to reject constructs like
18993 : * (SELECT foo ORDER BY bar) ORDER BY baz
18994 : */
18995 71808 : if (sortClause)
18996 : {
18997 62804 : if (stmt->sortClause)
18998 0 : ereport(ERROR,
18999 : (errcode(ERRCODE_SYNTAX_ERROR),
19000 : errmsg("multiple ORDER BY clauses not allowed"),
19001 : parser_errposition(exprLocation((Node *) sortClause))));
19002 62804 : stmt->sortClause = sortClause;
19003 : }
19004 : /* We can handle multiple locking clauses, though */
19005 71808 : stmt->lockingClause = list_concat(stmt->lockingClause, lockingClause);
19006 71808 : if (limitClause && limitClause->limitOffset)
19007 : {
19008 756 : if (stmt->limitOffset)
19009 0 : ereport(ERROR,
19010 : (errcode(ERRCODE_SYNTAX_ERROR),
19011 : errmsg("multiple OFFSET clauses not allowed"),
19012 : parser_errposition(limitClause->offsetLoc)));
19013 756 : stmt->limitOffset = limitClause->limitOffset;
19014 : }
19015 71808 : if (limitClause && limitClause->limitCount)
19016 : {
19017 4538 : if (stmt->limitCount)
19018 0 : ereport(ERROR,
19019 : (errcode(ERRCODE_SYNTAX_ERROR),
19020 : errmsg("multiple LIMIT clauses not allowed"),
19021 : parser_errposition(limitClause->countLoc)));
19022 4538 : stmt->limitCount = limitClause->limitCount;
19023 : }
19024 71808 : if (limitClause)
19025 : {
19026 : /* If there was a conflict, we must have detected it above */
19027 : Assert(!stmt->limitOption);
19028 4912 : if (!stmt->sortClause && limitClause->limitOption == LIMIT_OPTION_WITH_TIES)
19029 6 : ereport(ERROR,
19030 : (errcode(ERRCODE_SYNTAX_ERROR),
19031 : errmsg("WITH TIES cannot be specified without ORDER BY clause"),
19032 : parser_errposition(limitClause->optionLoc)));
19033 4906 : if (limitClause->limitOption == LIMIT_OPTION_WITH_TIES && stmt->lockingClause)
19034 : {
19035 : ListCell *lc;
19036 :
19037 6 : foreach(lc, stmt->lockingClause)
19038 : {
19039 6 : LockingClause *lock = lfirst_node(LockingClause, lc);
19040 :
19041 6 : if (lock->waitPolicy == LockWaitSkip)
19042 6 : ereport(ERROR,
19043 : (errcode(ERRCODE_SYNTAX_ERROR),
19044 : errmsg("%s and %s options cannot be used together",
19045 : "SKIP LOCKED", "WITH TIES"),
19046 : parser_errposition(limitClause->optionLoc)));
19047 : }
19048 : }
19049 4900 : stmt->limitOption = limitClause->limitOption;
19050 : }
19051 71796 : if (withClause)
19052 : {
19053 2488 : if (stmt->withClause)
19054 0 : ereport(ERROR,
19055 : (errcode(ERRCODE_SYNTAX_ERROR),
19056 : errmsg("multiple WITH clauses not allowed"),
19057 : parser_errposition(exprLocation((Node *) withClause))));
19058 2488 : stmt->withClause = withClause;
19059 :
19060 : /* Update SelectStmt's location to the start of the WITH clause */
19061 2488 : stmt->stmt_location = withClause->location;
19062 : }
19063 71796 : }
19064 :
19065 : static Node *
19066 14804 : makeSetOp(SetOperation op, bool all, Node *larg, Node *rarg, int location)
19067 : {
19068 14804 : SelectStmt *n = makeNode(SelectStmt);
19069 :
19070 14804 : n->op = op;
19071 14804 : n->all = all;
19072 14804 : n->larg = (SelectStmt *) larg;
19073 14804 : n->rarg = (SelectStmt *) rarg;
19074 14804 : n->stmt_location = location;
19075 14804 : return (Node *) n;
19076 : }
19077 :
19078 : /* SystemFuncName()
19079 : * Build a properly-qualified reference to a built-in function.
19080 : */
19081 : List *
19082 17466 : SystemFuncName(char *name)
19083 : {
19084 17466 : return list_make2(makeString("pg_catalog"), makeString(name));
19085 : }
19086 :
19087 : /* SystemTypeName()
19088 : * Build a properly-qualified reference to a built-in type.
19089 : *
19090 : * typmod is defaulted, but may be changed afterwards by caller.
19091 : * Likewise for the location.
19092 : */
19093 : TypeName *
19094 96204 : SystemTypeName(char *name)
19095 : {
19096 96204 : return makeTypeNameFromNameList(list_make2(makeString("pg_catalog"),
19097 : makeString(name)));
19098 : }
19099 :
19100 : /* doNegate()
19101 : * Handle negation of a numeric constant.
19102 : *
19103 : * Formerly, we did this here because the optimizer couldn't cope with
19104 : * indexquals that looked like "var = -4" --- it wants "var = const"
19105 : * and a unary minus operator applied to a constant didn't qualify.
19106 : * As of Postgres 7.0, that problem doesn't exist anymore because there
19107 : * is a constant-subexpression simplifier in the optimizer. However,
19108 : * there's still a good reason for doing this here, which is that we can
19109 : * postpone committing to a particular internal representation for simple
19110 : * negative constants. It's better to leave "-123.456" in string form
19111 : * until we know what the desired type is.
19112 : */
19113 : static Node *
19114 27910 : doNegate(Node *n, int location)
19115 : {
19116 27910 : if (IsA(n, A_Const))
19117 : {
19118 26638 : A_Const *con = (A_Const *) n;
19119 :
19120 : /* report the constant's location as that of the '-' sign */
19121 26638 : con->location = location;
19122 :
19123 26638 : if (IsA(&con->val, Integer))
19124 : {
19125 25698 : con->val.ival.ival = -con->val.ival.ival;
19126 25698 : return n;
19127 : }
19128 940 : if (IsA(&con->val, Float))
19129 : {
19130 940 : doNegateFloat(&con->val.fval);
19131 940 : return n;
19132 : }
19133 : }
19134 :
19135 1272 : return (Node *) makeSimpleA_Expr(AEXPR_OP, "-", NULL, n, location);
19136 : }
19137 :
19138 : static void
19139 960 : doNegateFloat(Float *v)
19140 : {
19141 960 : char *oldval = v->fval;
19142 :
19143 960 : if (*oldval == '+')
19144 0 : oldval++;
19145 960 : if (*oldval == '-')
19146 0 : v->fval = oldval+1; /* just strip the '-' */
19147 : else
19148 960 : v->fval = psprintf("-%s", oldval);
19149 960 : }
19150 :
19151 : static Node *
19152 209604 : makeAndExpr(Node *lexpr, Node *rexpr, int location)
19153 : {
19154 : /* Flatten "a AND b AND c ..." to a single BoolExpr on sight */
19155 209604 : if (IsA(lexpr, BoolExpr))
19156 : {
19157 97790 : BoolExpr *blexpr = (BoolExpr *) lexpr;
19158 :
19159 97790 : if (blexpr->boolop == AND_EXPR)
19160 : {
19161 95450 : blexpr->args = lappend(blexpr->args, rexpr);
19162 95450 : return (Node *) blexpr;
19163 : }
19164 : }
19165 114154 : return (Node *) makeBoolExpr(AND_EXPR, list_make2(lexpr, rexpr), location);
19166 : }
19167 :
19168 : static Node *
19169 15438 : makeOrExpr(Node *lexpr, Node *rexpr, int location)
19170 : {
19171 : /* Flatten "a OR b OR c ..." to a single BoolExpr on sight */
19172 15438 : if (IsA(lexpr, BoolExpr))
19173 : {
19174 6346 : BoolExpr *blexpr = (BoolExpr *) lexpr;
19175 :
19176 6346 : if (blexpr->boolop == OR_EXPR)
19177 : {
19178 3530 : blexpr->args = lappend(blexpr->args, rexpr);
19179 3530 : return (Node *) blexpr;
19180 : }
19181 : }
19182 11908 : return (Node *) makeBoolExpr(OR_EXPR, list_make2(lexpr, rexpr), location);
19183 : }
19184 :
19185 : static Node *
19186 14202 : makeNotExpr(Node *expr, int location)
19187 : {
19188 14202 : return (Node *) makeBoolExpr(NOT_EXPR, list_make1(expr), location);
19189 : }
19190 :
19191 : static Node *
19192 7876 : makeAArrayExpr(List *elements, int location)
19193 : {
19194 7876 : A_ArrayExpr *n = makeNode(A_ArrayExpr);
19195 :
19196 7876 : n->elements = elements;
19197 7876 : n->location = location;
19198 7876 : return (Node *) n;
19199 : }
19200 :
19201 : static Node *
19202 2654 : makeSQLValueFunction(SQLValueFunctionOp op, int32 typmod, int location)
19203 : {
19204 2654 : SQLValueFunction *svf = makeNode(SQLValueFunction);
19205 :
19206 2654 : svf->op = op;
19207 : /* svf->type will be filled during parse analysis */
19208 2654 : svf->typmod = typmod;
19209 2654 : svf->location = location;
19210 2654 : return (Node *) svf;
19211 : }
19212 :
19213 : static Node *
19214 596 : makeXmlExpr(XmlExprOp op, char *name, List *named_args, List *args,
19215 : int location)
19216 : {
19217 596 : XmlExpr *x = makeNode(XmlExpr);
19218 :
19219 596 : x->op = op;
19220 596 : x->name = name;
19221 : /*
19222 : * named_args is a list of ResTarget; it'll be split apart into separate
19223 : * expression and name lists in transformXmlExpr().
19224 : */
19225 596 : x->named_args = named_args;
19226 596 : x->arg_names = NIL;
19227 596 : x->args = args;
19228 : /* xmloption, if relevant, must be filled in by caller */
19229 : /* type and typmod will be filled in during parse analysis */
19230 596 : x->type = InvalidOid; /* marks the node as not analyzed */
19231 596 : x->location = location;
19232 596 : return (Node *) x;
19233 : }
19234 :
19235 : /*
19236 : * Merge the input and output parameters of a table function.
19237 : */
19238 : static List *
19239 188 : mergeTableFuncParameters(List *func_args, List *columns, core_yyscan_t yyscanner)
19240 : {
19241 : ListCell *lc;
19242 :
19243 : /* Explicit OUT and INOUT parameters shouldn't be used in this syntax */
19244 382 : foreach(lc, func_args)
19245 : {
19246 194 : FunctionParameter *p = (FunctionParameter *) lfirst(lc);
19247 :
19248 194 : if (p->mode != FUNC_PARAM_DEFAULT &&
19249 0 : p->mode != FUNC_PARAM_IN &&
19250 0 : p->mode != FUNC_PARAM_VARIADIC)
19251 0 : ereport(ERROR,
19252 : (errcode(ERRCODE_SYNTAX_ERROR),
19253 : errmsg("OUT and INOUT arguments aren't allowed in TABLE functions"),
19254 : parser_errposition(p->location)));
19255 : }
19256 :
19257 188 : return list_concat(func_args, columns);
19258 : }
19259 :
19260 : /*
19261 : * Determine return type of a TABLE function. A single result column
19262 : * returns setof that column's type; otherwise return setof record.
19263 : */
19264 : static TypeName *
19265 188 : TableFuncTypeName(List *columns)
19266 : {
19267 : TypeName *result;
19268 :
19269 188 : if (list_length(columns) == 1)
19270 : {
19271 62 : FunctionParameter *p = (FunctionParameter *) linitial(columns);
19272 :
19273 62 : result = copyObject(p->argType);
19274 : }
19275 : else
19276 126 : result = SystemTypeName("record");
19277 :
19278 188 : result->setof = true;
19279 :
19280 188 : return result;
19281 : }
19282 :
19283 : /*
19284 : * Convert a list of (dotted) names to a RangeVar (like
19285 : * makeRangeVarFromNameList, but with position support). The
19286 : * "AnyName" refers to the any_name production in the grammar.
19287 : */
19288 : static RangeVar *
19289 3718 : makeRangeVarFromAnyName(List *names, int position, core_yyscan_t yyscanner)
19290 : {
19291 3718 : RangeVar *r = makeNode(RangeVar);
19292 :
19293 3718 : switch (list_length(names))
19294 : {
19295 3628 : case 1:
19296 3628 : r->catalogname = NULL;
19297 3628 : r->schemaname = NULL;
19298 3628 : r->relname = strVal(linitial(names));
19299 3628 : break;
19300 90 : case 2:
19301 90 : r->catalogname = NULL;
19302 90 : r->schemaname = strVal(linitial(names));
19303 90 : r->relname = strVal(lsecond(names));
19304 90 : break;
19305 0 : case 3:
19306 0 : r->catalogname = strVal(linitial(names));
19307 0 : r->schemaname = strVal(lsecond(names));
19308 0 : r->relname = strVal(lthird(names));
19309 0 : break;
19310 0 : default:
19311 0 : ereport(ERROR,
19312 : (errcode(ERRCODE_SYNTAX_ERROR),
19313 : errmsg("improper qualified name (too many dotted names): %s",
19314 : NameListToString(names)),
19315 : parser_errposition(position)));
19316 : break;
19317 : }
19318 :
19319 3718 : r->relpersistence = RELPERSISTENCE_PERMANENT;
19320 3718 : r->location = position;
19321 :
19322 3718 : return r;
19323 : }
19324 :
19325 : /*
19326 : * Convert a relation_name with name and namelist to a RangeVar using
19327 : * makeRangeVar.
19328 : */
19329 : static RangeVar *
19330 222770 : makeRangeVarFromQualifiedName(char *name, List *namelist, int location,
19331 : core_yyscan_t yyscanner)
19332 : {
19333 : RangeVar *r;
19334 :
19335 222770 : check_qualified_name(namelist, yyscanner);
19336 222770 : r = makeRangeVar(NULL, NULL, location);
19337 :
19338 222770 : switch (list_length(namelist))
19339 : {
19340 222770 : case 1:
19341 222770 : r->catalogname = NULL;
19342 222770 : r->schemaname = name;
19343 222770 : r->relname = strVal(linitial(namelist));
19344 222770 : break;
19345 0 : case 2:
19346 0 : r->catalogname = name;
19347 0 : r->schemaname = strVal(linitial(namelist));
19348 0 : r->relname = strVal(lsecond(namelist));
19349 0 : break;
19350 0 : default:
19351 0 : ereport(ERROR,
19352 : errcode(ERRCODE_SYNTAX_ERROR),
19353 : errmsg("improper qualified name (too many dotted names): %s",
19354 : NameListToString(lcons(makeString(name), namelist))),
19355 : parser_errposition(location));
19356 : break;
19357 : }
19358 :
19359 222770 : return r;
19360 : }
19361 :
19362 : /* Separate Constraint nodes from COLLATE clauses in a ColQualList */
19363 : static void
19364 64680 : SplitColQualList(List *qualList,
19365 : List **constraintList, CollateClause **collClause,
19366 : core_yyscan_t yyscanner)
19367 : {
19368 : ListCell *cell;
19369 :
19370 64680 : *collClause = NULL;
19371 82112 : foreach(cell, qualList)
19372 : {
19373 17432 : Node *n = (Node *) lfirst(cell);
19374 :
19375 17432 : if (IsA(n, Constraint))
19376 : {
19377 : /* keep it in list */
19378 16750 : continue;
19379 : }
19380 682 : if (IsA(n, CollateClause))
19381 : {
19382 682 : CollateClause *c = (CollateClause *) n;
19383 :
19384 682 : if (*collClause)
19385 0 : ereport(ERROR,
19386 : (errcode(ERRCODE_SYNTAX_ERROR),
19387 : errmsg("multiple COLLATE clauses not allowed"),
19388 : parser_errposition(c->location)));
19389 682 : *collClause = c;
19390 : }
19391 : else
19392 0 : elog(ERROR, "unexpected node type %d", (int) n->type);
19393 : /* remove non-Constraint nodes from qualList */
19394 682 : qualList = foreach_delete_current(qualList, cell);
19395 : }
19396 64680 : *constraintList = qualList;
19397 64680 : }
19398 :
19399 : /*
19400 : * Process result of ConstraintAttributeSpec, and set appropriate bool flags
19401 : * in the output command node. Pass NULL for any flags the particular
19402 : * command doesn't support.
19403 : */
19404 : static void
19405 15972 : processCASbits(int cas_bits, int location, const char *constrType,
19406 : bool *deferrable, bool *initdeferred, bool *not_valid,
19407 : bool *no_inherit, core_yyscan_t yyscanner)
19408 : {
19409 : /* defaults */
19410 15972 : if (deferrable)
19411 14356 : *deferrable = false;
19412 15972 : if (initdeferred)
19413 14356 : *initdeferred = false;
19414 15972 : if (not_valid)
19415 2956 : *not_valid = false;
19416 :
19417 15972 : if (cas_bits & (CAS_DEFERRABLE | CAS_INITIALLY_DEFERRED))
19418 : {
19419 240 : if (deferrable)
19420 240 : *deferrable = true;
19421 : else
19422 0 : ereport(ERROR,
19423 : (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
19424 : /* translator: %s is CHECK, UNIQUE, or similar */
19425 : errmsg("%s constraints cannot be marked DEFERRABLE",
19426 : constrType),
19427 : parser_errposition(location)));
19428 : }
19429 :
19430 15972 : if (cas_bits & CAS_INITIALLY_DEFERRED)
19431 : {
19432 156 : if (initdeferred)
19433 156 : *initdeferred = true;
19434 : else
19435 0 : ereport(ERROR,
19436 : (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
19437 : /* translator: %s is CHECK, UNIQUE, or similar */
19438 : errmsg("%s constraints cannot be marked DEFERRABLE",
19439 : constrType),
19440 : parser_errposition(location)));
19441 : }
19442 :
19443 15972 : if (cas_bits & CAS_NOT_VALID)
19444 : {
19445 516 : if (not_valid)
19446 516 : *not_valid = true;
19447 : else
19448 0 : ereport(ERROR,
19449 : (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
19450 : /* translator: %s is CHECK, UNIQUE, or similar */
19451 : errmsg("%s constraints cannot be marked NOT VALID",
19452 : constrType),
19453 : parser_errposition(location)));
19454 : }
19455 :
19456 15972 : if (cas_bits & CAS_NO_INHERIT)
19457 : {
19458 190 : if (no_inherit)
19459 190 : *no_inherit = true;
19460 : else
19461 0 : ereport(ERROR,
19462 : (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
19463 : /* translator: %s is CHECK, UNIQUE, or similar */
19464 : errmsg("%s constraints cannot be marked NO INHERIT",
19465 : constrType),
19466 : parser_errposition(location)));
19467 : }
19468 15972 : }
19469 :
19470 : /*
19471 : * Parse a user-supplied partition strategy string into parse node
19472 : * PartitionStrategy representation, or die trying.
19473 : */
19474 : static PartitionStrategy
19475 4808 : parsePartitionStrategy(char *strategy, int location, core_yyscan_t yyscanner)
19476 : {
19477 4808 : if (pg_strcasecmp(strategy, "list") == 0)
19478 2460 : return PARTITION_STRATEGY_LIST;
19479 2348 : else if (pg_strcasecmp(strategy, "range") == 0)
19480 2102 : return PARTITION_STRATEGY_RANGE;
19481 246 : else if (pg_strcasecmp(strategy, "hash") == 0)
19482 240 : return PARTITION_STRATEGY_HASH;
19483 :
19484 6 : ereport(ERROR,
19485 : (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
19486 : errmsg("unrecognized partitioning strategy \"%s\"", strategy),
19487 : parser_errposition(location)));
19488 : return PARTITION_STRATEGY_LIST; /* keep compiler quiet */
19489 :
19490 : }
19491 :
19492 : /*
19493 : * Process pubobjspec_list to check for errors in any of the objects and
19494 : * convert PUBLICATIONOBJ_CONTINUATION into appropriate PublicationObjSpecType.
19495 : */
19496 : static void
19497 1526 : preprocess_pubobj_list(List *pubobjspec_list, core_yyscan_t yyscanner)
19498 : {
19499 : ListCell *cell;
19500 : PublicationObjSpec *pubobj;
19501 1526 : PublicationObjSpecType prevobjtype = PUBLICATIONOBJ_CONTINUATION;
19502 :
19503 1526 : if (!pubobjspec_list)
19504 0 : return;
19505 :
19506 1526 : pubobj = (PublicationObjSpec *) linitial(pubobjspec_list);
19507 1526 : if (pubobj->pubobjtype == PUBLICATIONOBJ_CONTINUATION)
19508 12 : ereport(ERROR,
19509 : errcode(ERRCODE_SYNTAX_ERROR),
19510 : errmsg("invalid publication object list"),
19511 : errdetail("One of TABLE or TABLES IN SCHEMA must be specified before a standalone table or schema name."),
19512 : parser_errposition(pubobj->location));
19513 :
19514 3228 : foreach(cell, pubobjspec_list)
19515 : {
19516 1738 : pubobj = (PublicationObjSpec *) lfirst(cell);
19517 :
19518 1738 : if (pubobj->pubobjtype == PUBLICATIONOBJ_CONTINUATION)
19519 174 : pubobj->pubobjtype = prevobjtype;
19520 :
19521 1738 : if (pubobj->pubobjtype == PUBLICATIONOBJ_TABLE)
19522 : {
19523 : /* relation name or pubtable must be set for this type of object */
19524 1334 : if (!pubobj->name && !pubobj->pubtable)
19525 6 : ereport(ERROR,
19526 : errcode(ERRCODE_SYNTAX_ERROR),
19527 : errmsg("invalid table name"),
19528 : parser_errposition(pubobj->location));
19529 :
19530 1328 : if (pubobj->name)
19531 : {
19532 : /* convert it to PublicationTable */
19533 58 : PublicationTable *pubtable = makeNode(PublicationTable);
19534 :
19535 58 : pubtable->relation =
19536 58 : makeRangeVar(NULL, pubobj->name, pubobj->location);
19537 58 : pubobj->pubtable = pubtable;
19538 58 : pubobj->name = NULL;
19539 : }
19540 : }
19541 404 : else if (pubobj->pubobjtype == PUBLICATIONOBJ_TABLES_IN_SCHEMA ||
19542 24 : pubobj->pubobjtype == PUBLICATIONOBJ_TABLES_IN_CUR_SCHEMA)
19543 : {
19544 : /* WHERE clause is not allowed on a schema object */
19545 404 : if (pubobj->pubtable && pubobj->pubtable->whereClause)
19546 6 : ereport(ERROR,
19547 : errcode(ERRCODE_SYNTAX_ERROR),
19548 : errmsg("WHERE clause not allowed for schema"),
19549 : parser_errposition(pubobj->location));
19550 :
19551 : /* Column list is not allowed on a schema object */
19552 398 : if (pubobj->pubtable && pubobj->pubtable->columns)
19553 6 : ereport(ERROR,
19554 : errcode(ERRCODE_SYNTAX_ERROR),
19555 : errmsg("column specification not allowed for schema"),
19556 : parser_errposition(pubobj->location));
19557 :
19558 : /*
19559 : * We can distinguish between the different type of schema
19560 : * objects based on whether name and pubtable is set.
19561 : */
19562 392 : if (pubobj->name)
19563 362 : pubobj->pubobjtype = PUBLICATIONOBJ_TABLES_IN_SCHEMA;
19564 30 : else if (!pubobj->name && !pubobj->pubtable)
19565 24 : pubobj->pubobjtype = PUBLICATIONOBJ_TABLES_IN_CUR_SCHEMA;
19566 : else
19567 6 : ereport(ERROR,
19568 : errcode(ERRCODE_SYNTAX_ERROR),
19569 : errmsg("invalid schema name"),
19570 : parser_errposition(pubobj->location));
19571 : }
19572 :
19573 1714 : prevobjtype = pubobj->pubobjtype;
19574 : }
19575 : }
19576 :
19577 : /*----------
19578 : * Recursive view transformation
19579 : *
19580 : * Convert
19581 : *
19582 : * CREATE RECURSIVE VIEW relname (aliases) AS query
19583 : *
19584 : * to
19585 : *
19586 : * CREATE VIEW relname (aliases) AS
19587 : * WITH RECURSIVE relname (aliases) AS (query)
19588 : * SELECT aliases FROM relname
19589 : *
19590 : * Actually, just the WITH ... part, which is then inserted into the original
19591 : * view definition as the query.
19592 : * ----------
19593 : */
19594 : static Node *
19595 14 : makeRecursiveViewSelect(char *relname, List *aliases, Node *query)
19596 : {
19597 14 : SelectStmt *s = makeNode(SelectStmt);
19598 14 : WithClause *w = makeNode(WithClause);
19599 14 : CommonTableExpr *cte = makeNode(CommonTableExpr);
19600 14 : List *tl = NIL;
19601 : ListCell *lc;
19602 :
19603 : /* create common table expression */
19604 14 : cte->ctename = relname;
19605 14 : cte->aliascolnames = aliases;
19606 14 : cte->ctematerialized = CTEMaterializeDefault;
19607 14 : cte->ctequery = query;
19608 14 : cte->location = -1;
19609 :
19610 : /* create WITH clause and attach CTE */
19611 14 : w->recursive = true;
19612 14 : w->ctes = list_make1(cte);
19613 14 : w->location = -1;
19614 :
19615 : /* create target list for the new SELECT from the alias list of the
19616 : * recursive view specification */
19617 28 : foreach (lc, aliases)
19618 : {
19619 14 : ResTarget *rt = makeNode(ResTarget);
19620 :
19621 14 : rt->name = NULL;
19622 14 : rt->indirection = NIL;
19623 14 : rt->val = makeColumnRef(strVal(lfirst(lc)), NIL, -1, 0);
19624 14 : rt->location = -1;
19625 :
19626 14 : tl = lappend(tl, rt);
19627 : }
19628 :
19629 : /* create new SELECT combining WITH clause, target list, and fake FROM
19630 : * clause */
19631 14 : s->withClause = w;
19632 14 : s->targetList = tl;
19633 14 : s->fromClause = list_make1(makeRangeVar(NULL, relname, -1));
19634 :
19635 14 : return (Node *) s;
19636 : }
19637 :
19638 : /* parser_init()
19639 : * Initialize to parse one query string
19640 : */
19641 : void
19642 758810 : parser_init(base_yy_extra_type *yyext)
19643 : {
19644 758810 : yyext->parsetree = NIL; /* in case grammar forgets to set it */
19645 758810 : }
|