Debian Codegraph @

src/backend/parser/gram.y

raw
1 %{
2
3 /*#define YYDEBUG 1*/
4 /*-------------------------------------------------------------------------
5 *
6 * gram.y
7 * POSTGRESQL BISON rules/actions
8 *
9 * Portions Copyright (c) 1996-2025, PostgreSQL Global Development Group
10 * Portions Copyright (c) 1994, Regents of the University of California
11 *
12 *
13 * IDENTIFICATION
14 * src/backend/parser/gram.y
15 *
16 * HISTORY
17 * AUTHOR DATE MAJOR EVENT
18 * Andrew Yu Sept, 1994 POSTQUEL to SQL conversion
19 * Andrew Yu Oct, 1994 lispy code conversion
20 *
21 * NOTES
22 * CAPITALS are used to represent terminal symbols.
23 * non-capitals are used to represent non-terminals.
24 *
25 * In general, nothing in this file should initiate database accesses
26 * nor depend on changeable state (such as SET variables). If you do
27 * database accesses, your code will fail when we have aborted the
28 * current transaction and are just parsing commands to find the next
29 * ROLLBACK or COMMIT. If you make use of SET variables, then you
30 * will do the wrong thing in multi-query strings like this:
31 * SET constraint_exclusion TO off; SELECT * FROM foo;
32 * because the entire string is parsed by gram.y before the SET gets
33 * executed. Anything that depends on the database or changeable state
34 * should be handled during parse analysis so that it happens at the
35 * right time not the wrong time.
36 *
37 * WARNINGS
38 * If you use a list, make sure the datum is a node so that the printing
39 * routines work.
40 *
41 * Sometimes we assign constants to makeStrings. Make sure we don't free
42 * those.
43 *
44 *-------------------------------------------------------------------------
45 */
46 #include "postgres.h"
47
48 #include <ctype.h>
49 #include <limits.h>
50
51 #include "catalog/index.h"
52 #include "catalog/namespace.h"
53 #include "catalog/pg_am.h"
54 #include "catalog/pg_trigger.h"
55 #include "commands/defrem.h"
56 #include "commands/trigger.h"
57 #include "gramparse.h"
58 #include "nodes/makefuncs.h"
59 #include "nodes/nodeFuncs.h"
60 #include "parser/parser.h"
61 #include "utils/datetime.h"
62 #include "utils/xml.h"
63
64
65 /*
66 * Location tracking support. Unlike bison's default, we only want
67 * to track the start position not the end position of each nonterminal.
68 * Nonterminals that reduce to empty receive position "-1". Since a
69 * production's leading RHS nonterminal(s) may have reduced to empty,
70 * we have to scan to find the first one that's not -1.
71 */
72 #define YYLLOC_DEFAULT(Current, Rhs, N) \
73 do { \
74 (Current) = (-1); \
75 for (int _i = 1; _i <= (N); _i++) \
76 { \
77 if ((Rhs)[_i] >= 0) \
78 { \
79 (Current) = (Rhs)[_i]; \
80 break; \
81 } \
82 } \
83 } while (0)
84
85 /*
86 * Bison doesn't allocate anything that needs to live across parser calls,
87 * so we can easily have it use palloc instead of malloc. This prevents
88 * memory leaks if we error out during parsing.
89 */
90 #define YYMALLOC palloc
91 #define YYFREE pfree
92
93 /* Private struct for the result of privilege_target production */
94 typedef struct PrivTarget
95 {
96 GrantTargetType targtype;
97 ObjectType objtype;
98 List *objs;
99 } PrivTarget;
100
101 /* Private struct for the result of import_qualification production */
102 typedef struct ImportQual
103 {
104 ImportForeignSchemaType type;
105 List *table_names;
106 } ImportQual;
107
108 /* Private struct for the result of select_limit & limit_clause productions */
109 typedef struct SelectLimit
110 {
111 Node *limitOffset;
112 Node *limitCount;
113 LimitOption limitOption; /* indicates presence of WITH TIES */
114 ParseLoc offsetLoc; /* location of OFFSET token, if present */
115 ParseLoc countLoc; /* location of LIMIT/FETCH token, if present */
116 ParseLoc optionLoc; /* location of WITH TIES, if present */
117 } SelectLimit;
118
119 /* Private struct for the result of group_clause production */
120 typedef struct GroupClause
121 {
122 bool distinct;
123 List *list;
124 } GroupClause;
125
126 /* Private structs for the result of key_actions and key_action productions */
127 typedef struct KeyAction
128 {
129 char action;
130 List *cols;
131 } KeyAction;
132
133 typedef struct KeyActions
134 {
135 KeyAction *updateAction;
136 KeyAction *deleteAction;
137 } KeyActions;
138
139 /* ConstraintAttributeSpec yields an integer bitmask of these flags: */
140 #define CAS_NOT_DEFERRABLE 0x01
141 #define CAS_DEFERRABLE 0x02
142 #define CAS_INITIALLY_IMMEDIATE 0x04
143 #define CAS_INITIALLY_DEFERRED 0x08
144 #define CAS_NOT_VALID 0x10
145 #define CAS_NO_INHERIT 0x20
146 #define CAS_NOT_ENFORCED 0x40
147 #define CAS_ENFORCED 0x80
148
149
150 #define parser_yyerror(msg) scanner_yyerror(msg, yyscanner)
151 #define parser_errposition(pos) scanner_errposition(pos, yyscanner)
152
153 static void base_yyerror(YYLTYPE *yylloc, core_yyscan_t yyscanner,
154 const char *msg);
155 static RawStmt *makeRawStmt(Node *stmt, int stmt_location);
156 static void updateRawStmtEnd(RawStmt *rs, int end_location);
157 static Node *makeColumnRef(char *colname, List *indirection,
158 int location, core_yyscan_t yyscanner);
159 static Node *makeTypeCast(Node *arg, TypeName *typename, int location);
160 static Node *makeStringConstCast(char *str, int location, TypeName *typename);
161 static Node *makeIntConst(int val, int location);
162 static Node *makeFloatConst(char *str, int location);
163 static Node *makeBoolAConst(bool state, int location);
164 static Node *makeBitStringConst(char *str, int location);
165 static Node *makeNullAConst(int location);
166 static Node *makeAConst(Node *v, int location);
167 static RoleSpec *makeRoleSpec(RoleSpecType type, int location);
168 static void check_qualified_name(List *names, core_yyscan_t yyscanner);
169 static List *check_func_name(List *names, core_yyscan_t yyscanner);
170 static List *check_indirection(List *indirection, core_yyscan_t yyscanner);
171 static List *extractArgTypes(List *parameters);
172 static List *extractAggrArgTypes(List *aggrargs);
173 static List *makeOrderedSetArgs(List *directargs, List *orderedargs,
174 core_yyscan_t yyscanner);
175 static void insertSelectOptions(SelectStmt *stmt,
176 List *sortClause, List *lockingClause,
177 SelectLimit *limitClause,
178 WithClause *withClause,
179 core_yyscan_t yyscanner);
180 static Node *makeSetOp(SetOperation op, bool all, Node *larg, Node *rarg);
181 static Node *doNegate(Node *n, int location);
182 static void doNegateFloat(Float *v);
183 static Node *makeAndExpr(Node *lexpr, Node *rexpr, int location);
184 static Node *makeOrExpr(Node *lexpr, Node *rexpr, int location);
185 static Node *makeNotExpr(Node *expr, int location);
186 static Node *makeAArrayExpr(List *elements, int location, int end_location);
187 static Node *makeSQLValueFunction(SQLValueFunctionOp op, int32 typmod,
188 int location);
189 static Node *makeXmlExpr(XmlExprOp op, char *name, List *named_args,
190 List *args, int location);
191 static List *mergeTableFuncParameters(List *func_args, List *columns, core_yyscan_t yyscanner);
192 static TypeName *TableFuncTypeName(List *columns);
193 static RangeVar *makeRangeVarFromAnyName(List *names, int position, core_yyscan_t yyscanner);
194 static RangeVar *makeRangeVarFromQualifiedName(char *name, List *namelist, int location,
195 core_yyscan_t yyscanner);
196 static void SplitColQualList(List *qualList,
197 List **constraintList, CollateClause **collClause,
198 core_yyscan_t yyscanner);
199 static void processCASbits(int cas_bits, int location, const char *constrType,
200 bool *deferrable, bool *initdeferred, bool *is_enforced,
201 bool *not_valid, bool *no_inherit, core_yyscan_t yyscanner);
202 static PartitionStrategy parsePartitionStrategy(char *strategy, int location,
203 core_yyscan_t yyscanner);
204 static void preprocess_pubobj_list(List *pubobjspec_list,
205 core_yyscan_t yyscanner);
206 static Node *makeRecursiveViewSelect(char *relname, List *aliases, Node *query);
207
208 %}
209
210 %pure-parser
211 %expect 0
212 %name-prefix="base_yy"
213 %locations
214
215 %parse-param {core_yyscan_t yyscanner}
216 %lex-param {core_yyscan_t yyscanner}
217
218 %union
219 {
220 core_YYSTYPE core_yystype;
221 /* these fields must match core_YYSTYPE: */
222 int ival;
223 char *str;
224 const char *keyword;
225
226 char chr;
227 bool boolean;
228 JoinType jtype;
229 DropBehavior dbehavior;
230 OnCommitAction oncommit;
231 List *list;
232 Node *node;
233 ObjectType objtype;
234 TypeName *typnam;
235 FunctionParameter *fun_param;
236 FunctionParameterMode fun_param_mode;
237 ObjectWithArgs *objwithargs;
238 DefElem *defelt;
239 SortBy *sortby;
240 WindowDef *windef;
241 JoinExpr *jexpr;
242 IndexElem *ielem;
243 StatsElem *selem;
244 Alias *alias;
245 RangeVar *range;
246 IntoClause *into;
247 WithClause *with;
248 InferClause *infer;
249 OnConflictClause *onconflict;
250 A_Indices *aind;
251 ResTarget *target;
252 struct PrivTarget *privtarget;
253 AccessPriv *accesspriv;
254 struct ImportQual *importqual;
255 InsertStmt *istmt;
256 VariableSetStmt *vsetstmt;
257 PartitionElem *partelem;
258 PartitionSpec *partspec;
259 PartitionBoundSpec *partboundspec;
260 RoleSpec *rolespec;
261 PublicationObjSpec *publicationobjectspec;
262 struct SelectLimit *selectlimit;
263 SetQuantifier setquantifier;
264 struct GroupClause *groupclause;
265 MergeMatchKind mergematch;
266 MergeWhenClause *mergewhen;
267 struct KeyActions *keyactions;
268 struct KeyAction *keyaction;
269 ReturningClause *retclause;
270 ReturningOptionKind retoptionkind;
271 }
272
273 %type <node> stmt toplevel_stmt schema_stmt routine_body_stmt
274 AlterEventTrigStmt AlterCollationStmt
275 AlterDatabaseStmt AlterDatabaseSetStmt AlterDomainStmt AlterEnumStmt
276 AlterFdwStmt AlterForeignServerStmt AlterGroupStmt
277 AlterObjectDependsStmt AlterObjectSchemaStmt AlterOwnerStmt
278 AlterOperatorStmt AlterTypeStmt AlterSeqStmt AlterSystemStmt AlterTableStmt
279 AlterTblSpcStmt AlterExtensionStmt AlterExtensionContentsStmt
280 AlterCompositeTypeStmt AlterUserMappingStmt
281 AlterRoleStmt AlterRoleSetStmt AlterPolicyStmt AlterStatsStmt
282 AlterDefaultPrivilegesStmt DefACLAction
283 AnalyzeStmt CallStmt ClosePortalStmt ClusterStmt CommentStmt
284 ConstraintsSetStmt CopyStmt CreateAsStmt CreateCastStmt
285 CreateDomainStmt CreateExtensionStmt CreateGroupStmt CreateOpClassStmt
286 CreateOpFamilyStmt AlterOpFamilyStmt CreatePLangStmt
287 CreateSchemaStmt CreateSeqStmt CreateStmt CreateStatsStmt CreateTableSpaceStmt
288 CreateFdwStmt CreateForeignServerStmt CreateForeignTableStmt
289 CreateAssertionStmt CreateTransformStmt CreateTrigStmt CreateEventTrigStmt
290 CreateUserStmt CreateUserMappingStmt CreateRoleStmt CreatePolicyStmt
291 CreatedbStmt DeclareCursorStmt DefineStmt DeleteStmt DiscardStmt DoStmt
292 DropOpClassStmt DropOpFamilyStmt DropStmt
293 DropCastStmt DropRoleStmt
294 DropdbStmt DropTableSpaceStmt
295 DropTransformStmt
296 DropUserMappingStmt ExplainStmt FetchStmt
297 GrantStmt GrantRoleStmt ImportForeignSchemaStmt IndexStmt InsertStmt
298 ListenStmt LoadStmt LockStmt MergeStmt NotifyStmt ExplainableStmt PreparableStmt
299 CreateFunctionStmt AlterFunctionStmt ReindexStmt RemoveAggrStmt
300 RemoveFuncStmt RemoveOperStmt RenameStmt ReturnStmt RevokeStmt RevokeRoleStmt
301 RuleActionStmt RuleActionStmtOrEmpty RuleStmt
302 SecLabelStmt SelectStmt TransactionStmt TransactionStmtLegacy TruncateStmt
303 UnlistenStmt UpdateStmt VacuumStmt
304 VariableResetStmt VariableSetStmt VariableShowStmt
305 ViewStmt CheckPointStmt CreateConversionStmt
306 DeallocateStmt PrepareStmt ExecuteStmt
307 DropOwnedStmt ReassignOwnedStmt
308 AlterTSConfigurationStmt AlterTSDictionaryStmt
309 CreateMatViewStmt RefreshMatViewStmt CreateAmStmt
310 CreatePublicationStmt AlterPublicationStmt
311 CreateSubscriptionStmt AlterSubscriptionStmt DropSubscriptionStmt
312
313 %type <node> select_no_parens select_with_parens select_clause
314 simple_select values_clause
315 PLpgSQL_Expr PLAssignStmt
316
317 %type <str> opt_single_name
318 %type <list> opt_qualified_name
319 %type <boolean> opt_concurrently
320 %type <dbehavior> opt_drop_behavior
321
322 %type <node> alter_column_default opclass_item opclass_drop alter_using
323 %type <ival> add_drop opt_asc_desc opt_nulls_order
324
325 %type <node> alter_table_cmd alter_type_cmd opt_collate_clause
326 replica_identity partition_cmd index_partition_cmd
327 %type <list> alter_table_cmds alter_type_cmds
328 %type <list> alter_identity_column_option_list
329 %type <defelt> alter_identity_column_option
330 %type <node> set_statistics_value
331 %type <str> set_access_method_name
332
333 %type <list> createdb_opt_list createdb_opt_items copy_opt_list
334 transaction_mode_list
335 create_extension_opt_list alter_extension_opt_list
336 %type <defelt> createdb_opt_item copy_opt_item
337 transaction_mode_item
338 create_extension_opt_item alter_extension_opt_item
339
340 %type <ival> opt_lock lock_type cast_context
341 %type <str> utility_option_name
342 %type <defelt> utility_option_elem
343 %type <list> utility_option_list
344 %type <node> utility_option_arg
345 %type <defelt> drop_option
346 %type <boolean> opt_or_replace opt_no
347 opt_grant_grant_option
348 opt_nowait opt_if_exists opt_with_data
349 opt_transaction_chain
350 %type <list> grant_role_opt_list
351 %type <defelt> grant_role_opt
352 %type <node> grant_role_opt_value
353 %type <ival> opt_nowait_or_skip
354
355 %type <list> OptRoleList AlterOptRoleList
356 %type <defelt> CreateOptRoleElem AlterOptRoleElem
357
358 %type <str> opt_type
359 %type <str> foreign_server_version opt_foreign_server_version
360 %type <str> opt_in_database
361
362 %type <str> parameter_name
363 %type <list> OptSchemaEltList parameter_name_list
364
365 %type <chr> am_type
366
367 %type <boolean> TriggerForSpec TriggerForType
368 %type <ival> TriggerActionTime
369 %type <list> TriggerEvents TriggerOneEvent
370 %type <node> TriggerFuncArg
371 %type <node> TriggerWhen
372 %type <str> TransitionRelName
373 %type <boolean> TransitionRowOrTable TransitionOldOrNew
374 %type <node> TriggerTransition
375
376 %type <list> event_trigger_when_list event_trigger_value_list
377 %type <defelt> event_trigger_when_item
378 %type <chr> enable_trigger
379
380 %type <str> copy_file_name
381 access_method_clause attr_name
382 table_access_method_clause name cursor_name file_name
383 cluster_index_specification
384
385 %type <list> func_name handler_name qual_Op qual_all_Op subquery_Op
386 opt_inline_handler opt_validator validator_clause
387 opt_collate
388
389 %type <range> qualified_name insert_target OptConstrFromTable
390
391 %type <str> all_Op MathOp
392
393 %type <str> row_security_cmd RowSecurityDefaultForCmd
394 %type <boolean> RowSecurityDefaultPermissive
395 %type <node> RowSecurityOptionalWithCheck RowSecurityOptionalExpr
396 %type <list> RowSecurityDefaultToRole RowSecurityOptionalToRole
397
398 %type <str> iso_level opt_encoding
399 %type <rolespec> grantee
400 %type <list> grantee_list
401 %type <accesspriv> privilege
402 %type <list> privileges privilege_list
403 %type <privtarget> privilege_target
404 %type <objwithargs> function_with_argtypes aggregate_with_argtypes operator_with_argtypes
405 %type <list> function_with_argtypes_list aggregate_with_argtypes_list operator_with_argtypes_list
406 %type <ival> defacl_privilege_target
407 %type <defelt> DefACLOption
408 %type <list> DefACLOptionList
409 %type <ival> import_qualification_type
410 %type <importqual> import_qualification
411 %type <node> vacuum_relation
412 %type <selectlimit> opt_select_limit select_limit limit_clause
413
414 %type <list> parse_toplevel stmtmulti routine_body_stmt_list
415 OptTableElementList TableElementList OptInherit definition
416 OptTypedTableElementList TypedTableElementList
417 reloptions opt_reloptions
418 OptWith opt_definition func_args func_args_list
419 func_args_with_defaults func_args_with_defaults_list
420 aggr_args aggr_args_list
421 func_as createfunc_opt_list opt_createfunc_opt_list alterfunc_opt_list
422 old_aggr_definition old_aggr_list
423 oper_argtypes RuleActionList RuleActionMulti
424 opt_column_list columnList opt_name_list
425 sort_clause opt_sort_clause sortby_list index_params
426 stats_params
427 opt_include opt_c_include index_including_params
428 name_list role_list from_clause from_list opt_array_bounds
429 qualified_name_list any_name any_name_list type_name_list
430 any_operator expr_list attrs
431 distinct_clause opt_distinct_clause
432 target_list opt_target_list insert_column_list set_target_list
433 merge_values_clause
434 set_clause_list set_clause
435 def_list operator_def_list indirection opt_indirection
436 reloption_list TriggerFuncArgs opclass_item_list opclass_drop_list
437 opclass_purpose opt_opfamily transaction_mode_list_or_empty
438 OptTableFuncElementList TableFuncElementList opt_type_modifiers
439 prep_type_clause
440 execute_param_clause using_clause
441 returning_with_clause returning_options
442 opt_enum_val_list enum_val_list table_func_column_list
443 create_generic_options alter_generic_options
444 relation_expr_list dostmt_opt_list
445 transform_element_list transform_type_list
446 TriggerTransitions TriggerReferencing
447 vacuum_relation_list opt_vacuum_relation_list
448 drop_option_list pub_obj_list
449
450 %type <retclause> returning_clause
451 %type <node> returning_option
452 %type <retoptionkind> returning_option_kind
453 %type <node> opt_routine_body
454 %type <groupclause> group_clause
455 %type <list> group_by_list
456 %type <node> group_by_item empty_grouping_set rollup_clause cube_clause
457 %type <node> grouping_sets_clause
458
459 %type <list> opt_fdw_options fdw_options
460 %type <defelt> fdw_option
461
462 %type <range> OptTempTableName
463 %type <into> into_clause create_as_target create_mv_target
464
465 %type <defelt> createfunc_opt_item common_func_opt_item dostmt_opt_item
466 %type <fun_param> func_arg func_arg_with_default table_func_column aggr_arg
467 %type <fun_param_mode> arg_class
468 %type <typnam> func_return func_type
469
470 %type <boolean> opt_trusted opt_restart_seqs
471 %type <ival> OptTemp
472 %type <ival> OptNoLog
473 %type <oncommit> OnCommitOption
474
475 %type <ival> for_locking_strength
476 %type <node> for_locking_item
477 %type <list> for_locking_clause opt_for_locking_clause for_locking_items
478 %type <list> locked_rels_list
479 %type <setquantifier> set_quantifier
480
481 %type <node> join_qual
482 %type <jtype> join_type
483
484 %type <list> extract_list overlay_list position_list
485 %type <list> substr_list trim_list
486 %type <list> opt_interval interval_second
487 %type <str> unicode_normal_form
488
489 %type <boolean> opt_instead
490 %type <boolean> opt_unique opt_verbose opt_full
491 %type <boolean> opt_freeze opt_analyze opt_default
492 %type <defelt> opt_binary copy_delimiter
493
494 %type <boolean> copy_from opt_program
495
496 %type <ival> event cursor_options opt_hold opt_set_data
497 %type <objtype> object_type_any_name object_type_name object_type_name_on_any_name
498 drop_type_name
499
500 %type <node> fetch_args select_limit_value
501 offset_clause select_offset_value
502 select_fetch_first_value I_or_F_const
503 %type <ival> row_or_rows first_or_next
504
505 %type <list> OptSeqOptList SeqOptList OptParenthesizedSeqOptList
506 %type <defelt> SeqOptElem
507
508 %type <istmt> insert_rest
509 %type <infer> opt_conf_expr
510 %type <onconflict> opt_on_conflict
511 %type <mergewhen> merge_insert merge_update merge_delete
512
513 %type <mergematch> merge_when_tgt_matched merge_when_tgt_not_matched
514 %type <node> merge_when_clause opt_merge_when_condition
515 %type <list> merge_when_list
516
517 %type <vsetstmt> generic_set set_rest set_rest_more generic_reset reset_rest
518 SetResetClause FunctionSetResetClause
519
520 %type <node> TableElement TypedTableElement ConstraintElem DomainConstraintElem TableFuncElement
521 %type <node> columnDef columnOptions optionalPeriodName
522 %type <defelt> def_elem reloption_elem old_aggr_elem operator_def_elem
523 %type <node> def_arg columnElem where_clause where_or_current_clause
524 a_expr b_expr c_expr AexprConst indirection_el opt_slice_bound
525 columnref having_clause func_table xmltable array_expr
526 OptWhereClause operator_def_arg
527 %type <list> opt_column_and_period_list
528 %type <list> rowsfrom_item rowsfrom_list opt_col_def_list
529 %type <boolean> opt_ordinality opt_without_overlaps
530 %type <list> ExclusionConstraintList ExclusionConstraintElem
531 %type <list> func_arg_list func_arg_list_opt
532 %type <node> func_arg_expr
533 %type <list> row explicit_row implicit_row type_list array_expr_list
534 %type <node> case_expr case_arg when_clause case_default
535 %type <list> when_clause_list
536 %type <node> opt_search_clause opt_cycle_clause
537 %type <ival> sub_type opt_materialized
538 %type <node> NumericOnly
539 %type <list> NumericOnly_list
540 %type <alias> alias_clause opt_alias_clause opt_alias_clause_for_join_using
541 %type <list> func_alias_clause
542 %type <sortby> sortby
543 %type <ielem> index_elem index_elem_options
544 %type <selem> stats_param
545 %type <node> table_ref
546 %type <jexpr> joined_table
547 %type <range> relation_expr
548 %type <range> extended_relation_expr
549 %type <range> relation_expr_opt_alias
550 %type <node> tablesample_clause opt_repeatable_clause
551 %type <target> target_el set_target insert_column_item
552
553 %type <str> generic_option_name
554 %type <node> generic_option_arg
555 %type <defelt> generic_option_elem alter_generic_option_elem
556 %type <list> generic_option_list alter_generic_option_list
557
558 %type <ival> reindex_target_relation reindex_target_all
559 %type <list> opt_reindex_option_list
560
561 %type <node> copy_generic_opt_arg copy_generic_opt_arg_list_item
562 %type <defelt> copy_generic_opt_elem
563 %type <list> copy_generic_opt_list copy_generic_opt_arg_list
564 %type <list> copy_options
565
566 %type <typnam> Typename SimpleTypename ConstTypename
567 GenericType Numeric opt_float JsonType
568 Character ConstCharacter
569 CharacterWithLength CharacterWithoutLength
570 ConstDatetime ConstInterval
571 Bit ConstBit BitWithLength BitWithoutLength
572 %type <str> character
573 %type <str> extract_arg
574 %type <boolean> opt_varying opt_timezone opt_no_inherit
575
576 %type <ival> Iconst SignedIconst
577 %type <str> Sconst comment_text notify_payload
578 %type <str> RoleId opt_boolean_or_string
579 %type <list> var_list
580 %type <str> ColId ColLabel BareColLabel
581 %type <str> NonReservedWord NonReservedWord_or_Sconst
582 %type <str> var_name type_function_name param_name
583 %type <str> createdb_opt_name plassign_target
584 %type <node> var_value zone_value
585 %type <rolespec> auth_ident RoleSpec opt_granted_by
586 %type <publicationobjectspec> PublicationObjSpec
587
588 %type <keyword> unreserved_keyword type_func_name_keyword
589 %type <keyword> col_name_keyword reserved_keyword
590 %type <keyword> bare_label_keyword
591
592 %type <node> DomainConstraint TableConstraint TableLikeClause
593 %type <ival> TableLikeOptionList TableLikeOption
594 %type <str> column_compression opt_column_compression column_storage opt_column_storage
595 %type <list> ColQualList
596 %type <node> ColConstraint ColConstraintElem ConstraintAttr
597 %type <ival> key_match
598 %type <keyaction> key_delete key_update key_action
599 %type <keyactions> key_actions
600 %type <ival> ConstraintAttributeSpec ConstraintAttributeElem
601 %type <str> ExistingIndex
602
603 %type <list> constraints_set_list
604 %type <boolean> constraints_set_mode
605 %type <str> OptTableSpace OptConsTableSpace
606 %type <rolespec> OptTableSpaceOwner
607 %type <ival> opt_check_option
608
609 %type <str> opt_provider security_label
610
611 %type <target> xml_attribute_el
612 %type <list> xml_attribute_list xml_attributes
613 %type <node> xml_root_version opt_xml_root_standalone
614 %type <node> xmlexists_argument
615 %type <ival> document_or_content
616 %type <boolean> xml_indent_option xml_whitespace_option
617 %type <list> xmltable_column_list xmltable_column_option_list
618 %type <node> xmltable_column_el
619 %type <defelt> xmltable_column_option_el
620 %type <list> xml_namespace_list
621 %type <target> xml_namespace_el
622
623 %type <node> func_application func_expr_common_subexpr
624 %type <node> func_expr func_expr_windowless
625 %type <node> common_table_expr
626 %type <with> with_clause opt_with_clause
627 %type <list> cte_list
628
629 %type <list> within_group_clause
630 %type <node> filter_clause
631 %type <list> window_clause window_definition_list opt_partition_clause
632 %type <windef> window_definition over_clause window_specification
633 opt_frame_clause frame_extent frame_bound
634 %type <ival> opt_window_exclusion_clause
635 %type <str> opt_existing_window_name
636 %type <boolean> opt_if_not_exists
637 %type <boolean> opt_unique_null_treatment
638 %type <ival> generated_when override_kind opt_virtual_or_stored
639 %type <partspec> PartitionSpec OptPartitionSpec
640 %type <partelem> part_elem
641 %type <list> part_params
642 %type <partboundspec> PartitionBoundSpec
643 %type <list> hash_partbound
644 %type <defelt> hash_partbound_elem
645
646 %type <node> json_format_clause
647 json_format_clause_opt
648 json_value_expr
649 json_returning_clause_opt
650 json_name_and_value
651 json_aggregate_func
652 json_argument
653 json_behavior
654 json_on_error_clause_opt
655 json_table
656 json_table_column_definition
657 json_table_column_path_clause_opt
658 %type <list> json_name_and_value_list
659 json_value_expr_list
660 json_array_aggregate_order_by_clause_opt
661 json_arguments
662 json_behavior_clause_opt
663 json_passing_clause_opt
664 json_table_column_definition_list
665 %type <str> json_table_path_name_opt
666 %type <ival> json_behavior_type
667 json_predicate_type_constraint
668 json_quotes_clause_opt
669 json_wrapper_behavior
670 %type <boolean> json_key_uniqueness_constraint_opt
671 json_object_constructor_null_clause_opt
672 json_array_constructor_null_clause_opt
673
674
675 /*
676 * Non-keyword token types. These are hard-wired into the "flex" lexer.
677 * They must be listed first so that their numeric codes do not depend on
678 * the set of keywords. PL/pgSQL depends on this so that it can share the
679 * same lexer. If you add/change tokens here, fix PL/pgSQL to match!
680 *
681 * UIDENT and USCONST are reduced to IDENT and SCONST in parser.c, so that
682 * they need no productions here; but we must assign token codes to them.
683 *
684 * DOT_DOT is unused in the core SQL grammar, and so will always provoke
685 * parse errors. It is needed by PL/pgSQL.
686 */
687 %token <str> IDENT UIDENT FCONST SCONST USCONST BCONST XCONST Op
688 %token <ival> ICONST PARAM
689 %token TYPECAST DOT_DOT COLON_EQUALS EQUALS_GREATER
690 %token LESS_EQUALS GREATER_EQUALS NOT_EQUALS
691
692 /*
693 * If you want to make any keyword changes, update the keyword table in
694 * src/include/parser/kwlist.h and add new keywords to the appropriate one
695 * of the reserved-or-not-so-reserved keyword lists, below; search
696 * this file for "Keyword category lists".
697 */
698
699 /* ordinary key words in alphabetical order */
700 %token <keyword> ABORT_P ABSENT ABSOLUTE_P ACCESS ACTION ADD_P ADMIN AFTER
701 AGGREGATE ALL ALSO ALTER ALWAYS ANALYSE ANALYZE AND ANY ARRAY AS ASC
702 ASENSITIVE ASSERTION ASSIGNMENT ASYMMETRIC ATOMIC AT ATTACH ATTRIBUTE AUTHORIZATION
703
704 BACKWARD BEFORE BEGIN_P BETWEEN BIGINT BINARY BIT
705 BOOLEAN_P BOTH BREADTH BY
706
707 CACHE CALL CALLED CASCADE CASCADED CASE CAST CATALOG_P CHAIN CHAR_P
708 CHARACTER CHARACTERISTICS CHECK CHECKPOINT CLASS CLOSE
709 CLUSTER COALESCE COLLATE COLLATION COLUMN COLUMNS COMMENT COMMENTS COMMIT
710 COMMITTED COMPRESSION CONCURRENTLY CONDITIONAL CONFIGURATION CONFLICT
711 CONNECTION CONSTRAINT CONSTRAINTS CONTENT_P CONTINUE_P CONVERSION_P COPY
712 COST CREATE CROSS CSV CUBE CURRENT_P
713 CURRENT_CATALOG CURRENT_DATE CURRENT_ROLE CURRENT_SCHEMA
714 CURRENT_TIME CURRENT_TIMESTAMP CURRENT_USER CURSOR CYCLE
715
716 DATA_P DATABASE DAY_P DEALLOCATE DEC DECIMAL_P DECLARE DEFAULT DEFAULTS
717 DEFERRABLE DEFERRED DEFINER DELETE_P DELIMITER DELIMITERS DEPENDS DEPTH DESC
718 DETACH DICTIONARY DISABLE_P DISCARD DISTINCT DO DOCUMENT_P DOMAIN_P
719 DOUBLE_P DROP
720
721 EACH ELSE EMPTY_P ENABLE_P ENCODING ENCRYPTED END_P ENFORCED ENUM_P ERROR_P
722 ESCAPE EVENT EXCEPT EXCLUDE EXCLUDING EXCLUSIVE EXECUTE EXISTS EXPLAIN
723 EXPRESSION EXTENSION EXTERNAL EXTRACT
724
725 FALSE_P FAMILY FETCH FILTER FINALIZE FIRST_P FLOAT_P FOLLOWING FOR
726 FORCE FOREIGN FORMAT FORWARD FREEZE FROM FULL FUNCTION FUNCTIONS
727
728 GENERATED GLOBAL GRANT GRANTED GREATEST GROUP_P GROUPING GROUPS
729
730 HANDLER HAVING HEADER_P HOLD HOUR_P
731
732 IDENTITY_P IF_P ILIKE IMMEDIATE IMMUTABLE IMPLICIT_P IMPORT_P IN_P INCLUDE
733 INCLUDING INCREMENT INDENT INDEX INDEXES INHERIT INHERITS INITIALLY INLINE_P
734 INNER_P INOUT INPUT_P INSENSITIVE INSERT INSTEAD INT_P INTEGER
735 INTERSECT INTERVAL INTO INVOKER IS ISNULL ISOLATION
736
737 JOIN JSON JSON_ARRAY JSON_ARRAYAGG JSON_EXISTS JSON_OBJECT JSON_OBJECTAGG
738 JSON_QUERY JSON_SCALAR JSON_SERIALIZE JSON_TABLE JSON_VALUE
739
740 KEEP KEY KEYS
741
742 LABEL LANGUAGE LARGE_P LAST_P LATERAL_P
743 LEADING LEAKPROOF LEAST LEFT LEVEL LIKE LIMIT LISTEN LOAD LOCAL
744 LOCALTIME LOCALTIMESTAMP LOCATION LOCK_P LOCKED LOGGED
745
746 MAPPING MATCH MATCHED MATERIALIZED MAXVALUE MERGE MERGE_ACTION METHOD
747 MINUTE_P MINVALUE MODE MONTH_P MOVE
748
749 NAME_P NAMES NATIONAL NATURAL NCHAR NESTED NEW NEXT NFC NFD NFKC NFKD NO
750 NONE NORMALIZE NORMALIZED
751 NOT NOTHING NOTIFY NOTNULL NOWAIT NULL_P NULLIF
752 NULLS_P NUMERIC
753
754 OBJECT_P OBJECTS_P OF OFF OFFSET OIDS OLD OMIT ON ONLY OPERATOR OPTION OPTIONS OR
755 ORDER ORDINALITY OTHERS OUT_P OUTER_P
756 OVER OVERLAPS OVERLAY OVERRIDING OWNED OWNER
757
758 PARALLEL PARAMETER PARSER PARTIAL PARTITION PASSING PASSWORD PATH
759 PERIOD PLACING PLAN PLANS POLICY
760 POSITION PRECEDING PRECISION PRESERVE PREPARE PREPARED PRIMARY
761 PRIOR PRIVILEGES PROCEDURAL PROCEDURE PROCEDURES PROGRAM PUBLICATION
762
763 QUOTE QUOTES
764
765 RANGE READ REAL REASSIGN RECURSIVE REF_P REFERENCES REFERENCING
766 REFRESH REINDEX RELATIVE_P RELEASE RENAME REPEATABLE REPLACE REPLICA
767 RESET RESTART RESTRICT RETURN RETURNING RETURNS REVOKE RIGHT ROLE ROLLBACK ROLLUP
768 ROUTINE ROUTINES ROW ROWS RULE
769
770 SAVEPOINT SCALAR SCHEMA SCHEMAS SCROLL SEARCH SECOND_P SECURITY SELECT
771 SEQUENCE SEQUENCES
772 SERIALIZABLE SERVER SESSION SESSION_USER SET SETS SETOF SHARE SHOW
773 SIMILAR SIMPLE SKIP SMALLINT SNAPSHOT SOME SOURCE SQL_P STABLE STANDALONE_P
774 START STATEMENT STATISTICS STDIN STDOUT STORAGE STORED STRICT_P STRING_P STRIP_P
775 SUBSCRIPTION SUBSTRING SUPPORT SYMMETRIC SYSID SYSTEM_P SYSTEM_USER
776
777 TABLE TABLES TABLESAMPLE TABLESPACE TARGET TEMP TEMPLATE TEMPORARY TEXT_P THEN
778 TIES TIME TIMESTAMP TO TRAILING TRANSACTION TRANSFORM
779 TREAT TRIGGER TRIM TRUE_P
780 TRUNCATE TRUSTED TYPE_P TYPES_P
781
782 UESCAPE UNBOUNDED UNCONDITIONAL UNCOMMITTED UNENCRYPTED UNION UNIQUE UNKNOWN
783 UNLISTEN UNLOGGED UNTIL UPDATE USER USING
784
785 VACUUM VALID VALIDATE VALIDATOR VALUE_P VALUES VARCHAR VARIADIC VARYING
786 VERBOSE VERSION_P VIEW VIEWS VIRTUAL VOLATILE
787
788 WHEN WHERE WHITESPACE_P WINDOW WITH WITHIN WITHOUT WORK WRAPPER WRITE
789
790 XML_P XMLATTRIBUTES XMLCONCAT XMLELEMENT XMLEXISTS XMLFOREST XMLNAMESPACES
791 XMLPARSE XMLPI XMLROOT XMLSERIALIZE XMLTABLE
792
793 YEAR_P YES_P
794
795 ZONE
796
797 /*
798 * The grammar thinks these are keywords, but they are not in the kwlist.h
799 * list and so can never be entered directly. The filter in parser.c
800 * creates these tokens when required (based on looking one token ahead).
801 *
802 * NOT_LA exists so that productions such as NOT LIKE can be given the same
803 * precedence as LIKE; otherwise they'd effectively have the same precedence
804 * as NOT, at least with respect to their left-hand subexpression.
805 * FORMAT_LA, NULLS_LA, WITH_LA, and WITHOUT_LA are needed to make the grammar
806 * LALR(1).
807 */
808 %token FORMAT_LA NOT_LA NULLS_LA WITH_LA WITHOUT_LA
809
810 /*
811 * The grammar likewise thinks these tokens are keywords, but they are never
812 * generated by the scanner. Rather, they can be injected by parser.c as
813 * the initial token of the string (using the lookahead-token mechanism
814 * implemented there). This provides a way to tell the grammar to parse
815 * something other than the usual list of SQL commands.
816 */
817 %token MODE_TYPE_NAME
818 %token MODE_PLPGSQL_EXPR
819 %token MODE_PLPGSQL_ASSIGN1
820 %token MODE_PLPGSQL_ASSIGN2
821 %token MODE_PLPGSQL_ASSIGN3
822
823
824 /* Precedence: lowest to highest */
825 %left UNION EXCEPT
826 %left INTERSECT
827 %left OR
828 %left AND
829 %right NOT
830 %nonassoc IS ISNULL NOTNULL /* IS sets precedence for IS NULL, etc */
831 %nonassoc '<' '>' '=' LESS_EQUALS GREATER_EQUALS NOT_EQUALS
832 %nonassoc BETWEEN IN_P LIKE ILIKE SIMILAR NOT_LA
833 %nonassoc ESCAPE /* ESCAPE must be just above LIKE/ILIKE/SIMILAR */
834
835 /*
836 * Sometimes it is necessary to assign precedence to keywords that are not
837 * really part of the operator hierarchy, in order to resolve grammar
838 * ambiguities. It's best to avoid doing so whenever possible, because such
839 * assignments have global effect and may hide ambiguities besides the one
840 * you intended to solve. (Attaching a precedence to a single rule with
841 * %prec is far safer and should be preferred.) If you must give precedence
842 * to a new keyword, try very hard to give it the same precedence as IDENT.
843 * If the keyword has IDENT's precedence then it clearly acts the same as
844 * non-keywords and other similar keywords, thus reducing the risk of
845 * unexpected precedence effects.
846 *
847 * We used to need to assign IDENT an explicit precedence just less than Op,
848 * to support target_el without AS. While that's not really necessary since
849 * we removed postfix operators, we continue to do so because it provides a
850 * reference point for a precedence level that we can assign to other
851 * keywords that lack a natural precedence level.
852 *
853 * We need to do this for PARTITION, RANGE, ROWS, and GROUPS to support
854 * opt_existing_window_name (see comment there).
855 *
856 * The frame_bound productions UNBOUNDED PRECEDING and UNBOUNDED FOLLOWING
857 * are even messier: since UNBOUNDED is an unreserved keyword (per spec!),
858 * there is no principled way to distinguish these from the productions
859 * a_expr PRECEDING/FOLLOWING. We hack this up by giving UNBOUNDED slightly
860 * lower precedence than PRECEDING and FOLLOWING. At present this doesn't
861 * appear to cause UNBOUNDED to be treated differently from other unreserved
862 * keywords anywhere else in the grammar, but it's definitely risky. We can
863 * blame any funny behavior of UNBOUNDED on the SQL standard, though.
864 *
865 * To support CUBE and ROLLUP in GROUP BY without reserving them, we give them
866 * an explicit priority lower than '(', so that a rule with CUBE '(' will shift
867 * rather than reducing a conflicting rule that takes CUBE as a function name.
868 * Using the same precedence as IDENT seems right for the reasons given above.
869 *
870 * SET is likewise assigned the same precedence as IDENT, to support the
871 * relation_expr_opt_alias production (see comment there).
872 *
873 * KEYS, OBJECT_P, SCALAR, VALUE_P, WITH, and WITHOUT are similarly assigned
874 * the same precedence as IDENT. This allows resolving conflicts in the
875 * json_predicate_type_constraint and json_key_uniqueness_constraint_opt
876 * productions (see comments there).
877 *
878 * Like the UNBOUNDED PRECEDING/FOLLOWING case, NESTED is assigned a lower
879 * precedence than PATH to fix ambiguity in the json_table production.
880 */
881 %nonassoc UNBOUNDED NESTED /* ideally would have same precedence as IDENT */
882 %nonassoc IDENT PARTITION RANGE ROWS GROUPS PRECEDING FOLLOWING CUBE ROLLUP
883 SET KEYS OBJECT_P SCALAR VALUE_P WITH WITHOUT PATH
884 %left Op OPERATOR /* multi-character ops and user-defined operators */
885 %left '+' '-'
886 %left '*' '/' '%'
887 %left '^'
888 /* Unary Operators */
889 %left AT /* sets precedence for AT TIME ZONE, AT LOCAL */
890 %left COLLATE
891 %right UMINUS
892 %left '[' ']'
893 %left '(' ')'
894 %left TYPECAST
895 %left '.'
896 /*
897 * These might seem to be low-precedence, but actually they are not part
898 * of the arithmetic hierarchy at all in their use as JOIN operators.
899 * We make them high-precedence to support their use as function names.
900 * They wouldn't be given a precedence at all, were it not that we need
901 * left-associativity among the JOIN rules themselves.
902 */
903 %left JOIN CROSS LEFT FULL RIGHT INNER_P NATURAL
904
905 %%
906
907 /*
908 * The target production for the whole parse.
909 *
910 * Ordinarily we parse a list of statements, but if we see one of the
911 * special MODE_XXX symbols as first token, we parse something else.
912 * The options here correspond to enum RawParseMode, which see for details.
913 */
914 parse_toplevel:
915 stmtmulti
916 {
917 pg_yyget_extra(yyscanner)->parsetree = $1;
918 (void) yynerrs; /* suppress compiler warning */
919 }
920 | MODE_TYPE_NAME Typename
921 {
922 pg_yyget_extra(yyscanner)->parsetree = list_make1($2);
923 }
924 | MODE_PLPGSQL_EXPR PLpgSQL_Expr
925 {
926 pg_yyget_extra(yyscanner)->parsetree =
927 list_make1(makeRawStmt($2, @2));
928 }
929 | MODE_PLPGSQL_ASSIGN1 PLAssignStmt
930 {
931 PLAssignStmt *n = (PLAssignStmt *) $2;
932
933 n->nnames = 1;
934 pg_yyget_extra(yyscanner)->parsetree =
935 list_make1(makeRawStmt((Node *) n, @2));
936 }
937 | MODE_PLPGSQL_ASSIGN2 PLAssignStmt
938 {
939 PLAssignStmt *n = (PLAssignStmt *) $2;
940
941 n->nnames = 2;
942 pg_yyget_extra(yyscanner)->parsetree =
943 list_make1(makeRawStmt((Node *) n, @2));
944 }
945 | MODE_PLPGSQL_ASSIGN3 PLAssignStmt
946 {
947 PLAssignStmt *n = (PLAssignStmt *) $2;
948
949 n->nnames = 3;
950 pg_yyget_extra(yyscanner)->parsetree =
951 list_make1(makeRawStmt((Node *) n, @2));
952 }
953 ;
954
955 /*
956 * At top level, we wrap each stmt with a RawStmt node carrying start location
957 * and length of the stmt's text.
958 * We also take care to discard empty statements entirely (which among other
959 * things dodges the problem of assigning them a location).
960 */
961 stmtmulti: stmtmulti ';' toplevel_stmt
962 {
963 if ($1 != NIL)
964 {
965 /* update length of previous stmt */
966 updateRawStmtEnd(llast_node(RawStmt, $1), @2);
967 }
968 if ($3 != NULL)
969 $$ = lappend($1, makeRawStmt($3, @3));
970 else
971 $$ = $1;
972 }
973 | toplevel_stmt
974 {
975 if ($1 != NULL)
976 $$ = list_make1(makeRawStmt($1, @1));
977 else
978 $$ = NIL;
979 }
980 ;
981
982 /*
983 * toplevel_stmt includes BEGIN and END. stmt does not include them, because
984 * those words have different meanings in function bodies.
985 */
986 toplevel_stmt:
987 stmt
988 | TransactionStmtLegacy
989 ;
990
991 stmt:
992 AlterEventTrigStmt
993 | AlterCollationStmt
994 | AlterDatabaseStmt
995 | AlterDatabaseSetStmt
996 | AlterDefaultPrivilegesStmt
997 | AlterDomainStmt
998 | AlterEnumStmt
999 | AlterExtensionStmt
1000 | AlterExtensionContentsStmt
1001 | AlterFdwStmt
1002 | AlterForeignServerStmt
1003 | AlterFunctionStmt
1004 | AlterGroupStmt
1005 | AlterObjectDependsStmt
1006 | AlterObjectSchemaStmt
1007 | AlterOwnerStmt
1008 | AlterOperatorStmt
1009 | AlterTypeStmt
1010 | AlterPolicyStmt
1011 | AlterSeqStmt
1012 | AlterSystemStmt
1013 | AlterTableStmt
1014 | AlterTblSpcStmt
1015 | AlterCompositeTypeStmt
1016 | AlterPublicationStmt
1017 | AlterRoleSetStmt
1018 | AlterRoleStmt
1019 | AlterSubscriptionStmt
1020 | AlterStatsStmt
1021 | AlterTSConfigurationStmt
1022 | AlterTSDictionaryStmt
1023 | AlterUserMappingStmt
1024 | AnalyzeStmt
1025 | CallStmt
1026 | CheckPointStmt
1027 | ClosePortalStmt
1028 | ClusterStmt
1029 | CommentStmt
1030 | ConstraintsSetStmt
1031 | CopyStmt
1032 | CreateAmStmt
1033 | CreateAsStmt
1034 | CreateAssertionStmt
1035 | CreateCastStmt
1036 | CreateConversionStmt
1037 | CreateDomainStmt
1038 | CreateExtensionStmt
1039 | CreateFdwStmt
1040 | CreateForeignServerStmt
1041 | CreateForeignTableStmt
1042 | CreateFunctionStmt
1043 | CreateGroupStmt
1044 | CreateMatViewStmt
1045 | CreateOpClassStmt
1046 | CreateOpFamilyStmt
1047 | CreatePublicationStmt
1048 | AlterOpFamilyStmt
1049 | CreatePolicyStmt
1050 | CreatePLangStmt
1051 | CreateSchemaStmt
1052 | CreateSeqStmt
1053 | CreateStmt
1054 | CreateSubscriptionStmt
1055 | CreateStatsStmt
1056 | CreateTableSpaceStmt
1057 | CreateTransformStmt
1058 | CreateTrigStmt
1059 | CreateEventTrigStmt
1060 | CreateRoleStmt
1061 | CreateUserStmt
1062 | CreateUserMappingStmt
1063 | CreatedbStmt
1064 | DeallocateStmt
1065 | DeclareCursorStmt
1066 | DefineStmt
1067 | DeleteStmt
1068 | DiscardStmt
1069 | DoStmt
1070 | DropCastStmt
1071 | DropOpClassStmt
1072 | DropOpFamilyStmt
1073 | DropOwnedStmt
1074 | DropStmt
1075 | DropSubscriptionStmt
1076 | DropTableSpaceStmt
1077 | DropTransformStmt
1078 | DropRoleStmt
1079 | DropUserMappingStmt
1080 | DropdbStmt
1081 | ExecuteStmt
1082 | ExplainStmt
1083 | FetchStmt
1084 | GrantStmt
1085 | GrantRoleStmt
1086 | ImportForeignSchemaStmt
1087 | IndexStmt
1088 | InsertStmt
1089 | ListenStmt
1090 | RefreshMatViewStmt
1091 | LoadStmt
1092 | LockStmt
1093 | MergeStmt
1094 | NotifyStmt
1095 | PrepareStmt
1096 | ReassignOwnedStmt
1097 | ReindexStmt
1098 | RemoveAggrStmt
1099 | RemoveFuncStmt
1100 | RemoveOperStmt
1101 | RenameStmt
1102 | RevokeStmt
1103 | RevokeRoleStmt
1104 | RuleStmt
1105 | SecLabelStmt
1106 | SelectStmt
1107 | TransactionStmt
1108 | TruncateStmt
1109 | UnlistenStmt
1110 | UpdateStmt
1111 | VacuumStmt
1112 | VariableResetStmt
1113 | VariableSetStmt
1114 | VariableShowStmt
1115 | ViewStmt
1116 | /*EMPTY*/
1117 { $$ = NULL; }
1118 ;
1119
1120 /*
1121 * Generic supporting productions for DDL
1122 */
1123 opt_single_name:
1124 ColId { $$ = $1; }
1125 | /* EMPTY */ { $$ = NULL; }
1126 ;
1127
1128 opt_qualified_name:
1129 any_name { $$ = $1; }
1130 | /*EMPTY*/ { $$ = NIL; }
1131 ;
1132
1133 opt_concurrently:
1134 CONCURRENTLY { $$ = true; }
1135 | /*EMPTY*/ { $$ = false; }
1136 ;
1137
1138 opt_drop_behavior:
1139 CASCADE { $$ = DROP_CASCADE; }
1140 | RESTRICT { $$ = DROP_RESTRICT; }
1141 | /* EMPTY */ { $$ = DROP_RESTRICT; /* default */ }
1142 ;
1143
1144 /*****************************************************************************
1145 *
1146 * CALL statement
1147 *
1148 *****************************************************************************/
1149
1150 CallStmt: CALL func_application
1151 {
1152 CallStmt *n = makeNode(CallStmt);
1153
1154 n->funccall = castNode(FuncCall, $2);
1155 $$ = (Node *) n;
1156 }
1157 ;
1158
1159 /*****************************************************************************
1160 *
1161 * Create a new Postgres DBMS role
1162 *
1163 *****************************************************************************/
1164
1165 CreateRoleStmt:
1166 CREATE ROLE RoleId opt_with OptRoleList
1167 {
1168 CreateRoleStmt *n = makeNode(CreateRoleStmt);
1169
1170 n->stmt_type = ROLESTMT_ROLE;
1171 n->role = $3;
1172 n->options = $5;
1173 $$ = (Node *) n;
1174 }
1175 ;
1176
1177
1178 opt_with: WITH
1179 | WITH_LA
1180 | /*EMPTY*/
1181 ;
1182
1183 /*
1184 * Options for CREATE ROLE and ALTER ROLE (also used by CREATE/ALTER USER
1185 * for backwards compatibility). Note: the only option required by SQL99
1186 * is "WITH ADMIN name".
1187 */
1188 OptRoleList:
1189 OptRoleList CreateOptRoleElem { $$ = lappend($1, $2); }
1190 | /* EMPTY */ { $$ = NIL; }
1191 ;
1192
1193 AlterOptRoleList:
1194 AlterOptRoleList AlterOptRoleElem { $$ = lappend($1, $2); }
1195 | /* EMPTY */ { $$ = NIL; }
1196 ;
1197
1198 AlterOptRoleElem:
1199 PASSWORD Sconst
1200 {
1201 $$ = makeDefElem("password",
1202 (Node *) makeString($2), @1);
1203 }
1204 | PASSWORD NULL_P
1205 {
1206 $$ = makeDefElem("password", NULL, @1);
1207 }
1208 | ENCRYPTED PASSWORD Sconst
1209 {
1210 /*
1211 * These days, passwords are always stored in encrypted
1212 * form, so there is no difference between PASSWORD and
1213 * ENCRYPTED PASSWORD.
1214 */
1215 $$ = makeDefElem("password",
1216 (Node *) makeString($3), @1);
1217 }
1218 | UNENCRYPTED PASSWORD Sconst
1219 {
1220 ereport(ERROR,
1221 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
1222 errmsg("UNENCRYPTED PASSWORD is no longer supported"),
1223 errhint("Remove UNENCRYPTED to store the password in encrypted form instead."),
1224 parser_errposition(@1)));
1225 }
1226 | INHERIT
1227 {
1228 $$ = makeDefElem("inherit", (Node *) makeBoolean(true), @1);
1229 }
1230 | CONNECTION LIMIT SignedIconst
1231 {
1232 $$ = makeDefElem("connectionlimit", (Node *) makeInteger($3), @1);
1233 }
1234 | VALID UNTIL Sconst
1235 {
1236 $$ = makeDefElem("validUntil", (Node *) makeString($3), @1);
1237 }
1238 /* Supported but not documented for roles, for use by ALTER GROUP. */
1239 | USER role_list
1240 {
1241 $$ = makeDefElem("rolemembers", (Node *) $2, @1);
1242 }
1243 | IDENT
1244 {
1245 /*
1246 * We handle identifiers that aren't parser keywords with
1247 * the following special-case codes, to avoid bloating the
1248 * size of the main parser.
1249 */
1250 if (strcmp($1, "superuser") == 0)
1251 $$ = makeDefElem("superuser", (Node *) makeBoolean(true), @1);
1252 else if (strcmp($1, "nosuperuser") == 0)
1253 $$ = makeDefElem("superuser", (Node *) makeBoolean(false), @1);
1254 else if (strcmp($1, "createrole") == 0)
1255 $$ = makeDefElem("createrole", (Node *) makeBoolean(true), @1);
1256 else if (strcmp($1, "nocreaterole") == 0)
1257 $$ = makeDefElem("createrole", (Node *) makeBoolean(false), @1);
1258 else if (strcmp($1, "replication") == 0)
1259 $$ = makeDefElem("isreplication", (Node *) makeBoolean(true), @1);
1260 else if (strcmp($1, "noreplication") == 0)
1261 $$ = makeDefElem("isreplication", (Node *) makeBoolean(false), @1);
1262 else if (strcmp($1, "createdb") == 0)
1263 $$ = makeDefElem("createdb", (Node *) makeBoolean(true), @1);
1264 else if (strcmp($1, "nocreatedb") == 0)
1265 $$ = makeDefElem("createdb", (Node *) makeBoolean(false), @1);
1266 else if (strcmp($1, "login") == 0)
1267 $$ = makeDefElem("canlogin", (Node *) makeBoolean(true), @1);
1268 else if (strcmp($1, "nologin") == 0)
1269 $$ = makeDefElem("canlogin", (Node *) makeBoolean(false), @1);
1270 else if (strcmp($1, "bypassrls") == 0)
1271 $$ = makeDefElem("bypassrls", (Node *) makeBoolean(true), @1);
1272 else if (strcmp($1, "nobypassrls") == 0)
1273 $$ = makeDefElem("bypassrls", (Node *) makeBoolean(false), @1);
1274 else if (strcmp($1, "noinherit") == 0)
1275 {
1276 /*
1277 * Note that INHERIT is a keyword, so it's handled by main parser, but
1278 * NOINHERIT is handled here.
1279 */
1280 $$ = makeDefElem("inherit", (Node *) makeBoolean(false), @1);
1281 }
1282 else
1283 ereport(ERROR,
1284 (errcode(ERRCODE_SYNTAX_ERROR),
1285 errmsg("unrecognized role option \"%s\"", $1),
1286 parser_errposition(@1)));
1287 }
1288 ;
1289
1290 CreateOptRoleElem:
1291 AlterOptRoleElem { $$ = $1; }
1292 /* The following are not supported by ALTER ROLE/USER/GROUP */
1293 | SYSID Iconst
1294 {
1295 $$ = makeDefElem("sysid", (Node *) makeInteger($2), @1);
1296 }
1297 | ADMIN role_list
1298 {
1299 $$ = makeDefElem("adminmembers", (Node *) $2, @1);
1300 }
1301 | ROLE role_list
1302 {
1303 $$ = makeDefElem("rolemembers", (Node *) $2, @1);
1304 }
1305 | IN_P ROLE role_list
1306 {
1307 $$ = makeDefElem("addroleto", (Node *) $3, @1);
1308 }
1309 | IN_P GROUP_P role_list
1310 {
1311 $$ = makeDefElem("addroleto", (Node *) $3, @1);
1312 }
1313 ;
1314
1315
1316 /*****************************************************************************
1317 *
1318 * Create a new Postgres DBMS user (role with implied login ability)
1319 *
1320 *****************************************************************************/
1321
1322 CreateUserStmt:
1323 CREATE USER RoleId opt_with OptRoleList
1324 {
1325 CreateRoleStmt *n = makeNode(CreateRoleStmt);
1326
1327 n->stmt_type = ROLESTMT_USER;
1328 n->role = $3;
1329 n->options = $5;
1330 $$ = (Node *) n;
1331 }
1332 ;
1333
1334
1335 /*****************************************************************************
1336 *
1337 * Alter a postgresql DBMS role
1338 *
1339 *****************************************************************************/
1340
1341 AlterRoleStmt:
1342 ALTER ROLE RoleSpec opt_with AlterOptRoleList
1343 {
1344 AlterRoleStmt *n = makeNode(AlterRoleStmt);
1345
1346 n->role = $3;
1347 n->action = +1; /* add, if there are members */
1348 n->options = $5;
1349 $$ = (Node *) n;
1350 }
1351 | ALTER USER RoleSpec opt_with AlterOptRoleList
1352 {
1353 AlterRoleStmt *n = makeNode(AlterRoleStmt);
1354
1355 n->role = $3;
1356 n->action = +1; /* add, if there are members */
1357 n->options = $5;
1358 $$ = (Node *) n;
1359 }
1360 ;
1361
1362 opt_in_database:
1363 /* EMPTY */ { $$ = NULL; }
1364 | IN_P DATABASE name { $$ = $3; }
1365 ;
1366
1367 AlterRoleSetStmt:
1368 ALTER ROLE RoleSpec opt_in_database SetResetClause
1369 {
1370 AlterRoleSetStmt *n = makeNode(AlterRoleSetStmt);
1371
1372 n->role = $3;
1373 n->database = $4;
1374 n->setstmt = $5;
1375 $$ = (Node *) n;
1376 }
1377 | ALTER ROLE ALL opt_in_database SetResetClause
1378 {
1379 AlterRoleSetStmt *n = makeNode(AlterRoleSetStmt);
1380
1381 n->role = NULL;
1382 n->database = $4;
1383 n->setstmt = $5;
1384 $$ = (Node *) n;
1385 }
1386 | ALTER USER RoleSpec opt_in_database SetResetClause
1387 {
1388 AlterRoleSetStmt *n = makeNode(AlterRoleSetStmt);
1389
1390 n->role = $3;
1391 n->database = $4;
1392 n->setstmt = $5;
1393 $$ = (Node *) n;
1394 }
1395 | ALTER USER ALL opt_in_database SetResetClause
1396 {
1397 AlterRoleSetStmt *n = makeNode(AlterRoleSetStmt);
1398
1399 n->role = NULL;
1400 n->database = $4;
1401 n->setstmt = $5;
1402 $$ = (Node *) n;
1403 }
1404 ;
1405
1406
1407 /*****************************************************************************
1408 *
1409 * Drop a postgresql DBMS role
1410 *
1411 * XXX Ideally this would have CASCADE/RESTRICT options, but a role
1412 * might own objects in multiple databases, and there is presently no way to
1413 * implement cascading to other databases. So we always behave as RESTRICT.
1414 *****************************************************************************/
1415
1416 DropRoleStmt:
1417 DROP ROLE role_list
1418 {
1419 DropRoleStmt *n = makeNode(DropRoleStmt);
1420
1421 n->missing_ok = false;
1422 n->roles = $3;
1423 $$ = (Node *) n;
1424 }
1425 | DROP ROLE IF_P EXISTS role_list
1426 {
1427 DropRoleStmt *n = makeNode(DropRoleStmt);
1428
1429 n->missing_ok = true;
1430 n->roles = $5;
1431 $$ = (Node *) n;
1432 }
1433 | DROP USER role_list
1434 {
1435 DropRoleStmt *n = makeNode(DropRoleStmt);
1436
1437 n->missing_ok = false;
1438 n->roles = $3;
1439 $$ = (Node *) n;
1440 }
1441 | DROP USER IF_P EXISTS role_list
1442 {
1443 DropRoleStmt *n = makeNode(DropRoleStmt);
1444
1445 n->roles = $5;
1446 n->missing_ok = true;
1447 $$ = (Node *) n;
1448 }
1449 | DROP GROUP_P role_list
1450 {
1451 DropRoleStmt *n = makeNode(DropRoleStmt);
1452
1453 n->missing_ok = false;
1454 n->roles = $3;
1455 $$ = (Node *) n;
1456 }
1457 | DROP GROUP_P IF_P EXISTS role_list
1458 {
1459 DropRoleStmt *n = makeNode(DropRoleStmt);
1460
1461 n->missing_ok = true;
1462 n->roles = $5;
1463 $$ = (Node *) n;
1464 }
1465 ;
1466
1467
1468 /*****************************************************************************
1469 *
1470 * Create a postgresql group (role without login ability)
1471 *
1472 *****************************************************************************/
1473
1474 CreateGroupStmt:
1475 CREATE GROUP_P RoleId opt_with OptRoleList
1476 {
1477 CreateRoleStmt *n = makeNode(CreateRoleStmt);
1478
1479 n->stmt_type = ROLESTMT_GROUP;
1480 n->role = $3;
1481 n->options = $5;
1482 $$ = (Node *) n;
1483 }
1484 ;
1485
1486
1487 /*****************************************************************************
1488 *
1489 * Alter a postgresql group
1490 *
1491 *****************************************************************************/
1492
1493 AlterGroupStmt:
1494 ALTER GROUP_P RoleSpec add_drop USER role_list
1495 {
1496 AlterRoleStmt *n = makeNode(AlterRoleStmt);
1497
1498 n->role = $3;
1499 n->action = $4;
1500 n->options = list_make1(makeDefElem("rolemembers",
1501 (Node *) $6, @6));
1502 $$ = (Node *) n;
1503 }
1504 ;
1505
1506 add_drop: ADD_P { $$ = +1; }
1507 | DROP { $$ = -1; }
1508 ;
1509
1510
1511 /*****************************************************************************
1512 *
1513 * Manipulate a schema
1514 *
1515 *****************************************************************************/
1516
1517 CreateSchemaStmt:
1518 CREATE SCHEMA opt_single_name AUTHORIZATION RoleSpec OptSchemaEltList
1519 {
1520 CreateSchemaStmt *n = makeNode(CreateSchemaStmt);
1521
1522 /* One can omit the schema name or the authorization id. */
1523 n->schemaname = $3;
1524 n->authrole = $5;
1525 n->schemaElts = $6;
1526 n->if_not_exists = false;
1527 $$ = (Node *) n;
1528 }
1529 | CREATE SCHEMA ColId OptSchemaEltList
1530 {
1531 CreateSchemaStmt *n = makeNode(CreateSchemaStmt);
1532
1533 /* ...but not both */
1534 n->schemaname = $3;
1535 n->authrole = NULL;
1536 n->schemaElts = $4;
1537 n->if_not_exists = false;
1538 $$ = (Node *) n;
1539 }
1540 | CREATE SCHEMA IF_P NOT EXISTS opt_single_name AUTHORIZATION RoleSpec OptSchemaEltList
1541 {
1542 CreateSchemaStmt *n = makeNode(CreateSchemaStmt);
1543
1544 /* schema name can be omitted here, too */
1545 n->schemaname = $6;
1546 n->authrole = $8;
1547 if ($9 != NIL)
1548 ereport(ERROR,
1549 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
1550 errmsg("CREATE SCHEMA IF NOT EXISTS cannot include schema elements"),
1551 parser_errposition(@9)));
1552 n->schemaElts = $9;
1553 n->if_not_exists = true;
1554 $$ = (Node *) n;
1555 }
1556 | CREATE SCHEMA IF_P NOT EXISTS ColId OptSchemaEltList
1557 {
1558 CreateSchemaStmt *n = makeNode(CreateSchemaStmt);
1559
1560 /* ...but not here */
1561 n->schemaname = $6;
1562 n->authrole = NULL;
1563 if ($7 != NIL)
1564 ereport(ERROR,
1565 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
1566 errmsg("CREATE SCHEMA IF NOT EXISTS cannot include schema elements"),
1567 parser_errposition(@7)));
1568 n->schemaElts = $7;
1569 n->if_not_exists = true;
1570 $$ = (Node *) n;
1571 }
1572 ;
1573
1574 OptSchemaEltList:
1575 OptSchemaEltList schema_stmt
1576 {
1577 $$ = lappend($1, $2);
1578 }
1579 | /* EMPTY */
1580 { $$ = NIL; }
1581 ;
1582
1583 /*
1584 * schema_stmt are the ones that can show up inside a CREATE SCHEMA
1585 * statement (in addition to by themselves).
1586 */
1587 schema_stmt:
1588 CreateStmt
1589 | IndexStmt
1590 | CreateSeqStmt
1591 | CreateTrigStmt
1592 | GrantStmt
1593 | ViewStmt
1594 ;
1595
1596
1597 /*****************************************************************************
1598 *
1599 * Set PG internal variable
1600 * SET name TO 'var_value'
1601 * Include SQL syntax (thomas 1997-10-22):
1602 * SET TIME ZONE 'var_value'
1603 *
1604 *****************************************************************************/
1605
1606 VariableSetStmt:
1607 SET set_rest
1608 {
1609 VariableSetStmt *n = $2;
1610
1611 n->is_local = false;
1612 $$ = (Node *) n;
1613 }
1614 | SET LOCAL set_rest
1615 {
1616 VariableSetStmt *n = $3;
1617
1618 n->is_local = true;
1619 $$ = (Node *) n;
1620 }
1621 | SET SESSION set_rest
1622 {
1623 VariableSetStmt *n = $3;
1624
1625 n->is_local = false;
1626 $$ = (Node *) n;
1627 }
1628 ;
1629
1630 set_rest:
1631 TRANSACTION transaction_mode_list
1632 {
1633 VariableSetStmt *n = makeNode(VariableSetStmt);
1634
1635 n->kind = VAR_SET_MULTI;
1636 n->name = "TRANSACTION";
1637 n->args = $2;
1638 n->jumble_args = true;
1639 n->location = -1;
1640 $$ = n;
1641 }
1642 | SESSION CHARACTERISTICS AS TRANSACTION transaction_mode_list
1643 {
1644 VariableSetStmt *n = makeNode(VariableSetStmt);
1645
1646 n->kind = VAR_SET_MULTI;
1647 n->name = "SESSION CHARACTERISTICS";
1648 n->args = $5;
1649 n->jumble_args = true;
1650 n->location = -1;
1651 $$ = n;
1652 }
1653 | set_rest_more
1654 ;
1655
1656 generic_set:
1657 var_name TO var_list
1658 {
1659 VariableSetStmt *n = makeNode(VariableSetStmt);
1660
1661 n->kind = VAR_SET_VALUE;
1662 n->name = $1;
1663 n->args = $3;
1664 n->location = @3;
1665 $$ = n;
1666 }
1667 | var_name '=' var_list
1668 {
1669 VariableSetStmt *n = makeNode(VariableSetStmt);
1670
1671 n->kind = VAR_SET_VALUE;
1672 n->name = $1;
1673 n->args = $3;
1674 n->location = @3;
1675 $$ = n;
1676 }
1677 | var_name TO DEFAULT
1678 {
1679 VariableSetStmt *n = makeNode(VariableSetStmt);
1680
1681 n->kind = VAR_SET_DEFAULT;
1682 n->name = $1;
1683 n->location = -1;
1684 $$ = n;
1685 }
1686 | var_name '=' DEFAULT
1687 {
1688 VariableSetStmt *n = makeNode(VariableSetStmt);
1689
1690 n->kind = VAR_SET_DEFAULT;
1691 n->name = $1;
1692 n->location = -1;
1693 $$ = n;
1694 }
1695 ;
1696
1697 set_rest_more: /* Generic SET syntaxes: */
1698 generic_set {$$ = $1;}
1699 | var_name FROM CURRENT_P
1700 {
1701 VariableSetStmt *n = makeNode(VariableSetStmt);
1702
1703 n->kind = VAR_SET_CURRENT;
1704 n->name = $1;
1705 n->location = -1;
1706 $$ = n;
1707 }
1708 /* Special syntaxes mandated by SQL standard: */
1709 | TIME ZONE zone_value
1710 {
1711 VariableSetStmt *n = makeNode(VariableSetStmt);
1712
1713 n->kind = VAR_SET_VALUE;
1714 n->name = "timezone";
1715 n->location = -1;
1716 n->jumble_args = true;
1717 if ($3 != NULL)
1718 n->args = list_make1($3);
1719 else
1720 n->kind = VAR_SET_DEFAULT;
1721 $$ = n;
1722 }
1723 | CATALOG_P Sconst
1724 {
1725 ereport(ERROR,
1726 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
1727 errmsg("current database cannot be changed"),
1728 parser_errposition(@2)));
1729 $$ = NULL; /*not reached*/
1730 }
1731 | SCHEMA Sconst
1732 {
1733 VariableSetStmt *n = makeNode(VariableSetStmt);
1734
1735 n->kind = VAR_SET_VALUE;
1736 n->name = "search_path";
1737 n->args = list_make1(makeStringConst($2, @2));
1738 n->location = @2;
1739 $$ = n;
1740 }
1741 | NAMES opt_encoding
1742 {
1743 VariableSetStmt *n = makeNode(VariableSetStmt);
1744
1745 n->kind = VAR_SET_VALUE;
1746 n->name = "client_encoding";
1747 n->location = @2;
1748 if ($2 != NULL)
1749 n->args = list_make1(makeStringConst($2, @2));
1750 else
1751 n->kind = VAR_SET_DEFAULT;
1752 $$ = n;
1753 }
1754 | ROLE NonReservedWord_or_Sconst
1755 {
1756 VariableSetStmt *n = makeNode(VariableSetStmt);
1757
1758 n->kind = VAR_SET_VALUE;
1759 n->name = "role";
1760 n->args = list_make1(makeStringConst($2, @2));
1761 n->location = @2;
1762 $$ = n;
1763 }
1764 | SESSION AUTHORIZATION NonReservedWord_or_Sconst
1765 {
1766 VariableSetStmt *n = makeNode(VariableSetStmt);
1767
1768 n->kind = VAR_SET_VALUE;
1769 n->name = "session_authorization";
1770 n->args = list_make1(makeStringConst($3, @3));
1771 n->location = @3;
1772 $$ = n;
1773 }
1774 | SESSION AUTHORIZATION DEFAULT
1775 {
1776 VariableSetStmt *n = makeNode(VariableSetStmt);
1777
1778 n->kind = VAR_SET_DEFAULT;
1779 n->name = "session_authorization";
1780 n->location = -1;
1781 $$ = n;
1782 }
1783 | XML_P OPTION document_or_content
1784 {
1785 VariableSetStmt *n = makeNode(VariableSetStmt);
1786
1787 n->kind = VAR_SET_VALUE;
1788 n->name = "xmloption";
1789 n->args = list_make1(makeStringConst($3 == XMLOPTION_DOCUMENT ? "DOCUMENT" : "CONTENT", @3));
1790 n->jumble_args = true;
1791 n->location = -1;
1792 $$ = n;
1793 }
1794 /* Special syntaxes invented by PostgreSQL: */
1795 | TRANSACTION SNAPSHOT Sconst
1796 {
1797 VariableSetStmt *n = makeNode(VariableSetStmt);
1798
1799 n->kind = VAR_SET_MULTI;
1800 n->name = "TRANSACTION SNAPSHOT";
1801 n->args = list_make1(makeStringConst($3, @3));
1802 n->location = @3;
1803 $$ = n;
1804 }
1805 ;
1806
1807 var_name: ColId { $$ = $1; }
1808 | var_name '.' ColId
1809 { $$ = psprintf("%s.%s", $1, $3); }
1810 ;
1811
1812 var_list: var_value { $$ = list_make1($1); }
1813 | var_list ',' var_value { $$ = lappend($1, $3); }
1814 ;
1815
1816 var_value: opt_boolean_or_string
1817 { $$ = makeStringConst($1, @1); }
1818 | NumericOnly
1819 { $$ = makeAConst($1, @1); }
1820 ;
1821
1822 iso_level: READ UNCOMMITTED { $$ = "read uncommitted"; }
1823 | READ COMMITTED { $$ = "read committed"; }
1824 | REPEATABLE READ { $$ = "repeatable read"; }
1825 | SERIALIZABLE { $$ = "serializable"; }
1826 ;
1827
1828 opt_boolean_or_string:
1829 TRUE_P { $$ = "true"; }
1830 | FALSE_P { $$ = "false"; }
1831 | ON { $$ = "on"; }
1832 /*
1833 * OFF is also accepted as a boolean value, but is handled by
1834 * the NonReservedWord rule. The action for booleans and strings
1835 * is the same, so we don't need to distinguish them here.
1836 */
1837 | NonReservedWord_or_Sconst { $$ = $1; }
1838 ;
1839
1840 /* Timezone values can be:
1841 * - a string such as 'pst8pdt'
1842 * - an identifier such as "pst8pdt"
1843 * - an integer or floating point number
1844 * - a time interval per SQL99
1845 * ColId gives reduce/reduce errors against ConstInterval and LOCAL,
1846 * so use IDENT (meaning we reject anything that is a key word).
1847 */
1848 zone_value:
1849 Sconst
1850 {
1851 $$ = makeStringConst($1, @1);
1852 }
1853 | IDENT
1854 {
1855 $$ = makeStringConst($1, @1);
1856 }
1857 | ConstInterval Sconst opt_interval
1858 {
1859 TypeName *t = $1;
1860
1861 if ($3 != NIL)
1862 {
1863 A_Const *n = (A_Const *) linitial($3);
1864
1865 if ((n->val.ival.ival & ~(INTERVAL_MASK(HOUR) | INTERVAL_MASK(MINUTE))) != 0)
1866 ereport(ERROR,
1867 (errcode(ERRCODE_SYNTAX_ERROR),
1868 errmsg("time zone interval must be HOUR or HOUR TO MINUTE"),
1869 parser_errposition(@3)));
1870 }
1871 t->typmods = $3;
1872 $$ = makeStringConstCast($2, @2, t);
1873 }
1874 | ConstInterval '(' Iconst ')' Sconst
1875 {
1876 TypeName *t = $1;
1877
1878 t->typmods = list_make2(makeIntConst(INTERVAL_FULL_RANGE, -1),
1879 makeIntConst($3, @3));
1880 $$ = makeStringConstCast($5, @5, t);
1881 }
1882 | NumericOnly { $$ = makeAConst($1, @1); }
1883 | DEFAULT { $$ = NULL; }
1884 | LOCAL { $$ = NULL; }
1885 ;
1886
1887 opt_encoding:
1888 Sconst { $$ = $1; }
1889 | DEFAULT { $$ = NULL; }
1890 | /*EMPTY*/ { $$ = NULL; }
1891 ;
1892
1893 NonReservedWord_or_Sconst:
1894 NonReservedWord { $$ = $1; }
1895 | Sconst { $$ = $1; }
1896 ;
1897
1898 VariableResetStmt:
1899 RESET reset_rest { $$ = (Node *) $2; }
1900 ;
1901
1902 reset_rest:
1903 generic_reset { $$ = $1; }
1904 | TIME ZONE
1905 {
1906 VariableSetStmt *n = makeNode(VariableSetStmt);
1907
1908 n->kind = VAR_RESET;
1909 n->name = "timezone";
1910 n->location = -1;
1911 $$ = n;
1912 }
1913 | TRANSACTION ISOLATION LEVEL
1914 {
1915 VariableSetStmt *n = makeNode(VariableSetStmt);
1916
1917 n->kind = VAR_RESET;
1918 n->name = "transaction_isolation";
1919 n->location = -1;
1920 $$ = n;
1921 }
1922 | SESSION AUTHORIZATION
1923 {
1924 VariableSetStmt *n = makeNode(VariableSetStmt);
1925
1926 n->kind = VAR_RESET;
1927 n->name = "session_authorization";
1928 n->location = -1;
1929 $$ = n;
1930 }
1931 ;
1932
1933 generic_reset:
1934 var_name
1935 {
1936 VariableSetStmt *n = makeNode(VariableSetStmt);
1937
1938 n->kind = VAR_RESET;
1939 n->name = $1;
1940 n->location = -1;
1941 $$ = n;
1942 }
1943 | ALL
1944 {
1945 VariableSetStmt *n = makeNode(VariableSetStmt);
1946
1947 n->kind = VAR_RESET_ALL;
1948 n->location = -1;
1949 $$ = n;
1950 }
1951 ;
1952
1953 /* SetResetClause allows SET or RESET without LOCAL */
1954 SetResetClause:
1955 SET set_rest { $$ = $2; }
1956 | VariableResetStmt { $$ = (VariableSetStmt *) $1; }
1957 ;
1958
1959 /* SetResetClause allows SET or RESET without LOCAL */
1960 FunctionSetResetClause:
1961 SET set_rest_more { $$ = $2; }
1962 | VariableResetStmt { $$ = (VariableSetStmt *) $1; }
1963 ;
1964
1965
1966 VariableShowStmt:
1967 SHOW var_name
1968 {
1969 VariableShowStmt *n = makeNode(VariableShowStmt);
1970
1971 n->name = $2;
1972 $$ = (Node *) n;
1973 }
1974 | SHOW TIME ZONE
1975 {
1976 VariableShowStmt *n = makeNode(VariableShowStmt);
1977
1978 n->name = "timezone";
1979 $$ = (Node *) n;
1980 }
1981 | SHOW TRANSACTION ISOLATION LEVEL
1982 {
1983 VariableShowStmt *n = makeNode(VariableShowStmt);
1984
1985 n->name = "transaction_isolation";
1986 $$ = (Node *) n;
1987 }
1988 | SHOW SESSION AUTHORIZATION
1989 {
1990 VariableShowStmt *n = makeNode(VariableShowStmt);
1991
1992 n->name = "session_authorization";
1993 $$ = (Node *) n;
1994 }
1995 | SHOW ALL
1996 {
1997 VariableShowStmt *n = makeNode(VariableShowStmt);
1998
1999 n->name = "all";
2000 $$ = (Node *) n;
2001 }
2002 ;
2003
2004
2005 ConstraintsSetStmt:
2006 SET CONSTRAINTS constraints_set_list constraints_set_mode
2007 {
2008 ConstraintsSetStmt *n = makeNode(ConstraintsSetStmt);
2009
2010 n->constraints = $3;
2011 n->deferred = $4;
2012 $$ = (Node *) n;
2013 }
2014 ;
2015
2016 constraints_set_list:
2017 ALL { $$ = NIL; }
2018 | qualified_name_list { $$ = $1; }
2019 ;
2020
2021 constraints_set_mode:
2022 DEFERRED { $$ = true; }
2023 | IMMEDIATE { $$ = false; }
2024 ;
2025
2026
2027 /*
2028 * Checkpoint statement
2029 */
2030 CheckPointStmt:
2031 CHECKPOINT
2032 {
2033 CheckPointStmt *n = makeNode(CheckPointStmt);
2034
2035 $$ = (Node *) n;
2036 }
2037 ;
2038
2039
2040 /*****************************************************************************
2041 *
2042 * DISCARD { ALL | TEMP | PLANS | SEQUENCES }
2043 *
2044 *****************************************************************************/
2045
2046 DiscardStmt:
2047 DISCARD ALL
2048 {
2049 DiscardStmt *n = makeNode(DiscardStmt);
2050
2051 n->target = DISCARD_ALL;
2052 $$ = (Node *) n;
2053 }
2054 | DISCARD TEMP
2055 {
2056 DiscardStmt *n = makeNode(DiscardStmt);
2057
2058 n->target = DISCARD_TEMP;
2059 $$ = (Node *) n;
2060 }
2061 | DISCARD TEMPORARY
2062 {
2063 DiscardStmt *n = makeNode(DiscardStmt);
2064
2065 n->target = DISCARD_TEMP;
2066 $$ = (Node *) n;
2067 }
2068 | DISCARD PLANS
2069 {
2070 DiscardStmt *n = makeNode(DiscardStmt);
2071
2072 n->target = DISCARD_PLANS;
2073 $$ = (Node *) n;
2074 }
2075 | DISCARD SEQUENCES
2076 {
2077 DiscardStmt *n = makeNode(DiscardStmt);
2078
2079 n->target = DISCARD_SEQUENCES;
2080 $$ = (Node *) n;
2081 }
2082
2083 ;
2084
2085
2086 /*****************************************************************************
2087 *
2088 * ALTER [ TABLE | INDEX | SEQUENCE | VIEW | MATERIALIZED VIEW | FOREIGN TABLE ] variations
2089 *
2090 * Note: we accept all subcommands for each of the variants, and sort
2091 * out what's really legal at execution time.
2092 *****************************************************************************/
2093
2094 AlterTableStmt:
2095 ALTER TABLE relation_expr alter_table_cmds
2096 {
2097 AlterTableStmt *n = makeNode(AlterTableStmt);
2098
2099 n->relation = $3;
2100 n->cmds = $4;
2101 n->objtype = OBJECT_TABLE;
2102 n->missing_ok = false;
2103 $$ = (Node *) n;
2104 }
2105 | ALTER TABLE IF_P EXISTS relation_expr alter_table_cmds
2106 {
2107 AlterTableStmt *n = makeNode(AlterTableStmt);
2108
2109 n->relation = $5;
2110 n->cmds = $6;
2111 n->objtype = OBJECT_TABLE;
2112 n->missing_ok = true;
2113 $$ = (Node *) n;
2114 }
2115 | ALTER TABLE relation_expr partition_cmd
2116 {
2117 AlterTableStmt *n = makeNode(AlterTableStmt);
2118
2119 n->relation = $3;
2120 n->cmds = list_make1($4);
2121 n->objtype = OBJECT_TABLE;
2122 n->missing_ok = false;
2123 $$ = (Node *) n;
2124 }
2125 | ALTER TABLE IF_P EXISTS relation_expr partition_cmd
2126 {
2127 AlterTableStmt *n = makeNode(AlterTableStmt);
2128
2129 n->relation = $5;
2130 n->cmds = list_make1($6);
2131 n->objtype = OBJECT_TABLE;
2132 n->missing_ok = true;
2133 $$ = (Node *) n;
2134 }
2135 | ALTER TABLE ALL IN_P TABLESPACE name SET TABLESPACE name opt_nowait
2136 {
2137 AlterTableMoveAllStmt *n =
2138 makeNode(AlterTableMoveAllStmt);
2139
2140 n->orig_tablespacename = $6;
2141 n->objtype = OBJECT_TABLE;
2142 n->roles = NIL;
2143 n->new_tablespacename = $9;
2144 n->nowait = $10;
2145 $$ = (Node *) n;
2146 }
2147 | ALTER TABLE ALL IN_P TABLESPACE name OWNED BY role_list SET TABLESPACE name opt_nowait
2148 {
2149 AlterTableMoveAllStmt *n =
2150 makeNode(AlterTableMoveAllStmt);
2151
2152 n->orig_tablespacename = $6;
2153 n->objtype = OBJECT_TABLE;
2154 n->roles = $9;
2155 n->new_tablespacename = $12;
2156 n->nowait = $13;
2157 $$ = (Node *) n;
2158 }
2159 | ALTER INDEX qualified_name alter_table_cmds
2160 {
2161 AlterTableStmt *n = makeNode(AlterTableStmt);
2162
2163 n->relation = $3;
2164 n->cmds = $4;
2165 n->objtype = OBJECT_INDEX;
2166 n->missing_ok = false;
2167 $$ = (Node *) n;
2168 }
2169 | ALTER INDEX IF_P EXISTS qualified_name alter_table_cmds
2170 {
2171 AlterTableStmt *n = makeNode(AlterTableStmt);
2172
2173 n->relation = $5;
2174 n->cmds = $6;
2175 n->objtype = OBJECT_INDEX;
2176 n->missing_ok = true;
2177 $$ = (Node *) n;
2178 }
2179 | ALTER INDEX qualified_name index_partition_cmd
2180 {
2181 AlterTableStmt *n = makeNode(AlterTableStmt);
2182
2183 n->relation = $3;
2184 n->cmds = list_make1($4);
2185 n->objtype = OBJECT_INDEX;
2186 n->missing_ok = false;
2187 $$ = (Node *) n;
2188 }
2189 | ALTER INDEX ALL IN_P TABLESPACE name SET TABLESPACE name opt_nowait
2190 {
2191 AlterTableMoveAllStmt *n =
2192 makeNode(AlterTableMoveAllStmt);
2193
2194 n->orig_tablespacename = $6;
2195 n->objtype = OBJECT_INDEX;
2196 n->roles = NIL;
2197 n->new_tablespacename = $9;
2198 n->nowait = $10;
2199 $$ = (Node *) n;
2200 }
2201 | ALTER INDEX ALL IN_P TABLESPACE name OWNED BY role_list SET TABLESPACE name opt_nowait
2202 {
2203 AlterTableMoveAllStmt *n =
2204 makeNode(AlterTableMoveAllStmt);
2205
2206 n->orig_tablespacename = $6;
2207 n->objtype = OBJECT_INDEX;
2208 n->roles = $9;
2209 n->new_tablespacename = $12;
2210 n->nowait = $13;
2211 $$ = (Node *) n;
2212 }
2213 | ALTER SEQUENCE qualified_name alter_table_cmds
2214 {
2215 AlterTableStmt *n = makeNode(AlterTableStmt);
2216
2217 n->relation = $3;
2218 n->cmds = $4;
2219 n->objtype = OBJECT_SEQUENCE;
2220 n->missing_ok = false;
2221 $$ = (Node *) n;
2222 }
2223 | ALTER SEQUENCE IF_P EXISTS qualified_name alter_table_cmds
2224 {
2225 AlterTableStmt *n = makeNode(AlterTableStmt);
2226
2227 n->relation = $5;
2228 n->cmds = $6;
2229 n->objtype = OBJECT_SEQUENCE;
2230 n->missing_ok = true;
2231 $$ = (Node *) n;
2232 }
2233 | ALTER VIEW qualified_name alter_table_cmds
2234 {
2235 AlterTableStmt *n = makeNode(AlterTableStmt);
2236
2237 n->relation = $3;
2238 n->cmds = $4;
2239 n->objtype = OBJECT_VIEW;
2240 n->missing_ok = false;
2241 $$ = (Node *) n;
2242 }
2243 | ALTER VIEW IF_P EXISTS qualified_name alter_table_cmds
2244 {
2245 AlterTableStmt *n = makeNode(AlterTableStmt);
2246
2247 n->relation = $5;
2248 n->cmds = $6;
2249 n->objtype = OBJECT_VIEW;
2250 n->missing_ok = true;
2251 $$ = (Node *) n;
2252 }
2253 | ALTER MATERIALIZED VIEW qualified_name alter_table_cmds
2254 {
2255 AlterTableStmt *n = makeNode(AlterTableStmt);
2256
2257 n->relation = $4;
2258 n->cmds = $5;
2259 n->objtype = OBJECT_MATVIEW;
2260 n->missing_ok = false;
2261 $$ = (Node *) n;
2262 }
2263 | ALTER MATERIALIZED VIEW IF_P EXISTS qualified_name alter_table_cmds
2264 {
2265 AlterTableStmt *n = makeNode(AlterTableStmt);
2266
2267 n->relation = $6;
2268 n->cmds = $7;
2269 n->objtype = OBJECT_MATVIEW;
2270 n->missing_ok = true;
2271 $$ = (Node *) n;
2272 }
2273 | ALTER MATERIALIZED VIEW ALL IN_P TABLESPACE name SET TABLESPACE name opt_nowait
2274 {
2275 AlterTableMoveAllStmt *n =
2276 makeNode(AlterTableMoveAllStmt);
2277
2278 n->orig_tablespacename = $7;
2279 n->objtype = OBJECT_MATVIEW;
2280 n->roles = NIL;
2281 n->new_tablespacename = $10;
2282 n->nowait = $11;
2283 $$ = (Node *) n;
2284 }
2285 | ALTER MATERIALIZED VIEW ALL IN_P TABLESPACE name OWNED BY role_list SET TABLESPACE name opt_nowait
2286 {
2287 AlterTableMoveAllStmt *n =
2288 makeNode(AlterTableMoveAllStmt);
2289
2290 n->orig_tablespacename = $7;
2291 n->objtype = OBJECT_MATVIEW;
2292 n->roles = $10;
2293 n->new_tablespacename = $13;
2294 n->nowait = $14;
2295 $$ = (Node *) n;
2296 }
2297 | ALTER FOREIGN TABLE relation_expr alter_table_cmds
2298 {
2299 AlterTableStmt *n = makeNode(AlterTableStmt);
2300
2301 n->relation = $4;
2302 n->cmds = $5;
2303 n->objtype = OBJECT_FOREIGN_TABLE;
2304 n->missing_ok = false;
2305 $$ = (Node *) n;
2306 }
2307 | ALTER FOREIGN TABLE IF_P EXISTS relation_expr alter_table_cmds
2308 {
2309 AlterTableStmt *n = makeNode(AlterTableStmt);
2310
2311 n->relation = $6;
2312 n->cmds = $7;
2313 n->objtype = OBJECT_FOREIGN_TABLE;
2314 n->missing_ok = true;
2315 $$ = (Node *) n;
2316 }
2317 ;
2318
2319 alter_table_cmds:
2320 alter_table_cmd { $$ = list_make1($1); }
2321 | alter_table_cmds ',' alter_table_cmd { $$ = lappend($1, $3); }
2322 ;
2323
2324 partition_cmd:
2325 /* ALTER TABLE <name> ATTACH PARTITION <table_name> FOR VALUES */
2326 ATTACH PARTITION qualified_name PartitionBoundSpec
2327 {
2328 AlterTableCmd *n = makeNode(AlterTableCmd);
2329 PartitionCmd *cmd = makeNode(PartitionCmd);
2330
2331 n->subtype = AT_AttachPartition;
2332 cmd->name = $3;
2333 cmd->bound = $4;
2334 cmd->concurrent = false;
2335 n->def = (Node *) cmd;
2336
2337 $$ = (Node *) n;
2338 }
2339 /* ALTER TABLE <name> DETACH PARTITION <partition_name> [CONCURRENTLY] */
2340 | DETACH PARTITION qualified_name opt_concurrently
2341 {
2342 AlterTableCmd *n = makeNode(AlterTableCmd);
2343 PartitionCmd *cmd = makeNode(PartitionCmd);
2344
2345 n->subtype = AT_DetachPartition;
2346 cmd->name = $3;
2347 cmd->bound = NULL;
2348 cmd->concurrent = $4;
2349 n->def = (Node *) cmd;
2350
2351 $$ = (Node *) n;
2352 }
2353 | DETACH PARTITION qualified_name FINALIZE
2354 {
2355 AlterTableCmd *n = makeNode(AlterTableCmd);
2356 PartitionCmd *cmd = makeNode(PartitionCmd);
2357
2358 n->subtype = AT_DetachPartitionFinalize;
2359 cmd->name = $3;
2360 cmd->bound = NULL;
2361 cmd->concurrent = false;
2362 n->def = (Node *) cmd;
2363 $$ = (Node *) n;
2364 }
2365 ;
2366
2367 index_partition_cmd:
2368 /* ALTER INDEX <name> ATTACH PARTITION <index_name> */
2369 ATTACH PARTITION qualified_name
2370 {
2371 AlterTableCmd *n = makeNode(AlterTableCmd);
2372 PartitionCmd *cmd = makeNode(PartitionCmd);
2373
2374 n->subtype = AT_AttachPartition;
2375 cmd->name = $3;
2376 cmd->bound = NULL;
2377 cmd->concurrent = false;
2378 n->def = (Node *) cmd;
2379
2380 $$ = (Node *) n;
2381 }
2382 ;
2383
2384 alter_table_cmd:
2385 /* ALTER TABLE <name> ADD <coldef> */
2386 ADD_P columnDef
2387 {
2388 AlterTableCmd *n = makeNode(AlterTableCmd);
2389
2390 n->subtype = AT_AddColumn;
2391 n->def = $2;
2392 n->missing_ok = false;
2393 $$ = (Node *) n;
2394 }
2395 /* ALTER TABLE <name> ADD IF NOT EXISTS <coldef> */
2396 | ADD_P IF_P NOT EXISTS columnDef
2397 {
2398 AlterTableCmd *n = makeNode(AlterTableCmd);
2399
2400 n->subtype = AT_AddColumn;
2401 n->def = $5;
2402 n->missing_ok = true;
2403 $$ = (Node *) n;
2404 }
2405 /* ALTER TABLE <name> ADD COLUMN <coldef> */
2406 | ADD_P COLUMN columnDef
2407 {
2408 AlterTableCmd *n = makeNode(AlterTableCmd);
2409
2410 n->subtype = AT_AddColumn;
2411 n->def = $3;
2412 n->missing_ok = false;
2413 $$ = (Node *) n;
2414 }
2415 /* ALTER TABLE <name> ADD COLUMN IF NOT EXISTS <coldef> */
2416 | ADD_P COLUMN IF_P NOT EXISTS columnDef
2417 {
2418 AlterTableCmd *n = makeNode(AlterTableCmd);
2419
2420 n->subtype = AT_AddColumn;
2421 n->def = $6;
2422 n->missing_ok = true;
2423 $$ = (Node *) n;
2424 }
2425 /* ALTER TABLE <name> ALTER [COLUMN] <colname> {SET DEFAULT <expr>|DROP DEFAULT} */
2426 | ALTER opt_column ColId alter_column_default
2427 {
2428 AlterTableCmd *n = makeNode(AlterTableCmd);
2429
2430 n->subtype = AT_ColumnDefault;
2431 n->name = $3;
2432 n->def = $4;
2433 $$ = (Node *) n;
2434 }
2435 /* ALTER TABLE <name> ALTER [COLUMN] <colname> DROP NOT NULL */
2436 | ALTER opt_column ColId DROP NOT NULL_P
2437 {
2438 AlterTableCmd *n = makeNode(AlterTableCmd);
2439
2440 n->subtype = AT_DropNotNull;
2441 n->name = $3;
2442 $$ = (Node *) n;
2443 }
2444 /* ALTER TABLE <name> ALTER [COLUMN] <colname> SET NOT NULL */
2445 | ALTER opt_column ColId SET NOT NULL_P
2446 {
2447 AlterTableCmd *n = makeNode(AlterTableCmd);
2448
2449 n->subtype = AT_SetNotNull;
2450 n->name = $3;
2451 $$ = (Node *) n;
2452 }
2453 /* ALTER TABLE <name> ALTER [COLUMN] <colname> SET EXPRESSION AS <expr> */
2454 | ALTER opt_column ColId SET EXPRESSION AS '(' a_expr ')'
2455 {
2456 AlterTableCmd *n = makeNode(AlterTableCmd);
2457
2458 n->subtype = AT_SetExpression;
2459 n->name = $3;
2460 n->def = $8;
2461 $$ = (Node *) n;
2462 }
2463 /* ALTER TABLE <name> ALTER [COLUMN] <colname> DROP EXPRESSION */
2464 | ALTER opt_column ColId DROP EXPRESSION
2465 {
2466 AlterTableCmd *n = makeNode(AlterTableCmd);
2467
2468 n->subtype = AT_DropExpression;
2469 n->name = $3;
2470 $$ = (Node *) n;
2471 }
2472 /* ALTER TABLE <name> ALTER [COLUMN] <colname> DROP EXPRESSION IF EXISTS */
2473 | ALTER opt_column ColId DROP EXPRESSION IF_P EXISTS
2474 {
2475 AlterTableCmd *n = makeNode(AlterTableCmd);
2476
2477 n->subtype = AT_DropExpression;
2478 n->name = $3;
2479 n->missing_ok = true;
2480 $$ = (Node *) n;
2481 }
2482 /* ALTER TABLE <name> ALTER [COLUMN] <colname> SET STATISTICS */
2483 | ALTER opt_column ColId SET STATISTICS set_statistics_value
2484 {
2485 AlterTableCmd *n = makeNode(AlterTableCmd);
2486
2487 n->subtype = AT_SetStatistics;
2488 n->name = $3;
2489 n->def = $6;
2490 $$ = (Node *) n;
2491 }
2492 /* ALTER TABLE <name> ALTER [COLUMN] <colnum> SET STATISTICS */
2493 | ALTER opt_column Iconst SET STATISTICS set_statistics_value
2494 {
2495 AlterTableCmd *n = makeNode(AlterTableCmd);
2496
2497 if ($3 <= 0 || $3 > PG_INT16_MAX)
2498 ereport(ERROR,
2499 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
2500 errmsg("column number must be in range from 1 to %d", PG_INT16_MAX),
2501 parser_errposition(@3)));
2502
2503 n->subtype = AT_SetStatistics;
2504 n->num = (int16) $3;
2505 n->def = $6;
2506 $$ = (Node *) n;
2507 }
2508 /* ALTER TABLE <name> ALTER [COLUMN] <colname> SET ( column_parameter = value [, ... ] ) */
2509 | ALTER opt_column ColId SET reloptions
2510 {
2511 AlterTableCmd *n = makeNode(AlterTableCmd);
2512
2513 n->subtype = AT_SetOptions;
2514 n->name = $3;
2515 n->def = (Node *) $5;
2516 $$ = (Node *) n;
2517 }
2518 /* ALTER TABLE <name> ALTER [COLUMN] <colname> RESET ( column_parameter [, ... ] ) */
2519 | ALTER opt_column ColId RESET reloptions
2520 {
2521 AlterTableCmd *n = makeNode(AlterTableCmd);
2522
2523 n->subtype = AT_ResetOptions;
2524 n->name = $3;
2525 n->def = (Node *) $5;
2526 $$ = (Node *) n;
2527 }
2528 /* ALTER TABLE <name> ALTER [COLUMN] <colname> SET STORAGE <storagemode> */
2529 | ALTER opt_column ColId SET column_storage
2530 {
2531 AlterTableCmd *n = makeNode(AlterTableCmd);
2532
2533 n->subtype = AT_SetStorage;
2534 n->name = $3;
2535 n->def = (Node *) makeString($5);
2536 $$ = (Node *) n;
2537 }
2538 /* ALTER TABLE <name> ALTER [COLUMN] <colname> SET COMPRESSION <cm> */
2539 | ALTER opt_column ColId SET column_compression
2540 {
2541 AlterTableCmd *n = makeNode(AlterTableCmd);
2542
2543 n->subtype = AT_SetCompression;
2544 n->name = $3;
2545 n->def = (Node *) makeString($5);
2546 $$ = (Node *) n;
2547 }
2548 /* ALTER TABLE <name> ALTER [COLUMN] <colname> ADD GENERATED ... AS IDENTITY ... */
2549 | ALTER opt_column ColId ADD_P GENERATED generated_when AS IDENTITY_P OptParenthesizedSeqOptList
2550 {
2551 AlterTableCmd *n = makeNode(AlterTableCmd);
2552 Constraint *c = makeNode(Constraint);
2553
2554 c->contype = CONSTR_IDENTITY;
2555 c->generated_when = $6;
2556 c->options = $9;
2557 c->location = @5;
2558
2559 n->subtype = AT_AddIdentity;
2560 n->name = $3;
2561 n->def = (Node *) c;
2562
2563 $$ = (Node *) n;
2564 }
2565 /* ALTER TABLE <name> ALTER [COLUMN] <colname> SET <sequence options>/RESET */
2566 | ALTER opt_column ColId alter_identity_column_option_list
2567 {
2568 AlterTableCmd *n = makeNode(AlterTableCmd);
2569
2570 n->subtype = AT_SetIdentity;
2571 n->name = $3;
2572 n->def = (Node *) $4;
2573 $$ = (Node *) n;
2574 }
2575 /* ALTER TABLE <name> ALTER [COLUMN] <colname> DROP IDENTITY */
2576 | ALTER opt_column ColId DROP IDENTITY_P
2577 {
2578 AlterTableCmd *n = makeNode(AlterTableCmd);
2579
2580 n->subtype = AT_DropIdentity;
2581 n->name = $3;
2582 n->missing_ok = false;
2583 $$ = (Node *) n;
2584 }
2585 /* ALTER TABLE <name> ALTER [COLUMN] <colname> DROP IDENTITY IF EXISTS */
2586 | ALTER opt_column ColId DROP IDENTITY_P IF_P EXISTS
2587 {
2588 AlterTableCmd *n = makeNode(AlterTableCmd);
2589
2590 n->subtype = AT_DropIdentity;
2591 n->name = $3;
2592 n->missing_ok = true;
2593 $$ = (Node *) n;
2594 }
2595 /* ALTER TABLE <name> DROP [COLUMN] IF EXISTS <colname> [RESTRICT|CASCADE] */
2596 | DROP opt_column IF_P EXISTS ColId opt_drop_behavior
2597 {
2598 AlterTableCmd *n = makeNode(AlterTableCmd);
2599
2600 n->subtype = AT_DropColumn;
2601 n->name = $5;
2602 n->behavior = $6;
2603 n->missing_ok = true;
2604 $$ = (Node *) n;
2605 }
2606 /* ALTER TABLE <name> DROP [COLUMN] <colname> [RESTRICT|CASCADE] */
2607 | DROP opt_column ColId opt_drop_behavior
2608 {
2609 AlterTableCmd *n = makeNode(AlterTableCmd);
2610
2611 n->subtype = AT_DropColumn;
2612 n->name = $3;
2613 n->behavior = $4;
2614 n->missing_ok = false;
2615 $$ = (Node *) n;
2616 }
2617 /*
2618 * ALTER TABLE <name> ALTER [COLUMN] <colname> [SET DATA] TYPE <typename>
2619 * [ USING <expression> ]
2620 */
2621 | ALTER opt_column ColId opt_set_data TYPE_P Typename opt_collate_clause alter_using
2622 {
2623 AlterTableCmd *n = makeNode(AlterTableCmd);
2624 ColumnDef *def = makeNode(ColumnDef);
2625
2626 n->subtype = AT_AlterColumnType;
2627 n->name = $3;
2628 n->def = (Node *) def;
2629 /* We only use these fields of the ColumnDef node */
2630 def->typeName = $6;
2631 def->collClause = (CollateClause *) $7;
2632 def->raw_default = $8;
2633 def->location = @3;
2634 $$ = (Node *) n;
2635 }
2636 /* ALTER FOREIGN TABLE <name> ALTER [COLUMN] <colname> OPTIONS */
2637 | ALTER opt_column ColId alter_generic_options
2638 {
2639 AlterTableCmd *n = makeNode(AlterTableCmd);
2640
2641 n->subtype = AT_AlterColumnGenericOptions;
2642 n->name = $3;
2643 n->def = (Node *) $4;
2644 $$ = (Node *) n;
2645 }
2646 /* ALTER TABLE <name> ADD CONSTRAINT ... */
2647 | ADD_P TableConstraint
2648 {
2649 AlterTableCmd *n = makeNode(AlterTableCmd);
2650
2651 n->subtype = AT_AddConstraint;
2652 n->def = $2;
2653 $$ = (Node *) n;
2654 }
2655 /* ALTER TABLE <name> ALTER CONSTRAINT ... */
2656 | ALTER CONSTRAINT name ConstraintAttributeSpec
2657 {
2658 AlterTableCmd *n = makeNode(AlterTableCmd);
2659 ATAlterConstraint *c = makeNode(ATAlterConstraint);
2660
2661 n->subtype = AT_AlterConstraint;
2662 n->def = (Node *) c;
2663 c->conname = $3;
2664 if ($4 & (CAS_NOT_ENFORCED | CAS_ENFORCED))
2665 c->alterEnforceability = true;
2666 if ($4 & (CAS_DEFERRABLE | CAS_NOT_DEFERRABLE |
2667 CAS_INITIALLY_DEFERRED | CAS_INITIALLY_IMMEDIATE))
2668 c->alterDeferrability = true;
2669 if ($4 & CAS_NO_INHERIT)
2670 c->alterInheritability = true;
2671 /* handle unsupported case with specific error message */
2672 if ($4 & CAS_NOT_VALID)
2673 ereport(ERROR,
2674 errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
2675 errmsg("constraints cannot be altered to be NOT VALID"),
2676 parser_errposition(@4));
2677 processCASbits($4, @4, "FOREIGN KEY",
2678 &c->deferrable,
2679 &c->initdeferred,
2680 &c->is_enforced,
2681 NULL,
2682 &c->noinherit,
2683 yyscanner);
2684 $$ = (Node *) n;
2685 }
2686 /* ALTER TABLE <name> ALTER CONSTRAINT INHERIT */
2687 | ALTER CONSTRAINT name INHERIT
2688 {
2689 AlterTableCmd *n = makeNode(AlterTableCmd);
2690 ATAlterConstraint *c = makeNode(ATAlterConstraint);
2691
2692 n->subtype = AT_AlterConstraint;
2693 n->def = (Node *) c;
2694 c->conname = $3;
2695 c->alterInheritability = true;
2696 c->noinherit = false;
2697
2698 $$ = (Node *) n;
2699 }
2700 /* ALTER TABLE <name> VALIDATE CONSTRAINT ... */
2701 | VALIDATE CONSTRAINT name
2702 {
2703 AlterTableCmd *n = makeNode(AlterTableCmd);
2704
2705 n->subtype = AT_ValidateConstraint;
2706 n->name = $3;
2707 $$ = (Node *) n;
2708 }
2709 /* ALTER TABLE <name> DROP CONSTRAINT IF EXISTS <name> [RESTRICT|CASCADE] */
2710 | DROP CONSTRAINT IF_P EXISTS name opt_drop_behavior
2711 {
2712 AlterTableCmd *n = makeNode(AlterTableCmd);
2713
2714 n->subtype = AT_DropConstraint;
2715 n->name = $5;
2716 n->behavior = $6;
2717 n->missing_ok = true;
2718 $$ = (Node *) n;
2719 }
2720 /* ALTER TABLE <name> DROP CONSTRAINT <name> [RESTRICT|CASCADE] */
2721 | DROP CONSTRAINT name opt_drop_behavior
2722 {
2723 AlterTableCmd *n = makeNode(AlterTableCmd);
2724
2725 n->subtype = AT_DropConstraint;
2726 n->name = $3;
2727 n->behavior = $4;
2728 n->missing_ok = false;
2729 $$ = (Node *) n;
2730 }
2731 /* ALTER TABLE <name> SET WITHOUT OIDS, for backward compat */
2732 | SET WITHOUT OIDS
2733 {
2734 AlterTableCmd *n = makeNode(AlterTableCmd);
2735
2736 n->subtype = AT_DropOids;
2737 $$ = (Node *) n;
2738 }
2739 /* ALTER TABLE <name> CLUSTER ON <indexname> */
2740 | CLUSTER ON name
2741 {
2742 AlterTableCmd *n = makeNode(AlterTableCmd);
2743
2744 n->subtype = AT_ClusterOn;
2745 n->name = $3;
2746 $$ = (Node *) n;
2747 }
2748 /* ALTER TABLE <name> SET WITHOUT CLUSTER */
2749 | SET WITHOUT CLUSTER
2750 {
2751 AlterTableCmd *n = makeNode(AlterTableCmd);
2752
2753 n->subtype = AT_DropCluster;
2754 n->name = NULL;
2755 $$ = (Node *) n;
2756 }
2757 /* ALTER TABLE <name> SET LOGGED */
2758 | SET LOGGED
2759 {
2760 AlterTableCmd *n = makeNode(AlterTableCmd);
2761
2762 n->subtype = AT_SetLogged;
2763 $$ = (Node *) n;
2764 }
2765 /* ALTER TABLE <name> SET UNLOGGED */
2766 | SET UNLOGGED
2767 {
2768 AlterTableCmd *n = makeNode(AlterTableCmd);
2769
2770 n->subtype = AT_SetUnLogged;
2771 $$ = (Node *) n;
2772 }
2773 /* ALTER TABLE <name> ENABLE TRIGGER <trig> */
2774 | ENABLE_P TRIGGER name
2775 {
2776 AlterTableCmd *n = makeNode(AlterTableCmd);
2777
2778 n->subtype = AT_EnableTrig;
2779 n->name = $3;
2780 $$ = (Node *) n;
2781 }
2782 /* ALTER TABLE <name> ENABLE ALWAYS TRIGGER <trig> */
2783 | ENABLE_P ALWAYS TRIGGER name
2784 {
2785 AlterTableCmd *n = makeNode(AlterTableCmd);
2786
2787 n->subtype = AT_EnableAlwaysTrig;
2788 n->name = $4;
2789 $$ = (Node *) n;
2790 }
2791 /* ALTER TABLE <name> ENABLE REPLICA TRIGGER <trig> */
2792 | ENABLE_P REPLICA TRIGGER name
2793 {
2794 AlterTableCmd *n = makeNode(AlterTableCmd);
2795
2796 n->subtype = AT_EnableReplicaTrig;
2797 n->name = $4;
2798 $$ = (Node *) n;
2799 }
2800 /* ALTER TABLE <name> ENABLE TRIGGER ALL */
2801 | ENABLE_P TRIGGER ALL
2802 {
2803 AlterTableCmd *n = makeNode(AlterTableCmd);
2804
2805 n->subtype = AT_EnableTrigAll;
2806 $$ = (Node *) n;
2807 }
2808 /* ALTER TABLE <name> ENABLE TRIGGER USER */
2809 | ENABLE_P TRIGGER USER
2810 {
2811 AlterTableCmd *n = makeNode(AlterTableCmd);
2812
2813 n->subtype = AT_EnableTrigUser;
2814 $$ = (Node *) n;
2815 }
2816 /* ALTER TABLE <name> DISABLE TRIGGER <trig> */
2817 | DISABLE_P TRIGGER name
2818 {
2819 AlterTableCmd *n = makeNode(AlterTableCmd);
2820
2821 n->subtype = AT_DisableTrig;
2822 n->name = $3;
2823 $$ = (Node *) n;
2824 }
2825 /* ALTER TABLE <name> DISABLE TRIGGER ALL */
2826 | DISABLE_P TRIGGER ALL
2827 {
2828 AlterTableCmd *n = makeNode(AlterTableCmd);
2829
2830 n->subtype = AT_DisableTrigAll;
2831 $$ = (Node *) n;
2832 }
2833 /* ALTER TABLE <name> DISABLE TRIGGER USER */
2834 | DISABLE_P TRIGGER USER
2835 {
2836 AlterTableCmd *n = makeNode(AlterTableCmd);
2837
2838 n->subtype = AT_DisableTrigUser;
2839 $$ = (Node *) n;
2840 }
2841 /* ALTER TABLE <name> ENABLE RULE <rule> */
2842 | ENABLE_P RULE name
2843 {
2844 AlterTableCmd *n = makeNode(AlterTableCmd);
2845
2846 n->subtype = AT_EnableRule;
2847 n->name = $3;
2848 $$ = (Node *) n;
2849 }
2850 /* ALTER TABLE <name> ENABLE ALWAYS RULE <rule> */
2851 | ENABLE_P ALWAYS RULE name
2852 {
2853 AlterTableCmd *n = makeNode(AlterTableCmd);
2854
2855 n->subtype = AT_EnableAlwaysRule;
2856 n->name = $4;
2857 $$ = (Node *) n;
2858 }
2859 /* ALTER TABLE <name> ENABLE REPLICA RULE <rule> */
2860 | ENABLE_P REPLICA RULE name
2861 {
2862 AlterTableCmd *n = makeNode(AlterTableCmd);
2863
2864 n->subtype = AT_EnableReplicaRule;
2865 n->name = $4;
2866 $$ = (Node *) n;
2867 }
2868 /* ALTER TABLE <name> DISABLE RULE <rule> */
2869 | DISABLE_P RULE name
2870 {
2871 AlterTableCmd *n = makeNode(AlterTableCmd);
2872
2873 n->subtype = AT_DisableRule;
2874 n->name = $3;
2875 $$ = (Node *) n;
2876 }
2877 /* ALTER TABLE <name> INHERIT <parent> */
2878 | INHERIT qualified_name
2879 {
2880 AlterTableCmd *n = makeNode(AlterTableCmd);
2881
2882 n->subtype = AT_AddInherit;
2883 n->def = (Node *) $2;
2884 $$ = (Node *) n;
2885 }
2886 /* ALTER TABLE <name> NO INHERIT <parent> */
2887 | NO INHERIT qualified_name
2888 {
2889 AlterTableCmd *n = makeNode(AlterTableCmd);
2890
2891 n->subtype = AT_DropInherit;
2892 n->def = (Node *) $3;
2893 $$ = (Node *) n;
2894 }
2895 /* ALTER TABLE <name> OF <type_name> */
2896 | OF any_name
2897 {
2898 AlterTableCmd *n = makeNode(AlterTableCmd);
2899 TypeName *def = makeTypeNameFromNameList($2);
2900
2901 def->location = @2;
2902 n->subtype = AT_AddOf;
2903 n->def = (Node *) def;
2904 $$ = (Node *) n;
2905 }
2906 /* ALTER TABLE <name> NOT OF */
2907 | NOT OF
2908 {
2909 AlterTableCmd *n = makeNode(AlterTableCmd);
2910
2911 n->subtype = AT_DropOf;
2912 $$ = (Node *) n;
2913 }
2914 /* ALTER TABLE <name> OWNER TO RoleSpec */
2915 | OWNER TO RoleSpec
2916 {
2917 AlterTableCmd *n = makeNode(AlterTableCmd);
2918
2919 n->subtype = AT_ChangeOwner;
2920 n->newowner = $3;
2921 $$ = (Node *) n;
2922 }
2923 /* ALTER TABLE <name> SET ACCESS METHOD { <amname> | DEFAULT } */
2924 | SET ACCESS METHOD set_access_method_name
2925 {
2926 AlterTableCmd *n = makeNode(AlterTableCmd);
2927
2928 n->subtype = AT_SetAccessMethod;
2929 n->name = $4;
2930 $$ = (Node *) n;
2931 }
2932 /* ALTER TABLE <name> SET TABLESPACE <tablespacename> */
2933 | SET TABLESPACE name
2934 {
2935 AlterTableCmd *n = makeNode(AlterTableCmd);
2936
2937 n->subtype = AT_SetTableSpace;
2938 n->name = $3;
2939 $$ = (Node *) n;
2940 }
2941 /* ALTER TABLE <name> SET (...) */
2942 | SET reloptions
2943 {
2944 AlterTableCmd *n = makeNode(AlterTableCmd);
2945
2946 n->subtype = AT_SetRelOptions;
2947 n->def = (Node *) $2;
2948 $$ = (Node *) n;
2949 }
2950 /* ALTER TABLE <name> RESET (...) */
2951 | RESET reloptions
2952 {
2953 AlterTableCmd *n = makeNode(AlterTableCmd);
2954
2955 n->subtype = AT_ResetRelOptions;
2956 n->def = (Node *) $2;
2957 $$ = (Node *) n;
2958 }
2959 /* ALTER TABLE <name> REPLICA IDENTITY */
2960 | REPLICA IDENTITY_P replica_identity
2961 {
2962 AlterTableCmd *n = makeNode(AlterTableCmd);
2963
2964 n->subtype = AT_ReplicaIdentity;
2965 n->def = $3;
2966 $$ = (Node *) n;
2967 }
2968 /* ALTER TABLE <name> ENABLE ROW LEVEL SECURITY */
2969 | ENABLE_P ROW LEVEL SECURITY
2970 {
2971 AlterTableCmd *n = makeNode(AlterTableCmd);
2972
2973 n->subtype = AT_EnableRowSecurity;
2974 $$ = (Node *) n;
2975 }
2976 /* ALTER TABLE <name> DISABLE ROW LEVEL SECURITY */
2977 | DISABLE_P ROW LEVEL SECURITY
2978 {
2979 AlterTableCmd *n = makeNode(AlterTableCmd);
2980
2981 n->subtype = AT_DisableRowSecurity;
2982 $$ = (Node *) n;
2983 }
2984 /* ALTER TABLE <name> FORCE ROW LEVEL SECURITY */
2985 | FORCE ROW LEVEL SECURITY
2986 {
2987 AlterTableCmd *n = makeNode(AlterTableCmd);
2988
2989 n->subtype = AT_ForceRowSecurity;
2990 $$ = (Node *) n;
2991 }
2992 /* ALTER TABLE <name> NO FORCE ROW LEVEL SECURITY */
2993 | NO FORCE ROW LEVEL SECURITY
2994 {
2995 AlterTableCmd *n = makeNode(AlterTableCmd);
2996
2997 n->subtype = AT_NoForceRowSecurity;
2998 $$ = (Node *) n;
2999 }
3000 | alter_generic_options
3001 {
3002 AlterTableCmd *n = makeNode(AlterTableCmd);
3003
3004 n->subtype = AT_GenericOptions;
3005 n->def = (Node *) $1;
3006 $$ = (Node *) n;
3007 }
3008 ;
3009
3010 alter_column_default:
3011 SET DEFAULT a_expr { $$ = $3; }
3012 | DROP DEFAULT { $$ = NULL; }
3013 ;
3014
3015 opt_collate_clause:
3016 COLLATE any_name
3017 {
3018 CollateClause *n = makeNode(CollateClause);
3019
3020 n->arg = NULL;
3021 n->collname = $2;
3022 n->location = @1;
3023 $$ = (Node *) n;
3024 }
3025 | /* EMPTY */ { $$ = NULL; }
3026 ;
3027
3028 alter_using:
3029 USING a_expr { $$ = $2; }
3030 | /* EMPTY */ { $$ = NULL; }
3031 ;
3032
3033 replica_identity:
3034 NOTHING
3035 {
3036 ReplicaIdentityStmt *n = makeNode(ReplicaIdentityStmt);
3037
3038 n->identity_type = REPLICA_IDENTITY_NOTHING;
3039 n->name = NULL;
3040 $$ = (Node *) n;
3041 }
3042 | FULL
3043 {
3044 ReplicaIdentityStmt *n = makeNode(ReplicaIdentityStmt);
3045
3046 n->identity_type = REPLICA_IDENTITY_FULL;
3047 n->name = NULL;
3048 $$ = (Node *) n;
3049 }
3050 | DEFAULT
3051 {
3052 ReplicaIdentityStmt *n = makeNode(ReplicaIdentityStmt);
3053
3054 n->identity_type = REPLICA_IDENTITY_DEFAULT;
3055 n->name = NULL;
3056 $$ = (Node *) n;
3057 }
3058 | USING INDEX name
3059 {
3060 ReplicaIdentityStmt *n = makeNode(ReplicaIdentityStmt);
3061
3062 n->identity_type = REPLICA_IDENTITY_INDEX;
3063 n->name = $3;
3064 $$ = (Node *) n;
3065 }
3066 ;
3067
3068 reloptions:
3069 '(' reloption_list ')' { $$ = $2; }
3070 ;
3071
3072 opt_reloptions: WITH reloptions { $$ = $2; }
3073 | /* EMPTY */ { $$ = NIL; }
3074 ;
3075
3076 reloption_list:
3077 reloption_elem { $$ = list_make1($1); }
3078 | reloption_list ',' reloption_elem { $$ = lappend($1, $3); }
3079 ;
3080
3081 /* This should match def_elem and also allow qualified names */
3082 reloption_elem:
3083 ColLabel '=' def_arg
3084 {
3085 $$ = makeDefElem($1, (Node *) $3, @1);
3086 }
3087 | ColLabel
3088 {
3089 $$ = makeDefElem($1, NULL, @1);
3090 }
3091 | ColLabel '.' ColLabel '=' def_arg
3092 {
3093 $$ = makeDefElemExtended($1, $3, (Node *) $5,
3094 DEFELEM_UNSPEC, @1);
3095 }
3096 | ColLabel '.' ColLabel
3097 {
3098 $$ = makeDefElemExtended($1, $3, NULL, DEFELEM_UNSPEC, @1);
3099 }
3100 ;
3101
3102 alter_identity_column_option_list:
3103 alter_identity_column_option
3104 { $$ = list_make1($1); }
3105 | alter_identity_column_option_list alter_identity_column_option
3106 { $$ = lappend($1, $2); }
3107 ;
3108
3109 alter_identity_column_option:
3110 RESTART
3111 {
3112 $$ = makeDefElem("restart", NULL, @1);
3113 }
3114 | RESTART opt_with NumericOnly
3115 {
3116 $$ = makeDefElem("restart", (Node *) $3, @1);
3117 }
3118 | SET SeqOptElem
3119 {
3120 if (strcmp($2->defname, "as") == 0 ||
3121 strcmp($2->defname, "restart") == 0 ||
3122 strcmp($2->defname, "owned_by") == 0)
3123 ereport(ERROR,
3124 (errcode(ERRCODE_SYNTAX_ERROR),
3125 errmsg("sequence option \"%s\" not supported here", $2->defname),
3126 parser_errposition(@2)));
3127 $$ = $2;
3128 }
3129 | SET GENERATED generated_when
3130 {
3131 $$ = makeDefElem("generated", (Node *) makeInteger($3), @1);
3132 }
3133 ;
3134
3135 set_statistics_value:
3136 SignedIconst { $$ = (Node *) makeInteger($1); }
3137 | DEFAULT { $$ = NULL; }
3138 ;
3139
3140 set_access_method_name:
3141 ColId { $$ = $1; }
3142 | DEFAULT { $$ = NULL; }
3143 ;
3144
3145 PartitionBoundSpec:
3146 /* a HASH partition */
3147 FOR VALUES WITH '(' hash_partbound ')'
3148 {
3149 ListCell *lc;
3150 PartitionBoundSpec *n = makeNode(PartitionBoundSpec);
3151
3152 n->strategy = PARTITION_STRATEGY_HASH;
3153 n->modulus = n->remainder = -1;
3154
3155 foreach (lc, $5)
3156 {
3157 DefElem *opt = lfirst_node(DefElem, lc);
3158
3159 if (strcmp(opt->defname, "modulus") == 0)
3160 {
3161 if (n->modulus != -1)
3162 ereport(ERROR,
3163 (errcode(ERRCODE_DUPLICATE_OBJECT),
3164 errmsg("modulus for hash partition provided more than once"),
3165 parser_errposition(opt->location)));
3166 n->modulus = defGetInt32(opt);
3167 }
3168 else if (strcmp(opt->defname, "remainder") == 0)
3169 {
3170 if (n->remainder != -1)
3171 ereport(ERROR,
3172 (errcode(ERRCODE_DUPLICATE_OBJECT),
3173 errmsg("remainder for hash partition provided more than once"),
3174 parser_errposition(opt->location)));
3175 n->remainder = defGetInt32(opt);
3176 }
3177 else
3178 ereport(ERROR,
3179 (errcode(ERRCODE_SYNTAX_ERROR),
3180 errmsg("unrecognized hash partition bound specification \"%s\"",
3181 opt->defname),
3182 parser_errposition(opt->location)));
3183 }
3184
3185 if (n->modulus == -1)
3186 ereport(ERROR,
3187 (errcode(ERRCODE_SYNTAX_ERROR),
3188 errmsg("modulus for hash partition must be specified"),
3189 parser_errposition(@3)));
3190 if (n->remainder == -1)
3191 ereport(ERROR,
3192 (errcode(ERRCODE_SYNTAX_ERROR),
3193 errmsg("remainder for hash partition must be specified"),
3194 parser_errposition(@3)));
3195
3196 n->location = @3;
3197
3198 $$ = n;
3199 }
3200
3201 /* a LIST partition */
3202 | FOR VALUES IN_P '(' expr_list ')'
3203 {
3204 PartitionBoundSpec *n = makeNode(PartitionBoundSpec);
3205
3206 n->strategy = PARTITION_STRATEGY_LIST;
3207 n->is_default = false;
3208 n->listdatums = $5;
3209 n->location = @3;
3210
3211 $$ = n;
3212 }
3213
3214 /* a RANGE partition */
3215 | FOR VALUES FROM '(' expr_list ')' TO '(' expr_list ')'
3216 {
3217 PartitionBoundSpec *n = makeNode(PartitionBoundSpec);
3218
3219 n->strategy = PARTITION_STRATEGY_RANGE;
3220 n->is_default = false;
3221 n->lowerdatums = $5;
3222 n->upperdatums = $9;
3223 n->location = @3;
3224
3225 $$ = n;
3226 }
3227
3228 /* a DEFAULT partition */
3229 | DEFAULT
3230 {
3231 PartitionBoundSpec *n = makeNode(PartitionBoundSpec);
3232
3233 n->is_default = true;
3234 n->location = @1;
3235
3236 $$ = n;
3237 }
3238 ;
3239
3240 hash_partbound_elem:
3241 NonReservedWord Iconst
3242 {
3243 $$ = makeDefElem($1, (Node *) makeInteger($2), @1);
3244 }
3245 ;
3246
3247 hash_partbound:
3248 hash_partbound_elem
3249 {
3250 $$ = list_make1($1);
3251 }
3252 | hash_partbound ',' hash_partbound_elem
3253 {
3254 $$ = lappend($1, $3);
3255 }
3256 ;
3257
3258 /*****************************************************************************
3259 *
3260 * ALTER TYPE
3261 *
3262 * really variants of the ALTER TABLE subcommands with different spellings
3263 *****************************************************************************/
3264
3265 AlterCompositeTypeStmt:
3266 ALTER TYPE_P any_name alter_type_cmds
3267 {
3268 AlterTableStmt *n = makeNode(AlterTableStmt);
3269
3270 /* can't use qualified_name, sigh */
3271 n->relation = makeRangeVarFromAnyName($3, @3, yyscanner);
3272 n->cmds = $4;
3273 n->objtype = OBJECT_TYPE;
3274 $$ = (Node *) n;
3275 }
3276 ;
3277
3278 alter_type_cmds:
3279 alter_type_cmd { $$ = list_make1($1); }
3280 | alter_type_cmds ',' alter_type_cmd { $$ = lappend($1, $3); }
3281 ;
3282
3283 alter_type_cmd:
3284 /* ALTER TYPE <name> ADD ATTRIBUTE <coldef> [RESTRICT|CASCADE] */
3285 ADD_P ATTRIBUTE TableFuncElement opt_drop_behavior
3286 {
3287 AlterTableCmd *n = makeNode(AlterTableCmd);
3288
3289 n->subtype = AT_AddColumn;
3290 n->def = $3;
3291 n->behavior = $4;
3292 $$ = (Node *) n;
3293 }
3294 /* ALTER TYPE <name> DROP ATTRIBUTE IF EXISTS <attname> [RESTRICT|CASCADE] */
3295 | DROP ATTRIBUTE IF_P EXISTS ColId opt_drop_behavior
3296 {
3297 AlterTableCmd *n = makeNode(AlterTableCmd);
3298
3299 n->subtype = AT_DropColumn;
3300 n->name = $5;
3301 n->behavior = $6;
3302 n->missing_ok = true;
3303 $$ = (Node *) n;
3304 }
3305 /* ALTER TYPE <name> DROP ATTRIBUTE <attname> [RESTRICT|CASCADE] */
3306 | DROP ATTRIBUTE ColId opt_drop_behavior
3307 {
3308 AlterTableCmd *n = makeNode(AlterTableCmd);
3309
3310 n->subtype = AT_DropColumn;
3311 n->name = $3;
3312 n->behavior = $4;
3313 n->missing_ok = false;
3314 $$ = (Node *) n;
3315 }
3316 /* ALTER TYPE <name> ALTER ATTRIBUTE <attname> [SET DATA] TYPE <typename> [RESTRICT|CASCADE] */
3317 | ALTER ATTRIBUTE ColId opt_set_data TYPE_P Typename opt_collate_clause opt_drop_behavior
3318 {
3319 AlterTableCmd *n = makeNode(AlterTableCmd);
3320 ColumnDef *def = makeNode(ColumnDef);
3321
3322 n->subtype = AT_AlterColumnType;
3323 n->name = $3;
3324 n->def = (Node *) def;
3325 n->behavior = $8;
3326 /* We only use these fields of the ColumnDef node */
3327 def->typeName = $6;
3328 def->collClause = (CollateClause *) $7;
3329 def->raw_default = NULL;
3330 def->location = @3;
3331 $$ = (Node *) n;
3332 }
3333 ;
3334
3335
3336 /*****************************************************************************
3337 *
3338 * QUERY :
3339 * close <portalname>
3340 *
3341 *****************************************************************************/
3342
3343 ClosePortalStmt:
3344 CLOSE cursor_name
3345 {
3346 ClosePortalStmt *n = makeNode(ClosePortalStmt);
3347
3348 n->portalname = $2;
3349 $$ = (Node *) n;
3350 }
3351 | CLOSE ALL
3352 {
3353 ClosePortalStmt *n = makeNode(ClosePortalStmt);
3354
3355 n->portalname = NULL;
3356 $$ = (Node *) n;
3357 }
3358 ;
3359
3360
3361 /*****************************************************************************
3362 *
3363 * QUERY :
3364 * COPY relname [(columnList)] FROM/TO file [WITH] [(options)]
3365 * COPY ( query ) TO file [WITH] [(options)]
3366 *
3367 * where 'query' can be one of:
3368 * { SELECT | UPDATE | INSERT | DELETE }
3369 *
3370 * and 'file' can be one of:
3371 * { PROGRAM 'command' | STDIN | STDOUT | 'filename' }
3372 *
3373 * In the preferred syntax the options are comma-separated
3374 * and use generic identifiers instead of keywords. The pre-9.0
3375 * syntax had a hard-wired, space-separated set of options.
3376 *
3377 * Really old syntax, from versions 7.2 and prior:
3378 * COPY [ BINARY ] table FROM/TO file
3379 * [ [ USING ] DELIMITERS 'delimiter' ] ]
3380 * [ WITH NULL AS 'null string' ]
3381 * This option placement is not supported with COPY (query...).
3382 *
3383 *****************************************************************************/
3384
3385 CopyStmt: COPY opt_binary qualified_name opt_column_list
3386 copy_from opt_program copy_file_name copy_delimiter opt_with
3387 copy_options where_clause
3388 {
3389 CopyStmt *n = makeNode(CopyStmt);
3390
3391 n->relation = $3;
3392 n->query = NULL;
3393 n->attlist = $4;
3394 n->is_from = $5;
3395 n->is_program = $6;
3396 n->filename = $7;
3397 n->whereClause = $11;
3398
3399 if (n->is_program && n->filename == NULL)
3400 ereport(ERROR,
3401 (errcode(ERRCODE_SYNTAX_ERROR),
3402 errmsg("STDIN/STDOUT not allowed with PROGRAM"),
3403 parser_errposition(@8)));
3404
3405 if (!n->is_from && n->whereClause != NULL)
3406 ereport(ERROR,
3407 (errcode(ERRCODE_SYNTAX_ERROR),
3408 errmsg("WHERE clause not allowed with COPY TO"),
3409 parser_errposition(@11)));
3410
3411 n->options = NIL;
3412 /* Concatenate user-supplied flags */
3413 if ($2)
3414 n->options = lappend(n->options, $2);
3415 if ($8)
3416 n->options = lappend(n->options, $8);
3417 if ($10)
3418 n->options = list_concat(n->options, $10);
3419 $$ = (Node *) n;
3420 }
3421 | COPY '(' PreparableStmt ')' TO opt_program copy_file_name opt_with copy_options
3422 {
3423 CopyStmt *n = makeNode(CopyStmt);
3424
3425 n->relation = NULL;
3426 n->query = $3;
3427 n->attlist = NIL;
3428 n->is_from = false;
3429 n->is_program = $6;
3430 n->filename = $7;
3431 n->options = $9;
3432
3433 if (n->is_program && n->filename == NULL)
3434 ereport(ERROR,
3435 (errcode(ERRCODE_SYNTAX_ERROR),
3436 errmsg("STDIN/STDOUT not allowed with PROGRAM"),
3437 parser_errposition(@5)));
3438
3439 $$ = (Node *) n;
3440 }
3441 ;
3442
3443 copy_from:
3444 FROM { $$ = true; }
3445 | TO { $$ = false; }
3446 ;
3447
3448 opt_program:
3449 PROGRAM { $$ = true; }
3450 | /* EMPTY */ { $$ = false; }
3451 ;
3452
3453 /*
3454 * copy_file_name NULL indicates stdio is used. Whether stdin or stdout is
3455 * used depends on the direction. (It really doesn't make sense to copy from
3456 * stdout. We silently correct the "typo".) - AY 9/94
3457 */
3458 copy_file_name:
3459 Sconst { $$ = $1; }
3460 | STDIN { $$ = NULL; }
3461 | STDOUT { $$ = NULL; }
3462 ;
3463
3464 copy_options: copy_opt_list { $$ = $1; }
3465 | '(' copy_generic_opt_list ')' { $$ = $2; }
3466 ;
3467
3468 /* old COPY option syntax */
3469 copy_opt_list:
3470 copy_opt_list copy_opt_item { $$ = lappend($1, $2); }
3471 | /* EMPTY */ { $$ = NIL; }
3472 ;
3473
3474 copy_opt_item:
3475 BINARY
3476 {
3477 $$ = makeDefElem("format", (Node *) makeString("binary"), @1);
3478 }
3479 | FREEZE
3480 {
3481 $$ = makeDefElem("freeze", (Node *) makeBoolean(true), @1);
3482 }
3483 | DELIMITER opt_as Sconst
3484 {
3485 $$ = makeDefElem("delimiter", (Node *) makeString($3), @1);
3486 }
3487 | NULL_P opt_as Sconst
3488 {
3489 $$ = makeDefElem("null", (Node *) makeString($3), @1);
3490 }
3491 | CSV
3492 {
3493 $$ = makeDefElem("format", (Node *) makeString("csv"), @1);
3494 }
3495 | HEADER_P
3496 {
3497 $$ = makeDefElem("header", (Node *) makeBoolean(true), @1);
3498 }
3499 | QUOTE opt_as Sconst
3500 {
3501 $$ = makeDefElem("quote", (Node *) makeString($3), @1);
3502 }
3503 | ESCAPE opt_as Sconst
3504 {
3505 $$ = makeDefElem("escape", (Node *) makeString($3), @1);
3506 }
3507 | FORCE QUOTE columnList
3508 {
3509 $$ = makeDefElem("force_quote", (Node *) $3, @1);
3510 }
3511 | FORCE QUOTE '*'
3512 {
3513 $$ = makeDefElem("force_quote", (Node *) makeNode(A_Star), @1);
3514 }
3515 | FORCE NOT NULL_P columnList
3516 {
3517 $$ = makeDefElem("force_not_null", (Node *) $4, @1);
3518 }
3519 | FORCE NOT NULL_P '*'
3520 {
3521 $$ = makeDefElem("force_not_null", (Node *) makeNode(A_Star), @1);
3522 }
3523 | FORCE NULL_P columnList
3524 {
3525 $$ = makeDefElem("force_null", (Node *) $3, @1);
3526 }
3527 | FORCE NULL_P '*'
3528 {
3529 $$ = makeDefElem("force_null", (Node *) makeNode(A_Star), @1);
3530 }
3531 | ENCODING Sconst
3532 {
3533 $$ = makeDefElem("encoding", (Node *) makeString($2), @1);
3534 }
3535 ;
3536
3537 /* The following exist for backward compatibility with very old versions */
3538
3539 opt_binary:
3540 BINARY
3541 {
3542 $$ = makeDefElem("format", (Node *) makeString("binary"), @1);
3543 }
3544 | /*EMPTY*/ { $$ = NULL; }
3545 ;
3546
3547 copy_delimiter:
3548 opt_using DELIMITERS Sconst
3549 {
3550 $$ = makeDefElem("delimiter", (Node *) makeString($3), @2);
3551 }
3552 | /*EMPTY*/ { $$ = NULL; }
3553 ;
3554
3555 opt_using:
3556 USING
3557 | /*EMPTY*/
3558 ;
3559
3560 /* new COPY option syntax */
3561 copy_generic_opt_list:
3562 copy_generic_opt_elem
3563 {
3564 $$ = list_make1($1);
3565 }
3566 | copy_generic_opt_list ',' copy_generic_opt_elem
3567 {
3568 $$ = lappend($1, $3);
3569 }
3570 ;
3571
3572 copy_generic_opt_elem:
3573 ColLabel copy_generic_opt_arg
3574 {
3575 $$ = makeDefElem($1, $2, @1);
3576 }
3577 ;
3578
3579 copy_generic_opt_arg:
3580 opt_boolean_or_string { $$ = (Node *) makeString($1); }
3581 | NumericOnly { $$ = (Node *) $1; }
3582 | '*' { $$ = (Node *) makeNode(A_Star); }
3583 | DEFAULT { $$ = (Node *) makeString("default"); }
3584 | '(' copy_generic_opt_arg_list ')' { $$ = (Node *) $2; }
3585 | /* EMPTY */ { $$ = NULL; }
3586 ;
3587
3588 copy_generic_opt_arg_list:
3589 copy_generic_opt_arg_list_item
3590 {
3591 $$ = list_make1($1);
3592 }
3593 | copy_generic_opt_arg_list ',' copy_generic_opt_arg_list_item
3594 {
3595 $$ = lappend($1, $3);
3596 }
3597 ;
3598
3599 /* beware of emitting non-string list elements here; see commands/define.c */
3600 copy_generic_opt_arg_list_item:
3601 opt_boolean_or_string { $$ = (Node *) makeString($1); }
3602 ;
3603
3604
3605 /*****************************************************************************
3606 *
3607 * QUERY :
3608 * CREATE TABLE relname
3609 *
3610 *****************************************************************************/
3611
3612 CreateStmt: CREATE OptTemp TABLE qualified_name '(' OptTableElementList ')'
3613 OptInherit OptPartitionSpec table_access_method_clause OptWith
3614 OnCommitOption OptTableSpace
3615 {
3616 CreateStmt *n = makeNode(CreateStmt);
3617
3618 $4->relpersistence = $2;
3619 n->relation = $4;
3620 n->tableElts = $6;
3621 n->inhRelations = $8;
3622 n->partspec = $9;
3623 n->ofTypename = NULL;
3624 n->constraints = NIL;
3625 n->accessMethod = $10;
3626 n->options = $11;
3627 n->oncommit = $12;
3628 n->tablespacename = $13;
3629 n->if_not_exists = false;
3630 $$ = (Node *) n;
3631 }
3632 | CREATE OptTemp TABLE IF_P NOT EXISTS qualified_name '('
3633 OptTableElementList ')' OptInherit OptPartitionSpec table_access_method_clause
3634 OptWith OnCommitOption OptTableSpace
3635 {
3636 CreateStmt *n = makeNode(CreateStmt);
3637
3638 $7->relpersistence = $2;
3639 n->relation = $7;
3640 n->tableElts = $9;
3641 n->inhRelations = $11;
3642 n->partspec = $12;
3643 n->ofTypename = NULL;
3644 n->constraints = NIL;
3645 n->accessMethod = $13;
3646 n->options = $14;
3647 n->oncommit = $15;
3648 n->tablespacename = $16;
3649 n->if_not_exists = true;
3650 $$ = (Node *) n;
3651 }
3652 | CREATE OptTemp TABLE qualified_name OF any_name
3653 OptTypedTableElementList OptPartitionSpec table_access_method_clause
3654 OptWith OnCommitOption OptTableSpace
3655 {
3656 CreateStmt *n = makeNode(CreateStmt);
3657
3658 $4->relpersistence = $2;
3659 n->relation = $4;
3660 n->tableElts = $7;
3661 n->inhRelations = NIL;
3662 n->partspec = $8;
3663 n->ofTypename = makeTypeNameFromNameList($6);
3664 n->ofTypename->location = @6;
3665 n->constraints = NIL;
3666 n->accessMethod = $9;
3667 n->options = $10;
3668 n->oncommit = $11;
3669 n->tablespacename = $12;
3670 n->if_not_exists = false;
3671 $$ = (Node *) n;
3672 }
3673 | CREATE OptTemp TABLE IF_P NOT EXISTS qualified_name OF any_name
3674 OptTypedTableElementList OptPartitionSpec table_access_method_clause
3675 OptWith OnCommitOption OptTableSpace
3676 {
3677 CreateStmt *n = makeNode(CreateStmt);
3678
3679 $7->relpersistence = $2;
3680 n->relation = $7;
3681 n->tableElts = $10;
3682 n->inhRelations = NIL;
3683 n->partspec = $11;
3684 n->ofTypename = makeTypeNameFromNameList($9);
3685 n->ofTypename->location = @9;
3686 n->constraints = NIL;
3687 n->accessMethod = $12;
3688 n->options = $13;
3689 n->oncommit = $14;
3690 n->tablespacename = $15;
3691 n->if_not_exists = true;
3692 $$ = (Node *) n;
3693 }
3694 | CREATE OptTemp TABLE qualified_name PARTITION OF qualified_name
3695 OptTypedTableElementList PartitionBoundSpec OptPartitionSpec
3696 table_access_method_clause OptWith OnCommitOption OptTableSpace
3697 {
3698 CreateStmt *n = makeNode(CreateStmt);
3699
3700 $4->relpersistence = $2;
3701 n->relation = $4;
3702 n->tableElts = $8;
3703 n->inhRelations = list_make1($7);
3704 n->partbound = $9;
3705 n->partspec = $10;
3706 n->ofTypename = NULL;
3707 n->constraints = NIL;
3708 n->accessMethod = $11;
3709 n->options = $12;
3710 n->oncommit = $13;
3711 n->tablespacename = $14;
3712 n->if_not_exists = false;
3713 $$ = (Node *) n;
3714 }
3715 | CREATE OptTemp TABLE IF_P NOT EXISTS qualified_name PARTITION OF
3716 qualified_name OptTypedTableElementList PartitionBoundSpec OptPartitionSpec
3717 table_access_method_clause OptWith OnCommitOption OptTableSpace
3718 {
3719 CreateStmt *n = makeNode(CreateStmt);
3720
3721 $7->relpersistence = $2;
3722 n->relation = $7;
3723 n->tableElts = $11;
3724 n->inhRelations = list_make1($10);
3725 n->partbound = $12;
3726 n->partspec = $13;
3727 n->ofTypename = NULL;
3728 n->constraints = NIL;
3729 n->accessMethod = $14;
3730 n->options = $15;
3731 n->oncommit = $16;
3732 n->tablespacename = $17;
3733 n->if_not_exists = true;
3734 $$ = (Node *) n;
3735 }
3736 ;
3737
3738 /*
3739 * Redundancy here is needed to avoid shift/reduce conflicts,
3740 * since TEMP is not a reserved word. See also OptTempTableName.
3741 *
3742 * NOTE: we accept both GLOBAL and LOCAL options. They currently do nothing,
3743 * but future versions might consider GLOBAL to request SQL-spec-compliant
3744 * temp table behavior, so warn about that. Since we have no modules the
3745 * LOCAL keyword is really meaningless; furthermore, some other products
3746 * implement LOCAL as meaning the same as our default temp table behavior,
3747 * so we'll probably continue to treat LOCAL as a noise word.
3748 */
3749 OptTemp: TEMPORARY { $$ = RELPERSISTENCE_TEMP; }
3750 | TEMP { $$ = RELPERSISTENCE_TEMP; }
3751 | LOCAL TEMPORARY { $$ = RELPERSISTENCE_TEMP; }
3752 | LOCAL TEMP { $$ = RELPERSISTENCE_TEMP; }
3753 | GLOBAL TEMPORARY
3754 {
3755 ereport(WARNING,
3756 (errmsg("GLOBAL is deprecated in temporary table creation"),
3757 parser_errposition(@1)));
3758 $$ = RELPERSISTENCE_TEMP;
3759 }
3760 | GLOBAL TEMP
3761 {
3762 ereport(WARNING,
3763 (errmsg("GLOBAL is deprecated in temporary table creation"),
3764 parser_errposition(@1)));
3765 $$ = RELPERSISTENCE_TEMP;
3766 }
3767 | UNLOGGED { $$ = RELPERSISTENCE_UNLOGGED; }
3768 | /*EMPTY*/ { $$ = RELPERSISTENCE_PERMANENT; }
3769 ;
3770
3771 OptTableElementList:
3772 TableElementList { $$ = $1; }
3773 | /*EMPTY*/ { $$ = NIL; }
3774 ;
3775
3776 OptTypedTableElementList:
3777 '(' TypedTableElementList ')' { $$ = $2; }
3778 | /*EMPTY*/ { $$ = NIL; }
3779 ;
3780
3781 TableElementList:
3782 TableElement
3783 {
3784 $$ = list_make1($1);
3785 }
3786 | TableElementList ',' TableElement
3787 {
3788 $$ = lappend($1, $3);
3789 }
3790 ;
3791
3792 TypedTableElementList:
3793 TypedTableElement
3794 {
3795 $$ = list_make1($1);
3796 }
3797 | TypedTableElementList ',' TypedTableElement
3798 {
3799 $$ = lappend($1, $3);
3800 }
3801 ;
3802
3803 TableElement:
3804 columnDef { $$ = $1; }
3805 | TableLikeClause { $$ = $1; }
3806 | TableConstraint { $$ = $1; }
3807 ;
3808
3809 TypedTableElement:
3810 columnOptions { $$ = $1; }
3811 | TableConstraint { $$ = $1; }
3812 ;
3813
3814 columnDef: ColId Typename opt_column_storage opt_column_compression create_generic_options ColQualList
3815 {
3816 ColumnDef *n = makeNode(ColumnDef);
3817
3818 n->colname = $1;
3819 n->typeName = $2;
3820 n->storage_name = $3;
3821 n->compression = $4;
3822 n->inhcount = 0;
3823 n->is_local = true;
3824 n->is_not_null = false;
3825 n->is_from_type = false;
3826 n->storage = 0;
3827 n->raw_default = NULL;
3828 n->cooked_default = NULL;
3829 n->collOid = InvalidOid;
3830 n->fdwoptions = $5;
3831 SplitColQualList($6, &n->constraints, &n->collClause,
3832 yyscanner);
3833 n->location = @1;
3834 $$ = (Node *) n;
3835 }
3836 ;
3837
3838 columnOptions: ColId ColQualList
3839 {
3840 ColumnDef *n = makeNode(ColumnDef);
3841
3842 n->colname = $1;
3843 n->typeName = NULL;
3844 n->inhcount = 0;
3845 n->is_local = true;
3846 n->is_not_null = false;
3847 n->is_from_type = false;
3848 n->storage = 0;
3849 n->raw_default = NULL;
3850 n->cooked_default = NULL;
3851 n->collOid = InvalidOid;
3852 SplitColQualList($2, &n->constraints, &n->collClause,
3853 yyscanner);
3854 n->location = @1;
3855 $$ = (Node *) n;
3856 }
3857 | ColId WITH OPTIONS ColQualList
3858 {
3859 ColumnDef *n = makeNode(ColumnDef);
3860
3861 n->colname = $1;
3862 n->typeName = NULL;
3863 n->inhcount = 0;
3864 n->is_local = true;
3865 n->is_not_null = false;
3866 n->is_from_type = false;
3867 n->storage = 0;
3868 n->raw_default = NULL;
3869 n->cooked_default = NULL;
3870 n->collOid = InvalidOid;
3871 SplitColQualList($4, &n->constraints, &n->collClause,
3872 yyscanner);
3873 n->location = @1;
3874 $$ = (Node *) n;
3875 }
3876 ;
3877
3878 column_compression:
3879 COMPRESSION ColId { $$ = $2; }
3880 | COMPRESSION DEFAULT { $$ = pstrdup("default"); }
3881 ;
3882
3883 opt_column_compression:
3884 column_compression { $$ = $1; }
3885 | /*EMPTY*/ { $$ = NULL; }
3886 ;
3887
3888 column_storage:
3889 STORAGE ColId { $$ = $2; }
3890 | STORAGE DEFAULT { $$ = pstrdup("default"); }
3891 ;
3892
3893 opt_column_storage:
3894 column_storage { $$ = $1; }
3895 | /*EMPTY*/ { $$ = NULL; }
3896 ;
3897
3898 ColQualList:
3899 ColQualList ColConstraint { $$ = lappend($1, $2); }
3900 | /*EMPTY*/ { $$ = NIL; }
3901 ;
3902
3903 ColConstraint:
3904 CONSTRAINT name ColConstraintElem
3905 {
3906 Constraint *n = castNode(Constraint, $3);
3907
3908 n->conname = $2;
3909 n->location = @1;
3910 $$ = (Node *) n;
3911 }
3912 | ColConstraintElem { $$ = $1; }
3913 | ConstraintAttr { $$ = $1; }
3914 | COLLATE any_name
3915 {
3916 /*
3917 * Note: the CollateClause is momentarily included in
3918 * the list built by ColQualList, but we split it out
3919 * again in SplitColQualList.
3920 */
3921 CollateClause *n = makeNode(CollateClause);
3922
3923 n->arg = NULL;
3924 n->collname = $2;
3925 n->location = @1;
3926 $$ = (Node *) n;
3927 }
3928 ;
3929
3930 /* DEFAULT NULL is already the default for Postgres.
3931 * But define it here and carry it forward into the system
3932 * to make it explicit.
3933 * - thomas 1998-09-13
3934 *
3935 * WITH NULL and NULL are not SQL-standard syntax elements,
3936 * so leave them out. Use DEFAULT NULL to explicitly indicate
3937 * that a column may have that value. WITH NULL leads to
3938 * shift/reduce conflicts with WITH TIME ZONE anyway.
3939 * - thomas 1999-01-08
3940 *
3941 * DEFAULT expression must be b_expr not a_expr to prevent shift/reduce
3942 * conflict on NOT (since NOT might start a subsequent NOT NULL constraint,
3943 * or be part of a_expr NOT LIKE or similar constructs).
3944 */
3945 ColConstraintElem:
3946 NOT NULL_P opt_no_inherit
3947 {
3948 Constraint *n = makeNode(Constraint);
3949
3950 n->contype = CONSTR_NOTNULL;
3951 n->location = @1;
3952 n->is_no_inherit = $3;
3953 n->is_enforced = true;
3954 n->skip_validation = false;
3955 n->initially_valid = true;
3956 $$ = (Node *) n;
3957 }
3958 | NULL_P
3959 {
3960 Constraint *n = makeNode(Constraint);
3961
3962 n->contype = CONSTR_NULL;
3963 n->location = @1;
3964 $$ = (Node *) n;
3965 }
3966 | UNIQUE opt_unique_null_treatment opt_definition OptConsTableSpace
3967 {
3968 Constraint *n = makeNode(Constraint);
3969
3970 n->contype = CONSTR_UNIQUE;
3971 n->location = @1;
3972 n->nulls_not_distinct = !$2;
3973 n->keys = NULL;
3974 n->options = $3;
3975 n->indexname = NULL;
3976 n->indexspace = $4;
3977 $$ = (Node *) n;
3978 }
3979 | PRIMARY KEY opt_definition OptConsTableSpace
3980 {
3981 Constraint *n = makeNode(Constraint);
3982
3983 n->contype = CONSTR_PRIMARY;
3984 n->location = @1;
3985 n->keys = NULL;
3986 n->options = $3;
3987 n->indexname = NULL;
3988 n->indexspace = $4;
3989 $$ = (Node *) n;
3990 }
3991 | CHECK '(' a_expr ')' opt_no_inherit
3992 {
3993 Constraint *n = makeNode(Constraint);
3994
3995 n->contype = CONSTR_CHECK;
3996 n->location = @1;
3997 n->is_no_inherit = $5;
3998 n->raw_expr = $3;
3999 n->cooked_expr = NULL;
4000 n->is_enforced = true;
4001 n->skip_validation = false;
4002 n->initially_valid = true;
4003 $$ = (Node *) n;
4004 }
4005 | DEFAULT b_expr
4006 {
4007 Constraint *n = makeNode(Constraint);
4008
4009 n->contype = CONSTR_DEFAULT;
4010 n->location = @1;
4011 n->raw_expr = $2;
4012 n->cooked_expr = NULL;
4013 $$ = (Node *) n;
4014 }
4015 | GENERATED generated_when AS IDENTITY_P OptParenthesizedSeqOptList
4016 {
4017 Constraint *n = makeNode(Constraint);
4018
4019 n->contype = CONSTR_IDENTITY;
4020 n->generated_when = $2;
4021 n->options = $5;
4022 n->location = @1;
4023 $$ = (Node *) n;
4024 }
4025 | GENERATED generated_when AS '(' a_expr ')' opt_virtual_or_stored
4026 {
4027 Constraint *n = makeNode(Constraint);
4028
4029 n->contype = CONSTR_GENERATED;
4030 n->generated_when = $2;
4031 n->raw_expr = $5;
4032 n->cooked_expr = NULL;
4033 n->generated_kind = $7;
4034 n->location = @1;
4035
4036 /*
4037 * Can't do this in the grammar because of shift/reduce
4038 * conflicts. (IDENTITY allows both ALWAYS and BY
4039 * DEFAULT, but generated columns only allow ALWAYS.) We
4040 * can also give a more useful error message and location.
4041 */
4042 if ($2 != ATTRIBUTE_IDENTITY_ALWAYS)
4043 ereport(ERROR,
4044 (errcode(ERRCODE_SYNTAX_ERROR),
4045 errmsg("for a generated column, GENERATED ALWAYS must be specified"),
4046 parser_errposition(@2)));
4047
4048 $$ = (Node *) n;
4049 }
4050 | REFERENCES qualified_name opt_column_list key_match key_actions
4051 {
4052 Constraint *n = makeNode(Constraint);
4053
4054 n->contype = CONSTR_FOREIGN;
4055 n->location = @1;
4056 n->pktable = $2;
4057 n->fk_attrs = NIL;
4058 n->pk_attrs = $3;
4059 n->fk_matchtype = $4;
4060 n->fk_upd_action = ($5)->updateAction->action;
4061 n->fk_del_action = ($5)->deleteAction->action;
4062 n->fk_del_set_cols = ($5)->deleteAction->cols;
4063 n->is_enforced = true;
4064 n->skip_validation = false;
4065 n->initially_valid = true;
4066 $$ = (Node *) n;
4067 }
4068 ;
4069
4070 opt_unique_null_treatment:
4071 NULLS_P DISTINCT { $$ = true; }
4072 | NULLS_P NOT DISTINCT { $$ = false; }
4073 | /*EMPTY*/ { $$ = true; }
4074 ;
4075
4076 generated_when:
4077 ALWAYS { $$ = ATTRIBUTE_IDENTITY_ALWAYS; }
4078 | BY DEFAULT { $$ = ATTRIBUTE_IDENTITY_BY_DEFAULT; }
4079 ;
4080
4081 opt_virtual_or_stored:
4082 STORED { $$ = ATTRIBUTE_GENERATED_STORED; }
4083 | VIRTUAL { $$ = ATTRIBUTE_GENERATED_VIRTUAL; }
4084 | /*EMPTY*/ { $$ = ATTRIBUTE_GENERATED_VIRTUAL; }
4085 ;
4086
4087 /*
4088 * ConstraintAttr represents constraint attributes, which we parse as if
4089 * they were independent constraint clauses, in order to avoid shift/reduce
4090 * conflicts (since NOT might start either an independent NOT NULL clause
4091 * or an attribute). parse_utilcmd.c is responsible for attaching the
4092 * attribute information to the preceding "real" constraint node, and for
4093 * complaining if attribute clauses appear in the wrong place or wrong
4094 * combinations.
4095 *
4096 * See also ConstraintAttributeSpec, which can be used in places where
4097 * there is no parsing conflict. (Note: currently, NOT VALID and NO INHERIT
4098 * are allowed clauses in ConstraintAttributeSpec, but not here. Someday we
4099 * might need to allow them here too, but for the moment it doesn't seem
4100 * useful in the statements that use ConstraintAttr.)
4101 */
4102 ConstraintAttr:
4103 DEFERRABLE
4104 {
4105 Constraint *n = makeNode(Constraint);
4106
4107 n->contype = CONSTR_ATTR_DEFERRABLE;
4108 n->location = @1;
4109 $$ = (Node *) n;
4110 }
4111 | NOT DEFERRABLE
4112 {
4113 Constraint *n = makeNode(Constraint);
4114
4115 n->contype = CONSTR_ATTR_NOT_DEFERRABLE;
4116 n->location = @1;
4117 $$ = (Node *) n;
4118 }
4119 | INITIALLY DEFERRED
4120 {
4121 Constraint *n = makeNode(Constraint);
4122
4123 n->contype = CONSTR_ATTR_DEFERRED;
4124 n->location = @1;
4125 $$ = (Node *) n;
4126 }
4127 | INITIALLY IMMEDIATE
4128 {
4129 Constraint *n = makeNode(Constraint);
4130
4131 n->contype = CONSTR_ATTR_IMMEDIATE;
4132 n->location = @1;
4133 $$ = (Node *) n;
4134 }
4135 | ENFORCED
4136 {
4137 Constraint *n = makeNode(Constraint);
4138
4139 n->contype = CONSTR_ATTR_ENFORCED;
4140 n->location = @1;
4141 $$ = (Node *) n;
4142 }
4143 | NOT ENFORCED
4144 {
4145 Constraint *n = makeNode(Constraint);
4146
4147 n->contype = CONSTR_ATTR_NOT_ENFORCED;
4148 n->location = @1;
4149 $$ = (Node *) n;
4150 }
4151 ;
4152
4153
4154 TableLikeClause:
4155 LIKE qualified_name TableLikeOptionList
4156 {
4157 TableLikeClause *n = makeNode(TableLikeClause);
4158
4159 n->relation = $2;
4160 n->options = $3;
4161 n->relationOid = InvalidOid;
4162 $$ = (Node *) n;
4163 }
4164 ;
4165
4166 TableLikeOptionList:
4167 TableLikeOptionList INCLUDING TableLikeOption { $$ = $1 | $3; }
4168 | TableLikeOptionList EXCLUDING TableLikeOption { $$ = $1 & ~$3; }
4169 | /* EMPTY */ { $$ = 0; }
4170 ;
4171
4172 TableLikeOption:
4173 COMMENTS { $$ = CREATE_TABLE_LIKE_COMMENTS; }
4174 | COMPRESSION { $$ = CREATE_TABLE_LIKE_COMPRESSION; }
4175 | CONSTRAINTS { $$ = CREATE_TABLE_LIKE_CONSTRAINTS; }
4176 | DEFAULTS { $$ = CREATE_TABLE_LIKE_DEFAULTS; }
4177 | IDENTITY_P { $$ = CREATE_TABLE_LIKE_IDENTITY; }
4178 | GENERATED { $$ = CREATE_TABLE_LIKE_GENERATED; }
4179 | INDEXES { $$ = CREATE_TABLE_LIKE_INDEXES; }
4180 | STATISTICS { $$ = CREATE_TABLE_LIKE_STATISTICS; }
4181 | STORAGE { $$ = CREATE_TABLE_LIKE_STORAGE; }
4182 | ALL { $$ = CREATE_TABLE_LIKE_ALL; }
4183 ;
4184
4185
4186 /* ConstraintElem specifies constraint syntax which is not embedded into
4187 * a column definition. ColConstraintElem specifies the embedded form.
4188 * - thomas 1997-12-03
4189 */
4190 TableConstraint:
4191 CONSTRAINT name ConstraintElem
4192 {
4193 Constraint *n = castNode(Constraint, $3);
4194
4195 n->conname = $2;
4196 n->location = @1;
4197 $$ = (Node *) n;
4198 }
4199 | ConstraintElem { $$ = $1; }
4200 ;
4201
4202 ConstraintElem:
4203 CHECK '(' a_expr ')' ConstraintAttributeSpec
4204 {
4205 Constraint *n = makeNode(Constraint);
4206
4207 n->contype = CONSTR_CHECK;
4208 n->location = @1;
4209 n->raw_expr = $3;
4210 n->cooked_expr = NULL;
4211 processCASbits($5, @5, "CHECK",
4212 NULL, NULL, &n->is_enforced, &n->skip_validation,
4213 &n->is_no_inherit, yyscanner);
4214 n->initially_valid = !n->skip_validation;
4215 $$ = (Node *) n;
4216 }
4217 | NOT NULL_P ColId ConstraintAttributeSpec
4218 {
4219 Constraint *n = makeNode(Constraint);
4220
4221 n->contype = CONSTR_NOTNULL;
4222 n->location = @1;
4223 n->keys = list_make1(makeString($3));
4224 processCASbits($4, @4, "NOT NULL",
4225 NULL, NULL, NULL, &n->skip_validation,
4226 &n->is_no_inherit, yyscanner);
4227 n->initially_valid = !n->skip_validation;
4228 $$ = (Node *) n;
4229 }
4230 | UNIQUE opt_unique_null_treatment '(' columnList opt_without_overlaps ')' opt_c_include opt_definition OptConsTableSpace
4231 ConstraintAttributeSpec
4232 {
4233 Constraint *n = makeNode(Constraint);
4234
4235 n->contype = CONSTR_UNIQUE;
4236 n->location = @1;
4237 n->nulls_not_distinct = !$2;
4238 n->keys = $4;
4239 n->without_overlaps = $5;
4240 n->including = $7;
4241 n->options = $8;
4242 n->indexname = NULL;
4243 n->indexspace = $9;
4244 processCASbits($10, @10, "UNIQUE",
4245 &n->deferrable, &n->initdeferred, NULL,
4246 NULL, NULL, yyscanner);
4247 $$ = (Node *) n;
4248 }
4249 | UNIQUE ExistingIndex ConstraintAttributeSpec
4250 {
4251 Constraint *n = makeNode(Constraint);
4252
4253 n->contype = CONSTR_UNIQUE;
4254 n->location = @1;
4255 n->keys = NIL;
4256 n->including = NIL;
4257 n->options = NIL;
4258 n->indexname = $2;
4259 n->indexspace = NULL;
4260 processCASbits($3, @3, "UNIQUE",
4261 &n->deferrable, &n->initdeferred, NULL,
4262 NULL, NULL, yyscanner);
4263 $$ = (Node *) n;
4264 }
4265 | PRIMARY KEY '(' columnList opt_without_overlaps ')' opt_c_include opt_definition OptConsTableSpace
4266 ConstraintAttributeSpec
4267 {
4268 Constraint *n = makeNode(Constraint);
4269
4270 n->contype = CONSTR_PRIMARY;
4271 n->location = @1;
4272 n->keys = $4;
4273 n->without_overlaps = $5;
4274 n->including = $7;
4275 n->options = $8;
4276 n->indexname = NULL;
4277 n->indexspace = $9;
4278 processCASbits($10, @10, "PRIMARY KEY",
4279 &n->deferrable, &n->initdeferred, NULL,
4280 NULL, NULL, yyscanner);
4281 $$ = (Node *) n;
4282 }
4283 | PRIMARY KEY ExistingIndex ConstraintAttributeSpec
4284 {
4285 Constraint *n = makeNode(Constraint);
4286
4287 n->contype = CONSTR_PRIMARY;
4288 n->location = @1;
4289 n->keys = NIL;
4290 n->including = NIL;
4291 n->options = NIL;
4292 n->indexname = $3;
4293 n->indexspace = NULL;
4294 processCASbits($4, @4, "PRIMARY KEY",
4295 &n->deferrable, &n->initdeferred, NULL,
4296 NULL, NULL, yyscanner);
4297 $$ = (Node *) n;
4298 }
4299 | EXCLUDE access_method_clause '(' ExclusionConstraintList ')'
4300 opt_c_include opt_definition OptConsTableSpace OptWhereClause
4301 ConstraintAttributeSpec
4302 {
4303 Constraint *n = makeNode(Constraint);
4304
4305 n->contype = CONSTR_EXCLUSION;
4306 n->location = @1;
4307 n->access_method = $2;
4308 n->exclusions = $4;
4309 n->including = $6;
4310 n->options = $7;
4311 n->indexname = NULL;
4312 n->indexspace = $8;
4313 n->where_clause = $9;
4314 processCASbits($10, @10, "EXCLUDE",
4315 &n->deferrable, &n->initdeferred, NULL,
4316 NULL, NULL, yyscanner);
4317 $$ = (Node *) n;
4318 }
4319 | FOREIGN KEY '(' columnList optionalPeriodName ')' REFERENCES qualified_name
4320 opt_column_and_period_list key_match key_actions ConstraintAttributeSpec
4321 {
4322 Constraint *n = makeNode(Constraint);
4323
4324 n->contype = CONSTR_FOREIGN;
4325 n->location = @1;
4326 n->pktable = $8;
4327 n->fk_attrs = $4;
4328 if ($5)
4329 {
4330 n->fk_attrs = lappend(n->fk_attrs, $5);
4331 n->fk_with_period = true;
4332 }
4333 n->pk_attrs = linitial($9);
4334 if (lsecond($9))
4335 {
4336 n->pk_attrs = lappend(n->pk_attrs, lsecond($9));
4337 n->pk_with_period = true;
4338 }
4339 n->fk_matchtype = $10;
4340 n->fk_upd_action = ($11)->updateAction->action;
4341 n->fk_del_action = ($11)->deleteAction->action;
4342 n->fk_del_set_cols = ($11)->deleteAction->cols;
4343 processCASbits($12, @12, "FOREIGN KEY",
4344 &n->deferrable, &n->initdeferred,
4345 &n->is_enforced, &n->skip_validation, NULL,
4346 yyscanner);
4347 n->initially_valid = !n->skip_validation;
4348 $$ = (Node *) n;
4349 }
4350 ;
4351
4352 /*
4353 * DomainConstraint is separate from TableConstraint because the syntax for
4354 * NOT NULL constraints is different. For table constraints, we need to
4355 * accept a column name, but for domain constraints, we don't. (We could
4356 * accept something like NOT NULL VALUE, but that seems weird.) CREATE DOMAIN
4357 * (which uses ColQualList) has for a long time accepted NOT NULL without a
4358 * column name, so it makes sense that ALTER DOMAIN (which uses
4359 * DomainConstraint) does as well. None of these syntaxes are per SQL
4360 * standard; we are just living with the bits of inconsistency that have built
4361 * up over time.
4362 */
4363 DomainConstraint:
4364 CONSTRAINT name DomainConstraintElem
4365 {
4366 Constraint *n = castNode(Constraint, $3);
4367
4368 n->conname = $2;
4369 n->location = @1;
4370 $$ = (Node *) n;
4371 }
4372 | DomainConstraintElem { $$ = $1; }
4373 ;
4374
4375 DomainConstraintElem:
4376 CHECK '(' a_expr ')' ConstraintAttributeSpec
4377 {
4378 Constraint *n = makeNode(Constraint);
4379
4380 n->contype = CONSTR_CHECK;
4381 n->location = @1;
4382 n->raw_expr = $3;
4383 n->cooked_expr = NULL;
4384 processCASbits($5, @5, "CHECK",
4385 NULL, NULL, NULL, &n->skip_validation,
4386 &n->is_no_inherit, yyscanner);
4387 n->is_enforced = true;
4388 n->initially_valid = !n->skip_validation;
4389 $$ = (Node *) n;
4390 }
4391 | NOT NULL_P ConstraintAttributeSpec
4392 {
4393 Constraint *n = makeNode(Constraint);
4394
4395 n->contype = CONSTR_NOTNULL;
4396 n->location = @1;
4397 n->keys = list_make1(makeString("value"));
4398 /* no NOT VALID, NO INHERIT support */
4399 processCASbits($3, @3, "NOT NULL",
4400 NULL, NULL, NULL,
4401 NULL, NULL, yyscanner);
4402 n->initially_valid = true;
4403 $$ = (Node *) n;
4404 }
4405 ;
4406
4407 opt_no_inherit: NO INHERIT { $$ = true; }
4408 | /* EMPTY */ { $$ = false; }
4409 ;
4410
4411 opt_without_overlaps:
4412 WITHOUT OVERLAPS { $$ = true; }
4413 | /*EMPTY*/ { $$ = false; }
4414 ;
4415
4416 opt_column_list:
4417 '(' columnList ')' { $$ = $2; }
4418 | /*EMPTY*/ { $$ = NIL; }
4419 ;
4420
4421 columnList:
4422 columnElem { $$ = list_make1($1); }
4423 | columnList ',' columnElem { $$ = lappend($1, $3); }
4424 ;
4425
4426 optionalPeriodName:
4427 ',' PERIOD columnElem { $$ = $3; }
4428 | /*EMPTY*/ { $$ = NULL; }
4429 ;
4430
4431 opt_column_and_period_list:
4432 '(' columnList optionalPeriodName ')' { $$ = list_make2($2, $3); }
4433 | /*EMPTY*/ { $$ = list_make2(NIL, NULL); }
4434 ;
4435
4436 columnElem: ColId
4437 {
4438 $$ = (Node *) makeString($1);
4439 }
4440 ;
4441
4442 opt_c_include: INCLUDE '(' columnList ')' { $$ = $3; }
4443 | /* EMPTY */ { $$ = NIL; }
4444 ;
4445
4446 key_match: MATCH FULL
4447 {
4448 $$ = FKCONSTR_MATCH_FULL;
4449 }
4450 | MATCH PARTIAL
4451 {
4452 ereport(ERROR,
4453 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
4454 errmsg("MATCH PARTIAL not yet implemented"),
4455 parser_errposition(@1)));
4456 $$ = FKCONSTR_MATCH_PARTIAL;
4457 }
4458 | MATCH SIMPLE
4459 {
4460 $$ = FKCONSTR_MATCH_SIMPLE;
4461 }
4462 | /*EMPTY*/
4463 {
4464 $$ = FKCONSTR_MATCH_SIMPLE;
4465 }
4466 ;
4467
4468 ExclusionConstraintList:
4469 ExclusionConstraintElem { $$ = list_make1($1); }
4470 | ExclusionConstraintList ',' ExclusionConstraintElem
4471 { $$ = lappend($1, $3); }
4472 ;
4473
4474 ExclusionConstraintElem: index_elem WITH any_operator
4475 {
4476 $$ = list_make2($1, $3);
4477 }
4478 /* allow OPERATOR() decoration for the benefit of ruleutils.c */
4479 | index_elem WITH OPERATOR '(' any_operator ')'
4480 {
4481 $$ = list_make2($1, $5);
4482 }
4483 ;
4484
4485 OptWhereClause:
4486 WHERE '(' a_expr ')' { $$ = $3; }
4487 | /*EMPTY*/ { $$ = NULL; }
4488 ;
4489
4490 key_actions:
4491 key_update
4492 {
4493 KeyActions *n = palloc(sizeof(KeyActions));
4494
4495 n->updateAction = $1;
4496 n->deleteAction = palloc(sizeof(KeyAction));
4497 n->deleteAction->action = FKCONSTR_ACTION_NOACTION;
4498 n->deleteAction->cols = NIL;
4499 $$ = n;
4500 }
4501 | key_delete
4502 {
4503 KeyActions *n = palloc(sizeof(KeyActions));
4504
4505 n->updateAction = palloc(sizeof(KeyAction));
4506 n->updateAction->action = FKCONSTR_ACTION_NOACTION;
4507 n->updateAction->cols = NIL;
4508 n->deleteAction = $1;
4509 $$ = n;
4510 }
4511 | key_update key_delete
4512 {
4513 KeyActions *n = palloc(sizeof(KeyActions));
4514
4515 n->updateAction = $1;
4516 n->deleteAction = $2;
4517 $$ = n;
4518 }
4519 | key_delete key_update
4520 {
4521 KeyActions *n = palloc(sizeof(KeyActions));
4522
4523 n->updateAction = $2;
4524 n->deleteAction = $1;
4525 $$ = n;
4526 }
4527 | /*EMPTY*/
4528 {
4529 KeyActions *n = palloc(sizeof(KeyActions));
4530
4531 n->updateAction = palloc(sizeof(KeyAction));
4532 n->updateAction->action = FKCONSTR_ACTION_NOACTION;
4533 n->updateAction->cols = NIL;
4534 n->deleteAction = palloc(sizeof(KeyAction));
4535 n->deleteAction->action = FKCONSTR_ACTION_NOACTION;
4536 n->deleteAction->cols = NIL;
4537 $$ = n;
4538 }
4539 ;
4540
4541 key_update: ON UPDATE key_action
4542 {
4543 if (($3)->cols)
4544 ereport(ERROR,
4545 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
4546 errmsg("a column list with %s is only supported for ON DELETE actions",
4547 ($3)->action == FKCONSTR_ACTION_SETNULL ? "SET NULL" : "SET DEFAULT"),
4548 parser_errposition(@1)));
4549 $$ = $3;
4550 }
4551 ;
4552
4553 key_delete: ON DELETE_P key_action
4554 {
4555 $$ = $3;
4556 }
4557 ;
4558
4559 key_action:
4560 NO ACTION
4561 {
4562 KeyAction *n = palloc(sizeof(KeyAction));
4563
4564 n->action = FKCONSTR_ACTION_NOACTION;
4565 n->cols = NIL;
4566 $$ = n;
4567 }
4568 | RESTRICT
4569 {
4570 KeyAction *n = palloc(sizeof(KeyAction));
4571
4572 n->action = FKCONSTR_ACTION_RESTRICT;
4573 n->cols = NIL;
4574 $$ = n;
4575 }
4576 | CASCADE
4577 {
4578 KeyAction *n = palloc(sizeof(KeyAction));
4579
4580 n->action = FKCONSTR_ACTION_CASCADE;
4581 n->cols = NIL;
4582 $$ = n;
4583 }
4584 | SET NULL_P opt_column_list
4585 {
4586 KeyAction *n = palloc(sizeof(KeyAction));
4587
4588 n->action = FKCONSTR_ACTION_SETNULL;
4589 n->cols = $3;
4590 $$ = n;
4591 }
4592 | SET DEFAULT opt_column_list
4593 {
4594 KeyAction *n = palloc(sizeof(KeyAction));
4595
4596 n->action = FKCONSTR_ACTION_SETDEFAULT;
4597 n->cols = $3;
4598 $$ = n;
4599 }
4600 ;
4601
4602 OptInherit: INHERITS '(' qualified_name_list ')' { $$ = $3; }
4603 | /*EMPTY*/ { $$ = NIL; }
4604 ;
4605
4606 /* Optional partition key specification */
4607 OptPartitionSpec: PartitionSpec { $$ = $1; }
4608 | /*EMPTY*/ { $$ = NULL; }
4609 ;
4610
4611 PartitionSpec: PARTITION BY ColId '(' part_params ')'
4612 {
4613 PartitionSpec *n = makeNode(PartitionSpec);
4614
4615 n->strategy = parsePartitionStrategy($3, @3, yyscanner);
4616 n->partParams = $5;
4617 n->location = @1;
4618
4619 $$ = n;
4620 }
4621 ;
4622
4623 part_params: part_elem { $$ = list_make1($1); }
4624 | part_params ',' part_elem { $$ = lappend($1, $3); }
4625 ;
4626
4627 part_elem: ColId opt_collate opt_qualified_name
4628 {
4629 PartitionElem *n = makeNode(PartitionElem);
4630
4631 n->name = $1;
4632 n->expr = NULL;
4633 n->collation = $2;
4634 n->opclass = $3;
4635 n->location = @1;
4636 $$ = n;
4637 }
4638 | func_expr_windowless opt_collate opt_qualified_name
4639 {
4640 PartitionElem *n = makeNode(PartitionElem);
4641
4642 n->name = NULL;
4643 n->expr = $1;
4644 n->collation = $2;
4645 n->opclass = $3;
4646 n->location = @1;
4647 $$ = n;
4648 }
4649 | '(' a_expr ')' opt_collate opt_qualified_name
4650 {
4651 PartitionElem *n = makeNode(PartitionElem);
4652
4653 n->name = NULL;
4654 n->expr = $2;
4655 n->collation = $4;
4656 n->opclass = $5;
4657 n->location = @1;
4658 $$ = n;
4659 }
4660 ;
4661
4662 table_access_method_clause:
4663 USING name { $$ = $2; }
4664 | /*EMPTY*/ { $$ = NULL; }
4665 ;
4666
4667 /* WITHOUT OIDS is legacy only */
4668 OptWith:
4669 WITH reloptions { $$ = $2; }
4670 | WITHOUT OIDS { $$ = NIL; }
4671 | /*EMPTY*/ { $$ = NIL; }
4672 ;
4673
4674 OnCommitOption: ON COMMIT DROP { $$ = ONCOMMIT_DROP; }
4675 | ON COMMIT DELETE_P ROWS { $$ = ONCOMMIT_DELETE_ROWS; }
4676 | ON COMMIT PRESERVE ROWS { $$ = ONCOMMIT_PRESERVE_ROWS; }
4677 | /*EMPTY*/ { $$ = ONCOMMIT_NOOP; }
4678 ;
4679
4680 OptTableSpace: TABLESPACE name { $$ = $2; }
4681 | /*EMPTY*/ { $$ = NULL; }
4682 ;
4683
4684 OptConsTableSpace: USING INDEX TABLESPACE name { $$ = $4; }
4685 | /*EMPTY*/ { $$ = NULL; }
4686 ;
4687
4688 ExistingIndex: USING INDEX name { $$ = $3; }
4689 ;
4690
4691 /*****************************************************************************
4692 *
4693 * QUERY :
4694 * CREATE STATISTICS [[IF NOT EXISTS] stats_name] [(stat types)]
4695 * ON expression-list FROM from_list
4696 *
4697 * Note: the expectation here is that the clauses after ON are a subset of
4698 * SELECT syntax, allowing for expressions and joined tables, and probably
4699 * someday a WHERE clause. Much less than that is currently implemented,
4700 * but the grammar accepts it and then we'll throw FEATURE_NOT_SUPPORTED
4701 * errors as necessary at execution.
4702 *
4703 * Statistics name is optional unless IF NOT EXISTS is specified.
4704 *
4705 *****************************************************************************/
4706
4707 CreateStatsStmt:
4708 CREATE STATISTICS opt_qualified_name
4709 opt_name_list ON stats_params FROM from_list
4710 {
4711 CreateStatsStmt *n = makeNode(CreateStatsStmt);
4712
4713 n->defnames = $3;
4714 n->stat_types = $4;
4715 n->exprs = $6;
4716 n->relations = $8;
4717 n->stxcomment = NULL;
4718 n->if_not_exists = false;
4719 $$ = (Node *) n;
4720 }
4721 | CREATE STATISTICS IF_P NOT EXISTS any_name
4722 opt_name_list ON stats_params FROM from_list
4723 {
4724 CreateStatsStmt *n = makeNode(CreateStatsStmt);
4725
4726 n->defnames = $6;
4727 n->stat_types = $7;
4728 n->exprs = $9;
4729 n->relations = $11;
4730 n->stxcomment = NULL;
4731 n->if_not_exists = true;
4732 $$ = (Node *) n;
4733 }
4734 ;
4735
4736 /*
4737 * Statistics attributes can be either simple column references, or arbitrary
4738 * expressions in parens. For compatibility with index attributes permitted
4739 * in CREATE INDEX, we allow an expression that's just a function call to be
4740 * written without parens.
4741 */
4742
4743 stats_params: stats_param { $$ = list_make1($1); }
4744 | stats_params ',' stats_param { $$ = lappend($1, $3); }
4745 ;
4746
4747 stats_param: ColId
4748 {
4749 $$ = makeNode(StatsElem);
4750 $$->name = $1;
4751 $$->expr = NULL;
4752 }
4753 | func_expr_windowless
4754 {
4755 $$ = makeNode(StatsElem);
4756 $$->name = NULL;
4757 $$->expr = $1;
4758 }
4759 | '(' a_expr ')'
4760 {
4761 $$ = makeNode(StatsElem);
4762 $$->name = NULL;
4763 $$->expr = $2;
4764 }
4765 ;
4766
4767 /*****************************************************************************
4768 *
4769 * QUERY :
4770 * ALTER STATISTICS [IF EXISTS] stats_name
4771 * SET STATISTICS <SignedIconst>
4772 *
4773 *****************************************************************************/
4774
4775 AlterStatsStmt:
4776 ALTER STATISTICS any_name SET STATISTICS set_statistics_value
4777 {
4778 AlterStatsStmt *n = makeNode(AlterStatsStmt);
4779
4780 n->defnames = $3;
4781 n->missing_ok = false;
4782 n->stxstattarget = $6;
4783 $$ = (Node *) n;
4784 }
4785 | ALTER STATISTICS IF_P EXISTS any_name SET STATISTICS set_statistics_value
4786 {
4787 AlterStatsStmt *n = makeNode(AlterStatsStmt);
4788
4789 n->defnames = $5;
4790 n->missing_ok = true;
4791 n->stxstattarget = $8;
4792 $$ = (Node *) n;
4793 }
4794 ;
4795
4796 /*****************************************************************************
4797 *
4798 * QUERY :
4799 * CREATE TABLE relname AS SelectStmt [ WITH [NO] DATA ]
4800 *
4801 *
4802 * Note: SELECT ... INTO is a now-deprecated alternative for this.
4803 *
4804 *****************************************************************************/
4805
4806 CreateAsStmt:
4807 CREATE OptTemp TABLE create_as_target AS SelectStmt opt_with_data
4808 {
4809 CreateTableAsStmt *ctas = makeNode(CreateTableAsStmt);
4810
4811 ctas->query = $6;
4812 ctas->into = $4;
4813 ctas->objtype = OBJECT_TABLE;
4814 ctas->is_select_into = false;
4815 ctas->if_not_exists = false;
4816 /* cram additional flags into the IntoClause */
4817 $4->rel->relpersistence = $2;
4818 $4->skipData = !($7);
4819 $$ = (Node *) ctas;
4820 }
4821 | CREATE OptTemp TABLE IF_P NOT EXISTS create_as_target AS SelectStmt opt_with_data
4822 {
4823 CreateTableAsStmt *ctas = makeNode(CreateTableAsStmt);
4824
4825 ctas->query = $9;
4826 ctas->into = $7;
4827 ctas->objtype = OBJECT_TABLE;
4828 ctas->is_select_into = false;
4829 ctas->if_not_exists = true;
4830 /* cram additional flags into the IntoClause */
4831 $7->rel->relpersistence = $2;
4832 $7->skipData = !($10);
4833 $$ = (Node *) ctas;
4834 }
4835 ;
4836
4837 create_as_target:
4838 qualified_name opt_column_list table_access_method_clause
4839 OptWith OnCommitOption OptTableSpace
4840 {
4841 $$ = makeNode(IntoClause);
4842 $$->rel = $1;
4843 $$->colNames = $2;
4844 $$->accessMethod = $3;
4845 $$->options = $4;
4846 $$->onCommit = $5;
4847 $$->tableSpaceName = $6;
4848 $$->viewQuery = NULL;
4849 $$->skipData = false; /* might get changed later */
4850 }
4851 ;
4852
4853 opt_with_data:
4854 WITH DATA_P { $$ = true; }
4855 | WITH NO DATA_P { $$ = false; }
4856 | /*EMPTY*/ { $$ = true; }
4857 ;
4858
4859
4860 /*****************************************************************************
4861 *
4862 * QUERY :
4863 * CREATE MATERIALIZED VIEW relname AS SelectStmt
4864 *
4865 *****************************************************************************/
4866
4867 CreateMatViewStmt:
4868 CREATE OptNoLog MATERIALIZED VIEW create_mv_target AS SelectStmt opt_with_data
4869 {
4870 CreateTableAsStmt *ctas = makeNode(CreateTableAsStmt);
4871
4872 ctas->query = $7;
4873 ctas->into = $5;
4874 ctas->objtype = OBJECT_MATVIEW;
4875 ctas->is_select_into = false;
4876 ctas->if_not_exists = false;
4877 /* cram additional flags into the IntoClause */
4878 $5->rel->relpersistence = $2;
4879 $5->skipData = !($8);
4880 $$ = (Node *) ctas;
4881 }
4882 | CREATE OptNoLog MATERIALIZED VIEW IF_P NOT EXISTS create_mv_target AS SelectStmt opt_with_data
4883 {
4884 CreateTableAsStmt *ctas = makeNode(CreateTableAsStmt);
4885
4886 ctas->query = $10;
4887 ctas->into = $8;
4888 ctas->objtype = OBJECT_MATVIEW;
4889 ctas->is_select_into = false;
4890 ctas->if_not_exists = true;
4891 /* cram additional flags into the IntoClause */
4892 $8->rel->relpersistence = $2;
4893 $8->skipData = !($11);
4894 $$ = (Node *) ctas;
4895 }
4896 ;
4897
4898 create_mv_target:
4899 qualified_name opt_column_list table_access_method_clause opt_reloptions OptTableSpace
4900 {
4901 $$ = makeNode(IntoClause);
4902 $$->rel = $1;
4903 $$->colNames = $2;
4904 $$->accessMethod = $3;
4905 $$->options = $4;
4906 $$->onCommit = ONCOMMIT_NOOP;
4907 $$->tableSpaceName = $5;
4908 $$->viewQuery = NULL; /* filled at analysis time */
4909 $$->skipData = false; /* might get changed later */
4910 }
4911 ;
4912
4913 OptNoLog: UNLOGGED { $$ = RELPERSISTENCE_UNLOGGED; }
4914 | /*EMPTY*/ { $$ = RELPERSISTENCE_PERMANENT; }
4915 ;
4916
4917
4918 /*****************************************************************************
4919 *
4920 * QUERY :
4921 * REFRESH MATERIALIZED VIEW qualified_name
4922 *
4923 *****************************************************************************/
4924
4925 RefreshMatViewStmt:
4926 REFRESH MATERIALIZED VIEW opt_concurrently qualified_name opt_with_data
4927 {
4928 RefreshMatViewStmt *n = makeNode(RefreshMatViewStmt);
4929
4930 n->concurrent = $4;
4931 n->relation = $5;
4932 n->skipData = !($6);
4933 $$ = (Node *) n;
4934 }
4935 ;
4936
4937
4938 /*****************************************************************************
4939 *
4940 * QUERY :
4941 * CREATE SEQUENCE seqname
4942 * ALTER SEQUENCE seqname
4943 *
4944 *****************************************************************************/
4945
4946 CreateSeqStmt:
4947 CREATE OptTemp SEQUENCE qualified_name OptSeqOptList
4948 {
4949 CreateSeqStmt *n = makeNode(CreateSeqStmt);
4950
4951 $4->relpersistence = $2;
4952 n->sequence = $4;
4953 n->options = $5;
4954 n->ownerId = InvalidOid;
4955 n->if_not_exists = false;
4956 $$ = (Node *) n;
4957 }
4958 | CREATE OptTemp SEQUENCE IF_P NOT EXISTS qualified_name OptSeqOptList
4959 {
4960 CreateSeqStmt *n = makeNode(CreateSeqStmt);
4961
4962 $7->relpersistence = $2;
4963 n->sequence = $7;
4964 n->options = $8;
4965 n->ownerId = InvalidOid;
4966 n->if_not_exists = true;
4967 $$ = (Node *) n;
4968 }
4969 ;
4970
4971 AlterSeqStmt:
4972 ALTER SEQUENCE qualified_name SeqOptList
4973 {
4974 AlterSeqStmt *n = makeNode(AlterSeqStmt);
4975
4976 n->sequence = $3;
4977 n->options = $4;
4978 n->missing_ok = false;
4979 $$ = (Node *) n;
4980 }
4981 | ALTER SEQUENCE IF_P EXISTS qualified_name SeqOptList
4982 {
4983 AlterSeqStmt *n = makeNode(AlterSeqStmt);
4984
4985 n->sequence = $5;
4986 n->options = $6;
4987 n->missing_ok = true;
4988 $$ = (Node *) n;
4989 }
4990
4991 ;
4992
4993 OptSeqOptList: SeqOptList { $$ = $1; }
4994 | /*EMPTY*/ { $$ = NIL; }
4995 ;
4996
4997 OptParenthesizedSeqOptList: '(' SeqOptList ')' { $$ = $2; }
4998 | /*EMPTY*/ { $$ = NIL; }
4999 ;
5000
5001 SeqOptList: SeqOptElem { $$ = list_make1($1); }
5002 | SeqOptList SeqOptElem { $$ = lappend($1, $2); }
5003 ;
5004
5005 SeqOptElem: AS SimpleTypename
5006 {
5007 $$ = makeDefElem("as", (Node *) $2, @1);
5008 }
5009 | CACHE NumericOnly
5010 {
5011 $$ = makeDefElem("cache", (Node *) $2, @1);
5012 }
5013 | CYCLE
5014 {
5015 $$ = makeDefElem("cycle", (Node *) makeBoolean(true), @1);
5016 }
5017 | NO CYCLE
5018 {
5019 $$ = makeDefElem("cycle", (Node *) makeBoolean(false), @1);
5020 }
5021 | INCREMENT opt_by NumericOnly
5022 {
5023 $$ = makeDefElem("increment", (Node *) $3, @1);
5024 }
5025 | LOGGED
5026 {
5027 $$ = makeDefElem("logged", NULL, @1);
5028 }
5029 | MAXVALUE NumericOnly
5030 {
5031 $$ = makeDefElem("maxvalue", (Node *) $2, @1);
5032 }
5033 | MINVALUE NumericOnly
5034 {
5035 $$ = makeDefElem("minvalue", (Node *) $2, @1);
5036 }
5037 | NO MAXVALUE
5038 {
5039 $$ = makeDefElem("maxvalue", NULL, @1);
5040 }
5041 | NO MINVALUE
5042 {
5043 $$ = makeDefElem("minvalue", NULL, @1);
5044 }
5045 | OWNED BY any_name
5046 {
5047 $$ = makeDefElem("owned_by", (Node *) $3, @1);
5048 }
5049 | SEQUENCE NAME_P any_name
5050 {
5051 $$ = makeDefElem("sequence_name", (Node *) $3, @1);
5052 }
5053 | START opt_with NumericOnly
5054 {
5055 $$ = makeDefElem("start", (Node *) $3, @1);
5056 }
5057 | RESTART
5058 {
5059 $$ = makeDefElem("restart", NULL, @1);
5060 }
5061 | RESTART opt_with NumericOnly
5062 {
5063 $$ = makeDefElem("restart", (Node *) $3, @1);
5064 }
5065 | UNLOGGED
5066 {
5067 $$ = makeDefElem("unlogged", NULL, @1);
5068 }
5069 ;
5070
5071 opt_by: BY
5072 | /* EMPTY */
5073 ;
5074
5075 NumericOnly:
5076 FCONST { $$ = (Node *) makeFloat($1); }
5077 | '+' FCONST { $$ = (Node *) makeFloat($2); }
5078 | '-' FCONST
5079 {
5080 Float *f = makeFloat($2);
5081
5082 doNegateFloat(f);
5083 $$ = (Node *) f;
5084 }
5085 | SignedIconst { $$ = (Node *) makeInteger($1); }
5086 ;
5087
5088 NumericOnly_list: NumericOnly { $$ = list_make1($1); }
5089 | NumericOnly_list ',' NumericOnly { $$ = lappend($1, $3); }
5090 ;
5091
5092 /*****************************************************************************
5093 *
5094 * QUERIES :
5095 * CREATE [OR REPLACE] [TRUSTED] [PROCEDURAL] LANGUAGE ...
5096 * DROP [PROCEDURAL] LANGUAGE ...
5097 *
5098 *****************************************************************************/
5099
5100 CreatePLangStmt:
5101 CREATE opt_or_replace opt_trusted opt_procedural LANGUAGE name
5102 {
5103 /*
5104 * We now interpret parameterless CREATE LANGUAGE as
5105 * CREATE EXTENSION. "OR REPLACE" is silently translated
5106 * to "IF NOT EXISTS", which isn't quite the same, but
5107 * seems more useful than throwing an error. We just
5108 * ignore TRUSTED, as the previous code would have too.
5109 */
5110 CreateExtensionStmt *n = makeNode(CreateExtensionStmt);
5111
5112 n->if_not_exists = $2;
5113 n->extname = $6;
5114 n->options = NIL;
5115 $$ = (Node *) n;
5116 }
5117 | CREATE opt_or_replace opt_trusted opt_procedural LANGUAGE name
5118 HANDLER handler_name opt_inline_handler opt_validator
5119 {
5120 CreatePLangStmt *n = makeNode(CreatePLangStmt);
5121
5122 n->replace = $2;
5123 n->plname = $6;
5124 n->plhandler = $8;
5125 n->plinline = $9;
5126 n->plvalidator = $10;
5127 n->pltrusted = $3;
5128 $$ = (Node *) n;
5129 }
5130 ;
5131
5132 opt_trusted:
5133 TRUSTED { $$ = true; }
5134 | /*EMPTY*/ { $$ = false; }
5135 ;
5136
5137 /* This ought to be just func_name, but that causes reduce/reduce conflicts
5138 * (CREATE LANGUAGE is the only place where func_name isn't followed by '(').
5139 * Work around by using simple names, instead.
5140 */
5141 handler_name:
5142 name { $$ = list_make1(makeString($1)); }
5143 | name attrs { $$ = lcons(makeString($1), $2); }
5144 ;
5145
5146 opt_inline_handler:
5147 INLINE_P handler_name { $$ = $2; }
5148 | /*EMPTY*/ { $$ = NIL; }
5149 ;
5150
5151 validator_clause:
5152 VALIDATOR handler_name { $$ = $2; }
5153 | NO VALIDATOR { $$ = NIL; }
5154 ;
5155
5156 opt_validator:
5157 validator_clause { $$ = $1; }
5158 | /*EMPTY*/ { $$ = NIL; }
5159 ;
5160
5161 opt_procedural:
5162 PROCEDURAL
5163 | /*EMPTY*/
5164 ;
5165
5166 /*****************************************************************************
5167 *
5168 * QUERY:
5169 * CREATE TABLESPACE tablespace LOCATION '/path/to/tablespace/'
5170 *
5171 *****************************************************************************/
5172
5173 CreateTableSpaceStmt: CREATE TABLESPACE name OptTableSpaceOwner LOCATION Sconst opt_reloptions
5174 {
5175 CreateTableSpaceStmt *n = makeNode(CreateTableSpaceStmt);
5176
5177 n->tablespacename = $3;
5178 n->owner = $4;
5179 n->location = $6;
5180 n->options = $7;
5181 $$ = (Node *) n;
5182 }
5183 ;
5184
5185 OptTableSpaceOwner: OWNER RoleSpec { $$ = $2; }
5186 | /*EMPTY */ { $$ = NULL; }
5187 ;
5188
5189 /*****************************************************************************
5190 *
5191 * QUERY :
5192 * DROP TABLESPACE <tablespace>
5193 *
5194 * No need for drop behaviour as we cannot implement dependencies for
5195 * objects in other databases; we can only support RESTRICT.
5196 *
5197 ****************************************************************************/
5198
5199 DropTableSpaceStmt: DROP TABLESPACE name
5200 {
5201 DropTableSpaceStmt *n = makeNode(DropTableSpaceStmt);
5202
5203 n->tablespacename = $3;
5204 n->missing_ok = false;
5205 $$ = (Node *) n;
5206 }
5207 | DROP TABLESPACE IF_P EXISTS name
5208 {
5209 DropTableSpaceStmt *n = makeNode(DropTableSpaceStmt);
5210
5211 n->tablespacename = $5;
5212 n->missing_ok = true;
5213 $$ = (Node *) n;
5214 }
5215 ;
5216
5217 /*****************************************************************************
5218 *
5219 * QUERY:
5220 * CREATE EXTENSION extension
5221 * [ WITH ] [ SCHEMA schema ] [ VERSION version ]
5222 *
5223 *****************************************************************************/
5224
5225 CreateExtensionStmt: CREATE EXTENSION name opt_with create_extension_opt_list
5226 {
5227 CreateExtensionStmt *n = makeNode(CreateExtensionStmt);
5228
5229 n->extname = $3;
5230 n->if_not_exists = false;
5231 n->options = $5;
5232 $$ = (Node *) n;
5233 }
5234 | CREATE EXTENSION IF_P NOT EXISTS name opt_with create_extension_opt_list
5235 {
5236 CreateExtensionStmt *n = makeNode(CreateExtensionStmt);
5237
5238 n->extname = $6;
5239 n->if_not_exists = true;
5240 n->options = $8;
5241 $$ = (Node *) n;
5242 }
5243 ;
5244
5245 create_extension_opt_list:
5246 create_extension_opt_list create_extension_opt_item
5247 { $$ = lappend($1, $2); }
5248 | /* EMPTY */
5249 { $$ = NIL; }
5250 ;
5251
5252 create_extension_opt_item:
5253 SCHEMA name
5254 {
5255 $$ = makeDefElem("schema", (Node *) makeString($2), @1);
5256 }
5257 | VERSION_P NonReservedWord_or_Sconst
5258 {
5259 $$ = makeDefElem("new_version", (Node *) makeString($2), @1);
5260 }
5261 | FROM NonReservedWord_or_Sconst
5262 {
5263 ereport(ERROR,
5264 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
5265 errmsg("CREATE EXTENSION ... FROM is no longer supported"),
5266 parser_errposition(@1)));
5267 }
5268 | CASCADE
5269 {
5270 $$ = makeDefElem("cascade", (Node *) makeBoolean(true), @1);
5271 }
5272 ;
5273
5274 /*****************************************************************************
5275 *
5276 * ALTER EXTENSION name UPDATE [ TO version ]
5277 *
5278 *****************************************************************************/
5279
5280 AlterExtensionStmt: ALTER EXTENSION name UPDATE alter_extension_opt_list
5281 {
5282 AlterExtensionStmt *n = makeNode(AlterExtensionStmt);
5283
5284 n->extname = $3;
5285 n->options = $5;
5286 $$ = (Node *) n;
5287 }
5288 ;
5289
5290 alter_extension_opt_list:
5291 alter_extension_opt_list alter_extension_opt_item
5292 { $$ = lappend($1, $2); }
5293 | /* EMPTY */
5294 { $$ = NIL; }
5295 ;
5296
5297 alter_extension_opt_item:
5298 TO NonReservedWord_or_Sconst
5299 {
5300 $$ = makeDefElem("new_version", (Node *) makeString($2), @1);
5301 }
5302 ;
5303
5304 /*****************************************************************************
5305 *
5306 * ALTER EXTENSION name ADD/DROP object-identifier
5307 *
5308 *****************************************************************************/
5309
5310 AlterExtensionContentsStmt:
5311 ALTER EXTENSION name add_drop object_type_name name
5312 {
5313 AlterExtensionContentsStmt *n = makeNode(AlterExtensionContentsStmt);
5314
5315 n->extname = $3;
5316 n->action = $4;
5317 n->objtype = $5;
5318 n->object = (Node *) makeString($6);
5319 $$ = (Node *) n;
5320 }
5321 | ALTER EXTENSION name add_drop object_type_any_name any_name
5322 {
5323 AlterExtensionContentsStmt *n = makeNode(AlterExtensionContentsStmt);
5324
5325 n->extname = $3;
5326 n->action = $4;
5327 n->objtype = $5;
5328 n->object = (Node *) $6;
5329 $$ = (Node *) n;
5330 }
5331 | ALTER EXTENSION name add_drop AGGREGATE aggregate_with_argtypes
5332 {
5333 AlterExtensionContentsStmt *n = makeNode(AlterExtensionContentsStmt);
5334
5335 n->extname = $3;
5336 n->action = $4;
5337 n->objtype = OBJECT_AGGREGATE;
5338 n->object = (Node *) $6;
5339 $$ = (Node *) n;
5340 }
5341 | ALTER EXTENSION name add_drop CAST '(' Typename AS Typename ')'
5342 {
5343 AlterExtensionContentsStmt *n = makeNode(AlterExtensionContentsStmt);
5344
5345 n->extname = $3;
5346 n->action = $4;
5347 n->objtype = OBJECT_CAST;
5348 n->object = (Node *) list_make2($7, $9);
5349 $$ = (Node *) n;
5350 }
5351 | ALTER EXTENSION name add_drop DOMAIN_P Typename
5352 {
5353 AlterExtensionContentsStmt *n = makeNode(AlterExtensionContentsStmt);
5354
5355 n->extname = $3;
5356 n->action = $4;
5357 n->objtype = OBJECT_DOMAIN;
5358 n->object = (Node *) $6;
5359 $$ = (Node *) n;
5360 }
5361 | ALTER EXTENSION name add_drop FUNCTION function_with_argtypes
5362 {
5363 AlterExtensionContentsStmt *n = makeNode(AlterExtensionContentsStmt);
5364
5365 n->extname = $3;
5366 n->action = $4;
5367 n->objtype = OBJECT_FUNCTION;
5368 n->object = (Node *) $6;
5369 $$ = (Node *) n;
5370 }
5371 | ALTER EXTENSION name add_drop OPERATOR operator_with_argtypes
5372 {
5373 AlterExtensionContentsStmt *n = makeNode(AlterExtensionContentsStmt);
5374
5375 n->extname = $3;
5376 n->action = $4;
5377 n->objtype = OBJECT_OPERATOR;
5378 n->object = (Node *) $6;
5379 $$ = (Node *) n;
5380 }
5381 | ALTER EXTENSION name add_drop OPERATOR CLASS any_name USING name
5382 {
5383 AlterExtensionContentsStmt *n = makeNode(AlterExtensionContentsStmt);
5384
5385 n->extname = $3;
5386 n->action = $4;
5387 n->objtype = OBJECT_OPCLASS;
5388 n->object = (Node *) lcons(makeString($9), $7);
5389 $$ = (Node *) n;
5390 }
5391 | ALTER EXTENSION name add_drop OPERATOR FAMILY any_name USING name
5392 {
5393 AlterExtensionContentsStmt *n = makeNode(AlterExtensionContentsStmt);
5394
5395 n->extname = $3;
5396 n->action = $4;
5397 n->objtype = OBJECT_OPFAMILY;
5398 n->object = (Node *) lcons(makeString($9), $7);
5399 $$ = (Node *) n;
5400 }
5401 | ALTER EXTENSION name add_drop PROCEDURE function_with_argtypes
5402 {
5403 AlterExtensionContentsStmt *n = makeNode(AlterExtensionContentsStmt);
5404
5405 n->extname = $3;
5406 n->action = $4;
5407 n->objtype = OBJECT_PROCEDURE;
5408 n->object = (Node *) $6;
5409 $$ = (Node *) n;
5410 }
5411 | ALTER EXTENSION name add_drop ROUTINE function_with_argtypes
5412 {
5413 AlterExtensionContentsStmt *n = makeNode(AlterExtensionContentsStmt);
5414
5415 n->extname = $3;
5416 n->action = $4;
5417 n->objtype = OBJECT_ROUTINE;
5418 n->object = (Node *) $6;
5419 $$ = (Node *) n;
5420 }
5421 | ALTER EXTENSION name add_drop TRANSFORM FOR Typename LANGUAGE name
5422 {
5423 AlterExtensionContentsStmt *n = makeNode(AlterExtensionContentsStmt);
5424
5425 n->extname = $3;
5426 n->action = $4;
5427 n->objtype = OBJECT_TRANSFORM;
5428 n->object = (Node *) list_make2($7, makeString($9));
5429 $$ = (Node *) n;
5430 }
5431 | ALTER EXTENSION name add_drop TYPE_P Typename
5432 {
5433 AlterExtensionContentsStmt *n = makeNode(AlterExtensionContentsStmt);
5434
5435 n->extname = $3;
5436 n->action = $4;
5437 n->objtype = OBJECT_TYPE;
5438 n->object = (Node *) $6;
5439 $$ = (Node *) n;
5440 }
5441 ;
5442
5443 /*****************************************************************************
5444 *
5445 * QUERY:
5446 * CREATE FOREIGN DATA WRAPPER name options
5447 *
5448 *****************************************************************************/
5449
5450 CreateFdwStmt: CREATE FOREIGN DATA_P WRAPPER name opt_fdw_options create_generic_options
5451 {
5452 CreateFdwStmt *n = makeNode(CreateFdwStmt);
5453
5454 n->fdwname = $5;
5455 n->func_options = $6;
5456 n->options = $7;
5457 $$ = (Node *) n;
5458 }
5459 ;
5460
5461 fdw_option:
5462 HANDLER handler_name { $$ = makeDefElem("handler", (Node *) $2, @1); }
5463 | NO HANDLER { $$ = makeDefElem("handler", NULL, @1); }
5464 | VALIDATOR handler_name { $$ = makeDefElem("validator", (Node *) $2, @1); }
5465 | NO VALIDATOR { $$ = makeDefElem("validator", NULL, @1); }
5466 ;
5467
5468 fdw_options:
5469 fdw_option { $$ = list_make1($1); }
5470 | fdw_options fdw_option { $$ = lappend($1, $2); }
5471 ;
5472
5473 opt_fdw_options:
5474 fdw_options { $$ = $1; }
5475 | /*EMPTY*/ { $$ = NIL; }
5476 ;
5477
5478 /*****************************************************************************
5479 *
5480 * QUERY :
5481 * ALTER FOREIGN DATA WRAPPER name options
5482 *
5483 ****************************************************************************/
5484
5485 AlterFdwStmt: ALTER FOREIGN DATA_P WRAPPER name opt_fdw_options alter_generic_options
5486 {
5487 AlterFdwStmt *n = makeNode(AlterFdwStmt);
5488
5489 n->fdwname = $5;
5490 n->func_options = $6;
5491 n->options = $7;
5492 $$ = (Node *) n;
5493 }
5494 | ALTER FOREIGN DATA_P WRAPPER name fdw_options
5495 {
5496 AlterFdwStmt *n = makeNode(AlterFdwStmt);
5497
5498 n->fdwname = $5;
5499 n->func_options = $6;
5500 n->options = NIL;
5501 $$ = (Node *) n;
5502 }
5503 ;
5504
5505 /* Options definition for CREATE FDW, SERVER and USER MAPPING */
5506 create_generic_options:
5507 OPTIONS '(' generic_option_list ')' { $$ = $3; }
5508 | /*EMPTY*/ { $$ = NIL; }
5509 ;
5510
5511 generic_option_list:
5512 generic_option_elem
5513 {
5514 $$ = list_make1($1);
5515 }
5516 | generic_option_list ',' generic_option_elem
5517 {
5518 $$ = lappend($1, $3);
5519 }
5520 ;
5521
5522 /* Options definition for ALTER FDW, SERVER and USER MAPPING */
5523 alter_generic_options:
5524 OPTIONS '(' alter_generic_option_list ')' { $$ = $3; }
5525 ;
5526
5527 alter_generic_option_list:
5528 alter_generic_option_elem
5529 {
5530 $$ = list_make1($1);
5531 }
5532 | alter_generic_option_list ',' alter_generic_option_elem
5533 {
5534 $$ = lappend($1, $3);
5535 }
5536 ;
5537
5538 alter_generic_option_elem:
5539 generic_option_elem
5540 {
5541 $$ = $1;
5542 }
5543 | SET generic_option_elem
5544 {
5545 $$ = $2;
5546 $$->defaction = DEFELEM_SET;
5547 }
5548 | ADD_P generic_option_elem
5549 {
5550 $$ = $2;
5551 $$->defaction = DEFELEM_ADD;
5552 }
5553 | DROP generic_option_name
5554 {
5555 $$ = makeDefElemExtended(NULL, $2, NULL, DEFELEM_DROP, @2);
5556 }
5557 ;
5558
5559 generic_option_elem:
5560 generic_option_name generic_option_arg
5561 {
5562 $$ = makeDefElem($1, $2, @1);
5563 }
5564 ;
5565
5566 generic_option_name:
5567 ColLabel { $$ = $1; }
5568 ;
5569
5570 /* We could use def_arg here, but the spec only requires string literals */
5571 generic_option_arg:
5572 Sconst { $$ = (Node *) makeString($1); }
5573 ;
5574
5575 /*****************************************************************************
5576 *
5577 * QUERY:
5578 * CREATE SERVER name [TYPE] [VERSION] [OPTIONS]
5579 *
5580 *****************************************************************************/
5581
5582 CreateForeignServerStmt: CREATE SERVER name opt_type opt_foreign_server_version
5583 FOREIGN DATA_P WRAPPER name create_generic_options
5584 {
5585 CreateForeignServerStmt *n = makeNode(CreateForeignServerStmt);
5586
5587 n->servername = $3;
5588 n->servertype = $4;
5589 n->version = $5;
5590 n->fdwname = $9;
5591 n->options = $10;
5592 n->if_not_exists = false;
5593 $$ = (Node *) n;
5594 }
5595 | CREATE SERVER IF_P NOT EXISTS name opt_type opt_foreign_server_version
5596 FOREIGN DATA_P WRAPPER name create_generic_options
5597 {
5598 CreateForeignServerStmt *n = makeNode(CreateForeignServerStmt);
5599
5600 n->servername = $6;
5601 n->servertype = $7;
5602 n->version = $8;
5603 n->fdwname = $12;
5604 n->options = $13;
5605 n->if_not_exists = true;
5606 $$ = (Node *) n;
5607 }
5608 ;
5609
5610 opt_type:
5611 TYPE_P Sconst { $$ = $2; }
5612 | /*EMPTY*/ { $$ = NULL; }
5613 ;
5614
5615
5616 foreign_server_version:
5617 VERSION_P Sconst { $$ = $2; }
5618 | VERSION_P NULL_P { $$ = NULL; }
5619 ;
5620
5621 opt_foreign_server_version:
5622 foreign_server_version { $$ = $1; }
5623 | /*EMPTY*/ { $$ = NULL; }
5624 ;
5625
5626 /*****************************************************************************
5627 *
5628 * QUERY :
5629 * ALTER SERVER name [VERSION] [OPTIONS]
5630 *
5631 ****************************************************************************/
5632
5633 AlterForeignServerStmt: ALTER SERVER name foreign_server_version alter_generic_options
5634 {
5635 AlterForeignServerStmt *n = makeNode(AlterForeignServerStmt);
5636
5637 n->servername = $3;
5638 n->version = $4;
5639 n->options = $5;
5640 n->has_version = true;
5641 $$ = (Node *) n;
5642 }
5643 | ALTER SERVER name foreign_server_version
5644 {
5645 AlterForeignServerStmt *n = makeNode(AlterForeignServerStmt);
5646
5647 n->servername = $3;
5648 n->version = $4;
5649 n->has_version = true;
5650 $$ = (Node *) n;
5651 }
5652 | ALTER SERVER name alter_generic_options
5653 {
5654 AlterForeignServerStmt *n = makeNode(AlterForeignServerStmt);
5655
5656 n->servername = $3;
5657 n->options = $4;
5658 $$ = (Node *) n;
5659 }
5660 ;
5661
5662 /*****************************************************************************
5663 *
5664 * QUERY:
5665 * CREATE FOREIGN TABLE relname (...) SERVER name (...)
5666 *
5667 *****************************************************************************/
5668
5669 CreateForeignTableStmt:
5670 CREATE FOREIGN TABLE qualified_name
5671 '(' OptTableElementList ')'
5672 OptInherit SERVER name create_generic_options
5673 {
5674 CreateForeignTableStmt *n = makeNode(CreateForeignTableStmt);
5675
5676 $4->relpersistence = RELPERSISTENCE_PERMANENT;
5677 n->base.relation = $4;
5678 n->base.tableElts = $6;
5679 n->base.inhRelations = $8;
5680 n->base.ofTypename = NULL;
5681 n->base.constraints = NIL;
5682 n->base.options = NIL;
5683 n->base.oncommit = ONCOMMIT_NOOP;
5684 n->base.tablespacename = NULL;
5685 n->base.if_not_exists = false;
5686 /* FDW-specific data */
5687 n->servername = $10;
5688 n->options = $11;
5689 $$ = (Node *) n;
5690 }
5691 | CREATE FOREIGN TABLE IF_P NOT EXISTS qualified_name
5692 '(' OptTableElementList ')'
5693 OptInherit SERVER name create_generic_options
5694 {
5695 CreateForeignTableStmt *n = makeNode(CreateForeignTableStmt);
5696
5697 $7->relpersistence = RELPERSISTENCE_PERMANENT;
5698 n->base.relation = $7;
5699 n->base.tableElts = $9;
5700 n->base.inhRelations = $11;
5701 n->base.ofTypename = NULL;
5702 n->base.constraints = NIL;
5703 n->base.options = NIL;
5704 n->base.oncommit = ONCOMMIT_NOOP;
5705 n->base.tablespacename = NULL;
5706 n->base.if_not_exists = true;
5707 /* FDW-specific data */
5708 n->servername = $13;
5709 n->options = $14;
5710 $$ = (Node *) n;
5711 }
5712 | CREATE FOREIGN TABLE qualified_name
5713 PARTITION OF qualified_name OptTypedTableElementList PartitionBoundSpec
5714 SERVER name create_generic_options
5715 {
5716 CreateForeignTableStmt *n = makeNode(CreateForeignTableStmt);
5717
5718 $4->relpersistence = RELPERSISTENCE_PERMANENT;
5719 n->base.relation = $4;
5720 n->base.inhRelations = list_make1($7);
5721 n->base.tableElts = $8;
5722 n->base.partbound = $9;
5723 n->base.ofTypename = NULL;
5724 n->base.constraints = NIL;
5725 n->base.options = NIL;
5726 n->base.oncommit = ONCOMMIT_NOOP;
5727 n->base.tablespacename = NULL;
5728 n->base.if_not_exists = false;
5729 /* FDW-specific data */
5730 n->servername = $11;
5731 n->options = $12;
5732 $$ = (Node *) n;
5733 }
5734 | CREATE FOREIGN TABLE IF_P NOT EXISTS qualified_name
5735 PARTITION OF qualified_name OptTypedTableElementList PartitionBoundSpec
5736 SERVER name create_generic_options
5737 {
5738 CreateForeignTableStmt *n = makeNode(CreateForeignTableStmt);
5739
5740 $7->relpersistence = RELPERSISTENCE_PERMANENT;
5741 n->base.relation = $7;
5742 n->base.inhRelations = list_make1($10);
5743 n->base.tableElts = $11;
5744 n->base.partbound = $12;
5745 n->base.ofTypename = NULL;
5746 n->base.constraints = NIL;
5747 n->base.options = NIL;
5748 n->base.oncommit = ONCOMMIT_NOOP;
5749 n->base.tablespacename = NULL;
5750 n->base.if_not_exists = true;
5751 /* FDW-specific data */
5752 n->servername = $14;
5753 n->options = $15;
5754 $$ = (Node *) n;
5755 }
5756 ;
5757
5758 /*****************************************************************************
5759 *
5760 * QUERY:
5761 * IMPORT FOREIGN SCHEMA remote_schema
5762 * [ { LIMIT TO | EXCEPT } ( table_list ) ]
5763 * FROM SERVER server_name INTO local_schema [ OPTIONS (...) ]
5764 *
5765 ****************************************************************************/
5766
5767 ImportForeignSchemaStmt:
5768 IMPORT_P FOREIGN SCHEMA name import_qualification
5769 FROM SERVER name INTO name create_generic_options
5770 {
5771 ImportForeignSchemaStmt *n = makeNode(ImportForeignSchemaStmt);
5772
5773 n->server_name = $8;
5774 n->remote_schema = $4;
5775 n->local_schema = $10;
5776 n->list_type = $5->type;
5777 n->table_list = $5->table_names;
5778 n->options = $11;
5779 $$ = (Node *) n;
5780 }
5781 ;
5782
5783 import_qualification_type:
5784 LIMIT TO { $$ = FDW_IMPORT_SCHEMA_LIMIT_TO; }
5785 | EXCEPT { $$ = FDW_IMPORT_SCHEMA_EXCEPT; }
5786 ;
5787
5788 import_qualification:
5789 import_qualification_type '(' relation_expr_list ')'
5790 {
5791 ImportQual *n = (ImportQual *) palloc(sizeof(ImportQual));
5792
5793 n->type = $1;
5794 n->table_names = $3;
5795 $$ = n;
5796 }
5797 | /*EMPTY*/
5798 {
5799 ImportQual *n = (ImportQual *) palloc(sizeof(ImportQual));
5800 n->type = FDW_IMPORT_SCHEMA_ALL;
5801 n->table_names = NIL;
5802 $$ = n;
5803 }
5804 ;
5805
5806 /*****************************************************************************
5807 *
5808 * QUERY:
5809 * CREATE USER MAPPING FOR auth_ident SERVER name [OPTIONS]
5810 *
5811 *****************************************************************************/
5812
5813 CreateUserMappingStmt: CREATE USER MAPPING FOR auth_ident SERVER name create_generic_options
5814 {
5815 CreateUserMappingStmt *n = makeNode(CreateUserMappingStmt);
5816
5817 n->user = $5;
5818 n->servername = $7;
5819 n->options = $8;
5820 n->if_not_exists = false;
5821 $$ = (Node *) n;
5822 }
5823 | CREATE USER MAPPING IF_P NOT EXISTS FOR auth_ident SERVER name create_generic_options
5824 {
5825 CreateUserMappingStmt *n = makeNode(CreateUserMappingStmt);
5826
5827 n->user = $8;
5828 n->servername = $10;
5829 n->options = $11;
5830 n->if_not_exists = true;
5831 $$ = (Node *) n;
5832 }
5833 ;
5834
5835 /* User mapping authorization identifier */
5836 auth_ident: RoleSpec { $$ = $1; }
5837 | USER { $$ = makeRoleSpec(ROLESPEC_CURRENT_USER, @1); }
5838 ;
5839
5840 /*****************************************************************************
5841 *
5842 * QUERY :
5843 * DROP USER MAPPING FOR auth_ident SERVER name
5844 *
5845 * XXX you'd think this should have a CASCADE/RESTRICT option, even if it's
5846 * only pro forma; but the SQL standard doesn't show one.
5847 ****************************************************************************/
5848
5849 DropUserMappingStmt: DROP USER MAPPING FOR auth_ident SERVER name
5850 {
5851 DropUserMappingStmt *n = makeNode(DropUserMappingStmt);
5852
5853 n->user = $5;
5854 n->servername = $7;
5855 n->missing_ok = false;
5856 $$ = (Node *) n;
5857 }
5858 | DROP USER MAPPING IF_P EXISTS FOR auth_ident SERVER name
5859 {
5860 DropUserMappingStmt *n = makeNode(DropUserMappingStmt);
5861
5862 n->user = $7;
5863 n->servername = $9;
5864 n->missing_ok = true;
5865 $$ = (Node *) n;
5866 }
5867 ;
5868
5869 /*****************************************************************************
5870 *
5871 * QUERY :
5872 * ALTER USER MAPPING FOR auth_ident SERVER name OPTIONS
5873 *
5874 ****************************************************************************/
5875
5876 AlterUserMappingStmt: ALTER USER MAPPING FOR auth_ident SERVER name alter_generic_options
5877 {
5878 AlterUserMappingStmt *n = makeNode(AlterUserMappingStmt);
5879
5880 n->user = $5;
5881 n->servername = $7;
5882 n->options = $8;
5883 $$ = (Node *) n;
5884 }
5885 ;
5886
5887 /*****************************************************************************
5888 *
5889 * QUERIES:
5890 * CREATE POLICY name ON table
5891 * [AS { PERMISSIVE | RESTRICTIVE } ]
5892 * [FOR { SELECT | INSERT | UPDATE | DELETE } ]
5893 * [TO role, ...]
5894 * [USING (qual)] [WITH CHECK (with check qual)]
5895 * ALTER POLICY name ON table [TO role, ...]
5896 * [USING (qual)] [WITH CHECK (with check qual)]
5897 *
5898 *****************************************************************************/
5899
5900 CreatePolicyStmt:
5901 CREATE POLICY name ON qualified_name RowSecurityDefaultPermissive
5902 RowSecurityDefaultForCmd RowSecurityDefaultToRole
5903 RowSecurityOptionalExpr RowSecurityOptionalWithCheck
5904 {
5905 CreatePolicyStmt *n = makeNode(CreatePolicyStmt);
5906
5907 n->policy_name = $3;
5908 n->table = $5;
5909 n->permissive = $6;
5910 n->cmd_name = $7;
5911 n->roles = $8;
5912 n->qual = $9;
5913 n->with_check = $10;
5914 $$ = (Node *) n;
5915 }
5916 ;
5917
5918 AlterPolicyStmt:
5919 ALTER POLICY name ON qualified_name RowSecurityOptionalToRole
5920 RowSecurityOptionalExpr RowSecurityOptionalWithCheck
5921 {
5922 AlterPolicyStmt *n = makeNode(AlterPolicyStmt);
5923
5924 n->policy_name = $3;
5925 n->table = $5;
5926 n->roles = $6;
5927 n->qual = $7;
5928 n->with_check = $8;
5929 $$ = (Node *) n;
5930 }
5931 ;
5932
5933 RowSecurityOptionalExpr:
5934 USING '(' a_expr ')' { $$ = $3; }
5935 | /* EMPTY */ { $$ = NULL; }
5936 ;
5937
5938 RowSecurityOptionalWithCheck:
5939 WITH CHECK '(' a_expr ')' { $$ = $4; }
5940 | /* EMPTY */ { $$ = NULL; }
5941 ;
5942
5943 RowSecurityDefaultToRole:
5944 TO role_list { $$ = $2; }
5945 | /* EMPTY */ { $$ = list_make1(makeRoleSpec(ROLESPEC_PUBLIC, -1)); }
5946 ;
5947
5948 RowSecurityOptionalToRole:
5949 TO role_list { $$ = $2; }
5950 | /* EMPTY */ { $$ = NULL; }
5951 ;
5952
5953 RowSecurityDefaultPermissive:
5954 AS IDENT
5955 {
5956 if (strcmp($2, "permissive") == 0)
5957 $$ = true;
5958 else if (strcmp($2, "restrictive") == 0)
5959 $$ = false;
5960 else
5961 ereport(ERROR,
5962 (errcode(ERRCODE_SYNTAX_ERROR),
5963 errmsg("unrecognized row security option \"%s\"", $2),
5964 errhint("Only PERMISSIVE or RESTRICTIVE policies are supported currently."),
5965 parser_errposition(@2)));
5966
5967 }
5968 | /* EMPTY */ { $$ = true; }
5969 ;
5970
5971 RowSecurityDefaultForCmd:
5972 FOR row_security_cmd { $$ = $2; }
5973 | /* EMPTY */ { $$ = "all"; }
5974 ;
5975
5976 row_security_cmd:
5977 ALL { $$ = "all"; }
5978 | SELECT { $$ = "select"; }
5979 | INSERT { $$ = "insert"; }
5980 | UPDATE { $$ = "update"; }
5981 | DELETE_P { $$ = "delete"; }
5982 ;
5983
5984 /*****************************************************************************
5985 *
5986 * QUERY:
5987 * CREATE ACCESS METHOD name HANDLER handler_name
5988 *
5989 *****************************************************************************/
5990
5991 CreateAmStmt: CREATE ACCESS METHOD name TYPE_P am_type HANDLER handler_name
5992 {
5993 CreateAmStmt *n = makeNode(CreateAmStmt);
5994
5995 n->amname = $4;
5996 n->handler_name = $8;
5997 n->amtype = $6;
5998 $$ = (Node *) n;
5999 }
6000 ;
6001
6002 am_type:
6003 INDEX { $$ = AMTYPE_INDEX; }
6004 | TABLE { $$ = AMTYPE_TABLE; }
6005 ;
6006
6007 /*****************************************************************************
6008 *
6009 * QUERIES :
6010 * CREATE TRIGGER ...
6011 *
6012 *****************************************************************************/
6013
6014 CreateTrigStmt:
6015 CREATE opt_or_replace TRIGGER name TriggerActionTime TriggerEvents ON
6016 qualified_name TriggerReferencing TriggerForSpec TriggerWhen
6017 EXECUTE FUNCTION_or_PROCEDURE func_name '(' TriggerFuncArgs ')'
6018 {
6019 CreateTrigStmt *n = makeNode(CreateTrigStmt);
6020
6021 n->replace = $2;
6022 n->isconstraint = false;
6023 n->trigname = $4;
6024 n->relation = $8;
6025 n->funcname = $14;
6026 n->args = $16;
6027 n->row = $10;
6028 n->timing = $5;
6029 n->events = intVal(linitial($6));
6030 n->columns = (List *) lsecond($6);
6031 n->whenClause = $11;
6032 n->transitionRels = $9;
6033 n->deferrable = false;
6034 n->initdeferred = false;
6035 n->constrrel = NULL;
6036 $$ = (Node *) n;
6037 }
6038 | CREATE opt_or_replace CONSTRAINT TRIGGER name AFTER TriggerEvents ON
6039 qualified_name OptConstrFromTable ConstraintAttributeSpec
6040 FOR EACH ROW TriggerWhen
6041 EXECUTE FUNCTION_or_PROCEDURE func_name '(' TriggerFuncArgs ')'
6042 {
6043 CreateTrigStmt *n = makeNode(CreateTrigStmt);
6044
6045 n->replace = $2;
6046 if (n->replace) /* not supported, see CreateTrigger */
6047 ereport(ERROR,
6048 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
6049 errmsg("CREATE OR REPLACE CONSTRAINT TRIGGER is not supported"),
6050 parser_errposition(@1)));
6051 n->isconstraint = true;
6052 n->trigname = $5;
6053 n->relation = $9;
6054 n->funcname = $18;
6055 n->args = $20;
6056 n->row = true;
6057 n->timing = TRIGGER_TYPE_AFTER;
6058 n->events = intVal(linitial($7));
6059 n->columns = (List *) lsecond($7);
6060 n->whenClause = $15;
6061 n->transitionRels = NIL;
6062 processCASbits($11, @11, "TRIGGER",
6063 &n->deferrable, &n->initdeferred, NULL,
6064 NULL, NULL, yyscanner);
6065 n->constrrel = $10;
6066 $$ = (Node *) n;
6067 }
6068 ;
6069
6070 TriggerActionTime:
6071 BEFORE { $$ = TRIGGER_TYPE_BEFORE; }
6072 | AFTER { $$ = TRIGGER_TYPE_AFTER; }
6073 | INSTEAD OF { $$ = TRIGGER_TYPE_INSTEAD; }
6074 ;
6075
6076 TriggerEvents:
6077 TriggerOneEvent
6078 { $$ = $1; }
6079 | TriggerEvents OR TriggerOneEvent
6080 {
6081 int events1 = intVal(linitial($1));
6082 int events2 = intVal(linitial($3));
6083 List *columns1 = (List *) lsecond($1);
6084 List *columns2 = (List *) lsecond($3);
6085
6086 if (events1 & events2)
6087 parser_yyerror("duplicate trigger events specified");
6088 /*
6089 * concat'ing the columns lists loses information about
6090 * which columns went with which event, but so long as
6091 * only UPDATE carries columns and we disallow multiple
6092 * UPDATE items, it doesn't matter. Command execution
6093 * should just ignore the columns for non-UPDATE events.
6094 */
6095 $$ = list_make2(makeInteger(events1 | events2),
6096 list_concat(columns1, columns2));
6097 }
6098 ;
6099
6100 TriggerOneEvent:
6101 INSERT
6102 { $$ = list_make2(makeInteger(TRIGGER_TYPE_INSERT), NIL); }
6103 | DELETE_P
6104 { $$ = list_make2(makeInteger(TRIGGER_TYPE_DELETE), NIL); }
6105 | UPDATE
6106 { $$ = list_make2(makeInteger(TRIGGER_TYPE_UPDATE), NIL); }
6107 | UPDATE OF columnList
6108 { $$ = list_make2(makeInteger(TRIGGER_TYPE_UPDATE), $3); }
6109 | TRUNCATE
6110 { $$ = list_make2(makeInteger(TRIGGER_TYPE_TRUNCATE), NIL); }
6111 ;
6112
6113 TriggerReferencing:
6114 REFERENCING TriggerTransitions { $$ = $2; }
6115 | /*EMPTY*/ { $$ = NIL; }
6116 ;
6117
6118 TriggerTransitions:
6119 TriggerTransition { $$ = list_make1($1); }
6120 | TriggerTransitions TriggerTransition { $$ = lappend($1, $2); }
6121 ;
6122
6123 TriggerTransition:
6124 TransitionOldOrNew TransitionRowOrTable opt_as TransitionRelName
6125 {
6126 TriggerTransition *n = makeNode(TriggerTransition);
6127
6128 n->name = $4;
6129 n->isNew = $1;
6130 n->isTable = $2;
6131 $$ = (Node *) n;
6132 }
6133 ;
6134
6135 TransitionOldOrNew:
6136 NEW { $$ = true; }
6137 | OLD { $$ = false; }
6138 ;
6139
6140 TransitionRowOrTable:
6141 TABLE { $$ = true; }
6142 /*
6143 * According to the standard, lack of a keyword here implies ROW.
6144 * Support for that would require prohibiting ROW entirely here,
6145 * reserving the keyword ROW, and/or requiring AS (instead of
6146 * allowing it to be optional, as the standard specifies) as the
6147 * next token. Requiring ROW seems cleanest and easiest to
6148 * explain.
6149 */
6150 | ROW { $$ = false; }
6151 ;
6152
6153 TransitionRelName:
6154 ColId { $$ = $1; }
6155 ;
6156
6157 TriggerForSpec:
6158 FOR TriggerForOptEach TriggerForType
6159 {
6160 $$ = $3;
6161 }
6162 | /* EMPTY */
6163 {
6164 /*
6165 * If ROW/STATEMENT not specified, default to
6166 * STATEMENT, per SQL
6167 */
6168 $$ = false;
6169 }
6170 ;
6171
6172 TriggerForOptEach:
6173 EACH
6174 | /*EMPTY*/
6175 ;
6176
6177 TriggerForType:
6178 ROW { $$ = true; }
6179 | STATEMENT { $$ = false; }
6180 ;
6181
6182 TriggerWhen:
6183 WHEN '(' a_expr ')' { $$ = $3; }
6184 | /*EMPTY*/ { $$ = NULL; }
6185 ;
6186
6187 FUNCTION_or_PROCEDURE:
6188 FUNCTION
6189 | PROCEDURE
6190 ;
6191
6192 TriggerFuncArgs:
6193 TriggerFuncArg { $$ = list_make1($1); }
6194 | TriggerFuncArgs ',' TriggerFuncArg { $$ = lappend($1, $3); }
6195 | /*EMPTY*/ { $$ = NIL; }
6196 ;
6197
6198 TriggerFuncArg:
6199 Iconst
6200 {
6201 $$ = (Node *) makeString(psprintf("%d", $1));
6202 }
6203 | FCONST { $$ = (Node *) makeString($1); }
6204 | Sconst { $$ = (Node *) makeString($1); }
6205 | ColLabel { $$ = (Node *) makeString($1); }
6206 ;
6207
6208 OptConstrFromTable:
6209 FROM qualified_name { $$ = $2; }
6210 | /*EMPTY*/ { $$ = NULL; }
6211 ;
6212
6213 ConstraintAttributeSpec:
6214 /*EMPTY*/
6215 { $$ = 0; }
6216 | ConstraintAttributeSpec ConstraintAttributeElem
6217 {
6218 /*
6219 * We must complain about conflicting options.
6220 * We could, but choose not to, complain about redundant
6221 * options (ie, where $2's bit is already set in $1).
6222 */
6223 int newspec = $1 | $2;
6224
6225 /* special message for this case */
6226 if ((newspec & (CAS_NOT_DEFERRABLE | CAS_INITIALLY_DEFERRED)) == (CAS_NOT_DEFERRABLE | CAS_INITIALLY_DEFERRED))
6227 ereport(ERROR,
6228 (errcode(ERRCODE_SYNTAX_ERROR),
6229 errmsg("constraint declared INITIALLY DEFERRED must be DEFERRABLE"),
6230 parser_errposition(@2)));
6231 /* generic message for other conflicts */
6232 if ((newspec & (CAS_NOT_DEFERRABLE | CAS_DEFERRABLE)) == (CAS_NOT_DEFERRABLE | CAS_DEFERRABLE) ||
6233 (newspec & (CAS_INITIALLY_IMMEDIATE | CAS_INITIALLY_DEFERRED)) == (CAS_INITIALLY_IMMEDIATE | CAS_INITIALLY_DEFERRED) ||
6234 (newspec & (CAS_NOT_ENFORCED | CAS_ENFORCED)) == (CAS_NOT_ENFORCED | CAS_ENFORCED))
6235 ereport(ERROR,
6236 (errcode(ERRCODE_SYNTAX_ERROR),
6237 errmsg("conflicting constraint properties"),
6238 parser_errposition(@2)));
6239 $$ = newspec;
6240 }
6241 ;
6242
6243 ConstraintAttributeElem:
6244 NOT DEFERRABLE { $$ = CAS_NOT_DEFERRABLE; }
6245 | DEFERRABLE { $$ = CAS_DEFERRABLE; }
6246 | INITIALLY IMMEDIATE { $$ = CAS_INITIALLY_IMMEDIATE; }
6247 | INITIALLY DEFERRED { $$ = CAS_INITIALLY_DEFERRED; }
6248 | NOT VALID { $$ = CAS_NOT_VALID; }
6249 | NO INHERIT { $$ = CAS_NO_INHERIT; }
6250 | NOT ENFORCED { $$ = CAS_NOT_ENFORCED; }
6251 | ENFORCED { $$ = CAS_ENFORCED; }
6252 ;
6253
6254
6255 /*****************************************************************************
6256 *
6257 * QUERIES :
6258 * CREATE EVENT TRIGGER ...
6259 * ALTER EVENT TRIGGER ...
6260 *
6261 *****************************************************************************/
6262
6263 CreateEventTrigStmt:
6264 CREATE EVENT TRIGGER name ON ColLabel
6265 EXECUTE FUNCTION_or_PROCEDURE func_name '(' ')'
6266 {
6267 CreateEventTrigStmt *n = makeNode(CreateEventTrigStmt);
6268
6269 n->trigname = $4;
6270 n->eventname = $6;
6271 n->whenclause = NULL;
6272 n->funcname = $9;
6273 $$ = (Node *) n;
6274 }
6275 | CREATE EVENT TRIGGER name ON ColLabel
6276 WHEN event_trigger_when_list
6277 EXECUTE FUNCTION_or_PROCEDURE func_name '(' ')'
6278 {
6279 CreateEventTrigStmt *n = makeNode(CreateEventTrigStmt);
6280
6281 n->trigname = $4;
6282 n->eventname = $6;
6283 n->whenclause = $8;
6284 n->funcname = $11;
6285 $$ = (Node *) n;
6286 }
6287 ;
6288
6289 event_trigger_when_list:
6290 event_trigger_when_item
6291 { $$ = list_make1($1); }
6292 | event_trigger_when_list AND event_trigger_when_item
6293 { $$ = lappend($1, $3); }
6294 ;
6295
6296 event_trigger_when_item:
6297 ColId IN_P '(' event_trigger_value_list ')'
6298 { $$ = makeDefElem($1, (Node *) $4, @1); }
6299 ;
6300
6301 event_trigger_value_list:
6302 SCONST
6303 { $$ = list_make1(makeString($1)); }
6304 | event_trigger_value_list ',' SCONST
6305 { $$ = lappend($1, makeString($3)); }
6306 ;
6307
6308 AlterEventTrigStmt:
6309 ALTER EVENT TRIGGER name enable_trigger
6310 {
6311 AlterEventTrigStmt *n = makeNode(AlterEventTrigStmt);
6312
6313 n->trigname = $4;
6314 n->tgenabled = $5;
6315 $$ = (Node *) n;
6316 }
6317 ;
6318
6319 enable_trigger:
6320 ENABLE_P { $$ = TRIGGER_FIRES_ON_ORIGIN; }
6321 | ENABLE_P REPLICA { $$ = TRIGGER_FIRES_ON_REPLICA; }
6322 | ENABLE_P ALWAYS { $$ = TRIGGER_FIRES_ALWAYS; }
6323 | DISABLE_P { $$ = TRIGGER_DISABLED; }
6324 ;
6325
6326 /*****************************************************************************
6327 *
6328 * QUERY :
6329 * CREATE ASSERTION ...
6330 *
6331 *****************************************************************************/
6332
6333 CreateAssertionStmt:
6334 CREATE ASSERTION any_name CHECK '(' a_expr ')' ConstraintAttributeSpec
6335 {
6336 ereport(ERROR,
6337 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
6338 errmsg("CREATE ASSERTION is not yet implemented"),
6339 parser_errposition(@1)));
6340
6341 $$ = NULL;
6342 }
6343 ;
6344
6345
6346 /*****************************************************************************
6347 *
6348 * QUERY :
6349 * define (aggregate,operator,type)
6350 *
6351 *****************************************************************************/
6352
6353 DefineStmt:
6354 CREATE opt_or_replace AGGREGATE func_name aggr_args definition
6355 {
6356 DefineStmt *n = makeNode(DefineStmt);
6357
6358 n->kind = OBJECT_AGGREGATE;
6359 n->oldstyle = false;
6360 n->replace = $2;
6361 n->defnames = $4;
6362 n->args = $5;
6363 n->definition = $6;
6364 $$ = (Node *) n;
6365 }
6366 | CREATE opt_or_replace AGGREGATE func_name old_aggr_definition
6367 {
6368 /* old-style (pre-8.2) syntax for CREATE AGGREGATE */
6369 DefineStmt *n = makeNode(DefineStmt);
6370
6371 n->kind = OBJECT_AGGREGATE;
6372 n->oldstyle = true;
6373 n->replace = $2;
6374 n->defnames = $4;
6375 n->args = NIL;
6376 n->definition = $5;
6377 $$ = (Node *) n;
6378 }
6379 | CREATE OPERATOR any_operator definition
6380 {
6381 DefineStmt *n = makeNode(DefineStmt);
6382
6383 n->kind = OBJECT_OPERATOR;
6384 n->oldstyle = false;
6385 n->defnames = $3;
6386 n->args = NIL;
6387 n->definition = $4;
6388 $$ = (Node *) n;
6389 }
6390 | CREATE TYPE_P any_name definition
6391 {
6392 DefineStmt *n = makeNode(DefineStmt);
6393
6394 n->kind = OBJECT_TYPE;
6395 n->oldstyle = false;
6396 n->defnames = $3;
6397 n->args = NIL;
6398 n->definition = $4;
6399 $$ = (Node *) n;
6400 }
6401 | CREATE TYPE_P any_name
6402 {
6403 /* Shell type (identified by lack of definition) */
6404 DefineStmt *n = makeNode(DefineStmt);
6405
6406 n->kind = OBJECT_TYPE;
6407 n->oldstyle = false;
6408 n->defnames = $3;
6409 n->args = NIL;
6410 n->definition = NIL;
6411 $$ = (Node *) n;
6412 }
6413 | CREATE TYPE_P any_name AS '(' OptTableFuncElementList ')'
6414 {
6415 CompositeTypeStmt *n = makeNode(CompositeTypeStmt);
6416
6417 /* can't use qualified_name, sigh */
6418 n->typevar = makeRangeVarFromAnyName($3, @3, yyscanner);
6419 n->coldeflist = $6;
6420 $$ = (Node *) n;
6421 }
6422 | CREATE TYPE_P any_name AS ENUM_P '(' opt_enum_val_list ')'
6423 {
6424 CreateEnumStmt *n = makeNode(CreateEnumStmt);
6425
6426 n->typeName = $3;
6427 n->vals = $7;
6428 $$ = (Node *) n;
6429 }
6430 | CREATE TYPE_P any_name AS RANGE definition
6431 {
6432 CreateRangeStmt *n = makeNode(CreateRangeStmt);
6433
6434 n->typeName = $3;
6435 n->params = $6;
6436 $$ = (Node *) n;
6437 }
6438 | CREATE TEXT_P SEARCH PARSER any_name definition
6439 {
6440 DefineStmt *n = makeNode(DefineStmt);
6441
6442 n->kind = OBJECT_TSPARSER;
6443 n->args = NIL;
6444 n->defnames = $5;
6445 n->definition = $6;
6446 $$ = (Node *) n;
6447 }
6448 | CREATE TEXT_P SEARCH DICTIONARY any_name definition
6449 {
6450 DefineStmt *n = makeNode(DefineStmt);
6451
6452 n->kind = OBJECT_TSDICTIONARY;
6453 n->args = NIL;
6454 n->defnames = $5;
6455 n->definition = $6;
6456 $$ = (Node *) n;
6457 }
6458 | CREATE TEXT_P SEARCH TEMPLATE any_name definition
6459 {
6460 DefineStmt *n = makeNode(DefineStmt);
6461
6462 n->kind = OBJECT_TSTEMPLATE;
6463 n->args = NIL;
6464 n->defnames = $5;
6465 n->definition = $6;
6466 $$ = (Node *) n;
6467 }
6468 | CREATE TEXT_P SEARCH CONFIGURATION any_name definition
6469 {
6470 DefineStmt *n = makeNode(DefineStmt);
6471
6472 n->kind = OBJECT_TSCONFIGURATION;
6473 n->args = NIL;
6474 n->defnames = $5;
6475 n->definition = $6;
6476 $$ = (Node *) n;
6477 }
6478 | CREATE COLLATION any_name definition
6479 {
6480 DefineStmt *n = makeNode(DefineStmt);
6481
6482 n->kind = OBJECT_COLLATION;
6483 n->args = NIL;
6484 n->defnames = $3;
6485 n->definition = $4;
6486 $$ = (Node *) n;
6487 }
6488 | CREATE COLLATION IF_P NOT EXISTS any_name definition
6489 {
6490 DefineStmt *n = makeNode(DefineStmt);
6491
6492 n->kind = OBJECT_COLLATION;
6493 n->args = NIL;
6494 n->defnames = $6;
6495 n->definition = $7;
6496 n->if_not_exists = true;
6497 $$ = (Node *) n;
6498 }
6499 | CREATE COLLATION any_name FROM any_name
6500 {
6501 DefineStmt *n = makeNode(DefineStmt);
6502
6503 n->kind = OBJECT_COLLATION;
6504 n->args = NIL;
6505 n->defnames = $3;
6506 n->definition = list_make1(makeDefElem("from", (Node *) $5, @5));
6507 $$ = (Node *) n;
6508 }
6509 | CREATE COLLATION IF_P NOT EXISTS any_name FROM any_name
6510 {
6511 DefineStmt *n = makeNode(DefineStmt);
6512
6513 n->kind = OBJECT_COLLATION;
6514 n->args = NIL;
6515 n->defnames = $6;
6516 n->definition = list_make1(makeDefElem("from", (Node *) $8, @8));
6517 n->if_not_exists = true;
6518 $$ = (Node *) n;
6519 }
6520 ;
6521
6522 definition: '(' def_list ')' { $$ = $2; }
6523 ;
6524
6525 def_list: def_elem { $$ = list_make1($1); }
6526 | def_list ',' def_elem { $$ = lappend($1, $3); }
6527 ;
6528
6529 def_elem: ColLabel '=' def_arg
6530 {
6531 $$ = makeDefElem($1, (Node *) $3, @1);
6532 }
6533 | ColLabel
6534 {
6535 $$ = makeDefElem($1, NULL, @1);
6536 }
6537 ;
6538
6539 /* Note: any simple identifier will be returned as a type name! */
6540 def_arg: func_type { $$ = (Node *) $1; }
6541 | reserved_keyword { $$ = (Node *) makeString(pstrdup($1)); }
6542 | qual_all_Op { $$ = (Node *) $1; }
6543 | NumericOnly { $$ = (Node *) $1; }
6544 | Sconst { $$ = (Node *) makeString($1); }
6545 | NONE { $$ = (Node *) makeString(pstrdup($1)); }
6546 ;
6547
6548 old_aggr_definition: '(' old_aggr_list ')' { $$ = $2; }
6549 ;
6550
6551 old_aggr_list: old_aggr_elem { $$ = list_make1($1); }
6552 | old_aggr_list ',' old_aggr_elem { $$ = lappend($1, $3); }
6553 ;
6554
6555 /*
6556 * Must use IDENT here to avoid reduce/reduce conflicts; fortunately none of
6557 * the item names needed in old aggregate definitions are likely to become
6558 * SQL keywords.
6559 */
6560 old_aggr_elem: IDENT '=' def_arg
6561 {
6562 $$ = makeDefElem($1, (Node *) $3, @1);
6563 }
6564 ;
6565
6566 opt_enum_val_list:
6567 enum_val_list { $$ = $1; }
6568 | /*EMPTY*/ { $$ = NIL; }
6569 ;
6570
6571 enum_val_list: Sconst
6572 { $$ = list_make1(makeString($1)); }
6573 | enum_val_list ',' Sconst
6574 { $$ = lappend($1, makeString($3)); }
6575 ;
6576
6577 /*****************************************************************************
6578 *
6579 * ALTER TYPE enumtype ADD ...
6580 *
6581 *****************************************************************************/
6582
6583 AlterEnumStmt:
6584 ALTER TYPE_P any_name ADD_P VALUE_P opt_if_not_exists Sconst
6585 {
6586 AlterEnumStmt *n = makeNode(AlterEnumStmt);
6587
6588 n->typeName = $3;
6589 n->oldVal = NULL;
6590 n->newVal = $7;
6591 n->newValNeighbor = NULL;
6592 n->newValIsAfter = true;
6593 n->skipIfNewValExists = $6;
6594 $$ = (Node *) n;
6595 }
6596 | ALTER TYPE_P any_name ADD_P VALUE_P opt_if_not_exists Sconst BEFORE Sconst
6597 {
6598 AlterEnumStmt *n = makeNode(AlterEnumStmt);
6599
6600 n->typeName = $3;
6601 n->oldVal = NULL;
6602 n->newVal = $7;
6603 n->newValNeighbor = $9;
6604 n->newValIsAfter = false;
6605 n->skipIfNewValExists = $6;
6606 $$ = (Node *) n;
6607 }
6608 | ALTER TYPE_P any_name ADD_P VALUE_P opt_if_not_exists Sconst AFTER Sconst
6609 {
6610 AlterEnumStmt *n = makeNode(AlterEnumStmt);
6611
6612 n->typeName = $3;
6613 n->oldVal = NULL;
6614 n->newVal = $7;
6615 n->newValNeighbor = $9;
6616 n->newValIsAfter = true;
6617 n->skipIfNewValExists = $6;
6618 $$ = (Node *) n;
6619 }
6620 | ALTER TYPE_P any_name RENAME VALUE_P Sconst TO Sconst
6621 {
6622 AlterEnumStmt *n = makeNode(AlterEnumStmt);
6623
6624 n->typeName = $3;
6625 n->oldVal = $6;
6626 n->newVal = $8;
6627 n->newValNeighbor = NULL;
6628 n->newValIsAfter = false;
6629 n->skipIfNewValExists = false;
6630 $$ = (Node *) n;
6631 }
6632 | ALTER TYPE_P any_name DROP VALUE_P Sconst
6633 {
6634 /*
6635 * The following problems must be solved before this can be
6636 * implemented:
6637 *
6638 * - There must be no instance of the target value in
6639 * any table.
6640 *
6641 * - The value must not appear in any catalog metadata,
6642 * such as stored view expressions or column defaults.
6643 *
6644 * - The value must not appear in any non-leaf page of a
6645 * btree (and similar issues with other index types).
6646 * This is problematic because a value could persist
6647 * there long after it's gone from user-visible data.
6648 *
6649 * - Concurrent sessions must not be able to insert the
6650 * value while the preceding conditions are being checked.
6651 *
6652 * - Possibly more...
6653 */
6654 ereport(ERROR,
6655 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
6656 errmsg("dropping an enum value is not implemented"),
6657 parser_errposition(@4)));
6658 }
6659 ;
6660
6661 opt_if_not_exists: IF_P NOT EXISTS { $$ = true; }
6662 | /* EMPTY */ { $$ = false; }
6663 ;
6664
6665
6666 /*****************************************************************************
6667 *
6668 * QUERIES :
6669 * CREATE OPERATOR CLASS ...
6670 * CREATE OPERATOR FAMILY ...
6671 * ALTER OPERATOR FAMILY ...
6672 * DROP OPERATOR CLASS ...
6673 * DROP OPERATOR FAMILY ...
6674 *
6675 *****************************************************************************/
6676
6677 CreateOpClassStmt:
6678 CREATE OPERATOR CLASS any_name opt_default FOR TYPE_P Typename
6679 USING name opt_opfamily AS opclass_item_list
6680 {
6681 CreateOpClassStmt *n = makeNode(CreateOpClassStmt);
6682
6683 n->opclassname = $4;
6684 n->isDefault = $5;
6685 n->datatype = $8;
6686 n->amname = $10;
6687 n->opfamilyname = $11;
6688 n->items = $13;
6689 $$ = (Node *) n;
6690 }
6691 ;
6692
6693 opclass_item_list:
6694 opclass_item { $$ = list_make1($1); }
6695 | opclass_item_list ',' opclass_item { $$ = lappend($1, $3); }
6696 ;
6697
6698 opclass_item:
6699 OPERATOR Iconst any_operator opclass_purpose
6700 {
6701 CreateOpClassItem *n = makeNode(CreateOpClassItem);
6702 ObjectWithArgs *owa = makeNode(ObjectWithArgs);
6703
6704 owa->objname = $3;
6705 owa->objargs = NIL;
6706 n->itemtype = OPCLASS_ITEM_OPERATOR;
6707 n->name = owa;
6708 n->number = $2;
6709 n->order_family = $4;
6710 $$ = (Node *) n;
6711 }
6712 | OPERATOR Iconst operator_with_argtypes opclass_purpose
6713 {
6714 CreateOpClassItem *n = makeNode(CreateOpClassItem);
6715
6716 n->itemtype = OPCLASS_ITEM_OPERATOR;
6717 n->name = $3;
6718 n->number = $2;
6719 n->order_family = $4;
6720 $$ = (Node *) n;
6721 }
6722 | FUNCTION Iconst function_with_argtypes
6723 {
6724 CreateOpClassItem *n = makeNode(CreateOpClassItem);
6725
6726 n->itemtype = OPCLASS_ITEM_FUNCTION;
6727 n->name = $3;
6728 n->number = $2;
6729 $$ = (Node *) n;
6730 }
6731 | FUNCTION Iconst '(' type_list ')' function_with_argtypes
6732 {
6733 CreateOpClassItem *n = makeNode(CreateOpClassItem);
6734
6735 n->itemtype = OPCLASS_ITEM_FUNCTION;
6736 n->name = $6;
6737 n->number = $2;
6738 n->class_args = $4;
6739 $$ = (Node *) n;
6740 }
6741 | STORAGE Typename
6742 {
6743 CreateOpClassItem *n = makeNode(CreateOpClassItem);
6744
6745 n->itemtype = OPCLASS_ITEM_STORAGETYPE;
6746 n->storedtype = $2;
6747 $$ = (Node *) n;
6748 }
6749 ;
6750
6751 opt_default: DEFAULT { $$ = true; }
6752 | /*EMPTY*/ { $$ = false; }
6753 ;
6754
6755 opt_opfamily: FAMILY any_name { $$ = $2; }
6756 | /*EMPTY*/ { $$ = NIL; }
6757 ;
6758
6759 opclass_purpose: FOR SEARCH { $$ = NIL; }
6760 | FOR ORDER BY any_name { $$ = $4; }
6761 | /*EMPTY*/ { $$ = NIL; }
6762 ;
6763
6764
6765 CreateOpFamilyStmt:
6766 CREATE OPERATOR FAMILY any_name USING name
6767 {
6768 CreateOpFamilyStmt *n = makeNode(CreateOpFamilyStmt);
6769
6770 n->opfamilyname = $4;
6771 n->amname = $6;
6772 $$ = (Node *) n;
6773 }
6774 ;
6775
6776 AlterOpFamilyStmt:
6777 ALTER OPERATOR FAMILY any_name USING name ADD_P opclass_item_list
6778 {
6779 AlterOpFamilyStmt *n = makeNode(AlterOpFamilyStmt);
6780
6781 n->opfamilyname = $4;
6782 n->amname = $6;
6783 n->isDrop = false;
6784 n->items = $8;
6785 $$ = (Node *) n;
6786 }
6787 | ALTER OPERATOR FAMILY any_name USING name DROP opclass_drop_list
6788 {
6789 AlterOpFamilyStmt *n = makeNode(AlterOpFamilyStmt);
6790
6791 n->opfamilyname = $4;
6792 n->amname = $6;
6793 n->isDrop = true;
6794 n->items = $8;
6795 $$ = (Node *) n;
6796 }
6797 ;
6798
6799 opclass_drop_list:
6800 opclass_drop { $$ = list_make1($1); }
6801 | opclass_drop_list ',' opclass_drop { $$ = lappend($1, $3); }
6802 ;
6803
6804 opclass_drop:
6805 OPERATOR Iconst '(' type_list ')'
6806 {
6807 CreateOpClassItem *n = makeNode(CreateOpClassItem);
6808
6809 n->itemtype = OPCLASS_ITEM_OPERATOR;
6810 n->number = $2;
6811 n->class_args = $4;
6812 $$ = (Node *) n;
6813 }
6814 | FUNCTION Iconst '(' type_list ')'
6815 {
6816 CreateOpClassItem *n = makeNode(CreateOpClassItem);
6817
6818 n->itemtype = OPCLASS_ITEM_FUNCTION;
6819 n->number = $2;
6820 n->class_args = $4;
6821 $$ = (Node *) n;
6822 }
6823 ;
6824
6825
6826 DropOpClassStmt:
6827 DROP OPERATOR CLASS any_name USING name opt_drop_behavior
6828 {
6829 DropStmt *n = makeNode(DropStmt);
6830
6831 n->objects = list_make1(lcons(makeString($6), $4));
6832 n->removeType = OBJECT_OPCLASS;
6833 n->behavior = $7;
6834 n->missing_ok = false;
6835 n->concurrent = false;
6836 $$ = (Node *) n;
6837 }
6838 | DROP OPERATOR CLASS IF_P EXISTS any_name USING name opt_drop_behavior
6839 {
6840 DropStmt *n = makeNode(DropStmt);
6841
6842 n->objects = list_make1(lcons(makeString($8), $6));
6843 n->removeType = OBJECT_OPCLASS;
6844 n->behavior = $9;
6845 n->missing_ok = true;
6846 n->concurrent = false;
6847 $$ = (Node *) n;
6848 }
6849 ;
6850
6851 DropOpFamilyStmt:
6852 DROP OPERATOR FAMILY any_name USING name opt_drop_behavior
6853 {
6854 DropStmt *n = makeNode(DropStmt);
6855
6856 n->objects = list_make1(lcons(makeString($6), $4));
6857 n->removeType = OBJECT_OPFAMILY;
6858 n->behavior = $7;
6859 n->missing_ok = false;
6860 n->concurrent = false;
6861 $$ = (Node *) n;
6862 }
6863 | DROP OPERATOR FAMILY IF_P EXISTS any_name USING name opt_drop_behavior
6864 {
6865 DropStmt *n = makeNode(DropStmt);
6866
6867 n->objects = list_make1(lcons(makeString($8), $6));
6868 n->removeType = OBJECT_OPFAMILY;
6869 n->behavior = $9;
6870 n->missing_ok = true;
6871 n->concurrent = false;
6872 $$ = (Node *) n;
6873 }
6874 ;
6875
6876
6877 /*****************************************************************************
6878 *
6879 * QUERY:
6880 *
6881 * DROP OWNED BY username [, username ...] [ RESTRICT | CASCADE ]
6882 * REASSIGN OWNED BY username [, username ...] TO username
6883 *
6884 *****************************************************************************/
6885 DropOwnedStmt:
6886 DROP OWNED BY role_list opt_drop_behavior
6887 {
6888 DropOwnedStmt *n = makeNode(DropOwnedStmt);
6889
6890 n->roles = $4;
6891 n->behavior = $5;
6892 $$ = (Node *) n;
6893 }
6894 ;
6895
6896 ReassignOwnedStmt:
6897 REASSIGN OWNED BY role_list TO RoleSpec
6898 {
6899 ReassignOwnedStmt *n = makeNode(ReassignOwnedStmt);
6900
6901 n->roles = $4;
6902 n->newrole = $6;
6903 $$ = (Node *) n;
6904 }
6905 ;
6906
6907 /*****************************************************************************
6908 *
6909 * QUERY:
6910 *
6911 * DROP itemtype [ IF EXISTS ] itemname [, itemname ...]
6912 * [ RESTRICT | CASCADE ]
6913 *
6914 *****************************************************************************/
6915
6916 DropStmt: DROP object_type_any_name IF_P EXISTS any_name_list opt_drop_behavior
6917 {
6918 DropStmt *n = makeNode(DropStmt);
6919
6920 n->removeType = $2;
6921 n->missing_ok = true;
6922 n->objects = $5;
6923 n->behavior = $6;
6924 n->concurrent = false;
6925 $$ = (Node *) n;
6926 }
6927 | DROP object_type_any_name any_name_list opt_drop_behavior
6928 {
6929 DropStmt *n = makeNode(DropStmt);
6930
6931 n->removeType = $2;
6932 n->missing_ok = false;
6933 n->objects = $3;
6934 n->behavior = $4;
6935 n->concurrent = false;
6936 $$ = (Node *) n;
6937 }
6938 | DROP drop_type_name IF_P EXISTS name_list opt_drop_behavior
6939 {
6940 DropStmt *n = makeNode(DropStmt);
6941
6942 n->removeType = $2;
6943 n->missing_ok = true;
6944 n->objects = $5;
6945 n->behavior = $6;
6946 n->concurrent = false;
6947 $$ = (Node *) n;
6948 }
6949 | DROP drop_type_name name_list opt_drop_behavior
6950 {
6951 DropStmt *n = makeNode(DropStmt);
6952
6953 n->removeType = $2;
6954 n->missing_ok = false;
6955 n->objects = $3;
6956 n->behavior = $4;
6957 n->concurrent = false;
6958 $$ = (Node *) n;
6959 }
6960 | DROP object_type_name_on_any_name name ON any_name opt_drop_behavior
6961 {
6962 DropStmt *n = makeNode(DropStmt);
6963
6964 n->removeType = $2;
6965 n->objects = list_make1(lappend($5, makeString($3)));
6966 n->behavior = $6;
6967 n->missing_ok = false;
6968 n->concurrent = false;
6969 $$ = (Node *) n;
6970 }
6971 | DROP object_type_name_on_any_name IF_P EXISTS name ON any_name opt_drop_behavior
6972 {
6973 DropStmt *n = makeNode(DropStmt);
6974
6975 n->removeType = $2;
6976 n->objects = list_make1(lappend($7, makeString($5)));
6977 n->behavior = $8;
6978 n->missing_ok = true;
6979 n->concurrent = false;
6980 $$ = (Node *) n;
6981 }
6982 | DROP TYPE_P type_name_list opt_drop_behavior
6983 {
6984 DropStmt *n = makeNode(DropStmt);
6985
6986 n->removeType = OBJECT_TYPE;
6987 n->missing_ok = false;
6988 n->objects = $3;
6989 n->behavior = $4;
6990 n->concurrent = false;
6991 $$ = (Node *) n;
6992 }
6993 | DROP TYPE_P IF_P EXISTS type_name_list opt_drop_behavior
6994 {
6995 DropStmt *n = makeNode(DropStmt);
6996
6997 n->removeType = OBJECT_TYPE;
6998 n->missing_ok = true;
6999 n->objects = $5;
7000 n->behavior = $6;
7001 n->concurrent = false;
7002 $$ = (Node *) n;
7003 }
7004 | DROP DOMAIN_P type_name_list opt_drop_behavior
7005 {
7006 DropStmt *n = makeNode(DropStmt);
7007
7008 n->removeType = OBJECT_DOMAIN;
7009 n->missing_ok = false;
7010 n->objects = $3;
7011 n->behavior = $4;
7012 n->concurrent = false;
7013 $$ = (Node *) n;
7014 }
7015 | DROP DOMAIN_P IF_P EXISTS type_name_list opt_drop_behavior
7016 {
7017 DropStmt *n = makeNode(DropStmt);
7018
7019 n->removeType = OBJECT_DOMAIN;
7020 n->missing_ok = true;
7021 n->objects = $5;
7022 n->behavior = $6;
7023 n->concurrent = false;
7024 $$ = (Node *) n;
7025 }
7026 | DROP INDEX CONCURRENTLY any_name_list opt_drop_behavior
7027 {
7028 DropStmt *n = makeNode(DropStmt);
7029
7030 n->removeType = OBJECT_INDEX;
7031 n->missing_ok = false;
7032 n->objects = $4;
7033 n->behavior = $5;
7034 n->concurrent = true;
7035 $$ = (Node *) n;
7036 }
7037 | DROP INDEX CONCURRENTLY IF_P EXISTS any_name_list opt_drop_behavior
7038 {
7039 DropStmt *n = makeNode(DropStmt);
7040
7041 n->removeType = OBJECT_INDEX;
7042 n->missing_ok = true;
7043 n->objects = $6;
7044 n->behavior = $7;
7045 n->concurrent = true;
7046 $$ = (Node *) n;
7047 }
7048 ;
7049
7050 /* object types taking any_name/any_name_list */
7051 object_type_any_name:
7052 TABLE { $$ = OBJECT_TABLE; }
7053 | SEQUENCE { $$ = OBJECT_SEQUENCE; }
7054 | VIEW { $$ = OBJECT_VIEW; }
7055 | MATERIALIZED VIEW { $$ = OBJECT_MATVIEW; }
7056 | INDEX { $$ = OBJECT_INDEX; }
7057 | FOREIGN TABLE { $$ = OBJECT_FOREIGN_TABLE; }
7058 | COLLATION { $$ = OBJECT_COLLATION; }
7059 | CONVERSION_P { $$ = OBJECT_CONVERSION; }
7060 | STATISTICS { $$ = OBJECT_STATISTIC_EXT; }
7061 | TEXT_P SEARCH PARSER { $$ = OBJECT_TSPARSER; }
7062 | TEXT_P SEARCH DICTIONARY { $$ = OBJECT_TSDICTIONARY; }
7063 | TEXT_P SEARCH TEMPLATE { $$ = OBJECT_TSTEMPLATE; }
7064 | TEXT_P SEARCH CONFIGURATION { $$ = OBJECT_TSCONFIGURATION; }
7065 ;
7066
7067 /*
7068 * object types taking name/name_list
7069 *
7070 * DROP handles some of them separately
7071 */
7072
7073 object_type_name:
7074 drop_type_name { $$ = $1; }
7075 | DATABASE { $$ = OBJECT_DATABASE; }
7076 | ROLE { $$ = OBJECT_ROLE; }
7077 | SUBSCRIPTION { $$ = OBJECT_SUBSCRIPTION; }
7078 | TABLESPACE { $$ = OBJECT_TABLESPACE; }
7079 ;
7080
7081 drop_type_name:
7082 ACCESS METHOD { $$ = OBJECT_ACCESS_METHOD; }
7083 | EVENT TRIGGER { $$ = OBJECT_EVENT_TRIGGER; }
7084 | EXTENSION { $$ = OBJECT_EXTENSION; }
7085 | FOREIGN DATA_P WRAPPER { $$ = OBJECT_FDW; }
7086 | opt_procedural LANGUAGE { $$ = OBJECT_LANGUAGE; }
7087 | PUBLICATION { $$ = OBJECT_PUBLICATION; }
7088 | SCHEMA { $$ = OBJECT_SCHEMA; }
7089 | SERVER { $$ = OBJECT_FOREIGN_SERVER; }
7090 ;
7091
7092 /* object types attached to a table */
7093 object_type_name_on_any_name:
7094 POLICY { $$ = OBJECT_POLICY; }
7095 | RULE { $$ = OBJECT_RULE; }
7096 | TRIGGER { $$ = OBJECT_TRIGGER; }
7097 ;
7098
7099 any_name_list:
7100 any_name { $$ = list_make1($1); }
7101 | any_name_list ',' any_name { $$ = lappend($1, $3); }
7102 ;
7103
7104 any_name: ColId { $$ = list_make1(makeString($1)); }
7105 | ColId attrs { $$ = lcons(makeString($1), $2); }
7106 ;
7107
7108 attrs: '.' attr_name
7109 { $$ = list_make1(makeString($2)); }
7110 | attrs '.' attr_name
7111 { $$ = lappend($1, makeString($3)); }
7112 ;
7113
7114 type_name_list:
7115 Typename { $$ = list_make1($1); }
7116 | type_name_list ',' Typename { $$ = lappend($1, $3); }
7117 ;
7118
7119 /*****************************************************************************
7120 *
7121 * QUERY:
7122 * truncate table relname1, relname2, ...
7123 *
7124 *****************************************************************************/
7125
7126 TruncateStmt:
7127 TRUNCATE opt_table relation_expr_list opt_restart_seqs opt_drop_behavior
7128 {
7129 TruncateStmt *n = makeNode(TruncateStmt);
7130
7131 n->relations = $3;
7132 n->restart_seqs = $4;
7133 n->behavior = $5;
7134 $$ = (Node *) n;
7135 }
7136 ;
7137
7138 opt_restart_seqs:
7139 CONTINUE_P IDENTITY_P { $$ = false; }
7140 | RESTART IDENTITY_P { $$ = true; }
7141 | /* EMPTY */ { $$ = false; }
7142 ;
7143
7144 /*****************************************************************************
7145 *
7146 * COMMENT ON <object> IS <text>
7147 *
7148 *****************************************************************************/
7149
7150 CommentStmt:
7151 COMMENT ON object_type_any_name any_name IS comment_text
7152 {
7153 CommentStmt *n = makeNode(CommentStmt);
7154
7155 n->objtype = $3;
7156 n->object = (Node *) $4;
7157 n->comment = $6;
7158 $$ = (Node *) n;
7159 }
7160 | COMMENT ON COLUMN any_name IS comment_text
7161 {
7162 CommentStmt *n = makeNode(CommentStmt);
7163
7164 n->objtype = OBJECT_COLUMN;
7165 n->object = (Node *) $4;
7166 n->comment = $6;
7167 $$ = (Node *) n;
7168 }
7169 | COMMENT ON object_type_name name IS comment_text
7170 {
7171 CommentStmt *n = makeNode(CommentStmt);
7172
7173 n->objtype = $3;
7174 n->object = (Node *) makeString($4);
7175 n->comment = $6;
7176 $$ = (Node *) n;
7177 }
7178 | COMMENT ON TYPE_P Typename IS comment_text
7179 {
7180 CommentStmt *n = makeNode(CommentStmt);
7181
7182 n->objtype = OBJECT_TYPE;
7183 n->object = (Node *) $4;
7184 n->comment = $6;
7185 $$ = (Node *) n;
7186 }
7187 | COMMENT ON DOMAIN_P Typename IS comment_text
7188 {
7189 CommentStmt *n = makeNode(CommentStmt);
7190
7191 n->objtype = OBJECT_DOMAIN;
7192 n->object = (Node *) $4;
7193 n->comment = $6;
7194 $$ = (Node *) n;
7195 }
7196 | COMMENT ON AGGREGATE aggregate_with_argtypes IS comment_text
7197 {
7198 CommentStmt *n = makeNode(CommentStmt);
7199
7200 n->objtype = OBJECT_AGGREGATE;
7201 n->object = (Node *) $4;
7202 n->comment = $6;
7203 $$ = (Node *) n;
7204 }
7205 | COMMENT ON FUNCTION function_with_argtypes IS comment_text
7206 {
7207 CommentStmt *n = makeNode(CommentStmt);
7208
7209 n->objtype = OBJECT_FUNCTION;
7210 n->object = (Node *) $4;
7211 n->comment = $6;
7212 $$ = (Node *) n;
7213 }
7214 | COMMENT ON OPERATOR operator_with_argtypes IS comment_text
7215 {
7216 CommentStmt *n = makeNode(CommentStmt);
7217
7218 n->objtype = OBJECT_OPERATOR;
7219 n->object = (Node *) $4;
7220 n->comment = $6;
7221 $$ = (Node *) n;
7222 }
7223 | COMMENT ON CONSTRAINT name ON any_name IS comment_text
7224 {
7225 CommentStmt *n = makeNode(CommentStmt);
7226
7227 n->objtype = OBJECT_TABCONSTRAINT;
7228 n->object = (Node *) lappend($6, makeString($4));
7229 n->comment = $8;
7230 $$ = (Node *) n;
7231 }
7232 | COMMENT ON CONSTRAINT name ON DOMAIN_P any_name IS comment_text
7233 {
7234 CommentStmt *n = makeNode(CommentStmt);
7235
7236 n->objtype = OBJECT_DOMCONSTRAINT;
7237 /*
7238 * should use Typename not any_name in the production, but
7239 * there's a shift/reduce conflict if we do that, so fix it
7240 * up here.
7241 */
7242 n->object = (Node *) list_make2(makeTypeNameFromNameList($7), makeString($4));
7243 n->comment = $9;
7244 $$ = (Node *) n;
7245 }
7246 | COMMENT ON object_type_name_on_any_name name ON any_name IS comment_text
7247 {
7248 CommentStmt *n = makeNode(CommentStmt);
7249
7250 n->objtype = $3;
7251 n->object = (Node *) lappend($6, makeString($4));
7252 n->comment = $8;
7253 $$ = (Node *) n;
7254 }
7255 | COMMENT ON PROCEDURE function_with_argtypes IS comment_text
7256 {
7257 CommentStmt *n = makeNode(CommentStmt);
7258
7259 n->objtype = OBJECT_PROCEDURE;
7260 n->object = (Node *) $4;
7261 n->comment = $6;
7262 $$ = (Node *) n;
7263 }
7264 | COMMENT ON ROUTINE function_with_argtypes IS comment_text
7265 {
7266 CommentStmt *n = makeNode(CommentStmt);
7267
7268 n->objtype = OBJECT_ROUTINE;
7269 n->object = (Node *) $4;
7270 n->comment = $6;
7271 $$ = (Node *) n;
7272 }
7273 | COMMENT ON TRANSFORM FOR Typename LANGUAGE name IS comment_text
7274 {
7275 CommentStmt *n = makeNode(CommentStmt);
7276
7277 n->objtype = OBJECT_TRANSFORM;
7278 n->object = (Node *) list_make2($5, makeString($7));
7279 n->comment = $9;
7280 $$ = (Node *) n;
7281 }
7282 | COMMENT ON OPERATOR CLASS any_name USING name IS comment_text
7283 {
7284 CommentStmt *n = makeNode(CommentStmt);
7285
7286 n->objtype = OBJECT_OPCLASS;
7287 n->object = (Node *) lcons(makeString($7), $5);
7288 n->comment = $9;
7289 $$ = (Node *) n;
7290 }
7291 | COMMENT ON OPERATOR FAMILY any_name USING name IS comment_text
7292 {
7293 CommentStmt *n = makeNode(CommentStmt);
7294
7295 n->objtype = OBJECT_OPFAMILY;
7296 n->object = (Node *) lcons(makeString($7), $5);
7297 n->comment = $9;
7298 $$ = (Node *) n;
7299 }
7300 | COMMENT ON LARGE_P OBJECT_P NumericOnly IS comment_text
7301 {
7302 CommentStmt *n = makeNode(CommentStmt);
7303
7304 n->objtype = OBJECT_LARGEOBJECT;
7305 n->object = (Node *) $5;
7306 n->comment = $7;
7307 $$ = (Node *) n;
7308 }
7309 | COMMENT ON CAST '(' Typename AS Typename ')' IS comment_text
7310 {
7311 CommentStmt *n = makeNode(CommentStmt);
7312
7313 n->objtype = OBJECT_CAST;
7314 n->object = (Node *) list_make2($5, $7);
7315 n->comment = $10;
7316 $$ = (Node *) n;
7317 }
7318 ;
7319
7320 comment_text:
7321 Sconst { $$ = $1; }
7322 | NULL_P { $$ = NULL; }
7323 ;
7324
7325
7326 /*****************************************************************************
7327 *
7328 * SECURITY LABEL [FOR <provider>] ON <object> IS <label>
7329 *
7330 * As with COMMENT ON, <object> can refer to various types of database
7331 * objects (e.g. TABLE, COLUMN, etc.).
7332 *
7333 *****************************************************************************/
7334
7335 SecLabelStmt:
7336 SECURITY LABEL opt_provider ON object_type_any_name any_name
7337 IS security_label
7338 {
7339 SecLabelStmt *n = makeNode(SecLabelStmt);
7340
7341 n->provider = $3;
7342 n->objtype = $5;
7343 n->object = (Node *) $6;
7344 n->label = $8;
7345 $$ = (Node *) n;
7346 }
7347 | SECURITY LABEL opt_provider ON COLUMN any_name
7348 IS security_label
7349 {
7350 SecLabelStmt *n = makeNode(SecLabelStmt);
7351
7352 n->provider = $3;
7353 n->objtype = OBJECT_COLUMN;
7354 n->object = (Node *) $6;
7355 n->label = $8;
7356 $$ = (Node *) n;
7357 }
7358 | SECURITY LABEL opt_provider ON object_type_name name
7359 IS security_label
7360 {
7361 SecLabelStmt *n = makeNode(SecLabelStmt);
7362
7363 n->provider = $3;
7364 n->objtype = $5;
7365 n->object = (Node *) makeString($6);
7366 n->label = $8;
7367 $$ = (Node *) n;
7368 }
7369 | SECURITY LABEL opt_provider ON TYPE_P Typename
7370 IS security_label
7371 {
7372 SecLabelStmt *n = makeNode(SecLabelStmt);
7373
7374 n->provider = $3;
7375 n->objtype = OBJECT_TYPE;
7376 n->object = (Node *) $6;
7377 n->label = $8;
7378 $$ = (Node *) n;
7379 }
7380 | SECURITY LABEL opt_provider ON DOMAIN_P Typename
7381 IS security_label
7382 {
7383 SecLabelStmt *n = makeNode(SecLabelStmt);
7384
7385 n->provider = $3;
7386 n->objtype = OBJECT_DOMAIN;
7387 n->object = (Node *) $6;
7388 n->label = $8;
7389 $$ = (Node *) n;
7390 }
7391 | SECURITY LABEL opt_provider ON AGGREGATE aggregate_with_argtypes
7392 IS security_label
7393 {
7394 SecLabelStmt *n = makeNode(SecLabelStmt);
7395
7396 n->provider = $3;
7397 n->objtype = OBJECT_AGGREGATE;
7398 n->object = (Node *) $6;
7399 n->label = $8;
7400 $$ = (Node *) n;
7401 }
7402 | SECURITY LABEL opt_provider ON FUNCTION function_with_argtypes
7403 IS security_label
7404 {
7405 SecLabelStmt *n = makeNode(SecLabelStmt);
7406
7407 n->provider = $3;
7408 n->objtype = OBJECT_FUNCTION;
7409 n->object = (Node *) $6;
7410 n->label = $8;
7411 $$ = (Node *) n;
7412 }
7413 | SECURITY LABEL opt_provider ON LARGE_P OBJECT_P NumericOnly
7414 IS security_label
7415 {
7416 SecLabelStmt *n = makeNode(SecLabelStmt);
7417
7418 n->provider = $3;
7419 n->objtype = OBJECT_LARGEOBJECT;
7420 n->object = (Node *) $7;
7421 n->label = $9;
7422 $$ = (Node *) n;
7423 }
7424 | SECURITY LABEL opt_provider ON PROCEDURE function_with_argtypes
7425 IS security_label
7426 {
7427 SecLabelStmt *n = makeNode(SecLabelStmt);
7428
7429 n->provider = $3;
7430 n->objtype = OBJECT_PROCEDURE;
7431 n->object = (Node *) $6;
7432 n->label = $8;
7433 $$ = (Node *) n;
7434 }
7435 | SECURITY LABEL opt_provider ON ROUTINE function_with_argtypes
7436 IS security_label
7437 {
7438 SecLabelStmt *n = makeNode(SecLabelStmt);
7439
7440 n->provider = $3;
7441 n->objtype = OBJECT_ROUTINE;
7442 n->object = (Node *) $6;
7443 n->label = $8;
7444 $$ = (Node *) n;
7445 }
7446 ;
7447
7448 opt_provider: FOR NonReservedWord_or_Sconst { $$ = $2; }
7449 | /* EMPTY */ { $$ = NULL; }
7450 ;
7451
7452 security_label: Sconst { $$ = $1; }
7453 | NULL_P { $$ = NULL; }
7454 ;
7455
7456 /*****************************************************************************
7457 *
7458 * QUERY:
7459 * fetch/move
7460 *
7461 *****************************************************************************/
7462
7463 FetchStmt: FETCH fetch_args
7464 {
7465 FetchStmt *n = (FetchStmt *) $2;
7466
7467 n->ismove = false;
7468 $$ = (Node *) n;
7469 }
7470 | MOVE fetch_args
7471 {
7472 FetchStmt *n = (FetchStmt *) $2;
7473
7474 n->ismove = true;
7475 $$ = (Node *) n;
7476 }
7477 ;
7478
7479 fetch_args: cursor_name
7480 {
7481 FetchStmt *n = makeNode(FetchStmt);
7482
7483 n->portalname = $1;
7484 n->direction = FETCH_FORWARD;
7485 n->howMany = 1;
7486 $$ = (Node *) n;
7487 }
7488 | from_in cursor_name
7489 {
7490 FetchStmt *n = makeNode(FetchStmt);
7491
7492 n->portalname = $2;
7493 n->direction = FETCH_FORWARD;
7494 n->howMany = 1;
7495 $$ = (Node *) n;
7496 }
7497 | NEXT opt_from_in cursor_name
7498 {
7499 FetchStmt *n = makeNode(FetchStmt);
7500
7501 n->portalname = $3;
7502 n->direction = FETCH_FORWARD;
7503 n->howMany = 1;
7504 $$ = (Node *) n;
7505 }
7506 | PRIOR opt_from_in cursor_name
7507 {
7508 FetchStmt *n = makeNode(FetchStmt);
7509
7510 n->portalname = $3;
7511 n->direction = FETCH_BACKWARD;
7512 n->howMany = 1;
7513 $$ = (Node *) n;
7514 }
7515 | FIRST_P opt_from_in cursor_name
7516 {
7517 FetchStmt *n = makeNode(FetchStmt);
7518
7519 n->portalname = $3;
7520 n->direction = FETCH_ABSOLUTE;
7521 n->howMany = 1;
7522 $$ = (Node *) n;
7523 }
7524 | LAST_P opt_from_in cursor_name
7525 {
7526 FetchStmt *n = makeNode(FetchStmt);
7527
7528 n->portalname = $3;
7529 n->direction = FETCH_ABSOLUTE;
7530 n->howMany = -1;
7531 $$ = (Node *) n;
7532 }
7533 | ABSOLUTE_P SignedIconst opt_from_in cursor_name
7534 {
7535 FetchStmt *n = makeNode(FetchStmt);
7536
7537 n->portalname = $4;
7538 n->direction = FETCH_ABSOLUTE;
7539 n->howMany = $2;
7540 $$ = (Node *) n;
7541 }
7542 | RELATIVE_P SignedIconst opt_from_in cursor_name
7543 {
7544 FetchStmt *n = makeNode(FetchStmt);
7545
7546 n->portalname = $4;
7547 n->direction = FETCH_RELATIVE;
7548 n->howMany = $2;
7549 $$ = (Node *) n;
7550 }
7551 | SignedIconst opt_from_in cursor_name
7552 {
7553 FetchStmt *n = makeNode(FetchStmt);
7554
7555 n->portalname = $3;
7556 n->direction = FETCH_FORWARD;
7557 n->howMany = $1;
7558 $$ = (Node *) n;
7559 }
7560 | ALL opt_from_in cursor_name
7561 {
7562 FetchStmt *n = makeNode(FetchStmt);
7563
7564 n->portalname = $3;
7565 n->direction = FETCH_FORWARD;
7566 n->howMany = FETCH_ALL;
7567 $$ = (Node *) n;
7568 }
7569 | FORWARD opt_from_in cursor_name
7570 {
7571 FetchStmt *n = makeNode(FetchStmt);
7572
7573 n->portalname = $3;
7574 n->direction = FETCH_FORWARD;
7575 n->howMany = 1;
7576 $$ = (Node *) n;
7577 }
7578 | FORWARD SignedIconst opt_from_in cursor_name
7579 {
7580 FetchStmt *n = makeNode(FetchStmt);
7581
7582 n->portalname = $4;
7583 n->direction = FETCH_FORWARD;
7584 n->howMany = $2;
7585 $$ = (Node *) n;
7586 }
7587 | FORWARD ALL opt_from_in cursor_name
7588 {
7589 FetchStmt *n = makeNode(FetchStmt);
7590
7591 n->portalname = $4;
7592 n->direction = FETCH_FORWARD;
7593 n->howMany = FETCH_ALL;
7594 $$ = (Node *) n;
7595 }
7596 | BACKWARD opt_from_in cursor_name
7597 {
7598 FetchStmt *n = makeNode(FetchStmt);
7599
7600 n->portalname = $3;
7601 n->direction = FETCH_BACKWARD;
7602 n->howMany = 1;
7603 $$ = (Node *) n;
7604 }
7605 | BACKWARD SignedIconst opt_from_in cursor_name
7606 {
7607 FetchStmt *n = makeNode(FetchStmt);
7608
7609 n->portalname = $4;
7610 n->direction = FETCH_BACKWARD;
7611 n->howMany = $2;
7612 $$ = (Node *) n;
7613 }
7614 | BACKWARD ALL opt_from_in cursor_name
7615 {
7616 FetchStmt *n = makeNode(FetchStmt);
7617
7618 n->portalname = $4;
7619 n->direction = FETCH_BACKWARD;
7620 n->howMany = FETCH_ALL;
7621 $$ = (Node *) n;
7622 }
7623 ;
7624
7625 from_in: FROM
7626 | IN_P
7627 ;
7628
7629 opt_from_in: from_in
7630 | /* EMPTY */
7631 ;
7632
7633
7634 /*****************************************************************************
7635 *
7636 * GRANT and REVOKE statements
7637 *
7638 *****************************************************************************/
7639
7640 GrantStmt: GRANT privileges ON privilege_target TO grantee_list
7641 opt_grant_grant_option opt_granted_by
7642 {
7643 GrantStmt *n = makeNode(GrantStmt);
7644
7645 n->is_grant = true;
7646 n->privileges = $2;
7647 n->targtype = ($4)->targtype;
7648 n->objtype = ($4)->objtype;
7649 n->objects = ($4)->objs;
7650 n->grantees = $6;
7651 n->grant_option = $7;
7652 n->grantor = $8;
7653 $$ = (Node *) n;
7654 }
7655 ;
7656
7657 RevokeStmt:
7658 REVOKE privileges ON privilege_target
7659 FROM grantee_list opt_granted_by opt_drop_behavior
7660 {
7661 GrantStmt *n = makeNode(GrantStmt);
7662
7663 n->is_grant = false;
7664 n->grant_option = false;
7665 n->privileges = $2;
7666 n->targtype = ($4)->targtype;
7667 n->objtype = ($4)->objtype;
7668 n->objects = ($4)->objs;
7669 n->grantees = $6;
7670 n->grantor = $7;
7671 n->behavior = $8;
7672 $$ = (Node *) n;
7673 }
7674 | REVOKE GRANT OPTION FOR privileges ON privilege_target
7675 FROM grantee_list opt_granted_by opt_drop_behavior
7676 {
7677 GrantStmt *n = makeNode(GrantStmt);
7678
7679 n->is_grant = false;
7680 n->grant_option = true;
7681 n->privileges = $5;
7682 n->targtype = ($7)->targtype;
7683 n->objtype = ($7)->objtype;
7684 n->objects = ($7)->objs;
7685 n->grantees = $9;
7686 n->grantor = $10;
7687 n->behavior = $11;
7688 $$ = (Node *) n;
7689 }
7690 ;
7691
7692
7693 /*
7694 * Privilege names are represented as strings; the validity of the privilege
7695 * names gets checked at execution. This is a bit annoying but we have little
7696 * choice because of the syntactic conflict with lists of role names in
7697 * GRANT/REVOKE. What's more, we have to call out in the "privilege"
7698 * production any reserved keywords that need to be usable as privilege names.
7699 */
7700
7701 /* either ALL [PRIVILEGES] or a list of individual privileges */
7702 privileges: privilege_list
7703 { $$ = $1; }
7704 | ALL
7705 { $$ = NIL; }
7706 | ALL PRIVILEGES
7707 { $$ = NIL; }
7708 | ALL '(' columnList ')'
7709 {
7710 AccessPriv *n = makeNode(AccessPriv);
7711
7712 n->priv_name = NULL;
7713 n->cols = $3;
7714 $$ = list_make1(n);
7715 }
7716 | ALL PRIVILEGES '(' columnList ')'
7717 {
7718 AccessPriv *n = makeNode(AccessPriv);
7719
7720 n->priv_name = NULL;
7721 n->cols = $4;
7722 $$ = list_make1(n);
7723 }
7724 ;
7725
7726 privilege_list: privilege { $$ = list_make1($1); }
7727 | privilege_list ',' privilege { $$ = lappend($1, $3); }
7728 ;
7729
7730 privilege: SELECT opt_column_list
7731 {
7732 AccessPriv *n = makeNode(AccessPriv);
7733
7734 n->priv_name = pstrdup($1);
7735 n->cols = $2;
7736 $$ = n;
7737 }
7738 | REFERENCES opt_column_list
7739 {
7740 AccessPriv *n = makeNode(AccessPriv);
7741
7742 n->priv_name = pstrdup($1);
7743 n->cols = $2;
7744 $$ = n;
7745 }
7746 | CREATE opt_column_list
7747 {
7748 AccessPriv *n = makeNode(AccessPriv);
7749
7750 n->priv_name = pstrdup($1);
7751 n->cols = $2;
7752 $$ = n;
7753 }
7754 | ALTER SYSTEM_P
7755 {
7756 AccessPriv *n = makeNode(AccessPriv);
7757 n->priv_name = pstrdup("alter system");
7758 n->cols = NIL;
7759 $$ = n;
7760 }
7761 | ColId opt_column_list
7762 {
7763 AccessPriv *n = makeNode(AccessPriv);
7764
7765 n->priv_name = $1;
7766 n->cols = $2;
7767 $$ = n;
7768 }
7769 ;
7770
7771 parameter_name_list:
7772 parameter_name
7773 {
7774 $$ = list_make1(makeString($1));
7775 }
7776 | parameter_name_list ',' parameter_name
7777 {
7778 $$ = lappend($1, makeString($3));
7779 }
7780 ;
7781
7782 parameter_name:
7783 ColId
7784 {
7785 $$ = $1;
7786 }
7787 | parameter_name '.' ColId
7788 {
7789 $$ = psprintf("%s.%s", $1, $3);
7790 }
7791 ;
7792
7793
7794 /* Don't bother trying to fold the first two rules into one using
7795 * opt_table. You're going to get conflicts.
7796 */
7797 privilege_target:
7798 qualified_name_list
7799 {
7800 PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
7801
7802 n->targtype = ACL_TARGET_OBJECT;
7803 n->objtype = OBJECT_TABLE;
7804 n->objs = $1;
7805 $$ = n;
7806 }
7807 | TABLE qualified_name_list
7808 {
7809 PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
7810
7811 n->targtype = ACL_TARGET_OBJECT;
7812 n->objtype = OBJECT_TABLE;
7813 n->objs = $2;
7814 $$ = n;
7815 }
7816 | SEQUENCE qualified_name_list
7817 {
7818 PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
7819
7820 n->targtype = ACL_TARGET_OBJECT;
7821 n->objtype = OBJECT_SEQUENCE;
7822 n->objs = $2;
7823 $$ = n;
7824 }
7825 | FOREIGN DATA_P WRAPPER name_list
7826 {
7827 PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
7828
7829 n->targtype = ACL_TARGET_OBJECT;
7830 n->objtype = OBJECT_FDW;
7831 n->objs = $4;
7832 $$ = n;
7833 }
7834 | FOREIGN SERVER name_list
7835 {
7836 PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
7837
7838 n->targtype = ACL_TARGET_OBJECT;
7839 n->objtype = OBJECT_FOREIGN_SERVER;
7840 n->objs = $3;
7841 $$ = n;
7842 }
7843 | FUNCTION function_with_argtypes_list
7844 {
7845 PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
7846
7847 n->targtype = ACL_TARGET_OBJECT;
7848 n->objtype = OBJECT_FUNCTION;
7849 n->objs = $2;
7850 $$ = n;
7851 }
7852 | PROCEDURE function_with_argtypes_list
7853 {
7854 PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
7855
7856 n->targtype = ACL_TARGET_OBJECT;
7857 n->objtype = OBJECT_PROCEDURE;
7858 n->objs = $2;
7859 $$ = n;
7860 }
7861 | ROUTINE function_with_argtypes_list
7862 {
7863 PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
7864
7865 n->targtype = ACL_TARGET_OBJECT;
7866 n->objtype = OBJECT_ROUTINE;
7867 n->objs = $2;
7868 $$ = n;
7869 }
7870 | DATABASE name_list
7871 {
7872 PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
7873
7874 n->targtype = ACL_TARGET_OBJECT;
7875 n->objtype = OBJECT_DATABASE;
7876 n->objs = $2;
7877 $$ = n;
7878 }
7879 | DOMAIN_P any_name_list
7880 {
7881 PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
7882
7883 n->targtype = ACL_TARGET_OBJECT;
7884 n->objtype = OBJECT_DOMAIN;
7885 n->objs = $2;
7886 $$ = n;
7887 }
7888 | LANGUAGE name_list
7889 {
7890 PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
7891
7892 n->targtype = ACL_TARGET_OBJECT;
7893 n->objtype = OBJECT_LANGUAGE;
7894 n->objs = $2;
7895 $$ = n;
7896 }
7897 | LARGE_P OBJECT_P NumericOnly_list
7898 {
7899 PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
7900
7901 n->targtype = ACL_TARGET_OBJECT;
7902 n->objtype = OBJECT_LARGEOBJECT;
7903 n->objs = $3;
7904 $$ = n;
7905 }
7906 | PARAMETER parameter_name_list
7907 {
7908 PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
7909 n->targtype = ACL_TARGET_OBJECT;
7910 n->objtype = OBJECT_PARAMETER_ACL;
7911 n->objs = $2;
7912 $$ = n;
7913 }
7914 | SCHEMA name_list
7915 {
7916 PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
7917
7918 n->targtype = ACL_TARGET_OBJECT;
7919 n->objtype = OBJECT_SCHEMA;
7920 n->objs = $2;
7921 $$ = n;
7922 }
7923 | TABLESPACE name_list
7924 {
7925 PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
7926
7927 n->targtype = ACL_TARGET_OBJECT;
7928 n->objtype = OBJECT_TABLESPACE;
7929 n->objs = $2;
7930 $$ = n;
7931 }
7932 | TYPE_P any_name_list
7933 {
7934 PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
7935
7936 n->targtype = ACL_TARGET_OBJECT;
7937 n->objtype = OBJECT_TYPE;
7938 n->objs = $2;
7939 $$ = n;
7940 }
7941 | ALL TABLES IN_P SCHEMA name_list
7942 {
7943 PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
7944
7945 n->targtype = ACL_TARGET_ALL_IN_SCHEMA;
7946 n->objtype = OBJECT_TABLE;
7947 n->objs = $5;
7948 $$ = n;
7949 }
7950 | ALL SEQUENCES IN_P SCHEMA name_list
7951 {
7952 PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
7953
7954 n->targtype = ACL_TARGET_ALL_IN_SCHEMA;
7955 n->objtype = OBJECT_SEQUENCE;
7956 n->objs = $5;
7957 $$ = n;
7958 }
7959 | ALL FUNCTIONS IN_P SCHEMA name_list
7960 {
7961 PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
7962
7963 n->targtype = ACL_TARGET_ALL_IN_SCHEMA;
7964 n->objtype = OBJECT_FUNCTION;
7965 n->objs = $5;
7966 $$ = n;
7967 }
7968 | ALL PROCEDURES IN_P SCHEMA name_list
7969 {
7970 PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
7971
7972 n->targtype = ACL_TARGET_ALL_IN_SCHEMA;
7973 n->objtype = OBJECT_PROCEDURE;
7974 n->objs = $5;
7975 $$ = n;
7976 }
7977 | ALL ROUTINES IN_P SCHEMA name_list
7978 {
7979 PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
7980
7981 n->targtype = ACL_TARGET_ALL_IN_SCHEMA;
7982 n->objtype = OBJECT_ROUTINE;
7983 n->objs = $5;
7984 $$ = n;
7985 }
7986 ;
7987
7988
7989 grantee_list:
7990 grantee { $$ = list_make1($1); }
7991 | grantee_list ',' grantee { $$ = lappend($1, $3); }
7992 ;
7993
7994 grantee:
7995 RoleSpec { $$ = $1; }
7996 | GROUP_P RoleSpec { $$ = $2; }
7997 ;
7998
7999
8000 opt_grant_grant_option:
8001 WITH GRANT OPTION { $$ = true; }
8002 | /*EMPTY*/ { $$ = false; }
8003 ;
8004
8005 /*****************************************************************************
8006 *
8007 * GRANT and REVOKE ROLE statements
8008 *
8009 *****************************************************************************/
8010
8011 GrantRoleStmt:
8012 GRANT privilege_list TO role_list opt_granted_by
8013 {
8014 GrantRoleStmt *n = makeNode(GrantRoleStmt);
8015
8016 n->is_grant = true;
8017 n->granted_roles = $2;
8018 n->grantee_roles = $4;
8019 n->opt = NIL;
8020 n->grantor = $5;
8021 $$ = (Node *) n;
8022 }
8023 | GRANT privilege_list TO role_list WITH grant_role_opt_list opt_granted_by
8024 {
8025 GrantRoleStmt *n = makeNode(GrantRoleStmt);
8026
8027 n->is_grant = true;
8028 n->granted_roles = $2;
8029 n->grantee_roles = $4;
8030 n->opt = $6;
8031 n->grantor = $7;
8032 $$ = (Node *) n;
8033 }
8034 ;
8035
8036 RevokeRoleStmt:
8037 REVOKE privilege_list FROM role_list opt_granted_by opt_drop_behavior
8038 {
8039 GrantRoleStmt *n = makeNode(GrantRoleStmt);
8040
8041 n->is_grant = false;
8042 n->opt = NIL;
8043 n->granted_roles = $2;
8044 n->grantee_roles = $4;
8045 n->grantor = $5;
8046 n->behavior = $6;
8047 $$ = (Node *) n;
8048 }
8049 | REVOKE ColId OPTION FOR privilege_list FROM role_list opt_granted_by opt_drop_behavior
8050 {
8051 GrantRoleStmt *n = makeNode(GrantRoleStmt);
8052 DefElem *opt;
8053
8054 opt = makeDefElem(pstrdup($2),
8055 (Node *) makeBoolean(false), @2);
8056 n->is_grant = false;
8057 n->opt = list_make1(opt);
8058 n->granted_roles = $5;
8059 n->grantee_roles = $7;
8060 n->grantor = $8;
8061 n->behavior = $9;
8062 $$ = (Node *) n;
8063 }
8064 ;
8065
8066 grant_role_opt_list:
8067 grant_role_opt_list ',' grant_role_opt { $$ = lappend($1, $3); }
8068 | grant_role_opt { $$ = list_make1($1); }
8069 ;
8070
8071 grant_role_opt:
8072 ColLabel grant_role_opt_value
8073 {
8074 $$ = makeDefElem(pstrdup($1), $2, @1);
8075 }
8076 ;
8077
8078 grant_role_opt_value:
8079 OPTION { $$ = (Node *) makeBoolean(true); }
8080 | TRUE_P { $$ = (Node *) makeBoolean(true); }
8081 | FALSE_P { $$ = (Node *) makeBoolean(false); }
8082 ;
8083
8084 opt_granted_by: GRANTED BY RoleSpec { $$ = $3; }
8085 | /*EMPTY*/ { $$ = NULL; }
8086 ;
8087
8088 /*****************************************************************************
8089 *
8090 * ALTER DEFAULT PRIVILEGES statement
8091 *
8092 *****************************************************************************/
8093
8094 AlterDefaultPrivilegesStmt:
8095 ALTER DEFAULT PRIVILEGES DefACLOptionList DefACLAction
8096 {
8097 AlterDefaultPrivilegesStmt *n = makeNode(AlterDefaultPrivilegesStmt);
8098
8099 n->options = $4;
8100 n->action = (GrantStmt *) $5;
8101 $$ = (Node *) n;
8102 }
8103 ;
8104
8105 DefACLOptionList:
8106 DefACLOptionList DefACLOption { $$ = lappend($1, $2); }
8107 | /* EMPTY */ { $$ = NIL; }
8108 ;
8109
8110 DefACLOption:
8111 IN_P SCHEMA name_list
8112 {
8113 $$ = makeDefElem("schemas", (Node *) $3, @1);
8114 }
8115 | FOR ROLE role_list
8116 {
8117 $$ = makeDefElem("roles", (Node *) $3, @1);
8118 }
8119 | FOR USER role_list
8120 {
8121 $$ = makeDefElem("roles", (Node *) $3, @1);
8122 }
8123 ;
8124
8125 /*
8126 * This should match GRANT/REVOKE, except that individual target objects
8127 * are not mentioned and we only allow a subset of object types.
8128 */
8129 DefACLAction:
8130 GRANT privileges ON defacl_privilege_target TO grantee_list
8131 opt_grant_grant_option
8132 {
8133 GrantStmt *n = makeNode(GrantStmt);
8134
8135 n->is_grant = true;
8136 n->privileges = $2;
8137 n->targtype = ACL_TARGET_DEFAULTS;
8138 n->objtype = $4;
8139 n->objects = NIL;
8140 n->grantees = $6;
8141 n->grant_option = $7;
8142 $$ = (Node *) n;
8143 }
8144 | REVOKE privileges ON defacl_privilege_target
8145 FROM grantee_list opt_drop_behavior
8146 {
8147 GrantStmt *n = makeNode(GrantStmt);
8148
8149 n->is_grant = false;
8150 n->grant_option = false;
8151 n->privileges = $2;
8152 n->targtype = ACL_TARGET_DEFAULTS;
8153 n->objtype = $4;
8154 n->objects = NIL;
8155 n->grantees = $6;
8156 n->behavior = $7;
8157 $$ = (Node *) n;
8158 }
8159 | REVOKE GRANT OPTION FOR privileges ON defacl_privilege_target
8160 FROM grantee_list opt_drop_behavior
8161 {
8162 GrantStmt *n = makeNode(GrantStmt);
8163
8164 n->is_grant = false;
8165 n->grant_option = true;
8166 n->privileges = $5;
8167 n->targtype = ACL_TARGET_DEFAULTS;
8168 n->objtype = $7;
8169 n->objects = NIL;
8170 n->grantees = $9;
8171 n->behavior = $10;
8172 $$ = (Node *) n;
8173 }
8174 ;
8175
8176 defacl_privilege_target:
8177 TABLES { $$ = OBJECT_TABLE; }
8178 | FUNCTIONS { $$ = OBJECT_FUNCTION; }
8179 | ROUTINES { $$ = OBJECT_FUNCTION; }
8180 | SEQUENCES { $$ = OBJECT_SEQUENCE; }
8181 | TYPES_P { $$ = OBJECT_TYPE; }
8182 | SCHEMAS { $$ = OBJECT_SCHEMA; }
8183 | LARGE_P OBJECTS_P { $$ = OBJECT_LARGEOBJECT; }
8184 ;
8185
8186
8187 /*****************************************************************************
8188 *
8189 * QUERY: CREATE INDEX
8190 *
8191 * Note: we cannot put TABLESPACE clause after WHERE clause unless we are
8192 * willing to make TABLESPACE a fully reserved word.
8193 *****************************************************************************/
8194
8195 IndexStmt: CREATE opt_unique INDEX opt_concurrently opt_single_name
8196 ON relation_expr access_method_clause '(' index_params ')'
8197 opt_include opt_unique_null_treatment opt_reloptions OptTableSpace where_clause
8198 {
8199 IndexStmt *n = makeNode(IndexStmt);
8200
8201 n->unique = $2;
8202 n->concurrent = $4;
8203 n->idxname = $5;
8204 n->relation = $7;
8205 n->accessMethod = $8;
8206 n->indexParams = $10;
8207 n->indexIncludingParams = $12;
8208 n->nulls_not_distinct = !$13;
8209 n->options = $14;
8210 n->tableSpace = $15;
8211 n->whereClause = $16;
8212 n->excludeOpNames = NIL;
8213 n->idxcomment = NULL;
8214 n->indexOid = InvalidOid;
8215 n->oldNumber = InvalidRelFileNumber;
8216 n->oldCreateSubid = InvalidSubTransactionId;
8217 n->oldFirstRelfilelocatorSubid = InvalidSubTransactionId;
8218 n->primary = false;
8219 n->isconstraint = false;
8220 n->deferrable = false;
8221 n->initdeferred = false;
8222 n->transformed = false;
8223 n->if_not_exists = false;
8224 n->reset_default_tblspc = false;
8225 $$ = (Node *) n;
8226 }
8227 | CREATE opt_unique INDEX opt_concurrently IF_P NOT EXISTS name
8228 ON relation_expr access_method_clause '(' index_params ')'
8229 opt_include opt_unique_null_treatment opt_reloptions OptTableSpace where_clause
8230 {
8231 IndexStmt *n = makeNode(IndexStmt);
8232
8233 n->unique = $2;
8234 n->concurrent = $4;
8235 n->idxname = $8;
8236 n->relation = $10;
8237 n->accessMethod = $11;
8238 n->indexParams = $13;
8239 n->indexIncludingParams = $15;
8240 n->nulls_not_distinct = !$16;
8241 n->options = $17;
8242 n->tableSpace = $18;
8243 n->whereClause = $19;
8244 n->excludeOpNames = NIL;
8245 n->idxcomment = NULL;
8246 n->indexOid = InvalidOid;
8247 n->oldNumber = InvalidRelFileNumber;
8248 n->oldCreateSubid = InvalidSubTransactionId;
8249 n->oldFirstRelfilelocatorSubid = InvalidSubTransactionId;
8250 n->primary = false;
8251 n->isconstraint = false;
8252 n->deferrable = false;
8253 n->initdeferred = false;
8254 n->transformed = false;
8255 n->if_not_exists = true;
8256 n->reset_default_tblspc = false;
8257 $$ = (Node *) n;
8258 }
8259 ;
8260
8261 opt_unique:
8262 UNIQUE { $$ = true; }
8263 | /*EMPTY*/ { $$ = false; }
8264 ;
8265
8266 access_method_clause:
8267 USING name { $$ = $2; }
8268 | /*EMPTY*/ { $$ = DEFAULT_INDEX_TYPE; }
8269 ;
8270
8271 index_params: index_elem { $$ = list_make1($1); }
8272 | index_params ',' index_elem { $$ = lappend($1, $3); }
8273 ;
8274
8275
8276 index_elem_options:
8277 opt_collate opt_qualified_name opt_asc_desc opt_nulls_order
8278 {
8279 $$ = makeNode(IndexElem);
8280 $$->name = NULL;
8281 $$->expr = NULL;
8282 $$->indexcolname = NULL;
8283 $$->collation = $1;
8284 $$->opclass = $2;
8285 $$->opclassopts = NIL;
8286 $$->ordering = $3;
8287 $$->nulls_ordering = $4;
8288 }
8289 | opt_collate any_name reloptions opt_asc_desc opt_nulls_order
8290 {
8291 $$ = makeNode(IndexElem);
8292 $$->name = NULL;
8293 $$->expr = NULL;
8294 $$->indexcolname = NULL;
8295 $$->collation = $1;
8296 $$->opclass = $2;
8297 $$->opclassopts = $3;
8298 $$->ordering = $4;
8299 $$->nulls_ordering = $5;
8300 }
8301 ;
8302
8303 /*
8304 * Index attributes can be either simple column references, or arbitrary
8305 * expressions in parens. For backwards-compatibility reasons, we allow
8306 * an expression that's just a function call to be written without parens.
8307 */
8308 index_elem: ColId index_elem_options
8309 {
8310 $$ = $2;
8311 $$->name = $1;
8312 }
8313 | func_expr_windowless index_elem_options
8314 {
8315 $$ = $2;
8316 $$->expr = $1;
8317 }
8318 | '(' a_expr ')' index_elem_options
8319 {
8320 $$ = $4;
8321 $$->expr = $2;
8322 }
8323 ;
8324
8325 opt_include: INCLUDE '(' index_including_params ')' { $$ = $3; }
8326 | /* EMPTY */ { $$ = NIL; }
8327 ;
8328
8329 index_including_params: index_elem { $$ = list_make1($1); }
8330 | index_including_params ',' index_elem { $$ = lappend($1, $3); }
8331 ;
8332
8333 opt_collate: COLLATE any_name { $$ = $2; }
8334 | /*EMPTY*/ { $$ = NIL; }
8335 ;
8336
8337
8338 opt_asc_desc: ASC { $$ = SORTBY_ASC; }
8339 | DESC { $$ = SORTBY_DESC; }
8340 | /*EMPTY*/ { $$ = SORTBY_DEFAULT; }
8341 ;
8342
8343 opt_nulls_order: NULLS_LA FIRST_P { $$ = SORTBY_NULLS_FIRST; }
8344 | NULLS_LA LAST_P { $$ = SORTBY_NULLS_LAST; }
8345 | /*EMPTY*/ { $$ = SORTBY_NULLS_DEFAULT; }
8346 ;
8347
8348
8349 /*****************************************************************************
8350 *
8351 * QUERY:
8352 * create [or replace] function <fname>
8353 * [(<type-1> { , <type-n>})]
8354 * returns <type-r>
8355 * as <filename or code in language as appropriate>
8356 * language <lang> [with parameters]
8357 *
8358 *****************************************************************************/
8359
8360 CreateFunctionStmt:
8361 CREATE opt_or_replace FUNCTION func_name func_args_with_defaults
8362 RETURNS func_return opt_createfunc_opt_list opt_routine_body
8363 {
8364 CreateFunctionStmt *n = makeNode(CreateFunctionStmt);
8365
8366 n->is_procedure = false;
8367 n->replace = $2;
8368 n->funcname = $4;
8369 n->parameters = $5;
8370 n->returnType = $7;
8371 n->options = $8;
8372 n->sql_body = $9;
8373 $$ = (Node *) n;
8374 }
8375 | CREATE opt_or_replace FUNCTION func_name func_args_with_defaults
8376 RETURNS TABLE '(' table_func_column_list ')' opt_createfunc_opt_list opt_routine_body
8377 {
8378 CreateFunctionStmt *n = makeNode(CreateFunctionStmt);
8379
8380 n->is_procedure = false;
8381 n->replace = $2;
8382 n->funcname = $4;
8383 n->parameters = mergeTableFuncParameters($5, $9, yyscanner);
8384 n->returnType = TableFuncTypeName($9);
8385 n->returnType->location = @7;
8386 n->options = $11;
8387 n->sql_body = $12;
8388 $$ = (Node *) n;
8389 }
8390 | CREATE opt_or_replace FUNCTION func_name func_args_with_defaults
8391 opt_createfunc_opt_list opt_routine_body
8392 {
8393 CreateFunctionStmt *n = makeNode(CreateFunctionStmt);
8394
8395 n->is_procedure = false;
8396 n->replace = $2;
8397 n->funcname = $4;
8398 n->parameters = $5;
8399 n->returnType = NULL;
8400 n->options = $6;
8401 n->sql_body = $7;
8402 $$ = (Node *) n;
8403 }
8404 | CREATE opt_or_replace PROCEDURE func_name func_args_with_defaults
8405 opt_createfunc_opt_list opt_routine_body
8406 {
8407 CreateFunctionStmt *n = makeNode(CreateFunctionStmt);
8408
8409 n->is_procedure = true;
8410 n->replace = $2;
8411 n->funcname = $4;
8412 n->parameters = $5;
8413 n->returnType = NULL;
8414 n->options = $6;
8415 n->sql_body = $7;
8416 $$ = (Node *) n;
8417 }
8418 ;
8419
8420 opt_or_replace:
8421 OR REPLACE { $$ = true; }
8422 | /*EMPTY*/ { $$ = false; }
8423 ;
8424
8425 func_args: '(' func_args_list ')' { $$ = $2; }
8426 | '(' ')' { $$ = NIL; }
8427 ;
8428
8429 func_args_list:
8430 func_arg { $$ = list_make1($1); }
8431 | func_args_list ',' func_arg { $$ = lappend($1, $3); }
8432 ;
8433
8434 function_with_argtypes_list:
8435 function_with_argtypes { $$ = list_make1($1); }
8436 | function_with_argtypes_list ',' function_with_argtypes
8437 { $$ = lappend($1, $3); }
8438 ;
8439
8440 function_with_argtypes:
8441 func_name func_args
8442 {
8443 ObjectWithArgs *n = makeNode(ObjectWithArgs);
8444
8445 n->objname = $1;
8446 n->objargs = extractArgTypes($2);
8447 n->objfuncargs = $2;
8448 $$ = n;
8449 }
8450 /*
8451 * Because of reduce/reduce conflicts, we can't use func_name
8452 * below, but we can write it out the long way, which actually
8453 * allows more cases.
8454 */
8455 | type_func_name_keyword
8456 {
8457 ObjectWithArgs *n = makeNode(ObjectWithArgs);
8458
8459 n->objname = list_make1(makeString(pstrdup($1)));
8460 n->args_unspecified = true;
8461 $$ = n;
8462 }
8463 | ColId
8464 {
8465 ObjectWithArgs *n = makeNode(ObjectWithArgs);
8466
8467 n->objname = list_make1(makeString($1));
8468 n->args_unspecified = true;
8469 $$ = n;
8470 }
8471 | ColId indirection
8472 {
8473 ObjectWithArgs *n = makeNode(ObjectWithArgs);
8474
8475 n->objname = check_func_name(lcons(makeString($1), $2),
8476 yyscanner);
8477 n->args_unspecified = true;
8478 $$ = n;
8479 }
8480 ;
8481
8482 /*
8483 * func_args_with_defaults is separate because we only want to accept
8484 * defaults in CREATE FUNCTION, not in ALTER etc.
8485 */
8486 func_args_with_defaults:
8487 '(' func_args_with_defaults_list ')' { $$ = $2; }
8488 | '(' ')' { $$ = NIL; }
8489 ;
8490
8491 func_args_with_defaults_list:
8492 func_arg_with_default { $$ = list_make1($1); }
8493 | func_args_with_defaults_list ',' func_arg_with_default
8494 { $$ = lappend($1, $3); }
8495 ;
8496
8497 /*
8498 * The style with arg_class first is SQL99 standard, but Oracle puts
8499 * param_name first; accept both since it's likely people will try both
8500 * anyway. Don't bother trying to save productions by letting arg_class
8501 * have an empty alternative ... you'll get shift/reduce conflicts.
8502 *
8503 * We can catch over-specified arguments here if we want to,
8504 * but for now better to silently swallow typmod, etc.
8505 * - thomas 2000-03-22
8506 */
8507 func_arg:
8508 arg_class param_name func_type
8509 {
8510 FunctionParameter *n = makeNode(FunctionParameter);
8511
8512 n->name = $2;
8513 n->argType = $3;
8514 n->mode = $1;
8515 n->defexpr = NULL;
8516 n->location = @1;
8517 $$ = n;
8518 }
8519 | param_name arg_class func_type
8520 {
8521 FunctionParameter *n = makeNode(FunctionParameter);
8522
8523 n->name = $1;
8524 n->argType = $3;
8525 n->mode = $2;
8526 n->defexpr = NULL;
8527 n->location = @1;
8528 $$ = n;
8529 }
8530 | param_name func_type
8531 {
8532 FunctionParameter *n = makeNode(FunctionParameter);
8533
8534 n->name = $1;
8535 n->argType = $2;
8536 n->mode = FUNC_PARAM_DEFAULT;
8537 n->defexpr = NULL;
8538 n->location = @1;
8539 $$ = n;
8540 }
8541 | arg_class func_type
8542 {
8543 FunctionParameter *n = makeNode(FunctionParameter);
8544
8545 n->name = NULL;
8546 n->argType = $2;
8547 n->mode = $1;
8548 n->defexpr = NULL;
8549 n->location = @1;
8550 $$ = n;
8551 }
8552 | func_type
8553 {
8554 FunctionParameter *n = makeNode(FunctionParameter);
8555
8556 n->name = NULL;
8557 n->argType = $1;
8558 n->mode = FUNC_PARAM_DEFAULT;
8559 n->defexpr = NULL;
8560 n->location = @1;
8561 $$ = n;
8562 }
8563 ;
8564
8565 /* INOUT is SQL99 standard, IN OUT is for Oracle compatibility */
8566 arg_class: IN_P { $$ = FUNC_PARAM_IN; }
8567 | OUT_P { $$ = FUNC_PARAM_OUT; }
8568 | INOUT { $$ = FUNC_PARAM_INOUT; }
8569 | IN_P OUT_P { $$ = FUNC_PARAM_INOUT; }
8570 | VARIADIC { $$ = FUNC_PARAM_VARIADIC; }
8571 ;
8572
8573 /*
8574 * Ideally param_name should be ColId, but that causes too many conflicts.
8575 */
8576 param_name: type_function_name
8577 ;
8578
8579 func_return:
8580 func_type
8581 {
8582 /* We can catch over-specified results here if we want to,
8583 * but for now better to silently swallow typmod, etc.
8584 * - thomas 2000-03-22
8585 */
8586 $$ = $1;
8587 }
8588 ;
8589
8590 /*
8591 * We would like to make the %TYPE productions here be ColId attrs etc,
8592 * but that causes reduce/reduce conflicts. type_function_name
8593 * is next best choice.
8594 */
8595 func_type: Typename { $$ = $1; }
8596 | type_function_name attrs '%' TYPE_P
8597 {
8598 $$ = makeTypeNameFromNameList(lcons(makeString($1), $2));
8599 $$->pct_type = true;
8600 $$->location = @1;
8601 }
8602 | SETOF type_function_name attrs '%' TYPE_P
8603 {
8604 $$ = makeTypeNameFromNameList(lcons(makeString($2), $3));
8605 $$->pct_type = true;
8606 $$->setof = true;
8607 $$->location = @2;
8608 }
8609 ;
8610
8611 func_arg_with_default:
8612 func_arg
8613 {
8614 $$ = $1;
8615 }
8616 | func_arg DEFAULT a_expr
8617 {
8618 $$ = $1;
8619 $$->defexpr = $3;
8620 }
8621 | func_arg '=' a_expr
8622 {
8623 $$ = $1;
8624 $$->defexpr = $3;
8625 }
8626 ;
8627
8628 /* Aggregate args can be most things that function args can be */
8629 aggr_arg: func_arg
8630 {
8631 if (!($1->mode == FUNC_PARAM_DEFAULT ||
8632 $1->mode == FUNC_PARAM_IN ||
8633 $1->mode == FUNC_PARAM_VARIADIC))
8634 ereport(ERROR,
8635 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
8636 errmsg("aggregates cannot have output arguments"),
8637 parser_errposition(@1)));
8638 $$ = $1;
8639 }
8640 ;
8641
8642 /*
8643 * The SQL standard offers no guidance on how to declare aggregate argument
8644 * lists, since it doesn't have CREATE AGGREGATE etc. We accept these cases:
8645 *
8646 * (*) - normal agg with no args
8647 * (aggr_arg,...) - normal agg with args
8648 * (ORDER BY aggr_arg,...) - ordered-set agg with no direct args
8649 * (aggr_arg,... ORDER BY aggr_arg,...) - ordered-set agg with direct args
8650 *
8651 * The zero-argument case is spelled with '*' for consistency with COUNT(*).
8652 *
8653 * An additional restriction is that if the direct-args list ends in a
8654 * VARIADIC item, the ordered-args list must contain exactly one item that
8655 * is also VARIADIC with the same type. This allows us to collapse the two
8656 * VARIADIC items into one, which is necessary to represent the aggregate in
8657 * pg_proc. We check this at the grammar stage so that we can return a list
8658 * in which the second VARIADIC item is already discarded, avoiding extra work
8659 * in cases such as DROP AGGREGATE.
8660 *
8661 * The return value of this production is a two-element list, in which the
8662 * first item is a sublist of FunctionParameter nodes (with any duplicate
8663 * VARIADIC item already dropped, as per above) and the second is an Integer
8664 * node, containing -1 if there was no ORDER BY and otherwise the number
8665 * of argument declarations before the ORDER BY. (If this number is equal
8666 * to the first sublist's length, then we dropped a duplicate VARIADIC item.)
8667 * This representation is passed as-is to CREATE AGGREGATE; for operations
8668 * on existing aggregates, we can just apply extractArgTypes to the first
8669 * sublist.
8670 */
8671 aggr_args: '(' '*' ')'
8672 {
8673 $$ = list_make2(NIL, makeInteger(-1));
8674 }
8675 | '(' aggr_args_list ')'
8676 {
8677 $$ = list_make2($2, makeInteger(-1));
8678 }
8679 | '(' ORDER BY aggr_args_list ')'
8680 {
8681 $$ = list_make2($4, makeInteger(0));
8682 }
8683 | '(' aggr_args_list ORDER BY aggr_args_list ')'
8684 {
8685 /* this is the only case requiring consistency checking */
8686 $$ = makeOrderedSetArgs($2, $5, yyscanner);
8687 }
8688 ;
8689
8690 aggr_args_list:
8691 aggr_arg { $$ = list_make1($1); }
8692 | aggr_args_list ',' aggr_arg { $$ = lappend($1, $3); }
8693 ;
8694
8695 aggregate_with_argtypes:
8696 func_name aggr_args
8697 {
8698 ObjectWithArgs *n = makeNode(ObjectWithArgs);
8699
8700 n->objname = $1;
8701 n->objargs = extractAggrArgTypes($2);
8702 n->objfuncargs = (List *) linitial($2);
8703 $$ = n;
8704 }
8705 ;
8706
8707 aggregate_with_argtypes_list:
8708 aggregate_with_argtypes { $$ = list_make1($1); }
8709 | aggregate_with_argtypes_list ',' aggregate_with_argtypes
8710 { $$ = lappend($1, $3); }
8711 ;
8712
8713 opt_createfunc_opt_list:
8714 createfunc_opt_list
8715 | /*EMPTY*/ { $$ = NIL; }
8716 ;
8717
8718 createfunc_opt_list:
8719 /* Must be at least one to prevent conflict */
8720 createfunc_opt_item { $$ = list_make1($1); }
8721 | createfunc_opt_list createfunc_opt_item { $$ = lappend($1, $2); }
8722 ;
8723
8724 /*
8725 * Options common to both CREATE FUNCTION and ALTER FUNCTION
8726 */
8727 common_func_opt_item:
8728 CALLED ON NULL_P INPUT_P
8729 {
8730 $$ = makeDefElem("strict", (Node *) makeBoolean(false), @1);
8731 }
8732 | RETURNS NULL_P ON NULL_P INPUT_P
8733 {
8734 $$ = makeDefElem("strict", (Node *) makeBoolean(true), @1);
8735 }
8736 | STRICT_P
8737 {
8738 $$ = makeDefElem("strict", (Node *) makeBoolean(true), @1);
8739 }
8740 | IMMUTABLE
8741 {
8742 $$ = makeDefElem("volatility", (Node *) makeString("immutable"), @1);
8743 }
8744 | STABLE
8745 {
8746 $$ = makeDefElem("volatility", (Node *) makeString("stable"), @1);
8747 }
8748 | VOLATILE
8749 {
8750 $$ = makeDefElem("volatility", (Node *) makeString("volatile"), @1);
8751 }
8752 | EXTERNAL SECURITY DEFINER
8753 {
8754 $$ = makeDefElem("security", (Node *) makeBoolean(true), @1);
8755 }
8756 | EXTERNAL SECURITY INVOKER
8757 {
8758 $$ = makeDefElem("security", (Node *) makeBoolean(false), @1);
8759 }
8760 | SECURITY DEFINER
8761 {
8762 $$ = makeDefElem("security", (Node *) makeBoolean(true), @1);
8763 }
8764 | SECURITY INVOKER
8765 {
8766 $$ = makeDefElem("security", (Node *) makeBoolean(false), @1);
8767 }
8768 | LEAKPROOF
8769 {
8770 $$ = makeDefElem("leakproof", (Node *) makeBoolean(true), @1);
8771 }
8772 | NOT LEAKPROOF
8773 {
8774 $$ = makeDefElem("leakproof", (Node *) makeBoolean(false), @1);
8775 }
8776 | COST NumericOnly
8777 {
8778 $$ = makeDefElem("cost", (Node *) $2, @1);
8779 }
8780 | ROWS NumericOnly
8781 {
8782 $$ = makeDefElem("rows", (Node *) $2, @1);
8783 }
8784 | SUPPORT any_name
8785 {
8786 $$ = makeDefElem("support", (Node *) $2, @1);
8787 }
8788 | FunctionSetResetClause
8789 {
8790 /* we abuse the normal content of a DefElem here */
8791 $$ = makeDefElem("set", (Node *) $1, @1);
8792 }
8793 | PARALLEL ColId
8794 {
8795 $$ = makeDefElem("parallel", (Node *) makeString($2), @1);
8796 }
8797 ;
8798
8799 createfunc_opt_item:
8800 AS func_as
8801 {
8802 $$ = makeDefElem("as", (Node *) $2, @1);
8803 }
8804 | LANGUAGE NonReservedWord_or_Sconst
8805 {
8806 $$ = makeDefElem("language", (Node *) makeString($2), @1);
8807 }
8808 | TRANSFORM transform_type_list
8809 {
8810 $$ = makeDefElem("transform", (Node *) $2, @1);
8811 }
8812 | WINDOW
8813 {
8814 $$ = makeDefElem("window", (Node *) makeBoolean(true), @1);
8815 }
8816 | common_func_opt_item
8817 {
8818 $$ = $1;
8819 }
8820 ;
8821
8822 func_as: Sconst { $$ = list_make1(makeString($1)); }
8823 | Sconst ',' Sconst
8824 {
8825 $$ = list_make2(makeString($1), makeString($3));
8826 }
8827 ;
8828
8829 ReturnStmt: RETURN a_expr
8830 {
8831 ReturnStmt *r = makeNode(ReturnStmt);
8832
8833 r->returnval = (Node *) $2;
8834 $$ = (Node *) r;
8835 }
8836 ;
8837
8838 opt_routine_body:
8839 ReturnStmt
8840 {
8841 $$ = $1;
8842 }
8843 | BEGIN_P ATOMIC routine_body_stmt_list END_P
8844 {
8845 /*
8846 * A compound statement is stored as a single-item list
8847 * containing the list of statements as its member. That
8848 * way, the parse analysis code can tell apart an empty
8849 * body from no body at all.
8850 */
8851 $$ = (Node *) list_make1($3);
8852 }
8853 | /*EMPTY*/
8854 {
8855 $$ = NULL;
8856 }
8857 ;
8858
8859 routine_body_stmt_list:
8860 routine_body_stmt_list routine_body_stmt ';'
8861 {
8862 /* As in stmtmulti, discard empty statements */
8863 if ($2 != NULL)
8864 $$ = lappend($1, $2);
8865 else
8866 $$ = $1;
8867 }
8868 | /*EMPTY*/
8869 {
8870 $$ = NIL;
8871 }
8872 ;
8873
8874 routine_body_stmt:
8875 stmt
8876 | ReturnStmt
8877 ;
8878
8879 transform_type_list:
8880 FOR TYPE_P Typename { $$ = list_make1($3); }
8881 | transform_type_list ',' FOR TYPE_P Typename { $$ = lappend($1, $5); }
8882 ;
8883
8884 opt_definition:
8885 WITH definition { $$ = $2; }
8886 | /*EMPTY*/ { $$ = NIL; }
8887 ;
8888
8889 table_func_column: param_name func_type
8890 {
8891 FunctionParameter *n = makeNode(FunctionParameter);
8892
8893 n->name = $1;
8894 n->argType = $2;
8895 n->mode = FUNC_PARAM_TABLE;
8896 n->defexpr = NULL;
8897 n->location = @1;
8898 $$ = n;
8899 }
8900 ;
8901
8902 table_func_column_list:
8903 table_func_column
8904 {
8905 $$ = list_make1($1);
8906 }
8907 | table_func_column_list ',' table_func_column
8908 {
8909 $$ = lappend($1, $3);
8910 }
8911 ;
8912
8913 /*****************************************************************************
8914 * ALTER FUNCTION / ALTER PROCEDURE / ALTER ROUTINE
8915 *
8916 * RENAME and OWNER subcommands are already provided by the generic
8917 * ALTER infrastructure, here we just specify alterations that can
8918 * only be applied to functions.
8919 *
8920 *****************************************************************************/
8921 AlterFunctionStmt:
8922 ALTER FUNCTION function_with_argtypes alterfunc_opt_list opt_restrict
8923 {
8924 AlterFunctionStmt *n = makeNode(AlterFunctionStmt);
8925
8926 n->objtype = OBJECT_FUNCTION;
8927 n->func = $3;
8928 n->actions = $4;
8929 $$ = (Node *) n;
8930 }
8931 | ALTER PROCEDURE function_with_argtypes alterfunc_opt_list opt_restrict
8932 {
8933 AlterFunctionStmt *n = makeNode(AlterFunctionStmt);
8934
8935 n->objtype = OBJECT_PROCEDURE;
8936 n->func = $3;
8937 n->actions = $4;
8938 $$ = (Node *) n;
8939 }
8940 | ALTER ROUTINE function_with_argtypes alterfunc_opt_list opt_restrict
8941 {
8942 AlterFunctionStmt *n = makeNode(AlterFunctionStmt);
8943
8944 n->objtype = OBJECT_ROUTINE;
8945 n->func = $3;
8946 n->actions = $4;
8947 $$ = (Node *) n;
8948 }
8949 ;
8950
8951 alterfunc_opt_list:
8952 /* At least one option must be specified */
8953 common_func_opt_item { $$ = list_make1($1); }
8954 | alterfunc_opt_list common_func_opt_item { $$ = lappend($1, $2); }
8955 ;
8956
8957 /* Ignored, merely for SQL compliance */
8958 opt_restrict:
8959 RESTRICT
8960 | /* EMPTY */
8961 ;
8962
8963
8964 /*****************************************************************************
8965 *
8966 * QUERY:
8967 *
8968 * DROP FUNCTION funcname (arg1, arg2, ...) [ RESTRICT | CASCADE ]
8969 * DROP PROCEDURE procname (arg1, arg2, ...) [ RESTRICT | CASCADE ]
8970 * DROP ROUTINE routname (arg1, arg2, ...) [ RESTRICT | CASCADE ]
8971 * DROP AGGREGATE aggname (arg1, ...) [ RESTRICT | CASCADE ]
8972 * DROP OPERATOR opname (leftoperand_typ, rightoperand_typ) [ RESTRICT | CASCADE ]
8973 *
8974 *****************************************************************************/
8975
8976 RemoveFuncStmt:
8977 DROP FUNCTION function_with_argtypes_list opt_drop_behavior
8978 {
8979 DropStmt *n = makeNode(DropStmt);
8980
8981 n->removeType = OBJECT_FUNCTION;
8982 n->objects = $3;
8983 n->behavior = $4;
8984 n->missing_ok = false;
8985 n->concurrent = false;
8986 $$ = (Node *) n;
8987 }
8988 | DROP FUNCTION IF_P EXISTS function_with_argtypes_list opt_drop_behavior
8989 {
8990 DropStmt *n = makeNode(DropStmt);
8991
8992 n->removeType = OBJECT_FUNCTION;
8993 n->objects = $5;
8994 n->behavior = $6;
8995 n->missing_ok = true;
8996 n->concurrent = false;
8997 $$ = (Node *) n;
8998 }
8999 | DROP PROCEDURE function_with_argtypes_list opt_drop_behavior
9000 {
9001 DropStmt *n = makeNode(DropStmt);
9002
9003 n->removeType = OBJECT_PROCEDURE;
9004 n->objects = $3;
9005 n->behavior = $4;
9006 n->missing_ok = false;
9007 n->concurrent = false;
9008 $$ = (Node *) n;
9009 }
9010 | DROP PROCEDURE IF_P EXISTS function_with_argtypes_list opt_drop_behavior
9011 {
9012 DropStmt *n = makeNode(DropStmt);
9013
9014 n->removeType = OBJECT_PROCEDURE;
9015 n->objects = $5;
9016 n->behavior = $6;
9017 n->missing_ok = true;
9018 n->concurrent = false;
9019 $$ = (Node *) n;
9020 }
9021 | DROP ROUTINE function_with_argtypes_list opt_drop_behavior
9022 {
9023 DropStmt *n = makeNode(DropStmt);
9024
9025 n->removeType = OBJECT_ROUTINE;
9026 n->objects = $3;
9027 n->behavior = $4;
9028 n->missing_ok = false;
9029 n->concurrent = false;
9030 $$ = (Node *) n;
9031 }
9032 | DROP ROUTINE IF_P EXISTS function_with_argtypes_list opt_drop_behavior
9033 {
9034 DropStmt *n = makeNode(DropStmt);
9035
9036 n->removeType = OBJECT_ROUTINE;
9037 n->objects = $5;
9038 n->behavior = $6;
9039 n->missing_ok = true;
9040 n->concurrent = false;
9041 $$ = (Node *) n;
9042 }
9043 ;
9044
9045 RemoveAggrStmt:
9046 DROP AGGREGATE aggregate_with_argtypes_list opt_drop_behavior
9047 {
9048 DropStmt *n = makeNode(DropStmt);
9049
9050 n->removeType = OBJECT_AGGREGATE;
9051 n->objects = $3;
9052 n->behavior = $4;
9053 n->missing_ok = false;
9054 n->concurrent = false;
9055 $$ = (Node *) n;
9056 }
9057 | DROP AGGREGATE IF_P EXISTS aggregate_with_argtypes_list opt_drop_behavior
9058 {
9059 DropStmt *n = makeNode(DropStmt);
9060
9061 n->removeType = OBJECT_AGGREGATE;
9062 n->objects = $5;
9063 n->behavior = $6;
9064 n->missing_ok = true;
9065 n->concurrent = false;
9066 $$ = (Node *) n;
9067 }
9068 ;
9069
9070 RemoveOperStmt:
9071 DROP OPERATOR operator_with_argtypes_list opt_drop_behavior
9072 {
9073 DropStmt *n = makeNode(DropStmt);
9074
9075 n->removeType = OBJECT_OPERATOR;
9076 n->objects = $3;
9077 n->behavior = $4;
9078 n->missing_ok = false;
9079 n->concurrent = false;
9080 $$ = (Node *) n;
9081 }
9082 | DROP OPERATOR IF_P EXISTS operator_with_argtypes_list opt_drop_behavior
9083 {
9084 DropStmt *n = makeNode(DropStmt);
9085
9086 n->removeType = OBJECT_OPERATOR;
9087 n->objects = $5;
9088 n->behavior = $6;
9089 n->missing_ok = true;
9090 n->concurrent = false;
9091 $$ = (Node *) n;
9092 }
9093 ;
9094
9095 oper_argtypes:
9096 '(' Typename ')'
9097 {
9098 ereport(ERROR,
9099 (errcode(ERRCODE_SYNTAX_ERROR),
9100 errmsg("missing argument"),
9101 errhint("Use NONE to denote the missing argument of a unary operator."),
9102 parser_errposition(@3)));
9103 }
9104 | '(' Typename ',' Typename ')'
9105 { $$ = list_make2($2, $4); }
9106 | '(' NONE ',' Typename ')' /* left unary */
9107 { $$ = list_make2(NULL, $4); }
9108 | '(' Typename ',' NONE ')' /* right unary */
9109 { $$ = list_make2($2, NULL); }
9110 ;
9111
9112 any_operator:
9113 all_Op
9114 { $$ = list_make1(makeString($1)); }
9115 | ColId '.' any_operator
9116 { $$ = lcons(makeString($1), $3); }
9117 ;
9118
9119 operator_with_argtypes_list:
9120 operator_with_argtypes { $$ = list_make1($1); }
9121 | operator_with_argtypes_list ',' operator_with_argtypes
9122 { $$ = lappend($1, $3); }
9123 ;
9124
9125 operator_with_argtypes:
9126 any_operator oper_argtypes
9127 {
9128 ObjectWithArgs *n = makeNode(ObjectWithArgs);
9129
9130 n->objname = $1;
9131 n->objargs = $2;
9132 $$ = n;
9133 }
9134 ;
9135
9136 /*****************************************************************************
9137 *
9138 * DO <anonymous code block> [ LANGUAGE language ]
9139 *
9140 * We use a DefElem list for future extensibility, and to allow flexibility
9141 * in the clause order.
9142 *
9143 *****************************************************************************/
9144
9145 DoStmt: DO dostmt_opt_list
9146 {
9147 DoStmt *n = makeNode(DoStmt);
9148
9149 n->args = $2;
9150 $$ = (Node *) n;
9151 }
9152 ;
9153
9154 dostmt_opt_list:
9155 dostmt_opt_item { $$ = list_make1($1); }
9156 | dostmt_opt_list dostmt_opt_item { $$ = lappend($1, $2); }
9157 ;
9158
9159 dostmt_opt_item:
9160 Sconst
9161 {
9162 $$ = makeDefElem("as", (Node *) makeString($1), @1);
9163 }
9164 | LANGUAGE NonReservedWord_or_Sconst
9165 {
9166 $$ = makeDefElem("language", (Node *) makeString($2), @1);
9167 }
9168 ;
9169
9170 /*****************************************************************************
9171 *
9172 * CREATE CAST / DROP CAST
9173 *
9174 *****************************************************************************/
9175
9176 CreateCastStmt: CREATE CAST '(' Typename AS Typename ')'
9177 WITH FUNCTION function_with_argtypes cast_context
9178 {
9179 CreateCastStmt *n = makeNode(CreateCastStmt);
9180
9181 n->sourcetype = $4;
9182 n->targettype = $6;
9183 n->func = $10;
9184 n->context = (CoercionContext) $11;
9185 n->inout = false;
9186 $$ = (Node *) n;
9187 }
9188 | CREATE CAST '(' Typename AS Typename ')'
9189 WITHOUT FUNCTION cast_context
9190 {
9191 CreateCastStmt *n = makeNode(CreateCastStmt);
9192
9193 n->sourcetype = $4;
9194 n->targettype = $6;
9195 n->func = NULL;
9196 n->context = (CoercionContext) $10;
9197 n->inout = false;
9198 $$ = (Node *) n;
9199 }
9200 | CREATE CAST '(' Typename AS Typename ')'
9201 WITH INOUT cast_context
9202 {
9203 CreateCastStmt *n = makeNode(CreateCastStmt);
9204
9205 n->sourcetype = $4;
9206 n->targettype = $6;
9207 n->func = NULL;
9208 n->context = (CoercionContext) $10;
9209 n->inout = true;
9210 $$ = (Node *) n;
9211 }
9212 ;
9213
9214 cast_context: AS IMPLICIT_P { $$ = COERCION_IMPLICIT; }
9215 | AS ASSIGNMENT { $$ = COERCION_ASSIGNMENT; }
9216 | /*EMPTY*/ { $$ = COERCION_EXPLICIT; }
9217 ;
9218
9219
9220 DropCastStmt: DROP CAST opt_if_exists '(' Typename AS Typename ')' opt_drop_behavior
9221 {
9222 DropStmt *n = makeNode(DropStmt);
9223
9224 n->removeType = OBJECT_CAST;
9225 n->objects = list_make1(list_make2($5, $7));
9226 n->behavior = $9;
9227 n->missing_ok = $3;
9228 n->concurrent = false;
9229 $$ = (Node *) n;
9230 }
9231 ;
9232
9233 opt_if_exists: IF_P EXISTS { $$ = true; }
9234 | /*EMPTY*/ { $$ = false; }
9235 ;
9236
9237
9238 /*****************************************************************************
9239 *
9240 * CREATE TRANSFORM / DROP TRANSFORM
9241 *
9242 *****************************************************************************/
9243
9244 CreateTransformStmt: CREATE opt_or_replace TRANSFORM FOR Typename LANGUAGE name '(' transform_element_list ')'
9245 {
9246 CreateTransformStmt *n = makeNode(CreateTransformStmt);
9247
9248 n->replace = $2;
9249 n->type_name = $5;
9250 n->lang = $7;
9251 n->fromsql = linitial($9);
9252 n->tosql = lsecond($9);
9253 $$ = (Node *) n;
9254 }
9255 ;
9256
9257 transform_element_list: FROM SQL_P WITH FUNCTION function_with_argtypes ',' TO SQL_P WITH FUNCTION function_with_argtypes
9258 {
9259 $$ = list_make2($5, $11);
9260 }
9261 | TO SQL_P WITH FUNCTION function_with_argtypes ',' FROM SQL_P WITH FUNCTION function_with_argtypes
9262 {
9263 $$ = list_make2($11, $5);
9264 }
9265 | FROM SQL_P WITH FUNCTION function_with_argtypes
9266 {
9267 $$ = list_make2($5, NULL);
9268 }
9269 | TO SQL_P WITH FUNCTION function_with_argtypes
9270 {
9271 $$ = list_make2(NULL, $5);
9272 }
9273 ;
9274
9275
9276 DropTransformStmt: DROP TRANSFORM opt_if_exists FOR Typename LANGUAGE name opt_drop_behavior
9277 {
9278 DropStmt *n = makeNode(DropStmt);
9279
9280 n->removeType = OBJECT_TRANSFORM;
9281 n->objects = list_make1(list_make2($5, makeString($7)));
9282 n->behavior = $8;
9283 n->missing_ok = $3;
9284 $$ = (Node *) n;
9285 }
9286 ;
9287
9288
9289 /*****************************************************************************
9290 *
9291 * QUERY:
9292 *
9293 * REINDEX [ (options) ] {INDEX | TABLE | SCHEMA} [CONCURRENTLY] <name>
9294 * REINDEX [ (options) ] {DATABASE | SYSTEM} [CONCURRENTLY] [<name>]
9295 *****************************************************************************/
9296
9297 ReindexStmt:
9298 REINDEX opt_reindex_option_list reindex_target_relation opt_concurrently qualified_name
9299 {
9300 ReindexStmt *n = makeNode(ReindexStmt);
9301
9302 n->kind = $3;
9303 n->relation = $5;
9304 n->name = NULL;
9305 n->params = $2;
9306 if ($4)
9307 n->params = lappend(n->params,
9308 makeDefElem("concurrently", NULL, @4));
9309 $$ = (Node *) n;
9310 }
9311 | REINDEX opt_reindex_option_list SCHEMA opt_concurrently name
9312 {
9313 ReindexStmt *n = makeNode(ReindexStmt);
9314
9315 n->kind = REINDEX_OBJECT_SCHEMA;
9316 n->relation = NULL;
9317 n->name = $5;
9318 n->params = $2;
9319 if ($4)
9320 n->params = lappend(n->params,
9321 makeDefElem("concurrently", NULL, @4));
9322 $$ = (Node *) n;
9323 }
9324 | REINDEX opt_reindex_option_list reindex_target_all opt_concurrently opt_single_name
9325 {
9326 ReindexStmt *n = makeNode(ReindexStmt);
9327
9328 n->kind = $3;
9329 n->relation = NULL;
9330 n->name = $5;
9331 n->params = $2;
9332 if ($4)
9333 n->params = lappend(n->params,
9334 makeDefElem("concurrently", NULL, @4));
9335 $$ = (Node *) n;
9336 }
9337 ;
9338 reindex_target_relation:
9339 INDEX { $$ = REINDEX_OBJECT_INDEX; }
9340 | TABLE { $$ = REINDEX_OBJECT_TABLE; }
9341 ;
9342 reindex_target_all:
9343 SYSTEM_P { $$ = REINDEX_OBJECT_SYSTEM; }
9344 | DATABASE { $$ = REINDEX_OBJECT_DATABASE; }
9345 ;
9346 opt_reindex_option_list:
9347 '(' utility_option_list ')' { $$ = $2; }
9348 | /* EMPTY */ { $$ = NULL; }
9349 ;
9350
9351 /*****************************************************************************
9352 *
9353 * ALTER TABLESPACE
9354 *
9355 *****************************************************************************/
9356
9357 AlterTblSpcStmt:
9358 ALTER TABLESPACE name SET reloptions
9359 {
9360 AlterTableSpaceOptionsStmt *n =
9361 makeNode(AlterTableSpaceOptionsStmt);
9362
9363 n->tablespacename = $3;
9364 n->options = $5;
9365 n->isReset = false;
9366 $$ = (Node *) n;
9367 }
9368 | ALTER TABLESPACE name RESET reloptions
9369 {
9370 AlterTableSpaceOptionsStmt *n =
9371 makeNode(AlterTableSpaceOptionsStmt);
9372
9373 n->tablespacename = $3;
9374 n->options = $5;
9375 n->isReset = true;
9376 $$ = (Node *) n;
9377 }
9378 ;
9379
9380 /*****************************************************************************
9381 *
9382 * ALTER THING name RENAME TO newname
9383 *
9384 *****************************************************************************/
9385
9386 RenameStmt: ALTER AGGREGATE aggregate_with_argtypes RENAME TO name
9387 {
9388 RenameStmt *n = makeNode(RenameStmt);
9389
9390 n->renameType = OBJECT_AGGREGATE;
9391 n->object = (Node *) $3;
9392 n->newname = $6;
9393 n->missing_ok = false;
9394 $$ = (Node *) n;
9395 }
9396 | ALTER COLLATION any_name RENAME TO name
9397 {
9398 RenameStmt *n = makeNode(RenameStmt);
9399
9400 n->renameType = OBJECT_COLLATION;
9401 n->object = (Node *) $3;
9402 n->newname = $6;
9403 n->missing_ok = false;
9404 $$ = (Node *) n;
9405 }
9406 | ALTER CONVERSION_P any_name RENAME TO name
9407 {
9408 RenameStmt *n = makeNode(RenameStmt);
9409
9410 n->renameType = OBJECT_CONVERSION;
9411 n->object = (Node *) $3;
9412 n->newname = $6;
9413 n->missing_ok = false;
9414 $$ = (Node *) n;
9415 }
9416 | ALTER DATABASE name RENAME TO name
9417 {
9418 RenameStmt *n = makeNode(RenameStmt);
9419
9420 n->renameType = OBJECT_DATABASE;
9421 n->subname = $3;
9422 n->newname = $6;
9423 n->missing_ok = false;
9424 $$ = (Node *) n;
9425 }
9426 | ALTER DOMAIN_P any_name RENAME TO name
9427 {
9428 RenameStmt *n = makeNode(RenameStmt);
9429
9430 n->renameType = OBJECT_DOMAIN;
9431 n->object = (Node *) $3;
9432 n->newname = $6;
9433 n->missing_ok = false;
9434 $$ = (Node *) n;
9435 }
9436 | ALTER DOMAIN_P any_name RENAME CONSTRAINT name TO name
9437 {
9438 RenameStmt *n = makeNode(RenameStmt);
9439
9440 n->renameType = OBJECT_DOMCONSTRAINT;
9441 n->object = (Node *) $3;
9442 n->subname = $6;
9443 n->newname = $8;
9444 $$ = (Node *) n;
9445 }
9446 | ALTER FOREIGN DATA_P WRAPPER name RENAME TO name
9447 {
9448 RenameStmt *n = makeNode(RenameStmt);
9449
9450 n->renameType = OBJECT_FDW;
9451 n->object = (Node *) makeString($5);
9452 n->newname = $8;
9453 n->missing_ok = false;
9454 $$ = (Node *) n;
9455 }
9456 | ALTER FUNCTION function_with_argtypes RENAME TO name
9457 {
9458 RenameStmt *n = makeNode(RenameStmt);
9459
9460 n->renameType = OBJECT_FUNCTION;
9461 n->object = (Node *) $3;
9462 n->newname = $6;
9463 n->missing_ok = false;
9464 $$ = (Node *) n;
9465 }
9466 | ALTER GROUP_P RoleId RENAME TO RoleId
9467 {
9468 RenameStmt *n = makeNode(RenameStmt);
9469
9470 n->renameType = OBJECT_ROLE;
9471 n->subname = $3;
9472 n->newname = $6;
9473 n->missing_ok = false;
9474 $$ = (Node *) n;
9475 }
9476 | ALTER opt_procedural LANGUAGE name RENAME TO name
9477 {
9478 RenameStmt *n = makeNode(RenameStmt);
9479
9480 n->renameType = OBJECT_LANGUAGE;
9481 n->object = (Node *) makeString($4);
9482 n->newname = $7;
9483 n->missing_ok = false;
9484 $$ = (Node *) n;
9485 }
9486 | ALTER OPERATOR CLASS any_name USING name RENAME TO name
9487 {
9488 RenameStmt *n = makeNode(RenameStmt);
9489
9490 n->renameType = OBJECT_OPCLASS;
9491 n->object = (Node *) lcons(makeString($6), $4);
9492 n->newname = $9;
9493 n->missing_ok = false;
9494 $$ = (Node *) n;
9495 }
9496 | ALTER OPERATOR FAMILY any_name USING name RENAME TO name
9497 {
9498 RenameStmt *n = makeNode(RenameStmt);
9499
9500 n->renameType = OBJECT_OPFAMILY;
9501 n->object = (Node *) lcons(makeString($6), $4);
9502 n->newname = $9;
9503 n->missing_ok = false;
9504 $$ = (Node *) n;
9505 }
9506 | ALTER POLICY name ON qualified_name RENAME TO name
9507 {
9508 RenameStmt *n = makeNode(RenameStmt);
9509
9510 n->renameType = OBJECT_POLICY;
9511 n->relation = $5;
9512 n->subname = $3;
9513 n->newname = $8;
9514 n->missing_ok = false;
9515 $$ = (Node *) n;
9516 }
9517 | ALTER POLICY IF_P EXISTS name ON qualified_name RENAME TO name
9518 {
9519 RenameStmt *n = makeNode(RenameStmt);
9520
9521 n->renameType = OBJECT_POLICY;
9522 n->relation = $7;
9523 n->subname = $5;
9524 n->newname = $10;
9525 n->missing_ok = true;
9526 $$ = (Node *) n;
9527 }
9528 | ALTER PROCEDURE function_with_argtypes RENAME TO name
9529 {
9530 RenameStmt *n = makeNode(RenameStmt);
9531
9532 n->renameType = OBJECT_PROCEDURE;
9533 n->object = (Node *) $3;
9534 n->newname = $6;
9535 n->missing_ok = false;
9536 $$ = (Node *) n;
9537 }
9538 | ALTER PUBLICATION name RENAME TO name
9539 {
9540 RenameStmt *n = makeNode(RenameStmt);
9541
9542 n->renameType = OBJECT_PUBLICATION;
9543 n->object = (Node *) makeString($3);
9544 n->newname = $6;
9545 n->missing_ok = false;
9546 $$ = (Node *) n;
9547 }
9548 | ALTER ROUTINE function_with_argtypes RENAME TO name
9549 {
9550 RenameStmt *n = makeNode(RenameStmt);
9551
9552 n->renameType = OBJECT_ROUTINE;
9553 n->object = (Node *) $3;
9554 n->newname = $6;
9555 n->missing_ok = false;
9556 $$ = (Node *) n;
9557 }
9558 | ALTER SCHEMA name RENAME TO name
9559 {
9560 RenameStmt *n = makeNode(RenameStmt);
9561
9562 n->renameType = OBJECT_SCHEMA;
9563 n->subname = $3;
9564 n->newname = $6;
9565 n->missing_ok = false;
9566 $$ = (Node *) n;
9567 }
9568 | ALTER SERVER name RENAME TO name
9569 {
9570 RenameStmt *n = makeNode(RenameStmt);
9571
9572 n->renameType = OBJECT_FOREIGN_SERVER;
9573 n->object = (Node *) makeString($3);
9574 n->newname = $6;
9575 n->missing_ok = false;
9576 $$ = (Node *) n;
9577 }
9578 | ALTER SUBSCRIPTION name RENAME TO name
9579 {
9580 RenameStmt *n = makeNode(RenameStmt);
9581
9582 n->renameType = OBJECT_SUBSCRIPTION;
9583 n->object = (Node *) makeString($3);
9584 n->newname = $6;
9585 n->missing_ok = false;
9586 $$ = (Node *) n;
9587 }
9588 | ALTER TABLE relation_expr RENAME TO name
9589 {
9590 RenameStmt *n = makeNode(RenameStmt);
9591
9592 n->renameType = OBJECT_TABLE;
9593 n->relation = $3;
9594 n->subname = NULL;
9595 n->newname = $6;
9596 n->missing_ok = false;
9597 $$ = (Node *) n;
9598 }
9599 | ALTER TABLE IF_P EXISTS relation_expr RENAME TO name
9600 {
9601 RenameStmt *n = makeNode(RenameStmt);
9602
9603 n->renameType = OBJECT_TABLE;
9604 n->relation = $5;
9605 n->subname = NULL;
9606 n->newname = $8;
9607 n->missing_ok = true;
9608 $$ = (Node *) n;
9609 }
9610 | ALTER SEQUENCE qualified_name RENAME TO name
9611 {
9612 RenameStmt *n = makeNode(RenameStmt);
9613
9614 n->renameType = OBJECT_SEQUENCE;
9615 n->relation = $3;
9616 n->subname = NULL;
9617 n->newname = $6;
9618 n->missing_ok = false;
9619 $$ = (Node *) n;
9620 }
9621 | ALTER SEQUENCE IF_P EXISTS qualified_name RENAME TO name
9622 {
9623 RenameStmt *n = makeNode(RenameStmt);
9624
9625 n->renameType = OBJECT_SEQUENCE;
9626 n->relation = $5;
9627 n->subname = NULL;
9628 n->newname = $8;
9629 n->missing_ok = true;
9630 $$ = (Node *) n;
9631 }
9632 | ALTER VIEW qualified_name RENAME TO name
9633 {
9634 RenameStmt *n = makeNode(RenameStmt);
9635
9636 n->renameType = OBJECT_VIEW;
9637 n->relation = $3;
9638 n->subname = NULL;
9639 n->newname = $6;
9640 n->missing_ok = false;
9641 $$ = (Node *) n;
9642 }
9643 | ALTER VIEW IF_P EXISTS qualified_name RENAME TO name
9644 {
9645 RenameStmt *n = makeNode(RenameStmt);
9646
9647 n->renameType = OBJECT_VIEW;
9648 n->relation = $5;
9649 n->subname = NULL;
9650 n->newname = $8;
9651 n->missing_ok = true;
9652 $$ = (Node *) n;
9653 }
9654 | ALTER MATERIALIZED VIEW qualified_name RENAME TO name
9655 {
9656 RenameStmt *n = makeNode(RenameStmt);
9657
9658 n->renameType = OBJECT_MATVIEW;
9659 n->relation = $4;
9660 n->subname = NULL;
9661 n->newname = $7;
9662 n->missing_ok = false;
9663 $$ = (Node *) n;
9664 }
9665 | ALTER MATERIALIZED VIEW IF_P EXISTS qualified_name RENAME TO name
9666 {
9667 RenameStmt *n = makeNode(RenameStmt);
9668
9669 n->renameType = OBJECT_MATVIEW;
9670 n->relation = $6;
9671 n->subname = NULL;
9672 n->newname = $9;
9673 n->missing_ok = true;
9674 $$ = (Node *) n;
9675 }
9676 | ALTER INDEX qualified_name RENAME TO name
9677 {
9678 RenameStmt *n = makeNode(RenameStmt);
9679
9680 n->renameType = OBJECT_INDEX;
9681 n->relation = $3;
9682 n->subname = NULL;
9683 n->newname = $6;
9684 n->missing_ok = false;
9685 $$ = (Node *) n;
9686 }
9687 | ALTER INDEX IF_P EXISTS qualified_name RENAME TO name
9688 {
9689 RenameStmt *n = makeNode(RenameStmt);
9690
9691 n->renameType = OBJECT_INDEX;
9692 n->relation = $5;
9693 n->subname = NULL;
9694 n->newname = $8;
9695 n->missing_ok = true;
9696 $$ = (Node *) n;
9697 }
9698 | ALTER FOREIGN TABLE relation_expr RENAME TO name
9699 {
9700 RenameStmt *n = makeNode(RenameStmt);
9701
9702 n->renameType = OBJECT_FOREIGN_TABLE;
9703 n->relation = $4;
9704 n->subname = NULL;
9705 n->newname = $7;
9706 n->missing_ok = false;
9707 $$ = (Node *) n;
9708 }
9709 | ALTER FOREIGN TABLE IF_P EXISTS relation_expr RENAME TO name
9710 {
9711 RenameStmt *n = makeNode(RenameStmt);
9712
9713 n->renameType = OBJECT_FOREIGN_TABLE;
9714 n->relation = $6;
9715 n->subname = NULL;
9716 n->newname = $9;
9717 n->missing_ok = true;
9718 $$ = (Node *) n;
9719 }
9720 | ALTER TABLE relation_expr RENAME opt_column name TO name
9721 {
9722 RenameStmt *n = makeNode(RenameStmt);
9723
9724 n->renameType = OBJECT_COLUMN;
9725 n->relationType = OBJECT_TABLE;
9726 n->relation = $3;
9727 n->subname = $6;
9728 n->newname = $8;
9729 n->missing_ok = false;
9730 $$ = (Node *) n;
9731 }
9732 | ALTER TABLE IF_P EXISTS relation_expr RENAME opt_column name TO name
9733 {
9734 RenameStmt *n = makeNode(RenameStmt);
9735
9736 n->renameType = OBJECT_COLUMN;
9737 n->relationType = OBJECT_TABLE;
9738 n->relation = $5;
9739 n->subname = $8;
9740 n->newname = $10;
9741 n->missing_ok = true;
9742 $$ = (Node *) n;
9743 }
9744 | ALTER VIEW qualified_name RENAME opt_column name TO name
9745 {
9746 RenameStmt *n = makeNode(RenameStmt);
9747
9748 n->renameType = OBJECT_COLUMN;
9749 n->relationType = OBJECT_VIEW;
9750 n->relation = $3;
9751 n->subname = $6;
9752 n->newname = $8;
9753 n->missing_ok = false;
9754 $$ = (Node *) n;
9755 }
9756 | ALTER VIEW IF_P EXISTS qualified_name RENAME opt_column name TO name
9757 {
9758 RenameStmt *n = makeNode(RenameStmt);
9759
9760 n->renameType = OBJECT_COLUMN;
9761 n->relationType = OBJECT_VIEW;
9762 n->relation = $5;
9763 n->subname = $8;
9764 n->newname = $10;
9765 n->missing_ok = true;
9766 $$ = (Node *) n;
9767 }
9768 | ALTER MATERIALIZED VIEW qualified_name RENAME opt_column name TO name
9769 {
9770 RenameStmt *n = makeNode(RenameStmt);
9771
9772 n->renameType = OBJECT_COLUMN;
9773 n->relationType = OBJECT_MATVIEW;
9774 n->relation = $4;
9775 n->subname = $7;
9776 n->newname = $9;
9777 n->missing_ok = false;
9778 $$ = (Node *) n;
9779 }
9780 | ALTER MATERIALIZED VIEW IF_P EXISTS qualified_name RENAME opt_column name TO name
9781 {
9782 RenameStmt *n = makeNode(RenameStmt);
9783
9784 n->renameType = OBJECT_COLUMN;
9785 n->relationType = OBJECT_MATVIEW;
9786 n->relation = $6;
9787 n->subname = $9;
9788 n->newname = $11;
9789 n->missing_ok = true;
9790 $$ = (Node *) n;
9791 }
9792 | ALTER TABLE relation_expr RENAME CONSTRAINT name TO name
9793 {
9794 RenameStmt *n = makeNode(RenameStmt);
9795
9796 n->renameType = OBJECT_TABCONSTRAINT;
9797 n->relation = $3;
9798 n->subname = $6;
9799 n->newname = $8;
9800 n->missing_ok = false;
9801 $$ = (Node *) n;
9802 }
9803 | ALTER TABLE IF_P EXISTS relation_expr RENAME CONSTRAINT name TO name
9804 {
9805 RenameStmt *n = makeNode(RenameStmt);
9806
9807 n->renameType = OBJECT_TABCONSTRAINT;
9808 n->relation = $5;
9809 n->subname = $8;
9810 n->newname = $10;
9811 n->missing_ok = true;
9812 $$ = (Node *) n;
9813 }
9814 | ALTER FOREIGN TABLE relation_expr RENAME opt_column name TO name
9815 {
9816 RenameStmt *n = makeNode(RenameStmt);
9817
9818 n->renameType = OBJECT_COLUMN;
9819 n->relationType = OBJECT_FOREIGN_TABLE;
9820 n->relation = $4;
9821 n->subname = $7;
9822 n->newname = $9;
9823 n->missing_ok = false;
9824 $$ = (Node *) n;
9825 }
9826 | ALTER FOREIGN TABLE IF_P EXISTS relation_expr RENAME opt_column name TO name
9827 {
9828 RenameStmt *n = makeNode(RenameStmt);
9829
9830 n->renameType = OBJECT_COLUMN;
9831 n->relationType = OBJECT_FOREIGN_TABLE;
9832 n->relation = $6;
9833 n->subname = $9;
9834 n->newname = $11;
9835 n->missing_ok = true;
9836 $$ = (Node *) n;
9837 }
9838 | ALTER RULE name ON qualified_name RENAME TO name
9839 {
9840 RenameStmt *n = makeNode(RenameStmt);
9841
9842 n->renameType = OBJECT_RULE;
9843 n->relation = $5;
9844 n->subname = $3;
9845 n->newname = $8;
9846 n->missing_ok = false;
9847 $$ = (Node *) n;
9848 }
9849 | ALTER TRIGGER name ON qualified_name RENAME TO name
9850 {
9851 RenameStmt *n = makeNode(RenameStmt);
9852
9853 n->renameType = OBJECT_TRIGGER;
9854 n->relation = $5;
9855 n->subname = $3;
9856 n->newname = $8;
9857 n->missing_ok = false;
9858 $$ = (Node *) n;
9859 }
9860 | ALTER EVENT TRIGGER name RENAME TO name
9861 {
9862 RenameStmt *n = makeNode(RenameStmt);
9863
9864 n->renameType = OBJECT_EVENT_TRIGGER;
9865 n->object = (Node *) makeString($4);
9866 n->newname = $7;
9867 $$ = (Node *) n;
9868 }
9869 | ALTER ROLE RoleId RENAME TO RoleId
9870 {
9871 RenameStmt *n = makeNode(RenameStmt);
9872
9873 n->renameType = OBJECT_ROLE;
9874 n->subname = $3;
9875 n->newname = $6;
9876 n->missing_ok = false;
9877 $$ = (Node *) n;
9878 }
9879 | ALTER USER RoleId RENAME TO RoleId
9880 {
9881 RenameStmt *n = makeNode(RenameStmt);
9882
9883 n->renameType = OBJECT_ROLE;
9884 n->subname = $3;
9885 n->newname = $6;
9886 n->missing_ok = false;
9887 $$ = (Node *) n;
9888 }
9889 | ALTER TABLESPACE name RENAME TO name
9890 {
9891 RenameStmt *n = makeNode(RenameStmt);
9892
9893 n->renameType = OBJECT_TABLESPACE;
9894 n->subname = $3;
9895 n->newname = $6;
9896 n->missing_ok = false;
9897 $$ = (Node *) n;
9898 }
9899 | ALTER STATISTICS any_name RENAME TO name
9900 {
9901 RenameStmt *n = makeNode(RenameStmt);
9902
9903 n->renameType = OBJECT_STATISTIC_EXT;
9904 n->object = (Node *) $3;
9905 n->newname = $6;
9906 n->missing_ok = false;
9907 $$ = (Node *) n;
9908 }
9909 | ALTER TEXT_P SEARCH PARSER any_name RENAME TO name
9910 {
9911 RenameStmt *n = makeNode(RenameStmt);
9912
9913 n->renameType = OBJECT_TSPARSER;
9914 n->object = (Node *) $5;
9915 n->newname = $8;
9916 n->missing_ok = false;
9917 $$ = (Node *) n;
9918 }
9919 | ALTER TEXT_P SEARCH DICTIONARY any_name RENAME TO name
9920 {
9921 RenameStmt *n = makeNode(RenameStmt);
9922
9923 n->renameType = OBJECT_TSDICTIONARY;
9924 n->object = (Node *) $5;
9925 n->newname = $8;
9926 n->missing_ok = false;
9927 $$ = (Node *) n;
9928 }
9929 | ALTER TEXT_P SEARCH TEMPLATE any_name RENAME TO name
9930 {
9931 RenameStmt *n = makeNode(RenameStmt);
9932
9933 n->renameType = OBJECT_TSTEMPLATE;
9934 n->object = (Node *) $5;
9935 n->newname = $8;
9936 n->missing_ok = false;
9937 $$ = (Node *) n;
9938 }
9939 | ALTER TEXT_P SEARCH CONFIGURATION any_name RENAME TO name
9940 {
9941 RenameStmt *n = makeNode(RenameStmt);
9942
9943 n->renameType = OBJECT_TSCONFIGURATION;
9944 n->object = (Node *) $5;
9945 n->newname = $8;
9946 n->missing_ok = false;
9947 $$ = (Node *) n;
9948 }
9949 | ALTER TYPE_P any_name RENAME TO name
9950 {
9951 RenameStmt *n = makeNode(RenameStmt);
9952
9953 n->renameType = OBJECT_TYPE;
9954 n->object = (Node *) $3;
9955 n->newname = $6;
9956 n->missing_ok = false;
9957 $$ = (Node *) n;
9958 }
9959 | ALTER TYPE_P any_name RENAME ATTRIBUTE name TO name opt_drop_behavior
9960 {
9961 RenameStmt *n = makeNode(RenameStmt);
9962
9963 n->renameType = OBJECT_ATTRIBUTE;
9964 n->relationType = OBJECT_TYPE;
9965 n->relation = makeRangeVarFromAnyName($3, @3, yyscanner);
9966 n->subname = $6;
9967 n->newname = $8;
9968 n->behavior = $9;
9969 n->missing_ok = false;
9970 $$ = (Node *) n;
9971 }
9972 ;
9973
9974 opt_column: COLUMN
9975 | /*EMPTY*/
9976 ;
9977
9978 opt_set_data: SET DATA_P { $$ = 1; }
9979 | /*EMPTY*/ { $$ = 0; }
9980 ;
9981
9982 /*****************************************************************************
9983 *
9984 * ALTER THING name DEPENDS ON EXTENSION name
9985 *
9986 *****************************************************************************/
9987
9988 AlterObjectDependsStmt:
9989 ALTER FUNCTION function_with_argtypes opt_no DEPENDS ON EXTENSION name
9990 {
9991 AlterObjectDependsStmt *n = makeNode(AlterObjectDependsStmt);
9992
9993 n->objectType = OBJECT_FUNCTION;
9994 n->object = (Node *) $3;
9995 n->extname = makeString($8);
9996 n->remove = $4;
9997 $$ = (Node *) n;
9998 }
9999 | ALTER PROCEDURE function_with_argtypes opt_no DEPENDS ON EXTENSION name
10000 {
10001 AlterObjectDependsStmt *n = makeNode(AlterObjectDependsStmt);
10002
10003 n->objectType = OBJECT_PROCEDURE;
10004 n->object = (Node *) $3;
10005 n->extname = makeString($8);
10006 n->remove = $4;
10007 $$ = (Node *) n;
10008 }
10009 | ALTER ROUTINE function_with_argtypes opt_no DEPENDS ON EXTENSION name
10010 {
10011 AlterObjectDependsStmt *n = makeNode(AlterObjectDependsStmt);
10012
10013 n->objectType = OBJECT_ROUTINE;
10014 n->object = (Node *) $3;
10015 n->extname = makeString($8);
10016 n->remove = $4;
10017 $$ = (Node *) n;
10018 }
10019 | ALTER TRIGGER name ON qualified_name opt_no DEPENDS ON EXTENSION name
10020 {
10021 AlterObjectDependsStmt *n = makeNode(AlterObjectDependsStmt);
10022
10023 n->objectType = OBJECT_TRIGGER;
10024 n->relation = $5;
10025 n->object = (Node *) list_make1(makeString($3));
10026 n->extname = makeString($10);
10027 n->remove = $6;
10028 $$ = (Node *) n;
10029 }
10030 | ALTER MATERIALIZED VIEW qualified_name opt_no DEPENDS ON EXTENSION name
10031 {
10032 AlterObjectDependsStmt *n = makeNode(AlterObjectDependsStmt);
10033
10034 n->objectType = OBJECT_MATVIEW;
10035 n->relation = $4;
10036 n->extname = makeString($9);
10037 n->remove = $5;
10038 $$ = (Node *) n;
10039 }
10040 | ALTER INDEX qualified_name opt_no DEPENDS ON EXTENSION name
10041 {
10042 AlterObjectDependsStmt *n = makeNode(AlterObjectDependsStmt);
10043
10044 n->objectType = OBJECT_INDEX;
10045 n->relation = $3;
10046 n->extname = makeString($8);
10047 n->remove = $4;
10048 $$ = (Node *) n;
10049 }
10050 ;
10051
10052 opt_no: NO { $$ = true; }
10053 | /* EMPTY */ { $$ = false; }
10054 ;
10055
10056 /*****************************************************************************
10057 *
10058 * ALTER THING name SET SCHEMA name
10059 *
10060 *****************************************************************************/
10061
10062 AlterObjectSchemaStmt:
10063 ALTER AGGREGATE aggregate_with_argtypes SET SCHEMA name
10064 {
10065 AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
10066
10067 n->objectType = OBJECT_AGGREGATE;
10068 n->object = (Node *) $3;
10069 n->newschema = $6;
10070 n->missing_ok = false;
10071 $$ = (Node *) n;
10072 }
10073 | ALTER COLLATION any_name SET SCHEMA name
10074 {
10075 AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
10076
10077 n->objectType = OBJECT_COLLATION;
10078 n->object = (Node *) $3;
10079 n->newschema = $6;
10080 n->missing_ok = false;
10081 $$ = (Node *) n;
10082 }
10083 | ALTER CONVERSION_P any_name SET SCHEMA name
10084 {
10085 AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
10086
10087 n->objectType = OBJECT_CONVERSION;
10088 n->object = (Node *) $3;
10089 n->newschema = $6;
10090 n->missing_ok = false;
10091 $$ = (Node *) n;
10092 }
10093 | ALTER DOMAIN_P any_name SET SCHEMA name
10094 {
10095 AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
10096
10097 n->objectType = OBJECT_DOMAIN;
10098 n->object = (Node *) $3;
10099 n->newschema = $6;
10100 n->missing_ok = false;
10101 $$ = (Node *) n;
10102 }
10103 | ALTER EXTENSION name SET SCHEMA name
10104 {
10105 AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
10106
10107 n->objectType = OBJECT_EXTENSION;
10108 n->object = (Node *) makeString($3);
10109 n->newschema = $6;
10110 n->missing_ok = false;
10111 $$ = (Node *) n;
10112 }
10113 | ALTER FUNCTION function_with_argtypes SET SCHEMA name
10114 {
10115 AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
10116
10117 n->objectType = OBJECT_FUNCTION;
10118 n->object = (Node *) $3;
10119 n->newschema = $6;
10120 n->missing_ok = false;
10121 $$ = (Node *) n;
10122 }
10123 | ALTER OPERATOR operator_with_argtypes SET SCHEMA name
10124 {
10125 AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
10126
10127 n->objectType = OBJECT_OPERATOR;
10128 n->object = (Node *) $3;
10129 n->newschema = $6;
10130 n->missing_ok = false;
10131 $$ = (Node *) n;
10132 }
10133 | ALTER OPERATOR CLASS any_name USING name SET SCHEMA name
10134 {
10135 AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
10136
10137 n->objectType = OBJECT_OPCLASS;
10138 n->object = (Node *) lcons(makeString($6), $4);
10139 n->newschema = $9;
10140 n->missing_ok = false;
10141 $$ = (Node *) n;
10142 }
10143 | ALTER OPERATOR FAMILY any_name USING name SET SCHEMA name
10144 {
10145 AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
10146
10147 n->objectType = OBJECT_OPFAMILY;
10148 n->object = (Node *) lcons(makeString($6), $4);
10149 n->newschema = $9;
10150 n->missing_ok = false;
10151 $$ = (Node *) n;
10152 }
10153 | ALTER PROCEDURE function_with_argtypes SET SCHEMA name
10154 {
10155 AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
10156
10157 n->objectType = OBJECT_PROCEDURE;
10158 n->object = (Node *) $3;
10159 n->newschema = $6;
10160 n->missing_ok = false;
10161 $$ = (Node *) n;
10162 }
10163 | ALTER ROUTINE function_with_argtypes SET SCHEMA name
10164 {
10165 AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
10166
10167 n->objectType = OBJECT_ROUTINE;
10168 n->object = (Node *) $3;
10169 n->newschema = $6;
10170 n->missing_ok = false;
10171 $$ = (Node *) n;
10172 }
10173 | ALTER TABLE relation_expr SET SCHEMA name
10174 {
10175 AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
10176
10177 n->objectType = OBJECT_TABLE;
10178 n->relation = $3;
10179 n->newschema = $6;
10180 n->missing_ok = false;
10181 $$ = (Node *) n;
10182 }
10183 | ALTER TABLE IF_P EXISTS relation_expr SET SCHEMA name
10184 {
10185 AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
10186
10187 n->objectType = OBJECT_TABLE;
10188 n->relation = $5;
10189 n->newschema = $8;
10190 n->missing_ok = true;
10191 $$ = (Node *) n;
10192 }
10193 | ALTER STATISTICS any_name SET SCHEMA name
10194 {
10195 AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
10196
10197 n->objectType = OBJECT_STATISTIC_EXT;
10198 n->object = (Node *) $3;
10199 n->newschema = $6;
10200 n->missing_ok = false;
10201 $$ = (Node *) n;
10202 }
10203 | ALTER TEXT_P SEARCH PARSER any_name SET SCHEMA name
10204 {
10205 AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
10206
10207 n->objectType = OBJECT_TSPARSER;
10208 n->object = (Node *) $5;
10209 n->newschema = $8;
10210 n->missing_ok = false;
10211 $$ = (Node *) n;
10212 }
10213 | ALTER TEXT_P SEARCH DICTIONARY any_name SET SCHEMA name
10214 {
10215 AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
10216
10217 n->objectType = OBJECT_TSDICTIONARY;
10218 n->object = (Node *) $5;
10219 n->newschema = $8;
10220 n->missing_ok = false;
10221 $$ = (Node *) n;
10222 }
10223 | ALTER TEXT_P SEARCH TEMPLATE any_name SET SCHEMA name
10224 {
10225 AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
10226
10227 n->objectType = OBJECT_TSTEMPLATE;
10228 n->object = (Node *) $5;
10229 n->newschema = $8;
10230 n->missing_ok = false;
10231 $$ = (Node *) n;
10232 }
10233 | ALTER TEXT_P SEARCH CONFIGURATION any_name SET SCHEMA name
10234 {
10235 AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
10236
10237 n->objectType = OBJECT_TSCONFIGURATION;
10238 n->object = (Node *) $5;
10239 n->newschema = $8;
10240 n->missing_ok = false;
10241 $$ = (Node *) n;
10242 }
10243 | ALTER SEQUENCE qualified_name SET SCHEMA name
10244 {
10245 AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
10246
10247 n->objectType = OBJECT_SEQUENCE;
10248 n->relation = $3;
10249 n->newschema = $6;
10250 n->missing_ok = false;
10251 $$ = (Node *) n;
10252 }
10253 | ALTER SEQUENCE IF_P EXISTS qualified_name SET SCHEMA name
10254 {
10255 AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
10256
10257 n->objectType = OBJECT_SEQUENCE;
10258 n->relation = $5;
10259 n->newschema = $8;
10260 n->missing_ok = true;
10261 $$ = (Node *) n;
10262 }
10263 | ALTER VIEW qualified_name SET SCHEMA name
10264 {
10265 AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
10266
10267 n->objectType = OBJECT_VIEW;
10268 n->relation = $3;
10269 n->newschema = $6;
10270 n->missing_ok = false;
10271 $$ = (Node *) n;
10272 }
10273 | ALTER VIEW IF_P EXISTS qualified_name SET SCHEMA name
10274 {
10275 AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
10276
10277 n->objectType = OBJECT_VIEW;
10278 n->relation = $5;
10279 n->newschema = $8;
10280 n->missing_ok = true;
10281 $$ = (Node *) n;
10282 }
10283 | ALTER MATERIALIZED VIEW qualified_name SET SCHEMA name
10284 {
10285 AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
10286
10287 n->objectType = OBJECT_MATVIEW;
10288 n->relation = $4;
10289 n->newschema = $7;
10290 n->missing_ok = false;
10291 $$ = (Node *) n;
10292 }
10293 | ALTER MATERIALIZED VIEW IF_P EXISTS qualified_name SET SCHEMA name
10294 {
10295 AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
10296
10297 n->objectType = OBJECT_MATVIEW;
10298 n->relation = $6;
10299 n->newschema = $9;
10300 n->missing_ok = true;
10301 $$ = (Node *) n;
10302 }
10303 | ALTER FOREIGN TABLE relation_expr SET SCHEMA name
10304 {
10305 AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
10306
10307 n->objectType = OBJECT_FOREIGN_TABLE;
10308 n->relation = $4;
10309 n->newschema = $7;
10310 n->missing_ok = false;
10311 $$ = (Node *) n;
10312 }
10313 | ALTER FOREIGN TABLE IF_P EXISTS relation_expr SET SCHEMA name
10314 {
10315 AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
10316
10317 n->objectType = OBJECT_FOREIGN_TABLE;
10318 n->relation = $6;
10319 n->newschema = $9;
10320 n->missing_ok = true;
10321 $$ = (Node *) n;
10322 }
10323 | ALTER TYPE_P any_name SET SCHEMA name
10324 {
10325 AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
10326
10327 n->objectType = OBJECT_TYPE;
10328 n->object = (Node *) $3;
10329 n->newschema = $6;
10330 n->missing_ok = false;
10331 $$ = (Node *) n;
10332 }
10333 ;
10334
10335 /*****************************************************************************
10336 *
10337 * ALTER OPERATOR name SET define
10338 *
10339 *****************************************************************************/
10340
10341 AlterOperatorStmt:
10342 ALTER OPERATOR operator_with_argtypes SET '(' operator_def_list ')'
10343 {
10344 AlterOperatorStmt *n = makeNode(AlterOperatorStmt);
10345
10346 n->opername = $3;
10347 n->options = $6;
10348 $$ = (Node *) n;
10349 }
10350 ;
10351
10352 operator_def_list: operator_def_elem { $$ = list_make1($1); }
10353 | operator_def_list ',' operator_def_elem { $$ = lappend($1, $3); }
10354 ;
10355
10356 operator_def_elem: ColLabel '=' NONE
10357 { $$ = makeDefElem($1, NULL, @1); }
10358 | ColLabel '=' operator_def_arg
10359 { $$ = makeDefElem($1, (Node *) $3, @1); }
10360 | ColLabel
10361 { $$ = makeDefElem($1, NULL, @1); }
10362 ;
10363
10364 /* must be similar enough to def_arg to avoid reduce/reduce conflicts */
10365 operator_def_arg:
10366 func_type { $$ = (Node *) $1; }
10367 | reserved_keyword { $$ = (Node *) makeString(pstrdup($1)); }
10368 | qual_all_Op { $$ = (Node *) $1; }
10369 | NumericOnly { $$ = (Node *) $1; }
10370 | Sconst { $$ = (Node *) makeString($1); }
10371 ;
10372
10373 /*****************************************************************************
10374 *
10375 * ALTER TYPE name SET define
10376 *
10377 * We repurpose ALTER OPERATOR's version of "definition" here
10378 *
10379 *****************************************************************************/
10380
10381 AlterTypeStmt:
10382 ALTER TYPE_P any_name SET '(' operator_def_list ')'
10383 {
10384 AlterTypeStmt *n = makeNode(AlterTypeStmt);
10385
10386 n->typeName = $3;
10387 n->options = $6;
10388 $$ = (Node *) n;
10389 }
10390 ;
10391
10392 /*****************************************************************************
10393 *
10394 * ALTER THING name OWNER TO newname
10395 *
10396 *****************************************************************************/
10397
10398 AlterOwnerStmt: ALTER AGGREGATE aggregate_with_argtypes OWNER TO RoleSpec
10399 {
10400 AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
10401
10402 n->objectType = OBJECT_AGGREGATE;
10403 n->object = (Node *) $3;
10404 n->newowner = $6;
10405 $$ = (Node *) n;
10406 }
10407 | ALTER COLLATION any_name OWNER TO RoleSpec
10408 {
10409 AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
10410
10411 n->objectType = OBJECT_COLLATION;
10412 n->object = (Node *) $3;
10413 n->newowner = $6;
10414 $$ = (Node *) n;
10415 }
10416 | ALTER CONVERSION_P any_name OWNER TO RoleSpec
10417 {
10418 AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
10419
10420 n->objectType = OBJECT_CONVERSION;
10421 n->object = (Node *) $3;
10422 n->newowner = $6;
10423 $$ = (Node *) n;
10424 }
10425 | ALTER DATABASE name OWNER TO RoleSpec
10426 {
10427 AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
10428
10429 n->objectType = OBJECT_DATABASE;
10430 n->object = (Node *) makeString($3);
10431 n->newowner = $6;
10432 $$ = (Node *) n;
10433 }
10434 | ALTER DOMAIN_P any_name OWNER TO RoleSpec
10435 {
10436 AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
10437
10438 n->objectType = OBJECT_DOMAIN;
10439 n->object = (Node *) $3;
10440 n->newowner = $6;
10441 $$ = (Node *) n;
10442 }
10443 | ALTER FUNCTION function_with_argtypes OWNER TO RoleSpec
10444 {
10445 AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
10446
10447 n->objectType = OBJECT_FUNCTION;
10448 n->object = (Node *) $3;
10449 n->newowner = $6;
10450 $$ = (Node *) n;
10451 }
10452 | ALTER opt_procedural LANGUAGE name OWNER TO RoleSpec
10453 {
10454 AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
10455
10456 n->objectType = OBJECT_LANGUAGE;
10457 n->object = (Node *) makeString($4);
10458 n->newowner = $7;
10459 $$ = (Node *) n;
10460 }
10461 | ALTER LARGE_P OBJECT_P NumericOnly OWNER TO RoleSpec
10462 {
10463 AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
10464
10465 n->objectType = OBJECT_LARGEOBJECT;
10466 n->object = (Node *) $4;
10467 n->newowner = $7;
10468 $$ = (Node *) n;
10469 }
10470 | ALTER OPERATOR operator_with_argtypes OWNER TO RoleSpec
10471 {
10472 AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
10473
10474 n->objectType = OBJECT_OPERATOR;
10475 n->object = (Node *) $3;
10476 n->newowner = $6;
10477 $$ = (Node *) n;
10478 }
10479 | ALTER OPERATOR CLASS any_name USING name OWNER TO RoleSpec
10480 {
10481 AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
10482
10483 n->objectType = OBJECT_OPCLASS;
10484 n->object = (Node *) lcons(makeString($6), $4);
10485 n->newowner = $9;
10486 $$ = (Node *) n;
10487 }
10488 | ALTER OPERATOR FAMILY any_name USING name OWNER TO RoleSpec
10489 {
10490 AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
10491
10492 n->objectType = OBJECT_OPFAMILY;
10493 n->object = (Node *) lcons(makeString($6), $4);
10494 n->newowner = $9;
10495 $$ = (Node *) n;
10496 }
10497 | ALTER PROCEDURE function_with_argtypes OWNER TO RoleSpec
10498 {
10499 AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
10500
10501 n->objectType = OBJECT_PROCEDURE;
10502 n->object = (Node *) $3;
10503 n->newowner = $6;
10504 $$ = (Node *) n;
10505 }
10506 | ALTER ROUTINE function_with_argtypes OWNER TO RoleSpec
10507 {
10508 AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
10509
10510 n->objectType = OBJECT_ROUTINE;
10511 n->object = (Node *) $3;
10512 n->newowner = $6;
10513 $$ = (Node *) n;
10514 }
10515 | ALTER SCHEMA name OWNER TO RoleSpec
10516 {
10517 AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
10518
10519 n->objectType = OBJECT_SCHEMA;
10520 n->object = (Node *) makeString($3);
10521 n->newowner = $6;
10522 $$ = (Node *) n;
10523 }
10524 | ALTER TYPE_P any_name OWNER TO RoleSpec
10525 {
10526 AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
10527
10528 n->objectType = OBJECT_TYPE;
10529 n->object = (Node *) $3;
10530 n->newowner = $6;
10531 $$ = (Node *) n;
10532 }
10533 | ALTER TABLESPACE name OWNER TO RoleSpec
10534 {
10535 AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
10536
10537 n->objectType = OBJECT_TABLESPACE;
10538 n->object = (Node *) makeString($3);
10539 n->newowner = $6;
10540 $$ = (Node *) n;
10541 }
10542 | ALTER STATISTICS any_name OWNER TO RoleSpec
10543 {
10544 AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
10545
10546 n->objectType = OBJECT_STATISTIC_EXT;
10547 n->object = (Node *) $3;
10548 n->newowner = $6;
10549 $$ = (Node *) n;
10550 }
10551 | ALTER TEXT_P SEARCH DICTIONARY any_name OWNER TO RoleSpec
10552 {
10553 AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
10554
10555 n->objectType = OBJECT_TSDICTIONARY;
10556 n->object = (Node *) $5;
10557 n->newowner = $8;
10558 $$ = (Node *) n;
10559 }
10560 | ALTER TEXT_P SEARCH CONFIGURATION any_name OWNER TO RoleSpec
10561 {
10562 AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
10563
10564 n->objectType = OBJECT_TSCONFIGURATION;
10565 n->object = (Node *) $5;
10566 n->newowner = $8;
10567 $$ = (Node *) n;
10568 }
10569 | ALTER FOREIGN DATA_P WRAPPER name OWNER TO RoleSpec
10570 {
10571 AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
10572
10573 n->objectType = OBJECT_FDW;
10574 n->object = (Node *) makeString($5);
10575 n->newowner = $8;
10576 $$ = (Node *) n;
10577 }
10578 | ALTER SERVER name OWNER TO RoleSpec
10579 {
10580 AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
10581
10582 n->objectType = OBJECT_FOREIGN_SERVER;
10583 n->object = (Node *) makeString($3);
10584 n->newowner = $6;
10585 $$ = (Node *) n;
10586 }
10587 | ALTER EVENT TRIGGER name OWNER TO RoleSpec
10588 {
10589 AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
10590
10591 n->objectType = OBJECT_EVENT_TRIGGER;
10592 n->object = (Node *) makeString($4);
10593 n->newowner = $7;
10594 $$ = (Node *) n;
10595 }
10596 | ALTER PUBLICATION name OWNER TO RoleSpec
10597 {
10598 AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
10599
10600 n->objectType = OBJECT_PUBLICATION;
10601 n->object = (Node *) makeString($3);
10602 n->newowner = $6;
10603 $$ = (Node *) n;
10604 }
10605 | ALTER SUBSCRIPTION name OWNER TO RoleSpec
10606 {
10607 AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
10608
10609 n->objectType = OBJECT_SUBSCRIPTION;
10610 n->object = (Node *) makeString($3);
10611 n->newowner = $6;
10612 $$ = (Node *) n;
10613 }
10614 ;
10615
10616
10617 /*****************************************************************************
10618 *
10619 * CREATE PUBLICATION name [WITH options]
10620 *
10621 * CREATE PUBLICATION FOR ALL TABLES [WITH options]
10622 *
10623 * CREATE PUBLICATION FOR pub_obj [, ...] [WITH options]
10624 *
10625 * pub_obj is one of:
10626 *
10627 * TABLE table [, ...]
10628 * TABLES IN SCHEMA schema [, ...]
10629 *
10630 *****************************************************************************/
10631
10632 CreatePublicationStmt:
10633 CREATE PUBLICATION name opt_definition
10634 {
10635 CreatePublicationStmt *n = makeNode(CreatePublicationStmt);
10636
10637 n->pubname = $3;
10638 n->options = $4;
10639 $$ = (Node *) n;
10640 }
10641 | CREATE PUBLICATION name FOR ALL TABLES opt_definition
10642 {
10643 CreatePublicationStmt *n = makeNode(CreatePublicationStmt);
10644
10645 n->pubname = $3;
10646 n->options = $7;
10647 n->for_all_tables = true;
10648 $$ = (Node *) n;
10649 }
10650 | CREATE PUBLICATION name FOR pub_obj_list opt_definition
10651 {
10652 CreatePublicationStmt *n = makeNode(CreatePublicationStmt);
10653
10654 n->pubname = $3;
10655 n->options = $6;
10656 n->pubobjects = (List *) $5;
10657 preprocess_pubobj_list(n->pubobjects, yyscanner);
10658 $$ = (Node *) n;
10659 }
10660 ;
10661
10662 /*
10663 * FOR TABLE and FOR TABLES IN SCHEMA specifications
10664 *
10665 * This rule parses publication objects with and without keyword prefixes.
10666 *
10667 * The actual type of the object without keyword prefix depends on the previous
10668 * one with keyword prefix. It will be preprocessed in preprocess_pubobj_list().
10669 *
10670 * For the object without keyword prefix, we cannot just use relation_expr here,
10671 * because some extended expressions in relation_expr cannot be used as a
10672 * schemaname and we cannot differentiate it. So, we extract the rules from
10673 * relation_expr here.
10674 */
10675 PublicationObjSpec:
10676 TABLE relation_expr opt_column_list OptWhereClause
10677 {
10678 $$ = makeNode(PublicationObjSpec);
10679 $$->pubobjtype = PUBLICATIONOBJ_TABLE;
10680 $$->pubtable = makeNode(PublicationTable);
10681 $$->pubtable->relation = $2;
10682 $$->pubtable->columns = $3;
10683 $$->pubtable->whereClause = $4;
10684 }
10685 | TABLES IN_P SCHEMA ColId
10686 {
10687 $$ = makeNode(PublicationObjSpec);
10688 $$->pubobjtype = PUBLICATIONOBJ_TABLES_IN_SCHEMA;
10689 $$->name = $4;
10690 $$->location = @4;
10691 }
10692 | TABLES IN_P SCHEMA CURRENT_SCHEMA
10693 {
10694 $$ = makeNode(PublicationObjSpec);
10695 $$->pubobjtype = PUBLICATIONOBJ_TABLES_IN_CUR_SCHEMA;
10696 $$->location = @4;
10697 }
10698 | ColId opt_column_list OptWhereClause
10699 {
10700 $$ = makeNode(PublicationObjSpec);
10701 $$->pubobjtype = PUBLICATIONOBJ_CONTINUATION;
10702 /*
10703 * If either a row filter or column list is specified, create
10704 * a PublicationTable object.
10705 */
10706 if ($2 || $3)
10707 {
10708 /*
10709 * The OptWhereClause must be stored here but it is
10710 * valid only for tables. For non-table objects, an
10711 * error will be thrown later via
10712 * preprocess_pubobj_list().
10713 */
10714 $$->pubtable = makeNode(PublicationTable);
10715 $$->pubtable->relation = makeRangeVar(NULL, $1, @1);
10716 $$->pubtable->columns = $2;
10717 $$->pubtable->whereClause = $3;
10718 }
10719 else
10720 {
10721 $$->name = $1;
10722 }
10723 $$->location = @1;
10724 }
10725 | ColId indirection opt_column_list OptWhereClause
10726 {
10727 $$ = makeNode(PublicationObjSpec);
10728 $$->pubobjtype = PUBLICATIONOBJ_CONTINUATION;
10729 $$->pubtable = makeNode(PublicationTable);
10730 $$->pubtable->relation = makeRangeVarFromQualifiedName($1, $2, @1, yyscanner);
10731 $$->pubtable->columns = $3;
10732 $$->pubtable->whereClause = $4;
10733 $$->location = @1;
10734 }
10735 /* grammar like tablename * , ONLY tablename, ONLY ( tablename ) */
10736 | extended_relation_expr opt_column_list OptWhereClause
10737 {
10738 $$ = makeNode(PublicationObjSpec);
10739 $$->pubobjtype = PUBLICATIONOBJ_CONTINUATION;
10740 $$->pubtable = makeNode(PublicationTable);
10741 $$->pubtable->relation = $1;
10742 $$->pubtable->columns = $2;
10743 $$->pubtable->whereClause = $3;
10744 }
10745 | CURRENT_SCHEMA
10746 {
10747 $$ = makeNode(PublicationObjSpec);
10748 $$->pubobjtype = PUBLICATIONOBJ_CONTINUATION;
10749 $$->location = @1;
10750 }
10751 ;
10752
10753 pub_obj_list: PublicationObjSpec
10754 { $$ = list_make1($1); }
10755 | pub_obj_list ',' PublicationObjSpec
10756 { $$ = lappend($1, $3); }
10757 ;
10758
10759 /*****************************************************************************
10760 *
10761 * ALTER PUBLICATION name SET ( options )
10762 *
10763 * ALTER PUBLICATION name ADD pub_obj [, ...]
10764 *
10765 * ALTER PUBLICATION name DROP pub_obj [, ...]
10766 *
10767 * ALTER PUBLICATION name SET pub_obj [, ...]
10768 *
10769 * pub_obj is one of:
10770 *
10771 * TABLE table_name [, ...]
10772 * TABLES IN SCHEMA schema_name [, ...]
10773 *
10774 *****************************************************************************/
10775
10776 AlterPublicationStmt:
10777 ALTER PUBLICATION name SET definition
10778 {
10779 AlterPublicationStmt *n = makeNode(AlterPublicationStmt);
10780
10781 n->pubname = $3;
10782 n->options = $5;
10783 $$ = (Node *) n;
10784 }
10785 | ALTER PUBLICATION name ADD_P pub_obj_list
10786 {
10787 AlterPublicationStmt *n = makeNode(AlterPublicationStmt);
10788
10789 n->pubname = $3;
10790 n->pubobjects = $5;
10791 preprocess_pubobj_list(n->pubobjects, yyscanner);
10792 n->action = AP_AddObjects;
10793 $$ = (Node *) n;
10794 }
10795 | ALTER PUBLICATION name SET pub_obj_list
10796 {
10797 AlterPublicationStmt *n = makeNode(AlterPublicationStmt);
10798
10799 n->pubname = $3;
10800 n->pubobjects = $5;
10801 preprocess_pubobj_list(n->pubobjects, yyscanner);
10802 n->action = AP_SetObjects;
10803 $$ = (Node *) n;
10804 }
10805 | ALTER PUBLICATION name DROP pub_obj_list
10806 {
10807 AlterPublicationStmt *n = makeNode(AlterPublicationStmt);
10808
10809 n->pubname = $3;
10810 n->pubobjects = $5;
10811 preprocess_pubobj_list(n->pubobjects, yyscanner);
10812 n->action = AP_DropObjects;
10813 $$ = (Node *) n;
10814 }
10815 ;
10816
10817 /*****************************************************************************
10818 *
10819 * CREATE SUBSCRIPTION name ...
10820 *
10821 *****************************************************************************/
10822
10823 CreateSubscriptionStmt:
10824 CREATE SUBSCRIPTION name CONNECTION Sconst PUBLICATION name_list opt_definition
10825 {
10826 CreateSubscriptionStmt *n =
10827 makeNode(CreateSubscriptionStmt);
10828 n->subname = $3;
10829 n->conninfo = $5;
10830 n->publication = $7;
10831 n->options = $8;
10832 $$ = (Node *) n;
10833 }
10834 ;
10835
10836 /*****************************************************************************
10837 *
10838 * ALTER SUBSCRIPTION name ...
10839 *
10840 *****************************************************************************/
10841
10842 AlterSubscriptionStmt:
10843 ALTER SUBSCRIPTION name SET definition
10844 {
10845 AlterSubscriptionStmt *n =
10846 makeNode(AlterSubscriptionStmt);
10847
10848 n->kind = ALTER_SUBSCRIPTION_OPTIONS;
10849 n->subname = $3;
10850 n->options = $5;
10851 $$ = (Node *) n;
10852 }
10853 | ALTER SUBSCRIPTION name CONNECTION Sconst
10854 {
10855 AlterSubscriptionStmt *n =
10856 makeNode(AlterSubscriptionStmt);
10857
10858 n->kind = ALTER_SUBSCRIPTION_CONNECTION;
10859 n->subname = $3;
10860 n->conninfo = $5;
10861 $$ = (Node *) n;
10862 }
10863 | ALTER SUBSCRIPTION name REFRESH PUBLICATION opt_definition
10864 {
10865 AlterSubscriptionStmt *n =
10866 makeNode(AlterSubscriptionStmt);
10867
10868 n->kind = ALTER_SUBSCRIPTION_REFRESH;
10869 n->subname = $3;
10870 n->options = $6;
10871 $$ = (Node *) n;
10872 }
10873 | ALTER SUBSCRIPTION name ADD_P PUBLICATION name_list opt_definition
10874 {
10875 AlterSubscriptionStmt *n =
10876 makeNode(AlterSubscriptionStmt);
10877
10878 n->kind = ALTER_SUBSCRIPTION_ADD_PUBLICATION;
10879 n->subname = $3;
10880 n->publication = $6;
10881 n->options = $7;
10882 $$ = (Node *) n;
10883 }
10884 | ALTER SUBSCRIPTION name DROP PUBLICATION name_list opt_definition
10885 {
10886 AlterSubscriptionStmt *n =
10887 makeNode(AlterSubscriptionStmt);
10888
10889 n->kind = ALTER_SUBSCRIPTION_DROP_PUBLICATION;
10890 n->subname = $3;
10891 n->publication = $6;
10892 n->options = $7;
10893 $$ = (Node *) n;
10894 }
10895 | ALTER SUBSCRIPTION name SET PUBLICATION name_list opt_definition
10896 {
10897 AlterSubscriptionStmt *n =
10898 makeNode(AlterSubscriptionStmt);
10899
10900 n->kind = ALTER_SUBSCRIPTION_SET_PUBLICATION;
10901 n->subname = $3;
10902 n->publication = $6;
10903 n->options = $7;
10904 $$ = (Node *) n;
10905 }
10906 | ALTER SUBSCRIPTION name ENABLE_P
10907 {
10908 AlterSubscriptionStmt *n =
10909 makeNode(AlterSubscriptionStmt);
10910
10911 n->kind = ALTER_SUBSCRIPTION_ENABLED;
10912 n->subname = $3;
10913 n->options = list_make1(makeDefElem("enabled",
10914 (Node *) makeBoolean(true), @1));
10915 $$ = (Node *) n;
10916 }
10917 | ALTER SUBSCRIPTION name DISABLE_P
10918 {
10919 AlterSubscriptionStmt *n =
10920 makeNode(AlterSubscriptionStmt);
10921
10922 n->kind = ALTER_SUBSCRIPTION_ENABLED;
10923 n->subname = $3;
10924 n->options = list_make1(makeDefElem("enabled",
10925 (Node *) makeBoolean(false), @1));
10926 $$ = (Node *) n;
10927 }
10928 | ALTER SUBSCRIPTION name SKIP definition
10929 {
10930 AlterSubscriptionStmt *n =
10931 makeNode(AlterSubscriptionStmt);
10932
10933 n->kind = ALTER_SUBSCRIPTION_SKIP;
10934 n->subname = $3;
10935 n->options = $5;
10936 $$ = (Node *) n;
10937 }
10938 ;
10939
10940 /*****************************************************************************
10941 *
10942 * DROP SUBSCRIPTION [ IF EXISTS ] name
10943 *
10944 *****************************************************************************/
10945
10946 DropSubscriptionStmt: DROP SUBSCRIPTION name opt_drop_behavior
10947 {
10948 DropSubscriptionStmt *n = makeNode(DropSubscriptionStmt);
10949
10950 n->subname = $3;
10951 n->missing_ok = false;
10952 n->behavior = $4;
10953 $$ = (Node *) n;
10954 }
10955 | DROP SUBSCRIPTION IF_P EXISTS name opt_drop_behavior
10956 {
10957 DropSubscriptionStmt *n = makeNode(DropSubscriptionStmt);
10958
10959 n->subname = $5;
10960 n->missing_ok = true;
10961 n->behavior = $6;
10962 $$ = (Node *) n;
10963 }
10964 ;
10965
10966 /*****************************************************************************
10967 *
10968 * QUERY: Define Rewrite Rule
10969 *
10970 *****************************************************************************/
10971
10972 RuleStmt: CREATE opt_or_replace RULE name AS
10973 ON event TO qualified_name where_clause
10974 DO opt_instead RuleActionList
10975 {
10976 RuleStmt *n = makeNode(RuleStmt);
10977
10978 n->replace = $2;
10979 n->relation = $9;
10980 n->rulename = $4;
10981 n->whereClause = $10;
10982 n->event = $7;
10983 n->instead = $12;
10984 n->actions = $13;
10985 $$ = (Node *) n;
10986 }
10987 ;
10988
10989 RuleActionList:
10990 NOTHING { $$ = NIL; }
10991 | RuleActionStmt { $$ = list_make1($1); }
10992 | '(' RuleActionMulti ')' { $$ = $2; }
10993 ;
10994
10995 /* the thrashing around here is to discard "empty" statements... */
10996 RuleActionMulti:
10997 RuleActionMulti ';' RuleActionStmtOrEmpty
10998 { if ($3 != NULL)
10999 $$ = lappend($1, $3);
11000 else
11001 $$ = $1;
11002 }
11003 | RuleActionStmtOrEmpty
11004 { if ($1 != NULL)
11005 $$ = list_make1($1);
11006 else
11007 $$ = NIL;
11008 }
11009 ;
11010
11011 RuleActionStmt:
11012 SelectStmt
11013 | InsertStmt
11014 | UpdateStmt
11015 | DeleteStmt
11016 | NotifyStmt
11017 ;
11018
11019 RuleActionStmtOrEmpty:
11020 RuleActionStmt { $$ = $1; }
11021 | /*EMPTY*/ { $$ = NULL; }
11022 ;
11023
11024 event: SELECT { $$ = CMD_SELECT; }
11025 | UPDATE { $$ = CMD_UPDATE; }
11026 | DELETE_P { $$ = CMD_DELETE; }
11027 | INSERT { $$ = CMD_INSERT; }
11028 ;
11029
11030 opt_instead:
11031 INSTEAD { $$ = true; }
11032 | ALSO { $$ = false; }
11033 | /*EMPTY*/ { $$ = false; }
11034 ;
11035
11036
11037 /*****************************************************************************
11038 *
11039 * QUERY:
11040 * NOTIFY <identifier> can appear both in rule bodies and
11041 * as a query-level command
11042 *
11043 *****************************************************************************/
11044
11045 NotifyStmt: NOTIFY ColId notify_payload
11046 {
11047 NotifyStmt *n = makeNode(NotifyStmt);
11048
11049 n->conditionname = $2;
11050 n->payload = $3;
11051 $$ = (Node *) n;
11052 }
11053 ;
11054
11055 notify_payload:
11056 ',' Sconst { $$ = $2; }
11057 | /*EMPTY*/ { $$ = NULL; }
11058 ;
11059
11060 ListenStmt: LISTEN ColId
11061 {
11062 ListenStmt *n = makeNode(ListenStmt);
11063
11064 n->conditionname = $2;
11065 $$ = (Node *) n;
11066 }
11067 ;
11068
11069 UnlistenStmt:
11070 UNLISTEN ColId
11071 {
11072 UnlistenStmt *n = makeNode(UnlistenStmt);
11073
11074 n->conditionname = $2;
11075 $$ = (Node *) n;
11076 }
11077 | UNLISTEN '*'
11078 {
11079 UnlistenStmt *n = makeNode(UnlistenStmt);
11080
11081 n->conditionname = NULL;
11082 $$ = (Node *) n;
11083 }
11084 ;
11085
11086
11087 /*****************************************************************************
11088 *
11089 * Transactions:
11090 *
11091 * BEGIN / COMMIT / ROLLBACK
11092 * (also older versions END / ABORT)
11093 *
11094 *****************************************************************************/
11095
11096 TransactionStmt:
11097 ABORT_P opt_transaction opt_transaction_chain
11098 {
11099 TransactionStmt *n = makeNode(TransactionStmt);
11100
11101 n->kind = TRANS_STMT_ROLLBACK;
11102 n->options = NIL;
11103 n->chain = $3;
11104 n->location = -1;
11105 $$ = (Node *) n;
11106 }
11107 | START TRANSACTION transaction_mode_list_or_empty
11108 {
11109 TransactionStmt *n = makeNode(TransactionStmt);
11110
11111 n->kind = TRANS_STMT_START;
11112 n->options = $3;
11113 n->location = -1;
11114 $$ = (Node *) n;
11115 }
11116 | COMMIT opt_transaction opt_transaction_chain
11117 {
11118 TransactionStmt *n = makeNode(TransactionStmt);
11119
11120 n->kind = TRANS_STMT_COMMIT;
11121 n->options = NIL;
11122 n->chain = $3;
11123 n->location = -1;
11124 $$ = (Node *) n;
11125 }
11126 | ROLLBACK opt_transaction opt_transaction_chain
11127 {
11128 TransactionStmt *n = makeNode(TransactionStmt);
11129
11130 n->kind = TRANS_STMT_ROLLBACK;
11131 n->options = NIL;
11132 n->chain = $3;
11133 n->location = -1;
11134 $$ = (Node *) n;
11135 }
11136 | SAVEPOINT ColId
11137 {
11138 TransactionStmt *n = makeNode(TransactionStmt);
11139
11140 n->kind = TRANS_STMT_SAVEPOINT;
11141 n->savepoint_name = $2;
11142 n->location = @2;
11143 $$ = (Node *) n;
11144 }
11145 | RELEASE SAVEPOINT ColId
11146 {
11147 TransactionStmt *n = makeNode(TransactionStmt);
11148
11149 n->kind = TRANS_STMT_RELEASE;
11150 n->savepoint_name = $3;
11151 n->location = @3;
11152 $$ = (Node *) n;
11153 }
11154 | RELEASE ColId
11155 {
11156 TransactionStmt *n = makeNode(TransactionStmt);
11157
11158 n->kind = TRANS_STMT_RELEASE;
11159 n->savepoint_name = $2;
11160 n->location = @2;
11161 $$ = (Node *) n;
11162 }
11163 | ROLLBACK opt_transaction TO SAVEPOINT ColId
11164 {
11165 TransactionStmt *n = makeNode(TransactionStmt);
11166
11167 n->kind = TRANS_STMT_ROLLBACK_TO;
11168 n->savepoint_name = $5;
11169 n->location = @5;
11170 $$ = (Node *) n;
11171 }
11172 | ROLLBACK opt_transaction TO ColId
11173 {
11174 TransactionStmt *n = makeNode(TransactionStmt);
11175
11176 n->kind = TRANS_STMT_ROLLBACK_TO;
11177 n->savepoint_name = $4;
11178 n->location = @4;
11179 $$ = (Node *) n;
11180 }
11181 | PREPARE TRANSACTION Sconst
11182 {
11183 TransactionStmt *n = makeNode(TransactionStmt);
11184
11185 n->kind = TRANS_STMT_PREPARE;
11186 n->gid = $3;
11187 n->location = @3;
11188 $$ = (Node *) n;
11189 }
11190 | COMMIT PREPARED Sconst
11191 {
11192 TransactionStmt *n = makeNode(TransactionStmt);
11193
11194 n->kind = TRANS_STMT_COMMIT_PREPARED;
11195 n->gid = $3;
11196 n->location = @3;
11197 $$ = (Node *) n;
11198 }
11199 | ROLLBACK PREPARED Sconst
11200 {
11201 TransactionStmt *n = makeNode(TransactionStmt);
11202
11203 n->kind = TRANS_STMT_ROLLBACK_PREPARED;
11204 n->gid = $3;
11205 n->location = @3;
11206 $$ = (Node *) n;
11207 }
11208 ;
11209
11210 TransactionStmtLegacy:
11211 BEGIN_P opt_transaction transaction_mode_list_or_empty
11212 {
11213 TransactionStmt *n = makeNode(TransactionStmt);
11214
11215 n->kind = TRANS_STMT_BEGIN;
11216 n->options = $3;
11217 n->location = -1;
11218 $$ = (Node *) n;
11219 }
11220 | END_P opt_transaction opt_transaction_chain
11221 {
11222 TransactionStmt *n = makeNode(TransactionStmt);
11223
11224 n->kind = TRANS_STMT_COMMIT;
11225 n->options = NIL;
11226 n->chain = $3;
11227 n->location = -1;
11228 $$ = (Node *) n;
11229 }
11230 ;
11231
11232 opt_transaction: WORK
11233 | TRANSACTION
11234 | /*EMPTY*/
11235 ;
11236
11237 transaction_mode_item:
11238 ISOLATION LEVEL iso_level
11239 { $$ = makeDefElem("transaction_isolation",
11240 makeStringConst($3, @3), @1); }
11241 | READ ONLY
11242 { $$ = makeDefElem("transaction_read_only",
11243 makeIntConst(true, @1), @1); }
11244 | READ WRITE
11245 { $$ = makeDefElem("transaction_read_only",
11246 makeIntConst(false, @1), @1); }
11247 | DEFERRABLE
11248 { $$ = makeDefElem("transaction_deferrable",
11249 makeIntConst(true, @1), @1); }
11250 | NOT DEFERRABLE
11251 { $$ = makeDefElem("transaction_deferrable",
11252 makeIntConst(false, @1), @1); }
11253 ;
11254
11255 /* Syntax with commas is SQL-spec, without commas is Postgres historical */
11256 transaction_mode_list:
11257 transaction_mode_item
11258 { $$ = list_make1($1); }
11259 | transaction_mode_list ',' transaction_mode_item
11260 { $$ = lappend($1, $3); }
11261 | transaction_mode_list transaction_mode_item
11262 { $$ = lappend($1, $2); }
11263 ;
11264
11265 transaction_mode_list_or_empty:
11266 transaction_mode_list
11267 | /* EMPTY */
11268 { $$ = NIL; }
11269 ;
11270
11271 opt_transaction_chain:
11272 AND CHAIN { $$ = true; }
11273 | AND NO CHAIN { $$ = false; }
11274 | /* EMPTY */ { $$ = false; }
11275 ;
11276
11277
11278 /*****************************************************************************
11279 *
11280 * QUERY:
11281 * CREATE [ OR REPLACE ] [ TEMP ] VIEW <viewname> '('target-list ')'
11282 * AS <query> [ WITH [ CASCADED | LOCAL ] CHECK OPTION ]
11283 *
11284 *****************************************************************************/
11285
11286 ViewStmt: CREATE OptTemp VIEW qualified_name opt_column_list opt_reloptions
11287 AS SelectStmt opt_check_option
11288 {
11289 ViewStmt *n = makeNode(ViewStmt);
11290
11291 n->view = $4;
11292 n->view->relpersistence = $2;
11293 n->aliases = $5;
11294 n->query = $8;
11295 n->replace = false;
11296 n->options = $6;
11297 n->withCheckOption = $9;
11298 $$ = (Node *) n;
11299 }
11300 | CREATE OR REPLACE OptTemp VIEW qualified_name opt_column_list opt_reloptions
11301 AS SelectStmt opt_check_option
11302 {
11303 ViewStmt *n = makeNode(ViewStmt);
11304
11305 n->view = $6;
11306 n->view->relpersistence = $4;
11307 n->aliases = $7;
11308 n->query = $10;
11309 n->replace = true;
11310 n->options = $8;
11311 n->withCheckOption = $11;
11312 $$ = (Node *) n;
11313 }
11314 | CREATE OptTemp RECURSIVE VIEW qualified_name '(' columnList ')' opt_reloptions
11315 AS SelectStmt opt_check_option
11316 {
11317 ViewStmt *n = makeNode(ViewStmt);
11318
11319 n->view = $5;
11320 n->view->relpersistence = $2;
11321 n->aliases = $7;
11322 n->query = makeRecursiveViewSelect(n->view->relname, n->aliases, $11);
11323 n->replace = false;
11324 n->options = $9;
11325 n->withCheckOption = $12;
11326 if (n->withCheckOption != NO_CHECK_OPTION)
11327 ereport(ERROR,
11328 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
11329 errmsg("WITH CHECK OPTION not supported on recursive views"),
11330 parser_errposition(@12)));
11331 $$ = (Node *) n;
11332 }
11333 | CREATE OR REPLACE OptTemp RECURSIVE VIEW qualified_name '(' columnList ')' opt_reloptions
11334 AS SelectStmt opt_check_option
11335 {
11336 ViewStmt *n = makeNode(ViewStmt);
11337
11338 n->view = $7;
11339 n->view->relpersistence = $4;
11340 n->aliases = $9;
11341 n->query = makeRecursiveViewSelect(n->view->relname, n->aliases, $13);
11342 n->replace = true;
11343 n->options = $11;
11344 n->withCheckOption = $14;
11345 if (n->withCheckOption != NO_CHECK_OPTION)
11346 ereport(ERROR,
11347 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
11348 errmsg("WITH CHECK OPTION not supported on recursive views"),
11349 parser_errposition(@14)));
11350 $$ = (Node *) n;
11351 }
11352 ;
11353
11354 opt_check_option:
11355 WITH CHECK OPTION { $$ = CASCADED_CHECK_OPTION; }
11356 | WITH CASCADED CHECK OPTION { $$ = CASCADED_CHECK_OPTION; }
11357 | WITH LOCAL CHECK OPTION { $$ = LOCAL_CHECK_OPTION; }
11358 | /* EMPTY */ { $$ = NO_CHECK_OPTION; }
11359 ;
11360
11361 /*****************************************************************************
11362 *
11363 * QUERY:
11364 * LOAD "filename"
11365 *
11366 *****************************************************************************/
11367
11368 LoadStmt: LOAD file_name
11369 {
11370 LoadStmt *n = makeNode(LoadStmt);
11371
11372 n->filename = $2;
11373 $$ = (Node *) n;
11374 }
11375 ;
11376
11377
11378 /*****************************************************************************
11379 *
11380 * CREATE DATABASE
11381 *
11382 *****************************************************************************/
11383
11384 CreatedbStmt:
11385 CREATE DATABASE name opt_with createdb_opt_list
11386 {
11387 CreatedbStmt *n = makeNode(CreatedbStmt);
11388
11389 n->dbname = $3;
11390 n->options = $5;
11391 $$ = (Node *) n;
11392 }
11393 ;
11394
11395 createdb_opt_list:
11396 createdb_opt_items { $$ = $1; }
11397 | /* EMPTY */ { $$ = NIL; }
11398 ;
11399
11400 createdb_opt_items:
11401 createdb_opt_item { $$ = list_make1($1); }
11402 | createdb_opt_items createdb_opt_item { $$ = lappend($1, $2); }
11403 ;
11404
11405 createdb_opt_item:
11406 createdb_opt_name opt_equal NumericOnly
11407 {
11408 $$ = makeDefElem($1, $3, @1);
11409 }
11410 | createdb_opt_name opt_equal opt_boolean_or_string
11411 {
11412 $$ = makeDefElem($1, (Node *) makeString($3), @1);
11413 }
11414 | createdb_opt_name opt_equal DEFAULT
11415 {
11416 $$ = makeDefElem($1, NULL, @1);
11417 }
11418 ;
11419
11420 /*
11421 * Ideally we'd use ColId here, but that causes shift/reduce conflicts against
11422 * the ALTER DATABASE SET/RESET syntaxes. Instead call out specific keywords
11423 * we need, and allow IDENT so that database option names don't have to be
11424 * parser keywords unless they are already keywords for other reasons.
11425 *
11426 * XXX this coding technique is fragile since if someone makes a formerly
11427 * non-keyword option name into a keyword and forgets to add it here, the
11428 * option will silently break. Best defense is to provide a regression test
11429 * exercising every such option, at least at the syntax level.
11430 */
11431 createdb_opt_name:
11432 IDENT { $$ = $1; }
11433 | CONNECTION LIMIT { $$ = pstrdup("connection_limit"); }
11434 | ENCODING { $$ = pstrdup($1); }
11435 | LOCATION { $$ = pstrdup($1); }
11436 | OWNER { $$ = pstrdup($1); }
11437 | TABLESPACE { $$ = pstrdup($1); }
11438 | TEMPLATE { $$ = pstrdup($1); }
11439 ;
11440
11441 /*
11442 * Though the equals sign doesn't match other WITH options, pg_dump uses
11443 * equals for backward compatibility, and it doesn't seem worth removing it.
11444 */
11445 opt_equal: '='
11446 | /*EMPTY*/
11447 ;
11448
11449
11450 /*****************************************************************************
11451 *
11452 * ALTER DATABASE
11453 *
11454 *****************************************************************************/
11455
11456 AlterDatabaseStmt:
11457 ALTER DATABASE name WITH createdb_opt_list
11458 {
11459 AlterDatabaseStmt *n = makeNode(AlterDatabaseStmt);
11460
11461 n->dbname = $3;
11462 n->options = $5;
11463 $$ = (Node *) n;
11464 }
11465 | ALTER DATABASE name createdb_opt_list
11466 {
11467 AlterDatabaseStmt *n = makeNode(AlterDatabaseStmt);
11468
11469 n->dbname = $3;
11470 n->options = $4;
11471 $$ = (Node *) n;
11472 }
11473 | ALTER DATABASE name SET TABLESPACE name
11474 {
11475 AlterDatabaseStmt *n = makeNode(AlterDatabaseStmt);
11476
11477 n->dbname = $3;
11478 n->options = list_make1(makeDefElem("tablespace",
11479 (Node *) makeString($6), @6));
11480 $$ = (Node *) n;
11481 }
11482 | ALTER DATABASE name REFRESH COLLATION VERSION_P
11483 {
11484 AlterDatabaseRefreshCollStmt *n = makeNode(AlterDatabaseRefreshCollStmt);
11485
11486 n->dbname = $3;
11487 $$ = (Node *) n;
11488 }
11489 ;
11490
11491 AlterDatabaseSetStmt:
11492 ALTER DATABASE name SetResetClause
11493 {
11494 AlterDatabaseSetStmt *n = makeNode(AlterDatabaseSetStmt);
11495
11496 n->dbname = $3;
11497 n->setstmt = $4;
11498 $$ = (Node *) n;
11499 }
11500 ;
11501
11502
11503 /*****************************************************************************
11504 *
11505 * DROP DATABASE [ IF EXISTS ] dbname [ [ WITH ] ( options ) ]
11506 *
11507 * This is implicitly CASCADE, no need for drop behavior
11508 *****************************************************************************/
11509
11510 DropdbStmt: DROP DATABASE name
11511 {
11512 DropdbStmt *n = makeNode(DropdbStmt);
11513
11514 n->dbname = $3;
11515 n->missing_ok = false;
11516 n->options = NULL;
11517 $$ = (Node *) n;
11518 }
11519 | DROP DATABASE IF_P EXISTS name
11520 {
11521 DropdbStmt *n = makeNode(DropdbStmt);
11522
11523 n->dbname = $5;
11524 n->missing_ok = true;
11525 n->options = NULL;
11526 $$ = (Node *) n;
11527 }
11528 | DROP DATABASE name opt_with '(' drop_option_list ')'
11529 {
11530 DropdbStmt *n = makeNode(DropdbStmt);
11531
11532 n->dbname = $3;
11533 n->missing_ok = false;
11534 n->options = $6;
11535 $$ = (Node *) n;
11536 }
11537 | DROP DATABASE IF_P EXISTS name opt_with '(' drop_option_list ')'
11538 {
11539 DropdbStmt *n = makeNode(DropdbStmt);
11540
11541 n->dbname = $5;
11542 n->missing_ok = true;
11543 n->options = $8;
11544 $$ = (Node *) n;
11545 }
11546 ;
11547
11548 drop_option_list:
11549 drop_option
11550 {
11551 $$ = list_make1((Node *) $1);
11552 }
11553 | drop_option_list ',' drop_option
11554 {
11555 $$ = lappend($1, (Node *) $3);
11556 }
11557 ;
11558
11559 /*
11560 * Currently only the FORCE option is supported, but the syntax is designed
11561 * to be extensible so that we can add more options in the future if required.
11562 */
11563 drop_option:
11564 FORCE
11565 {
11566 $$ = makeDefElem("force", NULL, @1);
11567 }
11568 ;
11569
11570 /*****************************************************************************
11571 *
11572 * ALTER COLLATION
11573 *
11574 *****************************************************************************/
11575
11576 AlterCollationStmt: ALTER COLLATION any_name REFRESH VERSION_P
11577 {
11578 AlterCollationStmt *n = makeNode(AlterCollationStmt);
11579
11580 n->collname = $3;
11581 $$ = (Node *) n;
11582 }
11583 ;
11584
11585
11586 /*****************************************************************************
11587 *
11588 * ALTER SYSTEM
11589 *
11590 * This is used to change configuration parameters persistently.
11591 *****************************************************************************/
11592
11593 AlterSystemStmt:
11594 ALTER SYSTEM_P SET generic_set
11595 {
11596 AlterSystemStmt *n = makeNode(AlterSystemStmt);
11597
11598 n->setstmt = $4;
11599 $$ = (Node *) n;
11600 }
11601 | ALTER SYSTEM_P RESET generic_reset
11602 {
11603 AlterSystemStmt *n = makeNode(AlterSystemStmt);
11604
11605 n->setstmt = $4;
11606 $$ = (Node *) n;
11607 }
11608 ;
11609
11610
11611 /*****************************************************************************
11612 *
11613 * Manipulate a domain
11614 *
11615 *****************************************************************************/
11616
11617 CreateDomainStmt:
11618 CREATE DOMAIN_P any_name opt_as Typename ColQualList
11619 {
11620 CreateDomainStmt *n = makeNode(CreateDomainStmt);
11621
11622 n->domainname = $3;
11623 n->typeName = $5;
11624 SplitColQualList($6, &n->constraints, &n->collClause,
11625 yyscanner);
11626 $$ = (Node *) n;
11627 }
11628 ;
11629
11630 AlterDomainStmt:
11631 /* ALTER DOMAIN <domain> {SET DEFAULT <expr>|DROP DEFAULT} */
11632 ALTER DOMAIN_P any_name alter_column_default
11633 {
11634 AlterDomainStmt *n = makeNode(AlterDomainStmt);
11635
11636 n->subtype = 'T';
11637 n->typeName = $3;
11638 n->def = $4;
11639 $$ = (Node *) n;
11640 }
11641 /* ALTER DOMAIN <domain> DROP NOT NULL */
11642 | ALTER DOMAIN_P any_name DROP NOT NULL_P
11643 {
11644 AlterDomainStmt *n = makeNode(AlterDomainStmt);
11645
11646 n->subtype = 'N';
11647 n->typeName = $3;
11648 $$ = (Node *) n;
11649 }
11650 /* ALTER DOMAIN <domain> SET NOT NULL */
11651 | ALTER DOMAIN_P any_name SET NOT NULL_P
11652 {
11653 AlterDomainStmt *n = makeNode(AlterDomainStmt);
11654
11655 n->subtype = 'O';
11656 n->typeName = $3;
11657 $$ = (Node *) n;
11658 }
11659 /* ALTER DOMAIN <domain> ADD CONSTRAINT ... */
11660 | ALTER DOMAIN_P any_name ADD_P DomainConstraint
11661 {
11662 AlterDomainStmt *n = makeNode(AlterDomainStmt);
11663
11664 n->subtype = 'C';
11665 n->typeName = $3;
11666 n->def = $5;
11667 $$ = (Node *) n;
11668 }
11669 /* ALTER DOMAIN <domain> DROP CONSTRAINT <name> [RESTRICT|CASCADE] */
11670 | ALTER DOMAIN_P any_name DROP CONSTRAINT name opt_drop_behavior
11671 {
11672 AlterDomainStmt *n = makeNode(AlterDomainStmt);
11673
11674 n->subtype = 'X';
11675 n->typeName = $3;
11676 n->name = $6;
11677 n->behavior = $7;
11678 n->missing_ok = false;
11679 $$ = (Node *) n;
11680 }
11681 /* ALTER DOMAIN <domain> DROP CONSTRAINT IF EXISTS <name> [RESTRICT|CASCADE] */
11682 | ALTER DOMAIN_P any_name DROP CONSTRAINT IF_P EXISTS name opt_drop_behavior
11683 {
11684 AlterDomainStmt *n = makeNode(AlterDomainStmt);
11685
11686 n->subtype = 'X';
11687 n->typeName = $3;
11688 n->name = $8;
11689 n->behavior = $9;
11690 n->missing_ok = true;
11691 $$ = (Node *) n;
11692 }
11693 /* ALTER DOMAIN <domain> VALIDATE CONSTRAINT <name> */
11694 | ALTER DOMAIN_P any_name VALIDATE CONSTRAINT name
11695 {
11696 AlterDomainStmt *n = makeNode(AlterDomainStmt);
11697
11698 n->subtype = 'V';
11699 n->typeName = $3;
11700 n->name = $6;
11701 $$ = (Node *) n;
11702 }
11703 ;
11704
11705 opt_as: AS
11706 | /* EMPTY */
11707 ;
11708
11709
11710 /*****************************************************************************
11711 *
11712 * Manipulate a text search dictionary or configuration
11713 *
11714 *****************************************************************************/
11715
11716 AlterTSDictionaryStmt:
11717 ALTER TEXT_P SEARCH DICTIONARY any_name definition
11718 {
11719 AlterTSDictionaryStmt *n = makeNode(AlterTSDictionaryStmt);
11720
11721 n->dictname = $5;
11722 n->options = $6;
11723 $$ = (Node *) n;
11724 }
11725 ;
11726
11727 AlterTSConfigurationStmt:
11728 ALTER TEXT_P SEARCH CONFIGURATION any_name ADD_P MAPPING FOR name_list any_with any_name_list
11729 {
11730 AlterTSConfigurationStmt *n = makeNode(AlterTSConfigurationStmt);
11731
11732 n->kind = ALTER_TSCONFIG_ADD_MAPPING;
11733 n->cfgname = $5;
11734 n->tokentype = $9;
11735 n->dicts = $11;
11736 n->override = false;
11737 n->replace = false;
11738 $$ = (Node *) n;
11739 }
11740 | ALTER TEXT_P SEARCH CONFIGURATION any_name ALTER MAPPING FOR name_list any_with any_name_list
11741 {
11742 AlterTSConfigurationStmt *n = makeNode(AlterTSConfigurationStmt);
11743
11744 n->kind = ALTER_TSCONFIG_ALTER_MAPPING_FOR_TOKEN;
11745 n->cfgname = $5;
11746 n->tokentype = $9;
11747 n->dicts = $11;
11748 n->override = true;
11749 n->replace = false;
11750 $$ = (Node *) n;
11751 }
11752 | ALTER TEXT_P SEARCH CONFIGURATION any_name ALTER MAPPING REPLACE any_name any_with any_name
11753 {
11754 AlterTSConfigurationStmt *n = makeNode(AlterTSConfigurationStmt);
11755
11756 n->kind = ALTER_TSCONFIG_REPLACE_DICT;
11757 n->cfgname = $5;
11758 n->tokentype = NIL;
11759 n->dicts = list_make2($9,$11);
11760 n->override = false;
11761 n->replace = true;
11762 $$ = (Node *) n;
11763 }
11764 | ALTER TEXT_P SEARCH CONFIGURATION any_name ALTER MAPPING FOR name_list REPLACE any_name any_with any_name
11765 {
11766 AlterTSConfigurationStmt *n = makeNode(AlterTSConfigurationStmt);
11767
11768 n->kind = ALTER_TSCONFIG_REPLACE_DICT_FOR_TOKEN;
11769 n->cfgname = $5;
11770 n->tokentype = $9;
11771 n->dicts = list_make2($11,$13);
11772 n->override = false;
11773 n->replace = true;
11774 $$ = (Node *) n;
11775 }
11776 | ALTER TEXT_P SEARCH CONFIGURATION any_name DROP MAPPING FOR name_list
11777 {
11778 AlterTSConfigurationStmt *n = makeNode(AlterTSConfigurationStmt);
11779
11780 n->kind = ALTER_TSCONFIG_DROP_MAPPING;
11781 n->cfgname = $5;
11782 n->tokentype = $9;
11783 n->missing_ok = false;
11784 $$ = (Node *) n;
11785 }
11786 | ALTER TEXT_P SEARCH CONFIGURATION any_name DROP MAPPING IF_P EXISTS FOR name_list
11787 {
11788 AlterTSConfigurationStmt *n = makeNode(AlterTSConfigurationStmt);
11789
11790 n->kind = ALTER_TSCONFIG_DROP_MAPPING;
11791 n->cfgname = $5;
11792 n->tokentype = $11;
11793 n->missing_ok = true;
11794 $$ = (Node *) n;
11795 }
11796 ;
11797
11798 /* Use this if TIME or ORDINALITY after WITH should be taken as an identifier */
11799 any_with: WITH
11800 | WITH_LA
11801 ;
11802
11803
11804 /*****************************************************************************
11805 *
11806 * Manipulate a conversion
11807 *
11808 * CREATE [DEFAULT] CONVERSION <conversion_name>
11809 * FOR <encoding_name> TO <encoding_name> FROM <func_name>
11810 *
11811 *****************************************************************************/
11812
11813 CreateConversionStmt:
11814 CREATE opt_default CONVERSION_P any_name FOR Sconst
11815 TO Sconst FROM any_name
11816 {
11817 CreateConversionStmt *n = makeNode(CreateConversionStmt);
11818
11819 n->conversion_name = $4;
11820 n->for_encoding_name = $6;
11821 n->to_encoding_name = $8;
11822 n->func_name = $10;
11823 n->def = $2;
11824 $$ = (Node *) n;
11825 }
11826 ;
11827
11828 /*****************************************************************************
11829 *
11830 * QUERY:
11831 * CLUSTER (options) [ <qualified_name> [ USING <index_name> ] ]
11832 * CLUSTER [VERBOSE] [ <qualified_name> [ USING <index_name> ] ]
11833 * CLUSTER [VERBOSE] <index_name> ON <qualified_name> (for pre-8.3)
11834 *
11835 *****************************************************************************/
11836
11837 ClusterStmt:
11838 CLUSTER '(' utility_option_list ')' qualified_name cluster_index_specification
11839 {
11840 ClusterStmt *n = makeNode(ClusterStmt);
11841
11842 n->relation = $5;
11843 n->indexname = $6;
11844 n->params = $3;
11845 $$ = (Node *) n;
11846 }
11847 | CLUSTER '(' utility_option_list ')'
11848 {
11849 ClusterStmt *n = makeNode(ClusterStmt);
11850
11851 n->relation = NULL;
11852 n->indexname = NULL;
11853 n->params = $3;
11854 $$ = (Node *) n;
11855 }
11856 /* unparenthesized VERBOSE kept for pre-14 compatibility */
11857 | CLUSTER opt_verbose qualified_name cluster_index_specification
11858 {
11859 ClusterStmt *n = makeNode(ClusterStmt);
11860
11861 n->relation = $3;
11862 n->indexname = $4;
11863 n->params = NIL;
11864 if ($2)
11865 n->params = lappend(n->params, makeDefElem("verbose", NULL, @2));
11866 $$ = (Node *) n;
11867 }
11868 /* unparenthesized VERBOSE kept for pre-17 compatibility */
11869 | CLUSTER opt_verbose
11870 {
11871 ClusterStmt *n = makeNode(ClusterStmt);
11872
11873 n->relation = NULL;
11874 n->indexname = NULL;
11875 n->params = NIL;
11876 if ($2)
11877 n->params = lappend(n->params, makeDefElem("verbose", NULL, @2));
11878 $$ = (Node *) n;
11879 }
11880 /* kept for pre-8.3 compatibility */
11881 | CLUSTER opt_verbose name ON qualified_name
11882 {
11883 ClusterStmt *n = makeNode(ClusterStmt);
11884
11885 n->relation = $5;
11886 n->indexname = $3;
11887 n->params = NIL;
11888 if ($2)
11889 n->params = lappend(n->params, makeDefElem("verbose", NULL, @2));
11890 $$ = (Node *) n;
11891 }
11892 ;
11893
11894 cluster_index_specification:
11895 USING name { $$ = $2; }
11896 | /*EMPTY*/ { $$ = NULL; }
11897 ;
11898
11899
11900 /*****************************************************************************
11901 *
11902 * QUERY:
11903 * VACUUM
11904 * ANALYZE
11905 *
11906 *****************************************************************************/
11907
11908 VacuumStmt: VACUUM opt_full opt_freeze opt_verbose opt_analyze opt_vacuum_relation_list
11909 {
11910 VacuumStmt *n = makeNode(VacuumStmt);
11911
11912 n->options = NIL;
11913 if ($2)
11914 n->options = lappend(n->options,
11915 makeDefElem("full", NULL, @2));
11916 if ($3)
11917 n->options = lappend(n->options,
11918 makeDefElem("freeze", NULL, @3));
11919 if ($4)
11920 n->options = lappend(n->options,
11921 makeDefElem("verbose", NULL, @4));
11922 if ($5)
11923 n->options = lappend(n->options,
11924 makeDefElem("analyze", NULL, @5));
11925 n->rels = $6;
11926 n->is_vacuumcmd = true;
11927 $$ = (Node *) n;
11928 }
11929 | VACUUM '(' utility_option_list ')' opt_vacuum_relation_list
11930 {
11931 VacuumStmt *n = makeNode(VacuumStmt);
11932
11933 n->options = $3;
11934 n->rels = $5;
11935 n->is_vacuumcmd = true;
11936 $$ = (Node *) n;
11937 }
11938 ;
11939
11940 AnalyzeStmt: analyze_keyword opt_verbose opt_vacuum_relation_list
11941 {
11942 VacuumStmt *n = makeNode(VacuumStmt);
11943
11944 n->options = NIL;
11945 if ($2)
11946 n->options = lappend(n->options,
11947 makeDefElem("verbose", NULL, @2));
11948 n->rels = $3;
11949 n->is_vacuumcmd = false;
11950 $$ = (Node *) n;
11951 }
11952 | analyze_keyword '(' utility_option_list ')' opt_vacuum_relation_list
11953 {
11954 VacuumStmt *n = makeNode(VacuumStmt);
11955
11956 n->options = $3;
11957 n->rels = $5;
11958 n->is_vacuumcmd = false;
11959 $$ = (Node *) n;
11960 }
11961 ;
11962
11963 utility_option_list:
11964 utility_option_elem
11965 {
11966 $$ = list_make1($1);
11967 }
11968 | utility_option_list ',' utility_option_elem
11969 {
11970 $$ = lappend($1, $3);
11971 }
11972 ;
11973
11974 analyze_keyword:
11975 ANALYZE
11976 | ANALYSE /* British */
11977 ;
11978
11979 utility_option_elem:
11980 utility_option_name utility_option_arg
11981 {
11982 $$ = makeDefElem($1, $2, @1);
11983 }
11984 ;
11985
11986 utility_option_name:
11987 NonReservedWord { $$ = $1; }
11988 | analyze_keyword { $$ = "analyze"; }
11989 | FORMAT_LA { $$ = "format"; }
11990 ;
11991
11992 utility_option_arg:
11993 opt_boolean_or_string { $$ = (Node *) makeString($1); }
11994 | NumericOnly { $$ = (Node *) $1; }
11995 | /* EMPTY */ { $$ = NULL; }
11996 ;
11997
11998 opt_analyze:
11999 analyze_keyword { $$ = true; }
12000 | /*EMPTY*/ { $$ = false; }
12001 ;
12002
12003 opt_verbose:
12004 VERBOSE { $$ = true; }
12005 | /*EMPTY*/ { $$ = false; }
12006 ;
12007
12008 opt_full: FULL { $$ = true; }
12009 | /*EMPTY*/ { $$ = false; }
12010 ;
12011
12012 opt_freeze: FREEZE { $$ = true; }
12013 | /*EMPTY*/ { $$ = false; }
12014 ;
12015
12016 opt_name_list:
12017 '(' name_list ')' { $$ = $2; }
12018 | /*EMPTY*/ { $$ = NIL; }
12019 ;
12020
12021 vacuum_relation:
12022 relation_expr opt_name_list
12023 {
12024 $$ = (Node *) makeVacuumRelation($1, InvalidOid, $2);
12025 }
12026 ;
12027
12028 vacuum_relation_list:
12029 vacuum_relation
12030 { $$ = list_make1($1); }
12031 | vacuum_relation_list ',' vacuum_relation
12032 { $$ = lappend($1, $3); }
12033 ;
12034
12035 opt_vacuum_relation_list:
12036 vacuum_relation_list { $$ = $1; }
12037 | /*EMPTY*/ { $$ = NIL; }
12038 ;
12039
12040
12041 /*****************************************************************************
12042 *
12043 * QUERY:
12044 * EXPLAIN [ANALYZE] [VERBOSE] query
12045 * EXPLAIN ( options ) query
12046 *
12047 *****************************************************************************/
12048
12049 ExplainStmt:
12050 EXPLAIN ExplainableStmt
12051 {
12052 ExplainStmt *n = makeNode(ExplainStmt);
12053
12054 n->query = $2;
12055 n->options = NIL;
12056 $$ = (Node *) n;
12057 }
12058 | EXPLAIN analyze_keyword opt_verbose ExplainableStmt
12059 {
12060 ExplainStmt *n = makeNode(ExplainStmt);
12061
12062 n->query = $4;
12063 n->options = list_make1(makeDefElem("analyze", NULL, @2));
12064 if ($3)
12065 n->options = lappend(n->options,
12066 makeDefElem("verbose", NULL, @3));
12067 $$ = (Node *) n;
12068 }
12069 | EXPLAIN VERBOSE ExplainableStmt
12070 {
12071 ExplainStmt *n = makeNode(ExplainStmt);
12072
12073 n->query = $3;
12074 n->options = list_make1(makeDefElem("verbose", NULL, @2));
12075 $$ = (Node *) n;
12076 }
12077 | EXPLAIN '(' utility_option_list ')' ExplainableStmt
12078 {
12079 ExplainStmt *n = makeNode(ExplainStmt);
12080
12081 n->query = $5;
12082 n->options = $3;
12083 $$ = (Node *) n;
12084 }
12085 ;
12086
12087 ExplainableStmt:
12088 SelectStmt
12089 | InsertStmt
12090 | UpdateStmt
12091 | DeleteStmt
12092 | MergeStmt
12093 | DeclareCursorStmt
12094 | CreateAsStmt
12095 | CreateMatViewStmt
12096 | RefreshMatViewStmt
12097 | ExecuteStmt /* by default all are $$=$1 */
12098 ;
12099
12100 /*****************************************************************************
12101 *
12102 * QUERY:
12103 * PREPARE <plan_name> [(args, ...)] AS <query>
12104 *
12105 *****************************************************************************/
12106
12107 PrepareStmt: PREPARE name prep_type_clause AS PreparableStmt
12108 {
12109 PrepareStmt *n = makeNode(PrepareStmt);
12110
12111 n->name = $2;
12112 n->argtypes = $3;
12113 n->query = $5;
12114 $$ = (Node *) n;
12115 }
12116 ;
12117
12118 prep_type_clause: '(' type_list ')' { $$ = $2; }
12119 | /* EMPTY */ { $$ = NIL; }
12120 ;
12121
12122 PreparableStmt:
12123 SelectStmt
12124 | InsertStmt
12125 | UpdateStmt
12126 | DeleteStmt
12127 | MergeStmt /* by default all are $$=$1 */
12128 ;
12129
12130 /*****************************************************************************
12131 *
12132 * EXECUTE <plan_name> [(params, ...)]
12133 * CREATE TABLE <name> AS EXECUTE <plan_name> [(params, ...)]
12134 *
12135 *****************************************************************************/
12136
12137 ExecuteStmt: EXECUTE name execute_param_clause
12138 {
12139 ExecuteStmt *n = makeNode(ExecuteStmt);
12140
12141 n->name = $2;
12142 n->params = $3;
12143 $$ = (Node *) n;
12144 }
12145 | CREATE OptTemp TABLE create_as_target AS
12146 EXECUTE name execute_param_clause opt_with_data
12147 {
12148 CreateTableAsStmt *ctas = makeNode(CreateTableAsStmt);
12149 ExecuteStmt *n = makeNode(ExecuteStmt);
12150
12151 n->name = $7;
12152 n->params = $8;
12153 ctas->query = (Node *) n;
12154 ctas->into = $4;
12155 ctas->objtype = OBJECT_TABLE;
12156 ctas->is_select_into = false;
12157 ctas->if_not_exists = false;
12158 /* cram additional flags into the IntoClause */
12159 $4->rel->relpersistence = $2;
12160 $4->skipData = !($9);
12161 $$ = (Node *) ctas;
12162 }
12163 | CREATE OptTemp TABLE IF_P NOT EXISTS create_as_target AS
12164 EXECUTE name execute_param_clause opt_with_data
12165 {
12166 CreateTableAsStmt *ctas = makeNode(CreateTableAsStmt);
12167 ExecuteStmt *n = makeNode(ExecuteStmt);
12168
12169 n->name = $10;
12170 n->params = $11;
12171 ctas->query = (Node *) n;
12172 ctas->into = $7;
12173 ctas->objtype = OBJECT_TABLE;
12174 ctas->is_select_into = false;
12175 ctas->if_not_exists = true;
12176 /* cram additional flags into the IntoClause */
12177 $7->rel->relpersistence = $2;
12178 $7->skipData = !($12);
12179 $$ = (Node *) ctas;
12180 }
12181 ;
12182
12183 execute_param_clause: '(' expr_list ')' { $$ = $2; }
12184 | /* EMPTY */ { $$ = NIL; }
12185 ;
12186
12187 /*****************************************************************************
12188 *
12189 * QUERY:
12190 * DEALLOCATE [PREPARE] <plan_name>
12191 *
12192 *****************************************************************************/
12193
12194 DeallocateStmt: DEALLOCATE name
12195 {
12196 DeallocateStmt *n = makeNode(DeallocateStmt);
12197
12198 n->name = $2;
12199 n->isall = false;
12200 n->location = @2;
12201 $$ = (Node *) n;
12202 }
12203 | DEALLOCATE PREPARE name
12204 {
12205 DeallocateStmt *n = makeNode(DeallocateStmt);
12206
12207 n->name = $3;
12208 n->isall = false;
12209 n->location = @3;
12210 $$ = (Node *) n;
12211 }
12212 | DEALLOCATE ALL
12213 {
12214 DeallocateStmt *n = makeNode(DeallocateStmt);
12215
12216 n->name = NULL;
12217 n->isall = true;
12218 n->location = -1;
12219 $$ = (Node *) n;
12220 }
12221 | DEALLOCATE PREPARE ALL
12222 {
12223 DeallocateStmt *n = makeNode(DeallocateStmt);
12224
12225 n->name = NULL;
12226 n->isall = true;
12227 n->location = -1;
12228 $$ = (Node *) n;
12229 }
12230 ;
12231
12232 /*****************************************************************************
12233 *
12234 * QUERY:
12235 * INSERT STATEMENTS
12236 *
12237 *****************************************************************************/
12238
12239 InsertStmt:
12240 opt_with_clause INSERT INTO insert_target insert_rest
12241 opt_on_conflict returning_clause
12242 {
12243 $5->relation = $4;
12244 $5->onConflictClause = $6;
12245 $5->returningClause = $7;
12246 $5->withClause = $1;
12247 $$ = (Node *) $5;
12248 }
12249 ;
12250
12251 /*
12252 * Can't easily make AS optional here, because VALUES in insert_rest would
12253 * have a shift/reduce conflict with VALUES as an optional alias. We could
12254 * easily allow unreserved_keywords as optional aliases, but that'd be an odd
12255 * divergence from other places. So just require AS for now.
12256 */
12257 insert_target:
12258 qualified_name
12259 {
12260 $$ = $1;
12261 }
12262 | qualified_name AS ColId
12263 {
12264 $1->alias = makeAlias($3, NIL);
12265 $$ = $1;
12266 }
12267 ;
12268
12269 insert_rest:
12270 SelectStmt
12271 {
12272 $$ = makeNode(InsertStmt);
12273 $$->cols = NIL;
12274 $$->selectStmt = $1;
12275 }
12276 | OVERRIDING override_kind VALUE_P SelectStmt
12277 {
12278 $$ = makeNode(InsertStmt);
12279 $$->cols = NIL;
12280 $$->override = $2;
12281 $$->selectStmt = $4;
12282 }
12283 | '(' insert_column_list ')' SelectStmt
12284 {
12285 $$ = makeNode(InsertStmt);
12286 $$->cols = $2;
12287 $$->selectStmt = $4;
12288 }
12289 | '(' insert_column_list ')' OVERRIDING override_kind VALUE_P SelectStmt
12290 {
12291 $$ = makeNode(InsertStmt);
12292 $$->cols = $2;
12293 $$->override = $5;
12294 $$->selectStmt = $7;
12295 }
12296 | DEFAULT VALUES
12297 {
12298 $$ = makeNode(InsertStmt);
12299 $$->cols = NIL;
12300 $$->selectStmt = NULL;
12301 }
12302 ;
12303
12304 override_kind:
12305 USER { $$ = OVERRIDING_USER_VALUE; }
12306 | SYSTEM_P { $$ = OVERRIDING_SYSTEM_VALUE; }
12307 ;
12308
12309 insert_column_list:
12310 insert_column_item
12311 { $$ = list_make1($1); }
12312 | insert_column_list ',' insert_column_item
12313 { $$ = lappend($1, $3); }
12314 ;
12315
12316 insert_column_item:
12317 ColId opt_indirection
12318 {
12319 $$ = makeNode(ResTarget);
12320 $$->name = $1;
12321 $$->indirection = check_indirection($2, yyscanner);
12322 $$->val = NULL;
12323 $$->location = @1;
12324 }
12325 ;
12326
12327 opt_on_conflict:
12328 ON CONFLICT opt_conf_expr DO UPDATE SET set_clause_list where_clause
12329 {
12330 $$ = makeNode(OnConflictClause);
12331 $$->action = ONCONFLICT_UPDATE;
12332 $$->infer = $3;
12333 $$->targetList = $7;
12334 $$->whereClause = $8;
12335 $$->location = @1;
12336 }
12337 |
12338 ON CONFLICT opt_conf_expr DO NOTHING
12339 {
12340 $$ = makeNode(OnConflictClause);
12341 $$->action = ONCONFLICT_NOTHING;
12342 $$->infer = $3;
12343 $$->targetList = NIL;
12344 $$->whereClause = NULL;
12345 $$->location = @1;
12346 }
12347 | /*EMPTY*/
12348 {
12349 $$ = NULL;
12350 }
12351 ;
12352
12353 opt_conf_expr:
12354 '(' index_params ')' where_clause
12355 {
12356 $$ = makeNode(InferClause);
12357 $$->indexElems = $2;
12358 $$->whereClause = $4;
12359 $$->conname = NULL;
12360 $$->location = @1;
12361 }
12362 |
12363 ON CONSTRAINT name
12364 {
12365 $$ = makeNode(InferClause);
12366 $$->indexElems = NIL;
12367 $$->whereClause = NULL;
12368 $$->conname = $3;
12369 $$->location = @1;
12370 }
12371 | /*EMPTY*/
12372 {
12373 $$ = NULL;
12374 }
12375 ;
12376
12377 returning_clause:
12378 RETURNING returning_with_clause target_list
12379 {
12380 ReturningClause *n = makeNode(ReturningClause);
12381
12382 n->options = $2;
12383 n->exprs = $3;
12384 $$ = n;
12385 }
12386 | /* EMPTY */
12387 {
12388 $$ = NULL;
12389 }
12390 ;
12391
12392 returning_with_clause:
12393 WITH '(' returning_options ')' { $$ = $3; }
12394 | /* EMPTY */ { $$ = NIL; }
12395 ;
12396
12397 returning_options:
12398 returning_option { $$ = list_make1($1); }
12399 | returning_options ',' returning_option { $$ = lappend($1, $3); }
12400 ;
12401
12402 returning_option:
12403 returning_option_kind AS ColId
12404 {
12405 ReturningOption *n = makeNode(ReturningOption);
12406
12407 n->option = $1;
12408 n->value = $3;
12409 n->location = @1;
12410 $$ = (Node *) n;
12411 }
12412 ;
12413
12414 returning_option_kind:
12415 OLD { $$ = RETURNING_OPTION_OLD; }
12416 | NEW { $$ = RETURNING_OPTION_NEW; }
12417 ;
12418
12419
12420 /*****************************************************************************
12421 *
12422 * QUERY:
12423 * DELETE STATEMENTS
12424 *
12425 *****************************************************************************/
12426
12427 DeleteStmt: opt_with_clause DELETE_P FROM relation_expr_opt_alias
12428 using_clause where_or_current_clause returning_clause
12429 {
12430 DeleteStmt *n = makeNode(DeleteStmt);
12431
12432 n->relation = $4;
12433 n->usingClause = $5;
12434 n->whereClause = $6;
12435 n->returningClause = $7;
12436 n->withClause = $1;
12437 $$ = (Node *) n;
12438 }
12439 ;
12440
12441 using_clause:
12442 USING from_list { $$ = $2; }
12443 | /*EMPTY*/ { $$ = NIL; }
12444 ;
12445
12446
12447 /*****************************************************************************
12448 *
12449 * QUERY:
12450 * LOCK TABLE
12451 *
12452 *****************************************************************************/
12453
12454 LockStmt: LOCK_P opt_table relation_expr_list opt_lock opt_nowait
12455 {
12456 LockStmt *n = makeNode(LockStmt);
12457
12458 n->relations = $3;
12459 n->mode = $4;
12460 n->nowait = $5;
12461 $$ = (Node *) n;
12462 }
12463 ;
12464
12465 opt_lock: IN_P lock_type MODE { $$ = $2; }
12466 | /*EMPTY*/ { $$ = AccessExclusiveLock; }
12467 ;
12468
12469 lock_type: ACCESS SHARE { $$ = AccessShareLock; }
12470 | ROW SHARE { $$ = RowShareLock; }
12471 | ROW EXCLUSIVE { $$ = RowExclusiveLock; }
12472 | SHARE UPDATE EXCLUSIVE { $$ = ShareUpdateExclusiveLock; }
12473 | SHARE { $$ = ShareLock; }
12474 | SHARE ROW EXCLUSIVE { $$ = ShareRowExclusiveLock; }
12475 | EXCLUSIVE { $$ = ExclusiveLock; }
12476 | ACCESS EXCLUSIVE { $$ = AccessExclusiveLock; }
12477 ;
12478
12479 opt_nowait: NOWAIT { $$ = true; }
12480 | /*EMPTY*/ { $$ = false; }
12481 ;
12482
12483 opt_nowait_or_skip:
12484 NOWAIT { $$ = LockWaitError; }
12485 | SKIP LOCKED { $$ = LockWaitSkip; }
12486 | /*EMPTY*/ { $$ = LockWaitBlock; }
12487 ;
12488
12489
12490 /*****************************************************************************
12491 *
12492 * QUERY:
12493 * UpdateStmt (UPDATE)
12494 *
12495 *****************************************************************************/
12496
12497 UpdateStmt: opt_with_clause UPDATE relation_expr_opt_alias
12498 SET set_clause_list
12499 from_clause
12500 where_or_current_clause
12501 returning_clause
12502 {
12503 UpdateStmt *n = makeNode(UpdateStmt);
12504
12505 n->relation = $3;
12506 n->targetList = $5;
12507 n->fromClause = $6;
12508 n->whereClause = $7;
12509 n->returningClause = $8;
12510 n->withClause = $1;
12511 $$ = (Node *) n;
12512 }
12513 ;
12514
12515 set_clause_list:
12516 set_clause { $$ = $1; }
12517 | set_clause_list ',' set_clause { $$ = list_concat($1,$3); }
12518 ;
12519
12520 set_clause:
12521 set_target '=' a_expr
12522 {
12523 $1->val = (Node *) $3;
12524 $$ = list_make1($1);
12525 }
12526 | '(' set_target_list ')' '=' a_expr
12527 {
12528 int ncolumns = list_length($2);
12529 int i = 1;
12530 ListCell *col_cell;
12531
12532 /* Create a MultiAssignRef source for each target */
12533 foreach(col_cell, $2)
12534 {
12535 ResTarget *res_col = (ResTarget *) lfirst(col_cell);
12536 MultiAssignRef *r = makeNode(MultiAssignRef);
12537
12538 r->source = (Node *) $5;
12539 r->colno = i;
12540 r->ncolumns = ncolumns;
12541 res_col->val = (Node *) r;
12542 i++;
12543 }
12544
12545 $$ = $2;
12546 }
12547 ;
12548
12549 set_target:
12550 ColId opt_indirection
12551 {
12552 $$ = makeNode(ResTarget);
12553 $$->name = $1;
12554 $$->indirection = check_indirection($2, yyscanner);
12555 $$->val = NULL; /* upper production sets this */
12556 $$->location = @1;
12557 }
12558 ;
12559
12560 set_target_list:
12561 set_target { $$ = list_make1($1); }
12562 | set_target_list ',' set_target { $$ = lappend($1,$3); }
12563 ;
12564
12565
12566 /*****************************************************************************
12567 *
12568 * QUERY:
12569 * MERGE
12570 *
12571 *****************************************************************************/
12572
12573 MergeStmt:
12574 opt_with_clause MERGE INTO relation_expr_opt_alias
12575 USING table_ref
12576 ON a_expr
12577 merge_when_list
12578 returning_clause
12579 {
12580 MergeStmt *m = makeNode(MergeStmt);
12581
12582 m->withClause = $1;
12583 m->relation = $4;
12584 m->sourceRelation = $6;
12585 m->joinCondition = $8;
12586 m->mergeWhenClauses = $9;
12587 m->returningClause = $10;
12588
12589 $$ = (Node *) m;
12590 }
12591 ;
12592
12593 merge_when_list:
12594 merge_when_clause { $$ = list_make1($1); }
12595 | merge_when_list merge_when_clause { $$ = lappend($1,$2); }
12596 ;
12597
12598 /*
12599 * A WHEN clause may be WHEN MATCHED, WHEN NOT MATCHED BY SOURCE, or WHEN NOT
12600 * MATCHED [BY TARGET]. The first two cases match target tuples, and support
12601 * UPDATE/DELETE/DO NOTHING actions. The third case does not match target
12602 * tuples, and only supports INSERT/DO NOTHING actions.
12603 */
12604 merge_when_clause:
12605 merge_when_tgt_matched opt_merge_when_condition THEN merge_update
12606 {
12607 $4->matchKind = $1;
12608 $4->condition = $2;
12609
12610 $$ = (Node *) $4;
12611 }
12612 | merge_when_tgt_matched opt_merge_when_condition THEN merge_delete
12613 {
12614 $4->matchKind = $1;
12615 $4->condition = $2;
12616
12617 $$ = (Node *) $4;
12618 }
12619 | merge_when_tgt_not_matched opt_merge_when_condition THEN merge_insert
12620 {
12621 $4->matchKind = $1;
12622 $4->condition = $2;
12623
12624 $$ = (Node *) $4;
12625 }
12626 | merge_when_tgt_matched opt_merge_when_condition THEN DO NOTHING
12627 {
12628 MergeWhenClause *m = makeNode(MergeWhenClause);
12629
12630 m->matchKind = $1;
12631 m->commandType = CMD_NOTHING;
12632 m->condition = $2;
12633
12634 $$ = (Node *) m;
12635 }
12636 | merge_when_tgt_not_matched opt_merge_when_condition THEN DO NOTHING
12637 {
12638 MergeWhenClause *m = makeNode(MergeWhenClause);
12639
12640 m->matchKind = $1;
12641 m->commandType = CMD_NOTHING;
12642 m->condition = $2;
12643
12644 $$ = (Node *) m;
12645 }
12646 ;
12647
12648 merge_when_tgt_matched:
12649 WHEN MATCHED { $$ = MERGE_WHEN_MATCHED; }
12650 | WHEN NOT MATCHED BY SOURCE { $$ = MERGE_WHEN_NOT_MATCHED_BY_SOURCE; }
12651 ;
12652
12653 merge_when_tgt_not_matched:
12654 WHEN NOT MATCHED { $$ = MERGE_WHEN_NOT_MATCHED_BY_TARGET; }
12655 | WHEN NOT MATCHED BY TARGET { $$ = MERGE_WHEN_NOT_MATCHED_BY_TARGET; }
12656 ;
12657
12658 opt_merge_when_condition:
12659 AND a_expr { $$ = $2; }
12660 | { $$ = NULL; }
12661 ;
12662
12663 merge_update:
12664 UPDATE SET set_clause_list
12665 {
12666 MergeWhenClause *n = makeNode(MergeWhenClause);
12667 n->commandType = CMD_UPDATE;
12668 n->override = OVERRIDING_NOT_SET;
12669 n->targetList = $3;
12670 n->values = NIL;
12671
12672 $$ = n;
12673 }
12674 ;
12675
12676 merge_delete:
12677 DELETE_P
12678 {
12679 MergeWhenClause *n = makeNode(MergeWhenClause);
12680 n->commandType = CMD_DELETE;
12681 n->override = OVERRIDING_NOT_SET;
12682 n->targetList = NIL;
12683 n->values = NIL;
12684
12685 $$ = n;
12686 }
12687 ;
12688
12689 merge_insert:
12690 INSERT merge_values_clause
12691 {
12692 MergeWhenClause *n = makeNode(MergeWhenClause);
12693 n->commandType = CMD_INSERT;
12694 n->override = OVERRIDING_NOT_SET;
12695 n->targetList = NIL;
12696 n->values = $2;
12697 $$ = n;
12698 }
12699 | INSERT OVERRIDING override_kind VALUE_P merge_values_clause
12700 {
12701 MergeWhenClause *n = makeNode(MergeWhenClause);
12702 n->commandType = CMD_INSERT;
12703 n->override = $3;
12704 n->targetList = NIL;
12705 n->values = $5;
12706 $$ = n;
12707 }
12708 | INSERT '(' insert_column_list ')' merge_values_clause
12709 {
12710 MergeWhenClause *n = makeNode(MergeWhenClause);
12711 n->commandType = CMD_INSERT;
12712 n->override = OVERRIDING_NOT_SET;
12713 n->targetList = $3;
12714 n->values = $5;
12715 $$ = n;
12716 }
12717 | INSERT '(' insert_column_list ')' OVERRIDING override_kind VALUE_P merge_values_clause
12718 {
12719 MergeWhenClause *n = makeNode(MergeWhenClause);
12720 n->commandType = CMD_INSERT;
12721 n->override = $6;
12722 n->targetList = $3;
12723 n->values = $8;
12724 $$ = n;
12725 }
12726 | INSERT DEFAULT VALUES
12727 {
12728 MergeWhenClause *n = makeNode(MergeWhenClause);
12729 n->commandType = CMD_INSERT;
12730 n->override = OVERRIDING_NOT_SET;
12731 n->targetList = NIL;
12732 n->values = NIL;
12733 $$ = n;
12734 }
12735 ;
12736
12737 merge_values_clause:
12738 VALUES '(' expr_list ')'
12739 {
12740 $$ = $3;
12741 }
12742 ;
12743
12744 /*****************************************************************************
12745 *
12746 * QUERY:
12747 * CURSOR STATEMENTS
12748 *
12749 *****************************************************************************/
12750 DeclareCursorStmt: DECLARE cursor_name cursor_options CURSOR opt_hold FOR SelectStmt
12751 {
12752 DeclareCursorStmt *n = makeNode(DeclareCursorStmt);
12753
12754 n->portalname = $2;
12755 /* currently we always set FAST_PLAN option */
12756 n->options = $3 | $5 | CURSOR_OPT_FAST_PLAN;
12757 n->query = $7;
12758 $$ = (Node *) n;
12759 }
12760 ;
12761
12762 cursor_name: name { $$ = $1; }
12763 ;
12764
12765 cursor_options: /*EMPTY*/ { $$ = 0; }
12766 | cursor_options NO SCROLL { $$ = $1 | CURSOR_OPT_NO_SCROLL; }
12767 | cursor_options SCROLL { $$ = $1 | CURSOR_OPT_SCROLL; }
12768 | cursor_options BINARY { $$ = $1 | CURSOR_OPT_BINARY; }
12769 | cursor_options ASENSITIVE { $$ = $1 | CURSOR_OPT_ASENSITIVE; }
12770 | cursor_options INSENSITIVE { $$ = $1 | CURSOR_OPT_INSENSITIVE; }
12771 ;
12772
12773 opt_hold: /* EMPTY */ { $$ = 0; }
12774 | WITH HOLD { $$ = CURSOR_OPT_HOLD; }
12775 | WITHOUT HOLD { $$ = 0; }
12776 ;
12777
12778 /*****************************************************************************
12779 *
12780 * QUERY:
12781 * SELECT STATEMENTS
12782 *
12783 *****************************************************************************/
12784
12785 /* A complete SELECT statement looks like this.
12786 *
12787 * The rule returns either a single SelectStmt node or a tree of them,
12788 * representing a set-operation tree.
12789 *
12790 * There is an ambiguity when a sub-SELECT is within an a_expr and there
12791 * are excess parentheses: do the parentheses belong to the sub-SELECT or
12792 * to the surrounding a_expr? We don't really care, but bison wants to know.
12793 * To resolve the ambiguity, we are careful to define the grammar so that
12794 * the decision is staved off as long as possible: as long as we can keep
12795 * absorbing parentheses into the sub-SELECT, we will do so, and only when
12796 * it's no longer possible to do that will we decide that parens belong to
12797 * the expression. For example, in "SELECT (((SELECT 2)) + 3)" the extra
12798 * parentheses are treated as part of the sub-select. The necessity of doing
12799 * it that way is shown by "SELECT (((SELECT 2)) UNION SELECT 2)". Had we
12800 * parsed "((SELECT 2))" as an a_expr, it'd be too late to go back to the
12801 * SELECT viewpoint when we see the UNION.
12802 *
12803 * This approach is implemented by defining a nonterminal select_with_parens,
12804 * which represents a SELECT with at least one outer layer of parentheses,
12805 * and being careful to use select_with_parens, never '(' SelectStmt ')',
12806 * in the expression grammar. We will then have shift-reduce conflicts
12807 * which we can resolve in favor of always treating '(' <select> ')' as
12808 * a select_with_parens. To resolve the conflicts, the productions that
12809 * conflict with the select_with_parens productions are manually given
12810 * precedences lower than the precedence of ')', thereby ensuring that we
12811 * shift ')' (and then reduce to select_with_parens) rather than trying to
12812 * reduce the inner <select> nonterminal to something else. We use UMINUS
12813 * precedence for this, which is a fairly arbitrary choice.
12814 *
12815 * To be able to define select_with_parens itself without ambiguity, we need
12816 * a nonterminal select_no_parens that represents a SELECT structure with no
12817 * outermost parentheses. This is a little bit tedious, but it works.
12818 *
12819 * In non-expression contexts, we use SelectStmt which can represent a SELECT
12820 * with or without outer parentheses.
12821 */
12822
12823 SelectStmt: select_no_parens %prec UMINUS
12824 | select_with_parens %prec UMINUS
12825 ;
12826
12827 select_with_parens:
12828 '(' select_no_parens ')' { $$ = $2; }
12829 | '(' select_with_parens ')' { $$ = $2; }
12830 ;
12831
12832 /*
12833 * This rule parses the equivalent of the standard's <query expression>.
12834 * The duplicative productions are annoying, but hard to get rid of without
12835 * creating shift/reduce conflicts.
12836 *
12837 * The locking clause (FOR UPDATE etc) may be before or after LIMIT/OFFSET.
12838 * In <=7.2.X, LIMIT/OFFSET had to be after FOR UPDATE
12839 * We now support both orderings, but prefer LIMIT/OFFSET before the locking
12840 * clause.
12841 * 2002-08-28 bjm
12842 */
12843 select_no_parens:
12844 simple_select { $$ = $1; }
12845 | select_clause sort_clause
12846 {
12847 insertSelectOptions((SelectStmt *) $1, $2, NIL,
12848 NULL, NULL,
12849 yyscanner);
12850 $$ = $1;
12851 }
12852 | select_clause opt_sort_clause for_locking_clause opt_select_limit
12853 {
12854 insertSelectOptions((SelectStmt *) $1, $2, $3,
12855 $4,
12856 NULL,
12857 yyscanner);
12858 $$ = $1;
12859 }
12860 | select_clause opt_sort_clause select_limit opt_for_locking_clause
12861 {
12862 insertSelectOptions((SelectStmt *) $1, $2, $4,
12863 $3,
12864 NULL,
12865 yyscanner);
12866 $$ = $1;
12867 }
12868 | with_clause select_clause
12869 {
12870 insertSelectOptions((SelectStmt *) $2, NULL, NIL,
12871 NULL,
12872 $1,
12873 yyscanner);
12874 $$ = $2;
12875 }
12876 | with_clause select_clause sort_clause
12877 {
12878 insertSelectOptions((SelectStmt *) $2, $3, NIL,
12879 NULL,
12880 $1,
12881 yyscanner);
12882 $$ = $2;
12883 }
12884 | with_clause select_clause opt_sort_clause for_locking_clause opt_select_limit
12885 {
12886 insertSelectOptions((SelectStmt *) $2, $3, $4,
12887 $5,
12888 $1,
12889 yyscanner);
12890 $$ = $2;
12891 }
12892 | with_clause select_clause opt_sort_clause select_limit opt_for_locking_clause
12893 {
12894 insertSelectOptions((SelectStmt *) $2, $3, $5,
12895 $4,
12896 $1,
12897 yyscanner);
12898 $$ = $2;
12899 }
12900 ;
12901
12902 select_clause:
12903 simple_select { $$ = $1; }
12904 | select_with_parens { $$ = $1; }
12905 ;
12906
12907 /*
12908 * This rule parses SELECT statements that can appear within set operations,
12909 * including UNION, INTERSECT and EXCEPT. '(' and ')' can be used to specify
12910 * the ordering of the set operations. Without '(' and ')' we want the
12911 * operations to be ordered per the precedence specs at the head of this file.
12912 *
12913 * As with select_no_parens, simple_select cannot have outer parentheses,
12914 * but can have parenthesized subclauses.
12915 *
12916 * It might appear that we could fold the first two alternatives into one
12917 * by using opt_distinct_clause. However, that causes a shift/reduce conflict
12918 * against INSERT ... SELECT ... ON CONFLICT. We avoid the ambiguity by
12919 * requiring SELECT DISTINCT [ON] to be followed by a non-empty target_list.
12920 *
12921 * Note that sort clauses cannot be included at this level --- SQL requires
12922 * SELECT foo UNION SELECT bar ORDER BY baz
12923 * to be parsed as
12924 * (SELECT foo UNION SELECT bar) ORDER BY baz
12925 * not
12926 * SELECT foo UNION (SELECT bar ORDER BY baz)
12927 * Likewise for WITH, FOR UPDATE and LIMIT. Therefore, those clauses are
12928 * described as part of the select_no_parens production, not simple_select.
12929 * This does not limit functionality, because you can reintroduce these
12930 * clauses inside parentheses.
12931 *
12932 * NOTE: only the leftmost component SelectStmt should have INTO.
12933 * However, this is not checked by the grammar; parse analysis must check it.
12934 */
12935 simple_select:
12936 SELECT opt_all_clause opt_target_list
12937 into_clause from_clause where_clause
12938 group_clause having_clause window_clause
12939 {
12940 SelectStmt *n = makeNode(SelectStmt);
12941
12942 n->targetList = $3;
12943 n->intoClause = $4;
12944 n->fromClause = $5;
12945 n->whereClause = $6;
12946 n->groupClause = ($7)->list;
12947 n->groupDistinct = ($7)->distinct;
12948 n->havingClause = $8;
12949 n->windowClause = $9;
12950 $$ = (Node *) n;
12951 }
12952 | SELECT distinct_clause target_list
12953 into_clause from_clause where_clause
12954 group_clause having_clause window_clause
12955 {
12956 SelectStmt *n = makeNode(SelectStmt);
12957
12958 n->distinctClause = $2;
12959 n->targetList = $3;
12960 n->intoClause = $4;
12961 n->fromClause = $5;
12962 n->whereClause = $6;
12963 n->groupClause = ($7)->list;
12964 n->groupDistinct = ($7)->distinct;
12965 n->havingClause = $8;
12966 n->windowClause = $9;
12967 $$ = (Node *) n;
12968 }
12969 | values_clause { $$ = $1; }
12970 | TABLE relation_expr
12971 {
12972 /* same as SELECT * FROM relation_expr */
12973 ColumnRef *cr = makeNode(ColumnRef);
12974 ResTarget *rt = makeNode(ResTarget);
12975 SelectStmt *n = makeNode(SelectStmt);
12976
12977 cr->fields = list_make1(makeNode(A_Star));
12978 cr->location = -1;
12979
12980 rt->name = NULL;
12981 rt->indirection = NIL;
12982 rt->val = (Node *) cr;
12983 rt->location = -1;
12984
12985 n->targetList = list_make1(rt);
12986 n->fromClause = list_make1($2);
12987 $$ = (Node *) n;
12988 }
12989 | select_clause UNION set_quantifier select_clause
12990 {
12991 $$ = makeSetOp(SETOP_UNION, $3 == SET_QUANTIFIER_ALL, $1, $4);
12992 }
12993 | select_clause INTERSECT set_quantifier select_clause
12994 {
12995 $$ = makeSetOp(SETOP_INTERSECT, $3 == SET_QUANTIFIER_ALL, $1, $4);
12996 }
12997 | select_clause EXCEPT set_quantifier select_clause
12998 {
12999 $$ = makeSetOp(SETOP_EXCEPT, $3 == SET_QUANTIFIER_ALL, $1, $4);
13000 }
13001 ;
13002
13003 /*
13004 * SQL standard WITH clause looks like:
13005 *
13006 * WITH [ RECURSIVE ] <query name> [ (<column>,...) ]
13007 * AS (query) [ SEARCH or CYCLE clause ]
13008 *
13009 * Recognizing WITH_LA here allows a CTE to be named TIME or ORDINALITY.
13010 */
13011 with_clause:
13012 WITH cte_list
13013 {
13014 $$ = makeNode(WithClause);
13015 $$->ctes = $2;
13016 $$->recursive = false;
13017 $$->location = @1;
13018 }
13019 | WITH_LA cte_list
13020 {
13021 $$ = makeNode(WithClause);
13022 $$->ctes = $2;
13023 $$->recursive = false;
13024 $$->location = @1;
13025 }
13026 | WITH RECURSIVE cte_list
13027 {
13028 $$ = makeNode(WithClause);
13029 $$->ctes = $3;
13030 $$->recursive = true;
13031 $$->location = @1;
13032 }
13033 ;
13034
13035 cte_list:
13036 common_table_expr { $$ = list_make1($1); }
13037 | cte_list ',' common_table_expr { $$ = lappend($1, $3); }
13038 ;
13039
13040 common_table_expr: name opt_name_list AS opt_materialized '(' PreparableStmt ')' opt_search_clause opt_cycle_clause
13041 {
13042 CommonTableExpr *n = makeNode(CommonTableExpr);
13043
13044 n->ctename = $1;
13045 n->aliascolnames = $2;
13046 n->ctematerialized = $4;
13047 n->ctequery = $6;
13048 n->search_clause = castNode(CTESearchClause, $8);
13049 n->cycle_clause = castNode(CTECycleClause, $9);
13050 n->location = @1;
13051 $$ = (Node *) n;
13052 }
13053 ;
13054
13055 opt_materialized:
13056 MATERIALIZED { $$ = CTEMaterializeAlways; }
13057 | NOT MATERIALIZED { $$ = CTEMaterializeNever; }
13058 | /*EMPTY*/ { $$ = CTEMaterializeDefault; }
13059 ;
13060
13061 opt_search_clause:
13062 SEARCH DEPTH FIRST_P BY columnList SET ColId
13063 {
13064 CTESearchClause *n = makeNode(CTESearchClause);
13065
13066 n->search_col_list = $5;
13067 n->search_breadth_first = false;
13068 n->search_seq_column = $7;
13069 n->location = @1;
13070 $$ = (Node *) n;
13071 }
13072 | SEARCH BREADTH FIRST_P BY columnList SET ColId
13073 {
13074 CTESearchClause *n = makeNode(CTESearchClause);
13075
13076 n->search_col_list = $5;
13077 n->search_breadth_first = true;
13078 n->search_seq_column = $7;
13079 n->location = @1;
13080 $$ = (Node *) n;
13081 }
13082 | /*EMPTY*/
13083 {
13084 $$ = NULL;
13085 }
13086 ;
13087
13088 opt_cycle_clause:
13089 CYCLE columnList SET ColId TO AexprConst DEFAULT AexprConst USING ColId
13090 {
13091 CTECycleClause *n = makeNode(CTECycleClause);
13092
13093 n->cycle_col_list = $2;
13094 n->cycle_mark_column = $4;
13095 n->cycle_mark_value = $6;
13096 n->cycle_mark_default = $8;
13097 n->cycle_path_column = $10;
13098 n->location = @1;
13099 $$ = (Node *) n;
13100 }
13101 | CYCLE columnList SET ColId USING ColId
13102 {
13103 CTECycleClause *n = makeNode(CTECycleClause);
13104
13105 n->cycle_col_list = $2;
13106 n->cycle_mark_column = $4;
13107 n->cycle_mark_value = makeBoolAConst(true, -1);
13108 n->cycle_mark_default = makeBoolAConst(false, -1);
13109 n->cycle_path_column = $6;
13110 n->location = @1;
13111 $$ = (Node *) n;
13112 }
13113 | /*EMPTY*/
13114 {
13115 $$ = NULL;
13116 }
13117 ;
13118
13119 opt_with_clause:
13120 with_clause { $$ = $1; }
13121 | /*EMPTY*/ { $$ = NULL; }
13122 ;
13123
13124 into_clause:
13125 INTO OptTempTableName
13126 {
13127 $$ = makeNode(IntoClause);
13128 $$->rel = $2;
13129 $$->colNames = NIL;
13130 $$->options = NIL;
13131 $$->onCommit = ONCOMMIT_NOOP;
13132 $$->tableSpaceName = NULL;
13133 $$->viewQuery = NULL;
13134 $$->skipData = false;
13135 }
13136 | /*EMPTY*/
13137 { $$ = NULL; }
13138 ;
13139
13140 /*
13141 * Redundancy here is needed to avoid shift/reduce conflicts,
13142 * since TEMP is not a reserved word. See also OptTemp.
13143 */
13144 OptTempTableName:
13145 TEMPORARY opt_table qualified_name
13146 {
13147 $$ = $3;
13148 $$->relpersistence = RELPERSISTENCE_TEMP;
13149 }
13150 | TEMP opt_table qualified_name
13151 {
13152 $$ = $3;
13153 $$->relpersistence = RELPERSISTENCE_TEMP;
13154 }
13155 | LOCAL TEMPORARY opt_table qualified_name
13156 {
13157 $$ = $4;
13158 $$->relpersistence = RELPERSISTENCE_TEMP;
13159 }
13160 | LOCAL TEMP opt_table qualified_name
13161 {
13162 $$ = $4;
13163 $$->relpersistence = RELPERSISTENCE_TEMP;
13164 }
13165 | GLOBAL TEMPORARY opt_table qualified_name
13166 {
13167 ereport(WARNING,
13168 (errmsg("GLOBAL is deprecated in temporary table creation"),
13169 parser_errposition(@1)));
13170 $$ = $4;
13171 $$->relpersistence = RELPERSISTENCE_TEMP;
13172 }
13173 | GLOBAL TEMP opt_table qualified_name
13174 {
13175 ereport(WARNING,
13176 (errmsg("GLOBAL is deprecated in temporary table creation"),
13177 parser_errposition(@1)));
13178 $$ = $4;
13179 $$->relpersistence = RELPERSISTENCE_TEMP;
13180 }
13181 | UNLOGGED opt_table qualified_name
13182 {
13183 $$ = $3;
13184 $$->relpersistence = RELPERSISTENCE_UNLOGGED;
13185 }
13186 | TABLE qualified_name
13187 {
13188 $$ = $2;
13189 $$->relpersistence = RELPERSISTENCE_PERMANENT;
13190 }
13191 | qualified_name
13192 {
13193 $$ = $1;
13194 $$->relpersistence = RELPERSISTENCE_PERMANENT;
13195 }
13196 ;
13197
13198 opt_table: TABLE
13199 | /*EMPTY*/
13200 ;
13201
13202 set_quantifier:
13203 ALL { $$ = SET_QUANTIFIER_ALL; }
13204 | DISTINCT { $$ = SET_QUANTIFIER_DISTINCT; }
13205 | /*EMPTY*/ { $$ = SET_QUANTIFIER_DEFAULT; }
13206 ;
13207
13208 /* We use (NIL) as a placeholder to indicate that all target expressions
13209 * should be placed in the DISTINCT list during parsetree analysis.
13210 */
13211 distinct_clause:
13212 DISTINCT { $$ = list_make1(NIL); }
13213 | DISTINCT ON '(' expr_list ')' { $$ = $4; }
13214 ;
13215
13216 opt_all_clause:
13217 ALL
13218 | /*EMPTY*/
13219 ;
13220
13221 opt_distinct_clause:
13222 distinct_clause { $$ = $1; }
13223 | opt_all_clause { $$ = NIL; }
13224 ;
13225
13226 opt_sort_clause:
13227 sort_clause { $$ = $1; }
13228 | /*EMPTY*/ { $$ = NIL; }
13229 ;
13230
13231 sort_clause:
13232 ORDER BY sortby_list { $$ = $3; }
13233 ;
13234
13235 sortby_list:
13236 sortby { $$ = list_make1($1); }
13237 | sortby_list ',' sortby { $$ = lappend($1, $3); }
13238 ;
13239
13240 sortby: a_expr USING qual_all_Op opt_nulls_order
13241 {
13242 $$ = makeNode(SortBy);
13243 $$->node = $1;
13244 $$->sortby_dir = SORTBY_USING;
13245 $$->sortby_nulls = $4;
13246 $$->useOp = $3;
13247 $$->location = @3;
13248 }
13249 | a_expr opt_asc_desc opt_nulls_order
13250 {
13251 $$ = makeNode(SortBy);
13252 $$->node = $1;
13253 $$->sortby_dir = $2;
13254 $$->sortby_nulls = $3;
13255 $$->useOp = NIL;
13256 $$->location = -1; /* no operator */
13257 }
13258 ;
13259
13260
13261 select_limit:
13262 limit_clause offset_clause
13263 {
13264 $$ = $1;
13265 ($$)->limitOffset = $2;
13266 ($$)->offsetLoc = @2;
13267 }
13268 | offset_clause limit_clause
13269 {
13270 $$ = $2;
13271 ($$)->limitOffset = $1;
13272 ($$)->offsetLoc = @1;
13273 }
13274 | limit_clause
13275 {
13276 $$ = $1;
13277 }
13278 | offset_clause
13279 {
13280 SelectLimit *n = (SelectLimit *) palloc(sizeof(SelectLimit));
13281
13282 n->limitOffset = $1;
13283 n->limitCount = NULL;
13284 n->limitOption = LIMIT_OPTION_COUNT;
13285 n->offsetLoc = @1;
13286 n->countLoc = -1;
13287 n->optionLoc = -1;
13288 $$ = n;
13289 }
13290 ;
13291
13292 opt_select_limit:
13293 select_limit { $$ = $1; }
13294 | /* EMPTY */ { $$ = NULL; }
13295 ;
13296
13297 limit_clause:
13298 LIMIT select_limit_value
13299 {
13300 SelectLimit *n = (SelectLimit *) palloc(sizeof(SelectLimit));
13301
13302 n->limitOffset = NULL;
13303 n->limitCount = $2;
13304 n->limitOption = LIMIT_OPTION_COUNT;
13305 n->offsetLoc = -1;
13306 n->countLoc = @1;
13307 n->optionLoc = -1;
13308 $$ = n;
13309 }
13310 | LIMIT select_limit_value ',' select_offset_value
13311 {
13312 /* Disabled because it was too confusing, bjm 2002-02-18 */
13313 ereport(ERROR,
13314 (errcode(ERRCODE_SYNTAX_ERROR),
13315 errmsg("LIMIT #,# syntax is not supported"),
13316 errhint("Use separate LIMIT and OFFSET clauses."),
13317 parser_errposition(@1)));
13318 }
13319 /* SQL:2008 syntax */
13320 /* to avoid shift/reduce conflicts, handle the optional value with
13321 * a separate production rather than an opt_ expression. The fact
13322 * that ONLY is fully reserved means that this way, we defer any
13323 * decision about what rule reduces ROW or ROWS to the point where
13324 * we can see the ONLY token in the lookahead slot.
13325 */
13326 | FETCH first_or_next select_fetch_first_value row_or_rows ONLY
13327 {
13328 SelectLimit *n = (SelectLimit *) palloc(sizeof(SelectLimit));
13329
13330 n->limitOffset = NULL;
13331 n->limitCount = $3;
13332 n->limitOption = LIMIT_OPTION_COUNT;
13333 n->offsetLoc = -1;
13334 n->countLoc = @1;
13335 n->optionLoc = -1;
13336 $$ = n;
13337 }
13338 | FETCH first_or_next select_fetch_first_value row_or_rows WITH TIES
13339 {
13340 SelectLimit *n = (SelectLimit *) palloc(sizeof(SelectLimit));
13341
13342 n->limitOffset = NULL;
13343 n->limitCount = $3;
13344 n->limitOption = LIMIT_OPTION_WITH_TIES;
13345 n->offsetLoc = -1;
13346 n->countLoc = @1;
13347 n->optionLoc = @5;
13348 $$ = n;
13349 }
13350 | FETCH first_or_next row_or_rows ONLY
13351 {
13352 SelectLimit *n = (SelectLimit *) palloc(sizeof(SelectLimit));
13353
13354 n->limitOffset = NULL;
13355 n->limitCount = makeIntConst(1, -1);
13356 n->limitOption = LIMIT_OPTION_COUNT;
13357 n->offsetLoc = -1;
13358 n->countLoc = @1;
13359 n->optionLoc = -1;
13360 $$ = n;
13361 }
13362 | FETCH first_or_next row_or_rows WITH TIES
13363 {
13364 SelectLimit *n = (SelectLimit *) palloc(sizeof(SelectLimit));
13365
13366 n->limitOffset = NULL;
13367 n->limitCount = makeIntConst(1, -1);
13368 n->limitOption = LIMIT_OPTION_WITH_TIES;
13369 n->offsetLoc = -1;
13370 n->countLoc = @1;
13371 n->optionLoc = @4;
13372 $$ = n;
13373 }
13374 ;
13375
13376 offset_clause:
13377 OFFSET select_offset_value
13378 { $$ = $2; }
13379 /* SQL:2008 syntax */
13380 | OFFSET select_fetch_first_value row_or_rows
13381 { $$ = $2; }
13382 ;
13383
13384 select_limit_value:
13385 a_expr { $$ = $1; }
13386 | ALL
13387 {
13388 /* LIMIT ALL is represented as a NULL constant */
13389 $$ = makeNullAConst(@1);
13390 }
13391 ;
13392
13393 select_offset_value:
13394 a_expr { $$ = $1; }
13395 ;
13396
13397 /*
13398 * Allowing full expressions without parentheses causes various parsing
13399 * problems with the trailing ROW/ROWS key words. SQL spec only calls for
13400 * <simple value specification>, which is either a literal or a parameter (but
13401 * an <SQL parameter reference> could be an identifier, bringing up conflicts
13402 * with ROW/ROWS). We solve this by leveraging the presence of ONLY (see above)
13403 * to determine whether the expression is missing rather than trying to make it
13404 * optional in this rule.
13405 *
13406 * c_expr covers almost all the spec-required cases (and more), but it doesn't
13407 * cover signed numeric literals, which are allowed by the spec. So we include
13408 * those here explicitly. We need FCONST as well as ICONST because values that
13409 * don't fit in the platform's "long", but do fit in bigint, should still be
13410 * accepted here. (This is possible in 64-bit Windows as well as all 32-bit
13411 * builds.)
13412 */
13413 select_fetch_first_value:
13414 c_expr { $$ = $1; }
13415 | '+' I_or_F_const
13416 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "+", NULL, $2, @1); }
13417 | '-' I_or_F_const
13418 { $$ = doNegate($2, @1); }
13419 ;
13420
13421 I_or_F_const:
13422 Iconst { $$ = makeIntConst($1,@1); }
13423 | FCONST { $$ = makeFloatConst($1,@1); }
13424 ;
13425
13426 /* noise words */
13427 row_or_rows: ROW { $$ = 0; }
13428 | ROWS { $$ = 0; }
13429 ;
13430
13431 first_or_next: FIRST_P { $$ = 0; }
13432 | NEXT { $$ = 0; }
13433 ;
13434
13435
13436 /*
13437 * This syntax for group_clause tries to follow the spec quite closely.
13438 * However, the spec allows only column references, not expressions,
13439 * which introduces an ambiguity between implicit row constructors
13440 * (a,b) and lists of column references.
13441 *
13442 * We handle this by using the a_expr production for what the spec calls
13443 * <ordinary grouping set>, which in the spec represents either one column
13444 * reference or a parenthesized list of column references. Then, we check the
13445 * top node of the a_expr to see if it's an implicit RowExpr, and if so, just
13446 * grab and use the list, discarding the node. (this is done in parse analysis,
13447 * not here)
13448 *
13449 * (we abuse the row_format field of RowExpr to distinguish implicit and
13450 * explicit row constructors; it's debatable if anyone sanely wants to use them
13451 * in a group clause, but if they have a reason to, we make it possible.)
13452 *
13453 * Each item in the group_clause list is either an expression tree or a
13454 * GroupingSet node of some type.
13455 */
13456 group_clause:
13457 GROUP_P BY set_quantifier group_by_list
13458 {
13459 GroupClause *n = (GroupClause *) palloc(sizeof(GroupClause));
13460
13461 n->distinct = $3 == SET_QUANTIFIER_DISTINCT;
13462 n->list = $4;
13463 $$ = n;
13464 }
13465 | /*EMPTY*/
13466 {
13467 GroupClause *n = (GroupClause *) palloc(sizeof(GroupClause));
13468
13469 n->distinct = false;
13470 n->list = NIL;
13471 $$ = n;
13472 }
13473 ;
13474
13475 group_by_list:
13476 group_by_item { $$ = list_make1($1); }
13477 | group_by_list ',' group_by_item { $$ = lappend($1,$3); }
13478 ;
13479
13480 group_by_item:
13481 a_expr { $$ = $1; }
13482 | empty_grouping_set { $$ = $1; }
13483 | cube_clause { $$ = $1; }
13484 | rollup_clause { $$ = $1; }
13485 | grouping_sets_clause { $$ = $1; }
13486 ;
13487
13488 empty_grouping_set:
13489 '(' ')'
13490 {
13491 $$ = (Node *) makeGroupingSet(GROUPING_SET_EMPTY, NIL, @1);
13492 }
13493 ;
13494
13495 /*
13496 * These hacks rely on setting precedence of CUBE and ROLLUP below that of '(',
13497 * so that they shift in these rules rather than reducing the conflicting
13498 * unreserved_keyword rule.
13499 */
13500
13501 rollup_clause:
13502 ROLLUP '(' expr_list ')'
13503 {
13504 $$ = (Node *) makeGroupingSet(GROUPING_SET_ROLLUP, $3, @1);
13505 }
13506 ;
13507
13508 cube_clause:
13509 CUBE '(' expr_list ')'
13510 {
13511 $$ = (Node *) makeGroupingSet(GROUPING_SET_CUBE, $3, @1);
13512 }
13513 ;
13514
13515 grouping_sets_clause:
13516 GROUPING SETS '(' group_by_list ')'
13517 {
13518 $$ = (Node *) makeGroupingSet(GROUPING_SET_SETS, $4, @1);
13519 }
13520 ;
13521
13522 having_clause:
13523 HAVING a_expr { $$ = $2; }
13524 | /*EMPTY*/ { $$ = NULL; }
13525 ;
13526
13527 for_locking_clause:
13528 for_locking_items { $$ = $1; }
13529 | FOR READ ONLY { $$ = NIL; }
13530 ;
13531
13532 opt_for_locking_clause:
13533 for_locking_clause { $$ = $1; }
13534 | /* EMPTY */ { $$ = NIL; }
13535 ;
13536
13537 for_locking_items:
13538 for_locking_item { $$ = list_make1($1); }
13539 | for_locking_items for_locking_item { $$ = lappend($1, $2); }
13540 ;
13541
13542 for_locking_item:
13543 for_locking_strength locked_rels_list opt_nowait_or_skip
13544 {
13545 LockingClause *n = makeNode(LockingClause);
13546
13547 n->lockedRels = $2;
13548 n->strength = $1;
13549 n->waitPolicy = $3;
13550 $$ = (Node *) n;
13551 }
13552 ;
13553
13554 for_locking_strength:
13555 FOR UPDATE { $$ = LCS_FORUPDATE; }
13556 | FOR NO KEY UPDATE { $$ = LCS_FORNOKEYUPDATE; }
13557 | FOR SHARE { $$ = LCS_FORSHARE; }
13558 | FOR KEY SHARE { $$ = LCS_FORKEYSHARE; }
13559 ;
13560
13561 locked_rels_list:
13562 OF qualified_name_list { $$ = $2; }
13563 | /* EMPTY */ { $$ = NIL; }
13564 ;
13565
13566
13567 /*
13568 * We should allow ROW '(' expr_list ')' too, but that seems to require
13569 * making VALUES a fully reserved word, which will probably break more apps
13570 * than allowing the noise-word is worth.
13571 */
13572 values_clause:
13573 VALUES '(' expr_list ')'
13574 {
13575 SelectStmt *n = makeNode(SelectStmt);
13576
13577 n->valuesLists = list_make1($3);
13578 $$ = (Node *) n;
13579 }
13580 | values_clause ',' '(' expr_list ')'
13581 {
13582 SelectStmt *n = (SelectStmt *) $1;
13583
13584 n->valuesLists = lappend(n->valuesLists, $4);
13585 $$ = (Node *) n;
13586 }
13587 ;
13588
13589
13590 /*****************************************************************************
13591 *
13592 * clauses common to all Optimizable Stmts:
13593 * from_clause - allow list of both JOIN expressions and table names
13594 * where_clause - qualifications for joins or restrictions
13595 *
13596 *****************************************************************************/
13597
13598 from_clause:
13599 FROM from_list { $$ = $2; }
13600 | /*EMPTY*/ { $$ = NIL; }
13601 ;
13602
13603 from_list:
13604 table_ref { $$ = list_make1($1); }
13605 | from_list ',' table_ref { $$ = lappend($1, $3); }
13606 ;
13607
13608 /*
13609 * table_ref is where an alias clause can be attached.
13610 */
13611 table_ref: relation_expr opt_alias_clause
13612 {
13613 $1->alias = $2;
13614 $$ = (Node *) $1;
13615 }
13616 | relation_expr opt_alias_clause tablesample_clause
13617 {
13618 RangeTableSample *n = (RangeTableSample *) $3;
13619
13620 $1->alias = $2;
13621 /* relation_expr goes inside the RangeTableSample node */
13622 n->relation = (Node *) $1;
13623 $$ = (Node *) n;
13624 }
13625 | func_table func_alias_clause
13626 {
13627 RangeFunction *n = (RangeFunction *) $1;
13628
13629 n->alias = linitial($2);
13630 n->coldeflist = lsecond($2);
13631 $$ = (Node *) n;
13632 }
13633 | LATERAL_P func_table func_alias_clause
13634 {
13635 RangeFunction *n = (RangeFunction *) $2;
13636
13637 n->lateral = true;
13638 n->alias = linitial($3);
13639 n->coldeflist = lsecond($3);
13640 $$ = (Node *) n;
13641 }
13642 | xmltable opt_alias_clause
13643 {
13644 RangeTableFunc *n = (RangeTableFunc *) $1;
13645
13646 n->alias = $2;
13647 $$ = (Node *) n;
13648 }
13649 | LATERAL_P xmltable opt_alias_clause
13650 {
13651 RangeTableFunc *n = (RangeTableFunc *) $2;
13652
13653 n->lateral = true;
13654 n->alias = $3;
13655 $$ = (Node *) n;
13656 }
13657 | select_with_parens opt_alias_clause
13658 {
13659 RangeSubselect *n = makeNode(RangeSubselect);
13660
13661 n->lateral = false;
13662 n->subquery = $1;
13663 n->alias = $2;
13664 $$ = (Node *) n;
13665 }
13666 | LATERAL_P select_with_parens opt_alias_clause
13667 {
13668 RangeSubselect *n = makeNode(RangeSubselect);
13669
13670 n->lateral = true;
13671 n->subquery = $2;
13672 n->alias = $3;
13673 $$ = (Node *) n;
13674 }
13675 | joined_table
13676 {
13677 $$ = (Node *) $1;
13678 }
13679 | '(' joined_table ')' alias_clause
13680 {
13681 $2->alias = $4;
13682 $$ = (Node *) $2;
13683 }
13684 | json_table opt_alias_clause
13685 {
13686 JsonTable *jt = castNode(JsonTable, $1);
13687
13688 jt->alias = $2;
13689 $$ = (Node *) jt;
13690 }
13691 | LATERAL_P json_table opt_alias_clause
13692 {
13693 JsonTable *jt = castNode(JsonTable, $2);
13694
13695 jt->alias = $3;
13696 jt->lateral = true;
13697 $$ = (Node *) jt;
13698 }
13699 ;
13700
13701
13702 /*
13703 * It may seem silly to separate joined_table from table_ref, but there is
13704 * method in SQL's madness: if you don't do it this way you get reduce-
13705 * reduce conflicts, because it's not clear to the parser generator whether
13706 * to expect alias_clause after ')' or not. For the same reason we must
13707 * treat 'JOIN' and 'join_type JOIN' separately, rather than allowing
13708 * join_type to expand to empty; if we try it, the parser generator can't
13709 * figure out when to reduce an empty join_type right after table_ref.
13710 *
13711 * Note that a CROSS JOIN is the same as an unqualified
13712 * INNER JOIN, and an INNER JOIN/ON has the same shape
13713 * but a qualification expression to limit membership.
13714 * A NATURAL JOIN implicitly matches column names between
13715 * tables and the shape is determined by which columns are
13716 * in common. We'll collect columns during the later transformations.
13717 */
13718
13719 joined_table:
13720 '(' joined_table ')'
13721 {
13722 $$ = $2;
13723 }
13724 | table_ref CROSS JOIN table_ref
13725 {
13726 /* CROSS JOIN is same as unqualified inner join */
13727 JoinExpr *n = makeNode(JoinExpr);
13728
13729 n->jointype = JOIN_INNER;
13730 n->isNatural = false;
13731 n->larg = $1;
13732 n->rarg = $4;
13733 n->usingClause = NIL;
13734 n->join_using_alias = NULL;
13735 n->quals = NULL;
13736 $$ = n;
13737 }
13738 | table_ref join_type JOIN table_ref join_qual
13739 {
13740 JoinExpr *n = makeNode(JoinExpr);
13741
13742 n->jointype = $2;
13743 n->isNatural = false;
13744 n->larg = $1;
13745 n->rarg = $4;
13746 if ($5 != NULL && IsA($5, List))
13747 {
13748 /* USING clause */
13749 n->usingClause = linitial_node(List, castNode(List, $5));
13750 n->join_using_alias = lsecond_node(Alias, castNode(List, $5));
13751 }
13752 else
13753 {
13754 /* ON clause */
13755 n->quals = $5;
13756 }
13757 $$ = n;
13758 }
13759 | table_ref JOIN table_ref join_qual
13760 {
13761 /* letting join_type reduce to empty doesn't work */
13762 JoinExpr *n = makeNode(JoinExpr);
13763
13764 n->jointype = JOIN_INNER;
13765 n->isNatural = false;
13766 n->larg = $1;
13767 n->rarg = $3;
13768 if ($4 != NULL && IsA($4, List))
13769 {
13770 /* USING clause */
13771 n->usingClause = linitial_node(List, castNode(List, $4));
13772 n->join_using_alias = lsecond_node(Alias, castNode(List, $4));
13773 }
13774 else
13775 {
13776 /* ON clause */
13777 n->quals = $4;
13778 }
13779 $$ = n;
13780 }
13781 | table_ref NATURAL join_type JOIN table_ref
13782 {
13783 JoinExpr *n = makeNode(JoinExpr);
13784
13785 n->jointype = $3;
13786 n->isNatural = true;
13787 n->larg = $1;
13788 n->rarg = $5;
13789 n->usingClause = NIL; /* figure out which columns later... */
13790 n->join_using_alias = NULL;
13791 n->quals = NULL; /* fill later */
13792 $$ = n;
13793 }
13794 | table_ref NATURAL JOIN table_ref
13795 {
13796 /* letting join_type reduce to empty doesn't work */
13797 JoinExpr *n = makeNode(JoinExpr);
13798
13799 n->jointype = JOIN_INNER;
13800 n->isNatural = true;
13801 n->larg = $1;
13802 n->rarg = $4;
13803 n->usingClause = NIL; /* figure out which columns later... */
13804 n->join_using_alias = NULL;
13805 n->quals = NULL; /* fill later */
13806 $$ = n;
13807 }
13808 ;
13809
13810 alias_clause:
13811 AS ColId '(' name_list ')'
13812 {
13813 $$ = makeNode(Alias);
13814 $$->aliasname = $2;
13815 $$->colnames = $4;
13816 }
13817 | AS ColId
13818 {
13819 $$ = makeNode(Alias);
13820 $$->aliasname = $2;
13821 }
13822 | ColId '(' name_list ')'
13823 {
13824 $$ = makeNode(Alias);
13825 $$->aliasname = $1;
13826 $$->colnames = $3;
13827 }
13828 | ColId
13829 {
13830 $$ = makeNode(Alias);
13831 $$->aliasname = $1;
13832 }
13833 ;
13834
13835 opt_alias_clause: alias_clause { $$ = $1; }
13836 | /*EMPTY*/ { $$ = NULL; }
13837 ;
13838
13839 /*
13840 * The alias clause after JOIN ... USING only accepts the AS ColId spelling,
13841 * per SQL standard. (The grammar could parse the other variants, but they
13842 * don't seem to be useful, and it might lead to parser problems in the
13843 * future.)
13844 */
13845 opt_alias_clause_for_join_using:
13846 AS ColId
13847 {
13848 $$ = makeNode(Alias);
13849 $$->aliasname = $2;
13850 /* the column name list will be inserted later */
13851 }
13852 | /*EMPTY*/ { $$ = NULL; }
13853 ;
13854
13855 /*
13856 * func_alias_clause can include both an Alias and a coldeflist, so we make it
13857 * return a 2-element list that gets disassembled by calling production.
13858 */
13859 func_alias_clause:
13860 alias_clause
13861 {
13862 $$ = list_make2($1, NIL);
13863 }
13864 | AS '(' TableFuncElementList ')'
13865 {
13866 $$ = list_make2(NULL, $3);
13867 }
13868 | AS ColId '(' TableFuncElementList ')'
13869 {
13870 Alias *a = makeNode(Alias);
13871
13872 a->aliasname = $2;
13873 $$ = list_make2(a, $4);
13874 }
13875 | ColId '(' TableFuncElementList ')'
13876 {
13877 Alias *a = makeNode(Alias);
13878
13879 a->aliasname = $1;
13880 $$ = list_make2(a, $3);
13881 }
13882 | /*EMPTY*/
13883 {
13884 $$ = list_make2(NULL, NIL);
13885 }
13886 ;
13887
13888 join_type: FULL opt_outer { $$ = JOIN_FULL; }
13889 | LEFT opt_outer { $$ = JOIN_LEFT; }
13890 | RIGHT opt_outer { $$ = JOIN_RIGHT; }
13891 | INNER_P { $$ = JOIN_INNER; }
13892 ;
13893
13894 /* OUTER is just noise... */
13895 opt_outer: OUTER_P
13896 | /*EMPTY*/
13897 ;
13898
13899 /* JOIN qualification clauses
13900 * Possibilities are:
13901 * USING ( column list ) [ AS alias ]
13902 * allows only unqualified column names,
13903 * which must match between tables.
13904 * ON expr allows more general qualifications.
13905 *
13906 * We return USING as a two-element List (the first item being a sub-List
13907 * of the common column names, and the second either an Alias item or NULL).
13908 * An ON-expr will not be a List, so it can be told apart that way.
13909 */
13910
13911 join_qual: USING '(' name_list ')' opt_alias_clause_for_join_using
13912 {
13913 $$ = (Node *) list_make2($3, $5);
13914 }
13915 | ON a_expr
13916 {
13917 $$ = $2;
13918 }
13919 ;
13920
13921
13922 relation_expr:
13923 qualified_name
13924 {
13925 /* inheritance query, implicitly */
13926 $$ = $1;
13927 $$->inh = true;
13928 $$->alias = NULL;
13929 }
13930 | extended_relation_expr
13931 {
13932 $$ = $1;
13933 }
13934 ;
13935
13936 extended_relation_expr:
13937 qualified_name '*'
13938 {
13939 /* inheritance query, explicitly */
13940 $$ = $1;
13941 $$->inh = true;
13942 $$->alias = NULL;
13943 }
13944 | ONLY qualified_name
13945 {
13946 /* no inheritance */
13947 $$ = $2;
13948 $$->inh = false;
13949 $$->alias = NULL;
13950 }
13951 | ONLY '(' qualified_name ')'
13952 {
13953 /* no inheritance, SQL99-style syntax */
13954 $$ = $3;
13955 $$->inh = false;
13956 $$->alias = NULL;
13957 }
13958 ;
13959
13960
13961 relation_expr_list:
13962 relation_expr { $$ = list_make1($1); }
13963 | relation_expr_list ',' relation_expr { $$ = lappend($1, $3); }
13964 ;
13965
13966
13967 /*
13968 * Given "UPDATE foo set set ...", we have to decide without looking any
13969 * further ahead whether the first "set" is an alias or the UPDATE's SET
13970 * keyword. Since "set" is allowed as a column name both interpretations
13971 * are feasible. We resolve the shift/reduce conflict by giving the first
13972 * relation_expr_opt_alias production a higher precedence than the SET token
13973 * has, causing the parser to prefer to reduce, in effect assuming that the
13974 * SET is not an alias.
13975 */
13976 relation_expr_opt_alias: relation_expr %prec UMINUS
13977 {
13978 $$ = $1;
13979 }
13980 | relation_expr ColId
13981 {
13982 Alias *alias = makeNode(Alias);
13983
13984 alias->aliasname = $2;
13985 $1->alias = alias;
13986 $$ = $1;
13987 }
13988 | relation_expr AS ColId
13989 {
13990 Alias *alias = makeNode(Alias);
13991
13992 alias->aliasname = $3;
13993 $1->alias = alias;
13994 $$ = $1;
13995 }
13996 ;
13997
13998 /*
13999 * TABLESAMPLE decoration in a FROM item
14000 */
14001 tablesample_clause:
14002 TABLESAMPLE func_name '(' expr_list ')' opt_repeatable_clause
14003 {
14004 RangeTableSample *n = makeNode(RangeTableSample);
14005
14006 /* n->relation will be filled in later */
14007 n->method = $2;
14008 n->args = $4;
14009 n->repeatable = $6;
14010 n->location = @2;
14011 $$ = (Node *) n;
14012 }
14013 ;
14014
14015 opt_repeatable_clause:
14016 REPEATABLE '(' a_expr ')' { $$ = (Node *) $3; }
14017 | /*EMPTY*/ { $$ = NULL; }
14018 ;
14019
14020 /*
14021 * func_table represents a function invocation in a FROM list. It can be
14022 * a plain function call, like "foo(...)", or a ROWS FROM expression with
14023 * one or more function calls, "ROWS FROM (foo(...), bar(...))",
14024 * optionally with WITH ORDINALITY attached.
14025 * In the ROWS FROM syntax, a column definition list can be given for each
14026 * function, for example:
14027 * ROWS FROM (foo() AS (foo_res_a text, foo_res_b text),
14028 * bar() AS (bar_res_a text, bar_res_b text))
14029 * It's also possible to attach a column definition list to the RangeFunction
14030 * as a whole, but that's handled by the table_ref production.
14031 */
14032 func_table: func_expr_windowless opt_ordinality
14033 {
14034 RangeFunction *n = makeNode(RangeFunction);
14035
14036 n->lateral = false;
14037 n->ordinality = $2;
14038 n->is_rowsfrom = false;
14039 n->functions = list_make1(list_make2($1, NIL));
14040 /* alias and coldeflist are set by table_ref production */
14041 $$ = (Node *) n;
14042 }
14043 | ROWS FROM '(' rowsfrom_list ')' opt_ordinality
14044 {
14045 RangeFunction *n = makeNode(RangeFunction);
14046
14047 n->lateral = false;
14048 n->ordinality = $6;
14049 n->is_rowsfrom = true;
14050 n->functions = $4;
14051 /* alias and coldeflist are set by table_ref production */
14052 $$ = (Node *) n;
14053 }
14054 ;
14055
14056 rowsfrom_item: func_expr_windowless opt_col_def_list
14057 { $$ = list_make2($1, $2); }
14058 ;
14059
14060 rowsfrom_list:
14061 rowsfrom_item { $$ = list_make1($1); }
14062 | rowsfrom_list ',' rowsfrom_item { $$ = lappend($1, $3); }
14063 ;
14064
14065 opt_col_def_list: AS '(' TableFuncElementList ')' { $$ = $3; }
14066 | /*EMPTY*/ { $$ = NIL; }
14067 ;
14068
14069 opt_ordinality: WITH_LA ORDINALITY { $$ = true; }
14070 | /*EMPTY*/ { $$ = false; }
14071 ;
14072
14073
14074 where_clause:
14075 WHERE a_expr { $$ = $2; }
14076 | /*EMPTY*/ { $$ = NULL; }
14077 ;
14078
14079 /* variant for UPDATE and DELETE */
14080 where_or_current_clause:
14081 WHERE a_expr { $$ = $2; }
14082 | WHERE CURRENT_P OF cursor_name
14083 {
14084 CurrentOfExpr *n = makeNode(CurrentOfExpr);
14085
14086 /* cvarno is filled in by parse analysis */
14087 n->cursor_name = $4;
14088 n->cursor_param = 0;
14089 $$ = (Node *) n;
14090 }
14091 | /*EMPTY*/ { $$ = NULL; }
14092 ;
14093
14094
14095 OptTableFuncElementList:
14096 TableFuncElementList { $$ = $1; }
14097 | /*EMPTY*/ { $$ = NIL; }
14098 ;
14099
14100 TableFuncElementList:
14101 TableFuncElement
14102 {
14103 $$ = list_make1($1);
14104 }
14105 | TableFuncElementList ',' TableFuncElement
14106 {
14107 $$ = lappend($1, $3);
14108 }
14109 ;
14110
14111 TableFuncElement: ColId Typename opt_collate_clause
14112 {
14113 ColumnDef *n = makeNode(ColumnDef);
14114
14115 n->colname = $1;
14116 n->typeName = $2;
14117 n->inhcount = 0;
14118 n->is_local = true;
14119 n->is_not_null = false;
14120 n->is_from_type = false;
14121 n->storage = 0;
14122 n->raw_default = NULL;
14123 n->cooked_default = NULL;
14124 n->collClause = (CollateClause *) $3;
14125 n->collOid = InvalidOid;
14126 n->constraints = NIL;
14127 n->location = @1;
14128 $$ = (Node *) n;
14129 }
14130 ;
14131
14132 /*
14133 * XMLTABLE
14134 */
14135 xmltable:
14136 XMLTABLE '(' c_expr xmlexists_argument COLUMNS xmltable_column_list ')'
14137 {
14138 RangeTableFunc *n = makeNode(RangeTableFunc);
14139
14140 n->rowexpr = $3;
14141 n->docexpr = $4;
14142 n->columns = $6;
14143 n->namespaces = NIL;
14144 n->location = @1;
14145 $$ = (Node *) n;
14146 }
14147 | XMLTABLE '(' XMLNAMESPACES '(' xml_namespace_list ')' ','
14148 c_expr xmlexists_argument COLUMNS xmltable_column_list ')'
14149 {
14150 RangeTableFunc *n = makeNode(RangeTableFunc);
14151
14152 n->rowexpr = $8;
14153 n->docexpr = $9;
14154 n->columns = $11;
14155 n->namespaces = $5;
14156 n->location = @1;
14157 $$ = (Node *) n;
14158 }
14159 ;
14160
14161 xmltable_column_list: xmltable_column_el { $$ = list_make1($1); }
14162 | xmltable_column_list ',' xmltable_column_el { $$ = lappend($1, $3); }
14163 ;
14164
14165 xmltable_column_el:
14166 ColId Typename
14167 {
14168 RangeTableFuncCol *fc = makeNode(RangeTableFuncCol);
14169
14170 fc->colname = $1;
14171 fc->for_ordinality = false;
14172 fc->typeName = $2;
14173 fc->is_not_null = false;
14174 fc->colexpr = NULL;
14175 fc->coldefexpr = NULL;
14176 fc->location = @1;
14177
14178 $$ = (Node *) fc;
14179 }
14180 | ColId Typename xmltable_column_option_list
14181 {
14182 RangeTableFuncCol *fc = makeNode(RangeTableFuncCol);
14183 ListCell *option;
14184 bool nullability_seen = false;
14185
14186 fc->colname = $1;
14187 fc->typeName = $2;
14188 fc->for_ordinality = false;
14189 fc->is_not_null = false;
14190 fc->colexpr = NULL;
14191 fc->coldefexpr = NULL;
14192 fc->location = @1;
14193
14194 foreach(option, $3)
14195 {
14196 DefElem *defel = (DefElem *) lfirst(option);
14197
14198 if (strcmp(defel->defname, "default") == 0)
14199 {
14200 if (fc->coldefexpr != NULL)
14201 ereport(ERROR,
14202 (errcode(ERRCODE_SYNTAX_ERROR),
14203 errmsg("only one DEFAULT value is allowed"),
14204 parser_errposition(defel->location)));
14205 fc->coldefexpr = defel->arg;
14206 }
14207 else if (strcmp(defel->defname, "path") == 0)
14208 {
14209 if (fc->colexpr != NULL)
14210 ereport(ERROR,
14211 (errcode(ERRCODE_SYNTAX_ERROR),
14212 errmsg("only one PATH value per column is allowed"),
14213 parser_errposition(defel->location)));
14214 fc->colexpr = defel->arg;
14215 }
14216 else if (strcmp(defel->defname, "__pg__is_not_null") == 0)
14217 {
14218 if (nullability_seen)
14219 ereport(ERROR,
14220 (errcode(ERRCODE_SYNTAX_ERROR),
14221 errmsg("conflicting or redundant NULL / NOT NULL declarations for column \"%s\"", fc->colname),
14222 parser_errposition(defel->location)));
14223 fc->is_not_null = boolVal(defel->arg);
14224 nullability_seen = true;
14225 }
14226 else
14227 {
14228 ereport(ERROR,
14229 (errcode(ERRCODE_SYNTAX_ERROR),
14230 errmsg("unrecognized column option \"%s\"",
14231 defel->defname),
14232 parser_errposition(defel->location)));
14233 }
14234 }
14235 $$ = (Node *) fc;
14236 }
14237 | ColId FOR ORDINALITY
14238 {
14239 RangeTableFuncCol *fc = makeNode(RangeTableFuncCol);
14240
14241 fc->colname = $1;
14242 fc->for_ordinality = true;
14243 /* other fields are ignored, initialized by makeNode */
14244 fc->location = @1;
14245
14246 $$ = (Node *) fc;
14247 }
14248 ;
14249
14250 xmltable_column_option_list:
14251 xmltable_column_option_el
14252 { $$ = list_make1($1); }
14253 | xmltable_column_option_list xmltable_column_option_el
14254 { $$ = lappend($1, $2); }
14255 ;
14256
14257 xmltable_column_option_el:
14258 IDENT b_expr
14259 {
14260 if (strcmp($1, "__pg__is_not_null") == 0)
14261 ereport(ERROR,
14262 (errcode(ERRCODE_SYNTAX_ERROR),
14263 errmsg("option name \"%s\" cannot be used in XMLTABLE", $1),
14264 parser_errposition(@1)));
14265 $$ = makeDefElem($1, $2, @1);
14266 }
14267 | DEFAULT b_expr
14268 { $$ = makeDefElem("default", $2, @1); }
14269 | NOT NULL_P
14270 { $$ = makeDefElem("__pg__is_not_null", (Node *) makeBoolean(true), @1); }
14271 | NULL_P
14272 { $$ = makeDefElem("__pg__is_not_null", (Node *) makeBoolean(false), @1); }
14273 | PATH b_expr
14274 { $$ = makeDefElem("path", $2, @1); }
14275 ;
14276
14277 xml_namespace_list:
14278 xml_namespace_el
14279 { $$ = list_make1($1); }
14280 | xml_namespace_list ',' xml_namespace_el
14281 { $$ = lappend($1, $3); }
14282 ;
14283
14284 xml_namespace_el:
14285 b_expr AS ColLabel
14286 {
14287 $$ = makeNode(ResTarget);
14288 $$->name = $3;
14289 $$->indirection = NIL;
14290 $$->val = $1;
14291 $$->location = @1;
14292 }
14293 | DEFAULT b_expr
14294 {
14295 $$ = makeNode(ResTarget);
14296 $$->name = NULL;
14297 $$->indirection = NIL;
14298 $$->val = $2;
14299 $$->location = @1;
14300 }
14301 ;
14302
14303 json_table:
14304 JSON_TABLE '('
14305 json_value_expr ',' a_expr json_table_path_name_opt
14306 json_passing_clause_opt
14307 COLUMNS '(' json_table_column_definition_list ')'
14308 json_on_error_clause_opt
14309 ')'
14310 {
14311 JsonTable *n = makeNode(JsonTable);
14312 char *pathstring;
14313
14314 n->context_item = (JsonValueExpr *) $3;
14315 if (!IsA($5, A_Const) ||
14316 castNode(A_Const, $5)->val.node.type != T_String)
14317 ereport(ERROR,
14318 errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
14319 errmsg("only string constants are supported in JSON_TABLE path specification"),
14320 parser_errposition(@5));
14321 pathstring = castNode(A_Const, $5)->val.sval.sval;
14322 n->pathspec = makeJsonTablePathSpec(pathstring, $6, @5, @6);
14323 n->passing = $7;
14324 n->columns = $10;
14325 n->on_error = (JsonBehavior *) $12;
14326 n->location = @1;
14327 $$ = (Node *) n;
14328 }
14329 ;
14330
14331 json_table_path_name_opt:
14332 AS name { $$ = $2; }
14333 | /* empty */ { $$ = NULL; }
14334 ;
14335
14336 json_table_column_definition_list:
14337 json_table_column_definition
14338 { $$ = list_make1($1); }
14339 | json_table_column_definition_list ',' json_table_column_definition
14340 { $$ = lappend($1, $3); }
14341 ;
14342
14343 json_table_column_definition:
14344 ColId FOR ORDINALITY
14345 {
14346 JsonTableColumn *n = makeNode(JsonTableColumn);
14347
14348 n->coltype = JTC_FOR_ORDINALITY;
14349 n->name = $1;
14350 n->location = @1;
14351 $$ = (Node *) n;
14352 }
14353 | ColId Typename
14354 json_table_column_path_clause_opt
14355 json_wrapper_behavior
14356 json_quotes_clause_opt
14357 json_behavior_clause_opt
14358 {
14359 JsonTableColumn *n = makeNode(JsonTableColumn);
14360
14361 n->coltype = JTC_REGULAR;
14362 n->name = $1;
14363 n->typeName = $2;
14364 n->format = makeJsonFormat(JS_FORMAT_DEFAULT, JS_ENC_DEFAULT, -1);
14365 n->pathspec = (JsonTablePathSpec *) $3;
14366 n->wrapper = $4;
14367 n->quotes = $5;
14368 n->on_empty = (JsonBehavior *) linitial($6);
14369 n->on_error = (JsonBehavior *) lsecond($6);
14370 n->location = @1;
14371 $$ = (Node *) n;
14372 }
14373 | ColId Typename json_format_clause
14374 json_table_column_path_clause_opt
14375 json_wrapper_behavior
14376 json_quotes_clause_opt
14377 json_behavior_clause_opt
14378 {
14379 JsonTableColumn *n = makeNode(JsonTableColumn);
14380
14381 n->coltype = JTC_FORMATTED;
14382 n->name = $1;
14383 n->typeName = $2;
14384 n->format = (JsonFormat *) $3;
14385 n->pathspec = (JsonTablePathSpec *) $4;
14386 n->wrapper = $5;
14387 n->quotes = $6;
14388 n->on_empty = (JsonBehavior *) linitial($7);
14389 n->on_error = (JsonBehavior *) lsecond($7);
14390 n->location = @1;
14391 $$ = (Node *) n;
14392 }
14393 | ColId Typename
14394 EXISTS json_table_column_path_clause_opt
14395 json_on_error_clause_opt
14396 {
14397 JsonTableColumn *n = makeNode(JsonTableColumn);
14398
14399 n->coltype = JTC_EXISTS;
14400 n->name = $1;
14401 n->typeName = $2;
14402 n->format = makeJsonFormat(JS_FORMAT_DEFAULT, JS_ENC_DEFAULT, -1);
14403 n->wrapper = JSW_NONE;
14404 n->quotes = JS_QUOTES_UNSPEC;
14405 n->pathspec = (JsonTablePathSpec *) $4;
14406 n->on_empty = NULL;
14407 n->on_error = (JsonBehavior *) $5;
14408 n->location = @1;
14409 $$ = (Node *) n;
14410 }
14411 | NESTED path_opt Sconst
14412 COLUMNS '(' json_table_column_definition_list ')'
14413 {
14414 JsonTableColumn *n = makeNode(JsonTableColumn);
14415
14416 n->coltype = JTC_NESTED;
14417 n->pathspec = (JsonTablePathSpec *)
14418 makeJsonTablePathSpec($3, NULL, @3, -1);
14419 n->columns = $6;
14420 n->location = @1;
14421 $$ = (Node *) n;
14422 }
14423 | NESTED path_opt Sconst AS name
14424 COLUMNS '(' json_table_column_definition_list ')'
14425 {
14426 JsonTableColumn *n = makeNode(JsonTableColumn);
14427
14428 n->coltype = JTC_NESTED;
14429 n->pathspec = (JsonTablePathSpec *)
14430 makeJsonTablePathSpec($3, $5, @3, @5);
14431 n->columns = $8;
14432 n->location = @1;
14433 $$ = (Node *) n;
14434 }
14435 ;
14436
14437 path_opt:
14438 PATH
14439 | /* EMPTY */
14440 ;
14441
14442 json_table_column_path_clause_opt:
14443 PATH Sconst
14444 { $$ = (Node *) makeJsonTablePathSpec($2, NULL, @2, -1); }
14445 | /* EMPTY */
14446 { $$ = NULL; }
14447 ;
14448
14449 /*****************************************************************************
14450 *
14451 * Type syntax
14452 * SQL introduces a large amount of type-specific syntax.
14453 * Define individual clauses to handle these cases, and use
14454 * the generic case to handle regular type-extensible Postgres syntax.
14455 * - thomas 1997-10-10
14456 *
14457 *****************************************************************************/
14458
14459 Typename: SimpleTypename opt_array_bounds
14460 {
14461 $$ = $1;
14462 $$->arrayBounds = $2;
14463 }
14464 | SETOF SimpleTypename opt_array_bounds
14465 {
14466 $$ = $2;
14467 $$->arrayBounds = $3;
14468 $$->setof = true;
14469 }
14470 /* SQL standard syntax, currently only one-dimensional */
14471 | SimpleTypename ARRAY '[' Iconst ']'
14472 {
14473 $$ = $1;
14474 $$->arrayBounds = list_make1(makeInteger($4));
14475 }
14476 | SETOF SimpleTypename ARRAY '[' Iconst ']'
14477 {
14478 $$ = $2;
14479 $$->arrayBounds = list_make1(makeInteger($5));
14480 $$->setof = true;
14481 }
14482 | SimpleTypename ARRAY
14483 {
14484 $$ = $1;
14485 $$->arrayBounds = list_make1(makeInteger(-1));
14486 }
14487 | SETOF SimpleTypename ARRAY
14488 {
14489 $$ = $2;
14490 $$->arrayBounds = list_make1(makeInteger(-1));
14491 $$->setof = true;
14492 }
14493 ;
14494
14495 opt_array_bounds:
14496 opt_array_bounds '[' ']'
14497 { $$ = lappend($1, makeInteger(-1)); }
14498 | opt_array_bounds '[' Iconst ']'
14499 { $$ = lappend($1, makeInteger($3)); }
14500 | /*EMPTY*/
14501 { $$ = NIL; }
14502 ;
14503
14504 SimpleTypename:
14505 GenericType { $$ = $1; }
14506 | Numeric { $$ = $1; }
14507 | Bit { $$ = $1; }
14508 | Character { $$ = $1; }
14509 | ConstDatetime { $$ = $1; }
14510 | ConstInterval opt_interval
14511 {
14512 $$ = $1;
14513 $$->typmods = $2;
14514 }
14515 | ConstInterval '(' Iconst ')'
14516 {
14517 $$ = $1;
14518 $$->typmods = list_make2(makeIntConst(INTERVAL_FULL_RANGE, -1),
14519 makeIntConst($3, @3));
14520 }
14521 | JsonType { $$ = $1; }
14522 ;
14523
14524 /* We have a separate ConstTypename to allow defaulting fixed-length
14525 * types such as CHAR() and BIT() to an unspecified length.
14526 * SQL9x requires that these default to a length of one, but this
14527 * makes no sense for constructs like CHAR 'hi' and BIT '0101',
14528 * where there is an obvious better choice to make.
14529 * Note that ConstInterval is not included here since it must
14530 * be pushed up higher in the rules to accommodate the postfix
14531 * options (e.g. INTERVAL '1' YEAR). Likewise, we have to handle
14532 * the generic-type-name case in AexprConst to avoid premature
14533 * reduce/reduce conflicts against function names.
14534 */
14535 ConstTypename:
14536 Numeric { $$ = $1; }
14537 | ConstBit { $$ = $1; }
14538 | ConstCharacter { $$ = $1; }
14539 | ConstDatetime { $$ = $1; }
14540 | JsonType { $$ = $1; }
14541 ;
14542
14543 /*
14544 * GenericType covers all type names that don't have special syntax mandated
14545 * by the standard, including qualified names. We also allow type modifiers.
14546 * To avoid parsing conflicts against function invocations, the modifiers
14547 * have to be shown as expr_list here, but parse analysis will only accept
14548 * constants for them.
14549 */
14550 GenericType:
14551 type_function_name opt_type_modifiers
14552 {
14553 $$ = makeTypeName($1);
14554 $$->typmods = $2;
14555 $$->location = @1;
14556 }
14557 | type_function_name attrs opt_type_modifiers
14558 {
14559 $$ = makeTypeNameFromNameList(lcons(makeString($1), $2));
14560 $$->typmods = $3;
14561 $$->location = @1;
14562 }
14563 ;
14564
14565 opt_type_modifiers: '(' expr_list ')' { $$ = $2; }
14566 | /* EMPTY */ { $$ = NIL; }
14567 ;
14568
14569 /*
14570 * SQL numeric data types
14571 */
14572 Numeric: INT_P
14573 {
14574 $$ = SystemTypeName("int4");
14575 $$->location = @1;
14576 }
14577 | INTEGER
14578 {
14579 $$ = SystemTypeName("int4");
14580 $$->location = @1;
14581 }
14582 | SMALLINT
14583 {
14584 $$ = SystemTypeName("int2");
14585 $$->location = @1;
14586 }
14587 | BIGINT
14588 {
14589 $$ = SystemTypeName("int8");
14590 $$->location = @1;
14591 }
14592 | REAL
14593 {
14594 $$ = SystemTypeName("float4");
14595 $$->location = @1;
14596 }
14597 | FLOAT_P opt_float
14598 {
14599 $$ = $2;
14600 $$->location = @1;
14601 }
14602 | DOUBLE_P PRECISION
14603 {
14604 $$ = SystemTypeName("float8");
14605 $$->location = @1;
14606 }
14607 | DECIMAL_P opt_type_modifiers
14608 {
14609 $$ = SystemTypeName("numeric");
14610 $$->typmods = $2;
14611 $$->location = @1;
14612 }
14613 | DEC opt_type_modifiers
14614 {
14615 $$ = SystemTypeName("numeric");
14616 $$->typmods = $2;
14617 $$->location = @1;
14618 }
14619 | NUMERIC opt_type_modifiers
14620 {
14621 $$ = SystemTypeName("numeric");
14622 $$->typmods = $2;
14623 $$->location = @1;
14624 }
14625 | BOOLEAN_P
14626 {
14627 $$ = SystemTypeName("bool");
14628 $$->location = @1;
14629 }
14630 ;
14631
14632 opt_float: '(' Iconst ')'
14633 {
14634 /*
14635 * Check FLOAT() precision limits assuming IEEE floating
14636 * types - thomas 1997-09-18
14637 */
14638 if ($2 < 1)
14639 ereport(ERROR,
14640 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
14641 errmsg("precision for type float must be at least 1 bit"),
14642 parser_errposition(@2)));
14643 else if ($2 <= 24)
14644 $$ = SystemTypeName("float4");
14645 else if ($2 <= 53)
14646 $$ = SystemTypeName("float8");
14647 else
14648 ereport(ERROR,
14649 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
14650 errmsg("precision for type float must be less than 54 bits"),
14651 parser_errposition(@2)));
14652 }
14653 | /*EMPTY*/
14654 {
14655 $$ = SystemTypeName("float8");
14656 }
14657 ;
14658
14659 /*
14660 * SQL bit-field data types
14661 * The following implements BIT() and BIT VARYING().
14662 */
14663 Bit: BitWithLength
14664 {
14665 $$ = $1;
14666 }
14667 | BitWithoutLength
14668 {
14669 $$ = $1;
14670 }
14671 ;
14672
14673 /* ConstBit is like Bit except "BIT" defaults to unspecified length */
14674 /* See notes for ConstCharacter, which addresses same issue for "CHAR" */
14675 ConstBit: BitWithLength
14676 {
14677 $$ = $1;
14678 }
14679 | BitWithoutLength
14680 {
14681 $$ = $1;
14682 $$->typmods = NIL;
14683 }
14684 ;
14685
14686 BitWithLength:
14687 BIT opt_varying '(' expr_list ')'
14688 {
14689 char *typname;
14690
14691 typname = $2 ? "varbit" : "bit";
14692 $$ = SystemTypeName(typname);
14693 $$->typmods = $4;
14694 $$->location = @1;
14695 }
14696 ;
14697
14698 BitWithoutLength:
14699 BIT opt_varying
14700 {
14701 /* bit defaults to bit(1), varbit to no limit */
14702 if ($2)
14703 {
14704 $$ = SystemTypeName("varbit");
14705 }
14706 else
14707 {
14708 $$ = SystemTypeName("bit");
14709 $$->typmods = list_make1(makeIntConst(1, -1));
14710 }
14711 $$->location = @1;
14712 }
14713 ;
14714
14715
14716 /*
14717 * SQL character data types
14718 * The following implements CHAR() and VARCHAR().
14719 */
14720 Character: CharacterWithLength
14721 {
14722 $$ = $1;
14723 }
14724 | CharacterWithoutLength
14725 {
14726 $$ = $1;
14727 }
14728 ;
14729
14730 ConstCharacter: CharacterWithLength
14731 {
14732 $$ = $1;
14733 }
14734 | CharacterWithoutLength
14735 {
14736 /* Length was not specified so allow to be unrestricted.
14737 * This handles problems with fixed-length (bpchar) strings
14738 * which in column definitions must default to a length
14739 * of one, but should not be constrained if the length
14740 * was not specified.
14741 */
14742 $$ = $1;
14743 $$->typmods = NIL;
14744 }
14745 ;
14746
14747 CharacterWithLength: character '(' Iconst ')'
14748 {
14749 $$ = SystemTypeName($1);
14750 $$->typmods = list_make1(makeIntConst($3, @3));
14751 $$->location = @1;
14752 }
14753 ;
14754
14755 CharacterWithoutLength: character
14756 {
14757 $$ = SystemTypeName($1);
14758 /* char defaults to char(1), varchar to no limit */
14759 if (strcmp($1, "bpchar") == 0)
14760 $$->typmods = list_make1(makeIntConst(1, -1));
14761 $$->location = @1;
14762 }
14763 ;
14764
14765 character: CHARACTER opt_varying
14766 { $$ = $2 ? "varchar": "bpchar"; }
14767 | CHAR_P opt_varying
14768 { $$ = $2 ? "varchar": "bpchar"; }
14769 | VARCHAR
14770 { $$ = "varchar"; }
14771 | NATIONAL CHARACTER opt_varying
14772 { $$ = $3 ? "varchar": "bpchar"; }
14773 | NATIONAL CHAR_P opt_varying
14774 { $$ = $3 ? "varchar": "bpchar"; }
14775 | NCHAR opt_varying
14776 { $$ = $2 ? "varchar": "bpchar"; }
14777 ;
14778
14779 opt_varying:
14780 VARYING { $$ = true; }
14781 | /*EMPTY*/ { $$ = false; }
14782 ;
14783
14784 /*
14785 * SQL date/time types
14786 */
14787 ConstDatetime:
14788 TIMESTAMP '(' Iconst ')' opt_timezone
14789 {
14790 if ($5)
14791 $$ = SystemTypeName("timestamptz");
14792 else
14793 $$ = SystemTypeName("timestamp");
14794 $$->typmods = list_make1(makeIntConst($3, @3));
14795 $$->location = @1;
14796 }
14797 | TIMESTAMP opt_timezone
14798 {
14799 if ($2)
14800 $$ = SystemTypeName("timestamptz");
14801 else
14802 $$ = SystemTypeName("timestamp");
14803 $$->location = @1;
14804 }
14805 | TIME '(' Iconst ')' opt_timezone
14806 {
14807 if ($5)
14808 $$ = SystemTypeName("timetz");
14809 else
14810 $$ = SystemTypeName("time");
14811 $$->typmods = list_make1(makeIntConst($3, @3));
14812 $$->location = @1;
14813 }
14814 | TIME opt_timezone
14815 {
14816 if ($2)
14817 $$ = SystemTypeName("timetz");
14818 else
14819 $$ = SystemTypeName("time");
14820 $$->location = @1;
14821 }
14822 ;
14823
14824 ConstInterval:
14825 INTERVAL
14826 {
14827 $$ = SystemTypeName("interval");
14828 $$->location = @1;
14829 }
14830 ;
14831
14832 opt_timezone:
14833 WITH_LA TIME ZONE { $$ = true; }
14834 | WITHOUT_LA TIME ZONE { $$ = false; }
14835 | /*EMPTY*/ { $$ = false; }
14836 ;
14837
14838 opt_interval:
14839 YEAR_P
14840 { $$ = list_make1(makeIntConst(INTERVAL_MASK(YEAR), @1)); }
14841 | MONTH_P
14842 { $$ = list_make1(makeIntConst(INTERVAL_MASK(MONTH), @1)); }
14843 | DAY_P
14844 { $$ = list_make1(makeIntConst(INTERVAL_MASK(DAY), @1)); }
14845 | HOUR_P
14846 { $$ = list_make1(makeIntConst(INTERVAL_MASK(HOUR), @1)); }
14847 | MINUTE_P
14848 { $$ = list_make1(makeIntConst(INTERVAL_MASK(MINUTE), @1)); }
14849 | interval_second
14850 { $$ = $1; }
14851 | YEAR_P TO MONTH_P
14852 {
14853 $$ = list_make1(makeIntConst(INTERVAL_MASK(YEAR) |
14854 INTERVAL_MASK(MONTH), @1));
14855 }
14856 | DAY_P TO HOUR_P
14857 {
14858 $$ = list_make1(makeIntConst(INTERVAL_MASK(DAY) |
14859 INTERVAL_MASK(HOUR), @1));
14860 }
14861 | DAY_P TO MINUTE_P
14862 {
14863 $$ = list_make1(makeIntConst(INTERVAL_MASK(DAY) |
14864 INTERVAL_MASK(HOUR) |
14865 INTERVAL_MASK(MINUTE), @1));
14866 }
14867 | DAY_P TO interval_second
14868 {
14869 $$ = $3;
14870 linitial($$) = makeIntConst(INTERVAL_MASK(DAY) |
14871 INTERVAL_MASK(HOUR) |
14872 INTERVAL_MASK(MINUTE) |
14873 INTERVAL_MASK(SECOND), @1);
14874 }
14875 | HOUR_P TO MINUTE_P
14876 {
14877 $$ = list_make1(makeIntConst(INTERVAL_MASK(HOUR) |
14878 INTERVAL_MASK(MINUTE), @1));
14879 }
14880 | HOUR_P TO interval_second
14881 {
14882 $$ = $3;
14883 linitial($$) = makeIntConst(INTERVAL_MASK(HOUR) |
14884 INTERVAL_MASK(MINUTE) |
14885 INTERVAL_MASK(SECOND), @1);
14886 }
14887 | MINUTE_P TO interval_second
14888 {
14889 $$ = $3;
14890 linitial($$) = makeIntConst(INTERVAL_MASK(MINUTE) |
14891 INTERVAL_MASK(SECOND), @1);
14892 }
14893 | /*EMPTY*/
14894 { $$ = NIL; }
14895 ;
14896
14897 interval_second:
14898 SECOND_P
14899 {
14900 $$ = list_make1(makeIntConst(INTERVAL_MASK(SECOND), @1));
14901 }
14902 | SECOND_P '(' Iconst ')'
14903 {
14904 $$ = list_make2(makeIntConst(INTERVAL_MASK(SECOND), @1),
14905 makeIntConst($3, @3));
14906 }
14907 ;
14908
14909 JsonType:
14910 JSON
14911 {
14912 $$ = SystemTypeName("json");
14913 $$->location = @1;
14914 }
14915 ;
14916
14917 /*****************************************************************************
14918 *
14919 * expression grammar
14920 *
14921 *****************************************************************************/
14922
14923 /*
14924 * General expressions
14925 * This is the heart of the expression syntax.
14926 *
14927 * We have two expression types: a_expr is the unrestricted kind, and
14928 * b_expr is a subset that must be used in some places to avoid shift/reduce
14929 * conflicts. For example, we can't do BETWEEN as "BETWEEN a_expr AND a_expr"
14930 * because that use of AND conflicts with AND as a boolean operator. So,
14931 * b_expr is used in BETWEEN and we remove boolean keywords from b_expr.
14932 *
14933 * Note that '(' a_expr ')' is a b_expr, so an unrestricted expression can
14934 * always be used by surrounding it with parens.
14935 *
14936 * c_expr is all the productions that are common to a_expr and b_expr;
14937 * it's factored out just to eliminate redundant coding.
14938 *
14939 * Be careful of productions involving more than one terminal token.
14940 * By default, bison will assign such productions the precedence of their
14941 * last terminal, but in nearly all cases you want it to be the precedence
14942 * of the first terminal instead; otherwise you will not get the behavior
14943 * you expect! So we use %prec annotations freely to set precedences.
14944 */
14945 a_expr: c_expr { $$ = $1; }
14946 | a_expr TYPECAST Typename
14947 { $$ = makeTypeCast($1, $3, @2); }
14948 | a_expr COLLATE any_name
14949 {
14950 CollateClause *n = makeNode(CollateClause);
14951
14952 n->arg = $1;
14953 n->collname = $3;
14954 n->location = @2;
14955 $$ = (Node *) n;
14956 }
14957 | a_expr AT TIME ZONE a_expr %prec AT
14958 {
14959 $$ = (Node *) makeFuncCall(SystemFuncName("timezone"),
14960 list_make2($5, $1),
14961 COERCE_SQL_SYNTAX,
14962 @2);
14963 }
14964 | a_expr AT LOCAL %prec AT
14965 {
14966 $$ = (Node *) makeFuncCall(SystemFuncName("timezone"),
14967 list_make1($1),
14968 COERCE_SQL_SYNTAX,
14969 -1);
14970 }
14971 /*
14972 * These operators must be called out explicitly in order to make use
14973 * of bison's automatic operator-precedence handling. All other
14974 * operator names are handled by the generic productions using "Op",
14975 * below; and all those operators will have the same precedence.
14976 *
14977 * If you add more explicitly-known operators, be sure to add them
14978 * also to b_expr and to the MathOp list below.
14979 */
14980 | '+' a_expr %prec UMINUS
14981 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "+", NULL, $2, @1); }
14982 | '-' a_expr %prec UMINUS
14983 { $$ = doNegate($2, @1); }
14984 | a_expr '+' a_expr
14985 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "+", $1, $3, @2); }
14986 | a_expr '-' a_expr
14987 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "-", $1, $3, @2); }
14988 | a_expr '*' a_expr
14989 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "*", $1, $3, @2); }
14990 | a_expr '/' a_expr
14991 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "/", $1, $3, @2); }
14992 | a_expr '%' a_expr
14993 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "%", $1, $3, @2); }
14994 | a_expr '^' a_expr
14995 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "^", $1, $3, @2); }
14996 | a_expr '<' a_expr
14997 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "<", $1, $3, @2); }
14998 | a_expr '>' a_expr
14999 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, ">", $1, $3, @2); }
15000 | a_expr '=' a_expr
15001 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "=", $1, $3, @2); }
15002 | a_expr LESS_EQUALS a_expr
15003 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "<=", $1, $3, @2); }
15004 | a_expr GREATER_EQUALS a_expr
15005 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, ">=", $1, $3, @2); }
15006 | a_expr NOT_EQUALS a_expr
15007 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "<>", $1, $3, @2); }
15008
15009 | a_expr qual_Op a_expr %prec Op
15010 { $$ = (Node *) makeA_Expr(AEXPR_OP, $2, $1, $3, @2); }
15011 | qual_Op a_expr %prec Op
15012 { $$ = (Node *) makeA_Expr(AEXPR_OP, $1, NULL, $2, @1); }
15013
15014 | a_expr AND a_expr
15015 { $$ = makeAndExpr($1, $3, @2); }
15016 | a_expr OR a_expr
15017 { $$ = makeOrExpr($1, $3, @2); }
15018 | NOT a_expr
15019 { $$ = makeNotExpr($2, @1); }
15020 | NOT_LA a_expr %prec NOT
15021 { $$ = makeNotExpr($2, @1); }
15022
15023 | a_expr LIKE a_expr
15024 {
15025 $$ = (Node *) makeSimpleA_Expr(AEXPR_LIKE, "~~",
15026 $1, $3, @2);
15027 }
15028 | a_expr LIKE a_expr ESCAPE a_expr %prec LIKE
15029 {
15030 FuncCall *n = makeFuncCall(SystemFuncName("like_escape"),
15031 list_make2($3, $5),
15032 COERCE_EXPLICIT_CALL,
15033 @2);
15034 $$ = (Node *) makeSimpleA_Expr(AEXPR_LIKE, "~~",
15035 $1, (Node *) n, @2);
15036 }
15037 | a_expr NOT_LA LIKE a_expr %prec NOT_LA
15038 {
15039 $$ = (Node *) makeSimpleA_Expr(AEXPR_LIKE, "!~~",
15040 $1, $4, @2);
15041 }
15042 | a_expr NOT_LA LIKE a_expr ESCAPE a_expr %prec NOT_LA
15043 {
15044 FuncCall *n = makeFuncCall(SystemFuncName("like_escape"),
15045 list_make2($4, $6),
15046 COERCE_EXPLICIT_CALL,
15047 @2);
15048 $$ = (Node *) makeSimpleA_Expr(AEXPR_LIKE, "!~~",
15049 $1, (Node *) n, @2);
15050 }
15051 | a_expr ILIKE a_expr
15052 {
15053 $$ = (Node *) makeSimpleA_Expr(AEXPR_ILIKE, "~~*",
15054 $1, $3, @2);
15055 }
15056 | a_expr ILIKE a_expr ESCAPE a_expr %prec ILIKE
15057 {
15058 FuncCall *n = makeFuncCall(SystemFuncName("like_escape"),
15059 list_make2($3, $5),
15060 COERCE_EXPLICIT_CALL,
15061 @2);
15062 $$ = (Node *) makeSimpleA_Expr(AEXPR_ILIKE, "~~*",
15063 $1, (Node *) n, @2);
15064 }
15065 | a_expr NOT_LA ILIKE a_expr %prec NOT_LA
15066 {
15067 $$ = (Node *) makeSimpleA_Expr(AEXPR_ILIKE, "!~~*",
15068 $1, $4, @2);
15069 }
15070 | a_expr NOT_LA ILIKE a_expr ESCAPE a_expr %prec NOT_LA
15071 {
15072 FuncCall *n = makeFuncCall(SystemFuncName("like_escape"),
15073 list_make2($4, $6),
15074 COERCE_EXPLICIT_CALL,
15075 @2);
15076 $$ = (Node *) makeSimpleA_Expr(AEXPR_ILIKE, "!~~*",
15077 $1, (Node *) n, @2);
15078 }
15079
15080 | a_expr SIMILAR TO a_expr %prec SIMILAR
15081 {
15082 FuncCall *n = makeFuncCall(SystemFuncName("similar_to_escape"),
15083 list_make1($4),
15084 COERCE_EXPLICIT_CALL,
15085 @2);
15086 $$ = (Node *) makeSimpleA_Expr(AEXPR_SIMILAR, "~",
15087 $1, (Node *) n, @2);
15088 }
15089 | a_expr SIMILAR TO a_expr ESCAPE a_expr %prec SIMILAR
15090 {
15091 FuncCall *n = makeFuncCall(SystemFuncName("similar_to_escape"),
15092 list_make2($4, $6),
15093 COERCE_EXPLICIT_CALL,
15094 @2);
15095 $$ = (Node *) makeSimpleA_Expr(AEXPR_SIMILAR, "~",
15096 $1, (Node *) n, @2);
15097 }
15098 | a_expr NOT_LA SIMILAR TO a_expr %prec NOT_LA
15099 {
15100 FuncCall *n = makeFuncCall(SystemFuncName("similar_to_escape"),
15101 list_make1($5),
15102 COERCE_EXPLICIT_CALL,
15103 @2);
15104 $$ = (Node *) makeSimpleA_Expr(AEXPR_SIMILAR, "!~",
15105 $1, (Node *) n, @2);
15106 }
15107 | a_expr NOT_LA SIMILAR TO a_expr ESCAPE a_expr %prec NOT_LA
15108 {
15109 FuncCall *n = makeFuncCall(SystemFuncName("similar_to_escape"),
15110 list_make2($5, $7),
15111 COERCE_EXPLICIT_CALL,
15112 @2);
15113 $$ = (Node *) makeSimpleA_Expr(AEXPR_SIMILAR, "!~",
15114 $1, (Node *) n, @2);
15115 }
15116
15117 /* NullTest clause
15118 * Define SQL-style Null test clause.
15119 * Allow two forms described in the standard:
15120 * a IS NULL
15121 * a IS NOT NULL
15122 * Allow two SQL extensions
15123 * a ISNULL
15124 * a NOTNULL
15125 */
15126 | a_expr IS NULL_P %prec IS
15127 {
15128 NullTest *n = makeNode(NullTest);
15129
15130 n->arg = (Expr *) $1;
15131 n->nulltesttype = IS_NULL;
15132 n->location = @2;
15133 $$ = (Node *) n;
15134 }
15135 | a_expr ISNULL
15136 {
15137 NullTest *n = makeNode(NullTest);
15138
15139 n->arg = (Expr *) $1;
15140 n->nulltesttype = IS_NULL;
15141 n->location = @2;
15142 $$ = (Node *) n;
15143 }
15144 | a_expr IS NOT NULL_P %prec IS
15145 {
15146 NullTest *n = makeNode(NullTest);
15147
15148 n->arg = (Expr *) $1;
15149 n->nulltesttype = IS_NOT_NULL;
15150 n->location = @2;
15151 $$ = (Node *) n;
15152 }
15153 | a_expr NOTNULL
15154 {
15155 NullTest *n = makeNode(NullTest);
15156
15157 n->arg = (Expr *) $1;
15158 n->nulltesttype = IS_NOT_NULL;
15159 n->location = @2;
15160 $$ = (Node *) n;
15161 }
15162 | row OVERLAPS row
15163 {
15164 if (list_length($1) != 2)
15165 ereport(ERROR,
15166 (errcode(ERRCODE_SYNTAX_ERROR),
15167 errmsg("wrong number of parameters on left side of OVERLAPS expression"),
15168 parser_errposition(@1)));
15169 if (list_length($3) != 2)
15170 ereport(ERROR,
15171 (errcode(ERRCODE_SYNTAX_ERROR),
15172 errmsg("wrong number of parameters on right side of OVERLAPS expression"),
15173 parser_errposition(@3)));
15174 $$ = (Node *) makeFuncCall(SystemFuncName("overlaps"),
15175 list_concat($1, $3),
15176 COERCE_SQL_SYNTAX,
15177 @2);
15178 }
15179 | a_expr IS TRUE_P %prec IS
15180 {
15181 BooleanTest *b = makeNode(BooleanTest);
15182
15183 b->arg = (Expr *) $1;
15184 b->booltesttype = IS_TRUE;
15185 b->location = @2;
15186 $$ = (Node *) b;
15187 }
15188 | a_expr IS NOT TRUE_P %prec IS
15189 {
15190 BooleanTest *b = makeNode(BooleanTest);
15191
15192 b->arg = (Expr *) $1;
15193 b->booltesttype = IS_NOT_TRUE;
15194 b->location = @2;
15195 $$ = (Node *) b;
15196 }
15197 | a_expr IS FALSE_P %prec IS
15198 {
15199 BooleanTest *b = makeNode(BooleanTest);
15200
15201 b->arg = (Expr *) $1;
15202 b->booltesttype = IS_FALSE;
15203 b->location = @2;
15204 $$ = (Node *) b;
15205 }
15206 | a_expr IS NOT FALSE_P %prec IS
15207 {
15208 BooleanTest *b = makeNode(BooleanTest);
15209
15210 b->arg = (Expr *) $1;
15211 b->booltesttype = IS_NOT_FALSE;
15212 b->location = @2;
15213 $$ = (Node *) b;
15214 }
15215 | a_expr IS UNKNOWN %prec IS
15216 {
15217 BooleanTest *b = makeNode(BooleanTest);
15218
15219 b->arg = (Expr *) $1;
15220 b->booltesttype = IS_UNKNOWN;
15221 b->location = @2;
15222 $$ = (Node *) b;
15223 }
15224 | a_expr IS NOT UNKNOWN %prec IS
15225 {
15226 BooleanTest *b = makeNode(BooleanTest);
15227
15228 b->arg = (Expr *) $1;
15229 b->booltesttype = IS_NOT_UNKNOWN;
15230 b->location = @2;
15231 $$ = (Node *) b;
15232 }
15233 | a_expr IS DISTINCT FROM a_expr %prec IS
15234 {
15235 $$ = (Node *) makeSimpleA_Expr(AEXPR_DISTINCT, "=", $1, $5, @2);
15236 }
15237 | a_expr IS NOT DISTINCT FROM a_expr %prec IS
15238 {
15239 $$ = (Node *) makeSimpleA_Expr(AEXPR_NOT_DISTINCT, "=", $1, $6, @2);
15240 }
15241 | a_expr BETWEEN opt_asymmetric b_expr AND a_expr %prec BETWEEN
15242 {
15243 $$ = (Node *) makeSimpleA_Expr(AEXPR_BETWEEN,
15244 "BETWEEN",
15245 $1,
15246 (Node *) list_make2($4, $6),
15247 @2);
15248 }
15249 | a_expr NOT_LA BETWEEN opt_asymmetric b_expr AND a_expr %prec NOT_LA
15250 {
15251 $$ = (Node *) makeSimpleA_Expr(AEXPR_NOT_BETWEEN,
15252 "NOT BETWEEN",
15253 $1,
15254 (Node *) list_make2($5, $7),
15255 @2);
15256 }
15257 | a_expr BETWEEN SYMMETRIC b_expr AND a_expr %prec BETWEEN
15258 {
15259 $$ = (Node *) makeSimpleA_Expr(AEXPR_BETWEEN_SYM,
15260 "BETWEEN SYMMETRIC",
15261 $1,
15262 (Node *) list_make2($4, $6),
15263 @2);
15264 }
15265 | a_expr NOT_LA BETWEEN SYMMETRIC b_expr AND a_expr %prec NOT_LA
15266 {
15267 $$ = (Node *) makeSimpleA_Expr(AEXPR_NOT_BETWEEN_SYM,
15268 "NOT BETWEEN SYMMETRIC",
15269 $1,
15270 (Node *) list_make2($5, $7),
15271 @2);
15272 }
15273 | a_expr IN_P select_with_parens
15274 {
15275 /* generate foo = ANY (subquery) */
15276 SubLink *n = makeNode(SubLink);
15277
15278 n->subselect = $3;
15279 n->subLinkType = ANY_SUBLINK;
15280 n->subLinkId = 0;
15281 n->testexpr = $1;
15282 n->operName = NIL; /* show it's IN not = ANY */
15283 n->location = @2;
15284 $$ = (Node *) n;
15285 }
15286 | a_expr IN_P '(' expr_list ')'
15287 {
15288 /* generate scalar IN expression */
15289 A_Expr *n = makeSimpleA_Expr(AEXPR_IN, "=", $1, (Node *) $4, @2);
15290
15291 n->rexpr_list_start = @3;
15292 n->rexpr_list_end = @5;
15293 $$ = (Node *) n;
15294 }
15295 | a_expr NOT_LA IN_P select_with_parens %prec NOT_LA
15296 {
15297 /* generate NOT (foo = ANY (subquery)) */
15298 SubLink *n = makeNode(SubLink);
15299
15300 n->subselect = $4;
15301 n->subLinkType = ANY_SUBLINK;
15302 n->subLinkId = 0;
15303 n->testexpr = $1;
15304 n->operName = NIL; /* show it's IN not = ANY */
15305 n->location = @2;
15306 /* Stick a NOT on top; must have same parse location */
15307 $$ = makeNotExpr((Node *) n, @2);
15308 }
15309 | a_expr NOT_LA IN_P '(' expr_list ')'
15310 {
15311 /* generate scalar NOT IN expression */
15312 A_Expr *n = makeSimpleA_Expr(AEXPR_IN, "<>", $1, (Node *) $5, @2);
15313
15314 n->rexpr_list_start = @4;
15315 n->rexpr_list_end = @6;
15316 $$ = (Node *) n;
15317 }
15318 | a_expr subquery_Op sub_type select_with_parens %prec Op
15319 {
15320 SubLink *n = makeNode(SubLink);
15321
15322 n->subLinkType = $3;
15323 n->subLinkId = 0;
15324 n->testexpr = $1;
15325 n->operName = $2;
15326 n->subselect = $4;
15327 n->location = @2;
15328 $$ = (Node *) n;
15329 }
15330 | a_expr subquery_Op sub_type '(' a_expr ')' %prec Op
15331 {
15332 if ($3 == ANY_SUBLINK)
15333 $$ = (Node *) makeA_Expr(AEXPR_OP_ANY, $2, $1, $5, @2);
15334 else
15335 $$ = (Node *) makeA_Expr(AEXPR_OP_ALL, $2, $1, $5, @2);
15336 }
15337 | UNIQUE opt_unique_null_treatment select_with_parens
15338 {
15339 /* Not sure how to get rid of the parentheses
15340 * but there are lots of shift/reduce errors without them.
15341 *
15342 * Should be able to implement this by plopping the entire
15343 * select into a node, then transforming the target expressions
15344 * from whatever they are into count(*), and testing the
15345 * entire result equal to one.
15346 * But, will probably implement a separate node in the executor.
15347 */
15348 ereport(ERROR,
15349 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
15350 errmsg("UNIQUE predicate is not yet implemented"),
15351 parser_errposition(@1)));
15352 }
15353 | a_expr IS DOCUMENT_P %prec IS
15354 {
15355 $$ = makeXmlExpr(IS_DOCUMENT, NULL, NIL,
15356 list_make1($1), @2);
15357 }
15358 | a_expr IS NOT DOCUMENT_P %prec IS
15359 {
15360 $$ = makeNotExpr(makeXmlExpr(IS_DOCUMENT, NULL, NIL,
15361 list_make1($1), @2),
15362 @2);
15363 }
15364 | a_expr IS NORMALIZED %prec IS
15365 {
15366 $$ = (Node *) makeFuncCall(SystemFuncName("is_normalized"),
15367 list_make1($1),
15368 COERCE_SQL_SYNTAX,
15369 @2);
15370 }
15371 | a_expr IS unicode_normal_form NORMALIZED %prec IS
15372 {
15373 $$ = (Node *) makeFuncCall(SystemFuncName("is_normalized"),
15374 list_make2($1, makeStringConst($3, @3)),
15375 COERCE_SQL_SYNTAX,
15376 @2);
15377 }
15378 | a_expr IS NOT NORMALIZED %prec IS
15379 {
15380 $$ = makeNotExpr((Node *) makeFuncCall(SystemFuncName("is_normalized"),
15381 list_make1($1),
15382 COERCE_SQL_SYNTAX,
15383 @2),
15384 @2);
15385 }
15386 | a_expr IS NOT unicode_normal_form NORMALIZED %prec IS
15387 {
15388 $$ = makeNotExpr((Node *) makeFuncCall(SystemFuncName("is_normalized"),
15389 list_make2($1, makeStringConst($4, @4)),
15390 COERCE_SQL_SYNTAX,
15391 @2),
15392 @2);
15393 }
15394 | a_expr IS json_predicate_type_constraint
15395 json_key_uniqueness_constraint_opt %prec IS
15396 {
15397 JsonFormat *format = makeJsonFormat(JS_FORMAT_DEFAULT, JS_ENC_DEFAULT, -1);
15398
15399 $$ = makeJsonIsPredicate($1, format, $3, $4, @1);
15400 }
15401 /*
15402 * Required by SQL/JSON, but there are conflicts
15403 | a_expr
15404 json_format_clause
15405 IS json_predicate_type_constraint
15406 json_key_uniqueness_constraint_opt %prec IS
15407 {
15408 $$ = makeJsonIsPredicate($1, $2, $4, $5, @1);
15409 }
15410 */
15411 | a_expr IS NOT
15412 json_predicate_type_constraint
15413 json_key_uniqueness_constraint_opt %prec IS
15414 {
15415 JsonFormat *format = makeJsonFormat(JS_FORMAT_DEFAULT, JS_ENC_DEFAULT, -1);
15416
15417 $$ = makeNotExpr(makeJsonIsPredicate($1, format, $4, $5, @1), @1);
15418 }
15419 /*
15420 * Required by SQL/JSON, but there are conflicts
15421 | a_expr
15422 json_format_clause
15423 IS NOT
15424 json_predicate_type_constraint
15425 json_key_uniqueness_constraint_opt %prec IS
15426 {
15427 $$ = makeNotExpr(makeJsonIsPredicate($1, $2, $5, $6, @1), @1);
15428 }
15429 */
15430 | DEFAULT
15431 {
15432 /*
15433 * The SQL spec only allows DEFAULT in "contextually typed
15434 * expressions", but for us, it's easier to allow it in
15435 * any a_expr and then throw error during parse analysis
15436 * if it's in an inappropriate context. This way also
15437 * lets us say something smarter than "syntax error".
15438 */
15439 SetToDefault *n = makeNode(SetToDefault);
15440
15441 /* parse analysis will fill in the rest */
15442 n->location = @1;
15443 $$ = (Node *) n;
15444 }
15445 ;
15446
15447 /*
15448 * Restricted expressions
15449 *
15450 * b_expr is a subset of the complete expression syntax defined by a_expr.
15451 *
15452 * Presently, AND, NOT, IS, and IN are the a_expr keywords that would
15453 * cause trouble in the places where b_expr is used. For simplicity, we
15454 * just eliminate all the boolean-keyword-operator productions from b_expr.
15455 */
15456 b_expr: c_expr
15457 { $$ = $1; }
15458 | b_expr TYPECAST Typename
15459 { $$ = makeTypeCast($1, $3, @2); }
15460 | '+' b_expr %prec UMINUS
15461 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "+", NULL, $2, @1); }
15462 | '-' b_expr %prec UMINUS
15463 { $$ = doNegate($2, @1); }
15464 | b_expr '+' b_expr
15465 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "+", $1, $3, @2); }
15466 | b_expr '-' b_expr
15467 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "-", $1, $3, @2); }
15468 | b_expr '*' b_expr
15469 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "*", $1, $3, @2); }
15470 | b_expr '/' b_expr
15471 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "/", $1, $3, @2); }
15472 | b_expr '%' b_expr
15473 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "%", $1, $3, @2); }
15474 | b_expr '^' b_expr
15475 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "^", $1, $3, @2); }
15476 | b_expr '<' b_expr
15477 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "<", $1, $3, @2); }
15478 | b_expr '>' b_expr
15479 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, ">", $1, $3, @2); }
15480 | b_expr '=' b_expr
15481 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "=", $1, $3, @2); }
15482 | b_expr LESS_EQUALS b_expr
15483 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "<=", $1, $3, @2); }
15484 | b_expr GREATER_EQUALS b_expr
15485 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, ">=", $1, $3, @2); }
15486 | b_expr NOT_EQUALS b_expr
15487 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "<>", $1, $3, @2); }
15488 | b_expr qual_Op b_expr %prec Op
15489 { $$ = (Node *) makeA_Expr(AEXPR_OP, $2, $1, $3, @2); }
15490 | qual_Op b_expr %prec Op
15491 { $$ = (Node *) makeA_Expr(AEXPR_OP, $1, NULL, $2, @1); }
15492 | b_expr IS DISTINCT FROM b_expr %prec IS
15493 {
15494 $$ = (Node *) makeSimpleA_Expr(AEXPR_DISTINCT, "=", $1, $5, @2);
15495 }
15496 | b_expr IS NOT DISTINCT FROM b_expr %prec IS
15497 {
15498 $$ = (Node *) makeSimpleA_Expr(AEXPR_NOT_DISTINCT, "=", $1, $6, @2);
15499 }
15500 | b_expr IS DOCUMENT_P %prec IS
15501 {
15502 $$ = makeXmlExpr(IS_DOCUMENT, NULL, NIL,
15503 list_make1($1), @2);
15504 }
15505 | b_expr IS NOT DOCUMENT_P %prec IS
15506 {
15507 $$ = makeNotExpr(makeXmlExpr(IS_DOCUMENT, NULL, NIL,
15508 list_make1($1), @2),
15509 @2);
15510 }
15511 ;
15512
15513 /*
15514 * Productions that can be used in both a_expr and b_expr.
15515 *
15516 * Note: productions that refer recursively to a_expr or b_expr mostly
15517 * cannot appear here. However, it's OK to refer to a_exprs that occur
15518 * inside parentheses, such as function arguments; that cannot introduce
15519 * ambiguity to the b_expr syntax.
15520 */
15521 c_expr: columnref { $$ = $1; }
15522 | AexprConst { $$ = $1; }
15523 | PARAM opt_indirection
15524 {
15525 ParamRef *p = makeNode(ParamRef);
15526
15527 p->number = $1;
15528 p->location = @1;
15529 if ($2)
15530 {
15531 A_Indirection *n = makeNode(A_Indirection);
15532
15533 n->arg = (Node *) p;
15534 n->indirection = check_indirection($2, yyscanner);
15535 $$ = (Node *) n;
15536 }
15537 else
15538 $$ = (Node *) p;
15539 }
15540 | '(' a_expr ')' opt_indirection
15541 {
15542 if ($4)
15543 {
15544 A_Indirection *n = makeNode(A_Indirection);
15545
15546 n->arg = $2;
15547 n->indirection = check_indirection($4, yyscanner);
15548 $$ = (Node *) n;
15549 }
15550 else
15551 $$ = $2;
15552 }
15553 | case_expr
15554 { $$ = $1; }
15555 | func_expr
15556 { $$ = $1; }
15557 | select_with_parens %prec UMINUS
15558 {
15559 SubLink *n = makeNode(SubLink);
15560
15561 n->subLinkType = EXPR_SUBLINK;
15562 n->subLinkId = 0;
15563 n->testexpr = NULL;
15564 n->operName = NIL;
15565 n->subselect = $1;
15566 n->location = @1;
15567 $$ = (Node *) n;
15568 }
15569 | select_with_parens indirection
15570 {
15571 /*
15572 * Because the select_with_parens nonterminal is designed
15573 * to "eat" as many levels of parens as possible, the
15574 * '(' a_expr ')' opt_indirection production above will
15575 * fail to match a sub-SELECT with indirection decoration;
15576 * the sub-SELECT won't be regarded as an a_expr as long
15577 * as there are parens around it. To support applying
15578 * subscripting or field selection to a sub-SELECT result,
15579 * we need this redundant-looking production.
15580 */
15581 SubLink *n = makeNode(SubLink);
15582 A_Indirection *a = makeNode(A_Indirection);
15583
15584 n->subLinkType = EXPR_SUBLINK;
15585 n->subLinkId = 0;
15586 n->testexpr = NULL;
15587 n->operName = NIL;
15588 n->subselect = $1;
15589 n->location = @1;
15590 a->arg = (Node *) n;
15591 a->indirection = check_indirection($2, yyscanner);
15592 $$ = (Node *) a;
15593 }
15594 | EXISTS select_with_parens
15595 {
15596 SubLink *n = makeNode(SubLink);
15597
15598 n->subLinkType = EXISTS_SUBLINK;
15599 n->subLinkId = 0;
15600 n->testexpr = NULL;
15601 n->operName = NIL;
15602 n->subselect = $2;
15603 n->location = @1;
15604 $$ = (Node *) n;
15605 }
15606 | ARRAY select_with_parens
15607 {
15608 SubLink *n = makeNode(SubLink);
15609
15610 n->subLinkType = ARRAY_SUBLINK;
15611 n->subLinkId = 0;
15612 n->testexpr = NULL;
15613 n->operName = NIL;
15614 n->subselect = $2;
15615 n->location = @1;
15616 $$ = (Node *) n;
15617 }
15618 | ARRAY array_expr
15619 {
15620 A_ArrayExpr *n = castNode(A_ArrayExpr, $2);
15621
15622 /* point outermost A_ArrayExpr to the ARRAY keyword */
15623 n->location = @1;
15624 $$ = (Node *) n;
15625 }
15626 | explicit_row
15627 {
15628 RowExpr *r = makeNode(RowExpr);
15629
15630 r->args = $1;
15631 r->row_typeid = InvalidOid; /* not analyzed yet */
15632 r->colnames = NIL; /* to be filled in during analysis */
15633 r->row_format = COERCE_EXPLICIT_CALL; /* abuse */
15634 r->location = @1;
15635 $$ = (Node *) r;
15636 }
15637 | implicit_row
15638 {
15639 RowExpr *r = makeNode(RowExpr);
15640
15641 r->args = $1;
15642 r->row_typeid = InvalidOid; /* not analyzed yet */
15643 r->colnames = NIL; /* to be filled in during analysis */
15644 r->row_format = COERCE_IMPLICIT_CAST; /* abuse */
15645 r->location = @1;
15646 $$ = (Node *) r;
15647 }
15648 | GROUPING '(' expr_list ')'
15649 {
15650 GroupingFunc *g = makeNode(GroupingFunc);
15651
15652 g->args = $3;
15653 g->location = @1;
15654 $$ = (Node *) g;
15655 }
15656 ;
15657
15658 func_application: func_name '(' ')'
15659 {
15660 $$ = (Node *) makeFuncCall($1, NIL,
15661 COERCE_EXPLICIT_CALL,
15662 @1);
15663 }
15664 | func_name '(' func_arg_list opt_sort_clause ')'
15665 {
15666 FuncCall *n = makeFuncCall($1, $3,
15667 COERCE_EXPLICIT_CALL,
15668 @1);
15669
15670 n->agg_order = $4;
15671 $$ = (Node *) n;
15672 }
15673 | func_name '(' VARIADIC func_arg_expr opt_sort_clause ')'
15674 {
15675 FuncCall *n = makeFuncCall($1, list_make1($4),
15676 COERCE_EXPLICIT_CALL,
15677 @1);
15678
15679 n->func_variadic = true;
15680 n->agg_order = $5;
15681 $$ = (Node *) n;
15682 }
15683 | func_name '(' func_arg_list ',' VARIADIC func_arg_expr opt_sort_clause ')'
15684 {
15685 FuncCall *n = makeFuncCall($1, lappend($3, $6),
15686 COERCE_EXPLICIT_CALL,
15687 @1);
15688
15689 n->func_variadic = true;
15690 n->agg_order = $7;
15691 $$ = (Node *) n;
15692 }
15693 | func_name '(' ALL func_arg_list opt_sort_clause ')'
15694 {
15695 FuncCall *n = makeFuncCall($1, $4,
15696 COERCE_EXPLICIT_CALL,
15697 @1);
15698
15699 n->agg_order = $5;
15700 /* Ideally we'd mark the FuncCall node to indicate
15701 * "must be an aggregate", but there's no provision
15702 * for that in FuncCall at the moment.
15703 */
15704 $$ = (Node *) n;
15705 }
15706 | func_name '(' DISTINCT func_arg_list opt_sort_clause ')'
15707 {
15708 FuncCall *n = makeFuncCall($1, $4,
15709 COERCE_EXPLICIT_CALL,
15710 @1);
15711
15712 n->agg_order = $5;
15713 n->agg_distinct = true;
15714 $$ = (Node *) n;
15715 }
15716 | func_name '(' '*' ')'
15717 {
15718 /*
15719 * We consider AGGREGATE(*) to invoke a parameterless
15720 * aggregate. This does the right thing for COUNT(*),
15721 * and there are no other aggregates in SQL that accept
15722 * '*' as parameter.
15723 *
15724 * The FuncCall node is also marked agg_star = true,
15725 * so that later processing can detect what the argument
15726 * really was.
15727 */
15728 FuncCall *n = makeFuncCall($1, NIL,
15729 COERCE_EXPLICIT_CALL,
15730 @1);
15731
15732 n->agg_star = true;
15733 $$ = (Node *) n;
15734 }
15735 ;
15736
15737
15738 /*
15739 * func_expr and its cousin func_expr_windowless are split out from c_expr just
15740 * so that we have classifications for "everything that is a function call or
15741 * looks like one". This isn't very important, but it saves us having to
15742 * document which variants are legal in places like "FROM function()" or the
15743 * backwards-compatible functional-index syntax for CREATE INDEX.
15744 * (Note that many of the special SQL functions wouldn't actually make any
15745 * sense as functional index entries, but we ignore that consideration here.)
15746 */
15747 func_expr: func_application within_group_clause filter_clause over_clause
15748 {
15749 FuncCall *n = (FuncCall *) $1;
15750
15751 /*
15752 * The order clause for WITHIN GROUP and the one for
15753 * plain-aggregate ORDER BY share a field, so we have to
15754 * check here that at most one is present. We also check
15755 * for DISTINCT and VARIADIC here to give a better error
15756 * location. Other consistency checks are deferred to
15757 * parse analysis.
15758 */
15759 if ($2 != NIL)
15760 {
15761 if (n->agg_order != NIL)
15762 ereport(ERROR,
15763 (errcode(ERRCODE_SYNTAX_ERROR),
15764 errmsg("cannot use multiple ORDER BY clauses with WITHIN GROUP"),
15765 parser_errposition(@2)));
15766 if (n->agg_distinct)
15767 ereport(ERROR,
15768 (errcode(ERRCODE_SYNTAX_ERROR),
15769 errmsg("cannot use DISTINCT with WITHIN GROUP"),
15770 parser_errposition(@2)));
15771 if (n->func_variadic)
15772 ereport(ERROR,
15773 (errcode(ERRCODE_SYNTAX_ERROR),
15774 errmsg("cannot use VARIADIC with WITHIN GROUP"),
15775 parser_errposition(@2)));
15776 n->agg_order = $2;
15777 n->agg_within_group = true;
15778 }
15779 n->agg_filter = $3;
15780 n->over = $4;
15781 $$ = (Node *) n;
15782 }
15783 | json_aggregate_func filter_clause over_clause
15784 {
15785 JsonAggConstructor *n = IsA($1, JsonObjectAgg) ?
15786 ((JsonObjectAgg *) $1)->constructor :
15787 ((JsonArrayAgg *) $1)->constructor;
15788
15789 n->agg_filter = $2;
15790 n->over = $3;
15791 $$ = (Node *) $1;
15792 }
15793 | func_expr_common_subexpr
15794 { $$ = $1; }
15795 ;
15796
15797 /*
15798 * Like func_expr but does not accept WINDOW functions directly
15799 * (but they can still be contained in arguments for functions etc).
15800 * Use this when window expressions are not allowed, where needed to
15801 * disambiguate the grammar (e.g. in CREATE INDEX).
15802 */
15803 func_expr_windowless:
15804 func_application { $$ = $1; }
15805 | func_expr_common_subexpr { $$ = $1; }
15806 | json_aggregate_func { $$ = $1; }
15807 ;
15808
15809 /*
15810 * Special expressions that are considered to be functions.
15811 */
15812 func_expr_common_subexpr:
15813 COLLATION FOR '(' a_expr ')'
15814 {
15815 $$ = (Node *) makeFuncCall(SystemFuncName("pg_collation_for"),
15816 list_make1($4),
15817 COERCE_SQL_SYNTAX,
15818 @1);
15819 }
15820 | CURRENT_DATE
15821 {
15822 $$ = makeSQLValueFunction(SVFOP_CURRENT_DATE, -1, @1);
15823 }
15824 | CURRENT_TIME
15825 {
15826 $$ = makeSQLValueFunction(SVFOP_CURRENT_TIME, -1, @1);
15827 }
15828 | CURRENT_TIME '(' Iconst ')'
15829 {
15830 $$ = makeSQLValueFunction(SVFOP_CURRENT_TIME_N, $3, @1);
15831 }
15832 | CURRENT_TIMESTAMP
15833 {
15834 $$ = makeSQLValueFunction(SVFOP_CURRENT_TIMESTAMP, -1, @1);
15835 }
15836 | CURRENT_TIMESTAMP '(' Iconst ')'
15837 {
15838 $$ = makeSQLValueFunction(SVFOP_CURRENT_TIMESTAMP_N, $3, @1);
15839 }
15840 | LOCALTIME
15841 {
15842 $$ = makeSQLValueFunction(SVFOP_LOCALTIME, -1, @1);
15843 }
15844 | LOCALTIME '(' Iconst ')'
15845 {
15846 $$ = makeSQLValueFunction(SVFOP_LOCALTIME_N, $3, @1);
15847 }
15848 | LOCALTIMESTAMP
15849 {
15850 $$ = makeSQLValueFunction(SVFOP_LOCALTIMESTAMP, -1, @1);
15851 }
15852 | LOCALTIMESTAMP '(' Iconst ')'
15853 {
15854 $$ = makeSQLValueFunction(SVFOP_LOCALTIMESTAMP_N, $3, @1);
15855 }
15856 | CURRENT_ROLE
15857 {
15858 $$ = makeSQLValueFunction(SVFOP_CURRENT_ROLE, -1, @1);
15859 }
15860 | CURRENT_USER
15861 {
15862 $$ = makeSQLValueFunction(SVFOP_CURRENT_USER, -1, @1);
15863 }
15864 | SESSION_USER
15865 {
15866 $$ = makeSQLValueFunction(SVFOP_SESSION_USER, -1, @1);
15867 }
15868 | SYSTEM_USER
15869 {
15870 $$ = (Node *) makeFuncCall(SystemFuncName("system_user"),
15871 NIL,
15872 COERCE_SQL_SYNTAX,
15873 @1);
15874 }
15875 | USER
15876 {
15877 $$ = makeSQLValueFunction(SVFOP_USER, -1, @1);
15878 }
15879 | CURRENT_CATALOG
15880 {
15881 $$ = makeSQLValueFunction(SVFOP_CURRENT_CATALOG, -1, @1);
15882 }
15883 | CURRENT_SCHEMA
15884 {
15885 $$ = makeSQLValueFunction(SVFOP_CURRENT_SCHEMA, -1, @1);
15886 }
15887 | CAST '(' a_expr AS Typename ')'
15888 { $$ = makeTypeCast($3, $5, @1); }
15889 | EXTRACT '(' extract_list ')'
15890 {
15891 $$ = (Node *) makeFuncCall(SystemFuncName("extract"),
15892 $3,
15893 COERCE_SQL_SYNTAX,
15894 @1);
15895 }
15896 | NORMALIZE '(' a_expr ')'
15897 {
15898 $$ = (Node *) makeFuncCall(SystemFuncName("normalize"),
15899 list_make1($3),
15900 COERCE_SQL_SYNTAX,
15901 @1);
15902 }
15903 | NORMALIZE '(' a_expr ',' unicode_normal_form ')'
15904 {
15905 $$ = (Node *) makeFuncCall(SystemFuncName("normalize"),
15906 list_make2($3, makeStringConst($5, @5)),
15907 COERCE_SQL_SYNTAX,
15908 @1);
15909 }
15910 | OVERLAY '(' overlay_list ')'
15911 {
15912 $$ = (Node *) makeFuncCall(SystemFuncName("overlay"),
15913 $3,
15914 COERCE_SQL_SYNTAX,
15915 @1);
15916 }
15917 | OVERLAY '(' func_arg_list_opt ')'
15918 {
15919 /*
15920 * allow functions named overlay() to be called without
15921 * special syntax
15922 */
15923 $$ = (Node *) makeFuncCall(list_make1(makeString("overlay")),
15924 $3,
15925 COERCE_EXPLICIT_CALL,
15926 @1);
15927 }
15928 | POSITION '(' position_list ')'
15929 {
15930 /*
15931 * position(A in B) is converted to position(B, A)
15932 *
15933 * We deliberately don't offer a "plain syntax" option
15934 * for position(), because the reversal of the arguments
15935 * creates too much risk of confusion.
15936 */
15937 $$ = (Node *) makeFuncCall(SystemFuncName("position"),
15938 $3,
15939 COERCE_SQL_SYNTAX,
15940 @1);
15941 }
15942 | SUBSTRING '(' substr_list ')'
15943 {
15944 /* substring(A from B for C) is converted to
15945 * substring(A, B, C) - thomas 2000-11-28
15946 */
15947 $$ = (Node *) makeFuncCall(SystemFuncName("substring"),
15948 $3,
15949 COERCE_SQL_SYNTAX,
15950 @1);
15951 }
15952 | SUBSTRING '(' func_arg_list_opt ')'
15953 {
15954 /*
15955 * allow functions named substring() to be called without
15956 * special syntax
15957 */
15958 $$ = (Node *) makeFuncCall(list_make1(makeString("substring")),
15959 $3,
15960 COERCE_EXPLICIT_CALL,
15961 @1);
15962 }
15963 | TREAT '(' a_expr AS Typename ')'
15964 {
15965 /* TREAT(expr AS target) converts expr of a particular type to target,
15966 * which is defined to be a subtype of the original expression.
15967 * In SQL99, this is intended for use with structured UDTs,
15968 * but let's make this a generally useful form allowing stronger
15969 * coercions than are handled by implicit casting.
15970 *
15971 * Convert SystemTypeName() to SystemFuncName() even though
15972 * at the moment they result in the same thing.
15973 */
15974 $$ = (Node *) makeFuncCall(SystemFuncName(strVal(llast($5->names))),
15975 list_make1($3),
15976 COERCE_EXPLICIT_CALL,
15977 @1);
15978 }
15979 | TRIM '(' BOTH trim_list ')'
15980 {
15981 /* various trim expressions are defined in SQL
15982 * - thomas 1997-07-19
15983 */
15984 $$ = (Node *) makeFuncCall(SystemFuncName("btrim"),
15985 $4,
15986 COERCE_SQL_SYNTAX,
15987 @1);
15988 }
15989 | TRIM '(' LEADING trim_list ')'
15990 {
15991 $$ = (Node *) makeFuncCall(SystemFuncName("ltrim"),
15992 $4,
15993 COERCE_SQL_SYNTAX,
15994 @1);
15995 }
15996 | TRIM '(' TRAILING trim_list ')'
15997 {
15998 $$ = (Node *) makeFuncCall(SystemFuncName("rtrim"),
15999 $4,
16000 COERCE_SQL_SYNTAX,
16001 @1);
16002 }
16003 | TRIM '(' trim_list ')'
16004 {
16005 $$ = (Node *) makeFuncCall(SystemFuncName("btrim"),
16006 $3,
16007 COERCE_SQL_SYNTAX,
16008 @1);
16009 }
16010 | NULLIF '(' a_expr ',' a_expr ')'
16011 {
16012 $$ = (Node *) makeSimpleA_Expr(AEXPR_NULLIF, "=", $3, $5, @1);
16013 }
16014 | COALESCE '(' expr_list ')'
16015 {
16016 CoalesceExpr *c = makeNode(CoalesceExpr);
16017
16018 c->args = $3;
16019 c->location = @1;
16020 $$ = (Node *) c;
16021 }
16022 | GREATEST '(' expr_list ')'
16023 {
16024 MinMaxExpr *v = makeNode(MinMaxExpr);
16025
16026 v->args = $3;
16027 v->op = IS_GREATEST;
16028 v->location = @1;
16029 $$ = (Node *) v;
16030 }
16031 | LEAST '(' expr_list ')'
16032 {
16033 MinMaxExpr *v = makeNode(MinMaxExpr);
16034
16035 v->args = $3;
16036 v->op = IS_LEAST;
16037 v->location = @1;
16038 $$ = (Node *) v;
16039 }
16040 | XMLCONCAT '(' expr_list ')'
16041 {
16042 $$ = makeXmlExpr(IS_XMLCONCAT, NULL, NIL, $3, @1);
16043 }
16044 | XMLELEMENT '(' NAME_P ColLabel ')'
16045 {
16046 $$ = makeXmlExpr(IS_XMLELEMENT, $4, NIL, NIL, @1);
16047 }
16048 | XMLELEMENT '(' NAME_P ColLabel ',' xml_attributes ')'
16049 {
16050 $$ = makeXmlExpr(IS_XMLELEMENT, $4, $6, NIL, @1);
16051 }
16052 | XMLELEMENT '(' NAME_P ColLabel ',' expr_list ')'
16053 {
16054 $$ = makeXmlExpr(IS_XMLELEMENT, $4, NIL, $6, @1);
16055 }
16056 | XMLELEMENT '(' NAME_P ColLabel ',' xml_attributes ',' expr_list ')'
16057 {
16058 $$ = makeXmlExpr(IS_XMLELEMENT, $4, $6, $8, @1);
16059 }
16060 | XMLEXISTS '(' c_expr xmlexists_argument ')'
16061 {
16062 /* xmlexists(A PASSING [BY REF] B [BY REF]) is
16063 * converted to xmlexists(A, B)*/
16064 $$ = (Node *) makeFuncCall(SystemFuncName("xmlexists"),
16065 list_make2($3, $4),
16066 COERCE_SQL_SYNTAX,
16067 @1);
16068 }
16069 | XMLFOREST '(' xml_attribute_list ')'
16070 {
16071 $$ = makeXmlExpr(IS_XMLFOREST, NULL, $3, NIL, @1);
16072 }
16073 | XMLPARSE '(' document_or_content a_expr xml_whitespace_option ')'
16074 {
16075 XmlExpr *x = (XmlExpr *)
16076 makeXmlExpr(IS_XMLPARSE, NULL, NIL,
16077 list_make2($4, makeBoolAConst($5, -1)),
16078 @1);
16079
16080 x->xmloption = $3;
16081 $$ = (Node *) x;
16082 }
16083 | XMLPI '(' NAME_P ColLabel ')'
16084 {
16085 $$ = makeXmlExpr(IS_XMLPI, $4, NULL, NIL, @1);
16086 }
16087 | XMLPI '(' NAME_P ColLabel ',' a_expr ')'
16088 {
16089 $$ = makeXmlExpr(IS_XMLPI, $4, NULL, list_make1($6), @1);
16090 }
16091 | XMLROOT '(' a_expr ',' xml_root_version opt_xml_root_standalone ')'
16092 {
16093 $$ = makeXmlExpr(IS_XMLROOT, NULL, NIL,
16094 list_make3($3, $5, $6), @1);
16095 }
16096 | XMLSERIALIZE '(' document_or_content a_expr AS SimpleTypename xml_indent_option ')'
16097 {
16098 XmlSerialize *n = makeNode(XmlSerialize);
16099
16100 n->xmloption = $3;
16101 n->expr = $4;
16102 n->typeName = $6;
16103 n->indent = $7;
16104 n->location = @1;
16105 $$ = (Node *) n;
16106 }
16107 | JSON_OBJECT '(' func_arg_list ')'
16108 {
16109 /* Support for legacy (non-standard) json_object() */
16110 $$ = (Node *) makeFuncCall(SystemFuncName("json_object"),
16111 $3, COERCE_EXPLICIT_CALL, @1);
16112 }
16113 | JSON_OBJECT '(' json_name_and_value_list
16114 json_object_constructor_null_clause_opt
16115 json_key_uniqueness_constraint_opt
16116 json_returning_clause_opt ')'
16117 {
16118 JsonObjectConstructor *n = makeNode(JsonObjectConstructor);
16119
16120 n->exprs = $3;
16121 n->absent_on_null = $4;
16122 n->unique = $5;
16123 n->output = (JsonOutput *) $6;
16124 n->location = @1;
16125 $$ = (Node *) n;
16126 }
16127 | JSON_OBJECT '(' json_returning_clause_opt ')'
16128 {
16129 JsonObjectConstructor *n = makeNode(JsonObjectConstructor);
16130
16131 n->exprs = NULL;
16132 n->absent_on_null = false;
16133 n->unique = false;
16134 n->output = (JsonOutput *) $3;
16135 n->location = @1;
16136 $$ = (Node *) n;
16137 }
16138 | JSON_ARRAY '('
16139 json_value_expr_list
16140 json_array_constructor_null_clause_opt
16141 json_returning_clause_opt
16142 ')'
16143 {
16144 JsonArrayConstructor *n = makeNode(JsonArrayConstructor);
16145
16146 n->exprs = $3;
16147 n->absent_on_null = $4;
16148 n->output = (JsonOutput *) $5;
16149 n->location = @1;
16150 $$ = (Node *) n;
16151 }
16152 | JSON_ARRAY '('
16153 select_no_parens
16154 json_format_clause_opt
16155 /* json_array_constructor_null_clause_opt */
16156 json_returning_clause_opt
16157 ')'
16158 {
16159 JsonArrayQueryConstructor *n = makeNode(JsonArrayQueryConstructor);
16160
16161 n->query = $3;
16162 n->format = (JsonFormat *) $4;
16163 n->absent_on_null = true; /* XXX */
16164 n->output = (JsonOutput *) $5;
16165 n->location = @1;
16166 $$ = (Node *) n;
16167 }
16168 | JSON_ARRAY '('
16169 json_returning_clause_opt
16170 ')'
16171 {
16172 JsonArrayConstructor *n = makeNode(JsonArrayConstructor);
16173
16174 n->exprs = NIL;
16175 n->absent_on_null = true;
16176 n->output = (JsonOutput *) $3;
16177 n->location = @1;
16178 $$ = (Node *) n;
16179 }
16180 | JSON '(' json_value_expr json_key_uniqueness_constraint_opt ')'
16181 {
16182 JsonParseExpr *n = makeNode(JsonParseExpr);
16183
16184 n->expr = (JsonValueExpr *) $3;
16185 n->unique_keys = $4;
16186 n->output = NULL;
16187 n->location = @1;
16188 $$ = (Node *) n;
16189 }
16190 | JSON_SCALAR '(' a_expr ')'
16191 {
16192 JsonScalarExpr *n = makeNode(JsonScalarExpr);
16193
16194 n->expr = (Expr *) $3;
16195 n->output = NULL;
16196 n->location = @1;
16197 $$ = (Node *) n;
16198 }
16199 | JSON_SERIALIZE '(' json_value_expr json_returning_clause_opt ')'
16200 {
16201 JsonSerializeExpr *n = makeNode(JsonSerializeExpr);
16202
16203 n->expr = (JsonValueExpr *) $3;
16204 n->output = (JsonOutput *) $4;
16205 n->location = @1;
16206 $$ = (Node *) n;
16207 }
16208 | MERGE_ACTION '(' ')'
16209 {
16210 MergeSupportFunc *m = makeNode(MergeSupportFunc);
16211
16212 m->msftype = TEXTOID;
16213 m->location = @1;
16214 $$ = (Node *) m;
16215 }
16216 | JSON_QUERY '('
16217 json_value_expr ',' a_expr json_passing_clause_opt
16218 json_returning_clause_opt
16219 json_wrapper_behavior
16220 json_quotes_clause_opt
16221 json_behavior_clause_opt
16222 ')'
16223 {
16224 JsonFuncExpr *n = makeNode(JsonFuncExpr);
16225
16226 n->op = JSON_QUERY_OP;
16227 n->context_item = (JsonValueExpr *) $3;
16228 n->pathspec = $5;
16229 n->passing = $6;
16230 n->output = (JsonOutput *) $7;
16231 n->wrapper = $8;
16232 n->quotes = $9;
16233 n->on_empty = (JsonBehavior *) linitial($10);
16234 n->on_error = (JsonBehavior *) lsecond($10);
16235 n->location = @1;
16236 $$ = (Node *) n;
16237 }
16238 | JSON_EXISTS '('
16239 json_value_expr ',' a_expr json_passing_clause_opt
16240 json_on_error_clause_opt
16241 ')'
16242 {
16243 JsonFuncExpr *n = makeNode(JsonFuncExpr);
16244
16245 n->op = JSON_EXISTS_OP;
16246 n->context_item = (JsonValueExpr *) $3;
16247 n->pathspec = $5;
16248 n->passing = $6;
16249 n->output = NULL;
16250 n->on_error = (JsonBehavior *) $7;
16251 n->location = @1;
16252 $$ = (Node *) n;
16253 }
16254 | JSON_VALUE '('
16255 json_value_expr ',' a_expr json_passing_clause_opt
16256 json_returning_clause_opt
16257 json_behavior_clause_opt
16258 ')'
16259 {
16260 JsonFuncExpr *n = makeNode(JsonFuncExpr);
16261
16262 n->op = JSON_VALUE_OP;
16263 n->context_item = (JsonValueExpr *) $3;
16264 n->pathspec = $5;
16265 n->passing = $6;
16266 n->output = (JsonOutput *) $7;
16267 n->on_empty = (JsonBehavior *) linitial($8);
16268 n->on_error = (JsonBehavior *) lsecond($8);
16269 n->location = @1;
16270 $$ = (Node *) n;
16271 }
16272 ;
16273
16274
16275 /*
16276 * SQL/XML support
16277 */
16278 xml_root_version: VERSION_P a_expr
16279 { $$ = $2; }
16280 | VERSION_P NO VALUE_P
16281 { $$ = makeNullAConst(-1); }
16282 ;
16283
16284 opt_xml_root_standalone: ',' STANDALONE_P YES_P
16285 { $$ = makeIntConst(XML_STANDALONE_YES, -1); }
16286 | ',' STANDALONE_P NO
16287 { $$ = makeIntConst(XML_STANDALONE_NO, -1); }
16288 | ',' STANDALONE_P NO VALUE_P
16289 { $$ = makeIntConst(XML_STANDALONE_NO_VALUE, -1); }
16290 | /*EMPTY*/
16291 { $$ = makeIntConst(XML_STANDALONE_OMITTED, -1); }
16292 ;
16293
16294 xml_attributes: XMLATTRIBUTES '(' xml_attribute_list ')' { $$ = $3; }
16295 ;
16296
16297 xml_attribute_list: xml_attribute_el { $$ = list_make1($1); }
16298 | xml_attribute_list ',' xml_attribute_el { $$ = lappend($1, $3); }
16299 ;
16300
16301 xml_attribute_el: a_expr AS ColLabel
16302 {
16303 $$ = makeNode(ResTarget);
16304 $$->name = $3;
16305 $$->indirection = NIL;
16306 $$->val = (Node *) $1;
16307 $$->location = @1;
16308 }
16309 | a_expr
16310 {
16311 $$ = makeNode(ResTarget);
16312 $$->name = NULL;
16313 $$->indirection = NIL;
16314 $$->val = (Node *) $1;
16315 $$->location = @1;
16316 }
16317 ;
16318
16319 document_or_content: DOCUMENT_P { $$ = XMLOPTION_DOCUMENT; }
16320 | CONTENT_P { $$ = XMLOPTION_CONTENT; }
16321 ;
16322
16323 xml_indent_option: INDENT { $$ = true; }
16324 | NO INDENT { $$ = false; }
16325 | /*EMPTY*/ { $$ = false; }
16326 ;
16327
16328 xml_whitespace_option: PRESERVE WHITESPACE_P { $$ = true; }
16329 | STRIP_P WHITESPACE_P { $$ = false; }
16330 | /*EMPTY*/ { $$ = false; }
16331 ;
16332
16333 /* We allow several variants for SQL and other compatibility. */
16334 xmlexists_argument:
16335 PASSING c_expr
16336 {
16337 $$ = $2;
16338 }
16339 | PASSING c_expr xml_passing_mech
16340 {
16341 $$ = $2;
16342 }
16343 | PASSING xml_passing_mech c_expr
16344 {
16345 $$ = $3;
16346 }
16347 | PASSING xml_passing_mech c_expr xml_passing_mech
16348 {
16349 $$ = $3;
16350 }
16351 ;
16352
16353 xml_passing_mech:
16354 BY REF_P
16355 | BY VALUE_P
16356 ;
16357
16358
16359 /*
16360 * Aggregate decoration clauses
16361 */
16362 within_group_clause:
16363 WITHIN GROUP_P '(' sort_clause ')' { $$ = $4; }
16364 | /*EMPTY*/ { $$ = NIL; }
16365 ;
16366
16367 filter_clause:
16368 FILTER '(' WHERE a_expr ')' { $$ = $4; }
16369 | /*EMPTY*/ { $$ = NULL; }
16370 ;
16371
16372
16373 /*
16374 * Window Definitions
16375 */
16376 window_clause:
16377 WINDOW window_definition_list { $$ = $2; }
16378 | /*EMPTY*/ { $$ = NIL; }
16379 ;
16380
16381 window_definition_list:
16382 window_definition { $$ = list_make1($1); }
16383 | window_definition_list ',' window_definition
16384 { $$ = lappend($1, $3); }
16385 ;
16386
16387 window_definition:
16388 ColId AS window_specification
16389 {
16390 WindowDef *n = $3;
16391
16392 n->name = $1;
16393 $$ = n;
16394 }
16395 ;
16396
16397 over_clause: OVER window_specification
16398 { $$ = $2; }
16399 | OVER ColId
16400 {
16401 WindowDef *n = makeNode(WindowDef);
16402
16403 n->name = $2;
16404 n->refname = NULL;
16405 n->partitionClause = NIL;
16406 n->orderClause = NIL;
16407 n->frameOptions = FRAMEOPTION_DEFAULTS;
16408 n->startOffset = NULL;
16409 n->endOffset = NULL;
16410 n->location = @2;
16411 $$ = n;
16412 }
16413 | /*EMPTY*/
16414 { $$ = NULL; }
16415 ;
16416
16417 window_specification: '(' opt_existing_window_name opt_partition_clause
16418 opt_sort_clause opt_frame_clause ')'
16419 {
16420 WindowDef *n = makeNode(WindowDef);
16421
16422 n->name = NULL;
16423 n->refname = $2;
16424 n->partitionClause = $3;
16425 n->orderClause = $4;
16426 /* copy relevant fields of opt_frame_clause */
16427 n->frameOptions = $5->frameOptions;
16428 n->startOffset = $5->startOffset;
16429 n->endOffset = $5->endOffset;
16430 n->location = @1;
16431 $$ = n;
16432 }
16433 ;
16434
16435 /*
16436 * If we see PARTITION, RANGE, ROWS or GROUPS as the first token after the '('
16437 * of a window_specification, we want the assumption to be that there is
16438 * no existing_window_name; but those keywords are unreserved and so could
16439 * be ColIds. We fix this by making them have the same precedence as IDENT
16440 * and giving the empty production here a slightly higher precedence, so
16441 * that the shift/reduce conflict is resolved in favor of reducing the rule.
16442 * These keywords are thus precluded from being an existing_window_name but
16443 * are not reserved for any other purpose.
16444 */
16445 opt_existing_window_name: ColId { $$ = $1; }
16446 | /*EMPTY*/ %prec Op { $$ = NULL; }
16447 ;
16448
16449 opt_partition_clause: PARTITION BY expr_list { $$ = $3; }
16450 | /*EMPTY*/ { $$ = NIL; }
16451 ;
16452
16453 /*
16454 * For frame clauses, we return a WindowDef, but only some fields are used:
16455 * frameOptions, startOffset, and endOffset.
16456 */
16457 opt_frame_clause:
16458 RANGE frame_extent opt_window_exclusion_clause
16459 {
16460 WindowDef *n = $2;
16461
16462 n->frameOptions |= FRAMEOPTION_NONDEFAULT | FRAMEOPTION_RANGE;
16463 n->frameOptions |= $3;
16464 $$ = n;
16465 }
16466 | ROWS frame_extent opt_window_exclusion_clause
16467 {
16468 WindowDef *n = $2;
16469
16470 n->frameOptions |= FRAMEOPTION_NONDEFAULT | FRAMEOPTION_ROWS;
16471 n->frameOptions |= $3;
16472 $$ = n;
16473 }
16474 | GROUPS frame_extent opt_window_exclusion_clause
16475 {
16476 WindowDef *n = $2;
16477
16478 n->frameOptions |= FRAMEOPTION_NONDEFAULT | FRAMEOPTION_GROUPS;
16479 n->frameOptions |= $3;
16480 $$ = n;
16481 }
16482 | /*EMPTY*/
16483 {
16484 WindowDef *n = makeNode(WindowDef);
16485
16486 n->frameOptions = FRAMEOPTION_DEFAULTS;
16487 n->startOffset = NULL;
16488 n->endOffset = NULL;
16489 $$ = n;
16490 }
16491 ;
16492
16493 frame_extent: frame_bound
16494 {
16495 WindowDef *n = $1;
16496
16497 /* reject invalid cases */
16498 if (n->frameOptions & FRAMEOPTION_START_UNBOUNDED_FOLLOWING)
16499 ereport(ERROR,
16500 (errcode(ERRCODE_WINDOWING_ERROR),
16501 errmsg("frame start cannot be UNBOUNDED FOLLOWING"),
16502 parser_errposition(@1)));
16503 if (n->frameOptions & FRAMEOPTION_START_OFFSET_FOLLOWING)
16504 ereport(ERROR,
16505 (errcode(ERRCODE_WINDOWING_ERROR),
16506 errmsg("frame starting from following row cannot end with current row"),
16507 parser_errposition(@1)));
16508 n->frameOptions |= FRAMEOPTION_END_CURRENT_ROW;
16509 $$ = n;
16510 }
16511 | BETWEEN frame_bound AND frame_bound
16512 {
16513 WindowDef *n1 = $2;
16514 WindowDef *n2 = $4;
16515
16516 /* form merged options */
16517 int frameOptions = n1->frameOptions;
16518 /* shift converts START_ options to END_ options */
16519 frameOptions |= n2->frameOptions << 1;
16520 frameOptions |= FRAMEOPTION_BETWEEN;
16521 /* reject invalid cases */
16522 if (frameOptions & FRAMEOPTION_START_UNBOUNDED_FOLLOWING)
16523 ereport(ERROR,
16524 (errcode(ERRCODE_WINDOWING_ERROR),
16525 errmsg("frame start cannot be UNBOUNDED FOLLOWING"),
16526 parser_errposition(@2)));
16527 if (frameOptions & FRAMEOPTION_END_UNBOUNDED_PRECEDING)
16528 ereport(ERROR,
16529 (errcode(ERRCODE_WINDOWING_ERROR),
16530 errmsg("frame end cannot be UNBOUNDED PRECEDING"),
16531 parser_errposition(@4)));
16532 if ((frameOptions & FRAMEOPTION_START_CURRENT_ROW) &&
16533 (frameOptions & FRAMEOPTION_END_OFFSET_PRECEDING))
16534 ereport(ERROR,
16535 (errcode(ERRCODE_WINDOWING_ERROR),
16536 errmsg("frame starting from current row cannot have preceding rows"),
16537 parser_errposition(@4)));
16538 if ((frameOptions & FRAMEOPTION_START_OFFSET_FOLLOWING) &&
16539 (frameOptions & (FRAMEOPTION_END_OFFSET_PRECEDING |
16540 FRAMEOPTION_END_CURRENT_ROW)))
16541 ereport(ERROR,
16542 (errcode(ERRCODE_WINDOWING_ERROR),
16543 errmsg("frame starting from following row cannot have preceding rows"),
16544 parser_errposition(@4)));
16545 n1->frameOptions = frameOptions;
16546 n1->endOffset = n2->startOffset;
16547 $$ = n1;
16548 }
16549 ;
16550
16551 /*
16552 * This is used for both frame start and frame end, with output set up on
16553 * the assumption it's frame start; the frame_extent productions must reject
16554 * invalid cases.
16555 */
16556 frame_bound:
16557 UNBOUNDED PRECEDING
16558 {
16559 WindowDef *n = makeNode(WindowDef);
16560
16561 n->frameOptions = FRAMEOPTION_START_UNBOUNDED_PRECEDING;
16562 n->startOffset = NULL;
16563 n->endOffset = NULL;
16564 $$ = n;
16565 }
16566 | UNBOUNDED FOLLOWING
16567 {
16568 WindowDef *n = makeNode(WindowDef);
16569
16570 n->frameOptions = FRAMEOPTION_START_UNBOUNDED_FOLLOWING;
16571 n->startOffset = NULL;
16572 n->endOffset = NULL;
16573 $$ = n;
16574 }
16575 | CURRENT_P ROW
16576 {
16577 WindowDef *n = makeNode(WindowDef);
16578
16579 n->frameOptions = FRAMEOPTION_START_CURRENT_ROW;
16580 n->startOffset = NULL;
16581 n->endOffset = NULL;
16582 $$ = n;
16583 }
16584 | a_expr PRECEDING
16585 {
16586 WindowDef *n = makeNode(WindowDef);
16587
16588 n->frameOptions = FRAMEOPTION_START_OFFSET_PRECEDING;
16589 n->startOffset = $1;
16590 n->endOffset = NULL;
16591 $$ = n;
16592 }
16593 | a_expr FOLLOWING
16594 {
16595 WindowDef *n = makeNode(WindowDef);
16596
16597 n->frameOptions = FRAMEOPTION_START_OFFSET_FOLLOWING;
16598 n->startOffset = $1;
16599 n->endOffset = NULL;
16600 $$ = n;
16601 }
16602 ;
16603
16604 opt_window_exclusion_clause:
16605 EXCLUDE CURRENT_P ROW { $$ = FRAMEOPTION_EXCLUDE_CURRENT_ROW; }
16606 | EXCLUDE GROUP_P { $$ = FRAMEOPTION_EXCLUDE_GROUP; }
16607 | EXCLUDE TIES { $$ = FRAMEOPTION_EXCLUDE_TIES; }
16608 | EXCLUDE NO OTHERS { $$ = 0; }
16609 | /*EMPTY*/ { $$ = 0; }
16610 ;
16611
16612
16613 /*
16614 * Supporting nonterminals for expressions.
16615 */
16616
16617 /* Explicit row production.
16618 *
16619 * SQL99 allows an optional ROW keyword, so we can now do single-element rows
16620 * without conflicting with the parenthesized a_expr production. Without the
16621 * ROW keyword, there must be more than one a_expr inside the parens.
16622 */
16623 row: ROW '(' expr_list ')' { $$ = $3; }
16624 | ROW '(' ')' { $$ = NIL; }
16625 | '(' expr_list ',' a_expr ')' { $$ = lappend($2, $4); }
16626 ;
16627
16628 explicit_row: ROW '(' expr_list ')' { $$ = $3; }
16629 | ROW '(' ')' { $$ = NIL; }
16630 ;
16631
16632 implicit_row: '(' expr_list ',' a_expr ')' { $$ = lappend($2, $4); }
16633 ;
16634
16635 sub_type: ANY { $$ = ANY_SUBLINK; }
16636 | SOME { $$ = ANY_SUBLINK; }
16637 | ALL { $$ = ALL_SUBLINK; }
16638 ;
16639
16640 all_Op: Op { $$ = $1; }
16641 | MathOp { $$ = $1; }
16642 ;
16643
16644 MathOp: '+' { $$ = "+"; }
16645 | '-' { $$ = "-"; }
16646 | '*' { $$ = "*"; }
16647 | '/' { $$ = "/"; }
16648 | '%' { $$ = "%"; }
16649 | '^' { $$ = "^"; }
16650 | '<' { $$ = "<"; }
16651 | '>' { $$ = ">"; }
16652 | '=' { $$ = "="; }
16653 | LESS_EQUALS { $$ = "<="; }
16654 | GREATER_EQUALS { $$ = ">="; }
16655 | NOT_EQUALS { $$ = "<>"; }
16656 ;
16657
16658 qual_Op: Op
16659 { $$ = list_make1(makeString($1)); }
16660 | OPERATOR '(' any_operator ')'
16661 { $$ = $3; }
16662 ;
16663
16664 qual_all_Op:
16665 all_Op
16666 { $$ = list_make1(makeString($1)); }
16667 | OPERATOR '(' any_operator ')'
16668 { $$ = $3; }
16669 ;
16670
16671 subquery_Op:
16672 all_Op
16673 { $$ = list_make1(makeString($1)); }
16674 | OPERATOR '(' any_operator ')'
16675 { $$ = $3; }
16676 | LIKE
16677 { $$ = list_make1(makeString("~~")); }
16678 | NOT_LA LIKE
16679 { $$ = list_make1(makeString("!~~")); }
16680 | ILIKE
16681 { $$ = list_make1(makeString("~~*")); }
16682 | NOT_LA ILIKE
16683 { $$ = list_make1(makeString("!~~*")); }
16684 /* cannot put SIMILAR TO here, because SIMILAR TO is a hack.
16685 * the regular expression is preprocessed by a function (similar_to_escape),
16686 * and the ~ operator for posix regular expressions is used.
16687 * x SIMILAR TO y -> x ~ similar_to_escape(y)
16688 * this transformation is made on the fly by the parser upwards.
16689 * however the SubLink structure which handles any/some/all stuff
16690 * is not ready for such a thing.
16691 */
16692 ;
16693
16694 expr_list: a_expr
16695 {
16696 $$ = list_make1($1);
16697 }
16698 | expr_list ',' a_expr
16699 {
16700 $$ = lappend($1, $3);
16701 }
16702 ;
16703
16704 /* function arguments can have names */
16705 func_arg_list: func_arg_expr
16706 {
16707 $$ = list_make1($1);
16708 }
16709 | func_arg_list ',' func_arg_expr
16710 {
16711 $$ = lappend($1, $3);
16712 }
16713 ;
16714
16715 func_arg_expr: a_expr
16716 {
16717 $$ = $1;
16718 }
16719 | param_name COLON_EQUALS a_expr
16720 {
16721 NamedArgExpr *na = makeNode(NamedArgExpr);
16722
16723 na->name = $1;
16724 na->arg = (Expr *) $3;
16725 na->argnumber = -1; /* until determined */
16726 na->location = @1;
16727 $$ = (Node *) na;
16728 }
16729 | param_name EQUALS_GREATER a_expr
16730 {
16731 NamedArgExpr *na = makeNode(NamedArgExpr);
16732
16733 na->name = $1;
16734 na->arg = (Expr *) $3;
16735 na->argnumber = -1; /* until determined */
16736 na->location = @1;
16737 $$ = (Node *) na;
16738 }
16739 ;
16740
16741 func_arg_list_opt: func_arg_list { $$ = $1; }
16742 | /*EMPTY*/ { $$ = NIL; }
16743 ;
16744
16745 type_list: Typename { $$ = list_make1($1); }
16746 | type_list ',' Typename { $$ = lappend($1, $3); }
16747 ;
16748
16749 array_expr: '[' expr_list ']'
16750 {
16751 $$ = makeAArrayExpr($2, @1, @3);
16752 }
16753 | '[' array_expr_list ']'
16754 {
16755 $$ = makeAArrayExpr($2, @1, @3);
16756 }
16757 | '[' ']'
16758 {
16759 $$ = makeAArrayExpr(NIL, @1, @2);
16760 }
16761 ;
16762
16763 array_expr_list: array_expr { $$ = list_make1($1); }
16764 | array_expr_list ',' array_expr { $$ = lappend($1, $3); }
16765 ;
16766
16767
16768 extract_list:
16769 extract_arg FROM a_expr
16770 {
16771 $$ = list_make2(makeStringConst($1, @1), $3);
16772 }
16773 ;
16774
16775 /* Allow delimited string Sconst in extract_arg as an SQL extension.
16776 * - thomas 2001-04-12
16777 */
16778 extract_arg:
16779 IDENT { $$ = $1; }
16780 | YEAR_P { $$ = "year"; }
16781 | MONTH_P { $$ = "month"; }
16782 | DAY_P { $$ = "day"; }
16783 | HOUR_P { $$ = "hour"; }
16784 | MINUTE_P { $$ = "minute"; }
16785 | SECOND_P { $$ = "second"; }
16786 | Sconst { $$ = $1; }
16787 ;
16788
16789 unicode_normal_form:
16790 NFC { $$ = "NFC"; }
16791 | NFD { $$ = "NFD"; }
16792 | NFKC { $$ = "NFKC"; }
16793 | NFKD { $$ = "NFKD"; }
16794 ;
16795
16796 /* OVERLAY() arguments */
16797 overlay_list:
16798 a_expr PLACING a_expr FROM a_expr FOR a_expr
16799 {
16800 /* overlay(A PLACING B FROM C FOR D) is converted to overlay(A, B, C, D) */
16801 $$ = list_make4($1, $3, $5, $7);
16802 }
16803 | a_expr PLACING a_expr FROM a_expr
16804 {
16805 /* overlay(A PLACING B FROM C) is converted to overlay(A, B, C) */
16806 $$ = list_make3($1, $3, $5);
16807 }
16808 ;
16809
16810 /* position_list uses b_expr not a_expr to avoid conflict with general IN */
16811 position_list:
16812 b_expr IN_P b_expr { $$ = list_make2($3, $1); }
16813 ;
16814
16815 /*
16816 * SUBSTRING() arguments
16817 *
16818 * Note that SQL:1999 has both
16819 * text FROM int FOR int
16820 * and
16821 * text FROM pattern FOR escape
16822 *
16823 * In the parser we map them both to a call to the substring() function and
16824 * rely on type resolution to pick the right one.
16825 *
16826 * In SQL:2003, the second variant was changed to
16827 * text SIMILAR pattern ESCAPE escape
16828 * We could in theory map that to a different function internally, but
16829 * since we still support the SQL:1999 version, we don't. However,
16830 * ruleutils.c will reverse-list the call in the newer style.
16831 */
16832 substr_list:
16833 a_expr FROM a_expr FOR a_expr
16834 {
16835 $$ = list_make3($1, $3, $5);
16836 }
16837 | a_expr FOR a_expr FROM a_expr
16838 {
16839 /* not legal per SQL, but might as well allow it */
16840 $$ = list_make3($1, $5, $3);
16841 }
16842 | a_expr FROM a_expr
16843 {
16844 /*
16845 * Because we aren't restricting data types here, this
16846 * syntax can end up resolving to textregexsubstr().
16847 * We've historically allowed that to happen, so continue
16848 * to accept it. However, ruleutils.c will reverse-list
16849 * such a call in regular function call syntax.
16850 */
16851 $$ = list_make2($1, $3);
16852 }
16853 | a_expr FOR a_expr
16854 {
16855 /* not legal per SQL */
16856
16857 /*
16858 * Since there are no cases where this syntax allows
16859 * a textual FOR value, we forcibly cast the argument
16860 * to int4. The possible matches in pg_proc are
16861 * substring(text,int4) and substring(text,text),
16862 * and we don't want the parser to choose the latter,
16863 * which it is likely to do if the second argument
16864 * is unknown or doesn't have an implicit cast to int4.
16865 */
16866 $$ = list_make3($1, makeIntConst(1, -1),
16867 makeTypeCast($3,
16868 SystemTypeName("int4"), -1));
16869 }
16870 | a_expr SIMILAR a_expr ESCAPE a_expr
16871 {
16872 $$ = list_make3($1, $3, $5);
16873 }
16874 ;
16875
16876 trim_list: a_expr FROM expr_list { $$ = lappend($3, $1); }
16877 | FROM expr_list { $$ = $2; }
16878 | expr_list { $$ = $1; }
16879 ;
16880
16881 /*
16882 * Define SQL-style CASE clause.
16883 * - Full specification
16884 * CASE WHEN a = b THEN c ... ELSE d END
16885 * - Implicit argument
16886 * CASE a WHEN b THEN c ... ELSE d END
16887 */
16888 case_expr: CASE case_arg when_clause_list case_default END_P
16889 {
16890 CaseExpr *c = makeNode(CaseExpr);
16891
16892 c->casetype = InvalidOid; /* not analyzed yet */
16893 c->arg = (Expr *) $2;
16894 c->args = $3;
16895 c->defresult = (Expr *) $4;
16896 c->location = @1;
16897 $$ = (Node *) c;
16898 }
16899 ;
16900
16901 when_clause_list:
16902 /* There must be at least one */
16903 when_clause { $$ = list_make1($1); }
16904 | when_clause_list when_clause { $$ = lappend($1, $2); }
16905 ;
16906
16907 when_clause:
16908 WHEN a_expr THEN a_expr
16909 {
16910 CaseWhen *w = makeNode(CaseWhen);
16911
16912 w->expr = (Expr *) $2;
16913 w->result = (Expr *) $4;
16914 w->location = @1;
16915 $$ = (Node *) w;
16916 }
16917 ;
16918
16919 case_default:
16920 ELSE a_expr { $$ = $2; }
16921 | /*EMPTY*/ { $$ = NULL; }
16922 ;
16923
16924 case_arg: a_expr { $$ = $1; }
16925 | /*EMPTY*/ { $$ = NULL; }
16926 ;
16927
16928 columnref: ColId
16929 {
16930 $$ = makeColumnRef($1, NIL, @1, yyscanner);
16931 }
16932 | ColId indirection
16933 {
16934 $$ = makeColumnRef($1, $2, @1, yyscanner);
16935 }
16936 ;
16937
16938 indirection_el:
16939 '.' attr_name
16940 {
16941 $$ = (Node *) makeString($2);
16942 }
16943 | '.' '*'
16944 {
16945 $$ = (Node *) makeNode(A_Star);
16946 }
16947 | '[' a_expr ']'
16948 {
16949 A_Indices *ai = makeNode(A_Indices);
16950
16951 ai->is_slice = false;
16952 ai->lidx = NULL;
16953 ai->uidx = $2;
16954 $$ = (Node *) ai;
16955 }
16956 | '[' opt_slice_bound ':' opt_slice_bound ']'
16957 {
16958 A_Indices *ai = makeNode(A_Indices);
16959
16960 ai->is_slice = true;
16961 ai->lidx = $2;
16962 ai->uidx = $4;
16963 $$ = (Node *) ai;
16964 }
16965 ;
16966
16967 opt_slice_bound:
16968 a_expr { $$ = $1; }
16969 | /*EMPTY*/ { $$ = NULL; }
16970 ;
16971
16972 indirection:
16973 indirection_el { $$ = list_make1($1); }
16974 | indirection indirection_el { $$ = lappend($1, $2); }
16975 ;
16976
16977 opt_indirection:
16978 /*EMPTY*/ { $$ = NIL; }
16979 | opt_indirection indirection_el { $$ = lappend($1, $2); }
16980 ;
16981
16982 opt_asymmetric: ASYMMETRIC
16983 | /*EMPTY*/
16984 ;
16985
16986 /* SQL/JSON support */
16987 json_passing_clause_opt:
16988 PASSING json_arguments { $$ = $2; }
16989 | /*EMPTY*/ { $$ = NIL; }
16990 ;
16991
16992 json_arguments:
16993 json_argument { $$ = list_make1($1); }
16994 | json_arguments ',' json_argument { $$ = lappend($1, $3); }
16995 ;
16996
16997 json_argument:
16998 json_value_expr AS ColLabel
16999 {
17000 JsonArgument *n = makeNode(JsonArgument);
17001
17002 n->val = (JsonValueExpr *) $1;
17003 n->name = $3;
17004 $$ = (Node *) n;
17005 }
17006 ;
17007
17008 /* ARRAY is a noise word */
17009 json_wrapper_behavior:
17010 WITHOUT WRAPPER { $$ = JSW_NONE; }
17011 | WITHOUT ARRAY WRAPPER { $$ = JSW_NONE; }
17012 | WITH WRAPPER { $$ = JSW_UNCONDITIONAL; }
17013 | WITH ARRAY WRAPPER { $$ = JSW_UNCONDITIONAL; }
17014 | WITH CONDITIONAL ARRAY WRAPPER { $$ = JSW_CONDITIONAL; }
17015 | WITH UNCONDITIONAL ARRAY WRAPPER { $$ = JSW_UNCONDITIONAL; }
17016 | WITH CONDITIONAL WRAPPER { $$ = JSW_CONDITIONAL; }
17017 | WITH UNCONDITIONAL WRAPPER { $$ = JSW_UNCONDITIONAL; }
17018 | /* empty */ { $$ = JSW_UNSPEC; }
17019 ;
17020
17021 json_behavior:
17022 DEFAULT a_expr
17023 { $$ = (Node *) makeJsonBehavior(JSON_BEHAVIOR_DEFAULT, $2, @1); }
17024 | json_behavior_type
17025 { $$ = (Node *) makeJsonBehavior($1, NULL, @1); }
17026 ;
17027
17028 json_behavior_type:
17029 ERROR_P { $$ = JSON_BEHAVIOR_ERROR; }
17030 | NULL_P { $$ = JSON_BEHAVIOR_NULL; }
17031 | TRUE_P { $$ = JSON_BEHAVIOR_TRUE; }
17032 | FALSE_P { $$ = JSON_BEHAVIOR_FALSE; }
17033 | UNKNOWN { $$ = JSON_BEHAVIOR_UNKNOWN; }
17034 | EMPTY_P ARRAY { $$ = JSON_BEHAVIOR_EMPTY_ARRAY; }
17035 | EMPTY_P OBJECT_P { $$ = JSON_BEHAVIOR_EMPTY_OBJECT; }
17036 /* non-standard, for Oracle compatibility only */
17037 | EMPTY_P { $$ = JSON_BEHAVIOR_EMPTY_ARRAY; }
17038 ;
17039
17040 json_behavior_clause_opt:
17041 json_behavior ON EMPTY_P
17042 { $$ = list_make2($1, NULL); }
17043 | json_behavior ON ERROR_P
17044 { $$ = list_make2(NULL, $1); }
17045 | json_behavior ON EMPTY_P json_behavior ON ERROR_P
17046 { $$ = list_make2($1, $4); }
17047 | /* EMPTY */
17048 { $$ = list_make2(NULL, NULL); }
17049 ;
17050
17051 json_on_error_clause_opt:
17052 json_behavior ON ERROR_P
17053 { $$ = $1; }
17054 | /* EMPTY */
17055 { $$ = NULL; }
17056 ;
17057
17058 json_value_expr:
17059 a_expr json_format_clause_opt
17060 {
17061 /* formatted_expr will be set during parse-analysis. */
17062 $$ = (Node *) makeJsonValueExpr((Expr *) $1, NULL,
17063 castNode(JsonFormat, $2));
17064 }
17065 ;
17066
17067 json_format_clause:
17068 FORMAT_LA JSON ENCODING name
17069 {
17070 int encoding;
17071
17072 if (!pg_strcasecmp($4, "utf8"))
17073 encoding = JS_ENC_UTF8;
17074 else if (!pg_strcasecmp($4, "utf16"))
17075 encoding = JS_ENC_UTF16;
17076 else if (!pg_strcasecmp($4, "utf32"))
17077 encoding = JS_ENC_UTF32;
17078 else
17079 ereport(ERROR,
17080 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
17081 errmsg("unrecognized JSON encoding: %s", $4),
17082 parser_errposition(@4)));
17083
17084 $$ = (Node *) makeJsonFormat(JS_FORMAT_JSON, encoding, @1);
17085 }
17086 | FORMAT_LA JSON
17087 {
17088 $$ = (Node *) makeJsonFormat(JS_FORMAT_JSON, JS_ENC_DEFAULT, @1);
17089 }
17090 ;
17091
17092 json_format_clause_opt:
17093 json_format_clause
17094 {
17095 $$ = $1;
17096 }
17097 | /* EMPTY */
17098 {
17099 $$ = (Node *) makeJsonFormat(JS_FORMAT_DEFAULT, JS_ENC_DEFAULT, -1);
17100 }
17101 ;
17102
17103 json_quotes_clause_opt:
17104 KEEP QUOTES ON SCALAR STRING_P { $$ = JS_QUOTES_KEEP; }
17105 | KEEP QUOTES { $$ = JS_QUOTES_KEEP; }
17106 | OMIT QUOTES ON SCALAR STRING_P { $$ = JS_QUOTES_OMIT; }
17107 | OMIT QUOTES { $$ = JS_QUOTES_OMIT; }
17108 | /* EMPTY */ { $$ = JS_QUOTES_UNSPEC; }
17109 ;
17110
17111 json_returning_clause_opt:
17112 RETURNING Typename json_format_clause_opt
17113 {
17114 JsonOutput *n = makeNode(JsonOutput);
17115
17116 n->typeName = $2;
17117 n->returning = makeNode(JsonReturning);
17118 n->returning->format = (JsonFormat *) $3;
17119 $$ = (Node *) n;
17120 }
17121 | /* EMPTY */ { $$ = NULL; }
17122 ;
17123
17124 /*
17125 * We must assign the only-JSON production a precedence less than IDENT in
17126 * order to favor shifting over reduction when JSON is followed by VALUE_P,
17127 * OBJECT_P, or SCALAR. (ARRAY doesn't need that treatment, because it's a
17128 * fully reserved word.) Because json_predicate_type_constraint is always
17129 * followed by json_key_uniqueness_constraint_opt, we also need the only-JSON
17130 * production to have precedence less than WITH and WITHOUT. UNBOUNDED isn't
17131 * really related to this syntax, but it's a convenient choice because it
17132 * already has a precedence less than IDENT for other reasons.
17133 */
17134 json_predicate_type_constraint:
17135 JSON %prec UNBOUNDED { $$ = JS_TYPE_ANY; }
17136 | JSON VALUE_P { $$ = JS_TYPE_ANY; }
17137 | JSON ARRAY { $$ = JS_TYPE_ARRAY; }
17138 | JSON OBJECT_P { $$ = JS_TYPE_OBJECT; }
17139 | JSON SCALAR { $$ = JS_TYPE_SCALAR; }
17140 ;
17141
17142 /*
17143 * KEYS is a noise word here. To avoid shift/reduce conflicts, assign the
17144 * KEYS-less productions a precedence less than IDENT (i.e., less than KEYS).
17145 * This prevents reducing them when the next token is KEYS.
17146 */
17147 json_key_uniqueness_constraint_opt:
17148 WITH UNIQUE KEYS { $$ = true; }
17149 | WITH UNIQUE %prec UNBOUNDED { $$ = true; }
17150 | WITHOUT UNIQUE KEYS { $$ = false; }
17151 | WITHOUT UNIQUE %prec UNBOUNDED { $$ = false; }
17152 | /* EMPTY */ %prec UNBOUNDED { $$ = false; }
17153 ;
17154
17155 json_name_and_value_list:
17156 json_name_and_value
17157 { $$ = list_make1($1); }
17158 | json_name_and_value_list ',' json_name_and_value
17159 { $$ = lappend($1, $3); }
17160 ;
17161
17162 json_name_and_value:
17163 /* Supporting this syntax seems to require major surgery
17164 KEY c_expr VALUE_P json_value_expr
17165 { $$ = makeJsonKeyValue($2, $4); }
17166 |
17167 */
17168 c_expr VALUE_P json_value_expr
17169 { $$ = makeJsonKeyValue($1, $3); }
17170 |
17171 a_expr ':' json_value_expr
17172 { $$ = makeJsonKeyValue($1, $3); }
17173 ;
17174
17175 /* empty means false for objects, true for arrays */
17176 json_object_constructor_null_clause_opt:
17177 NULL_P ON NULL_P { $$ = false; }
17178 | ABSENT ON NULL_P { $$ = true; }
17179 | /* EMPTY */ { $$ = false; }
17180 ;
17181
17182 json_array_constructor_null_clause_opt:
17183 NULL_P ON NULL_P { $$ = false; }
17184 | ABSENT ON NULL_P { $$ = true; }
17185 | /* EMPTY */ { $$ = true; }
17186 ;
17187
17188 json_value_expr_list:
17189 json_value_expr { $$ = list_make1($1); }
17190 | json_value_expr_list ',' json_value_expr { $$ = lappend($1, $3);}
17191 ;
17192
17193 json_aggregate_func:
17194 JSON_OBJECTAGG '('
17195 json_name_and_value
17196 json_object_constructor_null_clause_opt
17197 json_key_uniqueness_constraint_opt
17198 json_returning_clause_opt
17199 ')'
17200 {
17201 JsonObjectAgg *n = makeNode(JsonObjectAgg);
17202
17203 n->arg = (JsonKeyValue *) $3;
17204 n->absent_on_null = $4;
17205 n->unique = $5;
17206 n->constructor = makeNode(JsonAggConstructor);
17207 n->constructor->output = (JsonOutput *) $6;
17208 n->constructor->agg_order = NULL;
17209 n->constructor->location = @1;
17210 $$ = (Node *) n;
17211 }
17212 | JSON_ARRAYAGG '('
17213 json_value_expr
17214 json_array_aggregate_order_by_clause_opt
17215 json_array_constructor_null_clause_opt
17216 json_returning_clause_opt
17217 ')'
17218 {
17219 JsonArrayAgg *n = makeNode(JsonArrayAgg);
17220
17221 n->arg = (JsonValueExpr *) $3;
17222 n->absent_on_null = $5;
17223 n->constructor = makeNode(JsonAggConstructor);
17224 n->constructor->agg_order = $4;
17225 n->constructor->output = (JsonOutput *) $6;
17226 n->constructor->location = @1;
17227 $$ = (Node *) n;
17228 }
17229 ;
17230
17231 json_array_aggregate_order_by_clause_opt:
17232 ORDER BY sortby_list { $$ = $3; }
17233 | /* EMPTY */ { $$ = NIL; }
17234 ;
17235
17236 /*****************************************************************************
17237 *
17238 * target list for SELECT
17239 *
17240 *****************************************************************************/
17241
17242 opt_target_list: target_list { $$ = $1; }
17243 | /* EMPTY */ { $$ = NIL; }
17244 ;
17245
17246 target_list:
17247 target_el { $$ = list_make1($1); }
17248 | target_list ',' target_el { $$ = lappend($1, $3); }
17249 ;
17250
17251 target_el: a_expr AS ColLabel
17252 {
17253 $$ = makeNode(ResTarget);
17254 $$->name = $3;
17255 $$->indirection = NIL;
17256 $$->val = (Node *) $1;
17257 $$->location = @1;
17258 }
17259 | a_expr BareColLabel
17260 {
17261 $$ = makeNode(ResTarget);
17262 $$->name = $2;
17263 $$->indirection = NIL;
17264 $$->val = (Node *) $1;
17265 $$->location = @1;
17266 }
17267 | a_expr
17268 {
17269 $$ = makeNode(ResTarget);
17270 $$->name = NULL;
17271 $$->indirection = NIL;
17272 $$->val = (Node *) $1;
17273 $$->location = @1;
17274 }
17275 | '*'
17276 {
17277 ColumnRef *n = makeNode(ColumnRef);
17278
17279 n->fields = list_make1(makeNode(A_Star));
17280 n->location = @1;
17281
17282 $$ = makeNode(ResTarget);
17283 $$->name = NULL;
17284 $$->indirection = NIL;
17285 $$->val = (Node *) n;
17286 $$->location = @1;
17287 }
17288 ;
17289
17290
17291 /*****************************************************************************
17292 *
17293 * Names and constants
17294 *
17295 *****************************************************************************/
17296
17297 qualified_name_list:
17298 qualified_name { $$ = list_make1($1); }
17299 | qualified_name_list ',' qualified_name { $$ = lappend($1, $3); }
17300 ;
17301
17302 /*
17303 * The production for a qualified relation name has to exactly match the
17304 * production for a qualified func_name, because in a FROM clause we cannot
17305 * tell which we are parsing until we see what comes after it ('(' for a
17306 * func_name, something else for a relation). Therefore we allow 'indirection'
17307 * which may contain subscripts, and reject that case in the C code.
17308 */
17309 qualified_name:
17310 ColId
17311 {
17312 $$ = makeRangeVar(NULL, $1, @1);
17313 }
17314 | ColId indirection
17315 {
17316 $$ = makeRangeVarFromQualifiedName($1, $2, @1, yyscanner);
17317 }
17318 ;
17319
17320 name_list: name
17321 { $$ = list_make1(makeString($1)); }
17322 | name_list ',' name
17323 { $$ = lappend($1, makeString($3)); }
17324 ;
17325
17326
17327 name: ColId { $$ = $1; };
17328
17329 attr_name: ColLabel { $$ = $1; };
17330
17331 file_name: Sconst { $$ = $1; };
17332
17333 /*
17334 * The production for a qualified func_name has to exactly match the
17335 * production for a qualified columnref, because we cannot tell which we
17336 * are parsing until we see what comes after it ('(' or Sconst for a func_name,
17337 * anything else for a columnref). Therefore we allow 'indirection' which
17338 * may contain subscripts, and reject that case in the C code. (If we
17339 * ever implement SQL99-like methods, such syntax may actually become legal!)
17340 */
17341 func_name: type_function_name
17342 { $$ = list_make1(makeString($1)); }
17343 | ColId indirection
17344 {
17345 $$ = check_func_name(lcons(makeString($1), $2),
17346 yyscanner);
17347 }
17348 ;
17349
17350
17351 /*
17352 * Constants
17353 */
17354 AexprConst: Iconst
17355 {
17356 $$ = makeIntConst($1, @1);
17357 }
17358 | FCONST
17359 {
17360 $$ = makeFloatConst($1, @1);
17361 }
17362 | Sconst
17363 {
17364 $$ = makeStringConst($1, @1);
17365 }
17366 | BCONST
17367 {
17368 $$ = makeBitStringConst($1, @1);
17369 }
17370 | XCONST
17371 {
17372 /* This is a bit constant per SQL99:
17373 * Without Feature F511, "BIT data type",
17374 * a <general literal> shall not be a
17375 * <bit string literal> or a <hex string literal>.
17376 */
17377 $$ = makeBitStringConst($1, @1);
17378 }
17379 | func_name Sconst
17380 {
17381 /* generic type 'literal' syntax */
17382 TypeName *t = makeTypeNameFromNameList($1);
17383
17384 t->location = @1;
17385 $$ = makeStringConstCast($2, @2, t);
17386 }
17387 | func_name '(' func_arg_list opt_sort_clause ')' Sconst
17388 {
17389 /* generic syntax with a type modifier */
17390 TypeName *t = makeTypeNameFromNameList($1);
17391 ListCell *lc;
17392
17393 /*
17394 * We must use func_arg_list and opt_sort_clause in the
17395 * production to avoid reduce/reduce conflicts, but we
17396 * don't actually wish to allow NamedArgExpr in this
17397 * context, nor ORDER BY.
17398 */
17399 foreach(lc, $3)
17400 {
17401 NamedArgExpr *arg = (NamedArgExpr *) lfirst(lc);
17402
17403 if (IsA(arg, NamedArgExpr))
17404 ereport(ERROR,
17405 (errcode(ERRCODE_SYNTAX_ERROR),
17406 errmsg("type modifier cannot have parameter name"),
17407 parser_errposition(arg->location)));
17408 }
17409 if ($4 != NIL)
17410 ereport(ERROR,
17411 (errcode(ERRCODE_SYNTAX_ERROR),
17412 errmsg("type modifier cannot have ORDER BY"),
17413 parser_errposition(@4)));
17414
17415 t->typmods = $3;
17416 t->location = @1;
17417 $$ = makeStringConstCast($6, @6, t);
17418 }
17419 | ConstTypename Sconst
17420 {
17421 $$ = makeStringConstCast($2, @2, $1);
17422 }
17423 | ConstInterval Sconst opt_interval
17424 {
17425 TypeName *t = $1;
17426
17427 t->typmods = $3;
17428 $$ = makeStringConstCast($2, @2, t);
17429 }
17430 | ConstInterval '(' Iconst ')' Sconst
17431 {
17432 TypeName *t = $1;
17433
17434 t->typmods = list_make2(makeIntConst(INTERVAL_FULL_RANGE, -1),
17435 makeIntConst($3, @3));
17436 $$ = makeStringConstCast($5, @5, t);
17437 }
17438 | TRUE_P
17439 {
17440 $$ = makeBoolAConst(true, @1);
17441 }
17442 | FALSE_P
17443 {
17444 $$ = makeBoolAConst(false, @1);
17445 }
17446 | NULL_P
17447 {
17448 $$ = makeNullAConst(@1);
17449 }
17450 ;
17451
17452 Iconst: ICONST { $$ = $1; };
17453 Sconst: SCONST { $$ = $1; };
17454
17455 SignedIconst: Iconst { $$ = $1; }
17456 | '+' Iconst { $$ = + $2; }
17457 | '-' Iconst { $$ = - $2; }
17458 ;
17459
17460 /* Role specifications */
17461 RoleId: RoleSpec
17462 {
17463 RoleSpec *spc = (RoleSpec *) $1;
17464
17465 switch (spc->roletype)
17466 {
17467 case ROLESPEC_CSTRING:
17468 $$ = spc->rolename;
17469 break;
17470 case ROLESPEC_PUBLIC:
17471 ereport(ERROR,
17472 (errcode(ERRCODE_RESERVED_NAME),
17473 errmsg("role name \"%s\" is reserved",
17474 "public"),
17475 parser_errposition(@1)));
17476 break;
17477 case ROLESPEC_SESSION_USER:
17478 ereport(ERROR,
17479 (errcode(ERRCODE_RESERVED_NAME),
17480 errmsg("%s cannot be used as a role name here",
17481 "SESSION_USER"),
17482 parser_errposition(@1)));
17483 break;
17484 case ROLESPEC_CURRENT_USER:
17485 ereport(ERROR,
17486 (errcode(ERRCODE_RESERVED_NAME),
17487 errmsg("%s cannot be used as a role name here",
17488 "CURRENT_USER"),
17489 parser_errposition(@1)));
17490 break;
17491 case ROLESPEC_CURRENT_ROLE:
17492 ereport(ERROR,
17493 (errcode(ERRCODE_RESERVED_NAME),
17494 errmsg("%s cannot be used as a role name here",
17495 "CURRENT_ROLE"),
17496 parser_errposition(@1)));
17497 break;
17498 }
17499 }
17500 ;
17501
17502 RoleSpec: NonReservedWord
17503 {
17504 /*
17505 * "public" and "none" are not keywords, but they must
17506 * be treated specially here.
17507 */
17508 RoleSpec *n;
17509
17510 if (strcmp($1, "public") == 0)
17511 {
17512 n = (RoleSpec *) makeRoleSpec(ROLESPEC_PUBLIC, @1);
17513 n->roletype = ROLESPEC_PUBLIC;
17514 }
17515 else if (strcmp($1, "none") == 0)
17516 {
17517 ereport(ERROR,
17518 (errcode(ERRCODE_RESERVED_NAME),
17519 errmsg("role name \"%s\" is reserved",
17520 "none"),
17521 parser_errposition(@1)));
17522 }
17523 else
17524 {
17525 n = makeRoleSpec(ROLESPEC_CSTRING, @1);
17526 n->rolename = pstrdup($1);
17527 }
17528 $$ = n;
17529 }
17530 | CURRENT_ROLE
17531 {
17532 $$ = makeRoleSpec(ROLESPEC_CURRENT_ROLE, @1);
17533 }
17534 | CURRENT_USER
17535 {
17536 $$ = makeRoleSpec(ROLESPEC_CURRENT_USER, @1);
17537 }
17538 | SESSION_USER
17539 {
17540 $$ = makeRoleSpec(ROLESPEC_SESSION_USER, @1);
17541 }
17542 ;
17543
17544 role_list: RoleSpec
17545 { $$ = list_make1($1); }
17546 | role_list ',' RoleSpec
17547 { $$ = lappend($1, $3); }
17548 ;
17549
17550
17551 /*****************************************************************************
17552 *
17553 * PL/pgSQL extensions
17554 *
17555 * You'd think a PL/pgSQL "expression" should be just an a_expr, but
17556 * historically it can include just about anything that can follow SELECT.
17557 * Therefore the returned struct is a SelectStmt.
17558 *****************************************************************************/
17559
17560 PLpgSQL_Expr: opt_distinct_clause opt_target_list
17561 from_clause where_clause
17562 group_clause having_clause window_clause
17563 opt_sort_clause opt_select_limit opt_for_locking_clause
17564 {
17565 SelectStmt *n = makeNode(SelectStmt);
17566
17567 n->distinctClause = $1;
17568 n->targetList = $2;
17569 n->fromClause = $3;
17570 n->whereClause = $4;
17571 n->groupClause = ($5)->list;
17572 n->groupDistinct = ($5)->distinct;
17573 n->havingClause = $6;
17574 n->windowClause = $7;
17575 n->sortClause = $8;
17576 if ($9)
17577 {
17578 n->limitOffset = $9->limitOffset;
17579 n->limitCount = $9->limitCount;
17580 if (!n->sortClause &&
17581 $9->limitOption == LIMIT_OPTION_WITH_TIES)
17582 ereport(ERROR,
17583 (errcode(ERRCODE_SYNTAX_ERROR),
17584 errmsg("WITH TIES cannot be specified without ORDER BY clause"),
17585 parser_errposition($9->optionLoc)));
17586 n->limitOption = $9->limitOption;
17587 }
17588 n->lockingClause = $10;
17589 $$ = (Node *) n;
17590 }
17591 ;
17592
17593 /*
17594 * PL/pgSQL Assignment statement: name opt_indirection := PLpgSQL_Expr
17595 */
17596
17597 PLAssignStmt: plassign_target opt_indirection plassign_equals PLpgSQL_Expr
17598 {
17599 PLAssignStmt *n = makeNode(PLAssignStmt);
17600
17601 n->name = $1;
17602 n->indirection = check_indirection($2, yyscanner);
17603 /* nnames will be filled by calling production */
17604 n->val = (SelectStmt *) $4;
17605 n->location = @1;
17606 $$ = (Node *) n;
17607 }
17608 ;
17609
17610 plassign_target: ColId { $$ = $1; }
17611 | PARAM { $$ = psprintf("$%d", $1); }
17612 ;
17613
17614 plassign_equals: COLON_EQUALS
17615 | '='
17616 ;
17617
17618
17619 /*
17620 * Name classification hierarchy.
17621 *
17622 * IDENT is the lexeme returned by the lexer for identifiers that match
17623 * no known keyword. In most cases, we can accept certain keywords as
17624 * names, not only IDENTs. We prefer to accept as many such keywords
17625 * as possible to minimize the impact of "reserved words" on programmers.
17626 * So, we divide names into several possible classes. The classification
17627 * is chosen in part to make keywords acceptable as names wherever possible.
17628 */
17629
17630 /* Column identifier --- names that can be column, table, etc names.
17631 */
17632 ColId: IDENT { $$ = $1; }
17633 | unreserved_keyword { $$ = pstrdup($1); }
17634 | col_name_keyword { $$ = pstrdup($1); }
17635 ;
17636
17637 /* Type/function identifier --- names that can be type or function names.
17638 */
17639 type_function_name: IDENT { $$ = $1; }
17640 | unreserved_keyword { $$ = pstrdup($1); }
17641 | type_func_name_keyword { $$ = pstrdup($1); }
17642 ;
17643
17644 /* Any not-fully-reserved word --- these names can be, eg, role names.
17645 */
17646 NonReservedWord: IDENT { $$ = $1; }
17647 | unreserved_keyword { $$ = pstrdup($1); }
17648 | col_name_keyword { $$ = pstrdup($1); }
17649 | type_func_name_keyword { $$ = pstrdup($1); }
17650 ;
17651
17652 /* Column label --- allowed labels in "AS" clauses.
17653 * This presently includes *all* Postgres keywords.
17654 */
17655 ColLabel: IDENT { $$ = $1; }
17656 | unreserved_keyword { $$ = pstrdup($1); }
17657 | col_name_keyword { $$ = pstrdup($1); }
17658 | type_func_name_keyword { $$ = pstrdup($1); }
17659 | reserved_keyword { $$ = pstrdup($1); }
17660 ;
17661
17662 /* Bare column label --- names that can be column labels without writing "AS".
17663 * This classification is orthogonal to the other keyword categories.
17664 */
17665 BareColLabel: IDENT { $$ = $1; }
17666 | bare_label_keyword { $$ = pstrdup($1); }
17667 ;
17668
17669
17670 /*
17671 * Keyword category lists. Generally, every keyword present in
17672 * the Postgres grammar should appear in exactly one of these lists.
17673 *
17674 * Put a new keyword into the first list that it can go into without causing
17675 * shift or reduce conflicts. The earlier lists define "less reserved"
17676 * categories of keywords.
17677 *
17678 * Make sure that each keyword's category in kwlist.h matches where
17679 * it is listed here. (Someday we may be able to generate these lists and
17680 * kwlist.h's table from one source of truth.)
17681 */
17682
17683 /* "Unreserved" keywords --- available for use as any kind of name.
17684 */
17685 unreserved_keyword:
17686 ABORT_P
17687 | ABSENT
17688 | ABSOLUTE_P
17689 | ACCESS
17690 | ACTION
17691 | ADD_P
17692 | ADMIN
17693 | AFTER
17694 | AGGREGATE
17695 | ALSO
17696 | ALTER
17697 | ALWAYS
17698 | ASENSITIVE
17699 | ASSERTION
17700 | ASSIGNMENT
17701 | AT
17702 | ATOMIC
17703 | ATTACH
17704 | ATTRIBUTE
17705 | BACKWARD
17706 | BEFORE
17707 | BEGIN_P
17708 | BREADTH
17709 | BY
17710 | CACHE
17711 | CALL
17712 | CALLED
17713 | CASCADE
17714 | CASCADED
17715 | CATALOG_P
17716 | CHAIN
17717 | CHARACTERISTICS
17718 | CHECKPOINT
17719 | CLASS
17720 | CLOSE
17721 | CLUSTER
17722 | COLUMNS
17723 | COMMENT
17724 | COMMENTS
17725 | COMMIT
17726 | COMMITTED
17727 | COMPRESSION
17728 | CONDITIONAL
17729 | CONFIGURATION
17730 | CONFLICT
17731 | CONNECTION
17732 | CONSTRAINTS
17733 | CONTENT_P
17734 | CONTINUE_P
17735 | CONVERSION_P
17736 | COPY
17737 | COST
17738 | CSV
17739 | CUBE
17740 | CURRENT_P
17741 | CURSOR
17742 | CYCLE
17743 | DATA_P
17744 | DATABASE
17745 | DAY_P
17746 | DEALLOCATE
17747 | DECLARE
17748 | DEFAULTS
17749 | DEFERRED
17750 | DEFINER
17751 | DELETE_P
17752 | DELIMITER
17753 | DELIMITERS
17754 | DEPENDS
17755 | DEPTH
17756 | DETACH
17757 | DICTIONARY
17758 | DISABLE_P
17759 | DISCARD
17760 | DOCUMENT_P
17761 | DOMAIN_P
17762 | DOUBLE_P
17763 | DROP
17764 | EACH
17765 | EMPTY_P
17766 | ENABLE_P
17767 | ENCODING
17768 | ENCRYPTED
17769 | ENFORCED
17770 | ENUM_P
17771 | ERROR_P
17772 | ESCAPE
17773 | EVENT
17774 | EXCLUDE
17775 | EXCLUDING
17776 | EXCLUSIVE
17777 | EXECUTE
17778 | EXPLAIN
17779 | EXPRESSION
17780 | EXTENSION
17781 | EXTERNAL
17782 | FAMILY
17783 | FILTER
17784 | FINALIZE
17785 | FIRST_P
17786 | FOLLOWING
17787 | FORCE
17788 | FORMAT
17789 | FORWARD
17790 | FUNCTION
17791 | FUNCTIONS
17792 | GENERATED
17793 | GLOBAL
17794 | GRANTED
17795 | GROUPS
17796 | HANDLER
17797 | HEADER_P
17798 | HOLD
17799 | HOUR_P
17800 | IDENTITY_P
17801 | IF_P
17802 | IMMEDIATE
17803 | IMMUTABLE
17804 | IMPLICIT_P
17805 | IMPORT_P
17806 | INCLUDE
17807 | INCLUDING
17808 | INCREMENT
17809 | INDENT
17810 | INDEX
17811 | INDEXES
17812 | INHERIT
17813 | INHERITS
17814 | INLINE_P
17815 | INPUT_P
17816 | INSENSITIVE
17817 | INSERT
17818 | INSTEAD
17819 | INVOKER
17820 | ISOLATION
17821 | KEEP
17822 | KEY
17823 | KEYS
17824 | LABEL
17825 | LANGUAGE
17826 | LARGE_P
17827 | LAST_P
17828 | LEAKPROOF
17829 | LEVEL
17830 | LISTEN
17831 | LOAD
17832 | LOCAL
17833 | LOCATION
17834 | LOCK_P
17835 | LOCKED
17836 | LOGGED
17837 | MAPPING
17838 | MATCH
17839 | MATCHED
17840 | MATERIALIZED
17841 | MAXVALUE
17842 | MERGE
17843 | METHOD
17844 | MINUTE_P
17845 | MINVALUE
17846 | MODE
17847 | MONTH_P
17848 | MOVE
17849 | NAME_P
17850 | NAMES
17851 | NESTED
17852 | NEW
17853 | NEXT
17854 | NFC
17855 | NFD
17856 | NFKC
17857 | NFKD
17858 | NO
17859 | NORMALIZED
17860 | NOTHING
17861 | NOTIFY
17862 | NOWAIT
17863 | NULLS_P
17864 | OBJECT_P
17865 | OBJECTS_P
17866 | OF
17867 | OFF
17868 | OIDS
17869 | OLD
17870 | OMIT
17871 | OPERATOR
17872 | OPTION
17873 | OPTIONS
17874 | ORDINALITY
17875 | OTHERS
17876 | OVER
17877 | OVERRIDING
17878 | OWNED
17879 | OWNER
17880 | PARALLEL
17881 | PARAMETER
17882 | PARSER
17883 | PARTIAL
17884 | PARTITION
17885 | PASSING
17886 | PASSWORD
17887 | PATH
17888 | PERIOD
17889 | PLAN
17890 | PLANS
17891 | POLICY
17892 | PRECEDING
17893 | PREPARE
17894 | PREPARED
17895 | PRESERVE
17896 | PRIOR
17897 | PRIVILEGES
17898 | PROCEDURAL
17899 | PROCEDURE
17900 | PROCEDURES
17901 | PROGRAM
17902 | PUBLICATION
17903 | QUOTE
17904 | QUOTES
17905 | RANGE
17906 | READ
17907 | REASSIGN
17908 | RECURSIVE
17909 | REF_P
17910 | REFERENCING
17911 | REFRESH
17912 | REINDEX
17913 | RELATIVE_P
17914 | RELEASE
17915 | RENAME
17916 | REPEATABLE
17917 | REPLACE
17918 | REPLICA
17919 | RESET
17920 | RESTART
17921 | RESTRICT
17922 | RETURN
17923 | RETURNS
17924 | REVOKE
17925 | ROLE
17926 | ROLLBACK
17927 | ROLLUP
17928 | ROUTINE
17929 | ROUTINES
17930 | ROWS
17931 | RULE
17932 | SAVEPOINT
17933 | SCALAR
17934 | SCHEMA
17935 | SCHEMAS
17936 | SCROLL
17937 | SEARCH
17938 | SECOND_P
17939 | SECURITY
17940 | SEQUENCE
17941 | SEQUENCES
17942 | SERIALIZABLE
17943 | SERVER
17944 | SESSION
17945 | SET
17946 | SETS
17947 | SHARE
17948 | SHOW
17949 | SIMPLE
17950 | SKIP
17951 | SNAPSHOT
17952 | SOURCE
17953 | SQL_P
17954 | STABLE
17955 | STANDALONE_P
17956 | START
17957 | STATEMENT
17958 | STATISTICS
17959 | STDIN
17960 | STDOUT
17961 | STORAGE
17962 | STORED
17963 | STRICT_P
17964 | STRING_P
17965 | STRIP_P
17966 | SUBSCRIPTION
17967 | SUPPORT
17968 | SYSID
17969 | SYSTEM_P
17970 | TABLES
17971 | TABLESPACE
17972 | TARGET
17973 | TEMP
17974 | TEMPLATE
17975 | TEMPORARY
17976 | TEXT_P
17977 | TIES
17978 | TRANSACTION
17979 | TRANSFORM
17980 | TRIGGER
17981 | TRUNCATE
17982 | TRUSTED
17983 | TYPE_P
17984 | TYPES_P
17985 | UESCAPE
17986 | UNBOUNDED
17987 | UNCOMMITTED
17988 | UNCONDITIONAL
17989 | UNENCRYPTED
17990 | UNKNOWN
17991 | UNLISTEN
17992 | UNLOGGED
17993 | UNTIL
17994 | UPDATE
17995 | VACUUM
17996 | VALID
17997 | VALIDATE
17998 | VALIDATOR
17999 | VALUE_P
18000 | VARYING
18001 | VERSION_P
18002 | VIEW
18003 | VIEWS
18004 | VIRTUAL
18005 | VOLATILE
18006 | WHITESPACE_P
18007 | WITHIN
18008 | WITHOUT
18009 | WORK
18010 | WRAPPER
18011 | WRITE
18012 | XML_P
18013 | YEAR_P
18014 | YES_P
18015 | ZONE
18016 ;
18017
18018 /* Column identifier --- keywords that can be column, table, etc names.
18019 *
18020 * Many of these keywords will in fact be recognized as type or function
18021 * names too; but they have special productions for the purpose, and so
18022 * can't be treated as "generic" type or function names.
18023 *
18024 * The type names appearing here are not usable as function names
18025 * because they can be followed by '(' in typename productions, which
18026 * looks too much like a function call for an LR(1) parser.
18027 */
18028 col_name_keyword:
18029 BETWEEN
18030 | BIGINT
18031 | BIT
18032 | BOOLEAN_P
18033 | CHAR_P
18034 | CHARACTER
18035 | COALESCE
18036 | DEC
18037 | DECIMAL_P
18038 | EXISTS
18039 | EXTRACT
18040 | FLOAT_P
18041 | GREATEST
18042 | GROUPING
18043 | INOUT
18044 | INT_P
18045 | INTEGER
18046 | INTERVAL
18047 | JSON
18048 | JSON_ARRAY
18049 | JSON_ARRAYAGG
18050 | JSON_EXISTS
18051 | JSON_OBJECT
18052 | JSON_OBJECTAGG
18053 | JSON_QUERY
18054 | JSON_SCALAR
18055 | JSON_SERIALIZE
18056 | JSON_TABLE
18057 | JSON_VALUE
18058 | LEAST
18059 | MERGE_ACTION
18060 | NATIONAL
18061 | NCHAR
18062 | NONE
18063 | NORMALIZE
18064 | NULLIF
18065 | NUMERIC
18066 | OUT_P
18067 | OVERLAY
18068 | POSITION
18069 | PRECISION
18070 | REAL
18071 | ROW
18072 | SETOF
18073 | SMALLINT
18074 | SUBSTRING
18075 | TIME
18076 | TIMESTAMP
18077 | TREAT
18078 | TRIM
18079 | VALUES
18080 | VARCHAR
18081 | XMLATTRIBUTES
18082 | XMLCONCAT
18083 | XMLELEMENT
18084 | XMLEXISTS
18085 | XMLFOREST
18086 | XMLNAMESPACES
18087 | XMLPARSE
18088 | XMLPI
18089 | XMLROOT
18090 | XMLSERIALIZE
18091 | XMLTABLE
18092 ;
18093
18094 /* Type/function identifier --- keywords that can be type or function names.
18095 *
18096 * Most of these are keywords that are used as operators in expressions;
18097 * in general such keywords can't be column names because they would be
18098 * ambiguous with variables, but they are unambiguous as function identifiers.
18099 *
18100 * Do not include POSITION, SUBSTRING, etc here since they have explicit
18101 * productions in a_expr to support the goofy SQL9x argument syntax.
18102 * - thomas 2000-11-28
18103 */
18104 type_func_name_keyword:
18105 AUTHORIZATION
18106 | BINARY
18107 | COLLATION
18108 | CONCURRENTLY
18109 | CROSS
18110 | CURRENT_SCHEMA
18111 | FREEZE
18112 | FULL
18113 | ILIKE
18114 | INNER_P
18115 | IS
18116 | ISNULL
18117 | JOIN
18118 | LEFT
18119 | LIKE
18120 | NATURAL
18121 | NOTNULL
18122 | OUTER_P
18123 | OVERLAPS
18124 | RIGHT
18125 | SIMILAR
18126 | TABLESAMPLE
18127 | VERBOSE
18128 ;
18129
18130 /* Reserved keyword --- these keywords are usable only as a ColLabel.
18131 *
18132 * Keywords appear here if they could not be distinguished from variable,
18133 * type, or function names in some contexts. Don't put things here unless
18134 * forced to.
18135 */
18136 reserved_keyword:
18137 ALL
18138 | ANALYSE
18139 | ANALYZE
18140 | AND
18141 | ANY
18142 | ARRAY
18143 | AS
18144 | ASC
18145 | ASYMMETRIC
18146 | BOTH
18147 | CASE
18148 | CAST
18149 | CHECK
18150 | COLLATE
18151 | COLUMN
18152 | CONSTRAINT
18153 | CREATE
18154 | CURRENT_CATALOG
18155 | CURRENT_DATE
18156 | CURRENT_ROLE
18157 | CURRENT_TIME
18158 | CURRENT_TIMESTAMP
18159 | CURRENT_USER
18160 | DEFAULT
18161 | DEFERRABLE
18162 | DESC
18163 | DISTINCT
18164 | DO
18165 | ELSE
18166 | END_P
18167 | EXCEPT
18168 | FALSE_P
18169 | FETCH
18170 | FOR
18171 | FOREIGN
18172 | FROM
18173 | GRANT
18174 | GROUP_P
18175 | HAVING
18176 | IN_P
18177 | INITIALLY
18178 | INTERSECT
18179 | INTO
18180 | LATERAL_P
18181 | LEADING
18182 | LIMIT
18183 | LOCALTIME
18184 | LOCALTIMESTAMP
18185 | NOT
18186 | NULL_P
18187 | OFFSET
18188 | ON
18189 | ONLY
18190 | OR
18191 | ORDER
18192 | PLACING
18193 | PRIMARY
18194 | REFERENCES
18195 | RETURNING
18196 | SELECT
18197 | SESSION_USER
18198 | SOME
18199 | SYMMETRIC
18200 | SYSTEM_USER
18201 | TABLE
18202 | THEN
18203 | TO
18204 | TRAILING
18205 | TRUE_P
18206 | UNION
18207 | UNIQUE
18208 | USER
18209 | USING
18210 | VARIADIC
18211 | WHEN
18212 | WHERE
18213 | WINDOW
18214 | WITH
18215 ;
18216
18217 /*
18218 * While all keywords can be used as column labels when preceded by AS,
18219 * not all of them can be used as a "bare" column label without AS.
18220 * Those that can be used as a bare label must be listed here,
18221 * in addition to appearing in one of the category lists above.
18222 *
18223 * Always add a new keyword to this list if possible. Mark it BARE_LABEL
18224 * in kwlist.h if it is included here, or AS_LABEL if it is not.
18225 */
18226 bare_label_keyword:
18227 ABORT_P
18228 | ABSENT
18229 | ABSOLUTE_P
18230 | ACCESS
18231 | ACTION
18232 | ADD_P
18233 | ADMIN
18234 | AFTER
18235 | AGGREGATE
18236 | ALL
18237 | ALSO
18238 | ALTER
18239 | ALWAYS
18240 | ANALYSE
18241 | ANALYZE
18242 | AND
18243 | ANY
18244 | ASC
18245 | ASENSITIVE
18246 | ASSERTION
18247 | ASSIGNMENT
18248 | ASYMMETRIC
18249 | AT
18250 | ATOMIC
18251 | ATTACH
18252 | ATTRIBUTE
18253 | AUTHORIZATION
18254 | BACKWARD
18255 | BEFORE
18256 | BEGIN_P
18257 | BETWEEN
18258 | BIGINT
18259 | BINARY
18260 | BIT
18261 | BOOLEAN_P
18262 | BOTH
18263 | BREADTH
18264 | BY
18265 | CACHE
18266 | CALL
18267 | CALLED
18268 | CASCADE
18269 | CASCADED
18270 | CASE
18271 | CAST
18272 | CATALOG_P
18273 | CHAIN
18274 | CHARACTERISTICS
18275 | CHECK
18276 | CHECKPOINT
18277 | CLASS
18278 | CLOSE
18279 | CLUSTER
18280 | COALESCE
18281 | COLLATE
18282 | COLLATION
18283 | COLUMN
18284 | COLUMNS
18285 | COMMENT
18286 | COMMENTS
18287 | COMMIT
18288 | COMMITTED
18289 | COMPRESSION
18290 | CONCURRENTLY
18291 | CONDITIONAL
18292 | CONFIGURATION
18293 | CONFLICT
18294 | CONNECTION
18295 | CONSTRAINT
18296 | CONSTRAINTS
18297 | CONTENT_P
18298 | CONTINUE_P
18299 | CONVERSION_P
18300 | COPY
18301 | COST
18302 | CROSS
18303 | CSV
18304 | CUBE
18305 | CURRENT_P
18306 | CURRENT_CATALOG
18307 | CURRENT_DATE
18308 | CURRENT_ROLE
18309 | CURRENT_SCHEMA
18310 | CURRENT_TIME
18311 | CURRENT_TIMESTAMP
18312 | CURRENT_USER
18313 | CURSOR
18314 | CYCLE
18315 | DATA_P
18316 | DATABASE
18317 | DEALLOCATE
18318 | DEC
18319 | DECIMAL_P
18320 | DECLARE
18321 | DEFAULT
18322 | DEFAULTS
18323 | DEFERRABLE
18324 | DEFERRED
18325 | DEFINER
18326 | DELETE_P
18327 | DELIMITER
18328 | DELIMITERS
18329 | DEPENDS
18330 | DEPTH
18331 | DESC
18332 | DETACH
18333 | DICTIONARY
18334 | DISABLE_P
18335 | DISCARD
18336 | DISTINCT
18337 | DO
18338 | DOCUMENT_P
18339 | DOMAIN_P
18340 | DOUBLE_P
18341 | DROP
18342 | EACH
18343 | ELSE
18344 | EMPTY_P
18345 | ENABLE_P
18346 | ENCODING
18347 | ENCRYPTED
18348 | END_P
18349 | ENFORCED
18350 | ENUM_P
18351 | ERROR_P
18352 | ESCAPE
18353 | EVENT
18354 | EXCLUDE
18355 | EXCLUDING
18356 | EXCLUSIVE
18357 | EXECUTE
18358 | EXISTS
18359 | EXPLAIN
18360 | EXPRESSION
18361 | EXTENSION
18362 | EXTERNAL
18363 | EXTRACT
18364 | FALSE_P
18365 | FAMILY
18366 | FINALIZE
18367 | FIRST_P
18368 | FLOAT_P
18369 | FOLLOWING
18370 | FORCE
18371 | FOREIGN
18372 | FORMAT
18373 | FORWARD
18374 | FREEZE
18375 | FULL
18376 | FUNCTION
18377 | FUNCTIONS
18378 | GENERATED
18379 | GLOBAL
18380 | GRANTED
18381 | GREATEST
18382 | GROUPING
18383 | GROUPS
18384 | HANDLER
18385 | HEADER_P
18386 | HOLD
18387 | IDENTITY_P
18388 | IF_P
18389 | ILIKE
18390 | IMMEDIATE
18391 | IMMUTABLE
18392 | IMPLICIT_P
18393 | IMPORT_P
18394 | IN_P
18395 | INCLUDE
18396 | INCLUDING
18397 | INCREMENT
18398 | INDENT
18399 | INDEX
18400 | INDEXES
18401 | INHERIT
18402 | INHERITS
18403 | INITIALLY
18404 | INLINE_P
18405 | INNER_P
18406 | INOUT
18407 | INPUT_P
18408 | INSENSITIVE
18409 | INSERT
18410 | INSTEAD
18411 | INT_P
18412 | INTEGER
18413 | INTERVAL
18414 | INVOKER
18415 | IS
18416 | ISOLATION
18417 | JOIN
18418 | JSON
18419 | JSON_ARRAY
18420 | JSON_ARRAYAGG
18421 | JSON_EXISTS
18422 | JSON_OBJECT
18423 | JSON_OBJECTAGG
18424 | JSON_QUERY
18425 | JSON_SCALAR
18426 | JSON_SERIALIZE
18427 | JSON_TABLE
18428 | JSON_VALUE
18429 | KEEP
18430 | KEY
18431 | KEYS
18432 | LABEL
18433 | LANGUAGE
18434 | LARGE_P
18435 | LAST_P
18436 | LATERAL_P
18437 | LEADING
18438 | LEAKPROOF
18439 | LEAST
18440 | LEFT
18441 | LEVEL
18442 | LIKE
18443 | LISTEN
18444 | LOAD
18445 | LOCAL
18446 | LOCALTIME
18447 | LOCALTIMESTAMP
18448 | LOCATION
18449 | LOCK_P
18450 | LOCKED
18451 | LOGGED
18452 | MAPPING
18453 | MATCH
18454 | MATCHED
18455 | MATERIALIZED
18456 | MAXVALUE
18457 | MERGE
18458 | MERGE_ACTION
18459 | METHOD
18460 | MINVALUE
18461 | MODE
18462 | MOVE
18463 | NAME_P
18464 | NAMES
18465 | NATIONAL
18466 | NATURAL
18467 | NCHAR
18468 | NESTED
18469 | NEW
18470 | NEXT
18471 | NFC
18472 | NFD
18473 | NFKC
18474 | NFKD
18475 | NO
18476 | NONE
18477 | NORMALIZE
18478 | NORMALIZED
18479 | NOT
18480 | NOTHING
18481 | NOTIFY
18482 | NOWAIT
18483 | NULL_P
18484 | NULLIF
18485 | NULLS_P
18486 | NUMERIC
18487 | OBJECT_P
18488 | OBJECTS_P
18489 | OF
18490 | OFF
18491 | OIDS
18492 | OLD
18493 | OMIT
18494 | ONLY
18495 | OPERATOR
18496 | OPTION
18497 | OPTIONS
18498 | OR
18499 | ORDINALITY
18500 | OTHERS
18501 | OUT_P
18502 | OUTER_P
18503 | OVERLAY
18504 | OVERRIDING
18505 | OWNED
18506 | OWNER
18507 | PARALLEL
18508 | PARAMETER
18509 | PARSER
18510 | PARTIAL
18511 | PARTITION
18512 | PASSING
18513 | PASSWORD
18514 | PATH
18515 | PERIOD
18516 | PLACING
18517 | PLAN
18518 | PLANS
18519 | POLICY
18520 | POSITION
18521 | PRECEDING
18522 | PREPARE
18523 | PREPARED
18524 | PRESERVE
18525 | PRIMARY
18526 | PRIOR
18527 | PRIVILEGES
18528 | PROCEDURAL
18529 | PROCEDURE
18530 | PROCEDURES
18531 | PROGRAM
18532 | PUBLICATION
18533 | QUOTE
18534 | QUOTES
18535 | RANGE
18536 | READ
18537 | REAL
18538 | REASSIGN
18539 | RECURSIVE
18540 | REF_P
18541 | REFERENCES
18542 | REFERENCING
18543 | REFRESH
18544 | REINDEX
18545 | RELATIVE_P
18546 | RELEASE
18547 | RENAME
18548 | REPEATABLE
18549 | REPLACE
18550 | REPLICA
18551 | RESET
18552 | RESTART
18553 | RESTRICT
18554 | RETURN
18555 | RETURNS
18556 | REVOKE
18557 | RIGHT
18558 | ROLE
18559 | ROLLBACK
18560 | ROLLUP
18561 | ROUTINE
18562 | ROUTINES
18563 | ROW
18564 | ROWS
18565 | RULE
18566 | SAVEPOINT
18567 | SCALAR
18568 | SCHEMA
18569 | SCHEMAS
18570 | SCROLL
18571 | SEARCH
18572 | SECURITY
18573 | SELECT
18574 | SEQUENCE
18575 | SEQUENCES
18576 | SERIALIZABLE
18577 | SERVER
18578 | SESSION
18579 | SESSION_USER
18580 | SET
18581 | SETOF
18582 | SETS
18583 | SHARE
18584 | SHOW
18585 | SIMILAR
18586 | SIMPLE
18587 | SKIP
18588 | SMALLINT
18589 | SNAPSHOT
18590 | SOME
18591 | SOURCE
18592 | SQL_P
18593 | STABLE
18594 | STANDALONE_P
18595 | START
18596 | STATEMENT
18597 | STATISTICS
18598 | STDIN
18599 | STDOUT
18600 | STORAGE
18601 | STORED
18602 | STRICT_P
18603 | STRING_P
18604 | STRIP_P
18605 | SUBSCRIPTION
18606 | SUBSTRING
18607 | SUPPORT
18608 | SYMMETRIC
18609 | SYSID
18610 | SYSTEM_P
18611 | SYSTEM_USER
18612 | TABLE
18613 | TABLES
18614 | TABLESAMPLE
18615 | TABLESPACE
18616 | TARGET
18617 | TEMP
18618 | TEMPLATE
18619 | TEMPORARY
18620 | TEXT_P
18621 | THEN
18622 | TIES
18623 | TIME
18624 | TIMESTAMP
18625 | TRAILING
18626 | TRANSACTION
18627 | TRANSFORM
18628 | TREAT
18629 | TRIGGER
18630 | TRIM
18631 | TRUE_P
18632 | TRUNCATE
18633 | TRUSTED
18634 | TYPE_P
18635 | TYPES_P
18636 | UESCAPE
18637 | UNBOUNDED
18638 | UNCOMMITTED
18639 | UNCONDITIONAL
18640 | UNENCRYPTED
18641 | UNIQUE
18642 | UNKNOWN
18643 | UNLISTEN
18644 | UNLOGGED
18645 | UNTIL
18646 | UPDATE
18647 | USER
18648 | USING
18649 | VACUUM
18650 | VALID
18651 | VALIDATE
18652 | VALIDATOR
18653 | VALUE_P
18654 | VALUES
18655 | VARCHAR
18656 | VARIADIC
18657 | VERBOSE
18658 | VERSION_P
18659 | VIEW
18660 | VIEWS
18661 | VIRTUAL
18662 | VOLATILE
18663 | WHEN
18664 | WHITESPACE_P
18665 | WORK
18666 | WRAPPER
18667 | WRITE
18668 | XML_P
18669 | XMLATTRIBUTES
18670 | XMLCONCAT
18671 | XMLELEMENT
18672 | XMLEXISTS
18673 | XMLFOREST
18674 | XMLNAMESPACES
18675 | XMLPARSE
18676 | XMLPI
18677 | XMLROOT
18678 | XMLSERIALIZE
18679 | XMLTABLE
18680 | YES_P
18681 | ZONE
18682 ;
18683
18684 %%
18685
18686 /*
18687 * The signature of this function is required by bison. However, we
18688 * ignore the passed yylloc and instead use the last token position
18689 * available from the scanner.
18690 */
18691 static void
18692 base_yyerror(YYLTYPE *yylloc, core_yyscan_t yyscanner, const char *msg)
18693 {
18694 parser_yyerror(msg);
18695 }
18696
18697 static RawStmt *
18698 makeRawStmt(Node *stmt, int stmt_location)
18699 {
18700 RawStmt *rs = makeNode(RawStmt);
18701
18702 rs->stmt = stmt;
18703 rs->stmt_location = stmt_location;
18704 rs->stmt_len = 0; /* might get changed later */
18705 return rs;
18706 }
18707
18708 /* Adjust a RawStmt to reflect that it doesn't run to the end of the string */
18709 static void
18710 updateRawStmtEnd(RawStmt *rs, int end_location)
18711 {
18712 /*
18713 * If we already set the length, don't change it. This is for situations
18714 * like "select foo ;; select bar" where the same statement will be last
18715 * in the string for more than one semicolon.
18716 */
18717 if (rs->stmt_len > 0)
18718 return;
18719
18720 /* OK, update length of RawStmt */
18721 rs->stmt_len = end_location - rs->stmt_location;
18722 }
18723
18724 static Node *
18725 makeColumnRef(char *colname, List *indirection,
18726 int location, core_yyscan_t yyscanner)
18727 {
18728 /*
18729 * Generate a ColumnRef node, with an A_Indirection node added if there is
18730 * any subscripting in the specified indirection list. However, any field
18731 * selection at the start of the indirection list must be transposed into
18732 * the "fields" part of the ColumnRef node.
18733 */
18734 ColumnRef *c = makeNode(ColumnRef);
18735 int nfields = 0;
18736 ListCell *l;
18737
18738 c->location = location;
18739 foreach(l, indirection)
18740 {
18741 if (IsA(lfirst(l), A_Indices))
18742 {
18743 A_Indirection *i = makeNode(A_Indirection);
18744
18745 if (nfields == 0)
18746 {
18747 /* easy case - all indirection goes to A_Indirection */
18748 c->fields = list_make1(makeString(colname));
18749 i->indirection = check_indirection(indirection, yyscanner);
18750 }
18751 else
18752 {
18753 /* got to split the list in two */
18754 i->indirection = check_indirection(list_copy_tail(indirection,
18755 nfields),
18756 yyscanner);
18757 indirection = list_truncate(indirection, nfields);
18758 c->fields = lcons(makeString(colname), indirection);
18759 }
18760 i->arg = (Node *) c;
18761 return (Node *) i;
18762 }
18763 else if (IsA(lfirst(l), A_Star))
18764 {
18765 /* We only allow '*' at the end of a ColumnRef */
18766 if (lnext(indirection, l) != NULL)
18767 parser_yyerror("improper use of \"*\"");
18768 }
18769 nfields++;
18770 }
18771 /* No subscripting, so all indirection gets added to field list */
18772 c->fields = lcons(makeString(colname), indirection);
18773 return (Node *) c;
18774 }
18775
18776 static Node *
18777 makeTypeCast(Node *arg, TypeName *typename, int location)
18778 {
18779 TypeCast *n = makeNode(TypeCast);
18780
18781 n->arg = arg;
18782 n->typeName = typename;
18783 n->location = location;
18784 return (Node *) n;
18785 }
18786
18787 static Node *
18788 makeStringConstCast(char *str, int location, TypeName *typename)
18789 {
18790 Node *s = makeStringConst(str, location);
18791
18792 return makeTypeCast(s, typename, -1);
18793 }
18794
18795 static Node *
18796 makeIntConst(int val, int location)
18797 {
18798 A_Const *n = makeNode(A_Const);
18799
18800 n->val.ival.type = T_Integer;
18801 n->val.ival.ival = val;
18802 n->location = location;
18803
18804 return (Node *) n;
18805 }
18806
18807 static Node *
18808 makeFloatConst(char *str, int location)
18809 {
18810 A_Const *n = makeNode(A_Const);
18811
18812 n->val.fval.type = T_Float;
18813 n->val.fval.fval = str;
18814 n->location = location;
18815
18816 return (Node *) n;
18817 }
18818
18819 static Node *
18820 makeBoolAConst(bool state, int location)
18821 {
18822 A_Const *n = makeNode(A_Const);
18823
18824 n->val.boolval.type = T_Boolean;
18825 n->val.boolval.boolval = state;
18826 n->location = location;
18827
18828 return (Node *) n;
18829 }
18830
18831 static Node *
18832 makeBitStringConst(char *str, int location)
18833 {
18834 A_Const *n = makeNode(A_Const);
18835
18836 n->val.bsval.type = T_BitString;
18837 n->val.bsval.bsval = str;
18838 n->location = location;
18839
18840 return (Node *) n;
18841 }
18842
18843 static Node *
18844 makeNullAConst(int location)
18845 {
18846 A_Const *n = makeNode(A_Const);
18847
18848 n->isnull = true;
18849 n->location = location;
18850
18851 return (Node *) n;
18852 }
18853
18854 static Node *
18855 makeAConst(Node *v, int location)
18856 {
18857 Node *n;
18858
18859 switch (v->type)
18860 {
18861 case T_Float:
18862 n = makeFloatConst(castNode(Float, v)->fval, location);
18863 break;
18864
18865 case T_Integer:
18866 n = makeIntConst(castNode(Integer, v)->ival, location);
18867 break;
18868
18869 default:
18870 /* currently not used */
18871 Assert(false);
18872 n = NULL;
18873 }
18874
18875 return n;
18876 }
18877
18878 /* makeRoleSpec
18879 * Create a RoleSpec with the given type
18880 */
18881 static RoleSpec *
18882 makeRoleSpec(RoleSpecType type, int location)
18883 {
18884 RoleSpec *spec = makeNode(RoleSpec);
18885
18886 spec->roletype = type;
18887 spec->location = location;
18888
18889 return spec;
18890 }
18891
18892 /* check_qualified_name --- check the result of qualified_name production
18893 *
18894 * It's easiest to let the grammar production for qualified_name allow
18895 * subscripts and '*', which we then must reject here.
18896 */
18897 static void
18898 check_qualified_name(List *names, core_yyscan_t yyscanner)
18899 {
18900 ListCell *i;
18901
18902 foreach(i, names)
18903 {
18904 if (!IsA(lfirst(i), String))
18905 parser_yyerror("syntax error");
18906 }
18907 }
18908
18909 /* check_func_name --- check the result of func_name production
18910 *
18911 * It's easiest to let the grammar production for func_name allow subscripts
18912 * and '*', which we then must reject here.
18913 */
18914 static List *
18915 check_func_name(List *names, core_yyscan_t yyscanner)
18916 {
18917 ListCell *i;
18918
18919 foreach(i, names)
18920 {
18921 if (!IsA(lfirst(i), String))
18922 parser_yyerror("syntax error");
18923 }
18924 return names;
18925 }
18926
18927 /* check_indirection --- check the result of indirection production
18928 *
18929 * We only allow '*' at the end of the list, but it's hard to enforce that
18930 * in the grammar, so do it here.
18931 */
18932 static List *
18933 check_indirection(List *indirection, core_yyscan_t yyscanner)
18934 {
18935 ListCell *l;
18936
18937 foreach(l, indirection)
18938 {
18939 if (IsA(lfirst(l), A_Star))
18940 {
18941 if (lnext(indirection, l) != NULL)
18942 parser_yyerror("improper use of \"*\"");
18943 }
18944 }
18945 return indirection;
18946 }
18947
18948 /* extractArgTypes()
18949 * Given a list of FunctionParameter nodes, extract a list of just the
18950 * argument types (TypeNames) for input parameters only. This is what
18951 * is needed to look up an existing function, which is what is wanted by
18952 * the productions that use this call.
18953 */
18954 static List *
18955 extractArgTypes(List *parameters)
18956 {
18957 List *result = NIL;
18958 ListCell *i;
18959
18960 foreach(i, parameters)
18961 {
18962 FunctionParameter *p = (FunctionParameter *) lfirst(i);
18963
18964 if (p->mode != FUNC_PARAM_OUT && p->mode != FUNC_PARAM_TABLE)
18965 result = lappend(result, p->argType);
18966 }
18967 return result;
18968 }
18969
18970 /* extractAggrArgTypes()
18971 * As above, but work from the output of the aggr_args production.
18972 */
18973 static List *
18974 extractAggrArgTypes(List *aggrargs)
18975 {
18976 Assert(list_length(aggrargs) == 2);
18977 return extractArgTypes((List *) linitial(aggrargs));
18978 }
18979
18980 /* makeOrderedSetArgs()
18981 * Build the result of the aggr_args production (which see the comments for).
18982 * This handles only the case where both given lists are nonempty, so that
18983 * we have to deal with multiple VARIADIC arguments.
18984 */
18985 static List *
18986 makeOrderedSetArgs(List *directargs, List *orderedargs,
18987 core_yyscan_t yyscanner)
18988 {
18989 FunctionParameter *lastd = (FunctionParameter *) llast(directargs);
18990 Integer *ndirectargs;
18991
18992 /* No restriction unless last direct arg is VARIADIC */
18993 if (lastd->mode == FUNC_PARAM_VARIADIC)
18994 {
18995 FunctionParameter *firsto = (FunctionParameter *) linitial(orderedargs);
18996
18997 /*
18998 * We ignore the names, though the aggr_arg production allows them; it
18999 * doesn't allow default values, so those need not be checked.
19000 */
19001 if (list_length(orderedargs) != 1 ||
19002 firsto->mode != FUNC_PARAM_VARIADIC ||
19003 !equal(lastd->argType, firsto->argType))
19004 ereport(ERROR,
19005 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
19006 errmsg("an ordered-set aggregate with a VARIADIC direct argument must have one VARIADIC aggregated argument of the same data type"),
19007 parser_errposition(firsto->location)));
19008
19009 /* OK, drop the duplicate VARIADIC argument from the internal form */
19010 orderedargs = NIL;
19011 }
19012
19013 /* don't merge into the next line, as list_concat changes directargs */
19014 ndirectargs = makeInteger(list_length(directargs));
19015
19016 return list_make2(list_concat(directargs, orderedargs),
19017 ndirectargs);
19018 }
19019
19020 /* insertSelectOptions()
19021 * Insert ORDER BY, etc into an already-constructed SelectStmt.
19022 *
19023 * This routine is just to avoid duplicating code in SelectStmt productions.
19024 */
19025 static void
19026 insertSelectOptions(SelectStmt *stmt,
19027 List *sortClause, List *lockingClause,
19028 SelectLimit *limitClause,
19029 WithClause *withClause,
19030 core_yyscan_t yyscanner)
19031 {
19032 Assert(IsA(stmt, SelectStmt));
19033
19034 /*
19035 * Tests here are to reject constructs like
19036 * (SELECT foo ORDER BY bar) ORDER BY baz
19037 */
19038 if (sortClause)
19039 {
19040 if (stmt->sortClause)
19041 ereport(ERROR,
19042 (errcode(ERRCODE_SYNTAX_ERROR),
19043 errmsg("multiple ORDER BY clauses not allowed"),
19044 parser_errposition(exprLocation((Node *) sortClause))));
19045 stmt->sortClause = sortClause;
19046 }
19047 /* We can handle multiple locking clauses, though */
19048 stmt->lockingClause = list_concat(stmt->lockingClause, lockingClause);
19049 if (limitClause && limitClause->limitOffset)
19050 {
19051 if (stmt->limitOffset)
19052 ereport(ERROR,
19053 (errcode(ERRCODE_SYNTAX_ERROR),
19054 errmsg("multiple OFFSET clauses not allowed"),
19055 parser_errposition(limitClause->offsetLoc)));
19056 stmt->limitOffset = limitClause->limitOffset;
19057 }
19058 if (limitClause && limitClause->limitCount)
19059 {
19060 if (stmt->limitCount)
19061 ereport(ERROR,
19062 (errcode(ERRCODE_SYNTAX_ERROR),
19063 errmsg("multiple LIMIT clauses not allowed"),
19064 parser_errposition(limitClause->countLoc)));
19065 stmt->limitCount = limitClause->limitCount;
19066 }
19067 if (limitClause)
19068 {
19069 /* If there was a conflict, we must have detected it above */
19070 Assert(!stmt->limitOption);
19071 if (!stmt->sortClause && limitClause->limitOption == LIMIT_OPTION_WITH_TIES)
19072 ereport(ERROR,
19073 (errcode(ERRCODE_SYNTAX_ERROR),
19074 errmsg("WITH TIES cannot be specified without ORDER BY clause"),
19075 parser_errposition(limitClause->optionLoc)));
19076 if (limitClause->limitOption == LIMIT_OPTION_WITH_TIES && stmt->lockingClause)
19077 {
19078 ListCell *lc;
19079
19080 foreach(lc, stmt->lockingClause)
19081 {
19082 LockingClause *lock = lfirst_node(LockingClause, lc);
19083
19084 if (lock->waitPolicy == LockWaitSkip)
19085 ereport(ERROR,
19086 (errcode(ERRCODE_SYNTAX_ERROR),
19087 errmsg("%s and %s options cannot be used together",
19088 "SKIP LOCKED", "WITH TIES"),
19089 parser_errposition(limitClause->optionLoc)));
19090 }
19091 }
19092 stmt->limitOption = limitClause->limitOption;
19093 }
19094 if (withClause)
19095 {
19096 if (stmt->withClause)
19097 ereport(ERROR,
19098 (errcode(ERRCODE_SYNTAX_ERROR),
19099 errmsg("multiple WITH clauses not allowed"),
19100 parser_errposition(exprLocation((Node *) withClause))));
19101 stmt->withClause = withClause;
19102 }
19103 }
19104
19105 static Node *
19106 makeSetOp(SetOperation op, bool all, Node *larg, Node *rarg)
19107 {
19108 SelectStmt *n = makeNode(SelectStmt);
19109
19110 n->op = op;
19111 n->all = all;
19112 n->larg = (SelectStmt *) larg;
19113 n->rarg = (SelectStmt *) rarg;
19114 return (Node *) n;
19115 }
19116
19117 /* SystemFuncName()
19118 * Build a properly-qualified reference to a built-in function.
19119 */
19120 List *
19121 SystemFuncName(char *name)
19122 {
19123 return list_make2(makeString("pg_catalog"), makeString(name));
19124 }
19125
19126 /* SystemTypeName()
19127 * Build a properly-qualified reference to a built-in type.
19128 *
19129 * typmod is defaulted, but may be changed afterwards by caller.
19130 * Likewise for the location.
19131 */
19132 TypeName *
19133 SystemTypeName(char *name)
19134 {
19135 return makeTypeNameFromNameList(list_make2(makeString("pg_catalog"),
19136 makeString(name)));
19137 }
19138
19139 /* doNegate()
19140 * Handle negation of a numeric constant.
19141 *
19142 * Formerly, we did this here because the optimizer couldn't cope with
19143 * indexquals that looked like "var = -4" --- it wants "var = const"
19144 * and a unary minus operator applied to a constant didn't qualify.
19145 * As of Postgres 7.0, that problem doesn't exist anymore because there
19146 * is a constant-subexpression simplifier in the optimizer. However,
19147 * there's still a good reason for doing this here, which is that we can
19148 * postpone committing to a particular internal representation for simple
19149 * negative constants. It's better to leave "-123.456" in string form
19150 * until we know what the desired type is.
19151 */
19152 static Node *
19153 doNegate(Node *n, int location)
19154 {
19155 if (IsA(n, A_Const))
19156 {
19157 A_Const *con = (A_Const *) n;
19158
19159 /* report the constant's location as that of the '-' sign */
19160 con->location = location;
19161
19162 if (IsA(&con->val, Integer))
19163 {
19164 con->val.ival.ival = -con->val.ival.ival;
19165 return n;
19166 }
19167 if (IsA(&con->val, Float))
19168 {
19169 doNegateFloat(&con->val.fval);
19170 return n;
19171 }
19172 }
19173
19174 return (Node *) makeSimpleA_Expr(AEXPR_OP, "-", NULL, n, location);
19175 }
19176
19177 static void
19178 doNegateFloat(Float *v)
19179 {
19180 char *oldval = v->fval;
19181
19182 if (*oldval == '+')
19183 oldval++;
19184 if (*oldval == '-')
19185 v->fval = oldval + 1; /* just strip the '-' */
19186 else
19187 v->fval = psprintf("-%s", oldval);
19188 }
19189
19190 static Node *
19191 makeAndExpr(Node *lexpr, Node *rexpr, int location)
19192 {
19193 /* Flatten "a AND b AND c ..." to a single BoolExpr on sight */
19194 if (IsA(lexpr, BoolExpr))
19195 {
19196 BoolExpr *blexpr = (BoolExpr *) lexpr;
19197
19198 if (blexpr->boolop == AND_EXPR)
19199 {
19200 blexpr->args = lappend(blexpr->args, rexpr);
19201 return (Node *) blexpr;
19202 }
19203 }
19204 return (Node *) makeBoolExpr(AND_EXPR, list_make2(lexpr, rexpr), location);
19205 }
19206
19207 static Node *
19208 makeOrExpr(Node *lexpr, Node *rexpr, int location)
19209 {
19210 /* Flatten "a OR b OR c ..." to a single BoolExpr on sight */
19211 if (IsA(lexpr, BoolExpr))
19212 {
19213 BoolExpr *blexpr = (BoolExpr *) lexpr;
19214
19215 if (blexpr->boolop == OR_EXPR)
19216 {
19217 blexpr->args = lappend(blexpr->args, rexpr);
19218 return (Node *) blexpr;
19219 }
19220 }
19221 return (Node *) makeBoolExpr(OR_EXPR, list_make2(lexpr, rexpr), location);
19222 }
19223
19224 static Node *
19225 makeNotExpr(Node *expr, int location)
19226 {
19227 return (Node *) makeBoolExpr(NOT_EXPR, list_make1(expr), location);
19228 }
19229
19230 static Node *
19231 makeAArrayExpr(List *elements, int location, int location_end)
19232 {
19233 A_ArrayExpr *n = makeNode(A_ArrayExpr);
19234
19235 n->elements = elements;
19236 n->location = location;
19237 n->list_start = location;
19238 n->list_end = location_end;
19239 return (Node *) n;
19240 }
19241
19242 static Node *
19243 makeSQLValueFunction(SQLValueFunctionOp op, int32 typmod, int location)
19244 {
19245 SQLValueFunction *svf = makeNode(SQLValueFunction);
19246
19247 svf->op = op;
19248 /* svf->type will be filled during parse analysis */
19249 svf->typmod = typmod;
19250 svf->location = location;
19251 return (Node *) svf;
19252 }
19253
19254 static Node *
19255 makeXmlExpr(XmlExprOp op, char *name, List *named_args, List *args,
19256 int location)
19257 {
19258 XmlExpr *x = makeNode(XmlExpr);
19259
19260 x->op = op;
19261 x->name = name;
19262
19263 /*
19264 * named_args is a list of ResTarget; it'll be split apart into separate
19265 * expression and name lists in transformXmlExpr().
19266 */
19267 x->named_args = named_args;
19268 x->arg_names = NIL;
19269 x->args = args;
19270 /* xmloption, if relevant, must be filled in by caller */
19271 /* type and typmod will be filled in during parse analysis */
19272 x->type = InvalidOid; /* marks the node as not analyzed */
19273 x->location = location;
19274 return (Node *) x;
19275 }
19276
19277 /*
19278 * Merge the input and output parameters of a table function.
19279 */
19280 static List *
19281 mergeTableFuncParameters(List *func_args, List *columns, core_yyscan_t yyscanner)
19282 {
19283 ListCell *lc;
19284
19285 /* Explicit OUT and INOUT parameters shouldn't be used in this syntax */
19286 foreach(lc, func_args)
19287 {
19288 FunctionParameter *p = (FunctionParameter *) lfirst(lc);
19289
19290 if (p->mode != FUNC_PARAM_DEFAULT &&
19291 p->mode != FUNC_PARAM_IN &&
19292 p->mode != FUNC_PARAM_VARIADIC)
19293 ereport(ERROR,
19294 (errcode(ERRCODE_SYNTAX_ERROR),
19295 errmsg("OUT and INOUT arguments aren't allowed in TABLE functions"),
19296 parser_errposition(p->location)));
19297 }
19298
19299 return list_concat(func_args, columns);
19300 }
19301
19302 /*
19303 * Determine return type of a TABLE function. A single result column
19304 * returns setof that column's type; otherwise return setof record.
19305 */
19306 static TypeName *
19307 TableFuncTypeName(List *columns)
19308 {
19309 TypeName *result;
19310
19311 if (list_length(columns) == 1)
19312 {
19313 FunctionParameter *p = (FunctionParameter *) linitial(columns);
19314
19315 result = copyObject(p->argType);
19316 }
19317 else
19318 result = SystemTypeName("record");
19319
19320 result->setof = true;
19321
19322 return result;
19323 }
19324
19325 /*
19326 * Convert a list of (dotted) names to a RangeVar (like
19327 * makeRangeVarFromNameList, but with position support). The
19328 * "AnyName" refers to the any_name production in the grammar.
19329 */
19330 static RangeVar *
19331 makeRangeVarFromAnyName(List *names, int position, core_yyscan_t yyscanner)
19332 {
19333 RangeVar *r = makeNode(RangeVar);
19334
19335 switch (list_length(names))
19336 {
19337 case 1:
19338 r->catalogname = NULL;
19339 r->schemaname = NULL;
19340 r->relname = strVal(linitial(names));
19341 break;
19342 case 2:
19343 r->catalogname = NULL;
19344 r->schemaname = strVal(linitial(names));
19345 r->relname = strVal(lsecond(names));
19346 break;
19347 case 3:
19348 r->catalogname = strVal(linitial(names));
19349 r->schemaname = strVal(lsecond(names));
19350 r->relname = strVal(lthird(names));
19351 break;
19352 default:
19353 ereport(ERROR,
19354 (errcode(ERRCODE_SYNTAX_ERROR),
19355 errmsg("improper qualified name (too many dotted names): %s",
19356 NameListToString(names)),
19357 parser_errposition(position)));
19358 break;
19359 }
19360
19361 r->relpersistence = RELPERSISTENCE_PERMANENT;
19362 r->location = position;
19363
19364 return r;
19365 }
19366
19367 /*
19368 * Convert a relation_name with name and namelist to a RangeVar using
19369 * makeRangeVar.
19370 */
19371 static RangeVar *
19372 makeRangeVarFromQualifiedName(char *name, List *namelist, int location,
19373 core_yyscan_t yyscanner)
19374 {
19375 RangeVar *r;
19376
19377 check_qualified_name(namelist, yyscanner);
19378 r = makeRangeVar(NULL, NULL, location);
19379
19380 switch (list_length(namelist))
19381 {
19382 case 1:
19383 r->catalogname = NULL;
19384 r->schemaname = name;
19385 r->relname = strVal(linitial(namelist));
19386 break;
19387 case 2:
19388 r->catalogname = name;
19389 r->schemaname = strVal(linitial(namelist));
19390 r->relname = strVal(lsecond(namelist));
19391 break;
19392 default:
19393 ereport(ERROR,
19394 errcode(ERRCODE_SYNTAX_ERROR),
19395 errmsg("improper qualified name (too many dotted names): %s",
19396 NameListToString(lcons(makeString(name), namelist))),
19397 parser_errposition(location));
19398 break;
19399 }
19400
19401 return r;
19402 }
19403
19404 /* Separate Constraint nodes from COLLATE clauses in a ColQualList */
19405 static void
19406 SplitColQualList(List *qualList,
19407 List **constraintList, CollateClause **collClause,
19408 core_yyscan_t yyscanner)
19409 {
19410 ListCell *cell;
19411
19412 *collClause = NULL;
19413 foreach(cell, qualList)
19414 {
19415 Node *n = (Node *) lfirst(cell);
19416
19417 if (IsA(n, Constraint))
19418 {
19419 /* keep it in list */
19420 continue;
19421 }
19422 if (IsA(n, CollateClause))
19423 {
19424 CollateClause *c = (CollateClause *) n;
19425
19426 if (*collClause)
19427 ereport(ERROR,
19428 (errcode(ERRCODE_SYNTAX_ERROR),
19429 errmsg("multiple COLLATE clauses not allowed"),
19430 parser_errposition(c->location)));
19431 *collClause = c;
19432 }
19433 else
19434 elog(ERROR, "unexpected node type %d", (int) n->type);
19435 /* remove non-Constraint nodes from qualList */
19436 qualList = foreach_delete_current(qualList, cell);
19437 }
19438 *constraintList = qualList;
19439 }
19440
19441 /*
19442 * Process result of ConstraintAttributeSpec, and set appropriate bool flags
19443 * in the output command node. Pass NULL for any flags the particular
19444 * command doesn't support.
19445 */
19446 static void
19447 processCASbits(int cas_bits, int location, const char *constrType,
19448 bool *deferrable, bool *initdeferred, bool *is_enforced,
19449 bool *not_valid, bool *no_inherit, core_yyscan_t yyscanner)
19450 {
19451 /* defaults */
19452 if (deferrable)
19453 *deferrable = false;
19454 if (initdeferred)
19455 *initdeferred = false;
19456 if (not_valid)
19457 *not_valid = false;
19458 if (is_enforced)
19459 *is_enforced = true;
19460
19461 if (cas_bits & (CAS_DEFERRABLE | CAS_INITIALLY_DEFERRED))
19462 {
19463 if (deferrable)
19464 *deferrable = true;
19465 else
19466 ereport(ERROR,
19467 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
19468 /* translator: %s is CHECK, UNIQUE, or similar */
19469 errmsg("%s constraints cannot be marked DEFERRABLE",
19470 constrType),
19471 parser_errposition(location)));
19472 }
19473
19474 if (cas_bits & CAS_INITIALLY_DEFERRED)
19475 {
19476 if (initdeferred)
19477 *initdeferred = true;
19478 else
19479 ereport(ERROR,
19480 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
19481 /* translator: %s is CHECK, UNIQUE, or similar */
19482 errmsg("%s constraints cannot be marked DEFERRABLE",
19483 constrType),
19484 parser_errposition(location)));
19485 }
19486
19487 if (cas_bits & CAS_NOT_VALID)
19488 {
19489 if (not_valid)
19490 *not_valid = true;
19491 else
19492 ereport(ERROR,
19493 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
19494 /* translator: %s is CHECK, UNIQUE, or similar */
19495 errmsg("%s constraints cannot be marked NOT VALID",
19496 constrType),
19497 parser_errposition(location)));
19498 }
19499
19500 if (cas_bits & CAS_NO_INHERIT)
19501 {
19502 if (no_inherit)
19503 *no_inherit = true;
19504 else
19505 ereport(ERROR,
19506 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
19507 /* translator: %s is CHECK, UNIQUE, or similar */
19508 errmsg("%s constraints cannot be marked NO INHERIT",
19509 constrType),
19510 parser_errposition(location)));
19511 }
19512
19513 if (cas_bits & CAS_NOT_ENFORCED)
19514 {
19515 if (is_enforced)
19516 *is_enforced = false;
19517 else
19518 ereport(ERROR,
19519 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
19520 /* translator: %s is CHECK, UNIQUE, or similar */
19521 errmsg("%s constraints cannot be marked NOT ENFORCED",
19522 constrType),
19523 parser_errposition(location)));
19524
19525 /*
19526 * NB: The validated status is irrelevant when the constraint is set to
19527 * NOT ENFORCED, but for consistency, it should be set accordingly.
19528 * This ensures that if the constraint is later changed to ENFORCED, it
19529 * will automatically be in the correct NOT VALIDATED state.
19530 */
19531 if (not_valid)
19532 *not_valid = true;
19533 }
19534
19535 if (cas_bits & CAS_ENFORCED)
19536 {
19537 if (is_enforced)
19538 *is_enforced = true;
19539 else
19540 ereport(ERROR,
19541 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
19542 /* translator: %s is CHECK, UNIQUE, or similar */
19543 errmsg("%s constraints cannot be marked ENFORCED",
19544 constrType),
19545 parser_errposition(location)));
19546 }
19547 }
19548
19549 /*
19550 * Parse a user-supplied partition strategy string into parse node
19551 * PartitionStrategy representation, or die trying.
19552 */
19553 static PartitionStrategy
19554 parsePartitionStrategy(char *strategy, int location, core_yyscan_t yyscanner)
19555 {
19556 if (pg_strcasecmp(strategy, "list") == 0)
19557 return PARTITION_STRATEGY_LIST;
19558 else if (pg_strcasecmp(strategy, "range") == 0)
19559 return PARTITION_STRATEGY_RANGE;
19560 else if (pg_strcasecmp(strategy, "hash") == 0)
19561 return PARTITION_STRATEGY_HASH;
19562
19563 ereport(ERROR,
19564 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
19565 errmsg("unrecognized partitioning strategy \"%s\"", strategy),
19566 parser_errposition(location)));
19567 return PARTITION_STRATEGY_LIST; /* keep compiler quiet */
19568
19569 }
19570
19571 /*
19572 * Process pubobjspec_list to check for errors in any of the objects and
19573 * convert PUBLICATIONOBJ_CONTINUATION into appropriate PublicationObjSpecType.
19574 */
19575 static void
19576 preprocess_pubobj_list(List *pubobjspec_list, core_yyscan_t yyscanner)
19577 {
19578 ListCell *cell;
19579 PublicationObjSpec *pubobj;
19580 PublicationObjSpecType prevobjtype = PUBLICATIONOBJ_CONTINUATION;
19581
19582 if (!pubobjspec_list)
19583 return;
19584
19585 pubobj = (PublicationObjSpec *) linitial(pubobjspec_list);
19586 if (pubobj->pubobjtype == PUBLICATIONOBJ_CONTINUATION)
19587 ereport(ERROR,
19588 errcode(ERRCODE_SYNTAX_ERROR),
19589 errmsg("invalid publication object list"),
19590 errdetail("One of TABLE or TABLES IN SCHEMA must be specified before a standalone table or schema name."),
19591 parser_errposition(pubobj->location));
19592
19593 foreach(cell, pubobjspec_list)
19594 {
19595 pubobj = (PublicationObjSpec *) lfirst(cell);
19596
19597 if (pubobj->pubobjtype == PUBLICATIONOBJ_CONTINUATION)
19598 pubobj->pubobjtype = prevobjtype;
19599
19600 if (pubobj->pubobjtype == PUBLICATIONOBJ_TABLE)
19601 {
19602 /* relation name or pubtable must be set for this type of object */
19603 if (!pubobj->name && !pubobj->pubtable)
19604 ereport(ERROR,
19605 errcode(ERRCODE_SYNTAX_ERROR),
19606 errmsg("invalid table name"),
19607 parser_errposition(pubobj->location));
19608
19609 if (pubobj->name)
19610 {
19611 /* convert it to PublicationTable */
19612 PublicationTable *pubtable = makeNode(PublicationTable);
19613
19614 pubtable->relation =
19615 makeRangeVar(NULL, pubobj->name, pubobj->location);
19616 pubobj->pubtable = pubtable;
19617 pubobj->name = NULL;
19618 }
19619 }
19620 else if (pubobj->pubobjtype == PUBLICATIONOBJ_TABLES_IN_SCHEMA ||
19621 pubobj->pubobjtype == PUBLICATIONOBJ_TABLES_IN_CUR_SCHEMA)
19622 {
19623 /* WHERE clause is not allowed on a schema object */
19624 if (pubobj->pubtable && pubobj->pubtable->whereClause)
19625 ereport(ERROR,
19626 errcode(ERRCODE_SYNTAX_ERROR),
19627 errmsg("WHERE clause not allowed for schema"),
19628 parser_errposition(pubobj->location));
19629
19630 /* Column list is not allowed on a schema object */
19631 if (pubobj->pubtable && pubobj->pubtable->columns)
19632 ereport(ERROR,
19633 errcode(ERRCODE_SYNTAX_ERROR),
19634 errmsg("column specification not allowed for schema"),
19635 parser_errposition(pubobj->location));
19636
19637 /*
19638 * We can distinguish between the different type of schema objects
19639 * based on whether name and pubtable is set.
19640 */
19641 if (pubobj->name)
19642 pubobj->pubobjtype = PUBLICATIONOBJ_TABLES_IN_SCHEMA;
19643 else if (!pubobj->name && !pubobj->pubtable)
19644 pubobj->pubobjtype = PUBLICATIONOBJ_TABLES_IN_CUR_SCHEMA;
19645 else
19646 ereport(ERROR,
19647 errcode(ERRCODE_SYNTAX_ERROR),
19648 errmsg("invalid schema name"),
19649 parser_errposition(pubobj->location));
19650 }
19651
19652 prevobjtype = pubobj->pubobjtype;
19653 }
19654 }
19655
19656 /*----------
19657 * Recursive view transformation
19658 *
19659 * Convert
19660 *
19661 * CREATE RECURSIVE VIEW relname (aliases) AS query
19662 *
19663 * to
19664 *
19665 * CREATE VIEW relname (aliases) AS
19666 * WITH RECURSIVE relname (aliases) AS (query)
19667 * SELECT aliases FROM relname
19668 *
19669 * Actually, just the WITH ... part, which is then inserted into the original
19670 * view definition as the query.
19671 * ----------
19672 */
19673 static Node *
19674 makeRecursiveViewSelect(char *relname, List *aliases, Node *query)
19675 {
19676 SelectStmt *s = makeNode(SelectStmt);
19677 WithClause *w = makeNode(WithClause);
19678 CommonTableExpr *cte = makeNode(CommonTableExpr);
19679 List *tl = NIL;
19680 ListCell *lc;
19681
19682 /* create common table expression */
19683 cte->ctename = relname;
19684 cte->aliascolnames = aliases;
19685 cte->ctematerialized = CTEMaterializeDefault;
19686 cte->ctequery = query;
19687 cte->location = -1;
19688
19689 /* create WITH clause and attach CTE */
19690 w->recursive = true;
19691 w->ctes = list_make1(cte);
19692 w->location = -1;
19693
19694 /*
19695 * create target list for the new SELECT from the alias list of the
19696 * recursive view specification
19697 */
19698 foreach(lc, aliases)
19699 {
19700 ResTarget *rt = makeNode(ResTarget);
19701
19702 rt->name = NULL;
19703 rt->indirection = NIL;
19704 rt->val = makeColumnRef(strVal(lfirst(lc)), NIL, -1, 0);
19705 rt->location = -1;
19706
19707 tl = lappend(tl, rt);
19708 }
19709
19710 /*
19711 * create new SELECT combining WITH clause, target list, and fake FROM
19712 * clause
19713 */
19714 s->withClause = w;
19715 s->targetList = tl;
19716 s->fromClause = list_make1(makeRangeVar(NULL, relname, -1));
19717
19718 return (Node *) s;
19719 }
19720
19721 /* parser_init()
19722 * Initialize to parse one query string
19723 */
19724 void
19725 parser_init(base_yy_extra_type *yyext)
19726 {
19727 yyext->parsetree = NIL; /* in case grammar forgets to set it */
19728 }