Age Owner Branch data TLA Line data Source code
1 : : %{
2 : :
3 : : /*#define YYDEBUG 1*/
4 : : /*-------------------------------------------------------------------------
5 : : *
6 : : * gram.y
7 : : * POSTGRESQL BISON rules/actions
8 : : *
9 : : * Portions Copyright (c) 1996-2025, PostgreSQL Global Development Group
10 : : * Portions Copyright (c) 1994, Regents of the University of California
11 : : *
12 : : *
13 : : * IDENTIFICATION
14 : : * src/backend/parser/gram.y
15 : : *
16 : : * HISTORY
17 : : * AUTHOR DATE MAJOR EVENT
18 : : * Andrew Yu Sept, 1994 POSTQUEL to SQL conversion
19 : : * Andrew Yu Oct, 1994 lispy code conversion
20 : : *
21 : : * NOTES
22 : : * CAPITALS are used to represent terminal symbols.
23 : : * non-capitals are used to represent non-terminals.
24 : : *
25 : : * In general, nothing in this file should initiate database accesses
26 : : * nor depend on changeable state (such as SET variables). If you do
27 : : * database accesses, your code will fail when we have aborted the
28 : : * current transaction and are just parsing commands to find the next
29 : : * ROLLBACK or COMMIT. If you make use of SET variables, then you
30 : : * will do the wrong thing in multi-query strings like this:
31 : : * SET constraint_exclusion TO off; SELECT * FROM foo;
32 : : * because the entire string is parsed by gram.y before the SET gets
33 : : * executed. Anything that depends on the database or changeable state
34 : : * should be handled during parse analysis so that it happens at the
35 : : * right time not the wrong time.
36 : : *
37 : : * WARNINGS
38 : : * If you use a list, make sure the datum is a node so that the printing
39 : : * routines work.
40 : : *
41 : : * Sometimes we assign constants to makeStrings. Make sure we don't free
42 : : * those.
43 : : *
44 : : *-------------------------------------------------------------------------
45 : : */
46 : : #include "postgres.h"
47 : :
48 : : #include <ctype.h>
49 : : #include <limits.h>
50 : :
51 : : #include "catalog/index.h"
52 : : #include "catalog/namespace.h"
53 : : #include "catalog/pg_am.h"
54 : : #include "catalog/pg_trigger.h"
55 : : #include "commands/defrem.h"
56 : : #include "commands/trigger.h"
57 : : #include "gramparse.h"
58 : : #include "nodes/makefuncs.h"
59 : : #include "nodes/nodeFuncs.h"
60 : : #include "parser/parser.h"
61 : : #include "utils/datetime.h"
62 : : #include "utils/xml.h"
63 : :
64 : :
65 : : /*
66 : : * Location tracking support. Unlike bison's default, we only want
67 : : * to track the start position not the end position of each nonterminal.
68 : : * Nonterminals that reduce to empty receive position "-1". Since a
69 : : * production's leading RHS nonterminal(s) may have reduced to empty,
70 : : * we have to scan to find the first one that's not -1.
71 : : */
72 : : #define YYLLOC_DEFAULT(Current, Rhs, N) \
73 : : do { \
74 : : (Current) = (-1); \
75 : : for (int _i = 1; _i <= (N); _i++) \
76 : : { \
77 : : if ((Rhs)[_i] >= 0) \
78 : : { \
79 : : (Current) = (Rhs)[_i]; \
80 : : break; \
81 : : } \
82 : : } \
83 : : } while (0)
84 : :
85 : : /*
86 : : * Bison doesn't allocate anything that needs to live across parser calls,
87 : : * so we can easily have it use palloc instead of malloc. This prevents
88 : : * memory leaks if we error out during parsing.
89 : : */
90 : : #define YYMALLOC palloc
91 : : #define YYFREE pfree
92 : :
93 : : /* Private struct for the result of privilege_target production */
94 : : typedef struct PrivTarget
95 : : {
96 : : GrantTargetType targtype;
97 : : ObjectType objtype;
98 : : List *objs;
99 : : } PrivTarget;
100 : :
101 : : /* Private struct for the result of import_qualification production */
102 : : typedef struct ImportQual
103 : : {
104 : : ImportForeignSchemaType type;
105 : : List *table_names;
106 : : } ImportQual;
107 : :
108 : : /* Private struct for the result of select_limit & limit_clause productions */
109 : : typedef struct SelectLimit
110 : : {
111 : : Node *limitOffset;
112 : : Node *limitCount;
113 : : LimitOption limitOption; /* indicates presence of WITH TIES */
114 : : ParseLoc offsetLoc; /* location of OFFSET token, if present */
115 : : ParseLoc countLoc; /* location of LIMIT/FETCH token, if present */
116 : : ParseLoc optionLoc; /* location of WITH TIES, if present */
117 : : } SelectLimit;
118 : :
119 : : /* Private struct for the result of group_clause production */
120 : : typedef struct GroupClause
121 : : {
122 : : bool distinct;
123 : : bool all;
124 : : List *list;
125 : : } GroupClause;
126 : :
127 : : /* Private structs for the result of key_actions and key_action productions */
128 : : typedef struct KeyAction
129 : : {
130 : : char action;
131 : : List *cols;
132 : : } KeyAction;
133 : :
134 : : typedef struct KeyActions
135 : : {
136 : : KeyAction *updateAction;
137 : : KeyAction *deleteAction;
138 : : } KeyActions;
139 : :
140 : : /* ConstraintAttributeSpec yields an integer bitmask of these flags: */
141 : : #define CAS_NOT_DEFERRABLE 0x01
142 : : #define CAS_DEFERRABLE 0x02
143 : : #define CAS_INITIALLY_IMMEDIATE 0x04
144 : : #define CAS_INITIALLY_DEFERRED 0x08
145 : : #define CAS_NOT_VALID 0x10
146 : : #define CAS_NO_INHERIT 0x20
147 : : #define CAS_NOT_ENFORCED 0x40
148 : : #define CAS_ENFORCED 0x80
149 : :
150 : :
151 : : #define parser_yyerror(msg) scanner_yyerror(msg, yyscanner)
152 : : #define parser_errposition(pos) scanner_errposition(pos, yyscanner)
153 : :
154 : : static void base_yyerror(YYLTYPE *yylloc, core_yyscan_t yyscanner,
155 : : const char *msg);
156 : : static RawStmt *makeRawStmt(Node *stmt, int stmt_location);
157 : : static void updateRawStmtEnd(RawStmt *rs, 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);
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, int end_location);
188 : : static Node *makeSQLValueFunction(SQLValueFunctionOp op, int32 typmod,
189 : : int location);
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_pub_all_objtype_list(List *all_objects_list,
206 : : bool *all_tables,
207 : : bool *all_sequences,
208 : : core_yyscan_t yyscanner);
209 : : static void preprocess_pubobj_list(List *pubobjspec_list,
210 : : core_yyscan_t yyscanner);
211 : : static Node *makeRecursiveViewSelect(char *relname, List *aliases, Node *query);
212 : :
213 : : %}
214 : :
215 : : %pure-parser
216 : : %expect 0
217 : : %name-prefix="base_yy"
218 : : %locations
219 : :
220 : : %parse-param {core_yyscan_t yyscanner}
221 : : %lex-param {core_yyscan_t yyscanner}
222 : :
223 : : %union
224 : : {
225 : : core_YYSTYPE core_yystype;
226 : : /* these fields must match core_YYSTYPE: */
227 : : int ival;
228 : : char *str;
229 : : const char *keyword;
230 : :
231 : : char chr;
232 : : bool boolean;
233 : : JoinType jtype;
234 : : DropBehavior dbehavior;
235 : : OnCommitAction oncommit;
236 : : List *list;
237 : : Node *node;
238 : : ObjectType objtype;
239 : : TypeName *typnam;
240 : : FunctionParameter *fun_param;
241 : : FunctionParameterMode fun_param_mode;
242 : : ObjectWithArgs *objwithargs;
243 : : DefElem *defelt;
244 : : SortBy *sortby;
245 : : WindowDef *windef;
246 : : JoinExpr *jexpr;
247 : : IndexElem *ielem;
248 : : StatsElem *selem;
249 : : Alias *alias;
250 : : RangeVar *range;
251 : : IntoClause *into;
252 : : WithClause *with;
253 : : InferClause *infer;
254 : : OnConflictClause *onconflict;
255 : : A_Indices *aind;
256 : : ResTarget *target;
257 : : struct PrivTarget *privtarget;
258 : : AccessPriv *accesspriv;
259 : : struct ImportQual *importqual;
260 : : InsertStmt *istmt;
261 : : VariableSetStmt *vsetstmt;
262 : : PartitionElem *partelem;
263 : : PartitionSpec *partspec;
264 : : PartitionBoundSpec *partboundspec;
265 : : RoleSpec *rolespec;
266 : : PublicationObjSpec *publicationobjectspec;
267 : : PublicationAllObjSpec *publicationallobjectspec;
268 : : struct SelectLimit *selectlimit;
269 : : SetQuantifier setquantifier;
270 : : struct GroupClause *groupclause;
271 : : MergeMatchKind mergematch;
272 : : MergeWhenClause *mergewhen;
273 : : struct KeyActions *keyactions;
274 : : struct KeyAction *keyaction;
275 : : ReturningClause *retclause;
276 : : ReturningOptionKind retoptionkind;
277 : : }
278 : :
279 : : %type <node> stmt toplevel_stmt schema_stmt routine_body_stmt
280 : : AlterEventTrigStmt AlterCollationStmt
281 : : AlterDatabaseStmt AlterDatabaseSetStmt AlterDomainStmt AlterEnumStmt
282 : : AlterFdwStmt AlterForeignServerStmt AlterGroupStmt
283 : : AlterObjectDependsStmt AlterObjectSchemaStmt AlterOwnerStmt
284 : : AlterOperatorStmt AlterTypeStmt AlterSeqStmt AlterSystemStmt AlterTableStmt
285 : : AlterTblSpcStmt AlterExtensionStmt AlterExtensionContentsStmt
286 : : AlterCompositeTypeStmt AlterUserMappingStmt
287 : : AlterRoleStmt AlterRoleSetStmt AlterPolicyStmt AlterStatsStmt
288 : : AlterDefaultPrivilegesStmt DefACLAction
289 : : AnalyzeStmt CallStmt ClosePortalStmt ClusterStmt CommentStmt
290 : : ConstraintsSetStmt CopyStmt CreateAsStmt CreateCastStmt
291 : : CreateDomainStmt CreateExtensionStmt CreateGroupStmt CreateOpClassStmt
292 : : CreateOpFamilyStmt AlterOpFamilyStmt CreatePLangStmt
293 : : CreateSchemaStmt CreateSeqStmt CreateStmt CreateStatsStmt CreateTableSpaceStmt
294 : : CreateFdwStmt CreateForeignServerStmt CreateForeignTableStmt
295 : : CreateAssertionStmt CreateTransformStmt CreateTrigStmt CreateEventTrigStmt
296 : : CreateUserStmt CreateUserMappingStmt CreateRoleStmt CreatePolicyStmt
297 : : CreatedbStmt DeclareCursorStmt DefineStmt DeleteStmt DiscardStmt DoStmt
298 : : DropOpClassStmt DropOpFamilyStmt DropStmt
299 : : DropCastStmt DropRoleStmt
300 : : DropdbStmt DropTableSpaceStmt
301 : : DropTransformStmt
302 : : DropUserMappingStmt ExplainStmt FetchStmt
303 : : GrantStmt GrantRoleStmt ImportForeignSchemaStmt IndexStmt InsertStmt
304 : : ListenStmt LoadStmt LockStmt MergeStmt NotifyStmt ExplainableStmt PreparableStmt
305 : : CreateFunctionStmt AlterFunctionStmt ReindexStmt RemoveAggrStmt
306 : : RemoveFuncStmt RemoveOperStmt RenameStmt ReturnStmt RevokeStmt RevokeRoleStmt
307 : : RuleActionStmt RuleActionStmtOrEmpty RuleStmt
308 : : SecLabelStmt SelectStmt TransactionStmt TransactionStmtLegacy TruncateStmt
309 : : UnlistenStmt UpdateStmt VacuumStmt
310 : : VariableResetStmt VariableSetStmt VariableShowStmt
311 : : ViewStmt CheckPointStmt CreateConversionStmt
312 : : DeallocateStmt PrepareStmt ExecuteStmt
313 : : DropOwnedStmt ReassignOwnedStmt
314 : : AlterTSConfigurationStmt AlterTSDictionaryStmt
315 : : CreateMatViewStmt RefreshMatViewStmt CreateAmStmt
316 : : CreatePublicationStmt AlterPublicationStmt
317 : : CreateSubscriptionStmt AlterSubscriptionStmt DropSubscriptionStmt
318 : :
319 : : %type <node> select_no_parens select_with_parens select_clause
320 : : simple_select values_clause
321 : : PLpgSQL_Expr PLAssignStmt
322 : :
323 : : %type <str> opt_single_name
324 : : %type <list> opt_qualified_name
325 : : %type <boolean> opt_concurrently
326 : : %type <dbehavior> opt_drop_behavior
327 : : %type <list> opt_utility_option_list
328 : : %type <list> utility_option_list
329 : : %type <defelt> utility_option_elem
330 : : %type <str> utility_option_name
331 : : %type <node> utility_option_arg
332 : :
333 : : %type <node> alter_column_default opclass_item opclass_drop alter_using
334 : : %type <ival> add_drop opt_asc_desc opt_nulls_order
335 : :
336 : : %type <node> alter_table_cmd alter_type_cmd opt_collate_clause
337 : : replica_identity partition_cmd index_partition_cmd
338 : : %type <list> alter_table_cmds alter_type_cmds
339 : : %type <list> alter_identity_column_option_list
340 : : %type <defelt> alter_identity_column_option
341 : : %type <node> set_statistics_value
342 : : %type <str> set_access_method_name
343 : :
344 : : %type <list> createdb_opt_list createdb_opt_items copy_opt_list
345 : : transaction_mode_list
346 : : create_extension_opt_list alter_extension_opt_list
347 : : %type <defelt> createdb_opt_item copy_opt_item
348 : : transaction_mode_item
349 : : create_extension_opt_item alter_extension_opt_item
350 : :
351 : : %type <ival> opt_lock lock_type cast_context
352 : : %type <defelt> drop_option
353 : : %type <boolean> opt_or_replace opt_no
354 : : opt_grant_grant_option
355 : : opt_nowait opt_if_exists opt_with_data
356 : : opt_transaction_chain
357 : : %type <list> grant_role_opt_list
358 : : %type <defelt> grant_role_opt
359 : : %type <node> grant_role_opt_value
360 : : %type <ival> opt_nowait_or_skip
361 : :
362 : : %type <list> OptRoleList AlterOptRoleList
363 : : %type <defelt> CreateOptRoleElem AlterOptRoleElem
364 : :
365 : : %type <str> opt_type
366 : : %type <str> foreign_server_version opt_foreign_server_version
367 : : %type <str> opt_in_database
368 : :
369 : : %type <str> parameter_name
370 : : %type <list> OptSchemaEltList parameter_name_list
371 : :
372 : : %type <chr> am_type
373 : :
374 : : %type <boolean> TriggerForSpec TriggerForType
375 : : %type <ival> TriggerActionTime
376 : : %type <list> TriggerEvents TriggerOneEvent
377 : : %type <node> TriggerFuncArg
378 : : %type <node> TriggerWhen
379 : : %type <str> TransitionRelName
380 : : %type <boolean> TransitionRowOrTable TransitionOldOrNew
381 : : %type <node> TriggerTransition
382 : :
383 : : %type <list> event_trigger_when_list event_trigger_value_list
384 : : %type <defelt> event_trigger_when_item
385 : : %type <chr> enable_trigger
386 : :
387 : : %type <str> copy_file_name
388 : : access_method_clause attr_name
389 : : table_access_method_clause name cursor_name file_name
390 : : cluster_index_specification
391 : :
392 : : %type <list> func_name handler_name qual_Op qual_all_Op subquery_Op
393 : : opt_inline_handler opt_validator validator_clause
394 : : opt_collate
395 : :
396 : : %type <range> qualified_name insert_target OptConstrFromTable
397 : :
398 : : %type <str> all_Op MathOp
399 : :
400 : : %type <str> row_security_cmd RowSecurityDefaultForCmd
401 : : %type <boolean> RowSecurityDefaultPermissive
402 : : %type <node> RowSecurityOptionalWithCheck RowSecurityOptionalExpr
403 : : %type <list> RowSecurityDefaultToRole RowSecurityOptionalToRole
404 : :
405 : : %type <str> iso_level opt_encoding
406 : : %type <rolespec> grantee
407 : : %type <list> grantee_list
408 : : %type <accesspriv> privilege
409 : : %type <list> privileges privilege_list
410 : : %type <privtarget> privilege_target
411 : : %type <objwithargs> function_with_argtypes aggregate_with_argtypes operator_with_argtypes
412 : : %type <list> function_with_argtypes_list aggregate_with_argtypes_list operator_with_argtypes_list
413 : : %type <ival> defacl_privilege_target
414 : : %type <defelt> DefACLOption
415 : : %type <list> DefACLOptionList
416 : : %type <ival> import_qualification_type
417 : : %type <importqual> import_qualification
418 : : %type <node> vacuum_relation
419 : : %type <selectlimit> opt_select_limit select_limit limit_clause
420 : :
421 : : %type <list> parse_toplevel stmtmulti routine_body_stmt_list
422 : : OptTableElementList TableElementList OptInherit definition
423 : : OptTypedTableElementList TypedTableElementList
424 : : reloptions opt_reloptions
425 : : OptWith opt_definition func_args func_args_list
426 : : func_args_with_defaults func_args_with_defaults_list
427 : : aggr_args aggr_args_list
428 : : func_as createfunc_opt_list opt_createfunc_opt_list alterfunc_opt_list
429 : : old_aggr_definition old_aggr_list
430 : : oper_argtypes RuleActionList RuleActionMulti
431 : : opt_column_list columnList opt_name_list
432 : : sort_clause opt_sort_clause sortby_list index_params
433 : : stats_params
434 : : opt_include opt_c_include index_including_params
435 : : name_list role_list from_clause from_list opt_array_bounds
436 : : qualified_name_list any_name any_name_list type_name_list
437 : : any_operator expr_list attrs
438 : : distinct_clause opt_distinct_clause
439 : : target_list opt_target_list insert_column_list set_target_list
440 : : merge_values_clause
441 : : set_clause_list set_clause
442 : : def_list operator_def_list indirection opt_indirection
443 : : reloption_list TriggerFuncArgs opclass_item_list opclass_drop_list
444 : : opclass_purpose opt_opfamily transaction_mode_list_or_empty
445 : : OptTableFuncElementList TableFuncElementList opt_type_modifiers
446 : : prep_type_clause
447 : : execute_param_clause using_clause
448 : : returning_with_clause returning_options
449 : : opt_enum_val_list enum_val_list table_func_column_list
450 : : create_generic_options alter_generic_options
451 : : relation_expr_list dostmt_opt_list
452 : : transform_element_list transform_type_list
453 : : TriggerTransitions TriggerReferencing
454 : : vacuum_relation_list opt_vacuum_relation_list
455 : : drop_option_list pub_obj_list pub_obj_type_list
456 : :
457 : : %type <retclause> returning_clause
458 : : %type <node> returning_option
459 : : %type <retoptionkind> returning_option_kind
460 : : %type <node> opt_routine_body
461 : : %type <groupclause> group_clause
462 : : %type <list> group_by_list
463 : : %type <node> group_by_item empty_grouping_set rollup_clause cube_clause
464 : : %type <node> grouping_sets_clause
465 : :
466 : : %type <list> opt_fdw_options fdw_options
467 : : %type <defelt> fdw_option
468 : :
469 : : %type <range> OptTempTableName
470 : : %type <into> into_clause create_as_target create_mv_target
471 : :
472 : : %type <defelt> createfunc_opt_item common_func_opt_item dostmt_opt_item
473 : : %type <fun_param> func_arg func_arg_with_default table_func_column aggr_arg
474 : : %type <fun_param_mode> arg_class
475 : : %type <typnam> func_return func_type
476 : :
477 : : %type <boolean> opt_trusted opt_restart_seqs
478 : : %type <ival> OptTemp
479 : : %type <ival> OptNoLog
480 : : %type <oncommit> OnCommitOption
481 : :
482 : : %type <ival> for_locking_strength
483 : : %type <node> for_locking_item
484 : : %type <list> for_locking_clause opt_for_locking_clause for_locking_items
485 : : %type <list> locked_rels_list
486 : : %type <setquantifier> set_quantifier
487 : :
488 : : %type <node> join_qual
489 : : %type <jtype> join_type
490 : :
491 : : %type <list> extract_list overlay_list position_list
492 : : %type <list> substr_list trim_list
493 : : %type <list> opt_interval interval_second
494 : : %type <str> unicode_normal_form
495 : :
496 : : %type <boolean> opt_instead
497 : : %type <boolean> opt_unique opt_verbose opt_full
498 : : %type <boolean> opt_freeze opt_analyze opt_default
499 : : %type <defelt> opt_binary copy_delimiter
500 : :
501 : : %type <boolean> copy_from opt_program
502 : :
503 : : %type <ival> event cursor_options opt_hold opt_set_data
504 : : %type <objtype> object_type_any_name object_type_name object_type_name_on_any_name
505 : : drop_type_name
506 : :
507 : : %type <node> fetch_args select_limit_value
508 : : offset_clause select_offset_value
509 : : select_fetch_first_value I_or_F_const
510 : : %type <ival> row_or_rows first_or_next
511 : :
512 : : %type <list> OptSeqOptList SeqOptList OptParenthesizedSeqOptList
513 : : %type <defelt> SeqOptElem
514 : :
515 : : %type <istmt> insert_rest
516 : : %type <infer> opt_conf_expr
517 : : %type <onconflict> opt_on_conflict
518 : : %type <mergewhen> merge_insert merge_update merge_delete
519 : :
520 : : %type <mergematch> merge_when_tgt_matched merge_when_tgt_not_matched
521 : : %type <node> merge_when_clause opt_merge_when_condition
522 : : %type <list> merge_when_list
523 : :
524 : : %type <vsetstmt> generic_set set_rest set_rest_more generic_reset reset_rest
525 : : SetResetClause FunctionSetResetClause
526 : :
527 : : %type <node> TableElement TypedTableElement ConstraintElem DomainConstraintElem TableFuncElement
528 : : %type <node> columnDef columnOptions optionalPeriodName
529 : : %type <defelt> def_elem reloption_elem old_aggr_elem operator_def_elem
530 : : %type <node> def_arg columnElem where_clause where_or_current_clause
531 : : a_expr b_expr c_expr AexprConst indirection_el opt_slice_bound
532 : : columnref having_clause func_table xmltable array_expr
533 : : OptWhereClause operator_def_arg
534 : : %type <list> opt_column_and_period_list
535 : : %type <list> rowsfrom_item rowsfrom_list opt_col_def_list
536 : : %type <boolean> opt_ordinality opt_without_overlaps
537 : : %type <list> ExclusionConstraintList ExclusionConstraintElem
538 : : %type <list> func_arg_list func_arg_list_opt
539 : : %type <node> func_arg_expr
540 : : %type <list> row explicit_row implicit_row type_list array_expr_list
541 : : %type <node> case_expr case_arg when_clause case_default
542 : : %type <list> when_clause_list
543 : : %type <node> opt_search_clause opt_cycle_clause
544 : : %type <ival> sub_type opt_materialized
545 : : %type <node> NumericOnly
546 : : %type <list> NumericOnly_list
547 : : %type <alias> alias_clause opt_alias_clause opt_alias_clause_for_join_using
548 : : %type <list> func_alias_clause
549 : : %type <sortby> sortby
550 : : %type <ielem> index_elem index_elem_options
551 : : %type <selem> stats_param
552 : : %type <node> table_ref
553 : : %type <jexpr> joined_table
554 : : %type <range> relation_expr
555 : : %type <range> extended_relation_expr
556 : : %type <range> relation_expr_opt_alias
557 : : %type <node> tablesample_clause opt_repeatable_clause
558 : : %type <target> target_el set_target insert_column_item
559 : :
560 : : %type <str> generic_option_name
561 : : %type <node> generic_option_arg
562 : : %type <defelt> generic_option_elem alter_generic_option_elem
563 : : %type <list> generic_option_list alter_generic_option_list
564 : :
565 : : %type <ival> reindex_target_relation reindex_target_all
566 : :
567 : : %type <node> copy_generic_opt_arg copy_generic_opt_arg_list_item
568 : : %type <defelt> copy_generic_opt_elem
569 : : %type <list> copy_generic_opt_list copy_generic_opt_arg_list
570 : : %type <list> copy_options
571 : :
572 : : %type <typnam> Typename SimpleTypename ConstTypename
573 : : GenericType Numeric opt_float JsonType
574 : : Character ConstCharacter
575 : : CharacterWithLength CharacterWithoutLength
576 : : ConstDatetime ConstInterval
577 : : Bit ConstBit BitWithLength BitWithoutLength
578 : : %type <str> character
579 : : %type <str> extract_arg
580 : : %type <boolean> opt_varying opt_timezone opt_no_inherit
581 : :
582 : : %type <ival> Iconst SignedIconst
583 : : %type <str> Sconst comment_text notify_payload
584 : : %type <str> RoleId opt_boolean_or_string
585 : : %type <list> var_list
586 : : %type <str> ColId ColLabel BareColLabel
587 : : %type <str> NonReservedWord NonReservedWord_or_Sconst
588 : : %type <str> var_name type_function_name param_name
589 : : %type <str> createdb_opt_name plassign_target
590 : : %type <node> var_value zone_value
591 : : %type <rolespec> auth_ident RoleSpec opt_granted_by
592 : : %type <publicationobjectspec> PublicationObjSpec
593 : : %type <publicationallobjectspec> PublicationAllObjSpec
594 : :
595 : : %type <keyword> unreserved_keyword type_func_name_keyword
596 : : %type <keyword> col_name_keyword reserved_keyword
597 : : %type <keyword> bare_label_keyword
598 : :
599 : : %type <node> DomainConstraint TableConstraint TableLikeClause
600 : : %type <ival> TableLikeOptionList TableLikeOption
601 : : %type <str> column_compression opt_column_compression column_storage opt_column_storage
602 : : %type <list> ColQualList
603 : : %type <node> ColConstraint ColConstraintElem ConstraintAttr
604 : : %type <ival> key_match
605 : : %type <keyaction> key_delete key_update key_action
606 : : %type <keyactions> key_actions
607 : : %type <ival> ConstraintAttributeSpec ConstraintAttributeElem
608 : : %type <str> ExistingIndex
609 : :
610 : : %type <list> constraints_set_list
611 : : %type <boolean> constraints_set_mode
612 : : %type <str> OptTableSpace OptConsTableSpace
613 : : %type <rolespec> OptTableSpaceOwner
614 : : %type <ival> opt_check_option
615 : :
616 : : %type <str> opt_provider security_label
617 : :
618 : : %type <target> xml_attribute_el
619 : : %type <list> xml_attribute_list xml_attributes
620 : : %type <node> xml_root_version opt_xml_root_standalone
621 : : %type <node> xmlexists_argument
622 : : %type <ival> document_or_content
623 : : %type <boolean> xml_indent_option xml_whitespace_option
624 : : %type <list> xmltable_column_list xmltable_column_option_list
625 : : %type <node> xmltable_column_el
626 : : %type <defelt> xmltable_column_option_el
627 : : %type <list> xml_namespace_list
628 : : %type <target> xml_namespace_el
629 : :
630 : : %type <node> func_application func_expr_common_subexpr
631 : : %type <node> func_expr func_expr_windowless
632 : : %type <node> common_table_expr
633 : : %type <with> with_clause opt_with_clause
634 : : %type <list> cte_list
635 : :
636 : : %type <list> within_group_clause
637 : : %type <node> filter_clause
638 : : %type <list> window_clause window_definition_list opt_partition_clause
639 : : %type <windef> window_definition over_clause window_specification
640 : : opt_frame_clause frame_extent frame_bound
641 : : %type <ival> null_treatment opt_window_exclusion_clause
642 : : %type <str> opt_existing_window_name
643 : : %type <boolean> opt_if_not_exists
644 : : %type <boolean> opt_unique_null_treatment
645 : : %type <ival> generated_when override_kind opt_virtual_or_stored
646 : : %type <partspec> PartitionSpec OptPartitionSpec
647 : : %type <partelem> part_elem
648 : : %type <list> part_params
649 : : %type <partboundspec> PartitionBoundSpec
650 : : %type <list> hash_partbound
651 : : %type <defelt> hash_partbound_elem
652 : :
653 : : %type <node> json_format_clause
654 : : json_format_clause_opt
655 : : json_value_expr
656 : : json_returning_clause_opt
657 : : json_name_and_value
658 : : json_aggregate_func
659 : : json_argument
660 : : json_behavior
661 : : json_on_error_clause_opt
662 : : json_table
663 : : json_table_column_definition
664 : : json_table_column_path_clause_opt
665 : : %type <list> json_name_and_value_list
666 : : json_value_expr_list
667 : : json_array_aggregate_order_by_clause_opt
668 : : json_arguments
669 : : json_behavior_clause_opt
670 : : json_passing_clause_opt
671 : : json_table_column_definition_list
672 : : %type <str> json_table_path_name_opt
673 : : %type <ival> json_behavior_type
674 : : json_predicate_type_constraint
675 : : json_quotes_clause_opt
676 : : json_wrapper_behavior
677 : : %type <boolean> json_key_uniqueness_constraint_opt
678 : : json_object_constructor_null_clause_opt
679 : : json_array_constructor_null_clause_opt
680 : :
681 : :
682 : : /*
683 : : * Non-keyword token types. These are hard-wired into the "flex" lexer.
684 : : * They must be listed first so that their numeric codes do not depend on
685 : : * the set of keywords. PL/pgSQL depends on this so that it can share the
686 : : * same lexer. If you add/change tokens here, fix PL/pgSQL to match!
687 : : *
688 : : * UIDENT and USCONST are reduced to IDENT and SCONST in parser.c, so that
689 : : * they need no productions here; but we must assign token codes to them.
690 : : *
691 : : * DOT_DOT is unused in the core SQL grammar, and so will always provoke
692 : : * parse errors. It is needed by PL/pgSQL.
693 : : */
694 : : %token <str> IDENT UIDENT FCONST SCONST USCONST BCONST XCONST Op
695 : : %token <ival> ICONST PARAM
696 : : %token TYPECAST DOT_DOT COLON_EQUALS EQUALS_GREATER
697 : : %token LESS_EQUALS GREATER_EQUALS NOT_EQUALS
698 : :
699 : : /*
700 : : * If you want to make any keyword changes, update the keyword table in
701 : : * src/include/parser/kwlist.h and add new keywords to the appropriate one
702 : : * of the reserved-or-not-so-reserved keyword lists, below; search
703 : : * this file for "Keyword category lists".
704 : : */
705 : :
706 : : /* ordinary key words in alphabetical order */
707 : : %token <keyword> ABORT_P ABSENT ABSOLUTE_P ACCESS ACTION ADD_P ADMIN AFTER
708 : : AGGREGATE ALL ALSO ALTER ALWAYS ANALYSE ANALYZE AND ANY ARRAY AS ASC
709 : : ASENSITIVE ASSERTION ASSIGNMENT ASYMMETRIC ATOMIC AT ATTACH ATTRIBUTE AUTHORIZATION
710 : :
711 : : BACKWARD BEFORE BEGIN_P BETWEEN BIGINT BINARY BIT
712 : : BOOLEAN_P BOTH BREADTH BY
713 : :
714 : : CACHE CALL CALLED CASCADE CASCADED CASE CAST CATALOG_P CHAIN CHAR_P
715 : : CHARACTER CHARACTERISTICS CHECK CHECKPOINT CLASS CLOSE
716 : : CLUSTER COALESCE COLLATE COLLATION COLUMN COLUMNS COMMENT COMMENTS COMMIT
717 : : COMMITTED COMPRESSION CONCURRENTLY CONDITIONAL CONFIGURATION CONFLICT
718 : : CONNECTION CONSTRAINT CONSTRAINTS CONTENT_P CONTINUE_P CONVERSION_P COPY
719 : : COST CREATE CROSS CSV CUBE CURRENT_P
720 : : CURRENT_CATALOG CURRENT_DATE CURRENT_ROLE CURRENT_SCHEMA
721 : : CURRENT_TIME CURRENT_TIMESTAMP CURRENT_USER CURSOR CYCLE
722 : :
723 : : DATA_P DATABASE DAY_P DEALLOCATE DEC DECIMAL_P DECLARE DEFAULT DEFAULTS
724 : : DEFERRABLE DEFERRED DEFINER DELETE_P DELIMITER DELIMITERS DEPENDS DEPTH DESC
725 : : DETACH DICTIONARY DISABLE_P DISCARD DISTINCT DO DOCUMENT_P DOMAIN_P
726 : : DOUBLE_P DROP
727 : :
728 : : EACH ELSE EMPTY_P ENABLE_P ENCODING ENCRYPTED END_P ENFORCED ENUM_P ERROR_P
729 : : ESCAPE EVENT EXCEPT EXCLUDE EXCLUDING EXCLUSIVE EXECUTE EXISTS EXPLAIN
730 : : EXPRESSION EXTENSION EXTERNAL EXTRACT
731 : :
732 : : FALSE_P FAMILY FETCH FILTER FINALIZE FIRST_P FLOAT_P FOLLOWING FOR
733 : : FORCE FOREIGN FORMAT FORWARD FREEZE FROM FULL FUNCTION FUNCTIONS
734 : :
735 : : GENERATED GLOBAL GRANT GRANTED GREATEST GROUP_P GROUPING GROUPS
736 : :
737 : : HANDLER HAVING HEADER_P HOLD HOUR_P
738 : :
739 : : IDENTITY_P IF_P IGNORE_P ILIKE IMMEDIATE IMMUTABLE IMPLICIT_P IMPORT_P IN_P INCLUDE
740 : : INCLUDING INCREMENT INDENT INDEX INDEXES INHERIT INHERITS INITIALLY INLINE_P
741 : : INNER_P INOUT INPUT_P INSENSITIVE INSERT INSTEAD INT_P INTEGER
742 : : INTERSECT INTERVAL INTO INVOKER IS ISNULL ISOLATION
743 : :
744 : : JOIN JSON JSON_ARRAY JSON_ARRAYAGG JSON_EXISTS JSON_OBJECT JSON_OBJECTAGG
745 : : JSON_QUERY JSON_SCALAR JSON_SERIALIZE JSON_TABLE JSON_VALUE
746 : :
747 : : KEEP KEY KEYS
748 : :
749 : : LABEL LANGUAGE LARGE_P LAST_P LATERAL_P
750 : : LEADING LEAKPROOF LEAST LEFT LEVEL LIKE LIMIT LISTEN LOAD LOCAL
751 : : LOCALTIME LOCALTIMESTAMP LOCATION LOCK_P LOCKED LOGGED
752 : :
753 : : MAPPING MATCH MATCHED MATERIALIZED MAXVALUE MERGE MERGE_ACTION METHOD
754 : : MINUTE_P MINVALUE MODE MONTH_P MOVE
755 : :
756 : : NAME_P NAMES NATIONAL NATURAL NCHAR NESTED NEW NEXT NFC NFD NFKC NFKD NO
757 : : NONE NORMALIZE NORMALIZED
758 : : NOT NOTHING NOTIFY NOTNULL NOWAIT NULL_P NULLIF
759 : : NULLS_P NUMERIC
760 : :
761 : : OBJECT_P OBJECTS_P OF OFF OFFSET OIDS OLD OMIT ON ONLY OPERATOR OPTION OPTIONS OR
762 : : ORDER ORDINALITY OTHERS OUT_P OUTER_P
763 : : OVER OVERLAPS OVERLAY OVERRIDING OWNED OWNER
764 : :
765 : : PARALLEL PARAMETER PARSER PARTIAL PARTITION PASSING PASSWORD PATH
766 : : PERIOD PLACING PLAN PLANS POLICY
767 : : POSITION PRECEDING PRECISION PRESERVE PREPARE PREPARED PRIMARY
768 : : PRIOR PRIVILEGES PROCEDURAL PROCEDURE PROCEDURES PROGRAM PUBLICATION
769 : :
770 : : QUOTE QUOTES
771 : :
772 : : RANGE READ REAL REASSIGN RECURSIVE REF_P REFERENCES REFERENCING
773 : : REFRESH REINDEX RELATIVE_P RELEASE RENAME REPEATABLE REPLACE REPLICA
774 : : RESET RESPECT_P RESTART RESTRICT RETURN RETURNING RETURNS REVOKE RIGHT ROLE ROLLBACK ROLLUP
775 : : ROUTINE ROUTINES ROW ROWS RULE
776 : :
777 : : SAVEPOINT SCALAR SCHEMA SCHEMAS SCROLL SEARCH SECOND_P SECURITY SELECT
778 : : SEQUENCE SEQUENCES
779 : : SERIALIZABLE SERVER SESSION SESSION_USER SET SETS SETOF SHARE SHOW
780 : : SIMILAR SIMPLE SKIP SMALLINT SNAPSHOT SOME SOURCE SQL_P STABLE STANDALONE_P
781 : : START STATEMENT STATISTICS STDIN STDOUT STORAGE STORED STRICT_P STRING_P STRIP_P
782 : : SUBSCRIPTION SUBSTRING SUPPORT SYMMETRIC SYSID SYSTEM_P SYSTEM_USER
783 : :
784 : : TABLE TABLES TABLESAMPLE TABLESPACE TARGET TEMP TEMPLATE TEMPORARY TEXT_P THEN
785 : : TIES TIME TIMESTAMP TO TRAILING TRANSACTION TRANSFORM
786 : : TREAT TRIGGER TRIM TRUE_P
787 : : TRUNCATE TRUSTED TYPE_P TYPES_P
788 : :
789 : : UESCAPE UNBOUNDED UNCONDITIONAL UNCOMMITTED UNENCRYPTED UNION UNIQUE UNKNOWN
790 : : UNLISTEN UNLOGGED UNTIL UPDATE USER USING
791 : :
792 : : VACUUM VALID VALIDATE VALIDATOR VALUE_P VALUES VARCHAR VARIADIC VARYING
793 : : VERBOSE VERSION_P VIEW VIEWS VIRTUAL VOLATILE
794 : :
795 : : WHEN WHERE WHITESPACE_P WINDOW WITH WITHIN WITHOUT WORK WRAPPER WRITE
796 : :
797 : : XML_P XMLATTRIBUTES XMLCONCAT XMLELEMENT XMLEXISTS XMLFOREST XMLNAMESPACES
798 : : XMLPARSE XMLPI XMLROOT XMLSERIALIZE XMLTABLE
799 : :
800 : : YEAR_P YES_P
801 : :
802 : : ZONE
803 : :
804 : : /*
805 : : * The grammar thinks these are keywords, but they are not in the kwlist.h
806 : : * list and so can never be entered directly. The filter in parser.c
807 : : * creates these tokens when required (based on looking one token ahead).
808 : : *
809 : : * NOT_LA exists so that productions such as NOT LIKE can be given the same
810 : : * precedence as LIKE; otherwise they'd effectively have the same precedence
811 : : * as NOT, at least with respect to their left-hand subexpression.
812 : : * FORMAT_LA, NULLS_LA, WITH_LA, and WITHOUT_LA are needed to make the grammar
813 : : * LALR(1).
814 : : */
815 : : %token FORMAT_LA NOT_LA NULLS_LA WITH_LA WITHOUT_LA
816 : :
817 : : /*
818 : : * The grammar likewise thinks these tokens are keywords, but they are never
819 : : * generated by the scanner. Rather, they can be injected by parser.c as
820 : : * the initial token of the string (using the lookahead-token mechanism
821 : : * implemented there). This provides a way to tell the grammar to parse
822 : : * something other than the usual list of SQL commands.
823 : : */
824 : : %token MODE_TYPE_NAME
825 : : %token MODE_PLPGSQL_EXPR
826 : : %token MODE_PLPGSQL_ASSIGN1
827 : : %token MODE_PLPGSQL_ASSIGN2
828 : : %token MODE_PLPGSQL_ASSIGN3
829 : :
830 : :
831 : : /* Precedence: lowest to highest */
832 : : %left UNION EXCEPT
833 : : %left INTERSECT
834 : : %left OR
835 : : %left AND
836 : : %right NOT
837 : : %nonassoc IS ISNULL NOTNULL /* IS sets precedence for IS NULL, etc */
838 : : %nonassoc '<' '>' '=' LESS_EQUALS GREATER_EQUALS NOT_EQUALS
839 : : %nonassoc BETWEEN IN_P LIKE ILIKE SIMILAR NOT_LA
840 : : %nonassoc ESCAPE /* ESCAPE must be just above LIKE/ILIKE/SIMILAR */
841 : :
842 : : /*
843 : : * Sometimes it is necessary to assign precedence to keywords that are not
844 : : * really part of the operator hierarchy, in order to resolve grammar
845 : : * ambiguities. It's best to avoid doing so whenever possible, because such
846 : : * assignments have global effect and may hide ambiguities besides the one
847 : : * you intended to solve. (Attaching a precedence to a single rule with
848 : : * %prec is far safer and should be preferred.) If you must give precedence
849 : : * to a new keyword, try very hard to give it the same precedence as IDENT.
850 : : * If the keyword has IDENT's precedence then it clearly acts the same as
851 : : * non-keywords and other similar keywords, thus reducing the risk of
852 : : * unexpected precedence effects.
853 : : *
854 : : * We used to need to assign IDENT an explicit precedence just less than Op,
855 : : * to support target_el without AS. While that's not really necessary since
856 : : * we removed postfix operators, we continue to do so because it provides a
857 : : * reference point for a precedence level that we can assign to other
858 : : * keywords that lack a natural precedence level.
859 : : *
860 : : * We need to do this for PARTITION, RANGE, ROWS, and GROUPS to support
861 : : * opt_existing_window_name (see comment there).
862 : : *
863 : : * The frame_bound productions UNBOUNDED PRECEDING and UNBOUNDED FOLLOWING
864 : : * are even messier: since UNBOUNDED is an unreserved keyword (per spec!),
865 : : * there is no principled way to distinguish these from the productions
866 : : * a_expr PRECEDING/FOLLOWING. We hack this up by giving UNBOUNDED slightly
867 : : * lower precedence than PRECEDING and FOLLOWING. At present this doesn't
868 : : * appear to cause UNBOUNDED to be treated differently from other unreserved
869 : : * keywords anywhere else in the grammar, but it's definitely risky. We can
870 : : * blame any funny behavior of UNBOUNDED on the SQL standard, though.
871 : : *
872 : : * To support CUBE and ROLLUP in GROUP BY without reserving them, we give them
873 : : * an explicit priority lower than '(', so that a rule with CUBE '(' will shift
874 : : * rather than reducing a conflicting rule that takes CUBE as a function name.
875 : : * Using the same precedence as IDENT seems right for the reasons given above.
876 : : *
877 : : * SET is likewise assigned the same precedence as IDENT, to support the
878 : : * relation_expr_opt_alias production (see comment there).
879 : : *
880 : : * KEYS, OBJECT_P, SCALAR, VALUE_P, WITH, and WITHOUT are similarly assigned
881 : : * the same precedence as IDENT. This allows resolving conflicts in the
882 : : * json_predicate_type_constraint and json_key_uniqueness_constraint_opt
883 : : * productions (see comments there).
884 : : *
885 : : * Like the UNBOUNDED PRECEDING/FOLLOWING case, NESTED is assigned a lower
886 : : * precedence than PATH to fix ambiguity in the json_table production.
887 : : */
888 : : %nonassoc UNBOUNDED NESTED /* ideally would have same precedence as IDENT */
889 : : %nonassoc IDENT PARTITION RANGE ROWS GROUPS PRECEDING FOLLOWING CUBE ROLLUP
890 : : SET KEYS OBJECT_P SCALAR VALUE_P WITH WITHOUT PATH
891 : : %left Op OPERATOR /* multi-character ops and user-defined operators */
892 : : %left '+' '-'
893 : : %left '*' '/' '%'
894 : : %left '^'
895 : : /* Unary Operators */
896 : : %left AT /* sets precedence for AT TIME ZONE, AT LOCAL */
897 : : %left COLLATE
898 : : %right UMINUS
899 : : %left '[' ']'
900 : : %left '(' ')'
901 : : %left TYPECAST
902 : : %left '.'
903 : : /*
904 : : * These might seem to be low-precedence, but actually they are not part
905 : : * of the arithmetic hierarchy at all in their use as JOIN operators.
906 : : * We make them high-precedence to support their use as function names.
907 : : * They wouldn't be given a precedence at all, were it not that we need
908 : : * left-associativity among the JOIN rules themselves.
909 : : */
910 : : %left JOIN CROSS LEFT FULL RIGHT INNER_P NATURAL
911 : :
912 : : %%
913 : :
914 : : /*
915 : : * The target production for the whole parse.
916 : : *
917 : : * Ordinarily we parse a list of statements, but if we see one of the
918 : : * special MODE_XXX symbols as first token, we parse something else.
919 : : * The options here correspond to enum RawParseMode, which see for details.
920 : : */
921 : : parse_toplevel:
922 : : stmtmulti
923 : : {
5950 tgl@sss.pgh.pa.us 924 :CBC 358187 : pg_yyget_extra(yyscanner)->parsetree = $1;
925 : : (void) yynerrs; /* suppress compiler warning */
926 : : }
927 : : | MODE_TYPE_NAME Typename
928 : : {
1757 929 : 4958 : pg_yyget_extra(yyscanner)->parsetree = list_make1($2);
930 : : }
931 : : | MODE_PLPGSQL_EXPR PLpgSQL_Expr
932 : : {
933 : 17173 : pg_yyget_extra(yyscanner)->parsetree =
370 934 : 17173 : list_make1(makeRawStmt($2, @2));
935 : : }
936 : : | MODE_PLPGSQL_ASSIGN1 PLAssignStmt
937 : : {
1757 938 : 3288 : PLAssignStmt *n = (PLAssignStmt *) $2;
939 : :
940 : 3288 : n->nnames = 1;
941 : 3288 : pg_yyget_extra(yyscanner)->parsetree =
370 942 : 3288 : list_make1(makeRawStmt((Node *) n, @2));
943 : : }
944 : : | MODE_PLPGSQL_ASSIGN2 PLAssignStmt
945 : : {
1757 946 : 337 : PLAssignStmt *n = (PLAssignStmt *) $2;
947 : :
948 : 337 : n->nnames = 2;
949 : 337 : pg_yyget_extra(yyscanner)->parsetree =
370 950 : 337 : list_make1(makeRawStmt((Node *) n, @2));
951 : : }
952 : : | MODE_PLPGSQL_ASSIGN3 PLAssignStmt
953 : : {
1757 954 : 14 : PLAssignStmt *n = (PLAssignStmt *) $2;
955 : :
956 : 14 : n->nnames = 3;
957 : 14 : pg_yyget_extra(yyscanner)->parsetree =
370 958 : 14 : list_make1(makeRawStmt((Node *) n, @2));
959 : : }
960 : : ;
961 : :
962 : : /*
963 : : * At top level, we wrap each stmt with a RawStmt node carrying start location
964 : : * and length of the stmt's text.
965 : : * We also take care to discard empty statements entirely (which among other
966 : : * things dodges the problem of assigning them a location).
967 : : */
968 : : stmtmulti: stmtmulti ';' toplevel_stmt
969 : : {
3208 970 [ + + ]: 295138 : if ($1 != NIL)
971 : : {
972 : : /* update length of previous stmt */
3122 973 : 294775 : updateRawStmtEnd(llast_node(RawStmt, $1), @2);
974 : : }
5950 975 [ + + ]: 295138 : if ($3 != NULL)
370 976 : 29247 : $$ = lappend($1, makeRawStmt($3, @3));
977 : : else
5950 978 : 265891 : $$ = $1;
979 : : }
980 : : | toplevel_stmt
981 : : {
982 [ + + ]: 358191 : if ($1 != NULL)
370 983 : 357444 : $$ = list_make1(makeRawStmt($1, @1));
984 : : else
8533 bruce@momjian.us 985 : 747 : $$ = NIL;
986 : : }
987 : : ;
988 : :
989 : : /*
990 : : * toplevel_stmt includes BEGIN and END. stmt does not include them, because
991 : : * those words have different meanings in function bodies.
992 : : */
993 : : toplevel_stmt:
994 : : stmt
995 : : | TransactionStmtLegacy
996 : : ;
997 : :
998 : : stmt:
999 : : AlterEventTrigStmt
1000 : : | AlterCollationStmt
1001 : : | AlterDatabaseStmt
1002 : : | AlterDatabaseSetStmt
1003 : : | AlterDefaultPrivilegesStmt
1004 : : | AlterDomainStmt
1005 : : | AlterEnumStmt
1006 : : | AlterExtensionStmt
1007 : : | AlterExtensionContentsStmt
1008 : : | AlterFdwStmt
1009 : : | AlterForeignServerStmt
1010 : : | AlterFunctionStmt
1011 : : | AlterGroupStmt
1012 : : | AlterObjectDependsStmt
1013 : : | AlterObjectSchemaStmt
1014 : : | AlterOwnerStmt
1015 : : | AlterOperatorStmt
1016 : : | AlterTypeStmt
1017 : : | AlterPolicyStmt
1018 : : | AlterSeqStmt
1019 : : | AlterSystemStmt
1020 : : | AlterTableStmt
1021 : : | AlterTblSpcStmt
1022 : : | AlterCompositeTypeStmt
1023 : : | AlterPublicationStmt
1024 : : | AlterRoleSetStmt
1025 : : | AlterRoleStmt
1026 : : | AlterSubscriptionStmt
1027 : : | AlterStatsStmt
1028 : : | AlterTSConfigurationStmt
1029 : : | AlterTSDictionaryStmt
1030 : : | AlterUserMappingStmt
1031 : : | AnalyzeStmt
1032 : : | CallStmt
1033 : : | CheckPointStmt
1034 : : | ClosePortalStmt
1035 : : | ClusterStmt
1036 : : | CommentStmt
1037 : : | ConstraintsSetStmt
1038 : : | CopyStmt
1039 : : | CreateAmStmt
1040 : : | CreateAsStmt
1041 : : | CreateAssertionStmt
1042 : : | CreateCastStmt
1043 : : | CreateConversionStmt
1044 : : | CreateDomainStmt
1045 : : | CreateExtensionStmt
1046 : : | CreateFdwStmt
1047 : : | CreateForeignServerStmt
1048 : : | CreateForeignTableStmt
1049 : : | CreateFunctionStmt
1050 : : | CreateGroupStmt
1051 : : | CreateMatViewStmt
1052 : : | CreateOpClassStmt
1053 : : | CreateOpFamilyStmt
1054 : : | CreatePublicationStmt
1055 : : | AlterOpFamilyStmt
1056 : : | CreatePolicyStmt
1057 : : | CreatePLangStmt
1058 : : | CreateSchemaStmt
1059 : : | CreateSeqStmt
1060 : : | CreateStmt
1061 : : | CreateSubscriptionStmt
1062 : : | CreateStatsStmt
1063 : : | CreateTableSpaceStmt
1064 : : | CreateTransformStmt
1065 : : | CreateTrigStmt
1066 : : | CreateEventTrigStmt
1067 : : | CreateRoleStmt
1068 : : | CreateUserStmt
1069 : : | CreateUserMappingStmt
1070 : : | CreatedbStmt
1071 : : | DeallocateStmt
1072 : : | DeclareCursorStmt
1073 : : | DefineStmt
1074 : : | DeleteStmt
1075 : : | DiscardStmt
1076 : : | DoStmt
1077 : : | DropCastStmt
1078 : : | DropOpClassStmt
1079 : : | DropOpFamilyStmt
1080 : : | DropOwnedStmt
1081 : : | DropStmt
1082 : : | DropSubscriptionStmt
1083 : : | DropTableSpaceStmt
1084 : : | DropTransformStmt
1085 : : | DropRoleStmt
1086 : : | DropUserMappingStmt
1087 : : | DropdbStmt
1088 : : | ExecuteStmt
1089 : : | ExplainStmt
1090 : : | FetchStmt
1091 : : | GrantStmt
1092 : : | GrantRoleStmt
1093 : : | ImportForeignSchemaStmt
1094 : : | IndexStmt
1095 : : | InsertStmt
1096 : : | ListenStmt
1097 : : | RefreshMatViewStmt
1098 : : | LoadStmt
1099 : : | LockStmt
1100 : : | MergeStmt
1101 : : | NotifyStmt
1102 : : | PrepareStmt
1103 : : | ReassignOwnedStmt
1104 : : | ReindexStmt
1105 : : | RemoveAggrStmt
1106 : : | RemoveFuncStmt
1107 : : | RemoveOperStmt
1108 : : | RenameStmt
1109 : : | RevokeStmt
1110 : : | RevokeRoleStmt
1111 : : | RuleStmt
1112 : : | SecLabelStmt
1113 : : | SelectStmt
1114 : : | TransactionStmt
1115 : : | TruncateStmt
1116 : : | UnlistenStmt
1117 : : | UpdateStmt
1118 : : | VacuumStmt
1119 : : | VariableResetStmt
1120 : : | VariableSetStmt
1121 : : | VariableShowStmt
1122 : : | ViewStmt
1123 : : | /*EMPTY*/
7964 neilc@samurai.com 1124 : 266647 : { $$ = NULL; }
1125 : : ;
1126 : :
1127 : : /*
1128 : : * Generic supporting productions for DDL
1129 : : */
1130 : : opt_single_name:
1193 alvherre@alvh.no-ip. 1131 : 2685 : ColId { $$ = $1; }
1132 : 784 : | /* EMPTY */ { $$ = NULL; }
1133 : : ;
1134 : :
1135 : : opt_qualified_name:
1136 : 944 : any_name { $$ = $1; }
1137 : 7672 : | /*EMPTY*/ { $$ = NIL; }
1138 : : ;
1139 : :
1140 : : opt_concurrently:
1141 : 516 : CONCURRENTLY { $$ = true; }
1142 : 3817 : | /*EMPTY*/ { $$ = false; }
1143 : : ;
1144 : :
1145 : : opt_drop_behavior:
1146 : 985 : CASCADE { $$ = DROP_CASCADE; }
1147 : 85 : | RESTRICT { $$ = DROP_RESTRICT; }
1148 : 19690 : | /* EMPTY */ { $$ = DROP_RESTRICT; /* default */ }
1149 : : ;
1150 : :
1151 : : opt_utility_option_list:
94 alvherre@kurilemu.de 1152 :GNC 183 : '(' utility_option_list ')' { $$ = $2; }
1153 : 3029 : | /* EMPTY */ { $$ = NULL; }
1154 : : ;
1155 : :
1156 : : utility_option_list:
1157 : : utility_option_elem
1158 : : {
1159 : 11226 : $$ = list_make1($1);
1160 : : }
1161 : : | utility_option_list ',' utility_option_elem
1162 : : {
1163 : 6373 : $$ = lappend($1, $3);
1164 : : }
1165 : : ;
1166 : :
1167 : : utility_option_elem:
1168 : : utility_option_name utility_option_arg
1169 : : {
1170 : 17599 : $$ = makeDefElem($1, $2, @1);
1171 : : }
1172 : : ;
1173 : :
1174 : : utility_option_name:
1175 : 15702 : NonReservedWord { $$ = $1; }
1176 : 1826 : | analyze_keyword { $$ = "analyze"; }
1177 : 74 : | FORMAT_LA { $$ = "format"; }
1178 : : ;
1179 : :
1180 : : utility_option_arg:
1181 : 8991 : opt_boolean_or_string { $$ = (Node *) makeString($1); }
1182 : 191 : | NumericOnly { $$ = (Node *) $1; }
1183 : 8417 : | /* EMPTY */ { $$ = NULL; }
1184 : : ;
1185 : :
1186 : : /*****************************************************************************
1187 : : *
1188 : : * CALL statement
1189 : : *
1190 : : *****************************************************************************/
1191 : :
1192 : : CallStmt: CALL func_application
1193 : : {
1263 peter@eisentraut.org 1194 :CBC 305 : CallStmt *n = makeNode(CallStmt);
1195 : :
2888 peter_e@gmx.net 1196 : 305 : n->funccall = castNode(FuncCall, $2);
1263 peter@eisentraut.org 1197 : 305 : $$ = (Node *) n;
1198 : : }
1199 : : ;
1200 : :
1201 : : /*****************************************************************************
1202 : : *
1203 : : * Create a new Postgres DBMS role
1204 : : *
1205 : : *****************************************************************************/
1206 : :
1207 : : CreateRoleStmt:
1208 : : CREATE ROLE RoleId opt_with OptRoleList
1209 : : {
7426 tgl@sss.pgh.pa.us 1210 : 691 : CreateRoleStmt *n = makeNode(CreateRoleStmt);
1211 : :
7398 1212 : 691 : n->stmt_type = ROLESTMT_ROLE;
7426 1213 : 691 : n->role = $3;
8875 1214 : 691 : n->options = $5;
1263 peter@eisentraut.org 1215 : 691 : $$ = (Node *) n;
1216 : : }
1217 : : ;
1218 : :
1219 : :
1220 : : opt_with: WITH
1221 : : | WITH_LA
1222 : : | /*EMPTY*/
1223 : : ;
1224 : :
1225 : : /*
1226 : : * Options for CREATE ROLE and ALTER ROLE (also used by CREATE/ALTER USER
1227 : : * for backwards compatibility). Note: the only option required by SQL99
1228 : : * is "WITH ADMIN name".
1229 : : */
1230 : : OptRoleList:
5864 alvherre@alvh.no-ip. 1231 : 596 : OptRoleList CreateOptRoleElem { $$ = lappend($1, $2); }
7426 tgl@sss.pgh.pa.us 1232 : 930 : | /* EMPTY */ { $$ = NIL; }
1233 : : ;
1234 : :
1235 : : AlterOptRoleList:
5864 alvherre@alvh.no-ip. 1236 : 382 : AlterOptRoleList AlterOptRoleElem { $$ = lappend($1, $2); }
1237 : 214 : | /* EMPTY */ { $$ = NIL; }
1238 : : ;
1239 : :
1240 : : AlterOptRoleElem:
1241 : : PASSWORD Sconst
1242 : : {
7426 tgl@sss.pgh.pa.us 1243 : 94 : $$ = makeDefElem("password",
1263 peter@eisentraut.org 1244 : 94 : (Node *) makeString($2), @1);
1245 : : }
1246 : : | PASSWORD NULL_P
1247 : : {
3338 peter_e@gmx.net 1248 : 6 : $$ = makeDefElem("password", NULL, @1);
1249 : : }
1250 : : | ENCRYPTED PASSWORD Sconst
1251 : : {
1252 : : /*
1253 : : * These days, passwords are always stored in encrypted
1254 : : * form, so there is no difference between PASSWORD and
1255 : : * ENCRYPTED PASSWORD.
1256 : : */
3094 heikki.linnakangas@i 1257 : 6 : $$ = makeDefElem("password",
1263 peter@eisentraut.org 1258 : 6 : (Node *) makeString($3), @1);
1259 : : }
1260 : : | UNENCRYPTED PASSWORD Sconst
1261 : : {
3094 heikki.linnakangas@i 1262 [ # # ]:UBC 0 : ereport(ERROR,
1263 : : (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
1264 : : errmsg("UNENCRYPTED PASSWORD is no longer supported"),
1265 : : errhint("Remove UNENCRYPTED to store the password in encrypted form instead."),
1266 : : parser_errposition(@1)));
1267 : : }
1268 : : | INHERIT
1269 : : {
1263 peter@eisentraut.org 1270 :CBC 56 : $$ = makeDefElem("inherit", (Node *) makeBoolean(true), @1);
1271 : : }
1272 : : | CONNECTION LIMIT SignedIconst
1273 : : {
1274 : 12 : $$ = makeDefElem("connectionlimit", (Node *) makeInteger($3), @1);
1275 : : }
1276 : : | VALID UNTIL Sconst
1277 : : {
1278 : 1 : $$ = makeDefElem("validUntil", (Node *) makeString($3), @1);
1279 : : }
1280 : : /* Supported but not documented for roles, for use by ALTER GROUP. */
1281 : : | USER role_list
1282 : : {
1283 : 3 : $$ = makeDefElem("rolemembers", (Node *) $2, @1);
1284 : : }
1285 : : | IDENT
1286 : : {
1287 : : /*
1288 : : * We handle identifiers that aren't parser keywords with
1289 : : * the following special-case codes, to avoid bloating the
1290 : : * size of the main parser.
1291 : : */
5340 rhaas@postgresql.org 1292 [ + + ]: 725 : if (strcmp($1, "superuser") == 0)
1263 peter@eisentraut.org 1293 : 96 : $$ = makeDefElem("superuser", (Node *) makeBoolean(true), @1);
5340 rhaas@postgresql.org 1294 [ + + ]: 629 : else if (strcmp($1, "nosuperuser") == 0)
1263 peter@eisentraut.org 1295 : 58 : $$ = makeDefElem("superuser", (Node *) makeBoolean(false), @1);
5340 rhaas@postgresql.org 1296 [ + + ]: 571 : else if (strcmp($1, "createrole") == 0)
1263 peter@eisentraut.org 1297 : 51 : $$ = makeDefElem("createrole", (Node *) makeBoolean(true), @1);
5340 rhaas@postgresql.org 1298 [ + + ]: 520 : else if (strcmp($1, "nocreaterole") == 0)
1263 peter@eisentraut.org 1299 : 27 : $$ = makeDefElem("createrole", (Node *) makeBoolean(false), @1);
5340 rhaas@postgresql.org 1300 [ + + ]: 493 : else if (strcmp($1, "replication") == 0)
1263 peter@eisentraut.org 1301 : 65 : $$ = makeDefElem("isreplication", (Node *) makeBoolean(true), @1);
5340 rhaas@postgresql.org 1302 [ + + ]: 428 : else if (strcmp($1, "noreplication") == 0)
1263 peter@eisentraut.org 1303 : 56 : $$ = makeDefElem("isreplication", (Node *) makeBoolean(false), @1);
5340 rhaas@postgresql.org 1304 [ + + ]: 372 : else if (strcmp($1, "createdb") == 0)
1263 peter@eisentraut.org 1305 : 46 : $$ = makeDefElem("createdb", (Node *) makeBoolean(true), @1);
5340 rhaas@postgresql.org 1306 [ + + ]: 326 : else if (strcmp($1, "nocreatedb") == 0)
1263 peter@eisentraut.org 1307 : 31 : $$ = makeDefElem("createdb", (Node *) makeBoolean(false), @1);
5340 rhaas@postgresql.org 1308 [ + + ]: 295 : else if (strcmp($1, "login") == 0)
1263 peter@eisentraut.org 1309 : 143 : $$ = makeDefElem("canlogin", (Node *) makeBoolean(true), @1);
5340 rhaas@postgresql.org 1310 [ + + ]: 152 : else if (strcmp($1, "nologin") == 0)
1263 peter@eisentraut.org 1311 : 51 : $$ = makeDefElem("canlogin", (Node *) makeBoolean(false), @1);
4056 sfrost@snowman.net 1312 [ + + ]: 101 : else if (strcmp($1, "bypassrls") == 0)
1263 peter@eisentraut.org 1313 : 41 : $$ = makeDefElem("bypassrls", (Node *) makeBoolean(true), @1);
4056 sfrost@snowman.net 1314 [ + + ]: 60 : else if (strcmp($1, "nobypassrls") == 0)
1263 peter@eisentraut.org 1315 : 42 : $$ = makeDefElem("bypassrls", (Node *) makeBoolean(false), @1);
5340 rhaas@postgresql.org 1316 [ + - ]: 18 : else if (strcmp($1, "noinherit") == 0)
1317 : : {
1318 : : /*
1319 : : * Note that INHERIT is a keyword, so it's handled by main parser, but
1320 : : * NOINHERIT is handled here.
1321 : : */
1263 peter@eisentraut.org 1322 : 18 : $$ = makeDefElem("inherit", (Node *) makeBoolean(false), @1);
1323 : : }
1324 : : else
5340 rhaas@postgresql.org 1325 [ # # ]:UBC 0 : ereport(ERROR,
1326 : : (errcode(ERRCODE_SYNTAX_ERROR),
1327 : : errmsg("unrecognized role option \"%s\"", $1),
1328 : : parser_errposition(@1)));
1329 : : }
1330 : : ;
1331 : :
1332 : : CreateOptRoleElem:
5864 alvherre@alvh.no-ip. 1333 :CBC 521 : AlterOptRoleElem { $$ = $1; }
1334 : : /* The following are not supported by ALTER ROLE/USER/GROUP */
1335 : : | SYSID Iconst
1336 : : {
1263 peter@eisentraut.org 1337 : 3 : $$ = makeDefElem("sysid", (Node *) makeInteger($2), @1);
1338 : : }
1339 : : | ADMIN role_list
1340 : : {
1341 : 11 : $$ = makeDefElem("adminmembers", (Node *) $2, @1);
1342 : : }
1343 : : | ROLE role_list
1344 : : {
1345 : 11 : $$ = makeDefElem("rolemembers", (Node *) $2, @1);
1346 : : }
1347 : : | IN_P ROLE role_list
1348 : : {
1349 : 50 : $$ = makeDefElem("addroleto", (Node *) $3, @1);
1350 : : }
1351 : : | IN_P GROUP_P role_list
1352 : : {
1263 peter@eisentraut.org 1353 :UBC 0 : $$ = makeDefElem("addroleto", (Node *) $3, @1);
1354 : : }
1355 : : ;
1356 : :
1357 : :
1358 : : /*****************************************************************************
1359 : : *
1360 : : * Create a new Postgres DBMS user (role with implied login ability)
1361 : : *
1362 : : *****************************************************************************/
1363 : :
1364 : : CreateUserStmt:
1365 : : CREATE USER RoleId opt_with OptRoleList
1366 : : {
7426 tgl@sss.pgh.pa.us 1367 :CBC 227 : CreateRoleStmt *n = makeNode(CreateRoleStmt);
1368 : :
7398 1369 : 227 : n->stmt_type = ROLESTMT_USER;
7426 1370 : 227 : n->role = $3;
7398 1371 : 227 : n->options = $5;
1263 peter@eisentraut.org 1372 : 227 : $$ = (Node *) n;
1373 : : }
1374 : : ;
1375 : :
1376 : :
1377 : : /*****************************************************************************
1378 : : *
1379 : : * Alter a postgresql DBMS role
1380 : : *
1381 : : *****************************************************************************/
1382 : :
1383 : : AlterRoleStmt:
1384 : : ALTER ROLE RoleSpec opt_with AlterOptRoleList
1385 : : {
7426 tgl@sss.pgh.pa.us 1386 : 171 : AlterRoleStmt *n = makeNode(AlterRoleStmt);
1387 : :
1388 : 171 : n->role = $3;
7398 1389 : 171 : n->action = +1; /* add, if there are members */
7426 1390 : 171 : n->options = $5;
1263 peter@eisentraut.org 1391 : 171 : $$ = (Node *) n;
1392 : : }
1393 : : | ALTER USER RoleSpec opt_with AlterOptRoleList
1394 : : {
3010 peter_e@gmx.net 1395 : 43 : AlterRoleStmt *n = makeNode(AlterRoleStmt);
1396 : :
1397 : 43 : n->role = $3;
1398 : 43 : n->action = +1; /* add, if there are members */
1399 : 43 : n->options = $5;
1263 peter@eisentraut.org 1400 : 43 : $$ = (Node *) n;
1401 : : }
1402 : : ;
1403 : :
1404 : : opt_in_database:
5864 alvherre@alvh.no-ip. 1405 : 47 : /* EMPTY */ { $$ = NULL; }
1965 peter@eisentraut.org 1406 : 2 : | IN_P DATABASE name { $$ = $3; }
1407 : : ;
1408 : :
1409 : : AlterRoleSetStmt:
1410 : : ALTER ROLE RoleSpec opt_in_database SetResetClause
1411 : : {
7426 tgl@sss.pgh.pa.us 1412 : 29 : AlterRoleSetStmt *n = makeNode(AlterRoleSetStmt);
1413 : :
1414 : 29 : n->role = $3;
5864 alvherre@alvh.no-ip. 1415 : 29 : n->database = $4;
1416 : 29 : n->setstmt = $5;
1263 peter@eisentraut.org 1417 : 29 : $$ = (Node *) n;
1418 : : }
1419 : : | ALTER ROLE ALL opt_in_database SetResetClause
1420 : : {
4635 peter_e@gmx.net 1421 : 2 : AlterRoleSetStmt *n = makeNode(AlterRoleSetStmt);
1422 : :
1423 : 2 : n->role = NULL;
1424 : 2 : n->database = $4;
1425 : 2 : n->setstmt = $5;
1263 peter@eisentraut.org 1426 : 2 : $$ = (Node *) n;
1427 : : }
1428 : : | ALTER USER RoleSpec opt_in_database SetResetClause
1429 : : {
3010 peter_e@gmx.net 1430 : 14 : AlterRoleSetStmt *n = makeNode(AlterRoleSetStmt);
1431 : :
7426 tgl@sss.pgh.pa.us 1432 : 14 : n->role = $3;
3010 peter_e@gmx.net 1433 : 14 : n->database = $4;
1434 : 14 : n->setstmt = $5;
1263 peter@eisentraut.org 1435 : 14 : $$ = (Node *) n;
1436 : : }
1437 : : | ALTER USER ALL opt_in_database SetResetClause
1438 : : {
7426 tgl@sss.pgh.pa.us 1439 : 2 : AlterRoleSetStmt *n = makeNode(AlterRoleSetStmt);
1440 : :
3010 peter_e@gmx.net 1441 : 2 : n->role = NULL;
1442 : 2 : n->database = $4;
1443 : 2 : n->setstmt = $5;
1263 peter@eisentraut.org 1444 : 2 : $$ = (Node *) n;
1445 : : }
1446 : : ;
1447 : :
1448 : :
1449 : : /*****************************************************************************
1450 : : *
1451 : : * Drop a postgresql DBMS role
1452 : : *
1453 : : * XXX Ideally this would have CASCADE/RESTRICT options, but a role
1454 : : * might own objects in multiple databases, and there is presently no way to
1455 : : * implement cascading to other databases. So we always behave as RESTRICT.
1456 : : *****************************************************************************/
1457 : :
1458 : : DropRoleStmt:
1459 : : DROP ROLE role_list
1460 : : {
7426 tgl@sss.pgh.pa.us 1461 : 555 : DropRoleStmt *n = makeNode(DropRoleStmt);
1462 : :
2994 peter_e@gmx.net 1463 : 555 : n->missing_ok = false;
7426 tgl@sss.pgh.pa.us 1464 : 555 : n->roles = $3;
1263 peter@eisentraut.org 1465 : 555 : $$ = (Node *) n;
1466 : : }
1467 : : | DROP ROLE IF_P EXISTS role_list
1468 : : {
7205 andrew@dunslane.net 1469 : 67 : DropRoleStmt *n = makeNode(DropRoleStmt);
1470 : :
2994 peter_e@gmx.net 1471 : 67 : n->missing_ok = true;
7205 andrew@dunslane.net 1472 : 67 : n->roles = $5;
1263 peter@eisentraut.org 1473 : 67 : $$ = (Node *) n;
1474 : : }
1475 : : | DROP USER role_list
1476 : : {
7426 tgl@sss.pgh.pa.us 1477 : 203 : DropRoleStmt *n = makeNode(DropRoleStmt);
1478 : :
2994 peter_e@gmx.net 1479 : 203 : n->missing_ok = false;
7426 tgl@sss.pgh.pa.us 1480 : 203 : n->roles = $3;
1263 peter@eisentraut.org 1481 : 203 : $$ = (Node *) n;
1482 : : }
1483 : : | DROP USER IF_P EXISTS role_list
1484 : : {
7205 andrew@dunslane.net 1485 : 18 : DropRoleStmt *n = makeNode(DropRoleStmt);
1486 : :
1487 : 18 : n->roles = $5;
2994 peter_e@gmx.net 1488 : 18 : n->missing_ok = true;
1263 peter@eisentraut.org 1489 : 18 : $$ = (Node *) n;
1490 : : }
1491 : : | DROP GROUP_P role_list
1492 : : {
3010 peter_e@gmx.net 1493 : 18 : DropRoleStmt *n = makeNode(DropRoleStmt);
1494 : :
2994 1495 : 18 : n->missing_ok = false;
3010 1496 : 18 : n->roles = $3;
1263 peter@eisentraut.org 1497 : 18 : $$ = (Node *) n;
1498 : : }
1499 : : | DROP GROUP_P IF_P EXISTS role_list
1500 : : {
3010 peter_e@gmx.net 1501 : 3 : DropRoleStmt *n = makeNode(DropRoleStmt);
1502 : :
2994 1503 : 3 : n->missing_ok = true;
3010 1504 : 3 : n->roles = $5;
1263 peter@eisentraut.org 1505 : 3 : $$ = (Node *) n;
1506 : : }
1507 : : ;
1508 : :
1509 : :
1510 : : /*****************************************************************************
1511 : : *
1512 : : * Create a postgresql group (role without login ability)
1513 : : *
1514 : : *****************************************************************************/
1515 : :
1516 : : CreateGroupStmt:
1517 : : CREATE GROUP_P RoleId opt_with OptRoleList
1518 : : {
7426 tgl@sss.pgh.pa.us 1519 : 12 : CreateRoleStmt *n = makeNode(CreateRoleStmt);
1520 : :
7398 1521 : 12 : n->stmt_type = ROLESTMT_GROUP;
7426 1522 : 12 : n->role = $3;
8873 1523 : 12 : n->options = $5;
1263 peter@eisentraut.org 1524 : 12 : $$ = (Node *) n;
1525 : : }
1526 : : ;
1527 : :
1528 : :
1529 : : /*****************************************************************************
1530 : : *
1531 : : * Alter a postgresql group
1532 : : *
1533 : : *****************************************************************************/
1534 : :
1535 : : AlterGroupStmt:
1536 : : ALTER GROUP_P RoleSpec add_drop USER role_list
1537 : : {
7426 tgl@sss.pgh.pa.us 1538 : 21 : AlterRoleStmt *n = makeNode(AlterRoleStmt);
1539 : :
1540 : 21 : n->role = $3;
8533 bruce@momjian.us 1541 : 21 : n->action = $4;
7426 tgl@sss.pgh.pa.us 1542 : 21 : n->options = list_make1(makeDefElem("rolemembers",
1543 : : (Node *) $6, @6));
1263 peter@eisentraut.org 1544 : 21 : $$ = (Node *) n;
1545 : : }
1546 : : ;
1547 : :
6852 tgl@sss.pgh.pa.us 1548 : 47 : add_drop: ADD_P { $$ = +1; }
7426 1549 : 113 : | DROP { $$ = -1; }
1550 : : ;
1551 : :
1552 : :
1553 : : /*****************************************************************************
1554 : : *
1555 : : * Manipulate a schema
1556 : : *
1557 : : *****************************************************************************/
1558 : :
1559 : : CreateSchemaStmt:
1560 : : CREATE SCHEMA opt_single_name AUTHORIZATION RoleSpec OptSchemaEltList
1561 : : {
8621 1562 : 79 : CreateSchemaStmt *n = makeNode(CreateSchemaStmt);
1563 : :
1564 : : /* One can omit the schema name or the authorization id. */
3885 alvherre@alvh.no-ip. 1565 : 79 : n->schemaname = $3;
1566 : 79 : n->authrole = $5;
7661 tgl@sss.pgh.pa.us 1567 : 79 : n->schemaElts = $6;
4772 1568 : 79 : n->if_not_exists = false;
1263 peter@eisentraut.org 1569 : 79 : $$ = (Node *) n;
1570 : : }
1571 : : | CREATE SCHEMA ColId OptSchemaEltList
1572 : : {
8621 tgl@sss.pgh.pa.us 1573 : 429 : CreateSchemaStmt *n = makeNode(CreateSchemaStmt);
1574 : :
1575 : : /* ...but not both */
1576 : 429 : n->schemaname = $3;
3885 alvherre@alvh.no-ip. 1577 : 429 : n->authrole = NULL;
7661 tgl@sss.pgh.pa.us 1578 : 429 : n->schemaElts = $4;
4772 1579 : 429 : n->if_not_exists = false;
1263 peter@eisentraut.org 1580 : 429 : $$ = (Node *) n;
1581 : : }
1582 : : | CREATE SCHEMA IF_P NOT EXISTS opt_single_name AUTHORIZATION RoleSpec OptSchemaEltList
1583 : : {
4772 tgl@sss.pgh.pa.us 1584 : 9 : CreateSchemaStmt *n = makeNode(CreateSchemaStmt);
1585 : :
1586 : : /* schema name can be omitted here, too */
3885 alvherre@alvh.no-ip. 1587 : 9 : n->schemaname = $6;
1588 : 9 : n->authrole = $8;
4772 tgl@sss.pgh.pa.us 1589 [ - + ]: 9 : if ($9 != NIL)
4772 tgl@sss.pgh.pa.us 1590 [ # # ]:UBC 0 : ereport(ERROR,
1591 : : (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
1592 : : errmsg("CREATE SCHEMA IF NOT EXISTS cannot include schema elements"),
1593 : : parser_errposition(@9)));
4772 tgl@sss.pgh.pa.us 1594 :CBC 9 : n->schemaElts = $9;
1595 : 9 : n->if_not_exists = true;
1263 peter@eisentraut.org 1596 : 9 : $$ = (Node *) n;
1597 : : }
1598 : : | CREATE SCHEMA IF_P NOT EXISTS ColId OptSchemaEltList
1599 : : {
4772 tgl@sss.pgh.pa.us 1600 : 17 : CreateSchemaStmt *n = makeNode(CreateSchemaStmt);
1601 : :
1602 : : /* ...but not here */
1603 : 17 : n->schemaname = $6;
3885 alvherre@alvh.no-ip. 1604 : 17 : n->authrole = NULL;
4772 tgl@sss.pgh.pa.us 1605 [ + + ]: 17 : if ($7 != NIL)
1606 [ + - ]: 3 : ereport(ERROR,
1607 : : (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
1608 : : errmsg("CREATE SCHEMA IF NOT EXISTS cannot include schema elements"),
1609 : : parser_errposition(@7)));
1610 : 14 : n->schemaElts = $7;
1611 : 14 : n->if_not_exists = true;
1263 peter@eisentraut.org 1612 : 14 : $$ = (Node *) n;
1613 : : }
1614 : : ;
1615 : :
1616 : : OptSchemaEltList:
1617 : : OptSchemaEltList schema_stmt
1618 : : {
4771 tgl@sss.pgh.pa.us 1619 : 282 : $$ = lappend($1, $2);
1620 : : }
1621 : : | /* EMPTY */
1622 : 534 : { $$ = NIL; }
1623 : : ;
1624 : :
1625 : : /*
1626 : : * schema_stmt are the ones that can show up inside a CREATE SCHEMA
1627 : : * statement (in addition to by themselves).
1628 : : */
1629 : : schema_stmt:
1630 : : CreateStmt
1631 : : | IndexStmt
1632 : : | CreateSeqStmt
1633 : : | CreateTrigStmt
1634 : : | GrantStmt
1635 : : | ViewStmt
1636 : : ;
1637 : :
1638 : :
1639 : : /*****************************************************************************
1640 : : *
1641 : : * Set PG internal variable
1642 : : * SET name TO 'var_value'
1643 : : * Include SQL syntax (thomas 1997-10-22):
1644 : : * SET TIME ZONE 'var_value'
1645 : : *
1646 : : *****************************************************************************/
1647 : :
1648 : : VariableSetStmt:
1649 : : SET set_rest
1650 : : {
8564 1651 : 11004 : VariableSetStmt *n = $2;
1652 : :
1653 : 11004 : n->is_local = false;
10276 bruce@momjian.us 1654 : 11004 : $$ = (Node *) n;
1655 : : }
1656 : : | SET LOCAL set_rest
1657 : : {
8564 tgl@sss.pgh.pa.us 1658 : 622 : VariableSetStmt *n = $3;
1659 : :
1660 : 622 : n->is_local = true;
10276 bruce@momjian.us 1661 : 622 : $$ = (Node *) n;
1662 : : }
1663 : : | SET SESSION set_rest
1664 : : {
8564 tgl@sss.pgh.pa.us 1665 : 42 : VariableSetStmt *n = $3;
1666 : :
1667 : 42 : n->is_local = false;
10276 bruce@momjian.us 1668 : 42 : $$ = (Node *) n;
1669 : : }
1670 : : ;
1671 : :
1672 : : set_rest:
1673 : : TRANSACTION transaction_mode_list
1674 : : {
5003 rhaas@postgresql.org 1675 : 298 : VariableSetStmt *n = makeNode(VariableSetStmt);
1676 : :
1677 : 298 : n->kind = VAR_SET_MULTI;
1678 : 298 : n->name = "TRANSACTION";
1679 : 298 : n->args = $2;
392 michael@paquier.xyz 1680 : 298 : n->jumble_args = true;
1681 : 298 : n->location = -1;
5003 rhaas@postgresql.org 1682 : 298 : $$ = n;
1683 : : }
1684 : : | SESSION CHARACTERISTICS AS TRANSACTION transaction_mode_list
1685 : : {
1686 : 9 : VariableSetStmt *n = makeNode(VariableSetStmt);
1687 : :
1688 : 9 : n->kind = VAR_SET_MULTI;
1689 : 9 : n->name = "SESSION CHARACTERISTICS";
1690 : 9 : n->args = $5;
392 michael@paquier.xyz 1691 : 9 : n->jumble_args = true;
1692 : 9 : n->location = -1;
5003 rhaas@postgresql.org 1693 : 9 : $$ = n;
1694 : : }
1695 : : | set_rest_more
1696 : : ;
1697 : :
1698 : : generic_set:
1699 : : var_name TO var_list
1700 : : {
9810 vadim4o@yahoo.com 1701 : 2561 : VariableSetStmt *n = makeNode(VariableSetStmt);
1702 : :
6629 tgl@sss.pgh.pa.us 1703 : 2561 : n->kind = VAR_SET_VALUE;
8564 1704 : 2561 : n->name = $1;
1705 : 2561 : n->args = $3;
392 michael@paquier.xyz 1706 : 2561 : n->location = @3;
8564 tgl@sss.pgh.pa.us 1707 : 2561 : $$ = n;
1708 : : }
1709 : : | var_name '=' var_list
1710 : : {
9103 peter_e@gmx.net 1711 : 7599 : VariableSetStmt *n = makeNode(VariableSetStmt);
1712 : :
6629 tgl@sss.pgh.pa.us 1713 : 7599 : n->kind = VAR_SET_VALUE;
8564 1714 : 7599 : n->name = $1;
1715 : 7599 : n->args = $3;
392 michael@paquier.xyz 1716 : 7599 : n->location = @3;
1053 akorotkov@postgresql 1717 : 7599 : $$ = n;
1718 : : }
1719 : : | var_name TO DEFAULT
1720 : : {
6629 tgl@sss.pgh.pa.us 1721 : 68 : VariableSetStmt *n = makeNode(VariableSetStmt);
1722 : :
1723 : 68 : n->kind = VAR_SET_DEFAULT;
1724 : 68 : n->name = $1;
392 michael@paquier.xyz 1725 : 68 : n->location = -1;
6629 tgl@sss.pgh.pa.us 1726 : 68 : $$ = n;
1727 : : }
1728 : : | var_name '=' DEFAULT
1729 : : {
1730 : 5 : VariableSetStmt *n = makeNode(VariableSetStmt);
1731 : :
1732 : 5 : n->kind = VAR_SET_DEFAULT;
1733 : 5 : n->name = $1;
392 michael@paquier.xyz 1734 : 5 : n->location = -1;
6629 tgl@sss.pgh.pa.us 1735 : 5 : $$ = n;
1736 : : }
1737 : : ;
1738 : :
1739 : : set_rest_more: /* Generic SET syntaxes: */
1811 peter@eisentraut.org 1740 : 10160 : generic_set {$$ = $1;}
1741 : : | var_name FROM CURRENT_P
1742 : : {
6629 tgl@sss.pgh.pa.us 1743 : 2 : VariableSetStmt *n = makeNode(VariableSetStmt);
1744 : :
1745 : 2 : n->kind = VAR_SET_CURRENT;
1746 : 2 : n->name = $1;
392 michael@paquier.xyz 1747 : 2 : n->location = -1;
6629 tgl@sss.pgh.pa.us 1748 : 2 : $$ = n;
1749 : : }
1750 : : /* Special syntaxes mandated by SQL standard: */
1751 : : | TIME ZONE zone_value
1752 : : {
9957 scrappy@hub.org 1753 : 51 : VariableSetStmt *n = makeNode(VariableSetStmt);
1754 : :
6629 tgl@sss.pgh.pa.us 1755 : 51 : n->kind = VAR_SET_VALUE;
8564 1756 : 51 : n->name = "timezone";
392 michael@paquier.xyz 1757 : 51 : n->location = -1;
1758 : 51 : n->jumble_args = true;
8633 lockhart@fourpalms.o 1759 [ + + ]: 51 : if ($3 != NULL)
7820 neilc@samurai.com 1760 : 43 : n->args = list_make1($3);
1761 : : else
6629 tgl@sss.pgh.pa.us 1762 : 8 : n->kind = VAR_SET_DEFAULT;
8564 1763 : 51 : $$ = n;
1764 : : }
1765 : : | CATALOG_P Sconst
1766 : : {
6209 peter_e@gmx.net 1767 [ # # ]:UBC 0 : ereport(ERROR,
1768 : : (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
1769 : : errmsg("current database cannot be changed"),
1770 : : parser_errposition(@2)));
1771 : : $$ = NULL; /*not reached*/
1772 : : }
1773 : : | SCHEMA Sconst
1774 : : {
6209 peter_e@gmx.net 1775 :CBC 2 : VariableSetStmt *n = makeNode(VariableSetStmt);
1776 : :
1777 : 2 : n->kind = VAR_SET_VALUE;
1778 : 2 : n->name = "search_path";
1779 : 2 : n->args = list_make1(makeStringConst($2, @2));
392 michael@paquier.xyz 1780 : 2 : n->location = @2;
6209 peter_e@gmx.net 1781 : 2 : $$ = n;
1782 : : }
1783 : : | NAMES opt_encoding
1784 : : {
8564 tgl@sss.pgh.pa.us 1785 :UBC 0 : VariableSetStmt *n = makeNode(VariableSetStmt);
1786 : :
6629 1787 : 0 : n->kind = VAR_SET_VALUE;
8564 1788 : 0 : n->name = "client_encoding";
392 michael@paquier.xyz 1789 : 0 : n->location = @2;
8564 tgl@sss.pgh.pa.us 1790 [ # # ]: 0 : if ($2 != NULL)
6269 1791 : 0 : n->args = list_make1(makeStringConst($2, @2));
1792 : : else
6629 1793 : 0 : n->kind = VAR_SET_DEFAULT;
8564 1794 : 0 : $$ = n;
1795 : : }
1796 : : | ROLE NonReservedWord_or_Sconst
1797 : : {
7399 tgl@sss.pgh.pa.us 1798 :CBC 481 : VariableSetStmt *n = makeNode(VariableSetStmt);
1799 : :
6629 1800 : 481 : n->kind = VAR_SET_VALUE;
7399 1801 : 481 : n->name = "role";
6269 1802 : 481 : n->args = list_make1(makeStringConst($2, @2));
392 michael@paquier.xyz 1803 : 481 : n->location = @2;
7399 tgl@sss.pgh.pa.us 1804 : 481 : $$ = n;
1805 : : }
1806 : : | SESSION AUTHORIZATION NonReservedWord_or_Sconst
1807 : : {
8564 1808 : 1293 : VariableSetStmt *n = makeNode(VariableSetStmt);
1809 : :
6629 1810 : 1293 : n->kind = VAR_SET_VALUE;
8564 1811 : 1293 : n->name = "session_authorization";
6269 1812 : 1293 : n->args = list_make1(makeStringConst($3, @3));
392 michael@paquier.xyz 1813 : 1293 : n->location = @3;
8564 tgl@sss.pgh.pa.us 1814 : 1293 : $$ = n;
1815 : : }
1816 : : | SESSION AUTHORIZATION DEFAULT
1817 : : {
8575 1818 : 2 : VariableSetStmt *n = makeNode(VariableSetStmt);
1819 : :
6629 1820 : 2 : n->kind = VAR_SET_DEFAULT;
8575 1821 : 2 : n->name = "session_authorization";
392 michael@paquier.xyz 1822 : 2 : n->location = -1;
8564 tgl@sss.pgh.pa.us 1823 : 2 : $$ = n;
1824 : : }
1825 : : | XML_P OPTION document_or_content
1826 : : {
6850 peter_e@gmx.net 1827 : 8 : VariableSetStmt *n = makeNode(VariableSetStmt);
1828 : :
6629 tgl@sss.pgh.pa.us 1829 : 8 : n->kind = VAR_SET_VALUE;
6850 peter_e@gmx.net 1830 : 8 : n->name = "xmloption";
6269 tgl@sss.pgh.pa.us 1831 [ + + ]: 8 : n->args = list_make1(makeStringConst($3 == XMLOPTION_DOCUMENT ? "DOCUMENT" : "CONTENT", @3));
392 michael@paquier.xyz 1832 : 8 : n->jumble_args = true;
1833 : 8 : n->location = -1;
6850 peter_e@gmx.net 1834 : 8 : $$ = n;
1835 : : }
1836 : : /* Special syntaxes invented by PostgreSQL: */
1837 : : | TRANSACTION SNAPSHOT Sconst
1838 : : {
5119 tgl@sss.pgh.pa.us 1839 : 24 : VariableSetStmt *n = makeNode(VariableSetStmt);
1840 : :
1841 : 24 : n->kind = VAR_SET_MULTI;
1842 : 24 : n->name = "TRANSACTION SNAPSHOT";
1843 : 24 : n->args = list_make1(makeStringConst($3, @3));
392 michael@paquier.xyz 1844 : 24 : n->location = @3;
5119 tgl@sss.pgh.pa.us 1845 : 24 : $$ = n;
1846 : : }
1847 : : ;
1848 : :
6629 1849 : 12656 : var_name: ColId { $$ = $1; }
1850 : : | var_name '.' ColId
4397 peter_e@gmx.net 1851 : 255 : { $$ = psprintf("%s.%s", $1, $3); }
1852 : : ;
1853 : :
7820 neilc@samurai.com 1854 : 10160 : var_list: var_value { $$ = list_make1($1); }
8533 bruce@momjian.us 1855 : 91 : | var_list ',' var_value { $$ = lappend($1, $3); }
1856 : : ;
1857 : :
1858 : : var_value: opt_boolean_or_string
6269 tgl@sss.pgh.pa.us 1859 : 7531 : { $$ = makeStringConst($1, @1); }
1860 : : | NumericOnly
1861 : 2720 : { $$ = makeAConst($1, @1); }
1862 : : ;
1863 : :
8026 peter_e@gmx.net 1864 :UBC 0 : iso_level: READ UNCOMMITTED { $$ = "read uncommitted"; }
8026 peter_e@gmx.net 1865 :CBC 501 : | READ COMMITTED { $$ = "read committed"; }
1866 : 1331 : | REPEATABLE READ { $$ = "repeatable read"; }
8533 bruce@momjian.us 1867 : 1614 : | SERIALIZABLE { $$ = "serializable"; }
1868 : : ;
1869 : :
1870 : : opt_boolean_or_string:
1871 : 354 : TRUE_P { $$ = "true"; }
1872 : 746 : | FALSE_P { $$ = "false"; }
1873 : 1138 : | ON { $$ = "on"; }
1874 : : /*
1875 : : * OFF is also accepted as a boolean value, but is handled by
1876 : : * the NonReservedWord rule. The action for booleans and strings
1877 : : * is the same, so we don't need to distinguish them here.
1878 : : */
4530 tgl@sss.pgh.pa.us 1879 : 15453 : | NonReservedWord_or_Sconst { $$ = $1; }
1880 : : ;
1881 : :
1882 : : /* Timezone values can be:
1883 : : * - a string such as 'pst8pdt'
1884 : : * - an identifier such as "pst8pdt"
1885 : : * - an integer or floating point number
1886 : : * - a time interval per SQL99
1887 : : * ColId gives reduce/reduce errors against ConstInterval and LOCAL,
1888 : : * so use IDENT (meaning we reject anything that is a key word).
1889 : : */
1890 : : zone_value:
1891 : : Sconst
1892 : : {
6269 1893 : 30 : $$ = makeStringConst($1, @1);
1894 : : }
1895 : : | IDENT
1896 : : {
1897 : 1 : $$ = makeStringConst($1, @1);
1898 : : }
1899 : : | ConstInterval Sconst opt_interval
1900 : : {
1263 peter@eisentraut.org 1901 :UBC 0 : TypeName *t = $1;
1902 : :
6255 tgl@sss.pgh.pa.us 1903 [ # # ]: 0 : if ($3 != NIL)
1904 : : {
1263 peter@eisentraut.org 1905 : 0 : A_Const *n = (A_Const *) linitial($3);
1906 : :
1382 1907 [ # # ]: 0 : if ((n->val.ival.ival & ~(INTERVAL_MASK(HOUR) | INTERVAL_MASK(MINUTE))) != 0)
8136 tgl@sss.pgh.pa.us 1908 [ # # ]: 0 : ereport(ERROR,
1909 : : (errcode(ERRCODE_SYNTAX_ERROR),
1910 : : errmsg("time zone interval must be HOUR or HOUR TO MINUTE"),
1911 : : parser_errposition(@3)));
1912 : : }
6255 1913 : 0 : t->typmods = $3;
6269 1914 : 0 : $$ = makeStringConstCast($2, @2, t);
1915 : : }
1916 : : | ConstInterval '(' Iconst ')' Sconst
1917 : : {
1263 peter@eisentraut.org 1918 : 0 : TypeName *t = $1;
1919 : :
4027 bruce@momjian.us 1920 : 0 : t->typmods = list_make2(makeIntConst(INTERVAL_FULL_RANGE, -1),
1921 : : makeIntConst($3, @3));
6269 tgl@sss.pgh.pa.us 1922 : 0 : $$ = makeStringConstCast($5, @5, t);
1923 : : }
6269 tgl@sss.pgh.pa.us 1924 :CBC 12 : | NumericOnly { $$ = makeAConst($1, @1); }
8533 bruce@momjian.us 1925 : 7 : | DEFAULT { $$ = NULL; }
1926 : 1 : | LOCAL { $$ = NULL; }
1927 : : ;
1928 : :
1929 : : opt_encoding:
8533 bruce@momjian.us 1930 :UBC 0 : Sconst { $$ = $1; }
1931 : 0 : | DEFAULT { $$ = NULL; }
1932 : 0 : | /*EMPTY*/ { $$ = NULL; }
1933 : : ;
1934 : :
1935 : : NonReservedWord_or_Sconst:
4530 tgl@sss.pgh.pa.us 1936 :CBC 27039 : NonReservedWord { $$ = $1; }
6193 meskes@postgresql.or 1937 : 2776 : | Sconst { $$ = $1; }
1938 : : ;
1939 : :
1940 : : VariableResetStmt:
4073 fujii@postgresql.org 1941 : 2378 : RESET reset_rest { $$ = (Node *) $2; }
1942 : : ;
1943 : :
1944 : : reset_rest:
1945 : 1976 : generic_reset { $$ = $1; }
1946 : : | TIME ZONE
1947 : : {
6629 tgl@sss.pgh.pa.us 1948 : 7 : VariableSetStmt *n = makeNode(VariableSetStmt);
1949 : :
1950 : 7 : n->kind = VAR_RESET;
4073 fujii@postgresql.org 1951 : 7 : n->name = "timezone";
392 michael@paquier.xyz 1952 : 7 : n->location = -1;
4073 fujii@postgresql.org 1953 : 7 : $$ = n;
1954 : : }
1955 : : | TRANSACTION ISOLATION LEVEL
1956 : : {
6629 tgl@sss.pgh.pa.us 1957 :UBC 0 : VariableSetStmt *n = makeNode(VariableSetStmt);
1958 : :
1959 : 0 : n->kind = VAR_RESET;
4073 fujii@postgresql.org 1960 : 0 : n->name = "transaction_isolation";
392 michael@paquier.xyz 1961 : 0 : n->location = -1;
4073 fujii@postgresql.org 1962 : 0 : $$ = n;
1963 : : }
1964 : : | SESSION AUTHORIZATION
1965 : : {
6629 tgl@sss.pgh.pa.us 1966 :CBC 395 : VariableSetStmt *n = makeNode(VariableSetStmt);
1967 : :
1968 : 395 : n->kind = VAR_RESET;
4073 fujii@postgresql.org 1969 : 395 : n->name = "session_authorization";
392 michael@paquier.xyz 1970 : 395 : n->location = -1;
4073 fujii@postgresql.org 1971 : 395 : $$ = n;
1972 : : }
1973 : : ;
1974 : :
1975 : : generic_reset:
1976 : : var_name
1977 : : {
6629 tgl@sss.pgh.pa.us 1978 : 1993 : VariableSetStmt *n = makeNode(VariableSetStmt);
1979 : :
1980 : 1993 : n->kind = VAR_RESET;
4073 fujii@postgresql.org 1981 : 1993 : n->name = $1;
392 michael@paquier.xyz 1982 : 1993 : n->location = -1;
4073 fujii@postgresql.org 1983 : 1993 : $$ = n;
1984 : : }
1985 : : | ALL
1986 : : {
6629 tgl@sss.pgh.pa.us 1987 : 14 : VariableSetStmt *n = makeNode(VariableSetStmt);
1988 : :
1989 : 14 : n->kind = VAR_RESET_ALL;
392 michael@paquier.xyz 1990 : 14 : n->location = -1;
4073 fujii@postgresql.org 1991 : 14 : $$ = n;
1992 : : }
1993 : : ;
1994 : :
1995 : : /* SetResetClause allows SET or RESET without LOCAL */
1996 : : SetResetClause:
6629 tgl@sss.pgh.pa.us 1997 : 605 : SET set_rest { $$ = $2; }
1998 : 21 : | VariableResetStmt { $$ = (VariableSetStmt *) $1; }
1999 : : ;
2000 : :
2001 : : /* SetResetClause allows SET or RESET without LOCAL */
2002 : : FunctionSetResetClause:
5003 rhaas@postgresql.org 2003 : 57 : SET set_rest_more { $$ = $2; }
2004 : 6 : | VariableResetStmt { $$ = (VariableSetStmt *) $1; }
2005 : : ;
2006 : :
2007 : :
2008 : : VariableShowStmt:
2009 : : SHOW var_name
2010 : : {
6629 tgl@sss.pgh.pa.us 2011 : 428 : VariableShowStmt *n = makeNode(VariableShowStmt);
2012 : :
8564 2013 : 428 : n->name = $2;
10276 bruce@momjian.us 2014 : 428 : $$ = (Node *) n;
2015 : : }
2016 : : | SHOW TIME ZONE
2017 : : {
6629 tgl@sss.pgh.pa.us 2018 : 4 : VariableShowStmt *n = makeNode(VariableShowStmt);
2019 : :
8564 2020 : 4 : n->name = "timezone";
10224 lockhart@fourpalms.o 2021 : 4 : $$ = (Node *) n;
2022 : : }
2023 : : | SHOW TRANSACTION ISOLATION LEVEL
2024 : : {
6629 tgl@sss.pgh.pa.us 2025 : 1 : VariableShowStmt *n = makeNode(VariableShowStmt);
2026 : :
8326 peter_e@gmx.net 2027 : 1 : n->name = "transaction_isolation";
9810 vadim4o@yahoo.com 2028 : 1 : $$ = (Node *) n;
2029 : : }
2030 : : | SHOW SESSION AUTHORIZATION
2031 : : {
6629 tgl@sss.pgh.pa.us 2032 :UBC 0 : VariableShowStmt *n = makeNode(VariableShowStmt);
2033 : :
8575 2034 : 0 : n->name = "session_authorization";
2035 : 0 : $$ = (Node *) n;
2036 : : }
2037 : : | SHOW ALL
2038 : : {
6629 2039 : 0 : VariableShowStmt *n = makeNode(VariableShowStmt);
2040 : :
8564 2041 : 0 : n->name = "all";
8908 bruce@momjian.us 2042 : 0 : $$ = (Node *) n;
2043 : : }
2044 : : ;
2045 : :
2046 : :
2047 : : ConstraintsSetStmt:
2048 : : SET CONSTRAINTS constraints_set_list constraints_set_mode
2049 : : {
9525 JanWieck@Yahoo.com 2050 :CBC 52 : ConstraintsSetStmt *n = makeNode(ConstraintsSetStmt);
2051 : :
2052 : 52 : n->constraints = $3;
5109 peter_e@gmx.net 2053 : 52 : n->deferred = $4;
9525 JanWieck@Yahoo.com 2054 : 52 : $$ = (Node *) n;
2055 : : }
2056 : : ;
2057 : :
2058 : : constraints_set_list:
8533 bruce@momjian.us 2059 : 28 : ALL { $$ = NIL; }
7123 2060 : 24 : | qualified_name_list { $$ = $1; }
2061 : : ;
2062 : :
2063 : : constraints_set_mode:
2994 peter_e@gmx.net 2064 : 34 : DEFERRED { $$ = true; }
2065 : 18 : | IMMEDIATE { $$ = false; }
2066 : : ;
2067 : :
2068 : :
2069 : : /*
2070 : : * Checkpoint statement
2071 : : */
2072 : : CheckPointStmt:
2073 : : CHECKPOINT opt_utility_option_list
2074 : : {
9122 vadim4o@yahoo.com 2075 : 126 : CheckPointStmt *n = makeNode(CheckPointStmt);
2076 : :
1263 peter@eisentraut.org 2077 : 126 : $$ = (Node *) n;
94 alvherre@kurilemu.de 2078 :GNC 126 : n->options = $2;
2079 : : }
2080 : : ;
2081 : :
2082 : :
2083 : : /*****************************************************************************
2084 : : *
2085 : : * DISCARD { ALL | TEMP | PLANS | SEQUENCES }
2086 : : *
2087 : : *****************************************************************************/
2088 : :
2089 : : DiscardStmt:
2090 : : DISCARD ALL
2091 : : {
6759 neilc@samurai.com 2092 :CBC 3 : DiscardStmt *n = makeNode(DiscardStmt);
2093 : :
2094 : 3 : n->target = DISCARD_ALL;
2095 : 3 : $$ = (Node *) n;
2096 : : }
2097 : : | DISCARD TEMP
2098 : : {
2099 : 4 : DiscardStmt *n = makeNode(DiscardStmt);
2100 : :
2101 : 4 : n->target = DISCARD_TEMP;
2102 : 4 : $$ = (Node *) n;
2103 : : }
2104 : : | DISCARD TEMPORARY
2105 : : {
6759 neilc@samurai.com 2106 :UBC 0 : DiscardStmt *n = makeNode(DiscardStmt);
2107 : :
2108 : 0 : n->target = DISCARD_TEMP;
2109 : 0 : $$ = (Node *) n;
2110 : : }
2111 : : | DISCARD PLANS
2112 : : {
6759 neilc@samurai.com 2113 :CBC 2 : DiscardStmt *n = makeNode(DiscardStmt);
2114 : :
2115 : 2 : n->target = DISCARD_PLANS;
2116 : 2 : $$ = (Node *) n;
2117 : : }
2118 : : | DISCARD SEQUENCES
2119 : : {
4407 rhaas@postgresql.org 2120 : 6 : DiscardStmt *n = makeNode(DiscardStmt);
2121 : :
2122 : 6 : n->target = DISCARD_SEQUENCES;
2123 : 6 : $$ = (Node *) n;
2124 : : }
2125 : :
2126 : : ;
2127 : :
2128 : :
2129 : : /*****************************************************************************
2130 : : *
2131 : : * ALTER [ TABLE | INDEX | SEQUENCE | VIEW | MATERIALIZED VIEW | FOREIGN TABLE ] variations
2132 : : *
2133 : : * Note: we accept all subcommands for each of the variants, and sort
2134 : : * out what's really legal at execution time.
2135 : : *****************************************************************************/
2136 : :
2137 : : AlterTableStmt:
2138 : : ALTER TABLE relation_expr alter_table_cmds
2139 : : {
9386 lockhart@fourpalms.o 2140 : 13207 : AlterTableStmt *n = makeNode(AlterTableStmt);
2141 : :
8621 tgl@sss.pgh.pa.us 2142 : 13207 : n->relation = $3;
7845 2143 : 13207 : n->cmds = $4;
1934 michael@paquier.xyz 2144 : 13207 : n->objtype = OBJECT_TABLE;
5026 simon@2ndQuadrant.co 2145 : 13207 : n->missing_ok = false;
1263 peter@eisentraut.org 2146 : 13207 : $$ = (Node *) n;
2147 : : }
2148 : : | ALTER TABLE IF_P EXISTS relation_expr alter_table_cmds
2149 : : {
5026 simon@2ndQuadrant.co 2150 : 27 : AlterTableStmt *n = makeNode(AlterTableStmt);
2151 : :
2152 : 27 : n->relation = $5;
2153 : 27 : n->cmds = $6;
1934 michael@paquier.xyz 2154 : 27 : n->objtype = OBJECT_TABLE;
5026 simon@2ndQuadrant.co 2155 : 27 : n->missing_ok = true;
1263 peter@eisentraut.org 2156 : 27 : $$ = (Node *) n;
2157 : : }
2158 : : | ALTER TABLE relation_expr partition_cmd
2159 : : {
3246 rhaas@postgresql.org 2160 : 1532 : AlterTableStmt *n = makeNode(AlterTableStmt);
2161 : :
2162 : 1532 : n->relation = $3;
2163 : 1532 : n->cmds = list_make1($4);
1934 michael@paquier.xyz 2164 : 1532 : n->objtype = OBJECT_TABLE;
3246 rhaas@postgresql.org 2165 : 1532 : n->missing_ok = false;
1263 peter@eisentraut.org 2166 : 1532 : $$ = (Node *) n;
2167 : : }
2168 : : | ALTER TABLE IF_P EXISTS relation_expr partition_cmd
2169 : : {
3246 rhaas@postgresql.org 2170 :UBC 0 : AlterTableStmt *n = makeNode(AlterTableStmt);
2171 : :
2172 : 0 : n->relation = $5;
2173 : 0 : n->cmds = list_make1($6);
1934 michael@paquier.xyz 2174 : 0 : n->objtype = OBJECT_TABLE;
3246 rhaas@postgresql.org 2175 : 0 : n->missing_ok = true;
1263 peter@eisentraut.org 2176 : 0 : $$ = (Node *) n;
2177 : : }
2178 : : | ALTER TABLE ALL IN_P TABLESPACE name SET TABLESPACE name opt_nowait
2179 : : {
2180 : : AlterTableMoveAllStmt *n =
4085 sfrost@snowman.net 2181 :CBC 6 : makeNode(AlterTableMoveAllStmt);
2182 : :
2183 : 6 : n->orig_tablespacename = $6;
2184 : 6 : n->objtype = OBJECT_TABLE;
2185 : 6 : n->roles = NIL;
2186 : 6 : n->new_tablespacename = $9;
2187 : 6 : n->nowait = $10;
1263 peter@eisentraut.org 2188 : 6 : $$ = (Node *) n;
2189 : : }
2190 : : | ALTER TABLE ALL IN_P TABLESPACE name OWNED BY role_list SET TABLESPACE name opt_nowait
2191 : : {
2192 : : AlterTableMoveAllStmt *n =
4085 sfrost@snowman.net 2193 :UBC 0 : makeNode(AlterTableMoveAllStmt);
2194 : :
2195 : 0 : n->orig_tablespacename = $6;
2196 : 0 : n->objtype = OBJECT_TABLE;
2197 : 0 : n->roles = $9;
2198 : 0 : n->new_tablespacename = $12;
2199 : 0 : n->nowait = $13;
1263 peter@eisentraut.org 2200 : 0 : $$ = (Node *) n;
2201 : : }
2202 : : | ALTER INDEX qualified_name alter_table_cmds
2203 : : {
7738 bruce@momjian.us 2204 :CBC 114 : AlterTableStmt *n = makeNode(AlterTableStmt);
2205 : :
2206 : 114 : n->relation = $3;
2207 : 114 : n->cmds = $4;
1934 michael@paquier.xyz 2208 : 114 : n->objtype = OBJECT_INDEX;
5026 simon@2ndQuadrant.co 2209 : 114 : n->missing_ok = false;
1263 peter@eisentraut.org 2210 : 114 : $$ = (Node *) n;
2211 : : }
2212 : : | ALTER INDEX IF_P EXISTS qualified_name alter_table_cmds
2213 : : {
5026 simon@2ndQuadrant.co 2214 :UBC 0 : AlterTableStmt *n = makeNode(AlterTableStmt);
2215 : :
2216 : 0 : n->relation = $5;
2217 : 0 : n->cmds = $6;
1934 michael@paquier.xyz 2218 : 0 : n->objtype = OBJECT_INDEX;
5026 simon@2ndQuadrant.co 2219 : 0 : n->missing_ok = true;
1263 peter@eisentraut.org 2220 : 0 : $$ = (Node *) n;
2221 : : }
2222 : : | ALTER INDEX qualified_name index_partition_cmd
2223 : : {
2838 alvherre@alvh.no-ip. 2224 :CBC 199 : AlterTableStmt *n = makeNode(AlterTableStmt);
2225 : :
2226 : 199 : n->relation = $3;
2227 : 199 : n->cmds = list_make1($4);
1934 michael@paquier.xyz 2228 : 199 : n->objtype = OBJECT_INDEX;
2838 alvherre@alvh.no-ip. 2229 : 199 : n->missing_ok = false;
1263 peter@eisentraut.org 2230 : 199 : $$ = (Node *) n;
2231 : : }
2232 : : | ALTER INDEX ALL IN_P TABLESPACE name SET TABLESPACE name opt_nowait
2233 : : {
2234 : : AlterTableMoveAllStmt *n =
4085 sfrost@snowman.net 2235 : 3 : makeNode(AlterTableMoveAllStmt);
2236 : :
2237 : 3 : n->orig_tablespacename = $6;
2238 : 3 : n->objtype = OBJECT_INDEX;
2239 : 3 : n->roles = NIL;
2240 : 3 : n->new_tablespacename = $9;
2241 : 3 : n->nowait = $10;
1263 peter@eisentraut.org 2242 : 3 : $$ = (Node *) n;
2243 : : }
2244 : : | ALTER INDEX ALL IN_P TABLESPACE name OWNED BY role_list SET TABLESPACE name opt_nowait
2245 : : {
2246 : : AlterTableMoveAllStmt *n =
4085 sfrost@snowman.net 2247 :UBC 0 : makeNode(AlterTableMoveAllStmt);
2248 : :
2249 : 0 : n->orig_tablespacename = $6;
2250 : 0 : n->objtype = OBJECT_INDEX;
2251 : 0 : n->roles = $9;
2252 : 0 : n->new_tablespacename = $12;
2253 : 0 : n->nowait = $13;
1263 peter@eisentraut.org 2254 : 0 : $$ = (Node *) n;
2255 : : }
2256 : : | ALTER SEQUENCE qualified_name alter_table_cmds
2257 : : {
6343 tgl@sss.pgh.pa.us 2258 :CBC 47 : AlterTableStmt *n = makeNode(AlterTableStmt);
2259 : :
2260 : 47 : n->relation = $3;
2261 : 47 : n->cmds = $4;
1934 michael@paquier.xyz 2262 : 47 : n->objtype = OBJECT_SEQUENCE;
5026 simon@2ndQuadrant.co 2263 : 47 : n->missing_ok = false;
1263 peter@eisentraut.org 2264 : 47 : $$ = (Node *) n;
2265 : : }
2266 : : | ALTER SEQUENCE IF_P EXISTS qualified_name alter_table_cmds
2267 : : {
5026 simon@2ndQuadrant.co 2268 :UBC 0 : AlterTableStmt *n = makeNode(AlterTableStmt);
2269 : :
2270 : 0 : n->relation = $5;
2271 : 0 : n->cmds = $6;
1934 michael@paquier.xyz 2272 : 0 : n->objtype = OBJECT_SEQUENCE;
5026 simon@2ndQuadrant.co 2273 : 0 : n->missing_ok = true;
1263 peter@eisentraut.org 2274 : 0 : $$ = (Node *) n;
2275 : : }
2276 : : | ALTER VIEW qualified_name alter_table_cmds
2277 : : {
6343 tgl@sss.pgh.pa.us 2278 :CBC 127 : AlterTableStmt *n = makeNode(AlterTableStmt);
2279 : :
2280 : 127 : n->relation = $3;
2281 : 127 : n->cmds = $4;
1934 michael@paquier.xyz 2282 : 127 : n->objtype = OBJECT_VIEW;
5026 simon@2ndQuadrant.co 2283 : 127 : n->missing_ok = false;
1263 peter@eisentraut.org 2284 : 127 : $$ = (Node *) n;
2285 : : }
2286 : : | ALTER VIEW IF_P EXISTS qualified_name alter_table_cmds
2287 : : {
5026 simon@2ndQuadrant.co 2288 :UBC 0 : AlterTableStmt *n = makeNode(AlterTableStmt);
2289 : :
2290 : 0 : n->relation = $5;
2291 : 0 : n->cmds = $6;
1934 michael@paquier.xyz 2292 : 0 : n->objtype = OBJECT_VIEW;
5026 simon@2ndQuadrant.co 2293 : 0 : n->missing_ok = true;
1263 peter@eisentraut.org 2294 : 0 : $$ = (Node *) n;
2295 : : }
2296 : : | ALTER MATERIALIZED VIEW qualified_name alter_table_cmds
2297 : : {
4621 kgrittn@postgresql.o 2298 :CBC 24 : AlterTableStmt *n = makeNode(AlterTableStmt);
2299 : :
2300 : 24 : n->relation = $4;
2301 : 24 : n->cmds = $5;
1934 michael@paquier.xyz 2302 : 24 : n->objtype = OBJECT_MATVIEW;
4621 kgrittn@postgresql.o 2303 : 24 : n->missing_ok = false;
1263 peter@eisentraut.org 2304 : 24 : $$ = (Node *) n;
2305 : : }
2306 : : | ALTER MATERIALIZED VIEW IF_P EXISTS qualified_name alter_table_cmds
2307 : : {
4621 kgrittn@postgresql.o 2308 :UBC 0 : AlterTableStmt *n = makeNode(AlterTableStmt);
2309 : :
2310 : 0 : n->relation = $6;
2311 : 0 : n->cmds = $7;
1934 michael@paquier.xyz 2312 : 0 : n->objtype = OBJECT_MATVIEW;
4621 kgrittn@postgresql.o 2313 : 0 : n->missing_ok = true;
1263 peter@eisentraut.org 2314 : 0 : $$ = (Node *) n;
2315 : : }
2316 : : | ALTER MATERIALIZED VIEW ALL IN_P TABLESPACE name SET TABLESPACE name opt_nowait
2317 : : {
2318 : : AlterTableMoveAllStmt *n =
4085 sfrost@snowman.net 2319 :CBC 6 : makeNode(AlterTableMoveAllStmt);
2320 : :
2321 : 6 : n->orig_tablespacename = $7;
2322 : 6 : n->objtype = OBJECT_MATVIEW;
2323 : 6 : n->roles = NIL;
2324 : 6 : n->new_tablespacename = $10;
2325 : 6 : n->nowait = $11;
1263 peter@eisentraut.org 2326 : 6 : $$ = (Node *) n;
2327 : : }
2328 : : | ALTER MATERIALIZED VIEW ALL IN_P TABLESPACE name OWNED BY role_list SET TABLESPACE name opt_nowait
2329 : : {
2330 : : AlterTableMoveAllStmt *n =
4085 sfrost@snowman.net 2331 :UBC 0 : makeNode(AlterTableMoveAllStmt);
2332 : :
2333 : 0 : n->orig_tablespacename = $7;
2334 : 0 : n->objtype = OBJECT_MATVIEW;
2335 : 0 : n->roles = $10;
2336 : 0 : n->new_tablespacename = $13;
2337 : 0 : n->nowait = $14;
1263 peter@eisentraut.org 2338 : 0 : $$ = (Node *) n;
2339 : : }
2340 : : | ALTER FOREIGN TABLE relation_expr alter_table_cmds
2341 : : {
1964 peter@eisentraut.org 2342 :CBC 189 : AlterTableStmt *n = makeNode(AlterTableStmt);
2343 : :
2344 : 189 : n->relation = $4;
2345 : 189 : n->cmds = $5;
1934 michael@paquier.xyz 2346 : 189 : n->objtype = OBJECT_FOREIGN_TABLE;
1964 peter@eisentraut.org 2347 : 189 : n->missing_ok = false;
1263 2348 : 189 : $$ = (Node *) n;
2349 : : }
2350 : : | ALTER FOREIGN TABLE IF_P EXISTS relation_expr alter_table_cmds
2351 : : {
1964 2352 : 54 : AlterTableStmt *n = makeNode(AlterTableStmt);
2353 : :
2354 : 54 : n->relation = $6;
2355 : 54 : n->cmds = $7;
1934 michael@paquier.xyz 2356 : 54 : n->objtype = OBJECT_FOREIGN_TABLE;
1964 peter@eisentraut.org 2357 : 54 : n->missing_ok = true;
1263 2358 : 54 : $$ = (Node *) n;
2359 : : }
2360 : : ;
2361 : :
2362 : : alter_table_cmds:
7820 neilc@samurai.com 2363 : 13789 : alter_table_cmd { $$ = list_make1($1); }
7845 tgl@sss.pgh.pa.us 2364 : 510 : | alter_table_cmds ',' alter_table_cmd { $$ = lappend($1, $3); }
2365 : : ;
2366 : :
2367 : : partition_cmd:
2368 : : /* ALTER TABLE <name> ATTACH PARTITION <table_name> FOR VALUES */
2369 : : ATTACH PARTITION qualified_name PartitionBoundSpec
2370 : : {
3246 rhaas@postgresql.org 2371 : 1221 : AlterTableCmd *n = makeNode(AlterTableCmd);
2372 : 1221 : PartitionCmd *cmd = makeNode(PartitionCmd);
2373 : :
2374 : 1221 : n->subtype = AT_AttachPartition;
2375 : 1221 : cmd->name = $3;
3074 tgl@sss.pgh.pa.us 2376 : 1221 : cmd->bound = $4;
1677 alvherre@alvh.no-ip. 2377 : 1221 : cmd->concurrent = false;
3246 rhaas@postgresql.org 2378 : 1221 : n->def = (Node *) cmd;
2379 : :
2380 : 1221 : $$ = (Node *) n;
2381 : : }
2382 : : /* ALTER TABLE <name> DETACH PARTITION <partition_name> [CONCURRENTLY] */
2383 : : | DETACH PARTITION qualified_name opt_concurrently
2384 : : {
2385 : 301 : AlterTableCmd *n = makeNode(AlterTableCmd);
2386 : 301 : PartitionCmd *cmd = makeNode(PartitionCmd);
2387 : :
2388 : 301 : n->subtype = AT_DetachPartition;
2389 : 301 : cmd->name = $3;
3074 tgl@sss.pgh.pa.us 2390 : 301 : cmd->bound = NULL;
1677 alvherre@alvh.no-ip. 2391 : 301 : cmd->concurrent = $4;
3246 rhaas@postgresql.org 2392 : 301 : n->def = (Node *) cmd;
2393 : :
1677 alvherre@alvh.no-ip. 2394 : 301 : $$ = (Node *) n;
2395 : : }
2396 : : | DETACH PARTITION qualified_name FINALIZE
2397 : : {
2398 : 10 : AlterTableCmd *n = makeNode(AlterTableCmd);
2399 : 10 : PartitionCmd *cmd = makeNode(PartitionCmd);
2400 : :
2401 : 10 : n->subtype = AT_DetachPartitionFinalize;
2402 : 10 : cmd->name = $3;
2403 : 10 : cmd->bound = NULL;
2404 : 10 : cmd->concurrent = false;
2405 : 10 : n->def = (Node *) cmd;
3246 rhaas@postgresql.org 2406 : 10 : $$ = (Node *) n;
2407 : : }
2408 : : ;
2409 : :
2410 : : index_partition_cmd:
2411 : : /* ALTER INDEX <name> ATTACH PARTITION <index_name> */
2412 : : ATTACH PARTITION qualified_name
2413 : : {
2838 alvherre@alvh.no-ip. 2414 : 199 : AlterTableCmd *n = makeNode(AlterTableCmd);
2415 : 199 : PartitionCmd *cmd = makeNode(PartitionCmd);
2416 : :
2417 : 199 : n->subtype = AT_AttachPartition;
2418 : 199 : cmd->name = $3;
2419 : 199 : cmd->bound = NULL;
1677 2420 : 199 : cmd->concurrent = false;
2838 2421 : 199 : n->def = (Node *) cmd;
2422 : :
2423 : 199 : $$ = (Node *) n;
2424 : : }
2425 : : ;
2426 : :
2427 : : alter_table_cmd:
2428 : : /* ALTER TABLE <name> ADD <coldef> */
2429 : : ADD_P columnDef
2430 : : {
5803 tgl@sss.pgh.pa.us 2431 : 96 : AlterTableCmd *n = makeNode(AlterTableCmd);
2432 : :
2433 : 96 : n->subtype = AT_AddColumn;
2434 : 96 : n->def = $2;
3743 andrew@dunslane.net 2435 : 96 : n->missing_ok = false;
1263 peter@eisentraut.org 2436 : 96 : $$ = (Node *) n;
2437 : : }
2438 : : /* ALTER TABLE <name> ADD IF NOT EXISTS <coldef> */
2439 : : | ADD_P IF_P NOT EXISTS columnDef
2440 : : {
3743 andrew@dunslane.net 2441 :UBC 0 : AlterTableCmd *n = makeNode(AlterTableCmd);
2442 : :
2443 : 0 : n->subtype = AT_AddColumn;
2444 : 0 : n->def = $5;
2445 : 0 : n->missing_ok = true;
1263 peter@eisentraut.org 2446 : 0 : $$ = (Node *) n;
2447 : : }
2448 : : /* ALTER TABLE <name> ADD COLUMN <coldef> */
2449 : : | ADD_P COLUMN columnDef
2450 : : {
7845 tgl@sss.pgh.pa.us 2451 :CBC 960 : AlterTableCmd *n = makeNode(AlterTableCmd);
2452 : :
2453 : 960 : n->subtype = AT_AddColumn;
2454 : 960 : n->def = $3;
3743 andrew@dunslane.net 2455 : 960 : n->missing_ok = false;
1263 peter@eisentraut.org 2456 : 960 : $$ = (Node *) n;
2457 : : }
2458 : : /* ALTER TABLE <name> ADD COLUMN IF NOT EXISTS <coldef> */
2459 : : | ADD_P COLUMN IF_P NOT EXISTS columnDef
2460 : : {
3743 andrew@dunslane.net 2461 : 30 : AlterTableCmd *n = makeNode(AlterTableCmd);
2462 : :
2463 : 30 : n->subtype = AT_AddColumn;
2464 : 30 : n->def = $6;
2465 : 30 : n->missing_ok = true;
1263 peter@eisentraut.org 2466 : 30 : $$ = (Node *) n;
2467 : : }
2468 : : /* ALTER TABLE <name> ALTER [COLUMN] <colname> {SET DEFAULT <expr>|DROP DEFAULT} */
2469 : : | ALTER opt_column ColId alter_column_default
2470 : : {
7845 tgl@sss.pgh.pa.us 2471 : 275 : AlterTableCmd *n = makeNode(AlterTableCmd);
2472 : :
2473 : 275 : n->subtype = AT_ColumnDefault;
2474 : 275 : n->name = $3;
2475 : 275 : n->def = $4;
1263 peter@eisentraut.org 2476 : 275 : $$ = (Node *) n;
2477 : : }
2478 : : /* ALTER TABLE <name> ALTER [COLUMN] <colname> DROP NOT NULL */
2479 : : | ALTER opt_column ColId DROP NOT NULL_P
2480 : : {
7845 tgl@sss.pgh.pa.us 2481 : 147 : AlterTableCmd *n = makeNode(AlterTableCmd);
2482 : :
2483 : 147 : n->subtype = AT_DropNotNull;
2484 : 147 : n->name = $3;
1263 peter@eisentraut.org 2485 : 147 : $$ = (Node *) n;
2486 : : }
2487 : : /* ALTER TABLE <name> ALTER [COLUMN] <colname> SET NOT NULL */
2488 : : | ALTER opt_column ColId SET NOT NULL_P
2489 : : {
7845 tgl@sss.pgh.pa.us 2490 : 220 : AlterTableCmd *n = makeNode(AlterTableCmd);
2491 : :
2492 : 220 : n->subtype = AT_SetNotNull;
2493 : 220 : n->name = $3;
1263 peter@eisentraut.org 2494 : 220 : $$ = (Node *) n;
2495 : : }
2496 : : /* ALTER TABLE <name> ALTER [COLUMN] <colname> SET EXPRESSION AS <expr> */
2497 : : | ALTER opt_column ColId SET EXPRESSION AS '(' a_expr ')'
2498 : : {
662 2499 : 84 : AlterTableCmd *n = makeNode(AlterTableCmd);
2500 : :
2501 : 84 : n->subtype = AT_SetExpression;
2502 : 84 : n->name = $3;
2503 : 84 : n->def = $8;
2504 : 84 : $$ = (Node *) n;
2505 : : }
2506 : : /* ALTER TABLE <name> ALTER [COLUMN] <colname> DROP EXPRESSION */
2507 : : | ALTER opt_column ColId DROP EXPRESSION
2508 : : {
2113 2509 : 31 : AlterTableCmd *n = makeNode(AlterTableCmd);
2510 : :
2511 : 31 : n->subtype = AT_DropExpression;
2512 : 31 : n->name = $3;
1263 2513 : 31 : $$ = (Node *) n;
2514 : : }
2515 : : /* ALTER TABLE <name> ALTER [COLUMN] <colname> DROP EXPRESSION IF EXISTS */
2516 : : | ALTER opt_column ColId DROP EXPRESSION IF_P EXISTS
2517 : : {
2113 2518 : 6 : AlterTableCmd *n = makeNode(AlterTableCmd);
2519 : :
2520 : 6 : n->subtype = AT_DropExpression;
2521 : 6 : n->name = $3;
2522 : 6 : n->missing_ok = true;
1263 2523 : 6 : $$ = (Node *) n;
2524 : : }
2525 : : /* ALTER TABLE <name> ALTER [COLUMN] <colname> SET STATISTICS */
2526 : : | ALTER opt_column ColId SET STATISTICS set_statistics_value
2527 : : {
7845 tgl@sss.pgh.pa.us 2528 : 31 : AlterTableCmd *n = makeNode(AlterTableCmd);
2529 : :
2530 : 31 : n->subtype = AT_SetStatistics;
2531 : 31 : n->name = $3;
653 peter@eisentraut.org 2532 : 31 : n->def = $6;
1263 2533 : 31 : $$ = (Node *) n;
2534 : : }
2535 : : /* ALTER TABLE <name> ALTER [COLUMN] <colnum> SET STATISTICS */
2536 : : | ALTER opt_column Iconst SET STATISTICS set_statistics_value
2537 : : {
2973 simon@2ndQuadrant.co 2538 : 35 : AlterTableCmd *n = makeNode(AlterTableCmd);
2539 : :
2540 [ + + - + ]: 35 : if ($3 <= 0 || $3 > PG_INT16_MAX)
2541 [ + - ]: 3 : ereport(ERROR,
2542 : : (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
2543 : : errmsg("column number must be in range from 1 to %d", PG_INT16_MAX),
2544 : : parser_errposition(@3)));
2545 : :
2546 : 32 : n->subtype = AT_SetStatistics;
2547 : 32 : n->num = (int16) $3;
653 peter@eisentraut.org 2548 : 32 : n->def = $6;
1263 2549 : 32 : $$ = (Node *) n;
2550 : : }
2551 : : /* ALTER TABLE <name> ALTER [COLUMN] <colname> SET ( column_parameter = value [, ... ] ) */
2552 : : | ALTER opt_column ColId SET reloptions
2553 : : {
5930 tgl@sss.pgh.pa.us 2554 : 19 : AlterTableCmd *n = makeNode(AlterTableCmd);
2555 : :
5757 rhaas@postgresql.org 2556 : 19 : n->subtype = AT_SetOptions;
5930 tgl@sss.pgh.pa.us 2557 : 19 : n->name = $3;
5757 rhaas@postgresql.org 2558 : 19 : n->def = (Node *) $5;
1263 peter@eisentraut.org 2559 : 19 : $$ = (Node *) n;
2560 : : }
2561 : : /* ALTER TABLE <name> ALTER [COLUMN] <colname> RESET ( column_parameter [, ... ] ) */
2562 : : | ALTER opt_column ColId RESET reloptions
2563 : : {
5757 rhaas@postgresql.org 2564 : 3 : AlterTableCmd *n = makeNode(AlterTableCmd);
2565 : :
2566 : 3 : n->subtype = AT_ResetOptions;
2567 : 3 : n->name = $3;
2568 : 3 : n->def = (Node *) $5;
1263 peter@eisentraut.org 2569 : 3 : $$ = (Node *) n;
2570 : : }
2571 : : /* ALTER TABLE <name> ALTER [COLUMN] <colname> SET STORAGE <storagemode> */
2572 : : | ALTER opt_column ColId SET column_storage
2573 : : {
7845 tgl@sss.pgh.pa.us 2574 : 119 : AlterTableCmd *n = makeNode(AlterTableCmd);
2575 : :
2576 : 119 : n->subtype = AT_SetStorage;
2577 : 119 : n->name = $3;
1202 peter@eisentraut.org 2578 : 119 : n->def = (Node *) makeString($5);
1263 2579 : 119 : $$ = (Node *) n;
2580 : : }
2581 : : /* ALTER TABLE <name> ALTER [COLUMN] <colname> SET COMPRESSION <cm> */
2582 : : | ALTER opt_column ColId SET column_compression
2583 : : {
1614 tgl@sss.pgh.pa.us 2584 : 39 : AlterTableCmd *n = makeNode(AlterTableCmd);
2585 : :
2586 : 39 : n->subtype = AT_SetCompression;
2587 : 39 : n->name = $3;
2588 : 39 : n->def = (Node *) makeString($5);
1263 peter@eisentraut.org 2589 : 39 : $$ = (Node *) n;
2590 : : }
2591 : : /* ALTER TABLE <name> ALTER [COLUMN] <colname> ADD GENERATED ... AS IDENTITY ... */
2592 : : | ALTER opt_column ColId ADD_P GENERATED generated_when AS IDENTITY_P OptParenthesizedSeqOptList
2593 : : {
3126 peter_e@gmx.net 2594 : 83 : AlterTableCmd *n = makeNode(AlterTableCmd);
2595 : 83 : Constraint *c = makeNode(Constraint);
2596 : :
2597 : 83 : c->contype = CONSTR_IDENTITY;
2598 : 83 : c->generated_when = $6;
2599 : 83 : c->options = $9;
2600 : 83 : c->location = @5;
2601 : :
2602 : 83 : n->subtype = AT_AddIdentity;
2603 : 83 : n->name = $3;
2604 : 83 : n->def = (Node *) c;
2605 : :
1263 peter@eisentraut.org 2606 : 83 : $$ = (Node *) n;
2607 : : }
2608 : : /* ALTER TABLE <name> ALTER [COLUMN] <colname> SET <sequence options>/RESET */
2609 : : | ALTER opt_column ColId alter_identity_column_option_list
2610 : : {
3126 peter_e@gmx.net 2611 : 31 : AlterTableCmd *n = makeNode(AlterTableCmd);
2612 : :
2613 : 31 : n->subtype = AT_SetIdentity;
2614 : 31 : n->name = $3;
2615 : 31 : n->def = (Node *) $4;
1263 peter@eisentraut.org 2616 : 31 : $$ = (Node *) n;
2617 : : }
2618 : : /* ALTER TABLE <name> ALTER [COLUMN] <colname> DROP IDENTITY */
2619 : : | ALTER opt_column ColId DROP IDENTITY_P
2620 : : {
3126 peter_e@gmx.net 2621 : 25 : AlterTableCmd *n = makeNode(AlterTableCmd);
2622 : :
2623 : 25 : n->subtype = AT_DropIdentity;
2624 : 25 : n->name = $3;
2625 : 25 : n->missing_ok = false;
1263 peter@eisentraut.org 2626 : 25 : $$ = (Node *) n;
2627 : : }
2628 : : /* ALTER TABLE <name> ALTER [COLUMN] <colname> DROP IDENTITY IF EXISTS */
2629 : : | ALTER opt_column ColId DROP IDENTITY_P IF_P EXISTS
2630 : : {
3126 peter_e@gmx.net 2631 : 3 : AlterTableCmd *n = makeNode(AlterTableCmd);
2632 : :
2633 : 3 : n->subtype = AT_DropIdentity;
2634 : 3 : n->name = $3;
2635 : 3 : n->missing_ok = true;
1263 peter@eisentraut.org 2636 : 3 : $$ = (Node *) n;
2637 : : }
2638 : : /* ALTER TABLE <name> DROP [COLUMN] IF EXISTS <colname> [RESTRICT|CASCADE] */
2639 : : | DROP opt_column IF_P EXISTS ColId opt_drop_behavior
2640 : : {
5943 andrew@dunslane.net 2641 : 9 : AlterTableCmd *n = makeNode(AlterTableCmd);
2642 : :
2643 : 9 : n->subtype = AT_DropColumn;
2644 : 9 : n->name = $5;
2645 : 9 : n->behavior = $6;
2994 peter_e@gmx.net 2646 : 9 : n->missing_ok = true;
1263 peter@eisentraut.org 2647 : 9 : $$ = (Node *) n;
2648 : : }
2649 : : /* ALTER TABLE <name> DROP [COLUMN] <colname> [RESTRICT|CASCADE] */
2650 : : | DROP opt_column ColId opt_drop_behavior
2651 : : {
7845 tgl@sss.pgh.pa.us 2652 : 790 : AlterTableCmd *n = makeNode(AlterTableCmd);
2653 : :
2654 : 790 : n->subtype = AT_DropColumn;
2655 : 790 : n->name = $3;
2656 : 790 : n->behavior = $4;
2994 peter_e@gmx.net 2657 : 790 : n->missing_ok = false;
1263 peter@eisentraut.org 2658 : 790 : $$ = (Node *) n;
2659 : : }
2660 : : /*
2661 : : * ALTER TABLE <name> ALTER [COLUMN] <colname> [SET DATA] TYPE <typename>
2662 : : * [ USING <expression> ]
2663 : : */
2664 : : | ALTER opt_column ColId opt_set_data TYPE_P Typename opt_collate_clause alter_using
2665 : : {
7845 tgl@sss.pgh.pa.us 2666 : 510 : AlterTableCmd *n = makeNode(AlterTableCmd);
5346 2667 : 510 : ColumnDef *def = makeNode(ColumnDef);
2668 : :
7845 2669 : 510 : n->subtype = AT_AlterColumnType;
2670 : 510 : n->name = $3;
5346 2671 : 510 : n->def = (Node *) def;
2672 : : /* We only use these fields of the ColumnDef node */
2673 : 510 : def->typeName = $6;
2674 : 510 : def->collClause = (CollateClause *) $7;
2675 : 510 : def->raw_default = $8;
4358 2676 : 510 : def->location = @3;
1263 peter@eisentraut.org 2677 : 510 : $$ = (Node *) n;
2678 : : }
2679 : : /* ALTER FOREIGN TABLE <name> ALTER [COLUMN] <colname> OPTIONS */
2680 : : | ALTER opt_column ColId alter_generic_options
2681 : : {
5197 rhaas@postgresql.org 2682 : 25 : AlterTableCmd *n = makeNode(AlterTableCmd);
2683 : :
2684 : 25 : n->subtype = AT_AlterColumnGenericOptions;
2685 : 25 : n->name = $3;
2686 : 25 : n->def = (Node *) $4;
1263 peter@eisentraut.org 2687 : 25 : $$ = (Node *) n;
2688 : : }
2689 : : /* ALTER TABLE <name> ADD CONSTRAINT ... */
2690 : : | ADD_P TableConstraint
2691 : : {
7845 tgl@sss.pgh.pa.us 2692 : 7289 : AlterTableCmd *n = makeNode(AlterTableCmd);
2693 : :
2694 : 7289 : n->subtype = AT_AddConstraint;
2695 : 7289 : n->def = $2;
1263 peter@eisentraut.org 2696 : 7289 : $$ = (Node *) n;
2697 : : }
2698 : : /* ALTER TABLE <name> ALTER CONSTRAINT ... */
2699 : : | ALTER CONSTRAINT name ConstraintAttributeSpec
2700 : : {
4503 simon@2ndQuadrant.co 2701 : 120 : AlterTableCmd *n = makeNode(AlterTableCmd);
250 alvherre@alvh.no-ip. 2702 : 120 : ATAlterConstraint *c = makeNode(ATAlterConstraint);
2703 : :
4503 simon@2ndQuadrant.co 2704 : 120 : n->subtype = AT_AlterConstraint;
2705 : 120 : n->def = (Node *) c;
2706 : 120 : c->conname = $3;
208 peter@eisentraut.org 2707 [ + + ]: 120 : if ($4 & (CAS_NOT_ENFORCED | CAS_ENFORCED))
2708 : 42 : c->alterEnforceability = true;
214 alvherre@alvh.no-ip. 2709 [ + + ]: 120 : if ($4 & (CAS_DEFERRABLE | CAS_NOT_DEFERRABLE |
2710 : : CAS_INITIALLY_DEFERRED | CAS_INITIALLY_IMMEDIATE))
2711 : 60 : c->alterDeferrability = true;
2712 [ + + ]: 120 : if ($4 & CAS_NO_INHERIT)
2713 : 15 : c->alterInheritability = true;
2714 : : /* handle unsupported case with specific error message */
117 alvherre@kurilemu.de 2715 [ + + ]: 120 : if ($4 & CAS_NOT_VALID)
2716 [ + - ]: 6 : ereport(ERROR,
2717 : : errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
2718 : : errmsg("constraints cannot be altered to be NOT VALID"),
2719 : : parser_errposition(@4));
237 alvherre@alvh.no-ip. 2720 : 114 : processCASbits($4, @4, "FOREIGN KEY",
2721 : : &c->deferrable,
2722 : : &c->initdeferred,
2723 : : &c->is_enforced,
2724 : : NULL,
2725 : : &c->noinherit,
2726 : : yyscanner);
1263 peter@eisentraut.org 2727 : 114 : $$ = (Node *) n;
2728 : : }
2729 : : /* ALTER TABLE <name> ALTER CONSTRAINT INHERIT */
2730 : : | ALTER CONSTRAINT name INHERIT
2731 : : {
236 alvherre@alvh.no-ip. 2732 : 33 : AlterTableCmd *n = makeNode(AlterTableCmd);
2733 : 33 : ATAlterConstraint *c = makeNode(ATAlterConstraint);
2734 : :
2735 : 33 : n->subtype = AT_AlterConstraint;
2736 : 33 : n->def = (Node *) c;
2737 : 33 : c->conname = $3;
2738 : 33 : c->alterInheritability = true;
2739 : 33 : c->noinherit = false;
2740 : :
2741 : 33 : $$ = (Node *) n;
2742 : : }
2743 : : /* ALTER TABLE <name> VALIDATE CONSTRAINT ... */
2744 : : | VALIDATE CONSTRAINT name
2745 : : {
5375 simon@2ndQuadrant.co 2746 : 238 : AlterTableCmd *n = makeNode(AlterTableCmd);
2747 : :
2748 : 238 : n->subtype = AT_ValidateConstraint;
2749 : 238 : n->name = $3;
1263 peter@eisentraut.org 2750 : 238 : $$ = (Node *) n;
2751 : : }
2752 : : /* ALTER TABLE <name> DROP CONSTRAINT IF EXISTS <name> [RESTRICT|CASCADE] */
2753 : : | DROP CONSTRAINT IF_P EXISTS name opt_drop_behavior
2754 : : {
5943 andrew@dunslane.net 2755 : 9 : AlterTableCmd *n = makeNode(AlterTableCmd);
2756 : :
2757 : 9 : n->subtype = AT_DropConstraint;
2758 : 9 : n->name = $5;
2759 : 9 : n->behavior = $6;
2994 peter_e@gmx.net 2760 : 9 : n->missing_ok = true;
1263 peter@eisentraut.org 2761 : 9 : $$ = (Node *) n;
2762 : : }
2763 : : /* ALTER TABLE <name> DROP CONSTRAINT <name> [RESTRICT|CASCADE] */
2764 : : | DROP CONSTRAINT name opt_drop_behavior
2765 : : {
7845 tgl@sss.pgh.pa.us 2766 : 409 : AlterTableCmd *n = makeNode(AlterTableCmd);
2767 : :
2768 : 409 : n->subtype = AT_DropConstraint;
2769 : 409 : n->name = $3;
2770 : 409 : n->behavior = $4;
2994 peter_e@gmx.net 2771 : 409 : n->missing_ok = false;
1263 peter@eisentraut.org 2772 : 409 : $$ = (Node *) n;
2773 : : }
2774 : : /* ALTER TABLE <name> SET WITHOUT OIDS, for backward compat */
2775 : : | SET WITHOUT OIDS
2776 : : {
7845 tgl@sss.pgh.pa.us 2777 : 3 : AlterTableCmd *n = makeNode(AlterTableCmd);
2778 : :
2779 : 3 : n->subtype = AT_DropOids;
1263 peter@eisentraut.org 2780 : 3 : $$ = (Node *) n;
2781 : : }
2782 : : /* ALTER TABLE <name> CLUSTER ON <indexname> */
2783 : : | CLUSTER ON name
2784 : : {
7845 tgl@sss.pgh.pa.us 2785 : 23 : AlterTableCmd *n = makeNode(AlterTableCmd);
2786 : :
2787 : 23 : n->subtype = AT_ClusterOn;
2788 : 23 : n->name = $3;
1263 peter@eisentraut.org 2789 : 23 : $$ = (Node *) n;
2790 : : }
2791 : : /* ALTER TABLE <name> SET WITHOUT CLUSTER */
2792 : : | SET WITHOUT CLUSTER
2793 : : {
7817 bruce@momjian.us 2794 : 9 : AlterTableCmd *n = makeNode(AlterTableCmd);
2795 : :
2796 : 9 : n->subtype = AT_DropCluster;
2797 : 9 : n->name = NULL;
1263 peter@eisentraut.org 2798 : 9 : $$ = (Node *) n;
2799 : : }
2800 : : /* ALTER TABLE <name> SET LOGGED */
2801 : : | SET LOGGED
2802 : : {
4084 alvherre@alvh.no-ip. 2803 : 25 : AlterTableCmd *n = makeNode(AlterTableCmd);
2804 : :
2805 : 25 : n->subtype = AT_SetLogged;
1263 peter@eisentraut.org 2806 : 25 : $$ = (Node *) n;
2807 : : }
2808 : : /* ALTER TABLE <name> SET UNLOGGED */
2809 : : | SET UNLOGGED
2810 : : {
4084 alvherre@alvh.no-ip. 2811 : 31 : AlterTableCmd *n = makeNode(AlterTableCmd);
2812 : :
2813 : 31 : n->subtype = AT_SetUnLogged;
1263 peter@eisentraut.org 2814 : 31 : $$ = (Node *) n;
2815 : : }
2816 : : /* ALTER TABLE <name> ENABLE TRIGGER <trig> */
2817 : : | ENABLE_P TRIGGER name
2818 : : {
7370 tgl@sss.pgh.pa.us 2819 : 61 : AlterTableCmd *n = makeNode(AlterTableCmd);
2820 : :
2821 : 61 : n->subtype = AT_EnableTrig;
2822 : 61 : n->name = $3;
1263 peter@eisentraut.org 2823 : 61 : $$ = (Node *) n;
2824 : : }
2825 : : /* ALTER TABLE <name> ENABLE ALWAYS TRIGGER <trig> */
2826 : : | ENABLE_P ALWAYS TRIGGER name
2827 : : {
6797 JanWieck@Yahoo.com 2828 : 21 : AlterTableCmd *n = makeNode(AlterTableCmd);
2829 : :
2830 : 21 : n->subtype = AT_EnableAlwaysTrig;
2831 : 21 : n->name = $4;
1263 peter@eisentraut.org 2832 : 21 : $$ = (Node *) n;
2833 : : }
2834 : : /* ALTER TABLE <name> ENABLE REPLICA TRIGGER <trig> */
2835 : : | ENABLE_P REPLICA TRIGGER name
2836 : : {
6797 JanWieck@Yahoo.com 2837 : 8 : AlterTableCmd *n = makeNode(AlterTableCmd);
2838 : :
2839 : 8 : n->subtype = AT_EnableReplicaTrig;
2840 : 8 : n->name = $4;
1263 peter@eisentraut.org 2841 : 8 : $$ = (Node *) n;
2842 : : }
2843 : : /* ALTER TABLE <name> ENABLE TRIGGER ALL */
2844 : : | ENABLE_P TRIGGER ALL
2845 : : {
7370 tgl@sss.pgh.pa.us 2846 :UBC 0 : AlterTableCmd *n = makeNode(AlterTableCmd);
2847 : :
2848 : 0 : n->subtype = AT_EnableTrigAll;
1263 peter@eisentraut.org 2849 : 0 : $$ = (Node *) n;
2850 : : }
2851 : : /* ALTER TABLE <name> ENABLE TRIGGER USER */
2852 : : | ENABLE_P TRIGGER USER
2853 : : {
7370 tgl@sss.pgh.pa.us 2854 : 0 : AlterTableCmd *n = makeNode(AlterTableCmd);
2855 : :
2856 : 0 : n->subtype = AT_EnableTrigUser;
1263 peter@eisentraut.org 2857 : 0 : $$ = (Node *) n;
2858 : : }
2859 : : /* ALTER TABLE <name> DISABLE TRIGGER <trig> */
2860 : : | DISABLE_P TRIGGER name
2861 : : {
7370 tgl@sss.pgh.pa.us 2862 :CBC 69 : AlterTableCmd *n = makeNode(AlterTableCmd);
2863 : :
2864 : 69 : n->subtype = AT_DisableTrig;
2865 : 69 : n->name = $3;
1263 peter@eisentraut.org 2866 : 69 : $$ = (Node *) n;
2867 : : }
2868 : : /* ALTER TABLE <name> DISABLE TRIGGER ALL */
2869 : : | DISABLE_P TRIGGER ALL
2870 : : {
7370 tgl@sss.pgh.pa.us 2871 : 6 : AlterTableCmd *n = makeNode(AlterTableCmd);
2872 : :
2873 : 6 : n->subtype = AT_DisableTrigAll;
1263 peter@eisentraut.org 2874 : 6 : $$ = (Node *) n;
2875 : : }
2876 : : /* ALTER TABLE <name> DISABLE TRIGGER USER */
2877 : : | DISABLE_P TRIGGER USER
2878 : : {
7370 tgl@sss.pgh.pa.us 2879 : 6 : AlterTableCmd *n = makeNode(AlterTableCmd);
2880 : :
2881 : 6 : n->subtype = AT_DisableTrigUser;
1263 peter@eisentraut.org 2882 : 6 : $$ = (Node *) n;
2883 : : }
2884 : : /* ALTER TABLE <name> ENABLE RULE <rule> */
2885 : : | ENABLE_P RULE name
2886 : : {
6797 JanWieck@Yahoo.com 2887 : 4 : AlterTableCmd *n = makeNode(AlterTableCmd);
2888 : :
2889 : 4 : n->subtype = AT_EnableRule;
2890 : 4 : n->name = $3;
1263 peter@eisentraut.org 2891 : 4 : $$ = (Node *) n;
2892 : : }
2893 : : /* ALTER TABLE <name> ENABLE ALWAYS RULE <rule> */
2894 : : | ENABLE_P ALWAYS RULE name
2895 : : {
6797 JanWieck@Yahoo.com 2896 :UBC 0 : AlterTableCmd *n = makeNode(AlterTableCmd);
2897 : :
2898 : 0 : n->subtype = AT_EnableAlwaysRule;
2899 : 0 : n->name = $4;
1263 peter@eisentraut.org 2900 : 0 : $$ = (Node *) n;
2901 : : }
2902 : : /* ALTER TABLE <name> ENABLE REPLICA RULE <rule> */
2903 : : | ENABLE_P REPLICA RULE name
2904 : : {
6797 JanWieck@Yahoo.com 2905 :CBC 3 : AlterTableCmd *n = makeNode(AlterTableCmd);
2906 : :
2907 : 3 : n->subtype = AT_EnableReplicaRule;
2908 : 3 : n->name = $4;
1263 peter@eisentraut.org 2909 : 3 : $$ = (Node *) n;
2910 : : }
2911 : : /* ALTER TABLE <name> DISABLE RULE <rule> */
2912 : : | DISABLE_P RULE name
2913 : : {
6797 JanWieck@Yahoo.com 2914 : 16 : AlterTableCmd *n = makeNode(AlterTableCmd);
2915 : :
2916 : 16 : n->subtype = AT_DisableRule;
2917 : 16 : n->name = $3;
1263 peter@eisentraut.org 2918 : 16 : $$ = (Node *) n;
2919 : : }
2920 : : /* ALTER TABLE <name> INHERIT <parent> */
2921 : : | INHERIT qualified_name
2922 : : {
7057 bruce@momjian.us 2923 : 231 : AlterTableCmd *n = makeNode(AlterTableCmd);
2924 : :
6954 tgl@sss.pgh.pa.us 2925 : 231 : n->subtype = AT_AddInherit;
2926 : 231 : n->def = (Node *) $2;
1263 peter@eisentraut.org 2927 : 231 : $$ = (Node *) n;
2928 : : }
2929 : : /* ALTER TABLE <name> NO INHERIT <parent> */
2930 : : | NO INHERIT qualified_name
2931 : : {
7057 bruce@momjian.us 2932 : 47 : AlterTableCmd *n = makeNode(AlterTableCmd);
2933 : :
6954 tgl@sss.pgh.pa.us 2934 : 47 : n->subtype = AT_DropInherit;
2935 : 47 : n->def = (Node *) $3;
1263 peter@eisentraut.org 2936 : 47 : $$ = (Node *) n;
2937 : : }
2938 : : /* ALTER TABLE <name> OF <type_name> */
2939 : : | OF any_name
2940 : : {
5304 rhaas@postgresql.org 2941 : 33 : AlterTableCmd *n = makeNode(AlterTableCmd);
1263 peter@eisentraut.org 2942 : 33 : TypeName *def = makeTypeNameFromNameList($2);
2943 : :
5304 rhaas@postgresql.org 2944 : 33 : def->location = @2;
2945 : 33 : n->subtype = AT_AddOf;
2946 : 33 : n->def = (Node *) def;
1263 peter@eisentraut.org 2947 : 33 : $$ = (Node *) n;
2948 : : }
2949 : : /* ALTER TABLE <name> NOT OF */
2950 : : | NOT OF
2951 : : {
5304 rhaas@postgresql.org 2952 : 3 : AlterTableCmd *n = makeNode(AlterTableCmd);
2953 : :
2954 : 3 : n->subtype = AT_DropOf;
1263 peter@eisentraut.org 2955 : 3 : $$ = (Node *) n;
2956 : : }
2957 : : /* ALTER TABLE <name> OWNER TO RoleSpec */
2958 : : | OWNER TO RoleSpec
2959 : : {
7738 bruce@momjian.us 2960 : 1012 : AlterTableCmd *n = makeNode(AlterTableCmd);
2961 : :
2962 : 1012 : n->subtype = AT_ChangeOwner;
3885 alvherre@alvh.no-ip. 2963 : 1012 : n->newowner = $3;
1263 peter@eisentraut.org 2964 : 1012 : $$ = (Node *) n;
2965 : : }
2966 : : /* ALTER TABLE <name> SET ACCESS METHOD { <amname> | DEFAULT } */
2967 : : | SET ACCESS METHOD set_access_method_name
2968 : : {
1552 michael@paquier.xyz 2969 : 64 : AlterTableCmd *n = makeNode(AlterTableCmd);
2970 : :
2971 : 64 : n->subtype = AT_SetAccessMethod;
2972 : 64 : n->name = $4;
1263 peter@eisentraut.org 2973 : 64 : $$ = (Node *) n;
2974 : : }
2975 : : /* ALTER TABLE <name> SET TABLESPACE <tablespacename> */
2976 : : | SET TABLESPACE name
2977 : : {
7778 tgl@sss.pgh.pa.us 2978 : 66 : AlterTableCmd *n = makeNode(AlterTableCmd);
2979 : :
2980 : 66 : n->subtype = AT_SetTableSpace;
2981 : 66 : n->name = $3;
1263 peter@eisentraut.org 2982 : 66 : $$ = (Node *) n;
2983 : : }
2984 : : /* ALTER TABLE <name> SET (...) */
2985 : : | SET reloptions
2986 : : {
7057 bruce@momjian.us 2987 : 300 : AlterTableCmd *n = makeNode(AlterTableCmd);
2988 : :
7056 tgl@sss.pgh.pa.us 2989 : 300 : n->subtype = AT_SetRelOptions;
1263 peter@eisentraut.org 2990 : 300 : n->def = (Node *) $2;
2991 : 300 : $$ = (Node *) n;
2992 : : }
2993 : : /* ALTER TABLE <name> RESET (...) */
2994 : : | RESET reloptions
2995 : : {
7056 tgl@sss.pgh.pa.us 2996 : 85 : AlterTableCmd *n = makeNode(AlterTableCmd);
2997 : :
2998 : 85 : n->subtype = AT_ResetRelOptions;
1263 peter@eisentraut.org 2999 : 85 : n->def = (Node *) $2;
3000 : 85 : $$ = (Node *) n;
3001 : : }
3002 : : /* ALTER TABLE <name> REPLICA IDENTITY */
3003 : : | REPLICA IDENTITY_P replica_identity
3004 : : {
4371 rhaas@postgresql.org 3005 : 247 : AlterTableCmd *n = makeNode(AlterTableCmd);
3006 : :
3007 : 247 : n->subtype = AT_ReplicaIdentity;
3008 : 247 : n->def = $3;
1263 peter@eisentraut.org 3009 : 247 : $$ = (Node *) n;
3010 : : }
3011 : : /* ALTER TABLE <name> ENABLE ROW LEVEL SECURITY */
3012 : : | ENABLE_P ROW LEVEL SECURITY
3013 : : {
4056 sfrost@snowman.net 3014 : 163 : AlterTableCmd *n = makeNode(AlterTableCmd);
3015 : :
3016 : 163 : n->subtype = AT_EnableRowSecurity;
1263 peter@eisentraut.org 3017 : 163 : $$ = (Node *) n;
3018 : : }
3019 : : /* ALTER TABLE <name> DISABLE ROW LEVEL SECURITY */
3020 : : | DISABLE_P ROW LEVEL SECURITY
3021 : : {
4056 sfrost@snowman.net 3022 : 5 : AlterTableCmd *n = makeNode(AlterTableCmd);
3023 : :
3024 : 5 : n->subtype = AT_DisableRowSecurity;
1263 peter@eisentraut.org 3025 : 5 : $$ = (Node *) n;
3026 : : }
3027 : : /* ALTER TABLE <name> FORCE ROW LEVEL SECURITY */
3028 : : | FORCE ROW LEVEL SECURITY
3029 : : {
3676 sfrost@snowman.net 3030 : 50 : AlterTableCmd *n = makeNode(AlterTableCmd);
3031 : :
3032 : 50 : n->subtype = AT_ForceRowSecurity;
1263 peter@eisentraut.org 3033 : 50 : $$ = (Node *) n;
3034 : : }
3035 : : /* ALTER TABLE <name> NO FORCE ROW LEVEL SECURITY */
3036 : : | NO FORCE ROW LEVEL SECURITY
3037 : : {
3676 sfrost@snowman.net 3038 : 16 : AlterTableCmd *n = makeNode(AlterTableCmd);
3039 : :
3040 : 16 : n->subtype = AT_NoForceRowSecurity;
1263 peter@eisentraut.org 3041 : 16 : $$ = (Node *) n;
3042 : : }
3043 : : | alter_generic_options
3044 : : {
5413 rhaas@postgresql.org 3045 : 32 : AlterTableCmd *n = makeNode(AlterTableCmd);
3046 : :
3047 : 32 : n->subtype = AT_GenericOptions;
1263 peter@eisentraut.org 3048 : 32 : n->def = (Node *) $1;
5413 rhaas@postgresql.org 3049 : 32 : $$ = (Node *) n;
3050 : : }
3051 : : ;
3052 : :
3053 : : alter_column_default:
6573 tgl@sss.pgh.pa.us 3054 : 189 : SET DEFAULT a_expr { $$ = $3; }
7845 3055 : 93 : | DROP DEFAULT { $$ = NULL; }
3056 : : ;
3057 : :
3058 : : opt_collate_clause:
3059 : : COLLATE any_name
3060 : : {
5346 3061 : 9 : CollateClause *n = makeNode(CollateClause);
3062 : :
3063 : 9 : n->arg = NULL;
5344 3064 : 9 : n->collname = $2;
5346 3065 : 9 : n->location = @1;
3066 : 9 : $$ = (Node *) n;
3067 : : }
3068 : 2373 : | /* EMPTY */ { $$ = NULL; }
3069 : : ;
3070 : :
3071 : : alter_using:
7845 3072 : 90 : USING a_expr { $$ = $2; }
3073 : 420 : | /* EMPTY */ { $$ = NULL; }
3074 : : ;
3075 : :
3076 : : replica_identity:
3077 : : NOTHING
3078 : : {
4371 rhaas@postgresql.org 3079 : 24 : ReplicaIdentityStmt *n = makeNode(ReplicaIdentityStmt);
3080 : :
3081 : 24 : n->identity_type = REPLICA_IDENTITY_NOTHING;
3082 : 24 : n->name = NULL;
3083 : 24 : $$ = (Node *) n;
3084 : : }
3085 : : | FULL
3086 : : {
3087 : 85 : ReplicaIdentityStmt *n = makeNode(ReplicaIdentityStmt);
3088 : :
3089 : 85 : n->identity_type = REPLICA_IDENTITY_FULL;
3090 : 85 : n->name = NULL;
3091 : 85 : $$ = (Node *) n;
3092 : : }
3093 : : | DEFAULT
3094 : : {
3095 : 3 : ReplicaIdentityStmt *n = makeNode(ReplicaIdentityStmt);
3096 : :
3097 : 3 : n->identity_type = REPLICA_IDENTITY_DEFAULT;
3098 : 3 : n->name = NULL;
3099 : 3 : $$ = (Node *) n;
3100 : : }
3101 : : | USING INDEX name
3102 : : {
3103 : 135 : ReplicaIdentityStmt *n = makeNode(ReplicaIdentityStmt);
3104 : :
3105 : 135 : n->identity_type = REPLICA_IDENTITY_INDEX;
3106 : 135 : n->name = $3;
3107 : 135 : $$ = (Node *) n;
3108 : : }
3109 : : ;
3110 : :
3111 : : reloptions:
5109 peter_e@gmx.net 3112 : 1350 : '(' reloption_list ')' { $$ = $2; }
3113 : : ;
3114 : :
6111 alvherre@alvh.no-ip. 3115 : 481 : opt_reloptions: WITH reloptions { $$ = $2; }
3116 : 11765 : | /* EMPTY */ { $$ = NIL; }
3117 : : ;
3118 : :
3119 : : reloption_list:
3120 : 1350 : reloption_elem { $$ = list_make1($1); }
3121 : 114 : | reloption_list ',' reloption_elem { $$ = lappend($1, $3); }
3122 : : ;
3123 : :
3124 : : /* This should match def_elem and also allow qualified names */
3125 : : reloption_elem:
3126 : : ColLabel '=' def_arg
3127 : : {
3338 peter_e@gmx.net 3128 : 1138 : $$ = makeDefElem($1, (Node *) $3, @1);
3129 : : }
3130 : : | ColLabel
3131 : : {
3132 : 292 : $$ = makeDefElem($1, NULL, @1);
3133 : : }
3134 : : | ColLabel '.' ColLabel '=' def_arg
3135 : : {
6050 tgl@sss.pgh.pa.us 3136 : 31 : $$ = makeDefElemExtended($1, $3, (Node *) $5,
3338 peter_e@gmx.net 3137 : 31 : DEFELEM_UNSPEC, @1);
3138 : : }
3139 : : | ColLabel '.' ColLabel
3140 : : {
3141 : 3 : $$ = makeDefElemExtended($1, $3, NULL, DEFELEM_UNSPEC, @1);
3142 : : }
3143 : : ;
3144 : :
3145 : : alter_identity_column_option_list:
3146 : : alter_identity_column_option
3126 3147 : 31 : { $$ = list_make1($1); }
3148 : : | alter_identity_column_option_list alter_identity_column_option
3149 : 30 : { $$ = lappend($1, $2); }
3150 : : ;
3151 : :
3152 : : alter_identity_column_option:
3153 : : RESTART
3154 : : {
3155 : 12 : $$ = makeDefElem("restart", NULL, @1);
3156 : : }
3157 : : | RESTART opt_with NumericOnly
3158 : : {
1263 peter@eisentraut.org 3159 :UBC 0 : $$ = makeDefElem("restart", (Node *) $3, @1);
3160 : : }
3161 : : | SET SeqOptElem
3162 : : {
3126 peter_e@gmx.net 3163 [ + - ]:CBC 27 : if (strcmp($2->defname, "as") == 0 ||
3164 [ + - ]: 27 : strcmp($2->defname, "restart") == 0 ||
3165 [ - + ]: 27 : strcmp($2->defname, "owned_by") == 0)
3126 peter_e@gmx.net 3166 [ # # ]:UBC 0 : ereport(ERROR,
3167 : : (errcode(ERRCODE_SYNTAX_ERROR),
3168 : : errmsg("sequence option \"%s\" not supported here", $2->defname),
3169 : : parser_errposition(@2)));
3126 peter_e@gmx.net 3170 :CBC 27 : $$ = $2;
3171 : : }
3172 : : | SET GENERATED generated_when
3173 : : {
3174 : 22 : $$ = makeDefElem("generated", (Node *) makeInteger($3), @1);
3175 : : }
3176 : : ;
3177 : :
3178 : : set_statistics_value:
653 peter@eisentraut.org 3179 : 79 : SignedIconst { $$ = (Node *) makeInteger($1); }
653 peter@eisentraut.org 3180 :UBC 0 : | DEFAULT { $$ = NULL; }
3181 : : ;
3182 : :
3183 : : set_access_method_name:
598 michael@paquier.xyz 3184 :CBC 46 : ColId { $$ = $1; }
3185 : 18 : | DEFAULT { $$ = NULL; }
3186 : : ;
3187 : :
3188 : : PartitionBoundSpec:
3189 : : /* a HASH partition */
3190 : : FOR VALUES WITH '(' hash_partbound ')'
3191 : : {
3192 : : ListCell *lc;
2909 rhaas@postgresql.org 3193 : 366 : PartitionBoundSpec *n = makeNode(PartitionBoundSpec);
3194 : :
3195 : 366 : n->strategy = PARTITION_STRATEGY_HASH;
3196 : 366 : n->modulus = n->remainder = -1;
3197 : :
3198 [ + - + + : 1098 : foreach (lc, $5)
+ + ]
3199 : : {
3200 : 732 : DefElem *opt = lfirst_node(DefElem, lc);
3201 : :
3202 [ + + ]: 732 : if (strcmp(opt->defname, "modulus") == 0)
3203 : : {
3204 [ - + ]: 366 : if (n->modulus != -1)
2909 rhaas@postgresql.org 3205 [ # # ]:UBC 0 : ereport(ERROR,
3206 : : (errcode(ERRCODE_DUPLICATE_OBJECT),
3207 : : errmsg("modulus for hash partition provided more than once"),
3208 : : parser_errposition(opt->location)));
2909 rhaas@postgresql.org 3209 :CBC 366 : n->modulus = defGetInt32(opt);
3210 : : }
3211 [ + - ]: 366 : else if (strcmp(opt->defname, "remainder") == 0)
3212 : : {
3213 [ - + ]: 366 : if (n->remainder != -1)
2909 rhaas@postgresql.org 3214 [ # # ]:UBC 0 : ereport(ERROR,
3215 : : (errcode(ERRCODE_DUPLICATE_OBJECT),
3216 : : errmsg("remainder for hash partition provided more than once"),
3217 : : parser_errposition(opt->location)));
2909 rhaas@postgresql.org 3218 :CBC 366 : n->remainder = defGetInt32(opt);
3219 : : }
3220 : : else
2909 rhaas@postgresql.org 3221 [ # # ]:UBC 0 : ereport(ERROR,
3222 : : (errcode(ERRCODE_SYNTAX_ERROR),
3223 : : errmsg("unrecognized hash partition bound specification \"%s\"",
3224 : : opt->defname),
3225 : : parser_errposition(opt->location)));
3226 : : }
3227 : :
2909 rhaas@postgresql.org 3228 [ - + ]:CBC 366 : if (n->modulus == -1)
2909 rhaas@postgresql.org 3229 [ # # ]:UBC 0 : ereport(ERROR,
3230 : : (errcode(ERRCODE_SYNTAX_ERROR),
3231 : : errmsg("modulus for hash partition must be specified"),
3232 : : parser_errposition(@3)));
2909 rhaas@postgresql.org 3233 [ - + ]:CBC 366 : if (n->remainder == -1)
2909 rhaas@postgresql.org 3234 [ # # ]:UBC 0 : ereport(ERROR,
3235 : : (errcode(ERRCODE_SYNTAX_ERROR),
3236 : : errmsg("remainder for hash partition must be specified"),
3237 : : parser_errposition(@3)));
3238 : :
2909 rhaas@postgresql.org 3239 :CBC 366 : n->location = @3;
3240 : :
3241 : 366 : $$ = n;
3242 : : }
3243 : :
3244 : : /* a LIST partition */
3245 : : | FOR VALUES IN_P '(' expr_list ')'
3246 : : {
3246 3247 : 2503 : PartitionBoundSpec *n = makeNode(PartitionBoundSpec);
3248 : :
3249 : 2503 : n->strategy = PARTITION_STRATEGY_LIST;
2971 3250 : 2503 : n->is_default = false;
3246 3251 : 2503 : n->listdatums = $5;
3252 : 2503 : n->location = @3;
3253 : :
3074 tgl@sss.pgh.pa.us 3254 : 2503 : $$ = n;
3255 : : }
3256 : :
3257 : : /* a RANGE partition */
3258 : : | FOR VALUES FROM '(' expr_list ')' TO '(' expr_list ')'
3259 : : {
3246 rhaas@postgresql.org 3260 : 2161 : PartitionBoundSpec *n = makeNode(PartitionBoundSpec);
3261 : :
3262 : 2161 : n->strategy = PARTITION_STRATEGY_RANGE;
2971 3263 : 2161 : n->is_default = false;
3246 3264 : 2161 : n->lowerdatums = $5;
3265 : 2161 : n->upperdatums = $9;
3266 : 2161 : n->location = @3;
3267 : :
2971 3268 : 2161 : $$ = n;
3269 : : }
3270 : :
3271 : : /* a DEFAULT partition */
3272 : : | DEFAULT
3273 : : {
3274 : 299 : PartitionBoundSpec *n = makeNode(PartitionBoundSpec);
3275 : :
3276 : 299 : n->is_default = true;
3277 : 299 : n->location = @1;
3278 : :
3074 tgl@sss.pgh.pa.us 3279 : 299 : $$ = n;
3280 : : }
3281 : : ;
3282 : :
3283 : : hash_partbound_elem:
3284 : : NonReservedWord Iconst
3285 : : {
1263 peter@eisentraut.org 3286 : 732 : $$ = makeDefElem($1, (Node *) makeInteger($2), @1);
3287 : : }
3288 : : ;
3289 : :
3290 : : hash_partbound:
3291 : : hash_partbound_elem
3292 : : {
2909 rhaas@postgresql.org 3293 : 366 : $$ = list_make1($1);
3294 : : }
3295 : : | hash_partbound ',' hash_partbound_elem
3296 : : {
3297 : 366 : $$ = lappend($1, $3);
3298 : : }
3299 : : ;
3300 : :
3301 : : /*****************************************************************************
3302 : : *
3303 : : * ALTER TYPE
3304 : : *
3305 : : * really variants of the ALTER TABLE subcommands with different spellings
3306 : : *****************************************************************************/
3307 : :
3308 : : AlterCompositeTypeStmt:
3309 : : ALTER TYPE_P any_name alter_type_cmds
3310 : : {
5510 peter_e@gmx.net 3311 : 105 : AlterTableStmt *n = makeNode(AlterTableStmt);
3312 : :
3313 : : /* can't use qualified_name, sigh */
3314 : 105 : n->relation = makeRangeVarFromAnyName($3, @3, yyscanner);
3315 : 105 : n->cmds = $4;
1934 michael@paquier.xyz 3316 : 105 : n->objtype = OBJECT_TYPE;
1263 peter@eisentraut.org 3317 : 105 : $$ = (Node *) n;
3318 : : }
3319 : : ;
3320 : :
3321 : : alter_type_cmds:
5510 peter_e@gmx.net 3322 : 105 : alter_type_cmd { $$ = list_make1($1); }
3323 : 6 : | alter_type_cmds ',' alter_type_cmd { $$ = lappend($1, $3); }
3324 : : ;
3325 : :
3326 : : alter_type_cmd:
3327 : : /* ALTER TYPE <name> ADD ATTRIBUTE <coldef> [RESTRICT|CASCADE] */
3328 : : ADD_P ATTRIBUTE TableFuncElement opt_drop_behavior
3329 : : {
3330 : 32 : AlterTableCmd *n = makeNode(AlterTableCmd);
3331 : :
3332 : 32 : n->subtype = AT_AddColumn;
3333 : 32 : n->def = $3;
5452 3334 : 32 : n->behavior = $4;
1263 peter@eisentraut.org 3335 : 32 : $$ = (Node *) n;
3336 : : }
3337 : : /* ALTER TYPE <name> DROP ATTRIBUTE IF EXISTS <attname> [RESTRICT|CASCADE] */
3338 : : | DROP ATTRIBUTE IF_P EXISTS ColId opt_drop_behavior
3339 : : {
5510 peter_e@gmx.net 3340 : 3 : AlterTableCmd *n = makeNode(AlterTableCmd);
3341 : :
3342 : 3 : n->subtype = AT_DropColumn;
3343 : 3 : n->name = $5;
5452 3344 : 3 : n->behavior = $6;
2994 3345 : 3 : n->missing_ok = true;
1263 peter@eisentraut.org 3346 : 3 : $$ = (Node *) n;
3347 : : }
3348 : : /* ALTER TYPE <name> DROP ATTRIBUTE <attname> [RESTRICT|CASCADE] */
3349 : : | DROP ATTRIBUTE ColId opt_drop_behavior
3350 : : {
5510 peter_e@gmx.net 3351 : 39 : AlterTableCmd *n = makeNode(AlterTableCmd);
3352 : :
3353 : 39 : n->subtype = AT_DropColumn;
3354 : 39 : n->name = $3;
5452 3355 : 39 : n->behavior = $4;
2994 3356 : 39 : n->missing_ok = false;
1263 peter@eisentraut.org 3357 : 39 : $$ = (Node *) n;
3358 : : }
3359 : : /* ALTER TYPE <name> ALTER ATTRIBUTE <attname> [SET DATA] TYPE <typename> [RESTRICT|CASCADE] */
3360 : : | ALTER ATTRIBUTE ColId opt_set_data TYPE_P Typename opt_collate_clause opt_drop_behavior
3361 : : {
5510 peter_e@gmx.net 3362 : 37 : AlterTableCmd *n = makeNode(AlterTableCmd);
5346 tgl@sss.pgh.pa.us 3363 : 37 : ColumnDef *def = makeNode(ColumnDef);
3364 : :
5510 peter_e@gmx.net 3365 : 37 : n->subtype = AT_AlterColumnType;
3366 : 37 : n->name = $3;
5346 tgl@sss.pgh.pa.us 3367 : 37 : n->def = (Node *) def;
3368 : 37 : n->behavior = $8;
3369 : : /* We only use these fields of the ColumnDef node */
3370 : 37 : def->typeName = $6;
3371 : 37 : def->collClause = (CollateClause *) $7;
3372 : 37 : def->raw_default = NULL;
4358 3373 : 37 : def->location = @3;
1263 peter@eisentraut.org 3374 : 37 : $$ = (Node *) n;
3375 : : }
3376 : : ;
3377 : :
3378 : :
3379 : : /*****************************************************************************
3380 : : *
3381 : : * QUERY :
3382 : : * close <portalname>
3383 : : *
3384 : : *****************************************************************************/
3385 : :
3386 : : ClosePortalStmt:
3387 : : CLOSE cursor_name
3388 : : {
10276 bruce@momjian.us 3389 : 1078 : ClosePortalStmt *n = makeNode(ClosePortalStmt);
3390 : :
3391 : 1078 : n->portalname = $2;
1263 peter@eisentraut.org 3392 : 1078 : $$ = (Node *) n;
3393 : : }
3394 : : | CLOSE ALL
3395 : : {
6773 neilc@samurai.com 3396 : 6 : ClosePortalStmt *n = makeNode(ClosePortalStmt);
3397 : :
3398 : 6 : n->portalname = NULL;
1263 peter@eisentraut.org 3399 : 6 : $$ = (Node *) n;
3400 : : }
3401 : : ;
3402 : :
3403 : :
3404 : : /*****************************************************************************
3405 : : *
3406 : : * QUERY :
3407 : : * COPY relname [(columnList)] FROM/TO file [WITH] [(options)]
3408 : : * COPY ( query ) TO file [WITH] [(options)]
3409 : : *
3410 : : * where 'query' can be one of:
3411 : : * { SELECT | UPDATE | INSERT | DELETE }
3412 : : *
3413 : : * and 'file' can be one of:
3414 : : * { PROGRAM 'command' | STDIN | STDOUT | 'filename' }
3415 : : *
3416 : : * In the preferred syntax the options are comma-separated
3417 : : * and use generic identifiers instead of keywords. The pre-9.0
3418 : : * syntax had a hard-wired, space-separated set of options.
3419 : : *
3420 : : * Really old syntax, from versions 7.2 and prior:
3421 : : * COPY [ BINARY ] table FROM/TO file
3422 : : * [ [ USING ] DELIMITERS 'delimiter' ] ]
3423 : : * [ WITH NULL AS 'null string' ]
3424 : : * This option placement is not supported with COPY (query...).
3425 : : *
3426 : : *****************************************************************************/
3427 : :
3428 : : CopyStmt: COPY opt_binary qualified_name opt_column_list
3429 : : copy_from opt_program copy_file_name copy_delimiter opt_with
3430 : : copy_options where_clause
3431 : : {
10276 bruce@momjian.us 3432 : 5377 : CopyStmt *n = makeNode(CopyStmt);
3433 : :
8621 tgl@sss.pgh.pa.us 3434 : 5377 : n->relation = $3;
6998 3435 : 5377 : n->query = NULL;
8502 bruce@momjian.us 3436 : 5377 : n->attlist = $4;
2533 andres@anarazel.de 3437 : 5377 : n->is_from = $5;
3438 : 5377 : n->is_program = $6;
3439 : 5377 : n->filename = $7;
2473 tomas.vondra@postgre 3440 : 5377 : n->whereClause = $11;
3441 : :
4625 heikki.linnakangas@i 3442 [ - + - - ]: 5377 : if (n->is_program && n->filename == NULL)
4625 heikki.linnakangas@i 3443 [ # # ]:UBC 0 : ereport(ERROR,
3444 : : (errcode(ERRCODE_SYNTAX_ERROR),
3445 : : errmsg("STDIN/STDOUT not allowed with PROGRAM"),
3446 : : parser_errposition(@8)));
3447 : :
2473 tomas.vondra@postgre 3448 [ + + + + ]:CBC 5377 : if (!n->is_from && n->whereClause != NULL)
3449 [ + - ]: 3 : ereport(ERROR,
3450 : : (errcode(ERRCODE_SYNTAX_ERROR),
3451 : : errmsg("WHERE clause not allowed with COPY TO"),
3452 : : errhint("Try the COPY (SELECT ... WHERE ...) TO variant."),
3453 : : parser_errposition(@11)));
3454 : :
8530 bruce@momjian.us 3455 : 5374 : n->options = NIL;
3456 : : /* Concatenate user-supplied flags */
3457 [ + + ]: 5374 : if ($2)
3458 : 6 : n->options = lappend(n->options, $2);
2533 andres@anarazel.de 3459 [ - + ]: 5374 : if ($8)
2533 andres@anarazel.de 3460 :UBC 0 : n->options = lappend(n->options, $8);
2533 andres@anarazel.de 3461 [ + + ]:CBC 5374 : if ($10)
3462 : 513 : n->options = list_concat(n->options, $10);
1263 peter@eisentraut.org 3463 : 5374 : $$ = (Node *) n;
3464 : : }
3465 : : | COPY '(' PreparableStmt ')' TO opt_program copy_file_name opt_with copy_options
3466 : : {
6998 tgl@sss.pgh.pa.us 3467 : 304 : CopyStmt *n = makeNode(CopyStmt);
3468 : :
3469 : 304 : n->relation = NULL;
3622 teodor@sigaev.ru 3470 : 304 : n->query = $3;
6998 tgl@sss.pgh.pa.us 3471 : 304 : n->attlist = NIL;
3472 : 304 : n->is_from = false;
3622 teodor@sigaev.ru 3473 : 304 : n->is_program = $6;
3474 : 304 : n->filename = $7;
3475 : 304 : n->options = $9;
3476 : :
4625 heikki.linnakangas@i 3477 [ - + - - ]: 304 : if (n->is_program && n->filename == NULL)
4625 heikki.linnakangas@i 3478 [ # # ]:UBC 0 : ereport(ERROR,
3479 : : (errcode(ERRCODE_SYNTAX_ERROR),
3480 : : errmsg("STDIN/STDOUT not allowed with PROGRAM"),
3481 : : parser_errposition(@5)));
3482 : :
1263 peter@eisentraut.org 3483 :CBC 304 : $$ = (Node *) n;
3484 : : }
3485 : : ;
3486 : :
3487 : : copy_from:
2994 peter_e@gmx.net 3488 : 948 : FROM { $$ = true; }
3489 : 4429 : | TO { $$ = false; }
3490 : : ;
3491 : :
3492 : : opt_program:
2994 peter_e@gmx.net 3493 :UBC 0 : PROGRAM { $$ = true; }
2994 peter_e@gmx.net 3494 :CBC 5681 : | /* EMPTY */ { $$ = false; }
3495 : : ;
3496 : :
3497 : : /*
3498 : : * copy_file_name NULL indicates stdio is used. Whether stdin or stdout is
3499 : : * used depends on the direction. (It really doesn't make sense to copy from
3500 : : * stdout. We silently correct the "typo".) - AY 9/94
3501 : : */
3502 : : copy_file_name:
8533 bruce@momjian.us 3503 : 244 : Sconst { $$ = $1; }
3504 : 736 : | STDIN { $$ = NULL; }
3505 : 4701 : | STDOUT { $$ = NULL; }
3506 : : ;
3507 : :
5880 tgl@sss.pgh.pa.us 3508 : 5320 : copy_options: copy_opt_list { $$ = $1; }
3509 : 361 : | '(' copy_generic_opt_list ')' { $$ = $2; }
3510 : : ;
3511 : :
3512 : : /* old COPY option syntax */
3513 : : copy_opt_list:
8530 bruce@momjian.us 3514 : 269 : copy_opt_list copy_opt_item { $$ = lappend($1, $2); }
3515 : 5320 : | /* EMPTY */ { $$ = NIL; }
3516 : : ;
3517 : :
3518 : : copy_opt_item:
3519 : : BINARY
3520 : : {
1263 peter@eisentraut.org 3521 :UBC 0 : $$ = makeDefElem("format", (Node *) makeString("binary"), @1);
3522 : : }
3523 : : | FREEZE
3524 : : {
1263 peter@eisentraut.org 3525 :CBC 25 : $$ = makeDefElem("freeze", (Node *) makeBoolean(true), @1);
3526 : : }
3527 : : | DELIMITER opt_as Sconst
3528 : : {
3529 : 103 : $$ = makeDefElem("delimiter", (Node *) makeString($3), @1);
3530 : : }
3531 : : | NULL_P opt_as Sconst
3532 : : {
3533 : 24 : $$ = makeDefElem("null", (Node *) makeString($3), @1);
3534 : : }
3535 : : | CSV
3536 : : {
3537 : 75 : $$ = makeDefElem("format", (Node *) makeString("csv"), @1);
3538 : : }
3539 : : | HEADER_P
3540 : : {
3541 : 9 : $$ = makeDefElem("header", (Node *) makeBoolean(true), @1);
3542 : : }
3543 : : | QUOTE opt_as Sconst
3544 : : {
3545 : 9 : $$ = makeDefElem("quote", (Node *) makeString($3), @1);
3546 : : }
3547 : : | ESCAPE opt_as Sconst
3548 : : {
3549 : 9 : $$ = makeDefElem("escape", (Node *) makeString($3), @1);
3550 : : }
3551 : : | FORCE QUOTE columnList
3552 : : {
3553 : 6 : $$ = makeDefElem("force_quote", (Node *) $3, @1);
3554 : : }
3555 : : | FORCE QUOTE '*'
3556 : : {
3557 : 3 : $$ = makeDefElem("force_quote", (Node *) makeNode(A_Star), @1);
3558 : : }
3559 : : | FORCE NOT NULL_P columnList
3560 : : {
1263 peter@eisentraut.org 3561 :UBC 0 : $$ = makeDefElem("force_not_null", (Node *) $4, @1);
3562 : : }
3563 : : | FORCE NOT NULL_P '*'
3564 : : {
758 andrew@dunslane.net 3565 : 0 : $$ = makeDefElem("force_not_null", (Node *) makeNode(A_Star), @1);
3566 : : }
3567 : : | FORCE NULL_P columnList
3568 : : {
1263 peter@eisentraut.org 3569 : 0 : $$ = makeDefElem("force_null", (Node *) $3, @1);
3570 : : }
3571 : : | FORCE NULL_P '*'
3572 : : {
758 andrew@dunslane.net 3573 : 0 : $$ = makeDefElem("force_null", (Node *) makeNode(A_Star), @1);
3574 : : }
3575 : : | ENCODING Sconst
3576 : : {
1263 peter@eisentraut.org 3577 :CBC 6 : $$ = makeDefElem("encoding", (Node *) makeString($2), @1);
3578 : : }
3579 : : ;
3580 : :
3581 : : /* The following exist for backward compatibility with very old versions */
3582 : :
3583 : : opt_binary:
3584 : : BINARY
3585 : : {
3586 : 6 : $$ = makeDefElem("format", (Node *) makeString("binary"), @1);
3587 : : }
8530 bruce@momjian.us 3588 : 5371 : | /*EMPTY*/ { $$ = NULL; }
3589 : : ;
3590 : :
3591 : : copy_delimiter:
3592 : : opt_using DELIMITERS Sconst
3593 : : {
1263 peter@eisentraut.org 3594 :UBC 0 : $$ = makeDefElem("delimiter", (Node *) makeString($3), @2);
3595 : : }
8530 bruce@momjian.us 3596 :CBC 5377 : | /*EMPTY*/ { $$ = NULL; }
3597 : : ;
3598 : :
3599 : : opt_using:
3600 : : USING
3601 : : | /*EMPTY*/
3602 : : ;
3603 : :
3604 : : /* new COPY option syntax */
3605 : : copy_generic_opt_list:
3606 : : copy_generic_opt_elem
3607 : : {
5880 tgl@sss.pgh.pa.us 3608 : 361 : $$ = list_make1($1);
3609 : : }
3610 : : | copy_generic_opt_list ',' copy_generic_opt_elem
3611 : : {
3612 : 234 : $$ = lappend($1, $3);
3613 : : }
3614 : : ;
3615 : :
3616 : : copy_generic_opt_elem:
3617 : : ColLabel copy_generic_opt_arg
3618 : : {
3338 peter_e@gmx.net 3619 : 595 : $$ = makeDefElem($1, $2, @1);
3620 : : }
3621 : : ;
3622 : :
3623 : : copy_generic_opt_arg:
5484 heikki.linnakangas@i 3624 : 418 : opt_boolean_or_string { $$ = (Node *) makeString($1); }
5880 tgl@sss.pgh.pa.us 3625 : 30 : | NumericOnly { $$ = (Node *) $1; }
3626 : 45 : | '*' { $$ = (Node *) makeNode(A_Star); }
574 msawada@postgresql.o 3627 : 3 : | DEFAULT { $$ = (Node *) makeString("default"); }
5880 tgl@sss.pgh.pa.us 3628 : 75 : | '(' copy_generic_opt_arg_list ')' { $$ = (Node *) $2; }
3629 : 24 : | /* EMPTY */ { $$ = NULL; }
3630 : : ;
3631 : :
3632 : : copy_generic_opt_arg_list:
3633 : : copy_generic_opt_arg_list_item
3634 : : {
3635 : 75 : $$ = list_make1($1);
3636 : : }
3637 : : | copy_generic_opt_arg_list ',' copy_generic_opt_arg_list_item
3638 : : {
3639 : 6 : $$ = lappend($1, $3);
3640 : : }
3641 : : ;
3642 : :
3643 : : /* beware of emitting non-string list elements here; see commands/define.c */
3644 : : copy_generic_opt_arg_list_item:
5484 heikki.linnakangas@i 3645 : 81 : opt_boolean_or_string { $$ = (Node *) makeString($1); }
3646 : : ;
3647 : :
3648 : :
3649 : : /*****************************************************************************
3650 : : *
3651 : : * QUERY :
3652 : : * CREATE TABLE relname
3653 : : *
3654 : : *****************************************************************************/
3655 : :
3656 : : CreateStmt: CREATE OptTemp TABLE qualified_name '(' OptTableElementList ')'
3657 : : OptInherit OptPartitionSpec table_access_method_clause OptWith
3658 : : OnCommitOption OptTableSpace
3659 : : {
10276 bruce@momjian.us 3660 : 14963 : CreateStmt *n = makeNode(CreateStmt);
3661 : :
5432 rhaas@postgresql.org 3662 : 14963 : $4->relpersistence = $2;
8621 tgl@sss.pgh.pa.us 3663 : 14963 : n->relation = $4;
9061 3664 : 14963 : n->tableElts = $6;
8621 3665 : 14963 : n->inhRelations = $8;
3246 rhaas@postgresql.org 3666 : 14963 : n->partspec = $9;
3872 tgl@sss.pgh.pa.us 3667 : 14963 : n->ofTypename = NULL;
10189 lockhart@fourpalms.o 3668 : 14963 : n->constraints = NIL;
2427 andres@anarazel.de 3669 : 14963 : n->accessMethod = $10;
3670 : 14963 : n->options = $11;
3671 : 14963 : n->oncommit = $12;
3672 : 14963 : n->tablespacename = $13;
5573 rhaas@postgresql.org 3673 : 14963 : n->if_not_exists = false;
1263 peter@eisentraut.org 3674 : 14963 : $$ = (Node *) n;
3675 : : }
3676 : : | CREATE OptTemp TABLE IF_P NOT EXISTS qualified_name '('
3677 : : OptTableElementList ')' OptInherit OptPartitionSpec table_access_method_clause
3678 : : OptWith OnCommitOption OptTableSpace
3679 : : {
5573 rhaas@postgresql.org 3680 : 14 : CreateStmt *n = makeNode(CreateStmt);
3681 : :
5432 3682 : 14 : $7->relpersistence = $2;
5573 3683 : 14 : n->relation = $7;
3684 : 14 : n->tableElts = $9;
3685 : 14 : n->inhRelations = $11;
3246 3686 : 14 : n->partspec = $12;
3872 tgl@sss.pgh.pa.us 3687 : 14 : n->ofTypename = NULL;
5573 rhaas@postgresql.org 3688 : 14 : n->constraints = NIL;
2427 andres@anarazel.de 3689 : 14 : n->accessMethod = $13;
3690 : 14 : n->options = $14;
3691 : 14 : n->oncommit = $15;
3692 : 14 : n->tablespacename = $16;
5573 rhaas@postgresql.org 3693 : 14 : n->if_not_exists = true;
1263 peter@eisentraut.org 3694 : 14 : $$ = (Node *) n;
3695 : : }
3696 : : | CREATE OptTemp TABLE qualified_name OF any_name
3697 : : OptTypedTableElementList OptPartitionSpec table_access_method_clause
3698 : : OptWith OnCommitOption OptTableSpace
3699 : : {
8485 lockhart@fourpalms.o 3700 : 61 : CreateStmt *n = makeNode(CreateStmt);
3701 : :
5432 rhaas@postgresql.org 3702 : 61 : $4->relpersistence = $2;
8485 lockhart@fourpalms.o 3703 : 61 : n->relation = $4;
5751 peter_e@gmx.net 3704 : 61 : n->tableElts = $7;
3872 tgl@sss.pgh.pa.us 3705 : 61 : n->inhRelations = NIL;
3246 rhaas@postgresql.org 3706 : 61 : n->partspec = $8;
5751 peter_e@gmx.net 3707 : 61 : n->ofTypename = makeTypeNameFromNameList($6);
3708 : 61 : n->ofTypename->location = @6;
8485 lockhart@fourpalms.o 3709 : 61 : n->constraints = NIL;
2427 andres@anarazel.de 3710 : 61 : n->accessMethod = $9;
3711 : 61 : n->options = $10;
3712 : 61 : n->oncommit = $11;
3713 : 61 : n->tablespacename = $12;
5573 rhaas@postgresql.org 3714 : 61 : n->if_not_exists = false;
1263 peter@eisentraut.org 3715 : 61 : $$ = (Node *) n;
3716 : : }
3717 : : | CREATE OptTemp TABLE IF_P NOT EXISTS qualified_name OF any_name
3718 : : OptTypedTableElementList OptPartitionSpec table_access_method_clause
3719 : : OptWith OnCommitOption OptTableSpace
3720 : : {
5573 rhaas@postgresql.org 3721 : 3 : CreateStmt *n = makeNode(CreateStmt);
3722 : :
5432 3723 : 3 : $7->relpersistence = $2;
5573 3724 : 3 : n->relation = $7;
3725 : 3 : n->tableElts = $10;
3872 tgl@sss.pgh.pa.us 3726 : 3 : n->inhRelations = NIL;
3246 rhaas@postgresql.org 3727 : 3 : n->partspec = $11;
5573 3728 : 3 : n->ofTypename = makeTypeNameFromNameList($9);
3729 : 3 : n->ofTypename->location = @9;
3730 : 3 : n->constraints = NIL;
2427 andres@anarazel.de 3731 : 3 : n->accessMethod = $12;
3732 : 3 : n->options = $13;
3733 : 3 : n->oncommit = $14;
3734 : 3 : n->tablespacename = $15;
3246 rhaas@postgresql.org 3735 : 3 : n->if_not_exists = true;
1263 peter@eisentraut.org 3736 : 3 : $$ = (Node *) n;
3737 : : }
3738 : : | CREATE OptTemp TABLE qualified_name PARTITION OF qualified_name
3739 : : OptTypedTableElementList PartitionBoundSpec OptPartitionSpec
3740 : : table_access_method_clause OptWith OnCommitOption OptTableSpace
3741 : : {
3246 rhaas@postgresql.org 3742 : 4063 : CreateStmt *n = makeNode(CreateStmt);
3743 : :
3744 : 4063 : $4->relpersistence = $2;
3745 : 4063 : n->relation = $4;
3746 : 4063 : n->tableElts = $8;
3747 : 4063 : n->inhRelations = list_make1($7);
3074 tgl@sss.pgh.pa.us 3748 : 4063 : n->partbound = $9;
3246 rhaas@postgresql.org 3749 : 4063 : n->partspec = $10;
3750 : 4063 : n->ofTypename = NULL;
3751 : 4063 : n->constraints = NIL;
2427 andres@anarazel.de 3752 : 4063 : n->accessMethod = $11;
3753 : 4063 : n->options = $12;
3754 : 4063 : n->oncommit = $13;
3755 : 4063 : n->tablespacename = $14;
3246 rhaas@postgresql.org 3756 : 4063 : n->if_not_exists = false;
1263 peter@eisentraut.org 3757 : 4063 : $$ = (Node *) n;
3758 : : }
3759 : : | CREATE OptTemp TABLE IF_P NOT EXISTS qualified_name PARTITION OF
3760 : : qualified_name OptTypedTableElementList PartitionBoundSpec OptPartitionSpec
3761 : : table_access_method_clause OptWith OnCommitOption OptTableSpace
3762 : : {
3246 rhaas@postgresql.org 3763 :UBC 0 : CreateStmt *n = makeNode(CreateStmt);
3764 : :
3765 : 0 : $7->relpersistence = $2;
3766 : 0 : n->relation = $7;
3767 : 0 : n->tableElts = $11;
3768 : 0 : n->inhRelations = list_make1($10);
3074 tgl@sss.pgh.pa.us 3769 : 0 : n->partbound = $12;
3246 rhaas@postgresql.org 3770 : 0 : n->partspec = $13;
3771 : 0 : n->ofTypename = NULL;
3772 : 0 : n->constraints = NIL;
2427 andres@anarazel.de 3773 : 0 : n->accessMethod = $14;
3774 : 0 : n->options = $15;
3775 : 0 : n->oncommit = $16;
3776 : 0 : n->tablespacename = $17;
5573 rhaas@postgresql.org 3777 : 0 : n->if_not_exists = true;
1263 peter@eisentraut.org 3778 : 0 : $$ = (Node *) n;
3779 : : }
3780 : : ;
3781 : :
3782 : : /*
3783 : : * Redundancy here is needed to avoid shift/reduce conflicts,
3784 : : * since TEMP is not a reserved word. See also OptTempTableName.
3785 : : *
3786 : : * NOTE: we accept both GLOBAL and LOCAL options. They currently do nothing,
3787 : : * but future versions might consider GLOBAL to request SQL-spec-compliant
3788 : : * temp table behavior, so warn about that. Since we have no modules the
3789 : : * LOCAL keyword is really meaningless; furthermore, some other products
3790 : : * implement LOCAL as meaning the same as our default temp table behavior,
3791 : : * so we'll probably continue to treat LOCAL as a noise word.
3792 : : */
5432 rhaas@postgresql.org 3793 :CBC 182 : OptTemp: TEMPORARY { $$ = RELPERSISTENCE_TEMP; }
3794 : 1398 : | TEMP { $$ = RELPERSISTENCE_TEMP; }
4887 simon@2ndQuadrant.co 3795 :UBC 0 : | LOCAL TEMPORARY { $$ = RELPERSISTENCE_TEMP; }
3796 : 0 : | LOCAL TEMP { $$ = RELPERSISTENCE_TEMP; }
3797 : : | GLOBAL TEMPORARY
3798 : : {
4884 tgl@sss.pgh.pa.us 3799 [ # # ]: 0 : ereport(WARNING,
3800 : : (errmsg("GLOBAL is deprecated in temporary table creation"),
3801 : : parser_errposition(@1)));
3802 : 0 : $$ = RELPERSISTENCE_TEMP;
3803 : : }
3804 : : | GLOBAL TEMP
3805 : : {
3806 [ # # ]: 0 : ereport(WARNING,
3807 : : (errmsg("GLOBAL is deprecated in temporary table creation"),
3808 : : parser_errposition(@1)));
3809 : 0 : $$ = RELPERSISTENCE_TEMP;
3810 : : }
5416 rhaas@postgresql.org 3811 :CBC 84 : | UNLOGGED { $$ = RELPERSISTENCE_UNLOGGED; }
5432 3812 : 27069 : | /*EMPTY*/ { $$ = RELPERSISTENCE_PERMANENT; }
3813 : : ;
3814 : :
3815 : : OptTableElementList:
8484 tgl@sss.pgh.pa.us 3816 : 14373 : TableElementList { $$ = $1; }
3817 : 827 : | /*EMPTY*/ { $$ = NIL; }
3818 : : ;
3819 : :
3820 : : OptTypedTableElementList:
5751 peter_e@gmx.net 3821 : 177 : '(' TypedTableElementList ')' { $$ = $2; }
3822 : 3998 : | /*EMPTY*/ { $$ = NIL; }
3823 : : ;
3824 : :
3825 : : TableElementList:
3826 : : TableElement
3827 : : {
7820 neilc@samurai.com 3828 : 14400 : $$ = list_make1($1);
3829 : : }
3830 : : | TableElementList ',' TableElement
3831 : : {
8460 tgl@sss.pgh.pa.us 3832 : 20339 : $$ = lappend($1, $3);
3833 : : }
3834 : : ;
3835 : :
3836 : : TypedTableElementList:
3837 : : TypedTableElement
3838 : : {
5751 peter_e@gmx.net 3839 : 177 : $$ = list_make1($1);
3840 : : }
3841 : : | TypedTableElementList ',' TypedTableElement
3842 : : {
3843 : 34 : $$ = lappend($1, $3);
3844 : : }
3845 : : ;
3846 : :
3847 : : TableElement:
8533 bruce@momjian.us 3848 : 32969 : columnDef { $$ = $1; }
8528 lockhart@fourpalms.o 3849 : 387 : | TableLikeClause { $$ = $1; }
10189 3850 : 1383 : | TableConstraint { $$ = $1; }
3851 : : ;
3852 : :
3853 : : TypedTableElement:
5751 peter_e@gmx.net 3854 : 179 : columnOptions { $$ = $1; }
3855 : 32 : | TableConstraint { $$ = $1; }
3856 : : ;
3857 : :
3858 : : columnDef: ColId Typename opt_column_storage opt_column_compression create_generic_options ColQualList
3859 : : {
10189 lockhart@fourpalms.o 3860 : 34055 : ColumnDef *n = makeNode(ColumnDef);
3861 : :
3862 : 34055 : n->colname = $1;
5947 peter_e@gmx.net 3863 : 34055 : n->typeName = $2;
1202 peter@eisentraut.org 3864 : 34055 : n->storage_name = $3;
3865 : 34055 : n->compression = $4;
5346 tgl@sss.pgh.pa.us 3866 : 34055 : n->inhcount = 0;
8436 3867 : 34055 : n->is_local = true;
5346 3868 : 34055 : n->is_not_null = false;
3869 : 34055 : n->is_from_type = false;
615 peter@eisentraut.org 3870 : 34055 : n->storage = 0;
5346 tgl@sss.pgh.pa.us 3871 : 34055 : n->raw_default = NULL;
3872 : 34055 : n->cooked_default = NULL;
3873 : 34055 : n->collOid = InvalidOid;
1202 peter@eisentraut.org 3874 : 34055 : n->fdwoptions = $5;
3875 : 34055 : SplitColQualList($6, &n->constraints, &n->collClause,
3876 : : yyscanner);
4358 tgl@sss.pgh.pa.us 3877 : 34055 : n->location = @1;
1263 peter@eisentraut.org 3878 : 34055 : $$ = (Node *) n;
3879 : : }
3880 : : ;
3881 : :
3882 : : columnOptions: ColId ColQualList
3883 : : {
3105 sfrost@snowman.net 3884 : 69 : ColumnDef *n = makeNode(ColumnDef);
3885 : :
3886 : 69 : n->colname = $1;
3887 : 69 : n->typeName = NULL;
3888 : 69 : n->inhcount = 0;
3889 : 69 : n->is_local = true;
3890 : 69 : n->is_not_null = false;
3891 : 69 : n->is_from_type = false;
615 peter@eisentraut.org 3892 : 69 : n->storage = 0;
3105 sfrost@snowman.net 3893 : 69 : n->raw_default = NULL;
3894 : 69 : n->cooked_default = NULL;
3895 : 69 : n->collOid = InvalidOid;
3896 : 69 : SplitColQualList($2, &n->constraints, &n->collClause,
3897 : : yyscanner);
3898 : 69 : n->location = @1;
1263 peter@eisentraut.org 3899 : 69 : $$ = (Node *) n;
3900 : : }
3901 : : | ColId WITH OPTIONS ColQualList
3902 : : {
5751 peter_e@gmx.net 3903 : 110 : ColumnDef *n = makeNode(ColumnDef);
3904 : :
3905 : 110 : n->colname = $1;
5346 tgl@sss.pgh.pa.us 3906 : 110 : n->typeName = NULL;
3907 : 110 : n->inhcount = 0;
5751 peter_e@gmx.net 3908 : 110 : n->is_local = true;
5346 tgl@sss.pgh.pa.us 3909 : 110 : n->is_not_null = false;
3910 : 110 : n->is_from_type = false;
615 peter@eisentraut.org 3911 : 110 : n->storage = 0;
5346 tgl@sss.pgh.pa.us 3912 : 110 : n->raw_default = NULL;
3913 : 110 : n->cooked_default = NULL;
3914 : 110 : n->collOid = InvalidOid;
3915 : 110 : SplitColQualList($4, &n->constraints, &n->collClause,
3916 : : yyscanner);
4358 3917 : 110 : n->location = @1;
1263 peter@eisentraut.org 3918 : 110 : $$ = (Node *) n;
3919 : : }
3920 : : ;
3921 : :
3922 : : column_compression:
1614 tgl@sss.pgh.pa.us 3923 : 83 : COMPRESSION ColId { $$ = $2; }
3924 : 3 : | COMPRESSION DEFAULT { $$ = pstrdup("default"); }
3925 : : ;
3926 : :
3927 : : opt_column_compression:
3928 : 47 : column_compression { $$ = $1; }
3929 : 34041 : | /*EMPTY*/ { $$ = NULL; }
3930 : : ;
3931 : :
3932 : : column_storage:
1202 peter@eisentraut.org 3933 : 129 : STORAGE ColId { $$ = $2; }
1082 tgl@sss.pgh.pa.us 3934 : 3 : | STORAGE DEFAULT { $$ = pstrdup("default"); }
3935 : : ;
3936 : :
3937 : : opt_column_storage:
1202 peter@eisentraut.org 3938 : 13 : column_storage { $$ = $1; }
3939 : 34075 : | /*EMPTY*/ { $$ = NULL; }
3940 : : ;
3941 : :
3942 : : ColQualList:
8533 bruce@momjian.us 3943 : 10110 : ColQualList ColConstraint { $$ = lappend($1, $2); }
3944 : 34999 : | /*EMPTY*/ { $$ = NIL; }
3945 : : ;
3946 : :
3947 : : ColConstraint:
3948 : : CONSTRAINT name ColConstraintElem
3949 : : {
3170 peter_e@gmx.net 3950 : 401 : Constraint *n = castNode(Constraint, $3);
3951 : :
5933 tgl@sss.pgh.pa.us 3952 : 401 : n->conname = $2;
3953 : 401 : n->location = @1;
3954 : 401 : $$ = (Node *) n;
3955 : : }
8533 bruce@momjian.us 3956 : 9175 : | ColConstraintElem { $$ = $1; }
3957 : 147 : | ConstraintAttr { $$ = $1; }
3958 : : | COLLATE any_name
3959 : : {
3960 : : /*
3961 : : * Note: the CollateClause is momentarily included in
3962 : : * the list built by ColQualList, but we split it out
3963 : : * again in SplitColQualList.
3964 : : */
5346 tgl@sss.pgh.pa.us 3965 : 387 : CollateClause *n = makeNode(CollateClause);
3966 : :
3967 : 387 : n->arg = NULL;
5344 3968 : 387 : n->collname = $2;
5346 3969 : 387 : n->location = @1;
3970 : 387 : $$ = (Node *) n;
3971 : : }
3972 : : ;
3973 : :
3974 : : /* DEFAULT NULL is already the default for Postgres.
3975 : : * But define it here and carry it forward into the system
3976 : : * to make it explicit.
3977 : : * - thomas 1998-09-13
3978 : : *
3979 : : * WITH NULL and NULL are not SQL-standard syntax elements,
3980 : : * so leave them out. Use DEFAULT NULL to explicitly indicate
3981 : : * that a column may have that value. WITH NULL leads to
3982 : : * shift/reduce conflicts with WITH TIME ZONE anyway.
3983 : : * - thomas 1999-01-08
3984 : : *
3985 : : * DEFAULT expression must be b_expr not a_expr to prevent shift/reduce
3986 : : * conflict on NOT (since NOT might start a subsequent NOT NULL constraint,
3987 : : * or be part of a_expr NOT LIKE or similar constructs).
3988 : : */
3989 : : ColConstraintElem:
3990 : : NOT NULL_P opt_no_inherit
3991 : : {
9371 3992 : 3457 : Constraint *n = makeNode(Constraint);
3993 : :
3994 : 3457 : n->contype = CONSTR_NOTNULL;
5933 3995 : 3457 : n->location = @1;
353 alvherre@alvh.no-ip. 3996 : 3457 : n->is_no_inherit = $3;
289 peter@eisentraut.org 3997 : 3457 : n->is_enforced = true;
353 alvherre@alvh.no-ip. 3998 : 3457 : n->skip_validation = false;
3999 : 3457 : n->initially_valid = true;
1263 peter@eisentraut.org 4000 : 3457 : $$ = (Node *) n;
4001 : : }
4002 : : | NULL_P
4003 : : {
9371 tgl@sss.pgh.pa.us 4004 : 14 : Constraint *n = makeNode(Constraint);
4005 : :
4006 : 14 : n->contype = CONSTR_NULL;
5933 4007 : 14 : n->location = @1;
1263 peter@eisentraut.org 4008 : 14 : $$ = (Node *) n;
4009 : : }
4010 : : | UNIQUE opt_unique_null_treatment opt_definition OptConsTableSpace
4011 : : {
9903 lockhart@fourpalms.o 4012 : 232 : Constraint *n = makeNode(Constraint);
4013 : :
9386 4014 : 232 : n->contype = CONSTR_UNIQUE;
5933 tgl@sss.pgh.pa.us 4015 : 232 : n->location = @1;
1362 peter@eisentraut.org 4016 : 232 : n->nulls_not_distinct = !$2;
9903 lockhart@fourpalms.o 4017 : 232 : n->keys = NULL;
1362 peter@eisentraut.org 4018 : 232 : n->options = $3;
5389 tgl@sss.pgh.pa.us 4019 : 232 : n->indexname = NULL;
1362 peter@eisentraut.org 4020 : 232 : n->indexspace = $4;
1263 4021 : 232 : $$ = (Node *) n;
4022 : : }
4023 : : | PRIMARY KEY opt_definition OptConsTableSpace
4024 : : {
9371 tgl@sss.pgh.pa.us 4025 : 2955 : Constraint *n = makeNode(Constraint);
4026 : :
4027 : 2955 : n->contype = CONSTR_PRIMARY;
5933 4028 : 2955 : n->location = @1;
9371 4029 : 2955 : n->keys = NULL;
7057 bruce@momjian.us 4030 : 2955 : n->options = $3;
5389 tgl@sss.pgh.pa.us 4031 : 2955 : n->indexname = NULL;
7057 bruce@momjian.us 4032 : 2955 : n->indexspace = $4;
1263 peter@eisentraut.org 4033 : 2955 : $$ = (Node *) n;
4034 : : }
4035 : : | CHECK '(' a_expr ')' opt_no_inherit
4036 : : {
10189 lockhart@fourpalms.o 4037 : 543 : Constraint *n = makeNode(Constraint);
4038 : :
9386 4039 : 543 : n->contype = CONSTR_CHECK;
5933 tgl@sss.pgh.pa.us 4040 : 543 : n->location = @1;
4843 alvherre@alvh.no-ip. 4041 : 543 : n->is_no_inherit = $5;
4042 : 543 : n->raw_expr = $3;
9521 tgl@sss.pgh.pa.us 4043 : 543 : n->cooked_expr = NULL;
289 peter@eisentraut.org 4044 : 543 : n->is_enforced = true;
3603 rhaas@postgresql.org 4045 : 543 : n->skip_validation = false;
4046 : 543 : n->initially_valid = true;
1263 peter@eisentraut.org 4047 : 543 : $$ = (Node *) n;
4048 : : }
4049 : : | DEFAULT b_expr
4050 : : {
9371 tgl@sss.pgh.pa.us 4051 : 919 : Constraint *n = makeNode(Constraint);
4052 : :
4053 : 919 : n->contype = CONSTR_DEFAULT;
5933 4054 : 919 : n->location = @1;
6573 4055 : 919 : n->raw_expr = $2;
9371 4056 : 919 : n->cooked_expr = NULL;
1263 peter@eisentraut.org 4057 : 919 : $$ = (Node *) n;
4058 : : }
4059 : : | GENERATED generated_when AS IDENTITY_P OptParenthesizedSeqOptList
4060 : : {
3126 peter_e@gmx.net 4061 : 166 : Constraint *n = makeNode(Constraint);
4062 : :
4063 : 166 : n->contype = CONSTR_IDENTITY;
4064 : 166 : n->generated_when = $2;
4065 : 166 : n->options = $5;
4066 : 166 : n->location = @1;
1263 peter@eisentraut.org 4067 : 166 : $$ = (Node *) n;
4068 : : }
4069 : : | GENERATED generated_when AS '(' a_expr ')' opt_virtual_or_stored
4070 : : {
2403 4071 : 876 : Constraint *n = makeNode(Constraint);
4072 : :
4073 : 876 : n->contype = CONSTR_GENERATED;
4074 : 876 : n->generated_when = $2;
4075 : 876 : n->raw_expr = $5;
4076 : 876 : n->cooked_expr = NULL;
262 4077 : 876 : n->generated_kind = $7;
2403 4078 : 876 : n->location = @1;
4079 : :
4080 : : /*
4081 : : * Can't do this in the grammar because of shift/reduce
4082 : : * conflicts. (IDENTITY allows both ALWAYS and BY
4083 : : * DEFAULT, but generated columns only allow ALWAYS.) We
4084 : : * can also give a more useful error message and location.
4085 : : */
2401 4086 [ + + ]: 876 : if ($2 != ATTRIBUTE_IDENTITY_ALWAYS)
4087 [ + - ]: 6 : ereport(ERROR,
4088 : : (errcode(ERRCODE_SYNTAX_ERROR),
4089 : : errmsg("for a generated column, GENERATED ALWAYS must be specified"),
4090 : : parser_errposition(@2)));
4091 : :
1263 4092 : 870 : $$ = (Node *) n;
4093 : : }
4094 : : | REFERENCES qualified_name opt_column_list key_match key_actions
4095 : : {
5933 tgl@sss.pgh.pa.us 4096 : 420 : Constraint *n = makeNode(Constraint);
4097 : :
4098 : 420 : n->contype = CONSTR_FOREIGN;
4099 : 420 : n->location = @1;
1566 peter@eisentraut.org 4100 : 420 : n->pktable = $2;
4101 : 420 : n->fk_attrs = NIL;
4102 : 420 : n->pk_attrs = $3;
4103 : 420 : n->fk_matchtype = $4;
1419 4104 : 420 : n->fk_upd_action = ($5)->updateAction->action;
4105 : 420 : n->fk_del_action = ($5)->deleteAction->action;
4106 : 420 : n->fk_del_set_cols = ($5)->deleteAction->cols;
289 4107 : 420 : n->is_enforced = true;
1566 4108 : 420 : n->skip_validation = false;
4109 : 420 : n->initially_valid = true;
1263 4110 : 420 : $$ = (Node *) n;
4111 : : }
4112 : : ;
4113 : :
4114 : : opt_unique_null_treatment:
1362 4115 : 6 : NULLS_P DISTINCT { $$ = true; }
4116 : 18 : | NULLS_P NOT DISTINCT { $$ = false; }
4117 : 3868 : | /*EMPTY*/ { $$ = true; }
4118 : : ;
4119 : :
4120 : : generated_when:
3126 peter_e@gmx.net 4121 : 1056 : ALWAYS { $$ = ATTRIBUTE_IDENTITY_ALWAYS; }
4122 : 91 : | BY DEFAULT { $$ = ATTRIBUTE_IDENTITY_BY_DEFAULT; }
4123 : : ;
4124 : :
4125 : : opt_virtual_or_stored:
262 peter@eisentraut.org 4126 : 502 : STORED { $$ = ATTRIBUTE_GENERATED_STORED; }
4127 : 320 : | VIRTUAL { $$ = ATTRIBUTE_GENERATED_VIRTUAL; }
4128 : 54 : | /*EMPTY*/ { $$ = ATTRIBUTE_GENERATED_VIRTUAL; }
4129 : : ;
4130 : :
4131 : : /*
4132 : : * ConstraintAttr represents constraint attributes, which we parse as if
4133 : : * they were independent constraint clauses, in order to avoid shift/reduce
4134 : : * conflicts (since NOT might start either an independent NOT NULL clause
4135 : : * or an attribute). parse_utilcmd.c is responsible for attaching the
4136 : : * attribute information to the preceding "real" constraint node, and for
4137 : : * complaining if attribute clauses appear in the wrong place or wrong
4138 : : * combinations.
4139 : : *
4140 : : * See also ConstraintAttributeSpec, which can be used in places where
4141 : : * there is no parsing conflict. (Note: currently, NOT VALID and NO INHERIT
4142 : : * are allowed clauses in ConstraintAttributeSpec, but not here. Someday we
4143 : : * might need to allow them here too, but for the moment it doesn't seem
4144 : : * useful in the statements that use ConstraintAttr.)
4145 : : */
4146 : : ConstraintAttr:
4147 : : DEFERRABLE
4148 : : {
9382 lockhart@fourpalms.o 4149 : 51 : Constraint *n = makeNode(Constraint);
4150 : :
9371 tgl@sss.pgh.pa.us 4151 : 51 : n->contype = CONSTR_ATTR_DEFERRABLE;
5933 4152 : 51 : n->location = @1;
1263 peter@eisentraut.org 4153 : 51 : $$ = (Node *) n;
4154 : : }
4155 : : | NOT DEFERRABLE
4156 : : {
9382 lockhart@fourpalms.o 4157 :UBC 0 : Constraint *n = makeNode(Constraint);
4158 : :
9371 tgl@sss.pgh.pa.us 4159 : 0 : n->contype = CONSTR_ATTR_NOT_DEFERRABLE;
5933 4160 : 0 : n->location = @1;
1263 peter@eisentraut.org 4161 : 0 : $$ = (Node *) n;
4162 : : }
4163 : : | INITIALLY DEFERRED
4164 : : {
9371 tgl@sss.pgh.pa.us 4165 :CBC 39 : Constraint *n = makeNode(Constraint);
4166 : :
4167 : 39 : n->contype = CONSTR_ATTR_DEFERRED;
5933 4168 : 39 : n->location = @1;
1263 peter@eisentraut.org 4169 : 39 : $$ = (Node *) n;
4170 : : }
4171 : : | INITIALLY IMMEDIATE
4172 : : {
9371 tgl@sss.pgh.pa.us 4173 : 3 : Constraint *n = makeNode(Constraint);
4174 : :
4175 : 3 : n->contype = CONSTR_ATTR_IMMEDIATE;
5933 4176 : 3 : n->location = @1;
1263 peter@eisentraut.org 4177 : 3 : $$ = (Node *) n;
4178 : : }
4179 : : | ENFORCED
4180 : : {
289 4181 : 21 : Constraint *n = makeNode(Constraint);
4182 : :
4183 : 21 : n->contype = CONSTR_ATTR_ENFORCED;
4184 : 21 : n->location = @1;
4185 : 21 : $$ = (Node *) n;
4186 : : }
4187 : : | NOT ENFORCED
4188 : : {
4189 : 33 : Constraint *n = makeNode(Constraint);
4190 : :
4191 : 33 : n->contype = CONSTR_ATTR_NOT_ENFORCED;
4192 : 33 : n->location = @1;
4193 : 33 : $$ = (Node *) n;
4194 : : }
4195 : : ;
4196 : :
4197 : :
4198 : : TableLikeClause:
4199 : : LIKE qualified_name TableLikeOptionList
4200 : : {
5042 peter_e@gmx.net 4201 : 387 : TableLikeClause *n = makeNode(TableLikeClause);
4202 : :
8160 bruce@momjian.us 4203 : 387 : n->relation = $2;
7062 4204 : 387 : n->options = $3;
1791 tgl@sss.pgh.pa.us 4205 : 387 : n->relationOid = InvalidOid;
1263 peter@eisentraut.org 4206 : 387 : $$ = (Node *) n;
4207 : : }
4208 : : ;
4209 : :
4210 : : TableLikeOptionList:
5859 andrew@dunslane.net 4211 : 144 : TableLikeOptionList INCLUDING TableLikeOption { $$ = $1 | $3; }
4212 : 4 : | TableLikeOptionList EXCLUDING TableLikeOption { $$ = $1 & ~$3; }
4213 : 387 : | /* EMPTY */ { $$ = 0; }
4214 : : ;
4215 : :
4216 : : TableLikeOption:
2793 alvherre@alvh.no-ip. 4217 : 15 : COMMENTS { $$ = CREATE_TABLE_LIKE_COMMENTS; }
1648 fujii@postgresql.org 4218 : 3 : | COMPRESSION { $$ = CREATE_TABLE_LIKE_COMPRESSION; }
5859 andrew@dunslane.net 4219 : 27 : | CONSTRAINTS { $$ = CREATE_TABLE_LIKE_CONSTRAINTS; }
2793 alvherre@alvh.no-ip. 4220 : 10 : | DEFAULTS { $$ = CREATE_TABLE_LIKE_DEFAULTS; }
3126 peter_e@gmx.net 4221 : 6 : | IDENTITY_P { $$ = CREATE_TABLE_LIKE_IDENTITY; }
2403 peter@eisentraut.org 4222 : 15 : | GENERATED { $$ = CREATE_TABLE_LIKE_GENERATED; }
5859 andrew@dunslane.net 4223 : 25 : | INDEXES { $$ = CREATE_TABLE_LIKE_INDEXES; }
2793 alvherre@alvh.no-ip. 4224 :UBC 0 : | STATISTICS { $$ = CREATE_TABLE_LIKE_STATISTICS; }
5859 andrew@dunslane.net 4225 :CBC 13 : | STORAGE { $$ = CREATE_TABLE_LIKE_STORAGE; }
4226 : 34 : | ALL { $$ = CREATE_TABLE_LIKE_ALL; }
4227 : : ;
4228 : :
4229 : :
4230 : : /* ConstraintElem specifies constraint syntax which is not embedded into
4231 : : * a column definition. ColConstraintElem specifies the embedded form.
4232 : : * - thomas 1997-12-03
4233 : : */
4234 : : TableConstraint:
4235 : : CONSTRAINT name ConstraintElem
4236 : : {
3170 peter_e@gmx.net 4237 : 2061 : Constraint *n = castNode(Constraint, $3);
4238 : :
5933 tgl@sss.pgh.pa.us 4239 : 2061 : n->conname = $2;
4240 : 2061 : n->location = @1;
4241 : 2061 : $$ = (Node *) n;
4242 : : }
8533 bruce@momjian.us 4243 : 6643 : | ConstraintElem { $$ = $1; }
4244 : : ;
4245 : :
4246 : : ConstraintElem:
4247 : : CHECK '(' a_expr ')' ConstraintAttributeSpec
4248 : : {
10189 lockhart@fourpalms.o 4249 : 634 : Constraint *n = makeNode(Constraint);
4250 : :
4251 : 634 : n->contype = CONSTR_CHECK;
5933 tgl@sss.pgh.pa.us 4252 : 634 : n->location = @1;
4843 alvherre@alvh.no-ip. 4253 : 634 : n->raw_expr = $3;
9521 tgl@sss.pgh.pa.us 4254 : 634 : n->cooked_expr = NULL;
4843 alvherre@alvh.no-ip. 4255 : 634 : processCASbits($5, @5, "CHECK",
4256 : : NULL, NULL, &n->is_enforced, &n->skip_validation,
4257 : : &n->is_no_inherit, yyscanner);
5262 4258 : 634 : n->initially_valid = !n->skip_validation;
1263 peter@eisentraut.org 4259 : 634 : $$ = (Node *) n;
4260 : : }
4261 : : | NOT NULL_P ColId ConstraintAttributeSpec
4262 : : {
353 alvherre@alvh.no-ip. 4263 : 299 : Constraint *n = makeNode(Constraint);
4264 : :
4265 : 299 : n->contype = CONSTR_NOTNULL;
4266 : 299 : n->location = @1;
4267 : 299 : n->keys = list_make1(makeString($3));
4268 : 299 : processCASbits($4, @4, "NOT NULL",
4269 : : NULL, NULL, NULL, &n->skip_validation,
4270 : : &n->is_no_inherit, yyscanner);
203 4271 : 299 : n->initially_valid = !n->skip_validation;
353 4272 : 299 : $$ = (Node *) n;
4273 : : }
4274 : : | UNIQUE opt_unique_null_treatment '(' columnList opt_without_overlaps ')' opt_c_include opt_definition OptConsTableSpace
4275 : : ConstraintAttributeSpec
4276 : : {
10189 lockhart@fourpalms.o 4277 : 308 : Constraint *n = makeNode(Constraint);
4278 : :
4279 : 308 : n->contype = CONSTR_UNIQUE;
5933 tgl@sss.pgh.pa.us 4280 : 308 : n->location = @1;
1362 peter@eisentraut.org 4281 : 308 : n->nulls_not_distinct = !$2;
4282 : 308 : n->keys = $4;
405 4283 : 308 : n->without_overlaps = $5;
4284 : 308 : n->including = $7;
4285 : 308 : n->options = $8;
5389 tgl@sss.pgh.pa.us 4286 : 308 : n->indexname = NULL;
405 peter@eisentraut.org 4287 : 308 : n->indexspace = $9;
4288 : 308 : processCASbits($10, @10, "UNIQUE",
4289 : : &n->deferrable, &n->initdeferred, NULL,
4290 : : NULL, NULL, yyscanner);
1263 4291 : 308 : $$ = (Node *) n;
4292 : : }
4293 : : | UNIQUE ExistingIndex ConstraintAttributeSpec
4294 : : {
5389 tgl@sss.pgh.pa.us 4295 : 2324 : Constraint *n = makeNode(Constraint);
4296 : :
4297 : 2324 : n->contype = CONSTR_UNIQUE;
4298 : 2324 : n->location = @1;
4299 : 2324 : n->keys = NIL;
2760 teodor@sigaev.ru 4300 : 2324 : n->including = NIL;
5389 tgl@sss.pgh.pa.us 4301 : 2324 : n->options = NIL;
4302 : 2324 : n->indexname = $2;
4303 : 2324 : n->indexspace = NULL;
5248 4304 : 2324 : processCASbits($3, @3, "UNIQUE",
4305 : : &n->deferrable, &n->initdeferred, NULL,
4306 : : NULL, NULL, yyscanner);
1263 peter@eisentraut.org 4307 : 2324 : $$ = (Node *) n;
4308 : : }
4309 : : | PRIMARY KEY '(' columnList opt_without_overlaps ')' opt_c_include opt_definition OptConsTableSpace
4310 : : ConstraintAttributeSpec
4311 : : {
9371 tgl@sss.pgh.pa.us 4312 : 1085 : Constraint *n = makeNode(Constraint);
4313 : :
4314 : 1085 : n->contype = CONSTR_PRIMARY;
5933 4315 : 1085 : n->location = @1;
9371 4316 : 1085 : n->keys = $4;
405 peter@eisentraut.org 4317 : 1085 : n->without_overlaps = $5;
4318 : 1085 : n->including = $7;
4319 : 1085 : n->options = $8;
5389 tgl@sss.pgh.pa.us 4320 : 1085 : n->indexname = NULL;
405 peter@eisentraut.org 4321 : 1085 : n->indexspace = $9;
4322 : 1085 : processCASbits($10, @10, "PRIMARY KEY",
4323 : : &n->deferrable, &n->initdeferred, NULL,
4324 : : NULL, NULL, yyscanner);
1263 4325 : 1085 : $$ = (Node *) n;
4326 : : }
4327 : : | PRIMARY KEY ExistingIndex ConstraintAttributeSpec
4328 : : {
5389 tgl@sss.pgh.pa.us 4329 : 3009 : Constraint *n = makeNode(Constraint);
4330 : :
4331 : 3009 : n->contype = CONSTR_PRIMARY;
4332 : 3009 : n->location = @1;
4333 : 3009 : n->keys = NIL;
2760 teodor@sigaev.ru 4334 : 3009 : n->including = NIL;
5389 tgl@sss.pgh.pa.us 4335 : 3009 : n->options = NIL;
4336 : 3009 : n->indexname = $3;
4337 : 3009 : n->indexspace = NULL;
5248 4338 : 3009 : processCASbits($4, @4, "PRIMARY KEY",
4339 : : &n->deferrable, &n->initdeferred, NULL,
4340 : : NULL, NULL, yyscanner);
1263 peter@eisentraut.org 4341 : 3009 : $$ = (Node *) n;
4342 : : }
4343 : : | EXCLUDE access_method_clause '(' ExclusionConstraintList ')'
4344 : : opt_c_include opt_definition OptConsTableSpace OptWhereClause
4345 : : ConstraintAttributeSpec
4346 : : {
5803 tgl@sss.pgh.pa.us 4347 : 117 : Constraint *n = makeNode(Constraint);
4348 : :
4349 : 117 : n->contype = CONSTR_EXCLUSION;
4350 : 117 : n->location = @1;
1566 peter@eisentraut.org 4351 : 117 : n->access_method = $2;
4352 : 117 : n->exclusions = $4;
4353 : 117 : n->including = $6;
4354 : 117 : n->options = $7;
4355 : 117 : n->indexname = NULL;
4356 : 117 : n->indexspace = $8;
4357 : 117 : n->where_clause = $9;
2760 teodor@sigaev.ru 4358 : 117 : processCASbits($10, @10, "EXCLUDE",
4359 : : &n->deferrable, &n->initdeferred, NULL,
4360 : : NULL, NULL, yyscanner);
1263 peter@eisentraut.org 4361 : 117 : $$ = (Node *) n;
4362 : : }
4363 : : | FOREIGN KEY '(' columnList optionalPeriodName ')' REFERENCES qualified_name
4364 : : opt_column_and_period_list key_match key_actions ConstraintAttributeSpec
4365 : : {
5933 tgl@sss.pgh.pa.us 4366 : 928 : Constraint *n = makeNode(Constraint);
4367 : :
4368 : 928 : n->contype = CONSTR_FOREIGN;
4369 : 928 : n->location = @1;
405 peter@eisentraut.org 4370 : 928 : n->pktable = $8;
1566 4371 : 928 : n->fk_attrs = $4;
405 4372 [ + + ]: 928 : if ($5)
4373 : : {
4374 : 163 : n->fk_attrs = lappend(n->fk_attrs, $5);
4375 : 163 : n->fk_with_period = true;
4376 : : }
4377 : 928 : n->pk_attrs = linitial($9);
4378 [ + + ]: 928 : if (lsecond($9))
4379 : : {
4380 : 85 : n->pk_attrs = lappend(n->pk_attrs, lsecond($9));
4381 : 85 : n->pk_with_period = true;
4382 : : }
4383 : 928 : n->fk_matchtype = $10;
4384 : 928 : n->fk_upd_action = ($11)->updateAction->action;
4385 : 928 : n->fk_del_action = ($11)->deleteAction->action;
4386 : 928 : n->fk_del_set_cols = ($11)->deleteAction->cols;
4387 : 928 : processCASbits($12, @12, "FOREIGN KEY",
4388 : : &n->deferrable, &n->initdeferred,
4389 : : &n->is_enforced, &n->skip_validation, NULL,
4390 : : yyscanner);
5248 tgl@sss.pgh.pa.us 4391 : 928 : n->initially_valid = !n->skip_validation;
1263 peter@eisentraut.org 4392 : 928 : $$ = (Node *) n;
4393 : : }
4394 : : ;
4395 : :
4396 : : /*
4397 : : * DomainConstraint is separate from TableConstraint because the syntax for
4398 : : * NOT NULL constraints is different. For table constraints, we need to
4399 : : * accept a column name, but for domain constraints, we don't. (We could
4400 : : * accept something like NOT NULL VALUE, but that seems weird.) CREATE DOMAIN
4401 : : * (which uses ColQualList) has for a long time accepted NOT NULL without a
4402 : : * column name, so it makes sense that ALTER DOMAIN (which uses
4403 : : * DomainConstraint) does as well. None of these syntaxes are per SQL
4404 : : * standard; we are just living with the bits of inconsistency that have built
4405 : : * up over time.
4406 : : */
4407 : : DomainConstraint:
4408 : : CONSTRAINT name DomainConstraintElem
4409 : : {
560 4410 : 82 : Constraint *n = castNode(Constraint, $3);
4411 : :
4412 : 82 : n->conname = $2;
4413 : 82 : n->location = @1;
4414 : 82 : $$ = (Node *) n;
4415 : : }
4416 : 9 : | DomainConstraintElem { $$ = $1; }
4417 : : ;
4418 : :
4419 : : DomainConstraintElem:
4420 : : CHECK '(' a_expr ')' ConstraintAttributeSpec
4421 : : {
4422 : 82 : Constraint *n = makeNode(Constraint);
4423 : :
4424 : 82 : n->contype = CONSTR_CHECK;
4425 : 82 : n->location = @1;
4426 : 82 : n->raw_expr = $3;
4427 : 82 : n->cooked_expr = NULL;
4428 : 82 : processCASbits($5, @5, "CHECK",
4429 : : NULL, NULL, NULL, &n->skip_validation,
4430 : : &n->is_no_inherit, yyscanner);
289 4431 : 76 : n->is_enforced = true;
560 4432 : 76 : n->initially_valid = !n->skip_validation;
4433 : 76 : $$ = (Node *) n;
4434 : : }
4435 : : | NOT NULL_P ConstraintAttributeSpec
4436 : : {
4437 : 15 : Constraint *n = makeNode(Constraint);
4438 : :
4439 : 15 : n->contype = CONSTR_NOTNULL;
4440 : 15 : n->location = @1;
4441 : 15 : n->keys = list_make1(makeString("value"));
4442 : : /* no NOT VALID, NO INHERIT support */
4443 : 15 : processCASbits($3, @3, "NOT NULL",
4444 : : NULL, NULL, NULL,
4445 : : NULL, NULL, yyscanner);
4446 : 15 : n->initially_valid = true;
4447 : 15 : $$ = (Node *) n;
4448 : : }
4449 : : ;
4450 : :
2994 peter_e@gmx.net 4451 : 69 : opt_no_inherit: NO INHERIT { $$ = true; }
4452 : 3931 : | /* EMPTY */ { $$ = false; }
4453 : : ;
4454 : :
4455 : : opt_without_overlaps:
405 peter@eisentraut.org 4456 : 295 : WITHOUT OVERLAPS { $$ = true; }
4457 : 1098 : | /*EMPTY*/ { $$ = false; }
4458 : : ;
4459 : :
4460 : : opt_column_list:
8533 bruce@momjian.us 4461 : 5130 : '(' columnList ')' { $$ = $2; }
4462 : 21560 : | /*EMPTY*/ { $$ = NIL; }
4463 : : ;
4464 : :
4465 : : columnList:
7820 neilc@samurai.com 4466 : 8298 : columnElem { $$ = list_make1($1); }
8532 bruce@momjian.us 4467 : 14284 : | columnList ',' columnElem { $$ = lappend($1, $3); }
4468 : : ;
4469 : :
4470 : : optionalPeriodName:
405 peter@eisentraut.org 4471 : 248 : ',' PERIOD columnElem { $$ = $3; }
4472 : 1245 : | /*EMPTY*/ { $$ = NULL; }
4473 : : ;
4474 : :
4475 : : opt_column_and_period_list:
4476 : 562 : '(' columnList optionalPeriodName ')' { $$ = list_make2($2, $3); }
4477 : 369 : | /*EMPTY*/ { $$ = list_make2(NIL, NULL); }
4478 : : ;
4479 : :
4480 : : columnElem: ColId
4481 : : {
8470 tgl@sss.pgh.pa.us 4482 : 22830 : $$ = (Node *) makeString($1);
4483 : : }
4484 : : ;
4485 : :
2760 teodor@sigaev.ru 4486 : 84 : opt_c_include: INCLUDE '(' columnList ')' { $$ = $3; }
4487 : 1426 : | /* EMPTY */ { $$ = NIL; }
4488 : : ;
4489 : :
4490 : : key_match: MATCH FULL
4491 : : {
8508 tgl@sss.pgh.pa.us 4492 : 49 : $$ = FKCONSTR_MATCH_FULL;
4493 : : }
4494 : : | MATCH PARTIAL
4495 : : {
8136 tgl@sss.pgh.pa.us 4496 [ # # ]:UBC 0 : ereport(ERROR,
4497 : : (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
4498 : : errmsg("MATCH PARTIAL not yet implemented"),
4499 : : parser_errposition(@1)));
4500 : : $$ = FKCONSTR_MATCH_PARTIAL;
4501 : : }
4502 : : | MATCH SIMPLE
4503 : : {
4880 tgl@sss.pgh.pa.us 4504 :CBC 3 : $$ = FKCONSTR_MATCH_SIMPLE;
4505 : : }
4506 : : | /*EMPTY*/
4507 : : {
4508 : 1299 : $$ = FKCONSTR_MATCH_SIMPLE;
4509 : : }
4510 : : ;
4511 : :
4512 : : ExclusionConstraintList:
5803 4513 : 117 : ExclusionConstraintElem { $$ = list_make1($1); }
4514 : : | ExclusionConstraintList ',' ExclusionConstraintElem
4515 : 53 : { $$ = lappend($1, $3); }
4516 : : ;
4517 : :
4518 : : ExclusionConstraintElem: index_elem WITH any_operator
4519 : : {
4520 : 170 : $$ = list_make2($1, $3);
4521 : : }
4522 : : /* allow OPERATOR() decoration for the benefit of ruleutils.c */
4523 : : | index_elem WITH OPERATOR '(' any_operator ')'
4524 : : {
5803 tgl@sss.pgh.pa.us 4525 :UBC 0 : $$ = list_make2($1, $5);
4526 : : }
4527 : : ;
4528 : :
4529 : : OptWhereClause:
5803 tgl@sss.pgh.pa.us 4530 :CBC 232 : WHERE '(' a_expr ')' { $$ = $3; }
4531 : 632 : | /*EMPTY*/ { $$ = NULL; }
4532 : : ;
4533 : :
4534 : : key_actions:
4535 : : key_update
4536 : : {
1419 peter@eisentraut.org 4537 : 37 : KeyActions *n = palloc(sizeof(KeyActions));
4538 : :
4539 : 37 : n->updateAction = $1;
4540 : 37 : n->deleteAction = palloc(sizeof(KeyAction));
4541 : 37 : n->deleteAction->action = FKCONSTR_ACTION_NOACTION;
4542 : 37 : n->deleteAction->cols = NIL;
4543 : 37 : $$ = n;
4544 : : }
4545 : : | key_delete
4546 : : {
4547 : 75 : KeyActions *n = palloc(sizeof(KeyActions));
4548 : :
4549 : 75 : n->updateAction = palloc(sizeof(KeyAction));
4550 : 75 : n->updateAction->action = FKCONSTR_ACTION_NOACTION;
4551 : 75 : n->updateAction->cols = NIL;
4552 : 75 : n->deleteAction = $1;
4553 : 75 : $$ = n;
4554 : : }
4555 : : | key_update key_delete
4556 : : {
4557 : 84 : KeyActions *n = palloc(sizeof(KeyActions));
4558 : :
4559 : 84 : n->updateAction = $1;
4560 : 84 : n->deleteAction = $2;
4561 : 84 : $$ = n;
4562 : : }
4563 : : | key_delete key_update
4564 : : {
4565 : 75 : KeyActions *n = palloc(sizeof(KeyActions));
4566 : :
4567 : 75 : n->updateAction = $2;
4568 : 75 : n->deleteAction = $1;
4569 : 75 : $$ = n;
4570 : : }
4571 : : | /*EMPTY*/
4572 : : {
4573 : 1077 : KeyActions *n = palloc(sizeof(KeyActions));
4574 : :
4575 : 1077 : n->updateAction = palloc(sizeof(KeyAction));
4576 : 1077 : n->updateAction->action = FKCONSTR_ACTION_NOACTION;
4577 : 1077 : n->updateAction->cols = NIL;
4578 : 1077 : n->deleteAction = palloc(sizeof(KeyAction));
4579 : 1077 : n->deleteAction->action = FKCONSTR_ACTION_NOACTION;
4580 : 1077 : n->deleteAction->cols = NIL;
4581 : 1077 : $$ = n;
4582 : : }
4583 : : ;
4584 : :
4585 : : key_update: ON UPDATE key_action
4586 : : {
4587 [ + + ]: 199 : if (($3)->cols)
4588 [ + - + - ]: 3 : ereport(ERROR,
4589 : : (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
4590 : : errmsg("a column list with %s is only supported for ON DELETE actions",
4591 : : ($3)->action == FKCONSTR_ACTION_SETNULL ? "SET NULL" : "SET DEFAULT"),
4592 : : parser_errposition(@1)));
4593 : 196 : $$ = $3;
4594 : : }
4595 : : ;
4596 : :
4597 : : key_delete: ON DELETE_P key_action
4598 : : {
4599 : 234 : $$ = $3;
4600 : : }
4601 : : ;
4602 : :
4603 : : key_action:
4604 : : NO ACTION
4605 : : {
4606 : 40 : KeyAction *n = palloc(sizeof(KeyAction));
4607 : :
4608 : 40 : n->action = FKCONSTR_ACTION_NOACTION;
4609 : 40 : n->cols = NIL;
4610 : 40 : $$ = n;
4611 : : }
4612 : : | RESTRICT
4613 : : {
4614 : 24 : KeyAction *n = palloc(sizeof(KeyAction));
4615 : :
4616 : 24 : n->action = FKCONSTR_ACTION_RESTRICT;
4617 : 24 : n->cols = NIL;
4618 : 24 : $$ = n;
4619 : : }
4620 : : | CASCADE
4621 : : {
4622 : 223 : KeyAction *n = palloc(sizeof(KeyAction));
4623 : :
4624 : 223 : n->action = FKCONSTR_ACTION_CASCADE;
4625 : 223 : n->cols = NIL;
4626 : 223 : $$ = n;
4627 : : }
4628 : : | SET NULL_P opt_column_list
4629 : : {
4630 : 95 : KeyAction *n = palloc(sizeof(KeyAction));
4631 : :
4632 : 95 : n->action = FKCONSTR_ACTION_SETNULL;
4633 : 95 : n->cols = $3;
4634 : 95 : $$ = n;
4635 : : }
4636 : : | SET DEFAULT opt_column_list
4637 : : {
4638 : 51 : KeyAction *n = palloc(sizeof(KeyAction));
4639 : :
4640 : 51 : n->action = FKCONSTR_ACTION_SETDEFAULT;
4641 : 51 : n->cols = $3;
4642 : 51 : $$ = n;
4643 : : }
4644 : : ;
4645 : :
8533 bruce@momjian.us 4646 : 1066 : OptInherit: INHERITS '(' qualified_name_list ')' { $$ = $3; }
4647 : 14125 : | /*EMPTY*/ { $$ = NIL; }
4648 : : ;
4649 : :
4650 : : /* Optional partition key specification */
3246 rhaas@postgresql.org 4651 : 2556 : OptPartitionSpec: PartitionSpec { $$ = $1; }
4652 : 16554 : | /*EMPTY*/ { $$ = NULL; }
4653 : : ;
4654 : :
4655 : : PartitionSpec: PARTITION BY ColId '(' part_params ')'
4656 : : {
4657 : 2559 : PartitionSpec *n = makeNode(PartitionSpec);
4658 : :
361 tgl@sss.pgh.pa.us 4659 : 2559 : n->strategy = parsePartitionStrategy($3, @3, yyscanner);
3246 rhaas@postgresql.org 4660 : 2556 : n->partParams = $5;
4661 : 2556 : n->location = @1;
4662 : :
4663 : 2556 : $$ = n;
4664 : : }
4665 : : ;
4666 : :
4667 : 2559 : part_params: part_elem { $$ = list_make1($1); }
4668 : 228 : | part_params ',' part_elem { $$ = lappend($1, $3); }
4669 : : ;
4670 : :
4671 : : part_elem: ColId opt_collate opt_qualified_name
4672 : : {
4673 : 2635 : PartitionElem *n = makeNode(PartitionElem);
4674 : :
4675 : 2635 : n->name = $1;
4676 : 2635 : n->expr = NULL;
4677 : 2635 : n->collation = $2;
4678 : 2635 : n->opclass = $3;
4679 : 2635 : n->location = @1;
4680 : 2635 : $$ = n;
4681 : : }
4682 : : | func_expr_windowless opt_collate opt_qualified_name
4683 : : {
4684 : 65 : PartitionElem *n = makeNode(PartitionElem);
4685 : :
4686 : 65 : n->name = NULL;
4687 : 65 : n->expr = $1;
4688 : 65 : n->collation = $2;
4689 : 65 : n->opclass = $3;
4690 : 65 : n->location = @1;
4691 : 65 : $$ = n;
4692 : : }
4693 : : | '(' a_expr ')' opt_collate opt_qualified_name
4694 : : {
4695 : 87 : PartitionElem *n = makeNode(PartitionElem);
4696 : :
4697 : 87 : n->name = NULL;
4698 : 87 : n->expr = $2;
4699 : 87 : n->collation = $4;
4700 : 87 : n->opclass = $5;
4701 : 87 : n->location = @1;
4702 : 87 : $$ = n;
4703 : : }
4704 : : ;
4705 : :
4706 : : table_access_method_clause:
1965 peter@eisentraut.org 4707 : 61 : USING name { $$ = $2; }
2427 andres@anarazel.de 4708 : 20019 : | /*EMPTY*/ { $$ = NULL; }
4709 : : ;
4710 : :
4711 : : /* WITHOUT OIDS is legacy only */
4712 : : OptWith:
6111 alvherre@alvh.no-ip. 4713 : 379 : WITH reloptions { $$ = $2; }
2533 andres@anarazel.de 4714 : 12 : | WITHOUT OIDS { $$ = NIL; }
7056 tgl@sss.pgh.pa.us 4715 : 19395 : | /*EMPTY*/ { $$ = NIL; }
4716 : : ;
4717 : :
8386 4718 : 30 : OnCommitOption: ON COMMIT DROP { $$ = ONCOMMIT_DROP; }
4719 : 52 : | ON COMMIT DELETE_P ROWS { $$ = ONCOMMIT_DELETE_ROWS; }
4720 : 12 : | ON COMMIT PRESERVE ROWS { $$ = ONCOMMIT_PRESERVE_ROWS; }
4721 : 19692 : | /*EMPTY*/ { $$ = ONCOMMIT_NOOP; }
4722 : : ;
4723 : :
7801 4724 : 110 : OptTableSpace: TABLESPACE name { $$ = $2; }
4725 : 23319 : | /*EMPTY*/ { $$ = NULL; }
4726 : : ;
4727 : :
7756 4728 : 33 : OptConsTableSpace: USING INDEX TABLESPACE name { $$ = $4; }
4729 : 4664 : | /*EMPTY*/ { $$ = NULL; }
4730 : : ;
4731 : :
1965 peter@eisentraut.org 4732 : 5333 : ExistingIndex: USING INDEX name { $$ = $3; }
4733 : : ;
4734 : :
4735 : : /*****************************************************************************
4736 : : *
4737 : : * QUERY :
4738 : : * CREATE STATISTICS [[IF NOT EXISTS] stats_name] [(stat types)]
4739 : : * ON expression-list FROM from_list
4740 : : *
4741 : : * Note: the expectation here is that the clauses after ON are a subset of
4742 : : * SELECT syntax, allowing for expressions and joined tables, and probably
4743 : : * someday a WHERE clause. Much less than that is currently implemented,
4744 : : * but the grammar accepts it and then we'll throw FEATURE_NOT_SUPPORTED
4745 : : * errors as necessary at execution.
4746 : : *
4747 : : * Statistics name is optional unless IF NOT EXISTS is specified.
4748 : : *
4749 : : *****************************************************************************/
4750 : :
4751 : : CreateStatsStmt:
4752 : : CREATE STATISTICS opt_qualified_name
4753 : : opt_name_list ON stats_params FROM from_list
4754 : : {
3090 alvherre@alvh.no-ip. 4755 : 368 : CreateStatsStmt *n = makeNode(CreateStatsStmt);
4756 : :
3049 4757 : 368 : n->defnames = $3;
4758 : 368 : n->stat_types = $4;
4759 : 368 : n->exprs = $6;
4760 : 368 : n->relations = $8;
2793 4761 : 368 : n->stxcomment = NULL;
3049 4762 : 368 : n->if_not_exists = false;
1263 peter@eisentraut.org 4763 : 368 : $$ = (Node *) n;
4764 : : }
4765 : : | CREATE STATISTICS IF_P NOT EXISTS any_name
4766 : : opt_name_list ON stats_params FROM from_list
4767 : : {
3049 alvherre@alvh.no-ip. 4768 : 6 : CreateStatsStmt *n = makeNode(CreateStatsStmt);
4769 : :
4770 : 6 : n->defnames = $6;
4771 : 6 : n->stat_types = $7;
4772 : 6 : n->exprs = $9;
4773 : 6 : n->relations = $11;
2793 4774 : 6 : n->stxcomment = NULL;
3049 4775 : 6 : n->if_not_exists = true;
1263 peter@eisentraut.org 4776 : 6 : $$ = (Node *) n;
4777 : : }
4778 : : ;
4779 : :
4780 : : /*
4781 : : * Statistics attributes can be either simple column references, or arbitrary
4782 : : * expressions in parens. For compatibility with index attributes permitted
4783 : : * in CREATE INDEX, we allow an expression that's just a function call to be
4784 : : * written without parens.
4785 : : */
4786 : :
1676 tomas.vondra@postgre 4787 : 380 : stats_params: stats_param { $$ = list_make1($1); }
4788 : 489 : | stats_params ',' stats_param { $$ = lappend($1, $3); }
4789 : : ;
4790 : :
4791 : : stats_param: ColId
4792 : : {
4793 : 614 : $$ = makeNode(StatsElem);
4794 : 614 : $$->name = $1;
4795 : 614 : $$->expr = NULL;
4796 : : }
4797 : : | func_expr_windowless
4798 : : {
4799 : 19 : $$ = makeNode(StatsElem);
4800 : 19 : $$->name = NULL;
4801 : 19 : $$->expr = $1;
4802 : : }
4803 : : | '(' a_expr ')'
4804 : : {
4805 : 236 : $$ = makeNode(StatsElem);
4806 : 236 : $$->name = NULL;
4807 : 236 : $$->expr = $2;
4808 : : }
4809 : : ;
4810 : :
4811 : : /*****************************************************************************
4812 : : *
4813 : : * QUERY :
4814 : : * ALTER STATISTICS [IF EXISTS] stats_name
4815 : : * SET STATISTICS <SignedIconst>
4816 : : *
4817 : : *****************************************************************************/
4818 : :
4819 : : AlterStatsStmt:
4820 : : ALTER STATISTICS any_name SET STATISTICS set_statistics_value
4821 : : {
2239 4822 : 10 : AlterStatsStmt *n = makeNode(AlterStatsStmt);
4823 : :
4824 : 10 : n->defnames = $3;
4825 : 10 : n->missing_ok = false;
4826 : 10 : n->stxstattarget = $6;
1263 peter@eisentraut.org 4827 : 10 : $$ = (Node *) n;
4828 : : }
4829 : : | ALTER STATISTICS IF_P EXISTS any_name SET STATISTICS set_statistics_value
4830 : : {
2239 tomas.vondra@postgre 4831 : 3 : AlterStatsStmt *n = makeNode(AlterStatsStmt);
4832 : :
4833 : 3 : n->defnames = $5;
4834 : 3 : n->missing_ok = true;
4835 : 3 : n->stxstattarget = $8;
1263 peter@eisentraut.org 4836 : 3 : $$ = (Node *) n;
4837 : : }
4838 : : ;
4839 : :
4840 : : /*****************************************************************************
4841 : : *
4842 : : * QUERY :
4843 : : * CREATE TABLE relname AS SelectStmt [ WITH [NO] DATA ]
4844 : : *
4845 : : *
4846 : : * Note: SELECT ... INTO is a now-deprecated alternative for this.
4847 : : *
4848 : : *****************************************************************************/
4849 : :
4850 : : CreateAsStmt:
4851 : : CREATE OptTemp TABLE create_as_target AS SelectStmt opt_with_data
4852 : : {
4970 tgl@sss.pgh.pa.us 4853 : 613 : CreateTableAsStmt *ctas = makeNode(CreateTableAsStmt);
4854 : :
4855 : 613 : ctas->query = $6;
4856 : 613 : ctas->into = $4;
1934 michael@paquier.xyz 4857 : 613 : ctas->objtype = OBJECT_TABLE;
4970 tgl@sss.pgh.pa.us 4858 : 613 : ctas->is_select_into = false;
3971 andrew@dunslane.net 4859 : 613 : ctas->if_not_exists = false;
4860 : : /* cram additional flags into the IntoClause */
5086 tgl@sss.pgh.pa.us 4861 : 613 : $4->rel->relpersistence = $2;
4862 : 613 : $4->skipData = !($7);
4970 4863 : 613 : $$ = (Node *) ctas;
4864 : : }
4865 : : | CREATE OptTemp TABLE IF_P NOT EXISTS create_as_target AS SelectStmt opt_with_data
4866 : : {
3971 andrew@dunslane.net 4867 : 25 : CreateTableAsStmt *ctas = makeNode(CreateTableAsStmt);
4868 : :
4869 : 25 : ctas->query = $9;
4870 : 25 : ctas->into = $7;
1934 michael@paquier.xyz 4871 : 25 : ctas->objtype = OBJECT_TABLE;
3971 andrew@dunslane.net 4872 : 25 : ctas->is_select_into = false;
4873 : 25 : ctas->if_not_exists = true;
4874 : : /* cram additional flags into the IntoClause */
4875 : 25 : $7->rel->relpersistence = $2;
4876 : 25 : $7->skipData = !($10);
4877 : 25 : $$ = (Node *) ctas;
4878 : : }
4879 : : ;
4880 : :
4881 : : create_as_target:
4882 : : qualified_name opt_column_list table_access_method_clause
4883 : : OptWith OnCommitOption OptTableSpace
4884 : : {
6824 tgl@sss.pgh.pa.us 4885 : 682 : $$ = makeNode(IntoClause);
4886 : 682 : $$->rel = $1;
4887 : 682 : $$->colNames = $2;
2427 andres@anarazel.de 4888 : 682 : $$->accessMethod = $3;
4889 : 682 : $$->options = $4;
4890 : 682 : $$->onCommit = $5;
4891 : 682 : $$->tableSpaceName = $6;
4581 tgl@sss.pgh.pa.us 4892 : 682 : $$->viewQuery = NULL;
5086 4893 : 682 : $$->skipData = false; /* might get changed later */
4894 : : }
4895 : : ;
4896 : :
4897 : : opt_with_data:
2994 peter_e@gmx.net 4898 : 18 : WITH DATA_P { $$ = true; }
4899 : 108 : | WITH NO DATA_P { $$ = false; }
4900 : 981 : | /*EMPTY*/ { $$ = true; }
4901 : : ;
4902 : :
4903 : :
4904 : : /*****************************************************************************
4905 : : *
4906 : : * QUERY :
4907 : : * CREATE MATERIALIZED VIEW relname AS SelectStmt
4908 : : *
4909 : : *****************************************************************************/
4910 : :
4911 : : CreateMatViewStmt:
4912 : : CREATE OptNoLog MATERIALIZED VIEW create_mv_target AS SelectStmt opt_with_data
4913 : : {
4621 kgrittn@postgresql.o 4914 : 267 : CreateTableAsStmt *ctas = makeNode(CreateTableAsStmt);
4915 : :
4916 : 267 : ctas->query = $7;
4917 : 267 : ctas->into = $5;
1934 michael@paquier.xyz 4918 : 267 : ctas->objtype = OBJECT_MATVIEW;
4621 kgrittn@postgresql.o 4919 : 267 : ctas->is_select_into = false;
3971 andrew@dunslane.net 4920 : 267 : ctas->if_not_exists = false;
4921 : : /* cram additional flags into the IntoClause */
4621 kgrittn@postgresql.o 4922 : 267 : $5->rel->relpersistence = $2;
4923 : 267 : $5->skipData = !($8);
4924 : 267 : $$ = (Node *) ctas;
4925 : : }
4926 : : | CREATE OptNoLog MATERIALIZED VIEW IF_P NOT EXISTS create_mv_target AS SelectStmt opt_with_data
4927 : : {
3971 andrew@dunslane.net 4928 : 24 : CreateTableAsStmt *ctas = makeNode(CreateTableAsStmt);
4929 : :
4930 : 24 : ctas->query = $10;
4931 : 24 : ctas->into = $8;
1934 michael@paquier.xyz 4932 : 24 : ctas->objtype = OBJECT_MATVIEW;
3971 andrew@dunslane.net 4933 : 24 : ctas->is_select_into = false;
4934 : 24 : ctas->if_not_exists = true;
4935 : : /* cram additional flags into the IntoClause */
4936 : 24 : $8->rel->relpersistence = $2;
4937 : 24 : $8->skipData = !($11);
4938 : 24 : $$ = (Node *) ctas;
4939 : : }
4940 : : ;
4941 : :
4942 : : create_mv_target:
4943 : : qualified_name opt_column_list table_access_method_clause opt_reloptions OptTableSpace
4944 : : {
4621 kgrittn@postgresql.o 4945 : 291 : $$ = makeNode(IntoClause);
4946 : 291 : $$->rel = $1;
4947 : 291 : $$->colNames = $2;
2427 andres@anarazel.de 4948 : 291 : $$->accessMethod = $3;
4949 : 291 : $$->options = $4;
4621 kgrittn@postgresql.o 4950 : 291 : $$->onCommit = ONCOMMIT_NOOP;
2427 andres@anarazel.de 4951 : 291 : $$->tableSpaceName = $5;
4581 tgl@sss.pgh.pa.us 4952 : 291 : $$->viewQuery = NULL; /* filled at analysis time */
4621 kgrittn@postgresql.o 4953 : 291 : $$->skipData = false; /* might get changed later */
4954 : : }
4955 : : ;
4956 : :
4621 kgrittn@postgresql.o 4957 :UBC 0 : OptNoLog: UNLOGGED { $$ = RELPERSISTENCE_UNLOGGED; }
4621 kgrittn@postgresql.o 4958 :CBC 291 : | /*EMPTY*/ { $$ = RELPERSISTENCE_PERMANENT; }
4959 : : ;
4960 : :
4961 : :
4962 : : /*****************************************************************************
4963 : : *
4964 : : * QUERY :
4965 : : * REFRESH MATERIALIZED VIEW qualified_name
4966 : : *
4967 : : *****************************************************************************/
4968 : :
4969 : : RefreshMatViewStmt:
4970 : : REFRESH MATERIALIZED VIEW opt_concurrently qualified_name opt_with_data
4971 : : {
4972 : 134 : RefreshMatViewStmt *n = makeNode(RefreshMatViewStmt);
4973 : :
4486 4974 : 134 : n->concurrent = $4;
4975 : 134 : n->relation = $5;
4976 : 134 : n->skipData = !($6);
4621 4977 : 134 : $$ = (Node *) n;
4978 : : }
4979 : : ;
4980 : :
4981 : :
4982 : : /*****************************************************************************
4983 : : *
4984 : : * QUERY :
4985 : : * CREATE SEQUENCE seqname
4986 : : * ALTER SEQUENCE seqname
4987 : : *
4988 : : *****************************************************************************/
4989 : :
4990 : : CreateSeqStmt:
4991 : : CREATE OptTemp SEQUENCE qualified_name OptSeqOptList
4992 : : {
10276 bruce@momjian.us 4993 : 336 : CreateSeqStmt *n = makeNode(CreateSeqStmt);
4994 : :
5432 rhaas@postgresql.org 4995 : 336 : $4->relpersistence = $2;
8621 tgl@sss.pgh.pa.us 4996 : 336 : n->sequence = $4;
8892 bruce@momjian.us 4997 : 336 : n->options = $5;
5549 tgl@sss.pgh.pa.us 4998 : 336 : n->ownerId = InvalidOid;
4080 heikki.linnakangas@i 4999 : 336 : n->if_not_exists = false;
1263 peter@eisentraut.org 5000 : 336 : $$ = (Node *) n;
5001 : : }
5002 : : | CREATE OptTemp SEQUENCE IF_P NOT EXISTS qualified_name OptSeqOptList
5003 : : {
4080 heikki.linnakangas@i 5004 : 12 : CreateSeqStmt *n = makeNode(CreateSeqStmt);
5005 : :
5006 : 12 : $7->relpersistence = $2;
5007 : 12 : n->sequence = $7;
5008 : 12 : n->options = $8;
5009 : 12 : n->ownerId = InvalidOid;
5010 : 12 : n->if_not_exists = true;
1263 peter@eisentraut.org 5011 : 12 : $$ = (Node *) n;
5012 : : }
5013 : : ;
5014 : :
5015 : : AlterSeqStmt:
5016 : : ALTER SEQUENCE qualified_name SeqOptList
5017 : : {
8257 bruce@momjian.us 5018 : 92 : AlterSeqStmt *n = makeNode(AlterSeqStmt);
5019 : :
5020 : 92 : n->sequence = $3;
5021 : 92 : n->options = $4;
5026 simon@2ndQuadrant.co 5022 : 92 : n->missing_ok = false;
1263 peter@eisentraut.org 5023 : 92 : $$ = (Node *) n;
5024 : : }
5025 : : | ALTER SEQUENCE IF_P EXISTS qualified_name SeqOptList
5026 : : {
5026 simon@2ndQuadrant.co 5027 : 6 : AlterSeqStmt *n = makeNode(AlterSeqStmt);
5028 : :
5029 : 6 : n->sequence = $5;
5030 : 6 : n->options = $6;
5031 : 6 : n->missing_ok = true;
1263 peter@eisentraut.org 5032 : 6 : $$ = (Node *) n;
5033 : : }
5034 : :
5035 : : ;
5036 : :
6343 tgl@sss.pgh.pa.us 5037 : 131 : OptSeqOptList: SeqOptList { $$ = $1; }
8484 5038 : 217 : | /*EMPTY*/ { $$ = NIL; }
5039 : : ;
5040 : :
3126 peter_e@gmx.net 5041 : 37 : OptParenthesizedSeqOptList: '(' SeqOptList ')' { $$ = $2; }
5042 : 212 : | /*EMPTY*/ { $$ = NIL; }
5043 : : ;
5044 : :
6343 tgl@sss.pgh.pa.us 5045 : 266 : SeqOptList: SeqOptElem { $$ = list_make1($1); }
5046 : 401 : | SeqOptList SeqOptElem { $$ = lappend($1, $2); }
5047 : : ;
5048 : :
5049 : : SeqOptElem: AS SimpleTypename
5050 : : {
1263 peter@eisentraut.org 5051 : 95 : $$ = makeDefElem("as", (Node *) $2, @1);
5052 : : }
5053 : : | CACHE NumericOnly
5054 : : {
5055 : 65 : $$ = makeDefElem("cache", (Node *) $2, @1);
5056 : : }
5057 : : | CYCLE
5058 : : {
5059 : 17 : $$ = makeDefElem("cycle", (Node *) makeBoolean(true), @1);
5060 : : }
5061 : : | NO CYCLE
5062 : : {
5063 : 7 : $$ = makeDefElem("cycle", (Node *) makeBoolean(false), @1);
5064 : : }
5065 : : | INCREMENT opt_by NumericOnly
5066 : : {
5067 : 123 : $$ = makeDefElem("increment", (Node *) $3, @1);
5068 : : }
5069 : : | LOGGED
5070 : : {
405 tgl@sss.pgh.pa.us 5071 : 1 : $$ = makeDefElem("logged", NULL, @1);
5072 : : }
5073 : : | MAXVALUE NumericOnly
5074 : : {
1263 peter@eisentraut.org 5075 : 34 : $$ = makeDefElem("maxvalue", (Node *) $2, @1);
5076 : : }
5077 : : | MINVALUE NumericOnly
5078 : : {
5079 : 34 : $$ = makeDefElem("minvalue", (Node *) $2, @1);
5080 : : }
5081 : : | NO MAXVALUE
5082 : : {
3338 peter_e@gmx.net 5083 : 54 : $$ = makeDefElem("maxvalue", NULL, @1);
5084 : : }
5085 : : | NO MINVALUE
5086 : : {
5087 : 54 : $$ = makeDefElem("minvalue", NULL, @1);
5088 : : }
5089 : : | OWNED BY any_name
5090 : : {
1263 peter@eisentraut.org 5091 : 36 : $$ = makeDefElem("owned_by", (Node *) $3, @1);
5092 : : }
5093 : : | SEQUENCE NAME_P any_name
5094 : : {
5095 : 22 : $$ = makeDefElem("sequence_name", (Node *) $3, @1);
5096 : : }
5097 : : | START opt_with NumericOnly
5098 : : {
5099 : 118 : $$ = makeDefElem("start", (Node *) $3, @1);
5100 : : }
5101 : : | RESTART
5102 : : {
3338 peter_e@gmx.net 5103 : 3 : $$ = makeDefElem("restart", NULL, @1);
5104 : : }
5105 : : | RESTART opt_with NumericOnly
5106 : : {
1263 peter@eisentraut.org 5107 : 30 : $$ = makeDefElem("restart", (Node *) $3, @1);
5108 : : }
5109 : : | UNLOGGED
5110 : : {
405 tgl@sss.pgh.pa.us 5111 : 1 : $$ = makeDefElem("unlogged", NULL, @1);
5112 : : }
5113 : : ;
5114 : :
5115 : : opt_by: BY
5116 : : | /* EMPTY */
5117 : : ;
5118 : :
5119 : : NumericOnly:
1509 peter@eisentraut.org 5120 : 162 : FCONST { $$ = (Node *) makeFloat($1); }
1509 peter@eisentraut.org 5121 :UBC 0 : | '+' FCONST { $$ = (Node *) makeFloat($2); }
5122 : : | '-' FCONST
5123 : : {
1263 peter@eisentraut.org 5124 :CBC 10 : Float *f = makeFloat($2);
5125 : :
1509 5126 : 10 : doNegateFloat(f);
5127 : 10 : $$ = (Node *) f;
5128 : : }
5129 : 6555 : | SignedIconst { $$ = (Node *) makeInteger($1); }
5130 : : ;
5131 : :
5615 rhaas@postgresql.org 5132 : 45 : NumericOnly_list: NumericOnly { $$ = list_make1($1); }
5133 : 3 : | NumericOnly_list ',' NumericOnly { $$ = lappend($1, $3); }
5134 : : ;
5135 : :
5136 : : /*****************************************************************************
5137 : : *
5138 : : * QUERIES :
5139 : : * CREATE [OR REPLACE] [TRUSTED] [PROCEDURAL] LANGUAGE ...
5140 : : * DROP [PROCEDURAL] LANGUAGE ...
5141 : : *
5142 : : *****************************************************************************/
5143 : :
5144 : : CreatePLangStmt:
5145 : : CREATE opt_or_replace opt_trusted opt_procedural LANGUAGE name
5146 : : {
5147 : : /*
5148 : : * We now interpret parameterless CREATE LANGUAGE as
5149 : : * CREATE EXTENSION. "OR REPLACE" is silently translated
5150 : : * to "IF NOT EXISTS", which isn't quite the same, but
5151 : : * seems more useful than throwing an error. We just
5152 : : * ignore TRUSTED, as the previous code would have too.
5153 : : */
2098 tgl@sss.pgh.pa.us 5154 :UBC 0 : CreateExtensionStmt *n = makeNode(CreateExtensionStmt);
5155 : :
5156 : 0 : n->if_not_exists = $2;
5157 : 0 : n->extname = $6;
5158 : 0 : n->options = NIL;
1263 peter@eisentraut.org 5159 : 0 : $$ = (Node *) n;
5160 : : }
5161 : : | CREATE opt_or_replace opt_trusted opt_procedural LANGUAGE name
5162 : : HANDLER handler_name opt_inline_handler opt_validator
5163 : : {
10226 vadim4o@yahoo.com 5164 :CBC 71 : CreatePLangStmt *n = makeNode(CreatePLangStmt);
5165 : :
5725 tgl@sss.pgh.pa.us 5166 : 71 : n->replace = $2;
5167 : 71 : n->plname = $6;
5168 : 71 : n->plhandler = $8;
5169 : 71 : n->plinline = $9;
5170 : 71 : n->plvalidator = $10;
5171 : 71 : n->pltrusted = $3;
1263 peter@eisentraut.org 5172 : 71 : $$ = (Node *) n;
5173 : : }
5174 : : ;
5175 : :
5176 : : opt_trusted:
2994 peter_e@gmx.net 5177 : 56 : TRUSTED { $$ = true; }
5178 : 19 : | /*EMPTY*/ { $$ = false; }
5179 : : ;
5180 : :
5181 : : /* This ought to be just func_name, but that causes reduce/reduce conflicts
5182 : : * (CREATE LANGUAGE is the only place where func_name isn't followed by '(').
5183 : : * Work around by using simple names, instead.
5184 : : */
5185 : : handler_name:
7810 tgl@sss.pgh.pa.us 5186 : 282 : name { $$ = list_make1(makeString($1)); }
5187 : 1 : | name attrs { $$ = lcons(makeString($1), $2); }
5188 : : ;
5189 : :
5190 : : opt_inline_handler:
5879 5191 : 62 : INLINE_P handler_name { $$ = $2; }
5192 : 9 : | /*EMPTY*/ { $$ = NIL; }
5193 : : ;
5194 : :
5195 : : validator_clause:
7357 5196 : 62 : VALIDATOR handler_name { $$ = $2; }
6089 peter_e@gmx.net 5197 :UBC 0 : | NO VALIDATOR { $$ = NIL; }
5198 : : ;
5199 : :
5200 : : opt_validator:
6089 peter_e@gmx.net 5201 :CBC 62 : validator_clause { $$ = $1; }
7357 tgl@sss.pgh.pa.us 5202 : 9 : | /*EMPTY*/ { $$ = NIL; }
5203 : : ;
5204 : :
5205 : : opt_procedural:
5206 : : PROCEDURAL
5207 : : | /*EMPTY*/
5208 : : ;
5209 : :
5210 : : /*****************************************************************************
5211 : : *
5212 : : * QUERY:
5213 : : * CREATE TABLESPACE tablespace LOCATION '/path/to/tablespace/'
5214 : : *
5215 : : *****************************************************************************/
5216 : :
5217 : : CreateTableSpaceStmt: CREATE TABLESPACE name OptTableSpaceOwner LOCATION Sconst opt_reloptions
5218 : : {
7801 5219 : 67 : CreateTableSpaceStmt *n = makeNode(CreateTableSpaceStmt);
5220 : :
5221 : 67 : n->tablespacename = $3;
5222 : 67 : n->owner = $4;
5223 : 67 : n->location = $6;
4300 sfrost@snowman.net 5224 : 67 : n->options = $7;
7801 tgl@sss.pgh.pa.us 5225 : 67 : $$ = (Node *) n;
5226 : : }
5227 : : ;
5228 : :
3885 alvherre@alvh.no-ip. 5229 : 5 : OptTableSpaceOwner: OWNER RoleSpec { $$ = $2; }
7801 tgl@sss.pgh.pa.us 5230 : 62 : | /*EMPTY */ { $$ = NULL; }
5231 : : ;
5232 : :
5233 : : /*****************************************************************************
5234 : : *
5235 : : * QUERY :
5236 : : * DROP TABLESPACE <tablespace>
5237 : : *
5238 : : * No need for drop behaviour as we cannot implement dependencies for
5239 : : * objects in other databases; we can only support RESTRICT.
5240 : : *
5241 : : ****************************************************************************/
5242 : :
5243 : : DropTableSpaceStmt: DROP TABLESPACE name
5244 : : {
5245 : 32 : DropTableSpaceStmt *n = makeNode(DropTableSpaceStmt);
5246 : :
5247 : 32 : n->tablespacename = $3;
7073 andrew@dunslane.net 5248 : 32 : n->missing_ok = false;
5249 : 32 : $$ = (Node *) n;
5250 : : }
5251 : : | DROP TABLESPACE IF_P EXISTS name
5252 : : {
7073 andrew@dunslane.net 5253 :UBC 0 : DropTableSpaceStmt *n = makeNode(DropTableSpaceStmt);
5254 : :
5255 : 0 : n->tablespacename = $5;
5256 : 0 : n->missing_ok = true;
7801 tgl@sss.pgh.pa.us 5257 : 0 : $$ = (Node *) n;
5258 : : }
5259 : : ;
5260 : :
5261 : : /*****************************************************************************
5262 : : *
5263 : : * QUERY:
5264 : : * CREATE EXTENSION extension
5265 : : * [ WITH ] [ SCHEMA schema ] [ VERSION version ]
5266 : : *
5267 : : *****************************************************************************/
5268 : :
5269 : : CreateExtensionStmt: CREATE EXTENSION name opt_with create_extension_opt_list
5270 : : {
5375 tgl@sss.pgh.pa.us 5271 :CBC 238 : CreateExtensionStmt *n = makeNode(CreateExtensionStmt);
5272 : :
5273 : 238 : n->extname = $3;
5351 5274 : 238 : n->if_not_exists = false;
5375 5275 : 238 : n->options = $5;
5276 : 238 : $$ = (Node *) n;
5277 : : }
5278 : : | CREATE EXTENSION IF_P NOT EXISTS name opt_with create_extension_opt_list
5279 : : {
5351 5280 : 10 : CreateExtensionStmt *n = makeNode(CreateExtensionStmt);
5281 : :
5282 : 10 : n->extname = $6;
5283 : 10 : n->if_not_exists = true;
5284 : 10 : n->options = $8;
5285 : 10 : $$ = (Node *) n;
5286 : : }
5287 : : ;
5288 : :
5289 : : create_extension_opt_list:
5290 : : create_extension_opt_list create_extension_opt_item
5375 5291 : 49 : { $$ = lappend($1, $2); }
5292 : : | /* EMPTY */
5293 : 248 : { $$ = NIL; }
5294 : : ;
5295 : :
5296 : : create_extension_opt_item:
5297 : : SCHEMA name
5298 : : {
1263 peter@eisentraut.org 5299 : 23 : $$ = makeDefElem("schema", (Node *) makeString($2), @1);
5300 : : }
5301 : : | VERSION_P NonReservedWord_or_Sconst
5302 : : {
5303 : 6 : $$ = makeDefElem("new_version", (Node *) makeString($2), @1);
5304 : : }
5305 : : | FROM NonReservedWord_or_Sconst
5306 : : {
2077 tgl@sss.pgh.pa.us 5307 [ # # ]:UBC 0 : ereport(ERROR,
5308 : : (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
5309 : : errmsg("CREATE EXTENSION ... FROM is no longer supported"),
5310 : : parser_errposition(@1)));
5311 : : }
5312 : : | CASCADE
5313 : : {
1263 peter@eisentraut.org 5314 :CBC 20 : $$ = makeDefElem("cascade", (Node *) makeBoolean(true), @1);
5315 : : }
5316 : : ;
5317 : :
5318 : : /*****************************************************************************
5319 : : *
5320 : : * ALTER EXTENSION name UPDATE [ TO version ]
5321 : : *
5322 : : *****************************************************************************/
5323 : :
5324 : : AlterExtensionStmt: ALTER EXTENSION name UPDATE alter_extension_opt_list
5325 : : {
5372 tgl@sss.pgh.pa.us 5326 : 20 : AlterExtensionStmt *n = makeNode(AlterExtensionStmt);
5327 : :
5328 : 20 : n->extname = $3;
5329 : 20 : n->options = $5;
5330 : 20 : $$ = (Node *) n;
5331 : : }
5332 : : ;
5333 : :
5334 : : alter_extension_opt_list:
5335 : : alter_extension_opt_list alter_extension_opt_item
5336 : 20 : { $$ = lappend($1, $2); }
5337 : : | /* EMPTY */
5338 : 20 : { $$ = NIL; }
5339 : : ;
5340 : :
5341 : : alter_extension_opt_item:
5342 : : TO NonReservedWord_or_Sconst
5343 : : {
1263 peter@eisentraut.org 5344 : 20 : $$ = makeDefElem("new_version", (Node *) makeString($2), @1);
5345 : : }
5346 : : ;
5347 : :
5348 : : /*****************************************************************************
5349 : : *
5350 : : * ALTER EXTENSION name ADD/DROP object-identifier
5351 : : *
5352 : : *****************************************************************************/
5353 : :
5354 : : AlterExtensionContentsStmt:
5355 : : ALTER EXTENSION name add_drop object_type_name name
5356 : : {
3312 tgl@sss.pgh.pa.us 5357 : 9 : AlterExtensionContentsStmt *n = makeNode(AlterExtensionContentsStmt);
5358 : :
5359 : 9 : n->extname = $3;
5360 : 9 : n->action = $4;
1962 peter@eisentraut.org 5361 : 9 : n->objtype = $5;
5362 : 9 : n->object = (Node *) makeString($6);
1263 5363 : 9 : $$ = (Node *) n;
5364 : : }
5365 : : | ALTER EXTENSION name add_drop object_type_any_name any_name
5366 : : {
5373 tgl@sss.pgh.pa.us 5367 : 44 : AlterExtensionContentsStmt *n = makeNode(AlterExtensionContentsStmt);
5368 : :
5374 5369 : 44 : n->extname = $3;
5373 5370 : 44 : n->action = $4;
1962 peter@eisentraut.org 5371 : 44 : n->objtype = $5;
3271 peter_e@gmx.net 5372 : 44 : n->object = (Node *) $6;
1263 peter@eisentraut.org 5373 : 44 : $$ = (Node *) n;
5374 : : }
5375 : : | ALTER EXTENSION name add_drop AGGREGATE aggregate_with_argtypes
5376 : : {
5371 peter_e@gmx.net 5377 : 4 : AlterExtensionContentsStmt *n = makeNode(AlterExtensionContentsStmt);
5378 : :
5379 : 4 : n->extname = $3;
5380 : 4 : n->action = $4;
1962 peter@eisentraut.org 5381 : 4 : n->objtype = OBJECT_AGGREGATE;
3271 peter_e@gmx.net 5382 : 4 : n->object = (Node *) $6;
1263 peter@eisentraut.org 5383 : 4 : $$ = (Node *) n;
5384 : : }
5385 : : | ALTER EXTENSION name add_drop CAST '(' Typename AS Typename ')'
5386 : : {
5373 tgl@sss.pgh.pa.us 5387 : 2 : AlterExtensionContentsStmt *n = makeNode(AlterExtensionContentsStmt);
5388 : :
5374 5389 : 2 : n->extname = $3;
5373 5390 : 2 : n->action = $4;
1962 peter@eisentraut.org 5391 : 2 : n->objtype = OBJECT_CAST;
5392 : 2 : n->object = (Node *) list_make2($7, $9);
5393 : 2 : $$ = (Node *) n;
5394 : : }
5395 : : | ALTER EXTENSION name add_drop DOMAIN_P Typename
5396 : : {
5373 tgl@sss.pgh.pa.us 5397 :UBC 0 : AlterExtensionContentsStmt *n = makeNode(AlterExtensionContentsStmt);
5398 : :
5374 5399 : 0 : n->extname = $3;
5373 5400 : 0 : n->action = $4;
5374 5401 : 0 : n->objtype = OBJECT_DOMAIN;
3271 peter_e@gmx.net 5402 : 0 : n->object = (Node *) $6;
1263 peter@eisentraut.org 5403 : 0 : $$ = (Node *) n;
5404 : : }
5405 : : | ALTER EXTENSION name add_drop FUNCTION function_with_argtypes
5406 : : {
5373 tgl@sss.pgh.pa.us 5407 :CBC 61 : AlterExtensionContentsStmt *n = makeNode(AlterExtensionContentsStmt);
5408 : :
5374 5409 : 61 : n->extname = $3;
5373 5410 : 61 : n->action = $4;
5374 5411 : 61 : n->objtype = OBJECT_FUNCTION;
3271 peter_e@gmx.net 5412 : 61 : n->object = (Node *) $6;
1263 peter@eisentraut.org 5413 : 61 : $$ = (Node *) n;
5414 : : }
5415 : : | ALTER EXTENSION name add_drop OPERATOR operator_with_argtypes
5416 : : {
5373 tgl@sss.pgh.pa.us 5417 : 9 : AlterExtensionContentsStmt *n = makeNode(AlterExtensionContentsStmt);
5418 : :
5374 5419 : 9 : n->extname = $3;
5373 5420 : 9 : n->action = $4;
5374 5421 : 9 : n->objtype = OBJECT_OPERATOR;
3271 peter_e@gmx.net 5422 : 9 : n->object = (Node *) $6;
1263 peter@eisentraut.org 5423 : 9 : $$ = (Node *) n;
5424 : : }
5425 : : | ALTER EXTENSION name add_drop OPERATOR CLASS any_name USING name
5426 : : {
5373 tgl@sss.pgh.pa.us 5427 : 2 : AlterExtensionContentsStmt *n = makeNode(AlterExtensionContentsStmt);
5428 : :
5374 5429 : 2 : n->extname = $3;
5373 5430 : 2 : n->action = $4;
5374 5431 : 2 : n->objtype = OBJECT_OPCLASS;
3271 peter_e@gmx.net 5432 : 2 : n->object = (Node *) lcons(makeString($9), $7);
1263 peter@eisentraut.org 5433 : 2 : $$ = (Node *) n;
5434 : : }
5435 : : | ALTER EXTENSION name add_drop OPERATOR FAMILY any_name USING name
5436 : : {
5373 tgl@sss.pgh.pa.us 5437 : 2 : AlterExtensionContentsStmt *n = makeNode(AlterExtensionContentsStmt);
5438 : :
5374 5439 : 2 : n->extname = $3;
5373 5440 : 2 : n->action = $4;
5374 5441 : 2 : n->objtype = OBJECT_OPFAMILY;
3271 peter_e@gmx.net 5442 : 2 : n->object = (Node *) lcons(makeString($9), $7);
1263 peter@eisentraut.org 5443 : 2 : $$ = (Node *) n;
5444 : : }
5445 : : | ALTER EXTENSION name add_drop PROCEDURE function_with_argtypes
5446 : : {
2888 peter_e@gmx.net 5447 :UBC 0 : AlterExtensionContentsStmt *n = makeNode(AlterExtensionContentsStmt);
5448 : :
5449 : 0 : n->extname = $3;
5450 : 0 : n->action = $4;
5451 : 0 : n->objtype = OBJECT_PROCEDURE;
5452 : 0 : n->object = (Node *) $6;
1263 peter@eisentraut.org 5453 : 0 : $$ = (Node *) n;
5454 : : }
5455 : : | ALTER EXTENSION name add_drop ROUTINE function_with_argtypes
5456 : : {
2888 peter_e@gmx.net 5457 : 0 : AlterExtensionContentsStmt *n = makeNode(AlterExtensionContentsStmt);
5458 : :
5459 : 0 : n->extname = $3;
5460 : 0 : n->action = $4;
5461 : 0 : n->objtype = OBJECT_ROUTINE;
5462 : 0 : n->object = (Node *) $6;
1263 peter@eisentraut.org 5463 : 0 : $$ = (Node *) n;
5464 : : }
5465 : : | ALTER EXTENSION name add_drop TRANSFORM FOR Typename LANGUAGE name
5466 : : {
3837 peter_e@gmx.net 5467 :CBC 2 : AlterExtensionContentsStmt *n = makeNode(AlterExtensionContentsStmt);
5468 : :
5469 : 2 : n->extname = $3;
5470 : 2 : n->action = $4;
5471 : 2 : n->objtype = OBJECT_TRANSFORM;
3271 5472 : 2 : n->object = (Node *) list_make2($7, makeString($9));
1263 peter@eisentraut.org 5473 : 2 : $$ = (Node *) n;
5474 : : }
5475 : : | ALTER EXTENSION name add_drop TYPE_P Typename
5476 : : {
5373 tgl@sss.pgh.pa.us 5477 : 4 : AlterExtensionContentsStmt *n = makeNode(AlterExtensionContentsStmt);
5478 : :
5374 5479 : 4 : n->extname = $3;
5373 5480 : 4 : n->action = $4;
5374 5481 : 4 : n->objtype = OBJECT_TYPE;
3271 peter_e@gmx.net 5482 : 4 : n->object = (Node *) $6;
1263 peter@eisentraut.org 5483 : 4 : $$ = (Node *) n;
5484 : : }
5485 : : ;
5486 : :
5487 : : /*****************************************************************************
5488 : : *
5489 : : * QUERY:
5490 : : * CREATE FOREIGN DATA WRAPPER name options
5491 : : *
5492 : : *****************************************************************************/
5493 : :
5494 : : CreateFdwStmt: CREATE FOREIGN DATA_P WRAPPER name opt_fdw_options create_generic_options
5495 : : {
6156 peter_e@gmx.net 5496 : 106 : CreateFdwStmt *n = makeNode(CreateFdwStmt);
5497 : :
5498 : 106 : n->fdwname = $5;
5364 tgl@sss.pgh.pa.us 5499 : 106 : n->func_options = $6;
6089 peter_e@gmx.net 5500 : 106 : n->options = $7;
6156 5501 : 106 : $$ = (Node *) n;
5502 : : }
5503 : : ;
5504 : :
5505 : : fdw_option:
1263 peter@eisentraut.org 5506 : 30 : HANDLER handler_name { $$ = makeDefElem("handler", (Node *) $2, @1); }
3338 peter_e@gmx.net 5507 :UBC 0 : | NO HANDLER { $$ = makeDefElem("handler", NULL, @1); }
1263 peter@eisentraut.org 5508 :CBC 27 : | VALIDATOR handler_name { $$ = makeDefElem("validator", (Node *) $2, @1); }
3338 peter_e@gmx.net 5509 : 3 : | NO VALIDATOR { $$ = makeDefElem("validator", NULL, @1); }
5510 : : ;
5511 : :
5512 : : fdw_options:
5364 tgl@sss.pgh.pa.us 5513 : 48 : fdw_option { $$ = list_make1($1); }
5514 : 12 : | fdw_options fdw_option { $$ = lappend($1, $2); }
5515 : : ;
5516 : :
5517 : : opt_fdw_options:
5518 : 30 : fdw_options { $$ = $1; }
5519 : 122 : | /*EMPTY*/ { $$ = NIL; }
5520 : : ;
5521 : :
5522 : : /*****************************************************************************
5523 : : *
5524 : : * QUERY :
5525 : : * ALTER FOREIGN DATA WRAPPER name options
5526 : : *
5527 : : ****************************************************************************/
5528 : :
5529 : : AlterFdwStmt: ALTER FOREIGN DATA_P WRAPPER name opt_fdw_options alter_generic_options
5530 : : {
6156 peter_e@gmx.net 5531 : 43 : AlterFdwStmt *n = makeNode(AlterFdwStmt);
5532 : :
5533 : 43 : n->fdwname = $5;
5364 tgl@sss.pgh.pa.us 5534 : 43 : n->func_options = $6;
6089 peter_e@gmx.net 5535 : 43 : n->options = $7;
6156 5536 : 43 : $$ = (Node *) n;
5537 : : }
5538 : : | ALTER FOREIGN DATA_P WRAPPER name fdw_options
5539 : : {
5540 : 18 : AlterFdwStmt *n = makeNode(AlterFdwStmt);
5541 : :
5542 : 18 : n->fdwname = $5;
5364 tgl@sss.pgh.pa.us 5543 : 18 : n->func_options = $6;
5544 : 18 : n->options = NIL;
6156 peter_e@gmx.net 5545 : 18 : $$ = (Node *) n;
5546 : : }
5547 : : ;
5548 : :
5549 : : /* Options definition for CREATE FDW, SERVER and USER MAPPING */
5550 : : create_generic_options:
6050 tgl@sss.pgh.pa.us 5551 : 379 : OPTIONS '(' generic_option_list ')' { $$ = $3; }
5552 : 34366 : | /*EMPTY*/ { $$ = NIL; }
5553 : : ;
5554 : :
5555 : : generic_option_list:
5556 : : generic_option_elem
5557 : : {
5558 : 379 : $$ = list_make1($1);
5559 : : }
5560 : : | generic_option_list ',' generic_option_elem
5561 : : {
5562 : 248 : $$ = lappend($1, $3);
5563 : : }
5564 : : ;
5565 : :
5566 : : /* Options definition for ALTER FDW, SERVER and USER MAPPING */
5567 : : alter_generic_options:
5568 : 254 : OPTIONS '(' alter_generic_option_list ')' { $$ = $3; }
5569 : : ;
5570 : :
5571 : : alter_generic_option_list:
5572 : : alter_generic_option_elem
5573 : : {
5574 : 254 : $$ = list_make1($1);
5575 : : }
5576 : : | alter_generic_option_list ',' alter_generic_option_elem
5577 : : {
5578 : 84 : $$ = lappend($1, $3);
5579 : : }
5580 : : ;
5581 : :
5582 : : alter_generic_option_elem:
5583 : : generic_option_elem
5584 : : {
5585 : 100 : $$ = $1;
5586 : : }
5587 : : | SET generic_option_elem
5588 : : {
5589 : 64 : $$ = $2;
5590 : 64 : $$->defaction = DEFELEM_SET;
5591 : : }
5592 : : | ADD_P generic_option_elem
5593 : : {
5594 : 110 : $$ = $2;
5595 : 110 : $$->defaction = DEFELEM_ADD;
5596 : : }
5597 : : | DROP generic_option_name
5598 : : {
3338 peter_e@gmx.net 5599 : 64 : $$ = makeDefElemExtended(NULL, $2, NULL, DEFELEM_DROP, @2);
5600 : : }
5601 : : ;
5602 : :
5603 : : generic_option_elem:
5604 : : generic_option_name generic_option_arg
5605 : : {
5606 : 901 : $$ = makeDefElem($1, $2, @1);
5607 : : }
5608 : : ;
5609 : :
5610 : : generic_option_name:
6050 tgl@sss.pgh.pa.us 5611 : 965 : ColLabel { $$ = $1; }
5612 : : ;
5613 : :
5614 : : /* We could use def_arg here, but the spec only requires string literals */
5615 : : generic_option_arg:
5616 : 901 : Sconst { $$ = (Node *) makeString($1); }
5617 : : ;
5618 : :
5619 : : /*****************************************************************************
5620 : : *
5621 : : * QUERY:
5622 : : * CREATE SERVER name [TYPE] [VERSION] [OPTIONS]
5623 : : *
5624 : : *****************************************************************************/
5625 : :
5626 : : CreateForeignServerStmt: CREATE SERVER name opt_type opt_foreign_server_version
5627 : : FOREIGN DATA_P WRAPPER name create_generic_options
5628 : : {
6156 peter_e@gmx.net 5629 : 139 : CreateForeignServerStmt *n = makeNode(CreateForeignServerStmt);
5630 : :
5631 : 139 : n->servername = $3;
5632 : 139 : n->servertype = $4;
5633 : 139 : n->version = $5;
5634 : 139 : n->fdwname = $9;
5635 : 139 : n->options = $10;
3143 andrew@dunslane.net 5636 : 139 : n->if_not_exists = false;
5637 : 139 : $$ = (Node *) n;
5638 : : }
5639 : : | CREATE SERVER IF_P NOT EXISTS name opt_type opt_foreign_server_version
5640 : : FOREIGN DATA_P WRAPPER name create_generic_options
5641 : : {
5642 : 12 : CreateForeignServerStmt *n = makeNode(CreateForeignServerStmt);
5643 : :
5644 : 12 : n->servername = $6;
5645 : 12 : n->servertype = $7;
5646 : 12 : n->version = $8;
5647 : 12 : n->fdwname = $12;
5648 : 12 : n->options = $13;
5649 : 12 : n->if_not_exists = true;
6156 peter_e@gmx.net 5650 : 12 : $$ = (Node *) n;
5651 : : }
5652 : : ;
5653 : :
5654 : : opt_type:
5655 : 9 : TYPE_P Sconst { $$ = $2; }
5656 : 142 : | /*EMPTY*/ { $$ = NULL; }
5657 : : ;
5658 : :
5659 : :
5660 : : foreign_server_version:
5661 : 33 : VERSION_P Sconst { $$ = $2; }
6156 peter_e@gmx.net 5662 :UBC 0 : | VERSION_P NULL_P { $$ = NULL; }
5663 : : ;
5664 : :
5665 : : opt_foreign_server_version:
5109 peter_e@gmx.net 5666 :CBC 9 : foreign_server_version { $$ = $1; }
6156 5667 : 142 : | /*EMPTY*/ { $$ = NULL; }
5668 : : ;
5669 : :
5670 : : /*****************************************************************************
5671 : : *
5672 : : * QUERY :
5673 : : * ALTER SERVER name [VERSION] [OPTIONS]
5674 : : *
5675 : : ****************************************************************************/
5676 : :
5677 : : AlterForeignServerStmt: ALTER SERVER name foreign_server_version alter_generic_options
5678 : : {
5679 : 3 : AlterForeignServerStmt *n = makeNode(AlterForeignServerStmt);
5680 : :
5681 : 3 : n->servername = $3;
5682 : 3 : n->version = $4;
5683 : 3 : n->options = $5;
5684 : 3 : n->has_version = true;
5685 : 3 : $$ = (Node *) n;
5686 : : }
5687 : : | ALTER SERVER name foreign_server_version
5688 : : {
5689 : 21 : AlterForeignServerStmt *n = makeNode(AlterForeignServerStmt);
5690 : :
5691 : 21 : n->servername = $3;
5692 : 21 : n->version = $4;
5693 : 21 : n->has_version = true;
5694 : 21 : $$ = (Node *) n;
5695 : : }
5696 : : | ALTER SERVER name alter_generic_options
5697 : : {
5698 : 92 : AlterForeignServerStmt *n = makeNode(AlterForeignServerStmt);
5699 : :
5700 : 92 : n->servername = $3;
5701 : 92 : n->options = $4;
5702 : 92 : $$ = (Node *) n;
5703 : : }
5704 : : ;
5705 : :
5706 : : /*****************************************************************************
5707 : : *
5708 : : * QUERY:
5709 : : * CREATE FOREIGN TABLE relname (...) SERVER name (...)
5710 : : *
5711 : : *****************************************************************************/
5712 : :
5713 : : CreateForeignTableStmt:
5714 : : CREATE FOREIGN TABLE qualified_name
5715 : : '(' OptTableElementList ')'
5716 : : OptInherit SERVER name create_generic_options
5717 : : {
5413 rhaas@postgresql.org 5718 : 202 : CreateForeignTableStmt *n = makeNode(CreateForeignTableStmt);
5719 : :
5720 : 202 : $4->relpersistence = RELPERSISTENCE_PERMANENT;
5721 : 202 : n->base.relation = $4;
4612 tgl@sss.pgh.pa.us 5722 : 202 : n->base.tableElts = $6;
3872 5723 : 202 : n->base.inhRelations = $8;
5724 : 202 : n->base.ofTypename = NULL;
5725 : 202 : n->base.constraints = NIL;
5726 : 202 : n->base.options = NIL;
5727 : 202 : n->base.oncommit = ONCOMMIT_NOOP;
5728 : 202 : n->base.tablespacename = NULL;
5413 rhaas@postgresql.org 5729 : 202 : n->base.if_not_exists = false;
5730 : : /* FDW-specific data */
3872 tgl@sss.pgh.pa.us 5731 : 202 : n->servername = $10;
5732 : 202 : n->options = $11;
5413 rhaas@postgresql.org 5733 : 202 : $$ = (Node *) n;
5734 : : }
5735 : : | CREATE FOREIGN TABLE IF_P NOT EXISTS qualified_name
5736 : : '(' OptTableElementList ')'
5737 : : OptInherit SERVER name create_generic_options
5738 : : {
5413 rhaas@postgresql.org 5739 :UBC 0 : CreateForeignTableStmt *n = makeNode(CreateForeignTableStmt);
5740 : :
5741 : 0 : $7->relpersistence = RELPERSISTENCE_PERMANENT;
5742 : 0 : n->base.relation = $7;
4612 tgl@sss.pgh.pa.us 5743 : 0 : n->base.tableElts = $9;
3872 5744 : 0 : n->base.inhRelations = $11;
5745 : 0 : n->base.ofTypename = NULL;
5746 : 0 : n->base.constraints = NIL;
5747 : 0 : n->base.options = NIL;
5748 : 0 : n->base.oncommit = ONCOMMIT_NOOP;
5749 : 0 : n->base.tablespacename = NULL;
5413 rhaas@postgresql.org 5750 : 0 : n->base.if_not_exists = true;
5751 : : /* FDW-specific data */
3872 tgl@sss.pgh.pa.us 5752 : 0 : n->servername = $13;
5753 : 0 : n->options = $14;
5413 rhaas@postgresql.org 5754 : 0 : $$ = (Node *) n;
5755 : : }
5756 : : | CREATE FOREIGN TABLE qualified_name
5757 : : PARTITION OF qualified_name OptTypedTableElementList PartitionBoundSpec
5758 : : SERVER name create_generic_options
5759 : : {
3246 rhaas@postgresql.org 5760 :CBC 45 : CreateForeignTableStmt *n = makeNode(CreateForeignTableStmt);
5761 : :
5762 : 45 : $4->relpersistence = RELPERSISTENCE_PERMANENT;
5763 : 45 : n->base.relation = $4;
5764 : 45 : n->base.inhRelations = list_make1($7);
5765 : 45 : n->base.tableElts = $8;
3074 tgl@sss.pgh.pa.us 5766 : 45 : n->base.partbound = $9;
3246 rhaas@postgresql.org 5767 : 45 : n->base.ofTypename = NULL;
5768 : 45 : n->base.constraints = NIL;
5769 : 45 : n->base.options = NIL;
5770 : 45 : n->base.oncommit = ONCOMMIT_NOOP;
5771 : 45 : n->base.tablespacename = NULL;
5772 : 45 : n->base.if_not_exists = false;
5773 : : /* FDW-specific data */
5774 : 45 : n->servername = $11;
5775 : 45 : n->options = $12;
5776 : 45 : $$ = (Node *) n;
5777 : : }
5778 : : | CREATE FOREIGN TABLE IF_P NOT EXISTS qualified_name
5779 : : PARTITION OF qualified_name OptTypedTableElementList PartitionBoundSpec
5780 : : SERVER name create_generic_options
5781 : : {
3246 rhaas@postgresql.org 5782 :UBC 0 : CreateForeignTableStmt *n = makeNode(CreateForeignTableStmt);
5783 : :
5784 : 0 : $7->relpersistence = RELPERSISTENCE_PERMANENT;
5785 : 0 : n->base.relation = $7;
5786 : 0 : n->base.inhRelations = list_make1($10);
5787 : 0 : n->base.tableElts = $11;
3074 tgl@sss.pgh.pa.us 5788 : 0 : n->base.partbound = $12;
3246 rhaas@postgresql.org 5789 : 0 : n->base.ofTypename = NULL;
5790 : 0 : n->base.constraints = NIL;
5791 : 0 : n->base.options = NIL;
5792 : 0 : n->base.oncommit = ONCOMMIT_NOOP;
5793 : 0 : n->base.tablespacename = NULL;
5794 : 0 : n->base.if_not_exists = true;
5795 : : /* FDW-specific data */
5796 : 0 : n->servername = $14;
5797 : 0 : n->options = $15;
5798 : 0 : $$ = (Node *) n;
5799 : : }
5800 : : ;
5801 : :
5802 : : /*****************************************************************************
5803 : : *
5804 : : * QUERY:
5805 : : * IMPORT FOREIGN SCHEMA remote_schema
5806 : : * [ { LIMIT TO | EXCEPT } ( table_list ) ]
5807 : : * FROM SERVER server_name INTO local_schema [ OPTIONS (...) ]
5808 : : *
5809 : : ****************************************************************************/
5810 : :
5811 : : ImportForeignSchemaStmt:
5812 : : IMPORT_P FOREIGN SCHEMA name import_qualification
5813 : : FROM SERVER name INTO name create_generic_options
5814 : : {
4127 tgl@sss.pgh.pa.us 5815 :CBC 24 : ImportForeignSchemaStmt *n = makeNode(ImportForeignSchemaStmt);
5816 : :
5817 : 24 : n->server_name = $8;
5818 : 24 : n->remote_schema = $4;
5819 : 24 : n->local_schema = $10;
5820 : 24 : n->list_type = $5->type;
5821 : 24 : n->table_list = $5->table_names;
5822 : 24 : n->options = $11;
5823 : 24 : $$ = (Node *) n;
5824 : : }
5825 : : ;
5826 : :
5827 : : import_qualification_type:
1811 peter@eisentraut.org 5828 : 7 : LIMIT TO { $$ = FDW_IMPORT_SCHEMA_LIMIT_TO; }
5829 : 7 : | EXCEPT { $$ = FDW_IMPORT_SCHEMA_EXCEPT; }
5830 : : ;
5831 : :
5832 : : import_qualification:
5833 : : import_qualification_type '(' relation_expr_list ')'
5834 : : {
4127 tgl@sss.pgh.pa.us 5835 : 14 : ImportQual *n = (ImportQual *) palloc(sizeof(ImportQual));
5836 : :
5837 : 14 : n->type = $1;
5838 : 14 : n->table_names = $3;
5839 : 14 : $$ = n;
5840 : : }
5841 : : | /*EMPTY*/
5842 : : {
5843 : 10 : ImportQual *n = (ImportQual *) palloc(sizeof(ImportQual));
5844 : 10 : n->type = FDW_IMPORT_SCHEMA_ALL;
5845 : 10 : n->table_names = NIL;
5846 : 10 : $$ = n;
5847 : : }
5848 : : ;
5849 : :
5850 : : /*****************************************************************************
5851 : : *
5852 : : * QUERY:
5853 : : * CREATE USER MAPPING FOR auth_ident SERVER name [OPTIONS]
5854 : : *
5855 : : *****************************************************************************/
5856 : :
5857 : : CreateUserMappingStmt: CREATE USER MAPPING FOR auth_ident SERVER name create_generic_options
5858 : : {
6156 peter_e@gmx.net 5859 : 126 : CreateUserMappingStmt *n = makeNode(CreateUserMappingStmt);
5860 : :
3885 alvherre@alvh.no-ip. 5861 : 126 : n->user = $5;
6156 peter_e@gmx.net 5862 : 126 : n->servername = $7;
5863 : 126 : n->options = $8;
3143 andrew@dunslane.net 5864 : 126 : n->if_not_exists = false;
5865 : 126 : $$ = (Node *) n;
5866 : : }
5867 : : | CREATE USER MAPPING IF_P NOT EXISTS FOR auth_ident SERVER name create_generic_options
5868 : : {
5869 : 3 : CreateUserMappingStmt *n = makeNode(CreateUserMappingStmt);
5870 : :
5871 : 3 : n->user = $8;
5872 : 3 : n->servername = $10;
5873 : 3 : n->options = $11;
5874 : 3 : n->if_not_exists = true;
6156 peter_e@gmx.net 5875 : 3 : $$ = (Node *) n;
5876 : : }
5877 : : ;
5878 : :
5879 : : /* User mapping authorization identifier */
3885 alvherre@alvh.no-ip. 5880 : 228 : auth_ident: RoleSpec { $$ = $1; }
5881 : 23 : | USER { $$ = makeRoleSpec(ROLESPEC_CURRENT_USER, @1); }
5882 : : ;
5883 : :
5884 : : /*****************************************************************************
5885 : : *
5886 : : * QUERY :
5887 : : * DROP USER MAPPING FOR auth_ident SERVER name
5888 : : *
5889 : : * XXX you'd think this should have a CASCADE/RESTRICT option, even if it's
5890 : : * only pro forma; but the SQL standard doesn't show one.
5891 : : ****************************************************************************/
5892 : :
5893 : : DropUserMappingStmt: DROP USER MAPPING FOR auth_ident SERVER name
5894 : : {
6156 peter_e@gmx.net 5895 : 44 : DropUserMappingStmt *n = makeNode(DropUserMappingStmt);
5896 : :
3885 alvherre@alvh.no-ip. 5897 : 44 : n->user = $5;
6156 peter_e@gmx.net 5898 : 44 : n->servername = $7;
5899 : 44 : n->missing_ok = false;
5900 : 44 : $$ = (Node *) n;
5901 : : }
5902 : : | DROP USER MAPPING IF_P EXISTS FOR auth_ident SERVER name
5903 : : {
5904 : 19 : DropUserMappingStmt *n = makeNode(DropUserMappingStmt);
5905 : :
3885 alvherre@alvh.no-ip. 5906 : 19 : n->user = $7;
6156 peter_e@gmx.net 5907 : 19 : n->servername = $9;
5908 : 19 : n->missing_ok = true;
5909 : 19 : $$ = (Node *) n;
5910 : : }
5911 : : ;
5912 : :
5913 : : /*****************************************************************************
5914 : : *
5915 : : * QUERY :
5916 : : * ALTER USER MAPPING FOR auth_ident SERVER name OPTIONS
5917 : : *
5918 : : ****************************************************************************/
5919 : :
5920 : : AlterUserMappingStmt: ALTER USER MAPPING FOR auth_ident SERVER name alter_generic_options
5921 : : {
5922 : 59 : AlterUserMappingStmt *n = makeNode(AlterUserMappingStmt);
5923 : :
3885 alvherre@alvh.no-ip. 5924 : 59 : n->user = $5;
6156 peter_e@gmx.net 5925 : 59 : n->servername = $7;
5926 : 59 : n->options = $8;
5927 : 59 : $$ = (Node *) n;
5928 : : }
5929 : : ;
5930 : :
5931 : : /*****************************************************************************
5932 : : *
5933 : : * QUERIES:
5934 : : * CREATE POLICY name ON table
5935 : : * [AS { PERMISSIVE | RESTRICTIVE } ]
5936 : : * [FOR { SELECT | INSERT | UPDATE | DELETE } ]
5937 : : * [TO role, ...]
5938 : : * [USING (qual)] [WITH CHECK (with check qual)]
5939 : : * ALTER POLICY name ON table [TO role, ...]
5940 : : * [USING (qual)] [WITH CHECK (with check qual)]
5941 : : *
5942 : : *****************************************************************************/
5943 : :
5944 : : CreatePolicyStmt:
5945 : : CREATE POLICY name ON qualified_name RowSecurityDefaultPermissive
5946 : : RowSecurityDefaultForCmd RowSecurityDefaultToRole
5947 : : RowSecurityOptionalExpr RowSecurityOptionalWithCheck
5948 : : {
4056 sfrost@snowman.net 5949 : 368 : CreatePolicyStmt *n = makeNode(CreatePolicyStmt);
5950 : :
5951 : 368 : n->policy_name = $3;
5952 : 368 : n->table = $5;
3248 5953 : 368 : n->permissive = $6;
5954 : 368 : n->cmd_name = $7;
5955 : 368 : n->roles = $8;
5956 : 368 : n->qual = $9;
5957 : 368 : n->with_check = $10;
4056 5958 : 368 : $$ = (Node *) n;
5959 : : }
5960 : : ;
5961 : :
5962 : : AlterPolicyStmt:
5963 : : ALTER POLICY name ON qualified_name RowSecurityOptionalToRole
5964 : : RowSecurityOptionalExpr RowSecurityOptionalWithCheck
5965 : : {
5966 : 42 : AlterPolicyStmt *n = makeNode(AlterPolicyStmt);
5967 : :
5968 : 42 : n->policy_name = $3;
5969 : 42 : n->table = $5;
5970 : 42 : n->roles = $6;
5971 : 42 : n->qual = $7;
5972 : 42 : n->with_check = $8;
5973 : 42 : $$ = (Node *) n;
5974 : : }
5975 : : ;
5976 : :
5977 : : RowSecurityOptionalExpr:
5978 : 381 : USING '(' a_expr ')' { $$ = $3; }
5979 : 29 : | /* EMPTY */ { $$ = NULL; }
5980 : : ;
5981 : :
5982 : : RowSecurityOptionalWithCheck:
5983 : 61 : WITH CHECK '(' a_expr ')' { $$ = $4; }
5984 : 349 : | /* EMPTY */ { $$ = NULL; }
5985 : : ;
5986 : :
5987 : : RowSecurityDefaultToRole:
5988 : 65 : TO role_list { $$ = $2; }
3885 alvherre@alvh.no-ip. 5989 : 303 : | /* EMPTY */ { $$ = list_make1(makeRoleSpec(ROLESPEC_PUBLIC, -1)); }
5990 : : ;
5991 : :
5992 : : RowSecurityOptionalToRole:
4056 sfrost@snowman.net 5993 : 6 : TO role_list { $$ = $2; }
5994 : 36 : | /* EMPTY */ { $$ = NULL; }
5995 : : ;
5996 : :
5997 : : RowSecurityDefaultPermissive:
5998 : : AS IDENT
5999 : : {
3248 6000 [ + + ]: 49 : if (strcmp($2, "permissive") == 0)
6001 : 12 : $$ = true;
6002 [ + + ]: 37 : else if (strcmp($2, "restrictive") == 0)
6003 : 34 : $$ = false;
6004 : : else
6005 [ + - ]: 3 : ereport(ERROR,
6006 : : (errcode(ERRCODE_SYNTAX_ERROR),
6007 : : errmsg("unrecognized row security option \"%s\"", $2),
6008 : : errhint("Only PERMISSIVE or RESTRICTIVE policies are supported currently."),
6009 : : parser_errposition(@2)));
6010 : :
6011 : : }
6012 : 322 : | /* EMPTY */ { $$ = true; }
6013 : : ;
6014 : :
6015 : : RowSecurityDefaultForCmd:
4056 6016 : 160 : FOR row_security_cmd { $$ = $2; }
6017 : 208 : | /* EMPTY */ { $$ = "all"; }
6018 : : ;
6019 : :
6020 : : row_security_cmd:
6021 : 22 : ALL { $$ = "all"; }
6022 : 56 : | SELECT { $$ = "select"; }
6023 : 22 : | INSERT { $$ = "insert"; }
6024 : 39 : | UPDATE { $$ = "update"; }
6025 : 21 : | DELETE_P { $$ = "delete"; }
6026 : : ;
6027 : :
6028 : : /*****************************************************************************
6029 : : *
6030 : : * QUERY:
6031 : : * CREATE ACCESS METHOD name HANDLER handler_name
6032 : : *
6033 : : *****************************************************************************/
6034 : :
6035 : : CreateAmStmt: CREATE ACCESS METHOD name TYPE_P am_type HANDLER handler_name
6036 : : {
3505 alvherre@alvh.no-ip. 6037 : 31 : CreateAmStmt *n = makeNode(CreateAmStmt);
6038 : :
6039 : 31 : n->amname = $4;
6040 : 31 : n->handler_name = $8;
2427 andres@anarazel.de 6041 : 31 : n->amtype = $6;
3505 alvherre@alvh.no-ip. 6042 : 31 : $$ = (Node *) n;
6043 : : }
6044 : : ;
6045 : :
6046 : : am_type:
2427 andres@anarazel.de 6047 : 17 : INDEX { $$ = AMTYPE_INDEX; }
6048 : 14 : | TABLE { $$ = AMTYPE_TABLE; }
6049 : : ;
6050 : :
6051 : : /*****************************************************************************
6052 : : *
6053 : : * QUERIES :
6054 : : * CREATE TRIGGER ...
6055 : : *
6056 : : *****************************************************************************/
6057 : :
6058 : : CreateTrigStmt:
6059 : : CREATE opt_or_replace TRIGGER name TriggerActionTime TriggerEvents ON
6060 : : qualified_name TriggerReferencing TriggerForSpec TriggerWhen
6061 : : EXECUTE FUNCTION_or_PROCEDURE func_name '(' TriggerFuncArgs ')'
6062 : : {
10276 bruce@momjian.us 6063 : 1588 : CreateTrigStmt *n = makeNode(CreateTrigStmt);
6064 : :
1808 tgl@sss.pgh.pa.us 6065 : 1588 : n->replace = $2;
6066 : 1588 : n->isconstraint = false;
6067 : 1588 : n->trigname = $4;
6068 : 1588 : n->relation = $8;
6069 : 1588 : n->funcname = $14;
6070 : 1588 : n->args = $16;
6071 : 1588 : n->row = $10;
6072 : 1588 : n->timing = $5;
6073 : 1588 : n->events = intVal(linitial($6));
6074 : 1588 : n->columns = (List *) lsecond($6);
6075 : 1588 : n->whenClause = $11;
6076 : 1588 : n->transitionRels = $9;
1677 peter@eisentraut.org 6077 : 1588 : n->deferrable = false;
6078 : 1588 : n->initdeferred = false;
8621 tgl@sss.pgh.pa.us 6079 : 1588 : n->constrrel = NULL;
1263 peter@eisentraut.org 6080 : 1588 : $$ = (Node *) n;
6081 : : }
6082 : : | CREATE opt_or_replace CONSTRAINT TRIGGER name AFTER TriggerEvents ON
6083 : : qualified_name OptConstrFromTable ConstraintAttributeSpec
6084 : : FOR EACH ROW TriggerWhen
6085 : : EXECUTE FUNCTION_or_PROCEDURE func_name '(' TriggerFuncArgs ')'
6086 : : {
9525 JanWieck@Yahoo.com 6087 : 40 : CreateTrigStmt *n = makeNode(CreateTrigStmt);
6088 : : bool dummy;
6089 : :
116 alvherre@kurilemu.de 6090 [ + + ]:GNC 40 : if (($11 & CAS_NOT_VALID) != 0)
6091 [ + - ]: 3 : ereport(ERROR,
6092 : : errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
6093 : : errmsg("constraint triggers cannot be marked %s",
6094 : : "NOT VALID"),
6095 : : parser_errposition(@11));
6096 [ + + ]: 37 : if (($11 & CAS_NO_INHERIT) != 0)
6097 [ + - ]: 3 : ereport(ERROR,
6098 : : errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
6099 : : errmsg("constraint triggers cannot be marked %s",
6100 : : "NO INHERIT"),
6101 : : parser_errposition(@11));
6102 [ + + ]: 34 : if (($11 & CAS_NOT_ENFORCED) != 0)
6103 [ + - ]: 3 : ereport(ERROR,
6104 : : errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
6105 : : errmsg("constraint triggers cannot be marked %s",
6106 : : "NOT ENFORCED"),
6107 : : parser_errposition(@11));
6108 : :
1808 tgl@sss.pgh.pa.us 6109 :CBC 31 : n->replace = $2;
6110 [ - + ]: 31 : if (n->replace) /* not supported, see CreateTrigger */
1808 tgl@sss.pgh.pa.us 6111 [ # # ]:UBC 0 : ereport(ERROR,
6112 : : (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
6113 : : errmsg("CREATE OR REPLACE CONSTRAINT TRIGGER is not supported"),
6114 : : parser_errposition(@1)));
1808 tgl@sss.pgh.pa.us 6115 :CBC 31 : n->isconstraint = true;
6116 : 31 : n->trigname = $5;
6117 : 31 : n->relation = $9;
6118 : 31 : n->funcname = $18;
6119 : 31 : n->args = $20;
2994 peter_e@gmx.net 6120 : 31 : n->row = true;
5496 tgl@sss.pgh.pa.us 6121 : 31 : n->timing = TRIGGER_TYPE_AFTER;
1808 6122 : 31 : n->events = intVal(linitial($7));
6123 : 31 : n->columns = (List *) lsecond($7);
6124 : 31 : n->whenClause = $15;
3279 kgrittn@postgresql.o 6125 : 31 : n->transitionRels = NIL;
1808 tgl@sss.pgh.pa.us 6126 : 31 : processCASbits($11, @11, "TRIGGER",
6127 : : &n->deferrable, &n->initdeferred, &dummy,
6128 : : NULL, NULL, yyscanner);
6129 : 31 : n->constrrel = $10;
1263 peter@eisentraut.org 6130 : 31 : $$ = (Node *) n;
6131 : : }
6132 : : ;
6133 : :
6134 : : TriggerActionTime:
5496 tgl@sss.pgh.pa.us 6135 : 718 : BEFORE { $$ = TRIGGER_TYPE_BEFORE; }
6136 : 804 : | AFTER { $$ = TRIGGER_TYPE_AFTER; }
6137 : 72 : | INSTEAD OF { $$ = TRIGGER_TYPE_INSTEAD; }
6138 : : ;
6139 : :
6140 : : TriggerEvents:
6141 : : TriggerOneEvent
5975 6142 : 1634 : { $$ = $1; }
6143 : : | TriggerEvents OR TriggerOneEvent
6144 : : {
1263 peter@eisentraut.org 6145 : 578 : int events1 = intVal(linitial($1));
6146 : 578 : int events2 = intVal(linitial($3));
6147 : 578 : List *columns1 = (List *) lsecond($1);
6148 : 578 : List *columns2 = (List *) lsecond($3);
6149 : :
5857 tgl@sss.pgh.pa.us 6150 [ + + ]: 578 : if (events1 & events2)
5950 6151 : 3 : parser_yyerror("duplicate trigger events specified");
6152 : : /*
6153 : : * concat'ing the columns lists loses information about
6154 : : * which columns went with which event, but so long as
6155 : : * only UPDATE carries columns and we disallow multiple
6156 : : * UPDATE items, it doesn't matter. Command execution
6157 : : * should just ignore the columns for non-UPDATE events.
6158 : : */
5857 6159 : 575 : $$ = list_make2(makeInteger(events1 | events2),
6160 : : list_concat(columns1, columns2));
6161 : : }
6162 : : ;
6163 : :
6164 : : TriggerOneEvent:
6165 : : INSERT
6166 : 840 : { $$ = list_make2(makeInteger(TRIGGER_TYPE_INSERT), NIL); }
6167 : : | DELETE_P
6168 : 443 : { $$ = list_make2(makeInteger(TRIGGER_TYPE_DELETE), NIL); }
6169 : : | UPDATE
6170 : 856 : { $$ = list_make2(makeInteger(TRIGGER_TYPE_UPDATE), NIL); }
6171 : : | UPDATE OF columnList
6172 : 50 : { $$ = list_make2(makeInteger(TRIGGER_TYPE_UPDATE), $3); }
6173 : : | TRUNCATE
6174 : 23 : { $$ = list_make2(makeInteger(TRIGGER_TYPE_TRUNCATE), NIL); }
6175 : : ;
6176 : :
6177 : : TriggerReferencing:
3279 kgrittn@postgresql.o 6178 : 232 : REFERENCING TriggerTransitions { $$ = $2; }
6179 : 1356 : | /*EMPTY*/ { $$ = NIL; }
6180 : : ;
6181 : :
6182 : : TriggerTransitions:
6183 : 232 : TriggerTransition { $$ = list_make1($1); }
6184 : 71 : | TriggerTransitions TriggerTransition { $$ = lappend($1, $2); }
6185 : : ;
6186 : :
6187 : : TriggerTransition:
6188 : : TransitionOldOrNew TransitionRowOrTable opt_as TransitionRelName
6189 : : {
6190 : 303 : TriggerTransition *n = makeNode(TriggerTransition);
6191 : :
6192 : 303 : n->name = $4;
6193 : 303 : n->isNew = $1;
6194 : 303 : n->isTable = $2;
1263 peter@eisentraut.org 6195 : 303 : $$ = (Node *) n;
6196 : : }
6197 : : ;
6198 : :
6199 : : TransitionOldOrNew:
2994 peter_e@gmx.net 6200 : 165 : NEW { $$ = true; }
6201 : 138 : | OLD { $$ = false; }
6202 : : ;
6203 : :
6204 : : TransitionRowOrTable:
6205 : 303 : TABLE { $$ = true; }
6206 : : /*
6207 : : * According to the standard, lack of a keyword here implies ROW.
6208 : : * Support for that would require prohibiting ROW entirely here,
6209 : : * reserving the keyword ROW, and/or requiring AS (instead of
6210 : : * allowing it to be optional, as the standard specifies) as the
6211 : : * next token. Requiring ROW seems cleanest and easiest to
6212 : : * explain.
6213 : : */
2994 peter_e@gmx.net 6214 :UBC 0 : | ROW { $$ = false; }
6215 : : ;
6216 : :
6217 : : TransitionRelName:
3279 kgrittn@postgresql.o 6218 :CBC 303 : ColId { $$ = $1; }
6219 : : ;
6220 : :
6221 : : TriggerForSpec:
6222 : : FOR TriggerForOptEach TriggerForType
6223 : : {
10120 lockhart@fourpalms.o 6224 : 1468 : $$ = $3;
6225 : : }
6226 : : | /* EMPTY */
6227 : : {
6228 : : /*
6229 : : * If ROW/STATEMENT not specified, default to
6230 : : * STATEMENT, per SQL
6231 : : */
2994 peter_e@gmx.net 6232 : 120 : $$ = false;
6233 : : }
6234 : : ;
6235 : :
6236 : : TriggerForOptEach:
6237 : : EACH
6238 : : | /*EMPTY*/
6239 : : ;
6240 : :
6241 : : TriggerForType:
6242 : 1054 : ROW { $$ = true; }
6243 : 414 : | STATEMENT { $$ = false; }
6244 : : ;
6245 : :
6246 : : TriggerWhen:
5820 tgl@sss.pgh.pa.us 6247 : 95 : WHEN '(' a_expr ')' { $$ = $3; }
6248 : 1533 : | /*EMPTY*/ { $$ = NULL; }
6249 : : ;
6250 : :
6251 : : FUNCTION_or_PROCEDURE:
6252 : : FUNCTION
6253 : : | PROCEDURE
6254 : : ;
6255 : :
6256 : : TriggerFuncArgs:
7820 neilc@samurai.com 6257 : 273 : TriggerFuncArg { $$ = list_make1($1); }
8532 bruce@momjian.us 6258 : 81 : | TriggerFuncArgs ',' TriggerFuncArg { $$ = lappend($1, $3); }
8533 6259 : 1355 : | /*EMPTY*/ { $$ = NIL; }
6260 : : ;
6261 : :
6262 : : TriggerFuncArg:
6263 : : Iconst
6264 : : {
1509 peter@eisentraut.org 6265 : 47 : $$ = (Node *) makeString(psprintf("%d", $1));
6266 : : }
1509 peter@eisentraut.org 6267 :UBC 0 : | FCONST { $$ = (Node *) makeString($1); }
1509 peter@eisentraut.org 6268 :CBC 296 : | Sconst { $$ = (Node *) makeString($1); }
6269 : 11 : | ColLabel { $$ = (Node *) makeString($1); }
6270 : : ;
6271 : :
6272 : : OptConstrFromTable:
8533 bruce@momjian.us 6273 : 6 : FROM qualified_name { $$ = $2; }
6274 : 34 : | /*EMPTY*/ { $$ = NULL; }
6275 : : ;
6276 : :
6277 : : ConstraintAttributeSpec:
6278 : : /*EMPTY*/
5248 tgl@sss.pgh.pa.us 6279 : 8967 : { $$ = 0; }
6280 : : | ConstraintAttributeSpec ConstraintAttributeElem
6281 : : {
6282 : : /*
6283 : : * We must complain about conflicting options.
6284 : : * We could, but choose not to, complain about redundant
6285 : : * options (ie, where $2's bit is already set in $1).
6286 : : */
6287 : 841 : int newspec = $1 | $2;
6288 : :
6289 : : /* special message for this case */
6290 [ + + ]: 841 : if ((newspec & (CAS_NOT_DEFERRABLE | CAS_INITIALLY_DEFERRED)) == (CAS_NOT_DEFERRABLE | CAS_INITIALLY_DEFERRED))
8136 6291 [ + - ]: 3 : ereport(ERROR,
6292 : : (errcode(ERRCODE_SYNTAX_ERROR),
6293 : : errmsg("constraint declared INITIALLY DEFERRED must be DEFERRABLE"),
6294 : : parser_errposition(@2)));
6295 : : /* generic message for other conflicts */
5248 6296 [ + - ]: 838 : if ((newspec & (CAS_NOT_DEFERRABLE | CAS_DEFERRABLE)) == (CAS_NOT_DEFERRABLE | CAS_DEFERRABLE) ||
289 peter@eisentraut.org 6297 [ + - ]: 838 : (newspec & (CAS_INITIALLY_IMMEDIATE | CAS_INITIALLY_DEFERRED)) == (CAS_INITIALLY_IMMEDIATE | CAS_INITIALLY_DEFERRED) ||
6298 [ + + ]: 838 : (newspec & (CAS_NOT_ENFORCED | CAS_ENFORCED)) == (CAS_NOT_ENFORCED | CAS_ENFORCED))
8136 tgl@sss.pgh.pa.us 6299 [ + - ]: 3 : ereport(ERROR,
6300 : : (errcode(ERRCODE_SYNTAX_ERROR),
6301 : : errmsg("conflicting constraint properties"),
6302 : : parser_errposition(@2)));
5248 6303 : 835 : $$ = newspec;
6304 : : }
6305 : : ;
6306 : :
6307 : : ConstraintAttributeElem:
6308 : 21 : NOT DEFERRABLE { $$ = CAS_NOT_DEFERRABLE; }
6309 : 100 : | DEFERRABLE { $$ = CAS_DEFERRABLE; }
6310 : 15 : | INITIALLY IMMEDIATE { $$ = CAS_INITIALLY_IMMEDIATE; }
6311 : 76 : | INITIALLY DEFERRED { $$ = CAS_INITIALLY_DEFERRED; }
6312 : 366 : | NOT VALID { $$ = CAS_NOT_VALID; }
4843 alvherre@alvh.no-ip. 6313 : 125 : | NO INHERIT { $$ = CAS_NO_INHERIT; }
289 peter@eisentraut.org 6314 : 84 : | NOT ENFORCED { $$ = CAS_NOT_ENFORCED; }
6315 : 54 : | ENFORCED { $$ = CAS_ENFORCED; }
6316 : : ;
6317 : :
6318 : :
6319 : : /*****************************************************************************
6320 : : *
6321 : : * QUERIES :
6322 : : * CREATE EVENT TRIGGER ...
6323 : : * ALTER EVENT TRIGGER ...
6324 : : *
6325 : : *****************************************************************************/
6326 : :
6327 : : CreateEventTrigStmt:
6328 : : CREATE EVENT TRIGGER name ON ColLabel
6329 : : EXECUTE FUNCTION_or_PROCEDURE func_name '(' ')'
6330 : : {
4849 rhaas@postgresql.org 6331 : 51 : CreateEventTrigStmt *n = makeNode(CreateEventTrigStmt);
6332 : :
6333 : 51 : n->trigname = $4;
6334 : 51 : n->eventname = $6;
6335 : 51 : n->whenclause = NULL;
6336 : 51 : n->funcname = $9;
1263 peter@eisentraut.org 6337 : 51 : $$ = (Node *) n;
6338 : : }
6339 : : | CREATE EVENT TRIGGER name ON ColLabel
6340 : : WHEN event_trigger_when_list
6341 : : EXECUTE FUNCTION_or_PROCEDURE func_name '(' ')'
6342 : : {
4849 rhaas@postgresql.org 6343 : 49 : CreateEventTrigStmt *n = makeNode(CreateEventTrigStmt);
6344 : :
6345 : 49 : n->trigname = $4;
6346 : 49 : n->eventname = $6;
6347 : 49 : n->whenclause = $8;
6348 : 49 : n->funcname = $11;
1263 peter@eisentraut.org 6349 : 49 : $$ = (Node *) n;
6350 : : }
6351 : : ;
6352 : :
6353 : : event_trigger_when_list:
6354 : : event_trigger_when_item
4849 rhaas@postgresql.org 6355 : 49 : { $$ = list_make1($1); }
6356 : : | event_trigger_when_list AND event_trigger_when_item
6357 : 3 : { $$ = lappend($1, $3); }
6358 : : ;
6359 : :
6360 : : event_trigger_when_item:
6361 : : ColId IN_P '(' event_trigger_value_list ')'
3338 peter_e@gmx.net 6362 : 52 : { $$ = makeDefElem($1, (Node *) $4, @1); }
6363 : : ;
6364 : :
6365 : : event_trigger_value_list:
6366 : : SCONST
4849 rhaas@postgresql.org 6367 : 52 : { $$ = list_make1(makeString($1)); }
6368 : : | event_trigger_value_list ',' SCONST
6369 : 33 : { $$ = lappend($1, makeString($3)); }
6370 : : ;
6371 : :
6372 : : AlterEventTrigStmt:
6373 : : ALTER EVENT TRIGGER name enable_trigger
6374 : : {
6375 : 24 : AlterEventTrigStmt *n = makeNode(AlterEventTrigStmt);
6376 : :
6377 : 24 : n->trigname = $4;
6378 : 24 : n->tgenabled = $5;
6379 : 24 : $$ = (Node *) n;
6380 : : }
6381 : : ;
6382 : :
6383 : : enable_trigger:
6384 : 3 : ENABLE_P { $$ = TRIGGER_FIRES_ON_ORIGIN; }
6385 : 3 : | ENABLE_P REPLICA { $$ = TRIGGER_FIRES_ON_REPLICA; }
6386 : 8 : | ENABLE_P ALWAYS { $$ = TRIGGER_FIRES_ALWAYS; }
6387 : 10 : | DISABLE_P { $$ = TRIGGER_DISABLED; }
6388 : : ;
6389 : :
6390 : : /*****************************************************************************
6391 : : *
6392 : : * QUERY :
6393 : : * CREATE ASSERTION ...
6394 : : *
6395 : : *****************************************************************************/
6396 : :
6397 : : CreateAssertionStmt:
6398 : : CREATE ASSERTION any_name CHECK '(' a_expr ')' ConstraintAttributeSpec
6399 : : {
8136 tgl@sss.pgh.pa.us 6400 [ # # ]:UBC 0 : ereport(ERROR,
6401 : : (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
6402 : : errmsg("CREATE ASSERTION is not yet implemented"),
6403 : : parser_errposition(@1)));
6404 : :
6405 : : $$ = NULL;
6406 : : }
6407 : : ;
6408 : :
6409 : :
6410 : : /*****************************************************************************
6411 : : *
6412 : : * QUERY :
6413 : : * define (aggregate,operator,type)
6414 : : *
6415 : : *****************************************************************************/
6416 : :
6417 : : DefineStmt:
6418 : : CREATE opt_or_replace AGGREGATE func_name aggr_args definition
6419 : : {
9334 lockhart@fourpalms.o 6420 :CBC 272 : DefineStmt *n = makeNode(DefineStmt);
6421 : :
8158 peter_e@gmx.net 6422 : 272 : n->kind = OBJECT_AGGREGATE;
7135 tgl@sss.pgh.pa.us 6423 : 272 : n->oldstyle = false;
2414 rhodiumtoad@postgres 6424 : 272 : n->replace = $2;
6425 : 272 : n->defnames = $4;
6426 : 272 : n->args = $5;
6427 : 272 : n->definition = $6;
1263 peter@eisentraut.org 6428 : 272 : $$ = (Node *) n;
6429 : : }
6430 : : | CREATE opt_or_replace AGGREGATE func_name old_aggr_definition
6431 : : {
6432 : : /* old-style (pre-8.2) syntax for CREATE AGGREGATE */
7135 tgl@sss.pgh.pa.us 6433 : 181 : DefineStmt *n = makeNode(DefineStmt);
6434 : :
6435 : 181 : n->kind = OBJECT_AGGREGATE;
6436 : 181 : n->oldstyle = true;
2414 rhodiumtoad@postgres 6437 : 181 : n->replace = $2;
6438 : 181 : n->defnames = $4;
7135 tgl@sss.pgh.pa.us 6439 : 181 : n->args = NIL;
2414 rhodiumtoad@postgres 6440 : 181 : n->definition = $5;
1263 peter@eisentraut.org 6441 : 181 : $$ = (Node *) n;
6442 : : }
6443 : : | CREATE OPERATOR any_operator definition
6444 : : {
9075 tgl@sss.pgh.pa.us 6445 : 821 : DefineStmt *n = makeNode(DefineStmt);
6446 : :
8158 peter_e@gmx.net 6447 : 821 : n->kind = OBJECT_OPERATOR;
7135 tgl@sss.pgh.pa.us 6448 : 821 : n->oldstyle = false;
8595 6449 : 821 : n->defnames = $3;
7135 6450 : 821 : n->args = NIL;
9075 6451 : 821 : n->definition = $4;
1263 peter@eisentraut.org 6452 : 821 : $$ = (Node *) n;
6453 : : }
6454 : : | CREATE TYPE_P any_name definition
6455 : : {
9075 tgl@sss.pgh.pa.us 6456 : 120 : DefineStmt *n = makeNode(DefineStmt);
6457 : :
8158 peter_e@gmx.net 6458 : 120 : n->kind = OBJECT_TYPE;
7135 tgl@sss.pgh.pa.us 6459 : 120 : n->oldstyle = false;
8613 6460 : 120 : n->defnames = $3;
7135 6461 : 120 : n->args = NIL;
9334 lockhart@fourpalms.o 6462 : 120 : n->definition = $4;
1263 peter@eisentraut.org 6463 : 120 : $$ = (Node *) n;
6464 : : }
6465 : : | CREATE TYPE_P any_name
6466 : : {
6467 : : /* Shell type (identified by lack of definition) */
7181 tgl@sss.pgh.pa.us 6468 : 78 : DefineStmt *n = makeNode(DefineStmt);
6469 : :
6470 : 78 : n->kind = OBJECT_TYPE;
7135 6471 : 78 : n->oldstyle = false;
7181 6472 : 78 : n->defnames = $3;
7135 6473 : 78 : n->args = NIL;
7181 6474 : 78 : n->definition = NIL;
1263 peter@eisentraut.org 6475 : 78 : $$ = (Node *) n;
6476 : : }
6477 : : | CREATE TYPE_P any_name AS '(' OptTableFuncElementList ')'
6478 : : {
8474 bruce@momjian.us 6479 : 362 : CompositeTypeStmt *n = makeNode(CompositeTypeStmt);
6480 : :
6481 : : /* can't use qualified_name, sigh */
5510 peter_e@gmx.net 6482 : 362 : n->typevar = makeRangeVarFromAnyName($3, @3, yyscanner);
8460 tgl@sss.pgh.pa.us 6483 : 362 : n->coldeflist = $6;
1263 peter@eisentraut.org 6484 : 362 : $$ = (Node *) n;
6485 : : }
6486 : : | CREATE TYPE_P any_name AS ENUM_P '(' opt_enum_val_list ')'
6487 : : {
6783 tgl@sss.pgh.pa.us 6488 : 104 : CreateEnumStmt *n = makeNode(CreateEnumStmt);
6489 : :
5947 peter_e@gmx.net 6490 : 104 : n->typeName = $3;
6783 tgl@sss.pgh.pa.us 6491 : 104 : n->vals = $7;
1263 peter@eisentraut.org 6492 : 104 : $$ = (Node *) n;
6493 : : }
6494 : : | CREATE TYPE_P any_name AS RANGE definition
6495 : : {
5107 heikki.linnakangas@i 6496 : 92 : CreateRangeStmt *n = makeNode(CreateRangeStmt);
6497 : :
6498 : 92 : n->typeName = $3;
1566 peter@eisentraut.org 6499 : 92 : n->params = $6;
1263 6500 : 92 : $$ = (Node *) n;
6501 : : }
6502 : : | CREATE TEXT_P SEARCH PARSER any_name definition
6503 : : {
6642 tgl@sss.pgh.pa.us 6504 : 20 : DefineStmt *n = makeNode(DefineStmt);
6505 : :
6506 : 20 : n->kind = OBJECT_TSPARSER;
6507 : 20 : n->args = NIL;
6508 : 20 : n->defnames = $5;
6509 : 20 : n->definition = $6;
1263 peter@eisentraut.org 6510 : 20 : $$ = (Node *) n;
6511 : : }
6512 : : | CREATE TEXT_P SEARCH DICTIONARY any_name definition
6513 : : {
6642 tgl@sss.pgh.pa.us 6514 : 1465 : DefineStmt *n = makeNode(DefineStmt);
6515 : :
6516 : 1465 : n->kind = OBJECT_TSDICTIONARY;
6517 : 1465 : n->args = NIL;
6518 : 1465 : n->defnames = $5;
6519 : 1465 : n->definition = $6;
1263 peter@eisentraut.org 6520 : 1465 : $$ = (Node *) n;
6521 : : }
6522 : : | CREATE TEXT_P SEARCH TEMPLATE any_name definition
6523 : : {
6642 tgl@sss.pgh.pa.us 6524 : 70 : DefineStmt *n = makeNode(DefineStmt);
6525 : :
6526 : 70 : n->kind = OBJECT_TSTEMPLATE;
6527 : 70 : n->args = NIL;
6528 : 70 : n->defnames = $5;
6529 : 70 : n->definition = $6;
1263 peter@eisentraut.org 6530 : 70 : $$ = (Node *) n;
6531 : : }
6532 : : | CREATE TEXT_P SEARCH CONFIGURATION any_name definition
6533 : : {
6642 tgl@sss.pgh.pa.us 6534 : 1436 : DefineStmt *n = makeNode(DefineStmt);
6535 : :
6536 : 1436 : n->kind = OBJECT_TSCONFIGURATION;
6537 : 1436 : n->args = NIL;
6538 : 1436 : n->defnames = $5;
6539 : 1436 : n->definition = $6;
1263 peter@eisentraut.org 6540 : 1436 : $$ = (Node *) n;
6541 : : }
6542 : : | CREATE COLLATION any_name definition
6543 : : {
5371 peter_e@gmx.net 6544 : 146 : DefineStmt *n = makeNode(DefineStmt);
6545 : :
6546 : 146 : n->kind = OBJECT_COLLATION;
6547 : 146 : n->args = NIL;
6548 : 146 : n->defnames = $3;
6549 : 146 : n->definition = $4;
1263 peter@eisentraut.org 6550 : 146 : $$ = (Node *) n;
6551 : : }
6552 : : | CREATE COLLATION IF_P NOT EXISTS any_name definition
6553 : : {
3183 peter_e@gmx.net 6554 : 9 : DefineStmt *n = makeNode(DefineStmt);
6555 : :
6556 : 9 : n->kind = OBJECT_COLLATION;
6557 : 9 : n->args = NIL;
6558 : 9 : n->defnames = $6;
6559 : 9 : n->definition = $7;
6560 : 9 : n->if_not_exists = true;
1263 peter@eisentraut.org 6561 : 9 : $$ = (Node *) n;
6562 : : }
6563 : : | CREATE COLLATION any_name FROM any_name
6564 : : {
5371 peter_e@gmx.net 6565 : 27 : DefineStmt *n = makeNode(DefineStmt);
6566 : :
6567 : 27 : n->kind = OBJECT_COLLATION;
6568 : 27 : n->args = NIL;
6569 : 27 : n->defnames = $3;
3338 6570 : 27 : n->definition = list_make1(makeDefElem("from", (Node *) $5, @5));
1263 peter@eisentraut.org 6571 : 27 : $$ = (Node *) n;
6572 : : }
6573 : : | CREATE COLLATION IF_P NOT EXISTS any_name FROM any_name
6574 : : {
3183 peter_e@gmx.net 6575 :UBC 0 : DefineStmt *n = makeNode(DefineStmt);
6576 : :
6577 : 0 : n->kind = OBJECT_COLLATION;
6578 : 0 : n->args = NIL;
6579 : 0 : n->defnames = $6;
6580 : 0 : n->definition = list_make1(makeDefElem("from", (Node *) $8, @8));
6581 : 0 : n->if_not_exists = true;
1263 peter@eisentraut.org 6582 : 0 : $$ = (Node *) n;
6583 : : }
6584 : : ;
6585 : :
8533 bruce@momjian.us 6586 :CBC 4984 : definition: '(' def_list ')' { $$ = $2; }
6587 : : ;
6588 : :
5109 peter_e@gmx.net 6589 : 4984 : def_list: def_elem { $$ = list_make1($1); }
8533 bruce@momjian.us 6590 : 7407 : | def_list ',' def_elem { $$ = lappend($1, $3); }
6591 : : ;
6592 : :
6593 : : def_elem: ColLabel '=' def_arg
6594 : : {
3338 peter_e@gmx.net 6595 : 12222 : $$ = makeDefElem($1, (Node *) $3, @1);
6596 : : }
6597 : : | ColLabel
6598 : : {
6599 : 169 : $$ = makeDefElem($1, NULL, @1);
6600 : : }
6601 : : ;
6602 : :
6603 : : /* Note: any simple identifier will be returned as a type name! */
1263 peter@eisentraut.org 6604 : 9849 : def_arg: func_type { $$ = (Node *) $1; }
6605 : 2066 : | reserved_keyword { $$ = (Node *) makeString(pstrdup($1)); }
6606 : 588 : | qual_all_Op { $$ = (Node *) $1; }
6607 : 671 : | NumericOnly { $$ = (Node *) $1; }
6608 : 953 : | Sconst { $$ = (Node *) makeString($1); }
6609 : 91 : | NONE { $$ = (Node *) makeString(pstrdup($1)); }
6610 : : ;
6611 : :
7135 tgl@sss.pgh.pa.us 6612 : 181 : old_aggr_definition: '(' old_aggr_list ')' { $$ = $2; }
6613 : : ;
6614 : :
6615 : 181 : old_aggr_list: old_aggr_elem { $$ = list_make1($1); }
6616 : 646 : | old_aggr_list ',' old_aggr_elem { $$ = lappend($1, $3); }
6617 : : ;
6618 : :
6619 : : /*
6620 : : * Must use IDENT here to avoid reduce/reduce conflicts; fortunately none of
6621 : : * the item names needed in old aggregate definitions are likely to become
6622 : : * SQL keywords.
6623 : : */
6624 : : old_aggr_elem: IDENT '=' def_arg
6625 : : {
1263 peter@eisentraut.org 6626 : 827 : $$ = makeDefElem($1, (Node *) $3, @1);
6627 : : }
6628 : : ;
6629 : :
6630 : : opt_enum_val_list:
5784 bruce@momjian.us 6631 : 100 : enum_val_list { $$ = $1; }
6632 : 4 : | /*EMPTY*/ { $$ = NIL; }
6633 : : ;
6634 : :
6635 : : enum_val_list: Sconst
6783 tgl@sss.pgh.pa.us 6636 : 100 : { $$ = list_make1(makeString($1)); }
6637 : : | enum_val_list ',' Sconst
6638 : 5210 : { $$ = lappend($1, makeString($3)); }
6639 : : ;
6640 : :
6641 : : /*****************************************************************************
6642 : : *
6643 : : * ALTER TYPE enumtype ADD ...
6644 : : *
6645 : : *****************************************************************************/
6646 : :
6647 : : AlterEnumStmt:
6648 : : ALTER TYPE_P any_name ADD_P VALUE_P opt_if_not_exists Sconst
6649 : : {
5109 peter_e@gmx.net 6650 : 77 : AlterEnumStmt *n = makeNode(AlterEnumStmt);
6651 : :
6652 : 77 : n->typeName = $3;
3337 tgl@sss.pgh.pa.us 6653 : 77 : n->oldVal = NULL;
4783 andrew@dunslane.net 6654 : 77 : n->newVal = $7;
5109 peter_e@gmx.net 6655 : 77 : n->newValNeighbor = NULL;
6656 : 77 : n->newValIsAfter = true;
3337 tgl@sss.pgh.pa.us 6657 : 77 : n->skipIfNewValExists = $6;
5109 peter_e@gmx.net 6658 : 77 : $$ = (Node *) n;
6659 : : }
6660 : : | ALTER TYPE_P any_name ADD_P VALUE_P opt_if_not_exists Sconst BEFORE Sconst
6661 : : {
6662 : 98 : AlterEnumStmt *n = makeNode(AlterEnumStmt);
6663 : :
6664 : 98 : n->typeName = $3;
3337 tgl@sss.pgh.pa.us 6665 : 98 : n->oldVal = NULL;
4783 andrew@dunslane.net 6666 : 98 : n->newVal = $7;
6667 : 98 : n->newValNeighbor = $9;
5109 peter_e@gmx.net 6668 : 98 : n->newValIsAfter = false;
3337 tgl@sss.pgh.pa.us 6669 : 98 : n->skipIfNewValExists = $6;
5109 peter_e@gmx.net 6670 : 98 : $$ = (Node *) n;
6671 : : }
6672 : : | ALTER TYPE_P any_name ADD_P VALUE_P opt_if_not_exists Sconst AFTER Sconst
6673 : : {
6674 : 11 : AlterEnumStmt *n = makeNode(AlterEnumStmt);
6675 : :
6676 : 11 : n->typeName = $3;
3337 tgl@sss.pgh.pa.us 6677 : 11 : n->oldVal = NULL;
4783 andrew@dunslane.net 6678 : 11 : n->newVal = $7;
6679 : 11 : n->newValNeighbor = $9;
5109 peter_e@gmx.net 6680 : 11 : n->newValIsAfter = true;
3337 tgl@sss.pgh.pa.us 6681 : 11 : n->skipIfNewValExists = $6;
6682 : 11 : $$ = (Node *) n;
6683 : : }
6684 : : | ALTER TYPE_P any_name RENAME VALUE_P Sconst TO Sconst
6685 : : {
6686 : 12 : AlterEnumStmt *n = makeNode(AlterEnumStmt);
6687 : :
6688 : 12 : n->typeName = $3;
6689 : 12 : n->oldVal = $6;
6690 : 12 : n->newVal = $8;
6691 : 12 : n->newValNeighbor = NULL;
6692 : 12 : n->newValIsAfter = false;
6693 : 12 : n->skipIfNewValExists = false;
5109 peter_e@gmx.net 6694 : 12 : $$ = (Node *) n;
6695 : : }
6696 : : | ALTER TYPE_P any_name DROP VALUE_P Sconst
6697 : : {
6698 : : /*
6699 : : * The following problems must be solved before this can be
6700 : : * implemented:
6701 : : *
6702 : : * - There must be no instance of the target value in
6703 : : * any table.
6704 : : *
6705 : : * - The value must not appear in any catalog metadata,
6706 : : * such as stored view expressions or column defaults.
6707 : : *
6708 : : * - The value must not appear in any non-leaf page of a
6709 : : * btree (and similar issues with other index types).
6710 : : * This is problematic because a value could persist
6711 : : * there long after it's gone from user-visible data.
6712 : : *
6713 : : * - Concurrent sessions must not be able to insert the
6714 : : * value while the preceding conditions are being checked.
6715 : : *
6716 : : * - Possibly more...
6717 : : */
755 tgl@sss.pgh.pa.us 6718 [ # # ]:UBC 0 : ereport(ERROR,
6719 : : (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
6720 : : errmsg("dropping an enum value is not implemented"),
6721 : : parser_errposition(@4)));
6722 : : }
6723 : : ;
6724 : :
4783 andrew@dunslane.net 6725 :CBC 6 : opt_if_not_exists: IF_P NOT EXISTS { $$ = true; }
1806 peter@eisentraut.org 6726 : 180 : | /* EMPTY */ { $$ = false; }
6727 : : ;
6728 : :
6729 : :
6730 : : /*****************************************************************************
6731 : : *
6732 : : * QUERIES :
6733 : : * CREATE OPERATOR CLASS ...
6734 : : * CREATE OPERATOR FAMILY ...
6735 : : * ALTER OPERATOR FAMILY ...
6736 : : * DROP OPERATOR CLASS ...
6737 : : * DROP OPERATOR FAMILY ...
6738 : : *
6739 : : *****************************************************************************/
6740 : :
6741 : : CreateOpClassStmt:
6742 : : CREATE OPERATOR CLASS any_name opt_default FOR TYPE_P Typename
6743 : : USING name opt_opfamily AS opclass_item_list
6744 : : {
8491 tgl@sss.pgh.pa.us 6745 : 278 : CreateOpClassStmt *n = makeNode(CreateOpClassStmt);
6746 : :
6747 : 278 : n->opclassname = $4;
6748 : 278 : n->isDefault = $5;
6749 : 278 : n->datatype = $8;
6750 : 278 : n->amname = $10;
6852 6751 : 278 : n->opfamilyname = $11;
6752 : 278 : n->items = $13;
8491 6753 : 278 : $$ = (Node *) n;
6754 : : }
6755 : : ;
6756 : :
6757 : : opclass_item_list:
7820 neilc@samurai.com 6758 : 706 : opclass_item { $$ = list_make1($1); }
8491 tgl@sss.pgh.pa.us 6759 : 2694 : | opclass_item_list ',' opclass_item { $$ = lappend($1, $3); }
6760 : : ;
6761 : :
6762 : : opclass_item:
6763 : : OPERATOR Iconst any_operator opclass_purpose
6764 : : {
6765 : 933 : CreateOpClassItem *n = makeNode(CreateOpClassItem);
3225 peter_e@gmx.net 6766 : 933 : ObjectWithArgs *owa = makeNode(ObjectWithArgs);
6767 : :
6768 : 933 : owa->objname = $3;
6769 : 933 : owa->objargs = NIL;
8491 tgl@sss.pgh.pa.us 6770 : 933 : n->itemtype = OPCLASS_ITEM_OPERATOR;
3225 peter_e@gmx.net 6771 : 933 : n->name = owa;
8491 tgl@sss.pgh.pa.us 6772 : 933 : n->number = $2;
5451 6773 : 933 : n->order_family = $4;
8491 6774 : 933 : $$ = (Node *) n;
6775 : : }
6776 : : | OPERATOR Iconst operator_with_argtypes opclass_purpose
6777 : : {
6778 : 785 : CreateOpClassItem *n = makeNode(CreateOpClassItem);
6779 : :
6780 : 785 : n->itemtype = OPCLASS_ITEM_OPERATOR;
3225 peter_e@gmx.net 6781 : 785 : n->name = $3;
8491 tgl@sss.pgh.pa.us 6782 : 785 : n->number = $2;
3225 peter_e@gmx.net 6783 : 785 : n->order_family = $4;
8491 tgl@sss.pgh.pa.us 6784 : 785 : $$ = (Node *) n;
6785 : : }
6786 : : | FUNCTION Iconst function_with_argtypes
6787 : : {
6788 : 1207 : CreateOpClassItem *n = makeNode(CreateOpClassItem);
6789 : :
6790 : 1207 : n->itemtype = OPCLASS_ITEM_FUNCTION;
3225 peter_e@gmx.net 6791 : 1207 : n->name = $3;
8491 tgl@sss.pgh.pa.us 6792 : 1207 : n->number = $2;
6793 : 1207 : $$ = (Node *) n;
6794 : : }
6795 : : | FUNCTION Iconst '(' type_list ')' function_with_argtypes
6796 : : {
6852 6797 : 295 : CreateOpClassItem *n = makeNode(CreateOpClassItem);
6798 : :
6799 : 295 : n->itemtype = OPCLASS_ITEM_FUNCTION;
3225 peter_e@gmx.net 6800 : 295 : n->name = $6;
6852 tgl@sss.pgh.pa.us 6801 : 295 : n->number = $2;
6802 : 295 : n->class_args = $4;
6803 : 295 : $$ = (Node *) n;
6804 : : }
6805 : : | STORAGE Typename
6806 : : {
8491 6807 : 180 : CreateOpClassItem *n = makeNode(CreateOpClassItem);
6808 : :
6809 : 180 : n->itemtype = OPCLASS_ITEM_STORAGETYPE;
6810 : 180 : n->storedtype = $2;
6811 : 180 : $$ = (Node *) n;
6812 : : }
6813 : : ;
6814 : :
2994 peter_e@gmx.net 6815 : 226 : opt_default: DEFAULT { $$ = true; }
6816 : 84 : | /*EMPTY*/ { $$ = false; }
6817 : : ;
6818 : :
6852 tgl@sss.pgh.pa.us 6819 : 22 : opt_opfamily: FAMILY any_name { $$ = $2; }
6820 : 256 : | /*EMPTY*/ { $$ = NIL; }
6821 : : ;
6822 : :
5451 tgl@sss.pgh.pa.us 6823 :UBC 0 : opclass_purpose: FOR SEARCH { $$ = NIL; }
5451 tgl@sss.pgh.pa.us 6824 :CBC 60 : | FOR ORDER BY any_name { $$ = $4; }
6825 : 1658 : | /*EMPTY*/ { $$ = NIL; }
6826 : : ;
6827 : :
6828 : :
6829 : : CreateOpFamilyStmt:
6830 : : CREATE OPERATOR FAMILY any_name USING name
6831 : : {
6852 6832 : 74 : CreateOpFamilyStmt *n = makeNode(CreateOpFamilyStmt);
6833 : :
6834 : 74 : n->opfamilyname = $4;
6835 : 74 : n->amname = $6;
6836 : 74 : $$ = (Node *) n;
6837 : : }
6838 : : ;
6839 : :
6840 : : AlterOpFamilyStmt:
6841 : : ALTER OPERATOR FAMILY any_name USING name ADD_P opclass_item_list
6842 : : {
6843 : 428 : AlterOpFamilyStmt *n = makeNode(AlterOpFamilyStmt);
6844 : :
6845 : 428 : n->opfamilyname = $4;
6846 : 428 : n->amname = $6;
6847 : 428 : n->isDrop = false;
6848 : 428 : n->items = $8;
6849 : 428 : $$ = (Node *) n;
6850 : : }
6851 : : | ALTER OPERATOR FAMILY any_name USING name DROP opclass_drop_list
6852 : : {
6853 : 32 : AlterOpFamilyStmt *n = makeNode(AlterOpFamilyStmt);
6854 : :
6855 : 32 : n->opfamilyname = $4;
6856 : 32 : n->amname = $6;
6857 : 32 : n->isDrop = true;
6858 : 32 : n->items = $8;
6859 : 32 : $$ = (Node *) n;
6860 : : }
6861 : : ;
6862 : :
6863 : : opclass_drop_list:
6864 : 32 : opclass_drop { $$ = list_make1($1); }
6865 : 15 : | opclass_drop_list ',' opclass_drop { $$ = lappend($1, $3); }
6866 : : ;
6867 : :
6868 : : opclass_drop:
6869 : : OPERATOR Iconst '(' type_list ')'
6870 : : {
6871 : 28 : CreateOpClassItem *n = makeNode(CreateOpClassItem);
6872 : :
6873 : 28 : n->itemtype = OPCLASS_ITEM_OPERATOR;
6874 : 28 : n->number = $2;
3225 peter_e@gmx.net 6875 : 28 : n->class_args = $4;
6852 tgl@sss.pgh.pa.us 6876 : 28 : $$ = (Node *) n;
6877 : : }
6878 : : | FUNCTION Iconst '(' type_list ')'
6879 : : {
6880 : 19 : CreateOpClassItem *n = makeNode(CreateOpClassItem);
6881 : :
6882 : 19 : n->itemtype = OPCLASS_ITEM_FUNCTION;
6883 : 19 : n->number = $2;
3225 peter_e@gmx.net 6884 : 19 : n->class_args = $4;
6852 tgl@sss.pgh.pa.us 6885 : 19 : $$ = (Node *) n;
6886 : : }
6887 : : ;
6888 : :
6889 : :
6890 : : DropOpClassStmt:
6891 : : DROP OPERATOR CLASS any_name USING name opt_drop_behavior
6892 : : {
5093 rhaas@postgresql.org 6893 : 19 : DropStmt *n = makeNode(DropStmt);
6894 : :
3878 alvherre@alvh.no-ip. 6895 : 19 : n->objects = list_make1(lcons(makeString($6), $4));
5093 rhaas@postgresql.org 6896 : 19 : n->removeType = OBJECT_OPCLASS;
8491 tgl@sss.pgh.pa.us 6897 : 19 : n->behavior = $7;
7073 andrew@dunslane.net 6898 : 19 : n->missing_ok = false;
4952 simon@2ndQuadrant.co 6899 : 19 : n->concurrent = false;
7073 andrew@dunslane.net 6900 : 19 : $$ = (Node *) n;
6901 : : }
6902 : : | DROP OPERATOR CLASS IF_P EXISTS any_name USING name opt_drop_behavior
6903 : : {
5093 rhaas@postgresql.org 6904 : 9 : DropStmt *n = makeNode(DropStmt);
6905 : :
3878 alvherre@alvh.no-ip. 6906 : 9 : n->objects = list_make1(lcons(makeString($8), $6));
5093 rhaas@postgresql.org 6907 : 9 : n->removeType = OBJECT_OPCLASS;
7073 andrew@dunslane.net 6908 : 9 : n->behavior = $9;
6909 : 9 : n->missing_ok = true;
4952 simon@2ndQuadrant.co 6910 : 9 : n->concurrent = false;
8491 tgl@sss.pgh.pa.us 6911 : 9 : $$ = (Node *) n;
6912 : : }
6913 : : ;
6914 : :
6915 : : DropOpFamilyStmt:
6916 : : DROP OPERATOR FAMILY any_name USING name opt_drop_behavior
6917 : : {
5093 rhaas@postgresql.org 6918 : 55 : DropStmt *n = makeNode(DropStmt);
6919 : :
3878 alvherre@alvh.no-ip. 6920 : 55 : n->objects = list_make1(lcons(makeString($6), $4));
5093 rhaas@postgresql.org 6921 : 55 : n->removeType = OBJECT_OPFAMILY;
6852 tgl@sss.pgh.pa.us 6922 : 55 : n->behavior = $7;
6923 : 55 : n->missing_ok = false;
4952 simon@2ndQuadrant.co 6924 : 55 : n->concurrent = false;
6852 tgl@sss.pgh.pa.us 6925 : 55 : $$ = (Node *) n;
6926 : : }
6927 : : | DROP OPERATOR FAMILY IF_P EXISTS any_name USING name opt_drop_behavior
6928 : : {
5093 rhaas@postgresql.org 6929 : 9 : DropStmt *n = makeNode(DropStmt);
6930 : :
3878 alvherre@alvh.no-ip. 6931 : 9 : n->objects = list_make1(lcons(makeString($8), $6));
5093 rhaas@postgresql.org 6932 : 9 : n->removeType = OBJECT_OPFAMILY;
6852 tgl@sss.pgh.pa.us 6933 : 9 : n->behavior = $9;
6934 : 9 : n->missing_ok = true;
4952 simon@2ndQuadrant.co 6935 : 9 : n->concurrent = false;
6852 tgl@sss.pgh.pa.us 6936 : 9 : $$ = (Node *) n;
6937 : : }
6938 : : ;
6939 : :
6940 : :
6941 : : /*****************************************************************************
6942 : : *
6943 : : * QUERY:
6944 : : *
6945 : : * DROP OWNED BY username [, username ...] [ RESTRICT | CASCADE ]
6946 : : * REASSIGN OWNED BY username [, username ...] TO username
6947 : : *
6948 : : *****************************************************************************/
6949 : : DropOwnedStmt:
6950 : : DROP OWNED BY role_list opt_drop_behavior
6951 : : {
7280 alvherre@alvh.no-ip. 6952 : 74 : DropOwnedStmt *n = makeNode(DropOwnedStmt);
6953 : :
6954 : 74 : n->roles = $4;
6955 : 74 : n->behavior = $5;
1263 peter@eisentraut.org 6956 : 74 : $$ = (Node *) n;
6957 : : }
6958 : : ;
6959 : :
6960 : : ReassignOwnedStmt:
6961 : : REASSIGN OWNED BY role_list TO RoleSpec
6962 : : {
7280 alvherre@alvh.no-ip. 6963 : 23 : ReassignOwnedStmt *n = makeNode(ReassignOwnedStmt);
6964 : :
6965 : 23 : n->roles = $4;
6966 : 23 : n->newrole = $6;
1263 peter@eisentraut.org 6967 : 23 : $$ = (Node *) n;
6968 : : }
6969 : : ;
6970 : :
6971 : : /*****************************************************************************
6972 : : *
6973 : : * QUERY:
6974 : : *
6975 : : * DROP itemtype [ IF EXISTS ] itemname [, itemname ...]
6976 : : * [ RESTRICT | CASCADE ]
6977 : : *
6978 : : *****************************************************************************/
6979 : :
6980 : : DropStmt: DROP object_type_any_name IF_P EXISTS any_name_list opt_drop_behavior
6981 : : {
9140 bruce@momjian.us 6982 : 673 : DropStmt *n = makeNode(DropStmt);
6983 : :
9136 tgl@sss.pgh.pa.us 6984 : 673 : n->removeType = $2;
2994 peter_e@gmx.net 6985 : 673 : n->missing_ok = true;
7282 andrew@dunslane.net 6986 : 673 : n->objects = $5;
6987 : 673 : n->behavior = $6;
4952 simon@2ndQuadrant.co 6988 : 673 : n->concurrent = false;
1263 peter@eisentraut.org 6989 : 673 : $$ = (Node *) n;
6990 : : }
6991 : : | DROP object_type_any_name any_name_list opt_drop_behavior
6992 : : {
3271 peter_e@gmx.net 6993 : 8167 : DropStmt *n = makeNode(DropStmt);
6994 : :
6995 : 8167 : n->removeType = $2;
2994 6996 : 8167 : n->missing_ok = false;
3271 6997 : 8167 : n->objects = $3;
6998 : 8167 : n->behavior = $4;
6999 : 8167 : n->concurrent = false;
1263 peter@eisentraut.org 7000 : 8167 : $$ = (Node *) n;
7001 : : }
7002 : : | DROP drop_type_name IF_P EXISTS name_list opt_drop_behavior
7003 : : {
3271 peter_e@gmx.net 7004 : 43 : DropStmt *n = makeNode(DropStmt);
7005 : :
7006 : 43 : n->removeType = $2;
2994 7007 : 43 : n->missing_ok = true;
3271 7008 : 43 : n->objects = $5;
7009 : 43 : n->behavior = $6;
7010 : 43 : n->concurrent = false;
1263 peter@eisentraut.org 7011 : 43 : $$ = (Node *) n;
7012 : : }
7013 : : | DROP drop_type_name name_list opt_drop_behavior
7014 : : {
7282 andrew@dunslane.net 7015 : 708 : DropStmt *n = makeNode(DropStmt);
7016 : :
7017 : 708 : n->removeType = $2;
2994 peter_e@gmx.net 7018 : 708 : n->missing_ok = false;
8621 tgl@sss.pgh.pa.us 7019 : 708 : n->objects = $3;
8623 bruce@momjian.us 7020 : 708 : n->behavior = $4;
4952 simon@2ndQuadrant.co 7021 : 708 : n->concurrent = false;
1263 peter@eisentraut.org 7022 : 708 : $$ = (Node *) n;
7023 : : }
7024 : : | DROP object_type_name_on_any_name name ON any_name opt_drop_behavior
7025 : : {
3170 peter_e@gmx.net 7026 : 564 : DropStmt *n = makeNode(DropStmt);
7027 : :
7028 : 564 : n->removeType = $2;
7029 : 564 : n->objects = list_make1(lappend($5, makeString($3)));
7030 : 564 : n->behavior = $6;
7031 : 564 : n->missing_ok = false;
7032 : 564 : n->concurrent = false;
7033 : 564 : $$ = (Node *) n;
7034 : : }
7035 : : | DROP object_type_name_on_any_name IF_P EXISTS name ON any_name opt_drop_behavior
7036 : : {
7037 : 24 : DropStmt *n = makeNode(DropStmt);
7038 : :
7039 : 24 : n->removeType = $2;
7040 : 24 : n->objects = list_make1(lappend($7, makeString($5)));
7041 : 24 : n->behavior = $8;
7042 : 24 : n->missing_ok = true;
7043 : 24 : n->concurrent = false;
7044 : 24 : $$ = (Node *) n;
7045 : : }
7046 : : | DROP TYPE_P type_name_list opt_drop_behavior
7047 : : {
3954 alvherre@alvh.no-ip. 7048 : 280 : DropStmt *n = makeNode(DropStmt);
7049 : :
7050 : 280 : n->removeType = OBJECT_TYPE;
2994 peter_e@gmx.net 7051 : 280 : n->missing_ok = false;
3954 alvherre@alvh.no-ip. 7052 : 280 : n->objects = $3;
7053 : 280 : n->behavior = $4;
7054 : 280 : n->concurrent = false;
7055 : 280 : $$ = (Node *) n;
7056 : : }
7057 : : | DROP TYPE_P IF_P EXISTS type_name_list opt_drop_behavior
7058 : : {
7059 : 13 : DropStmt *n = makeNode(DropStmt);
7060 : :
7061 : 13 : n->removeType = OBJECT_TYPE;
2994 peter_e@gmx.net 7062 : 13 : n->missing_ok = true;
3954 alvherre@alvh.no-ip. 7063 : 13 : n->objects = $5;
7064 : 13 : n->behavior = $6;
7065 : 13 : n->concurrent = false;
7066 : 13 : $$ = (Node *) n;
7067 : : }
7068 : : | DROP DOMAIN_P type_name_list opt_drop_behavior
7069 : : {
7070 : 235 : DropStmt *n = makeNode(DropStmt);
7071 : :
7072 : 235 : n->removeType = OBJECT_DOMAIN;
2994 peter_e@gmx.net 7073 : 235 : n->missing_ok = false;
3954 alvherre@alvh.no-ip. 7074 : 235 : n->objects = $3;
7075 : 235 : n->behavior = $4;
7076 : 235 : n->concurrent = false;
7077 : 235 : $$ = (Node *) n;
7078 : : }
7079 : : | DROP DOMAIN_P IF_P EXISTS type_name_list opt_drop_behavior
7080 : : {
7081 : 9 : DropStmt *n = makeNode(DropStmt);
7082 : :
7083 : 9 : n->removeType = OBJECT_DOMAIN;
2994 peter_e@gmx.net 7084 : 9 : n->missing_ok = true;
3954 alvherre@alvh.no-ip. 7085 : 9 : n->objects = $5;
7086 : 9 : n->behavior = $6;
7087 : 9 : n->concurrent = false;
7088 : 9 : $$ = (Node *) n;
7089 : : }
7090 : : | DROP INDEX CONCURRENTLY any_name_list opt_drop_behavior
7091 : : {
4952 simon@2ndQuadrant.co 7092 : 79 : DropStmt *n = makeNode(DropStmt);
7093 : :
7094 : 79 : n->removeType = OBJECT_INDEX;
2994 peter_e@gmx.net 7095 : 79 : n->missing_ok = false;
4952 simon@2ndQuadrant.co 7096 : 79 : n->objects = $4;
7097 : 79 : n->behavior = $5;
7098 : 79 : n->concurrent = true;
1263 peter@eisentraut.org 7099 : 79 : $$ = (Node *) n;
7100 : : }
7101 : : | DROP INDEX CONCURRENTLY IF_P EXISTS any_name_list opt_drop_behavior
7102 : : {
4952 simon@2ndQuadrant.co 7103 : 6 : DropStmt *n = makeNode(DropStmt);
7104 : :
7105 : 6 : n->removeType = OBJECT_INDEX;
2994 peter_e@gmx.net 7106 : 6 : n->missing_ok = true;
4952 simon@2ndQuadrant.co 7107 : 6 : n->objects = $6;
7108 : 6 : n->behavior = $7;
7109 : 6 : n->concurrent = true;
1263 peter@eisentraut.org 7110 : 6 : $$ = (Node *) n;
7111 : : }
7112 : : ;
7113 : :
7114 : : /* object types taking any_name/any_name_list */
7115 : : object_type_any_name:
3271 peter_e@gmx.net 7116 : 7626 : TABLE { $$ = OBJECT_TABLE; }
8158 7117 : 99 : | SEQUENCE { $$ = OBJECT_SEQUENCE; }
7118 : 523 : | VIEW { $$ = OBJECT_VIEW; }
4621 kgrittn@postgresql.o 7119 : 65 : | MATERIALIZED VIEW { $$ = OBJECT_MATVIEW; }
8158 peter_e@gmx.net 7120 : 389 : | INDEX { $$ = OBJECT_INDEX; }
5413 rhaas@postgresql.org 7121 : 93 : | FOREIGN TABLE { $$ = OBJECT_FOREIGN_TABLE; }
5371 peter_e@gmx.net 7122 : 48 : | COLLATION { $$ = OBJECT_COLLATION; }
8158 7123 : 28 : | CONVERSION_P { $$ = OBJECT_CONVERSION; }
3139 alvherre@alvh.no-ip. 7124 : 111 : | STATISTICS { $$ = OBJECT_STATISTIC_EXT; }
6642 tgl@sss.pgh.pa.us 7125 : 10 : | TEXT_P SEARCH PARSER { $$ = OBJECT_TSPARSER; }
7126 : 1407 : | TEXT_P SEARCH DICTIONARY { $$ = OBJECT_TSDICTIONARY; }
7127 : 58 : | TEXT_P SEARCH TEMPLATE { $$ = OBJECT_TSTEMPLATE; }
7128 : 1409 : | TEXT_P SEARCH CONFIGURATION { $$ = OBJECT_TSCONFIGURATION; }
7129 : : ;
7130 : :
7131 : : /*
7132 : : * object types taking name/name_list
7133 : : *
7134 : : * DROP handles some of them separately
7135 : : */
7136 : :
7137 : : object_type_name:
1962 peter@eisentraut.org 7138 : 125 : drop_type_name { $$ = $1; }
7139 : 119 : | DATABASE { $$ = OBJECT_DATABASE; }
7140 : 26 : | ROLE { $$ = OBJECT_ROLE; }
7141 : 5 : | SUBSCRIPTION { $$ = OBJECT_SUBSCRIPTION; }
1962 peter@eisentraut.org 7142 :UBC 0 : | TABLESPACE { $$ = OBJECT_TABLESPACE; }
7143 : : ;
7144 : :
7145 : : drop_type_name:
3271 peter_e@gmx.net 7146 :CBC 23 : ACCESS METHOD { $$ = OBJECT_ACCESS_METHOD; }
7147 : 65 : | EVENT TRIGGER { $$ = OBJECT_EVENT_TRIGGER; }
7148 : 70 : | EXTENSION { $$ = OBJECT_EXTENSION; }
3170 7149 : 77 : | FOREIGN DATA_P WRAPPER { $$ = OBJECT_FDW; }
1964 peter@eisentraut.org 7150 : 77 : | opt_procedural LANGUAGE { $$ = OBJECT_LANGUAGE; }
3203 peter_e@gmx.net 7151 : 211 : | PUBLICATION { $$ = OBJECT_PUBLICATION; }
3271 7152 : 287 : | SCHEMA { $$ = OBJECT_SCHEMA; }
3170 7153 : 66 : | SERVER { $$ = OBJECT_FOREIGN_SERVER; }
7154 : : ;
7155 : :
7156 : : /* object types attached to a table */
7157 : : object_type_name_on_any_name:
7158 : 83 : POLICY { $$ = OBJECT_POLICY; }
7159 : 134 : | RULE { $$ = OBJECT_RULE; }
7160 : 398 : | TRIGGER { $$ = OBJECT_TRIGGER; }
7161 : : ;
7162 : :
7163 : : any_name_list:
7820 neilc@samurai.com 7164 : 13266 : any_name { $$ = list_make1($1); }
8533 bruce@momjian.us 7165 : 2132 : | any_name_list ',' any_name { $$ = lappend($1, $3); }
7166 : : ;
7167 : :
7820 neilc@samurai.com 7168 : 31953 : any_name: ColId { $$ = list_make1(makeString($1)); }
7810 tgl@sss.pgh.pa.us 7169 : 4496 : | ColId attrs { $$ = lcons(makeString($1), $2); }
7170 : : ;
7171 : :
7172 : : attrs: '.' attr_name
7173 : 64827 : { $$ = list_make1(makeString($2)); }
7174 : : | attrs '.' attr_name
7658 7175 : 32 : { $$ = lappend($1, makeString($3)); }
7176 : : ;
7177 : :
7178 : : type_name_list:
3271 peter_e@gmx.net 7179 : 537 : Typename { $$ = list_make1($1); }
7180 : 51 : | type_name_list ',' Typename { $$ = lappend($1, $3); }
7181 : : ;
7182 : :
7183 : : /*****************************************************************************
7184 : : *
7185 : : * QUERY:
7186 : : * truncate table relname1, relname2, ...
7187 : : *
7188 : : *****************************************************************************/
7189 : :
7190 : : TruncateStmt:
7191 : : TRUNCATE opt_table relation_expr_list opt_restart_seqs opt_drop_behavior
7192 : : {
9531 bruce@momjian.us 7193 : 878 : TruncateStmt *n = makeNode(TruncateStmt);
7194 : :
7578 tgl@sss.pgh.pa.us 7195 : 878 : n->relations = $3;
6373 7196 : 878 : n->restart_seqs = $4;
7197 : 878 : n->behavior = $5;
1263 peter@eisentraut.org 7198 : 878 : $$ = (Node *) n;
7199 : : }
7200 : : ;
7201 : :
7202 : : opt_restart_seqs:
6373 tgl@sss.pgh.pa.us 7203 : 12 : CONTINUE_P IDENTITY_P { $$ = false; }
7204 : 12 : | RESTART IDENTITY_P { $$ = true; }
7205 : 854 : | /* EMPTY */ { $$ = false; }
7206 : : ;
7207 : :
7208 : : /*****************************************************************************
7209 : : *
7210 : : * COMMENT ON <object> IS <text>
7211 : : *
7212 : : *****************************************************************************/
7213 : :
7214 : : CommentStmt:
7215 : : COMMENT ON object_type_any_name any_name IS comment_text
7216 : : {
8533 bruce@momjian.us 7217 : 2949 : CommentStmt *n = makeNode(CommentStmt);
7218 : :
7219 : 2949 : n->objtype = $3;
3271 peter_e@gmx.net 7220 : 2949 : n->object = (Node *) $4;
7221 : 2949 : n->comment = $6;
7222 : 2949 : $$ = (Node *) n;
7223 : : }
7224 : : | COMMENT ON COLUMN any_name IS comment_text
7225 : : {
1962 peter@eisentraut.org 7226 : 57 : CommentStmt *n = makeNode(CommentStmt);
7227 : :
7228 : 57 : n->objtype = OBJECT_COLUMN;
7229 : 57 : n->object = (Node *) $4;
7230 : 57 : n->comment = $6;
7231 : 57 : $$ = (Node *) n;
7232 : : }
7233 : : | COMMENT ON object_type_name name IS comment_text
7234 : : {
3271 peter_e@gmx.net 7235 : 244 : CommentStmt *n = makeNode(CommentStmt);
7236 : :
7237 : 244 : n->objtype = $3;
7238 : 244 : n->object = (Node *) makeString($4);
8533 bruce@momjian.us 7239 : 244 : n->comment = $6;
7240 : 244 : $$ = (Node *) n;
7241 : : }
7242 : : | COMMENT ON TYPE_P Typename IS comment_text
7243 : : {
3954 alvherre@alvh.no-ip. 7244 : 28 : CommentStmt *n = makeNode(CommentStmt);
7245 : :
7246 : 28 : n->objtype = OBJECT_TYPE;
3271 peter_e@gmx.net 7247 : 28 : n->object = (Node *) $4;
3954 alvherre@alvh.no-ip. 7248 : 28 : n->comment = $6;
7249 : 28 : $$ = (Node *) n;
7250 : : }
7251 : : | COMMENT ON DOMAIN_P Typename IS comment_text
7252 : : {
7253 : 4 : CommentStmt *n = makeNode(CommentStmt);
7254 : :
7255 : 4 : n->objtype = OBJECT_DOMAIN;
3271 peter_e@gmx.net 7256 : 4 : n->object = (Node *) $4;
3954 alvherre@alvh.no-ip. 7257 : 4 : n->comment = $6;
7258 : 4 : $$ = (Node *) n;
7259 : : }
7260 : : | COMMENT ON AGGREGATE aggregate_with_argtypes IS comment_text
7261 : : {
8533 bruce@momjian.us 7262 : 20 : CommentStmt *n = makeNode(CommentStmt);
7263 : :
8158 peter_e@gmx.net 7264 : 20 : n->objtype = OBJECT_AGGREGATE;
3271 7265 : 20 : n->object = (Node *) $4;
3329 7266 : 20 : n->comment = $6;
8533 bruce@momjian.us 7267 : 20 : $$ = (Node *) n;
7268 : : }
7269 : : | COMMENT ON FUNCTION function_with_argtypes IS comment_text
7270 : : {
7271 : 85 : CommentStmt *n = makeNode(CommentStmt);
7272 : :
8158 peter_e@gmx.net 7273 : 85 : n->objtype = OBJECT_FUNCTION;
3271 7274 : 85 : n->object = (Node *) $4;
3329 7275 : 85 : n->comment = $6;
8533 bruce@momjian.us 7276 : 85 : $$ = (Node *) n;
7277 : : }
7278 : : | COMMENT ON OPERATOR operator_with_argtypes IS comment_text
7279 : : {
7280 : 9 : CommentStmt *n = makeNode(CommentStmt);
7281 : :
8158 peter_e@gmx.net 7282 : 9 : n->objtype = OBJECT_OPERATOR;
3271 7283 : 9 : n->object = (Node *) $4;
3225 7284 : 9 : n->comment = $6;
8533 bruce@momjian.us 7285 : 9 : $$ = (Node *) n;
7286 : : }
7287 : : | COMMENT ON CONSTRAINT name ON any_name IS comment_text
7288 : : {
7289 : 75 : CommentStmt *n = makeNode(CommentStmt);
7290 : :
3961 alvherre@alvh.no-ip. 7291 : 75 : n->objtype = OBJECT_TABCONSTRAINT;
3271 peter_e@gmx.net 7292 : 75 : n->object = (Node *) lappend($6, makeString($4));
8533 bruce@momjian.us 7293 : 75 : n->comment = $8;
7294 : 75 : $$ = (Node *) n;
7295 : : }
7296 : : | COMMENT ON CONSTRAINT name ON DOMAIN_P any_name IS comment_text
7297 : : {
3961 alvherre@alvh.no-ip. 7298 : 24 : CommentStmt *n = makeNode(CommentStmt);
7299 : :
7300 : 24 : n->objtype = OBJECT_DOMCONSTRAINT;
7301 : : /*
7302 : : * should use Typename not any_name in the production, but
7303 : : * there's a shift/reduce conflict if we do that, so fix it
7304 : : * up here.
7305 : : */
3271 peter_e@gmx.net 7306 : 24 : n->object = (Node *) list_make2(makeTypeNameFromNameList($7), makeString($4));
3961 alvherre@alvh.no-ip. 7307 : 24 : n->comment = $9;
7308 : 24 : $$ = (Node *) n;
7309 : : }
7310 : : | COMMENT ON object_type_name_on_any_name name ON any_name IS comment_text
7311 : : {
3987 sfrost@snowman.net 7312 : 21 : CommentStmt *n = makeNode(CommentStmt);
7313 : :
1962 peter@eisentraut.org 7314 : 21 : n->objtype = $3;
3271 peter_e@gmx.net 7315 : 21 : n->object = (Node *) lappend($6, makeString($4));
3987 sfrost@snowman.net 7316 : 21 : n->comment = $8;
7317 : 21 : $$ = (Node *) n;
7318 : : }
7319 : : | COMMENT ON PROCEDURE function_with_argtypes IS comment_text
7320 : : {
2888 peter_e@gmx.net 7321 :UBC 0 : CommentStmt *n = makeNode(CommentStmt);
7322 : :
7323 : 0 : n->objtype = OBJECT_PROCEDURE;
7324 : 0 : n->object = (Node *) $4;
7325 : 0 : n->comment = $6;
7326 : 0 : $$ = (Node *) n;
7327 : : }
7328 : : | COMMENT ON ROUTINE function_with_argtypes IS comment_text
7329 : : {
7330 : 0 : CommentStmt *n = makeNode(CommentStmt);
7331 : :
7332 : 0 : n->objtype = OBJECT_ROUTINE;
7333 : 0 : n->object = (Node *) $4;
7334 : 0 : n->comment = $6;
7335 : 0 : $$ = (Node *) n;
7336 : : }
7337 : : | COMMENT ON TRANSFORM FOR Typename LANGUAGE name IS comment_text
7338 : : {
3837 peter_e@gmx.net 7339 :CBC 7 : CommentStmt *n = makeNode(CommentStmt);
7340 : :
7341 : 7 : n->objtype = OBJECT_TRANSFORM;
3271 7342 : 7 : n->object = (Node *) list_make2($5, makeString($7));
3837 7343 : 7 : n->comment = $9;
7344 : 7 : $$ = (Node *) n;
7345 : : }
7346 : : | COMMENT ON OPERATOR CLASS any_name USING name IS comment_text
7347 : : {
8011 tgl@sss.pgh.pa.us 7348 :UBC 0 : CommentStmt *n = makeNode(CommentStmt);
7349 : :
7350 : 0 : n->objtype = OBJECT_OPCLASS;
3271 peter_e@gmx.net 7351 : 0 : n->object = (Node *) lcons(makeString($7), $5);
8011 tgl@sss.pgh.pa.us 7352 : 0 : n->comment = $9;
7353 : 0 : $$ = (Node *) n;
7354 : : }
7355 : : | COMMENT ON OPERATOR FAMILY any_name USING name IS comment_text
7356 : : {
6852 7357 : 0 : CommentStmt *n = makeNode(CommentStmt);
7358 : :
7359 : 0 : n->objtype = OBJECT_OPFAMILY;
3271 peter_e@gmx.net 7360 : 0 : n->object = (Node *) lcons(makeString($7), $5);
6852 tgl@sss.pgh.pa.us 7361 : 0 : n->comment = $9;
7362 : 0 : $$ = (Node *) n;
7363 : : }
7364 : : | COMMENT ON LARGE_P OBJECT_P NumericOnly IS comment_text
7365 : : {
8011 tgl@sss.pgh.pa.us 7366 :CBC 21 : CommentStmt *n = makeNode(CommentStmt);
7367 : :
7368 : 21 : n->objtype = OBJECT_LARGEOBJECT;
3271 peter_e@gmx.net 7369 : 21 : n->object = (Node *) $5;
8011 tgl@sss.pgh.pa.us 7370 : 21 : n->comment = $7;
7371 : 21 : $$ = (Node *) n;
7372 : : }
7373 : : | COMMENT ON CAST '(' Typename AS Typename ')' IS comment_text
7374 : : {
8011 tgl@sss.pgh.pa.us 7375 :UBC 0 : CommentStmt *n = makeNode(CommentStmt);
7376 : :
7377 : 0 : n->objtype = OBJECT_CAST;
3271 peter_e@gmx.net 7378 : 0 : n->object = (Node *) list_make2($5, $7);
8011 tgl@sss.pgh.pa.us 7379 : 0 : n->comment = $10;
7380 : 0 : $$ = (Node *) n;
7381 : : }
7382 : : ;
7383 : :
7384 : : comment_text:
8506 tgl@sss.pgh.pa.us 7385 :CBC 3492 : Sconst { $$ = $1; }
7386 : 52 : | NULL_P { $$ = NULL; }
7387 : : ;
7388 : :
7389 : :
7390 : : /*****************************************************************************
7391 : : *
7392 : : * SECURITY LABEL [FOR <provider>] ON <object> IS <label>
7393 : : *
7394 : : * As with COMMENT ON, <object> can refer to various types of database
7395 : : * objects (e.g. TABLE, COLUMN, etc.).
7396 : : *
7397 : : *****************************************************************************/
7398 : :
7399 : : SecLabelStmt:
7400 : : SECURITY LABEL opt_provider ON object_type_any_name any_name
7401 : : IS security_label
7402 : : {
5509 rhaas@postgresql.org 7403 : 24 : SecLabelStmt *n = makeNode(SecLabelStmt);
7404 : :
7405 : 24 : n->provider = $3;
7406 : 24 : n->objtype = $5;
3271 peter_e@gmx.net 7407 : 24 : n->object = (Node *) $6;
7408 : 24 : n->label = $8;
7409 : 24 : $$ = (Node *) n;
7410 : : }
7411 : : | SECURITY LABEL opt_provider ON COLUMN any_name
7412 : : IS security_label
7413 : : {
1962 peter@eisentraut.org 7414 : 2 : SecLabelStmt *n = makeNode(SecLabelStmt);
7415 : :
7416 : 2 : n->provider = $3;
7417 : 2 : n->objtype = OBJECT_COLUMN;
7418 : 2 : n->object = (Node *) $6;
7419 : 2 : n->label = $8;
7420 : 2 : $$ = (Node *) n;
7421 : : }
7422 : : | SECURITY LABEL opt_provider ON object_type_name name
7423 : : IS security_label
7424 : : {
3271 peter_e@gmx.net 7425 : 22 : SecLabelStmt *n = makeNode(SecLabelStmt);
7426 : :
7427 : 22 : n->provider = $3;
7428 : 22 : n->objtype = $5;
7429 : 22 : n->object = (Node *) makeString($6);
5509 rhaas@postgresql.org 7430 : 22 : n->label = $8;
7431 : 22 : $$ = (Node *) n;
7432 : : }
7433 : : | SECURITY LABEL opt_provider ON TYPE_P Typename
7434 : : IS security_label
7435 : : {
3954 alvherre@alvh.no-ip. 7436 :UBC 0 : SecLabelStmt *n = makeNode(SecLabelStmt);
7437 : :
7438 : 0 : n->provider = $3;
7439 : 0 : n->objtype = OBJECT_TYPE;
3271 peter_e@gmx.net 7440 : 0 : n->object = (Node *) $6;
3954 alvherre@alvh.no-ip. 7441 : 0 : n->label = $8;
7442 : 0 : $$ = (Node *) n;
7443 : : }
7444 : : | SECURITY LABEL opt_provider ON DOMAIN_P Typename
7445 : : IS security_label
7446 : : {
3954 alvherre@alvh.no-ip. 7447 :CBC 1 : SecLabelStmt *n = makeNode(SecLabelStmt);
7448 : :
7449 : 1 : n->provider = $3;
3008 peter_e@gmx.net 7450 : 1 : n->objtype = OBJECT_DOMAIN;
3271 7451 : 1 : n->object = (Node *) $6;
3954 alvherre@alvh.no-ip. 7452 : 1 : n->label = $8;
7453 : 1 : $$ = (Node *) n;
7454 : : }
7455 : : | SECURITY LABEL opt_provider ON AGGREGATE aggregate_with_argtypes
7456 : : IS security_label
7457 : : {
5509 rhaas@postgresql.org 7458 :UBC 0 : SecLabelStmt *n = makeNode(SecLabelStmt);
7459 : :
7460 : 0 : n->provider = $3;
7461 : 0 : n->objtype = OBJECT_AGGREGATE;
3271 peter_e@gmx.net 7462 : 0 : n->object = (Node *) $6;
3329 7463 : 0 : n->label = $8;
5509 rhaas@postgresql.org 7464 : 0 : $$ = (Node *) n;
7465 : : }
7466 : : | SECURITY LABEL opt_provider ON FUNCTION function_with_argtypes
7467 : : IS security_label
7468 : : {
5509 rhaas@postgresql.org 7469 :CBC 1 : SecLabelStmt *n = makeNode(SecLabelStmt);
7470 : :
7471 : 1 : n->provider = $3;
7472 : 1 : n->objtype = OBJECT_FUNCTION;
3271 peter_e@gmx.net 7473 : 1 : n->object = (Node *) $6;
3329 7474 : 1 : n->label = $8;
5509 rhaas@postgresql.org 7475 : 1 : $$ = (Node *) n;
7476 : : }
7477 : : | SECURITY LABEL opt_provider ON LARGE_P OBJECT_P NumericOnly
7478 : : IS security_label
7479 : : {
5509 rhaas@postgresql.org 7480 :GBC 9 : SecLabelStmt *n = makeNode(SecLabelStmt);
7481 : :
7482 : 9 : n->provider = $3;
7483 : 9 : n->objtype = OBJECT_LARGEOBJECT;
3271 peter_e@gmx.net 7484 : 9 : n->object = (Node *) $7;
5509 rhaas@postgresql.org 7485 : 9 : n->label = $9;
7486 : 9 : $$ = (Node *) n;
7487 : : }
7488 : : | SECURITY LABEL opt_provider ON PROCEDURE function_with_argtypes
7489 : : IS security_label
7490 : : {
2888 peter_e@gmx.net 7491 :UBC 0 : SecLabelStmt *n = makeNode(SecLabelStmt);
7492 : :
7493 : 0 : n->provider = $3;
7494 : 0 : n->objtype = OBJECT_PROCEDURE;
7495 : 0 : n->object = (Node *) $6;
7496 : 0 : n->label = $8;
7497 : 0 : $$ = (Node *) n;
7498 : : }
7499 : : | SECURITY LABEL opt_provider ON ROUTINE function_with_argtypes
7500 : : IS security_label
7501 : : {
7502 : 0 : SecLabelStmt *n = makeNode(SecLabelStmt);
7503 : :
7504 : 0 : n->provider = $3;
7505 : 0 : n->objtype = OBJECT_ROUTINE;
7506 : 0 : n->object = (Node *) $6;
7507 : 0 : n->label = $8;
7508 : 0 : $$ = (Node *) n;
7509 : : }
7510 : : ;
7511 : :
4530 tgl@sss.pgh.pa.us 7512 :CBC 14 : opt_provider: FOR NonReservedWord_or_Sconst { $$ = $2; }
1806 peter@eisentraut.org 7513 : 45 : | /* EMPTY */ { $$ = NULL; }
7514 : : ;
7515 : :
5509 rhaas@postgresql.org 7516 : 59 : security_label: Sconst { $$ = $1; }
5509 rhaas@postgresql.org 7517 :UBC 0 : | NULL_P { $$ = NULL; }
7518 : : ;
7519 : :
7520 : : /*****************************************************************************
7521 : : *
7522 : : * QUERY:
7523 : : * fetch/move
7524 : : *
7525 : : *****************************************************************************/
7526 : :
7527 : : FetchStmt: FETCH fetch_args
7528 : : {
8266 tgl@sss.pgh.pa.us 7529 :CBC 3693 : FetchStmt *n = (FetchStmt *) $2;
7530 : :
2994 peter_e@gmx.net 7531 : 3693 : n->ismove = false;
1263 peter@eisentraut.org 7532 : 3693 : $$ = (Node *) n;
7533 : : }
7534 : : | MOVE fetch_args
7535 : : {
8266 tgl@sss.pgh.pa.us 7536 : 29 : FetchStmt *n = (FetchStmt *) $2;
7537 : :
2994 peter_e@gmx.net 7538 : 29 : n->ismove = true;
1263 peter@eisentraut.org 7539 : 29 : $$ = (Node *) n;
7540 : : }
7541 : : ;
7542 : :
7543 : : fetch_args: cursor_name
7544 : : {
9414 bruce@momjian.us 7545 : 83 : FetchStmt *n = makeNode(FetchStmt);
7546 : :
5829 alvherre@alvh.no-ip. 7547 : 83 : n->portalname = $1;
8295 tgl@sss.pgh.pa.us 7548 : 83 : n->direction = FETCH_FORWARD;
9414 bruce@momjian.us 7549 : 83 : n->howMany = 1;
117 michael@paquier.xyz 7550 :GNC 83 : n->location = -1;
7551 : 83 : n->direction_keyword = FETCH_KEYWORD_NONE;
1263 peter@eisentraut.org 7552 :CBC 83 : $$ = (Node *) n;
7553 : : }
7554 : : | from_in cursor_name
7555 : : {
9414 bruce@momjian.us 7556 : 78 : FetchStmt *n = makeNode(FetchStmt);
7557 : :
5829 alvherre@alvh.no-ip. 7558 : 78 : n->portalname = $2;
8295 tgl@sss.pgh.pa.us 7559 : 78 : n->direction = FETCH_FORWARD;
9414 bruce@momjian.us 7560 : 78 : n->howMany = 1;
117 michael@paquier.xyz 7561 :GNC 78 : n->location = -1;
7562 : 78 : n->direction_keyword = FETCH_KEYWORD_NONE;
7563 : 78 : $$ = (Node *) n;
7564 : : }
7565 : : | SignedIconst opt_from_in cursor_name
7566 : : {
7567 : 2103 : FetchStmt *n = makeNode(FetchStmt);
7568 : :
7569 : 2103 : n->portalname = $3;
7570 : 2103 : n->direction = FETCH_FORWARD;
7571 : 2103 : n->howMany = $1;
7572 : 2103 : n->location = @1;
7573 : 2103 : n->direction_keyword = FETCH_KEYWORD_NONE;
1263 peter@eisentraut.org 7574 :CBC 2103 : $$ = (Node *) n;
7575 : : }
7576 : : | NEXT opt_from_in cursor_name
7577 : : {
10255 vadim4o@yahoo.com 7578 : 1002 : FetchStmt *n = makeNode(FetchStmt);
7579 : :
5829 alvherre@alvh.no-ip. 7580 : 1002 : n->portalname = $3;
8266 tgl@sss.pgh.pa.us 7581 : 1002 : n->direction = FETCH_FORWARD;
7582 : 1002 : n->howMany = 1;
117 michael@paquier.xyz 7583 :GNC 1002 : n->location = -1;
7584 : 1002 : n->direction_keyword = FETCH_KEYWORD_NEXT;
1263 peter@eisentraut.org 7585 :CBC 1002 : $$ = (Node *) n;
7586 : : }
7587 : : | PRIOR opt_from_in cursor_name
7588 : : {
9414 bruce@momjian.us 7589 : 16 : FetchStmt *n = makeNode(FetchStmt);
7590 : :
5829 alvherre@alvh.no-ip. 7591 : 16 : n->portalname = $3;
8266 tgl@sss.pgh.pa.us 7592 : 16 : n->direction = FETCH_BACKWARD;
7593 : 16 : n->howMany = 1;
117 michael@paquier.xyz 7594 :GNC 16 : n->location = -1;
7595 : 16 : n->direction_keyword = FETCH_KEYWORD_PRIOR;
1263 peter@eisentraut.org 7596 :CBC 16 : $$ = (Node *) n;
7597 : : }
7598 : : | FIRST_P opt_from_in cursor_name
7599 : : {
9414 bruce@momjian.us 7600 : 13 : FetchStmt *n = makeNode(FetchStmt);
7601 : :
5829 alvherre@alvh.no-ip. 7602 : 13 : n->portalname = $3;
8266 tgl@sss.pgh.pa.us 7603 : 13 : n->direction = FETCH_ABSOLUTE;
9414 bruce@momjian.us 7604 : 13 : n->howMany = 1;
117 michael@paquier.xyz 7605 :GNC 13 : n->location = -1;
7606 : 13 : n->direction_keyword = FETCH_KEYWORD_FIRST;
1263 peter@eisentraut.org 7607 :CBC 13 : $$ = (Node *) n;
7608 : : }
7609 : : | LAST_P opt_from_in cursor_name
7610 : : {
8266 tgl@sss.pgh.pa.us 7611 : 10 : FetchStmt *n = makeNode(FetchStmt);
7612 : :
5829 alvherre@alvh.no-ip. 7613 : 10 : n->portalname = $3;
8266 tgl@sss.pgh.pa.us 7614 : 10 : n->direction = FETCH_ABSOLUTE;
7615 : 10 : n->howMany = -1;
117 michael@paquier.xyz 7616 :GNC 10 : n->location = -1;
7617 : 10 : n->direction_keyword = FETCH_KEYWORD_LAST;
1263 peter@eisentraut.org 7618 :CBC 10 : $$ = (Node *) n;
7619 : : }
7620 : : | ABSOLUTE_P SignedIconst opt_from_in cursor_name
7621 : : {
8266 tgl@sss.pgh.pa.us 7622 : 43 : FetchStmt *n = makeNode(FetchStmt);
7623 : :
5829 alvherre@alvh.no-ip. 7624 : 43 : n->portalname = $4;
8266 tgl@sss.pgh.pa.us 7625 : 43 : n->direction = FETCH_ABSOLUTE;
7626 : 43 : n->howMany = $2;
117 michael@paquier.xyz 7627 :GNC 43 : n->location = @2;
7628 : 43 : n->direction_keyword = FETCH_KEYWORD_ABSOLUTE;
1263 peter@eisentraut.org 7629 :CBC 43 : $$ = (Node *) n;
7630 : : }
7631 : : | RELATIVE_P SignedIconst opt_from_in cursor_name
7632 : : {
8266 tgl@sss.pgh.pa.us 7633 : 18 : FetchStmt *n = makeNode(FetchStmt);
7634 : :
5829 alvherre@alvh.no-ip. 7635 : 18 : n->portalname = $4;
8266 tgl@sss.pgh.pa.us 7636 : 18 : n->direction = FETCH_RELATIVE;
7637 : 18 : n->howMany = $2;
117 michael@paquier.xyz 7638 :GNC 18 : n->location = @2;
7639 : 18 : n->direction_keyword = FETCH_KEYWORD_RELATIVE;
1263 peter@eisentraut.org 7640 :CBC 18 : $$ = (Node *) n;
7641 : : }
7642 : : | ALL opt_from_in cursor_name
7643 : : {
8266 tgl@sss.pgh.pa.us 7644 : 134 : FetchStmt *n = makeNode(FetchStmt);
7645 : :
5829 alvherre@alvh.no-ip. 7646 : 134 : n->portalname = $3;
8266 tgl@sss.pgh.pa.us 7647 : 134 : n->direction = FETCH_FORWARD;
7648 : 134 : n->howMany = FETCH_ALL;
117 michael@paquier.xyz 7649 :GNC 134 : n->location = -1;
7650 : 134 : n->direction_keyword = FETCH_KEYWORD_ALL;
1263 peter@eisentraut.org 7651 :CBC 134 : $$ = (Node *) n;
7652 : : }
7653 : : | FORWARD opt_from_in cursor_name
7654 : : {
9414 bruce@momjian.us 7655 : 10 : FetchStmt *n = makeNode(FetchStmt);
7656 : :
5829 alvherre@alvh.no-ip. 7657 : 10 : n->portalname = $3;
8295 tgl@sss.pgh.pa.us 7658 : 10 : n->direction = FETCH_FORWARD;
9414 bruce@momjian.us 7659 : 10 : n->howMany = 1;
117 michael@paquier.xyz 7660 :GNC 10 : n->location = -1;
7661 : 10 : n->direction_keyword = FETCH_KEYWORD_FORWARD;
1263 peter@eisentraut.org 7662 :CBC 10 : $$ = (Node *) n;
7663 : : }
7664 : : | FORWARD SignedIconst opt_from_in cursor_name
7665 : : {
9414 bruce@momjian.us 7666 : 6 : FetchStmt *n = makeNode(FetchStmt);
7667 : :
5829 alvherre@alvh.no-ip. 7668 : 6 : n->portalname = $4;
8295 tgl@sss.pgh.pa.us 7669 : 6 : n->direction = FETCH_FORWARD;
8266 7670 : 6 : n->howMany = $2;
117 michael@paquier.xyz 7671 :GNC 6 : n->location = @2;
7672 : 6 : n->direction_keyword = FETCH_KEYWORD_FORWARD;
1263 peter@eisentraut.org 7673 :CBC 6 : $$ = (Node *) n;
7674 : : }
7675 : : | FORWARD ALL opt_from_in cursor_name
7676 : : {
8266 tgl@sss.pgh.pa.us 7677 : 8 : FetchStmt *n = makeNode(FetchStmt);
7678 : :
5829 alvherre@alvh.no-ip. 7679 : 8 : n->portalname = $4;
8266 tgl@sss.pgh.pa.us 7680 : 8 : n->direction = FETCH_FORWARD;
7681 : 8 : n->howMany = FETCH_ALL;
117 michael@paquier.xyz 7682 :GNC 8 : n->location = -1;
7683 : 8 : n->direction_keyword = FETCH_KEYWORD_FORWARD_ALL;
1263 peter@eisentraut.org 7684 :CBC 8 : $$ = (Node *) n;
7685 : : }
7686 : : | BACKWARD opt_from_in cursor_name
7687 : : {
8266 tgl@sss.pgh.pa.us 7688 : 40 : FetchStmt *n = makeNode(FetchStmt);
7689 : :
5829 alvherre@alvh.no-ip. 7690 : 40 : n->portalname = $3;
8266 tgl@sss.pgh.pa.us 7691 : 40 : n->direction = FETCH_BACKWARD;
9414 bruce@momjian.us 7692 : 40 : n->howMany = 1;
117 michael@paquier.xyz 7693 :GNC 40 : n->location = -1;
7694 : 40 : n->direction_keyword = FETCH_KEYWORD_BACKWARD;
1263 peter@eisentraut.org 7695 :CBC 40 : $$ = (Node *) n;
7696 : : }
7697 : : | BACKWARD SignedIconst opt_from_in cursor_name
7698 : : {
8266 tgl@sss.pgh.pa.us 7699 : 112 : FetchStmt *n = makeNode(FetchStmt);
7700 : :
5829 alvherre@alvh.no-ip. 7701 : 112 : n->portalname = $4;
8266 tgl@sss.pgh.pa.us 7702 : 112 : n->direction = FETCH_BACKWARD;
7703 : 112 : n->howMany = $2;
117 michael@paquier.xyz 7704 :GNC 112 : n->location = @2;
7705 : 112 : n->direction_keyword = FETCH_KEYWORD_BACKWARD;
1263 peter@eisentraut.org 7706 :CBC 112 : $$ = (Node *) n;
7707 : : }
7708 : : | BACKWARD ALL opt_from_in cursor_name
7709 : : {
8266 tgl@sss.pgh.pa.us 7710 : 46 : FetchStmt *n = makeNode(FetchStmt);
7711 : :
5829 alvherre@alvh.no-ip. 7712 : 46 : n->portalname = $4;
8266 tgl@sss.pgh.pa.us 7713 : 46 : n->direction = FETCH_BACKWARD;
7714 : 46 : n->howMany = FETCH_ALL;
117 michael@paquier.xyz 7715 :GNC 46 : n->location = -1;
7716 : 46 : n->direction_keyword = FETCH_KEYWORD_BACKWARD_ALL;
1263 peter@eisentraut.org 7717 :CBC 46 : $$ = (Node *) n;
7718 : : }
7719 : : ;
7720 : :
7721 : : from_in: FROM
7722 : : | IN_P
7723 : : ;
7724 : :
7725 : : opt_from_in: from_in
7726 : : | /* EMPTY */
7727 : : ;
7728 : :
7729 : :
7730 : : /*****************************************************************************
7731 : : *
7732 : : * GRANT and REVOKE statements
7733 : : *
7734 : : *****************************************************************************/
7735 : :
7736 : : GrantStmt: GRANT privileges ON privilege_target TO grantee_list
7737 : : opt_grant_grant_option opt_granted_by
7738 : : {
8906 peter_e@gmx.net 7739 : 5873 : GrantStmt *n = makeNode(GrantStmt);
7740 : :
7741 : 5873 : n->is_grant = true;
7742 : 5873 : n->privileges = $2;
5859 tgl@sss.pgh.pa.us 7743 : 5873 : n->targtype = ($4)->targtype;
8652 peter_e@gmx.net 7744 : 5873 : n->objtype = ($4)->objtype;
7745 : 5873 : n->objects = ($4)->objs;
7746 : 5873 : n->grantees = $6;
8313 7747 : 5873 : n->grant_option = $7;
1731 peter@eisentraut.org 7748 : 5873 : n->grantor = $8;
1263 7749 : 5873 : $$ = (Node *) n;
7750 : : }
7751 : : ;
7752 : :
7753 : : RevokeStmt:
7754 : : REVOKE privileges ON privilege_target
7755 : : FROM grantee_list opt_granted_by opt_drop_behavior
7756 : : {
8652 peter_e@gmx.net 7757 : 5206 : GrantStmt *n = makeNode(GrantStmt);
7758 : :
7759 : 5206 : n->is_grant = false;
7426 tgl@sss.pgh.pa.us 7760 : 5206 : n->grant_option = false;
7761 : 5206 : n->privileges = $2;
5859 7762 : 5206 : n->targtype = ($4)->targtype;
7426 7763 : 5206 : n->objtype = ($4)->objtype;
7764 : 5206 : n->objects = ($4)->objs;
7765 : 5206 : n->grantees = $6;
1731 peter@eisentraut.org 7766 : 5206 : n->grantor = $7;
7767 : 5206 : n->behavior = $8;
1263 7768 : 5206 : $$ = (Node *) n;
7769 : : }
7770 : : | REVOKE GRANT OPTION FOR privileges ON privilege_target
7771 : : FROM grantee_list opt_granted_by opt_drop_behavior
7772 : : {
7426 tgl@sss.pgh.pa.us 7773 : 8 : GrantStmt *n = makeNode(GrantStmt);
7774 : :
7775 : 8 : n->is_grant = false;
7776 : 8 : n->grant_option = true;
7777 : 8 : n->privileges = $5;
5859 7778 : 8 : n->targtype = ($7)->targtype;
7426 7779 : 8 : n->objtype = ($7)->objtype;
7780 : 8 : n->objects = ($7)->objs;
7781 : 8 : n->grantees = $9;
1731 peter@eisentraut.org 7782 : 8 : n->grantor = $10;
7783 : 8 : n->behavior = $11;
1263 7784 : 8 : $$ = (Node *) n;
7785 : : }
7786 : : ;
7787 : :
7788 : :
7789 : : /*
7790 : : * Privilege names are represented as strings; the validity of the privilege
7791 : : * names gets checked at execution. This is a bit annoying but we have little
7792 : : * choice because of the syntactic conflict with lists of role names in
7793 : : * GRANT/REVOKE. What's more, we have to call out in the "privilege"
7794 : : * production any reserved keywords that need to be usable as privilege names.
7795 : : */
7796 : :
7797 : : /* either ALL [PRIVILEGES] or a list of individual privileges */
7798 : : privileges: privilege_list
7426 tgl@sss.pgh.pa.us 7799 : 9782 : { $$ = $1; }
7800 : : | ALL
7801 : 1345 : { $$ = NIL; }
7802 : : | ALL PRIVILEGES
7803 : 60 : { $$ = NIL; }
7804 : : | ALL '(' columnList ')'
7805 : : {
6122 7806 : 9 : AccessPriv *n = makeNode(AccessPriv);
7807 : :
7808 : 9 : n->priv_name = NULL;
7809 : 9 : n->cols = $3;
7810 : 9 : $$ = list_make1(n);
7811 : : }
7812 : : | ALL PRIVILEGES '(' columnList ')'
7813 : : {
6122 tgl@sss.pgh.pa.us 7814 :UBC 0 : AccessPriv *n = makeNode(AccessPriv);
7815 : :
7816 : 0 : n->priv_name = NULL;
7817 : 0 : n->cols = $4;
7818 : 0 : $$ = list_make1(n);
7819 : : }
7820 : : ;
7821 : :
6122 tgl@sss.pgh.pa.us 7822 :CBC 10235 : privilege_list: privilege { $$ = list_make1($1); }
7823 : 275 : | privilege_list ',' privilege { $$ = lappend($1, $3); }
7824 : : ;
7825 : :
7826 : : privilege: SELECT opt_column_list
7827 : : {
7828 : 4752 : AccessPriv *n = makeNode(AccessPriv);
7829 : :
7830 : 4752 : n->priv_name = pstrdup($1);
7831 : 4752 : n->cols = $2;
7832 : 4752 : $$ = n;
7833 : : }
7834 : : | REFERENCES opt_column_list
7835 : : {
7836 : 7 : AccessPriv *n = makeNode(AccessPriv);
7837 : :
7838 : 7 : n->priv_name = pstrdup($1);
7839 : 7 : n->cols = $2;
7840 : 7 : $$ = n;
7841 : : }
7842 : : | CREATE opt_column_list
7843 : : {
7844 : 145 : AccessPriv *n = makeNode(AccessPriv);
7845 : :
7846 : 145 : n->priv_name = pstrdup($1);
7847 : 145 : n->cols = $2;
7848 : 145 : $$ = n;
7849 : : }
7850 : : | ALTER SYSTEM_P
7851 : : {
1300 7852 : 12 : AccessPriv *n = makeNode(AccessPriv);
7853 : 12 : n->priv_name = pstrdup("alter system");
7854 : 12 : n->cols = NIL;
7855 : 12 : $$ = n;
7856 : : }
7857 : : | ColId opt_column_list
7858 : : {
6122 7859 : 5594 : AccessPriv *n = makeNode(AccessPriv);
7860 : :
7861 : 5594 : n->priv_name = $1;
7862 : 5594 : n->cols = $2;
7863 : 5594 : $$ = n;
7864 : : }
7865 : : ;
7866 : :
7867 : : parameter_name_list:
7868 : : parameter_name
7869 : : {
1300 7870 : 38 : $$ = list_make1(makeString($1));
7871 : : }
7872 : : | parameter_name_list ',' parameter_name
7873 : : {
7874 : 25 : $$ = lappend($1, makeString($3));
7875 : : }
7876 : : ;
7877 : :
7878 : : parameter_name:
7879 : : ColId
7880 : : {
7881 : 63 : $$ = $1;
7882 : : }
7883 : : | parameter_name '.' ColId
7884 : : {
7885 : 16 : $$ = psprintf("%s.%s", $1, $3);
7886 : : }
7887 : : ;
7888 : :
7889 : :
7890 : : /* Don't bother trying to fold the first two rules into one using
7891 : : * opt_table. You're going to get conflicts.
7892 : : */
7893 : : privilege_target:
7894 : : qualified_name_list
7895 : : {
6122 7896 : 5780 : PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
7897 : :
5859 7898 : 5780 : n->targtype = ACL_TARGET_OBJECT;
2938 peter_e@gmx.net 7899 : 5780 : n->objtype = OBJECT_TABLE;
8652 7900 : 5780 : n->objs = $1;
7901 : 5780 : $$ = n;
7902 : : }
7903 : : | TABLE qualified_name_list
7904 : : {
6122 tgl@sss.pgh.pa.us 7905 : 181 : PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
7906 : :
5859 7907 : 181 : n->targtype = ACL_TARGET_OBJECT;
2938 peter_e@gmx.net 7908 : 181 : n->objtype = OBJECT_TABLE;
8652 7909 : 181 : n->objs = $2;
7910 : 181 : $$ = n;
7911 : : }
7912 : : | SEQUENCE qualified_name_list
7913 : : {
6122 tgl@sss.pgh.pa.us 7914 : 11 : PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
7915 : :
5859 7916 : 11 : n->targtype = ACL_TARGET_OBJECT;
2938 peter_e@gmx.net 7917 : 11 : n->objtype = OBJECT_SEQUENCE;
7219 bruce@momjian.us 7918 : 11 : n->objs = $2;
7919 : 11 : $$ = n;
7920 : : }
7921 : : | FOREIGN DATA_P WRAPPER name_list
7922 : : {
6122 tgl@sss.pgh.pa.us 7923 : 46 : PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
7924 : :
5859 7925 : 46 : n->targtype = ACL_TARGET_OBJECT;
2938 peter_e@gmx.net 7926 : 46 : n->objtype = OBJECT_FDW;
6156 7927 : 46 : n->objs = $4;
7928 : 46 : $$ = n;
7929 : : }
7930 : : | FOREIGN SERVER name_list
7931 : : {
6122 tgl@sss.pgh.pa.us 7932 : 45 : PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
7933 : :
5859 7934 : 45 : n->targtype = ACL_TARGET_OBJECT;
2938 peter_e@gmx.net 7935 : 45 : n->objtype = OBJECT_FOREIGN_SERVER;
6156 7936 : 45 : n->objs = $3;
7937 : 45 : $$ = n;
7938 : : }
7939 : : | FUNCTION function_with_argtypes_list
7940 : : {
6122 tgl@sss.pgh.pa.us 7941 : 4468 : PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
7942 : :
5859 7943 : 4468 : n->targtype = ACL_TARGET_OBJECT;
2938 peter_e@gmx.net 7944 : 4468 : n->objtype = OBJECT_FUNCTION;
8590 tgl@sss.pgh.pa.us 7945 : 4468 : n->objs = $2;
7946 : 4468 : $$ = n;
7947 : : }
7948 : : | PROCEDURE function_with_argtypes_list
7949 : : {
2888 peter_e@gmx.net 7950 : 21 : PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
7951 : :
7952 : 21 : n->targtype = ACL_TARGET_OBJECT;
2938 7953 : 21 : n->objtype = OBJECT_PROCEDURE;
2888 7954 : 21 : n->objs = $2;
7955 : 21 : $$ = n;
7956 : : }
7957 : : | ROUTINE function_with_argtypes_list
7958 : : {
2888 peter_e@gmx.net 7959 :UBC 0 : PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
7960 : :
7961 : 0 : n->targtype = ACL_TARGET_OBJECT;
2938 7962 : 0 : n->objtype = OBJECT_ROUTINE;
2888 7963 : 0 : n->objs = $2;
7964 : 0 : $$ = n;
7965 : : }
7966 : : | DATABASE name_list
7967 : : {
6122 tgl@sss.pgh.pa.us 7968 :CBC 169 : PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
7969 : :
5859 7970 : 169 : n->targtype = ACL_TARGET_OBJECT;
2938 peter_e@gmx.net 7971 : 169 : n->objtype = OBJECT_DATABASE;
8652 7972 : 169 : n->objs = $2;
7973 : 169 : $$ = n;
7974 : : }
7975 : : | DOMAIN_P any_name_list
7976 : : {
5060 7977 : 13 : PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
7978 : :
7979 : 13 : n->targtype = ACL_TARGET_OBJECT;
2938 7980 : 13 : n->objtype = OBJECT_DOMAIN;
5060 7981 : 13 : n->objs = $2;
7982 : 13 : $$ = n;
7983 : : }
7984 : : | LANGUAGE name_list
7985 : : {
6122 tgl@sss.pgh.pa.us 7986 : 21 : PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
7987 : :
5859 7988 : 21 : n->targtype = ACL_TARGET_OBJECT;
2938 peter_e@gmx.net 7989 : 21 : n->objtype = OBJECT_LANGUAGE;
8590 tgl@sss.pgh.pa.us 7990 : 21 : n->objs = $2;
7991 : 21 : $$ = n;
7992 : : }
7993 : : | LARGE_P OBJECT_P NumericOnly_list
7994 : : {
5799 itagaki.takahiro@gma 7995 : 45 : PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
7996 : :
7997 : 45 : n->targtype = ACL_TARGET_OBJECT;
2938 peter_e@gmx.net 7998 : 45 : n->objtype = OBJECT_LARGEOBJECT;
5799 itagaki.takahiro@gma 7999 : 45 : n->objs = $3;
8000 : 45 : $$ = n;
8001 : : }
8002 : : | PARAMETER parameter_name_list
8003 : : {
1300 tgl@sss.pgh.pa.us 8004 : 38 : PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
8005 : 38 : n->targtype = ACL_TARGET_OBJECT;
8006 : 38 : n->objtype = OBJECT_PARAMETER_ACL;
8007 : 38 : n->objs = $2;
8008 : 38 : $$ = n;
8009 : : }
8010 : : | SCHEMA name_list
8011 : : {
6122 8012 : 181 : PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
8013 : :
5859 8014 : 181 : n->targtype = ACL_TARGET_OBJECT;
2938 peter_e@gmx.net 8015 : 181 : n->objtype = OBJECT_SCHEMA;
8652 8016 : 181 : n->objs = $2;
8017 : 181 : $$ = n;
8018 : : }
8019 : : | TABLESPACE name_list
8020 : : {
6122 tgl@sss.pgh.pa.us 8021 : 3 : PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
8022 : :
5859 8023 : 3 : n->targtype = ACL_TARGET_OBJECT;
2938 peter_e@gmx.net 8024 : 3 : n->objtype = OBJECT_TABLESPACE;
7801 tgl@sss.pgh.pa.us 8025 : 3 : n->objs = $2;
8026 : 3 : $$ = n;
8027 : : }
8028 : : | TYPE_P any_name_list
8029 : : {
5060 peter_e@gmx.net 8030 : 56 : PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
8031 : :
8032 : 56 : n->targtype = ACL_TARGET_OBJECT;
2938 8033 : 56 : n->objtype = OBJECT_TYPE;
5060 8034 : 56 : n->objs = $2;
8035 : 56 : $$ = n;
8036 : : }
8037 : : | ALL TABLES IN_P SCHEMA name_list
8038 : : {
5859 tgl@sss.pgh.pa.us 8039 : 6 : PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
8040 : :
8041 : 6 : n->targtype = ACL_TARGET_ALL_IN_SCHEMA;
2938 peter_e@gmx.net 8042 : 6 : n->objtype = OBJECT_TABLE;
5859 tgl@sss.pgh.pa.us 8043 : 6 : n->objs = $5;
8044 : 6 : $$ = n;
8045 : : }
8046 : : | ALL SEQUENCES IN_P SCHEMA name_list
8047 : : {
5859 tgl@sss.pgh.pa.us 8048 :UBC 0 : PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
8049 : :
8050 : 0 : n->targtype = ACL_TARGET_ALL_IN_SCHEMA;
2938 peter_e@gmx.net 8051 : 0 : n->objtype = OBJECT_SEQUENCE;
5859 tgl@sss.pgh.pa.us 8052 : 0 : n->objs = $5;
8053 : 0 : $$ = n;
8054 : : }
8055 : : | ALL FUNCTIONS IN_P SCHEMA name_list
8056 : : {
5859 tgl@sss.pgh.pa.us 8057 :CBC 3 : PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
8058 : :
8059 : 3 : n->targtype = ACL_TARGET_ALL_IN_SCHEMA;
2938 peter_e@gmx.net 8060 : 3 : n->objtype = OBJECT_FUNCTION;
5859 tgl@sss.pgh.pa.us 8061 : 3 : n->objs = $5;
8062 : 3 : $$ = n;
8063 : : }
8064 : : | ALL PROCEDURES IN_P SCHEMA name_list
8065 : : {
2888 peter_e@gmx.net 8066 : 3 : PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
8067 : :
8068 : 3 : n->targtype = ACL_TARGET_ALL_IN_SCHEMA;
2938 8069 : 3 : n->objtype = OBJECT_PROCEDURE;
2888 8070 : 3 : n->objs = $5;
8071 : 3 : $$ = n;
8072 : : }
8073 : : | ALL ROUTINES IN_P SCHEMA name_list
8074 : : {
8075 : 3 : PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
8076 : :
8077 : 3 : n->targtype = ACL_TARGET_ALL_IN_SCHEMA;
2938 8078 : 3 : n->objtype = OBJECT_ROUTINE;
2888 8079 : 3 : n->objs = $5;
8080 : 3 : $$ = n;
8081 : : }
8082 : : ;
8083 : :
8084 : :
8085 : : grantee_list:
7820 neilc@samurai.com 8086 : 11190 : grantee { $$ = list_make1($1); }
8533 bruce@momjian.us 8087 : 54 : | grantee_list ',' grantee { $$ = lappend($1, $3); }
8088 : : ;
8089 : :
8090 : : grantee:
3885 alvherre@alvh.no-ip. 8091 : 11232 : RoleSpec { $$ = $1; }
8092 : 12 : | GROUP_P RoleSpec { $$ = $2; }
8093 : : ;
8094 : :
8095 : :
8096 : : opt_grant_grant_option:
2994 peter_e@gmx.net 8097 : 51 : WITH GRANT OPTION { $$ = true; }
8098 : 5884 : | /*EMPTY*/ { $$ = false; }
8099 : : ;
8100 : :
8101 : : /*****************************************************************************
8102 : : *
8103 : : * GRANT and REVOKE ROLE statements
8104 : : *
8105 : : *****************************************************************************/
8106 : :
8107 : : GrantRoleStmt:
8108 : : GRANT privilege_list TO role_list opt_granted_by
8109 : : {
7426 tgl@sss.pgh.pa.us 8110 : 286 : GrantRoleStmt *n = makeNode(GrantRoleStmt);
8111 : :
8112 : 286 : n->is_grant = true;
8113 : 286 : n->granted_roles = $2;
8114 : 286 : n->grantee_roles = $4;
1159 rhaas@postgresql.org 8115 : 286 : n->opt = NIL;
8116 : 286 : n->grantor = $5;
8117 : 286 : $$ = (Node *) n;
8118 : : }
8119 : : | GRANT privilege_list TO role_list WITH grant_role_opt_list opt_granted_by
8120 : : {
8121 : 89 : GrantRoleStmt *n = makeNode(GrantRoleStmt);
8122 : :
8123 : 89 : n->is_grant = true;
8124 : 89 : n->granted_roles = $2;
8125 : 89 : n->grantee_roles = $4;
8126 : 89 : n->opt = $6;
8127 : 89 : n->grantor = $7;
1263 peter@eisentraut.org 8128 : 89 : $$ = (Node *) n;
8129 : : }
8130 : : ;
8131 : :
8132 : : RevokeRoleStmt:
8133 : : REVOKE privilege_list FROM role_list opt_granted_by opt_drop_behavior
8134 : : {
7426 tgl@sss.pgh.pa.us 8135 : 45 : GrantRoleStmt *n = makeNode(GrantRoleStmt);
8136 : :
8137 : 45 : n->is_grant = false;
1159 rhaas@postgresql.org 8138 : 45 : n->opt = NIL;
7426 tgl@sss.pgh.pa.us 8139 : 45 : n->granted_roles = $2;
8140 : 45 : n->grantee_roles = $4;
1162 rhaas@postgresql.org 8141 : 45 : n->grantor = $5;
7426 tgl@sss.pgh.pa.us 8142 : 45 : n->behavior = $6;
1263 peter@eisentraut.org 8143 : 45 : $$ = (Node *) n;
8144 : : }
8145 : : | REVOKE ColId OPTION FOR privilege_list FROM role_list opt_granted_by opt_drop_behavior
8146 : : {
7426 tgl@sss.pgh.pa.us 8147 : 33 : GrantRoleStmt *n = makeNode(GrantRoleStmt);
8148 : : DefElem *opt;
8149 : :
1159 rhaas@postgresql.org 8150 : 33 : opt = makeDefElem(pstrdup($2),
8151 : 33 : (Node *) makeBoolean(false), @2);
7426 tgl@sss.pgh.pa.us 8152 : 33 : n->is_grant = false;
1159 rhaas@postgresql.org 8153 : 33 : n->opt = list_make1(opt);
7426 tgl@sss.pgh.pa.us 8154 : 33 : n->granted_roles = $5;
8155 : 33 : n->grantee_roles = $7;
1162 rhaas@postgresql.org 8156 : 33 : n->grantor = $8;
7426 tgl@sss.pgh.pa.us 8157 : 33 : n->behavior = $9;
1263 peter@eisentraut.org 8158 : 33 : $$ = (Node *) n;
8159 : : }
8160 : : ;
8161 : :
8162 : : grant_role_opt_list:
1159 rhaas@postgresql.org 8163 : 60 : grant_role_opt_list ',' grant_role_opt { $$ = lappend($1, $3); }
8164 : 89 : | grant_role_opt { $$ = list_make1($1); }
8165 : : ;
8166 : :
8167 : : grant_role_opt:
8168 : : ColLabel grant_role_opt_value
8169 : : {
8170 : 149 : $$ = makeDefElem(pstrdup($1), $2, @1);
8171 : : }
8172 : : ;
8173 : :
8174 : : grant_role_opt_value:
8175 : 36 : OPTION { $$ = (Node *) makeBoolean(true); }
8176 : 56 : | TRUE_P { $$ = (Node *) makeBoolean(true); }
8177 : 57 : | FALSE_P { $$ = (Node *) makeBoolean(false); }
8178 : : ;
8179 : :
3885 alvherre@alvh.no-ip. 8180 : 69 : opt_granted_by: GRANTED BY RoleSpec { $$ = $3; }
7426 tgl@sss.pgh.pa.us 8181 : 11471 : | /*EMPTY*/ { $$ = NULL; }
8182 : : ;
8183 : :
8184 : : /*****************************************************************************
8185 : : *
8186 : : * ALTER DEFAULT PRIVILEGES statement
8187 : : *
8188 : : *****************************************************************************/
8189 : :
8190 : : AlterDefaultPrivilegesStmt:
8191 : : ALTER DEFAULT PRIVILEGES DefACLOptionList DefACLAction
8192 : : {
5866 8193 : 103 : AlterDefaultPrivilegesStmt *n = makeNode(AlterDefaultPrivilegesStmt);
8194 : :
8195 : 103 : n->options = $4;
8196 : 103 : n->action = (GrantStmt *) $5;
1263 peter@eisentraut.org 8197 : 103 : $$ = (Node *) n;
8198 : : }
8199 : : ;
8200 : :
8201 : : DefACLOptionList:
5866 tgl@sss.pgh.pa.us 8202 : 72 : DefACLOptionList DefACLOption { $$ = lappend($1, $2); }
8203 : 103 : | /* EMPTY */ { $$ = NIL; }
8204 : : ;
8205 : :
8206 : : DefACLOption:
8207 : : IN_P SCHEMA name_list
8208 : : {
1263 peter@eisentraut.org 8209 : 30 : $$ = makeDefElem("schemas", (Node *) $3, @1);
8210 : : }
8211 : : | FOR ROLE role_list
8212 : : {
8213 : 42 : $$ = makeDefElem("roles", (Node *) $3, @1);
8214 : : }
8215 : : | FOR USER role_list
8216 : : {
1263 peter@eisentraut.org 8217 :UBC 0 : $$ = makeDefElem("roles", (Node *) $3, @1);
8218 : : }
8219 : : ;
8220 : :
8221 : : /*
8222 : : * This should match GRANT/REVOKE, except that individual target objects
8223 : : * are not mentioned and we only allow a subset of object types.
8224 : : */
8225 : : DefACLAction:
8226 : : GRANT privileges ON defacl_privilege_target TO grantee_list
8227 : : opt_grant_grant_option
8228 : : {
5866 tgl@sss.pgh.pa.us 8229 :CBC 62 : GrantStmt *n = makeNode(GrantStmt);
8230 : :
8231 : 62 : n->is_grant = true;
8232 : 62 : n->privileges = $2;
5859 8233 : 62 : n->targtype = ACL_TARGET_DEFAULTS;
5866 8234 : 62 : n->objtype = $4;
8235 : 62 : n->objects = NIL;
8236 : 62 : n->grantees = $6;
8237 : 62 : n->grant_option = $7;
1263 peter@eisentraut.org 8238 : 62 : $$ = (Node *) n;
8239 : : }
8240 : : | REVOKE privileges ON defacl_privilege_target
8241 : : FROM grantee_list opt_drop_behavior
8242 : : {
5866 tgl@sss.pgh.pa.us 8243 : 41 : GrantStmt *n = makeNode(GrantStmt);
8244 : :
8245 : 41 : n->is_grant = false;
8246 : 41 : n->grant_option = false;
8247 : 41 : n->privileges = $2;
5859 8248 : 41 : n->targtype = ACL_TARGET_DEFAULTS;
5866 8249 : 41 : n->objtype = $4;
8250 : 41 : n->objects = NIL;
8251 : 41 : n->grantees = $6;
8252 : 41 : n->behavior = $7;
1263 peter@eisentraut.org 8253 : 41 : $$ = (Node *) n;
8254 : : }
8255 : : | REVOKE GRANT OPTION FOR privileges ON defacl_privilege_target
8256 : : FROM grantee_list opt_drop_behavior
8257 : : {
5866 tgl@sss.pgh.pa.us 8258 :UBC 0 : GrantStmt *n = makeNode(GrantStmt);
8259 : :
8260 : 0 : n->is_grant = false;
8261 : 0 : n->grant_option = true;
8262 : 0 : n->privileges = $5;
5859 8263 : 0 : n->targtype = ACL_TARGET_DEFAULTS;
5866 8264 : 0 : n->objtype = $7;
8265 : 0 : n->objects = NIL;
8266 : 0 : n->grantees = $9;
8267 : 0 : n->behavior = $10;
1263 peter@eisentraut.org 8268 : 0 : $$ = (Node *) n;
8269 : : }
8270 : : ;
8271 : :
8272 : : defacl_privilege_target:
2938 peter_e@gmx.net 8273 :CBC 39 : TABLES { $$ = OBJECT_TABLE; }
8274 : 8 : | FUNCTIONS { $$ = OBJECT_FUNCTION; }
8275 : 3 : | ROUTINES { $$ = OBJECT_FUNCTION; }
8276 : 3 : | SEQUENCES { $$ = OBJECT_SEQUENCE; }
8277 : 17 : | TYPES_P { $$ = OBJECT_TYPE; }
8278 : 18 : | SCHEMAS { $$ = OBJECT_SCHEMA; }
206 fujii@postgresql.org 8279 : 15 : | LARGE_P OBJECTS_P { $$ = OBJECT_LARGEOBJECT; }
8280 : : ;
8281 : :
8282 : :
8283 : : /*****************************************************************************
8284 : : *
8285 : : * QUERY: CREATE INDEX
8286 : : *
8287 : : * Note: we cannot put TABLESPACE clause after WHERE clause unless we are
8288 : : * willing to make TABLESPACE a fully reserved word.
8289 : : *****************************************************************************/
8290 : :
8291 : : IndexStmt: CREATE opt_unique INDEX opt_concurrently opt_single_name
8292 : : ON relation_expr access_method_clause '(' index_params ')'
8293 : : opt_include opt_unique_null_treatment opt_reloptions OptTableSpace where_clause
8294 : : {
7003 tgl@sss.pgh.pa.us 8295 : 3343 : IndexStmt *n = makeNode(IndexStmt);
8296 : :
8297 : 3343 : n->unique = $2;
5787 8298 : 3343 : n->concurrent = $4;
7003 8299 : 3343 : n->idxname = $5;
8300 : 3343 : n->relation = $7;
8301 : 3343 : n->accessMethod = $8;
8302 : 3343 : n->indexParams = $10;
2760 teodor@sigaev.ru 8303 : 3343 : n->indexIncludingParams = $12;
1362 peter@eisentraut.org 8304 : 3343 : n->nulls_not_distinct = !$13;
8305 : 3343 : n->options = $14;
8306 : 3343 : n->tableSpace = $15;
8307 : 3343 : n->whereClause = $16;
4851 tgl@sss.pgh.pa.us 8308 : 3343 : n->excludeOpNames = NIL;
8309 : 3343 : n->idxcomment = NULL;
5389 8310 : 3343 : n->indexOid = InvalidOid;
1209 rhaas@postgresql.org 8311 : 3343 : n->oldNumber = InvalidRelFileNumber;
2032 noah@leadboat.com 8312 : 3343 : n->oldCreateSubid = InvalidSubTransactionId;
1209 rhaas@postgresql.org 8313 : 3343 : n->oldFirstRelfilelocatorSubid = InvalidSubTransactionId;
4851 tgl@sss.pgh.pa.us 8314 : 3343 : n->primary = false;
8315 : 3343 : n->isconstraint = false;
8316 : 3343 : n->deferrable = false;
8317 : 3343 : n->initdeferred = false;
3900 8318 : 3343 : n->transformed = false;
4008 fujii@postgresql.org 8319 : 3343 : n->if_not_exists = false;
2377 alvherre@alvh.no-ip. 8320 : 3343 : n->reset_default_tblspc = false;
1263 peter@eisentraut.org 8321 : 3343 : $$ = (Node *) n;
8322 : : }
8323 : : | CREATE opt_unique INDEX opt_concurrently IF_P NOT EXISTS name
8324 : : ON relation_expr access_method_clause '(' index_params ')'
8325 : : opt_include opt_unique_null_treatment opt_reloptions OptTableSpace where_clause
8326 : : {
4008 fujii@postgresql.org 8327 : 9 : IndexStmt *n = makeNode(IndexStmt);
8328 : :
8329 : 9 : n->unique = $2;
8330 : 9 : n->concurrent = $4;
8331 : 9 : n->idxname = $8;
8332 : 9 : n->relation = $10;
8333 : 9 : n->accessMethod = $11;
8334 : 9 : n->indexParams = $13;
2760 teodor@sigaev.ru 8335 : 9 : n->indexIncludingParams = $15;
1362 peter@eisentraut.org 8336 : 9 : n->nulls_not_distinct = !$16;
8337 : 9 : n->options = $17;
8338 : 9 : n->tableSpace = $18;
8339 : 9 : n->whereClause = $19;
4008 fujii@postgresql.org 8340 : 9 : n->excludeOpNames = NIL;
8341 : 9 : n->idxcomment = NULL;
8342 : 9 : n->indexOid = InvalidOid;
1209 rhaas@postgresql.org 8343 : 9 : n->oldNumber = InvalidRelFileNumber;
2032 noah@leadboat.com 8344 : 9 : n->oldCreateSubid = InvalidSubTransactionId;
1209 rhaas@postgresql.org 8345 : 9 : n->oldFirstRelfilelocatorSubid = InvalidSubTransactionId;
4008 fujii@postgresql.org 8346 : 9 : n->primary = false;
8347 : 9 : n->isconstraint = false;
8348 : 9 : n->deferrable = false;
8349 : 9 : n->initdeferred = false;
3900 tgl@sss.pgh.pa.us 8350 : 9 : n->transformed = false;
4008 fujii@postgresql.org 8351 : 9 : n->if_not_exists = true;
2377 alvherre@alvh.no-ip. 8352 : 9 : n->reset_default_tblspc = false;
1263 peter@eisentraut.org 8353 : 9 : $$ = (Node *) n;
8354 : : }
8355 : : ;
8356 : :
8357 : : opt_unique:
2994 peter_e@gmx.net 8358 : 645 : UNIQUE { $$ = true; }
8359 : 2710 : | /*EMPTY*/ { $$ = false; }
8360 : : ;
8361 : :
8362 : : access_method_clause:
1965 peter@eisentraut.org 8363 : 1513 : USING name { $$ = $2; }
8532 bruce@momjian.us 8364 : 1956 : | /*EMPTY*/ { $$ = DEFAULT_INDEX_TYPE; }
8365 : : ;
8366 : :
7820 neilc@samurai.com 8367 : 4073 : index_params: index_elem { $$ = list_make1($1); }
8188 tgl@sss.pgh.pa.us 8368 : 1082 : | index_params ',' index_elem { $$ = lappend($1, $3); }
8369 : : ;
8370 : :
8371 : :
8372 : : index_elem_options:
8373 : : opt_collate opt_qualified_name opt_asc_desc opt_nulls_order
8374 : : {
2037 akorotkov@postgresql 8375 : 5446 : $$ = makeNode(IndexElem);
8376 : 5446 : $$->name = NULL;
8377 : 5446 : $$->expr = NULL;
8378 : 5446 : $$->indexcolname = NULL;
8379 : 5446 : $$->collation = $1;
8380 : 5446 : $$->opclass = $2;
8381 : 5446 : $$->opclassopts = NIL;
8382 : 5446 : $$->ordering = $3;
8383 : 5446 : $$->nulls_ordering = $4;
8384 : : }
8385 : : | opt_collate any_name reloptions opt_asc_desc opt_nulls_order
8386 : : {
8387 : 71 : $$ = makeNode(IndexElem);
8388 : 71 : $$->name = NULL;
8389 : 71 : $$->expr = NULL;
8390 : 71 : $$->indexcolname = NULL;
8391 : 71 : $$->collation = $1;
8392 : 71 : $$->opclass = $2;
8393 : 71 : $$->opclassopts = $3;
8394 : 71 : $$->ordering = $4;
8395 : 71 : $$->nulls_ordering = $5;
8396 : : }
8397 : : ;
8398 : :
8399 : : /*
8400 : : * Index attributes can be either simple column references, or arbitrary
8401 : : * expressions in parens. For backwards-compatibility reasons, we allow
8402 : : * an expression that's just a function call to be written without parens.
8403 : : */
8404 : : index_elem: ColId index_elem_options
8405 : : {
8406 : 4956 : $$ = $2;
8188 tgl@sss.pgh.pa.us 8407 : 4956 : $$->name = $1;
8408 : : }
8409 : : | func_expr_windowless index_elem_options
8410 : : {
2037 akorotkov@postgresql 8411 : 303 : $$ = $2;
7698 tgl@sss.pgh.pa.us 8412 : 303 : $$->expr = $1;
8413 : : }
8414 : : | '(' a_expr ')' index_elem_options
8415 : : {
2037 akorotkov@postgresql 8416 : 258 : $$ = $4;
8188 tgl@sss.pgh.pa.us 8417 : 258 : $$->expr = $2;
8418 : : }
8419 : : ;
8420 : :
2760 teodor@sigaev.ru 8421 : 109 : opt_include: INCLUDE '(' index_including_params ')' { $$ = $3; }
8422 : 3243 : | /* EMPTY */ { $$ = NIL; }
8423 : : ;
8424 : :
8425 : 109 : index_including_params: index_elem { $$ = list_make1($1); }
8426 : 83 : | index_including_params ',' index_elem { $$ = lappend($1, $3); }
8427 : : ;
8428 : :
5375 peter_e@gmx.net 8429 : 96 : opt_collate: COLLATE any_name { $$ = $2; }
8430 : 8208 : | /*EMPTY*/ { $$ = NIL; }
8431 : : ;
8432 : :
8433 : :
6866 tgl@sss.pgh.pa.us 8434 : 909 : opt_asc_desc: ASC { $$ = SORTBY_ASC; }
6265 8435 : 1783 : | DESC { $$ = SORTBY_DESC; }
8436 : 56887 : | /*EMPTY*/ { $$ = SORTBY_DEFAULT; }
8437 : : ;
8438 : :
3898 8439 : 175 : opt_nulls_order: NULLS_LA FIRST_P { $$ = SORTBY_NULLS_FIRST; }
8440 : 859 : | NULLS_LA LAST_P { $$ = SORTBY_NULLS_LAST; }
6866 8441 : 58655 : | /*EMPTY*/ { $$ = SORTBY_NULLS_DEFAULT; }
8442 : : ;
8443 : :
8444 : :
8445 : : /*****************************************************************************
8446 : : *
8447 : : * QUERY:
8448 : : * create [or replace] function <fname>
8449 : : * [(<type-1> { , <type-n>})]
8450 : : * returns <type-r>
8451 : : * as <filename or code in language as appropriate>
8452 : : * language <lang> [with parameters]
8453 : : *
8454 : : *****************************************************************************/
8455 : :
8456 : : CreateFunctionStmt:
8457 : : CREATE opt_or_replace FUNCTION func_name func_args_with_defaults
8458 : : RETURNS func_return opt_createfunc_opt_list opt_routine_body
8459 : : {
8564 peter_e@gmx.net 8460 : 11965 : CreateFunctionStmt *n = makeNode(CreateFunctionStmt);
8461 : :
2831 tgl@sss.pgh.pa.us 8462 : 11965 : n->is_procedure = false;
8791 8463 : 11965 : n->replace = $2;
8602 8464 : 11965 : n->funcname = $4;
7965 8465 : 11965 : n->parameters = $5;
8613 8466 : 11965 : n->returnType = $7;
8564 peter_e@gmx.net 8467 : 11965 : n->options = $8;
1664 peter@eisentraut.org 8468 : 11965 : n->sql_body = $9;
1263 8469 : 11965 : $$ = (Node *) n;
8470 : : }
8471 : : | CREATE opt_or_replace FUNCTION func_name func_args_with_defaults
8472 : : RETURNS TABLE '(' table_func_column_list ')' opt_createfunc_opt_list opt_routine_body
8473 : : {
6310 tgl@sss.pgh.pa.us 8474 : 97 : CreateFunctionStmt *n = makeNode(CreateFunctionStmt);
8475 : :
2831 8476 : 97 : n->is_procedure = false;
6310 8477 : 97 : n->replace = $2;
8478 : 97 : n->funcname = $4;
361 8479 : 97 : n->parameters = mergeTableFuncParameters($5, $9, yyscanner);
6310 8480 : 97 : n->returnType = TableFuncTypeName($9);
8481 : 97 : n->returnType->location = @7;
8482 : 97 : n->options = $11;
1664 peter@eisentraut.org 8483 : 97 : n->sql_body = $12;
1263 8484 : 97 : $$ = (Node *) n;
8485 : : }
8486 : : | CREATE opt_or_replace FUNCTION func_name func_args_with_defaults
8487 : : opt_createfunc_opt_list opt_routine_body
8488 : : {
7515 tgl@sss.pgh.pa.us 8489 : 242 : CreateFunctionStmt *n = makeNode(CreateFunctionStmt);
8490 : :
2831 8491 : 242 : n->is_procedure = false;
7515 8492 : 242 : n->replace = $2;
8493 : 242 : n->funcname = $4;
8494 : 242 : n->parameters = $5;
8495 : 242 : n->returnType = NULL;
8496 : 242 : n->options = $6;
1664 peter@eisentraut.org 8497 : 242 : n->sql_body = $7;
1263 8498 : 242 : $$ = (Node *) n;
8499 : : }
8500 : : | CREATE opt_or_replace PROCEDURE func_name func_args_with_defaults
8501 : : opt_createfunc_opt_list opt_routine_body
8502 : : {
2888 peter_e@gmx.net 8503 : 182 : CreateFunctionStmt *n = makeNode(CreateFunctionStmt);
8504 : :
2831 tgl@sss.pgh.pa.us 8505 : 182 : n->is_procedure = true;
2888 peter_e@gmx.net 8506 : 182 : n->replace = $2;
8507 : 182 : n->funcname = $4;
8508 : 182 : n->parameters = $5;
8509 : 182 : n->returnType = NULL;
8510 : 182 : n->options = $6;
1664 peter@eisentraut.org 8511 : 182 : n->sql_body = $7;
1263 8512 : 182 : $$ = (Node *) n;
8513 : : }
8514 : : ;
8515 : :
8516 : : opt_or_replace:
2994 peter_e@gmx.net 8517 : 5026 : OR REPLACE { $$ = true; }
8518 : 10193 : | /*EMPTY*/ { $$ = false; }
8519 : : ;
8520 : :
8533 bruce@momjian.us 8521 : 6063 : func_args: '(' func_args_list ')' { $$ = $2; }
8522 : 2959 : | '(' ')' { $$ = NIL; }
8523 : : ;
8524 : :
8525 : : func_args_list:
7820 neilc@samurai.com 8526 : 6063 : func_arg { $$ = list_make1($1); }
8533 bruce@momjian.us 8527 : 5708 : | func_args_list ',' func_arg { $$ = lappend($1, $3); }
8528 : : ;
8529 : :
8530 : : function_with_argtypes_list:
3329 peter_e@gmx.net 8531 : 6374 : function_with_argtypes { $$ = list_make1($1); }
8532 : : | function_with_argtypes_list ',' function_with_argtypes
8533 : 42 : { $$ = lappend($1, $3); }
8534 : : ;
8535 : :
8536 : : function_with_argtypes:
8537 : : func_name func_args
8538 : : {
3225 8539 : 9022 : ObjectWithArgs *n = makeNode(ObjectWithArgs);
8540 : :
8541 : 9022 : n->objname = $1;
1600 tgl@sss.pgh.pa.us 8542 : 9022 : n->objargs = extractArgTypes($2);
8543 : 9022 : n->objfuncargs = $2;
3329 peter_e@gmx.net 8544 : 9022 : $$ = n;
8545 : : }
8546 : : /*
8547 : : * Because of reduce/reduce conflicts, we can't use func_name
8548 : : * below, but we can write it out the long way, which actually
8549 : : * allows more cases.
8550 : : */
8551 : : | type_func_name_keyword
8552 : : {
3154 peter_e@gmx.net 8553 :UBC 0 : ObjectWithArgs *n = makeNode(ObjectWithArgs);
8554 : :
8555 : 0 : n->objname = list_make1(makeString(pstrdup($1)));
8556 : 0 : n->args_unspecified = true;
8557 : 0 : $$ = n;
8558 : : }
8559 : : | ColId
8560 : : {
3154 peter_e@gmx.net 8561 :CBC 185 : ObjectWithArgs *n = makeNode(ObjectWithArgs);
8562 : :
8563 : 185 : n->objname = list_make1(makeString($1));
8564 : 185 : n->args_unspecified = true;
8565 : 185 : $$ = n;
8566 : : }
8567 : : | ColId indirection
8568 : : {
8569 : 14 : ObjectWithArgs *n = makeNode(ObjectWithArgs);
8570 : :
8571 : 14 : n->objname = check_func_name(lcons(makeString($1), $2),
8572 : : yyscanner);
8573 : 14 : n->args_unspecified = true;
8574 : 14 : $$ = n;
8575 : : }
8576 : : ;
8577 : :
8578 : : /*
8579 : : * func_args_with_defaults is separate because we only want to accept
8580 : : * defaults in CREATE FUNCTION, not in ALTER etc.
8581 : : */
8582 : : func_args_with_defaults:
6171 8583 : 10245 : '(' func_args_with_defaults_list ')' { $$ = $2; }
6157 tgl@sss.pgh.pa.us 8584 : 2241 : | '(' ')' { $$ = NIL; }
8585 : : ;
8586 : :
8587 : : func_args_with_defaults_list:
8588 : 10245 : func_arg_with_default { $$ = list_make1($1); }
8589 : : | func_args_with_defaults_list ',' func_arg_with_default
8590 : 17756 : { $$ = lappend($1, $3); }
8591 : : ;
8592 : :
8593 : : /*
8594 : : * The style with arg_class first is SQL99 standard, but Oracle puts
8595 : : * param_name first; accept both since it's likely people will try both
8596 : : * anyway. Don't bother trying to save productions by letting arg_class
8597 : : * have an empty alternative ... you'll get shift/reduce conflicts.
8598 : : *
8599 : : * We can catch over-specified arguments here if we want to,
8600 : : * but for now better to silently swallow typmod, etc.
8601 : : * - thomas 2000-03-22
8602 : : */
8603 : : func_arg:
8604 : : arg_class param_name func_type
8605 : : {
7965 8606 : 7918 : FunctionParameter *n = makeNode(FunctionParameter);
8607 : :
8608 : 7918 : n->name = $2;
8609 : 7918 : n->argType = $3;
7517 8610 : 7918 : n->mode = $1;
6171 peter_e@gmx.net 8611 : 7918 : n->defexpr = NULL;
361 tgl@sss.pgh.pa.us 8612 : 7918 : n->location = @1;
7965 8613 : 7918 : $$ = n;
8614 : : }
8615 : : | param_name arg_class func_type
8616 : : {
8617 : 210 : FunctionParameter *n = makeNode(FunctionParameter);
8618 : :
7517 8619 : 210 : n->name = $1;
8620 : 210 : n->argType = $3;
8621 : 210 : n->mode = $2;
6171 peter_e@gmx.net 8622 : 210 : n->defexpr = NULL;
361 tgl@sss.pgh.pa.us 8623 : 210 : n->location = @1;
7517 8624 : 210 : $$ = n;
8625 : : }
8626 : : | param_name func_type
8627 : : {
8628 : 7979 : FunctionParameter *n = makeNode(FunctionParameter);
8629 : :
8630 : 7979 : n->name = $1;
7965 8631 : 7979 : n->argType = $2;
1600 8632 : 7979 : n->mode = FUNC_PARAM_DEFAULT;
6171 peter_e@gmx.net 8633 : 7979 : n->defexpr = NULL;
361 tgl@sss.pgh.pa.us 8634 : 7979 : n->location = @1;
7965 8635 : 7979 : $$ = n;
8636 : : }
8637 : : | arg_class func_type
8638 : : {
7517 8639 : 164 : FunctionParameter *n = makeNode(FunctionParameter);
8640 : :
8641 : 164 : n->name = NULL;
8642 : 164 : n->argType = $2;
8643 : 164 : n->mode = $1;
6171 peter_e@gmx.net 8644 : 164 : n->defexpr = NULL;
361 tgl@sss.pgh.pa.us 8645 : 164 : n->location = @1;
7517 8646 : 164 : $$ = n;
8647 : : }
8648 : : | func_type
8649 : : {
8650 : 23951 : FunctionParameter *n = makeNode(FunctionParameter);
8651 : :
8652 : 23951 : n->name = NULL;
8653 : 23951 : n->argType = $1;
1600 8654 : 23951 : n->mode = FUNC_PARAM_DEFAULT;
6171 peter_e@gmx.net 8655 : 23951 : n->defexpr = NULL;
361 tgl@sss.pgh.pa.us 8656 : 23951 : n->location = @1;
7517 8657 : 23951 : $$ = n;
8658 : : }
8659 : : ;
8660 : :
8661 : : /* INOUT is SQL99 standard, IN OUT is for Oracle compatibility */
6312 8662 : 1699 : arg_class: IN_P { $$ = FUNC_PARAM_IN; }
8663 : 6205 : | OUT_P { $$ = FUNC_PARAM_OUT; }
8664 : 99 : | INOUT { $$ = FUNC_PARAM_INOUT; }
6312 tgl@sss.pgh.pa.us 8665 :UBC 0 : | IN_P OUT_P { $$ = FUNC_PARAM_INOUT; }
6312 tgl@sss.pgh.pa.us 8666 :CBC 289 : | VARIADIC { $$ = FUNC_PARAM_VARIADIC; }
8667 : : ;
8668 : :
8669 : : /*
8670 : : * Ideally param_name should be ColId, but that causes too many conflicts.
8671 : : */
8672 : : param_name: type_function_name
8673 : : ;
8674 : :
8675 : : func_return:
8676 : : func_type
8677 : : {
8678 : : /* We can catch over-specified results here if we want to,
8679 : : * but for now better to silently swallow typmod, etc.
8680 : : * - thomas 2000-03-22
8681 : : */
9345 lockhart@fourpalms.o 8682 : 11965 : $$ = $1;
8683 : : }
8684 : : ;
8685 : :
8686 : : /*
8687 : : * We would like to make the %TYPE productions here be ColId attrs etc,
8688 : : * but that causes reduce/reduce conflicts. type_function_name
8689 : : * is next best choice.
8690 : : */
8533 bruce@momjian.us 8691 : 62767 : func_type: Typename { $$ = $1; }
8692 : : | type_function_name attrs '%' TYPE_P
8693 : : {
6876 tgl@sss.pgh.pa.us 8694 : 9 : $$ = makeTypeNameFromNameList(lcons(makeString($1), $2));
8613 8695 : 9 : $$->pct_type = true;
7167 8696 : 9 : $$->location = @1;
8697 : : }
8698 : : | SETOF type_function_name attrs '%' TYPE_P
8699 : : {
6876 8700 : 3 : $$ = makeTypeNameFromNameList(lcons(makeString($2), $3));
7209 8701 : 3 : $$->pct_type = true;
2994 peter_e@gmx.net 8702 : 3 : $$->setof = true;
7167 tgl@sss.pgh.pa.us 8703 : 3 : $$->location = @2;
8704 : : }
8705 : : ;
8706 : :
8707 : : func_arg_with_default:
8708 : : func_arg
8709 : : {
5109 peter_e@gmx.net 8710 : 24780 : $$ = $1;
8711 : : }
8712 : : | func_arg DEFAULT a_expr
8713 : : {
8714 : 3123 : $$ = $1;
8715 : 3123 : $$->defexpr = $3;
8716 : : }
8717 : : | func_arg '=' a_expr
8718 : : {
8719 : 98 : $$ = $1;
8720 : 98 : $$->defexpr = $3;
8721 : : }
8722 : : ;
8723 : :
8724 : : /* Aggregate args can be most things that function args can be */
8725 : : aggr_arg: func_arg
8726 : : {
1600 tgl@sss.pgh.pa.us 8727 [ + + ]: 450 : if (!($1->mode == FUNC_PARAM_DEFAULT ||
8728 [ + - ]: 30 : $1->mode == FUNC_PARAM_IN ||
4437 8729 [ - + ]: 30 : $1->mode == FUNC_PARAM_VARIADIC))
4437 tgl@sss.pgh.pa.us 8730 [ # # ]:UBC 0 : ereport(ERROR,
8731 : : (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
8732 : : errmsg("aggregates cannot have output arguments"),
8733 : : parser_errposition(@1)));
4437 tgl@sss.pgh.pa.us 8734 :CBC 450 : $$ = $1;
8735 : : }
8736 : : ;
8737 : :
8738 : : /*
8739 : : * The SQL standard offers no guidance on how to declare aggregate argument
8740 : : * lists, since it doesn't have CREATE AGGREGATE etc. We accept these cases:
8741 : : *
8742 : : * (*) - normal agg with no args
8743 : : * (aggr_arg,...) - normal agg with args
8744 : : * (ORDER BY aggr_arg,...) - ordered-set agg with no direct args
8745 : : * (aggr_arg,... ORDER BY aggr_arg,...) - ordered-set agg with direct args
8746 : : *
8747 : : * The zero-argument case is spelled with '*' for consistency with COUNT(*).
8748 : : *
8749 : : * An additional restriction is that if the direct-args list ends in a
8750 : : * VARIADIC item, the ordered-args list must contain exactly one item that
8751 : : * is also VARIADIC with the same type. This allows us to collapse the two
8752 : : * VARIADIC items into one, which is necessary to represent the aggregate in
8753 : : * pg_proc. We check this at the grammar stage so that we can return a list
8754 : : * in which the second VARIADIC item is already discarded, avoiding extra work
8755 : : * in cases such as DROP AGGREGATE.
8756 : : *
8757 : : * The return value of this production is a two-element list, in which the
8758 : : * first item is a sublist of FunctionParameter nodes (with any duplicate
8759 : : * VARIADIC item already dropped, as per above) and the second is an Integer
8760 : : * node, containing -1 if there was no ORDER BY and otherwise the number
8761 : : * of argument declarations before the ORDER BY. (If this number is equal
8762 : : * to the first sublist's length, then we dropped a duplicate VARIADIC item.)
8763 : : * This representation is passed as-is to CREATE AGGREGATE; for operations
8764 : : * on existing aggregates, we can just apply extractArgTypes to the first
8765 : : * sublist.
8766 : : */
8767 : : aggr_args: '(' '*' ')'
8768 : : {
4326 8769 : 68 : $$ = list_make2(NIL, makeInteger(-1));
8770 : : }
8771 : : | '(' aggr_args_list ')'
8772 : : {
8773 : 366 : $$ = list_make2($2, makeInteger(-1));
8774 : : }
8775 : : | '(' ORDER BY aggr_args_list ')'
8776 : : {
8777 : 3 : $$ = list_make2($4, makeInteger(0));
8778 : : }
8779 : : | '(' aggr_args_list ORDER BY aggr_args_list ')'
8780 : : {
8781 : : /* this is the only case requiring consistency checking */
8782 : 16 : $$ = makeOrderedSetArgs($2, $5, yyscanner);
8783 : : }
8784 : : ;
8785 : :
8786 : : aggr_args_list:
4437 8787 : 401 : aggr_arg { $$ = list_make1($1); }
8788 : 49 : | aggr_args_list ',' aggr_arg { $$ = lappend($1, $3); }
8789 : : ;
8790 : :
8791 : : aggregate_with_argtypes:
8792 : : func_name aggr_args
8793 : : {
3225 peter_e@gmx.net 8794 : 181 : ObjectWithArgs *n = makeNode(ObjectWithArgs);
8795 : :
8796 : 181 : n->objname = $1;
8797 : 181 : n->objargs = extractAggrArgTypes($2);
1600 tgl@sss.pgh.pa.us 8798 : 181 : n->objfuncargs = (List *) linitial($2);
3329 peter_e@gmx.net 8799 : 181 : $$ = n;
8800 : : }
8801 : : ;
8802 : :
8803 : : aggregate_with_argtypes_list:
3225 8804 : 52 : aggregate_with_argtypes { $$ = list_make1($1); }
8805 : : | aggregate_with_argtypes_list ',' aggregate_with_argtypes
3225 peter_e@gmx.net 8806 :UBC 0 : { $$ = lappend($1, $3); }
8807 : : ;
8808 : :
8809 : : opt_createfunc_opt_list:
8810 : : createfunc_opt_list
1664 peter@eisentraut.org 8811 :CBC 27 : | /*EMPTY*/ { $$ = NIL; }
8812 : : ;
8813 : :
8814 : : createfunc_opt_list:
8815 : : /* Must be at least one to prevent conflict */
5109 peter_e@gmx.net 8816 : 12459 : createfunc_opt_item { $$ = list_make1($1); }
8532 bruce@momjian.us 8817 : 33170 : | createfunc_opt_list createfunc_opt_item { $$ = lappend($1, $2); }
8818 : : ;
8819 : :
8820 : : /*
8821 : : * Options common to both CREATE FUNCTION and ALTER FUNCTION
8822 : : */
8823 : : common_func_opt_item:
8824 : : CALLED ON NULL_P INPUT_P
8825 : : {
1263 peter@eisentraut.org 8826 : 159 : $$ = makeDefElem("strict", (Node *) makeBoolean(false), @1);
8827 : : }
8828 : : | RETURNS NULL_P ON NULL_P INPUT_P
8829 : : {
8830 : 441 : $$ = makeDefElem("strict", (Node *) makeBoolean(true), @1);
8831 : : }
8832 : : | STRICT_P
8833 : : {
8834 : 6741 : $$ = makeDefElem("strict", (Node *) makeBoolean(true), @1);
8835 : : }
8836 : : | IMMUTABLE
8837 : : {
8838 : 5102 : $$ = makeDefElem("volatility", (Node *) makeString("immutable"), @1);
8839 : : }
8840 : : | STABLE
8841 : : {
8842 : 1262 : $$ = makeDefElem("volatility", (Node *) makeString("stable"), @1);
8843 : : }
8844 : : | VOLATILE
8845 : : {
8846 : 885 : $$ = makeDefElem("volatility", (Node *) makeString("volatile"), @1);
8847 : : }
8848 : : | EXTERNAL SECURITY DEFINER
8849 : : {
1263 peter@eisentraut.org 8850 :UBC 0 : $$ = makeDefElem("security", (Node *) makeBoolean(true), @1);
8851 : : }
8852 : : | EXTERNAL SECURITY INVOKER
8853 : : {
8854 : 0 : $$ = makeDefElem("security", (Node *) makeBoolean(false), @1);
8855 : : }
8856 : : | SECURITY DEFINER
8857 : : {
1263 peter@eisentraut.org 8858 :CBC 31 : $$ = makeDefElem("security", (Node *) makeBoolean(true), @1);
8859 : : }
8860 : : | SECURITY INVOKER
8861 : : {
8862 : 9 : $$ = makeDefElem("security", (Node *) makeBoolean(false), @1);
8863 : : }
8864 : : | LEAKPROOF
8865 : : {
8866 : 23 : $$ = makeDefElem("leakproof", (Node *) makeBoolean(true), @1);
8867 : : }
8868 : : | NOT LEAKPROOF
8869 : : {
8870 : 6 : $$ = makeDefElem("leakproof", (Node *) makeBoolean(false), @1);
8871 : : }
8872 : : | COST NumericOnly
8873 : : {
8874 : 2180 : $$ = makeDefElem("cost", (Node *) $2, @1);
8875 : : }
8876 : : | ROWS NumericOnly
8877 : : {
8878 : 300 : $$ = makeDefElem("rows", (Node *) $2, @1);
8879 : : }
8880 : : | SUPPORT any_name
8881 : : {
8882 : 57 : $$ = makeDefElem("support", (Node *) $2, @1);
8883 : : }
8884 : : | FunctionSetResetClause
8885 : : {
8886 : : /* we abuse the normal content of a DefElem here */
8887 : 63 : $$ = makeDefElem("set", (Node *) $1, @1);
8888 : : }
8889 : : | PARALLEL ColId
8890 : : {
8891 : 6900 : $$ = makeDefElem("parallel", (Node *) makeString($2), @1);
8892 : : }
8893 : : ;
8894 : :
8895 : : createfunc_opt_item:
8896 : : AS func_as
8897 : : {
8898 : 9649 : $$ = makeDefElem("as", (Node *) $2, @1);
8899 : : }
8900 : : | LANGUAGE NonReservedWord_or_Sconst
8901 : : {
8902 : 12449 : $$ = makeDefElem("language", (Node *) makeString($2), @1);
8903 : : }
8904 : : | TRANSFORM transform_type_list
8905 : : {
8906 : 59 : $$ = makeDefElem("transform", (Node *) $2, @1);
8907 : : }
8908 : : | WINDOW
8909 : : {
8910 : 10 : $$ = makeDefElem("window", (Node *) makeBoolean(true), @1);
8911 : : }
8912 : : | common_func_opt_item
8913 : : {
7532 neilc@samurai.com 8914 : 23462 : $$ = $1;
8915 : : }
8916 : : ;
8917 : :
7820 8918 : 8311 : func_as: Sconst { $$ = list_make1(makeString($1)); }
8919 : : | Sconst ',' Sconst
8920 : : {
8921 : 1338 : $$ = list_make2(makeString($1), makeString($3));
8922 : : }
8923 : : ;
8924 : :
8925 : : ReturnStmt: RETURN a_expr
8926 : : {
1664 peter@eisentraut.org 8927 : 2439 : ReturnStmt *r = makeNode(ReturnStmt);
8928 : :
8929 : 2439 : r->returnval = (Node *) $2;
8930 : 2439 : $$ = (Node *) r;
8931 : : }
8932 : : ;
8933 : :
8934 : : opt_routine_body:
8935 : : ReturnStmt
8936 : : {
8937 : 2436 : $$ = $1;
8938 : : }
8939 : : | BEGIN_P ATOMIC routine_body_stmt_list END_P
8940 : : {
8941 : : /*
8942 : : * A compound statement is stored as a single-item list
8943 : : * containing the list of statements as its member. That
8944 : : * way, the parse analysis code can tell apart an empty
8945 : : * body from no body at all.
8946 : : */
8947 : 404 : $$ = (Node *) list_make1($3);
8948 : : }
8949 : : | /*EMPTY*/
8950 : : {
8951 : 9646 : $$ = NULL;
8952 : : }
8953 : : ;
8954 : :
8955 : : routine_body_stmt_list:
8956 : : routine_body_stmt_list routine_body_stmt ';'
8957 : : {
8958 : : /* As in stmtmulti, discard empty statements */
1602 tgl@sss.pgh.pa.us 8959 [ + + ]: 412 : if ($2 != NULL)
8960 : 403 : $$ = lappend($1, $2);
8961 : : else
8962 : 9 : $$ = $1;
8963 : : }
8964 : : | /*EMPTY*/
8965 : : {
1664 peter@eisentraut.org 8966 : 404 : $$ = NIL;
8967 : : }
8968 : : ;
8969 : :
8970 : : routine_body_stmt:
8971 : : stmt
8972 : : | ReturnStmt
8973 : : ;
8974 : :
8975 : : transform_type_list:
3837 peter_e@gmx.net 8976 : 59 : FOR TYPE_P Typename { $$ = list_make1($3); }
8977 : 2 : | transform_type_list ',' FOR TYPE_P Typename { $$ = lappend($1, $5); }
8978 : : ;
8979 : :
8980 : : opt_definition:
8533 bruce@momjian.us 8981 : 334 : WITH definition { $$ = $2; }
8982 : 5159 : | /*EMPTY*/ { $$ = NIL; }
8983 : : ;
8984 : :
8985 : : table_func_column: param_name func_type
8986 : : {
6310 tgl@sss.pgh.pa.us 8987 : 227 : FunctionParameter *n = makeNode(FunctionParameter);
8988 : :
8989 : 227 : n->name = $1;
8990 : 227 : n->argType = $2;
8991 : 227 : n->mode = FUNC_PARAM_TABLE;
6157 8992 : 227 : n->defexpr = NULL;
361 8993 : 227 : n->location = @1;
6310 8994 : 227 : $$ = n;
8995 : : }
8996 : : ;
8997 : :
8998 : : table_func_column_list:
8999 : : table_func_column
9000 : : {
9001 : 97 : $$ = list_make1($1);
9002 : : }
9003 : : | table_func_column_list ',' table_func_column
9004 : : {
9005 : 130 : $$ = lappend($1, $3);
9006 : : }
9007 : : ;
9008 : :
9009 : : /*****************************************************************************
9010 : : * ALTER FUNCTION / ALTER PROCEDURE / ALTER ROUTINE
9011 : : *
9012 : : * RENAME and OWNER subcommands are already provided by the generic
9013 : : * ALTER infrastructure, here we just specify alterations that can
9014 : : * only be applied to functions.
9015 : : *
9016 : : *****************************************************************************/
9017 : : AlterFunctionStmt:
9018 : : ALTER FUNCTION function_with_argtypes alterfunc_opt_list opt_restrict
9019 : : {
7532 neilc@samurai.com 9020 : 686 : AlterFunctionStmt *n = makeNode(AlterFunctionStmt);
9021 : :
2888 peter_e@gmx.net 9022 : 686 : n->objtype = OBJECT_FUNCTION;
9023 : 686 : n->func = $3;
9024 : 686 : n->actions = $4;
9025 : 686 : $$ = (Node *) n;
9026 : : }
9027 : : | ALTER PROCEDURE function_with_argtypes alterfunc_opt_list opt_restrict
9028 : : {
9029 : 9 : AlterFunctionStmt *n = makeNode(AlterFunctionStmt);
9030 : :
9031 : 9 : n->objtype = OBJECT_PROCEDURE;
9032 : 9 : n->func = $3;
9033 : 9 : n->actions = $4;
9034 : 9 : $$ = (Node *) n;
9035 : : }
9036 : : | ALTER ROUTINE function_with_argtypes alterfunc_opt_list opt_restrict
9037 : : {
2888 peter_e@gmx.net 9038 :UBC 0 : AlterFunctionStmt *n = makeNode(AlterFunctionStmt);
9039 : :
9040 : 0 : n->objtype = OBJECT_ROUTINE;
7517 tgl@sss.pgh.pa.us 9041 : 0 : n->func = $3;
7532 neilc@samurai.com 9042 : 0 : n->actions = $4;
9043 : 0 : $$ = (Node *) n;
9044 : : }
9045 : : ;
9046 : :
9047 : : alterfunc_opt_list:
9048 : : /* At least one option must be specified */
7532 neilc@samurai.com 9049 :CBC 695 : common_func_opt_item { $$ = list_make1($1); }
9050 : 2 : | alterfunc_opt_list common_func_opt_item { $$ = lappend($1, $2); }
9051 : : ;
9052 : :
9053 : : /* Ignored, merely for SQL compliance */
9054 : : opt_restrict:
9055 : : RESTRICT
9056 : : | /* EMPTY */
9057 : : ;
9058 : :
9059 : :
9060 : : /*****************************************************************************
9061 : : *
9062 : : * QUERY:
9063 : : *
9064 : : * DROP FUNCTION funcname (arg1, arg2, ...) [ RESTRICT | CASCADE ]
9065 : : * DROP PROCEDURE procname (arg1, arg2, ...) [ RESTRICT | CASCADE ]
9066 : : * DROP ROUTINE routname (arg1, arg2, ...) [ RESTRICT | CASCADE ]
9067 : : * DROP AGGREGATE aggname (arg1, ...) [ RESTRICT | CASCADE ]
9068 : : * DROP OPERATOR opname (leftoperand_typ, rightoperand_typ) [ RESTRICT | CASCADE ]
9069 : : *
9070 : : *****************************************************************************/
9071 : :
9072 : : RemoveFuncStmt:
9073 : : DROP FUNCTION function_with_argtypes_list opt_drop_behavior
9074 : : {
5093 rhaas@postgresql.org 9075 : 1673 : DropStmt *n = makeNode(DropStmt);
9076 : :
9077 : 1673 : n->removeType = OBJECT_FUNCTION;
3225 peter_e@gmx.net 9078 : 1673 : n->objects = $3;
3329 9079 : 1673 : n->behavior = $4;
7073 andrew@dunslane.net 9080 : 1673 : n->missing_ok = false;
4952 simon@2ndQuadrant.co 9081 : 1673 : n->concurrent = false;
1263 peter@eisentraut.org 9082 : 1673 : $$ = (Node *) n;
9083 : : }
9084 : : | DROP FUNCTION IF_P EXISTS function_with_argtypes_list opt_drop_behavior
9085 : : {
5093 rhaas@postgresql.org 9086 : 130 : DropStmt *n = makeNode(DropStmt);
9087 : :
9088 : 130 : n->removeType = OBJECT_FUNCTION;
3225 peter_e@gmx.net 9089 : 130 : n->objects = $5;
3329 9090 : 130 : n->behavior = $6;
7073 andrew@dunslane.net 9091 : 130 : n->missing_ok = true;
4952 simon@2ndQuadrant.co 9092 : 130 : n->concurrent = false;
1263 peter@eisentraut.org 9093 : 130 : $$ = (Node *) n;
9094 : : }
9095 : : | DROP PROCEDURE function_with_argtypes_list opt_drop_behavior
9096 : : {
2888 peter_e@gmx.net 9097 : 70 : DropStmt *n = makeNode(DropStmt);
9098 : :
9099 : 70 : n->removeType = OBJECT_PROCEDURE;
9100 : 70 : n->objects = $3;
9101 : 70 : n->behavior = $4;
9102 : 70 : n->missing_ok = false;
9103 : 70 : n->concurrent = false;
1263 peter@eisentraut.org 9104 : 70 : $$ = (Node *) n;
9105 : : }
9106 : : | DROP PROCEDURE IF_P EXISTS function_with_argtypes_list opt_drop_behavior
9107 : : {
2888 peter_e@gmx.net 9108 : 3 : DropStmt *n = makeNode(DropStmt);
9109 : :
9110 : 3 : n->removeType = OBJECT_PROCEDURE;
9111 : 3 : n->objects = $5;
9112 : 3 : n->behavior = $6;
9113 : 3 : n->missing_ok = true;
9114 : 3 : n->concurrent = false;
1263 peter@eisentraut.org 9115 : 3 : $$ = (Node *) n;
9116 : : }
9117 : : | DROP ROUTINE function_with_argtypes_list opt_drop_behavior
9118 : : {
2888 peter_e@gmx.net 9119 : 6 : DropStmt *n = makeNode(DropStmt);
9120 : :
9121 : 6 : n->removeType = OBJECT_ROUTINE;
9122 : 6 : n->objects = $3;
9123 : 6 : n->behavior = $4;
9124 : 6 : n->missing_ok = false;
9125 : 6 : n->concurrent = false;
1263 peter@eisentraut.org 9126 : 6 : $$ = (Node *) n;
9127 : : }
9128 : : | DROP ROUTINE IF_P EXISTS function_with_argtypes_list opt_drop_behavior
9129 : : {
2888 peter_e@gmx.net 9130 : 3 : DropStmt *n = makeNode(DropStmt);
9131 : :
9132 : 3 : n->removeType = OBJECT_ROUTINE;
9133 : 3 : n->objects = $5;
9134 : 3 : n->behavior = $6;
9135 : 3 : n->missing_ok = true;
9136 : 3 : n->concurrent = false;
1263 peter@eisentraut.org 9137 : 3 : $$ = (Node *) n;
9138 : : }
9139 : : ;
9140 : :
9141 : : RemoveAggrStmt:
9142 : : DROP AGGREGATE aggregate_with_argtypes_list opt_drop_behavior
9143 : : {
5093 rhaas@postgresql.org 9144 : 37 : DropStmt *n = makeNode(DropStmt);
9145 : :
9146 : 37 : n->removeType = OBJECT_AGGREGATE;
3225 peter_e@gmx.net 9147 : 37 : n->objects = $3;
3329 9148 : 37 : n->behavior = $4;
7073 andrew@dunslane.net 9149 : 37 : n->missing_ok = false;
4952 simon@2ndQuadrant.co 9150 : 37 : n->concurrent = false;
1263 peter@eisentraut.org 9151 : 37 : $$ = (Node *) n;
9152 : : }
9153 : : | DROP AGGREGATE IF_P EXISTS aggregate_with_argtypes_list opt_drop_behavior
9154 : : {
5093 rhaas@postgresql.org 9155 : 15 : DropStmt *n = makeNode(DropStmt);
9156 : :
9157 : 15 : n->removeType = OBJECT_AGGREGATE;
3225 peter_e@gmx.net 9158 : 15 : n->objects = $5;
3329 9159 : 15 : n->behavior = $6;
7073 andrew@dunslane.net 9160 : 15 : n->missing_ok = true;
4952 simon@2ndQuadrant.co 9161 : 15 : n->concurrent = false;
1263 peter@eisentraut.org 9162 : 15 : $$ = (Node *) n;
9163 : : }
9164 : : ;
9165 : :
9166 : : RemoveOperStmt:
9167 : : DROP OPERATOR operator_with_argtypes_list opt_drop_behavior
9168 : : {
5093 rhaas@postgresql.org 9169 : 100 : DropStmt *n = makeNode(DropStmt);
9170 : :
9171 : 100 : n->removeType = OBJECT_OPERATOR;
3225 peter_e@gmx.net 9172 : 100 : n->objects = $3;
9173 : 100 : n->behavior = $4;
7073 andrew@dunslane.net 9174 : 100 : n->missing_ok = false;
4952 simon@2ndQuadrant.co 9175 : 100 : n->concurrent = false;
1263 peter@eisentraut.org 9176 : 100 : $$ = (Node *) n;
9177 : : }
9178 : : | DROP OPERATOR IF_P EXISTS operator_with_argtypes_list opt_drop_behavior
9179 : : {
5093 rhaas@postgresql.org 9180 : 15 : DropStmt *n = makeNode(DropStmt);
9181 : :
9182 : 15 : n->removeType = OBJECT_OPERATOR;
3225 peter_e@gmx.net 9183 : 15 : n->objects = $5;
9184 : 15 : n->behavior = $6;
7073 andrew@dunslane.net 9185 : 15 : n->missing_ok = true;
4952 simon@2ndQuadrant.co 9186 : 15 : n->concurrent = false;
1263 peter@eisentraut.org 9187 : 15 : $$ = (Node *) n;
9188 : : }
9189 : : ;
9190 : :
9191 : : oper_argtypes:
9192 : : '(' Typename ')'
9193 : : {
8136 tgl@sss.pgh.pa.us 9194 [ + - ]: 6 : ereport(ERROR,
9195 : : (errcode(ERRCODE_SYNTAX_ERROR),
9196 : : errmsg("missing argument"),
9197 : : errhint("Use NONE to denote the missing argument of a unary operator."),
9198 : : parser_errposition(@3)));
9199 : : }
9200 : : | '(' Typename ',' Typename ')'
6265 9201 : 1232 : { $$ = list_make2($2, $4); }
9202 : : | '(' NONE ',' Typename ')' /* left unary */
9203 : 16 : { $$ = list_make2(NULL, $4); }
9204 : : | '(' Typename ',' NONE ')' /* right unary */
9205 : 6 : { $$ = list_make2($2, NULL); }
9206 : : ;
9207 : :
9208 : : any_operator:
9209 : : all_Op
7820 neilc@samurai.com 9210 : 11299 : { $$ = list_make1(makeString($1)); }
9211 : : | ColId '.' any_operator
8532 bruce@momjian.us 9212 : 8174 : { $$ = lcons(makeString($1), $3); }
9213 : : ;
9214 : :
9215 : : operator_with_argtypes_list:
3225 peter_e@gmx.net 9216 : 115 : operator_with_argtypes { $$ = list_make1($1); }
9217 : : | operator_with_argtypes_list ',' operator_with_argtypes
3225 peter_e@gmx.net 9218 :UBC 0 : { $$ = lappend($1, $3); }
9219 : : ;
9220 : :
9221 : : operator_with_argtypes:
9222 : : any_operator oper_argtypes
9223 : : {
3225 peter_e@gmx.net 9224 :CBC 1254 : ObjectWithArgs *n = makeNode(ObjectWithArgs);
9225 : :
9226 : 1254 : n->objname = $1;
9227 : 1254 : n->objargs = $2;
9228 : 1254 : $$ = n;
9229 : : }
9230 : : ;
9231 : :
9232 : : /*****************************************************************************
9233 : : *
9234 : : * DO <anonymous code block> [ LANGUAGE language ]
9235 : : *
9236 : : * We use a DefElem list for future extensibility, and to allow flexibility
9237 : : * in the clause order.
9238 : : *
9239 : : *****************************************************************************/
9240 : :
9241 : : DoStmt: DO dostmt_opt_list
9242 : : {
5879 tgl@sss.pgh.pa.us 9243 : 572 : DoStmt *n = makeNode(DoStmt);
9244 : :
9245 : 572 : n->args = $2;
1263 peter@eisentraut.org 9246 : 572 : $$ = (Node *) n;
9247 : : }
9248 : : ;
9249 : :
9250 : : dostmt_opt_list:
5879 tgl@sss.pgh.pa.us 9251 : 572 : dostmt_opt_item { $$ = list_make1($1); }
9252 : 99 : | dostmt_opt_list dostmt_opt_item { $$ = lappend($1, $2); }
9253 : : ;
9254 : :
9255 : : dostmt_opt_item:
9256 : : Sconst
9257 : : {
1263 peter@eisentraut.org 9258 : 572 : $$ = makeDefElem("as", (Node *) makeString($1), @1);
9259 : : }
9260 : : | LANGUAGE NonReservedWord_or_Sconst
9261 : : {
9262 : 99 : $$ = makeDefElem("language", (Node *) makeString($2), @1);
9263 : : }
9264 : : ;
9265 : :
9266 : : /*****************************************************************************
9267 : : *
9268 : : * CREATE CAST / DROP CAST
9269 : : *
9270 : : *****************************************************************************/
9271 : :
9272 : : CreateCastStmt: CREATE CAST '(' Typename AS Typename ')'
9273 : : WITH FUNCTION function_with_argtypes cast_context
9274 : : {
8502 peter_e@gmx.net 9275 : 54 : CreateCastStmt *n = makeNode(CreateCastStmt);
9276 : :
9277 : 54 : n->sourcetype = $4;
9278 : 54 : n->targettype = $6;
7517 tgl@sss.pgh.pa.us 9279 : 54 : n->func = $10;
8440 9280 : 54 : n->context = (CoercionContext) $11;
6205 heikki.linnakangas@i 9281 : 54 : n->inout = false;
1263 peter@eisentraut.org 9282 : 54 : $$ = (Node *) n;
9283 : : }
9284 : : | CREATE CAST '(' Typename AS Typename ')'
9285 : : WITHOUT FUNCTION cast_context
9286 : : {
8502 peter_e@gmx.net 9287 : 81 : CreateCastStmt *n = makeNode(CreateCastStmt);
9288 : :
9289 : 81 : n->sourcetype = $4;
9290 : 81 : n->targettype = $6;
9291 : 81 : n->func = NULL;
8440 tgl@sss.pgh.pa.us 9292 : 81 : n->context = (CoercionContext) $10;
6205 heikki.linnakangas@i 9293 : 81 : n->inout = false;
1263 peter@eisentraut.org 9294 : 81 : $$ = (Node *) n;
9295 : : }
9296 : : | CREATE CAST '(' Typename AS Typename ')'
9297 : : WITH INOUT cast_context
9298 : : {
6205 heikki.linnakangas@i 9299 : 4 : CreateCastStmt *n = makeNode(CreateCastStmt);
9300 : :
9301 : 4 : n->sourcetype = $4;
9302 : 4 : n->targettype = $6;
9303 : 4 : n->func = NULL;
9304 : 4 : n->context = (CoercionContext) $10;
9305 : 4 : n->inout = true;
1263 peter@eisentraut.org 9306 : 4 : $$ = (Node *) n;
9307 : : }
9308 : : ;
9309 : :
8440 tgl@sss.pgh.pa.us 9310 : 18 : cast_context: AS IMPLICIT_P { $$ = COERCION_IMPLICIT; }
9311 : 29 : | AS ASSIGNMENT { $$ = COERCION_ASSIGNMENT; }
9312 : 92 : | /*EMPTY*/ { $$ = COERCION_EXPLICIT; }
9313 : : ;
9314 : :
9315 : :
9316 : : DropCastStmt: DROP CAST opt_if_exists '(' Typename AS Typename ')' opt_drop_behavior
9317 : : {
5093 rhaas@postgresql.org 9318 : 30 : DropStmt *n = makeNode(DropStmt);
9319 : :
9320 : 30 : n->removeType = OBJECT_CAST;
3271 peter_e@gmx.net 9321 : 30 : n->objects = list_make1(list_make2($5, $7));
7073 andrew@dunslane.net 9322 : 30 : n->behavior = $9;
tgl@sss.pgh.pa.us 9323 : 30 : n->missing_ok = $3;
4952 simon@2ndQuadrant.co 9324 : 30 : n->concurrent = false;
1263 peter@eisentraut.org 9325 : 30 : $$ = (Node *) n;
9326 : : }
9327 : : ;
9328 : :
2994 peter_e@gmx.net 9329 : 18 : opt_if_exists: IF_P EXISTS { $$ = true; }
9330 : 19 : | /*EMPTY*/ { $$ = false; }
9331 : : ;
9332 : :
9333 : :
9334 : : /*****************************************************************************
9335 : : *
9336 : : * CREATE TRANSFORM / DROP TRANSFORM
9337 : : *
9338 : : *****************************************************************************/
9339 : :
9340 : : CreateTransformStmt: CREATE opt_or_replace TRANSFORM FOR Typename LANGUAGE name '(' transform_element_list ')'
9341 : : {
3837 9342 : 25 : CreateTransformStmt *n = makeNode(CreateTransformStmt);
9343 : :
9344 : 25 : n->replace = $2;
9345 : 25 : n->type_name = $5;
9346 : 25 : n->lang = $7;
9347 : 25 : n->fromsql = linitial($9);
9348 : 25 : n->tosql = lsecond($9);
1263 peter@eisentraut.org 9349 : 25 : $$ = (Node *) n;
9350 : : }
9351 : : ;
9352 : :
9353 : : transform_element_list: FROM SQL_P WITH FUNCTION function_with_argtypes ',' TO SQL_P WITH FUNCTION function_with_argtypes
9354 : : {
3837 peter_e@gmx.net 9355 : 22 : $$ = list_make2($5, $11);
9356 : : }
9357 : : | TO SQL_P WITH FUNCTION function_with_argtypes ',' FROM SQL_P WITH FUNCTION function_with_argtypes
9358 : : {
3837 peter_e@gmx.net 9359 :UBC 0 : $$ = list_make2($11, $5);
9360 : : }
9361 : : | FROM SQL_P WITH FUNCTION function_with_argtypes
9362 : : {
3837 peter_e@gmx.net 9363 :CBC 2 : $$ = list_make2($5, NULL);
9364 : : }
9365 : : | TO SQL_P WITH FUNCTION function_with_argtypes
9366 : : {
9367 : 1 : $$ = list_make2(NULL, $5);
9368 : : }
9369 : : ;
9370 : :
9371 : :
9372 : : DropTransformStmt: DROP TRANSFORM opt_if_exists FOR Typename LANGUAGE name opt_drop_behavior
9373 : : {
9374 : 7 : DropStmt *n = makeNode(DropStmt);
9375 : :
9376 : 7 : n->removeType = OBJECT_TRANSFORM;
3271 9377 : 7 : n->objects = list_make1(list_make2($5, makeString($7)));
3837 9378 : 7 : n->behavior = $8;
9379 : 7 : n->missing_ok = $3;
1263 peter@eisentraut.org 9380 : 7 : $$ = (Node *) n;
9381 : : }
9382 : : ;
9383 : :
9384 : :
9385 : : /*****************************************************************************
9386 : : *
9387 : : * QUERY:
9388 : : *
9389 : : * REINDEX [ (options) ] {INDEX | TABLE | SCHEMA} [CONCURRENTLY] <name>
9390 : : * REINDEX [ (options) ] {DATABASE | SYSTEM} [CONCURRENTLY] [<name>]
9391 : : *****************************************************************************/
9392 : :
9393 : : ReindexStmt:
9394 : : REINDEX opt_utility_option_list reindex_target_relation opt_concurrently qualified_name
9395 : : {
9383 inoue@tpf.co.jp 9396 : 451 : ReindexStmt *n = makeNode(ReindexStmt);
9397 : :
1193 alvherre@alvh.no-ip. 9398 : 451 : n->kind = $3;
9399 : 451 : n->relation = $5;
8621 tgl@sss.pgh.pa.us 9400 : 451 : n->name = NULL;
1193 alvherre@alvh.no-ip. 9401 : 451 : n->params = $2;
9402 [ + + ]: 451 : if ($4)
1789 michael@paquier.xyz 9403 : 256 : n->params = lappend(n->params,
1193 alvherre@alvh.no-ip. 9404 : 256 : makeDefElem("concurrently", NULL, @4));
1263 peter@eisentraut.org 9405 : 451 : $$ = (Node *) n;
9406 : : }
9407 : : | REINDEX opt_utility_option_list SCHEMA opt_concurrently name
9408 : : {
3975 simon@2ndQuadrant.co 9409 : 58 : ReindexStmt *n = makeNode(ReindexStmt);
9410 : :
1193 alvherre@alvh.no-ip. 9411 : 58 : n->kind = REINDEX_OBJECT_SCHEMA;
3975 simon@2ndQuadrant.co 9412 : 58 : n->relation = NULL;
1189 michael@paquier.xyz 9413 : 58 : n->name = $5;
1193 alvherre@alvh.no-ip. 9414 : 58 : n->params = $2;
9415 [ + + ]: 58 : if ($4)
1789 michael@paquier.xyz 9416 : 20 : n->params = lappend(n->params,
1193 alvherre@alvh.no-ip. 9417 : 20 : makeDefElem("concurrently", NULL, @4));
1263 peter@eisentraut.org 9418 : 58 : $$ = (Node *) n;
9419 : : }
9420 : : | REINDEX opt_utility_option_list reindex_target_all opt_concurrently opt_single_name
9421 : : {
8621 tgl@sss.pgh.pa.us 9422 : 34 : ReindexStmt *n = makeNode(ReindexStmt);
9423 : :
1189 michael@paquier.xyz 9424 : 34 : n->kind = $3;
8621 tgl@sss.pgh.pa.us 9425 : 34 : n->relation = NULL;
1189 michael@paquier.xyz 9426 : 34 : n->name = $5;
1193 alvherre@alvh.no-ip. 9427 : 34 : n->params = $2;
1189 michael@paquier.xyz 9428 [ + + ]: 34 : if ($4)
9429 : 5 : n->params = lappend(n->params,
9430 : 5 : makeDefElem("concurrently", NULL, @4));
1263 peter@eisentraut.org 9431 : 34 : $$ = (Node *) n;
9432 : : }
9433 : : ;
9434 : : reindex_target_relation:
3818 fujii@postgresql.org 9435 : 194 : INDEX { $$ = REINDEX_OBJECT_INDEX; }
9436 : 257 : | TABLE { $$ = REINDEX_OBJECT_TABLE; }
9437 : : ;
9438 : : reindex_target_all:
1189 michael@paquier.xyz 9439 : 17 : SYSTEM_P { $$ = REINDEX_OBJECT_SYSTEM; }
9440 : 17 : | DATABASE { $$ = REINDEX_OBJECT_DATABASE; }
9441 : : ;
9442 : :
9443 : : /*****************************************************************************
9444 : : *
9445 : : * ALTER TABLESPACE
9446 : : *
9447 : : *****************************************************************************/
9448 : :
9449 : : AlterTblSpcStmt:
9450 : : ALTER TABLESPACE name SET reloptions
9451 : : {
9452 : : AlterTableSpaceOptionsStmt *n =
4215 sfrost@snowman.net 9453 : 6 : makeNode(AlterTableSpaceOptionsStmt);
9454 : :
9455 : 6 : n->tablespacename = $3;
9456 : 6 : n->options = $5;
2994 peter_e@gmx.net 9457 : 6 : n->isReset = false;
1263 peter@eisentraut.org 9458 : 6 : $$ = (Node *) n;
9459 : : }
9460 : : | ALTER TABLESPACE name RESET reloptions
9461 : : {
9462 : : AlterTableSpaceOptionsStmt *n =
4215 sfrost@snowman.net 9463 : 6 : makeNode(AlterTableSpaceOptionsStmt);
9464 : :
9465 : 6 : n->tablespacename = $3;
9466 : 6 : n->options = $5;
2994 peter_e@gmx.net 9467 : 6 : n->isReset = true;
1263 peter@eisentraut.org 9468 : 6 : $$ = (Node *) n;
9469 : : }
9470 : : ;
9471 : :
9472 : : /*****************************************************************************
9473 : : *
9474 : : * ALTER THING name RENAME TO newname
9475 : : *
9476 : : *****************************************************************************/
9477 : :
9478 : : RenameStmt: ALTER AGGREGATE aggregate_with_argtypes RENAME TO name
9479 : : {
8158 peter_e@gmx.net 9480 : 21 : RenameStmt *n = makeNode(RenameStmt);
9481 : :
9482 : 21 : n->renameType = OBJECT_AGGREGATE;
3271 9483 : 21 : n->object = (Node *) $3;
3329 9484 : 21 : n->newname = $6;
5026 simon@2ndQuadrant.co 9485 : 21 : n->missing_ok = false;
1263 peter@eisentraut.org 9486 : 21 : $$ = (Node *) n;
9487 : : }
9488 : : | ALTER COLLATION any_name RENAME TO name
9489 : : {
5371 peter_e@gmx.net 9490 : 9 : RenameStmt *n = makeNode(RenameStmt);
9491 : :
9492 : 9 : n->renameType = OBJECT_COLLATION;
3271 9493 : 9 : n->object = (Node *) $3;
5371 9494 : 9 : n->newname = $6;
5026 simon@2ndQuadrant.co 9495 : 9 : n->missing_ok = false;
1263 peter@eisentraut.org 9496 : 9 : $$ = (Node *) n;
9497 : : }
9498 : : | ALTER CONVERSION_P any_name RENAME TO name
9499 : : {
8158 peter_e@gmx.net 9500 : 12 : RenameStmt *n = makeNode(RenameStmt);
9501 : :
9502 : 12 : n->renameType = OBJECT_CONVERSION;
3271 9503 : 12 : n->object = (Node *) $3;
8158 9504 : 12 : n->newname = $6;
5026 simon@2ndQuadrant.co 9505 : 12 : n->missing_ok = false;
1263 peter@eisentraut.org 9506 : 12 : $$ = (Node *) n;
9507 : : }
9508 : : | ALTER DATABASE name RENAME TO name
9509 : : {
8158 peter_e@gmx.net 9510 : 6 : RenameStmt *n = makeNode(RenameStmt);
9511 : :
9512 : 6 : n->renameType = OBJECT_DATABASE;
9513 : 6 : n->subname = $3;
9514 : 6 : n->newname = $6;
5026 simon@2ndQuadrant.co 9515 : 6 : n->missing_ok = false;
1263 peter@eisentraut.org 9516 : 6 : $$ = (Node *) n;
9517 : : }
9518 : : | ALTER DOMAIN_P any_name RENAME TO name
9519 : : {
5058 peter_e@gmx.net 9520 : 3 : RenameStmt *n = makeNode(RenameStmt);
9521 : :
9522 : 3 : n->renameType = OBJECT_DOMAIN;
3271 9523 : 3 : n->object = (Node *) $3;
5058 9524 : 3 : n->newname = $6;
5026 simon@2ndQuadrant.co 9525 : 3 : n->missing_ok = false;
1263 peter@eisentraut.org 9526 : 3 : $$ = (Node *) n;
9527 : : }
9528 : : | ALTER DOMAIN_P any_name RENAME CONSTRAINT name TO name
9529 : : {
4955 peter_e@gmx.net 9530 : 3 : RenameStmt *n = makeNode(RenameStmt);
9531 : :
3961 alvherre@alvh.no-ip. 9532 : 3 : n->renameType = OBJECT_DOMCONSTRAINT;
3271 peter_e@gmx.net 9533 : 3 : n->object = (Node *) $3;
4955 9534 : 3 : n->subname = $6;
9535 : 3 : n->newname = $8;
1263 peter@eisentraut.org 9536 : 3 : $$ = (Node *) n;
9537 : : }
9538 : : | ALTER FOREIGN DATA_P WRAPPER name RENAME TO name
9539 : : {
5071 peter_e@gmx.net 9540 : 12 : RenameStmt *n = makeNode(RenameStmt);
9541 : :
9542 : 12 : n->renameType = OBJECT_FDW;
3271 9543 : 12 : n->object = (Node *) makeString($5);
5071 9544 : 12 : n->newname = $8;
5026 simon@2ndQuadrant.co 9545 : 12 : n->missing_ok = false;
1263 peter@eisentraut.org 9546 : 12 : $$ = (Node *) n;
9547 : : }
9548 : : | ALTER FUNCTION function_with_argtypes RENAME TO name
9549 : : {
8158 peter_e@gmx.net 9550 : 12 : RenameStmt *n = makeNode(RenameStmt);
9551 : :
9552 : 12 : n->renameType = OBJECT_FUNCTION;
3271 9553 : 12 : n->object = (Node *) $3;
6629 tgl@sss.pgh.pa.us 9554 : 12 : n->newname = $6;
5026 simon@2ndQuadrant.co 9555 : 12 : n->missing_ok = false;
1263 peter@eisentraut.org 9556 : 12 : $$ = (Node *) n;
9557 : : }
9558 : : | ALTER GROUP_P RoleId RENAME TO RoleId
9559 : : {
8158 peter_e@gmx.net 9560 :UBC 0 : RenameStmt *n = makeNode(RenameStmt);
9561 : :
7426 tgl@sss.pgh.pa.us 9562 : 0 : n->renameType = OBJECT_ROLE;
8158 peter_e@gmx.net 9563 : 0 : n->subname = $3;
9564 : 0 : n->newname = $6;
5026 simon@2ndQuadrant.co 9565 : 0 : n->missing_ok = false;
1263 peter@eisentraut.org 9566 : 0 : $$ = (Node *) n;
9567 : : }
9568 : : | ALTER opt_procedural LANGUAGE name RENAME TO name
9569 : : {
8158 peter_e@gmx.net 9570 :CBC 9 : RenameStmt *n = makeNode(RenameStmt);
9571 : :
9572 : 9 : n->renameType = OBJECT_LANGUAGE;
3271 9573 : 9 : n->object = (Node *) makeString($4);
6790 tgl@sss.pgh.pa.us 9574 : 9 : n->newname = $7;
5026 simon@2ndQuadrant.co 9575 : 9 : n->missing_ok = false;
1263 peter@eisentraut.org 9576 : 9 : $$ = (Node *) n;
9577 : : }
9578 : : | ALTER OPERATOR CLASS any_name USING name RENAME TO name
9579 : : {
8158 peter_e@gmx.net 9580 : 12 : RenameStmt *n = makeNode(RenameStmt);
9581 : :
9582 : 12 : n->renameType = OBJECT_OPCLASS;
3271 9583 : 12 : n->object = (Node *) lcons(makeString($6), $4);
8158 9584 : 12 : n->newname = $9;
5026 simon@2ndQuadrant.co 9585 : 12 : n->missing_ok = false;
1263 peter@eisentraut.org 9586 : 12 : $$ = (Node *) n;
9587 : : }
9588 : : | ALTER OPERATOR FAMILY any_name USING name RENAME TO name
9589 : : {
6852 tgl@sss.pgh.pa.us 9590 : 12 : RenameStmt *n = makeNode(RenameStmt);
9591 : :
9592 : 12 : n->renameType = OBJECT_OPFAMILY;
3271 peter_e@gmx.net 9593 : 12 : n->object = (Node *) lcons(makeString($6), $4);
6852 tgl@sss.pgh.pa.us 9594 : 12 : n->newname = $9;
5026 simon@2ndQuadrant.co 9595 : 12 : n->missing_ok = false;
1263 peter@eisentraut.org 9596 : 12 : $$ = (Node *) n;
9597 : : }
9598 : : | ALTER POLICY name ON qualified_name RENAME TO name
9599 : : {
4056 sfrost@snowman.net 9600 : 9 : RenameStmt *n = makeNode(RenameStmt);
9601 : :
9602 : 9 : n->renameType = OBJECT_POLICY;
9603 : 9 : n->relation = $5;
9604 : 9 : n->subname = $3;
9605 : 9 : n->newname = $8;
9606 : 9 : n->missing_ok = false;
1263 peter@eisentraut.org 9607 : 9 : $$ = (Node *) n;
9608 : : }
9609 : : | ALTER POLICY IF_P EXISTS name ON qualified_name RENAME TO name
9610 : : {
4056 sfrost@snowman.net 9611 :UBC 0 : RenameStmt *n = makeNode(RenameStmt);
9612 : :
9613 : 0 : n->renameType = OBJECT_POLICY;
9614 : 0 : n->relation = $7;
9615 : 0 : n->subname = $5;
9616 : 0 : n->newname = $10;
9617 : 0 : n->missing_ok = true;
1263 peter@eisentraut.org 9618 : 0 : $$ = (Node *) n;
9619 : : }
9620 : : | ALTER PROCEDURE function_with_argtypes RENAME TO name
9621 : : {
2888 peter_e@gmx.net 9622 : 0 : RenameStmt *n = makeNode(RenameStmt);
9623 : :
9624 : 0 : n->renameType = OBJECT_PROCEDURE;
9625 : 0 : n->object = (Node *) $3;
9626 : 0 : n->newname = $6;
9627 : 0 : n->missing_ok = false;
1263 peter@eisentraut.org 9628 : 0 : $$ = (Node *) n;
9629 : : }
9630 : : | ALTER PUBLICATION name RENAME TO name
9631 : : {
3160 peter_e@gmx.net 9632 :CBC 21 : RenameStmt *n = makeNode(RenameStmt);
9633 : :
9634 : 21 : n->renameType = OBJECT_PUBLICATION;
3271 9635 : 21 : n->object = (Node *) makeString($3);
3160 9636 : 21 : n->newname = $6;
9637 : 21 : n->missing_ok = false;
1263 peter@eisentraut.org 9638 : 21 : $$ = (Node *) n;
9639 : : }
9640 : : | ALTER ROUTINE function_with_argtypes RENAME TO name
9641 : : {
2888 peter_e@gmx.net 9642 : 12 : RenameStmt *n = makeNode(RenameStmt);
9643 : :
9644 : 12 : n->renameType = OBJECT_ROUTINE;
9645 : 12 : n->object = (Node *) $3;
9646 : 12 : n->newname = $6;
9647 : 12 : n->missing_ok = false;
1263 peter@eisentraut.org 9648 : 12 : $$ = (Node *) n;
9649 : : }
9650 : : | ALTER SCHEMA name RENAME TO name
9651 : : {
8158 peter_e@gmx.net 9652 : 10 : RenameStmt *n = makeNode(RenameStmt);
9653 : :
9654 : 10 : n->renameType = OBJECT_SCHEMA;
9655 : 10 : n->subname = $3;
9656 : 10 : n->newname = $6;
5026 simon@2ndQuadrant.co 9657 : 10 : n->missing_ok = false;
1263 peter@eisentraut.org 9658 : 10 : $$ = (Node *) n;
9659 : : }
9660 : : | ALTER SERVER name RENAME TO name
9661 : : {
5071 peter_e@gmx.net 9662 : 12 : RenameStmt *n = makeNode(RenameStmt);
9663 : :
9664 : 12 : n->renameType = OBJECT_FOREIGN_SERVER;
3271 9665 : 12 : n->object = (Node *) makeString($3);
5071 9666 : 12 : n->newname = $6;
5026 simon@2ndQuadrant.co 9667 : 12 : n->missing_ok = false;
1263 peter@eisentraut.org 9668 : 12 : $$ = (Node *) n;
9669 : : }
9670 : : | ALTER SUBSCRIPTION name RENAME TO name
9671 : : {
3160 peter_e@gmx.net 9672 : 19 : RenameStmt *n = makeNode(RenameStmt);
9673 : :
9674 : 19 : n->renameType = OBJECT_SUBSCRIPTION;
3271 9675 : 19 : n->object = (Node *) makeString($3);
3160 9676 : 19 : n->newname = $6;
9677 : 19 : n->missing_ok = false;
1263 peter@eisentraut.org 9678 : 19 : $$ = (Node *) n;
9679 : : }
9680 : : | ALTER TABLE relation_expr RENAME TO name
9681 : : {
10276 bruce@momjian.us 9682 : 144 : RenameStmt *n = makeNode(RenameStmt);
9683 : :
7845 tgl@sss.pgh.pa.us 9684 : 144 : n->renameType = OBJECT_TABLE;
9685 : 144 : n->relation = $3;
9686 : 144 : n->subname = NULL;
9687 : 144 : n->newname = $6;
5026 simon@2ndQuadrant.co 9688 : 144 : n->missing_ok = false;
1263 peter@eisentraut.org 9689 : 144 : $$ = (Node *) n;
9690 : : }
9691 : : | ALTER TABLE IF_P EXISTS relation_expr RENAME TO name
9692 : : {
5026 simon@2ndQuadrant.co 9693 :UBC 0 : RenameStmt *n = makeNode(RenameStmt);
9694 : :
9695 : 0 : n->renameType = OBJECT_TABLE;
9696 : 0 : n->relation = $5;
9697 : 0 : n->subname = NULL;
9698 : 0 : n->newname = $8;
9699 : 0 : n->missing_ok = true;
1263 peter@eisentraut.org 9700 : 0 : $$ = (Node *) n;
9701 : : }
9702 : : | ALTER SEQUENCE qualified_name RENAME TO name
9703 : : {
6691 neilc@samurai.com 9704 :CBC 1 : RenameStmt *n = makeNode(RenameStmt);
9705 : :
9706 : 1 : n->renameType = OBJECT_SEQUENCE;
9707 : 1 : n->relation = $3;
9708 : 1 : n->subname = NULL;
9709 : 1 : n->newname = $6;
5026 simon@2ndQuadrant.co 9710 : 1 : n->missing_ok = false;
1263 peter@eisentraut.org 9711 : 1 : $$ = (Node *) n;
9712 : : }
9713 : : | ALTER SEQUENCE IF_P EXISTS qualified_name RENAME TO name
9714 : : {
5026 simon@2ndQuadrant.co 9715 :UBC 0 : RenameStmt *n = makeNode(RenameStmt);
9716 : :
9717 : 0 : n->renameType = OBJECT_SEQUENCE;
9718 : 0 : n->relation = $5;
9719 : 0 : n->subname = NULL;
9720 : 0 : n->newname = $8;
9721 : 0 : n->missing_ok = true;
1263 peter@eisentraut.org 9722 : 0 : $$ = (Node *) n;
9723 : : }
9724 : : | ALTER VIEW qualified_name RENAME TO name
9725 : : {
6691 neilc@samurai.com 9726 :CBC 3 : RenameStmt *n = makeNode(RenameStmt);
9727 : :
9728 : 3 : n->renameType = OBJECT_VIEW;
9729 : 3 : n->relation = $3;
9730 : 3 : n->subname = NULL;
9731 : 3 : n->newname = $6;
5026 simon@2ndQuadrant.co 9732 : 3 : n->missing_ok = false;
1263 peter@eisentraut.org 9733 : 3 : $$ = (Node *) n;
9734 : : }
9735 : : | ALTER VIEW IF_P EXISTS qualified_name RENAME TO name
9736 : : {
5026 simon@2ndQuadrant.co 9737 :UBC 0 : RenameStmt *n = makeNode(RenameStmt);
9738 : :
9739 : 0 : n->renameType = OBJECT_VIEW;
9740 : 0 : n->relation = $5;
9741 : 0 : n->subname = NULL;
9742 : 0 : n->newname = $8;
9743 : 0 : n->missing_ok = true;
1263 peter@eisentraut.org 9744 : 0 : $$ = (Node *) n;
9745 : : }
9746 : : | ALTER MATERIALIZED VIEW qualified_name RENAME TO name
9747 : : {
4621 kgrittn@postgresql.o 9748 : 0 : RenameStmt *n = makeNode(RenameStmt);
9749 : :
9750 : 0 : n->renameType = OBJECT_MATVIEW;
9751 : 0 : n->relation = $4;
9752 : 0 : n->subname = NULL;
9753 : 0 : n->newname = $7;
9754 : 0 : n->missing_ok = false;
1263 peter@eisentraut.org 9755 : 0 : $$ = (Node *) n;
9756 : : }
9757 : : | ALTER MATERIALIZED VIEW IF_P EXISTS qualified_name RENAME TO name
9758 : : {
4621 kgrittn@postgresql.o 9759 : 0 : RenameStmt *n = makeNode(RenameStmt);
9760 : :
9761 : 0 : n->renameType = OBJECT_MATVIEW;
9762 : 0 : n->relation = $6;
9763 : 0 : n->subname = NULL;
9764 : 0 : n->newname = $9;
9765 : 0 : n->missing_ok = true;
1263 peter@eisentraut.org 9766 : 0 : $$ = (Node *) n;
9767 : : }
9768 : : | ALTER INDEX qualified_name RENAME TO name
9769 : : {
7738 bruce@momjian.us 9770 :CBC 96 : RenameStmt *n = makeNode(RenameStmt);
9771 : :
9772 : 96 : n->renameType = OBJECT_INDEX;
9773 : 96 : n->relation = $3;
9774 : 96 : n->subname = NULL;
9775 : 96 : n->newname = $6;
5026 simon@2ndQuadrant.co 9776 : 96 : n->missing_ok = false;
1263 peter@eisentraut.org 9777 : 96 : $$ = (Node *) n;
9778 : : }
9779 : : | ALTER INDEX IF_P EXISTS qualified_name RENAME TO name
9780 : : {
5026 simon@2ndQuadrant.co 9781 : 6 : RenameStmt *n = makeNode(RenameStmt);
9782 : :
9783 : 6 : n->renameType = OBJECT_INDEX;
9784 : 6 : n->relation = $5;
9785 : 6 : n->subname = NULL;
9786 : 6 : n->newname = $8;
9787 : 6 : n->missing_ok = true;
1263 peter@eisentraut.org 9788 : 6 : $$ = (Node *) n;
9789 : : }
9790 : : | ALTER FOREIGN TABLE relation_expr RENAME TO name
9791 : : {
5413 rhaas@postgresql.org 9792 : 3 : RenameStmt *n = makeNode(RenameStmt);
9793 : :
9794 : 3 : n->renameType = OBJECT_FOREIGN_TABLE;
9795 : 3 : n->relation = $4;
9796 : 3 : n->subname = NULL;
9797 : 3 : n->newname = $7;
5026 simon@2ndQuadrant.co 9798 : 3 : n->missing_ok = false;
1263 peter@eisentraut.org 9799 : 3 : $$ = (Node *) n;
9800 : : }
9801 : : | ALTER FOREIGN TABLE IF_P EXISTS relation_expr RENAME TO name
9802 : : {
5026 simon@2ndQuadrant.co 9803 : 3 : RenameStmt *n = makeNode(RenameStmt);
9804 : :
9805 : 3 : n->renameType = OBJECT_FOREIGN_TABLE;
9806 : 3 : n->relation = $6;
9807 : 3 : n->subname = NULL;
9808 : 3 : n->newname = $9;
9809 : 3 : n->missing_ok = true;
1263 peter@eisentraut.org 9810 : 3 : $$ = (Node *) n;
9811 : : }
9812 : : | ALTER TABLE relation_expr RENAME opt_column name TO name
9813 : : {
7845 tgl@sss.pgh.pa.us 9814 : 119 : RenameStmt *n = makeNode(RenameStmt);
9815 : :
9816 : 119 : n->renameType = OBJECT_COLUMN;
5413 rhaas@postgresql.org 9817 : 119 : n->relationType = OBJECT_TABLE;
8621 tgl@sss.pgh.pa.us 9818 : 119 : n->relation = $3;
8158 peter_e@gmx.net 9819 : 119 : n->subname = $6;
8939 tgl@sss.pgh.pa.us 9820 : 119 : n->newname = $8;
5026 simon@2ndQuadrant.co 9821 : 119 : n->missing_ok = false;
1263 peter@eisentraut.org 9822 : 119 : $$ = (Node *) n;
9823 : : }
9824 : : | ALTER TABLE IF_P EXISTS relation_expr RENAME opt_column name TO name
9825 : : {
5026 simon@2ndQuadrant.co 9826 : 12 : RenameStmt *n = makeNode(RenameStmt);
9827 : :
9828 : 12 : n->renameType = OBJECT_COLUMN;
9829 : 12 : n->relationType = OBJECT_TABLE;
9830 : 12 : n->relation = $5;
9831 : 12 : n->subname = $8;
9832 : 12 : n->newname = $10;
9833 : 12 : n->missing_ok = true;
1263 peter@eisentraut.org 9834 : 12 : $$ = (Node *) n;
9835 : : }
9836 : : | ALTER VIEW qualified_name RENAME opt_column name TO name
9837 : : {
2167 fujii@postgresql.org 9838 : 9 : RenameStmt *n = makeNode(RenameStmt);
9839 : :
9840 : 9 : n->renameType = OBJECT_COLUMN;
9841 : 9 : n->relationType = OBJECT_VIEW;
9842 : 9 : n->relation = $3;
9843 : 9 : n->subname = $6;
9844 : 9 : n->newname = $8;
9845 : 9 : n->missing_ok = false;
1263 peter@eisentraut.org 9846 : 9 : $$ = (Node *) n;
9847 : : }
9848 : : | ALTER VIEW IF_P EXISTS qualified_name RENAME opt_column name TO name
9849 : : {
2167 fujii@postgresql.org 9850 :UBC 0 : RenameStmt *n = makeNode(RenameStmt);
9851 : :
9852 : 0 : n->renameType = OBJECT_COLUMN;
9853 : 0 : n->relationType = OBJECT_VIEW;
9854 : 0 : n->relation = $5;
9855 : 0 : n->subname = $8;
9856 : 0 : n->newname = $10;
9857 : 0 : n->missing_ok = true;
1263 peter@eisentraut.org 9858 : 0 : $$ = (Node *) n;
9859 : : }
9860 : : | ALTER MATERIALIZED VIEW qualified_name RENAME opt_column name TO name
9861 : : {
4621 kgrittn@postgresql.o 9862 : 0 : RenameStmt *n = makeNode(RenameStmt);
9863 : :
9864 : 0 : n->renameType = OBJECT_COLUMN;
9865 : 0 : n->relationType = OBJECT_MATVIEW;
9866 : 0 : n->relation = $4;
9867 : 0 : n->subname = $7;
9868 : 0 : n->newname = $9;
9869 : 0 : n->missing_ok = false;
1263 peter@eisentraut.org 9870 : 0 : $$ = (Node *) n;
9871 : : }
9872 : : | ALTER MATERIALIZED VIEW IF_P EXISTS qualified_name RENAME opt_column name TO name
9873 : : {
4621 kgrittn@postgresql.o 9874 : 0 : RenameStmt *n = makeNode(RenameStmt);
9875 : :
9876 : 0 : n->renameType = OBJECT_COLUMN;
9877 : 0 : n->relationType = OBJECT_MATVIEW;
9878 : 0 : n->relation = $6;
9879 : 0 : n->subname = $9;
9880 : 0 : n->newname = $11;
9881 : 0 : n->missing_ok = true;
1263 peter@eisentraut.org 9882 : 0 : $$ = (Node *) n;
9883 : : }
9884 : : | ALTER TABLE relation_expr RENAME CONSTRAINT name TO name
9885 : : {
4979 peter_e@gmx.net 9886 :CBC 36 : RenameStmt *n = makeNode(RenameStmt);
9887 : :
3961 alvherre@alvh.no-ip. 9888 : 36 : n->renameType = OBJECT_TABCONSTRAINT;
4979 peter_e@gmx.net 9889 : 36 : n->relation = $3;
9890 : 36 : n->subname = $6;
9891 : 36 : n->newname = $8;
3870 bruce@momjian.us 9892 : 36 : n->missing_ok = false;
1263 peter@eisentraut.org 9893 : 36 : $$ = (Node *) n;
9894 : : }
9895 : : | ALTER TABLE IF_P EXISTS relation_expr RENAME CONSTRAINT name TO name
9896 : : {
3870 bruce@momjian.us 9897 : 3 : RenameStmt *n = makeNode(RenameStmt);
9898 : :
9899 : 3 : n->renameType = OBJECT_TABCONSTRAINT;
9900 : 3 : n->relation = $5;
9901 : 3 : n->subname = $8;
9902 : 3 : n->newname = $10;
9903 : 3 : n->missing_ok = true;
1263 peter@eisentraut.org 9904 : 3 : $$ = (Node *) n;
9905 : : }
9906 : : | ALTER FOREIGN TABLE relation_expr RENAME opt_column name TO name
9907 : : {
5413 rhaas@postgresql.org 9908 : 3 : RenameStmt *n = makeNode(RenameStmt);
9909 : :
9910 : 3 : n->renameType = OBJECT_COLUMN;
9911 : 3 : n->relationType = OBJECT_FOREIGN_TABLE;
9912 : 3 : n->relation = $4;
9913 : 3 : n->subname = $7;
9914 : 3 : n->newname = $9;
5026 simon@2ndQuadrant.co 9915 : 3 : n->missing_ok = false;
1263 peter@eisentraut.org 9916 : 3 : $$ = (Node *) n;
9917 : : }
9918 : : | ALTER FOREIGN TABLE IF_P EXISTS relation_expr RENAME opt_column name TO name
9919 : : {
5026 simon@2ndQuadrant.co 9920 : 3 : RenameStmt *n = makeNode(RenameStmt);
9921 : :
9922 : 3 : n->renameType = OBJECT_COLUMN;
9923 : 3 : n->relationType = OBJECT_FOREIGN_TABLE;
9924 : 3 : n->relation = $6;
9925 : 3 : n->subname = $9;
9926 : 3 : n->newname = $11;
9927 : 3 : n->missing_ok = true;
1263 peter@eisentraut.org 9928 : 3 : $$ = (Node *) n;
9929 : : }
9930 : : | ALTER RULE name ON qualified_name RENAME TO name
9931 : : {
4644 tgl@sss.pgh.pa.us 9932 : 17 : RenameStmt *n = makeNode(RenameStmt);
9933 : :
9934 : 17 : n->renameType = OBJECT_RULE;
9935 : 17 : n->relation = $5;
9936 : 17 : n->subname = $3;
9937 : 17 : n->newname = $8;
9938 : 17 : n->missing_ok = false;
1263 peter@eisentraut.org 9939 : 17 : $$ = (Node *) n;
9940 : : }
9941 : : | ALTER TRIGGER name ON qualified_name RENAME TO name
9942 : : {
8587 bruce@momjian.us 9943 : 20 : RenameStmt *n = makeNode(RenameStmt);
9944 : :
7392 tgl@sss.pgh.pa.us 9945 : 20 : n->renameType = OBJECT_TRIGGER;
8587 bruce@momjian.us 9946 : 20 : n->relation = $5;
8158 peter_e@gmx.net 9947 : 20 : n->subname = $3;
8587 bruce@momjian.us 9948 : 20 : n->newname = $8;
5026 simon@2ndQuadrant.co 9949 : 20 : n->missing_ok = false;
1263 peter@eisentraut.org 9950 : 20 : $$ = (Node *) n;
9951 : : }
9952 : : | ALTER EVENT TRIGGER name RENAME TO name
9953 : : {
4849 rhaas@postgresql.org 9954 : 6 : RenameStmt *n = makeNode(RenameStmt);
9955 : :
9956 : 6 : n->renameType = OBJECT_EVENT_TRIGGER;
3271 peter_e@gmx.net 9957 : 6 : n->object = (Node *) makeString($4);
4849 rhaas@postgresql.org 9958 : 6 : n->newname = $7;
1263 peter@eisentraut.org 9959 : 6 : $$ = (Node *) n;
9960 : : }
9961 : : | ALTER ROLE RoleId RENAME TO RoleId
9962 : : {
8158 peter_e@gmx.net 9963 : 16 : RenameStmt *n = makeNode(RenameStmt);
9964 : :
7426 tgl@sss.pgh.pa.us 9965 : 16 : n->renameType = OBJECT_ROLE;
9966 : 16 : n->subname = $3;
9967 : 16 : n->newname = $6;
5026 simon@2ndQuadrant.co 9968 : 16 : n->missing_ok = false;
1263 peter@eisentraut.org 9969 : 16 : $$ = (Node *) n;
9970 : : }
9971 : : | ALTER USER RoleId RENAME TO RoleId
9972 : : {
7426 tgl@sss.pgh.pa.us 9973 :UBC 0 : RenameStmt *n = makeNode(RenameStmt);
9974 : :
9975 : 0 : n->renameType = OBJECT_ROLE;
8158 peter_e@gmx.net 9976 : 0 : n->subname = $3;
9977 : 0 : n->newname = $6;
5026 simon@2ndQuadrant.co 9978 : 0 : n->missing_ok = false;
1263 peter@eisentraut.org 9979 : 0 : $$ = (Node *) n;
9980 : : }
9981 : : | ALTER TABLESPACE name RENAME TO name
9982 : : {
7794 tgl@sss.pgh.pa.us 9983 :CBC 3 : RenameStmt *n = makeNode(RenameStmt);
9984 : :
9985 : 3 : n->renameType = OBJECT_TABLESPACE;
9986 : 3 : n->subname = $3;
9987 : 3 : n->newname = $6;
5026 simon@2ndQuadrant.co 9988 : 3 : n->missing_ok = false;
1263 peter@eisentraut.org 9989 : 3 : $$ = (Node *) n;
9990 : : }
9991 : : | ALTER STATISTICS any_name RENAME TO name
9992 : : {
3139 alvherre@alvh.no-ip. 9993 : 15 : RenameStmt *n = makeNode(RenameStmt);
9994 : :
9995 : 15 : n->renameType = OBJECT_STATISTIC_EXT;
9996 : 15 : n->object = (Node *) $3;
9997 : 15 : n->newname = $6;
9998 : 15 : n->missing_ok = false;
1263 peter@eisentraut.org 9999 : 15 : $$ = (Node *) n;
10000 : : }
10001 : : | ALTER TEXT_P SEARCH PARSER any_name RENAME TO name
10002 : : {
6642 tgl@sss.pgh.pa.us 10003 : 6 : RenameStmt *n = makeNode(RenameStmt);
10004 : :
10005 : 6 : n->renameType = OBJECT_TSPARSER;
3271 peter_e@gmx.net 10006 : 6 : n->object = (Node *) $5;
6642 tgl@sss.pgh.pa.us 10007 : 6 : n->newname = $8;
5026 simon@2ndQuadrant.co 10008 : 6 : n->missing_ok = false;
1263 peter@eisentraut.org 10009 : 6 : $$ = (Node *) n;
10010 : : }
10011 : : | ALTER TEXT_P SEARCH DICTIONARY any_name RENAME TO name
10012 : : {
6642 tgl@sss.pgh.pa.us 10013 : 12 : RenameStmt *n = makeNode(RenameStmt);
10014 : :
10015 : 12 : n->renameType = OBJECT_TSDICTIONARY;
3271 peter_e@gmx.net 10016 : 12 : n->object = (Node *) $5;
6642 tgl@sss.pgh.pa.us 10017 : 12 : n->newname = $8;
5026 simon@2ndQuadrant.co 10018 : 12 : n->missing_ok = false;
1263 peter@eisentraut.org 10019 : 12 : $$ = (Node *) n;
10020 : : }
10021 : : | ALTER TEXT_P SEARCH TEMPLATE any_name RENAME TO name
10022 : : {
6642 tgl@sss.pgh.pa.us 10023 : 6 : RenameStmt *n = makeNode(RenameStmt);
10024 : :
10025 : 6 : n->renameType = OBJECT_TSTEMPLATE;
3271 peter_e@gmx.net 10026 : 6 : n->object = (Node *) $5;
6642 tgl@sss.pgh.pa.us 10027 : 6 : n->newname = $8;
5026 simon@2ndQuadrant.co 10028 : 6 : n->missing_ok = false;
1263 peter@eisentraut.org 10029 : 6 : $$ = (Node *) n;
10030 : : }
10031 : : | ALTER TEXT_P SEARCH CONFIGURATION any_name RENAME TO name
10032 : : {
6642 tgl@sss.pgh.pa.us 10033 : 12 : RenameStmt *n = makeNode(RenameStmt);
10034 : :
10035 : 12 : n->renameType = OBJECT_TSCONFIGURATION;
3271 peter_e@gmx.net 10036 : 12 : n->object = (Node *) $5;
6642 tgl@sss.pgh.pa.us 10037 : 12 : n->newname = $8;
5026 simon@2ndQuadrant.co 10038 : 12 : n->missing_ok = false;
1263 peter@eisentraut.org 10039 : 12 : $$ = (Node *) n;
10040 : : }
10041 : : | ALTER TYPE_P any_name RENAME TO name
10042 : : {
6431 tgl@sss.pgh.pa.us 10043 : 13 : RenameStmt *n = makeNode(RenameStmt);
10044 : :
10045 : 13 : n->renameType = OBJECT_TYPE;
3271 peter_e@gmx.net 10046 : 13 : n->object = (Node *) $3;
6431 tgl@sss.pgh.pa.us 10047 : 13 : n->newname = $6;
5026 simon@2ndQuadrant.co 10048 : 13 : n->missing_ok = false;
1263 peter@eisentraut.org 10049 : 13 : $$ = (Node *) n;
10050 : : }
10051 : : | ALTER TYPE_P any_name RENAME ATTRIBUTE name TO name opt_drop_behavior
10052 : : {
5510 peter_e@gmx.net 10053 : 12 : RenameStmt *n = makeNode(RenameStmt);
10054 : :
10055 : 12 : n->renameType = OBJECT_ATTRIBUTE;
5413 rhaas@postgresql.org 10056 : 12 : n->relationType = OBJECT_TYPE;
5510 peter_e@gmx.net 10057 : 12 : n->relation = makeRangeVarFromAnyName($3, @3, yyscanner);
10058 : 12 : n->subname = $6;
10059 : 12 : n->newname = $8;
5452 10060 : 12 : n->behavior = $9;
5026 simon@2ndQuadrant.co 10061 : 12 : n->missing_ok = false;
1263 peter@eisentraut.org 10062 : 12 : $$ = (Node *) n;
10063 : : }
10064 : : ;
10065 : :
10066 : : opt_column: COLUMN
10067 : : | /*EMPTY*/
10068 : : ;
10069 : :
5346 tgl@sss.pgh.pa.us 10070 : 91 : opt_set_data: SET DATA_P { $$ = 1; }
6215 peter_e@gmx.net 10071 : 456 : | /*EMPTY*/ { $$ = 0; }
10072 : : ;
10073 : :
10074 : : /*****************************************************************************
10075 : : *
10076 : : * ALTER THING name DEPENDS ON EXTENSION name
10077 : : *
10078 : : *****************************************************************************/
10079 : :
10080 : : AlterObjectDependsStmt:
10081 : : ALTER FUNCTION function_with_argtypes opt_no DEPENDS ON EXTENSION name
10082 : : {
3492 alvherre@alvh.no-ip. 10083 : 6 : AlterObjectDependsStmt *n = makeNode(AlterObjectDependsStmt);
10084 : :
10085 : 6 : n->objectType = OBJECT_FUNCTION;
3271 peter_e@gmx.net 10086 : 6 : n->object = (Node *) $3;
2016 alvherre@alvh.no-ip. 10087 : 6 : n->extname = makeString($8);
10088 : 6 : n->remove = $4;
1263 peter@eisentraut.org 10089 : 6 : $$ = (Node *) n;
10090 : : }
10091 : : | ALTER PROCEDURE function_with_argtypes opt_no DEPENDS ON EXTENSION name
10092 : : {
2888 peter_e@gmx.net 10093 :UBC 0 : AlterObjectDependsStmt *n = makeNode(AlterObjectDependsStmt);
10094 : :
10095 : 0 : n->objectType = OBJECT_PROCEDURE;
10096 : 0 : n->object = (Node *) $3;
2016 alvherre@alvh.no-ip. 10097 : 0 : n->extname = makeString($8);
10098 : 0 : n->remove = $4;
1263 peter@eisentraut.org 10099 : 0 : $$ = (Node *) n;
10100 : : }
10101 : : | ALTER ROUTINE function_with_argtypes opt_no DEPENDS ON EXTENSION name
10102 : : {
2888 peter_e@gmx.net 10103 : 0 : AlterObjectDependsStmt *n = makeNode(AlterObjectDependsStmt);
10104 : :
10105 : 0 : n->objectType = OBJECT_ROUTINE;
10106 : 0 : n->object = (Node *) $3;
2016 alvherre@alvh.no-ip. 10107 : 0 : n->extname = makeString($8);
10108 : 0 : n->remove = $4;
1263 peter@eisentraut.org 10109 : 0 : $$ = (Node *) n;
10110 : : }
10111 : : | ALTER TRIGGER name ON qualified_name opt_no DEPENDS ON EXTENSION name
10112 : : {
3492 alvherre@alvh.no-ip. 10113 :CBC 5 : AlterObjectDependsStmt *n = makeNode(AlterObjectDependsStmt);
10114 : :
10115 : 5 : n->objectType = OBJECT_TRIGGER;
10116 : 5 : n->relation = $5;
3271 peter_e@gmx.net 10117 : 5 : n->object = (Node *) list_make1(makeString($3));
2016 alvherre@alvh.no-ip. 10118 : 5 : n->extname = makeString($10);
10119 : 5 : n->remove = $6;
1263 peter@eisentraut.org 10120 : 5 : $$ = (Node *) n;
10121 : : }
10122 : : | ALTER MATERIALIZED VIEW qualified_name opt_no DEPENDS ON EXTENSION name
10123 : : {
3492 alvherre@alvh.no-ip. 10124 : 5 : AlterObjectDependsStmt *n = makeNode(AlterObjectDependsStmt);
10125 : :
10126 : 5 : n->objectType = OBJECT_MATVIEW;
10127 : 5 : n->relation = $4;
2016 10128 : 5 : n->extname = makeString($9);
10129 : 5 : n->remove = $5;
1263 peter@eisentraut.org 10130 : 5 : $$ = (Node *) n;
10131 : : }
10132 : : | ALTER INDEX qualified_name opt_no DEPENDS ON EXTENSION name
10133 : : {
3492 alvherre@alvh.no-ip. 10134 : 7 : AlterObjectDependsStmt *n = makeNode(AlterObjectDependsStmt);
10135 : :
10136 : 7 : n->objectType = OBJECT_INDEX;
10137 : 7 : n->relation = $3;
2016 10138 : 7 : n->extname = makeString($8);
10139 : 7 : n->remove = $4;
1263 peter@eisentraut.org 10140 : 7 : $$ = (Node *) n;
10141 : : }
10142 : : ;
10143 : :
2016 alvherre@alvh.no-ip. 10144 : 4 : opt_no: NO { $$ = true; }
10145 : 19 : | /* EMPTY */ { $$ = false; }
10146 : : ;
10147 : :
10148 : : /*****************************************************************************
10149 : : *
10150 : : * ALTER THING name SET SCHEMA name
10151 : : *
10152 : : *****************************************************************************/
10153 : :
10154 : : AlterObjectSchemaStmt:
10155 : : ALTER AGGREGATE aggregate_with_argtypes SET SCHEMA name
10156 : : {
7392 tgl@sss.pgh.pa.us 10157 : 12 : AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
10158 : :
10159 : 12 : n->objectType = OBJECT_AGGREGATE;
3271 peter_e@gmx.net 10160 : 12 : n->object = (Node *) $3;
3329 10161 : 12 : n->newschema = $6;
5026 simon@2ndQuadrant.co 10162 : 12 : n->missing_ok = false;
1263 peter@eisentraut.org 10163 : 12 : $$ = (Node *) n;
10164 : : }
10165 : : | ALTER COLLATION any_name SET SCHEMA name
10166 : : {
5371 peter_e@gmx.net 10167 : 3 : AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
10168 : :
10169 : 3 : n->objectType = OBJECT_COLLATION;
3271 10170 : 3 : n->object = (Node *) $3;
5371 10171 : 3 : n->newschema = $6;
5026 simon@2ndQuadrant.co 10172 : 3 : n->missing_ok = false;
1263 peter@eisentraut.org 10173 : 3 : $$ = (Node *) n;
10174 : : }
10175 : : | ALTER CONVERSION_P any_name SET SCHEMA name
10176 : : {
5449 rhaas@postgresql.org 10177 : 12 : AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
10178 : :
10179 : 12 : n->objectType = OBJECT_CONVERSION;
3271 peter_e@gmx.net 10180 : 12 : n->object = (Node *) $3;
5449 rhaas@postgresql.org 10181 : 12 : n->newschema = $6;
5026 simon@2ndQuadrant.co 10182 : 12 : n->missing_ok = false;
1263 peter@eisentraut.org 10183 : 12 : $$ = (Node *) n;
10184 : : }
10185 : : | ALTER DOMAIN_P any_name SET SCHEMA name
10186 : : {
7392 tgl@sss.pgh.pa.us 10187 : 3 : AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
10188 : :
10189 : 3 : n->objectType = OBJECT_DOMAIN;
3271 peter_e@gmx.net 10190 : 3 : n->object = (Node *) $3;
7392 tgl@sss.pgh.pa.us 10191 : 3 : n->newschema = $6;
5026 simon@2ndQuadrant.co 10192 : 3 : n->missing_ok = false;
1263 peter@eisentraut.org 10193 : 3 : $$ = (Node *) n;
10194 : : }
10195 : : | ALTER EXTENSION name SET SCHEMA name
10196 : : {
5375 tgl@sss.pgh.pa.us 10197 : 6 : AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
10198 : :
10199 : 6 : n->objectType = OBJECT_EXTENSION;
3271 peter_e@gmx.net 10200 : 6 : n->object = (Node *) makeString($3);
5375 tgl@sss.pgh.pa.us 10201 : 6 : n->newschema = $6;
5026 simon@2ndQuadrant.co 10202 : 6 : n->missing_ok = false;
1263 peter@eisentraut.org 10203 : 6 : $$ = (Node *) n;
10204 : : }
10205 : : | ALTER FUNCTION function_with_argtypes SET SCHEMA name
10206 : : {
7392 tgl@sss.pgh.pa.us 10207 : 21 : AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
10208 : :
10209 : 21 : n->objectType = OBJECT_FUNCTION;
3271 peter_e@gmx.net 10210 : 21 : n->object = (Node *) $3;
6629 tgl@sss.pgh.pa.us 10211 : 21 : n->newschema = $6;
5026 simon@2ndQuadrant.co 10212 : 21 : n->missing_ok = false;
1263 peter@eisentraut.org 10213 : 21 : $$ = (Node *) n;
10214 : : }
10215 : : | ALTER OPERATOR operator_with_argtypes SET SCHEMA name
10216 : : {
5449 rhaas@postgresql.org 10217 : 9 : AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
10218 : :
10219 : 9 : n->objectType = OBJECT_OPERATOR;
3271 peter_e@gmx.net 10220 : 9 : n->object = (Node *) $3;
3225 10221 : 9 : n->newschema = $6;
5026 simon@2ndQuadrant.co 10222 : 9 : n->missing_ok = false;
1263 peter@eisentraut.org 10223 : 9 : $$ = (Node *) n;
10224 : : }
10225 : : | ALTER OPERATOR CLASS any_name USING name SET SCHEMA name
10226 : : {
5449 rhaas@postgresql.org 10227 : 12 : AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
10228 : :
10229 : 12 : n->objectType = OBJECT_OPCLASS;
3271 peter_e@gmx.net 10230 : 12 : n->object = (Node *) lcons(makeString($6), $4);
5449 rhaas@postgresql.org 10231 : 12 : n->newschema = $9;
5026 simon@2ndQuadrant.co 10232 : 12 : n->missing_ok = false;
1263 peter@eisentraut.org 10233 : 12 : $$ = (Node *) n;
10234 : : }
10235 : : | ALTER OPERATOR FAMILY any_name USING name SET SCHEMA name
10236 : : {
5449 rhaas@postgresql.org 10237 : 12 : AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
10238 : :
10239 : 12 : n->objectType = OBJECT_OPFAMILY;
3271 peter_e@gmx.net 10240 : 12 : n->object = (Node *) lcons(makeString($6), $4);
5449 rhaas@postgresql.org 10241 : 12 : n->newschema = $9;
5026 simon@2ndQuadrant.co 10242 : 12 : n->missing_ok = false;
1263 peter@eisentraut.org 10243 : 12 : $$ = (Node *) n;
10244 : : }
10245 : : | ALTER PROCEDURE function_with_argtypes SET SCHEMA name
10246 : : {
2888 peter_e@gmx.net 10247 :UBC 0 : AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
10248 : :
10249 : 0 : n->objectType = OBJECT_PROCEDURE;
10250 : 0 : n->object = (Node *) $3;
10251 : 0 : n->newschema = $6;
10252 : 0 : n->missing_ok = false;
1263 peter@eisentraut.org 10253 : 0 : $$ = (Node *) n;
10254 : : }
10255 : : | ALTER ROUTINE function_with_argtypes SET SCHEMA name
10256 : : {
2888 peter_e@gmx.net 10257 : 0 : AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
10258 : :
10259 : 0 : n->objectType = OBJECT_ROUTINE;
10260 : 0 : n->object = (Node *) $3;
10261 : 0 : n->newschema = $6;
10262 : 0 : n->missing_ok = false;
1263 peter@eisentraut.org 10263 : 0 : $$ = (Node *) n;
10264 : : }
10265 : : | ALTER TABLE relation_expr SET SCHEMA name
10266 : : {
6343 tgl@sss.pgh.pa.us 10267 :CBC 33 : AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
10268 : :
10269 : 33 : n->objectType = OBJECT_TABLE;
10270 : 33 : n->relation = $3;
10271 : 33 : n->newschema = $6;
5026 simon@2ndQuadrant.co 10272 : 33 : n->missing_ok = false;
1263 peter@eisentraut.org 10273 : 33 : $$ = (Node *) n;
10274 : : }
10275 : : | ALTER TABLE IF_P EXISTS relation_expr SET SCHEMA name
10276 : : {
5026 simon@2ndQuadrant.co 10277 : 6 : AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
10278 : :
10279 : 6 : n->objectType = OBJECT_TABLE;
10280 : 6 : n->relation = $5;
10281 : 6 : n->newschema = $8;
10282 : 6 : n->missing_ok = true;
1263 peter@eisentraut.org 10283 : 6 : $$ = (Node *) n;
10284 : : }
10285 : : | ALTER STATISTICS any_name SET SCHEMA name
10286 : : {
3139 alvherre@alvh.no-ip. 10287 : 9 : AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
10288 : :
10289 : 9 : n->objectType = OBJECT_STATISTIC_EXT;
10290 : 9 : n->object = (Node *) $3;
10291 : 9 : n->newschema = $6;
10292 : 9 : n->missing_ok = false;
1263 peter@eisentraut.org 10293 : 9 : $$ = (Node *) n;
10294 : : }
10295 : : | ALTER TEXT_P SEARCH PARSER any_name SET SCHEMA name
10296 : : {
5449 rhaas@postgresql.org 10297 : 9 : AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
10298 : :
10299 : 9 : n->objectType = OBJECT_TSPARSER;
3271 peter_e@gmx.net 10300 : 9 : n->object = (Node *) $5;
5449 rhaas@postgresql.org 10301 : 9 : n->newschema = $8;
5026 simon@2ndQuadrant.co 10302 : 9 : n->missing_ok = false;
1263 peter@eisentraut.org 10303 : 9 : $$ = (Node *) n;
10304 : : }
10305 : : | ALTER TEXT_P SEARCH DICTIONARY any_name SET SCHEMA name
10306 : : {
5449 rhaas@postgresql.org 10307 : 12 : AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
10308 : :
10309 : 12 : n->objectType = OBJECT_TSDICTIONARY;
3271 peter_e@gmx.net 10310 : 12 : n->object = (Node *) $5;
5449 rhaas@postgresql.org 10311 : 12 : n->newschema = $8;
5026 simon@2ndQuadrant.co 10312 : 12 : n->missing_ok = false;
1263 peter@eisentraut.org 10313 : 12 : $$ = (Node *) n;
10314 : : }
10315 : : | ALTER TEXT_P SEARCH TEMPLATE any_name SET SCHEMA name
10316 : : {
5449 rhaas@postgresql.org 10317 : 9 : AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
10318 : :
10319 : 9 : n->objectType = OBJECT_TSTEMPLATE;
3271 peter_e@gmx.net 10320 : 9 : n->object = (Node *) $5;
5449 rhaas@postgresql.org 10321 : 9 : n->newschema = $8;
5026 simon@2ndQuadrant.co 10322 : 9 : n->missing_ok = false;
1263 peter@eisentraut.org 10323 : 9 : $$ = (Node *) n;
10324 : : }
10325 : : | ALTER TEXT_P SEARCH CONFIGURATION any_name SET SCHEMA name
10326 : : {
5449 rhaas@postgresql.org 10327 : 12 : AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
10328 : :
10329 : 12 : n->objectType = OBJECT_TSCONFIGURATION;
3271 peter_e@gmx.net 10330 : 12 : n->object = (Node *) $5;
5449 rhaas@postgresql.org 10331 : 12 : n->newschema = $8;
5026 simon@2ndQuadrant.co 10332 : 12 : n->missing_ok = false;
1263 peter@eisentraut.org 10333 : 12 : $$ = (Node *) n;
10334 : : }
10335 : : | ALTER SEQUENCE qualified_name SET SCHEMA name
10336 : : {
7392 tgl@sss.pgh.pa.us 10337 : 4 : AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
10338 : :
10339 : 4 : n->objectType = OBJECT_SEQUENCE;
10340 : 4 : n->relation = $3;
10341 : 4 : n->newschema = $6;
5026 simon@2ndQuadrant.co 10342 : 4 : n->missing_ok = false;
1263 peter@eisentraut.org 10343 : 4 : $$ = (Node *) n;
10344 : : }
10345 : : | ALTER SEQUENCE IF_P EXISTS qualified_name SET SCHEMA name
10346 : : {
5026 simon@2ndQuadrant.co 10347 :UBC 0 : AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
10348 : :
10349 : 0 : n->objectType = OBJECT_SEQUENCE;
10350 : 0 : n->relation = $5;
10351 : 0 : n->newschema = $8;
10352 : 0 : n->missing_ok = true;
1263 peter@eisentraut.org 10353 : 0 : $$ = (Node *) n;
10354 : : }
10355 : : | ALTER VIEW qualified_name SET SCHEMA name
10356 : : {
7392 tgl@sss.pgh.pa.us 10357 : 0 : AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
10358 : :
6343 10359 : 0 : n->objectType = OBJECT_VIEW;
7392 10360 : 0 : n->relation = $3;
10361 : 0 : n->newschema = $6;
5026 simon@2ndQuadrant.co 10362 : 0 : n->missing_ok = false;
1263 peter@eisentraut.org 10363 : 0 : $$ = (Node *) n;
10364 : : }
10365 : : | ALTER VIEW IF_P EXISTS qualified_name SET SCHEMA name
10366 : : {
5026 simon@2ndQuadrant.co 10367 : 0 : AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
10368 : :
10369 : 0 : n->objectType = OBJECT_VIEW;
10370 : 0 : n->relation = $5;
10371 : 0 : n->newschema = $8;
10372 : 0 : n->missing_ok = true;
1263 peter@eisentraut.org 10373 : 0 : $$ = (Node *) n;
10374 : : }
10375 : : | ALTER MATERIALIZED VIEW qualified_name SET SCHEMA name
10376 : : {
4621 kgrittn@postgresql.o 10377 :CBC 3 : AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
10378 : :
10379 : 3 : n->objectType = OBJECT_MATVIEW;
10380 : 3 : n->relation = $4;
10381 : 3 : n->newschema = $7;
10382 : 3 : n->missing_ok = false;
1263 peter@eisentraut.org 10383 : 3 : $$ = (Node *) n;
10384 : : }
10385 : : | ALTER MATERIALIZED VIEW IF_P EXISTS qualified_name SET SCHEMA name
10386 : : {
4621 kgrittn@postgresql.o 10387 :UBC 0 : AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
10388 : :
10389 : 0 : n->objectType = OBJECT_MATVIEW;
10390 : 0 : n->relation = $6;
10391 : 0 : n->newschema = $9;
10392 : 0 : n->missing_ok = true;
1263 peter@eisentraut.org 10393 : 0 : $$ = (Node *) n;
10394 : : }
10395 : : | ALTER FOREIGN TABLE relation_expr SET SCHEMA name
10396 : : {
5413 rhaas@postgresql.org 10397 :CBC 3 : AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
10398 : :
10399 : 3 : n->objectType = OBJECT_FOREIGN_TABLE;
10400 : 3 : n->relation = $4;
10401 : 3 : n->newschema = $7;
5026 simon@2ndQuadrant.co 10402 : 3 : n->missing_ok = false;
1263 peter@eisentraut.org 10403 : 3 : $$ = (Node *) n;
10404 : : }
10405 : : | ALTER FOREIGN TABLE IF_P EXISTS relation_expr SET SCHEMA name
10406 : : {
5026 simon@2ndQuadrant.co 10407 : 3 : AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
10408 : :
10409 : 3 : n->objectType = OBJECT_FOREIGN_TABLE;
10410 : 3 : n->relation = $6;
10411 : 3 : n->newschema = $9;
10412 : 3 : n->missing_ok = true;
1263 peter@eisentraut.org 10413 : 3 : $$ = (Node *) n;
10414 : : }
10415 : : | ALTER TYPE_P any_name SET SCHEMA name
10416 : : {
7392 tgl@sss.pgh.pa.us 10417 : 6 : AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
10418 : :
10419 : 6 : n->objectType = OBJECT_TYPE;
3271 peter_e@gmx.net 10420 : 6 : n->object = (Node *) $3;
7392 tgl@sss.pgh.pa.us 10421 : 6 : n->newschema = $6;
5026 simon@2ndQuadrant.co 10422 : 6 : n->missing_ok = false;
1263 peter@eisentraut.org 10423 : 6 : $$ = (Node *) n;
10424 : : }
10425 : : ;
10426 : :
10427 : : /*****************************************************************************
10428 : : *
10429 : : * ALTER OPERATOR name SET define
10430 : : *
10431 : : *****************************************************************************/
10432 : :
10433 : : AlterOperatorStmt:
10434 : : ALTER OPERATOR operator_with_argtypes SET '(' operator_def_list ')'
10435 : : {
3758 heikki.linnakangas@i 10436 : 304 : AlterOperatorStmt *n = makeNode(AlterOperatorStmt);
10437 : :
3225 peter_e@gmx.net 10438 : 304 : n->opername = $3;
10439 : 304 : n->options = $6;
1263 peter@eisentraut.org 10440 : 304 : $$ = (Node *) n;
10441 : : }
10442 : : ;
10443 : :
3758 heikki.linnakangas@i 10444 : 334 : operator_def_list: operator_def_elem { $$ = list_make1($1); }
10445 : 253 : | operator_def_list ',' operator_def_elem { $$ = lappend($1, $3); }
10446 : : ;
10447 : :
10448 : : operator_def_elem: ColLabel '=' NONE
3338 peter_e@gmx.net 10449 : 15 : { $$ = makeDefElem($1, NULL, @1); }
10450 : : | ColLabel '=' operator_def_arg
3093 10451 : 555 : { $$ = makeDefElem($1, (Node *) $3, @1); }
10452 : : | ColLabel
738 tgl@sss.pgh.pa.us 10453 : 17 : { $$ = makeDefElem($1, NULL, @1); }
10454 : : ;
10455 : :
10456 : : /* must be similar enough to def_arg to avoid reduce/reduce conflicts */
10457 : : operator_def_arg:
1263 peter@eisentraut.org 10458 : 516 : func_type { $$ = (Node *) $1; }
10459 : 12 : | reserved_keyword { $$ = (Node *) makeString(pstrdup($1)); }
10460 : 27 : | qual_all_Op { $$ = (Node *) $1; }
1263 peter@eisentraut.org 10461 :UBC 0 : | NumericOnly { $$ = (Node *) $1; }
10462 : 0 : | Sconst { $$ = (Node *) makeString($1); }
10463 : : ;
10464 : :
10465 : : /*****************************************************************************
10466 : : *
10467 : : * ALTER TYPE name SET define
10468 : : *
10469 : : * We repurpose ALTER OPERATOR's version of "definition" here
10470 : : *
10471 : : *****************************************************************************/
10472 : :
10473 : : AlterTypeStmt:
10474 : : ALTER TYPE_P any_name SET '(' operator_def_list ')'
10475 : : {
2061 tgl@sss.pgh.pa.us 10476 :CBC 30 : AlterTypeStmt *n = makeNode(AlterTypeStmt);
10477 : :
10478 : 30 : n->typeName = $3;
10479 : 30 : n->options = $6;
1263 peter@eisentraut.org 10480 : 30 : $$ = (Node *) n;
10481 : : }
10482 : : ;
10483 : :
10484 : : /*****************************************************************************
10485 : : *
10486 : : * ALTER THING name OWNER TO newname
10487 : : *
10488 : : *****************************************************************************/
10489 : :
10490 : : AlterOwnerStmt: ALTER AGGREGATE aggregate_with_argtypes OWNER TO RoleSpec
10491 : : {
7794 tgl@sss.pgh.pa.us 10492 : 71 : AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
10493 : :
10494 : 71 : n->objectType = OBJECT_AGGREGATE;
3271 peter_e@gmx.net 10495 : 71 : n->object = (Node *) $3;
3329 10496 : 71 : n->newowner = $6;
1263 peter@eisentraut.org 10497 : 71 : $$ = (Node *) n;
10498 : : }
10499 : : | ALTER COLLATION any_name OWNER TO RoleSpec
10500 : : {
5371 peter_e@gmx.net 10501 : 9 : AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
10502 : :
10503 : 9 : n->objectType = OBJECT_COLLATION;
3271 10504 : 9 : n->object = (Node *) $3;
5371 10505 : 9 : n->newowner = $6;
1263 peter@eisentraut.org 10506 : 9 : $$ = (Node *) n;
10507 : : }
10508 : : | ALTER CONVERSION_P any_name OWNER TO RoleSpec
10509 : : {
7794 tgl@sss.pgh.pa.us 10510 : 12 : AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
10511 : :
10512 : 12 : n->objectType = OBJECT_CONVERSION;
3271 peter_e@gmx.net 10513 : 12 : n->object = (Node *) $3;
7794 tgl@sss.pgh.pa.us 10514 : 12 : n->newowner = $6;
1263 peter@eisentraut.org 10515 : 12 : $$ = (Node *) n;
10516 : : }
10517 : : | ALTER DATABASE name OWNER TO RoleSpec
10518 : : {
7794 tgl@sss.pgh.pa.us 10519 : 43 : AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
10520 : :
10521 : 43 : n->objectType = OBJECT_DATABASE;
3271 peter_e@gmx.net 10522 : 43 : n->object = (Node *) makeString($3);
7794 tgl@sss.pgh.pa.us 10523 : 43 : n->newowner = $6;
1263 peter@eisentraut.org 10524 : 43 : $$ = (Node *) n;
10525 : : }
10526 : : | ALTER DOMAIN_P any_name OWNER TO RoleSpec
10527 : : {
7794 tgl@sss.pgh.pa.us 10528 : 24 : AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
10529 : :
10530 : 24 : n->objectType = OBJECT_DOMAIN;
3271 peter_e@gmx.net 10531 : 24 : n->object = (Node *) $3;
7794 tgl@sss.pgh.pa.us 10532 : 24 : n->newowner = $6;
1263 peter@eisentraut.org 10533 : 24 : $$ = (Node *) n;
10534 : : }
10535 : : | ALTER FUNCTION function_with_argtypes OWNER TO RoleSpec
10536 : : {
7794 tgl@sss.pgh.pa.us 10537 : 297 : AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
10538 : :
10539 : 297 : n->objectType = OBJECT_FUNCTION;
3271 peter_e@gmx.net 10540 : 297 : n->object = (Node *) $3;
6629 tgl@sss.pgh.pa.us 10541 : 297 : n->newowner = $6;
1263 peter@eisentraut.org 10542 : 297 : $$ = (Node *) n;
10543 : : }
10544 : : | ALTER opt_procedural LANGUAGE name OWNER TO RoleSpec
10545 : : {
6790 tgl@sss.pgh.pa.us 10546 : 71 : AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
10547 : :
10548 : 71 : n->objectType = OBJECT_LANGUAGE;
3271 peter_e@gmx.net 10549 : 71 : n->object = (Node *) makeString($4);
6790 tgl@sss.pgh.pa.us 10550 : 71 : n->newowner = $7;
1263 peter@eisentraut.org 10551 : 71 : $$ = (Node *) n;
10552 : : }
10553 : : | ALTER LARGE_P OBJECT_P NumericOnly OWNER TO RoleSpec
10554 : : {
5799 itagaki.takahiro@gma 10555 : 8 : AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
10556 : :
10557 : 8 : n->objectType = OBJECT_LARGEOBJECT;
3271 peter_e@gmx.net 10558 : 8 : n->object = (Node *) $4;
5799 itagaki.takahiro@gma 10559 : 8 : n->newowner = $7;
1263 peter@eisentraut.org 10560 : 8 : $$ = (Node *) n;
10561 : : }
10562 : : | ALTER OPERATOR operator_with_argtypes OWNER TO RoleSpec
10563 : : {
7794 tgl@sss.pgh.pa.us 10564 : 23 : AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
10565 : :
10566 : 23 : n->objectType = OBJECT_OPERATOR;
3271 peter_e@gmx.net 10567 : 23 : n->object = (Node *) $3;
3225 10568 : 23 : n->newowner = $6;
1263 peter@eisentraut.org 10569 : 23 : $$ = (Node *) n;
10570 : : }
10571 : : | ALTER OPERATOR CLASS any_name USING name OWNER TO RoleSpec
10572 : : {
7794 tgl@sss.pgh.pa.us 10573 : 27 : AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
10574 : :
10575 : 27 : n->objectType = OBJECT_OPCLASS;
3271 peter_e@gmx.net 10576 : 27 : n->object = (Node *) lcons(makeString($6), $4);
7794 tgl@sss.pgh.pa.us 10577 : 27 : n->newowner = $9;
1263 peter@eisentraut.org 10578 : 27 : $$ = (Node *) n;
10579 : : }
10580 : : | ALTER OPERATOR FAMILY any_name USING name OWNER TO RoleSpec
10581 : : {
6852 tgl@sss.pgh.pa.us 10582 : 31 : AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
10583 : :
10584 : 31 : n->objectType = OBJECT_OPFAMILY;
3271 peter_e@gmx.net 10585 : 31 : n->object = (Node *) lcons(makeString($6), $4);
6852 tgl@sss.pgh.pa.us 10586 : 31 : n->newowner = $9;
1263 peter@eisentraut.org 10587 : 31 : $$ = (Node *) n;
10588 : : }
10589 : : | ALTER PROCEDURE function_with_argtypes OWNER TO RoleSpec
10590 : : {
2888 peter_e@gmx.net 10591 : 12 : AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
10592 : :
10593 : 12 : n->objectType = OBJECT_PROCEDURE;
10594 : 12 : n->object = (Node *) $3;
10595 : 12 : n->newowner = $6;
1263 peter@eisentraut.org 10596 : 12 : $$ = (Node *) n;
10597 : : }
10598 : : | ALTER ROUTINE function_with_argtypes OWNER TO RoleSpec
10599 : : {
2888 peter_e@gmx.net 10600 :UBC 0 : AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
10601 : :
10602 : 0 : n->objectType = OBJECT_ROUTINE;
10603 : 0 : n->object = (Node *) $3;
10604 : 0 : n->newowner = $6;
1263 peter@eisentraut.org 10605 : 0 : $$ = (Node *) n;
10606 : : }
10607 : : | ALTER SCHEMA name OWNER TO RoleSpec
10608 : : {
7794 tgl@sss.pgh.pa.us 10609 :CBC 32 : AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
10610 : :
10611 : 32 : n->objectType = OBJECT_SCHEMA;
3271 peter_e@gmx.net 10612 : 32 : n->object = (Node *) makeString($3);
7794 tgl@sss.pgh.pa.us 10613 : 32 : n->newowner = $6;
1263 peter@eisentraut.org 10614 : 32 : $$ = (Node *) n;
10615 : : }
10616 : : | ALTER TYPE_P any_name OWNER TO RoleSpec
10617 : : {
7794 tgl@sss.pgh.pa.us 10618 : 42 : AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
10619 : :
10620 : 42 : n->objectType = OBJECT_TYPE;
3271 peter_e@gmx.net 10621 : 42 : n->object = (Node *) $3;
7794 tgl@sss.pgh.pa.us 10622 : 42 : n->newowner = $6;
1263 peter@eisentraut.org 10623 : 42 : $$ = (Node *) n;
10624 : : }
10625 : : | ALTER TABLESPACE name OWNER TO RoleSpec
10626 : : {
7794 tgl@sss.pgh.pa.us 10627 : 3 : AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
10628 : :
10629 : 3 : n->objectType = OBJECT_TABLESPACE;
3271 peter_e@gmx.net 10630 : 3 : n->object = (Node *) makeString($3);
7794 tgl@sss.pgh.pa.us 10631 : 3 : n->newowner = $6;
1263 peter@eisentraut.org 10632 : 3 : $$ = (Node *) n;
10633 : : }
10634 : : | ALTER STATISTICS any_name OWNER TO RoleSpec
10635 : : {
3139 alvherre@alvh.no-ip. 10636 : 16 : AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
10637 : :
10638 : 16 : n->objectType = OBJECT_STATISTIC_EXT;
10639 : 16 : n->object = (Node *) $3;
10640 : 16 : n->newowner = $6;
1263 peter@eisentraut.org 10641 : 16 : $$ = (Node *) n;
10642 : : }
10643 : : | ALTER TEXT_P SEARCH DICTIONARY any_name OWNER TO RoleSpec
10644 : : {
6642 tgl@sss.pgh.pa.us 10645 : 21 : AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
10646 : :
10647 : 21 : n->objectType = OBJECT_TSDICTIONARY;
3271 peter_e@gmx.net 10648 : 21 : n->object = (Node *) $5;
6642 tgl@sss.pgh.pa.us 10649 : 21 : n->newowner = $8;
1263 peter@eisentraut.org 10650 : 21 : $$ = (Node *) n;
10651 : : }
10652 : : | ALTER TEXT_P SEARCH CONFIGURATION any_name OWNER TO RoleSpec
10653 : : {
6642 tgl@sss.pgh.pa.us 10654 : 16 : AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
10655 : :
10656 : 16 : n->objectType = OBJECT_TSCONFIGURATION;
3271 peter_e@gmx.net 10657 : 16 : n->object = (Node *) $5;
6642 tgl@sss.pgh.pa.us 10658 : 16 : n->newowner = $8;
1263 peter@eisentraut.org 10659 : 16 : $$ = (Node *) n;
10660 : : }
10661 : : | ALTER FOREIGN DATA_P WRAPPER name OWNER TO RoleSpec
10662 : : {
6156 peter_e@gmx.net 10663 : 10 : AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
10664 : :
10665 : 10 : n->objectType = OBJECT_FDW;
3271 10666 : 10 : n->object = (Node *) makeString($5);
6156 10667 : 10 : n->newowner = $8;
1263 peter@eisentraut.org 10668 : 10 : $$ = (Node *) n;
10669 : : }
10670 : : | ALTER SERVER name OWNER TO RoleSpec
10671 : : {
6156 peter_e@gmx.net 10672 : 34 : AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
10673 : :
10674 : 34 : n->objectType = OBJECT_FOREIGN_SERVER;
3271 10675 : 34 : n->object = (Node *) makeString($3);
6156 10676 : 34 : n->newowner = $6;
1263 peter@eisentraut.org 10677 : 34 : $$ = (Node *) n;
10678 : : }
10679 : : | ALTER EVENT TRIGGER name OWNER TO RoleSpec
10680 : : {
4849 rhaas@postgresql.org 10681 : 7 : AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
10682 : :
10683 : 7 : n->objectType = OBJECT_EVENT_TRIGGER;
3271 peter_e@gmx.net 10684 : 7 : n->object = (Node *) makeString($4);
4849 rhaas@postgresql.org 10685 : 7 : n->newowner = $7;
1263 peter@eisentraut.org 10686 : 7 : $$ = (Node *) n;
10687 : : }
10688 : : | ALTER PUBLICATION name OWNER TO RoleSpec
10689 : : {
3203 peter_e@gmx.net 10690 : 18 : AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
10691 : :
10692 : 18 : n->objectType = OBJECT_PUBLICATION;
3271 10693 : 18 : n->object = (Node *) makeString($3);
3203 10694 : 18 : n->newowner = $6;
1263 peter@eisentraut.org 10695 : 18 : $$ = (Node *) n;
10696 : : }
10697 : : | ALTER SUBSCRIPTION name OWNER TO RoleSpec
10698 : : {
3203 peter_e@gmx.net 10699 : 9 : AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
10700 : :
10701 : 9 : n->objectType = OBJECT_SUBSCRIPTION;
3271 10702 : 9 : n->object = (Node *) makeString($3);
3203 10703 : 9 : n->newowner = $6;
1263 peter@eisentraut.org 10704 : 9 : $$ = (Node *) n;
10705 : : }
10706 : : ;
10707 : :
10708 : :
10709 : : /*****************************************************************************
10710 : : *
10711 : : * CREATE PUBLICATION name [WITH options]
10712 : : *
10713 : : * CREATE PUBLICATION FOR ALL pub_obj_type [, ...] [WITH options]
10714 : : *
10715 : : * pub_obj_type is one of:
10716 : : *
10717 : : * TABLES
10718 : : * SEQUENCES
10719 : : *
10720 : : * CREATE PUBLICATION FOR pub_obj [, ...] [WITH options]
10721 : : *
10722 : : * pub_obj is one of:
10723 : : *
10724 : : * TABLE table [, ...]
10725 : : * TABLES IN SCHEMA schema [, ...]
10726 : : *
10727 : : *****************************************************************************/
10728 : :
10729 : : CreatePublicationStmt:
10730 : : CREATE PUBLICATION name opt_definition
10731 : : {
3203 peter_e@gmx.net 10732 : 73 : CreatePublicationStmt *n = makeNode(CreatePublicationStmt);
10733 : :
10734 : 73 : n->pubname = $3;
1461 akapila@postgresql.o 10735 : 73 : n->options = $4;
1263 peter@eisentraut.org 10736 : 73 : $$ = (Node *) n;
10737 : : }
10738 : : | CREATE PUBLICATION name FOR pub_obj_type_list opt_definition
10739 : : {
1461 akapila@postgresql.o 10740 : 74 : CreatePublicationStmt *n = makeNode(CreatePublicationStmt);
10741 : :
10742 : 74 : n->pubname = $3;
18 akapila@postgresql.o 10743 :GNC 74 : n->pubobjects = (List *) $5;
10744 : 74 : preprocess_pub_all_objtype_list($5, &n->for_all_tables,
10745 : : &n->for_all_sequences,
10746 : : yyscanner);
10747 : 68 : n->options = $6;
1263 peter@eisentraut.org 10748 :CBC 68 : $$ = (Node *) n;
10749 : : }
10750 : : | CREATE PUBLICATION name FOR pub_obj_list opt_definition
10751 : : {
1461 akapila@postgresql.o 10752 : 329 : CreatePublicationStmt *n = makeNode(CreatePublicationStmt);
10753 : :
10754 : 329 : n->pubname = $3;
10755 : 329 : n->options = $6;
1263 peter@eisentraut.org 10756 : 329 : n->pubobjects = (List *) $5;
1461 akapila@postgresql.o 10757 : 329 : preprocess_pubobj_list(n->pubobjects, yyscanner);
1263 peter@eisentraut.org 10758 : 314 : $$ = (Node *) n;
10759 : : }
10760 : : ;
10761 : :
10762 : : /*
10763 : : * FOR TABLE and FOR TABLES IN SCHEMA specifications
10764 : : *
10765 : : * This rule parses publication objects with and without keyword prefixes.
10766 : : *
10767 : : * The actual type of the object without keyword prefix depends on the previous
10768 : : * one with keyword prefix. It will be preprocessed in preprocess_pubobj_list().
10769 : : *
10770 : : * For the object without keyword prefix, we cannot just use relation_expr here,
10771 : : * because some extended expressions in relation_expr cannot be used as a
10772 : : * schemaname and we cannot differentiate it. So, we extract the rules from
10773 : : * relation_expr here.
10774 : : */
10775 : : PublicationObjSpec:
10776 : : TABLE relation_expr opt_column_list OptWhereClause
10777 : : {
1461 akapila@postgresql.o 10778 : 663 : $$ = makeNode(PublicationObjSpec);
10779 : 663 : $$->pubobjtype = PUBLICATIONOBJ_TABLE;
10780 : 663 : $$->pubtable = makeNode(PublicationTable);
10781 : 663 : $$->pubtable->relation = $2;
1311 tomas.vondra@postgre 10782 : 663 : $$->pubtable->columns = $3;
10783 : 663 : $$->pubtable->whereClause = $4;
10784 : : }
10785 : : | TABLES IN_P SCHEMA ColId
10786 : : {
1461 akapila@postgresql.o 10787 : 186 : $$ = makeNode(PublicationObjSpec);
1397 alvherre@alvh.no-ip. 10788 : 186 : $$->pubobjtype = PUBLICATIONOBJ_TABLES_IN_SCHEMA;
1131 10789 : 186 : $$->name = $4;
10790 : 186 : $$->location = @4;
10791 : : }
10792 : : | TABLES IN_P SCHEMA CURRENT_SCHEMA
10793 : : {
1461 akapila@postgresql.o 10794 : 9 : $$ = makeNode(PublicationObjSpec);
1397 alvherre@alvh.no-ip. 10795 : 9 : $$->pubobjtype = PUBLICATIONOBJ_TABLES_IN_CUR_SCHEMA;
1131 10796 : 9 : $$->location = @4;
10797 : : }
10798 : : | ColId opt_column_list OptWhereClause
10799 : : {
1461 akapila@postgresql.o 10800 : 65 : $$ = makeNode(PublicationObjSpec);
10801 : 65 : $$->pubobjtype = PUBLICATIONOBJ_CONTINUATION;
10802 : : /*
10803 : : * If either a row filter or column list is specified, create
10804 : : * a PublicationTable object.
10805 : : */
1311 tomas.vondra@postgre 10806 [ + + + + ]: 65 : if ($2 || $3)
10807 : : {
10808 : : /*
10809 : : * The OptWhereClause must be stored here but it is
10810 : : * valid only for tables. For non-table objects, an
10811 : : * error will be thrown later via
10812 : : * preprocess_pubobj_list().
10813 : : */
1343 akapila@postgresql.o 10814 : 21 : $$->pubtable = makeNode(PublicationTable);
10815 : 21 : $$->pubtable->relation = makeRangeVar(NULL, $1, @1);
1311 tomas.vondra@postgre 10816 : 21 : $$->pubtable->columns = $2;
10817 : 21 : $$->pubtable->whereClause = $3;
10818 : : }
10819 : : else
10820 : : {
1343 akapila@postgresql.o 10821 : 44 : $$->name = $1;
10822 : : }
1461 10823 : 65 : $$->location = @1;
10824 : : }
10825 : : | ColId indirection opt_column_list OptWhereClause
10826 : : {
10827 : 16 : $$ = makeNode(PublicationObjSpec);
10828 : 16 : $$->pubobjtype = PUBLICATIONOBJ_CONTINUATION;
10829 : 16 : $$->pubtable = makeNode(PublicationTable);
10830 : 16 : $$->pubtable->relation = makeRangeVarFromQualifiedName($1, $2, @1, yyscanner);
1311 tomas.vondra@postgre 10831 : 16 : $$->pubtable->columns = $3;
10832 : 16 : $$->pubtable->whereClause = $4;
1461 akapila@postgresql.o 10833 : 16 : $$->location = @1;
10834 : : }
10835 : : /* grammar like tablename * , ONLY tablename, ONLY ( tablename ) */
10836 : : | extended_relation_expr opt_column_list OptWhereClause
10837 : : {
10838 : 3 : $$ = makeNode(PublicationObjSpec);
10839 : 3 : $$->pubobjtype = PUBLICATIONOBJ_CONTINUATION;
10840 : 3 : $$->pubtable = makeNode(PublicationTable);
10841 : 3 : $$->pubtable->relation = $1;
1311 tomas.vondra@postgre 10842 : 3 : $$->pubtable->columns = $2;
10843 : 3 : $$->pubtable->whereClause = $3;
10844 : : }
10845 : : | CURRENT_SCHEMA
10846 : : {
1461 akapila@postgresql.o 10847 : 9 : $$ = makeNode(PublicationObjSpec);
10848 : 9 : $$->pubobjtype = PUBLICATIONOBJ_CONTINUATION;
10849 : 9 : $$->location = @1;
10850 : : }
10851 : : ;
10852 : :
10853 : : pub_obj_list: PublicationObjSpec
1512 alvherre@alvh.no-ip. 10854 : 824 : { $$ = list_make1($1); }
10855 : : | pub_obj_list ',' PublicationObjSpec
1461 akapila@postgresql.o 10856 : 127 : { $$ = lappend($1, $3); }
10857 : : ;
10858 : :
10859 : : PublicationAllObjSpec:
10860 : : ALL TABLES
10861 : : {
18 akapila@postgresql.o 10862 :GNC 66 : $$ = makeNode(PublicationAllObjSpec);
10863 : 66 : $$->pubobjtype = PUBLICATION_ALL_TABLES;
10864 : 66 : $$->location = @1;
10865 : : }
10866 : : | ALL SEQUENCES
10867 : : {
10868 : 27 : $$ = makeNode(PublicationAllObjSpec);
10869 : 27 : $$->pubobjtype = PUBLICATION_ALL_SEQUENCES;
10870 : 27 : $$->location = @1;
10871 : : }
10872 : : ;
10873 : :
10874 : : pub_obj_type_list: PublicationAllObjSpec
10875 : 74 : { $$ = list_make1($1); }
10876 : : | pub_obj_type_list ',' PublicationAllObjSpec
10877 : 19 : { $$ = lappend($1, $3); }
10878 : : ;
10879 : :
10880 : :
10881 : : /*****************************************************************************
10882 : : *
10883 : : * ALTER PUBLICATION name SET ( options )
10884 : : *
10885 : : * ALTER PUBLICATION name ADD pub_obj [, ...]
10886 : : *
10887 : : * ALTER PUBLICATION name DROP pub_obj [, ...]
10888 : : *
10889 : : * ALTER PUBLICATION name SET pub_obj [, ...]
10890 : : *
10891 : : * pub_obj is one of:
10892 : : *
10893 : : * TABLE table_name [, ...]
10894 : : * TABLES IN SCHEMA schema_name [, ...]
10895 : : *
10896 : : *****************************************************************************/
10897 : :
10898 : : AlterPublicationStmt:
10899 : : ALTER PUBLICATION name SET definition
10900 : : {
3203 peter_e@gmx.net 10901 :CBC 58 : AlterPublicationStmt *n = makeNode(AlterPublicationStmt);
10902 : :
10903 : 58 : n->pubname = $3;
10904 : 58 : n->options = $5;
1263 peter@eisentraut.org 10905 : 58 : $$ = (Node *) n;
10906 : : }
10907 : : | ALTER PUBLICATION name ADD_P pub_obj_list
10908 : : {
3203 peter_e@gmx.net 10909 : 185 : AlterPublicationStmt *n = makeNode(AlterPublicationStmt);
10910 : :
10911 : 185 : n->pubname = $3;
1461 akapila@postgresql.o 10912 : 185 : n->pubobjects = $5;
10913 : 185 : preprocess_pubobj_list(n->pubobjects, yyscanner);
1393 alvherre@alvh.no-ip. 10914 : 182 : n->action = AP_AddObjects;
1263 peter@eisentraut.org 10915 : 182 : $$ = (Node *) n;
10916 : : }
10917 : : | ALTER PUBLICATION name SET pub_obj_list
10918 : : {
3203 peter_e@gmx.net 10919 : 232 : AlterPublicationStmt *n = makeNode(AlterPublicationStmt);
10920 : :
10921 : 232 : n->pubname = $3;
1461 akapila@postgresql.o 10922 : 232 : n->pubobjects = $5;
10923 : 232 : preprocess_pubobj_list(n->pubobjects, yyscanner);
1393 alvherre@alvh.no-ip. 10924 : 232 : n->action = AP_SetObjects;
1263 peter@eisentraut.org 10925 : 232 : $$ = (Node *) n;
10926 : : }
10927 : : | ALTER PUBLICATION name DROP pub_obj_list
10928 : : {
3203 peter_e@gmx.net 10929 : 78 : AlterPublicationStmt *n = makeNode(AlterPublicationStmt);
10930 : :
10931 : 78 : n->pubname = $3;
1461 akapila@postgresql.o 10932 : 78 : n->pubobjects = $5;
10933 : 78 : preprocess_pubobj_list(n->pubobjects, yyscanner);
1393 alvherre@alvh.no-ip. 10934 : 78 : n->action = AP_DropObjects;
1263 peter@eisentraut.org 10935 : 78 : $$ = (Node *) n;
10936 : : }
10937 : : ;
10938 : :
10939 : : /*****************************************************************************
10940 : : *
10941 : : * CREATE SUBSCRIPTION name ...
10942 : : *
10943 : : *****************************************************************************/
10944 : :
10945 : : CreateSubscriptionStmt:
10946 : : CREATE SUBSCRIPTION name CONNECTION Sconst PUBLICATION name_list opt_definition
10947 : : {
10948 : : CreateSubscriptionStmt *n =
3203 peter_e@gmx.net 10949 : 240 : makeNode(CreateSubscriptionStmt);
10950 : 240 : n->subname = $3;
10951 : 240 : n->conninfo = $5;
10952 : 240 : n->publication = $7;
10953 : 240 : n->options = $8;
1263 peter@eisentraut.org 10954 : 240 : $$ = (Node *) n;
10955 : : }
10956 : : ;
10957 : :
10958 : : /*****************************************************************************
10959 : : *
10960 : : * ALTER SUBSCRIPTION name ...
10961 : : *
10962 : : *****************************************************************************/
10963 : :
10964 : : AlterSubscriptionStmt:
10965 : : ALTER SUBSCRIPTION name SET definition
10966 : : {
10967 : : AlterSubscriptionStmt *n =
3203 peter_e@gmx.net 10968 : 109 : makeNode(AlterSubscriptionStmt);
10969 : :
3140 10970 : 109 : n->kind = ALTER_SUBSCRIPTION_OPTIONS;
3203 10971 : 109 : n->subname = $3;
10972 : 109 : n->options = $5;
1263 peter@eisentraut.org 10973 : 109 : $$ = (Node *) n;
10974 : : }
10975 : : | ALTER SUBSCRIPTION name CONNECTION Sconst
10976 : : {
10977 : : AlterSubscriptionStmt *n =
3203 peter_e@gmx.net 10978 : 13 : makeNode(AlterSubscriptionStmt);
10979 : :
3140 10980 : 13 : n->kind = ALTER_SUBSCRIPTION_CONNECTION;
3203 10981 : 13 : n->subname = $3;
3140 10982 : 13 : n->conninfo = $5;
1263 peter@eisentraut.org 10983 : 13 : $$ = (Node *) n;
10984 : : }
10985 : : | ALTER SUBSCRIPTION name REFRESH PUBLICATION opt_definition
10986 : : {
10987 : : AlterSubscriptionStmt *n =
3140 peter_e@gmx.net 10988 : 31 : makeNode(AlterSubscriptionStmt);
10989 : :
12 akapila@postgresql.o 10990 :GNC 31 : n->kind = ALTER_SUBSCRIPTION_REFRESH_PUBLICATION;
3140 peter_e@gmx.net 10991 :CBC 31 : n->subname = $3;
10992 : 31 : n->options = $6;
1263 peter@eisentraut.org 10993 : 31 : $$ = (Node *) n;
10994 : : }
10995 : : | ALTER SUBSCRIPTION name REFRESH SEQUENCES
10996 : : {
10997 : : AlterSubscriptionStmt *n =
4 akapila@postgresql.o 10998 :UNC 0 : makeNode(AlterSubscriptionStmt);
10999 : :
11000 : 0 : n->kind = ALTER_SUBSCRIPTION_REFRESH_SEQUENCES;
11001 : 0 : n->subname = $3;
11002 : 0 : $$ = (Node *) n;
11003 : : }
11004 : : | ALTER SUBSCRIPTION name ADD_P PUBLICATION name_list opt_definition
11005 : : {
11006 : : AlterSubscriptionStmt *n =
1665 peter@eisentraut.org 11007 :CBC 14 : makeNode(AlterSubscriptionStmt);
11008 : :
11009 : 14 : n->kind = ALTER_SUBSCRIPTION_ADD_PUBLICATION;
11010 : 14 : n->subname = $3;
11011 : 14 : n->publication = $6;
11012 : 14 : n->options = $7;
1263 11013 : 14 : $$ = (Node *) n;
11014 : : }
11015 : : | ALTER SUBSCRIPTION name DROP PUBLICATION name_list opt_definition
11016 : : {
11017 : : AlterSubscriptionStmt *n =
1665 11018 : 13 : makeNode(AlterSubscriptionStmt);
11019 : :
11020 : 13 : n->kind = ALTER_SUBSCRIPTION_DROP_PUBLICATION;
11021 : 13 : n->subname = $3;
11022 : 13 : n->publication = $6;
11023 : 13 : n->options = $7;
1263 11024 : 13 : $$ = (Node *) n;
11025 : : }
11026 : : | ALTER SUBSCRIPTION name SET PUBLICATION name_list opt_definition
11027 : : {
11028 : : AlterSubscriptionStmt *n =
3203 peter_e@gmx.net 11029 : 22 : makeNode(AlterSubscriptionStmt);
11030 : :
1665 peter@eisentraut.org 11031 : 22 : n->kind = ALTER_SUBSCRIPTION_SET_PUBLICATION;
3203 peter_e@gmx.net 11032 : 22 : n->subname = $3;
3140 11033 : 22 : n->publication = $6;
3066 11034 : 22 : n->options = $7;
1263 peter@eisentraut.org 11035 : 22 : $$ = (Node *) n;
11036 : : }
11037 : : | ALTER SUBSCRIPTION name ENABLE_P
11038 : : {
11039 : : AlterSubscriptionStmt *n =
3203 peter_e@gmx.net 11040 : 29 : makeNode(AlterSubscriptionStmt);
11041 : :
3140 11042 : 29 : n->kind = ALTER_SUBSCRIPTION_ENABLED;
3203 11043 : 29 : n->subname = $3;
11044 : 29 : n->options = list_make1(makeDefElem("enabled",
11045 : : (Node *) makeBoolean(true), @1));
1263 peter@eisentraut.org 11046 : 29 : $$ = (Node *) n;
11047 : : }
11048 : : | ALTER SUBSCRIPTION name DISABLE_P
11049 : : {
11050 : : AlterSubscriptionStmt *n =
3203 peter_e@gmx.net 11051 : 21 : makeNode(AlterSubscriptionStmt);
11052 : :
3140 11053 : 21 : n->kind = ALTER_SUBSCRIPTION_ENABLED;
3203 11054 : 21 : n->subname = $3;
11055 : 21 : n->options = list_make1(makeDefElem("enabled",
11056 : : (Node *) makeBoolean(false), @1));
1263 peter@eisentraut.org 11057 : 21 : $$ = (Node *) n;
11058 : : }
11059 : : | ALTER SUBSCRIPTION name SKIP definition
11060 : : {
11061 : : AlterSubscriptionStmt *n =
1315 akapila@postgresql.o 11062 : 12 : makeNode(AlterSubscriptionStmt);
11063 : :
11064 : 12 : n->kind = ALTER_SUBSCRIPTION_SKIP;
11065 : 12 : n->subname = $3;
11066 : 12 : n->options = $5;
1263 peter@eisentraut.org 11067 : 12 : $$ = (Node *) n;
11068 : : }
11069 : : ;
11070 : :
11071 : : /*****************************************************************************
11072 : : *
11073 : : * DROP SUBSCRIPTION [ IF EXISTS ] name
11074 : : *
11075 : : *****************************************************************************/
11076 : :
11077 : : DropSubscriptionStmt: DROP SUBSCRIPTION name opt_drop_behavior
11078 : : {
3203 peter_e@gmx.net 11079 : 120 : DropSubscriptionStmt *n = makeNode(DropSubscriptionStmt);
11080 : :
11081 : 120 : n->subname = $3;
11082 : 120 : n->missing_ok = false;
3093 11083 : 120 : n->behavior = $4;
3203 11084 : 120 : $$ = (Node *) n;
11085 : : }
11086 : : | DROP SUBSCRIPTION IF_P EXISTS name opt_drop_behavior
11087 : : {
11088 : 3 : DropSubscriptionStmt *n = makeNode(DropSubscriptionStmt);
11089 : :
11090 : 3 : n->subname = $5;
11091 : 3 : n->missing_ok = true;
3093 11092 : 3 : n->behavior = $6;
3203 11093 : 3 : $$ = (Node *) n;
11094 : : }
11095 : : ;
11096 : :
11097 : : /*****************************************************************************
11098 : : *
11099 : : * QUERY: Define Rewrite Rule
11100 : : *
11101 : : *****************************************************************************/
11102 : :
11103 : : RuleStmt: CREATE opt_or_replace RULE name AS
11104 : : ON event TO qualified_name where_clause
11105 : : DO opt_instead RuleActionList
11106 : : {
1263 peter@eisentraut.org 11107 : 546 : RuleStmt *n = makeNode(RuleStmt);
11108 : :
8456 tgl@sss.pgh.pa.us 11109 : 546 : n->replace = $2;
5835 11110 : 546 : n->relation = $9;
8456 11111 : 546 : n->rulename = $4;
5835 11112 : 546 : n->whereClause = $10;
11113 : 546 : n->event = $7;
11114 : 546 : n->instead = $12;
11115 : 546 : n->actions = $13;
1263 peter@eisentraut.org 11116 : 546 : $$ = (Node *) n;
11117 : : }
11118 : : ;
11119 : :
11120 : : RuleActionList:
8533 bruce@momjian.us 11121 : 81 : NOTHING { $$ = NIL; }
7820 neilc@samurai.com 11122 : 442 : | RuleActionStmt { $$ = list_make1($1); }
8533 bruce@momjian.us 11123 : 23 : | '(' RuleActionMulti ')' { $$ = $2; }
11124 : : ;
11125 : :
11126 : : /* the thrashing around here is to discard "empty" statements... */
11127 : : RuleActionMulti:
11128 : : RuleActionMulti ';' RuleActionStmtOrEmpty
7964 neilc@samurai.com 11129 [ + + ]: 31 : { if ($3 != NULL)
9130 bruce@momjian.us 11130 : 23 : $$ = lappend($1, $3);
11131 : : else
9517 tgl@sss.pgh.pa.us 11132 : 8 : $$ = $1;
11133 : : }
11134 : : | RuleActionStmtOrEmpty
7964 neilc@samurai.com 11135 [ + - ]: 23 : { if ($1 != NULL)
7820 11136 : 23 : $$ = list_make1($1);
11137 : : else
9517 tgl@sss.pgh.pa.us 11138 :UBC 0 : $$ = NIL;
11139 : : }
11140 : : ;
11141 : :
11142 : : RuleActionStmt:
11143 : : SelectStmt
11144 : : | InsertStmt
11145 : : | UpdateStmt
11146 : : | DeleteStmt
11147 : : | NotifyStmt
11148 : : ;
11149 : :
11150 : : RuleActionStmtOrEmpty:
8533 bruce@momjian.us 11151 :CBC 46 : RuleActionStmt { $$ = $1; }
7964 neilc@samurai.com 11152 : 8 : | /*EMPTY*/ { $$ = NULL; }
11153 : : ;
11154 : :
8533 bruce@momjian.us 11155 : 9 : event: SELECT { $$ = CMD_SELECT; }
11156 : 216 : | UPDATE { $$ = CMD_UPDATE; }
11157 : 82 : | DELETE_P { $$ = CMD_DELETE; }
11158 : 239 : | INSERT { $$ = CMD_INSERT; }
11159 : : ;
11160 : :
11161 : : opt_instead:
2994 peter_e@gmx.net 11162 : 376 : INSTEAD { $$ = true; }
11163 : 78 : | ALSO { $$ = false; }
11164 : 92 : | /*EMPTY*/ { $$ = false; }
11165 : : ;
11166 : :
11167 : :
11168 : : /*****************************************************************************
11169 : : *
11170 : : * QUERY:
11171 : : * NOTIFY <identifier> can appear both in rule bodies and
11172 : : * as a query-level command
11173 : : *
11174 : : *****************************************************************************/
11175 : :
11176 : : NotifyStmt: NOTIFY ColId notify_payload
11177 : : {
10276 bruce@momjian.us 11178 : 64 : NotifyStmt *n = makeNode(NotifyStmt);
11179 : :
6265 tgl@sss.pgh.pa.us 11180 : 64 : n->conditionname = $2;
5732 11181 : 64 : n->payload = $3;
1263 peter@eisentraut.org 11182 : 64 : $$ = (Node *) n;
11183 : : }
11184 : : ;
11185 : :
11186 : : notify_payload:
5732 tgl@sss.pgh.pa.us 11187 : 31 : ',' Sconst { $$ = $2; }
11188 : 33 : | /*EMPTY*/ { $$ = NULL; }
11189 : : ;
11190 : :
11191 : : ListenStmt: LISTEN ColId
11192 : : {
10276 bruce@momjian.us 11193 : 37 : ListenStmt *n = makeNode(ListenStmt);
11194 : :
6265 tgl@sss.pgh.pa.us 11195 : 37 : n->conditionname = $2;
1263 peter@eisentraut.org 11196 : 37 : $$ = (Node *) n;
11197 : : }
11198 : : ;
11199 : :
11200 : : UnlistenStmt:
11201 : : UNLISTEN ColId
11202 : : {
9925 scrappy@hub.org 11203 : 3 : UnlistenStmt *n = makeNode(UnlistenStmt);
11204 : :
6265 tgl@sss.pgh.pa.us 11205 : 3 : n->conditionname = $2;
1263 peter@eisentraut.org 11206 : 3 : $$ = (Node *) n;
11207 : : }
11208 : : | UNLISTEN '*'
11209 : : {
9880 lockhart@fourpalms.o 11210 : 16 : UnlistenStmt *n = makeNode(UnlistenStmt);
11211 : :
6265 tgl@sss.pgh.pa.us 11212 : 16 : n->conditionname = NULL;
1263 peter@eisentraut.org 11213 : 16 : $$ = (Node *) n;
11214 : : }
11215 : : ;
11216 : :
11217 : :
11218 : : /*****************************************************************************
11219 : : *
11220 : : * Transactions:
11221 : : *
11222 : : * BEGIN / COMMIT / ROLLBACK
11223 : : * (also older versions END / ABORT)
11224 : : *
11225 : : *****************************************************************************/
11226 : :
11227 : : TransactionStmt:
11228 : : ABORT_P opt_transaction opt_transaction_chain
11229 : : {
10276 bruce@momjian.us 11230 : 116 : TransactionStmt *n = makeNode(TransactionStmt);
11231 : :
8295 tgl@sss.pgh.pa.us 11232 : 116 : n->kind = TRANS_STMT_ROLLBACK;
8485 bruce@momjian.us 11233 : 116 : n->options = NIL;
2409 peter@eisentraut.org 11234 : 116 : n->chain = $3;
823 michael@paquier.xyz 11235 : 116 : n->location = -1;
1263 peter@eisentraut.org 11236 : 116 : $$ = (Node *) n;
11237 : : }
11238 : : | START TRANSACTION transaction_mode_list_or_empty
11239 : : {
10276 bruce@momjian.us 11240 : 822 : TransactionStmt *n = makeNode(TransactionStmt);
11241 : :
8295 tgl@sss.pgh.pa.us 11242 : 822 : n->kind = TRANS_STMT_START;
8485 bruce@momjian.us 11243 : 822 : n->options = $3;
823 michael@paquier.xyz 11244 : 822 : n->location = -1;
1263 peter@eisentraut.org 11245 : 822 : $$ = (Node *) n;
11246 : : }
11247 : : | COMMIT opt_transaction opt_transaction_chain
11248 : : {
9213 lockhart@fourpalms.o 11249 : 5975 : TransactionStmt *n = makeNode(TransactionStmt);
11250 : :
8295 tgl@sss.pgh.pa.us 11251 : 5975 : n->kind = TRANS_STMT_COMMIT;
8485 bruce@momjian.us 11252 : 5975 : n->options = NIL;
2409 peter@eisentraut.org 11253 : 5975 : n->chain = $3;
823 michael@paquier.xyz 11254 : 5975 : n->location = -1;
1263 peter@eisentraut.org 11255 : 5975 : $$ = (Node *) n;
11256 : : }
11257 : : | ROLLBACK opt_transaction opt_transaction_chain
11258 : : {
10276 bruce@momjian.us 11259 : 1327 : TransactionStmt *n = makeNode(TransactionStmt);
11260 : :
8295 tgl@sss.pgh.pa.us 11261 : 1327 : n->kind = TRANS_STMT_ROLLBACK;
8485 bruce@momjian.us 11262 : 1327 : n->options = NIL;
2409 peter@eisentraut.org 11263 : 1327 : n->chain = $3;
823 michael@paquier.xyz 11264 : 1327 : n->location = -1;
1263 peter@eisentraut.org 11265 : 1327 : $$ = (Node *) n;
11266 : : }
11267 : : | SAVEPOINT ColId
11268 : : {
7762 tgl@sss.pgh.pa.us 11269 : 989 : TransactionStmt *n = makeNode(TransactionStmt);
11270 : :
11271 : 989 : n->kind = TRANS_STMT_SAVEPOINT;
2810 peter_e@gmx.net 11272 : 989 : n->savepoint_name = $2;
823 michael@paquier.xyz 11273 : 989 : n->location = @2;
1263 peter@eisentraut.org 11274 : 989 : $$ = (Node *) n;
11275 : : }
11276 : : | RELEASE SAVEPOINT ColId
11277 : : {
7746 tgl@sss.pgh.pa.us 11278 : 104 : TransactionStmt *n = makeNode(TransactionStmt);
11279 : :
11280 : 104 : n->kind = TRANS_STMT_RELEASE;
2810 peter_e@gmx.net 11281 : 104 : n->savepoint_name = $3;
823 michael@paquier.xyz 11282 : 104 : n->location = @3;
1263 peter@eisentraut.org 11283 : 104 : $$ = (Node *) n;
11284 : : }
11285 : : | RELEASE ColId
11286 : : {
7762 tgl@sss.pgh.pa.us 11287 : 47 : TransactionStmt *n = makeNode(TransactionStmt);
11288 : :
11289 : 47 : n->kind = TRANS_STMT_RELEASE;
2810 peter_e@gmx.net 11290 : 47 : n->savepoint_name = $2;
823 michael@paquier.xyz 11291 : 47 : n->location = @2;
1263 peter@eisentraut.org 11292 : 47 : $$ = (Node *) n;
11293 : : }
11294 : : | ROLLBACK opt_transaction TO SAVEPOINT ColId
11295 : : {
7762 tgl@sss.pgh.pa.us 11296 : 115 : TransactionStmt *n = makeNode(TransactionStmt);
11297 : :
11298 : 115 : n->kind = TRANS_STMT_ROLLBACK_TO;
2810 peter_e@gmx.net 11299 : 115 : n->savepoint_name = $5;
823 michael@paquier.xyz 11300 : 115 : n->location = @5;
1263 peter@eisentraut.org 11301 : 115 : $$ = (Node *) n;
11302 : : }
11303 : : | ROLLBACK opt_transaction TO ColId
11304 : : {
7746 tgl@sss.pgh.pa.us 11305 : 256 : TransactionStmt *n = makeNode(TransactionStmt);
11306 : :
11307 : 256 : n->kind = TRANS_STMT_ROLLBACK_TO;
2810 peter_e@gmx.net 11308 : 256 : n->savepoint_name = $4;
823 michael@paquier.xyz 11309 : 256 : n->location = @4;
1263 peter@eisentraut.org 11310 : 256 : $$ = (Node *) n;
11311 : : }
11312 : : | PREPARE TRANSACTION Sconst
11313 : : {
7437 tgl@sss.pgh.pa.us 11314 : 324 : TransactionStmt *n = makeNode(TransactionStmt);
11315 : :
11316 : 324 : n->kind = TRANS_STMT_PREPARE;
11317 : 324 : n->gid = $3;
807 michael@paquier.xyz 11318 : 324 : n->location = @3;
1263 peter@eisentraut.org 11319 : 324 : $$ = (Node *) n;
11320 : : }
11321 : : | COMMIT PREPARED Sconst
11322 : : {
7437 tgl@sss.pgh.pa.us 11323 : 239 : TransactionStmt *n = makeNode(TransactionStmt);
11324 : :
11325 : 239 : n->kind = TRANS_STMT_COMMIT_PREPARED;
11326 : 239 : n->gid = $3;
807 michael@paquier.xyz 11327 : 239 : n->location = @3;
1263 peter@eisentraut.org 11328 : 239 : $$ = (Node *) n;
11329 : : }
11330 : : | ROLLBACK PREPARED Sconst
11331 : : {
7437 tgl@sss.pgh.pa.us 11332 : 39 : TransactionStmt *n = makeNode(TransactionStmt);
11333 : :
11334 : 39 : n->kind = TRANS_STMT_ROLLBACK_PREPARED;
11335 : 39 : n->gid = $3;
807 michael@paquier.xyz 11336 : 39 : n->location = @3;
1263 peter@eisentraut.org 11337 : 39 : $$ = (Node *) n;
11338 : : }
11339 : : ;
11340 : :
11341 : : TransactionStmtLegacy:
11342 : : BEGIN_P opt_transaction transaction_mode_list_or_empty
11343 : : {
1664 11344 : 7267 : TransactionStmt *n = makeNode(TransactionStmt);
11345 : :
11346 : 7267 : n->kind = TRANS_STMT_BEGIN;
11347 : 7267 : n->options = $3;
823 michael@paquier.xyz 11348 : 7267 : n->location = -1;
1263 peter@eisentraut.org 11349 : 7267 : $$ = (Node *) n;
11350 : : }
11351 : : | END_P opt_transaction opt_transaction_chain
11352 : : {
1664 11353 : 185 : TransactionStmt *n = makeNode(TransactionStmt);
11354 : :
11355 : 185 : n->kind = TRANS_STMT_COMMIT;
11356 : 185 : n->options = NIL;
11357 : 185 : n->chain = $3;
823 michael@paquier.xyz 11358 : 185 : n->location = -1;
1263 peter@eisentraut.org 11359 : 185 : $$ = (Node *) n;
11360 : : }
11361 : : ;
11362 : :
11363 : : opt_transaction: WORK
11364 : : | TRANSACTION
11365 : : | /*EMPTY*/
11366 : : ;
11367 : :
11368 : : transaction_mode_item:
11369 : : ISOLATION LEVEL iso_level
7746 tgl@sss.pgh.pa.us 11370 : 3446 : { $$ = makeDefElem("transaction_isolation",
3338 peter_e@gmx.net 11371 : 3446 : makeStringConst($3, @3), @1); }
11372 : : | READ ONLY
7746 tgl@sss.pgh.pa.us 11373 : 714 : { $$ = makeDefElem("transaction_read_only",
2994 peter_e@gmx.net 11374 : 714 : makeIntConst(true, @1), @1); }
11375 : : | READ WRITE
7746 tgl@sss.pgh.pa.us 11376 : 45 : { $$ = makeDefElem("transaction_read_only",
2994 peter_e@gmx.net 11377 : 45 : makeIntConst(false, @1), @1); }
11378 : : | DEFERRABLE
5376 heikki.linnakangas@i 11379 : 22 : { $$ = makeDefElem("transaction_deferrable",
11380 : : makeIntConst(true, @1), @1); }
11381 : : | NOT DEFERRABLE
11382 : 5 : { $$ = makeDefElem("transaction_deferrable",
2994 peter_e@gmx.net 11383 : 5 : makeIntConst(false, @1), @1); }
11384 : : ;
11385 : :
11386 : : /* Syntax with commas is SQL-spec, without commas is Postgres historical */
11387 : : transaction_mode_list:
11388 : : transaction_mode_item
7746 tgl@sss.pgh.pa.us 11389 : 3554 : { $$ = list_make1($1); }
11390 : : | transaction_mode_list ',' transaction_mode_item
11391 : 478 : { $$ = lappend($1, $3); }
11392 : : | transaction_mode_list transaction_mode_item
11393 : 200 : { $$ = lappend($1, $2); }
11394 : : ;
11395 : :
11396 : : transaction_mode_list_or_empty:
11397 : : transaction_mode_list
11398 : : | /* EMPTY */
8326 peter_e@gmx.net 11399 : 4842 : { $$ = NIL; }
11400 : : ;
11401 : :
11402 : : opt_transaction_chain:
2409 peter@eisentraut.org 11403 : 60 : AND CHAIN { $$ = true; }
11404 : 1 : | AND NO CHAIN { $$ = false; }
11405 : 7542 : | /* EMPTY */ { $$ = false; }
11406 : : ;
11407 : :
11408 : :
11409 : : /*****************************************************************************
11410 : : *
11411 : : * QUERY:
11412 : : * CREATE [ OR REPLACE ] [ TEMP ] VIEW <viewname> '('target-list ')'
11413 : : * AS <query> [ WITH [ CASCADED | LOCAL ] CHECK OPTION ]
11414 : : *
11415 : : *****************************************************************************/
11416 : :
11417 : : ViewStmt: CREATE OptTemp VIEW qualified_name opt_column_list opt_reloptions
11418 : : AS SelectStmt opt_check_option
11419 : : {
1263 11420 : 8404 : ViewStmt *n = makeNode(ViewStmt);
11421 : :
8456 tgl@sss.pgh.pa.us 11422 : 8404 : n->view = $4;
5432 rhaas@postgresql.org 11423 : 8404 : n->view->relpersistence = $2;
8456 tgl@sss.pgh.pa.us 11424 : 8404 : n->aliases = $5;
5058 rhaas@postgresql.org 11425 : 8404 : n->query = $8;
6803 tgl@sss.pgh.pa.us 11426 : 8404 : n->replace = false;
5058 rhaas@postgresql.org 11427 : 8404 : n->options = $6;
4484 sfrost@snowman.net 11428 : 8404 : n->withCheckOption = $9;
7572 neilc@samurai.com 11429 : 8404 : $$ = (Node *) n;
11430 : : }
11431 : : | CREATE OR REPLACE OptTemp VIEW qualified_name opt_column_list opt_reloptions
11432 : : AS SelectStmt opt_check_option
11433 : : {
1263 peter@eisentraut.org 11434 : 122 : ViewStmt *n = makeNode(ViewStmt);
11435 : :
7572 neilc@samurai.com 11436 : 122 : n->view = $6;
5432 rhaas@postgresql.org 11437 : 122 : n->view->relpersistence = $4;
7572 neilc@samurai.com 11438 : 122 : n->aliases = $7;
5058 rhaas@postgresql.org 11439 : 122 : n->query = $10;
6803 tgl@sss.pgh.pa.us 11440 : 122 : n->replace = true;
5058 rhaas@postgresql.org 11441 : 122 : n->options = $8;
4484 sfrost@snowman.net 11442 : 122 : n->withCheckOption = $11;
7572 neilc@samurai.com 11443 : 122 : $$ = (Node *) n;
11444 : : }
11445 : : | CREATE OptTemp RECURSIVE VIEW qualified_name '(' columnList ')' opt_reloptions
11446 : : AS SelectStmt opt_check_option
11447 : : {
1263 peter@eisentraut.org 11448 : 4 : ViewStmt *n = makeNode(ViewStmt);
11449 : :
4652 peter_e@gmx.net 11450 : 4 : n->view = $5;
11451 : 4 : n->view->relpersistence = $2;
11452 : 4 : n->aliases = $7;
11453 : 4 : n->query = makeRecursiveViewSelect(n->view->relname, n->aliases, $11);
11454 : 4 : n->replace = false;
11455 : 4 : n->options = $9;
4484 sfrost@snowman.net 11456 : 4 : n->withCheckOption = $12;
11457 [ - + ]: 4 : if (n->withCheckOption != NO_CHECK_OPTION)
4484 sfrost@snowman.net 11458 [ # # ]:UBC 0 : ereport(ERROR,
11459 : : (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
11460 : : errmsg("WITH CHECK OPTION not supported on recursive views"),
11461 : : parser_errposition(@12)));
4652 peter_e@gmx.net 11462 :CBC 4 : $$ = (Node *) n;
11463 : : }
11464 : : | CREATE OR REPLACE OptTemp RECURSIVE VIEW qualified_name '(' columnList ')' opt_reloptions
11465 : : AS SelectStmt opt_check_option
11466 : : {
1263 peter@eisentraut.org 11467 : 3 : ViewStmt *n = makeNode(ViewStmt);
11468 : :
4652 peter_e@gmx.net 11469 : 3 : n->view = $7;
11470 : 3 : n->view->relpersistence = $4;
11471 : 3 : n->aliases = $9;
11472 : 3 : n->query = makeRecursiveViewSelect(n->view->relname, n->aliases, $13);
11473 : 3 : n->replace = true;
11474 : 3 : n->options = $11;
4484 sfrost@snowman.net 11475 : 3 : n->withCheckOption = $14;
11476 [ - + ]: 3 : if (n->withCheckOption != NO_CHECK_OPTION)
4484 sfrost@snowman.net 11477 [ # # ]:UBC 0 : ereport(ERROR,
11478 : : (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
11479 : : errmsg("WITH CHECK OPTION not supported on recursive views"),
11480 : : parser_errposition(@14)));
4652 peter_e@gmx.net 11481 :CBC 3 : $$ = (Node *) n;
11482 : : }
11483 : : ;
11484 : :
11485 : : opt_check_option:
4484 sfrost@snowman.net 11486 : 48 : WITH CHECK OPTION { $$ = CASCADED_CHECK_OPTION; }
11487 : 3 : | WITH CASCADED CHECK OPTION { $$ = CASCADED_CHECK_OPTION; }
11488 : 12 : | WITH LOCAL CHECK OPTION { $$ = LOCAL_CHECK_OPTION; }
11489 : 8470 : | /* EMPTY */ { $$ = NO_CHECK_OPTION; }
11490 : : ;
11491 : :
11492 : : /*****************************************************************************
11493 : : *
11494 : : * QUERY:
11495 : : * LOAD "filename"
11496 : : *
11497 : : *****************************************************************************/
11498 : :
11499 : : LoadStmt: LOAD file_name
11500 : : {
1263 peter@eisentraut.org 11501 : 32 : LoadStmt *n = makeNode(LoadStmt);
11502 : :
10276 bruce@momjian.us 11503 : 32 : n->filename = $2;
1263 peter@eisentraut.org 11504 : 32 : $$ = (Node *) n;
11505 : : }
11506 : : ;
11507 : :
11508 : :
11509 : : /*****************************************************************************
11510 : : *
11511 : : * CREATE DATABASE
11512 : : *
11513 : : *****************************************************************************/
11514 : :
11515 : : CreatedbStmt:
11516 : : CREATE DATABASE name opt_with createdb_opt_list
11517 : : {
9133 tgl@sss.pgh.pa.us 11518 : 398 : CreatedbStmt *n = makeNode(CreatedbStmt);
11519 : :
10276 bruce@momjian.us 11520 : 398 : n->dbname = $3;
8532 11521 : 398 : n->options = $5;
1263 peter@eisentraut.org 11522 : 398 : $$ = (Node *) n;
11523 : : }
11524 : : ;
11525 : :
11526 : : createdb_opt_list:
4136 tgl@sss.pgh.pa.us 11527 : 324 : createdb_opt_items { $$ = $1; }
8532 bruce@momjian.us 11528 : 104 : | /* EMPTY */ { $$ = NIL; }
11529 : : ;
11530 : :
11531 : : createdb_opt_items:
4136 tgl@sss.pgh.pa.us 11532 : 324 : createdb_opt_item { $$ = list_make1($1); }
11533 : 479 : | createdb_opt_items createdb_opt_item { $$ = lappend($1, $2); }
11534 : : ;
11535 : :
11536 : : createdb_opt_item:
11537 : : createdb_opt_name opt_equal NumericOnly
11538 : : {
1088 11539 : 133 : $$ = makeDefElem($1, $3, @1);
11540 : : }
11541 : : | createdb_opt_name opt_equal opt_boolean_or_string
11542 : : {
1263 peter@eisentraut.org 11543 : 670 : $$ = makeDefElem($1, (Node *) makeString($3), @1);
11544 : : }
11545 : : | createdb_opt_name opt_equal DEFAULT
11546 : : {
3338 peter_e@gmx.net 11547 :UBC 0 : $$ = makeDefElem($1, NULL, @1);
11548 : : }
11549 : : ;
11550 : :
11551 : : /*
11552 : : * Ideally we'd use ColId here, but that causes shift/reduce conflicts against
11553 : : * the ALTER DATABASE SET/RESET syntaxes. Instead call out specific keywords
11554 : : * we need, and allow IDENT so that database option names don't have to be
11555 : : * parser keywords unless they are already keywords for other reasons.
11556 : : *
11557 : : * XXX this coding technique is fragile since if someone makes a formerly
11558 : : * non-keyword option name into a keyword and forgets to add it here, the
11559 : : * option will silently break. Best defense is to provide a regression test
11560 : : * exercising every such option, at least at the syntax level.
11561 : : */
11562 : : createdb_opt_name:
4136 tgl@sss.pgh.pa.us 11563 :CBC 556 : IDENT { $$ = $1; }
11564 : 1 : | CONNECTION LIMIT { $$ = pstrdup("connection_limit"); }
11565 : 52 : | ENCODING { $$ = pstrdup($1); }
4136 tgl@sss.pgh.pa.us 11566 :UBC 0 : | LOCATION { $$ = pstrdup($1); }
4136 tgl@sss.pgh.pa.us 11567 :CBC 1 : | OWNER { $$ = pstrdup($1); }
11568 : 17 : | TABLESPACE { $$ = pstrdup($1); }
11569 : 176 : | TEMPLATE { $$ = pstrdup($1); }
11570 : : ;
11571 : :
11572 : : /*
11573 : : * Though the equals sign doesn't match other WITH options, pg_dump uses
11574 : : * equals for backward compatibility, and it doesn't seem worth removing it.
11575 : : */
11576 : : opt_equal: '='
11577 : : | /*EMPTY*/
11578 : : ;
11579 : :
11580 : :
11581 : : /*****************************************************************************
11582 : : *
11583 : : * ALTER DATABASE
11584 : : *
11585 : : *****************************************************************************/
11586 : :
11587 : : AlterDatabaseStmt:
11588 : : ALTER DATABASE name WITH createdb_opt_list
11589 : : {
7393 tgl@sss.pgh.pa.us 11590 :UBC 0 : AlterDatabaseStmt *n = makeNode(AlterDatabaseStmt);
11591 : :
11592 : 0 : n->dbname = $3;
11593 : 0 : n->options = $5;
1263 peter@eisentraut.org 11594 : 0 : $$ = (Node *) n;
11595 : : }
11596 : : | ALTER DATABASE name createdb_opt_list
11597 : : {
4136 tgl@sss.pgh.pa.us 11598 :CBC 30 : AlterDatabaseStmt *n = makeNode(AlterDatabaseStmt);
11599 : :
11600 : 30 : n->dbname = $3;
11601 : 30 : n->options = $4;
1263 peter@eisentraut.org 11602 : 30 : $$ = (Node *) n;
11603 : : }
11604 : : | ALTER DATABASE name SET TABLESPACE name
11605 : : {
6198 tgl@sss.pgh.pa.us 11606 : 11 : AlterDatabaseStmt *n = makeNode(AlterDatabaseStmt);
11607 : :
11608 : 11 : n->dbname = $3;
11609 : 11 : n->options = list_make1(makeDefElem("tablespace",
11610 : : (Node *) makeString($6), @6));
1263 peter@eisentraut.org 11611 : 11 : $$ = (Node *) n;
11612 : : }
11613 : : | ALTER DATABASE name REFRESH COLLATION VERSION_P
11614 : : {
1351 11615 : 3 : AlterDatabaseRefreshCollStmt *n = makeNode(AlterDatabaseRefreshCollStmt);
11616 : :
11617 : 3 : n->dbname = $3;
1263 11618 : 3 : $$ = (Node *) n;
11619 : : }
11620 : : ;
11621 : :
11622 : : AlterDatabaseSetStmt:
11623 : : ALTER DATABASE name SetResetClause
11624 : : {
8641 peter_e@gmx.net 11625 : 579 : AlterDatabaseSetStmt *n = makeNode(AlterDatabaseSetStmt);
11626 : :
11627 : 579 : n->dbname = $3;
6629 tgl@sss.pgh.pa.us 11628 : 579 : n->setstmt = $4;
1263 peter@eisentraut.org 11629 : 579 : $$ = (Node *) n;
11630 : : }
11631 : : ;
11632 : :
11633 : :
11634 : : /*****************************************************************************
11635 : : *
11636 : : * DROP DATABASE [ IF EXISTS ] dbname [ [ WITH ] ( options ) ]
11637 : : *
11638 : : * This is implicitly CASCADE, no need for drop behavior
11639 : : *****************************************************************************/
11640 : :
11641 : : DropdbStmt: DROP DATABASE name
11642 : : {
8621 tgl@sss.pgh.pa.us 11643 : 50 : DropdbStmt *n = makeNode(DropdbStmt);
11644 : :
11645 : 50 : n->dbname = $3;
2994 peter_e@gmx.net 11646 : 50 : n->missing_ok = false;
2176 akapila@postgresql.o 11647 : 50 : n->options = NULL;
1263 peter@eisentraut.org 11648 : 50 : $$ = (Node *) n;
11649 : : }
11650 : : | DROP DATABASE IF_P EXISTS name
11651 : : {
7279 andrew@dunslane.net 11652 : 2 : DropdbStmt *n = makeNode(DropdbStmt);
11653 : :
11654 : 2 : n->dbname = $5;
2994 peter_e@gmx.net 11655 : 2 : n->missing_ok = true;
2176 akapila@postgresql.o 11656 : 2 : n->options = NULL;
1263 peter@eisentraut.org 11657 : 2 : $$ = (Node *) n;
11658 : : }
11659 : : | DROP DATABASE name opt_with '(' drop_option_list ')'
11660 : : {
2176 akapila@postgresql.o 11661 : 7 : DropdbStmt *n = makeNode(DropdbStmt);
11662 : :
11663 : 7 : n->dbname = $3;
11664 : 7 : n->missing_ok = false;
11665 : 7 : n->options = $6;
1263 peter@eisentraut.org 11666 : 7 : $$ = (Node *) n;
11667 : : }
11668 : : | DROP DATABASE IF_P EXISTS name opt_with '(' drop_option_list ')'
11669 : : {
2176 akapila@postgresql.o 11670 : 6 : DropdbStmt *n = makeNode(DropdbStmt);
11671 : :
11672 : 6 : n->dbname = $5;
11673 : 6 : n->missing_ok = true;
11674 : 6 : n->options = $8;
1263 peter@eisentraut.org 11675 : 6 : $$ = (Node *) n;
11676 : : }
11677 : : ;
11678 : :
11679 : : drop_option_list:
11680 : : drop_option
11681 : : {
2176 akapila@postgresql.o 11682 : 13 : $$ = list_make1((Node *) $1);
11683 : : }
11684 : : | drop_option_list ',' drop_option
11685 : : {
2176 akapila@postgresql.o 11686 :UBC 0 : $$ = lappend($1, (Node *) $3);
11687 : : }
11688 : : ;
11689 : :
11690 : : /*
11691 : : * Currently only the FORCE option is supported, but the syntax is designed
11692 : : * to be extensible so that we can add more options in the future if required.
11693 : : */
11694 : : drop_option:
11695 : : FORCE
11696 : : {
2176 akapila@postgresql.o 11697 :CBC 13 : $$ = makeDefElem("force", NULL, @1);
11698 : : }
11699 : : ;
11700 : :
11701 : : /*****************************************************************************
11702 : : *
11703 : : * ALTER COLLATION
11704 : : *
11705 : : *****************************************************************************/
11706 : :
11707 : : AlterCollationStmt: ALTER COLLATION any_name REFRESH VERSION_P
11708 : : {
1634 tmunro@postgresql.or 11709 : 3 : AlterCollationStmt *n = makeNode(AlterCollationStmt);
11710 : :
11711 : 3 : n->collname = $3;
1263 peter@eisentraut.org 11712 : 3 : $$ = (Node *) n;
11713 : : }
11714 : : ;
11715 : :
11716 : :
11717 : : /*****************************************************************************
11718 : : *
11719 : : * ALTER SYSTEM
11720 : : *
11721 : : * This is used to change configuration parameters persistently.
11722 : : *****************************************************************************/
11723 : :
11724 : : AlterSystemStmt:
11725 : : ALTER SYSTEM_P SET generic_set
11726 : : {
4331 ishii@postgresql.org 11727 : 73 : AlterSystemStmt *n = makeNode(AlterSystemStmt);
11728 : :
11729 : 73 : n->setstmt = $4;
1263 peter@eisentraut.org 11730 : 73 : $$ = (Node *) n;
11731 : : }
11732 : : | ALTER SYSTEM_P RESET generic_reset
11733 : : {
4073 fujii@postgresql.org 11734 : 31 : AlterSystemStmt *n = makeNode(AlterSystemStmt);
11735 : :
11736 : 31 : n->setstmt = $4;
1263 peter@eisentraut.org 11737 : 31 : $$ = (Node *) n;
11738 : : }
11739 : : ;
11740 : :
11741 : :
11742 : : /*****************************************************************************
11743 : : *
11744 : : * Manipulate a domain
11745 : : *
11746 : : *****************************************************************************/
11747 : :
11748 : : CreateDomainStmt:
11749 : : CREATE DOMAIN_P any_name opt_as Typename ColQualList
11750 : : {
8623 bruce@momjian.us 11751 : 732 : CreateDomainStmt *n = makeNode(CreateDomainStmt);
11752 : :
11753 : 732 : n->domainname = $3;
5947 peter_e@gmx.net 11754 : 732 : n->typeName = $5;
5346 tgl@sss.pgh.pa.us 11755 : 732 : SplitColQualList($6, &n->constraints, &n->collClause,
11756 : : yyscanner);
1263 peter@eisentraut.org 11757 : 732 : $$ = (Node *) n;
11758 : : }
11759 : : ;
11760 : :
11761 : : AlterDomainStmt:
11762 : : /* ALTER DOMAIN <domain> {SET DEFAULT <expr>|DROP DEFAULT} */
11763 : : ALTER DOMAIN_P any_name alter_column_default
11764 : : {
8361 bruce@momjian.us 11765 : 7 : AlterDomainStmt *n = makeNode(AlterDomainStmt);
11766 : :
116 michael@paquier.xyz 11767 :GNC 7 : n->subtype = AD_AlterDefault;
5947 peter_e@gmx.net 11768 :CBC 7 : n->typeName = $3;
8361 bruce@momjian.us 11769 : 7 : n->def = $4;
1263 peter@eisentraut.org 11770 : 7 : $$ = (Node *) n;
11771 : : }
11772 : : /* ALTER DOMAIN <domain> DROP NOT NULL */
11773 : : | ALTER DOMAIN_P any_name DROP NOT NULL_P
11774 : : {
8361 bruce@momjian.us 11775 : 6 : AlterDomainStmt *n = makeNode(AlterDomainStmt);
11776 : :
116 michael@paquier.xyz 11777 :GNC 6 : n->subtype = AD_DropNotNull;
5947 peter_e@gmx.net 11778 :CBC 6 : n->typeName = $3;
1263 peter@eisentraut.org 11779 : 6 : $$ = (Node *) n;
11780 : : }
11781 : : /* ALTER DOMAIN <domain> SET NOT NULL */
11782 : : | ALTER DOMAIN_P any_name SET NOT NULL_P
11783 : : {
8361 bruce@momjian.us 11784 : 12 : AlterDomainStmt *n = makeNode(AlterDomainStmt);
11785 : :
116 michael@paquier.xyz 11786 :GNC 12 : n->subtype = AD_SetNotNull;
5947 peter_e@gmx.net 11787 :CBC 12 : n->typeName = $3;
1263 peter@eisentraut.org 11788 : 12 : $$ = (Node *) n;
11789 : : }
11790 : : /* ALTER DOMAIN <domain> ADD CONSTRAINT ... */
11791 : : | ALTER DOMAIN_P any_name ADD_P DomainConstraint
11792 : : {
8361 bruce@momjian.us 11793 : 91 : AlterDomainStmt *n = makeNode(AlterDomainStmt);
11794 : :
116 michael@paquier.xyz 11795 :GNC 91 : n->subtype = AD_AddConstraint;
5947 peter_e@gmx.net 11796 :CBC 91 : n->typeName = $3;
8361 bruce@momjian.us 11797 : 91 : n->def = $5;
1263 peter@eisentraut.org 11798 : 91 : $$ = (Node *) n;
11799 : : }
11800 : : /* ALTER DOMAIN <domain> DROP CONSTRAINT <name> [RESTRICT|CASCADE] */
11801 : : | ALTER DOMAIN_P any_name DROP CONSTRAINT name opt_drop_behavior
11802 : : {
8361 bruce@momjian.us 11803 : 27 : AlterDomainStmt *n = makeNode(AlterDomainStmt);
11804 : :
116 michael@paquier.xyz 11805 :GNC 27 : n->subtype = AD_DropConstraint;
5947 peter_e@gmx.net 11806 :CBC 27 : n->typeName = $3;
8361 bruce@momjian.us 11807 : 27 : n->name = $6;
11808 : 27 : n->behavior = $7;
5044 peter_e@gmx.net 11809 : 27 : n->missing_ok = false;
1263 peter@eisentraut.org 11810 : 27 : $$ = (Node *) n;
11811 : : }
11812 : : /* ALTER DOMAIN <domain> DROP CONSTRAINT IF EXISTS <name> [RESTRICT|CASCADE] */
11813 : : | ALTER DOMAIN_P any_name DROP CONSTRAINT IF_P EXISTS name opt_drop_behavior
11814 : : {
5044 peter_e@gmx.net 11815 : 3 : AlterDomainStmt *n = makeNode(AlterDomainStmt);
11816 : :
116 michael@paquier.xyz 11817 :GNC 3 : n->subtype = AD_DropConstraint;
5044 peter_e@gmx.net 11818 :CBC 3 : n->typeName = $3;
11819 : 3 : n->name = $8;
11820 : 3 : n->behavior = $9;
11821 : 3 : n->missing_ok = true;
1263 peter@eisentraut.org 11822 : 3 : $$ = (Node *) n;
11823 : : }
11824 : : /* ALTER DOMAIN <domain> VALIDATE CONSTRAINT <name> */
11825 : : | ALTER DOMAIN_P any_name VALIDATE CONSTRAINT name
11826 : : {
5262 alvherre@alvh.no-ip. 11827 : 6 : AlterDomainStmt *n = makeNode(AlterDomainStmt);
11828 : :
116 michael@paquier.xyz 11829 :GNC 6 : n->subtype = AD_ValidateConstraint;
5262 alvherre@alvh.no-ip. 11830 :CBC 6 : n->typeName = $3;
11831 : 6 : n->name = $6;
1263 peter@eisentraut.org 11832 : 6 : $$ = (Node *) n;
11833 : : }
11834 : : ;
11835 : :
11836 : : opt_as: AS
11837 : : | /* EMPTY */
11838 : : ;
11839 : :
11840 : :
11841 : : /*****************************************************************************
11842 : : *
11843 : : * Manipulate a text search dictionary or configuration
11844 : : *
11845 : : *****************************************************************************/
11846 : :
11847 : : AlterTSDictionaryStmt:
11848 : : ALTER TEXT_P SEARCH DICTIONARY any_name definition
11849 : : {
6642 tgl@sss.pgh.pa.us 11850 : 20 : AlterTSDictionaryStmt *n = makeNode(AlterTSDictionaryStmt);
11851 : :
11852 : 20 : n->dictname = $5;
11853 : 20 : n->options = $6;
1263 peter@eisentraut.org 11854 : 20 : $$ = (Node *) n;
11855 : : }
11856 : : ;
11857 : :
11858 : : AlterTSConfigurationStmt:
11859 : : ALTER TEXT_P SEARCH CONFIGURATION any_name ADD_P MAPPING FOR name_list any_with any_name_list
11860 : : {
6642 tgl@sss.pgh.pa.us 11861 : 4259 : AlterTSConfigurationStmt *n = makeNode(AlterTSConfigurationStmt);
11862 : :
3822 alvherre@alvh.no-ip. 11863 : 4259 : n->kind = ALTER_TSCONFIG_ADD_MAPPING;
6642 tgl@sss.pgh.pa.us 11864 : 4259 : n->cfgname = $5;
11865 : 4259 : n->tokentype = $9;
11866 : 4259 : n->dicts = $11;
11867 : 4259 : n->override = false;
11868 : 4259 : n->replace = false;
1263 peter@eisentraut.org 11869 : 4259 : $$ = (Node *) n;
11870 : : }
11871 : : | ALTER TEXT_P SEARCH CONFIGURATION any_name ALTER MAPPING FOR name_list any_with any_name_list
11872 : : {
6642 tgl@sss.pgh.pa.us 11873 : 13 : AlterTSConfigurationStmt *n = makeNode(AlterTSConfigurationStmt);
11874 : :
3822 alvherre@alvh.no-ip. 11875 : 13 : n->kind = ALTER_TSCONFIG_ALTER_MAPPING_FOR_TOKEN;
6642 tgl@sss.pgh.pa.us 11876 : 13 : n->cfgname = $5;
11877 : 13 : n->tokentype = $9;
11878 : 13 : n->dicts = $11;
11879 : 13 : n->override = true;
11880 : 13 : n->replace = false;
1263 peter@eisentraut.org 11881 : 13 : $$ = (Node *) n;
11882 : : }
11883 : : | ALTER TEXT_P SEARCH CONFIGURATION any_name ALTER MAPPING REPLACE any_name any_with any_name
11884 : : {
6642 tgl@sss.pgh.pa.us 11885 : 9 : AlterTSConfigurationStmt *n = makeNode(AlterTSConfigurationStmt);
11886 : :
3822 alvherre@alvh.no-ip. 11887 : 9 : n->kind = ALTER_TSCONFIG_REPLACE_DICT;
6642 tgl@sss.pgh.pa.us 11888 : 9 : n->cfgname = $5;
11889 : 9 : n->tokentype = NIL;
11890 : 9 : n->dicts = list_make2($9,$11);
11891 : 9 : n->override = false;
11892 : 9 : n->replace = true;
1263 peter@eisentraut.org 11893 : 9 : $$ = (Node *) n;
11894 : : }
11895 : : | ALTER TEXT_P SEARCH CONFIGURATION any_name ALTER MAPPING FOR name_list REPLACE any_name any_with any_name
11896 : : {
6642 tgl@sss.pgh.pa.us 11897 :UBC 0 : AlterTSConfigurationStmt *n = makeNode(AlterTSConfigurationStmt);
11898 : :
3822 alvherre@alvh.no-ip. 11899 : 0 : n->kind = ALTER_TSCONFIG_REPLACE_DICT_FOR_TOKEN;
6642 tgl@sss.pgh.pa.us 11900 : 0 : n->cfgname = $5;
11901 : 0 : n->tokentype = $9;
11902 : 0 : n->dicts = list_make2($11,$13);
11903 : 0 : n->override = false;
11904 : 0 : n->replace = true;
1263 peter@eisentraut.org 11905 : 0 : $$ = (Node *) n;
11906 : : }
11907 : : | ALTER TEXT_P SEARCH CONFIGURATION any_name DROP MAPPING FOR name_list
11908 : : {
6642 tgl@sss.pgh.pa.us 11909 :CBC 9 : AlterTSConfigurationStmt *n = makeNode(AlterTSConfigurationStmt);
11910 : :
3822 alvherre@alvh.no-ip. 11911 : 9 : n->kind = ALTER_TSCONFIG_DROP_MAPPING;
6642 tgl@sss.pgh.pa.us 11912 : 9 : n->cfgname = $5;
11913 : 9 : n->tokentype = $9;
11914 : 9 : n->missing_ok = false;
1263 peter@eisentraut.org 11915 : 9 : $$ = (Node *) n;
11916 : : }
11917 : : | ALTER TEXT_P SEARCH CONFIGURATION any_name DROP MAPPING IF_P EXISTS FOR name_list
11918 : : {
6642 tgl@sss.pgh.pa.us 11919 : 6 : AlterTSConfigurationStmt *n = makeNode(AlterTSConfigurationStmt);
11920 : :
3822 alvherre@alvh.no-ip. 11921 : 6 : n->kind = ALTER_TSCONFIG_DROP_MAPPING;
6642 tgl@sss.pgh.pa.us 11922 : 6 : n->cfgname = $5;
11923 : 6 : n->tokentype = $11;
11924 : 6 : n->missing_ok = true;
1263 peter@eisentraut.org 11925 : 6 : $$ = (Node *) n;
11926 : : }
11927 : : ;
11928 : :
11929 : : /* Use this if TIME or ORDINALITY after WITH should be taken as an identifier */
11930 : : any_with: WITH
11931 : : | WITH_LA
11932 : : ;
11933 : :
11934 : :
11935 : : /*****************************************************************************
11936 : : *
11937 : : * Manipulate a conversion
11938 : : *
11939 : : * CREATE [DEFAULT] CONVERSION <conversion_name>
11940 : : * FOR <encoding_name> TO <encoding_name> FROM <func_name>
11941 : : *
11942 : : *****************************************************************************/
11943 : :
11944 : : CreateConversionStmt:
11945 : : CREATE opt_default CONVERSION_P any_name FOR Sconst
11946 : : TO Sconst FROM any_name
11947 : : {
5109 peter_e@gmx.net 11948 : 32 : CreateConversionStmt *n = makeNode(CreateConversionStmt);
11949 : :
11950 : 32 : n->conversion_name = $4;
11951 : 32 : n->for_encoding_name = $6;
11952 : 32 : n->to_encoding_name = $8;
11953 : 32 : n->func_name = $10;
11954 : 32 : n->def = $2;
1263 peter@eisentraut.org 11955 : 32 : $$ = (Node *) n;
11956 : : }
11957 : : ;
11958 : :
11959 : : /*****************************************************************************
11960 : : *
11961 : : * QUERY:
11962 : : * CLUSTER (options) [ <qualified_name> [ USING <index_name> ] ]
11963 : : * CLUSTER [VERBOSE] [ <qualified_name> [ USING <index_name> ] ]
11964 : : * CLUSTER [VERBOSE] <index_name> ON <qualified_name> (for pre-8.3)
11965 : : *
11966 : : *****************************************************************************/
11967 : :
11968 : : ClusterStmt:
11969 : : CLUSTER '(' utility_option_list ')' qualified_name cluster_index_specification
11970 : : {
5109 peter_e@gmx.net 11971 :UBC 0 : ClusterStmt *n = makeNode(ClusterStmt);
11972 : :
831 nathan@postgresql.or 11973 : 0 : n->relation = $5;
11974 : 0 : n->indexname = $6;
11975 : 0 : n->params = $3;
1263 peter@eisentraut.org 11976 : 0 : $$ = (Node *) n;
11977 : : }
11978 : : | CLUSTER opt_utility_option_list
11979 : : {
831 nathan@postgresql.or 11980 :GBC 8 : ClusterStmt *n = makeNode(ClusterStmt);
11981 : :
11982 : 8 : n->relation = NULL;
11983 : 8 : n->indexname = NULL;
94 alvherre@kurilemu.de 11984 :GNC 8 : n->params = $2;
831 nathan@postgresql.or 11985 :GBC 8 : $$ = (Node *) n;
11986 : : }
11987 : : /* unparenthesized VERBOSE kept for pre-14 compatibility */
11988 : : | CLUSTER opt_verbose qualified_name cluster_index_specification
11989 : : {
1789 michael@paquier.xyz 11990 :CBC 98 : ClusterStmt *n = makeNode(ClusterStmt);
11991 : :
831 nathan@postgresql.or 11992 : 98 : n->relation = $3;
11993 : 98 : n->indexname = $4;
11994 [ - + ]: 98 : if ($2)
94 alvherre@kurilemu.de 11995 :UNC 0 : n->params = list_make1(makeDefElem("verbose", NULL, @2));
1263 peter@eisentraut.org 11996 :CBC 98 : $$ = (Node *) n;
11997 : : }
11998 : : /* unparenthesized VERBOSE kept for pre-17 compatibility */
11999 : : | CLUSTER VERBOSE
12000 : : {
5109 peter_e@gmx.net 12001 : 8 : ClusterStmt *n = makeNode(ClusterStmt);
12002 : :
12003 : 8 : n->relation = NULL;
12004 : 8 : n->indexname = NULL;
94 alvherre@kurilemu.de 12005 :GNC 8 : n->params = list_make1(makeDefElem("verbose", NULL, @2));
1263 peter@eisentraut.org 12006 :CBC 8 : $$ = (Node *) n;
12007 : : }
12008 : : /* kept for pre-8.3 compatibility */
12009 : : | CLUSTER opt_verbose name ON qualified_name
12010 : : {
5109 peter_e@gmx.net 12011 : 10 : ClusterStmt *n = makeNode(ClusterStmt);
12012 : :
12013 : 10 : n->relation = $5;
12014 : 10 : n->indexname = $3;
2652 michael@paquier.xyz 12015 [ - + ]: 10 : if ($2)
94 alvherre@kurilemu.de 12016 :UNC 0 : n->params = list_make1(makeDefElem("verbose", NULL, @2));
1263 peter@eisentraut.org 12017 :CBC 10 : $$ = (Node *) n;
12018 : : }
12019 : : ;
12020 : :
12021 : : cluster_index_specification:
1965 12022 : 78 : USING name { $$ = $2; }
6777 bruce@momjian.us 12023 : 20 : | /*EMPTY*/ { $$ = NULL; }
12024 : : ;
12025 : :
12026 : :
12027 : : /*****************************************************************************
12028 : : *
12029 : : * QUERY:
12030 : : * VACUUM
12031 : : * ANALYZE
12032 : : *
12033 : : *****************************************************************************/
12034 : :
12035 : : VacuumStmt: VACUUM opt_full opt_freeze opt_verbose opt_analyze opt_vacuum_relation_list
12036 : : {
10276 12037 : 593 : VacuumStmt *n = makeNode(VacuumStmt);
12038 : :
2415 rhaas@postgresql.org 12039 : 593 : n->options = NIL;
5824 tgl@sss.pgh.pa.us 12040 [ + + ]: 593 : if ($2)
2415 rhaas@postgresql.org 12041 : 65 : n->options = lappend(n->options,
12042 : 65 : makeDefElem("full", NULL, @2));
3876 alvherre@alvh.no-ip. 12043 [ + + ]: 593 : if ($3)
2415 rhaas@postgresql.org 12044 : 81 : n->options = lappend(n->options,
12045 : 81 : makeDefElem("freeze", NULL, @3));
5824 tgl@sss.pgh.pa.us 12046 [ + + ]: 593 : if ($4)
2415 rhaas@postgresql.org 12047 : 5 : n->options = lappend(n->options,
12048 : 5 : makeDefElem("verbose", NULL, @4));
2848 12049 [ + + ]: 593 : if ($5)
2415 12050 : 146 : n->options = lappend(n->options,
12051 : 146 : makeDefElem("analyze", NULL, @5));
2848 12052 : 593 : n->rels = $6;
2415 12053 : 593 : n->is_vacuumcmd = true;
1263 peter@eisentraut.org 12054 : 593 : $$ = (Node *) n;
12055 : : }
12056 : : | VACUUM '(' utility_option_list ')' opt_vacuum_relation_list
12057 : : {
5824 tgl@sss.pgh.pa.us 12058 : 3871 : VacuumStmt *n = makeNode(VacuumStmt);
12059 : :
2415 rhaas@postgresql.org 12060 : 3871 : n->options = $3;
2946 tgl@sss.pgh.pa.us 12061 : 3871 : n->rels = $5;
2415 rhaas@postgresql.org 12062 : 3871 : n->is_vacuumcmd = true;
5824 tgl@sss.pgh.pa.us 12063 : 3871 : $$ = (Node *) n;
12064 : : }
12065 : : ;
12066 : :
12067 : : AnalyzeStmt: analyze_keyword opt_utility_option_list opt_vacuum_relation_list
12068 : : {
8939 12069 : 2535 : VacuumStmt *n = makeNode(VacuumStmt);
12070 : :
94 alvherre@kurilemu.de 12071 :GNC 2535 : n->options = $2;
2946 tgl@sss.pgh.pa.us 12072 :CBC 2535 : n->rels = $3;
2415 rhaas@postgresql.org 12073 : 2535 : n->is_vacuumcmd = false;
1263 peter@eisentraut.org 12074 : 2535 : $$ = (Node *) n;
12075 : : }
12076 : : | analyze_keyword VERBOSE opt_vacuum_relation_list
12077 : : {
2793 andres@anarazel.de 12078 :LBC (93) : VacuumStmt *n = makeNode(VacuumStmt);
12079 : :
94 alvherre@kurilemu.de 12080 :UNC 0 : n->options = list_make1(makeDefElem("verbose", NULL, @2));
12081 : 0 : n->rels = $3;
2415 rhaas@postgresql.org 12082 :LBC (93) : n->is_vacuumcmd = false;
2793 andres@anarazel.de 12083 : (93) : $$ = (Node *) n;
12084 : : }
12085 : : ;
12086 : :
12087 : : analyze_keyword:
12088 : : ANALYZE
12089 : : | ANALYSE /* British */
12090 : : ;
12091 : :
12092 : : opt_analyze:
2848 rhaas@postgresql.org 12093 :CBC 146 : analyze_keyword { $$ = true; }
12094 : 447 : | /*EMPTY*/ { $$ = false; }
12095 : : ;
12096 : :
12097 : : opt_verbose:
2994 peter_e@gmx.net 12098 : 5 : VERBOSE { $$ = true; }
12099 : 1854 : | /*EMPTY*/ { $$ = false; }
12100 : : ;
12101 : :
12102 : 65 : opt_full: FULL { $$ = true; }
12103 : 528 : | /*EMPTY*/ { $$ = false; }
12104 : : ;
12105 : :
12106 : 81 : opt_freeze: FREEZE { $$ = true; }
12107 : 512 : | /*EMPTY*/ { $$ = false; }
12108 : : ;
12109 : :
12110 : : opt_name_list:
8533 bruce@momjian.us 12111 : 1449 : '(' name_list ')' { $$ = $2; }
12112 : 8159 : | /*EMPTY*/ { $$ = NIL; }
12113 : : ;
12114 : :
12115 : : vacuum_relation:
12116 : : relation_expr opt_name_list
12117 : : {
2946 tgl@sss.pgh.pa.us 12118 : 6903 : $$ = (Node *) makeVacuumRelation($1, InvalidOid, $2);
12119 : : }
12120 : : ;
12121 : :
12122 : : vacuum_relation_list:
12123 : : vacuum_relation
12124 : 6822 : { $$ = list_make1($1); }
12125 : : | vacuum_relation_list ',' vacuum_relation
12126 : 81 : { $$ = lappend($1, $3); }
12127 : : ;
12128 : :
12129 : : opt_vacuum_relation_list:
12130 : 6822 : vacuum_relation_list { $$ = $1; }
12131 : 177 : | /*EMPTY*/ { $$ = NIL; }
12132 : : ;
12133 : :
12134 : :
12135 : : /*****************************************************************************
12136 : : *
12137 : : * QUERY:
12138 : : * EXPLAIN [ANALYZE] [VERBOSE] query
12139 : : * EXPLAIN ( options ) query
12140 : : *
12141 : : *****************************************************************************/
12142 : :
12143 : : ExplainStmt:
12144 : : EXPLAIN ExplainableStmt
12145 : : {
5937 12146 : 3859 : ExplainStmt *n = makeNode(ExplainStmt);
12147 : :
12148 : 3859 : n->query = $2;
12149 : 3859 : n->options = NIL;
12150 : 3859 : $$ = (Node *) n;
12151 : : }
12152 : : | EXPLAIN analyze_keyword opt_verbose ExplainableStmt
12153 : : {
8805 12154 : 1158 : ExplainStmt *n = makeNode(ExplainStmt);
12155 : :
6803 12156 : 1158 : n->query = $4;
3338 peter_e@gmx.net 12157 : 1158 : n->options = list_make1(makeDefElem("analyze", NULL, @2));
5937 tgl@sss.pgh.pa.us 12158 [ - + ]: 1158 : if ($3)
5937 tgl@sss.pgh.pa.us 12159 :UBC 0 : n->options = lappend(n->options,
3338 peter_e@gmx.net 12160 : 0 : makeDefElem("verbose", NULL, @3));
5937 tgl@sss.pgh.pa.us 12161 :CBC 1158 : $$ = (Node *) n;
12162 : : }
12163 : : | EXPLAIN VERBOSE ExplainableStmt
12164 : : {
12165 : 6 : ExplainStmt *n = makeNode(ExplainStmt);
12166 : :
12167 : 6 : n->query = $3;
3338 peter_e@gmx.net 12168 : 6 : n->options = list_make1(makeDefElem("verbose", NULL, @2));
5937 tgl@sss.pgh.pa.us 12169 : 6 : $$ = (Node *) n;
12170 : : }
12171 : : | EXPLAIN '(' utility_option_list ')' ExplainableStmt
12172 : : {
12173 : 7172 : ExplainStmt *n = makeNode(ExplainStmt);
12174 : :
12175 : 7172 : n->query = $5;
12176 : 7172 : n->options = $3;
12177 : 7172 : $$ = (Node *) n;
12178 : : }
12179 : : ;
12180 : :
12181 : : ExplainableStmt:
12182 : : SelectStmt
12183 : : | InsertStmt
12184 : : | UpdateStmt
12185 : : | DeleteStmt
12186 : : | MergeStmt
12187 : : | DeclareCursorStmt
12188 : : | CreateAsStmt
12189 : : | CreateMatViewStmt
12190 : : | RefreshMatViewStmt
12191 : : | ExecuteStmt /* by default all are $$=$1 */
12192 : : ;
12193 : :
12194 : : /*****************************************************************************
12195 : : *
12196 : : * QUERY:
12197 : : * PREPARE <plan_name> [(args, ...)] AS <query>
12198 : : *
12199 : : *****************************************************************************/
12200 : :
12201 : : PrepareStmt: PREPARE name prep_type_clause AS PreparableStmt
12202 : : {
8462 12203 : 966 : PrepareStmt *n = makeNode(PrepareStmt);
12204 : :
12205 : 966 : n->name = $2;
12206 : 966 : n->argtypes = $3;
6803 12207 : 966 : n->query = $5;
8462 12208 : 966 : $$ = (Node *) n;
12209 : : }
12210 : : ;
12211 : :
6852 12212 : 808 : prep_type_clause: '(' type_list ')' { $$ = $2; }
8462 12213 : 167 : | /* EMPTY */ { $$ = NIL; }
12214 : : ;
12215 : :
12216 : : PreparableStmt:
12217 : : SelectStmt
12218 : : | InsertStmt
12219 : : | UpdateStmt
12220 : : | DeleteStmt
12221 : : | MergeStmt /* by default all are $$=$1 */
12222 : : ;
12223 : :
12224 : : /*****************************************************************************
12225 : : *
12226 : : * EXECUTE <plan_name> [(params, ...)]
12227 : : * CREATE TABLE <name> AS EXECUTE <plan_name> [(params, ...)]
12228 : : *
12229 : : *****************************************************************************/
12230 : :
12231 : : ExecuteStmt: EXECUTE name execute_param_clause
12232 : : {
12233 : 8065 : ExecuteStmt *n = makeNode(ExecuteStmt);
12234 : :
12235 : 8065 : n->name = $2;
12236 : 8065 : n->params = $3;
8154 peter_e@gmx.net 12237 : 8065 : $$ = (Node *) n;
12238 : : }
12239 : : | CREATE OptTemp TABLE create_as_target AS
12240 : : EXECUTE name execute_param_clause opt_with_data
12241 : : {
4970 tgl@sss.pgh.pa.us 12242 : 38 : CreateTableAsStmt *ctas = makeNode(CreateTableAsStmt);
8154 peter_e@gmx.net 12243 : 38 : ExecuteStmt *n = makeNode(ExecuteStmt);
12244 : :
6824 tgl@sss.pgh.pa.us 12245 : 38 : n->name = $7;
12246 : 38 : n->params = $8;
4970 12247 : 38 : ctas->query = (Node *) n;
12248 : 38 : ctas->into = $4;
1934 michael@paquier.xyz 12249 : 38 : ctas->objtype = OBJECT_TABLE;
4970 tgl@sss.pgh.pa.us 12250 : 38 : ctas->is_select_into = false;
2446 michael@paquier.xyz 12251 : 38 : ctas->if_not_exists = false;
12252 : : /* cram additional flags into the IntoClause */
5086 tgl@sss.pgh.pa.us 12253 : 38 : $4->rel->relpersistence = $2;
12254 : 38 : $4->skipData = !($9);
4970 12255 : 38 : $$ = (Node *) ctas;
12256 : : }
12257 : : | CREATE OptTemp TABLE IF_P NOT EXISTS create_as_target AS
12258 : : EXECUTE name execute_param_clause opt_with_data
12259 : : {
2446 michael@paquier.xyz 12260 : 6 : CreateTableAsStmt *ctas = makeNode(CreateTableAsStmt);
12261 : 6 : ExecuteStmt *n = makeNode(ExecuteStmt);
12262 : :
12263 : 6 : n->name = $10;
12264 : 6 : n->params = $11;
12265 : 6 : ctas->query = (Node *) n;
12266 : 6 : ctas->into = $7;
1934 12267 : 6 : ctas->objtype = OBJECT_TABLE;
2446 12268 : 6 : ctas->is_select_into = false;
12269 : 6 : ctas->if_not_exists = true;
12270 : : /* cram additional flags into the IntoClause */
12271 : 6 : $7->rel->relpersistence = $2;
12272 : 6 : $7->skipData = !($12);
12273 : 6 : $$ = (Node *) ctas;
12274 : : }
12275 : : ;
12276 : :
8395 tgl@sss.pgh.pa.us 12277 : 7537 : execute_param_clause: '(' expr_list ')' { $$ = $2; }
8462 12278 : 572 : | /* EMPTY */ { $$ = NIL; }
12279 : : ;
12280 : :
12281 : : /*****************************************************************************
12282 : : *
12283 : : * QUERY:
12284 : : * DEALLOCATE [PREPARE] <plan_name>
12285 : : *
12286 : : *****************************************************************************/
12287 : :
12288 : : DeallocateStmt: DEALLOCATE name
12289 : : {
12290 : 1141 : DeallocateStmt *n = makeNode(DeallocateStmt);
12291 : :
12292 : 1141 : n->name = $2;
792 michael@paquier.xyz 12293 : 1141 : n->isall = false;
12294 : 1141 : n->location = @2;
8462 tgl@sss.pgh.pa.us 12295 : 1141 : $$ = (Node *) n;
12296 : : }
12297 : : | DEALLOCATE PREPARE name
12298 : : {
12299 : 10 : DeallocateStmt *n = makeNode(DeallocateStmt);
12300 : :
12301 : 10 : n->name = $3;
792 michael@paquier.xyz 12302 : 10 : n->isall = false;
12303 : 10 : n->location = @3;
8462 tgl@sss.pgh.pa.us 12304 : 10 : $$ = (Node *) n;
12305 : : }
12306 : : | DEALLOCATE ALL
12307 : : {
6773 neilc@samurai.com 12308 : 35 : DeallocateStmt *n = makeNode(DeallocateStmt);
12309 : :
12310 : 35 : n->name = NULL;
792 michael@paquier.xyz 12311 : 35 : n->isall = true;
12312 : 35 : n->location = -1;
6773 neilc@samurai.com 12313 : 35 : $$ = (Node *) n;
12314 : : }
12315 : : | DEALLOCATE PREPARE ALL
12316 : : {
12317 : 1 : DeallocateStmt *n = makeNode(DeallocateStmt);
12318 : :
12319 : 1 : n->name = NULL;
792 michael@paquier.xyz 12320 : 1 : n->isall = true;
12321 : 1 : n->location = -1;
6773 neilc@samurai.com 12322 : 1 : $$ = (Node *) n;
12323 : : }
12324 : : ;
12325 : :
12326 : : /*****************************************************************************
12327 : : *
12328 : : * QUERY:
12329 : : * INSERT STATEMENTS
12330 : : *
12331 : : *****************************************************************************/
12332 : :
12333 : : InsertStmt:
12334 : : opt_with_clause INSERT INTO insert_target insert_rest
12335 : : opt_on_conflict returning_clause
12336 : : {
5491 tgl@sss.pgh.pa.us 12337 : 36030 : $5->relation = $4;
3825 andres@anarazel.de 12338 : 36030 : $5->onConflictClause = $6;
284 dean.a.rasheed@gmail 12339 : 36030 : $5->returningClause = $7;
5491 tgl@sss.pgh.pa.us 12340 : 36030 : $5->withClause = $1;
12341 : 36030 : $$ = (Node *) $5;
12342 : : }
12343 : : ;
12344 : :
12345 : : /*
12346 : : * Can't easily make AS optional here, because VALUES in insert_rest would
12347 : : * have a shift/reduce conflict with VALUES as an optional alias. We could
12348 : : * easily allow unreserved_keywords as optional aliases, but that'd be an odd
12349 : : * divergence from other places. So just require AS for now.
12350 : : */
12351 : : insert_target:
12352 : : qualified_name
12353 : : {
3825 andres@anarazel.de 12354 : 35967 : $$ = $1;
12355 : : }
12356 : : | qualified_name AS ColId
12357 : : {
12358 : 66 : $1->alias = makeAlias($3, NIL);
12359 : 66 : $$ = $1;
12360 : : }
12361 : : ;
12362 : :
12363 : : insert_rest:
12364 : : SelectStmt
12365 : : {
10153 bruce@momjian.us 12366 : 23889 : $$ = makeNode(InsertStmt);
9596 tgl@sss.pgh.pa.us 12367 : 23889 : $$->cols = NIL;
9153 12368 : 23889 : $$->selectStmt = $1;
12369 : : }
12370 : : | OVERRIDING override_kind VALUE_P SelectStmt
12371 : : {
3126 peter_e@gmx.net 12372 : 48 : $$ = makeNode(InsertStmt);
12373 : 48 : $$->cols = NIL;
12374 : 48 : $$->override = $2;
12375 : 48 : $$->selectStmt = $4;
12376 : : }
12377 : : | '(' insert_column_list ')' SelectStmt
12378 : : {
9779 bruce@momjian.us 12379 : 6695 : $$ = makeNode(InsertStmt);
12380 : 6695 : $$->cols = $2;
7026 mail@joeconway.com 12381 : 6695 : $$->selectStmt = $4;
12382 : : }
12383 : : | '(' insert_column_list ')' OVERRIDING override_kind VALUE_P SelectStmt
12384 : : {
3126 peter_e@gmx.net 12385 :UBC 0 : $$ = makeNode(InsertStmt);
12386 : 0 : $$->cols = $2;
12387 : 0 : $$->override = $5;
12388 : 0 : $$->selectStmt = $7;
12389 : : }
12390 : : | DEFAULT VALUES
12391 : : {
9779 bruce@momjian.us 12392 :CBC 5401 : $$ = makeNode(InsertStmt);
7026 mail@joeconway.com 12393 : 5401 : $$->cols = NIL;
12394 : 5401 : $$->selectStmt = NULL;
12395 : : }
12396 : : ;
12397 : :
12398 : : override_kind:
3126 peter_e@gmx.net 12399 : 33 : USER { $$ = OVERRIDING_USER_VALUE; }
12400 : 30 : | SYSTEM_P { $$ = OVERRIDING_SYSTEM_VALUE; }
12401 : : ;
12402 : :
12403 : : insert_column_list:
12404 : : insert_column_item
7810 tgl@sss.pgh.pa.us 12405 : 6862 : { $$ = list_make1($1); }
12406 : : | insert_column_list ',' insert_column_item
8532 bruce@momjian.us 12407 : 7569 : { $$ = lappend($1, $3); }
12408 : : ;
12409 : :
12410 : : insert_column_item:
12411 : : ColId opt_indirection
12412 : : {
7810 tgl@sss.pgh.pa.us 12413 : 14431 : $$ = makeNode(ResTarget);
12414 : 14431 : $$->name = $1;
5950 12415 : 14431 : $$->indirection = check_indirection($2, yyscanner);
7810 12416 : 14431 : $$->val = NULL;
7158 12417 : 14431 : $$->location = @1;
12418 : : }
12419 : : ;
12420 : :
12421 : : opt_on_conflict:
12422 : : ON CONFLICT opt_conf_expr DO UPDATE SET set_clause_list where_clause
12423 : : {
3825 andres@anarazel.de 12424 : 659 : $$ = makeNode(OnConflictClause);
12425 : 659 : $$->action = ONCONFLICT_UPDATE;
12426 : 659 : $$->infer = $3;
12427 : 659 : $$->targetList = $7;
12428 : 659 : $$->whereClause = $8;
12429 : 659 : $$->location = @1;
12430 : : }
12431 : : |
12432 : : ON CONFLICT opt_conf_expr DO NOTHING
12433 : : {
12434 : 281 : $$ = makeNode(OnConflictClause);
12435 : 281 : $$->action = ONCONFLICT_NOTHING;
12436 : 281 : $$->infer = $3;
12437 : 281 : $$->targetList = NIL;
12438 : 281 : $$->whereClause = NULL;
12439 : 281 : $$->location = @1;
12440 : : }
12441 : : | /*EMPTY*/
12442 : : {
12443 : 35093 : $$ = NULL;
12444 : : }
12445 : : ;
12446 : :
12447 : : opt_conf_expr:
12448 : : '(' index_params ')' where_clause
12449 : : {
12450 : 721 : $$ = makeNode(InferClause);
12451 : 721 : $$->indexElems = $2;
12452 : 721 : $$->whereClause = $4;
12453 : 721 : $$->conname = NULL;
12454 : 721 : $$->location = @1;
12455 : : }
12456 : : |
12457 : : ON CONSTRAINT name
12458 : : {
12459 : 96 : $$ = makeNode(InferClause);
12460 : 96 : $$->indexElems = NIL;
12461 : 96 : $$->whereClause = NULL;
12462 : 96 : $$->conname = $3;
12463 : 96 : $$->location = @1;
12464 : : }
12465 : : | /*EMPTY*/
12466 : : {
12467 : 123 : $$ = NULL;
12468 : : }
12469 : : ;
12470 : :
12471 : : returning_clause:
12472 : : RETURNING returning_with_clause target_list
12473 : : {
284 dean.a.rasheed@gmail 12474 : 1584 : ReturningClause *n = makeNode(ReturningClause);
12475 : :
12476 : 1584 : n->options = $2;
12477 : 1584 : n->exprs = $3;
12478 : 1584 : $$ = n;
12479 : : }
12480 : : | /* EMPTY */
12481 : : {
12482 : 45011 : $$ = NULL;
12483 : : }
12484 : : ;
12485 : :
12486 : : returning_with_clause:
12487 : 36 : WITH '(' returning_options ')' { $$ = $3; }
12488 : 1548 : | /* EMPTY */ { $$ = NIL; }
12489 : : ;
12490 : :
12491 : : returning_options:
12492 : 36 : returning_option { $$ = list_make1($1); }
12493 : 27 : | returning_options ',' returning_option { $$ = lappend($1, $3); }
12494 : : ;
12495 : :
12496 : : returning_option:
12497 : : returning_option_kind AS ColId
12498 : : {
12499 : 63 : ReturningOption *n = makeNode(ReturningOption);
12500 : :
12501 : 63 : n->option = $1;
12502 : 63 : n->value = $3;
12503 : 63 : n->location = @1;
12504 : 63 : $$ = (Node *) n;
12505 : : }
12506 : : ;
12507 : :
12508 : : returning_option_kind:
12509 : 27 : OLD { $$ = RETURNING_OPTION_OLD; }
12510 : 36 : | NEW { $$ = RETURNING_OPTION_NEW; }
12511 : : ;
12512 : :
12513 : :
12514 : : /*****************************************************************************
12515 : : *
12516 : : * QUERY:
12517 : : * DELETE STATEMENTS
12518 : : *
12519 : : *****************************************************************************/
12520 : :
12521 : : DeleteStmt: opt_with_clause DELETE_P FROM relation_expr_opt_alias
12522 : : using_clause where_or_current_clause returning_clause
12523 : : {
10276 bruce@momjian.us 12524 : 2337 : DeleteStmt *n = makeNode(DeleteStmt);
12525 : :
5491 tgl@sss.pgh.pa.us 12526 : 2337 : n->relation = $4;
12527 : 2337 : n->usingClause = $5;
12528 : 2337 : n->whereClause = $6;
284 dean.a.rasheed@gmail 12529 : 2337 : n->returningClause = $7;
5491 tgl@sss.pgh.pa.us 12530 : 2337 : n->withClause = $1;
1263 peter@eisentraut.org 12531 : 2337 : $$ = (Node *) n;
12532 : : }
12533 : : ;
12534 : :
12535 : : using_clause:
5109 peter_e@gmx.net 12536 : 54 : USING from_list { $$ = $2; }
7508 neilc@samurai.com 12537 : 2283 : | /*EMPTY*/ { $$ = NIL; }
12538 : : ;
12539 : :
12540 : :
12541 : : /*****************************************************************************
12542 : : *
12543 : : * QUERY:
12544 : : * LOCK TABLE
12545 : : *
12546 : : *****************************************************************************/
12547 : :
12548 : : LockStmt: LOCK_P opt_table relation_expr_list opt_lock opt_nowait
12549 : : {
1263 peter@eisentraut.org 12550 : 530 : LockStmt *n = makeNode(LockStmt);
12551 : :
8621 tgl@sss.pgh.pa.us 12552 : 530 : n->relations = $3;
9660 bruce@momjian.us 12553 : 530 : n->mode = $4;
7900 ishii@postgresql.org 12554 : 530 : n->nowait = $5;
1263 peter@eisentraut.org 12555 : 530 : $$ = (Node *) n;
12556 : : }
12557 : : ;
12558 : :
5109 peter_e@gmx.net 12559 : 475 : opt_lock: IN_P lock_type MODE { $$ = $2; }
8532 bruce@momjian.us 12560 : 55 : | /*EMPTY*/ { $$ = AccessExclusiveLock; }
12561 : : ;
12562 : :
12563 : 230 : lock_type: ACCESS SHARE { $$ = AccessShareLock; }
12564 : 7 : | ROW SHARE { $$ = RowShareLock; }
12565 : 44 : | ROW EXCLUSIVE { $$ = RowExclusiveLock; }
12566 : 33 : | SHARE UPDATE EXCLUSIVE { $$ = ShareUpdateExclusiveLock; }
12567 : 40 : | SHARE { $$ = ShareLock; }
12568 : 7 : | SHARE ROW EXCLUSIVE { $$ = ShareRowExclusiveLock; }
12569 : 51 : | EXCLUSIVE { $$ = ExclusiveLock; }
12570 : 63 : | ACCESS EXCLUSIVE { $$ = AccessExclusiveLock; }
12571 : : ;
12572 : :
2994 peter_e@gmx.net 12573 : 95 : opt_nowait: NOWAIT { $$ = true; }
12574 : 450 : | /*EMPTY*/ { $$ = false; }
12575 : : ;
12576 : :
12577 : : opt_nowait_or_skip:
4038 alvherre@alvh.no-ip. 12578 : 25 : NOWAIT { $$ = LockWaitError; }
12579 : 95 : | SKIP LOCKED { $$ = LockWaitSkip; }
12580 : 2592 : | /*EMPTY*/ { $$ = LockWaitBlock; }
12581 : : ;
12582 : :
12583 : :
12584 : : /*****************************************************************************
12585 : : *
12586 : : * QUERY:
12587 : : * UpdateStmt (UPDATE)
12588 : : *
12589 : : *****************************************************************************/
12590 : :
12591 : : UpdateStmt: opt_with_clause UPDATE relation_expr_opt_alias
12592 : : SET set_clause_list
12593 : : from_clause
12594 : : where_or_current_clause
12595 : : returning_clause
12596 : : {
6995 bruce@momjian.us 12597 : 7169 : UpdateStmt *n = makeNode(UpdateStmt);
12598 : :
5491 tgl@sss.pgh.pa.us 12599 : 7169 : n->relation = $3;
12600 : 7169 : n->targetList = $5;
12601 : 7169 : n->fromClause = $6;
12602 : 7169 : n->whereClause = $7;
284 dean.a.rasheed@gmail 12603 : 7169 : n->returningClause = $8;
5491 tgl@sss.pgh.pa.us 12604 : 7169 : n->withClause = $1;
1263 peter@eisentraut.org 12605 : 7169 : $$ = (Node *) n;
12606 : : }
12607 : : ;
12608 : :
12609 : : set_clause_list:
6994 tgl@sss.pgh.pa.us 12610 : 8627 : set_clause { $$ = $1; }
12611 : 2159 : | set_clause_list ',' set_clause { $$ = list_concat($1,$3); }
12612 : : ;
12613 : :
12614 : : set_clause:
12615 : : set_target '=' a_expr
12616 : : {
3261 12617 : 10695 : $1->val = (Node *) $3;
12618 : 10695 : $$ = list_make1($1);
12619 : : }
12620 : : | '(' set_target_list ')' '=' a_expr
12621 : : {
1263 peter@eisentraut.org 12622 : 91 : int ncolumns = list_length($2);
12623 : 91 : int i = 1;
12624 : : ListCell *col_cell;
12625 : :
12626 : : /* Create a MultiAssignRef source for each target */
4149 tgl@sss.pgh.pa.us 12627 [ + - + + : 281 : foreach(col_cell, $2)
+ + ]
12628 : : {
1263 peter@eisentraut.org 12629 : 190 : ResTarget *res_col = (ResTarget *) lfirst(col_cell);
4149 tgl@sss.pgh.pa.us 12630 : 190 : MultiAssignRef *r = makeNode(MultiAssignRef);
12631 : :
3261 12632 : 190 : r->source = (Node *) $5;
4149 12633 : 190 : r->colno = i;
12634 : 190 : r->ncolumns = ncolumns;
12635 : 190 : res_col->val = (Node *) r;
12636 : 190 : i++;
12637 : : }
12638 : :
6994 12639 : 91 : $$ = $2;
12640 : : }
12641 : : ;
12642 : :
12643 : : set_target:
12644 : : ColId opt_indirection
12645 : : {
12646 : 10888 : $$ = makeNode(ResTarget);
12647 : 10888 : $$->name = $1;
5950 12648 : 10888 : $$->indirection = check_indirection($2, yyscanner);
6994 12649 : 10888 : $$->val = NULL; /* upper production sets this */
12650 : 10888 : $$->location = @1;
12651 : : }
12652 : : ;
12653 : :
12654 : : set_target_list:
12655 : 94 : set_target { $$ = list_make1($1); }
12656 : 99 : | set_target_list ',' set_target { $$ = lappend($1,$3); }
12657 : : ;
12658 : :
12659 : :
12660 : : /*****************************************************************************
12661 : : *
12662 : : * QUERY:
12663 : : * MERGE
12664 : : *
12665 : : *****************************************************************************/
12666 : :
12667 : : MergeStmt:
12668 : : opt_with_clause MERGE INTO relation_expr_opt_alias
12669 : : USING table_ref
12670 : : ON a_expr
12671 : : merge_when_list
12672 : : returning_clause
12673 : : {
1263 peter@eisentraut.org 12674 : 1059 : MergeStmt *m = makeNode(MergeStmt);
12675 : :
1309 alvherre@alvh.no-ip. 12676 : 1059 : m->withClause = $1;
12677 : 1059 : m->relation = $4;
12678 : 1059 : m->sourceRelation = $6;
12679 : 1059 : m->joinCondition = $8;
12680 : 1059 : m->mergeWhenClauses = $9;
284 dean.a.rasheed@gmail 12681 : 1059 : m->returningClause = $10;
12682 : :
1263 peter@eisentraut.org 12683 : 1059 : $$ = (Node *) m;
12684 : : }
12685 : : ;
12686 : :
12687 : : merge_when_list:
1309 alvherre@alvh.no-ip. 12688 : 1059 : merge_when_clause { $$ = list_make1($1); }
12689 : 600 : | merge_when_list merge_when_clause { $$ = lappend($1,$2); }
12690 : : ;
12691 : :
12692 : : /*
12693 : : * A WHEN clause may be WHEN MATCHED, WHEN NOT MATCHED BY SOURCE, or WHEN NOT
12694 : : * MATCHED [BY TARGET]. The first two cases match target tuples, and support
12695 : : * UPDATE/DELETE/DO NOTHING actions. The third case does not match target
12696 : : * tuples, and only supports INSERT/DO NOTHING actions.
12697 : : */
12698 : : merge_when_clause:
12699 : : merge_when_tgt_matched opt_merge_when_condition THEN merge_update
12700 : : {
576 dean.a.rasheed@gmail 12701 : 799 : $4->matchKind = $1;
12702 : 799 : $4->condition = $2;
12703 : :
12704 : 799 : $$ = (Node *) $4;
12705 : : }
12706 : : | merge_when_tgt_matched opt_merge_when_condition THEN merge_delete
12707 : : {
12708 : 265 : $4->matchKind = $1;
12709 : 265 : $4->condition = $2;
12710 : :
12711 : 265 : $$ = (Node *) $4;
12712 : : }
12713 : : | merge_when_tgt_not_matched opt_merge_when_condition THEN merge_insert
12714 : : {
12715 : 550 : $4->matchKind = $1;
12716 : 550 : $4->condition = $2;
12717 : :
12718 : 550 : $$ = (Node *) $4;
12719 : : }
12720 : : | merge_when_tgt_matched opt_merge_when_condition THEN DO NOTHING
12721 : : {
1309 alvherre@alvh.no-ip. 12722 : 35 : MergeWhenClause *m = makeNode(MergeWhenClause);
12723 : :
576 dean.a.rasheed@gmail 12724 : 35 : m->matchKind = $1;
1309 alvherre@alvh.no-ip. 12725 : 35 : m->commandType = CMD_NOTHING;
576 dean.a.rasheed@gmail 12726 : 35 : m->condition = $2;
12727 : :
1263 peter@eisentraut.org 12728 : 35 : $$ = (Node *) m;
12729 : : }
12730 : : | merge_when_tgt_not_matched opt_merge_when_condition THEN DO NOTHING
12731 : : {
1309 alvherre@alvh.no-ip. 12732 : 10 : MergeWhenClause *m = makeNode(MergeWhenClause);
12733 : :
576 dean.a.rasheed@gmail 12734 : 10 : m->matchKind = $1;
1309 alvherre@alvh.no-ip. 12735 : 10 : m->commandType = CMD_NOTHING;
576 dean.a.rasheed@gmail 12736 : 10 : m->condition = $2;
12737 : :
1263 peter@eisentraut.org 12738 : 10 : $$ = (Node *) m;
12739 : : }
12740 : : ;
12741 : :
12742 : : merge_when_tgt_matched:
576 dean.a.rasheed@gmail 12743 : 1018 : WHEN MATCHED { $$ = MERGE_WHEN_MATCHED; }
12744 : 90 : | WHEN NOT MATCHED BY SOURCE { $$ = MERGE_WHEN_NOT_MATCHED_BY_SOURCE; }
12745 : : ;
12746 : :
12747 : : merge_when_tgt_not_matched:
12748 : 563 : WHEN NOT MATCHED { $$ = MERGE_WHEN_NOT_MATCHED_BY_TARGET; }
12749 : 9 : | WHEN NOT MATCHED BY TARGET { $$ = MERGE_WHEN_NOT_MATCHED_BY_TARGET; }
12750 : : ;
12751 : :
12752 : : opt_merge_when_condition:
1309 alvherre@alvh.no-ip. 12753 : 425 : AND a_expr { $$ = $2; }
12754 : 1255 : | { $$ = NULL; }
12755 : : ;
12756 : :
12757 : : merge_update:
12758 : : UPDATE SET set_clause_list
12759 : : {
12760 : 799 : MergeWhenClause *n = makeNode(MergeWhenClause);
12761 : 799 : n->commandType = CMD_UPDATE;
12762 : 799 : n->override = OVERRIDING_NOT_SET;
12763 : 799 : n->targetList = $3;
12764 : 799 : n->values = NIL;
12765 : :
12766 : 799 : $$ = n;
12767 : : }
12768 : : ;
12769 : :
12770 : : merge_delete:
12771 : : DELETE_P
12772 : : {
12773 : 265 : MergeWhenClause *n = makeNode(MergeWhenClause);
12774 : 265 : n->commandType = CMD_DELETE;
12775 : 265 : n->override = OVERRIDING_NOT_SET;
12776 : 265 : n->targetList = NIL;
12777 : 265 : n->values = NIL;
12778 : :
12779 : 265 : $$ = n;
12780 : : }
12781 : : ;
12782 : :
12783 : : merge_insert:
12784 : : INSERT merge_values_clause
12785 : : {
12786 : 365 : MergeWhenClause *n = makeNode(MergeWhenClause);
12787 : 365 : n->commandType = CMD_INSERT;
12788 : 365 : n->override = OVERRIDING_NOT_SET;
12789 : 365 : n->targetList = NIL;
12790 : 365 : n->values = $2;
12791 : 365 : $$ = n;
12792 : : }
12793 : : | INSERT OVERRIDING override_kind VALUE_P merge_values_clause
12794 : : {
1309 alvherre@alvh.no-ip. 12795 :UBC 0 : MergeWhenClause *n = makeNode(MergeWhenClause);
12796 : 0 : n->commandType = CMD_INSERT;
12797 : 0 : n->override = $3;
12798 : 0 : n->targetList = NIL;
12799 : 0 : n->values = $5;
12800 : 0 : $$ = n;
12801 : : }
12802 : : | INSERT '(' insert_column_list ')' merge_values_clause
12803 : : {
1309 alvherre@alvh.no-ip. 12804 :CBC 152 : MergeWhenClause *n = makeNode(MergeWhenClause);
12805 : 152 : n->commandType = CMD_INSERT;
12806 : 152 : n->override = OVERRIDING_NOT_SET;
12807 : 152 : n->targetList = $3;
12808 : 152 : n->values = $5;
12809 : 152 : $$ = n;
12810 : : }
12811 : : | INSERT '(' insert_column_list ')' OVERRIDING override_kind VALUE_P merge_values_clause
12812 : : {
12813 : 15 : MergeWhenClause *n = makeNode(MergeWhenClause);
12814 : 15 : n->commandType = CMD_INSERT;
12815 : 15 : n->override = $6;
12816 : 15 : n->targetList = $3;
12817 : 15 : n->values = $8;
12818 : 15 : $$ = n;
12819 : : }
12820 : : | INSERT DEFAULT VALUES
12821 : : {
12822 : 18 : MergeWhenClause *n = makeNode(MergeWhenClause);
12823 : 18 : n->commandType = CMD_INSERT;
12824 : 18 : n->override = OVERRIDING_NOT_SET;
12825 : 18 : n->targetList = NIL;
12826 : 18 : n->values = NIL;
12827 : 18 : $$ = n;
12828 : : }
12829 : : ;
12830 : :
12831 : : merge_values_clause:
12832 : : VALUES '(' expr_list ')'
12833 : : {
12834 : 532 : $$ = $3;
12835 : : }
12836 : : ;
12837 : :
12838 : : /*****************************************************************************
12839 : : *
12840 : : * QUERY:
12841 : : * CURSOR STATEMENTS
12842 : : *
12843 : : *****************************************************************************/
12844 : : DeclareCursorStmt: DECLARE cursor_name cursor_options CURSOR opt_hold FOR SelectStmt
12845 : : {
8267 tgl@sss.pgh.pa.us 12846 : 2265 : DeclareCursorStmt *n = makeNode(DeclareCursorStmt);
12847 : :
10276 bruce@momjian.us 12848 : 2265 : n->portalname = $2;
12849 : : /* currently we always set FAST_PLAN option */
6769 tgl@sss.pgh.pa.us 12850 : 2265 : n->options = $3 | $5 | CURSOR_OPT_FAST_PLAN;
8250 bruce@momjian.us 12851 : 2265 : n->query = $7;
1263 peter@eisentraut.org 12852 : 2265 : $$ = (Node *) n;
12853 : : }
12854 : : ;
12855 : :
5829 alvherre@alvh.no-ip. 12856 : 7198 : cursor_name: name { $$ = $1; }
12857 : : ;
12858 : :
8267 tgl@sss.pgh.pa.us 12859 : 2265 : cursor_options: /*EMPTY*/ { $$ = 0; }
8250 bruce@momjian.us 12860 : 14 : | cursor_options NO SCROLL { $$ = $1 | CURSOR_OPT_NO_SCROLL; }
8267 tgl@sss.pgh.pa.us 12861 : 120 : | cursor_options SCROLL { $$ = $1 | CURSOR_OPT_SCROLL; }
8250 bruce@momjian.us 12862 : 5 : | cursor_options BINARY { $$ = $1 | CURSOR_OPT_BINARY; }
1664 peter@eisentraut.org 12863 :UBC 0 : | cursor_options ASENSITIVE { $$ = $1 | CURSOR_OPT_ASENSITIVE; }
8267 tgl@sss.pgh.pa.us 12864 :CBC 3 : | cursor_options INSENSITIVE { $$ = $1 | CURSOR_OPT_INSENSITIVE; }
12865 : : ;
12866 : :
6769 12867 : 2216 : opt_hold: /* EMPTY */ { $$ = 0; }
12868 : 46 : | WITH HOLD { $$ = CURSOR_OPT_HOLD; }
12869 : 3 : | WITHOUT HOLD { $$ = 0; }
12870 : : ;
12871 : :
12872 : : /*****************************************************************************
12873 : : *
12874 : : * QUERY:
12875 : : * SELECT STATEMENTS
12876 : : *
12877 : : *****************************************************************************/
12878 : :
12879 : : /* A complete SELECT statement looks like this.
12880 : : *
12881 : : * The rule returns either a single SelectStmt node or a tree of them,
12882 : : * representing a set-operation tree.
12883 : : *
12884 : : * There is an ambiguity when a sub-SELECT is within an a_expr and there
12885 : : * are excess parentheses: do the parentheses belong to the sub-SELECT or
12886 : : * to the surrounding a_expr? We don't really care, but bison wants to know.
12887 : : * To resolve the ambiguity, we are careful to define the grammar so that
12888 : : * the decision is staved off as long as possible: as long as we can keep
12889 : : * absorbing parentheses into the sub-SELECT, we will do so, and only when
12890 : : * it's no longer possible to do that will we decide that parens belong to
12891 : : * the expression. For example, in "SELECT (((SELECT 2)) + 3)" the extra
12892 : : * parentheses are treated as part of the sub-select. The necessity of doing
12893 : : * it that way is shown by "SELECT (((SELECT 2)) UNION SELECT 2)". Had we
12894 : : * parsed "((SELECT 2))" as an a_expr, it'd be too late to go back to the
12895 : : * SELECT viewpoint when we see the UNION.
12896 : : *
12897 : : * This approach is implemented by defining a nonterminal select_with_parens,
12898 : : * which represents a SELECT with at least one outer layer of parentheses,
12899 : : * and being careful to use select_with_parens, never '(' SelectStmt ')',
12900 : : * in the expression grammar. We will then have shift-reduce conflicts
12901 : : * which we can resolve in favor of always treating '(' <select> ')' as
12902 : : * a select_with_parens. To resolve the conflicts, the productions that
12903 : : * conflict with the select_with_parens productions are manually given
12904 : : * precedences lower than the precedence of ')', thereby ensuring that we
12905 : : * shift ')' (and then reduce to select_with_parens) rather than trying to
12906 : : * reduce the inner <select> nonterminal to something else. We use UMINUS
12907 : : * precedence for this, which is a fairly arbitrary choice.
12908 : : *
12909 : : * To be able to define select_with_parens itself without ambiguity, we need
12910 : : * a nonterminal select_no_parens that represents a SELECT structure with no
12911 : : * outermost parentheses. This is a little bit tedious, but it works.
12912 : : *
12913 : : * In non-expression contexts, we use SelectStmt which can represent a SELECT
12914 : : * with or without outer parentheses.
12915 : : */
12916 : :
12917 : : SelectStmt: select_no_parens %prec UMINUS
12918 : : | select_with_parens %prec UMINUS
12919 : : ;
12920 : :
12921 : : select_with_parens:
137 michael@paquier.xyz 12922 : 32771 : '(' select_no_parens ')' { $$ = $2; }
8533 bruce@momjian.us 12923 : 78 : | '(' select_with_parens ')' { $$ = $2; }
12924 : : ;
12925 : :
12926 : : /*
12927 : : * This rule parses the equivalent of the standard's <query expression>.
12928 : : * The duplicative productions are annoying, but hard to get rid of without
12929 : : * creating shift/reduce conflicts.
12930 : : *
12931 : : * The locking clause (FOR UPDATE etc) may be before or after LIMIT/OFFSET.
12932 : : * In <=7.2.X, LIMIT/OFFSET had to be after FOR UPDATE
12933 : : * We now support both orderings, but prefer LIMIT/OFFSET before the locking
12934 : : * clause.
12935 : : * 2002-08-28 bjm
12936 : : */
12937 : : select_no_parens:
12938 : 198873 : simple_select { $$ = $1; }
12939 : : | select_clause sort_clause
12940 : : {
7120 tgl@sss.pgh.pa.us 12941 : 35502 : insertSelectOptions((SelectStmt *) $1, $2, NIL,
12942 : : NULL, NULL,
12943 : : yyscanner);
8533 bruce@momjian.us 12944 : 35502 : $$ = $1;
12945 : : }
12946 : : | select_clause opt_sort_clause for_locking_clause opt_select_limit
12947 : : {
8461 12948 : 2488 : insertSelectOptions((SelectStmt *) $1, $2, $3,
2029 alvherre@alvh.no-ip. 12949 : 2488 : $4,
12950 : : NULL,
12951 : : yyscanner);
8533 bruce@momjian.us 12952 : 2488 : $$ = $1;
12953 : : }
12954 : : | select_clause opt_sort_clause select_limit opt_for_locking_clause
12955 : : {
8461 12956 : 2444 : insertSelectOptions((SelectStmt *) $1, $2, $4,
2029 alvherre@alvh.no-ip. 12957 : 2444 : $3,
12958 : : NULL,
12959 : : yyscanner);
8533 bruce@momjian.us 12960 : 2438 : $$ = $1;
12961 : : }
12962 : : | with_clause select_clause
12963 : : {
6232 tgl@sss.pgh.pa.us 12964 : 1107 : insertSelectOptions((SelectStmt *) $2, NULL, NIL,
12965 : : NULL,
5950 12966 : 1107 : $1,
12967 : : yyscanner);
6232 12968 : 1107 : $$ = $2;
12969 : : }
12970 : : | with_clause select_clause sort_clause
12971 : : {
12972 : 307 : insertSelectOptions((SelectStmt *) $2, $3, NIL,
12973 : : NULL,
5950 12974 : 307 : $1,
12975 : : yyscanner);
6232 12976 : 307 : $$ = $2;
12977 : : }
12978 : : | with_clause select_clause opt_sort_clause for_locking_clause opt_select_limit
12979 : : {
12980 : 3 : insertSelectOptions((SelectStmt *) $2, $3, $4,
2029 alvherre@alvh.no-ip. 12981 : 3 : $5,
5950 tgl@sss.pgh.pa.us 12982 : 3 : $1,
12983 : : yyscanner);
6232 12984 : 3 : $$ = $2;
12985 : : }
12986 : : | with_clause select_clause opt_sort_clause select_limit opt_for_locking_clause
12987 : : {
12988 : 32 : insertSelectOptions((SelectStmt *) $2, $3, $5,
2029 alvherre@alvh.no-ip. 12989 : 32 : $4,
5950 tgl@sss.pgh.pa.us 12990 : 32 : $1,
12991 : : yyscanner);
6232 12992 : 32 : $$ = $2;
12993 : : }
12994 : : ;
12995 : :
12996 : : select_clause:
8533 bruce@momjian.us 12997 : 61367 : simple_select { $$ = $1; }
12998 : 294 : | select_with_parens { $$ = $1; }
12999 : : ;
13000 : :
13001 : : /*
13002 : : * This rule parses SELECT statements that can appear within set operations,
13003 : : * including UNION, INTERSECT and EXCEPT. '(' and ')' can be used to specify
13004 : : * the ordering of the set operations. Without '(' and ')' we want the
13005 : : * operations to be ordered per the precedence specs at the head of this file.
13006 : : *
13007 : : * As with select_no_parens, simple_select cannot have outer parentheses,
13008 : : * but can have parenthesized subclauses.
13009 : : *
13010 : : * It might appear that we could fold the first two alternatives into one
13011 : : * by using opt_distinct_clause. However, that causes a shift/reduce conflict
13012 : : * against INSERT ... SELECT ... ON CONFLICT. We avoid the ambiguity by
13013 : : * requiring SELECT DISTINCT [ON] to be followed by a non-empty target_list.
13014 : : *
13015 : : * Note that sort clauses cannot be included at this level --- SQL requires
13016 : : * SELECT foo UNION SELECT bar ORDER BY baz
13017 : : * to be parsed as
13018 : : * (SELECT foo UNION SELECT bar) ORDER BY baz
13019 : : * not
13020 : : * SELECT foo UNION (SELECT bar ORDER BY baz)
13021 : : * Likewise for WITH, FOR UPDATE and LIMIT. Therefore, those clauses are
13022 : : * described as part of the select_no_parens production, not simple_select.
13023 : : * This does not limit functionality, because you can reintroduce these
13024 : : * clauses inside parentheses.
13025 : : *
13026 : : * NOTE: only the leftmost component SelectStmt should have INTO.
13027 : : * However, this is not checked by the grammar; parse analysis must check it.
13028 : : */
13029 : : simple_select:
13030 : : SELECT opt_all_clause opt_target_list
13031 : : into_clause from_clause where_clause
13032 : : group_clause having_clause window_clause
13033 : : {
3825 andres@anarazel.de 13034 : 216993 : SelectStmt *n = makeNode(SelectStmt);
13035 : :
13036 : 216992 : n->targetList = $3;
13037 : 216992 : n->intoClause = $4;
13038 : 216992 : n->fromClause = $5;
13039 : 216992 : n->whereClause = $6;
1684 tomas.vondra@postgre 13040 : 216992 : n->groupClause = ($7)->list;
13041 : 216992 : n->groupDistinct = ($7)->distinct;
28 tgl@sss.pgh.pa.us 13042 :GNC 216992 : n->groupByAll = ($7)->all;
3825 andres@anarazel.de 13043 :CBC 216992 : n->havingClause = $8;
13044 : 216992 : n->windowClause = $9;
1263 peter@eisentraut.org 13045 : 216992 : $$ = (Node *) n;
13046 : : }
13047 : : | SELECT distinct_clause target_list
13048 : : into_clause from_clause where_clause
13049 : : group_clause having_clause window_clause
13050 : : {
10153 bruce@momjian.us 13051 : 2005 : SelectStmt *n = makeNode(SelectStmt);
13052 : :
9405 tgl@sss.pgh.pa.us 13053 : 2005 : n->distinctClause = $2;
10276 bruce@momjian.us 13054 : 2005 : n->targetList = $3;
6758 tgl@sss.pgh.pa.us 13055 : 2005 : n->intoClause = $4;
10276 bruce@momjian.us 13056 : 2005 : n->fromClause = $5;
13057 : 2005 : n->whereClause = $6;
1684 tomas.vondra@postgre 13058 : 2005 : n->groupClause = ($7)->list;
13059 : 2005 : n->groupDistinct = ($7)->distinct;
28 tgl@sss.pgh.pa.us 13060 :GNC 2005 : n->groupByAll = ($7)->all;
10276 bruce@momjian.us 13061 :CBC 2005 : n->havingClause = $8;
6147 tgl@sss.pgh.pa.us 13062 : 2005 : n->windowClause = $9;
1263 peter@eisentraut.org 13063 : 2005 : $$ = (Node *) n;
13064 : : }
7026 mail@joeconway.com 13065 : 31197 : | values_clause { $$ = $1; }
13066 : : | TABLE relation_expr
13067 : : {
13068 : : /* same as SELECT * FROM relation_expr */
1263 peter@eisentraut.org 13069 : 159 : ColumnRef *cr = makeNode(ColumnRef);
13070 : 159 : ResTarget *rt = makeNode(ResTarget);
6185 peter_e@gmx.net 13071 : 159 : SelectStmt *n = makeNode(SelectStmt);
13072 : :
13073 : 159 : cr->fields = list_make1(makeNode(A_Star));
13074 : 159 : cr->location = -1;
13075 : :
13076 : 159 : rt->name = NULL;
13077 : 159 : rt->indirection = NIL;
1263 peter@eisentraut.org 13078 : 159 : rt->val = (Node *) cr;
6185 peter_e@gmx.net 13079 : 159 : rt->location = -1;
13080 : :
13081 : 159 : n->targetList = list_make1(rt);
13082 : 159 : n->fromClause = list_make1($2);
1263 peter@eisentraut.org 13083 : 159 : $$ = (Node *) n;
13084 : : }
13085 : : | select_clause UNION set_quantifier select_clause
13086 : : {
137 michael@paquier.xyz 13087 : 9504 : $$ = makeSetOp(SETOP_UNION, $3 == SET_QUANTIFIER_ALL, $1, $4);
13088 : : }
13089 : : | select_clause INTERSECT set_quantifier select_clause
13090 : : {
13091 : 138 : $$ = makeSetOp(SETOP_INTERSECT, $3 == SET_QUANTIFIER_ALL, $1, $4);
13092 : : }
13093 : : | select_clause EXCEPT set_quantifier select_clause
13094 : : {
13095 : 244 : $$ = makeSetOp(SETOP_EXCEPT, $3 == SET_QUANTIFIER_ALL, $1, $4);
13096 : : }
13097 : : ;
13098 : :
13099 : : /*
13100 : : * SQL standard WITH clause looks like:
13101 : : *
13102 : : * WITH [ RECURSIVE ] <query name> [ (<column>,...) ]
13103 : : * AS (query) [ SEARCH or CYCLE clause ]
13104 : : *
13105 : : * Recognizing WITH_LA here allows a CTE to be named TIME or ORDINALITY.
13106 : : */
13107 : : with_clause:
13108 : : WITH cte_list
13109 : : {
6232 tgl@sss.pgh.pa.us 13110 : 1045 : $$ = makeNode(WithClause);
13111 : 1045 : $$->ctes = $2;
13112 : 1045 : $$->recursive = false;
13113 : 1045 : $$->location = @1;
13114 : : }
13115 : : | WITH_LA cte_list
13116 : : {
3898 13117 : 3 : $$ = makeNode(WithClause);
13118 : 3 : $$->ctes = $2;
13119 : 3 : $$->recursive = false;
13120 : 3 : $$->location = @1;
13121 : : }
13122 : : | WITH RECURSIVE cte_list
13123 : : {
6232 13124 : 629 : $$ = makeNode(WithClause);
13125 : 629 : $$->ctes = $3;
13126 : 629 : $$->recursive = true;
13127 : 629 : $$->location = @1;
13128 : : }
13129 : : ;
13130 : :
13131 : : cte_list:
13132 : 1677 : common_table_expr { $$ = list_make1($1); }
13133 : 639 : | cte_list ',' common_table_expr { $$ = lappend($1, $3); }
13134 : : ;
13135 : :
13136 : : common_table_expr: name opt_name_list AS opt_materialized '(' PreparableStmt ')' opt_search_clause opt_cycle_clause
13137 : : {
13138 : 2316 : CommonTableExpr *n = makeNode(CommonTableExpr);
13139 : :
13140 : 2316 : n->ctename = $1;
13141 : 2316 : n->aliascolnames = $2;
2445 13142 : 2316 : n->ctematerialized = $4;
13143 : 2316 : n->ctequery = $6;
1729 peter@eisentraut.org 13144 : 2316 : n->search_clause = castNode(CTESearchClause, $8);
13145 : 2316 : n->cycle_clause = castNode(CTECycleClause, $9);
6232 tgl@sss.pgh.pa.us 13146 : 2316 : n->location = @1;
13147 : 2316 : $$ = (Node *) n;
13148 : : }
13149 : : ;
13150 : :
13151 : : opt_materialized:
2445 13152 : 89 : MATERIALIZED { $$ = CTEMaterializeAlways; }
13153 : 24 : | NOT MATERIALIZED { $$ = CTEMaterializeNever; }
13154 : 2203 : | /*EMPTY*/ { $$ = CTEMaterializeDefault; }
13155 : : ;
13156 : :
13157 : : opt_search_clause:
13158 : : SEARCH DEPTH FIRST_P BY columnList SET ColId
13159 : : {
1729 peter@eisentraut.org 13160 : 45 : CTESearchClause *n = makeNode(CTESearchClause);
13161 : :
13162 : 45 : n->search_col_list = $5;
13163 : 45 : n->search_breadth_first = false;
13164 : 45 : n->search_seq_column = $7;
13165 : 45 : n->location = @1;
13166 : 45 : $$ = (Node *) n;
13167 : : }
13168 : : | SEARCH BREADTH FIRST_P BY columnList SET ColId
13169 : : {
13170 : 18 : CTESearchClause *n = makeNode(CTESearchClause);
13171 : :
13172 : 18 : n->search_col_list = $5;
13173 : 18 : n->search_breadth_first = true;
13174 : 18 : n->search_seq_column = $7;
13175 : 18 : n->location = @1;
13176 : 18 : $$ = (Node *) n;
13177 : : }
13178 : : | /*EMPTY*/
13179 : : {
13180 : 2253 : $$ = NULL;
13181 : : }
13182 : : ;
13183 : :
13184 : : opt_cycle_clause:
13185 : : CYCLE columnList SET ColId TO AexprConst DEFAULT AexprConst USING ColId
13186 : : {
13187 : 33 : CTECycleClause *n = makeNode(CTECycleClause);
13188 : :
13189 : 33 : n->cycle_col_list = $2;
13190 : 33 : n->cycle_mark_column = $4;
13191 : 33 : n->cycle_mark_value = $6;
13192 : 33 : n->cycle_mark_default = $8;
13193 : 33 : n->cycle_path_column = $10;
13194 : 33 : n->location = @1;
13195 : 33 : $$ = (Node *) n;
13196 : : }
13197 : : | CYCLE columnList SET ColId USING ColId
13198 : : {
1703 13199 : 30 : CTECycleClause *n = makeNode(CTECycleClause);
13200 : :
13201 : 30 : n->cycle_col_list = $2;
13202 : 30 : n->cycle_mark_column = $4;
13203 : 30 : n->cycle_mark_value = makeBoolAConst(true, -1);
13204 : 30 : n->cycle_mark_default = makeBoolAConst(false, -1);
13205 : 30 : n->cycle_path_column = $6;
13206 : 30 : n->location = @1;
13207 : 30 : $$ = (Node *) n;
13208 : : }
13209 : : | /*EMPTY*/
13210 : : {
1729 13211 : 2253 : $$ = NULL;
13212 : : }
13213 : : ;
13214 : :
13215 : : opt_with_clause:
5491 tgl@sss.pgh.pa.us 13216 : 228 : with_clause { $$ = $1; }
13217 : 46423 : | /*EMPTY*/ { $$ = NULL; }
13218 : : ;
13219 : :
13220 : : into_clause:
13221 : : INTO OptTempTableName
13222 : : {
6824 13223 : 68 : $$ = makeNode(IntoClause);
13224 : 68 : $$->rel = $2;
13225 : 68 : $$->colNames = NIL;
13226 : 68 : $$->options = NIL;
13227 : 68 : $$->onCommit = ONCOMMIT_NOOP;
13228 : 68 : $$->tableSpaceName = NULL;
4581 13229 : 68 : $$->viewQuery = NULL;
5086 13230 : 68 : $$->skipData = false;
13231 : : }
13232 : : | /*EMPTY*/
6824 13233 : 218945 : { $$ = NULL; }
13234 : : ;
13235 : :
13236 : : /*
13237 : : * Redundancy here is needed to avoid shift/reduce conflicts,
13238 : : * since TEMP is not a reserved word. See also OptTemp.
13239 : : */
13240 : : OptTempTableName:
13241 : : TEMPORARY opt_table qualified_name
13242 : : {
8621 tgl@sss.pgh.pa.us 13243 :UBC 0 : $$ = $3;
5432 rhaas@postgresql.org 13244 : 0 : $$->relpersistence = RELPERSISTENCE_TEMP;
13245 : : }
13246 : : | TEMP opt_table qualified_name
13247 : : {
8621 tgl@sss.pgh.pa.us 13248 :CBC 3 : $$ = $3;
5432 rhaas@postgresql.org 13249 : 3 : $$->relpersistence = RELPERSISTENCE_TEMP;
13250 : : }
13251 : : | LOCAL TEMPORARY opt_table qualified_name
13252 : : {
8621 tgl@sss.pgh.pa.us 13253 :UBC 0 : $$ = $4;
5432 rhaas@postgresql.org 13254 : 0 : $$->relpersistence = RELPERSISTENCE_TEMP;
13255 : : }
13256 : : | LOCAL TEMP opt_table qualified_name
13257 : : {
8621 tgl@sss.pgh.pa.us 13258 : 0 : $$ = $4;
5432 rhaas@postgresql.org 13259 : 0 : $$->relpersistence = RELPERSISTENCE_TEMP;
13260 : : }
13261 : : | GLOBAL TEMPORARY opt_table qualified_name
13262 : : {
4884 tgl@sss.pgh.pa.us 13263 [ # # ]: 0 : ereport(WARNING,
13264 : : (errmsg("GLOBAL is deprecated in temporary table creation"),
13265 : : parser_errposition(@1)));
8621 13266 : 0 : $$ = $4;
5432 rhaas@postgresql.org 13267 : 0 : $$->relpersistence = RELPERSISTENCE_TEMP;
13268 : : }
13269 : : | GLOBAL TEMP opt_table qualified_name
13270 : : {
4884 tgl@sss.pgh.pa.us 13271 [ # # ]: 0 : ereport(WARNING,
13272 : : (errmsg("GLOBAL is deprecated in temporary table creation"),
13273 : : parser_errposition(@1)));
8621 13274 : 0 : $$ = $4;
5432 rhaas@postgresql.org 13275 : 0 : $$->relpersistence = RELPERSISTENCE_TEMP;
13276 : : }
13277 : : | UNLOGGED opt_table qualified_name
13278 : : {
5416 13279 : 0 : $$ = $3;
13280 : 0 : $$->relpersistence = RELPERSISTENCE_UNLOGGED;
13281 : : }
13282 : : | TABLE qualified_name
13283 : : {
8621 tgl@sss.pgh.pa.us 13284 :CBC 15 : $$ = $2;
5432 rhaas@postgresql.org 13285 : 15 : $$->relpersistence = RELPERSISTENCE_PERMANENT;
13286 : : }
13287 : : | qualified_name
13288 : : {
8621 tgl@sss.pgh.pa.us 13289 : 50 : $$ = $1;
5432 rhaas@postgresql.org 13290 : 50 : $$->relpersistence = RELPERSISTENCE_PERMANENT;
13291 : : }
13292 : : ;
13293 : :
13294 : : opt_table: TABLE
13295 : : | /*EMPTY*/
13296 : : ;
13297 : :
13298 : : set_quantifier:
1684 tomas.vondra@postgre 13299 : 5548 : ALL { $$ = SET_QUANTIFIER_ALL; }
13300 : 16 : | DISTINCT { $$ = SET_QUANTIFIER_DISTINCT; }
13301 : 6782 : | /*EMPTY*/ { $$ = SET_QUANTIFIER_DEFAULT; }
13302 : : ;
13303 : :
13304 : : /* We use (NIL) as a placeholder to indicate that all target expressions
13305 : : * should be placed in the DISTINCT list during parsetree analysis.
13306 : : */
13307 : : distinct_clause:
7820 neilc@samurai.com 13308 : 1875 : DISTINCT { $$ = list_make1(NIL); }
8533 bruce@momjian.us 13309 : 133 : | DISTINCT ON '(' expr_list ')' { $$ = $4; }
13310 : : ;
13311 : :
13312 : : opt_all_clause:
13313 : : ALL
13314 : : | /*EMPTY*/
13315 : : ;
13316 : :
13317 : : opt_distinct_clause:
1739 tgl@sss.pgh.pa.us 13318 :UBC 0 : distinct_clause { $$ = $1; }
1739 tgl@sss.pgh.pa.us 13319 :CBC 20812 : | opt_all_clause { $$ = NIL; }
13320 : : ;
13321 : :
13322 : : opt_sort_clause:
13323 : 3762 : sort_clause { $$ = $1; }
8461 bruce@momjian.us 13324 : 183891 : | /*EMPTY*/ { $$ = NIL; }
13325 : : ;
13326 : :
13327 : : sort_clause:
8533 13328 : 39745 : ORDER BY sortby_list { $$ = $3; }
13329 : : ;
13330 : :
13331 : : sortby_list:
7820 neilc@samurai.com 13332 : 39754 : sortby { $$ = list_make1($1); }
8533 bruce@momjian.us 13333 : 14418 : | sortby_list ',' sortby { $$ = lappend($1, $3); }
13334 : : ;
13335 : :
13336 : : sortby: a_expr USING qual_all_Op opt_nulls_order
13337 : : {
8107 tgl@sss.pgh.pa.us 13338 : 110 : $$ = makeNode(SortBy);
9945 scrappy@hub.org 13339 : 110 : $$->node = $1;
6866 tgl@sss.pgh.pa.us 13340 : 110 : $$->sortby_dir = SORTBY_USING;
13341 : 110 : $$->sortby_nulls = $4;
8107 13342 : 110 : $$->useOp = $3;
6265 13343 : 110 : $$->location = @3;
13344 : : }
13345 : : | a_expr opt_asc_desc opt_nulls_order
13346 : : {
8107 13347 : 54062 : $$ = makeNode(SortBy);
13348 : 54062 : $$->node = $1;
6799 meskes@postgresql.or 13349 : 54062 : $$->sortby_dir = $2;
6866 tgl@sss.pgh.pa.us 13350 : 54062 : $$->sortby_nulls = $3;
8107 13351 : 54062 : $$->useOp = NIL;
6265 13352 : 54062 : $$->location = -1; /* no operator */
13353 : : }
13354 : : ;
13355 : :
13356 : :
13357 : : select_limit:
13358 : : limit_clause offset_clause
13359 : : {
2029 alvherre@alvh.no-ip. 13360 : 86 : $$ = $1;
13361 : 86 : ($$)->limitOffset = $2;
361 tgl@sss.pgh.pa.us 13362 : 86 : ($$)->offsetLoc = @2;
13363 : : }
13364 : : | offset_clause limit_clause
13365 : : {
2029 alvherre@alvh.no-ip. 13366 : 111 : $$ = $2;
13367 : 111 : ($$)->limitOffset = $1;
361 tgl@sss.pgh.pa.us 13368 : 111 : ($$)->offsetLoc = @1;
13369 : : }
13370 : : | limit_clause
13371 : : {
2029 alvherre@alvh.no-ip. 13372 : 2141 : $$ = $1;
13373 : : }
13374 : : | offset_clause
13375 : : {
13376 : 233 : SelectLimit *n = (SelectLimit *) palloc(sizeof(SelectLimit));
13377 : :
13378 : 233 : n->limitOffset = $1;
13379 : 233 : n->limitCount = NULL;
13380 : 233 : n->limitOption = LIMIT_OPTION_COUNT;
361 tgl@sss.pgh.pa.us 13381 : 233 : n->offsetLoc = @1;
13382 : 233 : n->countLoc = -1;
13383 : 233 : n->optionLoc = -1;
2029 alvherre@alvh.no-ip. 13384 : 233 : $$ = n;
13385 : : }
13386 : : ;
13387 : :
13388 : : opt_select_limit:
5914 tgl@sss.pgh.pa.us 13389 : 95 : select_limit { $$ = $1; }
2029 alvherre@alvh.no-ip. 13390 : 23208 : | /* EMPTY */ { $$ = NULL; }
13391 : : ;
13392 : :
13393 : : limit_clause:
13394 : : LIMIT select_limit_value
13395 : : {
13396 : 2290 : SelectLimit *n = (SelectLimit *) palloc(sizeof(SelectLimit));
13397 : :
13398 : 2290 : n->limitOffset = NULL;
13399 : 2290 : n->limitCount = $2;
13400 : 2290 : n->limitOption = LIMIT_OPTION_COUNT;
361 tgl@sss.pgh.pa.us 13401 : 2290 : n->offsetLoc = -1;
13402 : 2290 : n->countLoc = @1;
13403 : 2290 : n->optionLoc = -1;
2029 alvherre@alvh.no-ip. 13404 : 2290 : $$ = n;
13405 : : }
13406 : : | LIMIT select_limit_value ',' select_offset_value
13407 : : {
13408 : : /* Disabled because it was too confusing, bjm 2002-02-18 */
8136 tgl@sss.pgh.pa.us 13409 [ # # ]:UBC 0 : ereport(ERROR,
13410 : : (errcode(ERRCODE_SYNTAX_ERROR),
13411 : : errmsg("LIMIT #,# syntax is not supported"),
13412 : : errhint("Use separate LIMIT and OFFSET clauses."),
13413 : : parser_errposition(@1)));
13414 : : }
13415 : : /* SQL:2008 syntax */
13416 : : /* to avoid shift/reduce conflicts, handle the optional value with
13417 : : * a separate production rather than an opt_ expression. The fact
13418 : : * that ONLY is fully reserved means that this way, we defer any
13419 : : * decision about what rule reduces ROW or ROWS to the point where
13420 : : * we can see the ONLY token in the lookahead slot.
13421 : : */
13422 : : | FETCH first_or_next select_fetch_first_value row_or_rows ONLY
13423 : : {
2029 alvherre@alvh.no-ip. 13424 :CBC 12 : SelectLimit *n = (SelectLimit *) palloc(sizeof(SelectLimit));
13425 : :
13426 : 12 : n->limitOffset = NULL;
13427 : 12 : n->limitCount = $3;
13428 : 12 : n->limitOption = LIMIT_OPTION_COUNT;
361 tgl@sss.pgh.pa.us 13429 : 12 : n->offsetLoc = -1;
13430 : 12 : n->countLoc = @1;
13431 : 12 : n->optionLoc = -1;
2029 alvherre@alvh.no-ip. 13432 : 12 : $$ = n;
13433 : : }
13434 : : | FETCH first_or_next select_fetch_first_value row_or_rows WITH TIES
13435 : : {
13436 : 33 : SelectLimit *n = (SelectLimit *) palloc(sizeof(SelectLimit));
13437 : :
13438 : 33 : n->limitOffset = NULL;
13439 : 33 : n->limitCount = $3;
13440 : 33 : n->limitOption = LIMIT_OPTION_WITH_TIES;
361 tgl@sss.pgh.pa.us 13441 : 33 : n->offsetLoc = -1;
13442 : 33 : n->countLoc = @1;
13443 : 33 : n->optionLoc = @5;
2029 alvherre@alvh.no-ip. 13444 : 33 : $$ = n;
13445 : : }
13446 : : | FETCH first_or_next row_or_rows ONLY
13447 : : {
2029 alvherre@alvh.no-ip. 13448 :UBC 0 : SelectLimit *n = (SelectLimit *) palloc(sizeof(SelectLimit));
13449 : :
13450 : 0 : n->limitOffset = NULL;
13451 : 0 : n->limitCount = makeIntConst(1, -1);
13452 : 0 : n->limitOption = LIMIT_OPTION_COUNT;
361 tgl@sss.pgh.pa.us 13453 : 0 : n->offsetLoc = -1;
13454 : 0 : n->countLoc = @1;
13455 : 0 : n->optionLoc = -1;
2029 alvherre@alvh.no-ip. 13456 : 0 : $$ = n;
13457 : : }
13458 : : | FETCH first_or_next row_or_rows WITH TIES
13459 : : {
1988 alvherre@alvh.no-ip. 13460 :CBC 3 : SelectLimit *n = (SelectLimit *) palloc(sizeof(SelectLimit));
13461 : :
13462 : 3 : n->limitOffset = NULL;
13463 : 3 : n->limitCount = makeIntConst(1, -1);
13464 : 3 : n->limitOption = LIMIT_OPTION_WITH_TIES;
361 tgl@sss.pgh.pa.us 13465 : 3 : n->offsetLoc = -1;
13466 : 3 : n->countLoc = @1;
13467 : 3 : n->optionLoc = @4;
1988 alvherre@alvh.no-ip. 13468 : 3 : $$ = n;
13469 : : }
13470 : : ;
13471 : :
13472 : : offset_clause:
13473 : : OFFSET select_offset_value
5914 tgl@sss.pgh.pa.us 13474 : 430 : { $$ = $2; }
13475 : : /* SQL:2008 syntax */
13476 : : | OFFSET select_fetch_first_value row_or_rows
5914 tgl@sss.pgh.pa.us 13477 :UBC 0 : { $$ = $2; }
13478 : : ;
13479 : :
13480 : : select_limit_value:
8152 tgl@sss.pgh.pa.us 13481 :CBC 2289 : a_expr { $$ = $1; }
13482 : : | ALL
13483 : : {
13484 : : /* LIMIT ALL is represented as a NULL constant */
6269 13485 : 1 : $$ = makeNullAConst(@1);
13486 : : }
13487 : : ;
13488 : :
13489 : : select_offset_value:
5914 13490 : 430 : a_expr { $$ = $1; }
13491 : : ;
13492 : :
13493 : : /*
13494 : : * Allowing full expressions without parentheses causes various parsing
13495 : : * problems with the trailing ROW/ROWS key words. SQL spec only calls for
13496 : : * <simple value specification>, which is either a literal or a parameter (but
13497 : : * an <SQL parameter reference> could be an identifier, bringing up conflicts
13498 : : * with ROW/ROWS). We solve this by leveraging the presence of ONLY (see above)
13499 : : * to determine whether the expression is missing rather than trying to make it
13500 : : * optional in this rule.
13501 : : *
13502 : : * c_expr covers almost all the spec-required cases (and more), but it doesn't
13503 : : * cover signed numeric literals, which are allowed by the spec. So we include
13504 : : * those here explicitly. We need FCONST as well as ICONST because values that
13505 : : * don't fit in the platform's "long", but do fit in bigint, should still be
13506 : : * accepted here. (This is possible in 64-bit Windows as well as all 32-bit
13507 : : * builds.)
13508 : : */
13509 : : select_fetch_first_value:
2716 rhodiumtoad@postgres 13510 : 45 : c_expr { $$ = $1; }
13511 : : | '+' I_or_F_const
2716 rhodiumtoad@postgres 13512 :UBC 0 : { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "+", NULL, $2, @1); }
13513 : : | '-' I_or_F_const
13514 : 0 : { $$ = doNegate($2, @1); }
13515 : : ;
13516 : :
13517 : : I_or_F_const:
13518 : 0 : Iconst { $$ = makeIntConst($1,@1); }
13519 : 0 : | FCONST { $$ = makeFloatConst($1,@1); }
13520 : : ;
13521 : :
13522 : : /* noise words */
5914 tgl@sss.pgh.pa.us 13523 :CBC 18 : row_or_rows: ROW { $$ = 0; }
13524 : 30 : | ROWS { $$ = 0; }
13525 : : ;
13526 : :
13527 : 48 : first_or_next: FIRST_P { $$ = 0; }
5914 tgl@sss.pgh.pa.us 13528 :UBC 0 : | NEXT { $$ = 0; }
13529 : : ;
13530 : :
13531 : :
13532 : : /*
13533 : : * This syntax for group_clause tries to follow the spec quite closely.
13534 : : * However, the spec allows only column references, not expressions,
13535 : : * which introduces an ambiguity between implicit row constructors
13536 : : * (a,b) and lists of column references.
13537 : : *
13538 : : * We handle this by using the a_expr production for what the spec calls
13539 : : * <ordinary grouping set>, which in the spec represents either one column
13540 : : * reference or a parenthesized list of column references. Then, we check the
13541 : : * top node of the a_expr to see if it's an implicit RowExpr, and if so, just
13542 : : * grab and use the list, discarding the node. (this is done in parse analysis,
13543 : : * not here)
13544 : : *
13545 : : * (we abuse the row_format field of RowExpr to distinguish implicit and
13546 : : * explicit row constructors; it's debatable if anyone sanely wants to use them
13547 : : * in a group clause, but if they have a reason to, we make it possible.)
13548 : : *
13549 : : * Each item in the group_clause list is either an expression tree or a
13550 : : * GroupingSet node of some type.
13551 : : */
13552 : : group_clause:
13553 : : GROUP_P BY set_quantifier group_by_list
13554 : : {
1684 tomas.vondra@postgre 13555 :CBC 2454 : GroupClause *n = (GroupClause *) palloc(sizeof(GroupClause));
13556 : :
13557 : 2454 : n->distinct = $3 == SET_QUANTIFIER_DISTINCT;
28 tgl@sss.pgh.pa.us 13558 :GNC 2454 : n->all = false;
1684 tomas.vondra@postgre 13559 :CBC 2454 : n->list = $4;
13560 : 2454 : $$ = n;
13561 : : }
13562 : : | GROUP_P BY ALL
13563 : : {
28 tgl@sss.pgh.pa.us 13564 :GNC 33 : GroupClause *n = (GroupClause *) palloc(sizeof(GroupClause));
13565 : 33 : n->distinct = false;
13566 : 33 : n->all = true;
13567 : 33 : n->list = NIL;
13568 : 33 : $$ = n;
13569 : : }
13570 : : | /*EMPTY*/
13571 : : {
1684 tomas.vondra@postgre 13572 :CBC 237323 : GroupClause *n = (GroupClause *) palloc(sizeof(GroupClause));
13573 : :
13574 : 237322 : n->distinct = false;
28 tgl@sss.pgh.pa.us 13575 :GNC 237322 : n->all = false;
1684 tomas.vondra@postgre 13576 :CBC 237322 : n->list = NIL;
13577 : 237322 : $$ = n;
13578 : : }
13579 : : ;
13580 : :
13581 : : group_by_list:
3817 andres@anarazel.de 13582 : 2771 : group_by_item { $$ = list_make1($1); }
13583 : 1532 : | group_by_list ',' group_by_item { $$ = lappend($1,$3); }
13584 : : ;
13585 : :
13586 : : group_by_item:
13587 : 3622 : a_expr { $$ = $1; }
13588 : 123 : | empty_grouping_set { $$ = $1; }
13589 : 92 : | cube_clause { $$ = $1; }
13590 : 149 : | rollup_clause { $$ = $1; }
13591 : 317 : | grouping_sets_clause { $$ = $1; }
13592 : : ;
13593 : :
13594 : : empty_grouping_set:
13595 : : '(' ')'
13596 : : {
13597 : 123 : $$ = (Node *) makeGroupingSet(GROUPING_SET_EMPTY, NIL, @1);
13598 : : }
13599 : : ;
13600 : :
13601 : : /*
13602 : : * These hacks rely on setting precedence of CUBE and ROLLUP below that of '(',
13603 : : * so that they shift in these rules rather than reducing the conflicting
13604 : : * unreserved_keyword rule.
13605 : : */
13606 : :
13607 : : rollup_clause:
13608 : : ROLLUP '(' expr_list ')'
13609 : : {
13610 : 149 : $$ = (Node *) makeGroupingSet(GROUPING_SET_ROLLUP, $3, @1);
13611 : : }
13612 : : ;
13613 : :
13614 : : cube_clause:
13615 : : CUBE '(' expr_list ')'
13616 : : {
13617 : 92 : $$ = (Node *) makeGroupingSet(GROUPING_SET_CUBE, $3, @1);
13618 : : }
13619 : : ;
13620 : :
13621 : : grouping_sets_clause:
13622 : : GROUPING SETS '(' group_by_list ')'
13623 : : {
13624 : 317 : $$ = (Node *) makeGroupingSet(GROUPING_SET_SETS, $4, @1);
13625 : : }
13626 : : ;
13627 : :
13628 : : having_clause:
8533 bruce@momjian.us 13629 : 390 : HAVING a_expr { $$ = $2; }
13630 : 239420 : | /*EMPTY*/ { $$ = NULL; }
13631 : : ;
13632 : :
13633 : : for_locking_clause:
7120 tgl@sss.pgh.pa.us 13634 : 2661 : for_locking_items { $$ = $1; }
7120 tgl@sss.pgh.pa.us 13635 :UBC 0 : | FOR READ ONLY { $$ = NIL; }
13636 : : ;
13637 : :
13638 : : opt_for_locking_clause:
7120 tgl@sss.pgh.pa.us 13639 :CBC 170 : for_locking_clause { $$ = $1; }
13640 : 23118 : | /* EMPTY */ { $$ = NIL; }
13641 : : ;
13642 : :
13643 : : for_locking_items:
13644 : 2661 : for_locking_item { $$ = list_make1($1); }
13645 : 51 : | for_locking_items for_locking_item { $$ = lappend($1, $2); }
13646 : : ;
13647 : :
13648 : : for_locking_item:
13649 : : for_locking_strength locked_rels_list opt_nowait_or_skip
13650 : : {
7392 13651 : 2712 : LockingClause *n = makeNode(LockingClause);
13652 : :
4660 alvherre@alvh.no-ip. 13653 : 2712 : n->lockedRels = $2;
13654 : 2712 : n->strength = $1;
4038 13655 : 2712 : n->waitPolicy = $3;
7392 tgl@sss.pgh.pa.us 13656 : 2712 : $$ = (Node *) n;
13657 : : }
13658 : : ;
13659 : :
13660 : : for_locking_strength:
1811 peter@eisentraut.org 13661 : 769 : FOR UPDATE { $$ = LCS_FORUPDATE; }
13662 : 38 : | FOR NO KEY UPDATE { $$ = LCS_FORNOKEYUPDATE; }
13663 : 107 : | FOR SHARE { $$ = LCS_FORSHARE; }
13664 : 1798 : | FOR KEY SHARE { $$ = LCS_FORKEYSHARE; }
13665 : : ;
13666 : :
13667 : : locked_rels_list:
6265 tgl@sss.pgh.pa.us 13668 : 1811 : OF qualified_name_list { $$ = $2; }
7392 13669 : 901 : | /* EMPTY */ { $$ = NIL; }
13670 : : ;
13671 : :
13672 : :
13673 : : /*
13674 : : * We should allow ROW '(' expr_list ')' too, but that seems to require
13675 : : * making VALUES a fully reserved word, which will probably break more apps
13676 : : * than allowing the noise-word is worth.
13677 : : */
13678 : : values_clause:
13679 : : VALUES '(' expr_list ')'
13680 : : {
7026 mail@joeconway.com 13681 : 31197 : SelectStmt *n = makeNode(SelectStmt);
13682 : :
3261 tgl@sss.pgh.pa.us 13683 : 31197 : n->valuesLists = list_make1($3);
7026 mail@joeconway.com 13684 : 31197 : $$ = (Node *) n;
13685 : : }
13686 : : | values_clause ',' '(' expr_list ')'
13687 : : {
13688 : 12603 : SelectStmt *n = (SelectStmt *) $1;
13689 : :
3261 tgl@sss.pgh.pa.us 13690 : 12603 : n->valuesLists = lappend(n->valuesLists, $4);
7026 mail@joeconway.com 13691 : 12603 : $$ = (Node *) n;
13692 : : }
13693 : : ;
13694 : :
13695 : :
13696 : : /*****************************************************************************
13697 : : *
13698 : : * clauses common to all Optimizable Stmts:
13699 : : * from_clause - allow list of both JOIN expressions and table names
13700 : : * where_clause - qualifications for joins or restrictions
13701 : : *
13702 : : *****************************************************************************/
13703 : :
13704 : : from_clause:
8533 bruce@momjian.us 13705 : 159760 : FROM from_list { $$ = $2; }
13706 : 87219 : | /*EMPTY*/ { $$ = NIL; }
13707 : : ;
13708 : :
13709 : : from_list:
7820 neilc@samurai.com 13710 : 160188 : table_ref { $$ = list_make1($1); }
8532 bruce@momjian.us 13711 : 31367 : | from_list ',' table_ref { $$ = lappend($1, $3); }
13712 : : ;
13713 : :
13714 : : /*
13715 : : * table_ref is where an alias clause can be attached.
13716 : : */
13717 : : table_ref: relation_expr opt_alias_clause
13718 : : {
8621 tgl@sss.pgh.pa.us 13719 : 201779 : $1->alias = $2;
9176 13720 : 201779 : $$ = (Node *) $1;
13721 : : }
13722 : : | relation_expr opt_alias_clause tablesample_clause
13723 : : {
3747 13724 : 133 : RangeTableSample *n = (RangeTableSample *) $3;
13725 : :
13726 : 133 : $1->alias = $2;
13727 : : /* relation_expr goes inside the RangeTableSample node */
13728 : 133 : n->relation = (Node *) $1;
13729 : 133 : $$ = (Node *) n;
13730 : : }
13731 : : | func_table func_alias_clause
13732 : : {
4358 13733 : 23660 : RangeFunction *n = (RangeFunction *) $1;
13734 : :
4829 13735 : 23660 : n->alias = linitial($2);
13736 : 23660 : n->coldeflist = lsecond($2);
8485 bruce@momjian.us 13737 : 23660 : $$ = (Node *) n;
13738 : : }
13739 : : | LATERAL_P func_table func_alias_clause
13740 : : {
4358 tgl@sss.pgh.pa.us 13741 : 640 : RangeFunction *n = (RangeFunction *) $2;
13742 : :
4829 13743 : 640 : n->lateral = true;
13744 : 640 : n->alias = linitial($3);
13745 : 640 : n->coldeflist = lsecond($3);
8569 13746 : 640 : $$ = (Node *) n;
13747 : : }
13748 : : | xmltable opt_alias_clause
13749 : : {
3155 alvherre@alvh.no-ip. 13750 : 43 : RangeTableFunc *n = (RangeTableFunc *) $1;
13751 : :
13752 : 43 : n->alias = $2;
13753 : 43 : $$ = (Node *) n;
13754 : : }
13755 : : | LATERAL_P xmltable opt_alias_clause
13756 : : {
13757 : 70 : RangeTableFunc *n = (RangeTableFunc *) $2;
13758 : :
13759 : 70 : n->lateral = true;
13760 : 70 : n->alias = $3;
13761 : 70 : $$ = (Node *) n;
13762 : : }
13763 : : | select_with_parens opt_alias_clause
13764 : : {
4829 tgl@sss.pgh.pa.us 13765 : 7086 : RangeSubselect *n = makeNode(RangeSubselect);
13766 : :
13767 : 7086 : n->lateral = false;
13768 : 7086 : n->subquery = $1;
13769 : 7086 : n->alias = $2;
13770 : 7086 : $$ = (Node *) n;
13771 : : }
13772 : : | LATERAL_P select_with_parens opt_alias_clause
13773 : : {
9176 13774 : 952 : RangeSubselect *n = makeNode(RangeSubselect);
13775 : :
4829 13776 : 952 : n->lateral = true;
13777 : 952 : n->subquery = $2;
13778 : 952 : n->alias = $3;
9176 13779 : 952 : $$ = (Node *) n;
13780 : : }
13781 : : | joined_table
13782 : : {
13783 : 41904 : $$ = (Node *) $1;
13784 : : }
13785 : : | '(' joined_table ')' alias_clause
13786 : : {
13787 : 87 : $2->alias = $4;
13788 : 87 : $$ = (Node *) $2;
13789 : : }
13790 : : | json_table opt_alias_clause
13791 : : {
571 amitlan@postgresql.o 13792 : 263 : JsonTable *jt = castNode(JsonTable, $1);
13793 : :
13794 : 263 : jt->alias = $2;
13795 : 263 : $$ = (Node *) jt;
13796 : : }
13797 : : | LATERAL_P json_table opt_alias_clause
13798 : : {
571 amitlan@postgresql.o 13799 :UBC 0 : JsonTable *jt = castNode(JsonTable, $2);
13800 : :
13801 : 0 : jt->alias = $3;
13802 : 0 : jt->lateral = true;
13803 : 0 : $$ = (Node *) jt;
13804 : : }
13805 : : ;
13806 : :
13807 : :
13808 : : /*
13809 : : * It may seem silly to separate joined_table from table_ref, but there is
13810 : : * method in SQL's madness: if you don't do it this way you get reduce-
13811 : : * reduce conflicts, because it's not clear to the parser generator whether
13812 : : * to expect alias_clause after ')' or not. For the same reason we must
13813 : : * treat 'JOIN' and 'join_type JOIN' separately, rather than allowing
13814 : : * join_type to expand to empty; if we try it, the parser generator can't
13815 : : * figure out when to reduce an empty join_type right after table_ref.
13816 : : *
13817 : : * Note that a CROSS JOIN is the same as an unqualified
13818 : : * INNER JOIN, and an INNER JOIN/ON has the same shape
13819 : : * but a qualification expression to limit membership.
13820 : : * A NATURAL JOIN implicitly matches column names between
13821 : : * tables and the shape is determined by which columns are
13822 : : * in common. We'll collect columns during the later transformations.
13823 : : */
13824 : :
13825 : : joined_table:
13826 : : '(' joined_table ')'
13827 : : {
9176 tgl@sss.pgh.pa.us 13828 :CBC 1983 : $$ = $2;
13829 : : }
13830 : : | table_ref CROSS JOIN table_ref
13831 : : {
13832 : : /* CROSS JOIN is same as unqualified inner join */
1263 peter@eisentraut.org 13833 : 256 : JoinExpr *n = makeNode(JoinExpr);
13834 : :
9176 tgl@sss.pgh.pa.us 13835 : 256 : n->jointype = JOIN_INNER;
2994 peter_e@gmx.net 13836 : 256 : n->isNatural = false;
9176 tgl@sss.pgh.pa.us 13837 : 256 : n->larg = $1;
13838 : 256 : n->rarg = $4;
5947 peter_e@gmx.net 13839 : 256 : n->usingClause = NIL;
1671 peter@eisentraut.org 13840 : 256 : n->join_using_alias = NULL;
9176 tgl@sss.pgh.pa.us 13841 : 256 : n->quals = NULL;
9386 lockhart@fourpalms.o 13842 : 256 : $$ = n;
13843 : : }
13844 : : | table_ref join_type JOIN table_ref join_qual
13845 : : {
1263 peter@eisentraut.org 13846 : 23656 : JoinExpr *n = makeNode(JoinExpr);
13847 : :
9176 tgl@sss.pgh.pa.us 13848 : 23656 : n->jointype = $2;
2994 peter_e@gmx.net 13849 : 23656 : n->isNatural = false;
9176 tgl@sss.pgh.pa.us 13850 : 23656 : n->larg = $1;
13851 : 23656 : n->rarg = $4;
13852 [ + - + + ]: 23656 : if ($5 != NULL && IsA($5, List))
13853 : : {
13854 : : /* USING clause */
1671 peter@eisentraut.org 13855 : 249 : n->usingClause = linitial_node(List, castNode(List, $5));
13856 : 249 : n->join_using_alias = lsecond_node(Alias, castNode(List, $5));
13857 : : }
13858 : : else
13859 : : {
13860 : : /* ON clause */
13861 : 23407 : n->quals = $5;
13862 : : }
9386 lockhart@fourpalms.o 13863 : 23656 : $$ = n;
13864 : : }
13865 : : | table_ref JOIN table_ref join_qual
13866 : : {
13867 : : /* letting join_type reduce to empty doesn't work */
1263 peter@eisentraut.org 13868 : 17947 : JoinExpr *n = makeNode(JoinExpr);
13869 : :
9176 tgl@sss.pgh.pa.us 13870 : 17947 : n->jointype = JOIN_INNER;
2994 peter_e@gmx.net 13871 : 17947 : n->isNatural = false;
9176 tgl@sss.pgh.pa.us 13872 : 17947 : n->larg = $1;
13873 : 17947 : n->rarg = $3;
13874 [ + - + + ]: 17947 : if ($4 != NULL && IsA($4, List))
13875 : : {
13876 : : /* USING clause */
1671 peter@eisentraut.org 13877 : 372 : n->usingClause = linitial_node(List, castNode(List, $4));
13878 : 372 : n->join_using_alias = lsecond_node(Alias, castNode(List, $4));
13879 : : }
13880 : : else
13881 : : {
13882 : : /* ON clause */
13883 : 17575 : n->quals = $4;
13884 : : }
9176 tgl@sss.pgh.pa.us 13885 : 17947 : $$ = n;
13886 : : }
13887 : : | table_ref NATURAL join_type JOIN table_ref
13888 : : {
1263 peter@eisentraut.org 13889 : 39 : JoinExpr *n = makeNode(JoinExpr);
13890 : :
9176 tgl@sss.pgh.pa.us 13891 : 39 : n->jointype = $3;
2994 peter_e@gmx.net 13892 : 39 : n->isNatural = true;
9176 tgl@sss.pgh.pa.us 13893 : 39 : n->larg = $1;
13894 : 39 : n->rarg = $5;
5947 peter_e@gmx.net 13895 : 39 : n->usingClause = NIL; /* figure out which columns later... */
1671 peter@eisentraut.org 13896 : 39 : n->join_using_alias = NULL;
9176 tgl@sss.pgh.pa.us 13897 : 39 : n->quals = NULL; /* fill later */
13898 : 39 : $$ = n;
13899 : : }
13900 : : | table_ref NATURAL JOIN table_ref
13901 : : {
13902 : : /* letting join_type reduce to empty doesn't work */
1263 peter@eisentraut.org 13903 : 93 : JoinExpr *n = makeNode(JoinExpr);
13904 : :
9176 tgl@sss.pgh.pa.us 13905 : 93 : n->jointype = JOIN_INNER;
2994 peter_e@gmx.net 13906 : 93 : n->isNatural = true;
9176 tgl@sss.pgh.pa.us 13907 : 93 : n->larg = $1;
13908 : 93 : n->rarg = $4;
5947 peter_e@gmx.net 13909 : 93 : n->usingClause = NIL; /* figure out which columns later... */
1671 peter@eisentraut.org 13910 : 93 : n->join_using_alias = NULL;
9176 tgl@sss.pgh.pa.us 13911 : 93 : n->quals = NULL; /* fill later */
9386 lockhart@fourpalms.o 13912 : 93 : $$ = n;
13913 : : }
13914 : : ;
13915 : :
13916 : : alias_clause:
13917 : : AS ColId '(' name_list ')'
13918 : : {
8621 tgl@sss.pgh.pa.us 13919 : 3363 : $$ = makeNode(Alias);
13920 : 3363 : $$->aliasname = $2;
13921 : 3363 : $$->colnames = $4;
13922 : : }
13923 : : | AS ColId
13924 : : {
13925 : 5449 : $$ = makeNode(Alias);
13926 : 5449 : $$->aliasname = $2;
13927 : : }
13928 : : | ColId '(' name_list ')'
13929 : : {
13930 : 2937 : $$ = makeNode(Alias);
13931 : 2937 : $$->aliasname = $1;
13932 : 2937 : $$->colnames = $3;
13933 : : }
13934 : : | ColId
13935 : : {
13936 : 135694 : $$ = makeNode(Alias);
13937 : 135694 : $$->aliasname = $1;
13938 : : }
13939 : : ;
13940 : :
4829 13941 : 132613 : opt_alias_clause: alias_clause { $$ = $1; }
13942 : 77713 : | /*EMPTY*/ { $$ = NULL; }
13943 : : ;
13944 : :
13945 : : /*
13946 : : * The alias clause after JOIN ... USING only accepts the AS ColId spelling,
13947 : : * per SQL standard. (The grammar could parse the other variants, but they
13948 : : * don't seem to be useful, and it might lead to parser problems in the
13949 : : * future.)
13950 : : */
13951 : : opt_alias_clause_for_join_using:
13952 : : AS ColId
13953 : : {
1671 peter@eisentraut.org 13954 : 42 : $$ = makeNode(Alias);
13955 : 42 : $$->aliasname = $2;
13956 : : /* the column name list will be inserted later */
13957 : : }
13958 : 579 : | /*EMPTY*/ { $$ = NULL; }
13959 : : ;
13960 : :
13961 : : /*
13962 : : * func_alias_clause can include both an Alias and a coldeflist, so we make it
13963 : : * return a 2-element list that gets disassembled by calling production.
13964 : : */
13965 : : func_alias_clause:
13966 : : alias_clause
13967 : : {
4829 tgl@sss.pgh.pa.us 13968 : 14743 : $$ = list_make2($1, NIL);
13969 : : }
13970 : : | AS '(' TableFuncElementList ')'
13971 : : {
13972 : 57 : $$ = list_make2(NULL, $3);
13973 : : }
13974 : : | AS ColId '(' TableFuncElementList ')'
13975 : : {
1263 peter@eisentraut.org 13976 : 304 : Alias *a = makeNode(Alias);
13977 : :
4829 tgl@sss.pgh.pa.us 13978 : 304 : a->aliasname = $2;
13979 : 304 : $$ = list_make2(a, $4);
13980 : : }
13981 : : | ColId '(' TableFuncElementList ')'
13982 : : {
1263 peter@eisentraut.org 13983 : 25 : Alias *a = makeNode(Alias);
13984 : :
4829 tgl@sss.pgh.pa.us 13985 : 25 : a->aliasname = $1;
13986 : 25 : $$ = list_make2(a, $3);
13987 : : }
13988 : : | /*EMPTY*/
13989 : : {
13990 : 9171 : $$ = list_make2(NULL, NIL);
13991 : : }
13992 : : ;
13993 : :
1810 peter@eisentraut.org 13994 : 521 : join_type: FULL opt_outer { $$ = JOIN_FULL; }
13995 : 20957 : | LEFT opt_outer { $$ = JOIN_LEFT; }
13996 : 195 : | RIGHT opt_outer { $$ = JOIN_RIGHT; }
8533 bruce@momjian.us 13997 : 2022 : | INNER_P { $$ = JOIN_INNER; }
13998 : : ;
13999 : :
14000 : : /* OUTER is just noise... */
14001 : : opt_outer: OUTER_P
14002 : : | /*EMPTY*/
14003 : : ;
14004 : :
14005 : : /* JOIN qualification clauses
14006 : : * Possibilities are:
14007 : : * USING ( column list ) [ AS alias ]
14008 : : * allows only unqualified column names,
14009 : : * which must match between tables.
14010 : : * ON expr allows more general qualifications.
14011 : : *
14012 : : * We return USING as a two-element List (the first item being a sub-List
14013 : : * of the common column names, and the second either an Alias item or NULL).
14014 : : * An ON-expr will not be a List, so it can be told apart that way.
14015 : : */
14016 : :
14017 : : join_qual: USING '(' name_list ')' opt_alias_clause_for_join_using
14018 : : {
1671 peter@eisentraut.org 14019 : 621 : $$ = (Node *) list_make2($3, $5);
14020 : : }
14021 : : | ON a_expr
14022 : : {
14023 : 40982 : $$ = $2;
14024 : : }
14025 : : ;
14026 : :
14027 : :
14028 : : relation_expr:
14029 : : qualified_name
14030 : : {
14031 : : /* inheritance query, implicitly */
8621 tgl@sss.pgh.pa.us 14032 : 242323 : $$ = $1;
3230 14033 : 242323 : $$->inh = true;
8621 14034 : 242323 : $$->alias = NULL;
14035 : : }
14036 : : | extended_relation_expr
14037 : : {
1461 akapila@postgresql.o 14038 : 3688 : $$ = $1;
14039 : : }
14040 : : ;
14041 : :
14042 : : extended_relation_expr:
14043 : : qualified_name '*'
14044 : : {
14045 : : /* inheritance query, explicitly */
8621 tgl@sss.pgh.pa.us 14046 : 102 : $$ = $1;
3230 14047 : 102 : $$->inh = true;
8621 14048 : 102 : $$->alias = NULL;
14049 : : }
14050 : : | ONLY qualified_name
14051 : : {
14052 : : /* no inheritance */
14053 : 3589 : $$ = $2;
3230 14054 : 3589 : $$->inh = false;
8621 14055 : 3589 : $$->alias = NULL;
14056 : : }
14057 : : | ONLY '(' qualified_name ')'
14058 : : {
14059 : : /* no inheritance, SQL99-style syntax */
8485 lockhart@fourpalms.o 14060 :UBC 0 : $$ = $3;
3230 tgl@sss.pgh.pa.us 14061 : 0 : $$->inh = false;
8485 lockhart@fourpalms.o 14062 : 0 : $$->alias = NULL;
14063 : : }
14064 : : ;
14065 : :
14066 : :
14067 : : relation_expr_list:
6132 peter_e@gmx.net 14068 :CBC 1422 : relation_expr { $$ = list_make1($1); }
14069 : 5609 : | relation_expr_list ',' relation_expr { $$ = lappend($1, $3); }
14070 : : ;
14071 : :
14072 : :
14073 : : /*
14074 : : * Given "UPDATE foo set set ...", we have to decide without looking any
14075 : : * further ahead whether the first "set" is an alias or the UPDATE's SET
14076 : : * keyword. Since "set" is allowed as a column name both interpretations
14077 : : * are feasible. We resolve the shift/reduce conflict by giving the first
14078 : : * relation_expr_opt_alias production a higher precedence than the SET token
14079 : : * has, causing the parser to prefer to reduce, in effect assuming that the
14080 : : * SET is not an alias.
14081 : : */
14082 : : relation_expr_opt_alias: relation_expr %prec UMINUS
14083 : : {
7218 neilc@samurai.com 14084 : 9422 : $$ = $1;
14085 : : }
14086 : : | relation_expr ColId
14087 : : {
1263 peter@eisentraut.org 14088 : 1125 : Alias *alias = makeNode(Alias);
14089 : :
7218 tgl@sss.pgh.pa.us 14090 : 1125 : alias->aliasname = $2;
14091 : 1125 : $1->alias = alias;
14092 : 1125 : $$ = $1;
14093 : : }
14094 : : | relation_expr AS ColId
14095 : : {
1263 peter@eisentraut.org 14096 : 45 : Alias *alias = makeNode(Alias);
14097 : :
7218 neilc@samurai.com 14098 : 45 : alias->aliasname = $3;
14099 : 45 : $1->alias = alias;
14100 : 45 : $$ = $1;
14101 : : }
14102 : : ;
14103 : :
14104 : : /*
14105 : : * TABLESAMPLE decoration in a FROM item
14106 : : */
14107 : : tablesample_clause:
14108 : : TABLESAMPLE func_name '(' expr_list ')' opt_repeatable_clause
14109 : : {
3818 simon@2ndQuadrant.co 14110 : 133 : RangeTableSample *n = makeNode(RangeTableSample);
14111 : :
14112 : : /* n->relation will be filled in later */
14113 : 133 : n->method = $2;
14114 : 133 : n->args = $4;
14115 : 133 : n->repeatable = $6;
3747 tgl@sss.pgh.pa.us 14116 : 133 : n->location = @2;
3818 simon@2ndQuadrant.co 14117 : 133 : $$ = (Node *) n;
14118 : : }
14119 : : ;
14120 : :
14121 : : opt_repeatable_clause:
14122 : 54 : REPEATABLE '(' a_expr ')' { $$ = (Node *) $3; }
14123 : 79 : | /*EMPTY*/ { $$ = NULL; }
14124 : : ;
14125 : :
14126 : : /*
14127 : : * func_table represents a function invocation in a FROM list. It can be
14128 : : * a plain function call, like "foo(...)", or a ROWS FROM expression with
14129 : : * one or more function calls, "ROWS FROM (foo(...), bar(...))",
14130 : : * optionally with WITH ORDINALITY attached.
14131 : : * In the ROWS FROM syntax, a column definition list can be given for each
14132 : : * function, for example:
14133 : : * ROWS FROM (foo() AS (foo_res_a text, foo_res_b text),
14134 : : * bar() AS (bar_res_a text, bar_res_b text))
14135 : : * It's also possible to attach a column definition list to the RangeFunction
14136 : : * as a whole, but that's handled by the table_ref production.
14137 : : */
14138 : : func_table: func_expr_windowless opt_ordinality
14139 : : {
4358 tgl@sss.pgh.pa.us 14140 : 24237 : RangeFunction *n = makeNode(RangeFunction);
14141 : :
14142 : 24237 : n->lateral = false;
14143 : 24237 : n->ordinality = $2;
4339 noah@leadboat.com 14144 : 24237 : n->is_rowsfrom = false;
4358 tgl@sss.pgh.pa.us 14145 : 24237 : n->functions = list_make1(list_make2($1, NIL));
14146 : : /* alias and coldeflist are set by table_ref production */
14147 : 24237 : $$ = (Node *) n;
14148 : : }
14149 : : | ROWS FROM '(' rowsfrom_list ')' opt_ordinality
14150 : : {
14151 : 66 : RangeFunction *n = makeNode(RangeFunction);
14152 : :
14153 : 66 : n->lateral = false;
4339 noah@leadboat.com 14154 : 66 : n->ordinality = $6;
14155 : 66 : n->is_rowsfrom = true;
14156 : 66 : n->functions = $4;
14157 : : /* alias and coldeflist are set by table_ref production */
4358 tgl@sss.pgh.pa.us 14158 : 66 : $$ = (Node *) n;
14159 : : }
14160 : : ;
14161 : :
14162 : : rowsfrom_item: func_expr_windowless opt_col_def_list
14163 : 159 : { $$ = list_make2($1, $2); }
14164 : : ;
14165 : :
14166 : : rowsfrom_list:
4339 noah@leadboat.com 14167 : 66 : rowsfrom_item { $$ = list_make1($1); }
14168 : 93 : | rowsfrom_list ',' rowsfrom_item { $$ = lappend($1, $3); }
14169 : : ;
14170 : :
4358 tgl@sss.pgh.pa.us 14171 : 27 : opt_col_def_list: AS '(' TableFuncElementList ')' { $$ = $3; }
14172 : 132 : | /*EMPTY*/ { $$ = NIL; }
14173 : : ;
14174 : :
3898 14175 : 463 : opt_ordinality: WITH_LA ORDINALITY { $$ = true; }
4358 14176 : 23840 : | /*EMPTY*/ { $$ = false; }
14177 : : ;
14178 : :
14179 : :
14180 : : where_clause:
8533 bruce@momjian.us 14181 : 108070 : WHERE a_expr { $$ = $2; }
8532 14182 : 142395 : | /*EMPTY*/ { $$ = NULL; }
14183 : : ;
14184 : :
14185 : : /* variant for UPDATE and DELETE */
14186 : : where_or_current_clause:
6713 tgl@sss.pgh.pa.us 14187 : 6831 : WHERE a_expr { $$ = $2; }
14188 : : | WHERE CURRENT_P OF cursor_name
14189 : : {
14190 : 133 : CurrentOfExpr *n = makeNode(CurrentOfExpr);
14191 : :
14192 : : /* cvarno is filled in by parse analysis */
14193 : 133 : n->cursor_name = $4;
14194 : 133 : n->cursor_param = 0;
14195 : 133 : $$ = (Node *) n;
14196 : : }
14197 : 2542 : | /*EMPTY*/ { $$ = NULL; }
14198 : : ;
14199 : :
14200 : :
14201 : : OptTableFuncElementList:
5510 peter_e@gmx.net 14202 : 359 : TableFuncElementList { $$ = $1; }
14203 : 3 : | /*EMPTY*/ { $$ = NIL; }
14204 : : ;
14205 : :
14206 : : TableFuncElementList:
14207 : : TableFuncElement
14208 : : {
7820 neilc@samurai.com 14209 : 772 : $$ = list_make1($1);
14210 : : }
14211 : : | TableFuncElementList ',' TableFuncElement
14212 : : {
8460 tgl@sss.pgh.pa.us 14213 : 1031 : $$ = lappend($1, $3);
14214 : : }
14215 : : ;
14216 : :
14217 : : TableFuncElement: ColId Typename opt_collate_clause
14218 : : {
8485 bruce@momjian.us 14219 : 1835 : ColumnDef *n = makeNode(ColumnDef);
14220 : :
14221 : 1835 : n->colname = $1;
5947 peter_e@gmx.net 14222 : 1835 : n->typeName = $2;
5346 tgl@sss.pgh.pa.us 14223 : 1835 : n->inhcount = 0;
8436 14224 : 1835 : n->is_local = true;
5346 14225 : 1835 : n->is_not_null = false;
14226 : 1835 : n->is_from_type = false;
615 peter@eisentraut.org 14227 : 1835 : n->storage = 0;
5346 tgl@sss.pgh.pa.us 14228 : 1835 : n->raw_default = NULL;
14229 : 1835 : n->cooked_default = NULL;
14230 : 1835 : n->collClause = (CollateClause *) $3;
14231 : 1835 : n->collOid = InvalidOid;
14232 : 1835 : n->constraints = NIL;
4358 14233 : 1835 : n->location = @1;
1263 peter@eisentraut.org 14234 : 1835 : $$ = (Node *) n;
14235 : : }
14236 : : ;
14237 : :
14238 : : /*
14239 : : * XMLTABLE
14240 : : */
14241 : : xmltable:
14242 : : XMLTABLE '(' c_expr xmlexists_argument COLUMNS xmltable_column_list ')'
14243 : : {
3155 alvherre@alvh.no-ip. 14244 : 103 : RangeTableFunc *n = makeNode(RangeTableFunc);
14245 : :
14246 : 103 : n->rowexpr = $3;
14247 : 103 : n->docexpr = $4;
14248 : 103 : n->columns = $6;
14249 : 103 : n->namespaces = NIL;
14250 : 103 : n->location = @1;
1263 peter@eisentraut.org 14251 : 103 : $$ = (Node *) n;
14252 : : }
14253 : : | XMLTABLE '(' XMLNAMESPACES '(' xml_namespace_list ')' ','
14254 : : c_expr xmlexists_argument COLUMNS xmltable_column_list ')'
14255 : : {
3155 alvherre@alvh.no-ip. 14256 : 10 : RangeTableFunc *n = makeNode(RangeTableFunc);
14257 : :
14258 : 10 : n->rowexpr = $8;
14259 : 10 : n->docexpr = $9;
14260 : 10 : n->columns = $11;
14261 : 10 : n->namespaces = $5;
14262 : 10 : n->location = @1;
1263 peter@eisentraut.org 14263 : 10 : $$ = (Node *) n;
14264 : : }
14265 : : ;
14266 : :
3155 alvherre@alvh.no-ip. 14267 : 113 : xmltable_column_list: xmltable_column_el { $$ = list_make1($1); }
14268 : 265 : | xmltable_column_list ',' xmltable_column_el { $$ = lappend($1, $3); }
14269 : : ;
14270 : :
14271 : : xmltable_column_el:
14272 : : ColId Typename
14273 : : {
1263 peter@eisentraut.org 14274 : 102 : RangeTableFuncCol *fc = makeNode(RangeTableFuncCol);
14275 : :
3155 alvherre@alvh.no-ip. 14276 : 102 : fc->colname = $1;
14277 : 102 : fc->for_ordinality = false;
14278 : 102 : fc->typeName = $2;
14279 : 102 : fc->is_not_null = false;
14280 : 102 : fc->colexpr = NULL;
14281 : 102 : fc->coldefexpr = NULL;
14282 : 102 : fc->location = @1;
14283 : :
14284 : 102 : $$ = (Node *) fc;
14285 : : }
14286 : : | ColId Typename xmltable_column_option_list
14287 : : {
1263 peter@eisentraut.org 14288 : 245 : RangeTableFuncCol *fc = makeNode(RangeTableFuncCol);
14289 : : ListCell *option;
14290 : 245 : bool nullability_seen = false;
14291 : :
3155 alvherre@alvh.no-ip. 14292 : 245 : fc->colname = $1;
14293 : 245 : fc->typeName = $2;
14294 : 245 : fc->for_ordinality = false;
14295 : 245 : fc->is_not_null = false;
14296 : 245 : fc->colexpr = NULL;
14297 : 245 : fc->coldefexpr = NULL;
14298 : 245 : fc->location = @1;
14299 : :
14300 [ + - + + : 546 : foreach(option, $3)
+ + ]
14301 : : {
14302 : 301 : DefElem *defel = (DefElem *) lfirst(option);
14303 : :
14304 [ + + ]: 301 : if (strcmp(defel->defname, "default") == 0)
14305 : : {
14306 [ - + ]: 28 : if (fc->coldefexpr != NULL)
3155 alvherre@alvh.no-ip. 14307 [ # # ]:UBC 0 : ereport(ERROR,
14308 : : (errcode(ERRCODE_SYNTAX_ERROR),
14309 : : errmsg("only one DEFAULT value is allowed"),
14310 : : parser_errposition(defel->location)));
3155 alvherre@alvh.no-ip. 14311 :CBC 28 : fc->coldefexpr = defel->arg;
14312 : : }
14313 [ + + ]: 273 : else if (strcmp(defel->defname, "path") == 0)
14314 : : {
14315 [ - + ]: 245 : if (fc->colexpr != NULL)
3155 alvherre@alvh.no-ip. 14316 [ # # ]:UBC 0 : ereport(ERROR,
14317 : : (errcode(ERRCODE_SYNTAX_ERROR),
14318 : : errmsg("only one PATH value per column is allowed"),
14319 : : parser_errposition(defel->location)));
3155 alvherre@alvh.no-ip. 14320 :CBC 245 : fc->colexpr = defel->arg;
14321 : : }
165 rguo@postgresql.org 14322 [ + - ]: 28 : else if (strcmp(defel->defname, "__pg__is_not_null") == 0)
14323 : : {
3155 alvherre@alvh.no-ip. 14324 [ - + ]: 28 : if (nullability_seen)
3155 alvherre@alvh.no-ip. 14325 [ # # ]:UBC 0 : ereport(ERROR,
14326 : : (errcode(ERRCODE_SYNTAX_ERROR),
14327 : : errmsg("conflicting or redundant NULL / NOT NULL declarations for column \"%s\"", fc->colname),
14328 : : parser_errposition(defel->location)));
1382 peter@eisentraut.org 14329 :CBC 28 : fc->is_not_null = boolVal(defel->arg);
3155 alvherre@alvh.no-ip. 14330 : 28 : nullability_seen = true;
14331 : : }
14332 : : else
14333 : : {
3155 alvherre@alvh.no-ip. 14334 [ # # ]:UBC 0 : ereport(ERROR,
14335 : : (errcode(ERRCODE_SYNTAX_ERROR),
14336 : : errmsg("unrecognized column option \"%s\"",
14337 : : defel->defname),
14338 : : parser_errposition(defel->location)));
14339 : : }
14340 : : }
3155 alvherre@alvh.no-ip. 14341 :CBC 245 : $$ = (Node *) fc;
14342 : : }
14343 : : | ColId FOR ORDINALITY
14344 : : {
1263 peter@eisentraut.org 14345 : 31 : RangeTableFuncCol *fc = makeNode(RangeTableFuncCol);
14346 : :
3155 alvherre@alvh.no-ip. 14347 : 31 : fc->colname = $1;
14348 : 31 : fc->for_ordinality = true;
14349 : : /* other fields are ignored, initialized by makeNode */
14350 : 31 : fc->location = @1;
14351 : :
14352 : 31 : $$ = (Node *) fc;
14353 : : }
14354 : : ;
14355 : :
14356 : : xmltable_column_option_list:
14357 : : xmltable_column_option_el
14358 : 245 : { $$ = list_make1($1); }
14359 : : | xmltable_column_option_list xmltable_column_option_el
14360 : 56 : { $$ = lappend($1, $2); }
14361 : : ;
14362 : :
14363 : : xmltable_column_option_el:
14364 : : IDENT b_expr
14365 : : {
165 rguo@postgresql.org 14366 [ + - ]: 3 : if (strcmp($1, "__pg__is_not_null") == 0)
14367 [ + - ]: 3 : ereport(ERROR,
14368 : : (errcode(ERRCODE_SYNTAX_ERROR),
14369 : : errmsg("option name \"%s\" cannot be used in XMLTABLE", $1),
14370 : : parser_errposition(@1)));
165 rguo@postgresql.org 14371 :UBC 0 : $$ = makeDefElem($1, $2, @1);
14372 : : }
14373 : : | DEFAULT b_expr
3155 alvherre@alvh.no-ip. 14374 :CBC 28 : { $$ = makeDefElem("default", $2, @1); }
14375 : : | NOT NULL_P
165 rguo@postgresql.org 14376 : 28 : { $$ = makeDefElem("__pg__is_not_null", (Node *) makeBoolean(true), @1); }
14377 : : | NULL_P
165 rguo@postgresql.org 14378 :UBC 0 : { $$ = makeDefElem("__pg__is_not_null", (Node *) makeBoolean(false), @1); }
14379 : : | PATH b_expr
571 amitlan@postgresql.o 14380 :CBC 245 : { $$ = makeDefElem("path", $2, @1); }
14381 : : ;
14382 : :
14383 : : xml_namespace_list:
14384 : : xml_namespace_el
3155 alvherre@alvh.no-ip. 14385 : 10 : { $$ = list_make1($1); }
14386 : : | xml_namespace_list ',' xml_namespace_el
3155 alvherre@alvh.no-ip. 14387 :UBC 0 : { $$ = lappend($1, $3); }
14388 : : ;
14389 : :
14390 : : xml_namespace_el:
14391 : : b_expr AS ColLabel
14392 : : {
3155 alvherre@alvh.no-ip. 14393 :CBC 7 : $$ = makeNode(ResTarget);
14394 : 7 : $$->name = $3;
14395 : 7 : $$->indirection = NIL;
14396 : 7 : $$->val = $1;
14397 : 7 : $$->location = @1;
14398 : : }
14399 : : | DEFAULT b_expr
14400 : : {
14401 : 3 : $$ = makeNode(ResTarget);
14402 : 3 : $$->name = NULL;
14403 : 3 : $$->indirection = NIL;
14404 : 3 : $$->val = $2;
14405 : 3 : $$->location = @1;
14406 : : }
14407 : : ;
14408 : :
14409 : : json_table:
14410 : : JSON_TABLE '('
14411 : : json_value_expr ',' a_expr json_table_path_name_opt
14412 : : json_passing_clause_opt
14413 : : COLUMNS '(' json_table_column_definition_list ')'
14414 : : json_on_error_clause_opt
14415 : : ')'
14416 : : {
571 amitlan@postgresql.o 14417 : 266 : JsonTable *n = makeNode(JsonTable);
14418 : : char *pathstring;
14419 : :
14420 : 266 : n->context_item = (JsonValueExpr *) $3;
14421 [ + + ]: 266 : if (!IsA($5, A_Const) ||
14422 [ - + ]: 263 : castNode(A_Const, $5)->val.node.type != T_String)
14423 [ + - ]: 3 : ereport(ERROR,
14424 : : errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
14425 : : errmsg("only string constants are supported in JSON_TABLE path specification"),
14426 : : parser_errposition(@5));
14427 : 263 : pathstring = castNode(A_Const, $5)->val.sval.sval;
14428 : 263 : n->pathspec = makeJsonTablePathSpec(pathstring, $6, @5, @6);
14429 : 263 : n->passing = $7;
14430 : 263 : n->columns = $10;
14431 : 263 : n->on_error = (JsonBehavior *) $12;
14432 : 263 : n->location = @1;
14433 : 263 : $$ = (Node *) n;
14434 : : }
14435 : : ;
14436 : :
14437 : : json_table_path_name_opt:
14438 : 29 : AS name { $$ = $2; }
14439 : 243 : | /* empty */ { $$ = NULL; }
14440 : : ;
14441 : :
14442 : : json_table_column_definition_list:
14443 : : json_table_column_definition
14444 : 409 : { $$ = list_make1($1); }
14445 : : | json_table_column_definition_list ',' json_table_column_definition
14446 : 264 : { $$ = lappend($1, $3); }
14447 : : ;
14448 : :
14449 : : json_table_column_definition:
14450 : : ColId FOR ORDINALITY
14451 : : {
14452 : 42 : JsonTableColumn *n = makeNode(JsonTableColumn);
14453 : :
14454 : 42 : n->coltype = JTC_FOR_ORDINALITY;
14455 : 42 : n->name = $1;
14456 : 42 : n->location = @1;
14457 : 42 : $$ = (Node *) n;
14458 : : }
14459 : : | ColId Typename
14460 : : json_table_column_path_clause_opt
14461 : : json_wrapper_behavior
14462 : : json_quotes_clause_opt
14463 : : json_behavior_clause_opt
14464 : : {
14465 : 365 : JsonTableColumn *n = makeNode(JsonTableColumn);
14466 : :
14467 : 365 : n->coltype = JTC_REGULAR;
14468 : 365 : n->name = $1;
14469 : 365 : n->typeName = $2;
14470 : 365 : n->format = makeJsonFormat(JS_FORMAT_DEFAULT, JS_ENC_DEFAULT, -1);
14471 : 365 : n->pathspec = (JsonTablePathSpec *) $3;
14472 : 365 : n->wrapper = $4;
14473 : 365 : n->quotes = $5;
14474 : 365 : n->on_empty = (JsonBehavior *) linitial($6);
14475 : 365 : n->on_error = (JsonBehavior *) lsecond($6);
14476 : 365 : n->location = @1;
14477 : 365 : $$ = (Node *) n;
14478 : : }
14479 : : | ColId Typename json_format_clause
14480 : : json_table_column_path_clause_opt
14481 : : json_wrapper_behavior
14482 : : json_quotes_clause_opt
14483 : : json_behavior_clause_opt
14484 : : {
14485 : 54 : JsonTableColumn *n = makeNode(JsonTableColumn);
14486 : :
14487 : 54 : n->coltype = JTC_FORMATTED;
14488 : 54 : n->name = $1;
14489 : 54 : n->typeName = $2;
14490 : 54 : n->format = (JsonFormat *) $3;
14491 : 54 : n->pathspec = (JsonTablePathSpec *) $4;
14492 : 54 : n->wrapper = $5;
14493 : 54 : n->quotes = $6;
14494 : 54 : n->on_empty = (JsonBehavior *) linitial($7);
14495 : 54 : n->on_error = (JsonBehavior *) lsecond($7);
14496 : 54 : n->location = @1;
14497 : 54 : $$ = (Node *) n;
14498 : : }
14499 : : | ColId Typename
14500 : : EXISTS json_table_column_path_clause_opt
14501 : : json_on_error_clause_opt
14502 : : {
14503 : 69 : JsonTableColumn *n = makeNode(JsonTableColumn);
14504 : :
14505 : 69 : n->coltype = JTC_EXISTS;
14506 : 69 : n->name = $1;
14507 : 69 : n->typeName = $2;
14508 : 69 : n->format = makeJsonFormat(JS_FORMAT_DEFAULT, JS_ENC_DEFAULT, -1);
14509 : 69 : n->wrapper = JSW_NONE;
14510 : 69 : n->quotes = JS_QUOTES_UNSPEC;
14511 : 69 : n->pathspec = (JsonTablePathSpec *) $4;
486 14512 : 69 : n->on_empty = NULL;
14513 : 69 : n->on_error = (JsonBehavior *) $5;
571 14514 : 69 : n->location = @1;
14515 : 69 : $$ = (Node *) n;
14516 : : }
14517 : : | NESTED path_opt Sconst
14518 : : COLUMNS '(' json_table_column_definition_list ')'
14519 : : {
567 14520 : 72 : JsonTableColumn *n = makeNode(JsonTableColumn);
14521 : :
14522 : 72 : n->coltype = JTC_NESTED;
14523 : 144 : n->pathspec = (JsonTablePathSpec *)
14524 : 72 : makeJsonTablePathSpec($3, NULL, @3, -1);
14525 : 72 : n->columns = $6;
14526 : 72 : n->location = @1;
14527 : 72 : $$ = (Node *) n;
14528 : : }
14529 : : | NESTED path_opt Sconst AS name
14530 : : COLUMNS '(' json_table_column_definition_list ')'
14531 : : {
14532 : 71 : JsonTableColumn *n = makeNode(JsonTableColumn);
14533 : :
14534 : 71 : n->coltype = JTC_NESTED;
14535 : 142 : n->pathspec = (JsonTablePathSpec *)
14536 : 71 : makeJsonTablePathSpec($3, $5, @3, @5);
14537 : 71 : n->columns = $8;
14538 : 71 : n->location = @1;
14539 : 71 : $$ = (Node *) n;
14540 : : }
14541 : : ;
14542 : :
14543 : : path_opt:
14544 : : PATH
14545 : : | /* EMPTY */
14546 : : ;
14547 : :
14548 : : json_table_column_path_clause_opt:
14549 : : PATH Sconst
571 14550 : 414 : { $$ = (Node *) makeJsonTablePathSpec($2, NULL, @2, -1); }
14551 : : | /* EMPTY */
14552 : 77 : { $$ = NULL; }
14553 : : ;
14554 : :
14555 : : /*****************************************************************************
14556 : : *
14557 : : * Type syntax
14558 : : * SQL introduces a large amount of type-specific syntax.
14559 : : * Define individual clauses to handle these cases, and use
14560 : : * the generic case to handle regular type-extensible Postgres syntax.
14561 : : * - thomas 1997-10-10
14562 : : *
14563 : : *****************************************************************************/
14564 : :
14565 : : Typename: SimpleTypename opt_array_bounds
14566 : : {
10229 lockhart@fourpalms.o 14567 : 262872 : $$ = $1;
14568 : 262872 : $$->arrayBounds = $2;
14569 : : }
14570 : : | SETOF SimpleTypename opt_array_bounds
14571 : : {
14572 : 1164 : $$ = $2;
8300 tgl@sss.pgh.pa.us 14573 : 1164 : $$->arrayBounds = $3;
2994 peter_e@gmx.net 14574 : 1164 : $$->setof = true;
14575 : : }
14576 : : /* SQL standard syntax, currently only one-dimensional */
14577 : : | SimpleTypename ARRAY '[' Iconst ']'
14578 : : {
8238 tgl@sss.pgh.pa.us 14579 : 3 : $$ = $1;
7820 neilc@samurai.com 14580 : 3 : $$->arrayBounds = list_make1(makeInteger($4));
14581 : : }
14582 : : | SETOF SimpleTypename ARRAY '[' Iconst ']'
14583 : : {
8238 tgl@sss.pgh.pa.us 14584 :UBC 0 : $$ = $2;
7820 neilc@samurai.com 14585 : 0 : $$->arrayBounds = list_make1(makeInteger($5));
2994 peter_e@gmx.net 14586 : 0 : $$->setof = true;
14587 : : }
14588 : : | SimpleTypename ARRAY
14589 : : {
6207 14590 : 0 : $$ = $1;
14591 : 0 : $$->arrayBounds = list_make1(makeInteger(-1));
14592 : : }
14593 : : | SETOF SimpleTypename ARRAY
14594 : : {
14595 : 0 : $$ = $2;
14596 : 0 : $$->arrayBounds = list_make1(makeInteger(-1));
2994 14597 : 0 : $$->setof = true;
14598 : : }
14599 : : ;
14600 : :
14601 : : opt_array_bounds:
14602 : : opt_array_bounds '[' ']'
8533 bruce@momjian.us 14603 :CBC 7383 : { $$ = lappend($1, makeInteger(-1)); }
14604 : : | opt_array_bounds '[' Iconst ']'
14605 : 26 : { $$ = lappend($1, makeInteger($3)); }
14606 : : | /*EMPTY*/
14607 : 264036 : { $$ = NIL; }
14608 : : ;
14609 : :
14610 : : SimpleTypename:
8485 lockhart@fourpalms.o 14611 : 206735 : GenericType { $$ = $1; }
14612 : 49483 : | Numeric { $$ = $1; }
14613 : 986 : | Bit { $$ = $1; }
14614 : 1471 : | Character { $$ = $1; }
14615 : 2692 : | ConstDatetime { $$ = $1; }
14616 : : | ConstInterval opt_interval
14617 : : {
8775 14618 : 1932 : $$ = $1;
6255 tgl@sss.pgh.pa.us 14619 : 1932 : $$->typmods = $2;
14620 : : }
14621 : : | ConstInterval '(' Iconst ')'
14622 : : {
8775 lockhart@fourpalms.o 14623 :UBC 0 : $$ = $1;
4027 bruce@momjian.us 14624 : 0 : $$->typmods = list_make2(makeIntConst(INTERVAL_FULL_RANGE, -1),
14625 : : makeIntConst($3, @3));
14626 : : }
830 amitlan@postgresql.o 14627 :CBC 944 : | JsonType { $$ = $1; }
14628 : : ;
14629 : :
14630 : : /* We have a separate ConstTypename to allow defaulting fixed-length
14631 : : * types such as CHAR() and BIT() to an unspecified length.
14632 : : * SQL9x requires that these default to a length of one, but this
14633 : : * makes no sense for constructs like CHAR 'hi' and BIT '0101',
14634 : : * where there is an obvious better choice to make.
14635 : : * Note that ConstInterval is not included here since it must
14636 : : * be pushed up higher in the rules to accommodate the postfix
14637 : : * options (e.g. INTERVAL '1' YEAR). Likewise, we have to handle
14638 : : * the generic-type-name case in AexprConst to avoid premature
14639 : : * reduce/reduce conflicts against function names.
14640 : : */
14641 : : ConstTypename:
6876 tgl@sss.pgh.pa.us 14642 : 39 : Numeric { $$ = $1; }
8485 lockhart@fourpalms.o 14643 :UBC 0 : | ConstBit { $$ = $1; }
8485 lockhart@fourpalms.o 14644 :CBC 16 : | ConstCharacter { $$ = $1; }
14645 : 1399 : | ConstDatetime { $$ = $1; }
830 amitlan@postgresql.o 14646 : 132 : | JsonType { $$ = $1; }
14647 : : ;
14648 : :
14649 : : /*
14650 : : * GenericType covers all type names that don't have special syntax mandated
14651 : : * by the standard, including qualified names. We also allow type modifiers.
14652 : : * To avoid parsing conflicts against function invocations, the modifiers
14653 : : * have to be shown as expr_list here, but parse analysis will only accept
14654 : : * constants for them.
14655 : : */
14656 : : GenericType:
14657 : : type_function_name opt_type_modifiers
14658 : : {
8578 tgl@sss.pgh.pa.us 14659 : 146417 : $$ = makeTypeName($1);
6876 14660 : 146417 : $$->typmods = $2;
14661 : 146417 : $$->location = @1;
14662 : : }
14663 : : | type_function_name attrs opt_type_modifiers
14664 : : {
14665 : 60318 : $$ = makeTypeNameFromNameList(lcons(makeString($1), $2));
14666 : 60318 : $$->typmods = $3;
7167 14667 : 60318 : $$->location = @1;
14668 : : }
14669 : : ;
14670 : :
6876 14671 : 670 : opt_type_modifiers: '(' expr_list ')' { $$ = $2; }
14672 : 209189 : | /* EMPTY */ { $$ = NIL; }
14673 : : ;
14674 : :
14675 : : /*
14676 : : * SQL numeric data types
14677 : : */
14678 : : Numeric: INT_P
14679 : : {
8578 14680 : 19498 : $$ = SystemTypeName("int4");
6876 14681 : 19498 : $$->location = @1;
14682 : : }
14683 : : | INTEGER
14684 : : {
8578 14685 : 12823 : $$ = SystemTypeName("int4");
6876 14686 : 12823 : $$->location = @1;
14687 : : }
14688 : : | SMALLINT
14689 : : {
8578 14690 : 706 : $$ = SystemTypeName("int2");
6876 14691 : 706 : $$->location = @1;
14692 : : }
14693 : : | BIGINT
14694 : : {
8578 14695 : 2514 : $$ = SystemTypeName("int8");
6876 14696 : 2514 : $$->location = @1;
14697 : : }
14698 : : | REAL
14699 : : {
8578 14700 : 3751 : $$ = SystemTypeName("float4");
6876 14701 : 3751 : $$->location = @1;
14702 : : }
14703 : : | FLOAT_P opt_float
14704 : : {
8578 14705 : 267 : $$ = $2;
6876 14706 : 267 : $$->location = @1;
14707 : : }
14708 : : | DOUBLE_P PRECISION
14709 : : {
8578 14710 : 389 : $$ = SystemTypeName("float8");
6876 14711 : 389 : $$->location = @1;
14712 : : }
14713 : : | DECIMAL_P opt_type_modifiers
14714 : : {
8578 14715 : 16 : $$ = SystemTypeName("numeric");
6876 14716 : 16 : $$->typmods = $2;
14717 : 16 : $$->location = @1;
14718 : : }
14719 : : | DEC opt_type_modifiers
14720 : : {
8578 tgl@sss.pgh.pa.us 14721 :UBC 0 : $$ = SystemTypeName("numeric");
6876 14722 : 0 : $$->typmods = $2;
14723 : 0 : $$->location = @1;
14724 : : }
14725 : : | NUMERIC opt_type_modifiers
14726 : : {
8578 tgl@sss.pgh.pa.us 14727 :CBC 3108 : $$ = SystemTypeName("numeric");
6876 14728 : 3108 : $$->typmods = $2;
14729 : 3108 : $$->location = @1;
14730 : : }
14731 : : | BOOLEAN_P
14732 : : {
8578 14733 : 6450 : $$ = SystemTypeName("bool");
6876 14734 : 6450 : $$->location = @1;
14735 : : }
14736 : : ;
14737 : :
14738 : : opt_float: '(' Iconst ')'
14739 : : {
14740 : : /*
14741 : : * Check FLOAT() precision limits assuming IEEE floating
14742 : : * types - thomas 1997-09-18
14743 : : */
10229 lockhart@fourpalms.o 14744 [ - + ]: 1 : if ($2 < 1)
8136 tgl@sss.pgh.pa.us 14745 [ # # ]:UBC 0 : ereport(ERROR,
14746 : : (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
14747 : : errmsg("precision for type float must be at least 1 bit"),
14748 : : parser_errposition(@2)));
8168 tgl@sss.pgh.pa.us 14749 [ + - ]:CBC 1 : else if ($2 <= 24)
8578 14750 : 1 : $$ = SystemTypeName("float4");
8168 tgl@sss.pgh.pa.us 14751 [ # # ]:UBC 0 : else if ($2 <= 53)
8578 14752 : 0 : $$ = SystemTypeName("float8");
14753 : : else
8136 14754 [ # # ]: 0 : ereport(ERROR,
14755 : : (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
14756 : : errmsg("precision for type float must be less than 54 bits"),
14757 : : parser_errposition(@2)));
14758 : : }
14759 : : | /*EMPTY*/
14760 : : {
8578 tgl@sss.pgh.pa.us 14761 :CBC 266 : $$ = SystemTypeName("float8");
14762 : : }
14763 : : ;
14764 : :
14765 : : /*
14766 : : * SQL bit-field data types
14767 : : * The following implements BIT() and BIT VARYING().
14768 : : */
14769 : : Bit: BitWithLength
14770 : : {
8485 lockhart@fourpalms.o 14771 : 848 : $$ = $1;
14772 : : }
14773 : : | BitWithoutLength
14774 : : {
14775 : 138 : $$ = $1;
14776 : : }
14777 : : ;
14778 : :
14779 : : /* ConstBit is like Bit except "BIT" defaults to unspecified length */
14780 : : /* See notes for ConstCharacter, which addresses same issue for "CHAR" */
14781 : : ConstBit: BitWithLength
14782 : : {
8485 lockhart@fourpalms.o 14783 :UBC 0 : $$ = $1;
14784 : : }
14785 : : | BitWithoutLength
14786 : : {
14787 : 0 : $$ = $1;
6876 tgl@sss.pgh.pa.us 14788 : 0 : $$->typmods = NIL;
14789 : : }
14790 : : ;
14791 : :
14792 : : BitWithLength:
14793 : : BIT opt_varying '(' expr_list ')'
14794 : : {
14795 : : char *typname;
14796 : :
8578 tgl@sss.pgh.pa.us 14797 [ + + ]:CBC 848 : typname = $2 ? "varbit" : "bit";
14798 : 848 : $$ = SystemTypeName(typname);
6876 14799 : 848 : $$->typmods = $4;
14800 : 848 : $$->location = @1;
14801 : : }
14802 : : ;
14803 : :
14804 : : BitWithoutLength:
14805 : : BIT opt_varying
14806 : : {
14807 : : /* bit defaults to bit(1), varbit to no limit */
8578 14808 [ + + ]: 138 : if ($2)
14809 : : {
14810 : 10 : $$ = SystemTypeName("varbit");
14811 : : }
14812 : : else
14813 : : {
14814 : 128 : $$ = SystemTypeName("bit");
6269 14815 : 128 : $$->typmods = list_make1(makeIntConst(1, -1));
14816 : : }
6876 14817 : 138 : $$->location = @1;
14818 : : }
14819 : : ;
14820 : :
14821 : :
14822 : : /*
14823 : : * SQL character data types
14824 : : * The following implements CHAR() and VARCHAR().
14825 : : */
14826 : : Character: CharacterWithLength
14827 : : {
8485 lockhart@fourpalms.o 14828 : 830 : $$ = $1;
14829 : : }
14830 : : | CharacterWithoutLength
14831 : : {
14832 : 641 : $$ = $1;
14833 : : }
14834 : : ;
14835 : :
14836 : : ConstCharacter: CharacterWithLength
14837 : : {
14838 : 6 : $$ = $1;
14839 : : }
14840 : : | CharacterWithoutLength
14841 : : {
14842 : : /* Length was not specified so allow to be unrestricted.
14843 : : * This handles problems with fixed-length (bpchar) strings
14844 : : * which in column definitions must default to a length
14845 : : * of one, but should not be constrained if the length
14846 : : * was not specified.
14847 : : */
14848 : 10 : $$ = $1;
6876 tgl@sss.pgh.pa.us 14849 : 10 : $$->typmods = NIL;
14850 : : }
14851 : : ;
14852 : :
14853 : : CharacterWithLength: character '(' Iconst ')'
14854 : : {
8578 14855 : 836 : $$ = SystemTypeName($1);
6269 14856 : 836 : $$->typmods = list_make1(makeIntConst($3, @3));
6876 14857 : 836 : $$->location = @1;
14858 : : }
14859 : : ;
14860 : :
14861 : : CharacterWithoutLength: character
14862 : : {
8578 14863 : 651 : $$ = SystemTypeName($1);
14864 : : /* char defaults to char(1), varchar to no limit */
8750 14865 [ + + ]: 651 : if (strcmp($1, "bpchar") == 0)
6269 14866 : 127 : $$->typmods = list_make1(makeIntConst(1, -1));
6876 14867 : 651 : $$->location = @1;
14868 : : }
14869 : : ;
14870 : :
14871 : : character: CHARACTER opt_varying
8533 bruce@momjian.us 14872 [ + + ]: 282 : { $$ = $2 ? "varchar": "bpchar"; }
14873 : : | CHAR_P opt_varying
14874 [ - + ]: 564 : { $$ = $2 ? "varchar": "bpchar"; }
14875 : : | VARCHAR
14876 : 640 : { $$ = "varchar"; }
14877 : : | NATIONAL CHARACTER opt_varying
8533 bruce@momjian.us 14878 [ # # ]:UBC 0 : { $$ = $3 ? "varchar": "bpchar"; }
14879 : : | NATIONAL CHAR_P opt_varying
14880 [ # # ]: 0 : { $$ = $3 ? "varchar": "bpchar"; }
14881 : : | NCHAR opt_varying
8533 bruce@momjian.us 14882 [ - + ]:CBC 1 : { $$ = $2 ? "varchar": "bpchar"; }
14883 : : ;
14884 : :
14885 : : opt_varying:
2994 peter_e@gmx.net 14886 : 229 : VARYING { $$ = true; }
14887 : 1604 : | /*EMPTY*/ { $$ = false; }
14888 : : ;
14889 : :
14890 : : /*
14891 : : * SQL date/time types
14892 : : */
14893 : : ConstDatetime:
14894 : : TIMESTAMP '(' Iconst ')' opt_timezone
14895 : : {
8790 lockhart@fourpalms.o 14896 [ + + ]: 67 : if ($5)
8578 tgl@sss.pgh.pa.us 14897 : 55 : $$ = SystemTypeName("timestamptz");
14898 : : else
14899 : 12 : $$ = SystemTypeName("timestamp");
6269 14900 : 67 : $$->typmods = list_make1(makeIntConst($3, @3));
6876 14901 : 67 : $$->location = @1;
14902 : : }
14903 : : | TIMESTAMP opt_timezone
14904 : : {
8795 lockhart@fourpalms.o 14905 [ + + ]: 2717 : if ($2)
8578 tgl@sss.pgh.pa.us 14906 : 728 : $$ = SystemTypeName("timestamptz");
14907 : : else
14908 : 1989 : $$ = SystemTypeName("timestamp");
6876 14909 : 2717 : $$->location = @1;
14910 : : }
14911 : : | TIME '(' Iconst ')' opt_timezone
14912 : : {
8790 lockhart@fourpalms.o 14913 [ + + ]: 11 : if ($5)
8578 tgl@sss.pgh.pa.us 14914 : 4 : $$ = SystemTypeName("timetz");
14915 : : else
14916 : 7 : $$ = SystemTypeName("time");
6269 14917 : 11 : $$->typmods = list_make1(makeIntConst($3, @3));
6876 14918 : 11 : $$->location = @1;
14919 : : }
14920 : : | TIME opt_timezone
14921 : : {
9358 lockhart@fourpalms.o 14922 [ + + ]: 1296 : if ($2)
8578 tgl@sss.pgh.pa.us 14923 : 174 : $$ = SystemTypeName("timetz");
14924 : : else
14925 : 1122 : $$ = SystemTypeName("time");
6876 14926 : 1296 : $$->location = @1;
14927 : : }
14928 : : ;
14929 : :
14930 : : ConstInterval:
14931 : : INTERVAL
14932 : : {
14933 : 3587 : $$ = SystemTypeName("interval");
14934 : 3587 : $$->location = @1;
14935 : : }
14936 : : ;
14937 : :
14938 : : opt_timezone:
2994 peter_e@gmx.net 14939 : 961 : WITH_LA TIME ZONE { $$ = true; }
937 alvherre@alvh.no-ip. 14940 : 311 : | WITHOUT_LA TIME ZONE { $$ = false; }
2994 peter_e@gmx.net 14941 : 2819 : | /*EMPTY*/ { $$ = false; }
14942 : : ;
14943 : :
14944 : : opt_interval:
14945 : : YEAR_P
6255 tgl@sss.pgh.pa.us 14946 : 6 : { $$ = list_make1(makeIntConst(INTERVAL_MASK(YEAR), @1)); }
14947 : : | MONTH_P
14948 : 9 : { $$ = list_make1(makeIntConst(INTERVAL_MASK(MONTH), @1)); }
14949 : : | DAY_P
14950 : 9 : { $$ = list_make1(makeIntConst(INTERVAL_MASK(DAY), @1)); }
14951 : : | HOUR_P
14952 : 6 : { $$ = list_make1(makeIntConst(INTERVAL_MASK(HOUR), @1)); }
14953 : : | MINUTE_P
14954 : 6 : { $$ = list_make1(makeIntConst(INTERVAL_MASK(MINUTE), @1)); }
14955 : : | interval_second
14956 : 18 : { $$ = $1; }
14957 : : | YEAR_P TO MONTH_P
14958 : : {
14959 : 9 : $$ = list_make1(makeIntConst(INTERVAL_MASK(YEAR) |
14960 : : INTERVAL_MASK(MONTH), @1));
14961 : : }
14962 : : | DAY_P TO HOUR_P
14963 : : {
14964 : 12 : $$ = list_make1(makeIntConst(INTERVAL_MASK(DAY) |
14965 : : INTERVAL_MASK(HOUR), @1));
14966 : : }
14967 : : | DAY_P TO MINUTE_P
14968 : : {
14969 : 12 : $$ = list_make1(makeIntConst(INTERVAL_MASK(DAY) |
14970 : : INTERVAL_MASK(HOUR) |
14971 : : INTERVAL_MASK(MINUTE), @1));
14972 : : }
14973 : : | DAY_P TO interval_second
14974 : : {
14975 : 24 : $$ = $3;
14976 : 24 : linitial($$) = makeIntConst(INTERVAL_MASK(DAY) |
14977 : : INTERVAL_MASK(HOUR) |
14978 : : INTERVAL_MASK(MINUTE) |
14979 : 24 : INTERVAL_MASK(SECOND), @1);
14980 : : }
14981 : : | HOUR_P TO MINUTE_P
14982 : : {
14983 : 9 : $$ = list_make1(makeIntConst(INTERVAL_MASK(HOUR) |
14984 : : INTERVAL_MASK(MINUTE), @1));
14985 : : }
14986 : : | HOUR_P TO interval_second
14987 : : {
14988 : 18 : $$ = $3;
14989 : 18 : linitial($$) = makeIntConst(INTERVAL_MASK(HOUR) |
14990 : : INTERVAL_MASK(MINUTE) |
14991 : 18 : INTERVAL_MASK(SECOND), @1);
14992 : : }
14993 : : | MINUTE_P TO interval_second
14994 : : {
14995 : 33 : $$ = $3;
14996 : 33 : linitial($$) = makeIntConst(INTERVAL_MASK(MINUTE) |
14997 : 33 : INTERVAL_MASK(SECOND), @1);
14998 : : }
14999 : : | /*EMPTY*/
15000 : 3410 : { $$ = NIL; }
15001 : : ;
15002 : :
15003 : : interval_second:
15004 : : SECOND_P
15005 : : {
15006 : 51 : $$ = list_make1(makeIntConst(INTERVAL_MASK(SECOND), @1));
15007 : : }
15008 : : | SECOND_P '(' Iconst ')'
15009 : : {
15010 : 42 : $$ = list_make2(makeIntConst(INTERVAL_MASK(SECOND), @1),
15011 : : makeIntConst($3, @3));
15012 : : }
15013 : : ;
15014 : :
15015 : : JsonType:
15016 : : JSON
15017 : : {
830 amitlan@postgresql.o 15018 : 1076 : $$ = SystemTypeName("json");
15019 : 1076 : $$->location = @1;
15020 : : }
15021 : : ;
15022 : :
15023 : : /*****************************************************************************
15024 : : *
15025 : : * expression grammar
15026 : : *
15027 : : *****************************************************************************/
15028 : :
15029 : : /*
15030 : : * General expressions
15031 : : * This is the heart of the expression syntax.
15032 : : *
15033 : : * We have two expression types: a_expr is the unrestricted kind, and
15034 : : * b_expr is a subset that must be used in some places to avoid shift/reduce
15035 : : * conflicts. For example, we can't do BETWEEN as "BETWEEN a_expr AND a_expr"
15036 : : * because that use of AND conflicts with AND as a boolean operator. So,
15037 : : * b_expr is used in BETWEEN and we remove boolean keywords from b_expr.
15038 : : *
15039 : : * Note that '(' a_expr ')' is a b_expr, so an unrestricted expression can
15040 : : * always be used by surrounding it with parens.
15041 : : *
15042 : : * c_expr is all the productions that are common to a_expr and b_expr;
15043 : : * it's factored out just to eliminate redundant coding.
15044 : : *
15045 : : * Be careful of productions involving more than one terminal token.
15046 : : * By default, bison will assign such productions the precedence of their
15047 : : * last terminal, but in nearly all cases you want it to be the precedence
15048 : : * of the first terminal instead; otherwise you will not get the behavior
15049 : : * you expect! So we use %prec annotations freely to set precedences.
15050 : : */
8533 bruce@momjian.us 15051 : 1868042 : a_expr: c_expr { $$ = $1; }
15052 : : | a_expr TYPECAST Typename
6269 tgl@sss.pgh.pa.us 15053 : 120538 : { $$ = makeTypeCast($1, $3, @2); }
15054 : : | a_expr COLLATE any_name
15055 : : {
5346 15056 : 4535 : CollateClause *n = makeNode(CollateClause);
15057 : :
5344 15058 : 4535 : n->arg = $1;
15059 : 4535 : n->collname = $3;
5346 15060 : 4535 : n->location = @2;
15061 : 4535 : $$ = (Node *) n;
15062 : : }
15063 : : | a_expr AT TIME ZONE a_expr %prec AT
15064 : : {
4501 rhaas@postgresql.org 15065 : 204 : $$ = (Node *) makeFuncCall(SystemFuncName("timezone"),
15066 : 204 : list_make2($5, $1),
15067 : : COERCE_SQL_SYNTAX,
15068 : 204 : @2);
15069 : : }
15070 : : | a_expr AT LOCAL %prec AT
15071 : : {
745 michael@paquier.xyz 15072 : 21 : $$ = (Node *) makeFuncCall(SystemFuncName("timezone"),
15073 : 21 : list_make1($1),
15074 : : COERCE_SQL_SYNTAX,
15075 : : -1);
15076 : : }
15077 : : /*
15078 : : * These operators must be called out explicitly in order to make use
15079 : : * of bison's automatic operator-precedence handling. All other
15080 : : * operator names are handled by the generic productions using "Op",
15081 : : * below; and all those operators will have the same precedence.
15082 : : *
15083 : : * If you add more explicitly-known operators, be sure to add them
15084 : : * also to b_expr and to the MathOp list below.
15085 : : */
15086 : : | '+' a_expr %prec UMINUS
7167 tgl@sss.pgh.pa.us 15087 : 6 : { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "+", NULL, $2, @1); }
15088 : : | '-' a_expr %prec UMINUS
15089 : 4577 : { $$ = doNegate($2, @1); }
15090 : : | a_expr '+' a_expr
15091 : 7165 : { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "+", $1, $3, @2); }
15092 : : | a_expr '-' a_expr
15093 : 2288 : { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "-", $1, $3, @2); }
15094 : : | a_expr '*' a_expr
15095 : 3172 : { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "*", $1, $3, @2); }
15096 : : | a_expr '/' a_expr
15097 : 1739 : { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "/", $1, $3, @2); }
15098 : : | a_expr '%' a_expr
15099 : 1474 : { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "%", $1, $3, @2); }
15100 : : | a_expr '^' a_expr
15101 : 238 : { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "^", $1, $3, @2); }
15102 : : | a_expr '<' a_expr
15103 : 5303 : { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "<", $1, $3, @2); }
15104 : : | a_expr '>' a_expr
15105 : 8303 : { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, ">", $1, $3, @2); }
15106 : : | a_expr '=' a_expr
15107 : 197452 : { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "=", $1, $3, @2); }
15108 : : | a_expr LESS_EQUALS a_expr
3883 15109 : 2542 : { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "<=", $1, $3, @2); }
15110 : : | a_expr GREATER_EQUALS a_expr
15111 : 3576 : { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, ">=", $1, $3, @2); }
15112 : : | a_expr NOT_EQUALS a_expr
15113 : 20581 : { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "<>", $1, $3, @2); }
15114 : :
15115 : : | a_expr qual_Op a_expr %prec Op
7167 15116 : 29661 : { $$ = (Node *) makeA_Expr(AEXPR_OP, $2, $1, $3, @2); }
15117 : : | qual_Op a_expr %prec Op
15118 : 123 : { $$ = (Node *) makeA_Expr(AEXPR_OP, $1, NULL, $2, @1); }
15119 : :
15120 : : | a_expr AND a_expr
4151 15121 : 118740 : { $$ = makeAndExpr($1, $3, @2); }
15122 : : | a_expr OR a_expr
15123 : 8083 : { $$ = makeOrExpr($1, $3, @2); }
15124 : : | NOT a_expr
15125 : 8117 : { $$ = makeNotExpr($2, @1); }
15126 : : | NOT_LA a_expr %prec NOT
3883 tgl@sss.pgh.pa.us 15127 :UBC 0 : { $$ = makeNotExpr($2, @1); }
15128 : :
15129 : : | a_expr LIKE a_expr
15130 : : {
3899 tgl@sss.pgh.pa.us 15131 :CBC 984 : $$ = (Node *) makeSimpleA_Expr(AEXPR_LIKE, "~~",
15132 : 984 : $1, $3, @2);
15133 : : }
15134 : : | a_expr LIKE a_expr ESCAPE a_expr %prec LIKE
15135 : : {
1263 peter@eisentraut.org 15136 : 48 : FuncCall *n = makeFuncCall(SystemFuncName("like_escape"),
15137 : 48 : list_make2($3, $5),
15138 : : COERCE_EXPLICIT_CALL,
15139 : 48 : @2);
3899 tgl@sss.pgh.pa.us 15140 : 48 : $$ = (Node *) makeSimpleA_Expr(AEXPR_LIKE, "~~",
15141 : 48 : $1, (Node *) n, @2);
15142 : : }
15143 : : | a_expr NOT_LA LIKE a_expr %prec NOT_LA
15144 : : {
15145 : 107 : $$ = (Node *) makeSimpleA_Expr(AEXPR_LIKE, "!~~",
15146 : 107 : $1, $4, @2);
15147 : : }
15148 : : | a_expr NOT_LA LIKE a_expr ESCAPE a_expr %prec NOT_LA
15149 : : {
1263 peter@eisentraut.org 15150 : 48 : FuncCall *n = makeFuncCall(SystemFuncName("like_escape"),
15151 : 48 : list_make2($4, $6),
15152 : : COERCE_EXPLICIT_CALL,
15153 : 48 : @2);
3899 tgl@sss.pgh.pa.us 15154 : 48 : $$ = (Node *) makeSimpleA_Expr(AEXPR_LIKE, "!~~",
15155 : 48 : $1, (Node *) n, @2);
15156 : : }
15157 : : | a_expr ILIKE a_expr
15158 : : {
15159 : 86 : $$ = (Node *) makeSimpleA_Expr(AEXPR_ILIKE, "~~*",
15160 : 86 : $1, $3, @2);
15161 : : }
15162 : : | a_expr ILIKE a_expr ESCAPE a_expr %prec ILIKE
15163 : : {
1263 peter@eisentraut.org 15164 :UBC 0 : FuncCall *n = makeFuncCall(SystemFuncName("like_escape"),
15165 : 0 : list_make2($3, $5),
15166 : : COERCE_EXPLICIT_CALL,
15167 : 0 : @2);
3899 tgl@sss.pgh.pa.us 15168 : 0 : $$ = (Node *) makeSimpleA_Expr(AEXPR_ILIKE, "~~*",
15169 : 0 : $1, (Node *) n, @2);
15170 : : }
15171 : : | a_expr NOT_LA ILIKE a_expr %prec NOT_LA
15172 : : {
3899 tgl@sss.pgh.pa.us 15173 :CBC 15 : $$ = (Node *) makeSimpleA_Expr(AEXPR_ILIKE, "!~~*",
15174 : 15 : $1, $4, @2);
15175 : : }
15176 : : | a_expr NOT_LA ILIKE a_expr ESCAPE a_expr %prec NOT_LA
15177 : : {
1263 peter@eisentraut.org 15178 :UBC 0 : FuncCall *n = makeFuncCall(SystemFuncName("like_escape"),
15179 : 0 : list_make2($4, $6),
15180 : : COERCE_EXPLICIT_CALL,
15181 : 0 : @2);
3899 tgl@sss.pgh.pa.us 15182 : 0 : $$ = (Node *) makeSimpleA_Expr(AEXPR_ILIKE, "!~~*",
15183 : 0 : $1, (Node *) n, @2);
15184 : : }
15185 : :
15186 : : | a_expr SIMILAR TO a_expr %prec SIMILAR
15187 : : {
1263 peter@eisentraut.org 15188 :CBC 44 : FuncCall *n = makeFuncCall(SystemFuncName("similar_to_escape"),
15189 : 44 : list_make1($4),
15190 : : COERCE_EXPLICIT_CALL,
15191 : 44 : @2);
3899 tgl@sss.pgh.pa.us 15192 : 44 : $$ = (Node *) makeSimpleA_Expr(AEXPR_SIMILAR, "~",
15193 : 44 : $1, (Node *) n, @2);
15194 : : }
15195 : : | a_expr SIMILAR TO a_expr ESCAPE a_expr %prec SIMILAR
15196 : : {
1263 peter@eisentraut.org 15197 : 18 : FuncCall *n = makeFuncCall(SystemFuncName("similar_to_escape"),
15198 : 18 : list_make2($4, $6),
15199 : : COERCE_EXPLICIT_CALL,
15200 : 18 : @2);
3899 tgl@sss.pgh.pa.us 15201 : 18 : $$ = (Node *) makeSimpleA_Expr(AEXPR_SIMILAR, "~",
15202 : 18 : $1, (Node *) n, @2);
15203 : : }
15204 : : | a_expr NOT_LA SIMILAR TO a_expr %prec NOT_LA
15205 : : {
1263 peter@eisentraut.org 15206 :UBC 0 : FuncCall *n = makeFuncCall(SystemFuncName("similar_to_escape"),
15207 : 0 : list_make1($5),
15208 : : COERCE_EXPLICIT_CALL,
15209 : 0 : @2);
3899 tgl@sss.pgh.pa.us 15210 : 0 : $$ = (Node *) makeSimpleA_Expr(AEXPR_SIMILAR, "!~",
15211 : 0 : $1, (Node *) n, @2);
15212 : : }
15213 : : | a_expr NOT_LA SIMILAR TO a_expr ESCAPE a_expr %prec NOT_LA
15214 : : {
1263 peter@eisentraut.org 15215 : 0 : FuncCall *n = makeFuncCall(SystemFuncName("similar_to_escape"),
15216 : 0 : list_make2($5, $7),
15217 : : COERCE_EXPLICIT_CALL,
15218 : 0 : @2);
3899 tgl@sss.pgh.pa.us 15219 : 0 : $$ = (Node *) makeSimpleA_Expr(AEXPR_SIMILAR, "!~",
15220 : 0 : $1, (Node *) n, @2);
15221 : : }
15222 : :
15223 : : /* NullTest clause
15224 : : * Define SQL-style Null test clause.
15225 : : * Allow two forms described in the standard:
15226 : : * a IS NULL
15227 : : * a IS NOT NULL
15228 : : * Allow two SQL extensions
15229 : : * a ISNULL
15230 : : * a NOTNULL
15231 : : */
15232 : : | a_expr IS NULL_P %prec IS
15233 : : {
1263 peter@eisentraut.org 15234 :CBC 2642 : NullTest *n = makeNode(NullTest);
15235 : :
6969 tgl@sss.pgh.pa.us 15236 : 2642 : n->arg = (Expr *) $1;
15237 : 2642 : n->nulltesttype = IS_NULL;
3900 15238 : 2642 : n->location = @2;
1263 peter@eisentraut.org 15239 : 2642 : $$ = (Node *) n;
15240 : : }
15241 : : | a_expr ISNULL
15242 : : {
15243 : 48 : NullTest *n = makeNode(NullTest);
15244 : :
6969 tgl@sss.pgh.pa.us 15245 : 48 : n->arg = (Expr *) $1;
15246 : 48 : n->nulltesttype = IS_NULL;
3900 15247 : 48 : n->location = @2;
1263 peter@eisentraut.org 15248 : 48 : $$ = (Node *) n;
15249 : : }
15250 : : | a_expr IS NOT NULL_P %prec IS
15251 : : {
15252 : 6455 : NullTest *n = makeNode(NullTest);
15253 : :
6969 tgl@sss.pgh.pa.us 15254 : 6455 : n->arg = (Expr *) $1;
15255 : 6455 : n->nulltesttype = IS_NOT_NULL;
3900 15256 : 6455 : n->location = @2;
1263 peter@eisentraut.org 15257 : 6455 : $$ = (Node *) n;
15258 : : }
15259 : : | a_expr NOTNULL
15260 : : {
15261 : 3 : NullTest *n = makeNode(NullTest);
15262 : :
6969 tgl@sss.pgh.pa.us 15263 : 3 : n->arg = (Expr *) $1;
15264 : 3 : n->nulltesttype = IS_NOT_NULL;
3900 15265 : 3 : n->location = @2;
1263 peter@eisentraut.org 15266 : 3 : $$ = (Node *) n;
15267 : : }
15268 : : | row OVERLAPS row
15269 : : {
4269 tgl@sss.pgh.pa.us 15270 [ - + ]: 483 : if (list_length($1) != 2)
4269 tgl@sss.pgh.pa.us 15271 [ # # ]:UBC 0 : ereport(ERROR,
15272 : : (errcode(ERRCODE_SYNTAX_ERROR),
15273 : : errmsg("wrong number of parameters on left side of OVERLAPS expression"),
15274 : : parser_errposition(@1)));
4269 tgl@sss.pgh.pa.us 15275 [ - + ]:CBC 483 : if (list_length($3) != 2)
4269 tgl@sss.pgh.pa.us 15276 [ # # ]:UBC 0 : ereport(ERROR,
15277 : : (errcode(ERRCODE_SYNTAX_ERROR),
15278 : : errmsg("wrong number of parameters on right side of OVERLAPS expression"),
15279 : : parser_errposition(@3)));
4269 tgl@sss.pgh.pa.us 15280 :CBC 483 : $$ = (Node *) makeFuncCall(SystemFuncName("overlaps"),
15281 : 483 : list_concat($1, $3),
15282 : : COERCE_SQL_SYNTAX,
15283 : 483 : @2);
15284 : : }
15285 : : | a_expr IS TRUE_P %prec IS
15286 : : {
8896 15287 : 222 : BooleanTest *b = makeNode(BooleanTest);
15288 : :
8355 15289 : 222 : b->arg = (Expr *) $1;
8896 15290 : 222 : b->booltesttype = IS_TRUE;
3900 15291 : 222 : b->location = @2;
1263 peter@eisentraut.org 15292 : 222 : $$ = (Node *) b;
15293 : : }
15294 : : | a_expr IS NOT TRUE_P %prec IS
15295 : : {
8896 tgl@sss.pgh.pa.us 15296 : 70 : BooleanTest *b = makeNode(BooleanTest);
15297 : :
8355 15298 : 70 : b->arg = (Expr *) $1;
8896 15299 : 70 : b->booltesttype = IS_NOT_TRUE;
3900 15300 : 70 : b->location = @2;
1263 peter@eisentraut.org 15301 : 70 : $$ = (Node *) b;
15302 : : }
15303 : : | a_expr IS FALSE_P %prec IS
15304 : : {
8896 tgl@sss.pgh.pa.us 15305 : 77 : BooleanTest *b = makeNode(BooleanTest);
15306 : :
8355 15307 : 77 : b->arg = (Expr *) $1;
8896 15308 : 77 : b->booltesttype = IS_FALSE;
3900 15309 : 77 : b->location = @2;
1263 peter@eisentraut.org 15310 : 77 : $$ = (Node *) b;
15311 : : }
15312 : : | a_expr IS NOT FALSE_P %prec IS
15313 : : {
8896 tgl@sss.pgh.pa.us 15314 : 46 : BooleanTest *b = makeNode(BooleanTest);
15315 : :
8355 15316 : 46 : b->arg = (Expr *) $1;
8896 15317 : 46 : b->booltesttype = IS_NOT_FALSE;
3900 15318 : 46 : b->location = @2;
1263 peter@eisentraut.org 15319 : 46 : $$ = (Node *) b;
15320 : : }
15321 : : | a_expr IS UNKNOWN %prec IS
15322 : : {
8896 tgl@sss.pgh.pa.us 15323 : 26 : BooleanTest *b = makeNode(BooleanTest);
15324 : :
8355 15325 : 26 : b->arg = (Expr *) $1;
8896 15326 : 26 : b->booltesttype = IS_UNKNOWN;
3900 15327 : 26 : b->location = @2;
1263 peter@eisentraut.org 15328 : 26 : $$ = (Node *) b;
15329 : : }
15330 : : | a_expr IS NOT UNKNOWN %prec IS
15331 : : {
8896 tgl@sss.pgh.pa.us 15332 : 24 : BooleanTest *b = makeNode(BooleanTest);
15333 : :
8355 15334 : 24 : b->arg = (Expr *) $1;
8896 15335 : 24 : b->booltesttype = IS_NOT_UNKNOWN;
3900 15336 : 24 : b->location = @2;
1263 peter@eisentraut.org 15337 : 24 : $$ = (Node *) b;
15338 : : }
15339 : : | a_expr IS DISTINCT FROM a_expr %prec IS
15340 : : {
7167 tgl@sss.pgh.pa.us 15341 : 548 : $$ = (Node *) makeSimpleA_Expr(AEXPR_DISTINCT, "=", $1, $5, @2);
15342 : : }
15343 : : | a_expr IS NOT DISTINCT FROM a_expr %prec IS
15344 : : {
3378 15345 : 34 : $$ = (Node *) makeSimpleA_Expr(AEXPR_NOT_DISTINCT, "=", $1, $6, @2);
15346 : : }
15347 : : | a_expr BETWEEN opt_asymmetric b_expr AND a_expr %prec BETWEEN
15348 : : {
3900 15349 : 235 : $$ = (Node *) makeSimpleA_Expr(AEXPR_BETWEEN,
15350 : : "BETWEEN",
15351 : 235 : $1,
15352 : 235 : (Node *) list_make2($4, $6),
15353 : 235 : @2);
15354 : : }
15355 : : | a_expr NOT_LA BETWEEN opt_asymmetric b_expr AND a_expr %prec NOT_LA
15356 : : {
15357 : 6 : $$ = (Node *) makeSimpleA_Expr(AEXPR_NOT_BETWEEN,
15358 : : "NOT BETWEEN",
15359 : 6 : $1,
15360 : 6 : (Node *) list_make2($5, $7),
15361 : 6 : @2);
15362 : : }
15363 : : | a_expr BETWEEN SYMMETRIC b_expr AND a_expr %prec BETWEEN
15364 : : {
15365 : 6 : $$ = (Node *) makeSimpleA_Expr(AEXPR_BETWEEN_SYM,
15366 : : "BETWEEN SYMMETRIC",
15367 : 6 : $1,
15368 : 6 : (Node *) list_make2($4, $6),
15369 : 6 : @2);
15370 : : }
15371 : : | a_expr NOT_LA BETWEEN SYMMETRIC b_expr AND a_expr %prec NOT_LA
15372 : : {
15373 : 6 : $$ = (Node *) makeSimpleA_Expr(AEXPR_NOT_BETWEEN_SYM,
15374 : : "NOT BETWEEN SYMMETRIC",
15375 : 6 : $1,
15376 : 6 : (Node *) list_make2($5, $7),
15377 : 6 : @2);
15378 : : }
15379 : : | a_expr IN_P select_with_parens
15380 : : {
15381 : : /* generate foo = ANY (subquery) */
137 alvherre@kurilemu.de 15382 : 2786 : SubLink *n = makeNode(SubLink);
15383 : :
15384 : 2786 : n->subselect = $3;
15385 : 2786 : n->subLinkType = ANY_SUBLINK;
15386 : 2786 : n->subLinkId = 0;
15387 : 2786 : n->testexpr = $1;
15388 : 2786 : n->operName = NIL; /* show it's IN not = ANY */
15389 : 2786 : n->location = @2;
15390 : 2786 : $$ = (Node *) n;
15391 : : }
15392 : : | a_expr IN_P '(' expr_list ')'
15393 : : {
15394 : : /* generate scalar IN expression */
15395 : 9445 : A_Expr *n = makeSimpleA_Expr(AEXPR_IN, "=", $1, (Node *) $4, @2);
15396 : :
15397 : 9445 : n->rexpr_list_start = @3;
15398 : 9445 : n->rexpr_list_end = @5;
15399 : 9445 : $$ = (Node *) n;
15400 : : }
15401 : : | a_expr NOT_LA IN_P select_with_parens %prec NOT_LA
15402 : : {
15403 : : /* generate NOT (foo = ANY (subquery)) */
15404 : 60 : SubLink *n = makeNode(SubLink);
15405 : :
15406 : 60 : n->subselect = $4;
15407 : 60 : n->subLinkType = ANY_SUBLINK;
15408 : 60 : n->subLinkId = 0;
15409 : 60 : n->testexpr = $1;
15410 : 60 : n->operName = NIL; /* show it's IN not = ANY */
15411 : 60 : n->location = @2;
15412 : : /* Stick a NOT on top; must have same parse location */
15413 : 60 : $$ = makeNotExpr((Node *) n, @2);
15414 : : }
15415 : : | a_expr NOT_LA IN_P '(' expr_list ')'
15416 : : {
15417 : : /* generate scalar NOT IN expression */
15418 : 1346 : A_Expr *n = makeSimpleA_Expr(AEXPR_IN, "<>", $1, (Node *) $5, @2);
15419 : :
15420 : 1346 : n->rexpr_list_start = @4;
15421 : 1346 : n->rexpr_list_end = @6;
15422 : 1346 : $$ = (Node *) n;
15423 : : }
15424 : : | a_expr subquery_Op sub_type select_with_parens %prec Op
15425 : : {
1263 peter@eisentraut.org 15426 : 90 : SubLink *n = makeNode(SubLink);
15427 : :
9478 tgl@sss.pgh.pa.us 15428 : 90 : n->subLinkType = $3;
4149 15429 : 90 : n->subLinkId = 0;
7243 15430 : 90 : n->testexpr = $1;
8326 15431 : 90 : n->operName = $2;
9051 15432 : 90 : n->subselect = $4;
6269 15433 : 90 : n->location = @2;
1263 peter@eisentraut.org 15434 : 90 : $$ = (Node *) n;
15435 : : }
15436 : : | a_expr subquery_Op sub_type '(' a_expr ')' %prec Op
15437 : : {
8156 tgl@sss.pgh.pa.us 15438 [ + + ]: 8441 : if ($3 == ANY_SUBLINK)
7167 15439 : 8291 : $$ = (Node *) makeA_Expr(AEXPR_OP_ANY, $2, $1, $5, @2);
15440 : : else
15441 : 150 : $$ = (Node *) makeA_Expr(AEXPR_OP_ALL, $2, $1, $5, @2);
15442 : : }
15443 : : | UNIQUE opt_unique_null_treatment select_with_parens
15444 : : {
15445 : : /* Not sure how to get rid of the parentheses
15446 : : * but there are lots of shift/reduce errors without them.
15447 : : *
15448 : : * Should be able to implement this by plopping the entire
15449 : : * select into a node, then transforming the target expressions
15450 : : * from whatever they are into count(*), and testing the
15451 : : * entire result equal to one.
15452 : : * But, will probably implement a separate node in the executor.
15453 : : */
8136 tgl@sss.pgh.pa.us 15454 [ # # ]:UBC 0 : ereport(ERROR,
15455 : : (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
15456 : : errmsg("UNIQUE predicate is not yet implemented"),
15457 : : parser_errposition(@1)));
15458 : : }
15459 : : | a_expr IS DOCUMENT_P %prec IS
15460 : : {
6269 tgl@sss.pgh.pa.us 15461 :CBC 9 : $$ = makeXmlExpr(IS_DOCUMENT, NULL, NIL,
15462 : 9 : list_make1($1), @2);
15463 : : }
15464 : : | a_expr IS NOT DOCUMENT_P %prec IS
15465 : : {
4151 15466 : 9 : $$ = makeNotExpr(makeXmlExpr(IS_DOCUMENT, NULL, NIL,
15467 : 9 : list_make1($1), @2),
15468 : 9 : @2);
15469 : : }
15470 : : | a_expr IS NORMALIZED %prec IS
15471 : : {
1818 15472 : 6 : $$ = (Node *) makeFuncCall(SystemFuncName("is_normalized"),
15473 : 6 : list_make1($1),
15474 : : COERCE_SQL_SYNTAX,
15475 : 6 : @2);
15476 : : }
15477 : : | a_expr IS unicode_normal_form NORMALIZED %prec IS
15478 : : {
15479 : 18 : $$ = (Node *) makeFuncCall(SystemFuncName("is_normalized"),
15480 : 18 : list_make2($1, makeStringConst($3, @3)),
15481 : : COERCE_SQL_SYNTAX,
15482 : 18 : @2);
15483 : : }
15484 : : | a_expr IS NOT NORMALIZED %prec IS
15485 : : {
1818 tgl@sss.pgh.pa.us 15486 :UBC 0 : $$ = makeNotExpr((Node *) makeFuncCall(SystemFuncName("is_normalized"),
15487 : 0 : list_make1($1),
15488 : : COERCE_SQL_SYNTAX,
15489 : 0 : @2),
15490 : 0 : @2);
15491 : : }
15492 : : | a_expr IS NOT unicode_normal_form NORMALIZED %prec IS
15493 : : {
15494 : 0 : $$ = makeNotExpr((Node *) makeFuncCall(SystemFuncName("is_normalized"),
15495 : 0 : list_make2($1, makeStringConst($4, @4)),
15496 : : COERCE_SQL_SYNTAX,
15497 : 0 : @2),
15498 : 0 : @2);
15499 : : }
15500 : : | a_expr IS json_predicate_type_constraint
15501 : : json_key_uniqueness_constraint_opt %prec IS
15502 : : {
941 alvherre@alvh.no-ip. 15503 :CBC 145 : JsonFormat *format = makeJsonFormat(JS_FORMAT_DEFAULT, JS_ENC_DEFAULT, -1);
15504 : :
15505 : 145 : $$ = makeJsonIsPredicate($1, format, $3, $4, @1);
15506 : : }
15507 : : /*
15508 : : * Required by SQL/JSON, but there are conflicts
15509 : : | a_expr
15510 : : json_format_clause
15511 : : IS json_predicate_type_constraint
15512 : : json_key_uniqueness_constraint_opt %prec IS
15513 : : {
15514 : : $$ = makeJsonIsPredicate($1, $2, $4, $5, @1);
15515 : : }
15516 : : */
15517 : : | a_expr IS NOT
15518 : : json_predicate_type_constraint
15519 : : json_key_uniqueness_constraint_opt %prec IS
15520 : : {
15521 : 22 : JsonFormat *format = makeJsonFormat(JS_FORMAT_DEFAULT, JS_ENC_DEFAULT, -1);
15522 : :
15523 : 22 : $$ = makeNotExpr(makeJsonIsPredicate($1, format, $4, $5, @1), @1);
15524 : : }
15525 : : /*
15526 : : * Required by SQL/JSON, but there are conflicts
15527 : : | a_expr
15528 : : json_format_clause
15529 : : IS NOT
15530 : : json_predicate_type_constraint
15531 : : json_key_uniqueness_constraint_opt %prec IS
15532 : : {
15533 : : $$ = makeNotExpr(makeJsonIsPredicate($1, $2, $5, $6, @1), @1);
15534 : : }
15535 : : */
15536 : : | DEFAULT
15537 : : {
15538 : : /*
15539 : : * The SQL spec only allows DEFAULT in "contextually typed
15540 : : * expressions", but for us, it's easier to allow it in
15541 : : * any a_expr and then throw error during parse analysis
15542 : : * if it's in an inappropriate context. This way also
15543 : : * lets us say something smarter than "syntax error".
15544 : : */
3261 tgl@sss.pgh.pa.us 15545 : 790 : SetToDefault *n = makeNode(SetToDefault);
15546 : :
15547 : : /* parse analysis will fill in the rest */
15548 : 790 : n->location = @1;
1263 peter@eisentraut.org 15549 : 790 : $$ = (Node *) n;
15550 : : }
15551 : : ;
15552 : :
15553 : : /*
15554 : : * Restricted expressions
15555 : : *
15556 : : * b_expr is a subset of the complete expression syntax defined by a_expr.
15557 : : *
15558 : : * Presently, AND, NOT, IS, and IN are the a_expr keywords that would
15559 : : * cause trouble in the places where b_expr is used. For simplicity, we
15560 : : * just eliminate all the boolean-keyword-operator productions from b_expr.
15561 : : */
15562 : : b_expr: c_expr
8533 bruce@momjian.us 15563 : 1897 : { $$ = $1; }
15564 : : | b_expr TYPECAST Typename
6269 tgl@sss.pgh.pa.us 15565 : 106 : { $$ = makeTypeCast($1, $3, @2); }
15566 : : | '+' b_expr %prec UMINUS
7167 tgl@sss.pgh.pa.us 15567 :UBC 0 : { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "+", NULL, $2, @1); }
15568 : : | '-' b_expr %prec UMINUS
7167 tgl@sss.pgh.pa.us 15569 :CBC 33 : { $$ = doNegate($2, @1); }
15570 : : | b_expr '+' b_expr
15571 : 18 : { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "+", $1, $3, @2); }
15572 : : | b_expr '-' b_expr
15573 : 6 : { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "-", $1, $3, @2); }
15574 : : | b_expr '*' b_expr
15575 : 6 : { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "*", $1, $3, @2); }
15576 : : | b_expr '/' b_expr
7167 tgl@sss.pgh.pa.us 15577 :UBC 0 : { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "/", $1, $3, @2); }
15578 : : | b_expr '%' b_expr
15579 : 0 : { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "%", $1, $3, @2); }
15580 : : | b_expr '^' b_expr
7167 tgl@sss.pgh.pa.us 15581 :CBC 3 : { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "^", $1, $3, @2); }
15582 : : | b_expr '<' b_expr
7167 tgl@sss.pgh.pa.us 15583 :UBC 0 : { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "<", $1, $3, @2); }
15584 : : | b_expr '>' b_expr
15585 : 0 : { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, ">", $1, $3, @2); }
15586 : : | b_expr '=' b_expr
15587 : 0 : { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "=", $1, $3, @2); }
15588 : : | b_expr LESS_EQUALS b_expr
3883 15589 : 0 : { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "<=", $1, $3, @2); }
15590 : : | b_expr GREATER_EQUALS b_expr
15591 : 0 : { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, ">=", $1, $3, @2); }
15592 : : | b_expr NOT_EQUALS b_expr
15593 : 0 : { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "<>", $1, $3, @2); }
15594 : : | b_expr qual_Op b_expr %prec Op
7167 tgl@sss.pgh.pa.us 15595 :CBC 6 : { $$ = (Node *) makeA_Expr(AEXPR_OP, $2, $1, $3, @2); }
15596 : : | qual_Op b_expr %prec Op
7167 tgl@sss.pgh.pa.us 15597 :UBC 0 : { $$ = (Node *) makeA_Expr(AEXPR_OP, $1, NULL, $2, @1); }
15598 : : | b_expr IS DISTINCT FROM b_expr %prec IS
15599 : : {
15600 : 0 : $$ = (Node *) makeSimpleA_Expr(AEXPR_DISTINCT, "=", $1, $5, @2);
15601 : : }
15602 : : | b_expr IS NOT DISTINCT FROM b_expr %prec IS
15603 : : {
3378 15604 : 0 : $$ = (Node *) makeSimpleA_Expr(AEXPR_NOT_DISTINCT, "=", $1, $6, @2);
15605 : : }
15606 : : | b_expr IS DOCUMENT_P %prec IS
15607 : : {
6269 15608 : 0 : $$ = makeXmlExpr(IS_DOCUMENT, NULL, NIL,
15609 : 0 : list_make1($1), @2);
15610 : : }
15611 : : | b_expr IS NOT DOCUMENT_P %prec IS
15612 : : {
4151 15613 : 0 : $$ = makeNotExpr(makeXmlExpr(IS_DOCUMENT, NULL, NIL,
15614 : 0 : list_make1($1), @2),
15615 : 0 : @2);
15616 : : }
15617 : : ;
15618 : :
15619 : : /*
15620 : : * Productions that can be used in both a_expr and b_expr.
15621 : : *
15622 : : * Note: productions that refer recursively to a_expr or b_expr mostly
15623 : : * cannot appear here. However, it's OK to refer to a_exprs that occur
15624 : : * inside parentheses, such as function arguments; that cannot introduce
15625 : : * ambiguity to the b_expr syntax.
15626 : : */
7810 tgl@sss.pgh.pa.us 15627 :CBC 927988 : c_expr: columnref { $$ = $1; }
8533 bruce@momjian.us 15628 : 631052 : | AexprConst { $$ = $1; }
15629 : : | PARAM opt_indirection
15630 : : {
1263 peter@eisentraut.org 15631 : 21317 : ParamRef *p = makeNode(ParamRef);
15632 : :
7810 tgl@sss.pgh.pa.us 15633 : 21317 : p->number = $1;
6269 15634 : 21317 : p->location = @1;
7810 15635 [ + + ]: 21317 : if ($2)
15636 : : {
15637 : 542 : A_Indirection *n = makeNode(A_Indirection);
15638 : :
15639 : 542 : n->arg = (Node *) p;
5950 15640 : 542 : n->indirection = check_indirection($2, yyscanner);
7810 15641 : 542 : $$ = (Node *) n;
15642 : : }
15643 : : else
15644 : 20775 : $$ = (Node *) p;
15645 : : }
15646 : : | '(' a_expr ')' opt_indirection
15647 : : {
8238 15648 [ + + ]: 45163 : if ($4)
15649 : : {
7810 15650 : 6174 : A_Indirection *n = makeNode(A_Indirection);
15651 : :
8238 15652 : 6174 : n->arg = $2;
5950 15653 : 6174 : n->indirection = check_indirection($4, yyscanner);
1263 peter@eisentraut.org 15654 : 6174 : $$ = (Node *) n;
15655 : : }
15656 : : else
8238 tgl@sss.pgh.pa.us 15657 : 38989 : $$ = $2;
15658 : : }
15659 : : | case_expr
8533 bruce@momjian.us 15660 : 19622 : { $$ = $1; }
15661 : : | func_expr
7698 tgl@sss.pgh.pa.us 15662 : 196642 : { $$ = $1; }
15663 : : | select_with_parens %prec UMINUS
15664 : : {
1263 peter@eisentraut.org 15665 : 13974 : SubLink *n = makeNode(SubLink);
15666 : :
7698 tgl@sss.pgh.pa.us 15667 : 13974 : n->subLinkType = EXPR_SUBLINK;
4149 15668 : 13974 : n->subLinkId = 0;
7243 15669 : 13974 : n->testexpr = NULL;
7698 15670 : 13974 : n->operName = NIL;
15671 : 13974 : n->subselect = $1;
6269 15672 : 13974 : n->location = @1;
1263 peter@eisentraut.org 15673 : 13974 : $$ = (Node *) n;
15674 : : }
15675 : : | select_with_parens indirection
15676 : : {
15677 : : /*
15678 : : * Because the select_with_parens nonterminal is designed
15679 : : * to "eat" as many levels of parens as possible, the
15680 : : * '(' a_expr ')' opt_indirection production above will
15681 : : * fail to match a sub-SELECT with indirection decoration;
15682 : : * the sub-SELECT won't be regarded as an a_expr as long
15683 : : * as there are parens around it. To support applying
15684 : : * subscripting or field selection to a sub-SELECT result,
15685 : : * we need this redundant-looking production.
15686 : : */
15687 : 9 : SubLink *n = makeNode(SubLink);
4653 tgl@sss.pgh.pa.us 15688 : 9 : A_Indirection *a = makeNode(A_Indirection);
15689 : :
15690 : 9 : n->subLinkType = EXPR_SUBLINK;
4149 15691 : 9 : n->subLinkId = 0;
4653 15692 : 9 : n->testexpr = NULL;
15693 : 9 : n->operName = NIL;
15694 : 9 : n->subselect = $1;
15695 : 9 : n->location = @1;
1263 peter@eisentraut.org 15696 : 9 : a->arg = (Node *) n;
4653 tgl@sss.pgh.pa.us 15697 : 9 : a->indirection = check_indirection($2, yyscanner);
1263 peter@eisentraut.org 15698 : 9 : $$ = (Node *) a;
15699 : : }
15700 : : | EXISTS select_with_parens
15701 : : {
15702 : 3086 : SubLink *n = makeNode(SubLink);
15703 : :
7698 tgl@sss.pgh.pa.us 15704 : 3086 : n->subLinkType = EXISTS_SUBLINK;
4149 15705 : 3086 : n->subLinkId = 0;
7243 15706 : 3086 : n->testexpr = NULL;
7698 15707 : 3086 : n->operName = NIL;
15708 : 3086 : n->subselect = $2;
6269 15709 : 3086 : n->location = @1;
1263 peter@eisentraut.org 15710 : 3086 : $$ = (Node *) n;
15711 : : }
15712 : : | ARRAY select_with_parens
15713 : : {
15714 : 4242 : SubLink *n = makeNode(SubLink);
15715 : :
7698 tgl@sss.pgh.pa.us 15716 : 4242 : n->subLinkType = ARRAY_SUBLINK;
4149 15717 : 4242 : n->subLinkId = 0;
7243 15718 : 4242 : n->testexpr = NULL;
7698 15719 : 4242 : n->operName = NIL;
15720 : 4242 : n->subselect = $2;
6269 15721 : 4242 : n->location = @1;
1263 peter@eisentraut.org 15722 : 4242 : $$ = (Node *) n;
15723 : : }
15724 : : | ARRAY array_expr
15725 : : {
3170 peter_e@gmx.net 15726 : 3740 : A_ArrayExpr *n = castNode(A_ArrayExpr, $2);
15727 : :
15728 : : /* point outermost A_ArrayExpr to the ARRAY keyword */
6269 tgl@sss.pgh.pa.us 15729 : 3740 : n->location = @1;
1263 peter@eisentraut.org 15730 : 3740 : $$ = (Node *) n;
15731 : : }
15732 : : | explicit_row
15733 : : {
15734 : 1914 : RowExpr *r = makeNode(RowExpr);
15735 : :
3817 andres@anarazel.de 15736 : 1914 : r->args = $1;
15737 : 1914 : r->row_typeid = InvalidOid; /* not analyzed yet */
15738 : 1914 : r->colnames = NIL; /* to be filled in during analysis */
15739 : 1914 : r->row_format = COERCE_EXPLICIT_CALL; /* abuse */
15740 : 1914 : r->location = @1;
1263 peter@eisentraut.org 15741 : 1914 : $$ = (Node *) r;
15742 : : }
15743 : : | implicit_row
15744 : : {
15745 : 1352 : RowExpr *r = makeNode(RowExpr);
15746 : :
7698 tgl@sss.pgh.pa.us 15747 : 1352 : r->args = $1;
15748 : 1352 : r->row_typeid = InvalidOid; /* not analyzed yet */
5004 15749 : 1352 : r->colnames = NIL; /* to be filled in during analysis */
3817 andres@anarazel.de 15750 : 1352 : r->row_format = COERCE_IMPLICIT_CAST; /* abuse */
6269 tgl@sss.pgh.pa.us 15751 : 1352 : r->location = @1;
1263 peter@eisentraut.org 15752 : 1352 : $$ = (Node *) r;
15753 : : }
15754 : : | GROUPING '(' expr_list ')'
15755 : : {
3817 andres@anarazel.de 15756 : 181 : GroupingFunc *g = makeNode(GroupingFunc);
15757 : :
15758 : 181 : g->args = $3;
15759 : 181 : g->location = @1;
1263 peter@eisentraut.org 15760 : 181 : $$ = (Node *) g;
15761 : : }
15762 : : ;
15763 : :
15764 : : func_application: func_name '(' ')'
15765 : : {
1818 tgl@sss.pgh.pa.us 15766 : 16565 : $$ = (Node *) makeFuncCall($1, NIL,
15767 : : COERCE_EXPLICIT_CALL,
15768 : 16565 : @1);
15769 : : }
15770 : : | func_name '(' func_arg_list opt_sort_clause ')'
15771 : : {
1263 peter@eisentraut.org 15772 : 159508 : FuncCall *n = makeFuncCall($1, $3,
15773 : : COERCE_EXPLICIT_CALL,
15774 : 159508 : @1);
15775 : :
4326 tgl@sss.pgh.pa.us 15776 : 159506 : n->agg_order = $4;
1263 peter@eisentraut.org 15777 : 159506 : $$ = (Node *) n;
15778 : : }
15779 : : | func_name '(' VARIADIC func_arg_expr opt_sort_clause ')'
15780 : : {
15781 : 312 : FuncCall *n = makeFuncCall($1, list_make1($4),
15782 : : COERCE_EXPLICIT_CALL,
15783 : 312 : @1);
15784 : :
2994 peter_e@gmx.net 15785 : 312 : n->func_variadic = true;
4326 tgl@sss.pgh.pa.us 15786 : 312 : n->agg_order = $5;
1263 peter@eisentraut.org 15787 : 312 : $$ = (Node *) n;
15788 : : }
15789 : : | func_name '(' func_arg_list ',' VARIADIC func_arg_expr opt_sort_clause ')'
15790 : : {
15791 : 84 : FuncCall *n = makeFuncCall($1, lappend($3, $6),
15792 : : COERCE_EXPLICIT_CALL,
15793 : 84 : @1);
15794 : :
2994 peter_e@gmx.net 15795 : 84 : n->func_variadic = true;
4326 tgl@sss.pgh.pa.us 15796 : 84 : n->agg_order = $7;
1263 peter@eisentraut.org 15797 : 84 : $$ = (Node *) n;
15798 : : }
15799 : : | func_name '(' ALL func_arg_list opt_sort_clause ')'
15800 : : {
1263 peter@eisentraut.org 15801 :UBC 0 : FuncCall *n = makeFuncCall($1, $4,
15802 : : COERCE_EXPLICIT_CALL,
15803 : 0 : @1);
15804 : :
5795 tgl@sss.pgh.pa.us 15805 : 0 : n->agg_order = $5;
15806 : : /* Ideally we'd mark the FuncCall node to indicate
15807 : : * "must be an aggregate", but there's no provision
15808 : : * for that in FuncCall at the moment.
15809 : : */
1263 peter@eisentraut.org 15810 : 0 : $$ = (Node *) n;
15811 : : }
15812 : : | func_name '(' DISTINCT func_arg_list opt_sort_clause ')'
15813 : : {
1263 peter@eisentraut.org 15814 :CBC 275 : FuncCall *n = makeFuncCall($1, $4,
15815 : : COERCE_EXPLICIT_CALL,
15816 : 275 : @1);
15817 : :
5795 tgl@sss.pgh.pa.us 15818 : 275 : n->agg_order = $5;
2994 peter_e@gmx.net 15819 : 275 : n->agg_distinct = true;
1263 peter@eisentraut.org 15820 : 275 : $$ = (Node *) n;
15821 : : }
15822 : : | func_name '(' '*' ')'
15823 : : {
15824 : : /*
15825 : : * We consider AGGREGATE(*) to invoke a parameterless
15826 : : * aggregate. This does the right thing for COUNT(*),
15827 : : * and there are no other aggregates in SQL that accept
15828 : : * '*' as parameter.
15829 : : *
15830 : : * The FuncCall node is also marked agg_star = true,
15831 : : * so that later processing can detect what the argument
15832 : : * really was.
15833 : : */
15834 : 6426 : FuncCall *n = makeFuncCall($1, NIL,
15835 : : COERCE_EXPLICIT_CALL,
15836 : 6426 : @1);
15837 : :
2994 peter_e@gmx.net 15838 : 6426 : n->agg_star = true;
1263 peter@eisentraut.org 15839 : 6426 : $$ = (Node *) n;
15840 : : }
15841 : : ;
15842 : :
15843 : :
15844 : : /*
15845 : : * func_expr and its cousin func_expr_windowless are split out from c_expr just
15846 : : * so that we have classifications for "everything that is a function call or
15847 : : * looks like one". This isn't very important, but it saves us having to
15848 : : * document which variants are legal in places like "FROM function()" or the
15849 : : * backwards-compatible functional-index syntax for CREATE INDEX.
15850 : : * (Note that many of the special SQL functions wouldn't actually make any
15851 : : * sense as functional index entries, but we ignore that consideration here.)
15852 : : */
15853 : : func_expr: func_application within_group_clause filter_clause null_treatment over_clause
15854 : : {
15855 : 158280 : FuncCall *n = (FuncCall *) $1;
15856 : :
15857 : : /*
15858 : : * The order clause for WITHIN GROUP and the one for
15859 : : * plain-aggregate ORDER BY share a field, so we have to
15860 : : * check here that at most one is present. We also check
15861 : : * for DISTINCT and VARIADIC here to give a better error
15862 : : * location. Other consistency checks are deferred to
15863 : : * parse analysis.
15864 : : */
4326 tgl@sss.pgh.pa.us 15865 [ + + ]: 158280 : if ($2 != NIL)
15866 : : {
15867 [ + + ]: 174 : if (n->agg_order != NIL)
15868 [ + - ]: 3 : ereport(ERROR,
15869 : : (errcode(ERRCODE_SYNTAX_ERROR),
15870 : : errmsg("cannot use multiple ORDER BY clauses with WITHIN GROUP"),
15871 : : parser_errposition(@2)));
15872 [ - + ]: 171 : if (n->agg_distinct)
4326 tgl@sss.pgh.pa.us 15873 [ # # ]:UBC 0 : ereport(ERROR,
15874 : : (errcode(ERRCODE_SYNTAX_ERROR),
15875 : : errmsg("cannot use DISTINCT with WITHIN GROUP"),
15876 : : parser_errposition(@2)));
4326 tgl@sss.pgh.pa.us 15877 [ - + ]:CBC 171 : if (n->func_variadic)
4326 tgl@sss.pgh.pa.us 15878 [ # # ]:UBC 0 : ereport(ERROR,
15879 : : (errcode(ERRCODE_SYNTAX_ERROR),
15880 : : errmsg("cannot use VARIADIC with WITHIN GROUP"),
15881 : : parser_errposition(@2)));
4326 tgl@sss.pgh.pa.us 15882 :CBC 171 : n->agg_order = $2;
2994 peter_e@gmx.net 15883 : 171 : n->agg_within_group = true;
15884 : : }
4326 tgl@sss.pgh.pa.us 15885 : 158277 : n->agg_filter = $3;
24 ishii@postgresql.org 15886 :GNC 158277 : n->ignore_nulls = $4;
15887 : 158277 : n->over = $5;
4326 tgl@sss.pgh.pa.us 15888 :CBC 158277 : $$ = (Node *) n;
15889 : : }
15890 : : | json_aggregate_func filter_clause over_clause
15891 : : {
943 alvherre@alvh.no-ip. 15892 : 360 : JsonAggConstructor *n = IsA($1, JsonObjectAgg) ?
15893 [ + + ]: 180 : ((JsonObjectAgg *) $1)->constructor :
15894 : 78 : ((JsonArrayAgg *) $1)->constructor;
15895 : :
15896 : 180 : n->agg_filter = $2;
15897 : 180 : n->over = $3;
15898 : 180 : $$ = (Node *) $1;
15899 : : }
15900 : : | func_expr_common_subexpr
4504 rhaas@postgresql.org 15901 : 38185 : { $$ = $1; }
15902 : : ;
15903 : :
15904 : : /*
15905 : : * Like func_expr but does not accept WINDOW functions directly
15906 : : * (but they can still be contained in arguments for functions etc).
15907 : : * Use this when window expressions are not allowed, where needed to
15908 : : * disambiguate the grammar (e.g. in CREATE INDEX).
15909 : : */
15910 : : func_expr_windowless:
15911 : 24582 : func_application { $$ = $1; }
4369 peter_e@gmx.net 15912 : 201 : | func_expr_common_subexpr { $$ = $1; }
943 alvherre@alvh.no-ip. 15913 :UBC 0 : | json_aggregate_func { $$ = $1; }
15914 : : ;
15915 : :
15916 : : /*
15917 : : * Special expressions that are considered to be functions.
15918 : : */
15919 : : func_expr_common_subexpr:
15920 : : COLLATION FOR '(' a_expr ')'
15921 : : {
4501 rhaas@postgresql.org 15922 :CBC 15 : $$ = (Node *) makeFuncCall(SystemFuncName("pg_collation_for"),
15923 : 15 : list_make1($4),
15924 : : COERCE_SQL_SYNTAX,
15925 : 15 : @1);
15926 : : }
15927 : : | CURRENT_DATE
15928 : : {
894 michael@paquier.xyz 15929 : 154 : $$ = makeSQLValueFunction(SVFOP_CURRENT_DATE, -1, @1);
15930 : : }
15931 : : | CURRENT_TIME
15932 : : {
15933 : 12 : $$ = makeSQLValueFunction(SVFOP_CURRENT_TIME, -1, @1);
15934 : : }
15935 : : | CURRENT_TIME '(' Iconst ')'
15936 : : {
15937 : 12 : $$ = makeSQLValueFunction(SVFOP_CURRENT_TIME_N, $3, @1);
15938 : : }
15939 : : | CURRENT_TIMESTAMP
15940 : : {
15941 : 144 : $$ = makeSQLValueFunction(SVFOP_CURRENT_TIMESTAMP, -1, @1);
15942 : : }
15943 : : | CURRENT_TIMESTAMP '(' Iconst ')'
15944 : : {
15945 : 87 : $$ = makeSQLValueFunction(SVFOP_CURRENT_TIMESTAMP_N, $3, @1);
15946 : : }
15947 : : | LOCALTIME
15948 : : {
15949 : 12 : $$ = makeSQLValueFunction(SVFOP_LOCALTIME, -1, @1);
15950 : : }
15951 : : | LOCALTIME '(' Iconst ')'
15952 : : {
15953 : 12 : $$ = makeSQLValueFunction(SVFOP_LOCALTIME_N, $3, @1);
15954 : : }
15955 : : | LOCALTIMESTAMP
15956 : : {
15957 : 18 : $$ = makeSQLValueFunction(SVFOP_LOCALTIMESTAMP, -1, @1);
15958 : : }
15959 : : | LOCALTIMESTAMP '(' Iconst ')'
15960 : : {
15961 : 12 : $$ = makeSQLValueFunction(SVFOP_LOCALTIMESTAMP_N, $3, @1);
15962 : : }
15963 : : | CURRENT_ROLE
15964 : : {
15965 : 34 : $$ = makeSQLValueFunction(SVFOP_CURRENT_ROLE, -1, @1);
15966 : : }
15967 : : | CURRENT_USER
15968 : : {
15969 : 530 : $$ = makeSQLValueFunction(SVFOP_CURRENT_USER, -1, @1);
15970 : : }
15971 : : | SESSION_USER
15972 : : {
15973 : 310 : $$ = makeSQLValueFunction(SVFOP_SESSION_USER, -1, @1);
15974 : : }
15975 : : | SYSTEM_USER
15976 : : {
1124 15977 : 12 : $$ = (Node *) makeFuncCall(SystemFuncName("system_user"),
15978 : : NIL,
15979 : : COERCE_SQL_SYNTAX,
15980 : : @1);
15981 : : }
15982 : : | USER
15983 : : {
894 15984 : 12 : $$ = makeSQLValueFunction(SVFOP_USER, -1, @1);
15985 : : }
15986 : : | CURRENT_CATALOG
15987 : : {
15988 : 30 : $$ = makeSQLValueFunction(SVFOP_CURRENT_CATALOG, -1, @1);
15989 : : }
15990 : : | CURRENT_SCHEMA
15991 : : {
15992 : 15 : $$ = makeSQLValueFunction(SVFOP_CURRENT_SCHEMA, -1, @1);
15993 : : }
15994 : : | CAST '(' a_expr AS Typename ')'
6269 tgl@sss.pgh.pa.us 15995 : 31234 : { $$ = makeTypeCast($3, $5, @1); }
15996 : : | EXTRACT '(' extract_list ')'
15997 : : {
1665 peter@eisentraut.org 15998 : 691 : $$ = (Node *) makeFuncCall(SystemFuncName("extract"),
1818 tgl@sss.pgh.pa.us 15999 : 691 : $3,
16000 : : COERCE_SQL_SYNTAX,
16001 : 691 : @1);
16002 : : }
16003 : : | NORMALIZE '(' a_expr ')'
16004 : : {
16005 : 9 : $$ = (Node *) makeFuncCall(SystemFuncName("normalize"),
16006 : 9 : list_make1($3),
16007 : : COERCE_SQL_SYNTAX,
16008 : 9 : @1);
16009 : : }
16010 : : | NORMALIZE '(' a_expr ',' unicode_normal_form ')'
16011 : : {
16012 : 21 : $$ = (Node *) makeFuncCall(SystemFuncName("normalize"),
16013 : 21 : list_make2($3, makeStringConst($5, @5)),
16014 : : COERCE_SQL_SYNTAX,
16015 : 21 : @1);
16016 : : }
16017 : : | OVERLAY '(' overlay_list ')'
16018 : : {
16019 : 41 : $$ = (Node *) makeFuncCall(SystemFuncName("overlay"),
16020 : 41 : $3,
16021 : : COERCE_SQL_SYNTAX,
16022 : 41 : @1);
16023 : : }
16024 : : | OVERLAY '(' func_arg_list_opt ')'
16025 : : {
16026 : : /*
16027 : : * allow functions named overlay() to be called without
16028 : : * special syntax
16029 : : */
1818 tgl@sss.pgh.pa.us 16030 :UBC 0 : $$ = (Node *) makeFuncCall(list_make1(makeString("overlay")),
16031 : 0 : $3,
16032 : : COERCE_EXPLICIT_CALL,
16033 : 0 : @1);
16034 : : }
16035 : : | POSITION '(' position_list ')'
16036 : : {
16037 : : /*
16038 : : * position(A in B) is converted to position(B, A)
16039 : : *
16040 : : * We deliberately don't offer a "plain syntax" option
16041 : : * for position(), because the reversal of the arguments
16042 : : * creates too much risk of confusion.
16043 : : */
1818 tgl@sss.pgh.pa.us 16044 :CBC 200 : $$ = (Node *) makeFuncCall(SystemFuncName("position"),
16045 : 200 : $3,
16046 : : COERCE_SQL_SYNTAX,
16047 : 200 : @1);
16048 : : }
16049 : : | SUBSTRING '(' substr_list ')'
16050 : : {
16051 : : /* substring(A from B for C) is converted to
16052 : : * substring(A, B, C) - thomas 2000-11-28
16053 : : */
16054 : 355 : $$ = (Node *) makeFuncCall(SystemFuncName("substring"),
16055 : 355 : $3,
16056 : : COERCE_SQL_SYNTAX,
16057 : 355 : @1);
16058 : : }
16059 : : | SUBSTRING '(' func_arg_list_opt ')'
16060 : : {
16061 : : /*
16062 : : * allow functions named substring() to be called without
16063 : : * special syntax
16064 : : */
16065 : 126 : $$ = (Node *) makeFuncCall(list_make1(makeString("substring")),
16066 : 126 : $3,
16067 : : COERCE_EXPLICIT_CALL,
16068 : 126 : @1);
16069 : : }
16070 : : | TREAT '(' a_expr AS Typename ')'
16071 : : {
16072 : : /* TREAT(expr AS target) converts expr of a particular type to target,
16073 : : * which is defined to be a subtype of the original expression.
16074 : : * In SQL99, this is intended for use with structured UDTs,
16075 : : * but let's make this a generally useful form allowing stronger
16076 : : * coercions than are handled by implicit casting.
16077 : : *
16078 : : * Convert SystemTypeName() to SystemFuncName() even though
16079 : : * at the moment they result in the same thing.
16080 : : */
1789 peter@eisentraut.org 16081 :UBC 0 : $$ = (Node *) makeFuncCall(SystemFuncName(strVal(llast($5->names))),
1818 tgl@sss.pgh.pa.us 16082 : 0 : list_make1($3),
16083 : : COERCE_EXPLICIT_CALL,
16084 : 0 : @1);
16085 : : }
16086 : : | TRIM '(' BOTH trim_list ')'
16087 : : {
16088 : : /* various trim expressions are defined in SQL
16089 : : * - thomas 1997-07-19
16090 : : */
1818 tgl@sss.pgh.pa.us 16091 :CBC 6 : $$ = (Node *) makeFuncCall(SystemFuncName("btrim"),
16092 : 6 : $4,
16093 : : COERCE_SQL_SYNTAX,
16094 : 6 : @1);
16095 : : }
16096 : : | TRIM '(' LEADING trim_list ')'
16097 : : {
16098 : 12 : $$ = (Node *) makeFuncCall(SystemFuncName("ltrim"),
16099 : 12 : $4,
16100 : : COERCE_SQL_SYNTAX,
16101 : 12 : @1);
16102 : : }
16103 : : | TRIM '(' TRAILING trim_list ')'
16104 : : {
16105 : 291 : $$ = (Node *) makeFuncCall(SystemFuncName("rtrim"),
16106 : 291 : $4,
16107 : : COERCE_SQL_SYNTAX,
16108 : 291 : @1);
16109 : : }
16110 : : | TRIM '(' trim_list ')'
16111 : : {
16112 : 49 : $$ = (Node *) makeFuncCall(SystemFuncName("btrim"),
16113 : 49 : $3,
16114 : : COERCE_SQL_SYNTAX,
16115 : 49 : @1);
16116 : : }
16117 : : | NULLIF '(' a_expr ',' a_expr ')'
16118 : : {
7167 16119 : 192 : $$ = (Node *) makeSimpleA_Expr(AEXPR_NULLIF, "=", $3, $5, @1);
16120 : : }
16121 : : | COALESCE '(' expr_list ')'
16122 : : {
7697 16123 : 1620 : CoalesceExpr *c = makeNode(CoalesceExpr);
16124 : :
16125 : 1620 : c->args = $3;
6269 16126 : 1620 : c->location = @1;
1263 peter@eisentraut.org 16127 : 1620 : $$ = (Node *) c;
16128 : : }
16129 : : | GREATEST '(' expr_list ')'
16130 : : {
7428 tgl@sss.pgh.pa.us 16131 : 73 : MinMaxExpr *v = makeNode(MinMaxExpr);
16132 : :
16133 : 73 : v->args = $3;
16134 : 73 : v->op = IS_GREATEST;
6269 16135 : 73 : v->location = @1;
1263 peter@eisentraut.org 16136 : 73 : $$ = (Node *) v;
16137 : : }
16138 : : | LEAST '(' expr_list ')'
16139 : : {
7428 tgl@sss.pgh.pa.us 16140 : 74 : MinMaxExpr *v = makeNode(MinMaxExpr);
16141 : :
16142 : 74 : v->args = $3;
16143 : 74 : v->op = IS_LEAST;
6269 16144 : 74 : v->location = @1;
1263 peter@eisentraut.org 16145 : 74 : $$ = (Node *) v;
16146 : : }
16147 : : | XMLCONCAT '(' expr_list ')'
16148 : : {
6269 tgl@sss.pgh.pa.us 16149 : 31 : $$ = makeXmlExpr(IS_XMLCONCAT, NULL, NIL, $3, @1);
16150 : : }
16151 : : | XMLELEMENT '(' NAME_P ColLabel ')'
16152 : : {
16153 : 3 : $$ = makeXmlExpr(IS_XMLELEMENT, $4, NIL, NIL, @1);
16154 : : }
16155 : : | XMLELEMENT '(' NAME_P ColLabel ',' xml_attributes ')'
16156 : : {
16157 : 18 : $$ = makeXmlExpr(IS_XMLELEMENT, $4, $6, NIL, @1);
16158 : : }
16159 : : | XMLELEMENT '(' NAME_P ColLabel ',' expr_list ')'
16160 : : {
16161 : 58 : $$ = makeXmlExpr(IS_XMLELEMENT, $4, NIL, $6, @1);
16162 : : }
16163 : : | XMLELEMENT '(' NAME_P ColLabel ',' xml_attributes ',' expr_list ')'
16164 : : {
16165 : 10 : $$ = makeXmlExpr(IS_XMLELEMENT, $4, $6, $8, @1);
16166 : : }
16167 : : | XMLEXISTS '(' c_expr xmlexists_argument ')'
16168 : : {
16169 : : /* xmlexists(A PASSING [BY REF] B [BY REF]) is
16170 : : * converted to xmlexists(A, B)*/
1818 16171 : 27 : $$ = (Node *) makeFuncCall(SystemFuncName("xmlexists"),
16172 : 27 : list_make2($3, $4),
16173 : : COERCE_SQL_SYNTAX,
16174 : 27 : @1);
16175 : : }
16176 : : | XMLFOREST '(' xml_attribute_list ')'
16177 : : {
6269 16178 : 16 : $$ = makeXmlExpr(IS_XMLFOREST, NULL, $3, NIL, @1);
16179 : : }
16180 : : | XMLPARSE '(' document_or_content a_expr xml_whitespace_option ')'
16181 : : {
16182 : : XmlExpr *x = (XmlExpr *)
16183 : 70 : makeXmlExpr(IS_XMLPARSE, NULL, NIL,
16184 : 70 : list_make2($4, makeBoolAConst($5, -1)),
16185 : 70 : @1);
16186 : :
6841 peter_e@gmx.net 16187 : 70 : x->xmloption = $3;
1263 peter@eisentraut.org 16188 : 70 : $$ = (Node *) x;
16189 : : }
16190 : : | XMLPI '(' NAME_P ColLabel ')'
16191 : : {
6269 tgl@sss.pgh.pa.us 16192 : 15 : $$ = makeXmlExpr(IS_XMLPI, $4, NULL, NIL, @1);
16193 : : }
16194 : : | XMLPI '(' NAME_P ColLabel ',' a_expr ')'
16195 : : {
16196 : 25 : $$ = makeXmlExpr(IS_XMLPI, $4, NULL, list_make1($6), @1);
16197 : : }
16198 : : | XMLROOT '(' a_expr ',' xml_root_version opt_xml_root_standalone ')'
16199 : : {
6882 16200 : 34 : $$ = makeXmlExpr(IS_XMLROOT, NULL, NIL,
6269 16201 : 34 : list_make3($3, $5, $6), @1);
16202 : : }
16203 : : | XMLSERIALIZE '(' document_or_content a_expr AS SimpleTypename xml_indent_option ')'
16204 : : {
6841 peter_e@gmx.net 16205 : 109 : XmlSerialize *n = makeNode(XmlSerialize);
16206 : :
16207 : 109 : n->xmloption = $3;
16208 : 109 : n->expr = $4;
5947 16209 : 109 : n->typeName = $6;
957 tgl@sss.pgh.pa.us 16210 : 109 : n->indent = $7;
6269 16211 : 109 : n->location = @1;
1263 peter@eisentraut.org 16212 : 109 : $$ = (Node *) n;
16213 : : }
16214 : : | JSON_OBJECT '(' func_arg_list ')'
16215 : : {
16216 : : /* Support for legacy (non-standard) json_object() */
943 alvherre@alvh.no-ip. 16217 : 45 : $$ = (Node *) makeFuncCall(SystemFuncName("json_object"),
16218 : 45 : $3, COERCE_EXPLICIT_CALL, @1);
16219 : : }
16220 : : | JSON_OBJECT '(' json_name_and_value_list
16221 : : json_object_constructor_null_clause_opt
16222 : : json_key_uniqueness_constraint_opt
16223 : : json_returning_clause_opt ')'
16224 : : {
16225 : 171 : JsonObjectConstructor *n = makeNode(JsonObjectConstructor);
16226 : :
16227 : 171 : n->exprs = $3;
16228 : 171 : n->absent_on_null = $4;
16229 : 171 : n->unique = $5;
16230 : 171 : n->output = (JsonOutput *) $6;
16231 : 171 : n->location = @1;
16232 : 171 : $$ = (Node *) n;
16233 : : }
16234 : : | JSON_OBJECT '(' json_returning_clause_opt ')'
16235 : : {
16236 : 44 : JsonObjectConstructor *n = makeNode(JsonObjectConstructor);
16237 : :
16238 : 44 : n->exprs = NULL;
16239 : 44 : n->absent_on_null = false;
16240 : 44 : n->unique = false;
16241 : 44 : n->output = (JsonOutput *) $3;
16242 : 44 : n->location = @1;
16243 : 44 : $$ = (Node *) n;
16244 : : }
16245 : : | JSON_ARRAY '('
16246 : : json_value_expr_list
16247 : : json_array_constructor_null_clause_opt
16248 : : json_returning_clause_opt
16249 : : ')'
16250 : : {
16251 : 60 : JsonArrayConstructor *n = makeNode(JsonArrayConstructor);
16252 : :
16253 : 60 : n->exprs = $3;
16254 : 60 : n->absent_on_null = $4;
16255 : 60 : n->output = (JsonOutput *) $5;
16256 : 60 : n->location = @1;
16257 : 60 : $$ = (Node *) n;
16258 : : }
16259 : : | JSON_ARRAY '('
16260 : : select_no_parens
16261 : : json_format_clause_opt
16262 : : /* json_array_constructor_null_clause_opt */
16263 : : json_returning_clause_opt
16264 : : ')'
16265 : : {
16266 : 30 : JsonArrayQueryConstructor *n = makeNode(JsonArrayQueryConstructor);
16267 : :
16268 : 30 : n->query = $3;
16269 : 30 : n->format = (JsonFormat *) $4;
16270 : 30 : n->absent_on_null = true; /* XXX */
16271 : 30 : n->output = (JsonOutput *) $5;
16272 : 30 : n->location = @1;
16273 : 30 : $$ = (Node *) n;
16274 : : }
16275 : : | JSON_ARRAY '('
16276 : : json_returning_clause_opt
16277 : : ')'
16278 : : {
16279 : 41 : JsonArrayConstructor *n = makeNode(JsonArrayConstructor);
16280 : :
16281 : 41 : n->exprs = NIL;
16282 : 41 : n->absent_on_null = true;
16283 : 41 : n->output = (JsonOutput *) $3;
16284 : 41 : n->location = @1;
16285 : 41 : $$ = (Node *) n;
16286 : : }
16287 : : | JSON '(' json_value_expr json_key_uniqueness_constraint_opt ')'
16288 : : {
830 amitlan@postgresql.o 16289 : 74 : JsonParseExpr *n = makeNode(JsonParseExpr);
16290 : :
16291 : 74 : n->expr = (JsonValueExpr *) $3;
16292 : 74 : n->unique_keys = $4;
16293 : 74 : n->output = NULL;
16294 : 74 : n->location = @1;
16295 : 74 : $$ = (Node *) n;
16296 : : }
16297 : : | JSON_SCALAR '(' a_expr ')'
16298 : : {
16299 : 49 : JsonScalarExpr *n = makeNode(JsonScalarExpr);
16300 : :
16301 : 49 : n->expr = (Expr *) $3;
16302 : 49 : n->output = NULL;
16303 : 49 : n->location = @1;
16304 : 49 : $$ = (Node *) n;
16305 : : }
16306 : : | JSON_SERIALIZE '(' json_value_expr json_returning_clause_opt ')'
16307 : : {
16308 : 48 : JsonSerializeExpr *n = makeNode(JsonSerializeExpr);
16309 : :
16310 : 48 : n->expr = (JsonValueExpr *) $3;
16311 : 48 : n->output = (JsonOutput *) $4;
16312 : 48 : n->location = @1;
16313 : 48 : $$ = (Node *) n;
16314 : : }
16315 : : | MERGE_ACTION '(' ')'
16316 : : {
589 dean.a.rasheed@gmail 16317 : 105 : MergeSupportFunc *m = makeNode(MergeSupportFunc);
16318 : :
16319 : 105 : m->msftype = TEXTOID;
16320 : 105 : m->location = @1;
16321 : 105 : $$ = (Node *) m;
16322 : : }
16323 : : | JSON_QUERY '('
16324 : : json_value_expr ',' a_expr json_passing_clause_opt
16325 : : json_returning_clause_opt
16326 : : json_wrapper_behavior
16327 : : json_quotes_clause_opt
16328 : : json_behavior_clause_opt
16329 : : ')'
16330 : : {
585 amitlan@postgresql.o 16331 : 492 : JsonFuncExpr *n = makeNode(JsonFuncExpr);
16332 : :
16333 : 492 : n->op = JSON_QUERY_OP;
16334 : 492 : n->context_item = (JsonValueExpr *) $3;
16335 : 492 : n->pathspec = $5;
16336 : 492 : n->passing = $6;
16337 : 492 : n->output = (JsonOutput *) $7;
16338 : 492 : n->wrapper = $8;
16339 : 492 : n->quotes = $9;
16340 : 492 : n->on_empty = (JsonBehavior *) linitial($10);
16341 : 492 : n->on_error = (JsonBehavior *) lsecond($10);
16342 : 492 : n->location = @1;
16343 : 492 : $$ = (Node *) n;
16344 : : }
16345 : : | JSON_EXISTS '('
16346 : : json_value_expr ',' a_expr json_passing_clause_opt
16347 : : json_on_error_clause_opt
16348 : : ')'
16349 : : {
16350 : 84 : JsonFuncExpr *n = makeNode(JsonFuncExpr);
16351 : :
16352 : 84 : n->op = JSON_EXISTS_OP;
16353 : 84 : n->context_item = (JsonValueExpr *) $3;
16354 : 84 : n->pathspec = $5;
16355 : 84 : n->passing = $6;
16356 : 84 : n->output = NULL;
16357 : 84 : n->on_error = (JsonBehavior *) $7;
16358 : 84 : n->location = @1;
16359 : 84 : $$ = (Node *) n;
16360 : : }
16361 : : | JSON_VALUE '('
16362 : : json_value_expr ',' a_expr json_passing_clause_opt
16363 : : json_returning_clause_opt
16364 : : json_behavior_clause_opt
16365 : : ')'
16366 : : {
16367 : 312 : JsonFuncExpr *n = makeNode(JsonFuncExpr);
16368 : :
16369 : 312 : n->op = JSON_VALUE_OP;
16370 : 312 : n->context_item = (JsonValueExpr *) $3;
16371 : 312 : n->pathspec = $5;
16372 : 312 : n->passing = $6;
16373 : 312 : n->output = (JsonOutput *) $7;
16374 : 312 : n->on_empty = (JsonBehavior *) linitial($8);
16375 : 312 : n->on_error = (JsonBehavior *) lsecond($8);
16376 : 312 : n->location = @1;
16377 : 312 : $$ = (Node *) n;
16378 : : }
16379 : : ;
16380 : :
16381 : :
16382 : : /*
16383 : : * SQL/XML support
16384 : : */
16385 : : xml_root_version: VERSION_P a_expr
6882 tgl@sss.pgh.pa.us 16386 : 12 : { $$ = $2; }
16387 : : | VERSION_P NO VALUE_P
6269 16388 : 22 : { $$ = makeNullAConst(-1); }
16389 : : ;
16390 : :
16391 : : opt_xml_root_standalone: ',' STANDALONE_P YES_P
16392 : 13 : { $$ = makeIntConst(XML_STANDALONE_YES, -1); }
16393 : : | ',' STANDALONE_P NO
16394 : 6 : { $$ = makeIntConst(XML_STANDALONE_NO, -1); }
16395 : : | ',' STANDALONE_P NO VALUE_P
16396 : 6 : { $$ = makeIntConst(XML_STANDALONE_NO_VALUE, -1); }
16397 : : | /*EMPTY*/
16398 : 9 : { $$ = makeIntConst(XML_STANDALONE_OMITTED, -1); }
16399 : : ;
16400 : :
6882 16401 : 28 : xml_attributes: XMLATTRIBUTES '(' xml_attribute_list ')' { $$ = $3; }
16402 : : ;
16403 : :
6885 peter_e@gmx.net 16404 : 44 : xml_attribute_list: xml_attribute_el { $$ = list_make1($1); }
16405 : 72 : | xml_attribute_list ',' xml_attribute_el { $$ = lappend($1, $3); }
16406 : : ;
16407 : :
16408 : : xml_attribute_el: a_expr AS ColLabel
16409 : : {
16410 : 53 : $$ = makeNode(ResTarget);
16411 : 53 : $$->name = $3;
6267 tgl@sss.pgh.pa.us 16412 : 53 : $$->indirection = NIL;
6885 peter_e@gmx.net 16413 : 53 : $$->val = (Node *) $1;
6882 tgl@sss.pgh.pa.us 16414 : 53 : $$->location = @1;
16415 : : }
16416 : : | a_expr
16417 : : {
6885 peter_e@gmx.net 16418 : 63 : $$ = makeNode(ResTarget);
16419 : 63 : $$->name = NULL;
6267 tgl@sss.pgh.pa.us 16420 : 63 : $$->indirection = NIL;
6876 16421 : 63 : $$->val = (Node *) $1;
6882 16422 : 63 : $$->location = @1;
16423 : : }
16424 : : ;
16425 : :
6841 peter_e@gmx.net 16426 : 93 : document_or_content: DOCUMENT_P { $$ = XMLOPTION_DOCUMENT; }
16427 : 94 : | CONTENT_P { $$ = XMLOPTION_CONTENT; }
16428 : : ;
16429 : :
957 tgl@sss.pgh.pa.us 16430 : 70 : xml_indent_option: INDENT { $$ = true; }
16431 : 18 : | NO INDENT { $$ = false; }
16432 : 21 : | /*EMPTY*/ { $$ = false; }
16433 : : ;
16434 : :
2994 peter_e@gmx.net 16435 :UBC 0 : xml_whitespace_option: PRESERVE WHITESPACE_P { $$ = true; }
2994 peter_e@gmx.net 16436 :CBC 1 : | STRIP_P WHITESPACE_P { $$ = false; }
16437 : 69 : | /*EMPTY*/ { $$ = false; }
16438 : : ;
16439 : :
16440 : : /* We allow several variants for SQL and other compatibility. */
16441 : : xmlexists_argument:
16442 : : PASSING c_expr
16443 : : {
5562 16444 : 119 : $$ = $2;
16445 : : }
16446 : : | PASSING c_expr xml_passing_mech
16447 : : {
5562 peter_e@gmx.net 16448 :UBC 0 : $$ = $2;
16449 : : }
16450 : : | PASSING xml_passing_mech c_expr
16451 : : {
2426 alvherre@alvh.no-ip. 16452 :CBC 21 : $$ = $3;
16453 : : }
16454 : : | PASSING xml_passing_mech c_expr xml_passing_mech
16455 : : {
16456 : 3 : $$ = $3;
16457 : : }
16458 : : ;
16459 : :
16460 : : xml_passing_mech:
16461 : : BY REF_P
16462 : : | BY VALUE_P
16463 : : ;
16464 : :
16465 : :
16466 : : /*
16467 : : * Aggregate decoration clauses
16468 : : */
16469 : : within_group_clause:
4326 tgl@sss.pgh.pa.us 16470 : 174 : WITHIN GROUP_P '(' sort_clause ')' { $$ = $4; }
16471 : 158109 : | /*EMPTY*/ { $$ = NIL; }
16472 : : ;
16473 : :
16474 : : filter_clause:
16475 : 431 : FILTER '(' WHERE a_expr ')' { $$ = $4; }
16476 : 158032 : | /*EMPTY*/ { $$ = NULL; }
16477 : : ;
16478 : :
16479 : :
16480 : : /*
16481 : : * Window Definitions
16482 : : */
16483 : : null_treatment:
24 ishii@postgresql.org 16484 :GNC 99 : IGNORE_P NULLS_P { $$ = PARSER_IGNORE_NULLS; }
16485 : 48 : | RESPECT_P NULLS_P { $$ = PARSER_RESPECT_NULLS; }
16486 : 158136 : | /*EMPTY*/ { $$ = NO_NULLTREATMENT; }
16487 : : ;
16488 : :
16489 : : window_clause:
6147 tgl@sss.pgh.pa.us 16490 :CBC 303 : WINDOW window_definition_list { $$ = $2; }
16491 : 239507 : | /*EMPTY*/ { $$ = NIL; }
16492 : : ;
16493 : :
16494 : : window_definition_list:
16495 : 303 : window_definition { $$ = list_make1($1); }
16496 : : | window_definition_list ',' window_definition
16497 : 15 : { $$ = lappend($1, $3); }
16498 : : ;
16499 : :
16500 : : window_definition:
16501 : : ColId AS window_specification
16502 : : {
1263 peter@eisentraut.org 16503 : 318 : WindowDef *n = $3;
16504 : :
6147 tgl@sss.pgh.pa.us 16505 : 318 : n->name = $1;
16506 : 318 : $$ = n;
16507 : : }
16508 : : ;
16509 : :
16510 : : over_clause: OVER window_specification
16511 : 1377 : { $$ = $2; }
16512 : : | OVER ColId
16513 : : {
1263 peter@eisentraut.org 16514 : 591 : WindowDef *n = makeNode(WindowDef);
16515 : :
6144 tgl@sss.pgh.pa.us 16516 : 591 : n->name = $2;
16517 : 591 : n->refname = NULL;
6147 16518 : 591 : n->partitionClause = NIL;
16519 : 591 : n->orderClause = NIL;
6144 16520 : 591 : n->frameOptions = FRAMEOPTION_DEFAULTS;
5736 16521 : 591 : n->startOffset = NULL;
16522 : 591 : n->endOffset = NULL;
6147 16523 : 591 : n->location = @2;
16524 : 591 : $$ = n;
16525 : : }
16526 : : | /*EMPTY*/
16527 : 156492 : { $$ = NULL; }
16528 : : ;
16529 : :
16530 : : window_specification: '(' opt_existing_window_name opt_partition_clause
16531 : : opt_sort_clause opt_frame_clause ')'
16532 : : {
1263 peter@eisentraut.org 16533 : 1695 : WindowDef *n = makeNode(WindowDef);
16534 : :
6147 tgl@sss.pgh.pa.us 16535 : 1695 : n->name = NULL;
16536 : 1695 : n->refname = $2;
16537 : 1695 : n->partitionClause = $3;
16538 : 1695 : n->orderClause = $4;
16539 : : /* copy relevant fields of opt_frame_clause */
5736 16540 : 1695 : n->frameOptions = $5->frameOptions;
16541 : 1695 : n->startOffset = $5->startOffset;
16542 : 1695 : n->endOffset = $5->endOffset;
6147 16543 : 1695 : n->location = @1;
16544 : 1695 : $$ = n;
16545 : : }
16546 : : ;
16547 : :
16548 : : /*
16549 : : * If we see PARTITION, RANGE, ROWS or GROUPS as the first token after the '('
16550 : : * of a window_specification, we want the assumption to be that there is
16551 : : * no existing_window_name; but those keywords are unreserved and so could
16552 : : * be ColIds. We fix this by making them have the same precedence as IDENT
16553 : : * and giving the empty production here a slightly higher precedence, so
16554 : : * that the shift/reduce conflict is resolved in favor of reducing the rule.
16555 : : * These keywords are thus precluded from being an existing_window_name but
16556 : : * are not reserved for any other purpose.
16557 : : */
16558 : 27 : opt_existing_window_name: ColId { $$ = $1; }
16559 : 1671 : | /*EMPTY*/ %prec Op { $$ = NULL; }
16560 : : ;
16561 : :
16562 : 466 : opt_partition_clause: PARTITION BY expr_list { $$ = $3; }
16563 : 1229 : | /*EMPTY*/ { $$ = NIL; }
16564 : : ;
16565 : :
16566 : : /*
16567 : : * For frame clauses, we return a WindowDef, but only some fields are used:
16568 : : * frameOptions, startOffset, and endOffset.
16569 : : */
16570 : : opt_frame_clause:
16571 : : RANGE frame_extent opt_window_exclusion_clause
16572 : : {
1263 peter@eisentraut.org 16573 : 398 : WindowDef *n = $2;
16574 : :
5736 tgl@sss.pgh.pa.us 16575 : 398 : n->frameOptions |= FRAMEOPTION_NONDEFAULT | FRAMEOPTION_RANGE;
2819 16576 : 398 : n->frameOptions |= $3;
5736 16577 : 398 : $$ = n;
16578 : : }
16579 : : | ROWS frame_extent opt_window_exclusion_clause
16580 : : {
1263 peter@eisentraut.org 16581 : 345 : WindowDef *n = $2;
16582 : :
5736 tgl@sss.pgh.pa.us 16583 : 345 : n->frameOptions |= FRAMEOPTION_NONDEFAULT | FRAMEOPTION_ROWS;
2819 16584 : 345 : n->frameOptions |= $3;
16585 : 345 : $$ = n;
16586 : : }
16587 : : | GROUPS frame_extent opt_window_exclusion_clause
16588 : : {
1263 peter@eisentraut.org 16589 : 102 : WindowDef *n = $2;
16590 : :
2819 tgl@sss.pgh.pa.us 16591 : 102 : n->frameOptions |= FRAMEOPTION_NONDEFAULT | FRAMEOPTION_GROUPS;
16592 : 102 : n->frameOptions |= $3;
5736 16593 : 102 : $$ = n;
16594 : : }
16595 : : | /*EMPTY*/
16596 : : {
1263 peter@eisentraut.org 16597 : 850 : WindowDef *n = makeNode(WindowDef);
16598 : :
5736 tgl@sss.pgh.pa.us 16599 : 850 : n->frameOptions = FRAMEOPTION_DEFAULTS;
16600 : 850 : n->startOffset = NULL;
16601 : 850 : n->endOffset = NULL;
16602 : 850 : $$ = n;
16603 : : }
16604 : : ;
16605 : :
16606 : : frame_extent: frame_bound
16607 : : {
1263 peter@eisentraut.org 16608 : 6 : WindowDef *n = $1;
16609 : :
16610 : : /* reject invalid cases */
5736 tgl@sss.pgh.pa.us 16611 [ - + ]: 6 : if (n->frameOptions & FRAMEOPTION_START_UNBOUNDED_FOLLOWING)
6144 tgl@sss.pgh.pa.us 16612 [ # # ]:UBC 0 : ereport(ERROR,
16613 : : (errcode(ERRCODE_WINDOWING_ERROR),
16614 : : errmsg("frame start cannot be UNBOUNDED FOLLOWING"),
16615 : : parser_errposition(@1)));
2819 tgl@sss.pgh.pa.us 16616 [ - + ]:CBC 6 : if (n->frameOptions & FRAMEOPTION_START_OFFSET_FOLLOWING)
6144 tgl@sss.pgh.pa.us 16617 [ # # ]:UBC 0 : ereport(ERROR,
16618 : : (errcode(ERRCODE_WINDOWING_ERROR),
16619 : : errmsg("frame starting from following row cannot end with current row"),
16620 : : parser_errposition(@1)));
5736 tgl@sss.pgh.pa.us 16621 :CBC 6 : n->frameOptions |= FRAMEOPTION_END_CURRENT_ROW;
16622 : 6 : $$ = n;
16623 : : }
16624 : : | BETWEEN frame_bound AND frame_bound
16625 : : {
1263 peter@eisentraut.org 16626 : 839 : WindowDef *n1 = $2;
16627 : 839 : WindowDef *n2 = $4;
16628 : :
16629 : : /* form merged options */
5736 tgl@sss.pgh.pa.us 16630 : 839 : int frameOptions = n1->frameOptions;
16631 : : /* shift converts START_ options to END_ options */
16632 : 839 : frameOptions |= n2->frameOptions << 1;
16633 : 839 : frameOptions |= FRAMEOPTION_BETWEEN;
16634 : : /* reject invalid cases */
16635 [ - + ]: 839 : if (frameOptions & FRAMEOPTION_START_UNBOUNDED_FOLLOWING)
6144 tgl@sss.pgh.pa.us 16636 [ # # ]:UBC 0 : ereport(ERROR,
16637 : : (errcode(ERRCODE_WINDOWING_ERROR),
16638 : : errmsg("frame start cannot be UNBOUNDED FOLLOWING"),
16639 : : parser_errposition(@2)));
5736 tgl@sss.pgh.pa.us 16640 [ - + ]:CBC 839 : if (frameOptions & FRAMEOPTION_END_UNBOUNDED_PRECEDING)
6144 tgl@sss.pgh.pa.us 16641 [ # # ]:UBC 0 : ereport(ERROR,
16642 : : (errcode(ERRCODE_WINDOWING_ERROR),
16643 : : errmsg("frame end cannot be UNBOUNDED PRECEDING"),
16644 : : parser_errposition(@4)));
5736 tgl@sss.pgh.pa.us 16645 [ + + ]:CBC 839 : if ((frameOptions & FRAMEOPTION_START_CURRENT_ROW) &&
2819 16646 [ - + ]: 230 : (frameOptions & FRAMEOPTION_END_OFFSET_PRECEDING))
5736 tgl@sss.pgh.pa.us 16647 [ # # ]:UBC 0 : ereport(ERROR,
16648 : : (errcode(ERRCODE_WINDOWING_ERROR),
16649 : : errmsg("frame starting from current row cannot have preceding rows"),
16650 : : parser_errposition(@4)));
2819 tgl@sss.pgh.pa.us 16651 [ + + ]:CBC 839 : if ((frameOptions & FRAMEOPTION_START_OFFSET_FOLLOWING) &&
16652 [ - + ]: 84 : (frameOptions & (FRAMEOPTION_END_OFFSET_PRECEDING |
16653 : : FRAMEOPTION_END_CURRENT_ROW)))
5736 tgl@sss.pgh.pa.us 16654 [ # # ]:UBC 0 : ereport(ERROR,
16655 : : (errcode(ERRCODE_WINDOWING_ERROR),
16656 : : errmsg("frame starting from following row cannot have preceding rows"),
16657 : : parser_errposition(@4)));
5736 tgl@sss.pgh.pa.us 16658 :CBC 839 : n1->frameOptions = frameOptions;
16659 : 839 : n1->endOffset = n2->startOffset;
16660 : 839 : $$ = n1;
16661 : : }
16662 : : ;
16663 : :
16664 : : /*
16665 : : * This is used for both frame start and frame end, with output set up on
16666 : : * the assumption it's frame start; the frame_extent productions must reject
16667 : : * invalid cases.
16668 : : */
16669 : : frame_bound:
16670 : : UNBOUNDED PRECEDING
16671 : : {
1263 peter@eisentraut.org 16672 : 108 : WindowDef *n = makeNode(WindowDef);
16673 : :
5736 tgl@sss.pgh.pa.us 16674 : 108 : n->frameOptions = FRAMEOPTION_START_UNBOUNDED_PRECEDING;
16675 : 108 : n->startOffset = NULL;
16676 : 108 : n->endOffset = NULL;
16677 : 108 : $$ = n;
16678 : : }
16679 : : | UNBOUNDED FOLLOWING
16680 : : {
1263 peter@eisentraut.org 16681 : 197 : WindowDef *n = makeNode(WindowDef);
16682 : :
5736 tgl@sss.pgh.pa.us 16683 : 197 : n->frameOptions = FRAMEOPTION_START_UNBOUNDED_FOLLOWING;
16684 : 197 : n->startOffset = NULL;
16685 : 197 : n->endOffset = NULL;
16686 : 197 : $$ = n;
16687 : : }
16688 : : | CURRENT_P ROW
16689 : : {
1263 peter@eisentraut.org 16690 : 302 : WindowDef *n = makeNode(WindowDef);
16691 : :
5736 tgl@sss.pgh.pa.us 16692 : 302 : n->frameOptions = FRAMEOPTION_START_CURRENT_ROW;
16693 : 302 : n->startOffset = NULL;
16694 : 302 : n->endOffset = NULL;
16695 : 302 : $$ = n;
16696 : : }
16697 : : | a_expr PRECEDING
16698 : : {
1263 peter@eisentraut.org 16699 : 477 : WindowDef *n = makeNode(WindowDef);
16700 : :
2819 tgl@sss.pgh.pa.us 16701 : 477 : n->frameOptions = FRAMEOPTION_START_OFFSET_PRECEDING;
5736 16702 : 477 : n->startOffset = $1;
16703 : 477 : n->endOffset = NULL;
16704 : 477 : $$ = n;
16705 : : }
16706 : : | a_expr FOLLOWING
16707 : : {
1263 peter@eisentraut.org 16708 : 600 : WindowDef *n = makeNode(WindowDef);
16709 : :
2819 tgl@sss.pgh.pa.us 16710 : 600 : n->frameOptions = FRAMEOPTION_START_OFFSET_FOLLOWING;
5736 16711 : 600 : n->startOffset = $1;
16712 : 600 : n->endOffset = NULL;
16713 : 600 : $$ = n;
16714 : : }
16715 : : ;
16716 : :
16717 : : opt_window_exclusion_clause:
2819 16718 : 48 : EXCLUDE CURRENT_P ROW { $$ = FRAMEOPTION_EXCLUDE_CURRENT_ROW; }
16719 : 48 : | EXCLUDE GROUP_P { $$ = FRAMEOPTION_EXCLUDE_GROUP; }
16720 : 75 : | EXCLUDE TIES { $$ = FRAMEOPTION_EXCLUDE_TIES; }
16721 : 9 : | EXCLUDE NO OTHERS { $$ = 0; }
16722 : 665 : | /*EMPTY*/ { $$ = 0; }
16723 : : ;
16724 : :
16725 : :
16726 : : /*
16727 : : * Supporting nonterminals for expressions.
16728 : : */
16729 : :
16730 : : /* Explicit row production.
16731 : : *
16732 : : * SQL99 allows an optional ROW keyword, so we can now do single-element rows
16733 : : * without conflicting with the parenthesized a_expr production. Without the
16734 : : * ROW keyword, there must be more than one a_expr inside the parens.
16735 : : */
7840 tgl@sss.pgh.pa.us 16736 :UBC 0 : row: ROW '(' expr_list ')' { $$ = $3; }
16737 : 0 : | ROW '(' ')' { $$ = NIL; }
7840 tgl@sss.pgh.pa.us 16738 :CBC 966 : | '(' expr_list ',' a_expr ')' { $$ = lappend($2, $4); }
16739 : : ;
16740 : :
3817 andres@anarazel.de 16741 : 1896 : explicit_row: ROW '(' expr_list ')' { $$ = $3; }
16742 : 18 : | ROW '(' ')' { $$ = NIL; }
16743 : : ;
16744 : :
16745 : 1352 : implicit_row: '(' expr_list ',' a_expr ')' { $$ = lappend($2, $4); }
16746 : : ;
16747 : :
7840 tgl@sss.pgh.pa.us 16748 : 8369 : sub_type: ANY { $$ = ANY_SUBLINK; }
7840 tgl@sss.pgh.pa.us 16749 :UBC 0 : | SOME { $$ = ANY_SUBLINK; }
7840 tgl@sss.pgh.pa.us 16750 :CBC 162 : | ALL { $$ = ALL_SUBLINK; }
16751 : : ;
16752 : :
16753 : 5687 : all_Op: Op { $$ = $1; }
16754 : 14696 : | MathOp { $$ = $1; }
16755 : : ;
16756 : :
16757 : 20 : MathOp: '+' { $$ = "+"; }
16758 : 33 : | '-' { $$ = "-"; }
16759 : 75 : | '*' { $$ = "*"; }
7840 tgl@sss.pgh.pa.us 16760 :UBC 0 : | '/' { $$ = "/"; }
7840 tgl@sss.pgh.pa.us 16761 :CBC 4 : | '%' { $$ = "%"; }
7840 tgl@sss.pgh.pa.us 16762 :UBC 0 : | '^' { $$ = "^"; }
7840 tgl@sss.pgh.pa.us 16763 :CBC 489 : | '<' { $$ = "<"; }
16764 : 440 : | '>' { $$ = ">"; }
16765 : 12401 : | '=' { $$ = "="; }
3883 16766 : 422 : | LESS_EQUALS { $$ = "<="; }
16767 : 418 : | GREATER_EQUALS { $$ = ">="; }
16768 : 394 : | NOT_EQUALS { $$ = "<>"; }
16769 : : ;
16770 : :
16771 : : qual_Op: Op
7820 neilc@samurai.com 16772 : 21846 : { $$ = list_make1(makeString($1)); }
16773 : : | OPERATOR '(' any_operator ')'
7840 tgl@sss.pgh.pa.us 16774 : 7947 : { $$ = $3; }
16775 : : ;
16776 : :
16777 : : qual_all_Op:
16778 : : all_Op
7820 neilc@samurai.com 16779 : 708 : { $$ = list_make1(makeString($1)); }
16780 : : | OPERATOR '(' any_operator ')'
7840 tgl@sss.pgh.pa.us 16781 : 17 : { $$ = $3; }
16782 : : ;
16783 : :
16784 : : subquery_Op:
16785 : : all_Op
7820 neilc@samurai.com 16786 : 8376 : { $$ = list_make1(makeString($1)); }
16787 : : | OPERATOR '(' any_operator ')'
7840 tgl@sss.pgh.pa.us 16788 : 139 : { $$ = $3; }
16789 : : | LIKE
7820 neilc@samurai.com 16790 : 12 : { $$ = list_make1(makeString("~~")); }
16791 : : | NOT_LA LIKE
16792 : 6 : { $$ = list_make1(makeString("!~~")); }
16793 : : | ILIKE
16794 : 6 : { $$ = list_make1(makeString("~~*")); }
16795 : : | NOT_LA ILIKE
7820 neilc@samurai.com 16796 :UBC 0 : { $$ = list_make1(makeString("!~~*")); }
16797 : : /* cannot put SIMILAR TO here, because SIMILAR TO is a hack.
16798 : : * the regular expression is preprocessed by a function (similar_to_escape),
16799 : : * and the ~ operator for posix regular expressions is used.
16800 : : * x SIMILAR TO y -> x ~ similar_to_escape(y)
16801 : : * this transformation is made on the fly by the parser upwards.
16802 : : * however the SubLink structure which handles any/some/all stuff
16803 : : * is not ready for such a thing.
16804 : : */
16805 : : ;
16806 : :
16807 : : expr_list: a_expr
16808 : : {
7818 tgl@sss.pgh.pa.us 16809 :CBC 82463 : $$ = list_make1($1);
16810 : : }
16811 : : | expr_list ',' a_expr
16812 : : {
16813 : 75641 : $$ = lappend($1, $3);
16814 : : }
16815 : : ;
16816 : :
16817 : : /* function arguments can have names */
16818 : : func_arg_list: func_arg_expr
16819 : : {
5863 16820 : 160038 : $$ = list_make1($1);
16821 : : }
16822 : : | func_arg_list ',' func_arg_expr
16823 : : {
16824 : 143643 : $$ = lappend($1, $3);
16825 : : }
16826 : : ;
16827 : :
16828 : : func_arg_expr: a_expr
16829 : : {
16830 : 278276 : $$ = $1;
16831 : : }
16832 : : | param_name COLON_EQUALS a_expr
16833 : : {
16834 : 24821 : NamedArgExpr *na = makeNode(NamedArgExpr);
16835 : :
5629 16836 : 24821 : na->name = $1;
16837 : 24821 : na->arg = (Expr *) $3;
5863 16838 : 24821 : na->argnumber = -1; /* until determined */
5629 16839 : 24821 : na->location = @1;
5863 16840 : 24821 : $$ = (Node *) na;
16841 : : }
16842 : : | param_name EQUALS_GREATER a_expr
16843 : : {
3884 rhaas@postgresql.org 16844 : 980 : NamedArgExpr *na = makeNode(NamedArgExpr);
16845 : :
16846 : 980 : na->name = $1;
16847 : 980 : na->arg = (Expr *) $3;
16848 : 980 : na->argnumber = -1; /* until determined */
16849 : 980 : na->location = @1;
16850 : 980 : $$ = (Node *) na;
16851 : : }
16852 : : ;
16853 : :
1818 tgl@sss.pgh.pa.us 16854 : 126 : func_arg_list_opt: func_arg_list { $$ = $1; }
1818 tgl@sss.pgh.pa.us 16855 :UBC 0 : | /*EMPTY*/ { $$ = NIL; }
16856 : : ;
16857 : :
6852 tgl@sss.pgh.pa.us 16858 :CBC 1150 : type_list: Typename { $$ = list_make1($1); }
16859 : 470 : | type_list ',' Typename { $$ = lappend($1, $3); }
16860 : : ;
16861 : :
16862 : : array_expr: '[' expr_list ']'
16863 : : {
137 alvherre@kurilemu.de 16864 : 3862 : $$ = makeAArrayExpr($2, @1, @3);
16865 : : }
16866 : : | '[' array_expr_list ']'
16867 : : {
16868 : 206 : $$ = makeAArrayExpr($2, @1, @3);
16869 : : }
16870 : : | '[' ']'
16871 : : {
16872 : 49 : $$ = makeAArrayExpr(NIL, @1, @2);
16873 : : }
16874 : : ;
16875 : :
6430 tgl@sss.pgh.pa.us 16876 : 206 : array_expr_list: array_expr { $$ = list_make1($1); }
16877 : 171 : | array_expr_list ',' array_expr { $$ = lappend($1, $3); }
16878 : : ;
16879 : :
16880 : :
16881 : : extract_list:
16882 : : extract_arg FROM a_expr
16883 : : {
6269 16884 : 691 : $$ = list_make2(makeStringConst($1, @1), $3);
16885 : : }
16886 : : ;
16887 : :
16888 : : /* Allow delimited string Sconst in extract_arg as an SQL extension.
16889 : : * - thomas 2001-04-12
16890 : : */
16891 : : extract_arg:
8533 bruce@momjian.us 16892 : 562 : IDENT { $$ = $1; }
16893 : 36 : | YEAR_P { $$ = "year"; }
16894 : 21 : | MONTH_P { $$ = "month"; }
16895 : 27 : | DAY_P { $$ = "day"; }
16896 : 15 : | HOUR_P { $$ = "hour"; }
16897 : 15 : | MINUTE_P { $$ = "minute"; }
16898 : 15 : | SECOND_P { $$ = "second"; }
6193 meskes@postgresql.or 16899 :UBC 0 : | Sconst { $$ = $1; }
16900 : : ;
16901 : :
16902 : : unicode_normal_form:
1818 tgl@sss.pgh.pa.us 16903 :CBC 12 : NFC { $$ = "NFC"; }
16904 : 9 : | NFD { $$ = "NFD"; }
16905 : 9 : | NFKC { $$ = "NFKC"; }
16906 : 9 : | NFKD { $$ = "NFKD"; }
16907 : : ;
16908 : :
16909 : : /* OVERLAY() arguments */
16910 : : overlay_list:
16911 : : a_expr PLACING a_expr FROM a_expr FOR a_expr
16912 : : {
16913 : : /* overlay(A PLACING B FROM C FOR D) is converted to overlay(A, B, C, D) */
1946 peter@eisentraut.org 16914 : 17 : $$ = list_make4($1, $3, $5, $7);
16915 : : }
16916 : : | a_expr PLACING a_expr FROM a_expr
16917 : : {
16918 : : /* overlay(A PLACING B FROM C) is converted to overlay(A, B, C) */
16919 : 24 : $$ = list_make3($1, $3, $5);
16920 : : }
16921 : : ;
16922 : :
16923 : : /* position_list uses b_expr not a_expr to avoid conflict with general IN */
16924 : : position_list:
7820 neilc@samurai.com 16925 : 200 : b_expr IN_P b_expr { $$ = list_make2($3, $1); }
16926 : : ;
16927 : :
16928 : : /*
16929 : : * SUBSTRING() arguments
16930 : : *
16931 : : * Note that SQL:1999 has both
16932 : : * text FROM int FOR int
16933 : : * and
16934 : : * text FROM pattern FOR escape
16935 : : *
16936 : : * In the parser we map them both to a call to the substring() function and
16937 : : * rely on type resolution to pick the right one.
16938 : : *
16939 : : * In SQL:2003, the second variant was changed to
16940 : : * text SIMILAR pattern ESCAPE escape
16941 : : * We could in theory map that to a different function internally, but
16942 : : * since we still support the SQL:1999 version, we don't. However,
16943 : : * ruleutils.c will reverse-list the call in the newer style.
16944 : : */
16945 : : substr_list:
16946 : : a_expr FROM a_expr FOR a_expr
16947 : : {
1946 peter@eisentraut.org 16948 : 61 : $$ = list_make3($1, $3, $5);
16949 : : }
16950 : : | a_expr FOR a_expr FROM a_expr
16951 : : {
16952 : : /* not legal per SQL, but might as well allow it */
1946 peter@eisentraut.org 16953 :UBC 0 : $$ = list_make3($1, $5, $3);
16954 : : }
16955 : : | a_expr FROM a_expr
16956 : : {
16957 : : /*
16958 : : * Because we aren't restricting data types here, this
16959 : : * syntax can end up resolving to textregexsubstr().
16960 : : * We've historically allowed that to happen, so continue
16961 : : * to accept it. However, ruleutils.c will reverse-list
16962 : : * such a call in regular function call syntax.
16963 : : */
1946 peter@eisentraut.org 16964 :CBC 185 : $$ = list_make2($1, $3);
16965 : : }
16966 : : | a_expr FOR a_expr
16967 : : {
16968 : : /* not legal per SQL */
16969 : :
16970 : : /*
16971 : : * Since there are no cases where this syntax allows
16972 : : * a textual FOR value, we forcibly cast the argument
16973 : : * to int4. The possible matches in pg_proc are
16974 : : * substring(text,int4) and substring(text,text),
16975 : : * and we don't want the parser to choose the latter,
16976 : : * which it is likely to do if the second argument
16977 : : * is unknown or doesn't have an implicit cast to int4.
16978 : : */
6269 tgl@sss.pgh.pa.us 16979 : 18 : $$ = list_make3($1, makeIntConst(1, -1),
16980 : : makeTypeCast($3,
16981 : : SystemTypeName("int4"), -1));
16982 : : }
16983 : : | a_expr SIMILAR a_expr ESCAPE a_expr
16984 : : {
1946 peter@eisentraut.org 16985 : 91 : $$ = list_make3($1, $3, $5);
16986 : : }
16987 : : ;
16988 : :
8533 bruce@momjian.us 16989 : 303 : trim_list: a_expr FROM expr_list { $$ = lappend($3, $1); }
16990 : 12 : | FROM expr_list { $$ = $2; }
16991 : 43 : | expr_list { $$ = $1; }
16992 : : ;
16993 : :
16994 : : /*
16995 : : * Define SQL-style CASE clause.
16996 : : * - Full specification
16997 : : * CASE WHEN a = b THEN c ... ELSE d END
16998 : : * - Implicit argument
16999 : : * CASE a WHEN b THEN c ... ELSE d END
17000 : : */
17001 : : case_expr: CASE case_arg when_clause_list case_default END_P
17002 : : {
1263 peter@eisentraut.org 17003 : 19622 : CaseExpr *c = makeNode(CaseExpr);
17004 : :
7894 tgl@sss.pgh.pa.us 17005 : 19622 : c->casetype = InvalidOid; /* not analyzed yet */
8355 17006 : 19622 : c->arg = (Expr *) $2;
9824 lockhart@fourpalms.o 17007 : 19622 : c->args = $3;
8355 tgl@sss.pgh.pa.us 17008 : 19622 : c->defresult = (Expr *) $4;
6269 17009 : 19622 : c->location = @1;
1263 peter@eisentraut.org 17010 : 19622 : $$ = (Node *) c;
17011 : : }
17012 : : ;
17013 : :
17014 : : when_clause_list:
17015 : : /* There must be at least one */
7820 neilc@samurai.com 17016 : 19622 : when_clause { $$ = list_make1($1); }
8532 bruce@momjian.us 17017 : 14525 : | when_clause_list when_clause { $$ = lappend($1, $2); }
17018 : : ;
17019 : :
17020 : : when_clause:
17021 : : WHEN a_expr THEN a_expr
17022 : : {
1263 peter@eisentraut.org 17023 : 34147 : CaseWhen *w = makeNode(CaseWhen);
17024 : :
8355 tgl@sss.pgh.pa.us 17025 : 34147 : w->expr = (Expr *) $2;
17026 : 34147 : w->result = (Expr *) $4;
6269 17027 : 34147 : w->location = @1;
1263 peter@eisentraut.org 17028 : 34147 : $$ = (Node *) w;
17029 : : }
17030 : : ;
17031 : :
17032 : : case_default:
8533 bruce@momjian.us 17033 : 14758 : ELSE a_expr { $$ = $2; }
17034 : 4864 : | /*EMPTY*/ { $$ = NULL; }
17035 : : ;
17036 : :
17037 : 3379 : case_arg: a_expr { $$ = $1; }
17038 : 16243 : | /*EMPTY*/ { $$ = NULL; }
17039 : : ;
17040 : :
17041 : : columnref: ColId
17042 : : {
5950 tgl@sss.pgh.pa.us 17043 : 388437 : $$ = makeColumnRef($1, NIL, @1, yyscanner);
17044 : : }
17045 : : | ColId indirection
17046 : : {
17047 : 539551 : $$ = makeColumnRef($1, $2, @1, yyscanner);
17048 : : }
17049 : : ;
17050 : :
17051 : : indirection_el:
17052 : : '.' attr_name
17053 : : {
7810 17054 : 731655 : $$ = (Node *) makeString($2);
17055 : : }
17056 : : | '.' '*'
17057 : : {
6267 17058 : 3491 : $$ = (Node *) makeNode(A_Star);
17059 : : }
17060 : : | '[' a_expr ']'
17061 : : {
7810 17062 : 6462 : A_Indices *ai = makeNode(A_Indices);
17063 : :
3597 17064 : 6462 : ai->is_slice = false;
7810 17065 : 6462 : ai->lidx = NULL;
17066 : 6462 : ai->uidx = $2;
17067 : 6462 : $$ = (Node *) ai;
17068 : : }
17069 : : | '[' opt_slice_bound ':' opt_slice_bound ']'
17070 : : {
17071 : 294 : A_Indices *ai = makeNode(A_Indices);
17072 : :
3597 17073 : 294 : ai->is_slice = true;
7810 17074 : 294 : ai->lidx = $2;
17075 : 294 : ai->uidx = $4;
17076 : 294 : $$ = (Node *) ai;
17077 : : }
17078 : : ;
17079 : :
17080 : : opt_slice_bound:
3597 17081 : 498 : a_expr { $$ = $1; }
17082 : 90 : | /*EMPTY*/ { $$ = NULL; }
17083 : : ;
17084 : :
17085 : : indirection:
7810 17086 : 731658 : indirection_el { $$ = list_make1($1); }
17087 : 1542 : | indirection indirection_el { $$ = lappend($1, $2); }
17088 : : ;
17089 : :
17090 : : opt_indirection:
17091 : 95438 : /*EMPTY*/ { $$ = NIL; }
17092 : 8702 : | opt_indirection indirection_el { $$ = lappend($1, $2); }
17093 : : ;
17094 : :
17095 : : opt_asymmetric: ASYMMETRIC
17096 : : | /*EMPTY*/
17097 : : ;
17098 : :
17099 : : /* SQL/JSON support */
17100 : : json_passing_clause_opt:
585 amitlan@postgresql.o 17101 : 168 : PASSING json_arguments { $$ = $2; }
17102 : 992 : | /*EMPTY*/ { $$ = NIL; }
17103 : : ;
17104 : :
17105 : : json_arguments:
17106 : 168 : json_argument { $$ = list_make1($1); }
17107 : 63 : | json_arguments ',' json_argument { $$ = lappend($1, $3); }
17108 : : ;
17109 : :
17110 : : json_argument:
17111 : : json_value_expr AS ColLabel
17112 : : {
17113 : 231 : JsonArgument *n = makeNode(JsonArgument);
17114 : :
17115 : 231 : n->val = (JsonValueExpr *) $1;
17116 : 231 : n->name = $3;
17117 : 231 : $$ = (Node *) n;
17118 : : }
17119 : : ;
17120 : :
17121 : : /* ARRAY is a noise word */
17122 : : json_wrapper_behavior:
17123 : 21 : WITHOUT WRAPPER { $$ = JSW_NONE; }
585 amitlan@postgresql.o 17124 :UBC 0 : | WITHOUT ARRAY WRAPPER { $$ = JSW_NONE; }
585 amitlan@postgresql.o 17125 :CBC 39 : | WITH WRAPPER { $$ = JSW_UNCONDITIONAL; }
17126 : 6 : | WITH ARRAY WRAPPER { $$ = JSW_UNCONDITIONAL; }
585 amitlan@postgresql.o 17127 :UBC 0 : | WITH CONDITIONAL ARRAY WRAPPER { $$ = JSW_CONDITIONAL; }
585 amitlan@postgresql.o 17128 :CBC 6 : | WITH UNCONDITIONAL ARRAY WRAPPER { $$ = JSW_UNCONDITIONAL; }
17129 : 18 : | WITH CONDITIONAL WRAPPER { $$ = JSW_CONDITIONAL; }
17130 : 3 : | WITH UNCONDITIONAL WRAPPER { $$ = JSW_UNCONDITIONAL; }
17131 : 818 : | /* empty */ { $$ = JSW_UNSPEC; }
17132 : : ;
17133 : :
17134 : : json_behavior:
17135 : : DEFAULT a_expr
17136 : 216 : { $$ = (Node *) makeJsonBehavior(JSON_BEHAVIOR_DEFAULT, $2, @1); }
17137 : : | json_behavior_type
17138 : 351 : { $$ = (Node *) makeJsonBehavior($1, NULL, @1); }
17139 : : ;
17140 : :
17141 : : json_behavior_type:
17142 : 246 : ERROR_P { $$ = JSON_BEHAVIOR_ERROR; }
17143 : 15 : | NULL_P { $$ = JSON_BEHAVIOR_NULL; }
17144 : 15 : | TRUE_P { $$ = JSON_BEHAVIOR_TRUE; }
17145 : 6 : | FALSE_P { $$ = JSON_BEHAVIOR_FALSE; }
17146 : 6 : | UNKNOWN { $$ = JSON_BEHAVIOR_UNKNOWN; }
17147 : 15 : | EMPTY_P ARRAY { $$ = JSON_BEHAVIOR_EMPTY_ARRAY; }
17148 : 36 : | EMPTY_P OBJECT_P { $$ = JSON_BEHAVIOR_EMPTY_OBJECT; }
17149 : : /* non-standard, for Oracle compatibility only */
17150 : 12 : | EMPTY_P { $$ = JSON_BEHAVIOR_EMPTY_ARRAY; }
17151 : : ;
17152 : :
17153 : : json_behavior_clause_opt:
17154 : : json_behavior ON EMPTY_P
17155 : 111 : { $$ = list_make2($1, NULL); }
17156 : : | json_behavior ON ERROR_P
17157 : 276 : { $$ = list_make2(NULL, $1); }
17158 : : | json_behavior ON EMPTY_P json_behavior ON ERROR_P
17159 : 51 : { $$ = list_make2($1, $4); }
17160 : : | /* EMPTY */
17161 : 785 : { $$ = list_make2(NULL, NULL); }
17162 : : ;
17163 : :
17164 : : json_on_error_clause_opt:
17165 : : json_behavior ON ERROR_P
17166 : 75 : { $$ = $1; }
17167 : : | /* EMPTY */
17168 : 344 : { $$ = NULL; }
17169 : : ;
17170 : :
17171 : : json_value_expr:
17172 : : a_expr json_format_clause_opt
17173 : : {
17174 : : /* formatted_expr will be set during parse-analysis. */
829 17175 : 2117 : $$ = (Node *) makeJsonValueExpr((Expr *) $1, NULL,
17176 : 2117 : castNode(JsonFormat, $2));
17177 : : }
17178 : : ;
17179 : :
17180 : : json_format_clause:
17181 : : FORMAT_LA JSON ENCODING name
17182 : : {
17183 : : int encoding;
17184 : :
686 alvherre@alvh.no-ip. 17185 [ + + ]: 49 : if (!pg_strcasecmp($4, "utf8"))
17186 : 31 : encoding = JS_ENC_UTF8;
17187 [ + + ]: 18 : else if (!pg_strcasecmp($4, "utf16"))
17188 : 6 : encoding = JS_ENC_UTF16;
17189 [ + + ]: 12 : else if (!pg_strcasecmp($4, "utf32"))
17190 : 6 : encoding = JS_ENC_UTF32;
17191 : : else
17192 [ + - ]: 6 : ereport(ERROR,
17193 : : (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
17194 : : errmsg("unrecognized JSON encoding: %s", $4),
17195 : : parser_errposition(@4)));
17196 : :
17197 : 43 : $$ = (Node *) makeJsonFormat(JS_FORMAT_JSON, encoding, @1);
17198 : : }
17199 : : | FORMAT_LA JSON
17200 : : {
17201 : 202 : $$ = (Node *) makeJsonFormat(JS_FORMAT_JSON, JS_ENC_DEFAULT, @1);
17202 : : }
17203 : : ;
17204 : :
17205 : : json_format_clause_opt:
17206 : : json_format_clause
17207 : : {
17208 : 191 : $$ = $1;
17209 : : }
17210 : : | /* EMPTY */
17211 : : {
943 17212 : 2695 : $$ = (Node *) makeJsonFormat(JS_FORMAT_DEFAULT, JS_ENC_DEFAULT, -1);
17213 : : }
17214 : : ;
17215 : :
17216 : : json_quotes_clause_opt:
585 amitlan@postgresql.o 17217 : 6 : KEEP QUOTES ON SCALAR STRING_P { $$ = JS_QUOTES_KEEP; }
17218 : 45 : | KEEP QUOTES { $$ = JS_QUOTES_KEEP; }
17219 : 6 : | OMIT QUOTES ON SCALAR STRING_P { $$ = JS_QUOTES_OMIT; }
17220 : 84 : | OMIT QUOTES { $$ = JS_QUOTES_OMIT; }
17221 : 770 : | /* EMPTY */ { $$ = JS_QUOTES_UNSPEC; }
17222 : : ;
17223 : :
17224 : : json_returning_clause_opt:
17225 : : RETURNING Typename json_format_clause_opt
17226 : : {
943 alvherre@alvh.no-ip. 17227 : 739 : JsonOutput *n = makeNode(JsonOutput);
17228 : :
17229 : 739 : n->typeName = $2;
17230 : 739 : n->returning = makeNode(JsonReturning);
17231 : 739 : n->returning->format = (JsonFormat *) $3;
17232 : 739 : $$ = (Node *) n;
17233 : : }
17234 : 639 : | /* EMPTY */ { $$ = NULL; }
17235 : : ;
17236 : :
17237 : : /*
17238 : : * We must assign the only-JSON production a precedence less than IDENT in
17239 : : * order to favor shifting over reduction when JSON is followed by VALUE_P,
17240 : : * OBJECT_P, or SCALAR. (ARRAY doesn't need that treatment, because it's a
17241 : : * fully reserved word.) Because json_predicate_type_constraint is always
17242 : : * followed by json_key_uniqueness_constraint_opt, we also need the only-JSON
17243 : : * production to have precedence less than WITH and WITHOUT. UNBOUNDED isn't
17244 : : * really related to this syntax, but it's a convenient choice because it
17245 : : * already has a precedence less than IDENT for other reasons.
17246 : : */
17247 : : json_predicate_type_constraint:
699 tgl@sss.pgh.pa.us 17248 : 97 : JSON %prec UNBOUNDED { $$ = JS_TYPE_ANY; }
941 alvherre@alvh.no-ip. 17249 : 13 : | JSON VALUE_P { $$ = JS_TYPE_ANY; }
17250 : 19 : | JSON ARRAY { $$ = JS_TYPE_ARRAY; }
17251 : 19 : | JSON OBJECT_P { $$ = JS_TYPE_OBJECT; }
17252 : 19 : | JSON SCALAR { $$ = JS_TYPE_SCALAR; }
17253 : : ;
17254 : :
17255 : : /*
17256 : : * KEYS is a noise word here. To avoid shift/reduce conflicts, assign the
17257 : : * KEYS-less productions a precedence less than IDENT (i.e., less than KEYS).
17258 : : * This prevents reducing them when the next token is KEYS.
17259 : : */
17260 : : json_key_uniqueness_constraint_opt:
17261 : 51 : WITH UNIQUE KEYS { $$ = true; }
699 tgl@sss.pgh.pa.us 17262 : 49 : | WITH UNIQUE %prec UNBOUNDED { $$ = true; }
937 alvherre@alvh.no-ip. 17263 : 20 : | WITHOUT UNIQUE KEYS { $$ = false; }
699 tgl@sss.pgh.pa.us 17264 : 7 : | WITHOUT UNIQUE %prec UNBOUNDED { $$ = false; }
17265 : 387 : | /* EMPTY */ %prec UNBOUNDED { $$ = false; }
17266 : : ;
17267 : :
17268 : : json_name_and_value_list:
17269 : : json_name_and_value
943 alvherre@alvh.no-ip. 17270 : 171 : { $$ = list_make1($1); }
17271 : : | json_name_and_value_list ',' json_name_and_value
17272 : 124 : { $$ = lappend($1, $3); }
17273 : : ;
17274 : :
17275 : : json_name_and_value:
17276 : : /* Supporting this syntax seems to require major surgery
17277 : : KEY c_expr VALUE_P json_value_expr
17278 : : { $$ = makeJsonKeyValue($2, $4); }
17279 : : |
17280 : : */
17281 : : c_expr VALUE_P json_value_expr
17282 : 12 : { $$ = makeJsonKeyValue($1, $3); }
17283 : : |
17284 : : a_expr ':' json_value_expr
17285 : 385 : { $$ = makeJsonKeyValue($1, $3); }
17286 : : ;
17287 : :
17288 : : /* empty means false for objects, true for arrays */
17289 : : json_object_constructor_null_clause_opt:
17290 : 15 : NULL_P ON NULL_P { $$ = false; }
17291 : 53 : | ABSENT ON NULL_P { $$ = true; }
17292 : 205 : | /* EMPTY */ { $$ = false; }
17293 : : ;
17294 : :
17295 : : json_array_constructor_null_clause_opt:
17296 : 30 : NULL_P ON NULL_P { $$ = false; }
17297 : 18 : | ABSENT ON NULL_P { $$ = true; }
17298 : 90 : | /* EMPTY */ { $$ = true; }
17299 : : ;
17300 : :
17301 : : json_value_expr_list:
17302 : 60 : json_value_expr { $$ = list_make1($1); }
17303 : 69 : | json_value_expr_list ',' json_value_expr { $$ = lappend($1, $3);}
17304 : : ;
17305 : :
17306 : : json_aggregate_func:
17307 : : JSON_OBJECTAGG '('
17308 : : json_name_and_value
17309 : : json_object_constructor_null_clause_opt
17310 : : json_key_uniqueness_constraint_opt
17311 : : json_returning_clause_opt
17312 : : ')'
17313 : : {
17314 : 102 : JsonObjectAgg *n = makeNode(JsonObjectAgg);
17315 : :
17316 : 102 : n->arg = (JsonKeyValue *) $3;
17317 : 102 : n->absent_on_null = $4;
17318 : 102 : n->unique = $5;
17319 : 102 : n->constructor = makeNode(JsonAggConstructor);
17320 : 102 : n->constructor->output = (JsonOutput *) $6;
17321 : 102 : n->constructor->agg_order = NULL;
17322 : 102 : n->constructor->location = @1;
17323 : 102 : $$ = (Node *) n;
17324 : : }
17325 : : | JSON_ARRAYAGG '('
17326 : : json_value_expr
17327 : : json_array_aggregate_order_by_clause_opt
17328 : : json_array_constructor_null_clause_opt
17329 : : json_returning_clause_opt
17330 : : ')'
17331 : : {
17332 : 78 : JsonArrayAgg *n = makeNode(JsonArrayAgg);
17333 : :
17334 : 78 : n->arg = (JsonValueExpr *) $3;
17335 : 78 : n->absent_on_null = $5;
17336 : 78 : n->constructor = makeNode(JsonAggConstructor);
17337 : 78 : n->constructor->agg_order = $4;
17338 : 78 : n->constructor->output = (JsonOutput *) $6;
17339 : 78 : n->constructor->location = @1;
17340 : 78 : $$ = (Node *) n;
17341 : : }
17342 : : ;
17343 : :
17344 : : json_array_aggregate_order_by_clause_opt:
17345 : 9 : ORDER BY sortby_list { $$ = $3; }
17346 : 69 : | /* EMPTY */ { $$ = NIL; }
17347 : : ;
17348 : :
17349 : : /*****************************************************************************
17350 : : *
17351 : : * target list for SELECT
17352 : : *
17353 : : *****************************************************************************/
17354 : :
4335 tgl@sss.pgh.pa.us 17355 : 237574 : opt_target_list: target_list { $$ = $1; }
17356 : 246 : | /* EMPTY */ { $$ = NIL; }
17357 : : ;
17358 : :
17359 : : target_list:
7820 neilc@samurai.com 17360 : 241166 : target_el { $$ = list_make1($1); }
8532 bruce@momjian.us 17361 : 353942 : | target_list ',' target_el { $$ = lappend($1, $3); }
17362 : : ;
17363 : :
17364 : : target_el: a_expr AS ColLabel
17365 : : {
10276 17366 : 118912 : $$ = makeNode(ResTarget);
17367 : 118912 : $$->name = $3;
8621 tgl@sss.pgh.pa.us 17368 : 118912 : $$->indirection = NIL;
1263 peter@eisentraut.org 17369 : 118912 : $$->val = (Node *) $1;
7158 tgl@sss.pgh.pa.us 17370 : 118912 : $$->location = @1;
17371 : : }
17372 : : | a_expr BareColLabel
17373 : : {
6464 17374 : 1783 : $$ = makeNode(ResTarget);
17375 : 1783 : $$->name = $2;
17376 : 1783 : $$->indirection = NIL;
1263 peter@eisentraut.org 17377 : 1783 : $$->val = (Node *) $1;
6464 tgl@sss.pgh.pa.us 17378 : 1783 : $$->location = @1;
17379 : : }
17380 : : | a_expr
17381 : : {
10276 bruce@momjian.us 17382 : 446184 : $$ = makeNode(ResTarget);
17383 : 446183 : $$->name = NULL;
8621 tgl@sss.pgh.pa.us 17384 : 446183 : $$->indirection = NIL;
1263 peter@eisentraut.org 17385 : 446183 : $$->val = (Node *) $1;
7158 tgl@sss.pgh.pa.us 17386 : 446183 : $$->location = @1;
17387 : : }
17388 : : | '*'
17389 : : {
1263 peter@eisentraut.org 17390 : 28229 : ColumnRef *n = makeNode(ColumnRef);
17391 : :
6267 tgl@sss.pgh.pa.us 17392 : 28229 : n->fields = list_make1(makeNode(A_Star));
7167 17393 : 28229 : n->location = @1;
17394 : :
10276 bruce@momjian.us 17395 : 28229 : $$ = makeNode(ResTarget);
17396 : 28229 : $$->name = NULL;
8621 tgl@sss.pgh.pa.us 17397 : 28229 : $$->indirection = NIL;
1263 peter@eisentraut.org 17398 : 28229 : $$->val = (Node *) n;
7158 tgl@sss.pgh.pa.us 17399 : 28229 : $$->location = @1;
17400 : : }
17401 : : ;
17402 : :
17403 : :
17404 : : /*****************************************************************************
17405 : : *
17406 : : * Names and constants
17407 : : *
17408 : : *****************************************************************************/
17409 : :
17410 : : qualified_name_list:
7820 neilc@samurai.com 17411 : 8873 : qualified_name { $$ = list_make1($1); }
8533 bruce@momjian.us 17412 : 227 : | qualified_name_list ',' qualified_name { $$ = lappend($1, $3); }
17413 : : ;
17414 : :
17415 : : /*
17416 : : * The production for a qualified relation name has to exactly match the
17417 : : * production for a qualified func_name, because in a FROM clause we cannot
17418 : : * tell which we are parsing until we see what comes after it ('(' for a
17419 : : * func_name, something else for a relation). Therefore we allow 'indirection'
17420 : : * which may contain subscripts, and reject that case in the C code.
17421 : : */
17422 : : qualified_name:
17423 : : ColId
17424 : : {
5432 rhaas@postgresql.org 17425 : 209727 : $$ = makeRangeVar(NULL, $1, @1);
17426 : : }
17427 : : | ColId indirection
17428 : : {
1461 akapila@postgresql.o 17429 : 128074 : $$ = makeRangeVarFromQualifiedName($1, $2, @1, yyscanner);
17430 : : }
17431 : : ;
17432 : :
17433 : : name_list: name
7820 neilc@samurai.com 17434 : 14207 : { $$ = list_make1(makeString($1)); }
17435 : : | name_list ',' name
8532 bruce@momjian.us 17436 : 30856 : { $$ = lappend($1, makeString($3)); }
17437 : : ;
17438 : :
17439 : :
8533 17440 : 87272 : name: ColId { $$ = $1; };
17441 : :
7734 tgl@sss.pgh.pa.us 17442 : 796514 : attr_name: ColLabel { $$ = $1; };
17443 : :
8533 bruce@momjian.us 17444 : 32 : file_name: Sconst { $$ = $1; };
17445 : :
17446 : : /*
17447 : : * The production for a qualified func_name has to exactly match the
17448 : : * production for a qualified columnref, because we cannot tell which we
17449 : : * are parsing until we see what comes after it ('(' or Sconst for a func_name,
17450 : : * anything else for a columnref). Therefore we allow 'indirection' which
17451 : : * may contain subscripts, and reject that case in the C code. (If we
17452 : : * ever implement SQL99-like methods, such syntax may actually become legal!)
17453 : : */
17454 : : func_name: type_function_name
7820 neilc@samurai.com 17455 : 148101 : { $$ = list_make1(makeString($1)); }
17456 : : | ColId indirection
17457 : : {
5950 tgl@sss.pgh.pa.us 17458 : 63994 : $$ = check_func_name(lcons(makeString($1), $2),
17459 : : yyscanner);
17460 : : }
17461 : : ;
17462 : :
17463 : :
17464 : : /*
17465 : : * Constants
17466 : : */
17467 : : AexprConst: Iconst
17468 : : {
6269 17469 : 193945 : $$ = makeIntConst($1, @1);
17470 : : }
17471 : : | FCONST
17472 : : {
17473 : 5835 : $$ = makeFloatConst($1, @1);
17474 : : }
17475 : : | Sconst
17476 : : {
17477 : 352684 : $$ = makeStringConst($1, @1);
17478 : : }
17479 : : | BCONST
17480 : : {
17481 : 376 : $$ = makeBitStringConst($1, @1);
17482 : : }
17483 : : | XCONST
17484 : : {
17485 : : /* This is a bit constant per SQL99:
17486 : : * Without Feature F511, "BIT data type",
17487 : : * a <general literal> shall not be a
17488 : : * <bit string literal> or a <hex string literal>.
17489 : : */
17490 : 1650 : $$ = makeBitStringConst($1, @1);
17491 : : }
17492 : : | func_name Sconst
17493 : : {
17494 : : /* generic type 'literal' syntax */
1263 peter@eisentraut.org 17495 : 4919 : TypeName *t = makeTypeNameFromNameList($1);
17496 : :
6390 alvherre@alvh.no-ip. 17497 : 4919 : t->location = @1;
6269 tgl@sss.pgh.pa.us 17498 : 4919 : $$ = makeStringConstCast($2, @2, t);
17499 : : }
17500 : : | func_name '(' func_arg_list opt_sort_clause ')' Sconst
17501 : : {
17502 : : /* generic syntax with a type modifier */
1263 peter@eisentraut.org 17503 :UBC 0 : TypeName *t = makeTypeNameFromNameList($1);
17504 : : ListCell *lc;
17505 : :
17506 : : /*
17507 : : * We must use func_arg_list and opt_sort_clause in the
17508 : : * production to avoid reduce/reduce conflicts, but we
17509 : : * don't actually wish to allow NamedArgExpr in this
17510 : : * context, nor ORDER BY.
17511 : : */
5863 tgl@sss.pgh.pa.us 17512 [ # # # # : 0 : foreach(lc, $3)
# # ]
17513 : : {
17514 : 0 : NamedArgExpr *arg = (NamedArgExpr *) lfirst(lc);
17515 : :
17516 [ # # ]: 0 : if (IsA(arg, NamedArgExpr))
17517 [ # # ]: 0 : ereport(ERROR,
17518 : : (errcode(ERRCODE_SYNTAX_ERROR),
17519 : : errmsg("type modifier cannot have parameter name"),
17520 : : parser_errposition(arg->location)));
17521 : : }
4326 17522 [ # # ]: 0 : if ($4 != NIL)
17523 [ # # ]: 0 : ereport(ERROR,
17524 : : (errcode(ERRCODE_SYNTAX_ERROR),
17525 : : errmsg("type modifier cannot have ORDER BY"),
17526 : : parser_errposition(@4)));
17527 : :
6390 alvherre@alvh.no-ip. 17528 : 0 : t->typmods = $3;
17529 : 0 : t->location = @1;
4326 tgl@sss.pgh.pa.us 17530 : 0 : $$ = makeStringConstCast($6, @6, t);
17531 : : }
17532 : : | ConstTypename Sconst
17533 : : {
6269 tgl@sss.pgh.pa.us 17534 :CBC 1586 : $$ = makeStringConstCast($2, @2, $1);
17535 : : }
17536 : : | ConstInterval Sconst opt_interval
17537 : : {
1263 peter@eisentraut.org 17538 : 1649 : TypeName *t = $1;
17539 : :
6255 tgl@sss.pgh.pa.us 17540 : 1649 : t->typmods = $3;
6269 17541 : 1649 : $$ = makeStringConstCast($2, @2, t);
17542 : : }
17543 : : | ConstInterval '(' Iconst ')' Sconst
17544 : : {
1263 peter@eisentraut.org 17545 : 6 : TypeName *t = $1;
17546 : :
4027 bruce@momjian.us 17547 : 6 : t->typmods = list_make2(makeIntConst(INTERVAL_FULL_RANGE, -1),
17548 : : makeIntConst($3, @3));
6269 tgl@sss.pgh.pa.us 17549 : 6 : $$ = makeStringConstCast($5, @5, t);
17550 : : }
17551 : : | TRUE_P
17552 : : {
2994 peter_e@gmx.net 17553 : 16099 : $$ = makeBoolAConst(true, @1);
17554 : : }
17555 : : | FALSE_P
17556 : : {
17557 : 18661 : $$ = makeBoolAConst(false, @1);
17558 : : }
17559 : : | NULL_P
17560 : : {
6269 tgl@sss.pgh.pa.us 17561 : 33708 : $$ = makeNullAConst(@1);
17562 : : }
17563 : : ;
17564 : :
8533 bruce@momjian.us 17565 : 208072 : Iconst: ICONST { $$ = $1; };
17566 : 388712 : Sconst: SCONST { $$ = $1; };
17567 : :
6193 meskes@postgresql.or 17568 : 8784 : SignedIconst: Iconst { $$ = $1; }
6193 meskes@postgresql.or 17569 :UBC 0 : | '+' Iconst { $$ = + $2; }
6193 meskes@postgresql.or 17570 :CBC 144 : | '-' Iconst { $$ = - $2; }
17571 : : ;
17572 : :
17573 : : /* Role specifications */
17574 : : RoleId: RoleSpec
17575 : : {
1263 peter@eisentraut.org 17576 : 967 : RoleSpec *spc = (RoleSpec *) $1;
17577 : :
3885 alvherre@alvh.no-ip. 17578 [ + + + + : 967 : switch (spc->roletype)
+ - ]
17579 : : {
17580 : 962 : case ROLESPEC_CSTRING:
17581 : 962 : $$ = spc->rolename;
17582 : 962 : break;
17583 : 2 : case ROLESPEC_PUBLIC:
17584 [ + - ]: 2 : ereport(ERROR,
17585 : : (errcode(ERRCODE_RESERVED_NAME),
17586 : : errmsg("role name \"%s\" is reserved",
17587 : : "public"),
17588 : : parser_errposition(@1)));
17589 : : break;
17590 : 1 : case ROLESPEC_SESSION_USER:
17591 [ + - ]: 1 : ereport(ERROR,
17592 : : (errcode(ERRCODE_RESERVED_NAME),
17593 : : errmsg("%s cannot be used as a role name here",
17594 : : "SESSION_USER"),
17595 : : parser_errposition(@1)));
17596 : : break;
17597 : 1 : case ROLESPEC_CURRENT_USER:
17598 [ + - ]: 1 : ereport(ERROR,
17599 : : (errcode(ERRCODE_RESERVED_NAME),
17600 : : errmsg("%s cannot be used as a role name here",
17601 : : "CURRENT_USER"),
17602 : : parser_errposition(@1)));
17603 : : break;
1866 peter@eisentraut.org 17604 : 1 : case ROLESPEC_CURRENT_ROLE:
17605 [ + - ]: 1 : ereport(ERROR,
17606 : : (errcode(ERRCODE_RESERVED_NAME),
17607 : : errmsg("%s cannot be used as a role name here",
17608 : : "CURRENT_ROLE"),
17609 : : parser_errposition(@1)));
17610 : : break;
17611 : : }
17612 : : }
17613 : : ;
17614 : :
17615 : : RoleSpec: NonReservedWord
17616 : : {
17617 : : /*
17618 : : * "public" and "none" are not keywords, but they must
17619 : : * be treated specially here.
17620 : : */
17621 : : RoleSpec *n;
17622 : :
1263 17623 [ + + ]: 16324 : if (strcmp($1, "public") == 0)
17624 : : {
17625 : 8883 : n = (RoleSpec *) makeRoleSpec(ROLESPEC_PUBLIC, @1);
17626 : 8883 : n->roletype = ROLESPEC_PUBLIC;
17627 : : }
17628 [ + + ]: 7441 : else if (strcmp($1, "none") == 0)
17629 : : {
17630 [ + - ]: 13 : ereport(ERROR,
17631 : : (errcode(ERRCODE_RESERVED_NAME),
17632 : : errmsg("role name \"%s\" is reserved",
17633 : : "none"),
17634 : : parser_errposition(@1)));
17635 : : }
17636 : : else
17637 : : {
17638 : 7428 : n = makeRoleSpec(ROLESPEC_CSTRING, @1);
17639 : 7428 : n->rolename = pstrdup($1);
17640 : : }
17641 : 16311 : $$ = n;
17642 : : }
17643 : : | CURRENT_ROLE
17644 : : {
17645 : 65 : $$ = makeRoleSpec(ROLESPEC_CURRENT_ROLE, @1);
17646 : : }
17647 : : | CURRENT_USER
17648 : : {
17649 : 114 : $$ = makeRoleSpec(ROLESPEC_CURRENT_USER, @1);
17650 : : }
17651 : : | SESSION_USER
17652 : : {
17653 : 18 : $$ = makeRoleSpec(ROLESPEC_SESSION_USER, @1);
17654 : : }
17655 : : ;
17656 : :
17657 : : role_list: RoleSpec
17658 : 1623 : { $$ = list_make1($1); }
17659 : : | role_list ',' RoleSpec
17660 : 135 : { $$ = lappend($1, $3); }
17661 : : ;
17662 : :
17663 : :
17664 : : /*****************************************************************************
17665 : : *
17666 : : * PL/pgSQL extensions
17667 : : *
17668 : : * You'd think a PL/pgSQL "expression" should be just an a_expr, but
17669 : : * historically it can include just about anything that can follow SELECT.
17670 : : * Therefore the returned struct is a SelectStmt.
17671 : : *****************************************************************************/
17672 : :
17673 : : PLpgSQL_Expr: opt_distinct_clause opt_target_list
17674 : : from_clause where_clause
17675 : : group_clause having_clause window_clause
17676 : : opt_sort_clause opt_select_limit opt_for_locking_clause
17677 : : {
1757 tgl@sss.pgh.pa.us 17678 : 20812 : SelectStmt *n = makeNode(SelectStmt);
17679 : :
1739 17680 : 20812 : n->distinctClause = $1;
17681 : 20812 : n->targetList = $2;
17682 : 20812 : n->fromClause = $3;
17683 : 20812 : n->whereClause = $4;
1684 tomas.vondra@postgre 17684 : 20812 : n->groupClause = ($5)->list;
17685 : 20812 : n->groupDistinct = ($5)->distinct;
28 tgl@sss.pgh.pa.us 17686 :GNC 20812 : n->groupByAll = ($5)->all;
1739 tgl@sss.pgh.pa.us 17687 :CBC 20812 : n->havingClause = $6;
17688 : 20812 : n->windowClause = $7;
17689 : 20812 : n->sortClause = $8;
17690 [ + + ]: 20812 : if ($9)
17691 : : {
17692 : 2 : n->limitOffset = $9->limitOffset;
17693 : 2 : n->limitCount = $9->limitCount;
1757 17694 [ + - ]: 2 : if (!n->sortClause &&
1739 17695 [ - + ]: 2 : $9->limitOption == LIMIT_OPTION_WITH_TIES)
1757 tgl@sss.pgh.pa.us 17696 [ # # ]:UBC 0 : ereport(ERROR,
17697 : : (errcode(ERRCODE_SYNTAX_ERROR),
17698 : : errmsg("WITH TIES cannot be specified without ORDER BY clause"),
17699 : : parser_errposition($9->optionLoc)));
1739 tgl@sss.pgh.pa.us 17700 :CBC 2 : n->limitOption = $9->limitOption;
17701 : : }
17702 : 20812 : n->lockingClause = $10;
1757 17703 : 20812 : $$ = (Node *) n;
17704 : : }
17705 : : ;
17706 : :
17707 : : /*
17708 : : * PL/pgSQL Assignment statement: name opt_indirection := PLpgSQL_Expr
17709 : : */
17710 : :
17711 : : PLAssignStmt: plassign_target opt_indirection plassign_equals PLpgSQL_Expr
17712 : : {
17713 : 3639 : PLAssignStmt *n = makeNode(PLAssignStmt);
17714 : :
17715 : 3639 : n->name = $1;
17716 : 3639 : n->indirection = check_indirection($2, yyscanner);
17717 : : /* nnames will be filled by calling production */
17718 : 3589 : n->val = (SelectStmt *) $4;
17719 : 3589 : n->location = @1;
17720 : 3589 : $$ = (Node *) n;
17721 : : }
17722 : : ;
17723 : :
17724 : 3627 : plassign_target: ColId { $$ = $1; }
17725 : 12 : | PARAM { $$ = psprintf("$%d", $1); }
17726 : : ;
17727 : :
17728 : : plassign_equals: COLON_EQUALS
17729 : : | '='
17730 : : ;
17731 : :
17732 : :
17733 : : /*
17734 : : * Name classification hierarchy.
17735 : : *
17736 : : * IDENT is the lexeme returned by the lexer for identifiers that match
17737 : : * no known keyword. In most cases, we can accept certain keywords as
17738 : : * names, not only IDENTs. We prefer to accept as many such keywords
17739 : : * as possible to minimize the impact of "reserved words" on programmers.
17740 : : * So, we divide names into several possible classes. The classification
17741 : : * is chosen in part to make keywords acceptable as names wherever possible.
17742 : : */
17743 : :
17744 : : /* Column identifier --- names that can be column, table, etc names.
17745 : : */
8533 bruce@momjian.us 17746 : 1713520 : ColId: IDENT { $$ = $1; }
17747 : 29058 : | unreserved_keyword { $$ = pstrdup($1); }
17748 : 3076 : | col_name_keyword { $$ = pstrdup($1); }
17749 : : ;
17750 : :
17751 : : /* Type/function identifier --- names that can be type or function names.
17752 : : */
6876 tgl@sss.pgh.pa.us 17753 : 359256 : type_function_name: IDENT { $$ = $1; }
8533 bruce@momjian.us 17754 : 37694 : | unreserved_keyword { $$ = pstrdup($1); }
6876 tgl@sss.pgh.pa.us 17755 : 33 : | type_func_name_keyword { $$ = pstrdup($1); }
17756 : : ;
17757 : :
17758 : : /* Any not-fully-reserved word --- these names can be, eg, role names.
17759 : : */
4530 17760 : 41650 : NonReservedWord: IDENT { $$ = $1; }
17761 : 15347 : | unreserved_keyword { $$ = pstrdup($1); }
17762 : 89 : | col_name_keyword { $$ = pstrdup($1); }
17763 : 2711 : | type_func_name_keyword { $$ = pstrdup($1); }
17764 : : ;
17765 : :
17766 : : /* Column label --- allowed labels in "AS" clauses.
17767 : : * This presently includes *all* Postgres keywords.
17768 : : */
8533 bruce@momjian.us 17769 : 907410 : ColLabel: IDENT { $$ = $1; }
17770 : 19937 : | unreserved_keyword { $$ = pstrdup($1); }
17771 : 142 : | col_name_keyword { $$ = pstrdup($1); }
6876 tgl@sss.pgh.pa.us 17772 : 886 : | type_func_name_keyword { $$ = pstrdup($1); }
8533 bruce@momjian.us 17773 : 3770 : | reserved_keyword { $$ = pstrdup($1); }
17774 : : ;
17775 : :
17776 : : /* Bare column label --- names that can be column labels without writing "AS".
17777 : : * This classification is orthogonal to the other keyword categories.
17778 : : */
1865 tgl@sss.pgh.pa.us 17779 : 1774 : BareColLabel: IDENT { $$ = $1; }
17780 : 9 : | bare_label_keyword { $$ = pstrdup($1); }
17781 : : ;
17782 : :
17783 : :
17784 : : /*
17785 : : * Keyword category lists. Generally, every keyword present in
17786 : : * the Postgres grammar should appear in exactly one of these lists.
17787 : : *
17788 : : * Put a new keyword into the first list that it can go into without causing
17789 : : * shift or reduce conflicts. The earlier lists define "less reserved"
17790 : : * categories of keywords.
17791 : : *
17792 : : * Make sure that each keyword's category in kwlist.h matches where
17793 : : * it is listed here. (Someday we may be able to generate these lists and
17794 : : * kwlist.h's table from one source of truth.)
17795 : : */
17796 : :
17797 : : /* "Unreserved" keywords --- available for use as any kind of name.
17798 : : */
17799 : : unreserved_keyword:
17800 : : ABORT_P
17801 : : | ABSENT
17802 : : | ABSOLUTE_P
17803 : : | ACCESS
17804 : : | ACTION
17805 : : | ADD_P
17806 : : | ADMIN
17807 : : | AFTER
17808 : : | AGGREGATE
17809 : : | ALSO
17810 : : | ALTER
17811 : : | ALWAYS
17812 : : | ASENSITIVE
17813 : : | ASSERTION
17814 : : | ASSIGNMENT
17815 : : | AT
17816 : : | ATOMIC
17817 : : | ATTACH
17818 : : | ATTRIBUTE
17819 : : | BACKWARD
17820 : : | BEFORE
17821 : : | BEGIN_P
17822 : : | BREADTH
17823 : : | BY
17824 : : | CACHE
17825 : : | CALL
17826 : : | CALLED
17827 : : | CASCADE
17828 : : | CASCADED
17829 : : | CATALOG_P
17830 : : | CHAIN
17831 : : | CHARACTERISTICS
17832 : : | CHECKPOINT
17833 : : | CLASS
17834 : : | CLOSE
17835 : : | CLUSTER
17836 : : | COLUMNS
17837 : : | COMMENT
17838 : : | COMMENTS
17839 : : | COMMIT
17840 : : | COMMITTED
17841 : : | COMPRESSION
17842 : : | CONDITIONAL
17843 : : | CONFIGURATION
17844 : : | CONFLICT
17845 : : | CONNECTION
17846 : : | CONSTRAINTS
17847 : : | CONTENT_P
17848 : : | CONTINUE_P
17849 : : | CONVERSION_P
17850 : : | COPY
17851 : : | COST
17852 : : | CSV
17853 : : | CUBE
17854 : : | CURRENT_P
17855 : : | CURSOR
17856 : : | CYCLE
17857 : : | DATA_P
17858 : : | DATABASE
17859 : : | DAY_P
17860 : : | DEALLOCATE
17861 : : | DECLARE
17862 : : | DEFAULTS
17863 : : | DEFERRED
17864 : : | DEFINER
17865 : : | DELETE_P
17866 : : | DELIMITER
17867 : : | DELIMITERS
17868 : : | DEPENDS
17869 : : | DEPTH
17870 : : | DETACH
17871 : : | DICTIONARY
17872 : : | DISABLE_P
17873 : : | DISCARD
17874 : : | DOCUMENT_P
17875 : : | DOMAIN_P
17876 : : | DOUBLE_P
17877 : : | DROP
17878 : : | EACH
17879 : : | EMPTY_P
17880 : : | ENABLE_P
17881 : : | ENCODING
17882 : : | ENCRYPTED
17883 : : | ENFORCED
17884 : : | ENUM_P
17885 : : | ERROR_P
17886 : : | ESCAPE
17887 : : | EVENT
17888 : : | EXCLUDE
17889 : : | EXCLUDING
17890 : : | EXCLUSIVE
17891 : : | EXECUTE
17892 : : | EXPLAIN
17893 : : | EXPRESSION
17894 : : | EXTENSION
17895 : : | EXTERNAL
17896 : : | FAMILY
17897 : : | FILTER
17898 : : | FINALIZE
17899 : : | FIRST_P
17900 : : | FOLLOWING
17901 : : | FORCE
17902 : : | FORMAT
17903 : : | FORWARD
17904 : : | FUNCTION
17905 : : | FUNCTIONS
17906 : : | GENERATED
17907 : : | GLOBAL
17908 : : | GRANTED
17909 : : | GROUPS
17910 : : | HANDLER
17911 : : | HEADER_P
17912 : : | HOLD
17913 : : | HOUR_P
17914 : : | IDENTITY_P
17915 : : | IF_P
17916 : : | IGNORE_P
17917 : : | IMMEDIATE
17918 : : | IMMUTABLE
17919 : : | IMPLICIT_P
17920 : : | IMPORT_P
17921 : : | INCLUDE
17922 : : | INCLUDING
17923 : : | INCREMENT
17924 : : | INDENT
17925 : : | INDEX
17926 : : | INDEXES
17927 : : | INHERIT
17928 : : | INHERITS
17929 : : | INLINE_P
17930 : : | INPUT_P
17931 : : | INSENSITIVE
17932 : : | INSERT
17933 : : | INSTEAD
17934 : : | INVOKER
17935 : : | ISOLATION
17936 : : | KEEP
17937 : : | KEY
17938 : : | KEYS
17939 : : | LABEL
17940 : : | LANGUAGE
17941 : : | LARGE_P
17942 : : | LAST_P
17943 : : | LEAKPROOF
17944 : : | LEVEL
17945 : : | LISTEN
17946 : : | LOAD
17947 : : | LOCAL
17948 : : | LOCATION
17949 : : | LOCK_P
17950 : : | LOCKED
17951 : : | LOGGED
17952 : : | MAPPING
17953 : : | MATCH
17954 : : | MATCHED
17955 : : | MATERIALIZED
17956 : : | MAXVALUE
17957 : : | MERGE
17958 : : | METHOD
17959 : : | MINUTE_P
17960 : : | MINVALUE
17961 : : | MODE
17962 : : | MONTH_P
17963 : : | MOVE
17964 : : | NAME_P
17965 : : | NAMES
17966 : : | NESTED
17967 : : | NEW
17968 : : | NEXT
17969 : : | NFC
17970 : : | NFD
17971 : : | NFKC
17972 : : | NFKD
17973 : : | NO
17974 : : | NORMALIZED
17975 : : | NOTHING
17976 : : | NOTIFY
17977 : : | NOWAIT
17978 : : | NULLS_P
17979 : : | OBJECT_P
17980 : : | OBJECTS_P
17981 : : | OF
17982 : : | OFF
17983 : : | OIDS
17984 : : | OLD
17985 : : | OMIT
17986 : : | OPERATOR
17987 : : | OPTION
17988 : : | OPTIONS
17989 : : | ORDINALITY
17990 : : | OTHERS
17991 : : | OVER
17992 : : | OVERRIDING
17993 : : | OWNED
17994 : : | OWNER
17995 : : | PARALLEL
17996 : : | PARAMETER
17997 : : | PARSER
17998 : : | PARTIAL
17999 : : | PARTITION
18000 : : | PASSING
18001 : : | PASSWORD
18002 : : | PATH
18003 : : | PERIOD
18004 : : | PLAN
18005 : : | PLANS
18006 : : | POLICY
18007 : : | PRECEDING
18008 : : | PREPARE
18009 : : | PREPARED
18010 : : | PRESERVE
18011 : : | PRIOR
18012 : : | PRIVILEGES
18013 : : | PROCEDURAL
18014 : : | PROCEDURE
18015 : : | PROCEDURES
18016 : : | PROGRAM
18017 : : | PUBLICATION
18018 : : | QUOTE
18019 : : | QUOTES
18020 : : | RANGE
18021 : : | READ
18022 : : | REASSIGN
18023 : : | RECURSIVE
18024 : : | REF_P
18025 : : | REFERENCING
18026 : : | REFRESH
18027 : : | REINDEX
18028 : : | RELATIVE_P
18029 : : | RELEASE
18030 : : | RENAME
18031 : : | REPEATABLE
18032 : : | REPLACE
18033 : : | REPLICA
18034 : : | RESET
18035 : : | RESPECT_P
18036 : : | RESTART
18037 : : | RESTRICT
18038 : : | RETURN
18039 : : | RETURNS
18040 : : | REVOKE
18041 : : | ROLE
18042 : : | ROLLBACK
18043 : : | ROLLUP
18044 : : | ROUTINE
18045 : : | ROUTINES
18046 : : | ROWS
18047 : : | RULE
18048 : : | SAVEPOINT
18049 : : | SCALAR
18050 : : | SCHEMA
18051 : : | SCHEMAS
18052 : : | SCROLL
18053 : : | SEARCH
18054 : : | SECOND_P
18055 : : | SECURITY
18056 : : | SEQUENCE
18057 : : | SEQUENCES
18058 : : | SERIALIZABLE
18059 : : | SERVER
18060 : : | SESSION
18061 : : | SET
18062 : : | SETS
18063 : : | SHARE
18064 : : | SHOW
18065 : : | SIMPLE
18066 : : | SKIP
18067 : : | SNAPSHOT
18068 : : | SOURCE
18069 : : | SQL_P
18070 : : | STABLE
18071 : : | STANDALONE_P
18072 : : | START
18073 : : | STATEMENT
18074 : : | STATISTICS
18075 : : | STDIN
18076 : : | STDOUT
18077 : : | STORAGE
18078 : : | STORED
18079 : : | STRICT_P
18080 : : | STRING_P
18081 : : | STRIP_P
18082 : : | SUBSCRIPTION
18083 : : | SUPPORT
18084 : : | SYSID
18085 : : | SYSTEM_P
18086 : : | TABLES
18087 : : | TABLESPACE
18088 : : | TARGET
18089 : : | TEMP
18090 : : | TEMPLATE
18091 : : | TEMPORARY
18092 : : | TEXT_P
18093 : : | TIES
18094 : : | TRANSACTION
18095 : : | TRANSFORM
18096 : : | TRIGGER
18097 : : | TRUNCATE
18098 : : | TRUSTED
18099 : : | TYPE_P
18100 : : | TYPES_P
18101 : : | UESCAPE
18102 : : | UNBOUNDED
18103 : : | UNCOMMITTED
18104 : : | UNCONDITIONAL
18105 : : | UNENCRYPTED
18106 : : | UNKNOWN
18107 : : | UNLISTEN
18108 : : | UNLOGGED
18109 : : | UNTIL
18110 : : | UPDATE
18111 : : | VACUUM
18112 : : | VALID
18113 : : | VALIDATE
18114 : : | VALIDATOR
18115 : : | VALUE_P
18116 : : | VARYING
18117 : : | VERSION_P
18118 : : | VIEW
18119 : : | VIEWS
18120 : : | VIRTUAL
18121 : : | VOLATILE
18122 : : | WHITESPACE_P
18123 : : | WITHIN
18124 : : | WITHOUT
18125 : : | WORK
18126 : : | WRAPPER
18127 : : | WRITE
18128 : : | XML_P
18129 : : | YEAR_P
18130 : : | YES_P
18131 : : | ZONE
18132 : : ;
18133 : :
18134 : : /* Column identifier --- keywords that can be column, table, etc names.
18135 : : *
18136 : : * Many of these keywords will in fact be recognized as type or function
18137 : : * names too; but they have special productions for the purpose, and so
18138 : : * can't be treated as "generic" type or function names.
18139 : : *
18140 : : * The type names appearing here are not usable as function names
18141 : : * because they can be followed by '(' in typename productions, which
18142 : : * looks too much like a function call for an LR(1) parser.
18143 : : */
18144 : : col_name_keyword:
18145 : : BETWEEN
18146 : : | BIGINT
18147 : : | BIT
18148 : : | BOOLEAN_P
18149 : : | CHAR_P
18150 : : | CHARACTER
18151 : : | COALESCE
18152 : : | DEC
18153 : : | DECIMAL_P
18154 : : | EXISTS
18155 : : | EXTRACT
18156 : : | FLOAT_P
18157 : : | GREATEST
18158 : : | GROUPING
18159 : : | INOUT
18160 : : | INT_P
18161 : : | INTEGER
18162 : : | INTERVAL
18163 : : | JSON
18164 : : | JSON_ARRAY
18165 : : | JSON_ARRAYAGG
18166 : : | JSON_EXISTS
18167 : : | JSON_OBJECT
18168 : : | JSON_OBJECTAGG
18169 : : | JSON_QUERY
18170 : : | JSON_SCALAR
18171 : : | JSON_SERIALIZE
18172 : : | JSON_TABLE
18173 : : | JSON_VALUE
18174 : : | LEAST
18175 : : | MERGE_ACTION
18176 : : | NATIONAL
18177 : : | NCHAR
18178 : : | NONE
18179 : : | NORMALIZE
18180 : : | NULLIF
18181 : : | NUMERIC
18182 : : | OUT_P
18183 : : | OVERLAY
18184 : : | POSITION
18185 : : | PRECISION
18186 : : | REAL
18187 : : | ROW
18188 : : | SETOF
18189 : : | SMALLINT
18190 : : | SUBSTRING
18191 : : | TIME
18192 : : | TIMESTAMP
18193 : : | TREAT
18194 : : | TRIM
18195 : : | VALUES
18196 : : | VARCHAR
18197 : : | XMLATTRIBUTES
18198 : : | XMLCONCAT
18199 : : | XMLELEMENT
18200 : : | XMLEXISTS
18201 : : | XMLFOREST
18202 : : | XMLNAMESPACES
18203 : : | XMLPARSE
18204 : : | XMLPI
18205 : : | XMLROOT
18206 : : | XMLSERIALIZE
18207 : : | XMLTABLE
18208 : : ;
18209 : :
18210 : : /* Type/function identifier --- keywords that can be type or function names.
18211 : : *
18212 : : * Most of these are keywords that are used as operators in expressions;
18213 : : * in general such keywords can't be column names because they would be
18214 : : * ambiguous with variables, but they are unambiguous as function identifiers.
18215 : : *
18216 : : * Do not include POSITION, SUBSTRING, etc here since they have explicit
18217 : : * productions in a_expr to support the goofy SQL9x argument syntax.
18218 : : * - thomas 2000-11-28
18219 : : */
18220 : : type_func_name_keyword:
18221 : : AUTHORIZATION
18222 : : | BINARY
18223 : : | COLLATION
18224 : : | CONCURRENTLY
18225 : : | CROSS
18226 : : | CURRENT_SCHEMA
18227 : : | FREEZE
18228 : : | FULL
18229 : : | ILIKE
18230 : : | INNER_P
18231 : : | IS
18232 : : | ISNULL
18233 : : | JOIN
18234 : : | LEFT
18235 : : | LIKE
18236 : : | NATURAL
18237 : : | NOTNULL
18238 : : | OUTER_P
18239 : : | OVERLAPS
18240 : : | RIGHT
18241 : : | SIMILAR
18242 : : | TABLESAMPLE
18243 : : | VERBOSE
18244 : : ;
18245 : :
18246 : : /* Reserved keyword --- these keywords are usable only as a ColLabel.
18247 : : *
18248 : : * Keywords appear here if they could not be distinguished from variable,
18249 : : * type, or function names in some contexts. Don't put things here unless
18250 : : * forced to.
18251 : : */
18252 : : reserved_keyword:
18253 : : ALL
18254 : : | ANALYSE
18255 : : | ANALYZE
18256 : : | AND
18257 : : | ANY
18258 : : | ARRAY
18259 : : | AS
18260 : : | ASC
18261 : : | ASYMMETRIC
18262 : : | BOTH
18263 : : | CASE
18264 : : | CAST
18265 : : | CHECK
18266 : : | COLLATE
18267 : : | COLUMN
18268 : : | CONSTRAINT
18269 : : | CREATE
18270 : : | CURRENT_CATALOG
18271 : : | CURRENT_DATE
18272 : : | CURRENT_ROLE
18273 : : | CURRENT_TIME
18274 : : | CURRENT_TIMESTAMP
18275 : : | CURRENT_USER
18276 : : | DEFAULT
18277 : : | DEFERRABLE
18278 : : | DESC
18279 : : | DISTINCT
18280 : : | DO
18281 : : | ELSE
18282 : : | END_P
18283 : : | EXCEPT
18284 : : | FALSE_P
18285 : : | FETCH
18286 : : | FOR
18287 : : | FOREIGN
18288 : : | FROM
18289 : : | GRANT
18290 : : | GROUP_P
18291 : : | HAVING
18292 : : | IN_P
18293 : : | INITIALLY
18294 : : | INTERSECT
18295 : : | INTO
18296 : : | LATERAL_P
18297 : : | LEADING
18298 : : | LIMIT
18299 : : | LOCALTIME
18300 : : | LOCALTIMESTAMP
18301 : : | NOT
18302 : : | NULL_P
18303 : : | OFFSET
18304 : : | ON
18305 : : | ONLY
18306 : : | OR
18307 : : | ORDER
18308 : : | PLACING
18309 : : | PRIMARY
18310 : : | REFERENCES
18311 : : | RETURNING
18312 : : | SELECT
18313 : : | SESSION_USER
18314 : : | SOME
18315 : : | SYMMETRIC
18316 : : | SYSTEM_USER
18317 : : | TABLE
18318 : : | THEN
18319 : : | TO
18320 : : | TRAILING
18321 : : | TRUE_P
18322 : : | UNION
18323 : : | UNIQUE
18324 : : | USER
18325 : : | USING
18326 : : | VARIADIC
18327 : : | WHEN
18328 : : | WHERE
18329 : : | WINDOW
18330 : : | WITH
18331 : : ;
18332 : :
18333 : : /*
18334 : : * While all keywords can be used as column labels when preceded by AS,
18335 : : * not all of them can be used as a "bare" column label without AS.
18336 : : * Those that can be used as a bare label must be listed here,
18337 : : * in addition to appearing in one of the category lists above.
18338 : : *
18339 : : * Always add a new keyword to this list if possible. Mark it BARE_LABEL
18340 : : * in kwlist.h if it is included here, or AS_LABEL if it is not.
18341 : : */
18342 : : bare_label_keyword:
18343 : : ABORT_P
18344 : : | ABSENT
18345 : : | ABSOLUTE_P
18346 : : | ACCESS
18347 : : | ACTION
18348 : : | ADD_P
18349 : : | ADMIN
18350 : : | AFTER
18351 : : | AGGREGATE
18352 : : | ALL
18353 : : | ALSO
18354 : : | ALTER
18355 : : | ALWAYS
18356 : : | ANALYSE
18357 : : | ANALYZE
18358 : : | AND
18359 : : | ANY
18360 : : | ASC
18361 : : | ASENSITIVE
18362 : : | ASSERTION
18363 : : | ASSIGNMENT
18364 : : | ASYMMETRIC
18365 : : | AT
18366 : : | ATOMIC
18367 : : | ATTACH
18368 : : | ATTRIBUTE
18369 : : | AUTHORIZATION
18370 : : | BACKWARD
18371 : : | BEFORE
18372 : : | BEGIN_P
18373 : : | BETWEEN
18374 : : | BIGINT
18375 : : | BINARY
18376 : : | BIT
18377 : : | BOOLEAN_P
18378 : : | BOTH
18379 : : | BREADTH
18380 : : | BY
18381 : : | CACHE
18382 : : | CALL
18383 : : | CALLED
18384 : : | CASCADE
18385 : : | CASCADED
18386 : : | CASE
18387 : : | CAST
18388 : : | CATALOG_P
18389 : : | CHAIN
18390 : : | CHARACTERISTICS
18391 : : | CHECK
18392 : : | CHECKPOINT
18393 : : | CLASS
18394 : : | CLOSE
18395 : : | CLUSTER
18396 : : | COALESCE
18397 : : | COLLATE
18398 : : | COLLATION
18399 : : | COLUMN
18400 : : | COLUMNS
18401 : : | COMMENT
18402 : : | COMMENTS
18403 : : | COMMIT
18404 : : | COMMITTED
18405 : : | COMPRESSION
18406 : : | CONCURRENTLY
18407 : : | CONDITIONAL
18408 : : | CONFIGURATION
18409 : : | CONFLICT
18410 : : | CONNECTION
18411 : : | CONSTRAINT
18412 : : | CONSTRAINTS
18413 : : | CONTENT_P
18414 : : | CONTINUE_P
18415 : : | CONVERSION_P
18416 : : | COPY
18417 : : | COST
18418 : : | CROSS
18419 : : | CSV
18420 : : | CUBE
18421 : : | CURRENT_P
18422 : : | CURRENT_CATALOG
18423 : : | CURRENT_DATE
18424 : : | CURRENT_ROLE
18425 : : | CURRENT_SCHEMA
18426 : : | CURRENT_TIME
18427 : : | CURRENT_TIMESTAMP
18428 : : | CURRENT_USER
18429 : : | CURSOR
18430 : : | CYCLE
18431 : : | DATA_P
18432 : : | DATABASE
18433 : : | DEALLOCATE
18434 : : | DEC
18435 : : | DECIMAL_P
18436 : : | DECLARE
18437 : : | DEFAULT
18438 : : | DEFAULTS
18439 : : | DEFERRABLE
18440 : : | DEFERRED
18441 : : | DEFINER
18442 : : | DELETE_P
18443 : : | DELIMITER
18444 : : | DELIMITERS
18445 : : | DEPENDS
18446 : : | DEPTH
18447 : : | DESC
18448 : : | DETACH
18449 : : | DICTIONARY
18450 : : | DISABLE_P
18451 : : | DISCARD
18452 : : | DISTINCT
18453 : : | DO
18454 : : | DOCUMENT_P
18455 : : | DOMAIN_P
18456 : : | DOUBLE_P
18457 : : | DROP
18458 : : | EACH
18459 : : | ELSE
18460 : : | EMPTY_P
18461 : : | ENABLE_P
18462 : : | ENCODING
18463 : : | ENCRYPTED
18464 : : | END_P
18465 : : | ENFORCED
18466 : : | ENUM_P
18467 : : | ERROR_P
18468 : : | ESCAPE
18469 : : | EVENT
18470 : : | EXCLUDE
18471 : : | EXCLUDING
18472 : : | EXCLUSIVE
18473 : : | EXECUTE
18474 : : | EXISTS
18475 : : | EXPLAIN
18476 : : | EXPRESSION
18477 : : | EXTENSION
18478 : : | EXTERNAL
18479 : : | EXTRACT
18480 : : | FALSE_P
18481 : : | FAMILY
18482 : : | FINALIZE
18483 : : | FIRST_P
18484 : : | FLOAT_P
18485 : : | FOLLOWING
18486 : : | FORCE
18487 : : | FOREIGN
18488 : : | FORMAT
18489 : : | FORWARD
18490 : : | FREEZE
18491 : : | FULL
18492 : : | FUNCTION
18493 : : | FUNCTIONS
18494 : : | GENERATED
18495 : : | GLOBAL
18496 : : | GRANTED
18497 : : | GREATEST
18498 : : | GROUPING
18499 : : | GROUPS
18500 : : | HANDLER
18501 : : | HEADER_P
18502 : : | HOLD
18503 : : | IDENTITY_P
18504 : : | IF_P
18505 : : | ILIKE
18506 : : | IMMEDIATE
18507 : : | IMMUTABLE
18508 : : | IMPLICIT_P
18509 : : | IMPORT_P
18510 : : | IN_P
18511 : : | INCLUDE
18512 : : | INCLUDING
18513 : : | INCREMENT
18514 : : | INDENT
18515 : : | INDEX
18516 : : | INDEXES
18517 : : | INHERIT
18518 : : | INHERITS
18519 : : | INITIALLY
18520 : : | INLINE_P
18521 : : | INNER_P
18522 : : | INOUT
18523 : : | INPUT_P
18524 : : | INSENSITIVE
18525 : : | INSERT
18526 : : | INSTEAD
18527 : : | INT_P
18528 : : | INTEGER
18529 : : | INTERVAL
18530 : : | INVOKER
18531 : : | IS
18532 : : | ISOLATION
18533 : : | JOIN
18534 : : | JSON
18535 : : | JSON_ARRAY
18536 : : | JSON_ARRAYAGG
18537 : : | JSON_EXISTS
18538 : : | JSON_OBJECT
18539 : : | JSON_OBJECTAGG
18540 : : | JSON_QUERY
18541 : : | JSON_SCALAR
18542 : : | JSON_SERIALIZE
18543 : : | JSON_TABLE
18544 : : | JSON_VALUE
18545 : : | KEEP
18546 : : | KEY
18547 : : | KEYS
18548 : : | LABEL
18549 : : | LANGUAGE
18550 : : | LARGE_P
18551 : : | LAST_P
18552 : : | LATERAL_P
18553 : : | LEADING
18554 : : | LEAKPROOF
18555 : : | LEAST
18556 : : | LEFT
18557 : : | LEVEL
18558 : : | LIKE
18559 : : | LISTEN
18560 : : | LOAD
18561 : : | LOCAL
18562 : : | LOCALTIME
18563 : : | LOCALTIMESTAMP
18564 : : | LOCATION
18565 : : | LOCK_P
18566 : : | LOCKED
18567 : : | LOGGED
18568 : : | MAPPING
18569 : : | MATCH
18570 : : | MATCHED
18571 : : | MATERIALIZED
18572 : : | MAXVALUE
18573 : : | MERGE
18574 : : | MERGE_ACTION
18575 : : | METHOD
18576 : : | MINVALUE
18577 : : | MODE
18578 : : | MOVE
18579 : : | NAME_P
18580 : : | NAMES
18581 : : | NATIONAL
18582 : : | NATURAL
18583 : : | NCHAR
18584 : : | NESTED
18585 : : | NEW
18586 : : | NEXT
18587 : : | NFC
18588 : : | NFD
18589 : : | NFKC
18590 : : | NFKD
18591 : : | NO
18592 : : | NONE
18593 : : | NORMALIZE
18594 : : | NORMALIZED
18595 : : | NOT
18596 : : | NOTHING
18597 : : | NOTIFY
18598 : : | NOWAIT
18599 : : | NULL_P
18600 : : | NULLIF
18601 : : | NULLS_P
18602 : : | NUMERIC
18603 : : | OBJECT_P
18604 : : | OBJECTS_P
18605 : : | OF
18606 : : | OFF
18607 : : | OIDS
18608 : : | OLD
18609 : : | OMIT
18610 : : | ONLY
18611 : : | OPERATOR
18612 : : | OPTION
18613 : : | OPTIONS
18614 : : | OR
18615 : : | ORDINALITY
18616 : : | OTHERS
18617 : : | OUT_P
18618 : : | OUTER_P
18619 : : | OVERLAY
18620 : : | OVERRIDING
18621 : : | OWNED
18622 : : | OWNER
18623 : : | PARALLEL
18624 : : | PARAMETER
18625 : : | PARSER
18626 : : | PARTIAL
18627 : : | PARTITION
18628 : : | PASSING
18629 : : | PASSWORD
18630 : : | PATH
18631 : : | PERIOD
18632 : : | PLACING
18633 : : | PLAN
18634 : : | PLANS
18635 : : | POLICY
18636 : : | POSITION
18637 : : | PRECEDING
18638 : : | PREPARE
18639 : : | PREPARED
18640 : : | PRESERVE
18641 : : | PRIMARY
18642 : : | PRIOR
18643 : : | PRIVILEGES
18644 : : | PROCEDURAL
18645 : : | PROCEDURE
18646 : : | PROCEDURES
18647 : : | PROGRAM
18648 : : | PUBLICATION
18649 : : | QUOTE
18650 : : | QUOTES
18651 : : | RANGE
18652 : : | READ
18653 : : | REAL
18654 : : | REASSIGN
18655 : : | RECURSIVE
18656 : : | REF_P
18657 : : | REFERENCES
18658 : : | REFERENCING
18659 : : | REFRESH
18660 : : | REINDEX
18661 : : | RELATIVE_P
18662 : : | RELEASE
18663 : : | RENAME
18664 : : | REPEATABLE
18665 : : | REPLACE
18666 : : | REPLICA
18667 : : | RESET
18668 : : | RESTART
18669 : : | RESTRICT
18670 : : | RETURN
18671 : : | RETURNS
18672 : : | REVOKE
18673 : : | RIGHT
18674 : : | ROLE
18675 : : | ROLLBACK
18676 : : | ROLLUP
18677 : : | ROUTINE
18678 : : | ROUTINES
18679 : : | ROW
18680 : : | ROWS
18681 : : | RULE
18682 : : | SAVEPOINT
18683 : : | SCALAR
18684 : : | SCHEMA
18685 : : | SCHEMAS
18686 : : | SCROLL
18687 : : | SEARCH
18688 : : | SECURITY
18689 : : | SELECT
18690 : : | SEQUENCE
18691 : : | SEQUENCES
18692 : : | SERIALIZABLE
18693 : : | SERVER
18694 : : | SESSION
18695 : : | SESSION_USER
18696 : : | SET
18697 : : | SETOF
18698 : : | SETS
18699 : : | SHARE
18700 : : | SHOW
18701 : : | SIMILAR
18702 : : | SIMPLE
18703 : : | SKIP
18704 : : | SMALLINT
18705 : : | SNAPSHOT
18706 : : | SOME
18707 : : | SOURCE
18708 : : | SQL_P
18709 : : | STABLE
18710 : : | STANDALONE_P
18711 : : | START
18712 : : | STATEMENT
18713 : : | STATISTICS
18714 : : | STDIN
18715 : : | STDOUT
18716 : : | STORAGE
18717 : : | STORED
18718 : : | STRICT_P
18719 : : | STRING_P
18720 : : | STRIP_P
18721 : : | SUBSCRIPTION
18722 : : | SUBSTRING
18723 : : | SUPPORT
18724 : : | SYMMETRIC
18725 : : | SYSID
18726 : : | SYSTEM_P
18727 : : | SYSTEM_USER
18728 : : | TABLE
18729 : : | TABLES
18730 : : | TABLESAMPLE
18731 : : | TABLESPACE
18732 : : | TARGET
18733 : : | TEMP
18734 : : | TEMPLATE
18735 : : | TEMPORARY
18736 : : | TEXT_P
18737 : : | THEN
18738 : : | TIES
18739 : : | TIME
18740 : : | TIMESTAMP
18741 : : | TRAILING
18742 : : | TRANSACTION
18743 : : | TRANSFORM
18744 : : | TREAT
18745 : : | TRIGGER
18746 : : | TRIM
18747 : : | TRUE_P
18748 : : | TRUNCATE
18749 : : | TRUSTED
18750 : : | TYPE_P
18751 : : | TYPES_P
18752 : : | UESCAPE
18753 : : | UNBOUNDED
18754 : : | UNCOMMITTED
18755 : : | UNCONDITIONAL
18756 : : | UNENCRYPTED
18757 : : | UNIQUE
18758 : : | UNKNOWN
18759 : : | UNLISTEN
18760 : : | UNLOGGED
18761 : : | UNTIL
18762 : : | UPDATE
18763 : : | USER
18764 : : | USING
18765 : : | VACUUM
18766 : : | VALID
18767 : : | VALIDATE
18768 : : | VALIDATOR
18769 : : | VALUE_P
18770 : : | VALUES
18771 : : | VARCHAR
18772 : : | VARIADIC
18773 : : | VERBOSE
18774 : : | VERSION_P
18775 : : | VIEW
18776 : : | VIEWS
18777 : : | VIRTUAL
18778 : : | VOLATILE
18779 : : | WHEN
18780 : : | WHITESPACE_P
18781 : : | WORK
18782 : : | WRAPPER
18783 : : | WRITE
18784 : : | XML_P
18785 : : | XMLATTRIBUTES
18786 : : | XMLCONCAT
18787 : : | XMLELEMENT
18788 : : | XMLEXISTS
18789 : : | XMLFOREST
18790 : : | XMLNAMESPACES
18791 : : | XMLPARSE
18792 : : | XMLPI
18793 : : | XMLROOT
18794 : : | XMLSERIALIZE
18795 : : | XMLTABLE
18796 : : | YES_P
18797 : : | ZONE
18798 : : ;
18799 : :
18800 : : %%
18801 : :
18802 : : /*
18803 : : * The signature of this function is required by bison. However, we
18804 : : * ignore the passed yylloc and instead use the last token position
18805 : : * available from the scanner.
18806 : : */
18807 : : static void
5831 18808 : 346 : base_yyerror(YYLTYPE *yylloc, core_yyscan_t yyscanner, const char *msg)
18809 : : {
5950 18810 : 346 : parser_yyerror(msg);
18811 : : }
18812 : :
18813 : : static RawStmt *
3208 18814 : 407503 : makeRawStmt(Node *stmt, int stmt_location)
18815 : : {
18816 : 407503 : RawStmt *rs = makeNode(RawStmt);
18817 : :
18818 : 407503 : rs->stmt = stmt;
18819 : 407503 : rs->stmt_location = stmt_location;
18820 : 407503 : rs->stmt_len = 0; /* might get changed later */
18821 : 407503 : return rs;
18822 : : }
18823 : :
18824 : : /* Adjust a RawStmt to reflect that it doesn't run to the end of the string */
18825 : : static void
18826 : 294775 : updateRawStmtEnd(RawStmt *rs, int end_location)
18827 : : {
18828 : : /*
18829 : : * If we already set the length, don't change it. This is for situations
18830 : : * like "select foo ;; select bar" where the same statement will be last
18831 : : * in the string for more than one semicolon.
18832 : : */
18833 [ + + ]: 294775 : if (rs->stmt_len > 0)
18834 : 321 : return;
18835 : :
18836 : : /* OK, update length of RawStmt */
18837 : 294454 : rs->stmt_len = end_location - rs->stmt_location;
18838 : : }
18839 : :
18840 : : static Node *
5950 18841 : 927995 : makeColumnRef(char *colname, List *indirection,
18842 : : int location, core_yyscan_t yyscanner)
18843 : : {
18844 : : /*
18845 : : * Generate a ColumnRef node, with an A_Indirection node added if there is
18846 : : * any subscripting in the specified indirection list. However, any field
18847 : : * selection at the start of the indirection list must be transposed into
18848 : : * the "fields" part of the ColumnRef node.
18849 : : */
7810 18850 : 927995 : ColumnRef *c = makeNode(ColumnRef);
1263 peter@eisentraut.org 18851 : 927995 : int nfields = 0;
18852 : : ListCell *l;
18853 : :
7167 tgl@sss.pgh.pa.us 18854 : 927995 : c->location = location;
7810 18855 [ + + + + : 1463974 : foreach(l, indirection)
+ + ]
18856 : : {
18857 [ + + ]: 540953 : if (IsA(lfirst(l), A_Indices))
18858 : : {
18859 : 4974 : A_Indirection *i = makeNode(A_Indirection);
18860 : :
18861 [ + + ]: 4974 : if (nfields == 0)
18862 : : {
18863 : : /* easy case - all indirection goes to A_Indirection */
6267 18864 : 3615 : c->fields = list_make1(makeString(colname));
5950 18865 : 3615 : i->indirection = check_indirection(indirection, yyscanner);
18866 : : }
18867 : : else
18868 : : {
18869 : : /* got to split the list in two */
6267 18870 : 1359 : i->indirection = check_indirection(list_copy_tail(indirection,
18871 : : nfields),
18872 : : yyscanner);
7810 18873 : 1359 : indirection = list_truncate(indirection, nfields);
6267 18874 : 1359 : c->fields = lcons(makeString(colname), indirection);
18875 : : }
7810 18876 : 4974 : i->arg = (Node *) c;
18877 : 4974 : return (Node *) i;
18878 : : }
6267 18879 [ + + ]: 535979 : else if (IsA(lfirst(l), A_Star))
18880 : : {
18881 : : /* We only allow '*' at the end of a ColumnRef */
2296 18882 [ - + ]: 2760 : if (lnext(indirection, l) != NULL)
5950 tgl@sss.pgh.pa.us 18883 :UBC 0 : parser_yyerror("improper use of \"*\"");
18884 : : }
7810 tgl@sss.pgh.pa.us 18885 :CBC 535979 : nfields++;
18886 : : }
18887 : : /* No subscripting, so all indirection gets added to field list */
6267 18888 : 923021 : c->fields = lcons(makeString(colname), indirection);
7810 18889 : 923021 : return (Node *) c;
18890 : : }
18891 : :
18892 : : static Node *
6269 18893 : 160056 : makeTypeCast(Node *arg, TypeName *typename, int location)
18894 : : {
1263 peter@eisentraut.org 18895 : 160056 : TypeCast *n = makeNode(TypeCast);
18896 : :
8514 bruce@momjian.us 18897 : 160056 : n->arg = arg;
5947 peter_e@gmx.net 18898 : 160056 : n->typeName = typename;
6269 tgl@sss.pgh.pa.us 18899 : 160056 : n->location = location;
8514 bruce@momjian.us 18900 : 160056 : return (Node *) n;
18901 : : }
18902 : :
18903 : : static Node *
6269 tgl@sss.pgh.pa.us 18904 : 8160 : makeStringConstCast(char *str, int location, TypeName *typename)
18905 : : {
1263 peter@eisentraut.org 18906 : 8160 : Node *s = makeStringConst(str, location);
18907 : :
6269 tgl@sss.pgh.pa.us 18908 : 8160 : return makeTypeCast(s, typename, -1);
18909 : : }
18910 : :
18911 : : static Node *
18912 : 198878 : makeIntConst(int val, int location)
18913 : : {
306 peter@eisentraut.org 18914 : 198878 : A_Const *n = makeNode(A_Const);
18915 : :
1509 18916 : 198878 : n->val.ival.type = T_Integer;
1382 18917 : 198878 : n->val.ival.ival = val;
6269 tgl@sss.pgh.pa.us 18918 : 198878 : n->location = location;
18919 : :
306 peter@eisentraut.org 18920 : 198878 : return (Node *) n;
18921 : : }
18922 : :
18923 : : static Node *
6269 tgl@sss.pgh.pa.us 18924 : 5944 : makeFloatConst(char *str, int location)
18925 : : {
306 peter@eisentraut.org 18926 : 5944 : A_Const *n = makeNode(A_Const);
18927 : :
1509 18928 : 5944 : n->val.fval.type = T_Float;
1382 18929 : 5944 : n->val.fval.fval = str;
6269 tgl@sss.pgh.pa.us 18930 : 5944 : n->location = location;
18931 : :
306 peter@eisentraut.org 18932 : 5944 : return (Node *) n;
18933 : : }
18934 : :
18935 : : static Node *
1382 18936 : 34890 : makeBoolAConst(bool state, int location)
18937 : : {
306 18938 : 34890 : A_Const *n = makeNode(A_Const);
18939 : :
1382 18940 : 34890 : n->val.boolval.type = T_Boolean;
18941 : 34890 : n->val.boolval.boolval = state;
18942 : 34890 : n->location = location;
18943 : :
306 18944 : 34890 : return (Node *) n;
18945 : : }
18946 : :
18947 : : static Node *
6269 tgl@sss.pgh.pa.us 18948 : 2026 : makeBitStringConst(char *str, int location)
18949 : : {
306 peter@eisentraut.org 18950 : 2026 : A_Const *n = makeNode(A_Const);
18951 : :
1509 18952 : 2026 : n->val.bsval.type = T_BitString;
1382 18953 : 2026 : n->val.bsval.bsval = str;
6269 tgl@sss.pgh.pa.us 18954 : 2026 : n->location = location;
18955 : :
306 peter@eisentraut.org 18956 : 2026 : return (Node *) n;
18957 : : }
18958 : :
18959 : : static Node *
6269 tgl@sss.pgh.pa.us 18960 : 33731 : makeNullAConst(int location)
18961 : : {
306 peter@eisentraut.org 18962 : 33731 : A_Const *n = makeNode(A_Const);
18963 : :
1509 18964 : 33731 : n->isnull = true;
6269 tgl@sss.pgh.pa.us 18965 : 33731 : n->location = location;
18966 : :
1263 peter@eisentraut.org 18967 : 33731 : return (Node *) n;
18968 : : }
18969 : :
18970 : : static Node *
1509 18971 : 2732 : makeAConst(Node *v, int location)
18972 : : {
18973 : : Node *n;
18974 : :
8590 lockhart@fourpalms.o 18975 [ + + - ]: 2732 : switch (v->type)
18976 : : {
18977 : 109 : case T_Float:
1382 peter@eisentraut.org 18978 : 109 : n = makeFloatConst(castNode(Float, v)->fval, location);
8590 lockhart@fourpalms.o 18979 : 109 : break;
18980 : :
18981 : 2623 : case T_Integer:
1382 peter@eisentraut.org 18982 : 2623 : n = makeIntConst(castNode(Integer, v)->ival, location);
8590 lockhart@fourpalms.o 18983 : 2623 : break;
18984 : :
8590 lockhart@fourpalms.o 18985 :UBC 0 : default:
18986 : : /* currently not used */
1382 peter@eisentraut.org 18987 : 0 : Assert(false);
18988 : : n = NULL;
18989 : : }
18990 : :
8590 lockhart@fourpalms.o 18991 :CBC 2732 : return n;
18992 : : }
18993 : :
18994 : : /* makeRoleSpec
18995 : : * Create a RoleSpec with the given type
18996 : : */
18997 : : static RoleSpec *
3885 alvherre@alvh.no-ip. 18998 : 16834 : makeRoleSpec(RoleSpecType type, int location)
18999 : : {
1263 peter@eisentraut.org 19000 : 16834 : RoleSpec *spec = makeNode(RoleSpec);
19001 : :
3885 alvherre@alvh.no-ip. 19002 : 16834 : spec->roletype = type;
19003 : 16834 : spec->location = location;
19004 : :
3225 peter_e@gmx.net 19005 : 16834 : return spec;
19006 : : }
19007 : :
19008 : : /* check_qualified_name --- check the result of qualified_name production
19009 : : *
19010 : : * It's easiest to let the grammar production for qualified_name allow
19011 : : * subscripts and '*', which we then must reject here.
19012 : : */
19013 : : static void
5831 tgl@sss.pgh.pa.us 19014 : 128090 : check_qualified_name(List *names, core_yyscan_t yyscanner)
19015 : : {
19016 : : ListCell *i;
19017 : :
7658 19018 [ + - + + : 256180 : foreach(i, names)
+ + ]
19019 : : {
19020 [ - + ]: 128090 : if (!IsA(lfirst(i), String))
5950 tgl@sss.pgh.pa.us 19021 :UBC 0 : parser_yyerror("syntax error");
19022 : : }
7658 tgl@sss.pgh.pa.us 19023 :CBC 128090 : }
19024 : :
19025 : : /* check_func_name --- check the result of func_name production
19026 : : *
19027 : : * It's easiest to let the grammar production for func_name allow subscripts
19028 : : * and '*', which we then must reject here.
19029 : : */
19030 : : static List *
5831 19031 : 64008 : check_func_name(List *names, core_yyscan_t yyscanner)
19032 : : {
19033 : : ListCell *i;
19034 : :
7810 19035 [ + - + + : 192024 : foreach(i, names)
+ + ]
19036 : : {
19037 [ - + ]: 128016 : if (!IsA(lfirst(i), String))
5950 tgl@sss.pgh.pa.us 19038 :UBC 0 : parser_yyerror("syntax error");
19039 : : }
7810 tgl@sss.pgh.pa.us 19040 :CBC 64008 : return names;
19041 : : }
19042 : :
19043 : : /* check_indirection --- check the result of indirection production
19044 : : *
19045 : : * We only allow '*' at the end of the list, but it's hard to enforce that
19046 : : * in the grammar, so do it here.
19047 : : */
19048 : : static List *
5831 19049 : 40657 : check_indirection(List *indirection, core_yyscan_t yyscanner)
19050 : : {
19051 : : ListCell *l;
19052 : :
6267 19053 [ + + + + : 54482 : foreach(l, indirection)
+ + ]
19054 : : {
19055 [ + + ]: 13825 : if (IsA(lfirst(l), A_Star))
19056 : : {
2296 19057 [ - + ]: 731 : if (lnext(indirection, l) != NULL)
5950 tgl@sss.pgh.pa.us 19058 :UBC 0 : parser_yyerror("improper use of \"*\"");
19059 : : }
19060 : : }
6267 tgl@sss.pgh.pa.us 19061 :CBC 40657 : return indirection;
19062 : : }
19063 : :
19064 : : /* extractArgTypes()
19065 : : * Given a list of FunctionParameter nodes, extract a list of just the
19066 : : * argument types (TypeNames) for input parameters only. This is what
19067 : : * is needed to look up an existing function, which is what is wanted by
19068 : : * the productions that use this call.
19069 : : */
19070 : : static List *
1600 19071 : 9203 : extractArgTypes(List *parameters)
19072 : : {
7965 19073 : 9203 : List *result = NIL;
19074 : : ListCell *i;
19075 : :
19076 [ + + + + : 21146 : foreach(i, parameters)
+ + ]
19077 : : {
19078 : 11943 : FunctionParameter *p = (FunctionParameter *) lfirst(i);
19079 : :
1600 19080 [ + + + - ]: 11943 : if (p->mode != FUNC_PARAM_OUT && p->mode != FUNC_PARAM_TABLE)
7517 19081 : 11865 : result = lappend(result, p->argType);
19082 : : }
7965 19083 : 9203 : return result;
19084 : : }
19085 : :
19086 : : /* extractAggrArgTypes()
19087 : : * As above, but work from the output of the aggr_args production.
19088 : : */
19089 : : static List *
4326 19090 : 181 : extractAggrArgTypes(List *aggrargs)
19091 : : {
19092 [ - + ]: 181 : Assert(list_length(aggrargs) == 2);
1600 19093 : 181 : return extractArgTypes((List *) linitial(aggrargs));
19094 : : }
19095 : :
19096 : : /* makeOrderedSetArgs()
19097 : : * Build the result of the aggr_args production (which see the comments for).
19098 : : * This handles only the case where both given lists are nonempty, so that
19099 : : * we have to deal with multiple VARIADIC arguments.
19100 : : */
19101 : : static List *
4326 19102 : 16 : makeOrderedSetArgs(List *directargs, List *orderedargs,
19103 : : core_yyscan_t yyscanner)
19104 : : {
19105 : 16 : FunctionParameter *lastd = (FunctionParameter *) llast(directargs);
19106 : : Integer *ndirectargs;
19107 : :
19108 : : /* No restriction unless last direct arg is VARIADIC */
19109 [ + + ]: 16 : if (lastd->mode == FUNC_PARAM_VARIADIC)
19110 : : {
19111 : 8 : FunctionParameter *firsto = (FunctionParameter *) linitial(orderedargs);
19112 : :
19113 : : /*
19114 : : * We ignore the names, though the aggr_arg production allows them; it
19115 : : * doesn't allow default values, so those need not be checked.
19116 : : */
19117 [ + - ]: 8 : if (list_length(orderedargs) != 1 ||
19118 [ + - ]: 8 : firsto->mode != FUNC_PARAM_VARIADIC ||
19119 [ - + ]: 8 : !equal(lastd->argType, firsto->argType))
4326 tgl@sss.pgh.pa.us 19120 [ # # ]:UBC 0 : ereport(ERROR,
19121 : : (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
19122 : : errmsg("an ordered-set aggregate with a VARIADIC direct argument must have one VARIADIC aggregated argument of the same data type"),
19123 : : parser_errposition(firsto->location)));
19124 : :
19125 : : /* OK, drop the duplicate VARIADIC argument from the internal form */
4326 tgl@sss.pgh.pa.us 19126 :CBC 8 : orderedargs = NIL;
19127 : : }
19128 : :
19129 : : /* don't merge into the next line, as list_concat changes directargs */
1846 19130 : 16 : ndirectargs = makeInteger(list_length(directargs));
19131 : :
4326 19132 : 16 : return list_make2(list_concat(directargs, orderedargs),
19133 : : ndirectargs);
19134 : : }
19135 : :
19136 : : /* insertSelectOptions()
19137 : : * Insert ORDER BY, etc into an already-constructed SelectStmt.
19138 : : *
19139 : : * This routine is just to avoid duplicating code in SelectStmt productions.
19140 : : */
19141 : : static void
9122 19142 : 41883 : insertSelectOptions(SelectStmt *stmt,
19143 : : List *sortClause, List *lockingClause,
19144 : : SelectLimit *limitClause,
19145 : : WithClause *withClause,
19146 : : core_yyscan_t yyscanner)
19147 : : {
6232 19148 [ - + ]: 41883 : Assert(IsA(stmt, SelectStmt));
19149 : :
19150 : : /*
19151 : : * Tests here are to reject constructs like
19152 : : * (SELECT foo ORDER BY bar) ORDER BY baz
19153 : : */
9122 19154 [ + + ]: 41883 : if (sortClause)
19155 : : {
19156 [ - + ]: 37107 : if (stmt->sortClause)
8136 tgl@sss.pgh.pa.us 19157 [ # # ]:UBC 0 : ereport(ERROR,
19158 : : (errcode(ERRCODE_SYNTAX_ERROR),
19159 : : errmsg("multiple ORDER BY clauses not allowed"),
19160 : : parser_errposition(exprLocation((Node *) sortClause))));
9122 tgl@sss.pgh.pa.us 19161 :CBC 37107 : stmt->sortClause = sortClause;
19162 : : }
19163 : : /* We can handle multiple locking clauses, though */
7120 19164 : 41883 : stmt->lockingClause = list_concat(stmt->lockingClause, lockingClause);
2029 alvherre@alvh.no-ip. 19165 [ + + + + ]: 41883 : if (limitClause && limitClause->limitOffset)
19166 : : {
9122 tgl@sss.pgh.pa.us 19167 [ - + ]: 430 : if (stmt->limitOffset)
8136 tgl@sss.pgh.pa.us 19168 [ # # ]:UBC 0 : ereport(ERROR,
19169 : : (errcode(ERRCODE_SYNTAX_ERROR),
19170 : : errmsg("multiple OFFSET clauses not allowed"),
19171 : : parser_errposition(limitClause->offsetLoc)));
2029 alvherre@alvh.no-ip. 19172 :CBC 430 : stmt->limitOffset = limitClause->limitOffset;
19173 : : }
19174 [ + + + + ]: 41883 : if (limitClause && limitClause->limitCount)
19175 : : {
9122 tgl@sss.pgh.pa.us 19176 [ - + ]: 2336 : if (stmt->limitCount)
8136 tgl@sss.pgh.pa.us 19177 [ # # ]:UBC 0 : ereport(ERROR,
19178 : : (errcode(ERRCODE_SYNTAX_ERROR),
19179 : : errmsg("multiple LIMIT clauses not allowed"),
19180 : : parser_errposition(limitClause->countLoc)));
2029 alvherre@alvh.no-ip. 19181 :CBC 2336 : stmt->limitCount = limitClause->limitCount;
19182 : : }
681 19183 [ + + ]: 41883 : if (limitClause)
19184 : : {
19185 : : /* If there was a conflict, we must have detected it above */
361 tgl@sss.pgh.pa.us 19186 [ - + ]: 2569 : Assert(!stmt->limitOption);
2029 alvherre@alvh.no-ip. 19187 [ + + + + ]: 2569 : if (!stmt->sortClause && limitClause->limitOption == LIMIT_OPTION_WITH_TIES)
19188 [ + - ]: 3 : ereport(ERROR,
19189 : : (errcode(ERRCODE_SYNTAX_ERROR),
19190 : : errmsg("WITH TIES cannot be specified without ORDER BY clause"),
19191 : : parser_errposition(limitClause->optionLoc)));
1487 19192 [ + + + + ]: 2566 : if (limitClause->limitOption == LIMIT_OPTION_WITH_TIES && stmt->lockingClause)
19193 : : {
19194 : : ListCell *lc;
19195 : :
19196 [ + - + - : 3 : foreach(lc, stmt->lockingClause)
+ - ]
19197 : : {
19198 : 3 : LockingClause *lock = lfirst_node(LockingClause, lc);
19199 : :
19200 [ + - ]: 3 : if (lock->waitPolicy == LockWaitSkip)
19201 [ + - ]: 3 : ereport(ERROR,
19202 : : (errcode(ERRCODE_SYNTAX_ERROR),
19203 : : errmsg("%s and %s options cannot be used together",
19204 : : "SKIP LOCKED", "WITH TIES"),
19205 : : parser_errposition(limitClause->optionLoc)));
19206 : : }
19207 : : }
2029 19208 : 2563 : stmt->limitOption = limitClause->limitOption;
19209 : : }
6232 tgl@sss.pgh.pa.us 19210 [ + + ]: 41877 : if (withClause)
19211 : : {
19212 [ - + ]: 1449 : if (stmt->withClause)
6232 tgl@sss.pgh.pa.us 19213 [ # # ]:UBC 0 : ereport(ERROR,
19214 : : (errcode(ERRCODE_SYNTAX_ERROR),
19215 : : errmsg("multiple WITH clauses not allowed"),
19216 : : parser_errposition(exprLocation((Node *) withClause))));
6232 tgl@sss.pgh.pa.us 19217 :CBC 1449 : stmt->withClause = withClause;
19218 : : }
9122 19219 : 41877 : }
19220 : :
19221 : : static Node *
137 michael@paquier.xyz 19222 : 9886 : makeSetOp(SetOperation op, bool all, Node *larg, Node *rarg)
19223 : : {
9122 tgl@sss.pgh.pa.us 19224 : 9886 : SelectStmt *n = makeNode(SelectStmt);
19225 : :
19226 : 9886 : n->op = op;
19227 : 9886 : n->all = all;
19228 : 9886 : n->larg = (SelectStmt *) larg;
19229 : 9886 : n->rarg = (SelectStmt *) rarg;
19230 : 9886 : return (Node *) n;
19231 : : }
19232 : :
19233 : : /* SystemFuncName()
19234 : : * Build a properly-qualified reference to a built-in function.
19235 : : */
19236 : : List *
8602 19237 : 9766 : SystemFuncName(char *name)
19238 : : {
7820 neilc@samurai.com 19239 : 9766 : return list_make2(makeString("pg_catalog"), makeString(name));
19240 : : }
19241 : :
19242 : : /* SystemTypeName()
19243 : : * Build a properly-qualified reference to a built-in type.
19244 : : *
19245 : : * typmod is defaulted, but may be changed afterwards by caller.
19246 : : * Likewise for the location.
19247 : : */
19248 : : TypeName *
8578 tgl@sss.pgh.pa.us 19249 : 61280 : SystemTypeName(char *name)
19250 : : {
6876 19251 : 61280 : return makeTypeNameFromNameList(list_make2(makeString("pg_catalog"),
19252 : : makeString(name)));
19253 : : }
19254 : :
19255 : : /* doNegate()
19256 : : * Handle negation of a numeric constant.
19257 : : *
19258 : : * Formerly, we did this here because the optimizer couldn't cope with
19259 : : * indexquals that looked like "var = -4" --- it wants "var = const"
19260 : : * and a unary minus operator applied to a constant didn't qualify.
19261 : : * As of Postgres 7.0, that problem doesn't exist anymore because there
19262 : : * is a constant-subexpression simplifier in the optimizer. However,
19263 : : * there's still a good reason for doing this here, which is that we can
19264 : : * postpone committing to a particular internal representation for simple
19265 : : * negative constants. It's better to leave "-123.456" in string form
19266 : : * until we know what the desired type is.
19267 : : */
19268 : : static Node *
7167 19269 : 4610 : doNegate(Node *n, int location)
19270 : : {
9720 bruce@momjian.us 19271 [ + + ]: 4610 : if (IsA(n, A_Const))
19272 : : {
306 peter@eisentraut.org 19273 : 4109 : A_Const *con = (A_Const *) n;
19274 : :
19275 : : /* report the constant's location as that of the '-' sign */
6269 tgl@sss.pgh.pa.us 19276 : 4109 : con->location = location;
19277 : :
1509 peter@eisentraut.org 19278 [ + + ]: 4109 : if (IsA(&con->val, Integer))
19279 : : {
1382 19280 : 3630 : con->val.ival.ival = -con->val.ival.ival;
9720 bruce@momjian.us 19281 : 3630 : return n;
19282 : : }
1509 peter@eisentraut.org 19283 [ + - ]: 479 : if (IsA(&con->val, Float))
19284 : : {
19285 : 479 : doNegateFloat(&con->val.fval);
9720 bruce@momjian.us 19286 : 479 : return n;
19287 : : }
19288 : : }
19289 : :
7167 tgl@sss.pgh.pa.us 19290 : 501 : return (Node *) makeSimpleA_Expr(AEXPR_OP, "-", NULL, n, location);
19291 : : }
19292 : :
19293 : : static void
1509 peter@eisentraut.org 19294 : 489 : doNegateFloat(Float *v)
19295 : : {
1263 19296 : 489 : char *oldval = v->fval;
19297 : :
9380 tgl@sss.pgh.pa.us 19298 [ - + ]: 489 : if (*oldval == '+')
9380 tgl@sss.pgh.pa.us 19299 :UBC 0 : oldval++;
9380 tgl@sss.pgh.pa.us 19300 [ - + ]:CBC 489 : if (*oldval == '-')
306 peter@eisentraut.org 19301 :UBC 0 : v->fval = oldval + 1; /* just strip the '-' */
19302 : : else
1382 peter@eisentraut.org 19303 :CBC 489 : v->fval = psprintf("-%s", oldval);
9380 tgl@sss.pgh.pa.us 19304 : 489 : }
19305 : :
19306 : : static Node *
4151 19307 : 118740 : makeAndExpr(Node *lexpr, Node *rexpr, int location)
19308 : : {
19309 : : /* Flatten "a AND b AND c ..." to a single BoolExpr on sight */
1784 19310 [ + + ]: 118740 : if (IsA(lexpr, BoolExpr))
19311 : : {
1263 peter@eisentraut.org 19312 : 56886 : BoolExpr *blexpr = (BoolExpr *) lexpr;
19313 : :
4151 tgl@sss.pgh.pa.us 19314 [ + + ]: 56886 : if (blexpr->boolop == AND_EXPR)
19315 : : {
19316 : 55603 : blexpr->args = lappend(blexpr->args, rexpr);
19317 : 55603 : return (Node *) blexpr;
19318 : : }
19319 : : }
19320 : 63137 : return (Node *) makeBoolExpr(AND_EXPR, list_make2(lexpr, rexpr), location);
19321 : : }
19322 : :
19323 : : static Node *
19324 : 8083 : makeOrExpr(Node *lexpr, Node *rexpr, int location)
19325 : : {
19326 : : /* Flatten "a OR b OR c ..." to a single BoolExpr on sight */
1784 19327 [ + + ]: 8083 : if (IsA(lexpr, BoolExpr))
19328 : : {
1263 peter@eisentraut.org 19329 : 2844 : BoolExpr *blexpr = (BoolExpr *) lexpr;
19330 : :
4151 tgl@sss.pgh.pa.us 19331 [ + + ]: 2844 : if (blexpr->boolop == OR_EXPR)
19332 : : {
19333 : 2081 : blexpr->args = lappend(blexpr->args, rexpr);
19334 : 2081 : return (Node *) blexpr;
19335 : : }
19336 : : }
19337 : 6002 : return (Node *) makeBoolExpr(OR_EXPR, list_make2(lexpr, rexpr), location);
19338 : : }
19339 : :
19340 : : static Node *
19341 : 8208 : makeNotExpr(Node *expr, int location)
19342 : : {
19343 : 8208 : return (Node *) makeBoolExpr(NOT_EXPR, list_make1(expr), location);
19344 : : }
19345 : :
19346 : : static Node *
137 alvherre@kurilemu.de 19347 : 4117 : makeAArrayExpr(List *elements, int location, int location_end)
19348 : : {
6430 tgl@sss.pgh.pa.us 19349 : 4117 : A_ArrayExpr *n = makeNode(A_ArrayExpr);
19350 : :
19351 : 4117 : n->elements = elements;
6269 19352 : 4117 : n->location = location;
137 alvherre@kurilemu.de 19353 : 4117 : n->list_start = location;
19354 : 4117 : n->list_end = location_end;
6430 tgl@sss.pgh.pa.us 19355 : 4117 : return (Node *) n;
19356 : : }
19357 : :
19358 : : static Node *
894 michael@paquier.xyz 19359 : 1394 : makeSQLValueFunction(SQLValueFunctionOp op, int32 typmod, int location)
19360 : : {
19361 : 1394 : SQLValueFunction *svf = makeNode(SQLValueFunction);
19362 : :
19363 : 1394 : svf->op = op;
19364 : : /* svf->type will be filled during parse analysis */
19365 : 1394 : svf->typmod = typmod;
19366 : 1394 : svf->location = location;
19367 : 1394 : return (Node *) svf;
19368 : : }
19369 : :
19370 : : static Node *
6269 tgl@sss.pgh.pa.us 19371 : 298 : makeXmlExpr(XmlExprOp op, char *name, List *named_args, List *args,
19372 : : int location)
19373 : : {
306 peter@eisentraut.org 19374 : 298 : XmlExpr *x = makeNode(XmlExpr);
19375 : :
6885 peter_e@gmx.net 19376 : 298 : x->op = op;
19377 : 298 : x->name = name;
19378 : :
19379 : : /*
19380 : : * named_args is a list of ResTarget; it'll be split apart into separate
19381 : : * expression and name lists in transformXmlExpr().
19382 : : */
19383 : 298 : x->named_args = named_args;
6882 tgl@sss.pgh.pa.us 19384 : 298 : x->arg_names = NIL;
6885 peter_e@gmx.net 19385 : 298 : x->args = args;
19386 : : /* xmloption, if relevant, must be filled in by caller */
19387 : : /* type and typmod will be filled in during parse analysis */
306 peter@eisentraut.org 19388 : 298 : x->type = InvalidOid; /* marks the node as not analyzed */
6269 tgl@sss.pgh.pa.us 19389 : 298 : x->location = location;
6885 peter_e@gmx.net 19390 : 298 : return (Node *) x;
19391 : : }
19392 : :
19393 : : /*
19394 : : * Merge the input and output parameters of a table function.
19395 : : */
19396 : : static List *
361 tgl@sss.pgh.pa.us 19397 : 97 : mergeTableFuncParameters(List *func_args, List *columns, core_yyscan_t yyscanner)
19398 : : {
19399 : : ListCell *lc;
19400 : :
19401 : : /* Explicit OUT and INOUT parameters shouldn't be used in this syntax */
6310 19402 [ + + + + : 197 : foreach(lc, func_args)
+ + ]
19403 : : {
19404 : 100 : FunctionParameter *p = (FunctionParameter *) lfirst(lc);
19405 : :
1600 19406 [ - + ]: 100 : if (p->mode != FUNC_PARAM_DEFAULT &&
1600 tgl@sss.pgh.pa.us 19407 [ # # ]:UBC 0 : p->mode != FUNC_PARAM_IN &&
19408 [ # # ]: 0 : p->mode != FUNC_PARAM_VARIADIC)
6310 19409 [ # # ]: 0 : ereport(ERROR,
19410 : : (errcode(ERRCODE_SYNTAX_ERROR),
19411 : : errmsg("OUT and INOUT arguments aren't allowed in TABLE functions"),
19412 : : parser_errposition(p->location)));
19413 : : }
19414 : :
6310 tgl@sss.pgh.pa.us 19415 :CBC 97 : return list_concat(func_args, columns);
19416 : : }
19417 : :
19418 : : /*
19419 : : * Determine return type of a TABLE function. A single result column
19420 : : * returns setof that column's type; otherwise return setof record.
19421 : : */
19422 : : static TypeName *
19423 : 97 : TableFuncTypeName(List *columns)
19424 : : {
19425 : : TypeName *result;
19426 : :
19427 [ + + ]: 97 : if (list_length(columns) == 1)
19428 : : {
19429 : 31 : FunctionParameter *p = (FunctionParameter *) linitial(columns);
19430 : :
3154 peter_e@gmx.net 19431 : 31 : result = copyObject(p->argType);
19432 : : }
19433 : : else
6310 tgl@sss.pgh.pa.us 19434 : 66 : result = SystemTypeName("record");
19435 : :
19436 : 97 : result->setof = true;
19437 : :
19438 : 97 : return result;
19439 : : }
19440 : :
19441 : : /*
19442 : : * Convert a list of (dotted) names to a RangeVar (like
19443 : : * makeRangeVarFromNameList, but with position support). The
19444 : : * "AnyName" refers to the any_name production in the grammar.
19445 : : */
19446 : : static RangeVar *
5510 peter_e@gmx.net 19447 : 479 : makeRangeVarFromAnyName(List *names, int position, core_yyscan_t yyscanner)
19448 : : {
1263 peter@eisentraut.org 19449 : 479 : RangeVar *r = makeNode(RangeVar);
19450 : :
5510 peter_e@gmx.net 19451 [ + + - - ]: 479 : switch (list_length(names))
19452 : : {
19453 : 434 : case 1:
19454 : 434 : r->catalogname = NULL;
19455 : 434 : r->schemaname = NULL;
19456 : 434 : r->relname = strVal(linitial(names));
19457 : 434 : break;
19458 : 45 : case 2:
19459 : 45 : r->catalogname = NULL;
19460 : 45 : r->schemaname = strVal(linitial(names));
19461 : 45 : r->relname = strVal(lsecond(names));
19462 : 45 : break;
5510 peter_e@gmx.net 19463 :UBC 0 : case 3:
3863 heikki.linnakangas@i 19464 : 0 : r->catalogname = strVal(linitial(names));
5510 peter_e@gmx.net 19465 : 0 : r->schemaname = strVal(lsecond(names));
19466 : 0 : r->relname = strVal(lthird(names));
19467 : 0 : break;
19468 : 0 : default:
19469 [ # # ]: 0 : ereport(ERROR,
19470 : : (errcode(ERRCODE_SYNTAX_ERROR),
19471 : : errmsg("improper qualified name (too many dotted names): %s",
19472 : : NameListToString(names)),
19473 : : parser_errposition(position)));
19474 : : break;
19475 : : }
19476 : :
5432 rhaas@postgresql.org 19477 :CBC 479 : r->relpersistence = RELPERSISTENCE_PERMANENT;
5510 peter_e@gmx.net 19478 : 479 : r->location = position;
19479 : :
19480 : 479 : return r;
19481 : : }
19482 : :
19483 : : /*
19484 : : * Convert a relation_name with name and namelist to a RangeVar using
19485 : : * makeRangeVar.
19486 : : */
19487 : : static RangeVar *
1461 akapila@postgresql.o 19488 : 128090 : makeRangeVarFromQualifiedName(char *name, List *namelist, int location,
19489 : : core_yyscan_t yyscanner)
19490 : : {
19491 : : RangeVar *r;
19492 : :
19493 : 128090 : check_qualified_name(namelist, yyscanner);
19494 : 128090 : r = makeRangeVar(NULL, NULL, location);
19495 : :
19496 [ + - - ]: 128090 : switch (list_length(namelist))
19497 : : {
19498 : 128090 : case 1:
19499 : 128090 : r->catalogname = NULL;
19500 : 128090 : r->schemaname = name;
19501 : 128090 : r->relname = strVal(linitial(namelist));
19502 : 128090 : break;
1461 akapila@postgresql.o 19503 :UBC 0 : case 2:
19504 : 0 : r->catalogname = name;
19505 : 0 : r->schemaname = strVal(linitial(namelist));
19506 : 0 : r->relname = strVal(lsecond(namelist));
19507 : 0 : break;
19508 : 0 : default:
19509 [ # # ]: 0 : ereport(ERROR,
19510 : : errcode(ERRCODE_SYNTAX_ERROR),
19511 : : errmsg("improper qualified name (too many dotted names): %s",
19512 : : NameListToString(lcons(makeString(name), namelist))),
19513 : : parser_errposition(location));
19514 : : break;
19515 : : }
19516 : :
1461 akapila@postgresql.o 19517 :CBC 128090 : return r;
19518 : : }
19519 : :
19520 : : /* Separate Constraint nodes from COLLATE clauses in a ColQualList */
19521 : : static void
5346 tgl@sss.pgh.pa.us 19522 : 34966 : SplitColQualList(List *qualList,
19523 : : List **constraintList, CollateClause **collClause,
19524 : : core_yyscan_t yyscanner)
19525 : : {
19526 : : ListCell *cell;
19527 : :
19528 : 34966 : *collClause = NULL;
2296 19529 [ + + + + : 45076 : foreach(cell, qualList)
+ + ]
19530 : : {
1263 peter@eisentraut.org 19531 : 10110 : Node *n = (Node *) lfirst(cell);
19532 : :
5346 tgl@sss.pgh.pa.us 19533 [ + + ]: 10110 : if (IsA(n, Constraint))
19534 : : {
19535 : : /* keep it in list */
19536 : 9723 : continue;
19537 : : }
19538 [ + - ]: 387 : if (IsA(n, CollateClause))
19539 : : {
19540 : 387 : CollateClause *c = (CollateClause *) n;
19541 : :
19542 [ - + ]: 387 : if (*collClause)
5346 tgl@sss.pgh.pa.us 19543 [ # # ]:UBC 0 : ereport(ERROR,
19544 : : (errcode(ERRCODE_SYNTAX_ERROR),
19545 : : errmsg("multiple COLLATE clauses not allowed"),
19546 : : parser_errposition(c->location)));
5346 tgl@sss.pgh.pa.us 19547 :CBC 387 : *collClause = c;
19548 : : }
19549 : : else
5346 tgl@sss.pgh.pa.us 19550 [ # # ]:UBC 0 : elog(ERROR, "unexpected node type %d", (int) n->type);
19551 : : /* remove non-Constraint nodes from qualList */
2296 tgl@sss.pgh.pa.us 19552 :CBC 387 : qualList = foreach_delete_current(qualList, cell);
19553 : : }
5346 19554 : 34966 : *constraintList = qualList;
19555 : 34966 : }
19556 : :
19557 : : /*
19558 : : * Process result of ConstraintAttributeSpec, and set appropriate bool flags
19559 : : * in the output command node. Pass NULL for any flags the particular
19560 : : * command doesn't support.
19561 : : */
19562 : : static void
5248 19563 : 8946 : processCASbits(int cas_bits, int location, const char *constrType,
19564 : : bool *deferrable, bool *initdeferred, bool *is_enforced,
19565 : : bool *not_valid, bool *no_inherit, core_yyscan_t yyscanner)
19566 : : {
19567 : : /* defaults */
19568 [ + + ]: 8946 : if (deferrable)
19569 : 7916 : *deferrable = false;
19570 [ + + ]: 8946 : if (initdeferred)
19571 : 7916 : *initdeferred = false;
19572 [ + + ]: 8946 : if (not_valid)
19573 : 1943 : *not_valid = false;
289 peter@eisentraut.org 19574 [ + + ]: 8946 : if (is_enforced)
19575 : 1707 : *is_enforced = true;
19576 : :
5248 tgl@sss.pgh.pa.us 19577 [ + + ]: 8946 : if (cas_bits & (CAS_DEFERRABLE | CAS_INITIALLY_DEFERRED))
19578 : : {
19579 [ + - ]: 115 : if (deferrable)
19580 : 115 : *deferrable = true;
19581 : : else
5248 tgl@sss.pgh.pa.us 19582 [ # # ]:UBC 0 : ereport(ERROR,
19583 : : (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
19584 : : /* translator: %s is CHECK, UNIQUE, or similar */
19585 : : errmsg("%s constraints cannot be marked DEFERRABLE",
19586 : : constrType),
19587 : : parser_errposition(location)));
19588 : : }
19589 : :
5248 tgl@sss.pgh.pa.us 19590 [ + + ]:CBC 8946 : if (cas_bits & CAS_INITIALLY_DEFERRED)
19591 : : {
19592 [ + - ]: 73 : if (initdeferred)
19593 : 73 : *initdeferred = true;
19594 : : else
5248 tgl@sss.pgh.pa.us 19595 [ # # ]:UBC 0 : ereport(ERROR,
19596 : : (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
19597 : : /* translator: %s is CHECK, UNIQUE, or similar */
19598 : : errmsg("%s constraints cannot be marked DEFERRABLE",
19599 : : constrType),
19600 : : parser_errposition(location)));
19601 : : }
19602 : :
5248 tgl@sss.pgh.pa.us 19603 [ + + ]:CBC 8946 : if (cas_bits & CAS_NOT_VALID)
19604 : : {
19605 [ + - ]: 357 : if (not_valid)
19606 : 357 : *not_valid = true;
19607 : : else
5248 tgl@sss.pgh.pa.us 19608 [ # # ]:UBC 0 : ereport(ERROR,
19609 : : (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
19610 : : /* translator: %s is CHECK, UNIQUE, or similar */
19611 : : errmsg("%s constraints cannot be marked NOT VALID",
19612 : : constrType),
19613 : : parser_errposition(location)));
19614 : : }
19615 : :
4843 alvherre@alvh.no-ip. 19616 [ + + ]:CBC 8946 : if (cas_bits & CAS_NO_INHERIT)
19617 : : {
19618 [ + - ]: 122 : if (no_inherit)
19619 : 122 : *no_inherit = true;
19620 : : else
4843 alvherre@alvh.no-ip. 19621 [ # # ]:UBC 0 : ereport(ERROR,
19622 : : (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
19623 : : /* translator: %s is CHECK, UNIQUE, or similar */
19624 : : errmsg("%s constraints cannot be marked NO INHERIT",
19625 : : constrType),
19626 : : parser_errposition(location)));
19627 : : }
19628 : :
289 peter@eisentraut.org 19629 [ + + ]:CBC 8946 : if (cas_bits & CAS_NOT_ENFORCED)
19630 : : {
19631 [ + + ]: 78 : if (is_enforced)
19632 : 75 : *is_enforced = false;
19633 : : else
19634 [ + - ]: 3 : ereport(ERROR,
19635 : : (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
19636 : : /* translator: %s is CHECK, UNIQUE, or similar */
19637 : : errmsg("%s constraints cannot be marked NOT ENFORCED",
19638 : : constrType),
19639 : : parser_errposition(location)));
19640 : :
19641 : : /*
19642 : : * NB: The validated status is irrelevant when the constraint is set to
19643 : : * NOT ENFORCED, but for consistency, it should be set accordingly.
19644 : : * This ensures that if the constraint is later changed to ENFORCED, it
19645 : : * will automatically be in the correct NOT VALIDATED state.
19646 : : */
19647 [ + + ]: 75 : if (not_valid)
19648 : 57 : *not_valid = true;
19649 : : }
19650 : :
19651 [ + + ]: 8943 : if (cas_bits & CAS_ENFORCED)
19652 : : {
19653 [ + + ]: 51 : if (is_enforced)
19654 : 48 : *is_enforced = true;
19655 : : else
19656 [ + - ]: 3 : ereport(ERROR,
19657 : : (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
19658 : : /* translator: %s is CHECK, UNIQUE, or similar */
19659 : : errmsg("%s constraints cannot be marked ENFORCED",
19660 : : constrType),
19661 : : parser_errposition(location)));
19662 : : }
5248 tgl@sss.pgh.pa.us 19663 : 8940 : }
19664 : :
19665 : : /*
19666 : : * Parse a user-supplied partition strategy string into parse node
19667 : : * PartitionStrategy representation, or die trying.
19668 : : */
19669 : : static PartitionStrategy
361 19670 : 2559 : parsePartitionStrategy(char *strategy, int location, core_yyscan_t yyscanner)
19671 : : {
1089 alvherre@alvh.no-ip. 19672 [ + + ]: 2559 : if (pg_strcasecmp(strategy, "list") == 0)
19673 : 1285 : return PARTITION_STRATEGY_LIST;
19674 [ + + ]: 1274 : else if (pg_strcasecmp(strategy, "range") == 0)
19675 : 1138 : return PARTITION_STRATEGY_RANGE;
19676 [ + + ]: 136 : else if (pg_strcasecmp(strategy, "hash") == 0)
19677 : 133 : return PARTITION_STRATEGY_HASH;
19678 : :
19679 [ + - ]: 3 : ereport(ERROR,
19680 : : (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
19681 : : errmsg("unrecognized partitioning strategy \"%s\"", strategy),
19682 : : parser_errposition(location)));
19683 : : return PARTITION_STRATEGY_LIST; /* keep compiler quiet */
19684 : :
19685 : : }
19686 : :
19687 : : /*
19688 : : * Process all_objects_list to set all_tables and/or all_sequences.
19689 : : * Also, checks if the pub_object_type has been specified more than once.
19690 : : */
19691 : : static void
18 akapila@postgresql.o 19692 :GNC 74 : preprocess_pub_all_objtype_list(List *all_objects_list, bool *all_tables,
19693 : : bool *all_sequences, core_yyscan_t yyscanner)
19694 : : {
19695 [ - + ]: 74 : if (!all_objects_list)
18 akapila@postgresql.o 19696 :UNC 0 : return;
19697 : :
18 akapila@postgresql.o 19698 :GNC 74 : *all_tables = false;
19699 : 74 : *all_sequences = false;
19700 : :
19701 [ + - + + : 229 : foreach_ptr(PublicationAllObjSpec, obj, all_objects_list)
+ + ]
19702 : : {
19703 [ + + ]: 93 : if (obj->pubobjtype == PUBLICATION_ALL_TABLES)
19704 : : {
19705 [ + + ]: 66 : if (*all_tables)
19706 [ + - ]: 3 : ereport(ERROR,
19707 : : errcode(ERRCODE_SYNTAX_ERROR),
19708 : : errmsg("invalid publication object list"),
19709 : : errdetail("ALL TABLES can be specified only once."),
19710 : : parser_errposition(obj->location));
19711 : :
19712 : 63 : *all_tables = true;
19713 : : }
19714 [ + - ]: 27 : else if (obj->pubobjtype == PUBLICATION_ALL_SEQUENCES)
19715 : : {
19716 [ + + ]: 27 : if (*all_sequences)
19717 [ + - ]: 3 : ereport(ERROR,
19718 : : errcode(ERRCODE_SYNTAX_ERROR),
19719 : : errmsg("invalid publication object list"),
19720 : : errdetail("ALL SEQUENCES can be specified only once."),
19721 : : parser_errposition(obj->location));
19722 : :
19723 : 24 : *all_sequences = true;
19724 : : }
19725 : : }
19726 : : }
19727 : :
19728 : : /*
19729 : : * Process pubobjspec_list to check for errors in any of the objects and
19730 : : * convert PUBLICATIONOBJ_CONTINUATION into appropriate PublicationObjSpecType.
19731 : : */
19732 : : static void
1461 akapila@postgresql.o 19733 :CBC 824 : preprocess_pubobj_list(List *pubobjspec_list, core_yyscan_t yyscanner)
19734 : : {
19735 : : ListCell *cell;
19736 : : PublicationObjSpec *pubobj;
19737 : 824 : PublicationObjSpecType prevobjtype = PUBLICATIONOBJ_CONTINUATION;
19738 : :
19739 [ - + ]: 824 : if (!pubobjspec_list)
1461 akapila@postgresql.o 19740 :UBC 0 : return;
19741 : :
1461 akapila@postgresql.o 19742 :CBC 824 : pubobj = (PublicationObjSpec *) linitial(pubobjspec_list);
19743 [ + + ]: 824 : if (pubobj->pubobjtype == PUBLICATIONOBJ_CONTINUATION)
19744 [ + - ]: 6 : ereport(ERROR,
19745 : : errcode(ERRCODE_SYNTAX_ERROR),
19746 : : errmsg("invalid publication object list"),
19747 : : errdetail("One of TABLE or TABLES IN SCHEMA must be specified before a standalone table or schema name."),
19748 : : parser_errposition(pubobj->location));
19749 : :
19750 [ + - + + : 1751 : foreach(cell, pubobjspec_list)
+ + ]
19751 : : {
19752 : 945 : pubobj = (PublicationObjSpec *) lfirst(cell);
19753 : :
19754 [ + + ]: 945 : if (pubobj->pubobjtype == PUBLICATIONOBJ_CONTINUATION)
19755 : 87 : pubobj->pubobjtype = prevobjtype;
19756 : :
1299 tomas.vondra@postgre 19757 [ + + ]: 945 : if (pubobj->pubobjtype == PUBLICATIONOBJ_TABLE)
19758 : : {
19759 : : /* relation name or pubtable must be set for this type of object */
1461 akapila@postgresql.o 19760 [ + + + + ]: 723 : if (!pubobj->name && !pubobj->pubtable)
19761 [ + - ]: 3 : ereport(ERROR,
19762 : : errcode(ERRCODE_SYNTAX_ERROR),
19763 : : errmsg("invalid table name"),
19764 : : parser_errposition(pubobj->location));
19765 : :
1343 19766 [ + + ]: 720 : if (pubobj->name)
19767 : : {
19768 : : /* convert it to PublicationTable */
1461 19769 : 29 : PublicationTable *pubtable = makeNode(PublicationTable);
19770 : :
1397 alvherre@alvh.no-ip. 19771 : 29 : pubtable->relation =
19772 : 29 : makeRangeVar(NULL, pubobj->name, pubobj->location);
1461 akapila@postgresql.o 19773 : 29 : pubobj->pubtable = pubtable;
19774 : 29 : pubobj->name = NULL;
19775 : : }
19776 : : }
1397 alvherre@alvh.no-ip. 19777 [ + + ]: 222 : else if (pubobj->pubobjtype == PUBLICATIONOBJ_TABLES_IN_SCHEMA ||
19778 [ + - ]: 12 : pubobj->pubobjtype == PUBLICATIONOBJ_TABLES_IN_CUR_SCHEMA)
19779 : : {
19780 : : /* WHERE clause is not allowed on a schema object */
1343 akapila@postgresql.o 19781 [ + + + + ]: 222 : if (pubobj->pubtable && pubobj->pubtable->whereClause)
19782 [ + - ]: 3 : ereport(ERROR,
19783 : : errcode(ERRCODE_SYNTAX_ERROR),
19784 : : errmsg("WHERE clause not allowed for schema"),
19785 : : parser_errposition(pubobj->location));
19786 : :
19787 : : /* Column list is not allowed on a schema object */
1311 tomas.vondra@postgre 19788 [ + + + + ]: 219 : if (pubobj->pubtable && pubobj->pubtable->columns)
19789 [ + - ]: 3 : ereport(ERROR,
19790 : : errcode(ERRCODE_SYNTAX_ERROR),
19791 : : errmsg("column specification not allowed for schema"),
19792 : : parser_errposition(pubobj->location));
19793 : :
19794 : : /*
19795 : : * We can distinguish between the different type of schema objects
19796 : : * based on whether name and pubtable is set.
19797 : : */
1461 akapila@postgresql.o 19798 [ + + ]: 216 : if (pubobj->name)
1397 alvherre@alvh.no-ip. 19799 : 201 : pubobj->pubobjtype = PUBLICATIONOBJ_TABLES_IN_SCHEMA;
1461 akapila@postgresql.o 19800 [ + - + + ]: 15 : else if (!pubobj->name && !pubobj->pubtable)
1397 alvherre@alvh.no-ip. 19801 : 12 : pubobj->pubobjtype = PUBLICATIONOBJ_TABLES_IN_CUR_SCHEMA;
19802 : : else
1461 akapila@postgresql.o 19803 [ + - ]: 3 : ereport(ERROR,
19804 : : errcode(ERRCODE_SYNTAX_ERROR),
19805 : : errmsg("invalid schema name"),
19806 : : parser_errposition(pubobj->location));
19807 : : }
19808 : :
19809 : 933 : prevobjtype = pubobj->pubobjtype;
19810 : : }
19811 : : }
19812 : :
19813 : : /*----------
19814 : : * Recursive view transformation
19815 : : *
19816 : : * Convert
19817 : : *
19818 : : * CREATE RECURSIVE VIEW relname (aliases) AS query
19819 : : *
19820 : : * to
19821 : : *
19822 : : * CREATE VIEW relname (aliases) AS
19823 : : * WITH RECURSIVE relname (aliases) AS (query)
19824 : : * SELECT aliases FROM relname
19825 : : *
19826 : : * Actually, just the WITH ... part, which is then inserted into the original
19827 : : * view definition as the query.
19828 : : * ----------
19829 : : */
19830 : : static Node *
4652 peter_e@gmx.net 19831 : 7 : makeRecursiveViewSelect(char *relname, List *aliases, Node *query)
19832 : : {
19833 : 7 : SelectStmt *s = makeNode(SelectStmt);
19834 : 7 : WithClause *w = makeNode(WithClause);
19835 : 7 : CommonTableExpr *cte = makeNode(CommonTableExpr);
19836 : 7 : List *tl = NIL;
19837 : : ListCell *lc;
19838 : :
19839 : : /* create common table expression */
19840 : 7 : cte->ctename = relname;
19841 : 7 : cte->aliascolnames = aliases;
2445 tgl@sss.pgh.pa.us 19842 : 7 : cte->ctematerialized = CTEMaterializeDefault;
4652 peter_e@gmx.net 19843 : 7 : cte->ctequery = query;
19844 : 7 : cte->location = -1;
19845 : :
19846 : : /* create WITH clause and attach CTE */
19847 : 7 : w->recursive = true;
19848 : 7 : w->ctes = list_make1(cte);
19849 : 7 : w->location = -1;
19850 : :
19851 : : /*
19852 : : * create target list for the new SELECT from the alias list of the
19853 : : * recursive view specification
19854 : : */
306 peter@eisentraut.org 19855 [ + - + + : 14 : foreach(lc, aliases)
+ + ]
19856 : : {
19857 : 7 : ResTarget *rt = makeNode(ResTarget);
19858 : :
4652 peter_e@gmx.net 19859 : 7 : rt->name = NULL;
19860 : 7 : rt->indirection = NIL;
19861 : 7 : rt->val = makeColumnRef(strVal(lfirst(lc)), NIL, -1, 0);
19862 : 7 : rt->location = -1;
19863 : :
19864 : 7 : tl = lappend(tl, rt);
19865 : : }
19866 : :
19867 : : /*
19868 : : * create new SELECT combining WITH clause, target list, and fake FROM
19869 : : * clause
19870 : : */
19871 : 7 : s->withClause = w;
19872 : 7 : s->targetList = tl;
19873 : 7 : s->fromClause = list_make1(makeRangeVar(NULL, relname, -1));
19874 : :
19875 : 7 : return (Node *) s;
19876 : : }
19877 : :
19878 : : /* parser_init()
19879 : : * Initialize to parse one query string
19880 : : */
19881 : : void
5346 tgl@sss.pgh.pa.us 19882 : 384540 : parser_init(base_yy_extra_type *yyext)
19883 : : {
19884 : 384540 : yyext->parsetree = NIL; /* in case grammar forgets to set it */
19885 : 384540 : }
|