4 /*-------------------------------------------------------------------------
7 * POSTGRESQL BISON rules/actions
9 * Portions Copyright (c) 1996-2015, PostgreSQL Global Development Group
10 * Portions Copyright (c) 1994, Regents of the University of California
14 * src/backend/parser/gram.y
17 * AUTHOR DATE MAJOR EVENT
18 * Andrew Yu Sept, 1994 POSTQUEL to SQL conversion
19 * Andrew Yu Oct, 1994 lispy code conversion
22 * CAPITALS are used to represent terminal symbols.
23 * non-capitals are used to represent non-terminals.
25 * In general, nothing in this file should initiate database accesses
26 * nor depend on changeable state (such as SET variables). If you do
27 * database accesses, your code will fail when we have aborted the
28 * current transaction and are just parsing commands to find the next
29 * ROLLBACK or COMMIT. If you make use of SET variables, then you
30 * will do the wrong thing in multi-query strings like this:
31 * SET SQL_inheritance 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. The handling of SQL_inheritance is
39 * If you use a list, make sure the datum is a node so that the printing
42 * Sometimes we assign constants to makeStrings. Make sure we don't free
45 *-------------------------------------------------------------------------
52 #include "catalog/index.h"
53 #include "catalog/namespace.h"
54 #include "catalog/pg_trigger.h"
55 #include "commands/defrem.h"
56 #include "commands/trigger.h"
57 #include "nodes/makefuncs.h"
58 #include "nodes/nodeFuncs.h"
59 #include "parser/gramparse.h"
60 #include "parser/parser.h"
61 #include "parser/parse_expr.h"
62 #include "storage/lmgr.h"
63 #include "utils/date.h"
64 #include "utils/datetime.h"
65 #include "utils/numeric.h"
66 #include "utils/xml.h"
70 * Location tracking support --- simpler than bison's default, since we only
71 * want to track the start position not the end position of each nonterminal.
73 #define YYLLOC_DEFAULT(Current, Rhs, N) \
76 (Current) = (Rhs)[1]; \
82 * The above macro assigns -1 (unknown) as the parse location of any
83 * nonterminal that was reduced from an empty rule. This is problematic
84 * for nonterminals defined like
85 * OptFooList: / * EMPTY * / { ... } | OptFooList Foo { ... } ;
86 * because we'll set -1 as the location during the first reduction and then
87 * copy it during each subsequent reduction, leaving us with -1 for the
88 * location even when the list is not empty. To fix that, do this in the
89 * action for the nonempty rule(s):
90 * if (@$ < 0) @$ = @2;
91 * (Although we have many nonterminals that follow this pattern, we only
92 * bother with fixing @$ like this when the nonterminal's parse location
93 * is actually referenced in some rule.)
97 * Bison doesn't allocate anything that needs to live across parser calls,
98 * so we can easily have it use palloc instead of malloc. This prevents
99 * memory leaks if we error out during parsing. Note this only works with
100 * bison >= 2.0. However, in bison 1.875 the default is to use alloca()
101 * if possible, so there's not really much problem anyhow, at least if
102 * you're building with gcc.
104 #define YYMALLOC palloc
107 /* Private struct for the result of privilege_target production */
108 typedef struct PrivTarget
110 GrantTargetType targtype;
111 GrantObjectType objtype;
115 /* Private struct for the result of import_qualification production */
116 typedef struct ImportQual
118 ImportForeignSchemaType type;
122 /* ConstraintAttributeSpec yields an integer bitmask of these flags: */
123 #define CAS_NOT_DEFERRABLE 0x01
124 #define CAS_DEFERRABLE 0x02
125 #define CAS_INITIALLY_IMMEDIATE 0x04
126 #define CAS_INITIALLY_DEFERRED 0x08
127 #define CAS_NOT_VALID 0x10
128 #define CAS_NO_INHERIT 0x20
131 #define parser_yyerror(msg) scanner_yyerror(msg, yyscanner)
132 #define parser_errposition(pos) scanner_errposition(pos, yyscanner)
134 static void base_yyerror(YYLTYPE *yylloc, core_yyscan_t yyscanner,
136 static Node *makeColumnRef(char *colname, List *indirection,
137 int location, core_yyscan_t yyscanner);
138 static Node *makeTypeCast(Node *arg, TypeName *typename, int location);
139 static Node *makeStringConst(char *str, int location);
140 static Node *makeStringConstCast(char *str, int location, TypeName *typename);
141 static Node *makeIntConst(int val, int location);
142 static Node *makeFloatConst(char *str, int location);
143 static Node *makeBitStringConst(char *str, int location);
144 static Node *makeNullAConst(int location);
145 static Node *makeAConst(Value *v, int location);
146 static Node *makeBoolAConst(bool state, int location);
147 static Node *makeRoleSpec(RoleSpecType type, int location);
148 static void check_qualified_name(List *names, core_yyscan_t yyscanner);
149 static List *check_func_name(List *names, core_yyscan_t yyscanner);
150 static List *check_indirection(List *indirection, core_yyscan_t yyscanner);
151 static List *extractArgTypes(List *parameters);
152 static List *extractAggrArgTypes(List *aggrargs);
153 static List *makeOrderedSetArgs(List *directargs, List *orderedargs,
154 core_yyscan_t yyscanner);
155 static void insertSelectOptions(SelectStmt *stmt,
156 List *sortClause, List *lockingClause,
157 Node *limitOffset, Node *limitCount,
158 WithClause *withClause,
159 core_yyscan_t yyscanner);
160 static Node *makeSetOp(SetOperation op, bool all, Node *larg, Node *rarg);
161 static Node *doNegate(Node *n, int location);
162 static void doNegateFloat(Value *v);
163 static Node *makeAndExpr(Node *lexpr, Node *rexpr, int location);
164 static Node *makeOrExpr(Node *lexpr, Node *rexpr, int location);
165 static Node *makeNotExpr(Node *expr, int location);
166 static Node *makeAArrayExpr(List *elements, int location);
167 static Node *makeXmlExpr(XmlExprOp op, char *name, List *named_args,
168 List *args, int location);
169 static List *mergeTableFuncParameters(List *func_args, List *columns);
170 static TypeName *TableFuncTypeName(List *columns);
171 static RangeVar *makeRangeVarFromAnyName(List *names, int position, core_yyscan_t yyscanner);
172 static void SplitColQualList(List *qualList,
173 List **constraintList, CollateClause **collClause,
174 core_yyscan_t yyscanner);
175 static void processCASbits(int cas_bits, int location, const char *constrType,
176 bool *deferrable, bool *initdeferred, bool *not_valid,
177 bool *no_inherit, core_yyscan_t yyscanner);
178 static Node *makeRecursiveViewSelect(char *relname, List *aliases, Node *query);
184 %name-prefix="base_yy"
187 %parse-param {core_yyscan_t yyscanner}
188 %lex-param {core_yyscan_t yyscanner}
192 core_YYSTYPE core_yystype;
193 /* these fields must match core_YYSTYPE: */
201 DropBehavior dbehavior;
202 OnCommitAction oncommit;
208 FunctionParameter *fun_param;
209 FunctionParameterMode fun_param_mode;
210 FuncWithArgs *funwithargs;
221 OnConflictClause *onconflict;
224 struct PrivTarget *privtarget;
225 AccessPriv *accesspriv;
226 struct ImportQual *importqual;
228 VariableSetStmt *vsetstmt;
231 %type <node> stmt schema_stmt
233 AlterDatabaseStmt AlterDatabaseSetStmt AlterDomainStmt AlterEnumStmt
234 AlterFdwStmt AlterForeignServerStmt AlterGroupStmt
235 AlterObjectSchemaStmt AlterOwnerStmt AlterOperatorStmt AlterSeqStmt AlterSystemStmt AlterTableStmt
236 AlterTblSpcStmt AlterExtensionStmt AlterExtensionContentsStmt AlterForeignTableStmt
237 AlterCompositeTypeStmt AlterUserStmt AlterUserMappingStmt AlterUserSetStmt
238 AlterRoleStmt AlterRoleSetStmt AlterPolicyStmt
239 AlterDefaultPrivilegesStmt DefACLAction
240 AnalyzeStmt ClosePortalStmt ClusterStmt CommentStmt
241 ConstraintsSetStmt CopyStmt CreateAsStmt CreateCastStmt
242 CreateDomainStmt CreateExtensionStmt CreateGroupStmt CreateOpClassStmt
243 CreateOpFamilyStmt AlterOpFamilyStmt CreatePLangStmt
244 CreateSchemaStmt CreateSeqStmt CreateStmt CreateTableSpaceStmt
245 CreateFdwStmt CreateForeignServerStmt CreateForeignTableStmt
246 CreateAssertStmt CreateTransformStmt CreateTrigStmt CreateEventTrigStmt
247 CreateUserStmt CreateUserMappingStmt CreateRoleStmt CreatePolicyStmt
248 CreatedbStmt DeclareCursorStmt DefineStmt DeleteStmt DiscardStmt DoStmt
249 DropGroupStmt DropOpClassStmt DropOpFamilyStmt DropPLangStmt DropStmt
250 DropAssertStmt DropTrigStmt DropRuleStmt DropCastStmt DropRoleStmt
251 DropPolicyStmt DropUserStmt DropdbStmt DropTableSpaceStmt DropFdwStmt
253 DropForeignServerStmt DropUserMappingStmt ExplainStmt FetchStmt
254 GrantStmt GrantRoleStmt ImportForeignSchemaStmt IndexStmt InsertStmt
255 ListenStmt LoadStmt LockStmt NotifyStmt ExplainableStmt PreparableStmt
256 CreateFunctionStmt AlterFunctionStmt ReindexStmt RemoveAggrStmt
257 RemoveFuncStmt RemoveOperStmt RenameStmt RevokeStmt RevokeRoleStmt
258 RuleActionStmt RuleActionStmtOrEmpty RuleStmt
259 SecLabelStmt SelectStmt TransactionStmt TruncateStmt
260 UnlistenStmt UpdateStmt VacuumStmt
261 VariableResetStmt VariableSetStmt VariableShowStmt
262 ViewStmt CheckPointStmt CreateConversionStmt
263 DeallocateStmt PrepareStmt ExecuteStmt
264 DropOwnedStmt ReassignOwnedStmt
265 AlterTSConfigurationStmt AlterTSDictionaryStmt
266 CreateMatViewStmt RefreshMatViewStmt
268 %type <node> select_no_parens select_with_parens select_clause
269 simple_select values_clause
271 %type <node> alter_column_default opclass_item opclass_drop alter_using
272 %type <ival> add_drop opt_asc_desc opt_nulls_order
274 %type <node> alter_table_cmd alter_type_cmd opt_collate_clause
276 %type <list> alter_table_cmds alter_type_cmds
278 %type <dbehavior> opt_drop_behavior
280 %type <list> createdb_opt_list createdb_opt_items copy_opt_list
281 transaction_mode_list
282 create_extension_opt_list alter_extension_opt_list
283 %type <defelt> createdb_opt_item copy_opt_item
284 transaction_mode_item
285 create_extension_opt_item alter_extension_opt_item
287 %type <ival> opt_lock lock_type cast_context
288 %type <ival> vacuum_option_list vacuum_option_elem
289 %type <boolean> opt_or_replace
290 opt_grant_grant_option opt_grant_admin_option
291 opt_nowait opt_if_exists opt_with_data
292 %type <ival> opt_nowait_or_skip
294 %type <list> OptRoleList AlterOptRoleList
295 %type <defelt> CreateOptRoleElem AlterOptRoleElem
298 %type <str> foreign_server_version opt_foreign_server_version
299 %type <str> opt_in_database
301 %type <str> OptSchemaName
302 %type <list> OptSchemaEltList
304 %type <boolean> TriggerForSpec TriggerForType
305 %type <ival> TriggerActionTime
306 %type <list> TriggerEvents TriggerOneEvent
307 %type <value> TriggerFuncArg
308 %type <node> TriggerWhen
310 %type <list> event_trigger_when_list event_trigger_value_list
311 %type <defelt> event_trigger_when_item
312 %type <chr> enable_trigger
314 %type <str> copy_file_name
315 database_name access_method_clause access_method attr_name
316 name cursor_name file_name
317 index_name opt_index_name cluster_index_specification
319 %type <list> func_name handler_name qual_Op qual_all_Op subquery_Op
320 opt_class opt_inline_handler opt_validator validator_clause
323 %type <range> qualified_name insert_target OptConstrFromTable
325 %type <str> all_Op MathOp
327 %type <str> row_security_cmd RowSecurityDefaultForCmd
328 %type <node> RowSecurityOptionalWithCheck RowSecurityOptionalExpr
329 %type <list> RowSecurityDefaultToRole RowSecurityOptionalToRole
331 %type <str> iso_level opt_encoding
333 %type <list> grantee_list
334 %type <accesspriv> privilege
335 %type <list> privileges privilege_list
336 %type <privtarget> privilege_target
337 %type <funwithargs> function_with_argtypes
338 %type <list> function_with_argtypes_list
339 %type <ival> defacl_privilege_target
340 %type <defelt> DefACLOption
341 %type <list> DefACLOptionList
342 %type <ival> import_qualification_type
343 %type <importqual> import_qualification
345 %type <list> stmtblock stmtmulti
346 OptTableElementList TableElementList OptInherit definition
347 OptTypedTableElementList TypedTableElementList
348 reloptions opt_reloptions
349 OptWith distinct_clause opt_all_clause opt_definition func_args func_args_list
350 func_args_with_defaults func_args_with_defaults_list
351 aggr_args aggr_args_list
352 func_as createfunc_opt_list alterfunc_opt_list
353 old_aggr_definition old_aggr_list
354 oper_argtypes RuleActionList RuleActionMulti
355 opt_column_list columnList opt_name_list
356 sort_clause opt_sort_clause sortby_list index_params
357 name_list role_list from_clause from_list opt_array_bounds
358 qualified_name_list any_name any_name_list type_name_list
359 any_operator expr_list attrs
360 target_list opt_target_list insert_column_list set_target_list
361 set_clause_list set_clause multiple_set_clause
362 ctext_expr_list ctext_row def_list operator_def_list indirection opt_indirection
363 reloption_list group_clause TriggerFuncArgs select_limit
364 opt_select_limit opclass_item_list opclass_drop_list
365 opclass_purpose opt_opfamily transaction_mode_list_or_empty
366 OptTableFuncElementList TableFuncElementList opt_type_modifiers
368 execute_param_clause using_clause returning_clause
369 opt_enum_val_list enum_val_list table_func_column_list
370 create_generic_options alter_generic_options
371 relation_expr_list dostmt_opt_list
372 transform_element_list transform_type_list
374 %type <list> group_by_list
375 %type <node> group_by_item empty_grouping_set rollup_clause cube_clause
376 %type <node> grouping_sets_clause
378 %type <list> opt_fdw_options fdw_options
379 %type <defelt> fdw_option
381 %type <range> OptTempTableName
382 %type <into> into_clause create_as_target create_mv_target
384 %type <defelt> createfunc_opt_item common_func_opt_item dostmt_opt_item
385 %type <fun_param> func_arg func_arg_with_default table_func_column aggr_arg
386 %type <fun_param_mode> arg_class
387 %type <typnam> func_return func_type
389 %type <boolean> opt_trusted opt_restart_seqs
391 %type <ival> OptNoLog
392 %type <oncommit> OnCommitOption
394 %type <ival> for_locking_strength
395 %type <node> for_locking_item
396 %type <list> for_locking_clause opt_for_locking_clause for_locking_items
397 %type <list> locked_rels_list
398 %type <boolean> all_or_distinct
400 %type <node> join_outer join_qual
401 %type <jtype> join_type
403 %type <list> extract_list overlay_list position_list
404 %type <list> substr_list trim_list
405 %type <list> opt_interval interval_second
406 %type <node> overlay_placing substr_from substr_for
408 %type <boolean> opt_instead
409 %type <boolean> opt_unique opt_concurrently opt_verbose opt_full
410 %type <boolean> opt_freeze opt_default opt_recheck
411 %type <defelt> opt_binary opt_oids copy_delimiter
413 %type <boolean> copy_from opt_program
415 %type <ival> opt_column event cursor_options opt_hold opt_set_data
416 %type <objtype> drop_type comment_type security_label_type
418 %type <node> fetch_args limit_clause select_limit_value
419 offset_clause select_offset_value
420 select_offset_value2 opt_select_fetch_first_value
421 %type <ival> row_or_rows first_or_next
423 %type <list> OptSeqOptList SeqOptList
424 %type <defelt> SeqOptElem
426 %type <istmt> insert_rest
427 %type <infer> opt_conf_expr
428 %type <onconflict> opt_on_conflict
430 %type <vsetstmt> generic_set set_rest set_rest_more generic_reset reset_rest
431 SetResetClause FunctionSetResetClause
433 %type <node> TableElement TypedTableElement ConstraintElem TableFuncElement
434 %type <node> columnDef columnOptions
435 %type <defelt> def_elem reloption_elem old_aggr_elem operator_def_elem
436 %type <node> def_arg columnElem where_clause where_or_current_clause
437 a_expr b_expr c_expr AexprConst indirection_el
438 columnref in_expr having_clause func_table array_expr
440 %type <list> rowsfrom_item rowsfrom_list opt_col_def_list
441 %type <boolean> opt_ordinality
442 %type <list> ExclusionConstraintList ExclusionConstraintElem
443 %type <list> func_arg_list
444 %type <node> func_arg_expr
445 %type <list> row explicit_row implicit_row type_list array_expr_list
446 %type <node> case_expr case_arg when_clause case_default
447 %type <list> when_clause_list
448 %type <ival> sub_type
449 %type <node> ctext_expr
450 %type <value> NumericOnly
451 %type <list> NumericOnly_list
452 %type <alias> alias_clause opt_alias_clause
453 %type <list> func_alias_clause
454 %type <sortby> sortby
455 %type <ielem> index_elem
456 %type <node> table_ref
457 %type <jexpr> joined_table
458 %type <range> relation_expr
459 %type <range> relation_expr_opt_alias
460 %type <node> tablesample_clause opt_repeatable_clause
461 %type <target> target_el single_set_clause set_target insert_column_item
463 %type <str> generic_option_name
464 %type <node> generic_option_arg
465 %type <defelt> generic_option_elem alter_generic_option_elem
466 %type <list> generic_option_list alter_generic_option_list
467 %type <str> explain_option_name
468 %type <node> explain_option_arg
469 %type <defelt> explain_option_elem
470 %type <list> explain_option_list
472 %type <ival> reindex_target_type reindex_target_multitable
473 %type <ival> reindex_option_list reindex_option_elem
475 %type <node> copy_generic_opt_arg copy_generic_opt_arg_list_item
476 %type <defelt> copy_generic_opt_elem
477 %type <list> copy_generic_opt_list copy_generic_opt_arg_list
478 %type <list> copy_options
480 %type <typnam> Typename SimpleTypename ConstTypename
481 GenericType Numeric opt_float
482 Character ConstCharacter
483 CharacterWithLength CharacterWithoutLength
484 ConstDatetime ConstInterval
485 Bit ConstBit BitWithLength BitWithoutLength
486 %type <str> character
487 %type <str> extract_arg
488 %type <str> opt_charset
489 %type <boolean> opt_varying opt_timezone opt_no_inherit
491 %type <ival> Iconst SignedIconst
492 %type <str> Sconst comment_text notify_payload
493 %type <str> RoleId opt_boolean_or_string
494 %type <list> var_list
495 %type <str> ColId ColLabel var_name type_function_name param_name
496 %type <str> NonReservedWord NonReservedWord_or_Sconst
497 %type <str> createdb_opt_name
498 %type <node> var_value zone_value
499 %type <node> auth_ident RoleSpec opt_granted_by
501 %type <keyword> unreserved_keyword type_func_name_keyword
502 %type <keyword> col_name_keyword reserved_keyword
504 %type <node> TableConstraint TableLikeClause
505 %type <ival> TableLikeOptionList TableLikeOption
506 %type <list> ColQualList
507 %type <node> ColConstraint ColConstraintElem ConstraintAttr
508 %type <ival> key_actions key_delete key_match key_update key_action
509 %type <ival> ConstraintAttributeSpec ConstraintAttributeElem
510 %type <str> ExistingIndex
512 %type <list> constraints_set_list
513 %type <boolean> constraints_set_mode
514 %type <str> OptTableSpace OptConsTableSpace
515 %type <node> OptTableSpaceOwner
516 %type <ival> opt_check_option
518 %type <str> opt_provider security_label
520 %type <target> xml_attribute_el
521 %type <list> xml_attribute_list xml_attributes
522 %type <node> xml_root_version opt_xml_root_standalone
523 %type <node> xmlexists_argument
524 %type <ival> document_or_content
525 %type <boolean> xml_whitespace_option
527 %type <node> func_application func_expr_common_subexpr
528 %type <node> func_expr func_expr_windowless
529 %type <node> common_table_expr
530 %type <with> with_clause opt_with_clause
531 %type <list> cte_list
533 %type <list> within_group_clause
534 %type <node> filter_clause
535 %type <list> window_clause window_definition_list opt_partition_clause
536 %type <windef> window_definition over_clause window_specification
537 opt_frame_clause frame_extent frame_bound
538 %type <str> opt_existing_window_name
539 %type <boolean> opt_if_not_exists
542 * Non-keyword token types. These are hard-wired into the "flex" lexer.
543 * They must be listed first so that their numeric codes do not depend on
544 * the set of keywords. PL/pgsql depends on this so that it can share the
545 * same lexer. If you add/change tokens here, fix PL/pgsql to match!
547 * DOT_DOT is unused in the core SQL grammar, and so will always provoke
548 * parse errors. It is needed by PL/pgsql.
550 %token <str> IDENT FCONST SCONST BCONST XCONST Op
551 %token <ival> ICONST PARAM
552 %token TYPECAST DOT_DOT COLON_EQUALS EQUALS_GREATER
553 %token LESS_EQUALS GREATER_EQUALS NOT_EQUALS
556 * If you want to make any keyword changes, update the keyword table in
557 * src/include/parser/kwlist.h and add new keywords to the appropriate one
558 * of the reserved-or-not-so-reserved keyword lists, below; search
559 * this file for "Keyword category lists".
562 /* ordinary key words in alphabetical order */
563 %token <keyword> ABORT_P ABSOLUTE_P ACCESS ACTION ADD_P ADMIN AFTER
564 AGGREGATE ALL ALSO ALTER ALWAYS ANALYSE ANALYZE AND ANY ARRAY AS ASC
565 ASSERTION ASSIGNMENT ASYMMETRIC AT ATTRIBUTE AUTHORIZATION
567 BACKWARD BEFORE BEGIN_P BETWEEN BIGINT BINARY BIT
570 CACHE CALLED CASCADE CASCADED CASE CAST CATALOG_P CHAIN CHAR_P
571 CHARACTER CHARACTERISTICS CHECK CHECKPOINT CLASS CLOSE
572 CLUSTER COALESCE COLLATE COLLATION COLUMN COMMENT COMMENTS COMMIT
573 COMMITTED CONCURRENTLY CONFIGURATION CONFLICT CONNECTION CONSTRAINT
574 CONSTRAINTS CONTENT_P CONTINUE_P CONVERSION_P COPY COST CREATE
575 CROSS CSV CUBE CURRENT_P
576 CURRENT_CATALOG CURRENT_DATE CURRENT_ROLE CURRENT_SCHEMA
577 CURRENT_TIME CURRENT_TIMESTAMP CURRENT_USER CURSOR CYCLE
579 DATA_P DATABASE DAY_P DEALLOCATE DEC DECIMAL_P DECLARE DEFAULT DEFAULTS
580 DEFERRABLE DEFERRED DEFINER DELETE_P DELIMITER DELIMITERS DESC
581 DICTIONARY DISABLE_P DISCARD DISTINCT DO DOCUMENT_P DOMAIN_P DOUBLE_P DROP
583 EACH ELSE ENABLE_P ENCODING ENCRYPTED END_P ENUM_P ESCAPE EVENT EXCEPT
584 EXCLUDE EXCLUDING EXCLUSIVE EXECUTE EXISTS EXPLAIN
585 EXTENSION EXTERNAL EXTRACT
587 FALSE_P FAMILY FETCH FILTER FIRST_P FLOAT_P FOLLOWING FOR
588 FORCE FOREIGN FORWARD FREEZE FROM FULL FUNCTION FUNCTIONS
590 GLOBAL GRANT GRANTED GREATEST GROUP_P GROUPING
592 HANDLER HAVING HEADER_P HOLD HOUR_P
594 IDENTITY_P IF_P ILIKE IMMEDIATE IMMUTABLE IMPLICIT_P IMPORT_P IN_P
595 INCLUDING INCREMENT INDEX INDEXES INHERIT INHERITS INITIALLY INLINE_P
596 INNER_P INOUT INPUT_P INSENSITIVE INSERT INSTEAD INT_P INTEGER
597 INTERSECT INTERVAL INTO INVOKER IS ISNULL ISOLATION
603 LABEL LANGUAGE LARGE_P LAST_P LATERAL_P
604 LEADING LEAKPROOF LEAST LEFT LEVEL LIKE LIMIT LISTEN LOAD LOCAL
605 LOCALTIME LOCALTIMESTAMP LOCATION LOCK_P LOCKED LOGGED
607 MAPPING MATCH MATERIALIZED MAXVALUE MINUTE_P MINVALUE MODE MONTH_P MOVE
609 NAME_P NAMES NATIONAL NATURAL NCHAR NEXT NO NONE
610 NOT NOTHING NOTIFY NOTNULL NOWAIT NULL_P NULLIF
613 OBJECT_P OF OFF OFFSET OIDS ON ONLY OPERATOR OPTION OPTIONS OR
614 ORDER ORDINALITY OUT_P OUTER_P OVER OVERLAPS OVERLAY OWNED OWNER
616 PARALLEL PARSER PARTIAL PARTITION PASSING PASSWORD PLACING PLANS POLICY
617 POSITION PRECEDING PRECISION PRESERVE PREPARE PREPARED PRIMARY
618 PRIOR PRIVILEGES PROCEDURAL PROCEDURE PROGRAM
622 RANGE READ REAL REASSIGN RECHECK RECURSIVE REF REFERENCES REFRESH REINDEX
623 RELATIVE_P RELEASE RENAME REPEATABLE REPLACE REPLICA
624 RESET RESTART RESTRICT RETURNING RETURNS REVOKE RIGHT ROLE ROLLBACK ROLLUP
627 SAVEPOINT SCHEMA SCROLL SEARCH SECOND_P SECURITY SELECT SEQUENCE SEQUENCES
628 SERIALIZABLE SERVER SESSION SESSION_USER SET SETS SETOF SHARE SHOW
629 SIMILAR SIMPLE SKIP SMALLINT SNAPSHOT SOME SQL_P STABLE STANDALONE_P START
630 STATEMENT STATISTICS STDIN STDOUT STORAGE STRICT_P STRIP_P SUBSTRING
631 SYMMETRIC SYSID SYSTEM_P
633 TABLE TABLES TABLESAMPLE TABLESPACE TEMP TEMPLATE TEMPORARY TEXT_P THEN
634 TIME TIMESTAMP TO TRAILING TRANSACTION TRANSFORM TREAT TRIGGER TRIM TRUE_P
635 TRUNCATE TRUSTED TYPE_P TYPES_P
637 UNBOUNDED UNCOMMITTED UNENCRYPTED UNION UNIQUE UNKNOWN UNLISTEN UNLOGGED
638 UNTIL UPDATE USER USING
640 VACUUM VALID VALIDATE VALIDATOR VALUE_P VALUES VARCHAR VARIADIC VARYING
641 VERBOSE VERSION_P VIEW VIEWS VOLATILE
643 WHEN WHERE WHITESPACE_P WINDOW WITH WITHIN WITHOUT WORK WRAPPER WRITE
645 XML_P XMLATTRIBUTES XMLCONCAT XMLELEMENT XMLEXISTS XMLFOREST XMLPARSE
646 XMLPI XMLROOT XMLSERIALIZE
653 * The grammar thinks these are keywords, but they are not in the kwlist.h
654 * list and so can never be entered directly. The filter in parser.c
655 * creates these tokens when required (based on looking one token ahead).
657 * NOT_LA exists so that productions such as NOT LIKE can be given the same
658 * precedence as LIKE; otherwise they'd effectively have the same precedence
659 * as NOT, at least with respect to their left-hand subexpression.
660 * NULLS_LA and WITH_LA are needed to make the grammar LALR(1).
662 %token NOT_LA NULLS_LA WITH_LA
665 /* Precedence: lowest to highest */
666 %nonassoc SET /* see relation_expr_opt_alias */
672 %nonassoc IS ISNULL NOTNULL /* IS sets precedence for IS NULL, etc */
673 %nonassoc '<' '>' '=' LESS_EQUALS GREATER_EQUALS NOT_EQUALS
674 %nonassoc BETWEEN IN_P LIKE ILIKE SIMILAR NOT_LA
675 %nonassoc ESCAPE /* ESCAPE must be just above LIKE/ILIKE/SIMILAR */
676 %left POSTFIXOP /* dummy for postfix Op rules */
678 * To support target_el without AS, we must give IDENT an explicit priority
679 * between POSTFIXOP and Op. We can safely assign the same priority to
680 * various unreserved keywords as needed to resolve ambiguities (this can't
681 * have any bad effects since obviously the keywords will still behave the
682 * same as if they weren't keywords). We need to do this for PARTITION,
683 * RANGE, ROWS to support opt_existing_window_name; and for RANGE, ROWS
684 * so that they can follow a_expr without creating postfix-operator problems;
685 * and for NULL so that it can follow b_expr in ColQualList without creating
686 * postfix-operator problems.
688 * To support CUBE and ROLLUP in GROUP BY without reserving them, we give them
689 * an explicit priority lower than '(', so that a rule with CUBE '(' will shift
690 * rather than reducing a conflicting rule that takes CUBE as a function name.
691 * Using the same precedence as IDENT seems right for the reasons given above.
693 * The frame_bound productions UNBOUNDED PRECEDING and UNBOUNDED FOLLOWING
694 * are even messier: since UNBOUNDED is an unreserved keyword (per spec!),
695 * there is no principled way to distinguish these from the productions
696 * a_expr PRECEDING/FOLLOWING. We hack this up by giving UNBOUNDED slightly
697 * lower precedence than PRECEDING and FOLLOWING. At present this doesn't
698 * appear to cause UNBOUNDED to be treated differently from other unreserved
699 * keywords anywhere else in the grammar, but it's definitely risky. We can
700 * blame any funny behavior of UNBOUNDED on the SQL standard, though.
702 %nonassoc UNBOUNDED /* ideally should have same precedence as IDENT */
703 %nonassoc IDENT NULL_P PARTITION RANGE ROWS PRECEDING FOLLOWING CUBE ROLLUP
704 %left Op OPERATOR /* multi-character ops and user-defined operators */
708 /* Unary Operators */
709 %left AT /* sets precedence for AT TIME ZONE */
717 * These might seem to be low-precedence, but actually they are not part
718 * of the arithmetic hierarchy at all in their use as JOIN operators.
719 * We make them high-precedence to support their use as function names.
720 * They wouldn't be given a precedence at all, were it not that we need
721 * left-associativity among the JOIN rules themselves.
723 %left JOIN CROSS LEFT FULL RIGHT INNER_P NATURAL
724 /* kluge to keep xml_whitespace_option from causing shift/reduce conflicts */
725 %right PRESERVE STRIP_P
730 * The target production for the whole parse.
734 pg_yyget_extra(yyscanner)->parsetree = $1;
738 /* the thrashing around here is to discard "empty" statements... */
739 stmtmulti: stmtmulti ';' stmt
742 $$ = lappend($1, $3);
758 | AlterDatabaseSetStmt
759 | AlterDefaultPrivilegesStmt
763 | AlterExtensionContentsStmt
765 | AlterForeignServerStmt
766 | AlterForeignTableStmt
769 | AlterObjectSchemaStmt
777 | AlterCompositeTypeStmt
780 | AlterTSConfigurationStmt
781 | AlterTSDictionaryStmt
782 | AlterUserMappingStmt
795 | CreateConversionStmt
797 | CreateExtensionStmt
799 | CreateForeignServerStmt
800 | CreateForeignTableStmt
812 | CreateTableSpaceStmt
813 | CreateTransformStmt
815 | CreateEventTrigStmt
818 | CreateUserMappingStmt
829 | DropForeignServerStmt
843 | DropUserMappingStmt
850 | ImportForeignSchemaStmt
883 /*****************************************************************************
885 * Create a new Postgres DBMS role
887 *****************************************************************************/
890 CREATE ROLE RoleId opt_with OptRoleList
892 CreateRoleStmt *n = makeNode(CreateRoleStmt);
893 n->stmt_type = ROLESTMT_ROLE;
907 * Options for CREATE ROLE and ALTER ROLE (also used by CREATE/ALTER USER
908 * for backwards compatibility). Note: the only option required by SQL99
909 * is "WITH ADMIN name".
912 OptRoleList CreateOptRoleElem { $$ = lappend($1, $2); }
913 | /* EMPTY */ { $$ = NIL; }
917 AlterOptRoleList AlterOptRoleElem { $$ = lappend($1, $2); }
918 | /* EMPTY */ { $$ = NIL; }
924 $$ = makeDefElem("password",
925 (Node *)makeString($2));
929 $$ = makeDefElem("password", NULL);
931 | ENCRYPTED PASSWORD Sconst
933 $$ = makeDefElem("encryptedPassword",
934 (Node *)makeString($3));
936 | UNENCRYPTED PASSWORD Sconst
938 $$ = makeDefElem("unencryptedPassword",
939 (Node *)makeString($3));
943 $$ = makeDefElem("inherit", (Node *)makeInteger(TRUE));
945 | CONNECTION LIMIT SignedIconst
947 $$ = makeDefElem("connectionlimit", (Node *)makeInteger($3));
951 $$ = makeDefElem("validUntil", (Node *)makeString($3));
953 /* Supported but not documented for roles, for use by ALTER GROUP. */
956 $$ = makeDefElem("rolemembers", (Node *)$2);
961 * We handle identifiers that aren't parser keywords with
962 * the following special-case codes, to avoid bloating the
963 * size of the main parser.
965 if (strcmp($1, "superuser") == 0)
966 $$ = makeDefElem("superuser", (Node *)makeInteger(TRUE));
967 else if (strcmp($1, "nosuperuser") == 0)
968 $$ = makeDefElem("superuser", (Node *)makeInteger(FALSE));
969 else if (strcmp($1, "createuser") == 0)
971 /* For backwards compatibility, synonym for SUPERUSER */
972 $$ = makeDefElem("superuser", (Node *)makeInteger(TRUE));
974 else if (strcmp($1, "nocreateuser") == 0)
976 /* For backwards compatibility, synonym for SUPERUSER */
977 $$ = makeDefElem("superuser", (Node *)makeInteger(FALSE));
979 else if (strcmp($1, "createrole") == 0)
980 $$ = makeDefElem("createrole", (Node *)makeInteger(TRUE));
981 else if (strcmp($1, "nocreaterole") == 0)
982 $$ = makeDefElem("createrole", (Node *)makeInteger(FALSE));
983 else if (strcmp($1, "replication") == 0)
984 $$ = makeDefElem("isreplication", (Node *)makeInteger(TRUE));
985 else if (strcmp($1, "noreplication") == 0)
986 $$ = makeDefElem("isreplication", (Node *)makeInteger(FALSE));
987 else if (strcmp($1, "createdb") == 0)
988 $$ = makeDefElem("createdb", (Node *)makeInteger(TRUE));
989 else if (strcmp($1, "nocreatedb") == 0)
990 $$ = makeDefElem("createdb", (Node *)makeInteger(FALSE));
991 else if (strcmp($1, "login") == 0)
992 $$ = makeDefElem("canlogin", (Node *)makeInteger(TRUE));
993 else if (strcmp($1, "nologin") == 0)
994 $$ = makeDefElem("canlogin", (Node *)makeInteger(FALSE));
995 else if (strcmp($1, "bypassrls") == 0)
996 $$ = makeDefElem("bypassrls", (Node *)makeInteger(TRUE));
997 else if (strcmp($1, "nobypassrls") == 0)
998 $$ = makeDefElem("bypassrls", (Node *)makeInteger(FALSE));
999 else if (strcmp($1, "noinherit") == 0)
1002 * Note that INHERIT is a keyword, so it's handled by main parser, but
1003 * NOINHERIT is handled here.
1005 $$ = makeDefElem("inherit", (Node *)makeInteger(FALSE));
1009 (errcode(ERRCODE_SYNTAX_ERROR),
1010 errmsg("unrecognized role option \"%s\"", $1),
1011 parser_errposition(@1)));
1016 AlterOptRoleElem { $$ = $1; }
1017 /* The following are not supported by ALTER ROLE/USER/GROUP */
1020 $$ = makeDefElem("sysid", (Node *)makeInteger($2));
1024 $$ = makeDefElem("adminmembers", (Node *)$2);
1028 $$ = makeDefElem("rolemembers", (Node *)$2);
1030 | IN_P ROLE role_list
1032 $$ = makeDefElem("addroleto", (Node *)$3);
1034 | IN_P GROUP_P role_list
1036 $$ = makeDefElem("addroleto", (Node *)$3);
1041 /*****************************************************************************
1043 * Create a new Postgres DBMS user (role with implied login ability)
1045 *****************************************************************************/
1048 CREATE USER RoleId opt_with OptRoleList
1050 CreateRoleStmt *n = makeNode(CreateRoleStmt);
1051 n->stmt_type = ROLESTMT_USER;
1059 /*****************************************************************************
1061 * Alter a postgresql DBMS role
1063 *****************************************************************************/
1066 ALTER ROLE RoleSpec opt_with AlterOptRoleList
1068 AlterRoleStmt *n = makeNode(AlterRoleStmt);
1070 n->action = +1; /* add, if there are members */
1077 /* EMPTY */ { $$ = NULL; }
1078 | IN_P DATABASE database_name { $$ = $3; }
1082 ALTER ROLE RoleSpec opt_in_database SetResetClause
1084 AlterRoleSetStmt *n = makeNode(AlterRoleSetStmt);
1090 | ALTER ROLE ALL opt_in_database SetResetClause
1092 AlterRoleSetStmt *n = makeNode(AlterRoleSetStmt);
1101 /*****************************************************************************
1103 * Alter a postgresql DBMS user
1105 *****************************************************************************/
1108 ALTER USER RoleSpec opt_with AlterOptRoleList
1110 AlterRoleStmt *n = makeNode(AlterRoleStmt);
1112 n->action = +1; /* add, if there are members */
1120 ALTER USER RoleSpec SetResetClause
1122 AlterRoleSetStmt *n = makeNode(AlterRoleSetStmt);
1131 /*****************************************************************************
1133 * Drop a postgresql DBMS role
1135 * XXX Ideally this would have CASCADE/RESTRICT options, but since a role
1136 * might own objects in multiple databases, there is presently no way to
1137 * implement either cascading or restricting. Caveat DBA.
1138 *****************************************************************************/
1143 DropRoleStmt *n = makeNode(DropRoleStmt);
1144 n->missing_ok = FALSE;
1148 | DROP ROLE IF_P EXISTS role_list
1150 DropRoleStmt *n = makeNode(DropRoleStmt);
1151 n->missing_ok = TRUE;
1157 /*****************************************************************************
1159 * Drop a postgresql DBMS user
1161 * XXX Ideally this would have CASCADE/RESTRICT options, but since a user
1162 * might own objects in multiple databases, there is presently no way to
1163 * implement either cascading or restricting. Caveat DBA.
1164 *****************************************************************************/
1169 DropRoleStmt *n = makeNode(DropRoleStmt);
1170 n->missing_ok = FALSE;
1174 | DROP USER IF_P EXISTS role_list
1176 DropRoleStmt *n = makeNode(DropRoleStmt);
1178 n->missing_ok = TRUE;
1184 /*****************************************************************************
1186 * Create a postgresql group (role without login ability)
1188 *****************************************************************************/
1191 CREATE GROUP_P RoleId opt_with OptRoleList
1193 CreateRoleStmt *n = makeNode(CreateRoleStmt);
1194 n->stmt_type = ROLESTMT_GROUP;
1202 /*****************************************************************************
1204 * Alter a postgresql group
1206 *****************************************************************************/
1209 ALTER GROUP_P RoleSpec add_drop USER role_list
1211 AlterRoleStmt *n = makeNode(AlterRoleStmt);
1214 n->options = list_make1(makeDefElem("rolemembers",
1220 add_drop: ADD_P { $$ = +1; }
1225 /*****************************************************************************
1227 * Drop a postgresql group
1229 * XXX see above notes about cascading DROP USER; groups have same problem.
1230 *****************************************************************************/
1233 DROP GROUP_P role_list
1235 DropRoleStmt *n = makeNode(DropRoleStmt);
1236 n->missing_ok = FALSE;
1240 | DROP GROUP_P IF_P EXISTS role_list
1242 DropRoleStmt *n = makeNode(DropRoleStmt);
1243 n->missing_ok = TRUE;
1250 /*****************************************************************************
1252 * Manipulate a schema
1254 *****************************************************************************/
1257 CREATE SCHEMA OptSchemaName AUTHORIZATION RoleSpec OptSchemaEltList
1259 CreateSchemaStmt *n = makeNode(CreateSchemaStmt);
1260 /* One can omit the schema name or the authorization id. */
1264 n->if_not_exists = false;
1267 | CREATE SCHEMA ColId OptSchemaEltList
1269 CreateSchemaStmt *n = makeNode(CreateSchemaStmt);
1270 /* ...but not both */
1274 n->if_not_exists = false;
1277 | CREATE SCHEMA IF_P NOT EXISTS OptSchemaName AUTHORIZATION RoleSpec OptSchemaEltList
1279 CreateSchemaStmt *n = makeNode(CreateSchemaStmt);
1280 /* schema name can be omitted here, too */
1285 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
1286 errmsg("CREATE SCHEMA IF NOT EXISTS cannot include schema elements"),
1287 parser_errposition(@9)));
1289 n->if_not_exists = true;
1292 | CREATE SCHEMA IF_P NOT EXISTS ColId OptSchemaEltList
1294 CreateSchemaStmt *n = makeNode(CreateSchemaStmt);
1295 /* ...but not here */
1300 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
1301 errmsg("CREATE SCHEMA IF NOT EXISTS cannot include schema elements"),
1302 parser_errposition(@7)));
1304 n->if_not_exists = true;
1311 | /* EMPTY */ { $$ = NULL; }
1315 OptSchemaEltList schema_stmt
1317 if (@$ < 0) /* see comments for YYLLOC_DEFAULT */
1319 $$ = lappend($1, $2);
1326 * schema_stmt are the ones that can show up inside a CREATE SCHEMA
1327 * statement (in addition to by themselves).
1339 /*****************************************************************************
1341 * Set PG internal variable
1342 * SET name TO 'var_value'
1343 * Include SQL syntax (thomas 1997-10-22):
1344 * SET TIME ZONE 'var_value'
1346 *****************************************************************************/
1351 VariableSetStmt *n = $2;
1352 n->is_local = false;
1355 | SET LOCAL set_rest
1357 VariableSetStmt *n = $3;
1361 | SET SESSION set_rest
1363 VariableSetStmt *n = $3;
1364 n->is_local = false;
1370 TRANSACTION transaction_mode_list
1372 VariableSetStmt *n = makeNode(VariableSetStmt);
1373 n->kind = VAR_SET_MULTI;
1374 n->name = "TRANSACTION";
1378 | SESSION CHARACTERISTICS AS TRANSACTION transaction_mode_list
1380 VariableSetStmt *n = makeNode(VariableSetStmt);
1381 n->kind = VAR_SET_MULTI;
1382 n->name = "SESSION CHARACTERISTICS";
1390 var_name TO var_list
1392 VariableSetStmt *n = makeNode(VariableSetStmt);
1393 n->kind = VAR_SET_VALUE;
1398 | var_name '=' var_list
1400 VariableSetStmt *n = makeNode(VariableSetStmt);
1401 n->kind = VAR_SET_VALUE;
1406 | var_name TO DEFAULT
1408 VariableSetStmt *n = makeNode(VariableSetStmt);
1409 n->kind = VAR_SET_DEFAULT;
1413 | var_name '=' DEFAULT
1415 VariableSetStmt *n = makeNode(VariableSetStmt);
1416 n->kind = VAR_SET_DEFAULT;
1421 set_rest_more: /* Generic SET syntaxes: */
1422 generic_set {$$ = $1;}
1423 | var_name FROM CURRENT_P
1425 VariableSetStmt *n = makeNode(VariableSetStmt);
1426 n->kind = VAR_SET_CURRENT;
1430 /* Special syntaxes mandated by SQL standard: */
1431 | TIME ZONE zone_value
1433 VariableSetStmt *n = makeNode(VariableSetStmt);
1434 n->kind = VAR_SET_VALUE;
1435 n->name = "timezone";
1437 n->args = list_make1($3);
1439 n->kind = VAR_SET_DEFAULT;
1445 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
1446 errmsg("current database cannot be changed"),
1447 parser_errposition(@2)));
1448 $$ = NULL; /*not reached*/
1452 VariableSetStmt *n = makeNode(VariableSetStmt);
1453 n->kind = VAR_SET_VALUE;
1454 n->name = "search_path";
1455 n->args = list_make1(makeStringConst($2, @2));
1458 | NAMES opt_encoding
1460 VariableSetStmt *n = makeNode(VariableSetStmt);
1461 n->kind = VAR_SET_VALUE;
1462 n->name = "client_encoding";
1464 n->args = list_make1(makeStringConst($2, @2));
1466 n->kind = VAR_SET_DEFAULT;
1469 | ROLE NonReservedWord_or_Sconst
1471 VariableSetStmt *n = makeNode(VariableSetStmt);
1472 n->kind = VAR_SET_VALUE;
1474 n->args = list_make1(makeStringConst($2, @2));
1477 | SESSION AUTHORIZATION NonReservedWord_or_Sconst
1479 VariableSetStmt *n = makeNode(VariableSetStmt);
1480 n->kind = VAR_SET_VALUE;
1481 n->name = "session_authorization";
1482 n->args = list_make1(makeStringConst($3, @3));
1485 | SESSION AUTHORIZATION DEFAULT
1487 VariableSetStmt *n = makeNode(VariableSetStmt);
1488 n->kind = VAR_SET_DEFAULT;
1489 n->name = "session_authorization";
1492 | XML_P OPTION document_or_content
1494 VariableSetStmt *n = makeNode(VariableSetStmt);
1495 n->kind = VAR_SET_VALUE;
1496 n->name = "xmloption";
1497 n->args = list_make1(makeStringConst($3 == XMLOPTION_DOCUMENT ? "DOCUMENT" : "CONTENT", @3));
1500 /* Special syntaxes invented by PostgreSQL: */
1501 | TRANSACTION SNAPSHOT Sconst
1503 VariableSetStmt *n = makeNode(VariableSetStmt);
1504 n->kind = VAR_SET_MULTI;
1505 n->name = "TRANSACTION SNAPSHOT";
1506 n->args = list_make1(makeStringConst($3, @3));
1511 var_name: ColId { $$ = $1; }
1512 | var_name '.' ColId
1513 { $$ = psprintf("%s.%s", $1, $3); }
1516 var_list: var_value { $$ = list_make1($1); }
1517 | var_list ',' var_value { $$ = lappend($1, $3); }
1520 var_value: opt_boolean_or_string
1521 { $$ = makeStringConst($1, @1); }
1523 { $$ = makeAConst($1, @1); }
1526 iso_level: READ UNCOMMITTED { $$ = "read uncommitted"; }
1527 | READ COMMITTED { $$ = "read committed"; }
1528 | REPEATABLE READ { $$ = "repeatable read"; }
1529 | SERIALIZABLE { $$ = "serializable"; }
1532 opt_boolean_or_string:
1533 TRUE_P { $$ = "true"; }
1534 | FALSE_P { $$ = "false"; }
1537 * OFF is also accepted as a boolean value, but is handled by
1538 * the NonReservedWord rule. The action for booleans and strings
1539 * is the same, so we don't need to distinguish them here.
1541 | NonReservedWord_or_Sconst { $$ = $1; }
1544 /* Timezone values can be:
1545 * - a string such as 'pst8pdt'
1546 * - an identifier such as "pst8pdt"
1547 * - an integer or floating point number
1548 * - a time interval per SQL99
1549 * ColId gives reduce/reduce errors against ConstInterval and LOCAL,
1550 * so use IDENT (meaning we reject anything that is a key word).
1555 $$ = makeStringConst($1, @1);
1559 $$ = makeStringConst($1, @1);
1561 | ConstInterval Sconst opt_interval
1566 A_Const *n = (A_Const *) linitial($3);
1567 if ((n->val.val.ival & ~(INTERVAL_MASK(HOUR) | INTERVAL_MASK(MINUTE))) != 0)
1569 (errcode(ERRCODE_SYNTAX_ERROR),
1570 errmsg("time zone interval must be HOUR or HOUR TO MINUTE"),
1571 parser_errposition(@3)));
1574 $$ = makeStringConstCast($2, @2, t);
1576 | ConstInterval '(' Iconst ')' Sconst
1579 t->typmods = list_make2(makeIntConst(INTERVAL_FULL_RANGE, -1),
1580 makeIntConst($3, @3));
1581 $$ = makeStringConstCast($5, @5, t);
1583 | NumericOnly { $$ = makeAConst($1, @1); }
1584 | DEFAULT { $$ = NULL; }
1585 | LOCAL { $$ = NULL; }
1590 | DEFAULT { $$ = NULL; }
1591 | /*EMPTY*/ { $$ = NULL; }
1594 NonReservedWord_or_Sconst:
1595 NonReservedWord { $$ = $1; }
1596 | Sconst { $$ = $1; }
1600 RESET reset_rest { $$ = (Node *) $2; }
1604 generic_reset { $$ = $1; }
1607 VariableSetStmt *n = makeNode(VariableSetStmt);
1608 n->kind = VAR_RESET;
1609 n->name = "timezone";
1612 | TRANSACTION ISOLATION LEVEL
1614 VariableSetStmt *n = makeNode(VariableSetStmt);
1615 n->kind = VAR_RESET;
1616 n->name = "transaction_isolation";
1619 | SESSION AUTHORIZATION
1621 VariableSetStmt *n = makeNode(VariableSetStmt);
1622 n->kind = VAR_RESET;
1623 n->name = "session_authorization";
1631 VariableSetStmt *n = makeNode(VariableSetStmt);
1632 n->kind = VAR_RESET;
1638 VariableSetStmt *n = makeNode(VariableSetStmt);
1639 n->kind = VAR_RESET_ALL;
1644 /* SetResetClause allows SET or RESET without LOCAL */
1646 SET set_rest { $$ = $2; }
1647 | VariableResetStmt { $$ = (VariableSetStmt *) $1; }
1650 /* SetResetClause allows SET or RESET without LOCAL */
1651 FunctionSetResetClause:
1652 SET set_rest_more { $$ = $2; }
1653 | VariableResetStmt { $$ = (VariableSetStmt *) $1; }
1660 VariableShowStmt *n = makeNode(VariableShowStmt);
1666 VariableShowStmt *n = makeNode(VariableShowStmt);
1667 n->name = "timezone";
1670 | SHOW TRANSACTION ISOLATION LEVEL
1672 VariableShowStmt *n = makeNode(VariableShowStmt);
1673 n->name = "transaction_isolation";
1676 | SHOW SESSION AUTHORIZATION
1678 VariableShowStmt *n = makeNode(VariableShowStmt);
1679 n->name = "session_authorization";
1684 VariableShowStmt *n = makeNode(VariableShowStmt);
1692 SET CONSTRAINTS constraints_set_list constraints_set_mode
1694 ConstraintsSetStmt *n = makeNode(ConstraintsSetStmt);
1695 n->constraints = $3;
1701 constraints_set_list:
1703 | qualified_name_list { $$ = $1; }
1706 constraints_set_mode:
1707 DEFERRED { $$ = TRUE; }
1708 | IMMEDIATE { $$ = FALSE; }
1713 * Checkpoint statement
1718 CheckPointStmt *n = makeNode(CheckPointStmt);
1724 /*****************************************************************************
1726 * DISCARD { ALL | TEMP | PLANS | SEQUENCES }
1728 *****************************************************************************/
1733 DiscardStmt *n = makeNode(DiscardStmt);
1734 n->target = DISCARD_ALL;
1739 DiscardStmt *n = makeNode(DiscardStmt);
1740 n->target = DISCARD_TEMP;
1745 DiscardStmt *n = makeNode(DiscardStmt);
1746 n->target = DISCARD_TEMP;
1751 DiscardStmt *n = makeNode(DiscardStmt);
1752 n->target = DISCARD_PLANS;
1757 DiscardStmt *n = makeNode(DiscardStmt);
1758 n->target = DISCARD_SEQUENCES;
1765 /*****************************************************************************
1767 * ALTER [ TABLE | INDEX | SEQUENCE | VIEW | MATERIALIZED VIEW ] variations
1769 * Note: we accept all subcommands for each of the five variants, and sort
1770 * out what's really legal at execution time.
1771 *****************************************************************************/
1774 ALTER TABLE relation_expr alter_table_cmds
1776 AlterTableStmt *n = makeNode(AlterTableStmt);
1779 n->relkind = OBJECT_TABLE;
1780 n->missing_ok = false;
1783 | ALTER TABLE IF_P EXISTS relation_expr alter_table_cmds
1785 AlterTableStmt *n = makeNode(AlterTableStmt);
1788 n->relkind = OBJECT_TABLE;
1789 n->missing_ok = true;
1792 | ALTER TABLE ALL IN_P TABLESPACE name SET TABLESPACE name opt_nowait
1794 AlterTableMoveAllStmt *n =
1795 makeNode(AlterTableMoveAllStmt);
1796 n->orig_tablespacename = $6;
1797 n->objtype = OBJECT_TABLE;
1799 n->new_tablespacename = $9;
1803 | ALTER TABLE ALL IN_P TABLESPACE name OWNED BY role_list SET TABLESPACE name opt_nowait
1805 AlterTableMoveAllStmt *n =
1806 makeNode(AlterTableMoveAllStmt);
1807 n->orig_tablespacename = $6;
1808 n->objtype = OBJECT_TABLE;
1810 n->new_tablespacename = $12;
1814 | ALTER INDEX qualified_name alter_table_cmds
1816 AlterTableStmt *n = makeNode(AlterTableStmt);
1819 n->relkind = OBJECT_INDEX;
1820 n->missing_ok = false;
1823 | ALTER INDEX IF_P EXISTS qualified_name alter_table_cmds
1825 AlterTableStmt *n = makeNode(AlterTableStmt);
1828 n->relkind = OBJECT_INDEX;
1829 n->missing_ok = true;
1832 | ALTER INDEX ALL IN_P TABLESPACE name SET TABLESPACE name opt_nowait
1834 AlterTableMoveAllStmt *n =
1835 makeNode(AlterTableMoveAllStmt);
1836 n->orig_tablespacename = $6;
1837 n->objtype = OBJECT_INDEX;
1839 n->new_tablespacename = $9;
1843 | ALTER INDEX ALL IN_P TABLESPACE name OWNED BY role_list SET TABLESPACE name opt_nowait
1845 AlterTableMoveAllStmt *n =
1846 makeNode(AlterTableMoveAllStmt);
1847 n->orig_tablespacename = $6;
1848 n->objtype = OBJECT_INDEX;
1850 n->new_tablespacename = $12;
1854 | ALTER SEQUENCE qualified_name alter_table_cmds
1856 AlterTableStmt *n = makeNode(AlterTableStmt);
1859 n->relkind = OBJECT_SEQUENCE;
1860 n->missing_ok = false;
1863 | ALTER SEQUENCE IF_P EXISTS qualified_name alter_table_cmds
1865 AlterTableStmt *n = makeNode(AlterTableStmt);
1868 n->relkind = OBJECT_SEQUENCE;
1869 n->missing_ok = true;
1872 | ALTER VIEW qualified_name alter_table_cmds
1874 AlterTableStmt *n = makeNode(AlterTableStmt);
1877 n->relkind = OBJECT_VIEW;
1878 n->missing_ok = false;
1881 | ALTER VIEW IF_P EXISTS qualified_name alter_table_cmds
1883 AlterTableStmt *n = makeNode(AlterTableStmt);
1886 n->relkind = OBJECT_VIEW;
1887 n->missing_ok = true;
1890 | ALTER MATERIALIZED VIEW qualified_name alter_table_cmds
1892 AlterTableStmt *n = makeNode(AlterTableStmt);
1895 n->relkind = OBJECT_MATVIEW;
1896 n->missing_ok = false;
1899 | ALTER MATERIALIZED VIEW IF_P EXISTS qualified_name alter_table_cmds
1901 AlterTableStmt *n = makeNode(AlterTableStmt);
1904 n->relkind = OBJECT_MATVIEW;
1905 n->missing_ok = true;
1908 | ALTER MATERIALIZED VIEW ALL IN_P TABLESPACE name SET TABLESPACE name opt_nowait
1910 AlterTableMoveAllStmt *n =
1911 makeNode(AlterTableMoveAllStmt);
1912 n->orig_tablespacename = $7;
1913 n->objtype = OBJECT_MATVIEW;
1915 n->new_tablespacename = $10;
1919 | ALTER MATERIALIZED VIEW ALL IN_P TABLESPACE name OWNED BY role_list SET TABLESPACE name opt_nowait
1921 AlterTableMoveAllStmt *n =
1922 makeNode(AlterTableMoveAllStmt);
1923 n->orig_tablespacename = $7;
1924 n->objtype = OBJECT_MATVIEW;
1926 n->new_tablespacename = $13;
1933 alter_table_cmd { $$ = list_make1($1); }
1934 | alter_table_cmds ',' alter_table_cmd { $$ = lappend($1, $3); }
1938 /* ALTER TABLE <name> ADD <coldef> */
1941 AlterTableCmd *n = makeNode(AlterTableCmd);
1942 n->subtype = AT_AddColumn;
1944 n->missing_ok = false;
1947 /* ALTER TABLE <name> ADD IF NOT EXISTS <coldef> */
1948 | ADD_P IF_P NOT EXISTS columnDef
1950 AlterTableCmd *n = makeNode(AlterTableCmd);
1951 n->subtype = AT_AddColumn;
1953 n->missing_ok = true;
1956 /* ALTER TABLE <name> ADD COLUMN <coldef> */
1957 | ADD_P COLUMN columnDef
1959 AlterTableCmd *n = makeNode(AlterTableCmd);
1960 n->subtype = AT_AddColumn;
1962 n->missing_ok = false;
1965 /* ALTER TABLE <name> ADD COLUMN IF NOT EXISTS <coldef> */
1966 | ADD_P COLUMN IF_P NOT EXISTS columnDef
1968 AlterTableCmd *n = makeNode(AlterTableCmd);
1969 n->subtype = AT_AddColumn;
1971 n->missing_ok = true;
1974 /* ALTER TABLE <name> ALTER [COLUMN] <colname> {SET DEFAULT <expr>|DROP DEFAULT} */
1975 | ALTER opt_column ColId alter_column_default
1977 AlterTableCmd *n = makeNode(AlterTableCmd);
1978 n->subtype = AT_ColumnDefault;
1983 /* ALTER TABLE <name> ALTER [COLUMN] <colname> DROP NOT NULL */
1984 | ALTER opt_column ColId DROP NOT NULL_P
1986 AlterTableCmd *n = makeNode(AlterTableCmd);
1987 n->subtype = AT_DropNotNull;
1991 /* ALTER TABLE <name> ALTER [COLUMN] <colname> SET NOT NULL */
1992 | ALTER opt_column ColId SET NOT NULL_P
1994 AlterTableCmd *n = makeNode(AlterTableCmd);
1995 n->subtype = AT_SetNotNull;
1999 /* ALTER TABLE <name> ALTER [COLUMN] <colname> SET STATISTICS <SignedIconst> */
2000 | ALTER opt_column ColId SET STATISTICS SignedIconst
2002 AlterTableCmd *n = makeNode(AlterTableCmd);
2003 n->subtype = AT_SetStatistics;
2005 n->def = (Node *) makeInteger($6);
2008 /* ALTER TABLE <name> ALTER [COLUMN] <colname> SET ( column_parameter = value [, ... ] ) */
2009 | ALTER opt_column ColId SET reloptions
2011 AlterTableCmd *n = makeNode(AlterTableCmd);
2012 n->subtype = AT_SetOptions;
2014 n->def = (Node *) $5;
2017 /* ALTER TABLE <name> ALTER [COLUMN] <colname> SET ( column_parameter = value [, ... ] ) */
2018 | ALTER opt_column ColId RESET reloptions
2020 AlterTableCmd *n = makeNode(AlterTableCmd);
2021 n->subtype = AT_ResetOptions;
2023 n->def = (Node *) $5;
2026 /* ALTER TABLE <name> ALTER [COLUMN] <colname> SET STORAGE <storagemode> */
2027 | ALTER opt_column ColId SET STORAGE ColId
2029 AlterTableCmd *n = makeNode(AlterTableCmd);
2030 n->subtype = AT_SetStorage;
2032 n->def = (Node *) makeString($6);
2035 /* ALTER TABLE <name> DROP [COLUMN] IF EXISTS <colname> [RESTRICT|CASCADE] */
2036 | DROP opt_column IF_P EXISTS ColId opt_drop_behavior
2038 AlterTableCmd *n = makeNode(AlterTableCmd);
2039 n->subtype = AT_DropColumn;
2042 n->missing_ok = TRUE;
2045 /* ALTER TABLE <name> DROP [COLUMN] <colname> [RESTRICT|CASCADE] */
2046 | DROP opt_column ColId opt_drop_behavior
2048 AlterTableCmd *n = makeNode(AlterTableCmd);
2049 n->subtype = AT_DropColumn;
2052 n->missing_ok = FALSE;
2056 * ALTER TABLE <name> ALTER [COLUMN] <colname> [SET DATA] TYPE <typename>
2057 * [ USING <expression> ]
2059 | ALTER opt_column ColId opt_set_data TYPE_P Typename opt_collate_clause alter_using
2061 AlterTableCmd *n = makeNode(AlterTableCmd);
2062 ColumnDef *def = makeNode(ColumnDef);
2063 n->subtype = AT_AlterColumnType;
2065 n->def = (Node *) def;
2066 /* We only use these fields of the ColumnDef node */
2068 def->collClause = (CollateClause *) $7;
2069 def->raw_default = $8;
2073 /* ALTER FOREIGN TABLE <name> ALTER [COLUMN] <colname> OPTIONS */
2074 | ALTER opt_column ColId alter_generic_options
2076 AlterTableCmd *n = makeNode(AlterTableCmd);
2077 n->subtype = AT_AlterColumnGenericOptions;
2079 n->def = (Node *) $4;
2082 /* ALTER TABLE <name> ADD CONSTRAINT ... */
2083 | ADD_P TableConstraint
2085 AlterTableCmd *n = makeNode(AlterTableCmd);
2086 n->subtype = AT_AddConstraint;
2090 /* ALTER TABLE <name> ALTER CONSTRAINT ... */
2091 | ALTER CONSTRAINT name ConstraintAttributeSpec
2093 AlterTableCmd *n = makeNode(AlterTableCmd);
2094 Constraint *c = makeNode(Constraint);
2095 n->subtype = AT_AlterConstraint;
2096 n->def = (Node *) c;
2097 c->contype = CONSTR_FOREIGN; /* others not supported, yet */
2099 processCASbits($4, @4, "ALTER CONSTRAINT statement",
2102 NULL, NULL, yyscanner);
2105 /* ALTER TABLE <name> VALIDATE CONSTRAINT ... */
2106 | VALIDATE CONSTRAINT name
2108 AlterTableCmd *n = makeNode(AlterTableCmd);
2109 n->subtype = AT_ValidateConstraint;
2113 /* ALTER TABLE <name> DROP CONSTRAINT IF EXISTS <name> [RESTRICT|CASCADE] */
2114 | DROP CONSTRAINT IF_P EXISTS name opt_drop_behavior
2116 AlterTableCmd *n = makeNode(AlterTableCmd);
2117 n->subtype = AT_DropConstraint;
2120 n->missing_ok = TRUE;
2123 /* ALTER TABLE <name> DROP CONSTRAINT <name> [RESTRICT|CASCADE] */
2124 | DROP CONSTRAINT name opt_drop_behavior
2126 AlterTableCmd *n = makeNode(AlterTableCmd);
2127 n->subtype = AT_DropConstraint;
2130 n->missing_ok = FALSE;
2133 /* ALTER TABLE <name> SET WITH OIDS */
2136 AlterTableCmd *n = makeNode(AlterTableCmd);
2137 n->subtype = AT_AddOids;
2140 /* ALTER TABLE <name> SET WITHOUT OIDS */
2143 AlterTableCmd *n = makeNode(AlterTableCmd);
2144 n->subtype = AT_DropOids;
2147 /* ALTER TABLE <name> CLUSTER ON <indexname> */
2150 AlterTableCmd *n = makeNode(AlterTableCmd);
2151 n->subtype = AT_ClusterOn;
2155 /* ALTER TABLE <name> SET WITHOUT CLUSTER */
2156 | SET WITHOUT CLUSTER
2158 AlterTableCmd *n = makeNode(AlterTableCmd);
2159 n->subtype = AT_DropCluster;
2163 /* ALTER TABLE <name> SET LOGGED */
2166 AlterTableCmd *n = makeNode(AlterTableCmd);
2167 n->subtype = AT_SetLogged;
2170 /* ALTER TABLE <name> SET UNLOGGED */
2173 AlterTableCmd *n = makeNode(AlterTableCmd);
2174 n->subtype = AT_SetUnLogged;
2177 /* ALTER TABLE <name> ENABLE TRIGGER <trig> */
2178 | ENABLE_P TRIGGER name
2180 AlterTableCmd *n = makeNode(AlterTableCmd);
2181 n->subtype = AT_EnableTrig;
2185 /* ALTER TABLE <name> ENABLE ALWAYS TRIGGER <trig> */
2186 | ENABLE_P ALWAYS TRIGGER name
2188 AlterTableCmd *n = makeNode(AlterTableCmd);
2189 n->subtype = AT_EnableAlwaysTrig;
2193 /* ALTER TABLE <name> ENABLE REPLICA TRIGGER <trig> */
2194 | ENABLE_P REPLICA TRIGGER name
2196 AlterTableCmd *n = makeNode(AlterTableCmd);
2197 n->subtype = AT_EnableReplicaTrig;
2201 /* ALTER TABLE <name> ENABLE TRIGGER ALL */
2202 | ENABLE_P TRIGGER ALL
2204 AlterTableCmd *n = makeNode(AlterTableCmd);
2205 n->subtype = AT_EnableTrigAll;
2208 /* ALTER TABLE <name> ENABLE TRIGGER USER */
2209 | ENABLE_P TRIGGER USER
2211 AlterTableCmd *n = makeNode(AlterTableCmd);
2212 n->subtype = AT_EnableTrigUser;
2215 /* ALTER TABLE <name> DISABLE TRIGGER <trig> */
2216 | DISABLE_P TRIGGER name
2218 AlterTableCmd *n = makeNode(AlterTableCmd);
2219 n->subtype = AT_DisableTrig;
2223 /* ALTER TABLE <name> DISABLE TRIGGER ALL */
2224 | DISABLE_P TRIGGER ALL
2226 AlterTableCmd *n = makeNode(AlterTableCmd);
2227 n->subtype = AT_DisableTrigAll;
2230 /* ALTER TABLE <name> DISABLE TRIGGER USER */
2231 | DISABLE_P TRIGGER USER
2233 AlterTableCmd *n = makeNode(AlterTableCmd);
2234 n->subtype = AT_DisableTrigUser;
2237 /* ALTER TABLE <name> ENABLE RULE <rule> */
2238 | ENABLE_P RULE name
2240 AlterTableCmd *n = makeNode(AlterTableCmd);
2241 n->subtype = AT_EnableRule;
2245 /* ALTER TABLE <name> ENABLE ALWAYS RULE <rule> */
2246 | ENABLE_P ALWAYS RULE name
2248 AlterTableCmd *n = makeNode(AlterTableCmd);
2249 n->subtype = AT_EnableAlwaysRule;
2253 /* ALTER TABLE <name> ENABLE REPLICA RULE <rule> */
2254 | ENABLE_P REPLICA RULE name
2256 AlterTableCmd *n = makeNode(AlterTableCmd);
2257 n->subtype = AT_EnableReplicaRule;
2261 /* ALTER TABLE <name> DISABLE RULE <rule> */
2262 | DISABLE_P RULE name
2264 AlterTableCmd *n = makeNode(AlterTableCmd);
2265 n->subtype = AT_DisableRule;
2269 /* ALTER TABLE <name> INHERIT <parent> */
2270 | INHERIT qualified_name
2272 AlterTableCmd *n = makeNode(AlterTableCmd);
2273 n->subtype = AT_AddInherit;
2274 n->def = (Node *) $2;
2277 /* ALTER TABLE <name> NO INHERIT <parent> */
2278 | NO INHERIT qualified_name
2280 AlterTableCmd *n = makeNode(AlterTableCmd);
2281 n->subtype = AT_DropInherit;
2282 n->def = (Node *) $3;
2285 /* ALTER TABLE <name> OF <type_name> */
2288 AlterTableCmd *n = makeNode(AlterTableCmd);
2289 TypeName *def = makeTypeNameFromNameList($2);
2291 n->subtype = AT_AddOf;
2292 n->def = (Node *) def;
2295 /* ALTER TABLE <name> NOT OF */
2298 AlterTableCmd *n = makeNode(AlterTableCmd);
2299 n->subtype = AT_DropOf;
2302 /* ALTER TABLE <name> OWNER TO RoleSpec */
2305 AlterTableCmd *n = makeNode(AlterTableCmd);
2306 n->subtype = AT_ChangeOwner;
2310 /* ALTER TABLE <name> SET TABLESPACE <tablespacename> */
2311 | SET TABLESPACE name
2313 AlterTableCmd *n = makeNode(AlterTableCmd);
2314 n->subtype = AT_SetTableSpace;
2318 /* ALTER TABLE <name> SET (...) */
2321 AlterTableCmd *n = makeNode(AlterTableCmd);
2322 n->subtype = AT_SetRelOptions;
2323 n->def = (Node *)$2;
2326 /* ALTER TABLE <name> RESET (...) */
2329 AlterTableCmd *n = makeNode(AlterTableCmd);
2330 n->subtype = AT_ResetRelOptions;
2331 n->def = (Node *)$2;
2334 /* ALTER TABLE <name> REPLICA IDENTITY */
2335 | REPLICA IDENTITY_P replica_identity
2337 AlterTableCmd *n = makeNode(AlterTableCmd);
2338 n->subtype = AT_ReplicaIdentity;
2342 /* ALTER TABLE <name> ENABLE ROW LEVEL SECURITY */
2343 | ENABLE_P ROW LEVEL SECURITY
2345 AlterTableCmd *n = makeNode(AlterTableCmd);
2346 n->subtype = AT_EnableRowSecurity;
2349 /* ALTER TABLE <name> DISABLE ROW LEVEL SECURITY */
2350 | DISABLE_P ROW LEVEL SECURITY
2352 AlterTableCmd *n = makeNode(AlterTableCmd);
2353 n->subtype = AT_DisableRowSecurity;
2356 | alter_generic_options
2358 AlterTableCmd *n = makeNode(AlterTableCmd);
2359 n->subtype = AT_GenericOptions;
2360 n->def = (Node *)$1;
2365 alter_column_default:
2366 SET DEFAULT a_expr { $$ = $3; }
2367 | DROP DEFAULT { $$ = NULL; }
2371 CASCADE { $$ = DROP_CASCADE; }
2372 | RESTRICT { $$ = DROP_RESTRICT; }
2373 | /* EMPTY */ { $$ = DROP_RESTRICT; /* default */ }
2379 CollateClause *n = makeNode(CollateClause);
2385 | /* EMPTY */ { $$ = NULL; }
2389 USING a_expr { $$ = $2; }
2390 | /* EMPTY */ { $$ = NULL; }
2396 ReplicaIdentityStmt *n = makeNode(ReplicaIdentityStmt);
2397 n->identity_type = REPLICA_IDENTITY_NOTHING;
2403 ReplicaIdentityStmt *n = makeNode(ReplicaIdentityStmt);
2404 n->identity_type = REPLICA_IDENTITY_FULL;
2410 ReplicaIdentityStmt *n = makeNode(ReplicaIdentityStmt);
2411 n->identity_type = REPLICA_IDENTITY_DEFAULT;
2417 ReplicaIdentityStmt *n = makeNode(ReplicaIdentityStmt);
2418 n->identity_type = REPLICA_IDENTITY_INDEX;
2425 '(' reloption_list ')' { $$ = $2; }
2428 opt_reloptions: WITH reloptions { $$ = $2; }
2429 | /* EMPTY */ { $$ = NIL; }
2433 reloption_elem { $$ = list_make1($1); }
2434 | reloption_list ',' reloption_elem { $$ = lappend($1, $3); }
2437 /* This should match def_elem and also allow qualified names */
2439 ColLabel '=' def_arg
2441 $$ = makeDefElem($1, (Node *) $3);
2445 $$ = makeDefElem($1, NULL);
2447 | ColLabel '.' ColLabel '=' def_arg
2449 $$ = makeDefElemExtended($1, $3, (Node *) $5,
2452 | ColLabel '.' ColLabel
2454 $$ = makeDefElemExtended($1, $3, NULL, DEFELEM_UNSPEC);
2459 /*****************************************************************************
2463 * really variants of the ALTER TABLE subcommands with different spellings
2464 *****************************************************************************/
2466 AlterCompositeTypeStmt:
2467 ALTER TYPE_P any_name alter_type_cmds
2469 AlterTableStmt *n = makeNode(AlterTableStmt);
2471 /* can't use qualified_name, sigh */
2472 n->relation = makeRangeVarFromAnyName($3, @3, yyscanner);
2474 n->relkind = OBJECT_TYPE;
2480 alter_type_cmd { $$ = list_make1($1); }
2481 | alter_type_cmds ',' alter_type_cmd { $$ = lappend($1, $3); }
2485 /* ALTER TYPE <name> ADD ATTRIBUTE <coldef> [RESTRICT|CASCADE] */
2486 ADD_P ATTRIBUTE TableFuncElement opt_drop_behavior
2488 AlterTableCmd *n = makeNode(AlterTableCmd);
2489 n->subtype = AT_AddColumn;
2494 /* ALTER TYPE <name> DROP ATTRIBUTE IF EXISTS <attname> [RESTRICT|CASCADE] */
2495 | DROP ATTRIBUTE IF_P EXISTS ColId opt_drop_behavior
2497 AlterTableCmd *n = makeNode(AlterTableCmd);
2498 n->subtype = AT_DropColumn;
2501 n->missing_ok = TRUE;
2504 /* ALTER TYPE <name> DROP ATTRIBUTE <attname> [RESTRICT|CASCADE] */
2505 | DROP ATTRIBUTE ColId opt_drop_behavior
2507 AlterTableCmd *n = makeNode(AlterTableCmd);
2508 n->subtype = AT_DropColumn;
2511 n->missing_ok = FALSE;
2514 /* ALTER TYPE <name> ALTER ATTRIBUTE <attname> [SET DATA] TYPE <typename> [RESTRICT|CASCADE] */
2515 | ALTER ATTRIBUTE ColId opt_set_data TYPE_P Typename opt_collate_clause opt_drop_behavior
2517 AlterTableCmd *n = makeNode(AlterTableCmd);
2518 ColumnDef *def = makeNode(ColumnDef);
2519 n->subtype = AT_AlterColumnType;
2521 n->def = (Node *) def;
2523 /* We only use these fields of the ColumnDef node */
2525 def->collClause = (CollateClause *) $7;
2526 def->raw_default = NULL;
2533 /*****************************************************************************
2536 * close <portalname>
2538 *****************************************************************************/
2543 ClosePortalStmt *n = makeNode(ClosePortalStmt);
2549 ClosePortalStmt *n = makeNode(ClosePortalStmt);
2550 n->portalname = NULL;
2556 /*****************************************************************************
2559 * COPY relname [(columnList)] FROM/TO file [WITH] [(options)]
2560 * COPY ( SELECT ... ) TO file [WITH] [(options)]
2562 * where 'file' can be one of:
2563 * { PROGRAM 'command' | STDIN | STDOUT | 'filename' }
2565 * In the preferred syntax the options are comma-separated
2566 * and use generic identifiers instead of keywords. The pre-9.0
2567 * syntax had a hard-wired, space-separated set of options.
2569 * Really old syntax, from versions 7.2 and prior:
2570 * COPY [ BINARY ] table [ WITH OIDS ] FROM/TO file
2571 * [ [ USING ] DELIMITERS 'delimiter' ] ]
2572 * [ WITH NULL AS 'null string' ]
2573 * This option placement is not supported with COPY (SELECT...).
2575 *****************************************************************************/
2577 CopyStmt: COPY opt_binary qualified_name opt_column_list opt_oids
2578 copy_from opt_program copy_file_name copy_delimiter opt_with copy_options
2580 CopyStmt *n = makeNode(CopyStmt);
2588 if (n->is_program && n->filename == NULL)
2590 (errcode(ERRCODE_SYNTAX_ERROR),
2591 errmsg("STDIN/STDOUT not allowed with PROGRAM"),
2592 parser_errposition(@8)));
2595 /* Concatenate user-supplied flags */
2597 n->options = lappend(n->options, $2);
2599 n->options = lappend(n->options, $5);
2601 n->options = lappend(n->options, $9);
2603 n->options = list_concat(n->options, $11);
2606 | COPY select_with_parens TO opt_program copy_file_name opt_with copy_options
2608 CopyStmt *n = makeNode(CopyStmt);
2617 if (n->is_program && n->filename == NULL)
2619 (errcode(ERRCODE_SYNTAX_ERROR),
2620 errmsg("STDIN/STDOUT not allowed with PROGRAM"),
2621 parser_errposition(@5)));
2629 | TO { $$ = FALSE; }
2633 PROGRAM { $$ = TRUE; }
2634 | /* EMPTY */ { $$ = FALSE; }
2638 * copy_file_name NULL indicates stdio is used. Whether stdin or stdout is
2639 * used depends on the direction. (It really doesn't make sense to copy from
2640 * stdout. We silently correct the "typo".) - AY 9/94
2644 | STDIN { $$ = NULL; }
2645 | STDOUT { $$ = NULL; }
2648 copy_options: copy_opt_list { $$ = $1; }
2649 | '(' copy_generic_opt_list ')' { $$ = $2; }
2652 /* old COPY option syntax */
2654 copy_opt_list copy_opt_item { $$ = lappend($1, $2); }
2655 | /* EMPTY */ { $$ = NIL; }
2661 $$ = makeDefElem("format", (Node *)makeString("binary"));
2665 $$ = makeDefElem("oids", (Node *)makeInteger(TRUE));
2669 $$ = makeDefElem("freeze", (Node *)makeInteger(TRUE));
2671 | DELIMITER opt_as Sconst
2673 $$ = makeDefElem("delimiter", (Node *)makeString($3));
2675 | NULL_P opt_as Sconst
2677 $$ = makeDefElem("null", (Node *)makeString($3));
2681 $$ = makeDefElem("format", (Node *)makeString("csv"));
2685 $$ = makeDefElem("header", (Node *)makeInteger(TRUE));
2687 | QUOTE opt_as Sconst
2689 $$ = makeDefElem("quote", (Node *)makeString($3));
2691 | ESCAPE opt_as Sconst
2693 $$ = makeDefElem("escape", (Node *)makeString($3));
2695 | FORCE QUOTE columnList
2697 $$ = makeDefElem("force_quote", (Node *)$3);
2701 $$ = makeDefElem("force_quote", (Node *)makeNode(A_Star));
2703 | FORCE NOT NULL_P columnList
2705 $$ = makeDefElem("force_not_null", (Node *)$4);
2707 | FORCE NULL_P columnList
2709 $$ = makeDefElem("force_null", (Node *)$3);
2713 $$ = makeDefElem("encoding", (Node *)makeString($2));
2717 /* The following exist for backward compatibility with very old versions */
2722 $$ = makeDefElem("format", (Node *)makeString("binary"));
2724 | /*EMPTY*/ { $$ = NULL; }
2730 $$ = makeDefElem("oids", (Node *)makeInteger(TRUE));
2732 | /*EMPTY*/ { $$ = NULL; }
2736 opt_using DELIMITERS Sconst
2738 $$ = makeDefElem("delimiter", (Node *)makeString($3));
2740 | /*EMPTY*/ { $$ = NULL; }
2748 /* new COPY option syntax */
2749 copy_generic_opt_list:
2750 copy_generic_opt_elem
2752 $$ = list_make1($1);
2754 | copy_generic_opt_list ',' copy_generic_opt_elem
2756 $$ = lappend($1, $3);
2760 copy_generic_opt_elem:
2761 ColLabel copy_generic_opt_arg
2763 $$ = makeDefElem($1, $2);
2767 copy_generic_opt_arg:
2768 opt_boolean_or_string { $$ = (Node *) makeString($1); }
2769 | NumericOnly { $$ = (Node *) $1; }
2770 | '*' { $$ = (Node *) makeNode(A_Star); }
2771 | '(' copy_generic_opt_arg_list ')' { $$ = (Node *) $2; }
2772 | /* EMPTY */ { $$ = NULL; }
2775 copy_generic_opt_arg_list:
2776 copy_generic_opt_arg_list_item
2778 $$ = list_make1($1);
2780 | copy_generic_opt_arg_list ',' copy_generic_opt_arg_list_item
2782 $$ = lappend($1, $3);
2786 /* beware of emitting non-string list elements here; see commands/define.c */
2787 copy_generic_opt_arg_list_item:
2788 opt_boolean_or_string { $$ = (Node *) makeString($1); }
2792 /*****************************************************************************
2795 * CREATE TABLE relname
2797 *****************************************************************************/
2799 CreateStmt: CREATE OptTemp TABLE qualified_name '(' OptTableElementList ')'
2800 OptInherit OptWith OnCommitOption OptTableSpace
2802 CreateStmt *n = makeNode(CreateStmt);
2803 $4->relpersistence = $2;
2806 n->inhRelations = $8;
2807 n->ofTypename = NULL;
2808 n->constraints = NIL;
2811 n->tablespacename = $11;
2812 n->if_not_exists = false;
2815 | CREATE OptTemp TABLE IF_P NOT EXISTS qualified_name '('
2816 OptTableElementList ')' OptInherit OptWith OnCommitOption
2819 CreateStmt *n = makeNode(CreateStmt);
2820 $7->relpersistence = $2;
2823 n->inhRelations = $11;
2824 n->ofTypename = NULL;
2825 n->constraints = NIL;
2828 n->tablespacename = $14;
2829 n->if_not_exists = true;
2832 | CREATE OptTemp TABLE qualified_name OF any_name
2833 OptTypedTableElementList OptWith OnCommitOption OptTableSpace
2835 CreateStmt *n = makeNode(CreateStmt);
2836 $4->relpersistence = $2;
2839 n->inhRelations = NIL;
2840 n->ofTypename = makeTypeNameFromNameList($6);
2841 n->ofTypename->location = @6;
2842 n->constraints = NIL;
2845 n->tablespacename = $10;
2846 n->if_not_exists = false;
2849 | CREATE OptTemp TABLE IF_P NOT EXISTS qualified_name OF any_name
2850 OptTypedTableElementList OptWith OnCommitOption OptTableSpace
2852 CreateStmt *n = makeNode(CreateStmt);
2853 $7->relpersistence = $2;
2856 n->inhRelations = NIL;
2857 n->ofTypename = makeTypeNameFromNameList($9);
2858 n->ofTypename->location = @9;
2859 n->constraints = NIL;
2862 n->tablespacename = $13;
2863 n->if_not_exists = true;
2869 * Redundancy here is needed to avoid shift/reduce conflicts,
2870 * since TEMP is not a reserved word. See also OptTempTableName.
2872 * NOTE: we accept both GLOBAL and LOCAL options. They currently do nothing,
2873 * but future versions might consider GLOBAL to request SQL-spec-compliant
2874 * temp table behavior, so warn about that. Since we have no modules the
2875 * LOCAL keyword is really meaningless; furthermore, some other products
2876 * implement LOCAL as meaning the same as our default temp table behavior,
2877 * so we'll probably continue to treat LOCAL as a noise word.
2879 OptTemp: TEMPORARY { $$ = RELPERSISTENCE_TEMP; }
2880 | TEMP { $$ = RELPERSISTENCE_TEMP; }
2881 | LOCAL TEMPORARY { $$ = RELPERSISTENCE_TEMP; }
2882 | LOCAL TEMP { $$ = RELPERSISTENCE_TEMP; }
2886 (errmsg("GLOBAL is deprecated in temporary table creation"),
2887 parser_errposition(@1)));
2888 $$ = RELPERSISTENCE_TEMP;
2893 (errmsg("GLOBAL is deprecated in temporary table creation"),
2894 parser_errposition(@1)));
2895 $$ = RELPERSISTENCE_TEMP;
2897 | UNLOGGED { $$ = RELPERSISTENCE_UNLOGGED; }
2898 | /*EMPTY*/ { $$ = RELPERSISTENCE_PERMANENT; }
2901 OptTableElementList:
2902 TableElementList { $$ = $1; }
2903 | /*EMPTY*/ { $$ = NIL; }
2906 OptTypedTableElementList:
2907 '(' TypedTableElementList ')' { $$ = $2; }
2908 | /*EMPTY*/ { $$ = NIL; }
2914 $$ = list_make1($1);
2916 | TableElementList ',' TableElement
2918 $$ = lappend($1, $3);
2922 TypedTableElementList:
2925 $$ = list_make1($1);
2927 | TypedTableElementList ',' TypedTableElement
2929 $$ = lappend($1, $3);
2934 columnDef { $$ = $1; }
2935 | TableLikeClause { $$ = $1; }
2936 | TableConstraint { $$ = $1; }
2940 columnOptions { $$ = $1; }
2941 | TableConstraint { $$ = $1; }
2944 columnDef: ColId Typename create_generic_options ColQualList
2946 ColumnDef *n = makeNode(ColumnDef);
2951 n->is_not_null = false;
2952 n->is_from_type = false;
2954 n->raw_default = NULL;
2955 n->cooked_default = NULL;
2956 n->collOid = InvalidOid;
2958 SplitColQualList($4, &n->constraints, &n->collClause,
2965 columnOptions: ColId WITH OPTIONS ColQualList
2967 ColumnDef *n = makeNode(ColumnDef);
2972 n->is_not_null = false;
2973 n->is_from_type = false;
2975 n->raw_default = NULL;
2976 n->cooked_default = NULL;
2977 n->collOid = InvalidOid;
2978 SplitColQualList($4, &n->constraints, &n->collClause,
2986 ColQualList ColConstraint { $$ = lappend($1, $2); }
2987 | /*EMPTY*/ { $$ = NIL; }
2991 CONSTRAINT name ColConstraintElem
2993 Constraint *n = (Constraint *) $3;
2994 Assert(IsA(n, Constraint));
2999 | ColConstraintElem { $$ = $1; }
3000 | ConstraintAttr { $$ = $1; }
3004 * Note: the CollateClause is momentarily included in
3005 * the list built by ColQualList, but we split it out
3006 * again in SplitColQualList.
3008 CollateClause *n = makeNode(CollateClause);
3016 /* DEFAULT NULL is already the default for Postgres.
3017 * But define it here and carry it forward into the system
3018 * to make it explicit.
3019 * - thomas 1998-09-13
3021 * WITH NULL and NULL are not SQL-standard syntax elements,
3022 * so leave them out. Use DEFAULT NULL to explicitly indicate
3023 * that a column may have that value. WITH NULL leads to
3024 * shift/reduce conflicts with WITH TIME ZONE anyway.
3025 * - thomas 1999-01-08
3027 * DEFAULT expression must be b_expr not a_expr to prevent shift/reduce
3028 * conflict on NOT (since NOT might start a subsequent NOT NULL constraint,
3029 * or be part of a_expr NOT LIKE or similar constructs).
3034 Constraint *n = makeNode(Constraint);
3035 n->contype = CONSTR_NOTNULL;
3041 Constraint *n = makeNode(Constraint);
3042 n->contype = CONSTR_NULL;
3046 | UNIQUE opt_definition OptConsTableSpace
3048 Constraint *n = makeNode(Constraint);
3049 n->contype = CONSTR_UNIQUE;
3053 n->indexname = NULL;
3057 | PRIMARY KEY opt_definition OptConsTableSpace
3059 Constraint *n = makeNode(Constraint);
3060 n->contype = CONSTR_PRIMARY;
3064 n->indexname = NULL;
3068 | CHECK '(' a_expr ')' opt_no_inherit
3070 Constraint *n = makeNode(Constraint);
3071 n->contype = CONSTR_CHECK;
3073 n->is_no_inherit = $5;
3075 n->cooked_expr = NULL;
3080 Constraint *n = makeNode(Constraint);
3081 n->contype = CONSTR_DEFAULT;
3084 n->cooked_expr = NULL;
3087 | REFERENCES qualified_name opt_column_list key_match key_actions
3089 Constraint *n = makeNode(Constraint);
3090 n->contype = CONSTR_FOREIGN;
3095 n->fk_matchtype = $4;
3096 n->fk_upd_action = (char) ($5 >> 8);
3097 n->fk_del_action = (char) ($5 & 0xFF);
3098 n->skip_validation = false;
3099 n->initially_valid = true;
3105 * ConstraintAttr represents constraint attributes, which we parse as if
3106 * they were independent constraint clauses, in order to avoid shift/reduce
3107 * conflicts (since NOT might start either an independent NOT NULL clause
3108 * or an attribute). parse_utilcmd.c is responsible for attaching the
3109 * attribute information to the preceding "real" constraint node, and for
3110 * complaining if attribute clauses appear in the wrong place or wrong
3113 * See also ConstraintAttributeSpec, which can be used in places where
3114 * there is no parsing conflict. (Note: currently, NOT VALID and NO INHERIT
3115 * are allowed clauses in ConstraintAttributeSpec, but not here. Someday we
3116 * might need to allow them here too, but for the moment it doesn't seem
3117 * useful in the statements that use ConstraintAttr.)
3122 Constraint *n = makeNode(Constraint);
3123 n->contype = CONSTR_ATTR_DEFERRABLE;
3129 Constraint *n = makeNode(Constraint);
3130 n->contype = CONSTR_ATTR_NOT_DEFERRABLE;
3134 | INITIALLY DEFERRED
3136 Constraint *n = makeNode(Constraint);
3137 n->contype = CONSTR_ATTR_DEFERRED;
3141 | INITIALLY IMMEDIATE
3143 Constraint *n = makeNode(Constraint);
3144 n->contype = CONSTR_ATTR_IMMEDIATE;
3152 LIKE qualified_name TableLikeOptionList
3154 TableLikeClause *n = makeNode(TableLikeClause);
3161 TableLikeOptionList:
3162 TableLikeOptionList INCLUDING TableLikeOption { $$ = $1 | $3; }
3163 | TableLikeOptionList EXCLUDING TableLikeOption { $$ = $1 & ~$3; }
3164 | /* EMPTY */ { $$ = 0; }
3168 DEFAULTS { $$ = CREATE_TABLE_LIKE_DEFAULTS; }
3169 | CONSTRAINTS { $$ = CREATE_TABLE_LIKE_CONSTRAINTS; }
3170 | INDEXES { $$ = CREATE_TABLE_LIKE_INDEXES; }
3171 | STORAGE { $$ = CREATE_TABLE_LIKE_STORAGE; }
3172 | COMMENTS { $$ = CREATE_TABLE_LIKE_COMMENTS; }
3173 | ALL { $$ = CREATE_TABLE_LIKE_ALL; }
3177 /* ConstraintElem specifies constraint syntax which is not embedded into
3178 * a column definition. ColConstraintElem specifies the embedded form.
3179 * - thomas 1997-12-03
3182 CONSTRAINT name ConstraintElem
3184 Constraint *n = (Constraint *) $3;
3185 Assert(IsA(n, Constraint));
3190 | ConstraintElem { $$ = $1; }
3194 CHECK '(' a_expr ')' ConstraintAttributeSpec
3196 Constraint *n = makeNode(Constraint);
3197 n->contype = CONSTR_CHECK;
3200 n->cooked_expr = NULL;
3201 processCASbits($5, @5, "CHECK",
3202 NULL, NULL, &n->skip_validation,
3203 &n->is_no_inherit, yyscanner);
3204 n->initially_valid = !n->skip_validation;
3207 | UNIQUE '(' columnList ')' opt_definition OptConsTableSpace
3208 ConstraintAttributeSpec
3210 Constraint *n = makeNode(Constraint);
3211 n->contype = CONSTR_UNIQUE;
3215 n->indexname = NULL;
3217 processCASbits($7, @7, "UNIQUE",
3218 &n->deferrable, &n->initdeferred, NULL,
3222 | UNIQUE ExistingIndex ConstraintAttributeSpec
3224 Constraint *n = makeNode(Constraint);
3225 n->contype = CONSTR_UNIQUE;
3230 n->indexspace = NULL;
3231 processCASbits($3, @3, "UNIQUE",
3232 &n->deferrable, &n->initdeferred, NULL,
3236 | PRIMARY KEY '(' columnList ')' opt_definition OptConsTableSpace
3237 ConstraintAttributeSpec
3239 Constraint *n = makeNode(Constraint);
3240 n->contype = CONSTR_PRIMARY;
3244 n->indexname = NULL;
3246 processCASbits($8, @8, "PRIMARY KEY",
3247 &n->deferrable, &n->initdeferred, NULL,
3251 | PRIMARY KEY ExistingIndex ConstraintAttributeSpec
3253 Constraint *n = makeNode(Constraint);
3254 n->contype = CONSTR_PRIMARY;
3259 n->indexspace = NULL;
3260 processCASbits($4, @4, "PRIMARY KEY",
3261 &n->deferrable, &n->initdeferred, NULL,
3265 | EXCLUDE access_method_clause '(' ExclusionConstraintList ')'
3266 opt_definition OptConsTableSpace ExclusionWhereClause
3267 ConstraintAttributeSpec
3269 Constraint *n = makeNode(Constraint);
3270 n->contype = CONSTR_EXCLUSION;
3272 n->access_method = $2;
3275 n->indexname = NULL;
3277 n->where_clause = $8;
3278 processCASbits($9, @9, "EXCLUDE",
3279 &n->deferrable, &n->initdeferred, NULL,
3283 | FOREIGN KEY '(' columnList ')' REFERENCES qualified_name
3284 opt_column_list key_match key_actions ConstraintAttributeSpec
3286 Constraint *n = makeNode(Constraint);
3287 n->contype = CONSTR_FOREIGN;
3292 n->fk_matchtype = $9;
3293 n->fk_upd_action = (char) ($10 >> 8);
3294 n->fk_del_action = (char) ($10 & 0xFF);
3295 processCASbits($11, @11, "FOREIGN KEY",
3296 &n->deferrable, &n->initdeferred,
3297 &n->skip_validation, NULL,
3299 n->initially_valid = !n->skip_validation;
3304 opt_no_inherit: NO INHERIT { $$ = TRUE; }
3305 | /* EMPTY */ { $$ = FALSE; }
3309 '(' columnList ')' { $$ = $2; }
3310 | /*EMPTY*/ { $$ = NIL; }
3314 columnElem { $$ = list_make1($1); }
3315 | columnList ',' columnElem { $$ = lappend($1, $3); }
3320 $$ = (Node *) makeString($1);
3324 key_match: MATCH FULL
3326 $$ = FKCONSTR_MATCH_FULL;
3331 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
3332 errmsg("MATCH PARTIAL not yet implemented"),
3333 parser_errposition(@1)));
3334 $$ = FKCONSTR_MATCH_PARTIAL;
3338 $$ = FKCONSTR_MATCH_SIMPLE;
3342 $$ = FKCONSTR_MATCH_SIMPLE;
3346 ExclusionConstraintList:
3347 ExclusionConstraintElem { $$ = list_make1($1); }
3348 | ExclusionConstraintList ',' ExclusionConstraintElem
3349 { $$ = lappend($1, $3); }
3352 ExclusionConstraintElem: index_elem WITH any_operator
3354 $$ = list_make2($1, $3);
3356 /* allow OPERATOR() decoration for the benefit of ruleutils.c */
3357 | index_elem WITH OPERATOR '(' any_operator ')'
3359 $$ = list_make2($1, $5);
3363 ExclusionWhereClause:
3364 WHERE '(' a_expr ')' { $$ = $3; }
3365 | /*EMPTY*/ { $$ = NULL; }
3369 * We combine the update and delete actions into one value temporarily
3370 * for simplicity of parsing, and then break them down again in the
3371 * calling production. update is in the left 8 bits, delete in the right.
3372 * Note that NOACTION is the default.
3376 { $$ = ($1 << 8) | (FKCONSTR_ACTION_NOACTION & 0xFF); }
3378 { $$ = (FKCONSTR_ACTION_NOACTION << 8) | ($1 & 0xFF); }
3379 | key_update key_delete
3380 { $$ = ($1 << 8) | ($2 & 0xFF); }
3381 | key_delete key_update
3382 { $$ = ($2 << 8) | ($1 & 0xFF); }
3384 { $$ = (FKCONSTR_ACTION_NOACTION << 8) | (FKCONSTR_ACTION_NOACTION & 0xFF); }
3387 key_update: ON UPDATE key_action { $$ = $3; }
3390 key_delete: ON DELETE_P key_action { $$ = $3; }
3394 NO ACTION { $$ = FKCONSTR_ACTION_NOACTION; }
3395 | RESTRICT { $$ = FKCONSTR_ACTION_RESTRICT; }
3396 | CASCADE { $$ = FKCONSTR_ACTION_CASCADE; }
3397 | SET NULL_P { $$ = FKCONSTR_ACTION_SETNULL; }
3398 | SET DEFAULT { $$ = FKCONSTR_ACTION_SETDEFAULT; }
3401 OptInherit: INHERITS '(' qualified_name_list ')' { $$ = $3; }
3402 | /*EMPTY*/ { $$ = NIL; }
3405 /* WITH (options) is preferred, WITH OIDS and WITHOUT OIDS are legacy forms */
3407 WITH reloptions { $$ = $2; }
3408 | WITH OIDS { $$ = list_make1(defWithOids(true)); }
3409 | WITHOUT OIDS { $$ = list_make1(defWithOids(false)); }
3410 | /*EMPTY*/ { $$ = NIL; }
3413 OnCommitOption: ON COMMIT DROP { $$ = ONCOMMIT_DROP; }
3414 | ON COMMIT DELETE_P ROWS { $$ = ONCOMMIT_DELETE_ROWS; }
3415 | ON COMMIT PRESERVE ROWS { $$ = ONCOMMIT_PRESERVE_ROWS; }
3416 | /*EMPTY*/ { $$ = ONCOMMIT_NOOP; }
3419 OptTableSpace: TABLESPACE name { $$ = $2; }
3420 | /*EMPTY*/ { $$ = NULL; }
3423 OptConsTableSpace: USING INDEX TABLESPACE name { $$ = $4; }
3424 | /*EMPTY*/ { $$ = NULL; }
3427 ExistingIndex: USING INDEX index_name { $$ = $3; }
3431 /*****************************************************************************
3434 * CREATE TABLE relname AS SelectStmt [ WITH [NO] DATA ]
3437 * Note: SELECT ... INTO is a now-deprecated alternative for this.
3439 *****************************************************************************/
3442 CREATE OptTemp TABLE create_as_target AS SelectStmt opt_with_data
3444 CreateTableAsStmt *ctas = makeNode(CreateTableAsStmt);
3447 ctas->relkind = OBJECT_TABLE;
3448 ctas->is_select_into = false;
3449 ctas->if_not_exists = false;
3450 /* cram additional flags into the IntoClause */
3451 $4->rel->relpersistence = $2;
3452 $4->skipData = !($7);
3455 | CREATE OptTemp TABLE IF_P NOT EXISTS create_as_target AS SelectStmt opt_with_data
3457 CreateTableAsStmt *ctas = makeNode(CreateTableAsStmt);
3460 ctas->relkind = OBJECT_TABLE;
3461 ctas->is_select_into = false;
3462 ctas->if_not_exists = true;
3463 /* cram additional flags into the IntoClause */
3464 $7->rel->relpersistence = $2;
3465 $7->skipData = !($10);
3471 qualified_name opt_column_list OptWith OnCommitOption OptTableSpace
3473 $$ = makeNode(IntoClause);
3478 $$->tableSpaceName = $5;
3479 $$->viewQuery = NULL;
3480 $$->skipData = false; /* might get changed later */
3485 WITH DATA_P { $$ = TRUE; }
3486 | WITH NO DATA_P { $$ = FALSE; }
3487 | /*EMPTY*/ { $$ = TRUE; }
3491 /*****************************************************************************
3494 * CREATE MATERIALIZED VIEW relname AS SelectStmt
3496 *****************************************************************************/
3499 CREATE OptNoLog MATERIALIZED VIEW create_mv_target AS SelectStmt opt_with_data
3501 CreateTableAsStmt *ctas = makeNode(CreateTableAsStmt);
3504 ctas->relkind = OBJECT_MATVIEW;
3505 ctas->is_select_into = false;
3506 ctas->if_not_exists = false;
3507 /* cram additional flags into the IntoClause */
3508 $5->rel->relpersistence = $2;
3509 $5->skipData = !($8);
3512 | CREATE OptNoLog MATERIALIZED VIEW IF_P NOT EXISTS create_mv_target AS SelectStmt opt_with_data
3514 CreateTableAsStmt *ctas = makeNode(CreateTableAsStmt);
3517 ctas->relkind = OBJECT_MATVIEW;
3518 ctas->is_select_into = false;
3519 ctas->if_not_exists = true;
3520 /* cram additional flags into the IntoClause */
3521 $8->rel->relpersistence = $2;
3522 $8->skipData = !($11);
3528 qualified_name opt_column_list opt_reloptions OptTableSpace
3530 $$ = makeNode(IntoClause);
3534 $$->onCommit = ONCOMMIT_NOOP;
3535 $$->tableSpaceName = $4;
3536 $$->viewQuery = NULL; /* filled at analysis time */
3537 $$->skipData = false; /* might get changed later */
3541 OptNoLog: UNLOGGED { $$ = RELPERSISTENCE_UNLOGGED; }
3542 | /*EMPTY*/ { $$ = RELPERSISTENCE_PERMANENT; }
3546 /*****************************************************************************
3549 * REFRESH MATERIALIZED VIEW qualified_name
3551 *****************************************************************************/
3554 REFRESH MATERIALIZED VIEW opt_concurrently qualified_name opt_with_data
3556 RefreshMatViewStmt *n = makeNode(RefreshMatViewStmt);
3559 n->skipData = !($6);
3565 /*****************************************************************************
3568 * CREATE SEQUENCE seqname
3569 * ALTER SEQUENCE seqname
3571 *****************************************************************************/
3574 CREATE OptTemp SEQUENCE qualified_name OptSeqOptList
3576 CreateSeqStmt *n = makeNode(CreateSeqStmt);
3577 $4->relpersistence = $2;
3580 n->ownerId = InvalidOid;
3581 n->if_not_exists = false;
3584 | CREATE OptTemp SEQUENCE IF_P NOT EXISTS qualified_name OptSeqOptList
3586 CreateSeqStmt *n = makeNode(CreateSeqStmt);
3587 $7->relpersistence = $2;
3590 n->ownerId = InvalidOid;
3591 n->if_not_exists = true;
3597 ALTER SEQUENCE qualified_name SeqOptList
3599 AlterSeqStmt *n = makeNode(AlterSeqStmt);
3602 n->missing_ok = false;
3605 | ALTER SEQUENCE IF_P EXISTS qualified_name SeqOptList
3607 AlterSeqStmt *n = makeNode(AlterSeqStmt);
3610 n->missing_ok = true;
3616 OptSeqOptList: SeqOptList { $$ = $1; }
3617 | /*EMPTY*/ { $$ = NIL; }
3620 SeqOptList: SeqOptElem { $$ = list_make1($1); }
3621 | SeqOptList SeqOptElem { $$ = lappend($1, $2); }
3624 SeqOptElem: CACHE NumericOnly
3626 $$ = makeDefElem("cache", (Node *)$2);
3630 $$ = makeDefElem("cycle", (Node *)makeInteger(TRUE));
3634 $$ = makeDefElem("cycle", (Node *)makeInteger(FALSE));
3636 | INCREMENT opt_by NumericOnly
3638 $$ = makeDefElem("increment", (Node *)$3);
3640 | MAXVALUE NumericOnly
3642 $$ = makeDefElem("maxvalue", (Node *)$2);
3644 | MINVALUE NumericOnly
3646 $$ = makeDefElem("minvalue", (Node *)$2);
3650 $$ = makeDefElem("maxvalue", NULL);
3654 $$ = makeDefElem("minvalue", NULL);
3658 $$ = makeDefElem("owned_by", (Node *)$3);
3660 | START opt_with NumericOnly
3662 $$ = makeDefElem("start", (Node *)$3);
3666 $$ = makeDefElem("restart", NULL);
3668 | RESTART opt_with NumericOnly
3670 $$ = makeDefElem("restart", (Node *)$3);
3679 FCONST { $$ = makeFloat($1); }
3685 | SignedIconst { $$ = makeInteger($1); }
3688 NumericOnly_list: NumericOnly { $$ = list_make1($1); }
3689 | NumericOnly_list ',' NumericOnly { $$ = lappend($1, $3); }
3692 /*****************************************************************************
3695 * CREATE [OR REPLACE] [TRUSTED] [PROCEDURAL] LANGUAGE ...
3696 * DROP [PROCEDURAL] LANGUAGE ...
3698 *****************************************************************************/
3701 CREATE opt_or_replace opt_trusted opt_procedural LANGUAGE NonReservedWord_or_Sconst
3703 CreatePLangStmt *n = makeNode(CreatePLangStmt);
3706 /* parameters are all to be supplied by system */
3709 n->plvalidator = NIL;
3710 n->pltrusted = false;
3713 | CREATE opt_or_replace opt_trusted opt_procedural LANGUAGE NonReservedWord_or_Sconst
3714 HANDLER handler_name opt_inline_handler opt_validator
3716 CreatePLangStmt *n = makeNode(CreatePLangStmt);
3721 n->plvalidator = $10;
3728 TRUSTED { $$ = TRUE; }
3729 | /*EMPTY*/ { $$ = FALSE; }
3732 /* This ought to be just func_name, but that causes reduce/reduce conflicts
3733 * (CREATE LANGUAGE is the only place where func_name isn't followed by '(').
3734 * Work around by using simple names, instead.
3737 name { $$ = list_make1(makeString($1)); }
3738 | name attrs { $$ = lcons(makeString($1), $2); }
3742 INLINE_P handler_name { $$ = $2; }
3743 | /*EMPTY*/ { $$ = NIL; }
3747 VALIDATOR handler_name { $$ = $2; }
3748 | NO VALIDATOR { $$ = NIL; }
3752 validator_clause { $$ = $1; }
3753 | /*EMPTY*/ { $$ = NIL; }
3757 DROP opt_procedural LANGUAGE NonReservedWord_or_Sconst opt_drop_behavior
3759 DropStmt *n = makeNode(DropStmt);
3760 n->removeType = OBJECT_LANGUAGE;
3761 n->objects = list_make1(list_make1(makeString($4)));
3764 n->missing_ok = false;
3765 n->concurrent = false;
3768 | DROP opt_procedural LANGUAGE IF_P EXISTS NonReservedWord_or_Sconst opt_drop_behavior
3770 DropStmt *n = makeNode(DropStmt);
3771 n->removeType = OBJECT_LANGUAGE;
3772 n->objects = list_make1(list_make1(makeString($6)));
3774 n->missing_ok = true;
3775 n->concurrent = false;
3785 /*****************************************************************************
3788 * CREATE TABLESPACE tablespace LOCATION '/path/to/tablespace/'
3790 *****************************************************************************/
3792 CreateTableSpaceStmt: CREATE TABLESPACE name OptTableSpaceOwner LOCATION Sconst opt_reloptions
3794 CreateTableSpaceStmt *n = makeNode(CreateTableSpaceStmt);
3795 n->tablespacename = $3;
3803 OptTableSpaceOwner: OWNER RoleSpec { $$ = $2; }
3804 | /*EMPTY */ { $$ = NULL; }
3807 /*****************************************************************************
3810 * DROP TABLESPACE <tablespace>
3812 * No need for drop behaviour as we cannot implement dependencies for
3813 * objects in other databases; we can only support RESTRICT.
3815 ****************************************************************************/
3817 DropTableSpaceStmt: DROP TABLESPACE name
3819 DropTableSpaceStmt *n = makeNode(DropTableSpaceStmt);
3820 n->tablespacename = $3;
3821 n->missing_ok = false;
3824 | DROP TABLESPACE IF_P EXISTS name
3826 DropTableSpaceStmt *n = makeNode(DropTableSpaceStmt);
3827 n->tablespacename = $5;
3828 n->missing_ok = true;
3833 /*****************************************************************************
3836 * CREATE EXTENSION extension
3837 * [ WITH ] [ SCHEMA schema ] [ VERSION version ] [ FROM oldversion ]
3839 *****************************************************************************/
3841 CreateExtensionStmt: CREATE EXTENSION name opt_with create_extension_opt_list
3843 CreateExtensionStmt *n = makeNode(CreateExtensionStmt);
3845 n->if_not_exists = false;
3849 | CREATE EXTENSION IF_P NOT EXISTS name opt_with create_extension_opt_list
3851 CreateExtensionStmt *n = makeNode(CreateExtensionStmt);
3853 n->if_not_exists = true;
3859 create_extension_opt_list:
3860 create_extension_opt_list create_extension_opt_item
3861 { $$ = lappend($1, $2); }
3866 create_extension_opt_item:
3869 $$ = makeDefElem("schema", (Node *)makeString($2));
3871 | VERSION_P NonReservedWord_or_Sconst
3873 $$ = makeDefElem("new_version", (Node *)makeString($2));
3875 | FROM NonReservedWord_or_Sconst
3877 $$ = makeDefElem("old_version", (Node *)makeString($2));
3881 $$ = makeDefElem("cascade", (Node *)makeInteger(TRUE));
3885 /*****************************************************************************
3887 * ALTER EXTENSION name UPDATE [ TO version ]
3889 *****************************************************************************/
3891 AlterExtensionStmt: ALTER EXTENSION name UPDATE alter_extension_opt_list
3893 AlterExtensionStmt *n = makeNode(AlterExtensionStmt);
3900 alter_extension_opt_list:
3901 alter_extension_opt_list alter_extension_opt_item
3902 { $$ = lappend($1, $2); }
3907 alter_extension_opt_item:
3908 TO NonReservedWord_or_Sconst
3910 $$ = makeDefElem("new_version", (Node *)makeString($2));
3914 /*****************************************************************************
3916 * ALTER EXTENSION name ADD/DROP object-identifier
3918 *****************************************************************************/
3920 AlterExtensionContentsStmt:
3921 ALTER EXTENSION name add_drop AGGREGATE func_name aggr_args
3923 AlterExtensionContentsStmt *n = makeNode(AlterExtensionContentsStmt);
3926 n->objtype = OBJECT_AGGREGATE;
3928 n->objargs = extractAggrArgTypes($7);
3931 | ALTER EXTENSION name add_drop CAST '(' Typename AS Typename ')'
3933 AlterExtensionContentsStmt *n = makeNode(AlterExtensionContentsStmt);
3936 n->objtype = OBJECT_CAST;
3937 n->objname = list_make1($7);
3938 n->objargs = list_make1($9);
3941 | ALTER EXTENSION name add_drop COLLATION any_name
3943 AlterExtensionContentsStmt *n = makeNode(AlterExtensionContentsStmt);
3946 n->objtype = OBJECT_COLLATION;
3950 | ALTER EXTENSION name add_drop CONVERSION_P any_name
3952 AlterExtensionContentsStmt *n = makeNode(AlterExtensionContentsStmt);
3955 n->objtype = OBJECT_CONVERSION;
3959 | ALTER EXTENSION name add_drop DOMAIN_P Typename
3961 AlterExtensionContentsStmt *n = makeNode(AlterExtensionContentsStmt);
3964 n->objtype = OBJECT_DOMAIN;
3965 n->objname = list_make1($6);
3968 | ALTER EXTENSION name add_drop FUNCTION function_with_argtypes
3970 AlterExtensionContentsStmt *n = makeNode(AlterExtensionContentsStmt);
3973 n->objtype = OBJECT_FUNCTION;
3974 n->objname = $6->funcname;
3975 n->objargs = $6->funcargs;
3978 | ALTER EXTENSION name add_drop opt_procedural LANGUAGE name
3980 AlterExtensionContentsStmt *n = makeNode(AlterExtensionContentsStmt);
3983 n->objtype = OBJECT_LANGUAGE;
3984 n->objname = list_make1(makeString($7));
3987 | ALTER EXTENSION name add_drop OPERATOR any_operator oper_argtypes
3989 AlterExtensionContentsStmt *n = makeNode(AlterExtensionContentsStmt);
3992 n->objtype = OBJECT_OPERATOR;
3997 | ALTER EXTENSION name add_drop OPERATOR CLASS any_name USING access_method
3999 AlterExtensionContentsStmt *n = makeNode(AlterExtensionContentsStmt);
4002 n->objtype = OBJECT_OPCLASS;
4003 n->objname = lcons(makeString($9), $7);
4006 | ALTER EXTENSION name add_drop OPERATOR FAMILY any_name USING access_method
4008 AlterExtensionContentsStmt *n = makeNode(AlterExtensionContentsStmt);
4011 n->objtype = OBJECT_OPFAMILY;
4012 n->objname = lcons(makeString($9), $7);
4015 | ALTER EXTENSION name add_drop SCHEMA name
4017 AlterExtensionContentsStmt *n = makeNode(AlterExtensionContentsStmt);
4020 n->objtype = OBJECT_SCHEMA;
4021 n->objname = list_make1(makeString($6));
4024 | ALTER EXTENSION name add_drop EVENT TRIGGER name
4026 AlterExtensionContentsStmt *n = makeNode(AlterExtensionContentsStmt);
4029 n->objtype = OBJECT_EVENT_TRIGGER;
4030 n->objname = list_make1(makeString($7));
4033 | ALTER EXTENSION name add_drop TABLE any_name
4035 AlterExtensionContentsStmt *n = makeNode(AlterExtensionContentsStmt);
4038 n->objtype = OBJECT_TABLE;
4042 | ALTER EXTENSION name add_drop TEXT_P SEARCH PARSER any_name
4044 AlterExtensionContentsStmt *n = makeNode(AlterExtensionContentsStmt);
4047 n->objtype = OBJECT_TSPARSER;
4051 | ALTER EXTENSION name add_drop TEXT_P SEARCH DICTIONARY any_name
4053 AlterExtensionContentsStmt *n = makeNode(AlterExtensionContentsStmt);
4056 n->objtype = OBJECT_TSDICTIONARY;
4060 | ALTER EXTENSION name add_drop TEXT_P SEARCH TEMPLATE any_name
4062 AlterExtensionContentsStmt *n = makeNode(AlterExtensionContentsStmt);
4065 n->objtype = OBJECT_TSTEMPLATE;
4069 | ALTER EXTENSION name add_drop TEXT_P SEARCH CONFIGURATION any_name
4071 AlterExtensionContentsStmt *n = makeNode(AlterExtensionContentsStmt);
4074 n->objtype = OBJECT_TSCONFIGURATION;
4078 | ALTER EXTENSION name add_drop SEQUENCE any_name
4080 AlterExtensionContentsStmt *n = makeNode(AlterExtensionContentsStmt);
4083 n->objtype = OBJECT_SEQUENCE;
4087 | ALTER EXTENSION name add_drop VIEW any_name
4089 AlterExtensionContentsStmt *n = makeNode(AlterExtensionContentsStmt);
4092 n->objtype = OBJECT_VIEW;
4096 | ALTER EXTENSION name add_drop MATERIALIZED VIEW any_name
4098 AlterExtensionContentsStmt *n = makeNode(AlterExtensionContentsStmt);
4101 n->objtype = OBJECT_MATVIEW;
4105 | ALTER EXTENSION name add_drop FOREIGN TABLE any_name
4107 AlterExtensionContentsStmt *n = makeNode(AlterExtensionContentsStmt);
4110 n->objtype = OBJECT_FOREIGN_TABLE;
4114 | ALTER EXTENSION name add_drop FOREIGN DATA_P WRAPPER name
4116 AlterExtensionContentsStmt *n = makeNode(AlterExtensionContentsStmt);
4119 n->objtype = OBJECT_FDW;
4120 n->objname = list_make1(makeString($8));
4123 | ALTER EXTENSION name add_drop SERVER name
4125 AlterExtensionContentsStmt *n = makeNode(AlterExtensionContentsStmt);
4128 n->objtype = OBJECT_FOREIGN_SERVER;
4129 n->objname = list_make1(makeString($6));
4132 | ALTER EXTENSION name add_drop TRANSFORM FOR Typename LANGUAGE name
4134 AlterExtensionContentsStmt *n = makeNode(AlterExtensionContentsStmt);
4137 n->objtype = OBJECT_TRANSFORM;
4138 n->objname = list_make1($7);
4139 n->objargs = list_make1(makeString($9));
4142 | ALTER EXTENSION name add_drop TYPE_P Typename
4144 AlterExtensionContentsStmt *n = makeNode(AlterExtensionContentsStmt);
4147 n->objtype = OBJECT_TYPE;
4148 n->objname = list_make1($6);
4153 /*****************************************************************************
4156 * CREATE FOREIGN DATA WRAPPER name options
4158 *****************************************************************************/
4160 CreateFdwStmt: CREATE FOREIGN DATA_P WRAPPER name opt_fdw_options create_generic_options
4162 CreateFdwStmt *n = makeNode(CreateFdwStmt);
4164 n->func_options = $6;
4171 HANDLER handler_name { $$ = makeDefElem("handler", (Node *)$2); }
4172 | NO HANDLER { $$ = makeDefElem("handler", NULL); }
4173 | VALIDATOR handler_name { $$ = makeDefElem("validator", (Node *)$2); }
4174 | NO VALIDATOR { $$ = makeDefElem("validator", NULL); }
4178 fdw_option { $$ = list_make1($1); }
4179 | fdw_options fdw_option { $$ = lappend($1, $2); }
4183 fdw_options { $$ = $1; }
4184 | /*EMPTY*/ { $$ = NIL; }
4187 /*****************************************************************************
4190 * DROP FOREIGN DATA WRAPPER name
4192 ****************************************************************************/
4194 DropFdwStmt: DROP FOREIGN DATA_P WRAPPER name opt_drop_behavior
4196 DropStmt *n = makeNode(DropStmt);
4197 n->removeType = OBJECT_FDW;
4198 n->objects = list_make1(list_make1(makeString($5)));
4200 n->missing_ok = false;
4202 n->concurrent = false;
4205 | DROP FOREIGN DATA_P WRAPPER IF_P EXISTS name opt_drop_behavior
4207 DropStmt *n = makeNode(DropStmt);
4208 n->removeType = OBJECT_FDW;
4209 n->objects = list_make1(list_make1(makeString($7)));
4211 n->missing_ok = true;
4213 n->concurrent = false;
4218 /*****************************************************************************
4221 * ALTER FOREIGN DATA WRAPPER name options
4223 ****************************************************************************/
4225 AlterFdwStmt: ALTER FOREIGN DATA_P WRAPPER name opt_fdw_options alter_generic_options
4227 AlterFdwStmt *n = makeNode(AlterFdwStmt);
4229 n->func_options = $6;
4233 | ALTER FOREIGN DATA_P WRAPPER name fdw_options
4235 AlterFdwStmt *n = makeNode(AlterFdwStmt);
4237 n->func_options = $6;
4243 /* Options definition for CREATE FDW, SERVER and USER MAPPING */
4244 create_generic_options:
4245 OPTIONS '(' generic_option_list ')' { $$ = $3; }
4246 | /*EMPTY*/ { $$ = NIL; }
4249 generic_option_list:
4252 $$ = list_make1($1);
4254 | generic_option_list ',' generic_option_elem
4256 $$ = lappend($1, $3);
4260 /* Options definition for ALTER FDW, SERVER and USER MAPPING */
4261 alter_generic_options:
4262 OPTIONS '(' alter_generic_option_list ')' { $$ = $3; }
4265 alter_generic_option_list:
4266 alter_generic_option_elem
4268 $$ = list_make1($1);
4270 | alter_generic_option_list ',' alter_generic_option_elem
4272 $$ = lappend($1, $3);
4276 alter_generic_option_elem:
4281 | SET generic_option_elem
4284 $$->defaction = DEFELEM_SET;
4286 | ADD_P generic_option_elem
4289 $$->defaction = DEFELEM_ADD;
4291 | DROP generic_option_name
4293 $$ = makeDefElemExtended(NULL, $2, NULL, DEFELEM_DROP);
4297 generic_option_elem:
4298 generic_option_name generic_option_arg
4300 $$ = makeDefElem($1, $2);
4304 generic_option_name:
4305 ColLabel { $$ = $1; }
4308 /* We could use def_arg here, but the spec only requires string literals */
4310 Sconst { $$ = (Node *) makeString($1); }
4313 /*****************************************************************************
4316 * CREATE SERVER name [TYPE] [VERSION] [OPTIONS]
4318 *****************************************************************************/
4320 CreateForeignServerStmt: CREATE SERVER name opt_type opt_foreign_server_version
4321 FOREIGN DATA_P WRAPPER name create_generic_options
4323 CreateForeignServerStmt *n = makeNode(CreateForeignServerStmt);
4334 TYPE_P Sconst { $$ = $2; }
4335 | /*EMPTY*/ { $$ = NULL; }
4339 foreign_server_version:
4340 VERSION_P Sconst { $$ = $2; }
4341 | VERSION_P NULL_P { $$ = NULL; }
4344 opt_foreign_server_version:
4345 foreign_server_version { $$ = $1; }
4346 | /*EMPTY*/ { $$ = NULL; }
4349 /*****************************************************************************
4354 ****************************************************************************/
4356 DropForeignServerStmt: DROP SERVER name opt_drop_behavior
4358 DropStmt *n = makeNode(DropStmt);
4359 n->removeType = OBJECT_FOREIGN_SERVER;
4360 n->objects = list_make1(list_make1(makeString($3)));
4362 n->missing_ok = false;
4364 n->concurrent = false;
4367 | DROP SERVER IF_P EXISTS name opt_drop_behavior
4369 DropStmt *n = makeNode(DropStmt);
4370 n->removeType = OBJECT_FOREIGN_SERVER;
4371 n->objects = list_make1(list_make1(makeString($5)));
4373 n->missing_ok = true;
4375 n->concurrent = false;
4380 /*****************************************************************************
4383 * ALTER SERVER name [VERSION] [OPTIONS]
4385 ****************************************************************************/
4387 AlterForeignServerStmt: ALTER SERVER name foreign_server_version alter_generic_options
4389 AlterForeignServerStmt *n = makeNode(AlterForeignServerStmt);
4393 n->has_version = true;
4396 | ALTER SERVER name foreign_server_version
4398 AlterForeignServerStmt *n = makeNode(AlterForeignServerStmt);
4401 n->has_version = true;
4404 | ALTER SERVER name alter_generic_options
4406 AlterForeignServerStmt *n = makeNode(AlterForeignServerStmt);
4413 /*****************************************************************************
4416 * CREATE FOREIGN TABLE relname (...) SERVER name (...)
4418 *****************************************************************************/
4420 CreateForeignTableStmt:
4421 CREATE FOREIGN TABLE qualified_name
4422 '(' OptTableElementList ')'
4423 OptInherit SERVER name create_generic_options
4425 CreateForeignTableStmt *n = makeNode(CreateForeignTableStmt);
4426 $4->relpersistence = RELPERSISTENCE_PERMANENT;
4427 n->base.relation = $4;
4428 n->base.tableElts = $6;
4429 n->base.inhRelations = $8;
4430 n->base.ofTypename = NULL;
4431 n->base.constraints = NIL;
4432 n->base.options = NIL;
4433 n->base.oncommit = ONCOMMIT_NOOP;
4434 n->base.tablespacename = NULL;
4435 n->base.if_not_exists = false;
4436 /* FDW-specific data */
4437 n->servername = $10;
4441 | CREATE FOREIGN TABLE IF_P NOT EXISTS qualified_name
4442 '(' OptTableElementList ')'
4443 OptInherit SERVER name create_generic_options
4445 CreateForeignTableStmt *n = makeNode(CreateForeignTableStmt);
4446 $7->relpersistence = RELPERSISTENCE_PERMANENT;
4447 n->base.relation = $7;
4448 n->base.tableElts = $9;
4449 n->base.inhRelations = $11;
4450 n->base.ofTypename = NULL;
4451 n->base.constraints = NIL;
4452 n->base.options = NIL;
4453 n->base.oncommit = ONCOMMIT_NOOP;
4454 n->base.tablespacename = NULL;
4455 n->base.if_not_exists = true;
4456 /* FDW-specific data */
4457 n->servername = $13;
4463 /*****************************************************************************
4466 * ALTER FOREIGN TABLE relname [...]
4468 *****************************************************************************/
4470 AlterForeignTableStmt:
4471 ALTER FOREIGN TABLE relation_expr alter_table_cmds
4473 AlterTableStmt *n = makeNode(AlterTableStmt);
4476 n->relkind = OBJECT_FOREIGN_TABLE;
4477 n->missing_ok = false;
4480 | ALTER FOREIGN TABLE IF_P EXISTS relation_expr alter_table_cmds
4482 AlterTableStmt *n = makeNode(AlterTableStmt);
4485 n->relkind = OBJECT_FOREIGN_TABLE;
4486 n->missing_ok = true;
4491 /*****************************************************************************
4494 * IMPORT FOREIGN SCHEMA remote_schema
4495 * [ { LIMIT TO | EXCEPT } ( table_list ) ]
4496 * FROM SERVER server_name INTO local_schema [ OPTIONS (...) ]
4498 ****************************************************************************/
4500 ImportForeignSchemaStmt:
4501 IMPORT_P FOREIGN SCHEMA name import_qualification
4502 FROM SERVER name INTO name create_generic_options
4504 ImportForeignSchemaStmt *n = makeNode(ImportForeignSchemaStmt);
4505 n->server_name = $8;
4506 n->remote_schema = $4;
4507 n->local_schema = $10;
4508 n->list_type = $5->type;
4509 n->table_list = $5->table_names;
4515 import_qualification_type:
4516 LIMIT TO { $$ = FDW_IMPORT_SCHEMA_LIMIT_TO; }
4517 | EXCEPT { $$ = FDW_IMPORT_SCHEMA_EXCEPT; }
4520 import_qualification:
4521 import_qualification_type '(' relation_expr_list ')'
4523 ImportQual *n = (ImportQual *) palloc(sizeof(ImportQual));
4525 n->table_names = $3;
4530 ImportQual *n = (ImportQual *) palloc(sizeof(ImportQual));
4531 n->type = FDW_IMPORT_SCHEMA_ALL;
4532 n->table_names = NIL;
4537 /*****************************************************************************
4540 * CREATE USER MAPPING FOR auth_ident SERVER name [OPTIONS]
4542 *****************************************************************************/
4544 CreateUserMappingStmt: CREATE USER MAPPING FOR auth_ident SERVER name create_generic_options
4546 CreateUserMappingStmt *n = makeNode(CreateUserMappingStmt);
4554 /* User mapping authorization identifier */
4555 auth_ident: RoleSpec { $$ = $1; }
4556 | USER { $$ = makeRoleSpec(ROLESPEC_CURRENT_USER, @1); }
4559 /*****************************************************************************
4562 * DROP USER MAPPING FOR auth_ident SERVER name
4564 ****************************************************************************/
4566 DropUserMappingStmt: DROP USER MAPPING FOR auth_ident SERVER name
4568 DropUserMappingStmt *n = makeNode(DropUserMappingStmt);
4571 n->missing_ok = false;
4574 | DROP USER MAPPING IF_P EXISTS FOR auth_ident SERVER name
4576 DropUserMappingStmt *n = makeNode(DropUserMappingStmt);
4579 n->missing_ok = true;
4584 /*****************************************************************************
4587 * ALTER USER MAPPING FOR auth_ident SERVER name OPTIONS
4589 ****************************************************************************/
4591 AlterUserMappingStmt: ALTER USER MAPPING FOR auth_ident SERVER name alter_generic_options
4593 AlterUserMappingStmt *n = makeNode(AlterUserMappingStmt);
4601 /*****************************************************************************
4604 * CREATE POLICY name ON table [FOR cmd] [TO role, ...]
4605 * [USING (qual)] [WITH CHECK (with_check)]
4606 * ALTER POLICY name ON table [TO role, ...]
4607 * [USING (qual)] [WITH CHECK (with_check)]
4608 * DROP POLICY name ON table
4610 *****************************************************************************/
4613 CREATE POLICY name ON qualified_name RowSecurityDefaultForCmd
4614 RowSecurityDefaultToRole RowSecurityOptionalExpr
4615 RowSecurityOptionalWithCheck
4617 CreatePolicyStmt *n = makeNode(CreatePolicyStmt);
4618 n->policy_name = $3;
4629 ALTER POLICY name ON qualified_name RowSecurityOptionalToRole
4630 RowSecurityOptionalExpr RowSecurityOptionalWithCheck
4632 AlterPolicyStmt *n = makeNode(AlterPolicyStmt);
4633 n->policy_name = $3;
4643 DROP POLICY name ON any_name opt_drop_behavior
4645 DropStmt *n = makeNode(DropStmt);
4646 n->removeType = OBJECT_POLICY;
4647 n->objects = list_make1(lappend($5, makeString($3)));
4650 n->missing_ok = false;
4651 n->concurrent = false;
4654 | DROP POLICY IF_P EXISTS name ON any_name opt_drop_behavior
4656 DropStmt *n = makeNode(DropStmt);
4657 n->removeType = OBJECT_POLICY;
4658 n->objects = list_make1(lappend($7, makeString($5)));
4661 n->missing_ok = true;
4662 n->concurrent = false;
4667 RowSecurityOptionalExpr:
4668 USING '(' a_expr ')' { $$ = $3; }
4669 | /* EMPTY */ { $$ = NULL; }
4672 RowSecurityOptionalWithCheck:
4673 WITH CHECK '(' a_expr ')' { $$ = $4; }
4674 | /* EMPTY */ { $$ = NULL; }
4677 RowSecurityDefaultToRole:
4678 TO role_list { $$ = $2; }
4679 | /* EMPTY */ { $$ = list_make1(makeRoleSpec(ROLESPEC_PUBLIC, -1)); }
4682 RowSecurityOptionalToRole:
4683 TO role_list { $$ = $2; }
4684 | /* EMPTY */ { $$ = NULL; }
4687 RowSecurityDefaultForCmd:
4688 FOR row_security_cmd { $$ = $2; }
4689 | /* EMPTY */ { $$ = "all"; }
4694 | SELECT { $$ = "select"; }
4695 | INSERT { $$ = "insert"; }
4696 | UPDATE { $$ = "update"; }
4697 | DELETE_P { $$ = "delete"; }
4700 /*****************************************************************************
4703 * CREATE TRIGGER ...
4706 *****************************************************************************/
4709 CREATE TRIGGER name TriggerActionTime TriggerEvents ON
4710 qualified_name TriggerForSpec TriggerWhen
4711 EXECUTE PROCEDURE func_name '(' TriggerFuncArgs ')'
4713 CreateTrigStmt *n = makeNode(CreateTrigStmt);
4720 n->events = intVal(linitial($5));
4721 n->columns = (List *) lsecond($5);
4723 n->isconstraint = FALSE;
4724 n->deferrable = FALSE;
4725 n->initdeferred = FALSE;
4726 n->constrrel = NULL;
4729 | CREATE CONSTRAINT TRIGGER name AFTER TriggerEvents ON
4730 qualified_name OptConstrFromTable ConstraintAttributeSpec
4731 FOR EACH ROW TriggerWhen
4732 EXECUTE PROCEDURE func_name '(' TriggerFuncArgs ')'
4734 CreateTrigStmt *n = makeNode(CreateTrigStmt);
4740 n->timing = TRIGGER_TYPE_AFTER;
4741 n->events = intVal(linitial($6));
4742 n->columns = (List *) lsecond($6);
4743 n->whenClause = $14;
4744 n->isconstraint = TRUE;
4745 processCASbits($10, @10, "TRIGGER",
4746 &n->deferrable, &n->initdeferred, NULL,
4754 BEFORE { $$ = TRIGGER_TYPE_BEFORE; }
4755 | AFTER { $$ = TRIGGER_TYPE_AFTER; }
4756 | INSTEAD OF { $$ = TRIGGER_TYPE_INSTEAD; }
4762 | TriggerEvents OR TriggerOneEvent
4764 int events1 = intVal(linitial($1));
4765 int events2 = intVal(linitial($3));
4766 List *columns1 = (List *) lsecond($1);
4767 List *columns2 = (List *) lsecond($3);
4769 if (events1 & events2)
4770 parser_yyerror("duplicate trigger events specified");
4772 * concat'ing the columns lists loses information about
4773 * which columns went with which event, but so long as
4774 * only UPDATE carries columns and we disallow multiple
4775 * UPDATE items, it doesn't matter. Command execution
4776 * should just ignore the columns for non-UPDATE events.
4778 $$ = list_make2(makeInteger(events1 | events2),
4779 list_concat(columns1, columns2));
4785 { $$ = list_make2(makeInteger(TRIGGER_TYPE_INSERT), NIL); }
4787 { $$ = list_make2(makeInteger(TRIGGER_TYPE_DELETE), NIL); }
4789 { $$ = list_make2(makeInteger(TRIGGER_TYPE_UPDATE), NIL); }
4790 | UPDATE OF columnList
4791 { $$ = list_make2(makeInteger(TRIGGER_TYPE_UPDATE), $3); }
4793 { $$ = list_make2(makeInteger(TRIGGER_TYPE_TRUNCATE), NIL); }
4797 FOR TriggerForOptEach TriggerForType
4804 * If ROW/STATEMENT not specified, default to
4805 * STATEMENT, per SQL
4818 | STATEMENT { $$ = FALSE; }
4822 WHEN '(' a_expr ')' { $$ = $3; }
4823 | /*EMPTY*/ { $$ = NULL; }
4827 TriggerFuncArg { $$ = list_make1($1); }
4828 | TriggerFuncArgs ',' TriggerFuncArg { $$ = lappend($1, $3); }
4829 | /*EMPTY*/ { $$ = NIL; }
4835 $$ = makeString(psprintf("%d", $1));
4837 | FCONST { $$ = makeString($1); }
4838 | Sconst { $$ = makeString($1); }
4839 | ColLabel { $$ = makeString($1); }
4843 FROM qualified_name { $$ = $2; }
4844 | /*EMPTY*/ { $$ = NULL; }
4847 ConstraintAttributeSpec:
4850 | ConstraintAttributeSpec ConstraintAttributeElem
4853 * We must complain about conflicting options.
4854 * We could, but choose not to, complain about redundant
4855 * options (ie, where $2's bit is already set in $1).
4857 int newspec = $1 | $2;
4859 /* special message for this case */
4860 if ((newspec & (CAS_NOT_DEFERRABLE | CAS_INITIALLY_DEFERRED)) == (CAS_NOT_DEFERRABLE | CAS_INITIALLY_DEFERRED))
4862 (errcode(ERRCODE_SYNTAX_ERROR),
4863 errmsg("constraint declared INITIALLY DEFERRED must be DEFERRABLE"),
4864 parser_errposition(@2)));
4865 /* generic message for other conflicts */
4866 if ((newspec & (CAS_NOT_DEFERRABLE | CAS_DEFERRABLE)) == (CAS_NOT_DEFERRABLE | CAS_DEFERRABLE) ||
4867 (newspec & (CAS_INITIALLY_IMMEDIATE | CAS_INITIALLY_DEFERRED)) == (CAS_INITIALLY_IMMEDIATE | CAS_INITIALLY_DEFERRED))
4869 (errcode(ERRCODE_SYNTAX_ERROR),
4870 errmsg("conflicting constraint properties"),
4871 parser_errposition(@2)));
4876 ConstraintAttributeElem:
4877 NOT DEFERRABLE { $$ = CAS_NOT_DEFERRABLE; }
4878 | DEFERRABLE { $$ = CAS_DEFERRABLE; }
4879 | INITIALLY IMMEDIATE { $$ = CAS_INITIALLY_IMMEDIATE; }
4880 | INITIALLY DEFERRED { $$ = CAS_INITIALLY_DEFERRED; }
4881 | NOT VALID { $$ = CAS_NOT_VALID; }
4882 | NO INHERIT { $$ = CAS_NO_INHERIT; }
4887 DROP TRIGGER name ON any_name opt_drop_behavior
4889 DropStmt *n = makeNode(DropStmt);
4890 n->removeType = OBJECT_TRIGGER;
4891 n->objects = list_make1(lappend($5, makeString($3)));
4894 n->missing_ok = false;
4895 n->concurrent = false;
4898 | DROP TRIGGER IF_P EXISTS name ON any_name opt_drop_behavior
4900 DropStmt *n = makeNode(DropStmt);
4901 n->removeType = OBJECT_TRIGGER;
4902 n->objects = list_make1(lappend($7, makeString($5)));
4905 n->missing_ok = true;
4906 n->concurrent = false;
4912 /*****************************************************************************
4915 * CREATE EVENT TRIGGER ...
4916 * ALTER EVENT TRIGGER ...
4918 *****************************************************************************/
4920 CreateEventTrigStmt:
4921 CREATE EVENT TRIGGER name ON ColLabel
4922 EXECUTE PROCEDURE func_name '(' ')'
4924 CreateEventTrigStmt *n = makeNode(CreateEventTrigStmt);
4927 n->whenclause = NULL;
4931 | CREATE EVENT TRIGGER name ON ColLabel
4932 WHEN event_trigger_when_list
4933 EXECUTE PROCEDURE func_name '(' ')'
4935 CreateEventTrigStmt *n = makeNode(CreateEventTrigStmt);
4944 event_trigger_when_list:
4945 event_trigger_when_item
4946 { $$ = list_make1($1); }
4947 | event_trigger_when_list AND event_trigger_when_item
4948 { $$ = lappend($1, $3); }
4951 event_trigger_when_item:
4952 ColId IN_P '(' event_trigger_value_list ')'
4953 { $$ = makeDefElem($1, (Node *) $4); }
4956 event_trigger_value_list:
4958 { $$ = list_make1(makeString($1)); }
4959 | event_trigger_value_list ',' SCONST
4960 { $$ = lappend($1, makeString($3)); }
4964 ALTER EVENT TRIGGER name enable_trigger
4966 AlterEventTrigStmt *n = makeNode(AlterEventTrigStmt);
4974 ENABLE_P { $$ = TRIGGER_FIRES_ON_ORIGIN; }
4975 | ENABLE_P REPLICA { $$ = TRIGGER_FIRES_ON_REPLICA; }
4976 | ENABLE_P ALWAYS { $$ = TRIGGER_FIRES_ALWAYS; }
4977 | DISABLE_P { $$ = TRIGGER_DISABLED; }
4980 /*****************************************************************************
4983 * CREATE ASSERTION ...
4984 * DROP ASSERTION ...
4986 *****************************************************************************/
4989 CREATE ASSERTION name CHECK '(' a_expr ')'
4990 ConstraintAttributeSpec
4992 CreateTrigStmt *n = makeNode(CreateTrigStmt);
4994 n->args = list_make1($6);
4995 n->isconstraint = TRUE;
4996 processCASbits($8, @8, "ASSERTION",
4997 &n->deferrable, &n->initdeferred, NULL,
5001 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
5002 errmsg("CREATE ASSERTION is not yet implemented")));
5009 DROP ASSERTION name opt_drop_behavior
5011 DropStmt *n = makeNode(DropStmt);
5015 n->removeType = OBJECT_TRIGGER; /* XXX */
5017 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
5018 errmsg("DROP ASSERTION is not yet implemented")));
5024 /*****************************************************************************
5027 * define (aggregate,operator,type)
5029 *****************************************************************************/
5032 CREATE AGGREGATE func_name aggr_args definition
5034 DefineStmt *n = makeNode(DefineStmt);
5035 n->kind = OBJECT_AGGREGATE;
5036 n->oldstyle = false;
5042 | CREATE AGGREGATE func_name old_aggr_definition
5044 /* old-style (pre-8.2) syntax for CREATE AGGREGATE */
5045 DefineStmt *n = makeNode(DefineStmt);
5046 n->kind = OBJECT_AGGREGATE;
5053 | CREATE OPERATOR any_operator definition
5055 DefineStmt *n = makeNode(DefineStmt);
5056 n->kind = OBJECT_OPERATOR;
5057 n->oldstyle = false;
5063 | CREATE TYPE_P any_name definition
5065 DefineStmt *n = makeNode(DefineStmt);
5066 n->kind = OBJECT_TYPE;
5067 n->oldstyle = false;
5073 | CREATE TYPE_P any_name
5075 /* Shell type (identified by lack of definition) */
5076 DefineStmt *n = makeNode(DefineStmt);
5077 n->kind = OBJECT_TYPE;
5078 n->oldstyle = false;
5081 n->definition = NIL;
5084 | CREATE TYPE_P any_name AS '(' OptTableFuncElementList ')'
5086 CompositeTypeStmt *n = makeNode(CompositeTypeStmt);
5088 /* can't use qualified_name, sigh */
5089 n->typevar = makeRangeVarFromAnyName($3, @3, yyscanner);
5093 | CREATE TYPE_P any_name AS ENUM_P '(' opt_enum_val_list ')'
5095 CreateEnumStmt *n = makeNode(CreateEnumStmt);
5100 | CREATE TYPE_P any_name AS RANGE definition
5102 CreateRangeStmt *n = makeNode(CreateRangeStmt);
5107 | CREATE TEXT_P SEARCH PARSER any_name definition
5109 DefineStmt *n = makeNode(DefineStmt);
5110 n->kind = OBJECT_TSPARSER;
5116 | CREATE TEXT_P SEARCH DICTIONARY any_name definition
5118 DefineStmt *n = makeNode(DefineStmt);
5119 n->kind = OBJECT_TSDICTIONARY;
5125 | CREATE TEXT_P SEARCH TEMPLATE any_name definition
5127 DefineStmt *n = makeNode(DefineStmt);
5128 n->kind = OBJECT_TSTEMPLATE;
5134 | CREATE TEXT_P SEARCH CONFIGURATION any_name definition
5136 DefineStmt *n = makeNode(DefineStmt);
5137 n->kind = OBJECT_TSCONFIGURATION;
5143 | CREATE COLLATION any_name definition
5145 DefineStmt *n = makeNode(DefineStmt);
5146 n->kind = OBJECT_COLLATION;
5152 | CREATE COLLATION any_name FROM any_name
5154 DefineStmt *n = makeNode(DefineStmt);
5155 n->kind = OBJECT_COLLATION;
5158 n->definition = list_make1(makeDefElem("from", (Node *) $5));
5163 definition: '(' def_list ')' { $$ = $2; }
5166 def_list: def_elem { $$ = list_make1($1); }
5167 | def_list ',' def_elem { $$ = lappend($1, $3); }
5170 def_elem: ColLabel '=' def_arg
5172 $$ = makeDefElem($1, (Node *) $3);
5176 $$ = makeDefElem($1, NULL);
5180 /* Note: any simple identifier will be returned as a type name! */
5181 def_arg: func_type { $$ = (Node *)$1; }
5182 | reserved_keyword { $$ = (Node *)makeString(pstrdup($1)); }
5183 | qual_all_Op { $$ = (Node *)$1; }
5184 | NumericOnly { $$ = (Node *)$1; }
5185 | Sconst { $$ = (Node *)makeString($1); }
5188 old_aggr_definition: '(' old_aggr_list ')' { $$ = $2; }
5191 old_aggr_list: old_aggr_elem { $$ = list_make1($1); }
5192 | old_aggr_list ',' old_aggr_elem { $$ = lappend($1, $3); }
5196 * Must use IDENT here to avoid reduce/reduce conflicts; fortunately none of
5197 * the item names needed in old aggregate definitions are likely to become
5200 old_aggr_elem: IDENT '=' def_arg
5202 $$ = makeDefElem($1, (Node *)$3);
5207 enum_val_list { $$ = $1; }
5208 | /*EMPTY*/ { $$ = NIL; }
5211 enum_val_list: Sconst
5212 { $$ = list_make1(makeString($1)); }
5213 | enum_val_list ',' Sconst
5214 { $$ = lappend($1, makeString($3)); }
5217 /*****************************************************************************
5219 * ALTER TYPE enumtype ADD ...
5221 *****************************************************************************/
5224 ALTER TYPE_P any_name ADD_P VALUE_P opt_if_not_exists Sconst
5226 AlterEnumStmt *n = makeNode(AlterEnumStmt);
5229 n->newValNeighbor = NULL;
5230 n->newValIsAfter = true;
5231 n->skipIfExists = $6;
5234 | ALTER TYPE_P any_name ADD_P VALUE_P opt_if_not_exists Sconst BEFORE Sconst
5236 AlterEnumStmt *n = makeNode(AlterEnumStmt);
5239 n->newValNeighbor = $9;
5240 n->newValIsAfter = false;
5241 n->skipIfExists = $6;
5244 | ALTER TYPE_P any_name ADD_P VALUE_P opt_if_not_exists Sconst AFTER Sconst
5246 AlterEnumStmt *n = makeNode(AlterEnumStmt);
5249 n->newValNeighbor = $9;
5250 n->newValIsAfter = true;
5251 n->skipIfExists = $6;
5256 opt_if_not_exists: IF_P NOT EXISTS { $$ = true; }
5257 | /* empty */ { $$ = false; }
5261 /*****************************************************************************
5264 * CREATE OPERATOR CLASS ...
5265 * CREATE OPERATOR FAMILY ...
5266 * ALTER OPERATOR FAMILY ...
5267 * DROP OPERATOR CLASS ...
5268 * DROP OPERATOR FAMILY ...
5270 *****************************************************************************/
5273 CREATE OPERATOR CLASS any_name opt_default FOR TYPE_P Typename
5274 USING access_method opt_opfamily AS opclass_item_list
5276 CreateOpClassStmt *n = makeNode(CreateOpClassStmt);
5277 n->opclassname = $4;
5281 n->opfamilyname = $11;
5288 opclass_item { $$ = list_make1($1); }
5289 | opclass_item_list ',' opclass_item { $$ = lappend($1, $3); }
5293 OPERATOR Iconst any_operator opclass_purpose opt_recheck
5295 CreateOpClassItem *n = makeNode(CreateOpClassItem);
5296 n->itemtype = OPCLASS_ITEM_OPERATOR;
5300 n->order_family = $4;
5303 | OPERATOR Iconst any_operator oper_argtypes opclass_purpose
5306 CreateOpClassItem *n = makeNode(CreateOpClassItem);
5307 n->itemtype = OPCLASS_ITEM_OPERATOR;
5311 n->order_family = $5;
5314 | FUNCTION Iconst func_name func_args
5316 CreateOpClassItem *n = makeNode(CreateOpClassItem);
5317 n->itemtype = OPCLASS_ITEM_FUNCTION;
5319 n->args = extractArgTypes($4);
5323 | FUNCTION Iconst '(' type_list ')' func_name func_args
5325 CreateOpClassItem *n = makeNode(CreateOpClassItem);
5326 n->itemtype = OPCLASS_ITEM_FUNCTION;
5328 n->args = extractArgTypes($7);
5335 CreateOpClassItem *n = makeNode(CreateOpClassItem);
5336 n->itemtype = OPCLASS_ITEM_STORAGETYPE;
5342 opt_default: DEFAULT { $$ = TRUE; }
5343 | /*EMPTY*/ { $$ = FALSE; }
5346 opt_opfamily: FAMILY any_name { $$ = $2; }
5347 | /*EMPTY*/ { $$ = NIL; }
5350 opclass_purpose: FOR SEARCH { $$ = NIL; }
5351 | FOR ORDER BY any_name { $$ = $4; }
5352 | /*EMPTY*/ { $$ = NIL; }
5355 opt_recheck: RECHECK
5358 * RECHECK no longer does anything in opclass definitions,
5359 * but we still accept it to ease porting of old database
5363 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
5364 errmsg("RECHECK is no longer required"),
5365 errhint("Update your data type."),
5366 parser_errposition(@1)));
5369 | /*EMPTY*/ { $$ = FALSE; }
5374 CREATE OPERATOR FAMILY any_name USING access_method
5376 CreateOpFamilyStmt *n = makeNode(CreateOpFamilyStmt);
5377 n->opfamilyname = $4;
5384 ALTER OPERATOR FAMILY any_name USING access_method ADD_P opclass_item_list
5386 AlterOpFamilyStmt *n = makeNode(AlterOpFamilyStmt);
5387 n->opfamilyname = $4;
5393 | ALTER OPERATOR FAMILY any_name USING access_method DROP opclass_drop_list
5395 AlterOpFamilyStmt *n = makeNode(AlterOpFamilyStmt);
5396 n->opfamilyname = $4;
5405 opclass_drop { $$ = list_make1($1); }
5406 | opclass_drop_list ',' opclass_drop { $$ = lappend($1, $3); }
5410 OPERATOR Iconst '(' type_list ')'
5412 CreateOpClassItem *n = makeNode(CreateOpClassItem);
5413 n->itemtype = OPCLASS_ITEM_OPERATOR;
5418 | FUNCTION Iconst '(' type_list ')'
5420 CreateOpClassItem *n = makeNode(CreateOpClassItem);
5421 n->itemtype = OPCLASS_ITEM_FUNCTION;
5430 DROP OPERATOR CLASS any_name USING access_method opt_drop_behavior
5432 DropStmt *n = makeNode(DropStmt);
5433 n->objects = list_make1(lcons(makeString($6), $4));
5434 n->removeType = OBJECT_OPCLASS;
5436 n->missing_ok = false;
5437 n->concurrent = false;
5440 | DROP OPERATOR CLASS IF_P EXISTS any_name USING access_method opt_drop_behavior
5442 DropStmt *n = makeNode(DropStmt);
5443 n->objects = list_make1(lcons(makeString($8), $6));
5444 n->removeType = OBJECT_OPCLASS;
5446 n->missing_ok = true;
5447 n->concurrent = false;
5453 DROP OPERATOR FAMILY any_name USING access_method opt_drop_behavior
5455 DropStmt *n = makeNode(DropStmt);
5456 n->objects = list_make1(lcons(makeString($6), $4));
5457 n->removeType = OBJECT_OPFAMILY;
5459 n->missing_ok = false;
5460 n->concurrent = false;
5463 | DROP OPERATOR FAMILY IF_P EXISTS any_name USING access_method opt_drop_behavior
5465 DropStmt *n = makeNode(DropStmt);
5466 n->objects = list_make1(lcons(makeString($8), $6));
5467 n->removeType = OBJECT_OPFAMILY;
5469 n->missing_ok = true;
5470 n->concurrent = false;
5476 /*****************************************************************************
5480 * DROP OWNED BY username [, username ...] [ RESTRICT | CASCADE ]
5481 * REASSIGN OWNED BY username [, username ...] TO username
5483 *****************************************************************************/
5485 DROP OWNED BY role_list opt_drop_behavior
5487 DropOwnedStmt *n = makeNode(DropOwnedStmt);
5495 REASSIGN OWNED BY role_list TO RoleSpec
5497 ReassignOwnedStmt *n = makeNode(ReassignOwnedStmt);
5504 /*****************************************************************************
5508 * DROP itemtype [ IF EXISTS ] itemname [, itemname ...]
5509 * [ RESTRICT | CASCADE ]
5511 *****************************************************************************/
5513 DropStmt: DROP drop_type IF_P EXISTS any_name_list opt_drop_behavior
5515 DropStmt *n = makeNode(DropStmt);
5517 n->missing_ok = TRUE;
5521 n->concurrent = false;
5524 | DROP drop_type any_name_list opt_drop_behavior
5526 DropStmt *n = makeNode(DropStmt);
5528 n->missing_ok = FALSE;
5532 n->concurrent = false;
5535 | DROP TYPE_P type_name_list opt_drop_behavior
5537 DropStmt *n = makeNode(DropStmt);
5538 n->removeType = OBJECT_TYPE;
5539 n->missing_ok = FALSE;
5542 n->concurrent = false;
5545 | DROP TYPE_P IF_P EXISTS type_name_list opt_drop_behavior
5547 DropStmt *n = makeNode(DropStmt);
5548 n->removeType = OBJECT_TYPE;
5549 n->missing_ok = TRUE;
5552 n->concurrent = false;
5555 | DROP DOMAIN_P type_name_list opt_drop_behavior
5557 DropStmt *n = makeNode(DropStmt);
5558 n->removeType = OBJECT_DOMAIN;
5559 n->missing_ok = FALSE;
5562 n->concurrent = false;
5565 | DROP DOMAIN_P IF_P EXISTS type_name_list opt_drop_behavior
5567 DropStmt *n = makeNode(DropStmt);
5568 n->removeType = OBJECT_DOMAIN;
5569 n->missing_ok = TRUE;
5572 n->concurrent = false;
5575 | DROP INDEX CONCURRENTLY any_name_list opt_drop_behavior
5577 DropStmt *n = makeNode(DropStmt);
5578 n->removeType = OBJECT_INDEX;
5579 n->missing_ok = FALSE;
5583 n->concurrent = true;
5586 | DROP INDEX CONCURRENTLY IF_P EXISTS any_name_list opt_drop_behavior
5588 DropStmt *n = makeNode(DropStmt);
5589 n->removeType = OBJECT_INDEX;
5590 n->missing_ok = TRUE;
5594 n->concurrent = true;
5600 drop_type: TABLE { $$ = OBJECT_TABLE; }
5601 | SEQUENCE { $$ = OBJECT_SEQUENCE; }
5602 | VIEW { $$ = OBJECT_VIEW; }
5603 | MATERIALIZED VIEW { $$ = OBJECT_MATVIEW; }
5604 | INDEX { $$ = OBJECT_INDEX; }
5605 | FOREIGN TABLE { $$ = OBJECT_FOREIGN_TABLE; }
5606 | EVENT TRIGGER { $$ = OBJECT_EVENT_TRIGGER; }
5607 | COLLATION { $$ = OBJECT_COLLATION; }
5608 | CONVERSION_P { $$ = OBJECT_CONVERSION; }
5609 | SCHEMA { $$ = OBJECT_SCHEMA; }
5610 | EXTENSION { $$ = OBJECT_EXTENSION; }
5611 | TEXT_P SEARCH PARSER { $$ = OBJECT_TSPARSER; }
5612 | TEXT_P SEARCH DICTIONARY { $$ = OBJECT_TSDICTIONARY; }
5613 | TEXT_P SEARCH TEMPLATE { $$ = OBJECT_TSTEMPLATE; }
5614 | TEXT_P SEARCH CONFIGURATION { $$ = OBJECT_TSCONFIGURATION; }
5618 any_name { $$ = list_make1($1); }
5619 | any_name_list ',' any_name { $$ = lappend($1, $3); }
5622 any_name: ColId { $$ = list_make1(makeString($1)); }
5623 | ColId attrs { $$ = lcons(makeString($1), $2); }
5626 attrs: '.' attr_name
5627 { $$ = list_make1(makeString($2)); }
5628 | attrs '.' attr_name
5629 { $$ = lappend($1, makeString($3)); }
5633 Typename { $$ = list_make1(list_make1($1)); }
5634 | type_name_list ',' Typename { $$ = lappend($1, list_make1($3)); }
5636 /*****************************************************************************
5639 * truncate table relname1, relname2, ...
5641 *****************************************************************************/
5644 TRUNCATE opt_table relation_expr_list opt_restart_seqs opt_drop_behavior
5646 TruncateStmt *n = makeNode(TruncateStmt);
5648 n->restart_seqs = $4;
5655 CONTINUE_P IDENTITY_P { $$ = false; }
5656 | RESTART IDENTITY_P { $$ = true; }
5657 | /* EMPTY */ { $$ = false; }
5660 /*****************************************************************************
5662 * The COMMENT ON statement can take different forms based upon the type of
5663 * the object associated with the comment. The form of the statement is:
5665 * COMMENT ON [ [ CONVERSION | COLLATION | DATABASE | DOMAIN |
5666 * EXTENSION | EVENT TRIGGER | FOREIGN DATA WRAPPER |
5667 * FOREIGN TABLE | INDEX | [PROCEDURAL] LANGUAGE |
5668 * MATERIALIZED VIEW | POLICY | ROLE | SCHEMA | SEQUENCE |
5669 * SERVER | TABLE | TABLESPACE |
5670 * TEXT SEARCH CONFIGURATION | TEXT SEARCH DICTIONARY |
5671 * TEXT SEARCH PARSER | TEXT SEARCH TEMPLATE | TYPE |
5673 * AGGREGATE <aggname> (arg1, ...) |
5674 * CAST (<src type> AS <dst type>) |
5675 * COLUMN <relname>.<colname> |
5676 * CONSTRAINT <constraintname> ON <relname> |
5677 * CONSTRAINT <constraintname> ON DOMAIN <domainname> |
5678 * FUNCTION <funcname> (arg1, arg2, ...) |
5679 * LARGE OBJECT <oid> |
5680 * OPERATOR <op> (leftoperand_typ, rightoperand_typ) |
5681 * OPERATOR CLASS <name> USING <access-method> |
5682 * OPERATOR FAMILY <name> USING <access-method> |
5683 * RULE <rulename> ON <relname> |
5684 * TRIGGER <triggername> ON <relname> ]
5687 *****************************************************************************/
5690 COMMENT ON comment_type any_name IS comment_text
5692 CommentStmt *n = makeNode(CommentStmt);
5699 | COMMENT ON TYPE_P Typename IS comment_text
5701 CommentStmt *n = makeNode(CommentStmt);
5702 n->objtype = OBJECT_TYPE;
5703 n->objname = list_make1($4);
5708 | COMMENT ON DOMAIN_P Typename IS comment_text
5710 CommentStmt *n = makeNode(CommentStmt);
5711 n->objtype = OBJECT_DOMAIN;
5712 n->objname = list_make1($4);
5717 | COMMENT ON AGGREGATE func_name aggr_args IS comment_text
5719 CommentStmt *n = makeNode(CommentStmt);
5720 n->objtype = OBJECT_AGGREGATE;
5722 n->objargs = extractAggrArgTypes($5);
5726 | COMMENT ON FUNCTION func_name func_args IS comment_text
5728 CommentStmt *n = makeNode(CommentStmt);
5729 n->objtype = OBJECT_FUNCTION;
5731 n->objargs = extractArgTypes($5);
5735 | COMMENT ON OPERATOR any_operator oper_argtypes IS comment_text
5737 CommentStmt *n = makeNode(CommentStmt);
5738 n->objtype = OBJECT_OPERATOR;
5744 | COMMENT ON CONSTRAINT name ON any_name IS comment_text
5746 CommentStmt *n = makeNode(CommentStmt);
5747 n->objtype = OBJECT_TABCONSTRAINT;
5748 n->objname = lappend($6, makeString($4));
5753 | COMMENT ON CONSTRAINT name ON DOMAIN_P any_name IS comment_text
5755 CommentStmt *n = makeNode(CommentStmt);
5756 n->objtype = OBJECT_DOMCONSTRAINT;
5758 * should use Typename not any_name in the production, but
5759 * there's a shift/reduce conflict if we do that, so fix it
5762 n->objname = list_make1(makeTypeNameFromNameList($7));
5763 n->objargs = list_make1(makeString($4));
5767 | COMMENT ON POLICY name ON any_name IS comment_text
5769 CommentStmt *n = makeNode(CommentStmt);
5770 n->objtype = OBJECT_POLICY;
5771 n->objname = lappend($6, makeString($4));
5776 | COMMENT ON RULE name ON any_name IS comment_text
5778 CommentStmt *n = makeNode(CommentStmt);
5779 n->objtype = OBJECT_RULE;
5780 n->objname = lappend($6, makeString($4));
5785 | COMMENT ON RULE name IS comment_text
5787 /* Obsolete syntax supported for awhile for compatibility */
5788 CommentStmt *n = makeNode(CommentStmt);
5789 n->objtype = OBJECT_RULE;
5790 n->objname = list_make1(makeString($4));
5795 | COMMENT ON TRANSFORM FOR Typename LANGUAGE name IS comment_text
5797 CommentStmt *n = makeNode(CommentStmt);
5798 n->objtype = OBJECT_TRANSFORM;
5799 n->objname = list_make1($5);
5800 n->objargs = list_make1(makeString($7));
5804 | COMMENT ON TRIGGER name ON any_name IS comment_text
5806 CommentStmt *n = makeNode(CommentStmt);
5807 n->objtype = OBJECT_TRIGGER;
5808 n->objname = lappend($6, makeString($4));
5813 | COMMENT ON OPERATOR CLASS any_name USING access_method IS comment_text
5815 CommentStmt *n = makeNode(CommentStmt);
5816 n->objtype = OBJECT_OPCLASS;
5817 n->objname = lcons(makeString($7), $5);
5821 | COMMENT ON OPERATOR FAMILY any_name USING access_method IS comment_text
5823 CommentStmt *n = makeNode(CommentStmt);
5824 n->objtype = OBJECT_OPFAMILY;
5825 n->objname = lcons(makeString($7), $5);
5830 | COMMENT ON LARGE_P OBJECT_P NumericOnly IS comment_text
5832 CommentStmt *n = makeNode(CommentStmt);
5833 n->objtype = OBJECT_LARGEOBJECT;
5834 n->objname = list_make1($5);
5839 | COMMENT ON CAST '(' Typename AS Typename ')' IS comment_text
5841 CommentStmt *n = makeNode(CommentStmt);
5842 n->objtype = OBJECT_CAST;
5843 n->objname = list_make1($5);
5844 n->objargs = list_make1($7);
5848 | COMMENT ON opt_procedural LANGUAGE any_name IS comment_text
5850 CommentStmt *n = makeNode(CommentStmt);
5851 n->objtype = OBJECT_LANGUAGE;
5860 COLUMN { $$ = OBJECT_COLUMN; }
5861 | DATABASE { $$ = OBJECT_DATABASE; }
5862 | SCHEMA { $$ = OBJECT_SCHEMA; }
5863 | INDEX { $$ = OBJECT_INDEX; }
5864 | SEQUENCE { $$ = OBJECT_SEQUENCE; }
5865 | TABLE { $$ = OBJECT_TABLE; }
5866 | VIEW { $$ = OBJECT_VIEW; }
5867 | MATERIALIZED VIEW { $$ = OBJECT_MATVIEW; }
5868 | COLLATION { $$ = OBJECT_COLLATION; }
5869 | CONVERSION_P { $$ = OBJECT_CONVERSION; }
5870 | TABLESPACE { $$ = OBJECT_TABLESPACE; }
5871 | EXTENSION { $$ = OBJECT_EXTENSION; }
5872 | ROLE { $$ = OBJECT_ROLE; }
5873 | FOREIGN TABLE { $$ = OBJECT_FOREIGN_TABLE; }
5874 | SERVER { $$ = OBJECT_FOREIGN_SERVER; }
5875 | FOREIGN DATA_P WRAPPER { $$ = OBJECT_FDW; }
5876 | EVENT TRIGGER { $$ = OBJECT_EVENT_TRIGGER; }
5877 | TEXT_P SEARCH CONFIGURATION { $$ = OBJECT_TSCONFIGURATION; }
5878 | TEXT_P SEARCH DICTIONARY { $$ = OBJECT_TSDICTIONARY; }
5879 | TEXT_P SEARCH PARSER { $$ = OBJECT_TSPARSER; }
5880 | TEXT_P SEARCH TEMPLATE { $$ = OBJECT_TSTEMPLATE; }
5885 | NULL_P { $$ = NULL; }
5889 /*****************************************************************************
5891 * SECURITY LABEL [FOR <provider>] ON <object> IS <label>
5893 * As with COMMENT ON, <object> can refer to various types of database
5894 * objects (e.g. TABLE, COLUMN, etc.).
5896 *****************************************************************************/
5899 SECURITY LABEL opt_provider ON security_label_type any_name
5902 SecLabelStmt *n = makeNode(SecLabelStmt);
5910 | SECURITY LABEL opt_provider ON TYPE_P Typename
5913 SecLabelStmt *n = makeNode(SecLabelStmt);
5915 n->objtype = OBJECT_TYPE;
5916 n->objname = list_make1($6);
5921 | SECURITY LABEL opt_provider ON DOMAIN_P Typename
5924 SecLabelStmt *n = makeNode(SecLabelStmt);
5926 n->objtype = OBJECT_TYPE;
5927 n->objname = list_make1($6);
5932 | SECURITY LABEL opt_provider ON AGGREGATE func_name aggr_args
5935 SecLabelStmt *n = makeNode(SecLabelStmt);
5937 n->objtype = OBJECT_AGGREGATE;
5939 n->objargs = extractAggrArgTypes($7);
5943 | SECURITY LABEL opt_provider ON FUNCTION func_name func_args
5946 SecLabelStmt *n = makeNode(SecLabelStmt);
5948 n->objtype = OBJECT_FUNCTION;
5950 n->objargs = extractArgTypes($7);
5954 | SECURITY LABEL opt_provider ON LARGE_P OBJECT_P NumericOnly
5957 SecLabelStmt *n = makeNode(SecLabelStmt);
5959 n->objtype = OBJECT_LARGEOBJECT;
5960 n->objname = list_make1($7);
5965 | SECURITY LABEL opt_provider ON opt_procedural LANGUAGE any_name
5968 SecLabelStmt *n = makeNode(SecLabelStmt);
5970 n->objtype = OBJECT_LANGUAGE;
5978 opt_provider: FOR NonReservedWord_or_Sconst { $$ = $2; }
5979 | /* empty */ { $$ = NULL; }
5982 security_label_type:
5983 COLUMN { $$ = OBJECT_COLUMN; }
5984 | DATABASE { $$ = OBJECT_DATABASE; }
5985 | EVENT TRIGGER { $$ = OBJECT_EVENT_TRIGGER; }
5986 | FOREIGN TABLE { $$ = OBJECT_FOREIGN_TABLE; }
5987 | SCHEMA { $$ = OBJECT_SCHEMA; }
5988 | SEQUENCE { $$ = OBJECT_SEQUENCE; }
5989 | TABLE { $$ = OBJECT_TABLE; }
5990 | ROLE { $$ = OBJECT_ROLE; }
5991 | TABLESPACE { $$ = OBJECT_TABLESPACE; }
5992 | VIEW { $$ = OBJECT_VIEW; }
5993 | MATERIALIZED VIEW { $$ = OBJECT_MATVIEW; }
5996 security_label: Sconst { $$ = $1; }
5997 | NULL_P { $$ = NULL; }
6000 /*****************************************************************************
6005 *****************************************************************************/
6007 FetchStmt: FETCH fetch_args
6009 FetchStmt *n = (FetchStmt *) $2;
6015 FetchStmt *n = (FetchStmt *) $2;
6021 fetch_args: cursor_name
6023 FetchStmt *n = makeNode(FetchStmt);
6025 n->direction = FETCH_FORWARD;
6029 | from_in cursor_name
6031 FetchStmt *n = makeNode(FetchStmt);
6033 n->direction = FETCH_FORWARD;
6037 | NEXT opt_from_in cursor_name
6039 FetchStmt *n = makeNode(FetchStmt);
6041 n->direction = FETCH_FORWARD;
6045 | PRIOR opt_from_in cursor_name
6047 FetchStmt *n = makeNode(FetchStmt);
6049 n->direction = FETCH_BACKWARD;
6053 | FIRST_P opt_from_in cursor_name
6055 FetchStmt *n = makeNode(FetchStmt);
6057 n->direction = FETCH_ABSOLUTE;
6061 | LAST_P opt_from_in cursor_name
6063 FetchStmt *n = makeNode(FetchStmt);
6065 n->direction = FETCH_ABSOLUTE;
6069 | ABSOLUTE_P SignedIconst opt_from_in cursor_name
6071 FetchStmt *n = makeNode(FetchStmt);
6073 n->direction = FETCH_ABSOLUTE;
6077 | RELATIVE_P SignedIconst opt_from_in cursor_name
6079 FetchStmt *n = makeNode(FetchStmt);
6081 n->direction = FETCH_RELATIVE;
6085 | SignedIconst opt_from_in cursor_name
6087 FetchStmt *n = makeNode(FetchStmt);
6089 n->direction = FETCH_FORWARD;
6093 | ALL opt_from_in cursor_name
6095 FetchStmt *n = makeNode(FetchStmt);
6097 n->direction = FETCH_FORWARD;
6098 n->howMany = FETCH_ALL;
6101 | FORWARD opt_from_in cursor_name
6103 FetchStmt *n = makeNode(FetchStmt);
6105 n->direction = FETCH_FORWARD;
6109 | FORWARD SignedIconst opt_from_in cursor_name
6111 FetchStmt *n = makeNode(FetchStmt);
6113 n->direction = FETCH_FORWARD;
6117 | FORWARD ALL opt_from_in cursor_name
6119 FetchStmt *n = makeNode(FetchStmt);
6121 n->direction = FETCH_FORWARD;
6122 n->howMany = FETCH_ALL;
6125 | BACKWARD opt_from_in cursor_name
6127 FetchStmt *n = makeNode(FetchStmt);
6129 n->direction = FETCH_BACKWARD;
6133 | BACKWARD SignedIconst opt_from_in cursor_name
6135 FetchStmt *n = makeNode(FetchStmt);
6137 n->direction = FETCH_BACKWARD;
6141 | BACKWARD ALL opt_from_in cursor_name
6143 FetchStmt *n = makeNode(FetchStmt);
6145 n->direction = FETCH_BACKWARD;
6146 n->howMany = FETCH_ALL;
6155 opt_from_in: from_in {}
6160 /*****************************************************************************
6162 * GRANT and REVOKE statements
6164 *****************************************************************************/
6166 GrantStmt: GRANT privileges ON privilege_target TO grantee_list
6167 opt_grant_grant_option
6169 GrantStmt *n = makeNode(GrantStmt);
6172 n->targtype = ($4)->targtype;
6173 n->objtype = ($4)->objtype;
6174 n->objects = ($4)->objs;
6176 n->grant_option = $7;
6182 REVOKE privileges ON privilege_target
6183 FROM grantee_list opt_drop_behavior
6185 GrantStmt *n = makeNode(GrantStmt);
6186 n->is_grant = false;
6187 n->grant_option = false;
6189 n->targtype = ($4)->targtype;
6190 n->objtype = ($4)->objtype;
6191 n->objects = ($4)->objs;
6196 | REVOKE GRANT OPTION FOR privileges ON privilege_target
6197 FROM grantee_list opt_drop_behavior
6199 GrantStmt *n = makeNode(GrantStmt);
6200 n->is_grant = false;
6201 n->grant_option = true;
6203 n->targtype = ($7)->targtype;
6204 n->objtype = ($7)->objtype;
6205 n->objects = ($7)->objs;
6214 * Privilege names are represented as strings; the validity of the privilege
6215 * names gets checked at execution. This is a bit annoying but we have little
6216 * choice because of the syntactic conflict with lists of role names in
6217 * GRANT/REVOKE. What's more, we have to call out in the "privilege"
6218 * production any reserved keywords that need to be usable as privilege names.
6221 /* either ALL [PRIVILEGES] or a list of individual privileges */
6222 privileges: privilege_list
6228 | ALL '(' columnList ')'
6230 AccessPriv *n = makeNode(AccessPriv);
6231 n->priv_name = NULL;
6235 | ALL PRIVILEGES '(' columnList ')'
6237 AccessPriv *n = makeNode(AccessPriv);
6238 n->priv_name = NULL;
6244 privilege_list: privilege { $$ = list_make1($1); }
6245 | privilege_list ',' privilege { $$ = lappend($1, $3); }
6248 privilege: SELECT opt_column_list
6250 AccessPriv *n = makeNode(AccessPriv);
6251 n->priv_name = pstrdup($1);
6255 | REFERENCES opt_column_list
6257 AccessPriv *n = makeNode(AccessPriv);
6258 n->priv_name = pstrdup($1);
6262 | CREATE opt_column_list
6264 AccessPriv *n = makeNode(AccessPriv);
6265 n->priv_name = pstrdup($1);
6269 | ColId opt_column_list
6271 AccessPriv *n = makeNode(AccessPriv);
6279 /* Don't bother trying to fold the first two rules into one using
6280 * opt_table. You're going to get conflicts.
6285 PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
6286 n->targtype = ACL_TARGET_OBJECT;
6287 n->objtype = ACL_OBJECT_RELATION;
6291 | TABLE qualified_name_list
6293 PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
6294 n->targtype = ACL_TARGET_OBJECT;
6295 n->objtype = ACL_OBJECT_RELATION;
6299 | SEQUENCE qualified_name_list
6301 PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
6302 n->targtype = ACL_TARGET_OBJECT;
6303 n->objtype = ACL_OBJECT_SEQUENCE;
6307 | FOREIGN DATA_P WRAPPER name_list
6309 PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
6310 n->targtype = ACL_TARGET_OBJECT;
6311 n->objtype = ACL_OBJECT_FDW;
6315 | FOREIGN SERVER name_list
6317 PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
6318 n->targtype = ACL_TARGET_OBJECT;
6319 n->objtype = ACL_OBJECT_FOREIGN_SERVER;
6323 | FUNCTION function_with_argtypes_list
6325 PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
6326 n->targtype = ACL_TARGET_OBJECT;
6327 n->objtype = ACL_OBJECT_FUNCTION;
6331 | DATABASE name_list
6333 PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
6334 n->targtype = ACL_TARGET_OBJECT;
6335 n->objtype = ACL_OBJECT_DATABASE;
6339 | DOMAIN_P any_name_list
6341 PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
6342 n->targtype = ACL_TARGET_OBJECT;
6343 n->objtype = ACL_OBJECT_DOMAIN;
6347 | LANGUAGE name_list
6349 PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
6350 n->targtype = ACL_TARGET_OBJECT;
6351 n->objtype = ACL_OBJECT_LANGUAGE;
6355 | LARGE_P OBJECT_P NumericOnly_list
6357 PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
6358 n->targtype = ACL_TARGET_OBJECT;
6359 n->objtype = ACL_OBJECT_LARGEOBJECT;
6365 PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
6366 n->targtype = ACL_TARGET_OBJECT;
6367 n->objtype = ACL_OBJECT_NAMESPACE;
6371 | TABLESPACE name_list
6373 PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
6374 n->targtype = ACL_TARGET_OBJECT;
6375 n->objtype = ACL_OBJECT_TABLESPACE;
6379 | TYPE_P any_name_list
6381 PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
6382 n->targtype = ACL_TARGET_OBJECT;
6383 n->objtype = ACL_OBJECT_TYPE;
6387 | ALL TABLES IN_P SCHEMA name_list
6389 PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
6390 n->targtype = ACL_TARGET_ALL_IN_SCHEMA;
6391 n->objtype = ACL_OBJECT_RELATION;
6395 | ALL SEQUENCES IN_P SCHEMA name_list
6397 PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
6398 n->targtype = ACL_TARGET_ALL_IN_SCHEMA;
6399 n->objtype = ACL_OBJECT_SEQUENCE;
6403 | ALL FUNCTIONS IN_P SCHEMA name_list
6405 PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
6406 n->targtype = ACL_TARGET_ALL_IN_SCHEMA;
6407 n->objtype = ACL_OBJECT_FUNCTION;
6415 grantee { $$ = list_make1($1); }
6416 | grantee_list ',' grantee { $$ = lappend($1, $3); }
6420 RoleSpec { $$ = $1; }
6421 | GROUP_P RoleSpec { $$ = $2; }
6425 opt_grant_grant_option:
6426 WITH GRANT OPTION { $$ = TRUE; }
6427 | /*EMPTY*/ { $$ = FALSE; }
6430 function_with_argtypes_list:
6431 function_with_argtypes { $$ = list_make1($1); }
6432 | function_with_argtypes_list ',' function_with_argtypes
6433 { $$ = lappend($1, $3); }
6436 function_with_argtypes:
6439 FuncWithArgs *n = makeNode(FuncWithArgs);
6441 n->funcargs = extractArgTypes($2);
6446 /*****************************************************************************
6448 * GRANT and REVOKE ROLE statements
6450 *****************************************************************************/
6453 GRANT privilege_list TO role_list opt_grant_admin_option opt_granted_by
6455 GrantRoleStmt *n = makeNode(GrantRoleStmt);
6457 n->granted_roles = $2;
6458 n->grantee_roles = $4;
6466 REVOKE privilege_list FROM role_list opt_granted_by opt_drop_behavior
6468 GrantRoleStmt *n = makeNode(GrantRoleStmt);
6469 n->is_grant = false;
6470 n->admin_opt = false;
6471 n->granted_roles = $2;
6472 n->grantee_roles = $4;
6476 | REVOKE ADMIN OPTION FOR privilege_list FROM role_list opt_granted_by opt_drop_behavior
6478 GrantRoleStmt *n = makeNode(GrantRoleStmt);
6479 n->is_grant = false;
6480 n->admin_opt = true;
6481 n->granted_roles = $5;
6482 n->grantee_roles = $7;
6488 opt_grant_admin_option: WITH ADMIN OPTION { $$ = TRUE; }
6489 | /*EMPTY*/ { $$ = FALSE; }
6492 opt_granted_by: GRANTED BY RoleSpec { $$ = $3; }
6493 | /*EMPTY*/ { $$ = NULL; }
6496 /*****************************************************************************
6498 * ALTER DEFAULT PRIVILEGES statement
6500 *****************************************************************************/
6502 AlterDefaultPrivilegesStmt:
6503 ALTER DEFAULT PRIVILEGES DefACLOptionList DefACLAction
6505 AlterDefaultPrivilegesStmt *n = makeNode(AlterDefaultPrivilegesStmt);
6507 n->action = (GrantStmt *) $5;
6513 DefACLOptionList DefACLOption { $$ = lappend($1, $2); }
6514 | /* EMPTY */ { $$ = NIL; }
6518 IN_P SCHEMA name_list
6520 $$ = makeDefElem("schemas", (Node *)$3);
6522 | FOR ROLE role_list
6524 $$ = makeDefElem("roles", (Node *)$3);
6526 | FOR USER role_list
6528 $$ = makeDefElem("roles", (Node *)$3);
6533 * This should match GRANT/REVOKE, except that individual target objects
6534 * are not mentioned and we only allow a subset of object types.
6537 GRANT privileges ON defacl_privilege_target TO grantee_list
6538 opt_grant_grant_option
6540 GrantStmt *n = makeNode(GrantStmt);
6543 n->targtype = ACL_TARGET_DEFAULTS;
6547 n->grant_option = $7;
6550 | REVOKE privileges ON defacl_privilege_target
6551 FROM grantee_list opt_drop_behavior
6553 GrantStmt *n = makeNode(GrantStmt);
6554 n->is_grant = false;
6555 n->grant_option = false;
6557 n->targtype = ACL_TARGET_DEFAULTS;
6564 | REVOKE GRANT OPTION FOR privileges ON defacl_privilege_target
6565 FROM grantee_list opt_drop_behavior
6567 GrantStmt *n = makeNode(GrantStmt);
6568 n->is_grant = false;
6569 n->grant_option = true;
6571 n->targtype = ACL_TARGET_DEFAULTS;
6580 defacl_privilege_target:
6581 TABLES { $$ = ACL_OBJECT_RELATION; }
6582 | FUNCTIONS { $$ = ACL_OBJECT_FUNCTION; }
6583 | SEQUENCES { $$ = ACL_OBJECT_SEQUENCE; }
6584 | TYPES_P { $$ = ACL_OBJECT_TYPE; }
6588 /*****************************************************************************
6590 * QUERY: CREATE INDEX
6592 * Note: we cannot put TABLESPACE clause after WHERE clause unless we are
6593 * willing to make TABLESPACE a fully reserved word.
6594 *****************************************************************************/
6596 IndexStmt: CREATE opt_unique INDEX opt_concurrently opt_index_name
6597 ON qualified_name access_method_clause '(' index_params ')'
6598 opt_reloptions OptTableSpace where_clause
6600 IndexStmt *n = makeNode(IndexStmt);
6605 n->accessMethod = $8;
6606 n->indexParams = $10;
6608 n->tableSpace = $13;
6609 n->whereClause = $14;
6610 n->excludeOpNames = NIL;
6611 n->idxcomment = NULL;
6612 n->indexOid = InvalidOid;
6613 n->oldNode = InvalidOid;
6615 n->isconstraint = false;
6616 n->deferrable = false;
6617 n->initdeferred = false;
6618 n->transformed = false;
6619 n->if_not_exists = false;
6622 | CREATE opt_unique INDEX opt_concurrently IF_P NOT EXISTS index_name
6623 ON qualified_name access_method_clause '(' index_params ')'
6624 opt_reloptions OptTableSpace where_clause
6626 IndexStmt *n = makeNode(IndexStmt);
6631 n->accessMethod = $11;
6632 n->indexParams = $13;
6634 n->tableSpace = $16;
6635 n->whereClause = $17;
6636 n->excludeOpNames = NIL;
6637 n->idxcomment = NULL;
6638 n->indexOid = InvalidOid;
6639 n->oldNode = InvalidOid;
6641 n->isconstraint = false;
6642 n->deferrable = false;
6643 n->initdeferred = false;
6644 n->transformed = false;
6645 n->if_not_exists = true;
6651 UNIQUE { $$ = TRUE; }
6652 | /*EMPTY*/ { $$ = FALSE; }
6656 CONCURRENTLY { $$ = TRUE; }
6657 | /*EMPTY*/ { $$ = FALSE; }
6661 index_name { $$ = $1; }
6662 | /*EMPTY*/ { $$ = NULL; }
6665 access_method_clause:
6666 USING access_method { $$ = $2; }
6667 | /*EMPTY*/ { $$ = DEFAULT_INDEX_TYPE; }
6670 index_params: index_elem { $$ = list_make1($1); }
6671 | index_params ',' index_elem { $$ = lappend($1, $3); }
6675 * Index attributes can be either simple column references, or arbitrary
6676 * expressions in parens. For backwards-compatibility reasons, we allow
6677 * an expression that's just a function call to be written without parens.
6679 index_elem: ColId opt_collate opt_class opt_asc_desc opt_nulls_order
6681 $$ = makeNode(IndexElem);
6684 $$->indexcolname = NULL;
6688 $$->nulls_ordering = $5;
6690 | func_expr_windowless opt_collate opt_class opt_asc_desc opt_nulls_order
6692 $$ = makeNode(IndexElem);
6695 $$->indexcolname = NULL;
6699 $$->nulls_ordering = $5;
6701 | '(' a_expr ')' opt_collate opt_class opt_asc_desc opt_nulls_order
6703 $$ = makeNode(IndexElem);
6706 $$->indexcolname = NULL;
6710 $$->nulls_ordering = $7;
6714 opt_collate: COLLATE any_name { $$ = $2; }
6715 | /*EMPTY*/ { $$ = NIL; }
6718 opt_class: any_name { $$ = $1; }
6719 | USING any_name { $$ = $2; }
6720 | /*EMPTY*/ { $$ = NIL; }
6723 opt_asc_desc: ASC { $$ = SORTBY_ASC; }
6724 | DESC { $$ = SORTBY_DESC; }
6725 | /*EMPTY*/ { $$ = SORTBY_DEFAULT; }
6728 opt_nulls_order: NULLS_LA FIRST_P { $$ = SORTBY_NULLS_FIRST; }
6729 | NULLS_LA LAST_P { $$ = SORTBY_NULLS_LAST; }
6730 | /*EMPTY*/ { $$ = SORTBY_NULLS_DEFAULT; }
6734 /*****************************************************************************
6737 * create [or replace] function <fname>
6738 * [(<type-1> { , <type-n>})]
6740 * as <filename or code in language as appropriate>
6741 * language <lang> [with parameters]
6743 *****************************************************************************/
6746 CREATE opt_or_replace FUNCTION func_name func_args_with_defaults
6747 RETURNS func_return createfunc_opt_list opt_definition
6749 CreateFunctionStmt *n = makeNode(CreateFunctionStmt);
6758 | CREATE opt_or_replace FUNCTION func_name func_args_with_defaults
6759 RETURNS TABLE '(' table_func_column_list ')' createfunc_opt_list opt_definition
6761 CreateFunctionStmt *n = makeNode(CreateFunctionStmt);
6764 n->parameters = mergeTableFuncParameters($5, $9);
6765 n->returnType = TableFuncTypeName($9);
6766 n->returnType->location = @7;
6768 n->withClause = $12;
6771 | CREATE opt_or_replace FUNCTION func_name func_args_with_defaults
6772 createfunc_opt_list opt_definition
6774 CreateFunctionStmt *n = makeNode(CreateFunctionStmt);
6778 n->returnType = NULL;
6786 OR REPLACE { $$ = TRUE; }
6787 | /*EMPTY*/ { $$ = FALSE; }
6790 func_args: '(' func_args_list ')' { $$ = $2; }
6791 | '(' ')' { $$ = NIL; }
6795 func_arg { $$ = list_make1($1); }
6796 | func_args_list ',' func_arg { $$ = lappend($1, $3); }
6800 * func_args_with_defaults is separate because we only want to accept
6801 * defaults in CREATE FUNCTION, not in ALTER etc.
6803 func_args_with_defaults:
6804 '(' func_args_with_defaults_list ')' { $$ = $2; }
6805 | '(' ')' { $$ = NIL; }
6808 func_args_with_defaults_list:
6809 func_arg_with_default { $$ = list_make1($1); }
6810 | func_args_with_defaults_list ',' func_arg_with_default
6811 { $$ = lappend($1, $3); }
6815 * The style with arg_class first is SQL99 standard, but Oracle puts
6816 * param_name first; accept both since it's likely people will try both
6817 * anyway. Don't bother trying to save productions by letting arg_class
6818 * have an empty alternative ... you'll get shift/reduce conflicts.
6820 * We can catch over-specified arguments here if we want to,
6821 * but for now better to silently swallow typmod, etc.
6822 * - thomas 2000-03-22
6825 arg_class param_name func_type
6827 FunctionParameter *n = makeNode(FunctionParameter);
6834 | param_name arg_class func_type
6836 FunctionParameter *n = makeNode(FunctionParameter);
6843 | param_name func_type
6845 FunctionParameter *n = makeNode(FunctionParameter);
6848 n->mode = FUNC_PARAM_IN;
6852 | arg_class func_type
6854 FunctionParameter *n = makeNode(FunctionParameter);
6863 FunctionParameter *n = makeNode(FunctionParameter);
6866 n->mode = FUNC_PARAM_IN;
6872 /* INOUT is SQL99 standard, IN OUT is for Oracle compatibility */
6873 arg_class: IN_P { $$ = FUNC_PARAM_IN; }
6874 | OUT_P { $$ = FUNC_PARAM_OUT; }
6875 | INOUT { $$ = FUNC_PARAM_INOUT; }
6876 | IN_P OUT_P { $$ = FUNC_PARAM_INOUT; }
6877 | VARIADIC { $$ = FUNC_PARAM_VARIADIC; }
6881 * Ideally param_name should be ColId, but that causes too many conflicts.
6883 param_name: type_function_name
6889 /* We can catch over-specified results here if we want to,
6890 * but for now better to silently swallow typmod, etc.
6891 * - thomas 2000-03-22
6898 * We would like to make the %TYPE productions here be ColId attrs etc,
6899 * but that causes reduce/reduce conflicts. type_function_name
6900 * is next best choice.
6902 func_type: Typename { $$ = $1; }
6903 | type_function_name attrs '%' TYPE_P
6905 $$ = makeTypeNameFromNameList(lcons(makeString($1), $2));
6906 $$->pct_type = true;
6909 | SETOF type_function_name attrs '%' TYPE_P
6911 $$ = makeTypeNameFromNameList(lcons(makeString($2), $3));
6912 $$->pct_type = true;
6918 func_arg_with_default:
6923 | func_arg DEFAULT a_expr
6928 | func_arg '=' a_expr
6935 /* Aggregate args can be most things that function args can be */
6938 if (!($1->mode == FUNC_PARAM_IN ||
6939 $1->mode == FUNC_PARAM_VARIADIC))
6941 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
6942 errmsg("aggregates cannot have output arguments"),
6943 parser_errposition(@1)));
6949 * The SQL standard offers no guidance on how to declare aggregate argument
6950 * lists, since it doesn't have CREATE AGGREGATE etc. We accept these cases:
6952 * (*) - normal agg with no args
6953 * (aggr_arg,...) - normal agg with args
6954 * (ORDER BY aggr_arg,...) - ordered-set agg with no direct args
6955 * (aggr_arg,... ORDER BY aggr_arg,...) - ordered-set agg with direct args
6957 * The zero-argument case is spelled with '*' for consistency with COUNT(*).
6959 * An additional restriction is that if the direct-args list ends in a
6960 * VARIADIC item, the ordered-args list must contain exactly one item that
6961 * is also VARIADIC with the same type. This allows us to collapse the two
6962 * VARIADIC items into one, which is necessary to represent the aggregate in
6963 * pg_proc. We check this at the grammar stage so that we can return a list
6964 * in which the second VARIADIC item is already discarded, avoiding extra work
6965 * in cases such as DROP AGGREGATE.
6967 * The return value of this production is a two-element list, in which the
6968 * first item is a sublist of FunctionParameter nodes (with any duplicate
6969 * VARIADIC item already dropped, as per above) and the second is an integer
6970 * Value node, containing -1 if there was no ORDER BY and otherwise the number
6971 * of argument declarations before the ORDER BY. (If this number is equal
6972 * to the first sublist's length, then we dropped a duplicate VARIADIC item.)
6973 * This representation is passed as-is to CREATE AGGREGATE; for operations
6974 * on existing aggregates, we can just apply extractArgTypes to the first
6977 aggr_args: '(' '*' ')'
6979 $$ = list_make2(NIL, makeInteger(-1));
6981 | '(' aggr_args_list ')'
6983 $$ = list_make2($2, makeInteger(-1));
6985 | '(' ORDER BY aggr_args_list ')'
6987 $$ = list_make2($4, makeInteger(0));
6989 | '(' aggr_args_list ORDER BY aggr_args_list ')'
6991 /* this is the only case requiring consistency checking */
6992 $$ = makeOrderedSetArgs($2, $5, yyscanner);
6997 aggr_arg { $$ = list_make1($1); }
6998 | aggr_args_list ',' aggr_arg { $$ = lappend($1, $3); }
7001 createfunc_opt_list:
7002 /* Must be at least one to prevent conflict */
7003 createfunc_opt_item { $$ = list_make1($1); }
7004 | createfunc_opt_list createfunc_opt_item { $$ = lappend($1, $2); }
7008 * Options common to both CREATE FUNCTION and ALTER FUNCTION
7010 common_func_opt_item:
7011 CALLED ON NULL_P INPUT_P
7013 $$ = makeDefElem("strict", (Node *)makeInteger(FALSE));
7015 | RETURNS NULL_P ON NULL_P INPUT_P
7017 $$ = makeDefElem("strict", (Node *)makeInteger(TRUE));
7021 $$ = makeDefElem("strict", (Node *)makeInteger(TRUE));
7025 $$ = makeDefElem("volatility", (Node *)makeString("immutable"));
7029 $$ = makeDefElem("volatility", (Node *)makeString("stable"));
7033 $$ = makeDefElem("volatility", (Node *)makeString("volatile"));
7035 | EXTERNAL SECURITY DEFINER
7037 $$ = makeDefElem("security", (Node *)makeInteger(TRUE));
7039 | EXTERNAL SECURITY INVOKER
7041 $$ = makeDefElem("security", (Node *)makeInteger(FALSE));
7045 $$ = makeDefElem("security", (Node *)makeInteger(TRUE));
7049 $$ = makeDefElem("security", (Node *)makeInteger(FALSE));
7053 $$ = makeDefElem("leakproof", (Node *)makeInteger(TRUE));
7057 $$ = makeDefElem("leakproof", (Node *)makeInteger(FALSE));
7061 $$ = makeDefElem("cost", (Node *)$2);
7065 $$ = makeDefElem("rows", (Node *)$2);
7067 | FunctionSetResetClause
7069 /* we abuse the normal content of a DefElem here */
7070 $$ = makeDefElem("set", (Node *)$1);
7074 $$ = makeDefElem("parallel", (Node *)makeString($2));
7078 createfunc_opt_item:
7081 $$ = makeDefElem("as", (Node *)$2);
7083 | LANGUAGE NonReservedWord_or_Sconst
7085 $$ = makeDefElem("language", (Node *)makeString($2));
7087 | TRANSFORM transform_type_list
7089 $$ = makeDefElem("transform", (Node *)$2);
7093 $$ = makeDefElem("window", (Node *)makeInteger(TRUE));
7095 | common_func_opt_item
7101 func_as: Sconst { $$ = list_make1(makeString($1)); }
7104 $$ = list_make2(makeString($1), makeString($3));
7108 transform_type_list:
7109 FOR TYPE_P Typename { $$ = list_make1($3); }
7110 | transform_type_list ',' FOR TYPE_P Typename { $$ = lappend($1, $5); }
7114 WITH definition { $$ = $2; }
7115 | /*EMPTY*/ { $$ = NIL; }
7118 table_func_column: param_name func_type
7120 FunctionParameter *n = makeNode(FunctionParameter);
7123 n->mode = FUNC_PARAM_TABLE;
7129 table_func_column_list:
7132 $$ = list_make1($1);
7134 | table_func_column_list ',' table_func_column
7136 $$ = lappend($1, $3);
7140 /*****************************************************************************
7143 * RENAME and OWNER subcommands are already provided by the generic
7144 * ALTER infrastructure, here we just specify alterations that can
7145 * only be applied to functions.
7147 *****************************************************************************/
7149 ALTER FUNCTION function_with_argtypes alterfunc_opt_list opt_restrict
7151 AlterFunctionStmt *n = makeNode(AlterFunctionStmt);
7159 /* At least one option must be specified */
7160 common_func_opt_item { $$ = list_make1($1); }
7161 | alterfunc_opt_list common_func_opt_item { $$ = lappend($1, $2); }
7164 /* Ignored, merely for SQL compliance */
7171 /*****************************************************************************
7175 * DROP FUNCTION funcname (arg1, arg2, ...) [ RESTRICT | CASCADE ]
7176 * DROP AGGREGATE aggname (arg1, ...) [ RESTRICT | CASCADE ]
7177 * DROP OPERATOR opname (leftoperand_typ, rightoperand_typ) [ RESTRICT | CASCADE ]
7179 *****************************************************************************/
7182 DROP FUNCTION func_name func_args opt_drop_behavior
7184 DropStmt *n = makeNode(DropStmt);
7185 n->removeType = OBJECT_FUNCTION;
7186 n->objects = list_make1($3);
7187 n->arguments = list_make1(extractArgTypes($4));
7189 n->missing_ok = false;
7190 n->concurrent = false;
7193 | DROP FUNCTION IF_P EXISTS func_name func_args opt_drop_behavior
7195 DropStmt *n = makeNode(DropStmt);
7196 n->removeType = OBJECT_FUNCTION;
7197 n->objects = list_make1($5);
7198 n->arguments = list_make1(extractArgTypes($6));
7200 n->missing_ok = true;
7201 n->concurrent = false;
7207 DROP AGGREGATE func_name aggr_args opt_drop_behavior
7209 DropStmt *n = makeNode(DropStmt);
7210 n->removeType = OBJECT_AGGREGATE;
7211 n->objects = list_make1($3);
7212 n->arguments = list_make1(extractAggrArgTypes($4));
7214 n->missing_ok = false;
7215 n->concurrent = false;
7218 | DROP AGGREGATE IF_P EXISTS func_name aggr_args opt_drop_behavior
7220 DropStmt *n = makeNode(DropStmt);
7221 n->removeType = OBJECT_AGGREGATE;
7222 n->objects = list_make1($5);
7223 n->arguments = list_make1(extractAggrArgTypes($6));
7225 n->missing_ok = true;
7226 n->concurrent = false;
7232 DROP OPERATOR any_operator oper_argtypes opt_drop_behavior
7234 DropStmt *n = makeNode(DropStmt);
7235 n->removeType = OBJECT_OPERATOR;
7236 n->objects = list_make1($3);
7237 n->arguments = list_make1($4);
7239 n->missing_ok = false;
7240 n->concurrent = false;
7243 | DROP OPERATOR IF_P EXISTS any_operator oper_argtypes opt_drop_behavior
7245 DropStmt *n = makeNode(DropStmt);
7246 n->removeType = OBJECT_OPERATOR;
7247 n->objects = list_make1($5);
7248 n->arguments = list_make1($6);
7250 n->missing_ok = true;
7251 n->concurrent = false;
7260 (errcode(ERRCODE_SYNTAX_ERROR),
7261 errmsg("missing argument"),
7262 errhint("Use NONE to denote the missing argument of a unary operator."),
7263 parser_errposition(@3)));
7265 | '(' Typename ',' Typename ')'
7266 { $$ = list_make2($2, $4); }
7267 | '(' NONE ',' Typename ')' /* left unary */
7268 { $$ = list_make2(NULL, $4); }
7269 | '(' Typename ',' NONE ')' /* right unary */
7270 { $$ = list_make2($2, NULL); }
7275 { $$ = list_make1(makeString($1)); }
7276 | ColId '.' any_operator
7277 { $$ = lcons(makeString($1), $3); }
7280 /*****************************************************************************
7282 * DO <anonymous code block> [ LANGUAGE language ]
7284 * We use a DefElem list for future extensibility, and to allow flexibility
7285 * in the clause order.
7287 *****************************************************************************/
7289 DoStmt: DO dostmt_opt_list
7291 DoStmt *n = makeNode(DoStmt);
7298 dostmt_opt_item { $$ = list_make1($1); }
7299 | dostmt_opt_list dostmt_opt_item { $$ = lappend($1, $2); }
7305 $$ = makeDefElem("as", (Node *)makeString($1));
7307 | LANGUAGE NonReservedWord_or_Sconst
7309 $$ = makeDefElem("language", (Node *)makeString($2));
7313 /*****************************************************************************
7315 * CREATE CAST / DROP CAST
7317 *****************************************************************************/
7319 CreateCastStmt: CREATE CAST '(' Typename AS Typename ')'
7320 WITH FUNCTION function_with_argtypes cast_context
7322 CreateCastStmt *n = makeNode(CreateCastStmt);
7326 n->context = (CoercionContext) $11;
7330 | CREATE CAST '(' Typename AS Typename ')'
7331 WITHOUT FUNCTION cast_context
7333 CreateCastStmt *n = makeNode(CreateCastStmt);
7337 n->context = (CoercionContext) $10;
7341 | CREATE CAST '(' Typename AS Typename ')'
7342 WITH INOUT cast_context
7344 CreateCastStmt *n = makeNode(CreateCastStmt);
7348 n->context = (CoercionContext) $10;
7354 cast_context: AS IMPLICIT_P { $$ = COERCION_IMPLICIT; }
7355 | AS ASSIGNMENT { $$ = COERCION_ASSIGNMENT; }
7356 | /*EMPTY*/ { $$ = COERCION_EXPLICIT; }
7360 DropCastStmt: DROP CAST opt_if_exists '(' Typename AS Typename ')' opt_drop_behavior
7362 DropStmt *n = makeNode(DropStmt);
7363 n->removeType = OBJECT_CAST;
7364 n->objects = list_make1(list_make1($5));
7365 n->arguments = list_make1(list_make1($7));
7368 n->concurrent = false;
7373 opt_if_exists: IF_P EXISTS { $$ = TRUE; }
7374 | /*EMPTY*/ { $$ = FALSE; }
7378 /*****************************************************************************
7380 * CREATE TRANSFORM / DROP TRANSFORM
7382 *****************************************************************************/
7384 CreateTransformStmt: CREATE opt_or_replace TRANSFORM FOR Typename LANGUAGE name '(' transform_element_list ')'
7386 CreateTransformStmt *n = makeNode(CreateTransformStmt);
7390 n->fromsql = linitial($9);
7391 n->tosql = lsecond($9);
7396 transform_element_list: FROM SQL_P WITH FUNCTION function_with_argtypes ',' TO SQL_P WITH FUNCTION function_with_argtypes
7398 $$ = list_make2($5, $11);
7400 | TO SQL_P WITH FUNCTION function_with_argtypes ',' FROM SQL_P WITH FUNCTION function_with_argtypes
7402 $$ = list_make2($11, $5);
7404 | FROM SQL_P WITH FUNCTION function_with_argtypes
7406 $$ = list_make2($5, NULL);
7408 | TO SQL_P WITH FUNCTION function_with_argtypes
7410 $$ = list_make2(NULL, $5);
7415 DropTransformStmt: DROP TRANSFORM opt_if_exists FOR Typename LANGUAGE name opt_drop_behavior
7417 DropStmt *n = makeNode(DropStmt);
7418 n->removeType = OBJECT_TRANSFORM;
7419 n->objects = list_make1(list_make1($5));
7420 n->arguments = list_make1(list_make1(makeString($7)));
7428 /*****************************************************************************
7432 * REINDEX [ (options) ] type <name>
7433 *****************************************************************************/
7436 REINDEX reindex_target_type qualified_name
7438 ReindexStmt *n = makeNode(ReindexStmt);
7445 | REINDEX reindex_target_multitable name
7447 ReindexStmt *n = makeNode(ReindexStmt);
7454 | REINDEX '(' reindex_option_list ')' reindex_target_type qualified_name
7456 ReindexStmt *n = makeNode(ReindexStmt);
7463 | REINDEX '(' reindex_option_list ')' reindex_target_multitable name
7465 ReindexStmt *n = makeNode(ReindexStmt);
7473 reindex_target_type:
7474 INDEX { $$ = REINDEX_OBJECT_INDEX; }
7475 | TABLE { $$ = REINDEX_OBJECT_TABLE; }
7477 reindex_target_multitable:
7478 SCHEMA { $$ = REINDEX_OBJECT_SCHEMA; }
7479 | SYSTEM_P { $$ = REINDEX_OBJECT_SYSTEM; }
7480 | DATABASE { $$ = REINDEX_OBJECT_DATABASE; }
7482 reindex_option_list:
7483 reindex_option_elem { $$ = $1; }
7484 | reindex_option_list ',' reindex_option_elem { $$ = $1 | $3; }
7486 reindex_option_elem:
7487 VERBOSE { $$ = REINDEXOPT_VERBOSE; }
7490 /*****************************************************************************
7494 *****************************************************************************/
7497 ALTER TABLESPACE name SET reloptions
7499 AlterTableSpaceOptionsStmt *n =
7500 makeNode(AlterTableSpaceOptionsStmt);
7501 n->tablespacename = $3;
7506 | ALTER TABLESPACE name RESET reloptions
7508 AlterTableSpaceOptionsStmt *n =
7509 makeNode(AlterTableSpaceOptionsStmt);
7510 n->tablespacename = $3;
7517 /*****************************************************************************
7519 * ALTER THING name RENAME TO newname
7521 *****************************************************************************/
7523 RenameStmt: ALTER AGGREGATE func_name aggr_args RENAME TO name
7525 RenameStmt *n = makeNode(RenameStmt);
7526 n->renameType = OBJECT_AGGREGATE;
7528 n->objarg = extractAggrArgTypes($4);
7530 n->missing_ok = false;
7533 | ALTER COLLATION any_name RENAME TO name
7535 RenameStmt *n = makeNode(RenameStmt);
7536 n->renameType = OBJECT_COLLATION;
7539 n->missing_ok = false;
7542 | ALTER CONVERSION_P any_name RENAME TO name
7544 RenameStmt *n = makeNode(RenameStmt);
7545 n->renameType = OBJECT_CONVERSION;
7548 n->missing_ok = false;
7551 | ALTER DATABASE database_name RENAME TO database_name
7553 RenameStmt *n = makeNode(RenameStmt);
7554 n->renameType = OBJECT_DATABASE;
7557 n->missing_ok = false;
7560 | ALTER DOMAIN_P any_name RENAME TO name
7562 RenameStmt *n = makeNode(RenameStmt);
7563 n->renameType = OBJECT_DOMAIN;
7566 n->missing_ok = false;
7569 | ALTER DOMAIN_P any_name RENAME CONSTRAINT name TO name
7571 RenameStmt *n = makeNode(RenameStmt);
7572 n->renameType = OBJECT_DOMCONSTRAINT;
7578 | ALTER FOREIGN DATA_P WRAPPER name RENAME TO name
7580 RenameStmt *n = makeNode(RenameStmt);
7581 n->renameType = OBJECT_FDW;
7582 n->object = list_make1(makeString($5));
7584 n->missing_ok = false;
7587 | ALTER FUNCTION function_with_argtypes RENAME TO name
7589 RenameStmt *n = makeNode(RenameStmt);
7590 n->renameType = OBJECT_FUNCTION;
7591 n->object = $3->funcname;
7592 n->objarg = $3->funcargs;
7594 n->missing_ok = false;
7597 | ALTER GROUP_P RoleId RENAME TO RoleId
7599 RenameStmt *n = makeNode(RenameStmt);
7600 n->renameType = OBJECT_ROLE;
7603 n->missing_ok = false;
7606 | ALTER opt_procedural LANGUAGE name RENAME TO name
7608 RenameStmt *n = makeNode(RenameStmt);
7609 n->renameType = OBJECT_LANGUAGE;
7610 n->object = list_make1(makeString($4));
7612 n->missing_ok = false;
7615 | ALTER OPERATOR CLASS any_name USING access_method RENAME TO name
7617 RenameStmt *n = makeNode(RenameStmt);
7618 n->renameType = OBJECT_OPCLASS;
7619 n->object = lcons(makeString($6), $4);
7621 n->missing_ok = false;
7624 | ALTER OPERATOR FAMILY any_name USING access_method RENAME TO name
7626 RenameStmt *n = makeNode(RenameStmt);
7627 n->renameType = OBJECT_OPFAMILY;
7628 n->object = lcons(makeString($6), $4);
7630 n->missing_ok = false;
7633 | ALTER POLICY name ON qualified_name RENAME TO name
7635 RenameStmt *n = makeNode(RenameStmt);
7636 n->renameType = OBJECT_POLICY;
7640 n->missing_ok = false;
7643 | ALTER POLICY IF_P EXISTS name ON qualified_name RENAME TO name
7645 RenameStmt *n = makeNode(RenameStmt);
7646 n->renameType = OBJECT_POLICY;
7650 n->missing_ok = true;
7653 | ALTER SCHEMA name RENAME TO name
7655 RenameStmt *n = makeNode(RenameStmt);
7656 n->renameType = OBJECT_SCHEMA;
7659 n->missing_ok = false;
7662 | ALTER SERVER name RENAME TO name
7664 RenameStmt *n = makeNode(RenameStmt);
7665 n->renameType = OBJECT_FOREIGN_SERVER;
7666 n->object = list_make1(makeString($3));
7668 n->missing_ok = false;
7671 | ALTER TABLE relation_expr RENAME TO name
7673 RenameStmt *n = makeNode(RenameStmt);
7674 n->renameType = OBJECT_TABLE;
7678 n->missing_ok = false;
7681 | ALTER TABLE IF_P EXISTS relation_expr RENAME TO name
7683 RenameStmt *n = makeNode(RenameStmt);
7684 n->renameType = OBJECT_TABLE;
7688 n->missing_ok = true;
7691 | ALTER SEQUENCE qualified_name RENAME TO name
7693 RenameStmt *n = makeNode(RenameStmt);
7694 n->renameType = OBJECT_SEQUENCE;
7698 n->missing_ok = false;
7701 | ALTER SEQUENCE IF_P EXISTS qualified_name RENAME TO name
7703 RenameStmt *n = makeNode(RenameStmt);
7704 n->renameType = OBJECT_SEQUENCE;
7708 n->missing_ok = true;
7711 | ALTER VIEW qualified_name RENAME TO name
7713 RenameStmt *n = makeNode(RenameStmt);
7714 n->renameType = OBJECT_VIEW;
7718 n->missing_ok = false;
7721 | ALTER VIEW IF_P EXISTS qualified_name RENAME TO name
7723 RenameStmt *n = makeNode(RenameStmt);
7724 n->renameType = OBJECT_VIEW;
7728 n->missing_ok = true;
7731 | ALTER MATERIALIZED VIEW qualified_name RENAME TO name
7733 RenameStmt *n = makeNode(RenameStmt);
7734 n->renameType = OBJECT_MATVIEW;
7738 n->missing_ok = false;
7741 | ALTER MATERIALIZED VIEW IF_P EXISTS qualified_name RENAME TO name
7743 RenameStmt *n = makeNode(RenameStmt);
7744 n->renameType = OBJECT_MATVIEW;
7748 n->missing_ok = true;
7751 | ALTER INDEX qualified_name RENAME TO name
7753 RenameStmt *n = makeNode(RenameStmt);
7754 n->renameType = OBJECT_INDEX;
7758 n->missing_ok = false;
7761 | ALTER INDEX IF_P EXISTS qualified_name RENAME TO name
7763 RenameStmt *n = makeNode(RenameStmt);
7764 n->renameType = OBJECT_INDEX;
7768 n->missing_ok = true;
7771 | ALTER FOREIGN TABLE relation_expr RENAME TO name
7773 RenameStmt *n = makeNode(RenameStmt);
7774 n->renameType = OBJECT_FOREIGN_TABLE;
7778 n->missing_ok = false;
7781 | ALTER FOREIGN TABLE IF_P EXISTS relation_expr RENAME TO name
7783 RenameStmt *n = makeNode(RenameStmt);
7784 n->renameType = OBJECT_FOREIGN_TABLE;
7788 n->missing_ok = true;
7791 | ALTER TABLE relation_expr RENAME opt_column name TO name
7793 RenameStmt *n = makeNode(RenameStmt);
7794 n->renameType = OBJECT_COLUMN;
7795 n->relationType = OBJECT_TABLE;
7799 n->missing_ok = false;
7802 | ALTER TABLE IF_P EXISTS relation_expr RENAME opt_column name TO name
7804 RenameStmt *n = makeNode(RenameStmt);
7805 n->renameType = OBJECT_COLUMN;
7806 n->relationType = OBJECT_TABLE;
7810 n->missing_ok = true;
7813 | ALTER MATERIALIZED VIEW qualified_name RENAME opt_column name TO name
7815 RenameStmt *n = makeNode(RenameStmt);
7816 n->renameType = OBJECT_COLUMN;
7817 n->relationType = OBJECT_MATVIEW;
7821 n->missing_ok = false;
7824 | ALTER MATERIALIZED VIEW IF_P EXISTS qualified_name RENAME opt_column name TO name
7826 RenameStmt *n = makeNode(RenameStmt);
7827 n->renameType = OBJECT_COLUMN;
7828 n->relationType = OBJECT_MATVIEW;
7832 n->missing_ok = true;
7835 | ALTER TABLE relation_expr RENAME CONSTRAINT name TO name
7837 RenameStmt *n = makeNode(RenameStmt);
7838 n->renameType = OBJECT_TABCONSTRAINT;
7842 n->missing_ok = false;
7845 | ALTER TABLE IF_P EXISTS relation_expr RENAME CONSTRAINT name TO name
7847 RenameStmt *n = makeNode(RenameStmt);
7848 n->renameType = OBJECT_TABCONSTRAINT;
7852 n->missing_ok = true;
7855 | ALTER FOREIGN TABLE relation_expr RENAME opt_column name TO name
7857 RenameStmt *n = makeNode(RenameStmt);
7858 n->renameType = OBJECT_COLUMN;
7859 n->relationType = OBJECT_FOREIGN_TABLE;
7863 n->missing_ok = false;
7866 | ALTER FOREIGN TABLE IF_P EXISTS relation_expr RENAME opt_column name TO name
7868 RenameStmt *n = makeNode(RenameStmt);
7869 n->renameType = OBJECT_COLUMN;
7870 n->relationType = OBJECT_FOREIGN_TABLE;
7874 n->missing_ok = true;
7877 | ALTER RULE name ON qualified_name RENAME TO name
7879 RenameStmt *n = makeNode(RenameStmt);
7880 n->renameType = OBJECT_RULE;
7884 n->missing_ok = false;
7887 | ALTER TRIGGER name ON qualified_name RENAME TO name
7889 RenameStmt *n = makeNode(RenameStmt);
7890 n->renameType = OBJECT_TRIGGER;
7894 n->missing_ok = false;
7897 | ALTER EVENT TRIGGER name RENAME TO name
7899 RenameStmt *n = makeNode(RenameStmt);
7900 n->renameType = OBJECT_EVENT_TRIGGER;
7901 n->object = list_make1(makeString($4));
7905 | ALTER ROLE RoleId RENAME TO RoleId
7907 RenameStmt *n = makeNode(RenameStmt);
7908 n->renameType = OBJECT_ROLE;
7911 n->missing_ok = false;
7914 | ALTER USER RoleId RENAME TO RoleId
7916 RenameStmt *n = makeNode(RenameStmt);
7917 n->renameType = OBJECT_ROLE;
7920 n->missing_ok = false;
7923 | ALTER TABLESPACE name RENAME TO name
7925 RenameStmt *n = makeNode(RenameStmt);
7926 n->renameType = OBJECT_TABLESPACE;
7929 n->missing_ok = false;
7932 | ALTER TEXT_P SEARCH PARSER any_name RENAME TO name
7934 RenameStmt *n = makeNode(RenameStmt);
7935 n->renameType = OBJECT_TSPARSER;
7938 n->missing_ok = false;
7941 | ALTER TEXT_P SEARCH DICTIONARY any_name RENAME TO name
7943 RenameStmt *n = makeNode(RenameStmt);
7944 n->renameType = OBJECT_TSDICTIONARY;
7947 n->missing_ok = false;
7950 | ALTER TEXT_P SEARCH TEMPLATE any_name RENAME TO name
7952 RenameStmt *n = makeNode(RenameStmt);
7953 n->renameType = OBJECT_TSTEMPLATE;
7956 n->missing_ok = false;
7959 | ALTER TEXT_P SEARCH CONFIGURATION any_name RENAME TO name
7961 RenameStmt *n = makeNode(RenameStmt);
7962 n->renameType = OBJECT_TSCONFIGURATION;
7965 n->missing_ok = false;
7968 | ALTER TYPE_P any_name RENAME TO name
7970 RenameStmt *n = makeNode(RenameStmt);
7971 n->renameType = OBJECT_TYPE;
7974 n->missing_ok = false;
7977 | ALTER TYPE_P any_name RENAME ATTRIBUTE name TO name opt_drop_behavior
7979 RenameStmt *n = makeNode(RenameStmt);
7980 n->renameType = OBJECT_ATTRIBUTE;
7981 n->relationType = OBJECT_TYPE;
7982 n->relation = makeRangeVarFromAnyName($3, @3, yyscanner);
7986 n->missing_ok = false;
7991 opt_column: COLUMN { $$ = COLUMN; }
7992 | /*EMPTY*/ { $$ = 0; }
7995 opt_set_data: SET DATA_P { $$ = 1; }
7996 | /*EMPTY*/ { $$ = 0; }
7999 /*****************************************************************************
8001 * ALTER THING name SET SCHEMA name
8003 *****************************************************************************/
8005 AlterObjectSchemaStmt:
8006 ALTER AGGREGATE func_name aggr_args SET SCHEMA name
8008 AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
8009 n->objectType = OBJECT_AGGREGATE;
8011 n->objarg = extractAggrArgTypes($4);
8013 n->missing_ok = false;
8016 | ALTER COLLATION any_name SET SCHEMA name
8018 AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
8019 n->objectType = OBJECT_COLLATION;
8022 n->missing_ok = false;
8025 | ALTER CONVERSION_P any_name SET SCHEMA name
8027 AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
8028 n->objectType = OBJECT_CONVERSION;
8031 n->missing_ok = false;
8034 | ALTER DOMAIN_P any_name SET SCHEMA name
8036 AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
8037 n->objectType = OBJECT_DOMAIN;
8040 n->missing_ok = false;
8043 | ALTER EXTENSION any_name SET SCHEMA name
8045 AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
8046 n->objectType = OBJECT_EXTENSION;
8049 n->missing_ok = false;
8052 | ALTER FUNCTION function_with_argtypes SET SCHEMA name
8054 AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
8055 n->objectType = OBJECT_FUNCTION;
8056 n->object = $3->funcname;
8057 n->objarg = $3->funcargs;
8059 n->missing_ok = false;
8062 | ALTER OPERATOR any_operator oper_argtypes SET SCHEMA name
8064 AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
8065 n->objectType = OBJECT_OPERATOR;
8069 n->missing_ok = false;
8072 | ALTER OPERATOR CLASS any_name USING access_method SET SCHEMA name
8074 AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
8075 n->objectType = OBJECT_OPCLASS;
8076 n->object = lcons(makeString($6), $4);
8078 n->missing_ok = false;
8081 | ALTER OPERATOR FAMILY any_name USING access_method SET SCHEMA name
8083 AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
8084 n->objectType = OBJECT_OPFAMILY;
8085 n->object = lcons(makeString($6), $4);
8087 n->missing_ok = false;
8090 | ALTER TABLE relation_expr SET SCHEMA name
8092 AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
8093 n->objectType = OBJECT_TABLE;
8096 n->missing_ok = false;
8099 | ALTER TABLE IF_P EXISTS relation_expr SET SCHEMA name
8101 AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
8102 n->objectType = OBJECT_TABLE;
8105 n->missing_ok = true;
8108 | ALTER TEXT_P SEARCH PARSER any_name SET SCHEMA name
8110 AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
8111 n->objectType = OBJECT_TSPARSER;
8114 n->missing_ok = false;
8117 | ALTER TEXT_P SEARCH DICTIONARY any_name SET SCHEMA name
8119 AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
8120 n->objectType = OBJECT_TSDICTIONARY;
8123 n->missing_ok = false;
8126 | ALTER TEXT_P SEARCH TEMPLATE any_name SET SCHEMA name
8128 AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
8129 n->objectType = OBJECT_TSTEMPLATE;
8132 n->missing_ok = false;
8135 | ALTER TEXT_P SEARCH CONFIGURATION any_name SET SCHEMA name
8137 AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
8138 n->objectType = OBJECT_TSCONFIGURATION;
8141 n->missing_ok = false;
8144 | ALTER SEQUENCE qualified_name SET SCHEMA name
8146 AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
8147 n->objectType = OBJECT_SEQUENCE;
8150 n->missing_ok = false;
8153 | ALTER SEQUENCE IF_P EXISTS qualified_name SET SCHEMA name
8155 AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
8156 n->objectType = OBJECT_SEQUENCE;
8159 n->missing_ok = true;
8162 | ALTER VIEW qualified_name SET SCHEMA name
8164 AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
8165 n->objectType = OBJECT_VIEW;
8168 n->missing_ok = false;
8171 | ALTER VIEW IF_P EXISTS qualified_name SET SCHEMA name
8173 AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
8174 n->objectType = OBJECT_VIEW;
8177 n->missing_ok = true;
8180 | ALTER MATERIALIZED VIEW qualified_name SET SCHEMA name
8182 AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
8183 n->objectType = OBJECT_MATVIEW;
8186 n->missing_ok = false;
8189 | ALTER MATERIALIZED VIEW IF_P EXISTS qualified_name SET SCHEMA name
8191 AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
8192 n->objectType = OBJECT_MATVIEW;
8195 n->missing_ok = true;
8198 | ALTER FOREIGN TABLE relation_expr SET SCHEMA name
8200 AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
8201 n->objectType = OBJECT_FOREIGN_TABLE;
8204 n->missing_ok = false;
8207 | ALTER FOREIGN TABLE IF_P EXISTS relation_expr SET SCHEMA name
8209 AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
8210 n->objectType = OBJECT_FOREIGN_TABLE;
8213 n->missing_ok = true;
8216 | ALTER TYPE_P any_name SET SCHEMA name
8218 AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
8219 n->objectType = OBJECT_TYPE;
8222 n->missing_ok = false;
8227 /*****************************************************************************
8229 * ALTER OPERATOR name SET define
8231 *****************************************************************************/
8234 ALTER OPERATOR any_operator oper_argtypes SET '(' operator_def_list ')'
8236 AlterOperatorStmt *n = makeNode(AlterOperatorStmt);
8244 operator_def_list: operator_def_elem { $$ = list_make1($1); }
8245 | operator_def_list ',' operator_def_elem { $$ = lappend($1, $3); }
8248 operator_def_elem: ColLabel '=' NONE
8249 { $$ = makeDefElem($1, NULL); }
8250 | ColLabel '=' def_arg
8251 { $$ = makeDefElem($1, (Node *) $3); }
8254 /*****************************************************************************
8256 * ALTER THING name OWNER TO newname
8258 *****************************************************************************/
8260 AlterOwnerStmt: ALTER AGGREGATE func_name aggr_args OWNER TO RoleSpec
8262 AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
8263 n->objectType = OBJECT_AGGREGATE;
8265 n->objarg = extractAggrArgTypes($4);
8269 | ALTER COLLATION any_name OWNER TO RoleSpec
8271 AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
8272 n->objectType = OBJECT_COLLATION;
8277 | ALTER CONVERSION_P any_name OWNER TO RoleSpec
8279 AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
8280 n->objectType = OBJECT_CONVERSION;
8285 | ALTER DATABASE database_name OWNER TO RoleSpec
8287 AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
8288 n->objectType = OBJECT_DATABASE;
8289 n->object = list_make1(makeString($3));
8293 | ALTER DOMAIN_P any_name OWNER TO RoleSpec
8295 AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
8296 n->objectType = OBJECT_DOMAIN;
8301 | ALTER FUNCTION function_with_argtypes OWNER TO RoleSpec
8303 AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
8304 n->objectType = OBJECT_FUNCTION;
8305 n->object = $3->funcname;
8306 n->objarg = $3->funcargs;
8310 | ALTER opt_procedural LANGUAGE name OWNER TO RoleSpec
8312 AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
8313 n->objectType = OBJECT_LANGUAGE;
8314 n->object = list_make1(makeString($4));
8318 | ALTER LARGE_P OBJECT_P NumericOnly OWNER TO RoleSpec
8320 AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
8321 n->objectType = OBJECT_LARGEOBJECT;
8322 n->object = list_make1($4);
8326 | ALTER OPERATOR any_operator oper_argtypes OWNER TO RoleSpec
8328 AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
8329 n->objectType = OBJECT_OPERATOR;
8335 | ALTER OPERATOR CLASS any_name USING access_method OWNER TO RoleSpec
8337 AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
8338 n->objectType = OBJECT_OPCLASS;
8339 n->object = lcons(makeString($6), $4);
8343 | ALTER OPERATOR FAMILY any_name USING access_method OWNER TO RoleSpec
8345 AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
8346 n->objectType = OBJECT_OPFAMILY;
8347 n->object = lcons(makeString($6), $4);
8351 | ALTER SCHEMA name OWNER TO RoleSpec
8353 AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
8354 n->objectType = OBJECT_SCHEMA;
8355 n->object = list_make1(makeString($3));
8359 | ALTER TYPE_P any_name OWNER TO RoleSpec
8361 AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
8362 n->objectType = OBJECT_TYPE;
8367 | ALTER TABLESPACE name OWNER TO RoleSpec
8369 AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
8370 n->objectType = OBJECT_TABLESPACE;
8371 n->object = list_make1(makeString($3));
8375 | ALTER TEXT_P SEARCH DICTIONARY any_name OWNER TO RoleSpec
8377 AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
8378 n->objectType = OBJECT_TSDICTIONARY;
8383 | ALTER TEXT_P SEARCH CONFIGURATION any_name OWNER TO RoleSpec
8385 AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
8386 n->objectType = OBJECT_TSCONFIGURATION;
8391 | ALTER FOREIGN DATA_P WRAPPER name OWNER TO RoleSpec
8393 AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
8394 n->objectType = OBJECT_FDW;
8395 n->object = list_make1(makeString($5));
8399 | ALTER SERVER name OWNER TO RoleSpec
8401 AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
8402 n->objectType = OBJECT_FOREIGN_SERVER;
8403 n->object = list_make1(makeString($3));
8407 | ALTER EVENT TRIGGER name OWNER TO RoleSpec
8409 AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
8410 n->objectType = OBJECT_EVENT_TRIGGER;
8411 n->object = list_make1(makeString($4));
8418 /*****************************************************************************
8420 * QUERY: Define Rewrite Rule
8422 *****************************************************************************/
8424 RuleStmt: CREATE opt_or_replace RULE name AS
8425 ON event TO qualified_name where_clause
8426 DO opt_instead RuleActionList
8428 RuleStmt *n = makeNode(RuleStmt);
8432 n->whereClause = $10;
8441 NOTHING { $$ = NIL; }
8442 | RuleActionStmt { $$ = list_make1($1); }
8443 | '(' RuleActionMulti ')' { $$ = $2; }
8446 /* the thrashing around here is to discard "empty" statements... */
8448 RuleActionMulti ';' RuleActionStmtOrEmpty
8450 $$ = lappend($1, $3);
8454 | RuleActionStmtOrEmpty
8456 $$ = list_make1($1);
8470 RuleActionStmtOrEmpty:
8471 RuleActionStmt { $$ = $1; }
8472 | /*EMPTY*/ { $$ = NULL; }
8475 event: SELECT { $$ = CMD_SELECT; }
8476 | UPDATE { $$ = CMD_UPDATE; }
8477 | DELETE_P { $$ = CMD_DELETE; }
8478 | INSERT { $$ = CMD_INSERT; }
8482 INSTEAD { $$ = TRUE; }
8483 | ALSO { $$ = FALSE; }
8484 | /*EMPTY*/ { $$ = FALSE; }
8489 DROP RULE name ON any_name opt_drop_behavior
8491 DropStmt *n = makeNode(DropStmt);
8492 n->removeType = OBJECT_RULE;
8493 n->objects = list_make1(lappend($5, makeString($3)));
8496 n->missing_ok = false;
8497 n->concurrent = false;
8500 | DROP RULE IF_P EXISTS name ON any_name opt_drop_behavior
8502 DropStmt *n = makeNode(DropStmt);
8503 n->removeType = OBJECT_RULE;
8504 n->objects = list_make1(lappend($7, makeString($5)));
8507 n->missing_ok = true;
8508 n->concurrent = false;
8514 /*****************************************************************************
8517 * NOTIFY <identifier> can appear both in rule bodies and
8518 * as a query-level command
8520 *****************************************************************************/
8522 NotifyStmt: NOTIFY ColId notify_payload
8524 NotifyStmt *n = makeNode(NotifyStmt);
8525 n->conditionname = $2;
8532 ',' Sconst { $$ = $2; }
8533 | /*EMPTY*/ { $$ = NULL; }
8536 ListenStmt: LISTEN ColId
8538 ListenStmt *n = makeNode(ListenStmt);
8539 n->conditionname = $2;
8547 UnlistenStmt *n = makeNode(UnlistenStmt);
8548 n->conditionname = $2;
8553 UnlistenStmt *n = makeNode(UnlistenStmt);
8554 n->conditionname = NULL;
8560 /*****************************************************************************
8564 * BEGIN / COMMIT / ROLLBACK
8565 * (also older versions END / ABORT)
8567 *****************************************************************************/
8570 ABORT_P opt_transaction
8572 TransactionStmt *n = makeNode(TransactionStmt);
8573 n->kind = TRANS_STMT_ROLLBACK;
8577 | BEGIN_P opt_transaction transaction_mode_list_or_empty
8579 TransactionStmt *n = makeNode(TransactionStmt);
8580 n->kind = TRANS_STMT_BEGIN;
8584 | START TRANSACTION transaction_mode_list_or_empty
8586 TransactionStmt *n = makeNode(TransactionStmt);
8587 n->kind = TRANS_STMT_START;
8591 | COMMIT opt_transaction
8593 TransactionStmt *n = makeNode(TransactionStmt);
8594 n->kind = TRANS_STMT_COMMIT;
8598 | END_P opt_transaction
8600 TransactionStmt *n = makeNode(TransactionStmt);
8601 n->kind = TRANS_STMT_COMMIT;
8605 | ROLLBACK opt_transaction
8607 TransactionStmt *n = makeNode(TransactionStmt);
8608 n->kind = TRANS_STMT_ROLLBACK;
8614 TransactionStmt *n = makeNode(TransactionStmt);
8615 n->kind = TRANS_STMT_SAVEPOINT;
8616 n->options = list_make1(makeDefElem("savepoint_name",
8617 (Node *)makeString($2)));
8620 | RELEASE SAVEPOINT ColId
8622 TransactionStmt *n = makeNode(TransactionStmt);
8623 n->kind = TRANS_STMT_RELEASE;
8624 n->options = list_make1(makeDefElem("savepoint_name",
8625 (Node *)makeString($3)));
8630 TransactionStmt *n = makeNode(TransactionStmt);
8631 n->kind = TRANS_STMT_RELEASE;
8632 n->options = list_make1(makeDefElem("savepoint_name",
8633 (Node *)makeString($2)));
8636 | ROLLBACK opt_transaction TO SAVEPOINT ColId
8638 TransactionStmt *n = makeNode(TransactionStmt);
8639 n->kind = TRANS_STMT_ROLLBACK_TO;
8640 n->options = list_make1(makeDefElem("savepoint_name",
8641 (Node *)makeString($5)));
8644 | ROLLBACK opt_transaction TO ColId
8646 TransactionStmt *n = makeNode(TransactionStmt);
8647 n->kind = TRANS_STMT_ROLLBACK_TO;
8648 n->options = list_make1(makeDefElem("savepoint_name",
8649 (Node *)makeString($4)));
8652 | PREPARE TRANSACTION Sconst
8654 TransactionStmt *n = makeNode(TransactionStmt);
8655 n->kind = TRANS_STMT_PREPARE;
8659 | COMMIT PREPARED Sconst
8661 TransactionStmt *n = makeNode(TransactionStmt);
8662 n->kind = TRANS_STMT_COMMIT_PREPARED;
8666 | ROLLBACK PREPARED Sconst
8668 TransactionStmt *n = makeNode(TransactionStmt);
8669 n->kind = TRANS_STMT_ROLLBACK_PREPARED;
8675 opt_transaction: WORK {}
8680 transaction_mode_item:
8681 ISOLATION LEVEL iso_level
8682 { $$ = makeDefElem("transaction_isolation",
8683 makeStringConst($3, @3)); }
8685 { $$ = makeDefElem("transaction_read_only",
8686 makeIntConst(TRUE, @1)); }
8688 { $$ = makeDefElem("transaction_read_only",
8689 makeIntConst(FALSE, @1)); }
8691 { $$ = makeDefElem("transaction_deferrable",
8692 makeIntConst(TRUE, @1)); }
8694 { $$ = makeDefElem("transaction_deferrable",
8695 makeIntConst(FALSE, @1)); }
8698 /* Syntax with commas is SQL-spec, without commas is Postgres historical */
8699 transaction_mode_list:
8700 transaction_mode_item
8701 { $$ = list_make1($1); }
8702 | transaction_mode_list ',' transaction_mode_item
8703 { $$ = lappend($1, $3); }
8704 | transaction_mode_list transaction_mode_item
8705 { $$ = lappend($1, $2); }
8708 transaction_mode_list_or_empty:
8709 transaction_mode_list
8715 /*****************************************************************************
8718 * CREATE [ OR REPLACE ] [ TEMP ] VIEW <viewname> '('target-list ')'
8719 * AS <query> [ WITH [ CASCADED | LOCAL ] CHECK OPTION ]
8721 *****************************************************************************/
8723 ViewStmt: CREATE OptTemp VIEW qualified_name opt_column_list opt_reloptions
8724 AS SelectStmt opt_check_option
8726 ViewStmt *n = makeNode(ViewStmt);
8728 n->view->relpersistence = $2;
8733 n->withCheckOption = $9;
8736 | CREATE OR REPLACE OptTemp VIEW qualified_name opt_column_list opt_reloptions
8737 AS SelectStmt opt_check_option
8739 ViewStmt *n = makeNode(ViewStmt);
8741 n->view->relpersistence = $4;
8746 n->withCheckOption = $11;
8749 | CREATE OptTemp RECURSIVE VIEW qualified_name '(' columnList ')' opt_reloptions
8750 AS SelectStmt opt_check_option
8752 ViewStmt *n = makeNode(ViewStmt);
8754 n->view->relpersistence = $2;
8756 n->query = makeRecursiveViewSelect(n->view->relname, n->aliases, $11);
8759 n->withCheckOption = $12;
8760 if (n->withCheckOption != NO_CHECK_OPTION)
8762 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
8763 errmsg("WITH CHECK OPTION not supported on recursive views"),
8764 parser_errposition(@12)));
8767 | CREATE OR REPLACE OptTemp RECURSIVE VIEW qualified_name '(' columnList ')' opt_reloptions
8768 AS SelectStmt opt_check_option
8770 ViewStmt *n = makeNode(ViewStmt);
8772 n->view->relpersistence = $4;
8774 n->query = makeRecursiveViewSelect(n->view->relname, n->aliases, $13);
8777 n->withCheckOption = $14;
8778 if (n->withCheckOption != NO_CHECK_OPTION)
8780 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
8781 errmsg("WITH CHECK OPTION not supported on recursive views"),
8782 parser_errposition(@14)));
8788 WITH CHECK OPTION { $$ = CASCADED_CHECK_OPTION; }
8789 | WITH CASCADED CHECK OPTION { $$ = CASCADED_CHECK_OPTION; }
8790 | WITH LOCAL CHECK OPTION { $$ = LOCAL_CHECK_OPTION; }
8791 | /* EMPTY */ { $$ = NO_CHECK_OPTION; }
8794 /*****************************************************************************
8799 *****************************************************************************/
8801 LoadStmt: LOAD file_name
8803 LoadStmt *n = makeNode(LoadStmt);
8810 /*****************************************************************************
8814 *****************************************************************************/
8817 CREATE DATABASE database_name opt_with createdb_opt_list
8819 CreatedbStmt *n = makeNode(CreatedbStmt);
8827 createdb_opt_items { $$ = $1; }
8828 | /* EMPTY */ { $$ = NIL; }
8832 createdb_opt_item { $$ = list_make1($1); }
8833 | createdb_opt_items createdb_opt_item { $$ = lappend($1, $2); }
8837 createdb_opt_name opt_equal SignedIconst
8839 $$ = makeDefElem($1, (Node *)makeInteger($3));
8841 | createdb_opt_name opt_equal opt_boolean_or_string
8843 $$ = makeDefElem($1, (Node *)makeString($3));
8845 | createdb_opt_name opt_equal DEFAULT
8847 $$ = makeDefElem($1, NULL);
8852 * Ideally we'd use ColId here, but that causes shift/reduce conflicts against
8853 * the ALTER DATABASE SET/RESET syntaxes. Instead call out specific keywords
8854 * we need, and allow IDENT so that database option names don't have to be
8855 * parser keywords unless they are already keywords for other reasons.
8857 * XXX this coding technique is fragile since if someone makes a formerly
8858 * non-keyword option name into a keyword and forgets to add it here, the
8859 * option will silently break. Best defense is to provide a regression test
8860 * exercising every such option, at least at the syntax level.
8864 | CONNECTION LIMIT { $$ = pstrdup("connection_limit"); }
8865 | ENCODING { $$ = pstrdup($1); }
8866 | LOCATION { $$ = pstrdup($1); }
8867 | OWNER { $$ = pstrdup($1); }
8868 | TABLESPACE { $$ = pstrdup($1); }
8869 | TEMPLATE { $$ = pstrdup($1); }
8873 * Though the equals sign doesn't match other WITH options, pg_dump uses
8874 * equals for backward compatibility, and it doesn't seem worth removing it.
8881 /*****************************************************************************
8885 *****************************************************************************/
8888 ALTER DATABASE database_name WITH createdb_opt_list
8890 AlterDatabaseStmt *n = makeNode(AlterDatabaseStmt);
8895 | ALTER DATABASE database_name createdb_opt_list
8897 AlterDatabaseStmt *n = makeNode(AlterDatabaseStmt);
8902 | ALTER DATABASE database_name SET TABLESPACE name
8904 AlterDatabaseStmt *n = makeNode(AlterDatabaseStmt);
8906 n->options = list_make1(makeDefElem("tablespace",
8907 (Node *)makeString($6)));
8912 AlterDatabaseSetStmt:
8913 ALTER DATABASE database_name SetResetClause
8915 AlterDatabaseSetStmt *n = makeNode(AlterDatabaseSetStmt);
8923 /*****************************************************************************
8925 * DROP DATABASE [ IF EXISTS ]
8927 * This is implicitly CASCADE, no need for drop behavior
8928 *****************************************************************************/
8930 DropdbStmt: DROP DATABASE database_name
8932 DropdbStmt *n = makeNode(DropdbStmt);
8934 n->missing_ok = FALSE;
8937 | DROP DATABASE IF_P EXISTS database_name
8939 DropdbStmt *n = makeNode(DropdbStmt);
8941 n->missing_ok = TRUE;
8947 /*****************************************************************************
8951 * This is used to change configuration parameters persistently.
8952 *****************************************************************************/
8955 ALTER SYSTEM_P SET generic_set
8957 AlterSystemStmt *n = makeNode(AlterSystemStmt);
8961 | ALTER SYSTEM_P RESET generic_reset
8963 AlterSystemStmt *n = makeNode(AlterSystemStmt);
8970 /*****************************************************************************
8972 * Manipulate a domain
8974 *****************************************************************************/
8977 CREATE DOMAIN_P any_name opt_as Typename ColQualList
8979 CreateDomainStmt *n = makeNode(CreateDomainStmt);
8982 SplitColQualList($6, &n->constraints, &n->collClause,
8989 /* ALTER DOMAIN <domain> {SET DEFAULT <expr>|DROP DEFAULT} */
8990 ALTER DOMAIN_P any_name alter_column_default
8992 AlterDomainStmt *n = makeNode(AlterDomainStmt);
8998 /* ALTER DOMAIN <domain> DROP NOT NULL */
8999 | ALTER DOMAIN_P any_name DROP NOT NULL_P
9001 AlterDomainStmt *n = makeNode(AlterDomainStmt);
9006 /* ALTER DOMAIN <domain> SET NOT NULL */
9007 | ALTER DOMAIN_P any_name SET NOT NULL_P
9009 AlterDomainStmt *n = makeNode(AlterDomainStmt);
9014 /* ALTER DOMAIN <domain> ADD CONSTRAINT ... */
9015 | ALTER DOMAIN_P any_name ADD_P TableConstraint
9017 AlterDomainStmt *n = makeNode(AlterDomainStmt);
9023 /* ALTER DOMAIN <domain> DROP CONSTRAINT <name> [RESTRICT|CASCADE] */
9024 | ALTER DOMAIN_P any_name DROP CONSTRAINT name opt_drop_behavior
9026 AlterDomainStmt *n = makeNode(AlterDomainStmt);
9031 n->missing_ok = false;
9034 /* ALTER DOMAIN <domain> DROP CONSTRAINT IF EXISTS <name> [RESTRICT|CASCADE] */
9035 | ALTER DOMAIN_P any_name DROP CONSTRAINT IF_P EXISTS name opt_drop_behavior
9037 AlterDomainStmt *n = makeNode(AlterDomainStmt);
9042 n->missing_ok = true;
9045 /* ALTER DOMAIN <domain> VALIDATE CONSTRAINT <name> */
9046 | ALTER DOMAIN_P any_name VALIDATE CONSTRAINT name
9048 AlterDomainStmt *n = makeNode(AlterDomainStmt);
9061 /*****************************************************************************
9063 * Manipulate a text search dictionary or configuration
9065 *****************************************************************************/
9067 AlterTSDictionaryStmt:
9068 ALTER TEXT_P SEARCH DICTIONARY any_name definition
9070 AlterTSDictionaryStmt *n = makeNode(AlterTSDictionaryStmt);
9077 AlterTSConfigurationStmt:
9078 ALTER TEXT_P SEARCH CONFIGURATION any_name ADD_P MAPPING FOR name_list any_with any_name_list
9080 AlterTSConfigurationStmt *n = makeNode(AlterTSConfigurationStmt);
9081 n->kind = ALTER_TSCONFIG_ADD_MAPPING;
9085 n->override = false;
9089 | ALTER TEXT_P SEARCH CONFIGURATION any_name ALTER MAPPING FOR name_list any_with any_name_list
9091 AlterTSConfigurationStmt *n = makeNode(AlterTSConfigurationStmt);
9092 n->kind = ALTER_TSCONFIG_ALTER_MAPPING_FOR_TOKEN;
9100 | ALTER TEXT_P SEARCH CONFIGURATION any_name ALTER MAPPING REPLACE any_name any_with any_name
9102 AlterTSConfigurationStmt *n = makeNode(AlterTSConfigurationStmt);
9103 n->kind = ALTER_TSCONFIG_REPLACE_DICT;
9106 n->dicts = list_make2($9,$11);
9107 n->override = false;
9111 | ALTER TEXT_P SEARCH CONFIGURATION any_name ALTER MAPPING FOR name_list REPLACE any_name any_with any_name
9113 AlterTSConfigurationStmt *n = makeNode(AlterTSConfigurationStmt);
9114 n->kind = ALTER_TSCONFIG_REPLACE_DICT_FOR_TOKEN;
9117 n->dicts = list_make2($11,$13);
9118 n->override = false;
9122 | ALTER TEXT_P SEARCH CONFIGURATION any_name DROP MAPPING FOR name_list
9124 AlterTSConfigurationStmt *n = makeNode(AlterTSConfigurationStmt);
9125 n->kind = ALTER_TSCONFIG_DROP_MAPPING;
9128 n->missing_ok = false;
9131 | ALTER TEXT_P SEARCH CONFIGURATION any_name DROP MAPPING IF_P EXISTS FOR name_list
9133 AlterTSConfigurationStmt *n = makeNode(AlterTSConfigurationStmt);
9134 n->kind = ALTER_TSCONFIG_DROP_MAPPING;
9137 n->missing_ok = true;
9142 /* Use this if TIME or ORDINALITY after WITH should be taken as an identifier */
9148 /*****************************************************************************
9150 * Manipulate a conversion
9152 * CREATE [DEFAULT] CONVERSION <conversion_name>
9153 * FOR <encoding_name> TO <encoding_name> FROM <func_name>
9155 *****************************************************************************/
9157 CreateConversionStmt:
9158 CREATE opt_default CONVERSION_P any_name FOR Sconst
9159 TO Sconst FROM any_name
9161 CreateConversionStmt *n = makeNode(CreateConversionStmt);
9162 n->conversion_name = $4;
9163 n->for_encoding_name = $6;
9164 n->to_encoding_name = $8;
9171 /*****************************************************************************
9174 * CLUSTER [VERBOSE] <qualified_name> [ USING <index_name> ]
9176 * CLUSTER [VERBOSE] <index_name> ON <qualified_name> (for pre-8.3)
9178 *****************************************************************************/
9181 CLUSTER opt_verbose qualified_name cluster_index_specification
9183 ClusterStmt *n = makeNode(ClusterStmt);
9189 | CLUSTER opt_verbose
9191 ClusterStmt *n = makeNode(ClusterStmt);
9193 n->indexname = NULL;
9197 /* kept for pre-8.3 compatibility */
9198 | CLUSTER opt_verbose index_name ON qualified_name
9200 ClusterStmt *n = makeNode(ClusterStmt);
9208 cluster_index_specification:
9209 USING index_name { $$ = $2; }
9210 | /*EMPTY*/ { $$ = NULL; }
9214 /*****************************************************************************
9220 *****************************************************************************/
9222 VacuumStmt: VACUUM opt_full opt_freeze opt_verbose
9224 VacuumStmt *n = makeNode(VacuumStmt);
9225 n->options = VACOPT_VACUUM;
9227 n->options |= VACOPT_FULL;
9229 n->options |= VACOPT_FREEZE;
9231 n->options |= VACOPT_VERBOSE;
9236 | VACUUM opt_full opt_freeze opt_verbose qualified_name
9238 VacuumStmt *n = makeNode(VacuumStmt);
9239 n->options = VACOPT_VACUUM;
9241 n->options |= VACOPT_FULL;
9243 n->options |= VACOPT_FREEZE;
9245 n->options |= VACOPT_VERBOSE;
9250 | VACUUM opt_full opt_freeze opt_verbose AnalyzeStmt
9252 VacuumStmt *n = (VacuumStmt *) $5;
9253 n->options |= VACOPT_VACUUM;
9255 n->options |= VACOPT_FULL;
9257 n->options |= VACOPT_FREEZE;
9259 n->options |= VACOPT_VERBOSE;
9262 | VACUUM '(' vacuum_option_list ')'
9264 VacuumStmt *n = makeNode(VacuumStmt);
9265 n->options = VACOPT_VACUUM | $3;
9270 | VACUUM '(' vacuum_option_list ')' qualified_name opt_name_list
9272 VacuumStmt *n = makeNode(VacuumStmt);
9273 n->options = VACOPT_VACUUM | $3;
9276 if (n->va_cols != NIL) /* implies analyze */
9277 n->options |= VACOPT_ANALYZE;
9283 vacuum_option_elem { $$ = $1; }
9284 | vacuum_option_list ',' vacuum_option_elem { $$ = $1 | $3; }
9288 analyze_keyword { $$ = VACOPT_ANALYZE; }
9289 | VERBOSE { $$ = VACOPT_VERBOSE; }
9290 | FREEZE { $$ = VACOPT_FREEZE; }
9291 | FULL { $$ = VACOPT_FULL; }
9295 analyze_keyword opt_verbose
9297 VacuumStmt *n = makeNode(VacuumStmt);
9298 n->options = VACOPT_ANALYZE;
9300 n->options |= VACOPT_VERBOSE;
9305 | analyze_keyword opt_verbose qualified_name opt_name_list
9307 VacuumStmt *n = makeNode(VacuumStmt);
9308 n->options = VACOPT_ANALYZE;
9310 n->options |= VACOPT_VERBOSE;
9319 | ANALYSE /* British */ {}
9323 VERBOSE { $$ = TRUE; }
9324 | /*EMPTY*/ { $$ = FALSE; }
9327 opt_full: FULL { $$ = TRUE; }
9328 | /*EMPTY*/ { $$ = FALSE; }
9331 opt_freeze: FREEZE { $$ = TRUE; }
9332 | /*EMPTY*/ { $$ = FALSE; }
9336 '(' name_list ')' { $$ = $2; }
9337 | /*EMPTY*/ { $$ = NIL; }
9341 /*****************************************************************************
9344 * EXPLAIN [ANALYZE] [VERBOSE] query
9345 * EXPLAIN ( options ) query
9347 *****************************************************************************/
9350 EXPLAIN ExplainableStmt
9352 ExplainStmt *n = makeNode(ExplainStmt);
9357 | EXPLAIN analyze_keyword opt_verbose ExplainableStmt
9359 ExplainStmt *n = makeNode(ExplainStmt);
9361 n->options = list_make1(makeDefElem("analyze", NULL));
9363 n->options = lappend(n->options,
9364 makeDefElem("verbose", NULL));
9367 | EXPLAIN VERBOSE ExplainableStmt
9369 ExplainStmt *n = makeNode(ExplainStmt);
9371 n->options = list_make1(makeDefElem("verbose", NULL));
9374 | EXPLAIN '(' explain_option_list ')' ExplainableStmt
9376 ExplainStmt *n = makeNode(ExplainStmt);
9391 | RefreshMatViewStmt
9392 | ExecuteStmt /* by default all are $$=$1 */
9395 explain_option_list:
9398 $$ = list_make1($1);
9400 | explain_option_list ',' explain_option_elem
9402 $$ = lappend($1, $3);
9406 explain_option_elem:
9407 explain_option_name explain_option_arg
9409 $$ = makeDefElem($1, $2);
9413 explain_option_name:
9414 NonReservedWord { $$ = $1; }
9415 | analyze_keyword { $$ = "analyze"; }
9419 opt_boolean_or_string { $$ = (Node *) makeString($1); }
9420 | NumericOnly { $$ = (Node *) $1; }
9421 | /* EMPTY */ { $$ = NULL; }
9424 /*****************************************************************************
9427 * PREPARE <plan_name> [(args, ...)] AS <query>
9429 *****************************************************************************/
9431 PrepareStmt: PREPARE name prep_type_clause AS PreparableStmt
9433 PrepareStmt *n = makeNode(PrepareStmt);
9441 prep_type_clause: '(' type_list ')' { $$ = $2; }
9442 | /* EMPTY */ { $$ = NIL; }
9449 | DeleteStmt /* by default all are $$=$1 */
9452 /*****************************************************************************
9454 * EXECUTE <plan_name> [(params, ...)]
9455 * CREATE TABLE <name> AS EXECUTE <plan_name> [(params, ...)]
9457 *****************************************************************************/
9459 ExecuteStmt: EXECUTE name execute_param_clause
9461 ExecuteStmt *n = makeNode(ExecuteStmt);
9466 | CREATE OptTemp TABLE create_as_target AS
9467 EXECUTE name execute_param_clause opt_with_data
9469 CreateTableAsStmt *ctas = makeNode(CreateTableAsStmt);
9470 ExecuteStmt *n = makeNode(ExecuteStmt);
9473 ctas->query = (Node *) n;
9475 ctas->relkind = OBJECT_TABLE;
9476 ctas->is_select_into = false;
9477 /* cram additional flags into the IntoClause */
9478 $4->rel->relpersistence = $2;
9479 $4->skipData = !($9);
9484 execute_param_clause: '(' expr_list ')' { $$ = $2; }
9485 | /* EMPTY */ { $$ = NIL; }
9488 /*****************************************************************************
9491 * DEALLOCATE [PREPARE] <plan_name>
9493 *****************************************************************************/
9495 DeallocateStmt: DEALLOCATE name
9497 DeallocateStmt *n = makeNode(DeallocateStmt);
9501 | DEALLOCATE PREPARE name
9503 DeallocateStmt *n = makeNode(DeallocateStmt);
9509 DeallocateStmt *n = makeNode(DeallocateStmt);
9513 | DEALLOCATE PREPARE ALL
9515 DeallocateStmt *n = makeNode(DeallocateStmt);
9521 /*****************************************************************************
9526 *****************************************************************************/
9529 opt_with_clause INSERT INTO insert_target insert_rest
9530 opt_on_conflict returning_clause
9533 $5->onConflictClause = $6;
9534 $5->returningList = $7;
9535 $5->withClause = $1;
9541 * Can't easily make AS optional here, because VALUES in insert_rest would
9542 * have a shift/reduce conflict with VALUES as an optional alias. We could
9543 * easily allow unreserved_keywords as optional aliases, but that'd be an odd
9544 * divergence from other places. So just require AS for now.
9551 | qualified_name AS ColId
9553 $1->alias = makeAlias($3, NIL);
9561 $$ = makeNode(InsertStmt);
9563 $$->selectStmt = $1;
9565 | '(' insert_column_list ')' SelectStmt
9567 $$ = makeNode(InsertStmt);
9569 $$->selectStmt = $4;
9573 $$ = makeNode(InsertStmt);
9575 $$->selectStmt = NULL;
9581 { $$ = list_make1($1); }
9582 | insert_column_list ',' insert_column_item
9583 { $$ = lappend($1, $3); }
9587 ColId opt_indirection
9589 $$ = makeNode(ResTarget);
9591 $$->indirection = check_indirection($2, yyscanner);
9598 ON CONFLICT opt_conf_expr DO UPDATE SET set_clause_list where_clause
9600 $$ = makeNode(OnConflictClause);
9601 $$->action = ONCONFLICT_UPDATE;
9603 $$->targetList = $7;
9604 $$->whereClause = $8;
9608 ON CONFLICT opt_conf_expr DO NOTHING
9610 $$ = makeNode(OnConflictClause);
9611 $$->action = ONCONFLICT_NOTHING;
9613 $$->targetList = NIL;
9614 $$->whereClause = NULL;
9624 '(' index_params ')' where_clause
9626 $$ = makeNode(InferClause);
9627 $$->indexElems = $2;
9628 $$->whereClause = $4;
9635 $$ = makeNode(InferClause);
9636 $$->indexElems = NIL;
9637 $$->whereClause = NULL;
9648 RETURNING target_list { $$ = $2; }
9649 | /* EMPTY */ { $$ = NIL; }
9653 /*****************************************************************************
9658 *****************************************************************************/
9660 DeleteStmt: opt_with_clause DELETE_P FROM relation_expr_opt_alias
9661 using_clause where_or_current_clause returning_clause
9663 DeleteStmt *n = makeNode(DeleteStmt);
9665 n->usingClause = $5;
9666 n->whereClause = $6;
9667 n->returningList = $7;
9674 USING from_list { $$ = $2; }
9675 | /*EMPTY*/ { $$ = NIL; }
9679 /*****************************************************************************
9684 *****************************************************************************/
9686 LockStmt: LOCK_P opt_table relation_expr_list opt_lock opt_nowait
9688 LockStmt *n = makeNode(LockStmt);
9697 opt_lock: IN_P lock_type MODE { $$ = $2; }
9698 | /*EMPTY*/ { $$ = AccessExclusiveLock; }
9701 lock_type: ACCESS SHARE { $$ = AccessShareLock; }
9702 | ROW SHARE { $$ = RowShareLock; }
9703 | ROW EXCLUSIVE { $$ = RowExclusiveLock; }
9704 | SHARE UPDATE EXCLUSIVE { $$ = ShareUpdateExclusiveLock; }
9705 | SHARE { $$ = ShareLock; }
9706 | SHARE ROW EXCLUSIVE { $$ = ShareRowExclusiveLock; }
9707 | EXCLUSIVE { $$ = ExclusiveLock; }
9708 | ACCESS EXCLUSIVE { $$ = AccessExclusiveLock; }
9711 opt_nowait: NOWAIT { $$ = TRUE; }
9712 | /*EMPTY*/ { $$ = FALSE; }
9716 NOWAIT { $$ = LockWaitError; }
9717 | SKIP LOCKED { $$ = LockWaitSkip; }
9718 | /*EMPTY*/ { $$ = LockWaitBlock; }
9722 /*****************************************************************************
9725 * UpdateStmt (UPDATE)
9727 *****************************************************************************/
9729 UpdateStmt: opt_with_clause UPDATE relation_expr_opt_alias
9732 where_or_current_clause
9735 UpdateStmt *n = makeNode(UpdateStmt);
9739 n->whereClause = $7;
9740 n->returningList = $8;
9747 set_clause { $$ = $1; }
9748 | set_clause_list ',' set_clause { $$ = list_concat($1,$3); }
9752 single_set_clause { $$ = list_make1($1); }
9753 | multiple_set_clause { $$ = $1; }
9757 set_target '=' ctext_expr
9760 $$->val = (Node *) $3;
9765 * Ideally, we'd accept any row-valued a_expr as RHS of a multiple_set_clause.
9766 * However, per SQL spec the row-constructor case must allow DEFAULT as a row
9767 * member, and it's pretty unclear how to do that (unless perhaps we allow
9768 * DEFAULT in any a_expr and let parse analysis sort it out later?). For the
9769 * moment, the planner/executor only support a subquery as a multiassignment
9770 * source anyhow, so we need only accept ctext_row and subqueries here.
9772 multiple_set_clause:
9773 '(' set_target_list ')' '=' ctext_row
9779 * Break the ctext_row apart, merge individual expressions
9780 * into the destination ResTargets. This is semantically
9781 * equivalent to, and much cheaper to process than, the
9784 if (list_length($2) != list_length($5))
9786 (errcode(ERRCODE_SYNTAX_ERROR),
9787 errmsg("number of columns does not match number of values"),
9788 parser_errposition(@5)));
9789 forboth(col_cell, $2, val_cell, $5)
9791 ResTarget *res_col = (ResTarget *) lfirst(col_cell);
9792 Node *res_val = (Node *) lfirst(val_cell);
9794 res_col->val = res_val;
9799 | '(' set_target_list ')' '=' select_with_parens
9801 SubLink *sl = makeNode(SubLink);
9802 int ncolumns = list_length($2);
9806 /* First, convert bare SelectStmt into a SubLink */
9807 sl->subLinkType = MULTIEXPR_SUBLINK;
9808 sl->subLinkId = 0; /* will be assigned later */
9809 sl->testexpr = NULL;
9814 /* Create a MultiAssignRef source for each target */
9815 foreach(col_cell, $2)
9817 ResTarget *res_col = (ResTarget *) lfirst(col_cell);
9818 MultiAssignRef *r = makeNode(MultiAssignRef);
9820 r->source = (Node *) sl;
9822 r->ncolumns = ncolumns;
9823 res_col->val = (Node *) r;
9832 ColId opt_indirection
9834 $$ = makeNode(ResTarget);
9836 $$->indirection = check_indirection($2, yyscanner);
9837 $$->val = NULL; /* upper production sets this */
9843 set_target { $$ = list_make1($1); }
9844 | set_target_list ',' set_target { $$ = lappend($1,$3); }
9848 /*****************************************************************************
9853 *****************************************************************************/
9854 DeclareCursorStmt: DECLARE cursor_name cursor_options CURSOR opt_hold FOR SelectStmt
9856 DeclareCursorStmt *n = makeNode(DeclareCursorStmt);
9858 /* currently we always set FAST_PLAN option */
9859 n->options = $3 | $5 | CURSOR_OPT_FAST_PLAN;
9865 cursor_name: name { $$ = $1; }
9868 cursor_options: /*EMPTY*/ { $$ = 0; }
9869 | cursor_options NO SCROLL { $$ = $1 | CURSOR_OPT_NO_SCROLL; }
9870 | cursor_options SCROLL { $$ = $1 | CURSOR_OPT_SCROLL; }
9871 | cursor_options BINARY { $$ = $1 | CURSOR_OPT_BINARY; }
9872 | cursor_options INSENSITIVE { $$ = $1 | CURSOR_OPT_INSENSITIVE; }
9875 opt_hold: /* EMPTY */ { $$ = 0; }
9876 | WITH HOLD { $$ = CURSOR_OPT_HOLD; }
9877 | WITHOUT HOLD { $$ = 0; }
9880 /*****************************************************************************
9885 *****************************************************************************/
9887 /* A complete SELECT statement looks like this.
9889 * The rule returns either a single SelectStmt node or a tree of them,
9890 * representing a set-operation tree.
9892 * There is an ambiguity when a sub-SELECT is within an a_expr and there
9893 * are excess parentheses: do the parentheses belong to the sub-SELECT or
9894 * to the surrounding a_expr? We don't really care, but bison wants to know.
9895 * To resolve the ambiguity, we are careful to define the grammar so that
9896 * the decision is staved off as long as possible: as long as we can keep
9897 * absorbing parentheses into the sub-SELECT, we will do so, and only when
9898 * it's no longer possible to do that will we decide that parens belong to
9899 * the expression. For example, in "SELECT (((SELECT 2)) + 3)" the extra
9900 * parentheses are treated as part of the sub-select. The necessity of doing
9901 * it that way is shown by "SELECT (((SELECT 2)) UNION SELECT 2)". Had we
9902 * parsed "((SELECT 2))" as an a_expr, it'd be too late to go back to the
9903 * SELECT viewpoint when we see the UNION.
9905 * This approach is implemented by defining a nonterminal select_with_parens,
9906 * which represents a SELECT with at least one outer layer of parentheses,
9907 * and being careful to use select_with_parens, never '(' SelectStmt ')',
9908 * in the expression grammar. We will then have shift-reduce conflicts
9909 * which we can resolve in favor of always treating '(' <select> ')' as
9910 * a select_with_parens. To resolve the conflicts, the productions that
9911 * conflict with the select_with_parens productions are manually given
9912 * precedences lower than the precedence of ')', thereby ensuring that we
9913 * shift ')' (and then reduce to select_with_parens) rather than trying to
9914 * reduce the inner <select> nonterminal to something else. We use UMINUS
9915 * precedence for this, which is a fairly arbitrary choice.
9917 * To be able to define select_with_parens itself without ambiguity, we need
9918 * a nonterminal select_no_parens that represents a SELECT structure with no
9919 * outermost parentheses. This is a little bit tedious, but it works.
9921 * In non-expression contexts, we use SelectStmt which can represent a SELECT
9922 * with or without outer parentheses.
9925 SelectStmt: select_no_parens %prec UMINUS
9926 | select_with_parens %prec UMINUS
9930 '(' select_no_parens ')' { $$ = $2; }
9931 | '(' select_with_parens ')' { $$ = $2; }
9935 * This rule parses the equivalent of the standard's <query expression>.
9936 * The duplicative productions are annoying, but hard to get rid of without
9937 * creating shift/reduce conflicts.
9939 * The locking clause (FOR UPDATE etc) may be before or after LIMIT/OFFSET.
9940 * In <=7.2.X, LIMIT/OFFSET had to be after FOR UPDATE
9941 * We now support both orderings, but prefer LIMIT/OFFSET before the locking
9946 simple_select { $$ = $1; }
9947 | select_clause sort_clause
9949 insertSelectOptions((SelectStmt *) $1, $2, NIL,
9954 | select_clause opt_sort_clause for_locking_clause opt_select_limit
9956 insertSelectOptions((SelectStmt *) $1, $2, $3,
9957 list_nth($4, 0), list_nth($4, 1),
9962 | select_clause opt_sort_clause select_limit opt_for_locking_clause
9964 insertSelectOptions((SelectStmt *) $1, $2, $4,
9965 list_nth($3, 0), list_nth($3, 1),
9970 | with_clause select_clause
9972 insertSelectOptions((SelectStmt *) $2, NULL, NIL,
9978 | with_clause select_clause sort_clause
9980 insertSelectOptions((SelectStmt *) $2, $3, NIL,
9986 | with_clause select_clause opt_sort_clause for_locking_clause opt_select_limit
9988 insertSelectOptions((SelectStmt *) $2, $3, $4,
9989 list_nth($5, 0), list_nth($5, 1),
9994 | with_clause select_clause opt_sort_clause select_limit opt_for_locking_clause
9996 insertSelectOptions((SelectStmt *) $2, $3, $5,
9997 list_nth($4, 0), list_nth($4, 1),
10005 simple_select { $$ = $1; }
10006 | select_with_parens { $$ = $1; }
10010 * This rule parses SELECT statements that can appear within set operations,
10011 * including UNION, INTERSECT and EXCEPT. '(' and ')' can be used to specify
10012 * the ordering of the set operations. Without '(' and ')' we want the
10013 * operations to be ordered per the precedence specs at the head of this file.
10015 * As with select_no_parens, simple_select cannot have outer parentheses,
10016 * but can have parenthesized subclauses.
10018 * Note that sort clauses cannot be included at this level --- SQL requires
10019 * SELECT foo UNION SELECT bar ORDER BY baz
10021 * (SELECT foo UNION SELECT bar) ORDER BY baz
10023 * SELECT foo UNION (SELECT bar ORDER BY baz)
10024 * Likewise for WITH, FOR UPDATE and LIMIT. Therefore, those clauses are
10025 * described as part of the select_no_parens production, not simple_select.
10026 * This does not limit functionality, because you can reintroduce these
10027 * clauses inside parentheses.
10029 * NOTE: only the leftmost component SelectStmt should have INTO.
10030 * However, this is not checked by the grammar; parse analysis must check it.
10033 SELECT opt_all_clause opt_target_list
10034 into_clause from_clause where_clause
10035 group_clause having_clause window_clause
10037 SelectStmt *n = makeNode(SelectStmt);
10038 n->targetList = $3;
10039 n->intoClause = $4;
10040 n->fromClause = $5;
10041 n->whereClause = $6;
10042 n->groupClause = $7;
10043 n->havingClause = $8;
10044 n->windowClause = $9;
10047 | SELECT distinct_clause target_list
10048 into_clause from_clause where_clause
10049 group_clause having_clause window_clause
10051 SelectStmt *n = makeNode(SelectStmt);
10052 n->distinctClause = $2;
10053 n->targetList = $3;
10054 n->intoClause = $4;
10055 n->fromClause = $5;
10056 n->whereClause = $6;
10057 n->groupClause = $7;
10058 n->havingClause = $8;
10059 n->windowClause = $9;
10062 | values_clause { $$ = $1; }
10063 | TABLE relation_expr
10065 /* same as SELECT * FROM relation_expr */
10066 ColumnRef *cr = makeNode(ColumnRef);
10067 ResTarget *rt = makeNode(ResTarget);
10068 SelectStmt *n = makeNode(SelectStmt);
10070 cr->fields = list_make1(makeNode(A_Star));
10074 rt->indirection = NIL;
10075 rt->val = (Node *)cr;
10078 n->targetList = list_make1(rt);
10079 n->fromClause = list_make1($2);
10082 | select_clause UNION all_or_distinct select_clause
10084 $$ = makeSetOp(SETOP_UNION, $3, $1, $4);
10086 | select_clause INTERSECT all_or_distinct select_clause
10088 $$ = makeSetOp(SETOP_INTERSECT, $3, $1, $4);
10090 | select_clause EXCEPT all_or_distinct select_clause
10092 $$ = makeSetOp(SETOP_EXCEPT, $3, $1, $4);
10097 * SQL standard WITH clause looks like:
10099 * WITH [ RECURSIVE ] <query name> [ (<column>,...) ]
10100 * AS (query) [ SEARCH or CYCLE clause ]
10102 * We don't currently support the SEARCH or CYCLE clause.
10104 * Recognizing WITH_LA here allows a CTE to be named TIME or ORDINALITY.
10109 $$ = makeNode(WithClause);
10111 $$->recursive = false;
10116 $$ = makeNode(WithClause);
10118 $$->recursive = false;
10121 | WITH RECURSIVE cte_list
10123 $$ = makeNode(WithClause);
10125 $$->recursive = true;
10131 common_table_expr { $$ = list_make1($1); }
10132 | cte_list ',' common_table_expr { $$ = lappend($1, $3); }
10135 common_table_expr: name opt_name_list AS '(' PreparableStmt ')'
10137 CommonTableExpr *n = makeNode(CommonTableExpr);
10139 n->aliascolnames = $2;
10147 with_clause { $$ = $1; }
10148 | /*EMPTY*/ { $$ = NULL; }
10152 INTO OptTempTableName
10154 $$ = makeNode(IntoClause);
10156 $$->colNames = NIL;
10158 $$->onCommit = ONCOMMIT_NOOP;
10159 $$->tableSpaceName = NULL;
10160 $$->viewQuery = NULL;
10161 $$->skipData = false;
10168 * Redundancy here is needed to avoid shift/reduce conflicts,
10169 * since TEMP is not a reserved word. See also OptTemp.
10172 TEMPORARY opt_table qualified_name
10175 $$->relpersistence = RELPERSISTENCE_TEMP;
10177 | TEMP opt_table qualified_name
10180 $$->relpersistence = RELPERSISTENCE_TEMP;
10182 | LOCAL TEMPORARY opt_table qualified_name
10185 $$->relpersistence = RELPERSISTENCE_TEMP;
10187 | LOCAL TEMP opt_table qualified_name
10190 $$->relpersistence = RELPERSISTENCE_TEMP;
10192 | GLOBAL TEMPORARY opt_table qualified_name
10195 (errmsg("GLOBAL is deprecated in temporary table creation"),
10196 parser_errposition(@1)));
10198 $$->relpersistence = RELPERSISTENCE_TEMP;
10200 | GLOBAL TEMP opt_table qualified_name
10203 (errmsg("GLOBAL is deprecated in temporary table creation"),
10204 parser_errposition(@1)));
10206 $$->relpersistence = RELPERSISTENCE_TEMP;
10208 | UNLOGGED opt_table qualified_name
10211 $$->relpersistence = RELPERSISTENCE_UNLOGGED;
10213 | TABLE qualified_name
10216 $$->relpersistence = RELPERSISTENCE_PERMANENT;
10221 $$->relpersistence = RELPERSISTENCE_PERMANENT;
10225 opt_table: TABLE {}
10231 | DISTINCT { $$ = FALSE; }
10232 | /*EMPTY*/ { $$ = FALSE; }
10235 /* We use (NIL) as a placeholder to indicate that all target expressions
10236 * should be placed in the DISTINCT list during parsetree analysis.
10239 DISTINCT { $$ = list_make1(NIL); }
10240 | DISTINCT ON '(' expr_list ')' { $$ = $4; }
10245 | /*EMPTY*/ { $$ = NIL; }
10249 sort_clause { $$ = $1;}
10250 | /*EMPTY*/ { $$ = NIL; }
10254 ORDER BY sortby_list { $$ = $3; }
10258 sortby { $$ = list_make1($1); }
10259 | sortby_list ',' sortby { $$ = lappend($1, $3); }
10262 sortby: a_expr USING qual_all_Op opt_nulls_order
10264 $$ = makeNode(SortBy);
10266 $$->sortby_dir = SORTBY_USING;
10267 $$->sortby_nulls = $4;
10271 | a_expr opt_asc_desc opt_nulls_order
10273 $$ = makeNode(SortBy);
10275 $$->sortby_dir = $2;
10276 $$->sortby_nulls = $3;
10278 $$->location = -1; /* no operator */
10284 limit_clause offset_clause { $$ = list_make2($2, $1); }
10285 | offset_clause limit_clause { $$ = list_make2($1, $2); }
10286 | limit_clause { $$ = list_make2(NULL, $1); }
10287 | offset_clause { $$ = list_make2($1, NULL); }
10291 select_limit { $$ = $1; }
10292 | /* EMPTY */ { $$ = list_make2(NULL,NULL); }
10296 LIMIT select_limit_value
10298 | LIMIT select_limit_value ',' select_offset_value
10300 /* Disabled because it was too confusing, bjm 2002-02-18 */
10302 (errcode(ERRCODE_SYNTAX_ERROR),
10303 errmsg("LIMIT #,# syntax is not supported"),
10304 errhint("Use separate LIMIT and OFFSET clauses."),
10305 parser_errposition(@1)));
10307 /* SQL:2008 syntax */
10308 | FETCH first_or_next opt_select_fetch_first_value row_or_rows ONLY
10313 OFFSET select_offset_value
10315 /* SQL:2008 syntax */
10316 | OFFSET select_offset_value2 row_or_rows
10320 select_limit_value:
10321 a_expr { $$ = $1; }
10324 /* LIMIT ALL is represented as a NULL constant */
10325 $$ = makeNullAConst(@1);
10329 select_offset_value:
10330 a_expr { $$ = $1; }
10334 * Allowing full expressions without parentheses causes various parsing
10335 * problems with the trailing ROW/ROWS key words. SQL only calls for
10336 * constants, so we allow the rest only with parentheses. If omitted,
10339 opt_select_fetch_first_value:
10340 SignedIconst { $$ = makeIntConst($1, @1); }
10341 | '(' a_expr ')' { $$ = $2; }
10342 | /*EMPTY*/ { $$ = makeIntConst(1, -1); }
10346 * Again, the trailing ROW/ROWS in this case prevent the full expression
10347 * syntax. c_expr is the best we can do.
10349 select_offset_value2:
10350 c_expr { $$ = $1; }
10354 row_or_rows: ROW { $$ = 0; }
10358 first_or_next: FIRST_P { $$ = 0; }
10364 * This syntax for group_clause tries to follow the spec quite closely.
10365 * However, the spec allows only column references, not expressions,
10366 * which introduces an ambiguity between implicit row constructors
10367 * (a,b) and lists of column references.
10369 * We handle this by using the a_expr production for what the spec calls
10370 * <ordinary grouping set>, which in the spec represents either one column
10371 * reference or a parenthesized list of column references. Then, we check the
10372 * top node of the a_expr to see if it's an implicit RowExpr, and if so, just
10373 * grab and use the list, discarding the node. (this is done in parse analysis,
10376 * (we abuse the row_format field of RowExpr to distinguish implicit and
10377 * explicit row constructors; it's debatable if anyone sanely wants to use them
10378 * in a group clause, but if they have a reason to, we make it possible.)
10380 * Each item in the group_clause list is either an expression tree or a
10381 * GroupingSet node of some type.
10384 GROUP_P BY group_by_list { $$ = $3; }
10385 | /*EMPTY*/ { $$ = NIL; }
10389 group_by_item { $$ = list_make1($1); }
10390 | group_by_list ',' group_by_item { $$ = lappend($1,$3); }
10394 a_expr { $$ = $1; }
10395 | empty_grouping_set { $$ = $1; }
10396 | cube_clause { $$ = $1; }
10397 | rollup_clause { $$ = $1; }
10398 | grouping_sets_clause { $$ = $1; }
10401 empty_grouping_set:
10404 $$ = (Node *) makeGroupingSet(GROUPING_SET_EMPTY, NIL, @1);
10409 * These hacks rely on setting precedence of CUBE and ROLLUP below that of '(',
10410 * so that they shift in these rules rather than reducing the conflicting
10411 * unreserved_keyword rule.
10415 ROLLUP '(' expr_list ')'
10417 $$ = (Node *) makeGroupingSet(GROUPING_SET_ROLLUP, $3, @1);
10422 CUBE '(' expr_list ')'
10424 $$ = (Node *) makeGroupingSet(GROUPING_SET_CUBE, $3, @1);
10428 grouping_sets_clause:
10429 GROUPING SETS '(' group_by_list ')'
10431 $$ = (Node *) makeGroupingSet(GROUPING_SET_SETS, $4, @1);
10436 HAVING a_expr { $$ = $2; }
10437 | /*EMPTY*/ { $$ = NULL; }
10440 for_locking_clause:
10441 for_locking_items { $$ = $1; }
10442 | FOR READ ONLY { $$ = NIL; }
10445 opt_for_locking_clause:
10446 for_locking_clause { $$ = $1; }
10447 | /* EMPTY */ { $$ = NIL; }
10451 for_locking_item { $$ = list_make1($1); }
10452 | for_locking_items for_locking_item { $$ = lappend($1, $2); }
10456 for_locking_strength locked_rels_list opt_nowait_or_skip
10458 LockingClause *n = makeNode(LockingClause);
10459 n->lockedRels = $2;
10461 n->waitPolicy = $3;
10466 for_locking_strength:
10467 FOR UPDATE { $$ = LCS_FORUPDATE; }
10468 | FOR NO KEY UPDATE { $$ = LCS_FORNOKEYUPDATE; }
10469 | FOR SHARE { $$ = LCS_FORSHARE; }
10470 | FOR KEY SHARE { $$ = LCS_FORKEYSHARE; }
10474 OF qualified_name_list { $$ = $2; }
10475 | /* EMPTY */ { $$ = NIL; }
10482 SelectStmt *n = makeNode(SelectStmt);
10483 n->valuesLists = list_make1($2);
10486 | values_clause ',' ctext_row
10488 SelectStmt *n = (SelectStmt *) $1;
10489 n->valuesLists = lappend(n->valuesLists, $3);
10495 /*****************************************************************************
10497 * clauses common to all Optimizable Stmts:
10498 * from_clause - allow list of both JOIN expressions and table names
10499 * where_clause - qualifications for joins or restrictions
10501 *****************************************************************************/
10504 FROM from_list { $$ = $2; }
10505 | /*EMPTY*/ { $$ = NIL; }
10509 table_ref { $$ = list_make1($1); }
10510 | from_list ',' table_ref { $$ = lappend($1, $3); }
10514 * table_ref is where an alias clause can be attached.
10516 table_ref: relation_expr opt_alias_clause
10521 | relation_expr opt_alias_clause tablesample_clause
10523 RangeTableSample *n = (RangeTableSample *) $3;
10525 /* relation_expr goes inside the RangeTableSample node */
10526 n->relation = (Node *) $1;
10529 | func_table func_alias_clause
10531 RangeFunction *n = (RangeFunction *) $1;
10532 n->alias = linitial($2);
10533 n->coldeflist = lsecond($2);
10536 | LATERAL_P func_table func_alias_clause
10538 RangeFunction *n = (RangeFunction *) $2;
10540 n->alias = linitial($3);
10541 n->coldeflist = lsecond($3);
10544 | select_with_parens opt_alias_clause
10546 RangeSubselect *n = makeNode(RangeSubselect);
10547 n->lateral = false;
10551 * The SQL spec does not permit a subselect
10552 * (<derived_table>) without an alias clause,
10553 * so we don't either. This avoids the problem
10554 * of needing to invent a unique refname for it.
10555 * That could be surmounted if there's sufficient
10556 * popular demand, but for now let's just implement
10557 * the spec and see if anyone complains.
10558 * However, it does seem like a good idea to emit
10559 * an error message that's better than "syntax error".
10563 if (IsA($1, SelectStmt) &&
10564 ((SelectStmt *) $1)->valuesLists)
10566 (errcode(ERRCODE_SYNTAX_ERROR),
10567 errmsg("VALUES in FROM must have an alias"),
10568 errhint("For example, FROM (VALUES ...) [AS] foo."),
10569 parser_errposition(@1)));
10572 (errcode(ERRCODE_SYNTAX_ERROR),
10573 errmsg("subquery in FROM must have an alias"),
10574 errhint("For example, FROM (SELECT ...) [AS] foo."),
10575 parser_errposition(@1)));
10579 | LATERAL_P select_with_parens opt_alias_clause
10581 RangeSubselect *n = makeNode(RangeSubselect);
10585 /* same coment as above */
10588 if (IsA($2, SelectStmt) &&
10589 ((SelectStmt *) $2)->valuesLists)
10591 (errcode(ERRCODE_SYNTAX_ERROR),
10592 errmsg("VALUES in FROM must have an alias"),
10593 errhint("For example, FROM (VALUES ...) [AS] foo."),
10594 parser_errposition(@2)));
10597 (errcode(ERRCODE_SYNTAX_ERROR),
10598 errmsg("subquery in FROM must have an alias"),
10599 errhint("For example, FROM (SELECT ...) [AS] foo."),
10600 parser_errposition(@2)));
10608 | '(' joined_table ')' alias_clause
10617 * It may seem silly to separate joined_table from table_ref, but there is
10618 * method in SQL's madness: if you don't do it this way you get reduce-
10619 * reduce conflicts, because it's not clear to the parser generator whether
10620 * to expect alias_clause after ')' or not. For the same reason we must
10621 * treat 'JOIN' and 'join_type JOIN' separately, rather than allowing
10622 * join_type to expand to empty; if we try it, the parser generator can't
10623 * figure out when to reduce an empty join_type right after table_ref.
10625 * Note that a CROSS JOIN is the same as an unqualified
10626 * INNER JOIN, and an INNER JOIN/ON has the same shape
10627 * but a qualification expression to limit membership.
10628 * A NATURAL JOIN implicitly matches column names between
10629 * tables and the shape is determined by which columns are
10630 * in common. We'll collect columns during the later transformations.
10634 '(' joined_table ')'
10638 | table_ref CROSS JOIN table_ref
10640 /* CROSS JOIN is same as unqualified inner join */
10641 JoinExpr *n = makeNode(JoinExpr);
10642 n->jointype = JOIN_INNER;
10643 n->isNatural = FALSE;
10646 n->usingClause = NIL;
10650 | table_ref join_type JOIN table_ref join_qual
10652 JoinExpr *n = makeNode(JoinExpr);
10654 n->isNatural = FALSE;
10657 if ($5 != NULL && IsA($5, List))
10658 n->usingClause = (List *) $5; /* USING clause */
10660 n->quals = $5; /* ON clause */
10663 | table_ref JOIN table_ref join_qual
10665 /* letting join_type reduce to empty doesn't work */
10666 JoinExpr *n = makeNode(JoinExpr);
10667 n->jointype = JOIN_INNER;
10668 n->isNatural = FALSE;
10671 if ($4 != NULL && IsA($4, List))
10672 n->usingClause = (List *) $4; /* USING clause */
10674 n->quals = $4; /* ON clause */
10677 | table_ref NATURAL join_type JOIN table_ref
10679 JoinExpr *n = makeNode(JoinExpr);
10681 n->isNatural = TRUE;
10684 n->usingClause = NIL; /* figure out which columns later... */
10685 n->quals = NULL; /* fill later */
10688 | table_ref NATURAL JOIN table_ref
10690 /* letting join_type reduce to empty doesn't work */
10691 JoinExpr *n = makeNode(JoinExpr);
10692 n->jointype = JOIN_INNER;
10693 n->isNatural = TRUE;
10696 n->usingClause = NIL; /* figure out which columns later... */
10697 n->quals = NULL; /* fill later */
10703 AS ColId '(' name_list ')'
10705 $$ = makeNode(Alias);
10706 $$->aliasname = $2;
10711 $$ = makeNode(Alias);
10712 $$->aliasname = $2;
10714 | ColId '(' name_list ')'
10716 $$ = makeNode(Alias);
10717 $$->aliasname = $1;
10722 $$ = makeNode(Alias);
10723 $$->aliasname = $1;
10727 opt_alias_clause: alias_clause { $$ = $1; }
10728 | /*EMPTY*/ { $$ = NULL; }
10732 * func_alias_clause can include both an Alias and a coldeflist, so we make it
10733 * return a 2-element list that gets disassembled by calling production.
10738 $$ = list_make2($1, NIL);
10740 | AS '(' TableFuncElementList ')'
10742 $$ = list_make2(NULL, $3);
10744 | AS ColId '(' TableFuncElementList ')'
10746 Alias *a = makeNode(Alias);
10748 $$ = list_make2(a, $4);
10750 | ColId '(' TableFuncElementList ')'
10752 Alias *a = makeNode(Alias);
10754 $$ = list_make2(a, $3);
10758 $$ = list_make2(NULL, NIL);
10762 join_type: FULL join_outer { $$ = JOIN_FULL; }
10763 | LEFT join_outer { $$ = JOIN_LEFT; }
10764 | RIGHT join_outer { $$ = JOIN_RIGHT; }
10765 | INNER_P { $$ = JOIN_INNER; }
10768 /* OUTER is just noise... */
10769 join_outer: OUTER_P { $$ = NULL; }
10770 | /*EMPTY*/ { $$ = NULL; }
10773 /* JOIN qualification clauses
10774 * Possibilities are:
10775 * USING ( column list ) allows only unqualified column names,
10776 * which must match between tables.
10777 * ON expr allows more general qualifications.
10779 * We return USING as a List node, while an ON-expr will not be a List.
10782 join_qual: USING '(' name_list ')' { $$ = (Node *) $3; }
10783 | ON a_expr { $$ = $2; }
10790 /* default inheritance */
10792 $$->inhOpt = INH_DEFAULT;
10795 | qualified_name '*'
10797 /* inheritance query */
10799 $$->inhOpt = INH_YES;
10802 | ONLY qualified_name
10804 /* no inheritance */
10806 $$->inhOpt = INH_NO;
10809 | ONLY '(' qualified_name ')'
10811 /* no inheritance, SQL99-style syntax */
10813 $$->inhOpt = INH_NO;
10819 relation_expr_list:
10820 relation_expr { $$ = list_make1($1); }
10821 | relation_expr_list ',' relation_expr { $$ = lappend($1, $3); }
10826 * Given "UPDATE foo set set ...", we have to decide without looking any
10827 * further ahead whether the first "set" is an alias or the UPDATE's SET
10828 * keyword. Since "set" is allowed as a column name both interpretations
10829 * are feasible. We resolve the shift/reduce conflict by giving the first
10830 * relation_expr_opt_alias production a higher precedence than the SET token
10831 * has, causing the parser to prefer to reduce, in effect assuming that the
10832 * SET is not an alias.
10834 relation_expr_opt_alias: relation_expr %prec UMINUS
10838 | relation_expr ColId
10840 Alias *alias = makeNode(Alias);
10841 alias->aliasname = $2;
10845 | relation_expr AS ColId
10847 Alias *alias = makeNode(Alias);
10848 alias->aliasname = $3;
10855 * TABLESAMPLE decoration in a FROM item
10857 tablesample_clause:
10858 TABLESAMPLE func_name '(' expr_list ')' opt_repeatable_clause
10860 RangeTableSample *n = makeNode(RangeTableSample);
10861 /* n->relation will be filled in later */
10864 n->repeatable = $6;
10870 opt_repeatable_clause:
10871 REPEATABLE '(' a_expr ')' { $$ = (Node *) $3; }
10872 | /*EMPTY*/ { $$ = NULL; }
10876 * func_table represents a function invocation in a FROM list. It can be
10877 * a plain function call, like "foo(...)", or a ROWS FROM expression with
10878 * one or more function calls, "ROWS FROM (foo(...), bar(...))",
10879 * optionally with WITH ORDINALITY attached.
10880 * In the ROWS FROM syntax, a column definition list can be given for each
10881 * function, for example:
10882 * ROWS FROM (foo() AS (foo_res_a text, foo_res_b text),
10883 * bar() AS (bar_res_a text, bar_res_b text))
10884 * It's also possible to attach a column definition list to the RangeFunction
10885 * as a whole, but that's handled by the table_ref production.
10887 func_table: func_expr_windowless opt_ordinality
10889 RangeFunction *n = makeNode(RangeFunction);
10890 n->lateral = false;
10891 n->ordinality = $2;
10892 n->is_rowsfrom = false;
10893 n->functions = list_make1(list_make2($1, NIL));
10894 /* alias and coldeflist are set by table_ref production */
10897 | ROWS FROM '(' rowsfrom_list ')' opt_ordinality
10899 RangeFunction *n = makeNode(RangeFunction);
10900 n->lateral = false;
10901 n->ordinality = $6;
10902 n->is_rowsfrom = true;
10904 /* alias and coldeflist are set by table_ref production */
10909 rowsfrom_item: func_expr_windowless opt_col_def_list
10910 { $$ = list_make2($1, $2); }
10914 rowsfrom_item { $$ = list_make1($1); }
10915 | rowsfrom_list ',' rowsfrom_item { $$ = lappend($1, $3); }
10918 opt_col_def_list: AS '(' TableFuncElementList ')' { $$ = $3; }
10919 | /*EMPTY*/ { $$ = NIL; }
10922 opt_ordinality: WITH_LA ORDINALITY { $$ = true; }
10923 | /*EMPTY*/ { $$ = false; }
10928 WHERE a_expr { $$ = $2; }
10929 | /*EMPTY*/ { $$ = NULL; }
10932 /* variant for UPDATE and DELETE */
10933 where_or_current_clause:
10934 WHERE a_expr { $$ = $2; }
10935 | WHERE CURRENT_P OF cursor_name
10937 CurrentOfExpr *n = makeNode(CurrentOfExpr);
10938 /* cvarno is filled in by parse analysis */
10939 n->cursor_name = $4;
10940 n->cursor_param = 0;
10943 | /*EMPTY*/ { $$ = NULL; }
10947 OptTableFuncElementList:
10948 TableFuncElementList { $$ = $1; }
10949 | /*EMPTY*/ { $$ = NIL; }
10952 TableFuncElementList:
10955 $$ = list_make1($1);
10957 | TableFuncElementList ',' TableFuncElement
10959 $$ = lappend($1, $3);
10963 TableFuncElement: ColId Typename opt_collate_clause
10965 ColumnDef *n = makeNode(ColumnDef);
10969 n->is_local = true;
10970 n->is_not_null = false;
10971 n->is_from_type = false;
10973 n->raw_default = NULL;
10974 n->cooked_default = NULL;
10975 n->collClause = (CollateClause *) $3;
10976 n->collOid = InvalidOid;
10977 n->constraints = NIL;
10983 /*****************************************************************************
10986 * SQL introduces a large amount of type-specific syntax.
10987 * Define individual clauses to handle these cases, and use
10988 * the generic case to handle regular type-extensible Postgres syntax.
10989 * - thomas 1997-10-10
10991 *****************************************************************************/
10993 Typename: SimpleTypename opt_array_bounds
10996 $$->arrayBounds = $2;
10998 | SETOF SimpleTypename opt_array_bounds
11001 $$->arrayBounds = $3;
11004 /* SQL standard syntax, currently only one-dimensional */
11005 | SimpleTypename ARRAY '[' Iconst ']'
11008 $$->arrayBounds = list_make1(makeInteger($4));
11010 | SETOF SimpleTypename ARRAY '[' Iconst ']'
11013 $$->arrayBounds = list_make1(makeInteger($5));
11016 | SimpleTypename ARRAY
11019 $$->arrayBounds = list_make1(makeInteger(-1));
11021 | SETOF SimpleTypename ARRAY
11024 $$->arrayBounds = list_make1(makeInteger(-1));
11030 opt_array_bounds '[' ']'
11031 { $$ = lappend($1, makeInteger(-1)); }
11032 | opt_array_bounds '[' Iconst ']'
11033 { $$ = lappend($1, makeInteger($3)); }
11039 GenericType { $$ = $1; }
11040 | Numeric { $$ = $1; }
11042 | Character { $$ = $1; }
11043 | ConstDatetime { $$ = $1; }
11044 | ConstInterval opt_interval
11049 | ConstInterval '(' Iconst ')'
11052 $$->typmods = list_make2(makeIntConst(INTERVAL_FULL_RANGE, -1),
11053 makeIntConst($3, @3));
11057 /* We have a separate ConstTypename to allow defaulting fixed-length
11058 * types such as CHAR() and BIT() to an unspecified length.
11059 * SQL9x requires that these default to a length of one, but this
11060 * makes no sense for constructs like CHAR 'hi' and BIT '0101',
11061 * where there is an obvious better choice to make.
11062 * Note that ConstInterval is not included here since it must
11063 * be pushed up higher in the rules to accommodate the postfix
11064 * options (e.g. INTERVAL '1' YEAR). Likewise, we have to handle
11065 * the generic-type-name case in AExprConst to avoid premature
11066 * reduce/reduce conflicts against function names.
11069 Numeric { $$ = $1; }
11070 | ConstBit { $$ = $1; }
11071 | ConstCharacter { $$ = $1; }
11072 | ConstDatetime { $$ = $1; }
11076 * GenericType covers all type names that don't have special syntax mandated
11077 * by the standard, including qualified names. We also allow type modifiers.
11078 * To avoid parsing conflicts against function invocations, the modifiers
11079 * have to be shown as expr_list here, but parse analysis will only accept
11080 * constants for them.
11083 type_function_name opt_type_modifiers
11085 $$ = makeTypeName($1);
11089 | type_function_name attrs opt_type_modifiers
11091 $$ = makeTypeNameFromNameList(lcons(makeString($1), $2));
11097 opt_type_modifiers: '(' expr_list ')' { $$ = $2; }
11098 | /* EMPTY */ { $$ = NIL; }
11102 * SQL numeric data types
11106 $$ = SystemTypeName("int4");
11111 $$ = SystemTypeName("int4");
11116 $$ = SystemTypeName("int2");
11121 $$ = SystemTypeName("int8");
11126 $$ = SystemTypeName("float4");
11129 | FLOAT_P opt_float
11134 | DOUBLE_P PRECISION
11136 $$ = SystemTypeName("float8");
11139 | DECIMAL_P opt_type_modifiers
11141 $$ = SystemTypeName("numeric");
11145 | DEC opt_type_modifiers
11147 $$ = SystemTypeName("numeric");
11151 | NUMERIC opt_type_modifiers
11153 $$ = SystemTypeName("numeric");
11159 $$ = SystemTypeName("bool");
11164 opt_float: '(' Iconst ')'
11167 * Check FLOAT() precision limits assuming IEEE floating
11168 * types - thomas 1997-09-18
11172 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
11173 errmsg("precision for type float must be at least 1 bit"),
11174 parser_errposition(@2)));
11176 $$ = SystemTypeName("float4");
11178 $$ = SystemTypeName("float8");
11181 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
11182 errmsg("precision for type float must be less than 54 bits"),
11183 parser_errposition(@2)));
11187 $$ = SystemTypeName("float8");
11192 * SQL bit-field data types
11193 * The following implements BIT() and BIT VARYING().
11205 /* ConstBit is like Bit except "BIT" defaults to unspecified length */
11206 /* See notes for ConstCharacter, which addresses same issue for "CHAR" */
11207 ConstBit: BitWithLength
11219 BIT opt_varying '(' expr_list ')'
11223 typname = $2 ? "varbit" : "bit";
11224 $$ = SystemTypeName(typname);
11233 /* bit defaults to bit(1), varbit to no limit */
11236 $$ = SystemTypeName("varbit");
11240 $$ = SystemTypeName("bit");
11241 $$->typmods = list_make1(makeIntConst(1, -1));
11249 * SQL character data types
11250 * The following implements CHAR() and VARCHAR().
11252 Character: CharacterWithLength
11256 | CharacterWithoutLength
11262 ConstCharacter: CharacterWithLength
11266 | CharacterWithoutLength
11268 /* Length was not specified so allow to be unrestricted.
11269 * This handles problems with fixed-length (bpchar) strings
11270 * which in column definitions must default to a length
11271 * of one, but should not be constrained if the length
11272 * was not specified.
11279 CharacterWithLength: character '(' Iconst ')' opt_charset
11281 if (($5 != NULL) && (strcmp($5, "sql_text") != 0))
11282 $1 = psprintf("%s_%s", $1, $5);
11284 $$ = SystemTypeName($1);
11285 $$->typmods = list_make1(makeIntConst($3, @3));
11290 CharacterWithoutLength: character opt_charset
11292 if (($2 != NULL) && (strcmp($2, "sql_text") != 0))
11293 $1 = psprintf("%s_%s", $1, $2);
11295 $$ = SystemTypeName($1);
11297 /* char defaults to char(1), varchar to no limit */
11298 if (strcmp($1, "bpchar") == 0)
11299 $$->typmods = list_make1(makeIntConst(1, -1));
11305 character: CHARACTER opt_varying
11306 { $$ = $2 ? "varchar": "bpchar"; }
11307 | CHAR_P opt_varying
11308 { $$ = $2 ? "varchar": "bpchar"; }
11310 { $$ = "varchar"; }
11311 | NATIONAL CHARACTER opt_varying
11312 { $$ = $3 ? "varchar": "bpchar"; }
11313 | NATIONAL CHAR_P opt_varying
11314 { $$ = $3 ? "varchar": "bpchar"; }
11315 | NCHAR opt_varying
11316 { $$ = $2 ? "varchar": "bpchar"; }
11320 VARYING { $$ = TRUE; }
11321 | /*EMPTY*/ { $$ = FALSE; }
11325 CHARACTER SET ColId { $$ = $3; }
11326 | /*EMPTY*/ { $$ = NULL; }
11330 * SQL date/time types
11333 TIMESTAMP '(' Iconst ')' opt_timezone
11336 $$ = SystemTypeName("timestamptz");
11338 $$ = SystemTypeName("timestamp");
11339 $$->typmods = list_make1(makeIntConst($3, @3));
11342 | TIMESTAMP opt_timezone
11345 $$ = SystemTypeName("timestamptz");
11347 $$ = SystemTypeName("timestamp");
11350 | TIME '(' Iconst ')' opt_timezone
11353 $$ = SystemTypeName("timetz");
11355 $$ = SystemTypeName("time");
11356 $$->typmods = list_make1(makeIntConst($3, @3));
11359 | TIME opt_timezone
11362 $$ = SystemTypeName("timetz");
11364 $$ = SystemTypeName("time");
11372 $$ = SystemTypeName("interval");
11378 WITH_LA TIME ZONE { $$ = TRUE; }
11379 | WITHOUT TIME ZONE { $$ = FALSE; }
11380 | /*EMPTY*/ { $$ = FALSE; }
11385 { $$ = list_make1(makeIntConst(INTERVAL_MASK(YEAR), @1)); }
11387 { $$ = list_make1(makeIntConst(INTERVAL_MASK(MONTH), @1)); }
11389 { $$ = list_make1(makeIntConst(INTERVAL_MASK(DAY), @1)); }
11391 { $$ = list_make1(makeIntConst(INTERVAL_MASK(HOUR), @1)); }
11393 { $$ = list_make1(makeIntConst(INTERVAL_MASK(MINUTE), @1)); }
11396 | YEAR_P TO MONTH_P
11398 $$ = list_make1(makeIntConst(INTERVAL_MASK(YEAR) |
11399 INTERVAL_MASK(MONTH), @1));
11403 $$ = list_make1(makeIntConst(INTERVAL_MASK(DAY) |
11404 INTERVAL_MASK(HOUR), @1));
11406 | DAY_P TO MINUTE_P
11408 $$ = list_make1(makeIntConst(INTERVAL_MASK(DAY) |
11409 INTERVAL_MASK(HOUR) |
11410 INTERVAL_MASK(MINUTE), @1));
11412 | DAY_P TO interval_second
11415 linitial($$) = makeIntConst(INTERVAL_MASK(DAY) |
11416 INTERVAL_MASK(HOUR) |
11417 INTERVAL_MASK(MINUTE) |
11418 INTERVAL_MASK(SECOND), @1);
11420 | HOUR_P TO MINUTE_P
11422 $$ = list_make1(makeIntConst(INTERVAL_MASK(HOUR) |
11423 INTERVAL_MASK(MINUTE), @1));
11425 | HOUR_P TO interval_second
11428 linitial($$) = makeIntConst(INTERVAL_MASK(HOUR) |
11429 INTERVAL_MASK(MINUTE) |
11430 INTERVAL_MASK(SECOND), @1);
11432 | MINUTE_P TO interval_second
11435 linitial($$) = makeIntConst(INTERVAL_MASK(MINUTE) |
11436 INTERVAL_MASK(SECOND), @1);
11445 $$ = list_make1(makeIntConst(INTERVAL_MASK(SECOND), @1));
11447 | SECOND_P '(' Iconst ')'
11449 $$ = list_make2(makeIntConst(INTERVAL_MASK(SECOND), @1),
11450 makeIntConst($3, @3));
11455 /*****************************************************************************
11457 * expression grammar
11459 *****************************************************************************/
11462 * General expressions
11463 * This is the heart of the expression syntax.
11465 * We have two expression types: a_expr is the unrestricted kind, and
11466 * b_expr is a subset that must be used in some places to avoid shift/reduce
11467 * conflicts. For example, we can't do BETWEEN as "BETWEEN a_expr AND a_expr"
11468 * because that use of AND conflicts with AND as a boolean operator. So,
11469 * b_expr is used in BETWEEN and we remove boolean keywords from b_expr.
11471 * Note that '(' a_expr ')' is a b_expr, so an unrestricted expression can
11472 * always be used by surrounding it with parens.
11474 * c_expr is all the productions that are common to a_expr and b_expr;
11475 * it's factored out just to eliminate redundant coding.
11477 * Be careful of productions involving more than one terminal token.
11478 * By default, bison will assign such productions the precedence of their
11479 * last terminal, but in nearly all cases you want it to be the precedence
11480 * of the first terminal instead; otherwise you will not get the behavior
11481 * you expect! So we use %prec annotations freely to set precedences.
11483 a_expr: c_expr { $$ = $1; }
11484 | a_expr TYPECAST Typename
11485 { $$ = makeTypeCast($1, $3, @2); }
11486 | a_expr COLLATE any_name
11488 CollateClause *n = makeNode(CollateClause);
11494 | a_expr AT TIME ZONE a_expr %prec AT
11496 $$ = (Node *) makeFuncCall(SystemFuncName("timezone"),
11497 list_make2($5, $1),
11501 * These operators must be called out explicitly in order to make use
11502 * of bison's automatic operator-precedence handling. All other
11503 * operator names are handled by the generic productions using "Op",
11504 * below; and all those operators will have the same precedence.
11506 * If you add more explicitly-known operators, be sure to add them
11507 * also to b_expr and to the MathOp list below.
11509 | '+' a_expr %prec UMINUS
11510 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "+", NULL, $2, @1); }
11511 | '-' a_expr %prec UMINUS
11512 { $$ = doNegate($2, @1); }
11513 | a_expr '+' a_expr
11514 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "+", $1, $3, @2); }
11515 | a_expr '-' a_expr
11516 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "-", $1, $3, @2); }
11517 | a_expr '*' a_expr
11518 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "*", $1, $3, @2); }
11519 | a_expr '/' a_expr
11520 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "/", $1, $3, @2); }
11521 | a_expr '%' a_expr
11522 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "%", $1, $3, @2); }
11523 | a_expr '^' a_expr
11524 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "^", $1, $3, @2); }
11525 | a_expr '<' a_expr
11526 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "<", $1, $3, @2); }
11527 | a_expr '>' a_expr
11528 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, ">", $1, $3, @2); }
11529 | a_expr '=' a_expr
11530 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "=", $1, $3, @2); }
11531 | a_expr LESS_EQUALS a_expr
11532 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "<=", $1, $3, @2); }
11533 | a_expr GREATER_EQUALS a_expr
11534 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, ">=", $1, $3, @2); }
11535 | a_expr NOT_EQUALS a_expr
11536 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "<>", $1, $3, @2); }
11538 | a_expr qual_Op a_expr %prec Op
11539 { $$ = (Node *) makeA_Expr(AEXPR_OP, $2, $1, $3, @2); }
11540 | qual_Op a_expr %prec Op
11541 { $$ = (Node *) makeA_Expr(AEXPR_OP, $1, NULL, $2, @1); }
11542 | a_expr qual_Op %prec POSTFIXOP
11543 { $$ = (Node *) makeA_Expr(AEXPR_OP, $2, $1, NULL, @2); }
11545 | a_expr AND a_expr
11546 { $$ = makeAndExpr($1, $3, @2); }
11548 { $$ = makeOrExpr($1, $3, @2); }
11550 { $$ = makeNotExpr($2, @1); }
11551 | NOT_LA a_expr %prec NOT
11552 { $$ = makeNotExpr($2, @1); }
11554 | a_expr LIKE a_expr
11556 $$ = (Node *) makeSimpleA_Expr(AEXPR_LIKE, "~~",
11559 | a_expr LIKE a_expr ESCAPE a_expr %prec LIKE
11561 FuncCall *n = makeFuncCall(SystemFuncName("like_escape"),
11562 list_make2($3, $5),
11564 $$ = (Node *) makeSimpleA_Expr(AEXPR_LIKE, "~~",
11565 $1, (Node *) n, @2);
11567 | a_expr NOT_LA LIKE a_expr %prec NOT_LA
11569 $$ = (Node *) makeSimpleA_Expr(AEXPR_LIKE, "!~~",
11572 | a_expr NOT_LA LIKE a_expr ESCAPE a_expr %prec NOT_LA
11574 FuncCall *n = makeFuncCall(SystemFuncName("like_escape"),
11575 list_make2($4, $6),
11577 $$ = (Node *) makeSimpleA_Expr(AEXPR_LIKE, "!~~",
11578 $1, (Node *) n, @2);
11580 | a_expr ILIKE a_expr
11582 $$ = (Node *) makeSimpleA_Expr(AEXPR_ILIKE, "~~*",
11585 | a_expr ILIKE a_expr ESCAPE a_expr %prec ILIKE
11587 FuncCall *n = makeFuncCall(SystemFuncName("like_escape"),
11588 list_make2($3, $5),
11590 $$ = (Node *) makeSimpleA_Expr(AEXPR_ILIKE, "~~*",
11591 $1, (Node *) n, @2);
11593 | a_expr NOT_LA ILIKE a_expr %prec NOT_LA
11595 $$ = (Node *) makeSimpleA_Expr(AEXPR_ILIKE, "!~~*",
11598 | a_expr NOT_LA ILIKE a_expr ESCAPE a_expr %prec NOT_LA
11600 FuncCall *n = makeFuncCall(SystemFuncName("like_escape"),
11601 list_make2($4, $6),
11603 $$ = (Node *) makeSimpleA_Expr(AEXPR_ILIKE, "!~~*",
11604 $1, (Node *) n, @2);
11607 | a_expr SIMILAR TO a_expr %prec SIMILAR
11609 FuncCall *n = makeFuncCall(SystemFuncName("similar_escape"),
11610 list_make2($4, makeNullAConst(-1)),
11612 $$ = (Node *) makeSimpleA_Expr(AEXPR_SIMILAR, "~",
11613 $1, (Node *) n, @2);
11615 | a_expr SIMILAR TO a_expr ESCAPE a_expr %prec SIMILAR
11617 FuncCall *n = makeFuncCall(SystemFuncName("similar_escape"),
11618 list_make2($4, $6),
11620 $$ = (Node *) makeSimpleA_Expr(AEXPR_SIMILAR, "~",
11621 $1, (Node *) n, @2);
11623 | a_expr NOT_LA SIMILAR TO a_expr %prec NOT_LA
11625 FuncCall *n = makeFuncCall(SystemFuncName("similar_escape"),
11626 list_make2($5, makeNullAConst(-1)),
11628 $$ = (Node *) makeSimpleA_Expr(AEXPR_SIMILAR, "!~",
11629 $1, (Node *) n, @2);
11631 | a_expr NOT_LA SIMILAR TO a_expr ESCAPE a_expr %prec NOT_LA
11633 FuncCall *n = makeFuncCall(SystemFuncName("similar_escape"),
11634 list_make2($5, $7),
11636 $$ = (Node *) makeSimpleA_Expr(AEXPR_SIMILAR, "!~",
11637 $1, (Node *) n, @2);
11641 * Define SQL-style Null test clause.
11642 * Allow two forms described in the standard:
11645 * Allow two SQL extensions
11649 | a_expr IS NULL_P %prec IS
11651 NullTest *n = makeNode(NullTest);
11652 n->arg = (Expr *) $1;
11653 n->nulltesttype = IS_NULL;
11659 NullTest *n = makeNode(NullTest);
11660 n->arg = (Expr *) $1;
11661 n->nulltesttype = IS_NULL;
11665 | a_expr IS NOT NULL_P %prec IS
11667 NullTest *n = makeNode(NullTest);
11668 n->arg = (Expr *) $1;
11669 n->nulltesttype = IS_NOT_NULL;
11675 NullTest *n = makeNode(NullTest);
11676 n->arg = (Expr *) $1;
11677 n->nulltesttype = IS_NOT_NULL;
11683 if (list_length($1) != 2)
11685 (errcode(ERRCODE_SYNTAX_ERROR),
11686 errmsg("wrong number of parameters on left side of OVERLAPS expression"),
11687 parser_errposition(@1)));
11688 if (list_length($3) != 2)
11690 (errcode(ERRCODE_SYNTAX_ERROR),
11691 errmsg("wrong number of parameters on right side of OVERLAPS expression"),
11692 parser_errposition(@3)));
11693 $$ = (Node *) makeFuncCall(SystemFuncName("overlaps"),
11694 list_concat($1, $3),
11697 | a_expr IS TRUE_P %prec IS
11699 BooleanTest *b = makeNode(BooleanTest);
11700 b->arg = (Expr *) $1;
11701 b->booltesttype = IS_TRUE;
11705 | a_expr IS NOT TRUE_P %prec IS
11707 BooleanTest *b = makeNode(BooleanTest);
11708 b->arg = (Expr *) $1;
11709 b->booltesttype = IS_NOT_TRUE;
11713 | a_expr IS FALSE_P %prec IS
11715 BooleanTest *b = makeNode(BooleanTest);
11716 b->arg = (Expr *) $1;
11717 b->booltesttype = IS_FALSE;
11721 | a_expr IS NOT FALSE_P %prec IS
11723 BooleanTest *b = makeNode(BooleanTest);
11724 b->arg = (Expr *) $1;
11725 b->booltesttype = IS_NOT_FALSE;
11729 | a_expr IS UNKNOWN %prec IS
11731 BooleanTest *b = makeNode(BooleanTest);
11732 b->arg = (Expr *) $1;
11733 b->booltesttype = IS_UNKNOWN;
11737 | a_expr IS NOT UNKNOWN %prec IS
11739 BooleanTest *b = makeNode(BooleanTest);
11740 b->arg = (Expr *) $1;
11741 b->booltesttype = IS_NOT_UNKNOWN;
11745 | a_expr IS DISTINCT FROM a_expr %prec IS
11747 $$ = (Node *) makeSimpleA_Expr(AEXPR_DISTINCT, "=", $1, $5, @2);
11749 | a_expr IS NOT DISTINCT FROM a_expr %prec IS
11751 $$ = makeNotExpr((Node *) makeSimpleA_Expr(AEXPR_DISTINCT,
11755 | a_expr IS OF '(' type_list ')' %prec IS
11757 $$ = (Node *) makeSimpleA_Expr(AEXPR_OF, "=", $1, (Node *) $5, @2);
11759 | a_expr IS NOT OF '(' type_list ')' %prec IS
11761 $$ = (Node *) makeSimpleA_Expr(AEXPR_OF, "<>", $1, (Node *) $6, @2);
11763 | a_expr BETWEEN opt_asymmetric b_expr AND a_expr %prec BETWEEN
11765 $$ = (Node *) makeSimpleA_Expr(AEXPR_BETWEEN,
11768 (Node *) list_make2($4, $6),
11771 | a_expr NOT_LA BETWEEN opt_asymmetric b_expr AND a_expr %prec NOT_LA
11773 $$ = (Node *) makeSimpleA_Expr(AEXPR_NOT_BETWEEN,
11776 (Node *) list_make2($5, $7),
11779 | a_expr BETWEEN SYMMETRIC b_expr AND a_expr %prec BETWEEN
11781 $$ = (Node *) makeSimpleA_Expr(AEXPR_BETWEEN_SYM,
11782 "BETWEEN SYMMETRIC",
11784 (Node *) list_make2($4, $6),
11787 | a_expr NOT_LA BETWEEN SYMMETRIC b_expr AND a_expr %prec NOT_LA
11789 $$ = (Node *) makeSimpleA_Expr(AEXPR_NOT_BETWEEN_SYM,
11790 "NOT BETWEEN SYMMETRIC",
11792 (Node *) list_make2($5, $7),
11795 | a_expr IN_P in_expr
11797 /* in_expr returns a SubLink or a list of a_exprs */
11798 if (IsA($3, SubLink))
11800 /* generate foo = ANY (subquery) */
11801 SubLink *n = (SubLink *) $3;
11802 n->subLinkType = ANY_SUBLINK;
11805 n->operName = NIL; /* show it's IN not = ANY */
11811 /* generate scalar IN expression */
11812 $$ = (Node *) makeSimpleA_Expr(AEXPR_IN, "=", $1, $3, @2);
11815 | a_expr NOT_LA IN_P in_expr %prec NOT_LA
11817 /* in_expr returns a SubLink or a list of a_exprs */
11818 if (IsA($4, SubLink))
11820 /* generate NOT (foo = ANY (subquery)) */
11821 /* Make an = ANY node */
11822 SubLink *n = (SubLink *) $4;
11823 n->subLinkType = ANY_SUBLINK;
11826 n->operName = NIL; /* show it's IN not = ANY */
11828 /* Stick a NOT on top; must have same parse location */
11829 $$ = makeNotExpr((Node *) n, @2);
11833 /* generate scalar NOT IN expression */
11834 $$ = (Node *) makeSimpleA_Expr(AEXPR_IN, "<>", $1, $4, @2);
11837 | a_expr subquery_Op sub_type select_with_parens %prec Op
11839 SubLink *n = makeNode(SubLink);
11840 n->subLinkType = $3;
11848 | a_expr subquery_Op sub_type '(' a_expr ')' %prec Op
11850 if ($3 == ANY_SUBLINK)
11851 $$ = (Node *) makeA_Expr(AEXPR_OP_ANY, $2, $1, $5, @2);
11853 $$ = (Node *) makeA_Expr(AEXPR_OP_ALL, $2, $1, $5, @2);
11855 | UNIQUE select_with_parens
11857 /* Not sure how to get rid of the parentheses
11858 * but there are lots of shift/reduce errors without them.
11860 * Should be able to implement this by plopping the entire
11861 * select into a node, then transforming the target expressions
11862 * from whatever they are into count(*), and testing the
11863 * entire result equal to one.
11864 * But, will probably implement a separate node in the executor.
11867 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
11868 errmsg("UNIQUE predicate is not yet implemented"),
11869 parser_errposition(@1)));
11871 | a_expr IS DOCUMENT_P %prec IS
11873 $$ = makeXmlExpr(IS_DOCUMENT, NULL, NIL,
11874 list_make1($1), @2);
11876 | a_expr IS NOT DOCUMENT_P %prec IS
11878 $$ = makeNotExpr(makeXmlExpr(IS_DOCUMENT, NULL, NIL,
11879 list_make1($1), @2),
11885 * Restricted expressions
11887 * b_expr is a subset of the complete expression syntax defined by a_expr.
11889 * Presently, AND, NOT, IS, and IN are the a_expr keywords that would
11890 * cause trouble in the places where b_expr is used. For simplicity, we
11891 * just eliminate all the boolean-keyword-operator productions from b_expr.
11895 | b_expr TYPECAST Typename
11896 { $$ = makeTypeCast($1, $3, @2); }
11897 | '+' b_expr %prec UMINUS
11898 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "+", NULL, $2, @1); }
11899 | '-' b_expr %prec UMINUS
11900 { $$ = doNegate($2, @1); }
11901 | b_expr '+' b_expr
11902 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "+", $1, $3, @2); }
11903 | b_expr '-' b_expr
11904 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "-", $1, $3, @2); }
11905 | b_expr '*' b_expr
11906 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "*", $1, $3, @2); }
11907 | b_expr '/' b_expr
11908 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "/", $1, $3, @2); }
11909 | b_expr '%' b_expr
11910 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "%", $1, $3, @2); }
11911 | b_expr '^' b_expr
11912 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "^", $1, $3, @2); }
11913 | b_expr '<' b_expr
11914 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "<", $1, $3, @2); }
11915 | b_expr '>' b_expr
11916 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, ">", $1, $3, @2); }
11917 | b_expr '=' b_expr
11918 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "=", $1, $3, @2); }
11919 | b_expr LESS_EQUALS b_expr
11920 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "<=", $1, $3, @2); }
11921 | b_expr GREATER_EQUALS b_expr
11922 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, ">=", $1, $3, @2); }
11923 | b_expr NOT_EQUALS b_expr
11924 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "<>", $1, $3, @2); }
11925 | b_expr qual_Op b_expr %prec Op
11926 { $$ = (Node *) makeA_Expr(AEXPR_OP, $2, $1, $3, @2); }
11927 | qual_Op b_expr %prec Op
11928 { $$ = (Node *) makeA_Expr(AEXPR_OP, $1, NULL, $2, @1); }
11929 | b_expr qual_Op %prec POSTFIXOP
11930 { $$ = (Node *) makeA_Expr(AEXPR_OP, $2, $1, NULL, @2); }
11931 | b_expr IS DISTINCT FROM b_expr %prec IS
11933 $$ = (Node *) makeSimpleA_Expr(AEXPR_DISTINCT, "=", $1, $5, @2);
11935 | b_expr IS NOT DISTINCT FROM b_expr %prec IS
11937 $$ = makeNotExpr((Node *) makeSimpleA_Expr(AEXPR_DISTINCT,
11941 | b_expr IS OF '(' type_list ')' %prec IS
11943 $$ = (Node *) makeSimpleA_Expr(AEXPR_OF, "=", $1, (Node *) $5, @2);
11945 | b_expr IS NOT OF '(' type_list ')' %prec IS
11947 $$ = (Node *) makeSimpleA_Expr(AEXPR_OF, "<>", $1, (Node *) $6, @2);
11949 | b_expr IS DOCUMENT_P %prec IS
11951 $$ = makeXmlExpr(IS_DOCUMENT, NULL, NIL,
11952 list_make1($1), @2);
11954 | b_expr IS NOT DOCUMENT_P %prec IS
11956 $$ = makeNotExpr(makeXmlExpr(IS_DOCUMENT, NULL, NIL,
11957 list_make1($1), @2),
11963 * Productions that can be used in both a_expr and b_expr.
11965 * Note: productions that refer recursively to a_expr or b_expr mostly
11966 * cannot appear here. However, it's OK to refer to a_exprs that occur
11967 * inside parentheses, such as function arguments; that cannot introduce
11968 * ambiguity to the b_expr syntax.
11970 c_expr: columnref { $$ = $1; }
11971 | AexprConst { $$ = $1; }
11972 | PARAM opt_indirection
11974 ParamRef *p = makeNode(ParamRef);
11979 A_Indirection *n = makeNode(A_Indirection);
11980 n->arg = (Node *) p;
11981 n->indirection = check_indirection($2, yyscanner);
11987 | '(' a_expr ')' opt_indirection
11991 A_Indirection *n = makeNode(A_Indirection);
11993 n->indirection = check_indirection($4, yyscanner);
11996 else if (operator_precedence_warning)
11999 * If precedence warnings are enabled, insert
12000 * AEXPR_PAREN nodes wrapping all explicitly
12001 * parenthesized subexpressions; this prevents bogus
12002 * warnings from being issued when the ordering has
12003 * been forced by parentheses.
12005 * In principle we should not be relying on a GUC to
12006 * decide whether to insert AEXPR_PAREN nodes.
12007 * However, since they have no effect except to
12008 * suppress warnings, it's probably safe enough; and
12009 * we'd just as soon not waste cycles on dummy parse
12010 * nodes if we don't have to.
12012 $$ = (Node *) makeA_Expr(AEXPR_PAREN, NIL, $2, NULL, @1);
12021 | select_with_parens %prec UMINUS
12023 SubLink *n = makeNode(SubLink);
12024 n->subLinkType = EXPR_SUBLINK;
12026 n->testexpr = NULL;
12032 | select_with_parens indirection
12035 * Because the select_with_parens nonterminal is designed
12036 * to "eat" as many levels of parens as possible, the
12037 * '(' a_expr ')' opt_indirection production above will
12038 * fail to match a sub-SELECT with indirection decoration;
12039 * the sub-SELECT won't be regarded as an a_expr as long
12040 * as there are parens around it. To support applying
12041 * subscripting or field selection to a sub-SELECT result,
12042 * we need this redundant-looking production.
12044 SubLink *n = makeNode(SubLink);
12045 A_Indirection *a = makeNode(A_Indirection);
12046 n->subLinkType = EXPR_SUBLINK;
12048 n->testexpr = NULL;
12052 a->arg = (Node *)n;
12053 a->indirection = check_indirection($2, yyscanner);
12056 | EXISTS select_with_parens
12058 SubLink *n = makeNode(SubLink);
12059 n->subLinkType = EXISTS_SUBLINK;
12061 n->testexpr = NULL;
12067 | ARRAY select_with_parens
12069 SubLink *n = makeNode(SubLink);
12070 n->subLinkType = ARRAY_SUBLINK;
12072 n->testexpr = NULL;
12080 A_ArrayExpr *n = (A_ArrayExpr *) $2;
12081 Assert(IsA(n, A_ArrayExpr));
12082 /* point outermost A_ArrayExpr to the ARRAY keyword */
12088 RowExpr *r = makeNode(RowExpr);
12090 r->row_typeid = InvalidOid; /* not analyzed yet */
12091 r->colnames = NIL; /* to be filled in during analysis */
12092 r->row_format = COERCE_EXPLICIT_CALL; /* abuse */
12098 RowExpr *r = makeNode(RowExpr);
12100 r->row_typeid = InvalidOid; /* not analyzed yet */
12101 r->colnames = NIL; /* to be filled in during analysis */
12102 r->row_format = COERCE_IMPLICIT_CAST; /* abuse */
12106 | GROUPING '(' expr_list ')'
12108 GroupingFunc *g = makeNode(GroupingFunc);
12115 func_application: func_name '(' ')'
12117 $$ = (Node *) makeFuncCall($1, NIL, @1);
12119 | func_name '(' func_arg_list opt_sort_clause ')'
12121 FuncCall *n = makeFuncCall($1, $3, @1);
12125 | func_name '(' VARIADIC func_arg_expr opt_sort_clause ')'
12127 FuncCall *n = makeFuncCall($1, list_make1($4), @1);
12128 n->func_variadic = TRUE;
12132 | func_name '(' func_arg_list ',' VARIADIC func_arg_expr opt_sort_clause ')'
12134 FuncCall *n = makeFuncCall($1, lappend($3, $6), @1);
12135 n->func_variadic = TRUE;
12139 | func_name '(' ALL func_arg_list opt_sort_clause ')'
12141 FuncCall *n = makeFuncCall($1, $4, @1);
12143 /* Ideally we'd mark the FuncCall node to indicate
12144 * "must be an aggregate", but there's no provision
12145 * for that in FuncCall at the moment.
12149 | func_name '(' DISTINCT func_arg_list opt_sort_clause ')'
12151 FuncCall *n = makeFuncCall($1, $4, @1);
12153 n->agg_distinct = TRUE;
12156 | func_name '(' '*' ')'
12159 * We consider AGGREGATE(*) to invoke a parameterless
12160 * aggregate. This does the right thing for COUNT(*),
12161 * and there are no other aggregates in SQL that accept
12162 * '*' as parameter.
12164 * The FuncCall node is also marked agg_star = true,
12165 * so that later processing can detect what the argument
12168 FuncCall *n = makeFuncCall($1, NIL, @1);
12169 n->agg_star = TRUE;
12176 * func_expr and its cousin func_expr_windowless are split out from c_expr just
12177 * so that we have classifications for "everything that is a function call or
12178 * looks like one". This isn't very important, but it saves us having to
12179 * document which variants are legal in places like "FROM function()" or the
12180 * backwards-compatible functional-index syntax for CREATE INDEX.
12181 * (Note that many of the special SQL functions wouldn't actually make any
12182 * sense as functional index entries, but we ignore that consideration here.)
12184 func_expr: func_application within_group_clause filter_clause over_clause
12186 FuncCall *n = (FuncCall *) $1;
12188 * The order clause for WITHIN GROUP and the one for
12189 * plain-aggregate ORDER BY share a field, so we have to
12190 * check here that at most one is present. We also check
12191 * for DISTINCT and VARIADIC here to give a better error
12192 * location. Other consistency checks are deferred to
12197 if (n->agg_order != NIL)
12199 (errcode(ERRCODE_SYNTAX_ERROR),
12200 errmsg("cannot use multiple ORDER BY clauses with WITHIN GROUP"),
12201 parser_errposition(@2)));
12202 if (n->agg_distinct)
12204 (errcode(ERRCODE_SYNTAX_ERROR),
12205 errmsg("cannot use DISTINCT with WITHIN GROUP"),
12206 parser_errposition(@2)));
12207 if (n->func_variadic)
12209 (errcode(ERRCODE_SYNTAX_ERROR),
12210 errmsg("cannot use VARIADIC with WITHIN GROUP"),
12211 parser_errposition(@2)));
12213 n->agg_within_group = TRUE;
12215 n->agg_filter = $3;
12219 | func_expr_common_subexpr
12224 * As func_expr but does not accept WINDOW functions directly
12225 * (but they can still be contained in arguments for functions etc).
12226 * Use this when window expressions are not allowed, where needed to
12227 * disambiguate the grammar (e.g. in CREATE INDEX).
12229 func_expr_windowless:
12230 func_application { $$ = $1; }
12231 | func_expr_common_subexpr { $$ = $1; }
12235 * Special expressions that are considered to be functions.
12237 func_expr_common_subexpr:
12238 COLLATION FOR '(' a_expr ')'
12240 $$ = (Node *) makeFuncCall(SystemFuncName("pg_collation_for"),
12247 * Translate as "'now'::text::date".
12249 * We cannot use "'now'::date" because coerce_type() will
12250 * immediately reduce that to a constant representing
12251 * today's date. We need to delay the conversion until
12252 * runtime, else the wrong things will happen when
12253 * CURRENT_DATE is used in a column default value or rule.
12255 * This could be simplified if we had a way to generate
12256 * an expression tree representing runtime application
12257 * of type-input conversion functions. (As of PG 7.3
12258 * that is actually possible, but not clear that we want
12261 * The token location is attached to the run-time
12262 * typecast, not to the Const, for the convenience of
12263 * pg_stat_statements (which doesn't want these constructs
12264 * to appear to be replaceable constants).
12267 n = makeStringConstCast("now", -1, SystemTypeName("text"));
12268 $$ = makeTypeCast(n, SystemTypeName("date"), @1);
12273 * Translate as "'now'::text::timetz".
12274 * See comments for CURRENT_DATE.
12277 n = makeStringConstCast("now", -1, SystemTypeName("text"));
12278 $$ = makeTypeCast(n, SystemTypeName("timetz"), @1);
12280 | CURRENT_TIME '(' Iconst ')'
12283 * Translate as "'now'::text::timetz(n)".
12284 * See comments for CURRENT_DATE.
12288 n = makeStringConstCast("now", -1, SystemTypeName("text"));
12289 d = SystemTypeName("timetz");
12290 d->typmods = list_make1(makeIntConst($3, @3));
12291 $$ = makeTypeCast(n, d, @1);
12293 | CURRENT_TIMESTAMP
12296 * Translate as "now()", since we have a function that
12297 * does exactly what is needed.
12299 $$ = (Node *) makeFuncCall(SystemFuncName("now"), NIL, @1);
12301 | CURRENT_TIMESTAMP '(' Iconst ')'
12304 * Translate as "'now'::text::timestamptz(n)".
12305 * See comments for CURRENT_DATE.
12309 n = makeStringConstCast("now", -1, SystemTypeName("text"));
12310 d = SystemTypeName("timestamptz");
12311 d->typmods = list_make1(makeIntConst($3, @3));
12312 $$ = makeTypeCast(n, d, @1);
12317 * Translate as "'now'::text::time".
12318 * See comments for CURRENT_DATE.
12321 n = makeStringConstCast("now", -1, SystemTypeName("text"));
12322 $$ = makeTypeCast((Node *)n, SystemTypeName("time"), @1);
12324 | LOCALTIME '(' Iconst ')'
12327 * Translate as "'now'::text::time(n)".
12328 * See comments for CURRENT_DATE.
12332 n = makeStringConstCast("now", -1, SystemTypeName("text"));
12333 d = SystemTypeName("time");
12334 d->typmods = list_make1(makeIntConst($3, @3));
12335 $$ = makeTypeCast((Node *)n, d, @1);
12340 * Translate as "'now'::text::timestamp".
12341 * See comments for CURRENT_DATE.
12344 n = makeStringConstCast("now", -1, SystemTypeName("text"));
12345 $$ = makeTypeCast(n, SystemTypeName("timestamp"), @1);
12347 | LOCALTIMESTAMP '(' Iconst ')'
12350 * Translate as "'now'::text::timestamp(n)".
12351 * See comments for CURRENT_DATE.
12355 n = makeStringConstCast("now", -1, SystemTypeName("text"));
12356 d = SystemTypeName("timestamp");
12357 d->typmods = list_make1(makeIntConst($3, @3));
12358 $$ = makeTypeCast(n, d, @1);
12362 $$ = (Node *) makeFuncCall(SystemFuncName("current_user"), NIL, @1);
12366 $$ = (Node *) makeFuncCall(SystemFuncName("current_user"), NIL, @1);
12370 $$ = (Node *) makeFuncCall(SystemFuncName("session_user"), NIL, @1);
12374 $$ = (Node *) makeFuncCall(SystemFuncName("current_user"), NIL, @1);
12378 $$ = (Node *) makeFuncCall(SystemFuncName("current_database"), NIL, @1);
12382 $$ = (Node *) makeFuncCall(SystemFuncName("current_schema"), NIL, @1);
12384 | CAST '(' a_expr AS Typename ')'
12385 { $$ = makeTypeCast($3, $5, @1); }
12386 | EXTRACT '(' extract_list ')'
12388 $$ = (Node *) makeFuncCall(SystemFuncName("date_part"), $3, @1);
12390 | OVERLAY '(' overlay_list ')'
12392 /* overlay(A PLACING B FROM C FOR D) is converted to
12393 * overlay(A, B, C, D)
12394 * overlay(A PLACING B FROM C) is converted to
12397 $$ = (Node *) makeFuncCall(SystemFuncName("overlay"), $3, @1);
12399 | POSITION '(' position_list ')'
12401 /* position(A in B) is converted to position(B, A) */
12402 $$ = (Node *) makeFuncCall(SystemFuncName("position"), $3, @1);
12404 | SUBSTRING '(' substr_list ')'
12406 /* substring(A from B for C) is converted to
12407 * substring(A, B, C) - thomas 2000-11-28
12409 $$ = (Node *) makeFuncCall(SystemFuncName("substring"), $3, @1);
12411 | TREAT '(' a_expr AS Typename ')'
12413 /* TREAT(expr AS target) converts expr of a particular type to target,
12414 * which is defined to be a subtype of the original expression.
12415 * In SQL99, this is intended for use with structured UDTs,
12416 * but let's make this a generally useful form allowing stronger
12417 * coercions than are handled by implicit casting.
12419 * Convert SystemTypeName() to SystemFuncName() even though
12420 * at the moment they result in the same thing.
12422 $$ = (Node *) makeFuncCall(SystemFuncName(((Value *)llast($5->names))->val.str),
12426 | TRIM '(' BOTH trim_list ')'
12428 /* various trim expressions are defined in SQL
12429 * - thomas 1997-07-19
12431 $$ = (Node *) makeFuncCall(SystemFuncName("btrim"), $4, @1);
12433 | TRIM '(' LEADING trim_list ')'
12435 $$ = (Node *) makeFuncCall(SystemFuncName("ltrim"), $4, @1);
12437 | TRIM '(' TRAILING trim_list ')'
12439 $$ = (Node *) makeFuncCall(SystemFuncName("rtrim"), $4, @1);
12441 | TRIM '(' trim_list ')'
12443 $$ = (Node *) makeFuncCall(SystemFuncName("btrim"), $3, @1);
12445 | NULLIF '(' a_expr ',' a_expr ')'
12447 $$ = (Node *) makeSimpleA_Expr(AEXPR_NULLIF, "=", $3, $5, @1);
12449 | COALESCE '(' expr_list ')'
12451 CoalesceExpr *c = makeNode(CoalesceExpr);
12456 | GREATEST '(' expr_list ')'
12458 MinMaxExpr *v = makeNode(MinMaxExpr);
12460 v->op = IS_GREATEST;
12464 | LEAST '(' expr_list ')'
12466 MinMaxExpr *v = makeNode(MinMaxExpr);
12472 | XMLCONCAT '(' expr_list ')'
12474 $$ = makeXmlExpr(IS_XMLCONCAT, NULL, NIL, $3, @1);
12476 | XMLELEMENT '(' NAME_P ColLabel ')'
12478 $$ = makeXmlExpr(IS_XMLELEMENT, $4, NIL, NIL, @1);
12480 | XMLELEMENT '(' NAME_P ColLabel ',' xml_attributes ')'
12482 $$ = makeXmlExpr(IS_XMLELEMENT, $4, $6, NIL, @1);
12484 | XMLELEMENT '(' NAME_P ColLabel ',' expr_list ')'
12486 $$ = makeXmlExpr(IS_XMLELEMENT, $4, NIL, $6, @1);
12488 | XMLELEMENT '(' NAME_P ColLabel ',' xml_attributes ',' expr_list ')'
12490 $$ = makeXmlExpr(IS_XMLELEMENT, $4, $6, $8, @1);
12492 | XMLEXISTS '(' c_expr xmlexists_argument ')'
12494 /* xmlexists(A PASSING [BY REF] B [BY REF]) is
12495 * converted to xmlexists(A, B)*/
12496 $$ = (Node *) makeFuncCall(SystemFuncName("xmlexists"), list_make2($3, $4), @1);
12498 | XMLFOREST '(' xml_attribute_list ')'
12500 $$ = makeXmlExpr(IS_XMLFOREST, NULL, $3, NIL, @1);
12502 | XMLPARSE '(' document_or_content a_expr xml_whitespace_option ')'
12504 XmlExpr *x = (XmlExpr *)
12505 makeXmlExpr(IS_XMLPARSE, NULL, NIL,
12506 list_make2($4, makeBoolAConst($5, -1)),
12511 | XMLPI '(' NAME_P ColLabel ')'
12513 $$ = makeXmlExpr(IS_XMLPI, $4, NULL, NIL, @1);
12515 | XMLPI '(' NAME_P ColLabel ',' a_expr ')'
12517 $$ = makeXmlExpr(IS_XMLPI, $4, NULL, list_make1($6), @1);
12519 | XMLROOT '(' a_expr ',' xml_root_version opt_xml_root_standalone ')'
12521 $$ = makeXmlExpr(IS_XMLROOT, NULL, NIL,
12522 list_make3($3, $5, $6), @1);
12524 | XMLSERIALIZE '(' document_or_content a_expr AS SimpleTypename ')'
12526 XmlSerialize *n = makeNode(XmlSerialize);
12538 xml_root_version: VERSION_P a_expr
12540 | VERSION_P NO VALUE_P
12541 { $$ = makeNullAConst(-1); }
12544 opt_xml_root_standalone: ',' STANDALONE_P YES_P
12545 { $$ = makeIntConst(XML_STANDALONE_YES, -1); }
12546 | ',' STANDALONE_P NO
12547 { $$ = makeIntConst(XML_STANDALONE_NO, -1); }
12548 | ',' STANDALONE_P NO VALUE_P
12549 { $$ = makeIntConst(XML_STANDALONE_NO_VALUE, -1); }
12551 { $$ = makeIntConst(XML_STANDALONE_OMITTED, -1); }
12554 xml_attributes: XMLATTRIBUTES '(' xml_attribute_list ')' { $$ = $3; }
12557 xml_attribute_list: xml_attribute_el { $$ = list_make1($1); }
12558 | xml_attribute_list ',' xml_attribute_el { $$ = lappend($1, $3); }
12561 xml_attribute_el: a_expr AS ColLabel
12563 $$ = makeNode(ResTarget);
12565 $$->indirection = NIL;
12566 $$->val = (Node *) $1;
12571 $$ = makeNode(ResTarget);
12573 $$->indirection = NIL;
12574 $$->val = (Node *) $1;
12579 document_or_content: DOCUMENT_P { $$ = XMLOPTION_DOCUMENT; }
12580 | CONTENT_P { $$ = XMLOPTION_CONTENT; }
12583 xml_whitespace_option: PRESERVE WHITESPACE_P { $$ = TRUE; }
12584 | STRIP_P WHITESPACE_P { $$ = FALSE; }
12585 | /*EMPTY*/ { $$ = FALSE; }
12588 /* We allow several variants for SQL and other compatibility. */
12589 xmlexists_argument:
12594 | PASSING c_expr BY REF
12598 | PASSING BY REF c_expr
12602 | PASSING BY REF c_expr BY REF
12610 * Aggregate decoration clauses
12612 within_group_clause:
12613 WITHIN GROUP_P '(' sort_clause ')' { $$ = $4; }
12614 | /*EMPTY*/ { $$ = NIL; }
12618 FILTER '(' WHERE a_expr ')' { $$ = $4; }
12619 | /*EMPTY*/ { $$ = NULL; }
12624 * Window Definitions
12627 WINDOW window_definition_list { $$ = $2; }
12628 | /*EMPTY*/ { $$ = NIL; }
12631 window_definition_list:
12632 window_definition { $$ = list_make1($1); }
12633 | window_definition_list ',' window_definition
12634 { $$ = lappend($1, $3); }
12638 ColId AS window_specification
12646 over_clause: OVER window_specification
12650 WindowDef *n = makeNode(WindowDef);
12653 n->partitionClause = NIL;
12654 n->orderClause = NIL;
12655 n->frameOptions = FRAMEOPTION_DEFAULTS;
12656 n->startOffset = NULL;
12657 n->endOffset = NULL;
12665 window_specification: '(' opt_existing_window_name opt_partition_clause
12666 opt_sort_clause opt_frame_clause ')'
12668 WindowDef *n = makeNode(WindowDef);
12671 n->partitionClause = $3;
12672 n->orderClause = $4;
12673 /* copy relevant fields of opt_frame_clause */
12674 n->frameOptions = $5->frameOptions;
12675 n->startOffset = $5->startOffset;
12676 n->endOffset = $5->endOffset;
12683 * If we see PARTITION, RANGE, or ROWS as the first token after the '('
12684 * of a window_specification, we want the assumption to be that there is
12685 * no existing_window_name; but those keywords are unreserved and so could
12686 * be ColIds. We fix this by making them have the same precedence as IDENT
12687 * and giving the empty production here a slightly higher precedence, so
12688 * that the shift/reduce conflict is resolved in favor of reducing the rule.
12689 * These keywords are thus precluded from being an existing_window_name but
12690 * are not reserved for any other purpose.
12692 opt_existing_window_name: ColId { $$ = $1; }
12693 | /*EMPTY*/ %prec Op { $$ = NULL; }
12696 opt_partition_clause: PARTITION BY expr_list { $$ = $3; }
12697 | /*EMPTY*/ { $$ = NIL; }
12701 * For frame clauses, we return a WindowDef, but only some fields are used:
12702 * frameOptions, startOffset, and endOffset.
12704 * This is only a subset of the full SQL:2008 frame_clause grammar.
12705 * We don't support <window frame exclusion> yet.
12711 n->frameOptions |= FRAMEOPTION_NONDEFAULT | FRAMEOPTION_RANGE;
12712 if (n->frameOptions & (FRAMEOPTION_START_VALUE_PRECEDING |
12713 FRAMEOPTION_END_VALUE_PRECEDING))
12715 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
12716 errmsg("RANGE PRECEDING is only supported with UNBOUNDED"),
12717 parser_errposition(@1)));
12718 if (n->frameOptions & (FRAMEOPTION_START_VALUE_FOLLOWING |
12719 FRAMEOPTION_END_VALUE_FOLLOWING))
12721 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
12722 errmsg("RANGE FOLLOWING is only supported with UNBOUNDED"),
12723 parser_errposition(@1)));
12726 | ROWS frame_extent
12729 n->frameOptions |= FRAMEOPTION_NONDEFAULT | FRAMEOPTION_ROWS;
12734 WindowDef *n = makeNode(WindowDef);
12735 n->frameOptions = FRAMEOPTION_DEFAULTS;
12736 n->startOffset = NULL;
12737 n->endOffset = NULL;
12742 frame_extent: frame_bound
12745 /* reject invalid cases */
12746 if (n->frameOptions & FRAMEOPTION_START_UNBOUNDED_FOLLOWING)
12748 (errcode(ERRCODE_WINDOWING_ERROR),
12749 errmsg("frame start cannot be UNBOUNDED FOLLOWING"),
12750 parser_errposition(@1)));
12751 if (n->frameOptions & FRAMEOPTION_START_VALUE_FOLLOWING)
12753 (errcode(ERRCODE_WINDOWING_ERROR),
12754 errmsg("frame starting from following row cannot end with current row"),
12755 parser_errposition(@1)));
12756 n->frameOptions |= FRAMEOPTION_END_CURRENT_ROW;
12759 | BETWEEN frame_bound AND frame_bound
12761 WindowDef *n1 = $2;
12762 WindowDef *n2 = $4;
12763 /* form merged options */
12764 int frameOptions = n1->frameOptions;
12765 /* shift converts START_ options to END_ options */
12766 frameOptions |= n2->frameOptions << 1;
12767 frameOptions |= FRAMEOPTION_BETWEEN;
12768 /* reject invalid cases */
12769 if (frameOptions & FRAMEOPTION_START_UNBOUNDED_FOLLOWING)
12771 (errcode(ERRCODE_WINDOWING_ERROR),
12772 errmsg("frame start cannot be UNBOUNDED FOLLOWING"),
12773 parser_errposition(@2)));
12774 if (frameOptions & FRAMEOPTION_END_UNBOUNDED_PRECEDING)
12776 (errcode(ERRCODE_WINDOWING_ERROR),
12777 errmsg("frame end cannot be UNBOUNDED PRECEDING"),
12778 parser_errposition(@4)));
12779 if ((frameOptions & FRAMEOPTION_START_CURRENT_ROW) &&
12780 (frameOptions & FRAMEOPTION_END_VALUE_PRECEDING))
12782 (errcode(ERRCODE_WINDOWING_ERROR),
12783 errmsg("frame starting from current row cannot have preceding rows"),
12784 parser_errposition(@4)));
12785 if ((frameOptions & FRAMEOPTION_START_VALUE_FOLLOWING) &&
12786 (frameOptions & (FRAMEOPTION_END_VALUE_PRECEDING |
12787 FRAMEOPTION_END_CURRENT_ROW)))
12789 (errcode(ERRCODE_WINDOWING_ERROR),
12790 errmsg("frame starting from following row cannot have preceding rows"),
12791 parser_errposition(@4)));
12792 n1->frameOptions = frameOptions;
12793 n1->endOffset = n2->startOffset;
12799 * This is used for both frame start and frame end, with output set up on
12800 * the assumption it's frame start; the frame_extent productions must reject
12804 UNBOUNDED PRECEDING
12806 WindowDef *n = makeNode(WindowDef);
12807 n->frameOptions = FRAMEOPTION_START_UNBOUNDED_PRECEDING;
12808 n->startOffset = NULL;
12809 n->endOffset = NULL;
12812 | UNBOUNDED FOLLOWING
12814 WindowDef *n = makeNode(WindowDef);
12815 n->frameOptions = FRAMEOPTION_START_UNBOUNDED_FOLLOWING;
12816 n->startOffset = NULL;
12817 n->endOffset = NULL;
12822 WindowDef *n = makeNode(WindowDef);
12823 n->frameOptions = FRAMEOPTION_START_CURRENT_ROW;
12824 n->startOffset = NULL;
12825 n->endOffset = NULL;
12830 WindowDef *n = makeNode(WindowDef);
12831 n->frameOptions = FRAMEOPTION_START_VALUE_PRECEDING;
12832 n->startOffset = $1;
12833 n->endOffset = NULL;
12838 WindowDef *n = makeNode(WindowDef);
12839 n->frameOptions = FRAMEOPTION_START_VALUE_FOLLOWING;
12840 n->startOffset = $1;
12841 n->endOffset = NULL;
12848 * Supporting nonterminals for expressions.
12851 /* Explicit row production.
12853 * SQL99 allows an optional ROW keyword, so we can now do single-element rows
12854 * without conflicting with the parenthesized a_expr production. Without the
12855 * ROW keyword, there must be more than one a_expr inside the parens.
12857 row: ROW '(' expr_list ')' { $$ = $3; }
12858 | ROW '(' ')' { $$ = NIL; }
12859 | '(' expr_list ',' a_expr ')' { $$ = lappend($2, $4); }
12862 explicit_row: ROW '(' expr_list ')' { $$ = $3; }
12863 | ROW '(' ')' { $$ = NIL; }
12866 implicit_row: '(' expr_list ',' a_expr ')' { $$ = lappend($2, $4); }
12869 sub_type: ANY { $$ = ANY_SUBLINK; }
12870 | SOME { $$ = ANY_SUBLINK; }
12871 | ALL { $$ = ALL_SUBLINK; }
12874 all_Op: Op { $$ = $1; }
12875 | MathOp { $$ = $1; }
12878 MathOp: '+' { $$ = "+"; }
12879 | '-' { $$ = "-"; }
12880 | '*' { $$ = "*"; }
12881 | '/' { $$ = "/"; }
12882 | '%' { $$ = "%"; }
12883 | '^' { $$ = "^"; }
12884 | '<' { $$ = "<"; }
12885 | '>' { $$ = ">"; }
12886 | '=' { $$ = "="; }
12887 | LESS_EQUALS { $$ = "<="; }
12888 | GREATER_EQUALS { $$ = ">="; }
12889 | NOT_EQUALS { $$ = "<>"; }
12893 { $$ = list_make1(makeString($1)); }
12894 | OPERATOR '(' any_operator ')'
12900 { $$ = list_make1(makeString($1)); }
12901 | OPERATOR '(' any_operator ')'
12907 { $$ = list_make1(makeString($1)); }
12908 | OPERATOR '(' any_operator ')'
12911 { $$ = list_make1(makeString("~~")); }
12913 { $$ = list_make1(makeString("!~~")); }
12915 { $$ = list_make1(makeString("~~*")); }
12917 { $$ = list_make1(makeString("!~~*")); }
12918 /* cannot put SIMILAR TO here, because SIMILAR TO is a hack.
12919 * the regular expression is preprocessed by a function (similar_escape),
12920 * and the ~ operator for posix regular expressions is used.
12921 * x SIMILAR TO y -> x ~ similar_escape(y)
12922 * this transformation is made on the fly by the parser upwards.
12923 * however the SubLink structure which handles any/some/all stuff
12924 * is not ready for such a thing.
12930 $$ = list_make1($1);
12932 | expr_list ',' a_expr
12934 $$ = lappend($1, $3);
12938 /* function arguments can have names */
12939 func_arg_list: func_arg_expr
12941 $$ = list_make1($1);
12943 | func_arg_list ',' func_arg_expr
12945 $$ = lappend($1, $3);
12949 func_arg_expr: a_expr
12953 | param_name COLON_EQUALS a_expr
12955 NamedArgExpr *na = makeNode(NamedArgExpr);
12957 na->arg = (Expr *) $3;
12958 na->argnumber = -1; /* until determined */
12962 | param_name EQUALS_GREATER a_expr
12964 NamedArgExpr *na = makeNode(NamedArgExpr);
12966 na->arg = (Expr *) $3;
12967 na->argnumber = -1; /* until determined */
12973 type_list: Typename { $$ = list_make1($1); }
12974 | type_list ',' Typename { $$ = lappend($1, $3); }
12977 array_expr: '[' expr_list ']'
12979 $$ = makeAArrayExpr($2, @1);
12981 | '[' array_expr_list ']'
12983 $$ = makeAArrayExpr($2, @1);
12987 $$ = makeAArrayExpr(NIL, @1);
12991 array_expr_list: array_expr { $$ = list_make1($1); }
12992 | array_expr_list ',' array_expr { $$ = lappend($1, $3); }
12997 extract_arg FROM a_expr
12999 $$ = list_make2(makeStringConst($1, @1), $3);
13001 | /*EMPTY*/ { $$ = NIL; }
13004 /* Allow delimited string Sconst in extract_arg as an SQL extension.
13005 * - thomas 2001-04-12
13009 | YEAR_P { $$ = "year"; }
13010 | MONTH_P { $$ = "month"; }
13011 | DAY_P { $$ = "day"; }
13012 | HOUR_P { $$ = "hour"; }
13013 | MINUTE_P { $$ = "minute"; }
13014 | SECOND_P { $$ = "second"; }
13015 | Sconst { $$ = $1; }
13018 /* OVERLAY() arguments
13019 * SQL99 defines the OVERLAY() function:
13020 * o overlay(text placing text from int for int)
13021 * o overlay(text placing text from int)
13022 * and similarly for binary strings
13025 a_expr overlay_placing substr_from substr_for
13027 $$ = list_make4($1, $2, $3, $4);
13029 | a_expr overlay_placing substr_from
13031 $$ = list_make3($1, $2, $3);
13040 /* position_list uses b_expr not a_expr to avoid conflict with general IN */
13043 b_expr IN_P b_expr { $$ = list_make2($3, $1); }
13044 | /*EMPTY*/ { $$ = NIL; }
13047 /* SUBSTRING() arguments
13048 * SQL9x defines a specific syntax for arguments to SUBSTRING():
13049 * o substring(text from int for int)
13050 * o substring(text from int) get entire string from starting point "int"
13051 * o substring(text for int) get first "int" characters of string
13052 * o substring(text from pattern) get entire string matching pattern
13053 * o substring(text from pattern for escape) same with specified escape char
13054 * We also want to support generic substring functions which accept
13055 * the usual generic list of arguments. So we will accept both styles
13056 * here, and convert the SQL9x style to the generic list for further
13057 * processing. - thomas 2000-11-28
13060 a_expr substr_from substr_for
13062 $$ = list_make3($1, $2, $3);
13064 | a_expr substr_for substr_from
13066 /* not legal per SQL99, but might as well allow it */
13067 $$ = list_make3($1, $3, $2);
13069 | a_expr substr_from
13071 $$ = list_make2($1, $2);
13073 | a_expr substr_for
13076 * Since there are no cases where this syntax allows
13077 * a textual FOR value, we forcibly cast the argument
13078 * to int4. The possible matches in pg_proc are
13079 * substring(text,int4) and substring(text,text),
13080 * and we don't want the parser to choose the latter,
13081 * which it is likely to do if the second argument
13082 * is unknown or doesn't have an implicit cast to int4.
13084 $$ = list_make3($1, makeIntConst(1, -1),
13086 SystemTypeName("int4"), -1));
13097 FROM a_expr { $$ = $2; }
13100 substr_for: FOR a_expr { $$ = $2; }
13103 trim_list: a_expr FROM expr_list { $$ = lappend($3, $1); }
13104 | FROM expr_list { $$ = $2; }
13105 | expr_list { $$ = $1; }
13108 in_expr: select_with_parens
13110 SubLink *n = makeNode(SubLink);
13112 /* other fields will be filled later */
13115 | '(' expr_list ')' { $$ = (Node *)$2; }
13119 * Define SQL-style CASE clause.
13120 * - Full specification
13121 * CASE WHEN a = b THEN c ... ELSE d END
13122 * - Implicit argument
13123 * CASE a WHEN b THEN c ... ELSE d END
13125 case_expr: CASE case_arg when_clause_list case_default END_P
13127 CaseExpr *c = makeNode(CaseExpr);
13128 c->casetype = InvalidOid; /* not analyzed yet */
13129 c->arg = (Expr *) $2;
13131 c->defresult = (Expr *) $4;
13138 /* There must be at least one */
13139 when_clause { $$ = list_make1($1); }
13140 | when_clause_list when_clause { $$ = lappend($1, $2); }
13144 WHEN a_expr THEN a_expr
13146 CaseWhen *w = makeNode(CaseWhen);
13147 w->expr = (Expr *) $2;
13148 w->result = (Expr *) $4;
13155 ELSE a_expr { $$ = $2; }
13156 | /*EMPTY*/ { $$ = NULL; }
13159 case_arg: a_expr { $$ = $1; }
13160 | /*EMPTY*/ { $$ = NULL; }
13165 $$ = makeColumnRef($1, NIL, @1, yyscanner);
13167 | ColId indirection
13169 $$ = makeColumnRef($1, $2, @1, yyscanner);
13176 $$ = (Node *) makeString($2);
13180 $$ = (Node *) makeNode(A_Star);
13184 A_Indices *ai = makeNode(A_Indices);
13189 | '[' a_expr ':' a_expr ']'
13191 A_Indices *ai = makeNode(A_Indices);
13199 indirection_el { $$ = list_make1($1); }
13200 | indirection indirection_el { $$ = lappend($1, $2); }
13204 /*EMPTY*/ { $$ = NIL; }
13205 | opt_indirection indirection_el { $$ = lappend($1, $2); }
13208 opt_asymmetric: ASYMMETRIC
13213 * The SQL spec defines "contextually typed value expressions" and
13214 * "contextually typed row value constructors", which for our purposes
13215 * are the same as "a_expr" and "row" except that DEFAULT can appear at
13220 a_expr { $$ = (Node *) $1; }
13223 SetToDefault *n = makeNode(SetToDefault);
13230 ctext_expr { $$ = list_make1($1); }
13231 | ctext_expr_list ',' ctext_expr { $$ = lappend($1, $3); }
13235 * We should allow ROW '(' ctext_expr_list ')' too, but that seems to require
13236 * making VALUES a fully reserved word, which will probably break more apps
13237 * than allowing the noise-word is worth.
13239 ctext_row: '(' ctext_expr_list ')' { $$ = $2; }
13243 /*****************************************************************************
13245 * target list for SELECT
13247 *****************************************************************************/
13249 opt_target_list: target_list { $$ = $1; }
13250 | /* EMPTY */ { $$ = NIL; }
13254 target_el { $$ = list_make1($1); }
13255 | target_list ',' target_el { $$ = lappend($1, $3); }
13258 target_el: a_expr AS ColLabel
13260 $$ = makeNode(ResTarget);
13262 $$->indirection = NIL;
13263 $$->val = (Node *)$1;
13267 * We support omitting AS only for column labels that aren't
13268 * any known keyword. There is an ambiguity against postfix
13269 * operators: is "a ! b" an infix expression, or a postfix
13270 * expression and a column label? We prefer to resolve this
13271 * as an infix expression, which we accomplish by assigning
13272 * IDENT a precedence higher than POSTFIXOP.
13276 $$ = makeNode(ResTarget);
13278 $$->indirection = NIL;
13279 $$->val = (Node *)$1;
13284 $$ = makeNode(ResTarget);
13286 $$->indirection = NIL;
13287 $$->val = (Node *)$1;
13292 ColumnRef *n = makeNode(ColumnRef);
13293 n->fields = list_make1(makeNode(A_Star));
13296 $$ = makeNode(ResTarget);
13298 $$->indirection = NIL;
13299 $$->val = (Node *)n;
13305 /*****************************************************************************
13307 * Names and constants
13309 *****************************************************************************/
13311 qualified_name_list:
13312 qualified_name { $$ = list_make1($1); }
13313 | qualified_name_list ',' qualified_name { $$ = lappend($1, $3); }
13317 * The production for a qualified relation name has to exactly match the
13318 * production for a qualified func_name, because in a FROM clause we cannot
13319 * tell which we are parsing until we see what comes after it ('(' for a
13320 * func_name, something else for a relation). Therefore we allow 'indirection'
13321 * which may contain subscripts, and reject that case in the C code.
13326 $$ = makeRangeVar(NULL, $1, @1);
13328 | ColId indirection
13330 check_qualified_name($2, yyscanner);
13331 $$ = makeRangeVar(NULL, NULL, @1);
13332 switch (list_length($2))
13335 $$->catalogname = NULL;
13336 $$->schemaname = $1;
13337 $$->relname = strVal(linitial($2));
13340 $$->catalogname = $1;
13341 $$->schemaname = strVal(linitial($2));
13342 $$->relname = strVal(lsecond($2));
13346 (errcode(ERRCODE_SYNTAX_ERROR),
13347 errmsg("improper qualified name (too many dotted names): %s",
13348 NameListToString(lcons(makeString($1), $2))),
13349 parser_errposition(@1)));
13356 { $$ = list_make1(makeString($1)); }
13357 | name_list ',' name
13358 { $$ = lappend($1, makeString($3)); }
13362 name: ColId { $$ = $1; };
13365 ColId { $$ = $1; };
13368 ColId { $$ = $1; };
13370 attr_name: ColLabel { $$ = $1; };
13372 index_name: ColId { $$ = $1; };
13374 file_name: Sconst { $$ = $1; };
13377 * The production for a qualified func_name has to exactly match the
13378 * production for a qualified columnref, because we cannot tell which we
13379 * are parsing until we see what comes after it ('(' or Sconst for a func_name,
13380 * anything else for a columnref). Therefore we allow 'indirection' which
13381 * may contain subscripts, and reject that case in the C code. (If we
13382 * ever implement SQL99-like methods, such syntax may actually become legal!)
13384 func_name: type_function_name
13385 { $$ = list_make1(makeString($1)); }
13386 | ColId indirection
13388 $$ = check_func_name(lcons(makeString($1), $2),
13399 $$ = makeIntConst($1, @1);
13403 $$ = makeFloatConst($1, @1);
13407 $$ = makeStringConst($1, @1);
13411 $$ = makeBitStringConst($1, @1);
13415 /* This is a bit constant per SQL99:
13416 * Without Feature F511, "BIT data type",
13417 * a <general literal> shall not be a
13418 * <bit string literal> or a <hex string literal>.
13420 $$ = makeBitStringConst($1, @1);
13424 /* generic type 'literal' syntax */
13425 TypeName *t = makeTypeNameFromNameList($1);
13427 $$ = makeStringConstCast($2, @2, t);
13429 | func_name '(' func_arg_list opt_sort_clause ')' Sconst
13431 /* generic syntax with a type modifier */
13432 TypeName *t = makeTypeNameFromNameList($1);
13436 * We must use func_arg_list and opt_sort_clause in the
13437 * production to avoid reduce/reduce conflicts, but we
13438 * don't actually wish to allow NamedArgExpr in this
13439 * context, nor ORDER BY.
13443 NamedArgExpr *arg = (NamedArgExpr *) lfirst(lc);
13445 if (IsA(arg, NamedArgExpr))
13447 (errcode(ERRCODE_SYNTAX_ERROR),
13448 errmsg("type modifier cannot have parameter name"),
13449 parser_errposition(arg->location)));
13453 (errcode(ERRCODE_SYNTAX_ERROR),
13454 errmsg("type modifier cannot have ORDER BY"),
13455 parser_errposition(@4)));
13459 $$ = makeStringConstCast($6, @6, t);
13461 | ConstTypename Sconst
13463 $$ = makeStringConstCast($2, @2, $1);
13465 | ConstInterval Sconst opt_interval
13469 $$ = makeStringConstCast($2, @2, t);
13471 | ConstInterval '(' Iconst ')' Sconst
13474 t->typmods = list_make2(makeIntConst(INTERVAL_FULL_RANGE, -1),
13475 makeIntConst($3, @3));
13476 $$ = makeStringConstCast($5, @5, t);
13480 $$ = makeBoolAConst(TRUE, @1);
13484 $$ = makeBoolAConst(FALSE, @1);
13488 $$ = makeNullAConst(@1);
13492 Iconst: ICONST { $$ = $1; };
13493 Sconst: SCONST { $$ = $1; };
13495 SignedIconst: Iconst { $$ = $1; }
13496 | '+' Iconst { $$ = + $2; }
13497 | '-' Iconst { $$ = - $2; }
13500 /* Role specifications */
13503 RoleSpec *spc = (RoleSpec *) $1;
13504 switch (spc->roletype)
13506 case ROLESPEC_CSTRING:
13507 $$ = spc->rolename;
13509 case ROLESPEC_PUBLIC:
13511 (errcode(ERRCODE_RESERVED_NAME),
13512 errmsg("role name \"%s\" is reserved",
13514 parser_errposition(@1)));
13515 case ROLESPEC_SESSION_USER:
13517 (errcode(ERRCODE_RESERVED_NAME),
13518 errmsg("%s cannot be used as a role name here",
13520 parser_errposition(@1)));
13521 case ROLESPEC_CURRENT_USER:
13523 (errcode(ERRCODE_RESERVED_NAME),
13524 errmsg("%s cannot be used as a role name here",
13526 parser_errposition(@1)));
13531 RoleSpec: NonReservedWord
13534 * "public" and "none" are not keywords, but they must
13535 * be treated specially here.
13538 if (strcmp($1, "public") == 0)
13540 n = (RoleSpec *) makeRoleSpec(ROLESPEC_PUBLIC, @1);
13541 n->roletype = ROLESPEC_PUBLIC;
13543 else if (strcmp($1, "none") == 0)
13546 (errcode(ERRCODE_RESERVED_NAME),
13547 errmsg("role name \"%s\" is reserved",
13549 parser_errposition(@1)));
13553 n = (RoleSpec *) makeRoleSpec(ROLESPEC_CSTRING, @1);
13554 n->rolename = pstrdup($1);
13560 $$ = makeRoleSpec(ROLESPEC_CURRENT_USER, @1);
13564 $$ = makeRoleSpec(ROLESPEC_SESSION_USER, @1);
13568 role_list: RoleSpec
13569 { $$ = list_make1($1); }
13570 | role_list ',' RoleSpec
13571 { $$ = lappend($1, $3); }
13575 * Name classification hierarchy.
13577 * IDENT is the lexeme returned by the lexer for identifiers that match
13578 * no known keyword. In most cases, we can accept certain keywords as
13579 * names, not only IDENTs. We prefer to accept as many such keywords
13580 * as possible to minimize the impact of "reserved words" on programmers.
13581 * So, we divide names into several possible classes. The classification
13582 * is chosen in part to make keywords acceptable as names wherever possible.
13585 /* Column identifier --- names that can be column, table, etc names.
13587 ColId: IDENT { $$ = $1; }
13588 | unreserved_keyword { $$ = pstrdup($1); }
13589 | col_name_keyword { $$ = pstrdup($1); }
13592 /* Type/function identifier --- names that can be type or function names.
13594 type_function_name: IDENT { $$ = $1; }
13595 | unreserved_keyword { $$ = pstrdup($1); }
13596 | type_func_name_keyword { $$ = pstrdup($1); }
13599 /* Any not-fully-reserved word --- these names can be, eg, role names.
13601 NonReservedWord: IDENT { $$ = $1; }
13602 | unreserved_keyword { $$ = pstrdup($1); }
13603 | col_name_keyword { $$ = pstrdup($1); }
13604 | type_func_name_keyword { $$ = pstrdup($1); }
13607 /* Column label --- allowed labels in "AS" clauses.
13608 * This presently includes *all* Postgres keywords.
13610 ColLabel: IDENT { $$ = $1; }
13611 | unreserved_keyword { $$ = pstrdup($1); }
13612 | col_name_keyword { $$ = pstrdup($1); }
13613 | type_func_name_keyword { $$ = pstrdup($1); }
13614 | reserved_keyword { $$ = pstrdup($1); }
13619 * Keyword category lists. Generally, every keyword present in
13620 * the Postgres grammar should appear in exactly one of these lists.
13622 * Put a new keyword into the first list that it can go into without causing
13623 * shift or reduce conflicts. The earlier lists define "less reserved"
13624 * categories of keywords.
13626 * Make sure that each keyword's category in kwlist.h matches where
13627 * it is listed here. (Someday we may be able to generate these lists and
13628 * kwlist.h's table from a common master list.)
13631 /* "Unreserved" keywords --- available for use as any kind of name.
13633 unreserved_keyword:
13905 /* Column identifier --- keywords that can be column, table, etc names.
13907 * Many of these keywords will in fact be recognized as type or function
13908 * names too; but they have special productions for the purpose, and so
13909 * can't be treated as "generic" type or function names.
13911 * The type names appearing here are not usable as function names
13912 * because they can be followed by '(' in typename productions, which
13913 * looks too much like a function call for an LR(1) parser.
13966 /* Type/function identifier --- keywords that can be type or function names.
13968 * Most of these are keywords that are used as operators in expressions;
13969 * in general such keywords can't be column names because they would be
13970 * ambiguous with variables, but they are unambiguous as function identifiers.
13972 * Do not include POSITION, SUBSTRING, etc here since they have explicit
13973 * productions in a_expr to support the goofy SQL9x argument syntax.
13974 * - thomas 2000-11-28
13976 type_func_name_keyword:
14002 /* Reserved keyword --- these keywords are usable only as a ColLabel.
14004 * Keywords appear here if they could not be distinguished from variable,
14005 * type, or function names in some contexts. Don't put things here unless
14030 | CURRENT_TIMESTAMP
14091 * The signature of this function is required by bison. However, we
14092 * ignore the passed yylloc and instead use the last token position
14093 * available from the scanner.
14096 base_yyerror(YYLTYPE *yylloc, core_yyscan_t yyscanner, const char *msg)
14098 parser_yyerror(msg);
14102 makeColumnRef(char *colname, List *indirection,
14103 int location, core_yyscan_t yyscanner)
14106 * Generate a ColumnRef node, with an A_Indirection node added if there
14107 * is any subscripting in the specified indirection list. However,
14108 * any field selection at the start of the indirection list must be
14109 * transposed into the "fields" part of the ColumnRef node.
14111 ColumnRef *c = makeNode(ColumnRef);
14115 c->location = location;
14116 foreach(l, indirection)
14118 if (IsA(lfirst(l), A_Indices))
14120 A_Indirection *i = makeNode(A_Indirection);
14124 /* easy case - all indirection goes to A_Indirection */
14125 c->fields = list_make1(makeString(colname));
14126 i->indirection = check_indirection(indirection, yyscanner);
14130 /* got to split the list in two */
14131 i->indirection = check_indirection(list_copy_tail(indirection,
14134 indirection = list_truncate(indirection, nfields);
14135 c->fields = lcons(makeString(colname), indirection);
14137 i->arg = (Node *) c;
14140 else if (IsA(lfirst(l), A_Star))
14142 /* We only allow '*' at the end of a ColumnRef */
14143 if (lnext(l) != NULL)
14144 parser_yyerror("improper use of \"*\"");
14148 /* No subscripting, so all indirection gets added to field list */
14149 c->fields = lcons(makeString(colname), indirection);
14154 makeTypeCast(Node *arg, TypeName *typename, int location)
14156 TypeCast *n = makeNode(TypeCast);
14158 n->typeName = typename;
14159 n->location = location;
14164 makeStringConst(char *str, int location)
14166 A_Const *n = makeNode(A_Const);
14168 n->val.type = T_String;
14169 n->val.val.str = str;
14170 n->location = location;
14176 makeStringConstCast(char *str, int location, TypeName *typename)
14178 Node *s = makeStringConst(str, location);
14180 return makeTypeCast(s, typename, -1);
14184 makeIntConst(int val, int location)
14186 A_Const *n = makeNode(A_Const);
14188 n->val.type = T_Integer;
14189 n->val.val.ival = val;
14190 n->location = location;
14196 makeFloatConst(char *str, int location)
14198 A_Const *n = makeNode(A_Const);
14200 n->val.type = T_Float;
14201 n->val.val.str = str;
14202 n->location = location;
14208 makeBitStringConst(char *str, int location)
14210 A_Const *n = makeNode(A_Const);
14212 n->val.type = T_BitString;
14213 n->val.val.str = str;
14214 n->location = location;
14220 makeNullAConst(int location)
14222 A_Const *n = makeNode(A_Const);
14224 n->val.type = T_Null;
14225 n->location = location;
14231 makeAConst(Value *v, int location)
14238 n = makeFloatConst(v->val.str, location);
14242 n = makeIntConst(v->val.ival, location);
14247 n = makeStringConst(v->val.str, location);
14254 /* makeBoolAConst()
14255 * Create an A_Const string node and put it inside a boolean cast.
14258 makeBoolAConst(bool state, int location)
14260 A_Const *n = makeNode(A_Const);
14262 n->val.type = T_String;
14263 n->val.val.str = (state ? "t" : "f");
14264 n->location = location;
14266 return makeTypeCast((Node *)n, SystemTypeName("bool"), -1);
14270 * Create a RoleSpec with the given type
14273 makeRoleSpec(RoleSpecType type, int location)
14275 RoleSpec *spec = makeNode(RoleSpec);
14277 spec->roletype = type;
14278 spec->location = location;
14280 return (Node *) spec;
14283 /* check_qualified_name --- check the result of qualified_name production
14285 * It's easiest to let the grammar production for qualified_name allow
14286 * subscripts and '*', which we then must reject here.
14289 check_qualified_name(List *names, core_yyscan_t yyscanner)
14295 if (!IsA(lfirst(i), String))
14296 parser_yyerror("syntax error");
14300 /* check_func_name --- check the result of func_name production
14302 * It's easiest to let the grammar production for func_name allow subscripts
14303 * and '*', which we then must reject here.
14306 check_func_name(List *names, core_yyscan_t yyscanner)
14312 if (!IsA(lfirst(i), String))
14313 parser_yyerror("syntax error");
14318 /* check_indirection --- check the result of indirection production
14320 * We only allow '*' at the end of the list, but it's hard to enforce that
14321 * in the grammar, so do it here.
14324 check_indirection(List *indirection, core_yyscan_t yyscanner)
14328 foreach(l, indirection)
14330 if (IsA(lfirst(l), A_Star))
14332 if (lnext(l) != NULL)
14333 parser_yyerror("improper use of \"*\"");
14336 return indirection;
14339 /* extractArgTypes()
14340 * Given a list of FunctionParameter nodes, extract a list of just the
14341 * argument types (TypeNames) for input parameters only. This is what
14342 * is needed to look up an existing function, which is what is wanted by
14343 * the productions that use this call.
14346 extractArgTypes(List *parameters)
14348 List *result = NIL;
14351 foreach(i, parameters)
14353 FunctionParameter *p = (FunctionParameter *) lfirst(i);
14355 if (p->mode != FUNC_PARAM_OUT && p->mode != FUNC_PARAM_TABLE)
14356 result = lappend(result, p->argType);
14361 /* extractAggrArgTypes()
14362 * As above, but work from the output of the aggr_args production.
14365 extractAggrArgTypes(List *aggrargs)
14367 Assert(list_length(aggrargs) == 2);
14368 return extractArgTypes((List *) linitial(aggrargs));
14371 /* makeOrderedSetArgs()
14372 * Build the result of the aggr_args production (which see the comments for).
14373 * This handles only the case where both given lists are nonempty, so that
14374 * we have to deal with multiple VARIADIC arguments.
14377 makeOrderedSetArgs(List *directargs, List *orderedargs,
14378 core_yyscan_t yyscanner)
14380 FunctionParameter *lastd = (FunctionParameter *) llast(directargs);
14383 /* No restriction unless last direct arg is VARIADIC */
14384 if (lastd->mode == FUNC_PARAM_VARIADIC)
14386 FunctionParameter *firsto = (FunctionParameter *) linitial(orderedargs);
14389 * We ignore the names, though the aggr_arg production allows them;
14390 * it doesn't allow default values, so those need not be checked.
14392 if (list_length(orderedargs) != 1 ||
14393 firsto->mode != FUNC_PARAM_VARIADIC ||
14394 !equal(lastd->argType, firsto->argType))
14396 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
14397 errmsg("an ordered-set aggregate with a VARIADIC direct argument must have one VARIADIC aggregated argument of the same data type"),
14398 parser_errposition(exprLocation((Node *) firsto))));
14400 /* OK, drop the duplicate VARIADIC argument from the internal form */
14404 /* don't merge into the next line, as list_concat changes directargs */
14405 ndirectargs = list_length(directargs);
14407 return list_make2(list_concat(directargs, orderedargs),
14408 makeInteger(ndirectargs));
14411 /* insertSelectOptions()
14412 * Insert ORDER BY, etc into an already-constructed SelectStmt.
14414 * This routine is just to avoid duplicating code in SelectStmt productions.
14417 insertSelectOptions(SelectStmt *stmt,
14418 List *sortClause, List *lockingClause,
14419 Node *limitOffset, Node *limitCount,
14420 WithClause *withClause,
14421 core_yyscan_t yyscanner)
14423 Assert(IsA(stmt, SelectStmt));
14426 * Tests here are to reject constructs like
14427 * (SELECT foo ORDER BY bar) ORDER BY baz
14431 if (stmt->sortClause)
14433 (errcode(ERRCODE_SYNTAX_ERROR),
14434 errmsg("multiple ORDER BY clauses not allowed"),
14435 parser_errposition(exprLocation((Node *) sortClause))));
14436 stmt->sortClause = sortClause;
14438 /* We can handle multiple locking clauses, though */
14439 stmt->lockingClause = list_concat(stmt->lockingClause, lockingClause);
14442 if (stmt->limitOffset)
14444 (errcode(ERRCODE_SYNTAX_ERROR),
14445 errmsg("multiple OFFSET clauses not allowed"),
14446 parser_errposition(exprLocation(limitOffset))));
14447 stmt->limitOffset = limitOffset;
14451 if (stmt->limitCount)
14453 (errcode(ERRCODE_SYNTAX_ERROR),
14454 errmsg("multiple LIMIT clauses not allowed"),
14455 parser_errposition(exprLocation(limitCount))));
14456 stmt->limitCount = limitCount;
14460 if (stmt->withClause)
14462 (errcode(ERRCODE_SYNTAX_ERROR),
14463 errmsg("multiple WITH clauses not allowed"),
14464 parser_errposition(exprLocation((Node *) withClause))));
14465 stmt->withClause = withClause;
14470 makeSetOp(SetOperation op, bool all, Node *larg, Node *rarg)
14472 SelectStmt *n = makeNode(SelectStmt);
14476 n->larg = (SelectStmt *) larg;
14477 n->rarg = (SelectStmt *) rarg;
14481 /* SystemFuncName()
14482 * Build a properly-qualified reference to a built-in function.
14485 SystemFuncName(char *name)
14487 return list_make2(makeString("pg_catalog"), makeString(name));
14490 /* SystemTypeName()
14491 * Build a properly-qualified reference to a built-in type.
14493 * typmod is defaulted, but may be changed afterwards by caller.
14494 * Likewise for the location.
14497 SystemTypeName(char *name)
14499 return makeTypeNameFromNameList(list_make2(makeString("pg_catalog"),
14500 makeString(name)));
14504 * Handle negation of a numeric constant.
14506 * Formerly, we did this here because the optimizer couldn't cope with
14507 * indexquals that looked like "var = -4" --- it wants "var = const"
14508 * and a unary minus operator applied to a constant didn't qualify.
14509 * As of Postgres 7.0, that problem doesn't exist anymore because there
14510 * is a constant-subexpression simplifier in the optimizer. However,
14511 * there's still a good reason for doing this here, which is that we can
14512 * postpone committing to a particular internal representation for simple
14513 * negative constants. It's better to leave "-123.456" in string form
14514 * until we know what the desired type is.
14517 doNegate(Node *n, int location)
14519 if (IsA(n, A_Const))
14521 A_Const *con = (A_Const *)n;
14523 /* report the constant's location as that of the '-' sign */
14524 con->location = location;
14526 if (con->val.type == T_Integer)
14528 con->val.val.ival = -con->val.val.ival;
14531 if (con->val.type == T_Float)
14533 doNegateFloat(&con->val);
14538 return (Node *) makeSimpleA_Expr(AEXPR_OP, "-", NULL, n, location);
14542 doNegateFloat(Value *v)
14544 char *oldval = v->val.str;
14546 Assert(IsA(v, Float));
14547 if (*oldval == '+')
14549 if (*oldval == '-')
14550 v->val.str = oldval+1; /* just strip the '-' */
14552 v->val.str = psprintf("-%s", oldval);
14556 makeAndExpr(Node *lexpr, Node *rexpr, int location)
14558 /* Flatten "a AND b AND c ..." to a single BoolExpr on sight */
14559 if (IsA(lexpr, BoolExpr))
14561 BoolExpr *blexpr = (BoolExpr *) lexpr;
14563 if (blexpr->boolop == AND_EXPR)
14565 blexpr->args = lappend(blexpr->args, rexpr);
14566 return (Node *) blexpr;
14569 return (Node *) makeBoolExpr(AND_EXPR, list_make2(lexpr, rexpr), location);
14573 makeOrExpr(Node *lexpr, Node *rexpr, int location)
14575 /* Flatten "a OR b OR c ..." to a single BoolExpr on sight */
14576 if (IsA(lexpr, BoolExpr))
14578 BoolExpr *blexpr = (BoolExpr *) lexpr;
14580 if (blexpr->boolop == OR_EXPR)
14582 blexpr->args = lappend(blexpr->args, rexpr);
14583 return (Node *) blexpr;
14586 return (Node *) makeBoolExpr(OR_EXPR, list_make2(lexpr, rexpr), location);
14590 makeNotExpr(Node *expr, int location)
14592 return (Node *) makeBoolExpr(NOT_EXPR, list_make1(expr), location);
14596 makeAArrayExpr(List *elements, int location)
14598 A_ArrayExpr *n = makeNode(A_ArrayExpr);
14600 n->elements = elements;
14601 n->location = location;
14606 makeXmlExpr(XmlExprOp op, char *name, List *named_args, List *args,
14609 XmlExpr *x = makeNode(XmlExpr);
14614 * named_args is a list of ResTarget; it'll be split apart into separate
14615 * expression and name lists in transformXmlExpr().
14617 x->named_args = named_args;
14618 x->arg_names = NIL;
14620 /* xmloption, if relevant, must be filled in by caller */
14621 /* type and typmod will be filled in during parse analysis */
14622 x->type = InvalidOid; /* marks the node as not analyzed */
14623 x->location = location;
14628 * Merge the input and output parameters of a table function.
14631 mergeTableFuncParameters(List *func_args, List *columns)
14635 /* Explicit OUT and INOUT parameters shouldn't be used in this syntax */
14636 foreach(lc, func_args)
14638 FunctionParameter *p = (FunctionParameter *) lfirst(lc);
14640 if (p->mode != FUNC_PARAM_IN && p->mode != FUNC_PARAM_VARIADIC)
14642 (errcode(ERRCODE_SYNTAX_ERROR),
14643 errmsg("OUT and INOUT arguments aren't allowed in TABLE functions")));
14646 return list_concat(func_args, columns);
14650 * Determine return type of a TABLE function. A single result column
14651 * returns setof that column's type; otherwise return setof record.
14654 TableFuncTypeName(List *columns)
14658 if (list_length(columns) == 1)
14660 FunctionParameter *p = (FunctionParameter *) linitial(columns);
14662 result = (TypeName *) copyObject(p->argType);
14665 result = SystemTypeName("record");
14667 result->setof = true;
14673 * Convert a list of (dotted) names to a RangeVar (like
14674 * makeRangeVarFromNameList, but with position support). The
14675 * "AnyName" refers to the any_name production in the grammar.
14678 makeRangeVarFromAnyName(List *names, int position, core_yyscan_t yyscanner)
14680 RangeVar *r = makeNode(RangeVar);
14682 switch (list_length(names))
14685 r->catalogname = NULL;
14686 r->schemaname = NULL;
14687 r->relname = strVal(linitial(names));
14690 r->catalogname = NULL;
14691 r->schemaname = strVal(linitial(names));
14692 r->relname = strVal(lsecond(names));
14695 r->catalogname = strVal(linitial(names));
14696 r->schemaname = strVal(lsecond(names));
14697 r->relname = strVal(lthird(names));
14701 (errcode(ERRCODE_SYNTAX_ERROR),
14702 errmsg("improper qualified name (too many dotted names): %s",
14703 NameListToString(names)),
14704 parser_errposition(position)));
14708 r->relpersistence = RELPERSISTENCE_PERMANENT;
14709 r->location = position;
14714 /* Separate Constraint nodes from COLLATE clauses in a ColQualList */
14716 SplitColQualList(List *qualList,
14717 List **constraintList, CollateClause **collClause,
14718 core_yyscan_t yyscanner)
14724 *collClause = NULL;
14726 for (cell = list_head(qualList); cell; cell = next)
14728 Node *n = (Node *) lfirst(cell);
14730 next = lnext(cell);
14731 if (IsA(n, Constraint))
14733 /* keep it in list */
14737 if (IsA(n, CollateClause))
14739 CollateClause *c = (CollateClause *) n;
14743 (errcode(ERRCODE_SYNTAX_ERROR),
14744 errmsg("multiple COLLATE clauses not allowed"),
14745 parser_errposition(c->location)));
14749 elog(ERROR, "unexpected node type %d", (int) n->type);
14750 /* remove non-Constraint nodes from qualList */
14751 qualList = list_delete_cell(qualList, cell, prev);
14753 *constraintList = qualList;
14757 * Process result of ConstraintAttributeSpec, and set appropriate bool flags
14758 * in the output command node. Pass NULL for any flags the particular
14759 * command doesn't support.
14762 processCASbits(int cas_bits, int location, const char *constrType,
14763 bool *deferrable, bool *initdeferred, bool *not_valid,
14764 bool *no_inherit, core_yyscan_t yyscanner)
14768 *deferrable = false;
14770 *initdeferred = false;
14772 *not_valid = false;
14774 if (cas_bits & (CAS_DEFERRABLE | CAS_INITIALLY_DEFERRED))
14777 *deferrable = true;
14780 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
14781 /* translator: %s is CHECK, UNIQUE, or similar */
14782 errmsg("%s constraints cannot be marked DEFERRABLE",
14784 parser_errposition(location)));
14787 if (cas_bits & CAS_INITIALLY_DEFERRED)
14790 *initdeferred = true;
14793 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
14794 /* translator: %s is CHECK, UNIQUE, or similar */
14795 errmsg("%s constraints cannot be marked DEFERRABLE",
14797 parser_errposition(location)));
14800 if (cas_bits & CAS_NOT_VALID)
14806 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
14807 /* translator: %s is CHECK, UNIQUE, or similar */
14808 errmsg("%s constraints cannot be marked NOT VALID",
14810 parser_errposition(location)));
14813 if (cas_bits & CAS_NO_INHERIT)
14816 *no_inherit = true;
14819 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
14820 /* translator: %s is CHECK, UNIQUE, or similar */
14821 errmsg("%s constraints cannot be marked NO INHERIT",
14823 parser_errposition(location)));
14828 * Recursive view transformation
14832 * CREATE RECURSIVE VIEW relname (aliases) AS query
14836 * CREATE VIEW relname (aliases) AS
14837 * WITH RECURSIVE relname (aliases) AS (query)
14838 * SELECT aliases FROM relname
14840 * Actually, just the WITH ... part, which is then inserted into the original
14841 * view definition as the query.
14845 makeRecursiveViewSelect(char *relname, List *aliases, Node *query)
14847 SelectStmt *s = makeNode(SelectStmt);
14848 WithClause *w = makeNode(WithClause);
14849 CommonTableExpr *cte = makeNode(CommonTableExpr);
14853 /* create common table expression */
14854 cte->ctename = relname;
14855 cte->aliascolnames = aliases;
14856 cte->ctequery = query;
14857 cte->location = -1;
14859 /* create WITH clause and attach CTE */
14860 w->recursive = true;
14861 w->ctes = list_make1(cte);
14864 /* create target list for the new SELECT from the alias list of the
14865 * recursive view specification */
14866 foreach (lc, aliases)
14868 ResTarget *rt = makeNode(ResTarget);
14871 rt->indirection = NIL;
14872 rt->val = makeColumnRef(strVal(lfirst(lc)), NIL, -1, 0);
14875 tl = lappend(tl, rt);
14878 /* create new SELECT combining WITH clause, target list, and fake FROM
14881 s->targetList = tl;
14882 s->fromClause = list_make1(makeRangeVar(NULL, relname, -1));
14888 * Initialize to parse one query string
14891 parser_init(base_yy_extra_type *yyext)
14893 yyext->parsetree = NIL; /* in case grammar forgets to set it */
14897 * Must undefine this stuff before including scan.c, since it has different
14898 * definitions for these macros.