4 /*-------------------------------------------------------------------------
7 * POSTGRESQL BISON rules/actions
9 * Portions Copyright (c) 1996-2011, 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.
24 * SQL92-specific syntax is separated from plain SQL/Postgres syntax
25 * to help isolate the non-extensible portions of the parser.
27 * In general, nothing in this file should initiate database accesses
28 * nor depend on changeable state (such as SET variables). If you do
29 * database accesses, your code will fail when we have aborted the
30 * current transaction and are just parsing commands to find the next
31 * ROLLBACK or COMMIT. If you make use of SET variables, then you
32 * will do the wrong thing in multi-query strings like this:
33 * SET SQL_inheritance TO off; SELECT * FROM foo;
34 * because the entire string is parsed by gram.y before the SET gets
35 * executed. Anything that depends on the database or changeable state
36 * should be handled during parse analysis so that it happens at the
37 * right time not the wrong time. The handling of SQL_inheritance is
41 * If you use a list, make sure the datum is a node so that the printing
44 * Sometimes we assign constants to makeStrings. Make sure we don't free
47 *-------------------------------------------------------------------------
54 #include "catalog/index.h"
55 #include "catalog/namespace.h"
56 #include "catalog/pg_trigger.h"
57 #include "commands/defrem.h"
58 #include "nodes/makefuncs.h"
59 #include "nodes/nodeFuncs.h"
60 #include "parser/gramparse.h"
61 #include "parser/parser.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"
69 /* Location tracking support --- simpler than bison's default */
70 #define YYLLOC_DEFAULT(Current, Rhs, N) \
73 (Current) = (Rhs)[1]; \
75 (Current) = (Rhs)[0]; \
79 * Bison doesn't allocate anything that needs to live across parser calls,
80 * so we can easily have it use palloc instead of malloc. This prevents
81 * memory leaks if we error out during parsing. Note this only works with
82 * bison >= 2.0. However, in bison 1.875 the default is to use alloca()
83 * if possible, so there's not really much problem anyhow, at least if
84 * you're building with gcc.
86 #define YYMALLOC palloc
89 /* Private struct for the result of privilege_target production */
90 typedef struct PrivTarget
92 GrantTargetType targtype;
93 GrantObjectType objtype;
98 #define parser_yyerror(msg) scanner_yyerror(msg, yyscanner)
99 #define parser_errposition(pos) scanner_errposition(pos, yyscanner)
101 static void base_yyerror(YYLTYPE *yylloc, core_yyscan_t yyscanner,
103 static Node *makeColumnRef(char *colname, List *indirection,
104 int location, core_yyscan_t yyscanner);
105 static Node *makeTypeCast(Node *arg, TypeName *typename, int location);
106 static Node *makeStringConst(char *str, int location);
107 static Node *makeStringConstCast(char *str, int location, TypeName *typename);
108 static Node *makeIntConst(int val, int location);
109 static Node *makeFloatConst(char *str, int location);
110 static Node *makeBitStringConst(char *str, int location);
111 static Node *makeNullAConst(int location);
112 static Node *makeAConst(Value *v, int location);
113 static Node *makeBoolAConst(bool state, int location);
114 static FuncCall *makeOverlaps(List *largs, List *rargs,
115 int location, core_yyscan_t yyscanner);
116 static void check_qualified_name(List *names, core_yyscan_t yyscanner);
117 static List *check_func_name(List *names, core_yyscan_t yyscanner);
118 static List *check_indirection(List *indirection, core_yyscan_t yyscanner);
119 static List *extractArgTypes(List *parameters);
120 static SelectStmt *findLeftmostSelect(SelectStmt *node);
121 static void insertSelectOptions(SelectStmt *stmt,
122 List *sortClause, List *lockingClause,
123 Node *limitOffset, Node *limitCount,
124 WithClause *withClause,
125 core_yyscan_t yyscanner);
126 static Node *makeSetOp(SetOperation op, bool all, Node *larg, Node *rarg);
127 static Node *doNegate(Node *n, int location);
128 static void doNegateFloat(Value *v);
129 static Node *makeAArrayExpr(List *elements, int location);
130 static Node *makeXmlExpr(XmlExprOp op, char *name, List *named_args,
131 List *args, int location);
132 static List *mergeTableFuncParameters(List *func_args, List *columns);
133 static TypeName *TableFuncTypeName(List *columns);
134 static RangeVar *makeRangeVarFromAnyName(List *names, int position, core_yyscan_t yyscanner);
135 static void SplitColQualList(List *qualList,
136 List **constraintList, CollateClause **collClause,
137 core_yyscan_t yyscanner);
143 %name-prefix="base_yy"
146 %parse-param {core_yyscan_t yyscanner}
147 %lex-param {core_yyscan_t yyscanner}
151 core_YYSTYPE core_yystype;
152 /* these fields must match core_YYSTYPE: */
160 DropBehavior dbehavior;
161 OnCommitAction oncommit;
167 FunctionParameter *fun_param;
168 FunctionParameterMode fun_param_mode;
169 FuncWithArgs *funwithargs;
181 struct PrivTarget *privtarget;
182 AccessPriv *accesspriv;
184 VariableSetStmt *vsetstmt;
187 %type <node> stmt schema_stmt
188 AlterDatabaseStmt AlterDatabaseSetStmt AlterDomainStmt AlterEnumStmt
189 AlterFdwStmt AlterForeignServerStmt AlterGroupStmt
190 AlterObjectSchemaStmt AlterOwnerStmt AlterSeqStmt AlterTableStmt
191 AlterExtensionStmt AlterExtensionContentsStmt AlterForeignTableStmt
192 AlterCompositeTypeStmt AlterUserStmt AlterUserMappingStmt AlterUserSetStmt
193 AlterRoleStmt AlterRoleSetStmt
194 AlterDefaultPrivilegesStmt DefACLAction
195 AnalyzeStmt ClosePortalStmt ClusterStmt CommentStmt
196 ConstraintsSetStmt CopyStmt CreateAsStmt CreateCastStmt
197 CreateDomainStmt CreateExtensionStmt CreateGroupStmt CreateOpClassStmt
198 CreateOpFamilyStmt AlterOpFamilyStmt CreatePLangStmt
199 CreateSchemaStmt CreateSeqStmt CreateStmt CreateTableSpaceStmt
200 CreateFdwStmt CreateForeignServerStmt CreateForeignTableStmt
201 CreateAssertStmt CreateTrigStmt
202 CreateUserStmt CreateUserMappingStmt CreateRoleStmt
203 CreatedbStmt DeclareCursorStmt DefineStmt DeleteStmt DiscardStmt DoStmt
204 DropGroupStmt DropOpClassStmt DropOpFamilyStmt DropPLangStmt DropStmt
205 DropAssertStmt DropTrigStmt DropRuleStmt DropCastStmt DropRoleStmt
206 DropUserStmt DropdbStmt DropTableSpaceStmt DropFdwStmt
207 DropForeignServerStmt DropUserMappingStmt ExplainStmt FetchStmt
208 GrantStmt GrantRoleStmt IndexStmt InsertStmt ListenStmt LoadStmt
209 LockStmt NotifyStmt ExplainableStmt PreparableStmt
210 CreateFunctionStmt AlterFunctionStmt ReindexStmt RemoveAggrStmt
211 RemoveFuncStmt RemoveOperStmt RenameStmt RevokeStmt RevokeRoleStmt
212 RuleActionStmt RuleActionStmtOrEmpty RuleStmt
213 SecLabelStmt SelectStmt TransactionStmt TruncateStmt
214 UnlistenStmt UpdateStmt VacuumStmt
215 VariableResetStmt VariableSetStmt VariableShowStmt
216 ViewStmt CheckPointStmt CreateConversionStmt
217 DeallocateStmt PrepareStmt ExecuteStmt
218 DropOwnedStmt ReassignOwnedStmt
219 AlterTSConfigurationStmt AlterTSDictionaryStmt
221 %type <node> select_no_parens select_with_parens select_clause
222 simple_select values_clause
224 %type <node> alter_column_default opclass_item opclass_drop alter_using
225 %type <ival> add_drop opt_asc_desc opt_nulls_order
227 %type <node> alter_table_cmd alter_type_cmd opt_collate_clause
228 %type <list> alter_table_cmds alter_type_cmds
230 %type <dbehavior> opt_drop_behavior
232 %type <list> createdb_opt_list alterdb_opt_list copy_opt_list
233 transaction_mode_list
234 create_extension_opt_list alter_extension_opt_list
235 %type <defelt> createdb_opt_item alterdb_opt_item copy_opt_item
236 transaction_mode_item
237 create_extension_opt_item alter_extension_opt_item
239 %type <ival> opt_lock lock_type cast_context
240 %type <ival> vacuum_option_list vacuum_option_elem
241 %type <boolean> opt_force opt_or_replace
242 opt_grant_grant_option opt_grant_admin_option
243 opt_nowait opt_if_exists opt_with_data
245 %type <list> OptRoleList AlterOptRoleList
246 %type <defelt> CreateOptRoleElem AlterOptRoleElem
249 %type <str> foreign_server_version opt_foreign_server_version
250 %type <str> auth_ident
251 %type <str> opt_in_database
253 %type <str> OptSchemaName
254 %type <list> OptSchemaEltList
256 %type <boolean> TriggerForSpec TriggerForType
257 %type <ival> TriggerActionTime
258 %type <list> TriggerEvents TriggerOneEvent
259 %type <value> TriggerFuncArg
260 %type <node> TriggerWhen
262 %type <str> copy_file_name
263 database_name access_method_clause access_method attr_name
264 name cursor_name file_name
265 index_name opt_index_name cluster_index_specification
267 %type <list> func_name handler_name qual_Op qual_all_Op subquery_Op
268 opt_class opt_inline_handler opt_validator validator_clause
271 %type <range> qualified_name OptConstrFromTable
273 %type <str> all_Op MathOp
275 %type <str> iso_level opt_encoding
277 %type <list> grantee_list
278 %type <accesspriv> privilege
279 %type <list> privileges privilege_list
280 %type <privtarget> privilege_target
281 %type <funwithargs> function_with_argtypes
282 %type <list> function_with_argtypes_list
283 %type <ival> defacl_privilege_target
284 %type <defelt> DefACLOption
285 %type <list> DefACLOptionList
287 %type <list> stmtblock stmtmulti
288 OptTableElementList TableElementList OptInherit definition
289 OptTypedTableElementList TypedTableElementList
290 OptForeignTableElementList ForeignTableElementList
291 reloptions opt_reloptions
292 OptWith opt_distinct opt_definition func_args func_args_list
293 func_args_with_defaults func_args_with_defaults_list
294 func_as createfunc_opt_list alterfunc_opt_list
295 aggr_args old_aggr_definition old_aggr_list
296 oper_argtypes RuleActionList RuleActionMulti
297 opt_column_list columnList opt_name_list
298 sort_clause opt_sort_clause sortby_list index_params
299 name_list from_clause from_list opt_array_bounds
300 qualified_name_list any_name any_name_list
301 any_operator expr_list attrs
302 target_list insert_column_list set_target_list
303 set_clause_list set_clause multiple_set_clause
304 ctext_expr_list ctext_row def_list indirection opt_indirection
305 reloption_list group_clause TriggerFuncArgs select_limit
306 opt_select_limit opclass_item_list opclass_drop_list
307 opclass_purpose opt_opfamily transaction_mode_list_or_empty
308 OptTableFuncElementList TableFuncElementList opt_type_modifiers
310 execute_param_clause using_clause returning_clause
311 opt_enum_val_list enum_val_list table_func_column_list
312 create_generic_options alter_generic_options
313 relation_expr_list dostmt_opt_list
315 %type <list> opt_fdw_options fdw_options
316 %type <defelt> fdw_option
318 %type <range> OptTempTableName
319 %type <into> into_clause create_as_target
321 %type <defelt> createfunc_opt_item common_func_opt_item dostmt_opt_item
322 %type <fun_param> func_arg func_arg_with_default table_func_column
323 %type <fun_param_mode> arg_class
324 %type <typnam> func_return func_type
326 %type <boolean> opt_trusted opt_restart_seqs
328 %type <oncommit> OnCommitOption
330 %type <node> for_locking_item
331 %type <list> for_locking_clause opt_for_locking_clause for_locking_items
332 %type <list> locked_rels_list
333 %type <boolean> opt_all
335 %type <node> join_outer join_qual
336 %type <jtype> join_type
338 %type <list> extract_list overlay_list position_list
339 %type <list> substr_list trim_list
340 %type <list> opt_interval interval_second
341 %type <node> overlay_placing substr_from substr_for
343 %type <boolean> opt_instead
344 %type <boolean> opt_unique opt_concurrently opt_verbose opt_full
345 %type <boolean> opt_freeze opt_default opt_recheck
346 %type <defelt> opt_binary opt_oids copy_delimiter
348 %type <boolean> copy_from
350 %type <ival> opt_column event cursor_options opt_hold opt_set_data
351 %type <objtype> reindex_type drop_type comment_type security_label_type
353 %type <node> fetch_args limit_clause select_limit_value
354 offset_clause select_offset_value
355 select_offset_value2 opt_select_fetch_first_value
356 %type <ival> row_or_rows first_or_next
358 %type <list> OptSeqOptList SeqOptList
359 %type <defelt> SeqOptElem
361 %type <istmt> insert_rest
363 %type <vsetstmt> set_rest SetResetClause
365 %type <node> TableElement TypedTableElement ConstraintElem TableFuncElement
367 %type <node> columnDef columnOptions
368 %type <defelt> def_elem reloption_elem old_aggr_elem
369 %type <node> def_arg columnElem where_clause where_or_current_clause
370 a_expr b_expr c_expr func_expr AexprConst indirection_el
371 columnref in_expr having_clause func_table array_expr
373 %type <list> ExclusionConstraintList ExclusionConstraintElem
374 %type <list> func_arg_list
375 %type <node> func_arg_expr
376 %type <list> row type_list array_expr_list
377 %type <node> case_expr case_arg when_clause case_default
378 %type <list> when_clause_list
379 %type <ival> sub_type
380 %type <list> OptCreateAs CreateAsList
381 %type <node> CreateAsElement ctext_expr
382 %type <value> NumericOnly
383 %type <list> NumericOnly_list
384 %type <alias> alias_clause
385 %type <sortby> sortby
386 %type <ielem> index_elem
387 %type <node> table_ref
388 %type <jexpr> joined_table
389 %type <range> relation_expr
390 %type <range> relation_expr_opt_alias
391 %type <target> target_el single_set_clause set_target insert_column_item
393 %type <str> generic_option_name
394 %type <node> generic_option_arg
395 %type <defelt> generic_option_elem alter_generic_option_elem
396 %type <list> generic_option_list alter_generic_option_list
397 %type <str> explain_option_name
398 %type <node> explain_option_arg
399 %type <defelt> explain_option_elem
400 %type <list> explain_option_list
401 %type <node> copy_generic_opt_arg copy_generic_opt_arg_list_item
402 %type <defelt> copy_generic_opt_elem
403 %type <list> copy_generic_opt_list copy_generic_opt_arg_list
404 %type <list> copy_options
406 %type <typnam> Typename SimpleTypename ConstTypename
407 GenericType Numeric opt_float
408 Character ConstCharacter
409 CharacterWithLength CharacterWithoutLength
410 ConstDatetime ConstInterval
411 Bit ConstBit BitWithLength BitWithoutLength
412 %type <str> character
413 %type <str> extract_arg
414 %type <str> opt_charset
415 %type <boolean> opt_varying opt_timezone
417 %type <ival> Iconst SignedIconst
418 %type <str> Sconst comment_text notify_payload
419 %type <str> RoleId opt_granted_by opt_boolean_or_string ColId_or_Sconst
420 %type <list> var_list
421 %type <str> ColId ColLabel var_name type_function_name param_name
422 %type <node> var_value zone_value
424 %type <keyword> unreserved_keyword type_func_name_keyword
425 %type <keyword> col_name_keyword reserved_keyword
427 %type <node> TableConstraint TableLikeClause
428 %type <ival> TableLikeOptionList TableLikeOption
429 %type <list> ColQualList
430 %type <node> ColConstraint ColConstraintElem ConstraintAttr
431 %type <ival> key_actions key_delete key_match key_update key_action
432 %type <ival> ConstraintAttributeSpec ConstraintDeferrabilitySpec
434 %type <str> ExistingIndex
436 %type <list> constraints_set_list
437 %type <boolean> constraints_set_mode
438 %type <str> OptTableSpace OptConsTableSpace OptTableSpaceOwner
439 %type <list> opt_check_option
441 %type <str> opt_provider security_label
443 %type <target> xml_attribute_el
444 %type <list> xml_attribute_list xml_attributes
445 %type <node> xml_root_version opt_xml_root_standalone
446 %type <node> xmlexists_argument
447 %type <ival> document_or_content
448 %type <boolean> xml_whitespace_option
450 %type <node> common_table_expr
451 %type <with> with_clause opt_with_clause
452 %type <list> cte_list
454 %type <list> window_clause window_definition_list opt_partition_clause
455 %type <windef> window_definition over_clause window_specification
456 opt_frame_clause frame_extent frame_bound
457 %type <str> opt_existing_window_name
461 * Non-keyword token types. These are hard-wired into the "flex" lexer.
462 * They must be listed first so that their numeric codes do not depend on
463 * the set of keywords. PL/pgsql depends on this so that it can share the
464 * same lexer. If you add/change tokens here, fix PL/pgsql to match!
466 * DOT_DOT is unused in the core SQL grammar, and so will always provoke
467 * parse errors. It is needed by PL/pgsql.
469 %token <str> IDENT FCONST SCONST BCONST XCONST Op
470 %token <ival> ICONST PARAM
471 %token TYPECAST DOT_DOT COLON_EQUALS
474 * If you want to make any keyword changes, update the keyword table in
475 * src/include/parser/kwlist.h and add new keywords to the appropriate one
476 * of the reserved-or-not-so-reserved keyword lists, below; search
477 * this file for "Keyword category lists".
480 /* ordinary key words in alphabetical order */
481 %token <keyword> ABORT_P ABSOLUTE_P ACCESS ACTION ADD_P ADMIN AFTER
482 AGGREGATE ALL ALSO ALTER ALWAYS ANALYSE ANALYZE AND ANY ARRAY AS ASC
483 ASSERTION ASSIGNMENT ASYMMETRIC AT ATTRIBUTE AUTHORIZATION
485 BACKWARD BEFORE BEGIN_P BETWEEN BIGINT BINARY BIT
488 CACHE CALLED CASCADE CASCADED CASE CAST CATALOG_P CHAIN CHAR_P
489 CHARACTER CHARACTERISTICS CHECK CHECKPOINT CLASS CLOSE
490 CLUSTER COALESCE COLLATE COLLATION COLUMN COMMENT COMMENTS COMMIT
491 COMMITTED CONCURRENTLY CONFIGURATION CONNECTION CONSTRAINT CONSTRAINTS
492 CONTENT_P CONTINUE_P CONVERSION_P COPY COST CREATE
494 CURRENT_CATALOG CURRENT_DATE CURRENT_ROLE CURRENT_SCHEMA
495 CURRENT_TIME CURRENT_TIMESTAMP CURRENT_USER CURSOR CYCLE
497 DATA_P DATABASE DAY_P DEALLOCATE DEC DECIMAL_P DECLARE DEFAULT DEFAULTS
498 DEFERRABLE DEFERRED DEFINER DELETE_P DELIMITER DELIMITERS DESC
499 DICTIONARY DISABLE_P DISCARD DISTINCT DO DOCUMENT_P DOMAIN_P DOUBLE_P DROP
501 EACH ELSE ENABLE_P ENCODING ENCRYPTED END_P ENUM_P ESCAPE EXCEPT
502 EXCLUDE EXCLUDING EXCLUSIVE EXECUTE EXISTS EXPLAIN
503 EXTENSION EXTERNAL EXTRACT
505 FALSE_P FAMILY FETCH FIRST_P FLOAT_P FOLLOWING FOR FORCE FOREIGN FORWARD
506 FREEZE FROM FULL FUNCTION FUNCTIONS
508 GLOBAL GRANT GRANTED GREATEST GROUP_P
510 HANDLER HAVING HEADER_P HOLD HOUR_P
512 IDENTITY_P IF_P ILIKE IMMEDIATE IMMUTABLE IMPLICIT_P IN_P
513 INCLUDING INCREMENT INDEX INDEXES INHERIT INHERITS INITIALLY INLINE_P
514 INNER_P INOUT INPUT_P INSENSITIVE INSERT INSTEAD INT_P INTEGER
515 INTERSECT INTERVAL INTO INVOKER IS ISNULL ISOLATION
521 LABEL LANGUAGE LARGE_P LAST_P LC_COLLATE_P LC_CTYPE_P LEADING
522 LEAST LEFT LEVEL LIKE LIMIT LISTEN LOAD LOCAL LOCALTIME LOCALTIMESTAMP
525 MAPPING MATCH MAXVALUE MINUTE_P MINVALUE MODE MONTH_P MOVE
527 NAME_P NAMES NATIONAL NATURAL NCHAR NEXT NO NONE
528 NOT NOTHING NOTIFY NOTNULL NOWAIT NULL_P NULLIF
531 OBJECT_P OF OFF OFFSET OIDS ON ONLY OPERATOR OPTION OPTIONS OR
532 ORDER OUT_P OUTER_P OVER OVERLAPS OVERLAY OWNED OWNER
534 PARSER PARTIAL PARTITION PASSING PASSWORD PLACING PLANS POSITION
535 PRECEDING PRECISION PRESERVE PREPARE PREPARED PRIMARY
536 PRIOR PRIVILEGES PROCEDURAL PROCEDURE
540 RANGE READ REAL REASSIGN RECHECK RECURSIVE REF REFERENCES REINDEX
541 RELATIVE_P RELEASE RENAME REPEATABLE REPLACE REPLICA
542 RESET RESTART RESTRICT RETURNING RETURNS REVOKE RIGHT ROLE ROLLBACK
545 SAVEPOINT SCHEMA SCROLL SEARCH SECOND_P SECURITY SELECT SEQUENCE SEQUENCES
546 SERIALIZABLE SERVER SESSION SESSION_USER SET SETOF SHARE
547 SHOW SIMILAR SIMPLE SMALLINT SOME STABLE STANDALONE_P START STATEMENT
548 STATISTICS STDIN STDOUT STORAGE STRICT_P STRIP_P SUBSTRING
549 SYMMETRIC SYSID SYSTEM_P
551 TABLE TABLES TABLESPACE TEMP TEMPLATE TEMPORARY TEXT_P THEN TIME TIMESTAMP
552 TO TRAILING TRANSACTION TREAT TRIGGER TRIM TRUE_P
553 TRUNCATE TRUSTED TYPE_P
555 UNBOUNDED UNCOMMITTED UNENCRYPTED UNION UNIQUE UNKNOWN UNLISTEN UNLOGGED
556 UNTIL UPDATE USER USING
558 VACUUM VALID VALIDATE VALIDATOR VALUE_P VALUES VARCHAR VARIADIC VARYING
559 VERBOSE VERSION_P VIEW VOLATILE
561 WHEN WHERE WHITESPACE_P WINDOW WITH WITHOUT WORK WRAPPER WRITE
563 XML_P XMLATTRIBUTES XMLCONCAT XMLELEMENT XMLEXISTS XMLFOREST XMLPARSE
564 XMLPI XMLROOT XMLSERIALIZE
571 * The grammar thinks these are keywords, but they are not in the kwlist.h
572 * list and so can never be entered directly. The filter in parser.c
573 * creates these tokens when required.
575 %token NULLS_FIRST NULLS_LAST WITH_TIME
578 /* Precedence: lowest to highest */
579 %nonassoc SET /* see relation_expr_opt_alias */
587 %nonassoc LIKE ILIKE SIMILAR
592 %left POSTFIXOP /* dummy for postfix Op rules */
594 * To support target_el without AS, we must give IDENT an explicit priority
595 * between POSTFIXOP and Op. We can safely assign the same priority to
596 * various unreserved keywords as needed to resolve ambiguities (this can't
597 * have any bad effects since obviously the keywords will still behave the
598 * same as if they weren't keywords). We need to do this for PARTITION,
599 * RANGE, ROWS to support opt_existing_window_name; and for RANGE, ROWS
600 * so that they can follow a_expr without creating postfix-operator problems;
601 * and for NULL so that it can follow b_expr in ColQualList without creating
602 * postfix-operator problems.
604 * The frame_bound productions UNBOUNDED PRECEDING and UNBOUNDED FOLLOWING
605 * are even messier: since UNBOUNDED is an unreserved keyword (per spec!),
606 * there is no principled way to distinguish these from the productions
607 * a_expr PRECEDING/FOLLOWING. We hack this up by giving UNBOUNDED slightly
608 * lower precedence than PRECEDING and FOLLOWING. At present this doesn't
609 * appear to cause UNBOUNDED to be treated differently from other unreserved
610 * keywords anywhere else in the grammar, but it's definitely risky. We can
611 * blame any funny behavior of UNBOUNDED on the SQL standard, though.
613 %nonassoc UNBOUNDED /* ideally should have same precedence as IDENT */
614 %nonassoc IDENT NULL_P PARTITION RANGE ROWS PRECEDING FOLLOWING
615 %left Op OPERATOR /* multi-character ops and user-defined operators */
618 %nonassoc IS /* sets precedence for IS NULL, etc */
622 /* Unary Operators */
623 %left AT /* sets precedence for AT TIME ZONE */
631 * These might seem to be low-precedence, but actually they are not part
632 * of the arithmetic hierarchy at all in their use as JOIN operators.
633 * We make them high-precedence to support their use as function names.
634 * They wouldn't be given a precedence at all, were it not that we need
635 * left-associativity among the JOIN rules themselves.
637 %left JOIN CROSS LEFT FULL RIGHT INNER_P NATURAL
638 /* kluge to keep xml_whitespace_option from causing shift/reduce conflicts */
639 %right PRESERVE STRIP_P
644 * The target production for the whole parse.
648 pg_yyget_extra(yyscanner)->parsetree = $1;
652 /* the thrashing around here is to discard "empty" statements... */
653 stmtmulti: stmtmulti ';' stmt
656 $$ = lappend($1, $3);
671 | AlterDatabaseSetStmt
672 | AlterDefaultPrivilegesStmt
676 | AlterExtensionContentsStmt
678 | AlterForeignServerStmt
679 | AlterForeignTableStmt
682 | AlterObjectSchemaStmt
686 | AlterCompositeTypeStmt
689 | AlterTSConfigurationStmt
690 | AlterTSDictionaryStmt
691 | AlterUserMappingStmt
704 | CreateConversionStmt
706 | CreateExtensionStmt
708 | CreateForeignServerStmt
709 | CreateForeignTableStmt
719 | CreateTableSpaceStmt
723 | CreateUserMappingStmt
734 | DropForeignServerStmt
746 | DropUserMappingStmt
784 /*****************************************************************************
786 * Create a new Postgres DBMS role
788 *****************************************************************************/
791 CREATE ROLE RoleId opt_with OptRoleList
793 CreateRoleStmt *n = makeNode(CreateRoleStmt);
794 n->stmt_type = ROLESTMT_ROLE;
807 * Options for CREATE ROLE and ALTER ROLE (also used by CREATE/ALTER USER
808 * for backwards compatibility). Note: the only option required by SQL99
809 * is "WITH ADMIN name".
812 OptRoleList CreateOptRoleElem { $$ = lappend($1, $2); }
813 | /* EMPTY */ { $$ = NIL; }
817 AlterOptRoleList AlterOptRoleElem { $$ = lappend($1, $2); }
818 | /* EMPTY */ { $$ = NIL; }
824 $$ = makeDefElem("password",
825 (Node *)makeString($2));
829 $$ = makeDefElem("password", NULL);
831 | ENCRYPTED PASSWORD Sconst
833 $$ = makeDefElem("encryptedPassword",
834 (Node *)makeString($3));
836 | UNENCRYPTED PASSWORD Sconst
838 $$ = makeDefElem("unencryptedPassword",
839 (Node *)makeString($3));
843 $$ = makeDefElem("inherit", (Node *)makeInteger(TRUE));
845 | CONNECTION LIMIT SignedIconst
847 $$ = makeDefElem("connectionlimit", (Node *)makeInteger($3));
851 $$ = makeDefElem("validUntil", (Node *)makeString($3));
853 /* Supported but not documented for roles, for use by ALTER GROUP. */
856 $$ = makeDefElem("rolemembers", (Node *)$2);
861 * We handle identifiers that aren't parser keywords with
862 * the following special-case codes, to avoid bloating the
863 * size of the main parser.
865 if (strcmp($1, "superuser") == 0)
866 $$ = makeDefElem("superuser", (Node *)makeInteger(TRUE));
867 else if (strcmp($1, "nosuperuser") == 0)
868 $$ = makeDefElem("superuser", (Node *)makeInteger(FALSE));
869 else if (strcmp($1, "createuser") == 0)
871 /* For backwards compatibility, synonym for SUPERUSER */
872 $$ = makeDefElem("superuser", (Node *)makeInteger(TRUE));
874 else if (strcmp($1, "nocreateuser") == 0)
876 /* For backwards compatibility, synonym for SUPERUSER */
877 $$ = makeDefElem("superuser", (Node *)makeInteger(FALSE));
879 else if (strcmp($1, "createrole") == 0)
880 $$ = makeDefElem("createrole", (Node *)makeInteger(TRUE));
881 else if (strcmp($1, "nocreaterole") == 0)
882 $$ = makeDefElem("createrole", (Node *)makeInteger(FALSE));
883 else if (strcmp($1, "replication") == 0)
884 $$ = makeDefElem("isreplication", (Node *)makeInteger(TRUE));
885 else if (strcmp($1, "noreplication") == 0)
886 $$ = makeDefElem("isreplication", (Node *)makeInteger(FALSE));
887 else if (strcmp($1, "createdb") == 0)
888 $$ = makeDefElem("createdb", (Node *)makeInteger(TRUE));
889 else if (strcmp($1, "nocreatedb") == 0)
890 $$ = makeDefElem("createdb", (Node *)makeInteger(FALSE));
891 else if (strcmp($1, "login") == 0)
892 $$ = makeDefElem("canlogin", (Node *)makeInteger(TRUE));
893 else if (strcmp($1, "nologin") == 0)
894 $$ = makeDefElem("canlogin", (Node *)makeInteger(FALSE));
895 else if (strcmp($1, "noinherit") == 0)
898 * Note that INHERIT is a keyword, so it's handled by main parser, but
899 * NOINHERIT is handled here.
901 $$ = makeDefElem("inherit", (Node *)makeInteger(FALSE));
905 (errcode(ERRCODE_SYNTAX_ERROR),
906 errmsg("unrecognized role option \"%s\"", $1),
907 parser_errposition(@1)));
912 AlterOptRoleElem { $$ = $1; }
913 /* The following are not supported by ALTER ROLE/USER/GROUP */
916 $$ = makeDefElem("sysid", (Node *)makeInteger($2));
920 $$ = makeDefElem("adminmembers", (Node *)$2);
924 $$ = makeDefElem("rolemembers", (Node *)$2);
926 | IN_P ROLE name_list
928 $$ = makeDefElem("addroleto", (Node *)$3);
930 | IN_P GROUP_P name_list
932 $$ = makeDefElem("addroleto", (Node *)$3);
937 /*****************************************************************************
939 * Create a new Postgres DBMS user (role with implied login ability)
941 *****************************************************************************/
944 CREATE USER RoleId opt_with OptRoleList
946 CreateRoleStmt *n = makeNode(CreateRoleStmt);
947 n->stmt_type = ROLESTMT_USER;
955 /*****************************************************************************
957 * Alter a postgresql DBMS role
959 *****************************************************************************/
962 ALTER ROLE RoleId opt_with AlterOptRoleList
964 AlterRoleStmt *n = makeNode(AlterRoleStmt);
966 n->action = +1; /* add, if there are members */
973 /* EMPTY */ { $$ = NULL; }
974 | IN_P DATABASE database_name { $$ = $3; }
978 ALTER ROLE RoleId opt_in_database SetResetClause
980 AlterRoleSetStmt *n = makeNode(AlterRoleSetStmt);
989 /*****************************************************************************
991 * Alter a postgresql DBMS user
993 *****************************************************************************/
996 ALTER USER RoleId opt_with AlterOptRoleList
998 AlterRoleStmt *n = makeNode(AlterRoleStmt);
1000 n->action = +1; /* add, if there are members */
1008 ALTER USER RoleId SetResetClause
1010 AlterRoleSetStmt *n = makeNode(AlterRoleSetStmt);
1019 /*****************************************************************************
1021 * Drop a postgresql DBMS role
1023 * XXX Ideally this would have CASCADE/RESTRICT options, but since a role
1024 * might own objects in multiple databases, there is presently no way to
1025 * implement either cascading or restricting. Caveat DBA.
1026 *****************************************************************************/
1031 DropRoleStmt *n = makeNode(DropRoleStmt);
1032 n->missing_ok = FALSE;
1036 | DROP ROLE IF_P EXISTS name_list
1038 DropRoleStmt *n = makeNode(DropRoleStmt);
1039 n->missing_ok = TRUE;
1045 /*****************************************************************************
1047 * Drop a postgresql DBMS user
1049 * XXX Ideally this would have CASCADE/RESTRICT options, but since a user
1050 * might own objects in multiple databases, there is presently no way to
1051 * implement either cascading or restricting. Caveat DBA.
1052 *****************************************************************************/
1057 DropRoleStmt *n = makeNode(DropRoleStmt);
1058 n->missing_ok = FALSE;
1062 | DROP USER IF_P EXISTS name_list
1064 DropRoleStmt *n = makeNode(DropRoleStmt);
1066 n->missing_ok = TRUE;
1072 /*****************************************************************************
1074 * Create a postgresql group (role without login ability)
1076 *****************************************************************************/
1079 CREATE GROUP_P RoleId opt_with OptRoleList
1081 CreateRoleStmt *n = makeNode(CreateRoleStmt);
1082 n->stmt_type = ROLESTMT_GROUP;
1090 /*****************************************************************************
1092 * Alter a postgresql group
1094 *****************************************************************************/
1097 ALTER GROUP_P RoleId add_drop USER name_list
1099 AlterRoleStmt *n = makeNode(AlterRoleStmt);
1102 n->options = list_make1(makeDefElem("rolemembers",
1108 add_drop: ADD_P { $$ = +1; }
1113 /*****************************************************************************
1115 * Drop a postgresql group
1117 * XXX see above notes about cascading DROP USER; groups have same problem.
1118 *****************************************************************************/
1121 DROP GROUP_P name_list
1123 DropRoleStmt *n = makeNode(DropRoleStmt);
1124 n->missing_ok = FALSE;
1128 | DROP GROUP_P IF_P EXISTS name_list
1130 DropRoleStmt *n = makeNode(DropRoleStmt);
1131 n->missing_ok = TRUE;
1138 /*****************************************************************************
1140 * Manipulate a schema
1142 *****************************************************************************/
1145 CREATE SCHEMA OptSchemaName AUTHORIZATION RoleId OptSchemaEltList
1147 CreateSchemaStmt *n = makeNode(CreateSchemaStmt);
1148 /* One can omit the schema name or the authorization id. */
1157 | CREATE SCHEMA ColId OptSchemaEltList
1159 CreateSchemaStmt *n = makeNode(CreateSchemaStmt);
1160 /* ...but not both */
1170 | /* EMPTY */ { $$ = NULL; }
1174 OptSchemaEltList schema_stmt { $$ = lappend($1, $2); }
1175 | /* EMPTY */ { $$ = NIL; }
1179 * schema_stmt are the ones that can show up inside a CREATE SCHEMA
1180 * statement (in addition to by themselves).
1192 /*****************************************************************************
1194 * Set PG internal variable
1195 * SET name TO 'var_value'
1196 * Include SQL92 syntax (thomas 1997-10-22):
1197 * SET TIME ZONE 'var_value'
1199 *****************************************************************************/
1204 VariableSetStmt *n = $2;
1205 n->is_local = false;
1208 | SET LOCAL set_rest
1210 VariableSetStmt *n = $3;
1214 | SET SESSION set_rest
1216 VariableSetStmt *n = $3;
1217 n->is_local = false;
1222 set_rest: /* Generic SET syntaxes: */
1223 var_name TO var_list
1225 VariableSetStmt *n = makeNode(VariableSetStmt);
1226 n->kind = VAR_SET_VALUE;
1231 | var_name '=' var_list
1233 VariableSetStmt *n = makeNode(VariableSetStmt);
1234 n->kind = VAR_SET_VALUE;
1239 | var_name TO DEFAULT
1241 VariableSetStmt *n = makeNode(VariableSetStmt);
1242 n->kind = VAR_SET_DEFAULT;
1246 | var_name '=' DEFAULT
1248 VariableSetStmt *n = makeNode(VariableSetStmt);
1249 n->kind = VAR_SET_DEFAULT;
1253 | var_name FROM CURRENT_P
1255 VariableSetStmt *n = makeNode(VariableSetStmt);
1256 n->kind = VAR_SET_CURRENT;
1260 /* Special syntaxes mandated by SQL standard: */
1261 | TIME ZONE zone_value
1263 VariableSetStmt *n = makeNode(VariableSetStmt);
1264 n->kind = VAR_SET_VALUE;
1265 n->name = "timezone";
1267 n->args = list_make1($3);
1269 n->kind = VAR_SET_DEFAULT;
1272 | TRANSACTION transaction_mode_list
1274 VariableSetStmt *n = makeNode(VariableSetStmt);
1275 n->kind = VAR_SET_MULTI;
1276 n->name = "TRANSACTION";
1280 | SESSION CHARACTERISTICS AS TRANSACTION transaction_mode_list
1282 VariableSetStmt *n = makeNode(VariableSetStmt);
1283 n->kind = VAR_SET_MULTI;
1284 n->name = "SESSION CHARACTERISTICS";
1291 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
1292 errmsg("current database cannot be changed"),
1293 parser_errposition(@2)));
1294 $$ = NULL; /*not reached*/
1298 VariableSetStmt *n = makeNode(VariableSetStmt);
1299 n->kind = VAR_SET_VALUE;
1300 n->name = "search_path";
1301 n->args = list_make1(makeStringConst($2, @2));
1304 | NAMES opt_encoding
1306 VariableSetStmt *n = makeNode(VariableSetStmt);
1307 n->kind = VAR_SET_VALUE;
1308 n->name = "client_encoding";
1310 n->args = list_make1(makeStringConst($2, @2));
1312 n->kind = VAR_SET_DEFAULT;
1315 | ROLE ColId_or_Sconst
1317 VariableSetStmt *n = makeNode(VariableSetStmt);
1318 n->kind = VAR_SET_VALUE;
1320 n->args = list_make1(makeStringConst($2, @2));
1323 | SESSION AUTHORIZATION ColId_or_Sconst
1325 VariableSetStmt *n = makeNode(VariableSetStmt);
1326 n->kind = VAR_SET_VALUE;
1327 n->name = "session_authorization";
1328 n->args = list_make1(makeStringConst($3, @3));
1331 | SESSION AUTHORIZATION DEFAULT
1333 VariableSetStmt *n = makeNode(VariableSetStmt);
1334 n->kind = VAR_SET_DEFAULT;
1335 n->name = "session_authorization";
1338 | XML_P OPTION document_or_content
1340 VariableSetStmt *n = makeNode(VariableSetStmt);
1341 n->kind = VAR_SET_VALUE;
1342 n->name = "xmloption";
1343 n->args = list_make1(makeStringConst($3 == XMLOPTION_DOCUMENT ? "DOCUMENT" : "CONTENT", @3));
1348 var_name: ColId { $$ = $1; }
1349 | var_name '.' ColId
1351 $$ = palloc(strlen($1) + strlen($3) + 2);
1352 sprintf($$, "%s.%s", $1, $3);
1356 var_list: var_value { $$ = list_make1($1); }
1357 | var_list ',' var_value { $$ = lappend($1, $3); }
1360 var_value: opt_boolean_or_string
1361 { $$ = makeStringConst($1, @1); }
1363 { $$ = makeAConst($1, @1); }
1366 iso_level: READ UNCOMMITTED { $$ = "read uncommitted"; }
1367 | READ COMMITTED { $$ = "read committed"; }
1368 | REPEATABLE READ { $$ = "repeatable read"; }
1369 | SERIALIZABLE { $$ = "serializable"; }
1372 opt_boolean_or_string:
1373 TRUE_P { $$ = "true"; }
1374 | FALSE_P { $$ = "false"; }
1377 * OFF is also accepted as a boolean value, but is handled
1378 * by the ColId rule below. The action for booleans and strings
1379 * is the same, so we don't need to distinguish them here.
1381 | ColId_or_Sconst { $$ = $1; }
1384 /* Timezone values can be:
1385 * - a string such as 'pst8pdt'
1386 * - an identifier such as "pst8pdt"
1387 * - an integer or floating point number
1388 * - a time interval per SQL99
1389 * ColId gives reduce/reduce errors against ConstInterval and LOCAL,
1390 * so use IDENT (meaning we reject anything that is a key word).
1395 $$ = makeStringConst($1, @1);
1399 $$ = makeStringConst($1, @1);
1401 | ConstInterval Sconst opt_interval
1406 A_Const *n = (A_Const *) linitial($3);
1407 if ((n->val.val.ival & ~(INTERVAL_MASK(HOUR) | INTERVAL_MASK(MINUTE))) != 0)
1409 (errcode(ERRCODE_SYNTAX_ERROR),
1410 errmsg("time zone interval must be HOUR or HOUR TO MINUTE"),
1411 parser_errposition(@3)));
1414 $$ = makeStringConstCast($2, @2, t);
1416 | ConstInterval '(' Iconst ')' Sconst opt_interval
1421 A_Const *n = (A_Const *) linitial($6);
1422 if ((n->val.val.ival & ~(INTERVAL_MASK(HOUR) | INTERVAL_MASK(MINUTE))) != 0)
1424 (errcode(ERRCODE_SYNTAX_ERROR),
1425 errmsg("time zone interval must be HOUR or HOUR TO MINUTE"),
1426 parser_errposition(@6)));
1427 if (list_length($6) != 1)
1429 (errcode(ERRCODE_SYNTAX_ERROR),
1430 errmsg("interval precision specified twice"),
1431 parser_errposition(@1)));
1432 t->typmods = lappend($6, makeIntConst($3, @3));
1435 t->typmods = list_make2(makeIntConst(INTERVAL_FULL_RANGE, -1),
1436 makeIntConst($3, @3));
1437 $$ = makeStringConstCast($5, @5, t);
1439 | NumericOnly { $$ = makeAConst($1, @1); }
1440 | DEFAULT { $$ = NULL; }
1441 | LOCAL { $$ = NULL; }
1446 | DEFAULT { $$ = NULL; }
1447 | /*EMPTY*/ { $$ = NULL; }
1452 | Sconst { $$ = $1; }
1458 VariableSetStmt *n = makeNode(VariableSetStmt);
1459 n->kind = VAR_RESET;
1465 VariableSetStmt *n = makeNode(VariableSetStmt);
1466 n->kind = VAR_RESET;
1467 n->name = "timezone";
1470 | RESET TRANSACTION ISOLATION LEVEL
1472 VariableSetStmt *n = makeNode(VariableSetStmt);
1473 n->kind = VAR_RESET;
1474 n->name = "transaction_isolation";
1477 | RESET SESSION AUTHORIZATION
1479 VariableSetStmt *n = makeNode(VariableSetStmt);
1480 n->kind = VAR_RESET;
1481 n->name = "session_authorization";
1486 VariableSetStmt *n = makeNode(VariableSetStmt);
1487 n->kind = VAR_RESET_ALL;
1492 /* SetResetClause allows SET or RESET without LOCAL */
1494 SET set_rest { $$ = $2; }
1495 | VariableResetStmt { $$ = (VariableSetStmt *) $1; }
1502 VariableShowStmt *n = makeNode(VariableShowStmt);
1508 VariableShowStmt *n = makeNode(VariableShowStmt);
1509 n->name = "timezone";
1512 | SHOW TRANSACTION ISOLATION LEVEL
1514 VariableShowStmt *n = makeNode(VariableShowStmt);
1515 n->name = "transaction_isolation";
1518 | SHOW SESSION AUTHORIZATION
1520 VariableShowStmt *n = makeNode(VariableShowStmt);
1521 n->name = "session_authorization";
1526 VariableShowStmt *n = makeNode(VariableShowStmt);
1534 SET CONSTRAINTS constraints_set_list constraints_set_mode
1536 ConstraintsSetStmt *n = makeNode(ConstraintsSetStmt);
1537 n->constraints = $3;
1543 constraints_set_list:
1545 | qualified_name_list { $$ = $1; }
1548 constraints_set_mode:
1549 DEFERRED { $$ = TRUE; }
1550 | IMMEDIATE { $$ = FALSE; }
1555 * Checkpoint statement
1560 CheckPointStmt *n = makeNode(CheckPointStmt);
1566 /*****************************************************************************
1568 * DISCARD { ALL | TEMP | PLANS }
1570 *****************************************************************************/
1575 DiscardStmt *n = makeNode(DiscardStmt);
1576 n->target = DISCARD_ALL;
1581 DiscardStmt *n = makeNode(DiscardStmt);
1582 n->target = DISCARD_TEMP;
1587 DiscardStmt *n = makeNode(DiscardStmt);
1588 n->target = DISCARD_TEMP;
1593 DiscardStmt *n = makeNode(DiscardStmt);
1594 n->target = DISCARD_PLANS;
1600 /*****************************************************************************
1602 * ALTER [ TABLE | INDEX | SEQUENCE | VIEW ] variations
1604 * Note: we accept all subcommands for each of the four variants, and sort
1605 * out what's really legal at execution time.
1606 *****************************************************************************/
1609 ALTER TABLE relation_expr alter_table_cmds
1611 AlterTableStmt *n = makeNode(AlterTableStmt);
1614 n->relkind = OBJECT_TABLE;
1617 | ALTER INDEX qualified_name alter_table_cmds
1619 AlterTableStmt *n = makeNode(AlterTableStmt);
1622 n->relkind = OBJECT_INDEX;
1625 | ALTER SEQUENCE qualified_name alter_table_cmds
1627 AlterTableStmt *n = makeNode(AlterTableStmt);
1630 n->relkind = OBJECT_SEQUENCE;
1633 | ALTER VIEW qualified_name alter_table_cmds
1635 AlterTableStmt *n = makeNode(AlterTableStmt);
1638 n->relkind = OBJECT_VIEW;
1644 alter_table_cmd { $$ = list_make1($1); }
1645 | alter_table_cmds ',' alter_table_cmd { $$ = lappend($1, $3); }
1649 /* ALTER TABLE <name> ADD <coldef> */
1652 AlterTableCmd *n = makeNode(AlterTableCmd);
1653 n->subtype = AT_AddColumn;
1657 /* ALTER TABLE <name> ADD COLUMN <coldef> */
1658 | ADD_P COLUMN columnDef
1660 AlterTableCmd *n = makeNode(AlterTableCmd);
1661 n->subtype = AT_AddColumn;
1665 /* ALTER TABLE <name> ALTER [COLUMN] <colname> {SET DEFAULT <expr>|DROP DEFAULT} */
1666 | ALTER opt_column ColId alter_column_default
1668 AlterTableCmd *n = makeNode(AlterTableCmd);
1669 n->subtype = AT_ColumnDefault;
1674 /* ALTER TABLE <name> ALTER [COLUMN] <colname> DROP NOT NULL */
1675 | ALTER opt_column ColId DROP NOT NULL_P
1677 AlterTableCmd *n = makeNode(AlterTableCmd);
1678 n->subtype = AT_DropNotNull;
1682 /* ALTER TABLE <name> ALTER [COLUMN] <colname> SET NOT NULL */
1683 | ALTER opt_column ColId SET NOT NULL_P
1685 AlterTableCmd *n = makeNode(AlterTableCmd);
1686 n->subtype = AT_SetNotNull;
1690 /* ALTER TABLE <name> ALTER [COLUMN] <colname> SET STATISTICS <SignedIconst> */
1691 | ALTER opt_column ColId SET STATISTICS SignedIconst
1693 AlterTableCmd *n = makeNode(AlterTableCmd);
1694 n->subtype = AT_SetStatistics;
1696 n->def = (Node *) makeInteger($6);
1699 /* ALTER TABLE <name> ALTER [COLUMN] <colname> SET ( column_parameter = value [, ... ] ) */
1700 | ALTER opt_column ColId SET reloptions
1702 AlterTableCmd *n = makeNode(AlterTableCmd);
1703 n->subtype = AT_SetOptions;
1705 n->def = (Node *) $5;
1708 /* ALTER TABLE <name> ALTER [COLUMN] <colname> SET ( column_parameter = value [, ... ] ) */
1709 | ALTER opt_column ColId RESET reloptions
1711 AlterTableCmd *n = makeNode(AlterTableCmd);
1712 n->subtype = AT_ResetOptions;
1714 n->def = (Node *) $5;
1717 /* ALTER TABLE <name> ALTER [COLUMN] <colname> SET STORAGE <storagemode> */
1718 | ALTER opt_column ColId SET STORAGE ColId
1720 AlterTableCmd *n = makeNode(AlterTableCmd);
1721 n->subtype = AT_SetStorage;
1723 n->def = (Node *) makeString($6);
1726 /* ALTER TABLE <name> DROP [COLUMN] IF EXISTS <colname> [RESTRICT|CASCADE] */
1727 | DROP opt_column IF_P EXISTS ColId opt_drop_behavior
1729 AlterTableCmd *n = makeNode(AlterTableCmd);
1730 n->subtype = AT_DropColumn;
1733 n->missing_ok = TRUE;
1736 /* ALTER TABLE <name> DROP [COLUMN] <colname> [RESTRICT|CASCADE] */
1737 | DROP opt_column ColId opt_drop_behavior
1739 AlterTableCmd *n = makeNode(AlterTableCmd);
1740 n->subtype = AT_DropColumn;
1743 n->missing_ok = FALSE;
1747 * ALTER TABLE <name> ALTER [COLUMN] <colname> [SET DATA] TYPE <typename>
1748 * [ USING <expression> ]
1750 | ALTER opt_column ColId opt_set_data TYPE_P Typename opt_collate_clause alter_using
1752 AlterTableCmd *n = makeNode(AlterTableCmd);
1753 ColumnDef *def = makeNode(ColumnDef);
1754 n->subtype = AT_AlterColumnType;
1756 n->def = (Node *) def;
1757 /* We only use these three fields of the ColumnDef node */
1759 def->collClause = (CollateClause *) $7;
1760 def->raw_default = $8;
1763 /* ALTER TABLE <name> ADD CONSTRAINT ... */
1764 | ADD_P TableConstraint
1766 AlterTableCmd *n = makeNode(AlterTableCmd);
1767 n->subtype = AT_AddConstraint;
1771 /* ALTER TABLE <name> VALIDATE CONSTRAINT ... */
1772 | VALIDATE CONSTRAINT name
1774 AlterTableCmd *n = makeNode(AlterTableCmd);
1775 n->subtype = AT_ValidateConstraint;
1779 /* ALTER TABLE <name> DROP CONSTRAINT IF EXISTS <name> [RESTRICT|CASCADE] */
1780 | DROP CONSTRAINT IF_P EXISTS name opt_drop_behavior
1782 AlterTableCmd *n = makeNode(AlterTableCmd);
1783 n->subtype = AT_DropConstraint;
1786 n->missing_ok = TRUE;
1789 /* ALTER TABLE <name> DROP CONSTRAINT <name> [RESTRICT|CASCADE] */
1790 | DROP CONSTRAINT name opt_drop_behavior
1792 AlterTableCmd *n = makeNode(AlterTableCmd);
1793 n->subtype = AT_DropConstraint;
1796 n->missing_ok = FALSE;
1799 /* ALTER TABLE <name> SET WITH OIDS */
1802 AlterTableCmd *n = makeNode(AlterTableCmd);
1803 n->subtype = AT_AddOids;
1806 /* ALTER TABLE <name> SET WITHOUT OIDS */
1809 AlterTableCmd *n = makeNode(AlterTableCmd);
1810 n->subtype = AT_DropOids;
1813 /* ALTER TABLE <name> CLUSTER ON <indexname> */
1816 AlterTableCmd *n = makeNode(AlterTableCmd);
1817 n->subtype = AT_ClusterOn;
1821 /* ALTER TABLE <name> SET WITHOUT CLUSTER */
1822 | SET WITHOUT CLUSTER
1824 AlterTableCmd *n = makeNode(AlterTableCmd);
1825 n->subtype = AT_DropCluster;
1829 /* ALTER TABLE <name> ENABLE TRIGGER <trig> */
1830 | ENABLE_P TRIGGER name
1832 AlterTableCmd *n = makeNode(AlterTableCmd);
1833 n->subtype = AT_EnableTrig;
1837 /* ALTER TABLE <name> ENABLE ALWAYS TRIGGER <trig> */
1838 | ENABLE_P ALWAYS TRIGGER name
1840 AlterTableCmd *n = makeNode(AlterTableCmd);
1841 n->subtype = AT_EnableAlwaysTrig;
1845 /* ALTER TABLE <name> ENABLE REPLICA TRIGGER <trig> */
1846 | ENABLE_P REPLICA TRIGGER name
1848 AlterTableCmd *n = makeNode(AlterTableCmd);
1849 n->subtype = AT_EnableReplicaTrig;
1853 /* ALTER TABLE <name> ENABLE TRIGGER ALL */
1854 | ENABLE_P TRIGGER ALL
1856 AlterTableCmd *n = makeNode(AlterTableCmd);
1857 n->subtype = AT_EnableTrigAll;
1860 /* ALTER TABLE <name> ENABLE TRIGGER USER */
1861 | ENABLE_P TRIGGER USER
1863 AlterTableCmd *n = makeNode(AlterTableCmd);
1864 n->subtype = AT_EnableTrigUser;
1867 /* ALTER TABLE <name> DISABLE TRIGGER <trig> */
1868 | DISABLE_P TRIGGER name
1870 AlterTableCmd *n = makeNode(AlterTableCmd);
1871 n->subtype = AT_DisableTrig;
1875 /* ALTER TABLE <name> DISABLE TRIGGER ALL */
1876 | DISABLE_P TRIGGER ALL
1878 AlterTableCmd *n = makeNode(AlterTableCmd);
1879 n->subtype = AT_DisableTrigAll;
1882 /* ALTER TABLE <name> DISABLE TRIGGER USER */
1883 | DISABLE_P TRIGGER USER
1885 AlterTableCmd *n = makeNode(AlterTableCmd);
1886 n->subtype = AT_DisableTrigUser;
1889 /* ALTER TABLE <name> ENABLE RULE <rule> */
1890 | ENABLE_P RULE name
1892 AlterTableCmd *n = makeNode(AlterTableCmd);
1893 n->subtype = AT_EnableRule;
1897 /* ALTER TABLE <name> ENABLE ALWAYS RULE <rule> */
1898 | ENABLE_P ALWAYS RULE name
1900 AlterTableCmd *n = makeNode(AlterTableCmd);
1901 n->subtype = AT_EnableAlwaysRule;
1905 /* ALTER TABLE <name> ENABLE REPLICA RULE <rule> */
1906 | ENABLE_P REPLICA RULE name
1908 AlterTableCmd *n = makeNode(AlterTableCmd);
1909 n->subtype = AT_EnableReplicaRule;
1913 /* ALTER TABLE <name> DISABLE RULE <rule> */
1914 | DISABLE_P RULE name
1916 AlterTableCmd *n = makeNode(AlterTableCmd);
1917 n->subtype = AT_DisableRule;
1921 /* ALTER TABLE <name> INHERIT <parent> */
1922 | INHERIT qualified_name
1924 AlterTableCmd *n = makeNode(AlterTableCmd);
1925 n->subtype = AT_AddInherit;
1926 n->def = (Node *) $2;
1929 /* ALTER TABLE <name> NO INHERIT <parent> */
1930 | NO INHERIT qualified_name
1932 AlterTableCmd *n = makeNode(AlterTableCmd);
1933 n->subtype = AT_DropInherit;
1934 n->def = (Node *) $3;
1937 /* ALTER TABLE <name> OF <type_name> */
1940 AlterTableCmd *n = makeNode(AlterTableCmd);
1941 TypeName *def = makeTypeNameFromNameList($2);
1943 n->subtype = AT_AddOf;
1944 n->def = (Node *) def;
1947 /* ALTER TABLE <name> NOT OF */
1950 AlterTableCmd *n = makeNode(AlterTableCmd);
1951 n->subtype = AT_DropOf;
1954 /* ALTER TABLE <name> OWNER TO RoleId */
1957 AlterTableCmd *n = makeNode(AlterTableCmd);
1958 n->subtype = AT_ChangeOwner;
1962 /* ALTER TABLE <name> SET TABLESPACE <tablespacename> */
1963 | SET TABLESPACE name
1965 AlterTableCmd *n = makeNode(AlterTableCmd);
1966 n->subtype = AT_SetTableSpace;
1970 /* ALTER TABLE <name> SET (...) */
1973 AlterTableCmd *n = makeNode(AlterTableCmd);
1974 n->subtype = AT_SetRelOptions;
1975 n->def = (Node *)$2;
1978 /* ALTER TABLE <name> RESET (...) */
1981 AlterTableCmd *n = makeNode(AlterTableCmd);
1982 n->subtype = AT_ResetRelOptions;
1983 n->def = (Node *)$2;
1986 | alter_generic_options
1988 AlterTableCmd *n = makeNode(AlterTableCmd);
1989 n->subtype = AT_GenericOptions;
1990 n->def = (Node *)$1;
1995 alter_column_default:
1996 SET DEFAULT a_expr { $$ = $3; }
1997 | DROP DEFAULT { $$ = NULL; }
2001 CASCADE { $$ = DROP_CASCADE; }
2002 | RESTRICT { $$ = DROP_RESTRICT; }
2003 | /* EMPTY */ { $$ = DROP_RESTRICT; /* default */ }
2009 CollateClause *n = makeNode(CollateClause);
2015 | /* EMPTY */ { $$ = NULL; }
2019 USING a_expr { $$ = $2; }
2020 | /* EMPTY */ { $$ = NULL; }
2024 '(' reloption_list ')' { $$ = $2; }
2027 opt_reloptions: WITH reloptions { $$ = $2; }
2028 | /* EMPTY */ { $$ = NIL; }
2032 reloption_elem { $$ = list_make1($1); }
2033 | reloption_list ',' reloption_elem { $$ = lappend($1, $3); }
2036 /* This should match def_elem and also allow qualified names */
2038 ColLabel '=' def_arg
2040 $$ = makeDefElem($1, (Node *) $3);
2044 $$ = makeDefElem($1, NULL);
2046 | ColLabel '.' ColLabel '=' def_arg
2048 $$ = makeDefElemExtended($1, $3, (Node *) $5,
2051 | ColLabel '.' ColLabel
2053 $$ = makeDefElemExtended($1, $3, NULL, DEFELEM_UNSPEC);
2058 /*****************************************************************************
2062 * really variants of the ALTER TABLE subcommands with different spellings
2063 *****************************************************************************/
2065 AlterCompositeTypeStmt:
2066 ALTER TYPE_P any_name alter_type_cmds
2068 AlterTableStmt *n = makeNode(AlterTableStmt);
2070 /* can't use qualified_name, sigh */
2071 n->relation = makeRangeVarFromAnyName($3, @3, yyscanner);
2073 n->relkind = OBJECT_TYPE;
2079 alter_type_cmd { $$ = list_make1($1); }
2080 | alter_type_cmds ',' alter_type_cmd { $$ = lappend($1, $3); }
2084 /* ALTER TYPE <name> ADD ATTRIBUTE <coldef> [RESTRICT|CASCADE] */
2085 ADD_P ATTRIBUTE TableFuncElement opt_drop_behavior
2087 AlterTableCmd *n = makeNode(AlterTableCmd);
2088 n->subtype = AT_AddColumn;
2093 /* ALTER TYPE <name> DROP ATTRIBUTE IF EXISTS <attname> [RESTRICT|CASCADE] */
2094 | DROP ATTRIBUTE IF_P EXISTS ColId opt_drop_behavior
2096 AlterTableCmd *n = makeNode(AlterTableCmd);
2097 n->subtype = AT_DropColumn;
2100 n->missing_ok = TRUE;
2103 /* ALTER TYPE <name> DROP ATTRIBUTE <attname> [RESTRICT|CASCADE] */
2104 | DROP ATTRIBUTE ColId opt_drop_behavior
2106 AlterTableCmd *n = makeNode(AlterTableCmd);
2107 n->subtype = AT_DropColumn;
2110 n->missing_ok = FALSE;
2113 /* ALTER TYPE <name> ALTER ATTRIBUTE <attname> [SET DATA] TYPE <typename> [RESTRICT|CASCADE] */
2114 | ALTER ATTRIBUTE ColId opt_set_data TYPE_P Typename opt_collate_clause opt_drop_behavior
2116 AlterTableCmd *n = makeNode(AlterTableCmd);
2117 ColumnDef *def = makeNode(ColumnDef);
2118 n->subtype = AT_AlterColumnType;
2120 n->def = (Node *) def;
2122 /* We only use these three fields of the ColumnDef node */
2124 def->collClause = (CollateClause *) $7;
2125 def->raw_default = NULL;
2131 /*****************************************************************************
2134 * close <portalname>
2136 *****************************************************************************/
2141 ClosePortalStmt *n = makeNode(ClosePortalStmt);
2147 ClosePortalStmt *n = makeNode(ClosePortalStmt);
2148 n->portalname = NULL;
2154 /*****************************************************************************
2157 * COPY relname [(columnList)] FROM/TO file [WITH] [(options)]
2158 * COPY ( SELECT ... ) TO file [WITH] [(options)]
2160 * In the preferred syntax the options are comma-separated
2161 * and use generic identifiers instead of keywords. The pre-9.0
2162 * syntax had a hard-wired, space-separated set of options.
2164 * Really old syntax, from versions 7.2 and prior:
2165 * COPY [ BINARY ] table [ WITH OIDS ] FROM/TO file
2166 * [ [ USING ] DELIMITERS 'delimiter' ] ]
2167 * [ WITH NULL AS 'null string' ]
2168 * This option placement is not supported with COPY (SELECT...).
2170 *****************************************************************************/
2172 CopyStmt: COPY opt_binary qualified_name opt_column_list opt_oids
2173 copy_from copy_file_name copy_delimiter opt_with copy_options
2175 CopyStmt *n = makeNode(CopyStmt);
2183 /* Concatenate user-supplied flags */
2185 n->options = lappend(n->options, $2);
2187 n->options = lappend(n->options, $5);
2189 n->options = lappend(n->options, $8);
2191 n->options = list_concat(n->options, $10);
2194 | COPY select_with_parens TO copy_file_name opt_with copy_options
2196 CopyStmt *n = makeNode(CopyStmt);
2209 | TO { $$ = FALSE; }
2213 * copy_file_name NULL indicates stdio is used. Whether stdin or stdout is
2214 * used depends on the direction. (It really doesn't make sense to copy from
2215 * stdout. We silently correct the "typo".) - AY 9/94
2219 | STDIN { $$ = NULL; }
2220 | STDOUT { $$ = NULL; }
2223 copy_options: copy_opt_list { $$ = $1; }
2224 | '(' copy_generic_opt_list ')' { $$ = $2; }
2227 /* old COPY option syntax */
2229 copy_opt_list copy_opt_item { $$ = lappend($1, $2); }
2230 | /* EMPTY */ { $$ = NIL; }
2236 $$ = makeDefElem("format", (Node *)makeString("binary"));
2240 $$ = makeDefElem("oids", (Node *)makeInteger(TRUE));
2242 | DELIMITER opt_as Sconst
2244 $$ = makeDefElem("delimiter", (Node *)makeString($3));
2246 | NULL_P opt_as Sconst
2248 $$ = makeDefElem("null", (Node *)makeString($3));
2252 $$ = makeDefElem("format", (Node *)makeString("csv"));
2256 $$ = makeDefElem("header", (Node *)makeInteger(TRUE));
2258 | QUOTE opt_as Sconst
2260 $$ = makeDefElem("quote", (Node *)makeString($3));
2262 | ESCAPE opt_as Sconst
2264 $$ = makeDefElem("escape", (Node *)makeString($3));
2266 | FORCE QUOTE columnList
2268 $$ = makeDefElem("force_quote", (Node *)$3);
2272 $$ = makeDefElem("force_quote", (Node *)makeNode(A_Star));
2274 | FORCE NOT NULL_P columnList
2276 $$ = makeDefElem("force_not_null", (Node *)$4);
2280 $$ = makeDefElem("encoding", (Node *)makeString($2));
2284 /* The following exist for backward compatibility with very old versions */
2289 $$ = makeDefElem("format", (Node *)makeString("binary"));
2291 | /*EMPTY*/ { $$ = NULL; }
2297 $$ = makeDefElem("oids", (Node *)makeInteger(TRUE));
2299 | /*EMPTY*/ { $$ = NULL; }
2303 opt_using DELIMITERS Sconst
2305 $$ = makeDefElem("delimiter", (Node *)makeString($3));
2307 | /*EMPTY*/ { $$ = NULL; }
2315 /* new COPY option syntax */
2316 copy_generic_opt_list:
2317 copy_generic_opt_elem
2319 $$ = list_make1($1);
2321 | copy_generic_opt_list ',' copy_generic_opt_elem
2323 $$ = lappend($1, $3);
2327 copy_generic_opt_elem:
2328 ColLabel copy_generic_opt_arg
2330 $$ = makeDefElem($1, $2);
2334 copy_generic_opt_arg:
2335 opt_boolean_or_string { $$ = (Node *) makeString($1); }
2336 | NumericOnly { $$ = (Node *) $1; }
2337 | '*' { $$ = (Node *) makeNode(A_Star); }
2338 | '(' copy_generic_opt_arg_list ')' { $$ = (Node *) $2; }
2339 | /* EMPTY */ { $$ = NULL; }
2342 copy_generic_opt_arg_list:
2343 copy_generic_opt_arg_list_item
2345 $$ = list_make1($1);
2347 | copy_generic_opt_arg_list ',' copy_generic_opt_arg_list_item
2349 $$ = lappend($1, $3);
2353 /* beware of emitting non-string list elements here; see commands/define.c */
2354 copy_generic_opt_arg_list_item:
2355 opt_boolean_or_string { $$ = (Node *) makeString($1); }
2359 /*****************************************************************************
2362 * CREATE TABLE relname
2364 *****************************************************************************/
2366 CreateStmt: CREATE OptTemp TABLE qualified_name '(' OptTableElementList ')'
2367 OptInherit OptWith OnCommitOption OptTableSpace
2369 CreateStmt *n = makeNode(CreateStmt);
2370 $4->relpersistence = $2;
2373 n->inhRelations = $8;
2374 n->constraints = NIL;
2377 n->tablespacename = $11;
2378 n->if_not_exists = false;
2381 | CREATE OptTemp TABLE IF_P NOT EXISTS qualified_name '('
2382 OptTableElementList ')' OptInherit OptWith OnCommitOption
2385 CreateStmt *n = makeNode(CreateStmt);
2386 $7->relpersistence = $2;
2389 n->inhRelations = $11;
2390 n->constraints = NIL;
2393 n->tablespacename = $14;
2394 n->if_not_exists = true;
2397 | CREATE OptTemp TABLE qualified_name OF any_name
2398 OptTypedTableElementList OptWith OnCommitOption OptTableSpace
2400 CreateStmt *n = makeNode(CreateStmt);
2401 $4->relpersistence = $2;
2404 n->ofTypename = makeTypeNameFromNameList($6);
2405 n->ofTypename->location = @6;
2406 n->constraints = NIL;
2409 n->tablespacename = $10;
2410 n->if_not_exists = false;
2413 | CREATE OptTemp TABLE IF_P NOT EXISTS qualified_name OF any_name
2414 OptTypedTableElementList OptWith OnCommitOption OptTableSpace
2416 CreateStmt *n = makeNode(CreateStmt);
2417 $7->relpersistence = $2;
2420 n->ofTypename = makeTypeNameFromNameList($9);
2421 n->ofTypename->location = @9;
2422 n->constraints = NIL;
2425 n->tablespacename = $13;
2426 n->if_not_exists = true;
2432 * Redundancy here is needed to avoid shift/reduce conflicts,
2433 * since TEMP is not a reserved word. See also OptTempTableName.
2435 * NOTE: we accept both GLOBAL and LOCAL options; since we have no modules
2436 * the LOCAL keyword is really meaningless.
2438 OptTemp: TEMPORARY { $$ = RELPERSISTENCE_TEMP; }
2439 | TEMP { $$ = RELPERSISTENCE_TEMP; }
2440 | LOCAL TEMPORARY { $$ = RELPERSISTENCE_TEMP; }
2441 | LOCAL TEMP { $$ = RELPERSISTENCE_TEMP; }
2442 | GLOBAL TEMPORARY { $$ = RELPERSISTENCE_TEMP; }
2443 | GLOBAL TEMP { $$ = RELPERSISTENCE_TEMP; }
2444 | UNLOGGED { $$ = RELPERSISTENCE_UNLOGGED; }
2445 | /*EMPTY*/ { $$ = RELPERSISTENCE_PERMANENT; }
2448 OptTableElementList:
2449 TableElementList { $$ = $1; }
2450 | /*EMPTY*/ { $$ = NIL; }
2453 OptTypedTableElementList:
2454 '(' TypedTableElementList ')' { $$ = $2; }
2455 | /*EMPTY*/ { $$ = NIL; }
2461 $$ = list_make1($1);
2463 | TableElementList ',' TableElement
2465 $$ = lappend($1, $3);
2469 TypedTableElementList:
2472 $$ = list_make1($1);
2474 | TypedTableElementList ',' TypedTableElement
2476 $$ = lappend($1, $3);
2481 columnDef { $$ = $1; }
2482 | TableLikeClause { $$ = $1; }
2483 | TableConstraint { $$ = $1; }
2487 columnOptions { $$ = $1; }
2488 | TableConstraint { $$ = $1; }
2491 columnDef: ColId Typename ColQualList
2493 ColumnDef *n = makeNode(ColumnDef);
2498 n->is_not_null = false;
2499 n->is_from_type = false;
2501 n->raw_default = NULL;
2502 n->cooked_default = NULL;
2503 n->collOid = InvalidOid;
2504 SplitColQualList($3, &n->constraints, &n->collClause,
2510 columnOptions: ColId WITH OPTIONS ColQualList
2512 ColumnDef *n = makeNode(ColumnDef);
2517 n->is_not_null = false;
2518 n->is_from_type = false;
2520 n->raw_default = NULL;
2521 n->cooked_default = NULL;
2522 n->collOid = InvalidOid;
2523 SplitColQualList($4, &n->constraints, &n->collClause,
2530 ColQualList ColConstraint { $$ = lappend($1, $2); }
2531 | /*EMPTY*/ { $$ = NIL; }
2535 CONSTRAINT name ColConstraintElem
2537 Constraint *n = (Constraint *) $3;
2538 Assert(IsA(n, Constraint));
2543 | ColConstraintElem { $$ = $1; }
2544 | ConstraintAttr { $$ = $1; }
2548 * Note: the CollateClause is momentarily included in
2549 * the list built by ColQualList, but we split it out
2550 * again in SplitColQualList.
2552 CollateClause *n = makeNode(CollateClause);
2560 /* DEFAULT NULL is already the default for Postgres.
2561 * But define it here and carry it forward into the system
2562 * to make it explicit.
2563 * - thomas 1998-09-13
2565 * WITH NULL and NULL are not SQL92-standard syntax elements,
2566 * so leave them out. Use DEFAULT NULL to explicitly indicate
2567 * that a column may have that value. WITH NULL leads to
2568 * shift/reduce conflicts with WITH TIME ZONE anyway.
2569 * - thomas 1999-01-08
2571 * DEFAULT expression must be b_expr not a_expr to prevent shift/reduce
2572 * conflict on NOT (since NOT might start a subsequent NOT NULL constraint,
2573 * or be part of a_expr NOT LIKE or similar constructs).
2578 Constraint *n = makeNode(Constraint);
2579 n->contype = CONSTR_NOTNULL;
2585 Constraint *n = makeNode(Constraint);
2586 n->contype = CONSTR_NULL;
2590 | UNIQUE opt_definition OptConsTableSpace
2592 Constraint *n = makeNode(Constraint);
2593 n->contype = CONSTR_UNIQUE;
2597 n->indexname = NULL;
2601 | PRIMARY KEY opt_definition OptConsTableSpace
2603 Constraint *n = makeNode(Constraint);
2604 n->contype = CONSTR_PRIMARY;
2608 n->indexname = NULL;
2612 | CHECK '(' a_expr ')'
2614 Constraint *n = makeNode(Constraint);
2615 n->contype = CONSTR_CHECK;
2618 n->cooked_expr = NULL;
2623 Constraint *n = makeNode(Constraint);
2624 n->contype = CONSTR_DEFAULT;
2627 n->cooked_expr = NULL;
2630 | REFERENCES qualified_name opt_column_list key_match key_actions
2632 Constraint *n = makeNode(Constraint);
2633 n->contype = CONSTR_FOREIGN;
2638 n->fk_matchtype = $4;
2639 n->fk_upd_action = (char) ($5 >> 8);
2640 n->fk_del_action = (char) ($5 & 0xFF);
2641 n->skip_validation = FALSE;
2642 n->initially_valid = true;
2648 * ConstraintAttr represents constraint attributes, which we parse as if
2649 * they were independent constraint clauses, in order to avoid shift/reduce
2650 * conflicts (since NOT might start either an independent NOT NULL clause
2651 * or an attribute). parse_utilcmd.c is responsible for attaching the
2652 * attribute information to the preceding "real" constraint node, and for
2653 * complaining if attribute clauses appear in the wrong place or wrong
2656 * See also ConstraintAttributeSpec, which can be used in places where
2657 * there is no parsing conflict.
2662 Constraint *n = makeNode(Constraint);
2663 n->contype = CONSTR_ATTR_DEFERRABLE;
2669 Constraint *n = makeNode(Constraint);
2670 n->contype = CONSTR_ATTR_NOT_DEFERRABLE;
2674 | INITIALLY DEFERRED
2676 Constraint *n = makeNode(Constraint);
2677 n->contype = CONSTR_ATTR_DEFERRED;
2681 | INITIALLY IMMEDIATE
2683 Constraint *n = makeNode(Constraint);
2684 n->contype = CONSTR_ATTR_IMMEDIATE;
2692 * SQL99 supports wholesale borrowing of a table definition via the LIKE clause.
2693 * This seems to be a poor man's inheritance capability, with the resulting
2694 * tables completely decoupled except for the original commonality in definitions.
2696 * This is very similar to CREATE TABLE AS except for the INCLUDING DEFAULTS extension
2697 * which is a part of SQL:2003.
2700 LIKE qualified_name TableLikeOptionList
2702 InhRelation *n = makeNode(InhRelation);
2709 TableLikeOptionList:
2710 TableLikeOptionList INCLUDING TableLikeOption { $$ = $1 | $3; }
2711 | TableLikeOptionList EXCLUDING TableLikeOption { $$ = $1 & ~$3; }
2712 | /* EMPTY */ { $$ = 0; }
2716 DEFAULTS { $$ = CREATE_TABLE_LIKE_DEFAULTS; }
2717 | CONSTRAINTS { $$ = CREATE_TABLE_LIKE_CONSTRAINTS; }
2718 | INDEXES { $$ = CREATE_TABLE_LIKE_INDEXES; }
2719 | STORAGE { $$ = CREATE_TABLE_LIKE_STORAGE; }
2720 | COMMENTS { $$ = CREATE_TABLE_LIKE_COMMENTS; }
2721 | ALL { $$ = CREATE_TABLE_LIKE_ALL; }
2725 /* ConstraintElem specifies constraint syntax which is not embedded into
2726 * a column definition. ColConstraintElem specifies the embedded form.
2727 * - thomas 1997-12-03
2730 CONSTRAINT name ConstraintElem
2732 Constraint *n = (Constraint *) $3;
2733 Assert(IsA(n, Constraint));
2738 | ConstraintElem { $$ = $1; }
2742 CHECK '(' a_expr ')' ConstraintAttributeSpec
2744 Constraint *n = makeNode(Constraint);
2745 n->contype = CONSTR_CHECK;
2748 n->cooked_expr = NULL;
2751 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
2752 errmsg("CHECK constraints cannot be deferred"),
2753 parser_errposition(@5)));
2756 | UNIQUE '(' columnList ')' opt_definition OptConsTableSpace
2757 ConstraintAttributeSpec
2759 Constraint *n = makeNode(Constraint);
2760 n->contype = CONSTR_UNIQUE;
2764 n->indexname = NULL;
2766 n->deferrable = ($7 & 1) != 0;
2767 n->initdeferred = ($7 & 2) != 0;
2770 | UNIQUE ExistingIndex ConstraintAttributeSpec
2772 Constraint *n = makeNode(Constraint);
2773 n->contype = CONSTR_UNIQUE;
2778 n->indexspace = NULL;
2779 n->deferrable = ($3 & 1) != 0;
2780 n->initdeferred = ($3 & 2) != 0;
2783 | PRIMARY KEY '(' columnList ')' opt_definition OptConsTableSpace
2784 ConstraintAttributeSpec
2786 Constraint *n = makeNode(Constraint);
2787 n->contype = CONSTR_PRIMARY;
2791 n->indexname = NULL;
2793 n->deferrable = ($8 & 1) != 0;
2794 n->initdeferred = ($8 & 2) != 0;
2797 | PRIMARY KEY ExistingIndex ConstraintAttributeSpec
2799 Constraint *n = makeNode(Constraint);
2800 n->contype = CONSTR_PRIMARY;
2805 n->indexspace = NULL;
2806 n->deferrable = ($4 & 1) != 0;
2807 n->initdeferred = ($4 & 2) != 0;
2810 | EXCLUDE access_method_clause '(' ExclusionConstraintList ')'
2811 opt_definition OptConsTableSpace ExclusionWhereClause
2812 ConstraintAttributeSpec
2814 Constraint *n = makeNode(Constraint);
2815 n->contype = CONSTR_EXCLUSION;
2817 n->access_method = $2;
2820 n->indexname = NULL;
2822 n->where_clause = $8;
2823 n->deferrable = ($9 & 1) != 0;
2824 n->initdeferred = ($9 & 2) != 0;
2827 | FOREIGN KEY '(' columnList ')' REFERENCES qualified_name
2828 opt_column_list key_match key_actions ConstraintAttributeSpec
2830 Constraint *n = makeNode(Constraint);
2831 n->contype = CONSTR_FOREIGN;
2836 n->fk_matchtype = $9;
2837 n->fk_upd_action = (char) ($10 >> 8);
2838 n->fk_del_action = (char) ($10 & 0xFF);
2839 n->deferrable = ($11 & 1) != 0;
2840 n->initdeferred = ($11 & 2) != 0;
2841 n->skip_validation = false;
2842 n->initially_valid = true;
2845 | FOREIGN KEY '(' columnList ')' REFERENCES qualified_name
2846 opt_column_list key_match key_actions
2849 Constraint *n = makeNode(Constraint);
2850 n->contype = CONSTR_FOREIGN;
2855 n->fk_matchtype = $9;
2856 n->fk_upd_action = (char) ($10 >> 8);
2857 n->fk_del_action = (char) ($10 & 0xFF);
2858 n->skip_validation = true;
2859 n->initially_valid = false;
2865 '(' columnList ')' { $$ = $2; }
2866 | /*EMPTY*/ { $$ = NIL; }
2870 columnElem { $$ = list_make1($1); }
2871 | columnList ',' columnElem { $$ = lappend($1, $3); }
2876 $$ = (Node *) makeString($1);
2880 key_match: MATCH FULL
2882 $$ = FKCONSTR_MATCH_FULL;
2887 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
2888 errmsg("MATCH PARTIAL not yet implemented"),
2889 parser_errposition(@1)));
2890 $$ = FKCONSTR_MATCH_PARTIAL;
2894 $$ = FKCONSTR_MATCH_UNSPECIFIED;
2898 $$ = FKCONSTR_MATCH_UNSPECIFIED;
2902 ExclusionConstraintList:
2903 ExclusionConstraintElem { $$ = list_make1($1); }
2904 | ExclusionConstraintList ',' ExclusionConstraintElem
2905 { $$ = lappend($1, $3); }
2908 ExclusionConstraintElem: index_elem WITH any_operator
2910 $$ = list_make2($1, $3);
2912 /* allow OPERATOR() decoration for the benefit of ruleutils.c */
2913 | index_elem WITH OPERATOR '(' any_operator ')'
2915 $$ = list_make2($1, $5);
2919 ExclusionWhereClause:
2920 WHERE '(' a_expr ')' { $$ = $3; }
2921 | /*EMPTY*/ { $$ = NULL; }
2925 * We combine the update and delete actions into one value temporarily
2926 * for simplicity of parsing, and then break them down again in the
2927 * calling production. update is in the left 8 bits, delete in the right.
2928 * Note that NOACTION is the default.
2932 { $$ = ($1 << 8) | (FKCONSTR_ACTION_NOACTION & 0xFF); }
2934 { $$ = (FKCONSTR_ACTION_NOACTION << 8) | ($1 & 0xFF); }
2935 | key_update key_delete
2936 { $$ = ($1 << 8) | ($2 & 0xFF); }
2937 | key_delete key_update
2938 { $$ = ($2 << 8) | ($1 & 0xFF); }
2940 { $$ = (FKCONSTR_ACTION_NOACTION << 8) | (FKCONSTR_ACTION_NOACTION & 0xFF); }
2943 key_update: ON UPDATE key_action { $$ = $3; }
2946 key_delete: ON DELETE_P key_action { $$ = $3; }
2950 NO ACTION { $$ = FKCONSTR_ACTION_NOACTION; }
2951 | RESTRICT { $$ = FKCONSTR_ACTION_RESTRICT; }
2952 | CASCADE { $$ = FKCONSTR_ACTION_CASCADE; }
2953 | SET NULL_P { $$ = FKCONSTR_ACTION_SETNULL; }
2954 | SET DEFAULT { $$ = FKCONSTR_ACTION_SETDEFAULT; }
2957 OptInherit: INHERITS '(' qualified_name_list ')' { $$ = $3; }
2958 | /*EMPTY*/ { $$ = NIL; }
2961 /* WITH (options) is preferred, WITH OIDS and WITHOUT OIDS are legacy forms */
2963 WITH reloptions { $$ = $2; }
2964 | WITH OIDS { $$ = list_make1(defWithOids(true)); }
2965 | WITHOUT OIDS { $$ = list_make1(defWithOids(false)); }
2966 | /*EMPTY*/ { $$ = NIL; }
2969 OnCommitOption: ON COMMIT DROP { $$ = ONCOMMIT_DROP; }
2970 | ON COMMIT DELETE_P ROWS { $$ = ONCOMMIT_DELETE_ROWS; }
2971 | ON COMMIT PRESERVE ROWS { $$ = ONCOMMIT_PRESERVE_ROWS; }
2972 | /*EMPTY*/ { $$ = ONCOMMIT_NOOP; }
2975 OptTableSpace: TABLESPACE name { $$ = $2; }
2976 | /*EMPTY*/ { $$ = NULL; }
2979 OptConsTableSpace: USING INDEX TABLESPACE name { $$ = $4; }
2980 | /*EMPTY*/ { $$ = NULL; }
2983 ExistingIndex: USING INDEX index_name { $$ = $3; }
2988 * Note: CREATE TABLE ... AS SELECT ... is just another spelling for
2993 CREATE OptTemp TABLE create_as_target AS SelectStmt opt_with_data
2996 * When the SelectStmt is a set-operation tree, we must
2997 * stuff the INTO information into the leftmost component
2998 * Select, because that's where analyze.c will expect
2999 * to find it. Similarly, the output column names must
3000 * be attached to that Select's target list.
3002 SelectStmt *n = findLeftmostSelect((SelectStmt *) $6);
3003 if (n->intoClause != NULL)
3005 (errcode(ERRCODE_SYNTAX_ERROR),
3006 errmsg("CREATE TABLE AS cannot specify INTO"),
3007 parser_errposition(exprLocation((Node *) n->intoClause))));
3008 $4->rel->relpersistence = $2;
3010 /* Implement WITH NO DATA by forcing top-level LIMIT 0 */
3012 ((SelectStmt *) $6)->limitCount = makeIntConst(0, -1);
3018 qualified_name OptCreateAs OptWith OnCommitOption OptTableSpace
3020 $$ = makeNode(IntoClause);
3025 $$->tableSpaceName = $5;
3030 '(' CreateAsList ')' { $$ = $2; }
3031 | /*EMPTY*/ { $$ = NIL; }
3035 CreateAsElement { $$ = list_make1($1); }
3036 | CreateAsList ',' CreateAsElement { $$ = lappend($1, $3); }
3042 ColumnDef *n = makeNode(ColumnDef);
3047 n->is_not_null = false;
3048 n->is_from_type = false;
3050 n->raw_default = NULL;
3051 n->cooked_default = NULL;
3052 n->collClause = NULL;
3053 n->collOid = InvalidOid;
3054 n->constraints = NIL;
3060 WITH DATA_P { $$ = TRUE; }
3061 | WITH NO DATA_P { $$ = FALSE; }
3062 | /*EMPTY*/ { $$ = TRUE; }
3066 /*****************************************************************************
3069 * CREATE SEQUENCE seqname
3070 * ALTER SEQUENCE seqname
3072 *****************************************************************************/
3075 CREATE OptTemp SEQUENCE qualified_name OptSeqOptList
3077 CreateSeqStmt *n = makeNode(CreateSeqStmt);
3078 $4->relpersistence = $2;
3081 n->ownerId = InvalidOid;
3087 ALTER SEQUENCE qualified_name SeqOptList
3089 AlterSeqStmt *n = makeNode(AlterSeqStmt);
3096 OptSeqOptList: SeqOptList { $$ = $1; }
3097 | /*EMPTY*/ { $$ = NIL; }
3100 SeqOptList: SeqOptElem { $$ = list_make1($1); }
3101 | SeqOptList SeqOptElem { $$ = lappend($1, $2); }
3104 SeqOptElem: CACHE NumericOnly
3106 $$ = makeDefElem("cache", (Node *)$2);
3110 $$ = makeDefElem("cycle", (Node *)makeInteger(TRUE));
3114 $$ = makeDefElem("cycle", (Node *)makeInteger(FALSE));
3116 | INCREMENT opt_by NumericOnly
3118 $$ = makeDefElem("increment", (Node *)$3);
3120 | MAXVALUE NumericOnly
3122 $$ = makeDefElem("maxvalue", (Node *)$2);
3124 | MINVALUE NumericOnly
3126 $$ = makeDefElem("minvalue", (Node *)$2);
3130 $$ = makeDefElem("maxvalue", NULL);
3134 $$ = makeDefElem("minvalue", NULL);
3138 $$ = makeDefElem("owned_by", (Node *)$3);
3140 | START opt_with NumericOnly
3142 $$ = makeDefElem("start", (Node *)$3);
3146 $$ = makeDefElem("restart", NULL);
3148 | RESTART opt_with NumericOnly
3150 $$ = makeDefElem("restart", (Node *)$3);
3159 FCONST { $$ = makeFloat($1); }
3165 | SignedIconst { $$ = makeInteger($1); }
3168 NumericOnly_list: NumericOnly { $$ = list_make1($1); }
3169 | NumericOnly_list ',' NumericOnly { $$ = lappend($1, $3); }
3172 /*****************************************************************************
3175 * CREATE [OR REPLACE] [TRUSTED] [PROCEDURAL] LANGUAGE ...
3176 * DROP [PROCEDURAL] LANGUAGE ...
3178 *****************************************************************************/
3181 CREATE opt_or_replace opt_trusted opt_procedural LANGUAGE ColId_or_Sconst
3183 CreatePLangStmt *n = makeNode(CreatePLangStmt);
3186 /* parameters are all to be supplied by system */
3189 n->plvalidator = NIL;
3190 n->pltrusted = false;
3193 | CREATE opt_or_replace opt_trusted opt_procedural LANGUAGE ColId_or_Sconst
3194 HANDLER handler_name opt_inline_handler opt_validator
3196 CreatePLangStmt *n = makeNode(CreatePLangStmt);
3201 n->plvalidator = $10;
3208 TRUSTED { $$ = TRUE; }
3209 | /*EMPTY*/ { $$ = FALSE; }
3212 /* This ought to be just func_name, but that causes reduce/reduce conflicts
3213 * (CREATE LANGUAGE is the only place where func_name isn't followed by '(').
3214 * Work around by using simple names, instead.
3217 name { $$ = list_make1(makeString($1)); }
3218 | name attrs { $$ = lcons(makeString($1), $2); }
3222 INLINE_P handler_name { $$ = $2; }
3223 | /*EMPTY*/ { $$ = NIL; }
3227 VALIDATOR handler_name { $$ = $2; }
3228 | NO VALIDATOR { $$ = NIL; }
3232 validator_clause { $$ = $1; }
3233 | /*EMPTY*/ { $$ = NIL; }
3237 DROP opt_procedural LANGUAGE ColId_or_Sconst opt_drop_behavior
3239 DropPLangStmt *n = makeNode(DropPLangStmt);
3242 n->missing_ok = false;
3245 | DROP opt_procedural LANGUAGE IF_P EXISTS ColId_or_Sconst opt_drop_behavior
3247 DropPLangStmt *n = makeNode(DropPLangStmt);
3250 n->missing_ok = true;
3260 /*****************************************************************************
3263 * CREATE TABLESPACE tablespace LOCATION '/path/to/tablespace/'
3265 *****************************************************************************/
3267 CreateTableSpaceStmt: CREATE TABLESPACE name OptTableSpaceOwner LOCATION Sconst
3269 CreateTableSpaceStmt *n = makeNode(CreateTableSpaceStmt);
3270 n->tablespacename = $3;
3277 OptTableSpaceOwner: OWNER name { $$ = $2; }
3278 | /*EMPTY */ { $$ = NULL; }
3281 /*****************************************************************************
3284 * DROP TABLESPACE <tablespace>
3286 * No need for drop behaviour as we cannot implement dependencies for
3287 * objects in other databases; we can only support RESTRICT.
3289 ****************************************************************************/
3291 DropTableSpaceStmt: DROP TABLESPACE name
3293 DropTableSpaceStmt *n = makeNode(DropTableSpaceStmt);
3294 n->tablespacename = $3;
3295 n->missing_ok = false;
3298 | DROP TABLESPACE IF_P EXISTS name
3300 DropTableSpaceStmt *n = makeNode(DropTableSpaceStmt);
3301 n->tablespacename = $5;
3302 n->missing_ok = true;
3307 /*****************************************************************************
3310 * CREATE EXTENSION extension
3311 * [ WITH ] [ SCHEMA schema ] [ VERSION version ] [ FROM oldversion ]
3313 *****************************************************************************/
3315 CreateExtensionStmt: CREATE EXTENSION name opt_with create_extension_opt_list
3317 CreateExtensionStmt *n = makeNode(CreateExtensionStmt);
3319 n->if_not_exists = false;
3323 | CREATE EXTENSION IF_P NOT EXISTS name opt_with create_extension_opt_list
3325 CreateExtensionStmt *n = makeNode(CreateExtensionStmt);
3327 n->if_not_exists = true;
3333 create_extension_opt_list:
3334 create_extension_opt_list create_extension_opt_item
3335 { $$ = lappend($1, $2); }
3340 create_extension_opt_item:
3343 $$ = makeDefElem("schema", (Node *)makeString($2));
3345 | VERSION_P ColId_or_Sconst
3347 $$ = makeDefElem("new_version", (Node *)makeString($2));
3349 | FROM ColId_or_Sconst
3351 $$ = makeDefElem("old_version", (Node *)makeString($2));
3355 /*****************************************************************************
3357 * ALTER EXTENSION name UPDATE [ TO version ]
3359 *****************************************************************************/
3361 AlterExtensionStmt: ALTER EXTENSION name UPDATE alter_extension_opt_list
3363 AlterExtensionStmt *n = makeNode(AlterExtensionStmt);
3370 alter_extension_opt_list:
3371 alter_extension_opt_list alter_extension_opt_item
3372 { $$ = lappend($1, $2); }
3377 alter_extension_opt_item:
3380 $$ = makeDefElem("new_version", (Node *)makeString($2));
3384 /*****************************************************************************
3386 * ALTER EXTENSION name ADD/DROP object-identifier
3388 *****************************************************************************/
3390 AlterExtensionContentsStmt:
3391 ALTER EXTENSION name add_drop AGGREGATE func_name aggr_args
3393 AlterExtensionContentsStmt *n = makeNode(AlterExtensionContentsStmt);
3396 n->objtype = OBJECT_AGGREGATE;
3401 | ALTER EXTENSION name add_drop CAST '(' Typename AS Typename ')'
3403 AlterExtensionContentsStmt *n = makeNode(AlterExtensionContentsStmt);
3406 n->objtype = OBJECT_CAST;
3407 n->objname = list_make1($7);
3408 n->objargs = list_make1($9);
3411 | ALTER EXTENSION name add_drop COLLATION any_name
3413 AlterExtensionContentsStmt *n = makeNode(AlterExtensionContentsStmt);
3416 n->objtype = OBJECT_COLLATION;
3420 | ALTER EXTENSION name add_drop CONVERSION_P any_name
3422 AlterExtensionContentsStmt *n = makeNode(AlterExtensionContentsStmt);
3425 n->objtype = OBJECT_CONVERSION;
3429 | ALTER EXTENSION name add_drop DOMAIN_P any_name
3431 AlterExtensionContentsStmt *n = makeNode(AlterExtensionContentsStmt);
3434 n->objtype = OBJECT_DOMAIN;
3438 | ALTER EXTENSION name add_drop FUNCTION function_with_argtypes
3440 AlterExtensionContentsStmt *n = makeNode(AlterExtensionContentsStmt);
3443 n->objtype = OBJECT_FUNCTION;
3444 n->objname = $6->funcname;
3445 n->objargs = $6->funcargs;
3448 | ALTER EXTENSION name add_drop opt_procedural LANGUAGE name
3450 AlterExtensionContentsStmt *n = makeNode(AlterExtensionContentsStmt);
3453 n->objtype = OBJECT_LANGUAGE;
3454 n->objname = list_make1(makeString($7));
3457 | ALTER EXTENSION name add_drop OPERATOR any_operator oper_argtypes
3459 AlterExtensionContentsStmt *n = makeNode(AlterExtensionContentsStmt);
3462 n->objtype = OBJECT_OPERATOR;
3467 | ALTER EXTENSION name add_drop OPERATOR CLASS any_name USING access_method
3469 AlterExtensionContentsStmt *n = makeNode(AlterExtensionContentsStmt);
3472 n->objtype = OBJECT_OPCLASS;
3474 n->objargs = list_make1(makeString($9));
3477 | ALTER EXTENSION name add_drop OPERATOR FAMILY any_name USING access_method
3479 AlterExtensionContentsStmt *n = makeNode(AlterExtensionContentsStmt);
3482 n->objtype = OBJECT_OPFAMILY;
3484 n->objargs = list_make1(makeString($9));
3487 | ALTER EXTENSION name add_drop SCHEMA name
3489 AlterExtensionContentsStmt *n = makeNode(AlterExtensionContentsStmt);
3492 n->objtype = OBJECT_SCHEMA;
3493 n->objname = list_make1(makeString($6));
3496 | ALTER EXTENSION name add_drop TABLE any_name
3498 AlterExtensionContentsStmt *n = makeNode(AlterExtensionContentsStmt);
3501 n->objtype = OBJECT_TABLE;
3505 | ALTER EXTENSION name add_drop TEXT_P SEARCH PARSER any_name
3507 AlterExtensionContentsStmt *n = makeNode(AlterExtensionContentsStmt);
3510 n->objtype = OBJECT_TSPARSER;
3514 | ALTER EXTENSION name add_drop TEXT_P SEARCH DICTIONARY any_name
3516 AlterExtensionContentsStmt *n = makeNode(AlterExtensionContentsStmt);
3519 n->objtype = OBJECT_TSDICTIONARY;
3523 | ALTER EXTENSION name add_drop TEXT_P SEARCH TEMPLATE any_name
3525 AlterExtensionContentsStmt *n = makeNode(AlterExtensionContentsStmt);
3528 n->objtype = OBJECT_TSTEMPLATE;
3532 | ALTER EXTENSION name add_drop TEXT_P SEARCH CONFIGURATION any_name
3534 AlterExtensionContentsStmt *n = makeNode(AlterExtensionContentsStmt);
3537 n->objtype = OBJECT_TSCONFIGURATION;
3541 | ALTER EXTENSION name add_drop SEQUENCE any_name
3543 AlterExtensionContentsStmt *n = makeNode(AlterExtensionContentsStmt);
3546 n->objtype = OBJECT_SEQUENCE;
3550 | ALTER EXTENSION name add_drop VIEW any_name
3552 AlterExtensionContentsStmt *n = makeNode(AlterExtensionContentsStmt);
3555 n->objtype = OBJECT_VIEW;
3559 | ALTER EXTENSION name add_drop FOREIGN TABLE any_name
3561 AlterExtensionContentsStmt *n = makeNode(AlterExtensionContentsStmt);
3564 n->objtype = OBJECT_FOREIGN_TABLE;
3568 | ALTER EXTENSION name add_drop FOREIGN DATA_P WRAPPER name
3570 AlterExtensionContentsStmt *n = makeNode(AlterExtensionContentsStmt);
3573 n->objtype = OBJECT_FDW;
3574 n->objname = list_make1(makeString($8));
3577 | ALTER EXTENSION name add_drop SERVER name
3579 AlterExtensionContentsStmt *n = makeNode(AlterExtensionContentsStmt);
3582 n->objtype = OBJECT_FOREIGN_SERVER;
3583 n->objname = list_make1(makeString($6));
3586 | ALTER EXTENSION name add_drop TYPE_P any_name
3588 AlterExtensionContentsStmt *n = makeNode(AlterExtensionContentsStmt);
3591 n->objtype = OBJECT_TYPE;
3597 /*****************************************************************************
3600 * CREATE FOREIGN DATA WRAPPER name options
3602 *****************************************************************************/
3604 CreateFdwStmt: CREATE FOREIGN DATA_P WRAPPER name opt_fdw_options create_generic_options
3606 CreateFdwStmt *n = makeNode(CreateFdwStmt);
3608 n->func_options = $6;
3615 HANDLER handler_name { $$ = makeDefElem("handler", (Node *)$2); }
3616 | NO HANDLER { $$ = makeDefElem("handler", NULL); }
3617 | VALIDATOR handler_name { $$ = makeDefElem("validator", (Node *)$2); }
3618 | NO VALIDATOR { $$ = makeDefElem("validator", NULL); }
3622 fdw_option { $$ = list_make1($1); }
3623 | fdw_options fdw_option { $$ = lappend($1, $2); }
3627 fdw_options { $$ = $1; }
3628 | /*EMPTY*/ { $$ = NIL; }
3631 /*****************************************************************************
3634 * DROP FOREIGN DATA WRAPPER name
3636 ****************************************************************************/
3638 DropFdwStmt: DROP FOREIGN DATA_P WRAPPER name opt_drop_behavior
3640 DropFdwStmt *n = makeNode(DropFdwStmt);
3642 n->missing_ok = false;
3646 | DROP FOREIGN DATA_P WRAPPER IF_P EXISTS name opt_drop_behavior
3648 DropFdwStmt *n = makeNode(DropFdwStmt);
3650 n->missing_ok = true;
3656 /*****************************************************************************
3659 * ALTER FOREIGN DATA WRAPPER name options
3661 ****************************************************************************/
3663 AlterFdwStmt: ALTER FOREIGN DATA_P WRAPPER name opt_fdw_options alter_generic_options
3665 AlterFdwStmt *n = makeNode(AlterFdwStmt);
3667 n->func_options = $6;
3671 | ALTER FOREIGN DATA_P WRAPPER name fdw_options
3673 AlterFdwStmt *n = makeNode(AlterFdwStmt);
3675 n->func_options = $6;
3681 /* Options definition for CREATE FDW, SERVER and USER MAPPING */
3682 create_generic_options:
3683 OPTIONS '(' generic_option_list ')' { $$ = $3; }
3684 | /*EMPTY*/ { $$ = NIL; }
3687 generic_option_list:
3690 $$ = list_make1($1);
3692 | generic_option_list ',' generic_option_elem
3694 $$ = lappend($1, $3);
3698 /* Options definition for ALTER FDW, SERVER and USER MAPPING */
3699 alter_generic_options:
3700 OPTIONS '(' alter_generic_option_list ')' { $$ = $3; }
3703 alter_generic_option_list:
3704 alter_generic_option_elem
3706 $$ = list_make1($1);
3708 | alter_generic_option_list ',' alter_generic_option_elem
3710 $$ = lappend($1, $3);
3714 alter_generic_option_elem:
3719 | SET generic_option_elem
3722 $$->defaction = DEFELEM_SET;
3724 | ADD_P generic_option_elem
3727 $$->defaction = DEFELEM_ADD;
3729 | DROP generic_option_name
3731 $$ = makeDefElemExtended(NULL, $2, NULL, DEFELEM_DROP);
3735 generic_option_elem:
3736 generic_option_name generic_option_arg
3738 $$ = makeDefElem($1, $2);
3742 generic_option_name:
3743 ColLabel { $$ = $1; }
3746 /* We could use def_arg here, but the spec only requires string literals */
3748 Sconst { $$ = (Node *) makeString($1); }
3751 /*****************************************************************************
3754 * CREATE SERVER name [TYPE] [VERSION] [OPTIONS]
3756 *****************************************************************************/
3758 CreateForeignServerStmt: CREATE SERVER name opt_type opt_foreign_server_version
3759 FOREIGN DATA_P WRAPPER name create_generic_options
3761 CreateForeignServerStmt *n = makeNode(CreateForeignServerStmt);
3772 TYPE_P Sconst { $$ = $2; }
3773 | /*EMPTY*/ { $$ = NULL; }
3777 foreign_server_version:
3778 VERSION_P Sconst { $$ = $2; }
3779 | VERSION_P NULL_P { $$ = NULL; }
3782 opt_foreign_server_version:
3783 foreign_server_version { $$ = $1; }
3784 | /*EMPTY*/ { $$ = NULL; }
3787 /*****************************************************************************
3792 ****************************************************************************/
3794 DropForeignServerStmt: DROP SERVER name opt_drop_behavior
3796 DropForeignServerStmt *n = makeNode(DropForeignServerStmt);
3798 n->missing_ok = false;
3802 | DROP SERVER IF_P EXISTS name opt_drop_behavior
3804 DropForeignServerStmt *n = makeNode(DropForeignServerStmt);
3806 n->missing_ok = true;
3812 /*****************************************************************************
3815 * ALTER SERVER name [VERSION] [OPTIONS]
3817 ****************************************************************************/
3819 AlterForeignServerStmt: ALTER SERVER name foreign_server_version alter_generic_options
3821 AlterForeignServerStmt *n = makeNode(AlterForeignServerStmt);
3825 n->has_version = true;
3828 | ALTER SERVER name foreign_server_version
3830 AlterForeignServerStmt *n = makeNode(AlterForeignServerStmt);
3833 n->has_version = true;
3836 | ALTER SERVER name alter_generic_options
3838 AlterForeignServerStmt *n = makeNode(AlterForeignServerStmt);
3845 /*****************************************************************************
3848 * CREATE FOREIGN TABLE relname (...) SERVER name (...)
3850 *****************************************************************************/
3852 CreateForeignTableStmt:
3853 CREATE FOREIGN TABLE qualified_name
3854 OptForeignTableElementList
3855 SERVER name create_generic_options
3857 CreateForeignTableStmt *n = makeNode(CreateForeignTableStmt);
3858 $4->relpersistence = RELPERSISTENCE_PERMANENT;
3859 n->base.relation = $4;
3860 n->base.tableElts = $5;
3861 n->base.inhRelations = NIL;
3862 n->base.if_not_exists = false;
3863 /* FDW-specific data */
3868 | CREATE FOREIGN TABLE IF_P NOT EXISTS qualified_name
3869 OptForeignTableElementList
3870 SERVER name create_generic_options
3872 CreateForeignTableStmt *n = makeNode(CreateForeignTableStmt);
3873 $7->relpersistence = RELPERSISTENCE_PERMANENT;
3874 n->base.relation = $7;
3875 n->base.tableElts = $8;
3876 n->base.inhRelations = NIL;
3877 n->base.if_not_exists = true;
3878 /* FDW-specific data */
3879 n->servername = $10;
3885 OptForeignTableElementList:
3886 '(' ForeignTableElementList ')' { $$ = $2; }
3887 | '(' ')' { $$ = NIL; }
3890 ForeignTableElementList:
3893 $$ = list_make1($1);
3895 | ForeignTableElementList ',' ForeignTableElement
3897 $$ = lappend($1, $3);
3901 ForeignTableElement:
3902 columnDef { $$ = $1; }
3905 /*****************************************************************************
3908 * ALTER FOREIGN TABLE relname [...]
3910 *****************************************************************************/
3912 AlterForeignTableStmt:
3913 ALTER FOREIGN TABLE relation_expr alter_table_cmds
3915 AlterTableStmt *n = makeNode(AlterTableStmt);
3918 n->relkind = OBJECT_FOREIGN_TABLE;
3923 /*****************************************************************************
3926 * CREATE USER MAPPING FOR auth_ident SERVER name [OPTIONS]
3928 *****************************************************************************/
3930 CreateUserMappingStmt: CREATE USER MAPPING FOR auth_ident SERVER name create_generic_options
3932 CreateUserMappingStmt *n = makeNode(CreateUserMappingStmt);
3940 /* User mapping authorization identifier */
3942 CURRENT_USER { $$ = "current_user"; }
3943 | USER { $$ = "current_user"; }
3944 | RoleId { $$ = (strcmp($1, "public") == 0) ? NULL : $1; }
3947 /*****************************************************************************
3950 * DROP USER MAPPING FOR auth_ident SERVER name
3952 ****************************************************************************/
3954 DropUserMappingStmt: DROP USER MAPPING FOR auth_ident SERVER name
3956 DropUserMappingStmt *n = makeNode(DropUserMappingStmt);
3959 n->missing_ok = false;
3962 | DROP USER MAPPING IF_P EXISTS FOR auth_ident SERVER name
3964 DropUserMappingStmt *n = makeNode(DropUserMappingStmt);
3967 n->missing_ok = true;
3972 /*****************************************************************************
3975 * ALTER USER MAPPING FOR auth_ident SERVER name OPTIONS
3977 ****************************************************************************/
3979 AlterUserMappingStmt: ALTER USER MAPPING FOR auth_ident SERVER name alter_generic_options
3981 AlterUserMappingStmt *n = makeNode(AlterUserMappingStmt);
3989 /*****************************************************************************
3992 * CREATE TRIGGER ...
3995 *****************************************************************************/
3998 CREATE TRIGGER name TriggerActionTime TriggerEvents ON
3999 qualified_name TriggerForSpec TriggerWhen
4000 EXECUTE PROCEDURE func_name '(' TriggerFuncArgs ')'
4002 CreateTrigStmt *n = makeNode(CreateTrigStmt);
4009 n->events = intVal(linitial($5));
4010 n->columns = (List *) lsecond($5);
4012 n->isconstraint = FALSE;
4013 n->deferrable = FALSE;
4014 n->initdeferred = FALSE;
4015 n->constrrel = NULL;
4018 | CREATE CONSTRAINT TRIGGER name AFTER TriggerEvents ON
4019 qualified_name OptConstrFromTable ConstraintAttributeSpec
4020 FOR EACH ROW TriggerWhen
4021 EXECUTE PROCEDURE func_name '(' TriggerFuncArgs ')'
4023 CreateTrigStmt *n = makeNode(CreateTrigStmt);
4029 n->timing = TRIGGER_TYPE_AFTER;
4030 n->events = intVal(linitial($6));
4031 n->columns = (List *) lsecond($6);
4032 n->whenClause = $14;
4033 n->isconstraint = TRUE;
4034 n->deferrable = ($10 & 1) != 0;
4035 n->initdeferred = ($10 & 2) != 0;
4042 BEFORE { $$ = TRIGGER_TYPE_BEFORE; }
4043 | AFTER { $$ = TRIGGER_TYPE_AFTER; }
4044 | INSTEAD OF { $$ = TRIGGER_TYPE_INSTEAD; }
4050 | TriggerEvents OR TriggerOneEvent
4052 int events1 = intVal(linitial($1));
4053 int events2 = intVal(linitial($3));
4054 List *columns1 = (List *) lsecond($1);
4055 List *columns2 = (List *) lsecond($3);
4057 if (events1 & events2)
4058 parser_yyerror("duplicate trigger events specified");
4060 * concat'ing the columns lists loses information about
4061 * which columns went with which event, but so long as
4062 * only UPDATE carries columns and we disallow multiple
4063 * UPDATE items, it doesn't matter. Command execution
4064 * should just ignore the columns for non-UPDATE events.
4066 $$ = list_make2(makeInteger(events1 | events2),
4067 list_concat(columns1, columns2));
4073 { $$ = list_make2(makeInteger(TRIGGER_TYPE_INSERT), NIL); }
4075 { $$ = list_make2(makeInteger(TRIGGER_TYPE_DELETE), NIL); }
4077 { $$ = list_make2(makeInteger(TRIGGER_TYPE_UPDATE), NIL); }
4078 | UPDATE OF columnList
4079 { $$ = list_make2(makeInteger(TRIGGER_TYPE_UPDATE), $3); }
4081 { $$ = list_make2(makeInteger(TRIGGER_TYPE_TRUNCATE), NIL); }
4085 FOR TriggerForOptEach TriggerForType
4092 * If ROW/STATEMENT not specified, default to
4093 * STATEMENT, per SQL
4106 | STATEMENT { $$ = FALSE; }
4110 WHEN '(' a_expr ')' { $$ = $3; }
4111 | /*EMPTY*/ { $$ = NULL; }
4115 TriggerFuncArg { $$ = list_make1($1); }
4116 | TriggerFuncArgs ',' TriggerFuncArg { $$ = lappend($1, $3); }
4117 | /*EMPTY*/ { $$ = NIL; }
4124 snprintf(buf, sizeof(buf), "%d", $1);
4125 $$ = makeString(pstrdup(buf));
4127 | FCONST { $$ = makeString($1); }
4128 | Sconst { $$ = makeString($1); }
4129 | BCONST { $$ = makeString($1); }
4130 | XCONST { $$ = makeString($1); }
4131 | ColId { $$ = makeString($1); }
4135 FROM qualified_name { $$ = $2; }
4136 | /*EMPTY*/ { $$ = NULL; }
4139 ConstraintAttributeSpec:
4140 ConstraintDeferrabilitySpec
4142 | ConstraintDeferrabilitySpec ConstraintTimeSpec
4144 if ($1 == 0 && $2 != 0)
4146 (errcode(ERRCODE_SYNTAX_ERROR),
4147 errmsg("constraint declared INITIALLY DEFERRED must be DEFERRABLE"),
4148 parser_errposition(@1)));
4151 | ConstraintTimeSpec
4158 | ConstraintTimeSpec ConstraintDeferrabilitySpec
4160 if ($2 == 0 && $1 != 0)
4162 (errcode(ERRCODE_SYNTAX_ERROR),
4163 errmsg("constraint declared INITIALLY DEFERRED must be DEFERRABLE"),
4164 parser_errposition(@1)));
4171 ConstraintDeferrabilitySpec:
4172 NOT DEFERRABLE { $$ = 0; }
4173 | DEFERRABLE { $$ = 1; }
4177 INITIALLY IMMEDIATE { $$ = 0; }
4178 | INITIALLY DEFERRED { $$ = 2; }
4183 DROP TRIGGER name ON qualified_name opt_drop_behavior
4185 DropPropertyStmt *n = makeNode(DropPropertyStmt);
4189 n->removeType = OBJECT_TRIGGER;
4190 n->missing_ok = false;
4193 | DROP TRIGGER IF_P EXISTS name ON qualified_name opt_drop_behavior
4195 DropPropertyStmt *n = makeNode(DropPropertyStmt);
4199 n->removeType = OBJECT_TRIGGER;
4200 n->missing_ok = true;
4206 /*****************************************************************************
4209 * CREATE ASSERTION ...
4210 * DROP ASSERTION ...
4212 *****************************************************************************/
4215 CREATE ASSERTION name CHECK '(' a_expr ')'
4216 ConstraintAttributeSpec
4218 CreateTrigStmt *n = makeNode(CreateTrigStmt);
4220 n->args = list_make1($6);
4221 n->isconstraint = TRUE;
4222 n->deferrable = ($8 & 1) != 0;
4223 n->initdeferred = ($8 & 2) != 0;
4226 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
4227 errmsg("CREATE ASSERTION is not yet implemented")));
4234 DROP ASSERTION name opt_drop_behavior
4236 DropPropertyStmt *n = makeNode(DropPropertyStmt);
4240 n->removeType = OBJECT_TRIGGER; /* XXX */
4242 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
4243 errmsg("DROP ASSERTION is not yet implemented")));
4249 /*****************************************************************************
4252 * define (aggregate,operator,type)
4254 *****************************************************************************/
4257 CREATE AGGREGATE func_name aggr_args definition
4259 DefineStmt *n = makeNode(DefineStmt);
4260 n->kind = OBJECT_AGGREGATE;
4261 n->oldstyle = false;
4267 | CREATE AGGREGATE func_name old_aggr_definition
4269 /* old-style (pre-8.2) syntax for CREATE AGGREGATE */
4270 DefineStmt *n = makeNode(DefineStmt);
4271 n->kind = OBJECT_AGGREGATE;
4278 | CREATE OPERATOR any_operator definition
4280 DefineStmt *n = makeNode(DefineStmt);
4281 n->kind = OBJECT_OPERATOR;
4282 n->oldstyle = false;
4288 | CREATE TYPE_P any_name definition
4290 DefineStmt *n = makeNode(DefineStmt);
4291 n->kind = OBJECT_TYPE;
4292 n->oldstyle = false;
4298 | CREATE TYPE_P any_name
4300 /* Shell type (identified by lack of definition) */
4301 DefineStmt *n = makeNode(DefineStmt);
4302 n->kind = OBJECT_TYPE;
4303 n->oldstyle = false;
4306 n->definition = NIL;
4309 | CREATE TYPE_P any_name AS '(' OptTableFuncElementList ')'
4311 CompositeTypeStmt *n = makeNode(CompositeTypeStmt);
4313 /* can't use qualified_name, sigh */
4314 n->typevar = makeRangeVarFromAnyName($3, @3, yyscanner);
4318 | CREATE TYPE_P any_name AS ENUM_P '(' opt_enum_val_list ')'
4320 CreateEnumStmt *n = makeNode(CreateEnumStmt);
4325 | CREATE TEXT_P SEARCH PARSER any_name definition
4327 DefineStmt *n = makeNode(DefineStmt);
4328 n->kind = OBJECT_TSPARSER;
4334 | CREATE TEXT_P SEARCH DICTIONARY any_name definition
4336 DefineStmt *n = makeNode(DefineStmt);
4337 n->kind = OBJECT_TSDICTIONARY;
4343 | CREATE TEXT_P SEARCH TEMPLATE any_name definition
4345 DefineStmt *n = makeNode(DefineStmt);
4346 n->kind = OBJECT_TSTEMPLATE;
4352 | CREATE TEXT_P SEARCH CONFIGURATION any_name definition
4354 DefineStmt *n = makeNode(DefineStmt);
4355 n->kind = OBJECT_TSCONFIGURATION;
4361 | CREATE COLLATION any_name definition
4363 DefineStmt *n = makeNode(DefineStmt);
4364 n->kind = OBJECT_COLLATION;
4370 | CREATE COLLATION any_name FROM any_name
4372 DefineStmt *n = makeNode(DefineStmt);
4373 n->kind = OBJECT_COLLATION;
4376 n->definition = list_make1(makeDefElem("from", (Node *) $5));
4381 definition: '(' def_list ')' { $$ = $2; }
4384 def_list: def_elem { $$ = list_make1($1); }
4385 | def_list ',' def_elem { $$ = lappend($1, $3); }
4388 def_elem: ColLabel '=' def_arg
4390 $$ = makeDefElem($1, (Node *) $3);
4394 $$ = makeDefElem($1, NULL);
4398 /* Note: any simple identifier will be returned as a type name! */
4399 def_arg: func_type { $$ = (Node *)$1; }
4400 | reserved_keyword { $$ = (Node *)makeString(pstrdup($1)); }
4401 | qual_all_Op { $$ = (Node *)$1; }
4402 | NumericOnly { $$ = (Node *)$1; }
4403 | Sconst { $$ = (Node *)makeString($1); }
4406 aggr_args: '(' type_list ')' { $$ = $2; }
4407 | '(' '*' ')' { $$ = NIL; }
4410 old_aggr_definition: '(' old_aggr_list ')' { $$ = $2; }
4413 old_aggr_list: old_aggr_elem { $$ = list_make1($1); }
4414 | old_aggr_list ',' old_aggr_elem { $$ = lappend($1, $3); }
4418 * Must use IDENT here to avoid reduce/reduce conflicts; fortunately none of
4419 * the item names needed in old aggregate definitions are likely to become
4422 old_aggr_elem: IDENT '=' def_arg
4424 $$ = makeDefElem($1, (Node *)$3);
4429 enum_val_list { $$ = $1; }
4430 | /*EMPTY*/ { $$ = NIL; }
4433 enum_val_list: Sconst
4434 { $$ = list_make1(makeString($1)); }
4435 | enum_val_list ',' Sconst
4436 { $$ = lappend($1, makeString($3)); }
4439 /*****************************************************************************
4441 * ALTER TYPE enumtype ADD ...
4443 *****************************************************************************/
4446 ALTER TYPE_P any_name ADD_P VALUE_P Sconst
4448 AlterEnumStmt *n = makeNode(AlterEnumStmt);
4451 n->newValNeighbor = NULL;
4452 n->newValIsAfter = true;
4455 | ALTER TYPE_P any_name ADD_P VALUE_P Sconst BEFORE Sconst
4457 AlterEnumStmt *n = makeNode(AlterEnumStmt);
4460 n->newValNeighbor = $8;
4461 n->newValIsAfter = false;
4464 | ALTER TYPE_P any_name ADD_P VALUE_P Sconst AFTER Sconst
4466 AlterEnumStmt *n = makeNode(AlterEnumStmt);
4469 n->newValNeighbor = $8;
4470 n->newValIsAfter = true;
4476 /*****************************************************************************
4479 * CREATE OPERATOR CLASS ...
4480 * CREATE OPERATOR FAMILY ...
4481 * ALTER OPERATOR FAMILY ...
4482 * DROP OPERATOR CLASS ...
4483 * DROP OPERATOR FAMILY ...
4485 *****************************************************************************/
4488 CREATE OPERATOR CLASS any_name opt_default FOR TYPE_P Typename
4489 USING access_method opt_opfamily AS opclass_item_list
4491 CreateOpClassStmt *n = makeNode(CreateOpClassStmt);
4492 n->opclassname = $4;
4496 n->opfamilyname = $11;
4503 opclass_item { $$ = list_make1($1); }
4504 | opclass_item_list ',' opclass_item { $$ = lappend($1, $3); }
4508 OPERATOR Iconst any_operator opclass_purpose opt_recheck
4510 CreateOpClassItem *n = makeNode(CreateOpClassItem);
4511 n->itemtype = OPCLASS_ITEM_OPERATOR;
4515 n->order_family = $4;
4518 | OPERATOR Iconst any_operator oper_argtypes opclass_purpose
4521 CreateOpClassItem *n = makeNode(CreateOpClassItem);
4522 n->itemtype = OPCLASS_ITEM_OPERATOR;
4526 n->order_family = $5;
4529 | FUNCTION Iconst func_name func_args
4531 CreateOpClassItem *n = makeNode(CreateOpClassItem);
4532 n->itemtype = OPCLASS_ITEM_FUNCTION;
4534 n->args = extractArgTypes($4);
4538 | FUNCTION Iconst '(' type_list ')' func_name func_args
4540 CreateOpClassItem *n = makeNode(CreateOpClassItem);
4541 n->itemtype = OPCLASS_ITEM_FUNCTION;
4543 n->args = extractArgTypes($7);
4550 CreateOpClassItem *n = makeNode(CreateOpClassItem);
4551 n->itemtype = OPCLASS_ITEM_STORAGETYPE;
4557 opt_default: DEFAULT { $$ = TRUE; }
4558 | /*EMPTY*/ { $$ = FALSE; }
4561 opt_opfamily: FAMILY any_name { $$ = $2; }
4562 | /*EMPTY*/ { $$ = NIL; }
4565 opclass_purpose: FOR SEARCH { $$ = NIL; }
4566 | FOR ORDER BY any_name { $$ = $4; }
4567 | /*EMPTY*/ { $$ = NIL; }
4570 opt_recheck: RECHECK
4573 * RECHECK no longer does anything in opclass definitions,
4574 * but we still accept it to ease porting of old database
4578 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
4579 errmsg("RECHECK is no longer required"),
4580 errhint("Update your data type."),
4581 parser_errposition(@1)));
4584 | /*EMPTY*/ { $$ = FALSE; }
4589 CREATE OPERATOR FAMILY any_name USING access_method
4591 CreateOpFamilyStmt *n = makeNode(CreateOpFamilyStmt);
4592 n->opfamilyname = $4;
4599 ALTER OPERATOR FAMILY any_name USING access_method ADD_P opclass_item_list
4601 AlterOpFamilyStmt *n = makeNode(AlterOpFamilyStmt);
4602 n->opfamilyname = $4;
4608 | ALTER OPERATOR FAMILY any_name USING access_method DROP opclass_drop_list
4610 AlterOpFamilyStmt *n = makeNode(AlterOpFamilyStmt);
4611 n->opfamilyname = $4;
4620 opclass_drop { $$ = list_make1($1); }
4621 | opclass_drop_list ',' opclass_drop { $$ = lappend($1, $3); }
4625 OPERATOR Iconst '(' type_list ')'
4627 CreateOpClassItem *n = makeNode(CreateOpClassItem);
4628 n->itemtype = OPCLASS_ITEM_OPERATOR;
4633 | FUNCTION Iconst '(' type_list ')'
4635 CreateOpClassItem *n = makeNode(CreateOpClassItem);
4636 n->itemtype = OPCLASS_ITEM_FUNCTION;
4645 DROP OPERATOR CLASS any_name USING access_method opt_drop_behavior
4647 RemoveOpClassStmt *n = makeNode(RemoveOpClassStmt);
4648 n->opclassname = $4;
4651 n->missing_ok = false;
4654 | DROP OPERATOR CLASS IF_P EXISTS any_name USING access_method opt_drop_behavior
4656 RemoveOpClassStmt *n = makeNode(RemoveOpClassStmt);
4657 n->opclassname = $6;
4660 n->missing_ok = true;
4666 DROP OPERATOR FAMILY any_name USING access_method opt_drop_behavior
4668 RemoveOpFamilyStmt *n = makeNode(RemoveOpFamilyStmt);
4669 n->opfamilyname = $4;
4672 n->missing_ok = false;
4675 | DROP OPERATOR FAMILY IF_P EXISTS any_name USING access_method opt_drop_behavior
4677 RemoveOpFamilyStmt *n = makeNode(RemoveOpFamilyStmt);
4678 n->opfamilyname = $6;
4681 n->missing_ok = true;
4687 /*****************************************************************************
4691 * DROP OWNED BY username [, username ...] [ RESTRICT | CASCADE ]
4692 * REASSIGN OWNED BY username [, username ...] TO username
4694 *****************************************************************************/
4696 DROP OWNED BY name_list opt_drop_behavior
4698 DropOwnedStmt *n = makeNode(DropOwnedStmt);
4706 REASSIGN OWNED BY name_list TO name
4708 ReassignOwnedStmt *n = makeNode(ReassignOwnedStmt);
4715 /*****************************************************************************
4719 * DROP itemtype [ IF EXISTS ] itemname [, itemname ...]
4720 * [ RESTRICT | CASCADE ]
4722 *****************************************************************************/
4724 DropStmt: DROP drop_type IF_P EXISTS any_name_list opt_drop_behavior
4726 DropStmt *n = makeNode(DropStmt);
4728 n->missing_ok = TRUE;
4733 | DROP drop_type any_name_list opt_drop_behavior
4735 DropStmt *n = makeNode(DropStmt);
4737 n->missing_ok = FALSE;
4745 drop_type: TABLE { $$ = OBJECT_TABLE; }
4746 | SEQUENCE { $$ = OBJECT_SEQUENCE; }
4747 | VIEW { $$ = OBJECT_VIEW; }
4748 | INDEX { $$ = OBJECT_INDEX; }
4749 | FOREIGN TABLE { $$ = OBJECT_FOREIGN_TABLE; }
4750 | TYPE_P { $$ = OBJECT_TYPE; }
4751 | DOMAIN_P { $$ = OBJECT_DOMAIN; }
4752 | COLLATION { $$ = OBJECT_COLLATION; }
4753 | CONVERSION_P { $$ = OBJECT_CONVERSION; }
4754 | SCHEMA { $$ = OBJECT_SCHEMA; }
4755 | EXTENSION { $$ = OBJECT_EXTENSION; }
4756 | TEXT_P SEARCH PARSER { $$ = OBJECT_TSPARSER; }
4757 | TEXT_P SEARCH DICTIONARY { $$ = OBJECT_TSDICTIONARY; }
4758 | TEXT_P SEARCH TEMPLATE { $$ = OBJECT_TSTEMPLATE; }
4759 | TEXT_P SEARCH CONFIGURATION { $$ = OBJECT_TSCONFIGURATION; }
4763 any_name { $$ = list_make1($1); }
4764 | any_name_list ',' any_name { $$ = lappend($1, $3); }
4767 any_name: ColId { $$ = list_make1(makeString($1)); }
4768 | ColId attrs { $$ = lcons(makeString($1), $2); }
4771 attrs: '.' attr_name
4772 { $$ = list_make1(makeString($2)); }
4773 | attrs '.' attr_name
4774 { $$ = lappend($1, makeString($3)); }
4778 /*****************************************************************************
4781 * truncate table relname1, relname2, ...
4783 *****************************************************************************/
4786 TRUNCATE opt_table relation_expr_list opt_restart_seqs opt_drop_behavior
4788 TruncateStmt *n = makeNode(TruncateStmt);
4790 n->restart_seqs = $4;
4797 CONTINUE_P IDENTITY_P { $$ = false; }
4798 | RESTART IDENTITY_P { $$ = true; }
4799 | /* EMPTY */ { $$ = false; }
4802 /*****************************************************************************
4804 * The COMMENT ON statement can take different forms based upon the type of
4805 * the object associated with the comment. The form of the statement is:
4807 * COMMENT ON [ [ DATABASE | DOMAIN | INDEX | SEQUENCE | TABLE | TYPE | VIEW |
4808 * COLLATION | CONVERSION | LANGUAGE | OPERATOR CLASS |
4809 * LARGE OBJECT | CAST | COLUMN | SCHEMA | TABLESPACE |
4810 * EXTENSION | ROLE | TEXT SEARCH PARSER |
4811 * TEXT SEARCH DICTIONARY | TEXT SEARCH TEMPLATE |
4812 * TEXT SEARCH CONFIGURATION | FOREIGN TABLE |
4813 * FOREIGN DATA WRAPPER | SERVER ] <objname> |
4814 * AGGREGATE <aggname> (arg1, ...) |
4815 * FUNCTION <funcname> (arg1, arg2, ...) |
4816 * OPERATOR <op> (leftoperand_typ, rightoperand_typ) |
4817 * TRIGGER <triggername> ON <relname> |
4818 * CONSTRAINT <constraintname> ON <relname> |
4819 * RULE <rulename> ON <relname> ]
4822 *****************************************************************************/
4825 COMMENT ON comment_type any_name IS comment_text
4827 CommentStmt *n = makeNode(CommentStmt);
4834 | COMMENT ON AGGREGATE func_name aggr_args IS comment_text
4836 CommentStmt *n = makeNode(CommentStmt);
4837 n->objtype = OBJECT_AGGREGATE;
4843 | COMMENT ON FUNCTION func_name func_args IS comment_text
4845 CommentStmt *n = makeNode(CommentStmt);
4846 n->objtype = OBJECT_FUNCTION;
4848 n->objargs = extractArgTypes($5);
4852 | COMMENT ON OPERATOR any_operator oper_argtypes IS comment_text
4854 CommentStmt *n = makeNode(CommentStmt);
4855 n->objtype = OBJECT_OPERATOR;
4861 | COMMENT ON CONSTRAINT name ON any_name IS comment_text
4863 CommentStmt *n = makeNode(CommentStmt);
4864 n->objtype = OBJECT_CONSTRAINT;
4865 n->objname = lappend($6, makeString($4));
4870 | COMMENT ON RULE name ON any_name IS comment_text
4872 CommentStmt *n = makeNode(CommentStmt);
4873 n->objtype = OBJECT_RULE;
4874 n->objname = lappend($6, makeString($4));
4879 | COMMENT ON RULE name IS comment_text
4881 /* Obsolete syntax supported for awhile for compatibility */
4882 CommentStmt *n = makeNode(CommentStmt);
4883 n->objtype = OBJECT_RULE;
4884 n->objname = list_make1(makeString($4));
4889 | COMMENT ON TRIGGER name ON any_name IS comment_text
4891 CommentStmt *n = makeNode(CommentStmt);
4892 n->objtype = OBJECT_TRIGGER;
4893 n->objname = lappend($6, makeString($4));
4898 | COMMENT ON OPERATOR CLASS any_name USING access_method IS comment_text
4900 CommentStmt *n = makeNode(CommentStmt);
4901 n->objtype = OBJECT_OPCLASS;
4903 n->objargs = list_make1(makeString($7));
4907 | COMMENT ON OPERATOR FAMILY any_name USING access_method IS comment_text
4909 CommentStmt *n = makeNode(CommentStmt);
4910 n->objtype = OBJECT_OPFAMILY;
4912 n->objargs = list_make1(makeString($7));
4916 | COMMENT ON LARGE_P OBJECT_P NumericOnly IS comment_text
4918 CommentStmt *n = makeNode(CommentStmt);
4919 n->objtype = OBJECT_LARGEOBJECT;
4920 n->objname = list_make1($5);
4925 | COMMENT ON CAST '(' Typename AS Typename ')' IS comment_text
4927 CommentStmt *n = makeNode(CommentStmt);
4928 n->objtype = OBJECT_CAST;
4929 n->objname = list_make1($5);
4930 n->objargs = list_make1($7);
4934 | COMMENT ON opt_procedural LANGUAGE any_name IS comment_text
4936 CommentStmt *n = makeNode(CommentStmt);
4937 n->objtype = OBJECT_LANGUAGE;
4943 | COMMENT ON TEXT_P SEARCH PARSER any_name IS comment_text
4945 CommentStmt *n = makeNode(CommentStmt);
4946 n->objtype = OBJECT_TSPARSER;
4951 | COMMENT ON TEXT_P SEARCH DICTIONARY any_name IS comment_text
4953 CommentStmt *n = makeNode(CommentStmt);
4954 n->objtype = OBJECT_TSDICTIONARY;
4959 | COMMENT ON TEXT_P SEARCH TEMPLATE any_name IS comment_text
4961 CommentStmt *n = makeNode(CommentStmt);
4962 n->objtype = OBJECT_TSTEMPLATE;
4967 | COMMENT ON TEXT_P SEARCH CONFIGURATION any_name IS comment_text
4969 CommentStmt *n = makeNode(CommentStmt);
4970 n->objtype = OBJECT_TSCONFIGURATION;
4978 COLUMN { $$ = OBJECT_COLUMN; }
4979 | DATABASE { $$ = OBJECT_DATABASE; }
4980 | SCHEMA { $$ = OBJECT_SCHEMA; }
4981 | INDEX { $$ = OBJECT_INDEX; }
4982 | SEQUENCE { $$ = OBJECT_SEQUENCE; }
4983 | TABLE { $$ = OBJECT_TABLE; }
4984 | DOMAIN_P { $$ = OBJECT_DOMAIN; }
4985 | TYPE_P { $$ = OBJECT_TYPE; }
4986 | VIEW { $$ = OBJECT_VIEW; }
4987 | COLLATION { $$ = OBJECT_COLLATION; }
4988 | CONVERSION_P { $$ = OBJECT_CONVERSION; }
4989 | TABLESPACE { $$ = OBJECT_TABLESPACE; }
4990 | EXTENSION { $$ = OBJECT_EXTENSION; }
4991 | ROLE { $$ = OBJECT_ROLE; }
4992 | FOREIGN TABLE { $$ = OBJECT_FOREIGN_TABLE; }
4993 | SERVER { $$ = OBJECT_FOREIGN_SERVER; }
4994 | FOREIGN DATA_P WRAPPER { $$ = OBJECT_FDW; }
4999 | NULL_P { $$ = NULL; }
5003 /*****************************************************************************
5005 * SECURITY LABEL [FOR <provider>] ON <object> IS <label>
5007 * As with COMMENT ON, <object> can refer to various types of database
5008 * objects (e.g. TABLE, COLUMN, etc.).
5010 *****************************************************************************/
5013 SECURITY LABEL opt_provider ON security_label_type any_name
5016 SecLabelStmt *n = makeNode(SecLabelStmt);
5024 | SECURITY LABEL opt_provider ON AGGREGATE func_name aggr_args
5027 SecLabelStmt *n = makeNode(SecLabelStmt);
5029 n->objtype = OBJECT_AGGREGATE;
5035 | SECURITY LABEL opt_provider ON FUNCTION func_name func_args
5038 SecLabelStmt *n = makeNode(SecLabelStmt);
5040 n->objtype = OBJECT_FUNCTION;
5042 n->objargs = extractArgTypes($7);
5046 | SECURITY LABEL opt_provider ON LARGE_P OBJECT_P NumericOnly
5049 SecLabelStmt *n = makeNode(SecLabelStmt);
5051 n->objtype = OBJECT_LARGEOBJECT;
5052 n->objname = list_make1($7);
5057 | SECURITY LABEL opt_provider ON opt_procedural LANGUAGE any_name
5060 SecLabelStmt *n = makeNode(SecLabelStmt);
5062 n->objtype = OBJECT_LANGUAGE;
5070 opt_provider: FOR ColId_or_Sconst { $$ = $2; }
5071 | /* empty */ { $$ = NULL; }
5074 security_label_type:
5075 COLUMN { $$ = OBJECT_COLUMN; }
5076 | FOREIGN TABLE { $$ = OBJECT_FOREIGN_TABLE; }
5077 | SCHEMA { $$ = OBJECT_SCHEMA; }
5078 | SEQUENCE { $$ = OBJECT_SEQUENCE; }
5079 | TABLE { $$ = OBJECT_TABLE; }
5080 | DOMAIN_P { $$ = OBJECT_TYPE; }
5081 | TYPE_P { $$ = OBJECT_TYPE; }
5082 | VIEW { $$ = OBJECT_VIEW; }
5085 security_label: Sconst { $$ = $1; }
5086 | NULL_P { $$ = NULL; }
5089 /*****************************************************************************
5094 *****************************************************************************/
5096 FetchStmt: FETCH fetch_args
5098 FetchStmt *n = (FetchStmt *) $2;
5104 FetchStmt *n = (FetchStmt *) $2;
5110 fetch_args: cursor_name
5112 FetchStmt *n = makeNode(FetchStmt);
5114 n->direction = FETCH_FORWARD;
5118 | from_in cursor_name
5120 FetchStmt *n = makeNode(FetchStmt);
5122 n->direction = FETCH_FORWARD;
5126 | NEXT opt_from_in cursor_name
5128 FetchStmt *n = makeNode(FetchStmt);
5130 n->direction = FETCH_FORWARD;
5134 | PRIOR opt_from_in cursor_name
5136 FetchStmt *n = makeNode(FetchStmt);
5138 n->direction = FETCH_BACKWARD;
5142 | FIRST_P opt_from_in cursor_name
5144 FetchStmt *n = makeNode(FetchStmt);
5146 n->direction = FETCH_ABSOLUTE;
5150 | LAST_P opt_from_in cursor_name
5152 FetchStmt *n = makeNode(FetchStmt);
5154 n->direction = FETCH_ABSOLUTE;
5158 | ABSOLUTE_P SignedIconst opt_from_in cursor_name
5160 FetchStmt *n = makeNode(FetchStmt);
5162 n->direction = FETCH_ABSOLUTE;
5166 | RELATIVE_P SignedIconst opt_from_in cursor_name
5168 FetchStmt *n = makeNode(FetchStmt);
5170 n->direction = FETCH_RELATIVE;
5174 | SignedIconst opt_from_in cursor_name
5176 FetchStmt *n = makeNode(FetchStmt);
5178 n->direction = FETCH_FORWARD;
5182 | ALL opt_from_in cursor_name
5184 FetchStmt *n = makeNode(FetchStmt);
5186 n->direction = FETCH_FORWARD;
5187 n->howMany = FETCH_ALL;
5190 | FORWARD opt_from_in cursor_name
5192 FetchStmt *n = makeNode(FetchStmt);
5194 n->direction = FETCH_FORWARD;
5198 | FORWARD SignedIconst opt_from_in cursor_name
5200 FetchStmt *n = makeNode(FetchStmt);
5202 n->direction = FETCH_FORWARD;
5206 | FORWARD ALL opt_from_in cursor_name
5208 FetchStmt *n = makeNode(FetchStmt);
5210 n->direction = FETCH_FORWARD;
5211 n->howMany = FETCH_ALL;
5214 | BACKWARD opt_from_in cursor_name
5216 FetchStmt *n = makeNode(FetchStmt);
5218 n->direction = FETCH_BACKWARD;
5222 | BACKWARD SignedIconst opt_from_in cursor_name
5224 FetchStmt *n = makeNode(FetchStmt);
5226 n->direction = FETCH_BACKWARD;
5230 | BACKWARD ALL opt_from_in cursor_name
5232 FetchStmt *n = makeNode(FetchStmt);
5234 n->direction = FETCH_BACKWARD;
5235 n->howMany = FETCH_ALL;
5244 opt_from_in: from_in {}
5249 /*****************************************************************************
5251 * GRANT and REVOKE statements
5253 *****************************************************************************/
5255 GrantStmt: GRANT privileges ON privilege_target TO grantee_list
5256 opt_grant_grant_option
5258 GrantStmt *n = makeNode(GrantStmt);
5261 n->targtype = ($4)->targtype;
5262 n->objtype = ($4)->objtype;
5263 n->objects = ($4)->objs;
5265 n->grant_option = $7;
5271 REVOKE privileges ON privilege_target
5272 FROM grantee_list opt_drop_behavior
5274 GrantStmt *n = makeNode(GrantStmt);
5275 n->is_grant = false;
5276 n->grant_option = false;
5278 n->targtype = ($4)->targtype;
5279 n->objtype = ($4)->objtype;
5280 n->objects = ($4)->objs;
5285 | REVOKE GRANT OPTION FOR privileges ON privilege_target
5286 FROM grantee_list opt_drop_behavior
5288 GrantStmt *n = makeNode(GrantStmt);
5289 n->is_grant = false;
5290 n->grant_option = true;
5292 n->targtype = ($7)->targtype;
5293 n->objtype = ($7)->objtype;
5294 n->objects = ($7)->objs;
5303 * Privilege names are represented as strings; the validity of the privilege
5304 * names gets checked at execution. This is a bit annoying but we have little
5305 * choice because of the syntactic conflict with lists of role names in
5306 * GRANT/REVOKE. What's more, we have to call out in the "privilege"
5307 * production any reserved keywords that need to be usable as privilege names.
5310 /* either ALL [PRIVILEGES] or a list of individual privileges */
5311 privileges: privilege_list
5317 | ALL '(' columnList ')'
5319 AccessPriv *n = makeNode(AccessPriv);
5320 n->priv_name = NULL;
5324 | ALL PRIVILEGES '(' columnList ')'
5326 AccessPriv *n = makeNode(AccessPriv);
5327 n->priv_name = NULL;
5333 privilege_list: privilege { $$ = list_make1($1); }
5334 | privilege_list ',' privilege { $$ = lappend($1, $3); }
5337 privilege: SELECT opt_column_list
5339 AccessPriv *n = makeNode(AccessPriv);
5340 n->priv_name = pstrdup($1);
5344 | REFERENCES opt_column_list
5346 AccessPriv *n = makeNode(AccessPriv);
5347 n->priv_name = pstrdup($1);
5351 | CREATE opt_column_list
5353 AccessPriv *n = makeNode(AccessPriv);
5354 n->priv_name = pstrdup($1);
5358 | ColId opt_column_list
5360 AccessPriv *n = makeNode(AccessPriv);
5368 /* Don't bother trying to fold the first two rules into one using
5369 * opt_table. You're going to get conflicts.
5374 PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
5375 n->targtype = ACL_TARGET_OBJECT;
5376 n->objtype = ACL_OBJECT_RELATION;
5380 | TABLE qualified_name_list
5382 PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
5383 n->targtype = ACL_TARGET_OBJECT;
5384 n->objtype = ACL_OBJECT_RELATION;
5388 | SEQUENCE qualified_name_list
5390 PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
5391 n->targtype = ACL_TARGET_OBJECT;
5392 n->objtype = ACL_OBJECT_SEQUENCE;
5396 | FOREIGN DATA_P WRAPPER name_list
5398 PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
5399 n->targtype = ACL_TARGET_OBJECT;
5400 n->objtype = ACL_OBJECT_FDW;
5404 | FOREIGN SERVER name_list
5406 PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
5407 n->targtype = ACL_TARGET_OBJECT;
5408 n->objtype = ACL_OBJECT_FOREIGN_SERVER;
5412 | FUNCTION function_with_argtypes_list
5414 PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
5415 n->targtype = ACL_TARGET_OBJECT;
5416 n->objtype = ACL_OBJECT_FUNCTION;
5420 | DATABASE name_list
5422 PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
5423 n->targtype = ACL_TARGET_OBJECT;
5424 n->objtype = ACL_OBJECT_DATABASE;
5428 | LANGUAGE name_list
5430 PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
5431 n->targtype = ACL_TARGET_OBJECT;
5432 n->objtype = ACL_OBJECT_LANGUAGE;
5436 | LARGE_P OBJECT_P NumericOnly_list
5438 PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
5439 n->targtype = ACL_TARGET_OBJECT;
5440 n->objtype = ACL_OBJECT_LARGEOBJECT;
5446 PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
5447 n->targtype = ACL_TARGET_OBJECT;
5448 n->objtype = ACL_OBJECT_NAMESPACE;
5452 | TABLESPACE name_list
5454 PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
5455 n->targtype = ACL_TARGET_OBJECT;
5456 n->objtype = ACL_OBJECT_TABLESPACE;
5460 | ALL TABLES IN_P SCHEMA name_list
5462 PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
5463 n->targtype = ACL_TARGET_ALL_IN_SCHEMA;
5464 n->objtype = ACL_OBJECT_RELATION;
5468 | ALL SEQUENCES IN_P SCHEMA name_list
5470 PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
5471 n->targtype = ACL_TARGET_ALL_IN_SCHEMA;
5472 n->objtype = ACL_OBJECT_SEQUENCE;
5476 | ALL FUNCTIONS IN_P SCHEMA name_list
5478 PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
5479 n->targtype = ACL_TARGET_ALL_IN_SCHEMA;
5480 n->objtype = ACL_OBJECT_FUNCTION;
5488 grantee { $$ = list_make1($1); }
5489 | grantee_list ',' grantee { $$ = lappend($1, $3); }
5494 PrivGrantee *n = makeNode(PrivGrantee);
5495 /* This hack lets us avoid reserving PUBLIC as a keyword*/
5496 if (strcmp($1, "public") == 0)
5504 PrivGrantee *n = makeNode(PrivGrantee);
5505 /* Treat GROUP PUBLIC as a synonym for PUBLIC */
5506 if (strcmp($2, "public") == 0)
5515 opt_grant_grant_option:
5516 WITH GRANT OPTION { $$ = TRUE; }
5517 | /*EMPTY*/ { $$ = FALSE; }
5520 function_with_argtypes_list:
5521 function_with_argtypes { $$ = list_make1($1); }
5522 | function_with_argtypes_list ',' function_with_argtypes
5523 { $$ = lappend($1, $3); }
5526 function_with_argtypes:
5529 FuncWithArgs *n = makeNode(FuncWithArgs);
5531 n->funcargs = extractArgTypes($2);
5536 /*****************************************************************************
5538 * GRANT and REVOKE ROLE statements
5540 *****************************************************************************/
5543 GRANT privilege_list TO name_list opt_grant_admin_option opt_granted_by
5545 GrantRoleStmt *n = makeNode(GrantRoleStmt);
5547 n->granted_roles = $2;
5548 n->grantee_roles = $4;
5556 REVOKE privilege_list FROM name_list opt_granted_by opt_drop_behavior
5558 GrantRoleStmt *n = makeNode(GrantRoleStmt);
5559 n->is_grant = false;
5560 n->admin_opt = false;
5561 n->granted_roles = $2;
5562 n->grantee_roles = $4;
5566 | REVOKE ADMIN OPTION FOR privilege_list FROM name_list opt_granted_by opt_drop_behavior
5568 GrantRoleStmt *n = makeNode(GrantRoleStmt);
5569 n->is_grant = false;
5570 n->admin_opt = true;
5571 n->granted_roles = $5;
5572 n->grantee_roles = $7;
5578 opt_grant_admin_option: WITH ADMIN OPTION { $$ = TRUE; }
5579 | /*EMPTY*/ { $$ = FALSE; }
5582 opt_granted_by: GRANTED BY RoleId { $$ = $3; }
5583 | /*EMPTY*/ { $$ = NULL; }
5586 /*****************************************************************************
5588 * ALTER DEFAULT PRIVILEGES statement
5590 *****************************************************************************/
5592 AlterDefaultPrivilegesStmt:
5593 ALTER DEFAULT PRIVILEGES DefACLOptionList DefACLAction
5595 AlterDefaultPrivilegesStmt *n = makeNode(AlterDefaultPrivilegesStmt);
5597 n->action = (GrantStmt *) $5;
5603 DefACLOptionList DefACLOption { $$ = lappend($1, $2); }
5604 | /* EMPTY */ { $$ = NIL; }
5608 IN_P SCHEMA name_list
5610 $$ = makeDefElem("schemas", (Node *)$3);
5612 | FOR ROLE name_list
5614 $$ = makeDefElem("roles", (Node *)$3);
5616 | FOR USER name_list
5618 $$ = makeDefElem("roles", (Node *)$3);
5623 * This should match GRANT/REVOKE, except that individual target objects
5624 * are not mentioned and we only allow a subset of object types.
5627 GRANT privileges ON defacl_privilege_target TO grantee_list
5628 opt_grant_grant_option
5630 GrantStmt *n = makeNode(GrantStmt);
5633 n->targtype = ACL_TARGET_DEFAULTS;
5637 n->grant_option = $7;
5640 | REVOKE privileges ON defacl_privilege_target
5641 FROM grantee_list opt_drop_behavior
5643 GrantStmt *n = makeNode(GrantStmt);
5644 n->is_grant = false;
5645 n->grant_option = false;
5647 n->targtype = ACL_TARGET_DEFAULTS;
5654 | REVOKE GRANT OPTION FOR privileges ON defacl_privilege_target
5655 FROM grantee_list opt_drop_behavior
5657 GrantStmt *n = makeNode(GrantStmt);
5658 n->is_grant = false;
5659 n->grant_option = true;
5661 n->targtype = ACL_TARGET_DEFAULTS;
5670 defacl_privilege_target:
5671 TABLES { $$ = ACL_OBJECT_RELATION; }
5672 | FUNCTIONS { $$ = ACL_OBJECT_FUNCTION; }
5673 | SEQUENCES { $$ = ACL_OBJECT_SEQUENCE; }
5677 /*****************************************************************************
5679 * QUERY: CREATE INDEX
5681 * Note: we cannot put TABLESPACE clause after WHERE clause unless we are
5682 * willing to make TABLESPACE a fully reserved word.
5683 *****************************************************************************/
5685 IndexStmt: CREATE opt_unique INDEX opt_concurrently opt_index_name
5686 ON qualified_name access_method_clause '(' index_params ')'
5687 opt_reloptions OptTableSpace where_clause
5689 IndexStmt *n = makeNode(IndexStmt);
5694 n->accessMethod = $8;
5695 n->indexParams = $10;
5697 n->tableSpace = $13;
5698 n->whereClause = $14;
5699 n->indexOid = InvalidOid;
5705 UNIQUE { $$ = TRUE; }
5706 | /*EMPTY*/ { $$ = FALSE; }
5710 CONCURRENTLY { $$ = TRUE; }
5711 | /*EMPTY*/ { $$ = FALSE; }
5715 index_name { $$ = $1; }
5716 | /*EMPTY*/ { $$ = NULL; }
5719 access_method_clause:
5720 USING access_method { $$ = $2; }
5721 | /*EMPTY*/ { $$ = DEFAULT_INDEX_TYPE; }
5724 index_params: index_elem { $$ = list_make1($1); }
5725 | index_params ',' index_elem { $$ = lappend($1, $3); }
5729 * Index attributes can be either simple column references, or arbitrary
5730 * expressions in parens. For backwards-compatibility reasons, we allow
5731 * an expression that's just a function call to be written without parens.
5733 index_elem: ColId opt_collate opt_class opt_asc_desc opt_nulls_order
5735 $$ = makeNode(IndexElem);
5738 $$->indexcolname = NULL;
5742 $$->nulls_ordering = $5;
5744 | func_expr opt_collate opt_class opt_asc_desc opt_nulls_order
5746 $$ = makeNode(IndexElem);
5749 $$->indexcolname = NULL;
5753 $$->nulls_ordering = $5;
5755 | '(' a_expr ')' opt_collate opt_class opt_asc_desc opt_nulls_order
5757 $$ = makeNode(IndexElem);
5760 $$->indexcolname = NULL;
5764 $$->nulls_ordering = $7;
5768 opt_collate: COLLATE any_name { $$ = $2; }
5769 | /*EMPTY*/ { $$ = NIL; }
5772 opt_class: any_name { $$ = $1; }
5773 | USING any_name { $$ = $2; }
5774 | /*EMPTY*/ { $$ = NIL; }
5777 opt_asc_desc: ASC { $$ = SORTBY_ASC; }
5778 | DESC { $$ = SORTBY_DESC; }
5779 | /*EMPTY*/ { $$ = SORTBY_DEFAULT; }
5782 opt_nulls_order: NULLS_FIRST { $$ = SORTBY_NULLS_FIRST; }
5783 | NULLS_LAST { $$ = SORTBY_NULLS_LAST; }
5784 | /*EMPTY*/ { $$ = SORTBY_NULLS_DEFAULT; }
5788 /*****************************************************************************
5791 * create [or replace] function <fname>
5792 * [(<type-1> { , <type-n>})]
5794 * as <filename or code in language as appropriate>
5795 * language <lang> [with parameters]
5797 *****************************************************************************/
5800 CREATE opt_or_replace FUNCTION func_name func_args_with_defaults
5801 RETURNS func_return createfunc_opt_list opt_definition
5803 CreateFunctionStmt *n = makeNode(CreateFunctionStmt);
5812 | CREATE opt_or_replace FUNCTION func_name func_args_with_defaults
5813 RETURNS TABLE '(' table_func_column_list ')' createfunc_opt_list opt_definition
5815 CreateFunctionStmt *n = makeNode(CreateFunctionStmt);
5818 n->parameters = mergeTableFuncParameters($5, $9);
5819 n->returnType = TableFuncTypeName($9);
5820 n->returnType->location = @7;
5822 n->withClause = $12;
5825 | CREATE opt_or_replace FUNCTION func_name func_args_with_defaults
5826 createfunc_opt_list opt_definition
5828 CreateFunctionStmt *n = makeNode(CreateFunctionStmt);
5832 n->returnType = NULL;
5840 OR REPLACE { $$ = TRUE; }
5841 | /*EMPTY*/ { $$ = FALSE; }
5844 func_args: '(' func_args_list ')' { $$ = $2; }
5845 | '(' ')' { $$ = NIL; }
5849 func_arg { $$ = list_make1($1); }
5850 | func_args_list ',' func_arg { $$ = lappend($1, $3); }
5854 * func_args_with_defaults is separate because we only want to accept
5855 * defaults in CREATE FUNCTION, not in ALTER etc.
5857 func_args_with_defaults:
5858 '(' func_args_with_defaults_list ')' { $$ = $2; }
5859 | '(' ')' { $$ = NIL; }
5862 func_args_with_defaults_list:
5863 func_arg_with_default { $$ = list_make1($1); }
5864 | func_args_with_defaults_list ',' func_arg_with_default
5865 { $$ = lappend($1, $3); }
5869 * The style with arg_class first is SQL99 standard, but Oracle puts
5870 * param_name first; accept both since it's likely people will try both
5871 * anyway. Don't bother trying to save productions by letting arg_class
5872 * have an empty alternative ... you'll get shift/reduce conflicts.
5874 * We can catch over-specified arguments here if we want to,
5875 * but for now better to silently swallow typmod, etc.
5876 * - thomas 2000-03-22
5879 arg_class param_name func_type
5881 FunctionParameter *n = makeNode(FunctionParameter);
5888 | param_name arg_class func_type
5890 FunctionParameter *n = makeNode(FunctionParameter);
5897 | param_name func_type
5899 FunctionParameter *n = makeNode(FunctionParameter);
5902 n->mode = FUNC_PARAM_IN;
5906 | arg_class func_type
5908 FunctionParameter *n = makeNode(FunctionParameter);
5917 FunctionParameter *n = makeNode(FunctionParameter);
5920 n->mode = FUNC_PARAM_IN;
5926 /* INOUT is SQL99 standard, IN OUT is for Oracle compatibility */
5927 arg_class: IN_P { $$ = FUNC_PARAM_IN; }
5928 | OUT_P { $$ = FUNC_PARAM_OUT; }
5929 | INOUT { $$ = FUNC_PARAM_INOUT; }
5930 | IN_P OUT_P { $$ = FUNC_PARAM_INOUT; }
5931 | VARIADIC { $$ = FUNC_PARAM_VARIADIC; }
5935 * Ideally param_name should be ColId, but that causes too many conflicts.
5937 param_name: type_function_name
5943 /* We can catch over-specified results here if we want to,
5944 * but for now better to silently swallow typmod, etc.
5945 * - thomas 2000-03-22
5952 * We would like to make the %TYPE productions here be ColId attrs etc,
5953 * but that causes reduce/reduce conflicts. type_function_name
5954 * is next best choice.
5956 func_type: Typename { $$ = $1; }
5957 | type_function_name attrs '%' TYPE_P
5959 $$ = makeTypeNameFromNameList(lcons(makeString($1), $2));
5960 $$->pct_type = true;
5963 | SETOF type_function_name attrs '%' TYPE_P
5965 $$ = makeTypeNameFromNameList(lcons(makeString($2), $3));
5966 $$->pct_type = true;
5972 func_arg_with_default:
5977 | func_arg DEFAULT a_expr
5982 | func_arg '=' a_expr
5990 createfunc_opt_list:
5991 /* Must be at least one to prevent conflict */
5992 createfunc_opt_item { $$ = list_make1($1); }
5993 | createfunc_opt_list createfunc_opt_item { $$ = lappend($1, $2); }
5997 * Options common to both CREATE FUNCTION and ALTER FUNCTION
5999 common_func_opt_item:
6000 CALLED ON NULL_P INPUT_P
6002 $$ = makeDefElem("strict", (Node *)makeInteger(FALSE));
6004 | RETURNS NULL_P ON NULL_P INPUT_P
6006 $$ = makeDefElem("strict", (Node *)makeInteger(TRUE));
6010 $$ = makeDefElem("strict", (Node *)makeInteger(TRUE));
6014 $$ = makeDefElem("volatility", (Node *)makeString("immutable"));
6018 $$ = makeDefElem("volatility", (Node *)makeString("stable"));
6022 $$ = makeDefElem("volatility", (Node *)makeString("volatile"));
6024 | EXTERNAL SECURITY DEFINER
6026 $$ = makeDefElem("security", (Node *)makeInteger(TRUE));
6028 | EXTERNAL SECURITY INVOKER
6030 $$ = makeDefElem("security", (Node *)makeInteger(FALSE));
6034 $$ = makeDefElem("security", (Node *)makeInteger(TRUE));
6038 $$ = makeDefElem("security", (Node *)makeInteger(FALSE));
6042 $$ = makeDefElem("cost", (Node *)$2);
6046 $$ = makeDefElem("rows", (Node *)$2);
6050 /* we abuse the normal content of a DefElem here */
6051 $$ = makeDefElem("set", (Node *)$1);
6055 createfunc_opt_item:
6058 $$ = makeDefElem("as", (Node *)$2);
6060 | LANGUAGE ColId_or_Sconst
6062 $$ = makeDefElem("language", (Node *)makeString($2));
6066 $$ = makeDefElem("window", (Node *)makeInteger(TRUE));
6068 | common_func_opt_item
6074 func_as: Sconst { $$ = list_make1(makeString($1)); }
6077 $$ = list_make2(makeString($1), makeString($3));
6082 WITH definition { $$ = $2; }
6083 | /*EMPTY*/ { $$ = NIL; }
6086 table_func_column: param_name func_type
6088 FunctionParameter *n = makeNode(FunctionParameter);
6091 n->mode = FUNC_PARAM_TABLE;
6097 table_func_column_list:
6100 $$ = list_make1($1);
6102 | table_func_column_list ',' table_func_column
6104 $$ = lappend($1, $3);
6108 /*****************************************************************************
6111 * RENAME and OWNER subcommands are already provided by the generic
6112 * ALTER infrastructure, here we just specify alterations that can
6113 * only be applied to functions.
6115 *****************************************************************************/
6117 ALTER FUNCTION function_with_argtypes alterfunc_opt_list opt_restrict
6119 AlterFunctionStmt *n = makeNode(AlterFunctionStmt);
6127 /* At least one option must be specified */
6128 common_func_opt_item { $$ = list_make1($1); }
6129 | alterfunc_opt_list common_func_opt_item { $$ = lappend($1, $2); }
6132 /* Ignored, merely for SQL compliance */
6139 /*****************************************************************************
6143 * DROP FUNCTION funcname (arg1, arg2, ...) [ RESTRICT | CASCADE ]
6144 * DROP AGGREGATE aggname (arg1, ...) [ RESTRICT | CASCADE ]
6145 * DROP OPERATOR opname (leftoperand_typ, rightoperand_typ) [ RESTRICT | CASCADE ]
6147 *****************************************************************************/
6150 DROP FUNCTION func_name func_args opt_drop_behavior
6152 RemoveFuncStmt *n = makeNode(RemoveFuncStmt);
6153 n->kind = OBJECT_FUNCTION;
6155 n->args = extractArgTypes($4);
6157 n->missing_ok = false;
6160 | DROP FUNCTION IF_P EXISTS func_name func_args opt_drop_behavior
6162 RemoveFuncStmt *n = makeNode(RemoveFuncStmt);
6163 n->kind = OBJECT_FUNCTION;
6165 n->args = extractArgTypes($6);
6167 n->missing_ok = true;
6173 DROP AGGREGATE func_name aggr_args opt_drop_behavior
6175 RemoveFuncStmt *n = makeNode(RemoveFuncStmt);
6176 n->kind = OBJECT_AGGREGATE;
6180 n->missing_ok = false;
6183 | DROP AGGREGATE IF_P EXISTS func_name aggr_args opt_drop_behavior
6185 RemoveFuncStmt *n = makeNode(RemoveFuncStmt);
6186 n->kind = OBJECT_AGGREGATE;
6190 n->missing_ok = true;
6196 DROP OPERATOR any_operator oper_argtypes opt_drop_behavior
6198 RemoveFuncStmt *n = makeNode(RemoveFuncStmt);
6199 n->kind = OBJECT_OPERATOR;
6203 n->missing_ok = false;
6206 | DROP OPERATOR IF_P EXISTS any_operator oper_argtypes opt_drop_behavior
6208 RemoveFuncStmt *n = makeNode(RemoveFuncStmt);
6209 n->kind = OBJECT_OPERATOR;
6213 n->missing_ok = true;
6222 (errcode(ERRCODE_SYNTAX_ERROR),
6223 errmsg("missing argument"),
6224 errhint("Use NONE to denote the missing argument of a unary operator."),
6225 parser_errposition(@3)));
6227 | '(' Typename ',' Typename ')'
6228 { $$ = list_make2($2, $4); }
6229 | '(' NONE ',' Typename ')' /* left unary */
6230 { $$ = list_make2(NULL, $4); }
6231 | '(' Typename ',' NONE ')' /* right unary */
6232 { $$ = list_make2($2, NULL); }
6237 { $$ = list_make1(makeString($1)); }
6238 | ColId '.' any_operator
6239 { $$ = lcons(makeString($1), $3); }
6242 /*****************************************************************************
6244 * DO <anonymous code block> [ LANGUAGE language ]
6246 * We use a DefElem list for future extensibility, and to allow flexibility
6247 * in the clause order.
6249 *****************************************************************************/
6251 DoStmt: DO dostmt_opt_list
6253 DoStmt *n = makeNode(DoStmt);
6260 dostmt_opt_item { $$ = list_make1($1); }
6261 | dostmt_opt_list dostmt_opt_item { $$ = lappend($1, $2); }
6267 $$ = makeDefElem("as", (Node *)makeString($1));
6269 | LANGUAGE ColId_or_Sconst
6271 $$ = makeDefElem("language", (Node *)makeString($2));
6275 /*****************************************************************************
6277 * CREATE CAST / DROP CAST
6279 *****************************************************************************/
6281 CreateCastStmt: CREATE CAST '(' Typename AS Typename ')'
6282 WITH FUNCTION function_with_argtypes cast_context
6284 CreateCastStmt *n = makeNode(CreateCastStmt);
6288 n->context = (CoercionContext) $11;
6292 | CREATE CAST '(' Typename AS Typename ')'
6293 WITHOUT FUNCTION cast_context
6295 CreateCastStmt *n = makeNode(CreateCastStmt);
6299 n->context = (CoercionContext) $10;
6303 | CREATE CAST '(' Typename AS Typename ')'
6304 WITH INOUT cast_context
6306 CreateCastStmt *n = makeNode(CreateCastStmt);
6310 n->context = (CoercionContext) $10;
6316 cast_context: AS IMPLICIT_P { $$ = COERCION_IMPLICIT; }
6317 | AS ASSIGNMENT { $$ = COERCION_ASSIGNMENT; }
6318 | /*EMPTY*/ { $$ = COERCION_EXPLICIT; }
6322 DropCastStmt: DROP CAST opt_if_exists '(' Typename AS Typename ')' opt_drop_behavior
6324 DropCastStmt *n = makeNode(DropCastStmt);
6333 opt_if_exists: IF_P EXISTS { $$ = TRUE; }
6334 | /*EMPTY*/ { $$ = FALSE; }
6338 /*****************************************************************************
6342 * REINDEX type <name> [FORCE]
6344 * FORCE no longer does anything, but we accept it for backwards compatibility
6345 *****************************************************************************/
6348 REINDEX reindex_type qualified_name opt_force
6350 ReindexStmt *n = makeNode(ReindexStmt);
6356 | REINDEX SYSTEM_P name opt_force
6358 ReindexStmt *n = makeNode(ReindexStmt);
6359 n->kind = OBJECT_DATABASE;
6362 n->do_system = true;
6366 | REINDEX DATABASE name opt_force
6368 ReindexStmt *n = makeNode(ReindexStmt);
6369 n->kind = OBJECT_DATABASE;
6372 n->do_system = true;
6379 INDEX { $$ = OBJECT_INDEX; }
6380 | TABLE { $$ = OBJECT_TABLE; }
6383 opt_force: FORCE { $$ = TRUE; }
6384 | /* EMPTY */ { $$ = FALSE; }
6388 /*****************************************************************************
6390 * ALTER THING name RENAME TO newname
6392 *****************************************************************************/
6394 RenameStmt: ALTER AGGREGATE func_name aggr_args RENAME TO name
6396 RenameStmt *n = makeNode(RenameStmt);
6397 n->renameType = OBJECT_AGGREGATE;
6403 | ALTER COLLATION any_name RENAME TO name
6405 RenameStmt *n = makeNode(RenameStmt);
6406 n->renameType = OBJECT_COLLATION;
6411 | ALTER CONVERSION_P any_name RENAME TO name
6413 RenameStmt *n = makeNode(RenameStmt);
6414 n->renameType = OBJECT_CONVERSION;
6419 | ALTER DATABASE database_name RENAME TO database_name
6421 RenameStmt *n = makeNode(RenameStmt);
6422 n->renameType = OBJECT_DATABASE;
6427 | ALTER FUNCTION function_with_argtypes RENAME TO name
6429 RenameStmt *n = makeNode(RenameStmt);
6430 n->renameType = OBJECT_FUNCTION;
6431 n->object = $3->funcname;
6432 n->objarg = $3->funcargs;
6436 | ALTER GROUP_P RoleId RENAME TO RoleId
6438 RenameStmt *n = makeNode(RenameStmt);
6439 n->renameType = OBJECT_ROLE;
6444 | ALTER opt_procedural LANGUAGE name RENAME TO name
6446 RenameStmt *n = makeNode(RenameStmt);
6447 n->renameType = OBJECT_LANGUAGE;
6452 | ALTER OPERATOR CLASS any_name USING access_method RENAME TO name
6454 RenameStmt *n = makeNode(RenameStmt);
6455 n->renameType = OBJECT_OPCLASS;
6461 | ALTER OPERATOR FAMILY any_name USING access_method RENAME TO name
6463 RenameStmt *n = makeNode(RenameStmt);
6464 n->renameType = OBJECT_OPFAMILY;
6470 | ALTER SCHEMA name RENAME TO name
6472 RenameStmt *n = makeNode(RenameStmt);
6473 n->renameType = OBJECT_SCHEMA;
6478 | ALTER TABLE relation_expr RENAME TO name
6480 RenameStmt *n = makeNode(RenameStmt);
6481 n->renameType = OBJECT_TABLE;
6487 | ALTER SEQUENCE qualified_name RENAME TO name
6489 RenameStmt *n = makeNode(RenameStmt);
6490 n->renameType = OBJECT_SEQUENCE;
6496 | ALTER VIEW qualified_name RENAME TO name
6498 RenameStmt *n = makeNode(RenameStmt);
6499 n->renameType = OBJECT_VIEW;
6505 | ALTER INDEX qualified_name RENAME TO name
6507 RenameStmt *n = makeNode(RenameStmt);
6508 n->renameType = OBJECT_INDEX;
6514 | ALTER FOREIGN TABLE relation_expr RENAME TO name
6516 RenameStmt *n = makeNode(RenameStmt);
6517 n->renameType = OBJECT_FOREIGN_TABLE;
6523 | ALTER TABLE relation_expr RENAME opt_column name TO name
6525 RenameStmt *n = makeNode(RenameStmt);
6526 n->renameType = OBJECT_COLUMN;
6527 n->relationType = OBJECT_TABLE;
6533 | ALTER FOREIGN TABLE relation_expr RENAME opt_column name TO name
6535 RenameStmt *n = makeNode(RenameStmt);
6536 n->renameType = OBJECT_COLUMN;
6537 n->relationType = OBJECT_FOREIGN_TABLE;
6543 | ALTER TRIGGER name ON qualified_name RENAME TO name
6545 RenameStmt *n = makeNode(RenameStmt);
6546 n->renameType = OBJECT_TRIGGER;
6552 | ALTER ROLE RoleId RENAME TO RoleId
6554 RenameStmt *n = makeNode(RenameStmt);
6555 n->renameType = OBJECT_ROLE;
6560 | ALTER USER RoleId RENAME TO RoleId
6562 RenameStmt *n = makeNode(RenameStmt);
6563 n->renameType = OBJECT_ROLE;
6568 | ALTER TABLESPACE name RENAME TO name
6570 RenameStmt *n = makeNode(RenameStmt);
6571 n->renameType = OBJECT_TABLESPACE;
6576 | ALTER TABLESPACE name SET reloptions
6578 AlterTableSpaceOptionsStmt *n =
6579 makeNode(AlterTableSpaceOptionsStmt);
6580 n->tablespacename = $3;
6585 | ALTER TABLESPACE name RESET reloptions
6587 AlterTableSpaceOptionsStmt *n =
6588 makeNode(AlterTableSpaceOptionsStmt);
6589 n->tablespacename = $3;
6594 | ALTER TEXT_P SEARCH PARSER any_name RENAME TO name
6596 RenameStmt *n = makeNode(RenameStmt);
6597 n->renameType = OBJECT_TSPARSER;
6602 | ALTER TEXT_P SEARCH DICTIONARY any_name RENAME TO name
6604 RenameStmt *n = makeNode(RenameStmt);
6605 n->renameType = OBJECT_TSDICTIONARY;
6610 | ALTER TEXT_P SEARCH TEMPLATE any_name RENAME TO name
6612 RenameStmt *n = makeNode(RenameStmt);
6613 n->renameType = OBJECT_TSTEMPLATE;
6618 | ALTER TEXT_P SEARCH CONFIGURATION any_name RENAME TO name
6620 RenameStmt *n = makeNode(RenameStmt);
6621 n->renameType = OBJECT_TSCONFIGURATION;
6626 | ALTER TYPE_P any_name RENAME TO name
6628 RenameStmt *n = makeNode(RenameStmt);
6629 n->renameType = OBJECT_TYPE;
6634 | ALTER TYPE_P any_name RENAME ATTRIBUTE name TO name opt_drop_behavior
6636 RenameStmt *n = makeNode(RenameStmt);
6637 n->renameType = OBJECT_ATTRIBUTE;
6638 n->relationType = OBJECT_TYPE;
6639 n->relation = makeRangeVarFromAnyName($3, @3, yyscanner);
6647 opt_column: COLUMN { $$ = COLUMN; }
6648 | /*EMPTY*/ { $$ = 0; }
6651 opt_set_data: SET DATA_P { $$ = 1; }
6652 | /*EMPTY*/ { $$ = 0; }
6655 /*****************************************************************************
6657 * ALTER THING name SET SCHEMA name
6659 *****************************************************************************/
6661 AlterObjectSchemaStmt:
6662 ALTER AGGREGATE func_name aggr_args SET SCHEMA name
6664 AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
6665 n->objectType = OBJECT_AGGREGATE;
6671 | ALTER COLLATION any_name SET SCHEMA name
6673 AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
6674 n->objectType = OBJECT_COLLATION;
6679 | ALTER CONVERSION_P any_name SET SCHEMA name
6681 AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
6682 n->objectType = OBJECT_CONVERSION;
6687 | ALTER DOMAIN_P any_name SET SCHEMA name
6689 AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
6690 n->objectType = OBJECT_DOMAIN;
6695 | ALTER EXTENSION any_name SET SCHEMA name
6697 AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
6698 n->objectType = OBJECT_EXTENSION;
6703 | ALTER FUNCTION function_with_argtypes SET SCHEMA name
6705 AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
6706 n->objectType = OBJECT_FUNCTION;
6707 n->object = $3->funcname;
6708 n->objarg = $3->funcargs;
6712 | ALTER OPERATOR any_operator oper_argtypes SET SCHEMA name
6714 AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
6715 n->objectType = OBJECT_OPERATOR;
6721 | ALTER OPERATOR CLASS any_name USING access_method SET SCHEMA name
6723 AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
6724 n->objectType = OBJECT_OPCLASS;
6730 | ALTER OPERATOR FAMILY any_name USING access_method SET SCHEMA name
6732 AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
6733 n->objectType = OBJECT_OPFAMILY;
6739 | ALTER TABLE relation_expr SET SCHEMA name
6741 AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
6742 n->objectType = OBJECT_TABLE;
6747 | ALTER TEXT_P SEARCH PARSER any_name SET SCHEMA name
6749 AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
6750 n->objectType = OBJECT_TSPARSER;
6755 | ALTER TEXT_P SEARCH DICTIONARY any_name SET SCHEMA name
6757 AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
6758 n->objectType = OBJECT_TSDICTIONARY;
6763 | ALTER TEXT_P SEARCH TEMPLATE any_name SET SCHEMA name
6765 AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
6766 n->objectType = OBJECT_TSTEMPLATE;
6771 | ALTER TEXT_P SEARCH CONFIGURATION any_name SET SCHEMA name
6773 AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
6774 n->objectType = OBJECT_TSCONFIGURATION;
6779 | ALTER SEQUENCE qualified_name SET SCHEMA name
6781 AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
6782 n->objectType = OBJECT_SEQUENCE;
6787 | ALTER VIEW qualified_name SET SCHEMA name
6789 AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
6790 n->objectType = OBJECT_VIEW;
6795 | ALTER FOREIGN TABLE relation_expr SET SCHEMA name
6797 AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
6798 n->objectType = OBJECT_FOREIGN_TABLE;
6803 | ALTER TYPE_P any_name SET SCHEMA name
6805 AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
6806 n->objectType = OBJECT_TYPE;
6813 /*****************************************************************************
6815 * ALTER THING name OWNER TO newname
6817 *****************************************************************************/
6819 AlterOwnerStmt: ALTER AGGREGATE func_name aggr_args OWNER TO RoleId
6821 AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
6822 n->objectType = OBJECT_AGGREGATE;
6828 | ALTER COLLATION any_name OWNER TO RoleId
6830 AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
6831 n->objectType = OBJECT_COLLATION;
6836 | ALTER CONVERSION_P any_name OWNER TO RoleId
6838 AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
6839 n->objectType = OBJECT_CONVERSION;
6844 | ALTER DATABASE database_name OWNER TO RoleId
6846 AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
6847 n->objectType = OBJECT_DATABASE;
6848 n->object = list_make1(makeString($3));
6852 | ALTER DOMAIN_P any_name OWNER TO RoleId
6854 AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
6855 n->objectType = OBJECT_DOMAIN;
6860 | ALTER FUNCTION function_with_argtypes OWNER TO RoleId
6862 AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
6863 n->objectType = OBJECT_FUNCTION;
6864 n->object = $3->funcname;
6865 n->objarg = $3->funcargs;
6869 | ALTER opt_procedural LANGUAGE name OWNER TO RoleId
6871 AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
6872 n->objectType = OBJECT_LANGUAGE;
6873 n->object = list_make1(makeString($4));
6877 | ALTER LARGE_P OBJECT_P NumericOnly OWNER TO RoleId
6879 AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
6880 n->objectType = OBJECT_LARGEOBJECT;
6881 n->object = list_make1($4);
6885 | ALTER OPERATOR any_operator oper_argtypes OWNER TO RoleId
6887 AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
6888 n->objectType = OBJECT_OPERATOR;
6894 | ALTER OPERATOR CLASS any_name USING access_method OWNER TO RoleId
6896 AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
6897 n->objectType = OBJECT_OPCLASS;
6903 | ALTER OPERATOR FAMILY any_name USING access_method OWNER TO RoleId
6905 AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
6906 n->objectType = OBJECT_OPFAMILY;
6912 | ALTER SCHEMA name OWNER TO RoleId
6914 AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
6915 n->objectType = OBJECT_SCHEMA;
6916 n->object = list_make1(makeString($3));
6920 | ALTER TYPE_P any_name OWNER TO RoleId
6922 AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
6923 n->objectType = OBJECT_TYPE;
6928 | ALTER TABLESPACE name OWNER TO RoleId
6930 AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
6931 n->objectType = OBJECT_TABLESPACE;
6932 n->object = list_make1(makeString($3));
6936 | ALTER TEXT_P SEARCH DICTIONARY any_name OWNER TO RoleId
6938 AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
6939 n->objectType = OBJECT_TSDICTIONARY;
6944 | ALTER TEXT_P SEARCH CONFIGURATION any_name OWNER TO RoleId
6946 AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
6947 n->objectType = OBJECT_TSCONFIGURATION;
6952 | ALTER FOREIGN DATA_P WRAPPER name OWNER TO RoleId
6954 AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
6955 n->objectType = OBJECT_FDW;
6956 n->object = list_make1(makeString($5));
6960 | ALTER SERVER name OWNER TO RoleId
6962 AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
6963 n->objectType = OBJECT_FOREIGN_SERVER;
6964 n->object = list_make1(makeString($3));
6971 /*****************************************************************************
6973 * QUERY: Define Rewrite Rule
6975 *****************************************************************************/
6977 RuleStmt: CREATE opt_or_replace RULE name AS
6978 ON event TO qualified_name where_clause
6979 DO opt_instead RuleActionList
6981 RuleStmt *n = makeNode(RuleStmt);
6985 n->whereClause = $10;
6994 NOTHING { $$ = NIL; }
6995 | RuleActionStmt { $$ = list_make1($1); }
6996 | '(' RuleActionMulti ')' { $$ = $2; }
6999 /* the thrashing around here is to discard "empty" statements... */
7001 RuleActionMulti ';' RuleActionStmtOrEmpty
7003 $$ = lappend($1, $3);
7007 | RuleActionStmtOrEmpty
7009 $$ = list_make1($1);
7023 RuleActionStmtOrEmpty:
7024 RuleActionStmt { $$ = $1; }
7025 | /*EMPTY*/ { $$ = NULL; }
7028 event: SELECT { $$ = CMD_SELECT; }
7029 | UPDATE { $$ = CMD_UPDATE; }
7030 | DELETE_P { $$ = CMD_DELETE; }
7031 | INSERT { $$ = CMD_INSERT; }
7035 INSTEAD { $$ = TRUE; }
7036 | ALSO { $$ = FALSE; }
7037 | /*EMPTY*/ { $$ = FALSE; }
7042 DROP RULE name ON qualified_name opt_drop_behavior
7044 DropPropertyStmt *n = makeNode(DropPropertyStmt);
7048 n->removeType = OBJECT_RULE;
7049 n->missing_ok = false;
7052 | DROP RULE IF_P EXISTS name ON qualified_name opt_drop_behavior
7054 DropPropertyStmt *n = makeNode(DropPropertyStmt);
7058 n->removeType = OBJECT_RULE;
7059 n->missing_ok = true;
7065 /*****************************************************************************
7068 * NOTIFY <identifier> can appear both in rule bodies and
7069 * as a query-level command
7071 *****************************************************************************/
7073 NotifyStmt: NOTIFY ColId notify_payload
7075 NotifyStmt *n = makeNode(NotifyStmt);
7076 n->conditionname = $2;
7083 ',' Sconst { $$ = $2; }
7084 | /*EMPTY*/ { $$ = NULL; }
7087 ListenStmt: LISTEN ColId
7089 ListenStmt *n = makeNode(ListenStmt);
7090 n->conditionname = $2;
7098 UnlistenStmt *n = makeNode(UnlistenStmt);
7099 n->conditionname = $2;
7104 UnlistenStmt *n = makeNode(UnlistenStmt);
7105 n->conditionname = NULL;
7111 /*****************************************************************************
7115 * BEGIN / COMMIT / ROLLBACK
7116 * (also older versions END / ABORT)
7118 *****************************************************************************/
7121 ABORT_P opt_transaction
7123 TransactionStmt *n = makeNode(TransactionStmt);
7124 n->kind = TRANS_STMT_ROLLBACK;
7128 | BEGIN_P opt_transaction transaction_mode_list_or_empty
7130 TransactionStmt *n = makeNode(TransactionStmt);
7131 n->kind = TRANS_STMT_BEGIN;
7135 | START TRANSACTION transaction_mode_list_or_empty
7137 TransactionStmt *n = makeNode(TransactionStmt);
7138 n->kind = TRANS_STMT_START;
7142 | COMMIT opt_transaction
7144 TransactionStmt *n = makeNode(TransactionStmt);
7145 n->kind = TRANS_STMT_COMMIT;
7149 | END_P opt_transaction
7151 TransactionStmt *n = makeNode(TransactionStmt);
7152 n->kind = TRANS_STMT_COMMIT;
7156 | ROLLBACK opt_transaction
7158 TransactionStmt *n = makeNode(TransactionStmt);
7159 n->kind = TRANS_STMT_ROLLBACK;
7165 TransactionStmt *n = makeNode(TransactionStmt);
7166 n->kind = TRANS_STMT_SAVEPOINT;
7167 n->options = list_make1(makeDefElem("savepoint_name",
7168 (Node *)makeString($2)));
7171 | RELEASE SAVEPOINT ColId
7173 TransactionStmt *n = makeNode(TransactionStmt);
7174 n->kind = TRANS_STMT_RELEASE;
7175 n->options = list_make1(makeDefElem("savepoint_name",
7176 (Node *)makeString($3)));
7181 TransactionStmt *n = makeNode(TransactionStmt);
7182 n->kind = TRANS_STMT_RELEASE;
7183 n->options = list_make1(makeDefElem("savepoint_name",
7184 (Node *)makeString($2)));
7187 | ROLLBACK opt_transaction TO SAVEPOINT ColId
7189 TransactionStmt *n = makeNode(TransactionStmt);
7190 n->kind = TRANS_STMT_ROLLBACK_TO;
7191 n->options = list_make1(makeDefElem("savepoint_name",
7192 (Node *)makeString($5)));
7195 | ROLLBACK opt_transaction TO ColId
7197 TransactionStmt *n = makeNode(TransactionStmt);
7198 n->kind = TRANS_STMT_ROLLBACK_TO;
7199 n->options = list_make1(makeDefElem("savepoint_name",
7200 (Node *)makeString($4)));
7203 | PREPARE TRANSACTION Sconst
7205 TransactionStmt *n = makeNode(TransactionStmt);
7206 n->kind = TRANS_STMT_PREPARE;
7210 | COMMIT PREPARED Sconst
7212 TransactionStmt *n = makeNode(TransactionStmt);
7213 n->kind = TRANS_STMT_COMMIT_PREPARED;
7217 | ROLLBACK PREPARED Sconst
7219 TransactionStmt *n = makeNode(TransactionStmt);
7220 n->kind = TRANS_STMT_ROLLBACK_PREPARED;
7226 opt_transaction: WORK {}
7231 transaction_mode_item:
7232 ISOLATION LEVEL iso_level
7233 { $$ = makeDefElem("transaction_isolation",
7234 makeStringConst($3, @3)); }
7236 { $$ = makeDefElem("transaction_read_only",
7237 makeIntConst(TRUE, @1)); }
7239 { $$ = makeDefElem("transaction_read_only",
7240 makeIntConst(FALSE, @1)); }
7242 { $$ = makeDefElem("transaction_deferrable",
7243 makeIntConst(TRUE, @1)); }
7245 { $$ = makeDefElem("transaction_deferrable",
7246 makeIntConst(FALSE, @1)); }
7249 /* Syntax with commas is SQL-spec, without commas is Postgres historical */
7250 transaction_mode_list:
7251 transaction_mode_item
7252 { $$ = list_make1($1); }
7253 | transaction_mode_list ',' transaction_mode_item
7254 { $$ = lappend($1, $3); }
7255 | transaction_mode_list transaction_mode_item
7256 { $$ = lappend($1, $2); }
7259 transaction_mode_list_or_empty:
7260 transaction_mode_list
7266 /*****************************************************************************
7269 * CREATE [ OR REPLACE ] [ TEMP ] VIEW <viewname> '('target-list ')'
7270 * AS <query> [ WITH [ CASCADED | LOCAL ] CHECK OPTION ]
7272 *****************************************************************************/
7274 ViewStmt: CREATE OptTemp VIEW qualified_name opt_column_list
7275 AS SelectStmt opt_check_option
7277 ViewStmt *n = makeNode(ViewStmt);
7279 n->view->relpersistence = $2;
7285 | CREATE OR REPLACE OptTemp VIEW qualified_name opt_column_list
7286 AS SelectStmt opt_check_option
7288 ViewStmt *n = makeNode(ViewStmt);
7290 n->view->relpersistence = $4;
7302 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
7303 errmsg("WITH CHECK OPTION is not implemented")));
7305 | WITH CASCADED CHECK OPTION
7308 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
7309 errmsg("WITH CHECK OPTION is not implemented")));
7311 | WITH LOCAL CHECK OPTION
7314 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
7315 errmsg("WITH CHECK OPTION is not implemented")));
7317 | /* EMPTY */ { $$ = NIL; }
7320 /*****************************************************************************
7325 *****************************************************************************/
7327 LoadStmt: LOAD file_name
7329 LoadStmt *n = makeNode(LoadStmt);
7336 /*****************************************************************************
7340 *****************************************************************************/
7343 CREATE DATABASE database_name opt_with createdb_opt_list
7345 CreatedbStmt *n = makeNode(CreatedbStmt);
7353 createdb_opt_list createdb_opt_item { $$ = lappend($1, $2); }
7354 | /* EMPTY */ { $$ = NIL; }
7358 TABLESPACE opt_equal name
7360 $$ = makeDefElem("tablespace", (Node *)makeString($3));
7362 | TABLESPACE opt_equal DEFAULT
7364 $$ = makeDefElem("tablespace", NULL);
7366 | LOCATION opt_equal Sconst
7368 $$ = makeDefElem("location", (Node *)makeString($3));
7370 | LOCATION opt_equal DEFAULT
7372 $$ = makeDefElem("location", NULL);
7374 | TEMPLATE opt_equal name
7376 $$ = makeDefElem("template", (Node *)makeString($3));
7378 | TEMPLATE opt_equal DEFAULT
7380 $$ = makeDefElem("template", NULL);
7382 | ENCODING opt_equal Sconst
7384 $$ = makeDefElem("encoding", (Node *)makeString($3));
7386 | ENCODING opt_equal Iconst
7388 $$ = makeDefElem("encoding", (Node *)makeInteger($3));
7390 | ENCODING opt_equal DEFAULT
7392 $$ = makeDefElem("encoding", NULL);
7394 | LC_COLLATE_P opt_equal Sconst
7396 $$ = makeDefElem("lc_collate", (Node *)makeString($3));
7398 | LC_COLLATE_P opt_equal DEFAULT
7400 $$ = makeDefElem("lc_collate", NULL);
7402 | LC_CTYPE_P opt_equal Sconst
7404 $$ = makeDefElem("lc_ctype", (Node *)makeString($3));
7406 | LC_CTYPE_P opt_equal DEFAULT
7408 $$ = makeDefElem("lc_ctype", NULL);
7410 | CONNECTION LIMIT opt_equal SignedIconst
7412 $$ = makeDefElem("connectionlimit", (Node *)makeInteger($4));
7414 | OWNER opt_equal name
7416 $$ = makeDefElem("owner", (Node *)makeString($3));
7418 | OWNER opt_equal DEFAULT
7420 $$ = makeDefElem("owner", NULL);
7425 * Though the equals sign doesn't match other WITH options, pg_dump uses
7426 * equals for backward compatibility, and it doesn't seem worth removing it.
7433 /*****************************************************************************
7437 *****************************************************************************/
7440 ALTER DATABASE database_name opt_with alterdb_opt_list
7442 AlterDatabaseStmt *n = makeNode(AlterDatabaseStmt);
7447 | ALTER DATABASE database_name SET TABLESPACE name
7449 AlterDatabaseStmt *n = makeNode(AlterDatabaseStmt);
7451 n->options = list_make1(makeDefElem("tablespace",
7452 (Node *)makeString($6)));
7457 AlterDatabaseSetStmt:
7458 ALTER DATABASE database_name SetResetClause
7460 AlterDatabaseSetStmt *n = makeNode(AlterDatabaseSetStmt);
7469 alterdb_opt_list alterdb_opt_item { $$ = lappend($1, $2); }
7470 | /* EMPTY */ { $$ = NIL; }
7474 CONNECTION LIMIT opt_equal SignedIconst
7476 $$ = makeDefElem("connectionlimit", (Node *)makeInteger($4));
7481 /*****************************************************************************
7483 * DROP DATABASE [ IF EXISTS ]
7485 * This is implicitly CASCADE, no need for drop behavior
7486 *****************************************************************************/
7488 DropdbStmt: DROP DATABASE database_name
7490 DropdbStmt *n = makeNode(DropdbStmt);
7492 n->missing_ok = FALSE;
7495 | DROP DATABASE IF_P EXISTS database_name
7497 DropdbStmt *n = makeNode(DropdbStmt);
7499 n->missing_ok = TRUE;
7505 /*****************************************************************************
7507 * Manipulate a domain
7509 *****************************************************************************/
7512 CREATE DOMAIN_P any_name opt_as Typename ColQualList
7514 CreateDomainStmt *n = makeNode(CreateDomainStmt);
7517 SplitColQualList($6, &n->constraints, &n->collClause,
7524 /* ALTER DOMAIN <domain> {SET DEFAULT <expr>|DROP DEFAULT} */
7525 ALTER DOMAIN_P any_name alter_column_default
7527 AlterDomainStmt *n = makeNode(AlterDomainStmt);
7533 /* ALTER DOMAIN <domain> DROP NOT NULL */
7534 | ALTER DOMAIN_P any_name DROP NOT NULL_P
7536 AlterDomainStmt *n = makeNode(AlterDomainStmt);
7541 /* ALTER DOMAIN <domain> SET NOT NULL */
7542 | ALTER DOMAIN_P any_name SET NOT NULL_P
7544 AlterDomainStmt *n = makeNode(AlterDomainStmt);
7549 /* ALTER DOMAIN <domain> ADD CONSTRAINT ... */
7550 | ALTER DOMAIN_P any_name ADD_P TableConstraint
7552 AlterDomainStmt *n = makeNode(AlterDomainStmt);
7558 /* ALTER DOMAIN <domain> DROP CONSTRAINT <name> [RESTRICT|CASCADE] */
7559 | ALTER DOMAIN_P any_name DROP CONSTRAINT name opt_drop_behavior
7561 AlterDomainStmt *n = makeNode(AlterDomainStmt);
7575 /*****************************************************************************
7577 * Manipulate a text search dictionary or configuration
7579 *****************************************************************************/
7581 AlterTSDictionaryStmt:
7582 ALTER TEXT_P SEARCH DICTIONARY any_name definition
7584 AlterTSDictionaryStmt *n = makeNode(AlterTSDictionaryStmt);
7591 AlterTSConfigurationStmt:
7592 ALTER TEXT_P SEARCH CONFIGURATION any_name ADD_P MAPPING FOR name_list WITH any_name_list
7594 AlterTSConfigurationStmt *n = makeNode(AlterTSConfigurationStmt);
7598 n->override = false;
7602 | ALTER TEXT_P SEARCH CONFIGURATION any_name ALTER MAPPING FOR name_list WITH any_name_list
7604 AlterTSConfigurationStmt *n = makeNode(AlterTSConfigurationStmt);
7612 | ALTER TEXT_P SEARCH CONFIGURATION any_name ALTER MAPPING REPLACE any_name WITH any_name
7614 AlterTSConfigurationStmt *n = makeNode(AlterTSConfigurationStmt);
7617 n->dicts = list_make2($9,$11);
7618 n->override = false;
7622 | ALTER TEXT_P SEARCH CONFIGURATION any_name ALTER MAPPING FOR name_list REPLACE any_name WITH any_name
7624 AlterTSConfigurationStmt *n = makeNode(AlterTSConfigurationStmt);
7627 n->dicts = list_make2($11,$13);
7628 n->override = false;
7632 | ALTER TEXT_P SEARCH CONFIGURATION any_name DROP MAPPING FOR name_list
7634 AlterTSConfigurationStmt *n = makeNode(AlterTSConfigurationStmt);
7637 n->missing_ok = false;
7640 | ALTER TEXT_P SEARCH CONFIGURATION any_name DROP MAPPING IF_P EXISTS FOR name_list
7642 AlterTSConfigurationStmt *n = makeNode(AlterTSConfigurationStmt);
7645 n->missing_ok = true;
7651 /*****************************************************************************
7653 * Manipulate a conversion
7655 * CREATE [DEFAULT] CONVERSION <conversion_name>
7656 * FOR <encoding_name> TO <encoding_name> FROM <func_name>
7658 *****************************************************************************/
7660 CreateConversionStmt:
7661 CREATE opt_default CONVERSION_P any_name FOR Sconst
7662 TO Sconst FROM any_name
7664 CreateConversionStmt *n = makeNode(CreateConversionStmt);
7665 n->conversion_name = $4;
7666 n->for_encoding_name = $6;
7667 n->to_encoding_name = $8;
7674 /*****************************************************************************
7677 * CLUSTER [VERBOSE] <qualified_name> [ USING <index_name> ]
7679 * CLUSTER [VERBOSE] <index_name> ON <qualified_name> (for pre-8.3)
7681 *****************************************************************************/
7684 CLUSTER opt_verbose qualified_name cluster_index_specification
7686 ClusterStmt *n = makeNode(ClusterStmt);
7692 | CLUSTER opt_verbose
7694 ClusterStmt *n = makeNode(ClusterStmt);
7696 n->indexname = NULL;
7700 /* kept for pre-8.3 compatibility */
7701 | CLUSTER opt_verbose index_name ON qualified_name
7703 ClusterStmt *n = makeNode(ClusterStmt);
7711 cluster_index_specification:
7712 USING index_name { $$ = $2; }
7713 | /*EMPTY*/ { $$ = NULL; }
7717 /*****************************************************************************
7723 *****************************************************************************/
7725 VacuumStmt: VACUUM opt_full opt_freeze opt_verbose
7727 VacuumStmt *n = makeNode(VacuumStmt);
7728 n->options = VACOPT_VACUUM;
7730 n->options |= VACOPT_FULL;
7732 n->options |= VACOPT_VERBOSE;
7733 n->freeze_min_age = $3 ? 0 : -1;
7734 n->freeze_table_age = $3 ? 0 : -1;
7739 | VACUUM opt_full opt_freeze opt_verbose qualified_name
7741 VacuumStmt *n = makeNode(VacuumStmt);
7742 n->options = VACOPT_VACUUM;
7744 n->options |= VACOPT_FULL;
7746 n->options |= VACOPT_VERBOSE;
7747 n->freeze_min_age = $3 ? 0 : -1;
7748 n->freeze_table_age = $3 ? 0 : -1;
7753 | VACUUM opt_full opt_freeze opt_verbose AnalyzeStmt
7755 VacuumStmt *n = (VacuumStmt *) $5;
7756 n->options |= VACOPT_VACUUM;
7758 n->options |= VACOPT_FULL;
7760 n->options |= VACOPT_VERBOSE;
7761 n->freeze_min_age = $3 ? 0 : -1;
7762 n->freeze_table_age = $3 ? 0 : -1;
7765 | VACUUM '(' vacuum_option_list ')'
7767 VacuumStmt *n = makeNode(VacuumStmt);
7768 n->options = VACOPT_VACUUM | $3;
7769 if (n->options & VACOPT_FREEZE)
7770 n->freeze_min_age = n->freeze_table_age = 0;
7772 n->freeze_min_age = n->freeze_table_age = -1;
7777 | VACUUM '(' vacuum_option_list ')' qualified_name opt_name_list
7779 VacuumStmt *n = makeNode(VacuumStmt);
7780 n->options = VACOPT_VACUUM | $3;
7781 if (n->options & VACOPT_FREEZE)
7782 n->freeze_min_age = n->freeze_table_age = 0;
7784 n->freeze_min_age = n->freeze_table_age = -1;
7787 if (n->va_cols != NIL) /* implies analyze */
7788 n->options |= VACOPT_ANALYZE;
7794 vacuum_option_elem { $$ = $1; }
7795 | vacuum_option_list ',' vacuum_option_elem { $$ = $1 | $3; }
7799 analyze_keyword { $$ = VACOPT_ANALYZE; }
7800 | VERBOSE { $$ = VACOPT_VERBOSE; }
7801 | FREEZE { $$ = VACOPT_FREEZE; }
7802 | FULL { $$ = VACOPT_FULL; }
7806 analyze_keyword opt_verbose
7808 VacuumStmt *n = makeNode(VacuumStmt);
7809 n->options = VACOPT_ANALYZE;
7811 n->options |= VACOPT_VERBOSE;
7812 n->freeze_min_age = -1;
7813 n->freeze_table_age = -1;
7818 | analyze_keyword opt_verbose qualified_name opt_name_list
7820 VacuumStmt *n = makeNode(VacuumStmt);
7821 n->options = VACOPT_ANALYZE;
7823 n->options |= VACOPT_VERBOSE;
7824 n->freeze_min_age = -1;
7825 n->freeze_table_age = -1;
7834 | ANALYSE /* British */ {}
7838 VERBOSE { $$ = TRUE; }
7839 | /*EMPTY*/ { $$ = FALSE; }
7842 opt_full: FULL { $$ = TRUE; }
7843 | /*EMPTY*/ { $$ = FALSE; }
7846 opt_freeze: FREEZE { $$ = TRUE; }
7847 | /*EMPTY*/ { $$ = FALSE; }
7851 '(' name_list ')' { $$ = $2; }
7852 | /*EMPTY*/ { $$ = NIL; }
7856 /*****************************************************************************
7859 * EXPLAIN [ANALYZE] [VERBOSE] query
7860 * EXPLAIN ( options ) query
7862 *****************************************************************************/
7865 EXPLAIN ExplainableStmt
7867 ExplainStmt *n = makeNode(ExplainStmt);
7872 | EXPLAIN analyze_keyword opt_verbose ExplainableStmt
7874 ExplainStmt *n = makeNode(ExplainStmt);
7876 n->options = list_make1(makeDefElem("analyze", NULL));
7878 n->options = lappend(n->options,
7879 makeDefElem("verbose", NULL));
7882 | EXPLAIN VERBOSE ExplainableStmt
7884 ExplainStmt *n = makeNode(ExplainStmt);
7886 n->options = list_make1(makeDefElem("verbose", NULL));
7889 | EXPLAIN '(' explain_option_list ')' ExplainableStmt
7891 ExplainStmt *n = makeNode(ExplainStmt);
7905 | ExecuteStmt /* by default all are $$=$1 */
7908 explain_option_list:
7911 $$ = list_make1($1);
7913 | explain_option_list ',' explain_option_elem
7915 $$ = lappend($1, $3);
7919 explain_option_elem:
7920 explain_option_name explain_option_arg
7922 $$ = makeDefElem($1, $2);
7926 explain_option_name:
7928 | analyze_keyword { $$ = "analyze"; }
7929 | VERBOSE { $$ = "verbose"; }
7933 opt_boolean_or_string { $$ = (Node *) makeString($1); }
7934 | NumericOnly { $$ = (Node *) $1; }
7935 | /* EMPTY */ { $$ = NULL; }
7938 /*****************************************************************************
7941 * PREPARE <plan_name> [(args, ...)] AS <query>
7943 *****************************************************************************/
7945 PrepareStmt: PREPARE name prep_type_clause AS PreparableStmt
7947 PrepareStmt *n = makeNode(PrepareStmt);
7955 prep_type_clause: '(' type_list ')' { $$ = $2; }
7956 | /* EMPTY */ { $$ = NIL; }
7963 | DeleteStmt /* by default all are $$=$1 */
7966 /*****************************************************************************
7968 * EXECUTE <plan_name> [(params, ...)]
7969 * CREATE TABLE <name> AS EXECUTE <plan_name> [(params, ...)]
7971 *****************************************************************************/
7973 ExecuteStmt: EXECUTE name execute_param_clause
7975 ExecuteStmt *n = makeNode(ExecuteStmt);
7981 | CREATE OptTemp TABLE create_as_target AS
7982 EXECUTE name execute_param_clause
7984 ExecuteStmt *n = makeNode(ExecuteStmt);
7987 $4->rel->relpersistence = $2;
7991 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
7992 errmsg("column name list not allowed in CREATE TABLE / AS EXECUTE")));
7993 /* ... because it's not implemented, but it could be */
7998 execute_param_clause: '(' expr_list ')' { $$ = $2; }
7999 | /* EMPTY */ { $$ = NIL; }
8002 /*****************************************************************************
8005 * DEALLOCATE [PREPARE] <plan_name>
8007 *****************************************************************************/
8009 DeallocateStmt: DEALLOCATE name
8011 DeallocateStmt *n = makeNode(DeallocateStmt);
8015 | DEALLOCATE PREPARE name
8017 DeallocateStmt *n = makeNode(DeallocateStmt);
8023 DeallocateStmt *n = makeNode(DeallocateStmt);
8027 | DEALLOCATE PREPARE ALL
8029 DeallocateStmt *n = makeNode(DeallocateStmt);
8035 /*****************************************************************************
8040 *****************************************************************************/
8043 opt_with_clause INSERT INTO qualified_name insert_rest returning_clause
8046 $5->returningList = $6;
8047 $5->withClause = $1;
8055 $$ = makeNode(InsertStmt);
8057 $$->selectStmt = $1;
8059 | '(' insert_column_list ')' SelectStmt
8061 $$ = makeNode(InsertStmt);
8063 $$->selectStmt = $4;
8067 $$ = makeNode(InsertStmt);
8069 $$->selectStmt = NULL;
8075 { $$ = list_make1($1); }
8076 | insert_column_list ',' insert_column_item
8077 { $$ = lappend($1, $3); }
8081 ColId opt_indirection
8083 $$ = makeNode(ResTarget);
8085 $$->indirection = check_indirection($2, yyscanner);
8092 RETURNING target_list { $$ = $2; }
8093 | /* EMPTY */ { $$ = NIL; }
8097 /*****************************************************************************
8102 *****************************************************************************/
8104 DeleteStmt: opt_with_clause DELETE_P FROM relation_expr_opt_alias
8105 using_clause where_or_current_clause returning_clause
8107 DeleteStmt *n = makeNode(DeleteStmt);
8109 n->usingClause = $5;
8110 n->whereClause = $6;
8111 n->returningList = $7;
8118 USING from_list { $$ = $2; }
8119 | /*EMPTY*/ { $$ = NIL; }
8123 /*****************************************************************************
8128 *****************************************************************************/
8130 LockStmt: LOCK_P opt_table relation_expr_list opt_lock opt_nowait
8132 LockStmt *n = makeNode(LockStmt);
8141 opt_lock: IN_P lock_type MODE { $$ = $2; }
8142 | /*EMPTY*/ { $$ = AccessExclusiveLock; }
8145 lock_type: ACCESS SHARE { $$ = AccessShareLock; }
8146 | ROW SHARE { $$ = RowShareLock; }
8147 | ROW EXCLUSIVE { $$ = RowExclusiveLock; }
8148 | SHARE UPDATE EXCLUSIVE { $$ = ShareUpdateExclusiveLock; }
8149 | SHARE { $$ = ShareLock; }
8150 | SHARE ROW EXCLUSIVE { $$ = ShareRowExclusiveLock; }
8151 | EXCLUSIVE { $$ = ExclusiveLock; }
8152 | ACCESS EXCLUSIVE { $$ = AccessExclusiveLock; }
8155 opt_nowait: NOWAIT { $$ = TRUE; }
8156 | /*EMPTY*/ { $$ = FALSE; }
8160 /*****************************************************************************
8163 * UpdateStmt (UPDATE)
8165 *****************************************************************************/
8167 UpdateStmt: opt_with_clause UPDATE relation_expr_opt_alias
8170 where_or_current_clause
8173 UpdateStmt *n = makeNode(UpdateStmt);
8177 n->whereClause = $7;
8178 n->returningList = $8;
8185 set_clause { $$ = $1; }
8186 | set_clause_list ',' set_clause { $$ = list_concat($1,$3); }
8190 single_set_clause { $$ = list_make1($1); }
8191 | multiple_set_clause { $$ = $1; }
8195 set_target '=' ctext_expr
8198 $$->val = (Node *) $3;
8202 multiple_set_clause:
8203 '(' set_target_list ')' '=' ctext_row
8209 * Break the ctext_row apart, merge individual expressions
8210 * into the destination ResTargets. XXX this approach
8211 * cannot work for general row expressions as sources.
8213 if (list_length($2) != list_length($5))
8215 (errcode(ERRCODE_SYNTAX_ERROR),
8216 errmsg("number of columns does not match number of values"),
8217 parser_errposition(@1)));
8218 forboth(col_cell, $2, val_cell, $5)
8220 ResTarget *res_col = (ResTarget *) lfirst(col_cell);
8221 Node *res_val = (Node *) lfirst(val_cell);
8223 res_col->val = res_val;
8231 ColId opt_indirection
8233 $$ = makeNode(ResTarget);
8235 $$->indirection = check_indirection($2, yyscanner);
8236 $$->val = NULL; /* upper production sets this */
8242 set_target { $$ = list_make1($1); }
8243 | set_target_list ',' set_target { $$ = lappend($1,$3); }
8247 /*****************************************************************************
8252 *****************************************************************************/
8253 DeclareCursorStmt: DECLARE cursor_name cursor_options CURSOR opt_hold FOR SelectStmt
8255 DeclareCursorStmt *n = makeNode(DeclareCursorStmt);
8257 /* currently we always set FAST_PLAN option */
8258 n->options = $3 | $5 | CURSOR_OPT_FAST_PLAN;
8264 cursor_name: name { $$ = $1; }
8267 cursor_options: /*EMPTY*/ { $$ = 0; }
8268 | cursor_options NO SCROLL { $$ = $1 | CURSOR_OPT_NO_SCROLL; }
8269 | cursor_options SCROLL { $$ = $1 | CURSOR_OPT_SCROLL; }
8270 | cursor_options BINARY { $$ = $1 | CURSOR_OPT_BINARY; }
8271 | cursor_options INSENSITIVE { $$ = $1 | CURSOR_OPT_INSENSITIVE; }
8274 opt_hold: /* EMPTY */ { $$ = 0; }
8275 | WITH HOLD { $$ = CURSOR_OPT_HOLD; }
8276 | WITHOUT HOLD { $$ = 0; }
8279 /*****************************************************************************
8284 *****************************************************************************/
8286 /* A complete SELECT statement looks like this.
8288 * The rule returns either a single SelectStmt node or a tree of them,
8289 * representing a set-operation tree.
8291 * There is an ambiguity when a sub-SELECT is within an a_expr and there
8292 * are excess parentheses: do the parentheses belong to the sub-SELECT or
8293 * to the surrounding a_expr? We don't really care, but bison wants to know.
8294 * To resolve the ambiguity, we are careful to define the grammar so that
8295 * the decision is staved off as long as possible: as long as we can keep
8296 * absorbing parentheses into the sub-SELECT, we will do so, and only when
8297 * it's no longer possible to do that will we decide that parens belong to
8298 * the expression. For example, in "SELECT (((SELECT 2)) + 3)" the extra
8299 * parentheses are treated as part of the sub-select. The necessity of doing
8300 * it that way is shown by "SELECT (((SELECT 2)) UNION SELECT 2)". Had we
8301 * parsed "((SELECT 2))" as an a_expr, it'd be too late to go back to the
8302 * SELECT viewpoint when we see the UNION.
8304 * This approach is implemented by defining a nonterminal select_with_parens,
8305 * which represents a SELECT with at least one outer layer of parentheses,
8306 * and being careful to use select_with_parens, never '(' SelectStmt ')',
8307 * in the expression grammar. We will then have shift-reduce conflicts
8308 * which we can resolve in favor of always treating '(' <select> ')' as
8309 * a select_with_parens. To resolve the conflicts, the productions that
8310 * conflict with the select_with_parens productions are manually given
8311 * precedences lower than the precedence of ')', thereby ensuring that we
8312 * shift ')' (and then reduce to select_with_parens) rather than trying to
8313 * reduce the inner <select> nonterminal to something else. We use UMINUS
8314 * precedence for this, which is a fairly arbitrary choice.
8316 * To be able to define select_with_parens itself without ambiguity, we need
8317 * a nonterminal select_no_parens that represents a SELECT structure with no
8318 * outermost parentheses. This is a little bit tedious, but it works.
8320 * In non-expression contexts, we use SelectStmt which can represent a SELECT
8321 * with or without outer parentheses.
8324 SelectStmt: select_no_parens %prec UMINUS
8325 | select_with_parens %prec UMINUS
8329 '(' select_no_parens ')' { $$ = $2; }
8330 | '(' select_with_parens ')' { $$ = $2; }
8334 * This rule parses the equivalent of the standard's <query expression>.
8335 * The duplicative productions are annoying, but hard to get rid of without
8336 * creating shift/reduce conflicts.
8338 * FOR UPDATE/SHARE may be before or after LIMIT/OFFSET.
8339 * In <=7.2.X, LIMIT/OFFSET had to be after FOR UPDATE
8340 * We now support both orderings, but prefer LIMIT/OFFSET before FOR UPDATE/SHARE
8344 simple_select { $$ = $1; }
8345 | select_clause sort_clause
8347 insertSelectOptions((SelectStmt *) $1, $2, NIL,
8352 | select_clause opt_sort_clause for_locking_clause opt_select_limit
8354 insertSelectOptions((SelectStmt *) $1, $2, $3,
8355 list_nth($4, 0), list_nth($4, 1),
8360 | select_clause opt_sort_clause select_limit opt_for_locking_clause
8362 insertSelectOptions((SelectStmt *) $1, $2, $4,
8363 list_nth($3, 0), list_nth($3, 1),
8368 | with_clause select_clause
8370 insertSelectOptions((SelectStmt *) $2, NULL, NIL,
8376 | with_clause select_clause sort_clause
8378 insertSelectOptions((SelectStmt *) $2, $3, NIL,
8384 | with_clause select_clause opt_sort_clause for_locking_clause opt_select_limit
8386 insertSelectOptions((SelectStmt *) $2, $3, $4,
8387 list_nth($5, 0), list_nth($5, 1),
8392 | with_clause select_clause opt_sort_clause select_limit opt_for_locking_clause
8394 insertSelectOptions((SelectStmt *) $2, $3, $5,
8395 list_nth($4, 0), list_nth($4, 1),
8403 simple_select { $$ = $1; }
8404 | select_with_parens { $$ = $1; }
8408 * This rule parses SELECT statements that can appear within set operations,
8409 * including UNION, INTERSECT and EXCEPT. '(' and ')' can be used to specify
8410 * the ordering of the set operations. Without '(' and ')' we want the
8411 * operations to be ordered per the precedence specs at the head of this file.
8413 * As with select_no_parens, simple_select cannot have outer parentheses,
8414 * but can have parenthesized subclauses.
8416 * Note that sort clauses cannot be included at this level --- SQL92 requires
8417 * SELECT foo UNION SELECT bar ORDER BY baz
8419 * (SELECT foo UNION SELECT bar) ORDER BY baz
8421 * SELECT foo UNION (SELECT bar ORDER BY baz)
8422 * Likewise for WITH, FOR UPDATE and LIMIT. Therefore, those clauses are
8423 * described as part of the select_no_parens production, not simple_select.
8424 * This does not limit functionality, because you can reintroduce these
8425 * clauses inside parentheses.
8427 * NOTE: only the leftmost component SelectStmt should have INTO.
8428 * However, this is not checked by the grammar; parse analysis must check it.
8431 SELECT opt_distinct target_list
8432 into_clause from_clause where_clause
8433 group_clause having_clause window_clause
8435 SelectStmt *n = makeNode(SelectStmt);
8436 n->distinctClause = $2;
8440 n->whereClause = $6;
8441 n->groupClause = $7;
8442 n->havingClause = $8;
8443 n->windowClause = $9;
8446 | values_clause { $$ = $1; }
8447 | TABLE relation_expr
8449 /* same as SELECT * FROM relation_expr */
8450 ColumnRef *cr = makeNode(ColumnRef);
8451 ResTarget *rt = makeNode(ResTarget);
8452 SelectStmt *n = makeNode(SelectStmt);
8454 cr->fields = list_make1(makeNode(A_Star));
8458 rt->indirection = NIL;
8459 rt->val = (Node *)cr;
8462 n->targetList = list_make1(rt);
8463 n->fromClause = list_make1($2);
8466 | select_clause UNION opt_all select_clause
8468 $$ = makeSetOp(SETOP_UNION, $3, $1, $4);
8470 | select_clause INTERSECT opt_all select_clause
8472 $$ = makeSetOp(SETOP_INTERSECT, $3, $1, $4);
8474 | select_clause EXCEPT opt_all select_clause
8476 $$ = makeSetOp(SETOP_EXCEPT, $3, $1, $4);
8481 * SQL standard WITH clause looks like:
8483 * WITH [ RECURSIVE ] <query name> [ (<column>,...) ]
8484 * AS (query) [ SEARCH or CYCLE clause ]
8486 * We don't currently support the SEARCH or CYCLE clause.
8491 $$ = makeNode(WithClause);
8493 $$->recursive = false;
8496 | WITH RECURSIVE cte_list
8498 $$ = makeNode(WithClause);
8500 $$->recursive = true;
8506 common_table_expr { $$ = list_make1($1); }
8507 | cte_list ',' common_table_expr { $$ = lappend($1, $3); }
8510 common_table_expr: name opt_name_list AS '(' PreparableStmt ')'
8512 CommonTableExpr *n = makeNode(CommonTableExpr);
8514 n->aliascolnames = $2;
8522 with_clause { $$ = $1; }
8523 | /*EMPTY*/ { $$ = NULL; }
8527 INTO OptTempTableName
8529 $$ = makeNode(IntoClause);
8533 $$->onCommit = ONCOMMIT_NOOP;
8534 $$->tableSpaceName = NULL;
8541 * Redundancy here is needed to avoid shift/reduce conflicts,
8542 * since TEMP is not a reserved word. See also OptTemp.
8545 TEMPORARY opt_table qualified_name
8548 $$->relpersistence = RELPERSISTENCE_TEMP;
8550 | TEMP opt_table qualified_name
8553 $$->relpersistence = RELPERSISTENCE_TEMP;
8555 | LOCAL TEMPORARY opt_table qualified_name
8558 $$->relpersistence = RELPERSISTENCE_TEMP;
8560 | LOCAL TEMP opt_table qualified_name
8563 $$->relpersistence = RELPERSISTENCE_TEMP;
8565 | GLOBAL TEMPORARY opt_table qualified_name
8568 $$->relpersistence = RELPERSISTENCE_TEMP;
8570 | GLOBAL TEMP opt_table qualified_name
8573 $$->relpersistence = RELPERSISTENCE_TEMP;
8575 | UNLOGGED opt_table qualified_name
8578 $$->relpersistence = RELPERSISTENCE_UNLOGGED;
8580 | TABLE qualified_name
8583 $$->relpersistence = RELPERSISTENCE_PERMANENT;
8588 $$->relpersistence = RELPERSISTENCE_PERMANENT;
8596 opt_all: ALL { $$ = TRUE; }
8597 | DISTINCT { $$ = FALSE; }
8598 | /*EMPTY*/ { $$ = FALSE; }
8601 /* We use (NIL) as a placeholder to indicate that all target expressions
8602 * should be placed in the DISTINCT list during parsetree analysis.
8605 DISTINCT { $$ = list_make1(NIL); }
8606 | DISTINCT ON '(' expr_list ')' { $$ = $4; }
8608 | /*EMPTY*/ { $$ = NIL; }
8612 sort_clause { $$ = $1;}
8613 | /*EMPTY*/ { $$ = NIL; }
8617 ORDER BY sortby_list { $$ = $3; }
8621 sortby { $$ = list_make1($1); }
8622 | sortby_list ',' sortby { $$ = lappend($1, $3); }
8625 sortby: a_expr USING qual_all_Op opt_nulls_order
8627 $$ = makeNode(SortBy);
8629 $$->sortby_dir = SORTBY_USING;
8630 $$->sortby_nulls = $4;
8634 | a_expr opt_asc_desc opt_nulls_order
8636 $$ = makeNode(SortBy);
8638 $$->sortby_dir = $2;
8639 $$->sortby_nulls = $3;
8641 $$->location = -1; /* no operator */
8647 limit_clause offset_clause { $$ = list_make2($2, $1); }
8648 | offset_clause limit_clause { $$ = list_make2($1, $2); }
8649 | limit_clause { $$ = list_make2(NULL, $1); }
8650 | offset_clause { $$ = list_make2($1, NULL); }
8654 select_limit { $$ = $1; }
8655 | /* EMPTY */ { $$ = list_make2(NULL,NULL); }
8659 LIMIT select_limit_value
8661 | LIMIT select_limit_value ',' select_offset_value
8663 /* Disabled because it was too confusing, bjm 2002-02-18 */
8665 (errcode(ERRCODE_SYNTAX_ERROR),
8666 errmsg("LIMIT #,# syntax is not supported"),
8667 errhint("Use separate LIMIT and OFFSET clauses."),
8668 parser_errposition(@1)));
8670 /* SQL:2008 syntax */
8671 | FETCH first_or_next opt_select_fetch_first_value row_or_rows ONLY
8676 OFFSET select_offset_value
8678 /* SQL:2008 syntax */
8679 | OFFSET select_offset_value2 row_or_rows
8687 /* LIMIT ALL is represented as a NULL constant */
8688 $$ = makeNullAConst(@1);
8692 select_offset_value:
8697 * Allowing full expressions without parentheses causes various parsing
8698 * problems with the trailing ROW/ROWS key words. SQL only calls for
8699 * constants, so we allow the rest only with parentheses. If omitted,
8702 opt_select_fetch_first_value:
8703 SignedIconst { $$ = makeIntConst($1, @1); }
8704 | '(' a_expr ')' { $$ = $2; }
8705 | /*EMPTY*/ { $$ = makeIntConst(1, -1); }
8709 * Again, the trailing ROW/ROWS in this case prevent the full expression
8710 * syntax. c_expr is the best we can do.
8712 select_offset_value2:
8717 row_or_rows: ROW { $$ = 0; }
8721 first_or_next: FIRST_P { $$ = 0; }
8727 GROUP_P BY expr_list { $$ = $3; }
8728 | /*EMPTY*/ { $$ = NIL; }
8732 HAVING a_expr { $$ = $2; }
8733 | /*EMPTY*/ { $$ = NULL; }
8737 for_locking_items { $$ = $1; }
8738 | FOR READ ONLY { $$ = NIL; }
8741 opt_for_locking_clause:
8742 for_locking_clause { $$ = $1; }
8743 | /* EMPTY */ { $$ = NIL; }
8747 for_locking_item { $$ = list_make1($1); }
8748 | for_locking_items for_locking_item { $$ = lappend($1, $2); }
8752 FOR UPDATE locked_rels_list opt_nowait
8754 LockingClause *n = makeNode(LockingClause);
8756 n->forUpdate = TRUE;
8760 | FOR SHARE locked_rels_list opt_nowait
8762 LockingClause *n = makeNode(LockingClause);
8764 n->forUpdate = FALSE;
8771 OF qualified_name_list { $$ = $2; }
8772 | /* EMPTY */ { $$ = NIL; }
8779 SelectStmt *n = makeNode(SelectStmt);
8780 n->valuesLists = list_make1($2);
8783 | values_clause ',' ctext_row
8785 SelectStmt *n = (SelectStmt *) $1;
8786 n->valuesLists = lappend(n->valuesLists, $3);
8792 /*****************************************************************************
8794 * clauses common to all Optimizable Stmts:
8795 * from_clause - allow list of both JOIN expressions and table names
8796 * where_clause - qualifications for joins or restrictions
8798 *****************************************************************************/
8801 FROM from_list { $$ = $2; }
8802 | /*EMPTY*/ { $$ = NIL; }
8806 table_ref { $$ = list_make1($1); }
8807 | from_list ',' table_ref { $$ = lappend($1, $3); }
8811 * table_ref is where an alias clause can be attached. Note we cannot make
8812 * alias_clause have an empty production because that causes parse conflicts
8813 * between table_ref := '(' joined_table ')' alias_clause
8814 * and joined_table := '(' joined_table ')'. So, we must have the
8815 * redundant-looking productions here instead.
8817 table_ref: relation_expr
8821 | relation_expr alias_clause
8828 RangeFunction *n = makeNode(RangeFunction);
8829 n->funccallnode = $1;
8830 n->coldeflist = NIL;
8833 | func_table alias_clause
8835 RangeFunction *n = makeNode(RangeFunction);
8836 n->funccallnode = $1;
8838 n->coldeflist = NIL;
8841 | func_table AS '(' TableFuncElementList ')'
8843 RangeFunction *n = makeNode(RangeFunction);
8844 n->funccallnode = $1;
8848 | func_table AS ColId '(' TableFuncElementList ')'
8850 RangeFunction *n = makeNode(RangeFunction);
8851 Alias *a = makeNode(Alias);
8852 n->funccallnode = $1;
8858 | func_table ColId '(' TableFuncElementList ')'
8860 RangeFunction *n = makeNode(RangeFunction);
8861 Alias *a = makeNode(Alias);
8862 n->funccallnode = $1;
8868 | select_with_parens
8871 * The SQL spec does not permit a subselect
8872 * (<derived_table>) without an alias clause,
8873 * so we don't either. This avoids the problem
8874 * of needing to invent a unique refname for it.
8875 * That could be surmounted if there's sufficient
8876 * popular demand, but for now let's just implement
8877 * the spec and see if anyone complains.
8878 * However, it does seem like a good idea to emit
8879 * an error message that's better than "syntax error".
8881 if (IsA($1, SelectStmt) &&
8882 ((SelectStmt *) $1)->valuesLists)
8884 (errcode(ERRCODE_SYNTAX_ERROR),
8885 errmsg("VALUES in FROM must have an alias"),
8886 errhint("For example, FROM (VALUES ...) [AS] foo."),
8887 parser_errposition(@1)));
8890 (errcode(ERRCODE_SYNTAX_ERROR),
8891 errmsg("subquery in FROM must have an alias"),
8892 errhint("For example, FROM (SELECT ...) [AS] foo."),
8893 parser_errposition(@1)));
8896 | select_with_parens alias_clause
8898 RangeSubselect *n = makeNode(RangeSubselect);
8907 | '(' joined_table ')' alias_clause
8916 * It may seem silly to separate joined_table from table_ref, but there is
8917 * method in SQL92's madness: if you don't do it this way you get reduce-
8918 * reduce conflicts, because it's not clear to the parser generator whether
8919 * to expect alias_clause after ')' or not. For the same reason we must
8920 * treat 'JOIN' and 'join_type JOIN' separately, rather than allowing
8921 * join_type to expand to empty; if we try it, the parser generator can't
8922 * figure out when to reduce an empty join_type right after table_ref.
8924 * Note that a CROSS JOIN is the same as an unqualified
8925 * INNER JOIN, and an INNER JOIN/ON has the same shape
8926 * but a qualification expression to limit membership.
8927 * A NATURAL JOIN implicitly matches column names between
8928 * tables and the shape is determined by which columns are
8929 * in common. We'll collect columns during the later transformations.
8933 '(' joined_table ')'
8937 | table_ref CROSS JOIN table_ref
8939 /* CROSS JOIN is same as unqualified inner join */
8940 JoinExpr *n = makeNode(JoinExpr);
8941 n->jointype = JOIN_INNER;
8942 n->isNatural = FALSE;
8945 n->usingClause = NIL;
8949 | table_ref join_type JOIN table_ref join_qual
8951 JoinExpr *n = makeNode(JoinExpr);
8953 n->isNatural = FALSE;
8956 if ($5 != NULL && IsA($5, List))
8957 n->usingClause = (List *) $5; /* USING clause */
8959 n->quals = $5; /* ON clause */
8962 | table_ref JOIN table_ref join_qual
8964 /* letting join_type reduce to empty doesn't work */
8965 JoinExpr *n = makeNode(JoinExpr);
8966 n->jointype = JOIN_INNER;
8967 n->isNatural = FALSE;
8970 if ($4 != NULL && IsA($4, List))
8971 n->usingClause = (List *) $4; /* USING clause */
8973 n->quals = $4; /* ON clause */
8976 | table_ref NATURAL join_type JOIN table_ref
8978 JoinExpr *n = makeNode(JoinExpr);
8980 n->isNatural = TRUE;
8983 n->usingClause = NIL; /* figure out which columns later... */
8984 n->quals = NULL; /* fill later */
8987 | table_ref NATURAL JOIN table_ref
8989 /* letting join_type reduce to empty doesn't work */
8990 JoinExpr *n = makeNode(JoinExpr);
8991 n->jointype = JOIN_INNER;
8992 n->isNatural = TRUE;
8995 n->usingClause = NIL; /* figure out which columns later... */
8996 n->quals = NULL; /* fill later */
9002 AS ColId '(' name_list ')'
9004 $$ = makeNode(Alias);
9010 $$ = makeNode(Alias);
9013 | ColId '(' name_list ')'
9015 $$ = makeNode(Alias);
9021 $$ = makeNode(Alias);
9026 join_type: FULL join_outer { $$ = JOIN_FULL; }
9027 | LEFT join_outer { $$ = JOIN_LEFT; }
9028 | RIGHT join_outer { $$ = JOIN_RIGHT; }
9029 | INNER_P { $$ = JOIN_INNER; }
9032 /* OUTER is just noise... */
9033 join_outer: OUTER_P { $$ = NULL; }
9034 | /*EMPTY*/ { $$ = NULL; }
9037 /* JOIN qualification clauses
9038 * Possibilities are:
9039 * USING ( column list ) allows only unqualified column names,
9040 * which must match between tables.
9041 * ON expr allows more general qualifications.
9043 * We return USING as a List node, while an ON-expr will not be a List.
9046 join_qual: USING '(' name_list ')' { $$ = (Node *) $3; }
9047 | ON a_expr { $$ = $2; }
9054 /* default inheritance */
9056 $$->inhOpt = INH_DEFAULT;
9059 | qualified_name '*'
9061 /* inheritance query */
9063 $$->inhOpt = INH_YES;
9066 | ONLY qualified_name
9068 /* no inheritance */
9070 $$->inhOpt = INH_NO;
9073 | ONLY '(' qualified_name ')'
9075 /* no inheritance, SQL99-style syntax */
9077 $$->inhOpt = INH_NO;
9084 relation_expr { $$ = list_make1($1); }
9085 | relation_expr_list ',' relation_expr { $$ = lappend($1, $3); }
9090 * Given "UPDATE foo set set ...", we have to decide without looking any
9091 * further ahead whether the first "set" is an alias or the UPDATE's SET
9092 * keyword. Since "set" is allowed as a column name both interpretations
9093 * are feasible. We resolve the shift/reduce conflict by giving the first
9094 * relation_expr_opt_alias production a higher precedence than the SET token
9095 * has, causing the parser to prefer to reduce, in effect assuming that the
9096 * SET is not an alias.
9098 relation_expr_opt_alias: relation_expr %prec UMINUS
9102 | relation_expr ColId
9104 Alias *alias = makeNode(Alias);
9105 alias->aliasname = $2;
9109 | relation_expr AS ColId
9111 Alias *alias = makeNode(Alias);
9112 alias->aliasname = $3;
9119 func_table: func_expr { $$ = $1; }
9124 WHERE a_expr { $$ = $2; }
9125 | /*EMPTY*/ { $$ = NULL; }
9128 /* variant for UPDATE and DELETE */
9129 where_or_current_clause:
9130 WHERE a_expr { $$ = $2; }
9131 | WHERE CURRENT_P OF cursor_name
9133 CurrentOfExpr *n = makeNode(CurrentOfExpr);
9134 /* cvarno is filled in by parse analysis */
9135 n->cursor_name = $4;
9136 n->cursor_param = 0;
9139 | /*EMPTY*/ { $$ = NULL; }
9143 OptTableFuncElementList:
9144 TableFuncElementList { $$ = $1; }
9145 | /*EMPTY*/ { $$ = NIL; }
9148 TableFuncElementList:
9151 $$ = list_make1($1);
9153 | TableFuncElementList ',' TableFuncElement
9155 $$ = lappend($1, $3);
9159 TableFuncElement: ColId Typename opt_collate_clause
9161 ColumnDef *n = makeNode(ColumnDef);
9166 n->is_not_null = false;
9167 n->is_from_type = false;
9169 n->raw_default = NULL;
9170 n->cooked_default = NULL;
9171 n->collClause = (CollateClause *) $3;
9172 n->collOid = InvalidOid;
9173 n->constraints = NIL;
9178 /*****************************************************************************
9181 * SQL92 introduces a large amount of type-specific syntax.
9182 * Define individual clauses to handle these cases, and use
9183 * the generic case to handle regular type-extensible Postgres syntax.
9184 * - thomas 1997-10-10
9186 *****************************************************************************/
9188 Typename: SimpleTypename opt_array_bounds
9191 $$->arrayBounds = $2;
9193 | SETOF SimpleTypename opt_array_bounds
9196 $$->arrayBounds = $3;
9199 /* SQL standard syntax, currently only one-dimensional */
9200 | SimpleTypename ARRAY '[' Iconst ']'
9203 $$->arrayBounds = list_make1(makeInteger($4));
9205 | SETOF SimpleTypename ARRAY '[' Iconst ']'
9208 $$->arrayBounds = list_make1(makeInteger($5));
9211 | SimpleTypename ARRAY
9214 $$->arrayBounds = list_make1(makeInteger(-1));
9216 | SETOF SimpleTypename ARRAY
9219 $$->arrayBounds = list_make1(makeInteger(-1));
9225 opt_array_bounds '[' ']'
9226 { $$ = lappend($1, makeInteger(-1)); }
9227 | opt_array_bounds '[' Iconst ']'
9228 { $$ = lappend($1, makeInteger($3)); }
9234 GenericType { $$ = $1; }
9235 | Numeric { $$ = $1; }
9237 | Character { $$ = $1; }
9238 | ConstDatetime { $$ = $1; }
9239 | ConstInterval opt_interval
9244 | ConstInterval '(' Iconst ')' opt_interval
9249 if (list_length($5) != 1)
9251 (errcode(ERRCODE_SYNTAX_ERROR),
9252 errmsg("interval precision specified twice"),
9253 parser_errposition(@1)));
9254 $$->typmods = lappend($5, makeIntConst($3, @3));
9257 $$->typmods = list_make2(makeIntConst(INTERVAL_FULL_RANGE, -1),
9258 makeIntConst($3, @3));
9262 /* We have a separate ConstTypename to allow defaulting fixed-length
9263 * types such as CHAR() and BIT() to an unspecified length.
9264 * SQL9x requires that these default to a length of one, but this
9265 * makes no sense for constructs like CHAR 'hi' and BIT '0101',
9266 * where there is an obvious better choice to make.
9267 * Note that ConstInterval is not included here since it must
9268 * be pushed up higher in the rules to accomodate the postfix
9269 * options (e.g. INTERVAL '1' YEAR). Likewise, we have to handle
9270 * the generic-type-name case in AExprConst to avoid premature
9271 * reduce/reduce conflicts against function names.
9274 Numeric { $$ = $1; }
9275 | ConstBit { $$ = $1; }
9276 | ConstCharacter { $$ = $1; }
9277 | ConstDatetime { $$ = $1; }
9281 * GenericType covers all type names that don't have special syntax mandated
9282 * by the standard, including qualified names. We also allow type modifiers.
9283 * To avoid parsing conflicts against function invocations, the modifiers
9284 * have to be shown as expr_list here, but parse analysis will only accept
9285 * constants for them.
9288 type_function_name opt_type_modifiers
9290 $$ = makeTypeName($1);
9294 | type_function_name attrs opt_type_modifiers
9296 $$ = makeTypeNameFromNameList(lcons(makeString($1), $2));
9302 opt_type_modifiers: '(' expr_list ')' { $$ = $2; }
9303 | /* EMPTY */ { $$ = NIL; }
9307 * SQL92 numeric data types
9311 $$ = SystemTypeName("int4");
9316 $$ = SystemTypeName("int4");
9321 $$ = SystemTypeName("int2");
9326 $$ = SystemTypeName("int8");
9331 $$ = SystemTypeName("float4");
9339 | DOUBLE_P PRECISION
9341 $$ = SystemTypeName("float8");
9344 | DECIMAL_P opt_type_modifiers
9346 $$ = SystemTypeName("numeric");
9350 | DEC opt_type_modifiers
9352 $$ = SystemTypeName("numeric");
9356 | NUMERIC opt_type_modifiers
9358 $$ = SystemTypeName("numeric");
9364 $$ = SystemTypeName("bool");
9369 opt_float: '(' Iconst ')'
9372 * Check FLOAT() precision limits assuming IEEE floating
9373 * types - thomas 1997-09-18
9377 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
9378 errmsg("precision for type float must be at least 1 bit"),
9379 parser_errposition(@2)));
9381 $$ = SystemTypeName("float4");
9383 $$ = SystemTypeName("float8");
9386 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
9387 errmsg("precision for type float must be less than 54 bits"),
9388 parser_errposition(@2)));
9392 $$ = SystemTypeName("float8");
9397 * SQL92 bit-field data types
9398 * The following implements BIT() and BIT VARYING().
9410 /* ConstBit is like Bit except "BIT" defaults to unspecified length */
9411 /* See notes for ConstCharacter, which addresses same issue for "CHAR" */
9412 ConstBit: BitWithLength
9424 BIT opt_varying '(' expr_list ')'
9428 typname = $2 ? "varbit" : "bit";
9429 $$ = SystemTypeName(typname);
9438 /* bit defaults to bit(1), varbit to no limit */
9441 $$ = SystemTypeName("varbit");
9445 $$ = SystemTypeName("bit");
9446 $$->typmods = list_make1(makeIntConst(1, -1));
9454 * SQL92 character data types
9455 * The following implements CHAR() and VARCHAR().
9457 Character: CharacterWithLength
9461 | CharacterWithoutLength
9467 ConstCharacter: CharacterWithLength
9471 | CharacterWithoutLength
9473 /* Length was not specified so allow to be unrestricted.
9474 * This handles problems with fixed-length (bpchar) strings
9475 * which in column definitions must default to a length
9476 * of one, but should not be constrained if the length
9477 * was not specified.
9484 CharacterWithLength: character '(' Iconst ')' opt_charset
9486 if (($5 != NULL) && (strcmp($5, "sql_text") != 0))
9490 type = palloc(strlen($1) + 1 + strlen($5) + 1);
9497 $$ = SystemTypeName($1);
9498 $$->typmods = list_make1(makeIntConst($3, @3));
9503 CharacterWithoutLength: character opt_charset
9505 if (($2 != NULL) && (strcmp($2, "sql_text") != 0))
9509 type = palloc(strlen($1) + 1 + strlen($2) + 1);
9516 $$ = SystemTypeName($1);
9518 /* char defaults to char(1), varchar to no limit */
9519 if (strcmp($1, "bpchar") == 0)
9520 $$->typmods = list_make1(makeIntConst(1, -1));
9526 character: CHARACTER opt_varying
9527 { $$ = $2 ? "varchar": "bpchar"; }
9528 | CHAR_P opt_varying
9529 { $$ = $2 ? "varchar": "bpchar"; }
9532 | NATIONAL CHARACTER opt_varying
9533 { $$ = $3 ? "varchar": "bpchar"; }
9534 | NATIONAL CHAR_P opt_varying
9535 { $$ = $3 ? "varchar": "bpchar"; }
9537 { $$ = $2 ? "varchar": "bpchar"; }
9541 VARYING { $$ = TRUE; }
9542 | /*EMPTY*/ { $$ = FALSE; }
9546 CHARACTER SET ColId { $$ = $3; }
9547 | /*EMPTY*/ { $$ = NULL; }
9551 * SQL92 date/time types
9554 TIMESTAMP '(' Iconst ')' opt_timezone
9557 $$ = SystemTypeName("timestamptz");
9559 $$ = SystemTypeName("timestamp");
9560 $$->typmods = list_make1(makeIntConst($3, @3));
9563 | TIMESTAMP opt_timezone
9566 $$ = SystemTypeName("timestamptz");
9568 $$ = SystemTypeName("timestamp");
9571 | TIME '(' Iconst ')' opt_timezone
9574 $$ = SystemTypeName("timetz");
9576 $$ = SystemTypeName("time");
9577 $$->typmods = list_make1(makeIntConst($3, @3));
9583 $$ = SystemTypeName("timetz");
9585 $$ = SystemTypeName("time");
9593 $$ = SystemTypeName("interval");
9599 WITH_TIME ZONE { $$ = TRUE; }
9600 | WITHOUT TIME ZONE { $$ = FALSE; }
9601 | /*EMPTY*/ { $$ = FALSE; }
9606 { $$ = list_make1(makeIntConst(INTERVAL_MASK(YEAR), @1)); }
9608 { $$ = list_make1(makeIntConst(INTERVAL_MASK(MONTH), @1)); }
9610 { $$ = list_make1(makeIntConst(INTERVAL_MASK(DAY), @1)); }
9612 { $$ = list_make1(makeIntConst(INTERVAL_MASK(HOUR), @1)); }
9614 { $$ = list_make1(makeIntConst(INTERVAL_MASK(MINUTE), @1)); }
9619 $$ = list_make1(makeIntConst(INTERVAL_MASK(YEAR) |
9620 INTERVAL_MASK(MONTH), @1));
9624 $$ = list_make1(makeIntConst(INTERVAL_MASK(DAY) |
9625 INTERVAL_MASK(HOUR), @1));
9629 $$ = list_make1(makeIntConst(INTERVAL_MASK(DAY) |
9630 INTERVAL_MASK(HOUR) |
9631 INTERVAL_MASK(MINUTE), @1));
9633 | DAY_P TO interval_second
9636 linitial($$) = makeIntConst(INTERVAL_MASK(DAY) |
9637 INTERVAL_MASK(HOUR) |
9638 INTERVAL_MASK(MINUTE) |
9639 INTERVAL_MASK(SECOND), @1);
9641 | HOUR_P TO MINUTE_P
9643 $$ = list_make1(makeIntConst(INTERVAL_MASK(HOUR) |
9644 INTERVAL_MASK(MINUTE), @1));
9646 | HOUR_P TO interval_second
9649 linitial($$) = makeIntConst(INTERVAL_MASK(HOUR) |
9650 INTERVAL_MASK(MINUTE) |
9651 INTERVAL_MASK(SECOND), @1);
9653 | MINUTE_P TO interval_second
9656 linitial($$) = makeIntConst(INTERVAL_MASK(MINUTE) |
9657 INTERVAL_MASK(SECOND), @1);
9666 $$ = list_make1(makeIntConst(INTERVAL_MASK(SECOND), @1));
9668 | SECOND_P '(' Iconst ')'
9670 $$ = list_make2(makeIntConst(INTERVAL_MASK(SECOND), @1),
9671 makeIntConst($3, @3));
9676 /*****************************************************************************
9678 * expression grammar
9680 *****************************************************************************/
9683 * General expressions
9684 * This is the heart of the expression syntax.
9686 * We have two expression types: a_expr is the unrestricted kind, and
9687 * b_expr is a subset that must be used in some places to avoid shift/reduce
9688 * conflicts. For example, we can't do BETWEEN as "BETWEEN a_expr AND a_expr"
9689 * because that use of AND conflicts with AND as a boolean operator. So,
9690 * b_expr is used in BETWEEN and we remove boolean keywords from b_expr.
9692 * Note that '(' a_expr ')' is a b_expr, so an unrestricted expression can
9693 * always be used by surrounding it with parens.
9695 * c_expr is all the productions that are common to a_expr and b_expr;
9696 * it's factored out just to eliminate redundant coding.
9698 a_expr: c_expr { $$ = $1; }
9699 | a_expr TYPECAST Typename
9700 { $$ = makeTypeCast($1, $3, @2); }
9701 | a_expr COLLATE any_name
9703 CollateClause *n = makeNode(CollateClause);
9709 | a_expr AT TIME ZONE a_expr %prec AT
9711 FuncCall *n = makeNode(FuncCall);
9712 n->funcname = SystemFuncName("timezone");
9713 n->args = list_make2($5, $1);
9715 n->agg_star = FALSE;
9716 n->agg_distinct = FALSE;
9717 n->func_variadic = FALSE;
9723 * These operators must be called out explicitly in order to make use
9724 * of bison's automatic operator-precedence handling. All other
9725 * operator names are handled by the generic productions using "Op",
9726 * below; and all those operators will have the same precedence.
9728 * If you add more explicitly-known operators, be sure to add them
9729 * also to b_expr and to the MathOp list above.
9731 | '+' a_expr %prec UMINUS
9732 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "+", NULL, $2, @1); }
9733 | '-' a_expr %prec UMINUS
9734 { $$ = doNegate($2, @1); }
9736 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "+", $1, $3, @2); }
9738 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "-", $1, $3, @2); }
9740 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "*", $1, $3, @2); }
9742 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "/", $1, $3, @2); }
9744 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "%", $1, $3, @2); }
9746 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "^", $1, $3, @2); }
9748 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "<", $1, $3, @2); }
9750 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, ">", $1, $3, @2); }
9752 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "=", $1, $3, @2); }
9754 | a_expr qual_Op a_expr %prec Op
9755 { $$ = (Node *) makeA_Expr(AEXPR_OP, $2, $1, $3, @2); }
9756 | qual_Op a_expr %prec Op
9757 { $$ = (Node *) makeA_Expr(AEXPR_OP, $1, NULL, $2, @1); }
9758 | a_expr qual_Op %prec POSTFIXOP
9759 { $$ = (Node *) makeA_Expr(AEXPR_OP, $2, $1, NULL, @2); }
9762 { $$ = (Node *) makeA_Expr(AEXPR_AND, NIL, $1, $3, @2); }
9764 { $$ = (Node *) makeA_Expr(AEXPR_OR, NIL, $1, $3, @2); }
9766 { $$ = (Node *) makeA_Expr(AEXPR_NOT, NIL, NULL, $2, @1); }
9768 | a_expr LIKE a_expr
9769 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "~~", $1, $3, @2); }
9770 | a_expr LIKE a_expr ESCAPE a_expr
9772 FuncCall *n = makeNode(FuncCall);
9773 n->funcname = SystemFuncName("like_escape");
9774 n->args = list_make2($3, $5);
9776 n->agg_star = FALSE;
9777 n->agg_distinct = FALSE;
9778 n->func_variadic = FALSE;
9781 $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "~~", $1, (Node *) n, @2);
9783 | a_expr NOT LIKE a_expr
9784 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "!~~", $1, $4, @2); }
9785 | a_expr NOT LIKE a_expr ESCAPE a_expr
9787 FuncCall *n = makeNode(FuncCall);
9788 n->funcname = SystemFuncName("like_escape");
9789 n->args = list_make2($4, $6);
9791 n->agg_star = FALSE;
9792 n->agg_distinct = FALSE;
9793 n->func_variadic = FALSE;
9796 $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "!~~", $1, (Node *) n, @2);
9798 | a_expr ILIKE a_expr
9799 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "~~*", $1, $3, @2); }
9800 | a_expr ILIKE a_expr ESCAPE a_expr
9802 FuncCall *n = makeNode(FuncCall);
9803 n->funcname = SystemFuncName("like_escape");
9804 n->args = list_make2($3, $5);
9806 n->agg_star = FALSE;
9807 n->agg_distinct = FALSE;
9808 n->func_variadic = FALSE;
9811 $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "~~*", $1, (Node *) n, @2);
9813 | a_expr NOT ILIKE a_expr
9814 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "!~~*", $1, $4, @2); }
9815 | a_expr NOT ILIKE a_expr ESCAPE a_expr
9817 FuncCall *n = makeNode(FuncCall);
9818 n->funcname = SystemFuncName("like_escape");
9819 n->args = list_make2($4, $6);
9821 n->agg_star = FALSE;
9822 n->agg_distinct = FALSE;
9823 n->func_variadic = FALSE;
9826 $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "!~~*", $1, (Node *) n, @2);
9829 | a_expr SIMILAR TO a_expr %prec SIMILAR
9831 FuncCall *n = makeNode(FuncCall);
9832 n->funcname = SystemFuncName("similar_escape");
9833 n->args = list_make2($4, makeNullAConst(-1));
9835 n->agg_star = FALSE;
9836 n->agg_distinct = FALSE;
9837 n->func_variadic = FALSE;
9840 $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "~", $1, (Node *) n, @2);
9842 | a_expr SIMILAR TO a_expr ESCAPE a_expr
9844 FuncCall *n = makeNode(FuncCall);
9845 n->funcname = SystemFuncName("similar_escape");
9846 n->args = list_make2($4, $6);
9848 n->agg_star = FALSE;
9849 n->agg_distinct = FALSE;
9850 n->func_variadic = FALSE;
9853 $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "~", $1, (Node *) n, @2);
9855 | a_expr NOT SIMILAR TO a_expr %prec SIMILAR
9857 FuncCall *n = makeNode(FuncCall);
9858 n->funcname = SystemFuncName("similar_escape");
9859 n->args = list_make2($5, makeNullAConst(-1));
9861 n->agg_star = FALSE;
9862 n->agg_distinct = FALSE;
9863 n->func_variadic = FALSE;
9866 $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "!~", $1, (Node *) n, @2);
9868 | a_expr NOT SIMILAR TO a_expr ESCAPE a_expr
9870 FuncCall *n = makeNode(FuncCall);
9871 n->funcname = SystemFuncName("similar_escape");
9872 n->args = list_make2($5, $7);
9874 n->agg_star = FALSE;
9875 n->agg_distinct = FALSE;
9876 n->func_variadic = FALSE;
9879 $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "!~", $1, (Node *) n, @2);
9883 * Define SQL92-style Null test clause.
9884 * Allow two forms described in the standard:
9887 * Allow two SQL extensions
9891 | a_expr IS NULL_P %prec IS
9893 NullTest *n = makeNode(NullTest);
9894 n->arg = (Expr *) $1;
9895 n->nulltesttype = IS_NULL;
9900 NullTest *n = makeNode(NullTest);
9901 n->arg = (Expr *) $1;
9902 n->nulltesttype = IS_NULL;
9905 | a_expr IS NOT NULL_P %prec IS
9907 NullTest *n = makeNode(NullTest);
9908 n->arg = (Expr *) $1;
9909 n->nulltesttype = IS_NOT_NULL;
9914 NullTest *n = makeNode(NullTest);
9915 n->arg = (Expr *) $1;
9916 n->nulltesttype = IS_NOT_NULL;
9921 $$ = (Node *)makeOverlaps($1, $3, @2, yyscanner);
9923 | a_expr IS TRUE_P %prec IS
9925 BooleanTest *b = makeNode(BooleanTest);
9926 b->arg = (Expr *) $1;
9927 b->booltesttype = IS_TRUE;
9930 | a_expr IS NOT TRUE_P %prec IS
9932 BooleanTest *b = makeNode(BooleanTest);
9933 b->arg = (Expr *) $1;
9934 b->booltesttype = IS_NOT_TRUE;
9937 | a_expr IS FALSE_P %prec IS
9939 BooleanTest *b = makeNode(BooleanTest);
9940 b->arg = (Expr *) $1;
9941 b->booltesttype = IS_FALSE;
9944 | a_expr IS NOT FALSE_P %prec IS
9946 BooleanTest *b = makeNode(BooleanTest);
9947 b->arg = (Expr *) $1;
9948 b->booltesttype = IS_NOT_FALSE;
9951 | a_expr IS UNKNOWN %prec IS
9953 BooleanTest *b = makeNode(BooleanTest);
9954 b->arg = (Expr *) $1;
9955 b->booltesttype = IS_UNKNOWN;
9958 | a_expr IS NOT UNKNOWN %prec IS
9960 BooleanTest *b = makeNode(BooleanTest);
9961 b->arg = (Expr *) $1;
9962 b->booltesttype = IS_NOT_UNKNOWN;
9965 | a_expr IS DISTINCT FROM a_expr %prec IS
9967 $$ = (Node *) makeSimpleA_Expr(AEXPR_DISTINCT, "=", $1, $5, @2);
9969 | a_expr IS NOT DISTINCT FROM a_expr %prec IS
9971 $$ = (Node *) makeA_Expr(AEXPR_NOT, NIL, NULL,
9972 (Node *) makeSimpleA_Expr(AEXPR_DISTINCT,
9977 | a_expr IS OF '(' type_list ')' %prec IS
9979 $$ = (Node *) makeSimpleA_Expr(AEXPR_OF, "=", $1, (Node *) $5, @2);
9981 | a_expr IS NOT OF '(' type_list ')' %prec IS
9983 $$ = (Node *) makeSimpleA_Expr(AEXPR_OF, "<>", $1, (Node *) $6, @2);
9986 * Ideally we would not use hard-wired operators below but
9987 * instead use opclasses. However, mixed data types and other
9988 * issues make this difficult:
9989 * http://archives.postgresql.org/pgsql-hackers/2008-08/msg01142.php
9991 | a_expr BETWEEN opt_asymmetric b_expr AND b_expr %prec BETWEEN
9993 $$ = (Node *) makeA_Expr(AEXPR_AND, NIL,
9994 (Node *) makeSimpleA_Expr(AEXPR_OP, ">=", $1, $4, @2),
9995 (Node *) makeSimpleA_Expr(AEXPR_OP, "<=", $1, $6, @2),
9998 | a_expr NOT BETWEEN opt_asymmetric b_expr AND b_expr %prec BETWEEN
10000 $$ = (Node *) makeA_Expr(AEXPR_OR, NIL,
10001 (Node *) makeSimpleA_Expr(AEXPR_OP, "<", $1, $5, @2),
10002 (Node *) makeSimpleA_Expr(AEXPR_OP, ">", $1, $7, @2),
10005 | a_expr BETWEEN SYMMETRIC b_expr AND b_expr %prec BETWEEN
10007 $$ = (Node *) makeA_Expr(AEXPR_OR, NIL,
10008 (Node *) makeA_Expr(AEXPR_AND, NIL,
10009 (Node *) makeSimpleA_Expr(AEXPR_OP, ">=", $1, $4, @2),
10010 (Node *) makeSimpleA_Expr(AEXPR_OP, "<=", $1, $6, @2),
10012 (Node *) makeA_Expr(AEXPR_AND, NIL,
10013 (Node *) makeSimpleA_Expr(AEXPR_OP, ">=", $1, $6, @2),
10014 (Node *) makeSimpleA_Expr(AEXPR_OP, "<=", $1, $4, @2),
10018 | a_expr NOT BETWEEN SYMMETRIC b_expr AND b_expr %prec BETWEEN
10020 $$ = (Node *) makeA_Expr(AEXPR_AND, NIL,
10021 (Node *) makeA_Expr(AEXPR_OR, NIL,
10022 (Node *) makeSimpleA_Expr(AEXPR_OP, "<", $1, $5, @2),
10023 (Node *) makeSimpleA_Expr(AEXPR_OP, ">", $1, $7, @2),
10025 (Node *) makeA_Expr(AEXPR_OR, NIL,
10026 (Node *) makeSimpleA_Expr(AEXPR_OP, "<", $1, $7, @2),
10027 (Node *) makeSimpleA_Expr(AEXPR_OP, ">", $1, $5, @2),
10031 | a_expr IN_P in_expr
10033 /* in_expr returns a SubLink or a list of a_exprs */
10034 if (IsA($3, SubLink))
10036 /* generate foo = ANY (subquery) */
10037 SubLink *n = (SubLink *) $3;
10038 n->subLinkType = ANY_SUBLINK;
10040 n->operName = list_make1(makeString("="));
10046 /* generate scalar IN expression */
10047 $$ = (Node *) makeSimpleA_Expr(AEXPR_IN, "=", $1, $3, @2);
10050 | a_expr NOT IN_P in_expr
10052 /* in_expr returns a SubLink or a list of a_exprs */
10053 if (IsA($4, SubLink))
10055 /* generate NOT (foo = ANY (subquery)) */
10056 /* Make an = ANY node */
10057 SubLink *n = (SubLink *) $4;
10058 n->subLinkType = ANY_SUBLINK;
10060 n->operName = list_make1(makeString("="));
10062 /* Stick a NOT on top */
10063 $$ = (Node *) makeA_Expr(AEXPR_NOT, NIL, NULL, (Node *) n, @2);
10067 /* generate scalar NOT IN expression */
10068 $$ = (Node *) makeSimpleA_Expr(AEXPR_IN, "<>", $1, $4, @2);
10071 | a_expr subquery_Op sub_type select_with_parens %prec Op
10073 SubLink *n = makeNode(SubLink);
10074 n->subLinkType = $3;
10081 | a_expr subquery_Op sub_type '(' a_expr ')' %prec Op
10083 if ($3 == ANY_SUBLINK)
10084 $$ = (Node *) makeA_Expr(AEXPR_OP_ANY, $2, $1, $5, @2);
10086 $$ = (Node *) makeA_Expr(AEXPR_OP_ALL, $2, $1, $5, @2);
10088 | UNIQUE select_with_parens
10090 /* Not sure how to get rid of the parentheses
10091 * but there are lots of shift/reduce errors without them.
10093 * Should be able to implement this by plopping the entire
10094 * select into a node, then transforming the target expressions
10095 * from whatever they are into count(*), and testing the
10096 * entire result equal to one.
10097 * But, will probably implement a separate node in the executor.
10100 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
10101 errmsg("UNIQUE predicate is not yet implemented"),
10102 parser_errposition(@1)));
10104 | a_expr IS DOCUMENT_P %prec IS
10106 $$ = makeXmlExpr(IS_DOCUMENT, NULL, NIL,
10107 list_make1($1), @2);
10109 | a_expr IS NOT DOCUMENT_P %prec IS
10111 $$ = (Node *) makeA_Expr(AEXPR_NOT, NIL, NULL,
10112 makeXmlExpr(IS_DOCUMENT, NULL, NIL,
10113 list_make1($1), @2),
10119 * Restricted expressions
10121 * b_expr is a subset of the complete expression syntax defined by a_expr.
10123 * Presently, AND, NOT, IS, and IN are the a_expr keywords that would
10124 * cause trouble in the places where b_expr is used. For simplicity, we
10125 * just eliminate all the boolean-keyword-operator productions from b_expr.
10129 | b_expr TYPECAST Typename
10130 { $$ = makeTypeCast($1, $3, @2); }
10131 | '+' b_expr %prec UMINUS
10132 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "+", NULL, $2, @1); }
10133 | '-' b_expr %prec UMINUS
10134 { $$ = doNegate($2, @1); }
10135 | b_expr '+' b_expr
10136 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "+", $1, $3, @2); }
10137 | b_expr '-' b_expr
10138 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "-", $1, $3, @2); }
10139 | b_expr '*' b_expr
10140 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "*", $1, $3, @2); }
10141 | b_expr '/' b_expr
10142 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "/", $1, $3, @2); }
10143 | b_expr '%' b_expr
10144 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "%", $1, $3, @2); }
10145 | b_expr '^' b_expr
10146 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "^", $1, $3, @2); }
10147 | b_expr '<' b_expr
10148 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "<", $1, $3, @2); }
10149 | b_expr '>' b_expr
10150 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, ">", $1, $3, @2); }
10151 | b_expr '=' b_expr
10152 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "=", $1, $3, @2); }
10153 | b_expr qual_Op b_expr %prec Op
10154 { $$ = (Node *) makeA_Expr(AEXPR_OP, $2, $1, $3, @2); }
10155 | qual_Op b_expr %prec Op
10156 { $$ = (Node *) makeA_Expr(AEXPR_OP, $1, NULL, $2, @1); }
10157 | b_expr qual_Op %prec POSTFIXOP
10158 { $$ = (Node *) makeA_Expr(AEXPR_OP, $2, $1, NULL, @2); }
10159 | b_expr IS DISTINCT FROM b_expr %prec IS
10161 $$ = (Node *) makeSimpleA_Expr(AEXPR_DISTINCT, "=", $1, $5, @2);
10163 | b_expr IS NOT DISTINCT FROM b_expr %prec IS
10165 $$ = (Node *) makeA_Expr(AEXPR_NOT, NIL,
10166 NULL, (Node *) makeSimpleA_Expr(AEXPR_DISTINCT, "=", $1, $6, @2), @2);
10168 | b_expr IS OF '(' type_list ')' %prec IS
10170 $$ = (Node *) makeSimpleA_Expr(AEXPR_OF, "=", $1, (Node *) $5, @2);
10172 | b_expr IS NOT OF '(' type_list ')' %prec IS
10174 $$ = (Node *) makeSimpleA_Expr(AEXPR_OF, "<>", $1, (Node *) $6, @2);
10176 | b_expr IS DOCUMENT_P %prec IS
10178 $$ = makeXmlExpr(IS_DOCUMENT, NULL, NIL,
10179 list_make1($1), @2);
10181 | b_expr IS NOT DOCUMENT_P %prec IS
10183 $$ = (Node *) makeA_Expr(AEXPR_NOT, NIL, NULL,
10184 makeXmlExpr(IS_DOCUMENT, NULL, NIL,
10185 list_make1($1), @2),
10191 * Productions that can be used in both a_expr and b_expr.
10193 * Note: productions that refer recursively to a_expr or b_expr mostly
10194 * cannot appear here. However, it's OK to refer to a_exprs that occur
10195 * inside parentheses, such as function arguments; that cannot introduce
10196 * ambiguity to the b_expr syntax.
10198 c_expr: columnref { $$ = $1; }
10199 | AexprConst { $$ = $1; }
10200 | PARAM opt_indirection
10202 ParamRef *p = makeNode(ParamRef);
10207 A_Indirection *n = makeNode(A_Indirection);
10208 n->arg = (Node *) p;
10209 n->indirection = check_indirection($2, yyscanner);
10215 | '(' a_expr ')' opt_indirection
10219 A_Indirection *n = makeNode(A_Indirection);
10221 n->indirection = check_indirection($4, yyscanner);
10231 | select_with_parens %prec UMINUS
10233 SubLink *n = makeNode(SubLink);
10234 n->subLinkType = EXPR_SUBLINK;
10235 n->testexpr = NULL;
10241 | EXISTS select_with_parens
10243 SubLink *n = makeNode(SubLink);
10244 n->subLinkType = EXISTS_SUBLINK;
10245 n->testexpr = NULL;
10251 | ARRAY select_with_parens
10253 SubLink *n = makeNode(SubLink);
10254 n->subLinkType = ARRAY_SUBLINK;
10255 n->testexpr = NULL;
10263 A_ArrayExpr *n = (A_ArrayExpr *) $2;
10264 Assert(IsA(n, A_ArrayExpr));
10265 /* point outermost A_ArrayExpr to the ARRAY keyword */
10271 RowExpr *r = makeNode(RowExpr);
10273 r->row_typeid = InvalidOid; /* not analyzed yet */
10280 * func_expr is split out from c_expr just so that we have a classification
10281 * for "everything that is a function call or looks like one". This isn't
10282 * very important, but it saves us having to document which variants are
10283 * legal in the backwards-compatible functional-index syntax for CREATE INDEX.
10284 * (Note that many of the special SQL functions wouldn't actually make any
10285 * sense as functional index entries, but we ignore that consideration here.)
10287 func_expr: func_name '(' ')' over_clause
10289 FuncCall *n = makeNode(FuncCall);
10292 n->agg_order = NIL;
10293 n->agg_star = FALSE;
10294 n->agg_distinct = FALSE;
10295 n->func_variadic = FALSE;
10300 | func_name '(' func_arg_list ')' over_clause
10302 FuncCall *n = makeNode(FuncCall);
10305 n->agg_order = NIL;
10306 n->agg_star = FALSE;
10307 n->agg_distinct = FALSE;
10308 n->func_variadic = FALSE;
10313 | func_name '(' VARIADIC func_arg_expr ')' over_clause
10315 FuncCall *n = makeNode(FuncCall);
10317 n->args = list_make1($4);
10318 n->agg_order = NIL;
10319 n->agg_star = FALSE;
10320 n->agg_distinct = FALSE;
10321 n->func_variadic = TRUE;
10326 | func_name '(' func_arg_list ',' VARIADIC func_arg_expr ')' over_clause
10328 FuncCall *n = makeNode(FuncCall);
10330 n->args = lappend($3, $6);
10331 n->agg_order = NIL;
10332 n->agg_star = FALSE;
10333 n->agg_distinct = FALSE;
10334 n->func_variadic = TRUE;
10339 | func_name '(' func_arg_list sort_clause ')' over_clause
10341 FuncCall *n = makeNode(FuncCall);
10345 n->agg_star = FALSE;
10346 n->agg_distinct = FALSE;
10347 n->func_variadic = FALSE;
10352 | func_name '(' ALL func_arg_list opt_sort_clause ')' over_clause
10354 FuncCall *n = makeNode(FuncCall);
10358 n->agg_star = FALSE;
10359 n->agg_distinct = FALSE;
10360 /* Ideally we'd mark the FuncCall node to indicate
10361 * "must be an aggregate", but there's no provision
10362 * for that in FuncCall at the moment.
10364 n->func_variadic = FALSE;
10369 | func_name '(' DISTINCT func_arg_list opt_sort_clause ')' over_clause
10371 FuncCall *n = makeNode(FuncCall);
10375 n->agg_star = FALSE;
10376 n->agg_distinct = TRUE;
10377 n->func_variadic = FALSE;
10382 | func_name '(' '*' ')' over_clause
10385 * We consider AGGREGATE(*) to invoke a parameterless
10386 * aggregate. This does the right thing for COUNT(*),
10387 * and there are no other aggregates in SQL92 that accept
10388 * '*' as parameter.
10390 * The FuncCall node is also marked agg_star = true,
10391 * so that later processing can detect what the argument
10394 FuncCall *n = makeNode(FuncCall);
10397 n->agg_order = NIL;
10398 n->agg_star = TRUE;
10399 n->agg_distinct = FALSE;
10400 n->func_variadic = FALSE;
10408 * Translate as "'now'::text::date".
10410 * We cannot use "'now'::date" because coerce_type() will
10411 * immediately reduce that to a constant representing
10412 * today's date. We need to delay the conversion until
10413 * runtime, else the wrong things will happen when
10414 * CURRENT_DATE is used in a column default value or rule.
10416 * This could be simplified if we had a way to generate
10417 * an expression tree representing runtime application
10418 * of type-input conversion functions. (As of PG 7.3
10419 * that is actually possible, but not clear that we want
10423 n = makeStringConstCast("now", @1, SystemTypeName("text"));
10424 $$ = makeTypeCast(n, SystemTypeName("date"), -1);
10429 * Translate as "'now'::text::timetz".
10430 * See comments for CURRENT_DATE.
10433 n = makeStringConstCast("now", @1, SystemTypeName("text"));
10434 $$ = makeTypeCast(n, SystemTypeName("timetz"), -1);
10436 | CURRENT_TIME '(' Iconst ')'
10439 * Translate as "'now'::text::timetz(n)".
10440 * See comments for CURRENT_DATE.
10444 n = makeStringConstCast("now", @1, SystemTypeName("text"));
10445 d = SystemTypeName("timetz");
10446 d->typmods = list_make1(makeIntConst($3, @3));
10447 $$ = makeTypeCast(n, d, -1);
10449 | CURRENT_TIMESTAMP
10452 * Translate as "now()", since we have a function that
10453 * does exactly what is needed.
10455 FuncCall *n = makeNode(FuncCall);
10456 n->funcname = SystemFuncName("now");
10458 n->agg_order = NIL;
10459 n->agg_star = FALSE;
10460 n->agg_distinct = FALSE;
10461 n->func_variadic = FALSE;
10466 | CURRENT_TIMESTAMP '(' Iconst ')'
10469 * Translate as "'now'::text::timestamptz(n)".
10470 * See comments for CURRENT_DATE.
10474 n = makeStringConstCast("now", @1, SystemTypeName("text"));
10475 d = SystemTypeName("timestamptz");
10476 d->typmods = list_make1(makeIntConst($3, @3));
10477 $$ = makeTypeCast(n, d, -1);
10482 * Translate as "'now'::text::time".
10483 * See comments for CURRENT_DATE.
10486 n = makeStringConstCast("now", @1, SystemTypeName("text"));
10487 $$ = makeTypeCast((Node *)n, SystemTypeName("time"), -1);
10489 | LOCALTIME '(' Iconst ')'
10492 * Translate as "'now'::text::time(n)".
10493 * See comments for CURRENT_DATE.
10497 n = makeStringConstCast("now", @1, SystemTypeName("text"));
10498 d = SystemTypeName("time");
10499 d->typmods = list_make1(makeIntConst($3, @3));
10500 $$ = makeTypeCast((Node *)n, d, -1);
10505 * Translate as "'now'::text::timestamp".
10506 * See comments for CURRENT_DATE.
10509 n = makeStringConstCast("now", @1, SystemTypeName("text"));
10510 $$ = makeTypeCast(n, SystemTypeName("timestamp"), -1);
10512 | LOCALTIMESTAMP '(' Iconst ')'
10515 * Translate as "'now'::text::timestamp(n)".
10516 * See comments for CURRENT_DATE.
10520 n = makeStringConstCast("now", @1, SystemTypeName("text"));
10521 d = SystemTypeName("timestamp");
10522 d->typmods = list_make1(makeIntConst($3, @3));
10523 $$ = makeTypeCast(n, d, -1);
10527 FuncCall *n = makeNode(FuncCall);
10528 n->funcname = SystemFuncName("current_user");
10530 n->agg_order = NIL;
10531 n->agg_star = FALSE;
10532 n->agg_distinct = FALSE;
10533 n->func_variadic = FALSE;
10540 FuncCall *n = makeNode(FuncCall);
10541 n->funcname = SystemFuncName("current_user");
10543 n->agg_order = NIL;
10544 n->agg_star = FALSE;
10545 n->agg_distinct = FALSE;
10546 n->func_variadic = FALSE;
10553 FuncCall *n = makeNode(FuncCall);
10554 n->funcname = SystemFuncName("session_user");
10556 n->agg_order = NIL;
10557 n->agg_star = FALSE;
10558 n->agg_distinct = FALSE;
10559 n->func_variadic = FALSE;
10566 FuncCall *n = makeNode(FuncCall);
10567 n->funcname = SystemFuncName("current_user");
10569 n->agg_order = NIL;
10570 n->agg_star = FALSE;
10571 n->agg_distinct = FALSE;
10572 n->func_variadic = FALSE;
10579 FuncCall *n = makeNode(FuncCall);
10580 n->funcname = SystemFuncName("current_database");
10582 n->agg_order = NIL;
10583 n->agg_star = FALSE;
10584 n->agg_distinct = FALSE;
10585 n->func_variadic = FALSE;
10592 FuncCall *n = makeNode(FuncCall);
10593 n->funcname = SystemFuncName("current_schema");
10595 n->agg_order = NIL;
10596 n->agg_star = FALSE;
10597 n->agg_distinct = FALSE;
10598 n->func_variadic = FALSE;
10603 | CAST '(' a_expr AS Typename ')'
10604 { $$ = makeTypeCast($3, $5, @1); }
10605 | EXTRACT '(' extract_list ')'
10607 FuncCall *n = makeNode(FuncCall);
10608 n->funcname = SystemFuncName("date_part");
10610 n->agg_order = NIL;
10611 n->agg_star = FALSE;
10612 n->agg_distinct = FALSE;
10613 n->func_variadic = FALSE;
10618 | OVERLAY '(' overlay_list ')'
10620 /* overlay(A PLACING B FROM C FOR D) is converted to
10621 * overlay(A, B, C, D)
10622 * overlay(A PLACING B FROM C) is converted to
10625 FuncCall *n = makeNode(FuncCall);
10626 n->funcname = SystemFuncName("overlay");
10628 n->agg_order = NIL;
10629 n->agg_star = FALSE;
10630 n->agg_distinct = FALSE;
10631 n->func_variadic = FALSE;
10636 | POSITION '(' position_list ')'
10638 /* position(A in B) is converted to position(B, A) */
10639 FuncCall *n = makeNode(FuncCall);
10640 n->funcname = SystemFuncName("position");
10642 n->agg_order = NIL;
10643 n->agg_star = FALSE;
10644 n->agg_distinct = FALSE;
10645 n->func_variadic = FALSE;
10650 | SUBSTRING '(' substr_list ')'
10652 /* substring(A from B for C) is converted to
10653 * substring(A, B, C) - thomas 2000-11-28
10655 FuncCall *n = makeNode(FuncCall);
10656 n->funcname = SystemFuncName("substring");
10658 n->agg_order = NIL;
10659 n->agg_star = FALSE;
10660 n->agg_distinct = FALSE;
10661 n->func_variadic = FALSE;
10666 | TREAT '(' a_expr AS Typename ')'
10668 /* TREAT(expr AS target) converts expr of a particular type to target,
10669 * which is defined to be a subtype of the original expression.
10670 * In SQL99, this is intended for use with structured UDTs,
10671 * but let's make this a generally useful form allowing stronger
10672 * coercions than are handled by implicit casting.
10674 FuncCall *n = makeNode(FuncCall);
10675 /* Convert SystemTypeName() to SystemFuncName() even though
10676 * at the moment they result in the same thing.
10678 n->funcname = SystemFuncName(((Value *)llast($5->names))->val.str);
10679 n->args = list_make1($3);
10680 n->agg_order = NIL;
10681 n->agg_star = FALSE;
10682 n->agg_distinct = FALSE;
10683 n->func_variadic = FALSE;
10688 | TRIM '(' BOTH trim_list ')'
10690 /* various trim expressions are defined in SQL92
10691 * - thomas 1997-07-19
10693 FuncCall *n = makeNode(FuncCall);
10694 n->funcname = SystemFuncName("btrim");
10696 n->agg_order = NIL;
10697 n->agg_star = FALSE;
10698 n->agg_distinct = FALSE;
10699 n->func_variadic = FALSE;
10704 | TRIM '(' LEADING trim_list ')'
10706 FuncCall *n = makeNode(FuncCall);
10707 n->funcname = SystemFuncName("ltrim");
10709 n->agg_order = NIL;
10710 n->agg_star = FALSE;
10711 n->agg_distinct = FALSE;
10712 n->func_variadic = FALSE;
10717 | TRIM '(' TRAILING trim_list ')'
10719 FuncCall *n = makeNode(FuncCall);
10720 n->funcname = SystemFuncName("rtrim");
10722 n->agg_order = NIL;
10723 n->agg_star = FALSE;
10724 n->agg_distinct = FALSE;
10725 n->func_variadic = FALSE;
10730 | TRIM '(' trim_list ')'
10732 FuncCall *n = makeNode(FuncCall);
10733 n->funcname = SystemFuncName("btrim");
10735 n->agg_order = NIL;
10736 n->agg_star = FALSE;
10737 n->agg_distinct = FALSE;
10738 n->func_variadic = FALSE;
10743 | NULLIF '(' a_expr ',' a_expr ')'
10745 $$ = (Node *) makeSimpleA_Expr(AEXPR_NULLIF, "=", $3, $5, @1);
10747 | COALESCE '(' expr_list ')'
10749 CoalesceExpr *c = makeNode(CoalesceExpr);
10754 | GREATEST '(' expr_list ')'
10756 MinMaxExpr *v = makeNode(MinMaxExpr);
10758 v->op = IS_GREATEST;
10762 | LEAST '(' expr_list ')'
10764 MinMaxExpr *v = makeNode(MinMaxExpr);
10770 | XMLCONCAT '(' expr_list ')'
10772 $$ = makeXmlExpr(IS_XMLCONCAT, NULL, NIL, $3, @1);
10774 | XMLELEMENT '(' NAME_P ColLabel ')'
10776 $$ = makeXmlExpr(IS_XMLELEMENT, $4, NIL, NIL, @1);
10778 | XMLELEMENT '(' NAME_P ColLabel ',' xml_attributes ')'
10780 $$ = makeXmlExpr(IS_XMLELEMENT, $4, $6, NIL, @1);
10782 | XMLELEMENT '(' NAME_P ColLabel ',' expr_list ')'
10784 $$ = makeXmlExpr(IS_XMLELEMENT, $4, NIL, $6, @1);
10786 | XMLELEMENT '(' NAME_P ColLabel ',' xml_attributes ',' expr_list ')'
10788 $$ = makeXmlExpr(IS_XMLELEMENT, $4, $6, $8, @1);
10790 | XMLEXISTS '(' c_expr xmlexists_argument ')'
10792 /* xmlexists(A PASSING [BY REF] B [BY REF]) is
10793 * converted to xmlexists(A, B)*/
10794 FuncCall *n = makeNode(FuncCall);
10795 n->funcname = SystemFuncName("xmlexists");
10796 n->args = list_make2($3, $4);
10797 n->agg_order = NIL;
10798 n->agg_star = FALSE;
10799 n->agg_distinct = FALSE;
10800 n->func_variadic = FALSE;
10805 | XMLFOREST '(' xml_attribute_list ')'
10807 $$ = makeXmlExpr(IS_XMLFOREST, NULL, $3, NIL, @1);
10809 | XMLPARSE '(' document_or_content a_expr xml_whitespace_option ')'
10811 XmlExpr *x = (XmlExpr *)
10812 makeXmlExpr(IS_XMLPARSE, NULL, NIL,
10813 list_make2($4, makeBoolAConst($5, -1)),
10818 | XMLPI '(' NAME_P ColLabel ')'
10820 $$ = makeXmlExpr(IS_XMLPI, $4, NULL, NIL, @1);
10822 | XMLPI '(' NAME_P ColLabel ',' a_expr ')'
10824 $$ = makeXmlExpr(IS_XMLPI, $4, NULL, list_make1($6), @1);
10826 | XMLROOT '(' a_expr ',' xml_root_version opt_xml_root_standalone ')'
10828 $$ = makeXmlExpr(IS_XMLROOT, NULL, NIL,
10829 list_make3($3, $5, $6), @1);
10831 | XMLSERIALIZE '(' document_or_content a_expr AS SimpleTypename ')'
10833 XmlSerialize *n = makeNode(XmlSerialize);
10845 xml_root_version: VERSION_P a_expr
10847 | VERSION_P NO VALUE_P
10848 { $$ = makeNullAConst(-1); }
10851 opt_xml_root_standalone: ',' STANDALONE_P YES_P
10852 { $$ = makeIntConst(XML_STANDALONE_YES, -1); }
10853 | ',' STANDALONE_P NO
10854 { $$ = makeIntConst(XML_STANDALONE_NO, -1); }
10855 | ',' STANDALONE_P NO VALUE_P
10856 { $$ = makeIntConst(XML_STANDALONE_NO_VALUE, -1); }
10858 { $$ = makeIntConst(XML_STANDALONE_OMITTED, -1); }
10861 xml_attributes: XMLATTRIBUTES '(' xml_attribute_list ')' { $$ = $3; }
10864 xml_attribute_list: xml_attribute_el { $$ = list_make1($1); }
10865 | xml_attribute_list ',' xml_attribute_el { $$ = lappend($1, $3); }
10868 xml_attribute_el: a_expr AS ColLabel
10870 $$ = makeNode(ResTarget);
10872 $$->indirection = NIL;
10873 $$->val = (Node *) $1;
10878 $$ = makeNode(ResTarget);
10880 $$->indirection = NIL;
10881 $$->val = (Node *) $1;
10886 document_or_content: DOCUMENT_P { $$ = XMLOPTION_DOCUMENT; }
10887 | CONTENT_P { $$ = XMLOPTION_CONTENT; }
10890 xml_whitespace_option: PRESERVE WHITESPACE_P { $$ = TRUE; }
10891 | STRIP_P WHITESPACE_P { $$ = FALSE; }
10892 | /*EMPTY*/ { $$ = FALSE; }
10895 /* We allow several variants for SQL and other compatibility. */
10896 xmlexists_argument:
10901 | PASSING c_expr BY REF
10905 | PASSING BY REF c_expr
10909 | PASSING BY REF c_expr BY REF
10917 * Window Definitions
10920 WINDOW window_definition_list { $$ = $2; }
10921 | /*EMPTY*/ { $$ = NIL; }
10924 window_definition_list:
10925 window_definition { $$ = list_make1($1); }
10926 | window_definition_list ',' window_definition
10927 { $$ = lappend($1, $3); }
10931 ColId AS window_specification
10939 over_clause: OVER window_specification
10943 WindowDef *n = makeNode(WindowDef);
10946 n->partitionClause = NIL;
10947 n->orderClause = NIL;
10948 n->frameOptions = FRAMEOPTION_DEFAULTS;
10949 n->startOffset = NULL;
10950 n->endOffset = NULL;
10958 window_specification: '(' opt_existing_window_name opt_partition_clause
10959 opt_sort_clause opt_frame_clause ')'
10961 WindowDef *n = makeNode(WindowDef);
10964 n->partitionClause = $3;
10965 n->orderClause = $4;
10966 /* copy relevant fields of opt_frame_clause */
10967 n->frameOptions = $5->frameOptions;
10968 n->startOffset = $5->startOffset;
10969 n->endOffset = $5->endOffset;
10976 * If we see PARTITION, RANGE, or ROWS as the first token after the '('
10977 * of a window_specification, we want the assumption to be that there is
10978 * no existing_window_name; but those keywords are unreserved and so could
10979 * be ColIds. We fix this by making them have the same precedence as IDENT
10980 * and giving the empty production here a slightly higher precedence, so
10981 * that the shift/reduce conflict is resolved in favor of reducing the rule.
10982 * These keywords are thus precluded from being an existing_window_name but
10983 * are not reserved for any other purpose.
10985 opt_existing_window_name: ColId { $$ = $1; }
10986 | /*EMPTY*/ %prec Op { $$ = NULL; }
10989 opt_partition_clause: PARTITION BY expr_list { $$ = $3; }
10990 | /*EMPTY*/ { $$ = NIL; }
10994 * For frame clauses, we return a WindowDef, but only some fields are used:
10995 * frameOptions, startOffset, and endOffset.
10997 * This is only a subset of the full SQL:2008 frame_clause grammar.
10998 * We don't support <window frame exclusion> yet.
11004 n->frameOptions |= FRAMEOPTION_NONDEFAULT | FRAMEOPTION_RANGE;
11005 if (n->frameOptions & (FRAMEOPTION_START_VALUE_PRECEDING |
11006 FRAMEOPTION_END_VALUE_PRECEDING))
11008 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
11009 errmsg("RANGE PRECEDING is only supported with UNBOUNDED"),
11010 parser_errposition(@1)));
11011 if (n->frameOptions & (FRAMEOPTION_START_VALUE_FOLLOWING |
11012 FRAMEOPTION_END_VALUE_FOLLOWING))
11014 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
11015 errmsg("RANGE FOLLOWING is only supported with UNBOUNDED"),
11016 parser_errposition(@1)));
11019 | ROWS frame_extent
11022 n->frameOptions |= FRAMEOPTION_NONDEFAULT | FRAMEOPTION_ROWS;
11027 WindowDef *n = makeNode(WindowDef);
11028 n->frameOptions = FRAMEOPTION_DEFAULTS;
11029 n->startOffset = NULL;
11030 n->endOffset = NULL;
11035 frame_extent: frame_bound
11038 /* reject invalid cases */
11039 if (n->frameOptions & FRAMEOPTION_START_UNBOUNDED_FOLLOWING)
11041 (errcode(ERRCODE_WINDOWING_ERROR),
11042 errmsg("frame start cannot be UNBOUNDED FOLLOWING"),
11043 parser_errposition(@1)));
11044 if (n->frameOptions & FRAMEOPTION_START_VALUE_FOLLOWING)
11046 (errcode(ERRCODE_WINDOWING_ERROR),
11047 errmsg("frame starting from following row cannot end with current row"),
11048 parser_errposition(@1)));
11049 n->frameOptions |= FRAMEOPTION_END_CURRENT_ROW;
11052 | BETWEEN frame_bound AND frame_bound
11054 WindowDef *n1 = $2;
11055 WindowDef *n2 = $4;
11056 /* form merged options */
11057 int frameOptions = n1->frameOptions;
11058 /* shift converts START_ options to END_ options */
11059 frameOptions |= n2->frameOptions << 1;
11060 frameOptions |= FRAMEOPTION_BETWEEN;
11061 /* reject invalid cases */
11062 if (frameOptions & FRAMEOPTION_START_UNBOUNDED_FOLLOWING)
11064 (errcode(ERRCODE_WINDOWING_ERROR),
11065 errmsg("frame start cannot be UNBOUNDED FOLLOWING"),
11066 parser_errposition(@2)));
11067 if (frameOptions & FRAMEOPTION_END_UNBOUNDED_PRECEDING)
11069 (errcode(ERRCODE_WINDOWING_ERROR),
11070 errmsg("frame end cannot be UNBOUNDED PRECEDING"),
11071 parser_errposition(@4)));
11072 if ((frameOptions & FRAMEOPTION_START_CURRENT_ROW) &&
11073 (frameOptions & FRAMEOPTION_END_VALUE_PRECEDING))
11075 (errcode(ERRCODE_WINDOWING_ERROR),
11076 errmsg("frame starting from current row cannot have preceding rows"),
11077 parser_errposition(@4)));
11078 if ((frameOptions & FRAMEOPTION_START_VALUE_FOLLOWING) &&
11079 (frameOptions & (FRAMEOPTION_END_VALUE_PRECEDING |
11080 FRAMEOPTION_END_CURRENT_ROW)))
11082 (errcode(ERRCODE_WINDOWING_ERROR),
11083 errmsg("frame starting from following row cannot have preceding rows"),
11084 parser_errposition(@4)));
11085 n1->frameOptions = frameOptions;
11086 n1->endOffset = n2->startOffset;
11092 * This is used for both frame start and frame end, with output set up on
11093 * the assumption it's frame start; the frame_extent productions must reject
11097 UNBOUNDED PRECEDING
11099 WindowDef *n = makeNode(WindowDef);
11100 n->frameOptions = FRAMEOPTION_START_UNBOUNDED_PRECEDING;
11101 n->startOffset = NULL;
11102 n->endOffset = NULL;
11105 | UNBOUNDED FOLLOWING
11107 WindowDef *n = makeNode(WindowDef);
11108 n->frameOptions = FRAMEOPTION_START_UNBOUNDED_FOLLOWING;
11109 n->startOffset = NULL;
11110 n->endOffset = NULL;
11115 WindowDef *n = makeNode(WindowDef);
11116 n->frameOptions = FRAMEOPTION_START_CURRENT_ROW;
11117 n->startOffset = NULL;
11118 n->endOffset = NULL;
11123 WindowDef *n = makeNode(WindowDef);
11124 n->frameOptions = FRAMEOPTION_START_VALUE_PRECEDING;
11125 n->startOffset = $1;
11126 n->endOffset = NULL;
11131 WindowDef *n = makeNode(WindowDef);
11132 n->frameOptions = FRAMEOPTION_START_VALUE_FOLLOWING;
11133 n->startOffset = $1;
11134 n->endOffset = NULL;
11141 * Supporting nonterminals for expressions.
11144 /* Explicit row production.
11146 * SQL99 allows an optional ROW keyword, so we can now do single-element rows
11147 * without conflicting with the parenthesized a_expr production. Without the
11148 * ROW keyword, there must be more than one a_expr inside the parens.
11150 row: ROW '(' expr_list ')' { $$ = $3; }
11151 | ROW '(' ')' { $$ = NIL; }
11152 | '(' expr_list ',' a_expr ')' { $$ = lappend($2, $4); }
11155 sub_type: ANY { $$ = ANY_SUBLINK; }
11156 | SOME { $$ = ANY_SUBLINK; }
11157 | ALL { $$ = ALL_SUBLINK; }
11160 all_Op: Op { $$ = $1; }
11161 | MathOp { $$ = $1; }
11164 MathOp: '+' { $$ = "+"; }
11165 | '-' { $$ = "-"; }
11166 | '*' { $$ = "*"; }
11167 | '/' { $$ = "/"; }
11168 | '%' { $$ = "%"; }
11169 | '^' { $$ = "^"; }
11170 | '<' { $$ = "<"; }
11171 | '>' { $$ = ">"; }
11172 | '=' { $$ = "="; }
11176 { $$ = list_make1(makeString($1)); }
11177 | OPERATOR '(' any_operator ')'
11183 { $$ = list_make1(makeString($1)); }
11184 | OPERATOR '(' any_operator ')'
11190 { $$ = list_make1(makeString($1)); }
11191 | OPERATOR '(' any_operator ')'
11194 { $$ = list_make1(makeString("~~")); }
11196 { $$ = list_make1(makeString("!~~")); }
11198 { $$ = list_make1(makeString("~~*")); }
11200 { $$ = list_make1(makeString("!~~*")); }
11201 /* cannot put SIMILAR TO here, because SIMILAR TO is a hack.
11202 * the regular expression is preprocessed by a function (similar_escape),
11203 * and the ~ operator for posix regular expressions is used.
11204 * x SIMILAR TO y -> x ~ similar_escape(y)
11205 * this transformation is made on the fly by the parser upwards.
11206 * however the SubLink structure which handles any/some/all stuff
11207 * is not ready for such a thing.
11213 $$ = list_make1($1);
11215 | expr_list ',' a_expr
11217 $$ = lappend($1, $3);
11221 /* function arguments can have names */
11222 func_arg_list: func_arg_expr
11224 $$ = list_make1($1);
11226 | func_arg_list ',' func_arg_expr
11228 $$ = lappend($1, $3);
11232 func_arg_expr: a_expr
11236 | param_name COLON_EQUALS a_expr
11238 NamedArgExpr *na = makeNode(NamedArgExpr);
11240 na->arg = (Expr *) $3;
11241 na->argnumber = -1; /* until determined */
11247 type_list: Typename { $$ = list_make1($1); }
11248 | type_list ',' Typename { $$ = lappend($1, $3); }
11251 array_expr: '[' expr_list ']'
11253 $$ = makeAArrayExpr($2, @1);
11255 | '[' array_expr_list ']'
11257 $$ = makeAArrayExpr($2, @1);
11261 $$ = makeAArrayExpr(NIL, @1);
11265 array_expr_list: array_expr { $$ = list_make1($1); }
11266 | array_expr_list ',' array_expr { $$ = lappend($1, $3); }
11271 extract_arg FROM a_expr
11273 $$ = list_make2(makeStringConst($1, @1), $3);
11275 | /*EMPTY*/ { $$ = NIL; }
11278 /* Allow delimited string Sconst in extract_arg as an SQL extension.
11279 * - thomas 2001-04-12
11283 | YEAR_P { $$ = "year"; }
11284 | MONTH_P { $$ = "month"; }
11285 | DAY_P { $$ = "day"; }
11286 | HOUR_P { $$ = "hour"; }
11287 | MINUTE_P { $$ = "minute"; }
11288 | SECOND_P { $$ = "second"; }
11289 | Sconst { $$ = $1; }
11292 /* OVERLAY() arguments
11293 * SQL99 defines the OVERLAY() function:
11294 * o overlay(text placing text from int for int)
11295 * o overlay(text placing text from int)
11296 * and similarly for binary strings
11299 a_expr overlay_placing substr_from substr_for
11301 $$ = list_make4($1, $2, $3, $4);
11303 | a_expr overlay_placing substr_from
11305 $$ = list_make3($1, $2, $3);
11314 /* position_list uses b_expr not a_expr to avoid conflict with general IN */
11317 b_expr IN_P b_expr { $$ = list_make2($3, $1); }
11318 | /*EMPTY*/ { $$ = NIL; }
11321 /* SUBSTRING() arguments
11322 * SQL9x defines a specific syntax for arguments to SUBSTRING():
11323 * o substring(text from int for int)
11324 * o substring(text from int) get entire string from starting point "int"
11325 * o substring(text for int) get first "int" characters of string
11326 * o substring(text from pattern) get entire string matching pattern
11327 * o substring(text from pattern for escape) same with specified escape char
11328 * We also want to support generic substring functions which accept
11329 * the usual generic list of arguments. So we will accept both styles
11330 * here, and convert the SQL9x style to the generic list for further
11331 * processing. - thomas 2000-11-28
11334 a_expr substr_from substr_for
11336 $$ = list_make3($1, $2, $3);
11338 | a_expr substr_for substr_from
11340 /* not legal per SQL99, but might as well allow it */
11341 $$ = list_make3($1, $3, $2);
11343 | a_expr substr_from
11345 $$ = list_make2($1, $2);
11347 | a_expr substr_for
11350 * Since there are no cases where this syntax allows
11351 * a textual FOR value, we forcibly cast the argument
11352 * to int4. The possible matches in pg_proc are
11353 * substring(text,int4) and substring(text,text),
11354 * and we don't want the parser to choose the latter,
11355 * which it is likely to do if the second argument
11356 * is unknown or doesn't have an implicit cast to int4.
11358 $$ = list_make3($1, makeIntConst(1, -1),
11360 SystemTypeName("int4"), -1));
11371 FROM a_expr { $$ = $2; }
11374 substr_for: FOR a_expr { $$ = $2; }
11377 trim_list: a_expr FROM expr_list { $$ = lappend($3, $1); }
11378 | FROM expr_list { $$ = $2; }
11379 | expr_list { $$ = $1; }
11382 in_expr: select_with_parens
11384 SubLink *n = makeNode(SubLink);
11386 /* other fields will be filled later */
11389 | '(' expr_list ')' { $$ = (Node *)$2; }
11393 * Define SQL92-style case clause.
11394 * - Full specification
11395 * CASE WHEN a = b THEN c ... ELSE d END
11396 * - Implicit argument
11397 * CASE a WHEN b THEN c ... ELSE d END
11399 case_expr: CASE case_arg when_clause_list case_default END_P
11401 CaseExpr *c = makeNode(CaseExpr);
11402 c->casetype = InvalidOid; /* not analyzed yet */
11403 c->arg = (Expr *) $2;
11405 c->defresult = (Expr *) $4;
11412 /* There must be at least one */
11413 when_clause { $$ = list_make1($1); }
11414 | when_clause_list when_clause { $$ = lappend($1, $2); }
11418 WHEN a_expr THEN a_expr
11420 CaseWhen *w = makeNode(CaseWhen);
11421 w->expr = (Expr *) $2;
11422 w->result = (Expr *) $4;
11429 ELSE a_expr { $$ = $2; }
11430 | /*EMPTY*/ { $$ = NULL; }
11433 case_arg: a_expr { $$ = $1; }
11434 | /*EMPTY*/ { $$ = NULL; }
11439 $$ = makeColumnRef($1, NIL, @1, yyscanner);
11441 | ColId indirection
11443 $$ = makeColumnRef($1, $2, @1, yyscanner);
11450 $$ = (Node *) makeString($2);
11454 $$ = (Node *) makeNode(A_Star);
11458 A_Indices *ai = makeNode(A_Indices);
11463 | '[' a_expr ':' a_expr ']'
11465 A_Indices *ai = makeNode(A_Indices);
11473 indirection_el { $$ = list_make1($1); }
11474 | indirection indirection_el { $$ = lappend($1, $2); }
11478 /*EMPTY*/ { $$ = NIL; }
11479 | opt_indirection indirection_el { $$ = lappend($1, $2); }
11482 opt_asymmetric: ASYMMETRIC
11487 * The SQL spec defines "contextually typed value expressions" and
11488 * "contextually typed row value constructors", which for our purposes
11489 * are the same as "a_expr" and "row" except that DEFAULT can appear at
11494 a_expr { $$ = (Node *) $1; }
11497 SetToDefault *n = makeNode(SetToDefault);
11504 ctext_expr { $$ = list_make1($1); }
11505 | ctext_expr_list ',' ctext_expr { $$ = lappend($1, $3); }
11509 * We should allow ROW '(' ctext_expr_list ')' too, but that seems to require
11510 * making VALUES a fully reserved word, which will probably break more apps
11511 * than allowing the noise-word is worth.
11513 ctext_row: '(' ctext_expr_list ')' { $$ = $2; }
11517 /*****************************************************************************
11519 * target list for SELECT
11521 *****************************************************************************/
11524 target_el { $$ = list_make1($1); }
11525 | target_list ',' target_el { $$ = lappend($1, $3); }
11528 target_el: a_expr AS ColLabel
11530 $$ = makeNode(ResTarget);
11532 $$->indirection = NIL;
11533 $$->val = (Node *)$1;
11537 * We support omitting AS only for column labels that aren't
11538 * any known keyword. There is an ambiguity against postfix
11539 * operators: is "a ! b" an infix expression, or a postfix
11540 * expression and a column label? We prefer to resolve this
11541 * as an infix expression, which we accomplish by assigning
11542 * IDENT a precedence higher than POSTFIXOP.
11546 $$ = makeNode(ResTarget);
11548 $$->indirection = NIL;
11549 $$->val = (Node *)$1;
11554 $$ = makeNode(ResTarget);
11556 $$->indirection = NIL;
11557 $$->val = (Node *)$1;
11562 ColumnRef *n = makeNode(ColumnRef);
11563 n->fields = list_make1(makeNode(A_Star));
11566 $$ = makeNode(ResTarget);
11568 $$->indirection = NIL;
11569 $$->val = (Node *)n;
11575 /*****************************************************************************
11577 * Names and constants
11579 *****************************************************************************/
11581 qualified_name_list:
11582 qualified_name { $$ = list_make1($1); }
11583 | qualified_name_list ',' qualified_name { $$ = lappend($1, $3); }
11587 * The production for a qualified relation name has to exactly match the
11588 * production for a qualified func_name, because in a FROM clause we cannot
11589 * tell which we are parsing until we see what comes after it ('(' for a
11590 * func_name, something else for a relation). Therefore we allow 'indirection'
11591 * which may contain subscripts, and reject that case in the C code.
11596 $$ = makeRangeVar(NULL, $1, @1);
11598 | ColId indirection
11600 check_qualified_name($2, yyscanner);
11601 $$ = makeRangeVar(NULL, NULL, @1);
11602 switch (list_length($2))
11605 $$->catalogname = NULL;
11606 $$->schemaname = $1;
11607 $$->relname = strVal(linitial($2));
11610 $$->catalogname = $1;
11611 $$->schemaname = strVal(linitial($2));
11612 $$->relname = strVal(lsecond($2));
11616 (errcode(ERRCODE_SYNTAX_ERROR),
11617 errmsg("improper qualified name (too many dotted names): %s",
11618 NameListToString(lcons(makeString($1), $2))),
11619 parser_errposition(@1)));
11626 { $$ = list_make1(makeString($1)); }
11627 | name_list ',' name
11628 { $$ = lappend($1, makeString($3)); }
11632 name: ColId { $$ = $1; };
11635 ColId { $$ = $1; };
11638 ColId { $$ = $1; };
11640 attr_name: ColLabel { $$ = $1; };
11642 index_name: ColId { $$ = $1; };
11644 file_name: Sconst { $$ = $1; };
11647 * The production for a qualified func_name has to exactly match the
11648 * production for a qualified columnref, because we cannot tell which we
11649 * are parsing until we see what comes after it ('(' or Sconst for a func_name,
11650 * anything else for a columnref). Therefore we allow 'indirection' which
11651 * may contain subscripts, and reject that case in the C code. (If we
11652 * ever implement SQL99-like methods, such syntax may actually become legal!)
11654 func_name: type_function_name
11655 { $$ = list_make1(makeString($1)); }
11656 | ColId indirection
11658 $$ = check_func_name(lcons(makeString($1), $2),
11669 $$ = makeIntConst($1, @1);
11673 $$ = makeFloatConst($1, @1);
11677 $$ = makeStringConst($1, @1);
11681 $$ = makeBitStringConst($1, @1);
11685 /* This is a bit constant per SQL99:
11686 * Without Feature F511, "BIT data type",
11687 * a <general literal> shall not be a
11688 * <bit string literal> or a <hex string literal>.
11690 $$ = makeBitStringConst($1, @1);
11694 /* generic type 'literal' syntax */
11695 TypeName *t = makeTypeNameFromNameList($1);
11697 $$ = makeStringConstCast($2, @2, t);
11699 | func_name '(' func_arg_list ')' Sconst
11701 /* generic syntax with a type modifier */
11702 TypeName *t = makeTypeNameFromNameList($1);
11706 * We must use func_arg_list in the production to avoid
11707 * reduce/reduce conflicts, but we don't actually wish
11708 * to allow NamedArgExpr in this context.
11712 NamedArgExpr *arg = (NamedArgExpr *) lfirst(lc);
11714 if (IsA(arg, NamedArgExpr))
11716 (errcode(ERRCODE_SYNTAX_ERROR),
11717 errmsg("type modifier cannot have parameter name"),
11718 parser_errposition(arg->location)));
11722 $$ = makeStringConstCast($5, @5, t);
11724 | ConstTypename Sconst
11726 $$ = makeStringConstCast($2, @2, $1);
11728 | ConstInterval Sconst opt_interval
11732 $$ = makeStringConstCast($2, @2, t);
11734 | ConstInterval '(' Iconst ')' Sconst opt_interval
11739 if (list_length($6) != 1)
11741 (errcode(ERRCODE_SYNTAX_ERROR),
11742 errmsg("interval precision specified twice"),
11743 parser_errposition(@1)));
11744 t->typmods = lappend($6, makeIntConst($3, @3));
11747 t->typmods = list_make2(makeIntConst(INTERVAL_FULL_RANGE, -1),
11748 makeIntConst($3, @3));
11749 $$ = makeStringConstCast($5, @5, t);
11753 $$ = makeBoolAConst(TRUE, @1);
11757 $$ = makeBoolAConst(FALSE, @1);
11761 $$ = makeNullAConst(@1);
11765 Iconst: ICONST { $$ = $1; };
11766 Sconst: SCONST { $$ = $1; };
11767 RoleId: ColId { $$ = $1; };
11769 SignedIconst: Iconst { $$ = $1; }
11770 | '+' Iconst { $$ = + $2; }
11771 | '-' Iconst { $$ = - $2; }
11775 * Name classification hierarchy.
11777 * IDENT is the lexeme returned by the lexer for identifiers that match
11778 * no known keyword. In most cases, we can accept certain keywords as
11779 * names, not only IDENTs. We prefer to accept as many such keywords
11780 * as possible to minimize the impact of "reserved words" on programmers.
11781 * So, we divide names into several possible classes. The classification
11782 * is chosen in part to make keywords acceptable as names wherever possible.
11785 /* Column identifier --- names that can be column, table, etc names.
11787 ColId: IDENT { $$ = $1; }
11788 | unreserved_keyword { $$ = pstrdup($1); }
11789 | col_name_keyword { $$ = pstrdup($1); }
11792 /* Type/function identifier --- names that can be type or function names.
11794 type_function_name: IDENT { $$ = $1; }
11795 | unreserved_keyword { $$ = pstrdup($1); }
11796 | type_func_name_keyword { $$ = pstrdup($1); }
11799 /* Column label --- allowed labels in "AS" clauses.
11800 * This presently includes *all* Postgres keywords.
11802 ColLabel: IDENT { $$ = $1; }
11803 | unreserved_keyword { $$ = pstrdup($1); }
11804 | col_name_keyword { $$ = pstrdup($1); }
11805 | type_func_name_keyword { $$ = pstrdup($1); }
11806 | reserved_keyword { $$ = pstrdup($1); }
11811 * Keyword category lists. Generally, every keyword present in
11812 * the Postgres grammar should appear in exactly one of these lists.
11814 * Put a new keyword into the first list that it can go into without causing
11815 * shift or reduce conflicts. The earlier lists define "less reserved"
11816 * categories of keywords.
11818 * Make sure that each keyword's category in kwlist.h matches where
11819 * it is listed here. (Someday we may be able to generate these lists and
11820 * kwlist.h's table from a common master list.)
11823 /* "Unreserved" keywords --- available for use as any kind of name.
11825 unreserved_keyword:
12076 /* Column identifier --- keywords that can be column, table, etc names.
12078 * Many of these keywords will in fact be recognized as type or function
12079 * names too; but they have special productions for the purpose, and so
12080 * can't be treated as "generic" type or function names.
12082 * The type names appearing here are not usable as function names
12083 * because they can be followed by '(' in typename productions, which
12084 * looks too much like a function call for an LR(1) parser.
12136 /* Type/function identifier --- keywords that can be type or function names.
12138 * Most of these are keywords that are used as operators in expressions;
12139 * in general such keywords can't be column names because they would be
12140 * ambiguous with variables, but they are unambiguous as function identifiers.
12142 * Do not include POSITION, SUBSTRING, etc here since they have explicit
12143 * productions in a_expr to support the goofy SQL9x argument syntax.
12144 * - thomas 2000-11-28
12146 type_func_name_keyword:
12171 /* Reserved keyword --- these keywords are usable only as a ColLabel.
12173 * Keywords appear here if they could not be distinguished from variable,
12174 * type, or function names in some contexts. Don't put things here unless
12199 | CURRENT_TIMESTAMP
12259 * The signature of this function is required by bison. However, we
12260 * ignore the passed yylloc and instead use the last token position
12261 * available from the scanner.
12264 base_yyerror(YYLTYPE *yylloc, core_yyscan_t yyscanner, const char *msg)
12266 parser_yyerror(msg);
12270 makeColumnRef(char *colname, List *indirection,
12271 int location, core_yyscan_t yyscanner)
12274 * Generate a ColumnRef node, with an A_Indirection node added if there
12275 * is any subscripting in the specified indirection list. However,
12276 * any field selection at the start of the indirection list must be
12277 * transposed into the "fields" part of the ColumnRef node.
12279 ColumnRef *c = makeNode(ColumnRef);
12283 c->location = location;
12284 foreach(l, indirection)
12286 if (IsA(lfirst(l), A_Indices))
12288 A_Indirection *i = makeNode(A_Indirection);
12292 /* easy case - all indirection goes to A_Indirection */
12293 c->fields = list_make1(makeString(colname));
12294 i->indirection = check_indirection(indirection, yyscanner);
12298 /* got to split the list in two */
12299 i->indirection = check_indirection(list_copy_tail(indirection,
12302 indirection = list_truncate(indirection, nfields);
12303 c->fields = lcons(makeString(colname), indirection);
12305 i->arg = (Node *) c;
12308 else if (IsA(lfirst(l), A_Star))
12310 /* We only allow '*' at the end of a ColumnRef */
12311 if (lnext(l) != NULL)
12312 parser_yyerror("improper use of \"*\"");
12316 /* No subscripting, so all indirection gets added to field list */
12317 c->fields = lcons(makeString(colname), indirection);
12322 makeTypeCast(Node *arg, TypeName *typename, int location)
12324 TypeCast *n = makeNode(TypeCast);
12326 n->typeName = typename;
12327 n->location = location;
12332 makeStringConst(char *str, int location)
12334 A_Const *n = makeNode(A_Const);
12336 n->val.type = T_String;
12337 n->val.val.str = str;
12338 n->location = location;
12344 makeStringConstCast(char *str, int location, TypeName *typename)
12346 Node *s = makeStringConst(str, location);
12348 return makeTypeCast(s, typename, -1);
12352 makeIntConst(int val, int location)
12354 A_Const *n = makeNode(A_Const);
12356 n->val.type = T_Integer;
12357 n->val.val.ival = val;
12358 n->location = location;
12364 makeFloatConst(char *str, int location)
12366 A_Const *n = makeNode(A_Const);
12368 n->val.type = T_Float;
12369 n->val.val.str = str;
12370 n->location = location;
12376 makeBitStringConst(char *str, int location)
12378 A_Const *n = makeNode(A_Const);
12380 n->val.type = T_BitString;
12381 n->val.val.str = str;
12382 n->location = location;
12388 makeNullAConst(int location)
12390 A_Const *n = makeNode(A_Const);
12392 n->val.type = T_Null;
12393 n->location = location;
12399 makeAConst(Value *v, int location)
12406 n = makeFloatConst(v->val.str, location);
12410 n = makeIntConst(v->val.ival, location);
12415 n = makeStringConst(v->val.str, location);
12422 /* makeBoolAConst()
12423 * Create an A_Const string node and put it inside a boolean cast.
12426 makeBoolAConst(bool state, int location)
12428 A_Const *n = makeNode(A_Const);
12430 n->val.type = T_String;
12431 n->val.val.str = (state ? "t" : "f");
12432 n->location = location;
12434 return makeTypeCast((Node *)n, SystemTypeName("bool"), -1);
12438 * Create and populate a FuncCall node to support the OVERLAPS operator.
12441 makeOverlaps(List *largs, List *rargs, int location, core_yyscan_t yyscanner)
12443 FuncCall *n = makeNode(FuncCall);
12445 n->funcname = SystemFuncName("overlaps");
12446 if (list_length(largs) == 1)
12447 largs = lappend(largs, largs);
12448 else if (list_length(largs) != 2)
12450 (errcode(ERRCODE_SYNTAX_ERROR),
12451 errmsg("wrong number of parameters on left side of OVERLAPS expression"),
12452 parser_errposition(location)));
12453 if (list_length(rargs) == 1)
12454 rargs = lappend(rargs, rargs);
12455 else if (list_length(rargs) != 2)
12457 (errcode(ERRCODE_SYNTAX_ERROR),
12458 errmsg("wrong number of parameters on right side of OVERLAPS expression"),
12459 parser_errposition(location)));
12460 n->args = list_concat(largs, rargs);
12461 n->agg_order = NIL;
12462 n->agg_star = FALSE;
12463 n->agg_distinct = FALSE;
12464 n->func_variadic = FALSE;
12466 n->location = location;
12470 /* check_qualified_name --- check the result of qualified_name production
12472 * It's easiest to let the grammar production for qualified_name allow
12473 * subscripts and '*', which we then must reject here.
12476 check_qualified_name(List *names, core_yyscan_t yyscanner)
12482 if (!IsA(lfirst(i), String))
12483 parser_yyerror("syntax error");
12487 /* check_func_name --- check the result of func_name production
12489 * It's easiest to let the grammar production for func_name allow subscripts
12490 * and '*', which we then must reject here.
12493 check_func_name(List *names, core_yyscan_t yyscanner)
12499 if (!IsA(lfirst(i), String))
12500 parser_yyerror("syntax error");
12505 /* check_indirection --- check the result of indirection production
12507 * We only allow '*' at the end of the list, but it's hard to enforce that
12508 * in the grammar, so do it here.
12511 check_indirection(List *indirection, core_yyscan_t yyscanner)
12515 foreach(l, indirection)
12517 if (IsA(lfirst(l), A_Star))
12519 if (lnext(l) != NULL)
12520 parser_yyerror("improper use of \"*\"");
12523 return indirection;
12526 /* extractArgTypes()
12527 * Given a list of FunctionParameter nodes, extract a list of just the
12528 * argument types (TypeNames) for input parameters only. This is what
12529 * is needed to look up an existing function, which is what is wanted by
12530 * the productions that use this call.
12533 extractArgTypes(List *parameters)
12535 List *result = NIL;
12538 foreach(i, parameters)
12540 FunctionParameter *p = (FunctionParameter *) lfirst(i);
12542 if (p->mode != FUNC_PARAM_OUT && p->mode != FUNC_PARAM_TABLE)
12543 result = lappend(result, p->argType);
12548 /* findLeftmostSelect()
12549 * Find the leftmost component SelectStmt in a set-operation parsetree.
12551 static SelectStmt *
12552 findLeftmostSelect(SelectStmt *node)
12554 while (node && node->op != SETOP_NONE)
12556 Assert(node && IsA(node, SelectStmt) && node->larg == NULL);
12560 /* insertSelectOptions()
12561 * Insert ORDER BY, etc into an already-constructed SelectStmt.
12563 * This routine is just to avoid duplicating code in SelectStmt productions.
12566 insertSelectOptions(SelectStmt *stmt,
12567 List *sortClause, List *lockingClause,
12568 Node *limitOffset, Node *limitCount,
12569 WithClause *withClause,
12570 core_yyscan_t yyscanner)
12572 Assert(IsA(stmt, SelectStmt));
12575 * Tests here are to reject constructs like
12576 * (SELECT foo ORDER BY bar) ORDER BY baz
12580 if (stmt->sortClause)
12582 (errcode(ERRCODE_SYNTAX_ERROR),
12583 errmsg("multiple ORDER BY clauses not allowed"),
12584 parser_errposition(exprLocation((Node *) sortClause))));
12585 stmt->sortClause = sortClause;
12587 /* We can handle multiple locking clauses, though */
12588 stmt->lockingClause = list_concat(stmt->lockingClause, lockingClause);
12591 if (stmt->limitOffset)
12593 (errcode(ERRCODE_SYNTAX_ERROR),
12594 errmsg("multiple OFFSET clauses not allowed"),
12595 parser_errposition(exprLocation(limitOffset))));
12596 stmt->limitOffset = limitOffset;
12600 if (stmt->limitCount)
12602 (errcode(ERRCODE_SYNTAX_ERROR),
12603 errmsg("multiple LIMIT clauses not allowed"),
12604 parser_errposition(exprLocation(limitCount))));
12605 stmt->limitCount = limitCount;
12609 if (stmt->withClause)
12611 (errcode(ERRCODE_SYNTAX_ERROR),
12612 errmsg("multiple WITH clauses not allowed"),
12613 parser_errposition(exprLocation((Node *) withClause))));
12614 stmt->withClause = withClause;
12619 makeSetOp(SetOperation op, bool all, Node *larg, Node *rarg)
12621 SelectStmt *n = makeNode(SelectStmt);
12625 n->larg = (SelectStmt *) larg;
12626 n->rarg = (SelectStmt *) rarg;
12630 /* SystemFuncName()
12631 * Build a properly-qualified reference to a built-in function.
12634 SystemFuncName(char *name)
12636 return list_make2(makeString("pg_catalog"), makeString(name));
12639 /* SystemTypeName()
12640 * Build a properly-qualified reference to a built-in type.
12642 * typmod is defaulted, but may be changed afterwards by caller.
12643 * Likewise for the location.
12646 SystemTypeName(char *name)
12648 return makeTypeNameFromNameList(list_make2(makeString("pg_catalog"),
12649 makeString(name)));
12653 * Handle negation of a numeric constant.
12655 * Formerly, we did this here because the optimizer couldn't cope with
12656 * indexquals that looked like "var = -4" --- it wants "var = const"
12657 * and a unary minus operator applied to a constant didn't qualify.
12658 * As of Postgres 7.0, that problem doesn't exist anymore because there
12659 * is a constant-subexpression simplifier in the optimizer. However,
12660 * there's still a good reason for doing this here, which is that we can
12661 * postpone committing to a particular internal representation for simple
12662 * negative constants. It's better to leave "-123.456" in string form
12663 * until we know what the desired type is.
12666 doNegate(Node *n, int location)
12668 if (IsA(n, A_Const))
12670 A_Const *con = (A_Const *)n;
12672 /* report the constant's location as that of the '-' sign */
12673 con->location = location;
12675 if (con->val.type == T_Integer)
12677 con->val.val.ival = -con->val.val.ival;
12680 if (con->val.type == T_Float)
12682 doNegateFloat(&con->val);
12687 return (Node *) makeSimpleA_Expr(AEXPR_OP, "-", NULL, n, location);
12691 doNegateFloat(Value *v)
12693 char *oldval = v->val.str;
12695 Assert(IsA(v, Float));
12696 if (*oldval == '+')
12698 if (*oldval == '-')
12699 v->val.str = oldval+1; /* just strip the '-' */
12702 char *newval = (char *) palloc(strlen(oldval) + 2);
12705 strcpy(newval+1, oldval);
12706 v->val.str = newval;
12711 makeAArrayExpr(List *elements, int location)
12713 A_ArrayExpr *n = makeNode(A_ArrayExpr);
12715 n->elements = elements;
12716 n->location = location;
12721 makeXmlExpr(XmlExprOp op, char *name, List *named_args, List *args,
12724 XmlExpr *x = makeNode(XmlExpr);
12729 * named_args is a list of ResTarget; it'll be split apart into separate
12730 * expression and name lists in transformXmlExpr().
12732 x->named_args = named_args;
12733 x->arg_names = NIL;
12735 /* xmloption, if relevant, must be filled in by caller */
12736 /* type and typmod will be filled in during parse analysis */
12737 x->location = location;
12742 * Merge the input and output parameters of a table function.
12745 mergeTableFuncParameters(List *func_args, List *columns)
12749 /* Explicit OUT and INOUT parameters shouldn't be used in this syntax */
12750 foreach(lc, func_args)
12752 FunctionParameter *p = (FunctionParameter *) lfirst(lc);
12754 if (p->mode != FUNC_PARAM_IN && p->mode != FUNC_PARAM_VARIADIC)
12756 (errcode(ERRCODE_SYNTAX_ERROR),
12757 errmsg("OUT and INOUT arguments aren't allowed in TABLE functions")));
12760 return list_concat(func_args, columns);
12764 * Determine return type of a TABLE function. A single result column
12765 * returns setof that column's type; otherwise return setof record.
12768 TableFuncTypeName(List *columns)
12772 if (list_length(columns) == 1)
12774 FunctionParameter *p = (FunctionParameter *) linitial(columns);
12776 result = (TypeName *) copyObject(p->argType);
12779 result = SystemTypeName("record");
12781 result->setof = true;
12787 * Convert a list of (dotted) names to a RangeVar (like
12788 * makeRangeVarFromNameList, but with position support). The
12789 * "AnyName" refers to the any_name production in the grammar.
12792 makeRangeVarFromAnyName(List *names, int position, core_yyscan_t yyscanner)
12794 RangeVar *r = makeNode(RangeVar);
12796 switch (list_length(names))
12799 r->catalogname = NULL;
12800 r->schemaname = NULL;
12801 r->relname = strVal(linitial(names));
12804 r->catalogname = NULL;
12805 r->schemaname = strVal(linitial(names));
12806 r->relname = strVal(lsecond(names));
12809 r->catalogname = strVal(linitial(names));;
12810 r->schemaname = strVal(lsecond(names));
12811 r->relname = strVal(lthird(names));
12815 (errcode(ERRCODE_SYNTAX_ERROR),
12816 errmsg("improper qualified name (too many dotted names): %s",
12817 NameListToString(names)),
12818 parser_errposition(position)));
12822 r->relpersistence = RELPERSISTENCE_PERMANENT;
12823 r->location = position;
12828 /* Separate Constraint nodes from COLLATE clauses in a ColQualList */
12830 SplitColQualList(List *qualList,
12831 List **constraintList, CollateClause **collClause,
12832 core_yyscan_t yyscanner)
12838 *collClause = NULL;
12840 for (cell = list_head(qualList); cell; cell = next)
12842 Node *n = (Node *) lfirst(cell);
12844 next = lnext(cell);
12845 if (IsA(n, Constraint))
12847 /* keep it in list */
12851 if (IsA(n, CollateClause))
12853 CollateClause *c = (CollateClause *) n;
12857 (errcode(ERRCODE_SYNTAX_ERROR),
12858 errmsg("multiple COLLATE clauses not allowed"),
12859 parser_errposition(c->location)));
12863 elog(ERROR, "unexpected node type %d", (int) n->type);
12864 /* remove non-Constraint nodes from qualList */
12865 qualList = list_delete_cell(qualList, cell, prev);
12867 *constraintList = qualList;
12871 * Initialize to parse one query string
12874 parser_init(base_yy_extra_type *yyext)
12876 yyext->parsetree = NIL; /* in case grammar forgets to set it */
12880 * Must undefine this stuff before including scan.c, since it has different
12881 * definitions for these macros.