Line data Source code
1 : %{
2 :
3 : /*#define YYDEBUG 1*/
4 : /*-------------------------------------------------------------------------
5 : *
6 : * gram.y
7 : * POSTGRESQL BISON rules/actions
8 : *
9 : * Portions Copyright (c) 1996-2017, 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 "nodes/makefuncs.h"
58 : #include "nodes/nodeFuncs.h"
59 : #include "parser/gramparse.h"
60 : #include "parser/parser.h"
61 : #include "parser/parse_expr.h"
62 : #include "storage/lmgr.h"
63 : #include "utils/date.h"
64 : #include "utils/datetime.h"
65 : #include "utils/numeric.h"
66 : #include "utils/xml.h"
67 :
68 :
69 : /*
70 : * Location tracking support --- simpler than bison's default, since we only
71 : * want to track the start position not the end position of each nonterminal.
72 : */
73 : #define YYLLOC_DEFAULT(Current, Rhs, N) \
74 : do { \
75 : if ((N) > 0) \
76 : (Current) = (Rhs)[1]; \
77 : else \
78 : (Current) = (-1); \
79 : } while (0)
80 :
81 : /*
82 : * The above macro assigns -1 (unknown) as the parse location of any
83 : * nonterminal that was reduced from an empty rule, or whose leftmost
84 : * component was reduced from an empty rule. This is problematic
85 : * for nonterminals defined like
86 : * OptFooList: / * EMPTY * / { ... } | OptFooList Foo { ... } ;
87 : * because we'll set -1 as the location during the first reduction and then
88 : * copy it during each subsequent reduction, leaving us with -1 for the
89 : * location even when the list is not empty. To fix that, do this in the
90 : * action for the nonempty rule(s):
91 : * if (@$ < 0) @$ = @2;
92 : * (Although we have many nonterminals that follow this pattern, we only
93 : * bother with fixing @$ like this when the nonterminal's parse location
94 : * is actually referenced in some rule.)
95 : *
96 : * A cleaner answer would be to make YYLLOC_DEFAULT scan all the Rhs
97 : * locations until it's found one that's not -1. Then we'd get a correct
98 : * location for any nonterminal that isn't entirely empty. But this way
99 : * would add overhead to every rule reduction, and so far there's not been
100 : * a compelling reason to pay that overhead.
101 : */
102 :
103 : /*
104 : * Bison doesn't allocate anything that needs to live across parser calls,
105 : * so we can easily have it use palloc instead of malloc. This prevents
106 : * memory leaks if we error out during parsing. Note this only works with
107 : * bison >= 2.0. However, in bison 1.875 the default is to use alloca()
108 : * if possible, so there's not really much problem anyhow, at least if
109 : * you're building with gcc.
110 : */
111 : #define YYMALLOC palloc
112 : #define YYFREE pfree
113 :
114 : /* Private struct for the result of privilege_target production */
115 : typedef struct PrivTarget
116 : {
117 : GrantTargetType targtype;
118 : GrantObjectType objtype;
119 : List *objs;
120 : } PrivTarget;
121 :
122 : /* Private struct for the result of import_qualification production */
123 : typedef struct ImportQual
124 : {
125 : ImportForeignSchemaType type;
126 : List *table_names;
127 : } ImportQual;
128 :
129 : /* ConstraintAttributeSpec yields an integer bitmask of these flags: */
130 : #define CAS_NOT_DEFERRABLE 0x01
131 : #define CAS_DEFERRABLE 0x02
132 : #define CAS_INITIALLY_IMMEDIATE 0x04
133 : #define CAS_INITIALLY_DEFERRED 0x08
134 : #define CAS_NOT_VALID 0x10
135 : #define CAS_NO_INHERIT 0x20
136 :
137 :
138 : #define parser_yyerror(msg) scanner_yyerror(msg, yyscanner)
139 : #define parser_errposition(pos) scanner_errposition(pos, yyscanner)
140 :
141 : static void base_yyerror(YYLTYPE *yylloc, core_yyscan_t yyscanner,
142 : const char *msg);
143 : static RawStmt *makeRawStmt(Node *stmt, int stmt_location);
144 : static void updateRawStmtEnd(RawStmt *rs, int end_location);
145 : static Node *makeColumnRef(char *colname, List *indirection,
146 : int location, core_yyscan_t yyscanner);
147 : static Node *makeTypeCast(Node *arg, TypeName *typename, int location);
148 : static Node *makeStringConst(char *str, int location);
149 : static Node *makeStringConstCast(char *str, int location, TypeName *typename);
150 : static Node *makeIntConst(int val, int location);
151 : static Node *makeFloatConst(char *str, int location);
152 : static Node *makeBitStringConst(char *str, int location);
153 : static Node *makeNullAConst(int location);
154 : static Node *makeAConst(Value *v, int location);
155 : static Node *makeBoolAConst(bool state, int location);
156 : static RoleSpec *makeRoleSpec(RoleSpecType type, int location);
157 : static void check_qualified_name(List *names, core_yyscan_t yyscanner);
158 : static List *check_func_name(List *names, core_yyscan_t yyscanner);
159 : static List *check_indirection(List *indirection, core_yyscan_t yyscanner);
160 : static List *extractArgTypes(List *parameters);
161 : static List *extractAggrArgTypes(List *aggrargs);
162 : static List *makeOrderedSetArgs(List *directargs, List *orderedargs,
163 : core_yyscan_t yyscanner);
164 : static void insertSelectOptions(SelectStmt *stmt,
165 : List *sortClause, List *lockingClause,
166 : Node *limitOffset, Node *limitCount,
167 : WithClause *withClause,
168 : core_yyscan_t yyscanner);
169 : static Node *makeSetOp(SetOperation op, bool all, Node *larg, Node *rarg);
170 : static Node *doNegate(Node *n, int location);
171 : static void doNegateFloat(Value *v);
172 : static Node *makeAndExpr(Node *lexpr, Node *rexpr, int location);
173 : static Node *makeOrExpr(Node *lexpr, Node *rexpr, int location);
174 : static Node *makeNotExpr(Node *expr, int location);
175 : static Node *makeAArrayExpr(List *elements, int location);
176 : static Node *makeSQLValueFunction(SQLValueFunctionOp op, int32 typmod,
177 : int location);
178 : static Node *makeXmlExpr(XmlExprOp op, char *name, List *named_args,
179 : List *args, int location);
180 : static List *mergeTableFuncParameters(List *func_args, List *columns);
181 : static TypeName *TableFuncTypeName(List *columns);
182 : static RangeVar *makeRangeVarFromAnyName(List *names, int position, core_yyscan_t yyscanner);
183 : static void SplitColQualList(List *qualList,
184 : List **constraintList, CollateClause **collClause,
185 : core_yyscan_t yyscanner);
186 : static void processCASbits(int cas_bits, int location, const char *constrType,
187 : bool *deferrable, bool *initdeferred, bool *not_valid,
188 : bool *no_inherit, core_yyscan_t yyscanner);
189 : static Node *makeRecursiveViewSelect(char *relname, List *aliases, Node *query);
190 :
191 : %}
192 :
193 : %pure-parser
194 : %expect 0
195 : %name-prefix="base_yy"
196 : %locations
197 :
198 : %parse-param {core_yyscan_t yyscanner}
199 : %lex-param {core_yyscan_t yyscanner}
200 :
201 : %union
202 : {
203 : core_YYSTYPE core_yystype;
204 : /* these fields must match core_YYSTYPE: */
205 : int ival;
206 : char *str;
207 : const char *keyword;
208 :
209 : char chr;
210 : bool boolean;
211 : JoinType jtype;
212 : DropBehavior dbehavior;
213 : OnCommitAction oncommit;
214 : List *list;
215 : Node *node;
216 : Value *value;
217 : ObjectType objtype;
218 : TypeName *typnam;
219 : FunctionParameter *fun_param;
220 : FunctionParameterMode fun_param_mode;
221 : ObjectWithArgs *objwithargs;
222 : DefElem *defelt;
223 : SortBy *sortby;
224 : WindowDef *windef;
225 : JoinExpr *jexpr;
226 : IndexElem *ielem;
227 : Alias *alias;
228 : RangeVar *range;
229 : IntoClause *into;
230 : WithClause *with;
231 : InferClause *infer;
232 : OnConflictClause *onconflict;
233 : A_Indices *aind;
234 : ResTarget *target;
235 : struct PrivTarget *privtarget;
236 : AccessPriv *accesspriv;
237 : struct ImportQual *importqual;
238 : InsertStmt *istmt;
239 : VariableSetStmt *vsetstmt;
240 : PartitionElem *partelem;
241 : PartitionSpec *partspec;
242 : PartitionBoundSpec *partboundspec;
243 : RoleSpec *rolespec;
244 : }
245 :
246 : %type <node> stmt schema_stmt
247 : AlterEventTrigStmt AlterCollationStmt
248 : AlterDatabaseStmt AlterDatabaseSetStmt AlterDomainStmt AlterEnumStmt
249 : AlterFdwStmt AlterForeignServerStmt AlterGroupStmt
250 : AlterObjectDependsStmt AlterObjectSchemaStmt AlterOwnerStmt
251 : AlterOperatorStmt AlterSeqStmt AlterSystemStmt AlterTableStmt
252 : AlterTblSpcStmt AlterExtensionStmt AlterExtensionContentsStmt AlterForeignTableStmt
253 : AlterCompositeTypeStmt AlterUserMappingStmt
254 : AlterRoleStmt AlterRoleSetStmt AlterPolicyStmt
255 : AlterDefaultPrivilegesStmt DefACLAction
256 : AnalyzeStmt ClosePortalStmt ClusterStmt CommentStmt
257 : ConstraintsSetStmt CopyStmt CreateAsStmt CreateCastStmt
258 : CreateDomainStmt CreateExtensionStmt CreateGroupStmt CreateOpClassStmt
259 : CreateOpFamilyStmt AlterOpFamilyStmt CreatePLangStmt
260 : CreateSchemaStmt CreateSeqStmt CreateStmt CreateStatsStmt CreateTableSpaceStmt
261 : CreateFdwStmt CreateForeignServerStmt CreateForeignTableStmt
262 : CreateAssertStmt CreateTransformStmt CreateTrigStmt CreateEventTrigStmt
263 : CreateUserStmt CreateUserMappingStmt CreateRoleStmt CreatePolicyStmt
264 : CreatedbStmt DeclareCursorStmt DefineStmt DeleteStmt DiscardStmt DoStmt
265 : DropOpClassStmt DropOpFamilyStmt DropPLangStmt DropStmt
266 : DropAssertStmt DropCastStmt DropRoleStmt
267 : DropdbStmt DropTableSpaceStmt
268 : DropTransformStmt
269 : DropUserMappingStmt ExplainStmt FetchStmt
270 : GrantStmt GrantRoleStmt ImportForeignSchemaStmt IndexStmt InsertStmt
271 : ListenStmt LoadStmt LockStmt NotifyStmt ExplainableStmt PreparableStmt
272 : CreateFunctionStmt AlterFunctionStmt ReindexStmt RemoveAggrStmt
273 : RemoveFuncStmt RemoveOperStmt RenameStmt RevokeStmt RevokeRoleStmt
274 : RuleActionStmt RuleActionStmtOrEmpty RuleStmt
275 : SecLabelStmt SelectStmt TransactionStmt TruncateStmt
276 : UnlistenStmt UpdateStmt VacuumStmt
277 : VariableResetStmt VariableSetStmt VariableShowStmt
278 : ViewStmt CheckPointStmt CreateConversionStmt
279 : DeallocateStmt PrepareStmt ExecuteStmt
280 : DropOwnedStmt ReassignOwnedStmt
281 : AlterTSConfigurationStmt AlterTSDictionaryStmt
282 : CreateMatViewStmt RefreshMatViewStmt CreateAmStmt
283 : CreatePublicationStmt AlterPublicationStmt
284 : CreateSubscriptionStmt AlterSubscriptionStmt DropSubscriptionStmt
285 :
286 : %type <node> select_no_parens select_with_parens select_clause
287 : simple_select values_clause
288 :
289 : %type <node> alter_column_default opclass_item opclass_drop alter_using
290 : %type <ival> add_drop opt_asc_desc opt_nulls_order
291 :
292 : %type <node> alter_table_cmd alter_type_cmd opt_collate_clause
293 : replica_identity partition_cmd
294 : %type <list> alter_table_cmds alter_type_cmds
295 : %type <list> alter_identity_column_option_list
296 : %type <defelt> alter_identity_column_option
297 :
298 : %type <dbehavior> opt_drop_behavior
299 :
300 : %type <list> createdb_opt_list createdb_opt_items copy_opt_list
301 : transaction_mode_list
302 : create_extension_opt_list alter_extension_opt_list
303 : %type <defelt> createdb_opt_item copy_opt_item
304 : transaction_mode_item
305 : create_extension_opt_item alter_extension_opt_item
306 :
307 : %type <ival> opt_lock lock_type cast_context
308 : %type <ival> vacuum_option_list vacuum_option_elem
309 : %type <boolean> opt_or_replace
310 : opt_grant_grant_option opt_grant_admin_option
311 : opt_nowait opt_if_exists opt_with_data
312 : %type <ival> opt_nowait_or_skip
313 :
314 : %type <list> OptRoleList AlterOptRoleList
315 : %type <defelt> CreateOptRoleElem AlterOptRoleElem
316 :
317 : %type <str> opt_type
318 : %type <str> foreign_server_version opt_foreign_server_version
319 : %type <str> opt_in_database
320 :
321 : %type <str> OptSchemaName
322 : %type <list> OptSchemaEltList
323 :
324 : %type <boolean> TriggerForSpec TriggerForType
325 : %type <ival> TriggerActionTime
326 : %type <list> TriggerEvents TriggerOneEvent
327 : %type <value> TriggerFuncArg
328 : %type <node> TriggerWhen
329 : %type <str> TransitionRelName
330 : %type <boolean> TransitionRowOrTable TransitionOldOrNew
331 : %type <node> TriggerTransition
332 :
333 : %type <list> event_trigger_when_list event_trigger_value_list
334 : %type <defelt> event_trigger_when_item
335 : %type <chr> enable_trigger
336 :
337 : %type <str> copy_file_name
338 : database_name access_method_clause access_method attr_name
339 : name cursor_name file_name
340 : index_name opt_index_name cluster_index_specification
341 :
342 : %type <list> func_name handler_name qual_Op qual_all_Op subquery_Op
343 : opt_class opt_inline_handler opt_validator validator_clause
344 : opt_collate
345 :
346 : %type <range> qualified_name insert_target OptConstrFromTable
347 :
348 : %type <str> all_Op MathOp
349 :
350 : %type <str> row_security_cmd RowSecurityDefaultForCmd
351 : %type <boolean> RowSecurityDefaultPermissive
352 : %type <node> RowSecurityOptionalWithCheck RowSecurityOptionalExpr
353 : %type <list> RowSecurityDefaultToRole RowSecurityOptionalToRole
354 :
355 : %type <str> iso_level opt_encoding
356 : %type <rolespec> grantee
357 : %type <list> grantee_list
358 : %type <accesspriv> privilege
359 : %type <list> privileges privilege_list
360 : %type <privtarget> privilege_target
361 : %type <objwithargs> function_with_argtypes aggregate_with_argtypes operator_with_argtypes
362 : %type <list> function_with_argtypes_list aggregate_with_argtypes_list operator_with_argtypes_list
363 : %type <ival> defacl_privilege_target
364 : %type <defelt> DefACLOption
365 : %type <list> DefACLOptionList
366 : %type <ival> import_qualification_type
367 : %type <importqual> import_qualification
368 :
369 : %type <list> stmtblock stmtmulti
370 : OptTableElementList TableElementList OptInherit definition
371 : OptTypedTableElementList TypedTableElementList
372 : reloptions opt_reloptions
373 : OptWith distinct_clause opt_all_clause opt_definition func_args func_args_list
374 : func_args_with_defaults func_args_with_defaults_list
375 : aggr_args aggr_args_list
376 : func_as createfunc_opt_list alterfunc_opt_list
377 : old_aggr_definition old_aggr_list
378 : oper_argtypes RuleActionList RuleActionMulti
379 : opt_column_list columnList opt_name_list
380 : sort_clause opt_sort_clause sortby_list index_params
381 : name_list role_list from_clause from_list opt_array_bounds
382 : qualified_name_list any_name any_name_list type_name_list
383 : any_operator expr_list attrs
384 : target_list opt_target_list insert_column_list set_target_list
385 : set_clause_list set_clause
386 : def_list operator_def_list indirection opt_indirection
387 : reloption_list group_clause TriggerFuncArgs select_limit
388 : opt_select_limit opclass_item_list opclass_drop_list
389 : opclass_purpose opt_opfamily transaction_mode_list_or_empty
390 : OptTableFuncElementList TableFuncElementList opt_type_modifiers
391 : prep_type_clause
392 : execute_param_clause using_clause returning_clause
393 : opt_enum_val_list enum_val_list table_func_column_list
394 : create_generic_options alter_generic_options
395 : relation_expr_list dostmt_opt_list
396 : transform_element_list transform_type_list
397 : TriggerTransitions TriggerReferencing
398 : publication_name_list
399 :
400 : %type <list> group_by_list
401 : %type <node> group_by_item empty_grouping_set rollup_clause cube_clause
402 : %type <node> grouping_sets_clause
403 : %type <node> opt_publication_for_tables publication_for_tables
404 : %type <value> publication_name_item
405 :
406 : %type <list> opt_fdw_options fdw_options
407 : %type <defelt> fdw_option
408 :
409 : %type <range> OptTempTableName
410 : %type <into> into_clause create_as_target create_mv_target
411 :
412 : %type <defelt> createfunc_opt_item common_func_opt_item dostmt_opt_item
413 : %type <fun_param> func_arg func_arg_with_default table_func_column aggr_arg
414 : %type <fun_param_mode> arg_class
415 : %type <typnam> func_return func_type
416 :
417 : %type <boolean> opt_trusted opt_restart_seqs
418 : %type <ival> OptTemp
419 : %type <ival> OptNoLog
420 : %type <oncommit> OnCommitOption
421 :
422 : %type <ival> for_locking_strength
423 : %type <node> for_locking_item
424 : %type <list> for_locking_clause opt_for_locking_clause for_locking_items
425 : %type <list> locked_rels_list
426 : %type <boolean> all_or_distinct
427 :
428 : %type <node> join_outer join_qual
429 : %type <jtype> join_type
430 :
431 : %type <list> extract_list overlay_list position_list
432 : %type <list> substr_list trim_list
433 : %type <list> opt_interval interval_second
434 : %type <node> overlay_placing substr_from substr_for
435 :
436 : %type <boolean> opt_instead
437 : %type <boolean> opt_unique opt_concurrently opt_verbose opt_full
438 : %type <boolean> opt_freeze opt_default opt_recheck
439 : %type <defelt> opt_binary opt_oids copy_delimiter
440 :
441 : %type <boolean> copy_from opt_program
442 :
443 : %type <ival> opt_column event cursor_options opt_hold opt_set_data
444 : %type <objtype> drop_type_any_name drop_type_name drop_type_name_on_any_name
445 : comment_type_any_name comment_type_name
446 : security_label_type_any_name security_label_type_name
447 :
448 : %type <node> fetch_args limit_clause select_limit_value
449 : offset_clause select_offset_value
450 : select_offset_value2 opt_select_fetch_first_value
451 : %type <ival> row_or_rows first_or_next
452 :
453 : %type <list> OptSeqOptList SeqOptList OptParenthesizedSeqOptList
454 : %type <defelt> SeqOptElem
455 :
456 : %type <istmt> insert_rest
457 : %type <infer> opt_conf_expr
458 : %type <onconflict> opt_on_conflict
459 :
460 : %type <vsetstmt> generic_set set_rest set_rest_more generic_reset reset_rest
461 : SetResetClause FunctionSetResetClause
462 :
463 : %type <node> TableElement TypedTableElement ConstraintElem TableFuncElement
464 : %type <node> columnDef columnOptions
465 : %type <defelt> def_elem reloption_elem old_aggr_elem operator_def_elem
466 : %type <node> def_arg columnElem where_clause where_or_current_clause
467 : a_expr b_expr c_expr AexprConst indirection_el opt_slice_bound
468 : columnref in_expr having_clause func_table xmltable array_expr
469 : ExclusionWhereClause operator_def_arg
470 : %type <list> rowsfrom_item rowsfrom_list opt_col_def_list
471 : %type <boolean> opt_ordinality
472 : %type <list> ExclusionConstraintList ExclusionConstraintElem
473 : %type <list> func_arg_list
474 : %type <node> func_arg_expr
475 : %type <list> row explicit_row implicit_row type_list array_expr_list
476 : %type <node> case_expr case_arg when_clause case_default
477 : %type <list> when_clause_list
478 : %type <ival> sub_type
479 : %type <value> NumericOnly
480 : %type <list> NumericOnly_list
481 : %type <alias> alias_clause opt_alias_clause
482 : %type <list> func_alias_clause
483 : %type <sortby> sortby
484 : %type <ielem> index_elem
485 : %type <node> table_ref
486 : %type <jexpr> joined_table
487 : %type <range> relation_expr
488 : %type <range> relation_expr_opt_alias
489 : %type <node> tablesample_clause opt_repeatable_clause
490 : %type <target> target_el set_target insert_column_item
491 :
492 : %type <str> generic_option_name
493 : %type <node> generic_option_arg
494 : %type <defelt> generic_option_elem alter_generic_option_elem
495 : %type <list> generic_option_list alter_generic_option_list
496 : %type <str> explain_option_name
497 : %type <node> explain_option_arg
498 : %type <defelt> explain_option_elem
499 : %type <list> explain_option_list
500 :
501 : %type <ival> reindex_target_type reindex_target_multitable
502 : %type <ival> reindex_option_list reindex_option_elem
503 :
504 : %type <node> copy_generic_opt_arg copy_generic_opt_arg_list_item
505 : %type <defelt> copy_generic_opt_elem
506 : %type <list> copy_generic_opt_list copy_generic_opt_arg_list
507 : %type <list> copy_options
508 :
509 : %type <typnam> Typename SimpleTypename ConstTypename
510 : GenericType Numeric opt_float
511 : Character ConstCharacter
512 : CharacterWithLength CharacterWithoutLength
513 : ConstDatetime ConstInterval
514 : Bit ConstBit BitWithLength BitWithoutLength
515 : %type <str> character
516 : %type <str> extract_arg
517 : %type <boolean> opt_varying opt_timezone opt_no_inherit
518 :
519 : %type <ival> Iconst SignedIconst
520 : %type <str> Sconst comment_text notify_payload
521 : %type <str> RoleId opt_boolean_or_string
522 : %type <list> var_list
523 : %type <str> ColId ColLabel var_name type_function_name param_name
524 : %type <str> NonReservedWord NonReservedWord_or_Sconst
525 : %type <str> createdb_opt_name
526 : %type <node> var_value zone_value
527 : %type <rolespec> auth_ident RoleSpec opt_granted_by
528 :
529 : %type <keyword> unreserved_keyword type_func_name_keyword
530 : %type <keyword> col_name_keyword reserved_keyword
531 :
532 : %type <node> TableConstraint TableLikeClause
533 : %type <ival> TableLikeOptionList TableLikeOption
534 : %type <list> ColQualList
535 : %type <node> ColConstraint ColConstraintElem ConstraintAttr
536 : %type <ival> key_actions key_delete key_match key_update key_action
537 : %type <ival> ConstraintAttributeSpec ConstraintAttributeElem
538 : %type <str> ExistingIndex
539 :
540 : %type <list> constraints_set_list
541 : %type <boolean> constraints_set_mode
542 : %type <str> OptTableSpace OptConsTableSpace
543 : %type <rolespec> OptTableSpaceOwner
544 : %type <ival> opt_check_option
545 :
546 : %type <str> opt_provider security_label
547 :
548 : %type <target> xml_attribute_el
549 : %type <list> xml_attribute_list xml_attributes
550 : %type <node> xml_root_version opt_xml_root_standalone
551 : %type <node> xmlexists_argument
552 : %type <ival> document_or_content
553 : %type <boolean> xml_whitespace_option
554 : %type <list> xmltable_column_list xmltable_column_option_list
555 : %type <node> xmltable_column_el
556 : %type <defelt> xmltable_column_option_el
557 : %type <list> xml_namespace_list
558 : %type <target> xml_namespace_el
559 :
560 : %type <node> func_application func_expr_common_subexpr
561 : %type <node> func_expr func_expr_windowless
562 : %type <node> common_table_expr
563 : %type <with> with_clause opt_with_clause
564 : %type <list> cte_list
565 :
566 : %type <list> within_group_clause
567 : %type <node> filter_clause
568 : %type <list> window_clause window_definition_list opt_partition_clause
569 : %type <windef> window_definition over_clause window_specification
570 : opt_frame_clause frame_extent frame_bound
571 : %type <str> opt_existing_window_name
572 : %type <boolean> opt_if_not_exists
573 : %type <ival> generated_when override_kind
574 : %type <partspec> PartitionSpec OptPartitionSpec
575 : %type <str> part_strategy
576 : %type <partelem> part_elem
577 : %type <list> part_params
578 : %type <partboundspec> ForValues
579 : %type <node> partbound_datum PartitionRangeDatum
580 : %type <list> partbound_datum_list range_datum_list
581 :
582 : /*
583 : * Non-keyword token types. These are hard-wired into the "flex" lexer.
584 : * They must be listed first so that their numeric codes do not depend on
585 : * the set of keywords. PL/pgSQL depends on this so that it can share the
586 : * same lexer. If you add/change tokens here, fix PL/pgSQL to match!
587 : *
588 : * DOT_DOT is unused in the core SQL grammar, and so will always provoke
589 : * parse errors. It is needed by PL/pgSQL.
590 : */
591 : %token <str> IDENT FCONST SCONST BCONST XCONST Op
592 : %token <ival> ICONST PARAM
593 : %token TYPECAST DOT_DOT COLON_EQUALS EQUALS_GREATER
594 : %token LESS_EQUALS GREATER_EQUALS NOT_EQUALS
595 :
596 : /*
597 : * If you want to make any keyword changes, update the keyword table in
598 : * src/include/parser/kwlist.h and add new keywords to the appropriate one
599 : * of the reserved-or-not-so-reserved keyword lists, below; search
600 : * this file for "Keyword category lists".
601 : */
602 :
603 : /* ordinary key words in alphabetical order */
604 : %token <keyword> ABORT_P ABSOLUTE_P ACCESS ACTION ADD_P ADMIN AFTER
605 : AGGREGATE ALL ALSO ALTER ALWAYS ANALYSE ANALYZE AND ANY ARRAY AS ASC
606 : ASSERTION ASSIGNMENT ASYMMETRIC AT ATTACH ATTRIBUTE AUTHORIZATION
607 :
608 : BACKWARD BEFORE BEGIN_P BETWEEN BIGINT BINARY BIT
609 : BOOLEAN_P BOTH BY
610 :
611 : CACHE CALLED CASCADE CASCADED CASE CAST CATALOG_P CHAIN CHAR_P
612 : CHARACTER CHARACTERISTICS CHECK CHECKPOINT CLASS CLOSE
613 : CLUSTER COALESCE COLLATE COLLATION COLUMN COLUMNS COMMENT COMMENTS COMMIT
614 : COMMITTED CONCURRENTLY CONFIGURATION CONFLICT CONNECTION CONSTRAINT
615 : CONSTRAINTS CONTENT_P CONTINUE_P CONVERSION_P COPY COST CREATE
616 : CROSS CSV CUBE CURRENT_P
617 : CURRENT_CATALOG CURRENT_DATE CURRENT_ROLE CURRENT_SCHEMA
618 : CURRENT_TIME CURRENT_TIMESTAMP CURRENT_USER CURSOR CYCLE
619 :
620 : DATA_P DATABASE DAY_P DEALLOCATE DEC DECIMAL_P DECLARE DEFAULT DEFAULTS
621 : DEFERRABLE DEFERRED DEFINER DELETE_P DELIMITER DELIMITERS DEPENDS DESC
622 : DETACH DICTIONARY DISABLE_P DISCARD DISTINCT DO DOCUMENT_P DOMAIN_P
623 : DOUBLE_P DROP
624 :
625 : EACH ELSE ENABLE_P ENCODING ENCRYPTED END_P ENUM_P ESCAPE EVENT EXCEPT
626 : EXCLUDE EXCLUDING EXCLUSIVE EXECUTE EXISTS EXPLAIN
627 : EXTENSION EXTERNAL EXTRACT
628 :
629 : FALSE_P FAMILY FETCH FILTER FIRST_P FLOAT_P FOLLOWING FOR
630 : FORCE FOREIGN FORWARD FREEZE FROM FULL FUNCTION FUNCTIONS
631 :
632 : GENERATED GLOBAL GRANT GRANTED GREATEST GROUP_P GROUPING
633 :
634 : HANDLER HAVING HEADER_P HOLD HOUR_P
635 :
636 : IDENTITY_P IF_P ILIKE IMMEDIATE IMMUTABLE IMPLICIT_P IMPORT_P IN_P
637 : INCLUDING INCREMENT INDEX INDEXES INHERIT INHERITS INITIALLY INLINE_P
638 : INNER_P INOUT INPUT_P INSENSITIVE INSERT INSTEAD INT_P INTEGER
639 : INTERSECT INTERVAL INTO INVOKER IS ISNULL ISOLATION
640 :
641 : JOIN
642 :
643 : KEY
644 :
645 : LABEL LANGUAGE LARGE_P LAST_P LATERAL_P
646 : LEADING LEAKPROOF LEAST LEFT LEVEL LIKE LIMIT LISTEN LOAD LOCAL
647 : LOCALTIME LOCALTIMESTAMP LOCATION LOCK_P LOCKED LOGGED
648 :
649 : MAPPING MATCH MATERIALIZED MAXVALUE METHOD MINUTE_P MINVALUE MODE MONTH_P MOVE
650 :
651 : NAME_P NAMES NATIONAL NATURAL NCHAR NEW NEXT NO NONE
652 : NOT NOTHING NOTIFY NOTNULL NOWAIT NULL_P NULLIF
653 : NULLS_P NUMERIC
654 :
655 : OBJECT_P OF OFF OFFSET OIDS OLD ON ONLY OPERATOR OPTION OPTIONS OR
656 : ORDER ORDINALITY OUT_P OUTER_P OVER OVERLAPS OVERLAY OVERRIDING OWNED OWNER
657 :
658 : PARALLEL PARSER PARTIAL PARTITION PASSING PASSWORD PLACING PLANS POLICY
659 : POSITION PRECEDING PRECISION PRESERVE PREPARE PREPARED PRIMARY
660 : PRIOR PRIVILEGES PROCEDURAL PROCEDURE PROGRAM PUBLICATION
661 :
662 : QUOTE
663 :
664 : RANGE READ REAL REASSIGN RECHECK RECURSIVE REF REFERENCES REFERENCING
665 : REFRESH REINDEX RELATIVE_P RELEASE RENAME REPEATABLE REPLACE REPLICA
666 : RESET RESTART RESTRICT RETURNING RETURNS REVOKE RIGHT ROLE ROLLBACK ROLLUP
667 : ROW ROWS RULE
668 :
669 : SAVEPOINT SCHEMA SCHEMAS SCROLL SEARCH SECOND_P SECURITY SELECT SEQUENCE SEQUENCES
670 : SERIALIZABLE SERVER SESSION SESSION_USER SET SETS SETOF SHARE SHOW
671 : SIMILAR SIMPLE SKIP SMALLINT SNAPSHOT SOME SQL_P STABLE STANDALONE_P
672 : START STATEMENT STATISTICS STDIN STDOUT STORAGE STRICT_P STRIP_P
673 : SUBSCRIPTION SUBSTRING SYMMETRIC SYSID SYSTEM_P
674 :
675 : TABLE TABLES TABLESAMPLE TABLESPACE TEMP TEMPLATE TEMPORARY TEXT_P THEN
676 : TIME TIMESTAMP TO TRAILING TRANSACTION TRANSFORM TREAT TRIGGER TRIM TRUE_P
677 : TRUNCATE TRUSTED TYPE_P TYPES_P
678 :
679 : UNBOUNDED UNCOMMITTED UNENCRYPTED UNION UNIQUE UNKNOWN UNLISTEN UNLOGGED
680 : UNTIL UPDATE USER USING
681 :
682 : VACUUM VALID VALIDATE VALIDATOR VALUE_P VALUES VARCHAR VARIADIC VARYING
683 : VERBOSE VERSION_P VIEW VIEWS VOLATILE
684 :
685 : WHEN WHERE WHITESPACE_P WINDOW WITH WITHIN WITHOUT WORK WRAPPER WRITE
686 :
687 : XML_P XMLATTRIBUTES XMLCONCAT XMLELEMENT XMLEXISTS XMLFOREST XMLNAMESPACES
688 : XMLPARSE XMLPI XMLROOT XMLSERIALIZE XMLTABLE
689 :
690 : YEAR_P YES_P
691 :
692 : ZONE
693 :
694 : /*
695 : * The grammar thinks these are keywords, but they are not in the kwlist.h
696 : * list and so can never be entered directly. The filter in parser.c
697 : * creates these tokens when required (based on looking one token ahead).
698 : *
699 : * NOT_LA exists so that productions such as NOT LIKE can be given the same
700 : * precedence as LIKE; otherwise they'd effectively have the same precedence
701 : * as NOT, at least with respect to their left-hand subexpression.
702 : * NULLS_LA and WITH_LA are needed to make the grammar LALR(1).
703 : */
704 : %token NOT_LA NULLS_LA WITH_LA
705 :
706 :
707 : /* Precedence: lowest to highest */
708 : %nonassoc SET /* see relation_expr_opt_alias */
709 : %left UNION EXCEPT
710 : %left INTERSECT
711 : %left OR
712 : %left AND
713 : %right NOT
714 : %nonassoc IS ISNULL NOTNULL /* IS sets precedence for IS NULL, etc */
715 : %nonassoc '<' '>' '=' LESS_EQUALS GREATER_EQUALS NOT_EQUALS
716 : %nonassoc BETWEEN IN_P LIKE ILIKE SIMILAR NOT_LA
717 : %nonassoc ESCAPE /* ESCAPE must be just above LIKE/ILIKE/SIMILAR */
718 : %left POSTFIXOP /* dummy for postfix Op rules */
719 : /*
720 : * To support target_el without AS, we must give IDENT an explicit priority
721 : * between POSTFIXOP and Op. We can safely assign the same priority to
722 : * various unreserved keywords as needed to resolve ambiguities (this can't
723 : * have any bad effects since obviously the keywords will still behave the
724 : * same as if they weren't keywords). We need to do this for PARTITION,
725 : * RANGE, ROWS to support opt_existing_window_name; and for RANGE, ROWS
726 : * so that they can follow a_expr without creating postfix-operator problems;
727 : * for GENERATED so that it can follow b_expr;
728 : * and for NULL so that it can follow b_expr in ColQualList without creating
729 : * postfix-operator problems.
730 : *
731 : * To support CUBE and ROLLUP in GROUP BY without reserving them, we give them
732 : * an explicit priority lower than '(', so that a rule with CUBE '(' will shift
733 : * rather than reducing a conflicting rule that takes CUBE as a function name.
734 : * Using the same precedence as IDENT seems right for the reasons given above.
735 : *
736 : * The frame_bound productions UNBOUNDED PRECEDING and UNBOUNDED FOLLOWING
737 : * are even messier: since UNBOUNDED is an unreserved keyword (per spec!),
738 : * there is no principled way to distinguish these from the productions
739 : * a_expr PRECEDING/FOLLOWING. We hack this up by giving UNBOUNDED slightly
740 : * lower precedence than PRECEDING and FOLLOWING. At present this doesn't
741 : * appear to cause UNBOUNDED to be treated differently from other unreserved
742 : * keywords anywhere else in the grammar, but it's definitely risky. We can
743 : * blame any funny behavior of UNBOUNDED on the SQL standard, though.
744 : */
745 : %nonassoc UNBOUNDED /* ideally should have same precedence as IDENT */
746 : %nonassoc IDENT GENERATED NULL_P PARTITION RANGE ROWS PRECEDING FOLLOWING CUBE ROLLUP
747 : %left Op OPERATOR /* multi-character ops and user-defined operators */
748 : %left '+' '-'
749 : %left '*' '/' '%'
750 : %left '^'
751 : /* Unary Operators */
752 : %left AT /* sets precedence for AT TIME ZONE */
753 : %left COLLATE
754 : %right UMINUS
755 : %left '[' ']'
756 : %left '(' ')'
757 : %left TYPECAST
758 : %left '.'
759 : /*
760 : * These might seem to be low-precedence, but actually they are not part
761 : * of the arithmetic hierarchy at all in their use as JOIN operators.
762 : * We make them high-precedence to support their use as function names.
763 : * They wouldn't be given a precedence at all, were it not that we need
764 : * left-associativity among the JOIN rules themselves.
765 : */
766 : %left JOIN CROSS LEFT FULL RIGHT INNER_P NATURAL
767 : /* kluge to keep xml_whitespace_option from causing shift/reduce conflicts */
768 : %right PRESERVE STRIP_P
769 :
770 : %%
771 :
772 : /*
773 : * The target production for the whole parse.
774 : */
775 : stmtblock: stmtmulti
776 : {
777 37599 : pg_yyget_extra(yyscanner)->parsetree = $1;
778 : }
779 : ;
780 :
781 : /*
782 : * At top level, we wrap each stmt with a RawStmt node carrying start location
783 : * and length of the stmt's text. Notice that the start loc/len are driven
784 : * entirely from semicolon locations (@2). It would seem natural to use
785 : * @1 or @3 to get the true start location of a stmt, but that doesn't work
786 : * for statements that can start with empty nonterminals (opt_with_clause is
787 : * the main offender here); as noted in the comments for YYLLOC_DEFAULT,
788 : * we'd get -1 for the location in such cases.
789 : * We also take care to discard empty statements entirely.
790 : */
791 : stmtmulti: stmtmulti ';' stmt
792 : {
793 27583 : if ($1 != NIL)
794 : {
795 : /* update length of previous stmt */
796 27579 : updateRawStmtEnd(llast_node(RawStmt, $1), @2);
797 : }
798 27583 : if ($3 != NULL)
799 514 : $$ = lappend($1, makeRawStmt($3, @2 + 1));
800 : else
801 27069 : $$ = $1;
802 : }
803 : | stmt
804 : {
805 37599 : if ($1 != NULL)
806 37594 : $$ = list_make1(makeRawStmt($1, 0));
807 : else
808 5 : $$ = NIL;
809 : }
810 : ;
811 :
812 : stmt :
813 : AlterEventTrigStmt
814 : | AlterCollationStmt
815 : | AlterDatabaseStmt
816 : | AlterDatabaseSetStmt
817 : | AlterDefaultPrivilegesStmt
818 : | AlterDomainStmt
819 : | AlterEnumStmt
820 : | AlterExtensionStmt
821 : | AlterExtensionContentsStmt
822 : | AlterFdwStmt
823 : | AlterForeignServerStmt
824 : | AlterForeignTableStmt
825 : | AlterFunctionStmt
826 : | AlterGroupStmt
827 : | AlterObjectDependsStmt
828 : | AlterObjectSchemaStmt
829 : | AlterOwnerStmt
830 : | AlterOperatorStmt
831 : | AlterPolicyStmt
832 : | AlterSeqStmt
833 : | AlterSystemStmt
834 : | AlterTableStmt
835 : | AlterTblSpcStmt
836 : | AlterCompositeTypeStmt
837 : | AlterPublicationStmt
838 : | AlterRoleSetStmt
839 : | AlterRoleStmt
840 : | AlterSubscriptionStmt
841 : | AlterTSConfigurationStmt
842 : | AlterTSDictionaryStmt
843 : | AlterUserMappingStmt
844 : | AnalyzeStmt
845 : | CheckPointStmt
846 : | ClosePortalStmt
847 : | ClusterStmt
848 : | CommentStmt
849 : | ConstraintsSetStmt
850 : | CopyStmt
851 : | CreateAmStmt
852 : | CreateAsStmt
853 : | CreateAssertStmt
854 : | CreateCastStmt
855 : | CreateConversionStmt
856 : | CreateDomainStmt
857 : | CreateExtensionStmt
858 : | CreateFdwStmt
859 : | CreateForeignServerStmt
860 : | CreateForeignTableStmt
861 : | CreateFunctionStmt
862 : | CreateGroupStmt
863 : | CreateMatViewStmt
864 : | CreateOpClassStmt
865 : | CreateOpFamilyStmt
866 : | CreatePublicationStmt
867 : | AlterOpFamilyStmt
868 : | CreatePolicyStmt
869 : | CreatePLangStmt
870 : | CreateSchemaStmt
871 : | CreateSeqStmt
872 : | CreateStmt
873 : | CreateSubscriptionStmt
874 : | CreateStatsStmt
875 : | CreateTableSpaceStmt
876 : | CreateTransformStmt
877 : | CreateTrigStmt
878 : | CreateEventTrigStmt
879 : | CreateRoleStmt
880 : | CreateUserStmt
881 : | CreateUserMappingStmt
882 : | CreatedbStmt
883 : | DeallocateStmt
884 : | DeclareCursorStmt
885 : | DefineStmt
886 : | DeleteStmt
887 : | DiscardStmt
888 : | DoStmt
889 : | DropAssertStmt
890 : | DropCastStmt
891 : | DropOpClassStmt
892 : | DropOpFamilyStmt
893 : | DropOwnedStmt
894 : | DropPLangStmt
895 : | DropStmt
896 : | DropSubscriptionStmt
897 : | DropTableSpaceStmt
898 : | DropTransformStmt
899 : | DropRoleStmt
900 : | DropUserMappingStmt
901 : | DropdbStmt
902 : | ExecuteStmt
903 : | ExplainStmt
904 : | FetchStmt
905 : | GrantStmt
906 : | GrantRoleStmt
907 : | ImportForeignSchemaStmt
908 : | IndexStmt
909 : | InsertStmt
910 : | ListenStmt
911 : | RefreshMatViewStmt
912 : | LoadStmt
913 : | LockStmt
914 : | NotifyStmt
915 : | PrepareStmt
916 : | ReassignOwnedStmt
917 : | ReindexStmt
918 : | RemoveAggrStmt
919 : | RemoveFuncStmt
920 : | RemoveOperStmt
921 : | RenameStmt
922 : | RevokeStmt
923 : | RevokeRoleStmt
924 : | RuleStmt
925 : | SecLabelStmt
926 : | SelectStmt
927 : | TransactionStmt
928 : | TruncateStmt
929 : | UnlistenStmt
930 : | UpdateStmt
931 : | VacuumStmt
932 : | VariableResetStmt
933 : | VariableSetStmt
934 : | VariableShowStmt
935 : | ViewStmt
936 : | /*EMPTY*/
937 27074 : { $$ = NULL; }
938 : ;
939 :
940 : /*****************************************************************************
941 : *
942 : * Create a new Postgres DBMS role
943 : *
944 : *****************************************************************************/
945 :
946 : CreateRoleStmt:
947 : CREATE ROLE RoleId opt_with OptRoleList
948 : {
949 76 : CreateRoleStmt *n = makeNode(CreateRoleStmt);
950 76 : n->stmt_type = ROLESTMT_ROLE;
951 76 : n->role = $3;
952 76 : n->options = $5;
953 76 : $$ = (Node *)n;
954 : }
955 : ;
956 :
957 :
958 : opt_with: WITH {}
959 : | WITH_LA {}
960 : | /*EMPTY*/ {}
961 : ;
962 :
963 : /*
964 : * Options for CREATE ROLE and ALTER ROLE (also used by CREATE/ALTER USER
965 : * for backwards compatibility). Note: the only option required by SQL99
966 : * is "WITH ADMIN name".
967 : */
968 : OptRoleList:
969 54 : OptRoleList CreateOptRoleElem { $$ = lappend($1, $2); }
970 118 : | /* EMPTY */ { $$ = NIL; }
971 : ;
972 :
973 : AlterOptRoleList:
974 49 : AlterOptRoleList AlterOptRoleElem { $$ = lappend($1, $2); }
975 49 : | /* EMPTY */ { $$ = NIL; }
976 : ;
977 :
978 : AlterOptRoleElem:
979 : PASSWORD Sconst
980 : {
981 22 : $$ = makeDefElem("password",
982 22 : (Node *)makeString($2), @1);
983 : }
984 : | PASSWORD NULL_P
985 : {
986 1 : $$ = makeDefElem("password", NULL, @1);
987 : }
988 : | ENCRYPTED PASSWORD Sconst
989 : {
990 : /*
991 : * These days, passwords are always stored in encrypted
992 : * form, so there is no difference between PASSWORD and
993 : * ENCRYPTED PASSWORD.
994 : */
995 0 : $$ = makeDefElem("password",
996 0 : (Node *)makeString($3), @1);
997 : }
998 : | UNENCRYPTED PASSWORD Sconst
999 : {
1000 0 : ereport(ERROR,
1001 : (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
1002 : errmsg("UNENCRYPTED PASSWORD is no longer supported"),
1003 : errhint("Remove UNENCRYPTED to store the password in encrypted form instead."),
1004 : parser_errposition(@1)));
1005 : }
1006 : | INHERIT
1007 : {
1008 1 : $$ = makeDefElem("inherit", (Node *)makeInteger(TRUE), @1);
1009 : }
1010 : | CONNECTION LIMIT SignedIconst
1011 : {
1012 0 : $$ = makeDefElem("connectionlimit", (Node *)makeInteger($3), @1);
1013 : }
1014 : | VALID UNTIL Sconst
1015 : {
1016 0 : $$ = makeDefElem("validUntil", (Node *)makeString($3), @1);
1017 : }
1018 : /* Supported but not documented for roles, for use by ALTER GROUP. */
1019 : | USER role_list
1020 : {
1021 1 : $$ = makeDefElem("rolemembers", (Node *)$2, @1);
1022 : }
1023 : | IDENT
1024 : {
1025 : /*
1026 : * We handle identifiers that aren't parser keywords with
1027 : * the following special-case codes, to avoid bloating the
1028 : * size of the main parser.
1029 : */
1030 87 : if (strcmp($1, "superuser") == 0)
1031 14 : $$ = makeDefElem("superuser", (Node *)makeInteger(TRUE), @1);
1032 73 : else if (strcmp($1, "nosuperuser") == 0)
1033 5 : $$ = makeDefElem("superuser", (Node *)makeInteger(FALSE), @1);
1034 68 : else if (strcmp($1, "createrole") == 0)
1035 3 : $$ = makeDefElem("createrole", (Node *)makeInteger(TRUE), @1);
1036 65 : else if (strcmp($1, "nocreaterole") == 0)
1037 2 : $$ = makeDefElem("createrole", (Node *)makeInteger(FALSE), @1);
1038 63 : else if (strcmp($1, "replication") == 0)
1039 14 : $$ = makeDefElem("isreplication", (Node *)makeInteger(TRUE), @1);
1040 49 : else if (strcmp($1, "noreplication") == 0)
1041 13 : $$ = makeDefElem("isreplication", (Node *)makeInteger(FALSE), @1);
1042 36 : else if (strcmp($1, "createdb") == 0)
1043 2 : $$ = makeDefElem("createdb", (Node *)makeInteger(TRUE), @1);
1044 34 : else if (strcmp($1, "nocreatedb") == 0)
1045 2 : $$ = makeDefElem("createdb", (Node *)makeInteger(FALSE), @1);
1046 32 : else if (strcmp($1, "login") == 0)
1047 15 : $$ = makeDefElem("canlogin", (Node *)makeInteger(TRUE), @1);
1048 17 : else if (strcmp($1, "nologin") == 0)
1049 11 : $$ = makeDefElem("canlogin", (Node *)makeInteger(FALSE), @1);
1050 6 : else if (strcmp($1, "bypassrls") == 0)
1051 3 : $$ = makeDefElem("bypassrls", (Node *)makeInteger(TRUE), @1);
1052 3 : else if (strcmp($1, "nobypassrls") == 0)
1053 1 : $$ = makeDefElem("bypassrls", (Node *)makeInteger(FALSE), @1);
1054 2 : else if (strcmp($1, "noinherit") == 0)
1055 : {
1056 : /*
1057 : * Note that INHERIT is a keyword, so it's handled by main parser, but
1058 : * NOINHERIT is handled here.
1059 : */
1060 2 : $$ = makeDefElem("inherit", (Node *)makeInteger(FALSE), @1);
1061 : }
1062 : else
1063 0 : ereport(ERROR,
1064 : (errcode(ERRCODE_SYNTAX_ERROR),
1065 : errmsg("unrecognized role option \"%s\"", $1),
1066 : parser_errposition(@1)));
1067 : }
1068 : ;
1069 :
1070 : CreateOptRoleElem:
1071 52 : AlterOptRoleElem { $$ = $1; }
1072 : /* The following are not supported by ALTER ROLE/USER/GROUP */
1073 : | SYSID Iconst
1074 : {
1075 0 : $$ = makeDefElem("sysid", (Node *)makeInteger($2), @1);
1076 : }
1077 : | ADMIN role_list
1078 : {
1079 0 : $$ = makeDefElem("adminmembers", (Node *)$2, @1);
1080 : }
1081 : | ROLE role_list
1082 : {
1083 0 : $$ = makeDefElem("rolemembers", (Node *)$2, @1);
1084 : }
1085 : | IN_P ROLE role_list
1086 : {
1087 2 : $$ = makeDefElem("addroleto", (Node *)$3, @1);
1088 : }
1089 : | IN_P GROUP_P role_list
1090 : {
1091 0 : $$ = makeDefElem("addroleto", (Node *)$3, @1);
1092 : }
1093 : ;
1094 :
1095 :
1096 : /*****************************************************************************
1097 : *
1098 : * Create a new Postgres DBMS user (role with implied login ability)
1099 : *
1100 : *****************************************************************************/
1101 :
1102 : CreateUserStmt:
1103 : CREATE USER RoleId opt_with OptRoleList
1104 : {
1105 38 : CreateRoleStmt *n = makeNode(CreateRoleStmt);
1106 38 : n->stmt_type = ROLESTMT_USER;
1107 38 : n->role = $3;
1108 38 : n->options = $5;
1109 38 : $$ = (Node *)n;
1110 : }
1111 : ;
1112 :
1113 :
1114 : /*****************************************************************************
1115 : *
1116 : * Alter a postgresql DBMS role
1117 : *
1118 : *****************************************************************************/
1119 :
1120 : AlterRoleStmt:
1121 : ALTER ROLE RoleSpec opt_with AlterOptRoleList
1122 : {
1123 31 : AlterRoleStmt *n = makeNode(AlterRoleStmt);
1124 31 : n->role = $3;
1125 31 : n->action = +1; /* add, if there are members */
1126 31 : n->options = $5;
1127 31 : $$ = (Node *)n;
1128 : }
1129 : | ALTER USER RoleSpec opt_with AlterOptRoleList
1130 : {
1131 18 : AlterRoleStmt *n = makeNode(AlterRoleStmt);
1132 18 : n->role = $3;
1133 18 : n->action = +1; /* add, if there are members */
1134 18 : n->options = $5;
1135 18 : $$ = (Node *)n;
1136 : }
1137 : ;
1138 :
1139 : opt_in_database:
1140 30 : /* EMPTY */ { $$ = NULL; }
1141 0 : | IN_P DATABASE database_name { $$ = $3; }
1142 : ;
1143 :
1144 : AlterRoleSetStmt:
1145 : ALTER ROLE RoleSpec opt_in_database SetResetClause
1146 : {
1147 12 : AlterRoleSetStmt *n = makeNode(AlterRoleSetStmt);
1148 12 : n->role = $3;
1149 12 : n->database = $4;
1150 12 : n->setstmt = $5;
1151 12 : $$ = (Node *)n;
1152 : }
1153 : | ALTER ROLE ALL opt_in_database SetResetClause
1154 : {
1155 2 : AlterRoleSetStmt *n = makeNode(AlterRoleSetStmt);
1156 2 : n->role = NULL;
1157 2 : n->database = $4;
1158 2 : n->setstmt = $5;
1159 2 : $$ = (Node *)n;
1160 : }
1161 : | ALTER USER RoleSpec opt_in_database SetResetClause
1162 : {
1163 12 : AlterRoleSetStmt *n = makeNode(AlterRoleSetStmt);
1164 12 : n->role = $3;
1165 12 : n->database = $4;
1166 12 : n->setstmt = $5;
1167 12 : $$ = (Node *)n;
1168 : }
1169 : | ALTER USER ALL opt_in_database SetResetClause
1170 : {
1171 2 : AlterRoleSetStmt *n = makeNode(AlterRoleSetStmt);
1172 2 : n->role = NULL;
1173 2 : n->database = $4;
1174 2 : n->setstmt = $5;
1175 2 : $$ = (Node *)n;
1176 : }
1177 : ;
1178 :
1179 :
1180 : /*****************************************************************************
1181 : *
1182 : * Drop a postgresql DBMS role
1183 : *
1184 : * XXX Ideally this would have CASCADE/RESTRICT options, but a role
1185 : * might own objects in multiple databases, and there is presently no way to
1186 : * implement cascading to other databases. So we always behave as RESTRICT.
1187 : *****************************************************************************/
1188 :
1189 : DropRoleStmt:
1190 : DROP ROLE role_list
1191 : {
1192 65 : DropRoleStmt *n = makeNode(DropRoleStmt);
1193 65 : n->missing_ok = FALSE;
1194 65 : n->roles = $3;
1195 65 : $$ = (Node *)n;
1196 : }
1197 : | DROP ROLE IF_P EXISTS role_list
1198 : {
1199 18 : DropRoleStmt *n = makeNode(DropRoleStmt);
1200 18 : n->missing_ok = TRUE;
1201 18 : n->roles = $5;
1202 18 : $$ = (Node *)n;
1203 : }
1204 : | DROP USER role_list
1205 : {
1206 45 : DropRoleStmt *n = makeNode(DropRoleStmt);
1207 45 : n->missing_ok = FALSE;
1208 45 : n->roles = $3;
1209 45 : $$ = (Node *)n;
1210 : }
1211 : | DROP USER IF_P EXISTS role_list
1212 : {
1213 6 : DropRoleStmt *n = makeNode(DropRoleStmt);
1214 6 : n->roles = $5;
1215 6 : n->missing_ok = TRUE;
1216 6 : $$ = (Node *)n;
1217 : }
1218 : | DROP GROUP_P role_list
1219 : {
1220 6 : DropRoleStmt *n = makeNode(DropRoleStmt);
1221 6 : n->missing_ok = FALSE;
1222 6 : n->roles = $3;
1223 6 : $$ = (Node *)n;
1224 : }
1225 : | DROP GROUP_P IF_P EXISTS role_list
1226 : {
1227 1 : DropRoleStmt *n = makeNode(DropRoleStmt);
1228 1 : n->missing_ok = TRUE;
1229 1 : n->roles = $5;
1230 1 : $$ = (Node *)n;
1231 : }
1232 : ;
1233 :
1234 :
1235 : /*****************************************************************************
1236 : *
1237 : * Create a postgresql group (role without login ability)
1238 : *
1239 : *****************************************************************************/
1240 :
1241 : CreateGroupStmt:
1242 : CREATE GROUP_P RoleId opt_with OptRoleList
1243 : {
1244 4 : CreateRoleStmt *n = makeNode(CreateRoleStmt);
1245 4 : n->stmt_type = ROLESTMT_GROUP;
1246 4 : n->role = $3;
1247 4 : n->options = $5;
1248 4 : $$ = (Node *)n;
1249 : }
1250 : ;
1251 :
1252 :
1253 : /*****************************************************************************
1254 : *
1255 : * Alter a postgresql group
1256 : *
1257 : *****************************************************************************/
1258 :
1259 : AlterGroupStmt:
1260 : ALTER GROUP_P RoleSpec add_drop USER role_list
1261 : {
1262 3 : AlterRoleStmt *n = makeNode(AlterRoleStmt);
1263 3 : n->role = $3;
1264 3 : n->action = $4;
1265 3 : n->options = list_make1(makeDefElem("rolemembers",
1266 : (Node *)$6, @6));
1267 3 : $$ = (Node *)n;
1268 : }
1269 : ;
1270 :
1271 2 : add_drop: ADD_P { $$ = +1; }
1272 1 : | DROP { $$ = -1; }
1273 : ;
1274 :
1275 :
1276 : /*****************************************************************************
1277 : *
1278 : * Manipulate a schema
1279 : *
1280 : *****************************************************************************/
1281 :
1282 : CreateSchemaStmt:
1283 : CREATE SCHEMA OptSchemaName AUTHORIZATION RoleSpec OptSchemaEltList
1284 : {
1285 12 : CreateSchemaStmt *n = makeNode(CreateSchemaStmt);
1286 : /* One can omit the schema name or the authorization id. */
1287 12 : n->schemaname = $3;
1288 12 : n->authrole = $5;
1289 12 : n->schemaElts = $6;
1290 12 : n->if_not_exists = false;
1291 12 : $$ = (Node *)n;
1292 : }
1293 : | CREATE SCHEMA ColId OptSchemaEltList
1294 : {
1295 41 : CreateSchemaStmt *n = makeNode(CreateSchemaStmt);
1296 : /* ...but not both */
1297 41 : n->schemaname = $3;
1298 41 : n->authrole = NULL;
1299 41 : n->schemaElts = $4;
1300 41 : n->if_not_exists = false;
1301 41 : $$ = (Node *)n;
1302 : }
1303 : | CREATE SCHEMA IF_P NOT EXISTS OptSchemaName AUTHORIZATION RoleSpec OptSchemaEltList
1304 : {
1305 8 : CreateSchemaStmt *n = makeNode(CreateSchemaStmt);
1306 : /* schema name can be omitted here, too */
1307 8 : n->schemaname = $6;
1308 8 : n->authrole = $8;
1309 8 : if ($9 != NIL)
1310 0 : ereport(ERROR,
1311 : (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
1312 : errmsg("CREATE SCHEMA IF NOT EXISTS cannot include schema elements"),
1313 : parser_errposition(@9)));
1314 8 : n->schemaElts = $9;
1315 8 : n->if_not_exists = true;
1316 8 : $$ = (Node *)n;
1317 : }
1318 : | CREATE SCHEMA IF_P NOT EXISTS ColId OptSchemaEltList
1319 : {
1320 2 : CreateSchemaStmt *n = makeNode(CreateSchemaStmt);
1321 : /* ...but not here */
1322 2 : n->schemaname = $6;
1323 2 : n->authrole = NULL;
1324 2 : if ($7 != NIL)
1325 1 : ereport(ERROR,
1326 : (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
1327 : errmsg("CREATE SCHEMA IF NOT EXISTS cannot include schema elements"),
1328 : parser_errposition(@7)));
1329 1 : n->schemaElts = $7;
1330 1 : n->if_not_exists = true;
1331 1 : $$ = (Node *)n;
1332 : }
1333 : ;
1334 :
1335 : OptSchemaName:
1336 26 : ColId { $$ = $1; }
1337 0 : | /* EMPTY */ { $$ = NULL; }
1338 : ;
1339 :
1340 : OptSchemaEltList:
1341 : OptSchemaEltList schema_stmt
1342 : {
1343 12 : if (@$ < 0) /* see comments for YYLLOC_DEFAULT */
1344 7 : @$ = @2;
1345 12 : $$ = lappend($1, $2);
1346 : }
1347 : | /* EMPTY */
1348 63 : { $$ = NIL; }
1349 : ;
1350 :
1351 : /*
1352 : * schema_stmt are the ones that can show up inside a CREATE SCHEMA
1353 : * statement (in addition to by themselves).
1354 : */
1355 : schema_stmt:
1356 : CreateStmt
1357 : | IndexStmt
1358 : | CreateSeqStmt
1359 : | CreateTrigStmt
1360 : | GrantStmt
1361 : | ViewStmt
1362 : ;
1363 :
1364 :
1365 : /*****************************************************************************
1366 : *
1367 : * Set PG internal variable
1368 : * SET name TO 'var_value'
1369 : * Include SQL syntax (thomas 1997-10-22):
1370 : * SET TIME ZONE 'var_value'
1371 : *
1372 : *****************************************************************************/
1373 :
1374 : VariableSetStmt:
1375 : SET set_rest
1376 : {
1377 722 : VariableSetStmt *n = $2;
1378 722 : n->is_local = false;
1379 722 : $$ = (Node *) n;
1380 : }
1381 : | SET LOCAL set_rest
1382 : {
1383 33 : VariableSetStmt *n = $3;
1384 33 : n->is_local = true;
1385 33 : $$ = (Node *) n;
1386 : }
1387 : | SET SESSION set_rest
1388 : {
1389 11 : VariableSetStmt *n = $3;
1390 11 : n->is_local = false;
1391 11 : $$ = (Node *) n;
1392 : }
1393 : ;
1394 :
1395 : set_rest:
1396 : TRANSACTION transaction_mode_list
1397 : {
1398 18 : VariableSetStmt *n = makeNode(VariableSetStmt);
1399 18 : n->kind = VAR_SET_MULTI;
1400 18 : n->name = "TRANSACTION";
1401 18 : n->args = $2;
1402 18 : $$ = n;
1403 : }
1404 : | SESSION CHARACTERISTICS AS TRANSACTION transaction_mode_list
1405 : {
1406 2 : VariableSetStmt *n = makeNode(VariableSetStmt);
1407 2 : n->kind = VAR_SET_MULTI;
1408 2 : n->name = "SESSION CHARACTERISTICS";
1409 2 : n->args = $5;
1410 2 : $$ = n;
1411 : }
1412 : | set_rest_more
1413 : ;
1414 :
1415 : generic_set:
1416 : var_name TO var_list
1417 : {
1418 200 : VariableSetStmt *n = makeNode(VariableSetStmt);
1419 200 : n->kind = VAR_SET_VALUE;
1420 200 : n->name = $1;
1421 200 : n->args = $3;
1422 200 : $$ = n;
1423 : }
1424 : | var_name '=' var_list
1425 : {
1426 252 : VariableSetStmt *n = makeNode(VariableSetStmt);
1427 252 : n->kind = VAR_SET_VALUE;
1428 252 : n->name = $1;
1429 252 : n->args = $3;
1430 252 : $$ = n;
1431 : }
1432 : | var_name TO DEFAULT
1433 : {
1434 4 : VariableSetStmt *n = makeNode(VariableSetStmt);
1435 4 : n->kind = VAR_SET_DEFAULT;
1436 4 : n->name = $1;
1437 4 : $$ = n;
1438 : }
1439 : | var_name '=' DEFAULT
1440 : {
1441 0 : VariableSetStmt *n = makeNode(VariableSetStmt);
1442 0 : n->kind = VAR_SET_DEFAULT;
1443 0 : n->name = $1;
1444 0 : $$ = n;
1445 : }
1446 :
1447 : set_rest_more: /* Generic SET syntaxes: */
1448 456 : generic_set {$$ = $1;}
1449 : | var_name FROM CURRENT_P
1450 : {
1451 0 : VariableSetStmt *n = makeNode(VariableSetStmt);
1452 0 : n->kind = VAR_SET_CURRENT;
1453 0 : n->name = $1;
1454 0 : $$ = n;
1455 : }
1456 : /* Special syntaxes mandated by SQL standard: */
1457 : | TIME ZONE zone_value
1458 : {
1459 7 : VariableSetStmt *n = makeNode(VariableSetStmt);
1460 7 : n->kind = VAR_SET_VALUE;
1461 7 : n->name = "timezone";
1462 7 : if ($3 != NULL)
1463 7 : n->args = list_make1($3);
1464 : else
1465 0 : n->kind = VAR_SET_DEFAULT;
1466 7 : $$ = n;
1467 : }
1468 : | CATALOG_P Sconst
1469 : {
1470 0 : ereport(ERROR,
1471 : (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
1472 : errmsg("current database cannot be changed"),
1473 : parser_errposition(@2)));
1474 : $$ = NULL; /*not reached*/
1475 : }
1476 : | SCHEMA Sconst
1477 : {
1478 0 : VariableSetStmt *n = makeNode(VariableSetStmt);
1479 0 : n->kind = VAR_SET_VALUE;
1480 0 : n->name = "search_path";
1481 0 : n->args = list_make1(makeStringConst($2, @2));
1482 0 : $$ = n;
1483 : }
1484 : | NAMES opt_encoding
1485 : {
1486 0 : VariableSetStmt *n = makeNode(VariableSetStmt);
1487 0 : n->kind = VAR_SET_VALUE;
1488 0 : n->name = "client_encoding";
1489 0 : if ($2 != NULL)
1490 0 : n->args = list_make1(makeStringConst($2, @2));
1491 : else
1492 0 : n->kind = VAR_SET_DEFAULT;
1493 0 : $$ = n;
1494 : }
1495 : | ROLE NonReservedWord_or_Sconst
1496 : {
1497 75 : VariableSetStmt *n = makeNode(VariableSetStmt);
1498 75 : n->kind = VAR_SET_VALUE;
1499 75 : n->name = "role";
1500 75 : n->args = list_make1(makeStringConst($2, @2));
1501 75 : $$ = n;
1502 : }
1503 : | SESSION AUTHORIZATION NonReservedWord_or_Sconst
1504 : {
1505 237 : VariableSetStmt *n = makeNode(VariableSetStmt);
1506 237 : n->kind = VAR_SET_VALUE;
1507 237 : n->name = "session_authorization";
1508 237 : n->args = list_make1(makeStringConst($3, @3));
1509 237 : $$ = n;
1510 : }
1511 : | SESSION AUTHORIZATION DEFAULT
1512 : {
1513 0 : VariableSetStmt *n = makeNode(VariableSetStmt);
1514 0 : n->kind = VAR_SET_DEFAULT;
1515 0 : n->name = "session_authorization";
1516 0 : $$ = n;
1517 : }
1518 : | XML_P OPTION document_or_content
1519 : {
1520 2 : VariableSetStmt *n = makeNode(VariableSetStmt);
1521 2 : n->kind = VAR_SET_VALUE;
1522 2 : n->name = "xmloption";
1523 2 : n->args = list_make1(makeStringConst($3 == XMLOPTION_DOCUMENT ? "DOCUMENT" : "CONTENT", @3));
1524 2 : $$ = n;
1525 : }
1526 : /* Special syntaxes invented by PostgreSQL: */
1527 : | TRANSACTION SNAPSHOT Sconst
1528 : {
1529 0 : VariableSetStmt *n = makeNode(VariableSetStmt);
1530 0 : n->kind = VAR_SET_MULTI;
1531 0 : n->name = "TRANSACTION SNAPSHOT";
1532 0 : n->args = list_make1(makeStringConst($3, @3));
1533 0 : $$ = n;
1534 : }
1535 : ;
1536 :
1537 695 : var_name: ColId { $$ = $1; }
1538 : | var_name '.' ColId
1539 15 : { $$ = psprintf("%s.%s", $1, $3); }
1540 : ;
1541 :
1542 452 : var_list: var_value { $$ = list_make1($1); }
1543 11 : | var_list ',' var_value { $$ = lappend($1, $3); }
1544 : ;
1545 :
1546 : var_value: opt_boolean_or_string
1547 406 : { $$ = makeStringConst($1, @1); }
1548 : | NumericOnly
1549 57 : { $$ = makeAConst($1, @1); }
1550 : ;
1551 :
1552 0 : iso_level: READ UNCOMMITTED { $$ = "read uncommitted"; }
1553 2 : | READ COMMITTED { $$ = "read committed"; }
1554 3 : | REPEATABLE READ { $$ = "repeatable read"; }
1555 13 : | SERIALIZABLE { $$ = "serializable"; }
1556 : ;
1557 :
1558 : opt_boolean_or_string:
1559 10 : TRUE_P { $$ = "true"; }
1560 19 : | FALSE_P { $$ = "false"; }
1561 75 : | ON { $$ = "on"; }
1562 : /*
1563 : * OFF is also accepted as a boolean value, but is handled by
1564 : * the NonReservedWord rule. The action for booleans and strings
1565 : * is the same, so we don't need to distinguish them here.
1566 : */
1567 983 : | NonReservedWord_or_Sconst { $$ = $1; }
1568 : ;
1569 :
1570 : /* Timezone values can be:
1571 : * - a string such as 'pst8pdt'
1572 : * - an identifier such as "pst8pdt"
1573 : * - an integer or floating point number
1574 : * - a time interval per SQL99
1575 : * ColId gives reduce/reduce errors against ConstInterval and LOCAL,
1576 : * so use IDENT (meaning we reject anything that is a key word).
1577 : */
1578 : zone_value:
1579 : Sconst
1580 : {
1581 3 : $$ = makeStringConst($1, @1);
1582 : }
1583 : | IDENT
1584 : {
1585 0 : $$ = makeStringConst($1, @1);
1586 : }
1587 : | ConstInterval Sconst opt_interval
1588 : {
1589 0 : TypeName *t = $1;
1590 0 : if ($3 != NIL)
1591 : {
1592 0 : A_Const *n = (A_Const *) linitial($3);
1593 0 : if ((n->val.val.ival & ~(INTERVAL_MASK(HOUR) | INTERVAL_MASK(MINUTE))) != 0)
1594 0 : ereport(ERROR,
1595 : (errcode(ERRCODE_SYNTAX_ERROR),
1596 : errmsg("time zone interval must be HOUR or HOUR TO MINUTE"),
1597 : parser_errposition(@3)));
1598 : }
1599 0 : t->typmods = $3;
1600 0 : $$ = makeStringConstCast($2, @2, t);
1601 : }
1602 : | ConstInterval '(' Iconst ')' Sconst
1603 : {
1604 0 : TypeName *t = $1;
1605 0 : t->typmods = list_make2(makeIntConst(INTERVAL_FULL_RANGE, -1),
1606 : makeIntConst($3, @3));
1607 0 : $$ = makeStringConstCast($5, @5, t);
1608 : }
1609 4 : | NumericOnly { $$ = makeAConst($1, @1); }
1610 0 : | DEFAULT { $$ = NULL; }
1611 0 : | LOCAL { $$ = NULL; }
1612 : ;
1613 :
1614 : opt_encoding:
1615 0 : Sconst { $$ = $1; }
1616 0 : | DEFAULT { $$ = NULL; }
1617 0 : | /*EMPTY*/ { $$ = NULL; }
1618 : ;
1619 :
1620 : NonReservedWord_or_Sconst:
1621 1926 : NonReservedWord { $$ = $1; }
1622 147 : | Sconst { $$ = $1; }
1623 : ;
1624 :
1625 : VariableResetStmt:
1626 234 : RESET reset_rest { $$ = (Node *) $2; }
1627 : ;
1628 :
1629 : reset_rest:
1630 178 : generic_reset { $$ = $1; }
1631 : | TIME ZONE
1632 : {
1633 2 : VariableSetStmt *n = makeNode(VariableSetStmt);
1634 2 : n->kind = VAR_RESET;
1635 2 : n->name = "timezone";
1636 2 : $$ = n;
1637 : }
1638 : | TRANSACTION ISOLATION LEVEL
1639 : {
1640 0 : VariableSetStmt *n = makeNode(VariableSetStmt);
1641 0 : n->kind = VAR_RESET;
1642 0 : n->name = "transaction_isolation";
1643 0 : $$ = n;
1644 : }
1645 : | SESSION AUTHORIZATION
1646 : {
1647 54 : VariableSetStmt *n = makeNode(VariableSetStmt);
1648 54 : n->kind = VAR_RESET;
1649 54 : n->name = "session_authorization";
1650 54 : $$ = n;
1651 : }
1652 : ;
1653 :
1654 : generic_reset:
1655 : var_name
1656 : {
1657 176 : VariableSetStmt *n = makeNode(VariableSetStmt);
1658 176 : n->kind = VAR_RESET;
1659 176 : n->name = $1;
1660 176 : $$ = n;
1661 : }
1662 : | ALL
1663 : {
1664 2 : VariableSetStmt *n = makeNode(VariableSetStmt);
1665 2 : n->kind = VAR_RESET_ALL;
1666 2 : $$ = n;
1667 : }
1668 : ;
1669 :
1670 : /* SetResetClause allows SET or RESET without LOCAL */
1671 : SetResetClause:
1672 24 : SET set_rest { $$ = $2; }
1673 10 : | VariableResetStmt { $$ = (VariableSetStmt *) $1; }
1674 : ;
1675 :
1676 : /* SetResetClause allows SET or RESET without LOCAL */
1677 : FunctionSetResetClause:
1678 7 : SET set_rest_more { $$ = $2; }
1679 2 : | VariableResetStmt { $$ = (VariableSetStmt *) $1; }
1680 : ;
1681 :
1682 :
1683 : VariableShowStmt:
1684 : SHOW var_name
1685 : {
1686 63 : VariableShowStmt *n = makeNode(VariableShowStmt);
1687 63 : n->name = $2;
1688 63 : $$ = (Node *) n;
1689 : }
1690 : | SHOW TIME ZONE
1691 : {
1692 1 : VariableShowStmt *n = makeNode(VariableShowStmt);
1693 1 : n->name = "timezone";
1694 1 : $$ = (Node *) n;
1695 : }
1696 : | SHOW TRANSACTION ISOLATION LEVEL
1697 : {
1698 0 : VariableShowStmt *n = makeNode(VariableShowStmt);
1699 0 : n->name = "transaction_isolation";
1700 0 : $$ = (Node *) n;
1701 : }
1702 : | SHOW SESSION AUTHORIZATION
1703 : {
1704 0 : VariableShowStmt *n = makeNode(VariableShowStmt);
1705 0 : n->name = "session_authorization";
1706 0 : $$ = (Node *) n;
1707 : }
1708 : | SHOW ALL
1709 : {
1710 0 : VariableShowStmt *n = makeNode(VariableShowStmt);
1711 0 : n->name = "all";
1712 0 : $$ = (Node *) n;
1713 : }
1714 : ;
1715 :
1716 :
1717 : ConstraintsSetStmt:
1718 : SET CONSTRAINTS constraints_set_list constraints_set_mode
1719 : {
1720 12 : ConstraintsSetStmt *n = makeNode(ConstraintsSetStmt);
1721 12 : n->constraints = $3;
1722 12 : n->deferred = $4;
1723 12 : $$ = (Node *) n;
1724 : }
1725 : ;
1726 :
1727 : constraints_set_list:
1728 11 : ALL { $$ = NIL; }
1729 1 : | qualified_name_list { $$ = $1; }
1730 : ;
1731 :
1732 : constraints_set_mode:
1733 5 : DEFERRED { $$ = TRUE; }
1734 7 : | IMMEDIATE { $$ = FALSE; }
1735 : ;
1736 :
1737 :
1738 : /*
1739 : * Checkpoint statement
1740 : */
1741 : CheckPointStmt:
1742 : CHECKPOINT
1743 : {
1744 0 : CheckPointStmt *n = makeNode(CheckPointStmt);
1745 0 : $$ = (Node *)n;
1746 : }
1747 : ;
1748 :
1749 :
1750 : /*****************************************************************************
1751 : *
1752 : * DISCARD { ALL | TEMP | PLANS | SEQUENCES }
1753 : *
1754 : *****************************************************************************/
1755 :
1756 : DiscardStmt:
1757 : DISCARD ALL
1758 : {
1759 1 : DiscardStmt *n = makeNode(DiscardStmt);
1760 1 : n->target = DISCARD_ALL;
1761 1 : $$ = (Node *) n;
1762 : }
1763 : | DISCARD TEMP
1764 : {
1765 1 : DiscardStmt *n = makeNode(DiscardStmt);
1766 1 : n->target = DISCARD_TEMP;
1767 1 : $$ = (Node *) n;
1768 : }
1769 : | DISCARD TEMPORARY
1770 : {
1771 0 : DiscardStmt *n = makeNode(DiscardStmt);
1772 0 : n->target = DISCARD_TEMP;
1773 0 : $$ = (Node *) n;
1774 : }
1775 : | DISCARD PLANS
1776 : {
1777 0 : DiscardStmt *n = makeNode(DiscardStmt);
1778 0 : n->target = DISCARD_PLANS;
1779 0 : $$ = (Node *) n;
1780 : }
1781 : | DISCARD SEQUENCES
1782 : {
1783 2 : DiscardStmt *n = makeNode(DiscardStmt);
1784 2 : n->target = DISCARD_SEQUENCES;
1785 2 : $$ = (Node *) n;
1786 : }
1787 :
1788 : ;
1789 :
1790 :
1791 : /*****************************************************************************
1792 : *
1793 : * ALTER [ TABLE | INDEX | SEQUENCE | VIEW | MATERIALIZED VIEW ] variations
1794 : *
1795 : * Note: we accept all subcommands for each of the five variants, and sort
1796 : * out what's really legal at execution time.
1797 : *****************************************************************************/
1798 :
1799 : AlterTableStmt:
1800 : ALTER TABLE relation_expr alter_table_cmds
1801 : {
1802 769 : AlterTableStmt *n = makeNode(AlterTableStmt);
1803 769 : n->relation = $3;
1804 769 : n->cmds = $4;
1805 769 : n->relkind = OBJECT_TABLE;
1806 769 : n->missing_ok = false;
1807 769 : $$ = (Node *)n;
1808 : }
1809 : | ALTER TABLE IF_P EXISTS relation_expr alter_table_cmds
1810 : {
1811 9 : AlterTableStmt *n = makeNode(AlterTableStmt);
1812 9 : n->relation = $5;
1813 9 : n->cmds = $6;
1814 9 : n->relkind = OBJECT_TABLE;
1815 9 : n->missing_ok = true;
1816 9 : $$ = (Node *)n;
1817 : }
1818 : | ALTER TABLE relation_expr partition_cmd
1819 : {
1820 69 : AlterTableStmt *n = makeNode(AlterTableStmt);
1821 69 : n->relation = $3;
1822 69 : n->cmds = list_make1($4);
1823 69 : n->relkind = OBJECT_TABLE;
1824 69 : n->missing_ok = false;
1825 69 : $$ = (Node *)n;
1826 : }
1827 : | ALTER TABLE IF_P EXISTS relation_expr partition_cmd
1828 : {
1829 0 : AlterTableStmt *n = makeNode(AlterTableStmt);
1830 0 : n->relation = $5;
1831 0 : n->cmds = list_make1($6);
1832 0 : n->relkind = OBJECT_TABLE;
1833 0 : n->missing_ok = true;
1834 0 : $$ = (Node *)n;
1835 : }
1836 : | ALTER TABLE ALL IN_P TABLESPACE name SET TABLESPACE name opt_nowait
1837 : {
1838 2 : AlterTableMoveAllStmt *n =
1839 2 : makeNode(AlterTableMoveAllStmt);
1840 2 : n->orig_tablespacename = $6;
1841 2 : n->objtype = OBJECT_TABLE;
1842 2 : n->roles = NIL;
1843 2 : n->new_tablespacename = $9;
1844 2 : n->nowait = $10;
1845 2 : $$ = (Node *)n;
1846 : }
1847 : | ALTER TABLE ALL IN_P TABLESPACE name OWNED BY role_list SET TABLESPACE name opt_nowait
1848 : {
1849 0 : AlterTableMoveAllStmt *n =
1850 0 : makeNode(AlterTableMoveAllStmt);
1851 0 : n->orig_tablespacename = $6;
1852 0 : n->objtype = OBJECT_TABLE;
1853 0 : n->roles = $9;
1854 0 : n->new_tablespacename = $12;
1855 0 : n->nowait = $13;
1856 0 : $$ = (Node *)n;
1857 : }
1858 : | ALTER INDEX qualified_name alter_table_cmds
1859 : {
1860 2 : AlterTableStmt *n = makeNode(AlterTableStmt);
1861 2 : n->relation = $3;
1862 2 : n->cmds = $4;
1863 2 : n->relkind = OBJECT_INDEX;
1864 2 : n->missing_ok = false;
1865 2 : $$ = (Node *)n;
1866 : }
1867 : | ALTER INDEX IF_P EXISTS qualified_name alter_table_cmds
1868 : {
1869 0 : AlterTableStmt *n = makeNode(AlterTableStmt);
1870 0 : n->relation = $5;
1871 0 : n->cmds = $6;
1872 0 : n->relkind = OBJECT_INDEX;
1873 0 : n->missing_ok = true;
1874 0 : $$ = (Node *)n;
1875 : }
1876 : | ALTER INDEX ALL IN_P TABLESPACE name SET TABLESPACE name opt_nowait
1877 : {
1878 1 : AlterTableMoveAllStmt *n =
1879 1 : makeNode(AlterTableMoveAllStmt);
1880 1 : n->orig_tablespacename = $6;
1881 1 : n->objtype = OBJECT_INDEX;
1882 1 : n->roles = NIL;
1883 1 : n->new_tablespacename = $9;
1884 1 : n->nowait = $10;
1885 1 : $$ = (Node *)n;
1886 : }
1887 : | ALTER INDEX ALL IN_P TABLESPACE name OWNED BY role_list SET TABLESPACE name opt_nowait
1888 : {
1889 0 : AlterTableMoveAllStmt *n =
1890 0 : makeNode(AlterTableMoveAllStmt);
1891 0 : n->orig_tablespacename = $6;
1892 0 : n->objtype = OBJECT_INDEX;
1893 0 : n->roles = $9;
1894 0 : n->new_tablespacename = $12;
1895 0 : n->nowait = $13;
1896 0 : $$ = (Node *)n;
1897 : }
1898 : | ALTER SEQUENCE qualified_name alter_table_cmds
1899 : {
1900 0 : AlterTableStmt *n = makeNode(AlterTableStmt);
1901 0 : n->relation = $3;
1902 0 : n->cmds = $4;
1903 0 : n->relkind = OBJECT_SEQUENCE;
1904 0 : n->missing_ok = false;
1905 0 : $$ = (Node *)n;
1906 : }
1907 : | ALTER SEQUENCE IF_P EXISTS qualified_name alter_table_cmds
1908 : {
1909 0 : AlterTableStmt *n = makeNode(AlterTableStmt);
1910 0 : n->relation = $5;
1911 0 : n->cmds = $6;
1912 0 : n->relkind = OBJECT_SEQUENCE;
1913 0 : n->missing_ok = true;
1914 0 : $$ = (Node *)n;
1915 : }
1916 : | ALTER VIEW qualified_name alter_table_cmds
1917 : {
1918 13 : AlterTableStmt *n = makeNode(AlterTableStmt);
1919 13 : n->relation = $3;
1920 13 : n->cmds = $4;
1921 13 : n->relkind = OBJECT_VIEW;
1922 13 : n->missing_ok = false;
1923 13 : $$ = (Node *)n;
1924 : }
1925 : | ALTER VIEW IF_P EXISTS qualified_name alter_table_cmds
1926 : {
1927 0 : AlterTableStmt *n = makeNode(AlterTableStmt);
1928 0 : n->relation = $5;
1929 0 : n->cmds = $6;
1930 0 : n->relkind = OBJECT_VIEW;
1931 0 : n->missing_ok = true;
1932 0 : $$ = (Node *)n;
1933 : }
1934 : | ALTER MATERIALIZED VIEW qualified_name alter_table_cmds
1935 : {
1936 0 : AlterTableStmt *n = makeNode(AlterTableStmt);
1937 0 : n->relation = $4;
1938 0 : n->cmds = $5;
1939 0 : n->relkind = OBJECT_MATVIEW;
1940 0 : n->missing_ok = false;
1941 0 : $$ = (Node *)n;
1942 : }
1943 : | ALTER MATERIALIZED VIEW IF_P EXISTS qualified_name alter_table_cmds
1944 : {
1945 0 : AlterTableStmt *n = makeNode(AlterTableStmt);
1946 0 : n->relation = $6;
1947 0 : n->cmds = $7;
1948 0 : n->relkind = OBJECT_MATVIEW;
1949 0 : n->missing_ok = true;
1950 0 : $$ = (Node *)n;
1951 : }
1952 : | ALTER MATERIALIZED VIEW ALL IN_P TABLESPACE name SET TABLESPACE name opt_nowait
1953 : {
1954 0 : AlterTableMoveAllStmt *n =
1955 0 : makeNode(AlterTableMoveAllStmt);
1956 0 : n->orig_tablespacename = $7;
1957 0 : n->objtype = OBJECT_MATVIEW;
1958 0 : n->roles = NIL;
1959 0 : n->new_tablespacename = $10;
1960 0 : n->nowait = $11;
1961 0 : $$ = (Node *)n;
1962 : }
1963 : | ALTER MATERIALIZED VIEW ALL IN_P TABLESPACE name OWNED BY role_list SET TABLESPACE name opt_nowait
1964 : {
1965 0 : AlterTableMoveAllStmt *n =
1966 0 : makeNode(AlterTableMoveAllStmt);
1967 0 : n->orig_tablespacename = $7;
1968 0 : n->objtype = OBJECT_MATVIEW;
1969 0 : n->roles = $10;
1970 0 : n->new_tablespacename = $13;
1971 0 : n->nowait = $14;
1972 0 : $$ = (Node *)n;
1973 : }
1974 : ;
1975 :
1976 : alter_table_cmds:
1977 854 : alter_table_cmd { $$ = list_make1($1); }
1978 16 : | alter_table_cmds ',' alter_table_cmd { $$ = lappend($1, $3); }
1979 : ;
1980 :
1981 : partition_cmd:
1982 : /* ALTER TABLE <name> ATTACH PARTITION <table_name> FOR VALUES */
1983 : ATTACH PARTITION qualified_name ForValues
1984 : {
1985 57 : AlterTableCmd *n = makeNode(AlterTableCmd);
1986 57 : PartitionCmd *cmd = makeNode(PartitionCmd);
1987 :
1988 57 : n->subtype = AT_AttachPartition;
1989 57 : cmd->name = $3;
1990 57 : cmd->bound = $4;
1991 57 : n->def = (Node *) cmd;
1992 :
1993 57 : $$ = (Node *) n;
1994 : }
1995 : /* ALTER TABLE <name> DETACH PARTITION <partition_name> */
1996 : | DETACH PARTITION qualified_name
1997 : {
1998 12 : AlterTableCmd *n = makeNode(AlterTableCmd);
1999 12 : PartitionCmd *cmd = makeNode(PartitionCmd);
2000 :
2001 12 : n->subtype = AT_DetachPartition;
2002 12 : cmd->name = $3;
2003 12 : cmd->bound = NULL;
2004 12 : n->def = (Node *) cmd;
2005 :
2006 12 : $$ = (Node *) n;
2007 : }
2008 : ;
2009 :
2010 : alter_table_cmd:
2011 : /* ALTER TABLE <name> ADD <coldef> */
2012 : ADD_P columnDef
2013 : {
2014 15 : AlterTableCmd *n = makeNode(AlterTableCmd);
2015 15 : n->subtype = AT_AddColumn;
2016 15 : n->def = $2;
2017 15 : n->missing_ok = false;
2018 15 : $$ = (Node *)n;
2019 : }
2020 : /* ALTER TABLE <name> ADD IF NOT EXISTS <coldef> */
2021 : | ADD_P IF_P NOT EXISTS columnDef
2022 : {
2023 0 : AlterTableCmd *n = makeNode(AlterTableCmd);
2024 0 : n->subtype = AT_AddColumn;
2025 0 : n->def = $5;
2026 0 : n->missing_ok = true;
2027 0 : $$ = (Node *)n;
2028 : }
2029 : /* ALTER TABLE <name> ADD COLUMN <coldef> */
2030 : | ADD_P COLUMN columnDef
2031 : {
2032 126 : AlterTableCmd *n = makeNode(AlterTableCmd);
2033 126 : n->subtype = AT_AddColumn;
2034 126 : n->def = $3;
2035 126 : n->missing_ok = false;
2036 126 : $$ = (Node *)n;
2037 : }
2038 : /* ALTER TABLE <name> ADD COLUMN IF NOT EXISTS <coldef> */
2039 : | ADD_P COLUMN IF_P NOT EXISTS columnDef
2040 : {
2041 6 : AlterTableCmd *n = makeNode(AlterTableCmd);
2042 6 : n->subtype = AT_AddColumn;
2043 6 : n->def = $6;
2044 6 : n->missing_ok = true;
2045 6 : $$ = (Node *)n;
2046 : }
2047 : /* ALTER TABLE <name> ALTER [COLUMN] <colname> {SET DEFAULT <expr>|DROP DEFAULT} */
2048 : | ALTER opt_column ColId alter_column_default
2049 : {
2050 31 : AlterTableCmd *n = makeNode(AlterTableCmd);
2051 31 : n->subtype = AT_ColumnDefault;
2052 31 : n->name = $3;
2053 31 : n->def = $4;
2054 31 : $$ = (Node *)n;
2055 : }
2056 : /* ALTER TABLE <name> ALTER [COLUMN] <colname> DROP NOT NULL */
2057 : | ALTER opt_column ColId DROP NOT NULL_P
2058 : {
2059 19 : AlterTableCmd *n = makeNode(AlterTableCmd);
2060 19 : n->subtype = AT_DropNotNull;
2061 19 : n->name = $3;
2062 19 : $$ = (Node *)n;
2063 : }
2064 : /* ALTER TABLE <name> ALTER [COLUMN] <colname> SET NOT NULL */
2065 : | ALTER opt_column ColId SET NOT NULL_P
2066 : {
2067 28 : AlterTableCmd *n = makeNode(AlterTableCmd);
2068 28 : n->subtype = AT_SetNotNull;
2069 28 : n->name = $3;
2070 28 : $$ = (Node *)n;
2071 : }
2072 : /* ALTER TABLE <name> ALTER [COLUMN] <colname> SET STATISTICS <SignedIconst> */
2073 : | ALTER opt_column ColId SET STATISTICS SignedIconst
2074 : {
2075 9 : AlterTableCmd *n = makeNode(AlterTableCmd);
2076 9 : n->subtype = AT_SetStatistics;
2077 9 : n->name = $3;
2078 9 : n->def = (Node *) makeInteger($6);
2079 9 : $$ = (Node *)n;
2080 : }
2081 : /* ALTER TABLE <name> ALTER [COLUMN] <colname> SET ( column_parameter = value [, ... ] ) */
2082 : | ALTER opt_column ColId SET reloptions
2083 : {
2084 3 : AlterTableCmd *n = makeNode(AlterTableCmd);
2085 3 : n->subtype = AT_SetOptions;
2086 3 : n->name = $3;
2087 3 : n->def = (Node *) $5;
2088 3 : $$ = (Node *)n;
2089 : }
2090 : /* ALTER TABLE <name> ALTER [COLUMN] <colname> RESET ( column_parameter = value [, ... ] ) */
2091 : | ALTER opt_column ColId RESET reloptions
2092 : {
2093 0 : AlterTableCmd *n = makeNode(AlterTableCmd);
2094 0 : n->subtype = AT_ResetOptions;
2095 0 : n->name = $3;
2096 0 : n->def = (Node *) $5;
2097 0 : $$ = (Node *)n;
2098 : }
2099 : /* ALTER TABLE <name> ALTER [COLUMN] <colname> SET STORAGE <storagemode> */
2100 : | ALTER opt_column ColId SET STORAGE ColId
2101 : {
2102 14 : AlterTableCmd *n = makeNode(AlterTableCmd);
2103 14 : n->subtype = AT_SetStorage;
2104 14 : n->name = $3;
2105 14 : n->def = (Node *) makeString($6);
2106 14 : $$ = (Node *)n;
2107 : }
2108 : /* ALTER TABLE <name> ALTER [COLUMN] <colname> ADD GENERATED ... AS IDENTITY ... */
2109 : | ALTER opt_column ColId ADD_P GENERATED generated_when AS IDENTITY_P OptParenthesizedSeqOptList
2110 : {
2111 7 : AlterTableCmd *n = makeNode(AlterTableCmd);
2112 7 : Constraint *c = makeNode(Constraint);
2113 :
2114 7 : c->contype = CONSTR_IDENTITY;
2115 7 : c->generated_when = $6;
2116 7 : c->options = $9;
2117 7 : c->location = @5;
2118 :
2119 7 : n->subtype = AT_AddIdentity;
2120 7 : n->name = $3;
2121 7 : n->def = (Node *) c;
2122 :
2123 7 : $$ = (Node *)n;
2124 : }
2125 : /* ALTER TABLE <name> ALTER [COLUMN] <colname> SET <sequence options>/RESET */
2126 : | ALTER opt_column ColId alter_identity_column_option_list
2127 : {
2128 4 : AlterTableCmd *n = makeNode(AlterTableCmd);
2129 4 : n->subtype = AT_SetIdentity;
2130 4 : n->name = $3;
2131 4 : n->def = (Node *) $4;
2132 4 : $$ = (Node *)n;
2133 : }
2134 : /* ALTER TABLE <name> ALTER [COLUMN] <colname> DROP IDENTITY */
2135 : | ALTER opt_column ColId DROP IDENTITY_P
2136 : {
2137 3 : AlterTableCmd *n = makeNode(AlterTableCmd);
2138 3 : n->subtype = AT_DropIdentity;
2139 3 : n->name = $3;
2140 3 : n->missing_ok = false;
2141 3 : $$ = (Node *)n;
2142 : }
2143 : /* ALTER TABLE <name> ALTER [COLUMN] <colname> DROP IDENTITY IF EXISTS */
2144 : | ALTER opt_column ColId DROP IDENTITY_P IF_P EXISTS
2145 : {
2146 1 : AlterTableCmd *n = makeNode(AlterTableCmd);
2147 1 : n->subtype = AT_DropIdentity;
2148 1 : n->name = $3;
2149 1 : n->missing_ok = true;
2150 1 : $$ = (Node *)n;
2151 : }
2152 : /* ALTER TABLE <name> DROP [COLUMN] IF EXISTS <colname> [RESTRICT|CASCADE] */
2153 : | DROP opt_column IF_P EXISTS ColId opt_drop_behavior
2154 : {
2155 3 : AlterTableCmd *n = makeNode(AlterTableCmd);
2156 3 : n->subtype = AT_DropColumn;
2157 3 : n->name = $5;
2158 3 : n->behavior = $6;
2159 3 : n->missing_ok = TRUE;
2160 3 : $$ = (Node *)n;
2161 : }
2162 : /* ALTER TABLE <name> DROP [COLUMN] <colname> [RESTRICT|CASCADE] */
2163 : | DROP opt_column ColId opt_drop_behavior
2164 : {
2165 97 : AlterTableCmd *n = makeNode(AlterTableCmd);
2166 97 : n->subtype = AT_DropColumn;
2167 97 : n->name = $3;
2168 97 : n->behavior = $4;
2169 97 : n->missing_ok = FALSE;
2170 97 : $$ = (Node *)n;
2171 : }
2172 : /*
2173 : * ALTER TABLE <name> ALTER [COLUMN] <colname> [SET DATA] TYPE <typename>
2174 : * [ USING <expression> ]
2175 : */
2176 : | ALTER opt_column ColId opt_set_data TYPE_P Typename opt_collate_clause alter_using
2177 : {
2178 61 : AlterTableCmd *n = makeNode(AlterTableCmd);
2179 61 : ColumnDef *def = makeNode(ColumnDef);
2180 61 : n->subtype = AT_AlterColumnType;
2181 61 : n->name = $3;
2182 61 : n->def = (Node *) def;
2183 : /* We only use these fields of the ColumnDef node */
2184 61 : def->typeName = $6;
2185 61 : def->collClause = (CollateClause *) $7;
2186 61 : def->raw_default = $8;
2187 61 : def->location = @3;
2188 61 : $$ = (Node *)n;
2189 : }
2190 : /* ALTER FOREIGN TABLE <name> ALTER [COLUMN] <colname> OPTIONS */
2191 : | ALTER opt_column ColId alter_generic_options
2192 : {
2193 7 : AlterTableCmd *n = makeNode(AlterTableCmd);
2194 7 : n->subtype = AT_AlterColumnGenericOptions;
2195 7 : n->name = $3;
2196 7 : n->def = (Node *) $4;
2197 7 : $$ = (Node *)n;
2198 : }
2199 : /* ALTER TABLE <name> ADD CONSTRAINT ... */
2200 : | ADD_P TableConstraint
2201 : {
2202 173 : AlterTableCmd *n = makeNode(AlterTableCmd);
2203 173 : n->subtype = AT_AddConstraint;
2204 173 : n->def = $2;
2205 173 : $$ = (Node *)n;
2206 : }
2207 : /* ALTER TABLE <name> ALTER CONSTRAINT ... */
2208 : | ALTER CONSTRAINT name ConstraintAttributeSpec
2209 : {
2210 6 : AlterTableCmd *n = makeNode(AlterTableCmd);
2211 6 : Constraint *c = makeNode(Constraint);
2212 6 : n->subtype = AT_AlterConstraint;
2213 6 : n->def = (Node *) c;
2214 6 : c->contype = CONSTR_FOREIGN; /* others not supported, yet */
2215 6 : c->conname = $3;
2216 6 : processCASbits($4, @4, "ALTER CONSTRAINT statement",
2217 : &c->deferrable,
2218 : &c->initdeferred,
2219 : NULL, NULL, yyscanner);
2220 6 : $$ = (Node *)n;
2221 : }
2222 : /* ALTER TABLE <name> VALIDATE CONSTRAINT ... */
2223 : | VALIDATE CONSTRAINT name
2224 : {
2225 15 : AlterTableCmd *n = makeNode(AlterTableCmd);
2226 15 : n->subtype = AT_ValidateConstraint;
2227 15 : n->name = $3;
2228 15 : $$ = (Node *)n;
2229 : }
2230 : /* ALTER TABLE <name> DROP CONSTRAINT IF EXISTS <name> [RESTRICT|CASCADE] */
2231 : | DROP CONSTRAINT IF_P EXISTS name opt_drop_behavior
2232 : {
2233 3 : AlterTableCmd *n = makeNode(AlterTableCmd);
2234 3 : n->subtype = AT_DropConstraint;
2235 3 : n->name = $5;
2236 3 : n->behavior = $6;
2237 3 : n->missing_ok = TRUE;
2238 3 : $$ = (Node *)n;
2239 : }
2240 : /* ALTER TABLE <name> DROP CONSTRAINT <name> [RESTRICT|CASCADE] */
2241 : | DROP CONSTRAINT name opt_drop_behavior
2242 : {
2243 45 : AlterTableCmd *n = makeNode(AlterTableCmd);
2244 45 : n->subtype = AT_DropConstraint;
2245 45 : n->name = $3;
2246 45 : n->behavior = $4;
2247 45 : n->missing_ok = FALSE;
2248 45 : $$ = (Node *)n;
2249 : }
2250 : /* ALTER TABLE <name> SET WITH OIDS */
2251 : | SET WITH OIDS
2252 : {
2253 9 : AlterTableCmd *n = makeNode(AlterTableCmd);
2254 9 : n->subtype = AT_AddOids;
2255 9 : $$ = (Node *)n;
2256 : }
2257 : /* ALTER TABLE <name> SET WITHOUT OIDS */
2258 : | SET WITHOUT OIDS
2259 : {
2260 10 : AlterTableCmd *n = makeNode(AlterTableCmd);
2261 10 : n->subtype = AT_DropOids;
2262 10 : $$ = (Node *)n;
2263 : }
2264 : /* ALTER TABLE <name> CLUSTER ON <indexname> */
2265 : | CLUSTER ON name
2266 : {
2267 3 : AlterTableCmd *n = makeNode(AlterTableCmd);
2268 3 : n->subtype = AT_ClusterOn;
2269 3 : n->name = $3;
2270 3 : $$ = (Node *)n;
2271 : }
2272 : /* ALTER TABLE <name> SET WITHOUT CLUSTER */
2273 : | SET WITHOUT CLUSTER
2274 : {
2275 2 : AlterTableCmd *n = makeNode(AlterTableCmd);
2276 2 : n->subtype = AT_DropCluster;
2277 2 : n->name = NULL;
2278 2 : $$ = (Node *)n;
2279 : }
2280 : /* ALTER TABLE <name> SET LOGGED */
2281 : | SET LOGGED
2282 : {
2283 4 : AlterTableCmd *n = makeNode(AlterTableCmd);
2284 4 : n->subtype = AT_SetLogged;
2285 4 : $$ = (Node *)n;
2286 : }
2287 : /* ALTER TABLE <name> SET UNLOGGED */
2288 : | SET UNLOGGED
2289 : {
2290 5 : AlterTableCmd *n = makeNode(AlterTableCmd);
2291 5 : n->subtype = AT_SetUnLogged;
2292 5 : $$ = (Node *)n;
2293 : }
2294 : /* ALTER TABLE <name> ENABLE TRIGGER <trig> */
2295 : | ENABLE_P TRIGGER name
2296 : {
2297 2 : AlterTableCmd *n = makeNode(AlterTableCmd);
2298 2 : n->subtype = AT_EnableTrig;
2299 2 : n->name = $3;
2300 2 : $$ = (Node *)n;
2301 : }
2302 : /* ALTER TABLE <name> ENABLE ALWAYS TRIGGER <trig> */
2303 : | ENABLE_P ALWAYS TRIGGER name
2304 : {
2305 0 : AlterTableCmd *n = makeNode(AlterTableCmd);
2306 0 : n->subtype = AT_EnableAlwaysTrig;
2307 0 : n->name = $4;
2308 0 : $$ = (Node *)n;
2309 : }
2310 : /* ALTER TABLE <name> ENABLE REPLICA TRIGGER <trig> */
2311 : | ENABLE_P REPLICA TRIGGER name
2312 : {
2313 0 : AlterTableCmd *n = makeNode(AlterTableCmd);
2314 0 : n->subtype = AT_EnableReplicaTrig;
2315 0 : n->name = $4;
2316 0 : $$ = (Node *)n;
2317 : }
2318 : /* ALTER TABLE <name> ENABLE TRIGGER ALL */
2319 : | ENABLE_P TRIGGER ALL
2320 : {
2321 0 : AlterTableCmd *n = makeNode(AlterTableCmd);
2322 0 : n->subtype = AT_EnableTrigAll;
2323 0 : $$ = (Node *)n;
2324 : }
2325 : /* ALTER TABLE <name> ENABLE TRIGGER USER */
2326 : | ENABLE_P TRIGGER USER
2327 : {
2328 0 : AlterTableCmd *n = makeNode(AlterTableCmd);
2329 0 : n->subtype = AT_EnableTrigUser;
2330 0 : $$ = (Node *)n;
2331 : }
2332 : /* ALTER TABLE <name> DISABLE TRIGGER <trig> */
2333 : | DISABLE_P TRIGGER name
2334 : {
2335 2 : AlterTableCmd *n = makeNode(AlterTableCmd);
2336 2 : n->subtype = AT_DisableTrig;
2337 2 : n->name = $3;
2338 2 : $$ = (Node *)n;
2339 : }
2340 : /* ALTER TABLE <name> DISABLE TRIGGER ALL */
2341 : | DISABLE_P TRIGGER ALL
2342 : {
2343 1 : AlterTableCmd *n = makeNode(AlterTableCmd);
2344 1 : n->subtype = AT_DisableTrigAll;
2345 1 : $$ = (Node *)n;
2346 : }
2347 : /* ALTER TABLE <name> DISABLE TRIGGER USER */
2348 : | DISABLE_P TRIGGER USER
2349 : {
2350 1 : AlterTableCmd *n = makeNode(AlterTableCmd);
2351 1 : n->subtype = AT_DisableTrigUser;
2352 1 : $$ = (Node *)n;
2353 : }
2354 : /* ALTER TABLE <name> ENABLE RULE <rule> */
2355 : | ENABLE_P RULE name
2356 : {
2357 0 : AlterTableCmd *n = makeNode(AlterTableCmd);
2358 0 : n->subtype = AT_EnableRule;
2359 0 : n->name = $3;
2360 0 : $$ = (Node *)n;
2361 : }
2362 : /* ALTER TABLE <name> ENABLE ALWAYS RULE <rule> */
2363 : | ENABLE_P ALWAYS RULE name
2364 : {
2365 0 : AlterTableCmd *n = makeNode(AlterTableCmd);
2366 0 : n->subtype = AT_EnableAlwaysRule;
2367 0 : n->name = $4;
2368 0 : $$ = (Node *)n;
2369 : }
2370 : /* ALTER TABLE <name> ENABLE REPLICA RULE <rule> */
2371 : | ENABLE_P REPLICA RULE name
2372 : {
2373 0 : AlterTableCmd *n = makeNode(AlterTableCmd);
2374 0 : n->subtype = AT_EnableReplicaRule;
2375 0 : n->name = $4;
2376 0 : $$ = (Node *)n;
2377 : }
2378 : /* ALTER TABLE <name> DISABLE RULE <rule> */
2379 : | DISABLE_P RULE name
2380 : {
2381 0 : AlterTableCmd *n = makeNode(AlterTableCmd);
2382 0 : n->subtype = AT_DisableRule;
2383 0 : n->name = $3;
2384 0 : $$ = (Node *)n;
2385 : }
2386 : /* ALTER TABLE <name> INHERIT <parent> */
2387 : | INHERIT qualified_name
2388 : {
2389 25 : AlterTableCmd *n = makeNode(AlterTableCmd);
2390 25 : n->subtype = AT_AddInherit;
2391 25 : n->def = (Node *) $2;
2392 25 : $$ = (Node *)n;
2393 : }
2394 : /* ALTER TABLE <name> NO INHERIT <parent> */
2395 : | NO INHERIT qualified_name
2396 : {
2397 5 : AlterTableCmd *n = makeNode(AlterTableCmd);
2398 5 : n->subtype = AT_DropInherit;
2399 5 : n->def = (Node *) $3;
2400 5 : $$ = (Node *)n;
2401 : }
2402 : /* ALTER TABLE <name> OF <type_name> */
2403 : | OF any_name
2404 : {
2405 9 : AlterTableCmd *n = makeNode(AlterTableCmd);
2406 9 : TypeName *def = makeTypeNameFromNameList($2);
2407 9 : def->location = @2;
2408 9 : n->subtype = AT_AddOf;
2409 9 : n->def = (Node *) def;
2410 9 : $$ = (Node *)n;
2411 : }
2412 : /* ALTER TABLE <name> NOT OF */
2413 : | NOT OF
2414 : {
2415 1 : AlterTableCmd *n = makeNode(AlterTableCmd);
2416 1 : n->subtype = AT_DropOf;
2417 1 : $$ = (Node *)n;
2418 : }
2419 : /* ALTER TABLE <name> OWNER TO RoleSpec */
2420 : | OWNER TO RoleSpec
2421 : {
2422 18 : AlterTableCmd *n = makeNode(AlterTableCmd);
2423 18 : n->subtype = AT_ChangeOwner;
2424 18 : n->newowner = $3;
2425 18 : $$ = (Node *)n;
2426 : }
2427 : /* ALTER TABLE <name> SET TABLESPACE <tablespacename> */
2428 : | SET TABLESPACE name
2429 : {
2430 3 : AlterTableCmd *n = makeNode(AlterTableCmd);
2431 3 : n->subtype = AT_SetTableSpace;
2432 3 : n->name = $3;
2433 3 : $$ = (Node *)n;
2434 : }
2435 : /* ALTER TABLE <name> SET (...) */
2436 : | SET reloptions
2437 : {
2438 17 : AlterTableCmd *n = makeNode(AlterTableCmd);
2439 17 : n->subtype = AT_SetRelOptions;
2440 17 : n->def = (Node *)$2;
2441 17 : $$ = (Node *)n;
2442 : }
2443 : /* ALTER TABLE <name> RESET (...) */
2444 : | RESET reloptions
2445 : {
2446 7 : AlterTableCmd *n = makeNode(AlterTableCmd);
2447 7 : n->subtype = AT_ResetRelOptions;
2448 7 : n->def = (Node *)$2;
2449 7 : $$ = (Node *)n;
2450 : }
2451 : /* ALTER TABLE <name> REPLICA IDENTITY */
2452 : | REPLICA IDENTITY_P replica_identity
2453 : {
2454 15 : AlterTableCmd *n = makeNode(AlterTableCmd);
2455 15 : n->subtype = AT_ReplicaIdentity;
2456 15 : n->def = $3;
2457 15 : $$ = (Node *)n;
2458 : }
2459 : /* ALTER TABLE <name> ENABLE ROW LEVEL SECURITY */
2460 : | ENABLE_P ROW LEVEL SECURITY
2461 : {
2462 37 : AlterTableCmd *n = makeNode(AlterTableCmd);
2463 37 : n->subtype = AT_EnableRowSecurity;
2464 37 : $$ = (Node *)n;
2465 : }
2466 : /* ALTER TABLE <name> DISABLE ROW LEVEL SECURITY */
2467 : | DISABLE_P ROW LEVEL SECURITY
2468 : {
2469 2 : AlterTableCmd *n = makeNode(AlterTableCmd);
2470 2 : n->subtype = AT_DisableRowSecurity;
2471 2 : $$ = (Node *)n;
2472 : }
2473 : /* ALTER TABLE <name> FORCE ROW LEVEL SECURITY */
2474 : | FORCE ROW LEVEL SECURITY
2475 : {
2476 10 : AlterTableCmd *n = makeNode(AlterTableCmd);
2477 10 : n->subtype = AT_ForceRowSecurity;
2478 10 : $$ = (Node *)n;
2479 : }
2480 : /* ALTER TABLE <name> NO FORCE ROW LEVEL SECURITY */
2481 : | NO FORCE ROW LEVEL SECURITY
2482 : {
2483 4 : AlterTableCmd *n = makeNode(AlterTableCmd);
2484 4 : n->subtype = AT_NoForceRowSecurity;
2485 4 : $$ = (Node *)n;
2486 : }
2487 : | alter_generic_options
2488 : {
2489 2 : AlterTableCmd *n = makeNode(AlterTableCmd);
2490 2 : n->subtype = AT_GenericOptions;
2491 2 : n->def = (Node *)$1;
2492 2 : $$ = (Node *) n;
2493 : }
2494 : ;
2495 :
2496 : alter_column_default:
2497 22 : SET DEFAULT a_expr { $$ = $3; }
2498 11 : | DROP DEFAULT { $$ = NULL; }
2499 : ;
2500 :
2501 : opt_drop_behavior:
2502 166 : CASCADE { $$ = DROP_CASCADE; }
2503 23 : | RESTRICT { $$ = DROP_RESTRICT; }
2504 1629 : | /* EMPTY */ { $$ = DROP_RESTRICT; /* default */ }
2505 : ;
2506 :
2507 : opt_collate_clause:
2508 : COLLATE any_name
2509 : {
2510 1 : CollateClause *n = makeNode(CollateClause);
2511 1 : n->arg = NULL;
2512 1 : n->collname = $2;
2513 1 : n->location = @1;
2514 1 : $$ = (Node *) n;
2515 : }
2516 316 : | /* EMPTY */ { $$ = NULL; }
2517 : ;
2518 :
2519 : alter_using:
2520 17 : USING a_expr { $$ = $2; }
2521 44 : | /* EMPTY */ { $$ = NULL; }
2522 : ;
2523 :
2524 : replica_identity:
2525 : NOTHING
2526 : {
2527 1 : ReplicaIdentityStmt *n = makeNode(ReplicaIdentityStmt);
2528 1 : n->identity_type = REPLICA_IDENTITY_NOTHING;
2529 1 : n->name = NULL;
2530 1 : $$ = (Node *) n;
2531 : }
2532 : | FULL
2533 : {
2534 1 : ReplicaIdentityStmt *n = makeNode(ReplicaIdentityStmt);
2535 1 : n->identity_type = REPLICA_IDENTITY_FULL;
2536 1 : n->name = NULL;
2537 1 : $$ = (Node *) n;
2538 : }
2539 : | DEFAULT
2540 : {
2541 1 : ReplicaIdentityStmt *n = makeNode(ReplicaIdentityStmt);
2542 1 : n->identity_type = REPLICA_IDENTITY_DEFAULT;
2543 1 : n->name = NULL;
2544 1 : $$ = (Node *) n;
2545 : }
2546 : | USING INDEX name
2547 : {
2548 12 : ReplicaIdentityStmt *n = makeNode(ReplicaIdentityStmt);
2549 12 : n->identity_type = REPLICA_IDENTITY_INDEX;
2550 12 : n->name = $3;
2551 12 : $$ = (Node *) n;
2552 : }
2553 : ;
2554 :
2555 : reloptions:
2556 66 : '(' reloption_list ')' { $$ = $2; }
2557 : ;
2558 :
2559 31 : opt_reloptions: WITH reloptions { $$ = $2; }
2560 703 : | /* EMPTY */ { $$ = NIL; }
2561 : ;
2562 :
2563 : reloption_list:
2564 66 : reloption_elem { $$ = list_make1($1); }
2565 5 : | reloption_list ',' reloption_elem { $$ = lappend($1, $3); }
2566 : ;
2567 :
2568 : /* This should match def_elem and also allow qualified names */
2569 : reloption_elem:
2570 : ColLabel '=' def_arg
2571 : {
2572 50 : $$ = makeDefElem($1, (Node *) $3, @1);
2573 : }
2574 : | ColLabel
2575 : {
2576 20 : $$ = makeDefElem($1, NULL, @1);
2577 : }
2578 : | ColLabel '.' ColLabel '=' def_arg
2579 : {
2580 1 : $$ = makeDefElemExtended($1, $3, (Node *) $5,
2581 1 : DEFELEM_UNSPEC, @1);
2582 : }
2583 : | ColLabel '.' ColLabel
2584 : {
2585 0 : $$ = makeDefElemExtended($1, $3, NULL, DEFELEM_UNSPEC, @1);
2586 : }
2587 : ;
2588 :
2589 : alter_identity_column_option_list:
2590 : alter_identity_column_option
2591 4 : { $$ = list_make1($1); }
2592 : | alter_identity_column_option_list alter_identity_column_option
2593 3 : { $$ = lappend($1, $2); }
2594 : ;
2595 :
2596 : alter_identity_column_option:
2597 : RESTART
2598 : {
2599 2 : $$ = makeDefElem("restart", NULL, @1);
2600 : }
2601 : | RESTART opt_with NumericOnly
2602 : {
2603 0 : $$ = makeDefElem("restart", (Node *)$3, @1);
2604 : }
2605 : | SET SeqOptElem
2606 : {
2607 6 : if (strcmp($2->defname, "as") == 0 ||
2608 6 : strcmp($2->defname, "restart") == 0 ||
2609 3 : strcmp($2->defname, "owned_by") == 0)
2610 0 : ereport(ERROR,
2611 : (errcode(ERRCODE_SYNTAX_ERROR),
2612 : errmsg("sequence option \"%s\" not supported here", $2->defname),
2613 : parser_errposition(@2)));
2614 3 : $$ = $2;
2615 : }
2616 : | SET GENERATED generated_when
2617 : {
2618 2 : $$ = makeDefElem("generated", (Node *) makeInteger($3), @1);
2619 : }
2620 : ;
2621 :
2622 : ForValues:
2623 : /* a LIST partition */
2624 : FOR VALUES IN_P '(' partbound_datum_list ')'
2625 : {
2626 106 : PartitionBoundSpec *n = makeNode(PartitionBoundSpec);
2627 :
2628 106 : n->strategy = PARTITION_STRATEGY_LIST;
2629 106 : n->listdatums = $5;
2630 106 : n->location = @3;
2631 :
2632 106 : $$ = n;
2633 : }
2634 :
2635 : /* a RANGE partition */
2636 : | FOR VALUES FROM '(' range_datum_list ')' TO '(' range_datum_list ')'
2637 : {
2638 90 : PartitionBoundSpec *n = makeNode(PartitionBoundSpec);
2639 :
2640 90 : n->strategy = PARTITION_STRATEGY_RANGE;
2641 90 : n->lowerdatums = $5;
2642 90 : n->upperdatums = $9;
2643 90 : n->location = @3;
2644 :
2645 90 : $$ = n;
2646 : }
2647 : ;
2648 :
2649 : partbound_datum:
2650 83 : Sconst { $$ = makeStringConst($1, @1); }
2651 301 : | NumericOnly { $$ = makeAConst($1, @1); }
2652 8 : | NULL_P { $$ = makeNullAConst(@1); }
2653 : ;
2654 :
2655 : partbound_datum_list:
2656 107 : partbound_datum { $$ = list_make1($1); }
2657 : | partbound_datum_list ',' partbound_datum
2658 13 : { $$ = lappend($1, $3); }
2659 : ;
2660 :
2661 : range_datum_list:
2662 180 : PartitionRangeDatum { $$ = list_make1($1); }
2663 : | range_datum_list ',' PartitionRangeDatum
2664 134 : { $$ = lappend($1, $3); }
2665 : ;
2666 :
2667 : PartitionRangeDatum:
2668 : MINVALUE
2669 : {
2670 24 : PartitionRangeDatum *n = makeNode(PartitionRangeDatum);
2671 :
2672 24 : n->kind = PARTITION_RANGE_DATUM_MINVALUE;
2673 24 : n->value = NULL;
2674 24 : n->location = @1;
2675 :
2676 24 : $$ = (Node *) n;
2677 : }
2678 : | MAXVALUE
2679 : {
2680 18 : PartitionRangeDatum *n = makeNode(PartitionRangeDatum);
2681 :
2682 18 : n->kind = PARTITION_RANGE_DATUM_MAXVALUE;
2683 18 : n->value = NULL;
2684 18 : n->location = @1;
2685 :
2686 18 : $$ = (Node *) n;
2687 : }
2688 : | partbound_datum
2689 : {
2690 272 : PartitionRangeDatum *n = makeNode(PartitionRangeDatum);
2691 :
2692 272 : n->kind = PARTITION_RANGE_DATUM_VALUE;
2693 272 : n->value = $1;
2694 272 : n->location = @1;
2695 :
2696 272 : $$ = (Node *) n;
2697 : }
2698 : ;
2699 :
2700 : /*****************************************************************************
2701 : *
2702 : * ALTER TYPE
2703 : *
2704 : * really variants of the ALTER TABLE subcommands with different spellings
2705 : *****************************************************************************/
2706 :
2707 : AlterCompositeTypeStmt:
2708 : ALTER TYPE_P any_name alter_type_cmds
2709 : {
2710 24 : AlterTableStmt *n = makeNode(AlterTableStmt);
2711 :
2712 : /* can't use qualified_name, sigh */
2713 24 : n->relation = makeRangeVarFromAnyName($3, @3, yyscanner);
2714 24 : n->cmds = $4;
2715 24 : n->relkind = OBJECT_TYPE;
2716 24 : $$ = (Node *)n;
2717 : }
2718 : ;
2719 :
2720 : alter_type_cmds:
2721 24 : alter_type_cmd { $$ = list_make1($1); }
2722 2 : | alter_type_cmds ',' alter_type_cmd { $$ = lappend($1, $3); }
2723 : ;
2724 :
2725 : alter_type_cmd:
2726 : /* ALTER TYPE <name> ADD ATTRIBUTE <coldef> [RESTRICT|CASCADE] */
2727 : ADD_P ATTRIBUTE TableFuncElement opt_drop_behavior
2728 : {
2729 9 : AlterTableCmd *n = makeNode(AlterTableCmd);
2730 9 : n->subtype = AT_AddColumn;
2731 9 : n->def = $3;
2732 9 : n->behavior = $4;
2733 9 : $$ = (Node *)n;
2734 : }
2735 : /* ALTER TYPE <name> DROP ATTRIBUTE IF EXISTS <attname> [RESTRICT|CASCADE] */
2736 : | DROP ATTRIBUTE IF_P EXISTS ColId opt_drop_behavior
2737 : {
2738 1 : AlterTableCmd *n = makeNode(AlterTableCmd);
2739 1 : n->subtype = AT_DropColumn;
2740 1 : n->name = $5;
2741 1 : n->behavior = $6;
2742 1 : n->missing_ok = TRUE;
2743 1 : $$ = (Node *)n;
2744 : }
2745 : /* ALTER TYPE <name> DROP ATTRIBUTE <attname> [RESTRICT|CASCADE] */
2746 : | DROP ATTRIBUTE ColId opt_drop_behavior
2747 : {
2748 7 : AlterTableCmd *n = makeNode(AlterTableCmd);
2749 7 : n->subtype = AT_DropColumn;
2750 7 : n->name = $3;
2751 7 : n->behavior = $4;
2752 7 : n->missing_ok = FALSE;
2753 7 : $$ = (Node *)n;
2754 : }
2755 : /* ALTER TYPE <name> ALTER ATTRIBUTE <attname> [SET DATA] TYPE <typename> [RESTRICT|CASCADE] */
2756 : | ALTER ATTRIBUTE ColId opt_set_data TYPE_P Typename opt_collate_clause opt_drop_behavior
2757 : {
2758 9 : AlterTableCmd *n = makeNode(AlterTableCmd);
2759 9 : ColumnDef *def = makeNode(ColumnDef);
2760 9 : n->subtype = AT_AlterColumnType;
2761 9 : n->name = $3;
2762 9 : n->def = (Node *) def;
2763 9 : n->behavior = $8;
2764 : /* We only use these fields of the ColumnDef node */
2765 9 : def->typeName = $6;
2766 9 : def->collClause = (CollateClause *) $7;
2767 9 : def->raw_default = NULL;
2768 9 : def->location = @3;
2769 9 : $$ = (Node *)n;
2770 : }
2771 : ;
2772 :
2773 :
2774 : /*****************************************************************************
2775 : *
2776 : * QUERY :
2777 : * close <portalname>
2778 : *
2779 : *****************************************************************************/
2780 :
2781 : ClosePortalStmt:
2782 : CLOSE cursor_name
2783 : {
2784 40 : ClosePortalStmt *n = makeNode(ClosePortalStmt);
2785 40 : n->portalname = $2;
2786 40 : $$ = (Node *)n;
2787 : }
2788 : | CLOSE ALL
2789 : {
2790 2 : ClosePortalStmt *n = makeNode(ClosePortalStmt);
2791 2 : n->portalname = NULL;
2792 2 : $$ = (Node *)n;
2793 : }
2794 : ;
2795 :
2796 :
2797 : /*****************************************************************************
2798 : *
2799 : * QUERY :
2800 : * COPY relname [(columnList)] FROM/TO file [WITH] [(options)]
2801 : * COPY ( query ) TO file [WITH] [(options)]
2802 : *
2803 : * where 'query' can be one of:
2804 : * { SELECT | UPDATE | INSERT | DELETE }
2805 : *
2806 : * and 'file' can be one of:
2807 : * { PROGRAM 'command' | STDIN | STDOUT | 'filename' }
2808 : *
2809 : * In the preferred syntax the options are comma-separated
2810 : * and use generic identifiers instead of keywords. The pre-9.0
2811 : * syntax had a hard-wired, space-separated set of options.
2812 : *
2813 : * Really old syntax, from versions 7.2 and prior:
2814 : * COPY [ BINARY ] table [ WITH OIDS ] FROM/TO file
2815 : * [ [ USING ] DELIMITERS 'delimiter' ] ]
2816 : * [ WITH NULL AS 'null string' ]
2817 : * This option placement is not supported with COPY (query...).
2818 : *
2819 : *****************************************************************************/
2820 :
2821 : CopyStmt: COPY opt_binary qualified_name opt_column_list opt_oids
2822 : copy_from opt_program copy_file_name copy_delimiter opt_with copy_options
2823 : {
2824 182 : CopyStmt *n = makeNode(CopyStmt);
2825 182 : n->relation = $3;
2826 182 : n->query = NULL;
2827 182 : n->attlist = $4;
2828 182 : n->is_from = $6;
2829 182 : n->is_program = $7;
2830 182 : n->filename = $8;
2831 :
2832 182 : if (n->is_program && n->filename == NULL)
2833 0 : ereport(ERROR,
2834 : (errcode(ERRCODE_SYNTAX_ERROR),
2835 : errmsg("STDIN/STDOUT not allowed with PROGRAM"),
2836 : parser_errposition(@8)));
2837 :
2838 182 : n->options = NIL;
2839 : /* Concatenate user-supplied flags */
2840 182 : if ($2)
2841 2 : n->options = lappend(n->options, $2);
2842 182 : if ($5)
2843 0 : n->options = lappend(n->options, $5);
2844 182 : if ($9)
2845 0 : n->options = lappend(n->options, $9);
2846 182 : if ($11)
2847 57 : n->options = list_concat(n->options, $11);
2848 182 : $$ = (Node *)n;
2849 : }
2850 : | COPY '(' PreparableStmt ')' TO opt_program copy_file_name opt_with copy_options
2851 : {
2852 45 : CopyStmt *n = makeNode(CopyStmt);
2853 45 : n->relation = NULL;
2854 45 : n->query = $3;
2855 45 : n->attlist = NIL;
2856 45 : n->is_from = false;
2857 45 : n->is_program = $6;
2858 45 : n->filename = $7;
2859 45 : n->options = $9;
2860 :
2861 45 : if (n->is_program && n->filename == NULL)
2862 0 : ereport(ERROR,
2863 : (errcode(ERRCODE_SYNTAX_ERROR),
2864 : errmsg("STDIN/STDOUT not allowed with PROGRAM"),
2865 : parser_errposition(@5)));
2866 :
2867 45 : $$ = (Node *)n;
2868 : }
2869 : ;
2870 :
2871 : copy_from:
2872 124 : FROM { $$ = TRUE; }
2873 58 : | TO { $$ = FALSE; }
2874 : ;
2875 :
2876 : opt_program:
2877 0 : PROGRAM { $$ = TRUE; }
2878 227 : | /* EMPTY */ { $$ = FALSE; }
2879 : ;
2880 :
2881 : /*
2882 : * copy_file_name NULL indicates stdio is used. Whether stdin or stdout is
2883 : * used depends on the direction. (It really doesn't make sense to copy from
2884 : * stdout. We silently correct the "typo".) - AY 9/94
2885 : */
2886 : copy_file_name:
2887 39 : Sconst { $$ = $1; }
2888 91 : | STDIN { $$ = NULL; }
2889 97 : | STDOUT { $$ = NULL; }
2890 : ;
2891 :
2892 211 : copy_options: copy_opt_list { $$ = $1; }
2893 16 : | '(' copy_generic_opt_list ')' { $$ = $2; }
2894 : ;
2895 :
2896 : /* old COPY option syntax */
2897 : copy_opt_list:
2898 76 : copy_opt_list copy_opt_item { $$ = lappend($1, $2); }
2899 211 : | /* EMPTY */ { $$ = NIL; }
2900 : ;
2901 :
2902 : copy_opt_item:
2903 : BINARY
2904 : {
2905 0 : $$ = makeDefElem("format", (Node *)makeString("binary"), @1);
2906 : }
2907 : | OIDS
2908 : {
2909 3 : $$ = makeDefElem("oids", (Node *)makeInteger(TRUE), @1);
2910 : }
2911 : | FREEZE
2912 : {
2913 7 : $$ = makeDefElem("freeze", (Node *)makeInteger(TRUE), @1);
2914 : }
2915 : | DELIMITER opt_as Sconst
2916 : {
2917 20 : $$ = makeDefElem("delimiter", (Node *)makeString($3), @1);
2918 : }
2919 : | NULL_P opt_as Sconst
2920 : {
2921 8 : $$ = makeDefElem("null", (Node *)makeString($3), @1);
2922 : }
2923 : | CSV
2924 : {
2925 24 : $$ = makeDefElem("format", (Node *)makeString("csv"), @1);
2926 : }
2927 : | HEADER_P
2928 : {
2929 3 : $$ = makeDefElem("header", (Node *)makeInteger(TRUE), @1);
2930 : }
2931 : | QUOTE opt_as Sconst
2932 : {
2933 3 : $$ = makeDefElem("quote", (Node *)makeString($3), @1);
2934 : }
2935 : | ESCAPE opt_as Sconst
2936 : {
2937 3 : $$ = makeDefElem("escape", (Node *)makeString($3), @1);
2938 : }
2939 : | FORCE QUOTE columnList
2940 : {
2941 2 : $$ = makeDefElem("force_quote", (Node *)$3, @1);
2942 : }
2943 : | FORCE QUOTE '*'
2944 : {
2945 1 : $$ = makeDefElem("force_quote", (Node *)makeNode(A_Star), @1);
2946 : }
2947 : | FORCE NOT NULL_P columnList
2948 : {
2949 0 : $$ = makeDefElem("force_not_null", (Node *)$4, @1);
2950 : }
2951 : | FORCE NULL_P columnList
2952 : {
2953 0 : $$ = makeDefElem("force_null", (Node *)$3, @1);
2954 : }
2955 : | ENCODING Sconst
2956 : {
2957 2 : $$ = makeDefElem("encoding", (Node *)makeString($2), @1);
2958 : }
2959 : ;
2960 :
2961 : /* The following exist for backward compatibility with very old versions */
2962 :
2963 : opt_binary:
2964 : BINARY
2965 : {
2966 2 : $$ = makeDefElem("format", (Node *)makeString("binary"), @1);
2967 : }
2968 180 : | /*EMPTY*/ { $$ = NULL; }
2969 : ;
2970 :
2971 : opt_oids:
2972 : WITH OIDS
2973 : {
2974 0 : $$ = makeDefElem("oids", (Node *)makeInteger(TRUE), @1);
2975 : }
2976 182 : | /*EMPTY*/ { $$ = NULL; }
2977 : ;
2978 :
2979 : copy_delimiter:
2980 : opt_using DELIMITERS Sconst
2981 : {
2982 0 : $$ = makeDefElem("delimiter", (Node *)makeString($3), @2);
2983 : }
2984 182 : | /*EMPTY*/ { $$ = NULL; }
2985 : ;
2986 :
2987 : opt_using:
2988 : USING {}
2989 : | /*EMPTY*/ {}
2990 : ;
2991 :
2992 : /* new COPY option syntax */
2993 : copy_generic_opt_list:
2994 : copy_generic_opt_elem
2995 : {
2996 16 : $$ = list_make1($1);
2997 : }
2998 : | copy_generic_opt_list ',' copy_generic_opt_elem
2999 : {
3000 18 : $$ = lappend($1, $3);
3001 : }
3002 : ;
3003 :
3004 : copy_generic_opt_elem:
3005 : ColLabel copy_generic_opt_arg
3006 : {
3007 34 : $$ = makeDefElem($1, $2, @1);
3008 : }
3009 : ;
3010 :
3011 : copy_generic_opt_arg:
3012 19 : opt_boolean_or_string { $$ = (Node *) makeString($1); }
3013 0 : | NumericOnly { $$ = (Node *) $1; }
3014 2 : | '*' { $$ = (Node *) makeNode(A_Star); }
3015 10 : | '(' copy_generic_opt_arg_list ')' { $$ = (Node *) $2; }
3016 3 : | /* EMPTY */ { $$ = NULL; }
3017 : ;
3018 :
3019 : copy_generic_opt_arg_list:
3020 : copy_generic_opt_arg_list_item
3021 : {
3022 10 : $$ = list_make1($1);
3023 : }
3024 : | copy_generic_opt_arg_list ',' copy_generic_opt_arg_list_item
3025 : {
3026 2 : $$ = lappend($1, $3);
3027 : }
3028 : ;
3029 :
3030 : /* beware of emitting non-string list elements here; see commands/define.c */
3031 : copy_generic_opt_arg_list_item:
3032 12 : opt_boolean_or_string { $$ = (Node *) makeString($1); }
3033 : ;
3034 :
3035 :
3036 : /*****************************************************************************
3037 : *
3038 : * QUERY :
3039 : * CREATE TABLE relname
3040 : *
3041 : *****************************************************************************/
3042 :
3043 : CreateStmt: CREATE OptTemp TABLE qualified_name '(' OptTableElementList ')'
3044 : OptInherit OptPartitionSpec OptWith OnCommitOption OptTableSpace
3045 : {
3046 1324 : CreateStmt *n = makeNode(CreateStmt);
3047 1324 : $4->relpersistence = $2;
3048 1324 : n->relation = $4;
3049 1324 : n->tableElts = $6;
3050 1324 : n->inhRelations = $8;
3051 1324 : n->partspec = $9;
3052 1324 : n->ofTypename = NULL;
3053 1324 : n->constraints = NIL;
3054 1324 : n->options = $10;
3055 1324 : n->oncommit = $11;
3056 1324 : n->tablespacename = $12;
3057 1324 : n->if_not_exists = false;
3058 1324 : $$ = (Node *)n;
3059 : }
3060 : | CREATE OptTemp TABLE IF_P NOT EXISTS qualified_name '('
3061 : OptTableElementList ')' OptInherit OptPartitionSpec OptWith
3062 : OnCommitOption OptTableSpace
3063 : {
3064 3 : CreateStmt *n = makeNode(CreateStmt);
3065 3 : $7->relpersistence = $2;
3066 3 : n->relation = $7;
3067 3 : n->tableElts = $9;
3068 3 : n->inhRelations = $11;
3069 3 : n->partspec = $12;
3070 3 : n->ofTypename = NULL;
3071 3 : n->constraints = NIL;
3072 3 : n->options = $13;
3073 3 : n->oncommit = $14;
3074 3 : n->tablespacename = $15;
3075 3 : n->if_not_exists = true;
3076 3 : $$ = (Node *)n;
3077 : }
3078 : | CREATE OptTemp TABLE qualified_name OF any_name
3079 : OptTypedTableElementList OptPartitionSpec OptWith OnCommitOption
3080 : OptTableSpace
3081 : {
3082 16 : CreateStmt *n = makeNode(CreateStmt);
3083 16 : $4->relpersistence = $2;
3084 16 : n->relation = $4;
3085 16 : n->tableElts = $7;
3086 16 : n->inhRelations = NIL;
3087 16 : n->partspec = $8;
3088 16 : n->ofTypename = makeTypeNameFromNameList($6);
3089 16 : n->ofTypename->location = @6;
3090 16 : n->constraints = NIL;
3091 16 : n->options = $9;
3092 16 : n->oncommit = $10;
3093 16 : n->tablespacename = $11;
3094 16 : n->if_not_exists = false;
3095 16 : $$ = (Node *)n;
3096 : }
3097 : | CREATE OptTemp TABLE IF_P NOT EXISTS qualified_name OF any_name
3098 : OptTypedTableElementList OptPartitionSpec OptWith OnCommitOption
3099 : OptTableSpace
3100 : {
3101 1 : CreateStmt *n = makeNode(CreateStmt);
3102 1 : $7->relpersistence = $2;
3103 1 : n->relation = $7;
3104 1 : n->tableElts = $10;
3105 1 : n->inhRelations = NIL;
3106 1 : n->partspec = $11;
3107 1 : n->ofTypename = makeTypeNameFromNameList($9);
3108 1 : n->ofTypename->location = @9;
3109 1 : n->constraints = NIL;
3110 1 : n->options = $12;
3111 1 : n->oncommit = $13;
3112 1 : n->tablespacename = $14;
3113 1 : n->if_not_exists = true;
3114 1 : $$ = (Node *)n;
3115 : }
3116 : | CREATE OptTemp TABLE qualified_name PARTITION OF qualified_name
3117 : OptTypedTableElementList ForValues OptPartitionSpec OptWith
3118 : OnCommitOption OptTableSpace
3119 : {
3120 138 : CreateStmt *n = makeNode(CreateStmt);
3121 138 : $4->relpersistence = $2;
3122 138 : n->relation = $4;
3123 138 : n->tableElts = $8;
3124 138 : n->inhRelations = list_make1($7);
3125 138 : n->partbound = $9;
3126 138 : n->partspec = $10;
3127 138 : n->ofTypename = NULL;
3128 138 : n->constraints = NIL;
3129 138 : n->options = $11;
3130 138 : n->oncommit = $12;
3131 138 : n->tablespacename = $13;
3132 138 : n->if_not_exists = false;
3133 138 : $$ = (Node *)n;
3134 : }
3135 : | CREATE OptTemp TABLE IF_P NOT EXISTS qualified_name PARTITION OF
3136 : qualified_name OptTypedTableElementList ForValues OptPartitionSpec
3137 : OptWith OnCommitOption OptTableSpace
3138 : {
3139 0 : CreateStmt *n = makeNode(CreateStmt);
3140 0 : $7->relpersistence = $2;
3141 0 : n->relation = $7;
3142 0 : n->tableElts = $11;
3143 0 : n->inhRelations = list_make1($10);
3144 0 : n->partbound = $12;
3145 0 : n->partspec = $13;
3146 0 : n->ofTypename = NULL;
3147 0 : n->constraints = NIL;
3148 0 : n->options = $14;
3149 0 : n->oncommit = $15;
3150 0 : n->tablespacename = $16;
3151 0 : n->if_not_exists = true;
3152 0 : $$ = (Node *)n;
3153 : }
3154 : ;
3155 :
3156 : /*
3157 : * Redundancy here is needed to avoid shift/reduce conflicts,
3158 : * since TEMP is not a reserved word. See also OptTempTableName.
3159 : *
3160 : * NOTE: we accept both GLOBAL and LOCAL options. They currently do nothing,
3161 : * but future versions might consider GLOBAL to request SQL-spec-compliant
3162 : * temp table behavior, so warn about that. Since we have no modules the
3163 : * LOCAL keyword is really meaningless; furthermore, some other products
3164 : * implement LOCAL as meaning the same as our default temp table behavior,
3165 : * so we'll probably continue to treat LOCAL as a noise word.
3166 : */
3167 29 : OptTemp: TEMPORARY { $$ = RELPERSISTENCE_TEMP; }
3168 269 : | TEMP { $$ = RELPERSISTENCE_TEMP; }
3169 0 : | LOCAL TEMPORARY { $$ = RELPERSISTENCE_TEMP; }
3170 0 : | LOCAL TEMP { $$ = RELPERSISTENCE_TEMP; }
3171 : | GLOBAL TEMPORARY
3172 : {
3173 0 : ereport(WARNING,
3174 : (errmsg("GLOBAL is deprecated in temporary table creation"),
3175 : parser_errposition(@1)));
3176 0 : $$ = RELPERSISTENCE_TEMP;
3177 : }
3178 : | GLOBAL TEMP
3179 : {
3180 0 : ereport(WARNING,
3181 : (errmsg("GLOBAL is deprecated in temporary table creation"),
3182 : parser_errposition(@1)));
3183 0 : $$ = RELPERSISTENCE_TEMP;
3184 : }
3185 8 : | UNLOGGED { $$ = RELPERSISTENCE_UNLOGGED; }
3186 1754 : | /*EMPTY*/ { $$ = RELPERSISTENCE_PERMANENT; }
3187 : ;
3188 :
3189 : OptTableElementList:
3190 1280 : TableElementList { $$ = $1; }
3191 65 : | /*EMPTY*/ { $$ = NIL; }
3192 : ;
3193 :
3194 : OptTypedTableElementList:
3195 9 : '(' TypedTableElementList ')' { $$ = $2; }
3196 150 : | /*EMPTY*/ { $$ = NIL; }
3197 : ;
3198 :
3199 : TableElementList:
3200 : TableElement
3201 : {
3202 1286 : $$ = list_make1($1);
3203 : }
3204 : | TableElementList ',' TableElement
3205 : {
3206 1317 : $$ = lappend($1, $3);
3207 : }
3208 : ;
3209 :
3210 : TypedTableElementList:
3211 : TypedTableElement
3212 : {
3213 9 : $$ = list_make1($1);
3214 : }
3215 : | TypedTableElementList ',' TypedTableElement
3216 : {
3217 9 : $$ = lappend($1, $3);
3218 : }
3219 : ;
3220 :
3221 : TableElement:
3222 2420 : columnDef { $$ = $1; }
3223 50 : | TableLikeClause { $$ = $1; }
3224 133 : | TableConstraint { $$ = $1; }
3225 : ;
3226 :
3227 : TypedTableElement:
3228 12 : columnOptions { $$ = $1; }
3229 6 : | TableConstraint { $$ = $1; }
3230 : ;
3231 :
3232 : columnDef: ColId Typename create_generic_options ColQualList
3233 : {
3234 2567 : ColumnDef *n = makeNode(ColumnDef);
3235 2567 : n->colname = $1;
3236 2567 : n->typeName = $2;
3237 2567 : n->inhcount = 0;
3238 2567 : n->is_local = true;
3239 2567 : n->is_not_null = false;
3240 2567 : n->is_from_type = false;
3241 2567 : n->is_from_parent = false;
3242 2567 : n->storage = 0;
3243 2567 : n->raw_default = NULL;
3244 2567 : n->cooked_default = NULL;
3245 2567 : n->collOid = InvalidOid;
3246 2567 : n->fdwoptions = $3;
3247 2567 : SplitColQualList($4, &n->constraints, &n->collClause,
3248 : yyscanner);
3249 2567 : n->location = @1;
3250 2567 : $$ = (Node *)n;
3251 : }
3252 : ;
3253 :
3254 : columnOptions: ColId ColQualList
3255 : {
3256 5 : ColumnDef *n = makeNode(ColumnDef);
3257 5 : n->colname = $1;
3258 5 : n->typeName = NULL;
3259 5 : n->inhcount = 0;
3260 5 : n->is_local = true;
3261 5 : n->is_not_null = false;
3262 5 : n->is_from_type = false;
3263 5 : n->is_from_parent = false;
3264 5 : n->storage = 0;
3265 5 : n->raw_default = NULL;
3266 5 : n->cooked_default = NULL;
3267 5 : n->collOid = InvalidOid;
3268 5 : SplitColQualList($2, &n->constraints, &n->collClause,
3269 : yyscanner);
3270 5 : n->location = @1;
3271 5 : $$ = (Node *)n;
3272 : }
3273 : | ColId WITH OPTIONS ColQualList
3274 : {
3275 7 : ColumnDef *n = makeNode(ColumnDef);
3276 7 : n->colname = $1;
3277 7 : n->typeName = NULL;
3278 7 : n->inhcount = 0;
3279 7 : n->is_local = true;
3280 7 : n->is_not_null = false;
3281 7 : n->is_from_type = false;
3282 7 : n->is_from_parent = false;
3283 7 : n->storage = 0;
3284 7 : n->raw_default = NULL;
3285 7 : n->cooked_default = NULL;
3286 7 : n->collOid = InvalidOid;
3287 7 : SplitColQualList($4, &n->constraints, &n->collClause,
3288 : yyscanner);
3289 7 : n->location = @1;
3290 7 : $$ = (Node *)n;
3291 : }
3292 : ;
3293 :
3294 : ColQualList:
3295 600 : ColQualList ColConstraint { $$ = lappend($1, $2); }
3296 2665 : | /*EMPTY*/ { $$ = NIL; }
3297 : ;
3298 :
3299 : ColConstraint:
3300 : CONSTRAINT name ColConstraintElem
3301 : {
3302 18 : Constraint *n = castNode(Constraint, $3);
3303 18 : n->conname = $2;
3304 18 : n->location = @1;
3305 18 : $$ = (Node *) n;
3306 : }
3307 553 : | ColConstraintElem { $$ = $1; }
3308 12 : | ConstraintAttr { $$ = $1; }
3309 : | COLLATE any_name
3310 : {
3311 : /*
3312 : * Note: the CollateClause is momentarily included in
3313 : * the list built by ColQualList, but we split it out
3314 : * again in SplitColQualList.
3315 : */
3316 17 : CollateClause *n = makeNode(CollateClause);
3317 17 : n->arg = NULL;
3318 17 : n->collname = $2;
3319 17 : n->location = @1;
3320 17 : $$ = (Node *) n;
3321 : }
3322 : ;
3323 :
3324 : /* DEFAULT NULL is already the default for Postgres.
3325 : * But define it here and carry it forward into the system
3326 : * to make it explicit.
3327 : * - thomas 1998-09-13
3328 : *
3329 : * WITH NULL and NULL are not SQL-standard syntax elements,
3330 : * so leave them out. Use DEFAULT NULL to explicitly indicate
3331 : * that a column may have that value. WITH NULL leads to
3332 : * shift/reduce conflicts with WITH TIME ZONE anyway.
3333 : * - thomas 1999-01-08
3334 : *
3335 : * DEFAULT expression must be b_expr not a_expr to prevent shift/reduce
3336 : * conflict on NOT (since NOT might start a subsequent NOT NULL constraint,
3337 : * or be part of a_expr NOT LIKE or similar constructs).
3338 : */
3339 : ColConstraintElem:
3340 : NOT NULL_P
3341 : {
3342 131 : Constraint *n = makeNode(Constraint);
3343 131 : n->contype = CONSTR_NOTNULL;
3344 131 : n->location = @1;
3345 131 : $$ = (Node *)n;
3346 : }
3347 : | NULL_P
3348 : {
3349 1 : Constraint *n = makeNode(Constraint);
3350 1 : n->contype = CONSTR_NULL;
3351 1 : n->location = @1;
3352 1 : $$ = (Node *)n;
3353 : }
3354 : | UNIQUE opt_definition OptConsTableSpace
3355 : {
3356 37 : Constraint *n = makeNode(Constraint);
3357 37 : n->contype = CONSTR_UNIQUE;
3358 37 : n->location = @1;
3359 37 : n->keys = NULL;
3360 37 : n->options = $2;
3361 37 : n->indexname = NULL;
3362 37 : n->indexspace = $3;
3363 37 : $$ = (Node *)n;
3364 : }
3365 : | PRIMARY KEY opt_definition OptConsTableSpace
3366 : {
3367 178 : Constraint *n = makeNode(Constraint);
3368 178 : n->contype = CONSTR_PRIMARY;
3369 178 : n->location = @1;
3370 178 : n->keys = NULL;
3371 178 : n->options = $3;
3372 178 : n->indexname = NULL;
3373 178 : n->indexspace = $4;
3374 178 : $$ = (Node *)n;
3375 : }
3376 : | CHECK '(' a_expr ')' opt_no_inherit
3377 : {
3378 59 : Constraint *n = makeNode(Constraint);
3379 59 : n->contype = CONSTR_CHECK;
3380 59 : n->location = @1;
3381 59 : n->is_no_inherit = $5;
3382 59 : n->raw_expr = $3;
3383 59 : n->cooked_expr = NULL;
3384 59 : n->skip_validation = false;
3385 59 : n->initially_valid = true;
3386 59 : $$ = (Node *)n;
3387 : }
3388 : | DEFAULT b_expr
3389 : {
3390 92 : Constraint *n = makeNode(Constraint);
3391 92 : n->contype = CONSTR_DEFAULT;
3392 92 : n->location = @1;
3393 92 : n->raw_expr = $2;
3394 92 : n->cooked_expr = NULL;
3395 92 : $$ = (Node *)n;
3396 : }
3397 : | GENERATED generated_when AS IDENTITY_P OptParenthesizedSeqOptList
3398 : {
3399 17 : Constraint *n = makeNode(Constraint);
3400 17 : n->contype = CONSTR_IDENTITY;
3401 17 : n->generated_when = $2;
3402 17 : n->options = $5;
3403 17 : n->location = @1;
3404 17 : $$ = (Node *)n;
3405 : }
3406 : | REFERENCES qualified_name opt_column_list key_match key_actions
3407 : {
3408 56 : Constraint *n = makeNode(Constraint);
3409 56 : n->contype = CONSTR_FOREIGN;
3410 56 : n->location = @1;
3411 56 : n->pktable = $2;
3412 56 : n->fk_attrs = NIL;
3413 56 : n->pk_attrs = $3;
3414 56 : n->fk_matchtype = $4;
3415 56 : n->fk_upd_action = (char) ($5 >> 8);
3416 56 : n->fk_del_action = (char) ($5 & 0xFF);
3417 56 : n->skip_validation = false;
3418 56 : n->initially_valid = true;
3419 56 : $$ = (Node *)n;
3420 : }
3421 : ;
3422 :
3423 : generated_when:
3424 17 : ALWAYS { $$ = ATTRIBUTE_IDENTITY_ALWAYS; }
3425 9 : | BY DEFAULT { $$ = ATTRIBUTE_IDENTITY_BY_DEFAULT; }
3426 : ;
3427 :
3428 : /*
3429 : * ConstraintAttr represents constraint attributes, which we parse as if
3430 : * they were independent constraint clauses, in order to avoid shift/reduce
3431 : * conflicts (since NOT might start either an independent NOT NULL clause
3432 : * or an attribute). parse_utilcmd.c is responsible for attaching the
3433 : * attribute information to the preceding "real" constraint node, and for
3434 : * complaining if attribute clauses appear in the wrong place or wrong
3435 : * combinations.
3436 : *
3437 : * See also ConstraintAttributeSpec, which can be used in places where
3438 : * there is no parsing conflict. (Note: currently, NOT VALID and NO INHERIT
3439 : * are allowed clauses in ConstraintAttributeSpec, but not here. Someday we
3440 : * might need to allow them here too, but for the moment it doesn't seem
3441 : * useful in the statements that use ConstraintAttr.)
3442 : */
3443 : ConstraintAttr:
3444 : DEFERRABLE
3445 : {
3446 8 : Constraint *n = makeNode(Constraint);
3447 8 : n->contype = CONSTR_ATTR_DEFERRABLE;
3448 8 : n->location = @1;
3449 8 : $$ = (Node *)n;
3450 : }
3451 : | NOT DEFERRABLE
3452 : {
3453 0 : Constraint *n = makeNode(Constraint);
3454 0 : n->contype = CONSTR_ATTR_NOT_DEFERRABLE;
3455 0 : n->location = @1;
3456 0 : $$ = (Node *)n;
3457 : }
3458 : | INITIALLY DEFERRED
3459 : {
3460 4 : Constraint *n = makeNode(Constraint);
3461 4 : n->contype = CONSTR_ATTR_DEFERRED;
3462 4 : n->location = @1;
3463 4 : $$ = (Node *)n;
3464 : }
3465 : | INITIALLY IMMEDIATE
3466 : {
3467 0 : Constraint *n = makeNode(Constraint);
3468 0 : n->contype = CONSTR_ATTR_IMMEDIATE;
3469 0 : n->location = @1;
3470 0 : $$ = (Node *)n;
3471 : }
3472 : ;
3473 :
3474 :
3475 : TableLikeClause:
3476 : LIKE qualified_name TableLikeOptionList
3477 : {
3478 50 : TableLikeClause *n = makeNode(TableLikeClause);
3479 50 : n->relation = $2;
3480 50 : n->options = $3;
3481 50 : $$ = (Node *)n;
3482 : }
3483 : ;
3484 :
3485 : TableLikeOptionList:
3486 20 : TableLikeOptionList INCLUDING TableLikeOption { $$ = $1 | $3; }
3487 0 : | TableLikeOptionList EXCLUDING TableLikeOption { $$ = $1 & ~$3; }
3488 50 : | /* EMPTY */ { $$ = 0; }
3489 : ;
3490 :
3491 : TableLikeOption:
3492 1 : DEFAULTS { $$ = CREATE_TABLE_LIKE_DEFAULTS; }
3493 5 : | CONSTRAINTS { $$ = CREATE_TABLE_LIKE_CONSTRAINTS; }
3494 1 : | IDENTITY_P { $$ = CREATE_TABLE_LIKE_IDENTITY; }
3495 3 : | INDEXES { $$ = CREATE_TABLE_LIKE_INDEXES; }
3496 4 : | STORAGE { $$ = CREATE_TABLE_LIKE_STORAGE; }
3497 4 : | COMMENTS { $$ = CREATE_TABLE_LIKE_COMMENTS; }
3498 2 : | ALL { $$ = CREATE_TABLE_LIKE_ALL; }
3499 : ;
3500 :
3501 :
3502 : /* ConstraintElem specifies constraint syntax which is not embedded into
3503 : * a column definition. ColConstraintElem specifies the embedded form.
3504 : * - thomas 1997-12-03
3505 : */
3506 : TableConstraint:
3507 : CONSTRAINT name ConstraintElem
3508 : {
3509 173 : Constraint *n = castNode(Constraint, $3);
3510 173 : n->conname = $2;
3511 173 : n->location = @1;
3512 173 : $$ = (Node *) n;
3513 : }
3514 155 : | ConstraintElem { $$ = $1; }
3515 : ;
3516 :
3517 : ConstraintElem:
3518 : CHECK '(' a_expr ')' ConstraintAttributeSpec
3519 : {
3520 121 : Constraint *n = makeNode(Constraint);
3521 121 : n->contype = CONSTR_CHECK;
3522 121 : n->location = @1;
3523 121 : n->raw_expr = $3;
3524 121 : n->cooked_expr = NULL;
3525 121 : processCASbits($5, @5, "CHECK",
3526 : NULL, NULL, &n->skip_validation,
3527 : &n->is_no_inherit, yyscanner);
3528 121 : n->initially_valid = !n->skip_validation;
3529 121 : $$ = (Node *)n;
3530 : }
3531 : | UNIQUE '(' columnList ')' opt_definition OptConsTableSpace
3532 : ConstraintAttributeSpec
3533 : {
3534 30 : Constraint *n = makeNode(Constraint);
3535 30 : n->contype = CONSTR_UNIQUE;
3536 30 : n->location = @1;
3537 30 : n->keys = $3;
3538 30 : n->options = $5;
3539 30 : n->indexname = NULL;
3540 30 : n->indexspace = $6;
3541 30 : processCASbits($7, @7, "UNIQUE",
3542 : &n->deferrable, &n->initdeferred, NULL,
3543 : NULL, yyscanner);
3544 30 : $$ = (Node *)n;
3545 : }
3546 : | UNIQUE ExistingIndex ConstraintAttributeSpec
3547 : {
3548 0 : Constraint *n = makeNode(Constraint);
3549 0 : n->contype = CONSTR_UNIQUE;
3550 0 : n->location = @1;
3551 0 : n->keys = NIL;
3552 0 : n->options = NIL;
3553 0 : n->indexname = $2;
3554 0 : n->indexspace = NULL;
3555 0 : processCASbits($3, @3, "UNIQUE",
3556 : &n->deferrable, &n->initdeferred, NULL,
3557 : NULL, yyscanner);
3558 0 : $$ = (Node *)n;
3559 : }
3560 : | PRIMARY KEY '(' columnList ')' opt_definition OptConsTableSpace
3561 : ConstraintAttributeSpec
3562 : {
3563 80 : Constraint *n = makeNode(Constraint);
3564 80 : n->contype = CONSTR_PRIMARY;
3565 80 : n->location = @1;
3566 80 : n->keys = $4;
3567 80 : n->options = $6;
3568 80 : n->indexname = NULL;
3569 80 : n->indexspace = $7;
3570 80 : processCASbits($8, @8, "PRIMARY KEY",
3571 : &n->deferrable, &n->initdeferred, NULL,
3572 : NULL, yyscanner);
3573 80 : $$ = (Node *)n;
3574 : }
3575 : | PRIMARY KEY ExistingIndex ConstraintAttributeSpec
3576 : {
3577 2 : Constraint *n = makeNode(Constraint);
3578 2 : n->contype = CONSTR_PRIMARY;
3579 2 : n->location = @1;
3580 2 : n->keys = NIL;
3581 2 : n->options = NIL;
3582 2 : n->indexname = $3;
3583 2 : n->indexspace = NULL;
3584 2 : processCASbits($4, @4, "PRIMARY KEY",
3585 : &n->deferrable, &n->initdeferred, NULL,
3586 : NULL, yyscanner);
3587 2 : $$ = (Node *)n;
3588 : }
3589 : | EXCLUDE access_method_clause '(' ExclusionConstraintList ')'
3590 : opt_definition OptConsTableSpace ExclusionWhereClause
3591 : ConstraintAttributeSpec
3592 : {
3593 10 : Constraint *n = makeNode(Constraint);
3594 10 : n->contype = CONSTR_EXCLUSION;
3595 10 : n->location = @1;
3596 10 : n->access_method = $2;
3597 10 : n->exclusions = $4;
3598 10 : n->options = $6;
3599 10 : n->indexname = NULL;
3600 10 : n->indexspace = $7;
3601 10 : n->where_clause = $8;
3602 10 : processCASbits($9, @9, "EXCLUDE",
3603 : &n->deferrable, &n->initdeferred, NULL,
3604 : NULL, yyscanner);
3605 10 : $$ = (Node *)n;
3606 : }
3607 : | FOREIGN KEY '(' columnList ')' REFERENCES qualified_name
3608 : opt_column_list key_match key_actions ConstraintAttributeSpec
3609 : {
3610 85 : Constraint *n = makeNode(Constraint);
3611 85 : n->contype = CONSTR_FOREIGN;
3612 85 : n->location = @1;
3613 85 : n->pktable = $7;
3614 85 : n->fk_attrs = $4;
3615 85 : n->pk_attrs = $8;
3616 85 : n->fk_matchtype = $9;
3617 85 : n->fk_upd_action = (char) ($10 >> 8);
3618 85 : n->fk_del_action = (char) ($10 & 0xFF);
3619 85 : processCASbits($11, @11, "FOREIGN KEY",
3620 : &n->deferrable, &n->initdeferred,
3621 : &n->skip_validation, NULL,
3622 : yyscanner);
3623 85 : n->initially_valid = !n->skip_validation;
3624 85 : $$ = (Node *)n;
3625 : }
3626 : ;
3627 :
3628 1 : opt_no_inherit: NO INHERIT { $$ = TRUE; }
3629 58 : | /* EMPTY */ { $$ = FALSE; }
3630 : ;
3631 :
3632 : opt_column_list:
3633 171 : '(' columnList ')' { $$ = $2; }
3634 990 : | /*EMPTY*/ { $$ = NIL; }
3635 : ;
3636 :
3637 : columnList:
3638 384 : columnElem { $$ = list_make1($1); }
3639 252 : | columnList ',' columnElem { $$ = lappend($1, $3); }
3640 : ;
3641 :
3642 : columnElem: ColId
3643 : {
3644 636 : $$ = (Node *) makeString($1);
3645 : }
3646 : ;
3647 :
3648 : key_match: MATCH FULL
3649 : {
3650 12 : $$ = FKCONSTR_MATCH_FULL;
3651 : }
3652 : | MATCH PARTIAL
3653 : {
3654 0 : ereport(ERROR,
3655 : (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
3656 : errmsg("MATCH PARTIAL not yet implemented"),
3657 : parser_errposition(@1)));
3658 : $$ = FKCONSTR_MATCH_PARTIAL;
3659 : }
3660 : | MATCH SIMPLE
3661 : {
3662 0 : $$ = FKCONSTR_MATCH_SIMPLE;
3663 : }
3664 : | /*EMPTY*/
3665 : {
3666 129 : $$ = FKCONSTR_MATCH_SIMPLE;
3667 : }
3668 : ;
3669 :
3670 : ExclusionConstraintList:
3671 10 : ExclusionConstraintElem { $$ = list_make1($1); }
3672 : | ExclusionConstraintList ',' ExclusionConstraintElem
3673 4 : { $$ = lappend($1, $3); }
3674 : ;
3675 :
3676 : ExclusionConstraintElem: index_elem WITH any_operator
3677 : {
3678 14 : $$ = list_make2($1, $3);
3679 : }
3680 : /* allow OPERATOR() decoration for the benefit of ruleutils.c */
3681 : | index_elem WITH OPERATOR '(' any_operator ')'
3682 : {
3683 0 : $$ = list_make2($1, $5);
3684 : }
3685 : ;
3686 :
3687 : ExclusionWhereClause:
3688 1 : WHERE '(' a_expr ')' { $$ = $3; }
3689 9 : | /*EMPTY*/ { $$ = NULL; }
3690 : ;
3691 :
3692 : /*
3693 : * We combine the update and delete actions into one value temporarily
3694 : * for simplicity of parsing, and then break them down again in the
3695 : * calling production. update is in the left 8 bits, delete in the right.
3696 : * Note that NOACTION is the default.
3697 : */
3698 : key_actions:
3699 : key_update
3700 3 : { $$ = ($1 << 8) | (FKCONSTR_ACTION_NOACTION & 0xFF); }
3701 : | key_delete
3702 3 : { $$ = (FKCONSTR_ACTION_NOACTION << 8) | ($1 & 0xFF); }
3703 : | key_update key_delete
3704 6 : { $$ = ($1 << 8) | ($2 & 0xFF); }
3705 : | key_delete key_update
3706 12 : { $$ = ($2 << 8) | ($1 & 0xFF); }
3707 : | /*EMPTY*/
3708 117 : { $$ = (FKCONSTR_ACTION_NOACTION << 8) | (FKCONSTR_ACTION_NOACTION & 0xFF); }
3709 : ;
3710 :
3711 21 : key_update: ON UPDATE key_action { $$ = $3; }
3712 : ;
3713 :
3714 21 : key_delete: ON DELETE_P key_action { $$ = $3; }
3715 : ;
3716 :
3717 : key_action:
3718 7 : NO ACTION { $$ = FKCONSTR_ACTION_NOACTION; }
3719 1 : | RESTRICT { $$ = FKCONSTR_ACTION_RESTRICT; }
3720 18 : | CASCADE { $$ = FKCONSTR_ACTION_CASCADE; }
3721 11 : | SET NULL_P { $$ = FKCONSTR_ACTION_SETNULL; }
3722 5 : | SET DEFAULT { $$ = FKCONSTR_ACTION_SETDEFAULT; }
3723 : ;
3724 :
3725 146 : OptInherit: INHERITS '(' qualified_name_list ')' { $$ = $3; }
3726 1196 : | /*EMPTY*/ { $$ = NIL; }
3727 : ;
3728 :
3729 : /* Optional partition key specification */
3730 98 : OptPartitionSpec: PartitionSpec { $$ = $1; }
3731 1384 : | /*EMPTY*/ { $$ = NULL; }
3732 : ;
3733 :
3734 : PartitionSpec: PARTITION BY part_strategy '(' part_params ')'
3735 : {
3736 98 : PartitionSpec *n = makeNode(PartitionSpec);
3737 :
3738 98 : n->strategy = $3;
3739 98 : n->partParams = $5;
3740 98 : n->location = @1;
3741 :
3742 98 : $$ = n;
3743 : }
3744 : ;
3745 :
3746 48 : part_strategy: IDENT { $$ = $1; }
3747 50 : | unreserved_keyword { $$ = pstrdup($1); }
3748 : ;
3749 :
3750 98 : part_params: part_elem { $$ = list_make1($1); }
3751 21 : | part_params ',' part_elem { $$ = lappend($1, $3); }
3752 : ;
3753 :
3754 : part_elem: ColId opt_collate opt_class
3755 : {
3756 98 : PartitionElem *n = makeNode(PartitionElem);
3757 :
3758 98 : n->name = $1;
3759 98 : n->expr = NULL;
3760 98 : n->collation = $2;
3761 98 : n->opclass = $3;
3762 98 : n->location = @1;
3763 98 : $$ = n;
3764 : }
3765 : | func_expr_windowless opt_collate opt_class
3766 : {
3767 9 : PartitionElem *n = makeNode(PartitionElem);
3768 :
3769 9 : n->name = NULL;
3770 9 : n->expr = $1;
3771 9 : n->collation = $2;
3772 9 : n->opclass = $3;
3773 9 : n->location = @1;
3774 9 : $$ = n;
3775 : }
3776 : | '(' a_expr ')' opt_collate opt_class
3777 : {
3778 12 : PartitionElem *n = makeNode(PartitionElem);
3779 :
3780 12 : n->name = NULL;
3781 12 : n->expr = $2;
3782 12 : n->collation = $4;
3783 12 : n->opclass = $5;
3784 12 : n->location = @1;
3785 12 : $$ = n;
3786 : }
3787 : ;
3788 : /* WITH (options) is preferred, WITH OIDS and WITHOUT OIDS are legacy forms */
3789 : OptWith:
3790 4 : WITH reloptions { $$ = $2; }
3791 29 : | WITH OIDS { $$ = list_make1(makeDefElem("oids", (Node *) makeInteger(true), @1)); }
3792 22 : | WITHOUT OIDS { $$ = list_make1(makeDefElem("oids", (Node *) makeInteger(false), @1)); }
3793 1500 : | /*EMPTY*/ { $$ = NIL; }
3794 : ;
3795 :
3796 2 : OnCommitOption: ON COMMIT DROP { $$ = ONCOMMIT_DROP; }
3797 8 : | ON COMMIT DELETE_P ROWS { $$ = ONCOMMIT_DELETE_ROWS; }
3798 0 : | ON COMMIT PRESERVE ROWS { $$ = ONCOMMIT_PRESERVE_ROWS; }
3799 1545 : | /*EMPTY*/ { $$ = ONCOMMIT_NOOP; }
3800 : ;
3801 :
3802 22 : OptTableSpace: TABLESPACE name { $$ = $2; }
3803 1843 : | /*EMPTY*/ { $$ = NULL; }
3804 : ;
3805 :
3806 0 : OptConsTableSpace: USING INDEX TABLESPACE name { $$ = $4; }
3807 335 : | /*EMPTY*/ { $$ = NULL; }
3808 : ;
3809 :
3810 2 : ExistingIndex: USING INDEX index_name { $$ = $3; }
3811 : ;
3812 :
3813 : /*****************************************************************************
3814 : *
3815 : * QUERY :
3816 : * CREATE STATISTICS [IF NOT EXISTS] stats_name [(stat types)]
3817 : * ON expression-list FROM from_list
3818 : *
3819 : * Note: the expectation here is that the clauses after ON are a subset of
3820 : * SELECT syntax, allowing for expressions and joined tables, and probably
3821 : * someday a WHERE clause. Much less than that is currently implemented,
3822 : * but the grammar accepts it and then we'll throw FEATURE_NOT_SUPPORTED
3823 : * errors as necessary at execution.
3824 : *
3825 : *****************************************************************************/
3826 :
3827 : CreateStatsStmt:
3828 : CREATE STATISTICS any_name
3829 : opt_name_list ON expr_list FROM from_list
3830 : {
3831 29 : CreateStatsStmt *n = makeNode(CreateStatsStmt);
3832 29 : n->defnames = $3;
3833 29 : n->stat_types = $4;
3834 29 : n->exprs = $6;
3835 29 : n->relations = $8;
3836 29 : n->if_not_exists = false;
3837 29 : $$ = (Node *)n;
3838 : }
3839 : | CREATE STATISTICS IF_P NOT EXISTS any_name
3840 : opt_name_list ON expr_list FROM from_list
3841 : {
3842 2 : CreateStatsStmt *n = makeNode(CreateStatsStmt);
3843 2 : n->defnames = $6;
3844 2 : n->stat_types = $7;
3845 2 : n->exprs = $9;
3846 2 : n->relations = $11;
3847 2 : n->if_not_exists = true;
3848 2 : $$ = (Node *)n;
3849 : }
3850 : ;
3851 :
3852 : /*****************************************************************************
3853 : *
3854 : * QUERY :
3855 : * CREATE TABLE relname AS SelectStmt [ WITH [NO] DATA ]
3856 : *
3857 : *
3858 : * Note: SELECT ... INTO is a now-deprecated alternative for this.
3859 : *
3860 : *****************************************************************************/
3861 :
3862 : CreateAsStmt:
3863 : CREATE OptTemp TABLE create_as_target AS SelectStmt opt_with_data
3864 : {
3865 68 : CreateTableAsStmt *ctas = makeNode(CreateTableAsStmt);
3866 68 : ctas->query = $6;
3867 68 : ctas->into = $4;
3868 68 : ctas->relkind = OBJECT_TABLE;
3869 68 : ctas->is_select_into = false;
3870 68 : ctas->if_not_exists = false;
3871 : /* cram additional flags into the IntoClause */
3872 68 : $4->rel->relpersistence = $2;
3873 68 : $4->skipData = !($7);
3874 68 : $$ = (Node *) ctas;
3875 : }
3876 : | CREATE OptTemp TABLE IF_P NOT EXISTS create_as_target AS SelectStmt opt_with_data
3877 : {
3878 1 : CreateTableAsStmt *ctas = makeNode(CreateTableAsStmt);
3879 1 : ctas->query = $9;
3880 1 : ctas->into = $7;
3881 1 : ctas->relkind = OBJECT_TABLE;
3882 1 : ctas->is_select_into = false;
3883 1 : ctas->if_not_exists = true;
3884 : /* cram additional flags into the IntoClause */
3885 1 : $7->rel->relpersistence = $2;
3886 1 : $7->skipData = !($10);
3887 1 : $$ = (Node *) ctas;
3888 : }
3889 : ;
3890 :
3891 : create_as_target:
3892 : qualified_name opt_column_list OptWith OnCommitOption OptTableSpace
3893 : {
3894 73 : $$ = makeNode(IntoClause);
3895 73 : $$->rel = $1;
3896 73 : $$->colNames = $2;
3897 73 : $$->options = $3;
3898 73 : $$->onCommit = $4;
3899 73 : $$->tableSpaceName = $5;
3900 73 : $$->viewQuery = NULL;
3901 73 : $$->skipData = false; /* might get changed later */
3902 : }
3903 : ;
3904 :
3905 : opt_with_data:
3906 0 : WITH DATA_P { $$ = TRUE; }
3907 14 : | WITH NO DATA_P { $$ = FALSE; }
3908 116 : | /*EMPTY*/ { $$ = TRUE; }
3909 : ;
3910 :
3911 :
3912 : /*****************************************************************************
3913 : *
3914 : * QUERY :
3915 : * CREATE MATERIALIZED VIEW relname AS SelectStmt
3916 : *
3917 : *****************************************************************************/
3918 :
3919 : CreateMatViewStmt:
3920 : CREATE OptNoLog MATERIALIZED VIEW create_mv_target AS SelectStmt opt_with_data
3921 : {
3922 35 : CreateTableAsStmt *ctas = makeNode(CreateTableAsStmt);
3923 35 : ctas->query = $7;
3924 35 : ctas->into = $5;
3925 35 : ctas->relkind = OBJECT_MATVIEW;
3926 35 : ctas->is_select_into = false;
3927 35 : ctas->if_not_exists = false;
3928 : /* cram additional flags into the IntoClause */
3929 35 : $5->rel->relpersistence = $2;
3930 35 : $5->skipData = !($8);
3931 35 : $$ = (Node *) ctas;
3932 : }
3933 : | CREATE OptNoLog MATERIALIZED VIEW IF_P NOT EXISTS create_mv_target AS SelectStmt opt_with_data
3934 : {
3935 1 : CreateTableAsStmt *ctas = makeNode(CreateTableAsStmt);
3936 1 : ctas->query = $10;
3937 1 : ctas->into = $8;
3938 1 : ctas->relkind = OBJECT_MATVIEW;
3939 1 : ctas->is_select_into = false;
3940 1 : ctas->if_not_exists = true;
3941 : /* cram additional flags into the IntoClause */
3942 1 : $8->rel->relpersistence = $2;
3943 1 : $8->skipData = !($11);
3944 1 : $$ = (Node *) ctas;
3945 : }
3946 : ;
3947 :
3948 : create_mv_target:
3949 : qualified_name opt_column_list opt_reloptions OptTableSpace
3950 : {
3951 36 : $$ = makeNode(IntoClause);
3952 36 : $$->rel = $1;
3953 36 : $$->colNames = $2;
3954 36 : $$->options = $3;
3955 36 : $$->onCommit = ONCOMMIT_NOOP;
3956 36 : $$->tableSpaceName = $4;
3957 36 : $$->viewQuery = NULL; /* filled at analysis time */
3958 36 : $$->skipData = false; /* might get changed later */
3959 : }
3960 : ;
3961 :
3962 0 : OptNoLog: UNLOGGED { $$ = RELPERSISTENCE_UNLOGGED; }
3963 36 : | /*EMPTY*/ { $$ = RELPERSISTENCE_PERMANENT; }
3964 : ;
3965 :
3966 :
3967 : /*****************************************************************************
3968 : *
3969 : * QUERY :
3970 : * REFRESH MATERIALIZED VIEW qualified_name
3971 : *
3972 : *****************************************************************************/
3973 :
3974 : RefreshMatViewStmt:
3975 : REFRESH MATERIALIZED VIEW opt_concurrently qualified_name opt_with_data
3976 : {
3977 21 : RefreshMatViewStmt *n = makeNode(RefreshMatViewStmt);
3978 21 : n->concurrent = $4;
3979 21 : n->relation = $5;
3980 21 : n->skipData = !($6);
3981 21 : $$ = (Node *) n;
3982 : }
3983 : ;
3984 :
3985 :
3986 : /*****************************************************************************
3987 : *
3988 : * QUERY :
3989 : * CREATE SEQUENCE seqname
3990 : * ALTER SEQUENCE seqname
3991 : *
3992 : *****************************************************************************/
3993 :
3994 : CreateSeqStmt:
3995 : CREATE OptTemp SEQUENCE qualified_name OptSeqOptList
3996 : {
3997 67 : CreateSeqStmt *n = makeNode(CreateSeqStmt);
3998 67 : $4->relpersistence = $2;
3999 67 : n->sequence = $4;
4000 67 : n->options = $5;
4001 67 : n->ownerId = InvalidOid;
4002 67 : n->if_not_exists = false;
4003 67 : $$ = (Node *)n;
4004 : }
4005 : | CREATE OptTemp SEQUENCE IF_P NOT EXISTS qualified_name OptSeqOptList
4006 : {
4007 1 : CreateSeqStmt *n = makeNode(CreateSeqStmt);
4008 1 : $7->relpersistence = $2;
4009 1 : n->sequence = $7;
4010 1 : n->options = $8;
4011 1 : n->ownerId = InvalidOid;
4012 1 : n->if_not_exists = true;
4013 1 : $$ = (Node *)n;
4014 : }
4015 : ;
4016 :
4017 : AlterSeqStmt:
4018 : ALTER SEQUENCE qualified_name SeqOptList
4019 : {
4020 23 : AlterSeqStmt *n = makeNode(AlterSeqStmt);
4021 23 : n->sequence = $3;
4022 23 : n->options = $4;
4023 23 : n->missing_ok = false;
4024 23 : $$ = (Node *)n;
4025 : }
4026 : | ALTER SEQUENCE IF_P EXISTS qualified_name SeqOptList
4027 : {
4028 2 : AlterSeqStmt *n = makeNode(AlterSeqStmt);
4029 2 : n->sequence = $5;
4030 2 : n->options = $6;
4031 2 : n->missing_ok = true;
4032 2 : $$ = (Node *)n;
4033 : }
4034 :
4035 : ;
4036 :
4037 29 : OptSeqOptList: SeqOptList { $$ = $1; }
4038 39 : | /*EMPTY*/ { $$ = NIL; }
4039 : ;
4040 :
4041 2 : OptParenthesizedSeqOptList: '(' SeqOptList ')' { $$ = $2; }
4042 22 : | /*EMPTY*/ { $$ = NIL; }
4043 : ;
4044 :
4045 56 : SeqOptList: SeqOptElem { $$ = list_make1($1); }
4046 39 : | SeqOptList SeqOptElem { $$ = lappend($1, $2); }
4047 : ;
4048 :
4049 : SeqOptElem: AS SimpleTypename
4050 : {
4051 24 : $$ = makeDefElem("as", (Node *)$2, @1);
4052 : }
4053 : | CACHE NumericOnly
4054 : {
4055 2 : $$ = makeDefElem("cache", (Node *)$2, @1);
4056 : }
4057 : | CYCLE
4058 : {
4059 5 : $$ = makeDefElem("cycle", (Node *)makeInteger(TRUE), @1);
4060 : }
4061 : | NO CYCLE
4062 : {
4063 2 : $$ = makeDefElem("cycle", (Node *)makeInteger(FALSE), @1);
4064 : }
4065 : | INCREMENT opt_by NumericOnly
4066 : {
4067 17 : $$ = makeDefElem("increment", (Node *)$3, @1);
4068 : }
4069 : | MAXVALUE NumericOnly
4070 : {
4071 9 : $$ = makeDefElem("maxvalue", (Node *)$2, @1);
4072 : }
4073 : | MINVALUE NumericOnly
4074 : {
4075 10 : $$ = makeDefElem("minvalue", (Node *)$2, @1);
4076 : }
4077 : | NO MAXVALUE
4078 : {
4079 0 : $$ = makeDefElem("maxvalue", NULL, @1);
4080 : }
4081 : | NO MINVALUE
4082 : {
4083 0 : $$ = makeDefElem("minvalue", NULL, @1);
4084 : }
4085 : | OWNED BY any_name
4086 : {
4087 7 : $$ = makeDefElem("owned_by", (Node *)$3, @1);
4088 : }
4089 : | SEQUENCE NAME_P any_name
4090 : {
4091 : /* not documented, only used by pg_dump */
4092 0 : $$ = makeDefElem("sequence_name", (Node *)$3, @1);
4093 : }
4094 : | START opt_with NumericOnly
4095 : {
4096 12 : $$ = makeDefElem("start", (Node *)$3, @1);
4097 : }
4098 : | RESTART
4099 : {
4100 1 : $$ = makeDefElem("restart", NULL, @1);
4101 : }
4102 : | RESTART opt_with NumericOnly
4103 : {
4104 9 : $$ = makeDefElem("restart", (Node *)$3, @1);
4105 : }
4106 : ;
4107 :
4108 : opt_by: BY {}
4109 : | /* empty */ {}
4110 : ;
4111 :
4112 : NumericOnly:
4113 9 : FCONST { $$ = makeFloat($1); }
4114 0 : | '+' FCONST { $$ = makeFloat($2); }
4115 : | '-' FCONST
4116 : {
4117 0 : $$ = makeFloat($2);
4118 0 : doNegateFloat($$);
4119 : }
4120 474 : | SignedIconst { $$ = makeInteger($1); }
4121 : ;
4122 :
4123 12 : NumericOnly_list: NumericOnly { $$ = list_make1($1); }
4124 1 : | NumericOnly_list ',' NumericOnly { $$ = lappend($1, $3); }
4125 : ;
4126 :
4127 : /*****************************************************************************
4128 : *
4129 : * QUERIES :
4130 : * CREATE [OR REPLACE] [TRUSTED] [PROCEDURAL] LANGUAGE ...
4131 : * DROP [PROCEDURAL] LANGUAGE ...
4132 : *
4133 : *****************************************************************************/
4134 :
4135 : CreatePLangStmt:
4136 : CREATE opt_or_replace opt_trusted opt_procedural LANGUAGE NonReservedWord_or_Sconst
4137 : {
4138 1 : CreatePLangStmt *n = makeNode(CreatePLangStmt);
4139 1 : n->replace = $2;
4140 1 : n->plname = $6;
4141 : /* parameters are all to be supplied by system */
4142 1 : n->plhandler = NIL;
4143 1 : n->plinline = NIL;
4144 1 : n->plvalidator = NIL;
4145 1 : n->pltrusted = false;
4146 1 : $$ = (Node *)n;
4147 : }
4148 : | CREATE opt_or_replace opt_trusted opt_procedural LANGUAGE NonReservedWord_or_Sconst
4149 : HANDLER handler_name opt_inline_handler opt_validator
4150 : {
4151 2 : CreatePLangStmt *n = makeNode(CreatePLangStmt);
4152 2 : n->replace = $2;
4153 2 : n->plname = $6;
4154 2 : n->plhandler = $8;
4155 2 : n->plinline = $9;
4156 2 : n->plvalidator = $10;
4157 2 : n->pltrusted = $3;
4158 2 : $$ = (Node *)n;
4159 : }
4160 : ;
4161 :
4162 : opt_trusted:
4163 0 : TRUSTED { $$ = TRUE; }
4164 4 : | /*EMPTY*/ { $$ = FALSE; }
4165 : ;
4166 :
4167 : /* This ought to be just func_name, but that causes reduce/reduce conflicts
4168 : * (CREATE LANGUAGE is the only place where func_name isn't followed by '(').
4169 : * Work around by using simple names, instead.
4170 : */
4171 : handler_name:
4172 8 : name { $$ = list_make1(makeString($1)); }
4173 0 : | name attrs { $$ = lcons(makeString($1), $2); }
4174 : ;
4175 :
4176 : opt_inline_handler:
4177 0 : INLINE_P handler_name { $$ = $2; }
4178 2 : | /*EMPTY*/ { $$ = NIL; }
4179 : ;
4180 :
4181 : validator_clause:
4182 0 : VALIDATOR handler_name { $$ = $2; }
4183 0 : | NO VALIDATOR { $$ = NIL; }
4184 : ;
4185 :
4186 : opt_validator:
4187 0 : validator_clause { $$ = $1; }
4188 2 : | /*EMPTY*/ { $$ = NIL; }
4189 : ;
4190 :
4191 : DropPLangStmt:
4192 : DROP opt_procedural LANGUAGE NonReservedWord_or_Sconst opt_drop_behavior
4193 : {
4194 3 : DropStmt *n = makeNode(DropStmt);
4195 3 : n->removeType = OBJECT_LANGUAGE;
4196 3 : n->objects = list_make1(makeString($4));
4197 3 : n->behavior = $5;
4198 3 : n->missing_ok = false;
4199 3 : n->concurrent = false;
4200 3 : $$ = (Node *)n;
4201 : }
4202 : | DROP opt_procedural LANGUAGE IF_P EXISTS NonReservedWord_or_Sconst opt_drop_behavior
4203 : {
4204 1 : DropStmt *n = makeNode(DropStmt);
4205 1 : n->removeType = OBJECT_LANGUAGE;
4206 1 : n->objects = list_make1(makeString($6));
4207 1 : n->behavior = $7;
4208 1 : n->missing_ok = true;
4209 1 : n->concurrent = false;
4210 1 : $$ = (Node *)n;
4211 : }
4212 : ;
4213 :
4214 : opt_procedural:
4215 : PROCEDURAL {}
4216 : | /*EMPTY*/ {}
4217 : ;
4218 :
4219 : /*****************************************************************************
4220 : *
4221 : * QUERY:
4222 : * CREATE TABLESPACE tablespace LOCATION '/path/to/tablespace/'
4223 : *
4224 : *****************************************************************************/
4225 :
4226 : CreateTableSpaceStmt: CREATE TABLESPACE name OptTableSpaceOwner LOCATION Sconst opt_reloptions
4227 : {
4228 4 : CreateTableSpaceStmt *n = makeNode(CreateTableSpaceStmt);
4229 4 : n->tablespacename = $3;
4230 4 : n->owner = $4;
4231 4 : n->location = $6;
4232 4 : n->options = $7;
4233 4 : $$ = (Node *) n;
4234 : }
4235 : ;
4236 :
4237 0 : OptTableSpaceOwner: OWNER RoleSpec { $$ = $2; }
4238 4 : | /*EMPTY */ { $$ = NULL; }
4239 : ;
4240 :
4241 : /*****************************************************************************
4242 : *
4243 : * QUERY :
4244 : * DROP TABLESPACE <tablespace>
4245 : *
4246 : * No need for drop behaviour as we cannot implement dependencies for
4247 : * objects in other databases; we can only support RESTRICT.
4248 : *
4249 : ****************************************************************************/
4250 :
4251 : DropTableSpaceStmt: DROP TABLESPACE name
4252 : {
4253 3 : DropTableSpaceStmt *n = makeNode(DropTableSpaceStmt);
4254 3 : n->tablespacename = $3;
4255 3 : n->missing_ok = false;
4256 3 : $$ = (Node *) n;
4257 : }
4258 : | DROP TABLESPACE IF_P EXISTS name
4259 : {
4260 0 : DropTableSpaceStmt *n = makeNode(DropTableSpaceStmt);
4261 0 : n->tablespacename = $5;
4262 0 : n->missing_ok = true;
4263 0 : $$ = (Node *) n;
4264 : }
4265 : ;
4266 :
4267 : /*****************************************************************************
4268 : *
4269 : * QUERY:
4270 : * CREATE EXTENSION extension
4271 : * [ WITH ] [ SCHEMA schema ] [ VERSION version ] [ FROM oldversion ]
4272 : *
4273 : *****************************************************************************/
4274 :
4275 : CreateExtensionStmt: CREATE EXTENSION name opt_with create_extension_opt_list
4276 : {
4277 1 : CreateExtensionStmt *n = makeNode(CreateExtensionStmt);
4278 1 : n->extname = $3;
4279 1 : n->if_not_exists = false;
4280 1 : n->options = $5;
4281 1 : $$ = (Node *) n;
4282 : }
4283 : | CREATE EXTENSION IF_P NOT EXISTS name opt_with create_extension_opt_list
4284 : {
4285 0 : CreateExtensionStmt *n = makeNode(CreateExtensionStmt);
4286 0 : n->extname = $6;
4287 0 : n->if_not_exists = true;
4288 0 : n->options = $8;
4289 0 : $$ = (Node *) n;
4290 : }
4291 : ;
4292 :
4293 : create_extension_opt_list:
4294 : create_extension_opt_list create_extension_opt_item
4295 0 : { $$ = lappend($1, $2); }
4296 : | /* EMPTY */
4297 1 : { $$ = NIL; }
4298 : ;
4299 :
4300 : create_extension_opt_item:
4301 : SCHEMA name
4302 : {
4303 0 : $$ = makeDefElem("schema", (Node *)makeString($2), @1);
4304 : }
4305 : | VERSION_P NonReservedWord_or_Sconst
4306 : {
4307 0 : $$ = makeDefElem("new_version", (Node *)makeString($2), @1);
4308 : }
4309 : | FROM NonReservedWord_or_Sconst
4310 : {
4311 0 : $$ = makeDefElem("old_version", (Node *)makeString($2), @1);
4312 : }
4313 : | CASCADE
4314 : {
4315 0 : $$ = makeDefElem("cascade", (Node *)makeInteger(TRUE), @1);
4316 : }
4317 : ;
4318 :
4319 : /*****************************************************************************
4320 : *
4321 : * ALTER EXTENSION name UPDATE [ TO version ]
4322 : *
4323 : *****************************************************************************/
4324 :
4325 : AlterExtensionStmt: ALTER EXTENSION name UPDATE alter_extension_opt_list
4326 : {
4327 0 : AlterExtensionStmt *n = makeNode(AlterExtensionStmt);
4328 0 : n->extname = $3;
4329 0 : n->options = $5;
4330 0 : $$ = (Node *) n;
4331 : }
4332 : ;
4333 :
4334 : alter_extension_opt_list:
4335 : alter_extension_opt_list alter_extension_opt_item
4336 0 : { $$ = lappend($1, $2); }
4337 : | /* EMPTY */
4338 0 : { $$ = NIL; }
4339 : ;
4340 :
4341 : alter_extension_opt_item:
4342 : TO NonReservedWord_or_Sconst
4343 : {
4344 0 : $$ = makeDefElem("new_version", (Node *)makeString($2), @1);
4345 : }
4346 : ;
4347 :
4348 : /*****************************************************************************
4349 : *
4350 : * ALTER EXTENSION name ADD/DROP object-identifier
4351 : *
4352 : *****************************************************************************/
4353 :
4354 : AlterExtensionContentsStmt:
4355 : ALTER EXTENSION name add_drop ACCESS METHOD name
4356 : {
4357 0 : AlterExtensionContentsStmt *n = makeNode(AlterExtensionContentsStmt);
4358 0 : n->extname = $3;
4359 0 : n->action = $4;
4360 0 : n->objtype = OBJECT_ACCESS_METHOD;
4361 0 : n->object = (Node *) makeString($7);
4362 0 : $$ = (Node *)n;
4363 : }
4364 : | ALTER EXTENSION name add_drop AGGREGATE aggregate_with_argtypes
4365 : {
4366 0 : AlterExtensionContentsStmt *n = makeNode(AlterExtensionContentsStmt);
4367 0 : n->extname = $3;
4368 0 : n->action = $4;
4369 0 : n->objtype = OBJECT_AGGREGATE;
4370 0 : n->object = (Node *) $6;
4371 0 : $$ = (Node *)n;
4372 : }
4373 : | ALTER EXTENSION name add_drop CAST '(' Typename AS Typename ')'
4374 : {
4375 0 : AlterExtensionContentsStmt *n = makeNode(AlterExtensionContentsStmt);
4376 0 : n->extname = $3;
4377 0 : n->action = $4;
4378 0 : n->objtype = OBJECT_CAST;
4379 0 : n->object = (Node *) list_make2($7, $9);
4380 0 : $$ = (Node *) n;
4381 : }
4382 : | ALTER EXTENSION name add_drop COLLATION any_name
4383 : {
4384 0 : AlterExtensionContentsStmt *n = makeNode(AlterExtensionContentsStmt);
4385 0 : n->extname = $3;
4386 0 : n->action = $4;
4387 0 : n->objtype = OBJECT_COLLATION;
4388 0 : n->object = (Node *) $6;
4389 0 : $$ = (Node *)n;
4390 : }
4391 : | ALTER EXTENSION name add_drop CONVERSION_P any_name
4392 : {
4393 0 : AlterExtensionContentsStmt *n = makeNode(AlterExtensionContentsStmt);
4394 0 : n->extname = $3;
4395 0 : n->action = $4;
4396 0 : n->objtype = OBJECT_CONVERSION;
4397 0 : n->object = (Node *) $6;
4398 0 : $$ = (Node *)n;
4399 : }
4400 : | ALTER EXTENSION name add_drop DOMAIN_P Typename
4401 : {
4402 0 : AlterExtensionContentsStmt *n = makeNode(AlterExtensionContentsStmt);
4403 0 : n->extname = $3;
4404 0 : n->action = $4;
4405 0 : n->objtype = OBJECT_DOMAIN;
4406 0 : n->object = (Node *) $6;
4407 0 : $$ = (Node *)n;
4408 : }
4409 : | ALTER EXTENSION name add_drop FUNCTION function_with_argtypes
4410 : {
4411 0 : AlterExtensionContentsStmt *n = makeNode(AlterExtensionContentsStmt);
4412 0 : n->extname = $3;
4413 0 : n->action = $4;
4414 0 : n->objtype = OBJECT_FUNCTION;
4415 0 : n->object = (Node *) $6;
4416 0 : $$ = (Node *)n;
4417 : }
4418 : | ALTER EXTENSION name add_drop opt_procedural LANGUAGE name
4419 : {
4420 0 : AlterExtensionContentsStmt *n = makeNode(AlterExtensionContentsStmt);
4421 0 : n->extname = $3;
4422 0 : n->action = $4;
4423 0 : n->objtype = OBJECT_LANGUAGE;
4424 0 : n->object = (Node *) makeString($7);
4425 0 : $$ = (Node *)n;
4426 : }
4427 : | ALTER EXTENSION name add_drop OPERATOR operator_with_argtypes
4428 : {
4429 0 : AlterExtensionContentsStmt *n = makeNode(AlterExtensionContentsStmt);
4430 0 : n->extname = $3;
4431 0 : n->action = $4;
4432 0 : n->objtype = OBJECT_OPERATOR;
4433 0 : n->object = (Node *) $6;
4434 0 : $$ = (Node *)n;
4435 : }
4436 : | ALTER EXTENSION name add_drop OPERATOR CLASS any_name USING access_method
4437 : {
4438 0 : AlterExtensionContentsStmt *n = makeNode(AlterExtensionContentsStmt);
4439 0 : n->extname = $3;
4440 0 : n->action = $4;
4441 0 : n->objtype = OBJECT_OPCLASS;
4442 0 : n->object = (Node *) lcons(makeString($9), $7);
4443 0 : $$ = (Node *)n;
4444 : }
4445 : | ALTER EXTENSION name add_drop OPERATOR FAMILY any_name USING access_method
4446 : {
4447 0 : AlterExtensionContentsStmt *n = makeNode(AlterExtensionContentsStmt);
4448 0 : n->extname = $3;
4449 0 : n->action = $4;
4450 0 : n->objtype = OBJECT_OPFAMILY;
4451 0 : n->object = (Node *) lcons(makeString($9), $7);
4452 0 : $$ = (Node *)n;
4453 : }
4454 : | ALTER EXTENSION name add_drop SCHEMA name
4455 : {
4456 0 : AlterExtensionContentsStmt *n = makeNode(AlterExtensionContentsStmt);
4457 0 : n->extname = $3;
4458 0 : n->action = $4;
4459 0 : n->objtype = OBJECT_SCHEMA;
4460 0 : n->object = (Node *) makeString($6);
4461 0 : $$ = (Node *)n;
4462 : }
4463 : | ALTER EXTENSION name add_drop EVENT TRIGGER name
4464 : {
4465 0 : AlterExtensionContentsStmt *n = makeNode(AlterExtensionContentsStmt);
4466 0 : n->extname = $3;
4467 0 : n->action = $4;
4468 0 : n->objtype = OBJECT_EVENT_TRIGGER;
4469 0 : n->object = (Node *) makeString($7);
4470 0 : $$ = (Node *)n;
4471 : }
4472 : | ALTER EXTENSION name add_drop TABLE any_name
4473 : {
4474 0 : AlterExtensionContentsStmt *n = makeNode(AlterExtensionContentsStmt);
4475 0 : n->extname = $3;
4476 0 : n->action = $4;
4477 0 : n->objtype = OBJECT_TABLE;
4478 0 : n->object = (Node *) $6;
4479 0 : $$ = (Node *)n;
4480 : }
4481 : | ALTER EXTENSION name add_drop TEXT_P SEARCH PARSER any_name
4482 : {
4483 0 : AlterExtensionContentsStmt *n = makeNode(AlterExtensionContentsStmt);
4484 0 : n->extname = $3;
4485 0 : n->action = $4;
4486 0 : n->objtype = OBJECT_TSPARSER;
4487 0 : n->object = (Node *) $8;
4488 0 : $$ = (Node *)n;
4489 : }
4490 : | ALTER EXTENSION name add_drop TEXT_P SEARCH DICTIONARY any_name
4491 : {
4492 0 : AlterExtensionContentsStmt *n = makeNode(AlterExtensionContentsStmt);
4493 0 : n->extname = $3;
4494 0 : n->action = $4;
4495 0 : n->objtype = OBJECT_TSDICTIONARY;
4496 0 : n->object = (Node *) $8;
4497 0 : $$ = (Node *)n;
4498 : }
4499 : | ALTER EXTENSION name add_drop TEXT_P SEARCH TEMPLATE any_name
4500 : {
4501 0 : AlterExtensionContentsStmt *n = makeNode(AlterExtensionContentsStmt);
4502 0 : n->extname = $3;
4503 0 : n->action = $4;
4504 0 : n->objtype = OBJECT_TSTEMPLATE;
4505 0 : n->object = (Node *) $8;
4506 0 : $$ = (Node *)n;
4507 : }
4508 : | ALTER EXTENSION name add_drop TEXT_P SEARCH CONFIGURATION any_name
4509 : {
4510 0 : AlterExtensionContentsStmt *n = makeNode(AlterExtensionContentsStmt);
4511 0 : n->extname = $3;
4512 0 : n->action = $4;
4513 0 : n->objtype = OBJECT_TSCONFIGURATION;
4514 0 : n->object = (Node *) $8;
4515 0 : $$ = (Node *)n;
4516 : }
4517 : | ALTER EXTENSION name add_drop SEQUENCE any_name
4518 : {
4519 0 : AlterExtensionContentsStmt *n = makeNode(AlterExtensionContentsStmt);
4520 0 : n->extname = $3;
4521 0 : n->action = $4;
4522 0 : n->objtype = OBJECT_SEQUENCE;
4523 0 : n->object = (Node *) $6;
4524 0 : $$ = (Node *)n;
4525 : }
4526 : | ALTER EXTENSION name add_drop VIEW any_name
4527 : {
4528 0 : AlterExtensionContentsStmt *n = makeNode(AlterExtensionContentsStmt);
4529 0 : n->extname = $3;
4530 0 : n->action = $4;
4531 0 : n->objtype = OBJECT_VIEW;
4532 0 : n->object = (Node *) $6;
4533 0 : $$ = (Node *)n;
4534 : }
4535 : | ALTER EXTENSION name add_drop MATERIALIZED VIEW any_name
4536 : {
4537 0 : AlterExtensionContentsStmt *n = makeNode(AlterExtensionContentsStmt);
4538 0 : n->extname = $3;
4539 0 : n->action = $4;
4540 0 : n->objtype = OBJECT_MATVIEW;
4541 0 : n->object = (Node *) $7;
4542 0 : $$ = (Node *)n;
4543 : }
4544 : | ALTER EXTENSION name add_drop FOREIGN TABLE any_name
4545 : {
4546 0 : AlterExtensionContentsStmt *n = makeNode(AlterExtensionContentsStmt);
4547 0 : n->extname = $3;
4548 0 : n->action = $4;
4549 0 : n->objtype = OBJECT_FOREIGN_TABLE;
4550 0 : n->object = (Node *) $7;
4551 0 : $$ = (Node *)n;
4552 : }
4553 : | ALTER EXTENSION name add_drop FOREIGN DATA_P WRAPPER name
4554 : {
4555 0 : AlterExtensionContentsStmt *n = makeNode(AlterExtensionContentsStmt);
4556 0 : n->extname = $3;
4557 0 : n->action = $4;
4558 0 : n->objtype = OBJECT_FDW;
4559 0 : n->object = (Node *) makeString($8);
4560 0 : $$ = (Node *)n;
4561 : }
4562 : | ALTER EXTENSION name add_drop SERVER name
4563 : {
4564 0 : AlterExtensionContentsStmt *n = makeNode(AlterExtensionContentsStmt);
4565 0 : n->extname = $3;
4566 0 : n->action = $4;
4567 0 : n->objtype = OBJECT_FOREIGN_SERVER;
4568 0 : n->object = (Node *) makeString($6);
4569 0 : $$ = (Node *)n;
4570 : }
4571 : | ALTER EXTENSION name add_drop TRANSFORM FOR Typename LANGUAGE name
4572 : {
4573 0 : AlterExtensionContentsStmt *n = makeNode(AlterExtensionContentsStmt);
4574 0 : n->extname = $3;
4575 0 : n->action = $4;
4576 0 : n->objtype = OBJECT_TRANSFORM;
4577 0 : n->object = (Node *) list_make2($7, makeString($9));
4578 0 : $$ = (Node *)n;
4579 : }
4580 : | ALTER EXTENSION name add_drop TYPE_P Typename
4581 : {
4582 0 : AlterExtensionContentsStmt *n = makeNode(AlterExtensionContentsStmt);
4583 0 : n->extname = $3;
4584 0 : n->action = $4;
4585 0 : n->objtype = OBJECT_TYPE;
4586 0 : n->object = (Node *) $6;
4587 0 : $$ = (Node *)n;
4588 : }
4589 : ;
4590 :
4591 : /*****************************************************************************
4592 : *
4593 : * QUERY:
4594 : * CREATE FOREIGN DATA WRAPPER name options
4595 : *
4596 : *****************************************************************************/
4597 :
4598 : CreateFdwStmt: CREATE FOREIGN DATA_P WRAPPER name opt_fdw_options create_generic_options
4599 : {
4600 20 : CreateFdwStmt *n = makeNode(CreateFdwStmt);
4601 20 : n->fdwname = $5;
4602 20 : n->func_options = $6;
4603 20 : n->options = $7;
4604 20 : $$ = (Node *) n;
4605 : }
4606 : ;
4607 :
4608 : fdw_option:
4609 0 : HANDLER handler_name { $$ = makeDefElem("handler", (Node *)$2, @1); }
4610 0 : | NO HANDLER { $$ = makeDefElem("handler", NULL, @1); }
4611 5 : | VALIDATOR handler_name { $$ = makeDefElem("validator", (Node *)$2, @1); }
4612 1 : | NO VALIDATOR { $$ = makeDefElem("validator", NULL, @1); }
4613 : ;
4614 :
4615 : fdw_options:
4616 6 : fdw_option { $$ = list_make1($1); }
4617 0 : | fdw_options fdw_option { $$ = lappend($1, $2); }
4618 : ;
4619 :
4620 : opt_fdw_options:
4621 3 : fdw_options { $$ = $1; }
4622 30 : | /*EMPTY*/ { $$ = NIL; }
4623 : ;
4624 :
4625 : /*****************************************************************************
4626 : *
4627 : * QUERY :
4628 : * ALTER FOREIGN DATA WRAPPER name options
4629 : *
4630 : ****************************************************************************/
4631 :
4632 : AlterFdwStmt: ALTER FOREIGN DATA_P WRAPPER name opt_fdw_options alter_generic_options
4633 : {
4634 12 : AlterFdwStmt *n = makeNode(AlterFdwStmt);
4635 12 : n->fdwname = $5;
4636 12 : n->func_options = $6;
4637 12 : n->options = $7;
4638 12 : $$ = (Node *) n;
4639 : }
4640 : | ALTER FOREIGN DATA_P WRAPPER name fdw_options
4641 : {
4642 3 : AlterFdwStmt *n = makeNode(AlterFdwStmt);
4643 3 : n->fdwname = $5;
4644 3 : n->func_options = $6;
4645 3 : n->options = NIL;
4646 3 : $$ = (Node *) n;
4647 : }
4648 : ;
4649 :
4650 : /* Options definition for CREATE FDW, SERVER and USER MAPPING */
4651 : create_generic_options:
4652 55 : OPTIONS '(' generic_option_list ')' { $$ = $3; }
4653 2642 : | /*EMPTY*/ { $$ = NIL; }
4654 : ;
4655 :
4656 : generic_option_list:
4657 : generic_option_elem
4658 : {
4659 55 : $$ = list_make1($1);
4660 : }
4661 : | generic_option_list ',' generic_option_elem
4662 : {
4663 35 : $$ = lappend($1, $3);
4664 : }
4665 : ;
4666 :
4667 : /* Options definition for ALTER FDW, SERVER and USER MAPPING */
4668 : alter_generic_options:
4669 47 : OPTIONS '(' alter_generic_option_list ')' { $$ = $3; }
4670 : ;
4671 :
4672 : alter_generic_option_list:
4673 : alter_generic_option_elem
4674 : {
4675 47 : $$ = list_make1($1);
4676 : }
4677 : | alter_generic_option_list ',' alter_generic_option_elem
4678 : {
4679 19 : $$ = lappend($1, $3);
4680 : }
4681 : ;
4682 :
4683 : alter_generic_option_elem:
4684 : generic_option_elem
4685 : {
4686 18 : $$ = $1;
4687 : }
4688 : | SET generic_option_elem
4689 : {
4690 17 : $$ = $2;
4691 17 : $$->defaction = DEFELEM_SET;
4692 : }
4693 : | ADD_P generic_option_elem
4694 : {
4695 19 : $$ = $2;
4696 19 : $$->defaction = DEFELEM_ADD;
4697 : }
4698 : | DROP generic_option_name
4699 : {
4700 12 : $$ = makeDefElemExtended(NULL, $2, NULL, DEFELEM_DROP, @2);
4701 : }
4702 : ;
4703 :
4704 : generic_option_elem:
4705 : generic_option_name generic_option_arg
4706 : {
4707 144 : $$ = makeDefElem($1, $2, @1);
4708 : }
4709 : ;
4710 :
4711 : generic_option_name:
4712 156 : ColLabel { $$ = $1; }
4713 : ;
4714 :
4715 : /* We could use def_arg here, but the spec only requires string literals */
4716 : generic_option_arg:
4717 144 : Sconst { $$ = (Node *) makeString($1); }
4718 : ;
4719 :
4720 : /*****************************************************************************
4721 : *
4722 : * QUERY:
4723 : * CREATE SERVER name [TYPE] [VERSION] [OPTIONS]
4724 : *
4725 : *****************************************************************************/
4726 :
4727 : CreateForeignServerStmt: CREATE SERVER name opt_type opt_foreign_server_version
4728 : FOREIGN DATA_P WRAPPER name create_generic_options
4729 : {
4730 37 : CreateForeignServerStmt *n = makeNode(CreateForeignServerStmt);
4731 37 : n->servername = $3;
4732 37 : n->servertype = $4;
4733 37 : n->version = $5;
4734 37 : n->fdwname = $9;
4735 37 : n->options = $10;
4736 37 : n->if_not_exists = false;
4737 37 : $$ = (Node *) n;
4738 : }
4739 : | CREATE SERVER IF_P NOT EXISTS name opt_type opt_foreign_server_version
4740 : FOREIGN DATA_P WRAPPER name create_generic_options
4741 : {
4742 1 : CreateForeignServerStmt *n = makeNode(CreateForeignServerStmt);
4743 1 : n->servername = $6;
4744 1 : n->servertype = $7;
4745 1 : n->version = $8;
4746 1 : n->fdwname = $12;
4747 1 : n->options = $13;
4748 1 : n->if_not_exists = true;
4749 1 : $$ = (Node *) n;
4750 : }
4751 : ;
4752 :
4753 : opt_type:
4754 3 : TYPE_P Sconst { $$ = $2; }
4755 35 : | /*EMPTY*/ { $$ = NULL; }
4756 : ;
4757 :
4758 :
4759 : foreign_server_version:
4760 11 : VERSION_P Sconst { $$ = $2; }
4761 0 : | VERSION_P NULL_P { $$ = NULL; }
4762 : ;
4763 :
4764 : opt_foreign_server_version:
4765 3 : foreign_server_version { $$ = $1; }
4766 35 : | /*EMPTY*/ { $$ = NULL; }
4767 : ;
4768 :
4769 : /*****************************************************************************
4770 : *
4771 : * QUERY :
4772 : * ALTER SERVER name [VERSION] [OPTIONS]
4773 : *
4774 : ****************************************************************************/
4775 :
4776 : AlterForeignServerStmt: ALTER SERVER name foreign_server_version alter_generic_options
4777 : {
4778 1 : AlterForeignServerStmt *n = makeNode(AlterForeignServerStmt);
4779 1 : n->servername = $3;
4780 1 : n->version = $4;
4781 1 : n->options = $5;
4782 1 : n->has_version = true;
4783 1 : $$ = (Node *) n;
4784 : }
4785 : | ALTER SERVER name foreign_server_version
4786 : {
4787 7 : AlterForeignServerStmt *n = makeNode(AlterForeignServerStmt);
4788 7 : n->servername = $3;
4789 7 : n->version = $4;
4790 7 : n->has_version = true;
4791 7 : $$ = (Node *) n;
4792 : }
4793 : | ALTER SERVER name alter_generic_options
4794 : {
4795 5 : AlterForeignServerStmt *n = makeNode(AlterForeignServerStmt);
4796 5 : n->servername = $3;
4797 5 : n->options = $4;
4798 5 : $$ = (Node *) n;
4799 : }
4800 : ;
4801 :
4802 : /*****************************************************************************
4803 : *
4804 : * QUERY:
4805 : * CREATE FOREIGN TABLE relname (...) SERVER name (...)
4806 : *
4807 : *****************************************************************************/
4808 :
4809 : CreateForeignTableStmt:
4810 : CREATE FOREIGN TABLE qualified_name
4811 : '(' OptTableElementList ')'
4812 : OptInherit SERVER name create_generic_options
4813 : {
4814 14 : CreateForeignTableStmt *n = makeNode(CreateForeignTableStmt);
4815 14 : $4->relpersistence = RELPERSISTENCE_PERMANENT;
4816 14 : n->base.relation = $4;
4817 14 : n->base.tableElts = $6;
4818 14 : n->base.inhRelations = $8;
4819 14 : n->base.ofTypename = NULL;
4820 14 : n->base.constraints = NIL;
4821 14 : n->base.options = NIL;
4822 14 : n->base.oncommit = ONCOMMIT_NOOP;
4823 14 : n->base.tablespacename = NULL;
4824 14 : n->base.if_not_exists = false;
4825 : /* FDW-specific data */
4826 14 : n->servername = $10;
4827 14 : n->options = $11;
4828 14 : $$ = (Node *) n;
4829 : }
4830 : | CREATE FOREIGN TABLE IF_P NOT EXISTS qualified_name
4831 : '(' OptTableElementList ')'
4832 : OptInherit SERVER name create_generic_options
4833 : {
4834 0 : CreateForeignTableStmt *n = makeNode(CreateForeignTableStmt);
4835 0 : $7->relpersistence = RELPERSISTENCE_PERMANENT;
4836 0 : n->base.relation = $7;
4837 0 : n->base.tableElts = $9;
4838 0 : n->base.inhRelations = $11;
4839 0 : n->base.ofTypename = NULL;
4840 0 : n->base.constraints = NIL;
4841 0 : n->base.options = NIL;
4842 0 : n->base.oncommit = ONCOMMIT_NOOP;
4843 0 : n->base.tablespacename = NULL;
4844 0 : n->base.if_not_exists = true;
4845 : /* FDW-specific data */
4846 0 : n->servername = $13;
4847 0 : n->options = $14;
4848 0 : $$ = (Node *) n;
4849 : }
4850 : | CREATE FOREIGN TABLE qualified_name
4851 : PARTITION OF qualified_name OptTypedTableElementList ForValues
4852 : SERVER name create_generic_options
4853 : {
4854 1 : CreateForeignTableStmt *n = makeNode(CreateForeignTableStmt);
4855 1 : $4->relpersistence = RELPERSISTENCE_PERMANENT;
4856 1 : n->base.relation = $4;
4857 1 : n->base.inhRelations = list_make1($7);
4858 1 : n->base.tableElts = $8;
4859 1 : n->base.partbound = $9;
4860 1 : n->base.ofTypename = NULL;
4861 1 : n->base.constraints = NIL;
4862 1 : n->base.options = NIL;
4863 1 : n->base.oncommit = ONCOMMIT_NOOP;
4864 1 : n->base.tablespacename = NULL;
4865 1 : n->base.if_not_exists = false;
4866 : /* FDW-specific data */
4867 1 : n->servername = $11;
4868 1 : n->options = $12;
4869 1 : $$ = (Node *) n;
4870 : }
4871 : | CREATE FOREIGN TABLE IF_P NOT EXISTS qualified_name
4872 : PARTITION OF qualified_name OptTypedTableElementList ForValues
4873 : SERVER name create_generic_options
4874 : {
4875 0 : CreateForeignTableStmt *n = makeNode(CreateForeignTableStmt);
4876 0 : $7->relpersistence = RELPERSISTENCE_PERMANENT;
4877 0 : n->base.relation = $7;
4878 0 : n->base.inhRelations = list_make1($10);
4879 0 : n->base.tableElts = $11;
4880 0 : n->base.partbound = $12;
4881 0 : n->base.ofTypename = NULL;
4882 0 : n->base.constraints = NIL;
4883 0 : n->base.options = NIL;
4884 0 : n->base.oncommit = ONCOMMIT_NOOP;
4885 0 : n->base.tablespacename = NULL;
4886 0 : n->base.if_not_exists = true;
4887 : /* FDW-specific data */
4888 0 : n->servername = $14;
4889 0 : n->options = $15;
4890 0 : $$ = (Node *) n;
4891 : }
4892 : ;
4893 :
4894 : /*****************************************************************************
4895 : *
4896 : * QUERY:
4897 : * ALTER FOREIGN TABLE relname [...]
4898 : *
4899 : *****************************************************************************/
4900 :
4901 : AlterForeignTableStmt:
4902 : ALTER FOREIGN TABLE relation_expr alter_table_cmds
4903 : {
4904 43 : AlterTableStmt *n = makeNode(AlterTableStmt);
4905 43 : n->relation = $4;
4906 43 : n->cmds = $5;
4907 43 : n->relkind = OBJECT_FOREIGN_TABLE;
4908 43 : n->missing_ok = false;
4909 43 : $$ = (Node *)n;
4910 : }
4911 : | ALTER FOREIGN TABLE IF_P EXISTS relation_expr alter_table_cmds
4912 : {
4913 18 : AlterTableStmt *n = makeNode(AlterTableStmt);
4914 18 : n->relation = $6;
4915 18 : n->cmds = $7;
4916 18 : n->relkind = OBJECT_FOREIGN_TABLE;
4917 18 : n->missing_ok = true;
4918 18 : $$ = (Node *)n;
4919 : }
4920 : ;
4921 :
4922 : /*****************************************************************************
4923 : *
4924 : * QUERY:
4925 : * IMPORT FOREIGN SCHEMA remote_schema
4926 : * [ { LIMIT TO | EXCEPT } ( table_list ) ]
4927 : * FROM SERVER server_name INTO local_schema [ OPTIONS (...) ]
4928 : *
4929 : ****************************************************************************/
4930 :
4931 : ImportForeignSchemaStmt:
4932 : IMPORT_P FOREIGN SCHEMA name import_qualification
4933 : FROM SERVER name INTO name create_generic_options
4934 : {
4935 4 : ImportForeignSchemaStmt *n = makeNode(ImportForeignSchemaStmt);
4936 4 : n->server_name = $8;
4937 4 : n->remote_schema = $4;
4938 4 : n->local_schema = $10;
4939 4 : n->list_type = $5->type;
4940 4 : n->table_list = $5->table_names;
4941 4 : n->options = $11;
4942 4 : $$ = (Node *) n;
4943 : }
4944 : ;
4945 :
4946 : import_qualification_type:
4947 1 : LIMIT TO { $$ = FDW_IMPORT_SCHEMA_LIMIT_TO; }
4948 2 : | EXCEPT { $$ = FDW_IMPORT_SCHEMA_EXCEPT; }
4949 : ;
4950 :
4951 : import_qualification:
4952 : import_qualification_type '(' relation_expr_list ')'
4953 : {
4954 3 : ImportQual *n = (ImportQual *) palloc(sizeof(ImportQual));
4955 3 : n->type = $1;
4956 3 : n->table_names = $3;
4957 3 : $$ = n;
4958 : }
4959 : | /*EMPTY*/
4960 : {
4961 1 : ImportQual *n = (ImportQual *) palloc(sizeof(ImportQual));
4962 1 : n->type = FDW_IMPORT_SCHEMA_ALL;
4963 1 : n->table_names = NIL;
4964 1 : $$ = n;
4965 : }
4966 : ;
4967 :
4968 : /*****************************************************************************
4969 : *
4970 : * QUERY:
4971 : * CREATE USER MAPPING FOR auth_ident SERVER name [OPTIONS]
4972 : *
4973 : *****************************************************************************/
4974 :
4975 : CreateUserMappingStmt: CREATE USER MAPPING FOR auth_ident SERVER name create_generic_options
4976 : {
4977 43 : CreateUserMappingStmt *n = makeNode(CreateUserMappingStmt);
4978 43 : n->user = $5;
4979 43 : n->servername = $7;
4980 43 : n->options = $8;
4981 43 : n->if_not_exists = false;
4982 43 : $$ = (Node *) n;
4983 : }
4984 : | CREATE USER MAPPING IF_P NOT EXISTS FOR auth_ident SERVER name create_generic_options
4985 : {
4986 1 : CreateUserMappingStmt *n = makeNode(CreateUserMappingStmt);
4987 1 : n->user = $8;
4988 1 : n->servername = $10;
4989 1 : n->options = $11;
4990 1 : n->if_not_exists = true;
4991 1 : $$ = (Node *) n;
4992 : }
4993 : ;
4994 :
4995 : /* User mapping authorization identifier */
4996 83 : auth_ident: RoleSpec { $$ = $1; }
4997 11 : | USER { $$ = makeRoleSpec(ROLESPEC_CURRENT_USER, @1); }
4998 : ;
4999 :
5000 : /*****************************************************************************
5001 : *
5002 : * QUERY :
5003 : * DROP USER MAPPING FOR auth_ident SERVER name
5004 : *
5005 : * XXX you'd think this should have a CASCADE/RESTRICT option, even if it's
5006 : * only pro forma; but the SQL standard doesn't show one.
5007 : ****************************************************************************/
5008 :
5009 : DropUserMappingStmt: DROP USER MAPPING FOR auth_ident SERVER name
5010 : {
5011 18 : DropUserMappingStmt *n = makeNode(DropUserMappingStmt);
5012 18 : n->user = $5;
5013 18 : n->servername = $7;
5014 18 : n->missing_ok = false;
5015 18 : $$ = (Node *) n;
5016 : }
5017 : | DROP USER MAPPING IF_P EXISTS FOR auth_ident SERVER name
5018 : {
5019 12 : DropUserMappingStmt *n = makeNode(DropUserMappingStmt);
5020 12 : n->user = $7;
5021 12 : n->servername = $9;
5022 12 : n->missing_ok = true;
5023 12 : $$ = (Node *) n;
5024 : }
5025 : ;
5026 :
5027 : /*****************************************************************************
5028 : *
5029 : * QUERY :
5030 : * ALTER USER MAPPING FOR auth_ident SERVER name OPTIONS
5031 : *
5032 : ****************************************************************************/
5033 :
5034 : AlterUserMappingStmt: ALTER USER MAPPING FOR auth_ident SERVER name alter_generic_options
5035 : {
5036 20 : AlterUserMappingStmt *n = makeNode(AlterUserMappingStmt);
5037 20 : n->user = $5;
5038 20 : n->servername = $7;
5039 20 : n->options = $8;
5040 20 : $$ = (Node *) n;
5041 : }
5042 : ;
5043 :
5044 : /*****************************************************************************
5045 : *
5046 : * QUERIES:
5047 : * CREATE POLICY name ON table
5048 : * [AS { PERMISSIVE | RESTRICTIVE } ]
5049 : * [FOR { SELECT | INSERT | UPDATE | DELETE } ]
5050 : * [TO role, ...]
5051 : * [USING (qual)] [WITH CHECK (with check qual)]
5052 : * ALTER POLICY name ON table [TO role, ...]
5053 : * [USING (qual)] [WITH CHECK (with check qual)]
5054 : *
5055 : *****************************************************************************/
5056 :
5057 : CreatePolicyStmt:
5058 : CREATE POLICY name ON qualified_name RowSecurityDefaultPermissive
5059 : RowSecurityDefaultForCmd RowSecurityDefaultToRole
5060 : RowSecurityOptionalExpr RowSecurityOptionalWithCheck
5061 : {
5062 81 : CreatePolicyStmt *n = makeNode(CreatePolicyStmt);
5063 81 : n->policy_name = $3;
5064 81 : n->table = $5;
5065 81 : n->permissive = $6;
5066 81 : n->cmd_name = $7;
5067 81 : n->roles = $8;
5068 81 : n->qual = $9;
5069 81 : n->with_check = $10;
5070 81 : $$ = (Node *) n;
5071 : }
5072 : ;
5073 :
5074 : AlterPolicyStmt:
5075 : ALTER POLICY name ON qualified_name RowSecurityOptionalToRole
5076 : RowSecurityOptionalExpr RowSecurityOptionalWithCheck
5077 : {
5078 14 : AlterPolicyStmt *n = makeNode(AlterPolicyStmt);
5079 14 : n->policy_name = $3;
5080 14 : n->table = $5;
5081 14 : n->roles = $6;
5082 14 : n->qual = $7;
5083 14 : n->with_check = $8;
5084 14 : $$ = (Node *) n;
5085 : }
5086 : ;
5087 :
5088 : RowSecurityOptionalExpr:
5089 88 : USING '(' a_expr ')' { $$ = $3; }
5090 7 : | /* EMPTY */ { $$ = NULL; }
5091 : ;
5092 :
5093 : RowSecurityOptionalWithCheck:
5094 12 : WITH CHECK '(' a_expr ')' { $$ = $4; }
5095 83 : | /* EMPTY */ { $$ = NULL; }
5096 : ;
5097 :
5098 : RowSecurityDefaultToRole:
5099 15 : TO role_list { $$ = $2; }
5100 66 : | /* EMPTY */ { $$ = list_make1(makeRoleSpec(ROLESPEC_PUBLIC, -1)); }
5101 : ;
5102 :
5103 : RowSecurityOptionalToRole:
5104 2 : TO role_list { $$ = $2; }
5105 12 : | /* EMPTY */ { $$ = NULL; }
5106 : ;
5107 :
5108 : RowSecurityDefaultPermissive:
5109 : AS IDENT
5110 : {
5111 8 : if (strcmp($2, "permissive") == 0)
5112 2 : $$ = true;
5113 6 : else if (strcmp($2, "restrictive") == 0)
5114 5 : $$ = false;
5115 : else
5116 1 : ereport(ERROR,
5117 : (errcode(ERRCODE_SYNTAX_ERROR),
5118 : errmsg("unrecognized row security option \"%s\"", $2),
5119 : errhint("Only PERMISSIVE or RESTRICTIVE policies are supported currently."),
5120 : parser_errposition(@2)));
5121 :
5122 : }
5123 74 : | /* EMPTY */ { $$ = true; }
5124 : ;
5125 :
5126 : RowSecurityDefaultForCmd:
5127 36 : FOR row_security_cmd { $$ = $2; }
5128 45 : | /* EMPTY */ { $$ = "all"; }
5129 : ;
5130 :
5131 : row_security_cmd:
5132 7 : ALL { $$ = "all"; }
5133 11 : | SELECT { $$ = "select"; }
5134 5 : | INSERT { $$ = "insert"; }
5135 8 : | UPDATE { $$ = "update"; }
5136 5 : | DELETE_P { $$ = "delete"; }
5137 : ;
5138 :
5139 : /*****************************************************************************
5140 : *
5141 : * QUERY:
5142 : * CREATE ACCESS METHOD name HANDLER handler_name
5143 : *
5144 : *****************************************************************************/
5145 :
5146 : CreateAmStmt: CREATE ACCESS METHOD name TYPE_P INDEX HANDLER handler_name
5147 : {
5148 1 : CreateAmStmt *n = makeNode(CreateAmStmt);
5149 1 : n->amname = $4;
5150 1 : n->handler_name = $8;
5151 1 : n->amtype = AMTYPE_INDEX;
5152 1 : $$ = (Node *) n;
5153 : }
5154 : ;
5155 :
5156 : /*****************************************************************************
5157 : *
5158 : * QUERIES :
5159 : * CREATE TRIGGER ...
5160 : *
5161 : *****************************************************************************/
5162 :
5163 : CreateTrigStmt:
5164 : CREATE TRIGGER name TriggerActionTime TriggerEvents ON
5165 : qualified_name TriggerReferencing TriggerForSpec TriggerWhen
5166 : EXECUTE PROCEDURE func_name '(' TriggerFuncArgs ')'
5167 : {
5168 207 : CreateTrigStmt *n = makeNode(CreateTrigStmt);
5169 207 : n->trigname = $3;
5170 207 : n->relation = $7;
5171 207 : n->funcname = $13;
5172 207 : n->args = $15;
5173 207 : n->row = $9;
5174 207 : n->timing = $4;
5175 207 : n->events = intVal(linitial($5));
5176 207 : n->columns = (List *) lsecond($5);
5177 207 : n->whenClause = $10;
5178 207 : n->transitionRels = $8;
5179 207 : n->isconstraint = FALSE;
5180 207 : n->deferrable = FALSE;
5181 207 : n->initdeferred = FALSE;
5182 207 : n->constrrel = NULL;
5183 207 : $$ = (Node *)n;
5184 : }
5185 : | CREATE CONSTRAINT TRIGGER name AFTER TriggerEvents ON
5186 : qualified_name OptConstrFromTable ConstraintAttributeSpec
5187 : FOR EACH ROW TriggerWhen
5188 : EXECUTE PROCEDURE func_name '(' TriggerFuncArgs ')'
5189 : {
5190 1 : CreateTrigStmt *n = makeNode(CreateTrigStmt);
5191 1 : n->trigname = $4;
5192 1 : n->relation = $8;
5193 1 : n->funcname = $17;
5194 1 : n->args = $19;
5195 1 : n->row = TRUE;
5196 1 : n->timing = TRIGGER_TYPE_AFTER;
5197 1 : n->events = intVal(linitial($6));
5198 1 : n->columns = (List *) lsecond($6);
5199 1 : n->whenClause = $14;
5200 1 : n->transitionRels = NIL;
5201 1 : n->isconstraint = TRUE;
5202 1 : processCASbits($10, @10, "TRIGGER",
5203 : &n->deferrable, &n->initdeferred, NULL,
5204 : NULL, yyscanner);
5205 1 : n->constrrel = $9;
5206 1 : $$ = (Node *)n;
5207 : }
5208 : ;
5209 :
5210 : TriggerActionTime:
5211 92 : BEFORE { $$ = TRIGGER_TYPE_BEFORE; }
5212 99 : | AFTER { $$ = TRIGGER_TYPE_AFTER; }
5213 18 : | INSTEAD OF { $$ = TRIGGER_TYPE_INSTEAD; }
5214 : ;
5215 :
5216 : TriggerEvents:
5217 : TriggerOneEvent
5218 210 : { $$ = $1; }
5219 : | TriggerEvents OR TriggerOneEvent
5220 : {
5221 79 : int events1 = intVal(linitial($1));
5222 79 : int events2 = intVal(linitial($3));
5223 79 : List *columns1 = (List *) lsecond($1);
5224 79 : List *columns2 = (List *) lsecond($3);
5225 :
5226 79 : if (events1 & events2)
5227 1 : parser_yyerror("duplicate trigger events specified");
5228 : /*
5229 : * concat'ing the columns lists loses information about
5230 : * which columns went with which event, but so long as
5231 : * only UPDATE carries columns and we disallow multiple
5232 : * UPDATE items, it doesn't matter. Command execution
5233 : * should just ignore the columns for non-UPDATE events.
5234 : */
5235 78 : $$ = list_make2(makeInteger(events1 | events2),
5236 : list_concat(columns1, columns2));
5237 : }
5238 : ;
5239 :
5240 : TriggerOneEvent:
5241 : INSERT
5242 109 : { $$ = list_make2(makeInteger(TRIGGER_TYPE_INSERT), NIL); }
5243 : | DELETE_P
5244 59 : { $$ = list_make2(makeInteger(TRIGGER_TYPE_DELETE), NIL); }
5245 : | UPDATE
5246 105 : { $$ = list_make2(makeInteger(TRIGGER_TYPE_UPDATE), NIL); }
5247 : | UPDATE OF columnList
5248 11 : { $$ = list_make2(makeInteger(TRIGGER_TYPE_UPDATE), $3); }
5249 : | TRUNCATE
5250 5 : { $$ = list_make2(makeInteger(TRIGGER_TYPE_TRUNCATE), NIL); }
5251 : ;
5252 :
5253 : TriggerReferencing:
5254 45 : REFERENCING TriggerTransitions { $$ = $2; }
5255 162 : | /*EMPTY*/ { $$ = NIL; }
5256 : ;
5257 :
5258 : TriggerTransitions:
5259 45 : TriggerTransition { $$ = list_make1($1); }
5260 14 : | TriggerTransitions TriggerTransition { $$ = lappend($1, $2); }
5261 : ;
5262 :
5263 : TriggerTransition:
5264 : TransitionOldOrNew TransitionRowOrTable opt_as TransitionRelName
5265 : {
5266 59 : TriggerTransition *n = makeNode(TriggerTransition);
5267 59 : n->name = $4;
5268 59 : n->isNew = $1;
5269 59 : n->isTable = $2;
5270 59 : $$ = (Node *)n;
5271 : }
5272 : ;
5273 :
5274 : TransitionOldOrNew:
5275 34 : NEW { $$ = TRUE; }
5276 25 : | OLD { $$ = FALSE; }
5277 : ;
5278 :
5279 : TransitionRowOrTable:
5280 59 : TABLE { $$ = TRUE; }
5281 : /*
5282 : * According to the standard, lack of a keyword here implies ROW.
5283 : * Support for that would require prohibiting ROW entirely here,
5284 : * reserving the keyword ROW, and/or requiring AS (instead of
5285 : * allowing it to be optional, as the standard specifies) as the
5286 : * next token. Requiring ROW seems cleanest and easiest to
5287 : * explain.
5288 : */
5289 0 : | ROW { $$ = FALSE; }
5290 : ;
5291 :
5292 : TransitionRelName:
5293 59 : ColId { $$ = $1; }
5294 : ;
5295 :
5296 : TriggerForSpec:
5297 : FOR TriggerForOptEach TriggerForType
5298 : {
5299 203 : $$ = $3;
5300 : }
5301 : | /* EMPTY */
5302 : {
5303 : /*
5304 : * If ROW/STATEMENT not specified, default to
5305 : * STATEMENT, per SQL
5306 : */
5307 4 : $$ = FALSE;
5308 : }
5309 : ;
5310 :
5311 : TriggerForOptEach:
5312 : EACH {}
5313 : | /*EMPTY*/ {}
5314 : ;
5315 :
5316 : TriggerForType:
5317 130 : ROW { $$ = TRUE; }
5318 73 : | STATEMENT { $$ = FALSE; }
5319 : ;
5320 :
5321 : TriggerWhen:
5322 13 : WHEN '(' a_expr ')' { $$ = $3; }
5323 195 : | /*EMPTY*/ { $$ = NULL; }
5324 : ;
5325 :
5326 : TriggerFuncArgs:
5327 71 : TriggerFuncArg { $$ = list_make1($1); }
5328 29 : | TriggerFuncArgs ',' TriggerFuncArg { $$ = lappend($1, $3); }
5329 137 : | /*EMPTY*/ { $$ = NIL; }
5330 : ;
5331 :
5332 : TriggerFuncArg:
5333 : Iconst
5334 : {
5335 5 : $$ = makeString(psprintf("%d", $1));
5336 : }
5337 0 : | FCONST { $$ = makeString($1); }
5338 89 : | Sconst { $$ = makeString($1); }
5339 6 : | ColLabel { $$ = makeString($1); }
5340 : ;
5341 :
5342 : OptConstrFromTable:
5343 0 : FROM qualified_name { $$ = $2; }
5344 1 : | /*EMPTY*/ { $$ = NULL; }
5345 : ;
5346 :
5347 : ConstraintAttributeSpec:
5348 : /*EMPTY*/
5349 336 : { $$ = 0; }
5350 : | ConstraintAttributeSpec ConstraintAttributeElem
5351 : {
5352 : /*
5353 : * We must complain about conflicting options.
5354 : * We could, but choose not to, complain about redundant
5355 : * options (ie, where $2's bit is already set in $1).
5356 : */
5357 55 : int newspec = $1 | $2;
5358 :
5359 : /* special message for this case */
5360 55 : if ((newspec & (CAS_NOT_DEFERRABLE | CAS_INITIALLY_DEFERRED)) == (CAS_NOT_DEFERRABLE | CAS_INITIALLY_DEFERRED))
5361 1 : ereport(ERROR,
5362 : (errcode(ERRCODE_SYNTAX_ERROR),
5363 : errmsg("constraint declared INITIALLY DEFERRED must be DEFERRABLE"),
5364 : parser_errposition(@2)));
5365 : /* generic message for other conflicts */
5366 108 : if ((newspec & (CAS_NOT_DEFERRABLE | CAS_DEFERRABLE)) == (CAS_NOT_DEFERRABLE | CAS_DEFERRABLE) ||
5367 54 : (newspec & (CAS_INITIALLY_IMMEDIATE | CAS_INITIALLY_DEFERRED)) == (CAS_INITIALLY_IMMEDIATE | CAS_INITIALLY_DEFERRED))
5368 0 : ereport(ERROR,
5369 : (errcode(ERRCODE_SYNTAX_ERROR),
5370 : errmsg("conflicting constraint properties"),
5371 : parser_errposition(@2)));
5372 54 : $$ = newspec;
5373 : }
5374 : ;
5375 :
5376 : ConstraintAttributeElem:
5377 6 : NOT DEFERRABLE { $$ = CAS_NOT_DEFERRABLE; }
5378 10 : | DEFERRABLE { $$ = CAS_DEFERRABLE; }
5379 3 : | INITIALLY IMMEDIATE { $$ = CAS_INITIALLY_IMMEDIATE; }
5380 6 : | INITIALLY DEFERRED { $$ = CAS_INITIALLY_DEFERRED; }
5381 16 : | NOT VALID { $$ = CAS_NOT_VALID; }
5382 14 : | NO INHERIT { $$ = CAS_NO_INHERIT; }
5383 : ;
5384 :
5385 :
5386 : /*****************************************************************************
5387 : *
5388 : * QUERIES :
5389 : * CREATE EVENT TRIGGER ...
5390 : * ALTER EVENT TRIGGER ...
5391 : *
5392 : *****************************************************************************/
5393 :
5394 : CreateEventTrigStmt:
5395 : CREATE EVENT TRIGGER name ON ColLabel
5396 : EXECUTE PROCEDURE func_name '(' ')'
5397 : {
5398 8 : CreateEventTrigStmt *n = makeNode(CreateEventTrigStmt);
5399 8 : n->trigname = $4;
5400 8 : n->eventname = $6;
5401 8 : n->whenclause = NULL;
5402 8 : n->funcname = $9;
5403 8 : $$ = (Node *)n;
5404 : }
5405 : | CREATE EVENT TRIGGER name ON ColLabel
5406 : WHEN event_trigger_when_list
5407 : EXECUTE PROCEDURE func_name '(' ')'
5408 : {
5409 13 : CreateEventTrigStmt *n = makeNode(CreateEventTrigStmt);
5410 13 : n->trigname = $4;
5411 13 : n->eventname = $6;
5412 13 : n->whenclause = $8;
5413 13 : n->funcname = $11;
5414 13 : $$ = (Node *)n;
5415 : }
5416 : ;
5417 :
5418 : event_trigger_when_list:
5419 : event_trigger_when_item
5420 13 : { $$ = list_make1($1); }
5421 : | event_trigger_when_list AND event_trigger_when_item
5422 1 : { $$ = lappend($1, $3); }
5423 : ;
5424 :
5425 : event_trigger_when_item:
5426 : ColId IN_P '(' event_trigger_value_list ')'
5427 14 : { $$ = makeDefElem($1, (Node *) $4, @1); }
5428 : ;
5429 :
5430 : event_trigger_value_list:
5431 : SCONST
5432 14 : { $$ = list_make1(makeString($1)); }
5433 : | event_trigger_value_list ',' SCONST
5434 11 : { $$ = lappend($1, makeString($3)); }
5435 : ;
5436 :
5437 : AlterEventTrigStmt:
5438 : ALTER EVENT TRIGGER name enable_trigger
5439 : {
5440 4 : AlterEventTrigStmt *n = makeNode(AlterEventTrigStmt);
5441 4 : n->trigname = $4;
5442 4 : n->tgenabled = $5;
5443 4 : $$ = (Node *) n;
5444 : }
5445 : ;
5446 :
5447 : enable_trigger:
5448 1 : ENABLE_P { $$ = TRIGGER_FIRES_ON_ORIGIN; }
5449 1 : | ENABLE_P REPLICA { $$ = TRIGGER_FIRES_ON_REPLICA; }
5450 1 : | ENABLE_P ALWAYS { $$ = TRIGGER_FIRES_ALWAYS; }
5451 1 : | DISABLE_P { $$ = TRIGGER_DISABLED; }
5452 : ;
5453 :
5454 : /*****************************************************************************
5455 : *
5456 : * QUERIES :
5457 : * CREATE ASSERTION ...
5458 : * DROP ASSERTION ...
5459 : *
5460 : *****************************************************************************/
5461 :
5462 : CreateAssertStmt:
5463 : CREATE ASSERTION name CHECK '(' a_expr ')'
5464 : ConstraintAttributeSpec
5465 : {
5466 0 : CreateTrigStmt *n = makeNode(CreateTrigStmt);
5467 0 : n->trigname = $3;
5468 0 : n->args = list_make1($6);
5469 0 : n->isconstraint = TRUE;
5470 0 : processCASbits($8, @8, "ASSERTION",
5471 : &n->deferrable, &n->initdeferred, NULL,
5472 : NULL, yyscanner);
5473 :
5474 0 : ereport(ERROR,
5475 : (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
5476 : errmsg("CREATE ASSERTION is not yet implemented")));
5477 :
5478 : $$ = (Node *)n;
5479 : }
5480 : ;
5481 :
5482 : DropAssertStmt:
5483 : DROP ASSERTION name opt_drop_behavior
5484 : {
5485 0 : DropStmt *n = makeNode(DropStmt);
5486 0 : n->objects = NIL;
5487 0 : n->behavior = $4;
5488 0 : n->removeType = OBJECT_TRIGGER; /* XXX */
5489 0 : ereport(ERROR,
5490 : (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
5491 : errmsg("DROP ASSERTION is not yet implemented")));
5492 : $$ = (Node *) n;
5493 : }
5494 : ;
5495 :
5496 :
5497 : /*****************************************************************************
5498 : *
5499 : * QUERY :
5500 : * define (aggregate,operator,type)
5501 : *
5502 : *****************************************************************************/
5503 :
5504 : DefineStmt:
5505 : CREATE AGGREGATE func_name aggr_args definition
5506 : {
5507 61 : DefineStmt *n = makeNode(DefineStmt);
5508 61 : n->kind = OBJECT_AGGREGATE;
5509 61 : n->oldstyle = false;
5510 61 : n->defnames = $3;
5511 61 : n->args = $4;
5512 61 : n->definition = $5;
5513 61 : $$ = (Node *)n;
5514 : }
5515 : | CREATE AGGREGATE func_name old_aggr_definition
5516 : {
5517 : /* old-style (pre-8.2) syntax for CREATE AGGREGATE */
5518 58 : DefineStmt *n = makeNode(DefineStmt);
5519 58 : n->kind = OBJECT_AGGREGATE;
5520 58 : n->oldstyle = true;
5521 58 : n->defnames = $3;
5522 58 : n->args = NIL;
5523 58 : n->definition = $4;
5524 58 : $$ = (Node *)n;
5525 : }
5526 : | CREATE OPERATOR any_operator definition
5527 : {
5528 38 : DefineStmt *n = makeNode(DefineStmt);
5529 38 : n->kind = OBJECT_OPERATOR;
5530 38 : n->oldstyle = false;
5531 38 : n->defnames = $3;
5532 38 : n->args = NIL;
5533 38 : n->definition = $4;
5534 38 : $$ = (Node *)n;
5535 : }
5536 : | CREATE TYPE_P any_name definition
5537 : {
5538 9 : DefineStmt *n = makeNode(DefineStmt);
5539 9 : n->kind = OBJECT_TYPE;
5540 9 : n->oldstyle = false;
5541 9 : n->defnames = $3;
5542 9 : n->args = NIL;
5543 9 : n->definition = $4;
5544 9 : $$ = (Node *)n;
5545 : }
5546 : | CREATE TYPE_P any_name
5547 : {
5548 : /* Shell type (identified by lack of definition) */
5549 9 : DefineStmt *n = makeNode(DefineStmt);
5550 9 : n->kind = OBJECT_TYPE;
5551 9 : n->oldstyle = false;
5552 9 : n->defnames = $3;
5553 9 : n->args = NIL;
5554 9 : n->definition = NIL;
5555 9 : $$ = (Node *)n;
5556 : }
5557 : | CREATE TYPE_P any_name AS '(' OptTableFuncElementList ')'
5558 : {
5559 51 : CompositeTypeStmt *n = makeNode(CompositeTypeStmt);
5560 :
5561 : /* can't use qualified_name, sigh */
5562 51 : n->typevar = makeRangeVarFromAnyName($3, @3, yyscanner);
5563 51 : n->coldeflist = $6;
5564 51 : $$ = (Node *)n;
5565 : }
5566 : | CREATE TYPE_P any_name AS ENUM_P '(' opt_enum_val_list ')'
5567 : {
5568 15 : CreateEnumStmt *n = makeNode(CreateEnumStmt);
5569 15 : n->typeName = $3;
5570 15 : n->vals = $7;
5571 15 : $$ = (Node *)n;
5572 : }
5573 : | CREATE TYPE_P any_name AS RANGE definition
5574 : {
5575 10 : CreateRangeStmt *n = makeNode(CreateRangeStmt);
5576 10 : n->typeName = $3;
5577 10 : n->params = $6;
5578 10 : $$ = (Node *)n;
5579 : }
5580 : | CREATE TEXT_P SEARCH PARSER any_name definition
5581 : {
5582 5 : DefineStmt *n = makeNode(DefineStmt);
5583 5 : n->kind = OBJECT_TSPARSER;
5584 5 : n->args = NIL;
5585 5 : n->defnames = $5;
5586 5 : n->definition = $6;
5587 5 : $$ = (Node *)n;
5588 : }
5589 : | CREATE TEXT_P SEARCH DICTIONARY any_name definition
5590 : {
5591 28 : DefineStmt *n = makeNode(DefineStmt);
5592 28 : n->kind = OBJECT_TSDICTIONARY;
5593 28 : n->args = NIL;
5594 28 : n->defnames = $5;
5595 28 : n->definition = $6;
5596 28 : $$ = (Node *)n;
5597 : }
5598 : | CREATE TEXT_P SEARCH TEMPLATE any_name definition
5599 : {
5600 6 : DefineStmt *n = makeNode(DefineStmt);
5601 6 : n->kind = OBJECT_TSTEMPLATE;
5602 6 : n->args = NIL;
5603 6 : n->defnames = $5;
5604 6 : n->definition = $6;
5605 6 : $$ = (Node *)n;
5606 : }
5607 : | CREATE TEXT_P SEARCH CONFIGURATION any_name definition
5608 : {
5609 26 : DefineStmt *n = makeNode(DefineStmt);
5610 26 : n->kind = OBJECT_TSCONFIGURATION;
5611 26 : n->args = NIL;
5612 26 : n->defnames = $5;
5613 26 : n->definition = $6;
5614 26 : $$ = (Node *)n;
5615 : }
5616 : | CREATE COLLATION any_name definition
5617 : {
5618 1 : DefineStmt *n = makeNode(DefineStmt);
5619 1 : n->kind = OBJECT_COLLATION;
5620 1 : n->args = NIL;
5621 1 : n->defnames = $3;
5622 1 : n->definition = $4;
5623 1 : $$ = (Node *)n;
5624 : }
5625 : | CREATE COLLATION IF_P NOT EXISTS any_name definition
5626 : {
5627 0 : DefineStmt *n = makeNode(DefineStmt);
5628 0 : n->kind = OBJECT_COLLATION;
5629 0 : n->args = NIL;
5630 0 : n->defnames = $6;
5631 0 : n->definition = $7;
5632 0 : n->if_not_exists = true;
5633 0 : $$ = (Node *)n;
5634 : }
5635 : | CREATE COLLATION any_name FROM any_name
5636 : {
5637 2 : DefineStmt *n = makeNode(DefineStmt);
5638 2 : n->kind = OBJECT_COLLATION;
5639 2 : n->args = NIL;
5640 2 : n->defnames = $3;
5641 2 : n->definition = list_make1(makeDefElem("from", (Node *) $5, @5));
5642 2 : $$ = (Node *)n;
5643 : }
5644 : | CREATE COLLATION IF_P NOT EXISTS any_name FROM any_name
5645 : {
5646 0 : DefineStmt *n = makeNode(DefineStmt);
5647 0 : n->kind = OBJECT_COLLATION;
5648 0 : n->args = NIL;
5649 0 : n->defnames = $6;
5650 0 : n->definition = list_make1(makeDefElem("from", (Node *) $8, @8));
5651 0 : n->if_not_exists = true;
5652 0 : $$ = (Node *)n;
5653 : }
5654 : ;
5655 :
5656 212 : definition: '(' def_list ')' { $$ = $2; }
5657 : ;
5658 :
5659 212 : def_list: def_elem { $$ = list_make1($1); }
5660 355 : | def_list ',' def_elem { $$ = lappend($1, $3); }
5661 : ;
5662 :
5663 : def_elem: ColLabel '=' def_arg
5664 : {
5665 551 : $$ = makeDefElem($1, (Node *) $3, @1);
5666 : }
5667 : | ColLabel
5668 : {
5669 16 : $$ = makeDefElem($1, NULL, @1);
5670 : }
5671 : ;
5672 :
5673 : /* Note: any simple identifier will be returned as a type name! */
5674 670 : def_arg: func_type { $$ = (Node *)$1; }
5675 55 : | reserved_keyword { $$ = (Node *)makeString(pstrdup($1)); }
5676 14 : | qual_all_Op { $$ = (Node *)$1; }
5677 32 : | NumericOnly { $$ = (Node *)$1; }
5678 87 : | Sconst { $$ = (Node *)makeString($1); }
5679 8 : | NONE { $$ = (Node *)makeString(pstrdup($1)); }
5680 : ;
5681 :
5682 58 : old_aggr_definition: '(' old_aggr_list ')' { $$ = $2; }
5683 : ;
5684 :
5685 58 : old_aggr_list: old_aggr_elem { $$ = list_make1($1); }
5686 206 : | old_aggr_list ',' old_aggr_elem { $$ = lappend($1, $3); }
5687 : ;
5688 :
5689 : /*
5690 : * Must use IDENT here to avoid reduce/reduce conflicts; fortunately none of
5691 : * the item names needed in old aggregate definitions are likely to become
5692 : * SQL keywords.
5693 : */
5694 : old_aggr_elem: IDENT '=' def_arg
5695 : {
5696 264 : $$ = makeDefElem($1, (Node *)$3, @1);
5697 : }
5698 : ;
5699 :
5700 : opt_enum_val_list:
5701 15 : enum_val_list { $$ = $1; }
5702 0 : | /*EMPTY*/ { $$ = NIL; }
5703 : ;
5704 :
5705 : enum_val_list: Sconst
5706 15 : { $$ = list_make1(makeString($1)); }
5707 : | enum_val_list ',' Sconst
5708 29 : { $$ = lappend($1, makeString($3)); }
5709 : ;
5710 :
5711 : /*****************************************************************************
5712 : *
5713 : * ALTER TYPE enumtype ADD ...
5714 : *
5715 : *****************************************************************************/
5716 :
5717 : AlterEnumStmt:
5718 : ALTER TYPE_P any_name ADD_P VALUE_P opt_if_not_exists Sconst
5719 : {
5720 9 : AlterEnumStmt *n = makeNode(AlterEnumStmt);
5721 9 : n->typeName = $3;
5722 9 : n->oldVal = NULL;
5723 9 : n->newVal = $7;
5724 9 : n->newValNeighbor = NULL;
5725 9 : n->newValIsAfter = true;
5726 9 : n->skipIfNewValExists = $6;
5727 9 : $$ = (Node *) n;
5728 : }
5729 : | ALTER TYPE_P any_name ADD_P VALUE_P opt_if_not_exists Sconst BEFORE Sconst
5730 : {
5731 32 : AlterEnumStmt *n = makeNode(AlterEnumStmt);
5732 32 : n->typeName = $3;
5733 32 : n->oldVal = NULL;
5734 32 : n->newVal = $7;
5735 32 : n->newValNeighbor = $9;
5736 32 : n->newValIsAfter = false;
5737 32 : n->skipIfNewValExists = $6;
5738 32 : $$ = (Node *) n;
5739 : }
5740 : | ALTER TYPE_P any_name ADD_P VALUE_P opt_if_not_exists Sconst AFTER Sconst
5741 : {
5742 3 : AlterEnumStmt *n = makeNode(AlterEnumStmt);
5743 3 : n->typeName = $3;
5744 3 : n->oldVal = NULL;
5745 3 : n->newVal = $7;
5746 3 : n->newValNeighbor = $9;
5747 3 : n->newValIsAfter = true;
5748 3 : n->skipIfNewValExists = $6;
5749 3 : $$ = (Node *) n;
5750 : }
5751 : | ALTER TYPE_P any_name RENAME VALUE_P Sconst TO Sconst
5752 : {
5753 3 : AlterEnumStmt *n = makeNode(AlterEnumStmt);
5754 3 : n->typeName = $3;
5755 3 : n->oldVal = $6;
5756 3 : n->newVal = $8;
5757 3 : n->newValNeighbor = NULL;
5758 3 : n->newValIsAfter = false;
5759 3 : n->skipIfNewValExists = false;
5760 3 : $$ = (Node *) n;
5761 : }
5762 : ;
5763 :
5764 2 : opt_if_not_exists: IF_P NOT EXISTS { $$ = true; }
5765 42 : | /* empty */ { $$ = false; }
5766 : ;
5767 :
5768 :
5769 : /*****************************************************************************
5770 : *
5771 : * QUERIES :
5772 : * CREATE OPERATOR CLASS ...
5773 : * CREATE OPERATOR FAMILY ...
5774 : * ALTER OPERATOR FAMILY ...
5775 : * DROP OPERATOR CLASS ...
5776 : * DROP OPERATOR FAMILY ...
5777 : *
5778 : *****************************************************************************/
5779 :
5780 : CreateOpClassStmt:
5781 : CREATE OPERATOR CLASS any_name opt_default FOR TYPE_P Typename
5782 : USING access_method opt_opfamily AS opclass_item_list
5783 : {
5784 6 : CreateOpClassStmt *n = makeNode(CreateOpClassStmt);
5785 6 : n->opclassname = $4;
5786 6 : n->isDefault = $5;
5787 6 : n->datatype = $8;
5788 6 : n->amname = $10;
5789 6 : n->opfamilyname = $11;
5790 6 : n->items = $13;
5791 6 : $$ = (Node *) n;
5792 : }
5793 : ;
5794 :
5795 : opclass_item_list:
5796 39 : opclass_item { $$ = list_make1($1); }
5797 49 : | opclass_item_list ',' opclass_item { $$ = lappend($1, $3); }
5798 : ;
5799 :
5800 : opclass_item:
5801 : OPERATOR Iconst any_operator opclass_purpose opt_recheck
5802 : {
5803 15 : CreateOpClassItem *n = makeNode(CreateOpClassItem);
5804 15 : ObjectWithArgs *owa = makeNode(ObjectWithArgs);
5805 15 : owa->objname = $3;
5806 15 : owa->objargs = NIL;
5807 15 : n->itemtype = OPCLASS_ITEM_OPERATOR;
5808 15 : n->name = owa;
5809 15 : n->number = $2;
5810 15 : n->order_family = $4;
5811 15 : $$ = (Node *) n;
5812 : }
5813 : | OPERATOR Iconst operator_with_argtypes opclass_purpose
5814 : opt_recheck
5815 : {
5816 45 : CreateOpClassItem *n = makeNode(CreateOpClassItem);
5817 45 : n->itemtype = OPCLASS_ITEM_OPERATOR;
5818 45 : n->name = $3;
5819 45 : n->number = $2;
5820 45 : n->order_family = $4;
5821 45 : $$ = (Node *) n;
5822 : }
5823 : | FUNCTION Iconst function_with_argtypes
5824 : {
5825 23 : CreateOpClassItem *n = makeNode(CreateOpClassItem);
5826 23 : n->itemtype = OPCLASS_ITEM_FUNCTION;
5827 23 : n->name = $3;
5828 23 : n->number = $2;
5829 23 : $$ = (Node *) n;
5830 : }
5831 : | FUNCTION Iconst '(' type_list ')' function_with_argtypes
5832 : {
5833 0 : CreateOpClassItem *n = makeNode(CreateOpClassItem);
5834 0 : n->itemtype = OPCLASS_ITEM_FUNCTION;
5835 0 : n->name = $6;
5836 0 : n->number = $2;
5837 0 : n->class_args = $4;
5838 0 : $$ = (Node *) n;
5839 : }
5840 : | STORAGE Typename
5841 : {
5842 5 : CreateOpClassItem *n = makeNode(CreateOpClassItem);
5843 5 : n->itemtype = OPCLASS_ITEM_STORAGETYPE;
5844 5 : n->storedtype = $2;
5845 5 : $$ = (Node *) n;
5846 : }
5847 : ;
5848 :
5849 136 : opt_default: DEFAULT { $$ = TRUE; }
5850 12 : | /*EMPTY*/ { $$ = FALSE; }
5851 : ;
5852 :
5853 0 : opt_opfamily: FAMILY any_name { $$ = $2; }
5854 6 : | /*EMPTY*/ { $$ = NIL; }
5855 : ;
5856 :
5857 0 : opclass_purpose: FOR SEARCH { $$ = NIL; }
5858 3 : | FOR ORDER BY any_name { $$ = $4; }
5859 57 : | /*EMPTY*/ { $$ = NIL; }
5860 : ;
5861 :
5862 : opt_recheck: RECHECK
5863 : {
5864 : /*
5865 : * RECHECK no longer does anything in opclass definitions,
5866 : * but we still accept it to ease porting of old database
5867 : * dumps.
5868 : */
5869 0 : ereport(NOTICE,
5870 : (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
5871 : errmsg("RECHECK is no longer required"),
5872 : errhint("Update your data type."),
5873 : parser_errposition(@1)));
5874 0 : $$ = TRUE;
5875 : }
5876 60 : | /*EMPTY*/ { $$ = FALSE; }
5877 : ;
5878 :
5879 :
5880 : CreateOpFamilyStmt:
5881 : CREATE OPERATOR FAMILY any_name USING access_method
5882 : {
5883 20 : CreateOpFamilyStmt *n = makeNode(CreateOpFamilyStmt);
5884 20 : n->opfamilyname = $4;
5885 20 : n->amname = $6;
5886 20 : $$ = (Node *) n;
5887 : }
5888 : ;
5889 :
5890 : AlterOpFamilyStmt:
5891 : ALTER OPERATOR FAMILY any_name USING access_method ADD_P opclass_item_list
5892 : {
5893 33 : AlterOpFamilyStmt *n = makeNode(AlterOpFamilyStmt);
5894 33 : n->opfamilyname = $4;
5895 33 : n->amname = $6;
5896 33 : n->isDrop = false;
5897 33 : n->items = $8;
5898 33 : $$ = (Node *) n;
5899 : }
5900 : | ALTER OPERATOR FAMILY any_name USING access_method DROP opclass_drop_list
5901 : {
5902 5 : AlterOpFamilyStmt *n = makeNode(AlterOpFamilyStmt);
5903 5 : n->opfamilyname = $4;
5904 5 : n->amname = $6;
5905 5 : n->isDrop = true;
5906 5 : n->items = $8;
5907 5 : $$ = (Node *) n;
5908 : }
5909 : ;
5910 :
5911 : opclass_drop_list:
5912 5 : opclass_drop { $$ = list_make1($1); }
5913 5 : | opclass_drop_list ',' opclass_drop { $$ = lappend($1, $3); }
5914 : ;
5915 :
5916 : opclass_drop:
5917 : OPERATOR Iconst '(' type_list ')'
5918 : {
5919 8 : CreateOpClassItem *n = makeNode(CreateOpClassItem);
5920 8 : n->itemtype = OPCLASS_ITEM_OPERATOR;
5921 8 : n->number = $2;
5922 8 : n->class_args = $4;
5923 8 : $$ = (Node *) n;
5924 : }
5925 : | FUNCTION Iconst '(' type_list ')'
5926 : {
5927 2 : CreateOpClassItem *n = makeNode(CreateOpClassItem);
5928 2 : n->itemtype = OPCLASS_ITEM_FUNCTION;
5929 2 : n->number = $2;
5930 2 : n->class_args = $4;
5931 2 : $$ = (Node *) n;
5932 : }
5933 : ;
5934 :
5935 :
5936 : DropOpClassStmt:
5937 : DROP OPERATOR CLASS any_name USING access_method opt_drop_behavior
5938 : {
5939 2 : DropStmt *n = makeNode(DropStmt);
5940 2 : n->objects = list_make1(lcons(makeString($6), $4));
5941 2 : n->removeType = OBJECT_OPCLASS;
5942 2 : n->behavior = $7;
5943 2 : n->missing_ok = false;
5944 2 : n->concurrent = false;
5945 2 : $$ = (Node *) n;
5946 : }
5947 : | DROP OPERATOR CLASS IF_P EXISTS any_name USING access_method opt_drop_behavior
5948 : {
5949 3 : DropStmt *n = makeNode(DropStmt);
5950 3 : n->objects = list_make1(lcons(makeString($8), $6));
5951 3 : n->removeType = OBJECT_OPCLASS;
5952 3 : n->behavior = $9;
5953 3 : n->missing_ok = true;
5954 3 : n->concurrent = false;
5955 3 : $$ = (Node *) n;
5956 : }
5957 : ;
5958 :
5959 : DropOpFamilyStmt:
5960 : DROP OPERATOR FAMILY any_name USING access_method opt_drop_behavior
5961 : {
5962 17 : DropStmt *n = makeNode(DropStmt);
5963 17 : n->objects = list_make1(lcons(makeString($6), $4));
5964 17 : n->removeType = OBJECT_OPFAMILY;
5965 17 : n->behavior = $7;
5966 17 : n->missing_ok = false;
5967 17 : n->concurrent = false;
5968 17 : $$ = (Node *) n;
5969 : }
5970 : | DROP OPERATOR FAMILY IF_P EXISTS any_name USING access_method opt_drop_behavior
5971 : {
5972 3 : DropStmt *n = makeNode(DropStmt);
5973 3 : n->objects = list_make1(lcons(makeString($8), $6));
5974 3 : n->removeType = OBJECT_OPFAMILY;
5975 3 : n->behavior = $9;
5976 3 : n->missing_ok = true;
5977 3 : n->concurrent = false;
5978 3 : $$ = (Node *) n;
5979 : }
5980 : ;
5981 :
5982 :
5983 : /*****************************************************************************
5984 : *
5985 : * QUERY:
5986 : *
5987 : * DROP OWNED BY username [, username ...] [ RESTRICT | CASCADE ]
5988 : * REASSIGN OWNED BY username [, username ...] TO username
5989 : *
5990 : *****************************************************************************/
5991 : DropOwnedStmt:
5992 : DROP OWNED BY role_list opt_drop_behavior
5993 : {
5994 16 : DropOwnedStmt *n = makeNode(DropOwnedStmt);
5995 16 : n->roles = $4;
5996 16 : n->behavior = $5;
5997 16 : $$ = (Node *)n;
5998 : }
5999 : ;
6000 :
6001 : ReassignOwnedStmt:
6002 : REASSIGN OWNED BY role_list TO RoleSpec
6003 : {
6004 4 : ReassignOwnedStmt *n = makeNode(ReassignOwnedStmt);
6005 4 : n->roles = $4;
6006 4 : n->newrole = $6;
6007 4 : $$ = (Node *)n;
6008 : }
6009 : ;
6010 :
6011 : /*****************************************************************************
6012 : *
6013 : * QUERY:
6014 : *
6015 : * DROP itemtype [ IF EXISTS ] itemname [, itemname ...]
6016 : * [ RESTRICT | CASCADE ]
6017 : *
6018 : *****************************************************************************/
6019 :
6020 : DropStmt: DROP drop_type_any_name IF_P EXISTS any_name_list opt_drop_behavior
6021 : {
6022 47 : DropStmt *n = makeNode(DropStmt);
6023 47 : n->removeType = $2;
6024 47 : n->missing_ok = TRUE;
6025 47 : n->objects = $5;
6026 47 : n->behavior = $6;
6027 47 : n->concurrent = false;
6028 47 : $$ = (Node *)n;
6029 : }
6030 : | DROP drop_type_any_name any_name_list opt_drop_behavior
6031 : {
6032 792 : DropStmt *n = makeNode(DropStmt);
6033 792 : n->removeType = $2;
6034 792 : n->missing_ok = FALSE;
6035 792 : n->objects = $3;
6036 792 : n->behavior = $4;
6037 792 : n->concurrent = false;
6038 792 : $$ = (Node *)n;
6039 : }
6040 : | DROP drop_type_name IF_P EXISTS name_list opt_drop_behavior
6041 : {
6042 11 : DropStmt *n = makeNode(DropStmt);
6043 11 : n->removeType = $2;
6044 11 : n->missing_ok = TRUE;
6045 11 : n->objects = $5;
6046 11 : n->behavior = $6;
6047 11 : n->concurrent = false;
6048 11 : $$ = (Node *)n;
6049 : }
6050 : | DROP drop_type_name name_list opt_drop_behavior
6051 : {
6052 90 : DropStmt *n = makeNode(DropStmt);
6053 90 : n->removeType = $2;
6054 90 : n->missing_ok = FALSE;
6055 90 : n->objects = $3;
6056 90 : n->behavior = $4;
6057 90 : n->concurrent = false;
6058 90 : $$ = (Node *)n;
6059 : }
6060 : | DROP drop_type_name_on_any_name name ON any_name opt_drop_behavior
6061 : {
6062 94 : DropStmt *n = makeNode(DropStmt);
6063 94 : n->removeType = $2;
6064 94 : n->objects = list_make1(lappend($5, makeString($3)));
6065 94 : n->behavior = $6;
6066 94 : n->missing_ok = false;
6067 94 : n->concurrent = false;
6068 94 : $$ = (Node *) n;
6069 : }
6070 : | DROP drop_type_name_on_any_name IF_P EXISTS name ON any_name opt_drop_behavior
6071 : {
6072 8 : DropStmt *n = makeNode(DropStmt);
6073 8 : n->removeType = $2;
6074 8 : n->objects = list_make1(lappend($7, makeString($5)));
6075 8 : n->behavior = $8;
6076 8 : n->missing_ok = true;
6077 8 : n->concurrent = false;
6078 8 : $$ = (Node *) n;
6079 : }
6080 : | DROP TYPE_P type_name_list opt_drop_behavior
6081 : {
6082 41 : DropStmt *n = makeNode(DropStmt);
6083 41 : n->removeType = OBJECT_TYPE;
6084 41 : n->missing_ok = FALSE;
6085 41 : n->objects = $3;
6086 41 : n->behavior = $4;
6087 41 : n->concurrent = false;
6088 41 : $$ = (Node *) n;
6089 : }
6090 : | DROP TYPE_P IF_P EXISTS type_name_list opt_drop_behavior
6091 : {
6092 3 : DropStmt *n = makeNode(DropStmt);
6093 3 : n->removeType = OBJECT_TYPE;
6094 3 : n->missing_ok = TRUE;
6095 3 : n->objects = $5;
6096 3 : n->behavior = $6;
6097 3 : n->concurrent = false;
6098 3 : $$ = (Node *) n;
6099 : }
6100 : | DROP DOMAIN_P type_name_list opt_drop_behavior
6101 : {
6102 47 : DropStmt *n = makeNode(DropStmt);
6103 47 : n->removeType = OBJECT_DOMAIN;
6104 47 : n->missing_ok = FALSE;
6105 47 : n->objects = $3;
6106 47 : n->behavior = $4;
6107 47 : n->concurrent = false;
6108 47 : $$ = (Node *) n;
6109 : }
6110 : | DROP DOMAIN_P IF_P EXISTS type_name_list opt_drop_behavior
6111 : {
6112 3 : DropStmt *n = makeNode(DropStmt);
6113 3 : n->removeType = OBJECT_DOMAIN;
6114 3 : n->missing_ok = TRUE;
6115 3 : n->objects = $5;
6116 3 : n->behavior = $6;
6117 3 : n->concurrent = false;
6118 3 : $$ = (Node *) n;
6119 : }
6120 : | DROP INDEX CONCURRENTLY any_name_list opt_drop_behavior
6121 : {
6122 7 : DropStmt *n = makeNode(DropStmt);
6123 7 : n->removeType = OBJECT_INDEX;
6124 7 : n->missing_ok = FALSE;
6125 7 : n->objects = $4;
6126 7 : n->behavior = $5;
6127 7 : n->concurrent = true;
6128 7 : $$ = (Node *)n;
6129 : }
6130 : | DROP INDEX CONCURRENTLY IF_P EXISTS any_name_list opt_drop_behavior
6131 : {
6132 2 : DropStmt *n = makeNode(DropStmt);
6133 2 : n->removeType = OBJECT_INDEX;
6134 2 : n->missing_ok = TRUE;
6135 2 : n->objects = $6;
6136 2 : n->behavior = $7;
6137 2 : n->concurrent = true;
6138 2 : $$ = (Node *)n;
6139 : }
6140 : ;
6141 :
6142 : /* object types taking any_name_list */
6143 : drop_type_any_name:
6144 636 : TABLE { $$ = OBJECT_TABLE; }
6145 23 : | SEQUENCE { $$ = OBJECT_SEQUENCE; }
6146 83 : | VIEW { $$ = OBJECT_VIEW; }
6147 5 : | MATERIALIZED VIEW { $$ = OBJECT_MATVIEW; }
6148 57 : | INDEX { $$ = OBJECT_INDEX; }
6149 10 : | FOREIGN TABLE { $$ = OBJECT_FOREIGN_TABLE; }
6150 4 : | COLLATION { $$ = OBJECT_COLLATION; }
6151 6 : | CONVERSION_P { $$ = OBJECT_CONVERSION; }
6152 4 : | STATISTICS { $$ = OBJECT_STATISTIC_EXT; }
6153 3 : | TEXT_P SEARCH PARSER { $$ = OBJECT_TSPARSER; }
6154 4 : | TEXT_P SEARCH DICTIONARY { $$ = OBJECT_TSDICTIONARY; }
6155 3 : | TEXT_P SEARCH TEMPLATE { $$ = OBJECT_TSTEMPLATE; }
6156 4 : | TEXT_P SEARCH CONFIGURATION { $$ = OBJECT_TSCONFIGURATION; }
6157 : ;
6158 :
6159 : /* object types taking name_list */
6160 : drop_type_name:
6161 4 : ACCESS METHOD { $$ = OBJECT_ACCESS_METHOD; }
6162 12 : | EVENT TRIGGER { $$ = OBJECT_EVENT_TRIGGER; }
6163 2 : | EXTENSION { $$ = OBJECT_EXTENSION; }
6164 20 : | FOREIGN DATA_P WRAPPER { $$ = OBJECT_FDW; }
6165 7 : | PUBLICATION { $$ = OBJECT_PUBLICATION; }
6166 39 : | SCHEMA { $$ = OBJECT_SCHEMA; }
6167 17 : | SERVER { $$ = OBJECT_FOREIGN_SERVER; }
6168 : ;
6169 :
6170 : /* object types attached to a table */
6171 : drop_type_name_on_any_name:
6172 17 : POLICY { $$ = OBJECT_POLICY; }
6173 33 : | RULE { $$ = OBJECT_RULE; }
6174 54 : | TRIGGER { $$ = OBJECT_TRIGGER; }
6175 : ;
6176 :
6177 : any_name_list:
6178 911 : any_name { $$ = list_make1($1); }
6179 108 : | any_name_list ',' any_name { $$ = lappend($1, $3); }
6180 : ;
6181 :
6182 2045 : any_name: ColId { $$ = list_make1(makeString($1)); }
6183 388 : | ColId attrs { $$ = lcons(makeString($1), $2); }
6184 : ;
6185 :
6186 : attrs: '.' attr_name
6187 2668 : { $$ = list_make1(makeString($2)); }
6188 : | attrs '.' attr_name
6189 0 : { $$ = lappend($1, makeString($3)); }
6190 : ;
6191 :
6192 : type_name_list:
6193 94 : Typename { $$ = list_make1($1); }
6194 0 : | type_name_list ',' Typename { $$ = lappend($1, $3); }
6195 :
6196 : /*****************************************************************************
6197 : *
6198 : * QUERY:
6199 : * truncate table relname1, relname2, ...
6200 : *
6201 : *****************************************************************************/
6202 :
6203 : TruncateStmt:
6204 : TRUNCATE opt_table relation_expr_list opt_restart_seqs opt_drop_behavior
6205 : {
6206 70 : TruncateStmt *n = makeNode(TruncateStmt);
6207 70 : n->relations = $3;
6208 70 : n->restart_seqs = $4;
6209 70 : n->behavior = $5;
6210 70 : $$ = (Node *)n;
6211 : }
6212 : ;
6213 :
6214 : opt_restart_seqs:
6215 0 : CONTINUE_P IDENTITY_P { $$ = false; }
6216 3 : | RESTART IDENTITY_P { $$ = true; }
6217 67 : | /* EMPTY */ { $$ = false; }
6218 : ;
6219 :
6220 : /*****************************************************************************
6221 : *
6222 : * The COMMENT ON statement can take different forms based upon the type of
6223 : * the object associated with the comment. The form of the statement is:
6224 : *
6225 : * COMMENT ON [ [ ACCESS METHOD | CONVERSION | COLLATION |
6226 : * DATABASE | DOMAIN |
6227 : * EXTENSION | EVENT TRIGGER | FOREIGN DATA WRAPPER |
6228 : * FOREIGN TABLE | INDEX | [PROCEDURAL] LANGUAGE |
6229 : * MATERIALIZED VIEW | POLICY | ROLE | SCHEMA | SEQUENCE |
6230 : * SERVER | STATISTICS | TABLE | TABLESPACE |
6231 : * TEXT SEARCH CONFIGURATION | TEXT SEARCH DICTIONARY |
6232 : * TEXT SEARCH PARSER | TEXT SEARCH TEMPLATE | TYPE |
6233 : * VIEW] <objname> |
6234 : * AGGREGATE <aggname> (arg1, ...) |
6235 : * CAST (<src type> AS <dst type>) |
6236 : * COLUMN <relname>.<colname> |
6237 : * CONSTRAINT <constraintname> ON <relname> |
6238 : * CONSTRAINT <constraintname> ON DOMAIN <domainname> |
6239 : * FUNCTION <funcname> (arg1, arg2, ...) |
6240 : * LARGE OBJECT <oid> |
6241 : * OPERATOR <op> (leftoperand_typ, rightoperand_typ) |
6242 : * OPERATOR CLASS <name> USING <access-method> |
6243 : * OPERATOR FAMILY <name> USING <access-method> |
6244 : * RULE <rulename> ON <relname> |
6245 : * TRIGGER <triggername> ON <relname> ]
6246 : * IS { 'text' | NULL }
6247 : *
6248 : *****************************************************************************/
6249 :
6250 : CommentStmt:
6251 : COMMENT ON comment_type_any_name any_name IS comment_text
6252 : {
6253 204 : CommentStmt *n = makeNode(CommentStmt);
6254 204 : n->objtype = $3;
6255 204 : n->object = (Node *) $4;
6256 204 : n->comment = $6;
6257 204 : $$ = (Node *) n;
6258 : }
6259 : | COMMENT ON comment_type_name name IS comment_text
6260 : {
6261 8 : CommentStmt *n = makeNode(CommentStmt);
6262 8 : n->objtype = $3;
6263 8 : n->object = (Node *) makeString($4);
6264 8 : n->comment = $6;
6265 8 : $$ = (Node *) n;
6266 : }
6267 : | COMMENT ON TYPE_P Typename IS comment_text
6268 : {
6269 3 : CommentStmt *n = makeNode(CommentStmt);
6270 3 : n->objtype = OBJECT_TYPE;
6271 3 : n->object = (Node *) $4;
6272 3 : n->comment = $6;
6273 3 : $$ = (Node *) n;
6274 : }
6275 : | COMMENT ON DOMAIN_P Typename IS comment_text
6276 : {
6277 1 : CommentStmt *n = makeNode(CommentStmt);
6278 1 : n->objtype = OBJECT_DOMAIN;
6279 1 : n->object = (Node *) $4;
6280 1 : n->comment = $6;
6281 1 : $$ = (Node *) n;
6282 : }
6283 : | COMMENT ON AGGREGATE aggregate_with_argtypes IS comment_text
6284 : {
6285 6 : CommentStmt *n = makeNode(CommentStmt);
6286 6 : n->objtype = OBJECT_AGGREGATE;
6287 6 : n->object = (Node *) $4;
6288 6 : n->comment = $6;
6289 6 : $$ = (Node *) n;
6290 : }
6291 : | COMMENT ON FUNCTION function_with_argtypes IS comment_text
6292 : {
6293 137 : CommentStmt *n = makeNode(CommentStmt);
6294 137 : n->objtype = OBJECT_FUNCTION;
6295 137 : n->object = (Node *) $4;
6296 137 : n->comment = $6;
6297 137 : $$ = (Node *) n;
6298 : }
6299 : | COMMENT ON OPERATOR operator_with_argtypes IS comment_text
6300 : {
6301 1 : CommentStmt *n = makeNode(CommentStmt);
6302 1 : n->objtype = OBJECT_OPERATOR;
6303 1 : n->object = (Node *) $4;
6304 1 : n->comment = $6;
6305 1 : $$ = (Node *) n;
6306 : }
6307 : | COMMENT ON CONSTRAINT name ON any_name IS comment_text
6308 : {
6309 12 : CommentStmt *n = makeNode(CommentStmt);
6310 12 : n->objtype = OBJECT_TABCONSTRAINT;
6311 12 : n->object = (Node *) lappend($6, makeString($4));
6312 12 : n->comment = $8;
6313 12 : $$ = (Node *) n;
6314 : }
6315 : | COMMENT ON CONSTRAINT name ON DOMAIN_P any_name IS comment_text
6316 : {
6317 4 : CommentStmt *n = makeNode(CommentStmt);
6318 4 : n->objtype = OBJECT_DOMCONSTRAINT;
6319 : /*
6320 : * should use Typename not any_name in the production, but
6321 : * there's a shift/reduce conflict if we do that, so fix it
6322 : * up here.
6323 : */
6324 4 : n->object = (Node *) list_make2(makeTypeNameFromNameList($7), makeString($4));
6325 4 : n->comment = $9;
6326 4 : $$ = (Node *) n;
6327 : }
6328 : | COMMENT ON POLICY name ON any_name IS comment_text
6329 : {
6330 0 : CommentStmt *n = makeNode(CommentStmt);
6331 0 : n->objtype = OBJECT_POLICY;
6332 0 : n->object = (Node *) lappend($6, makeString($4));
6333 0 : n->comment = $8;
6334 0 : $$ = (Node *) n;
6335 : }
6336 : | COMMENT ON RULE name ON any_name IS comment_text
6337 : {
6338 3 : CommentStmt *n = makeNode(CommentStmt);
6339 3 : n->objtype = OBJECT_RULE;
6340 3 : n->object = (Node *) lappend($6, makeString($4));
6341 3 : n->comment = $8;
6342 3 : $$ = (Node *) n;
6343 : }
6344 : | COMMENT ON TRANSFORM FOR Typename LANGUAGE name IS comment_text
6345 : {
6346 0 : CommentStmt *n = makeNode(CommentStmt);
6347 0 : n->objtype = OBJECT_TRANSFORM;
6348 0 : n->object = (Node *) list_make2($5, makeString($7));
6349 0 : n->comment = $9;
6350 0 : $$ = (Node *) n;
6351 : }
6352 : | COMMENT ON TRIGGER name ON any_name IS comment_text
6353 : {
6354 3 : CommentStmt *n = makeNode(CommentStmt);
6355 3 : n->objtype = OBJECT_TRIGGER;
6356 3 : n->object = (Node *) lappend($6, makeString($4));
6357 3 : n->comment = $8;
6358 3 : $$ = (Node *) n;
6359 : }
6360 : | COMMENT ON OPERATOR CLASS any_name USING access_method IS comment_text
6361 : {
6362 0 : CommentStmt *n = makeNode(CommentStmt);
6363 0 : n->objtype = OBJECT_OPCLASS;
6364 0 : n->object = (Node *) lcons(makeString($7), $5);
6365 0 : n->comment = $9;
6366 0 : $$ = (Node *) n;
6367 : }
6368 : | COMMENT ON OPERATOR FAMILY any_name USING access_method IS comment_text
6369 : {
6370 0 : CommentStmt *n = makeNode(CommentStmt);
6371 0 : n->objtype = OBJECT_OPFAMILY;
6372 0 : n->object = (Node *) lcons(makeString($7), $5);
6373 0 : n->comment = $9;
6374 0 : $$ = (Node *) n;
6375 : }
6376 : | COMMENT ON LARGE_P OBJECT_P NumericOnly IS comment_text
6377 : {
6378 2 : CommentStmt *n = makeNode(CommentStmt);
6379 2 : n->objtype = OBJECT_LARGEOBJECT;
6380 2 : n->object = (Node *) $5;
6381 2 : n->comment = $7;
6382 2 : $$ = (Node *) n;
6383 : }
6384 : | COMMENT ON CAST '(' Typename AS Typename ')' IS comment_text
6385 : {
6386 0 : CommentStmt *n = makeNode(CommentStmt);
6387 0 : n->objtype = OBJECT_CAST;
6388 0 : n->object = (Node *) list_make2($5, $7);
6389 0 : n->comment = $10;
6390 0 : $$ = (Node *) n;
6391 : }
6392 : ;
6393 :
6394 : /* object types taking any_name */
6395 : comment_type_any_name:
6396 16 : COLUMN { $$ = OBJECT_COLUMN; }
6397 8 : | INDEX { $$ = OBJECT_INDEX; }
6398 3 : | SEQUENCE { $$ = OBJECT_SEQUENCE; }
6399 0 : | STATISTICS { $$ = OBJECT_STATISTIC_EXT; }
6400 5 : | TABLE { $$ = OBJECT_TABLE; }
6401 3 : | VIEW { $$ = OBJECT_VIEW; }
6402 0 : | MATERIALIZED VIEW { $$ = OBJECT_MATVIEW; }
6403 0 : | COLLATION { $$ = OBJECT_COLLATION; }
6404 135 : | CONVERSION_P { $$ = OBJECT_CONVERSION; }
6405 3 : | FOREIGN TABLE { $$ = OBJECT_FOREIGN_TABLE; }
6406 15 : | TEXT_P SEARCH CONFIGURATION { $$ = OBJECT_TSCONFIGURATION; }
6407 15 : | TEXT_P SEARCH DICTIONARY { $$ = OBJECT_TSDICTIONARY; }
6408 0 : | TEXT_P SEARCH PARSER { $$ = OBJECT_TSPARSER; }
6409 1 : | TEXT_P SEARCH TEMPLATE { $$ = OBJECT_TSTEMPLATE; }
6410 : ;
6411 :
6412 : /* object types taking name */
6413 : comment_type_name:
6414 0 : ACCESS METHOD { $$ = OBJECT_ACCESS_METHOD; }
6415 2 : | DATABASE { $$ = OBJECT_DATABASE; }
6416 1 : | EVENT TRIGGER { $$ = OBJECT_EVENT_TRIGGER; }
6417 0 : | EXTENSION { $$ = OBJECT_EXTENSION; }
6418 1 : | FOREIGN DATA_P WRAPPER { $$ = OBJECT_FDW; }
6419 1 : | opt_procedural LANGUAGE { $$ = OBJECT_LANGUAGE; }
6420 1 : | PUBLICATION { $$ = OBJECT_PUBLICATION; }
6421 0 : | ROLE { $$ = OBJECT_ROLE; }
6422 0 : | SCHEMA { $$ = OBJECT_SCHEMA; }
6423 1 : | SERVER { $$ = OBJECT_FOREIGN_SERVER; }
6424 1 : | SUBSCRIPTION { $$ = OBJECT_SUBSCRIPTION; }
6425 0 : | TABLESPACE { $$ = OBJECT_TABLESPACE; }
6426 : ;
6427 :
6428 : comment_text:
6429 368 : Sconst { $$ = $1; }
6430 16 : | NULL_P { $$ = NULL; }
6431 : ;
6432 :
6433 :
6434 : /*****************************************************************************
6435 : *
6436 : * SECURITY LABEL [FOR <provider>] ON <object> IS <label>
6437 : *
6438 : * As with COMMENT ON, <object> can refer to various types of database
6439 : * objects (e.g. TABLE, COLUMN, etc.).
6440 : *
6441 : *****************************************************************************/
6442 :
6443 : SecLabelStmt:
6444 : SECURITY LABEL opt_provider ON security_label_type_any_name any_name
6445 : IS security_label
6446 : {
6447 4 : SecLabelStmt *n = makeNode(SecLabelStmt);
6448 4 : n->provider = $3;
6449 4 : n->objtype = $5;
6450 4 : n->object = (Node *) $6;
6451 4 : n->label = $8;
6452 4 : $$ = (Node *) n;
6453 : }
6454 : | SECURITY LABEL opt_provider ON security_label_type_name name
6455 : IS security_label
6456 : {
6457 4 : SecLabelStmt *n = makeNode(SecLabelStmt);
6458 4 : n->provider = $3;
6459 4 : n->objtype = $5;
6460 4 : n->object = (Node *) makeString($6);
6461 4 : n->label = $8;
6462 4 : $$ = (Node *) n;
6463 : }
6464 : | SECURITY LABEL opt_provider ON TYPE_P Typename
6465 : IS security_label
6466 : {
6467 0 : SecLabelStmt *n = makeNode(SecLabelStmt);
6468 0 : n->provider = $3;
6469 0 : n->objtype = OBJECT_TYPE;
6470 0 : n->object = (Node *) $6;
6471 0 : n->label = $8;
6472 0 : $$ = (Node *) n;
6473 : }
6474 : | SECURITY LABEL opt_provider ON DOMAIN_P Typename
6475 : IS security_label
6476 : {
6477 0 : SecLabelStmt *n = makeNode(SecLabelStmt);
6478 0 : n->provider = $3;
6479 0 : n->objtype = OBJECT_DOMAIN;
6480 0 : n->object = (Node *) $6;
6481 0 : n->label = $8;
6482 0 : $$ = (Node *) n;
6483 : }
6484 : | SECURITY LABEL opt_provider ON AGGREGATE aggregate_with_argtypes
6485 : IS security_label
6486 : {
6487 0 : SecLabelStmt *n = makeNode(SecLabelStmt);
6488 0 : n->provider = $3;
6489 0 : n->objtype = OBJECT_AGGREGATE;
6490 0 : n->object = (Node *) $6;
6491 0 : n->label = $8;
6492 0 : $$ = (Node *) n;
6493 : }
6494 : | SECURITY LABEL opt_provider ON FUNCTION function_with_argtypes
6495 : IS security_label
6496 : {
6497 0 : SecLabelStmt *n = makeNode(SecLabelStmt);
6498 0 : n->provider = $3;
6499 0 : n->objtype = OBJECT_FUNCTION;
6500 0 : n->object = (Node *) $6;
6501 0 : n->label = $8;
6502 0 : $$ = (Node *) n;
6503 : }
6504 : | SECURITY LABEL opt_provider ON LARGE_P OBJECT_P NumericOnly
6505 : IS security_label
6506 : {
6507 0 : SecLabelStmt *n = makeNode(SecLabelStmt);
6508 0 : n->provider = $3;
6509 0 : n->objtype = OBJECT_LARGEOBJECT;
6510 0 : n->object = (Node *) $7;
6511 0 : n->label = $9;
6512 0 : $$ = (Node *) n;
6513 : }
6514 : ;
6515 :
6516 2 : opt_provider: FOR NonReservedWord_or_Sconst { $$ = $2; }
6517 6 : | /* empty */ { $$ = NULL; }
6518 : ;
6519 :
6520 : /* object types taking any_name */
6521 : security_label_type_any_name:
6522 0 : COLUMN { $$ = OBJECT_COLUMN; }
6523 0 : | FOREIGN TABLE { $$ = OBJECT_FOREIGN_TABLE; }
6524 0 : | SEQUENCE { $$ = OBJECT_SEQUENCE; }
6525 4 : | TABLE { $$ = OBJECT_TABLE; }
6526 0 : | VIEW { $$ = OBJECT_VIEW; }
6527 0 : | MATERIALIZED VIEW { $$ = OBJECT_MATVIEW; }
6528 : ;
6529 :
6530 : /* object types taking name */
6531 : security_label_type_name:
6532 0 : DATABASE { $$ = OBJECT_DATABASE; }
6533 0 : | EVENT TRIGGER { $$ = OBJECT_EVENT_TRIGGER; }
6534 0 : | opt_procedural LANGUAGE { $$ = OBJECT_LANGUAGE; }
6535 0 : | PUBLICATION { $$ = OBJECT_PUBLICATION; }
6536 4 : | ROLE { $$ = OBJECT_ROLE; }
6537 0 : | SCHEMA { $$ = OBJECT_SCHEMA; }
6538 0 : | SUBSCRIPTION { $$ = OBJECT_SUBSCRIPTION; }
6539 0 : | TABLESPACE { $$ = OBJECT_TABLESPACE; }
6540 : ;
6541 :
6542 8 : security_label: Sconst { $$ = $1; }
6543 0 : | NULL_P { $$ = NULL; }
6544 : ;
6545 :
6546 : /*****************************************************************************
6547 : *
6548 : * QUERY:
6549 : * fetch/move
6550 : *
6551 : *****************************************************************************/
6552 :
6553 : FetchStmt: FETCH fetch_args
6554 : {
6555 197 : FetchStmt *n = (FetchStmt *) $2;
6556 197 : n->ismove = FALSE;
6557 197 : $$ = (Node *)n;
6558 : }
6559 : | MOVE fetch_args
6560 : {
6561 6 : FetchStmt *n = (FetchStmt *) $2;
6562 6 : n->ismove = TRUE;
6563 6 : $$ = (Node *)n;
6564 : }
6565 : ;
6566 :
6567 : fetch_args: cursor_name
6568 : {
6569 8 : FetchStmt *n = makeNode(FetchStmt);
6570 8 : n->portalname = $1;
6571 8 : n->direction = FETCH_FORWARD;
6572 8 : n->howMany = 1;
6573 8 : $$ = (Node *)n;
6574 : }
6575 : | from_in cursor_name
6576 : {
6577 10 : FetchStmt *n = makeNode(FetchStmt);
6578 10 : n->portalname = $2;
6579 10 : n->direction = FETCH_FORWARD;
6580 10 : n->howMany = 1;
6581 10 : $$ = (Node *)n;
6582 : }
6583 : | NEXT opt_from_in cursor_name
6584 : {
6585 21 : FetchStmt *n = makeNode(FetchStmt);
6586 21 : n->portalname = $3;
6587 21 : n->direction = FETCH_FORWARD;
6588 21 : n->howMany = 1;
6589 21 : $$ = (Node *)n;
6590 : }
6591 : | PRIOR opt_from_in cursor_name
6592 : {
6593 4 : FetchStmt *n = makeNode(FetchStmt);
6594 4 : n->portalname = $3;
6595 4 : n->direction = FETCH_BACKWARD;
6596 4 : n->howMany = 1;
6597 4 : $$ = (Node *)n;
6598 : }
6599 : | FIRST_P opt_from_in cursor_name
6600 : {
6601 3 : FetchStmt *n = makeNode(FetchStmt);
6602 3 : n->portalname = $3;
6603 3 : n->direction = FETCH_ABSOLUTE;
6604 3 : n->howMany = 1;
6605 3 : $$ = (Node *)n;
6606 : }
6607 : | LAST_P opt_from_in cursor_name
6608 : {
6609 0 : FetchStmt *n = makeNode(FetchStmt);
6610 0 : n->portalname = $3;
6611 0 : n->direction = FETCH_ABSOLUTE;
6612 0 : n->howMany = -1;
6613 0 : $$ = (Node *)n;
6614 : }
6615 : | ABSOLUTE_P SignedIconst opt_from_in cursor_name
6616 : {
6617 4 : FetchStmt *n = makeNode(FetchStmt);
6618 4 : n->portalname = $4;
6619 4 : n->direction = FETCH_ABSOLUTE;
6620 4 : n->howMany = $2;
6621 4 : $$ = (Node *)n;
6622 : }
6623 : | RELATIVE_P SignedIconst opt_from_in cursor_name
6624 : {
6625 5 : FetchStmt *n = makeNode(FetchStmt);
6626 5 : n->portalname = $4;
6627 5 : n->direction = FETCH_RELATIVE;
6628 5 : n->howMany = $2;
6629 5 : $$ = (Node *)n;
6630 : }
6631 : | SignedIconst opt_from_in cursor_name
6632 : {
6633 44 : FetchStmt *n = makeNode(FetchStmt);
6634 44 : n->portalname = $3;
6635 44 : n->direction = FETCH_FORWARD;
6636 44 : n->howMany = $1;
6637 44 : $$ = (Node *)n;
6638 : }
6639 : | ALL opt_from_in cursor_name
6640 : {
6641 36 : FetchStmt *n = makeNode(FetchStmt);
6642 36 : n->portalname = $3;
6643 36 : n->direction = FETCH_FORWARD;
6644 36 : n->howMany = FETCH_ALL;
6645 36 : $$ = (Node *)n;
6646 : }
6647 : | FORWARD opt_from_in cursor_name
6648 : {
6649 0 : FetchStmt *n = makeNode(FetchStmt);
6650 0 : n->portalname = $3;
6651 0 : n->direction = FETCH_FORWARD;
6652 0 : n->howMany = 1;
6653 0 : $$ = (Node *)n;
6654 : }
6655 : | FORWARD SignedIconst opt_from_in cursor_name
6656 : {
6657 21 : FetchStmt *n = makeNode(FetchStmt);
6658 21 : n->portalname = $4;
6659 21 : n->direction = FETCH_FORWARD;
6660 21 : n->howMany = $2;
6661 21 : $$ = (Node *)n;
6662 : }
6663 : | FORWARD ALL opt_from_in cursor_name
6664 : {
6665 1 : FetchStmt *n = makeNode(FetchStmt);
6666 1 : n->portalname = $4;
6667 1 : n->direction = FETCH_FORWARD;
6668 1 : n->howMany = FETCH_ALL;
6669 1 : $$ = (Node *)n;
6670 : }
6671 : | BACKWARD opt_from_in cursor_name
6672 : {
6673 1 : FetchStmt *n = makeNode(FetchStmt);
6674 1 : n->portalname = $3;
6675 1 : n->direction = FETCH_BACKWARD;
6676 1 : n->howMany = 1;
6677 1 : $$ = (Node *)n;
6678 : }
6679 : | BACKWARD SignedIconst opt_from_in cursor_name
6680 : {
6681 34 : FetchStmt *n = makeNode(FetchStmt);
6682 34 : n->portalname = $4;
6683 34 : n->direction = FETCH_BACKWARD;
6684 34 : n->howMany = $2;
6685 34 : $$ = (Node *)n;
6686 : }
6687 : | BACKWARD ALL opt_from_in cursor_name
6688 : {
6689 11 : FetchStmt *n = makeNode(FetchStmt);
6690 11 : n->portalname = $4;
6691 11 : n->direction = FETCH_BACKWARD;
6692 11 : n->howMany = FETCH_ALL;
6693 11 : $$ = (Node *)n;
6694 : }
6695 : ;
6696 :
6697 : from_in: FROM {}
6698 : | IN_P {}
6699 : ;
6700 :
6701 : opt_from_in: from_in {}
6702 : | /* EMPTY */ {}
6703 : ;
6704 :
6705 :
6706 : /*****************************************************************************
6707 : *
6708 : * GRANT and REVOKE statements
6709 : *
6710 : *****************************************************************************/
6711 :
6712 : GrantStmt: GRANT privileges ON privilege_target TO grantee_list
6713 : opt_grant_grant_option
6714 : {
6715 246 : GrantStmt *n = makeNode(GrantStmt);
6716 246 : n->is_grant = true;
6717 246 : n->privileges = $2;
6718 246 : n->targtype = ($4)->targtype;
6719 246 : n->objtype = ($4)->objtype;
6720 246 : n->objects = ($4)->objs;
6721 246 : n->grantees = $6;
6722 246 : n->grant_option = $7;
6723 246 : $$ = (Node*)n;
6724 : }
6725 : ;
6726 :
6727 : RevokeStmt:
6728 : REVOKE privileges ON privilege_target
6729 : FROM grantee_list opt_drop_behavior
6730 : {
6731 112 : GrantStmt *n = makeNode(GrantStmt);
6732 112 : n->is_grant = false;
6733 112 : n->grant_option = false;
6734 112 : n->privileges = $2;
6735 112 : n->targtype = ($4)->targtype;
6736 112 : n->objtype = ($4)->objtype;
6737 112 : n->objects = ($4)->objs;
6738 112 : n->grantees = $6;
6739 112 : n->behavior = $7;
6740 112 : $$ = (Node *)n;
6741 : }
6742 : | REVOKE GRANT OPTION FOR privileges ON privilege_target
6743 : FROM grantee_list opt_drop_behavior
6744 : {
6745 1 : GrantStmt *n = makeNode(GrantStmt);
6746 1 : n->is_grant = false;
6747 1 : n->grant_option = true;
6748 1 : n->privileges = $5;
6749 1 : n->targtype = ($7)->targtype;
6750 1 : n->objtype = ($7)->objtype;
6751 1 : n->objects = ($7)->objs;
6752 1 : n->grantees = $9;
6753 1 : n->behavior = $10;
6754 1 : $$ = (Node *)n;
6755 : }
6756 : ;
6757 :
6758 :
6759 : /*
6760 : * Privilege names are represented as strings; the validity of the privilege
6761 : * names gets checked at execution. This is a bit annoying but we have little
6762 : * choice because of the syntactic conflict with lists of role names in
6763 : * GRANT/REVOKE. What's more, we have to call out in the "privilege"
6764 : * production any reserved keywords that need to be usable as privilege names.
6765 : */
6766 :
6767 : /* either ALL [PRIVILEGES] or a list of individual privileges */
6768 : privileges: privilege_list
6769 270 : { $$ = $1; }
6770 : | ALL
6771 76 : { $$ = NIL; }
6772 : | ALL PRIVILEGES
6773 36 : { $$ = NIL; }
6774 : | ALL '(' columnList ')'
6775 : {
6776 3 : AccessPriv *n = makeNode(AccessPriv);
6777 3 : n->priv_name = NULL;
6778 3 : n->cols = $3;
6779 3 : $$ = list_make1(n);
6780 : }
6781 : | ALL PRIVILEGES '(' columnList ')'
6782 : {
6783 0 : AccessPriv *n = makeNode(AccessPriv);
6784 0 : n->priv_name = NULL;
6785 0 : n->cols = $4;
6786 0 : $$ = list_make1(n);
6787 : }
6788 : ;
6789 :
6790 292 : privilege_list: privilege { $$ = list_make1($1); }
6791 19 : | privilege_list ',' privilege { $$ = lappend($1, $3); }
6792 : ;
6793 :
6794 : privilege: SELECT opt_column_list
6795 : {
6796 140 : AccessPriv *n = makeNode(AccessPriv);
6797 140 : n->priv_name = pstrdup($1);
6798 140 : n->cols = $2;
6799 140 : $$ = n;
6800 : }
6801 : | REFERENCES opt_column_list
6802 : {
6803 1 : AccessPriv *n = makeNode(AccessPriv);
6804 1 : n->priv_name = pstrdup($1);
6805 1 : n->cols = $2;
6806 1 : $$ = n;
6807 : }
6808 : | CREATE opt_column_list
6809 : {
6810 6 : AccessPriv *n = makeNode(AccessPriv);
6811 6 : n->priv_name = pstrdup($1);
6812 6 : n->cols = $2;
6813 6 : $$ = n;
6814 : }
6815 : | ColId opt_column_list
6816 : {
6817 164 : AccessPriv *n = makeNode(AccessPriv);
6818 164 : n->priv_name = $1;
6819 164 : n->cols = $2;
6820 164 : $$ = n;
6821 : }
6822 : ;
6823 :
6824 :
6825 : /* Don't bother trying to fold the first two rules into one using
6826 : * opt_table. You're going to get conflicts.
6827 : */
6828 : privilege_target:
6829 : qualified_name_list
6830 : {
6831 213 : PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
6832 213 : n->targtype = ACL_TARGET_OBJECT;
6833 213 : n->objtype = ACL_OBJECT_RELATION;
6834 213 : n->objs = $1;
6835 213 : $$ = n;
6836 : }
6837 : | TABLE qualified_name_list
6838 : {
6839 11 : PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
6840 11 : n->targtype = ACL_TARGET_OBJECT;
6841 11 : n->objtype = ACL_OBJECT_RELATION;
6842 11 : n->objs = $2;
6843 11 : $$ = n;
6844 : }
6845 : | SEQUENCE qualified_name_list
6846 : {
6847 0 : PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
6848 0 : n->targtype = ACL_TARGET_OBJECT;
6849 0 : n->objtype = ACL_OBJECT_SEQUENCE;
6850 0 : n->objs = $2;
6851 0 : $$ = n;
6852 : }
6853 : | FOREIGN DATA_P WRAPPER name_list
6854 : {
6855 14 : PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
6856 14 : n->targtype = ACL_TARGET_OBJECT;
6857 14 : n->objtype = ACL_OBJECT_FDW;
6858 14 : n->objs = $4;
6859 14 : $$ = n;
6860 : }
6861 : | FOREIGN SERVER name_list
6862 : {
6863 11 : PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
6864 11 : n->targtype = ACL_TARGET_OBJECT;
6865 11 : n->objtype = ACL_OBJECT_FOREIGN_SERVER;
6866 11 : n->objs = $3;
6867 11 : $$ = n;
6868 : }
6869 : | FUNCTION function_with_argtypes_list
6870 : {
6871 64 : PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
6872 64 : n->targtype = ACL_TARGET_OBJECT;
6873 64 : n->objtype = ACL_OBJECT_FUNCTION;
6874 64 : n->objs = $2;
6875 64 : $$ = n;
6876 : }
6877 : | DATABASE name_list
6878 : {
6879 5 : PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
6880 5 : n->targtype = ACL_TARGET_OBJECT;
6881 5 : n->objtype = ACL_OBJECT_DATABASE;
6882 5 : n->objs = $2;
6883 5 : $$ = n;
6884 : }
6885 : | DOMAIN_P any_name_list
6886 : {
6887 3 : PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
6888 3 : n->targtype = ACL_TARGET_OBJECT;
6889 3 : n->objtype = ACL_OBJECT_DOMAIN;
6890 3 : n->objs = $2;
6891 3 : $$ = n;
6892 : }
6893 : | LANGUAGE name_list
6894 : {
6895 6 : PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
6896 6 : n->targtype = ACL_TARGET_OBJECT;
6897 6 : n->objtype = ACL_OBJECT_LANGUAGE;
6898 6 : n->objs = $2;
6899 6 : $$ = n;
6900 : }
6901 : | LARGE_P OBJECT_P NumericOnly_list
6902 : {
6903 12 : PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
6904 12 : n->targtype = ACL_TARGET_OBJECT;
6905 12 : n->objtype = ACL_OBJECT_LARGEOBJECT;
6906 12 : n->objs = $3;
6907 12 : $$ = n;
6908 : }
6909 : | SCHEMA name_list
6910 : {
6911 13 : PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
6912 13 : n->targtype = ACL_TARGET_OBJECT;
6913 13 : n->objtype = ACL_OBJECT_NAMESPACE;
6914 13 : n->objs = $2;
6915 13 : $$ = n;
6916 : }
6917 : | TABLESPACE name_list
6918 : {
6919 0 : PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
6920 0 : n->targtype = ACL_TARGET_OBJECT;
6921 0 : n->objtype = ACL_OBJECT_TABLESPACE;
6922 0 : n->objs = $2;
6923 0 : $$ = n;
6924 : }
6925 : | TYPE_P any_name_list
6926 : {
6927 12 : PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
6928 12 : n->targtype = ACL_TARGET_OBJECT;
6929 12 : n->objtype = ACL_OBJECT_TYPE;
6930 12 : n->objs = $2;
6931 12 : $$ = n;
6932 : }
6933 : | ALL TABLES IN_P SCHEMA name_list
6934 : {
6935 2 : PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
6936 2 : n->targtype = ACL_TARGET_ALL_IN_SCHEMA;
6937 2 : n->objtype = ACL_OBJECT_RELATION;
6938 2 : n->objs = $5;
6939 2 : $$ = n;
6940 : }
6941 : | ALL SEQUENCES IN_P SCHEMA name_list
6942 : {
6943 0 : PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
6944 0 : n->targtype = ACL_TARGET_ALL_IN_SCHEMA;
6945 0 : n->objtype = ACL_OBJECT_SEQUENCE;
6946 0 : n->objs = $5;
6947 0 : $$ = n;
6948 : }
6949 : | ALL FUNCTIONS IN_P SCHEMA name_list
6950 : {
6951 1 : PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
6952 1 : n->targtype = ACL_TARGET_ALL_IN_SCHEMA;
6953 1 : n->objtype = ACL_OBJECT_FUNCTION;
6954 1 : n->objs = $5;
6955 1 : $$ = n;
6956 : }
6957 : ;
6958 :
6959 :
6960 : grantee_list:
6961 377 : grantee { $$ = list_make1($1); }
6962 12 : | grantee_list ',' grantee { $$ = lappend($1, $3); }
6963 : ;
6964 :
6965 : grantee:
6966 385 : RoleSpec { $$ = $1; }
6967 4 : | GROUP_P RoleSpec { $$ = $2; }
6968 : ;
6969 :
6970 :
6971 : opt_grant_grant_option:
6972 10 : WITH GRANT OPTION { $$ = TRUE; }
6973 246 : | /*EMPTY*/ { $$ = FALSE; }
6974 : ;
6975 :
6976 : /*****************************************************************************
6977 : *
6978 : * GRANT and REVOKE ROLE statements
6979 : *
6980 : *****************************************************************************/
6981 :
6982 : GrantRoleStmt:
6983 : GRANT privilege_list TO role_list opt_grant_admin_option opt_granted_by
6984 : {
6985 20 : GrantRoleStmt *n = makeNode(GrantRoleStmt);
6986 20 : n->is_grant = true;
6987 20 : n->granted_roles = $2;
6988 20 : n->grantee_roles = $4;
6989 20 : n->admin_opt = $5;
6990 20 : n->grantor = $6;
6991 20 : $$ = (Node*)n;
6992 : }
6993 : ;
6994 :
6995 : RevokeRoleStmt:
6996 : REVOKE privilege_list FROM role_list opt_granted_by opt_drop_behavior
6997 : {
6998 2 : GrantRoleStmt *n = makeNode(GrantRoleStmt);
6999 2 : n->is_grant = false;
7000 2 : n->admin_opt = false;
7001 2 : n->granted_roles = $2;
7002 2 : n->grantee_roles = $4;
7003 2 : n->behavior = $6;
7004 2 : $$ = (Node*)n;
7005 : }
7006 : | REVOKE ADMIN OPTION FOR privilege_list FROM role_list opt_granted_by opt_drop_behavior
7007 : {
7008 0 : GrantRoleStmt *n = makeNode(GrantRoleStmt);
7009 0 : n->is_grant = false;
7010 0 : n->admin_opt = true;
7011 0 : n->granted_roles = $5;
7012 0 : n->grantee_roles = $7;
7013 0 : n->behavior = $9;
7014 0 : $$ = (Node*)n;
7015 : }
7016 : ;
7017 :
7018 1 : opt_grant_admin_option: WITH ADMIN OPTION { $$ = TRUE; }
7019 19 : | /*EMPTY*/ { $$ = FALSE; }
7020 : ;
7021 :
7022 0 : opt_granted_by: GRANTED BY RoleSpec { $$ = $3; }
7023 22 : | /*EMPTY*/ { $$ = NULL; }
7024 : ;
7025 :
7026 : /*****************************************************************************
7027 : *
7028 : * ALTER DEFAULT PRIVILEGES statement
7029 : *
7030 : *****************************************************************************/
7031 :
7032 : AlterDefaultPrivilegesStmt:
7033 : ALTER DEFAULT PRIVILEGES DefACLOptionList DefACLAction
7034 : {
7035 18 : AlterDefaultPrivilegesStmt *n = makeNode(AlterDefaultPrivilegesStmt);
7036 18 : n->options = $4;
7037 18 : n->action = (GrantStmt *) $5;
7038 18 : $$ = (Node*)n;
7039 : }
7040 : ;
7041 :
7042 : DefACLOptionList:
7043 16 : DefACLOptionList DefACLOption { $$ = lappend($1, $2); }
7044 18 : | /* EMPTY */ { $$ = NIL; }
7045 : ;
7046 :
7047 : DefACLOption:
7048 : IN_P SCHEMA name_list
7049 : {
7050 8 : $$ = makeDefElem("schemas", (Node *)$3, @1);
7051 : }
7052 : | FOR ROLE role_list
7053 : {
7054 8 : $$ = makeDefElem("roles", (Node *)$3, @1);
7055 : }
7056 : | FOR USER role_list
7057 : {
7058 0 : $$ = makeDefElem("roles", (Node *)$3, @1);
7059 : }
7060 : ;
7061 :
7062 : /*
7063 : * This should match GRANT/REVOKE, except that individual target objects
7064 : * are not mentioned and we only allow a subset of object types.
7065 : */
7066 : DefACLAction:
7067 : GRANT privileges ON defacl_privilege_target TO grantee_list
7068 : opt_grant_grant_option
7069 : {
7070 10 : GrantStmt *n = makeNode(GrantStmt);
7071 10 : n->is_grant = true;
7072 10 : n->privileges = $2;
7073 10 : n->targtype = ACL_TARGET_DEFAULTS;
7074 10 : n->objtype = $4;
7075 10 : n->objects = NIL;
7076 10 : n->grantees = $6;
7077 10 : n->grant_option = $7;
7078 10 : $$ = (Node*)n;
7079 : }
7080 : | REVOKE privileges ON defacl_privilege_target
7081 : FROM grantee_list opt_drop_behavior
7082 : {
7083 8 : GrantStmt *n = makeNode(GrantStmt);
7084 8 : n->is_grant = false;
7085 8 : n->grant_option = false;
7086 8 : n->privileges = $2;
7087 8 : n->targtype = ACL_TARGET_DEFAULTS;
7088 8 : n->objtype = $4;
7089 8 : n->objects = NIL;
7090 8 : n->grantees = $6;
7091 8 : n->behavior = $7;
7092 8 : $$ = (Node *)n;
7093 : }
7094 : | REVOKE GRANT OPTION FOR privileges ON defacl_privilege_target
7095 : FROM grantee_list opt_drop_behavior
7096 : {
7097 0 : GrantStmt *n = makeNode(GrantStmt);
7098 0 : n->is_grant = false;
7099 0 : n->grant_option = true;
7100 0 : n->privileges = $5;
7101 0 : n->targtype = ACL_TARGET_DEFAULTS;
7102 0 : n->objtype = $7;
7103 0 : n->objects = NIL;
7104 0 : n->grantees = $9;
7105 0 : n->behavior = $10;
7106 0 : $$ = (Node *)n;
7107 : }
7108 : ;
7109 :
7110 : defacl_privilege_target:
7111 9 : TABLES { $$ = ACL_OBJECT_RELATION; }
7112 2 : | FUNCTIONS { $$ = ACL_OBJECT_FUNCTION; }
7113 0 : | SEQUENCES { $$ = ACL_OBJECT_SEQUENCE; }
7114 2 : | TYPES_P { $$ = ACL_OBJECT_TYPE; }
7115 5 : | SCHEMAS { $$ = ACL_OBJECT_NAMESPACE; }
7116 : ;
7117 :
7118 :
7119 : /*****************************************************************************
7120 : *
7121 : * QUERY: CREATE INDEX
7122 : *
7123 : * Note: we cannot put TABLESPACE clause after WHERE clause unless we are
7124 : * willing to make TABLESPACE a fully reserved word.
7125 : *****************************************************************************/
7126 :
7127 : IndexStmt: CREATE opt_unique INDEX opt_concurrently opt_index_name
7128 : ON qualified_name access_method_clause '(' index_params ')'
7129 : opt_reloptions OptTableSpace where_clause
7130 : {
7131 271 : IndexStmt *n = makeNode(IndexStmt);
7132 271 : n->unique = $2;
7133 271 : n->concurrent = $4;
7134 271 : n->idxname = $5;
7135 271 : n->relation = $7;
7136 271 : n->accessMethod = $8;
7137 271 : n->indexParams = $10;
7138 271 : n->options = $12;
7139 271 : n->tableSpace = $13;
7140 271 : n->whereClause = $14;
7141 271 : n->excludeOpNames = NIL;
7142 271 : n->idxcomment = NULL;
7143 271 : n->indexOid = InvalidOid;
7144 271 : n->oldNode = InvalidOid;
7145 271 : n->primary = false;
7146 271 : n->isconstraint = false;
7147 271 : n->deferrable = false;
7148 271 : n->initdeferred = false;
7149 271 : n->transformed = false;
7150 271 : n->if_not_exists = false;
7151 271 : $$ = (Node *)n;
7152 : }
7153 : | CREATE opt_unique INDEX opt_concurrently IF_P NOT EXISTS index_name
7154 : ON qualified_name access_method_clause '(' index_params ')'
7155 : opt_reloptions OptTableSpace where_clause
7156 : {
7157 3 : IndexStmt *n = makeNode(IndexStmt);
7158 3 : n->unique = $2;
7159 3 : n->concurrent = $4;
7160 3 : n->idxname = $8;
7161 3 : n->relation = $10;
7162 3 : n->accessMethod = $11;
7163 3 : n->indexParams = $13;
7164 3 : n->options = $15;
7165 3 : n->tableSpace = $16;
7166 3 : n->whereClause = $17;
7167 3 : n->excludeOpNames = NIL;
7168 3 : n->idxcomment = NULL;
7169 3 : n->indexOid = InvalidOid;
7170 3 : n->oldNode = InvalidOid;
7171 3 : n->primary = false;
7172 3 : n->isconstraint = false;
7173 3 : n->deferrable = false;
7174 3 : n->initdeferred = false;
7175 3 : n->transformed = false;
7176 3 : n->if_not_exists = true;
7177 3 : $$ = (Node *)n;
7178 : }
7179 : ;
7180 :
7181 : opt_unique:
7182 81 : UNIQUE { $$ = TRUE; }
7183 194 : | /*EMPTY*/ { $$ = FALSE; }
7184 : ;
7185 :
7186 : opt_concurrently:
7187 17 : CONCURRENTLY { $$ = TRUE; }
7188 279 : | /*EMPTY*/ { $$ = FALSE; }
7189 : ;
7190 :
7191 : opt_index_name:
7192 245 : index_name { $$ = $1; }
7193 26 : | /*EMPTY*/ { $$ = NULL; }
7194 : ;
7195 :
7196 : access_method_clause:
7197 118 : USING access_method { $$ = $2; }
7198 166 : | /*EMPTY*/ { $$ = DEFAULT_INDEX_TYPE; }
7199 : ;
7200 :
7201 432 : index_params: index_elem { $$ = list_make1($1); }
7202 132 : | index_params ',' index_elem { $$ = lappend($1, $3); }
7203 : ;
7204 :
7205 : /*
7206 : * Index attributes can be either simple column references, or arbitrary
7207 : * expressions in parens. For backwards-compatibility reasons, we allow
7208 : * an expression that's just a function call to be written without parens.
7209 : */
7210 : index_elem: ColId opt_collate opt_class opt_asc_desc opt_nulls_order
7211 : {
7212 519 : $$ = makeNode(IndexElem);
7213 519 : $$->name = $1;
7214 519 : $$->expr = NULL;
7215 519 : $$->indexcolname = NULL;
7216 519 : $$->collation = $2;
7217 519 : $$->opclass = $3;
7218 519 : $$->ordering = $4;
7219 519 : $$->nulls_ordering = $5;
7220 : }
7221 : | func_expr_windowless opt_collate opt_class opt_asc_desc opt_nulls_order
7222 : {
7223 37 : $$ = makeNode(IndexElem);
7224 37 : $$->name = NULL;
7225 37 : $$->expr = $1;
7226 37 : $$->indexcolname = NULL;
7227 37 : $$->collation = $2;
7228 37 : $$->opclass = $3;
7229 37 : $$->ordering = $4;
7230 37 : $$->nulls_ordering = $5;
7231 : }
7232 : | '(' a_expr ')' opt_collate opt_class opt_asc_desc opt_nulls_order
7233 : {
7234 22 : $$ = makeNode(IndexElem);
7235 22 : $$->name = NULL;
7236 22 : $$->expr = $2;
7237 22 : $$->indexcolname = NULL;
7238 22 : $$->collation = $4;
7239 22 : $$->opclass = $5;
7240 22 : $$->ordering = $6;
7241 22 : $$->nulls_ordering = $7;
7242 : }
7243 : ;
7244 :
7245 16 : opt_collate: COLLATE any_name { $$ = $2; }
7246 681 : | /*EMPTY*/ { $$ = NIL; }
7247 : ;
7248 :
7249 64 : opt_class: any_name { $$ = $1; }
7250 633 : | /*EMPTY*/ { $$ = NIL; }
7251 : ;
7252 :
7253 20 : opt_asc_desc: ASC { $$ = SORTBY_ASC; }
7254 121 : | DESC { $$ = SORTBY_DESC; }
7255 4198 : | /*EMPTY*/ { $$ = SORTBY_DEFAULT; }
7256 : ;
7257 :
7258 10 : opt_nulls_order: NULLS_LA FIRST_P { $$ = SORTBY_NULLS_FIRST; }
7259 10 : | NULLS_LA LAST_P { $$ = SORTBY_NULLS_LAST; }
7260 4351 : | /*EMPTY*/ { $$ = SORTBY_NULLS_DEFAULT; }
7261 : ;
7262 :
7263 :
7264 : /*****************************************************************************
7265 : *
7266 : * QUERY:
7267 : * create [or replace] function <fname>
7268 : * [(<type-1> { , <type-n>})]
7269 : * returns <type-r>
7270 : * as <filename or code in language as appropriate>
7271 : * language <lang> [with parameters]
7272 : *
7273 : *****************************************************************************/
7274 :
7275 : CreateFunctionStmt:
7276 : CREATE opt_or_replace FUNCTION func_name func_args_with_defaults
7277 : RETURNS func_return createfunc_opt_list opt_definition
7278 : {
7279 730 : CreateFunctionStmt *n = makeNode(CreateFunctionStmt);
7280 730 : n->replace = $2;
7281 730 : n->funcname = $4;
7282 730 : n->parameters = $5;
7283 730 : n->returnType = $7;
7284 730 : n->options = $8;
7285 730 : n->withClause = $9;
7286 730 : $$ = (Node *)n;
7287 : }
7288 : | CREATE opt_or_replace FUNCTION func_name func_args_with_defaults
7289 : RETURNS TABLE '(' table_func_column_list ')' createfunc_opt_list opt_definition
7290 : {
7291 17 : CreateFunctionStmt *n = makeNode(CreateFunctionStmt);
7292 17 : n->replace = $2;
7293 17 : n->funcname = $4;
7294 17 : n->parameters = mergeTableFuncParameters($5, $9);
7295 17 : n->returnType = TableFuncTypeName($9);
7296 17 : n->returnType->location = @7;
7297 17 : n->options = $11;
7298 17 : n->withClause = $12;
7299 17 : $$ = (Node *)n;
7300 : }
7301 : | CREATE opt_or_replace FUNCTION func_name func_args_with_defaults
7302 : createfunc_opt_list opt_definition
7303 : {
7304 20 : CreateFunctionStmt *n = makeNode(CreateFunctionStmt);
7305 20 : n->replace = $2;
7306 20 : n->funcname = $4;
7307 20 : n->parameters = $5;
7308 20 : n->returnType = NULL;
7309 20 : n->options = $6;
7310 20 : n->withClause = $7;
7311 20 : $$ = (Node *)n;
7312 : }
7313 : ;
7314 :
7315 : opt_or_replace:
7316 320 : OR REPLACE { $$ = TRUE; }
7317 553 : | /*EMPTY*/ { $$ = FALSE; }
7318 : ;
7319 :
7320 364 : func_args: '(' func_args_list ')' { $$ = $2; }
7321 110 : | '(' ')' { $$ = NIL; }
7322 : ;
7323 :
7324 : func_args_list:
7325 364 : func_arg { $$ = list_make1($1); }
7326 608 : | func_args_list ',' func_arg { $$ = lappend($1, $3); }
7327 : ;
7328 :
7329 : function_with_argtypes_list:
7330 272 : function_with_argtypes { $$ = list_make1($1); }
7331 : | function_with_argtypes_list ',' function_with_argtypes
7332 4 : { $$ = lappend($1, $3); }
7333 : ;
7334 :
7335 : function_with_argtypes:
7336 : func_name func_args
7337 : {
7338 474 : ObjectWithArgs *n = makeNode(ObjectWithArgs);
7339 474 : n->objname = $1;
7340 474 : n->objargs = extractArgTypes($2);
7341 474 : $$ = n;
7342 : }
7343 : /*
7344 : * Because of reduce/reduce conflicts, we can't use func_name
7345 : * below, but we can write it out the long way, which actually
7346 : * allows more cases.
7347 : */
7348 : | type_func_name_keyword
7349 : {
7350 0 : ObjectWithArgs *n = makeNode(ObjectWithArgs);
7351 0 : n->objname = list_make1(makeString(pstrdup($1)));
7352 0 : n->args_unspecified = true;
7353 0 : $$ = n;
7354 : }
7355 : | ColId
7356 : {
7357 3 : ObjectWithArgs *n = makeNode(ObjectWithArgs);
7358 3 : n->objname = list_make1(makeString($1));
7359 3 : n->args_unspecified = true;
7360 3 : $$ = n;
7361 : }
7362 : | ColId indirection
7363 : {
7364 0 : ObjectWithArgs *n = makeNode(ObjectWithArgs);
7365 0 : n->objname = check_func_name(lcons(makeString($1), $2),
7366 : yyscanner);
7367 0 : n->args_unspecified = true;
7368 0 : $$ = n;
7369 : }
7370 : ;
7371 :
7372 : /*
7373 : * func_args_with_defaults is separate because we only want to accept
7374 : * defaults in CREATE FUNCTION, not in ALTER etc.
7375 : */
7376 : func_args_with_defaults:
7377 511 : '(' func_args_with_defaults_list ')' { $$ = $2; }
7378 256 : | '(' ')' { $$ = NIL; }
7379 : ;
7380 :
7381 : func_args_with_defaults_list:
7382 511 : func_arg_with_default { $$ = list_make1($1); }
7383 : | func_args_with_defaults_list ',' func_arg_with_default
7384 780 : { $$ = lappend($1, $3); }
7385 : ;
7386 :
7387 : /*
7388 : * The style with arg_class first is SQL99 standard, but Oracle puts
7389 : * param_name first; accept both since it's likely people will try both
7390 : * anyway. Don't bother trying to save productions by letting arg_class
7391 : * have an empty alternative ... you'll get shift/reduce conflicts.
7392 : *
7393 : * We can catch over-specified arguments here if we want to,
7394 : * but for now better to silently swallow typmod, etc.
7395 : * - thomas 2000-03-22
7396 : */
7397 : func_arg:
7398 : arg_class param_name func_type
7399 : {
7400 131 : FunctionParameter *n = makeNode(FunctionParameter);
7401 131 : n->name = $2;
7402 131 : n->argType = $3;
7403 131 : n->mode = $1;
7404 131 : n->defexpr = NULL;
7405 131 : $$ = n;
7406 : }
7407 : | param_name arg_class func_type
7408 : {
7409 6 : FunctionParameter *n = makeNode(FunctionParameter);
7410 6 : n->name = $1;
7411 6 : n->argType = $3;
7412 6 : n->mode = $2;
7413 6 : n->defexpr = NULL;
7414 6 : $$ = n;
7415 : }
7416 : | param_name func_type
7417 : {
7418 171 : FunctionParameter *n = makeNode(FunctionParameter);
7419 171 : n->name = $1;
7420 171 : n->argType = $2;
7421 171 : n->mode = FUNC_PARAM_IN;
7422 171 : n->defexpr = NULL;
7423 171 : $$ = n;
7424 : }
7425 : | arg_class func_type
7426 : {
7427 24 : FunctionParameter *n = makeNode(FunctionParameter);
7428 24 : n->name = NULL;
7429 24 : n->argType = $2;
7430 24 : n->mode = $1;
7431 24 : n->defexpr = NULL;
7432 24 : $$ = n;
7433 : }
7434 : | func_type
7435 : {
7436 2032 : FunctionParameter *n = makeNode(FunctionParameter);
7437 2032 : n->name = NULL;
7438 2032 : n->argType = $1;
7439 2032 : n->mode = FUNC_PARAM_IN;
7440 2032 : n->defexpr = NULL;
7441 2032 : $$ = n;
7442 : }
7443 : ;
7444 :
7445 : /* INOUT is SQL99 standard, IN OUT is for Oracle compatibility */
7446 37 : arg_class: IN_P { $$ = FUNC_PARAM_IN; }
7447 95 : | OUT_P { $$ = FUNC_PARAM_OUT; }
7448 9 : | INOUT { $$ = FUNC_PARAM_INOUT; }
7449 0 : | IN_P OUT_P { $$ = FUNC_PARAM_INOUT; }
7450 20 : | VARIADIC { $$ = FUNC_PARAM_VARIADIC; }
7451 : ;
7452 :
7453 : /*
7454 : * Ideally param_name should be ColId, but that causes too many conflicts.
7455 : */
7456 : param_name: type_function_name
7457 : ;
7458 :
7459 : func_return:
7460 : func_type
7461 : {
7462 : /* We can catch over-specified results here if we want to,
7463 : * but for now better to silently swallow typmod, etc.
7464 : * - thomas 2000-03-22
7465 : */
7466 730 : $$ = $1;
7467 : }
7468 : ;
7469 :
7470 : /*
7471 : * We would like to make the %TYPE productions here be ColId attrs etc,
7472 : * but that causes reduce/reduce conflicts. type_function_name
7473 : * is next best choice.
7474 : */
7475 3801 : func_type: Typename { $$ = $1; }
7476 : | type_function_name attrs '%' TYPE_P
7477 : {
7478 3 : $$ = makeTypeNameFromNameList(lcons(makeString($1), $2));
7479 3 : $$->pct_type = true;
7480 3 : $$->location = @1;
7481 : }
7482 : | SETOF type_function_name attrs '%' TYPE_P
7483 : {
7484 1 : $$ = makeTypeNameFromNameList(lcons(makeString($2), $3));
7485 1 : $$->pct_type = true;
7486 1 : $$->setof = TRUE;
7487 1 : $$->location = @2;
7488 : }
7489 : ;
7490 :
7491 : func_arg_with_default:
7492 : func_arg
7493 : {
7494 1230 : $$ = $1;
7495 : }
7496 : | func_arg DEFAULT a_expr
7497 : {
7498 31 : $$ = $1;
7499 31 : $$->defexpr = $3;
7500 : }
7501 : | func_arg '=' a_expr
7502 : {
7503 30 : $$ = $1;
7504 30 : $$->defexpr = $3;
7505 : }
7506 : ;
7507 :
7508 : /* Aggregate args can be most things that function args can be */
7509 : aggr_arg: func_arg
7510 : {
7511 106 : if (!($1->mode == FUNC_PARAM_IN ||
7512 5 : $1->mode == FUNC_PARAM_VARIADIC))
7513 0 : ereport(ERROR,
7514 : (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
7515 : errmsg("aggregates cannot have output arguments"),
7516 : parser_errposition(@1)));
7517 101 : $$ = $1;
7518 : }
7519 : ;
7520 :
7521 : /*
7522 : * The SQL standard offers no guidance on how to declare aggregate argument
7523 : * lists, since it doesn't have CREATE AGGREGATE etc. We accept these cases:
7524 : *
7525 : * (*) - normal agg with no args
7526 : * (aggr_arg,...) - normal agg with args
7527 : * (ORDER BY aggr_arg,...) - ordered-set agg with no direct args
7528 : * (aggr_arg,... ORDER BY aggr_arg,...) - ordered-set agg with direct args
7529 : *
7530 : * The zero-argument case is spelled with '*' for consistency with COUNT(*).
7531 : *
7532 : * An additional restriction is that if the direct-args list ends in a
7533 : * VARIADIC item, the ordered-args list must contain exactly one item that
7534 : * is also VARIADIC with the same type. This allows us to collapse the two
7535 : * VARIADIC items into one, which is necessary to represent the aggregate in
7536 : * pg_proc. We check this at the grammar stage so that we can return a list
7537 : * in which the second VARIADIC item is already discarded, avoiding extra work
7538 : * in cases such as DROP AGGREGATE.
7539 : *
7540 : * The return value of this production is a two-element list, in which the
7541 : * first item is a sublist of FunctionParameter nodes (with any duplicate
7542 : * VARIADIC item already dropped, as per above) and the second is an integer
7543 : * Value node, containing -1 if there was no ORDER BY and otherwise the number
7544 : * of argument declarations before the ORDER BY. (If this number is equal
7545 : * to the first sublist's length, then we dropped a duplicate VARIADIC item.)
7546 : * This representation is passed as-is to CREATE AGGREGATE; for operations
7547 : * on existing aggregates, we can just apply extractArgTypes to the first
7548 : * sublist.
7549 : */
7550 : aggr_args: '(' '*' ')'
7551 : {
7552 17 : $$ = list_make2(NIL, makeInteger(-1));
7553 : }
7554 : | '(' aggr_args_list ')'
7555 : {
7556 84 : $$ = list_make2($2, makeInteger(-1));
7557 : }
7558 : | '(' ORDER BY aggr_args_list ')'
7559 : {
7560 0 : $$ = list_make2($4, makeInteger(0));
7561 : }
7562 : | '(' aggr_args_list ORDER BY aggr_args_list ')'
7563 : {
7564 : /* this is the only case requiring consistency checking */
7565 4 : $$ = makeOrderedSetArgs($2, $5, yyscanner);
7566 : }
7567 : ;
7568 :
7569 : aggr_args_list:
7570 92 : aggr_arg { $$ = list_make1($1); }
7571 9 : | aggr_args_list ',' aggr_arg { $$ = lappend($1, $3); }
7572 : ;
7573 :
7574 : aggregate_with_argtypes:
7575 : func_name aggr_args
7576 : {
7577 44 : ObjectWithArgs *n = makeNode(ObjectWithArgs);
7578 44 : n->objname = $1;
7579 44 : n->objargs = extractAggrArgTypes($2);
7580 44 : $$ = n;
7581 : }
7582 : ;
7583 :
7584 : aggregate_with_argtypes_list:
7585 12 : aggregate_with_argtypes { $$ = list_make1($1); }
7586 : | aggregate_with_argtypes_list ',' aggregate_with_argtypes
7587 0 : { $$ = lappend($1, $3); }
7588 : ;
7589 :
7590 : createfunc_opt_list:
7591 : /* Must be at least one to prevent conflict */
7592 767 : createfunc_opt_item { $$ = list_make1($1); }
7593 1288 : | createfunc_opt_list createfunc_opt_item { $$ = lappend($1, $2); }
7594 : ;
7595 :
7596 : /*
7597 : * Options common to both CREATE FUNCTION and ALTER FUNCTION
7598 : */
7599 : common_func_opt_item:
7600 : CALLED ON NULL_P INPUT_P
7601 : {
7602 5 : $$ = makeDefElem("strict", (Node *)makeInteger(FALSE), @1);
7603 : }
7604 : | RETURNS NULL_P ON NULL_P INPUT_P
7605 : {
7606 12 : $$ = makeDefElem("strict", (Node *)makeInteger(TRUE), @1);
7607 : }
7608 : | STRICT_P
7609 : {
7610 201 : $$ = makeDefElem("strict", (Node *)makeInteger(TRUE), @1);
7611 : }
7612 : | IMMUTABLE
7613 : {
7614 88 : $$ = makeDefElem("volatility", (Node *)makeString("immutable"), @1);
7615 : }
7616 : | STABLE
7617 : {
7618 22 : $$ = makeDefElem("volatility", (Node *)makeString("stable"), @1);
7619 : }
7620 : | VOLATILE
7621 : {
7622 19 : $$ = makeDefElem("volatility", (Node *)makeString("volatile"), @1);
7623 : }
7624 : | EXTERNAL SECURITY DEFINER
7625 : {
7626 0 : $$ = makeDefElem("security", (Node *)makeInteger(TRUE), @1);
7627 : }
7628 : | EXTERNAL SECURITY INVOKER
7629 : {
7630 0 : $$ = makeDefElem("security", (Node *)makeInteger(FALSE), @1);
7631 : }
7632 : | SECURITY DEFINER
7633 : {
7634 5 : $$ = makeDefElem("security", (Node *)makeInteger(TRUE), @1);
7635 : }
7636 : | SECURITY INVOKER
7637 : {
7638 2 : $$ = makeDefElem("security", (Node *)makeInteger(FALSE), @1);
7639 : }
7640 : | LEAKPROOF
7641 : {
7642 5 : $$ = makeDefElem("leakproof", (Node *)makeInteger(TRUE), @1);
7643 : }
7644 : | NOT LEAKPROOF
7645 : {
7646 2 : $$ = makeDefElem("leakproof", (Node *)makeInteger(FALSE), @1);
7647 : }
7648 : | COST NumericOnly
7649 : {
7650 9 : $$ = makeDefElem("cost", (Node *)$2, @1);
7651 : }
7652 : | ROWS NumericOnly
7653 : {
7654 5 : $$ = makeDefElem("rows", (Node *)$2, @1);
7655 : }
7656 : | FunctionSetResetClause
7657 : {
7658 : /* we abuse the normal content of a DefElem here */
7659 9 : $$ = makeDefElem("set", (Node *)$1, @1);
7660 : }
7661 : | PARALLEL ColId
7662 : {
7663 155 : $$ = makeDefElem("parallel", (Node *)makeString($2), @1);
7664 : }
7665 : ;
7666 :
7667 : createfunc_opt_item:
7668 : AS func_as
7669 : {
7670 767 : $$ = makeDefElem("as", (Node *)$2, @1);
7671 : }
7672 : | LANGUAGE NonReservedWord_or_Sconst
7673 : {
7674 767 : $$ = makeDefElem("language", (Node *)makeString($2), @1);
7675 : }
7676 : | TRANSFORM transform_type_list
7677 : {
7678 0 : $$ = makeDefElem("transform", (Node *)$2, @1);
7679 : }
7680 : | WINDOW
7681 : {
7682 1 : $$ = makeDefElem("window", (Node *)makeInteger(TRUE), @1);
7683 : }
7684 : | common_func_opt_item
7685 : {
7686 520 : $$ = $1;
7687 : }
7688 : ;
7689 :
7690 631 : func_as: Sconst { $$ = list_make1(makeString($1)); }
7691 : | Sconst ',' Sconst
7692 : {
7693 136 : $$ = list_make2(makeString($1), makeString($3));
7694 : }
7695 : ;
7696 :
7697 : transform_type_list:
7698 0 : FOR TYPE_P Typename { $$ = list_make1($3); }
7699 0 : | transform_type_list ',' FOR TYPE_P Typename { $$ = lappend($1, $5); }
7700 : ;
7701 :
7702 : opt_definition:
7703 20 : WITH definition { $$ = $2; }
7704 1113 : | /*EMPTY*/ { $$ = NIL; }
7705 : ;
7706 :
7707 : table_func_column: param_name func_type
7708 : {
7709 35 : FunctionParameter *n = makeNode(FunctionParameter);
7710 35 : n->name = $1;
7711 35 : n->argType = $2;
7712 35 : n->mode = FUNC_PARAM_TABLE;
7713 35 : n->defexpr = NULL;
7714 35 : $$ = n;
7715 : }
7716 : ;
7717 :
7718 : table_func_column_list:
7719 : table_func_column
7720 : {
7721 17 : $$ = list_make1($1);
7722 : }
7723 : | table_func_column_list ',' table_func_column
7724 : {
7725 18 : $$ = lappend($1, $3);
7726 : }
7727 : ;
7728 :
7729 : /*****************************************************************************
7730 : * ALTER FUNCTION
7731 : *
7732 : * RENAME and OWNER subcommands are already provided by the generic
7733 : * ALTER infrastructure, here we just specify alterations that can
7734 : * only be applied to functions.
7735 : *
7736 : *****************************************************************************/
7737 : AlterFunctionStmt:
7738 : ALTER FUNCTION function_with_argtypes alterfunc_opt_list opt_restrict
7739 : {
7740 19 : AlterFunctionStmt *n = makeNode(AlterFunctionStmt);
7741 19 : n->func = $3;
7742 19 : n->actions = $4;
7743 19 : $$ = (Node *) n;
7744 : }
7745 : ;
7746 :
7747 : alterfunc_opt_list:
7748 : /* At least one option must be specified */
7749 19 : common_func_opt_item { $$ = list_make1($1); }
7750 0 : | alterfunc_opt_list common_func_opt_item { $$ = lappend($1, $2); }
7751 : ;
7752 :
7753 : /* Ignored, merely for SQL compliance */
7754 : opt_restrict:
7755 : RESTRICT
7756 : | /* EMPTY */
7757 : ;
7758 :
7759 :
7760 : /*****************************************************************************
7761 : *
7762 : * QUERY:
7763 : *
7764 : * DROP FUNCTION funcname (arg1, arg2, ...) [ RESTRICT | CASCADE ]
7765 : * DROP AGGREGATE aggname (arg1, ...) [ RESTRICT | CASCADE ]
7766 : * DROP OPERATOR opname (leftoperand_typ, rightoperand_typ) [ RESTRICT | CASCADE ]
7767 : *
7768 : *****************************************************************************/
7769 :
7770 : RemoveFuncStmt:
7771 : DROP FUNCTION function_with_argtypes_list opt_drop_behavior
7772 : {
7773 203 : DropStmt *n = makeNode(DropStmt);
7774 203 : n->removeType = OBJECT_FUNCTION;
7775 203 : n->objects = $3;
7776 203 : n->behavior = $4;
7777 203 : n->missing_ok = false;
7778 203 : n->concurrent = false;
7779 203 : $$ = (Node *)n;
7780 : }
7781 : | DROP FUNCTION IF_P EXISTS function_with_argtypes_list opt_drop_behavior
7782 : {
7783 5 : DropStmt *n = makeNode(DropStmt);
7784 5 : n->removeType = OBJECT_FUNCTION;
7785 5 : n->objects = $5;
7786 5 : n->behavior = $6;
7787 5 : n->missing_ok = true;
7788 5 : n->concurrent = false;
7789 5 : $$ = (Node *)n;
7790 : }
7791 : ;
7792 :
7793 : RemoveAggrStmt:
7794 : DROP AGGREGATE aggregate_with_argtypes_list opt_drop_behavior
7795 : {
7796 7 : DropStmt *n = makeNode(DropStmt);
7797 7 : n->removeType = OBJECT_AGGREGATE;
7798 7 : n->objects = $3;
7799 7 : n->behavior = $4;
7800 7 : n->missing_ok = false;
7801 7 : n->concurrent = false;
7802 7 : $$ = (Node *)n;
7803 : }
7804 : | DROP AGGREGATE IF_P EXISTS aggregate_with_argtypes_list opt_drop_behavior
7805 : {
7806 5 : DropStmt *n = makeNode(DropStmt);
7807 5 : n->removeType = OBJECT_AGGREGATE;
7808 5 : n->objects = $5;
7809 5 : n->behavior = $6;
7810 5 : n->missing_ok = true;
7811 5 : n->concurrent = false;
7812 5 : $$ = (Node *)n;
7813 : }
7814 : ;
7815 :
7816 : RemoveOperStmt:
7817 : DROP OPERATOR operator_with_argtypes_list opt_drop_behavior
7818 : {
7819 11 : DropStmt *n = makeNode(DropStmt);
7820 11 : n->removeType = OBJECT_OPERATOR;
7821 11 : n->objects = $3;
7822 11 : n->behavior = $4;
7823 11 : n->missing_ok = false;
7824 11 : n->concurrent = false;
7825 11 : $$ = (Node *)n;
7826 : }
7827 : | DROP OPERATOR IF_P EXISTS operator_with_argtypes_list opt_drop_behavior
7828 : {
7829 5 : DropStmt *n = makeNode(DropStmt);
7830 5 : n->removeType = OBJECT_OPERATOR;
7831 5 : n->objects = $5;
7832 5 : n->behavior = $6;
7833 5 : n->missing_ok = true;
7834 5 : n->concurrent = false;
7835 5 : $$ = (Node *)n;
7836 : }
7837 : ;
7838 :
7839 : oper_argtypes:
7840 : '(' Typename ')'
7841 : {
7842 2 : ereport(ERROR,
7843 : (errcode(ERRCODE_SYNTAX_ERROR),
7844 : errmsg("missing argument"),
7845 : errhint("Use NONE to denote the missing argument of a unary operator."),
7846 : parser_errposition(@3)));
7847 : }
7848 : | '(' Typename ',' Typename ')'
7849 79 : { $$ = list_make2($2, $4); }
7850 : | '(' NONE ',' Typename ')' /* left unary */
7851 2 : { $$ = list_make2(NULL, $4); }
7852 : | '(' Typename ',' NONE ')' /* right unary */
7853 1 : { $$ = list_make2($2, NULL); }
7854 : ;
7855 :
7856 : any_operator:
7857 : all_Op
7858 405 : { $$ = list_make1(makeString($1)); }
7859 : | ColId '.' any_operator
7860 255 : { $$ = lcons(makeString($1), $3); }
7861 : ;
7862 :
7863 : operator_with_argtypes_list:
7864 16 : operator_with_argtypes { $$ = list_make1($1); }
7865 : | operator_with_argtypes_list ',' operator_with_argtypes
7866 0 : { $$ = lappend($1, $3); }
7867 : ;
7868 :
7869 : operator_with_argtypes:
7870 : any_operator oper_argtypes
7871 : {
7872 82 : ObjectWithArgs *n = makeNode(ObjectWithArgs);
7873 82 : n->objname = $1;
7874 82 : n->objargs = $2;
7875 82 : $$ = n;
7876 : }
7877 : ;
7878 :
7879 : /*****************************************************************************
7880 : *
7881 : * DO <anonymous code block> [ LANGUAGE language ]
7882 : *
7883 : * We use a DefElem list for future extensibility, and to allow flexibility
7884 : * in the clause order.
7885 : *
7886 : *****************************************************************************/
7887 :
7888 : DoStmt: DO dostmt_opt_list
7889 : {
7890 40 : DoStmt *n = makeNode(DoStmt);
7891 40 : n->args = $2;
7892 40 : $$ = (Node *)n;
7893 : }
7894 : ;
7895 :
7896 : dostmt_opt_list:
7897 40 : dostmt_opt_item { $$ = list_make1($1); }
7898 2 : | dostmt_opt_list dostmt_opt_item { $$ = lappend($1, $2); }
7899 : ;
7900 :
7901 : dostmt_opt_item:
7902 : Sconst
7903 : {
7904 40 : $$ = makeDefElem("as", (Node *)makeString($1), @1);
7905 : }
7906 : | LANGUAGE NonReservedWord_or_Sconst
7907 : {
7908 2 : $$ = makeDefElem("language", (Node *)makeString($2), @1);
7909 : }
7910 : ;
7911 :
7912 : /*****************************************************************************
7913 : *
7914 : * CREATE CAST / DROP CAST
7915 : *
7916 : *****************************************************************************/
7917 :
7918 : CreateCastStmt: CREATE CAST '(' Typename AS Typename ')'
7919 : WITH FUNCTION function_with_argtypes cast_context
7920 : {
7921 4 : CreateCastStmt *n = makeNode(CreateCastStmt);
7922 4 : n->sourcetype = $4;
7923 4 : n->targettype = $6;
7924 4 : n->func = $10;
7925 4 : n->context = (CoercionContext) $11;
7926 4 : n->inout = false;
7927 4 : $$ = (Node *)n;
7928 : }
7929 : | CREATE CAST '(' Typename AS Typename ')'
7930 : WITHOUT FUNCTION cast_context
7931 : {
7932 6 : CreateCastStmt *n = makeNode(CreateCastStmt);
7933 6 : n->sourcetype = $4;
7934 6 : n->targettype = $6;
7935 6 : n->func = NULL;
7936 6 : n->context = (CoercionContext) $10;
7937 6 : n->inout = false;
7938 6 : $$ = (Node *)n;
7939 : }
7940 : | CREATE CAST '(' Typename AS Typename ')'
7941 : WITH INOUT cast_context
7942 : {
7943 1 : CreateCastStmt *n = makeNode(CreateCastStmt);
7944 1 : n->sourcetype = $4;
7945 1 : n->targettype = $6;
7946 1 : n->func = NULL;
7947 1 : n->context = (CoercionContext) $10;
7948 1 : n->inout = true;
7949 1 : $$ = (Node *)n;
7950 : }
7951 : ;
7952 :
7953 2 : cast_context: AS IMPLICIT_P { $$ = COERCION_IMPLICIT; }
7954 1 : | AS ASSIGNMENT { $$ = COERCION_ASSIGNMENT; }
7955 8 : | /*EMPTY*/ { $$ = COERCION_EXPLICIT; }
7956 : ;
7957 :
7958 :
7959 : DropCastStmt: DROP CAST opt_if_exists '(' Typename AS Typename ')' opt_drop_behavior
7960 : {
7961 9 : DropStmt *n = makeNode(DropStmt);
7962 9 : n->removeType = OBJECT_CAST;
7963 9 : n->objects = list_make1(list_make2($5, $7));
7964 9 : n->behavior = $9;
7965 9 : n->missing_ok = $3;
7966 9 : n->concurrent = false;
7967 9 : $$ = (Node *)n;
7968 : }
7969 : ;
7970 :
7971 5 : opt_if_exists: IF_P EXISTS { $$ = TRUE; }
7972 4 : | /*EMPTY*/ { $$ = FALSE; }
7973 : ;
7974 :
7975 :
7976 : /*****************************************************************************
7977 : *
7978 : * CREATE TRANSFORM / DROP TRANSFORM
7979 : *
7980 : *****************************************************************************/
7981 :
7982 : CreateTransformStmt: CREATE opt_or_replace TRANSFORM FOR Typename LANGUAGE name '(' transform_element_list ')'
7983 : {
7984 1 : CreateTransformStmt *n = makeNode(CreateTransformStmt);
7985 1 : n->replace = $2;
7986 1 : n->type_name = $5;
7987 1 : n->lang = $7;
7988 1 : n->fromsql = linitial($9);
7989 1 : n->tosql = lsecond($9);
7990 1 : $$ = (Node *)n;
7991 : }
7992 : ;
7993 :
7994 : transform_element_list: FROM SQL_P WITH FUNCTION function_with_argtypes ',' TO SQL_P WITH FUNCTION function_with_argtypes
7995 : {
7996 1 : $$ = list_make2($5, $11);
7997 : }
7998 : | TO SQL_P WITH FUNCTION function_with_argtypes ',' FROM SQL_P WITH FUNCTION function_with_argtypes
7999 : {
8000 0 : $$ = list_make2($11, $5);
8001 : }
8002 : | FROM SQL_P WITH FUNCTION function_with_argtypes
8003 : {
8004 0 : $$ = list_make2($5, NULL);
8005 : }
8006 : | TO SQL_P WITH FUNCTION function_with_argtypes
8007 : {
8008 0 : $$ = list_make2(NULL, $5);
8009 : }
8010 : ;
8011 :
8012 :
8013 : DropTransformStmt: DROP TRANSFORM opt_if_exists FOR Typename LANGUAGE name opt_drop_behavior
8014 : {
8015 0 : DropStmt *n = makeNode(DropStmt);
8016 0 : n->removeType = OBJECT_TRANSFORM;
8017 0 : n->objects = list_make1(list_make2($5, makeString($7)));
8018 0 : n->behavior = $8;
8019 0 : n->missing_ok = $3;
8020 0 : $$ = (Node *)n;
8021 : }
8022 : ;
8023 :
8024 :
8025 : /*****************************************************************************
8026 : *
8027 : * QUERY:
8028 : *
8029 : * REINDEX [ (options) ] type <name>
8030 : *****************************************************************************/
8031 :
8032 : ReindexStmt:
8033 : REINDEX reindex_target_type qualified_name
8034 : {
8035 5 : ReindexStmt *n = makeNode(ReindexStmt);
8036 5 : n->kind = $2;
8037 5 : n->relation = $3;
8038 5 : n->name = NULL;
8039 5 : n->options = 0;
8040 5 : $$ = (Node *)n;
8041 : }
8042 : | REINDEX reindex_target_multitable name
8043 : {
8044 5 : ReindexStmt *n = makeNode(ReindexStmt);
8045 5 : n->kind = $2;
8046 5 : n->name = $3;
8047 5 : n->relation = NULL;
8048 5 : n->options = 0;
8049 5 : $$ = (Node *)n;
8050 : }
8051 : | REINDEX '(' reindex_option_list ')' reindex_target_type qualified_name
8052 : {
8053 1 : ReindexStmt *n = makeNode(ReindexStmt);
8054 1 : n->kind = $5;
8055 1 : n->relation = $6;
8056 1 : n->name = NULL;
8057 1 : n->options = $3;
8058 1 : $$ = (Node *)n;
8059 : }
8060 : | REINDEX '(' reindex_option_list ')' reindex_target_multitable name
8061 : {
8062 0 : ReindexStmt *n = makeNode(ReindexStmt);
8063 0 : n->kind = $5;
8064 0 : n->name = $6;
8065 0 : n->relation = NULL;
8066 0 : n->options = $3;
8067 0 : $$ = (Node *)n;
8068 : }
8069 : ;
8070 : reindex_target_type:
8071 3 : INDEX { $$ = REINDEX_OBJECT_INDEX; }
8072 3 : | TABLE { $$ = REINDEX_OBJECT_TABLE; }
8073 : ;
8074 : reindex_target_multitable:
8075 5 : SCHEMA { $$ = REINDEX_OBJECT_SCHEMA; }
8076 0 : | SYSTEM_P { $$ = REINDEX_OBJECT_SYSTEM; }
8077 0 : | DATABASE { $$ = REINDEX_OBJECT_DATABASE; }
8078 : ;
8079 : reindex_option_list:
8080 1 : reindex_option_elem { $$ = $1; }
8081 0 : | reindex_option_list ',' reindex_option_elem { $$ = $1 | $3; }
8082 : ;
8083 : reindex_option_elem:
8084 1 : VERBOSE { $$ = REINDEXOPT_VERBOSE; }
8085 : ;
8086 :
8087 : /*****************************************************************************
8088 : *
8089 : * ALTER TABLESPACE
8090 : *
8091 : *****************************************************************************/
8092 :
8093 : AlterTblSpcStmt:
8094 : ALTER TABLESPACE name SET reloptions
8095 : {
8096 2 : AlterTableSpaceOptionsStmt *n =
8097 2 : makeNode(AlterTableSpaceOptionsStmt);
8098 2 : n->tablespacename = $3;
8099 2 : n->options = $5;
8100 2 : n->isReset = FALSE;
8101 2 : $$ = (Node *)n;
8102 : }
8103 : | ALTER TABLESPACE name RESET reloptions
8104 : {
8105 2 : AlterTableSpaceOptionsStmt *n =
8106 2 : makeNode(AlterTableSpaceOptionsStmt);
8107 2 : n->tablespacename = $3;
8108 2 : n->options = $5;
8109 2 : n->isReset = TRUE;
8110 2 : $$ = (Node *)n;
8111 : }
8112 : ;
8113 :
8114 : /*****************************************************************************
8115 : *
8116 : * ALTER THING name RENAME TO newname
8117 : *
8118 : *****************************************************************************/
8119 :
8120 : RenameStmt: ALTER AGGREGATE aggregate_with_argtypes RENAME TO name
8121 : {
8122 7 : RenameStmt *n = makeNode(RenameStmt);
8123 7 : n->renameType = OBJECT_AGGREGATE;
8124 7 : n->object = (Node *) $3;
8125 7 : n->newname = $6;
8126 7 : n->missing_ok = false;
8127 7 : $$ = (Node *)n;
8128 : }
8129 : | ALTER COLLATION any_name RENAME TO name
8130 : {
8131 0 : RenameStmt *n = makeNode(RenameStmt);
8132 0 : n->renameType = OBJECT_COLLATION;
8133 0 : n->object = (Node *) $3;
8134 0 : n->newname = $6;
8135 0 : n->missing_ok = false;
8136 0 : $$ = (Node *)n;
8137 : }
8138 : | ALTER CONVERSION_P any_name RENAME TO name
8139 : {
8140 4 : RenameStmt *n = makeNode(RenameStmt);
8141 4 : n->renameType = OBJECT_CONVERSION;
8142 4 : n->object = (Node *) $3;
8143 4 : n->newname = $6;
8144 4 : n->missing_ok = false;
8145 4 : $$ = (Node *)n;
8146 : }
8147 : | ALTER DATABASE database_name RENAME TO database_name
8148 : {
8149 0 : RenameStmt *n = makeNode(RenameStmt);
8150 0 : n->renameType = OBJECT_DATABASE;
8151 0 : n->subname = $3;
8152 0 : n->newname = $6;
8153 0 : n->missing_ok = false;
8154 0 : $$ = (Node *)n;
8155 : }
8156 : | ALTER DOMAIN_P any_name RENAME TO name
8157 : {
8158 1 : RenameStmt *n = makeNode(RenameStmt);
8159 1 : n->renameType = OBJECT_DOMAIN;
8160 1 : n->object = (Node *) $3;
8161 1 : n->newname = $6;
8162 1 : n->missing_ok = false;
8163 1 : $$ = (Node *)n;
8164 : }
8165 : | ALTER DOMAIN_P any_name RENAME CONSTRAINT name TO name
8166 : {
8167 1 : RenameStmt *n = makeNode(RenameStmt);
8168 1 : n->renameType = OBJECT_DOMCONSTRAINT;
8169 1 : n->object = (Node *) $3;
8170 1 : n->subname = $6;
8171 1 : n->newname = $8;
8172 1 : $$ = (Node *)n;
8173 : }
8174 : | ALTER FOREIGN DATA_P WRAPPER name RENAME TO name
8175 : {
8176 4 : RenameStmt *n = makeNode(RenameStmt);
8177 4 : n->renameType = OBJECT_FDW;
8178 4 : n->object = (Node *) makeString($5);
8179 4 : n->newname = $8;
8180 4 : n->missing_ok = false;
8181 4 : $$ = (Node *)n;
8182 : }
8183 : | ALTER FUNCTION function_with_argtypes RENAME TO name
8184 : {
8185 4 : RenameStmt *n = makeNode(RenameStmt);
8186 4 : n->renameType = OBJECT_FUNCTION;
8187 4 : n->object = (Node *) $3;
8188 4 : n->newname = $6;
8189 4 : n->missing_ok = false;
8190 4 : $$ = (Node *)n;
8191 : }
8192 : | ALTER GROUP_P RoleId RENAME TO RoleId
8193 : {
8194 0 : RenameStmt *n = makeNode(RenameStmt);
8195 0 : n->renameType = OBJECT_ROLE;
8196 0 : n->subname = $3;
8197 0 : n->newname = $6;
8198 0 : n->missing_ok = false;
8199 0 : $$ = (Node *)n;
8200 : }
8201 : | ALTER opt_procedural LANGUAGE name RENAME TO name
8202 : {
8203 3 : RenameStmt *n = makeNode(RenameStmt);
8204 3 : n->renameType = OBJECT_LANGUAGE;
8205 3 : n->object = (Node *) makeString($4);
8206 3 : n->newname = $7;
8207 3 : n->missing_ok = false;
8208 3 : $$ = (Node *)n;
8209 : }
8210 : | ALTER OPERATOR CLASS any_name USING access_method RENAME TO name
8211 : {
8212 4 : RenameStmt *n = makeNode(RenameStmt);
8213 4 : n->renameType = OBJECT_OPCLASS;
8214 4 : n->object = (Node *) lcons(makeString($6), $4);
8215 4 : n->newname = $9;
8216 4 : n->missing_ok = false;
8217 4 : $$ = (Node *)n;
8218 : }
8219 : | ALTER OPERATOR FAMILY any_name USING access_method RENAME TO name
8220 : {
8221 4 : RenameStmt *n = makeNode(RenameStmt);
8222 4 : n->renameType = OBJECT_OPFAMILY;
8223 4 : n->object = (Node *) lcons(makeString($6), $4);
8224 4 : n->newname = $9;
8225 4 : n->missing_ok = false;
8226 4 : $$ = (Node *)n;
8227 : }
8228 : | ALTER POLICY name ON qualified_name RENAME TO name
8229 : {
8230 3 : RenameStmt *n = makeNode(RenameStmt);
8231 3 : n->renameType = OBJECT_POLICY;
8232 3 : n->relation = $5;
8233 3 : n->subname = $3;
8234 3 : n->newname = $8;
8235 3 : n->missing_ok = false;
8236 3 : $$ = (Node *)n;
8237 : }
8238 : | ALTER POLICY IF_P EXISTS name ON qualified_name RENAME TO name
8239 : {
8240 0 : RenameStmt *n = makeNode(RenameStmt);
8241 0 : n->renameType = OBJECT_POLICY;
8242 0 : n->relation = $7;
8243 0 : n->subname = $5;
8244 0 : n->newname = $10;
8245 0 : n->missing_ok = true;
8246 0 : $$ = (Node *)n;
8247 : }
8248 : | ALTER PUBLICATION name RENAME TO name
8249 : {
8250 3 : RenameStmt *n = makeNode(RenameStmt);
8251 3 : n->renameType = OBJECT_PUBLICATION;
8252 3 : n->object = (Node *) makeString($3);
8253 3 : n->newname = $6;
8254 3 : n->missing_ok = false;
8255 3 : $$ = (Node *)n;
8256 : }
8257 : | ALTER SCHEMA name RENAME TO name
8258 : {
8259 1 : RenameStmt *n = makeNode(RenameStmt);
8260 1 : n->renameType = OBJECT_SCHEMA;
8261 1 : n->subname = $3;
8262 1 : n->newname = $6;
8263 1 : n->missing_ok = false;
8264 1 : $$ = (Node *)n;
8265 : }
8266 : | ALTER SERVER name RENAME TO name
8267 : {
8268 4 : RenameStmt *n = makeNode(RenameStmt);
8269 4 : n->renameType = OBJECT_FOREIGN_SERVER;
8270 4 : n->object = (Node *) makeString($3);
8271 4 : n->newname = $6;
8272 4 : n->missing_ok = false;
8273 4 : $$ = (Node *)n;
8274 : }
8275 : | ALTER SUBSCRIPTION name RENAME TO name
8276 : {
8277 3 : RenameStmt *n = makeNode(RenameStmt);
8278 3 : n->renameType = OBJECT_SUBSCRIPTION;
8279 3 : n->object = (Node *) makeString($3);
8280 3 : n->newname = $6;
8281 3 : n->missing_ok = false;
8282 3 : $$ = (Node *)n;
8283 : }
8284 : | ALTER TABLE relation_expr RENAME TO name
8285 : {
8286 20 : RenameStmt *n = makeNode(RenameStmt);
8287 20 : n->renameType = OBJECT_TABLE;
8288 20 : n->relation = $3;
8289 20 : n->subname = NULL;
8290 20 : n->newname = $6;
8291 20 : n->missing_ok = false;
8292 20 : $$ = (Node *)n;
8293 : }
8294 : | ALTER TABLE IF_P EXISTS relation_expr RENAME TO name
8295 : {
8296 0 : RenameStmt *n = makeNode(RenameStmt);
8297 0 : n->renameType = OBJECT_TABLE;
8298 0 : n->relation = $5;
8299 0 : n->subname = NULL;
8300 0 : n->newname = $8;
8301 0 : n->missing_ok = true;
8302 0 : $$ = (Node *)n;
8303 : }
8304 : | ALTER SEQUENCE qualified_name RENAME TO name
8305 : {
8306 0 : RenameStmt *n = makeNode(RenameStmt);
8307 0 : n->renameType = OBJECT_SEQUENCE;
8308 0 : n->relation = $3;
8309 0 : n->subname = NULL;
8310 0 : n->newname = $6;
8311 0 : n->missing_ok = false;
8312 0 : $$ = (Node *)n;
8313 : }
8314 : | ALTER SEQUENCE IF_P EXISTS qualified_name RENAME TO name
8315 : {
8316 0 : RenameStmt *n = makeNode(RenameStmt);
8317 0 : n->renameType = OBJECT_SEQUENCE;
8318 0 : n->relation = $5;
8319 0 : n->subname = NULL;
8320 0 : n->newname = $8;
8321 0 : n->missing_ok = true;
8322 0 : $$ = (Node *)n;
8323 : }
8324 : | ALTER VIEW qualified_name RENAME TO name
8325 : {
8326 0 : RenameStmt *n = makeNode(RenameStmt);
8327 0 : n->renameType = OBJECT_VIEW;
8328 0 : n->relation = $3;
8329 0 : n->subname = NULL;
8330 0 : n->newname = $6;
8331 0 : n->missing_ok = false;
8332 0 : $$ = (Node *)n;
8333 : }
8334 : | ALTER VIEW IF_P EXISTS qualified_name RENAME TO name
8335 : {
8336 0 : RenameStmt *n = makeNode(RenameStmt);
8337 0 : n->renameType = OBJECT_VIEW;
8338 0 : n->relation = $5;
8339 0 : n->subname = NULL;
8340 0 : n->newname = $8;
8341 0 : n->missing_ok = true;
8342 0 : $$ = (Node *)n;
8343 : }
8344 : | ALTER MATERIALIZED VIEW qualified_name RENAME TO name
8345 : {
8346 0 : RenameStmt *n = makeNode(RenameStmt);
8347 0 : n->renameType = OBJECT_MATVIEW;
8348 0 : n->relation = $4;
8349 0 : n->subname = NULL;
8350 0 : n->newname = $7;
8351 0 : n->missing_ok = false;
8352 0 : $$ = (Node *)n;
8353 : }
8354 : | ALTER MATERIALIZED VIEW IF_P EXISTS qualified_name RENAME TO name
8355 : {
8356 0 : RenameStmt *n = makeNode(RenameStmt);
8357 0 : n->renameType = OBJECT_MATVIEW;
8358 0 : n->relation = $6;
8359 0 : n->subname = NULL;
8360 0 : n->newname = $9;
8361 0 : n->missing_ok = true;
8362 0 : $$ = (Node *)n;
8363 : }
8364 : | ALTER INDEX qualified_name RENAME TO name
8365 : {
8366 3 : RenameStmt *n = makeNode(RenameStmt);
8367 3 : n->renameType = OBJECT_INDEX;
8368 3 : n->relation = $3;
8369 3 : n->subname = NULL;
8370 3 : n->newname = $6;
8371 3 : n->missing_ok = false;
8372 3 : $$ = (Node *)n;
8373 : }
8374 : | ALTER INDEX IF_P EXISTS qualified_name RENAME TO name
8375 : {
8376 2 : RenameStmt *n = makeNode(RenameStmt);
8377 2 : n->renameType = OBJECT_INDEX;
8378 2 : n->relation = $5;
8379 2 : n->subname = NULL;
8380 2 : n->newname = $8;
8381 2 : n->missing_ok = true;
8382 2 : $$ = (Node *)n;
8383 : }
8384 : | ALTER FOREIGN TABLE relation_expr RENAME TO name
8385 : {
8386 1 : RenameStmt *n = makeNode(RenameStmt);
8387 1 : n->renameType = OBJECT_FOREIGN_TABLE;
8388 1 : n->relation = $4;
8389 1 : n->subname = NULL;
8390 1 : n->newname = $7;
8391 1 : n->missing_ok = false;
8392 1 : $$ = (Node *)n;
8393 : }
8394 : | ALTER FOREIGN TABLE IF_P EXISTS relation_expr RENAME TO name
8395 : {
8396 1 : RenameStmt *n = makeNode(RenameStmt);
8397 1 : n->renameType = OBJECT_FOREIGN_TABLE;
8398 1 : n->relation = $6;
8399 1 : n->subname = NULL;
8400 1 : n->newname = $9;
8401 1 : n->missing_ok = true;
8402 1 : $$ = (Node *)n;
8403 : }
8404 : | ALTER TABLE relation_expr RENAME opt_column name TO name
8405 : {
8406 34 : RenameStmt *n = makeNode(RenameStmt);
8407 34 : n->renameType = OBJECT_COLUMN;
8408 34 : n->relationType = OBJECT_TABLE;
8409 34 : n->relation = $3;
8410 34 : n->subname = $6;
8411 34 : n->newname = $8;
8412 34 : n->missing_ok = false;
8413 34 : $$ = (Node *)n;
8414 : }
8415 : | ALTER TABLE IF_P EXISTS relation_expr RENAME opt_column name TO name
8416 : {
8417 4 : RenameStmt *n = makeNode(RenameStmt);
8418 4 : n->renameType = OBJECT_COLUMN;
8419 4 : n->relationType = OBJECT_TABLE;
8420 4 : n->relation = $5;
8421 4 : n->subname = $8;
8422 4 : n->newname = $10;
8423 4 : n->missing_ok = true;
8424 4 : $$ = (Node *)n;
8425 : }
8426 : | ALTER MATERIALIZED VIEW qualified_name RENAME opt_column name TO name
8427 : {
8428 0 : RenameStmt *n = makeNode(RenameStmt);
8429 0 : n->renameType = OBJECT_COLUMN;
8430 0 : n->relationType = OBJECT_MATVIEW;
8431 0 : n->relation = $4;
8432 0 : n->subname = $7;
8433 0 : n->newname = $9;
8434 0 : n->missing_ok = false;
8435 0 : $$ = (Node *)n;
8436 : }
8437 : | ALTER MATERIALIZED VIEW IF_P EXISTS qualified_name RENAME opt_column name TO name
8438 : {
8439 0 : RenameStmt *n = makeNode(RenameStmt);
8440 0 : n->renameType = OBJECT_COLUMN;
8441 0 : n->relationType = OBJECT_MATVIEW;
8442 0 : n->relation = $6;
8443 0 : n->subname = $9;
8444 0 : n->newname = $11;
8445 0 : n->missing_ok = true;
8446 0 : $$ = (Node *)n;
8447 : }
8448 : | ALTER TABLE relation_expr RENAME CONSTRAINT name TO name
8449 : {
8450 9 : RenameStmt *n = makeNode(RenameStmt);
8451 9 : n->renameType = OBJECT_TABCONSTRAINT;
8452 9 : n->relation = $3;
8453 9 : n->subname = $6;
8454 9 : n->newname = $8;
8455 9 : n->missing_ok = false;
8456 9 : $$ = (Node *)n;
8457 : }
8458 : | ALTER TABLE IF_P EXISTS relation_expr RENAME CONSTRAINT name TO name
8459 : {
8460 1 : RenameStmt *n = makeNode(RenameStmt);
8461 1 : n->renameType = OBJECT_TABCONSTRAINT;
8462 1 : n->relation = $5;
8463 1 : n->subname = $8;
8464 1 : n->newname = $10;
8465 1 : n->missing_ok = true;
8466 1 : $$ = (Node *)n;
8467 : }
8468 : | ALTER FOREIGN TABLE relation_expr RENAME opt_column name TO name
8469 : {
8470 1 : RenameStmt *n = makeNode(RenameStmt);
8471 1 : n->renameType = OBJECT_COLUMN;
8472 1 : n->relationType = OBJECT_FOREIGN_TABLE;
8473 1 : n->relation = $4;
8474 1 : n->subname = $7;
8475 1 : n->newname = $9;
8476 1 : n->missing_ok = false;
8477 1 : $$ = (Node *)n;
8478 : }
8479 : | ALTER FOREIGN TABLE IF_P EXISTS relation_expr RENAME opt_column name TO name
8480 : {
8481 1 : RenameStmt *n = makeNode(RenameStmt);
8482 1 : n->renameType = OBJECT_COLUMN;
8483 1 : n->relationType = OBJECT_FOREIGN_TABLE;
8484 1 : n->relation = $6;
8485 1 : n->subname = $9;
8486 1 : n->newname = $11;
8487 1 : n->missing_ok = true;
8488 1 : $$ = (Node *)n;
8489 : }
8490 : | ALTER RULE name ON qualified_name RENAME TO name
8491 : {
8492 5 : RenameStmt *n = makeNode(RenameStmt);
8493 5 : n->renameType = OBJECT_RULE;
8494 5 : n->relation = $5;
8495 5 : n->subname = $3;
8496 5 : n->newname = $8;
8497 5 : n->missing_ok = false;
8498 5 : $$ = (Node *)n;
8499 : }
8500 : | ALTER TRIGGER name ON qualified_name RENAME TO name
8501 : {
8502 0 : RenameStmt *n = makeNode(RenameStmt);
8503 0 : n->renameType = OBJECT_TRIGGER;
8504 0 : n->relation = $5;
8505 0 : n->subname = $3;
8506 0 : n->newname = $8;
8507 0 : n->missing_ok = false;
8508 0 : $$ = (Node *)n;
8509 : }
8510 : | ALTER EVENT TRIGGER name RENAME TO name
8511 : {
8512 2 : RenameStmt *n = makeNode(RenameStmt);
8513 2 : n->renameType = OBJECT_EVENT_TRIGGER;
8514 2 : n->object = (Node *) makeString($4);
8515 2 : n->newname = $7;
8516 2 : $$ = (Node *)n;
8517 : }
8518 : | ALTER ROLE RoleId RENAME TO RoleId
8519 : {
8520 3 : RenameStmt *n = makeNode(RenameStmt);
8521 3 : n->renameType = OBJECT_ROLE;
8522 3 : n->subname = $3;
8523 3 : n->newname = $6;
8524 3 : n->missing_ok = false;
8525 3 : $$ = (Node *)n;
8526 : }
8527 : | ALTER USER RoleId RENAME TO RoleId
8528 : {
8529 0 : RenameStmt *n = makeNode(RenameStmt);
8530 0 : n->renameType = OBJECT_ROLE;
8531 0 : n->subname = $3;
8532 0 : n->newname = $6;
8533 0 : n->missing_ok = false;
8534 0 : $$ = (Node *)n;
8535 : }
8536 : | ALTER TABLESPACE name RENAME TO name
8537 : {
8538 1 : RenameStmt *n = makeNode(RenameStmt);
8539 1 : n->renameType = OBJECT_TABLESPACE;
8540 1 : n->subname = $3;
8541 1 : n->newname = $6;
8542 1 : n->missing_ok = false;
8543 1 : $$ = (Node *)n;
8544 : }
8545 : | ALTER STATISTICS any_name RENAME TO name
8546 : {
8547 4 : RenameStmt *n = makeNode(RenameStmt);
8548 4 : n->renameType = OBJECT_STATISTIC_EXT;
8549 4 : n->object = (Node *) $3;
8550 4 : n->newname = $6;
8551 4 : n->missing_ok = false;
8552 4 : $$ = (Node *)n;
8553 : }
8554 : | ALTER TEXT_P SEARCH PARSER any_name RENAME TO name
8555 : {
8556 2 : RenameStmt *n = makeNode(RenameStmt);
8557 2 : n->renameType = OBJECT_TSPARSER;
8558 2 : n->object = (Node *) $5;
8559 2 : n->newname = $8;
8560 2 : n->missing_ok = false;
8561 2 : $$ = (Node *)n;
8562 : }
8563 : | ALTER TEXT_P SEARCH DICTIONARY any_name RENAME TO name
8564 : {
8565 4 : RenameStmt *n = makeNode(RenameStmt);
8566 4 : n->renameType = OBJECT_TSDICTIONARY;
8567 4 : n->object = (Node *) $5;
8568 4 : n->newname = $8;
8569 4 : n->missing_ok = false;
8570 4 : $$ = (Node *)n;
8571 : }
8572 : | ALTER TEXT_P SEARCH TEMPLATE any_name RENAME TO name
8573 : {
8574 2 : RenameStmt *n = makeNode(RenameStmt);
8575 2 : n->renameType = OBJECT_TSTEMPLATE;
8576 2 : n->object = (Node *) $5;
8577 2 : n->newname = $8;
8578 2 : n->missing_ok = false;
8579 2 : $$ = (Node *)n;
8580 : }
8581 : | ALTER TEXT_P SEARCH CONFIGURATION any_name RENAME TO name
8582 : {
8583 4 : RenameStmt *n = makeNode(RenameStmt);
8584 4 : n->renameType = OBJECT_TSCONFIGURATION;
8585 4 : n->object = (Node *) $5;
8586 4 : n->newname = $8;
8587 4 : n->missing_ok = false;
8588 4 : $$ = (Node *)n;
8589 : }
8590 : | ALTER TYPE_P any_name RENAME TO name
8591 : {
8592 2 : RenameStmt *n = makeNode(RenameStmt);
8593 2 : n->renameType = OBJECT_TYPE;
8594 2 : n->object = (Node *) $3;
8595 2 : n->newname = $6;
8596 2 : n->missing_ok = false;
8597 2 : $$ = (Node *)n;
8598 : }
8599 : | ALTER TYPE_P any_name RENAME ATTRIBUTE name TO name opt_drop_behavior
8600 : {
8601 4 : RenameStmt *n = makeNode(RenameStmt);
8602 4 : n->renameType = OBJECT_ATTRIBUTE;
8603 4 : n->relationType = OBJECT_TYPE;
8604 4 : n->relation = makeRangeVarFromAnyName($3, @3, yyscanner);
8605 4 : n->subname = $6;
8606 4 : n->newname = $8;
8607 4 : n->behavior = $9;
8608 4 : n->missing_ok = false;
8609 4 : $$ = (Node *)n;
8610 : }
8611 : ;
8612 :
8613 233 : opt_column: COLUMN { $$ = COLUMN; }
8614 94 : | /*EMPTY*/ { $$ = 0; }
8615 : ;
8616 :
8617 14 : opt_set_data: SET DATA_P { $$ = 1; }
8618 56 : | /*EMPTY*/ { $$ = 0; }
8619 : ;
8620 :
8621 : /*****************************************************************************
8622 : *
8623 : * ALTER THING name DEPENDS ON EXTENSION name
8624 : *
8625 : *****************************************************************************/
8626 :
8627 : AlterObjectDependsStmt:
8628 : ALTER FUNCTION function_with_argtypes DEPENDS ON EXTENSION name
8629 : {
8630 0 : AlterObjectDependsStmt *n = makeNode(AlterObjectDependsStmt);
8631 0 : n->objectType = OBJECT_FUNCTION;
8632 0 : n->object = (Node *) $3;
8633 0 : n->extname = makeString($7);
8634 0 : $$ = (Node *)n;
8635 : }
8636 : | ALTER TRIGGER name ON qualified_name DEPENDS ON EXTENSION name
8637 : {
8638 0 : AlterObjectDependsStmt *n = makeNode(AlterObjectDependsStmt);
8639 0 : n->objectType = OBJECT_TRIGGER;
8640 0 : n->relation = $5;
8641 0 : n->object = (Node *) list_make1(makeString($3));
8642 0 : n->extname = makeString($9);
8643 0 : $$ = (Node *)n;
8644 : }
8645 : | ALTER MATERIALIZED VIEW qualified_name DEPENDS ON EXTENSION name
8646 : {
8647 0 : AlterObjectDependsStmt *n = makeNode(AlterObjectDependsStmt);
8648 0 : n->objectType = OBJECT_MATVIEW;
8649 0 : n->relation = $4;
8650 0 : n->extname = makeString($8);
8651 0 : $$ = (Node *)n;
8652 : }
8653 : | ALTER INDEX qualified_name DEPENDS ON EXTENSION name
8654 : {
8655 0 : AlterObjectDependsStmt *n = makeNode(AlterObjectDependsStmt);
8656 0 : n->objectType = OBJECT_INDEX;
8657 0 : n->relation = $3;
8658 0 : n->extname = makeString($7);
8659 0 : $$ = (Node *)n;
8660 : }
8661 : ;
8662 :
8663 : /*****************************************************************************
8664 : *
8665 : * ALTER THING name SET SCHEMA name
8666 : *
8667 : *****************************************************************************/
8668 :
8669 : AlterObjectSchemaStmt:
8670 : ALTER AGGREGATE aggregate_with_argtypes SET SCHEMA name
8671 : {
8672 4 : AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
8673 4 : n->objectType = OBJECT_AGGREGATE;
8674 4 : n->object = (Node *) $3;
8675 4 : n->newschema = $6;
8676 4 : n->missing_ok = false;
8677 4 : $$ = (Node *)n;
8678 : }
8679 : | ALTER COLLATION any_name SET SCHEMA name
8680 : {
8681 0 : AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
8682 0 : n->objectType = OBJECT_COLLATION;
8683 0 : n->object = (Node *) $3;
8684 0 : n->newschema = $6;
8685 0 : n->missing_ok = false;
8686 0 : $$ = (Node *)n;
8687 : }
8688 : | ALTER CONVERSION_P any_name SET SCHEMA name
8689 : {
8690 4 : AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
8691 4 : n->objectType = OBJECT_CONVERSION;
8692 4 : n->object = (Node *) $3;
8693 4 : n->newschema = $6;
8694 4 : n->missing_ok = false;
8695 4 : $$ = (Node *)n;
8696 : }
8697 : | ALTER DOMAIN_P any_name SET SCHEMA name
8698 : {
8699 1 : AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
8700 1 : n->objectType = OBJECT_DOMAIN;
8701 1 : n->object = (Node *) $3;
8702 1 : n->newschema = $6;
8703 1 : n->missing_ok = false;
8704 1 : $$ = (Node *)n;
8705 : }
8706 : | ALTER EXTENSION name SET SCHEMA name
8707 : {
8708 0 : AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
8709 0 : n->objectType = OBJECT_EXTENSION;
8710 0 : n->object = (Node *) makeString($3);
8711 0 : n->newschema = $6;
8712 0 : n->missing_ok = false;
8713 0 : $$ = (Node *)n;
8714 : }
8715 : | ALTER FUNCTION function_with_argtypes SET SCHEMA name
8716 : {
8717 6 : AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
8718 6 : n->objectType = OBJECT_FUNCTION;
8719 6 : n->object = (Node *) $3;
8720 6 : n->newschema = $6;
8721 6 : n->missing_ok = false;
8722 6 : $$ = (Node *)n;
8723 : }
8724 : | ALTER OPERATOR operator_with_argtypes SET SCHEMA name
8725 : {
8726 3 : AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
8727 3 : n->objectType = OBJECT_OPERATOR;
8728 3 : n->object = (Node *) $3;
8729 3 : n->newschema = $6;
8730 3 : n->missing_ok = false;
8731 3 : $$ = (Node *)n;
8732 : }
8733 : | ALTER OPERATOR CLASS any_name USING access_method SET SCHEMA name
8734 : {
8735 4 : AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
8736 4 : n->objectType = OBJECT_OPCLASS;
8737 4 : n->object = (Node *) lcons(makeString($6), $4);
8738 4 : n->newschema = $9;
8739 4 : n->missing_ok = false;
8740 4 : $$ = (Node *)n;
8741 : }
8742 : | ALTER OPERATOR FAMILY any_name USING access_method SET SCHEMA name
8743 : {
8744 4 : AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
8745 4 : n->objectType = OBJECT_OPFAMILY;
8746 4 : n->object = (Node *) lcons(makeString($6), $4);
8747 4 : n->newschema = $9;
8748 4 : n->missing_ok = false;
8749 4 : $$ = (Node *)n;
8750 : }
8751 : | ALTER TABLE relation_expr SET SCHEMA name
8752 : {
8753 8 : AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
8754 8 : n->objectType = OBJECT_TABLE;
8755 8 : n->relation = $3;
8756 8 : n->newschema = $6;
8757 8 : n->missing_ok = false;
8758 8 : $$ = (Node *)n;
8759 : }
8760 : | ALTER TABLE IF_P EXISTS relation_expr SET SCHEMA name
8761 : {
8762 2 : AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
8763 2 : n->objectType = OBJECT_TABLE;
8764 2 : n->relation = $5;
8765 2 : n->newschema = $8;
8766 2 : n->missing_ok = true;
8767 2 : $$ = (Node *)n;
8768 : }
8769 : | ALTER STATISTICS any_name SET SCHEMA name
8770 : {
8771 3 : AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
8772 3 : n->objectType = OBJECT_STATISTIC_EXT;
8773 3 : n->object = (Node *) $3;
8774 3 : n->newschema = $6;
8775 3 : n->missing_ok = false;
8776 3 : $$ = (Node *)n;
8777 : }
8778 : | ALTER TEXT_P SEARCH PARSER any_name SET SCHEMA name
8779 : {
8780 3 : AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
8781 3 : n->objectType = OBJECT_TSPARSER;
8782 3 : n->object = (Node *) $5;
8783 3 : n->newschema = $8;
8784 3 : n->missing_ok = false;
8785 3 : $$ = (Node *)n;
8786 : }
8787 : | ALTER TEXT_P SEARCH DICTIONARY any_name SET SCHEMA name
8788 : {
8789 4 : AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
8790 4 : n->objectType = OBJECT_TSDICTIONARY;
8791 4 : n->object = (Node *) $5;
8792 4 : n->newschema = $8;
8793 4 : n->missing_ok = false;
8794 4 : $$ = (Node *)n;
8795 : }
8796 : | ALTER TEXT_P SEARCH TEMPLATE any_name SET SCHEMA name
8797 : {
8798 3 : AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
8799 3 : n->objectType = OBJECT_TSTEMPLATE;
8800 3 : n->object = (Node *) $5;
8801 3 : n->newschema = $8;
8802 3 : n->missing_ok = false;
8803 3 : $$ = (Node *)n;
8804 : }
8805 : | ALTER TEXT_P SEARCH CONFIGURATION any_name SET SCHEMA name
8806 : {
8807 4 : AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
8808 4 : n->objectType = OBJECT_TSCONFIGURATION;
8809 4 : n->object = (Node *) $5;
8810 4 : n->newschema = $8;
8811 4 : n->missing_ok = false;
8812 4 : $$ = (Node *)n;
8813 : }
8814 : | ALTER SEQUENCE qualified_name SET SCHEMA name
8815 : {
8816 0 : AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
8817 0 : n->objectType = OBJECT_SEQUENCE;
8818 0 : n->relation = $3;
8819 0 : n->newschema = $6;
8820 0 : n->missing_ok = false;
8821 0 : $$ = (Node *)n;
8822 : }
8823 : | ALTER SEQUENCE IF_P EXISTS qualified_name SET SCHEMA name
8824 : {
8825 0 : AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
8826 0 : n->objectType = OBJECT_SEQUENCE;
8827 0 : n->relation = $5;
8828 0 : n->newschema = $8;
8829 0 : n->missing_ok = true;
8830 0 : $$ = (Node *)n;
8831 : }
8832 : | ALTER VIEW qualified_name SET SCHEMA name
8833 : {
8834 0 : AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
8835 0 : n->objectType = OBJECT_VIEW;
8836 0 : n->relation = $3;
8837 0 : n->newschema = $6;
8838 0 : n->missing_ok = false;
8839 0 : $$ = (Node *)n;
8840 : }
8841 : | ALTER VIEW IF_P EXISTS qualified_name SET SCHEMA name
8842 : {
8843 0 : AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
8844 0 : n->objectType = OBJECT_VIEW;
8845 0 : n->relation = $5;
8846 0 : n->newschema = $8;
8847 0 : n->missing_ok = true;
8848 0 : $$ = (Node *)n;
8849 : }
8850 : | ALTER MATERIALIZED VIEW qualified_name SET SCHEMA name
8851 : {
8852 1 : AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
8853 1 : n->objectType = OBJECT_MATVIEW;
8854 1 : n->relation = $4;
8855 1 : n->newschema = $7;
8856 1 : n->missing_ok = false;
8857 1 : $$ = (Node *)n;
8858 : }
8859 : | ALTER MATERIALIZED VIEW IF_P EXISTS qualified_name SET SCHEMA name
8860 : {
8861 0 : AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
8862 0 : n->objectType = OBJECT_MATVIEW;
8863 0 : n->relation = $6;
8864 0 : n->newschema = $9;
8865 0 : n->missing_ok = true;
8866 0 : $$ = (Node *)n;
8867 : }
8868 : | ALTER FOREIGN TABLE relation_expr SET SCHEMA name
8869 : {
8870 1 : AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
8871 1 : n->objectType = OBJECT_FOREIGN_TABLE;
8872 1 : n->relation = $4;
8873 1 : n->newschema = $7;
8874 1 : n->missing_ok = false;
8875 1 : $$ = (Node *)n;
8876 : }
8877 : | ALTER FOREIGN TABLE IF_P EXISTS relation_expr SET SCHEMA name
8878 : {
8879 1 : AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
8880 1 : n->objectType = OBJECT_FOREIGN_TABLE;
8881 1 : n->relation = $6;
8882 1 : n->newschema = $9;
8883 1 : n->missing_ok = true;
8884 1 : $$ = (Node *)n;
8885 : }
8886 : | ALTER TYPE_P any_name SET SCHEMA name
8887 : {
8888 2 : AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
8889 2 : n->objectType = OBJECT_TYPE;
8890 2 : n->object = (Node *) $3;
8891 2 : n->newschema = $6;
8892 2 : n->missing_ok = false;
8893 2 : $$ = (Node *)n;
8894 : }
8895 : ;
8896 :
8897 : /*****************************************************************************
8898 : *
8899 : * ALTER OPERATOR name SET define
8900 : *
8901 : *****************************************************************************/
8902 :
8903 : AlterOperatorStmt:
8904 : ALTER OPERATOR operator_with_argtypes SET '(' operator_def_list ')'
8905 : {
8906 13 : AlterOperatorStmt *n = makeNode(AlterOperatorStmt);
8907 13 : n->opername = $3;
8908 13 : n->options = $6;
8909 13 : $$ = (Node *)n;
8910 : }
8911 : ;
8912 :
8913 13 : operator_def_list: operator_def_elem { $$ = list_make1($1); }
8914 2 : | operator_def_list ',' operator_def_elem { $$ = lappend($1, $3); }
8915 : ;
8916 :
8917 : operator_def_elem: ColLabel '=' NONE
8918 5 : { $$ = makeDefElem($1, NULL, @1); }
8919 : | ColLabel '=' operator_def_arg
8920 10 : { $$ = makeDefElem($1, (Node *) $3, @1); }
8921 : ;
8922 :
8923 : /* must be similar enough to def_arg to avoid reduce/reduce conflicts */
8924 : operator_def_arg:
8925 6 : func_type { $$ = (Node *)$1; }
8926 0 : | reserved_keyword { $$ = (Node *)makeString(pstrdup($1)); }
8927 4 : | qual_all_Op { $$ = (Node *)$1; }
8928 0 : | NumericOnly { $$ = (Node *)$1; }
8929 0 : | Sconst { $$ = (Node *)makeString($1); }
8930 : ;
8931 :
8932 : /*****************************************************************************
8933 : *
8934 : * ALTER THING name OWNER TO newname
8935 : *
8936 : *****************************************************************************/
8937 :
8938 : AlterOwnerStmt: ALTER AGGREGATE aggregate_with_argtypes OWNER TO RoleSpec
8939 : {
8940 13 : AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
8941 13 : n->objectType = OBJECT_AGGREGATE;
8942 13 : n->object = (Node *) $3;
8943 13 : n->newowner = $6;
8944 13 : $$ = (Node *)n;
8945 : }
8946 : | ALTER COLLATION any_name OWNER TO RoleSpec
8947 : {
8948 0 : AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
8949 0 : n->objectType = OBJECT_COLLATION;
8950 0 : n->object = (Node *) $3;
8951 0 : n->newowner = $6;
8952 0 : $$ = (Node *)n;
8953 : }
8954 : | ALTER CONVERSION_P any_name OWNER TO RoleSpec
8955 : {
8956 4 : AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
8957 4 : n->objectType = OBJECT_CONVERSION;
8958 4 : n->object = (Node *) $3;
8959 4 : n->newowner = $6;
8960 4 : $$ = (Node *)n;
8961 : }
8962 : | ALTER DATABASE database_name OWNER TO RoleSpec
8963 : {
8964 0 : AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
8965 0 : n->objectType = OBJECT_DATABASE;
8966 0 : n->object = (Node *) makeString($3);
8967 0 : n->newowner = $6;
8968 0 : $$ = (Node *)n;
8969 : }
8970 : | ALTER DOMAIN_P any_name OWNER TO RoleSpec
8971 : {
8972 0 : AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
8973 0 : n->objectType = OBJECT_DOMAIN;
8974 0 : n->object = (Node *) $3;
8975 0 : n->newowner = $6;
8976 0 : $$ = (Node *)n;
8977 : }
8978 : | ALTER FUNCTION function_with_argtypes OWNER TO RoleSpec
8979 : {
8980 6 : AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
8981 6 : n->objectType = OBJECT_FUNCTION;
8982 6 : n->object = (Node *) $3;
8983 6 : n->newowner = $6;
8984 6 : $$ = (Node *)n;
8985 : }
8986 : | ALTER opt_procedural LANGUAGE name OWNER TO RoleSpec
8987 : {
8988 5 : AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
8989 5 : n->objectType = OBJECT_LANGUAGE;
8990 5 : n->object = (Node *) makeString($4);
8991 5 : n->newowner = $7;
8992 5 : $$ = (Node *)n;
8993 : }
8994 : | ALTER LARGE_P OBJECT_P NumericOnly OWNER TO RoleSpec
8995 : {
8996 1 : AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
8997 1 : n->objectType = OBJECT_LARGEOBJECT;
8998 1 : n->object = (Node *) $4;
8999 1 : n->newowner = $7;
9000 1 : $$ = (Node *)n;
9001 : }
9002 : | ALTER OPERATOR operator_with_argtypes OWNER TO RoleSpec
9003 : {
9004 4 : AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
9005 4 : n->objectType = OBJECT_OPERATOR;
9006 4 : n->object = (Node *) $3;
9007 4 : n->newowner = $6;
9008 4 : $$ = (Node *)n;
9009 : }
9010 : | ALTER OPERATOR CLASS any_name USING access_method OWNER TO RoleSpec
9011 : {
9012 8 : AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
9013 8 : n->objectType = OBJECT_OPCLASS;
9014 8 : n->object = (Node *) lcons(makeString($6), $4);
9015 8 : n->newowner = $9;
9016 8 : $$ = (Node *)n;
9017 : }
9018 : | ALTER OPERATOR FAMILY any_name USING access_method OWNER TO RoleSpec
9019 : {
9020 8 : AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
9021 8 : n->objectType = OBJECT_OPFAMILY;
9022 8 : n->object = (Node *) lcons(makeString($6), $4);
9023 8 : n->newowner = $9;
9024 8 : $$ = (Node *)n;
9025 : }
9026 : | ALTER SCHEMA name OWNER TO RoleSpec
9027 : {
9028 1 : AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
9029 1 : n->objectType = OBJECT_SCHEMA;
9030 1 : n->object = (Node *) makeString($3);
9031 1 : n->newowner = $6;
9032 1 : $$ = (Node *)n;
9033 : }
9034 : | ALTER TYPE_P any_name OWNER TO RoleSpec
9035 : {
9036 0 : AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
9037 0 : n->objectType = OBJECT_TYPE;
9038 0 : n->object = (Node *) $3;
9039 0 : n->newowner = $6;
9040 0 : $$ = (Node *)n;
9041 : }
9042 : | ALTER TABLESPACE name OWNER TO RoleSpec
9043 : {
9044 1 : AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
9045 1 : n->objectType = OBJECT_TABLESPACE;
9046 1 : n->object = (Node *) makeString($3);
9047 1 : n->newowner = $6;
9048 1 : $$ = (Node *)n;
9049 : }
9050 : | ALTER STATISTICS any_name OWNER TO RoleSpec
9051 : {
9052 4 : AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
9053 4 : n->objectType = OBJECT_STATISTIC_EXT;
9054 4 : n->object = (Node *) $3;
9055 4 : n->newowner = $6;
9056 4 : $$ = (Node *)n;
9057 : }
9058 : | ALTER TEXT_P SEARCH DICTIONARY any_name OWNER TO RoleSpec
9059 : {
9060 4 : AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
9061 4 : n->objectType = OBJECT_TSDICTIONARY;
9062 4 : n->object = (Node *) $5;
9063 4 : n->newowner = $8;
9064 4 : $$ = (Node *)n;
9065 : }
9066 : | ALTER TEXT_P SEARCH CONFIGURATION any_name OWNER TO RoleSpec
9067 : {
9068 4 : AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
9069 4 : n->objectType = OBJECT_TSCONFIGURATION;
9070 4 : n->object = (Node *) $5;
9071 4 : n->newowner = $8;
9072 4 : $$ = (Node *)n;
9073 : }
9074 : | ALTER FOREIGN DATA_P WRAPPER name OWNER TO RoleSpec
9075 : {
9076 3 : AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
9077 3 : n->objectType = OBJECT_FDW;
9078 3 : n->object = (Node *) makeString($5);
9079 3 : n->newowner = $8;
9080 3 : $$ = (Node *)n;
9081 : }
9082 : | ALTER SERVER name OWNER TO RoleSpec
9083 : {
9084 11 : AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
9085 11 : n->objectType = OBJECT_FOREIGN_SERVER;
9086 11 : n->object = (Node *) makeString($3);
9087 11 : n->newowner = $6;
9088 11 : $$ = (Node *)n;
9089 : }
9090 : | ALTER EVENT TRIGGER name OWNER TO RoleSpec
9091 : {
9092 2 : AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
9093 2 : n->objectType = OBJECT_EVENT_TRIGGER;
9094 2 : n->object = (Node *) makeString($4);
9095 2 : n->newowner = $7;
9096 2 : $$ = (Node *)n;
9097 : }
9098 : | ALTER PUBLICATION name OWNER TO RoleSpec
9099 : {
9100 1 : AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
9101 1 : n->objectType = OBJECT_PUBLICATION;
9102 1 : n->object = (Node *) makeString($3);
9103 1 : n->newowner = $6;
9104 1 : $$ = (Node *)n;
9105 : }
9106 : | ALTER SUBSCRIPTION name OWNER TO RoleSpec
9107 : {
9108 2 : AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
9109 2 : n->objectType = OBJECT_SUBSCRIPTION;
9110 2 : n->object = (Node *) makeString($3);
9111 2 : n->newowner = $6;
9112 2 : $$ = (Node *)n;
9113 : }
9114 : ;
9115 :
9116 :
9117 : /*****************************************************************************
9118 : *
9119 : * CREATE PUBLICATION name [ FOR TABLE ] [ WITH options ]
9120 : *
9121 : *****************************************************************************/
9122 :
9123 : CreatePublicationStmt:
9124 : CREATE PUBLICATION name opt_publication_for_tables opt_definition
9125 : {
9126 13 : CreatePublicationStmt *n = makeNode(CreatePublicationStmt);
9127 13 : n->pubname = $3;
9128 13 : n->options = $5;
9129 13 : if ($4 != NULL)
9130 : {
9131 : /* FOR TABLE */
9132 7 : if (IsA($4, List))
9133 6 : n->tables = (List *)$4;
9134 : /* FOR ALL TABLES */
9135 : else
9136 1 : n->for_all_tables = TRUE;
9137 : }
9138 13 : $$ = (Node *)n;
9139 : }
9140 : ;
9141 :
9142 : opt_publication_for_tables:
9143 7 : publication_for_tables { $$ = $1; }
9144 6 : | /* EMPTY */ { $$ = NULL; }
9145 : ;
9146 :
9147 : publication_for_tables:
9148 : FOR TABLE relation_expr_list
9149 : {
9150 6 : $$ = (Node *) $3;
9151 : }
9152 : | FOR ALL TABLES
9153 : {
9154 1 : $$ = (Node *) makeInteger(TRUE);
9155 : }
9156 : ;
9157 :
9158 :
9159 : /*****************************************************************************
9160 : *
9161 : * ALTER PUBLICATION name SET ( options )
9162 : *
9163 : * ALTER PUBLICATION name ADD TABLE table [, table2]
9164 : *
9165 : * ALTER PUBLICATION name DROP TABLE table [, table2]
9166 : *
9167 : * ALTER PUBLICATION name SET TABLE table [, table2]
9168 : *
9169 : *****************************************************************************/
9170 :
9171 : AlterPublicationStmt:
9172 : ALTER PUBLICATION name SET definition
9173 : {
9174 3 : AlterPublicationStmt *n = makeNode(AlterPublicationStmt);
9175 3 : n->pubname = $3;
9176 3 : n->options = $5;
9177 3 : $$ = (Node *)n;
9178 : }
9179 : | ALTER PUBLICATION name ADD_P TABLE relation_expr_list
9180 : {
9181 9 : AlterPublicationStmt *n = makeNode(AlterPublicationStmt);
9182 9 : n->pubname = $3;
9183 9 : n->tables = $6;
9184 9 : n->tableAction = DEFELEM_ADD;
9185 9 : $$ = (Node *)n;
9186 : }
9187 : | ALTER PUBLICATION name SET TABLE relation_expr_list
9188 : {
9189 2 : AlterPublicationStmt *n = makeNode(AlterPublicationStmt);
9190 2 : n->pubname = $3;
9191 2 : n->tables = $6;
9192 2 : n->tableAction = DEFELEM_SET;
9193 2 : $$ = (Node *)n;
9194 : }
9195 : | ALTER PUBLICATION name DROP TABLE relation_expr_list
9196 : {
9197 3 : AlterPublicationStmt *n = makeNode(AlterPublicationStmt);
9198 3 : n->pubname = $3;
9199 3 : n->tables = $6;
9200 3 : n->tableAction = DEFELEM_DROP;
9201 3 : $$ = (Node *)n;
9202 : }
9203 : ;
9204 :
9205 : /*****************************************************************************
9206 : *
9207 : * CREATE SUBSCRIPTION name ...
9208 : *
9209 : *****************************************************************************/
9210 :
9211 : CreateSubscriptionStmt:
9212 : CREATE SUBSCRIPTION name CONNECTION Sconst PUBLICATION publication_name_list opt_definition
9213 : {
9214 16 : CreateSubscriptionStmt *n =
9215 16 : makeNode(CreateSubscriptionStmt);
9216 16 : n->subname = $3;
9217 16 : n->conninfo = $5;
9218 16 : n->publication = $7;
9219 16 : n->options = $8;
9220 16 : $$ = (Node *)n;
9221 : }
9222 : ;
9223 :
9224 : publication_name_list:
9225 : publication_name_item
9226 : {
9227 17 : $$ = list_make1($1);
9228 : }
9229 : | publication_name_list ',' publication_name_item
9230 : {
9231 3 : $$ = lappend($1, $3);
9232 : }
9233 : ;
9234 :
9235 : publication_name_item:
9236 20 : ColLabel { $$ = makeString($1); };
9237 :
9238 : /*****************************************************************************
9239 : *
9240 : * ALTER SUBSCRIPTION name ...
9241 : *
9242 : *****************************************************************************/
9243 :
9244 : AlterSubscriptionStmt:
9245 : ALTER SUBSCRIPTION name SET definition
9246 : {
9247 5 : AlterSubscriptionStmt *n =
9248 5 : makeNode(AlterSubscriptionStmt);
9249 5 : n->kind = ALTER_SUBSCRIPTION_OPTIONS;
9250 5 : n->subname = $3;
9251 5 : n->options = $5;
9252 5 : $$ = (Node *)n;
9253 : }
9254 : | ALTER SUBSCRIPTION name CONNECTION Sconst
9255 : {
9256 3 : AlterSubscriptionStmt *n =
9257 3 : makeNode(AlterSubscriptionStmt);
9258 3 : n->kind = ALTER_SUBSCRIPTION_CONNECTION;
9259 3 : n->subname = $3;
9260 3 : n->conninfo = $5;
9261 3 : $$ = (Node *)n;
9262 : }
9263 : | ALTER SUBSCRIPTION name REFRESH PUBLICATION opt_definition
9264 : {
9265 1 : AlterSubscriptionStmt *n =
9266 1 : makeNode(AlterSubscriptionStmt);
9267 1 : n->kind = ALTER_SUBSCRIPTION_REFRESH;
9268 1 : n->subname = $3;
9269 1 : n->options = $6;
9270 1 : $$ = (Node *)n;
9271 : }
9272 : | ALTER SUBSCRIPTION name SET PUBLICATION publication_name_list opt_definition
9273 : {
9274 1 : AlterSubscriptionStmt *n =
9275 1 : makeNode(AlterSubscriptionStmt);
9276 1 : n->kind = ALTER_SUBSCRIPTION_PUBLICATION;
9277 1 : n->subname = $3;
9278 1 : n->publication = $6;
9279 1 : n->options = $7;
9280 1 : $$ = (Node *)n;
9281 : }
9282 : | ALTER SUBSCRIPTION name ENABLE_P
9283 : {
9284 2 : AlterSubscriptionStmt *n =
9285 2 : makeNode(AlterSubscriptionStmt);
9286 2 : n->kind = ALTER_SUBSCRIPTION_ENABLED;
9287 2 : n->subname = $3;
9288 2 : n->options = list_make1(makeDefElem("enabled",
9289 : (Node *)makeInteger(TRUE), @1));
9290 2 : $$ = (Node *)n;
9291 : }
9292 : | ALTER SUBSCRIPTION name DISABLE_P
9293 : {
9294 1 : AlterSubscriptionStmt *n =
9295 1 : makeNode(AlterSubscriptionStmt);
9296 1 : n->kind = ALTER_SUBSCRIPTION_ENABLED;
9297 1 : n->subname = $3;
9298 1 : n->options = list_make1(makeDefElem("enabled",
9299 : (Node *)makeInteger(FALSE), @1));
9300 1 : $$ = (Node *)n;
9301 : }
9302 : ;
9303 :
9304 : /*****************************************************************************
9305 : *
9306 : * DROP SUBSCRIPTION [ IF EXISTS ] name
9307 : *
9308 : *****************************************************************************/
9309 :
9310 : DropSubscriptionStmt: DROP SUBSCRIPTION name opt_drop_behavior
9311 : {
9312 5 : DropSubscriptionStmt *n = makeNode(DropSubscriptionStmt);
9313 5 : n->subname = $3;
9314 5 : n->missing_ok = false;
9315 5 : n->behavior = $4;
9316 5 : $$ = (Node *) n;
9317 : }
9318 : | DROP SUBSCRIPTION IF_P EXISTS name opt_drop_behavior
9319 : {
9320 1 : DropSubscriptionStmt *n = makeNode(DropSubscriptionStmt);
9321 1 : n->subname = $5;
9322 1 : n->missing_ok = true;
9323 1 : n->behavior = $6;
9324 1 : $$ = (Node *) n;
9325 : }
9326 : ;
9327 :
9328 : /*****************************************************************************
9329 : *
9330 : * QUERY: Define Rewrite Rule
9331 : *
9332 : *****************************************************************************/
9333 :
9334 : RuleStmt: CREATE opt_or_replace RULE name AS
9335 : ON event TO qualified_name where_clause
9336 : DO opt_instead RuleActionList
9337 : {
9338 101 : RuleStmt *n = makeNode(RuleStmt);
9339 101 : n->replace = $2;
9340 101 : n->relation = $9;
9341 101 : n->rulename = $4;
9342 101 : n->whereClause = $10;
9343 101 : n->event = $7;
9344 101 : n->instead = $12;
9345 101 : n->actions = $13;
9346 101 : $$ = (Node *)n;
9347 : }
9348 : ;
9349 :
9350 : RuleActionList:
9351 8 : NOTHING { $$ = NIL; }
9352 87 : | RuleActionStmt { $$ = list_make1($1); }
9353 6 : | '(' RuleActionMulti ')' { $$ = $2; }
9354 : ;
9355 :
9356 : /* the thrashing around here is to discard "empty" statements... */
9357 : RuleActionMulti:
9358 : RuleActionMulti ';' RuleActionStmtOrEmpty
9359 8 : { if ($3 != NULL)
9360 6 : $$ = lappend($1, $3);
9361 : else
9362 2 : $$ = $1;
9363 : }
9364 : | RuleActionStmtOrEmpty
9365 6 : { if ($1 != NULL)
9366 6 : $$ = list_make1($1);
9367 : else
9368 0 : $$ = NIL;
9369 : }
9370 : ;
9371 :
9372 : RuleActionStmt:
9373 : SelectStmt
9374 : | InsertStmt
9375 : | UpdateStmt
9376 : | DeleteStmt
9377 : | NotifyStmt
9378 : ;
9379 :
9380 : RuleActionStmtOrEmpty:
9381 12 : RuleActionStmt { $$ = $1; }
9382 2 : | /*EMPTY*/ { $$ = NULL; }
9383 : ;
9384 :
9385 6 : event: SELECT { $$ = CMD_SELECT; }
9386 26 : | UPDATE { $$ = CMD_UPDATE; }
9387 18 : | DELETE_P { $$ = CMD_DELETE; }
9388 51 : | INSERT { $$ = CMD_INSERT; }
9389 : ;
9390 :
9391 : opt_instead:
9392 78 : INSTEAD { $$ = TRUE; }
9393 13 : | ALSO { $$ = FALSE; }
9394 10 : | /*EMPTY*/ { $$ = FALSE; }
9395 : ;
9396 :
9397 :
9398 : /*****************************************************************************
9399 : *
9400 : * QUERY:
9401 : * NOTIFY <identifier> can appear both in rule bodies and
9402 : * as a query-level command
9403 : *
9404 : *****************************************************************************/
9405 :
9406 : NotifyStmt: NOTIFY ColId notify_payload
9407 : {
9408 2 : NotifyStmt *n = makeNode(NotifyStmt);
9409 2 : n->conditionname = $2;
9410 2 : n->payload = $3;
9411 2 : $$ = (Node *)n;
9412 : }
9413 : ;
9414 :
9415 : notify_payload:
9416 0 : ',' Sconst { $$ = $2; }
9417 2 : | /*EMPTY*/ { $$ = NULL; }
9418 : ;
9419 :
9420 : ListenStmt: LISTEN ColId
9421 : {
9422 2 : ListenStmt *n = makeNode(ListenStmt);
9423 2 : n->conditionname = $2;
9424 2 : $$ = (Node *)n;
9425 : }
9426 : ;
9427 :
9428 : UnlistenStmt:
9429 : UNLISTEN ColId
9430 : {
9431 1 : UnlistenStmt *n = makeNode(UnlistenStmt);
9432 1 : n->conditionname = $2;
9433 1 : $$ = (Node *)n;
9434 : }
9435 : | UNLISTEN '*'
9436 : {
9437 1 : UnlistenStmt *n = makeNode(UnlistenStmt);
9438 1 : n->conditionname = NULL;
9439 1 : $$ = (Node *)n;
9440 : }
9441 : ;
9442 :
9443 :
9444 : /*****************************************************************************
9445 : *
9446 : * Transactions:
9447 : *
9448 : * BEGIN / COMMIT / ROLLBACK
9449 : * (also older versions END / ABORT)
9450 : *
9451 : *****************************************************************************/
9452 :
9453 : TransactionStmt:
9454 : ABORT_P opt_transaction
9455 : {
9456 4 : TransactionStmt *n = makeNode(TransactionStmt);
9457 4 : n->kind = TRANS_STMT_ROLLBACK;
9458 4 : n->options = NIL;
9459 4 : $$ = (Node *)n;
9460 : }
9461 : | BEGIN_P opt_transaction transaction_mode_list_or_empty
9462 : {
9463 305 : TransactionStmt *n = makeNode(TransactionStmt);
9464 305 : n->kind = TRANS_STMT_BEGIN;
9465 305 : n->options = $3;
9466 305 : $$ = (Node *)n;
9467 : }
9468 : | START TRANSACTION transaction_mode_list_or_empty
9469 : {
9470 3 : TransactionStmt *n = makeNode(TransactionStmt);
9471 3 : n->kind = TRANS_STMT_START;
9472 3 : n->options = $3;
9473 3 : $$ = (Node *)n;
9474 : }
9475 : | COMMIT opt_transaction
9476 : {
9477 147 : TransactionStmt *n = makeNode(TransactionStmt);
9478 147 : n->kind = TRANS_STMT_COMMIT;
9479 147 : n->options = NIL;
9480 147 : $$ = (Node *)n;
9481 : }
9482 : | END_P opt_transaction
9483 : {
9484 15 : TransactionStmt *n = makeNode(TransactionStmt);
9485 15 : n->kind = TRANS_STMT_COMMIT;
9486 15 : n->options = NIL;
9487 15 : $$ = (Node *)n;
9488 : }
9489 : | ROLLBACK opt_transaction
9490 : {
9491 137 : TransactionStmt *n = makeNode(TransactionStmt);
9492 137 : n->kind = TRANS_STMT_ROLLBACK;
9493 137 : n->options = NIL;
9494 137 : $$ = (Node *)n;
9495 : }
9496 : | SAVEPOINT ColId
9497 : {
9498 73 : TransactionStmt *n = makeNode(TransactionStmt);
9499 73 : n->kind = TRANS_STMT_SAVEPOINT;
9500 73 : n->options = list_make1(makeDefElem("savepoint_name",
9501 : (Node *)makeString($2), @1));
9502 73 : $$ = (Node *)n;
9503 : }
9504 : | RELEASE SAVEPOINT ColId
9505 : {
9506 16 : TransactionStmt *n = makeNode(TransactionStmt);
9507 16 : n->kind = TRANS_STMT_RELEASE;
9508 16 : n->options = list_make1(makeDefElem("savepoint_name",
9509 : (Node *)makeString($3), @1));
9510 16 : $$ = (Node *)n;
9511 : }
9512 : | RELEASE ColId
9513 : {
9514 1 : TransactionStmt *n = makeNode(TransactionStmt);
9515 1 : n->kind = TRANS_STMT_RELEASE;
9516 1 : n->options = list_make1(makeDefElem("savepoint_name",
9517 : (Node *)makeString($2), @1));
9518 1 : $$ = (Node *)n;
9519 : }
9520 : | ROLLBACK opt_transaction TO SAVEPOINT ColId
9521 : {
9522 22 : TransactionStmt *n = makeNode(TransactionStmt);
9523 22 : n->kind = TRANS_STMT_ROLLBACK_TO;
9524 22 : n->options = list_make1(makeDefElem("savepoint_name",
9525 : (Node *)makeString($5), @1));
9526 22 : $$ = (Node *)n;
9527 : }
9528 : | ROLLBACK opt_transaction TO ColId
9529 : {
9530 29 : TransactionStmt *n = makeNode(TransactionStmt);
9531 29 : n->kind = TRANS_STMT_ROLLBACK_TO;
9532 29 : n->options = list_make1(makeDefElem("savepoint_name",
9533 : (Node *)makeString($4), @1));
9534 29 : $$ = (Node *)n;
9535 : }
9536 : | PREPARE TRANSACTION Sconst
9537 : {
9538 8 : TransactionStmt *n = makeNode(TransactionStmt);
9539 8 : n->kind = TRANS_STMT_PREPARE;
9540 8 : n->gid = $3;
9541 8 : $$ = (Node *)n;
9542 : }
9543 : | COMMIT PREPARED Sconst
9544 : {
9545 3 : TransactionStmt *n = makeNode(TransactionStmt);
9546 3 : n->kind = TRANS_STMT_COMMIT_PREPARED;
9547 3 : n->gid = $3;
9548 3 : $$ = (Node *)n;
9549 : }
9550 : | ROLLBACK PREPARED Sconst
9551 : {
9552 3 : TransactionStmt *n = makeNode(TransactionStmt);
9553 3 : n->kind = TRANS_STMT_ROLLBACK_PREPARED;
9554 3 : n->gid = $3;
9555 3 : $$ = (Node *)n;
9556 : }
9557 : ;
9558 :
9559 : opt_transaction: WORK {}
9560 : | TRANSACTION {}
9561 : | /*EMPTY*/ {}
9562 : ;
9563 :
9564 : transaction_mode_item:
9565 : ISOLATION LEVEL iso_level
9566 18 : { $$ = makeDefElem("transaction_isolation",
9567 18 : makeStringConst($3, @3), @1); }
9568 : | READ ONLY
9569 24 : { $$ = makeDefElem("transaction_read_only",
9570 24 : makeIntConst(TRUE, @1), @1); }
9571 : | READ WRITE
9572 18 : { $$ = makeDefElem("transaction_read_only",
9573 18 : makeIntConst(FALSE, @1), @1); }
9574 : | DEFERRABLE
9575 1 : { $$ = makeDefElem("transaction_deferrable",
9576 : makeIntConst(TRUE, @1), @1); }
9577 : | NOT DEFERRABLE
9578 0 : { $$ = makeDefElem("transaction_deferrable",
9579 0 : makeIntConst(FALSE, @1), @1); }
9580 : ;
9581 :
9582 : /* Syntax with commas is SQL-spec, without commas is Postgres historical */
9583 : transaction_mode_list:
9584 : transaction_mode_item
9585 38 : { $$ = list_make1($1); }
9586 : | transaction_mode_list ',' transaction_mode_item
9587 2 : { $$ = lappend($1, $3); }
9588 : | transaction_mode_list transaction_mode_item
9589 0 : { $$ = lappend($1, $2); }
9590 : ;
9591 :
9592 : transaction_mode_list_or_empty:
9593 : transaction_mode_list
9594 : | /* EMPTY */
9595 290 : { $$ = NIL; }
9596 : ;
9597 :
9598 :
9599 : /*****************************************************************************
9600 : *
9601 : * QUERY:
9602 : * CREATE [ OR REPLACE ] [ TEMP ] VIEW <viewname> '('target-list ')'
9603 : * AS <query> [ WITH [ CASCADED | LOCAL ] CHECK OPTION ]
9604 : *
9605 : *****************************************************************************/
9606 :
9607 : ViewStmt: CREATE OptTemp VIEW qualified_name opt_column_list opt_reloptions
9608 : AS SelectStmt opt_check_option
9609 : {
9610 393 : ViewStmt *n = makeNode(ViewStmt);
9611 393 : n->view = $4;
9612 393 : n->view->relpersistence = $2;
9613 393 : n->aliases = $5;
9614 393 : n->query = $8;
9615 393 : n->replace = false;
9616 393 : n->options = $6;
9617 393 : n->withCheckOption = $9;
9618 393 : $$ = (Node *) n;
9619 : }
9620 : | CREATE OR REPLACE OptTemp VIEW qualified_name opt_column_list opt_reloptions
9621 : AS SelectStmt opt_check_option
9622 : {
9623 25 : ViewStmt *n = makeNode(ViewStmt);
9624 25 : n->view = $6;
9625 25 : n->view->relpersistence = $4;
9626 25 : n->aliases = $7;
9627 25 : n->query = $10;
9628 25 : n->replace = true;
9629 25 : n->options = $8;
9630 25 : n->withCheckOption = $11;
9631 25 : $$ = (Node *) n;
9632 : }
9633 : | CREATE OptTemp RECURSIVE VIEW qualified_name '(' columnList ')' opt_reloptions
9634 : AS SelectStmt opt_check_option
9635 : {
9636 1 : ViewStmt *n = makeNode(ViewStmt);
9637 1 : n->view = $5;
9638 1 : n->view->relpersistence = $2;
9639 1 : n->aliases = $7;
9640 1 : n->query = makeRecursiveViewSelect(n->view->relname, n->aliases, $11);
9641 1 : n->replace = false;
9642 1 : n->options = $9;
9643 1 : n->withCheckOption = $12;
9644 1 : if (n->withCheckOption != NO_CHECK_OPTION)
9645 0 : ereport(ERROR,
9646 : (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
9647 : errmsg("WITH CHECK OPTION not supported on recursive views"),
9648 : parser_errposition(@12)));
9649 1 : $$ = (Node *) n;
9650 : }
9651 : | CREATE OR REPLACE OptTemp RECURSIVE VIEW qualified_name '(' columnList ')' opt_reloptions
9652 : AS SelectStmt opt_check_option
9653 : {
9654 1 : ViewStmt *n = makeNode(ViewStmt);
9655 1 : n->view = $7;
9656 1 : n->view->relpersistence = $4;
9657 1 : n->aliases = $9;
9658 1 : n->query = makeRecursiveViewSelect(n->view->relname, n->aliases, $13);
9659 1 : n->replace = true;
9660 1 : n->options = $11;
9661 1 : n->withCheckOption = $14;
9662 1 : if (n->withCheckOption != NO_CHECK_OPTION)
9663 0 : ereport(ERROR,
9664 : (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
9665 : errmsg("WITH CHECK OPTION not supported on recursive views"),
9666 : parser_errposition(@14)));
9667 1 : $$ = (Node *) n;
9668 : }
9669 : ;
9670 :
9671 : opt_check_option:
9672 13 : WITH CHECK OPTION { $$ = CASCADED_CHECK_OPTION; }
9673 1 : | WITH CASCADED CHECK OPTION { $$ = CASCADED_CHECK_OPTION; }
9674 4 : | WITH LOCAL CHECK OPTION { $$ = LOCAL_CHECK_OPTION; }
9675 402 : | /* EMPTY */ { $$ = NO_CHECK_OPTION; }
9676 : ;
9677 :
9678 : /*****************************************************************************
9679 : *
9680 : * QUERY:
9681 : * LOAD "filename"
9682 : *
9683 : *****************************************************************************/
9684 :
9685 : LoadStmt: LOAD file_name
9686 : {
9687 1 : LoadStmt *n = makeNode(LoadStmt);
9688 1 : n->filename = $2;
9689 1 : $$ = (Node *)n;
9690 : }
9691 : ;
9692 :
9693 :
9694 : /*****************************************************************************
9695 : *
9696 : * CREATE DATABASE
9697 : *
9698 : *****************************************************************************/
9699 :
9700 : CreatedbStmt:
9701 : CREATE DATABASE database_name opt_with createdb_opt_list
9702 : {
9703 3 : CreatedbStmt *n = makeNode(CreatedbStmt);
9704 3 : n->dbname = $3;
9705 3 : n->options = $5;
9706 3 : $$ = (Node *)n;
9707 : }
9708 : ;
9709 :
9710 : createdb_opt_list:
9711 2 : createdb_opt_items { $$ = $1; }
9712 1 : | /* EMPTY */ { $$ = NIL; }
9713 : ;
9714 :
9715 : createdb_opt_items:
9716 2 : createdb_opt_item { $$ = list_make1($1); }
9717 1 : | createdb_opt_items createdb_opt_item { $$ = lappend($1, $2); }
9718 : ;
9719 :
9720 : createdb_opt_item:
9721 : createdb_opt_name opt_equal SignedIconst
9722 : {
9723 0 : $$ = makeDefElem($1, (Node *)makeInteger($3), @1);
9724 : }
9725 : | createdb_opt_name opt_equal opt_boolean_or_string
9726 : {
9727 3 : $$ = makeDefElem($1, (Node *)makeString($3), @1);
9728 : }
9729 : | createdb_opt_name opt_equal DEFAULT
9730 : {
9731 0 : $$ = makeDefElem($1, NULL, @1);
9732 : }
9733 : ;
9734 :
9735 : /*
9736 : * Ideally we'd use ColId here, but that causes shift/reduce conflicts against
9737 : * the ALTER DATABASE SET/RESET syntaxes. Instead call out specific keywords
9738 : * we need, and allow IDENT so that database option names don't have to be
9739 : * parser keywords unless they are already keywords for other reasons.
9740 : *
9741 : * XXX this coding technique is fragile since if someone makes a formerly
9742 : * non-keyword option name into a keyword and forgets to add it here, the
9743 : * option will silently break. Best defense is to provide a regression test
9744 : * exercising every such option, at least at the syntax level.
9745 : */
9746 : createdb_opt_name:
9747 2 : IDENT { $$ = $1; }
9748 0 : | CONNECTION LIMIT { $$ = pstrdup("connection_limit"); }
9749 0 : | ENCODING { $$ = pstrdup($1); }
9750 0 : | LOCATION { $$ = pstrdup($1); }
9751 0 : | OWNER { $$ = pstrdup($1); }
9752 0 : | TABLESPACE { $$ = pstrdup($1); }
9753 1 : | TEMPLATE { $$ = pstrdup($1); }
9754 : ;
9755 :
9756 : /*
9757 : * Though the equals sign doesn't match other WITH options, pg_dump uses
9758 : * equals for backward compatibility, and it doesn't seem worth removing it.
9759 : */
9760 : opt_equal: '=' {}
9761 : | /*EMPTY*/ {}
9762 : ;
9763 :
9764 :
9765 : /*****************************************************************************
9766 : *
9767 : * ALTER DATABASE
9768 : *
9769 : *****************************************************************************/
9770 :
9771 : AlterDatabaseStmt:
9772 : ALTER DATABASE database_name WITH createdb_opt_list
9773 : {
9774 0 : AlterDatabaseStmt *n = makeNode(AlterDatabaseStmt);
9775 0 : n->dbname = $3;
9776 0 : n->options = $5;
9777 0 : $$ = (Node *)n;
9778 : }
9779 : | ALTER DATABASE database_name createdb_opt_list
9780 : {
9781 0 : AlterDatabaseStmt *n = makeNode(AlterDatabaseStmt);
9782 0 : n->dbname = $3;
9783 0 : n->options = $4;
9784 0 : $$ = (Node *)n;
9785 : }
9786 : | ALTER DATABASE database_name SET TABLESPACE name
9787 : {
9788 0 : AlterDatabaseStmt *n = makeNode(AlterDatabaseStmt);
9789 0 : n->dbname = $3;
9790 0 : n->options = list_make1(makeDefElem("tablespace",
9791 : (Node *)makeString($6), @6));
9792 0 : $$ = (Node *)n;
9793 : }
9794 : ;
9795 :
9796 : AlterDatabaseSetStmt:
9797 : ALTER DATABASE database_name SetResetClause
9798 : {
9799 6 : AlterDatabaseSetStmt *n = makeNode(AlterDatabaseSetStmt);
9800 6 : n->dbname = $3;
9801 6 : n->setstmt = $4;
9802 6 : $$ = (Node *)n;
9803 : }
9804 : ;
9805 :
9806 :
9807 : /*****************************************************************************
9808 : *
9809 : * DROP DATABASE [ IF EXISTS ]
9810 : *
9811 : * This is implicitly CASCADE, no need for drop behavior
9812 : *****************************************************************************/
9813 :
9814 : DropdbStmt: DROP DATABASE database_name
9815 : {
9816 0 : DropdbStmt *n = makeNode(DropdbStmt);
9817 0 : n->dbname = $3;
9818 0 : n->missing_ok = FALSE;
9819 0 : $$ = (Node *)n;
9820 : }
9821 : | DROP DATABASE IF_P EXISTS database_name
9822 : {
9823 0 : DropdbStmt *n = makeNode(DropdbStmt);
9824 0 : n->dbname = $5;
9825 0 : n->missing_ok = TRUE;
9826 0 : $$ = (Node *)n;
9827 : }
9828 : ;
9829 :
9830 :
9831 : /*****************************************************************************
9832 : *
9833 : * ALTER COLLATION
9834 : *
9835 : *****************************************************************************/
9836 :
9837 : AlterCollationStmt: ALTER COLLATION any_name REFRESH VERSION_P
9838 : {
9839 0 : AlterCollationStmt *n = makeNode(AlterCollationStmt);
9840 0 : n->collname = $3;
9841 0 : $$ = (Node *)n;
9842 : }
9843 : ;
9844 :
9845 :
9846 : /*****************************************************************************
9847 : *
9848 : * ALTER SYSTEM
9849 : *
9850 : * This is used to change configuration parameters persistently.
9851 : *****************************************************************************/
9852 :
9853 : AlterSystemStmt:
9854 : ALTER SYSTEM_P SET generic_set
9855 : {
9856 0 : AlterSystemStmt *n = makeNode(AlterSystemStmt);
9857 0 : n->setstmt = $4;
9858 0 : $$ = (Node *)n;
9859 : }
9860 : | ALTER SYSTEM_P RESET generic_reset
9861 : {
9862 0 : AlterSystemStmt *n = makeNode(AlterSystemStmt);
9863 0 : n->setstmt = $4;
9864 0 : $$ = (Node *)n;
9865 : }
9866 : ;
9867 :
9868 :
9869 : /*****************************************************************************
9870 : *
9871 : * Manipulate a domain
9872 : *
9873 : *****************************************************************************/
9874 :
9875 : CreateDomainStmt:
9876 : CREATE DOMAIN_P any_name opt_as Typename ColQualList
9877 : {
9878 77 : CreateDomainStmt *n = makeNode(CreateDomainStmt);
9879 77 : n->domainname = $3;
9880 77 : n->typeName = $5;
9881 77 : SplitColQualList($6, &n->constraints, &n->collClause,
9882 : yyscanner);
9883 77 : $$ = (Node *)n;
9884 : }
9885 : ;
9886 :
9887 : AlterDomainStmt:
9888 : /* ALTER DOMAIN <domain> {SET DEFAULT <expr>|DROP DEFAULT} */
9889 : ALTER DOMAIN_P any_name alter_column_default
9890 : {
9891 2 : AlterDomainStmt *n = makeNode(AlterDomainStmt);
9892 2 : n->subtype = 'T';
9893 2 : n->typeName = $3;
9894 2 : n->def = $4;
9895 2 : $$ = (Node *)n;
9896 : }
9897 : /* ALTER DOMAIN <domain> DROP NOT NULL */
9898 : | ALTER DOMAIN_P any_name DROP NOT NULL_P
9899 : {
9900 2 : AlterDomainStmt *n = makeNode(AlterDomainStmt);
9901 2 : n->subtype = 'N';
9902 2 : n->typeName = $3;
9903 2 : $$ = (Node *)n;
9904 : }
9905 : /* ALTER DOMAIN <domain> SET NOT NULL */
9906 : | ALTER DOMAIN_P any_name SET NOT NULL_P
9907 : {
9908 4 : AlterDomainStmt *n = makeNode(AlterDomainStmt);
9909 4 : n->subtype = 'O';
9910 4 : n->typeName = $3;
9911 4 : $$ = (Node *)n;
9912 : }
9913 : /* ALTER DOMAIN <domain> ADD CONSTRAINT ... */
9914 : | ALTER DOMAIN_P any_name ADD_P TableConstraint
9915 : {
9916 16 : AlterDomainStmt *n = makeNode(AlterDomainStmt);
9917 16 : n->subtype = 'C';
9918 16 : n->typeName = $3;
9919 16 : n->def = $5;
9920 16 : $$ = (Node *)n;
9921 : }
9922 : /* ALTER DOMAIN <domain> DROP CONSTRAINT <name> [RESTRICT|CASCADE] */
9923 : | ALTER DOMAIN_P any_name DROP CONSTRAINT name opt_drop_behavior
9924 : {
9925 5 : AlterDomainStmt *n = makeNode(AlterDomainStmt);
9926 5 : n->subtype = 'X';
9927 5 : n->typeName = $3;
9928 5 : n->name = $6;
9929 5 : n->behavior = $7;
9930 5 : n->missing_ok = false;
9931 5 : $$ = (Node *)n;
9932 : }
9933 : /* ALTER DOMAIN <domain> DROP CONSTRAINT IF EXISTS <name> [RESTRICT|CASCADE] */
9934 : | ALTER DOMAIN_P any_name DROP CONSTRAINT IF_P EXISTS name opt_drop_behavior
9935 : {
9936 1 : AlterDomainStmt *n = makeNode(AlterDomainStmt);
9937 1 : n->subtype = 'X';
9938 1 : n->typeName = $3;
9939 1 : n->name = $8;
9940 1 : n->behavior = $9;
9941 1 : n->missing_ok = true;
9942 1 : $$ = (Node *)n;
9943 : }
9944 : /* ALTER DOMAIN <domain> VALIDATE CONSTRAINT <name> */
9945 : | ALTER DOMAIN_P any_name VALIDATE CONSTRAINT name
9946 : {
9947 2 : AlterDomainStmt *n = makeNode(AlterDomainStmt);
9948 2 : n->subtype = 'V';
9949 2 : n->typeName = $3;
9950 2 : n->name = $6;
9951 2 : $$ = (Node *)n;
9952 : }
9953 : ;
9954 :
9955 : opt_as: AS {}
9956 : | /* EMPTY */ {}
9957 : ;
9958 :
9959 :
9960 : /*****************************************************************************
9961 : *
9962 : * Manipulate a text search dictionary or configuration
9963 : *
9964 : *****************************************************************************/
9965 :
9966 : AlterTSDictionaryStmt:
9967 : ALTER TEXT_P SEARCH DICTIONARY any_name definition
9968 : {
9969 0 : AlterTSDictionaryStmt *n = makeNode(AlterTSDictionaryStmt);
9970 0 : n->dictname = $5;
9971 0 : n->options = $6;
9972 0 : $$ = (Node *)n;
9973 : }
9974 : ;
9975 :
9976 : AlterTSConfigurationStmt:
9977 : ALTER TEXT_P SEARCH CONFIGURATION any_name ADD_P MAPPING FOR name_list any_with any_name_list
9978 : {
9979 45 : AlterTSConfigurationStmt *n = makeNode(AlterTSConfigurationStmt);
9980 45 : n->kind = ALTER_TSCONFIG_ADD_MAPPING;
9981 45 : n->cfgname = $5;
9982 45 : n->tokentype = $9;
9983 45 : n->dicts = $11;
9984 45 : n->override = false;
9985 45 : n->replace = false;
9986 45 : $$ = (Node*)n;
9987 : }
9988 : | ALTER TEXT_P SEARCH CONFIGURATION any_name ALTER MAPPING FOR name_list any_with any_name_list
9989 : {
9990 3 : AlterTSConfigurationStmt *n = makeNode(AlterTSConfigurationStmt);
9991 3 : n->kind = ALTER_TSCONFIG_ALTER_MAPPING_FOR_TOKEN;
9992 3 : n->cfgname = $5;
9993 3 : n->tokentype = $9;
9994 3 : n->dicts = $11;
9995 3 : n->override = true;
9996 3 : n->replace = false;
9997 3 : $$ = (Node*)n;
9998 : }
9999 : | ALTER TEXT_P SEARCH CONFIGURATION any_name ALTER MAPPING REPLACE any_name any_with any_name
10000 : {
10001 3 : AlterTSConfigurationStmt *n = makeNode(AlterTSConfigurationStmt);
10002 3 : n->kind = ALTER_TSCONFIG_REPLACE_DICT;
10003 3 : n->cfgname = $5;
10004 3 : n->tokentype = NIL;
10005 3 : n->dicts = list_make2($9,$11);
10006 3 : n->override = false;
10007 3 : n->replace = true;
10008 3 : $$ = (Node*)n;
10009 : }
10010 : | ALTER TEXT_P SEARCH CONFIGURATION any_name ALTER MAPPING FOR name_list REPLACE any_name any_with any_name
10011 : {
10012 0 : AlterTSConfigurationStmt *n = makeNode(AlterTSConfigurationStmt);
10013 0 : n->kind = ALTER_TSCONFIG_REPLACE_DICT_FOR_TOKEN;
10014 0 : n->cfgname = $5;
10015 0 : n->tokentype = $9;
10016 0 : n->dicts = list_make2($11,$13);
10017 0 : n->override = false;
10018 0 : n->replace = true;
10019 0 : $$ = (Node*)n;
10020 : }
10021 : | ALTER TEXT_P SEARCH CONFIGURATION any_name DROP MAPPING FOR name_list
10022 : {
10023 0 : AlterTSConfigurationStmt *n = makeNode(AlterTSConfigurationStmt);
10024 0 : n->kind = ALTER_TSCONFIG_DROP_MAPPING;
10025 0 : n->cfgname = $5;
10026 0 : n->tokentype = $9;
10027 0 : n->missing_ok = false;
10028 0 : $$ = (Node*)n;
10029 : }
10030 : | ALTER TEXT_P SEARCH CONFIGURATION any_name DROP MAPPING IF_P EXISTS FOR name_list
10031 : {
10032 0 : AlterTSConfigurationStmt *n = makeNode(AlterTSConfigurationStmt);
10033 0 : n->kind = ALTER_TSCONFIG_DROP_MAPPING;
10034 0 : n->cfgname = $5;
10035 0 : n->tokentype = $11;
10036 0 : n->missing_ok = true;
10037 0 : $$ = (Node*)n;
10038 : }
10039 : ;
10040 :
10041 : /* Use this if TIME or ORDINALITY after WITH should be taken as an identifier */
10042 : any_with: WITH {}
10043 : | WITH_LA {}
10044 : ;
10045 :
10046 :
10047 : /*****************************************************************************
10048 : *
10049 : * Manipulate a conversion
10050 : *
10051 : * CREATE [DEFAULT] CONVERSION <conversion_name>
10052 : * FOR <encoding_name> TO <encoding_name> FROM <func_name>
10053 : *
10054 : *****************************************************************************/
10055 :
10056 : CreateConversionStmt:
10057 : CREATE opt_default CONVERSION_P any_name FOR Sconst
10058 : TO Sconst FROM any_name
10059 : {
10060 142 : CreateConversionStmt *n = makeNode(CreateConversionStmt);
10061 142 : n->conversion_name = $4;
10062 142 : n->for_encoding_name = $6;
10063 142 : n->to_encoding_name = $8;
10064 142 : n->func_name = $10;
10065 142 : n->def = $2;
10066 142 : $$ = (Node *)n;
10067 : }
10068 : ;
10069 :
10070 : /*****************************************************************************
10071 : *
10072 : * QUERY:
10073 : * CLUSTER [VERBOSE] <qualified_name> [ USING <index_name> ]
10074 : * CLUSTER [VERBOSE]
10075 : * CLUSTER [VERBOSE] <index_name> ON <qualified_name> (for pre-8.3)
10076 : *
10077 : *****************************************************************************/
10078 :
10079 : ClusterStmt:
10080 : CLUSTER opt_verbose qualified_name cluster_index_specification
10081 : {
10082 7 : ClusterStmt *n = makeNode(ClusterStmt);
10083 7 : n->relation = $3;
10084 7 : n->indexname = $4;
10085 7 : n->verbose = $2;
10086 7 : $$ = (Node*)n;
10087 : }
10088 : | CLUSTER opt_verbose
10089 : {
10090 1 : ClusterStmt *n = makeNode(ClusterStmt);
10091 1 : n->relation = NULL;
10092 1 : n->indexname = NULL;
10093 1 : n->verbose = $2;
10094 1 : $$ = (Node*)n;
10095 : }
10096 : /* kept for pre-8.3 compatibility */
10097 : | CLUSTER opt_verbose index_name ON qualified_name
10098 : {
10099 3 : ClusterStmt *n = makeNode(ClusterStmt);
10100 3 : n->relation = $5;
10101 3 : n->indexname = $3;
10102 3 : n->verbose = $2;
10103 3 : $$ = (Node*)n;
10104 : }
10105 : ;
10106 :
10107 : cluster_index_specification:
10108 4 : USING index_name { $$ = $2; }
10109 3 : | /*EMPTY*/ { $$ = NULL; }
10110 : ;
10111 :
10112 :
10113 : /*****************************************************************************
10114 : *
10115 : * QUERY:
10116 : * VACUUM
10117 : * ANALYZE
10118 : *
10119 : *****************************************************************************/
10120 :
10121 : VacuumStmt: VACUUM opt_full opt_freeze opt_verbose
10122 : {
10123 2 : VacuumStmt *n = makeNode(VacuumStmt);
10124 2 : n->options = VACOPT_VACUUM;
10125 2 : if ($2)
10126 0 : n->options |= VACOPT_FULL;
10127 2 : if ($3)
10128 1 : n->options |= VACOPT_FREEZE;
10129 2 : if ($4)
10130 0 : n->options |= VACOPT_VERBOSE;
10131 2 : n->relation = NULL;
10132 2 : n->va_cols = NIL;
10133 2 : $$ = (Node *)n;
10134 : }
10135 : | VACUUM opt_full opt_freeze opt_verbose qualified_name
10136 : {
10137 22 : VacuumStmt *n = makeNode(VacuumStmt);
10138 22 : n->options = VACOPT_VACUUM;
10139 22 : if ($2)
10140 8 : n->options |= VACOPT_FULL;
10141 22 : if ($3)
10142 2 : n->options |= VACOPT_FREEZE;
10143 22 : if ($4)
10144 0 : n->options |= VACOPT_VERBOSE;
10145 22 : n->relation = $5;
10146 22 : n->va_cols = NIL;
10147 22 : $$ = (Node *)n;
10148 : }
10149 : | VACUUM opt_full opt_freeze opt_verbose AnalyzeStmt
10150 : {
10151 17 : VacuumStmt *n = (VacuumStmt *) $5;
10152 17 : n->options |= VACOPT_VACUUM;
10153 17 : if ($2)
10154 0 : n->options |= VACOPT_FULL;
10155 17 : if ($3)
10156 0 : n->options |= VACOPT_FREEZE;
10157 17 : if ($4)
10158 0 : n->options |= VACOPT_VERBOSE;
10159 17 : $$ = (Node *)n;
10160 : }
10161 : | VACUUM '(' vacuum_option_list ')'
10162 : {
10163 0 : VacuumStmt *n = makeNode(VacuumStmt);
10164 0 : n->options = VACOPT_VACUUM | $3;
10165 0 : n->relation = NULL;
10166 0 : n->va_cols = NIL;
10167 0 : $$ = (Node *) n;
10168 : }
10169 : | VACUUM '(' vacuum_option_list ')' qualified_name opt_name_list
10170 : {
10171 7 : VacuumStmt *n = makeNode(VacuumStmt);
10172 7 : n->options = VACOPT_VACUUM | $3;
10173 7 : n->relation = $5;
10174 7 : n->va_cols = $6;
10175 7 : if (n->va_cols != NIL) /* implies analyze */
10176 0 : n->options |= VACOPT_ANALYZE;
10177 7 : $$ = (Node *) n;
10178 : }
10179 : ;
10180 :
10181 : vacuum_option_list:
10182 7 : vacuum_option_elem { $$ = $1; }
10183 2 : | vacuum_option_list ',' vacuum_option_elem { $$ = $1 | $3; }
10184 : ;
10185 :
10186 : vacuum_option_elem:
10187 2 : analyze_keyword { $$ = VACOPT_ANALYZE; }
10188 0 : | VERBOSE { $$ = VACOPT_VERBOSE; }
10189 2 : | FREEZE { $$ = VACOPT_FREEZE; }
10190 4 : | FULL { $$ = VACOPT_FULL; }
10191 : | IDENT
10192 : {
10193 1 : if (strcmp($1, "disable_page_skipping") == 0)
10194 1 : $$ = VACOPT_DISABLE_PAGE_SKIPPING;
10195 : else
10196 0 : ereport(ERROR,
10197 : (errcode(ERRCODE_SYNTAX_ERROR),
10198 : errmsg("unrecognized VACUUM option \"%s\"", $1),
10199 : parser_errposition(@1)));
10200 : }
10201 : ;
10202 :
10203 : AnalyzeStmt:
10204 : analyze_keyword opt_verbose
10205 : {
10206 1 : VacuumStmt *n = makeNode(VacuumStmt);
10207 1 : n->options = VACOPT_ANALYZE;
10208 1 : if ($2)
10209 0 : n->options |= VACOPT_VERBOSE;
10210 1 : n->relation = NULL;
10211 1 : n->va_cols = NIL;
10212 1 : $$ = (Node *)n;
10213 : }
10214 : | analyze_keyword opt_verbose qualified_name opt_name_list
10215 : {
10216 101 : VacuumStmt *n = makeNode(VacuumStmt);
10217 101 : n->options = VACOPT_ANALYZE;
10218 101 : if ($2)
10219 0 : n->options |= VACOPT_VERBOSE;
10220 101 : n->relation = $3;
10221 101 : n->va_cols = $4;
10222 101 : $$ = (Node *)n;
10223 : }
10224 : ;
10225 :
10226 : analyze_keyword:
10227 : ANALYZE {}
10228 : | ANALYSE /* British */ {}
10229 : ;
10230 :
10231 : opt_verbose:
10232 0 : VERBOSE { $$ = TRUE; }
10233 155 : | /*EMPTY*/ { $$ = FALSE; }
10234 : ;
10235 :
10236 8 : opt_full: FULL { $$ = TRUE; }
10237 33 : | /*EMPTY*/ { $$ = FALSE; }
10238 : ;
10239 :
10240 3 : opt_freeze: FREEZE { $$ = TRUE; }
10241 38 : | /*EMPTY*/ { $$ = FALSE; }
10242 : ;
10243 :
10244 : opt_name_list:
10245 94 : '(' name_list ')' { $$ = $2; }
10246 224 : | /*EMPTY*/ { $$ = NIL; }
10247 : ;
10248 :
10249 :
10250 : /*****************************************************************************
10251 : *
10252 : * QUERY:
10253 : * EXPLAIN [ANALYZE] [VERBOSE] query
10254 : * EXPLAIN ( options ) query
10255 : *
10256 : *****************************************************************************/
10257 :
10258 : ExplainStmt:
10259 : EXPLAIN ExplainableStmt
10260 : {
10261 497 : ExplainStmt *n = makeNode(ExplainStmt);
10262 497 : n->query = $2;
10263 497 : n->options = NIL;
10264 497 : $$ = (Node *) n;
10265 : }
10266 : | EXPLAIN analyze_keyword opt_verbose ExplainableStmt
10267 : {
10268 1 : ExplainStmt *n = makeNode(ExplainStmt);
10269 1 : n->query = $4;
10270 1 : n->options = list_make1(makeDefElem("analyze", NULL, @2));
10271 1 : if ($3)
10272 0 : n->options = lappend(n->options,
10273 0 : makeDefElem("verbose", NULL, @3));
10274 1 : $$ = (Node *) n;
10275 : }
10276 : | EXPLAIN VERBOSE ExplainableStmt
10277 : {
10278 2 : ExplainStmt *n = makeNode(ExplainStmt);
10279 2 : n->query = $3;
10280 2 : n->options = list_make1(makeDefElem("verbose", NULL, @2));
10281 2 : $$ = (Node *) n;
10282 : }
10283 : | EXPLAIN '(' explain_option_list ')' ExplainableStmt
10284 : {
10285 625 : ExplainStmt *n = makeNode(ExplainStmt);
10286 625 : n->query = $5;
10287 625 : n->options = $3;
10288 625 : $$ = (Node *) n;
10289 : }
10290 : ;
10291 :
10292 : ExplainableStmt:
10293 : SelectStmt
10294 : | InsertStmt
10295 : | UpdateStmt
10296 : | DeleteStmt
10297 : | DeclareCursorStmt
10298 : | CreateAsStmt
10299 : | CreateMatViewStmt
10300 : | RefreshMatViewStmt
10301 : | ExecuteStmt /* by default all are $$=$1 */
10302 : ;
10303 :
10304 : explain_option_list:
10305 : explain_option_elem
10306 : {
10307 625 : $$ = list_make1($1);
10308 : }
10309 : | explain_option_list ',' explain_option_elem
10310 : {
10311 111 : $$ = lappend($1, $3);
10312 : }
10313 : ;
10314 :
10315 : explain_option_elem:
10316 : explain_option_name explain_option_arg
10317 : {
10318 736 : $$ = makeDefElem($1, $2, @1);
10319 : }
10320 : ;
10321 :
10322 : explain_option_name:
10323 729 : NonReservedWord { $$ = $1; }
10324 7 : | analyze_keyword { $$ = "analyze"; }
10325 : ;
10326 :
10327 : explain_option_arg:
10328 647 : opt_boolean_or_string { $$ = (Node *) makeString($1); }
10329 0 : | NumericOnly { $$ = (Node *) $1; }
10330 89 : | /* EMPTY */ { $$ = NULL; }
10331 : ;
10332 :
10333 : /*****************************************************************************
10334 : *
10335 : * QUERY:
10336 : * PREPARE <plan_name> [(args, ...)] AS <query>
10337 : *
10338 : *****************************************************************************/
10339 :
10340 : PrepareStmt: PREPARE name prep_type_clause AS PreparableStmt
10341 : {
10342 37 : PrepareStmt *n = makeNode(PrepareStmt);
10343 37 : n->name = $2;
10344 37 : n->argtypes = $3;
10345 37 : n->query = $5;
10346 37 : $$ = (Node *) n;
10347 : }
10348 : ;
10349 :
10350 13 : prep_type_clause: '(' type_list ')' { $$ = $2; }
10351 24 : | /* EMPTY */ { $$ = NIL; }
10352 : ;
10353 :
10354 : PreparableStmt:
10355 : SelectStmt
10356 : | InsertStmt
10357 : | UpdateStmt
10358 : | DeleteStmt /* by default all are $$=$1 */
10359 : ;
10360 :
10361 : /*****************************************************************************
10362 : *
10363 : * EXECUTE <plan_name> [(params, ...)]
10364 : * CREATE TABLE <name> AS EXECUTE <plan_name> [(params, ...)]
10365 : *
10366 : *****************************************************************************/
10367 :
10368 : ExecuteStmt: EXECUTE name execute_param_clause
10369 : {
10370 154 : ExecuteStmt *n = makeNode(ExecuteStmt);
10371 154 : n->name = $2;
10372 154 : n->params = $3;
10373 154 : $$ = (Node *) n;
10374 : }
10375 : | CREATE OptTemp TABLE create_as_target AS
10376 : EXECUTE name execute_param_clause opt_with_data
10377 : {
10378 4 : CreateTableAsStmt *ctas = makeNode(CreateTableAsStmt);
10379 4 : ExecuteStmt *n = makeNode(ExecuteStmt);
10380 4 : n->name = $7;
10381 4 : n->params = $8;
10382 4 : ctas->query = (Node *) n;
10383 4 : ctas->into = $4;
10384 4 : ctas->relkind = OBJECT_TABLE;
10385 4 : ctas->is_select_into = false;
10386 : /* cram additional flags into the IntoClause */
10387 4 : $4->rel->relpersistence = $2;
10388 4 : $4->skipData = !($9);
10389 4 : $$ = (Node *) ctas;
10390 : }
10391 : ;
10392 :
10393 33 : execute_param_clause: '(' expr_list ')' { $$ = $2; }
10394 125 : | /* EMPTY */ { $$ = NIL; }
10395 : ;
10396 :
10397 : /*****************************************************************************
10398 : *
10399 : * QUERY:
10400 : * DEALLOCATE [PREPARE] <plan_name>
10401 : *
10402 : *****************************************************************************/
10403 :
10404 : DeallocateStmt: DEALLOCATE name
10405 : {
10406 4 : DeallocateStmt *n = makeNode(DeallocateStmt);
10407 4 : n->name = $2;
10408 4 : $$ = (Node *) n;
10409 : }
10410 : | DEALLOCATE PREPARE name
10411 : {
10412 3 : DeallocateStmt *n = makeNode(DeallocateStmt);
10413 3 : n->name = $3;
10414 3 : $$ = (Node *) n;
10415 : }
10416 : | DEALLOCATE ALL
10417 : {
10418 1 : DeallocateStmt *n = makeNode(DeallocateStmt);
10419 1 : n->name = NULL;
10420 1 : $$ = (Node *) n;
10421 : }
10422 : | DEALLOCATE PREPARE ALL
10423 : {
10424 0 : DeallocateStmt *n = makeNode(DeallocateStmt);
10425 0 : n->name = NULL;
10426 0 : $$ = (Node *) n;
10427 : }
10428 : ;
10429 :
10430 : /*****************************************************************************
10431 : *
10432 : * QUERY:
10433 : * INSERT STATEMENTS
10434 : *
10435 : *****************************************************************************/
10436 :
10437 : InsertStmt:
10438 : opt_with_clause INSERT INTO insert_target insert_rest
10439 : opt_on_conflict returning_clause
10440 : {
10441 3701 : $5->relation = $4;
10442 3701 : $5->onConflictClause = $6;
10443 3701 : $5->returningList = $7;
10444 3701 : $5->withClause = $1;
10445 3701 : $$ = (Node *) $5;
10446 : }
10447 : ;
10448 :
10449 : /*
10450 : * Can't easily make AS optional here, because VALUES in insert_rest would
10451 : * have a shift/reduce conflict with VALUES as an optional alias. We could
10452 : * easily allow unreserved_keywords as optional aliases, but that'd be an odd
10453 : * divergence from other places. So just require AS for now.
10454 : */
10455 : insert_target:
10456 : qualified_name
10457 : {
10458 3685 : $$ = $1;
10459 : }
10460 : | qualified_name AS ColId
10461 : {
10462 16 : $1->alias = makeAlias($3, NIL);
10463 16 : $$ = $1;
10464 : }
10465 : ;
10466 :
10467 : insert_rest:
10468 : SelectStmt
10469 : {
10470 2835 : $$ = makeNode(InsertStmt);
10471 2835 : $$->cols = NIL;
10472 2835 : $$->selectStmt = $1;
10473 : }
10474 : | OVERRIDING override_kind VALUE_P SelectStmt
10475 : {
10476 4 : $$ = makeNode(InsertStmt);
10477 4 : $$->cols = NIL;
10478 4 : $$->override = $2;
10479 4 : $$->selectStmt = $4;
10480 : }
10481 : | '(' insert_column_list ')' SelectStmt
10482 : {
10483 768 : $$ = makeNode(InsertStmt);
10484 768 : $$->cols = $2;
10485 768 : $$->selectStmt = $4;
10486 : }
10487 : | '(' insert_column_list ')' OVERRIDING override_kind VALUE_P SelectStmt
10488 : {
10489 0 : $$ = makeNode(InsertStmt);
10490 0 : $$->cols = $2;
10491 0 : $$->override = $5;
10492 0 : $$->selectStmt = $7;
10493 : }
10494 : | DEFAULT VALUES
10495 : {
10496 94 : $$ = makeNode(InsertStmt);
10497 94 : $$->cols = NIL;
10498 94 : $$->selectStmt = NULL;
10499 : }
10500 : ;
10501 :
10502 : override_kind:
10503 2 : USER { $$ = OVERRIDING_USER_VALUE; }
10504 2 : | SYSTEM_P { $$ = OVERRIDING_SYSTEM_VALUE; }
10505 : ;
10506 :
10507 : insert_column_list:
10508 : insert_column_item
10509 768 : { $$ = list_make1($1); }
10510 : | insert_column_list ',' insert_column_item
10511 535 : { $$ = lappend($1, $3); }
10512 : ;
10513 :
10514 : insert_column_item:
10515 : ColId opt_indirection
10516 : {
10517 1303 : $$ = makeNode(ResTarget);
10518 1303 : $$->name = $1;
10519 1303 : $$->indirection = check_indirection($2, yyscanner);
10520 1303 : $$->val = NULL;
10521 1303 : $$->location = @1;
10522 : }
10523 : ;
10524 :
10525 : opt_on_conflict:
10526 : ON CONFLICT opt_conf_expr DO UPDATE SET set_clause_list where_clause
10527 : {
10528 139 : $$ = makeNode(OnConflictClause);
10529 139 : $$->action = ONCONFLICT_UPDATE;
10530 139 : $$->infer = $3;
10531 139 : $$->targetList = $7;
10532 139 : $$->whereClause = $8;
10533 139 : $$->location = @1;
10534 : }
10535 : |
10536 : ON CONFLICT opt_conf_expr DO NOTHING
10537 : {
10538 33 : $$ = makeNode(OnConflictClause);
10539 33 : $$->action = ONCONFLICT_NOTHING;
10540 33 : $$->infer = $3;
10541 33 : $$->targetList = NIL;
10542 33 : $$->whereClause = NULL;
10543 33 : $$->location = @1;
10544 : }
10545 : | /*EMPTY*/
10546 : {
10547 3529 : $$ = NULL;
10548 : }
10549 : ;
10550 :
10551 : opt_conf_expr:
10552 : '(' index_params ')' where_clause
10553 : {
10554 158 : $$ = makeNode(InferClause);
10555 158 : $$->indexElems = $2;
10556 158 : $$->whereClause = $4;
10557 158 : $$->conname = NULL;
10558 158 : $$->location = @1;
10559 : }
10560 : |
10561 : ON CONSTRAINT name
10562 : {
10563 5 : $$ = makeNode(InferClause);
10564 5 : $$->indexElems = NIL;
10565 5 : $$->whereClause = NULL;
10566 5 : $$->conname = $3;
10567 5 : $$->location = @1;
10568 : }
10569 : | /*EMPTY*/
10570 : {
10571 9 : $$ = NULL;
10572 : }
10573 : ;
10574 :
10575 : returning_clause:
10576 240 : RETURNING target_list { $$ = $2; }
10577 4386 : | /* EMPTY */ { $$ = NIL; }
10578 : ;
10579 :
10580 :
10581 : /*****************************************************************************
10582 : *
10583 : * QUERY:
10584 : * DELETE STATEMENTS
10585 : *
10586 : *****************************************************************************/
10587 :
10588 : DeleteStmt: opt_with_clause DELETE_P FROM relation_expr_opt_alias
10589 : using_clause where_or_current_clause returning_clause
10590 : {
10591 350 : DeleteStmt *n = makeNode(DeleteStmt);
10592 350 : n->relation = $4;
10593 350 : n->usingClause = $5;
10594 350 : n->whereClause = $6;
10595 350 : n->returningList = $7;
10596 350 : n->withClause = $1;
10597 350 : $$ = (Node *)n;
10598 : }
10599 : ;
10600 :
10601 : using_clause:
10602 14 : USING from_list { $$ = $2; }
10603 336 : | /*EMPTY*/ { $$ = NIL; }
10604 : ;
10605 :
10606 :
10607 : /*****************************************************************************
10608 : *
10609 : * QUERY:
10610 : * LOCK TABLE
10611 : *
10612 : *****************************************************************************/
10613 :
10614 : LockStmt: LOCK_P opt_table relation_expr_list opt_lock opt_nowait
10615 : {
10616 40 : LockStmt *n = makeNode(LockStmt);
10617 :
10618 40 : n->relations = $3;
10619 40 : n->mode = $4;
10620 40 : n->nowait = $5;
10621 40 : $$ = (Node *)n;
10622 : }
10623 : ;
10624 :
10625 39 : opt_lock: IN_P lock_type MODE { $$ = $2; }
10626 1 : | /*EMPTY*/ { $$ = AccessExclusiveLock; }
10627 : ;
10628 :
10629 9 : lock_type: ACCESS SHARE { $$ = AccessShareLock; }
10630 2 : | ROW SHARE { $$ = RowShareLock; }
10631 7 : | ROW EXCLUSIVE { $$ = RowExclusiveLock; }
10632 2 : | SHARE UPDATE EXCLUSIVE { $$ = ShareUpdateExclusiveLock; }
10633 2 : | SHARE { $$ = ShareLock; }
10634 2 : | SHARE ROW EXCLUSIVE { $$ = ShareRowExclusiveLock; }
10635 3 : | EXCLUSIVE { $$ = ExclusiveLock; }
10636 12 : | ACCESS EXCLUSIVE { $$ = AccessExclusiveLock; }
10637 : ;
10638 :
10639 10 : opt_nowait: NOWAIT { $$ = TRUE; }
10640 33 : | /*EMPTY*/ { $$ = FALSE; }
10641 : ;
10642 :
10643 : opt_nowait_or_skip:
10644 0 : NOWAIT { $$ = LockWaitError; }
10645 0 : | SKIP LOCKED { $$ = LockWaitSkip; }
10646 126 : | /*EMPTY*/ { $$ = LockWaitBlock; }
10647 : ;
10648 :
10649 :
10650 : /*****************************************************************************
10651 : *
10652 : * QUERY:
10653 : * UpdateStmt (UPDATE)
10654 : *
10655 : *****************************************************************************/
10656 :
10657 : UpdateStmt: opt_with_clause UPDATE relation_expr_opt_alias
10658 : SET set_clause_list
10659 : from_clause
10660 : where_or_current_clause
10661 : returning_clause
10662 : {
10663 575 : UpdateStmt *n = makeNode(UpdateStmt);
10664 575 : n->relation = $3;
10665 575 : n->targetList = $5;
10666 575 : n->fromClause = $6;
10667 575 : n->whereClause = $7;
10668 575 : n->returningList = $8;
10669 575 : n->withClause = $1;
10670 575 : $$ = (Node *)n;
10671 : }
10672 : ;
10673 :
10674 : set_clause_list:
10675 714 : set_clause { $$ = $1; }
10676 109 : | set_clause_list ',' set_clause { $$ = list_concat($1,$3); }
10677 : ;
10678 :
10679 : set_clause:
10680 : set_target '=' a_expr
10681 : {
10682 808 : $1->val = (Node *) $3;
10683 808 : $$ = list_make1($1);
10684 : }
10685 : | '(' set_target_list ')' '=' a_expr
10686 : {
10687 15 : int ncolumns = list_length($2);
10688 15 : int i = 1;
10689 : ListCell *col_cell;
10690 :
10691 : /* Create a MultiAssignRef source for each target */
10692 46 : foreach(col_cell, $2)
10693 : {
10694 31 : ResTarget *res_col = (ResTarget *) lfirst(col_cell);
10695 31 : MultiAssignRef *r = makeNode(MultiAssignRef);
10696 :
10697 31 : r->source = (Node *) $5;
10698 31 : r->colno = i;
10699 31 : r->ncolumns = ncolumns;
10700 31 : res_col->val = (Node *) r;
10701 31 : i++;
10702 : }
10703 :
10704 15 : $$ = $2;
10705 : }
10706 : ;
10707 :
10708 : set_target:
10709 : ColId opt_indirection
10710 : {
10711 839 : $$ = makeNode(ResTarget);
10712 839 : $$->name = $1;
10713 839 : $$->indirection = check_indirection($2, yyscanner);
10714 839 : $$->val = NULL; /* upper production sets this */
10715 839 : $$->location = @1;
10716 : }
10717 : ;
10718 :
10719 : set_target_list:
10720 15 : set_target { $$ = list_make1($1); }
10721 16 : | set_target_list ',' set_target { $$ = lappend($1,$3); }
10722 : ;
10723 :
10724 :
10725 : /*****************************************************************************
10726 : *
10727 : * QUERY:
10728 : * CURSOR STATEMENTS
10729 : *
10730 : *****************************************************************************/
10731 : DeclareCursorStmt: DECLARE cursor_name cursor_options CURSOR opt_hold FOR SelectStmt
10732 : {
10733 103 : DeclareCursorStmt *n = makeNode(DeclareCursorStmt);
10734 103 : n->portalname = $2;
10735 : /* currently we always set FAST_PLAN option */
10736 103 : n->options = $3 | $5 | CURSOR_OPT_FAST_PLAN;
10737 103 : n->query = $7;
10738 103 : $$ = (Node *)n;
10739 : }
10740 : ;
10741 :
10742 384 : cursor_name: name { $$ = $1; }
10743 : ;
10744 :
10745 103 : cursor_options: /*EMPTY*/ { $$ = 0; }
10746 13 : | cursor_options NO SCROLL { $$ = $1 | CURSOR_OPT_NO_SCROLL; }
10747 30 : | cursor_options SCROLL { $$ = $1 | CURSOR_OPT_SCROLL; }
10748 1 : | cursor_options BINARY { $$ = $1 | CURSOR_OPT_BINARY; }
10749 0 : | cursor_options INSENSITIVE { $$ = $1 | CURSOR_OPT_INSENSITIVE; }
10750 : ;
10751 :
10752 95 : opt_hold: /* EMPTY */ { $$ = 0; }
10753 7 : | WITH HOLD { $$ = CURSOR_OPT_HOLD; }
10754 1 : | WITHOUT HOLD { $$ = 0; }
10755 : ;
10756 :
10757 : /*****************************************************************************
10758 : *
10759 : * QUERY:
10760 : * SELECT STATEMENTS
10761 : *
10762 : *****************************************************************************/
10763 :
10764 : /* A complete SELECT statement looks like this.
10765 : *
10766 : * The rule returns either a single SelectStmt node or a tree of them,
10767 : * representing a set-operation tree.
10768 : *
10769 : * There is an ambiguity when a sub-SELECT is within an a_expr and there
10770 : * are excess parentheses: do the parentheses belong to the sub-SELECT or
10771 : * to the surrounding a_expr? We don't really care, but bison wants to know.
10772 : * To resolve the ambiguity, we are careful to define the grammar so that
10773 : * the decision is staved off as long as possible: as long as we can keep
10774 : * absorbing parentheses into the sub-SELECT, we will do so, and only when
10775 : * it's no longer possible to do that will we decide that parens belong to
10776 : * the expression. For example, in "SELECT (((SELECT 2)) + 3)" the extra
10777 : * parentheses are treated as part of the sub-select. The necessity of doing
10778 : * it that way is shown by "SELECT (((SELECT 2)) UNION SELECT 2)". Had we
10779 : * parsed "((SELECT 2))" as an a_expr, it'd be too late to go back to the
10780 : * SELECT viewpoint when we see the UNION.
10781 : *
10782 : * This approach is implemented by defining a nonterminal select_with_parens,
10783 : * which represents a SELECT with at least one outer layer of parentheses,
10784 : * and being careful to use select_with_parens, never '(' SelectStmt ')',
10785 : * in the expression grammar. We will then have shift-reduce conflicts
10786 : * which we can resolve in favor of always treating '(' <select> ')' as
10787 : * a select_with_parens. To resolve the conflicts, the productions that
10788 : * conflict with the select_with_parens productions are manually given
10789 : * precedences lower than the precedence of ')', thereby ensuring that we
10790 : * shift ')' (and then reduce to select_with_parens) rather than trying to
10791 : * reduce the inner <select> nonterminal to something else. We use UMINUS
10792 : * precedence for this, which is a fairly arbitrary choice.
10793 : *
10794 : * To be able to define select_with_parens itself without ambiguity, we need
10795 : * a nonterminal select_no_parens that represents a SELECT structure with no
10796 : * outermost parentheses. This is a little bit tedious, but it works.
10797 : *
10798 : * In non-expression contexts, we use SelectStmt which can represent a SELECT
10799 : * with or without outer parentheses.
10800 : */
10801 :
10802 : SelectStmt: select_no_parens %prec UMINUS
10803 : | select_with_parens %prec UMINUS
10804 : ;
10805 :
10806 : select_with_parens:
10807 2648 : '(' select_no_parens ')' { $$ = $2; }
10808 22 : | '(' select_with_parens ')' { $$ = $2; }
10809 : ;
10810 :
10811 : /*
10812 : * This rule parses the equivalent of the standard's <query expression>.
10813 : * The duplicative productions are annoying, but hard to get rid of without
10814 : * creating shift/reduce conflicts.
10815 : *
10816 : * The locking clause (FOR UPDATE etc) may be before or after LIMIT/OFFSET.
10817 : * In <=7.2.X, LIMIT/OFFSET had to be after FOR UPDATE
10818 : * We now support both orderings, but prefer LIMIT/OFFSET before the locking
10819 : * clause.
10820 : * 2002-08-28 bjm
10821 : */
10822 : select_no_parens:
10823 26022 : simple_select { $$ = $1; }
10824 : | select_clause sort_clause
10825 : {
10826 2742 : insertSelectOptions((SelectStmt *) $1, $2, NIL,
10827 : NULL, NULL, NULL,
10828 : yyscanner);
10829 2742 : $$ = $1;
10830 : }
10831 : | select_clause opt_sort_clause for_locking_clause opt_select_limit
10832 : {
10833 126 : insertSelectOptions((SelectStmt *) $1, $2, $3,
10834 126 : list_nth($4, 0), list_nth($4, 1),
10835 : NULL,
10836 : yyscanner);
10837 126 : $$ = $1;
10838 : }
10839 : | select_clause opt_sort_clause select_limit opt_for_locking_clause
10840 : {
10841 226 : insertSelectOptions((SelectStmt *) $1, $2, $4,
10842 226 : list_nth($3, 0), list_nth($3, 1),
10843 : NULL,
10844 : yyscanner);
10845 226 : $$ = $1;
10846 : }
10847 : | with_clause select_clause
10848 : {
10849 98 : insertSelectOptions((SelectStmt *) $2, NULL, NIL,
10850 : NULL, NULL,
10851 98 : $1,
10852 : yyscanner);
10853 98 : $$ = $2;
10854 : }
10855 : | with_clause select_clause sort_clause
10856 : {
10857 17 : insertSelectOptions((SelectStmt *) $2, $3, NIL,
10858 : NULL, NULL,
10859 17 : $1,
10860 : yyscanner);
10861 17 : $$ = $2;
10862 : }
10863 : | with_clause select_clause opt_sort_clause for_locking_clause opt_select_limit
10864 : {
10865 0 : insertSelectOptions((SelectStmt *) $2, $3, $4,
10866 0 : list_nth($5, 0), list_nth($5, 1),
10867 0 : $1,
10868 : yyscanner);
10869 0 : $$ = $2;
10870 : }
10871 : | with_clause select_clause opt_sort_clause select_limit opt_for_locking_clause
10872 : {
10873 12 : insertSelectOptions((SelectStmt *) $2, $3, $5,
10874 6 : list_nth($4, 0), list_nth($4, 1),
10875 6 : $1,
10876 : yyscanner);
10877 6 : $$ = $2;
10878 : }
10879 : ;
10880 :
10881 : select_clause:
10882 4175 : simple_select { $$ = $1; }
10883 36 : | select_with_parens { $$ = $1; }
10884 : ;
10885 :
10886 : /*
10887 : * This rule parses SELECT statements that can appear within set operations,
10888 : * including UNION, INTERSECT and EXCEPT. '(' and ')' can be used to specify
10889 : * the ordering of the set operations. Without '(' and ')' we want the
10890 : * operations to be ordered per the precedence specs at the head of this file.
10891 : *
10892 : * As with select_no_parens, simple_select cannot have outer parentheses,
10893 : * but can have parenthesized subclauses.
10894 : *
10895 : * Note that sort clauses cannot be included at this level --- SQL requires
10896 : * SELECT foo UNION SELECT bar ORDER BY baz
10897 : * to be parsed as
10898 : * (SELECT foo UNION SELECT bar) ORDER BY baz
10899 : * not
10900 : * SELECT foo UNION (SELECT bar ORDER BY baz)
10901 : * Likewise for WITH, FOR UPDATE and LIMIT. Therefore, those clauses are
10902 : * described as part of the select_no_parens production, not simple_select.
10903 : * This does not limit functionality, because you can reintroduce these
10904 : * clauses inside parentheses.
10905 : *
10906 : * NOTE: only the leftmost component SelectStmt should have INTO.
10907 : * However, this is not checked by the grammar; parse analysis must check it.
10908 : */
10909 : simple_select:
10910 : SELECT opt_all_clause opt_target_list
10911 : into_clause from_clause where_clause
10912 : group_clause having_clause window_clause
10913 : {
10914 25912 : SelectStmt *n = makeNode(SelectStmt);
10915 25912 : n->targetList = $3;
10916 25912 : n->intoClause = $4;
10917 25912 : n->fromClause = $5;
10918 25912 : n->whereClause = $6;
10919 25912 : n->groupClause = $7;
10920 25912 : n->havingClause = $8;
10921 25912 : n->windowClause = $9;
10922 25912 : $$ = (Node *)n;
10923 : }
10924 : | SELECT distinct_clause target_list
10925 : into_clause from_clause where_clause
10926 : group_clause having_clause window_clause
10927 : {
10928 68 : SelectStmt *n = makeNode(SelectStmt);
10929 68 : n->distinctClause = $2;
10930 68 : n->targetList = $3;
10931 68 : n->intoClause = $4;
10932 68 : n->fromClause = $5;
10933 68 : n->whereClause = $6;
10934 68 : n->groupClause = $7;
10935 68 : n->havingClause = $8;
10936 68 : n->windowClause = $9;
10937 68 : $$ = (Node *)n;
10938 : }
10939 3706 : | values_clause { $$ = $1; }
10940 : | TABLE relation_expr
10941 : {
10942 : /* same as SELECT * FROM relation_expr */
10943 13 : ColumnRef *cr = makeNode(ColumnRef);
10944 13 : ResTarget *rt = makeNode(ResTarget);
10945 13 : SelectStmt *n = makeNode(SelectStmt);
10946 :
10947 13 : cr->fields = list_make1(makeNode(A_Star));
10948 13 : cr->location = -1;
10949 :
10950 13 : rt->name = NULL;
10951 13 : rt->indirection = NIL;
10952 13 : rt->val = (Node *)cr;
10953 13 : rt->location = -1;
10954 :
10955 13 : n->targetList = list_make1(rt);
10956 13 : n->fromClause = list_make1($2);
10957 13 : $$ = (Node *)n;
10958 : }
10959 : | select_clause UNION all_or_distinct select_clause
10960 : {
10961 449 : $$ = makeSetOp(SETOP_UNION, $3, $1, $4);
10962 : }
10963 : | select_clause INTERSECT all_or_distinct select_clause
10964 : {
10965 19 : $$ = makeSetOp(SETOP_INTERSECT, $3, $1, $4);
10966 : }
10967 : | select_clause EXCEPT all_or_distinct select_clause
10968 : {
10969 30 : $$ = makeSetOp(SETOP_EXCEPT, $3, $1, $4);
10970 : }
10971 : ;
10972 :
10973 : /*
10974 : * SQL standard WITH clause looks like:
10975 : *
10976 : * WITH [ RECURSIVE ] <query name> [ (<column>,...) ]
10977 : * AS (query) [ SEARCH or CYCLE clause ]
10978 : *
10979 : * We don't currently support the SEARCH or CYCLE clause.
10980 : *
10981 : * Recognizing WITH_LA here allows a CTE to be named TIME or ORDINALITY.
10982 : */
10983 : with_clause:
10984 : WITH cte_list
10985 : {
10986 81 : $$ = makeNode(WithClause);
10987 81 : $$->ctes = $2;
10988 81 : $$->recursive = false;
10989 81 : $$->location = @1;
10990 : }
10991 : | WITH_LA cte_list
10992 : {
10993 1 : $$ = makeNode(WithClause);
10994 1 : $$->ctes = $2;
10995 1 : $$->recursive = false;
10996 1 : $$->location = @1;
10997 : }
10998 : | WITH RECURSIVE cte_list
10999 : {
11000 67 : $$ = makeNode(WithClause);
11001 67 : $$->ctes = $3;
11002 67 : $$->recursive = true;
11003 67 : $$->location = @1;
11004 : }
11005 : ;
11006 :
11007 : cte_list:
11008 149 : common_table_expr { $$ = list_make1($1); }
11009 27 : | cte_list ',' common_table_expr { $$ = lappend($1, $3); }
11010 : ;
11011 :
11012 : common_table_expr: name opt_name_list AS '(' PreparableStmt ')'
11013 : {
11014 176 : CommonTableExpr *n = makeNode(CommonTableExpr);
11015 176 : n->ctename = $1;
11016 176 : n->aliascolnames = $2;
11017 176 : n->ctequery = $5;
11018 176 : n->location = @1;
11019 176 : $$ = (Node *) n;
11020 : }
11021 : ;
11022 :
11023 : opt_with_clause:
11024 28 : with_clause { $$ = $1; }
11025 4603 : | /*EMPTY*/ { $$ = NULL; }
11026 : ;
11027 :
11028 : into_clause:
11029 : INTO OptTempTableName
11030 : {
11031 24 : $$ = makeNode(IntoClause);
11032 24 : $$->rel = $2;
11033 24 : $$->colNames = NIL;
11034 24 : $$->options = NIL;
11035 24 : $$->onCommit = ONCOMMIT_NOOP;
11036 24 : $$->tableSpaceName = NULL;
11037 24 : $$->viewQuery = NULL;
11038 24 : $$->skipData = false;
11039 : }
11040 : | /*EMPTY*/
11041 25957 : { $$ = NULL; }
11042 : ;
11043 :
11044 : /*
11045 : * Redundancy here is needed to avoid shift/reduce conflicts,
11046 : * since TEMP is not a reserved word. See also OptTemp.
11047 : */
11048 : OptTempTableName:
11049 : TEMPORARY opt_table qualified_name
11050 : {
11051 0 : $$ = $3;
11052 0 : $$->relpersistence = RELPERSISTENCE_TEMP;
11053 : }
11054 : | TEMP opt_table qualified_name
11055 : {
11056 1 : $$ = $3;
11057 1 : $$->relpersistence = RELPERSISTENCE_TEMP;
11058 : }
11059 : | LOCAL TEMPORARY opt_table qualified_name
11060 : {
11061 0 : $$ = $4;
11062 0 : $$->relpersistence = RELPERSISTENCE_TEMP;
11063 : }
11064 : | LOCAL TEMP opt_table qualified_name
11065 : {
11066 0 : $$ = $4;
11067 0 : $$->relpersistence = RELPERSISTENCE_TEMP;
11068 : }
11069 : | GLOBAL TEMPORARY opt_table qualified_name
11070 : {
11071 0 : ereport(WARNING,
11072 : (errmsg("GLOBAL is deprecated in temporary table creation"),
11073 : parser_errposition(@1)));
11074 0 : $$ = $4;
11075 0 : $$->relpersistence = RELPERSISTENCE_TEMP;
11076 : }
11077 : | GLOBAL TEMP opt_table qualified_name
11078 : {
11079 0 : ereport(WARNING,
11080 : (errmsg("GLOBAL is deprecated in temporary table creation"),
11081 : parser_errposition(@1)));
11082 0 : $$ = $4;
11083 0 : $$->relpersistence = RELPERSISTENCE_TEMP;
11084 : }
11085 : | UNLOGGED opt_table qualified_name
11086 : {
11087 0 : $$ = $3;
11088 0 : $$->relpersistence = RELPERSISTENCE_UNLOGGED;
11089 : }
11090 : | TABLE qualified_name
11091 : {
11092 12 : $$ = $2;
11093 12 : $$->relpersistence = RELPERSISTENCE_PERMANENT;
11094 : }
11095 : | qualified_name
11096 : {
11097 11 : $$ = $1;
11098 11 : $$->relpersistence = RELPERSISTENCE_PERMANENT;
11099 : }
11100 : ;
11101 :
11102 : opt_table: TABLE {}
11103 : | /*EMPTY*/ {}
11104 : ;
11105 :
11106 : all_or_distinct:
11107 387 : ALL { $$ = TRUE; }
11108 0 : | DISTINCT { $$ = FALSE; }
11109 111 : | /*EMPTY*/ { $$ = FALSE; }
11110 : ;
11111 :
11112 : /* We use (NIL) as a placeholder to indicate that all target expressions
11113 : * should be placed in the DISTINCT list during parsetree analysis.
11114 : */
11115 : distinct_clause:
11116 58 : DISTINCT { $$ = list_make1(NIL); }
11117 11 : | DISTINCT ON '(' expr_list ')' { $$ = $4; }
11118 : ;
11119 :
11120 : opt_all_clause:
11121 0 : ALL { $$ = NIL;}
11122 25917 : | /*EMPTY*/ { $$ = NIL; }
11123 : ;
11124 :
11125 : opt_sort_clause:
11126 281 : sort_clause { $$ = $1;}
11127 11254 : | /*EMPTY*/ { $$ = NIL; }
11128 : ;
11129 :
11130 : sort_clause:
11131 3077 : ORDER BY sortby_list { $$ = $3; }
11132 : ;
11133 :
11134 : sortby_list:
11135 3077 : sortby { $$ = list_make1($1); }
11136 716 : | sortby_list ',' sortby { $$ = lappend($1, $3); }
11137 : ;
11138 :
11139 : sortby: a_expr USING qual_all_Op opt_nulls_order
11140 : {
11141 32 : $$ = makeNode(SortBy);
11142 32 : $$->node = $1;
11143 32 : $$->sortby_dir = SORTBY_USING;
11144 32 : $$->sortby_nulls = $4;
11145 32 : $$->useOp = $3;
11146 32 : $$->location = @3;
11147 : }
11148 : | a_expr opt_asc_desc opt_nulls_order
11149 : {
11150 3761 : $$ = makeNode(SortBy);
11151 3761 : $$->node = $1;
11152 3761 : $$->sortby_dir = $2;
11153 3761 : $$->sortby_nulls = $3;
11154 3761 : $$->useOp = NIL;
11155 3761 : $$->location = -1; /* no operator */
11156 : }
11157 : ;
11158 :
11159 :
11160 : select_limit:
11161 10 : limit_clause offset_clause { $$ = list_make2($2, $1); }
11162 1 : | offset_clause limit_clause { $$ = list_make2($1, $2); }
11163 186 : | limit_clause { $$ = list_make2(NULL, $1); }
11164 35 : | offset_clause { $$ = list_make2($1, NULL); }
11165 : ;
11166 :
11167 : opt_select_limit:
11168 0 : select_limit { $$ = $1; }
11169 126 : | /* EMPTY */ { $$ = list_make2(NULL,NULL); }
11170 : ;
11171 :
11172 : limit_clause:
11173 : LIMIT select_limit_value
11174 197 : { $$ = $2; }
11175 : | LIMIT select_limit_value ',' select_offset_value
11176 : {
11177 : /* Disabled because it was too confusing, bjm 2002-02-18 */
11178 0 : ereport(ERROR,
11179 : (errcode(ERRCODE_SYNTAX_ERROR),
11180 : errmsg("LIMIT #,# syntax is not supported"),
11181 : errhint("Use separate LIMIT and OFFSET clauses."),
11182 : parser_errposition(@1)));
11183 : }
11184 : /* SQL:2008 syntax */
11185 : | FETCH first_or_next opt_select_fetch_first_value row_or_rows ONLY
11186 0 : { $$ = $3; }
11187 : ;
11188 :
11189 : offset_clause:
11190 : OFFSET select_offset_value
11191 46 : { $$ = $2; }
11192 : /* SQL:2008 syntax */
11193 : | OFFSET select_offset_value2 row_or_rows
11194 0 : { $$ = $2; }
11195 : ;
11196 :
11197 : select_limit_value:
11198 197 : a_expr { $$ = $1; }
11199 : | ALL
11200 : {
11201 : /* LIMIT ALL is represented as a NULL constant */
11202 0 : $$ = makeNullAConst(@1);
11203 : }
11204 : ;
11205 :
11206 : select_offset_value:
11207 46 : a_expr { $$ = $1; }
11208 : ;
11209 :
11210 : /*
11211 : * Allowing full expressions without parentheses causes various parsing
11212 : * problems with the trailing ROW/ROWS key words. SQL only calls for
11213 : * constants, so we allow the rest only with parentheses. If omitted,
11214 : * default to 1.
11215 : */
11216 : opt_select_fetch_first_value:
11217 0 : SignedIconst { $$ = makeIntConst($1, @1); }
11218 0 : | '(' a_expr ')' { $$ = $2; }
11219 0 : | /*EMPTY*/ { $$ = makeIntConst(1, -1); }
11220 : ;
11221 :
11222 : /*
11223 : * Again, the trailing ROW/ROWS in this case prevent the full expression
11224 : * syntax. c_expr is the best we can do.
11225 : */
11226 : select_offset_value2:
11227 0 : c_expr { $$ = $1; }
11228 : ;
11229 :
11230 : /* noise words */
11231 0 : row_or_rows: ROW { $$ = 0; }
11232 0 : | ROWS { $$ = 0; }
11233 : ;
11234 :
11235 0 : first_or_next: FIRST_P { $$ = 0; }
11236 0 : | NEXT { $$ = 0; }
11237 : ;
11238 :
11239 :
11240 : /*
11241 : * This syntax for group_clause tries to follow the spec quite closely.
11242 : * However, the spec allows only column references, not expressions,
11243 : * which introduces an ambiguity between implicit row constructors
11244 : * (a,b) and lists of column references.
11245 : *
11246 : * We handle this by using the a_expr production for what the spec calls
11247 : * <ordinary grouping set>, which in the spec represents either one column
11248 : * reference or a parenthesized list of column references. Then, we check the
11249 : * top node of the a_expr to see if it's an implicit RowExpr, and if so, just
11250 : * grab and use the list, discarding the node. (this is done in parse analysis,
11251 : * not here)
11252 : *
11253 : * (we abuse the row_format field of RowExpr to distinguish implicit and
11254 : * explicit row constructors; it's debatable if anyone sanely wants to use them
11255 : * in a group clause, but if they have a reason to, we make it possible.)
11256 : *
11257 : * Each item in the group_clause list is either an expression tree or a
11258 : * GroupingSet node of some type.
11259 : */
11260 : group_clause:
11261 312 : GROUP_P BY group_by_list { $$ = $3; }
11262 25668 : | /*EMPTY*/ { $$ = NIL; }
11263 : ;
11264 :
11265 : group_by_list:
11266 380 : group_by_item { $$ = list_make1($1); }
11267 191 : | group_by_list ',' group_by_item { $$ = lappend($1,$3); }
11268 : ;
11269 :
11270 : group_by_item:
11271 422 : a_expr { $$ = $1; }
11272 32 : | empty_grouping_set { $$ = $1; }
11273 23 : | cube_clause { $$ = $1; }
11274 26 : | rollup_clause { $$ = $1; }
11275 68 : | grouping_sets_clause { $$ = $1; }
11276 : ;
11277 :
11278 : empty_grouping_set:
11279 : '(' ')'
11280 : {
11281 32 : $$ = (Node *) makeGroupingSet(GROUPING_SET_EMPTY, NIL, @1);
11282 : }
11283 : ;
11284 :
11285 : /*
11286 : * These hacks rely on setting precedence of CUBE and ROLLUP below that of '(',
11287 : * so that they shift in these rules rather than reducing the conflicting
11288 : * unreserved_keyword rule.
11289 : */
11290 :
11291 : rollup_clause:
11292 : ROLLUP '(' expr_list ')'
11293 : {
11294 26 : $$ = (Node *) makeGroupingSet(GROUPING_SET_ROLLUP, $3, @1);
11295 : }
11296 : ;
11297 :
11298 : cube_clause:
11299 : CUBE '(' expr_list ')'
11300 : {
11301 23 : $$ = (Node *) makeGroupingSet(GROUPING_SET_CUBE, $3, @1);
11302 : }
11303 : ;
11304 :
11305 : grouping_sets_clause:
11306 : GROUPING SETS '(' group_by_list ')'
11307 : {
11308 68 : $$ = (Node *) makeGroupingSet(GROUPING_SET_SETS, $4, @1);
11309 : }
11310 : ;
11311 :
11312 : having_clause:
11313 31 : HAVING a_expr { $$ = $2; }
11314 25949 : | /*EMPTY*/ { $$ = NULL; }
11315 : ;
11316 :
11317 : for_locking_clause:
11318 126 : for_locking_items { $$ = $1; }
11319 0 : | FOR READ ONLY { $$ = NIL; }
11320 : ;
11321 :
11322 : opt_for_locking_clause:
11323 0 : for_locking_clause { $$ = $1; }
11324 232 : | /* EMPTY */ { $$ = NIL; }
11325 : ;
11326 :
11327 : for_locking_items:
11328 126 : for_locking_item { $$ = list_make1($1); }
11329 0 : | for_locking_items for_locking_item { $$ = lappend($1, $2); }
11330 : ;
11331 :
11332 : for_locking_item:
11333 : for_locking_strength locked_rels_list opt_nowait_or_skip
11334 : {
11335 126 : LockingClause *n = makeNode(LockingClause);
11336 126 : n->lockedRels = $2;
11337 126 : n->strength = $1;
11338 126 : n->waitPolicy = $3;
11339 126 : $$ = (Node *) n;
11340 : }
11341 : ;
11342 :
11343 : for_locking_strength:
11344 17 : FOR UPDATE { $$ = LCS_FORUPDATE; }
11345 1 : | FOR NO KEY UPDATE { $$ = LCS_FORNOKEYUPDATE; }
11346 7 : | FOR SHARE { $$ = LCS_FORSHARE; }
11347 101 : | FOR KEY SHARE { $$ = LCS_FORKEYSHARE; }
11348 : ;
11349 :
11350 : locked_rels_list:
11351 102 : OF qualified_name_list { $$ = $2; }
11352 24 : | /* EMPTY */ { $$ = NIL; }
11353 : ;
11354 :
11355 :
11356 : /*
11357 : * We should allow ROW '(' expr_list ')' too, but that seems to require
11358 : * making VALUES a fully reserved word, which will probably break more apps
11359 : * than allowing the noise-word is worth.
11360 : */
11361 : values_clause:
11362 : VALUES '(' expr_list ')'
11363 : {
11364 3706 : SelectStmt *n = makeNode(SelectStmt);
11365 3706 : n->valuesLists = list_make1($3);
11366 3706 : $$ = (Node *) n;
11367 : }
11368 : | values_clause ',' '(' expr_list ')'
11369 : {
11370 1472 : SelectStmt *n = (SelectStmt *) $1;
11371 1472 : n->valuesLists = lappend(n->valuesLists, $4);
11372 1472 : $$ = (Node *) n;
11373 : }
11374 : ;
11375 :
11376 :
11377 : /*****************************************************************************
11378 : *
11379 : * clauses common to all Optimizable Stmts:
11380 : * from_clause - allow list of both JOIN expressions and table names
11381 : * where_clause - qualifications for joins or restrictions
11382 : *
11383 : *****************************************************************************/
11384 :
11385 : from_clause:
11386 13122 : FROM from_list { $$ = $2; }
11387 13433 : | /*EMPTY*/ { $$ = NIL; }
11388 : ;
11389 :
11390 : from_list:
11391 13167 : table_ref { $$ = list_make1($1); }
11392 1411 : | from_list ',' table_ref { $$ = lappend($1, $3); }
11393 : ;
11394 :
11395 : /*
11396 : * table_ref is where an alias clause can be attached.
11397 : */
11398 : table_ref: relation_expr opt_alias_clause
11399 : {
11400 14304 : $1->alias = $2;
11401 14304 : $$ = (Node *) $1;
11402 : }
11403 : | relation_expr opt_alias_clause tablesample_clause
11404 : {
11405 33 : RangeTableSample *n = (RangeTableSample *) $3;
11406 33 : $1->alias = $2;
11407 : /* relation_expr goes inside the RangeTableSample node */
11408 33 : n->relation = (Node *) $1;
11409 33 : $$ = (Node *) n;
11410 : }
11411 : | func_table func_alias_clause
11412 : {
11413 1296 : RangeFunction *n = (RangeFunction *) $1;
11414 1296 : n->alias = linitial($2);
11415 1296 : n->coldeflist = lsecond($2);
11416 1296 : $$ = (Node *) n;
11417 : }
11418 : | LATERAL_P func_table func_alias_clause
11419 : {
11420 9 : RangeFunction *n = (RangeFunction *) $2;
11421 9 : n->lateral = true;
11422 9 : n->alias = linitial($3);
11423 9 : n->coldeflist = lsecond($3);
11424 9 : $$ = (Node *) n;
11425 : }
11426 : | xmltable opt_alias_clause
11427 : {
11428 8 : RangeTableFunc *n = (RangeTableFunc *) $1;
11429 8 : n->alias = $2;
11430 8 : $$ = (Node *) n;
11431 : }
11432 : | LATERAL_P xmltable opt_alias_clause
11433 : {
11434 22 : RangeTableFunc *n = (RangeTableFunc *) $2;
11435 22 : n->lateral = true;
11436 22 : n->alias = $3;
11437 22 : $$ = (Node *) n;
11438 : }
11439 : | select_with_parens opt_alias_clause
11440 : {
11441 731 : RangeSubselect *n = makeNode(RangeSubselect);
11442 731 : n->lateral = false;
11443 731 : n->subquery = $1;
11444 731 : n->alias = $2;
11445 : /*
11446 : * The SQL spec does not permit a subselect
11447 : * (<derived_table>) without an alias clause,
11448 : * so we don't either. This avoids the problem
11449 : * of needing to invent a unique refname for it.
11450 : * That could be surmounted if there's sufficient
11451 : * popular demand, but for now let's just implement
11452 : * the spec and see if anyone complains.
11453 : * However, it does seem like a good idea to emit
11454 : * an error message that's better than "syntax error".
11455 : */
11456 731 : if ($2 == NULL)
11457 : {
11458 0 : if (IsA($1, SelectStmt) &&
11459 0 : ((SelectStmt *) $1)->valuesLists)
11460 0 : ereport(ERROR,
11461 : (errcode(ERRCODE_SYNTAX_ERROR),
11462 : errmsg("VALUES in FROM must have an alias"),
11463 : errhint("For example, FROM (VALUES ...) [AS] foo."),
11464 : parser_errposition(@1)));
11465 : else
11466 0 : ereport(ERROR,
11467 : (errcode(ERRCODE_SYNTAX_ERROR),
11468 : errmsg("subquery in FROM must have an alias"),
11469 : errhint("For example, FROM (SELECT ...) [AS] foo."),
11470 : parser_errposition(@1)));
11471 : }
11472 731 : $$ = (Node *) n;
11473 : }
11474 : | LATERAL_P select_with_parens opt_alias_clause
11475 : {
11476 87 : RangeSubselect *n = makeNode(RangeSubselect);
11477 87 : n->lateral = true;
11478 87 : n->subquery = $2;
11479 87 : n->alias = $3;
11480 : /* same comment as above */
11481 87 : if ($3 == NULL)
11482 : {
11483 0 : if (IsA($2, SelectStmt) &&
11484 0 : ((SelectStmt *) $2)->valuesLists)
11485 0 : ereport(ERROR,
11486 : (errcode(ERRCODE_SYNTAX_ERROR),
11487 : errmsg("VALUES in FROM must have an alias"),
11488 : errhint("For example, FROM (VALUES ...) [AS] foo."),
11489 : parser_errposition(@2)));
11490 : else
11491 0 : ereport(ERROR,
11492 : (errcode(ERRCODE_SYNTAX_ERROR),
11493 : errmsg("subquery in FROM must have an alias"),
11494 : errhint("For example, FROM (SELECT ...) [AS] foo."),
11495 : parser_errposition(@2)));
11496 : }
11497 87 : $$ = (Node *) n;
11498 : }
11499 : | joined_table
11500 : {
11501 1902 : $$ = (Node *) $1;
11502 : }
11503 : | '(' joined_table ')' alias_clause
11504 : {
11505 10 : $2->alias = $4;
11506 10 : $$ = (Node *) $2;
11507 : }
11508 : ;
11509 :
11510 :
11511 : /*
11512 : * It may seem silly to separate joined_table from table_ref, but there is
11513 : * method in SQL's madness: if you don't do it this way you get reduce-
11514 : * reduce conflicts, because it's not clear to the parser generator whether
11515 : * to expect alias_clause after ')' or not. For the same reason we must
11516 : * treat 'JOIN' and 'join_type JOIN' separately, rather than allowing
11517 : * join_type to expand to empty; if we try it, the parser generator can't
11518 : * figure out when to reduce an empty join_type right after table_ref.
11519 : *
11520 : * Note that a CROSS JOIN is the same as an unqualified
11521 : * INNER JOIN, and an INNER JOIN/ON has the same shape
11522 : * but a qualification expression to limit membership.
11523 : * A NATURAL JOIN implicitly matches column names between
11524 : * tables and the shape is determined by which columns are
11525 : * in common. We'll collect columns during the later transformations.
11526 : */
11527 :
11528 : joined_table:
11529 : '(' joined_table ')'
11530 : {
11531 43 : $$ = $2;
11532 : }
11533 : | table_ref CROSS JOIN table_ref
11534 : {
11535 : /* CROSS JOIN is same as unqualified inner join */
11536 27 : JoinExpr *n = makeNode(JoinExpr);
11537 27 : n->jointype = JOIN_INNER;
11538 27 : n->isNatural = FALSE;
11539 27 : n->larg = $1;
11540 27 : n->rarg = $4;
11541 27 : n->usingClause = NIL;
11542 27 : n->quals = NULL;
11543 27 : $$ = n;
11544 : }
11545 : | table_ref join_type JOIN table_ref join_qual
11546 : {
11547 1007 : JoinExpr *n = makeNode(JoinExpr);
11548 1007 : n->jointype = $2;
11549 1007 : n->isNatural = FALSE;
11550 1007 : n->larg = $1;
11551 1007 : n->rarg = $4;
11552 1007 : if ($5 != NULL && IsA($5, List))
11553 39 : n->usingClause = (List *) $5; /* USING clause */
11554 : else
11555 968 : n->quals = $5; /* ON clause */
11556 1007 : $$ = n;
11557 : }
11558 : | table_ref JOIN table_ref join_qual
11559 : {
11560 : /* letting join_type reduce to empty doesn't work */
11561 838 : JoinExpr *n = makeNode(JoinExpr);
11562 838 : n->jointype = JOIN_INNER;
11563 838 : n->isNatural = FALSE;
11564 838 : n->larg = $1;
11565 838 : n->rarg = $3;
11566 838 : if ($4 != NULL && IsA($4, List))
11567 23 : n->usingClause = (List *) $4; /* USING clause */
11568 : else
11569 815 : n->quals = $4; /* ON clause */
11570 838 : $$ = n;
11571 : }
11572 : | table_ref NATURAL join_type JOIN table_ref
11573 : {
11574 13 : JoinExpr *n = makeNode(JoinExpr);
11575 13 : n->jointype = $3;
11576 13 : n->isNatural = TRUE;
11577 13 : n->larg = $1;
11578 13 : n->rarg = $5;
11579 13 : n->usingClause = NIL; /* figure out which columns later... */
11580 13 : n->quals = NULL; /* fill later */
11581 13 : $$ = n;
11582 : }
11583 : | table_ref NATURAL JOIN table_ref
11584 : {
11585 : /* letting join_type reduce to empty doesn't work */
11586 27 : JoinExpr *n = makeNode(JoinExpr);
11587 27 : n->jointype = JOIN_INNER;
11588 27 : n->isNatural = TRUE;
11589 27 : n->larg = $1;
11590 27 : n->rarg = $4;
11591 27 : n->usingClause = NIL; /* figure out which columns later... */
11592 27 : n->quals = NULL; /* fill later */
11593 27 : $$ = n;
11594 : }
11595 : ;
11596 :
11597 : alias_clause:
11598 : AS ColId '(' name_list ')'
11599 : {
11600 144 : $$ = makeNode(Alias);
11601 144 : $$->aliasname = $2;
11602 144 : $$->colnames = $4;
11603 : }
11604 : | AS ColId
11605 : {
11606 571 : $$ = makeNode(Alias);
11607 571 : $$->aliasname = $2;
11608 : }
11609 : | ColId '(' name_list ')'
11610 : {
11611 584 : $$ = makeNode(Alias);
11612 584 : $$->aliasname = $1;
11613 584 : $$->colnames = $3;
11614 : }
11615 : | ColId
11616 : {
11617 7508 : $$ = makeNode(Alias);
11618 7508 : $$->aliasname = $1;
11619 : }
11620 : ;
11621 :
11622 7857 : opt_alias_clause: alias_clause { $$ = $1; }
11623 7328 : | /*EMPTY*/ { $$ = NULL; }
11624 : ;
11625 :
11626 : /*
11627 : * func_alias_clause can include both an Alias and a coldeflist, so we make it
11628 : * return a 2-element list that gets disassembled by calling production.
11629 : */
11630 : func_alias_clause:
11631 : alias_clause
11632 : {
11633 940 : $$ = list_make2($1, NIL);
11634 : }
11635 : | AS '(' TableFuncElementList ')'
11636 : {
11637 6 : $$ = list_make2(NULL, $3);
11638 : }
11639 : | AS ColId '(' TableFuncElementList ')'
11640 : {
11641 32 : Alias *a = makeNode(Alias);
11642 32 : a->aliasname = $2;
11643 32 : $$ = list_make2(a, $4);
11644 : }
11645 : | ColId '(' TableFuncElementList ')'
11646 : {
11647 0 : Alias *a = makeNode(Alias);
11648 0 : a->aliasname = $1;
11649 0 : $$ = list_make2(a, $3);
11650 : }
11651 : | /*EMPTY*/
11652 : {
11653 327 : $$ = list_make2(NULL, NIL);
11654 : }
11655 : ;
11656 :
11657 37 : join_type: FULL join_outer { $$ = JOIN_FULL; }
11658 909 : | LEFT join_outer { $$ = JOIN_LEFT; }
11659 19 : | RIGHT join_outer { $$ = JOIN_RIGHT; }
11660 55 : | INNER_P { $$ = JOIN_INNER; }
11661 : ;
11662 :
11663 : /* OUTER is just noise... */
11664 36 : join_outer: OUTER_P { $$ = NULL; }
11665 929 : | /*EMPTY*/ { $$ = NULL; }
11666 : ;
11667 :
11668 : /* JOIN qualification clauses
11669 : * Possibilities are:
11670 : * USING ( column list ) allows only unqualified column names,
11671 : * which must match between tables.
11672 : * ON expr allows more general qualifications.
11673 : *
11674 : * We return USING as a List node, while an ON-expr will not be a List.
11675 : */
11676 :
11677 62 : join_qual: USING '(' name_list ')' { $$ = (Node *) $3; }
11678 1783 : | ON a_expr { $$ = $2; }
11679 : ;
11680 :
11681 :
11682 : relation_expr:
11683 : qualified_name
11684 : {
11685 : /* inheritance query, implicitly */
11686 16148 : $$ = $1;
11687 16148 : $$->inh = true;
11688 16148 : $$->alias = NULL;
11689 : }
11690 : | qualified_name '*'
11691 : {
11692 : /* inheritance query, explicitly */
11693 30 : $$ = $1;
11694 30 : $$->inh = true;
11695 30 : $$->alias = NULL;
11696 : }
11697 : | ONLY qualified_name
11698 : {
11699 : /* no inheritance */
11700 256 : $$ = $2;
11701 256 : $$->inh = false;
11702 256 : $$->alias = NULL;
11703 : }
11704 : | ONLY '(' qualified_name ')'
11705 : {
11706 : /* no inheritance, SQL99-style syntax */
11707 0 : $$ = $3;
11708 0 : $$->inh = false;
11709 0 : $$->alias = NULL;
11710 : }
11711 : ;
11712 :
11713 :
11714 : relation_expr_list:
11715 133 : relation_expr { $$ = list_make1($1); }
11716 30 : | relation_expr_list ',' relation_expr { $$ = lappend($1, $3); }
11717 : ;
11718 :
11719 :
11720 : /*
11721 : * Given "UPDATE foo set set ...", we have to decide without looking any
11722 : * further ahead whether the first "set" is an alias or the UPDATE's SET
11723 : * keyword. Since "set" is allowed as a column name both interpretations
11724 : * are feasible. We resolve the shift/reduce conflict by giving the first
11725 : * relation_expr_opt_alias production a higher precedence than the SET token
11726 : * has, causing the parser to prefer to reduce, in effect assuming that the
11727 : * SET is not an alias.
11728 : */
11729 : relation_expr_opt_alias: relation_expr %prec UMINUS
11730 : {
11731 905 : $$ = $1;
11732 : }
11733 : | relation_expr ColId
11734 : {
11735 16 : Alias *alias = makeNode(Alias);
11736 16 : alias->aliasname = $2;
11737 16 : $1->alias = alias;
11738 16 : $$ = $1;
11739 : }
11740 : | relation_expr AS ColId
11741 : {
11742 4 : Alias *alias = makeNode(Alias);
11743 4 : alias->aliasname = $3;
11744 4 : $1->alias = alias;
11745 4 : $$ = $1;
11746 : }
11747 : ;
11748 :
11749 : /*
11750 : * TABLESAMPLE decoration in a FROM item
11751 : */
11752 : tablesample_clause:
11753 : TABLESAMPLE func_name '(' expr_list ')' opt_repeatable_clause
11754 : {
11755 33 : RangeTableSample *n = makeNode(RangeTableSample);
11756 : /* n->relation will be filled in later */
11757 33 : n->method = $2;
11758 33 : n->args = $4;
11759 33 : n->repeatable = $6;
11760 33 : n->location = @2;
11761 33 : $$ = (Node *) n;
11762 : }
11763 : ;
11764 :
11765 : opt_repeatable_clause:
11766 15 : REPEATABLE '(' a_expr ')' { $$ = (Node *) $3; }
11767 18 : | /*EMPTY*/ { $$ = NULL; }
11768 : ;
11769 :
11770 : /*
11771 : * func_table represents a function invocation in a FROM list. It can be
11772 : * a plain function call, like "foo(...)", or a ROWS FROM expression with
11773 : * one or more function calls, "ROWS FROM (foo(...), bar(...))",
11774 : * optionally with WITH ORDINALITY attached.
11775 : * In the ROWS FROM syntax, a column definition list can be given for each
11776 : * function, for example:
11777 : * ROWS FROM (foo() AS (foo_res_a text, foo_res_b text),
11778 : * bar() AS (bar_res_a text, bar_res_b text))
11779 : * It's also possible to attach a column definition list to the RangeFunction
11780 : * as a whole, but that's handled by the table_ref production.
11781 : */
11782 : func_table: func_expr_windowless opt_ordinality
11783 : {
11784 1284 : RangeFunction *n = makeNode(RangeFunction);
11785 1284 : n->lateral = false;
11786 1284 : n->ordinality = $2;
11787 1284 : n->is_rowsfrom = false;
11788 1284 : n->functions = list_make1(list_make2($1, NIL));
11789 : /* alias and coldeflist are set by table_ref production */
11790 1284 : $$ = (Node *) n;
11791 : }
11792 : | ROWS FROM '(' rowsfrom_list ')' opt_ordinality
11793 : {
11794 22 : RangeFunction *n = makeNode(RangeFunction);
11795 22 : n->lateral = false;
11796 22 : n->ordinality = $6;
11797 22 : n->is_rowsfrom = true;
11798 22 : n->functions = $4;
11799 : /* alias and coldeflist are set by table_ref production */
11800 22 : $$ = (Node *) n;
11801 : }
11802 : ;
11803 :
11804 : rowsfrom_item: func_expr_windowless opt_col_def_list
11805 53 : { $$ = list_make2($1, $2); }
11806 : ;
11807 :
11808 : rowsfrom_list:
11809 22 : rowsfrom_item { $$ = list_make1($1); }
11810 31 : | rowsfrom_list ',' rowsfrom_item { $$ = lappend($1, $3); }
11811 : ;
11812 :
11813 9 : opt_col_def_list: AS '(' TableFuncElementList ')' { $$ = $3; }
11814 44 : | /*EMPTY*/ { $$ = NIL; }
11815 : ;
11816 :
11817 61 : opt_ordinality: WITH_LA ORDINALITY { $$ = true; }
11818 1245 : | /*EMPTY*/ { $$ = false; }
11819 : ;
11820 :
11821 :
11822 : where_clause:
11823 7964 : WHERE a_expr { $$ = $2; }
11824 18688 : | /*EMPTY*/ { $$ = NULL; }
11825 : ;
11826 :
11827 : /* variant for UPDATE and DELETE */
11828 : where_or_current_clause:
11829 581 : WHERE a_expr { $$ = $2; }
11830 : | WHERE CURRENT_P OF cursor_name
11831 : {
11832 38 : CurrentOfExpr *n = makeNode(CurrentOfExpr);
11833 : /* cvarno is filled in by parse analysis */
11834 38 : n->cursor_name = $4;
11835 38 : n->cursor_param = 0;
11836 38 : $$ = (Node *) n;
11837 : }
11838 306 : | /*EMPTY*/ { $$ = NULL; }
11839 : ;
11840 :
11841 :
11842 : OptTableFuncElementList:
11843 50 : TableFuncElementList { $$ = $1; }
11844 1 : | /*EMPTY*/ { $$ = NIL; }
11845 : ;
11846 :
11847 : TableFuncElementList:
11848 : TableFuncElement
11849 : {
11850 97 : $$ = list_make1($1);
11851 : }
11852 : | TableFuncElementList ',' TableFuncElement
11853 : {
11854 141 : $$ = lappend($1, $3);
11855 : }
11856 : ;
11857 :
11858 : TableFuncElement: ColId Typename opt_collate_clause
11859 : {
11860 247 : ColumnDef *n = makeNode(ColumnDef);
11861 247 : n->colname = $1;
11862 247 : n->typeName = $2;
11863 247 : n->inhcount = 0;
11864 247 : n->is_local = true;
11865 247 : n->is_not_null = false;
11866 247 : n->is_from_type = false;
11867 247 : n->is_from_parent = false;
11868 247 : n->storage = 0;
11869 247 : n->raw_default = NULL;
11870 247 : n->cooked_default = NULL;
11871 247 : n->collClause = (CollateClause *) $3;
11872 247 : n->collOid = InvalidOid;
11873 247 : n->constraints = NIL;
11874 247 : n->location = @1;
11875 247 : $$ = (Node *)n;
11876 : }
11877 : ;
11878 :
11879 : /*
11880 : * XMLTABLE
11881 : */
11882 : xmltable:
11883 : XMLTABLE '(' c_expr xmlexists_argument COLUMNS xmltable_column_list ')'
11884 : {
11885 27 : RangeTableFunc *n = makeNode(RangeTableFunc);
11886 27 : n->rowexpr = $3;
11887 27 : n->docexpr = $4;
11888 27 : n->columns = $6;
11889 27 : n->namespaces = NIL;
11890 27 : n->location = @1;
11891 27 : $$ = (Node *)n;
11892 : }
11893 : | XMLTABLE '(' XMLNAMESPACES '(' xml_namespace_list ')' ','
11894 : c_expr xmlexists_argument COLUMNS xmltable_column_list ')'
11895 : {
11896 3 : RangeTableFunc *n = makeNode(RangeTableFunc);
11897 3 : n->rowexpr = $8;
11898 3 : n->docexpr = $9;
11899 3 : n->columns = $11;
11900 3 : n->namespaces = $5;
11901 3 : n->location = @1;
11902 3 : $$ = (Node *)n;
11903 : }
11904 : ;
11905 :
11906 30 : xmltable_column_list: xmltable_column_el { $$ = list_make1($1); }
11907 79 : | xmltable_column_list ',' xmltable_column_el { $$ = lappend($1, $3); }
11908 : ;
11909 :
11910 : xmltable_column_el:
11911 : ColId Typename
11912 : {
11913 30 : RangeTableFuncCol *fc = makeNode(RangeTableFuncCol);
11914 :
11915 30 : fc->colname = $1;
11916 30 : fc->for_ordinality = false;
11917 30 : fc->typeName = $2;
11918 30 : fc->is_not_null = false;
11919 30 : fc->colexpr = NULL;
11920 30 : fc->coldefexpr = NULL;
11921 30 : fc->location = @1;
11922 :
11923 30 : $$ = (Node *) fc;
11924 : }
11925 : | ColId Typename xmltable_column_option_list
11926 : {
11927 69 : RangeTableFuncCol *fc = makeNode(RangeTableFuncCol);
11928 : ListCell *option;
11929 69 : bool nullability_seen = false;
11930 :
11931 69 : fc->colname = $1;
11932 69 : fc->typeName = $2;
11933 69 : fc->for_ordinality = false;
11934 69 : fc->is_not_null = false;
11935 69 : fc->colexpr = NULL;
11936 69 : fc->coldefexpr = NULL;
11937 69 : fc->location = @1;
11938 :
11939 156 : foreach(option, $3)
11940 : {
11941 87 : DefElem *defel = (DefElem *) lfirst(option);
11942 :
11943 87 : if (strcmp(defel->defname, "default") == 0)
11944 : {
11945 9 : if (fc->coldefexpr != NULL)
11946 0 : ereport(ERROR,
11947 : (errcode(ERRCODE_SYNTAX_ERROR),
11948 : errmsg("only one DEFAULT value is allowed"),
11949 : parser_errposition(defel->location)));
11950 9 : fc->coldefexpr = defel->arg;
11951 : }
11952 78 : else if (strcmp(defel->defname, "path") == 0)
11953 : {
11954 69 : if (fc->colexpr != NULL)
11955 0 : ereport(ERROR,
11956 : (errcode(ERRCODE_SYNTAX_ERROR),
11957 : errmsg("only one PATH value per column is allowed"),
11958 : parser_errposition(defel->location)));
11959 69 : fc->colexpr = defel->arg;
11960 : }
11961 9 : else if (strcmp(defel->defname, "is_not_null") == 0)
11962 : {
11963 9 : if (nullability_seen)
11964 0 : ereport(ERROR,
11965 : (errcode(ERRCODE_SYNTAX_ERROR),
11966 : errmsg("conflicting or redundant NULL / NOT NULL declarations for column \"%s\"", fc->colname),
11967 : parser_errposition(defel->location)));
11968 9 : fc->is_not_null = intVal(defel->arg);
11969 9 : nullability_seen = true;
11970 : }
11971 : else
11972 : {
11973 0 : ereport(ERROR,
11974 : (errcode(ERRCODE_SYNTAX_ERROR),
11975 : errmsg("unrecognized column option \"%s\"",
11976 : defel->defname),
11977 : parser_errposition(defel->location)));
11978 : }
11979 : }
11980 69 : $$ = (Node *) fc;
11981 : }
11982 : | ColId FOR ORDINALITY
11983 : {
11984 10 : RangeTableFuncCol *fc = makeNode(RangeTableFuncCol);
11985 :
11986 10 : fc->colname = $1;
11987 10 : fc->for_ordinality = true;
11988 : /* other fields are ignored, initialized by makeNode */
11989 10 : fc->location = @1;
11990 :
11991 10 : $$ = (Node *) fc;
11992 : }
11993 : ;
11994 :
11995 : xmltable_column_option_list:
11996 : xmltable_column_option_el
11997 69 : { $$ = list_make1($1); }
11998 : | xmltable_column_option_list xmltable_column_option_el
11999 18 : { $$ = lappend($1, $2); }
12000 : ;
12001 :
12002 : xmltable_column_option_el:
12003 : IDENT b_expr
12004 69 : { $$ = makeDefElem($1, $2, @1); }
12005 : | DEFAULT b_expr
12006 9 : { $$ = makeDefElem("default", $2, @1); }
12007 : | NOT NULL_P
12008 9 : { $$ = makeDefElem("is_not_null", (Node *) makeInteger(true), @1); }
12009 : | NULL_P
12010 0 : { $$ = makeDefElem("is_not_null", (Node *) makeInteger(false), @1); }
12011 : ;
12012 :
12013 : xml_namespace_list:
12014 : xml_namespace_el
12015 3 : { $$ = list_make1($1); }
12016 : | xml_namespace_list ',' xml_namespace_el
12017 0 : { $$ = lappend($1, $3); }
12018 : ;
12019 :
12020 : xml_namespace_el:
12021 : b_expr AS ColLabel
12022 : {
12023 2 : $$ = makeNode(ResTarget);
12024 2 : $$->name = $3;
12025 2 : $$->indirection = NIL;
12026 2 : $$->val = $1;
12027 2 : $$->location = @1;
12028 : }
12029 : | DEFAULT b_expr
12030 : {
12031 1 : $$ = makeNode(ResTarget);
12032 1 : $$->name = NULL;
12033 1 : $$->indirection = NIL;
12034 1 : $$->val = $2;
12035 1 : $$->location = @1;
12036 : }
12037 : ;
12038 :
12039 : /*****************************************************************************
12040 : *
12041 : * Type syntax
12042 : * SQL introduces a large amount of type-specific syntax.
12043 : * Define individual clauses to handle these cases, and use
12044 : * the generic case to handle regular type-extensible Postgres syntax.
12045 : * - thomas 1997-10-10
12046 : *
12047 : *****************************************************************************/
12048 :
12049 : Typename: SimpleTypename opt_array_bounds
12050 : {
12051 15160 : $$ = $1;
12052 15160 : $$->arrayBounds = $2;
12053 : }
12054 : | SETOF SimpleTypename opt_array_bounds
12055 : {
12056 63 : $$ = $2;
12057 63 : $$->arrayBounds = $3;
12058 63 : $$->setof = TRUE;
12059 : }
12060 : /* SQL standard syntax, currently only one-dimensional */
12061 : | SimpleTypename ARRAY '[' Iconst ']'
12062 : {
12063 1 : $$ = $1;
12064 1 : $$->arrayBounds = list_make1(makeInteger($4));
12065 : }
12066 : | SETOF SimpleTypename ARRAY '[' Iconst ']'
12067 : {
12068 0 : $$ = $2;
12069 0 : $$->arrayBounds = list_make1(makeInteger($5));
12070 0 : $$->setof = TRUE;
12071 : }
12072 : | SimpleTypename ARRAY
12073 : {
12074 0 : $$ = $1;
12075 0 : $$->arrayBounds = list_make1(makeInteger(-1));
12076 : }
12077 : | SETOF SimpleTypename ARRAY
12078 : {
12079 0 : $$ = $2;
12080 0 : $$->arrayBounds = list_make1(makeInteger(-1));
12081 0 : $$->setof = TRUE;
12082 : }
12083 : ;
12084 :
12085 : opt_array_bounds:
12086 : opt_array_bounds '[' ']'
12087 383 : { $$ = lappend($1, makeInteger(-1)); }
12088 : | opt_array_bounds '[' Iconst ']'
12089 7 : { $$ = lappend($1, makeInteger($3)); }
12090 : | /*EMPTY*/
12091 15223 : { $$ = NIL; }
12092 : ;
12093 :
12094 : SimpleTypename:
12095 10876 : GenericType { $$ = $1; }
12096 3719 : | Numeric { $$ = $1; }
12097 222 : | Bit { $$ = $1; }
12098 206 : | Character { $$ = $1; }
12099 177 : | ConstDatetime { $$ = $1; }
12100 : | ConstInterval opt_interval
12101 : {
12102 53 : $$ = $1;
12103 53 : $$->typmods = $2;
12104 : }
12105 : | ConstInterval '(' Iconst ')'
12106 : {
12107 0 : $$ = $1;
12108 0 : $$->typmods = list_make2(makeIntConst(INTERVAL_FULL_RANGE, -1),
12109 : makeIntConst($3, @3));
12110 : }
12111 : ;
12112 :
12113 : /* We have a separate ConstTypename to allow defaulting fixed-length
12114 : * types such as CHAR() and BIT() to an unspecified length.
12115 : * SQL9x requires that these default to a length of one, but this
12116 : * makes no sense for constructs like CHAR 'hi' and BIT '0101',
12117 : * where there is an obvious better choice to make.
12118 : * Note that ConstInterval is not included here since it must
12119 : * be pushed up higher in the rules to accommodate the postfix
12120 : * options (e.g. INTERVAL '1' YEAR). Likewise, we have to handle
12121 : * the generic-type-name case in AExprConst to avoid premature
12122 : * reduce/reduce conflicts against function names.
12123 : */
12124 : ConstTypename:
12125 4 : Numeric { $$ = $1; }
12126 0 : | ConstBit { $$ = $1; }
12127 5 : | ConstCharacter { $$ = $1; }
12128 209 : | ConstDatetime { $$ = $1; }
12129 : ;
12130 :
12131 : /*
12132 : * GenericType covers all type names that don't have special syntax mandated
12133 : * by the standard, including qualified names. We also allow type modifiers.
12134 : * To avoid parsing conflicts against function invocations, the modifiers
12135 : * have to be shown as expr_list here, but parse analysis will only accept
12136 : * constants for them.
12137 : */
12138 : GenericType:
12139 : type_function_name opt_type_modifiers
12140 : {
12141 8600 : $$ = makeTypeName($1);
12142 8600 : $$->typmods = $2;
12143 8600 : $$->location = @1;
12144 : }
12145 : | type_function_name attrs opt_type_modifiers
12146 : {
12147 2276 : $$ = makeTypeNameFromNameList(lcons(makeString($1), $2));
12148 2276 : $$->typmods = $3;
12149 2276 : $$->location = @1;
12150 : }
12151 : ;
12152 :
12153 60 : opt_type_modifiers: '(' expr_list ')' { $$ = $2; }
12154 11073 : | /* EMPTY */ { $$ = NIL; }
12155 : ;
12156 :
12157 : /*
12158 : * SQL numeric data types
12159 : */
12160 : Numeric: INT_P
12161 : {
12162 1970 : $$ = SystemTypeName("int4");
12163 1970 : $$->location = @1;
12164 : }
12165 : | INTEGER
12166 : {
12167 1175 : $$ = SystemTypeName("int4");
12168 1175 : $$->location = @1;
12169 : }
12170 : | SMALLINT
12171 : {
12172 43 : $$ = SystemTypeName("int2");
12173 43 : $$->location = @1;
12174 : }
12175 : | BIGINT
12176 : {
12177 106 : $$ = SystemTypeName("int8");
12178 106 : $$->location = @1;
12179 : }
12180 : | REAL
12181 : {
12182 4 : $$ = SystemTypeName("float4");
12183 4 : $$->location = @1;
12184 : }
12185 : | FLOAT_P opt_float
12186 : {
12187 41 : $$ = $2;
12188 41 : $$->location = @1;
12189 : }
12190 : | DOUBLE_P PRECISION
12191 : {
12192 9 : $$ = SystemTypeName("float8");
12193 9 : $$->location = @1;
12194 : }
12195 : | DECIMAL_P opt_type_modifiers
12196 : {
12197 2 : $$ = SystemTypeName("numeric");
12198 2 : $$->typmods = $2;
12199 2 : $$->location = @1;
12200 : }
12201 : | DEC opt_type_modifiers
12202 : {
12203 0 : $$ = SystemTypeName("numeric");
12204 0 : $$->typmods = $2;
12205 0 : $$->location = @1;
12206 : }
12207 : | NUMERIC opt_type_modifiers
12208 : {
12209 255 : $$ = SystemTypeName("numeric");
12210 255 : $$->typmods = $2;
12211 255 : $$->location = @1;
12212 : }
12213 : | BOOLEAN_P
12214 : {
12215 118 : $$ = SystemTypeName("bool");
12216 118 : $$->location = @1;
12217 : }
12218 : ;
12219 :
12220 : opt_float: '(' Iconst ')'
12221 : {
12222 : /*
12223 : * Check FLOAT() precision limits assuming IEEE floating
12224 : * types - thomas 1997-09-18
12225 : */
12226 0 : if ($2 < 1)
12227 0 : ereport(ERROR,
12228 : (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
12229 : errmsg("precision for type float must be at least 1 bit"),
12230 : parser_errposition(@2)));
12231 0 : else if ($2 <= 24)
12232 0 : $$ = SystemTypeName("float4");
12233 0 : else if ($2 <= 53)
12234 0 : $$ = SystemTypeName("float8");
12235 : else
12236 0 : ereport(ERROR,
12237 : (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
12238 : errmsg("precision for type float must be less than 54 bits"),
12239 : parser_errposition(@2)));
12240 : }
12241 : | /*EMPTY*/
12242 : {
12243 41 : $$ = SystemTypeName("float8");
12244 : }
12245 : ;
12246 :
12247 : /*
12248 : * SQL bit-field data types
12249 : * The following implements BIT() and BIT VARYING().
12250 : */
12251 : Bit: BitWithLength
12252 : {
12253 222 : $$ = $1;
12254 : }
12255 : | BitWithoutLength
12256 : {
12257 0 : $$ = $1;
12258 : }
12259 : ;
12260 :
12261 : /* ConstBit is like Bit except "BIT" defaults to unspecified length */
12262 : /* See notes for ConstCharacter, which addresses same issue for "CHAR" */
12263 : ConstBit: BitWithLength
12264 : {
12265 0 : $$ = $1;
12266 : }
12267 : | BitWithoutLength
12268 : {
12269 0 : $$ = $1;
12270 0 : $$->typmods = NIL;
12271 : }
12272 : ;
12273 :
12274 : BitWithLength:
12275 : BIT opt_varying '(' expr_list ')'
12276 : {
12277 : char *typname;
12278 :
12279 222 : typname = $2 ? "varbit" : "bit";
12280 222 : $$ = SystemTypeName(typname);
12281 222 : $$->typmods = $4;
12282 222 : $$->location = @1;
12283 : }
12284 : ;
12285 :
12286 : BitWithoutLength:
12287 : BIT opt_varying
12288 : {
12289 : /* bit defaults to bit(1), varbit to no limit */
12290 0 : if ($2)
12291 : {
12292 0 : $$ = SystemTypeName("varbit");
12293 : }
12294 : else
12295 : {
12296 0 : $$ = SystemTypeName("bit");
12297 0 : $$->typmods = list_make1(makeIntConst(1, -1));
12298 : }
12299 0 : $$->location = @1;
12300 : }
12301 : ;
12302 :
12303 :
12304 : /*
12305 : * SQL character data types
12306 : * The following implements CHAR() and VARCHAR().
12307 : */
12308 : Character: CharacterWithLength
12309 : {
12310 128 : $$ = $1;
12311 : }
12312 : | CharacterWithoutLength
12313 : {
12314 78 : $$ = $1;
12315 : }
12316 : ;
12317 :
12318 : ConstCharacter: CharacterWithLength
12319 : {
12320 2 : $$ = $1;
12321 : }
12322 : | CharacterWithoutLength
12323 : {
12324 : /* Length was not specified so allow to be unrestricted.
12325 : * This handles problems with fixed-length (bpchar) strings
12326 : * which in column definitions must default to a length
12327 : * of one, but should not be constrained if the length
12328 : * was not specified.
12329 : */
12330 3 : $$ = $1;
12331 3 : $$->typmods = NIL;
12332 : }
12333 : ;
12334 :
12335 : CharacterWithLength: character '(' Iconst ')'
12336 : {
12337 130 : $$ = SystemTypeName($1);
12338 130 : $$->typmods = list_make1(makeIntConst($3, @3));
12339 130 : $$->location = @1;
12340 : }
12341 : ;
12342 :
12343 : CharacterWithoutLength: character
12344 : {
12345 81 : $$ = SystemTypeName($1);
12346 : /* char defaults to char(1), varchar to no limit */
12347 81 : if (strcmp($1, "bpchar") == 0)
12348 22 : $$->typmods = list_make1(makeIntConst(1, -1));
12349 81 : $$->location = @1;
12350 : }
12351 : ;
12352 :
12353 : character: CHARACTER opt_varying
12354 6 : { $$ = $2 ? "varchar": "bpchar"; }
12355 : | CHAR_P opt_varying
12356 113 : { $$ = $2 ? "varchar": "bpchar"; }
12357 : | VARCHAR
12358 92 : { $$ = "varchar"; }
12359 : | NATIONAL CHARACTER opt_varying
12360 0 : { $$ = $3 ? "varchar": "bpchar"; }
12361 : | NATIONAL CHAR_P opt_varying
12362 0 : { $$ = $3 ? "varchar": "bpchar"; }
12363 : | NCHAR opt_varying
12364 0 : { $$ = $2 ? "varchar": "bpchar"; }
12365 : ;
12366 :
12367 : opt_varying:
12368 13 : VARYING { $$ = TRUE; }
12369 328 : | /*EMPTY*/ { $$ = FALSE; }
12370 : ;
12371 :
12372 : /*
12373 : * SQL date/time types
12374 : */
12375 : ConstDatetime:
12376 : TIMESTAMP '(' Iconst ')' opt_timezone
12377 : {
12378 7 : if ($5)
12379 4 : $$ = SystemTypeName("timestamptz");
12380 : else
12381 3 : $$ = SystemTypeName("timestamp");
12382 7 : $$->typmods = list_make1(makeIntConst($3, @3));
12383 7 : $$->location = @1;
12384 : }
12385 : | TIMESTAMP opt_timezone
12386 : {
12387 300 : if ($2)
12388 91 : $$ = SystemTypeName("timestamptz");
12389 : else
12390 209 : $$ = SystemTypeName("timestamp");
12391 300 : $$->location = @1;
12392 : }
12393 : | TIME '(' Iconst ')' opt_timezone
12394 : {
12395 2 : if ($5)
12396 1 : $$ = SystemTypeName("timetz");
12397 : else
12398 1 : $$ = SystemTypeName("time");
12399 2 : $$->typmods = list_make1(makeIntConst($3, @3));
12400 2 : $$->location = @1;
12401 : }
12402 : | TIME opt_timezone
12403 : {
12404 77 : if ($2)
12405 22 : $$ = SystemTypeName("timetz");
12406 : else
12407 55 : $$ = SystemTypeName("time");
12408 77 : $$->location = @1;
12409 : }
12410 : ;
12411 :
12412 : ConstInterval:
12413 : INTERVAL
12414 : {
12415 246 : $$ = SystemTypeName("interval");
12416 246 : $$->location = @1;
12417 : }
12418 : ;
12419 :
12420 : opt_timezone:
12421 118 : WITH_LA TIME ZONE { $$ = TRUE; }
12422 128 : | WITHOUT TIME ZONE { $$ = FALSE; }
12423 140 : | /*EMPTY*/ { $$ = FALSE; }
12424 : ;
12425 :
12426 : opt_interval:
12427 : YEAR_P
12428 2 : { $$ = list_make1(makeIntConst(INTERVAL_MASK(YEAR), @1)); }
12429 : | MONTH_P
12430 3 : { $$ = list_make1(makeIntConst(INTERVAL_MASK(MONTH), @1)); }
12431 : | DAY_P
12432 3 : { $$ = list_make1(makeIntConst(INTERVAL_MASK(DAY), @1)); }
12433 : | HOUR_P
12434 2 : { $$ = list_make1(makeIntConst(INTERVAL_MASK(HOUR), @1)); }
12435 : | MINUTE_P
12436 2 : { $$ = list_make1(makeIntConst(INTERVAL_MASK(MINUTE), @1)); }
12437 : | interval_second
12438 4 : { $$ = $1; }
12439 : | YEAR_P TO MONTH_P
12440 : {
12441 3 : $$ = list_make1(makeIntConst(INTERVAL_MASK(YEAR) |
12442 : INTERVAL_MASK(MONTH), @1));
12443 : }
12444 : | DAY_P TO HOUR_P
12445 : {
12446 4 : $$ = list_make1(makeIntConst(INTERVAL_MASK(DAY) |
12447 : INTERVAL_MASK(HOUR), @1));
12448 : }
12449 : | DAY_P TO MINUTE_P
12450 : {
12451 4 : $$ = list_make1(makeIntConst(INTERVAL_MASK(DAY) |
12452 : INTERVAL_MASK(HOUR) |
12453 : INTERVAL_MASK(MINUTE), @1));
12454 : }
12455 : | DAY_P TO interval_second
12456 : {
12457 8 : $$ = $3;
12458 16 : linitial($$) = makeIntConst(INTERVAL_MASK(DAY) |
12459 : INTERVAL_MASK(HOUR) |
12460 : INTERVAL_MASK(MINUTE) |
12461 8 : INTERVAL_MASK(SECOND), @1);
12462 : }
12463 : | HOUR_P TO MINUTE_P
12464 : {
12465 3 : $$ = list_make1(makeIntConst(INTERVAL_MASK(HOUR) |
12466 : INTERVAL_MASK(MINUTE), @1));
12467 : }
12468 : | HOUR_P TO interval_second
12469 : {
12470 6 : $$ = $3;
12471 12 : linitial($$) = makeIntConst(INTERVAL_MASK(HOUR) |
12472 : INTERVAL_MASK(MINUTE) |
12473 6 : INTERVAL_MASK(SECOND), @1);
12474 : }
12475 : | MINUTE_P TO interval_second
12476 : {
12477 11 : $$ = $3;
12478 22 : linitial($$) = makeIntConst(INTERVAL_MASK(MINUTE) |
12479 11 : INTERVAL_MASK(SECOND), @1);
12480 : }
12481 : | /*EMPTY*/
12482 189 : { $$ = NIL; }
12483 : ;
12484 :
12485 : interval_second:
12486 : SECOND_P
12487 : {
12488 17 : $$ = list_make1(makeIntConst(INTERVAL_MASK(SECOND), @1));
12489 : }
12490 : | SECOND_P '(' Iconst ')'
12491 : {
12492 12 : $$ = list_make2(makeIntConst(INTERVAL_MASK(SECOND), @1),
12493 : makeIntConst($3, @3));
12494 : }
12495 : ;
12496 :
12497 :
12498 : /*****************************************************************************
12499 : *
12500 : * expression grammar
12501 : *
12502 : *****************************************************************************/
12503 :
12504 : /*
12505 : * General expressions
12506 : * This is the heart of the expression syntax.
12507 : *
12508 : * We have two expression types: a_expr is the unrestricted kind, and
12509 : * b_expr is a subset that must be used in some places to avoid shift/reduce
12510 : * conflicts. For example, we can't do BETWEEN as "BETWEEN a_expr AND a_expr"
12511 : * because that use of AND conflicts with AND as a boolean operator. So,
12512 : * b_expr is used in BETWEEN and we remove boolean keywords from b_expr.
12513 : *
12514 : * Note that '(' a_expr ')' is a b_expr, so an unrestricted expression can
12515 : * always be used by surrounding it with parens.
12516 : *
12517 : * c_expr is all the productions that are common to a_expr and b_expr;
12518 : * it's factored out just to eliminate redundant coding.
12519 : *
12520 : * Be careful of productions involving more than one terminal token.
12521 : * By default, bison will assign such productions the precedence of their
12522 : * last terminal, but in nearly all cases you want it to be the precedence
12523 : * of the first terminal instead; otherwise you will not get the behavior
12524 : * you expect! So we use %prec annotations freely to set precedences.
12525 : */
12526 120508 : a_expr: c_expr { $$ = $1; }
12527 : | a_expr TYPECAST Typename
12528 7222 : { $$ = makeTypeCast($1, $3, @2); }
12529 : | a_expr COLLATE any_name
12530 : {
12531 40 : CollateClause *n = makeNode(CollateClause);
12532 40 : n->arg = $1;
12533 40 : n->collname = $3;
12534 40 : n->location = @2;
12535 40 : $$ = (Node *) n;
12536 : }
12537 : | a_expr AT TIME ZONE a_expr %prec AT
12538 : {
12539 180 : $$ = (Node *) makeFuncCall(SystemFuncName("timezone"),
12540 120 : list_make2($5, $1),
12541 60 : @2);
12542 : }
12543 : /*
12544 : * These operators must be called out explicitly in order to make use
12545 : * of bison's automatic operator-precedence handling. All other
12546 : * operator names are handled by the generic productions using "Op",
12547 : * below; and all those operators will have the same precedence.
12548 : *
12549 : * If you add more explicitly-known operators, be sure to add them
12550 : * also to b_expr and to the MathOp list below.
12551 : */
12552 : | '+' a_expr %prec UMINUS
12553 1 : { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "+", NULL, $2, @1); }
12554 : | '-' a_expr %prec UMINUS
12555 578 : { $$ = doNegate($2, @1); }
12556 : | a_expr '+' a_expr
12557 704 : { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "+", $1, $3, @2); }
12558 : | a_expr '-' a_expr
12559 222 : { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "-", $1, $3, @2); }
12560 : | a_expr '*' a_expr
12561 226 : { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "*", $1, $3, @2); }
12562 : | a_expr '/' a_expr
12563 201 : { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "/", $1, $3, @2); }
12564 : | a_expr '%' a_expr
12565 67 : { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "%", $1, $3, @2); }
12566 : | a_expr '^' a_expr
12567 38 : { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "^", $1, $3, @2); }
12568 : | a_expr '<' a_expr
12569 586 : { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "<", $1, $3, @2); }
12570 : | a_expr '>' a_expr
12571 861 : { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, ">", $1, $3, @2); }
12572 : | a_expr '=' a_expr
12573 10469 : { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "=", $1, $3, @2); }
12574 : | a_expr LESS_EQUALS a_expr
12575 244 : { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "<=", $1, $3, @2); }
12576 : | a_expr GREATER_EQUALS a_expr
12577 297 : { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, ">=", $1, $3, @2); }
12578 : | a_expr NOT_EQUALS a_expr
12579 1138 : { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "<>", $1, $3, @2); }
12580 :
12581 : | a_expr qual_Op a_expr %prec Op
12582 3433 : { $$ = (Node *) makeA_Expr(AEXPR_OP, $2, $1, $3, @2); }
12583 : | qual_Op a_expr %prec Op
12584 27 : { $$ = (Node *) makeA_Expr(AEXPR_OP, $1, NULL, $2, @1); }
12585 : | a_expr qual_Op %prec POSTFIXOP
12586 1 : { $$ = (Node *) makeA_Expr(AEXPR_OP, $2, $1, NULL, @2); }
12587 :
12588 : | a_expr AND a_expr
12589 5739 : { $$ = makeAndExpr($1, $3, @2); }
12590 : | a_expr OR a_expr
12591 436 : { $$ = makeOrExpr($1, $3, @2); }
12592 : | NOT a_expr
12593 896 : { $$ = makeNotExpr($2, @1); }
12594 : | NOT_LA a_expr %prec NOT
12595 0 : { $$ = makeNotExpr($2, @1); }
12596 :
12597 : | a_expr LIKE a_expr
12598 : {
12599 266 : $$ = (Node *) makeSimpleA_Expr(AEXPR_LIKE, "~~",
12600 266 : $1, $3, @2);
12601 : }
12602 : | a_expr LIKE a_expr ESCAPE a_expr %prec LIKE
12603 : {
12604 45 : FuncCall *n = makeFuncCall(SystemFuncName("like_escape"),
12605 30 : list_make2($3, $5),
12606 15 : @2);
12607 30 : $$ = (Node *) makeSimpleA_Expr(AEXPR_LIKE, "~~",
12608 30 : $1, (Node *) n, @2);
12609 : }
12610 : | a_expr NOT_LA LIKE a_expr %prec NOT_LA
12611 : {
12612 34 : $$ = (Node *) makeSimpleA_Expr(AEXPR_LIKE, "!~~",
12613 34 : $1, $4, @2);
12614 : }
12615 : | a_expr NOT_LA LIKE a_expr ESCAPE a_expr %prec NOT_LA
12616 : {
12617 45 : FuncCall *n = makeFuncCall(SystemFuncName("like_escape"),
12618 30 : list_make2($4, $6),
12619 15 : @2);
12620 30 : $$ = (Node *) makeSimpleA_Expr(AEXPR_LIKE, "!~~",
12621 30 : $1, (Node *) n, @2);
12622 : }
12623 : | a_expr ILIKE a_expr
12624 : {
12625 8 : $$ = (Node *) makeSimpleA_Expr(AEXPR_ILIKE, "~~*",
12626 8 : $1, $3, @2);
12627 : }
12628 : | a_expr ILIKE a_expr ESCAPE a_expr %prec ILIKE
12629 : {
12630 0 : FuncCall *n = makeFuncCall(SystemFuncName("like_escape"),
12631 0 : list_make2($3, $5),
12632 0 : @2);
12633 0 : $$ = (Node *) makeSimpleA_Expr(AEXPR_ILIKE, "~~*",
12634 0 : $1, (Node *) n, @2);
12635 : }
12636 : | a_expr NOT_LA ILIKE a_expr %prec NOT_LA
12637 : {
12638 8 : $$ = (Node *) makeSimpleA_Expr(AEXPR_ILIKE, "!~~*",
12639 8 : $1, $4, @2);
12640 : }
12641 : | a_expr NOT_LA ILIKE a_expr ESCAPE a_expr %prec NOT_LA
12642 : {
12643 0 : FuncCall *n = makeFuncCall(SystemFuncName("like_escape"),
12644 0 : list_make2($4, $6),
12645 0 : @2);
12646 0 : $$ = (Node *) makeSimpleA_Expr(AEXPR_ILIKE, "!~~*",
12647 0 : $1, (Node *) n, @2);
12648 : }
12649 :
12650 : | a_expr SIMILAR TO a_expr %prec SIMILAR
12651 : {
12652 0 : FuncCall *n = makeFuncCall(SystemFuncName("similar_escape"),
12653 0 : list_make2($4, makeNullAConst(-1)),
12654 0 : @2);
12655 0 : $$ = (Node *) makeSimpleA_Expr(AEXPR_SIMILAR, "~",
12656 0 : $1, (Node *) n, @2);
12657 : }
12658 : | a_expr SIMILAR TO a_expr ESCAPE a_expr %prec SIMILAR
12659 : {
12660 0 : FuncCall *n = makeFuncCall(SystemFuncName("similar_escape"),
12661 0 : list_make2($4, $6),
12662 0 : @2);
12663 0 : $$ = (Node *) makeSimpleA_Expr(AEXPR_SIMILAR, "~",
12664 0 : $1, (Node *) n, @2);
12665 : }
12666 : | a_expr NOT_LA SIMILAR TO a_expr %prec NOT_LA
12667 : {
12668 0 : FuncCall *n = makeFuncCall(SystemFuncName("similar_escape"),
12669 0 : list_make2($5, makeNullAConst(-1)),
12670 0 : @2);
12671 0 : $$ = (Node *) makeSimpleA_Expr(AEXPR_SIMILAR, "!~",
12672 0 : $1, (Node *) n, @2);
12673 : }
12674 : | a_expr NOT_LA SIMILAR TO a_expr ESCAPE a_expr %prec NOT_LA
12675 : {
12676 0 : FuncCall *n = makeFuncCall(SystemFuncName("similar_escape"),
12677 0 : list_make2($5, $7),
12678 0 : @2);
12679 0 : $$ = (Node *) makeSimpleA_Expr(AEXPR_SIMILAR, "!~",
12680 0 : $1, (Node *) n, @2);
12681 : }
12682 :
12683 : /* NullTest clause
12684 : * Define SQL-style Null test clause.
12685 : * Allow two forms described in the standard:
12686 : * a IS NULL
12687 : * a IS NOT NULL
12688 : * Allow two SQL extensions
12689 : * a ISNULL
12690 : * a NOTNULL
12691 : */
12692 : | a_expr IS NULL_P %prec IS
12693 : {
12694 263 : NullTest *n = makeNode(NullTest);
12695 263 : n->arg = (Expr *) $1;
12696 263 : n->nulltesttype = IS_NULL;
12697 263 : n->location = @2;
12698 263 : $$ = (Node *)n;
12699 : }
12700 : | a_expr ISNULL
12701 : {
12702 16 : NullTest *n = makeNode(NullTest);
12703 16 : n->arg = (Expr *) $1;
12704 16 : n->nulltesttype = IS_NULL;
12705 16 : n->location = @2;
12706 16 : $$ = (Node *)n;
12707 : }
12708 : | a_expr IS NOT NULL_P %prec IS
12709 : {
12710 198 : NullTest *n = makeNode(NullTest);
12711 198 : n->arg = (Expr *) $1;
12712 198 : n->nulltesttype = IS_NOT_NULL;
12713 198 : n->location = @2;
12714 198 : $$ = (Node *)n;
12715 : }
12716 : | a_expr NOTNULL
12717 : {
12718 1 : NullTest *n = makeNode(NullTest);
12719 1 : n->arg = (Expr *) $1;
12720 1 : n->nulltesttype = IS_NOT_NULL;
12721 1 : n->location = @2;
12722 1 : $$ = (Node *)n;
12723 : }
12724 : | row OVERLAPS row
12725 : {
12726 27 : if (list_length($1) != 2)
12727 0 : ereport(ERROR,
12728 : (errcode(ERRCODE_SYNTAX_ERROR),
12729 : errmsg("wrong number of parameters on left side of OVERLAPS expression"),
12730 : parser_errposition(@1)));
12731 27 : if (list_length($3) != 2)
12732 0 : ereport(ERROR,
12733 : (errcode(ERRCODE_SYNTAX_ERROR),
12734 : errmsg("wrong number of parameters on right side of OVERLAPS expression"),
12735 : parser_errposition(@3)));
12736 54 : $$ = (Node *) makeFuncCall(SystemFuncName("overlaps"),
12737 27 : list_concat($1, $3),
12738 27 : @2);
12739 : }
12740 : | a_expr IS TRUE_P %prec IS
12741 : {
12742 4 : BooleanTest *b = makeNode(BooleanTest);
12743 4 : b->arg = (Expr *) $1;
12744 4 : b->booltesttype = IS_TRUE;
12745 4 : b->location = @2;
12746 4 : $$ = (Node *)b;
12747 : }
12748 : | a_expr IS NOT TRUE_P %prec IS
12749 : {
12750 4 : BooleanTest *b = makeNode(BooleanTest);
12751 4 : b->arg = (Expr *) $1;
12752 4 : b->booltesttype = IS_NOT_TRUE;
12753 4 : b->location = @2;
12754 4 : $$ = (Node *)b;
12755 : }
12756 : | a_expr IS FALSE_P %prec IS
12757 : {
12758 4 : BooleanTest *b = makeNode(BooleanTest);
12759 4 : b->arg = (Expr *) $1;
12760 4 : b->booltesttype = IS_FALSE;
12761 4 : b->location = @2;
12762 4 : $$ = (Node *)b;
12763 : }
12764 : | a_expr IS NOT FALSE_P %prec IS
12765 : {
12766 4 : BooleanTest *b = makeNode(BooleanTest);
12767 4 : b->arg = (Expr *) $1;
12768 4 : b->booltesttype = IS_NOT_FALSE;
12769 4 : b->location = @2;
12770 4 : $$ = (Node *)b;
12771 : }
12772 : | a_expr IS UNKNOWN %prec IS
12773 : {
12774 1 : BooleanTest *b = makeNode(BooleanTest);
12775 1 : b->arg = (Expr *) $1;
12776 1 : b->booltesttype = IS_UNKNOWN;
12777 1 : b->location = @2;
12778 1 : $$ = (Node *)b;
12779 : }
12780 : | a_expr IS NOT UNKNOWN %prec IS
12781 : {
12782 1 : BooleanTest *b = makeNode(BooleanTest);
12783 1 : b->arg = (Expr *) $1;
12784 1 : b->booltesttype = IS_NOT_UNKNOWN;
12785 1 : b->location = @2;
12786 1 : $$ = (Node *)b;
12787 : }
12788 : | a_expr IS DISTINCT FROM a_expr %prec IS
12789 : {
12790 31 : $$ = (Node *) makeSimpleA_Expr(AEXPR_DISTINCT, "=", $1, $5, @2);
12791 : }
12792 : | a_expr IS NOT DISTINCT FROM a_expr %prec IS
12793 : {
12794 8 : $$ = (Node *) makeSimpleA_Expr(AEXPR_NOT_DISTINCT, "=", $1, $6, @2);
12795 : }
12796 : | a_expr IS OF '(' type_list ')' %prec IS
12797 : {
12798 8 : $$ = (Node *) makeSimpleA_Expr(AEXPR_OF, "=", $1, (Node *) $5, @2);
12799 : }
12800 : | a_expr IS NOT OF '(' type_list ')' %prec IS
12801 : {
12802 0 : $$ = (Node *) makeSimpleA_Expr(AEXPR_OF, "<>", $1, (Node *) $6, @2);
12803 : }
12804 : | a_expr BETWEEN opt_asymmetric b_expr AND a_expr %prec BETWEEN
12805 : {
12806 80 : $$ = (Node *) makeSimpleA_Expr(AEXPR_BETWEEN,
12807 : "BETWEEN",
12808 40 : $1,
12809 40 : (Node *) list_make2($4, $6),
12810 40 : @2);
12811 : }
12812 : | a_expr NOT_LA BETWEEN opt_asymmetric b_expr AND a_expr %prec NOT_LA
12813 : {
12814 2 : $$ = (Node *) makeSimpleA_Expr(AEXPR_NOT_BETWEEN,
12815 : "NOT BETWEEN",
12816 1 : $1,
12817 1 : (Node *) list_make2($5, $7),
12818 1 : @2);
12819 : }
12820 : | a_expr BETWEEN SYMMETRIC b_expr AND a_expr %prec BETWEEN
12821 : {
12822 0 : $$ = (Node *) makeSimpleA_Expr(AEXPR_BETWEEN_SYM,
12823 : "BETWEEN SYMMETRIC",
12824 0 : $1,
12825 0 : (Node *) list_make2($4, $6),
12826 0 : @2);
12827 : }
12828 : | a_expr NOT_LA BETWEEN SYMMETRIC b_expr AND a_expr %prec NOT_LA
12829 : {
12830 0 : $$ = (Node *) makeSimpleA_Expr(AEXPR_NOT_BETWEEN_SYM,
12831 : "NOT BETWEEN SYMMETRIC",
12832 0 : $1,
12833 0 : (Node *) list_make2($5, $7),
12834 0 : @2);
12835 : }
12836 : | a_expr IN_P in_expr
12837 : {
12838 : /* in_expr returns a SubLink or a list of a_exprs */
12839 345 : if (IsA($3, SubLink))
12840 : {
12841 : /* generate foo = ANY (subquery) */
12842 79 : SubLink *n = (SubLink *) $3;
12843 79 : n->subLinkType = ANY_SUBLINK;
12844 79 : n->subLinkId = 0;
12845 79 : n->testexpr = $1;
12846 79 : n->operName = NIL; /* show it's IN not = ANY */
12847 79 : n->location = @2;
12848 79 : $$ = (Node *)n;
12849 : }
12850 : else
12851 : {
12852 : /* generate scalar IN expression */
12853 266 : $$ = (Node *) makeSimpleA_Expr(AEXPR_IN, "=", $1, $3, @2);
12854 : }
12855 : }
12856 : | a_expr NOT_LA IN_P in_expr %prec NOT_LA
12857 : {
12858 : /* in_expr returns a SubLink or a list of a_exprs */
12859 40 : if (IsA($4, SubLink))
12860 : {
12861 : /* generate NOT (foo = ANY (subquery)) */
12862 : /* Make an = ANY node */
12863 7 : SubLink *n = (SubLink *) $4;
12864 7 : n->subLinkType = ANY_SUBLINK;
12865 7 : n->subLinkId = 0;
12866 7 : n->testexpr = $1;
12867 7 : n->operName = NIL; /* show it's IN not = ANY */
12868 7 : n->location = @2;
12869 : /* Stick a NOT on top; must have same parse location */
12870 7 : $$ = makeNotExpr((Node *) n, @2);
12871 : }
12872 : else
12873 : {
12874 : /* generate scalar NOT IN expression */
12875 33 : $$ = (Node *) makeSimpleA_Expr(AEXPR_IN, "<>", $1, $4, @2);
12876 : }
12877 : }
12878 : | a_expr subquery_Op sub_type select_with_parens %prec Op
12879 : {
12880 15 : SubLink *n = makeNode(SubLink);
12881 15 : n->subLinkType = $3;
12882 15 : n->subLinkId = 0;
12883 15 : n->testexpr = $1;
12884 15 : n->operName = $2;
12885 15 : n->subselect = $4;
12886 15 : n->location = @2;
12887 15 : $$ = (Node *)n;
12888 : }
12889 : | a_expr subquery_Op sub_type '(' a_expr ')' %prec Op
12890 : {
12891 241 : if ($3 == ANY_SUBLINK)
12892 225 : $$ = (Node *) makeA_Expr(AEXPR_OP_ANY, $2, $1, $5, @2);
12893 : else
12894 16 : $$ = (Node *) makeA_Expr(AEXPR_OP_ALL, $2, $1, $5, @2);
12895 : }
12896 : | UNIQUE select_with_parens
12897 : {
12898 : /* Not sure how to get rid of the parentheses
12899 : * but there are lots of shift/reduce errors without them.
12900 : *
12901 : * Should be able to implement this by plopping the entire
12902 : * select into a node, then transforming the target expressions
12903 : * from whatever they are into count(*), and testing the
12904 : * entire result equal to one.
12905 : * But, will probably implement a separate node in the executor.
12906 : */
12907 0 : ereport(ERROR,
12908 : (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
12909 : errmsg("UNIQUE predicate is not yet implemented"),
12910 : parser_errposition(@1)));
12911 : }
12912 : | a_expr IS DOCUMENT_P %prec IS
12913 : {
12914 4 : $$ = makeXmlExpr(IS_DOCUMENT, NULL, NIL,
12915 4 : list_make1($1), @2);
12916 : }
12917 : | a_expr IS NOT DOCUMENT_P %prec IS
12918 : {
12919 9 : $$ = makeNotExpr(makeXmlExpr(IS_DOCUMENT, NULL, NIL,
12920 6 : list_make1($1), @2),
12921 3 : @2);
12922 : }
12923 : | DEFAULT
12924 : {
12925 : /*
12926 : * The SQL spec only allows DEFAULT in "contextually typed
12927 : * expressions", but for us, it's easier to allow it in
12928 : * any a_expr and then throw error during parse analysis
12929 : * if it's in an inappropriate context. This way also
12930 : * lets us say something smarter than "syntax error".
12931 : */
12932 44 : SetToDefault *n = makeNode(SetToDefault);
12933 : /* parse analysis will fill in the rest */
12934 44 : n->location = @1;
12935 44 : $$ = (Node *)n;
12936 : }
12937 : ;
12938 :
12939 : /*
12940 : * Restricted expressions
12941 : *
12942 : * b_expr is a subset of the complete expression syntax defined by a_expr.
12943 : *
12944 : * Presently, AND, NOT, IS, and IN are the a_expr keywords that would
12945 : * cause trouble in the places where b_expr is used. For simplicity, we
12946 : * just eliminate all the boolean-keyword-operator productions from b_expr.
12947 : */
12948 : b_expr: c_expr
12949 313 : { $$ = $1; }
12950 : | b_expr TYPECAST Typename
12951 12 : { $$ = makeTypeCast($1, $3, @2); }
12952 : | '+' b_expr %prec UMINUS
12953 0 : { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "+", NULL, $2, @1); }
12954 : | '-' b_expr %prec UMINUS
12955 7 : { $$ = doNegate($2, @1); }
12956 : | b_expr '+' b_expr
12957 3 : { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "+", $1, $3, @2); }
12958 : | b_expr '-' b_expr
12959 2 : { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "-", $1, $3, @2); }
12960 : | b_expr '*' b_expr
12961 2 : { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "*", $1, $3, @2); }
12962 : | b_expr '/' b_expr
12963 0 : { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "/", $1, $3, @2); }
12964 : | b_expr '%' b_expr
12965 0 : { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "%", $1, $3, @2); }
12966 : | b_expr '^' b_expr
12967 0 : { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "^", $1, $3, @2); }
12968 : | b_expr '<' b_expr
12969 0 : { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "<", $1, $3, @2); }
12970 : | b_expr '>' b_expr
12971 0 : { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, ">", $1, $3, @2); }
12972 : | b_expr '=' b_expr
12973 0 : { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "=", $1, $3, @2); }
12974 : | b_expr LESS_EQUALS b_expr
12975 0 : { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "<=", $1, $3, @2); }
12976 : | b_expr GREATER_EQUALS b_expr
12977 0 : { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, ">=", $1, $3, @2); }
12978 : | b_expr NOT_EQUALS b_expr
12979 0 : { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "<>", $1, $3, @2); }
12980 : | b_expr qual_Op b_expr %prec Op
12981 2 : { $$ = (Node *) makeA_Expr(AEXPR_OP, $2, $1, $3, @2); }
12982 : | qual_Op b_expr %prec Op
12983 0 : { $$ = (Node *) makeA_Expr(AEXPR_OP, $1, NULL, $2, @1); }
12984 : | b_expr qual_Op %prec POSTFIXOP
12985 0 : { $$ = (Node *) makeA_Expr(AEXPR_OP, $2, $1, NULL, @2); }
12986 : | b_expr IS DISTINCT FROM b_expr %prec IS
12987 : {
12988 0 : $$ = (Node *) makeSimpleA_Expr(AEXPR_DISTINCT, "=", $1, $5, @2);
12989 : }
12990 : | b_expr IS NOT DISTINCT FROM b_expr %prec IS
12991 : {
12992 0 : $$ = (Node *) makeSimpleA_Expr(AEXPR_NOT_DISTINCT, "=", $1, $6, @2);
12993 : }
12994 : | b_expr IS OF '(' type_list ')' %prec IS
12995 : {
12996 0 : $$ = (Node *) makeSimpleA_Expr(AEXPR_OF, "=", $1, (Node *) $5, @2);
12997 : }
12998 : | b_expr IS NOT OF '(' type_list ')' %prec IS
12999 : {
13000 0 : $$ = (Node *) makeSimpleA_Expr(AEXPR_OF, "<>", $1, (Node *) $6, @2);
13001 : }
13002 : | b_expr IS DOCUMENT_P %prec IS
13003 : {
13004 0 : $$ = makeXmlExpr(IS_DOCUMENT, NULL, NIL,
13005 0 : list_make1($1), @2);
13006 : }
13007 : | b_expr IS NOT DOCUMENT_P %prec IS
13008 : {
13009 0 : $$ = makeNotExpr(makeXmlExpr(IS_DOCUMENT, NULL, NIL,
13010 0 : list_make1($1), @2),
13011 0 : @2);
13012 : }
13013 : ;
13014 :
13015 : /*
13016 : * Productions that can be used in both a_expr and b_expr.
13017 : *
13018 : * Note: productions that refer recursively to a_expr or b_expr mostly
13019 : * cannot appear here. However, it's OK to refer to a_exprs that occur
13020 : * inside parentheses, such as function arguments; that cannot introduce
13021 : * ambiguity to the b_expr syntax.
13022 : */
13023 51207 : c_expr: columnref { $$ = $1; }
13024 44755 : | AexprConst { $$ = $1; }
13025 : | PARAM opt_indirection
13026 : {
13027 2399 : ParamRef *p = makeNode(ParamRef);
13028 2399 : p->number = $1;
13029 2399 : p->location = @1;
13030 2399 : if ($2)
13031 : {
13032 86 : A_Indirection *n = makeNode(A_Indirection);
13033 86 : n->arg = (Node *) p;
13034 86 : n->indirection = check_indirection($2, yyscanner);
13035 86 : $$ = (Node *) n;
13036 : }
13037 : else
13038 2313 : $$ = (Node *) p;
13039 : }
13040 : | '(' a_expr ')' opt_indirection
13041 : {
13042 1884 : if ($4)
13043 : {
13044 90 : A_Indirection *n = makeNode(A_Indirection);
13045 90 : n->arg = $2;
13046 90 : n->indirection = check_indirection($4, yyscanner);
13047 90 : $$ = (Node *)n;
13048 : }
13049 1794 : else if (operator_precedence_warning)
13050 : {
13051 : /*
13052 : * If precedence warnings are enabled, insert
13053 : * AEXPR_PAREN nodes wrapping all explicitly
13054 : * parenthesized subexpressions; this prevents bogus
13055 : * warnings from being issued when the ordering has
13056 : * been forced by parentheses. Take care that an
13057 : * AEXPR_PAREN node has the same exprLocation as its
13058 : * child, so as not to cause surprising changes in
13059 : * error cursor positioning.
13060 : *
13061 : * In principle we should not be relying on a GUC to
13062 : * decide whether to insert AEXPR_PAREN nodes.
13063 : * However, since they have no effect except to
13064 : * suppress warnings, it's probably safe enough; and
13065 : * we'd just as soon not waste cycles on dummy parse
13066 : * nodes if we don't have to.
13067 : */
13068 0 : $$ = (Node *) makeA_Expr(AEXPR_PAREN, NIL, $2, NULL,
13069 0 : exprLocation($2));
13070 : }
13071 : else
13072 1794 : $$ = $2;
13073 : }
13074 : | case_expr
13075 1034 : { $$ = $1; }
13076 : | func_expr
13077 17045 : { $$ = $1; }
13078 : | select_with_parens %prec UMINUS
13079 : {
13080 957 : SubLink *n = makeNode(SubLink);
13081 957 : n->subLinkType = EXPR_SUBLINK;
13082 957 : n->subLinkId = 0;
13083 957 : n->testexpr = NULL;
13084 957 : n->operName = NIL;
13085 957 : n->subselect = $1;
13086 957 : n->location = @1;
13087 957 : $$ = (Node *)n;
13088 : }
13089 : | select_with_parens indirection
13090 : {
13091 : /*
13092 : * Because the select_with_parens nonterminal is designed
13093 : * to "eat" as many levels of parens as possible, the
13094 : * '(' a_expr ')' opt_indirection production above will
13095 : * fail to match a sub-SELECT with indirection decoration;
13096 : * the sub-SELECT won't be regarded as an a_expr as long
13097 : * as there are parens around it. To support applying
13098 : * subscripting or field selection to a sub-SELECT result,
13099 : * we need this redundant-looking production.
13100 : */
13101 3 : SubLink *n = makeNode(SubLink);
13102 3 : A_Indirection *a = makeNode(A_Indirection);
13103 3 : n->subLinkType = EXPR_SUBLINK;
13104 3 : n->subLinkId = 0;
13105 3 : n->testexpr = NULL;
13106 3 : n->operName = NIL;
13107 3 : n->subselect = $1;
13108 3 : n->location = @1;
13109 3 : a->arg = (Node *)n;
13110 3 : a->indirection = check_indirection($2, yyscanner);
13111 3 : $$ = (Node *)a;
13112 : }
13113 : | EXISTS select_with_parens
13114 : {
13115 283 : SubLink *n = makeNode(SubLink);
13116 283 : n->subLinkType = EXISTS_SUBLINK;
13117 283 : n->subLinkId = 0;
13118 283 : n->testexpr = NULL;
13119 283 : n->operName = NIL;
13120 283 : n->subselect = $2;
13121 283 : n->location = @1;
13122 283 : $$ = (Node *)n;
13123 : }
13124 : | ARRAY select_with_parens
13125 : {
13126 439 : SubLink *n = makeNode(SubLink);
13127 439 : n->subLinkType = ARRAY_SUBLINK;
13128 439 : n->subLinkId = 0;
13129 439 : n->testexpr = NULL;
13130 439 : n->operName = NIL;
13131 439 : n->subselect = $2;
13132 439 : n->location = @1;
13133 439 : $$ = (Node *)n;
13134 : }
13135 : | ARRAY array_expr
13136 : {
13137 495 : A_ArrayExpr *n = castNode(A_ArrayExpr, $2);
13138 : /* point outermost A_ArrayExpr to the ARRAY keyword */
13139 495 : n->location = @1;
13140 495 : $$ = (Node *)n;
13141 : }
13142 : | explicit_row
13143 : {
13144 202 : RowExpr *r = makeNode(RowExpr);
13145 202 : r->args = $1;
13146 202 : r->row_typeid = InvalidOid; /* not analyzed yet */
13147 202 : r->colnames = NIL; /* to be filled in during analysis */
13148 202 : r->row_format = COERCE_EXPLICIT_CALL; /* abuse */
13149 202 : r->location = @1;
13150 202 : $$ = (Node *)r;
13151 : }
13152 : | implicit_row
13153 : {
13154 153 : RowExpr *r = makeNode(RowExpr);
13155 153 : r->args = $1;
13156 153 : r->row_typeid = InvalidOid; /* not analyzed yet */
13157 153 : r->colnames = NIL; /* to be filled in during analysis */
13158 153 : r->row_format = COERCE_IMPLICIT_CAST; /* abuse */
13159 153 : r->location = @1;
13160 153 : $$ = (Node *)r;
13161 : }
13162 : | GROUPING '(' expr_list ')'
13163 : {
13164 41 : GroupingFunc *g = makeNode(GroupingFunc);
13165 41 : g->args = $3;
13166 41 : g->location = @1;
13167 41 : $$ = (Node *)g;
13168 : }
13169 : ;
13170 :
13171 : func_application: func_name '(' ')'
13172 : {
13173 5106 : $$ = (Node *) makeFuncCall($1, NIL, @1);
13174 : }
13175 : | func_name '(' func_arg_list opt_sort_clause ')'
13176 : {
13177 10927 : FuncCall *n = makeFuncCall($1, $3, @1);
13178 10927 : n->agg_order = $4;
13179 10927 : $$ = (Node *)n;
13180 : }
13181 : | func_name '(' VARIADIC func_arg_expr opt_sort_clause ')'
13182 : {
13183 18 : FuncCall *n = makeFuncCall($1, list_make1($4), @1);
13184 18 : n->func_variadic = TRUE;
13185 18 : n->agg_order = $5;
13186 18 : $$ = (Node *)n;
13187 : }
13188 : | func_name '(' func_arg_list ',' VARIADIC func_arg_expr opt_sort_clause ')'
13189 : {
13190 15 : FuncCall *n = makeFuncCall($1, lappend($3, $6), @1);
13191 15 : n->func_variadic = TRUE;
13192 15 : n->agg_order = $7;
13193 15 : $$ = (Node *)n;
13194 : }
13195 : | func_name '(' ALL func_arg_list opt_sort_clause ')'
13196 : {
13197 0 : FuncCall *n = makeFuncCall($1, $4, @1);
13198 0 : n->agg_order = $5;
13199 : /* Ideally we'd mark the FuncCall node to indicate
13200 : * "must be an aggregate", but there's no provision
13201 : * for that in FuncCall at the moment.
13202 : */
13203 0 : $$ = (Node *)n;
13204 : }
13205 : | func_name '(' DISTINCT func_arg_list opt_sort_clause ')'
13206 : {
13207 47 : FuncCall *n = makeFuncCall($1, $4, @1);
13208 47 : n->agg_order = $5;
13209 47 : n->agg_distinct = TRUE;
13210 47 : $$ = (Node *)n;
13211 : }
13212 : | func_name '(' '*' ')'
13213 : {
13214 : /*
13215 : * We consider AGGREGATE(*) to invoke a parameterless
13216 : * aggregate. This does the right thing for COUNT(*),
13217 : * and there are no other aggregates in SQL that accept
13218 : * '*' as parameter.
13219 : *
13220 : * The FuncCall node is also marked agg_star = true,
13221 : * so that later processing can detect what the argument
13222 : * really was.
13223 : */
13224 685 : FuncCall *n = makeFuncCall($1, NIL, @1);
13225 685 : n->agg_star = TRUE;
13226 685 : $$ = (Node *)n;
13227 : }
13228 : ;
13229 :
13230 :
13231 : /*
13232 : * func_expr and its cousin func_expr_windowless are split out from c_expr just
13233 : * so that we have classifications for "everything that is a function call or
13234 : * looks like one". This isn't very important, but it saves us having to
13235 : * document which variants are legal in places like "FROM function()" or the
13236 : * backwards-compatible functional-index syntax for CREATE INDEX.
13237 : * (Note that many of the special SQL functions wouldn't actually make any
13238 : * sense as functional index entries, but we ignore that consideration here.)
13239 : */
13240 : func_expr: func_application within_group_clause filter_clause over_clause
13241 : {
13242 15421 : FuncCall *n = (FuncCall *) $1;
13243 : /*
13244 : * The order clause for WITHIN GROUP and the one for
13245 : * plain-aggregate ORDER BY share a field, so we have to
13246 : * check here that at most one is present. We also check
13247 : * for DISTINCT and VARIADIC here to give a better error
13248 : * location. Other consistency checks are deferred to
13249 : * parse analysis.
13250 : */
13251 15421 : if ($2 != NIL)
13252 : {
13253 37 : if (n->agg_order != NIL)
13254 1 : ereport(ERROR,
13255 : (errcode(ERRCODE_SYNTAX_ERROR),
13256 : errmsg("cannot use multiple ORDER BY clauses with WITHIN GROUP"),
13257 : parser_errposition(@2)));
13258 36 : if (n->agg_distinct)
13259 0 : ereport(ERROR,
13260 : (errcode(ERRCODE_SYNTAX_ERROR),
13261 : errmsg("cannot use DISTINCT with WITHIN GROUP"),
13262 : parser_errposition(@2)));
13263 36 : if (n->func_variadic)
13264 0 : ereport(ERROR,
13265 : (errcode(ERRCODE_SYNTAX_ERROR),
13266 : errmsg("cannot use VARIADIC with WITHIN GROUP"),
13267 : parser_errposition(@2)));
13268 36 : n->agg_order = $2;
13269 36 : n->agg_within_group = TRUE;
13270 : }
13271 15420 : n->agg_filter = $3;
13272 15420 : n->over = $4;
13273 15420 : $$ = (Node *) n;
13274 : }
13275 : | func_expr_common_subexpr
13276 1625 : { $$ = $1; }
13277 : ;
13278 :
13279 : /*
13280 : * As func_expr but does not accept WINDOW functions directly
13281 : * (but they can still be contained in arguments for functions etc).
13282 : * Use this when window expressions are not allowed, where needed to
13283 : * disambiguate the grammar (e.g. in CREATE INDEX).
13284 : */
13285 : func_expr_windowless:
13286 1375 : func_application { $$ = $1; }
13287 8 : | func_expr_common_subexpr { $$ = $1; }
13288 : ;
13289 :
13290 : /*
13291 : * Special expressions that are considered to be functions.
13292 : */
13293 : func_expr_common_subexpr:
13294 : COLLATION FOR '(' a_expr ')'
13295 : {
13296 10 : $$ = (Node *) makeFuncCall(SystemFuncName("pg_collation_for"),
13297 5 : list_make1($4),
13298 5 : @1);
13299 : }
13300 : | CURRENT_DATE
13301 : {
13302 6 : $$ = makeSQLValueFunction(SVFOP_CURRENT_DATE, -1, @1);
13303 : }
13304 : | CURRENT_TIME
13305 : {
13306 1 : $$ = makeSQLValueFunction(SVFOP_CURRENT_TIME, -1, @1);
13307 : }
13308 : | CURRENT_TIME '(' Iconst ')'
13309 : {
13310 0 : $$ = makeSQLValueFunction(SVFOP_CURRENT_TIME_N, $3, @1);
13311 : }
13312 : | CURRENT_TIMESTAMP
13313 : {
13314 2 : $$ = makeSQLValueFunction(SVFOP_CURRENT_TIMESTAMP, -1, @1);
13315 : }
13316 : | CURRENT_TIMESTAMP '(' Iconst ')'
13317 : {
13318 2 : $$ = makeSQLValueFunction(SVFOP_CURRENT_TIMESTAMP_N, $3, @1);
13319 : }
13320 : | LOCALTIME
13321 : {
13322 1 : $$ = makeSQLValueFunction(SVFOP_LOCALTIME, -1, @1);
13323 : }
13324 : | LOCALTIME '(' Iconst ')'
13325 : {
13326 0 : $$ = makeSQLValueFunction(SVFOP_LOCALTIME_N, $3, @1);
13327 : }
13328 : | LOCALTIMESTAMP
13329 : {
13330 1 : $$ = makeSQLValueFunction(SVFOP_LOCALTIMESTAMP, -1, @1);
13331 : }
13332 : | LOCALTIMESTAMP '(' Iconst ')'
13333 : {
13334 1 : $$ = makeSQLValueFunction(SVFOP_LOCALTIMESTAMP_N, $3, @1);
13335 : }
13336 : | CURRENT_ROLE
13337 : {
13338 0 : $$ = makeSQLValueFunction(SVFOP_CURRENT_ROLE, -1, @1);
13339 : }
13340 : | CURRENT_USER
13341 : {
13342 80 : $$ = makeSQLValueFunction(SVFOP_CURRENT_USER, -1, @1);
13343 : }
13344 : | SESSION_USER
13345 : {
13346 27 : $$ = makeSQLValueFunction(SVFOP_SESSION_USER, -1, @1);
13347 : }
13348 : | USER
13349 : {
13350 0 : $$ = makeSQLValueFunction(SVFOP_USER, -1, @1);
13351 : }
13352 : | CURRENT_CATALOG
13353 : {
13354 1 : $$ = makeSQLValueFunction(SVFOP_CURRENT_CATALOG, -1, @1);
13355 : }
13356 : | CURRENT_SCHEMA
13357 : {
13358 3 : $$ = makeSQLValueFunction(SVFOP_CURRENT_SCHEMA, -1, @1);
13359 : }
13360 : | CAST '(' a_expr AS Typename ')'
13361 756 : { $$ = makeTypeCast($3, $5, @1); }
13362 : | EXTRACT '(' extract_list ')'
13363 : {
13364 81 : $$ = (Node *) makeFuncCall(SystemFuncName("date_part"), $3, @1);
13365 : }
13366 : | OVERLAY '(' overlay_list ')'
13367 : {
13368 : /* overlay(A PLACING B FROM C FOR D) is converted to
13369 : * overlay(A, B, C, D)
13370 : * overlay(A PLACING B FROM C) is converted to
13371 : * overlay(A, B, C)
13372 : */
13373 11 : $$ = (Node *) makeFuncCall(SystemFuncName("overlay"), $3, @1);
13374 : }
13375 : | POSITION '(' position_list ')'
13376 : {
13377 : /* position(A in B) is converted to position(B, A) */
13378 45 : $$ = (Node *) makeFuncCall(SystemFuncName("position"), $3, @1);
13379 : }
13380 : | SUBSTRING '(' substr_list ')'
13381 : {
13382 : /* substring(A from B for C) is converted to
13383 : * substring(A, B, C) - thomas 2000-11-28
13384 : */
13385 281 : $$ = (Node *) makeFuncCall(SystemFuncName("substring"), $3, @1);
13386 : }
13387 : | TREAT '(' a_expr AS Typename ')'
13388 : {
13389 : /* TREAT(expr AS target) converts expr of a particular type to target,
13390 : * which is defined to be a subtype of the original expression.
13391 : * In SQL99, this is intended for use with structured UDTs,
13392 : * but let's make this a generally useful form allowing stronger
13393 : * coercions than are handled by implicit casting.
13394 : *
13395 : * Convert SystemTypeName() to SystemFuncName() even though
13396 : * at the moment they result in the same thing.
13397 : */
13398 0 : $$ = (Node *) makeFuncCall(SystemFuncName(((Value *)llast($5->names))->val.str),
13399 0 : list_make1($3),
13400 0 : @1);
13401 : }
13402 : | TRIM '(' BOTH trim_list ')'
13403 : {
13404 : /* various trim expressions are defined in SQL
13405 : * - thomas 1997-07-19
13406 : */
13407 2 : $$ = (Node *) makeFuncCall(SystemFuncName("btrim"), $4, @1);
13408 : }
13409 : | TRIM '(' LEADING trim_list ')'
13410 : {
13411 1 : $$ = (Node *) makeFuncCall(SystemFuncName("ltrim"), $4, @1);
13412 : }
13413 : | TRIM '(' TRAILING trim_list ')'
13414 : {
13415 56 : $$ = (Node *) makeFuncCall(SystemFuncName("rtrim"), $4, @1);
13416 : }
13417 : | TRIM '(' trim_list ')'
13418 : {
13419 13 : $$ = (Node *) makeFuncCall(SystemFuncName("btrim"), $3, @1);
13420 : }
13421 : | NULLIF '(' a_expr ',' a_expr ')'
13422 : {
13423 11 : $$ = (Node *) makeSimpleA_Expr(AEXPR_NULLIF, "=", $3, $5, @1);
13424 : }
13425 : | COALESCE '(' expr_list ')'
13426 : {
13427 127 : CoalesceExpr *c = makeNode(CoalesceExpr);
13428 127 : c->args = $3;
13429 127 : c->location = @1;
13430 127 : $$ = (Node *)c;
13431 : }
13432 : | GREATEST '(' expr_list ')'
13433 : {
13434 9 : MinMaxExpr *v = makeNode(MinMaxExpr);
13435 9 : v->args = $3;
13436 9 : v->op = IS_GREATEST;
13437 9 : v->location = @1;
13438 9 : $$ = (Node *)v;
13439 : }
13440 : | LEAST '(' expr_list ')'
13441 : {
13442 7 : MinMaxExpr *v = makeNode(MinMaxExpr);
13443 7 : v->args = $3;
13444 7 : v->op = IS_LEAST;
13445 7 : v->location = @1;
13446 7 : $$ = (Node *)v;
13447 : }
13448 : | XMLCONCAT '(' expr_list ')'
13449 : {
13450 10 : $$ = makeXmlExpr(IS_XMLCONCAT, NULL, NIL, $3, @1);
13451 : }
13452 : | XMLELEMENT '(' NAME_P ColLabel ')'
13453 : {
13454 0 : $$ = makeXmlExpr(IS_XMLELEMENT, $4, NIL, NIL, @1);
13455 : }
13456 : | XMLELEMENT '(' NAME_P ColLabel ',' xml_attributes ')'
13457 : {
13458 6 : $$ = makeXmlExpr(IS_XMLELEMENT, $4, $6, NIL, @1);
13459 : }
13460 : | XMLELEMENT '(' NAME_P ColLabel ',' expr_list ')'
13461 : {
13462 19 : $$ = makeXmlExpr(IS_XMLELEMENT, $4, NIL, $6, @1);
13463 : }
13464 : | XMLELEMENT '(' NAME_P ColLabel ',' xml_attributes ',' expr_list ')'
13465 : {
13466 3 : $$ = makeXmlExpr(IS_XMLELEMENT, $4, $6, $8, @1);
13467 : }
13468 : | XMLEXISTS '(' c_expr xmlexists_argument ')'
13469 : {
13470 : /* xmlexists(A PASSING [BY REF] B [BY REF]) is
13471 : * converted to xmlexists(A, B)*/
13472 8 : $$ = (Node *) makeFuncCall(SystemFuncName("xmlexists"), list_make2($3, $4), @1);
13473 : }
13474 : | XMLFOREST '(' xml_attribute_list ')'
13475 : {
13476 5 : $$ = makeXmlExpr(IS_XMLFOREST, NULL, $3, NIL, @1);
13477 : }
13478 : | XMLPARSE '(' document_or_content a_expr xml_whitespace_option ')'
13479 : {
13480 23 : XmlExpr *x = (XmlExpr *)
13481 69 : makeXmlExpr(IS_XMLPARSE, NULL, NIL,
13482 46 : list_make2($4, makeBoolAConst($5, -1)),
13483 23 : @1);
13484 23 : x->xmloption = $3;
13485 23 : $$ = (Node *)x;
13486 : }
13487 : | XMLPI '(' NAME_P ColLabel ')'
13488 : {
13489 5 : $$ = makeXmlExpr(IS_XMLPI, $4, NULL, NIL, @1);
13490 : }
13491 : | XMLPI '(' NAME_P ColLabel ',' a_expr ')'
13492 : {
13493 8 : $$ = makeXmlExpr(IS_XMLPI, $4, NULL, list_make1($6), @1);
13494 : }
13495 : | XMLROOT '(' a_expr ',' xml_root_version opt_xml_root_standalone ')'
13496 : {
13497 44 : $$ = makeXmlExpr(IS_XMLROOT, NULL, NIL,
13498 44 : list_make3($3, $5, $6), @1);
13499 : }
13500 : | XMLSERIALIZE '(' document_or_content a_expr AS SimpleTypename ')'
13501 : {
13502 5 : XmlSerialize *n = makeNode(XmlSerialize);
13503 5 : n->xmloption = $3;
13504 5 : n->expr = $4;
13505 5 : n->typeName = $6;
13506 5 : n->location = @1;
13507 5 : $$ = (Node *)n;
13508 : }
13509 : ;
13510 :
13511 : /*
13512 : * SQL/XML support
13513 : */
13514 : xml_root_version: VERSION_P a_expr
13515 4 : { $$ = $2; }
13516 : | VERSION_P NO VALUE_P
13517 7 : { $$ = makeNullAConst(-1); }
13518 : ;
13519 :
13520 : opt_xml_root_standalone: ',' STANDALONE_P YES_P
13521 4 : { $$ = makeIntConst(XML_STANDALONE_YES, -1); }
13522 : | ',' STANDALONE_P NO
13523 2 : { $$ = makeIntConst(XML_STANDALONE_NO, -1); }
13524 : | ',' STANDALONE_P NO VALUE_P
13525 2 : { $$ = makeIntConst(XML_STANDALONE_NO_VALUE, -1); }
13526 : | /*EMPTY*/
13527 3 : { $$ = makeIntConst(XML_STANDALONE_OMITTED, -1); }
13528 : ;
13529 :
13530 9 : xml_attributes: XMLATTRIBUTES '(' xml_attribute_list ')' { $$ = $3; }
13531 : ;
13532 :
13533 14 : xml_attribute_list: xml_attribute_el { $$ = list_make1($1); }
13534 23 : | xml_attribute_list ',' xml_attribute_el { $$ = lappend($1, $3); }
13535 : ;
13536 :
13537 : xml_attribute_el: a_expr AS ColLabel
13538 : {
13539 16 : $$ = makeNode(ResTarget);
13540 16 : $$->name = $3;
13541 16 : $$->indirection = NIL;
13542 16 : $$->val = (Node *) $1;
13543 16 : $$->location = @1;
13544 : }
13545 : | a_expr
13546 : {
13547 21 : $$ = makeNode(ResTarget);
13548 21 : $$->name = NULL;
13549 21 : $$->indirection = NIL;
13550 21 : $$->val = (Node *) $1;
13551 21 : $$->location = @1;
13552 : }
13553 : ;
13554 :
13555 14 : document_or_content: DOCUMENT_P { $$ = XMLOPTION_DOCUMENT; }
13556 16 : | CONTENT_P { $$ = XMLOPTION_CONTENT; }
13557 : ;
13558 :
13559 0 : xml_whitespace_option: PRESERVE WHITESPACE_P { $$ = TRUE; }
13560 0 : | STRIP_P WHITESPACE_P { $$ = FALSE; }
13561 23 : | /*EMPTY*/ { $$ = FALSE; }
13562 : ;
13563 :
13564 : /* We allow several variants for SQL and other compatibility. */
13565 : xmlexists_argument:
13566 : PASSING c_expr
13567 : {
13568 31 : $$ = $2;
13569 : }
13570 : | PASSING c_expr BY REF
13571 : {
13572 0 : $$ = $2;
13573 : }
13574 : | PASSING BY REF c_expr
13575 : {
13576 6 : $$ = $4;
13577 : }
13578 : | PASSING BY REF c_expr BY REF
13579 : {
13580 1 : $$ = $4;
13581 : }
13582 : ;
13583 :
13584 :
13585 : /*
13586 : * Aggregate decoration clauses
13587 : */
13588 : within_group_clause:
13589 37 : WITHIN GROUP_P '(' sort_clause ')' { $$ = $4; }
13590 15386 : | /*EMPTY*/ { $$ = NIL; }
13591 : ;
13592 :
13593 : filter_clause:
13594 20 : FILTER '(' WHERE a_expr ')' { $$ = $4; }
13595 15403 : | /*EMPTY*/ { $$ = NULL; }
13596 : ;
13597 :
13598 :
13599 : /*
13600 : * Window Definitions
13601 : */
13602 : window_clause:
13603 17 : WINDOW window_definition_list { $$ = $2; }
13604 25963 : | /*EMPTY*/ { $$ = NIL; }
13605 : ;
13606 :
13607 : window_definition_list:
13608 17 : window_definition { $$ = list_make1($1); }
13609 : | window_definition_list ',' window_definition
13610 2 : { $$ = lappend($1, $3); }
13611 : ;
13612 :
13613 : window_definition:
13614 : ColId AS window_specification
13615 : {
13616 19 : WindowDef *n = $3;
13617 19 : n->name = $1;
13618 19 : $$ = n;
13619 : }
13620 : ;
13621 :
13622 : over_clause: OVER window_specification
13623 150 : { $$ = $2; }
13624 : | OVER ColId
13625 : {
13626 31 : WindowDef *n = makeNode(WindowDef);
13627 31 : n->name = $2;
13628 31 : n->refname = NULL;
13629 31 : n->partitionClause = NIL;
13630 31 : n->orderClause = NIL;
13631 31 : n->frameOptions = FRAMEOPTION_DEFAULTS;
13632 31 : n->startOffset = NULL;
13633 31 : n->endOffset = NULL;
13634 31 : n->location = @2;
13635 31 : $$ = n;
13636 : }
13637 : | /*EMPTY*/
13638 15240 : { $$ = NULL; }
13639 : ;
13640 :
13641 : window_specification: '(' opt_existing_window_name opt_partition_clause
13642 : opt_sort_clause opt_frame_clause ')'
13643 : {
13644 169 : WindowDef *n = makeNode(WindowDef);
13645 169 : n->name = NULL;
13646 169 : n->refname = $2;
13647 169 : n->partitionClause = $3;
13648 169 : n->orderClause = $4;
13649 : /* copy relevant fields of opt_frame_clause */
13650 169 : n->frameOptions = $5->frameOptions;
13651 169 : n->startOffset = $5->startOffset;
13652 169 : n->endOffset = $5->endOffset;
13653 169 : n->location = @1;
13654 169 : $$ = n;
13655 : }
13656 : ;
13657 :
13658 : /*
13659 : * If we see PARTITION, RANGE, or ROWS as the first token after the '('
13660 : * of a window_specification, we want the assumption to be that there is
13661 : * no existing_window_name; but those keywords are unreserved and so could
13662 : * be ColIds. We fix this by making them have the same precedence as IDENT
13663 : * and giving the empty production here a slightly higher precedence, so
13664 : * that the shift/reduce conflict is resolved in favor of reducing the rule.
13665 : * These keywords are thus precluded from being an existing_window_name but
13666 : * are not reserved for any other purpose.
13667 : */
13668 1 : opt_existing_window_name: ColId { $$ = $1; }
13669 170 : | /*EMPTY*/ %prec Op { $$ = NULL; }
13670 : ;
13671 :
13672 56 : opt_partition_clause: PARTITION BY expr_list { $$ = $3; }
13673 114 : | /*EMPTY*/ { $$ = NIL; }
13674 : ;
13675 :
13676 : /*
13677 : * For frame clauses, we return a WindowDef, but only some fields are used:
13678 : * frameOptions, startOffset, and endOffset.
13679 : *
13680 : * This is only a subset of the full SQL:2008 frame_clause grammar.
13681 : * We don't support <window frame exclusion> yet.
13682 : */
13683 : opt_frame_clause:
13684 : RANGE frame_extent
13685 : {
13686 10 : WindowDef *n = $2;
13687 10 : n->frameOptions |= FRAMEOPTION_NONDEFAULT | FRAMEOPTION_RANGE;
13688 10 : if (n->frameOptions & (FRAMEOPTION_START_VALUE_PRECEDING |
13689 : FRAMEOPTION_END_VALUE_PRECEDING))
13690 1 : ereport(ERROR,
13691 : (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
13692 : errmsg("RANGE PRECEDING is only supported with UNBOUNDED"),
13693 : parser_errposition(@1)));
13694 9 : if (n->frameOptions & (FRAMEOPTION_START_VALUE_FOLLOWING |
13695 : FRAMEOPTION_END_VALUE_FOLLOWING))
13696 0 : ereport(ERROR,
13697 : (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
13698 : errmsg("RANGE FOLLOWING is only supported with UNBOUNDED"),
13699 : parser_errposition(@1)));
13700 9 : $$ = n;
13701 : }
13702 : | ROWS frame_extent
13703 : {
13704 60 : WindowDef *n = $2;
13705 60 : n->frameOptions |= FRAMEOPTION_NONDEFAULT | FRAMEOPTION_ROWS;
13706 60 : $$ = n;
13707 : }
13708 : | /*EMPTY*/
13709 : {
13710 100 : WindowDef *n = makeNode(WindowDef);
13711 100 : n->frameOptions = FRAMEOPTION_DEFAULTS;
13712 100 : n->startOffset = NULL;
13713 100 : n->endOffset = NULL;
13714 100 : $$ = n;
13715 : }
13716 : ;
13717 :
13718 : frame_extent: frame_bound
13719 : {
13720 1 : WindowDef *n = $1;
13721 : /* reject invalid cases */
13722 1 : if (n->frameOptions & FRAMEOPTION_START_UNBOUNDED_FOLLOWING)
13723 0 : ereport(ERROR,
13724 : (errcode(ERRCODE_WINDOWING_ERROR),
13725 : errmsg("frame start cannot be UNBOUNDED FOLLOWING"),
13726 : parser_errposition(@1)));
13727 1 : if (n->frameOptions & FRAMEOPTION_START_VALUE_FOLLOWING)
13728 0 : ereport(ERROR,
13729 : (errcode(ERRCODE_WINDOWING_ERROR),
13730 : errmsg("frame starting from following row cannot end with current row"),
13731 : parser_errposition(@1)));
13732 1 : n->frameOptions |= FRAMEOPTION_END_CURRENT_ROW;
13733 1 : $$ = n;
13734 : }
13735 : | BETWEEN frame_bound AND frame_bound
13736 : {
13737 69 : WindowDef *n1 = $2;
13738 69 : WindowDef *n2 = $4;
13739 : /* form merged options */
13740 69 : int frameOptions = n1->frameOptions;
13741 : /* shift converts START_ options to END_ options */
13742 69 : frameOptions |= n2->frameOptions << 1;
13743 69 : frameOptions |= FRAMEOPTION_BETWEEN;
13744 : /* reject invalid cases */
13745 69 : if (frameOptions & FRAMEOPTION_START_UNBOUNDED_FOLLOWING)
13746 0 : ereport(ERROR,
13747 : (errcode(ERRCODE_WINDOWING_ERROR),
13748 : errmsg("frame start cannot be UNBOUNDED FOLLOWING"),
13749 : parser_errposition(@2)));
13750 69 : if (frameOptions & FRAMEOPTION_END_UNBOUNDED_PRECEDING)
13751 0 : ereport(ERROR,
13752 : (errcode(ERRCODE_WINDOWING_ERROR),
13753 : errmsg("frame end cannot be UNBOUNDED PRECEDING"),
13754 : parser_errposition(@4)));
13755 117 : if ((frameOptions & FRAMEOPTION_START_CURRENT_ROW) &&
13756 48 : (frameOptions & FRAMEOPTION_END_VALUE_PRECEDING))
13757 0 : ereport(ERROR,
13758 : (errcode(ERRCODE_WINDOWING_ERROR),
13759 : errmsg("frame starting from current row cannot have preceding rows"),
13760 : parser_errposition(@4)));
13761 70 : if ((frameOptions & FRAMEOPTION_START_VALUE_FOLLOWING) &&
13762 1 : (frameOptions & (FRAMEOPTION_END_VALUE_PRECEDING |
13763 : FRAMEOPTION_END_CURRENT_ROW)))
13764 0 : ereport(ERROR,
13765 : (errcode(ERRCODE_WINDOWING_ERROR),
13766 : errmsg("frame starting from following row cannot have preceding rows"),
13767 : parser_errposition(@4)));
13768 69 : n1->frameOptions = frameOptions;
13769 69 : n1->endOffset = n2->startOffset;
13770 69 : $$ = n1;
13771 : }
13772 : ;
13773 :
13774 : /*
13775 : * This is used for both frame start and frame end, with output set up on
13776 : * the assumption it's frame start; the frame_extent productions must reject
13777 : * invalid cases.
13778 : */
13779 : frame_bound:
13780 : UNBOUNDED PRECEDING
13781 : {
13782 10 : WindowDef *n = makeNode(WindowDef);
13783 10 : n->frameOptions = FRAMEOPTION_START_UNBOUNDED_PRECEDING;
13784 10 : n->startOffset = NULL;
13785 10 : n->endOffset = NULL;
13786 10 : $$ = n;
13787 : }
13788 : | UNBOUNDED FOLLOWING
13789 : {
13790 45 : WindowDef *n = makeNode(WindowDef);
13791 45 : n->frameOptions = FRAMEOPTION_START_UNBOUNDED_FOLLOWING;
13792 45 : n->startOffset = NULL;
13793 45 : n->endOffset = NULL;
13794 45 : $$ = n;
13795 : }
13796 : | CURRENT_P ROW
13797 : {
13798 62 : WindowDef *n = makeNode(WindowDef);
13799 62 : n->frameOptions = FRAMEOPTION_START_CURRENT_ROW;
13800 62 : n->startOffset = NULL;
13801 62 : n->endOffset = NULL;
13802 62 : $$ = n;
13803 : }
13804 : | a_expr PRECEDING
13805 : {
13806 13 : WindowDef *n = makeNode(WindowDef);
13807 13 : n->frameOptions = FRAMEOPTION_START_VALUE_PRECEDING;
13808 13 : n->startOffset = $1;
13809 13 : n->endOffset = NULL;
13810 13 : $$ = n;
13811 : }
13812 : | a_expr FOLLOWING
13813 : {
13814 9 : WindowDef *n = makeNode(WindowDef);
13815 9 : n->frameOptions = FRAMEOPTION_START_VALUE_FOLLOWING;
13816 9 : n->startOffset = $1;
13817 9 : n->endOffset = NULL;
13818 9 : $$ = n;
13819 : }
13820 : ;
13821 :
13822 :
13823 : /*
13824 : * Supporting nonterminals for expressions.
13825 : */
13826 :
13827 : /* Explicit row production.
13828 : *
13829 : * SQL99 allows an optional ROW keyword, so we can now do single-element rows
13830 : * without conflicting with the parenthesized a_expr production. Without the
13831 : * ROW keyword, there must be more than one a_expr inside the parens.
13832 : */
13833 0 : row: ROW '(' expr_list ')' { $$ = $3; }
13834 0 : | ROW '(' ')' { $$ = NIL; }
13835 54 : | '(' expr_list ',' a_expr ')' { $$ = lappend($2, $4); }
13836 : ;
13837 :
13838 198 : explicit_row: ROW '(' expr_list ')' { $$ = $3; }
13839 4 : | ROW '(' ')' { $$ = NIL; }
13840 : ;
13841 :
13842 153 : implicit_row: '(' expr_list ',' a_expr ')' { $$ = lappend($2, $4); }
13843 : ;
13844 :
13845 238 : sub_type: ANY { $$ = ANY_SUBLINK; }
13846 0 : | SOME { $$ = ANY_SUBLINK; }
13847 18 : | ALL { $$ = ALL_SUBLINK; }
13848 : ;
13849 :
13850 129 : all_Op: Op { $$ = $1; }
13851 569 : | MathOp { $$ = $1; }
13852 : ;
13853 :
13854 4 : MathOp: '+' { $$ = "+"; }
13855 1 : | '-' { $$ = "-"; }
13856 2 : | '*' { $$ = "*"; }
13857 0 : | '/' { $$ = "/"; }
13858 0 : | '%' { $$ = "%"; }
13859 0 : | '^' { $$ = "^"; }
13860 38 : | '<' { $$ = "<"; }
13861 17 : | '>' { $$ = ">"; }
13862 484 : | '=' { $$ = "="; }
13863 5 : | LESS_EQUALS { $$ = "<="; }
13864 9 : | GREATER_EQUALS { $$ = ">="; }
13865 9 : | NOT_EQUALS { $$ = "<>"; }
13866 : ;
13867 :
13868 : qual_Op: Op
13869 3218 : { $$ = list_make1(makeString($1)); }
13870 : | OPERATOR '(' any_operator ')'
13871 245 : { $$ = $3; }
13872 : ;
13873 :
13874 : qual_all_Op:
13875 : all_Op
13876 50 : { $$ = list_make1(makeString($1)); }
13877 : | OPERATOR '(' any_operator ')'
13878 0 : { $$ = $3; }
13879 : ;
13880 :
13881 : subquery_Op:
13882 : all_Op
13883 243 : { $$ = list_make1(makeString($1)); }
13884 : | OPERATOR '(' any_operator ')'
13885 5 : { $$ = $3; }
13886 : | LIKE
13887 4 : { $$ = list_make1(makeString("~~")); }
13888 : | NOT_LA LIKE
13889 2 : { $$ = list_make1(makeString("!~~")); }
13890 : | ILIKE
13891 2 : { $$ = list_make1(makeString("~~*")); }
13892 : | NOT_LA ILIKE
13893 0 : { $$ = list_make1(makeString("!~~*")); }
13894 : /* cannot put SIMILAR TO here, because SIMILAR TO is a hack.
13895 : * the regular expression is preprocessed by a function (similar_escape),
13896 : * and the ~ operator for posix regular expressions is used.
13897 : * x SIMILAR TO y -> x ~ similar_escape(y)
13898 : * this transformation is made on the fly by the parser upwards.
13899 : * however the SubLink structure which handles any/some/all stuff
13900 : * is not ready for such a thing.
13901 : */
13902 : ;
13903 :
13904 : expr_list: a_expr
13905 : {
13906 7204 : $$ = list_make1($1);
13907 : }
13908 : | expr_list ',' a_expr
13909 : {
13910 7356 : $$ = lappend($1, $3);
13911 : }
13912 : ;
13913 :
13914 : /* function arguments can have names */
13915 : func_arg_list: func_arg_expr
13916 : {
13917 10989 : $$ = list_make1($1);
13918 : }
13919 : | func_arg_list ',' func_arg_expr
13920 : {
13921 6807 : $$ = lappend($1, $3);
13922 : }
13923 : ;
13924 :
13925 : func_arg_expr: a_expr
13926 : {
13927 17730 : $$ = $1;
13928 : }
13929 : | param_name COLON_EQUALS a_expr
13930 : {
13931 80 : NamedArgExpr *na = makeNode(NamedArgExpr);
13932 80 : na->name = $1;
13933 80 : na->arg = (Expr *) $3;
13934 80 : na->argnumber = -1; /* until determined */
13935 80 : na->location = @1;
13936 80 : $$ = (Node *) na;
13937 : }
13938 : | param_name EQUALS_GREATER a_expr
13939 : {
13940 19 : NamedArgExpr *na = makeNode(NamedArgExpr);
13941 19 : na->name = $1;
13942 19 : na->arg = (Expr *) $3;
13943 19 : na->argnumber = -1; /* until determined */
13944 19 : na->location = @1;
13945 19 : $$ = (Node *) na;
13946 : }
13947 : ;
13948 :
13949 31 : type_list: Typename { $$ = list_make1($1); }
13950 18 : | type_list ',' Typename { $$ = lappend($1, $3); }
13951 : ;
13952 :
13953 : array_expr: '[' expr_list ']'
13954 : {
13955 521 : $$ = makeAArrayExpr($2, @1);
13956 : }
13957 : | '[' array_expr_list ']'
13958 : {
13959 48 : $$ = makeAArrayExpr($2, @1);
13960 : }
13961 : | '[' ']'
13962 : {
13963 9 : $$ = makeAArrayExpr(NIL, @1);
13964 : }
13965 : ;
13966 :
13967 48 : array_expr_list: array_expr { $$ = list_make1($1); }
13968 35 : | array_expr_list ',' array_expr { $$ = lappend($1, $3); }
13969 : ;
13970 :
13971 :
13972 : extract_list:
13973 : extract_arg FROM a_expr
13974 : {
13975 81 : $$ = list_make2(makeStringConst($1, @1), $3);
13976 : }
13977 0 : | /*EMPTY*/ { $$ = NIL; }
13978 : ;
13979 :
13980 : /* Allow delimited string Sconst in extract_arg as an SQL extension.
13981 : * - thomas 2001-04-12
13982 : */
13983 : extract_arg:
13984 61 : IDENT { $$ = $1; }
13985 6 : | YEAR_P { $$ = "year"; }
13986 4 : | MONTH_P { $$ = "month"; }
13987 1 : | DAY_P { $$ = "day"; }
13988 7 : | HOUR_P { $$ = "hour"; }
13989 1 : | MINUTE_P { $$ = "minute"; }
13990 1 : | SECOND_P { $$ = "second"; }
13991 0 : | Sconst { $$ = $1; }
13992 : ;
13993 :
13994 : /* OVERLAY() arguments
13995 : * SQL99 defines the OVERLAY() function:
13996 : * o overlay(text placing text from int for int)
13997 : * o overlay(text placing text from int)
13998 : * and similarly for binary strings
13999 : */
14000 : overlay_list:
14001 : a_expr overlay_placing substr_from substr_for
14002 : {
14003 4 : $$ = list_make4($1, $2, $3, $4);
14004 : }
14005 : | a_expr overlay_placing substr_from
14006 : {
14007 7 : $$ = list_make3($1, $2, $3);
14008 : }
14009 : ;
14010 :
14011 : overlay_placing:
14012 : PLACING a_expr
14013 11 : { $$ = $2; }
14014 : ;
14015 :
14016 : /* position_list uses b_expr not a_expr to avoid conflict with general IN */
14017 :
14018 : position_list:
14019 45 : b_expr IN_P b_expr { $$ = list_make2($3, $1); }
14020 0 : | /*EMPTY*/ { $$ = NIL; }
14021 : ;
14022 :
14023 : /* SUBSTRING() arguments
14024 : * SQL9x defines a specific syntax for arguments to SUBSTRING():
14025 : * o substring(text from int for int)
14026 : * o substring(text from int) get entire string from starting point "int"
14027 : * o substring(text for int) get first "int" characters of string
14028 : * o substring(text from pattern) get entire string matching pattern
14029 : * o substring(text from pattern for escape) same with specified escape char
14030 : * We also want to support generic substring functions which accept
14031 : * the usual generic list of arguments. So we will accept both styles
14032 : * here, and convert the SQL9x style to the generic list for further
14033 : * processing. - thomas 2000-11-28
14034 : */
14035 : substr_list:
14036 : a_expr substr_from substr_for
14037 : {
14038 11 : $$ = list_make3($1, $2, $3);
14039 : }
14040 : | a_expr substr_for substr_from
14041 : {
14042 : /* not legal per SQL99, but might as well allow it */
14043 0 : $$ = list_make3($1, $3, $2);
14044 : }
14045 : | a_expr substr_from
14046 : {
14047 12 : $$ = list_make2($1, $2);
14048 : }
14049 : | a_expr substr_for
14050 : {
14051 : /*
14052 : * Since there are no cases where this syntax allows
14053 : * a textual FOR value, we forcibly cast the argument
14054 : * to int4. The possible matches in pg_proc are
14055 : * substring(text,int4) and substring(text,text),
14056 : * and we don't want the parser to choose the latter,
14057 : * which it is likely to do if the second argument
14058 : * is unknown or doesn't have an implicit cast to int4.
14059 : */
14060 243 : $$ = list_make3($1, makeIntConst(1, -1),
14061 : makeTypeCast($2,
14062 : SystemTypeName("int4"), -1));
14063 : }
14064 : | expr_list
14065 : {
14066 15 : $$ = $1;
14067 : }
14068 : | /*EMPTY*/
14069 0 : { $$ = NIL; }
14070 : ;
14071 :
14072 : substr_from:
14073 34 : FROM a_expr { $$ = $2; }
14074 : ;
14075 :
14076 258 : substr_for: FOR a_expr { $$ = $2; }
14077 : ;
14078 :
14079 56 : trim_list: a_expr FROM expr_list { $$ = lappend($3, $1); }
14080 4 : | FROM expr_list { $$ = $2; }
14081 12 : | expr_list { $$ = $1; }
14082 : ;
14083 :
14084 : in_expr: select_with_parens
14085 : {
14086 86 : SubLink *n = makeNode(SubLink);
14087 86 : n->subselect = $1;
14088 : /* other fields will be filled later */
14089 86 : $$ = (Node *)n;
14090 : }
14091 299 : | '(' expr_list ')' { $$ = (Node *)$2; }
14092 : ;
14093 :
14094 : /*
14095 : * Define SQL-style CASE clause.
14096 : * - Full specification
14097 : * CASE WHEN a = b THEN c ... ELSE d END
14098 : * - Implicit argument
14099 : * CASE a WHEN b THEN c ... ELSE d END
14100 : */
14101 : case_expr: CASE case_arg when_clause_list case_default END_P
14102 : {
14103 1034 : CaseExpr *c = makeNode(CaseExpr);
14104 1034 : c->casetype = InvalidOid; /* not analyzed yet */
14105 1034 : c->arg = (Expr *) $2;
14106 1034 : c->args = $3;
14107 1034 : c->defresult = (Expr *) $4;
14108 1034 : c->location = @1;
14109 1034 : $$ = (Node *)c;
14110 : }
14111 : ;
14112 :
14113 : when_clause_list:
14114 : /* There must be at least one */
14115 1034 : when_clause { $$ = list_make1($1); }
14116 675 : | when_clause_list when_clause { $$ = lappend($1, $2); }
14117 : ;
14118 :
14119 : when_clause:
14120 : WHEN a_expr THEN a_expr
14121 : {
14122 1709 : CaseWhen *w = makeNode(CaseWhen);
14123 1709 : w->expr = (Expr *) $2;
14124 1709 : w->result = (Expr *) $4;
14125 1709 : w->location = @1;
14126 1709 : $$ = (Node *)w;
14127 : }
14128 : ;
14129 :
14130 : case_default:
14131 823 : ELSE a_expr { $$ = $2; }
14132 211 : | /*EMPTY*/ { $$ = NULL; }
14133 : ;
14134 :
14135 207 : case_arg: a_expr { $$ = $1; }
14136 827 : | /*EMPTY*/ { $$ = NULL; }
14137 : ;
14138 :
14139 : columnref: ColId
14140 : {
14141 22613 : $$ = makeColumnRef($1, NIL, @1, yyscanner);
14142 : }
14143 : | ColId indirection
14144 : {
14145 28594 : $$ = makeColumnRef($1, $2, @1, yyscanner);
14146 : }
14147 : ;
14148 :
14149 : indirection_el:
14150 : '.' attr_name
14151 : {
14152 38029 : $$ = (Node *) makeString($2);
14153 : }
14154 : | '.' '*'
14155 : {
14156 401 : $$ = (Node *) makeNode(A_Star);
14157 : }
14158 : | '[' a_expr ']'
14159 : {
14160 454 : A_Indices *ai = makeNode(A_Indices);
14161 454 : ai->is_slice = false;
14162 454 : ai->lidx = NULL;
14163 454 : ai->uidx = $2;
14164 454 : $$ = (Node *) ai;
14165 : }
14166 : | '[' opt_slice_bound ':' opt_slice_bound ']'
14167 : {
14168 77 : A_Indices *ai = makeNode(A_Indices);
14169 77 : ai->is_slice = true;
14170 77 : ai->lidx = $2;
14171 77 : ai->uidx = $4;
14172 77 : $$ = (Node *) ai;
14173 : }
14174 : ;
14175 :
14176 : opt_slice_bound:
14177 128 : a_expr { $$ = $1; }
14178 26 : | /*EMPTY*/ { $$ = NULL; }
14179 : ;
14180 :
14181 : indirection:
14182 38396 : indirection_el { $$ = list_make1($1); }
14183 192 : | indirection indirection_el { $$ = lappend($1, $2); }
14184 : ;
14185 :
14186 : opt_indirection:
14187 6425 : /*EMPTY*/ { $$ = NIL; }
14188 373 : | opt_indirection indirection_el { $$ = lappend($1, $2); }
14189 : ;
14190 :
14191 : opt_asymmetric: ASYMMETRIC
14192 : | /*EMPTY*/
14193 : ;
14194 :
14195 :
14196 : /*****************************************************************************
14197 : *
14198 : * target list for SELECT
14199 : *
14200 : *****************************************************************************/
14201 :
14202 25907 : opt_target_list: target_list { $$ = $1; }
14203 6 : | /* EMPTY */ { $$ = NIL; }
14204 : ;
14205 :
14206 : target_list:
14207 26216 : target_el { $$ = list_make1($1); }
14208 15015 : | target_list ',' target_el { $$ = lappend($1, $3); }
14209 : ;
14210 :
14211 : target_el: a_expr AS ColLabel
14212 : {
14213 5551 : $$ = makeNode(ResTarget);
14214 5551 : $$->name = $3;
14215 5551 : $$->indirection = NIL;
14216 5551 : $$->val = (Node *)$1;
14217 5551 : $$->location = @1;
14218 : }
14219 : /*
14220 : * We support omitting AS only for column labels that aren't
14221 : * any known keyword. There is an ambiguity against postfix
14222 : * operators: is "a ! b" an infix expression, or a postfix
14223 : * expression and a column label? We prefer to resolve this
14224 : * as an infix expression, which we accomplish by assigning
14225 : * IDENT a precedence higher than POSTFIXOP.
14226 : */
14227 : | a_expr IDENT
14228 : {
14229 80 : $$ = makeNode(ResTarget);
14230 80 : $$->name = $2;
14231 80 : $$->indirection = NIL;
14232 80 : $$->val = (Node *)$1;
14233 80 : $$->location = @1;
14234 : }
14235 : | a_expr
14236 : {
14237 32464 : $$ = makeNode(ResTarget);
14238 32464 : $$->name = NULL;
14239 32464 : $$->indirection = NIL;
14240 32464 : $$->val = (Node *)$1;
14241 32464 : $$->location = @1;
14242 : }
14243 : | '*'
14244 : {
14245 3136 : ColumnRef *n = makeNode(ColumnRef);
14246 3136 : n->fields = list_make1(makeNode(A_Star));
14247 3136 : n->location = @1;
14248 :
14249 3136 : $$ = makeNode(ResTarget);
14250 3136 : $$->name = NULL;
14251 3136 : $$->indirection = NIL;
14252 3136 : $$->val = (Node *)n;
14253 3136 : $$->location = @1;
14254 : }
14255 : ;
14256 :
14257 :
14258 : /*****************************************************************************
14259 : *
14260 : * Names and constants
14261 : *
14262 : *****************************************************************************/
14263 :
14264 : qualified_name_list:
14265 473 : qualified_name { $$ = list_make1($1); }
14266 29 : | qualified_name_list ',' qualified_name { $$ = lappend($1, $3); }
14267 : ;
14268 :
14269 : /*
14270 : * The production for a qualified relation name has to exactly match the
14271 : * production for a qualified func_name, because in a FROM clause we cannot
14272 : * tell which we are parsing until we see what comes after it ('(' for a
14273 : * func_name, something else for a relation). Therefore we allow 'indirection'
14274 : * which may contain subscripts, and reject that case in the C code.
14275 : */
14276 : qualified_name:
14277 : ColId
14278 : {
14279 18254 : $$ = makeRangeVar(NULL, $1, @1);
14280 : }
14281 : | ColId indirection
14282 : {
14283 6031 : check_qualified_name($2, yyscanner);
14284 6031 : $$ = makeRangeVar(NULL, NULL, @1);
14285 6031 : switch (list_length($2))
14286 : {
14287 : case 1:
14288 6031 : $$->catalogname = NULL;
14289 6031 : $$->schemaname = $1;
14290 6031 : $$->relname = strVal(linitial($2));
14291 6031 : break;
14292 : case 2:
14293 0 : $$->catalogname = $1;
14294 0 : $$->schemaname = strVal(linitial($2));
14295 0 : $$->relname = strVal(lsecond($2));
14296 0 : break;
14297 : default:
14298 0 : ereport(ERROR,
14299 : (errcode(ERRCODE_SYNTAX_ERROR),
14300 : errmsg("improper qualified name (too many dotted names): %s",
14301 : NameListToString(lcons(makeString($1), $2))),
14302 : parser_errposition(@1)));
14303 : break;
14304 : }
14305 : }
14306 : ;
14307 :
14308 : name_list: name
14309 1093 : { $$ = list_make1(makeString($1)); }
14310 : | name_list ',' name
14311 776 : { $$ = lappend($1, makeString($3)); }
14312 : ;
14313 :
14314 :
14315 4186 : name: ColId { $$ = $1; };
14316 :
14317 : database_name:
14318 9 : ColId { $$ = $1; };
14319 :
14320 : access_method:
14321 239 : ColId { $$ = $1; };
14322 :
14323 40697 : attr_name: ColLabel { $$ = $1; };
14324 :
14325 257 : index_name: ColId { $$ = $1; };
14326 :
14327 1 : file_name: Sconst { $$ = $1; };
14328 :
14329 : /*
14330 : * The production for a qualified func_name has to exactly match the
14331 : * production for a qualified columnref, because we cannot tell which we
14332 : * are parsing until we see what comes after it ('(' or Sconst for a func_name,
14333 : * anything else for a columnref). Therefore we allow 'indirection' which
14334 : * may contain subscripts, and reject that case in the C code. (If we
14335 : * ever implement SQL99-like methods, such syntax may actually become legal!)
14336 : */
14337 : func_name: type_function_name
14338 15395 : { $$ = list_make1(makeString($1)); }
14339 : | ColId indirection
14340 : {
14341 3768 : $$ = check_func_name(lcons(makeString($1), $2),
14342 : yyscanner);
14343 : }
14344 : ;
14345 :
14346 :
14347 : /*
14348 : * Constants
14349 : */
14350 : AexprConst: Iconst
14351 : {
14352 17249 : $$ = makeIntConst($1, @1);
14353 : }
14354 : | FCONST
14355 : {
14356 825 : $$ = makeFloatConst($1, @1);
14357 : }
14358 : | Sconst
14359 : {
14360 22119 : $$ = makeStringConst($1, @1);
14361 : }
14362 : | BCONST
14363 : {
14364 117 : $$ = makeBitStringConst($1, @1);
14365 : }
14366 : | XCONST
14367 : {
14368 : /* This is a bit constant per SQL99:
14369 : * Without Feature F511, "BIT data type",
14370 : * a <general literal> shall not be a
14371 : * <bit string literal> or a <hex string literal>.
14372 : */
14373 32 : $$ = makeBitStringConst($1, @1);
14374 : }
14375 : | func_name Sconst
14376 : {
14377 : /* generic type 'literal' syntax */
14378 698 : TypeName *t = makeTypeNameFromNameList($1);
14379 698 : t->location = @1;
14380 698 : $$ = makeStringConstCast($2, @2, t);
14381 : }
14382 : | func_name '(' func_arg_list opt_sort_clause ')' Sconst
14383 : {
14384 : /* generic syntax with a type modifier */
14385 0 : TypeName *t = makeTypeNameFromNameList($1);
14386 : ListCell *lc;
14387 :
14388 : /*
14389 : * We must use func_arg_list and opt_sort_clause in the
14390 : * production to avoid reduce/reduce conflicts, but we
14391 : * don't actually wish to allow NamedArgExpr in this
14392 : * context, nor ORDER BY.
14393 : */
14394 0 : foreach(lc, $3)
14395 : {
14396 0 : NamedArgExpr *arg = (NamedArgExpr *) lfirst(lc);
14397 :
14398 0 : if (IsA(arg, NamedArgExpr))
14399 0 : ereport(ERROR,
14400 : (errcode(ERRCODE_SYNTAX_ERROR),
14401 : errmsg("type modifier cannot have parameter name"),
14402 : parser_errposition(arg->location)));
14403 : }
14404 0 : if ($4 != NIL)
14405 0 : ereport(ERROR,
14406 : (errcode(ERRCODE_SYNTAX_ERROR),
14407 : errmsg("type modifier cannot have ORDER BY"),
14408 : parser_errposition(@4)));
14409 :
14410 0 : t->typmods = $3;
14411 0 : t->location = @1;
14412 0 : $$ = makeStringConstCast($6, @6, t);
14413 : }
14414 : | ConstTypename Sconst
14415 : {
14416 218 : $$ = makeStringConstCast($2, @2, $1);
14417 : }
14418 : | ConstInterval Sconst opt_interval
14419 : {
14420 191 : TypeName *t = $1;
14421 191 : t->typmods = $3;
14422 191 : $$ = makeStringConstCast($2, @2, t);
14423 : }
14424 : | ConstInterval '(' Iconst ')' Sconst
14425 : {
14426 2 : TypeName *t = $1;
14427 2 : t->typmods = list_make2(makeIntConst(INTERVAL_FULL_RANGE, -1),
14428 : makeIntConst($3, @3));
14429 2 : $$ = makeStringConstCast($5, @5, t);
14430 : }
14431 : | TRUE_P
14432 : {
14433 533 : $$ = makeBoolAConst(TRUE, @1);
14434 : }
14435 : | FALSE_P
14436 : {
14437 218 : $$ = makeBoolAConst(FALSE, @1);
14438 : }
14439 : | NULL_P
14440 : {
14441 2553 : $$ = makeNullAConst(@1);
14442 : }
14443 : ;
14444 :
14445 18102 : Iconst: ICONST { $$ = $1; };
14446 25652 : Sconst: SCONST { $$ = $1; };
14447 :
14448 563 : SignedIconst: Iconst { $$ = $1; }
14449 0 : | '+' Iconst { $$ = + $2; }
14450 28 : | '-' Iconst { $$ = - $2; }
14451 : ;
14452 :
14453 : /* Role specifications */
14454 : RoleId: RoleSpec
14455 : {
14456 128 : RoleSpec *spc = (RoleSpec *) $1;
14457 128 : switch (spc->roletype)
14458 : {
14459 : case ROLESPEC_CSTRING:
14460 124 : $$ = spc->rolename;
14461 124 : break;
14462 : case ROLESPEC_PUBLIC:
14463 2 : ereport(ERROR,
14464 : (errcode(ERRCODE_RESERVED_NAME),
14465 : errmsg("role name \"%s\" is reserved",
14466 : "public"),
14467 : parser_errposition(@1)));
14468 : case ROLESPEC_SESSION_USER:
14469 1 : ereport(ERROR,
14470 : (errcode(ERRCODE_RESERVED_NAME),
14471 : errmsg("%s cannot be used as a role name here",
14472 : "SESSION_USER"),
14473 : parser_errposition(@1)));
14474 : case ROLESPEC_CURRENT_USER:
14475 1 : ereport(ERROR,
14476 : (errcode(ERRCODE_RESERVED_NAME),
14477 : errmsg("%s cannot be used as a role name here",
14478 : "CURRENT_USER"),
14479 : parser_errposition(@1)));
14480 : }
14481 : }
14482 : ;
14483 :
14484 : RoleSpec: NonReservedWord
14485 : {
14486 : /*
14487 : * "public" and "none" are not keywords, but they must
14488 : * be treated specially here.
14489 : */
14490 : RoleSpec *n;
14491 997 : if (strcmp($1, "public") == 0)
14492 : {
14493 203 : n = (RoleSpec *) makeRoleSpec(ROLESPEC_PUBLIC, @1);
14494 203 : n->roletype = ROLESPEC_PUBLIC;
14495 : }
14496 794 : else if (strcmp($1, "none") == 0)
14497 : {
14498 13 : ereport(ERROR,
14499 : (errcode(ERRCODE_RESERVED_NAME),
14500 : errmsg("role name \"%s\" is reserved",
14501 : "none"),
14502 : parser_errposition(@1)));
14503 : }
14504 : else
14505 : {
14506 781 : n = makeRoleSpec(ROLESPEC_CSTRING, @1);
14507 781 : n->rolename = pstrdup($1);
14508 : }
14509 984 : $$ = n;
14510 : }
14511 : | CURRENT_USER
14512 : {
14513 40 : $$ = makeRoleSpec(ROLESPEC_CURRENT_USER, @1);
14514 : }
14515 : | SESSION_USER
14516 : {
14517 18 : $$ = makeRoleSpec(ROLESPEC_SESSION_USER, @1);
14518 : }
14519 : ;
14520 :
14521 : role_list: RoleSpec
14522 214 : { $$ = list_make1($1); }
14523 : | role_list ',' RoleSpec
14524 28 : { $$ = lappend($1, $3); }
14525 : ;
14526 :
14527 : /*
14528 : * Name classification hierarchy.
14529 : *
14530 : * IDENT is the lexeme returned by the lexer for identifiers that match
14531 : * no known keyword. In most cases, we can accept certain keywords as
14532 : * names, not only IDENTs. We prefer to accept as many such keywords
14533 : * as possible to minimize the impact of "reserved words" on programmers.
14534 : * So, we divide names into several possible classes. The classification
14535 : * is chosen in part to make keywords acceptable as names wherever possible.
14536 : */
14537 :
14538 : /* Column identifier --- names that can be column, table, etc names.
14539 : */
14540 101861 : ColId: IDENT { $$ = $1; }
14541 1629 : | unreserved_keyword { $$ = pstrdup($1); }
14542 56 : | col_name_keyword { $$ = pstrdup($1); }
14543 : ;
14544 :
14545 : /* Type/function identifier --- names that can be type or function names.
14546 : */
14547 25024 : type_function_name: IDENT { $$ = $1; }
14548 1691 : | unreserved_keyword { $$ = pstrdup($1); }
14549 2 : | type_func_name_keyword { $$ = pstrdup($1); }
14550 : ;
14551 :
14552 : /* Any not-fully-reserved word --- these names can be, eg, role names.
14553 : */
14554 2572 : NonReservedWord: IDENT { $$ = $1; }
14555 986 : | unreserved_keyword { $$ = pstrdup($1); }
14556 8 : | col_name_keyword { $$ = pstrdup($1); }
14557 86 : | type_func_name_keyword { $$ = pstrdup($1); }
14558 : ;
14559 :
14560 : /* Column label --- allowed labels in "AS" clauses.
14561 : * This presently includes *all* Postgres keywords.
14562 : */
14563 45908 : ColLabel: IDENT { $$ = $1; }
14564 1157 : | unreserved_keyword { $$ = pstrdup($1); }
14565 11 : | col_name_keyword { $$ = pstrdup($1); }
14566 20 : | type_func_name_keyword { $$ = pstrdup($1); }
14567 103 : | reserved_keyword { $$ = pstrdup($1); }
14568 : ;
14569 :
14570 :
14571 : /*
14572 : * Keyword category lists. Generally, every keyword present in
14573 : * the Postgres grammar should appear in exactly one of these lists.
14574 : *
14575 : * Put a new keyword into the first list that it can go into without causing
14576 : * shift or reduce conflicts. The earlier lists define "less reserved"
14577 : * categories of keywords.
14578 : *
14579 : * Make sure that each keyword's category in kwlist.h matches where
14580 : * it is listed here. (Someday we may be able to generate these lists and
14581 : * kwlist.h's table from a common master list.)
14582 : */
14583 :
14584 : /* "Unreserved" keywords --- available for use as any kind of name.
14585 : */
14586 : unreserved_keyword:
14587 : ABORT_P
14588 : | ABSOLUTE_P
14589 : | ACCESS
14590 : | ACTION
14591 : | ADD_P
14592 : | ADMIN
14593 : | AFTER
14594 : | AGGREGATE
14595 : | ALSO
14596 : | ALTER
14597 : | ALWAYS
14598 : | ASSERTION
14599 : | ASSIGNMENT
14600 : | AT
14601 : | ATTACH
14602 : | ATTRIBUTE
14603 : | BACKWARD
14604 : | BEFORE
14605 : | BEGIN_P
14606 : | BY
14607 : | CACHE
14608 : | CALLED
14609 : | CASCADE
14610 : | CASCADED
14611 : | CATALOG_P
14612 : | CHAIN
14613 : | CHARACTERISTICS
14614 : | CHECKPOINT
14615 : | CLASS
14616 : | CLOSE
14617 : | CLUSTER
14618 : | COLUMNS
14619 : | COMMENT
14620 : | COMMENTS
14621 : | COMMIT
14622 : | COMMITTED
14623 : | CONFIGURATION
14624 : | CONFLICT
14625 : | CONNECTION
14626 : | CONSTRAINTS
14627 : | CONTENT_P
14628 : | CONTINUE_P
14629 : | CONVERSION_P
14630 : | COPY
14631 : | COST
14632 : | CSV
14633 : | CUBE
14634 : | CURRENT_P
14635 : | CURSOR
14636 : | CYCLE
14637 : | DATA_P
14638 : | DATABASE
14639 : | DAY_P
14640 : | DEALLOCATE
14641 : | DECLARE
14642 : | DEFAULTS
14643 : | DEFERRED
14644 : | DEFINER
14645 : | DELETE_P
14646 : | DELIMITER
14647 : | DELIMITERS
14648 : | DEPENDS
14649 : | DETACH
14650 : | DICTIONARY
14651 : | DISABLE_P
14652 : | DISCARD
14653 : | DOCUMENT_P
14654 : | DOMAIN_P
14655 : | DOUBLE_P
14656 : | DROP
14657 : | EACH
14658 : | ENABLE_P
14659 : | ENCODING
14660 : | ENCRYPTED
14661 : | ENUM_P
14662 : | ESCAPE
14663 : | EVENT
14664 : | EXCLUDE
14665 : | EXCLUDING
14666 : | EXCLUSIVE
14667 : | EXECUTE
14668 : | EXPLAIN
14669 : | EXTENSION
14670 : | EXTERNAL
14671 : | FAMILY
14672 : | FILTER
14673 : | FIRST_P
14674 : | FOLLOWING
14675 : | FORCE
14676 : | FORWARD
14677 : | FUNCTION
14678 : | FUNCTIONS
14679 : | GENERATED
14680 : | GLOBAL
14681 : | GRANTED
14682 : | HANDLER
14683 : | HEADER_P
14684 : | HOLD
14685 : | HOUR_P
14686 : | IDENTITY_P
14687 : | IF_P
14688 : | IMMEDIATE
14689 : | IMMUTABLE
14690 : | IMPLICIT_P
14691 : | IMPORT_P
14692 : | INCLUDING
14693 : | INCREMENT
14694 : | INDEX
14695 : | INDEXES
14696 : | INHERIT
14697 : | INHERITS
14698 : | INLINE_P
14699 : | INPUT_P
14700 : | INSENSITIVE
14701 : | INSERT
14702 : | INSTEAD
14703 : | INVOKER
14704 : | ISOLATION
14705 : | KEY
14706 : | LABEL
14707 : | LANGUAGE
14708 : | LARGE_P
14709 : | LAST_P
14710 : | LEAKPROOF
14711 : | LEVEL
14712 : | LISTEN
14713 : | LOAD
14714 : | LOCAL
14715 : | LOCATION
14716 : | LOCK_P
14717 : | LOCKED
14718 : | LOGGED
14719 : | MAPPING
14720 : | MATCH
14721 : | MATERIALIZED
14722 : | MAXVALUE
14723 : | METHOD
14724 : | MINUTE_P
14725 : | MINVALUE
14726 : | MODE
14727 : | MONTH_P
14728 : | MOVE
14729 : | NAME_P
14730 : | NAMES
14731 : | NEW
14732 : | NEXT
14733 : | NO
14734 : | NOTHING
14735 : | NOTIFY
14736 : | NOWAIT
14737 : | NULLS_P
14738 : | OBJECT_P
14739 : | OF
14740 : | OFF
14741 : | OIDS
14742 : | OLD
14743 : | OPERATOR
14744 : | OPTION
14745 : | OPTIONS
14746 : | ORDINALITY
14747 : | OVER
14748 : | OVERRIDING
14749 : | OWNED
14750 : | OWNER
14751 : | PARALLEL
14752 : | PARSER
14753 : | PARTIAL
14754 : | PARTITION
14755 : | PASSING
14756 : | PASSWORD
14757 : | PLANS
14758 : | POLICY
14759 : | PRECEDING
14760 : | PREPARE
14761 : | PREPARED
14762 : | PRESERVE
14763 : | PRIOR
14764 : | PRIVILEGES
14765 : | PROCEDURAL
14766 : | PROCEDURE
14767 : | PROGRAM
14768 : | PUBLICATION
14769 : | QUOTE
14770 : | RANGE
14771 : | READ
14772 : | REASSIGN
14773 : | RECHECK
14774 : | RECURSIVE
14775 : | REF
14776 : | REFERENCING
14777 : | REFRESH
14778 : | REINDEX
14779 : | RELATIVE_P
14780 : | RELEASE
14781 : | RENAME
14782 : | REPEATABLE
14783 : | REPLACE
14784 : | REPLICA
14785 : | RESET
14786 : | RESTART
14787 : | RESTRICT
14788 : | RETURNS
14789 : | REVOKE
14790 : | ROLE
14791 : | ROLLBACK
14792 : | ROLLUP
14793 : | ROWS
14794 : | RULE
14795 : | SAVEPOINT
14796 : | SCHEMA
14797 : | SCHEMAS
14798 : | SCROLL
14799 : | SEARCH
14800 : | SECOND_P
14801 : | SECURITY
14802 : | SEQUENCE
14803 : | SEQUENCES
14804 : | SERIALIZABLE
14805 : | SERVER
14806 : | SESSION
14807 : | SET
14808 : | SETS
14809 : | SHARE
14810 : | SHOW
14811 : | SIMPLE
14812 : | SKIP
14813 : | SNAPSHOT
14814 : | SQL_P
14815 : | STABLE
14816 : | STANDALONE_P
14817 : | START
14818 : | STATEMENT
14819 : | STATISTICS
14820 : | STDIN
14821 : | STDOUT
14822 : | STORAGE
14823 : | STRICT_P
14824 : | STRIP_P
14825 : | SUBSCRIPTION
14826 : | SYSID
14827 : | SYSTEM_P
14828 : | TABLES
14829 : | TABLESPACE
14830 : | TEMP
14831 : | TEMPLATE
14832 : | TEMPORARY
14833 : | TEXT_P
14834 : | TRANSACTION
14835 : | TRANSFORM
14836 : | TRIGGER
14837 : | TRUNCATE
14838 : | TRUSTED
14839 : | TYPE_P
14840 : | TYPES_P
14841 : | UNBOUNDED
14842 : | UNCOMMITTED
14843 : | UNENCRYPTED
14844 : | UNKNOWN
14845 : | UNLISTEN
14846 : | UNLOGGED
14847 : | UNTIL
14848 : | UPDATE
14849 : | VACUUM
14850 : | VALID
14851 : | VALIDATE
14852 : | VALIDATOR
14853 : | VALUE_P
14854 : | VARYING
14855 : | VERSION_P
14856 : | VIEW
14857 : | VIEWS
14858 : | VOLATILE
14859 : | WHITESPACE_P
14860 : | WITHIN
14861 : | WITHOUT
14862 : | WORK
14863 : | WRAPPER
14864 : | WRITE
14865 : | XML_P
14866 : | YEAR_P
14867 : | YES_P
14868 : | ZONE
14869 : ;
14870 :
14871 : /* Column identifier --- keywords that can be column, table, etc names.
14872 : *
14873 : * Many of these keywords will in fact be recognized as type or function
14874 : * names too; but they have special productions for the purpose, and so
14875 : * can't be treated as "generic" type or function names.
14876 : *
14877 : * The type names appearing here are not usable as function names
14878 : * because they can be followed by '(' in typename productions, which
14879 : * looks too much like a function call for an LR(1) parser.
14880 : */
14881 : col_name_keyword:
14882 : BETWEEN
14883 : | BIGINT
14884 : | BIT
14885 : | BOOLEAN_P
14886 : | CHAR_P
14887 : | CHARACTER
14888 : | COALESCE
14889 : | DEC
14890 : | DECIMAL_P
14891 : | EXISTS
14892 : | EXTRACT
14893 : | FLOAT_P
14894 : | GREATEST
14895 : | GROUPING
14896 : | INOUT
14897 : | INT_P
14898 : | INTEGER
14899 : | INTERVAL
14900 : | LEAST
14901 : | NATIONAL
14902 : | NCHAR
14903 : | NONE
14904 : | NULLIF
14905 : | NUMERIC
14906 : | OUT_P
14907 : | OVERLAY
14908 : | POSITION
14909 : | PRECISION
14910 : | REAL
14911 : | ROW
14912 : | SETOF
14913 : | SMALLINT
14914 : | SUBSTRING
14915 : | TIME
14916 : | TIMESTAMP
14917 : | TREAT
14918 : | TRIM
14919 : | VALUES
14920 : | VARCHAR
14921 : | XMLATTRIBUTES
14922 : | XMLCONCAT
14923 : | XMLELEMENT
14924 : | XMLEXISTS
14925 : | XMLFOREST
14926 : | XMLNAMESPACES
14927 : | XMLPARSE
14928 : | XMLPI
14929 : | XMLROOT
14930 : | XMLSERIALIZE
14931 : | XMLTABLE
14932 : ;
14933 :
14934 : /* Type/function identifier --- keywords that can be type or function names.
14935 : *
14936 : * Most of these are keywords that are used as operators in expressions;
14937 : * in general such keywords can't be column names because they would be
14938 : * ambiguous with variables, but they are unambiguous as function identifiers.
14939 : *
14940 : * Do not include POSITION, SUBSTRING, etc here since they have explicit
14941 : * productions in a_expr to support the goofy SQL9x argument syntax.
14942 : * - thomas 2000-11-28
14943 : */
14944 : type_func_name_keyword:
14945 : AUTHORIZATION
14946 : | BINARY
14947 : | COLLATION
14948 : | CONCURRENTLY
14949 : | CROSS
14950 : | CURRENT_SCHEMA
14951 : | FREEZE
14952 : | FULL
14953 : | ILIKE
14954 : | INNER_P
14955 : | IS
14956 : | ISNULL
14957 : | JOIN
14958 : | LEFT
14959 : | LIKE
14960 : | NATURAL
14961 : | NOTNULL
14962 : | OUTER_P
14963 : | OVERLAPS
14964 : | RIGHT
14965 : | SIMILAR
14966 : | TABLESAMPLE
14967 : | VERBOSE
14968 : ;
14969 :
14970 : /* Reserved keyword --- these keywords are usable only as a ColLabel.
14971 : *
14972 : * Keywords appear here if they could not be distinguished from variable,
14973 : * type, or function names in some contexts. Don't put things here unless
14974 : * forced to.
14975 : */
14976 : reserved_keyword:
14977 : ALL
14978 : | ANALYSE
14979 : | ANALYZE
14980 : | AND
14981 : | ANY
14982 : | ARRAY
14983 : | AS
14984 : | ASC
14985 : | ASYMMETRIC
14986 : | BOTH
14987 : | CASE
14988 : | CAST
14989 : | CHECK
14990 : | COLLATE
14991 : | COLUMN
14992 : | CONSTRAINT
14993 : | CREATE
14994 : | CURRENT_CATALOG
14995 : | CURRENT_DATE
14996 : | CURRENT_ROLE
14997 : | CURRENT_TIME
14998 : | CURRENT_TIMESTAMP
14999 : | CURRENT_USER
15000 : | DEFAULT
15001 : | DEFERRABLE
15002 : | DESC
15003 : | DISTINCT
15004 : | DO
15005 : | ELSE
15006 : | END_P
15007 : | EXCEPT
15008 : | FALSE_P
15009 : | FETCH
15010 : | FOR
15011 : | FOREIGN
15012 : | FROM
15013 : | GRANT
15014 : | GROUP_P
15015 : | HAVING
15016 : | IN_P
15017 : | INITIALLY
15018 : | INTERSECT
15019 : | INTO
15020 : | LATERAL_P
15021 : | LEADING
15022 : | LIMIT
15023 : | LOCALTIME
15024 : | LOCALTIMESTAMP
15025 : | NOT
15026 : | NULL_P
15027 : | OFFSET
15028 : | ON
15029 : | ONLY
15030 : | OR
15031 : | ORDER
15032 : | PLACING
15033 : | PRIMARY
15034 : | REFERENCES
15035 : | RETURNING
15036 : | SELECT
15037 : | SESSION_USER
15038 : | SOME
15039 : | SYMMETRIC
15040 : | TABLE
15041 : | THEN
15042 : | TO
15043 : | TRAILING
15044 : | TRUE_P
15045 : | UNION
15046 : | UNIQUE
15047 : | USER
15048 : | USING
15049 : | VARIADIC
15050 : | WHEN
15051 : | WHERE
15052 : | WINDOW
15053 : | WITH
15054 : ;
15055 :
15056 : %%
15057 :
15058 : /*
15059 : * The signature of this function is required by bison. However, we
15060 : * ignore the passed yylloc and instead use the last token position
15061 : * available from the scanner.
15062 : */
15063 : static void
15064 99 : base_yyerror(YYLTYPE *yylloc, core_yyscan_t yyscanner, const char *msg)
15065 : {
15066 99 : parser_yyerror(msg);
15067 : }
15068 :
15069 : static RawStmt *
15070 38108 : makeRawStmt(Node *stmt, int stmt_location)
15071 : {
15072 38108 : RawStmt *rs = makeNode(RawStmt);
15073 :
15074 38108 : rs->stmt = stmt;
15075 38108 : rs->stmt_location = stmt_location;
15076 38108 : rs->stmt_len = 0; /* might get changed later */
15077 38108 : return rs;
15078 : }
15079 :
15080 : /* Adjust a RawStmt to reflect that it doesn't run to the end of the string */
15081 : static void
15082 27579 : updateRawStmtEnd(RawStmt *rs, int end_location)
15083 : {
15084 : /*
15085 : * If we already set the length, don't change it. This is for situations
15086 : * like "select foo ;; select bar" where the same statement will be last
15087 : * in the string for more than one semicolon.
15088 : */
15089 27579 : if (rs->stmt_len > 0)
15090 27579 : return;
15091 :
15092 : /* OK, update length of RawStmt */
15093 27579 : rs->stmt_len = end_location - rs->stmt_location;
15094 : }
15095 :
15096 : static Node *
15097 51209 : makeColumnRef(char *colname, List *indirection,
15098 : int location, core_yyscan_t yyscanner)
15099 : {
15100 : /*
15101 : * Generate a ColumnRef node, with an A_Indirection node added if there
15102 : * is any subscripting in the specified indirection list. However,
15103 : * any field selection at the start of the indirection list must be
15104 : * transposed into the "fields" part of the ColumnRef node.
15105 : */
15106 51209 : ColumnRef *c = makeNode(ColumnRef);
15107 51209 : int nfields = 0;
15108 : ListCell *l;
15109 :
15110 51209 : c->location = location;
15111 79649 : foreach(l, indirection)
15112 : {
15113 28743 : if (IsA(lfirst(l), A_Indices))
15114 : {
15115 303 : A_Indirection *i = makeNode(A_Indirection);
15116 :
15117 303 : if (nfields == 0)
15118 : {
15119 : /* easy case - all indirection goes to A_Indirection */
15120 163 : c->fields = list_make1(makeString(colname));
15121 163 : i->indirection = check_indirection(indirection, yyscanner);
15122 : }
15123 : else
15124 : {
15125 : /* got to split the list in two */
15126 140 : i->indirection = check_indirection(list_copy_tail(indirection,
15127 : nfields),
15128 : yyscanner);
15129 140 : indirection = list_truncate(indirection, nfields);
15130 140 : c->fields = lcons(makeString(colname), indirection);
15131 : }
15132 303 : i->arg = (Node *) c;
15133 303 : return (Node *) i;
15134 : }
15135 28440 : else if (IsA(lfirst(l), A_Star))
15136 : {
15137 : /* We only allow '*' at the end of a ColumnRef */
15138 379 : if (lnext(l) != NULL)
15139 0 : parser_yyerror("improper use of \"*\"");
15140 : }
15141 28440 : nfields++;
15142 : }
15143 : /* No subscripting, so all indirection gets added to field list */
15144 50906 : c->fields = lcons(makeString(colname), indirection);
15145 50906 : return (Node *) c;
15146 : }
15147 :
15148 : static Node *
15149 10116 : makeTypeCast(Node *arg, TypeName *typename, int location)
15150 : {
15151 10116 : TypeCast *n = makeNode(TypeCast);
15152 10116 : n->arg = arg;
15153 10116 : n->typeName = typename;
15154 10116 : n->location = location;
15155 10116 : return (Node *) n;
15156 : }
15157 :
15158 : static Node *
15159 24133 : makeStringConst(char *str, int location)
15160 : {
15161 24133 : A_Const *n = makeNode(A_Const);
15162 :
15163 24133 : n->val.type = T_String;
15164 24133 : n->val.val.str = str;
15165 24133 : n->location = location;
15166 :
15167 24133 : return (Node *)n;
15168 : }
15169 :
15170 : static Node *
15171 1109 : makeStringConstCast(char *str, int location, TypeName *typename)
15172 : {
15173 1109 : Node *s = makeStringConst(str, location);
15174 :
15175 1109 : return makeTypeCast(s, typename, -1);
15176 : }
15177 :
15178 : static Node *
15179 18141 : makeIntConst(int val, int location)
15180 : {
15181 18141 : A_Const *n = makeNode(A_Const);
15182 :
15183 18141 : n->val.type = T_Integer;
15184 18141 : n->val.val.ival = val;
15185 18141 : n->location = location;
15186 :
15187 18141 : return (Node *)n;
15188 : }
15189 :
15190 : static Node *
15191 828 : makeFloatConst(char *str, int location)
15192 : {
15193 828 : A_Const *n = makeNode(A_Const);
15194 :
15195 828 : n->val.type = T_Float;
15196 828 : n->val.val.str = str;
15197 828 : n->location = location;
15198 :
15199 828 : return (Node *)n;
15200 : }
15201 :
15202 : static Node *
15203 149 : makeBitStringConst(char *str, int location)
15204 : {
15205 149 : A_Const *n = makeNode(A_Const);
15206 :
15207 149 : n->val.type = T_BitString;
15208 149 : n->val.val.str = str;
15209 149 : n->location = location;
15210 :
15211 149 : return (Node *)n;
15212 : }
15213 :
15214 : static Node *
15215 2568 : makeNullAConst(int location)
15216 : {
15217 2568 : A_Const *n = makeNode(A_Const);
15218 :
15219 2568 : n->val.type = T_Null;
15220 2568 : n->location = location;
15221 :
15222 2568 : return (Node *)n;
15223 : }
15224 :
15225 : static Node *
15226 362 : makeAConst(Value *v, int location)
15227 : {
15228 : Node *n;
15229 :
15230 362 : switch (v->type)
15231 : {
15232 : case T_Float:
15233 3 : n = makeFloatConst(v->val.str, location);
15234 3 : break;
15235 :
15236 : case T_Integer:
15237 359 : n = makeIntConst(v->val.ival, location);
15238 359 : break;
15239 :
15240 : case T_String:
15241 : default:
15242 0 : n = makeStringConst(v->val.str, location);
15243 0 : break;
15244 : }
15245 :
15246 362 : return n;
15247 : }
15248 :
15249 : /* makeBoolAConst()
15250 : * Create an A_Const string node and put it inside a boolean cast.
15251 : */
15252 : static Node *
15253 774 : makeBoolAConst(bool state, int location)
15254 : {
15255 774 : A_Const *n = makeNode(A_Const);
15256 :
15257 774 : n->val.type = T_String;
15258 774 : n->val.val.str = (state ? "t" : "f");
15259 774 : n->location = location;
15260 :
15261 774 : return makeTypeCast((Node *)n, SystemTypeName("bool"), -1);
15262 : }
15263 :
15264 : /* makeRoleSpec
15265 : * Create a RoleSpec with the given type
15266 : */
15267 : static RoleSpec *
15268 1119 : makeRoleSpec(RoleSpecType type, int location)
15269 : {
15270 1119 : RoleSpec *spec = makeNode(RoleSpec);
15271 :
15272 1119 : spec->roletype = type;
15273 1119 : spec->location = location;
15274 :
15275 1119 : return spec;
15276 : }
15277 :
15278 : /* check_qualified_name --- check the result of qualified_name production
15279 : *
15280 : * It's easiest to let the grammar production for qualified_name allow
15281 : * subscripts and '*', which we then must reject here.
15282 : */
15283 : static void
15284 6031 : check_qualified_name(List *names, core_yyscan_t yyscanner)
15285 : {
15286 : ListCell *i;
15287 :
15288 12062 : foreach(i, names)
15289 : {
15290 6031 : if (!IsA(lfirst(i), String))
15291 0 : parser_yyerror("syntax error");
15292 : }
15293 6031 : }
15294 :
15295 : /* check_func_name --- check the result of func_name production
15296 : *
15297 : * It's easiest to let the grammar production for func_name allow subscripts
15298 : * and '*', which we then must reject here.
15299 : */
15300 : static List *
15301 3768 : check_func_name(List *names, core_yyscan_t yyscanner)
15302 : {
15303 : ListCell *i;
15304 :
15305 11304 : foreach(i, names)
15306 : {
15307 7536 : if (!IsA(lfirst(i), String))
15308 0 : parser_yyerror("syntax error");
15309 : }
15310 3768 : return names;
15311 : }
15312 :
15313 : /* check_indirection --- check the result of indirection production
15314 : *
15315 : * We only allow '*' at the end of the list, but it's hard to enforce that
15316 : * in the grammar, so do it here.
15317 : */
15318 : static List *
15319 2624 : check_indirection(List *indirection, core_yyscan_t yyscanner)
15320 : {
15321 : ListCell *l;
15322 :
15323 3346 : foreach(l, indirection)
15324 : {
15325 722 : if (IsA(lfirst(l), A_Star))
15326 : {
15327 22 : if (lnext(l) != NULL)
15328 0 : parser_yyerror("improper use of \"*\"");
15329 : }
15330 : }
15331 2624 : return indirection;
15332 : }
15333 :
15334 : /* extractArgTypes()
15335 : * Given a list of FunctionParameter nodes, extract a list of just the
15336 : * argument types (TypeNames) for input parameters only. This is what
15337 : * is needed to look up an existing function, which is what is wanted by
15338 : * the productions that use this call.
15339 : */
15340 : static List *
15341 518 : extractArgTypes(List *parameters)
15342 : {
15343 518 : List *result = NIL;
15344 : ListCell *i;
15345 :
15346 1531 : foreach(i, parameters)
15347 : {
15348 1013 : FunctionParameter *p = (FunctionParameter *) lfirst(i);
15349 :
15350 1013 : if (p->mode != FUNC_PARAM_OUT && p->mode != FUNC_PARAM_TABLE)
15351 1011 : result = lappend(result, p->argType);
15352 : }
15353 518 : return result;
15354 : }
15355 :
15356 : /* extractAggrArgTypes()
15357 : * As above, but work from the output of the aggr_args production.
15358 : */
15359 : static List *
15360 44 : extractAggrArgTypes(List *aggrargs)
15361 : {
15362 44 : Assert(list_length(aggrargs) == 2);
15363 44 : return extractArgTypes((List *) linitial(aggrargs));
15364 : }
15365 :
15366 : /* makeOrderedSetArgs()
15367 : * Build the result of the aggr_args production (which see the comments for).
15368 : * This handles only the case where both given lists are nonempty, so that
15369 : * we have to deal with multiple VARIADIC arguments.
15370 : */
15371 : static List *
15372 4 : makeOrderedSetArgs(List *directargs, List *orderedargs,
15373 : core_yyscan_t yyscanner)
15374 : {
15375 4 : FunctionParameter *lastd = (FunctionParameter *) llast(directargs);
15376 : int ndirectargs;
15377 :
15378 : /* No restriction unless last direct arg is VARIADIC */
15379 4 : if (lastd->mode == FUNC_PARAM_VARIADIC)
15380 : {
15381 2 : FunctionParameter *firsto = (FunctionParameter *) linitial(orderedargs);
15382 :
15383 : /*
15384 : * We ignore the names, though the aggr_arg production allows them;
15385 : * it doesn't allow default values, so those need not be checked.
15386 : */
15387 4 : if (list_length(orderedargs) != 1 ||
15388 4 : firsto->mode != FUNC_PARAM_VARIADIC ||
15389 2 : !equal(lastd->argType, firsto->argType))
15390 0 : ereport(ERROR,
15391 : (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
15392 : errmsg("an ordered-set aggregate with a VARIADIC direct argument must have one VARIADIC aggregated argument of the same data type"),
15393 : parser_errposition(exprLocation((Node *) firsto))));
15394 :
15395 : /* OK, drop the duplicate VARIADIC argument from the internal form */
15396 2 : orderedargs = NIL;
15397 : }
15398 :
15399 : /* don't merge into the next line, as list_concat changes directargs */
15400 4 : ndirectargs = list_length(directargs);
15401 :
15402 4 : return list_make2(list_concat(directargs, orderedargs),
15403 : makeInteger(ndirectargs));
15404 : }
15405 :
15406 : /* insertSelectOptions()
15407 : * Insert ORDER BY, etc into an already-constructed SelectStmt.
15408 : *
15409 : * This routine is just to avoid duplicating code in SelectStmt productions.
15410 : */
15411 : static void
15412 3215 : insertSelectOptions(SelectStmt *stmt,
15413 : List *sortClause, List *lockingClause,
15414 : Node *limitOffset, Node *limitCount,
15415 : WithClause *withClause,
15416 : core_yyscan_t yyscanner)
15417 : {
15418 3215 : Assert(IsA(stmt, SelectStmt));
15419 :
15420 : /*
15421 : * Tests here are to reject constructs like
15422 : * (SELECT foo ORDER BY bar) ORDER BY baz
15423 : */
15424 3215 : if (sortClause)
15425 : {
15426 2840 : if (stmt->sortClause)
15427 0 : ereport(ERROR,
15428 : (errcode(ERRCODE_SYNTAX_ERROR),
15429 : errmsg("multiple ORDER BY clauses not allowed"),
15430 : parser_errposition(exprLocation((Node *) sortClause))));
15431 2840 : stmt->sortClause = sortClause;
15432 : }
15433 : /* We can handle multiple locking clauses, though */
15434 3215 : stmt->lockingClause = list_concat(stmt->lockingClause, lockingClause);
15435 3215 : if (limitOffset)
15436 : {
15437 46 : if (stmt->limitOffset)
15438 0 : ereport(ERROR,
15439 : (errcode(ERRCODE_SYNTAX_ERROR),
15440 : errmsg("multiple OFFSET clauses not allowed"),
15441 : parser_errposition(exprLocation(limitOffset))));
15442 46 : stmt->limitOffset = limitOffset;
15443 : }
15444 3215 : if (limitCount)
15445 : {
15446 197 : if (stmt->limitCount)
15447 0 : ereport(ERROR,
15448 : (errcode(ERRCODE_SYNTAX_ERROR),
15449 : errmsg("multiple LIMIT clauses not allowed"),
15450 : parser_errposition(exprLocation(limitCount))));
15451 197 : stmt->limitCount = limitCount;
15452 : }
15453 3215 : if (withClause)
15454 : {
15455 121 : if (stmt->withClause)
15456 0 : ereport(ERROR,
15457 : (errcode(ERRCODE_SYNTAX_ERROR),
15458 : errmsg("multiple WITH clauses not allowed"),
15459 : parser_errposition(exprLocation((Node *) withClause))));
15460 121 : stmt->withClause = withClause;
15461 : }
15462 3215 : }
15463 :
15464 : static Node *
15465 498 : makeSetOp(SetOperation op, bool all, Node *larg, Node *rarg)
15466 : {
15467 498 : SelectStmt *n = makeNode(SelectStmt);
15468 :
15469 498 : n->op = op;
15470 498 : n->all = all;
15471 498 : n->larg = (SelectStmt *) larg;
15472 498 : n->rarg = (SelectStmt *) rarg;
15473 498 : return (Node *) n;
15474 : }
15475 :
15476 : /* SystemFuncName()
15477 : * Build a properly-qualified reference to a built-in function.
15478 : */
15479 : List *
15480 1081 : SystemFuncName(char *name)
15481 : {
15482 1081 : return list_make2(makeString("pg_catalog"), makeString(name));
15483 : }
15484 :
15485 : /* SystemTypeName()
15486 : * Build a properly-qualified reference to a built-in type.
15487 : *
15488 : * typmod is defaulted, but may be changed afterwards by caller.
15489 : * Likewise for the location.
15490 : */
15491 : TypeName *
15492 5877 : SystemTypeName(char *name)
15493 : {
15494 5877 : return makeTypeNameFromNameList(list_make2(makeString("pg_catalog"),
15495 : makeString(name)));
15496 : }
15497 :
15498 : /* doNegate()
15499 : * Handle negation of a numeric constant.
15500 : *
15501 : * Formerly, we did this here because the optimizer couldn't cope with
15502 : * indexquals that looked like "var = -4" --- it wants "var = const"
15503 : * and a unary minus operator applied to a constant didn't qualify.
15504 : * As of Postgres 7.0, that problem doesn't exist anymore because there
15505 : * is a constant-subexpression simplifier in the optimizer. However,
15506 : * there's still a good reason for doing this here, which is that we can
15507 : * postpone committing to a particular internal representation for simple
15508 : * negative constants. It's better to leave "-123.456" in string form
15509 : * until we know what the desired type is.
15510 : */
15511 : static Node *
15512 585 : doNegate(Node *n, int location)
15513 : {
15514 585 : if (IsA(n, A_Const))
15515 : {
15516 521 : A_Const *con = (A_Const *)n;
15517 :
15518 : /* report the constant's location as that of the '-' sign */
15519 521 : con->location = location;
15520 :
15521 521 : if (con->val.type == T_Integer)
15522 : {
15523 460 : con->val.val.ival = -con->val.val.ival;
15524 460 : return n;
15525 : }
15526 61 : if (con->val.type == T_Float)
15527 : {
15528 61 : doNegateFloat(&con->val);
15529 61 : return n;
15530 : }
15531 : }
15532 :
15533 64 : return (Node *) makeSimpleA_Expr(AEXPR_OP, "-", NULL, n, location);
15534 : }
15535 :
15536 : static void
15537 61 : doNegateFloat(Value *v)
15538 : {
15539 61 : char *oldval = v->val.str;
15540 :
15541 61 : Assert(IsA(v, Float));
15542 61 : if (*oldval == '+')
15543 0 : oldval++;
15544 61 : if (*oldval == '-')
15545 0 : v->val.str = oldval+1; /* just strip the '-' */
15546 : else
15547 61 : v->val.str = psprintf("-%s", oldval);
15548 61 : }
15549 :
15550 : static Node *
15551 5739 : makeAndExpr(Node *lexpr, Node *rexpr, int location)
15552 : {
15553 5739 : Node *lexp = lexpr;
15554 :
15555 : /* Look through AEXPR_PAREN nodes so they don't affect flattening */
15556 14794 : while (IsA(lexp, A_Expr) &&
15557 3316 : ((A_Expr *) lexp)->kind == AEXPR_PAREN)
15558 0 : lexp = ((A_Expr *) lexp)->lexpr;
15559 : /* Flatten "a AND b AND c ..." to a single BoolExpr on sight */
15560 5739 : if (IsA(lexp, BoolExpr))
15561 : {
15562 2118 : BoolExpr *blexpr = (BoolExpr *) lexp;
15563 :
15564 2118 : if (blexpr->boolop == AND_EXPR)
15565 : {
15566 2077 : blexpr->args = lappend(blexpr->args, rexpr);
15567 2077 : return (Node *) blexpr;
15568 : }
15569 : }
15570 3662 : return (Node *) makeBoolExpr(AND_EXPR, list_make2(lexpr, rexpr), location);
15571 : }
15572 :
15573 : static Node *
15574 436 : makeOrExpr(Node *lexpr, Node *rexpr, int location)
15575 : {
15576 436 : Node *lexp = lexpr;
15577 :
15578 : /* Look through AEXPR_PAREN nodes so they don't affect flattening */
15579 1013 : while (IsA(lexp, A_Expr) &&
15580 141 : ((A_Expr *) lexp)->kind == AEXPR_PAREN)
15581 0 : lexp = ((A_Expr *) lexp)->lexpr;
15582 : /* Flatten "a OR b OR c ..." to a single BoolExpr on sight */
15583 436 : if (IsA(lexp, BoolExpr))
15584 : {
15585 220 : BoolExpr *blexpr = (BoolExpr *) lexp;
15586 :
15587 220 : if (blexpr->boolop == OR_EXPR)
15588 : {
15589 188 : blexpr->args = lappend(blexpr->args, rexpr);
15590 188 : return (Node *) blexpr;
15591 : }
15592 : }
15593 248 : return (Node *) makeBoolExpr(OR_EXPR, list_make2(lexpr, rexpr), location);
15594 : }
15595 :
15596 : static Node *
15597 906 : makeNotExpr(Node *expr, int location)
15598 : {
15599 906 : return (Node *) makeBoolExpr(NOT_EXPR, list_make1(expr), location);
15600 : }
15601 :
15602 : static Node *
15603 578 : makeAArrayExpr(List *elements, int location)
15604 : {
15605 578 : A_ArrayExpr *n = makeNode(A_ArrayExpr);
15606 :
15607 578 : n->elements = elements;
15608 578 : n->location = location;
15609 578 : return (Node *) n;
15610 : }
15611 :
15612 : static Node *
15613 125 : makeSQLValueFunction(SQLValueFunctionOp op, int32 typmod, int location)
15614 : {
15615 125 : SQLValueFunction *svf = makeNode(SQLValueFunction);
15616 :
15617 125 : svf->op = op;
15618 : /* svf->type will be filled during parse analysis */
15619 125 : svf->typmod = typmod;
15620 125 : svf->location = location;
15621 125 : return (Node *) svf;
15622 : }
15623 :
15624 : static Node *
15625 95 : makeXmlExpr(XmlExprOp op, char *name, List *named_args, List *args,
15626 : int location)
15627 : {
15628 95 : XmlExpr *x = makeNode(XmlExpr);
15629 :
15630 95 : x->op = op;
15631 95 : x->name = name;
15632 : /*
15633 : * named_args is a list of ResTarget; it'll be split apart into separate
15634 : * expression and name lists in transformXmlExpr().
15635 : */
15636 95 : x->named_args = named_args;
15637 95 : x->arg_names = NIL;
15638 95 : x->args = args;
15639 : /* xmloption, if relevant, must be filled in by caller */
15640 : /* type and typmod will be filled in during parse analysis */
15641 95 : x->type = InvalidOid; /* marks the node as not analyzed */
15642 95 : x->location = location;
15643 95 : return (Node *) x;
15644 : }
15645 :
15646 : /*
15647 : * Merge the input and output parameters of a table function.
15648 : */
15649 : static List *
15650 17 : mergeTableFuncParameters(List *func_args, List *columns)
15651 : {
15652 : ListCell *lc;
15653 :
15654 : /* Explicit OUT and INOUT parameters shouldn't be used in this syntax */
15655 35 : foreach(lc, func_args)
15656 : {
15657 18 : FunctionParameter *p = (FunctionParameter *) lfirst(lc);
15658 :
15659 18 : if (p->mode != FUNC_PARAM_IN && p->mode != FUNC_PARAM_VARIADIC)
15660 0 : ereport(ERROR,
15661 : (errcode(ERRCODE_SYNTAX_ERROR),
15662 : errmsg("OUT and INOUT arguments aren't allowed in TABLE functions")));
15663 : }
15664 :
15665 17 : return list_concat(func_args, columns);
15666 : }
15667 :
15668 : /*
15669 : * Determine return type of a TABLE function. A single result column
15670 : * returns setof that column's type; otherwise return setof record.
15671 : */
15672 : static TypeName *
15673 17 : TableFuncTypeName(List *columns)
15674 : {
15675 : TypeName *result;
15676 :
15677 17 : if (list_length(columns) == 1)
15678 : {
15679 7 : FunctionParameter *p = (FunctionParameter *) linitial(columns);
15680 :
15681 7 : result = copyObject(p->argType);
15682 : }
15683 : else
15684 10 : result = SystemTypeName("record");
15685 :
15686 17 : result->setof = true;
15687 :
15688 17 : return result;
15689 : }
15690 :
15691 : /*
15692 : * Convert a list of (dotted) names to a RangeVar (like
15693 : * makeRangeVarFromNameList, but with position support). The
15694 : * "AnyName" refers to the any_name production in the grammar.
15695 : */
15696 : static RangeVar *
15697 79 : makeRangeVarFromAnyName(List *names, int position, core_yyscan_t yyscanner)
15698 : {
15699 79 : RangeVar *r = makeNode(RangeVar);
15700 :
15701 79 : switch (list_length(names))
15702 : {
15703 : case 1:
15704 76 : r->catalogname = NULL;
15705 76 : r->schemaname = NULL;
15706 76 : r->relname = strVal(linitial(names));
15707 76 : break;
15708 : case 2:
15709 3 : r->catalogname = NULL;
15710 3 : r->schemaname = strVal(linitial(names));
15711 3 : r->relname = strVal(lsecond(names));
15712 3 : break;
15713 : case 3:
15714 0 : r->catalogname = strVal(linitial(names));
15715 0 : r->schemaname = strVal(lsecond(names));
15716 0 : r->relname = strVal(lthird(names));
15717 0 : break;
15718 : default:
15719 0 : ereport(ERROR,
15720 : (errcode(ERRCODE_SYNTAX_ERROR),
15721 : errmsg("improper qualified name (too many dotted names): %s",
15722 : NameListToString(names)),
15723 : parser_errposition(position)));
15724 : break;
15725 : }
15726 :
15727 79 : r->relpersistence = RELPERSISTENCE_PERMANENT;
15728 79 : r->location = position;
15729 :
15730 79 : return r;
15731 : }
15732 :
15733 : /* Separate Constraint nodes from COLLATE clauses in a ColQualList */
15734 : static void
15735 2656 : SplitColQualList(List *qualList,
15736 : List **constraintList, CollateClause **collClause,
15737 : core_yyscan_t yyscanner)
15738 : {
15739 : ListCell *cell;
15740 : ListCell *prev;
15741 : ListCell *next;
15742 :
15743 2656 : *collClause = NULL;
15744 2656 : prev = NULL;
15745 3256 : for (cell = list_head(qualList); cell; cell = next)
15746 : {
15747 600 : Node *n = (Node *) lfirst(cell);
15748 :
15749 600 : next = lnext(cell);
15750 600 : if (IsA(n, Constraint))
15751 : {
15752 : /* keep it in list */
15753 583 : prev = cell;
15754 583 : continue;
15755 : }
15756 17 : if (IsA(n, CollateClause))
15757 : {
15758 17 : CollateClause *c = (CollateClause *) n;
15759 :
15760 17 : if (*collClause)
15761 0 : ereport(ERROR,
15762 : (errcode(ERRCODE_SYNTAX_ERROR),
15763 : errmsg("multiple COLLATE clauses not allowed"),
15764 : parser_errposition(c->location)));
15765 17 : *collClause = c;
15766 : }
15767 : else
15768 0 : elog(ERROR, "unexpected node type %d", (int) n->type);
15769 : /* remove non-Constraint nodes from qualList */
15770 17 : qualList = list_delete_cell(qualList, cell, prev);
15771 : }
15772 2656 : *constraintList = qualList;
15773 2656 : }
15774 :
15775 : /*
15776 : * Process result of ConstraintAttributeSpec, and set appropriate bool flags
15777 : * in the output command node. Pass NULL for any flags the particular
15778 : * command doesn't support.
15779 : */
15780 : static void
15781 335 : processCASbits(int cas_bits, int location, const char *constrType,
15782 : bool *deferrable, bool *initdeferred, bool *not_valid,
15783 : bool *no_inherit, core_yyscan_t yyscanner)
15784 : {
15785 : /* defaults */
15786 335 : if (deferrable)
15787 214 : *deferrable = false;
15788 335 : if (initdeferred)
15789 214 : *initdeferred = false;
15790 335 : if (not_valid)
15791 206 : *not_valid = false;
15792 :
15793 335 : if (cas_bits & (CAS_DEFERRABLE | CAS_INITIALLY_DEFERRED))
15794 : {
15795 11 : if (deferrable)
15796 11 : *deferrable = true;
15797 : else
15798 0 : ereport(ERROR,
15799 : (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
15800 : /* translator: %s is CHECK, UNIQUE, or similar */
15801 : errmsg("%s constraints cannot be marked DEFERRABLE",
15802 : constrType),
15803 : parser_errposition(location)));
15804 : }
15805 :
15806 335 : if (cas_bits & CAS_INITIALLY_DEFERRED)
15807 : {
15808 5 : if (initdeferred)
15809 5 : *initdeferred = true;
15810 : else
15811 0 : ereport(ERROR,
15812 : (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
15813 : /* translator: %s is CHECK, UNIQUE, or similar */
15814 : errmsg("%s constraints cannot be marked DEFERRABLE",
15815 : constrType),
15816 : parser_errposition(location)));
15817 : }
15818 :
15819 335 : if (cas_bits & CAS_NOT_VALID)
15820 : {
15821 16 : if (not_valid)
15822 16 : *not_valid = true;
15823 : else
15824 0 : ereport(ERROR,
15825 : (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
15826 : /* translator: %s is CHECK, UNIQUE, or similar */
15827 : errmsg("%s constraints cannot be marked NOT VALID",
15828 : constrType),
15829 : parser_errposition(location)));
15830 : }
15831 :
15832 335 : if (cas_bits & CAS_NO_INHERIT)
15833 : {
15834 14 : if (no_inherit)
15835 14 : *no_inherit = true;
15836 : else
15837 0 : ereport(ERROR,
15838 : (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
15839 : /* translator: %s is CHECK, UNIQUE, or similar */
15840 : errmsg("%s constraints cannot be marked NO INHERIT",
15841 : constrType),
15842 : parser_errposition(location)));
15843 : }
15844 335 : }
15845 :
15846 : /*----------
15847 : * Recursive view transformation
15848 : *
15849 : * Convert
15850 : *
15851 : * CREATE RECURSIVE VIEW relname (aliases) AS query
15852 : *
15853 : * to
15854 : *
15855 : * CREATE VIEW relname (aliases) AS
15856 : * WITH RECURSIVE relname (aliases) AS (query)
15857 : * SELECT aliases FROM relname
15858 : *
15859 : * Actually, just the WITH ... part, which is then inserted into the original
15860 : * view definition as the query.
15861 : * ----------
15862 : */
15863 : static Node *
15864 2 : makeRecursiveViewSelect(char *relname, List *aliases, Node *query)
15865 : {
15866 2 : SelectStmt *s = makeNode(SelectStmt);
15867 2 : WithClause *w = makeNode(WithClause);
15868 2 : CommonTableExpr *cte = makeNode(CommonTableExpr);
15869 2 : List *tl = NIL;
15870 : ListCell *lc;
15871 :
15872 : /* create common table expression */
15873 2 : cte->ctename = relname;
15874 2 : cte->aliascolnames = aliases;
15875 2 : cte->ctequery = query;
15876 2 : cte->location = -1;
15877 :
15878 : /* create WITH clause and attach CTE */
15879 2 : w->recursive = true;
15880 2 : w->ctes = list_make1(cte);
15881 2 : w->location = -1;
15882 :
15883 : /* create target list for the new SELECT from the alias list of the
15884 : * recursive view specification */
15885 4 : foreach (lc, aliases)
15886 : {
15887 2 : ResTarget *rt = makeNode(ResTarget);
15888 :
15889 2 : rt->name = NULL;
15890 2 : rt->indirection = NIL;
15891 2 : rt->val = makeColumnRef(strVal(lfirst(lc)), NIL, -1, 0);
15892 2 : rt->location = -1;
15893 :
15894 2 : tl = lappend(tl, rt);
15895 : }
15896 :
15897 : /* create new SELECT combining WITH clause, target list, and fake FROM
15898 : * clause */
15899 2 : s->withClause = w;
15900 2 : s->targetList = tl;
15901 2 : s->fromClause = list_make1(makeRangeVar(NULL, relname, -1));
15902 :
15903 2 : return (Node *) s;
15904 : }
15905 :
15906 : /* parser_init()
15907 : * Initialize to parse one query string
15908 : */
15909 : void
15910 37726 : parser_init(base_yy_extra_type *yyext)
15911 : {
15912 37726 : yyext->parsetree = NIL; /* in case grammar forgets to set it */
15913 37726 : }
|