4 /*-------------------------------------------------------------------------
7 * POSTGRESQL BISON rules/actions
9 * Portions Copyright (c) 1996-2025, PostgreSQL Global Development Group
10 * Portions Copyright (c) 1994, Regents of the University of California
14 * src/backend/parser/gram.y
17 * AUTHOR DATE MAJOR EVENT
18 * Andrew Yu Sept, 1994 POSTQUEL to SQL conversion
19 * Andrew Yu Oct, 1994 lispy code conversion
22 * CAPITALS are used to represent terminal symbols.
23 * non-capitals are used to represent non-terminals.
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.
38 * If you use a list, make sure the datum is a node so that the printing
41 * Sometimes we assign constants to makeStrings. Make sure we don't free
44 *-------------------------------------------------------------------------
51 #include "catalog/index.h"
52 #include "catalog/namespace.h"
53 #include "catalog/pg_am.h"
54 #include "catalog/pg_trigger.h"
55 #include "commands/defrem.h"
56 #include "commands/trigger.h"
57 #include "gramparse.h"
58 #include "nodes/makefuncs.h"
59 #include "nodes/nodeFuncs.h"
60 #include "parser/parser.h"
61 #include "utils/datetime.h"
62 #include "utils/xml.h"
66 * Location tracking support. Unlike bison's default, we only want
67 * to track the start position not the end position of each nonterminal.
68 * Nonterminals that reduce to empty receive position "-1". Since a
69 * production's leading RHS nonterminal(s) may have reduced to empty,
70 * we have to scan to find the first one that's not -1.
72 #define YYLLOC_DEFAULT(Current, Rhs, N) \
75 for
(int _i
= 1; _i
<= (N
); _i
++) \
79 (Current
) = (Rhs
)[_i
]; \
86 * Bison doesn't allocate anything that needs to live across parser calls,
87 * so we can easily have it use palloc instead of malloc. This prevents
88 * memory leaks if we error out during parsing.
90 #define YYMALLOC palloc
93 /* Private struct for the result of privilege_target production */
94 typedef
struct PrivTarget
96 GrantTargetType targtype
;
101 /* Private struct for the result of import_qualification production */
102 typedef
struct ImportQual
104 ImportForeignSchemaType type
;
108 /* Private struct for the result of select_limit & limit_clause productions */
109 typedef
struct SelectLimit
113 LimitOption limitOption
; /* indicates presence of WITH TIES */
114 ParseLoc offsetLoc
; /* location of OFFSET token, if present */
115 ParseLoc countLoc
; /* location of LIMIT/FETCH token, if present */
116 ParseLoc optionLoc
; /* location of WITH TIES, if present */
119 /* Private struct for the result of group_clause production */
120 typedef
struct GroupClause
126 /* Private structs for the result of key_actions and key_action productions */
127 typedef
struct KeyAction
133 typedef
struct KeyActions
135 KeyAction
*updateAction
;
136 KeyAction
*deleteAction
;
139 /* ConstraintAttributeSpec yields an integer bitmask of these flags: */
140 #define CAS_NOT_DEFERRABLE 0x01
141 #define CAS_DEFERRABLE 0x02
142 #define CAS_INITIALLY_IMMEDIATE 0x04
143 #define CAS_INITIALLY_DEFERRED 0x08
144 #define CAS_NOT_VALID 0x10
145 #define CAS_NO_INHERIT 0x20
146 #define CAS_NOT_ENFORCED 0x40
147 #define CAS_ENFORCED 0x80
150 #define parser_yyerror(msg) scanner_yyerror(msg, yyscanner)
151 #define parser_errposition(pos) scanner_errposition(pos, yyscanner)
153 static void base_yyerror
(YYLTYPE *yylloc, core_yyscan_t yyscanner
,
155 static RawStmt
*makeRawStmt
(Node
*stmt
, int stmt_location
);
156 static void updateRawStmtEnd
(RawStmt
*rs
, int end_location
);
157 static void updatePreparableStmtEnd
(Node
*n
, int end_location
);
158 static Node
*makeColumnRef
(char *colname
, List
*indirection
,
159 int location
, core_yyscan_t yyscanner
);
160 static Node
*makeTypeCast
(Node
*arg
, TypeName
*typename
, int location
);
161 static Node
*makeStringConstCast
(char *str
, int location
, TypeName
*typename
);
162 static Node
*makeIntConst
(int val
, int location
);
163 static Node
*makeFloatConst
(char *str
, int location
);
164 static Node
*makeBoolAConst
(bool state
, int location
);
165 static Node
*makeBitStringConst
(char *str
, int location
);
166 static Node
*makeNullAConst
(int location
);
167 static Node
*makeAConst
(Node
*v
, int location
);
168 static RoleSpec
*makeRoleSpec
(RoleSpecType type
, int location
);
169 static void check_qualified_name
(List
*names
, core_yyscan_t yyscanner
);
170 static List
*check_func_name
(List
*names
, core_yyscan_t yyscanner
);
171 static List
*check_indirection
(List
*indirection
, core_yyscan_t yyscanner
);
172 static List
*extractArgTypes
(List
*parameters
);
173 static List
*extractAggrArgTypes
(List
*aggrargs
);
174 static List
*makeOrderedSetArgs
(List
*directargs
, List
*orderedargs
,
175 core_yyscan_t yyscanner
);
176 static void insertSelectOptions
(SelectStmt
*stmt
,
177 List
*sortClause
, List
*lockingClause
,
178 SelectLimit
*limitClause
,
179 WithClause
*withClause
,
180 core_yyscan_t yyscanner
);
181 static Node
*makeSetOp
(SetOperation op
, bool all
, Node
*larg
, Node
*rarg
, int location
);
182 static Node
*doNegate
(Node
*n
, int location
);
183 static void doNegateFloat
(Float
*v
);
184 static Node
*makeAndExpr
(Node
*lexpr
, Node
*rexpr
, int location
);
185 static Node
*makeOrExpr
(Node
*lexpr
, Node
*rexpr
, int location
);
186 static Node
*makeNotExpr
(Node
*expr
, int location
);
187 static Node
*makeAArrayExpr
(List
*elements
, int location
);
188 static Node
*makeSQLValueFunction
(SQLValueFunctionOp op
, int32 typmod
,
190 static Node
*makeXmlExpr
(XmlExprOp op
, char *name
, List
*named_args
,
191 List
*args
, int location
);
192 static List
*mergeTableFuncParameters
(List
*func_args
, List
*columns
, core_yyscan_t yyscanner
);
193 static TypeName
*TableFuncTypeName
(List
*columns
);
194 static RangeVar
*makeRangeVarFromAnyName
(List
*names
, int position
, core_yyscan_t yyscanner
);
195 static RangeVar
*makeRangeVarFromQualifiedName
(char *name
, List
*namelist
, int location
,
196 core_yyscan_t yyscanner
);
197 static void SplitColQualList
(List
*qualList
,
198 List
**constraintList
, CollateClause
**collClause
,
199 core_yyscan_t yyscanner
);
200 static void processCASbits
(int cas_bits
, int location
, const char *constrType
,
201 bool *deferrable
, bool *initdeferred
, bool *is_enforced
,
202 bool *not_valid
, bool *no_inherit
, core_yyscan_t yyscanner
);
203 static PartitionStrategy parsePartitionStrategy
(char *strategy
, int location
,
204 core_yyscan_t yyscanner
);
205 static void preprocess_pubobj_list
(List
*pubobjspec_list
,
206 core_yyscan_t yyscanner
);
207 static Node
*makeRecursiveViewSelect
(char *relname
, List
*aliases
, Node
*query
);
213 %name
-prefix
="base_yy"
216 %parse
-param
{core_yyscan_t yyscanner
}
217 %lex
-param
{core_yyscan_t yyscanner
}
221 core_YYSTYPE core_yystype
;
222 /* these fields must match core_YYSTYPE: */
230 DropBehavior dbehavior
;
231 OnCommitAction oncommit
;
236 FunctionParameter
*fun_param
;
237 FunctionParameterMode fun_param_mode
;
238 ObjectWithArgs
*objwithargs
;
250 OnConflictClause
*onconflict
;
253 struct PrivTarget
*privtarget
;
254 AccessPriv
*accesspriv
;
255 struct ImportQual
*importqual
;
257 VariableSetStmt
*vsetstmt
;
258 PartitionElem
*partelem
;
259 PartitionSpec
*partspec
;
260 PartitionBoundSpec
*partboundspec
;
262 PublicationObjSpec
*publicationobjectspec
;
263 struct SelectLimit
*selectlimit
;
264 SetQuantifier setquantifier
;
265 struct GroupClause
*groupclause
;
266 MergeMatchKind mergematch
;
267 MergeWhenClause
*mergewhen
;
268 struct KeyActions
*keyactions
;
269 struct KeyAction
*keyaction
;
270 ReturningClause
*retclause
;
271 ReturningOptionKind retoptionkind
;
274 %type
<node
> stmt toplevel_stmt schema_stmt routine_body_stmt
275 AlterEventTrigStmt AlterCollationStmt
276 AlterDatabaseStmt AlterDatabaseSetStmt AlterDomainStmt AlterEnumStmt
277 AlterFdwStmt AlterForeignServerStmt AlterGroupStmt
278 AlterObjectDependsStmt AlterObjectSchemaStmt AlterOwnerStmt
279 AlterOperatorStmt AlterTypeStmt AlterSeqStmt AlterSystemStmt AlterTableStmt
280 AlterTblSpcStmt AlterExtensionStmt AlterExtensionContentsStmt
281 AlterCompositeTypeStmt AlterUserMappingStmt
282 AlterRoleStmt AlterRoleSetStmt AlterPolicyStmt AlterStatsStmt
283 AlterDefaultPrivilegesStmt DefACLAction
284 AnalyzeStmt CallStmt ClosePortalStmt ClusterStmt CommentStmt
285 ConstraintsSetStmt CopyStmt CreateAsStmt CreateCastStmt
286 CreateDomainStmt CreateExtensionStmt CreateGroupStmt CreateOpClassStmt
287 CreateOpFamilyStmt AlterOpFamilyStmt CreatePLangStmt
288 CreateSchemaStmt CreateSeqStmt CreateStmt CreateStatsStmt CreateTableSpaceStmt
289 CreateFdwStmt CreateForeignServerStmt CreateForeignTableStmt
290 CreateAssertionStmt CreateTransformStmt CreateTrigStmt CreateEventTrigStmt
291 CreateUserStmt CreateUserMappingStmt CreateRoleStmt CreatePolicyStmt
292 CreatedbStmt DeclareCursorStmt DefineStmt DeleteStmt DiscardStmt DoStmt
293 DropOpClassStmt DropOpFamilyStmt DropStmt
294 DropCastStmt DropRoleStmt
295 DropdbStmt DropTableSpaceStmt
297 DropUserMappingStmt ExplainStmt FetchStmt
298 GrantStmt GrantRoleStmt ImportForeignSchemaStmt IndexStmt InsertStmt
299 ListenStmt LoadStmt LockStmt MergeStmt NotifyStmt ExplainableStmt PreparableStmt
300 CreateFunctionStmt AlterFunctionStmt ReindexStmt RemoveAggrStmt
301 RemoveFuncStmt RemoveOperStmt RenameStmt ReturnStmt RevokeStmt RevokeRoleStmt
302 RuleActionStmt RuleActionStmtOrEmpty RuleStmt
303 SecLabelStmt SelectStmt TransactionStmt TransactionStmtLegacy TruncateStmt
304 UnlistenStmt UpdateStmt VacuumStmt
305 VariableResetStmt VariableSetStmt VariableShowStmt
306 ViewStmt CheckPointStmt CreateConversionStmt
307 DeallocateStmt PrepareStmt ExecuteStmt
308 DropOwnedStmt ReassignOwnedStmt
309 AlterTSConfigurationStmt AlterTSDictionaryStmt
310 CreateMatViewStmt RefreshMatViewStmt CreateAmStmt
311 CreatePublicationStmt AlterPublicationStmt
312 CreateSubscriptionStmt AlterSubscriptionStmt DropSubscriptionStmt
314 %type
<node
> select_no_parens select_with_parens select_clause
315 simple_select values_clause
316 PLpgSQL_Expr PLAssignStmt
318 %type
<str
> opt_single_name
319 %type
<list
> opt_qualified_name
320 %type
<boolean
> opt_concurrently
321 %type
<dbehavior
> opt_drop_behavior
323 %type
<node
> alter_column_default opclass_item opclass_drop alter_using
324 %type
<ival
> add_drop opt_asc_desc opt_nulls_order
326 %type
<node
> alter_table_cmd alter_type_cmd opt_collate_clause
327 replica_identity partition_cmd index_partition_cmd
328 %type
<list
> alter_table_cmds alter_type_cmds
329 %type
<list
> alter_identity_column_option_list
330 %type
<defelt
> alter_identity_column_option
331 %type
<node
> set_statistics_value
332 %type
<str
> set_access_method_name
334 %type
<list
> createdb_opt_list createdb_opt_items copy_opt_list
335 transaction_mode_list
336 create_extension_opt_list alter_extension_opt_list
337 %type
<defelt
> createdb_opt_item copy_opt_item
338 transaction_mode_item
339 create_extension_opt_item alter_extension_opt_item
341 %type
<ival
> opt_lock lock_type cast_context
342 %type
<str
> utility_option_name
343 %type
<defelt
> utility_option_elem
344 %type
<list
> utility_option_list
345 %type
<node
> utility_option_arg
346 %type
<defelt
> drop_option
347 %type
<boolean
> opt_or_replace opt_no
348 opt_grant_grant_option
349 opt_nowait opt_if_exists opt_with_data
350 opt_transaction_chain
351 %type
<list
> grant_role_opt_list
352 %type
<defelt
> grant_role_opt
353 %type
<node
> grant_role_opt_value
354 %type
<ival
> opt_nowait_or_skip
356 %type
<list
> OptRoleList AlterOptRoleList
357 %type
<defelt
> CreateOptRoleElem AlterOptRoleElem
360 %type
<str
> foreign_server_version opt_foreign_server_version
361 %type
<str
> opt_in_database
363 %type
<str
> parameter_name
364 %type
<list
> OptSchemaEltList parameter_name_list
368 %type
<boolean
> TriggerForSpec TriggerForType
369 %type
<ival
> TriggerActionTime
370 %type
<list
> TriggerEvents TriggerOneEvent
371 %type
<node
> TriggerFuncArg
372 %type
<node
> TriggerWhen
373 %type
<str
> TransitionRelName
374 %type
<boolean
> TransitionRowOrTable TransitionOldOrNew
375 %type
<node
> TriggerTransition
377 %type
<list
> event_trigger_when_list event_trigger_value_list
378 %type
<defelt
> event_trigger_when_item
379 %type
<chr
> enable_trigger
381 %type
<str
> copy_file_name
382 access_method_clause attr_name
383 table_access_method_clause name cursor_name file_name
384 cluster_index_specification
386 %type
<list
> func_name handler_name qual_Op qual_all_Op subquery_Op
387 opt_inline_handler opt_validator validator_clause
390 %type
<range
> qualified_name insert_target OptConstrFromTable
392 %type
<str
> all_Op MathOp
394 %type
<str
> row_security_cmd RowSecurityDefaultForCmd
395 %type
<boolean
> RowSecurityDefaultPermissive
396 %type
<node
> RowSecurityOptionalWithCheck RowSecurityOptionalExpr
397 %type
<list
> RowSecurityDefaultToRole RowSecurityOptionalToRole
399 %type
<str
> iso_level opt_encoding
400 %type
<rolespec
> grantee
401 %type
<list
> grantee_list
402 %type
<accesspriv
> privilege
403 %type
<list
> privileges privilege_list
404 %type
<privtarget
> privilege_target
405 %type
<objwithargs
> function_with_argtypes aggregate_with_argtypes operator_with_argtypes
406 %type
<list
> function_with_argtypes_list aggregate_with_argtypes_list operator_with_argtypes_list
407 %type
<ival
> defacl_privilege_target
408 %type
<defelt
> DefACLOption
409 %type
<list
> DefACLOptionList
410 %type
<ival
> import_qualification_type
411 %type
<importqual
> import_qualification
412 %type
<node
> vacuum_relation
413 %type
<selectlimit
> opt_select_limit select_limit limit_clause
415 %type
<list
> parse_toplevel stmtmulti routine_body_stmt_list
416 OptTableElementList TableElementList OptInherit definition
417 OptTypedTableElementList TypedTableElementList
418 reloptions opt_reloptions
419 OptWith opt_definition func_args func_args_list
420 func_args_with_defaults func_args_with_defaults_list
421 aggr_args aggr_args_list
422 func_as createfunc_opt_list opt_createfunc_opt_list alterfunc_opt_list
423 old_aggr_definition old_aggr_list
424 oper_argtypes RuleActionList RuleActionMulti
425 opt_column_list columnList opt_name_list
426 sort_clause opt_sort_clause sortby_list index_params
428 opt_include opt_c_include index_including_params
429 name_list role_list from_clause from_list opt_array_bounds
430 qualified_name_list any_name any_name_list type_name_list
431 any_operator expr_list attrs
432 distinct_clause opt_distinct_clause
433 target_list opt_target_list insert_column_list set_target_list
435 set_clause_list set_clause
436 def_list operator_def_list indirection opt_indirection
437 reloption_list TriggerFuncArgs opclass_item_list opclass_drop_list
438 opclass_purpose opt_opfamily transaction_mode_list_or_empty
439 OptTableFuncElementList TableFuncElementList opt_type_modifiers
441 execute_param_clause using_clause
442 returning_with_clause returning_options
443 opt_enum_val_list enum_val_list table_func_column_list
444 create_generic_options alter_generic_options
445 relation_expr_list dostmt_opt_list
446 transform_element_list transform_type_list
447 TriggerTransitions TriggerReferencing
448 vacuum_relation_list opt_vacuum_relation_list
449 drop_option_list pub_obj_list
451 %type
<retclause
> returning_clause
452 %type
<node
> returning_option
453 %type
<retoptionkind
> returning_option_kind
454 %type
<node
> opt_routine_body
455 %type
<groupclause
> group_clause
456 %type
<list
> group_by_list
457 %type
<node
> group_by_item empty_grouping_set rollup_clause cube_clause
458 %type
<node
> grouping_sets_clause
460 %type
<list
> opt_fdw_options fdw_options
461 %type
<defelt
> fdw_option
463 %type
<range
> OptTempTableName
464 %type
<into
> into_clause create_as_target create_mv_target
466 %type
<defelt
> createfunc_opt_item common_func_opt_item dostmt_opt_item
467 %type
<fun_param
> func_arg func_arg_with_default table_func_column aggr_arg
468 %type
<fun_param_mode
> arg_class
469 %type
<typnam
> func_return func_type
471 %type
<boolean
> opt_trusted opt_restart_seqs
473 %type
<ival
> OptNoLog
474 %type
<oncommit
> OnCommitOption
476 %type
<ival
> for_locking_strength
477 %type
<node
> for_locking_item
478 %type
<list
> for_locking_clause opt_for_locking_clause for_locking_items
479 %type
<list
> locked_rels_list
480 %type
<setquantifier
> set_quantifier
482 %type
<node
> join_qual
483 %type
<jtype
> join_type
485 %type
<list
> extract_list overlay_list position_list
486 %type
<list
> substr_list trim_list
487 %type
<list
> opt_interval interval_second
488 %type
<str
> unicode_normal_form
490 %type
<boolean
> opt_instead
491 %type
<boolean
> opt_unique opt_verbose opt_full
492 %type
<boolean
> opt_freeze opt_analyze opt_default
493 %type
<defelt
> opt_binary copy_delimiter
495 %type
<boolean
> copy_from opt_program
497 %type
<ival
> event cursor_options opt_hold opt_set_data
498 %type
<objtype
> object_type_any_name object_type_name object_type_name_on_any_name
501 %type
<node
> fetch_args select_limit_value
502 offset_clause select_offset_value
503 select_fetch_first_value I_or_F_const
504 %type
<ival
> row_or_rows first_or_next
506 %type
<list
> OptSeqOptList SeqOptList OptParenthesizedSeqOptList
507 %type
<defelt
> SeqOptElem
509 %type
<istmt
> insert_rest
510 %type
<infer
> opt_conf_expr
511 %type
<onconflict
> opt_on_conflict
512 %type
<mergewhen
> merge_insert merge_update merge_delete
514 %type
<mergematch
> merge_when_tgt_matched merge_when_tgt_not_matched
515 %type
<node
> merge_when_clause opt_merge_when_condition
516 %type
<list
> merge_when_list
518 %type
<vsetstmt
> generic_set set_rest set_rest_more generic_reset reset_rest
519 SetResetClause FunctionSetResetClause
521 %type
<node
> TableElement TypedTableElement ConstraintElem DomainConstraintElem TableFuncElement
522 %type
<node
> columnDef columnOptions optionalPeriodName
523 %type
<defelt
> def_elem reloption_elem old_aggr_elem operator_def_elem
524 %type
<node
> def_arg columnElem where_clause where_or_current_clause
525 a_expr b_expr c_expr AexprConst indirection_el opt_slice_bound
526 columnref in_expr having_clause func_table xmltable array_expr
527 OptWhereClause operator_def_arg
528 %type
<list
> opt_column_and_period_list
529 %type
<list
> rowsfrom_item rowsfrom_list opt_col_def_list
530 %type
<boolean
> opt_ordinality opt_without_overlaps
531 %type
<list
> ExclusionConstraintList ExclusionConstraintElem
532 %type
<list
> func_arg_list func_arg_list_opt
533 %type
<node
> func_arg_expr
534 %type
<list
> row explicit_row implicit_row type_list array_expr_list
535 %type
<node
> case_expr case_arg when_clause case_default
536 %type
<list
> when_clause_list
537 %type
<node
> opt_search_clause opt_cycle_clause
538 %type
<ival
> sub_type opt_materialized
539 %type
<node
> NumericOnly
540 %type
<list
> NumericOnly_list
541 %type
<alias
> alias_clause opt_alias_clause opt_alias_clause_for_join_using
542 %type
<list
> func_alias_clause
543 %type
<sortby
> sortby
544 %type
<ielem
> index_elem index_elem_options
545 %type
<selem
> stats_param
546 %type
<node
> table_ref
547 %type
<jexpr
> joined_table
548 %type
<range
> relation_expr
549 %type
<range
> extended_relation_expr
550 %type
<range
> relation_expr_opt_alias
551 %type
<node
> tablesample_clause opt_repeatable_clause
552 %type
<target
> target_el set_target insert_column_item
554 %type
<str
> generic_option_name
555 %type
<node
> generic_option_arg
556 %type
<defelt
> generic_option_elem alter_generic_option_elem
557 %type
<list
> generic_option_list alter_generic_option_list
559 %type
<ival
> reindex_target_relation reindex_target_all
560 %type
<list
> opt_reindex_option_list
562 %type
<node
> copy_generic_opt_arg copy_generic_opt_arg_list_item
563 %type
<defelt
> copy_generic_opt_elem
564 %type
<list
> copy_generic_opt_list copy_generic_opt_arg_list
565 %type
<list
> copy_options
567 %type
<typnam
> Typename SimpleTypename ConstTypename
568 GenericType Numeric opt_float JsonType
569 Character ConstCharacter
570 CharacterWithLength CharacterWithoutLength
571 ConstDatetime ConstInterval
572 Bit ConstBit BitWithLength BitWithoutLength
573 %type
<str
> character
574 %type
<str
> extract_arg
575 %type
<boolean
> opt_varying opt_timezone opt_no_inherit
577 %type
<ival
> Iconst SignedIconst
578 %type
<str
> Sconst comment_text notify_payload
579 %type
<str
> RoleId opt_boolean_or_string
580 %type
<list
> var_list
581 %type
<str
> ColId ColLabel BareColLabel
582 %type
<str
> NonReservedWord NonReservedWord_or_Sconst
583 %type
<str
> var_name type_function_name param_name
584 %type
<str
> createdb_opt_name plassign_target
585 %type
<node
> var_value zone_value
586 %type
<rolespec
> auth_ident RoleSpec opt_granted_by
587 %type
<publicationobjectspec
> PublicationObjSpec
589 %type
<keyword
> unreserved_keyword type_func_name_keyword
590 %type
<keyword
> col_name_keyword reserved_keyword
591 %type
<keyword
> bare_label_keyword
593 %type
<node
> DomainConstraint TableConstraint TableLikeClause
594 %type
<ival
> TableLikeOptionList TableLikeOption
595 %type
<str
> column_compression opt_column_compression column_storage opt_column_storage
596 %type
<list
> ColQualList
597 %type
<node
> ColConstraint ColConstraintElem ConstraintAttr
598 %type
<ival
> key_match
599 %type
<keyaction
> key_delete key_update key_action
600 %type
<keyactions
> key_actions
601 %type
<ival
> ConstraintAttributeSpec ConstraintAttributeElem
602 %type
<str
> ExistingIndex
604 %type
<list
> constraints_set_list
605 %type
<boolean
> constraints_set_mode
606 %type
<str
> OptTableSpace OptConsTableSpace
607 %type
<rolespec
> OptTableSpaceOwner
608 %type
<ival
> opt_check_option
610 %type
<str
> opt_provider security_label
612 %type
<target
> xml_attribute_el
613 %type
<list
> xml_attribute_list xml_attributes
614 %type
<node
> xml_root_version opt_xml_root_standalone
615 %type
<node
> xmlexists_argument
616 %type
<ival
> document_or_content
617 %type
<boolean
> xml_indent_option xml_whitespace_option
618 %type
<list
> xmltable_column_list xmltable_column_option_list
619 %type
<node
> xmltable_column_el
620 %type
<defelt
> xmltable_column_option_el
621 %type
<list
> xml_namespace_list
622 %type
<target
> xml_namespace_el
624 %type
<node
> func_application func_expr_common_subexpr
625 %type
<node
> func_expr func_expr_windowless
626 %type
<node
> common_table_expr
627 %type
<with
> with_clause opt_with_clause
628 %type
<list
> cte_list
630 %type
<list
> within_group_clause
631 %type
<node
> filter_clause
632 %type
<list
> window_clause window_definition_list opt_partition_clause
633 %type
<windef
> window_definition over_clause window_specification
634 opt_frame_clause frame_extent frame_bound
635 %type
<ival
> opt_window_exclusion_clause
636 %type
<str
> opt_existing_window_name
637 %type
<boolean
> opt_if_not_exists
638 %type
<boolean
> opt_unique_null_treatment
639 %type
<ival
> generated_when override_kind
640 %type
<partspec
> PartitionSpec OptPartitionSpec
641 %type
<partelem
> part_elem
642 %type
<list
> part_params
643 %type
<partboundspec
> PartitionBoundSpec
644 %type
<list
> hash_partbound
645 %type
<defelt
> hash_partbound_elem
647 %type
<node
> json_format_clause
648 json_format_clause_opt
650 json_returning_clause_opt
655 json_on_error_clause_opt
657 json_table_column_definition
658 json_table_column_path_clause_opt
659 %type
<list
> json_name_and_value_list
661 json_array_aggregate_order_by_clause_opt
663 json_behavior_clause_opt
664 json_passing_clause_opt
665 json_table_column_definition_list
666 %type
<str
> json_table_path_name_opt
667 %type
<ival
> json_behavior_type
668 json_predicate_type_constraint
669 json_quotes_clause_opt
670 json_wrapper_behavior
671 %type
<boolean
> json_key_uniqueness_constraint_opt
672 json_object_constructor_null_clause_opt
673 json_array_constructor_null_clause_opt
677 * Non-keyword token types. These are hard-wired into the "flex" lexer.
678 * They must be listed first so that their numeric codes do not depend on
679 * the set of keywords. PL/pgSQL depends on this so that it can share the
680 * same lexer. If you add/change tokens here, fix PL/pgSQL to match!
682 * UIDENT and USCONST are reduced to IDENT and SCONST in parser.c, so that
683 * they need no productions here; but we must assign token codes to them.
685 * DOT_DOT is unused in the core SQL grammar, and so will always provoke
686 * parse errors. It is needed by PL/pgSQL.
688 %token
<str
> IDENT UIDENT FCONST SCONST USCONST BCONST XCONST Op
689 %token
<ival
> ICONST PARAM
690 %token TYPECAST DOT_DOT COLON_EQUALS EQUALS_GREATER
691 %token LESS_EQUALS GREATER_EQUALS NOT_EQUALS
694 * If you want to make any keyword changes, update the keyword table in
695 * src/include/parser/kwlist.h and add new keywords to the appropriate one
696 * of the reserved-or-not-so-reserved keyword lists, below; search
697 * this file for "Keyword category lists".
700 /* ordinary key words in alphabetical order */
701 %token
<keyword
> ABORT_P ABSENT ABSOLUTE_P ACCESS ACTION ADD_P ADMIN AFTER
702 AGGREGATE ALL ALSO ALTER ALWAYS ANALYSE ANALYZE AND ANY ARRAY AS ASC
703 ASENSITIVE ASSERTION ASSIGNMENT ASYMMETRIC ATOMIC AT ATTACH ATTRIBUTE AUTHORIZATION
705 BACKWARD BEFORE BEGIN_P BETWEEN BIGINT BINARY BIT
706 BOOLEAN_P BOTH BREADTH BY
708 CACHE CALL CALLED CASCADE CASCADED CASE CAST CATALOG_P CHAIN CHAR_P
709 CHARACTER CHARACTERISTICS CHECK CHECKPOINT CLASS CLOSE
710 CLUSTER COALESCE COLLATE COLLATION COLUMN COLUMNS COMMENT COMMENTS COMMIT
711 COMMITTED COMPRESSION CONCURRENTLY CONDITIONAL CONFIGURATION CONFLICT
712 CONNECTION CONSTRAINT CONSTRAINTS CONTENT_P CONTINUE_P CONVERSION_P COPY
713 COST CREATE CROSS CSV CUBE CURRENT_P
714 CURRENT_CATALOG CURRENT_DATE CURRENT_ROLE CURRENT_SCHEMA
715 CURRENT_TIME CURRENT_TIMESTAMP CURRENT_USER CURSOR CYCLE
717 DATA_P DATABASE DAY_P DEALLOCATE DEC DECIMAL_P DECLARE DEFAULT DEFAULTS
718 DEFERRABLE DEFERRED DEFINER DELETE_P DELIMITER DELIMITERS DEPENDS DEPTH DESC
719 DETACH DICTIONARY DISABLE_P DISCARD DISTINCT DO DOCUMENT_P DOMAIN_P
722 EACH ELSE EMPTY_P ENABLE_P ENCODING ENCRYPTED END_P ENFORCED ENUM_P ERROR_P
723 ESCAPE EVENT EXCEPT EXCLUDE EXCLUDING EXCLUSIVE EXECUTE EXISTS EXPLAIN
724 EXPRESSION EXTENSION EXTERNAL EXTRACT
726 FALSE_P FAMILY FETCH FILTER FINALIZE FIRST_P FLOAT_P FOLLOWING FOR
727 FORCE FOREIGN FORMAT FORWARD FREEZE FROM FULL FUNCTION FUNCTIONS
729 GENERATED GLOBAL GRANT GRANTED GREATEST GROUP_P GROUPING GROUPS
731 HANDLER HAVING HEADER_P HOLD HOUR_P
733 IDENTITY_P IF_P ILIKE IMMEDIATE IMMUTABLE IMPLICIT_P IMPORT_P IN_P INCLUDE
734 INCLUDING INCREMENT INDENT INDEX INDEXES INHERIT INHERITS INITIALLY INLINE_P
735 INNER_P INOUT INPUT_P INSENSITIVE INSERT INSTEAD INT_P INTEGER
736 INTERSECT INTERVAL INTO INVOKER IS ISNULL ISOLATION
738 JOIN JSON JSON_ARRAY JSON_ARRAYAGG JSON_EXISTS JSON_OBJECT JSON_OBJECTAGG
739 JSON_QUERY JSON_SCALAR JSON_SERIALIZE JSON_TABLE JSON_VALUE
743 LABEL LANGUAGE LARGE_P LAST_P LATERAL_P
744 LEADING LEAKPROOF LEAST LEFT LEVEL LIKE LIMIT LISTEN LOAD LOCAL
745 LOCALTIME LOCALTIMESTAMP LOCATION LOCK_P LOCKED LOGGED
747 MAPPING MATCH MATCHED MATERIALIZED MAXVALUE MERGE MERGE_ACTION METHOD
748 MINUTE_P MINVALUE MODE MONTH_P MOVE
750 NAME_P NAMES NATIONAL NATURAL NCHAR NESTED NEW NEXT NFC NFD NFKC NFKD NO
751 NONE NORMALIZE NORMALIZED
752 NOT NOTHING NOTIFY NOTNULL NOWAIT NULL_P NULLIF
755 OBJECT_P OF OFF OFFSET OIDS OLD OMIT ON ONLY OPERATOR OPTION OPTIONS OR
756 ORDER ORDINALITY OTHERS OUT_P OUTER_P
757 OVER OVERLAPS OVERLAY OVERRIDING OWNED OWNER
759 PARALLEL PARAMETER PARSER PARTIAL PARTITION PASSING PASSWORD PATH
760 PERIOD PLACING PLAN PLANS POLICY
761 POSITION PRECEDING PRECISION PRESERVE PREPARE PREPARED PRIMARY
762 PRIOR PRIVILEGES PROCEDURAL PROCEDURE PROCEDURES PROGRAM PUBLICATION
766 RANGE READ REAL REASSIGN RECURSIVE REF_P REFERENCES REFERENCING
767 REFRESH REINDEX RELATIVE_P RELEASE RENAME REPEATABLE REPLACE REPLICA
768 RESET RESTART RESTRICT RETURN RETURNING RETURNS REVOKE RIGHT ROLE ROLLBACK ROLLUP
769 ROUTINE ROUTINES ROW ROWS RULE
771 SAVEPOINT SCALAR SCHEMA SCHEMAS SCROLL SEARCH SECOND_P SECURITY SELECT
773 SERIALIZABLE SERVER SESSION SESSION_USER SET SETS SETOF SHARE SHOW
774 SIMILAR SIMPLE SKIP SMALLINT SNAPSHOT SOME SOURCE SQL_P STABLE STANDALONE_P
775 START STATEMENT STATISTICS STDIN STDOUT STORAGE STORED STRICT_P STRING_P STRIP_P
776 SUBSCRIPTION SUBSTRING SUPPORT SYMMETRIC SYSID SYSTEM_P SYSTEM_USER
778 TABLE TABLES TABLESAMPLE TABLESPACE TARGET TEMP TEMPLATE TEMPORARY TEXT_P THEN
779 TIES TIME TIMESTAMP TO TRAILING TRANSACTION TRANSFORM
780 TREAT TRIGGER TRIM TRUE_P
781 TRUNCATE TRUSTED TYPE_P TYPES_P
783 UESCAPE UNBOUNDED UNCONDITIONAL UNCOMMITTED UNENCRYPTED UNION UNIQUE UNKNOWN
784 UNLISTEN UNLOGGED UNTIL UPDATE USER USING
786 VACUUM VALID VALIDATE VALIDATOR VALUE_P VALUES VARCHAR VARIADIC VARYING
787 VERBOSE VERSION_P VIEW VIEWS VOLATILE
789 WHEN WHERE WHITESPACE_P WINDOW WITH WITHIN WITHOUT WORK WRAPPER WRITE
791 XML_P XMLATTRIBUTES XMLCONCAT XMLELEMENT XMLEXISTS XMLFOREST XMLNAMESPACES
792 XMLPARSE XMLPI XMLROOT XMLSERIALIZE XMLTABLE
799 * The grammar thinks these are keywords, but they are not in the kwlist.h
800 * list and so can never be entered directly. The filter in parser.c
801 * creates these tokens when required (based on looking one token ahead).
803 * NOT_LA exists so that productions such as NOT LIKE can be given the same
804 * precedence as LIKE; otherwise they'd effectively have the same precedence
805 * as NOT, at least with respect to their left-hand subexpression.
806 * FORMAT_LA, NULLS_LA, WITH_LA, and WITHOUT_LA are needed to make the grammar
809 %token FORMAT_LA NOT_LA NULLS_LA WITH_LA WITHOUT_LA
812 * The grammar likewise thinks these tokens are keywords, but they are never
813 * generated by the scanner. Rather, they can be injected by parser.c as
814 * the initial token of the string (using the lookahead-token mechanism
815 * implemented there). This provides a way to tell the grammar to parse
816 * something other than the usual list of SQL commands.
818 %token MODE_TYPE_NAME
819 %token MODE_PLPGSQL_EXPR
820 %token MODE_PLPGSQL_ASSIGN1
821 %token MODE_PLPGSQL_ASSIGN2
822 %token MODE_PLPGSQL_ASSIGN3
825 /* Precedence: lowest to highest */
831 %nonassoc IS ISNULL NOTNULL
/* IS sets precedence for IS NULL, etc */
832 %nonassoc
'<' '>' '=' LESS_EQUALS GREATER_EQUALS NOT_EQUALS
833 %nonassoc BETWEEN IN_P LIKE ILIKE SIMILAR NOT_LA
834 %nonassoc ESCAPE
/* ESCAPE must be just above LIKE/ILIKE/SIMILAR */
837 * Sometimes it is necessary to assign precedence to keywords that are not
838 * really part of the operator hierarchy, in order to resolve grammar
839 * ambiguities. It's best to avoid doing so whenever possible, because such
840 * assignments have global effect and may hide ambiguities besides the one
841 * you intended to solve. (Attaching a precedence to a single rule with
842 * %prec is far safer and should be preferred.) If you must give precedence
843 * to a new keyword, try very hard to give it the same precedence as IDENT.
844 * If the keyword has IDENT's precedence then it clearly acts the same as
845 * non-keywords and other similar keywords, thus reducing the risk of
846 * unexpected precedence effects.
848 * We used to need to assign IDENT an explicit precedence just less than Op,
849 * to support target_el without AS. While that's not really necessary since
850 * we removed postfix operators, we continue to do so because it provides a
851 * reference point for a precedence level that we can assign to other
852 * keywords that lack a natural precedence level.
854 * We need to do this for PARTITION, RANGE, ROWS, and GROUPS to support
855 * opt_existing_window_name (see comment there).
857 * The frame_bound productions UNBOUNDED PRECEDING and UNBOUNDED FOLLOWING
858 * are even messier: since UNBOUNDED is an unreserved keyword (per spec!),
859 * there is no principled way to distinguish these from the productions
860 * a_expr PRECEDING/FOLLOWING. We hack this up by giving UNBOUNDED slightly
861 * lower precedence than PRECEDING and FOLLOWING. At present this doesn't
862 * appear to cause UNBOUNDED to be treated differently from other unreserved
863 * keywords anywhere else in the grammar, but it's definitely risky. We can
864 * blame any funny behavior of UNBOUNDED on the SQL standard, though.
866 * To support CUBE and ROLLUP in GROUP BY without reserving them, we give them
867 * an explicit priority lower than '(', so that a rule with CUBE '(' will shift
868 * rather than reducing a conflicting rule that takes CUBE as a function name.
869 * Using the same precedence as IDENT seems right for the reasons given above.
871 * SET is likewise assigned the same precedence as IDENT, to support the
872 * relation_expr_opt_alias production (see comment there).
874 * KEYS, OBJECT_P, SCALAR, VALUE_P, WITH, and WITHOUT are similarly assigned
875 * the same precedence as IDENT. This allows resolving conflicts in the
876 * json_predicate_type_constraint and json_key_uniqueness_constraint_opt
877 * productions (see comments there).
879 * Like the UNBOUNDED PRECEDING/FOLLOWING case, NESTED is assigned a lower
880 * precedence than PATH to fix ambiguity in the json_table production.
882 %nonassoc UNBOUNDED NESTED
/* ideally would have same precedence as IDENT */
883 %nonassoc IDENT PARTITION RANGE ROWS GROUPS PRECEDING FOLLOWING CUBE ROLLUP
884 SET KEYS OBJECT_P SCALAR VALUE_P WITH WITHOUT PATH
885 %left Op OPERATOR
/* multi-character ops and user-defined operators */
889 /* Unary Operators */
890 %left AT
/* sets precedence for AT TIME ZONE, AT LOCAL */
898 * These might seem to be low-precedence, but actually they are not part
899 * of the arithmetic hierarchy at all in their use as JOIN operators.
900 * We make them high-precedence to support their use as function names.
901 * They wouldn't be given a precedence at all, were it not that we need
902 * left-associativity among the JOIN rules themselves.
904 %left JOIN CROSS LEFT FULL RIGHT INNER_P NATURAL
909 * The target production for the whole parse.
911 * Ordinarily we parse a list of statements, but if we see one of the
912 * special MODE_XXX symbols as first token, we parse something else.
913 * The options here correspond to enum RawParseMode, which see for details.
918 pg_yyget_extra
(yyscanner
)->parsetree
= $1;
919 (void) yynerrs; /* suppress compiler warning */
921 | MODE_TYPE_NAME Typename
923 pg_yyget_extra
(yyscanner
)->parsetree
= list_make1
($2);
925 | MODE_PLPGSQL_EXPR PLpgSQL_Expr
927 pg_yyget_extra
(yyscanner
)->parsetree
=
928 list_make1
(makeRawStmt
($2, @
2));
930 | MODE_PLPGSQL_ASSIGN1 PLAssignStmt
932 PLAssignStmt
*n
= (PLAssignStmt
*) $2;
935 pg_yyget_extra
(yyscanner
)->parsetree
=
936 list_make1
(makeRawStmt
((Node
*) n
, @
2));
938 | MODE_PLPGSQL_ASSIGN2 PLAssignStmt
940 PLAssignStmt
*n
= (PLAssignStmt
*) $2;
943 pg_yyget_extra
(yyscanner
)->parsetree
=
944 list_make1
(makeRawStmt
((Node
*) n
, @
2));
946 | MODE_PLPGSQL_ASSIGN3 PLAssignStmt
948 PLAssignStmt
*n
= (PLAssignStmt
*) $2;
951 pg_yyget_extra
(yyscanner
)->parsetree
=
952 list_make1
(makeRawStmt
((Node
*) n
, @
2));
957 * At top level, we wrap each stmt with a RawStmt node carrying start location
958 * and length of the stmt's text.
959 * We also take care to discard empty statements entirely (which among other
960 * things dodges the problem of assigning them a location).
962 stmtmulti: stmtmulti
';' toplevel_stmt
966 /* update length of previous stmt */
967 updateRawStmtEnd
(llast_node
(RawStmt
, $1), @
2);
970 $$
= lappend
($1, makeRawStmt
($3, @
3));
977 $$
= list_make1
(makeRawStmt
($1, @
1));
984 * toplevel_stmt includes BEGIN and END. stmt does not include them, because
985 * those words have different meanings in function bodies.
989 | TransactionStmtLegacy
996 | AlterDatabaseSetStmt
997 | AlterDefaultPrivilegesStmt
1000 | AlterExtensionStmt
1001 | AlterExtensionContentsStmt
1003 | AlterForeignServerStmt
1006 | AlterObjectDependsStmt
1007 | AlterObjectSchemaStmt
1016 | AlterCompositeTypeStmt
1017 | AlterPublicationStmt
1020 | AlterSubscriptionStmt
1022 | AlterTSConfigurationStmt
1023 | AlterTSDictionaryStmt
1024 | AlterUserMappingStmt
1031 | ConstraintsSetStmt
1035 | CreateAssertionStmt
1037 | CreateConversionStmt
1039 | CreateExtensionStmt
1041 | CreateForeignServerStmt
1042 | CreateForeignTableStmt
1043 | CreateFunctionStmt
1047 | CreateOpFamilyStmt
1048 | CreatePublicationStmt
1055 | CreateSubscriptionStmt
1057 | CreateTableSpaceStmt
1058 | CreateTransformStmt
1060 | CreateEventTrigStmt
1063 | CreateUserMappingStmt
1076 | DropSubscriptionStmt
1077 | DropTableSpaceStmt
1080 | DropUserMappingStmt
1087 | ImportForeignSchemaStmt
1091 | RefreshMatViewStmt
1122 * Generic supporting productions for DDL
1126 |
/* EMPTY */ { $$
= NULL
; }
1130 any_name
{ $$
= $1; }
1131 |
/*EMPTY*/ { $$
= NIL
; }
1135 CONCURRENTLY
{ $$
= true
; }
1136 |
/*EMPTY*/ { $$
= false
; }
1140 CASCADE
{ $$
= DROP_CASCADE
; }
1141 | RESTRICT
{ $$
= DROP_RESTRICT
; }
1142 |
/* EMPTY */ { $$
= DROP_RESTRICT
; /* default */ }
1145 /*****************************************************************************
1149 *****************************************************************************/
1151 CallStmt: CALL func_application
1153 CallStmt
*n
= makeNode
(CallStmt
);
1155 n
->funccall
= castNode
(FuncCall
, $2);
1160 /*****************************************************************************
1162 * Create a new Postgres DBMS role
1164 *****************************************************************************/
1167 CREATE ROLE RoleId opt_with OptRoleList
1169 CreateRoleStmt
*n
= makeNode
(CreateRoleStmt
);
1171 n
->stmt_type
= ROLESTMT_ROLE
;
1185 * Options for CREATE ROLE and ALTER ROLE (also used by CREATE/ALTER USER
1186 * for backwards compatibility). Note: the only option required by SQL99
1187 * is "WITH ADMIN name".
1190 OptRoleList CreateOptRoleElem
{ $$
= lappend
($1, $2); }
1191 |
/* EMPTY */ { $$
= NIL
; }
1195 AlterOptRoleList AlterOptRoleElem
{ $$
= lappend
($1, $2); }
1196 |
/* EMPTY */ { $$
= NIL
; }
1202 $$
= makeDefElem
("password",
1203 (Node
*) makeString
($2), @
1);
1207 $$
= makeDefElem
("password", NULL
, @
1);
1209 | ENCRYPTED PASSWORD Sconst
1212 * These days, passwords are always stored in encrypted
1213 * form, so there is no difference between PASSWORD and
1214 * ENCRYPTED PASSWORD.
1216 $$
= makeDefElem
("password",
1217 (Node
*) makeString
($3), @
1);
1219 | UNENCRYPTED PASSWORD Sconst
1222 (errcode
(ERRCODE_FEATURE_NOT_SUPPORTED
),
1223 errmsg
("UNENCRYPTED PASSWORD is no longer supported"),
1224 errhint
("Remove UNENCRYPTED to store the password in encrypted form instead."),
1225 parser_errposition
(@
1)));
1229 $$
= makeDefElem
("inherit", (Node
*) makeBoolean
(true
), @
1);
1231 | CONNECTION LIMIT SignedIconst
1233 $$
= makeDefElem
("connectionlimit", (Node
*) makeInteger
($3), @
1);
1235 | VALID UNTIL Sconst
1237 $$
= makeDefElem
("validUntil", (Node
*) makeString
($3), @
1);
1239 /* Supported but not documented for roles, for use by ALTER GROUP. */
1242 $$
= makeDefElem
("rolemembers", (Node
*) $2, @
1);
1247 * We handle identifiers that aren't parser keywords with
1248 * the following special-case codes, to avoid bloating the
1249 * size of the main parser.
1251 if
(strcmp
($1, "superuser") == 0)
1252 $$
= makeDefElem
("superuser", (Node
*) makeBoolean
(true
), @
1);
1253 else if
(strcmp
($1, "nosuperuser") == 0)
1254 $$
= makeDefElem
("superuser", (Node
*) makeBoolean
(false
), @
1);
1255 else if
(strcmp
($1, "createrole") == 0)
1256 $$
= makeDefElem
("createrole", (Node
*) makeBoolean
(true
), @
1);
1257 else if
(strcmp
($1, "nocreaterole") == 0)
1258 $$
= makeDefElem
("createrole", (Node
*) makeBoolean
(false
), @
1);
1259 else if
(strcmp
($1, "replication") == 0)
1260 $$
= makeDefElem
("isreplication", (Node
*) makeBoolean
(true
), @
1);
1261 else if
(strcmp
($1, "noreplication") == 0)
1262 $$
= makeDefElem
("isreplication", (Node
*) makeBoolean
(false
), @
1);
1263 else if
(strcmp
($1, "createdb") == 0)
1264 $$
= makeDefElem
("createdb", (Node
*) makeBoolean
(true
), @
1);
1265 else if
(strcmp
($1, "nocreatedb") == 0)
1266 $$
= makeDefElem
("createdb", (Node
*) makeBoolean
(false
), @
1);
1267 else if
(strcmp
($1, "login") == 0)
1268 $$
= makeDefElem
("canlogin", (Node
*) makeBoolean
(true
), @
1);
1269 else if
(strcmp
($1, "nologin") == 0)
1270 $$
= makeDefElem
("canlogin", (Node
*) makeBoolean
(false
), @
1);
1271 else if
(strcmp
($1, "bypassrls") == 0)
1272 $$
= makeDefElem
("bypassrls", (Node
*) makeBoolean
(true
), @
1);
1273 else if
(strcmp
($1, "nobypassrls") == 0)
1274 $$
= makeDefElem
("bypassrls", (Node
*) makeBoolean
(false
), @
1);
1275 else if
(strcmp
($1, "noinherit") == 0)
1278 * Note that INHERIT is a keyword, so it's handled by main parser, but
1279 * NOINHERIT is handled here.
1281 $$
= makeDefElem
("inherit", (Node
*) makeBoolean
(false
), @
1);
1285 (errcode
(ERRCODE_SYNTAX_ERROR
),
1286 errmsg
("unrecognized role option \"%s\"", $1),
1287 parser_errposition
(@
1)));
1292 AlterOptRoleElem
{ $$
= $1; }
1293 /* The following are not supported by ALTER ROLE/USER/GROUP */
1296 $$
= makeDefElem
("sysid", (Node
*) makeInteger
($2), @
1);
1300 $$
= makeDefElem
("adminmembers", (Node
*) $2, @
1);
1304 $$
= makeDefElem
("rolemembers", (Node
*) $2, @
1);
1306 | IN_P ROLE role_list
1308 $$
= makeDefElem
("addroleto", (Node
*) $3, @
1);
1310 | IN_P GROUP_P role_list
1312 $$
= makeDefElem
("addroleto", (Node
*) $3, @
1);
1317 /*****************************************************************************
1319 * Create a new Postgres DBMS user (role with implied login ability)
1321 *****************************************************************************/
1324 CREATE USER RoleId opt_with OptRoleList
1326 CreateRoleStmt
*n
= makeNode
(CreateRoleStmt
);
1328 n
->stmt_type
= ROLESTMT_USER
;
1336 /*****************************************************************************
1338 * Alter a postgresql DBMS role
1340 *****************************************************************************/
1343 ALTER ROLE RoleSpec opt_with AlterOptRoleList
1345 AlterRoleStmt
*n
= makeNode
(AlterRoleStmt
);
1348 n
->action
= +1; /* add, if there are members */
1352 | ALTER USER RoleSpec opt_with AlterOptRoleList
1354 AlterRoleStmt
*n
= makeNode
(AlterRoleStmt
);
1357 n
->action
= +1; /* add, if there are members */
1364 /* EMPTY */ { $$
= NULL
; }
1365 | IN_P DATABASE name
{ $$
= $3; }
1369 ALTER ROLE RoleSpec opt_in_database SetResetClause
1371 AlterRoleSetStmt
*n
= makeNode
(AlterRoleSetStmt
);
1378 | ALTER ROLE ALL opt_in_database SetResetClause
1380 AlterRoleSetStmt
*n
= makeNode
(AlterRoleSetStmt
);
1387 | ALTER USER RoleSpec opt_in_database SetResetClause
1389 AlterRoleSetStmt
*n
= makeNode
(AlterRoleSetStmt
);
1396 | ALTER USER ALL opt_in_database SetResetClause
1398 AlterRoleSetStmt
*n
= makeNode
(AlterRoleSetStmt
);
1408 /*****************************************************************************
1410 * Drop a postgresql DBMS role
1412 * XXX Ideally this would have CASCADE/RESTRICT options, but a role
1413 * might own objects in multiple databases, and there is presently no way to
1414 * implement cascading to other databases. So we always behave as RESTRICT.
1415 *****************************************************************************/
1420 DropRoleStmt
*n
= makeNode
(DropRoleStmt
);
1422 n
->missing_ok
= false
;
1426 | DROP ROLE IF_P EXISTS role_list
1428 DropRoleStmt
*n
= makeNode
(DropRoleStmt
);
1430 n
->missing_ok
= true
;
1434 | DROP USER role_list
1436 DropRoleStmt
*n
= makeNode
(DropRoleStmt
);
1438 n
->missing_ok
= false
;
1442 | DROP USER IF_P EXISTS role_list
1444 DropRoleStmt
*n
= makeNode
(DropRoleStmt
);
1447 n
->missing_ok
= true
;
1450 | DROP GROUP_P role_list
1452 DropRoleStmt
*n
= makeNode
(DropRoleStmt
);
1454 n
->missing_ok
= false
;
1458 | DROP GROUP_P IF_P EXISTS role_list
1460 DropRoleStmt
*n
= makeNode
(DropRoleStmt
);
1462 n
->missing_ok
= true
;
1469 /*****************************************************************************
1471 * Create a postgresql group (role without login ability)
1473 *****************************************************************************/
1476 CREATE GROUP_P RoleId opt_with OptRoleList
1478 CreateRoleStmt
*n
= makeNode
(CreateRoleStmt
);
1480 n
->stmt_type
= ROLESTMT_GROUP
;
1488 /*****************************************************************************
1490 * Alter a postgresql group
1492 *****************************************************************************/
1495 ALTER GROUP_P RoleSpec add_drop USER role_list
1497 AlterRoleStmt
*n
= makeNode
(AlterRoleStmt
);
1501 n
->options
= list_make1
(makeDefElem
("rolemembers",
1507 add_drop: ADD_P
{ $$
= +1; }
1512 /*****************************************************************************
1514 * Manipulate a schema
1516 *****************************************************************************/
1519 CREATE SCHEMA opt_single_name AUTHORIZATION RoleSpec OptSchemaEltList
1521 CreateSchemaStmt
*n
= makeNode
(CreateSchemaStmt
);
1523 /* One can omit the schema name or the authorization id. */
1527 n
->if_not_exists
= false
;
1530 | CREATE SCHEMA ColId OptSchemaEltList
1532 CreateSchemaStmt
*n
= makeNode
(CreateSchemaStmt
);
1534 /* ...but not both */
1538 n
->if_not_exists
= false
;
1541 | CREATE SCHEMA IF_P NOT EXISTS opt_single_name AUTHORIZATION RoleSpec OptSchemaEltList
1543 CreateSchemaStmt
*n
= makeNode
(CreateSchemaStmt
);
1545 /* schema name can be omitted here, too */
1550 (errcode
(ERRCODE_FEATURE_NOT_SUPPORTED
),
1551 errmsg
("CREATE SCHEMA IF NOT EXISTS cannot include schema elements"),
1552 parser_errposition
(@
9)));
1554 n
->if_not_exists
= true
;
1557 | CREATE SCHEMA IF_P NOT EXISTS ColId OptSchemaEltList
1559 CreateSchemaStmt
*n
= makeNode
(CreateSchemaStmt
);
1561 /* ...but not here */
1566 (errcode
(ERRCODE_FEATURE_NOT_SUPPORTED
),
1567 errmsg
("CREATE SCHEMA IF NOT EXISTS cannot include schema elements"),
1568 parser_errposition
(@
7)));
1570 n
->if_not_exists
= true
;
1576 OptSchemaEltList schema_stmt
1578 $$
= lappend
($1, $2);
1585 * schema_stmt are the ones that can show up inside a CREATE SCHEMA
1586 * statement (in addition to by themselves).
1598 /*****************************************************************************
1600 * Set PG internal variable
1601 * SET name TO 'var_value'
1602 * Include SQL syntax (thomas 1997-10-22):
1603 * SET TIME ZONE 'var_value'
1605 *****************************************************************************/
1610 VariableSetStmt
*n
= $2;
1612 n
->is_local
= false
;
1615 | SET LOCAL set_rest
1617 VariableSetStmt
*n
= $3;
1622 | SET SESSION set_rest
1624 VariableSetStmt
*n
= $3;
1626 n
->is_local
= false
;
1632 TRANSACTION transaction_mode_list
1634 VariableSetStmt
*n
= makeNode
(VariableSetStmt
);
1636 n
->kind
= VAR_SET_MULTI
;
1637 n
->name
= "TRANSACTION";
1639 n
->jumble_args
= true
;
1643 | SESSION CHARACTERISTICS AS TRANSACTION transaction_mode_list
1645 VariableSetStmt
*n
= makeNode
(VariableSetStmt
);
1647 n
->kind
= VAR_SET_MULTI
;
1648 n
->name
= "SESSION CHARACTERISTICS";
1650 n
->jumble_args
= true
;
1658 var_name TO var_list
1660 VariableSetStmt
*n
= makeNode
(VariableSetStmt
);
1662 n
->kind
= VAR_SET_VALUE
;
1668 | var_name
'=' var_list
1670 VariableSetStmt
*n
= makeNode
(VariableSetStmt
);
1672 n
->kind
= VAR_SET_VALUE
;
1678 | var_name TO DEFAULT
1680 VariableSetStmt
*n
= makeNode
(VariableSetStmt
);
1682 n
->kind
= VAR_SET_DEFAULT
;
1687 | var_name
'=' DEFAULT
1689 VariableSetStmt
*n
= makeNode
(VariableSetStmt
);
1691 n
->kind
= VAR_SET_DEFAULT
;
1698 set_rest_more: /* Generic SET syntaxes: */
1699 generic_set
{$$
= $1;}
1700 | var_name FROM CURRENT_P
1702 VariableSetStmt
*n
= makeNode
(VariableSetStmt
);
1704 n
->kind
= VAR_SET_CURRENT
;
1709 /* Special syntaxes mandated by SQL standard: */
1710 | TIME ZONE zone_value
1712 VariableSetStmt
*n
= makeNode
(VariableSetStmt
);
1714 n
->kind
= VAR_SET_VALUE
;
1715 n
->name
= "timezone";
1717 n
->jumble_args
= true
;
1719 n
->args
= list_make1
($3);
1721 n
->kind
= VAR_SET_DEFAULT
;
1727 (errcode
(ERRCODE_FEATURE_NOT_SUPPORTED
),
1728 errmsg
("current database cannot be changed"),
1729 parser_errposition
(@
2)));
1730 $$
= NULL
; /*not reached*/
1734 VariableSetStmt
*n
= makeNode
(VariableSetStmt
);
1736 n
->kind
= VAR_SET_VALUE
;
1737 n
->name
= "search_path";
1738 n
->args
= list_make1
(makeStringConst
($2, @
2));
1742 | NAMES opt_encoding
1744 VariableSetStmt
*n
= makeNode
(VariableSetStmt
);
1746 n
->kind
= VAR_SET_VALUE
;
1747 n
->name
= "client_encoding";
1750 n
->args
= list_make1
(makeStringConst
($2, @
2));
1752 n
->kind
= VAR_SET_DEFAULT
;
1755 | ROLE NonReservedWord_or_Sconst
1757 VariableSetStmt
*n
= makeNode
(VariableSetStmt
);
1759 n
->kind
= VAR_SET_VALUE
;
1761 n
->args
= list_make1
(makeStringConst
($2, @
2));
1765 | SESSION AUTHORIZATION NonReservedWord_or_Sconst
1767 VariableSetStmt
*n
= makeNode
(VariableSetStmt
);
1769 n
->kind
= VAR_SET_VALUE
;
1770 n
->name
= "session_authorization";
1771 n
->args
= list_make1
(makeStringConst
($3, @
3));
1775 | SESSION AUTHORIZATION DEFAULT
1777 VariableSetStmt
*n
= makeNode
(VariableSetStmt
);
1779 n
->kind
= VAR_SET_DEFAULT
;
1780 n
->name
= "session_authorization";
1784 | XML_P OPTION document_or_content
1786 VariableSetStmt
*n
= makeNode
(VariableSetStmt
);
1788 n
->kind
= VAR_SET_VALUE
;
1789 n
->name
= "xmloption";
1790 n
->args
= list_make1
(makeStringConst
($3 == XMLOPTION_DOCUMENT ?
"DOCUMENT" : "CONTENT", @
3));
1791 n
->jumble_args
= true
;
1795 /* Special syntaxes invented by PostgreSQL: */
1796 | TRANSACTION SNAPSHOT Sconst
1798 VariableSetStmt
*n
= makeNode
(VariableSetStmt
);
1800 n
->kind
= VAR_SET_MULTI
;
1801 n
->name
= "TRANSACTION SNAPSHOT";
1802 n
->args
= list_make1
(makeStringConst
($3, @
3));
1808 var_name: ColId
{ $$
= $1; }
1809 | var_name
'.' ColId
1810 { $$
= psprintf
("%s.%s", $1, $3); }
1813 var_list: var_value
{ $$
= list_make1
($1); }
1814 | var_list
',' var_value
{ $$
= lappend
($1, $3); }
1817 var_value: opt_boolean_or_string
1818 { $$
= makeStringConst
($1, @
1); }
1820 { $$
= makeAConst
($1, @
1); }
1823 iso_level: READ UNCOMMITTED
{ $$
= "read uncommitted"; }
1824 | READ COMMITTED
{ $$
= "read committed"; }
1825 | REPEATABLE READ
{ $$
= "repeatable read"; }
1826 | SERIALIZABLE
{ $$
= "serializable"; }
1829 opt_boolean_or_string:
1830 TRUE_P
{ $$
= "true"; }
1831 | FALSE_P
{ $$
= "false"; }
1834 * OFF is also accepted as a boolean value, but is handled by
1835 * the NonReservedWord rule. The action for booleans and strings
1836 * is the same, so we don't need to distinguish them here.
1838 | NonReservedWord_or_Sconst
{ $$
= $1; }
1841 /* Timezone values can be:
1842 * - a string such as 'pst8pdt'
1843 * - an identifier such as "pst8pdt"
1844 * - an integer or floating point number
1845 * - a time interval per SQL99
1846 * ColId gives reduce/reduce errors against ConstInterval and LOCAL,
1847 * so use IDENT (meaning we reject anything that is a key word).
1852 $$
= makeStringConst
($1, @
1);
1856 $$
= makeStringConst
($1, @
1);
1858 | ConstInterval Sconst opt_interval
1864 A_Const
*n
= (A_Const
*) linitial
($3);
1866 if
((n
->val.ival.ival
& ~
(INTERVAL_MASK
(HOUR
) | INTERVAL_MASK
(MINUTE
))) != 0)
1868 (errcode
(ERRCODE_SYNTAX_ERROR
),
1869 errmsg
("time zone interval must be HOUR or HOUR TO MINUTE"),
1870 parser_errposition
(@
3)));
1873 $$
= makeStringConstCast
($2, @
2, t
);
1875 | ConstInterval
'(' Iconst
')' Sconst
1879 t
->typmods
= list_make2
(makeIntConst
(INTERVAL_FULL_RANGE
, -1),
1880 makeIntConst
($3, @
3));
1881 $$
= makeStringConstCast
($5, @
5, t
);
1883 | NumericOnly
{ $$
= makeAConst
($1, @
1); }
1884 | DEFAULT
{ $$
= NULL
; }
1885 | LOCAL
{ $$
= NULL
; }
1890 | DEFAULT
{ $$
= NULL
; }
1891 |
/*EMPTY*/ { $$
= NULL
; }
1894 NonReservedWord_or_Sconst:
1895 NonReservedWord
{ $$
= $1; }
1896 | Sconst
{ $$
= $1; }
1900 RESET reset_rest
{ $$
= (Node
*) $2; }
1904 generic_reset
{ $$
= $1; }
1907 VariableSetStmt
*n
= makeNode
(VariableSetStmt
);
1909 n
->kind
= VAR_RESET
;
1910 n
->name
= "timezone";
1914 | TRANSACTION ISOLATION LEVEL
1916 VariableSetStmt
*n
= makeNode
(VariableSetStmt
);
1918 n
->kind
= VAR_RESET
;
1919 n
->name
= "transaction_isolation";
1923 | SESSION AUTHORIZATION
1925 VariableSetStmt
*n
= makeNode
(VariableSetStmt
);
1927 n
->kind
= VAR_RESET
;
1928 n
->name
= "session_authorization";
1937 VariableSetStmt
*n
= makeNode
(VariableSetStmt
);
1939 n
->kind
= VAR_RESET
;
1946 VariableSetStmt
*n
= makeNode
(VariableSetStmt
);
1948 n
->kind
= VAR_RESET_ALL
;
1954 /* SetResetClause allows SET or RESET without LOCAL */
1956 SET set_rest
{ $$
= $2; }
1957 | VariableResetStmt
{ $$
= (VariableSetStmt
*) $1; }
1960 /* SetResetClause allows SET or RESET without LOCAL */
1961 FunctionSetResetClause:
1962 SET set_rest_more
{ $$
= $2; }
1963 | VariableResetStmt
{ $$
= (VariableSetStmt
*) $1; }
1970 VariableShowStmt
*n
= makeNode
(VariableShowStmt
);
1977 VariableShowStmt
*n
= makeNode
(VariableShowStmt
);
1979 n
->name
= "timezone";
1982 | SHOW TRANSACTION ISOLATION LEVEL
1984 VariableShowStmt
*n
= makeNode
(VariableShowStmt
);
1986 n
->name
= "transaction_isolation";
1989 | SHOW SESSION AUTHORIZATION
1991 VariableShowStmt
*n
= makeNode
(VariableShowStmt
);
1993 n
->name
= "session_authorization";
1998 VariableShowStmt
*n
= makeNode
(VariableShowStmt
);
2007 SET CONSTRAINTS constraints_set_list constraints_set_mode
2009 ConstraintsSetStmt
*n
= makeNode
(ConstraintsSetStmt
);
2011 n
->constraints
= $3;
2017 constraints_set_list:
2019 | qualified_name_list
{ $$
= $1; }
2022 constraints_set_mode:
2023 DEFERRED
{ $$
= true
; }
2024 | IMMEDIATE
{ $$
= false
; }
2029 * Checkpoint statement
2034 CheckPointStmt
*n
= makeNode
(CheckPointStmt
);
2041 /*****************************************************************************
2043 * DISCARD { ALL | TEMP | PLANS | SEQUENCES }
2045 *****************************************************************************/
2050 DiscardStmt
*n
= makeNode
(DiscardStmt
);
2052 n
->target
= DISCARD_ALL
;
2057 DiscardStmt
*n
= makeNode
(DiscardStmt
);
2059 n
->target
= DISCARD_TEMP
;
2064 DiscardStmt
*n
= makeNode
(DiscardStmt
);
2066 n
->target
= DISCARD_TEMP
;
2071 DiscardStmt
*n
= makeNode
(DiscardStmt
);
2073 n
->target
= DISCARD_PLANS
;
2078 DiscardStmt
*n
= makeNode
(DiscardStmt
);
2080 n
->target
= DISCARD_SEQUENCES
;
2087 /*****************************************************************************
2089 * ALTER [ TABLE | INDEX | SEQUENCE | VIEW | MATERIALIZED VIEW | FOREIGN TABLE ] variations
2091 * Note: we accept all subcommands for each of the variants, and sort
2092 * out what's really legal at execution time.
2093 *****************************************************************************/
2096 ALTER TABLE relation_expr alter_table_cmds
2098 AlterTableStmt
*n
= makeNode
(AlterTableStmt
);
2102 n
->objtype
= OBJECT_TABLE
;
2103 n
->missing_ok
= false
;
2106 | ALTER TABLE IF_P EXISTS relation_expr alter_table_cmds
2108 AlterTableStmt
*n
= makeNode
(AlterTableStmt
);
2112 n
->objtype
= OBJECT_TABLE
;
2113 n
->missing_ok
= true
;
2116 | ALTER TABLE relation_expr partition_cmd
2118 AlterTableStmt
*n
= makeNode
(AlterTableStmt
);
2121 n
->cmds
= list_make1
($4);
2122 n
->objtype
= OBJECT_TABLE
;
2123 n
->missing_ok
= false
;
2126 | ALTER TABLE IF_P EXISTS relation_expr partition_cmd
2128 AlterTableStmt
*n
= makeNode
(AlterTableStmt
);
2131 n
->cmds
= list_make1
($6);
2132 n
->objtype
= OBJECT_TABLE
;
2133 n
->missing_ok
= true
;
2136 | ALTER TABLE ALL IN_P TABLESPACE name SET TABLESPACE name opt_nowait
2138 AlterTableMoveAllStmt
*n
=
2139 makeNode
(AlterTableMoveAllStmt
);
2141 n
->orig_tablespacename
= $6;
2142 n
->objtype
= OBJECT_TABLE
;
2144 n
->new_tablespacename
= $9;
2148 | ALTER TABLE ALL IN_P TABLESPACE name OWNED BY role_list SET TABLESPACE name opt_nowait
2150 AlterTableMoveAllStmt
*n
=
2151 makeNode
(AlterTableMoveAllStmt
);
2153 n
->orig_tablespacename
= $6;
2154 n
->objtype
= OBJECT_TABLE
;
2156 n
->new_tablespacename
= $12;
2160 | ALTER INDEX qualified_name alter_table_cmds
2162 AlterTableStmt
*n
= makeNode
(AlterTableStmt
);
2166 n
->objtype
= OBJECT_INDEX
;
2167 n
->missing_ok
= false
;
2170 | ALTER INDEX IF_P EXISTS qualified_name alter_table_cmds
2172 AlterTableStmt
*n
= makeNode
(AlterTableStmt
);
2176 n
->objtype
= OBJECT_INDEX
;
2177 n
->missing_ok
= true
;
2180 | ALTER INDEX qualified_name index_partition_cmd
2182 AlterTableStmt
*n
= makeNode
(AlterTableStmt
);
2185 n
->cmds
= list_make1
($4);
2186 n
->objtype
= OBJECT_INDEX
;
2187 n
->missing_ok
= false
;
2190 | ALTER INDEX ALL IN_P TABLESPACE name SET TABLESPACE name opt_nowait
2192 AlterTableMoveAllStmt
*n
=
2193 makeNode
(AlterTableMoveAllStmt
);
2195 n
->orig_tablespacename
= $6;
2196 n
->objtype
= OBJECT_INDEX
;
2198 n
->new_tablespacename
= $9;
2202 | ALTER INDEX ALL IN_P TABLESPACE name OWNED BY role_list SET TABLESPACE name opt_nowait
2204 AlterTableMoveAllStmt
*n
=
2205 makeNode
(AlterTableMoveAllStmt
);
2207 n
->orig_tablespacename
= $6;
2208 n
->objtype
= OBJECT_INDEX
;
2210 n
->new_tablespacename
= $12;
2214 | ALTER SEQUENCE qualified_name alter_table_cmds
2216 AlterTableStmt
*n
= makeNode
(AlterTableStmt
);
2220 n
->objtype
= OBJECT_SEQUENCE
;
2221 n
->missing_ok
= false
;
2224 | ALTER SEQUENCE IF_P EXISTS qualified_name alter_table_cmds
2226 AlterTableStmt
*n
= makeNode
(AlterTableStmt
);
2230 n
->objtype
= OBJECT_SEQUENCE
;
2231 n
->missing_ok
= true
;
2234 | ALTER VIEW qualified_name alter_table_cmds
2236 AlterTableStmt
*n
= makeNode
(AlterTableStmt
);
2240 n
->objtype
= OBJECT_VIEW
;
2241 n
->missing_ok
= false
;
2244 | ALTER VIEW IF_P EXISTS qualified_name alter_table_cmds
2246 AlterTableStmt
*n
= makeNode
(AlterTableStmt
);
2250 n
->objtype
= OBJECT_VIEW
;
2251 n
->missing_ok
= true
;
2254 | ALTER MATERIALIZED VIEW qualified_name alter_table_cmds
2256 AlterTableStmt
*n
= makeNode
(AlterTableStmt
);
2260 n
->objtype
= OBJECT_MATVIEW
;
2261 n
->missing_ok
= false
;
2264 | ALTER MATERIALIZED VIEW IF_P EXISTS qualified_name alter_table_cmds
2266 AlterTableStmt
*n
= makeNode
(AlterTableStmt
);
2270 n
->objtype
= OBJECT_MATVIEW
;
2271 n
->missing_ok
= true
;
2274 | ALTER MATERIALIZED VIEW ALL IN_P TABLESPACE name SET TABLESPACE name opt_nowait
2276 AlterTableMoveAllStmt
*n
=
2277 makeNode
(AlterTableMoveAllStmt
);
2279 n
->orig_tablespacename
= $7;
2280 n
->objtype
= OBJECT_MATVIEW
;
2282 n
->new_tablespacename
= $10;
2286 | ALTER MATERIALIZED VIEW ALL IN_P TABLESPACE name OWNED BY role_list SET TABLESPACE name opt_nowait
2288 AlterTableMoveAllStmt
*n
=
2289 makeNode
(AlterTableMoveAllStmt
);
2291 n
->orig_tablespacename
= $7;
2292 n
->objtype
= OBJECT_MATVIEW
;
2294 n
->new_tablespacename
= $13;
2298 | ALTER FOREIGN TABLE relation_expr alter_table_cmds
2300 AlterTableStmt
*n
= makeNode
(AlterTableStmt
);
2304 n
->objtype
= OBJECT_FOREIGN_TABLE
;
2305 n
->missing_ok
= false
;
2308 | ALTER FOREIGN TABLE IF_P EXISTS relation_expr alter_table_cmds
2310 AlterTableStmt
*n
= makeNode
(AlterTableStmt
);
2314 n
->objtype
= OBJECT_FOREIGN_TABLE
;
2315 n
->missing_ok
= true
;
2321 alter_table_cmd
{ $$
= list_make1
($1); }
2322 | alter_table_cmds
',' alter_table_cmd
{ $$
= lappend
($1, $3); }
2326 /* ALTER TABLE <name> ATTACH PARTITION <table_name> FOR VALUES */
2327 ATTACH PARTITION qualified_name PartitionBoundSpec
2329 AlterTableCmd
*n
= makeNode
(AlterTableCmd
);
2330 PartitionCmd
*cmd
= makeNode
(PartitionCmd
);
2332 n
->subtype
= AT_AttachPartition
;
2335 cmd
->concurrent
= false
;
2336 n
->def
= (Node
*) cmd
;
2340 /* ALTER TABLE <name> DETACH PARTITION <partition_name> [CONCURRENTLY] */
2341 | DETACH PARTITION qualified_name opt_concurrently
2343 AlterTableCmd
*n
= makeNode
(AlterTableCmd
);
2344 PartitionCmd
*cmd
= makeNode
(PartitionCmd
);
2346 n
->subtype
= AT_DetachPartition
;
2349 cmd
->concurrent
= $4;
2350 n
->def
= (Node
*) cmd
;
2354 | DETACH PARTITION qualified_name FINALIZE
2356 AlterTableCmd
*n
= makeNode
(AlterTableCmd
);
2357 PartitionCmd
*cmd
= makeNode
(PartitionCmd
);
2359 n
->subtype
= AT_DetachPartitionFinalize
;
2362 cmd
->concurrent
= false
;
2363 n
->def
= (Node
*) cmd
;
2368 index_partition_cmd:
2369 /* ALTER INDEX <name> ATTACH PARTITION <index_name> */
2370 ATTACH PARTITION qualified_name
2372 AlterTableCmd
*n
= makeNode
(AlterTableCmd
);
2373 PartitionCmd
*cmd
= makeNode
(PartitionCmd
);
2375 n
->subtype
= AT_AttachPartition
;
2378 cmd
->concurrent
= false
;
2379 n
->def
= (Node
*) cmd
;
2386 /* ALTER TABLE <name> ADD <coldef> */
2389 AlterTableCmd
*n
= makeNode
(AlterTableCmd
);
2391 n
->subtype
= AT_AddColumn
;
2393 n
->missing_ok
= false
;
2396 /* ALTER TABLE <name> ADD IF NOT EXISTS <coldef> */
2397 | ADD_P IF_P NOT EXISTS columnDef
2399 AlterTableCmd
*n
= makeNode
(AlterTableCmd
);
2401 n
->subtype
= AT_AddColumn
;
2403 n
->missing_ok
= true
;
2406 /* ALTER TABLE <name> ADD COLUMN <coldef> */
2407 | ADD_P COLUMN columnDef
2409 AlterTableCmd
*n
= makeNode
(AlterTableCmd
);
2411 n
->subtype
= AT_AddColumn
;
2413 n
->missing_ok
= false
;
2416 /* ALTER TABLE <name> ADD COLUMN IF NOT EXISTS <coldef> */
2417 | ADD_P COLUMN IF_P NOT EXISTS columnDef
2419 AlterTableCmd
*n
= makeNode
(AlterTableCmd
);
2421 n
->subtype
= AT_AddColumn
;
2423 n
->missing_ok
= true
;
2426 /* ALTER TABLE <name> ALTER [COLUMN] <colname> {SET DEFAULT <expr>|DROP DEFAULT} */
2427 | ALTER opt_column ColId alter_column_default
2429 AlterTableCmd
*n
= makeNode
(AlterTableCmd
);
2431 n
->subtype
= AT_ColumnDefault
;
2436 /* ALTER TABLE <name> ALTER [COLUMN] <colname> DROP NOT NULL */
2437 | ALTER opt_column ColId DROP NOT NULL_P
2439 AlterTableCmd
*n
= makeNode
(AlterTableCmd
);
2441 n
->subtype
= AT_DropNotNull
;
2445 /* ALTER TABLE <name> ALTER [COLUMN] <colname> SET NOT NULL */
2446 | ALTER opt_column ColId SET NOT NULL_P
2448 AlterTableCmd
*n
= makeNode
(AlterTableCmd
);
2450 n
->subtype
= AT_SetNotNull
;
2454 /* ALTER TABLE <name> ALTER [COLUMN] <colname> SET EXPRESSION AS <expr> */
2455 | ALTER opt_column ColId SET EXPRESSION AS
'(' a_expr
')'
2457 AlterTableCmd
*n
= makeNode
(AlterTableCmd
);
2459 n
->subtype
= AT_SetExpression
;
2464 /* ALTER TABLE <name> ALTER [COLUMN] <colname> DROP EXPRESSION */
2465 | ALTER opt_column ColId DROP EXPRESSION
2467 AlterTableCmd
*n
= makeNode
(AlterTableCmd
);
2469 n
->subtype
= AT_DropExpression
;
2473 /* ALTER TABLE <name> ALTER [COLUMN] <colname> DROP EXPRESSION IF EXISTS */
2474 | ALTER opt_column ColId DROP EXPRESSION IF_P EXISTS
2476 AlterTableCmd
*n
= makeNode
(AlterTableCmd
);
2478 n
->subtype
= AT_DropExpression
;
2480 n
->missing_ok
= true
;
2483 /* ALTER TABLE <name> ALTER [COLUMN] <colname> SET STATISTICS */
2484 | ALTER opt_column ColId SET STATISTICS set_statistics_value
2486 AlterTableCmd
*n
= makeNode
(AlterTableCmd
);
2488 n
->subtype
= AT_SetStatistics
;
2493 /* ALTER TABLE <name> ALTER [COLUMN] <colnum> SET STATISTICS */
2494 | ALTER opt_column Iconst SET STATISTICS set_statistics_value
2496 AlterTableCmd
*n
= makeNode
(AlterTableCmd
);
2498 if
($3 <= 0 ||
$3 > PG_INT16_MAX
)
2500 (errcode
(ERRCODE_INVALID_PARAMETER_VALUE
),
2501 errmsg
("column number must be in range from 1 to %d", PG_INT16_MAX
),
2502 parser_errposition
(@
3)));
2504 n
->subtype
= AT_SetStatistics
;
2505 n
->num
= (int16
) $3;
2509 /* ALTER TABLE <name> ALTER [COLUMN] <colname> SET ( column_parameter = value [, ... ] ) */
2510 | ALTER opt_column ColId SET reloptions
2512 AlterTableCmd
*n
= makeNode
(AlterTableCmd
);
2514 n
->subtype
= AT_SetOptions
;
2516 n
->def
= (Node
*) $5;
2519 /* ALTER TABLE <name> ALTER [COLUMN] <colname> RESET ( column_parameter [, ... ] ) */
2520 | ALTER opt_column ColId RESET reloptions
2522 AlterTableCmd
*n
= makeNode
(AlterTableCmd
);
2524 n
->subtype
= AT_ResetOptions
;
2526 n
->def
= (Node
*) $5;
2529 /* ALTER TABLE <name> ALTER [COLUMN] <colname> SET STORAGE <storagemode> */
2530 | ALTER opt_column ColId SET column_storage
2532 AlterTableCmd
*n
= makeNode
(AlterTableCmd
);
2534 n
->subtype
= AT_SetStorage
;
2536 n
->def
= (Node
*) makeString
($5);
2539 /* ALTER TABLE <name> ALTER [COLUMN] <colname> SET COMPRESSION <cm> */
2540 | ALTER opt_column ColId SET column_compression
2542 AlterTableCmd
*n
= makeNode
(AlterTableCmd
);
2544 n
->subtype
= AT_SetCompression
;
2546 n
->def
= (Node
*) makeString
($5);
2549 /* ALTER TABLE <name> ALTER [COLUMN] <colname> ADD GENERATED ... AS IDENTITY ... */
2550 | ALTER opt_column ColId ADD_P GENERATED generated_when AS IDENTITY_P OptParenthesizedSeqOptList
2552 AlterTableCmd
*n
= makeNode
(AlterTableCmd
);
2553 Constraint
*c
= makeNode
(Constraint
);
2555 c
->contype
= CONSTR_IDENTITY
;
2556 c
->generated_when
= $6;
2560 n
->subtype
= AT_AddIdentity
;
2562 n
->def
= (Node
*) c
;
2566 /* ALTER TABLE <name> ALTER [COLUMN] <colname> SET <sequence options>/RESET */
2567 | ALTER opt_column ColId alter_identity_column_option_list
2569 AlterTableCmd
*n
= makeNode
(AlterTableCmd
);
2571 n
->subtype
= AT_SetIdentity
;
2573 n
->def
= (Node
*) $4;
2576 /* ALTER TABLE <name> ALTER [COLUMN] <colname> DROP IDENTITY */
2577 | ALTER opt_column ColId DROP IDENTITY_P
2579 AlterTableCmd
*n
= makeNode
(AlterTableCmd
);
2581 n
->subtype
= AT_DropIdentity
;
2583 n
->missing_ok
= false
;
2586 /* ALTER TABLE <name> ALTER [COLUMN] <colname> DROP IDENTITY IF EXISTS */
2587 | ALTER opt_column ColId DROP IDENTITY_P IF_P EXISTS
2589 AlterTableCmd
*n
= makeNode
(AlterTableCmd
);
2591 n
->subtype
= AT_DropIdentity
;
2593 n
->missing_ok
= true
;
2596 /* ALTER TABLE <name> DROP [COLUMN] IF EXISTS <colname> [RESTRICT|CASCADE] */
2597 | DROP opt_column IF_P EXISTS ColId opt_drop_behavior
2599 AlterTableCmd
*n
= makeNode
(AlterTableCmd
);
2601 n
->subtype
= AT_DropColumn
;
2604 n
->missing_ok
= true
;
2607 /* ALTER TABLE <name> DROP [COLUMN] <colname> [RESTRICT|CASCADE] */
2608 | DROP opt_column ColId opt_drop_behavior
2610 AlterTableCmd
*n
= makeNode
(AlterTableCmd
);
2612 n
->subtype
= AT_DropColumn
;
2615 n
->missing_ok
= false
;
2619 * ALTER TABLE <name> ALTER [COLUMN] <colname> [SET DATA] TYPE <typename>
2620 * [ USING <expression> ]
2622 | ALTER opt_column ColId opt_set_data TYPE_P Typename opt_collate_clause alter_using
2624 AlterTableCmd
*n
= makeNode
(AlterTableCmd
);
2625 ColumnDef
*def
= makeNode
(ColumnDef
);
2627 n
->subtype
= AT_AlterColumnType
;
2629 n
->def
= (Node
*) def
;
2630 /* We only use these fields of the ColumnDef node */
2632 def
->collClause
= (CollateClause
*) $7;
2633 def
->raw_default
= $8;
2637 /* ALTER FOREIGN TABLE <name> ALTER [COLUMN] <colname> OPTIONS */
2638 | ALTER opt_column ColId alter_generic_options
2640 AlterTableCmd
*n
= makeNode
(AlterTableCmd
);
2642 n
->subtype
= AT_AlterColumnGenericOptions
;
2644 n
->def
= (Node
*) $4;
2647 /* ALTER TABLE <name> ADD CONSTRAINT ... */
2648 | ADD_P TableConstraint
2650 AlterTableCmd
*n
= makeNode
(AlterTableCmd
);
2652 n
->subtype
= AT_AddConstraint
;
2656 /* ALTER TABLE <name> ALTER CONSTRAINT ... */
2657 | ALTER CONSTRAINT name ConstraintAttributeSpec
2659 AlterTableCmd
*n
= makeNode
(AlterTableCmd
);
2660 Constraint
*c
= makeNode
(Constraint
);
2662 n
->subtype
= AT_AlterConstraint
;
2663 n
->def
= (Node
*) c
;
2664 c
->contype
= CONSTR_FOREIGN
; /* others not supported, yet */
2666 processCASbits
($4, @
4, "ALTER CONSTRAINT statement",
2669 NULL
, NULL
, NULL
, yyscanner
);
2672 /* ALTER TABLE <name> VALIDATE CONSTRAINT ... */
2673 | VALIDATE CONSTRAINT name
2675 AlterTableCmd
*n
= makeNode
(AlterTableCmd
);
2677 n
->subtype
= AT_ValidateConstraint
;
2681 /* ALTER TABLE <name> DROP CONSTRAINT IF EXISTS <name> [RESTRICT|CASCADE] */
2682 | DROP CONSTRAINT IF_P EXISTS name opt_drop_behavior
2684 AlterTableCmd
*n
= makeNode
(AlterTableCmd
);
2686 n
->subtype
= AT_DropConstraint
;
2689 n
->missing_ok
= true
;
2692 /* ALTER TABLE <name> DROP CONSTRAINT <name> [RESTRICT|CASCADE] */
2693 | DROP CONSTRAINT name opt_drop_behavior
2695 AlterTableCmd
*n
= makeNode
(AlterTableCmd
);
2697 n
->subtype
= AT_DropConstraint
;
2700 n
->missing_ok
= false
;
2703 /* ALTER TABLE <name> SET WITHOUT OIDS, for backward compat */
2706 AlterTableCmd
*n
= makeNode
(AlterTableCmd
);
2708 n
->subtype
= AT_DropOids
;
2711 /* ALTER TABLE <name> CLUSTER ON <indexname> */
2714 AlterTableCmd
*n
= makeNode
(AlterTableCmd
);
2716 n
->subtype
= AT_ClusterOn
;
2720 /* ALTER TABLE <name> SET WITHOUT CLUSTER */
2721 | SET WITHOUT CLUSTER
2723 AlterTableCmd
*n
= makeNode
(AlterTableCmd
);
2725 n
->subtype
= AT_DropCluster
;
2729 /* ALTER TABLE <name> SET LOGGED */
2732 AlterTableCmd
*n
= makeNode
(AlterTableCmd
);
2734 n
->subtype
= AT_SetLogged
;
2737 /* ALTER TABLE <name> SET UNLOGGED */
2740 AlterTableCmd
*n
= makeNode
(AlterTableCmd
);
2742 n
->subtype
= AT_SetUnLogged
;
2745 /* ALTER TABLE <name> ENABLE TRIGGER <trig> */
2746 | ENABLE_P TRIGGER name
2748 AlterTableCmd
*n
= makeNode
(AlterTableCmd
);
2750 n
->subtype
= AT_EnableTrig
;
2754 /* ALTER TABLE <name> ENABLE ALWAYS TRIGGER <trig> */
2755 | ENABLE_P ALWAYS TRIGGER name
2757 AlterTableCmd
*n
= makeNode
(AlterTableCmd
);
2759 n
->subtype
= AT_EnableAlwaysTrig
;
2763 /* ALTER TABLE <name> ENABLE REPLICA TRIGGER <trig> */
2764 | ENABLE_P REPLICA TRIGGER name
2766 AlterTableCmd
*n
= makeNode
(AlterTableCmd
);
2768 n
->subtype
= AT_EnableReplicaTrig
;
2772 /* ALTER TABLE <name> ENABLE TRIGGER ALL */
2773 | ENABLE_P TRIGGER ALL
2775 AlterTableCmd
*n
= makeNode
(AlterTableCmd
);
2777 n
->subtype
= AT_EnableTrigAll
;
2780 /* ALTER TABLE <name> ENABLE TRIGGER USER */
2781 | ENABLE_P TRIGGER USER
2783 AlterTableCmd
*n
= makeNode
(AlterTableCmd
);
2785 n
->subtype
= AT_EnableTrigUser
;
2788 /* ALTER TABLE <name> DISABLE TRIGGER <trig> */
2789 | DISABLE_P TRIGGER name
2791 AlterTableCmd
*n
= makeNode
(AlterTableCmd
);
2793 n
->subtype
= AT_DisableTrig
;
2797 /* ALTER TABLE <name> DISABLE TRIGGER ALL */
2798 | DISABLE_P TRIGGER ALL
2800 AlterTableCmd
*n
= makeNode
(AlterTableCmd
);
2802 n
->subtype
= AT_DisableTrigAll
;
2805 /* ALTER TABLE <name> DISABLE TRIGGER USER */
2806 | DISABLE_P TRIGGER USER
2808 AlterTableCmd
*n
= makeNode
(AlterTableCmd
);
2810 n
->subtype
= AT_DisableTrigUser
;
2813 /* ALTER TABLE <name> ENABLE RULE <rule> */
2814 | ENABLE_P RULE name
2816 AlterTableCmd
*n
= makeNode
(AlterTableCmd
);
2818 n
->subtype
= AT_EnableRule
;
2822 /* ALTER TABLE <name> ENABLE ALWAYS RULE <rule> */
2823 | ENABLE_P ALWAYS RULE name
2825 AlterTableCmd
*n
= makeNode
(AlterTableCmd
);
2827 n
->subtype
= AT_EnableAlwaysRule
;
2831 /* ALTER TABLE <name> ENABLE REPLICA RULE <rule> */
2832 | ENABLE_P REPLICA RULE name
2834 AlterTableCmd
*n
= makeNode
(AlterTableCmd
);
2836 n
->subtype
= AT_EnableReplicaRule
;
2840 /* ALTER TABLE <name> DISABLE RULE <rule> */
2841 | DISABLE_P RULE name
2843 AlterTableCmd
*n
= makeNode
(AlterTableCmd
);
2845 n
->subtype
= AT_DisableRule
;
2849 /* ALTER TABLE <name> INHERIT <parent> */
2850 | INHERIT qualified_name
2852 AlterTableCmd
*n
= makeNode
(AlterTableCmd
);
2854 n
->subtype
= AT_AddInherit
;
2855 n
->def
= (Node
*) $2;
2858 /* ALTER TABLE <name> NO INHERIT <parent> */
2859 | NO INHERIT qualified_name
2861 AlterTableCmd
*n
= makeNode
(AlterTableCmd
);
2863 n
->subtype
= AT_DropInherit
;
2864 n
->def
= (Node
*) $3;
2867 /* ALTER TABLE <name> OF <type_name> */
2870 AlterTableCmd
*n
= makeNode
(AlterTableCmd
);
2871 TypeName
*def
= makeTypeNameFromNameList
($2);
2874 n
->subtype
= AT_AddOf
;
2875 n
->def
= (Node
*) def
;
2878 /* ALTER TABLE <name> NOT OF */
2881 AlterTableCmd
*n
= makeNode
(AlterTableCmd
);
2883 n
->subtype
= AT_DropOf
;
2886 /* ALTER TABLE <name> OWNER TO RoleSpec */
2889 AlterTableCmd
*n
= makeNode
(AlterTableCmd
);
2891 n
->subtype
= AT_ChangeOwner
;
2895 /* ALTER TABLE <name> SET ACCESS METHOD { <amname> | DEFAULT } */
2896 | SET ACCESS METHOD set_access_method_name
2898 AlterTableCmd
*n
= makeNode
(AlterTableCmd
);
2900 n
->subtype
= AT_SetAccessMethod
;
2904 /* ALTER TABLE <name> SET TABLESPACE <tablespacename> */
2905 | SET TABLESPACE name
2907 AlterTableCmd
*n
= makeNode
(AlterTableCmd
);
2909 n
->subtype
= AT_SetTableSpace
;
2913 /* ALTER TABLE <name> SET (...) */
2916 AlterTableCmd
*n
= makeNode
(AlterTableCmd
);
2918 n
->subtype
= AT_SetRelOptions
;
2919 n
->def
= (Node
*) $2;
2922 /* ALTER TABLE <name> RESET (...) */
2925 AlterTableCmd
*n
= makeNode
(AlterTableCmd
);
2927 n
->subtype
= AT_ResetRelOptions
;
2928 n
->def
= (Node
*) $2;
2931 /* ALTER TABLE <name> REPLICA IDENTITY */
2932 | REPLICA IDENTITY_P replica_identity
2934 AlterTableCmd
*n
= makeNode
(AlterTableCmd
);
2936 n
->subtype
= AT_ReplicaIdentity
;
2940 /* ALTER TABLE <name> ENABLE ROW LEVEL SECURITY */
2941 | ENABLE_P ROW LEVEL SECURITY
2943 AlterTableCmd
*n
= makeNode
(AlterTableCmd
);
2945 n
->subtype
= AT_EnableRowSecurity
;
2948 /* ALTER TABLE <name> DISABLE ROW LEVEL SECURITY */
2949 | DISABLE_P ROW LEVEL SECURITY
2951 AlterTableCmd
*n
= makeNode
(AlterTableCmd
);
2953 n
->subtype
= AT_DisableRowSecurity
;
2956 /* ALTER TABLE <name> FORCE ROW LEVEL SECURITY */
2957 | FORCE ROW LEVEL SECURITY
2959 AlterTableCmd
*n
= makeNode
(AlterTableCmd
);
2961 n
->subtype
= AT_ForceRowSecurity
;
2964 /* ALTER TABLE <name> NO FORCE ROW LEVEL SECURITY */
2965 | NO FORCE ROW LEVEL SECURITY
2967 AlterTableCmd
*n
= makeNode
(AlterTableCmd
);
2969 n
->subtype
= AT_NoForceRowSecurity
;
2972 | alter_generic_options
2974 AlterTableCmd
*n
= makeNode
(AlterTableCmd
);
2976 n
->subtype
= AT_GenericOptions
;
2977 n
->def
= (Node
*) $1;
2982 alter_column_default:
2983 SET DEFAULT a_expr
{ $$
= $3; }
2984 | DROP DEFAULT
{ $$
= NULL
; }
2990 CollateClause
*n
= makeNode
(CollateClause
);
2997 |
/* EMPTY */ { $$
= NULL
; }
3001 USING a_expr
{ $$
= $2; }
3002 |
/* EMPTY */ { $$
= NULL
; }
3008 ReplicaIdentityStmt
*n
= makeNode
(ReplicaIdentityStmt
);
3010 n
->identity_type
= REPLICA_IDENTITY_NOTHING
;
3016 ReplicaIdentityStmt
*n
= makeNode
(ReplicaIdentityStmt
);
3018 n
->identity_type
= REPLICA_IDENTITY_FULL
;
3024 ReplicaIdentityStmt
*n
= makeNode
(ReplicaIdentityStmt
);
3026 n
->identity_type
= REPLICA_IDENTITY_DEFAULT
;
3032 ReplicaIdentityStmt
*n
= makeNode
(ReplicaIdentityStmt
);
3034 n
->identity_type
= REPLICA_IDENTITY_INDEX
;
3041 '(' reloption_list
')' { $$
= $2; }
3044 opt_reloptions: WITH reloptions
{ $$
= $2; }
3045 |
/* EMPTY */ { $$
= NIL
; }
3049 reloption_elem
{ $$
= list_make1
($1); }
3050 | reloption_list
',' reloption_elem
{ $$
= lappend
($1, $3); }
3053 /* This should match def_elem and also allow qualified names */
3055 ColLabel
'=' def_arg
3057 $$
= makeDefElem
($1, (Node
*) $3, @
1);
3061 $$
= makeDefElem
($1, NULL
, @
1);
3063 | ColLabel
'.' ColLabel
'=' def_arg
3065 $$
= makeDefElemExtended
($1, $3, (Node
*) $5,
3066 DEFELEM_UNSPEC
, @
1);
3068 | ColLabel
'.' ColLabel
3070 $$
= makeDefElemExtended
($1, $3, NULL
, DEFELEM_UNSPEC
, @
1);
3074 alter_identity_column_option_list:
3075 alter_identity_column_option
3076 { $$
= list_make1
($1); }
3077 | alter_identity_column_option_list alter_identity_column_option
3078 { $$
= lappend
($1, $2); }
3081 alter_identity_column_option:
3084 $$
= makeDefElem
("restart", NULL
, @
1);
3086 | RESTART opt_with NumericOnly
3088 $$
= makeDefElem
("restart", (Node
*) $3, @
1);
3092 if
(strcmp
($2->defname
, "as") == 0 ||
3093 strcmp
($2->defname
, "restart") == 0 ||
3094 strcmp
($2->defname
, "owned_by") == 0)
3096 (errcode
(ERRCODE_SYNTAX_ERROR
),
3097 errmsg
("sequence option \"%s\" not supported here", $2->defname
),
3098 parser_errposition
(@
2)));
3101 | SET GENERATED generated_when
3103 $$
= makeDefElem
("generated", (Node
*) makeInteger
($3), @
1);
3107 set_statistics_value:
3108 SignedIconst
{ $$
= (Node
*) makeInteger
($1); }
3109 | DEFAULT
{ $$
= NULL
; }
3112 set_access_method_name:
3114 | DEFAULT
{ $$
= NULL
; }
3118 /* a HASH partition */
3119 FOR VALUES WITH
'(' hash_partbound
')'
3122 PartitionBoundSpec
*n
= makeNode
(PartitionBoundSpec
);
3124 n
->strategy
= PARTITION_STRATEGY_HASH
;
3125 n
->modulus
= n
->remainder
= -1;
3129 DefElem
*opt
= lfirst_node
(DefElem
, lc
);
3131 if
(strcmp
(opt
->defname
, "modulus") == 0)
3133 if
(n
->modulus
!= -1)
3135 (errcode
(ERRCODE_DUPLICATE_OBJECT
),
3136 errmsg
("modulus for hash partition provided more than once"),
3137 parser_errposition
(opt
->location
)));
3138 n
->modulus
= defGetInt32
(opt
);
3140 else if
(strcmp
(opt
->defname
, "remainder") == 0)
3142 if
(n
->remainder
!= -1)
3144 (errcode
(ERRCODE_DUPLICATE_OBJECT
),
3145 errmsg
("remainder for hash partition provided more than once"),
3146 parser_errposition
(opt
->location
)));
3147 n
->remainder
= defGetInt32
(opt
);
3151 (errcode
(ERRCODE_SYNTAX_ERROR
),
3152 errmsg
("unrecognized hash partition bound specification \"%s\"",
3154 parser_errposition
(opt
->location
)));
3157 if
(n
->modulus
== -1)
3159 (errcode
(ERRCODE_SYNTAX_ERROR
),
3160 errmsg
("modulus for hash partition must be specified"),
3161 parser_errposition
(@
3)));
3162 if
(n
->remainder
== -1)
3164 (errcode
(ERRCODE_SYNTAX_ERROR
),
3165 errmsg
("remainder for hash partition must be specified"),
3166 parser_errposition
(@
3)));
3173 /* a LIST partition */
3174 | FOR VALUES IN_P
'(' expr_list
')'
3176 PartitionBoundSpec
*n
= makeNode
(PartitionBoundSpec
);
3178 n
->strategy
= PARTITION_STRATEGY_LIST
;
3179 n
->is_default
= false
;
3186 /* a RANGE partition */
3187 | FOR VALUES FROM
'(' expr_list
')' TO
'(' expr_list
')'
3189 PartitionBoundSpec
*n
= makeNode
(PartitionBoundSpec
);
3191 n
->strategy
= PARTITION_STRATEGY_RANGE
;
3192 n
->is_default
= false
;
3193 n
->lowerdatums
= $5;
3194 n
->upperdatums
= $9;
3200 /* a DEFAULT partition */
3203 PartitionBoundSpec
*n
= makeNode
(PartitionBoundSpec
);
3205 n
->is_default
= true
;
3212 hash_partbound_elem:
3213 NonReservedWord Iconst
3215 $$
= makeDefElem
($1, (Node
*) makeInteger
($2), @
1);
3222 $$
= list_make1
($1);
3224 | hash_partbound
',' hash_partbound_elem
3226 $$
= lappend
($1, $3);
3230 /*****************************************************************************
3234 * really variants of the ALTER TABLE subcommands with different spellings
3235 *****************************************************************************/
3237 AlterCompositeTypeStmt:
3238 ALTER TYPE_P any_name alter_type_cmds
3240 AlterTableStmt
*n
= makeNode
(AlterTableStmt
);
3242 /* can't use qualified_name, sigh */
3243 n
->relation
= makeRangeVarFromAnyName
($3, @
3, yyscanner
);
3245 n
->objtype
= OBJECT_TYPE
;
3251 alter_type_cmd
{ $$
= list_make1
($1); }
3252 | alter_type_cmds
',' alter_type_cmd
{ $$
= lappend
($1, $3); }
3256 /* ALTER TYPE <name> ADD ATTRIBUTE <coldef> [RESTRICT|CASCADE] */
3257 ADD_P ATTRIBUTE TableFuncElement opt_drop_behavior
3259 AlterTableCmd
*n
= makeNode
(AlterTableCmd
);
3261 n
->subtype
= AT_AddColumn
;
3266 /* ALTER TYPE <name> DROP ATTRIBUTE IF EXISTS <attname> [RESTRICT|CASCADE] */
3267 | DROP ATTRIBUTE IF_P EXISTS ColId opt_drop_behavior
3269 AlterTableCmd
*n
= makeNode
(AlterTableCmd
);
3271 n
->subtype
= AT_DropColumn
;
3274 n
->missing_ok
= true
;
3277 /* ALTER TYPE <name> DROP ATTRIBUTE <attname> [RESTRICT|CASCADE] */
3278 | DROP ATTRIBUTE ColId opt_drop_behavior
3280 AlterTableCmd
*n
= makeNode
(AlterTableCmd
);
3282 n
->subtype
= AT_DropColumn
;
3285 n
->missing_ok
= false
;
3288 /* ALTER TYPE <name> ALTER ATTRIBUTE <attname> [SET DATA] TYPE <typename> [RESTRICT|CASCADE] */
3289 | ALTER ATTRIBUTE ColId opt_set_data TYPE_P Typename opt_collate_clause opt_drop_behavior
3291 AlterTableCmd
*n
= makeNode
(AlterTableCmd
);
3292 ColumnDef
*def
= makeNode
(ColumnDef
);
3294 n
->subtype
= AT_AlterColumnType
;
3296 n
->def
= (Node
*) def
;
3298 /* We only use these fields of the ColumnDef node */
3300 def
->collClause
= (CollateClause
*) $7;
3301 def
->raw_default
= NULL
;
3308 /*****************************************************************************
3311 * close <portalname>
3313 *****************************************************************************/
3318 ClosePortalStmt
*n
= makeNode
(ClosePortalStmt
);
3325 ClosePortalStmt
*n
= makeNode
(ClosePortalStmt
);
3327 n
->portalname
= NULL
;
3333 /*****************************************************************************
3336 * COPY relname [(columnList)] FROM/TO file [WITH] [(options)]
3337 * COPY ( query ) TO file [WITH] [(options)]
3339 * where 'query' can be one of:
3340 * { SELECT | UPDATE | INSERT | DELETE }
3342 * and 'file' can be one of:
3343 * { PROGRAM 'command' | STDIN | STDOUT | 'filename' }
3345 * In the preferred syntax the options are comma-separated
3346 * and use generic identifiers instead of keywords. The pre-9.0
3347 * syntax had a hard-wired, space-separated set of options.
3349 * Really old syntax, from versions 7.2 and prior:
3350 * COPY [ BINARY ] table FROM/TO file
3351 * [ [ USING ] DELIMITERS 'delimiter' ] ]
3352 * [ WITH NULL AS 'null string' ]
3353 * This option placement is not supported with COPY (query...).
3355 *****************************************************************************/
3357 CopyStmt: COPY opt_binary qualified_name opt_column_list
3358 copy_from opt_program copy_file_name copy_delimiter opt_with
3359 copy_options where_clause
3361 CopyStmt
*n
= makeNode
(CopyStmt
);
3369 n
->whereClause
= $11;
3371 if
(n
->is_program
&& n
->filename
== NULL
)
3373 (errcode
(ERRCODE_SYNTAX_ERROR
),
3374 errmsg
("STDIN/STDOUT not allowed with PROGRAM"),
3375 parser_errposition
(@
8)));
3377 if
(!n
->is_from
&& n
->whereClause
!= NULL
)
3379 (errcode
(ERRCODE_SYNTAX_ERROR
),
3380 errmsg
("WHERE clause not allowed with COPY TO"),
3381 parser_errposition
(@
11)));
3384 /* Concatenate user-supplied flags */
3386 n
->options
= lappend
(n
->options
, $2);
3388 n
->options
= lappend
(n
->options
, $8);
3390 n
->options
= list_concat
(n
->options
, $10);
3393 | COPY
'(' PreparableStmt
')' TO opt_program copy_file_name opt_with copy_options
3395 CopyStmt
*n
= makeNode
(CopyStmt
);
3397 updatePreparableStmtEnd
($3, @
4);
3406 if
(n
->is_program
&& n
->filename
== NULL
)
3408 (errcode
(ERRCODE_SYNTAX_ERROR
),
3409 errmsg
("STDIN/STDOUT not allowed with PROGRAM"),
3410 parser_errposition
(@
5)));
3418 | TO
{ $$
= false
; }
3422 PROGRAM
{ $$
= true
; }
3423 |
/* EMPTY */ { $$
= false
; }
3427 * copy_file_name NULL indicates stdio is used. Whether stdin or stdout is
3428 * used depends on the direction. (It really doesn't make sense to copy from
3429 * stdout. We silently correct the "typo".) - AY 9/94
3433 | STDIN
{ $$
= NULL
; }
3434 | STDOUT
{ $$
= NULL
; }
3437 copy_options: copy_opt_list
{ $$
= $1; }
3438 |
'(' copy_generic_opt_list
')' { $$
= $2; }
3441 /* old COPY option syntax */
3443 copy_opt_list copy_opt_item
{ $$
= lappend
($1, $2); }
3444 |
/* EMPTY */ { $$
= NIL
; }
3450 $$
= makeDefElem
("format", (Node
*) makeString
("binary"), @
1);
3454 $$
= makeDefElem
("freeze", (Node
*) makeBoolean
(true
), @
1);
3456 | DELIMITER opt_as Sconst
3458 $$
= makeDefElem
("delimiter", (Node
*) makeString
($3), @
1);
3460 | NULL_P opt_as Sconst
3462 $$
= makeDefElem
("null", (Node
*) makeString
($3), @
1);
3466 $$
= makeDefElem
("format", (Node
*) makeString
("csv"), @
1);
3470 $$
= makeDefElem
("header", (Node
*) makeBoolean
(true
), @
1);
3472 | QUOTE opt_as Sconst
3474 $$
= makeDefElem
("quote", (Node
*) makeString
($3), @
1);
3476 | ESCAPE opt_as Sconst
3478 $$
= makeDefElem
("escape", (Node
*) makeString
($3), @
1);
3480 | FORCE QUOTE columnList
3482 $$
= makeDefElem
("force_quote", (Node
*) $3, @
1);
3486 $$
= makeDefElem
("force_quote", (Node
*) makeNode
(A_Star
), @
1);
3488 | FORCE NOT NULL_P columnList
3490 $$
= makeDefElem
("force_not_null", (Node
*) $4, @
1);
3492 | FORCE NOT NULL_P
'*'
3494 $$
= makeDefElem
("force_not_null", (Node
*) makeNode
(A_Star
), @
1);
3496 | FORCE NULL_P columnList
3498 $$
= makeDefElem
("force_null", (Node
*) $3, @
1);
3502 $$
= makeDefElem
("force_null", (Node
*) makeNode
(A_Star
), @
1);
3506 $$
= makeDefElem
("encoding", (Node
*) makeString
($2), @
1);
3510 /* The following exist for backward compatibility with very old versions */
3515 $$
= makeDefElem
("format", (Node
*) makeString
("binary"), @
1);
3517 |
/*EMPTY*/ { $$
= NULL
; }
3521 opt_using DELIMITERS Sconst
3523 $$
= makeDefElem
("delimiter", (Node
*) makeString
($3), @
2);
3525 |
/*EMPTY*/ { $$
= NULL
; }
3533 /* new COPY option syntax */
3534 copy_generic_opt_list:
3535 copy_generic_opt_elem
3537 $$
= list_make1
($1);
3539 | copy_generic_opt_list
',' copy_generic_opt_elem
3541 $$
= lappend
($1, $3);
3545 copy_generic_opt_elem:
3546 ColLabel copy_generic_opt_arg
3548 $$
= makeDefElem
($1, $2, @
1);
3552 copy_generic_opt_arg:
3553 opt_boolean_or_string
{ $$
= (Node
*) makeString
($1); }
3554 | NumericOnly
{ $$
= (Node
*) $1; }
3555 |
'*' { $$
= (Node
*) makeNode
(A_Star
); }
3556 | DEFAULT
{ $$
= (Node
*) makeString
("default"); }
3557 |
'(' copy_generic_opt_arg_list
')' { $$
= (Node
*) $2; }
3558 |
/* EMPTY */ { $$
= NULL
; }
3561 copy_generic_opt_arg_list:
3562 copy_generic_opt_arg_list_item
3564 $$
= list_make1
($1);
3566 | copy_generic_opt_arg_list
',' copy_generic_opt_arg_list_item
3568 $$
= lappend
($1, $3);
3572 /* beware of emitting non-string list elements here; see commands/define.c */
3573 copy_generic_opt_arg_list_item:
3574 opt_boolean_or_string
{ $$
= (Node
*) makeString
($1); }
3578 /*****************************************************************************
3581 * CREATE TABLE relname
3583 *****************************************************************************/
3585 CreateStmt: CREATE OptTemp TABLE qualified_name
'(' OptTableElementList
')'
3586 OptInherit OptPartitionSpec table_access_method_clause OptWith
3587 OnCommitOption OptTableSpace
3589 CreateStmt
*n
= makeNode
(CreateStmt
);
3591 $4->relpersistence
= $2;
3594 n
->inhRelations
= $8;
3596 n
->ofTypename
= NULL
;
3597 n
->constraints
= NIL
;
3598 n
->accessMethod
= $10;
3601 n
->tablespacename
= $13;
3602 n
->if_not_exists
= false
;
3605 | CREATE OptTemp TABLE IF_P NOT EXISTS qualified_name
'('
3606 OptTableElementList
')' OptInherit OptPartitionSpec table_access_method_clause
3607 OptWith OnCommitOption OptTableSpace
3609 CreateStmt
*n
= makeNode
(CreateStmt
);
3611 $7->relpersistence
= $2;
3614 n
->inhRelations
= $11;
3616 n
->ofTypename
= NULL
;
3617 n
->constraints
= NIL
;
3618 n
->accessMethod
= $13;
3621 n
->tablespacename
= $16;
3622 n
->if_not_exists
= true
;
3625 | CREATE OptTemp TABLE qualified_name OF any_name
3626 OptTypedTableElementList OptPartitionSpec table_access_method_clause
3627 OptWith OnCommitOption OptTableSpace
3629 CreateStmt
*n
= makeNode
(CreateStmt
);
3631 $4->relpersistence
= $2;
3634 n
->inhRelations
= NIL
;
3636 n
->ofTypename
= makeTypeNameFromNameList
($6);
3637 n
->ofTypename
->location
= @
6;
3638 n
->constraints
= NIL
;
3639 n
->accessMethod
= $9;
3642 n
->tablespacename
= $12;
3643 n
->if_not_exists
= false
;
3646 | CREATE OptTemp TABLE IF_P NOT EXISTS qualified_name OF any_name
3647 OptTypedTableElementList OptPartitionSpec table_access_method_clause
3648 OptWith OnCommitOption OptTableSpace
3650 CreateStmt
*n
= makeNode
(CreateStmt
);
3652 $7->relpersistence
= $2;
3655 n
->inhRelations
= NIL
;
3657 n
->ofTypename
= makeTypeNameFromNameList
($9);
3658 n
->ofTypename
->location
= @
9;
3659 n
->constraints
= NIL
;
3660 n
->accessMethod
= $12;
3663 n
->tablespacename
= $15;
3664 n
->if_not_exists
= true
;
3667 | CREATE OptTemp TABLE qualified_name PARTITION OF qualified_name
3668 OptTypedTableElementList PartitionBoundSpec OptPartitionSpec
3669 table_access_method_clause OptWith OnCommitOption OptTableSpace
3671 CreateStmt
*n
= makeNode
(CreateStmt
);
3673 $4->relpersistence
= $2;
3676 n
->inhRelations
= list_make1
($7);
3679 n
->ofTypename
= NULL
;
3680 n
->constraints
= NIL
;
3681 n
->accessMethod
= $11;
3684 n
->tablespacename
= $14;
3685 n
->if_not_exists
= false
;
3688 | CREATE OptTemp TABLE IF_P NOT EXISTS qualified_name PARTITION OF
3689 qualified_name OptTypedTableElementList PartitionBoundSpec OptPartitionSpec
3690 table_access_method_clause OptWith OnCommitOption OptTableSpace
3692 CreateStmt
*n
= makeNode
(CreateStmt
);
3694 $7->relpersistence
= $2;
3697 n
->inhRelations
= list_make1
($10);
3700 n
->ofTypename
= NULL
;
3701 n
->constraints
= NIL
;
3702 n
->accessMethod
= $14;
3705 n
->tablespacename
= $17;
3706 n
->if_not_exists
= true
;
3712 * Redundancy here is needed to avoid shift/reduce conflicts,
3713 * since TEMP is not a reserved word. See also OptTempTableName.
3715 * NOTE: we accept both GLOBAL and LOCAL options. They currently do nothing,
3716 * but future versions might consider GLOBAL to request SQL-spec-compliant
3717 * temp table behavior, so warn about that. Since we have no modules the
3718 * LOCAL keyword is really meaningless; furthermore, some other products
3719 * implement LOCAL as meaning the same as our default temp table behavior,
3720 * so we'll probably continue to treat LOCAL as a noise word.
3722 OptTemp: TEMPORARY
{ $$
= RELPERSISTENCE_TEMP
; }
3723 | TEMP
{ $$
= RELPERSISTENCE_TEMP
; }
3724 | LOCAL TEMPORARY
{ $$
= RELPERSISTENCE_TEMP
; }
3725 | LOCAL TEMP
{ $$
= RELPERSISTENCE_TEMP
; }
3729 (errmsg
("GLOBAL is deprecated in temporary table creation"),
3730 parser_errposition
(@
1)));
3731 $$
= RELPERSISTENCE_TEMP
;
3736 (errmsg
("GLOBAL is deprecated in temporary table creation"),
3737 parser_errposition
(@
1)));
3738 $$
= RELPERSISTENCE_TEMP
;
3740 | UNLOGGED
{ $$
= RELPERSISTENCE_UNLOGGED
; }
3741 |
/*EMPTY*/ { $$
= RELPERSISTENCE_PERMANENT
; }
3744 OptTableElementList:
3745 TableElementList
{ $$
= $1; }
3746 |
/*EMPTY*/ { $$
= NIL
; }
3749 OptTypedTableElementList:
3750 '(' TypedTableElementList
')' { $$
= $2; }
3751 |
/*EMPTY*/ { $$
= NIL
; }
3757 $$
= list_make1
($1);
3759 | TableElementList
',' TableElement
3761 $$
= lappend
($1, $3);
3765 TypedTableElementList:
3768 $$
= list_make1
($1);
3770 | TypedTableElementList
',' TypedTableElement
3772 $$
= lappend
($1, $3);
3777 columnDef
{ $$
= $1; }
3778 | TableLikeClause
{ $$
= $1; }
3779 | TableConstraint
{ $$
= $1; }
3783 columnOptions
{ $$
= $1; }
3784 | TableConstraint
{ $$
= $1; }
3787 columnDef: ColId Typename opt_column_storage opt_column_compression create_generic_options ColQualList
3789 ColumnDef
*n
= makeNode
(ColumnDef
);
3793 n
->storage_name
= $3;
3794 n
->compression
= $4;
3797 n
->is_not_null
= false
;
3798 n
->is_from_type
= false
;
3800 n
->raw_default
= NULL
;
3801 n
->cooked_default
= NULL
;
3802 n
->collOid
= InvalidOid
;
3804 SplitColQualList
($6, &n
->constraints
, &n
->collClause
,
3811 columnOptions: ColId ColQualList
3813 ColumnDef
*n
= makeNode
(ColumnDef
);
3819 n
->is_not_null
= false
;
3820 n
->is_from_type
= false
;
3822 n
->raw_default
= NULL
;
3823 n
->cooked_default
= NULL
;
3824 n
->collOid
= InvalidOid
;
3825 SplitColQualList
($2, &n
->constraints
, &n
->collClause
,
3830 | ColId WITH OPTIONS ColQualList
3832 ColumnDef
*n
= makeNode
(ColumnDef
);
3838 n
->is_not_null
= false
;
3839 n
->is_from_type
= false
;
3841 n
->raw_default
= NULL
;
3842 n
->cooked_default
= NULL
;
3843 n
->collOid
= InvalidOid
;
3844 SplitColQualList
($4, &n
->constraints
, &n
->collClause
,
3852 COMPRESSION ColId
{ $$
= $2; }
3853 | COMPRESSION DEFAULT
{ $$
= pstrdup
("default"); }
3856 opt_column_compression:
3857 column_compression
{ $$
= $1; }
3858 |
/*EMPTY*/ { $$
= NULL
; }
3862 STORAGE ColId
{ $$
= $2; }
3863 | STORAGE DEFAULT
{ $$
= pstrdup
("default"); }
3867 column_storage
{ $$
= $1; }
3868 |
/*EMPTY*/ { $$
= NULL
; }
3872 ColQualList ColConstraint
{ $$
= lappend
($1, $2); }
3873 |
/*EMPTY*/ { $$
= NIL
; }
3877 CONSTRAINT name ColConstraintElem
3879 Constraint
*n
= castNode
(Constraint
, $3);
3885 | ColConstraintElem
{ $$
= $1; }
3886 | ConstraintAttr
{ $$
= $1; }
3890 * Note: the CollateClause is momentarily included in
3891 * the list built by ColQualList, but we split it out
3892 * again in SplitColQualList.
3894 CollateClause
*n
= makeNode
(CollateClause
);
3903 /* DEFAULT NULL is already the default for Postgres.
3904 * But define it here and carry it forward into the system
3905 * to make it explicit.
3906 * - thomas 1998-09-13
3908 * WITH NULL and NULL are not SQL-standard syntax elements,
3909 * so leave them out. Use DEFAULT NULL to explicitly indicate
3910 * that a column may have that value. WITH NULL leads to
3911 * shift/reduce conflicts with WITH TIME ZONE anyway.
3912 * - thomas 1999-01-08
3914 * DEFAULT expression must be b_expr not a_expr to prevent shift/reduce
3915 * conflict on NOT (since NOT might start a subsequent NOT NULL constraint,
3916 * or be part of a_expr NOT LIKE or similar constructs).
3919 NOT NULL_P opt_no_inherit
3921 Constraint
*n
= makeNode
(Constraint
);
3923 n
->contype
= CONSTR_NOTNULL
;
3925 n
->is_no_inherit
= $3;
3926 n
->is_enforced
= true
;
3927 n
->skip_validation
= false
;
3928 n
->initially_valid
= true
;
3933 Constraint
*n
= makeNode
(Constraint
);
3935 n
->contype
= CONSTR_NULL
;
3939 | UNIQUE opt_unique_null_treatment opt_definition OptConsTableSpace
3941 Constraint
*n
= makeNode
(Constraint
);
3943 n
->contype
= CONSTR_UNIQUE
;
3945 n
->nulls_not_distinct
= !$2;
3948 n
->indexname
= NULL
;
3952 | PRIMARY KEY opt_definition OptConsTableSpace
3954 Constraint
*n
= makeNode
(Constraint
);
3956 n
->contype
= CONSTR_PRIMARY
;
3960 n
->indexname
= NULL
;
3964 | CHECK
'(' a_expr
')' opt_no_inherit
3966 Constraint
*n
= makeNode
(Constraint
);
3968 n
->contype
= CONSTR_CHECK
;
3970 n
->is_no_inherit
= $5;
3972 n
->cooked_expr
= NULL
;
3973 n
->is_enforced
= true
;
3974 n
->skip_validation
= false
;
3975 n
->initially_valid
= true
;
3980 Constraint
*n
= makeNode
(Constraint
);
3982 n
->contype
= CONSTR_DEFAULT
;
3985 n
->cooked_expr
= NULL
;
3988 | GENERATED generated_when AS IDENTITY_P OptParenthesizedSeqOptList
3990 Constraint
*n
= makeNode
(Constraint
);
3992 n
->contype
= CONSTR_IDENTITY
;
3993 n
->generated_when
= $2;
3998 | GENERATED generated_when AS
'(' a_expr
')' STORED
4000 Constraint
*n
= makeNode
(Constraint
);
4002 n
->contype
= CONSTR_GENERATED
;
4003 n
->generated_when
= $2;
4005 n
->cooked_expr
= NULL
;
4009 * Can't do this in the grammar because of shift/reduce
4010 * conflicts. (IDENTITY allows both ALWAYS and BY
4011 * DEFAULT, but generated columns only allow ALWAYS.) We
4012 * can also give a more useful error message and location.
4014 if
($2 != ATTRIBUTE_IDENTITY_ALWAYS
)
4016 (errcode
(ERRCODE_SYNTAX_ERROR
),
4017 errmsg
("for a generated column, GENERATED ALWAYS must be specified"),
4018 parser_errposition
(@
2)));
4022 | REFERENCES qualified_name opt_column_list key_match key_actions
4024 Constraint
*n
= makeNode
(Constraint
);
4026 n
->contype
= CONSTR_FOREIGN
;
4031 n
->fk_matchtype
= $4;
4032 n
->fk_upd_action
= ($5)->updateAction
->action
;
4033 n
->fk_del_action
= ($5)->deleteAction
->action
;
4034 n
->fk_del_set_cols
= ($5)->deleteAction
->cols
;
4035 n
->is_enforced
= true
;
4036 n
->skip_validation
= false
;
4037 n
->initially_valid
= true
;
4042 opt_unique_null_treatment:
4043 NULLS_P DISTINCT
{ $$
= true
; }
4044 | NULLS_P NOT DISTINCT
{ $$
= false
; }
4045 |
/*EMPTY*/ { $$
= true
; }
4049 ALWAYS
{ $$
= ATTRIBUTE_IDENTITY_ALWAYS
; }
4050 | BY DEFAULT
{ $$
= ATTRIBUTE_IDENTITY_BY_DEFAULT
; }
4054 * ConstraintAttr represents constraint attributes, which we parse as if
4055 * they were independent constraint clauses, in order to avoid shift/reduce
4056 * conflicts (since NOT might start either an independent NOT NULL clause
4057 * or an attribute). parse_utilcmd.c is responsible for attaching the
4058 * attribute information to the preceding "real" constraint node, and for
4059 * complaining if attribute clauses appear in the wrong place or wrong
4062 * See also ConstraintAttributeSpec, which can be used in places where
4063 * there is no parsing conflict. (Note: currently, NOT VALID and NO INHERIT
4064 * are allowed clauses in ConstraintAttributeSpec, but not here. Someday we
4065 * might need to allow them here too, but for the moment it doesn't seem
4066 * useful in the statements that use ConstraintAttr.)
4071 Constraint
*n
= makeNode
(Constraint
);
4073 n
->contype
= CONSTR_ATTR_DEFERRABLE
;
4079 Constraint
*n
= makeNode
(Constraint
);
4081 n
->contype
= CONSTR_ATTR_NOT_DEFERRABLE
;
4085 | INITIALLY DEFERRED
4087 Constraint
*n
= makeNode
(Constraint
);
4089 n
->contype
= CONSTR_ATTR_DEFERRED
;
4093 | INITIALLY IMMEDIATE
4095 Constraint
*n
= makeNode
(Constraint
);
4097 n
->contype
= CONSTR_ATTR_IMMEDIATE
;
4103 Constraint
*n
= makeNode
(Constraint
);
4105 n
->contype
= CONSTR_ATTR_ENFORCED
;
4111 Constraint
*n
= makeNode
(Constraint
);
4113 n
->contype
= CONSTR_ATTR_NOT_ENFORCED
;
4121 LIKE qualified_name TableLikeOptionList
4123 TableLikeClause
*n
= makeNode
(TableLikeClause
);
4127 n
->relationOid
= InvalidOid
;
4132 TableLikeOptionList:
4133 TableLikeOptionList INCLUDING TableLikeOption
{ $$
= $1 |
$3; }
4134 | TableLikeOptionList EXCLUDING TableLikeOption
{ $$
= $1 & ~
$3; }
4135 |
/* EMPTY */ { $$
= 0; }
4139 COMMENTS
{ $$
= CREATE_TABLE_LIKE_COMMENTS
; }
4140 | COMPRESSION
{ $$
= CREATE_TABLE_LIKE_COMPRESSION
; }
4141 | CONSTRAINTS
{ $$
= CREATE_TABLE_LIKE_CONSTRAINTS
; }
4142 | DEFAULTS
{ $$
= CREATE_TABLE_LIKE_DEFAULTS
; }
4143 | IDENTITY_P
{ $$
= CREATE_TABLE_LIKE_IDENTITY
; }
4144 | GENERATED
{ $$
= CREATE_TABLE_LIKE_GENERATED
; }
4145 | INDEXES
{ $$
= CREATE_TABLE_LIKE_INDEXES
; }
4146 | STATISTICS
{ $$
= CREATE_TABLE_LIKE_STATISTICS
; }
4147 | STORAGE
{ $$
= CREATE_TABLE_LIKE_STORAGE
; }
4148 | ALL
{ $$
= CREATE_TABLE_LIKE_ALL
; }
4152 /* ConstraintElem specifies constraint syntax which is not embedded into
4153 * a column definition. ColConstraintElem specifies the embedded form.
4154 * - thomas 1997-12-03
4157 CONSTRAINT name ConstraintElem
4159 Constraint
*n
= castNode
(Constraint
, $3);
4165 | ConstraintElem
{ $$
= $1; }
4169 CHECK
'(' a_expr
')' ConstraintAttributeSpec
4171 Constraint
*n
= makeNode
(Constraint
);
4173 n
->contype
= CONSTR_CHECK
;
4176 n
->cooked_expr
= NULL
;
4177 processCASbits
($5, @
5, "CHECK",
4178 NULL
, NULL
, &n
->is_enforced
, &n
->skip_validation
,
4179 &n
->is_no_inherit
, yyscanner
);
4180 n
->initially_valid
= !n
->skip_validation
;
4183 | NOT NULL_P ColId ConstraintAttributeSpec
4185 Constraint
*n
= makeNode
(Constraint
);
4187 n
->contype
= CONSTR_NOTNULL
;
4189 n
->keys
= list_make1
(makeString
($3));
4190 /* no NOT VALID support yet */
4191 processCASbits
($4, @
4, "NOT NULL",
4192 NULL
, NULL
, NULL
, NULL
,
4193 &n
->is_no_inherit
, yyscanner
);
4194 n
->initially_valid
= true
;
4197 | UNIQUE opt_unique_null_treatment
'(' columnList opt_without_overlaps
')' opt_c_include opt_definition OptConsTableSpace
4198 ConstraintAttributeSpec
4200 Constraint
*n
= makeNode
(Constraint
);
4202 n
->contype
= CONSTR_UNIQUE
;
4204 n
->nulls_not_distinct
= !$2;
4206 n
->without_overlaps
= $5;
4209 n
->indexname
= NULL
;
4211 processCASbits
($10, @
10, "UNIQUE",
4212 &n
->deferrable
, &n
->initdeferred
, NULL
,
4213 NULL
, NULL
, yyscanner
);
4216 | UNIQUE ExistingIndex ConstraintAttributeSpec
4218 Constraint
*n
= makeNode
(Constraint
);
4220 n
->contype
= CONSTR_UNIQUE
;
4226 n
->indexspace
= NULL
;
4227 processCASbits
($3, @
3, "UNIQUE",
4228 &n
->deferrable
, &n
->initdeferred
, NULL
,
4229 NULL
, NULL
, yyscanner
);
4232 | PRIMARY KEY
'(' columnList opt_without_overlaps
')' opt_c_include opt_definition OptConsTableSpace
4233 ConstraintAttributeSpec
4235 Constraint
*n
= makeNode
(Constraint
);
4237 n
->contype
= CONSTR_PRIMARY
;
4240 n
->without_overlaps
= $5;
4243 n
->indexname
= NULL
;
4245 processCASbits
($10, @
10, "PRIMARY KEY",
4246 &n
->deferrable
, &n
->initdeferred
, NULL
,
4247 NULL
, NULL
, yyscanner
);
4250 | PRIMARY KEY ExistingIndex ConstraintAttributeSpec
4252 Constraint
*n
= makeNode
(Constraint
);
4254 n
->contype
= CONSTR_PRIMARY
;
4260 n
->indexspace
= NULL
;
4261 processCASbits
($4, @
4, "PRIMARY KEY",
4262 &n
->deferrable
, &n
->initdeferred
, NULL
,
4263 NULL
, NULL
, yyscanner
);
4266 | EXCLUDE access_method_clause
'(' ExclusionConstraintList
')'
4267 opt_c_include opt_definition OptConsTableSpace OptWhereClause
4268 ConstraintAttributeSpec
4270 Constraint
*n
= makeNode
(Constraint
);
4272 n
->contype
= CONSTR_EXCLUSION
;
4274 n
->access_method
= $2;
4278 n
->indexname
= NULL
;
4280 n
->where_clause
= $9;
4281 processCASbits
($10, @
10, "EXCLUDE",
4282 &n
->deferrable
, &n
->initdeferred
, NULL
,
4283 NULL
, NULL
, yyscanner
);
4286 | FOREIGN KEY
'(' columnList optionalPeriodName
')' REFERENCES qualified_name
4287 opt_column_and_period_list key_match key_actions ConstraintAttributeSpec
4289 Constraint
*n
= makeNode
(Constraint
);
4291 n
->contype
= CONSTR_FOREIGN
;
4297 n
->fk_attrs
= lappend
(n
->fk_attrs
, $5);
4298 n
->fk_with_period
= true
;
4300 n
->pk_attrs
= linitial
($9);
4303 n
->pk_attrs
= lappend
(n
->pk_attrs
, lsecond
($9));
4304 n
->pk_with_period
= true
;
4306 n
->fk_matchtype
= $10;
4307 n
->fk_upd_action
= ($11)->updateAction
->action
;
4308 n
->fk_del_action
= ($11)->deleteAction
->action
;
4309 n
->fk_del_set_cols
= ($11)->deleteAction
->cols
;
4310 processCASbits
($12, @
12, "FOREIGN KEY",
4311 &n
->deferrable
, &n
->initdeferred
,
4312 NULL
, &n
->skip_validation
, NULL
,
4314 n
->initially_valid
= !n
->skip_validation
;
4320 * DomainConstraint is separate from TableConstraint because the syntax for
4321 * NOT NULL constraints is different. For table constraints, we need to
4322 * accept a column name, but for domain constraints, we don't. (We could
4323 * accept something like NOT NULL VALUE, but that seems weird.) CREATE DOMAIN
4324 * (which uses ColQualList) has for a long time accepted NOT NULL without a
4325 * column name, so it makes sense that ALTER DOMAIN (which uses
4326 * DomainConstraint) does as well. None of these syntaxes are per SQL
4327 * standard; we are just living with the bits of inconsistency that have built
4331 CONSTRAINT name DomainConstraintElem
4333 Constraint
*n
= castNode
(Constraint
, $3);
4339 | DomainConstraintElem
{ $$
= $1; }
4342 DomainConstraintElem:
4343 CHECK
'(' a_expr
')' ConstraintAttributeSpec
4345 Constraint
*n
= makeNode
(Constraint
);
4347 n
->contype
= CONSTR_CHECK
;
4350 n
->cooked_expr
= NULL
;
4351 processCASbits
($5, @
5, "CHECK",
4352 NULL
, NULL
, NULL
, &n
->skip_validation
,
4353 &n
->is_no_inherit
, yyscanner
);
4354 n
->is_enforced
= true
;
4355 n
->initially_valid
= !n
->skip_validation
;
4358 | NOT NULL_P ConstraintAttributeSpec
4360 Constraint
*n
= makeNode
(Constraint
);
4362 n
->contype
= CONSTR_NOTNULL
;
4364 n
->keys
= list_make1
(makeString
("value"));
4365 /* no NOT VALID, NO INHERIT support */
4366 processCASbits
($3, @
3, "NOT NULL",
4368 NULL
, NULL
, yyscanner
);
4369 n
->initially_valid
= true
;
4374 opt_no_inherit: NO INHERIT
{ $$
= true
; }
4375 |
/* EMPTY */ { $$
= false
; }
4378 opt_without_overlaps:
4379 WITHOUT OVERLAPS
{ $$
= true
; }
4380 |
/*EMPTY*/ { $$
= false
; }
4384 '(' columnList
')' { $$
= $2; }
4385 |
/*EMPTY*/ { $$
= NIL
; }
4389 columnElem
{ $$
= list_make1
($1); }
4390 | columnList
',' columnElem
{ $$
= lappend
($1, $3); }
4394 ',' PERIOD columnElem
{ $$
= $3; }
4395 |
/*EMPTY*/ { $$
= NULL
; }
4398 opt_column_and_period_list:
4399 '(' columnList optionalPeriodName
')' { $$
= list_make2
($2, $3); }
4400 |
/*EMPTY*/ { $$
= list_make2
(NIL
, NULL
); }
4405 $$
= (Node
*) makeString
($1);
4409 opt_c_include: INCLUDE
'(' columnList
')' { $$
= $3; }
4410 |
/* EMPTY */ { $$
= NIL
; }
4413 key_match: MATCH FULL
4415 $$
= FKCONSTR_MATCH_FULL
;
4420 (errcode
(ERRCODE_FEATURE_NOT_SUPPORTED
),
4421 errmsg
("MATCH PARTIAL not yet implemented"),
4422 parser_errposition
(@
1)));
4423 $$
= FKCONSTR_MATCH_PARTIAL
;
4427 $$
= FKCONSTR_MATCH_SIMPLE
;
4431 $$
= FKCONSTR_MATCH_SIMPLE
;
4435 ExclusionConstraintList:
4436 ExclusionConstraintElem
{ $$
= list_make1
($1); }
4437 | ExclusionConstraintList
',' ExclusionConstraintElem
4438 { $$
= lappend
($1, $3); }
4441 ExclusionConstraintElem: index_elem WITH any_operator
4443 $$
= list_make2
($1, $3);
4445 /* allow OPERATOR() decoration for the benefit of ruleutils.c */
4446 | index_elem WITH OPERATOR
'(' any_operator
')'
4448 $$
= list_make2
($1, $5);
4453 WHERE
'(' a_expr
')' { $$
= $3; }
4454 |
/*EMPTY*/ { $$
= NULL
; }
4460 KeyActions
*n
= palloc
(sizeof
(KeyActions
));
4462 n
->updateAction
= $1;
4463 n
->deleteAction
= palloc
(sizeof
(KeyAction
));
4464 n
->deleteAction
->action
= FKCONSTR_ACTION_NOACTION
;
4465 n
->deleteAction
->cols
= NIL
;
4470 KeyActions
*n
= palloc
(sizeof
(KeyActions
));
4472 n
->updateAction
= palloc
(sizeof
(KeyAction
));
4473 n
->updateAction
->action
= FKCONSTR_ACTION_NOACTION
;
4474 n
->updateAction
->cols
= NIL
;
4475 n
->deleteAction
= $1;
4478 | key_update key_delete
4480 KeyActions
*n
= palloc
(sizeof
(KeyActions
));
4482 n
->updateAction
= $1;
4483 n
->deleteAction
= $2;
4486 | key_delete key_update
4488 KeyActions
*n
= palloc
(sizeof
(KeyActions
));
4490 n
->updateAction
= $2;
4491 n
->deleteAction
= $1;
4496 KeyActions
*n
= palloc
(sizeof
(KeyActions
));
4498 n
->updateAction
= palloc
(sizeof
(KeyAction
));
4499 n
->updateAction
->action
= FKCONSTR_ACTION_NOACTION
;
4500 n
->updateAction
->cols
= NIL
;
4501 n
->deleteAction
= palloc
(sizeof
(KeyAction
));
4502 n
->deleteAction
->action
= FKCONSTR_ACTION_NOACTION
;
4503 n
->deleteAction
->cols
= NIL
;
4508 key_update: ON UPDATE key_action
4512 (errcode
(ERRCODE_FEATURE_NOT_SUPPORTED
),
4513 errmsg
("a column list with %s is only supported for ON DELETE actions",
4514 ($3)->action
== FKCONSTR_ACTION_SETNULL ?
"SET NULL" : "SET DEFAULT"),
4515 parser_errposition
(@
1)));
4520 key_delete: ON DELETE_P key_action
4529 KeyAction
*n
= palloc
(sizeof
(KeyAction
));
4531 n
->action
= FKCONSTR_ACTION_NOACTION
;
4537 KeyAction
*n
= palloc
(sizeof
(KeyAction
));
4539 n
->action
= FKCONSTR_ACTION_RESTRICT
;
4545 KeyAction
*n
= palloc
(sizeof
(KeyAction
));
4547 n
->action
= FKCONSTR_ACTION_CASCADE
;
4551 | SET NULL_P opt_column_list
4553 KeyAction
*n
= palloc
(sizeof
(KeyAction
));
4555 n
->action
= FKCONSTR_ACTION_SETNULL
;
4559 | SET DEFAULT opt_column_list
4561 KeyAction
*n
= palloc
(sizeof
(KeyAction
));
4563 n
->action
= FKCONSTR_ACTION_SETDEFAULT
;
4569 OptInherit: INHERITS
'(' qualified_name_list
')' { $$
= $3; }
4570 |
/*EMPTY*/ { $$
= NIL
; }
4573 /* Optional partition key specification */
4574 OptPartitionSpec: PartitionSpec
{ $$
= $1; }
4575 |
/*EMPTY*/ { $$
= NULL
; }
4578 PartitionSpec: PARTITION BY ColId
'(' part_params
')'
4580 PartitionSpec
*n
= makeNode
(PartitionSpec
);
4582 n
->strategy
= parsePartitionStrategy
($3, @
3, yyscanner
);
4590 part_params: part_elem
{ $$
= list_make1
($1); }
4591 | part_params
',' part_elem
{ $$
= lappend
($1, $3); }
4594 part_elem: ColId opt_collate opt_qualified_name
4596 PartitionElem
*n
= makeNode
(PartitionElem
);
4605 | func_expr_windowless opt_collate opt_qualified_name
4607 PartitionElem
*n
= makeNode
(PartitionElem
);
4616 |
'(' a_expr
')' opt_collate opt_qualified_name
4618 PartitionElem
*n
= makeNode
(PartitionElem
);
4629 table_access_method_clause:
4630 USING name
{ $$
= $2; }
4631 |
/*EMPTY*/ { $$
= NULL
; }
4634 /* WITHOUT OIDS is legacy only */
4636 WITH reloptions
{ $$
= $2; }
4637 | WITHOUT OIDS
{ $$
= NIL
; }
4638 |
/*EMPTY*/ { $$
= NIL
; }
4641 OnCommitOption: ON COMMIT DROP
{ $$
= ONCOMMIT_DROP
; }
4642 | ON COMMIT DELETE_P ROWS
{ $$
= ONCOMMIT_DELETE_ROWS
; }
4643 | ON COMMIT PRESERVE ROWS
{ $$
= ONCOMMIT_PRESERVE_ROWS
; }
4644 |
/*EMPTY*/ { $$
= ONCOMMIT_NOOP
; }
4647 OptTableSpace: TABLESPACE name
{ $$
= $2; }
4648 |
/*EMPTY*/ { $$
= NULL
; }
4651 OptConsTableSpace: USING INDEX TABLESPACE name
{ $$
= $4; }
4652 |
/*EMPTY*/ { $$
= NULL
; }
4655 ExistingIndex: USING INDEX name
{ $$
= $3; }
4658 /*****************************************************************************
4661 * CREATE STATISTICS [[IF NOT EXISTS] stats_name] [(stat types)]
4662 * ON expression-list FROM from_list
4664 * Note: the expectation here is that the clauses after ON are a subset of
4665 * SELECT syntax, allowing for expressions and joined tables, and probably
4666 * someday a WHERE clause. Much less than that is currently implemented,
4667 * but the grammar accepts it and then we'll throw FEATURE_NOT_SUPPORTED
4668 * errors as necessary at execution.
4670 * Statistics name is optional unless IF NOT EXISTS is specified.
4672 *****************************************************************************/
4675 CREATE STATISTICS opt_qualified_name
4676 opt_name_list ON stats_params FROM from_list
4678 CreateStatsStmt
*n
= makeNode
(CreateStatsStmt
);
4684 n
->stxcomment
= NULL
;
4685 n
->if_not_exists
= false
;
4688 | CREATE STATISTICS IF_P NOT EXISTS any_name
4689 opt_name_list ON stats_params FROM from_list
4691 CreateStatsStmt
*n
= makeNode
(CreateStatsStmt
);
4697 n
->stxcomment
= NULL
;
4698 n
->if_not_exists
= true
;
4704 * Statistics attributes can be either simple column references, or arbitrary
4705 * expressions in parens. For compatibility with index attributes permitted
4706 * in CREATE INDEX, we allow an expression that's just a function call to be
4707 * written without parens.
4710 stats_params: stats_param
{ $$
= list_make1
($1); }
4711 | stats_params
',' stats_param
{ $$
= lappend
($1, $3); }
4716 $$
= makeNode
(StatsElem
);
4720 | func_expr_windowless
4722 $$
= makeNode
(StatsElem
);
4728 $$
= makeNode
(StatsElem
);
4734 /*****************************************************************************
4737 * ALTER STATISTICS [IF EXISTS] stats_name
4738 * SET STATISTICS <SignedIconst>
4740 *****************************************************************************/
4743 ALTER STATISTICS any_name SET STATISTICS set_statistics_value
4745 AlterStatsStmt
*n
= makeNode
(AlterStatsStmt
);
4748 n
->missing_ok
= false
;
4749 n
->stxstattarget
= $6;
4752 | ALTER STATISTICS IF_P EXISTS any_name SET STATISTICS set_statistics_value
4754 AlterStatsStmt
*n
= makeNode
(AlterStatsStmt
);
4757 n
->missing_ok
= true
;
4758 n
->stxstattarget
= $8;
4763 /*****************************************************************************
4766 * CREATE TABLE relname AS SelectStmt [ WITH [NO] DATA ]
4769 * Note: SELECT ... INTO is a now-deprecated alternative for this.
4771 *****************************************************************************/
4774 CREATE OptTemp TABLE create_as_target AS SelectStmt opt_with_data
4776 CreateTableAsStmt
*ctas
= makeNode
(CreateTableAsStmt
);
4780 ctas
->objtype
= OBJECT_TABLE
;
4781 ctas
->is_select_into
= false
;
4782 ctas
->if_not_exists
= false
;
4783 /* cram additional flags into the IntoClause */
4784 $4->rel
->relpersistence
= $2;
4785 $4->skipData
= !($7);
4788 | CREATE OptTemp TABLE IF_P NOT EXISTS create_as_target AS SelectStmt opt_with_data
4790 CreateTableAsStmt
*ctas
= makeNode
(CreateTableAsStmt
);
4794 ctas
->objtype
= OBJECT_TABLE
;
4795 ctas
->is_select_into
= false
;
4796 ctas
->if_not_exists
= true
;
4797 /* cram additional flags into the IntoClause */
4798 $7->rel
->relpersistence
= $2;
4799 $7->skipData
= !($10);
4805 qualified_name opt_column_list table_access_method_clause
4806 OptWith OnCommitOption OptTableSpace
4808 $$
= makeNode
(IntoClause
);
4811 $$
->accessMethod
= $3;
4814 $$
->tableSpaceName
= $6;
4815 $$
->viewQuery
= NULL
;
4816 $$
->skipData
= false
; /* might get changed later */
4821 WITH DATA_P
{ $$
= true
; }
4822 | WITH NO DATA_P
{ $$
= false
; }
4823 |
/*EMPTY*/ { $$
= true
; }
4827 /*****************************************************************************
4830 * CREATE MATERIALIZED VIEW relname AS SelectStmt
4832 *****************************************************************************/
4835 CREATE OptNoLog MATERIALIZED VIEW create_mv_target AS SelectStmt opt_with_data
4837 CreateTableAsStmt
*ctas
= makeNode
(CreateTableAsStmt
);
4841 ctas
->objtype
= OBJECT_MATVIEW
;
4842 ctas
->is_select_into
= false
;
4843 ctas
->if_not_exists
= false
;
4844 /* cram additional flags into the IntoClause */
4845 $5->rel
->relpersistence
= $2;
4846 $5->skipData
= !($8);
4849 | CREATE OptNoLog MATERIALIZED VIEW IF_P NOT EXISTS create_mv_target AS SelectStmt opt_with_data
4851 CreateTableAsStmt
*ctas
= makeNode
(CreateTableAsStmt
);
4855 ctas
->objtype
= OBJECT_MATVIEW
;
4856 ctas
->is_select_into
= false
;
4857 ctas
->if_not_exists
= true
;
4858 /* cram additional flags into the IntoClause */
4859 $8->rel
->relpersistence
= $2;
4860 $8->skipData
= !($11);
4866 qualified_name opt_column_list table_access_method_clause opt_reloptions OptTableSpace
4868 $$
= makeNode
(IntoClause
);
4871 $$
->accessMethod
= $3;
4873 $$
->onCommit
= ONCOMMIT_NOOP
;
4874 $$
->tableSpaceName
= $5;
4875 $$
->viewQuery
= NULL
; /* filled at analysis time */
4876 $$
->skipData
= false
; /* might get changed later */
4880 OptNoLog: UNLOGGED
{ $$
= RELPERSISTENCE_UNLOGGED
; }
4881 |
/*EMPTY*/ { $$
= RELPERSISTENCE_PERMANENT
; }
4885 /*****************************************************************************
4888 * REFRESH MATERIALIZED VIEW qualified_name
4890 *****************************************************************************/
4893 REFRESH MATERIALIZED VIEW opt_concurrently qualified_name opt_with_data
4895 RefreshMatViewStmt
*n
= makeNode
(RefreshMatViewStmt
);
4899 n
->skipData
= !($6);
4905 /*****************************************************************************
4908 * CREATE SEQUENCE seqname
4909 * ALTER SEQUENCE seqname
4911 *****************************************************************************/
4914 CREATE OptTemp SEQUENCE qualified_name OptSeqOptList
4916 CreateSeqStmt
*n
= makeNode
(CreateSeqStmt
);
4918 $4->relpersistence
= $2;
4921 n
->ownerId
= InvalidOid
;
4922 n
->if_not_exists
= false
;
4925 | CREATE OptTemp SEQUENCE IF_P NOT EXISTS qualified_name OptSeqOptList
4927 CreateSeqStmt
*n
= makeNode
(CreateSeqStmt
);
4929 $7->relpersistence
= $2;
4932 n
->ownerId
= InvalidOid
;
4933 n
->if_not_exists
= true
;
4939 ALTER SEQUENCE qualified_name SeqOptList
4941 AlterSeqStmt
*n
= makeNode
(AlterSeqStmt
);
4945 n
->missing_ok
= false
;
4948 | ALTER SEQUENCE IF_P EXISTS qualified_name SeqOptList
4950 AlterSeqStmt
*n
= makeNode
(AlterSeqStmt
);
4954 n
->missing_ok
= true
;
4960 OptSeqOptList: SeqOptList
{ $$
= $1; }
4961 |
/*EMPTY*/ { $$
= NIL
; }
4964 OptParenthesizedSeqOptList: '(' SeqOptList
')' { $$
= $2; }
4965 |
/*EMPTY*/ { $$
= NIL
; }
4968 SeqOptList: SeqOptElem
{ $$
= list_make1
($1); }
4969 | SeqOptList SeqOptElem
{ $$
= lappend
($1, $2); }
4972 SeqOptElem: AS SimpleTypename
4974 $$
= makeDefElem
("as", (Node
*) $2, @
1);
4978 $$
= makeDefElem
("cache", (Node
*) $2, @
1);
4982 $$
= makeDefElem
("cycle", (Node
*) makeBoolean
(true
), @
1);
4986 $$
= makeDefElem
("cycle", (Node
*) makeBoolean
(false
), @
1);
4988 | INCREMENT opt_by NumericOnly
4990 $$
= makeDefElem
("increment", (Node
*) $3, @
1);
4994 $$
= makeDefElem
("logged", NULL
, @
1);
4996 | MAXVALUE NumericOnly
4998 $$
= makeDefElem
("maxvalue", (Node
*) $2, @
1);
5000 | MINVALUE NumericOnly
5002 $$
= makeDefElem
("minvalue", (Node
*) $2, @
1);
5006 $$
= makeDefElem
("maxvalue", NULL
, @
1);
5010 $$
= makeDefElem
("minvalue", NULL
, @
1);
5014 $$
= makeDefElem
("owned_by", (Node
*) $3, @
1);
5016 | SEQUENCE NAME_P any_name
5018 $$
= makeDefElem
("sequence_name", (Node
*) $3, @
1);
5020 | START opt_with NumericOnly
5022 $$
= makeDefElem
("start", (Node
*) $3, @
1);
5026 $$
= makeDefElem
("restart", NULL
, @
1);
5028 | RESTART opt_with NumericOnly
5030 $$
= makeDefElem
("restart", (Node
*) $3, @
1);
5034 $$
= makeDefElem
("unlogged", NULL
, @
1);
5043 FCONST
{ $$
= (Node
*) makeFloat
($1); }
5044 |
'+' FCONST
{ $$
= (Node
*) makeFloat
($2); }
5047 Float
*f
= makeFloat
($2);
5052 | SignedIconst
{ $$
= (Node
*) makeInteger
($1); }
5055 NumericOnly_list: NumericOnly
{ $$
= list_make1
($1); }
5056 | NumericOnly_list
',' NumericOnly
{ $$
= lappend
($1, $3); }
5059 /*****************************************************************************
5062 * CREATE [OR REPLACE] [TRUSTED] [PROCEDURAL] LANGUAGE ...
5063 * DROP [PROCEDURAL] LANGUAGE ...
5065 *****************************************************************************/
5068 CREATE opt_or_replace opt_trusted opt_procedural LANGUAGE name
5071 * We now interpret parameterless CREATE LANGUAGE as
5072 * CREATE EXTENSION. "OR REPLACE" is silently translated
5073 * to "IF NOT EXISTS", which isn't quite the same, but
5074 * seems more useful than throwing an error. We just
5075 * ignore TRUSTED, as the previous code would have too.
5077 CreateExtensionStmt
*n
= makeNode
(CreateExtensionStmt
);
5079 n
->if_not_exists
= $2;
5084 | CREATE opt_or_replace opt_trusted opt_procedural LANGUAGE name
5085 HANDLER handler_name opt_inline_handler opt_validator
5087 CreatePLangStmt
*n
= makeNode
(CreatePLangStmt
);
5093 n
->plvalidator
= $10;
5100 TRUSTED
{ $$
= true
; }
5101 |
/*EMPTY*/ { $$
= false
; }
5104 /* This ought to be just func_name, but that causes reduce/reduce conflicts
5105 * (CREATE LANGUAGE is the only place where func_name isn't followed by '(').
5106 * Work around by using simple names, instead.
5109 name
{ $$
= list_make1
(makeString
($1)); }
5110 | name attrs
{ $$
= lcons
(makeString
($1), $2); }
5114 INLINE_P handler_name
{ $$
= $2; }
5115 |
/*EMPTY*/ { $$
= NIL
; }
5119 VALIDATOR handler_name
{ $$
= $2; }
5120 | NO VALIDATOR
{ $$
= NIL
; }
5124 validator_clause
{ $$
= $1; }
5125 |
/*EMPTY*/ { $$
= NIL
; }
5133 /*****************************************************************************
5136 * CREATE TABLESPACE tablespace LOCATION '/path/to/tablespace/'
5138 *****************************************************************************/
5140 CreateTableSpaceStmt: CREATE TABLESPACE name OptTableSpaceOwner LOCATION Sconst opt_reloptions
5142 CreateTableSpaceStmt
*n
= makeNode
(CreateTableSpaceStmt
);
5144 n
->tablespacename
= $3;
5152 OptTableSpaceOwner: OWNER RoleSpec
{ $$
= $2; }
5153 |
/*EMPTY */ { $$
= NULL
; }
5156 /*****************************************************************************
5159 * DROP TABLESPACE <tablespace>
5161 * No need for drop behaviour as we cannot implement dependencies for
5162 * objects in other databases; we can only support RESTRICT.
5164 ****************************************************************************/
5166 DropTableSpaceStmt: DROP TABLESPACE name
5168 DropTableSpaceStmt
*n
= makeNode
(DropTableSpaceStmt
);
5170 n
->tablespacename
= $3;
5171 n
->missing_ok
= false
;
5174 | DROP TABLESPACE IF_P EXISTS name
5176 DropTableSpaceStmt
*n
= makeNode
(DropTableSpaceStmt
);
5178 n
->tablespacename
= $5;
5179 n
->missing_ok
= true
;
5184 /*****************************************************************************
5187 * CREATE EXTENSION extension
5188 * [ WITH ] [ SCHEMA schema ] [ VERSION version ]
5190 *****************************************************************************/
5192 CreateExtensionStmt: CREATE EXTENSION name opt_with create_extension_opt_list
5194 CreateExtensionStmt
*n
= makeNode
(CreateExtensionStmt
);
5197 n
->if_not_exists
= false
;
5201 | CREATE EXTENSION IF_P NOT EXISTS name opt_with create_extension_opt_list
5203 CreateExtensionStmt
*n
= makeNode
(CreateExtensionStmt
);
5206 n
->if_not_exists
= true
;
5212 create_extension_opt_list:
5213 create_extension_opt_list create_extension_opt_item
5214 { $$
= lappend
($1, $2); }
5219 create_extension_opt_item:
5222 $$
= makeDefElem
("schema", (Node
*) makeString
($2), @
1);
5224 | VERSION_P NonReservedWord_or_Sconst
5226 $$
= makeDefElem
("new_version", (Node
*) makeString
($2), @
1);
5228 | FROM NonReservedWord_or_Sconst
5231 (errcode
(ERRCODE_FEATURE_NOT_SUPPORTED
),
5232 errmsg
("CREATE EXTENSION ... FROM is no longer supported"),
5233 parser_errposition
(@
1)));
5237 $$
= makeDefElem
("cascade", (Node
*) makeBoolean
(true
), @
1);
5241 /*****************************************************************************
5243 * ALTER EXTENSION name UPDATE [ TO version ]
5245 *****************************************************************************/
5247 AlterExtensionStmt: ALTER EXTENSION name UPDATE alter_extension_opt_list
5249 AlterExtensionStmt
*n
= makeNode
(AlterExtensionStmt
);
5257 alter_extension_opt_list:
5258 alter_extension_opt_list alter_extension_opt_item
5259 { $$
= lappend
($1, $2); }
5264 alter_extension_opt_item:
5265 TO NonReservedWord_or_Sconst
5267 $$
= makeDefElem
("new_version", (Node
*) makeString
($2), @
1);
5271 /*****************************************************************************
5273 * ALTER EXTENSION name ADD/DROP object-identifier
5275 *****************************************************************************/
5277 AlterExtensionContentsStmt:
5278 ALTER EXTENSION name add_drop object_type_name name
5280 AlterExtensionContentsStmt
*n
= makeNode
(AlterExtensionContentsStmt
);
5285 n
->object
= (Node
*) makeString
($6);
5288 | ALTER EXTENSION name add_drop object_type_any_name any_name
5290 AlterExtensionContentsStmt
*n
= makeNode
(AlterExtensionContentsStmt
);
5295 n
->object
= (Node
*) $6;
5298 | ALTER EXTENSION name add_drop AGGREGATE aggregate_with_argtypes
5300 AlterExtensionContentsStmt
*n
= makeNode
(AlterExtensionContentsStmt
);
5304 n
->objtype
= OBJECT_AGGREGATE
;
5305 n
->object
= (Node
*) $6;
5308 | ALTER EXTENSION name add_drop CAST
'(' Typename AS Typename
')'
5310 AlterExtensionContentsStmt
*n
= makeNode
(AlterExtensionContentsStmt
);
5314 n
->objtype
= OBJECT_CAST
;
5315 n
->object
= (Node
*) list_make2
($7, $9);
5318 | ALTER EXTENSION name add_drop DOMAIN_P Typename
5320 AlterExtensionContentsStmt
*n
= makeNode
(AlterExtensionContentsStmt
);
5324 n
->objtype
= OBJECT_DOMAIN
;
5325 n
->object
= (Node
*) $6;
5328 | ALTER EXTENSION name add_drop FUNCTION function_with_argtypes
5330 AlterExtensionContentsStmt
*n
= makeNode
(AlterExtensionContentsStmt
);
5334 n
->objtype
= OBJECT_FUNCTION
;
5335 n
->object
= (Node
*) $6;
5338 | ALTER EXTENSION name add_drop OPERATOR operator_with_argtypes
5340 AlterExtensionContentsStmt
*n
= makeNode
(AlterExtensionContentsStmt
);
5344 n
->objtype
= OBJECT_OPERATOR
;
5345 n
->object
= (Node
*) $6;
5348 | ALTER EXTENSION name add_drop OPERATOR CLASS any_name USING name
5350 AlterExtensionContentsStmt
*n
= makeNode
(AlterExtensionContentsStmt
);
5354 n
->objtype
= OBJECT_OPCLASS
;
5355 n
->object
= (Node
*) lcons
(makeString
($9), $7);
5358 | ALTER EXTENSION name add_drop OPERATOR FAMILY any_name USING name
5360 AlterExtensionContentsStmt
*n
= makeNode
(AlterExtensionContentsStmt
);
5364 n
->objtype
= OBJECT_OPFAMILY
;
5365 n
->object
= (Node
*) lcons
(makeString
($9), $7);
5368 | ALTER EXTENSION name add_drop PROCEDURE function_with_argtypes
5370 AlterExtensionContentsStmt
*n
= makeNode
(AlterExtensionContentsStmt
);
5374 n
->objtype
= OBJECT_PROCEDURE
;
5375 n
->object
= (Node
*) $6;
5378 | ALTER EXTENSION name add_drop ROUTINE function_with_argtypes
5380 AlterExtensionContentsStmt
*n
= makeNode
(AlterExtensionContentsStmt
);
5384 n
->objtype
= OBJECT_ROUTINE
;
5385 n
->object
= (Node
*) $6;
5388 | ALTER EXTENSION name add_drop TRANSFORM FOR Typename LANGUAGE name
5390 AlterExtensionContentsStmt
*n
= makeNode
(AlterExtensionContentsStmt
);
5394 n
->objtype
= OBJECT_TRANSFORM
;
5395 n
->object
= (Node
*) list_make2
($7, makeString
($9));
5398 | ALTER EXTENSION name add_drop TYPE_P Typename
5400 AlterExtensionContentsStmt
*n
= makeNode
(AlterExtensionContentsStmt
);
5404 n
->objtype
= OBJECT_TYPE
;
5405 n
->object
= (Node
*) $6;
5410 /*****************************************************************************
5413 * CREATE FOREIGN DATA WRAPPER name options
5415 *****************************************************************************/
5417 CreateFdwStmt: CREATE FOREIGN DATA_P WRAPPER name opt_fdw_options create_generic_options
5419 CreateFdwStmt
*n
= makeNode
(CreateFdwStmt
);
5422 n
->func_options
= $6;
5429 HANDLER handler_name
{ $$
= makeDefElem
("handler", (Node
*) $2, @
1); }
5430 | NO HANDLER
{ $$
= makeDefElem
("handler", NULL
, @
1); }
5431 | VALIDATOR handler_name
{ $$
= makeDefElem
("validator", (Node
*) $2, @
1); }
5432 | NO VALIDATOR
{ $$
= makeDefElem
("validator", NULL
, @
1); }
5436 fdw_option
{ $$
= list_make1
($1); }
5437 | fdw_options fdw_option
{ $$
= lappend
($1, $2); }
5441 fdw_options
{ $$
= $1; }
5442 |
/*EMPTY*/ { $$
= NIL
; }
5445 /*****************************************************************************
5448 * ALTER FOREIGN DATA WRAPPER name options
5450 ****************************************************************************/
5452 AlterFdwStmt: ALTER FOREIGN DATA_P WRAPPER name opt_fdw_options alter_generic_options
5454 AlterFdwStmt
*n
= makeNode
(AlterFdwStmt
);
5457 n
->func_options
= $6;
5461 | ALTER FOREIGN DATA_P WRAPPER name fdw_options
5463 AlterFdwStmt
*n
= makeNode
(AlterFdwStmt
);
5466 n
->func_options
= $6;
5472 /* Options definition for CREATE FDW, SERVER and USER MAPPING */
5473 create_generic_options:
5474 OPTIONS
'(' generic_option_list
')' { $$
= $3; }
5475 |
/*EMPTY*/ { $$
= NIL
; }
5478 generic_option_list:
5481 $$
= list_make1
($1);
5483 | generic_option_list
',' generic_option_elem
5485 $$
= lappend
($1, $3);
5489 /* Options definition for ALTER FDW, SERVER and USER MAPPING */
5490 alter_generic_options:
5491 OPTIONS
'(' alter_generic_option_list
')' { $$
= $3; }
5494 alter_generic_option_list:
5495 alter_generic_option_elem
5497 $$
= list_make1
($1);
5499 | alter_generic_option_list
',' alter_generic_option_elem
5501 $$
= lappend
($1, $3);
5505 alter_generic_option_elem:
5510 | SET generic_option_elem
5513 $$
->defaction
= DEFELEM_SET
;
5515 | ADD_P generic_option_elem
5518 $$
->defaction
= DEFELEM_ADD
;
5520 | DROP generic_option_name
5522 $$
= makeDefElemExtended
(NULL
, $2, NULL
, DEFELEM_DROP
, @
2);
5526 generic_option_elem:
5527 generic_option_name generic_option_arg
5529 $$
= makeDefElem
($1, $2, @
1);
5533 generic_option_name:
5534 ColLabel
{ $$
= $1; }
5537 /* We could use def_arg here, but the spec only requires string literals */
5539 Sconst
{ $$
= (Node
*) makeString
($1); }
5542 /*****************************************************************************
5545 * CREATE SERVER name [TYPE] [VERSION] [OPTIONS]
5547 *****************************************************************************/
5549 CreateForeignServerStmt: CREATE SERVER name opt_type opt_foreign_server_version
5550 FOREIGN DATA_P WRAPPER name create_generic_options
5552 CreateForeignServerStmt
*n
= makeNode
(CreateForeignServerStmt
);
5559 n
->if_not_exists
= false
;
5562 | CREATE SERVER IF_P NOT EXISTS name opt_type opt_foreign_server_version
5563 FOREIGN DATA_P WRAPPER name create_generic_options
5565 CreateForeignServerStmt
*n
= makeNode
(CreateForeignServerStmt
);
5572 n
->if_not_exists
= true
;
5578 TYPE_P Sconst
{ $$
= $2; }
5579 |
/*EMPTY*/ { $$
= NULL
; }
5583 foreign_server_version:
5584 VERSION_P Sconst
{ $$
= $2; }
5585 | VERSION_P NULL_P
{ $$
= NULL
; }
5588 opt_foreign_server_version:
5589 foreign_server_version
{ $$
= $1; }
5590 |
/*EMPTY*/ { $$
= NULL
; }
5593 /*****************************************************************************
5596 * ALTER SERVER name [VERSION] [OPTIONS]
5598 ****************************************************************************/
5600 AlterForeignServerStmt: ALTER SERVER name foreign_server_version alter_generic_options
5602 AlterForeignServerStmt
*n
= makeNode
(AlterForeignServerStmt
);
5607 n
->has_version
= true
;
5610 | ALTER SERVER name foreign_server_version
5612 AlterForeignServerStmt
*n
= makeNode
(AlterForeignServerStmt
);
5616 n
->has_version
= true
;
5619 | ALTER SERVER name alter_generic_options
5621 AlterForeignServerStmt
*n
= makeNode
(AlterForeignServerStmt
);
5629 /*****************************************************************************
5632 * CREATE FOREIGN TABLE relname (...) SERVER name (...)
5634 *****************************************************************************/
5636 CreateForeignTableStmt:
5637 CREATE FOREIGN TABLE qualified_name
5638 '(' OptTableElementList
')'
5639 OptInherit SERVER name create_generic_options
5641 CreateForeignTableStmt
*n
= makeNode
(CreateForeignTableStmt
);
5643 $4->relpersistence
= RELPERSISTENCE_PERMANENT
;
5644 n
->base.relation
= $4;
5645 n
->base.tableElts
= $6;
5646 n
->base.inhRelations
= $8;
5647 n
->base.ofTypename
= NULL
;
5648 n
->base.constraints
= NIL
;
5649 n
->base.options
= NIL
;
5650 n
->base.oncommit
= ONCOMMIT_NOOP
;
5651 n
->base.tablespacename
= NULL
;
5652 n
->base.if_not_exists
= false
;
5653 /* FDW-specific data */
5654 n
->servername
= $10;
5658 | CREATE FOREIGN TABLE IF_P NOT EXISTS qualified_name
5659 '(' OptTableElementList
')'
5660 OptInherit SERVER name create_generic_options
5662 CreateForeignTableStmt
*n
= makeNode
(CreateForeignTableStmt
);
5664 $7->relpersistence
= RELPERSISTENCE_PERMANENT
;
5665 n
->base.relation
= $7;
5666 n
->base.tableElts
= $9;
5667 n
->base.inhRelations
= $11;
5668 n
->base.ofTypename
= NULL
;
5669 n
->base.constraints
= NIL
;
5670 n
->base.options
= NIL
;
5671 n
->base.oncommit
= ONCOMMIT_NOOP
;
5672 n
->base.tablespacename
= NULL
;
5673 n
->base.if_not_exists
= true
;
5674 /* FDW-specific data */
5675 n
->servername
= $13;
5679 | CREATE FOREIGN TABLE qualified_name
5680 PARTITION OF qualified_name OptTypedTableElementList PartitionBoundSpec
5681 SERVER name create_generic_options
5683 CreateForeignTableStmt
*n
= makeNode
(CreateForeignTableStmt
);
5685 $4->relpersistence
= RELPERSISTENCE_PERMANENT
;
5686 n
->base.relation
= $4;
5687 n
->base.inhRelations
= list_make1
($7);
5688 n
->base.tableElts
= $8;
5689 n
->base.partbound
= $9;
5690 n
->base.ofTypename
= NULL
;
5691 n
->base.constraints
= NIL
;
5692 n
->base.options
= NIL
;
5693 n
->base.oncommit
= ONCOMMIT_NOOP
;
5694 n
->base.tablespacename
= NULL
;
5695 n
->base.if_not_exists
= false
;
5696 /* FDW-specific data */
5697 n
->servername
= $11;
5701 | CREATE FOREIGN TABLE IF_P NOT EXISTS qualified_name
5702 PARTITION OF qualified_name OptTypedTableElementList PartitionBoundSpec
5703 SERVER name create_generic_options
5705 CreateForeignTableStmt
*n
= makeNode
(CreateForeignTableStmt
);
5707 $7->relpersistence
= RELPERSISTENCE_PERMANENT
;
5708 n
->base.relation
= $7;
5709 n
->base.inhRelations
= list_make1
($10);
5710 n
->base.tableElts
= $11;
5711 n
->base.partbound
= $12;
5712 n
->base.ofTypename
= NULL
;
5713 n
->base.constraints
= NIL
;
5714 n
->base.options
= NIL
;
5715 n
->base.oncommit
= ONCOMMIT_NOOP
;
5716 n
->base.tablespacename
= NULL
;
5717 n
->base.if_not_exists
= true
;
5718 /* FDW-specific data */
5719 n
->servername
= $14;
5725 /*****************************************************************************
5728 * IMPORT FOREIGN SCHEMA remote_schema
5729 * [ { LIMIT TO | EXCEPT } ( table_list ) ]
5730 * FROM SERVER server_name INTO local_schema [ OPTIONS (...) ]
5732 ****************************************************************************/
5734 ImportForeignSchemaStmt:
5735 IMPORT_P FOREIGN SCHEMA name import_qualification
5736 FROM SERVER name INTO name create_generic_options
5738 ImportForeignSchemaStmt
*n
= makeNode
(ImportForeignSchemaStmt
);
5740 n
->server_name
= $8;
5741 n
->remote_schema
= $4;
5742 n
->local_schema
= $10;
5743 n
->list_type
= $5->type
;
5744 n
->table_list
= $5->table_names
;
5750 import_qualification_type:
5751 LIMIT TO
{ $$
= FDW_IMPORT_SCHEMA_LIMIT_TO
; }
5752 | EXCEPT
{ $$
= FDW_IMPORT_SCHEMA_EXCEPT
; }
5755 import_qualification:
5756 import_qualification_type
'(' relation_expr_list
')'
5758 ImportQual
*n
= (ImportQual
*) palloc
(sizeof
(ImportQual
));
5761 n
->table_names
= $3;
5766 ImportQual
*n
= (ImportQual
*) palloc
(sizeof
(ImportQual
));
5767 n
->type
= FDW_IMPORT_SCHEMA_ALL
;
5768 n
->table_names
= NIL
;
5773 /*****************************************************************************
5776 * CREATE USER MAPPING FOR auth_ident SERVER name [OPTIONS]
5778 *****************************************************************************/
5780 CreateUserMappingStmt: CREATE USER MAPPING FOR auth_ident SERVER name create_generic_options
5782 CreateUserMappingStmt
*n
= makeNode
(CreateUserMappingStmt
);
5787 n
->if_not_exists
= false
;
5790 | CREATE USER MAPPING IF_P NOT EXISTS FOR auth_ident SERVER name create_generic_options
5792 CreateUserMappingStmt
*n
= makeNode
(CreateUserMappingStmt
);
5795 n
->servername
= $10;
5797 n
->if_not_exists
= true
;
5802 /* User mapping authorization identifier */
5803 auth_ident: RoleSpec
{ $$
= $1; }
5804 | USER
{ $$
= makeRoleSpec
(ROLESPEC_CURRENT_USER
, @
1); }
5807 /*****************************************************************************
5810 * DROP USER MAPPING FOR auth_ident SERVER name
5812 * XXX you'd think this should have a CASCADE/RESTRICT option, even if it's
5813 * only pro forma; but the SQL standard doesn't show one.
5814 ****************************************************************************/
5816 DropUserMappingStmt: DROP USER MAPPING FOR auth_ident SERVER name
5818 DropUserMappingStmt
*n
= makeNode
(DropUserMappingStmt
);
5822 n
->missing_ok
= false
;
5825 | DROP USER MAPPING IF_P EXISTS FOR auth_ident SERVER name
5827 DropUserMappingStmt
*n
= makeNode
(DropUserMappingStmt
);
5831 n
->missing_ok
= true
;
5836 /*****************************************************************************
5839 * ALTER USER MAPPING FOR auth_ident SERVER name OPTIONS
5841 ****************************************************************************/
5843 AlterUserMappingStmt: ALTER USER MAPPING FOR auth_ident SERVER name alter_generic_options
5845 AlterUserMappingStmt
*n
= makeNode
(AlterUserMappingStmt
);
5854 /*****************************************************************************
5857 * CREATE POLICY name ON table
5858 * [AS { PERMISSIVE | RESTRICTIVE } ]
5859 * [FOR { SELECT | INSERT | UPDATE | DELETE } ]
5861 * [USING (qual)] [WITH CHECK (with check qual)]
5862 * ALTER POLICY name ON table [TO role, ...]
5863 * [USING (qual)] [WITH CHECK (with check qual)]
5865 *****************************************************************************/
5868 CREATE POLICY name ON qualified_name RowSecurityDefaultPermissive
5869 RowSecurityDefaultForCmd RowSecurityDefaultToRole
5870 RowSecurityOptionalExpr RowSecurityOptionalWithCheck
5872 CreatePolicyStmt
*n
= makeNode
(CreatePolicyStmt
);
5874 n
->policy_name
= $3;
5880 n
->with_check
= $10;
5886 ALTER POLICY name ON qualified_name RowSecurityOptionalToRole
5887 RowSecurityOptionalExpr RowSecurityOptionalWithCheck
5889 AlterPolicyStmt
*n
= makeNode
(AlterPolicyStmt
);
5891 n
->policy_name
= $3;
5900 RowSecurityOptionalExpr:
5901 USING
'(' a_expr
')' { $$
= $3; }
5902 |
/* EMPTY */ { $$
= NULL
; }
5905 RowSecurityOptionalWithCheck:
5906 WITH CHECK
'(' a_expr
')' { $$
= $4; }
5907 |
/* EMPTY */ { $$
= NULL
; }
5910 RowSecurityDefaultToRole:
5911 TO role_list
{ $$
= $2; }
5912 |
/* EMPTY */ { $$
= list_make1
(makeRoleSpec
(ROLESPEC_PUBLIC
, -1)); }
5915 RowSecurityOptionalToRole:
5916 TO role_list
{ $$
= $2; }
5917 |
/* EMPTY */ { $$
= NULL
; }
5920 RowSecurityDefaultPermissive:
5923 if
(strcmp
($2, "permissive") == 0)
5925 else if
(strcmp
($2, "restrictive") == 0)
5929 (errcode
(ERRCODE_SYNTAX_ERROR
),
5930 errmsg
("unrecognized row security option \"%s\"", $2),
5931 errhint
("Only PERMISSIVE or RESTRICTIVE policies are supported currently."),
5932 parser_errposition
(@
2)));
5935 |
/* EMPTY */ { $$
= true
; }
5938 RowSecurityDefaultForCmd:
5939 FOR row_security_cmd
{ $$
= $2; }
5940 |
/* EMPTY */ { $$
= "all"; }
5945 | SELECT
{ $$
= "select"; }
5946 | INSERT
{ $$
= "insert"; }
5947 | UPDATE
{ $$
= "update"; }
5948 | DELETE_P
{ $$
= "delete"; }
5951 /*****************************************************************************
5954 * CREATE ACCESS METHOD name HANDLER handler_name
5956 *****************************************************************************/
5958 CreateAmStmt: CREATE ACCESS METHOD name TYPE_P am_type HANDLER handler_name
5960 CreateAmStmt
*n
= makeNode
(CreateAmStmt
);
5963 n
->handler_name
= $8;
5970 INDEX
{ $$
= AMTYPE_INDEX
; }
5971 | TABLE
{ $$
= AMTYPE_TABLE
; }
5974 /*****************************************************************************
5977 * CREATE TRIGGER ...
5979 *****************************************************************************/
5982 CREATE opt_or_replace TRIGGER name TriggerActionTime TriggerEvents ON
5983 qualified_name TriggerReferencing TriggerForSpec TriggerWhen
5984 EXECUTE FUNCTION_or_PROCEDURE func_name
'(' TriggerFuncArgs
')'
5986 CreateTrigStmt
*n
= makeNode
(CreateTrigStmt
);
5989 n
->isconstraint
= false
;
5996 n
->events
= intVal
(linitial
($6));
5997 n
->columns
= (List
*) lsecond
($6);
5998 n
->whenClause
= $11;
5999 n
->transitionRels
= $9;
6000 n
->deferrable
= false
;
6001 n
->initdeferred
= false
;
6002 n
->constrrel
= NULL
;
6005 | CREATE opt_or_replace CONSTRAINT TRIGGER name AFTER TriggerEvents ON
6006 qualified_name OptConstrFromTable ConstraintAttributeSpec
6007 FOR EACH ROW TriggerWhen
6008 EXECUTE FUNCTION_or_PROCEDURE func_name
'(' TriggerFuncArgs
')'
6010 CreateTrigStmt
*n
= makeNode
(CreateTrigStmt
);
6013 if
(n
->replace
) /* not supported, see CreateTrigger */
6015 (errcode
(ERRCODE_FEATURE_NOT_SUPPORTED
),
6016 errmsg
("CREATE OR REPLACE CONSTRAINT TRIGGER is not supported"),
6017 parser_errposition
(@
1)));
6018 n
->isconstraint
= true
;
6024 n
->timing
= TRIGGER_TYPE_AFTER
;
6025 n
->events
= intVal
(linitial
($7));
6026 n
->columns
= (List
*) lsecond
($7);
6027 n
->whenClause
= $15;
6028 n
->transitionRels
= NIL
;
6029 processCASbits
($11, @
11, "TRIGGER",
6030 &n
->deferrable
, &n
->initdeferred
, NULL
,
6031 NULL
, NULL
, yyscanner
);
6038 BEFORE
{ $$
= TRIGGER_TYPE_BEFORE
; }
6039 | AFTER
{ $$
= TRIGGER_TYPE_AFTER
; }
6040 | INSTEAD OF
{ $$
= TRIGGER_TYPE_INSTEAD
; }
6046 | TriggerEvents OR TriggerOneEvent
6048 int events1
= intVal
(linitial
($1));
6049 int events2
= intVal
(linitial
($3));
6050 List
*columns1
= (List
*) lsecond
($1);
6051 List
*columns2
= (List
*) lsecond
($3);
6053 if
(events1
& events2
)
6054 parser_yyerror
("duplicate trigger events specified");
6056 * concat'ing the columns lists loses information about
6057 * which columns went with which event, but so long as
6058 * only UPDATE carries columns and we disallow multiple
6059 * UPDATE items, it doesn't matter. Command execution
6060 * should just ignore the columns for non-UPDATE events.
6062 $$
= list_make2
(makeInteger
(events1 | events2
),
6063 list_concat
(columns1
, columns2
));
6069 { $$
= list_make2
(makeInteger
(TRIGGER_TYPE_INSERT
), NIL
); }
6071 { $$
= list_make2
(makeInteger
(TRIGGER_TYPE_DELETE
), NIL
); }
6073 { $$
= list_make2
(makeInteger
(TRIGGER_TYPE_UPDATE
), NIL
); }
6074 | UPDATE OF columnList
6075 { $$
= list_make2
(makeInteger
(TRIGGER_TYPE_UPDATE
), $3); }
6077 { $$
= list_make2
(makeInteger
(TRIGGER_TYPE_TRUNCATE
), NIL
); }
6081 REFERENCING TriggerTransitions
{ $$
= $2; }
6082 |
/*EMPTY*/ { $$
= NIL
; }
6086 TriggerTransition
{ $$
= list_make1
($1); }
6087 | TriggerTransitions TriggerTransition
{ $$
= lappend
($1, $2); }
6091 TransitionOldOrNew TransitionRowOrTable opt_as TransitionRelName
6093 TriggerTransition
*n
= makeNode
(TriggerTransition
);
6104 | OLD
{ $$
= false
; }
6107 TransitionRowOrTable:
6108 TABLE
{ $$
= true
; }
6110 * According to the standard, lack of a keyword here implies ROW.
6111 * Support for that would require prohibiting ROW entirely here,
6112 * reserving the keyword ROW, and/or requiring AS (instead of
6113 * allowing it to be optional, as the standard specifies) as the
6114 * next token. Requiring ROW seems cleanest and easiest to
6117 | ROW
{ $$
= false
; }
6125 FOR TriggerForOptEach TriggerForType
6132 * If ROW/STATEMENT not specified, default to
6133 * STATEMENT, per SQL
6146 | STATEMENT
{ $$
= false
; }
6150 WHEN
'(' a_expr
')' { $$
= $3; }
6151 |
/*EMPTY*/ { $$
= NULL
; }
6154 FUNCTION_or_PROCEDURE:
6160 TriggerFuncArg
{ $$
= list_make1
($1); }
6161 | TriggerFuncArgs
',' TriggerFuncArg
{ $$
= lappend
($1, $3); }
6162 |
/*EMPTY*/ { $$
= NIL
; }
6168 $$
= (Node
*) makeString
(psprintf
("%d", $1));
6170 | FCONST
{ $$
= (Node
*) makeString
($1); }
6171 | Sconst
{ $$
= (Node
*) makeString
($1); }
6172 | ColLabel
{ $$
= (Node
*) makeString
($1); }
6176 FROM qualified_name
{ $$
= $2; }
6177 |
/*EMPTY*/ { $$
= NULL
; }
6180 ConstraintAttributeSpec:
6183 | ConstraintAttributeSpec ConstraintAttributeElem
6186 * We must complain about conflicting options.
6187 * We could, but choose not to, complain about redundant
6188 * options (ie, where $2's bit is already set in $1).
6190 int newspec
= $1 |
$2;
6192 /* special message for this case */
6193 if
((newspec
& (CAS_NOT_DEFERRABLE | CAS_INITIALLY_DEFERRED
)) == (CAS_NOT_DEFERRABLE | CAS_INITIALLY_DEFERRED
))
6195 (errcode
(ERRCODE_SYNTAX_ERROR
),
6196 errmsg
("constraint declared INITIALLY DEFERRED must be DEFERRABLE"),
6197 parser_errposition
(@
2)));
6198 /* generic message for other conflicts */
6199 if
((newspec
& (CAS_NOT_DEFERRABLE | CAS_DEFERRABLE
)) == (CAS_NOT_DEFERRABLE | CAS_DEFERRABLE
) ||
6200 (newspec
& (CAS_INITIALLY_IMMEDIATE | CAS_INITIALLY_DEFERRED
)) == (CAS_INITIALLY_IMMEDIATE | CAS_INITIALLY_DEFERRED
) ||
6201 (newspec
& (CAS_NOT_ENFORCED | CAS_ENFORCED
)) == (CAS_NOT_ENFORCED | CAS_ENFORCED
))
6203 (errcode
(ERRCODE_SYNTAX_ERROR
),
6204 errmsg
("conflicting constraint properties"),
6205 parser_errposition
(@
2)));
6210 ConstraintAttributeElem:
6211 NOT DEFERRABLE
{ $$
= CAS_NOT_DEFERRABLE
; }
6212 | DEFERRABLE
{ $$
= CAS_DEFERRABLE
; }
6213 | INITIALLY IMMEDIATE
{ $$
= CAS_INITIALLY_IMMEDIATE
; }
6214 | INITIALLY DEFERRED
{ $$
= CAS_INITIALLY_DEFERRED
; }
6215 | NOT VALID
{ $$
= CAS_NOT_VALID
; }
6216 | NO INHERIT
{ $$
= CAS_NO_INHERIT
; }
6217 | NOT ENFORCED
{ $$
= CAS_NOT_ENFORCED
; }
6218 | ENFORCED
{ $$
= CAS_ENFORCED
; }
6222 /*****************************************************************************
6225 * CREATE EVENT TRIGGER ...
6226 * ALTER EVENT TRIGGER ...
6228 *****************************************************************************/
6230 CreateEventTrigStmt:
6231 CREATE EVENT TRIGGER name ON ColLabel
6232 EXECUTE FUNCTION_or_PROCEDURE func_name
'(' ')'
6234 CreateEventTrigStmt
*n
= makeNode
(CreateEventTrigStmt
);
6238 n
->whenclause
= NULL
;
6242 | CREATE EVENT TRIGGER name ON ColLabel
6243 WHEN event_trigger_when_list
6244 EXECUTE FUNCTION_or_PROCEDURE func_name
'(' ')'
6246 CreateEventTrigStmt
*n
= makeNode
(CreateEventTrigStmt
);
6256 event_trigger_when_list:
6257 event_trigger_when_item
6258 { $$
= list_make1
($1); }
6259 | event_trigger_when_list AND event_trigger_when_item
6260 { $$
= lappend
($1, $3); }
6263 event_trigger_when_item:
6264 ColId IN_P
'(' event_trigger_value_list
')'
6265 { $$
= makeDefElem
($1, (Node
*) $4, @
1); }
6268 event_trigger_value_list:
6270 { $$
= list_make1
(makeString
($1)); }
6271 | event_trigger_value_list
',' SCONST
6272 { $$
= lappend
($1, makeString
($3)); }
6276 ALTER EVENT TRIGGER name enable_trigger
6278 AlterEventTrigStmt
*n
= makeNode
(AlterEventTrigStmt
);
6287 ENABLE_P
{ $$
= TRIGGER_FIRES_ON_ORIGIN
; }
6288 | ENABLE_P REPLICA
{ $$
= TRIGGER_FIRES_ON_REPLICA
; }
6289 | ENABLE_P ALWAYS
{ $$
= TRIGGER_FIRES_ALWAYS
; }
6290 | DISABLE_P
{ $$
= TRIGGER_DISABLED
; }
6293 /*****************************************************************************
6296 * CREATE ASSERTION ...
6298 *****************************************************************************/
6300 CreateAssertionStmt:
6301 CREATE ASSERTION any_name CHECK
'(' a_expr
')' ConstraintAttributeSpec
6304 (errcode
(ERRCODE_FEATURE_NOT_SUPPORTED
),
6305 errmsg
("CREATE ASSERTION is not yet implemented"),
6306 parser_errposition
(@
1)));
6313 /*****************************************************************************
6316 * define (aggregate,operator,type)
6318 *****************************************************************************/
6321 CREATE opt_or_replace AGGREGATE func_name aggr_args definition
6323 DefineStmt
*n
= makeNode
(DefineStmt
);
6325 n
->kind
= OBJECT_AGGREGATE
;
6326 n
->oldstyle
= false
;
6333 | CREATE opt_or_replace AGGREGATE func_name old_aggr_definition
6335 /* old-style (pre-8.2) syntax for CREATE AGGREGATE */
6336 DefineStmt
*n
= makeNode
(DefineStmt
);
6338 n
->kind
= OBJECT_AGGREGATE
;
6346 | CREATE OPERATOR any_operator definition
6348 DefineStmt
*n
= makeNode
(DefineStmt
);
6350 n
->kind
= OBJECT_OPERATOR
;
6351 n
->oldstyle
= false
;
6357 | CREATE TYPE_P any_name definition
6359 DefineStmt
*n
= makeNode
(DefineStmt
);
6361 n
->kind
= OBJECT_TYPE
;
6362 n
->oldstyle
= false
;
6368 | CREATE TYPE_P any_name
6370 /* Shell type (identified by lack of definition) */
6371 DefineStmt
*n
= makeNode
(DefineStmt
);
6373 n
->kind
= OBJECT_TYPE
;
6374 n
->oldstyle
= false
;
6377 n
->definition
= NIL
;
6380 | CREATE TYPE_P any_name AS
'(' OptTableFuncElementList
')'
6382 CompositeTypeStmt
*n
= makeNode
(CompositeTypeStmt
);
6384 /* can't use qualified_name, sigh */
6385 n
->typevar
= makeRangeVarFromAnyName
($3, @
3, yyscanner
);
6389 | CREATE TYPE_P any_name AS ENUM_P
'(' opt_enum_val_list
')'
6391 CreateEnumStmt
*n
= makeNode
(CreateEnumStmt
);
6397 | CREATE TYPE_P any_name AS RANGE definition
6399 CreateRangeStmt
*n
= makeNode
(CreateRangeStmt
);
6405 | CREATE TEXT_P SEARCH PARSER any_name definition
6407 DefineStmt
*n
= makeNode
(DefineStmt
);
6409 n
->kind
= OBJECT_TSPARSER
;
6415 | CREATE TEXT_P SEARCH DICTIONARY any_name definition
6417 DefineStmt
*n
= makeNode
(DefineStmt
);
6419 n
->kind
= OBJECT_TSDICTIONARY
;
6425 | CREATE TEXT_P SEARCH TEMPLATE any_name definition
6427 DefineStmt
*n
= makeNode
(DefineStmt
);
6429 n
->kind
= OBJECT_TSTEMPLATE
;
6435 | CREATE TEXT_P SEARCH CONFIGURATION any_name definition
6437 DefineStmt
*n
= makeNode
(DefineStmt
);
6439 n
->kind
= OBJECT_TSCONFIGURATION
;
6445 | CREATE COLLATION any_name definition
6447 DefineStmt
*n
= makeNode
(DefineStmt
);
6449 n
->kind
= OBJECT_COLLATION
;
6455 | CREATE COLLATION IF_P NOT EXISTS any_name definition
6457 DefineStmt
*n
= makeNode
(DefineStmt
);
6459 n
->kind
= OBJECT_COLLATION
;
6463 n
->if_not_exists
= true
;
6466 | CREATE COLLATION any_name FROM any_name
6468 DefineStmt
*n
= makeNode
(DefineStmt
);
6470 n
->kind
= OBJECT_COLLATION
;
6473 n
->definition
= list_make1
(makeDefElem
("from", (Node
*) $5, @
5));
6476 | CREATE COLLATION IF_P NOT EXISTS any_name FROM any_name
6478 DefineStmt
*n
= makeNode
(DefineStmt
);
6480 n
->kind
= OBJECT_COLLATION
;
6483 n
->definition
= list_make1
(makeDefElem
("from", (Node
*) $8, @
8));
6484 n
->if_not_exists
= true
;
6489 definition: '(' def_list
')' { $$
= $2; }
6492 def_list: def_elem
{ $$
= list_make1
($1); }
6493 | def_list
',' def_elem
{ $$
= lappend
($1, $3); }
6496 def_elem: ColLabel
'=' def_arg
6498 $$
= makeDefElem
($1, (Node
*) $3, @
1);
6502 $$
= makeDefElem
($1, NULL
, @
1);
6506 /* Note: any simple identifier will be returned as a type name! */
6507 def_arg: func_type
{ $$
= (Node
*) $1; }
6508 | reserved_keyword
{ $$
= (Node
*) makeString
(pstrdup
($1)); }
6509 | qual_all_Op
{ $$
= (Node
*) $1; }
6510 | NumericOnly
{ $$
= (Node
*) $1; }
6511 | Sconst
{ $$
= (Node
*) makeString
($1); }
6512 | NONE
{ $$
= (Node
*) makeString
(pstrdup
($1)); }
6515 old_aggr_definition: '(' old_aggr_list
')' { $$
= $2; }
6518 old_aggr_list: old_aggr_elem
{ $$
= list_make1
($1); }
6519 | old_aggr_list
',' old_aggr_elem
{ $$
= lappend
($1, $3); }
6523 * Must use IDENT here to avoid reduce/reduce conflicts; fortunately none of
6524 * the item names needed in old aggregate definitions are likely to become
6527 old_aggr_elem: IDENT
'=' def_arg
6529 $$
= makeDefElem
($1, (Node
*) $3, @
1);
6534 enum_val_list
{ $$
= $1; }
6535 |
/*EMPTY*/ { $$
= NIL
; }
6538 enum_val_list: Sconst
6539 { $$
= list_make1
(makeString
($1)); }
6540 | enum_val_list
',' Sconst
6541 { $$
= lappend
($1, makeString
($3)); }
6544 /*****************************************************************************
6546 * ALTER TYPE enumtype ADD ...
6548 *****************************************************************************/
6551 ALTER TYPE_P any_name ADD_P VALUE_P opt_if_not_exists Sconst
6553 AlterEnumStmt
*n
= makeNode
(AlterEnumStmt
);
6558 n
->newValNeighbor
= NULL
;
6559 n
->newValIsAfter
= true
;
6560 n
->skipIfNewValExists
= $6;
6563 | ALTER TYPE_P any_name ADD_P VALUE_P opt_if_not_exists Sconst BEFORE Sconst
6565 AlterEnumStmt
*n
= makeNode
(AlterEnumStmt
);
6570 n
->newValNeighbor
= $9;
6571 n
->newValIsAfter
= false
;
6572 n
->skipIfNewValExists
= $6;
6575 | ALTER TYPE_P any_name ADD_P VALUE_P opt_if_not_exists Sconst AFTER Sconst
6577 AlterEnumStmt
*n
= makeNode
(AlterEnumStmt
);
6582 n
->newValNeighbor
= $9;
6583 n
->newValIsAfter
= true
;
6584 n
->skipIfNewValExists
= $6;
6587 | ALTER TYPE_P any_name RENAME VALUE_P Sconst TO Sconst
6589 AlterEnumStmt
*n
= makeNode
(AlterEnumStmt
);
6594 n
->newValNeighbor
= NULL
;
6595 n
->newValIsAfter
= false
;
6596 n
->skipIfNewValExists
= false
;
6599 | ALTER TYPE_P any_name DROP VALUE_P Sconst
6602 * The following problems must be solved before this can be
6605 * - There must be no instance of the target value in
6608 * - The value must not appear in any catalog metadata,
6609 * such as stored view expressions or column defaults.
6611 * - The value must not appear in any non-leaf page of a
6612 * btree (and similar issues with other index types).
6613 * This is problematic because a value could persist
6614 * there long after it's gone from user-visible data.
6616 * - Concurrent sessions must not be able to insert the
6617 * value while the preceding conditions are being checked.
6619 * - Possibly more...
6622 (errcode
(ERRCODE_FEATURE_NOT_SUPPORTED
),
6623 errmsg
("dropping an enum value is not implemented"),
6624 parser_errposition
(@
4)));
6628 opt_if_not_exists: IF_P NOT EXISTS
{ $$
= true
; }
6629 |
/* EMPTY */ { $$
= false
; }
6633 /*****************************************************************************
6636 * CREATE OPERATOR CLASS ...
6637 * CREATE OPERATOR FAMILY ...
6638 * ALTER OPERATOR FAMILY ...
6639 * DROP OPERATOR CLASS ...
6640 * DROP OPERATOR FAMILY ...
6642 *****************************************************************************/
6645 CREATE OPERATOR CLASS any_name opt_default FOR TYPE_P Typename
6646 USING name opt_opfamily AS opclass_item_list
6648 CreateOpClassStmt
*n
= makeNode
(CreateOpClassStmt
);
6650 n
->opclassname
= $4;
6654 n
->opfamilyname
= $11;
6661 opclass_item
{ $$
= list_make1
($1); }
6662 | opclass_item_list
',' opclass_item
{ $$
= lappend
($1, $3); }
6666 OPERATOR Iconst any_operator opclass_purpose
6668 CreateOpClassItem
*n
= makeNode
(CreateOpClassItem
);
6669 ObjectWithArgs
*owa
= makeNode
(ObjectWithArgs
);
6673 n
->itemtype
= OPCLASS_ITEM_OPERATOR
;
6676 n
->order_family
= $4;
6679 | OPERATOR Iconst operator_with_argtypes opclass_purpose
6681 CreateOpClassItem
*n
= makeNode
(CreateOpClassItem
);
6683 n
->itemtype
= OPCLASS_ITEM_OPERATOR
;
6686 n
->order_family
= $4;
6689 | FUNCTION Iconst function_with_argtypes
6691 CreateOpClassItem
*n
= makeNode
(CreateOpClassItem
);
6693 n
->itemtype
= OPCLASS_ITEM_FUNCTION
;
6698 | FUNCTION Iconst
'(' type_list
')' function_with_argtypes
6700 CreateOpClassItem
*n
= makeNode
(CreateOpClassItem
);
6702 n
->itemtype
= OPCLASS_ITEM_FUNCTION
;
6710 CreateOpClassItem
*n
= makeNode
(CreateOpClassItem
);
6712 n
->itemtype
= OPCLASS_ITEM_STORAGETYPE
;
6718 opt_default: DEFAULT
{ $$
= true
; }
6719 |
/*EMPTY*/ { $$
= false
; }
6722 opt_opfamily: FAMILY any_name
{ $$
= $2; }
6723 |
/*EMPTY*/ { $$
= NIL
; }
6726 opclass_purpose: FOR SEARCH
{ $$
= NIL
; }
6727 | FOR ORDER BY any_name
{ $$
= $4; }
6728 |
/*EMPTY*/ { $$
= NIL
; }
6733 CREATE OPERATOR FAMILY any_name USING name
6735 CreateOpFamilyStmt
*n
= makeNode
(CreateOpFamilyStmt
);
6737 n
->opfamilyname
= $4;
6744 ALTER OPERATOR FAMILY any_name USING name ADD_P opclass_item_list
6746 AlterOpFamilyStmt
*n
= makeNode
(AlterOpFamilyStmt
);
6748 n
->opfamilyname
= $4;
6754 | ALTER OPERATOR FAMILY any_name USING name DROP opclass_drop_list
6756 AlterOpFamilyStmt
*n
= makeNode
(AlterOpFamilyStmt
);
6758 n
->opfamilyname
= $4;
6767 opclass_drop
{ $$
= list_make1
($1); }
6768 | opclass_drop_list
',' opclass_drop
{ $$
= lappend
($1, $3); }
6772 OPERATOR Iconst
'(' type_list
')'
6774 CreateOpClassItem
*n
= makeNode
(CreateOpClassItem
);
6776 n
->itemtype
= OPCLASS_ITEM_OPERATOR
;
6781 | FUNCTION Iconst
'(' type_list
')'
6783 CreateOpClassItem
*n
= makeNode
(CreateOpClassItem
);
6785 n
->itemtype
= OPCLASS_ITEM_FUNCTION
;
6794 DROP OPERATOR CLASS any_name USING name opt_drop_behavior
6796 DropStmt
*n
= makeNode
(DropStmt
);
6798 n
->objects
= list_make1
(lcons
(makeString
($6), $4));
6799 n
->removeType
= OBJECT_OPCLASS
;
6801 n
->missing_ok
= false
;
6802 n
->concurrent
= false
;
6805 | DROP OPERATOR CLASS IF_P EXISTS any_name USING name opt_drop_behavior
6807 DropStmt
*n
= makeNode
(DropStmt
);
6809 n
->objects
= list_make1
(lcons
(makeString
($8), $6));
6810 n
->removeType
= OBJECT_OPCLASS
;
6812 n
->missing_ok
= true
;
6813 n
->concurrent
= false
;
6819 DROP OPERATOR FAMILY any_name USING name opt_drop_behavior
6821 DropStmt
*n
= makeNode
(DropStmt
);
6823 n
->objects
= list_make1
(lcons
(makeString
($6), $4));
6824 n
->removeType
= OBJECT_OPFAMILY
;
6826 n
->missing_ok
= false
;
6827 n
->concurrent
= false
;
6830 | DROP OPERATOR FAMILY IF_P EXISTS any_name USING name opt_drop_behavior
6832 DropStmt
*n
= makeNode
(DropStmt
);
6834 n
->objects
= list_make1
(lcons
(makeString
($8), $6));
6835 n
->removeType
= OBJECT_OPFAMILY
;
6837 n
->missing_ok
= true
;
6838 n
->concurrent
= false
;
6844 /*****************************************************************************
6848 * DROP OWNED BY username [, username ...] [ RESTRICT | CASCADE ]
6849 * REASSIGN OWNED BY username [, username ...] TO username
6851 *****************************************************************************/
6853 DROP OWNED BY role_list opt_drop_behavior
6855 DropOwnedStmt
*n
= makeNode
(DropOwnedStmt
);
6864 REASSIGN OWNED BY role_list TO RoleSpec
6866 ReassignOwnedStmt
*n
= makeNode
(ReassignOwnedStmt
);
6874 /*****************************************************************************
6878 * DROP itemtype [ IF EXISTS ] itemname [, itemname ...]
6879 * [ RESTRICT | CASCADE ]
6881 *****************************************************************************/
6883 DropStmt: DROP object_type_any_name IF_P EXISTS any_name_list opt_drop_behavior
6885 DropStmt
*n
= makeNode
(DropStmt
);
6888 n
->missing_ok
= true
;
6891 n
->concurrent
= false
;
6894 | DROP object_type_any_name any_name_list opt_drop_behavior
6896 DropStmt
*n
= makeNode
(DropStmt
);
6899 n
->missing_ok
= false
;
6902 n
->concurrent
= false
;
6905 | DROP drop_type_name IF_P EXISTS name_list opt_drop_behavior
6907 DropStmt
*n
= makeNode
(DropStmt
);
6910 n
->missing_ok
= true
;
6913 n
->concurrent
= false
;
6916 | DROP drop_type_name name_list opt_drop_behavior
6918 DropStmt
*n
= makeNode
(DropStmt
);
6921 n
->missing_ok
= false
;
6924 n
->concurrent
= false
;
6927 | DROP object_type_name_on_any_name name ON any_name opt_drop_behavior
6929 DropStmt
*n
= makeNode
(DropStmt
);
6932 n
->objects
= list_make1
(lappend
($5, makeString
($3)));
6934 n
->missing_ok
= false
;
6935 n
->concurrent
= false
;
6938 | DROP object_type_name_on_any_name IF_P EXISTS name ON any_name opt_drop_behavior
6940 DropStmt
*n
= makeNode
(DropStmt
);
6943 n
->objects
= list_make1
(lappend
($7, makeString
($5)));
6945 n
->missing_ok
= true
;
6946 n
->concurrent
= false
;
6949 | DROP TYPE_P type_name_list opt_drop_behavior
6951 DropStmt
*n
= makeNode
(DropStmt
);
6953 n
->removeType
= OBJECT_TYPE
;
6954 n
->missing_ok
= false
;
6957 n
->concurrent
= false
;
6960 | DROP TYPE_P IF_P EXISTS type_name_list opt_drop_behavior
6962 DropStmt
*n
= makeNode
(DropStmt
);
6964 n
->removeType
= OBJECT_TYPE
;
6965 n
->missing_ok
= true
;
6968 n
->concurrent
= false
;
6971 | DROP DOMAIN_P type_name_list opt_drop_behavior
6973 DropStmt
*n
= makeNode
(DropStmt
);
6975 n
->removeType
= OBJECT_DOMAIN
;
6976 n
->missing_ok
= false
;
6979 n
->concurrent
= false
;
6982 | DROP DOMAIN_P IF_P EXISTS type_name_list opt_drop_behavior
6984 DropStmt
*n
= makeNode
(DropStmt
);
6986 n
->removeType
= OBJECT_DOMAIN
;
6987 n
->missing_ok
= true
;
6990 n
->concurrent
= false
;
6993 | DROP INDEX CONCURRENTLY any_name_list opt_drop_behavior
6995 DropStmt
*n
= makeNode
(DropStmt
);
6997 n
->removeType
= OBJECT_INDEX
;
6998 n
->missing_ok
= false
;
7001 n
->concurrent
= true
;
7004 | DROP INDEX CONCURRENTLY IF_P EXISTS any_name_list opt_drop_behavior
7006 DropStmt
*n
= makeNode
(DropStmt
);
7008 n
->removeType
= OBJECT_INDEX
;
7009 n
->missing_ok
= true
;
7012 n
->concurrent
= true
;
7017 /* object types taking any_name/any_name_list */
7018 object_type_any_name:
7019 TABLE
{ $$
= OBJECT_TABLE
; }
7020 | SEQUENCE
{ $$
= OBJECT_SEQUENCE
; }
7021 | VIEW
{ $$
= OBJECT_VIEW
; }
7022 | MATERIALIZED VIEW
{ $$
= OBJECT_MATVIEW
; }
7023 | INDEX
{ $$
= OBJECT_INDEX
; }
7024 | FOREIGN TABLE
{ $$
= OBJECT_FOREIGN_TABLE
; }
7025 | COLLATION
{ $$
= OBJECT_COLLATION
; }
7026 | CONVERSION_P
{ $$
= OBJECT_CONVERSION
; }
7027 | STATISTICS
{ $$
= OBJECT_STATISTIC_EXT
; }
7028 | TEXT_P SEARCH PARSER
{ $$
= OBJECT_TSPARSER
; }
7029 | TEXT_P SEARCH DICTIONARY
{ $$
= OBJECT_TSDICTIONARY
; }
7030 | TEXT_P SEARCH TEMPLATE
{ $$
= OBJECT_TSTEMPLATE
; }
7031 | TEXT_P SEARCH CONFIGURATION
{ $$
= OBJECT_TSCONFIGURATION
; }
7035 * object types taking name/name_list
7037 * DROP handles some of them separately
7041 drop_type_name
{ $$
= $1; }
7042 | DATABASE
{ $$
= OBJECT_DATABASE
; }
7043 | ROLE
{ $$
= OBJECT_ROLE
; }
7044 | SUBSCRIPTION
{ $$
= OBJECT_SUBSCRIPTION
; }
7045 | TABLESPACE
{ $$
= OBJECT_TABLESPACE
; }
7049 ACCESS METHOD
{ $$
= OBJECT_ACCESS_METHOD
; }
7050 | EVENT TRIGGER
{ $$
= OBJECT_EVENT_TRIGGER
; }
7051 | EXTENSION
{ $$
= OBJECT_EXTENSION
; }
7052 | FOREIGN DATA_P WRAPPER
{ $$
= OBJECT_FDW
; }
7053 | opt_procedural LANGUAGE
{ $$
= OBJECT_LANGUAGE
; }
7054 | PUBLICATION
{ $$
= OBJECT_PUBLICATION
; }
7055 | SCHEMA
{ $$
= OBJECT_SCHEMA
; }
7056 | SERVER
{ $$
= OBJECT_FOREIGN_SERVER
; }
7059 /* object types attached to a table */
7060 object_type_name_on_any_name:
7061 POLICY
{ $$
= OBJECT_POLICY
; }
7062 | RULE
{ $$
= OBJECT_RULE
; }
7063 | TRIGGER
{ $$
= OBJECT_TRIGGER
; }
7067 any_name
{ $$
= list_make1
($1); }
7068 | any_name_list
',' any_name
{ $$
= lappend
($1, $3); }
7071 any_name: ColId
{ $$
= list_make1
(makeString
($1)); }
7072 | ColId attrs
{ $$
= lcons
(makeString
($1), $2); }
7075 attrs: '.' attr_name
7076 { $$
= list_make1
(makeString
($2)); }
7077 | attrs
'.' attr_name
7078 { $$
= lappend
($1, makeString
($3)); }
7082 Typename
{ $$
= list_make1
($1); }
7083 | type_name_list
',' Typename
{ $$
= lappend
($1, $3); }
7086 /*****************************************************************************
7089 * truncate table relname1, relname2, ...
7091 *****************************************************************************/
7094 TRUNCATE opt_table relation_expr_list opt_restart_seqs opt_drop_behavior
7096 TruncateStmt
*n
= makeNode
(TruncateStmt
);
7099 n
->restart_seqs
= $4;
7106 CONTINUE_P IDENTITY_P
{ $$
= false
; }
7107 | RESTART IDENTITY_P
{ $$
= true
; }
7108 |
/* EMPTY */ { $$
= false
; }
7111 /*****************************************************************************
7113 * COMMENT ON <object> IS <text>
7115 *****************************************************************************/
7118 COMMENT ON object_type_any_name any_name IS comment_text
7120 CommentStmt
*n
= makeNode
(CommentStmt
);
7123 n
->object
= (Node
*) $4;
7127 | COMMENT ON COLUMN any_name IS comment_text
7129 CommentStmt
*n
= makeNode
(CommentStmt
);
7131 n
->objtype
= OBJECT_COLUMN
;
7132 n
->object
= (Node
*) $4;
7136 | COMMENT ON object_type_name name IS comment_text
7138 CommentStmt
*n
= makeNode
(CommentStmt
);
7141 n
->object
= (Node
*) makeString
($4);
7145 | COMMENT ON TYPE_P Typename IS comment_text
7147 CommentStmt
*n
= makeNode
(CommentStmt
);
7149 n
->objtype
= OBJECT_TYPE
;
7150 n
->object
= (Node
*) $4;
7154 | COMMENT ON DOMAIN_P Typename IS comment_text
7156 CommentStmt
*n
= makeNode
(CommentStmt
);
7158 n
->objtype
= OBJECT_DOMAIN
;
7159 n
->object
= (Node
*) $4;
7163 | COMMENT ON AGGREGATE aggregate_with_argtypes IS comment_text
7165 CommentStmt
*n
= makeNode
(CommentStmt
);
7167 n
->objtype
= OBJECT_AGGREGATE
;
7168 n
->object
= (Node
*) $4;
7172 | COMMENT ON FUNCTION function_with_argtypes IS comment_text
7174 CommentStmt
*n
= makeNode
(CommentStmt
);
7176 n
->objtype
= OBJECT_FUNCTION
;
7177 n
->object
= (Node
*) $4;
7181 | COMMENT ON OPERATOR operator_with_argtypes IS comment_text
7183 CommentStmt
*n
= makeNode
(CommentStmt
);
7185 n
->objtype
= OBJECT_OPERATOR
;
7186 n
->object
= (Node
*) $4;
7190 | COMMENT ON CONSTRAINT name ON any_name IS comment_text
7192 CommentStmt
*n
= makeNode
(CommentStmt
);
7194 n
->objtype
= OBJECT_TABCONSTRAINT
;
7195 n
->object
= (Node
*) lappend
($6, makeString
($4));
7199 | COMMENT ON CONSTRAINT name ON DOMAIN_P any_name IS comment_text
7201 CommentStmt
*n
= makeNode
(CommentStmt
);
7203 n
->objtype
= OBJECT_DOMCONSTRAINT
;
7205 * should use Typename not any_name in the production, but
7206 * there's a shift/reduce conflict if we do that, so fix it
7209 n
->object
= (Node
*) list_make2
(makeTypeNameFromNameList
($7), makeString
($4));
7213 | COMMENT ON object_type_name_on_any_name name ON any_name IS comment_text
7215 CommentStmt
*n
= makeNode
(CommentStmt
);
7218 n
->object
= (Node
*) lappend
($6, makeString
($4));
7222 | COMMENT ON PROCEDURE function_with_argtypes IS comment_text
7224 CommentStmt
*n
= makeNode
(CommentStmt
);
7226 n
->objtype
= OBJECT_PROCEDURE
;
7227 n
->object
= (Node
*) $4;
7231 | COMMENT ON ROUTINE function_with_argtypes IS comment_text
7233 CommentStmt
*n
= makeNode
(CommentStmt
);
7235 n
->objtype
= OBJECT_ROUTINE
;
7236 n
->object
= (Node
*) $4;
7240 | COMMENT ON TRANSFORM FOR Typename LANGUAGE name IS comment_text
7242 CommentStmt
*n
= makeNode
(CommentStmt
);
7244 n
->objtype
= OBJECT_TRANSFORM
;
7245 n
->object
= (Node
*) list_make2
($5, makeString
($7));
7249 | COMMENT ON OPERATOR CLASS any_name USING name IS comment_text
7251 CommentStmt
*n
= makeNode
(CommentStmt
);
7253 n
->objtype
= OBJECT_OPCLASS
;
7254 n
->object
= (Node
*) lcons
(makeString
($7), $5);
7258 | COMMENT ON OPERATOR FAMILY any_name USING name IS comment_text
7260 CommentStmt
*n
= makeNode
(CommentStmt
);
7262 n
->objtype
= OBJECT_OPFAMILY
;
7263 n
->object
= (Node
*) lcons
(makeString
($7), $5);
7267 | COMMENT ON LARGE_P OBJECT_P NumericOnly IS comment_text
7269 CommentStmt
*n
= makeNode
(CommentStmt
);
7271 n
->objtype
= OBJECT_LARGEOBJECT
;
7272 n
->object
= (Node
*) $5;
7276 | COMMENT ON CAST
'(' Typename AS Typename
')' IS comment_text
7278 CommentStmt
*n
= makeNode
(CommentStmt
);
7280 n
->objtype
= OBJECT_CAST
;
7281 n
->object
= (Node
*) list_make2
($5, $7);
7289 | NULL_P
{ $$
= NULL
; }
7293 /*****************************************************************************
7295 * SECURITY LABEL [FOR <provider>] ON <object> IS <label>
7297 * As with COMMENT ON, <object> can refer to various types of database
7298 * objects (e.g. TABLE, COLUMN, etc.).
7300 *****************************************************************************/
7303 SECURITY LABEL opt_provider ON object_type_any_name any_name
7306 SecLabelStmt
*n
= makeNode
(SecLabelStmt
);
7310 n
->object
= (Node
*) $6;
7314 | SECURITY LABEL opt_provider ON COLUMN any_name
7317 SecLabelStmt
*n
= makeNode
(SecLabelStmt
);
7320 n
->objtype
= OBJECT_COLUMN
;
7321 n
->object
= (Node
*) $6;
7325 | SECURITY LABEL opt_provider ON object_type_name name
7328 SecLabelStmt
*n
= makeNode
(SecLabelStmt
);
7332 n
->object
= (Node
*) makeString
($6);
7336 | SECURITY LABEL opt_provider ON TYPE_P Typename
7339 SecLabelStmt
*n
= makeNode
(SecLabelStmt
);
7342 n
->objtype
= OBJECT_TYPE
;
7343 n
->object
= (Node
*) $6;
7347 | SECURITY LABEL opt_provider ON DOMAIN_P Typename
7350 SecLabelStmt
*n
= makeNode
(SecLabelStmt
);
7353 n
->objtype
= OBJECT_DOMAIN
;
7354 n
->object
= (Node
*) $6;
7358 | SECURITY LABEL opt_provider ON AGGREGATE aggregate_with_argtypes
7361 SecLabelStmt
*n
= makeNode
(SecLabelStmt
);
7364 n
->objtype
= OBJECT_AGGREGATE
;
7365 n
->object
= (Node
*) $6;
7369 | SECURITY LABEL opt_provider ON FUNCTION function_with_argtypes
7372 SecLabelStmt
*n
= makeNode
(SecLabelStmt
);
7375 n
->objtype
= OBJECT_FUNCTION
;
7376 n
->object
= (Node
*) $6;
7380 | SECURITY LABEL opt_provider ON LARGE_P OBJECT_P NumericOnly
7383 SecLabelStmt
*n
= makeNode
(SecLabelStmt
);
7386 n
->objtype
= OBJECT_LARGEOBJECT
;
7387 n
->object
= (Node
*) $7;
7391 | SECURITY LABEL opt_provider ON PROCEDURE function_with_argtypes
7394 SecLabelStmt
*n
= makeNode
(SecLabelStmt
);
7397 n
->objtype
= OBJECT_PROCEDURE
;
7398 n
->object
= (Node
*) $6;
7402 | SECURITY LABEL opt_provider ON ROUTINE function_with_argtypes
7405 SecLabelStmt
*n
= makeNode
(SecLabelStmt
);
7408 n
->objtype
= OBJECT_ROUTINE
;
7409 n
->object
= (Node
*) $6;
7415 opt_provider: FOR NonReservedWord_or_Sconst
{ $$
= $2; }
7416 |
/* EMPTY */ { $$
= NULL
; }
7419 security_label: Sconst
{ $$
= $1; }
7420 | NULL_P
{ $$
= NULL
; }
7423 /*****************************************************************************
7428 *****************************************************************************/
7430 FetchStmt: FETCH fetch_args
7432 FetchStmt
*n
= (FetchStmt
*) $2;
7439 FetchStmt
*n
= (FetchStmt
*) $2;
7446 fetch_args: cursor_name
7448 FetchStmt
*n
= makeNode
(FetchStmt
);
7451 n
->direction
= FETCH_FORWARD
;
7455 | from_in cursor_name
7457 FetchStmt
*n
= makeNode
(FetchStmt
);
7460 n
->direction
= FETCH_FORWARD
;
7464 | NEXT opt_from_in cursor_name
7466 FetchStmt
*n
= makeNode
(FetchStmt
);
7469 n
->direction
= FETCH_FORWARD
;
7473 | PRIOR opt_from_in cursor_name
7475 FetchStmt
*n
= makeNode
(FetchStmt
);
7478 n
->direction
= FETCH_BACKWARD
;
7482 | FIRST_P opt_from_in cursor_name
7484 FetchStmt
*n
= makeNode
(FetchStmt
);
7487 n
->direction
= FETCH_ABSOLUTE
;
7491 | LAST_P opt_from_in cursor_name
7493 FetchStmt
*n
= makeNode
(FetchStmt
);
7496 n
->direction
= FETCH_ABSOLUTE
;
7500 | ABSOLUTE_P SignedIconst opt_from_in cursor_name
7502 FetchStmt
*n
= makeNode
(FetchStmt
);
7505 n
->direction
= FETCH_ABSOLUTE
;
7509 | RELATIVE_P SignedIconst opt_from_in cursor_name
7511 FetchStmt
*n
= makeNode
(FetchStmt
);
7514 n
->direction
= FETCH_RELATIVE
;
7518 | SignedIconst opt_from_in cursor_name
7520 FetchStmt
*n
= makeNode
(FetchStmt
);
7523 n
->direction
= FETCH_FORWARD
;
7527 | ALL opt_from_in cursor_name
7529 FetchStmt
*n
= makeNode
(FetchStmt
);
7532 n
->direction
= FETCH_FORWARD
;
7533 n
->howMany
= FETCH_ALL
;
7536 | FORWARD opt_from_in cursor_name
7538 FetchStmt
*n
= makeNode
(FetchStmt
);
7541 n
->direction
= FETCH_FORWARD
;
7545 | FORWARD SignedIconst opt_from_in cursor_name
7547 FetchStmt
*n
= makeNode
(FetchStmt
);
7550 n
->direction
= FETCH_FORWARD
;
7554 | FORWARD ALL opt_from_in cursor_name
7556 FetchStmt
*n
= makeNode
(FetchStmt
);
7559 n
->direction
= FETCH_FORWARD
;
7560 n
->howMany
= FETCH_ALL
;
7563 | BACKWARD opt_from_in cursor_name
7565 FetchStmt
*n
= makeNode
(FetchStmt
);
7568 n
->direction
= FETCH_BACKWARD
;
7572 | BACKWARD SignedIconst opt_from_in cursor_name
7574 FetchStmt
*n
= makeNode
(FetchStmt
);
7577 n
->direction
= FETCH_BACKWARD
;
7581 | BACKWARD ALL opt_from_in cursor_name
7583 FetchStmt
*n
= makeNode
(FetchStmt
);
7586 n
->direction
= FETCH_BACKWARD
;
7587 n
->howMany
= FETCH_ALL
;
7596 opt_from_in: from_in
7601 /*****************************************************************************
7603 * GRANT and REVOKE statements
7605 *****************************************************************************/
7607 GrantStmt: GRANT privileges ON privilege_target TO grantee_list
7608 opt_grant_grant_option opt_granted_by
7610 GrantStmt
*n
= makeNode
(GrantStmt
);
7614 n
->targtype
= ($4)->targtype
;
7615 n
->objtype
= ($4)->objtype
;
7616 n
->objects
= ($4)->objs
;
7618 n
->grant_option
= $7;
7625 REVOKE privileges ON privilege_target
7626 FROM grantee_list opt_granted_by opt_drop_behavior
7628 GrantStmt
*n
= makeNode
(GrantStmt
);
7630 n
->is_grant
= false
;
7631 n
->grant_option
= false
;
7633 n
->targtype
= ($4)->targtype
;
7634 n
->objtype
= ($4)->objtype
;
7635 n
->objects
= ($4)->objs
;
7641 | REVOKE GRANT OPTION FOR privileges ON privilege_target
7642 FROM grantee_list opt_granted_by opt_drop_behavior
7644 GrantStmt
*n
= makeNode
(GrantStmt
);
7646 n
->is_grant
= false
;
7647 n
->grant_option
= true
;
7649 n
->targtype
= ($7)->targtype
;
7650 n
->objtype
= ($7)->objtype
;
7651 n
->objects
= ($7)->objs
;
7661 * Privilege names are represented as strings; the validity of the privilege
7662 * names gets checked at execution. This is a bit annoying but we have little
7663 * choice because of the syntactic conflict with lists of role names in
7664 * GRANT/REVOKE. What's more, we have to call out in the "privilege"
7665 * production any reserved keywords that need to be usable as privilege names.
7668 /* either ALL [PRIVILEGES] or a list of individual privileges */
7669 privileges: privilege_list
7675 | ALL
'(' columnList
')'
7677 AccessPriv
*n
= makeNode
(AccessPriv
);
7679 n
->priv_name
= NULL
;
7683 | ALL PRIVILEGES
'(' columnList
')'
7685 AccessPriv
*n
= makeNode
(AccessPriv
);
7687 n
->priv_name
= NULL
;
7693 privilege_list: privilege
{ $$
= list_make1
($1); }
7694 | privilege_list
',' privilege
{ $$
= lappend
($1, $3); }
7697 privilege: SELECT opt_column_list
7699 AccessPriv
*n
= makeNode
(AccessPriv
);
7701 n
->priv_name
= pstrdup
($1);
7705 | REFERENCES opt_column_list
7707 AccessPriv
*n
= makeNode
(AccessPriv
);
7709 n
->priv_name
= pstrdup
($1);
7713 | CREATE opt_column_list
7715 AccessPriv
*n
= makeNode
(AccessPriv
);
7717 n
->priv_name
= pstrdup
($1);
7723 AccessPriv
*n
= makeNode
(AccessPriv
);
7724 n
->priv_name
= pstrdup
("alter system");
7728 | ColId opt_column_list
7730 AccessPriv
*n
= makeNode
(AccessPriv
);
7738 parameter_name_list:
7741 $$
= list_make1
(makeString
($1));
7743 | parameter_name_list
',' parameter_name
7745 $$
= lappend
($1, makeString
($3));
7754 | parameter_name
'.' ColId
7756 $$
= psprintf
("%s.%s", $1, $3);
7761 /* Don't bother trying to fold the first two rules into one using
7762 * opt_table. You're going to get conflicts.
7767 PrivTarget
*n
= (PrivTarget
*) palloc
(sizeof
(PrivTarget
));
7769 n
->targtype
= ACL_TARGET_OBJECT
;
7770 n
->objtype
= OBJECT_TABLE
;
7774 | TABLE qualified_name_list
7776 PrivTarget
*n
= (PrivTarget
*) palloc
(sizeof
(PrivTarget
));
7778 n
->targtype
= ACL_TARGET_OBJECT
;
7779 n
->objtype
= OBJECT_TABLE
;
7783 | SEQUENCE qualified_name_list
7785 PrivTarget
*n
= (PrivTarget
*) palloc
(sizeof
(PrivTarget
));
7787 n
->targtype
= ACL_TARGET_OBJECT
;
7788 n
->objtype
= OBJECT_SEQUENCE
;
7792 | FOREIGN DATA_P WRAPPER name_list
7794 PrivTarget
*n
= (PrivTarget
*) palloc
(sizeof
(PrivTarget
));
7796 n
->targtype
= ACL_TARGET_OBJECT
;
7797 n
->objtype
= OBJECT_FDW
;
7801 | FOREIGN SERVER name_list
7803 PrivTarget
*n
= (PrivTarget
*) palloc
(sizeof
(PrivTarget
));
7805 n
->targtype
= ACL_TARGET_OBJECT
;
7806 n
->objtype
= OBJECT_FOREIGN_SERVER
;
7810 | FUNCTION function_with_argtypes_list
7812 PrivTarget
*n
= (PrivTarget
*) palloc
(sizeof
(PrivTarget
));
7814 n
->targtype
= ACL_TARGET_OBJECT
;
7815 n
->objtype
= OBJECT_FUNCTION
;
7819 | PROCEDURE function_with_argtypes_list
7821 PrivTarget
*n
= (PrivTarget
*) palloc
(sizeof
(PrivTarget
));
7823 n
->targtype
= ACL_TARGET_OBJECT
;
7824 n
->objtype
= OBJECT_PROCEDURE
;
7828 | ROUTINE function_with_argtypes_list
7830 PrivTarget
*n
= (PrivTarget
*) palloc
(sizeof
(PrivTarget
));
7832 n
->targtype
= ACL_TARGET_OBJECT
;
7833 n
->objtype
= OBJECT_ROUTINE
;
7837 | DATABASE name_list
7839 PrivTarget
*n
= (PrivTarget
*) palloc
(sizeof
(PrivTarget
));
7841 n
->targtype
= ACL_TARGET_OBJECT
;
7842 n
->objtype
= OBJECT_DATABASE
;
7846 | DOMAIN_P any_name_list
7848 PrivTarget
*n
= (PrivTarget
*) palloc
(sizeof
(PrivTarget
));
7850 n
->targtype
= ACL_TARGET_OBJECT
;
7851 n
->objtype
= OBJECT_DOMAIN
;
7855 | LANGUAGE name_list
7857 PrivTarget
*n
= (PrivTarget
*) palloc
(sizeof
(PrivTarget
));
7859 n
->targtype
= ACL_TARGET_OBJECT
;
7860 n
->objtype
= OBJECT_LANGUAGE
;
7864 | LARGE_P OBJECT_P NumericOnly_list
7866 PrivTarget
*n
= (PrivTarget
*) palloc
(sizeof
(PrivTarget
));
7868 n
->targtype
= ACL_TARGET_OBJECT
;
7869 n
->objtype
= OBJECT_LARGEOBJECT
;
7873 | PARAMETER parameter_name_list
7875 PrivTarget
*n
= (PrivTarget
*) palloc
(sizeof
(PrivTarget
));
7876 n
->targtype
= ACL_TARGET_OBJECT
;
7877 n
->objtype
= OBJECT_PARAMETER_ACL
;
7883 PrivTarget
*n
= (PrivTarget
*) palloc
(sizeof
(PrivTarget
));
7885 n
->targtype
= ACL_TARGET_OBJECT
;
7886 n
->objtype
= OBJECT_SCHEMA
;
7890 | TABLESPACE name_list
7892 PrivTarget
*n
= (PrivTarget
*) palloc
(sizeof
(PrivTarget
));
7894 n
->targtype
= ACL_TARGET_OBJECT
;
7895 n
->objtype
= OBJECT_TABLESPACE
;
7899 | TYPE_P any_name_list
7901 PrivTarget
*n
= (PrivTarget
*) palloc
(sizeof
(PrivTarget
));
7903 n
->targtype
= ACL_TARGET_OBJECT
;
7904 n
->objtype
= OBJECT_TYPE
;
7908 | ALL TABLES IN_P SCHEMA name_list
7910 PrivTarget
*n
= (PrivTarget
*) palloc
(sizeof
(PrivTarget
));
7912 n
->targtype
= ACL_TARGET_ALL_IN_SCHEMA
;
7913 n
->objtype
= OBJECT_TABLE
;
7917 | ALL SEQUENCES IN_P SCHEMA name_list
7919 PrivTarget
*n
= (PrivTarget
*) palloc
(sizeof
(PrivTarget
));
7921 n
->targtype
= ACL_TARGET_ALL_IN_SCHEMA
;
7922 n
->objtype
= OBJECT_SEQUENCE
;
7926 | ALL FUNCTIONS IN_P SCHEMA name_list
7928 PrivTarget
*n
= (PrivTarget
*) palloc
(sizeof
(PrivTarget
));
7930 n
->targtype
= ACL_TARGET_ALL_IN_SCHEMA
;
7931 n
->objtype
= OBJECT_FUNCTION
;
7935 | ALL PROCEDURES IN_P SCHEMA name_list
7937 PrivTarget
*n
= (PrivTarget
*) palloc
(sizeof
(PrivTarget
));
7939 n
->targtype
= ACL_TARGET_ALL_IN_SCHEMA
;
7940 n
->objtype
= OBJECT_PROCEDURE
;
7944 | ALL ROUTINES IN_P SCHEMA name_list
7946 PrivTarget
*n
= (PrivTarget
*) palloc
(sizeof
(PrivTarget
));
7948 n
->targtype
= ACL_TARGET_ALL_IN_SCHEMA
;
7949 n
->objtype
= OBJECT_ROUTINE
;
7957 grantee
{ $$
= list_make1
($1); }
7958 | grantee_list
',' grantee
{ $$
= lappend
($1, $3); }
7962 RoleSpec
{ $$
= $1; }
7963 | GROUP_P RoleSpec
{ $$
= $2; }
7967 opt_grant_grant_option:
7968 WITH GRANT OPTION
{ $$
= true
; }
7969 |
/*EMPTY*/ { $$
= false
; }
7972 /*****************************************************************************
7974 * GRANT and REVOKE ROLE statements
7976 *****************************************************************************/
7979 GRANT privilege_list TO role_list opt_granted_by
7981 GrantRoleStmt
*n
= makeNode
(GrantRoleStmt
);
7984 n
->granted_roles
= $2;
7985 n
->grantee_roles
= $4;
7990 | GRANT privilege_list TO role_list WITH grant_role_opt_list opt_granted_by
7992 GrantRoleStmt
*n
= makeNode
(GrantRoleStmt
);
7995 n
->granted_roles
= $2;
7996 n
->grantee_roles
= $4;
8004 REVOKE privilege_list FROM role_list opt_granted_by opt_drop_behavior
8006 GrantRoleStmt
*n
= makeNode
(GrantRoleStmt
);
8008 n
->is_grant
= false
;
8010 n
->granted_roles
= $2;
8011 n
->grantee_roles
= $4;
8016 | REVOKE ColId OPTION FOR privilege_list FROM role_list opt_granted_by opt_drop_behavior
8018 GrantRoleStmt
*n
= makeNode
(GrantRoleStmt
);
8021 opt
= makeDefElem
(pstrdup
($2),
8022 (Node
*) makeBoolean
(false
), @
2);
8023 n
->is_grant
= false
;
8024 n
->opt
= list_make1
(opt
);
8025 n
->granted_roles
= $5;
8026 n
->grantee_roles
= $7;
8033 grant_role_opt_list:
8034 grant_role_opt_list
',' grant_role_opt
{ $$
= lappend
($1, $3); }
8035 | grant_role_opt
{ $$
= list_make1
($1); }
8039 ColLabel grant_role_opt_value
8041 $$
= makeDefElem
(pstrdup
($1), $2, @
1);
8045 grant_role_opt_value:
8046 OPTION
{ $$
= (Node
*) makeBoolean
(true
); }
8047 | TRUE_P
{ $$
= (Node
*) makeBoolean
(true
); }
8048 | FALSE_P
{ $$
= (Node
*) makeBoolean
(false
); }
8051 opt_granted_by: GRANTED BY RoleSpec
{ $$
= $3; }
8052 |
/*EMPTY*/ { $$
= NULL
; }
8055 /*****************************************************************************
8057 * ALTER DEFAULT PRIVILEGES statement
8059 *****************************************************************************/
8061 AlterDefaultPrivilegesStmt:
8062 ALTER DEFAULT PRIVILEGES DefACLOptionList DefACLAction
8064 AlterDefaultPrivilegesStmt
*n
= makeNode
(AlterDefaultPrivilegesStmt
);
8067 n
->action
= (GrantStmt
*) $5;
8073 DefACLOptionList DefACLOption
{ $$
= lappend
($1, $2); }
8074 |
/* EMPTY */ { $$
= NIL
; }
8078 IN_P SCHEMA name_list
8080 $$
= makeDefElem
("schemas", (Node
*) $3, @
1);
8082 | FOR ROLE role_list
8084 $$
= makeDefElem
("roles", (Node
*) $3, @
1);
8086 | FOR USER role_list
8088 $$
= makeDefElem
("roles", (Node
*) $3, @
1);
8093 * This should match GRANT/REVOKE, except that individual target objects
8094 * are not mentioned and we only allow a subset of object types.
8097 GRANT privileges ON defacl_privilege_target TO grantee_list
8098 opt_grant_grant_option
8100 GrantStmt
*n
= makeNode
(GrantStmt
);
8104 n
->targtype
= ACL_TARGET_DEFAULTS
;
8108 n
->grant_option
= $7;
8111 | REVOKE privileges ON defacl_privilege_target
8112 FROM grantee_list opt_drop_behavior
8114 GrantStmt
*n
= makeNode
(GrantStmt
);
8116 n
->is_grant
= false
;
8117 n
->grant_option
= false
;
8119 n
->targtype
= ACL_TARGET_DEFAULTS
;
8126 | REVOKE GRANT OPTION FOR privileges ON defacl_privilege_target
8127 FROM grantee_list opt_drop_behavior
8129 GrantStmt
*n
= makeNode
(GrantStmt
);
8131 n
->is_grant
= false
;
8132 n
->grant_option
= true
;
8134 n
->targtype
= ACL_TARGET_DEFAULTS
;
8143 defacl_privilege_target:
8144 TABLES
{ $$
= OBJECT_TABLE
; }
8145 | FUNCTIONS
{ $$
= OBJECT_FUNCTION
; }
8146 | ROUTINES
{ $$
= OBJECT_FUNCTION
; }
8147 | SEQUENCES
{ $$
= OBJECT_SEQUENCE
; }
8148 | TYPES_P
{ $$
= OBJECT_TYPE
; }
8149 | SCHEMAS
{ $$
= OBJECT_SCHEMA
; }
8153 /*****************************************************************************
8155 * QUERY: CREATE INDEX
8157 * Note: we cannot put TABLESPACE clause after WHERE clause unless we are
8158 * willing to make TABLESPACE a fully reserved word.
8159 *****************************************************************************/
8161 IndexStmt: CREATE opt_unique INDEX opt_concurrently opt_single_name
8162 ON relation_expr access_method_clause
'(' index_params
')'
8163 opt_include opt_unique_null_treatment opt_reloptions OptTableSpace where_clause
8165 IndexStmt
*n
= makeNode
(IndexStmt
);
8171 n
->accessMethod
= $8;
8172 n
->indexParams
= $10;
8173 n
->indexIncludingParams
= $12;
8174 n
->nulls_not_distinct
= !$13;
8176 n
->tableSpace
= $15;
8177 n
->whereClause
= $16;
8178 n
->excludeOpNames
= NIL
;
8179 n
->idxcomment
= NULL
;
8180 n
->indexOid
= InvalidOid
;
8181 n
->oldNumber
= InvalidRelFileNumber
;
8182 n
->oldCreateSubid
= InvalidSubTransactionId
;
8183 n
->oldFirstRelfilelocatorSubid
= InvalidSubTransactionId
;
8185 n
->isconstraint
= false
;
8186 n
->deferrable
= false
;
8187 n
->initdeferred
= false
;
8188 n
->transformed
= false
;
8189 n
->if_not_exists
= false
;
8190 n
->reset_default_tblspc
= false
;
8193 | CREATE opt_unique INDEX opt_concurrently IF_P NOT EXISTS name
8194 ON relation_expr access_method_clause
'(' index_params
')'
8195 opt_include opt_unique_null_treatment opt_reloptions OptTableSpace where_clause
8197 IndexStmt
*n
= makeNode
(IndexStmt
);
8203 n
->accessMethod
= $11;
8204 n
->indexParams
= $13;
8205 n
->indexIncludingParams
= $15;
8206 n
->nulls_not_distinct
= !$16;
8208 n
->tableSpace
= $18;
8209 n
->whereClause
= $19;
8210 n
->excludeOpNames
= NIL
;
8211 n
->idxcomment
= NULL
;
8212 n
->indexOid
= InvalidOid
;
8213 n
->oldNumber
= InvalidRelFileNumber
;
8214 n
->oldCreateSubid
= InvalidSubTransactionId
;
8215 n
->oldFirstRelfilelocatorSubid
= InvalidSubTransactionId
;
8217 n
->isconstraint
= false
;
8218 n
->deferrable
= false
;
8219 n
->initdeferred
= false
;
8220 n
->transformed
= false
;
8221 n
->if_not_exists
= true
;
8222 n
->reset_default_tblspc
= false
;
8228 UNIQUE
{ $$
= true
; }
8229 |
/*EMPTY*/ { $$
= false
; }
8232 access_method_clause:
8233 USING name
{ $$
= $2; }
8234 |
/*EMPTY*/ { $$
= DEFAULT_INDEX_TYPE
; }
8237 index_params: index_elem
{ $$
= list_make1
($1); }
8238 | index_params
',' index_elem
{ $$
= lappend
($1, $3); }
8243 opt_collate opt_qualified_name opt_asc_desc opt_nulls_order
8245 $$
= makeNode
(IndexElem
);
8248 $$
->indexcolname
= NULL
;
8251 $$
->opclassopts
= NIL
;
8253 $$
->nulls_ordering
= $4;
8255 | opt_collate any_name reloptions opt_asc_desc opt_nulls_order
8257 $$
= makeNode
(IndexElem
);
8260 $$
->indexcolname
= NULL
;
8263 $$
->opclassopts
= $3;
8265 $$
->nulls_ordering
= $5;
8270 * Index attributes can be either simple column references, or arbitrary
8271 * expressions in parens. For backwards-compatibility reasons, we allow
8272 * an expression that's just a function call to be written without parens.
8274 index_elem: ColId index_elem_options
8279 | func_expr_windowless index_elem_options
8284 |
'(' a_expr
')' index_elem_options
8291 opt_include: INCLUDE
'(' index_including_params
')' { $$
= $3; }
8292 |
/* EMPTY */ { $$
= NIL
; }
8295 index_including_params: index_elem
{ $$
= list_make1
($1); }
8296 | index_including_params
',' index_elem
{ $$
= lappend
($1, $3); }
8299 opt_collate: COLLATE any_name
{ $$
= $2; }
8300 |
/*EMPTY*/ { $$
= NIL
; }
8304 opt_asc_desc: ASC
{ $$
= SORTBY_ASC
; }
8305 | DESC
{ $$
= SORTBY_DESC
; }
8306 |
/*EMPTY*/ { $$
= SORTBY_DEFAULT
; }
8309 opt_nulls_order: NULLS_LA FIRST_P
{ $$
= SORTBY_NULLS_FIRST
; }
8310 | NULLS_LA LAST_P
{ $$
= SORTBY_NULLS_LAST
; }
8311 |
/*EMPTY*/ { $$
= SORTBY_NULLS_DEFAULT
; }
8315 /*****************************************************************************
8318 * create [or replace] function <fname>
8319 * [(<type-1> { , <type-n>})]
8321 * as <filename or code in language as appropriate>
8322 * language <lang> [with parameters]
8324 *****************************************************************************/
8327 CREATE opt_or_replace FUNCTION func_name func_args_with_defaults
8328 RETURNS func_return opt_createfunc_opt_list opt_routine_body
8330 CreateFunctionStmt
*n
= makeNode
(CreateFunctionStmt
);
8332 n
->is_procedure
= false
;
8341 | CREATE opt_or_replace FUNCTION func_name func_args_with_defaults
8342 RETURNS TABLE
'(' table_func_column_list
')' opt_createfunc_opt_list opt_routine_body
8344 CreateFunctionStmt
*n
= makeNode
(CreateFunctionStmt
);
8346 n
->is_procedure
= false
;
8349 n
->parameters
= mergeTableFuncParameters
($5, $9, yyscanner
);
8350 n
->returnType
= TableFuncTypeName
($9);
8351 n
->returnType
->location
= @
7;
8356 | CREATE opt_or_replace FUNCTION func_name func_args_with_defaults
8357 opt_createfunc_opt_list opt_routine_body
8359 CreateFunctionStmt
*n
= makeNode
(CreateFunctionStmt
);
8361 n
->is_procedure
= false
;
8365 n
->returnType
= NULL
;
8370 | CREATE opt_or_replace PROCEDURE func_name func_args_with_defaults
8371 opt_createfunc_opt_list opt_routine_body
8373 CreateFunctionStmt
*n
= makeNode
(CreateFunctionStmt
);
8375 n
->is_procedure
= true
;
8379 n
->returnType
= NULL
;
8387 OR REPLACE
{ $$
= true
; }
8388 |
/*EMPTY*/ { $$
= false
; }
8391 func_args: '(' func_args_list
')' { $$
= $2; }
8392 |
'(' ')' { $$
= NIL
; }
8396 func_arg
{ $$
= list_make1
($1); }
8397 | func_args_list
',' func_arg
{ $$
= lappend
($1, $3); }
8400 function_with_argtypes_list:
8401 function_with_argtypes
{ $$
= list_make1
($1); }
8402 | function_with_argtypes_list
',' function_with_argtypes
8403 { $$
= lappend
($1, $3); }
8406 function_with_argtypes:
8409 ObjectWithArgs
*n
= makeNode
(ObjectWithArgs
);
8412 n
->objargs
= extractArgTypes
($2);
8413 n
->objfuncargs
= $2;
8417 * Because of reduce/reduce conflicts, we can't use func_name
8418 * below, but we can write it out the long way, which actually
8419 * allows more cases.
8421 | type_func_name_keyword
8423 ObjectWithArgs
*n
= makeNode
(ObjectWithArgs
);
8425 n
->objname
= list_make1
(makeString
(pstrdup
($1)));
8426 n
->args_unspecified
= true
;
8431 ObjectWithArgs
*n
= makeNode
(ObjectWithArgs
);
8433 n
->objname
= list_make1
(makeString
($1));
8434 n
->args_unspecified
= true
;
8439 ObjectWithArgs
*n
= makeNode
(ObjectWithArgs
);
8441 n
->objname
= check_func_name
(lcons
(makeString
($1), $2),
8443 n
->args_unspecified
= true
;
8449 * func_args_with_defaults is separate because we only want to accept
8450 * defaults in CREATE FUNCTION, not in ALTER etc.
8452 func_args_with_defaults:
8453 '(' func_args_with_defaults_list
')' { $$
= $2; }
8454 |
'(' ')' { $$
= NIL
; }
8457 func_args_with_defaults_list:
8458 func_arg_with_default
{ $$
= list_make1
($1); }
8459 | func_args_with_defaults_list
',' func_arg_with_default
8460 { $$
= lappend
($1, $3); }
8464 * The style with arg_class first is SQL99 standard, but Oracle puts
8465 * param_name first; accept both since it's likely people will try both
8466 * anyway. Don't bother trying to save productions by letting arg_class
8467 * have an empty alternative ... you'll get shift/reduce conflicts.
8469 * We can catch over-specified arguments here if we want to,
8470 * but for now better to silently swallow typmod, etc.
8471 * - thomas 2000-03-22
8474 arg_class param_name func_type
8476 FunctionParameter
*n
= makeNode
(FunctionParameter
);
8485 | param_name arg_class func_type
8487 FunctionParameter
*n
= makeNode
(FunctionParameter
);
8496 | param_name func_type
8498 FunctionParameter
*n
= makeNode
(FunctionParameter
);
8502 n
->mode
= FUNC_PARAM_DEFAULT
;
8507 | arg_class func_type
8509 FunctionParameter
*n
= makeNode
(FunctionParameter
);
8520 FunctionParameter
*n
= makeNode
(FunctionParameter
);
8524 n
->mode
= FUNC_PARAM_DEFAULT
;
8531 /* INOUT is SQL99 standard, IN OUT is for Oracle compatibility */
8532 arg_class: IN_P
{ $$
= FUNC_PARAM_IN
; }
8533 | OUT_P
{ $$
= FUNC_PARAM_OUT
; }
8534 | INOUT
{ $$
= FUNC_PARAM_INOUT
; }
8535 | IN_P OUT_P
{ $$
= FUNC_PARAM_INOUT
; }
8536 | VARIADIC
{ $$
= FUNC_PARAM_VARIADIC
; }
8540 * Ideally param_name should be ColId, but that causes too many conflicts.
8542 param_name: type_function_name
8548 /* We can catch over-specified results here if we want to,
8549 * but for now better to silently swallow typmod, etc.
8550 * - thomas 2000-03-22
8557 * We would like to make the %TYPE productions here be ColId attrs etc,
8558 * but that causes reduce/reduce conflicts. type_function_name
8559 * is next best choice.
8561 func_type: Typename
{ $$
= $1; }
8562 | type_function_name attrs
'%' TYPE_P
8564 $$
= makeTypeNameFromNameList
(lcons
(makeString
($1), $2));
8565 $$
->pct_type
= true
;
8568 | SETOF type_function_name attrs
'%' TYPE_P
8570 $$
= makeTypeNameFromNameList
(lcons
(makeString
($2), $3));
8571 $$
->pct_type
= true
;
8577 func_arg_with_default:
8582 | func_arg DEFAULT a_expr
8587 | func_arg
'=' a_expr
8594 /* Aggregate args can be most things that function args can be */
8597 if
(!($1->mode
== FUNC_PARAM_DEFAULT ||
8598 $1->mode
== FUNC_PARAM_IN ||
8599 $1->mode
== FUNC_PARAM_VARIADIC
))
8601 (errcode
(ERRCODE_FEATURE_NOT_SUPPORTED
),
8602 errmsg
("aggregates cannot have output arguments"),
8603 parser_errposition
(@
1)));
8609 * The SQL standard offers no guidance on how to declare aggregate argument
8610 * lists, since it doesn't have CREATE AGGREGATE etc. We accept these cases:
8612 * (*) - normal agg with no args
8613 * (aggr_arg,...) - normal agg with args
8614 * (ORDER BY aggr_arg,...) - ordered-set agg with no direct args
8615 * (aggr_arg,... ORDER BY aggr_arg,...) - ordered-set agg with direct args
8617 * The zero-argument case is spelled with '*' for consistency with COUNT(*).
8619 * An additional restriction is that if the direct-args list ends in a
8620 * VARIADIC item, the ordered-args list must contain exactly one item that
8621 * is also VARIADIC with the same type. This allows us to collapse the two
8622 * VARIADIC items into one, which is necessary to represent the aggregate in
8623 * pg_proc. We check this at the grammar stage so that we can return a list
8624 * in which the second VARIADIC item is already discarded, avoiding extra work
8625 * in cases such as DROP AGGREGATE.
8627 * The return value of this production is a two-element list, in which the
8628 * first item is a sublist of FunctionParameter nodes (with any duplicate
8629 * VARIADIC item already dropped, as per above) and the second is an Integer
8630 * node, containing -1 if there was no ORDER BY and otherwise the number
8631 * of argument declarations before the ORDER BY. (If this number is equal
8632 * to the first sublist's length, then we dropped a duplicate VARIADIC item.)
8633 * This representation is passed as-is to CREATE AGGREGATE; for operations
8634 * on existing aggregates, we can just apply extractArgTypes to the first
8637 aggr_args: '(' '*' ')'
8639 $$
= list_make2
(NIL
, makeInteger
(-1));
8641 |
'(' aggr_args_list
')'
8643 $$
= list_make2
($2, makeInteger
(-1));
8645 |
'(' ORDER BY aggr_args_list
')'
8647 $$
= list_make2
($4, makeInteger
(0));
8649 |
'(' aggr_args_list ORDER BY aggr_args_list
')'
8651 /* this is the only case requiring consistency checking */
8652 $$
= makeOrderedSetArgs
($2, $5, yyscanner
);
8657 aggr_arg
{ $$
= list_make1
($1); }
8658 | aggr_args_list
',' aggr_arg
{ $$
= lappend
($1, $3); }
8661 aggregate_with_argtypes:
8664 ObjectWithArgs
*n
= makeNode
(ObjectWithArgs
);
8667 n
->objargs
= extractAggrArgTypes
($2);
8668 n
->objfuncargs
= (List
*) linitial
($2);
8673 aggregate_with_argtypes_list:
8674 aggregate_with_argtypes
{ $$
= list_make1
($1); }
8675 | aggregate_with_argtypes_list
',' aggregate_with_argtypes
8676 { $$
= lappend
($1, $3); }
8679 opt_createfunc_opt_list:
8681 |
/*EMPTY*/ { $$
= NIL
; }
8684 createfunc_opt_list:
8685 /* Must be at least one to prevent conflict */
8686 createfunc_opt_item
{ $$
= list_make1
($1); }
8687 | createfunc_opt_list createfunc_opt_item
{ $$
= lappend
($1, $2); }
8691 * Options common to both CREATE FUNCTION and ALTER FUNCTION
8693 common_func_opt_item:
8694 CALLED ON NULL_P INPUT_P
8696 $$
= makeDefElem
("strict", (Node
*) makeBoolean
(false
), @
1);
8698 | RETURNS NULL_P ON NULL_P INPUT_P
8700 $$
= makeDefElem
("strict", (Node
*) makeBoolean
(true
), @
1);
8704 $$
= makeDefElem
("strict", (Node
*) makeBoolean
(true
), @
1);
8708 $$
= makeDefElem
("volatility", (Node
*) makeString
("immutable"), @
1);
8712 $$
= makeDefElem
("volatility", (Node
*) makeString
("stable"), @
1);
8716 $$
= makeDefElem
("volatility", (Node
*) makeString
("volatile"), @
1);
8718 | EXTERNAL SECURITY DEFINER
8720 $$
= makeDefElem
("security", (Node
*) makeBoolean
(true
), @
1);
8722 | EXTERNAL SECURITY INVOKER
8724 $$
= makeDefElem
("security", (Node
*) makeBoolean
(false
), @
1);
8728 $$
= makeDefElem
("security", (Node
*) makeBoolean
(true
), @
1);
8732 $$
= makeDefElem
("security", (Node
*) makeBoolean
(false
), @
1);
8736 $$
= makeDefElem
("leakproof", (Node
*) makeBoolean
(true
), @
1);
8740 $$
= makeDefElem
("leakproof", (Node
*) makeBoolean
(false
), @
1);
8744 $$
= makeDefElem
("cost", (Node
*) $2, @
1);
8748 $$
= makeDefElem
("rows", (Node
*) $2, @
1);
8752 $$
= makeDefElem
("support", (Node
*) $2, @
1);
8754 | FunctionSetResetClause
8756 /* we abuse the normal content of a DefElem here */
8757 $$
= makeDefElem
("set", (Node
*) $1, @
1);
8761 $$
= makeDefElem
("parallel", (Node
*) makeString
($2), @
1);
8765 createfunc_opt_item:
8768 $$
= makeDefElem
("as", (Node
*) $2, @
1);
8770 | LANGUAGE NonReservedWord_or_Sconst
8772 $$
= makeDefElem
("language", (Node
*) makeString
($2), @
1);
8774 | TRANSFORM transform_type_list
8776 $$
= makeDefElem
("transform", (Node
*) $2, @
1);
8780 $$
= makeDefElem
("window", (Node
*) makeBoolean
(true
), @
1);
8782 | common_func_opt_item
8788 func_as: Sconst
{ $$
= list_make1
(makeString
($1)); }
8791 $$
= list_make2
(makeString
($1), makeString
($3));
8795 ReturnStmt: RETURN a_expr
8797 ReturnStmt
*r
= makeNode
(ReturnStmt
);
8799 r
->returnval
= (Node
*) $2;
8809 | BEGIN_P ATOMIC routine_body_stmt_list END_P
8812 * A compound statement is stored as a single-item list
8813 * containing the list of statements as its member. That
8814 * way, the parse analysis code can tell apart an empty
8815 * body from no body at all.
8817 $$
= (Node
*) list_make1
($3);
8825 routine_body_stmt_list:
8826 routine_body_stmt_list routine_body_stmt
';'
8828 /* As in stmtmulti, discard empty statements */
8830 $$
= lappend
($1, $2);
8845 transform_type_list:
8846 FOR TYPE_P Typename
{ $$
= list_make1
($3); }
8847 | transform_type_list
',' FOR TYPE_P Typename
{ $$
= lappend
($1, $5); }
8851 WITH definition
{ $$
= $2; }
8852 |
/*EMPTY*/ { $$
= NIL
; }
8855 table_func_column: param_name func_type
8857 FunctionParameter
*n
= makeNode
(FunctionParameter
);
8861 n
->mode
= FUNC_PARAM_TABLE
;
8868 table_func_column_list:
8871 $$
= list_make1
($1);
8873 | table_func_column_list
',' table_func_column
8875 $$
= lappend
($1, $3);
8879 /*****************************************************************************
8880 * ALTER FUNCTION / ALTER PROCEDURE / ALTER ROUTINE
8882 * RENAME and OWNER subcommands are already provided by the generic
8883 * ALTER infrastructure, here we just specify alterations that can
8884 * only be applied to functions.
8886 *****************************************************************************/
8888 ALTER FUNCTION function_with_argtypes alterfunc_opt_list opt_restrict
8890 AlterFunctionStmt
*n
= makeNode
(AlterFunctionStmt
);
8892 n
->objtype
= OBJECT_FUNCTION
;
8897 | ALTER PROCEDURE function_with_argtypes alterfunc_opt_list opt_restrict
8899 AlterFunctionStmt
*n
= makeNode
(AlterFunctionStmt
);
8901 n
->objtype
= OBJECT_PROCEDURE
;
8906 | ALTER ROUTINE function_with_argtypes alterfunc_opt_list opt_restrict
8908 AlterFunctionStmt
*n
= makeNode
(AlterFunctionStmt
);
8910 n
->objtype
= OBJECT_ROUTINE
;
8918 /* At least one option must be specified */
8919 common_func_opt_item
{ $$
= list_make1
($1); }
8920 | alterfunc_opt_list common_func_opt_item
{ $$
= lappend
($1, $2); }
8923 /* Ignored, merely for SQL compliance */
8930 /*****************************************************************************
8934 * DROP FUNCTION funcname (arg1, arg2, ...) [ RESTRICT | CASCADE ]
8935 * DROP PROCEDURE procname (arg1, arg2, ...) [ RESTRICT | CASCADE ]
8936 * DROP ROUTINE routname (arg1, arg2, ...) [ RESTRICT | CASCADE ]
8937 * DROP AGGREGATE aggname (arg1, ...) [ RESTRICT | CASCADE ]
8938 * DROP OPERATOR opname (leftoperand_typ, rightoperand_typ) [ RESTRICT | CASCADE ]
8940 *****************************************************************************/
8943 DROP FUNCTION function_with_argtypes_list opt_drop_behavior
8945 DropStmt
*n
= makeNode
(DropStmt
);
8947 n
->removeType
= OBJECT_FUNCTION
;
8950 n
->missing_ok
= false
;
8951 n
->concurrent
= false
;
8954 | DROP FUNCTION IF_P EXISTS function_with_argtypes_list opt_drop_behavior
8956 DropStmt
*n
= makeNode
(DropStmt
);
8958 n
->removeType
= OBJECT_FUNCTION
;
8961 n
->missing_ok
= true
;
8962 n
->concurrent
= false
;
8965 | DROP PROCEDURE function_with_argtypes_list opt_drop_behavior
8967 DropStmt
*n
= makeNode
(DropStmt
);
8969 n
->removeType
= OBJECT_PROCEDURE
;
8972 n
->missing_ok
= false
;
8973 n
->concurrent
= false
;
8976 | DROP PROCEDURE IF_P EXISTS function_with_argtypes_list opt_drop_behavior
8978 DropStmt
*n
= makeNode
(DropStmt
);
8980 n
->removeType
= OBJECT_PROCEDURE
;
8983 n
->missing_ok
= true
;
8984 n
->concurrent
= false
;
8987 | DROP ROUTINE function_with_argtypes_list opt_drop_behavior
8989 DropStmt
*n
= makeNode
(DropStmt
);
8991 n
->removeType
= OBJECT_ROUTINE
;
8994 n
->missing_ok
= false
;
8995 n
->concurrent
= false
;
8998 | DROP ROUTINE IF_P EXISTS function_with_argtypes_list opt_drop_behavior
9000 DropStmt
*n
= makeNode
(DropStmt
);
9002 n
->removeType
= OBJECT_ROUTINE
;
9005 n
->missing_ok
= true
;
9006 n
->concurrent
= false
;
9012 DROP AGGREGATE aggregate_with_argtypes_list opt_drop_behavior
9014 DropStmt
*n
= makeNode
(DropStmt
);
9016 n
->removeType
= OBJECT_AGGREGATE
;
9019 n
->missing_ok
= false
;
9020 n
->concurrent
= false
;
9023 | DROP AGGREGATE IF_P EXISTS aggregate_with_argtypes_list opt_drop_behavior
9025 DropStmt
*n
= makeNode
(DropStmt
);
9027 n
->removeType
= OBJECT_AGGREGATE
;
9030 n
->missing_ok
= true
;
9031 n
->concurrent
= false
;
9037 DROP OPERATOR operator_with_argtypes_list opt_drop_behavior
9039 DropStmt
*n
= makeNode
(DropStmt
);
9041 n
->removeType
= OBJECT_OPERATOR
;
9044 n
->missing_ok
= false
;
9045 n
->concurrent
= false
;
9048 | DROP OPERATOR IF_P EXISTS operator_with_argtypes_list opt_drop_behavior
9050 DropStmt
*n
= makeNode
(DropStmt
);
9052 n
->removeType
= OBJECT_OPERATOR
;
9055 n
->missing_ok
= true
;
9056 n
->concurrent
= false
;
9065 (errcode
(ERRCODE_SYNTAX_ERROR
),
9066 errmsg
("missing argument"),
9067 errhint
("Use NONE to denote the missing argument of a unary operator."),
9068 parser_errposition
(@
3)));
9070 |
'(' Typename
',' Typename
')'
9071 { $$
= list_make2
($2, $4); }
9072 |
'(' NONE
',' Typename
')' /* left unary */
9073 { $$
= list_make2
(NULL
, $4); }
9074 |
'(' Typename
',' NONE
')' /* right unary */
9075 { $$
= list_make2
($2, NULL
); }
9080 { $$
= list_make1
(makeString
($1)); }
9081 | ColId
'.' any_operator
9082 { $$
= lcons
(makeString
($1), $3); }
9085 operator_with_argtypes_list:
9086 operator_with_argtypes
{ $$
= list_make1
($1); }
9087 | operator_with_argtypes_list
',' operator_with_argtypes
9088 { $$
= lappend
($1, $3); }
9091 operator_with_argtypes:
9092 any_operator oper_argtypes
9094 ObjectWithArgs
*n
= makeNode
(ObjectWithArgs
);
9102 /*****************************************************************************
9104 * DO <anonymous code block> [ LANGUAGE language ]
9106 * We use a DefElem list for future extensibility, and to allow flexibility
9107 * in the clause order.
9109 *****************************************************************************/
9111 DoStmt: DO dostmt_opt_list
9113 DoStmt
*n
= makeNode
(DoStmt
);
9121 dostmt_opt_item
{ $$
= list_make1
($1); }
9122 | dostmt_opt_list dostmt_opt_item
{ $$
= lappend
($1, $2); }
9128 $$
= makeDefElem
("as", (Node
*) makeString
($1), @
1);
9130 | LANGUAGE NonReservedWord_or_Sconst
9132 $$
= makeDefElem
("language", (Node
*) makeString
($2), @
1);
9136 /*****************************************************************************
9138 * CREATE CAST / DROP CAST
9140 *****************************************************************************/
9142 CreateCastStmt: CREATE CAST
'(' Typename AS Typename
')'
9143 WITH FUNCTION function_with_argtypes cast_context
9145 CreateCastStmt
*n
= makeNode
(CreateCastStmt
);
9150 n
->context
= (CoercionContext
) $11;
9154 | CREATE CAST
'(' Typename AS Typename
')'
9155 WITHOUT FUNCTION cast_context
9157 CreateCastStmt
*n
= makeNode
(CreateCastStmt
);
9162 n
->context
= (CoercionContext
) $10;
9166 | CREATE CAST
'(' Typename AS Typename
')'
9167 WITH INOUT cast_context
9169 CreateCastStmt
*n
= makeNode
(CreateCastStmt
);
9174 n
->context
= (CoercionContext
) $10;
9180 cast_context: AS IMPLICIT_P
{ $$
= COERCION_IMPLICIT
; }
9181 | AS ASSIGNMENT
{ $$
= COERCION_ASSIGNMENT
; }
9182 |
/*EMPTY*/ { $$
= COERCION_EXPLICIT
; }
9186 DropCastStmt: DROP CAST opt_if_exists
'(' Typename AS Typename
')' opt_drop_behavior
9188 DropStmt
*n
= makeNode
(DropStmt
);
9190 n
->removeType
= OBJECT_CAST
;
9191 n
->objects
= list_make1
(list_make2
($5, $7));
9194 n
->concurrent
= false
;
9199 opt_if_exists: IF_P EXISTS
{ $$
= true
; }
9200 |
/*EMPTY*/ { $$
= false
; }
9204 /*****************************************************************************
9206 * CREATE TRANSFORM / DROP TRANSFORM
9208 *****************************************************************************/
9210 CreateTransformStmt: CREATE opt_or_replace TRANSFORM FOR Typename LANGUAGE name
'(' transform_element_list
')'
9212 CreateTransformStmt
*n
= makeNode
(CreateTransformStmt
);
9217 n
->fromsql
= linitial
($9);
9218 n
->tosql
= lsecond
($9);
9223 transform_element_list: FROM SQL_P WITH FUNCTION function_with_argtypes
',' TO SQL_P WITH FUNCTION function_with_argtypes
9225 $$
= list_make2
($5, $11);
9227 | TO SQL_P WITH FUNCTION function_with_argtypes
',' FROM SQL_P WITH FUNCTION function_with_argtypes
9229 $$
= list_make2
($11, $5);
9231 | FROM SQL_P WITH FUNCTION function_with_argtypes
9233 $$
= list_make2
($5, NULL
);
9235 | TO SQL_P WITH FUNCTION function_with_argtypes
9237 $$
= list_make2
(NULL
, $5);
9242 DropTransformStmt: DROP TRANSFORM opt_if_exists FOR Typename LANGUAGE name opt_drop_behavior
9244 DropStmt
*n
= makeNode
(DropStmt
);
9246 n
->removeType
= OBJECT_TRANSFORM
;
9247 n
->objects
= list_make1
(list_make2
($5, makeString
($7)));
9255 /*****************************************************************************
9259 * REINDEX [ (options) ] {INDEX | TABLE | SCHEMA} [CONCURRENTLY] <name>
9260 * REINDEX [ (options) ] {DATABASE | SYSTEM} [CONCURRENTLY] [<name>]
9261 *****************************************************************************/
9264 REINDEX opt_reindex_option_list reindex_target_relation opt_concurrently qualified_name
9266 ReindexStmt
*n
= makeNode
(ReindexStmt
);
9273 n
->params
= lappend
(n
->params
,
9274 makeDefElem
("concurrently", NULL
, @
4));
9277 | REINDEX opt_reindex_option_list SCHEMA opt_concurrently name
9279 ReindexStmt
*n
= makeNode
(ReindexStmt
);
9281 n
->kind
= REINDEX_OBJECT_SCHEMA
;
9286 n
->params
= lappend
(n
->params
,
9287 makeDefElem
("concurrently", NULL
, @
4));
9290 | REINDEX opt_reindex_option_list reindex_target_all opt_concurrently opt_single_name
9292 ReindexStmt
*n
= makeNode
(ReindexStmt
);
9299 n
->params
= lappend
(n
->params
,
9300 makeDefElem
("concurrently", NULL
, @
4));
9304 reindex_target_relation:
9305 INDEX
{ $$
= REINDEX_OBJECT_INDEX
; }
9306 | TABLE
{ $$
= REINDEX_OBJECT_TABLE
; }
9309 SYSTEM_P
{ $$
= REINDEX_OBJECT_SYSTEM
; }
9310 | DATABASE
{ $$
= REINDEX_OBJECT_DATABASE
; }
9312 opt_reindex_option_list:
9313 '(' utility_option_list
')' { $$
= $2; }
9314 |
/* EMPTY */ { $$
= NULL
; }
9317 /*****************************************************************************
9321 *****************************************************************************/
9324 ALTER TABLESPACE name SET reloptions
9326 AlterTableSpaceOptionsStmt
*n
=
9327 makeNode
(AlterTableSpaceOptionsStmt
);
9329 n
->tablespacename
= $3;
9334 | ALTER TABLESPACE name RESET reloptions
9336 AlterTableSpaceOptionsStmt
*n
=
9337 makeNode
(AlterTableSpaceOptionsStmt
);
9339 n
->tablespacename
= $3;
9346 /*****************************************************************************
9348 * ALTER THING name RENAME TO newname
9350 *****************************************************************************/
9352 RenameStmt: ALTER AGGREGATE aggregate_with_argtypes RENAME TO name
9354 RenameStmt
*n
= makeNode
(RenameStmt
);
9356 n
->renameType
= OBJECT_AGGREGATE
;
9357 n
->object
= (Node
*) $3;
9359 n
->missing_ok
= false
;
9362 | ALTER COLLATION any_name RENAME TO name
9364 RenameStmt
*n
= makeNode
(RenameStmt
);
9366 n
->renameType
= OBJECT_COLLATION
;
9367 n
->object
= (Node
*) $3;
9369 n
->missing_ok
= false
;
9372 | ALTER CONVERSION_P any_name RENAME TO name
9374 RenameStmt
*n
= makeNode
(RenameStmt
);
9376 n
->renameType
= OBJECT_CONVERSION
;
9377 n
->object
= (Node
*) $3;
9379 n
->missing_ok
= false
;
9382 | ALTER DATABASE name RENAME TO name
9384 RenameStmt
*n
= makeNode
(RenameStmt
);
9386 n
->renameType
= OBJECT_DATABASE
;
9389 n
->missing_ok
= false
;
9392 | ALTER DOMAIN_P any_name RENAME TO name
9394 RenameStmt
*n
= makeNode
(RenameStmt
);
9396 n
->renameType
= OBJECT_DOMAIN
;
9397 n
->object
= (Node
*) $3;
9399 n
->missing_ok
= false
;
9402 | ALTER DOMAIN_P any_name RENAME CONSTRAINT name TO name
9404 RenameStmt
*n
= makeNode
(RenameStmt
);
9406 n
->renameType
= OBJECT_DOMCONSTRAINT
;
9407 n
->object
= (Node
*) $3;
9412 | ALTER FOREIGN DATA_P WRAPPER name RENAME TO name
9414 RenameStmt
*n
= makeNode
(RenameStmt
);
9416 n
->renameType
= OBJECT_FDW
;
9417 n
->object
= (Node
*) makeString
($5);
9419 n
->missing_ok
= false
;
9422 | ALTER FUNCTION function_with_argtypes RENAME TO name
9424 RenameStmt
*n
= makeNode
(RenameStmt
);
9426 n
->renameType
= OBJECT_FUNCTION
;
9427 n
->object
= (Node
*) $3;
9429 n
->missing_ok
= false
;
9432 | ALTER GROUP_P RoleId RENAME TO RoleId
9434 RenameStmt
*n
= makeNode
(RenameStmt
);
9436 n
->renameType
= OBJECT_ROLE
;
9439 n
->missing_ok
= false
;
9442 | ALTER opt_procedural LANGUAGE name RENAME TO name
9444 RenameStmt
*n
= makeNode
(RenameStmt
);
9446 n
->renameType
= OBJECT_LANGUAGE
;
9447 n
->object
= (Node
*) makeString
($4);
9449 n
->missing_ok
= false
;
9452 | ALTER OPERATOR CLASS any_name USING name RENAME TO name
9454 RenameStmt
*n
= makeNode
(RenameStmt
);
9456 n
->renameType
= OBJECT_OPCLASS
;
9457 n
->object
= (Node
*) lcons
(makeString
($6), $4);
9459 n
->missing_ok
= false
;
9462 | ALTER OPERATOR FAMILY any_name USING name RENAME TO name
9464 RenameStmt
*n
= makeNode
(RenameStmt
);
9466 n
->renameType
= OBJECT_OPFAMILY
;
9467 n
->object
= (Node
*) lcons
(makeString
($6), $4);
9469 n
->missing_ok
= false
;
9472 | ALTER POLICY name ON qualified_name RENAME TO name
9474 RenameStmt
*n
= makeNode
(RenameStmt
);
9476 n
->renameType
= OBJECT_POLICY
;
9480 n
->missing_ok
= false
;
9483 | ALTER POLICY IF_P EXISTS name ON qualified_name RENAME TO name
9485 RenameStmt
*n
= makeNode
(RenameStmt
);
9487 n
->renameType
= OBJECT_POLICY
;
9491 n
->missing_ok
= true
;
9494 | ALTER PROCEDURE function_with_argtypes RENAME TO name
9496 RenameStmt
*n
= makeNode
(RenameStmt
);
9498 n
->renameType
= OBJECT_PROCEDURE
;
9499 n
->object
= (Node
*) $3;
9501 n
->missing_ok
= false
;
9504 | ALTER PUBLICATION name RENAME TO name
9506 RenameStmt
*n
= makeNode
(RenameStmt
);
9508 n
->renameType
= OBJECT_PUBLICATION
;
9509 n
->object
= (Node
*) makeString
($3);
9511 n
->missing_ok
= false
;
9514 | ALTER ROUTINE function_with_argtypes RENAME TO name
9516 RenameStmt
*n
= makeNode
(RenameStmt
);
9518 n
->renameType
= OBJECT_ROUTINE
;
9519 n
->object
= (Node
*) $3;
9521 n
->missing_ok
= false
;
9524 | ALTER SCHEMA name RENAME TO name
9526 RenameStmt
*n
= makeNode
(RenameStmt
);
9528 n
->renameType
= OBJECT_SCHEMA
;
9531 n
->missing_ok
= false
;
9534 | ALTER SERVER name RENAME TO name
9536 RenameStmt
*n
= makeNode
(RenameStmt
);
9538 n
->renameType
= OBJECT_FOREIGN_SERVER
;
9539 n
->object
= (Node
*) makeString
($3);
9541 n
->missing_ok
= false
;
9544 | ALTER SUBSCRIPTION name RENAME TO name
9546 RenameStmt
*n
= makeNode
(RenameStmt
);
9548 n
->renameType
= OBJECT_SUBSCRIPTION
;
9549 n
->object
= (Node
*) makeString
($3);
9551 n
->missing_ok
= false
;
9554 | ALTER TABLE relation_expr RENAME TO name
9556 RenameStmt
*n
= makeNode
(RenameStmt
);
9558 n
->renameType
= OBJECT_TABLE
;
9562 n
->missing_ok
= false
;
9565 | ALTER TABLE IF_P EXISTS relation_expr RENAME TO name
9567 RenameStmt
*n
= makeNode
(RenameStmt
);
9569 n
->renameType
= OBJECT_TABLE
;
9573 n
->missing_ok
= true
;
9576 | ALTER SEQUENCE qualified_name RENAME TO name
9578 RenameStmt
*n
= makeNode
(RenameStmt
);
9580 n
->renameType
= OBJECT_SEQUENCE
;
9584 n
->missing_ok
= false
;
9587 | ALTER SEQUENCE IF_P EXISTS qualified_name RENAME TO name
9589 RenameStmt
*n
= makeNode
(RenameStmt
);
9591 n
->renameType
= OBJECT_SEQUENCE
;
9595 n
->missing_ok
= true
;
9598 | ALTER VIEW qualified_name RENAME TO name
9600 RenameStmt
*n
= makeNode
(RenameStmt
);
9602 n
->renameType
= OBJECT_VIEW
;
9606 n
->missing_ok
= false
;
9609 | ALTER VIEW IF_P EXISTS qualified_name RENAME TO name
9611 RenameStmt
*n
= makeNode
(RenameStmt
);
9613 n
->renameType
= OBJECT_VIEW
;
9617 n
->missing_ok
= true
;
9620 | ALTER MATERIALIZED VIEW qualified_name RENAME TO name
9622 RenameStmt
*n
= makeNode
(RenameStmt
);
9624 n
->renameType
= OBJECT_MATVIEW
;
9628 n
->missing_ok
= false
;
9631 | ALTER MATERIALIZED VIEW IF_P EXISTS qualified_name RENAME TO name
9633 RenameStmt
*n
= makeNode
(RenameStmt
);
9635 n
->renameType
= OBJECT_MATVIEW
;
9639 n
->missing_ok
= true
;
9642 | ALTER INDEX qualified_name RENAME TO name
9644 RenameStmt
*n
= makeNode
(RenameStmt
);
9646 n
->renameType
= OBJECT_INDEX
;
9650 n
->missing_ok
= false
;
9653 | ALTER INDEX IF_P EXISTS qualified_name RENAME TO name
9655 RenameStmt
*n
= makeNode
(RenameStmt
);
9657 n
->renameType
= OBJECT_INDEX
;
9661 n
->missing_ok
= true
;
9664 | ALTER FOREIGN TABLE relation_expr RENAME TO name
9666 RenameStmt
*n
= makeNode
(RenameStmt
);
9668 n
->renameType
= OBJECT_FOREIGN_TABLE
;
9672 n
->missing_ok
= false
;
9675 | ALTER FOREIGN TABLE IF_P EXISTS relation_expr RENAME TO name
9677 RenameStmt
*n
= makeNode
(RenameStmt
);
9679 n
->renameType
= OBJECT_FOREIGN_TABLE
;
9683 n
->missing_ok
= true
;
9686 | ALTER TABLE relation_expr RENAME opt_column name TO name
9688 RenameStmt
*n
= makeNode
(RenameStmt
);
9690 n
->renameType
= OBJECT_COLUMN
;
9691 n
->relationType
= OBJECT_TABLE
;
9695 n
->missing_ok
= false
;
9698 | ALTER TABLE IF_P EXISTS relation_expr RENAME opt_column name TO name
9700 RenameStmt
*n
= makeNode
(RenameStmt
);
9702 n
->renameType
= OBJECT_COLUMN
;
9703 n
->relationType
= OBJECT_TABLE
;
9707 n
->missing_ok
= true
;
9710 | ALTER VIEW qualified_name RENAME opt_column name TO name
9712 RenameStmt
*n
= makeNode
(RenameStmt
);
9714 n
->renameType
= OBJECT_COLUMN
;
9715 n
->relationType
= OBJECT_VIEW
;
9719 n
->missing_ok
= false
;
9722 | ALTER VIEW IF_P EXISTS qualified_name RENAME opt_column name TO name
9724 RenameStmt
*n
= makeNode
(RenameStmt
);
9726 n
->renameType
= OBJECT_COLUMN
;
9727 n
->relationType
= OBJECT_VIEW
;
9731 n
->missing_ok
= true
;
9734 | ALTER MATERIALIZED VIEW qualified_name RENAME opt_column name TO name
9736 RenameStmt
*n
= makeNode
(RenameStmt
);
9738 n
->renameType
= OBJECT_COLUMN
;
9739 n
->relationType
= OBJECT_MATVIEW
;
9743 n
->missing_ok
= false
;
9746 | ALTER MATERIALIZED VIEW IF_P EXISTS qualified_name RENAME opt_column name TO name
9748 RenameStmt
*n
= makeNode
(RenameStmt
);
9750 n
->renameType
= OBJECT_COLUMN
;
9751 n
->relationType
= OBJECT_MATVIEW
;
9755 n
->missing_ok
= true
;
9758 | ALTER TABLE relation_expr RENAME CONSTRAINT name TO name
9760 RenameStmt
*n
= makeNode
(RenameStmt
);
9762 n
->renameType
= OBJECT_TABCONSTRAINT
;
9766 n
->missing_ok
= false
;
9769 | ALTER TABLE IF_P EXISTS relation_expr RENAME CONSTRAINT name TO name
9771 RenameStmt
*n
= makeNode
(RenameStmt
);
9773 n
->renameType
= OBJECT_TABCONSTRAINT
;
9777 n
->missing_ok
= true
;
9780 | ALTER FOREIGN TABLE relation_expr RENAME opt_column name TO name
9782 RenameStmt
*n
= makeNode
(RenameStmt
);
9784 n
->renameType
= OBJECT_COLUMN
;
9785 n
->relationType
= OBJECT_FOREIGN_TABLE
;
9789 n
->missing_ok
= false
;
9792 | ALTER FOREIGN TABLE IF_P EXISTS relation_expr RENAME opt_column name TO name
9794 RenameStmt
*n
= makeNode
(RenameStmt
);
9796 n
->renameType
= OBJECT_COLUMN
;
9797 n
->relationType
= OBJECT_FOREIGN_TABLE
;
9801 n
->missing_ok
= true
;
9804 | ALTER RULE name ON qualified_name RENAME TO name
9806 RenameStmt
*n
= makeNode
(RenameStmt
);
9808 n
->renameType
= OBJECT_RULE
;
9812 n
->missing_ok
= false
;
9815 | ALTER TRIGGER name ON qualified_name RENAME TO name
9817 RenameStmt
*n
= makeNode
(RenameStmt
);
9819 n
->renameType
= OBJECT_TRIGGER
;
9823 n
->missing_ok
= false
;
9826 | ALTER EVENT TRIGGER name RENAME TO name
9828 RenameStmt
*n
= makeNode
(RenameStmt
);
9830 n
->renameType
= OBJECT_EVENT_TRIGGER
;
9831 n
->object
= (Node
*) makeString
($4);
9835 | ALTER ROLE RoleId RENAME TO RoleId
9837 RenameStmt
*n
= makeNode
(RenameStmt
);
9839 n
->renameType
= OBJECT_ROLE
;
9842 n
->missing_ok
= false
;
9845 | ALTER USER RoleId RENAME TO RoleId
9847 RenameStmt
*n
= makeNode
(RenameStmt
);
9849 n
->renameType
= OBJECT_ROLE
;
9852 n
->missing_ok
= false
;
9855 | ALTER TABLESPACE name RENAME TO name
9857 RenameStmt
*n
= makeNode
(RenameStmt
);
9859 n
->renameType
= OBJECT_TABLESPACE
;
9862 n
->missing_ok
= false
;
9865 | ALTER STATISTICS any_name RENAME TO name
9867 RenameStmt
*n
= makeNode
(RenameStmt
);
9869 n
->renameType
= OBJECT_STATISTIC_EXT
;
9870 n
->object
= (Node
*) $3;
9872 n
->missing_ok
= false
;
9875 | ALTER TEXT_P SEARCH PARSER any_name RENAME TO name
9877 RenameStmt
*n
= makeNode
(RenameStmt
);
9879 n
->renameType
= OBJECT_TSPARSER
;
9880 n
->object
= (Node
*) $5;
9882 n
->missing_ok
= false
;
9885 | ALTER TEXT_P SEARCH DICTIONARY any_name RENAME TO name
9887 RenameStmt
*n
= makeNode
(RenameStmt
);
9889 n
->renameType
= OBJECT_TSDICTIONARY
;
9890 n
->object
= (Node
*) $5;
9892 n
->missing_ok
= false
;
9895 | ALTER TEXT_P SEARCH TEMPLATE any_name RENAME TO name
9897 RenameStmt
*n
= makeNode
(RenameStmt
);
9899 n
->renameType
= OBJECT_TSTEMPLATE
;
9900 n
->object
= (Node
*) $5;
9902 n
->missing_ok
= false
;
9905 | ALTER TEXT_P SEARCH CONFIGURATION any_name RENAME TO name
9907 RenameStmt
*n
= makeNode
(RenameStmt
);
9909 n
->renameType
= OBJECT_TSCONFIGURATION
;
9910 n
->object
= (Node
*) $5;
9912 n
->missing_ok
= false
;
9915 | ALTER TYPE_P any_name RENAME TO name
9917 RenameStmt
*n
= makeNode
(RenameStmt
);
9919 n
->renameType
= OBJECT_TYPE
;
9920 n
->object
= (Node
*) $3;
9922 n
->missing_ok
= false
;
9925 | ALTER TYPE_P any_name RENAME ATTRIBUTE name TO name opt_drop_behavior
9927 RenameStmt
*n
= makeNode
(RenameStmt
);
9929 n
->renameType
= OBJECT_ATTRIBUTE
;
9930 n
->relationType
= OBJECT_TYPE
;
9931 n
->relation
= makeRangeVarFromAnyName
($3, @
3, yyscanner
);
9935 n
->missing_ok
= false
;
9944 opt_set_data: SET DATA_P
{ $$
= 1; }
9945 |
/*EMPTY*/ { $$
= 0; }
9948 /*****************************************************************************
9950 * ALTER THING name DEPENDS ON EXTENSION name
9952 *****************************************************************************/
9954 AlterObjectDependsStmt:
9955 ALTER FUNCTION function_with_argtypes opt_no DEPENDS ON EXTENSION name
9957 AlterObjectDependsStmt
*n
= makeNode
(AlterObjectDependsStmt
);
9959 n
->objectType
= OBJECT_FUNCTION
;
9960 n
->object
= (Node
*) $3;
9961 n
->extname
= makeString
($8);
9965 | ALTER PROCEDURE function_with_argtypes opt_no DEPENDS ON EXTENSION name
9967 AlterObjectDependsStmt
*n
= makeNode
(AlterObjectDependsStmt
);
9969 n
->objectType
= OBJECT_PROCEDURE
;
9970 n
->object
= (Node
*) $3;
9971 n
->extname
= makeString
($8);
9975 | ALTER ROUTINE function_with_argtypes opt_no DEPENDS ON EXTENSION name
9977 AlterObjectDependsStmt
*n
= makeNode
(AlterObjectDependsStmt
);
9979 n
->objectType
= OBJECT_ROUTINE
;
9980 n
->object
= (Node
*) $3;
9981 n
->extname
= makeString
($8);
9985 | ALTER TRIGGER name ON qualified_name opt_no DEPENDS ON EXTENSION name
9987 AlterObjectDependsStmt
*n
= makeNode
(AlterObjectDependsStmt
);
9989 n
->objectType
= OBJECT_TRIGGER
;
9991 n
->object
= (Node
*) list_make1
(makeString
($3));
9992 n
->extname
= makeString
($10);
9996 | ALTER MATERIALIZED VIEW qualified_name opt_no DEPENDS ON EXTENSION name
9998 AlterObjectDependsStmt
*n
= makeNode
(AlterObjectDependsStmt
);
10000 n
->objectType
= OBJECT_MATVIEW
;
10002 n
->extname
= makeString
($9);
10006 | ALTER INDEX qualified_name opt_no DEPENDS ON EXTENSION name
10008 AlterObjectDependsStmt
*n
= makeNode
(AlterObjectDependsStmt
);
10010 n
->objectType
= OBJECT_INDEX
;
10012 n
->extname
= makeString
($8);
10018 opt_no: NO
{ $$
= true
; }
10019 |
/* EMPTY */ { $$
= false
; }
10022 /*****************************************************************************
10024 * ALTER THING name SET SCHEMA name
10026 *****************************************************************************/
10028 AlterObjectSchemaStmt:
10029 ALTER AGGREGATE aggregate_with_argtypes SET SCHEMA name
10031 AlterObjectSchemaStmt
*n
= makeNode
(AlterObjectSchemaStmt
);
10033 n
->objectType
= OBJECT_AGGREGATE
;
10034 n
->object
= (Node
*) $3;
10036 n
->missing_ok
= false
;
10039 | ALTER COLLATION any_name SET SCHEMA name
10041 AlterObjectSchemaStmt
*n
= makeNode
(AlterObjectSchemaStmt
);
10043 n
->objectType
= OBJECT_COLLATION
;
10044 n
->object
= (Node
*) $3;
10046 n
->missing_ok
= false
;
10049 | ALTER CONVERSION_P any_name SET SCHEMA name
10051 AlterObjectSchemaStmt
*n
= makeNode
(AlterObjectSchemaStmt
);
10053 n
->objectType
= OBJECT_CONVERSION
;
10054 n
->object
= (Node
*) $3;
10056 n
->missing_ok
= false
;
10059 | ALTER DOMAIN_P any_name SET SCHEMA name
10061 AlterObjectSchemaStmt
*n
= makeNode
(AlterObjectSchemaStmt
);
10063 n
->objectType
= OBJECT_DOMAIN
;
10064 n
->object
= (Node
*) $3;
10066 n
->missing_ok
= false
;
10069 | ALTER EXTENSION name SET SCHEMA name
10071 AlterObjectSchemaStmt
*n
= makeNode
(AlterObjectSchemaStmt
);
10073 n
->objectType
= OBJECT_EXTENSION
;
10074 n
->object
= (Node
*) makeString
($3);
10076 n
->missing_ok
= false
;
10079 | ALTER FUNCTION function_with_argtypes SET SCHEMA name
10081 AlterObjectSchemaStmt
*n
= makeNode
(AlterObjectSchemaStmt
);
10083 n
->objectType
= OBJECT_FUNCTION
;
10084 n
->object
= (Node
*) $3;
10086 n
->missing_ok
= false
;
10089 | ALTER OPERATOR operator_with_argtypes SET SCHEMA name
10091 AlterObjectSchemaStmt
*n
= makeNode
(AlterObjectSchemaStmt
);
10093 n
->objectType
= OBJECT_OPERATOR
;
10094 n
->object
= (Node
*) $3;
10096 n
->missing_ok
= false
;
10099 | ALTER OPERATOR CLASS any_name USING name SET SCHEMA name
10101 AlterObjectSchemaStmt
*n
= makeNode
(AlterObjectSchemaStmt
);
10103 n
->objectType
= OBJECT_OPCLASS
;
10104 n
->object
= (Node
*) lcons
(makeString
($6), $4);
10106 n
->missing_ok
= false
;
10109 | ALTER OPERATOR FAMILY any_name USING name SET SCHEMA name
10111 AlterObjectSchemaStmt
*n
= makeNode
(AlterObjectSchemaStmt
);
10113 n
->objectType
= OBJECT_OPFAMILY
;
10114 n
->object
= (Node
*) lcons
(makeString
($6), $4);
10116 n
->missing_ok
= false
;
10119 | ALTER PROCEDURE function_with_argtypes SET SCHEMA name
10121 AlterObjectSchemaStmt
*n
= makeNode
(AlterObjectSchemaStmt
);
10123 n
->objectType
= OBJECT_PROCEDURE
;
10124 n
->object
= (Node
*) $3;
10126 n
->missing_ok
= false
;
10129 | ALTER ROUTINE function_with_argtypes SET SCHEMA name
10131 AlterObjectSchemaStmt
*n
= makeNode
(AlterObjectSchemaStmt
);
10133 n
->objectType
= OBJECT_ROUTINE
;
10134 n
->object
= (Node
*) $3;
10136 n
->missing_ok
= false
;
10139 | ALTER TABLE relation_expr SET SCHEMA name
10141 AlterObjectSchemaStmt
*n
= makeNode
(AlterObjectSchemaStmt
);
10143 n
->objectType
= OBJECT_TABLE
;
10146 n
->missing_ok
= false
;
10149 | ALTER TABLE IF_P EXISTS relation_expr SET SCHEMA name
10151 AlterObjectSchemaStmt
*n
= makeNode
(AlterObjectSchemaStmt
);
10153 n
->objectType
= OBJECT_TABLE
;
10156 n
->missing_ok
= true
;
10159 | ALTER STATISTICS any_name SET SCHEMA name
10161 AlterObjectSchemaStmt
*n
= makeNode
(AlterObjectSchemaStmt
);
10163 n
->objectType
= OBJECT_STATISTIC_EXT
;
10164 n
->object
= (Node
*) $3;
10166 n
->missing_ok
= false
;
10169 | ALTER TEXT_P SEARCH PARSER any_name SET SCHEMA name
10171 AlterObjectSchemaStmt
*n
= makeNode
(AlterObjectSchemaStmt
);
10173 n
->objectType
= OBJECT_TSPARSER
;
10174 n
->object
= (Node
*) $5;
10176 n
->missing_ok
= false
;
10179 | ALTER TEXT_P SEARCH DICTIONARY any_name SET SCHEMA name
10181 AlterObjectSchemaStmt
*n
= makeNode
(AlterObjectSchemaStmt
);
10183 n
->objectType
= OBJECT_TSDICTIONARY
;
10184 n
->object
= (Node
*) $5;
10186 n
->missing_ok
= false
;
10189 | ALTER TEXT_P SEARCH TEMPLATE any_name SET SCHEMA name
10191 AlterObjectSchemaStmt
*n
= makeNode
(AlterObjectSchemaStmt
);
10193 n
->objectType
= OBJECT_TSTEMPLATE
;
10194 n
->object
= (Node
*) $5;
10196 n
->missing_ok
= false
;
10199 | ALTER TEXT_P SEARCH CONFIGURATION any_name SET SCHEMA name
10201 AlterObjectSchemaStmt
*n
= makeNode
(AlterObjectSchemaStmt
);
10203 n
->objectType
= OBJECT_TSCONFIGURATION
;
10204 n
->object
= (Node
*) $5;
10206 n
->missing_ok
= false
;
10209 | ALTER SEQUENCE qualified_name SET SCHEMA name
10211 AlterObjectSchemaStmt
*n
= makeNode
(AlterObjectSchemaStmt
);
10213 n
->objectType
= OBJECT_SEQUENCE
;
10216 n
->missing_ok
= false
;
10219 | ALTER SEQUENCE IF_P EXISTS qualified_name SET SCHEMA name
10221 AlterObjectSchemaStmt
*n
= makeNode
(AlterObjectSchemaStmt
);
10223 n
->objectType
= OBJECT_SEQUENCE
;
10226 n
->missing_ok
= true
;
10229 | ALTER VIEW qualified_name SET SCHEMA name
10231 AlterObjectSchemaStmt
*n
= makeNode
(AlterObjectSchemaStmt
);
10233 n
->objectType
= OBJECT_VIEW
;
10236 n
->missing_ok
= false
;
10239 | ALTER VIEW IF_P EXISTS qualified_name SET SCHEMA name
10241 AlterObjectSchemaStmt
*n
= makeNode
(AlterObjectSchemaStmt
);
10243 n
->objectType
= OBJECT_VIEW
;
10246 n
->missing_ok
= true
;
10249 | ALTER MATERIALIZED VIEW qualified_name SET SCHEMA name
10251 AlterObjectSchemaStmt
*n
= makeNode
(AlterObjectSchemaStmt
);
10253 n
->objectType
= OBJECT_MATVIEW
;
10256 n
->missing_ok
= false
;
10259 | ALTER MATERIALIZED VIEW IF_P EXISTS qualified_name SET SCHEMA name
10261 AlterObjectSchemaStmt
*n
= makeNode
(AlterObjectSchemaStmt
);
10263 n
->objectType
= OBJECT_MATVIEW
;
10266 n
->missing_ok
= true
;
10269 | ALTER FOREIGN TABLE relation_expr SET SCHEMA name
10271 AlterObjectSchemaStmt
*n
= makeNode
(AlterObjectSchemaStmt
);
10273 n
->objectType
= OBJECT_FOREIGN_TABLE
;
10276 n
->missing_ok
= false
;
10279 | ALTER FOREIGN TABLE IF_P EXISTS relation_expr SET SCHEMA name
10281 AlterObjectSchemaStmt
*n
= makeNode
(AlterObjectSchemaStmt
);
10283 n
->objectType
= OBJECT_FOREIGN_TABLE
;
10286 n
->missing_ok
= true
;
10289 | ALTER TYPE_P any_name SET SCHEMA name
10291 AlterObjectSchemaStmt
*n
= makeNode
(AlterObjectSchemaStmt
);
10293 n
->objectType
= OBJECT_TYPE
;
10294 n
->object
= (Node
*) $3;
10296 n
->missing_ok
= false
;
10301 /*****************************************************************************
10303 * ALTER OPERATOR name SET define
10305 *****************************************************************************/
10308 ALTER OPERATOR operator_with_argtypes SET
'(' operator_def_list
')'
10310 AlterOperatorStmt
*n
= makeNode
(AlterOperatorStmt
);
10318 operator_def_list: operator_def_elem
{ $$
= list_make1
($1); }
10319 | operator_def_list
',' operator_def_elem
{ $$
= lappend
($1, $3); }
10322 operator_def_elem: ColLabel
'=' NONE
10323 { $$
= makeDefElem
($1, NULL
, @
1); }
10324 | ColLabel
'=' operator_def_arg
10325 { $$
= makeDefElem
($1, (Node
*) $3, @
1); }
10327 { $$
= makeDefElem
($1, NULL
, @
1); }
10330 /* must be similar enough to def_arg to avoid reduce/reduce conflicts */
10332 func_type
{ $$
= (Node
*) $1; }
10333 | reserved_keyword
{ $$
= (Node
*) makeString
(pstrdup
($1)); }
10334 | qual_all_Op
{ $$
= (Node
*) $1; }
10335 | NumericOnly
{ $$
= (Node
*) $1; }
10336 | Sconst
{ $$
= (Node
*) makeString
($1); }
10339 /*****************************************************************************
10341 * ALTER TYPE name SET define
10343 * We repurpose ALTER OPERATOR's version of "definition" here
10345 *****************************************************************************/
10348 ALTER TYPE_P any_name SET
'(' operator_def_list
')'
10350 AlterTypeStmt
*n
= makeNode
(AlterTypeStmt
);
10358 /*****************************************************************************
10360 * ALTER THING name OWNER TO newname
10362 *****************************************************************************/
10364 AlterOwnerStmt: ALTER AGGREGATE aggregate_with_argtypes OWNER TO RoleSpec
10366 AlterOwnerStmt
*n
= makeNode
(AlterOwnerStmt
);
10368 n
->objectType
= OBJECT_AGGREGATE
;
10369 n
->object
= (Node
*) $3;
10373 | ALTER COLLATION any_name OWNER TO RoleSpec
10375 AlterOwnerStmt
*n
= makeNode
(AlterOwnerStmt
);
10377 n
->objectType
= OBJECT_COLLATION
;
10378 n
->object
= (Node
*) $3;
10382 | ALTER CONVERSION_P any_name OWNER TO RoleSpec
10384 AlterOwnerStmt
*n
= makeNode
(AlterOwnerStmt
);
10386 n
->objectType
= OBJECT_CONVERSION
;
10387 n
->object
= (Node
*) $3;
10391 | ALTER DATABASE name OWNER TO RoleSpec
10393 AlterOwnerStmt
*n
= makeNode
(AlterOwnerStmt
);
10395 n
->objectType
= OBJECT_DATABASE
;
10396 n
->object
= (Node
*) makeString
($3);
10400 | ALTER DOMAIN_P any_name OWNER TO RoleSpec
10402 AlterOwnerStmt
*n
= makeNode
(AlterOwnerStmt
);
10404 n
->objectType
= OBJECT_DOMAIN
;
10405 n
->object
= (Node
*) $3;
10409 | ALTER FUNCTION function_with_argtypes OWNER TO RoleSpec
10411 AlterOwnerStmt
*n
= makeNode
(AlterOwnerStmt
);
10413 n
->objectType
= OBJECT_FUNCTION
;
10414 n
->object
= (Node
*) $3;
10418 | ALTER opt_procedural LANGUAGE name OWNER TO RoleSpec
10420 AlterOwnerStmt
*n
= makeNode
(AlterOwnerStmt
);
10422 n
->objectType
= OBJECT_LANGUAGE
;
10423 n
->object
= (Node
*) makeString
($4);
10427 | ALTER LARGE_P OBJECT_P NumericOnly OWNER TO RoleSpec
10429 AlterOwnerStmt
*n
= makeNode
(AlterOwnerStmt
);
10431 n
->objectType
= OBJECT_LARGEOBJECT
;
10432 n
->object
= (Node
*) $4;
10436 | ALTER OPERATOR operator_with_argtypes OWNER TO RoleSpec
10438 AlterOwnerStmt
*n
= makeNode
(AlterOwnerStmt
);
10440 n
->objectType
= OBJECT_OPERATOR
;
10441 n
->object
= (Node
*) $3;
10445 | ALTER OPERATOR CLASS any_name USING name OWNER TO RoleSpec
10447 AlterOwnerStmt
*n
= makeNode
(AlterOwnerStmt
);
10449 n
->objectType
= OBJECT_OPCLASS
;
10450 n
->object
= (Node
*) lcons
(makeString
($6), $4);
10454 | ALTER OPERATOR FAMILY any_name USING name OWNER TO RoleSpec
10456 AlterOwnerStmt
*n
= makeNode
(AlterOwnerStmt
);
10458 n
->objectType
= OBJECT_OPFAMILY
;
10459 n
->object
= (Node
*) lcons
(makeString
($6), $4);
10463 | ALTER PROCEDURE function_with_argtypes OWNER TO RoleSpec
10465 AlterOwnerStmt
*n
= makeNode
(AlterOwnerStmt
);
10467 n
->objectType
= OBJECT_PROCEDURE
;
10468 n
->object
= (Node
*) $3;
10472 | ALTER ROUTINE function_with_argtypes OWNER TO RoleSpec
10474 AlterOwnerStmt
*n
= makeNode
(AlterOwnerStmt
);
10476 n
->objectType
= OBJECT_ROUTINE
;
10477 n
->object
= (Node
*) $3;
10481 | ALTER SCHEMA name OWNER TO RoleSpec
10483 AlterOwnerStmt
*n
= makeNode
(AlterOwnerStmt
);
10485 n
->objectType
= OBJECT_SCHEMA
;
10486 n
->object
= (Node
*) makeString
($3);
10490 | ALTER TYPE_P any_name OWNER TO RoleSpec
10492 AlterOwnerStmt
*n
= makeNode
(AlterOwnerStmt
);
10494 n
->objectType
= OBJECT_TYPE
;
10495 n
->object
= (Node
*) $3;
10499 | ALTER TABLESPACE name OWNER TO RoleSpec
10501 AlterOwnerStmt
*n
= makeNode
(AlterOwnerStmt
);
10503 n
->objectType
= OBJECT_TABLESPACE
;
10504 n
->object
= (Node
*) makeString
($3);
10508 | ALTER STATISTICS any_name OWNER TO RoleSpec
10510 AlterOwnerStmt
*n
= makeNode
(AlterOwnerStmt
);
10512 n
->objectType
= OBJECT_STATISTIC_EXT
;
10513 n
->object
= (Node
*) $3;
10517 | ALTER TEXT_P SEARCH DICTIONARY any_name OWNER TO RoleSpec
10519 AlterOwnerStmt
*n
= makeNode
(AlterOwnerStmt
);
10521 n
->objectType
= OBJECT_TSDICTIONARY
;
10522 n
->object
= (Node
*) $5;
10526 | ALTER TEXT_P SEARCH CONFIGURATION any_name OWNER TO RoleSpec
10528 AlterOwnerStmt
*n
= makeNode
(AlterOwnerStmt
);
10530 n
->objectType
= OBJECT_TSCONFIGURATION
;
10531 n
->object
= (Node
*) $5;
10535 | ALTER FOREIGN DATA_P WRAPPER name OWNER TO RoleSpec
10537 AlterOwnerStmt
*n
= makeNode
(AlterOwnerStmt
);
10539 n
->objectType
= OBJECT_FDW
;
10540 n
->object
= (Node
*) makeString
($5);
10544 | ALTER SERVER name OWNER TO RoleSpec
10546 AlterOwnerStmt
*n
= makeNode
(AlterOwnerStmt
);
10548 n
->objectType
= OBJECT_FOREIGN_SERVER
;
10549 n
->object
= (Node
*) makeString
($3);
10553 | ALTER EVENT TRIGGER name OWNER TO RoleSpec
10555 AlterOwnerStmt
*n
= makeNode
(AlterOwnerStmt
);
10557 n
->objectType
= OBJECT_EVENT_TRIGGER
;
10558 n
->object
= (Node
*) makeString
($4);
10562 | ALTER PUBLICATION name OWNER TO RoleSpec
10564 AlterOwnerStmt
*n
= makeNode
(AlterOwnerStmt
);
10566 n
->objectType
= OBJECT_PUBLICATION
;
10567 n
->object
= (Node
*) makeString
($3);
10571 | ALTER SUBSCRIPTION name OWNER TO RoleSpec
10573 AlterOwnerStmt
*n
= makeNode
(AlterOwnerStmt
);
10575 n
->objectType
= OBJECT_SUBSCRIPTION
;
10576 n
->object
= (Node
*) makeString
($3);
10583 /*****************************************************************************
10585 * CREATE PUBLICATION name [WITH options]
10587 * CREATE PUBLICATION FOR ALL TABLES [WITH options]
10589 * CREATE PUBLICATION FOR pub_obj [, ...] [WITH options]
10591 * pub_obj is one of:
10593 * TABLE table [, ...]
10594 * TABLES IN SCHEMA schema [, ...]
10596 *****************************************************************************/
10598 CreatePublicationStmt:
10599 CREATE PUBLICATION name opt_definition
10601 CreatePublicationStmt
*n
= makeNode
(CreatePublicationStmt
);
10607 | CREATE PUBLICATION name FOR ALL TABLES opt_definition
10609 CreatePublicationStmt
*n
= makeNode
(CreatePublicationStmt
);
10613 n
->for_all_tables
= true
;
10616 | CREATE PUBLICATION name FOR pub_obj_list opt_definition
10618 CreatePublicationStmt
*n
= makeNode
(CreatePublicationStmt
);
10622 n
->pubobjects
= (List
*) $5;
10623 preprocess_pubobj_list
(n
->pubobjects
, yyscanner
);
10629 * FOR TABLE and FOR TABLES IN SCHEMA specifications
10631 * This rule parses publication objects with and without keyword prefixes.
10633 * The actual type of the object without keyword prefix depends on the previous
10634 * one with keyword prefix. It will be preprocessed in preprocess_pubobj_list().
10636 * For the object without keyword prefix, we cannot just use relation_expr here,
10637 * because some extended expressions in relation_expr cannot be used as a
10638 * schemaname and we cannot differentiate it. So, we extract the rules from
10639 * relation_expr here.
10641 PublicationObjSpec:
10642 TABLE relation_expr opt_column_list OptWhereClause
10644 $$
= makeNode
(PublicationObjSpec
);
10645 $$
->pubobjtype
= PUBLICATIONOBJ_TABLE
;
10646 $$
->pubtable
= makeNode
(PublicationTable
);
10647 $$
->pubtable
->relation
= $2;
10648 $$
->pubtable
->columns
= $3;
10649 $$
->pubtable
->whereClause
= $4;
10651 | TABLES IN_P SCHEMA ColId
10653 $$
= makeNode
(PublicationObjSpec
);
10654 $$
->pubobjtype
= PUBLICATIONOBJ_TABLES_IN_SCHEMA
;
10658 | TABLES IN_P SCHEMA CURRENT_SCHEMA
10660 $$
= makeNode
(PublicationObjSpec
);
10661 $$
->pubobjtype
= PUBLICATIONOBJ_TABLES_IN_CUR_SCHEMA
;
10664 | ColId opt_column_list OptWhereClause
10666 $$
= makeNode
(PublicationObjSpec
);
10667 $$
->pubobjtype
= PUBLICATIONOBJ_CONTINUATION
;
10669 * If either a row filter or column list is specified, create
10670 * a PublicationTable object.
10675 * The OptWhereClause must be stored here but it is
10676 * valid only for tables. For non-table objects, an
10677 * error will be thrown later via
10678 * preprocess_pubobj_list().
10680 $$
->pubtable
= makeNode
(PublicationTable
);
10681 $$
->pubtable
->relation
= makeRangeVar
(NULL
, $1, @
1);
10682 $$
->pubtable
->columns
= $2;
10683 $$
->pubtable
->whereClause
= $3;
10691 | ColId indirection opt_column_list OptWhereClause
10693 $$
= makeNode
(PublicationObjSpec
);
10694 $$
->pubobjtype
= PUBLICATIONOBJ_CONTINUATION
;
10695 $$
->pubtable
= makeNode
(PublicationTable
);
10696 $$
->pubtable
->relation
= makeRangeVarFromQualifiedName
($1, $2, @
1, yyscanner
);
10697 $$
->pubtable
->columns
= $3;
10698 $$
->pubtable
->whereClause
= $4;
10701 /* grammar like tablename * , ONLY tablename, ONLY ( tablename ) */
10702 | extended_relation_expr opt_column_list OptWhereClause
10704 $$
= makeNode
(PublicationObjSpec
);
10705 $$
->pubobjtype
= PUBLICATIONOBJ_CONTINUATION
;
10706 $$
->pubtable
= makeNode
(PublicationTable
);
10707 $$
->pubtable
->relation
= $1;
10708 $$
->pubtable
->columns
= $2;
10709 $$
->pubtable
->whereClause
= $3;
10713 $$
= makeNode
(PublicationObjSpec
);
10714 $$
->pubobjtype
= PUBLICATIONOBJ_CONTINUATION
;
10719 pub_obj_list: PublicationObjSpec
10720 { $$
= list_make1
($1); }
10721 | pub_obj_list
',' PublicationObjSpec
10722 { $$
= lappend
($1, $3); }
10725 /*****************************************************************************
10727 * ALTER PUBLICATION name SET ( options )
10729 * ALTER PUBLICATION name ADD pub_obj [, ...]
10731 * ALTER PUBLICATION name DROP pub_obj [, ...]
10733 * ALTER PUBLICATION name SET pub_obj [, ...]
10735 * pub_obj is one of:
10737 * TABLE table_name [, ...]
10738 * TABLES IN SCHEMA schema_name [, ...]
10740 *****************************************************************************/
10742 AlterPublicationStmt:
10743 ALTER PUBLICATION name SET definition
10745 AlterPublicationStmt
*n
= makeNode
(AlterPublicationStmt
);
10751 | ALTER PUBLICATION name ADD_P pub_obj_list
10753 AlterPublicationStmt
*n
= makeNode
(AlterPublicationStmt
);
10756 n
->pubobjects
= $5;
10757 preprocess_pubobj_list
(n
->pubobjects
, yyscanner
);
10758 n
->action
= AP_AddObjects
;
10761 | ALTER PUBLICATION name SET pub_obj_list
10763 AlterPublicationStmt
*n
= makeNode
(AlterPublicationStmt
);
10766 n
->pubobjects
= $5;
10767 preprocess_pubobj_list
(n
->pubobjects
, yyscanner
);
10768 n
->action
= AP_SetObjects
;
10771 | ALTER PUBLICATION name DROP pub_obj_list
10773 AlterPublicationStmt
*n
= makeNode
(AlterPublicationStmt
);
10776 n
->pubobjects
= $5;
10777 preprocess_pubobj_list
(n
->pubobjects
, yyscanner
);
10778 n
->action
= AP_DropObjects
;
10783 /*****************************************************************************
10785 * CREATE SUBSCRIPTION name ...
10787 *****************************************************************************/
10789 CreateSubscriptionStmt:
10790 CREATE SUBSCRIPTION name CONNECTION Sconst PUBLICATION name_list opt_definition
10792 CreateSubscriptionStmt
*n
=
10793 makeNode
(CreateSubscriptionStmt
);
10796 n
->publication
= $7;
10802 /*****************************************************************************
10804 * ALTER SUBSCRIPTION name ...
10806 *****************************************************************************/
10808 AlterSubscriptionStmt:
10809 ALTER SUBSCRIPTION name SET definition
10811 AlterSubscriptionStmt
*n
=
10812 makeNode
(AlterSubscriptionStmt
);
10814 n
->kind
= ALTER_SUBSCRIPTION_OPTIONS
;
10819 | ALTER SUBSCRIPTION name CONNECTION Sconst
10821 AlterSubscriptionStmt
*n
=
10822 makeNode
(AlterSubscriptionStmt
);
10824 n
->kind
= ALTER_SUBSCRIPTION_CONNECTION
;
10829 | ALTER SUBSCRIPTION name REFRESH PUBLICATION opt_definition
10831 AlterSubscriptionStmt
*n
=
10832 makeNode
(AlterSubscriptionStmt
);
10834 n
->kind
= ALTER_SUBSCRIPTION_REFRESH
;
10839 | ALTER SUBSCRIPTION name ADD_P PUBLICATION name_list opt_definition
10841 AlterSubscriptionStmt
*n
=
10842 makeNode
(AlterSubscriptionStmt
);
10844 n
->kind
= ALTER_SUBSCRIPTION_ADD_PUBLICATION
;
10846 n
->publication
= $6;
10850 | ALTER SUBSCRIPTION name DROP PUBLICATION name_list opt_definition
10852 AlterSubscriptionStmt
*n
=
10853 makeNode
(AlterSubscriptionStmt
);
10855 n
->kind
= ALTER_SUBSCRIPTION_DROP_PUBLICATION
;
10857 n
->publication
= $6;
10861 | ALTER SUBSCRIPTION name SET PUBLICATION name_list opt_definition
10863 AlterSubscriptionStmt
*n
=
10864 makeNode
(AlterSubscriptionStmt
);
10866 n
->kind
= ALTER_SUBSCRIPTION_SET_PUBLICATION
;
10868 n
->publication
= $6;
10872 | ALTER SUBSCRIPTION name ENABLE_P
10874 AlterSubscriptionStmt
*n
=
10875 makeNode
(AlterSubscriptionStmt
);
10877 n
->kind
= ALTER_SUBSCRIPTION_ENABLED
;
10879 n
->options
= list_make1
(makeDefElem
("enabled",
10880 (Node
*) makeBoolean
(true
), @
1));
10883 | ALTER SUBSCRIPTION name DISABLE_P
10885 AlterSubscriptionStmt
*n
=
10886 makeNode
(AlterSubscriptionStmt
);
10888 n
->kind
= ALTER_SUBSCRIPTION_ENABLED
;
10890 n
->options
= list_make1
(makeDefElem
("enabled",
10891 (Node
*) makeBoolean
(false
), @
1));
10894 | ALTER SUBSCRIPTION name SKIP definition
10896 AlterSubscriptionStmt
*n
=
10897 makeNode
(AlterSubscriptionStmt
);
10899 n
->kind
= ALTER_SUBSCRIPTION_SKIP
;
10906 /*****************************************************************************
10908 * DROP SUBSCRIPTION [ IF EXISTS ] name
10910 *****************************************************************************/
10912 DropSubscriptionStmt: DROP SUBSCRIPTION name opt_drop_behavior
10914 DropSubscriptionStmt
*n
= makeNode
(DropSubscriptionStmt
);
10917 n
->missing_ok
= false
;
10921 | DROP SUBSCRIPTION IF_P EXISTS name opt_drop_behavior
10923 DropSubscriptionStmt
*n
= makeNode
(DropSubscriptionStmt
);
10926 n
->missing_ok
= true
;
10932 /*****************************************************************************
10934 * QUERY: Define Rewrite Rule
10936 *****************************************************************************/
10938 RuleStmt: CREATE opt_or_replace RULE name AS
10939 ON event TO qualified_name where_clause
10940 DO opt_instead RuleActionList
10942 RuleStmt
*n
= makeNode
(RuleStmt
);
10947 n
->whereClause
= $10;
10956 NOTHING
{ $$
= NIL
; }
10957 | RuleActionStmt
{ $$
= list_make1
($1); }
10958 |
'(' RuleActionMulti
')' { $$
= $2; }
10961 /* the thrashing around here is to discard "empty" statements... */
10963 RuleActionMulti
';' RuleActionStmtOrEmpty
10965 $$
= lappend
($1, $3);
10969 | RuleActionStmtOrEmpty
10971 $$
= list_make1
($1);
10985 RuleActionStmtOrEmpty:
10986 RuleActionStmt
{ $$
= $1; }
10987 |
/*EMPTY*/ { $$
= NULL
; }
10990 event: SELECT
{ $$
= CMD_SELECT
; }
10991 | UPDATE
{ $$
= CMD_UPDATE
; }
10992 | DELETE_P
{ $$
= CMD_DELETE
; }
10993 | INSERT
{ $$
= CMD_INSERT
; }
10997 INSTEAD
{ $$
= true
; }
10998 | ALSO
{ $$
= false
; }
10999 |
/*EMPTY*/ { $$
= false
; }
11003 /*****************************************************************************
11006 * NOTIFY <identifier> can appear both in rule bodies and
11007 * as a query-level command
11009 *****************************************************************************/
11011 NotifyStmt: NOTIFY ColId notify_payload
11013 NotifyStmt
*n
= makeNode
(NotifyStmt
);
11015 n
->conditionname
= $2;
11022 ',' Sconst
{ $$
= $2; }
11023 |
/*EMPTY*/ { $$
= NULL
; }
11026 ListenStmt: LISTEN ColId
11028 ListenStmt
*n
= makeNode
(ListenStmt
);
11030 n
->conditionname
= $2;
11038 UnlistenStmt
*n
= makeNode
(UnlistenStmt
);
11040 n
->conditionname
= $2;
11045 UnlistenStmt
*n
= makeNode
(UnlistenStmt
);
11047 n
->conditionname
= NULL
;
11053 /*****************************************************************************
11057 * BEGIN / COMMIT / ROLLBACK
11058 * (also older versions END / ABORT)
11060 *****************************************************************************/
11063 ABORT_P opt_transaction opt_transaction_chain
11065 TransactionStmt
*n
= makeNode
(TransactionStmt
);
11067 n
->kind
= TRANS_STMT_ROLLBACK
;
11073 | START TRANSACTION transaction_mode_list_or_empty
11075 TransactionStmt
*n
= makeNode
(TransactionStmt
);
11077 n
->kind
= TRANS_STMT_START
;
11082 | COMMIT opt_transaction opt_transaction_chain
11084 TransactionStmt
*n
= makeNode
(TransactionStmt
);
11086 n
->kind
= TRANS_STMT_COMMIT
;
11092 | ROLLBACK opt_transaction opt_transaction_chain
11094 TransactionStmt
*n
= makeNode
(TransactionStmt
);
11096 n
->kind
= TRANS_STMT_ROLLBACK
;
11104 TransactionStmt
*n
= makeNode
(TransactionStmt
);
11106 n
->kind
= TRANS_STMT_SAVEPOINT
;
11107 n
->savepoint_name
= $2;
11111 | RELEASE SAVEPOINT ColId
11113 TransactionStmt
*n
= makeNode
(TransactionStmt
);
11115 n
->kind
= TRANS_STMT_RELEASE
;
11116 n
->savepoint_name
= $3;
11122 TransactionStmt
*n
= makeNode
(TransactionStmt
);
11124 n
->kind
= TRANS_STMT_RELEASE
;
11125 n
->savepoint_name
= $2;
11129 | ROLLBACK opt_transaction TO SAVEPOINT ColId
11131 TransactionStmt
*n
= makeNode
(TransactionStmt
);
11133 n
->kind
= TRANS_STMT_ROLLBACK_TO
;
11134 n
->savepoint_name
= $5;
11138 | ROLLBACK opt_transaction TO ColId
11140 TransactionStmt
*n
= makeNode
(TransactionStmt
);
11142 n
->kind
= TRANS_STMT_ROLLBACK_TO
;
11143 n
->savepoint_name
= $4;
11147 | PREPARE TRANSACTION Sconst
11149 TransactionStmt
*n
= makeNode
(TransactionStmt
);
11151 n
->kind
= TRANS_STMT_PREPARE
;
11156 | COMMIT PREPARED Sconst
11158 TransactionStmt
*n
= makeNode
(TransactionStmt
);
11160 n
->kind
= TRANS_STMT_COMMIT_PREPARED
;
11165 | ROLLBACK PREPARED Sconst
11167 TransactionStmt
*n
= makeNode
(TransactionStmt
);
11169 n
->kind
= TRANS_STMT_ROLLBACK_PREPARED
;
11176 TransactionStmtLegacy:
11177 BEGIN_P opt_transaction transaction_mode_list_or_empty
11179 TransactionStmt
*n
= makeNode
(TransactionStmt
);
11181 n
->kind
= TRANS_STMT_BEGIN
;
11186 | END_P opt_transaction opt_transaction_chain
11188 TransactionStmt
*n
= makeNode
(TransactionStmt
);
11190 n
->kind
= TRANS_STMT_COMMIT
;
11198 opt_transaction: WORK
11203 transaction_mode_item:
11204 ISOLATION LEVEL iso_level
11205 { $$
= makeDefElem
("transaction_isolation",
11206 makeStringConst
($3, @
3), @
1); }
11208 { $$
= makeDefElem
("transaction_read_only",
11209 makeIntConst
(true
, @
1), @
1); }
11211 { $$
= makeDefElem
("transaction_read_only",
11212 makeIntConst
(false
, @
1), @
1); }
11214 { $$
= makeDefElem
("transaction_deferrable",
11215 makeIntConst
(true
, @
1), @
1); }
11217 { $$
= makeDefElem
("transaction_deferrable",
11218 makeIntConst
(false
, @
1), @
1); }
11221 /* Syntax with commas is SQL-spec, without commas is Postgres historical */
11222 transaction_mode_list:
11223 transaction_mode_item
11224 { $$
= list_make1
($1); }
11225 | transaction_mode_list
',' transaction_mode_item
11226 { $$
= lappend
($1, $3); }
11227 | transaction_mode_list transaction_mode_item
11228 { $$
= lappend
($1, $2); }
11231 transaction_mode_list_or_empty:
11232 transaction_mode_list
11237 opt_transaction_chain:
11238 AND CHAIN
{ $$
= true
; }
11239 | AND NO CHAIN
{ $$
= false
; }
11240 |
/* EMPTY */ { $$
= false
; }
11244 /*****************************************************************************
11247 * CREATE [ OR REPLACE ] [ TEMP ] VIEW <viewname> '('target-list ')'
11248 * AS <query> [ WITH [ CASCADED | LOCAL ] CHECK OPTION ]
11250 *****************************************************************************/
11252 ViewStmt: CREATE OptTemp VIEW qualified_name opt_column_list opt_reloptions
11253 AS SelectStmt opt_check_option
11255 ViewStmt
*n
= makeNode
(ViewStmt
);
11258 n
->view
->relpersistence
= $2;
11261 n
->replace
= false
;
11263 n
->withCheckOption
= $9;
11266 | CREATE OR REPLACE OptTemp VIEW qualified_name opt_column_list opt_reloptions
11267 AS SelectStmt opt_check_option
11269 ViewStmt
*n
= makeNode
(ViewStmt
);
11272 n
->view
->relpersistence
= $4;
11277 n
->withCheckOption
= $11;
11280 | CREATE OptTemp RECURSIVE VIEW qualified_name
'(' columnList
')' opt_reloptions
11281 AS SelectStmt opt_check_option
11283 ViewStmt
*n
= makeNode
(ViewStmt
);
11286 n
->view
->relpersistence
= $2;
11288 n
->query
= makeRecursiveViewSelect
(n
->view
->relname
, n
->aliases
, $11);
11289 n
->replace
= false
;
11291 n
->withCheckOption
= $12;
11292 if
(n
->withCheckOption
!= NO_CHECK_OPTION
)
11294 (errcode
(ERRCODE_FEATURE_NOT_SUPPORTED
),
11295 errmsg
("WITH CHECK OPTION not supported on recursive views"),
11296 parser_errposition
(@
12)));
11299 | CREATE OR REPLACE OptTemp RECURSIVE VIEW qualified_name
'(' columnList
')' opt_reloptions
11300 AS SelectStmt opt_check_option
11302 ViewStmt
*n
= makeNode
(ViewStmt
);
11305 n
->view
->relpersistence
= $4;
11307 n
->query
= makeRecursiveViewSelect
(n
->view
->relname
, n
->aliases
, $13);
11310 n
->withCheckOption
= $14;
11311 if
(n
->withCheckOption
!= NO_CHECK_OPTION
)
11313 (errcode
(ERRCODE_FEATURE_NOT_SUPPORTED
),
11314 errmsg
("WITH CHECK OPTION not supported on recursive views"),
11315 parser_errposition
(@
14)));
11321 WITH CHECK OPTION
{ $$
= CASCADED_CHECK_OPTION
; }
11322 | WITH CASCADED CHECK OPTION
{ $$
= CASCADED_CHECK_OPTION
; }
11323 | WITH LOCAL CHECK OPTION
{ $$
= LOCAL_CHECK_OPTION
; }
11324 |
/* EMPTY */ { $$
= NO_CHECK_OPTION
; }
11327 /*****************************************************************************
11332 *****************************************************************************/
11334 LoadStmt: LOAD file_name
11336 LoadStmt
*n
= makeNode
(LoadStmt
);
11344 /*****************************************************************************
11348 *****************************************************************************/
11351 CREATE DATABASE name opt_with createdb_opt_list
11353 CreatedbStmt
*n
= makeNode
(CreatedbStmt
);
11362 createdb_opt_items
{ $$
= $1; }
11363 |
/* EMPTY */ { $$
= NIL
; }
11366 createdb_opt_items:
11367 createdb_opt_item
{ $$
= list_make1
($1); }
11368 | createdb_opt_items createdb_opt_item
{ $$
= lappend
($1, $2); }
11372 createdb_opt_name opt_equal NumericOnly
11374 $$
= makeDefElem
($1, $3, @
1);
11376 | createdb_opt_name opt_equal opt_boolean_or_string
11378 $$
= makeDefElem
($1, (Node
*) makeString
($3), @
1);
11380 | createdb_opt_name opt_equal DEFAULT
11382 $$
= makeDefElem
($1, NULL
, @
1);
11387 * Ideally we'd use ColId here, but that causes shift/reduce conflicts against
11388 * the ALTER DATABASE SET/RESET syntaxes. Instead call out specific keywords
11389 * we need, and allow IDENT so that database option names don't have to be
11390 * parser keywords unless they are already keywords for other reasons.
11392 * XXX this coding technique is fragile since if someone makes a formerly
11393 * non-keyword option name into a keyword and forgets to add it here, the
11394 * option will silently break. Best defense is to provide a regression test
11395 * exercising every such option, at least at the syntax level.
11399 | CONNECTION LIMIT
{ $$
= pstrdup
("connection_limit"); }
11400 | ENCODING
{ $$
= pstrdup
($1); }
11401 | LOCATION
{ $$
= pstrdup
($1); }
11402 | OWNER
{ $$
= pstrdup
($1); }
11403 | TABLESPACE
{ $$
= pstrdup
($1); }
11404 | TEMPLATE
{ $$
= pstrdup
($1); }
11408 * Though the equals sign doesn't match other WITH options, pg_dump uses
11409 * equals for backward compatibility, and it doesn't seem worth removing it.
11416 /*****************************************************************************
11420 *****************************************************************************/
11423 ALTER DATABASE name WITH createdb_opt_list
11425 AlterDatabaseStmt
*n
= makeNode
(AlterDatabaseStmt
);
11431 | ALTER DATABASE name createdb_opt_list
11433 AlterDatabaseStmt
*n
= makeNode
(AlterDatabaseStmt
);
11439 | ALTER DATABASE name SET TABLESPACE name
11441 AlterDatabaseStmt
*n
= makeNode
(AlterDatabaseStmt
);
11444 n
->options
= list_make1
(makeDefElem
("tablespace",
11445 (Node
*) makeString
($6), @
6));
11448 | ALTER DATABASE name REFRESH COLLATION VERSION_P
11450 AlterDatabaseRefreshCollStmt
*n
= makeNode
(AlterDatabaseRefreshCollStmt
);
11457 AlterDatabaseSetStmt:
11458 ALTER DATABASE name SetResetClause
11460 AlterDatabaseSetStmt
*n
= makeNode
(AlterDatabaseSetStmt
);
11469 /*****************************************************************************
11471 * DROP DATABASE [ IF EXISTS ] dbname [ [ WITH ] ( options ) ]
11473 * This is implicitly CASCADE, no need for drop behavior
11474 *****************************************************************************/
11476 DropdbStmt: DROP DATABASE name
11478 DropdbStmt
*n
= makeNode
(DropdbStmt
);
11481 n
->missing_ok
= false
;
11485 | DROP DATABASE IF_P EXISTS name
11487 DropdbStmt
*n
= makeNode
(DropdbStmt
);
11490 n
->missing_ok
= true
;
11494 | DROP DATABASE name opt_with
'(' drop_option_list
')'
11496 DropdbStmt
*n
= makeNode
(DropdbStmt
);
11499 n
->missing_ok
= false
;
11503 | DROP DATABASE IF_P EXISTS name opt_with
'(' drop_option_list
')'
11505 DropdbStmt
*n
= makeNode
(DropdbStmt
);
11508 n
->missing_ok
= true
;
11517 $$
= list_make1
((Node
*) $1);
11519 | drop_option_list
',' drop_option
11521 $$
= lappend
($1, (Node
*) $3);
11526 * Currently only the FORCE option is supported, but the syntax is designed
11527 * to be extensible so that we can add more options in the future if required.
11532 $$
= makeDefElem
("force", NULL
, @
1);
11536 /*****************************************************************************
11540 *****************************************************************************/
11542 AlterCollationStmt: ALTER COLLATION any_name REFRESH VERSION_P
11544 AlterCollationStmt
*n
= makeNode
(AlterCollationStmt
);
11552 /*****************************************************************************
11556 * This is used to change configuration parameters persistently.
11557 *****************************************************************************/
11560 ALTER SYSTEM_P SET generic_set
11562 AlterSystemStmt
*n
= makeNode
(AlterSystemStmt
);
11567 | ALTER SYSTEM_P RESET generic_reset
11569 AlterSystemStmt
*n
= makeNode
(AlterSystemStmt
);
11577 /*****************************************************************************
11579 * Manipulate a domain
11581 *****************************************************************************/
11584 CREATE DOMAIN_P any_name opt_as Typename ColQualList
11586 CreateDomainStmt
*n
= makeNode
(CreateDomainStmt
);
11588 n
->domainname
= $3;
11590 SplitColQualList
($6, &n
->constraints
, &n
->collClause
,
11597 /* ALTER DOMAIN <domain> {SET DEFAULT <expr>|DROP DEFAULT} */
11598 ALTER DOMAIN_P any_name alter_column_default
11600 AlterDomainStmt
*n
= makeNode
(AlterDomainStmt
);
11607 /* ALTER DOMAIN <domain> DROP NOT NULL */
11608 | ALTER DOMAIN_P any_name DROP NOT NULL_P
11610 AlterDomainStmt
*n
= makeNode
(AlterDomainStmt
);
11616 /* ALTER DOMAIN <domain> SET NOT NULL */
11617 | ALTER DOMAIN_P any_name SET NOT NULL_P
11619 AlterDomainStmt
*n
= makeNode
(AlterDomainStmt
);
11625 /* ALTER DOMAIN <domain> ADD CONSTRAINT ... */
11626 | ALTER DOMAIN_P any_name ADD_P DomainConstraint
11628 AlterDomainStmt
*n
= makeNode
(AlterDomainStmt
);
11635 /* ALTER DOMAIN <domain> DROP CONSTRAINT <name> [RESTRICT|CASCADE] */
11636 | ALTER DOMAIN_P any_name DROP CONSTRAINT name opt_drop_behavior
11638 AlterDomainStmt
*n
= makeNode
(AlterDomainStmt
);
11644 n
->missing_ok
= false
;
11647 /* ALTER DOMAIN <domain> DROP CONSTRAINT IF EXISTS <name> [RESTRICT|CASCADE] */
11648 | ALTER DOMAIN_P any_name DROP CONSTRAINT IF_P EXISTS name opt_drop_behavior
11650 AlterDomainStmt
*n
= makeNode
(AlterDomainStmt
);
11656 n
->missing_ok
= true
;
11659 /* ALTER DOMAIN <domain> VALIDATE CONSTRAINT <name> */
11660 | ALTER DOMAIN_P any_name VALIDATE CONSTRAINT name
11662 AlterDomainStmt
*n
= makeNode
(AlterDomainStmt
);
11676 /*****************************************************************************
11678 * Manipulate a text search dictionary or configuration
11680 *****************************************************************************/
11682 AlterTSDictionaryStmt:
11683 ALTER TEXT_P SEARCH DICTIONARY any_name definition
11685 AlterTSDictionaryStmt
*n
= makeNode
(AlterTSDictionaryStmt
);
11693 AlterTSConfigurationStmt:
11694 ALTER TEXT_P SEARCH CONFIGURATION any_name ADD_P MAPPING FOR name_list any_with any_name_list
11696 AlterTSConfigurationStmt
*n
= makeNode
(AlterTSConfigurationStmt
);
11698 n
->kind
= ALTER_TSCONFIG_ADD_MAPPING
;
11702 n
->override
= false
;
11703 n
->replace
= false
;
11706 | ALTER TEXT_P SEARCH CONFIGURATION any_name ALTER MAPPING FOR name_list any_with any_name_list
11708 AlterTSConfigurationStmt
*n
= makeNode
(AlterTSConfigurationStmt
);
11710 n
->kind
= ALTER_TSCONFIG_ALTER_MAPPING_FOR_TOKEN
;
11714 n
->override
= true
;
11715 n
->replace
= false
;
11718 | ALTER TEXT_P SEARCH CONFIGURATION any_name ALTER MAPPING REPLACE any_name any_with any_name
11720 AlterTSConfigurationStmt
*n
= makeNode
(AlterTSConfigurationStmt
);
11722 n
->kind
= ALTER_TSCONFIG_REPLACE_DICT
;
11724 n
->tokentype
= NIL
;
11725 n
->dicts
= list_make2
($9,$11);
11726 n
->override
= false
;
11730 | ALTER TEXT_P SEARCH CONFIGURATION any_name ALTER MAPPING FOR name_list REPLACE any_name any_with any_name
11732 AlterTSConfigurationStmt
*n
= makeNode
(AlterTSConfigurationStmt
);
11734 n
->kind
= ALTER_TSCONFIG_REPLACE_DICT_FOR_TOKEN
;
11737 n
->dicts
= list_make2
($11,$13);
11738 n
->override
= false
;
11742 | ALTER TEXT_P SEARCH CONFIGURATION any_name DROP MAPPING FOR name_list
11744 AlterTSConfigurationStmt
*n
= makeNode
(AlterTSConfigurationStmt
);
11746 n
->kind
= ALTER_TSCONFIG_DROP_MAPPING
;
11749 n
->missing_ok
= false
;
11752 | ALTER TEXT_P SEARCH CONFIGURATION any_name DROP MAPPING IF_P EXISTS FOR name_list
11754 AlterTSConfigurationStmt
*n
= makeNode
(AlterTSConfigurationStmt
);
11756 n
->kind
= ALTER_TSCONFIG_DROP_MAPPING
;
11758 n
->tokentype
= $11;
11759 n
->missing_ok
= true
;
11764 /* Use this if TIME or ORDINALITY after WITH should be taken as an identifier */
11770 /*****************************************************************************
11772 * Manipulate a conversion
11774 * CREATE [DEFAULT] CONVERSION <conversion_name>
11775 * FOR <encoding_name> TO <encoding_name> FROM <func_name>
11777 *****************************************************************************/
11779 CreateConversionStmt:
11780 CREATE opt_default CONVERSION_P any_name FOR Sconst
11781 TO Sconst FROM any_name
11783 CreateConversionStmt
*n
= makeNode
(CreateConversionStmt
);
11785 n
->conversion_name
= $4;
11786 n
->for_encoding_name
= $6;
11787 n
->to_encoding_name
= $8;
11788 n
->func_name
= $10;
11794 /*****************************************************************************
11797 * CLUSTER (options) [ <qualified_name> [ USING <index_name> ] ]
11798 * CLUSTER [VERBOSE] [ <qualified_name> [ USING <index_name> ] ]
11799 * CLUSTER [VERBOSE] <index_name> ON <qualified_name> (for pre-8.3)
11801 *****************************************************************************/
11804 CLUSTER
'(' utility_option_list
')' qualified_name cluster_index_specification
11806 ClusterStmt
*n
= makeNode
(ClusterStmt
);
11813 | CLUSTER
'(' utility_option_list
')'
11815 ClusterStmt
*n
= makeNode
(ClusterStmt
);
11817 n
->relation
= NULL
;
11818 n
->indexname
= NULL
;
11822 /* unparenthesized VERBOSE kept for pre-14 compatibility */
11823 | CLUSTER opt_verbose qualified_name cluster_index_specification
11825 ClusterStmt
*n
= makeNode
(ClusterStmt
);
11831 n
->params
= lappend
(n
->params
, makeDefElem
("verbose", NULL
, @
2));
11834 /* unparenthesized VERBOSE kept for pre-17 compatibility */
11835 | CLUSTER opt_verbose
11837 ClusterStmt
*n
= makeNode
(ClusterStmt
);
11839 n
->relation
= NULL
;
11840 n
->indexname
= NULL
;
11843 n
->params
= lappend
(n
->params
, makeDefElem
("verbose", NULL
, @
2));
11846 /* kept for pre-8.3 compatibility */
11847 | CLUSTER opt_verbose name ON qualified_name
11849 ClusterStmt
*n
= makeNode
(ClusterStmt
);
11855 n
->params
= lappend
(n
->params
, makeDefElem
("verbose", NULL
, @
2));
11860 cluster_index_specification:
11861 USING name
{ $$
= $2; }
11862 |
/*EMPTY*/ { $$
= NULL
; }
11866 /*****************************************************************************
11872 *****************************************************************************/
11874 VacuumStmt: VACUUM opt_full opt_freeze opt_verbose opt_analyze opt_vacuum_relation_list
11876 VacuumStmt
*n
= makeNode
(VacuumStmt
);
11880 n
->options
= lappend
(n
->options
,
11881 makeDefElem
("full", NULL
, @
2));
11883 n
->options
= lappend
(n
->options
,
11884 makeDefElem
("freeze", NULL
, @
3));
11886 n
->options
= lappend
(n
->options
,
11887 makeDefElem
("verbose", NULL
, @
4));
11889 n
->options
= lappend
(n
->options
,
11890 makeDefElem
("analyze", NULL
, @
5));
11892 n
->is_vacuumcmd
= true
;
11895 | VACUUM
'(' utility_option_list
')' opt_vacuum_relation_list
11897 VacuumStmt
*n
= makeNode
(VacuumStmt
);
11901 n
->is_vacuumcmd
= true
;
11906 AnalyzeStmt: analyze_keyword opt_verbose opt_vacuum_relation_list
11908 VacuumStmt
*n
= makeNode
(VacuumStmt
);
11912 n
->options
= lappend
(n
->options
,
11913 makeDefElem
("verbose", NULL
, @
2));
11915 n
->is_vacuumcmd
= false
;
11918 | analyze_keyword
'(' utility_option_list
')' opt_vacuum_relation_list
11920 VacuumStmt
*n
= makeNode
(VacuumStmt
);
11924 n
->is_vacuumcmd
= false
;
11929 utility_option_list:
11930 utility_option_elem
11932 $$
= list_make1
($1);
11934 | utility_option_list
',' utility_option_elem
11936 $$
= lappend
($1, $3);
11942 | ANALYSE
/* British */
11945 utility_option_elem:
11946 utility_option_name utility_option_arg
11948 $$
= makeDefElem
($1, $2, @
1);
11952 utility_option_name:
11953 NonReservedWord
{ $$
= $1; }
11954 | analyze_keyword
{ $$
= "analyze"; }
11955 | FORMAT_LA
{ $$
= "format"; }
11958 utility_option_arg:
11959 opt_boolean_or_string
{ $$
= (Node
*) makeString
($1); }
11960 | NumericOnly
{ $$
= (Node
*) $1; }
11961 |
/* EMPTY */ { $$
= NULL
; }
11965 analyze_keyword
{ $$
= true
; }
11966 |
/*EMPTY*/ { $$
= false
; }
11970 VERBOSE
{ $$
= true
; }
11971 |
/*EMPTY*/ { $$
= false
; }
11974 opt_full: FULL
{ $$
= true
; }
11975 |
/*EMPTY*/ { $$
= false
; }
11978 opt_freeze: FREEZE
{ $$
= true
; }
11979 |
/*EMPTY*/ { $$
= false
; }
11983 '(' name_list
')' { $$
= $2; }
11984 |
/*EMPTY*/ { $$
= NIL
; }
11988 relation_expr opt_name_list
11990 $$
= (Node
*) makeVacuumRelation
($1, InvalidOid
, $2);
11994 vacuum_relation_list:
11996 { $$
= list_make1
($1); }
11997 | vacuum_relation_list
',' vacuum_relation
11998 { $$
= lappend
($1, $3); }
12001 opt_vacuum_relation_list:
12002 vacuum_relation_list
{ $$
= $1; }
12003 |
/*EMPTY*/ { $$
= NIL
; }
12007 /*****************************************************************************
12010 * EXPLAIN [ANALYZE] [VERBOSE] query
12011 * EXPLAIN ( options ) query
12013 *****************************************************************************/
12016 EXPLAIN ExplainableStmt
12018 ExplainStmt
*n
= makeNode
(ExplainStmt
);
12024 | EXPLAIN analyze_keyword opt_verbose ExplainableStmt
12026 ExplainStmt
*n
= makeNode
(ExplainStmt
);
12029 n
->options
= list_make1
(makeDefElem
("analyze", NULL
, @
2));
12031 n
->options
= lappend
(n
->options
,
12032 makeDefElem
("verbose", NULL
, @
3));
12035 | EXPLAIN VERBOSE ExplainableStmt
12037 ExplainStmt
*n
= makeNode
(ExplainStmt
);
12040 n
->options
= list_make1
(makeDefElem
("verbose", NULL
, @
2));
12043 | EXPLAIN
'(' utility_option_list
')' ExplainableStmt
12045 ExplainStmt
*n
= makeNode
(ExplainStmt
);
12059 | DeclareCursorStmt
12061 | CreateMatViewStmt
12062 | RefreshMatViewStmt
12063 | ExecuteStmt
/* by default all are $$=$1 */
12066 /*****************************************************************************
12069 * PREPARE <plan_name> [(args, ...)] AS <query>
12071 *****************************************************************************/
12073 PrepareStmt: PREPARE name prep_type_clause AS PreparableStmt
12075 PrepareStmt
*n
= makeNode
(PrepareStmt
);
12084 prep_type_clause: '(' type_list
')' { $$
= $2; }
12085 |
/* EMPTY */ { $$
= NIL
; }
12093 | MergeStmt
/* by default all are $$=$1 */
12096 /*****************************************************************************
12098 * EXECUTE <plan_name> [(params, ...)]
12099 * CREATE TABLE <name> AS EXECUTE <plan_name> [(params, ...)]
12101 *****************************************************************************/
12103 ExecuteStmt: EXECUTE name execute_param_clause
12105 ExecuteStmt
*n
= makeNode
(ExecuteStmt
);
12111 | CREATE OptTemp TABLE create_as_target AS
12112 EXECUTE name execute_param_clause opt_with_data
12114 CreateTableAsStmt
*ctas
= makeNode
(CreateTableAsStmt
);
12115 ExecuteStmt
*n
= makeNode
(ExecuteStmt
);
12119 ctas
->query
= (Node
*) n
;
12121 ctas
->objtype
= OBJECT_TABLE
;
12122 ctas
->is_select_into
= false
;
12123 ctas
->if_not_exists
= false
;
12124 /* cram additional flags into the IntoClause */
12125 $4->rel
->relpersistence
= $2;
12126 $4->skipData
= !($9);
12127 $$
= (Node
*) ctas
;
12129 | CREATE OptTemp TABLE IF_P NOT EXISTS create_as_target AS
12130 EXECUTE name execute_param_clause opt_with_data
12132 CreateTableAsStmt
*ctas
= makeNode
(CreateTableAsStmt
);
12133 ExecuteStmt
*n
= makeNode
(ExecuteStmt
);
12137 ctas
->query
= (Node
*) n
;
12139 ctas
->objtype
= OBJECT_TABLE
;
12140 ctas
->is_select_into
= false
;
12141 ctas
->if_not_exists
= true
;
12142 /* cram additional flags into the IntoClause */
12143 $7->rel
->relpersistence
= $2;
12144 $7->skipData
= !($12);
12145 $$
= (Node
*) ctas
;
12149 execute_param_clause: '(' expr_list
')' { $$
= $2; }
12150 |
/* EMPTY */ { $$
= NIL
; }
12153 /*****************************************************************************
12156 * DEALLOCATE [PREPARE] <plan_name>
12158 *****************************************************************************/
12160 DeallocateStmt: DEALLOCATE name
12162 DeallocateStmt
*n
= makeNode
(DeallocateStmt
);
12169 | DEALLOCATE PREPARE name
12171 DeallocateStmt
*n
= makeNode
(DeallocateStmt
);
12180 DeallocateStmt
*n
= makeNode
(DeallocateStmt
);
12187 | DEALLOCATE PREPARE ALL
12189 DeallocateStmt
*n
= makeNode
(DeallocateStmt
);
12198 /*****************************************************************************
12201 * INSERT STATEMENTS
12203 *****************************************************************************/
12206 opt_with_clause INSERT INTO insert_target insert_rest
12207 opt_on_conflict returning_clause
12210 $5->onConflictClause
= $6;
12211 $5->returningClause
= $7;
12212 $5->withClause
= $1;
12213 $5->stmt_location
= @$
;
12219 * Can't easily make AS optional here, because VALUES in insert_rest would
12220 * have a shift/reduce conflict with VALUES as an optional alias. We could
12221 * easily allow unreserved_keywords as optional aliases, but that'd be an odd
12222 * divergence from other places. So just require AS for now.
12229 | qualified_name AS ColId
12231 $1->alias
= makeAlias
($3, NIL
);
12239 $$
= makeNode
(InsertStmt
);
12241 $$
->selectStmt
= $1;
12243 | OVERRIDING override_kind VALUE_P SelectStmt
12245 $$
= makeNode
(InsertStmt
);
12248 $$
->selectStmt
= $4;
12250 |
'(' insert_column_list
')' SelectStmt
12252 $$
= makeNode
(InsertStmt
);
12254 $$
->selectStmt
= $4;
12256 |
'(' insert_column_list
')' OVERRIDING override_kind VALUE_P SelectStmt
12258 $$
= makeNode
(InsertStmt
);
12261 $$
->selectStmt
= $7;
12265 $$
= makeNode
(InsertStmt
);
12267 $$
->selectStmt
= NULL
;
12272 USER
{ $$
= OVERRIDING_USER_VALUE
; }
12273 | SYSTEM_P
{ $$
= OVERRIDING_SYSTEM_VALUE
; }
12276 insert_column_list:
12278 { $$
= list_make1
($1); }
12279 | insert_column_list
',' insert_column_item
12280 { $$
= lappend
($1, $3); }
12283 insert_column_item:
12284 ColId opt_indirection
12286 $$
= makeNode
(ResTarget
);
12288 $$
->indirection
= check_indirection
($2, yyscanner
);
12295 ON CONFLICT opt_conf_expr DO UPDATE SET set_clause_list where_clause
12297 $$
= makeNode
(OnConflictClause
);
12298 $$
->action
= ONCONFLICT_UPDATE
;
12300 $$
->targetList
= $7;
12301 $$
->whereClause
= $8;
12305 ON CONFLICT opt_conf_expr DO NOTHING
12307 $$
= makeNode
(OnConflictClause
);
12308 $$
->action
= ONCONFLICT_NOTHING
;
12310 $$
->targetList
= NIL
;
12311 $$
->whereClause
= NULL
;
12321 '(' index_params
')' where_clause
12323 $$
= makeNode
(InferClause
);
12324 $$
->indexElems
= $2;
12325 $$
->whereClause
= $4;
12326 $$
->conname
= NULL
;
12332 $$
= makeNode
(InferClause
);
12333 $$
->indexElems
= NIL
;
12334 $$
->whereClause
= NULL
;
12345 RETURNING returning_with_clause target_list
12347 ReturningClause
*n
= makeNode
(ReturningClause
);
12359 returning_with_clause:
12360 WITH
'(' returning_options
')' { $$
= $3; }
12361 |
/* EMPTY */ { $$
= NIL
; }
12365 returning_option
{ $$
= list_make1
($1); }
12366 | returning_options
',' returning_option
{ $$
= lappend
($1, $3); }
12370 returning_option_kind AS ColId
12372 ReturningOption
*n
= makeNode
(ReturningOption
);
12381 returning_option_kind:
12382 OLD
{ $$
= RETURNING_OPTION_OLD
; }
12383 | NEW
{ $$
= RETURNING_OPTION_NEW
; }
12387 /*****************************************************************************
12390 * DELETE STATEMENTS
12392 *****************************************************************************/
12394 DeleteStmt: opt_with_clause DELETE_P FROM relation_expr_opt_alias
12395 using_clause where_or_current_clause returning_clause
12397 DeleteStmt
*n
= makeNode
(DeleteStmt
);
12400 n
->usingClause
= $5;
12401 n
->whereClause
= $6;
12402 n
->returningClause
= $7;
12403 n
->withClause
= $1;
12404 n
->stmt_location
= @$
;
12410 USING from_list
{ $$
= $2; }
12411 |
/*EMPTY*/ { $$
= NIL
; }
12415 /*****************************************************************************
12420 *****************************************************************************/
12422 LockStmt: LOCK_P opt_table relation_expr_list opt_lock opt_nowait
12424 LockStmt
*n
= makeNode
(LockStmt
);
12433 opt_lock: IN_P lock_type MODE
{ $$
= $2; }
12434 |
/*EMPTY*/ { $$
= AccessExclusiveLock
; }
12437 lock_type: ACCESS SHARE
{ $$
= AccessShareLock
; }
12438 | ROW SHARE
{ $$
= RowShareLock
; }
12439 | ROW EXCLUSIVE
{ $$
= RowExclusiveLock
; }
12440 | SHARE UPDATE EXCLUSIVE
{ $$
= ShareUpdateExclusiveLock
; }
12441 | SHARE
{ $$
= ShareLock
; }
12442 | SHARE ROW EXCLUSIVE
{ $$
= ShareRowExclusiveLock
; }
12443 | EXCLUSIVE
{ $$
= ExclusiveLock
; }
12444 | ACCESS EXCLUSIVE
{ $$
= AccessExclusiveLock
; }
12447 opt_nowait: NOWAIT
{ $$
= true
; }
12448 |
/*EMPTY*/ { $$
= false
; }
12451 opt_nowait_or_skip:
12452 NOWAIT
{ $$
= LockWaitError
; }
12453 | SKIP LOCKED
{ $$
= LockWaitSkip
; }
12454 |
/*EMPTY*/ { $$
= LockWaitBlock
; }
12458 /*****************************************************************************
12461 * UpdateStmt (UPDATE)
12463 *****************************************************************************/
12465 UpdateStmt: opt_with_clause UPDATE relation_expr_opt_alias
12466 SET set_clause_list
12468 where_or_current_clause
12471 UpdateStmt
*n
= makeNode
(UpdateStmt
);
12474 n
->targetList
= $5;
12475 n
->fromClause
= $6;
12476 n
->whereClause
= $7;
12477 n
->returningClause
= $8;
12478 n
->withClause
= $1;
12479 n
->stmt_location
= @$
;
12485 set_clause
{ $$
= $1; }
12486 | set_clause_list
',' set_clause
{ $$
= list_concat
($1,$3); }
12490 set_target
'=' a_expr
12492 $1->val
= (Node
*) $3;
12493 $$
= list_make1
($1);
12495 |
'(' set_target_list
')' '=' a_expr
12497 int ncolumns
= list_length
($2);
12499 ListCell
*col_cell
;
12501 /* Create a MultiAssignRef source for each target */
12502 foreach
(col_cell
, $2)
12504 ResTarget
*res_col
= (ResTarget
*) lfirst
(col_cell
);
12505 MultiAssignRef
*r
= makeNode
(MultiAssignRef
);
12507 r
->source
= (Node
*) $5;
12509 r
->ncolumns
= ncolumns
;
12510 res_col
->val
= (Node
*) r
;
12519 ColId opt_indirection
12521 $$
= makeNode
(ResTarget
);
12523 $$
->indirection
= check_indirection
($2, yyscanner
);
12524 $$
->val
= NULL
; /* upper production sets this */
12530 set_target
{ $$
= list_make1
($1); }
12531 | set_target_list
',' set_target
{ $$
= lappend
($1,$3); }
12535 /*****************************************************************************
12540 *****************************************************************************/
12543 opt_with_clause MERGE INTO relation_expr_opt_alias
12549 MergeStmt
*m
= makeNode
(MergeStmt
);
12551 m
->withClause
= $1;
12553 m
->sourceRelation
= $6;
12554 m
->joinCondition
= $8;
12555 m
->mergeWhenClauses
= $9;
12556 m
->returningClause
= $10;
12557 m
->stmt_location
= @$
;
12564 merge_when_clause
{ $$
= list_make1
($1); }
12565 | merge_when_list merge_when_clause
{ $$
= lappend
($1,$2); }
12569 * A WHEN clause may be WHEN MATCHED, WHEN NOT MATCHED BY SOURCE, or WHEN NOT
12570 * MATCHED [BY TARGET]. The first two cases match target tuples, and support
12571 * UPDATE/DELETE/DO NOTHING actions. The third case does not match target
12572 * tuples, and only supports INSERT/DO NOTHING actions.
12575 merge_when_tgt_matched opt_merge_when_condition THEN merge_update
12577 $4->matchKind
= $1;
12578 $4->condition
= $2;
12582 | merge_when_tgt_matched opt_merge_when_condition THEN merge_delete
12584 $4->matchKind
= $1;
12585 $4->condition
= $2;
12589 | merge_when_tgt_not_matched opt_merge_when_condition THEN merge_insert
12591 $4->matchKind
= $1;
12592 $4->condition
= $2;
12596 | merge_when_tgt_matched opt_merge_when_condition THEN DO NOTHING
12598 MergeWhenClause
*m
= makeNode
(MergeWhenClause
);
12601 m
->commandType
= CMD_NOTHING
;
12606 | merge_when_tgt_not_matched opt_merge_when_condition THEN DO NOTHING
12608 MergeWhenClause
*m
= makeNode
(MergeWhenClause
);
12611 m
->commandType
= CMD_NOTHING
;
12618 merge_when_tgt_matched:
12619 WHEN MATCHED
{ $$
= MERGE_WHEN_MATCHED
; }
12620 | WHEN NOT MATCHED BY SOURCE
{ $$
= MERGE_WHEN_NOT_MATCHED_BY_SOURCE
; }
12623 merge_when_tgt_not_matched:
12624 WHEN NOT MATCHED
{ $$
= MERGE_WHEN_NOT_MATCHED_BY_TARGET
; }
12625 | WHEN NOT MATCHED BY TARGET
{ $$
= MERGE_WHEN_NOT_MATCHED_BY_TARGET
; }
12628 opt_merge_when_condition:
12629 AND a_expr
{ $$
= $2; }
12634 UPDATE SET set_clause_list
12636 MergeWhenClause
*n
= makeNode
(MergeWhenClause
);
12637 n
->commandType
= CMD_UPDATE
;
12638 n
->override
= OVERRIDING_NOT_SET
;
12639 n
->targetList
= $3;
12649 MergeWhenClause
*n
= makeNode
(MergeWhenClause
);
12650 n
->commandType
= CMD_DELETE
;
12651 n
->override
= OVERRIDING_NOT_SET
;
12652 n
->targetList
= NIL
;
12660 INSERT merge_values_clause
12662 MergeWhenClause
*n
= makeNode
(MergeWhenClause
);
12663 n
->commandType
= CMD_INSERT
;
12664 n
->override
= OVERRIDING_NOT_SET
;
12665 n
->targetList
= NIL
;
12669 | INSERT OVERRIDING override_kind VALUE_P merge_values_clause
12671 MergeWhenClause
*n
= makeNode
(MergeWhenClause
);
12672 n
->commandType
= CMD_INSERT
;
12674 n
->targetList
= NIL
;
12678 | INSERT
'(' insert_column_list
')' merge_values_clause
12680 MergeWhenClause
*n
= makeNode
(MergeWhenClause
);
12681 n
->commandType
= CMD_INSERT
;
12682 n
->override
= OVERRIDING_NOT_SET
;
12683 n
->targetList
= $3;
12687 | INSERT
'(' insert_column_list
')' OVERRIDING override_kind VALUE_P merge_values_clause
12689 MergeWhenClause
*n
= makeNode
(MergeWhenClause
);
12690 n
->commandType
= CMD_INSERT
;
12692 n
->targetList
= $3;
12696 | INSERT DEFAULT VALUES
12698 MergeWhenClause
*n
= makeNode
(MergeWhenClause
);
12699 n
->commandType
= CMD_INSERT
;
12700 n
->override
= OVERRIDING_NOT_SET
;
12701 n
->targetList
= NIL
;
12707 merge_values_clause:
12708 VALUES
'(' expr_list
')'
12714 /*****************************************************************************
12717 * CURSOR STATEMENTS
12719 *****************************************************************************/
12720 DeclareCursorStmt: DECLARE cursor_name cursor_options CURSOR opt_hold FOR SelectStmt
12722 DeclareCursorStmt
*n
= makeNode
(DeclareCursorStmt
);
12724 n
->portalname
= $2;
12725 /* currently we always set FAST_PLAN option */
12726 n
->options
= $3 |
$5 | CURSOR_OPT_FAST_PLAN
;
12732 cursor_name: name
{ $$
= $1; }
12735 cursor_options: /*EMPTY*/ { $$
= 0; }
12736 | cursor_options NO SCROLL
{ $$
= $1 | CURSOR_OPT_NO_SCROLL
; }
12737 | cursor_options SCROLL
{ $$
= $1 | CURSOR_OPT_SCROLL
; }
12738 | cursor_options BINARY
{ $$
= $1 | CURSOR_OPT_BINARY
; }
12739 | cursor_options ASENSITIVE
{ $$
= $1 | CURSOR_OPT_ASENSITIVE
; }
12740 | cursor_options INSENSITIVE
{ $$
= $1 | CURSOR_OPT_INSENSITIVE
; }
12743 opt_hold: /* EMPTY */ { $$
= 0; }
12744 | WITH HOLD
{ $$
= CURSOR_OPT_HOLD
; }
12745 | WITHOUT HOLD
{ $$
= 0; }
12748 /*****************************************************************************
12751 * SELECT STATEMENTS
12753 *****************************************************************************/
12755 /* A complete SELECT statement looks like this.
12757 * The rule returns either a single SelectStmt node or a tree of them,
12758 * representing a set-operation tree.
12760 * There is an ambiguity when a sub-SELECT is within an a_expr and there
12761 * are excess parentheses: do the parentheses belong to the sub-SELECT or
12762 * to the surrounding a_expr? We don't really care, but bison wants to know.
12763 * To resolve the ambiguity, we are careful to define the grammar so that
12764 * the decision is staved off as long as possible: as long as we can keep
12765 * absorbing parentheses into the sub-SELECT, we will do so, and only when
12766 * it's no longer possible to do that will we decide that parens belong to
12767 * the expression. For example, in "SELECT (((SELECT 2)) + 3)" the extra
12768 * parentheses are treated as part of the sub-select. The necessity of doing
12769 * it that way is shown by "SELECT (((SELECT 2)) UNION SELECT 2)". Had we
12770 * parsed "((SELECT 2))" as an a_expr, it'd be too late to go back to the
12771 * SELECT viewpoint when we see the UNION.
12773 * This approach is implemented by defining a nonterminal select_with_parens,
12774 * which represents a SELECT with at least one outer layer of parentheses,
12775 * and being careful to use select_with_parens, never '(' SelectStmt ')',
12776 * in the expression grammar. We will then have shift-reduce conflicts
12777 * which we can resolve in favor of always treating '(' <select> ')' as
12778 * a select_with_parens. To resolve the conflicts, the productions that
12779 * conflict with the select_with_parens productions are manually given
12780 * precedences lower than the precedence of ')', thereby ensuring that we
12781 * shift ')' (and then reduce to select_with_parens) rather than trying to
12782 * reduce the inner <select> nonterminal to something else. We use UMINUS
12783 * precedence for this, which is a fairly arbitrary choice.
12785 * To be able to define select_with_parens itself without ambiguity, we need
12786 * a nonterminal select_no_parens that represents a SELECT structure with no
12787 * outermost parentheses. This is a little bit tedious, but it works.
12789 * In non-expression contexts, we use SelectStmt which can represent a SELECT
12790 * with or without outer parentheses.
12793 SelectStmt: select_no_parens %prec UMINUS
12794 | select_with_parens %prec UMINUS
12797 select_with_parens:
12798 '(' select_no_parens
')'
12800 SelectStmt
*n
= (SelectStmt
*) $2;
12803 * As SelectStmt's location starts at the SELECT keyword,
12804 * we need to track the length of the SelectStmt within
12805 * parentheses to be able to extract the relevant part
12806 * of the query. Without this, the RawStmt's length would
12807 * be used and would include the closing parenthesis.
12809 n
->stmt_len
= @
3 - @
2;
12812 |
'(' select_with_parens
')' { $$
= $2; }
12816 * This rule parses the equivalent of the standard's <query expression>.
12817 * The duplicative productions are annoying, but hard to get rid of without
12818 * creating shift/reduce conflicts.
12820 * The locking clause (FOR UPDATE etc) may be before or after LIMIT/OFFSET.
12821 * In <=7.2.X, LIMIT/OFFSET had to be after FOR UPDATE
12822 * We now support both orderings, but prefer LIMIT/OFFSET before the locking
12827 simple_select
{ $$
= $1; }
12828 | select_clause sort_clause
12830 insertSelectOptions
((SelectStmt
*) $1, $2, NIL
,
12835 | select_clause opt_sort_clause for_locking_clause opt_select_limit
12837 insertSelectOptions
((SelectStmt
*) $1, $2, $3,
12843 | select_clause opt_sort_clause select_limit opt_for_locking_clause
12845 insertSelectOptions
((SelectStmt
*) $1, $2, $4,
12851 | with_clause select_clause
12853 insertSelectOptions
((SelectStmt
*) $2, NULL
, NIL
,
12859 | with_clause select_clause sort_clause
12861 insertSelectOptions
((SelectStmt
*) $2, $3, NIL
,
12867 | with_clause select_clause opt_sort_clause for_locking_clause opt_select_limit
12869 insertSelectOptions
((SelectStmt
*) $2, $3, $4,
12875 | with_clause select_clause opt_sort_clause select_limit opt_for_locking_clause
12877 insertSelectOptions
((SelectStmt
*) $2, $3, $5,
12886 simple_select
{ $$
= $1; }
12887 | select_with_parens
{ $$
= $1; }
12891 * This rule parses SELECT statements that can appear within set operations,
12892 * including UNION, INTERSECT and EXCEPT. '(' and ')' can be used to specify
12893 * the ordering of the set operations. Without '(' and ')' we want the
12894 * operations to be ordered per the precedence specs at the head of this file.
12896 * As with select_no_parens, simple_select cannot have outer parentheses,
12897 * but can have parenthesized subclauses.
12899 * It might appear that we could fold the first two alternatives into one
12900 * by using opt_distinct_clause. However, that causes a shift/reduce conflict
12901 * against INSERT ... SELECT ... ON CONFLICT. We avoid the ambiguity by
12902 * requiring SELECT DISTINCT [ON] to be followed by a non-empty target_list.
12904 * Note that sort clauses cannot be included at this level --- SQL requires
12905 * SELECT foo UNION SELECT bar ORDER BY baz
12907 * (SELECT foo UNION SELECT bar) ORDER BY baz
12909 * SELECT foo UNION (SELECT bar ORDER BY baz)
12910 * Likewise for WITH, FOR UPDATE and LIMIT. Therefore, those clauses are
12911 * described as part of the select_no_parens production, not simple_select.
12912 * This does not limit functionality, because you can reintroduce these
12913 * clauses inside parentheses.
12915 * NOTE: only the leftmost component SelectStmt should have INTO.
12916 * However, this is not checked by the grammar; parse analysis must check it.
12919 SELECT opt_all_clause opt_target_list
12920 into_clause from_clause where_clause
12921 group_clause having_clause window_clause
12923 SelectStmt
*n
= makeNode
(SelectStmt
);
12925 n
->targetList
= $3;
12926 n
->intoClause
= $4;
12927 n
->fromClause
= $5;
12928 n
->whereClause
= $6;
12929 n
->groupClause
= ($7)->list
;
12930 n
->groupDistinct
= ($7)->distinct
;
12931 n
->havingClause
= $8;
12932 n
->windowClause
= $9;
12933 n
->stmt_location
= @
1;
12936 | SELECT distinct_clause target_list
12937 into_clause from_clause where_clause
12938 group_clause having_clause window_clause
12940 SelectStmt
*n
= makeNode
(SelectStmt
);
12942 n
->distinctClause
= $2;
12943 n
->targetList
= $3;
12944 n
->intoClause
= $4;
12945 n
->fromClause
= $5;
12946 n
->whereClause
= $6;
12947 n
->groupClause
= ($7)->list
;
12948 n
->groupDistinct
= ($7)->distinct
;
12949 n
->havingClause
= $8;
12950 n
->windowClause
= $9;
12951 n
->stmt_location
= @
1;
12954 | values_clause
{ $$
= $1; }
12955 | TABLE relation_expr
12957 /* same as SELECT * FROM relation_expr */
12958 ColumnRef
*cr
= makeNode
(ColumnRef
);
12959 ResTarget
*rt
= makeNode
(ResTarget
);
12960 SelectStmt
*n
= makeNode
(SelectStmt
);
12962 cr
->fields
= list_make1
(makeNode
(A_Star
));
12966 rt
->indirection
= NIL
;
12967 rt
->val
= (Node
*) cr
;
12970 n
->targetList
= list_make1
(rt
);
12971 n
->fromClause
= list_make1
($2);
12972 n
->stmt_location
= @
1;
12975 | select_clause UNION set_quantifier select_clause
12977 $$
= makeSetOp
(SETOP_UNION
, $3 == SET_QUANTIFIER_ALL
, $1, $4, @
1);
12979 | select_clause INTERSECT set_quantifier select_clause
12981 $$
= makeSetOp
(SETOP_INTERSECT
, $3 == SET_QUANTIFIER_ALL
, $1, $4, @
1);
12983 | select_clause EXCEPT set_quantifier select_clause
12985 $$
= makeSetOp
(SETOP_EXCEPT
, $3 == SET_QUANTIFIER_ALL
, $1, $4, @
1);
12990 * SQL standard WITH clause looks like:
12992 * WITH [ RECURSIVE ] <query name> [ (<column>,...) ]
12993 * AS (query) [ SEARCH or CYCLE clause ]
12995 * Recognizing WITH_LA here allows a CTE to be named TIME or ORDINALITY.
13000 $$
= makeNode
(WithClause
);
13002 $$
->recursive
= false
;
13007 $$
= makeNode
(WithClause
);
13009 $$
->recursive
= false
;
13012 | WITH RECURSIVE cte_list
13014 $$
= makeNode
(WithClause
);
13016 $$
->recursive
= true
;
13022 common_table_expr
{ $$
= list_make1
($1); }
13023 | cte_list
',' common_table_expr
{ $$
= lappend
($1, $3); }
13026 common_table_expr: name opt_name_list AS opt_materialized
'(' PreparableStmt
')' opt_search_clause opt_cycle_clause
13028 CommonTableExpr
*n
= makeNode
(CommonTableExpr
);
13031 n
->aliascolnames
= $2;
13032 n
->ctematerialized
= $4;
13034 n
->search_clause
= castNode
(CTESearchClause
, $8);
13035 n
->cycle_clause
= castNode
(CTECycleClause
, $9);
13042 MATERIALIZED
{ $$
= CTEMaterializeAlways
; }
13043 | NOT MATERIALIZED
{ $$
= CTEMaterializeNever
; }
13044 |
/*EMPTY*/ { $$
= CTEMaterializeDefault
; }
13048 SEARCH DEPTH FIRST_P BY columnList SET ColId
13050 CTESearchClause
*n
= makeNode
(CTESearchClause
);
13052 n
->search_col_list
= $5;
13053 n
->search_breadth_first
= false
;
13054 n
->search_seq_column
= $7;
13058 | SEARCH BREADTH FIRST_P BY columnList SET ColId
13060 CTESearchClause
*n
= makeNode
(CTESearchClause
);
13062 n
->search_col_list
= $5;
13063 n
->search_breadth_first
= true
;
13064 n
->search_seq_column
= $7;
13075 CYCLE columnList SET ColId TO AexprConst DEFAULT AexprConst USING ColId
13077 CTECycleClause
*n
= makeNode
(CTECycleClause
);
13079 n
->cycle_col_list
= $2;
13080 n
->cycle_mark_column
= $4;
13081 n
->cycle_mark_value
= $6;
13082 n
->cycle_mark_default
= $8;
13083 n
->cycle_path_column
= $10;
13087 | CYCLE columnList SET ColId USING ColId
13089 CTECycleClause
*n
= makeNode
(CTECycleClause
);
13091 n
->cycle_col_list
= $2;
13092 n
->cycle_mark_column
= $4;
13093 n
->cycle_mark_value
= makeBoolAConst
(true
, -1);
13094 n
->cycle_mark_default
= makeBoolAConst
(false
, -1);
13095 n
->cycle_path_column
= $6;
13106 with_clause
{ $$
= $1; }
13107 |
/*EMPTY*/ { $$
= NULL
; }
13111 INTO OptTempTableName
13113 $$
= makeNode
(IntoClause
);
13115 $$
->colNames
= NIL
;
13117 $$
->onCommit
= ONCOMMIT_NOOP
;
13118 $$
->tableSpaceName
= NULL
;
13119 $$
->viewQuery
= NULL
;
13120 $$
->skipData
= false
;
13127 * Redundancy here is needed to avoid shift/reduce conflicts,
13128 * since TEMP is not a reserved word. See also OptTemp.
13131 TEMPORARY opt_table qualified_name
13134 $$
->relpersistence
= RELPERSISTENCE_TEMP
;
13136 | TEMP opt_table qualified_name
13139 $$
->relpersistence
= RELPERSISTENCE_TEMP
;
13141 | LOCAL TEMPORARY opt_table qualified_name
13144 $$
->relpersistence
= RELPERSISTENCE_TEMP
;
13146 | LOCAL TEMP opt_table qualified_name
13149 $$
->relpersistence
= RELPERSISTENCE_TEMP
;
13151 | GLOBAL TEMPORARY opt_table qualified_name
13154 (errmsg
("GLOBAL is deprecated in temporary table creation"),
13155 parser_errposition
(@
1)));
13157 $$
->relpersistence
= RELPERSISTENCE_TEMP
;
13159 | GLOBAL TEMP opt_table qualified_name
13162 (errmsg
("GLOBAL is deprecated in temporary table creation"),
13163 parser_errposition
(@
1)));
13165 $$
->relpersistence
= RELPERSISTENCE_TEMP
;
13167 | UNLOGGED opt_table qualified_name
13170 $$
->relpersistence
= RELPERSISTENCE_UNLOGGED
;
13172 | TABLE qualified_name
13175 $$
->relpersistence
= RELPERSISTENCE_PERMANENT
;
13180 $$
->relpersistence
= RELPERSISTENCE_PERMANENT
;
13189 ALL
{ $$
= SET_QUANTIFIER_ALL
; }
13190 | DISTINCT
{ $$
= SET_QUANTIFIER_DISTINCT
; }
13191 |
/*EMPTY*/ { $$
= SET_QUANTIFIER_DEFAULT
; }
13194 /* We use (NIL) as a placeholder to indicate that all target expressions
13195 * should be placed in the DISTINCT list during parsetree analysis.
13198 DISTINCT
{ $$
= list_make1
(NIL
); }
13199 | DISTINCT ON
'(' expr_list
')' { $$
= $4; }
13207 opt_distinct_clause:
13208 distinct_clause
{ $$
= $1; }
13209 | opt_all_clause
{ $$
= NIL
; }
13213 sort_clause
{ $$
= $1; }
13214 |
/*EMPTY*/ { $$
= NIL
; }
13218 ORDER BY sortby_list
{ $$
= $3; }
13222 sortby
{ $$
= list_make1
($1); }
13223 | sortby_list
',' sortby
{ $$
= lappend
($1, $3); }
13226 sortby: a_expr USING qual_all_Op opt_nulls_order
13228 $$
= makeNode
(SortBy
);
13230 $$
->sortby_dir
= SORTBY_USING
;
13231 $$
->sortby_nulls
= $4;
13235 | a_expr opt_asc_desc opt_nulls_order
13237 $$
= makeNode
(SortBy
);
13239 $$
->sortby_dir
= $2;
13240 $$
->sortby_nulls
= $3;
13242 $$
->location
= -1; /* no operator */
13248 limit_clause offset_clause
13251 ($$
)->limitOffset
= $2;
13252 ($$
)->offsetLoc
= @
2;
13254 | offset_clause limit_clause
13257 ($$
)->limitOffset
= $1;
13258 ($$
)->offsetLoc
= @
1;
13266 SelectLimit
*n
= (SelectLimit
*) palloc
(sizeof
(SelectLimit
));
13268 n
->limitOffset
= $1;
13269 n
->limitCount
= NULL
;
13270 n
->limitOption
= LIMIT_OPTION_COUNT
;
13279 select_limit
{ $$
= $1; }
13280 |
/* EMPTY */ { $$
= NULL
; }
13284 LIMIT select_limit_value
13286 SelectLimit
*n
= (SelectLimit
*) palloc
(sizeof
(SelectLimit
));
13288 n
->limitOffset
= NULL
;
13289 n
->limitCount
= $2;
13290 n
->limitOption
= LIMIT_OPTION_COUNT
;
13296 | LIMIT select_limit_value
',' select_offset_value
13298 /* Disabled because it was too confusing, bjm 2002-02-18 */
13300 (errcode
(ERRCODE_SYNTAX_ERROR
),
13301 errmsg
("LIMIT #,# syntax is not supported"),
13302 errhint
("Use separate LIMIT and OFFSET clauses."),
13303 parser_errposition
(@
1)));
13305 /* SQL:2008 syntax */
13306 /* to avoid shift/reduce conflicts, handle the optional value with
13307 * a separate production rather than an opt_ expression. The fact
13308 * that ONLY is fully reserved means that this way, we defer any
13309 * decision about what rule reduces ROW or ROWS to the point where
13310 * we can see the ONLY token in the lookahead slot.
13312 | FETCH first_or_next select_fetch_first_value row_or_rows ONLY
13314 SelectLimit
*n
= (SelectLimit
*) palloc
(sizeof
(SelectLimit
));
13316 n
->limitOffset
= NULL
;
13317 n
->limitCount
= $3;
13318 n
->limitOption
= LIMIT_OPTION_COUNT
;
13324 | FETCH first_or_next select_fetch_first_value row_or_rows WITH TIES
13326 SelectLimit
*n
= (SelectLimit
*) palloc
(sizeof
(SelectLimit
));
13328 n
->limitOffset
= NULL
;
13329 n
->limitCount
= $3;
13330 n
->limitOption
= LIMIT_OPTION_WITH_TIES
;
13336 | FETCH first_or_next row_or_rows ONLY
13338 SelectLimit
*n
= (SelectLimit
*) palloc
(sizeof
(SelectLimit
));
13340 n
->limitOffset
= NULL
;
13341 n
->limitCount
= makeIntConst
(1, -1);
13342 n
->limitOption
= LIMIT_OPTION_COUNT
;
13348 | FETCH first_or_next row_or_rows WITH TIES
13350 SelectLimit
*n
= (SelectLimit
*) palloc
(sizeof
(SelectLimit
));
13352 n
->limitOffset
= NULL
;
13353 n
->limitCount
= makeIntConst
(1, -1);
13354 n
->limitOption
= LIMIT_OPTION_WITH_TIES
;
13363 OFFSET select_offset_value
13365 /* SQL:2008 syntax */
13366 | OFFSET select_fetch_first_value row_or_rows
13370 select_limit_value:
13371 a_expr
{ $$
= $1; }
13374 /* LIMIT ALL is represented as a NULL constant */
13375 $$
= makeNullAConst
(@
1);
13379 select_offset_value:
13380 a_expr
{ $$
= $1; }
13384 * Allowing full expressions without parentheses causes various parsing
13385 * problems with the trailing ROW/ROWS key words. SQL spec only calls for
13386 * <simple value specification>, which is either a literal or a parameter (but
13387 * an <SQL parameter reference> could be an identifier, bringing up conflicts
13388 * with ROW/ROWS). We solve this by leveraging the presence of ONLY (see above)
13389 * to determine whether the expression is missing rather than trying to make it
13390 * optional in this rule.
13392 * c_expr covers almost all the spec-required cases (and more), but it doesn't
13393 * cover signed numeric literals, which are allowed by the spec. So we include
13394 * those here explicitly. We need FCONST as well as ICONST because values that
13395 * don't fit in the platform's "long", but do fit in bigint, should still be
13396 * accepted here. (This is possible in 64-bit Windows as well as all 32-bit
13399 select_fetch_first_value:
13400 c_expr
{ $$
= $1; }
13402 { $$
= (Node
*) makeSimpleA_Expr
(AEXPR_OP
, "+", NULL
, $2, @
1); }
13404 { $$
= doNegate
($2, @
1); }
13408 Iconst
{ $$
= makeIntConst
($1,@
1); }
13409 | FCONST
{ $$
= makeFloatConst
($1,@
1); }
13413 row_or_rows: ROW
{ $$
= 0; }
13417 first_or_next: FIRST_P
{ $$
= 0; }
13423 * This syntax for group_clause tries to follow the spec quite closely.
13424 * However, the spec allows only column references, not expressions,
13425 * which introduces an ambiguity between implicit row constructors
13426 * (a,b) and lists of column references.
13428 * We handle this by using the a_expr production for what the spec calls
13429 * <ordinary grouping set>, which in the spec represents either one column
13430 * reference or a parenthesized list of column references. Then, we check the
13431 * top node of the a_expr to see if it's an implicit RowExpr, and if so, just
13432 * grab and use the list, discarding the node. (this is done in parse analysis,
13435 * (we abuse the row_format field of RowExpr to distinguish implicit and
13436 * explicit row constructors; it's debatable if anyone sanely wants to use them
13437 * in a group clause, but if they have a reason to, we make it possible.)
13439 * Each item in the group_clause list is either an expression tree or a
13440 * GroupingSet node of some type.
13443 GROUP_P BY set_quantifier group_by_list
13445 GroupClause
*n
= (GroupClause
*) palloc
(sizeof
(GroupClause
));
13447 n
->distinct
= $3 == SET_QUANTIFIER_DISTINCT
;
13453 GroupClause
*n
= (GroupClause
*) palloc
(sizeof
(GroupClause
));
13455 n
->distinct
= false
;
13462 group_by_item
{ $$
= list_make1
($1); }
13463 | group_by_list
',' group_by_item
{ $$
= lappend
($1,$3); }
13467 a_expr
{ $$
= $1; }
13468 | empty_grouping_set
{ $$
= $1; }
13469 | cube_clause
{ $$
= $1; }
13470 | rollup_clause
{ $$
= $1; }
13471 | grouping_sets_clause
{ $$
= $1; }
13474 empty_grouping_set:
13477 $$
= (Node
*) makeGroupingSet
(GROUPING_SET_EMPTY
, NIL
, @
1);
13482 * These hacks rely on setting precedence of CUBE and ROLLUP below that of '(',
13483 * so that they shift in these rules rather than reducing the conflicting
13484 * unreserved_keyword rule.
13488 ROLLUP
'(' expr_list
')'
13490 $$
= (Node
*) makeGroupingSet
(GROUPING_SET_ROLLUP
, $3, @
1);
13495 CUBE
'(' expr_list
')'
13497 $$
= (Node
*) makeGroupingSet
(GROUPING_SET_CUBE
, $3, @
1);
13501 grouping_sets_clause:
13502 GROUPING SETS
'(' group_by_list
')'
13504 $$
= (Node
*) makeGroupingSet
(GROUPING_SET_SETS
, $4, @
1);
13509 HAVING a_expr
{ $$
= $2; }
13510 |
/*EMPTY*/ { $$
= NULL
; }
13513 for_locking_clause:
13514 for_locking_items
{ $$
= $1; }
13515 | FOR READ ONLY
{ $$
= NIL
; }
13518 opt_for_locking_clause:
13519 for_locking_clause
{ $$
= $1; }
13520 |
/* EMPTY */ { $$
= NIL
; }
13524 for_locking_item
{ $$
= list_make1
($1); }
13525 | for_locking_items for_locking_item
{ $$
= lappend
($1, $2); }
13529 for_locking_strength locked_rels_list opt_nowait_or_skip
13531 LockingClause
*n
= makeNode
(LockingClause
);
13533 n
->lockedRels
= $2;
13535 n
->waitPolicy
= $3;
13540 for_locking_strength:
13541 FOR UPDATE
{ $$
= LCS_FORUPDATE
; }
13542 | FOR NO KEY UPDATE
{ $$
= LCS_FORNOKEYUPDATE
; }
13543 | FOR SHARE
{ $$
= LCS_FORSHARE
; }
13544 | FOR KEY SHARE
{ $$
= LCS_FORKEYSHARE
; }
13548 OF qualified_name_list
{ $$
= $2; }
13549 |
/* EMPTY */ { $$
= NIL
; }
13554 * We should allow ROW '(' expr_list ')' too, but that seems to require
13555 * making VALUES a fully reserved word, which will probably break more apps
13556 * than allowing the noise-word is worth.
13559 VALUES
'(' expr_list
')'
13561 SelectStmt
*n
= makeNode
(SelectStmt
);
13563 n
->stmt_location
= @
1;
13564 n
->valuesLists
= list_make1
($3);
13567 | values_clause
',' '(' expr_list
')'
13569 SelectStmt
*n
= (SelectStmt
*) $1;
13571 n
->valuesLists
= lappend
(n
->valuesLists
, $4);
13577 /*****************************************************************************
13579 * clauses common to all Optimizable Stmts:
13580 * from_clause - allow list of both JOIN expressions and table names
13581 * where_clause - qualifications for joins or restrictions
13583 *****************************************************************************/
13586 FROM from_list
{ $$
= $2; }
13587 |
/*EMPTY*/ { $$
= NIL
; }
13591 table_ref
{ $$
= list_make1
($1); }
13592 | from_list
',' table_ref
{ $$
= lappend
($1, $3); }
13596 * table_ref is where an alias clause can be attached.
13598 table_ref: relation_expr opt_alias_clause
13603 | relation_expr opt_alias_clause tablesample_clause
13605 RangeTableSample
*n
= (RangeTableSample
*) $3;
13608 /* relation_expr goes inside the RangeTableSample node */
13609 n
->relation
= (Node
*) $1;
13612 | func_table func_alias_clause
13614 RangeFunction
*n
= (RangeFunction
*) $1;
13616 n
->alias
= linitial
($2);
13617 n
->coldeflist
= lsecond
($2);
13620 | LATERAL_P func_table func_alias_clause
13622 RangeFunction
*n
= (RangeFunction
*) $2;
13625 n
->alias
= linitial
($3);
13626 n
->coldeflist
= lsecond
($3);
13629 | xmltable opt_alias_clause
13631 RangeTableFunc
*n
= (RangeTableFunc
*) $1;
13636 | LATERAL_P xmltable opt_alias_clause
13638 RangeTableFunc
*n
= (RangeTableFunc
*) $2;
13644 | select_with_parens opt_alias_clause
13646 RangeSubselect
*n
= makeNode
(RangeSubselect
);
13648 n
->lateral
= false
;
13653 | LATERAL_P select_with_parens opt_alias_clause
13655 RangeSubselect
*n
= makeNode
(RangeSubselect
);
13666 |
'(' joined_table
')' alias_clause
13671 | json_table opt_alias_clause
13673 JsonTable
*jt
= castNode
(JsonTable
, $1);
13678 | LATERAL_P json_table opt_alias_clause
13680 JsonTable
*jt
= castNode
(JsonTable
, $2);
13683 jt
->lateral
= true
;
13690 * It may seem silly to separate joined_table from table_ref, but there is
13691 * method in SQL's madness: if you don't do it this way you get reduce-
13692 * reduce conflicts, because it's not clear to the parser generator whether
13693 * to expect alias_clause after ')' or not. For the same reason we must
13694 * treat 'JOIN' and 'join_type JOIN' separately, rather than allowing
13695 * join_type to expand to empty; if we try it, the parser generator can't
13696 * figure out when to reduce an empty join_type right after table_ref.
13698 * Note that a CROSS JOIN is the same as an unqualified
13699 * INNER JOIN, and an INNER JOIN/ON has the same shape
13700 * but a qualification expression to limit membership.
13701 * A NATURAL JOIN implicitly matches column names between
13702 * tables and the shape is determined by which columns are
13703 * in common. We'll collect columns during the later transformations.
13707 '(' joined_table
')'
13711 | table_ref CROSS JOIN table_ref
13713 /* CROSS JOIN is same as unqualified inner join */
13714 JoinExpr
*n
= makeNode
(JoinExpr
);
13716 n
->jointype
= JOIN_INNER
;
13717 n
->isNatural
= false
;
13720 n
->usingClause
= NIL
;
13721 n
->join_using_alias
= NULL
;
13725 | table_ref join_type JOIN table_ref join_qual
13727 JoinExpr
*n
= makeNode
(JoinExpr
);
13730 n
->isNatural
= false
;
13733 if
($5 != NULL
&& IsA
($5, List
))
13736 n
->usingClause
= linitial_node
(List
, castNode
(List
, $5));
13737 n
->join_using_alias
= lsecond_node
(Alias
, castNode
(List
, $5));
13746 | table_ref JOIN table_ref join_qual
13748 /* letting join_type reduce to empty doesn't work */
13749 JoinExpr
*n
= makeNode
(JoinExpr
);
13751 n
->jointype
= JOIN_INNER
;
13752 n
->isNatural
= false
;
13755 if
($4 != NULL
&& IsA
($4, List
))
13758 n
->usingClause
= linitial_node
(List
, castNode
(List
, $4));
13759 n
->join_using_alias
= lsecond_node
(Alias
, castNode
(List
, $4));
13768 | table_ref NATURAL join_type JOIN table_ref
13770 JoinExpr
*n
= makeNode
(JoinExpr
);
13773 n
->isNatural
= true
;
13776 n
->usingClause
= NIL
; /* figure out which columns later... */
13777 n
->join_using_alias
= NULL
;
13778 n
->quals
= NULL
; /* fill later */
13781 | table_ref NATURAL JOIN table_ref
13783 /* letting join_type reduce to empty doesn't work */
13784 JoinExpr
*n
= makeNode
(JoinExpr
);
13786 n
->jointype
= JOIN_INNER
;
13787 n
->isNatural
= true
;
13790 n
->usingClause
= NIL
; /* figure out which columns later... */
13791 n
->join_using_alias
= NULL
;
13792 n
->quals
= NULL
; /* fill later */
13798 AS ColId
'(' name_list
')'
13800 $$
= makeNode
(Alias
);
13801 $$
->aliasname
= $2;
13806 $$
= makeNode
(Alias
);
13807 $$
->aliasname
= $2;
13809 | ColId
'(' name_list
')'
13811 $$
= makeNode
(Alias
);
13812 $$
->aliasname
= $1;
13817 $$
= makeNode
(Alias
);
13818 $$
->aliasname
= $1;
13822 opt_alias_clause: alias_clause
{ $$
= $1; }
13823 |
/*EMPTY*/ { $$
= NULL
; }
13827 * The alias clause after JOIN ... USING only accepts the AS ColId spelling,
13828 * per SQL standard. (The grammar could parse the other variants, but they
13829 * don't seem to be useful, and it might lead to parser problems in the
13832 opt_alias_clause_for_join_using:
13835 $$
= makeNode
(Alias
);
13836 $$
->aliasname
= $2;
13837 /* the column name list will be inserted later */
13839 |
/*EMPTY*/ { $$
= NULL
; }
13843 * func_alias_clause can include both an Alias and a coldeflist, so we make it
13844 * return a 2-element list that gets disassembled by calling production.
13849 $$
= list_make2
($1, NIL
);
13851 | AS
'(' TableFuncElementList
')'
13853 $$
= list_make2
(NULL
, $3);
13855 | AS ColId
'(' TableFuncElementList
')'
13857 Alias
*a
= makeNode
(Alias
);
13860 $$
= list_make2
(a
, $4);
13862 | ColId
'(' TableFuncElementList
')'
13864 Alias
*a
= makeNode
(Alias
);
13867 $$
= list_make2
(a
, $3);
13871 $$
= list_make2
(NULL
, NIL
);
13875 join_type: FULL opt_outer
{ $$
= JOIN_FULL
; }
13876 | LEFT opt_outer
{ $$
= JOIN_LEFT
; }
13877 | RIGHT opt_outer
{ $$
= JOIN_RIGHT
; }
13878 | INNER_P
{ $$
= JOIN_INNER
; }
13881 /* OUTER is just noise... */
13886 /* JOIN qualification clauses
13887 * Possibilities are:
13888 * USING ( column list ) [ AS alias ]
13889 * allows only unqualified column names,
13890 * which must match between tables.
13891 * ON expr allows more general qualifications.
13893 * We return USING as a two-element List (the first item being a sub-List
13894 * of the common column names, and the second either an Alias item or NULL).
13895 * An ON-expr will not be a List, so it can be told apart that way.
13898 join_qual: USING
'(' name_list
')' opt_alias_clause_for_join_using
13900 $$
= (Node
*) list_make2
($3, $5);
13912 /* inheritance query, implicitly */
13917 | extended_relation_expr
13923 extended_relation_expr:
13926 /* inheritance query, explicitly */
13931 | ONLY qualified_name
13933 /* no inheritance */
13938 | ONLY
'(' qualified_name
')'
13940 /* no inheritance, SQL99-style syntax */
13948 relation_expr_list:
13949 relation_expr
{ $$
= list_make1
($1); }
13950 | relation_expr_list
',' relation_expr
{ $$
= lappend
($1, $3); }
13955 * Given "UPDATE foo set set ...", we have to decide without looking any
13956 * further ahead whether the first "set" is an alias or the UPDATE's SET
13957 * keyword. Since "set" is allowed as a column name both interpretations
13958 * are feasible. We resolve the shift/reduce conflict by giving the first
13959 * relation_expr_opt_alias production a higher precedence than the SET token
13960 * has, causing the parser to prefer to reduce, in effect assuming that the
13961 * SET is not an alias.
13963 relation_expr_opt_alias: relation_expr %prec UMINUS
13967 | relation_expr ColId
13969 Alias
*alias
= makeNode
(Alias
);
13971 alias
->aliasname
= $2;
13975 | relation_expr AS ColId
13977 Alias
*alias
= makeNode
(Alias
);
13979 alias
->aliasname
= $3;
13986 * TABLESAMPLE decoration in a FROM item
13988 tablesample_clause:
13989 TABLESAMPLE func_name
'(' expr_list
')' opt_repeatable_clause
13991 RangeTableSample
*n
= makeNode
(RangeTableSample
);
13993 /* n->relation will be filled in later */
13996 n
->repeatable
= $6;
14002 opt_repeatable_clause:
14003 REPEATABLE
'(' a_expr
')' { $$
= (Node
*) $3; }
14004 |
/*EMPTY*/ { $$
= NULL
; }
14008 * func_table represents a function invocation in a FROM list. It can be
14009 * a plain function call, like "foo(...)", or a ROWS FROM expression with
14010 * one or more function calls, "ROWS FROM (foo(...), bar(...))",
14011 * optionally with WITH ORDINALITY attached.
14012 * In the ROWS FROM syntax, a column definition list can be given for each
14013 * function, for example:
14014 * ROWS FROM (foo() AS (foo_res_a text, foo_res_b text),
14015 * bar() AS (bar_res_a text, bar_res_b text))
14016 * It's also possible to attach a column definition list to the RangeFunction
14017 * as a whole, but that's handled by the table_ref production.
14019 func_table: func_expr_windowless opt_ordinality
14021 RangeFunction
*n
= makeNode
(RangeFunction
);
14023 n
->lateral
= false
;
14024 n
->ordinality
= $2;
14025 n
->is_rowsfrom
= false
;
14026 n
->functions
= list_make1
(list_make2
($1, NIL
));
14027 /* alias and coldeflist are set by table_ref production */
14030 | ROWS FROM
'(' rowsfrom_list
')' opt_ordinality
14032 RangeFunction
*n
= makeNode
(RangeFunction
);
14034 n
->lateral
= false
;
14035 n
->ordinality
= $6;
14036 n
->is_rowsfrom
= true
;
14038 /* alias and coldeflist are set by table_ref production */
14043 rowsfrom_item: func_expr_windowless opt_col_def_list
14044 { $$
= list_make2
($1, $2); }
14048 rowsfrom_item
{ $$
= list_make1
($1); }
14049 | rowsfrom_list
',' rowsfrom_item
{ $$
= lappend
($1, $3); }
14052 opt_col_def_list: AS
'(' TableFuncElementList
')' { $$
= $3; }
14053 |
/*EMPTY*/ { $$
= NIL
; }
14056 opt_ordinality: WITH_LA ORDINALITY
{ $$
= true
; }
14057 |
/*EMPTY*/ { $$
= false
; }
14062 WHERE a_expr
{ $$
= $2; }
14063 |
/*EMPTY*/ { $$
= NULL
; }
14066 /* variant for UPDATE and DELETE */
14067 where_or_current_clause:
14068 WHERE a_expr
{ $$
= $2; }
14069 | WHERE CURRENT_P OF cursor_name
14071 CurrentOfExpr
*n
= makeNode
(CurrentOfExpr
);
14073 /* cvarno is filled in by parse analysis */
14074 n
->cursor_name
= $4;
14075 n
->cursor_param
= 0;
14078 |
/*EMPTY*/ { $$
= NULL
; }
14082 OptTableFuncElementList:
14083 TableFuncElementList
{ $$
= $1; }
14084 |
/*EMPTY*/ { $$
= NIL
; }
14087 TableFuncElementList:
14090 $$
= list_make1
($1);
14092 | TableFuncElementList
',' TableFuncElement
14094 $$
= lappend
($1, $3);
14098 TableFuncElement: ColId Typename opt_collate_clause
14100 ColumnDef
*n
= makeNode
(ColumnDef
);
14105 n
->is_local
= true
;
14106 n
->is_not_null
= false
;
14107 n
->is_from_type
= false
;
14109 n
->raw_default
= NULL
;
14110 n
->cooked_default
= NULL
;
14111 n
->collClause
= (CollateClause
*) $3;
14112 n
->collOid
= InvalidOid
;
14113 n
->constraints
= NIL
;
14123 XMLTABLE
'(' c_expr xmlexists_argument COLUMNS xmltable_column_list
')'
14125 RangeTableFunc
*n
= makeNode
(RangeTableFunc
);
14130 n
->namespaces
= NIL
;
14134 | XMLTABLE
'(' XMLNAMESPACES
'(' xml_namespace_list
')' ','
14135 c_expr xmlexists_argument COLUMNS xmltable_column_list
')'
14137 RangeTableFunc
*n
= makeNode
(RangeTableFunc
);
14142 n
->namespaces
= $5;
14148 xmltable_column_list: xmltable_column_el
{ $$
= list_make1
($1); }
14149 | xmltable_column_list
',' xmltable_column_el
{ $$
= lappend
($1, $3); }
14152 xmltable_column_el:
14155 RangeTableFuncCol
*fc
= makeNode
(RangeTableFuncCol
);
14158 fc
->for_ordinality
= false
;
14160 fc
->is_not_null
= false
;
14161 fc
->colexpr
= NULL
;
14162 fc
->coldefexpr
= NULL
;
14167 | ColId Typename xmltable_column_option_list
14169 RangeTableFuncCol
*fc
= makeNode
(RangeTableFuncCol
);
14171 bool nullability_seen
= false
;
14175 fc
->for_ordinality
= false
;
14176 fc
->is_not_null
= false
;
14177 fc
->colexpr
= NULL
;
14178 fc
->coldefexpr
= NULL
;
14181 foreach
(option
, $3)
14183 DefElem
*defel
= (DefElem
*) lfirst
(option
);
14185 if
(strcmp
(defel
->defname
, "default") == 0)
14187 if
(fc
->coldefexpr
!= NULL
)
14189 (errcode
(ERRCODE_SYNTAX_ERROR
),
14190 errmsg
("only one DEFAULT value is allowed"),
14191 parser_errposition
(defel
->location
)));
14192 fc
->coldefexpr
= defel
->arg
;
14194 else if
(strcmp
(defel
->defname
, "path") == 0)
14196 if
(fc
->colexpr
!= NULL
)
14198 (errcode
(ERRCODE_SYNTAX_ERROR
),
14199 errmsg
("only one PATH value per column is allowed"),
14200 parser_errposition
(defel
->location
)));
14201 fc
->colexpr
= defel
->arg
;
14203 else if
(strcmp
(defel
->defname
, "is_not_null") == 0)
14205 if
(nullability_seen
)
14207 (errcode
(ERRCODE_SYNTAX_ERROR
),
14208 errmsg
("conflicting or redundant NULL / NOT NULL declarations for column \"%s\"", fc
->colname
),
14209 parser_errposition
(defel
->location
)));
14210 fc
->is_not_null
= boolVal
(defel
->arg
);
14211 nullability_seen
= true
;
14216 (errcode
(ERRCODE_SYNTAX_ERROR
),
14217 errmsg
("unrecognized column option \"%s\"",
14219 parser_errposition
(defel
->location
)));
14224 | ColId FOR ORDINALITY
14226 RangeTableFuncCol
*fc
= makeNode
(RangeTableFuncCol
);
14229 fc
->for_ordinality
= true
;
14230 /* other fields are ignored, initialized by makeNode */
14237 xmltable_column_option_list:
14238 xmltable_column_option_el
14239 { $$
= list_make1
($1); }
14240 | xmltable_column_option_list xmltable_column_option_el
14241 { $$
= lappend
($1, $2); }
14244 xmltable_column_option_el:
14246 { $$
= makeDefElem
($1, $2, @
1); }
14248 { $$
= makeDefElem
("default", $2, @
1); }
14250 { $$
= makeDefElem
("is_not_null", (Node
*) makeBoolean
(true
), @
1); }
14252 { $$
= makeDefElem
("is_not_null", (Node
*) makeBoolean
(false
), @
1); }
14254 { $$
= makeDefElem
("path", $2, @
1); }
14257 xml_namespace_list:
14259 { $$
= list_make1
($1); }
14260 | xml_namespace_list
',' xml_namespace_el
14261 { $$
= lappend
($1, $3); }
14267 $$
= makeNode
(ResTarget
);
14269 $$
->indirection
= NIL
;
14275 $$
= makeNode
(ResTarget
);
14277 $$
->indirection
= NIL
;
14285 json_value_expr
',' a_expr json_table_path_name_opt
14286 json_passing_clause_opt
14287 COLUMNS
'(' json_table_column_definition_list
')'
14288 json_on_error_clause_opt
14291 JsonTable
*n
= makeNode
(JsonTable
);
14294 n
->context_item
= (JsonValueExpr
*) $3;
14295 if
(!IsA
($5, A_Const
) ||
14296 castNode
(A_Const
, $5)->val.node.type
!= T_String
)
14298 errcode
(ERRCODE_FEATURE_NOT_SUPPORTED
),
14299 errmsg
("only string constants are supported in JSON_TABLE path specification"),
14300 parser_errposition
(@
5));
14301 pathstring
= castNode
(A_Const
, $5)->val.sval.sval
;
14302 n
->pathspec
= makeJsonTablePathSpec
(pathstring
, $6, @
5, @
6);
14305 n
->on_error
= (JsonBehavior
*) $12;
14311 json_table_path_name_opt:
14312 AS name
{ $$
= $2; }
14313 |
/* empty */ { $$
= NULL
; }
14316 json_table_column_definition_list:
14317 json_table_column_definition
14318 { $$
= list_make1
($1); }
14319 | json_table_column_definition_list
',' json_table_column_definition
14320 { $$
= lappend
($1, $3); }
14323 json_table_column_definition:
14324 ColId FOR ORDINALITY
14326 JsonTableColumn
*n
= makeNode
(JsonTableColumn
);
14328 n
->coltype
= JTC_FOR_ORDINALITY
;
14334 json_table_column_path_clause_opt
14335 json_wrapper_behavior
14336 json_quotes_clause_opt
14337 json_behavior_clause_opt
14339 JsonTableColumn
*n
= makeNode
(JsonTableColumn
);
14341 n
->coltype
= JTC_REGULAR
;
14344 n
->format
= makeJsonFormat
(JS_FORMAT_DEFAULT
, JS_ENC_DEFAULT
, -1);
14345 n
->pathspec
= (JsonTablePathSpec
*) $3;
14348 n
->on_empty
= (JsonBehavior
*) linitial
($6);
14349 n
->on_error
= (JsonBehavior
*) lsecond
($6);
14353 | ColId Typename json_format_clause
14354 json_table_column_path_clause_opt
14355 json_wrapper_behavior
14356 json_quotes_clause_opt
14357 json_behavior_clause_opt
14359 JsonTableColumn
*n
= makeNode
(JsonTableColumn
);
14361 n
->coltype
= JTC_FORMATTED
;
14364 n
->format
= (JsonFormat
*) $3;
14365 n
->pathspec
= (JsonTablePathSpec
*) $4;
14368 n
->on_empty
= (JsonBehavior
*) linitial
($7);
14369 n
->on_error
= (JsonBehavior
*) lsecond
($7);
14374 EXISTS json_table_column_path_clause_opt
14375 json_on_error_clause_opt
14377 JsonTableColumn
*n
= makeNode
(JsonTableColumn
);
14379 n
->coltype
= JTC_EXISTS
;
14382 n
->format
= makeJsonFormat
(JS_FORMAT_DEFAULT
, JS_ENC_DEFAULT
, -1);
14383 n
->wrapper
= JSW_NONE
;
14384 n
->quotes
= JS_QUOTES_UNSPEC
;
14385 n
->pathspec
= (JsonTablePathSpec
*) $4;
14386 n
->on_empty
= NULL
;
14387 n
->on_error
= (JsonBehavior
*) $5;
14391 | NESTED path_opt Sconst
14392 COLUMNS
'(' json_table_column_definition_list
')'
14394 JsonTableColumn
*n
= makeNode
(JsonTableColumn
);
14396 n
->coltype
= JTC_NESTED
;
14397 n
->pathspec
= (JsonTablePathSpec
*)
14398 makeJsonTablePathSpec
($3, NULL
, @
3, -1);
14403 | NESTED path_opt Sconst AS name
14404 COLUMNS
'(' json_table_column_definition_list
')'
14406 JsonTableColumn
*n
= makeNode
(JsonTableColumn
);
14408 n
->coltype
= JTC_NESTED
;
14409 n
->pathspec
= (JsonTablePathSpec
*)
14410 makeJsonTablePathSpec
($3, $5, @
3, @
5);
14422 json_table_column_path_clause_opt:
14424 { $$
= (Node
*) makeJsonTablePathSpec
($2, NULL
, @
2, -1); }
14429 /*****************************************************************************
14432 * SQL introduces a large amount of type-specific syntax.
14433 * Define individual clauses to handle these cases, and use
14434 * the generic case to handle regular type-extensible Postgres syntax.
14435 * - thomas 1997-10-10
14437 *****************************************************************************/
14439 Typename: SimpleTypename opt_array_bounds
14442 $$
->arrayBounds
= $2;
14444 | SETOF SimpleTypename opt_array_bounds
14447 $$
->arrayBounds
= $3;
14450 /* SQL standard syntax, currently only one-dimensional */
14451 | SimpleTypename ARRAY
'[' Iconst
']'
14454 $$
->arrayBounds
= list_make1
(makeInteger
($4));
14456 | SETOF SimpleTypename ARRAY
'[' Iconst
']'
14459 $$
->arrayBounds
= list_make1
(makeInteger
($5));
14462 | SimpleTypename ARRAY
14465 $$
->arrayBounds
= list_make1
(makeInteger
(-1));
14467 | SETOF SimpleTypename ARRAY
14470 $$
->arrayBounds
= list_make1
(makeInteger
(-1));
14476 opt_array_bounds
'[' ']'
14477 { $$
= lappend
($1, makeInteger
(-1)); }
14478 | opt_array_bounds
'[' Iconst
']'
14479 { $$
= lappend
($1, makeInteger
($3)); }
14485 GenericType
{ $$
= $1; }
14486 | Numeric
{ $$
= $1; }
14488 | Character
{ $$
= $1; }
14489 | ConstDatetime
{ $$
= $1; }
14490 | ConstInterval opt_interval
14495 | ConstInterval
'(' Iconst
')'
14498 $$
->typmods
= list_make2
(makeIntConst
(INTERVAL_FULL_RANGE
, -1),
14499 makeIntConst
($3, @
3));
14501 | JsonType
{ $$
= $1; }
14504 /* We have a separate ConstTypename to allow defaulting fixed-length
14505 * types such as CHAR() and BIT() to an unspecified length.
14506 * SQL9x requires that these default to a length of one, but this
14507 * makes no sense for constructs like CHAR 'hi' and BIT '0101',
14508 * where there is an obvious better choice to make.
14509 * Note that ConstInterval is not included here since it must
14510 * be pushed up higher in the rules to accommodate the postfix
14511 * options (e.g. INTERVAL '1' YEAR). Likewise, we have to handle
14512 * the generic-type-name case in AexprConst to avoid premature
14513 * reduce/reduce conflicts against function names.
14516 Numeric
{ $$
= $1; }
14517 | ConstBit
{ $$
= $1; }
14518 | ConstCharacter
{ $$
= $1; }
14519 | ConstDatetime
{ $$
= $1; }
14520 | JsonType
{ $$
= $1; }
14524 * GenericType covers all type names that don't have special syntax mandated
14525 * by the standard, including qualified names. We also allow type modifiers.
14526 * To avoid parsing conflicts against function invocations, the modifiers
14527 * have to be shown as expr_list here, but parse analysis will only accept
14528 * constants for them.
14531 type_function_name opt_type_modifiers
14533 $$
= makeTypeName
($1);
14537 | type_function_name attrs opt_type_modifiers
14539 $$
= makeTypeNameFromNameList
(lcons
(makeString
($1), $2));
14545 opt_type_modifiers: '(' expr_list
')' { $$
= $2; }
14546 |
/* EMPTY */ { $$
= NIL
; }
14550 * SQL numeric data types
14554 $$
= SystemTypeName
("int4");
14559 $$
= SystemTypeName
("int4");
14564 $$
= SystemTypeName
("int2");
14569 $$
= SystemTypeName
("int8");
14574 $$
= SystemTypeName
("float4");
14577 | FLOAT_P opt_float
14582 | DOUBLE_P PRECISION
14584 $$
= SystemTypeName
("float8");
14587 | DECIMAL_P opt_type_modifiers
14589 $$
= SystemTypeName
("numeric");
14593 | DEC opt_type_modifiers
14595 $$
= SystemTypeName
("numeric");
14599 | NUMERIC opt_type_modifiers
14601 $$
= SystemTypeName
("numeric");
14607 $$
= SystemTypeName
("bool");
14612 opt_float: '(' Iconst
')'
14615 * Check FLOAT() precision limits assuming IEEE floating
14616 * types - thomas 1997-09-18
14620 (errcode
(ERRCODE_INVALID_PARAMETER_VALUE
),
14621 errmsg
("precision for type float must be at least 1 bit"),
14622 parser_errposition
(@
2)));
14624 $$
= SystemTypeName
("float4");
14626 $$
= SystemTypeName
("float8");
14629 (errcode
(ERRCODE_INVALID_PARAMETER_VALUE
),
14630 errmsg
("precision for type float must be less than 54 bits"),
14631 parser_errposition
(@
2)));
14635 $$
= SystemTypeName
("float8");
14640 * SQL bit-field data types
14641 * The following implements BIT() and BIT VARYING().
14653 /* ConstBit is like Bit except "BIT" defaults to unspecified length */
14654 /* See notes for ConstCharacter, which addresses same issue for "CHAR" */
14655 ConstBit: BitWithLength
14667 BIT opt_varying
'(' expr_list
')'
14671 typname
= $2 ?
"varbit" : "bit";
14672 $$
= SystemTypeName
(typname
);
14681 /* bit defaults to bit(1), varbit to no limit */
14684 $$
= SystemTypeName
("varbit");
14688 $$
= SystemTypeName
("bit");
14689 $$
->typmods
= list_make1
(makeIntConst
(1, -1));
14697 * SQL character data types
14698 * The following implements CHAR() and VARCHAR().
14700 Character: CharacterWithLength
14704 | CharacterWithoutLength
14710 ConstCharacter: CharacterWithLength
14714 | CharacterWithoutLength
14716 /* Length was not specified so allow to be unrestricted.
14717 * This handles problems with fixed-length (bpchar) strings
14718 * which in column definitions must default to a length
14719 * of one, but should not be constrained if the length
14720 * was not specified.
14727 CharacterWithLength: character
'(' Iconst
')'
14729 $$
= SystemTypeName
($1);
14730 $$
->typmods
= list_make1
(makeIntConst
($3, @
3));
14735 CharacterWithoutLength: character
14737 $$
= SystemTypeName
($1);
14738 /* char defaults to char(1), varchar to no limit */
14739 if
(strcmp
($1, "bpchar") == 0)
14740 $$
->typmods
= list_make1
(makeIntConst
(1, -1));
14745 character: CHARACTER opt_varying
14746 { $$
= $2 ?
"varchar": "bpchar"; }
14747 | CHAR_P opt_varying
14748 { $$
= $2 ?
"varchar": "bpchar"; }
14750 { $$
= "varchar"; }
14751 | NATIONAL CHARACTER opt_varying
14752 { $$
= $3 ?
"varchar": "bpchar"; }
14753 | NATIONAL CHAR_P opt_varying
14754 { $$
= $3 ?
"varchar": "bpchar"; }
14755 | NCHAR opt_varying
14756 { $$
= $2 ?
"varchar": "bpchar"; }
14760 VARYING
{ $$
= true
; }
14761 |
/*EMPTY*/ { $$
= false
; }
14765 * SQL date/time types
14768 TIMESTAMP
'(' Iconst
')' opt_timezone
14771 $$
= SystemTypeName
("timestamptz");
14773 $$
= SystemTypeName
("timestamp");
14774 $$
->typmods
= list_make1
(makeIntConst
($3, @
3));
14777 | TIMESTAMP opt_timezone
14780 $$
= SystemTypeName
("timestamptz");
14782 $$
= SystemTypeName
("timestamp");
14785 | TIME
'(' Iconst
')' opt_timezone
14788 $$
= SystemTypeName
("timetz");
14790 $$
= SystemTypeName
("time");
14791 $$
->typmods
= list_make1
(makeIntConst
($3, @
3));
14794 | TIME opt_timezone
14797 $$
= SystemTypeName
("timetz");
14799 $$
= SystemTypeName
("time");
14807 $$
= SystemTypeName
("interval");
14813 WITH_LA TIME ZONE
{ $$
= true
; }
14814 | WITHOUT_LA TIME ZONE
{ $$
= false
; }
14815 |
/*EMPTY*/ { $$
= false
; }
14820 { $$
= list_make1
(makeIntConst
(INTERVAL_MASK
(YEAR
), @
1)); }
14822 { $$
= list_make1
(makeIntConst
(INTERVAL_MASK
(MONTH
), @
1)); }
14824 { $$
= list_make1
(makeIntConst
(INTERVAL_MASK
(DAY
), @
1)); }
14826 { $$
= list_make1
(makeIntConst
(INTERVAL_MASK
(HOUR
), @
1)); }
14828 { $$
= list_make1
(makeIntConst
(INTERVAL_MASK
(MINUTE
), @
1)); }
14831 | YEAR_P TO MONTH_P
14833 $$
= list_make1
(makeIntConst
(INTERVAL_MASK
(YEAR
) |
14834 INTERVAL_MASK
(MONTH
), @
1));
14838 $$
= list_make1
(makeIntConst
(INTERVAL_MASK
(DAY
) |
14839 INTERVAL_MASK
(HOUR
), @
1));
14841 | DAY_P TO MINUTE_P
14843 $$
= list_make1
(makeIntConst
(INTERVAL_MASK
(DAY
) |
14844 INTERVAL_MASK
(HOUR
) |
14845 INTERVAL_MASK
(MINUTE
), @
1));
14847 | DAY_P TO interval_second
14850 linitial
($$
) = makeIntConst
(INTERVAL_MASK
(DAY
) |
14851 INTERVAL_MASK
(HOUR
) |
14852 INTERVAL_MASK
(MINUTE
) |
14853 INTERVAL_MASK
(SECOND
), @
1);
14855 | HOUR_P TO MINUTE_P
14857 $$
= list_make1
(makeIntConst
(INTERVAL_MASK
(HOUR
) |
14858 INTERVAL_MASK
(MINUTE
), @
1));
14860 | HOUR_P TO interval_second
14863 linitial
($$
) = makeIntConst
(INTERVAL_MASK
(HOUR
) |
14864 INTERVAL_MASK
(MINUTE
) |
14865 INTERVAL_MASK
(SECOND
), @
1);
14867 | MINUTE_P TO interval_second
14870 linitial
($$
) = makeIntConst
(INTERVAL_MASK
(MINUTE
) |
14871 INTERVAL_MASK
(SECOND
), @
1);
14880 $$
= list_make1
(makeIntConst
(INTERVAL_MASK
(SECOND
), @
1));
14882 | SECOND_P
'(' Iconst
')'
14884 $$
= list_make2
(makeIntConst
(INTERVAL_MASK
(SECOND
), @
1),
14885 makeIntConst
($3, @
3));
14892 $$
= SystemTypeName
("json");
14897 /*****************************************************************************
14899 * expression grammar
14901 *****************************************************************************/
14904 * General expressions
14905 * This is the heart of the expression syntax.
14907 * We have two expression types: a_expr is the unrestricted kind, and
14908 * b_expr is a subset that must be used in some places to avoid shift/reduce
14909 * conflicts. For example, we can't do BETWEEN as "BETWEEN a_expr AND a_expr"
14910 * because that use of AND conflicts with AND as a boolean operator. So,
14911 * b_expr is used in BETWEEN and we remove boolean keywords from b_expr.
14913 * Note that '(' a_expr ')' is a b_expr, so an unrestricted expression can
14914 * always be used by surrounding it with parens.
14916 * c_expr is all the productions that are common to a_expr and b_expr;
14917 * it's factored out just to eliminate redundant coding.
14919 * Be careful of productions involving more than one terminal token.
14920 * By default, bison will assign such productions the precedence of their
14921 * last terminal, but in nearly all cases you want it to be the precedence
14922 * of the first terminal instead; otherwise you will not get the behavior
14923 * you expect! So we use %prec annotations freely to set precedences.
14925 a_expr: c_expr
{ $$
= $1; }
14926 | a_expr TYPECAST Typename
14927 { $$
= makeTypeCast
($1, $3, @
2); }
14928 | a_expr COLLATE any_name
14930 CollateClause
*n
= makeNode
(CollateClause
);
14937 | a_expr AT TIME ZONE a_expr %prec AT
14939 $$
= (Node
*) makeFuncCall
(SystemFuncName
("timezone"),
14940 list_make2
($5, $1),
14944 | a_expr AT LOCAL %prec AT
14946 $$
= (Node
*) makeFuncCall
(SystemFuncName
("timezone"),
14952 * These operators must be called out explicitly in order to make use
14953 * of bison's automatic operator-precedence handling. All other
14954 * operator names are handled by the generic productions using "Op",
14955 * below; and all those operators will have the same precedence.
14957 * If you add more explicitly-known operators, be sure to add them
14958 * also to b_expr and to the MathOp list below.
14960 |
'+' a_expr %prec UMINUS
14961 { $$
= (Node
*) makeSimpleA_Expr
(AEXPR_OP
, "+", NULL
, $2, @
1); }
14962 |
'-' a_expr %prec UMINUS
14963 { $$
= doNegate
($2, @
1); }
14964 | a_expr
'+' a_expr
14965 { $$
= (Node
*) makeSimpleA_Expr
(AEXPR_OP
, "+", $1, $3, @
2); }
14966 | a_expr
'-' a_expr
14967 { $$
= (Node
*) makeSimpleA_Expr
(AEXPR_OP
, "-", $1, $3, @
2); }
14968 | a_expr
'*' a_expr
14969 { $$
= (Node
*) makeSimpleA_Expr
(AEXPR_OP
, "*", $1, $3, @
2); }
14970 | a_expr
'/' a_expr
14971 { $$
= (Node
*) makeSimpleA_Expr
(AEXPR_OP
, "/", $1, $3, @
2); }
14972 | a_expr
'%' a_expr
14973 { $$
= (Node
*) makeSimpleA_Expr
(AEXPR_OP
, "%", $1, $3, @
2); }
14974 | a_expr
'^' a_expr
14975 { $$
= (Node
*) makeSimpleA_Expr
(AEXPR_OP
, "^", $1, $3, @
2); }
14976 | a_expr
'<' a_expr
14977 { $$
= (Node
*) makeSimpleA_Expr
(AEXPR_OP
, "<", $1, $3, @
2); }
14978 | a_expr
'>' a_expr
14979 { $$
= (Node
*) makeSimpleA_Expr
(AEXPR_OP
, ">", $1, $3, @
2); }
14980 | a_expr
'=' a_expr
14981 { $$
= (Node
*) makeSimpleA_Expr
(AEXPR_OP
, "=", $1, $3, @
2); }
14982 | a_expr LESS_EQUALS a_expr
14983 { $$
= (Node
*) makeSimpleA_Expr
(AEXPR_OP
, "<=", $1, $3, @
2); }
14984 | a_expr GREATER_EQUALS a_expr
14985 { $$
= (Node
*) makeSimpleA_Expr
(AEXPR_OP
, ">=", $1, $3, @
2); }
14986 | a_expr NOT_EQUALS a_expr
14987 { $$
= (Node
*) makeSimpleA_Expr
(AEXPR_OP
, "<>", $1, $3, @
2); }
14989 | a_expr qual_Op a_expr %prec Op
14990 { $$
= (Node
*) makeA_Expr
(AEXPR_OP
, $2, $1, $3, @
2); }
14991 | qual_Op a_expr %prec Op
14992 { $$
= (Node
*) makeA_Expr
(AEXPR_OP
, $1, NULL
, $2, @
1); }
14994 | a_expr AND a_expr
14995 { $$
= makeAndExpr
($1, $3, @
2); }
14997 { $$
= makeOrExpr
($1, $3, @
2); }
14999 { $$
= makeNotExpr
($2, @
1); }
15000 | NOT_LA a_expr %prec NOT
15001 { $$
= makeNotExpr
($2, @
1); }
15003 | a_expr LIKE a_expr
15005 $$
= (Node
*) makeSimpleA_Expr
(AEXPR_LIKE
, "~~",
15008 | a_expr LIKE a_expr ESCAPE a_expr %prec LIKE
15010 FuncCall
*n
= makeFuncCall
(SystemFuncName
("like_escape"),
15011 list_make2
($3, $5),
15012 COERCE_EXPLICIT_CALL
,
15014 $$
= (Node
*) makeSimpleA_Expr
(AEXPR_LIKE
, "~~",
15015 $1, (Node
*) n
, @
2);
15017 | a_expr NOT_LA LIKE a_expr %prec NOT_LA
15019 $$
= (Node
*) makeSimpleA_Expr
(AEXPR_LIKE
, "!~~",
15022 | a_expr NOT_LA LIKE a_expr ESCAPE a_expr %prec NOT_LA
15024 FuncCall
*n
= makeFuncCall
(SystemFuncName
("like_escape"),
15025 list_make2
($4, $6),
15026 COERCE_EXPLICIT_CALL
,
15028 $$
= (Node
*) makeSimpleA_Expr
(AEXPR_LIKE
, "!~~",
15029 $1, (Node
*) n
, @
2);
15031 | a_expr ILIKE a_expr
15033 $$
= (Node
*) makeSimpleA_Expr
(AEXPR_ILIKE
, "~~*",
15036 | a_expr ILIKE a_expr ESCAPE a_expr %prec ILIKE
15038 FuncCall
*n
= makeFuncCall
(SystemFuncName
("like_escape"),
15039 list_make2
($3, $5),
15040 COERCE_EXPLICIT_CALL
,
15042 $$
= (Node
*) makeSimpleA_Expr
(AEXPR_ILIKE
, "~~*",
15043 $1, (Node
*) n
, @
2);
15045 | a_expr NOT_LA ILIKE a_expr %prec NOT_LA
15047 $$
= (Node
*) makeSimpleA_Expr
(AEXPR_ILIKE
, "!~~*",
15050 | a_expr NOT_LA ILIKE a_expr ESCAPE a_expr %prec NOT_LA
15052 FuncCall
*n
= makeFuncCall
(SystemFuncName
("like_escape"),
15053 list_make2
($4, $6),
15054 COERCE_EXPLICIT_CALL
,
15056 $$
= (Node
*) makeSimpleA_Expr
(AEXPR_ILIKE
, "!~~*",
15057 $1, (Node
*) n
, @
2);
15060 | a_expr SIMILAR TO a_expr %prec SIMILAR
15062 FuncCall
*n
= makeFuncCall
(SystemFuncName
("similar_to_escape"),
15064 COERCE_EXPLICIT_CALL
,
15066 $$
= (Node
*) makeSimpleA_Expr
(AEXPR_SIMILAR
, "~",
15067 $1, (Node
*) n
, @
2);
15069 | a_expr SIMILAR TO a_expr ESCAPE a_expr %prec SIMILAR
15071 FuncCall
*n
= makeFuncCall
(SystemFuncName
("similar_to_escape"),
15072 list_make2
($4, $6),
15073 COERCE_EXPLICIT_CALL
,
15075 $$
= (Node
*) makeSimpleA_Expr
(AEXPR_SIMILAR
, "~",
15076 $1, (Node
*) n
, @
2);
15078 | a_expr NOT_LA SIMILAR TO a_expr %prec NOT_LA
15080 FuncCall
*n
= makeFuncCall
(SystemFuncName
("similar_to_escape"),
15082 COERCE_EXPLICIT_CALL
,
15084 $$
= (Node
*) makeSimpleA_Expr
(AEXPR_SIMILAR
, "!~",
15085 $1, (Node
*) n
, @
2);
15087 | a_expr NOT_LA SIMILAR TO a_expr ESCAPE a_expr %prec NOT_LA
15089 FuncCall
*n
= makeFuncCall
(SystemFuncName
("similar_to_escape"),
15090 list_make2
($5, $7),
15091 COERCE_EXPLICIT_CALL
,
15093 $$
= (Node
*) makeSimpleA_Expr
(AEXPR_SIMILAR
, "!~",
15094 $1, (Node
*) n
, @
2);
15098 * Define SQL-style Null test clause.
15099 * Allow two forms described in the standard:
15102 * Allow two SQL extensions
15106 | a_expr IS NULL_P %prec IS
15108 NullTest
*n
= makeNode
(NullTest
);
15110 n
->arg
= (Expr
*) $1;
15111 n
->nulltesttype
= IS_NULL
;
15117 NullTest
*n
= makeNode
(NullTest
);
15119 n
->arg
= (Expr
*) $1;
15120 n
->nulltesttype
= IS_NULL
;
15124 | a_expr IS NOT NULL_P %prec IS
15126 NullTest
*n
= makeNode
(NullTest
);
15128 n
->arg
= (Expr
*) $1;
15129 n
->nulltesttype
= IS_NOT_NULL
;
15135 NullTest
*n
= makeNode
(NullTest
);
15137 n
->arg
= (Expr
*) $1;
15138 n
->nulltesttype
= IS_NOT_NULL
;
15144 if
(list_length
($1) != 2)
15146 (errcode
(ERRCODE_SYNTAX_ERROR
),
15147 errmsg
("wrong number of parameters on left side of OVERLAPS expression"),
15148 parser_errposition
(@
1)));
15149 if
(list_length
($3) != 2)
15151 (errcode
(ERRCODE_SYNTAX_ERROR
),
15152 errmsg
("wrong number of parameters on right side of OVERLAPS expression"),
15153 parser_errposition
(@
3)));
15154 $$
= (Node
*) makeFuncCall
(SystemFuncName
("overlaps"),
15155 list_concat
($1, $3),
15159 | a_expr IS TRUE_P %prec IS
15161 BooleanTest
*b
= makeNode
(BooleanTest
);
15163 b
->arg
= (Expr
*) $1;
15164 b
->booltesttype
= IS_TRUE
;
15168 | a_expr IS NOT TRUE_P %prec IS
15170 BooleanTest
*b
= makeNode
(BooleanTest
);
15172 b
->arg
= (Expr
*) $1;
15173 b
->booltesttype
= IS_NOT_TRUE
;
15177 | a_expr IS FALSE_P %prec IS
15179 BooleanTest
*b
= makeNode
(BooleanTest
);
15181 b
->arg
= (Expr
*) $1;
15182 b
->booltesttype
= IS_FALSE
;
15186 | a_expr IS NOT FALSE_P %prec IS
15188 BooleanTest
*b
= makeNode
(BooleanTest
);
15190 b
->arg
= (Expr
*) $1;
15191 b
->booltesttype
= IS_NOT_FALSE
;
15195 | a_expr IS UNKNOWN %prec IS
15197 BooleanTest
*b
= makeNode
(BooleanTest
);
15199 b
->arg
= (Expr
*) $1;
15200 b
->booltesttype
= IS_UNKNOWN
;
15204 | a_expr IS NOT UNKNOWN %prec IS
15206 BooleanTest
*b
= makeNode
(BooleanTest
);
15208 b
->arg
= (Expr
*) $1;
15209 b
->booltesttype
= IS_NOT_UNKNOWN
;
15213 | a_expr IS DISTINCT FROM a_expr %prec IS
15215 $$
= (Node
*) makeSimpleA_Expr
(AEXPR_DISTINCT
, "=", $1, $5, @
2);
15217 | a_expr IS NOT DISTINCT FROM a_expr %prec IS
15219 $$
= (Node
*) makeSimpleA_Expr
(AEXPR_NOT_DISTINCT
, "=", $1, $6, @
2);
15221 | a_expr BETWEEN opt_asymmetric b_expr AND a_expr %prec BETWEEN
15223 $$
= (Node
*) makeSimpleA_Expr
(AEXPR_BETWEEN
,
15226 (Node
*) list_make2
($4, $6),
15229 | a_expr NOT_LA BETWEEN opt_asymmetric b_expr AND a_expr %prec NOT_LA
15231 $$
= (Node
*) makeSimpleA_Expr
(AEXPR_NOT_BETWEEN
,
15234 (Node
*) list_make2
($5, $7),
15237 | a_expr BETWEEN SYMMETRIC b_expr AND a_expr %prec BETWEEN
15239 $$
= (Node
*) makeSimpleA_Expr
(AEXPR_BETWEEN_SYM
,
15240 "BETWEEN SYMMETRIC",
15242 (Node
*) list_make2
($4, $6),
15245 | a_expr NOT_LA BETWEEN SYMMETRIC b_expr AND a_expr %prec NOT_LA
15247 $$
= (Node
*) makeSimpleA_Expr
(AEXPR_NOT_BETWEEN_SYM
,
15248 "NOT BETWEEN SYMMETRIC",
15250 (Node
*) list_make2
($5, $7),
15253 | a_expr IN_P in_expr
15255 /* in_expr returns a SubLink or a list of a_exprs */
15256 if
(IsA
($3, SubLink
))
15258 /* generate foo = ANY (subquery) */
15259 SubLink
*n
= (SubLink
*) $3;
15261 n
->subLinkType
= ANY_SUBLINK
;
15264 n
->operName
= NIL
; /* show it's IN not = ANY */
15270 /* generate scalar IN expression */
15271 $$
= (Node
*) makeSimpleA_Expr
(AEXPR_IN
, "=", $1, $3, @
2);
15274 | a_expr NOT_LA IN_P in_expr %prec NOT_LA
15276 /* in_expr returns a SubLink or a list of a_exprs */
15277 if
(IsA
($4, SubLink
))
15279 /* generate NOT (foo = ANY (subquery)) */
15280 /* Make an = ANY node */
15281 SubLink
*n
= (SubLink
*) $4;
15283 n
->subLinkType
= ANY_SUBLINK
;
15286 n
->operName
= NIL
; /* show it's IN not = ANY */
15288 /* Stick a NOT on top; must have same parse location */
15289 $$
= makeNotExpr
((Node
*) n
, @
2);
15293 /* generate scalar NOT IN expression */
15294 $$
= (Node
*) makeSimpleA_Expr
(AEXPR_IN
, "<>", $1, $4, @
2);
15297 | a_expr subquery_Op sub_type select_with_parens %prec Op
15299 SubLink
*n
= makeNode
(SubLink
);
15301 n
->subLinkType
= $3;
15309 | a_expr subquery_Op sub_type
'(' a_expr
')' %prec Op
15311 if
($3 == ANY_SUBLINK
)
15312 $$
= (Node
*) makeA_Expr
(AEXPR_OP_ANY
, $2, $1, $5, @
2);
15314 $$
= (Node
*) makeA_Expr
(AEXPR_OP_ALL
, $2, $1, $5, @
2);
15316 | UNIQUE opt_unique_null_treatment select_with_parens
15318 /* Not sure how to get rid of the parentheses
15319 * but there are lots of shift/reduce errors without them.
15321 * Should be able to implement this by plopping the entire
15322 * select into a node, then transforming the target expressions
15323 * from whatever they are into count(*), and testing the
15324 * entire result equal to one.
15325 * But, will probably implement a separate node in the executor.
15328 (errcode
(ERRCODE_FEATURE_NOT_SUPPORTED
),
15329 errmsg
("UNIQUE predicate is not yet implemented"),
15330 parser_errposition
(@
1)));
15332 | a_expr IS DOCUMENT_P %prec IS
15334 $$
= makeXmlExpr
(IS_DOCUMENT
, NULL
, NIL
,
15335 list_make1
($1), @
2);
15337 | a_expr IS NOT DOCUMENT_P %prec IS
15339 $$
= makeNotExpr
(makeXmlExpr
(IS_DOCUMENT
, NULL
, NIL
,
15340 list_make1
($1), @
2),
15343 | a_expr IS NORMALIZED %prec IS
15345 $$
= (Node
*) makeFuncCall
(SystemFuncName
("is_normalized"),
15350 | a_expr IS unicode_normal_form NORMALIZED %prec IS
15352 $$
= (Node
*) makeFuncCall
(SystemFuncName
("is_normalized"),
15353 list_make2
($1, makeStringConst
($3, @
3)),
15357 | a_expr IS NOT NORMALIZED %prec IS
15359 $$
= makeNotExpr
((Node
*) makeFuncCall
(SystemFuncName
("is_normalized"),
15365 | a_expr IS NOT unicode_normal_form NORMALIZED %prec IS
15367 $$
= makeNotExpr
((Node
*) makeFuncCall
(SystemFuncName
("is_normalized"),
15368 list_make2
($1, makeStringConst
($4, @
4)),
15373 | a_expr IS json_predicate_type_constraint
15374 json_key_uniqueness_constraint_opt %prec IS
15376 JsonFormat
*format
= makeJsonFormat
(JS_FORMAT_DEFAULT
, JS_ENC_DEFAULT
, -1);
15378 $$
= makeJsonIsPredicate
($1, format
, $3, $4, @
1);
15381 * Required by SQL/JSON, but there are conflicts
15384 IS json_predicate_type_constraint
15385 json_key_uniqueness_constraint_opt %prec IS
15387 $$ = makeJsonIsPredicate($1, $2, $4, $5, @1);
15391 json_predicate_type_constraint
15392 json_key_uniqueness_constraint_opt %prec IS
15394 JsonFormat
*format
= makeJsonFormat
(JS_FORMAT_DEFAULT
, JS_ENC_DEFAULT
, -1);
15396 $$
= makeNotExpr
(makeJsonIsPredicate
($1, format
, $4, $5, @
1), @
1);
15399 * Required by SQL/JSON, but there are conflicts
15403 json_predicate_type_constraint
15404 json_key_uniqueness_constraint_opt %prec IS
15406 $$ = makeNotExpr(makeJsonIsPredicate($1, $2, $5, $6, @1), @1);
15412 * The SQL spec only allows DEFAULT in "contextually typed
15413 * expressions", but for us, it's easier to allow it in
15414 * any a_expr and then throw error during parse analysis
15415 * if it's in an inappropriate context. This way also
15416 * lets us say something smarter than "syntax error".
15418 SetToDefault
*n
= makeNode
(SetToDefault
);
15420 /* parse analysis will fill in the rest */
15427 * Restricted expressions
15429 * b_expr is a subset of the complete expression syntax defined by a_expr.
15431 * Presently, AND, NOT, IS, and IN are the a_expr keywords that would
15432 * cause trouble in the places where b_expr is used. For simplicity, we
15433 * just eliminate all the boolean-keyword-operator productions from b_expr.
15437 | b_expr TYPECAST Typename
15438 { $$
= makeTypeCast
($1, $3, @
2); }
15439 |
'+' b_expr %prec UMINUS
15440 { $$
= (Node
*) makeSimpleA_Expr
(AEXPR_OP
, "+", NULL
, $2, @
1); }
15441 |
'-' b_expr %prec UMINUS
15442 { $$
= doNegate
($2, @
1); }
15443 | b_expr
'+' b_expr
15444 { $$
= (Node
*) makeSimpleA_Expr
(AEXPR_OP
, "+", $1, $3, @
2); }
15445 | b_expr
'-' b_expr
15446 { $$
= (Node
*) makeSimpleA_Expr
(AEXPR_OP
, "-", $1, $3, @
2); }
15447 | b_expr
'*' b_expr
15448 { $$
= (Node
*) makeSimpleA_Expr
(AEXPR_OP
, "*", $1, $3, @
2); }
15449 | b_expr
'/' b_expr
15450 { $$
= (Node
*) makeSimpleA_Expr
(AEXPR_OP
, "/", $1, $3, @
2); }
15451 | b_expr
'%' b_expr
15452 { $$
= (Node
*) makeSimpleA_Expr
(AEXPR_OP
, "%", $1, $3, @
2); }
15453 | b_expr
'^' b_expr
15454 { $$
= (Node
*) makeSimpleA_Expr
(AEXPR_OP
, "^", $1, $3, @
2); }
15455 | b_expr
'<' b_expr
15456 { $$
= (Node
*) makeSimpleA_Expr
(AEXPR_OP
, "<", $1, $3, @
2); }
15457 | b_expr
'>' b_expr
15458 { $$
= (Node
*) makeSimpleA_Expr
(AEXPR_OP
, ">", $1, $3, @
2); }
15459 | b_expr
'=' b_expr
15460 { $$
= (Node
*) makeSimpleA_Expr
(AEXPR_OP
, "=", $1, $3, @
2); }
15461 | b_expr LESS_EQUALS b_expr
15462 { $$
= (Node
*) makeSimpleA_Expr
(AEXPR_OP
, "<=", $1, $3, @
2); }
15463 | b_expr GREATER_EQUALS b_expr
15464 { $$
= (Node
*) makeSimpleA_Expr
(AEXPR_OP
, ">=", $1, $3, @
2); }
15465 | b_expr NOT_EQUALS b_expr
15466 { $$
= (Node
*) makeSimpleA_Expr
(AEXPR_OP
, "<>", $1, $3, @
2); }
15467 | b_expr qual_Op b_expr %prec Op
15468 { $$
= (Node
*) makeA_Expr
(AEXPR_OP
, $2, $1, $3, @
2); }
15469 | qual_Op b_expr %prec Op
15470 { $$
= (Node
*) makeA_Expr
(AEXPR_OP
, $1, NULL
, $2, @
1); }
15471 | b_expr IS DISTINCT FROM b_expr %prec IS
15473 $$
= (Node
*) makeSimpleA_Expr
(AEXPR_DISTINCT
, "=", $1, $5, @
2);
15475 | b_expr IS NOT DISTINCT FROM b_expr %prec IS
15477 $$
= (Node
*) makeSimpleA_Expr
(AEXPR_NOT_DISTINCT
, "=", $1, $6, @
2);
15479 | b_expr IS DOCUMENT_P %prec IS
15481 $$
= makeXmlExpr
(IS_DOCUMENT
, NULL
, NIL
,
15482 list_make1
($1), @
2);
15484 | b_expr IS NOT DOCUMENT_P %prec IS
15486 $$
= makeNotExpr
(makeXmlExpr
(IS_DOCUMENT
, NULL
, NIL
,
15487 list_make1
($1), @
2),
15493 * Productions that can be used in both a_expr and b_expr.
15495 * Note: productions that refer recursively to a_expr or b_expr mostly
15496 * cannot appear here. However, it's OK to refer to a_exprs that occur
15497 * inside parentheses, such as function arguments; that cannot introduce
15498 * ambiguity to the b_expr syntax.
15500 c_expr: columnref
{ $$
= $1; }
15501 | AexprConst
{ $$
= $1; }
15502 | PARAM opt_indirection
15504 ParamRef
*p
= makeNode
(ParamRef
);
15510 A_Indirection
*n
= makeNode
(A_Indirection
);
15512 n
->arg
= (Node
*) p
;
15513 n
->indirection
= check_indirection
($2, yyscanner
);
15519 |
'(' a_expr
')' opt_indirection
15523 A_Indirection
*n
= makeNode
(A_Indirection
);
15526 n
->indirection
= check_indirection
($4, yyscanner
);
15536 | select_with_parens %prec UMINUS
15538 SubLink
*n
= makeNode
(SubLink
);
15540 n
->subLinkType
= EXPR_SUBLINK
;
15542 n
->testexpr
= NULL
;
15548 | select_with_parens indirection
15551 * Because the select_with_parens nonterminal is designed
15552 * to "eat" as many levels of parens as possible, the
15553 * '(' a_expr ')' opt_indirection production above will
15554 * fail to match a sub-SELECT with indirection decoration;
15555 * the sub-SELECT won't be regarded as an a_expr as long
15556 * as there are parens around it. To support applying
15557 * subscripting or field selection to a sub-SELECT result,
15558 * we need this redundant-looking production.
15560 SubLink
*n
= makeNode
(SubLink
);
15561 A_Indirection
*a
= makeNode
(A_Indirection
);
15563 n
->subLinkType
= EXPR_SUBLINK
;
15565 n
->testexpr
= NULL
;
15569 a
->arg
= (Node
*) n
;
15570 a
->indirection
= check_indirection
($2, yyscanner
);
15573 | EXISTS select_with_parens
15575 SubLink
*n
= makeNode
(SubLink
);
15577 n
->subLinkType
= EXISTS_SUBLINK
;
15579 n
->testexpr
= NULL
;
15585 | ARRAY select_with_parens
15587 SubLink
*n
= makeNode
(SubLink
);
15589 n
->subLinkType
= ARRAY_SUBLINK
;
15591 n
->testexpr
= NULL
;
15599 A_ArrayExpr
*n
= castNode
(A_ArrayExpr
, $2);
15601 /* point outermost A_ArrayExpr to the ARRAY keyword */
15607 RowExpr
*r
= makeNode
(RowExpr
);
15610 r
->row_typeid
= InvalidOid
; /* not analyzed yet */
15611 r
->colnames
= NIL
; /* to be filled in during analysis */
15612 r
->row_format
= COERCE_EXPLICIT_CALL
; /* abuse */
15618 RowExpr
*r
= makeNode
(RowExpr
);
15621 r
->row_typeid
= InvalidOid
; /* not analyzed yet */
15622 r
->colnames
= NIL
; /* to be filled in during analysis */
15623 r
->row_format
= COERCE_IMPLICIT_CAST
; /* abuse */
15627 | GROUPING
'(' expr_list
')'
15629 GroupingFunc
*g
= makeNode
(GroupingFunc
);
15637 func_application: func_name
'(' ')'
15639 $$
= (Node
*) makeFuncCall
($1, NIL
,
15640 COERCE_EXPLICIT_CALL
,
15643 | func_name
'(' func_arg_list opt_sort_clause
')'
15645 FuncCall
*n
= makeFuncCall
($1, $3,
15646 COERCE_EXPLICIT_CALL
,
15652 | func_name
'(' VARIADIC func_arg_expr opt_sort_clause
')'
15654 FuncCall
*n
= makeFuncCall
($1, list_make1
($4),
15655 COERCE_EXPLICIT_CALL
,
15658 n
->func_variadic
= true
;
15662 | func_name
'(' func_arg_list
',' VARIADIC func_arg_expr opt_sort_clause
')'
15664 FuncCall
*n
= makeFuncCall
($1, lappend
($3, $6),
15665 COERCE_EXPLICIT_CALL
,
15668 n
->func_variadic
= true
;
15672 | func_name
'(' ALL func_arg_list opt_sort_clause
')'
15674 FuncCall
*n
= makeFuncCall
($1, $4,
15675 COERCE_EXPLICIT_CALL
,
15679 /* Ideally we'd mark the FuncCall node to indicate
15680 * "must be an aggregate", but there's no provision
15681 * for that in FuncCall at the moment.
15685 | func_name
'(' DISTINCT func_arg_list opt_sort_clause
')'
15687 FuncCall
*n
= makeFuncCall
($1, $4,
15688 COERCE_EXPLICIT_CALL
,
15692 n
->agg_distinct
= true
;
15695 | func_name
'(' '*' ')'
15698 * We consider AGGREGATE(*) to invoke a parameterless
15699 * aggregate. This does the right thing for COUNT(*),
15700 * and there are no other aggregates in SQL that accept
15701 * '*' as parameter.
15703 * The FuncCall node is also marked agg_star = true,
15704 * so that later processing can detect what the argument
15707 FuncCall
*n
= makeFuncCall
($1, NIL
,
15708 COERCE_EXPLICIT_CALL
,
15711 n
->agg_star
= true
;
15718 * func_expr and its cousin func_expr_windowless are split out from c_expr just
15719 * so that we have classifications for "everything that is a function call or
15720 * looks like one". This isn't very important, but it saves us having to
15721 * document which variants are legal in places like "FROM function()" or the
15722 * backwards-compatible functional-index syntax for CREATE INDEX.
15723 * (Note that many of the special SQL functions wouldn't actually make any
15724 * sense as functional index entries, but we ignore that consideration here.)
15726 func_expr: func_application within_group_clause filter_clause over_clause
15728 FuncCall
*n
= (FuncCall
*) $1;
15731 * The order clause for WITHIN GROUP and the one for
15732 * plain-aggregate ORDER BY share a field, so we have to
15733 * check here that at most one is present. We also check
15734 * for DISTINCT and VARIADIC here to give a better error
15735 * location. Other consistency checks are deferred to
15740 if
(n
->agg_order
!= NIL
)
15742 (errcode
(ERRCODE_SYNTAX_ERROR
),
15743 errmsg
("cannot use multiple ORDER BY clauses with WITHIN GROUP"),
15744 parser_errposition
(@
2)));
15745 if
(n
->agg_distinct
)
15747 (errcode
(ERRCODE_SYNTAX_ERROR
),
15748 errmsg
("cannot use DISTINCT with WITHIN GROUP"),
15749 parser_errposition
(@
2)));
15750 if
(n
->func_variadic
)
15752 (errcode
(ERRCODE_SYNTAX_ERROR
),
15753 errmsg
("cannot use VARIADIC with WITHIN GROUP"),
15754 parser_errposition
(@
2)));
15756 n
->agg_within_group
= true
;
15758 n
->agg_filter
= $3;
15762 | json_aggregate_func filter_clause over_clause
15764 JsonAggConstructor
*n
= IsA
($1, JsonObjectAgg
) ?
15765 ((JsonObjectAgg
*) $1)->constructor
:
15766 ((JsonArrayAgg
*) $1)->constructor
;
15768 n
->agg_filter
= $2;
15772 | func_expr_common_subexpr
15777 * Like func_expr but does not accept WINDOW functions directly
15778 * (but they can still be contained in arguments for functions etc).
15779 * Use this when window expressions are not allowed, where needed to
15780 * disambiguate the grammar (e.g. in CREATE INDEX).
15782 func_expr_windowless:
15783 func_application
{ $$
= $1; }
15784 | func_expr_common_subexpr
{ $$
= $1; }
15785 | json_aggregate_func
{ $$
= $1; }
15789 * Special expressions that are considered to be functions.
15791 func_expr_common_subexpr:
15792 COLLATION FOR
'(' a_expr
')'
15794 $$
= (Node
*) makeFuncCall
(SystemFuncName
("pg_collation_for"),
15801 $$
= makeSQLValueFunction
(SVFOP_CURRENT_DATE
, -1, @
1);
15805 $$
= makeSQLValueFunction
(SVFOP_CURRENT_TIME
, -1, @
1);
15807 | CURRENT_TIME
'(' Iconst
')'
15809 $$
= makeSQLValueFunction
(SVFOP_CURRENT_TIME_N
, $3, @
1);
15811 | CURRENT_TIMESTAMP
15813 $$
= makeSQLValueFunction
(SVFOP_CURRENT_TIMESTAMP
, -1, @
1);
15815 | CURRENT_TIMESTAMP
'(' Iconst
')'
15817 $$
= makeSQLValueFunction
(SVFOP_CURRENT_TIMESTAMP_N
, $3, @
1);
15821 $$
= makeSQLValueFunction
(SVFOP_LOCALTIME
, -1, @
1);
15823 | LOCALTIME
'(' Iconst
')'
15825 $$
= makeSQLValueFunction
(SVFOP_LOCALTIME_N
, $3, @
1);
15829 $$
= makeSQLValueFunction
(SVFOP_LOCALTIMESTAMP
, -1, @
1);
15831 | LOCALTIMESTAMP
'(' Iconst
')'
15833 $$
= makeSQLValueFunction
(SVFOP_LOCALTIMESTAMP_N
, $3, @
1);
15837 $$
= makeSQLValueFunction
(SVFOP_CURRENT_ROLE
, -1, @
1);
15841 $$
= makeSQLValueFunction
(SVFOP_CURRENT_USER
, -1, @
1);
15845 $$
= makeSQLValueFunction
(SVFOP_SESSION_USER
, -1, @
1);
15849 $$
= (Node
*) makeFuncCall
(SystemFuncName
("system_user"),
15856 $$
= makeSQLValueFunction
(SVFOP_USER
, -1, @
1);
15860 $$
= makeSQLValueFunction
(SVFOP_CURRENT_CATALOG
, -1, @
1);
15864 $$
= makeSQLValueFunction
(SVFOP_CURRENT_SCHEMA
, -1, @
1);
15866 | CAST
'(' a_expr AS Typename
')'
15867 { $$
= makeTypeCast
($3, $5, @
1); }
15868 | EXTRACT
'(' extract_list
')'
15870 $$
= (Node
*) makeFuncCall
(SystemFuncName
("extract"),
15875 | NORMALIZE
'(' a_expr
')'
15877 $$
= (Node
*) makeFuncCall
(SystemFuncName
("normalize"),
15882 | NORMALIZE
'(' a_expr
',' unicode_normal_form
')'
15884 $$
= (Node
*) makeFuncCall
(SystemFuncName
("normalize"),
15885 list_make2
($3, makeStringConst
($5, @
5)),
15889 | OVERLAY
'(' overlay_list
')'
15891 $$
= (Node
*) makeFuncCall
(SystemFuncName
("overlay"),
15896 | OVERLAY
'(' func_arg_list_opt
')'
15899 * allow functions named overlay() to be called without
15902 $$
= (Node
*) makeFuncCall
(list_make1
(makeString
("overlay")),
15904 COERCE_EXPLICIT_CALL
,
15907 | POSITION
'(' position_list
')'
15910 * position(A in B) is converted to position(B, A)
15912 * We deliberately don't offer a "plain syntax" option
15913 * for position(), because the reversal of the arguments
15914 * creates too much risk of confusion.
15916 $$
= (Node
*) makeFuncCall
(SystemFuncName
("position"),
15921 | SUBSTRING
'(' substr_list
')'
15923 /* substring(A from B for C) is converted to
15924 * substring(A, B, C) - thomas 2000-11-28
15926 $$
= (Node
*) makeFuncCall
(SystemFuncName
("substring"),
15931 | SUBSTRING
'(' func_arg_list_opt
')'
15934 * allow functions named substring() to be called without
15937 $$
= (Node
*) makeFuncCall
(list_make1
(makeString
("substring")),
15939 COERCE_EXPLICIT_CALL
,
15942 | TREAT
'(' a_expr AS Typename
')'
15944 /* TREAT(expr AS target) converts expr of a particular type to target,
15945 * which is defined to be a subtype of the original expression.
15946 * In SQL99, this is intended for use with structured UDTs,
15947 * but let's make this a generally useful form allowing stronger
15948 * coercions than are handled by implicit casting.
15950 * Convert SystemTypeName() to SystemFuncName() even though
15951 * at the moment they result in the same thing.
15953 $$
= (Node
*) makeFuncCall
(SystemFuncName
(strVal
(llast
($5->names
))),
15955 COERCE_EXPLICIT_CALL
,
15958 | TRIM
'(' BOTH trim_list
')'
15960 /* various trim expressions are defined in SQL
15961 * - thomas 1997-07-19
15963 $$
= (Node
*) makeFuncCall
(SystemFuncName
("btrim"),
15968 | TRIM
'(' LEADING trim_list
')'
15970 $$
= (Node
*) makeFuncCall
(SystemFuncName
("ltrim"),
15975 | TRIM
'(' TRAILING trim_list
')'
15977 $$
= (Node
*) makeFuncCall
(SystemFuncName
("rtrim"),
15982 | TRIM
'(' trim_list
')'
15984 $$
= (Node
*) makeFuncCall
(SystemFuncName
("btrim"),
15989 | NULLIF
'(' a_expr
',' a_expr
')'
15991 $$
= (Node
*) makeSimpleA_Expr
(AEXPR_NULLIF
, "=", $3, $5, @
1);
15993 | COALESCE
'(' expr_list
')'
15995 CoalesceExpr
*c
= makeNode
(CoalesceExpr
);
16001 | GREATEST
'(' expr_list
')'
16003 MinMaxExpr
*v
= makeNode
(MinMaxExpr
);
16006 v
->op
= IS_GREATEST
;
16010 | LEAST
'(' expr_list
')'
16012 MinMaxExpr
*v
= makeNode
(MinMaxExpr
);
16019 | XMLCONCAT
'(' expr_list
')'
16021 $$
= makeXmlExpr
(IS_XMLCONCAT
, NULL
, NIL
, $3, @
1);
16023 | XMLELEMENT
'(' NAME_P ColLabel
')'
16025 $$
= makeXmlExpr
(IS_XMLELEMENT
, $4, NIL
, NIL
, @
1);
16027 | XMLELEMENT
'(' NAME_P ColLabel
',' xml_attributes
')'
16029 $$
= makeXmlExpr
(IS_XMLELEMENT
, $4, $6, NIL
, @
1);
16031 | XMLELEMENT
'(' NAME_P ColLabel
',' expr_list
')'
16033 $$
= makeXmlExpr
(IS_XMLELEMENT
, $4, NIL
, $6, @
1);
16035 | XMLELEMENT
'(' NAME_P ColLabel
',' xml_attributes
',' expr_list
')'
16037 $$
= makeXmlExpr
(IS_XMLELEMENT
, $4, $6, $8, @
1);
16039 | XMLEXISTS
'(' c_expr xmlexists_argument
')'
16041 /* xmlexists(A PASSING [BY REF] B [BY REF]) is
16042 * converted to xmlexists(A, B)*/
16043 $$
= (Node
*) makeFuncCall
(SystemFuncName
("xmlexists"),
16044 list_make2
($3, $4),
16048 | XMLFOREST
'(' xml_attribute_list
')'
16050 $$
= makeXmlExpr
(IS_XMLFOREST
, NULL
, $3, NIL
, @
1);
16052 | XMLPARSE
'(' document_or_content a_expr xml_whitespace_option
')'
16054 XmlExpr
*x
= (XmlExpr
*)
16055 makeXmlExpr
(IS_XMLPARSE
, NULL
, NIL
,
16056 list_make2
($4, makeBoolAConst
($5, -1)),
16062 | XMLPI
'(' NAME_P ColLabel
')'
16064 $$
= makeXmlExpr
(IS_XMLPI
, $4, NULL
, NIL
, @
1);
16066 | XMLPI
'(' NAME_P ColLabel
',' a_expr
')'
16068 $$
= makeXmlExpr
(IS_XMLPI
, $4, NULL
, list_make1
($6), @
1);
16070 | XMLROOT
'(' a_expr
',' xml_root_version opt_xml_root_standalone
')'
16072 $$
= makeXmlExpr
(IS_XMLROOT
, NULL
, NIL
,
16073 list_make3
($3, $5, $6), @
1);
16075 | XMLSERIALIZE
'(' document_or_content a_expr AS SimpleTypename xml_indent_option
')'
16077 XmlSerialize
*n
= makeNode
(XmlSerialize
);
16086 | JSON_OBJECT
'(' func_arg_list
')'
16088 /* Support for legacy (non-standard) json_object() */
16089 $$
= (Node
*) makeFuncCall
(SystemFuncName
("json_object"),
16090 $3, COERCE_EXPLICIT_CALL
, @
1);
16092 | JSON_OBJECT
'(' json_name_and_value_list
16093 json_object_constructor_null_clause_opt
16094 json_key_uniqueness_constraint_opt
16095 json_returning_clause_opt
')'
16097 JsonObjectConstructor
*n
= makeNode
(JsonObjectConstructor
);
16100 n
->absent_on_null
= $4;
16102 n
->output
= (JsonOutput
*) $6;
16106 | JSON_OBJECT
'(' json_returning_clause_opt
')'
16108 JsonObjectConstructor
*n
= makeNode
(JsonObjectConstructor
);
16111 n
->absent_on_null
= false
;
16113 n
->output
= (JsonOutput
*) $3;
16118 json_value_expr_list
16119 json_array_constructor_null_clause_opt
16120 json_returning_clause_opt
16123 JsonArrayConstructor
*n
= makeNode
(JsonArrayConstructor
);
16126 n
->absent_on_null
= $4;
16127 n
->output
= (JsonOutput
*) $5;
16133 json_format_clause_opt
16134 /* json_array_constructor_null_clause_opt */
16135 json_returning_clause_opt
16138 JsonArrayQueryConstructor
*n
= makeNode
(JsonArrayQueryConstructor
);
16141 n
->format
= (JsonFormat
*) $4;
16142 n
->absent_on_null
= true
; /* XXX */
16143 n
->output
= (JsonOutput
*) $5;
16148 json_returning_clause_opt
16151 JsonArrayConstructor
*n
= makeNode
(JsonArrayConstructor
);
16154 n
->absent_on_null
= true
;
16155 n
->output
= (JsonOutput
*) $3;
16159 | JSON
'(' json_value_expr json_key_uniqueness_constraint_opt
')'
16161 JsonParseExpr
*n
= makeNode
(JsonParseExpr
);
16163 n
->expr
= (JsonValueExpr
*) $3;
16164 n
->unique_keys
= $4;
16169 | JSON_SCALAR
'(' a_expr
')'
16171 JsonScalarExpr
*n
= makeNode
(JsonScalarExpr
);
16173 n
->expr
= (Expr
*) $3;
16178 | JSON_SERIALIZE
'(' json_value_expr json_returning_clause_opt
')'
16180 JsonSerializeExpr
*n
= makeNode
(JsonSerializeExpr
);
16182 n
->expr
= (JsonValueExpr
*) $3;
16183 n
->output
= (JsonOutput
*) $4;
16187 | MERGE_ACTION
'(' ')'
16189 MergeSupportFunc
*m
= makeNode
(MergeSupportFunc
);
16191 m
->msftype
= TEXTOID
;
16196 json_value_expr
',' a_expr json_passing_clause_opt
16197 json_returning_clause_opt
16198 json_wrapper_behavior
16199 json_quotes_clause_opt
16200 json_behavior_clause_opt
16203 JsonFuncExpr
*n
= makeNode
(JsonFuncExpr
);
16205 n
->op
= JSON_QUERY_OP
;
16206 n
->context_item
= (JsonValueExpr
*) $3;
16209 n
->output
= (JsonOutput
*) $7;
16212 n
->on_empty
= (JsonBehavior
*) linitial
($10);
16213 n
->on_error
= (JsonBehavior
*) lsecond
($10);
16218 json_value_expr
',' a_expr json_passing_clause_opt
16219 json_on_error_clause_opt
16222 JsonFuncExpr
*n
= makeNode
(JsonFuncExpr
);
16224 n
->op
= JSON_EXISTS_OP
;
16225 n
->context_item
= (JsonValueExpr
*) $3;
16229 n
->on_error
= (JsonBehavior
*) $7;
16234 json_value_expr
',' a_expr json_passing_clause_opt
16235 json_returning_clause_opt
16236 json_behavior_clause_opt
16239 JsonFuncExpr
*n
= makeNode
(JsonFuncExpr
);
16241 n
->op
= JSON_VALUE_OP
;
16242 n
->context_item
= (JsonValueExpr
*) $3;
16245 n
->output
= (JsonOutput
*) $7;
16246 n
->on_empty
= (JsonBehavior
*) linitial
($8);
16247 n
->on_error
= (JsonBehavior
*) lsecond
($8);
16257 xml_root_version: VERSION_P a_expr
16259 | VERSION_P NO VALUE_P
16260 { $$
= makeNullAConst
(-1); }
16263 opt_xml_root_standalone: ',' STANDALONE_P YES_P
16264 { $$
= makeIntConst
(XML_STANDALONE_YES
, -1); }
16265 |
',' STANDALONE_P NO
16266 { $$
= makeIntConst
(XML_STANDALONE_NO
, -1); }
16267 |
',' STANDALONE_P NO VALUE_P
16268 { $$
= makeIntConst
(XML_STANDALONE_NO_VALUE
, -1); }
16270 { $$
= makeIntConst
(XML_STANDALONE_OMITTED
, -1); }
16273 xml_attributes: XMLATTRIBUTES
'(' xml_attribute_list
')' { $$
= $3; }
16276 xml_attribute_list: xml_attribute_el
{ $$
= list_make1
($1); }
16277 | xml_attribute_list
',' xml_attribute_el
{ $$
= lappend
($1, $3); }
16280 xml_attribute_el: a_expr AS ColLabel
16282 $$
= makeNode
(ResTarget
);
16284 $$
->indirection
= NIL
;
16285 $$
->val
= (Node
*) $1;
16290 $$
= makeNode
(ResTarget
);
16292 $$
->indirection
= NIL
;
16293 $$
->val
= (Node
*) $1;
16298 document_or_content: DOCUMENT_P
{ $$
= XMLOPTION_DOCUMENT
; }
16299 | CONTENT_P
{ $$
= XMLOPTION_CONTENT
; }
16302 xml_indent_option: INDENT
{ $$
= true
; }
16303 | NO INDENT
{ $$
= false
; }
16304 |
/*EMPTY*/ { $$
= false
; }
16307 xml_whitespace_option: PRESERVE WHITESPACE_P
{ $$
= true
; }
16308 | STRIP_P WHITESPACE_P
{ $$
= false
; }
16309 |
/*EMPTY*/ { $$
= false
; }
16312 /* We allow several variants for SQL and other compatibility. */
16313 xmlexists_argument:
16318 | PASSING c_expr xml_passing_mech
16322 | PASSING xml_passing_mech c_expr
16326 | PASSING xml_passing_mech c_expr xml_passing_mech
16339 * Aggregate decoration clauses
16341 within_group_clause:
16342 WITHIN GROUP_P
'(' sort_clause
')' { $$
= $4; }
16343 |
/*EMPTY*/ { $$
= NIL
; }
16347 FILTER
'(' WHERE a_expr
')' { $$
= $4; }
16348 |
/*EMPTY*/ { $$
= NULL
; }
16353 * Window Definitions
16356 WINDOW window_definition_list
{ $$
= $2; }
16357 |
/*EMPTY*/ { $$
= NIL
; }
16360 window_definition_list:
16361 window_definition
{ $$
= list_make1
($1); }
16362 | window_definition_list
',' window_definition
16363 { $$
= lappend
($1, $3); }
16367 ColId AS window_specification
16376 over_clause: OVER window_specification
16380 WindowDef
*n
= makeNode
(WindowDef
);
16384 n
->partitionClause
= NIL
;
16385 n
->orderClause
= NIL
;
16386 n
->frameOptions
= FRAMEOPTION_DEFAULTS
;
16387 n
->startOffset
= NULL
;
16388 n
->endOffset
= NULL
;
16396 window_specification: '(' opt_existing_window_name opt_partition_clause
16397 opt_sort_clause opt_frame_clause
')'
16399 WindowDef
*n
= makeNode
(WindowDef
);
16403 n
->partitionClause
= $3;
16404 n
->orderClause
= $4;
16405 /* copy relevant fields of opt_frame_clause */
16406 n
->frameOptions
= $5->frameOptions
;
16407 n
->startOffset
= $5->startOffset
;
16408 n
->endOffset
= $5->endOffset
;
16415 * If we see PARTITION, RANGE, ROWS or GROUPS as the first token after the '('
16416 * of a window_specification, we want the assumption to be that there is
16417 * no existing_window_name; but those keywords are unreserved and so could
16418 * be ColIds. We fix this by making them have the same precedence as IDENT
16419 * and giving the empty production here a slightly higher precedence, so
16420 * that the shift/reduce conflict is resolved in favor of reducing the rule.
16421 * These keywords are thus precluded from being an existing_window_name but
16422 * are not reserved for any other purpose.
16424 opt_existing_window_name: ColId
{ $$
= $1; }
16425 |
/*EMPTY*/ %prec Op
{ $$
= NULL
; }
16428 opt_partition_clause: PARTITION BY expr_list
{ $$
= $3; }
16429 |
/*EMPTY*/ { $$
= NIL
; }
16433 * For frame clauses, we return a WindowDef, but only some fields are used:
16434 * frameOptions, startOffset, and endOffset.
16437 RANGE frame_extent opt_window_exclusion_clause
16441 n
->frameOptions |
= FRAMEOPTION_NONDEFAULT | FRAMEOPTION_RANGE
;
16442 n
->frameOptions |
= $3;
16445 | ROWS frame_extent opt_window_exclusion_clause
16449 n
->frameOptions |
= FRAMEOPTION_NONDEFAULT | FRAMEOPTION_ROWS
;
16450 n
->frameOptions |
= $3;
16453 | GROUPS frame_extent opt_window_exclusion_clause
16457 n
->frameOptions |
= FRAMEOPTION_NONDEFAULT | FRAMEOPTION_GROUPS
;
16458 n
->frameOptions |
= $3;
16463 WindowDef
*n
= makeNode
(WindowDef
);
16465 n
->frameOptions
= FRAMEOPTION_DEFAULTS
;
16466 n
->startOffset
= NULL
;
16467 n
->endOffset
= NULL
;
16472 frame_extent: frame_bound
16476 /* reject invalid cases */
16477 if
(n
->frameOptions
& FRAMEOPTION_START_UNBOUNDED_FOLLOWING
)
16479 (errcode
(ERRCODE_WINDOWING_ERROR
),
16480 errmsg
("frame start cannot be UNBOUNDED FOLLOWING"),
16481 parser_errposition
(@
1)));
16482 if
(n
->frameOptions
& FRAMEOPTION_START_OFFSET_FOLLOWING
)
16484 (errcode
(ERRCODE_WINDOWING_ERROR
),
16485 errmsg
("frame starting from following row cannot end with current row"),
16486 parser_errposition
(@
1)));
16487 n
->frameOptions |
= FRAMEOPTION_END_CURRENT_ROW
;
16490 | BETWEEN frame_bound AND frame_bound
16492 WindowDef
*n1
= $2;
16493 WindowDef
*n2
= $4;
16495 /* form merged options */
16496 int frameOptions
= n1
->frameOptions
;
16497 /* shift converts START_ options to END_ options */
16498 frameOptions |
= n2
->frameOptions
<< 1;
16499 frameOptions |
= FRAMEOPTION_BETWEEN
;
16500 /* reject invalid cases */
16501 if
(frameOptions
& FRAMEOPTION_START_UNBOUNDED_FOLLOWING
)
16503 (errcode
(ERRCODE_WINDOWING_ERROR
),
16504 errmsg
("frame start cannot be UNBOUNDED FOLLOWING"),
16505 parser_errposition
(@
2)));
16506 if
(frameOptions
& FRAMEOPTION_END_UNBOUNDED_PRECEDING
)
16508 (errcode
(ERRCODE_WINDOWING_ERROR
),
16509 errmsg
("frame end cannot be UNBOUNDED PRECEDING"),
16510 parser_errposition
(@
4)));
16511 if
((frameOptions
& FRAMEOPTION_START_CURRENT_ROW
) &&
16512 (frameOptions
& FRAMEOPTION_END_OFFSET_PRECEDING
))
16514 (errcode
(ERRCODE_WINDOWING_ERROR
),
16515 errmsg
("frame starting from current row cannot have preceding rows"),
16516 parser_errposition
(@
4)));
16517 if
((frameOptions
& FRAMEOPTION_START_OFFSET_FOLLOWING
) &&
16518 (frameOptions
& (FRAMEOPTION_END_OFFSET_PRECEDING |
16519 FRAMEOPTION_END_CURRENT_ROW
)))
16521 (errcode
(ERRCODE_WINDOWING_ERROR
),
16522 errmsg
("frame starting from following row cannot have preceding rows"),
16523 parser_errposition
(@
4)));
16524 n1
->frameOptions
= frameOptions
;
16525 n1
->endOffset
= n2
->startOffset
;
16531 * This is used for both frame start and frame end, with output set up on
16532 * the assumption it's frame start; the frame_extent productions must reject
16536 UNBOUNDED PRECEDING
16538 WindowDef
*n
= makeNode
(WindowDef
);
16540 n
->frameOptions
= FRAMEOPTION_START_UNBOUNDED_PRECEDING
;
16541 n
->startOffset
= NULL
;
16542 n
->endOffset
= NULL
;
16545 | UNBOUNDED FOLLOWING
16547 WindowDef
*n
= makeNode
(WindowDef
);
16549 n
->frameOptions
= FRAMEOPTION_START_UNBOUNDED_FOLLOWING
;
16550 n
->startOffset
= NULL
;
16551 n
->endOffset
= NULL
;
16556 WindowDef
*n
= makeNode
(WindowDef
);
16558 n
->frameOptions
= FRAMEOPTION_START_CURRENT_ROW
;
16559 n
->startOffset
= NULL
;
16560 n
->endOffset
= NULL
;
16565 WindowDef
*n
= makeNode
(WindowDef
);
16567 n
->frameOptions
= FRAMEOPTION_START_OFFSET_PRECEDING
;
16568 n
->startOffset
= $1;
16569 n
->endOffset
= NULL
;
16574 WindowDef
*n
= makeNode
(WindowDef
);
16576 n
->frameOptions
= FRAMEOPTION_START_OFFSET_FOLLOWING
;
16577 n
->startOffset
= $1;
16578 n
->endOffset
= NULL
;
16583 opt_window_exclusion_clause:
16584 EXCLUDE CURRENT_P ROW
{ $$
= FRAMEOPTION_EXCLUDE_CURRENT_ROW
; }
16585 | EXCLUDE GROUP_P
{ $$
= FRAMEOPTION_EXCLUDE_GROUP
; }
16586 | EXCLUDE TIES
{ $$
= FRAMEOPTION_EXCLUDE_TIES
; }
16587 | EXCLUDE NO OTHERS
{ $$
= 0; }
16588 |
/*EMPTY*/ { $$
= 0; }
16593 * Supporting nonterminals for expressions.
16596 /* Explicit row production.
16598 * SQL99 allows an optional ROW keyword, so we can now do single-element rows
16599 * without conflicting with the parenthesized a_expr production. Without the
16600 * ROW keyword, there must be more than one a_expr inside the parens.
16602 row: ROW
'(' expr_list
')' { $$
= $3; }
16603 | ROW
'(' ')' { $$
= NIL
; }
16604 |
'(' expr_list
',' a_expr
')' { $$
= lappend
($2, $4); }
16607 explicit_row: ROW
'(' expr_list
')' { $$
= $3; }
16608 | ROW
'(' ')' { $$
= NIL
; }
16611 implicit_row: '(' expr_list
',' a_expr
')' { $$
= lappend
($2, $4); }
16614 sub_type: ANY
{ $$
= ANY_SUBLINK
; }
16615 | SOME
{ $$
= ANY_SUBLINK
; }
16616 | ALL
{ $$
= ALL_SUBLINK
; }
16619 all_Op: Op
{ $$
= $1; }
16620 | MathOp
{ $$
= $1; }
16623 MathOp: '+' { $$
= "+"; }
16624 |
'-' { $$
= "-"; }
16625 |
'*' { $$
= "*"; }
16626 |
'/' { $$
= "/"; }
16627 |
'%' { $$
= "%"; }
16628 |
'^' { $$
= "^"; }
16629 |
'<' { $$
= "<"; }
16630 |
'>' { $$
= ">"; }
16631 |
'=' { $$
= "="; }
16632 | LESS_EQUALS
{ $$
= "<="; }
16633 | GREATER_EQUALS
{ $$
= ">="; }
16634 | NOT_EQUALS
{ $$
= "<>"; }
16638 { $$
= list_make1
(makeString
($1)); }
16639 | OPERATOR
'(' any_operator
')'
16645 { $$
= list_make1
(makeString
($1)); }
16646 | OPERATOR
'(' any_operator
')'
16652 { $$
= list_make1
(makeString
($1)); }
16653 | OPERATOR
'(' any_operator
')'
16656 { $$
= list_make1
(makeString
("~~")); }
16658 { $$
= list_make1
(makeString
("!~~")); }
16660 { $$
= list_make1
(makeString
("~~*")); }
16662 { $$
= list_make1
(makeString
("!~~*")); }
16663 /* cannot put SIMILAR TO here, because SIMILAR TO is a hack.
16664 * the regular expression is preprocessed by a function (similar_to_escape),
16665 * and the ~ operator for posix regular expressions is used.
16666 * x SIMILAR TO y -> x ~ similar_to_escape(y)
16667 * this transformation is made on the fly by the parser upwards.
16668 * however the SubLink structure which handles any/some/all stuff
16669 * is not ready for such a thing.
16675 $$
= list_make1
($1);
16677 | expr_list
',' a_expr
16679 $$
= lappend
($1, $3);
16683 /* function arguments can have names */
16684 func_arg_list: func_arg_expr
16686 $$
= list_make1
($1);
16688 | func_arg_list
',' func_arg_expr
16690 $$
= lappend
($1, $3);
16694 func_arg_expr: a_expr
16698 | param_name COLON_EQUALS a_expr
16700 NamedArgExpr
*na
= makeNode
(NamedArgExpr
);
16703 na
->arg
= (Expr
*) $3;
16704 na
->argnumber
= -1; /* until determined */
16708 | param_name EQUALS_GREATER a_expr
16710 NamedArgExpr
*na
= makeNode
(NamedArgExpr
);
16713 na
->arg
= (Expr
*) $3;
16714 na
->argnumber
= -1; /* until determined */
16720 func_arg_list_opt: func_arg_list
{ $$
= $1; }
16721 |
/*EMPTY*/ { $$
= NIL
; }
16724 type_list: Typename
{ $$
= list_make1
($1); }
16725 | type_list
',' Typename
{ $$
= lappend
($1, $3); }
16728 array_expr: '[' expr_list
']'
16730 $$
= makeAArrayExpr
($2, @
1);
16732 |
'[' array_expr_list
']'
16734 $$
= makeAArrayExpr
($2, @
1);
16738 $$
= makeAArrayExpr
(NIL
, @
1);
16742 array_expr_list: array_expr
{ $$
= list_make1
($1); }
16743 | array_expr_list
',' array_expr
{ $$
= lappend
($1, $3); }
16748 extract_arg FROM a_expr
16750 $$
= list_make2
(makeStringConst
($1, @
1), $3);
16754 /* Allow delimited string Sconst in extract_arg as an SQL extension.
16755 * - thomas 2001-04-12
16759 | YEAR_P
{ $$
= "year"; }
16760 | MONTH_P
{ $$
= "month"; }
16761 | DAY_P
{ $$
= "day"; }
16762 | HOUR_P
{ $$
= "hour"; }
16763 | MINUTE_P
{ $$
= "minute"; }
16764 | SECOND_P
{ $$
= "second"; }
16765 | Sconst
{ $$
= $1; }
16768 unicode_normal_form:
16769 NFC
{ $$
= "NFC"; }
16770 | NFD
{ $$
= "NFD"; }
16771 | NFKC
{ $$
= "NFKC"; }
16772 | NFKD
{ $$
= "NFKD"; }
16775 /* OVERLAY() arguments */
16777 a_expr PLACING a_expr FROM a_expr FOR a_expr
16779 /* overlay(A PLACING B FROM C FOR D) is converted to overlay(A, B, C, D) */
16780 $$
= list_make4
($1, $3, $5, $7);
16782 | a_expr PLACING a_expr FROM a_expr
16784 /* overlay(A PLACING B FROM C) is converted to overlay(A, B, C) */
16785 $$
= list_make3
($1, $3, $5);
16789 /* position_list uses b_expr not a_expr to avoid conflict with general IN */
16791 b_expr IN_P b_expr
{ $$
= list_make2
($3, $1); }
16795 * SUBSTRING() arguments
16797 * Note that SQL:1999 has both
16798 * text FROM int FOR int
16800 * text FROM pattern FOR escape
16802 * In the parser we map them both to a call to the substring() function and
16803 * rely on type resolution to pick the right one.
16805 * In SQL:2003, the second variant was changed to
16806 * text SIMILAR pattern ESCAPE escape
16807 * We could in theory map that to a different function internally, but
16808 * since we still support the SQL:1999 version, we don't. However,
16809 * ruleutils.c will reverse-list the call in the newer style.
16812 a_expr FROM a_expr FOR a_expr
16814 $$
= list_make3
($1, $3, $5);
16816 | a_expr FOR a_expr FROM a_expr
16818 /* not legal per SQL, but might as well allow it */
16819 $$
= list_make3
($1, $5, $3);
16821 | a_expr FROM a_expr
16824 * Because we aren't restricting data types here, this
16825 * syntax can end up resolving to textregexsubstr().
16826 * We've historically allowed that to happen, so continue
16827 * to accept it. However, ruleutils.c will reverse-list
16828 * such a call in regular function call syntax.
16830 $$
= list_make2
($1, $3);
16832 | a_expr FOR a_expr
16834 /* not legal per SQL */
16837 * Since there are no cases where this syntax allows
16838 * a textual FOR value, we forcibly cast the argument
16839 * to int4. The possible matches in pg_proc are
16840 * substring(text,int4) and substring(text,text),
16841 * and we don't want the parser to choose the latter,
16842 * which it is likely to do if the second argument
16843 * is unknown or doesn't have an implicit cast to int4.
16845 $$
= list_make3
($1, makeIntConst
(1, -1),
16847 SystemTypeName
("int4"), -1));
16849 | a_expr SIMILAR a_expr ESCAPE a_expr
16851 $$
= list_make3
($1, $3, $5);
16855 trim_list: a_expr FROM expr_list
{ $$
= lappend
($3, $1); }
16856 | FROM expr_list
{ $$
= $2; }
16857 | expr_list
{ $$
= $1; }
16860 in_expr: select_with_parens
16862 SubLink
*n
= makeNode
(SubLink
);
16865 /* other fields will be filled later */
16868 |
'(' expr_list
')' { $$
= (Node
*) $2; }
16872 * Define SQL-style CASE clause.
16873 * - Full specification
16874 * CASE WHEN a = b THEN c ... ELSE d END
16875 * - Implicit argument
16876 * CASE a WHEN b THEN c ... ELSE d END
16878 case_expr: CASE case_arg when_clause_list case_default END_P
16880 CaseExpr
*c
= makeNode
(CaseExpr
);
16882 c
->casetype
= InvalidOid
; /* not analyzed yet */
16883 c
->arg
= (Expr
*) $2;
16885 c
->defresult
= (Expr
*) $4;
16892 /* There must be at least one */
16893 when_clause
{ $$
= list_make1
($1); }
16894 | when_clause_list when_clause
{ $$
= lappend
($1, $2); }
16898 WHEN a_expr THEN a_expr
16900 CaseWhen
*w
= makeNode
(CaseWhen
);
16902 w
->expr
= (Expr
*) $2;
16903 w
->result
= (Expr
*) $4;
16910 ELSE a_expr
{ $$
= $2; }
16911 |
/*EMPTY*/ { $$
= NULL
; }
16914 case_arg: a_expr
{ $$
= $1; }
16915 |
/*EMPTY*/ { $$
= NULL
; }
16920 $$
= makeColumnRef
($1, NIL
, @
1, yyscanner
);
16922 | ColId indirection
16924 $$
= makeColumnRef
($1, $2, @
1, yyscanner
);
16931 $$
= (Node
*) makeString
($2);
16935 $$
= (Node
*) makeNode
(A_Star
);
16939 A_Indices
*ai
= makeNode
(A_Indices
);
16941 ai
->is_slice
= false
;
16946 |
'[' opt_slice_bound
':' opt_slice_bound
']'
16948 A_Indices
*ai
= makeNode
(A_Indices
);
16950 ai
->is_slice
= true
;
16958 a_expr
{ $$
= $1; }
16959 |
/*EMPTY*/ { $$
= NULL
; }
16963 indirection_el
{ $$
= list_make1
($1); }
16964 | indirection indirection_el
{ $$
= lappend
($1, $2); }
16968 /*EMPTY*/ { $$
= NIL
; }
16969 | opt_indirection indirection_el
{ $$
= lappend
($1, $2); }
16972 opt_asymmetric: ASYMMETRIC
16976 /* SQL/JSON support */
16977 json_passing_clause_opt:
16978 PASSING json_arguments
{ $$
= $2; }
16979 |
/*EMPTY*/ { $$
= NIL
; }
16983 json_argument
{ $$
= list_make1
($1); }
16984 | json_arguments
',' json_argument
{ $$
= lappend
($1, $3); }
16988 json_value_expr AS ColLabel
16990 JsonArgument
*n
= makeNode
(JsonArgument
);
16992 n
->val
= (JsonValueExpr
*) $1;
16998 /* ARRAY is a noise word */
16999 json_wrapper_behavior:
17000 WITHOUT WRAPPER
{ $$
= JSW_NONE
; }
17001 | WITHOUT ARRAY WRAPPER
{ $$
= JSW_NONE
; }
17002 | WITH WRAPPER
{ $$
= JSW_UNCONDITIONAL
; }
17003 | WITH ARRAY WRAPPER
{ $$
= JSW_UNCONDITIONAL
; }
17004 | WITH CONDITIONAL ARRAY WRAPPER
{ $$
= JSW_CONDITIONAL
; }
17005 | WITH UNCONDITIONAL ARRAY WRAPPER
{ $$
= JSW_UNCONDITIONAL
; }
17006 | WITH CONDITIONAL WRAPPER
{ $$
= JSW_CONDITIONAL
; }
17007 | WITH UNCONDITIONAL WRAPPER
{ $$
= JSW_UNCONDITIONAL
; }
17008 |
/* empty */ { $$
= JSW_UNSPEC
; }
17013 { $$
= (Node
*) makeJsonBehavior
(JSON_BEHAVIOR_DEFAULT
, $2, @
1); }
17014 | json_behavior_type
17015 { $$
= (Node
*) makeJsonBehavior
($1, NULL
, @
1); }
17018 json_behavior_type:
17019 ERROR_P
{ $$
= JSON_BEHAVIOR_ERROR
; }
17020 | NULL_P
{ $$
= JSON_BEHAVIOR_NULL
; }
17021 | TRUE_P
{ $$
= JSON_BEHAVIOR_TRUE
; }
17022 | FALSE_P
{ $$
= JSON_BEHAVIOR_FALSE
; }
17023 | UNKNOWN
{ $$
= JSON_BEHAVIOR_UNKNOWN
; }
17024 | EMPTY_P ARRAY
{ $$
= JSON_BEHAVIOR_EMPTY_ARRAY
; }
17025 | EMPTY_P OBJECT_P
{ $$
= JSON_BEHAVIOR_EMPTY_OBJECT
; }
17026 /* non-standard, for Oracle compatibility only */
17027 | EMPTY_P
{ $$
= JSON_BEHAVIOR_EMPTY_ARRAY
; }
17030 json_behavior_clause_opt:
17031 json_behavior ON EMPTY_P
17032 { $$
= list_make2
($1, NULL
); }
17033 | json_behavior ON ERROR_P
17034 { $$
= list_make2
(NULL
, $1); }
17035 | json_behavior ON EMPTY_P json_behavior ON ERROR_P
17036 { $$
= list_make2
($1, $4); }
17038 { $$
= list_make2
(NULL
, NULL
); }
17041 json_on_error_clause_opt:
17042 json_behavior ON ERROR_P
17049 a_expr json_format_clause_opt
17051 /* formatted_expr will be set during parse-analysis. */
17052 $$
= (Node
*) makeJsonValueExpr
((Expr
*) $1, NULL
,
17053 castNode
(JsonFormat
, $2));
17057 json_format_clause:
17058 FORMAT_LA JSON ENCODING name
17062 if
(!pg_strcasecmp
($4, "utf8"))
17063 encoding
= JS_ENC_UTF8
;
17064 else if
(!pg_strcasecmp
($4, "utf16"))
17065 encoding
= JS_ENC_UTF16
;
17066 else if
(!pg_strcasecmp
($4, "utf32"))
17067 encoding
= JS_ENC_UTF32
;
17070 (errcode
(ERRCODE_INVALID_PARAMETER_VALUE
),
17071 errmsg
("unrecognized JSON encoding: %s", $4),
17072 parser_errposition
(@
4)));
17074 $$
= (Node
*) makeJsonFormat
(JS_FORMAT_JSON
, encoding
, @
1);
17078 $$
= (Node
*) makeJsonFormat
(JS_FORMAT_JSON
, JS_ENC_DEFAULT
, @
1);
17082 json_format_clause_opt:
17089 $$
= (Node
*) makeJsonFormat
(JS_FORMAT_DEFAULT
, JS_ENC_DEFAULT
, -1);
17093 json_quotes_clause_opt:
17094 KEEP QUOTES ON SCALAR STRING_P
{ $$
= JS_QUOTES_KEEP
; }
17095 | KEEP QUOTES
{ $$
= JS_QUOTES_KEEP
; }
17096 | OMIT QUOTES ON SCALAR STRING_P
{ $$
= JS_QUOTES_OMIT
; }
17097 | OMIT QUOTES
{ $$
= JS_QUOTES_OMIT
; }
17098 |
/* EMPTY */ { $$
= JS_QUOTES_UNSPEC
; }
17101 json_returning_clause_opt:
17102 RETURNING Typename json_format_clause_opt
17104 JsonOutput
*n
= makeNode
(JsonOutput
);
17107 n
->returning
= makeNode
(JsonReturning
);
17108 n
->returning
->format
= (JsonFormat
*) $3;
17111 |
/* EMPTY */ { $$
= NULL
; }
17115 * We must assign the only-JSON production a precedence less than IDENT in
17116 * order to favor shifting over reduction when JSON is followed by VALUE_P,
17117 * OBJECT_P, or SCALAR. (ARRAY doesn't need that treatment, because it's a
17118 * fully reserved word.) Because json_predicate_type_constraint is always
17119 * followed by json_key_uniqueness_constraint_opt, we also need the only-JSON
17120 * production to have precedence less than WITH and WITHOUT. UNBOUNDED isn't
17121 * really related to this syntax, but it's a convenient choice because it
17122 * already has a precedence less than IDENT for other reasons.
17124 json_predicate_type_constraint:
17125 JSON %prec UNBOUNDED
{ $$
= JS_TYPE_ANY
; }
17126 | JSON VALUE_P
{ $$
= JS_TYPE_ANY
; }
17127 | JSON ARRAY
{ $$
= JS_TYPE_ARRAY
; }
17128 | JSON OBJECT_P
{ $$
= JS_TYPE_OBJECT
; }
17129 | JSON SCALAR
{ $$
= JS_TYPE_SCALAR
; }
17133 * KEYS is a noise word here. To avoid shift/reduce conflicts, assign the
17134 * KEYS-less productions a precedence less than IDENT (i.e., less than KEYS).
17135 * This prevents reducing them when the next token is KEYS.
17137 json_key_uniqueness_constraint_opt:
17138 WITH UNIQUE KEYS
{ $$
= true
; }
17139 | WITH UNIQUE %prec UNBOUNDED
{ $$
= true
; }
17140 | WITHOUT UNIQUE KEYS
{ $$
= false
; }
17141 | WITHOUT UNIQUE %prec UNBOUNDED
{ $$
= false
; }
17142 |
/* EMPTY */ %prec UNBOUNDED
{ $$
= false
; }
17145 json_name_and_value_list:
17146 json_name_and_value
17147 { $$
= list_make1
($1); }
17148 | json_name_and_value_list
',' json_name_and_value
17149 { $$
= lappend
($1, $3); }
17152 json_name_and_value:
17153 /* Supporting this syntax seems to require major surgery
17154 KEY c_expr VALUE_P json_value_expr
17155 { $$ = makeJsonKeyValue($2, $4); }
17158 c_expr VALUE_P json_value_expr
17159 { $$
= makeJsonKeyValue
($1, $3); }
17161 a_expr
':' json_value_expr
17162 { $$
= makeJsonKeyValue
($1, $3); }
17165 /* empty means false for objects, true for arrays */
17166 json_object_constructor_null_clause_opt:
17167 NULL_P ON NULL_P
{ $$
= false
; }
17168 | ABSENT ON NULL_P
{ $$
= true
; }
17169 |
/* EMPTY */ { $$
= false
; }
17172 json_array_constructor_null_clause_opt:
17173 NULL_P ON NULL_P
{ $$
= false
; }
17174 | ABSENT ON NULL_P
{ $$
= true
; }
17175 |
/* EMPTY */ { $$
= true
; }
17178 json_value_expr_list:
17179 json_value_expr
{ $$
= list_make1
($1); }
17180 | json_value_expr_list
',' json_value_expr
{ $$
= lappend
($1, $3);}
17183 json_aggregate_func:
17185 json_name_and_value
17186 json_object_constructor_null_clause_opt
17187 json_key_uniqueness_constraint_opt
17188 json_returning_clause_opt
17191 JsonObjectAgg
*n
= makeNode
(JsonObjectAgg
);
17193 n
->arg
= (JsonKeyValue
*) $3;
17194 n
->absent_on_null
= $4;
17196 n
->constructor
= makeNode
(JsonAggConstructor
);
17197 n
->constructor
->output
= (JsonOutput
*) $6;
17198 n
->constructor
->agg_order
= NULL
;
17199 n
->constructor
->location
= @
1;
17202 | JSON_ARRAYAGG
'('
17204 json_array_aggregate_order_by_clause_opt
17205 json_array_constructor_null_clause_opt
17206 json_returning_clause_opt
17209 JsonArrayAgg
*n
= makeNode
(JsonArrayAgg
);
17211 n
->arg
= (JsonValueExpr
*) $3;
17212 n
->absent_on_null
= $5;
17213 n
->constructor
= makeNode
(JsonAggConstructor
);
17214 n
->constructor
->agg_order
= $4;
17215 n
->constructor
->output
= (JsonOutput
*) $6;
17216 n
->constructor
->location
= @
1;
17221 json_array_aggregate_order_by_clause_opt:
17222 ORDER BY sortby_list
{ $$
= $3; }
17223 |
/* EMPTY */ { $$
= NIL
; }
17226 /*****************************************************************************
17228 * target list for SELECT
17230 *****************************************************************************/
17232 opt_target_list: target_list
{ $$
= $1; }
17233 |
/* EMPTY */ { $$
= NIL
; }
17237 target_el
{ $$
= list_make1
($1); }
17238 | target_list
',' target_el
{ $$
= lappend
($1, $3); }
17241 target_el: a_expr AS ColLabel
17243 $$
= makeNode
(ResTarget
);
17245 $$
->indirection
= NIL
;
17246 $$
->val
= (Node
*) $1;
17249 | a_expr BareColLabel
17251 $$
= makeNode
(ResTarget
);
17253 $$
->indirection
= NIL
;
17254 $$
->val
= (Node
*) $1;
17259 $$
= makeNode
(ResTarget
);
17261 $$
->indirection
= NIL
;
17262 $$
->val
= (Node
*) $1;
17267 ColumnRef
*n
= makeNode
(ColumnRef
);
17269 n
->fields
= list_make1
(makeNode
(A_Star
));
17272 $$
= makeNode
(ResTarget
);
17274 $$
->indirection
= NIL
;
17275 $$
->val
= (Node
*) n
;
17281 /*****************************************************************************
17283 * Names and constants
17285 *****************************************************************************/
17287 qualified_name_list:
17288 qualified_name
{ $$
= list_make1
($1); }
17289 | qualified_name_list
',' qualified_name
{ $$
= lappend
($1, $3); }
17293 * The production for a qualified relation name has to exactly match the
17294 * production for a qualified func_name, because in a FROM clause we cannot
17295 * tell which we are parsing until we see what comes after it ('(' for a
17296 * func_name, something else for a relation). Therefore we allow 'indirection'
17297 * which may contain subscripts, and reject that case in the C code.
17302 $$
= makeRangeVar
(NULL
, $1, @
1);
17304 | ColId indirection
17306 $$
= makeRangeVarFromQualifiedName
($1, $2, @
1, yyscanner
);
17311 { $$
= list_make1
(makeString
($1)); }
17312 | name_list
',' name
17313 { $$
= lappend
($1, makeString
($3)); }
17317 name: ColId
{ $$
= $1; };
17319 attr_name: ColLabel
{ $$
= $1; };
17321 file_name: Sconst
{ $$
= $1; };
17324 * The production for a qualified func_name has to exactly match the
17325 * production for a qualified columnref, because we cannot tell which we
17326 * are parsing until we see what comes after it ('(' or Sconst for a func_name,
17327 * anything else for a columnref). Therefore we allow 'indirection' which
17328 * may contain subscripts, and reject that case in the C code. (If we
17329 * ever implement SQL99-like methods, such syntax may actually become legal!)
17331 func_name: type_function_name
17332 { $$
= list_make1
(makeString
($1)); }
17333 | ColId indirection
17335 $$
= check_func_name
(lcons
(makeString
($1), $2),
17346 $$
= makeIntConst
($1, @
1);
17350 $$
= makeFloatConst
($1, @
1);
17354 $$
= makeStringConst
($1, @
1);
17358 $$
= makeBitStringConst
($1, @
1);
17362 /* This is a bit constant per SQL99:
17363 * Without Feature F511, "BIT data type",
17364 * a <general literal> shall not be a
17365 * <bit string literal> or a <hex string literal>.
17367 $$
= makeBitStringConst
($1, @
1);
17371 /* generic type 'literal' syntax */
17372 TypeName
*t
= makeTypeNameFromNameList
($1);
17375 $$
= makeStringConstCast
($2, @
2, t
);
17377 | func_name
'(' func_arg_list opt_sort_clause
')' Sconst
17379 /* generic syntax with a type modifier */
17380 TypeName
*t
= makeTypeNameFromNameList
($1);
17384 * We must use func_arg_list and opt_sort_clause in the
17385 * production to avoid reduce/reduce conflicts, but we
17386 * don't actually wish to allow NamedArgExpr in this
17387 * context, nor ORDER BY.
17391 NamedArgExpr
*arg
= (NamedArgExpr
*) lfirst
(lc
);
17393 if
(IsA
(arg
, NamedArgExpr
))
17395 (errcode
(ERRCODE_SYNTAX_ERROR
),
17396 errmsg
("type modifier cannot have parameter name"),
17397 parser_errposition
(arg
->location
)));
17401 (errcode
(ERRCODE_SYNTAX_ERROR
),
17402 errmsg
("type modifier cannot have ORDER BY"),
17403 parser_errposition
(@
4)));
17407 $$
= makeStringConstCast
($6, @
6, t
);
17409 | ConstTypename Sconst
17411 $$
= makeStringConstCast
($2, @
2, $1);
17413 | ConstInterval Sconst opt_interval
17418 $$
= makeStringConstCast
($2, @
2, t
);
17420 | ConstInterval
'(' Iconst
')' Sconst
17424 t
->typmods
= list_make2
(makeIntConst
(INTERVAL_FULL_RANGE
, -1),
17425 makeIntConst
($3, @
3));
17426 $$
= makeStringConstCast
($5, @
5, t
);
17430 $$
= makeBoolAConst
(true
, @
1);
17434 $$
= makeBoolAConst
(false
, @
1);
17438 $$
= makeNullAConst
(@
1);
17442 Iconst: ICONST
{ $$
= $1; };
17443 Sconst: SCONST
{ $$
= $1; };
17445 SignedIconst: Iconst
{ $$
= $1; }
17446 |
'+' Iconst
{ $$
= + $2; }
17447 |
'-' Iconst
{ $$
= - $2; }
17450 /* Role specifications */
17453 RoleSpec
*spc
= (RoleSpec
*) $1;
17455 switch
(spc
->roletype
)
17457 case ROLESPEC_CSTRING
:
17458 $$
= spc
->rolename
;
17460 case ROLESPEC_PUBLIC
:
17462 (errcode
(ERRCODE_RESERVED_NAME
),
17463 errmsg
("role name \"%s\" is reserved",
17465 parser_errposition
(@
1)));
17467 case ROLESPEC_SESSION_USER
:
17469 (errcode
(ERRCODE_RESERVED_NAME
),
17470 errmsg
("%s cannot be used as a role name here",
17472 parser_errposition
(@
1)));
17474 case ROLESPEC_CURRENT_USER
:
17476 (errcode
(ERRCODE_RESERVED_NAME
),
17477 errmsg
("%s cannot be used as a role name here",
17479 parser_errposition
(@
1)));
17481 case ROLESPEC_CURRENT_ROLE
:
17483 (errcode
(ERRCODE_RESERVED_NAME
),
17484 errmsg
("%s cannot be used as a role name here",
17486 parser_errposition
(@
1)));
17492 RoleSpec: NonReservedWord
17495 * "public" and "none" are not keywords, but they must
17496 * be treated specially here.
17500 if
(strcmp
($1, "public") == 0)
17502 n
= (RoleSpec
*) makeRoleSpec
(ROLESPEC_PUBLIC
, @
1);
17503 n
->roletype
= ROLESPEC_PUBLIC
;
17505 else if
(strcmp
($1, "none") == 0)
17508 (errcode
(ERRCODE_RESERVED_NAME
),
17509 errmsg
("role name \"%s\" is reserved",
17511 parser_errposition
(@
1)));
17515 n
= makeRoleSpec
(ROLESPEC_CSTRING
, @
1);
17516 n
->rolename
= pstrdup
($1);
17522 $$
= makeRoleSpec
(ROLESPEC_CURRENT_ROLE
, @
1);
17526 $$
= makeRoleSpec
(ROLESPEC_CURRENT_USER
, @
1);
17530 $$
= makeRoleSpec
(ROLESPEC_SESSION_USER
, @
1);
17534 role_list: RoleSpec
17535 { $$
= list_make1
($1); }
17536 | role_list
',' RoleSpec
17537 { $$
= lappend
($1, $3); }
17541 /*****************************************************************************
17543 * PL/pgSQL extensions
17545 * You'd think a PL/pgSQL "expression" should be just an a_expr, but
17546 * historically it can include just about anything that can follow SELECT.
17547 * Therefore the returned struct is a SelectStmt.
17548 *****************************************************************************/
17550 PLpgSQL_Expr: opt_distinct_clause opt_target_list
17551 from_clause where_clause
17552 group_clause having_clause window_clause
17553 opt_sort_clause opt_select_limit opt_for_locking_clause
17555 SelectStmt
*n
= makeNode
(SelectStmt
);
17557 n
->distinctClause
= $1;
17558 n
->targetList
= $2;
17559 n
->fromClause
= $3;
17560 n
->whereClause
= $4;
17561 n
->groupClause
= ($5)->list
;
17562 n
->groupDistinct
= ($5)->distinct
;
17563 n
->havingClause
= $6;
17564 n
->windowClause
= $7;
17565 n
->sortClause
= $8;
17568 n
->limitOffset
= $9->limitOffset
;
17569 n
->limitCount
= $9->limitCount
;
17570 if
(!n
->sortClause
&&
17571 $9->limitOption
== LIMIT_OPTION_WITH_TIES
)
17573 (errcode
(ERRCODE_SYNTAX_ERROR
),
17574 errmsg
("WITH TIES cannot be specified without ORDER BY clause"),
17575 parser_errposition
($9->optionLoc
)));
17576 n
->limitOption
= $9->limitOption
;
17578 n
->lockingClause
= $10;
17584 * PL/pgSQL Assignment statement: name opt_indirection := PLpgSQL_Expr
17587 PLAssignStmt: plassign_target opt_indirection plassign_equals PLpgSQL_Expr
17589 PLAssignStmt
*n
= makeNode
(PLAssignStmt
);
17592 n
->indirection
= check_indirection
($2, yyscanner
);
17593 /* nnames will be filled by calling production */
17594 n
->val
= (SelectStmt
*) $4;
17600 plassign_target: ColId
{ $$
= $1; }
17601 | PARAM
{ $$
= psprintf
("$%d", $1); }
17604 plassign_equals: COLON_EQUALS
17610 * Name classification hierarchy.
17612 * IDENT is the lexeme returned by the lexer for identifiers that match
17613 * no known keyword. In most cases, we can accept certain keywords as
17614 * names, not only IDENTs. We prefer to accept as many such keywords
17615 * as possible to minimize the impact of "reserved words" on programmers.
17616 * So, we divide names into several possible classes. The classification
17617 * is chosen in part to make keywords acceptable as names wherever possible.
17620 /* Column identifier --- names that can be column, table, etc names.
17622 ColId: IDENT
{ $$
= $1; }
17623 | unreserved_keyword
{ $$
= pstrdup
($1); }
17624 | col_name_keyword
{ $$
= pstrdup
($1); }
17627 /* Type/function identifier --- names that can be type or function names.
17629 type_function_name: IDENT
{ $$
= $1; }
17630 | unreserved_keyword
{ $$
= pstrdup
($1); }
17631 | type_func_name_keyword
{ $$
= pstrdup
($1); }
17634 /* Any not-fully-reserved word --- these names can be, eg, role names.
17636 NonReservedWord: IDENT
{ $$
= $1; }
17637 | unreserved_keyword
{ $$
= pstrdup
($1); }
17638 | col_name_keyword
{ $$
= pstrdup
($1); }
17639 | type_func_name_keyword
{ $$
= pstrdup
($1); }
17642 /* Column label --- allowed labels in "AS" clauses.
17643 * This presently includes *all* Postgres keywords.
17645 ColLabel: IDENT
{ $$
= $1; }
17646 | unreserved_keyword
{ $$
= pstrdup
($1); }
17647 | col_name_keyword
{ $$
= pstrdup
($1); }
17648 | type_func_name_keyword
{ $$
= pstrdup
($1); }
17649 | reserved_keyword
{ $$
= pstrdup
($1); }
17652 /* Bare column label --- names that can be column labels without writing "AS".
17653 * This classification is orthogonal to the other keyword categories.
17655 BareColLabel: IDENT
{ $$
= $1; }
17656 | bare_label_keyword
{ $$
= pstrdup
($1); }
17661 * Keyword category lists. Generally, every keyword present in
17662 * the Postgres grammar should appear in exactly one of these lists.
17664 * Put a new keyword into the first list that it can go into without causing
17665 * shift or reduce conflicts. The earlier lists define "less reserved"
17666 * categories of keywords.
17668 * Make sure that each keyword's category in kwlist.h matches where
17669 * it is listed here. (Someday we may be able to generate these lists and
17670 * kwlist.h's table from one source of truth.)
17673 /* "Unreserved" keywords --- available for use as any kind of name.
17675 unreserved_keyword:
18006 /* Column identifier --- keywords that can be column, table, etc names.
18008 * Many of these keywords will in fact be recognized as type or function
18009 * names too; but they have special productions for the purpose, and so
18010 * can't be treated as "generic" type or function names.
18012 * The type names appearing here are not usable as function names
18013 * because they can be followed by '(' in typename productions, which
18014 * looks too much like a function call for an LR(1) parser.
18082 /* Type/function identifier --- keywords that can be type or function names.
18084 * Most of these are keywords that are used as operators in expressions;
18085 * in general such keywords can't be column names because they would be
18086 * ambiguous with variables, but they are unambiguous as function identifiers.
18088 * Do not include POSITION, SUBSTRING, etc here since they have explicit
18089 * productions in a_expr to support the goofy SQL9x argument syntax.
18090 * - thomas 2000-11-28
18092 type_func_name_keyword:
18118 /* Reserved keyword --- these keywords are usable only as a ColLabel.
18120 * Keywords appear here if they could not be distinguished from variable,
18121 * type, or function names in some contexts. Don't put things here unless
18146 | CURRENT_TIMESTAMP
18206 * While all keywords can be used as column labels when preceded by AS,
18207 * not all of them can be used as a "bare" column label without AS.
18208 * Those that can be used as a bare label must be listed here,
18209 * in addition to appearing in one of the category lists above.
18211 * Always add a new keyword to this list if possible. Mark it BARE_LABEL
18212 * in kwlist.h if it is included here, or AS_LABEL if it is not.
18214 bare_label_keyword:
18299 | CURRENT_TIMESTAMP
18673 * The signature of this function is required by bison. However, we
18674 * ignore the passed yylloc and instead use the last token position
18675 * available from the scanner.
18678 base_yyerror
(YYLTYPE *yylloc, core_yyscan_t yyscanner
, const char *msg
)
18680 parser_yyerror
(msg
);
18684 makeRawStmt
(Node
*stmt
, int stmt_location
)
18686 RawStmt
*rs
= makeNode
(RawStmt
);
18689 rs
->stmt_location
= stmt_location
;
18690 rs
->stmt_len
= 0; /* might get changed later */
18694 /* Adjust a RawStmt to reflect that it doesn't run to the end of the string */
18696 updateRawStmtEnd
(RawStmt
*rs
, int end_location
)
18699 * If we already set the length, don't change it. This is for situations
18700 * like "select foo ;; select bar" where the same statement will be last
18701 * in the string for more than one semicolon.
18703 if
(rs
->stmt_len
> 0)
18706 /* OK, update length of RawStmt */
18707 rs
->stmt_len
= end_location
- rs
->stmt_location
;
18711 * Adjust a PreparableStmt to reflect that it doesn't run to the end of the
18715 updatePreparableStmtEnd
(Node
*n
, int end_location
)
18717 if
(IsA
(n
, SelectStmt
))
18719 SelectStmt
*stmt
= (SelectStmt
*) n
;
18721 stmt
->stmt_len
= end_location
- stmt
->stmt_location
;
18723 else if
(IsA
(n
, InsertStmt
))
18725 InsertStmt
*stmt
= (InsertStmt
*) n
;
18727 stmt
->stmt_len
= end_location
- stmt
->stmt_location
;
18729 else if
(IsA
(n
, UpdateStmt
))
18731 UpdateStmt
*stmt
= (UpdateStmt
*) n
;
18733 stmt
->stmt_len
= end_location
- stmt
->stmt_location
;
18735 else if
(IsA
(n
, DeleteStmt
))
18737 DeleteStmt
*stmt
= (DeleteStmt
*) n
;
18739 stmt
->stmt_len
= end_location
- stmt
->stmt_location
;
18741 else if
(IsA
(n
, MergeStmt
))
18743 MergeStmt
*stmt
= (MergeStmt
*) n
;
18745 stmt
->stmt_len
= end_location
- stmt
->stmt_location
;
18748 elog
(ERROR
, "unexpected node type %d", (int) n
->type
);
18752 makeColumnRef
(char *colname
, List
*indirection
,
18753 int location
, core_yyscan_t yyscanner
)
18756 * Generate a ColumnRef node, with an A_Indirection node added if there is
18757 * any subscripting in the specified indirection list. However, any field
18758 * selection at the start of the indirection list must be transposed into
18759 * the "fields" part of the ColumnRef node.
18761 ColumnRef
*c
= makeNode
(ColumnRef
);
18765 c
->location
= location
;
18766 foreach
(l
, indirection
)
18768 if
(IsA
(lfirst
(l
), A_Indices
))
18770 A_Indirection
*i
= makeNode
(A_Indirection
);
18774 /* easy case - all indirection goes to A_Indirection */
18775 c
->fields
= list_make1
(makeString
(colname
));
18776 i
->indirection
= check_indirection
(indirection
, yyscanner
);
18780 /* got to split the list in two */
18781 i
->indirection
= check_indirection
(list_copy_tail
(indirection
,
18784 indirection
= list_truncate
(indirection
, nfields
);
18785 c
->fields
= lcons
(makeString
(colname
), indirection
);
18787 i
->arg
= (Node
*) c
;
18790 else if
(IsA
(lfirst
(l
), A_Star
))
18792 /* We only allow '*' at the end of a ColumnRef */
18793 if
(lnext
(indirection
, l
) != NULL
)
18794 parser_yyerror
("improper use of \"*\"");
18798 /* No subscripting, so all indirection gets added to field list */
18799 c
->fields
= lcons
(makeString
(colname
), indirection
);
18804 makeTypeCast
(Node
*arg
, TypeName
*typename
, int location
)
18806 TypeCast
*n
= makeNode
(TypeCast
);
18809 n
->typeName
= typename
;
18810 n
->location
= location
;
18815 makeStringConstCast
(char *str
, int location
, TypeName
*typename
)
18817 Node
*s
= makeStringConst
(str
, location
);
18819 return makeTypeCast
(s
, typename
, -1);
18823 makeIntConst
(int val
, int location
)
18825 A_Const
*n
= makeNode
(A_Const
);
18827 n
->val.ival.type
= T_Integer
;
18828 n
->val.ival.ival
= val
;
18829 n
->location
= location
;
18835 makeFloatConst
(char *str
, int location
)
18837 A_Const
*n
= makeNode
(A_Const
);
18839 n
->val.fval.type
= T_Float
;
18840 n
->val.fval.fval
= str
;
18841 n
->location
= location
;
18847 makeBoolAConst
(bool state
, int location
)
18849 A_Const
*n
= makeNode
(A_Const
);
18851 n
->val.boolval.type
= T_Boolean
;
18852 n
->val.boolval.boolval
= state
;
18853 n
->location
= location
;
18859 makeBitStringConst
(char *str
, int location
)
18861 A_Const
*n
= makeNode
(A_Const
);
18863 n
->val.bsval.type
= T_BitString
;
18864 n
->val.bsval.bsval
= str
;
18865 n
->location
= location
;
18871 makeNullAConst
(int location
)
18873 A_Const
*n
= makeNode
(A_Const
);
18876 n
->location
= location
;
18882 makeAConst
(Node
*v
, int location
)
18889 n
= makeFloatConst
(castNode
(Float
, v
)->fval
, location
);
18893 n
= makeIntConst
(castNode
(Integer
, v
)->ival
, location
);
18897 /* currently not used */
18906 * Create a RoleSpec with the given type
18909 makeRoleSpec
(RoleSpecType type
, int location
)
18911 RoleSpec
*spec
= makeNode
(RoleSpec
);
18913 spec
->roletype
= type
;
18914 spec
->location
= location
;
18919 /* check_qualified_name --- check the result of qualified_name production
18921 * It's easiest to let the grammar production for qualified_name allow
18922 * subscripts and '*', which we then must reject here.
18925 check_qualified_name
(List
*names
, core_yyscan_t yyscanner
)
18931 if
(!IsA
(lfirst
(i
), String
))
18932 parser_yyerror
("syntax error");
18936 /* check_func_name --- check the result of func_name production
18938 * It's easiest to let the grammar production for func_name allow subscripts
18939 * and '*', which we then must reject here.
18942 check_func_name
(List
*names
, core_yyscan_t yyscanner
)
18948 if
(!IsA
(lfirst
(i
), String
))
18949 parser_yyerror
("syntax error");
18954 /* check_indirection --- check the result of indirection production
18956 * We only allow '*' at the end of the list, but it's hard to enforce that
18957 * in the grammar, so do it here.
18960 check_indirection
(List
*indirection
, core_yyscan_t yyscanner
)
18964 foreach
(l
, indirection
)
18966 if
(IsA
(lfirst
(l
), A_Star
))
18968 if
(lnext
(indirection
, l
) != NULL
)
18969 parser_yyerror
("improper use of \"*\"");
18972 return indirection
;
18975 /* extractArgTypes()
18976 * Given a list of FunctionParameter nodes, extract a list of just the
18977 * argument types (TypeNames) for input parameters only. This is what
18978 * is needed to look up an existing function, which is what is wanted by
18979 * the productions that use this call.
18982 extractArgTypes
(List
*parameters
)
18984 List
*result
= NIL
;
18987 foreach
(i
, parameters
)
18989 FunctionParameter
*p
= (FunctionParameter
*) lfirst
(i
);
18991 if
(p
->mode
!= FUNC_PARAM_OUT
&& p
->mode
!= FUNC_PARAM_TABLE
)
18992 result
= lappend
(result
, p
->argType
);
18997 /* extractAggrArgTypes()
18998 * As above, but work from the output of the aggr_args production.
19001 extractAggrArgTypes
(List
*aggrargs
)
19003 Assert
(list_length
(aggrargs
) == 2);
19004 return extractArgTypes
((List
*) linitial
(aggrargs
));
19007 /* makeOrderedSetArgs()
19008 * Build the result of the aggr_args production (which see the comments for).
19009 * This handles only the case where both given lists are nonempty, so that
19010 * we have to deal with multiple VARIADIC arguments.
19013 makeOrderedSetArgs
(List
*directargs
, List
*orderedargs
,
19014 core_yyscan_t yyscanner
)
19016 FunctionParameter
*lastd
= (FunctionParameter
*) llast
(directargs
);
19017 Integer
*ndirectargs
;
19019 /* No restriction unless last direct arg is VARIADIC */
19020 if
(lastd
->mode
== FUNC_PARAM_VARIADIC
)
19022 FunctionParameter
*firsto
= (FunctionParameter
*) linitial
(orderedargs
);
19025 * We ignore the names, though the aggr_arg production allows them; it
19026 * doesn't allow default values, so those need not be checked.
19028 if
(list_length
(orderedargs
) != 1 ||
19029 firsto
->mode
!= FUNC_PARAM_VARIADIC ||
19030 !equal
(lastd
->argType
, firsto
->argType
))
19032 (errcode
(ERRCODE_FEATURE_NOT_SUPPORTED
),
19033 errmsg
("an ordered-set aggregate with a VARIADIC direct argument must have one VARIADIC aggregated argument of the same data type"),
19034 parser_errposition
(firsto
->location
)));
19036 /* OK, drop the duplicate VARIADIC argument from the internal form */
19040 /* don't merge into the next line, as list_concat changes directargs */
19041 ndirectargs
= makeInteger
(list_length
(directargs
));
19043 return list_make2
(list_concat
(directargs
, orderedargs
),
19047 /* insertSelectOptions()
19048 * Insert ORDER BY, etc into an already-constructed SelectStmt.
19050 * This routine is just to avoid duplicating code in SelectStmt productions.
19053 insertSelectOptions
(SelectStmt
*stmt
,
19054 List
*sortClause
, List
*lockingClause
,
19055 SelectLimit
*limitClause
,
19056 WithClause
*withClause
,
19057 core_yyscan_t yyscanner
)
19059 Assert
(IsA
(stmt
, SelectStmt
));
19062 * Tests here are to reject constructs like
19063 * (SELECT foo ORDER BY bar) ORDER BY baz
19067 if
(stmt
->sortClause
)
19069 (errcode
(ERRCODE_SYNTAX_ERROR
),
19070 errmsg
("multiple ORDER BY clauses not allowed"),
19071 parser_errposition
(exprLocation
((Node
*) sortClause
))));
19072 stmt
->sortClause
= sortClause
;
19074 /* We can handle multiple locking clauses, though */
19075 stmt
->lockingClause
= list_concat
(stmt
->lockingClause
, lockingClause
);
19076 if
(limitClause
&& limitClause
->limitOffset
)
19078 if
(stmt
->limitOffset
)
19080 (errcode
(ERRCODE_SYNTAX_ERROR
),
19081 errmsg
("multiple OFFSET clauses not allowed"),
19082 parser_errposition
(limitClause
->offsetLoc
)));
19083 stmt
->limitOffset
= limitClause
->limitOffset
;
19085 if
(limitClause
&& limitClause
->limitCount
)
19087 if
(stmt
->limitCount
)
19089 (errcode
(ERRCODE_SYNTAX_ERROR
),
19090 errmsg
("multiple LIMIT clauses not allowed"),
19091 parser_errposition
(limitClause
->countLoc
)));
19092 stmt
->limitCount
= limitClause
->limitCount
;
19096 /* If there was a conflict, we must have detected it above */
19097 Assert
(!stmt
->limitOption
);
19098 if
(!stmt
->sortClause
&& limitClause
->limitOption
== LIMIT_OPTION_WITH_TIES
)
19100 (errcode
(ERRCODE_SYNTAX_ERROR
),
19101 errmsg
("WITH TIES cannot be specified without ORDER BY clause"),
19102 parser_errposition
(limitClause
->optionLoc
)));
19103 if
(limitClause
->limitOption
== LIMIT_OPTION_WITH_TIES
&& stmt
->lockingClause
)
19107 foreach
(lc
, stmt
->lockingClause
)
19109 LockingClause
*lock
= lfirst_node
(LockingClause
, lc
);
19111 if
(lock
->waitPolicy
== LockWaitSkip
)
19113 (errcode
(ERRCODE_SYNTAX_ERROR
),
19114 errmsg
("%s and %s options cannot be used together",
19115 "SKIP LOCKED", "WITH TIES"),
19116 parser_errposition
(limitClause
->optionLoc
)));
19119 stmt
->limitOption
= limitClause
->limitOption
;
19123 if
(stmt
->withClause
)
19125 (errcode
(ERRCODE_SYNTAX_ERROR
),
19126 errmsg
("multiple WITH clauses not allowed"),
19127 parser_errposition
(exprLocation
((Node
*) withClause
))));
19128 stmt
->withClause
= withClause
;
19130 /* Update SelectStmt's location to the start of the WITH clause */
19131 stmt
->stmt_location
= withClause
->location
;
19136 makeSetOp
(SetOperation op
, bool all
, Node
*larg
, Node
*rarg
, int location
)
19138 SelectStmt
*n
= makeNode
(SelectStmt
);
19142 n
->larg
= (SelectStmt
*) larg
;
19143 n
->rarg
= (SelectStmt
*) rarg
;
19144 n
->stmt_location
= location
;
19148 /* SystemFuncName()
19149 * Build a properly-qualified reference to a built-in function.
19152 SystemFuncName
(char *name
)
19154 return list_make2
(makeString
("pg_catalog"), makeString
(name
));
19157 /* SystemTypeName()
19158 * Build a properly-qualified reference to a built-in type.
19160 * typmod is defaulted, but may be changed afterwards by caller.
19161 * Likewise for the location.
19164 SystemTypeName
(char *name
)
19166 return makeTypeNameFromNameList
(list_make2
(makeString
("pg_catalog"),
19167 makeString
(name
)));
19171 * Handle negation of a numeric constant.
19173 * Formerly, we did this here because the optimizer couldn't cope with
19174 * indexquals that looked like "var = -4" --- it wants "var = const"
19175 * and a unary minus operator applied to a constant didn't qualify.
19176 * As of Postgres 7.0, that problem doesn't exist anymore because there
19177 * is a constant-subexpression simplifier in the optimizer. However,
19178 * there's still a good reason for doing this here, which is that we can
19179 * postpone committing to a particular internal representation for simple
19180 * negative constants. It's better to leave "-123.456" in string form
19181 * until we know what the desired type is.
19184 doNegate
(Node
*n
, int location
)
19186 if
(IsA
(n
, A_Const
))
19188 A_Const
*con
= (A_Const
*) n
;
19190 /* report the constant's location as that of the '-' sign */
19191 con
->location
= location
;
19193 if
(IsA
(&con
->val
, Integer
))
19195 con
->val.ival.ival
= -con
->val.ival.ival
;
19198 if
(IsA
(&con
->val
, Float
))
19200 doNegateFloat
(&con
->val.fval
);
19205 return
(Node
*) makeSimpleA_Expr
(AEXPR_OP
, "-", NULL
, n
, location
);
19209 doNegateFloat
(Float
*v
)
19211 char *oldval
= v
->fval
;
19213 if
(*oldval
== '+')
19215 if
(*oldval
== '-')
19216 v
->fval
= oldval
+ 1; /* just strip the '-' */
19218 v
->fval
= psprintf
("-%s", oldval
);
19222 makeAndExpr
(Node
*lexpr
, Node
*rexpr
, int location
)
19224 /* Flatten "a AND b AND c ..." to a single BoolExpr on sight */
19225 if
(IsA
(lexpr
, BoolExpr
))
19227 BoolExpr
*blexpr
= (BoolExpr
*) lexpr
;
19229 if
(blexpr
->boolop
== AND_EXPR
)
19231 blexpr
->args
= lappend
(blexpr
->args
, rexpr
);
19232 return
(Node
*) blexpr
;
19235 return
(Node
*) makeBoolExpr
(AND_EXPR
, list_make2
(lexpr
, rexpr
), location
);
19239 makeOrExpr
(Node
*lexpr
, Node
*rexpr
, int location
)
19241 /* Flatten "a OR b OR c ..." to a single BoolExpr on sight */
19242 if
(IsA
(lexpr
, BoolExpr
))
19244 BoolExpr
*blexpr
= (BoolExpr
*) lexpr
;
19246 if
(blexpr
->boolop
== OR_EXPR
)
19248 blexpr
->args
= lappend
(blexpr
->args
, rexpr
);
19249 return
(Node
*) blexpr
;
19252 return
(Node
*) makeBoolExpr
(OR_EXPR
, list_make2
(lexpr
, rexpr
), location
);
19256 makeNotExpr
(Node
*expr
, int location
)
19258 return
(Node
*) makeBoolExpr
(NOT_EXPR
, list_make1
(expr
), location
);
19262 makeAArrayExpr
(List
*elements
, int location
)
19264 A_ArrayExpr
*n
= makeNode
(A_ArrayExpr
);
19266 n
->elements
= elements
;
19267 n
->location
= location
;
19272 makeSQLValueFunction
(SQLValueFunctionOp op
, int32 typmod
, int location
)
19274 SQLValueFunction
*svf
= makeNode
(SQLValueFunction
);
19277 /* svf->type will be filled during parse analysis */
19278 svf
->typmod
= typmod
;
19279 svf
->location
= location
;
19280 return
(Node
*) svf
;
19284 makeXmlExpr
(XmlExprOp op
, char *name
, List
*named_args
, List
*args
,
19287 XmlExpr
*x
= makeNode
(XmlExpr
);
19293 * named_args is a list of ResTarget; it'll be split apart into separate
19294 * expression and name lists in transformXmlExpr().
19296 x
->named_args
= named_args
;
19297 x
->arg_names
= NIL
;
19299 /* xmloption, if relevant, must be filled in by caller */
19300 /* type and typmod will be filled in during parse analysis */
19301 x
->type
= InvalidOid
; /* marks the node as not analyzed */
19302 x
->location
= location
;
19307 * Merge the input and output parameters of a table function.
19310 mergeTableFuncParameters
(List
*func_args
, List
*columns
, core_yyscan_t yyscanner
)
19314 /* Explicit OUT and INOUT parameters shouldn't be used in this syntax */
19315 foreach
(lc
, func_args
)
19317 FunctionParameter
*p
= (FunctionParameter
*) lfirst
(lc
);
19319 if
(p
->mode
!= FUNC_PARAM_DEFAULT
&&
19320 p
->mode
!= FUNC_PARAM_IN
&&
19321 p
->mode
!= FUNC_PARAM_VARIADIC
)
19323 (errcode
(ERRCODE_SYNTAX_ERROR
),
19324 errmsg
("OUT and INOUT arguments aren't allowed in TABLE functions"),
19325 parser_errposition
(p
->location
)));
19328 return list_concat
(func_args
, columns
);
19332 * Determine return type of a TABLE function. A single result column
19333 * returns setof that column's type; otherwise return setof record.
19336 TableFuncTypeName
(List
*columns
)
19340 if
(list_length
(columns
) == 1)
19342 FunctionParameter
*p
= (FunctionParameter
*) linitial
(columns
);
19344 result
= copyObject
(p
->argType
);
19347 result
= SystemTypeName
("record");
19349 result
->setof
= true
;
19355 * Convert a list of (dotted) names to a RangeVar (like
19356 * makeRangeVarFromNameList, but with position support). The
19357 * "AnyName" refers to the any_name production in the grammar.
19360 makeRangeVarFromAnyName
(List
*names
, int position
, core_yyscan_t yyscanner
)
19362 RangeVar
*r
= makeNode
(RangeVar
);
19364 switch
(list_length
(names
))
19367 r
->catalogname
= NULL
;
19368 r
->schemaname
= NULL
;
19369 r
->relname
= strVal
(linitial
(names
));
19372 r
->catalogname
= NULL
;
19373 r
->schemaname
= strVal
(linitial
(names
));
19374 r
->relname
= strVal
(lsecond
(names
));
19377 r
->catalogname
= strVal
(linitial
(names
));
19378 r
->schemaname
= strVal
(lsecond
(names
));
19379 r
->relname
= strVal
(lthird
(names
));
19383 (errcode
(ERRCODE_SYNTAX_ERROR
),
19384 errmsg
("improper qualified name (too many dotted names): %s",
19385 NameListToString
(names
)),
19386 parser_errposition
(position
)));
19390 r
->relpersistence
= RELPERSISTENCE_PERMANENT
;
19391 r
->location
= position
;
19397 * Convert a relation_name with name and namelist to a RangeVar using
19401 makeRangeVarFromQualifiedName
(char *name
, List
*namelist
, int location
,
19402 core_yyscan_t yyscanner
)
19406 check_qualified_name
(namelist
, yyscanner
);
19407 r
= makeRangeVar
(NULL
, NULL
, location
);
19409 switch
(list_length
(namelist
))
19412 r
->catalogname
= NULL
;
19413 r
->schemaname
= name
;
19414 r
->relname
= strVal
(linitial
(namelist
));
19417 r
->catalogname
= name
;
19418 r
->schemaname
= strVal
(linitial
(namelist
));
19419 r
->relname
= strVal
(lsecond
(namelist
));
19423 errcode
(ERRCODE_SYNTAX_ERROR
),
19424 errmsg
("improper qualified name (too many dotted names): %s",
19425 NameListToString
(lcons
(makeString
(name
), namelist
))),
19426 parser_errposition
(location
));
19433 /* Separate Constraint nodes from COLLATE clauses in a ColQualList */
19435 SplitColQualList
(List
*qualList
,
19436 List
**constraintList
, CollateClause
**collClause
,
19437 core_yyscan_t yyscanner
)
19441 *collClause
= NULL
;
19442 foreach
(cell
, qualList
)
19444 Node
*n
= (Node
*) lfirst
(cell
);
19446 if
(IsA
(n
, Constraint
))
19448 /* keep it in list */
19451 if
(IsA
(n
, CollateClause
))
19453 CollateClause
*c
= (CollateClause
*) n
;
19457 (errcode
(ERRCODE_SYNTAX_ERROR
),
19458 errmsg
("multiple COLLATE clauses not allowed"),
19459 parser_errposition
(c
->location
)));
19463 elog
(ERROR
, "unexpected node type %d", (int) n
->type
);
19464 /* remove non-Constraint nodes from qualList */
19465 qualList
= foreach_delete_current
(qualList
, cell
);
19467 *constraintList
= qualList
;
19471 * Process result of ConstraintAttributeSpec, and set appropriate bool flags
19472 * in the output command node. Pass NULL for any flags the particular
19473 * command doesn't support.
19476 processCASbits
(int cas_bits
, int location
, const char *constrType
,
19477 bool *deferrable
, bool *initdeferred
, bool *is_enforced
,
19478 bool *not_valid
, bool *no_inherit
, core_yyscan_t yyscanner
)
19482 *deferrable
= false
;
19484 *initdeferred
= false
;
19486 *not_valid
= false
;
19488 *is_enforced
= true
;
19490 if
(cas_bits
& (CAS_DEFERRABLE | CAS_INITIALLY_DEFERRED
))
19493 *deferrable
= true
;
19496 (errcode
(ERRCODE_FEATURE_NOT_SUPPORTED
),
19497 /* translator: %s is CHECK, UNIQUE, or similar */
19498 errmsg
("%s constraints cannot be marked DEFERRABLE",
19500 parser_errposition
(location
)));
19503 if
(cas_bits
& CAS_INITIALLY_DEFERRED
)
19506 *initdeferred
= true
;
19509 (errcode
(ERRCODE_FEATURE_NOT_SUPPORTED
),
19510 /* translator: %s is CHECK, UNIQUE, or similar */
19511 errmsg
("%s constraints cannot be marked DEFERRABLE",
19513 parser_errposition
(location
)));
19516 if
(cas_bits
& CAS_NOT_VALID
)
19522 (errcode
(ERRCODE_FEATURE_NOT_SUPPORTED
),
19523 /* translator: %s is CHECK, UNIQUE, or similar */
19524 errmsg
("%s constraints cannot be marked NOT VALID",
19526 parser_errposition
(location
)));
19529 if
(cas_bits
& CAS_NO_INHERIT
)
19532 *no_inherit
= true
;
19535 (errcode
(ERRCODE_FEATURE_NOT_SUPPORTED
),
19536 /* translator: %s is CHECK, UNIQUE, or similar */
19537 errmsg
("%s constraints cannot be marked NO INHERIT",
19539 parser_errposition
(location
)));
19542 if
(cas_bits
& CAS_NOT_ENFORCED
)
19545 *is_enforced
= false
;
19548 (errcode
(ERRCODE_FEATURE_NOT_SUPPORTED
),
19549 /* translator: %s is CHECK, UNIQUE, or similar */
19550 errmsg
("%s constraints cannot be marked NOT ENFORCED",
19552 parser_errposition
(location
)));
19555 * NB: The validated status is irrelevant when the constraint is set to
19556 * NOT ENFORCED, but for consistency, it should be set accordingly.
19557 * This ensures that if the constraint is later changed to ENFORCED, it
19558 * will automatically be in the correct NOT VALIDATED state.
19564 if
(cas_bits
& CAS_ENFORCED
)
19567 *is_enforced
= true
;
19570 (errcode
(ERRCODE_FEATURE_NOT_SUPPORTED
),
19571 /* translator: %s is CHECK, UNIQUE, or similar */
19572 errmsg
("%s constraints cannot be marked ENFORCED",
19574 parser_errposition
(location
)));
19579 * Parse a user-supplied partition strategy string into parse node
19580 * PartitionStrategy representation, or die trying.
19582 static PartitionStrategy
19583 parsePartitionStrategy
(char *strategy
, int location
, core_yyscan_t yyscanner
)
19585 if
(pg_strcasecmp
(strategy
, "list") == 0)
19586 return PARTITION_STRATEGY_LIST
;
19587 else if
(pg_strcasecmp
(strategy
, "range") == 0)
19588 return PARTITION_STRATEGY_RANGE
;
19589 else if
(pg_strcasecmp
(strategy
, "hash") == 0)
19590 return PARTITION_STRATEGY_HASH
;
19593 (errcode
(ERRCODE_INVALID_PARAMETER_VALUE
),
19594 errmsg
("unrecognized partitioning strategy \"%s\"", strategy
),
19595 parser_errposition
(location
)));
19596 return PARTITION_STRATEGY_LIST
; /* keep compiler quiet */
19601 * Process pubobjspec_list to check for errors in any of the objects and
19602 * convert PUBLICATIONOBJ_CONTINUATION into appropriate PublicationObjSpecType.
19605 preprocess_pubobj_list
(List
*pubobjspec_list
, core_yyscan_t yyscanner
)
19608 PublicationObjSpec
*pubobj
;
19609 PublicationObjSpecType prevobjtype
= PUBLICATIONOBJ_CONTINUATION
;
19611 if
(!pubobjspec_list
)
19614 pubobj
= (PublicationObjSpec
*) linitial
(pubobjspec_list
);
19615 if
(pubobj
->pubobjtype
== PUBLICATIONOBJ_CONTINUATION
)
19617 errcode
(ERRCODE_SYNTAX_ERROR
),
19618 errmsg
("invalid publication object list"),
19619 errdetail
("One of TABLE or TABLES IN SCHEMA must be specified before a standalone table or schema name."),
19620 parser_errposition
(pubobj
->location
));
19622 foreach
(cell
, pubobjspec_list
)
19624 pubobj
= (PublicationObjSpec
*) lfirst
(cell
);
19626 if
(pubobj
->pubobjtype
== PUBLICATIONOBJ_CONTINUATION
)
19627 pubobj
->pubobjtype
= prevobjtype
;
19629 if
(pubobj
->pubobjtype
== PUBLICATIONOBJ_TABLE
)
19631 /* relation name or pubtable must be set for this type of object */
19632 if
(!pubobj
->name
&& !pubobj
->pubtable
)
19634 errcode
(ERRCODE_SYNTAX_ERROR
),
19635 errmsg
("invalid table name"),
19636 parser_errposition
(pubobj
->location
));
19640 /* convert it to PublicationTable */
19641 PublicationTable
*pubtable
= makeNode
(PublicationTable
);
19643 pubtable
->relation
=
19644 makeRangeVar
(NULL
, pubobj
->name
, pubobj
->location
);
19645 pubobj
->pubtable
= pubtable
;
19646 pubobj
->name
= NULL
;
19649 else if
(pubobj
->pubobjtype
== PUBLICATIONOBJ_TABLES_IN_SCHEMA ||
19650 pubobj
->pubobjtype
== PUBLICATIONOBJ_TABLES_IN_CUR_SCHEMA
)
19652 /* WHERE clause is not allowed on a schema object */
19653 if
(pubobj
->pubtable
&& pubobj
->pubtable
->whereClause
)
19655 errcode
(ERRCODE_SYNTAX_ERROR
),
19656 errmsg
("WHERE clause not allowed for schema"),
19657 parser_errposition
(pubobj
->location
));
19659 /* Column list is not allowed on a schema object */
19660 if
(pubobj
->pubtable
&& pubobj
->pubtable
->columns
)
19662 errcode
(ERRCODE_SYNTAX_ERROR
),
19663 errmsg
("column specification not allowed for schema"),
19664 parser_errposition
(pubobj
->location
));
19667 * We can distinguish between the different type of schema objects
19668 * based on whether name and pubtable is set.
19671 pubobj
->pubobjtype
= PUBLICATIONOBJ_TABLES_IN_SCHEMA
;
19672 else if
(!pubobj
->name
&& !pubobj
->pubtable
)
19673 pubobj
->pubobjtype
= PUBLICATIONOBJ_TABLES_IN_CUR_SCHEMA
;
19676 errcode
(ERRCODE_SYNTAX_ERROR
),
19677 errmsg
("invalid schema name"),
19678 parser_errposition
(pubobj
->location
));
19681 prevobjtype
= pubobj
->pubobjtype
;
19686 * Recursive view transformation
19690 * CREATE RECURSIVE VIEW relname (aliases) AS query
19694 * CREATE VIEW relname (aliases) AS
19695 * WITH RECURSIVE relname (aliases) AS (query)
19696 * SELECT aliases FROM relname
19698 * Actually, just the WITH ... part, which is then inserted into the original
19699 * view definition as the query.
19703 makeRecursiveViewSelect
(char *relname
, List
*aliases
, Node
*query
)
19705 SelectStmt
*s
= makeNode
(SelectStmt
);
19706 WithClause
*w
= makeNode
(WithClause
);
19707 CommonTableExpr
*cte
= makeNode
(CommonTableExpr
);
19711 /* create common table expression */
19712 cte
->ctename
= relname
;
19713 cte
->aliascolnames
= aliases
;
19714 cte
->ctematerialized
= CTEMaterializeDefault
;
19715 cte
->ctequery
= query
;
19716 cte
->location
= -1;
19718 /* create WITH clause and attach CTE */
19719 w
->recursive
= true
;
19720 w
->ctes
= list_make1
(cte
);
19724 * create target list for the new SELECT from the alias list of the
19725 * recursive view specification
19727 foreach
(lc
, aliases
)
19729 ResTarget
*rt
= makeNode
(ResTarget
);
19732 rt
->indirection
= NIL
;
19733 rt
->val
= makeColumnRef
(strVal
(lfirst
(lc
)), NIL
, -1, 0);
19736 tl
= lappend
(tl
, rt
);
19740 * create new SELECT combining WITH clause, target list, and fake FROM
19744 s
->targetList
= tl
;
19745 s
->fromClause
= list_make1
(makeRangeVar
(NULL
, relname
, -1));
19751 * Initialize to parse one query string
19754 parser_init
(base_yy_extra_type
*yyext
)
19756 yyext
->parsetree
= NIL
; /* in case grammar forgets to set it */