4 /*-------------------------------------------------------------------------
7 * POSTGRESQL BISON rules/actions
9 * Portions Copyright (c) 1996-2010, 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);
140 %name-prefix="base_yy"
143 %parse-param {core_yyscan_t yyscanner}
144 %lex-param {core_yyscan_t yyscanner}
148 core_YYSTYPE core_yystype;
149 /* these fields must match core_YYSTYPE: */
157 DropBehavior dbehavior;
158 OnCommitAction oncommit;
164 FunctionParameter *fun_param;
165 FunctionParameterMode fun_param_mode;
166 FuncWithArgs *funwithargs;
178 struct PrivTarget *privtarget;
179 AccessPriv *accesspriv;
181 VariableSetStmt *vsetstmt;
184 %type <node> stmt schema_stmt
185 AlterDatabaseStmt AlterDatabaseSetStmt AlterDomainStmt AlterFdwStmt
186 AlterForeignServerStmt AlterGroupStmt
187 AlterObjectSchemaStmt AlterOwnerStmt AlterSeqStmt AlterTableStmt
188 AlterCompositeTypeStmt AlterUserStmt AlterUserMappingStmt AlterUserSetStmt
189 AlterRoleStmt AlterRoleSetStmt
190 AlterDefaultPrivilegesStmt DefACLAction
191 AnalyzeStmt ClosePortalStmt ClusterStmt CommentStmt
192 ConstraintsSetStmt CopyStmt CreateAsStmt CreateCastStmt
193 CreateDomainStmt CreateGroupStmt CreateOpClassStmt
194 CreateOpFamilyStmt AlterOpFamilyStmt CreatePLangStmt
195 CreateSchemaStmt CreateSeqStmt CreateStmt CreateTableSpaceStmt
196 CreateFdwStmt CreateForeignServerStmt CreateAssertStmt CreateTrigStmt
197 CreateUserStmt CreateUserMappingStmt CreateRoleStmt
198 CreatedbStmt DeclareCursorStmt DefineStmt DeleteStmt DiscardStmt DoStmt
199 DropGroupStmt DropOpClassStmt DropOpFamilyStmt DropPLangStmt DropStmt
200 DropAssertStmt DropTrigStmt DropRuleStmt DropCastStmt DropRoleStmt
201 DropUserStmt DropdbStmt DropTableSpaceStmt DropFdwStmt
202 DropForeignServerStmt DropUserMappingStmt ExplainStmt FetchStmt
203 GrantStmt GrantRoleStmt IndexStmt InsertStmt ListenStmt LoadStmt
204 LockStmt NotifyStmt ExplainableStmt PreparableStmt
205 CreateFunctionStmt AlterFunctionStmt ReindexStmt RemoveAggrStmt
206 RemoveFuncStmt RemoveOperStmt RenameStmt RevokeStmt RevokeRoleStmt
207 RuleActionStmt RuleActionStmtOrEmpty RuleStmt
208 SelectStmt TransactionStmt TruncateStmt
209 UnlistenStmt UpdateStmt VacuumStmt
210 VariableResetStmt VariableSetStmt VariableShowStmt
211 ViewStmt CheckPointStmt CreateConversionStmt
212 DeallocateStmt PrepareStmt ExecuteStmt
213 DropOwnedStmt ReassignOwnedStmt
214 AlterTSConfigurationStmt AlterTSDictionaryStmt
216 %type <node> select_no_parens select_with_parens select_clause
217 simple_select values_clause
219 %type <node> alter_column_default opclass_item opclass_drop alter_using
220 %type <ival> add_drop opt_asc_desc opt_nulls_order
222 %type <node> alter_table_cmd alter_type_cmd
223 %type <list> alter_table_cmds alter_type_cmds
225 %type <dbehavior> opt_drop_behavior
227 %type <list> createdb_opt_list alterdb_opt_list copy_opt_list
228 transaction_mode_list
229 %type <defelt> createdb_opt_item alterdb_opt_item copy_opt_item
230 transaction_mode_item
232 %type <ival> opt_lock lock_type cast_context
233 %type <ival> vacuum_option_list vacuum_option_elem
234 %type <boolean> opt_force opt_or_replace
235 opt_grant_grant_option opt_grant_admin_option
236 opt_nowait opt_if_exists opt_with_data
238 %type <list> OptRoleList AlterOptRoleList
239 %type <defelt> CreateOptRoleElem AlterOptRoleElem
242 %type <str> foreign_server_version opt_foreign_server_version
243 %type <str> auth_ident
244 %type <str> opt_in_database
246 %type <str> OptSchemaName
247 %type <list> OptSchemaEltList
249 %type <boolean> TriggerActionTime TriggerForSpec opt_trusted opt_restart_seqs
251 %type <list> TriggerEvents TriggerOneEvent
252 %type <value> TriggerFuncArg
253 %type <node> TriggerWhen
255 %type <str> copy_file_name
256 database_name access_method_clause access_method attr_name
257 name cursor_name file_name
258 index_name opt_index_name cluster_index_specification
260 %type <list> func_name handler_name qual_Op qual_all_Op subquery_Op
261 opt_class opt_inline_handler opt_validator validator_clause
263 %type <range> qualified_name OptConstrFromTable
265 %type <str> all_Op MathOp
267 %type <str> iso_level opt_encoding
269 %type <list> grantee_list
270 %type <accesspriv> privilege
271 %type <list> privileges privilege_list
272 %type <privtarget> privilege_target
273 %type <funwithargs> function_with_argtypes
274 %type <list> function_with_argtypes_list
275 %type <ival> defacl_privilege_target
276 %type <defelt> DefACLOption
277 %type <list> DefACLOptionList
279 %type <list> stmtblock stmtmulti
280 OptTableElementList TableElementList OptInherit definition
281 OptTypedTableElementList TypedTableElementList
282 reloptions opt_reloptions
283 OptWith opt_distinct opt_definition func_args func_args_list
284 func_args_with_defaults func_args_with_defaults_list
285 func_as createfunc_opt_list alterfunc_opt_list
286 aggr_args old_aggr_definition old_aggr_list
287 oper_argtypes RuleActionList RuleActionMulti
288 opt_column_list columnList opt_name_list
289 sort_clause opt_sort_clause sortby_list index_params
290 name_list from_clause from_list opt_array_bounds
291 qualified_name_list any_name any_name_list
292 any_operator expr_list attrs
293 target_list insert_column_list set_target_list
294 set_clause_list set_clause multiple_set_clause
295 ctext_expr_list ctext_row def_list indirection opt_indirection
296 reloption_list group_clause TriggerFuncArgs select_limit
297 opt_select_limit opclass_item_list opclass_drop_list
298 opt_opfamily transaction_mode_list_or_empty
299 OptTableFuncElementList TableFuncElementList opt_type_modifiers
301 execute_param_clause using_clause returning_clause
302 opt_enum_val_list enum_val_list table_func_column_list
303 create_generic_options alter_generic_options
304 relation_expr_list dostmt_opt_list
306 %type <range> OptTempTableName
307 %type <into> into_clause create_as_target
309 %type <defelt> createfunc_opt_item common_func_opt_item dostmt_opt_item
310 %type <fun_param> func_arg func_arg_with_default table_func_column
311 %type <fun_param_mode> arg_class
312 %type <typnam> func_return func_type
314 %type <boolean> TriggerForType OptTemp
315 %type <oncommit> OnCommitOption
317 %type <node> for_locking_item
318 %type <list> for_locking_clause opt_for_locking_clause for_locking_items
319 %type <list> locked_rels_list
320 %type <boolean> opt_all
322 %type <node> join_outer join_qual
323 %type <jtype> join_type
325 %type <list> extract_list overlay_list position_list
326 %type <list> substr_list trim_list
327 %type <list> opt_interval interval_second
328 %type <node> overlay_placing substr_from substr_for
330 %type <boolean> opt_instead
331 %type <boolean> opt_unique opt_concurrently opt_verbose opt_full
332 %type <boolean> opt_freeze opt_default opt_recheck
333 %type <defelt> opt_binary opt_oids copy_delimiter
335 %type <boolean> copy_from
337 %type <ival> opt_column event cursor_options opt_hold opt_set_data
338 %type <objtype> reindex_type drop_type comment_type
340 %type <node> fetch_args limit_clause select_limit_value
341 offset_clause select_offset_value
342 select_offset_value2 opt_select_fetch_first_value
343 %type <ival> row_or_rows first_or_next
345 %type <list> OptSeqOptList SeqOptList
346 %type <defelt> SeqOptElem
348 %type <istmt> insert_rest
350 %type <vsetstmt> set_rest SetResetClause
352 %type <node> TableElement TypedTableElement ConstraintElem TableFuncElement
353 %type <node> columnDef columnOptions
354 %type <defelt> def_elem reloption_elem old_aggr_elem
355 %type <node> def_arg columnElem where_clause where_or_current_clause
356 a_expr b_expr c_expr func_expr AexprConst indirection_el
357 columnref in_expr having_clause func_table array_expr
359 %type <list> ExclusionConstraintList ExclusionConstraintElem
360 %type <list> func_arg_list
361 %type <node> func_arg_expr
362 %type <list> row type_list array_expr_list
363 %type <node> case_expr case_arg when_clause case_default
364 %type <list> when_clause_list
365 %type <ival> sub_type
366 %type <list> OptCreateAs CreateAsList
367 %type <node> CreateAsElement ctext_expr
368 %type <value> NumericOnly
369 %type <list> NumericOnly_list
370 %type <alias> alias_clause
371 %type <sortby> sortby
372 %type <ielem> index_elem
373 %type <node> table_ref
374 %type <jexpr> joined_table
375 %type <range> relation_expr
376 %type <range> relation_expr_opt_alias
377 %type <target> target_el single_set_clause set_target insert_column_item
379 %type <str> generic_option_name
380 %type <node> generic_option_arg
381 %type <defelt> generic_option_elem alter_generic_option_elem
382 %type <list> generic_option_list alter_generic_option_list
383 %type <str> explain_option_name
384 %type <node> explain_option_arg
385 %type <defelt> explain_option_elem
386 %type <list> explain_option_list
387 %type <node> copy_generic_opt_arg copy_generic_opt_arg_list_item
388 %type <defelt> copy_generic_opt_elem
389 %type <list> copy_generic_opt_list copy_generic_opt_arg_list
390 %type <list> copy_options
392 %type <typnam> Typename SimpleTypename ConstTypename
393 GenericType Numeric opt_float
394 Character ConstCharacter
395 CharacterWithLength CharacterWithoutLength
396 ConstDatetime ConstInterval
397 Bit ConstBit BitWithLength BitWithoutLength
398 %type <str> character
399 %type <str> extract_arg
400 %type <str> opt_charset
401 %type <boolean> opt_varying opt_timezone
403 %type <ival> Iconst SignedIconst
404 %type <str> Sconst comment_text notify_payload
405 %type <str> RoleId opt_granted_by opt_boolean ColId_or_Sconst
406 %type <list> var_list
407 %type <str> ColId ColLabel var_name type_function_name param_name
408 %type <node> var_value zone_value
410 %type <keyword> unreserved_keyword type_func_name_keyword
411 %type <keyword> col_name_keyword reserved_keyword
413 %type <node> TableConstraint TableLikeClause
414 %type <ival> TableLikeOptionList TableLikeOption
415 %type <list> ColQualList
416 %type <node> ColConstraint ColConstraintElem ConstraintAttr
417 %type <ival> key_actions key_delete key_match key_update key_action
418 %type <ival> ConstraintAttributeSpec ConstraintDeferrabilitySpec
421 %type <list> constraints_set_list
422 %type <boolean> constraints_set_mode
423 %type <str> OptTableSpace OptConsTableSpace OptTableSpaceOwner
424 %type <list> opt_check_option
426 %type <target> xml_attribute_el
427 %type <list> xml_attribute_list xml_attributes
428 %type <node> xml_root_version opt_xml_root_standalone
429 %type <node> xmlexists_argument
430 %type <ival> document_or_content
431 %type <boolean> xml_whitespace_option
433 %type <node> common_table_expr
434 %type <with> with_clause
435 %type <list> cte_list
437 %type <list> window_clause window_definition_list opt_partition_clause
438 %type <windef> window_definition over_clause window_specification
439 opt_frame_clause frame_extent frame_bound
440 %type <str> opt_existing_window_name
444 * Non-keyword token types. These are hard-wired into the "flex" lexer.
445 * They must be listed first so that their numeric codes do not depend on
446 * the set of keywords. PL/pgsql depends on this so that it can share the
447 * same lexer. If you add/change tokens here, fix PL/pgsql to match!
449 * DOT_DOT is unused in the core SQL grammar, and so will always provoke
450 * parse errors. It is needed by PL/pgsql.
452 %token <str> IDENT FCONST SCONST BCONST XCONST Op
453 %token <ival> ICONST PARAM
454 %token TYPECAST DOT_DOT COLON_EQUALS
457 * If you want to make any keyword changes, update the keyword table in
458 * src/include/parser/kwlist.h and add new keywords to the appropriate one
459 * of the reserved-or-not-so-reserved keyword lists, below; search
460 * this file for "Keyword category lists".
463 /* ordinary key words in alphabetical order */
464 %token <keyword> ABORT_P ABSOLUTE_P ACCESS ACTION ADD_P ADMIN AFTER
465 AGGREGATE ALL ALSO ALTER ALWAYS ANALYSE ANALYZE AND ANY ARRAY AS ASC
466 ASSERTION ASSIGNMENT ASYMMETRIC AT ATTRIBUTE AUTHORIZATION
468 BACKWARD BEFORE BEGIN_P BETWEEN BIGINT BINARY BIT
471 CACHE CALLED CASCADE CASCADED CASE CAST CATALOG_P CHAIN CHAR_P
472 CHARACTER CHARACTERISTICS CHECK CHECKPOINT CLASS CLOSE
473 CLUSTER COALESCE COLLATE COLUMN COMMENT COMMENTS COMMIT
474 COMMITTED CONCURRENTLY CONFIGURATION CONNECTION CONSTRAINT CONSTRAINTS
475 CONTENT_P CONTINUE_P CONVERSION_P COPY COST CREATE CREATEDB
476 CREATEROLE CREATEUSER CROSS CSV CURRENT_P
477 CURRENT_CATALOG CURRENT_DATE CURRENT_ROLE CURRENT_SCHEMA
478 CURRENT_TIME CURRENT_TIMESTAMP CURRENT_USER CURSOR CYCLE
480 DATA_P DATABASE DAY_P DEALLOCATE DEC DECIMAL_P DECLARE DEFAULT DEFAULTS
481 DEFERRABLE DEFERRED DEFINER DELETE_P DELIMITER DELIMITERS DESC
482 DICTIONARY DISABLE_P DISCARD DISTINCT DO DOCUMENT_P DOMAIN_P DOUBLE_P DROP
484 EACH ELSE ENABLE_P ENCODING ENCRYPTED END_P ENUM_P ESCAPE EXCEPT
485 EXCLUDE EXCLUDING EXCLUSIVE EXECUTE EXISTS EXPLAIN EXTERNAL EXTRACT
487 FALSE_P FAMILY FETCH FIRST_P FLOAT_P FOLLOWING FOR FORCE FOREIGN FORWARD
488 FREEZE FROM FULL FUNCTION FUNCTIONS
490 GLOBAL GRANT GRANTED GREATEST GROUP_P
492 HANDLER HAVING HEADER_P HOLD HOUR_P
494 IDENTITY_P IF_P ILIKE IMMEDIATE IMMUTABLE IMPLICIT_P IN_P
495 INCLUDING INCREMENT INDEX INDEXES INHERIT INHERITS INITIALLY INLINE_P
496 INNER_P INOUT INPUT_P INSENSITIVE INSERT INSTEAD INT_P INTEGER
497 INTERSECT INTERVAL INTO INVOKER IS ISNULL ISOLATION
503 LANGUAGE LARGE_P LAST_P LC_COLLATE_P LC_CTYPE_P LEADING
504 LEAST LEFT LEVEL LIKE LIMIT LISTEN LOAD LOCAL LOCALTIME LOCALTIMESTAMP
505 LOCATION LOCK_P LOGIN_P
507 MAPPING MATCH MAXVALUE MINUTE_P MINVALUE MODE MONTH_P MOVE
509 NAME_P NAMES NATIONAL NATURAL NCHAR NEXT NO NOCREATEDB
510 NOCREATEROLE NOCREATEUSER NOINHERIT NOLOGIN_P NONE NOSUPERUSER
511 NOT NOTHING NOTIFY NOTNULL NOWAIT NULL_P NULLIF NULLS_P NUMERIC
513 OBJECT_P OF OFF OFFSET OIDS ON ONLY OPERATOR OPTION OPTIONS OR
514 ORDER OUT_P OUTER_P OVER OVERLAPS OVERLAY OWNED OWNER
516 PARSER PARTIAL PARTITION PASSING PASSWORD PLACING PLANS POSITION
517 PRECEDING PRECISION PRESERVE PREPARE PREPARED PRIMARY
518 PRIOR PRIVILEGES PROCEDURAL PROCEDURE
522 RANGE READ REAL REASSIGN RECHECK RECURSIVE REF REFERENCES REINDEX
523 RELATIVE_P RELEASE RENAME REPEATABLE REPLACE REPLICA RESET RESTART
524 RESTRICT RETURNING RETURNS REVOKE RIGHT ROLE ROLLBACK ROW ROWS RULE
526 SAVEPOINT SCHEMA SCROLL SEARCH SECOND_P SECURITY SELECT SEQUENCE SEQUENCES
527 SERIALIZABLE SERVER SESSION SESSION_USER SET SETOF SHARE
528 SHOW SIMILAR SIMPLE SMALLINT SOME STABLE STANDALONE_P START STATEMENT
529 STATISTICS STDIN STDOUT STORAGE STRICT_P STRIP_P SUBSTRING SUPERUSER_P
530 SYMMETRIC SYSID SYSTEM_P
532 TABLE TABLES TABLESPACE TEMP TEMPLATE TEMPORARY TEXT_P THEN TIME TIMESTAMP
533 TO TRAILING TRANSACTION TREAT TRIGGER TRIM TRUE_P
534 TRUNCATE TRUSTED TYPE_P
536 UNBOUNDED UNCOMMITTED UNENCRYPTED UNION UNIQUE UNKNOWN UNLISTEN UNTIL
539 VACUUM VALID VALIDATOR VALUE_P VALUES VARCHAR VARIADIC VARYING
540 VERBOSE VERSION_P VIEW VOLATILE
542 WHEN WHERE WHITESPACE_P WINDOW WITH WITHOUT WORK WRAPPER WRITE
544 XML_P XMLATTRIBUTES XMLCONCAT XMLELEMENT XMLEXISTS XMLFOREST XMLPARSE
545 XMLPI XMLROOT XMLSERIALIZE
552 * The grammar thinks these are keywords, but they are not in the kwlist.h
553 * list and so can never be entered directly. The filter in parser.c
554 * creates these tokens when required.
556 %token NULLS_FIRST NULLS_LAST WITH_TIME
559 /* Precedence: lowest to highest */
560 %nonassoc SET /* see relation_expr_opt_alias */
568 %nonassoc LIKE ILIKE SIMILAR
573 %left POSTFIXOP /* dummy for postfix Op rules */
575 * To support target_el without AS, we must give IDENT an explicit priority
576 * between POSTFIXOP and Op. We can safely assign the same priority to
577 * various unreserved keywords as needed to resolve ambiguities (this can't
578 * have any bad effects since obviously the keywords will still behave the
579 * same as if they weren't keywords). We need to do this for PARTITION,
580 * RANGE, ROWS to support opt_existing_window_name; and for RANGE, ROWS
581 * so that they can follow a_expr without creating
582 * postfix-operator problems.
584 * The frame_bound productions UNBOUNDED PRECEDING and UNBOUNDED FOLLOWING
585 * are even messier: since UNBOUNDED is an unreserved keyword (per spec!),
586 * there is no principled way to distinguish these from the productions
587 * a_expr PRECEDING/FOLLOWING. We hack this up by giving UNBOUNDED slightly
588 * lower precedence than PRECEDING and FOLLOWING. At present this doesn't
589 * appear to cause UNBOUNDED to be treated differently from other unreserved
590 * keywords anywhere else in the grammar, but it's definitely risky. We can
591 * blame any funny behavior of UNBOUNDED on the SQL standard, though.
593 %nonassoc UNBOUNDED /* ideally should have same precedence as IDENT */
594 %nonassoc IDENT PARTITION RANGE ROWS PRECEDING FOLLOWING
595 %left Op OPERATOR /* multi-character ops and user-defined operators */
598 %nonassoc IS NULL_P TRUE_P FALSE_P UNKNOWN /* sets precedence for IS NULL, etc */
602 /* Unary Operators */
603 %left AT ZONE /* sets precedence for AT TIME ZONE */
610 * These might seem to be low-precedence, but actually they are not part
611 * of the arithmetic hierarchy at all in their use as JOIN operators.
612 * We make them high-precedence to support their use as function names.
613 * They wouldn't be given a precedence at all, were it not that we need
614 * left-associativity among the JOIN rules themselves.
616 %left JOIN CROSS LEFT FULL RIGHT INNER_P NATURAL
617 /* kluge to keep xml_whitespace_option from causing shift/reduce conflicts */
618 %right PRESERVE STRIP_P
623 * The target production for the whole parse.
627 pg_yyget_extra(yyscanner)->parsetree = $1;
631 /* the thrashing around here is to discard "empty" statements... */
632 stmtmulti: stmtmulti ';' stmt
635 $$ = lappend($1, $3);
650 | AlterDatabaseSetStmt
651 | AlterDefaultPrivilegesStmt
654 | AlterForeignServerStmt
657 | AlterObjectSchemaStmt
661 | AlterCompositeTypeStmt
664 | AlterTSConfigurationStmt
665 | AlterTSDictionaryStmt
666 | AlterUserMappingStmt
679 | CreateConversionStmt
682 | CreateForeignServerStmt
692 | CreateTableSpaceStmt
696 | CreateUserMappingStmt
707 | DropForeignServerStmt
719 | DropUserMappingStmt
756 /*****************************************************************************
758 * Create a new Postgres DBMS role
760 *****************************************************************************/
763 CREATE ROLE RoleId opt_with OptRoleList
765 CreateRoleStmt *n = makeNode(CreateRoleStmt);
766 n->stmt_type = ROLESTMT_ROLE;
779 * Options for CREATE ROLE and ALTER ROLE (also used by CREATE/ALTER USER
780 * for backwards compatibility). Note: the only option required by SQL99
781 * is "WITH ADMIN name".
784 OptRoleList CreateOptRoleElem { $$ = lappend($1, $2); }
785 | /* EMPTY */ { $$ = NIL; }
789 AlterOptRoleList AlterOptRoleElem { $$ = lappend($1, $2); }
790 | /* EMPTY */ { $$ = NIL; }
796 $$ = makeDefElem("password",
797 (Node *)makeString($2));
801 $$ = makeDefElem("password", NULL);
803 | ENCRYPTED PASSWORD Sconst
805 $$ = makeDefElem("encryptedPassword",
806 (Node *)makeString($3));
808 | UNENCRYPTED PASSWORD Sconst
810 $$ = makeDefElem("unencryptedPassword",
811 (Node *)makeString($3));
815 $$ = makeDefElem("superuser", (Node *)makeInteger(TRUE));
819 $$ = makeDefElem("superuser", (Node *)makeInteger(FALSE));
823 $$ = makeDefElem("inherit", (Node *)makeInteger(TRUE));
827 $$ = makeDefElem("inherit", (Node *)makeInteger(FALSE));
831 $$ = makeDefElem("createdb", (Node *)makeInteger(TRUE));
835 $$ = makeDefElem("createdb", (Node *)makeInteger(FALSE));
839 $$ = makeDefElem("createrole", (Node *)makeInteger(TRUE));
843 $$ = makeDefElem("createrole", (Node *)makeInteger(FALSE));
847 /* For backwards compatibility, synonym for SUPERUSER */
848 $$ = makeDefElem("superuser", (Node *)makeInteger(TRUE));
852 $$ = makeDefElem("superuser", (Node *)makeInteger(FALSE));
856 $$ = makeDefElem("canlogin", (Node *)makeInteger(TRUE));
860 $$ = makeDefElem("canlogin", (Node *)makeInteger(FALSE));
862 | CONNECTION LIMIT SignedIconst
864 $$ = makeDefElem("connectionlimit", (Node *)makeInteger($3));
868 $$ = makeDefElem("validUntil", (Node *)makeString($3));
870 /* Supported but not documented for roles, for use by ALTER GROUP. */
873 $$ = makeDefElem("rolemembers", (Node *)$2);
878 AlterOptRoleElem { $$ = $1; }
879 /* The following are not supported by ALTER ROLE/USER/GROUP */
882 $$ = makeDefElem("sysid", (Node *)makeInteger($2));
886 $$ = makeDefElem("adminmembers", (Node *)$2);
890 $$ = makeDefElem("rolemembers", (Node *)$2);
892 | IN_P ROLE name_list
894 $$ = makeDefElem("addroleto", (Node *)$3);
896 | IN_P GROUP_P name_list
898 $$ = makeDefElem("addroleto", (Node *)$3);
903 /*****************************************************************************
905 * Create a new Postgres DBMS user (role with implied login ability)
907 *****************************************************************************/
910 CREATE USER RoleId opt_with OptRoleList
912 CreateRoleStmt *n = makeNode(CreateRoleStmt);
913 n->stmt_type = ROLESTMT_USER;
921 /*****************************************************************************
923 * Alter a postgresql DBMS role
925 *****************************************************************************/
928 ALTER ROLE RoleId opt_with AlterOptRoleList
930 AlterRoleStmt *n = makeNode(AlterRoleStmt);
932 n->action = +1; /* add, if there are members */
939 /* EMPTY */ { $$ = NULL; }
940 | IN_P DATABASE database_name { $$ = $3; }
944 ALTER ROLE RoleId opt_in_database SetResetClause
946 AlterRoleSetStmt *n = makeNode(AlterRoleSetStmt);
955 /*****************************************************************************
957 * Alter a postgresql DBMS user
959 *****************************************************************************/
962 ALTER USER RoleId opt_with AlterOptRoleList
964 AlterRoleStmt *n = makeNode(AlterRoleStmt);
966 n->action = +1; /* add, if there are members */
974 ALTER USER RoleId SetResetClause
976 AlterRoleSetStmt *n = makeNode(AlterRoleSetStmt);
985 /*****************************************************************************
987 * Drop a postgresql DBMS role
989 * XXX Ideally this would have CASCADE/RESTRICT options, but since a role
990 * might own objects in multiple databases, there is presently no way to
991 * implement either cascading or restricting. Caveat DBA.
992 *****************************************************************************/
997 DropRoleStmt *n = makeNode(DropRoleStmt);
998 n->missing_ok = FALSE;
1002 | DROP ROLE IF_P EXISTS name_list
1004 DropRoleStmt *n = makeNode(DropRoleStmt);
1005 n->missing_ok = TRUE;
1011 /*****************************************************************************
1013 * Drop a postgresql DBMS user
1015 * XXX Ideally this would have CASCADE/RESTRICT options, but since a user
1016 * might own objects in multiple databases, there is presently no way to
1017 * implement either cascading or restricting. Caveat DBA.
1018 *****************************************************************************/
1023 DropRoleStmt *n = makeNode(DropRoleStmt);
1024 n->missing_ok = FALSE;
1028 | DROP USER IF_P EXISTS name_list
1030 DropRoleStmt *n = makeNode(DropRoleStmt);
1032 n->missing_ok = TRUE;
1038 /*****************************************************************************
1040 * Create a postgresql group (role without login ability)
1042 *****************************************************************************/
1045 CREATE GROUP_P RoleId opt_with OptRoleList
1047 CreateRoleStmt *n = makeNode(CreateRoleStmt);
1048 n->stmt_type = ROLESTMT_GROUP;
1056 /*****************************************************************************
1058 * Alter a postgresql group
1060 *****************************************************************************/
1063 ALTER GROUP_P RoleId add_drop USER name_list
1065 AlterRoleStmt *n = makeNode(AlterRoleStmt);
1068 n->options = list_make1(makeDefElem("rolemembers",
1074 add_drop: ADD_P { $$ = +1; }
1079 /*****************************************************************************
1081 * Drop a postgresql group
1083 * XXX see above notes about cascading DROP USER; groups have same problem.
1084 *****************************************************************************/
1087 DROP GROUP_P name_list
1089 DropRoleStmt *n = makeNode(DropRoleStmt);
1090 n->missing_ok = FALSE;
1094 | DROP GROUP_P IF_P EXISTS name_list
1096 DropRoleStmt *n = makeNode(DropRoleStmt);
1097 n->missing_ok = TRUE;
1104 /*****************************************************************************
1106 * Manipulate a schema
1108 *****************************************************************************/
1111 CREATE SCHEMA OptSchemaName AUTHORIZATION RoleId OptSchemaEltList
1113 CreateSchemaStmt *n = makeNode(CreateSchemaStmt);
1114 /* One can omit the schema name or the authorization id. */
1123 | CREATE SCHEMA ColId OptSchemaEltList
1125 CreateSchemaStmt *n = makeNode(CreateSchemaStmt);
1126 /* ...but not both */
1136 | /* EMPTY */ { $$ = NULL; }
1140 OptSchemaEltList schema_stmt { $$ = lappend($1, $2); }
1141 | /* EMPTY */ { $$ = NIL; }
1145 * schema_stmt are the ones that can show up inside a CREATE SCHEMA
1146 * statement (in addition to by themselves).
1158 /*****************************************************************************
1160 * Set PG internal variable
1161 * SET name TO 'var_value'
1162 * Include SQL92 syntax (thomas 1997-10-22):
1163 * SET TIME ZONE 'var_value'
1165 *****************************************************************************/
1170 VariableSetStmt *n = $2;
1171 n->is_local = false;
1174 | SET LOCAL set_rest
1176 VariableSetStmt *n = $3;
1180 | SET SESSION set_rest
1182 VariableSetStmt *n = $3;
1183 n->is_local = false;
1188 set_rest: /* Generic SET syntaxes: */
1189 var_name TO var_list
1191 VariableSetStmt *n = makeNode(VariableSetStmt);
1192 n->kind = VAR_SET_VALUE;
1197 | var_name '=' var_list
1199 VariableSetStmt *n = makeNode(VariableSetStmt);
1200 n->kind = VAR_SET_VALUE;
1205 | var_name TO DEFAULT
1207 VariableSetStmt *n = makeNode(VariableSetStmt);
1208 n->kind = VAR_SET_DEFAULT;
1212 | var_name '=' DEFAULT
1214 VariableSetStmt *n = makeNode(VariableSetStmt);
1215 n->kind = VAR_SET_DEFAULT;
1219 | var_name FROM CURRENT_P
1221 VariableSetStmt *n = makeNode(VariableSetStmt);
1222 n->kind = VAR_SET_CURRENT;
1226 /* Special syntaxes mandated by SQL standard: */
1227 | TIME ZONE zone_value
1229 VariableSetStmt *n = makeNode(VariableSetStmt);
1230 n->kind = VAR_SET_VALUE;
1231 n->name = "timezone";
1233 n->args = list_make1($3);
1235 n->kind = VAR_SET_DEFAULT;
1238 | TRANSACTION transaction_mode_list
1240 VariableSetStmt *n = makeNode(VariableSetStmt);
1241 n->kind = VAR_SET_MULTI;
1242 n->name = "TRANSACTION";
1246 | SESSION CHARACTERISTICS AS TRANSACTION transaction_mode_list
1248 VariableSetStmt *n = makeNode(VariableSetStmt);
1249 n->kind = VAR_SET_MULTI;
1250 n->name = "SESSION CHARACTERISTICS";
1257 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
1258 errmsg("current database cannot be changed"),
1259 parser_errposition(@2)));
1260 $$ = NULL; /*not reached*/
1264 VariableSetStmt *n = makeNode(VariableSetStmt);
1265 n->kind = VAR_SET_VALUE;
1266 n->name = "search_path";
1267 n->args = list_make1(makeStringConst($2, @2));
1270 | NAMES opt_encoding
1272 VariableSetStmt *n = makeNode(VariableSetStmt);
1273 n->kind = VAR_SET_VALUE;
1274 n->name = "client_encoding";
1276 n->args = list_make1(makeStringConst($2, @2));
1278 n->kind = VAR_SET_DEFAULT;
1281 | ROLE ColId_or_Sconst
1283 VariableSetStmt *n = makeNode(VariableSetStmt);
1284 n->kind = VAR_SET_VALUE;
1286 n->args = list_make1(makeStringConst($2, @2));
1289 | SESSION AUTHORIZATION ColId_or_Sconst
1291 VariableSetStmt *n = makeNode(VariableSetStmt);
1292 n->kind = VAR_SET_VALUE;
1293 n->name = "session_authorization";
1294 n->args = list_make1(makeStringConst($3, @3));
1297 | SESSION AUTHORIZATION DEFAULT
1299 VariableSetStmt *n = makeNode(VariableSetStmt);
1300 n->kind = VAR_SET_DEFAULT;
1301 n->name = "session_authorization";
1304 | XML_P OPTION document_or_content
1306 VariableSetStmt *n = makeNode(VariableSetStmt);
1307 n->kind = VAR_SET_VALUE;
1308 n->name = "xmloption";
1309 n->args = list_make1(makeStringConst($3 == XMLOPTION_DOCUMENT ? "DOCUMENT" : "CONTENT", @3));
1314 var_name: ColId { $$ = $1; }
1315 | var_name '.' ColId
1317 $$ = palloc(strlen($1) + strlen($3) + 2);
1318 sprintf($$, "%s.%s", $1, $3);
1322 var_list: var_value { $$ = list_make1($1); }
1323 | var_list ',' var_value { $$ = lappend($1, $3); }
1326 var_value: opt_boolean
1327 { $$ = makeStringConst($1, @1); }
1329 { $$ = makeStringConst($1, @1); }
1331 { $$ = makeAConst($1, @1); }
1334 iso_level: READ UNCOMMITTED { $$ = "read uncommitted"; }
1335 | READ COMMITTED { $$ = "read committed"; }
1336 | REPEATABLE READ { $$ = "repeatable read"; }
1337 | SERIALIZABLE { $$ = "serializable"; }
1341 TRUE_P { $$ = "true"; }
1342 | FALSE_P { $$ = "false"; }
1344 | OFF { $$ = "off"; }
1347 /* Timezone values can be:
1348 * - a string such as 'pst8pdt'
1349 * - an identifier such as "pst8pdt"
1350 * - an integer or floating point number
1351 * - a time interval per SQL99
1352 * ColId gives reduce/reduce errors against ConstInterval and LOCAL,
1353 * so use IDENT (meaning we reject anything that is a key word).
1358 $$ = makeStringConst($1, @1);
1362 $$ = makeStringConst($1, @1);
1364 | ConstInterval Sconst opt_interval
1369 A_Const *n = (A_Const *) linitial($3);
1370 if ((n->val.val.ival & ~(INTERVAL_MASK(HOUR) | INTERVAL_MASK(MINUTE))) != 0)
1372 (errcode(ERRCODE_SYNTAX_ERROR),
1373 errmsg("time zone interval must be HOUR or HOUR TO MINUTE"),
1374 parser_errposition(@3)));
1377 $$ = makeStringConstCast($2, @2, t);
1379 | ConstInterval '(' Iconst ')' Sconst opt_interval
1384 A_Const *n = (A_Const *) linitial($6);
1385 if ((n->val.val.ival & ~(INTERVAL_MASK(HOUR) | INTERVAL_MASK(MINUTE))) != 0)
1387 (errcode(ERRCODE_SYNTAX_ERROR),
1388 errmsg("time zone interval must be HOUR or HOUR TO MINUTE"),
1389 parser_errposition(@6)));
1390 if (list_length($6) != 1)
1392 (errcode(ERRCODE_SYNTAX_ERROR),
1393 errmsg("interval precision specified twice"),
1394 parser_errposition(@1)));
1395 t->typmods = lappend($6, makeIntConst($3, @3));
1398 t->typmods = list_make2(makeIntConst(INTERVAL_FULL_RANGE, -1),
1399 makeIntConst($3, @3));
1400 $$ = makeStringConstCast($5, @5, t);
1402 | NumericOnly { $$ = makeAConst($1, @1); }
1403 | DEFAULT { $$ = NULL; }
1404 | LOCAL { $$ = NULL; }
1409 | DEFAULT { $$ = NULL; }
1410 | /*EMPTY*/ { $$ = NULL; }
1415 | Sconst { $$ = $1; }
1421 VariableSetStmt *n = makeNode(VariableSetStmt);
1422 n->kind = VAR_RESET;
1428 VariableSetStmt *n = makeNode(VariableSetStmt);
1429 n->kind = VAR_RESET;
1430 n->name = "timezone";
1433 | RESET TRANSACTION ISOLATION LEVEL
1435 VariableSetStmt *n = makeNode(VariableSetStmt);
1436 n->kind = VAR_RESET;
1437 n->name = "transaction_isolation";
1440 | RESET SESSION AUTHORIZATION
1442 VariableSetStmt *n = makeNode(VariableSetStmt);
1443 n->kind = VAR_RESET;
1444 n->name = "session_authorization";
1449 VariableSetStmt *n = makeNode(VariableSetStmt);
1450 n->kind = VAR_RESET_ALL;
1455 /* SetResetClause allows SET or RESET without LOCAL */
1457 SET set_rest { $$ = $2; }
1458 | VariableResetStmt { $$ = (VariableSetStmt *) $1; }
1465 VariableShowStmt *n = makeNode(VariableShowStmt);
1471 VariableShowStmt *n = makeNode(VariableShowStmt);
1472 n->name = "timezone";
1475 | SHOW TRANSACTION ISOLATION LEVEL
1477 VariableShowStmt *n = makeNode(VariableShowStmt);
1478 n->name = "transaction_isolation";
1481 | SHOW SESSION AUTHORIZATION
1483 VariableShowStmt *n = makeNode(VariableShowStmt);
1484 n->name = "session_authorization";
1489 VariableShowStmt *n = makeNode(VariableShowStmt);
1497 SET CONSTRAINTS constraints_set_list constraints_set_mode
1499 ConstraintsSetStmt *n = makeNode(ConstraintsSetStmt);
1500 n->constraints = $3;
1506 constraints_set_list:
1508 | qualified_name_list { $$ = $1; }
1511 constraints_set_mode:
1512 DEFERRED { $$ = TRUE; }
1513 | IMMEDIATE { $$ = FALSE; }
1518 * Checkpoint statement
1523 CheckPointStmt *n = makeNode(CheckPointStmt);
1529 /*****************************************************************************
1531 * DISCARD { ALL | TEMP | PLANS }
1533 *****************************************************************************/
1538 DiscardStmt *n = makeNode(DiscardStmt);
1539 n->target = DISCARD_ALL;
1544 DiscardStmt *n = makeNode(DiscardStmt);
1545 n->target = DISCARD_TEMP;
1550 DiscardStmt *n = makeNode(DiscardStmt);
1551 n->target = DISCARD_TEMP;
1556 DiscardStmt *n = makeNode(DiscardStmt);
1557 n->target = DISCARD_PLANS;
1563 /*****************************************************************************
1565 * ALTER [ TABLE | INDEX | SEQUENCE | VIEW ] variations
1567 * Note: we accept all subcommands for each of the four variants, and sort
1568 * out what's really legal at execution time.
1569 *****************************************************************************/
1572 ALTER TABLE relation_expr alter_table_cmds
1574 AlterTableStmt *n = makeNode(AlterTableStmt);
1577 n->relkind = OBJECT_TABLE;
1580 | ALTER INDEX qualified_name alter_table_cmds
1582 AlterTableStmt *n = makeNode(AlterTableStmt);
1585 n->relkind = OBJECT_INDEX;
1588 | ALTER SEQUENCE qualified_name alter_table_cmds
1590 AlterTableStmt *n = makeNode(AlterTableStmt);
1593 n->relkind = OBJECT_SEQUENCE;
1596 | ALTER VIEW qualified_name alter_table_cmds
1598 AlterTableStmt *n = makeNode(AlterTableStmt);
1601 n->relkind = OBJECT_VIEW;
1607 alter_table_cmd { $$ = list_make1($1); }
1608 | alter_table_cmds ',' alter_table_cmd { $$ = lappend($1, $3); }
1612 /* ALTER TABLE <name> ADD <coldef> */
1615 AlterTableCmd *n = makeNode(AlterTableCmd);
1616 n->subtype = AT_AddColumn;
1620 /* ALTER TABLE <name> ADD COLUMN <coldef> */
1621 | ADD_P COLUMN columnDef
1623 AlterTableCmd *n = makeNode(AlterTableCmd);
1624 n->subtype = AT_AddColumn;
1628 /* ALTER TABLE <name> ALTER [COLUMN] <colname> {SET DEFAULT <expr>|DROP DEFAULT} */
1629 | ALTER opt_column ColId alter_column_default
1631 AlterTableCmd *n = makeNode(AlterTableCmd);
1632 n->subtype = AT_ColumnDefault;
1637 /* ALTER TABLE <name> ALTER [COLUMN] <colname> DROP NOT NULL */
1638 | ALTER opt_column ColId DROP NOT NULL_P
1640 AlterTableCmd *n = makeNode(AlterTableCmd);
1641 n->subtype = AT_DropNotNull;
1645 /* ALTER TABLE <name> ALTER [COLUMN] <colname> SET NOT NULL */
1646 | ALTER opt_column ColId SET NOT NULL_P
1648 AlterTableCmd *n = makeNode(AlterTableCmd);
1649 n->subtype = AT_SetNotNull;
1653 /* ALTER TABLE <name> ALTER [COLUMN] <colname> SET STATISTICS <SignedIconst> */
1654 | ALTER opt_column ColId SET STATISTICS SignedIconst
1656 AlterTableCmd *n = makeNode(AlterTableCmd);
1657 n->subtype = AT_SetStatistics;
1659 n->def = (Node *) makeInteger($6);
1662 /* ALTER TABLE <name> ALTER [COLUMN] <colname> SET ( column_parameter = value [, ... ] ) */
1663 | ALTER opt_column ColId SET reloptions
1665 AlterTableCmd *n = makeNode(AlterTableCmd);
1666 n->subtype = AT_SetOptions;
1668 n->def = (Node *) $5;
1671 /* ALTER TABLE <name> ALTER [COLUMN] <colname> SET ( column_parameter = value [, ... ] ) */
1672 | ALTER opt_column ColId RESET reloptions
1674 AlterTableCmd *n = makeNode(AlterTableCmd);
1675 n->subtype = AT_ResetOptions;
1677 n->def = (Node *) $5;
1680 /* ALTER TABLE <name> ALTER [COLUMN] <colname> SET STORAGE <storagemode> */
1681 | ALTER opt_column ColId SET STORAGE ColId
1683 AlterTableCmd *n = makeNode(AlterTableCmd);
1684 n->subtype = AT_SetStorage;
1686 n->def = (Node *) makeString($6);
1689 /* ALTER TABLE <name> DROP [COLUMN] IF EXISTS <colname> [RESTRICT|CASCADE] */
1690 | DROP opt_column IF_P EXISTS ColId opt_drop_behavior
1692 AlterTableCmd *n = makeNode(AlterTableCmd);
1693 n->subtype = AT_DropColumn;
1696 n->missing_ok = TRUE;
1699 /* ALTER TABLE <name> DROP [COLUMN] <colname> [RESTRICT|CASCADE] */
1700 | DROP opt_column ColId opt_drop_behavior
1702 AlterTableCmd *n = makeNode(AlterTableCmd);
1703 n->subtype = AT_DropColumn;
1706 n->missing_ok = FALSE;
1710 * ALTER TABLE <name> ALTER [COLUMN] <colname> [SET DATA] TYPE <typename>
1711 * [ USING <expression> ]
1713 | ALTER opt_column ColId opt_set_data TYPE_P Typename alter_using
1715 AlterTableCmd *n = makeNode(AlterTableCmd);
1716 n->subtype = AT_AlterColumnType;
1718 n->def = (Node *) $6;
1722 /* ALTER TABLE <name> ADD CONSTRAINT ... */
1723 | ADD_P TableConstraint
1725 AlterTableCmd *n = makeNode(AlterTableCmd);
1726 n->subtype = AT_AddConstraint;
1730 /* ALTER TABLE <name> DROP CONSTRAINT IF EXISTS <name> [RESTRICT|CASCADE] */
1731 | DROP CONSTRAINT IF_P EXISTS name opt_drop_behavior
1733 AlterTableCmd *n = makeNode(AlterTableCmd);
1734 n->subtype = AT_DropConstraint;
1737 n->missing_ok = TRUE;
1740 /* ALTER TABLE <name> DROP CONSTRAINT <name> [RESTRICT|CASCADE] */
1741 | DROP CONSTRAINT name opt_drop_behavior
1743 AlterTableCmd *n = makeNode(AlterTableCmd);
1744 n->subtype = AT_DropConstraint;
1747 n->missing_ok = FALSE;
1750 /* ALTER TABLE <name> SET WITH OIDS */
1753 AlterTableCmd *n = makeNode(AlterTableCmd);
1754 n->subtype = AT_AddOids;
1757 /* ALTER TABLE <name> SET WITHOUT OIDS */
1760 AlterTableCmd *n = makeNode(AlterTableCmd);
1761 n->subtype = AT_DropOids;
1764 /* ALTER TABLE <name> CLUSTER ON <indexname> */
1767 AlterTableCmd *n = makeNode(AlterTableCmd);
1768 n->subtype = AT_ClusterOn;
1772 /* ALTER TABLE <name> SET WITHOUT CLUSTER */
1773 | SET WITHOUT CLUSTER
1775 AlterTableCmd *n = makeNode(AlterTableCmd);
1776 n->subtype = AT_DropCluster;
1780 /* ALTER TABLE <name> ENABLE TRIGGER <trig> */
1781 | ENABLE_P TRIGGER name
1783 AlterTableCmd *n = makeNode(AlterTableCmd);
1784 n->subtype = AT_EnableTrig;
1788 /* ALTER TABLE <name> ENABLE ALWAYS TRIGGER <trig> */
1789 | ENABLE_P ALWAYS TRIGGER name
1791 AlterTableCmd *n = makeNode(AlterTableCmd);
1792 n->subtype = AT_EnableAlwaysTrig;
1796 /* ALTER TABLE <name> ENABLE REPLICA TRIGGER <trig> */
1797 | ENABLE_P REPLICA TRIGGER name
1799 AlterTableCmd *n = makeNode(AlterTableCmd);
1800 n->subtype = AT_EnableReplicaTrig;
1804 /* ALTER TABLE <name> ENABLE TRIGGER ALL */
1805 | ENABLE_P TRIGGER ALL
1807 AlterTableCmd *n = makeNode(AlterTableCmd);
1808 n->subtype = AT_EnableTrigAll;
1811 /* ALTER TABLE <name> ENABLE TRIGGER USER */
1812 | ENABLE_P TRIGGER USER
1814 AlterTableCmd *n = makeNode(AlterTableCmd);
1815 n->subtype = AT_EnableTrigUser;
1818 /* ALTER TABLE <name> DISABLE TRIGGER <trig> */
1819 | DISABLE_P TRIGGER name
1821 AlterTableCmd *n = makeNode(AlterTableCmd);
1822 n->subtype = AT_DisableTrig;
1826 /* ALTER TABLE <name> DISABLE TRIGGER ALL */
1827 | DISABLE_P TRIGGER ALL
1829 AlterTableCmd *n = makeNode(AlterTableCmd);
1830 n->subtype = AT_DisableTrigAll;
1833 /* ALTER TABLE <name> DISABLE TRIGGER USER */
1834 | DISABLE_P TRIGGER USER
1836 AlterTableCmd *n = makeNode(AlterTableCmd);
1837 n->subtype = AT_DisableTrigUser;
1840 /* ALTER TABLE <name> ENABLE RULE <rule> */
1841 | ENABLE_P RULE name
1843 AlterTableCmd *n = makeNode(AlterTableCmd);
1844 n->subtype = AT_EnableRule;
1848 /* ALTER TABLE <name> ENABLE ALWAYS RULE <rule> */
1849 | ENABLE_P ALWAYS RULE name
1851 AlterTableCmd *n = makeNode(AlterTableCmd);
1852 n->subtype = AT_EnableAlwaysRule;
1856 /* ALTER TABLE <name> ENABLE REPLICA RULE <rule> */
1857 | ENABLE_P REPLICA RULE name
1859 AlterTableCmd *n = makeNode(AlterTableCmd);
1860 n->subtype = AT_EnableReplicaRule;
1864 /* ALTER TABLE <name> DISABLE RULE <rule> */
1865 | DISABLE_P RULE name
1867 AlterTableCmd *n = makeNode(AlterTableCmd);
1868 n->subtype = AT_DisableRule;
1872 /* ALTER TABLE <name> INHERIT <parent> */
1873 | INHERIT qualified_name
1875 AlterTableCmd *n = makeNode(AlterTableCmd);
1876 n->subtype = AT_AddInherit;
1877 n->def = (Node *) $2;
1880 /* ALTER TABLE <name> NO INHERIT <parent> */
1881 | NO INHERIT qualified_name
1883 AlterTableCmd *n = makeNode(AlterTableCmd);
1884 n->subtype = AT_DropInherit;
1885 n->def = (Node *) $3;
1888 /* ALTER TABLE <name> OWNER TO RoleId */
1891 AlterTableCmd *n = makeNode(AlterTableCmd);
1892 n->subtype = AT_ChangeOwner;
1896 /* ALTER TABLE <name> SET TABLESPACE <tablespacename> */
1897 | SET TABLESPACE name
1899 AlterTableCmd *n = makeNode(AlterTableCmd);
1900 n->subtype = AT_SetTableSpace;
1904 /* ALTER TABLE <name> SET (...) */
1907 AlterTableCmd *n = makeNode(AlterTableCmd);
1908 n->subtype = AT_SetRelOptions;
1909 n->def = (Node *)$2;
1912 /* ALTER TABLE <name> RESET (...) */
1915 AlterTableCmd *n = makeNode(AlterTableCmd);
1916 n->subtype = AT_ResetRelOptions;
1917 n->def = (Node *)$2;
1922 alter_column_default:
1923 SET DEFAULT a_expr { $$ = $3; }
1924 | DROP DEFAULT { $$ = NULL; }
1928 CASCADE { $$ = DROP_CASCADE; }
1929 | RESTRICT { $$ = DROP_RESTRICT; }
1930 | /* EMPTY */ { $$ = DROP_RESTRICT; /* default */ }
1934 USING a_expr { $$ = $2; }
1935 | /* EMPTY */ { $$ = NULL; }
1939 '(' reloption_list ')' { $$ = $2; }
1942 opt_reloptions: WITH reloptions { $$ = $2; }
1943 | /* EMPTY */ { $$ = NIL; }
1947 reloption_elem { $$ = list_make1($1); }
1948 | reloption_list ',' reloption_elem { $$ = lappend($1, $3); }
1951 /* This should match def_elem and also allow qualified names */
1953 ColLabel '=' def_arg
1955 $$ = makeDefElem($1, (Node *) $3);
1959 $$ = makeDefElem($1, NULL);
1961 | ColLabel '.' ColLabel '=' def_arg
1963 $$ = makeDefElemExtended($1, $3, (Node *) $5,
1966 | ColLabel '.' ColLabel
1968 $$ = makeDefElemExtended($1, $3, NULL, DEFELEM_UNSPEC);
1973 /*****************************************************************************
1977 * really variants of the ALTER TABLE subcommands with different spellings
1978 *****************************************************************************/
1980 AlterCompositeTypeStmt:
1981 ALTER TYPE_P any_name alter_type_cmds
1983 AlterTableStmt *n = makeNode(AlterTableStmt);
1985 /* can't use qualified_name, sigh */
1986 n->relation = makeRangeVarFromAnyName($3, @3, yyscanner);
1988 n->relkind = OBJECT_TYPE;
1994 alter_type_cmd { $$ = list_make1($1); }
1995 | alter_type_cmds ',' alter_type_cmd { $$ = lappend($1, $3); }
1999 /* ALTER TYPE <name> ADD ATTRIBUTE <coldef> */
2000 ADD_P ATTRIBUTE TableFuncElement
2002 AlterTableCmd *n = makeNode(AlterTableCmd);
2003 n->subtype = AT_AddColumn;
2007 /* ALTER TYPE <name> DROP ATTRIBUTE IF EXISTS <attname> */
2008 | DROP ATTRIBUTE IF_P EXISTS ColId
2010 AlterTableCmd *n = makeNode(AlterTableCmd);
2011 n->subtype = AT_DropColumn;
2013 n->behavior = DROP_RESTRICT; /* currently no effect */
2014 n->missing_ok = TRUE;
2017 /* ALTER TYPE <name> DROP ATTRIBUTE <attname> */
2018 | DROP ATTRIBUTE ColId opt_drop_behavior
2020 AlterTableCmd *n = makeNode(AlterTableCmd);
2021 n->subtype = AT_DropColumn;
2023 n->behavior = DROP_RESTRICT; /* currently no effect */
2024 n->missing_ok = FALSE;
2027 /* ALTER TYPE <name> ALTER ATTRIBUTE <attname> [SET DATA] TYPE <typename> */
2028 | ALTER ATTRIBUTE ColId opt_set_data TYPE_P Typename
2030 AlterTableCmd *n = makeNode(AlterTableCmd);
2031 n->subtype = AT_AlterColumnType;
2033 n->def = (Node *) $6;
2039 /*****************************************************************************
2042 * close <portalname>
2044 *****************************************************************************/
2049 ClosePortalStmt *n = makeNode(ClosePortalStmt);
2055 ClosePortalStmt *n = makeNode(ClosePortalStmt);
2056 n->portalname = NULL;
2062 /*****************************************************************************
2065 * COPY relname [(columnList)] FROM/TO file [WITH] [(options)]
2066 * COPY ( SELECT ... ) TO file [WITH] [(options)]
2068 * In the preferred syntax the options are comma-separated
2069 * and use generic identifiers instead of keywords. The pre-9.0
2070 * syntax had a hard-wired, space-separated set of options.
2072 * Really old syntax, from versions 7.2 and prior:
2073 * COPY [ BINARY ] table [ WITH OIDS ] FROM/TO file
2074 * [ [ USING ] DELIMITERS 'delimiter' ] ]
2075 * [ WITH NULL AS 'null string' ]
2076 * This option placement is not supported with COPY (SELECT...).
2078 *****************************************************************************/
2080 CopyStmt: COPY opt_binary qualified_name opt_column_list opt_oids
2081 copy_from copy_file_name copy_delimiter opt_with copy_options
2083 CopyStmt *n = makeNode(CopyStmt);
2091 /* Concatenate user-supplied flags */
2093 n->options = lappend(n->options, $2);
2095 n->options = lappend(n->options, $5);
2097 n->options = lappend(n->options, $8);
2099 n->options = list_concat(n->options, $10);
2102 | COPY select_with_parens TO copy_file_name opt_with copy_options
2104 CopyStmt *n = makeNode(CopyStmt);
2117 | TO { $$ = FALSE; }
2121 * copy_file_name NULL indicates stdio is used. Whether stdin or stdout is
2122 * used depends on the direction. (It really doesn't make sense to copy from
2123 * stdout. We silently correct the "typo".) - AY 9/94
2127 | STDIN { $$ = NULL; }
2128 | STDOUT { $$ = NULL; }
2131 copy_options: copy_opt_list { $$ = $1; }
2132 | '(' copy_generic_opt_list ')' { $$ = $2; }
2135 /* old COPY option syntax */
2137 copy_opt_list copy_opt_item { $$ = lappend($1, $2); }
2138 | /* EMPTY */ { $$ = NIL; }
2144 $$ = makeDefElem("format", (Node *)makeString("binary"));
2148 $$ = makeDefElem("oids", (Node *)makeInteger(TRUE));
2150 | DELIMITER opt_as Sconst
2152 $$ = makeDefElem("delimiter", (Node *)makeString($3));
2154 | NULL_P opt_as Sconst
2156 $$ = makeDefElem("null", (Node *)makeString($3));
2160 $$ = makeDefElem("format", (Node *)makeString("csv"));
2164 $$ = makeDefElem("header", (Node *)makeInteger(TRUE));
2166 | QUOTE opt_as Sconst
2168 $$ = makeDefElem("quote", (Node *)makeString($3));
2170 | ESCAPE opt_as Sconst
2172 $$ = makeDefElem("escape", (Node *)makeString($3));
2174 | FORCE QUOTE columnList
2176 $$ = makeDefElem("force_quote", (Node *)$3);
2180 $$ = makeDefElem("force_quote", (Node *)makeNode(A_Star));
2182 | FORCE NOT NULL_P columnList
2184 $$ = makeDefElem("force_not_null", (Node *)$4);
2188 /* The following exist for backward compatibility with very old versions */
2193 $$ = makeDefElem("format", (Node *)makeString("binary"));
2195 | /*EMPTY*/ { $$ = NULL; }
2201 $$ = makeDefElem("oids", (Node *)makeInteger(TRUE));
2203 | /*EMPTY*/ { $$ = NULL; }
2207 opt_using DELIMITERS Sconst
2209 $$ = makeDefElem("delimiter", (Node *)makeString($3));
2211 | /*EMPTY*/ { $$ = NULL; }
2219 /* new COPY option syntax */
2220 copy_generic_opt_list:
2221 copy_generic_opt_elem
2223 $$ = list_make1($1);
2225 | copy_generic_opt_list ',' copy_generic_opt_elem
2227 $$ = lappend($1, $3);
2231 copy_generic_opt_elem:
2232 ColLabel copy_generic_opt_arg
2234 $$ = makeDefElem($1, $2);
2238 copy_generic_opt_arg:
2239 opt_boolean { $$ = (Node *) makeString($1); }
2240 | ColId_or_Sconst { $$ = (Node *) makeString($1); }
2241 | NumericOnly { $$ = (Node *) $1; }
2242 | '*' { $$ = (Node *) makeNode(A_Star); }
2243 | '(' copy_generic_opt_arg_list ')' { $$ = (Node *) $2; }
2244 | /* EMPTY */ { $$ = NULL; }
2247 copy_generic_opt_arg_list:
2248 copy_generic_opt_arg_list_item
2250 $$ = list_make1($1);
2252 | copy_generic_opt_arg_list ',' copy_generic_opt_arg_list_item
2254 $$ = lappend($1, $3);
2258 /* beware of emitting non-string list elements here; see commands/define.c */
2259 copy_generic_opt_arg_list_item:
2260 opt_boolean { $$ = (Node *) makeString($1); }
2261 | ColId_or_Sconst { $$ = (Node *) makeString($1); }
2265 /*****************************************************************************
2268 * CREATE TABLE relname
2270 *****************************************************************************/
2272 CreateStmt: CREATE OptTemp TABLE qualified_name '(' OptTableElementList ')'
2273 OptInherit OptWith OnCommitOption OptTableSpace
2275 CreateStmt *n = makeNode(CreateStmt);
2279 n->inhRelations = $8;
2280 n->constraints = NIL;
2283 n->tablespacename = $11;
2284 n->if_not_exists = false;
2287 | CREATE OptTemp TABLE IF_P NOT EXISTS qualified_name '('
2288 OptTableElementList ')' OptInherit OptWith OnCommitOption
2291 CreateStmt *n = makeNode(CreateStmt);
2295 n->inhRelations = $11;
2296 n->constraints = NIL;
2299 n->tablespacename = $14;
2300 n->if_not_exists = true;
2303 | CREATE OptTemp TABLE qualified_name OF any_name
2304 OptTypedTableElementList OptWith OnCommitOption OptTableSpace
2306 CreateStmt *n = makeNode(CreateStmt);
2310 n->ofTypename = makeTypeNameFromNameList($6);
2311 n->ofTypename->location = @6;
2312 n->constraints = NIL;
2315 n->tablespacename = $10;
2316 n->if_not_exists = false;
2319 | CREATE OptTemp TABLE IF_P NOT EXISTS qualified_name OF any_name
2320 OptTypedTableElementList OptWith OnCommitOption OptTableSpace
2322 CreateStmt *n = makeNode(CreateStmt);
2326 n->ofTypename = makeTypeNameFromNameList($9);
2327 n->ofTypename->location = @9;
2328 n->constraints = NIL;
2331 n->tablespacename = $13;
2332 n->if_not_exists = true;
2338 * Redundancy here is needed to avoid shift/reduce conflicts,
2339 * since TEMP is not a reserved word. See also OptTempTableName.
2341 * NOTE: we accept both GLOBAL and LOCAL options; since we have no modules
2342 * the LOCAL keyword is really meaningless.
2344 OptTemp: TEMPORARY { $$ = TRUE; }
2345 | TEMP { $$ = TRUE; }
2346 | LOCAL TEMPORARY { $$ = TRUE; }
2347 | LOCAL TEMP { $$ = TRUE; }
2348 | GLOBAL TEMPORARY { $$ = TRUE; }
2349 | GLOBAL TEMP { $$ = TRUE; }
2350 | /*EMPTY*/ { $$ = FALSE; }
2353 OptTableElementList:
2354 TableElementList { $$ = $1; }
2355 | /*EMPTY*/ { $$ = NIL; }
2358 OptTypedTableElementList:
2359 '(' TypedTableElementList ')' { $$ = $2; }
2360 | /*EMPTY*/ { $$ = NIL; }
2366 $$ = list_make1($1);
2368 | TableElementList ',' TableElement
2370 $$ = lappend($1, $3);
2374 TypedTableElementList:
2377 $$ = list_make1($1);
2379 | TypedTableElementList ',' TypedTableElement
2381 $$ = lappend($1, $3);
2386 columnDef { $$ = $1; }
2387 | TableLikeClause { $$ = $1; }
2388 | TableConstraint { $$ = $1; }
2392 columnOptions { $$ = $1; }
2393 | TableConstraint { $$ = $1; }
2396 columnDef: ColId Typename ColQualList
2398 ColumnDef *n = makeNode(ColumnDef);
2401 n->constraints = $3;
2407 columnOptions: ColId WITH OPTIONS ColQualList
2409 ColumnDef *n = makeNode(ColumnDef);
2411 n->constraints = $4;
2418 ColQualList ColConstraint { $$ = lappend($1, $2); }
2419 | /*EMPTY*/ { $$ = NIL; }
2423 CONSTRAINT name ColConstraintElem
2425 Constraint *n = (Constraint *) $3;
2426 Assert(IsA(n, Constraint));
2431 | ColConstraintElem { $$ = $1; }
2432 | ConstraintAttr { $$ = $1; }
2435 /* DEFAULT NULL is already the default for Postgres.
2436 * But define it here and carry it forward into the system
2437 * to make it explicit.
2438 * - thomas 1998-09-13
2440 * WITH NULL and NULL are not SQL92-standard syntax elements,
2441 * so leave them out. Use DEFAULT NULL to explicitly indicate
2442 * that a column may have that value. WITH NULL leads to
2443 * shift/reduce conflicts with WITH TIME ZONE anyway.
2444 * - thomas 1999-01-08
2446 * DEFAULT expression must be b_expr not a_expr to prevent shift/reduce
2447 * conflict on NOT (since NOT might start a subsequent NOT NULL constraint,
2448 * or be part of a_expr NOT LIKE or similar constructs).
2453 Constraint *n = makeNode(Constraint);
2454 n->contype = CONSTR_NOTNULL;
2460 Constraint *n = makeNode(Constraint);
2461 n->contype = CONSTR_NULL;
2465 | UNIQUE opt_definition OptConsTableSpace
2467 Constraint *n = makeNode(Constraint);
2468 n->contype = CONSTR_UNIQUE;
2475 | PRIMARY KEY opt_definition OptConsTableSpace
2477 Constraint *n = makeNode(Constraint);
2478 n->contype = CONSTR_PRIMARY;
2485 | CHECK '(' a_expr ')'
2487 Constraint *n = makeNode(Constraint);
2488 n->contype = CONSTR_CHECK;
2491 n->cooked_expr = NULL;
2496 Constraint *n = makeNode(Constraint);
2497 n->contype = CONSTR_DEFAULT;
2500 n->cooked_expr = NULL;
2503 | REFERENCES qualified_name opt_column_list key_match key_actions
2505 Constraint *n = makeNode(Constraint);
2506 n->contype = CONSTR_FOREIGN;
2511 n->fk_matchtype = $4;
2512 n->fk_upd_action = (char) ($5 >> 8);
2513 n->fk_del_action = (char) ($5 & 0xFF);
2514 n->skip_validation = FALSE;
2520 * ConstraintAttr represents constraint attributes, which we parse as if
2521 * they were independent constraint clauses, in order to avoid shift/reduce
2522 * conflicts (since NOT might start either an independent NOT NULL clause
2523 * or an attribute). parse_utilcmd.c is responsible for attaching the
2524 * attribute information to the preceding "real" constraint node, and for
2525 * complaining if attribute clauses appear in the wrong place or wrong
2528 * See also ConstraintAttributeSpec, which can be used in places where
2529 * there is no parsing conflict.
2534 Constraint *n = makeNode(Constraint);
2535 n->contype = CONSTR_ATTR_DEFERRABLE;
2541 Constraint *n = makeNode(Constraint);
2542 n->contype = CONSTR_ATTR_NOT_DEFERRABLE;
2546 | INITIALLY DEFERRED
2548 Constraint *n = makeNode(Constraint);
2549 n->contype = CONSTR_ATTR_DEFERRED;
2553 | INITIALLY IMMEDIATE
2555 Constraint *n = makeNode(Constraint);
2556 n->contype = CONSTR_ATTR_IMMEDIATE;
2564 * SQL99 supports wholesale borrowing of a table definition via the LIKE clause.
2565 * This seems to be a poor man's inheritance capability, with the resulting
2566 * tables completely decoupled except for the original commonality in definitions.
2568 * This is very similar to CREATE TABLE AS except for the INCLUDING DEFAULTS extension
2569 * which is a part of SQL:2003.
2572 LIKE qualified_name TableLikeOptionList
2574 InhRelation *n = makeNode(InhRelation);
2581 TableLikeOptionList:
2582 TableLikeOptionList INCLUDING TableLikeOption { $$ = $1 | $3; }
2583 | TableLikeOptionList EXCLUDING TableLikeOption { $$ = $1 & ~$3; }
2584 | /* EMPTY */ { $$ = 0; }
2588 DEFAULTS { $$ = CREATE_TABLE_LIKE_DEFAULTS; }
2589 | CONSTRAINTS { $$ = CREATE_TABLE_LIKE_CONSTRAINTS; }
2590 | INDEXES { $$ = CREATE_TABLE_LIKE_INDEXES; }
2591 | STORAGE { $$ = CREATE_TABLE_LIKE_STORAGE; }
2592 | COMMENTS { $$ = CREATE_TABLE_LIKE_COMMENTS; }
2593 | ALL { $$ = CREATE_TABLE_LIKE_ALL; }
2597 /* ConstraintElem specifies constraint syntax which is not embedded into
2598 * a column definition. ColConstraintElem specifies the embedded form.
2599 * - thomas 1997-12-03
2602 CONSTRAINT name ConstraintElem
2604 Constraint *n = (Constraint *) $3;
2605 Assert(IsA(n, Constraint));
2610 | ConstraintElem { $$ = $1; }
2614 CHECK '(' a_expr ')' ConstraintAttributeSpec
2616 Constraint *n = makeNode(Constraint);
2617 n->contype = CONSTR_CHECK;
2620 n->cooked_expr = NULL;
2623 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
2624 errmsg("CHECK constraints cannot be deferred"),
2625 parser_errposition(@5)));
2628 | UNIQUE '(' columnList ')' opt_definition OptConsTableSpace
2629 ConstraintAttributeSpec
2631 Constraint *n = makeNode(Constraint);
2632 n->contype = CONSTR_UNIQUE;
2637 n->deferrable = ($7 & 1) != 0;
2638 n->initdeferred = ($7 & 2) != 0;
2641 | PRIMARY KEY '(' columnList ')' opt_definition OptConsTableSpace
2642 ConstraintAttributeSpec
2644 Constraint *n = makeNode(Constraint);
2645 n->contype = CONSTR_PRIMARY;
2650 n->deferrable = ($8 & 1) != 0;
2651 n->initdeferred = ($8 & 2) != 0;
2654 | EXCLUDE access_method_clause '(' ExclusionConstraintList ')'
2655 opt_definition OptConsTableSpace ExclusionWhereClause
2656 ConstraintAttributeSpec
2658 Constraint *n = makeNode(Constraint);
2659 n->contype = CONSTR_EXCLUSION;
2661 n->access_method = $2;
2665 n->where_clause = $8;
2666 n->deferrable = ($9 & 1) != 0;
2667 n->initdeferred = ($9 & 2) != 0;
2670 | FOREIGN KEY '(' columnList ')' REFERENCES qualified_name
2671 opt_column_list key_match key_actions ConstraintAttributeSpec
2673 Constraint *n = makeNode(Constraint);
2674 n->contype = CONSTR_FOREIGN;
2679 n->fk_matchtype = $9;
2680 n->fk_upd_action = (char) ($10 >> 8);
2681 n->fk_del_action = (char) ($10 & 0xFF);
2682 n->skip_validation = FALSE;
2683 n->deferrable = ($11 & 1) != 0;
2684 n->initdeferred = ($11 & 2) != 0;
2690 '(' columnList ')' { $$ = $2; }
2691 | /*EMPTY*/ { $$ = NIL; }
2695 columnElem { $$ = list_make1($1); }
2696 | columnList ',' columnElem { $$ = lappend($1, $3); }
2701 $$ = (Node *) makeString($1);
2705 key_match: MATCH FULL
2707 $$ = FKCONSTR_MATCH_FULL;
2712 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
2713 errmsg("MATCH PARTIAL not yet implemented"),
2714 parser_errposition(@1)));
2715 $$ = FKCONSTR_MATCH_PARTIAL;
2719 $$ = FKCONSTR_MATCH_UNSPECIFIED;
2723 $$ = FKCONSTR_MATCH_UNSPECIFIED;
2727 ExclusionConstraintList:
2728 ExclusionConstraintElem { $$ = list_make1($1); }
2729 | ExclusionConstraintList ',' ExclusionConstraintElem
2730 { $$ = lappend($1, $3); }
2733 ExclusionConstraintElem: index_elem WITH any_operator
2735 $$ = list_make2($1, $3);
2737 /* allow OPERATOR() decoration for the benefit of ruleutils.c */
2738 | index_elem WITH OPERATOR '(' any_operator ')'
2740 $$ = list_make2($1, $5);
2744 ExclusionWhereClause:
2745 WHERE '(' a_expr ')' { $$ = $3; }
2746 | /*EMPTY*/ { $$ = NULL; }
2750 * We combine the update and delete actions into one value temporarily
2751 * for simplicity of parsing, and then break them down again in the
2752 * calling production. update is in the left 8 bits, delete in the right.
2753 * Note that NOACTION is the default.
2757 { $$ = ($1 << 8) | (FKCONSTR_ACTION_NOACTION & 0xFF); }
2759 { $$ = (FKCONSTR_ACTION_NOACTION << 8) | ($1 & 0xFF); }
2760 | key_update key_delete
2761 { $$ = ($1 << 8) | ($2 & 0xFF); }
2762 | key_delete key_update
2763 { $$ = ($2 << 8) | ($1 & 0xFF); }
2765 { $$ = (FKCONSTR_ACTION_NOACTION << 8) | (FKCONSTR_ACTION_NOACTION & 0xFF); }
2768 key_update: ON UPDATE key_action { $$ = $3; }
2771 key_delete: ON DELETE_P key_action { $$ = $3; }
2775 NO ACTION { $$ = FKCONSTR_ACTION_NOACTION; }
2776 | RESTRICT { $$ = FKCONSTR_ACTION_RESTRICT; }
2777 | CASCADE { $$ = FKCONSTR_ACTION_CASCADE; }
2778 | SET NULL_P { $$ = FKCONSTR_ACTION_SETNULL; }
2779 | SET DEFAULT { $$ = FKCONSTR_ACTION_SETDEFAULT; }
2782 OptInherit: INHERITS '(' qualified_name_list ')' { $$ = $3; }
2783 | /*EMPTY*/ { $$ = NIL; }
2786 /* WITH (options) is preferred, WITH OIDS and WITHOUT OIDS are legacy forms */
2788 WITH reloptions { $$ = $2; }
2789 | WITH OIDS { $$ = list_make1(defWithOids(true)); }
2790 | WITHOUT OIDS { $$ = list_make1(defWithOids(false)); }
2791 | /*EMPTY*/ { $$ = NIL; }
2794 OnCommitOption: ON COMMIT DROP { $$ = ONCOMMIT_DROP; }
2795 | ON COMMIT DELETE_P ROWS { $$ = ONCOMMIT_DELETE_ROWS; }
2796 | ON COMMIT PRESERVE ROWS { $$ = ONCOMMIT_PRESERVE_ROWS; }
2797 | /*EMPTY*/ { $$ = ONCOMMIT_NOOP; }
2800 OptTableSpace: TABLESPACE name { $$ = $2; }
2801 | /*EMPTY*/ { $$ = NULL; }
2804 OptConsTableSpace: USING INDEX TABLESPACE name { $$ = $4; }
2805 | /*EMPTY*/ { $$ = NULL; }
2810 * Note: CREATE TABLE ... AS SELECT ... is just another spelling for
2815 CREATE OptTemp TABLE create_as_target AS SelectStmt opt_with_data
2818 * When the SelectStmt is a set-operation tree, we must
2819 * stuff the INTO information into the leftmost component
2820 * Select, because that's where analyze.c will expect
2821 * to find it. Similarly, the output column names must
2822 * be attached to that Select's target list.
2824 SelectStmt *n = findLeftmostSelect((SelectStmt *) $6);
2825 if (n->intoClause != NULL)
2827 (errcode(ERRCODE_SYNTAX_ERROR),
2828 errmsg("CREATE TABLE AS cannot specify INTO"),
2829 parser_errposition(exprLocation((Node *) n->intoClause))));
2830 $4->rel->istemp = $2;
2832 /* Implement WITH NO DATA by forcing top-level LIMIT 0 */
2834 ((SelectStmt *) $6)->limitCount = makeIntConst(0, -1);
2840 qualified_name OptCreateAs OptWith OnCommitOption OptTableSpace
2842 $$ = makeNode(IntoClause);
2847 $$->tableSpaceName = $5;
2852 '(' CreateAsList ')' { $$ = $2; }
2853 | /*EMPTY*/ { $$ = NIL; }
2857 CreateAsElement { $$ = list_make1($1); }
2858 | CreateAsList ',' CreateAsElement { $$ = lappend($1, $3); }
2864 ColumnDef *n = makeNode(ColumnDef);
2869 n->is_not_null = false;
2870 n->raw_default = NULL;
2871 n->cooked_default = NULL;
2872 n->constraints = NIL;
2878 WITH DATA_P { $$ = TRUE; }
2879 | WITH NO DATA_P { $$ = FALSE; }
2880 | /*EMPTY*/ { $$ = TRUE; }
2884 /*****************************************************************************
2887 * CREATE SEQUENCE seqname
2888 * ALTER SEQUENCE seqname
2890 *****************************************************************************/
2893 CREATE OptTemp SEQUENCE qualified_name OptSeqOptList
2895 CreateSeqStmt *n = makeNode(CreateSeqStmt);
2899 n->ownerId = InvalidOid;
2905 ALTER SEQUENCE qualified_name SeqOptList
2907 AlterSeqStmt *n = makeNode(AlterSeqStmt);
2914 OptSeqOptList: SeqOptList { $$ = $1; }
2915 | /*EMPTY*/ { $$ = NIL; }
2918 SeqOptList: SeqOptElem { $$ = list_make1($1); }
2919 | SeqOptList SeqOptElem { $$ = lappend($1, $2); }
2922 SeqOptElem: CACHE NumericOnly
2924 $$ = makeDefElem("cache", (Node *)$2);
2928 $$ = makeDefElem("cycle", (Node *)makeInteger(TRUE));
2932 $$ = makeDefElem("cycle", (Node *)makeInteger(FALSE));
2934 | INCREMENT opt_by NumericOnly
2936 $$ = makeDefElem("increment", (Node *)$3);
2938 | MAXVALUE NumericOnly
2940 $$ = makeDefElem("maxvalue", (Node *)$2);
2942 | MINVALUE NumericOnly
2944 $$ = makeDefElem("minvalue", (Node *)$2);
2948 $$ = makeDefElem("maxvalue", NULL);
2952 $$ = makeDefElem("minvalue", NULL);
2956 $$ = makeDefElem("owned_by", (Node *)$3);
2958 | START opt_with NumericOnly
2960 $$ = makeDefElem("start", (Node *)$3);
2964 $$ = makeDefElem("restart", NULL);
2966 | RESTART opt_with NumericOnly
2968 $$ = makeDefElem("restart", (Node *)$3);
2977 FCONST { $$ = makeFloat($1); }
2983 | SignedIconst { $$ = makeInteger($1); }
2986 NumericOnly_list: NumericOnly { $$ = list_make1($1); }
2987 | NumericOnly_list ',' NumericOnly { $$ = lappend($1, $3); }
2990 /*****************************************************************************
2993 * CREATE [OR REPLACE] [TRUSTED] [PROCEDURAL] LANGUAGE ...
2994 * DROP [PROCEDURAL] LANGUAGE ...
2996 *****************************************************************************/
2999 CREATE opt_or_replace opt_trusted opt_procedural LANGUAGE ColId_or_Sconst
3001 CreatePLangStmt *n = makeNode(CreatePLangStmt);
3004 /* parameters are all to be supplied by system */
3007 n->plvalidator = NIL;
3008 n->pltrusted = false;
3011 | CREATE opt_or_replace opt_trusted opt_procedural LANGUAGE ColId_or_Sconst
3012 HANDLER handler_name opt_inline_handler opt_validator
3014 CreatePLangStmt *n = makeNode(CreatePLangStmt);
3019 n->plvalidator = $10;
3026 TRUSTED { $$ = TRUE; }
3027 | /*EMPTY*/ { $$ = FALSE; }
3030 /* This ought to be just func_name, but that causes reduce/reduce conflicts
3031 * (CREATE LANGUAGE is the only place where func_name isn't followed by '(').
3032 * Work around by using simple names, instead.
3035 name { $$ = list_make1(makeString($1)); }
3036 | name attrs { $$ = lcons(makeString($1), $2); }
3040 INLINE_P handler_name { $$ = $2; }
3041 | /*EMPTY*/ { $$ = NIL; }
3045 VALIDATOR handler_name { $$ = $2; }
3046 | NO VALIDATOR { $$ = NIL; }
3050 validator_clause { $$ = $1; }
3051 | /*EMPTY*/ { $$ = NIL; }
3055 DROP opt_procedural LANGUAGE ColId_or_Sconst opt_drop_behavior
3057 DropPLangStmt *n = makeNode(DropPLangStmt);
3060 n->missing_ok = false;
3063 | DROP opt_procedural LANGUAGE IF_P EXISTS ColId_or_Sconst opt_drop_behavior
3065 DropPLangStmt *n = makeNode(DropPLangStmt);
3068 n->missing_ok = true;
3078 /*****************************************************************************
3081 * CREATE TABLESPACE tablespace LOCATION '/path/to/tablespace/'
3083 *****************************************************************************/
3085 CreateTableSpaceStmt: CREATE TABLESPACE name OptTableSpaceOwner LOCATION Sconst
3087 CreateTableSpaceStmt *n = makeNode(CreateTableSpaceStmt);
3088 n->tablespacename = $3;
3095 OptTableSpaceOwner: OWNER name { $$ = $2; }
3096 | /*EMPTY */ { $$ = NULL; }
3099 /*****************************************************************************
3102 * DROP TABLESPACE <tablespace>
3104 * No need for drop behaviour as we cannot implement dependencies for
3105 * objects in other databases; we can only support RESTRICT.
3107 ****************************************************************************/
3109 DropTableSpaceStmt: DROP TABLESPACE name
3111 DropTableSpaceStmt *n = makeNode(DropTableSpaceStmt);
3112 n->tablespacename = $3;
3113 n->missing_ok = false;
3116 | DROP TABLESPACE IF_P EXISTS name
3118 DropTableSpaceStmt *n = makeNode(DropTableSpaceStmt);
3119 n->tablespacename = $5;
3120 n->missing_ok = true;
3125 /*****************************************************************************
3128 * CREATE FOREIGN DATA WRAPPER name [ VALIDATOR name ]
3130 *****************************************************************************/
3132 CreateFdwStmt: CREATE FOREIGN DATA_P WRAPPER name opt_validator create_generic_options
3134 CreateFdwStmt *n = makeNode(CreateFdwStmt);
3142 /*****************************************************************************
3145 * DROP FOREIGN DATA WRAPPER name
3147 ****************************************************************************/
3149 DropFdwStmt: DROP FOREIGN DATA_P WRAPPER name opt_drop_behavior
3151 DropFdwStmt *n = makeNode(DropFdwStmt);
3153 n->missing_ok = false;
3157 | DROP FOREIGN DATA_P WRAPPER IF_P EXISTS name opt_drop_behavior
3159 DropFdwStmt *n = makeNode(DropFdwStmt);
3161 n->missing_ok = true;
3167 /*****************************************************************************
3170 * ALTER FOREIGN DATA WRAPPER name
3172 ****************************************************************************/
3174 AlterFdwStmt: ALTER FOREIGN DATA_P WRAPPER name validator_clause alter_generic_options
3176 AlterFdwStmt *n = makeNode(AlterFdwStmt);
3179 n->change_validator = true;
3183 | ALTER FOREIGN DATA_P WRAPPER name validator_clause
3185 AlterFdwStmt *n = makeNode(AlterFdwStmt);
3188 n->change_validator = true;
3191 | ALTER FOREIGN DATA_P WRAPPER name alter_generic_options
3193 AlterFdwStmt *n = makeNode(AlterFdwStmt);
3200 /* Options definition for CREATE FDW, SERVER and USER MAPPING */
3201 create_generic_options:
3202 OPTIONS '(' generic_option_list ')' { $$ = $3; }
3203 | /*EMPTY*/ { $$ = NIL; }
3206 generic_option_list:
3209 $$ = list_make1($1);
3211 | generic_option_list ',' generic_option_elem
3213 $$ = lappend($1, $3);
3217 /* Options definition for ALTER FDW, SERVER and USER MAPPING */
3218 alter_generic_options:
3219 OPTIONS '(' alter_generic_option_list ')' { $$ = $3; }
3222 alter_generic_option_list:
3223 alter_generic_option_elem
3225 $$ = list_make1($1);
3227 | alter_generic_option_list ',' alter_generic_option_elem
3229 $$ = lappend($1, $3);
3233 alter_generic_option_elem:
3238 | SET generic_option_elem
3241 $$->defaction = DEFELEM_SET;
3243 | ADD_P generic_option_elem
3246 $$->defaction = DEFELEM_ADD;
3248 | DROP generic_option_name
3250 $$ = makeDefElemExtended(NULL, $2, NULL, DEFELEM_DROP);
3254 generic_option_elem:
3255 generic_option_name generic_option_arg
3257 $$ = makeDefElem($1, $2);
3261 generic_option_name:
3262 ColLabel { $$ = $1; }
3265 /* We could use def_arg here, but the spec only requires string literals */
3267 Sconst { $$ = (Node *) makeString($1); }
3270 /*****************************************************************************
3273 * CREATE SERVER name [TYPE] [VERSION] [OPTIONS]
3275 *****************************************************************************/
3277 CreateForeignServerStmt: CREATE SERVER name opt_type opt_foreign_server_version
3278 FOREIGN DATA_P WRAPPER name create_generic_options
3280 CreateForeignServerStmt *n = makeNode(CreateForeignServerStmt);
3291 TYPE_P Sconst { $$ = $2; }
3292 | /*EMPTY*/ { $$ = NULL; }
3296 foreign_server_version:
3297 VERSION_P Sconst { $$ = $2; }
3298 | VERSION_P NULL_P { $$ = NULL; }
3301 opt_foreign_server_version:
3302 foreign_server_version { $$ = $1; }
3303 | /*EMPTY*/ { $$ = NULL; }
3306 /*****************************************************************************
3311 ****************************************************************************/
3313 DropForeignServerStmt: DROP SERVER name opt_drop_behavior
3315 DropForeignServerStmt *n = makeNode(DropForeignServerStmt);
3317 n->missing_ok = false;
3321 | DROP SERVER IF_P EXISTS name opt_drop_behavior
3323 DropForeignServerStmt *n = makeNode(DropForeignServerStmt);
3325 n->missing_ok = true;
3331 /*****************************************************************************
3334 * ALTER SERVER name [VERSION] [OPTIONS]
3336 ****************************************************************************/
3338 AlterForeignServerStmt: ALTER SERVER name foreign_server_version alter_generic_options
3340 AlterForeignServerStmt *n = makeNode(AlterForeignServerStmt);
3344 n->has_version = true;
3347 | ALTER SERVER name foreign_server_version
3349 AlterForeignServerStmt *n = makeNode(AlterForeignServerStmt);
3352 n->has_version = true;
3355 | ALTER SERVER name alter_generic_options
3357 AlterForeignServerStmt *n = makeNode(AlterForeignServerStmt);
3364 /*****************************************************************************
3367 * CREATE USER MAPPING FOR auth_ident SERVER name [OPTIONS]
3369 *****************************************************************************/
3371 CreateUserMappingStmt: CREATE USER MAPPING FOR auth_ident SERVER name create_generic_options
3373 CreateUserMappingStmt *n = makeNode(CreateUserMappingStmt);
3381 /* User mapping authorization identifier */
3383 CURRENT_USER { $$ = "current_user"; }
3384 | USER { $$ = "current_user"; }
3385 | RoleId { $$ = (strcmp($1, "public") == 0) ? NULL : $1; }
3388 /*****************************************************************************
3391 * DROP USER MAPPING FOR auth_ident SERVER name
3393 ****************************************************************************/
3395 DropUserMappingStmt: DROP USER MAPPING FOR auth_ident SERVER name
3397 DropUserMappingStmt *n = makeNode(DropUserMappingStmt);
3400 n->missing_ok = false;
3403 | DROP USER MAPPING IF_P EXISTS FOR auth_ident SERVER name
3405 DropUserMappingStmt *n = makeNode(DropUserMappingStmt);
3408 n->missing_ok = true;
3413 /*****************************************************************************
3416 * ALTER USER MAPPING FOR auth_ident SERVER name OPTIONS
3418 ****************************************************************************/
3420 AlterUserMappingStmt: ALTER USER MAPPING FOR auth_ident SERVER name alter_generic_options
3422 AlterUserMappingStmt *n = makeNode(AlterUserMappingStmt);
3430 /*****************************************************************************
3433 * CREATE TRIGGER ...
3436 *****************************************************************************/
3439 CREATE TRIGGER name TriggerActionTime TriggerEvents ON
3440 qualified_name TriggerForSpec TriggerWhen
3441 EXECUTE PROCEDURE func_name '(' TriggerFuncArgs ')'
3443 CreateTrigStmt *n = makeNode(CreateTrigStmt);
3450 n->events = intVal(linitial($5));
3451 n->columns = (List *) lsecond($5);
3453 n->isconstraint = FALSE;
3454 n->deferrable = FALSE;
3455 n->initdeferred = FALSE;
3456 n->constrrel = NULL;
3459 | CREATE CONSTRAINT TRIGGER name AFTER TriggerEvents ON
3460 qualified_name OptConstrFromTable ConstraintAttributeSpec
3461 FOR EACH ROW TriggerWhen
3462 EXECUTE PROCEDURE func_name '(' TriggerFuncArgs ')'
3464 CreateTrigStmt *n = makeNode(CreateTrigStmt);
3471 n->events = intVal(linitial($6));
3472 n->columns = (List *) lsecond($6);
3473 n->whenClause = $14;
3474 n->isconstraint = TRUE;
3475 n->deferrable = ($10 & 1) != 0;
3476 n->initdeferred = ($10 & 2) != 0;
3483 BEFORE { $$ = TRUE; }
3484 | AFTER { $$ = FALSE; }
3490 | TriggerEvents OR TriggerOneEvent
3492 int events1 = intVal(linitial($1));
3493 int events2 = intVal(linitial($3));
3494 List *columns1 = (List *) lsecond($1);
3495 List *columns2 = (List *) lsecond($3);
3497 if (events1 & events2)
3498 parser_yyerror("duplicate trigger events specified");
3500 * concat'ing the columns lists loses information about
3501 * which columns went with which event, but so long as
3502 * only UPDATE carries columns and we disallow multiple
3503 * UPDATE items, it doesn't matter. Command execution
3504 * should just ignore the columns for non-UPDATE events.
3506 $$ = list_make2(makeInteger(events1 | events2),
3507 list_concat(columns1, columns2));
3513 { $$ = list_make2(makeInteger(TRIGGER_TYPE_INSERT), NIL); }
3515 { $$ = list_make2(makeInteger(TRIGGER_TYPE_DELETE), NIL); }
3517 { $$ = list_make2(makeInteger(TRIGGER_TYPE_UPDATE), NIL); }
3518 | UPDATE OF columnList
3519 { $$ = list_make2(makeInteger(TRIGGER_TYPE_UPDATE), $3); }
3521 { $$ = list_make2(makeInteger(TRIGGER_TYPE_TRUNCATE), NIL); }
3525 FOR TriggerForOpt TriggerForType
3532 * If ROW/STATEMENT not specified, default to
3533 * STATEMENT, per SQL
3546 | STATEMENT { $$ = FALSE; }
3550 WHEN '(' a_expr ')' { $$ = $3; }
3551 | /*EMPTY*/ { $$ = NULL; }
3555 TriggerFuncArg { $$ = list_make1($1); }
3556 | TriggerFuncArgs ',' TriggerFuncArg { $$ = lappend($1, $3); }
3557 | /*EMPTY*/ { $$ = NIL; }
3564 snprintf(buf, sizeof(buf), "%d", $1);
3565 $$ = makeString(pstrdup(buf));
3567 | FCONST { $$ = makeString($1); }
3568 | Sconst { $$ = makeString($1); }
3569 | BCONST { $$ = makeString($1); }
3570 | XCONST { $$ = makeString($1); }
3571 | ColId { $$ = makeString($1); }
3575 FROM qualified_name { $$ = $2; }
3576 | /*EMPTY*/ { $$ = NULL; }
3579 ConstraintAttributeSpec:
3580 ConstraintDeferrabilitySpec
3582 | ConstraintDeferrabilitySpec ConstraintTimeSpec
3584 if ($1 == 0 && $2 != 0)
3586 (errcode(ERRCODE_SYNTAX_ERROR),
3587 errmsg("constraint declared INITIALLY DEFERRED must be DEFERRABLE"),
3588 parser_errposition(@1)));
3591 | ConstraintTimeSpec
3598 | ConstraintTimeSpec ConstraintDeferrabilitySpec
3600 if ($2 == 0 && $1 != 0)
3602 (errcode(ERRCODE_SYNTAX_ERROR),
3603 errmsg("constraint declared INITIALLY DEFERRED must be DEFERRABLE"),
3604 parser_errposition(@1)));
3611 ConstraintDeferrabilitySpec:
3612 NOT DEFERRABLE { $$ = 0; }
3613 | DEFERRABLE { $$ = 1; }
3617 INITIALLY IMMEDIATE { $$ = 0; }
3618 | INITIALLY DEFERRED { $$ = 2; }
3623 DROP TRIGGER name ON qualified_name opt_drop_behavior
3625 DropPropertyStmt *n = makeNode(DropPropertyStmt);
3629 n->removeType = OBJECT_TRIGGER;
3630 n->missing_ok = false;
3633 | DROP TRIGGER IF_P EXISTS name ON qualified_name opt_drop_behavior
3635 DropPropertyStmt *n = makeNode(DropPropertyStmt);
3639 n->removeType = OBJECT_TRIGGER;
3640 n->missing_ok = true;
3646 /*****************************************************************************
3649 * CREATE ASSERTION ...
3650 * DROP ASSERTION ...
3652 *****************************************************************************/
3655 CREATE ASSERTION name CHECK '(' a_expr ')'
3656 ConstraintAttributeSpec
3658 CreateTrigStmt *n = makeNode(CreateTrigStmt);
3660 n->args = list_make1($6);
3661 n->isconstraint = TRUE;
3662 n->deferrable = ($8 & 1) != 0;
3663 n->initdeferred = ($8 & 2) != 0;
3666 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
3667 errmsg("CREATE ASSERTION is not yet implemented")));
3674 DROP ASSERTION name opt_drop_behavior
3676 DropPropertyStmt *n = makeNode(DropPropertyStmt);
3680 n->removeType = OBJECT_TRIGGER; /* XXX */
3682 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
3683 errmsg("DROP ASSERTION is not yet implemented")));
3689 /*****************************************************************************
3692 * define (aggregate,operator,type)
3694 *****************************************************************************/
3697 CREATE AGGREGATE func_name aggr_args definition
3699 DefineStmt *n = makeNode(DefineStmt);
3700 n->kind = OBJECT_AGGREGATE;
3701 n->oldstyle = false;
3707 | CREATE AGGREGATE func_name old_aggr_definition
3709 /* old-style (pre-8.2) syntax for CREATE AGGREGATE */
3710 DefineStmt *n = makeNode(DefineStmt);
3711 n->kind = OBJECT_AGGREGATE;
3718 | CREATE OPERATOR any_operator definition
3720 DefineStmt *n = makeNode(DefineStmt);
3721 n->kind = OBJECT_OPERATOR;
3722 n->oldstyle = false;
3728 | CREATE TYPE_P any_name definition
3730 DefineStmt *n = makeNode(DefineStmt);
3731 n->kind = OBJECT_TYPE;
3732 n->oldstyle = false;
3738 | CREATE TYPE_P any_name
3740 /* Shell type (identified by lack of definition) */
3741 DefineStmt *n = makeNode(DefineStmt);
3742 n->kind = OBJECT_TYPE;
3743 n->oldstyle = false;
3746 n->definition = NIL;
3749 | CREATE TYPE_P any_name AS '(' OptTableFuncElementList ')'
3751 CompositeTypeStmt *n = makeNode(CompositeTypeStmt);
3753 /* can't use qualified_name, sigh */
3754 n->typevar = makeRangeVarFromAnyName($3, @3, yyscanner);
3758 | CREATE TYPE_P any_name AS ENUM_P '(' opt_enum_val_list ')'
3760 CreateEnumStmt *n = makeNode(CreateEnumStmt);
3765 | CREATE TEXT_P SEARCH PARSER any_name definition
3767 DefineStmt *n = makeNode(DefineStmt);
3768 n->kind = OBJECT_TSPARSER;
3774 | CREATE TEXT_P SEARCH DICTIONARY any_name definition
3776 DefineStmt *n = makeNode(DefineStmt);
3777 n->kind = OBJECT_TSDICTIONARY;
3783 | CREATE TEXT_P SEARCH TEMPLATE any_name definition
3785 DefineStmt *n = makeNode(DefineStmt);
3786 n->kind = OBJECT_TSTEMPLATE;
3792 | CREATE TEXT_P SEARCH CONFIGURATION any_name definition
3794 DefineStmt *n = makeNode(DefineStmt);
3795 n->kind = OBJECT_TSCONFIGURATION;
3803 definition: '(' def_list ')' { $$ = $2; }
3806 def_list: def_elem { $$ = list_make1($1); }
3807 | def_list ',' def_elem { $$ = lappend($1, $3); }
3810 def_elem: ColLabel '=' def_arg
3812 $$ = makeDefElem($1, (Node *) $3);
3816 $$ = makeDefElem($1, NULL);
3820 /* Note: any simple identifier will be returned as a type name! */
3821 def_arg: func_type { $$ = (Node *)$1; }
3822 | reserved_keyword { $$ = (Node *)makeString(pstrdup($1)); }
3823 | qual_all_Op { $$ = (Node *)$1; }
3824 | NumericOnly { $$ = (Node *)$1; }
3825 | Sconst { $$ = (Node *)makeString($1); }
3828 aggr_args: '(' type_list ')' { $$ = $2; }
3829 | '(' '*' ')' { $$ = NIL; }
3832 old_aggr_definition: '(' old_aggr_list ')' { $$ = $2; }
3835 old_aggr_list: old_aggr_elem { $$ = list_make1($1); }
3836 | old_aggr_list ',' old_aggr_elem { $$ = lappend($1, $3); }
3840 * Must use IDENT here to avoid reduce/reduce conflicts; fortunately none of
3841 * the item names needed in old aggregate definitions are likely to become
3844 old_aggr_elem: IDENT '=' def_arg
3846 $$ = makeDefElem($1, (Node *)$3);
3851 enum_val_list { $$ = $1; }
3852 | /*EMPTY*/ { $$ = NIL; }
3855 enum_val_list: Sconst
3856 { $$ = list_make1(makeString($1)); }
3857 | enum_val_list ',' Sconst
3858 { $$ = lappend($1, makeString($3)); }
3862 /*****************************************************************************
3865 * CREATE OPERATOR CLASS ...
3866 * CREATE OPERATOR FAMILY ...
3867 * ALTER OPERATOR FAMILY ...
3868 * DROP OPERATOR CLASS ...
3869 * DROP OPERATOR FAMILY ...
3871 *****************************************************************************/
3874 CREATE OPERATOR CLASS any_name opt_default FOR TYPE_P Typename
3875 USING access_method opt_opfamily AS opclass_item_list
3877 CreateOpClassStmt *n = makeNode(CreateOpClassStmt);
3878 n->opclassname = $4;
3882 n->opfamilyname = $11;
3889 opclass_item { $$ = list_make1($1); }
3890 | opclass_item_list ',' opclass_item { $$ = lappend($1, $3); }
3894 OPERATOR Iconst any_operator opt_recheck
3896 CreateOpClassItem *n = makeNode(CreateOpClassItem);
3897 n->itemtype = OPCLASS_ITEM_OPERATOR;
3903 | OPERATOR Iconst any_operator oper_argtypes opt_recheck
3905 CreateOpClassItem *n = makeNode(CreateOpClassItem);
3906 n->itemtype = OPCLASS_ITEM_OPERATOR;
3912 | FUNCTION Iconst func_name func_args
3914 CreateOpClassItem *n = makeNode(CreateOpClassItem);
3915 n->itemtype = OPCLASS_ITEM_FUNCTION;
3917 n->args = extractArgTypes($4);
3921 | FUNCTION Iconst '(' type_list ')' func_name func_args
3923 CreateOpClassItem *n = makeNode(CreateOpClassItem);
3924 n->itemtype = OPCLASS_ITEM_FUNCTION;
3926 n->args = extractArgTypes($7);
3933 CreateOpClassItem *n = makeNode(CreateOpClassItem);
3934 n->itemtype = OPCLASS_ITEM_STORAGETYPE;
3940 opt_default: DEFAULT { $$ = TRUE; }
3941 | /*EMPTY*/ { $$ = FALSE; }
3944 opt_opfamily: FAMILY any_name { $$ = $2; }
3945 | /*EMPTY*/ { $$ = NIL; }
3948 opt_recheck: RECHECK
3951 * RECHECK no longer does anything in opclass definitions,
3952 * but we still accept it to ease porting of old database
3956 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
3957 errmsg("RECHECK is no longer required"),
3958 errhint("Update your data type."),
3959 parser_errposition(@1)));
3962 | /*EMPTY*/ { $$ = FALSE; }
3967 CREATE OPERATOR FAMILY any_name USING access_method
3969 CreateOpFamilyStmt *n = makeNode(CreateOpFamilyStmt);
3970 n->opfamilyname = $4;
3977 ALTER OPERATOR FAMILY any_name USING access_method ADD_P opclass_item_list
3979 AlterOpFamilyStmt *n = makeNode(AlterOpFamilyStmt);
3980 n->opfamilyname = $4;
3986 | ALTER OPERATOR FAMILY any_name USING access_method DROP opclass_drop_list
3988 AlterOpFamilyStmt *n = makeNode(AlterOpFamilyStmt);
3989 n->opfamilyname = $4;
3998 opclass_drop { $$ = list_make1($1); }
3999 | opclass_drop_list ',' opclass_drop { $$ = lappend($1, $3); }
4003 OPERATOR Iconst '(' type_list ')'
4005 CreateOpClassItem *n = makeNode(CreateOpClassItem);
4006 n->itemtype = OPCLASS_ITEM_OPERATOR;
4011 | FUNCTION Iconst '(' type_list ')'
4013 CreateOpClassItem *n = makeNode(CreateOpClassItem);
4014 n->itemtype = OPCLASS_ITEM_FUNCTION;
4023 DROP OPERATOR CLASS any_name USING access_method opt_drop_behavior
4025 RemoveOpClassStmt *n = makeNode(RemoveOpClassStmt);
4026 n->opclassname = $4;
4029 n->missing_ok = false;
4032 | DROP OPERATOR CLASS IF_P EXISTS any_name USING access_method opt_drop_behavior
4034 RemoveOpClassStmt *n = makeNode(RemoveOpClassStmt);
4035 n->opclassname = $6;
4038 n->missing_ok = true;
4044 DROP OPERATOR FAMILY any_name USING access_method opt_drop_behavior
4046 RemoveOpFamilyStmt *n = makeNode(RemoveOpFamilyStmt);
4047 n->opfamilyname = $4;
4050 n->missing_ok = false;
4053 | DROP OPERATOR FAMILY IF_P EXISTS any_name USING access_method opt_drop_behavior
4055 RemoveOpFamilyStmt *n = makeNode(RemoveOpFamilyStmt);
4056 n->opfamilyname = $6;
4059 n->missing_ok = true;
4065 /*****************************************************************************
4069 * DROP OWNED BY username [, username ...] [ RESTRICT | CASCADE ]
4070 * REASSIGN OWNED BY username [, username ...] TO username
4072 *****************************************************************************/
4074 DROP OWNED BY name_list opt_drop_behavior
4076 DropOwnedStmt *n = makeNode(DropOwnedStmt);
4084 REASSIGN OWNED BY name_list TO name
4086 ReassignOwnedStmt *n = makeNode(ReassignOwnedStmt);
4093 /*****************************************************************************
4097 * DROP itemtype [ IF EXISTS ] itemname [, itemname ...]
4098 * [ RESTRICT | CASCADE ]
4100 *****************************************************************************/
4102 DropStmt: DROP drop_type IF_P EXISTS any_name_list opt_drop_behavior
4104 DropStmt *n = makeNode(DropStmt);
4106 n->missing_ok = TRUE;
4111 | DROP drop_type any_name_list opt_drop_behavior
4113 DropStmt *n = makeNode(DropStmt);
4115 n->missing_ok = FALSE;
4123 drop_type: TABLE { $$ = OBJECT_TABLE; }
4124 | SEQUENCE { $$ = OBJECT_SEQUENCE; }
4125 | VIEW { $$ = OBJECT_VIEW; }
4126 | INDEX { $$ = OBJECT_INDEX; }
4127 | TYPE_P { $$ = OBJECT_TYPE; }
4128 | DOMAIN_P { $$ = OBJECT_DOMAIN; }
4129 | CONVERSION_P { $$ = OBJECT_CONVERSION; }
4130 | SCHEMA { $$ = OBJECT_SCHEMA; }
4131 | TEXT_P SEARCH PARSER { $$ = OBJECT_TSPARSER; }
4132 | TEXT_P SEARCH DICTIONARY { $$ = OBJECT_TSDICTIONARY; }
4133 | TEXT_P SEARCH TEMPLATE { $$ = OBJECT_TSTEMPLATE; }
4134 | TEXT_P SEARCH CONFIGURATION { $$ = OBJECT_TSCONFIGURATION; }
4138 any_name { $$ = list_make1($1); }
4139 | any_name_list ',' any_name { $$ = lappend($1, $3); }
4142 any_name: ColId { $$ = list_make1(makeString($1)); }
4143 | ColId attrs { $$ = lcons(makeString($1), $2); }
4146 attrs: '.' attr_name
4147 { $$ = list_make1(makeString($2)); }
4148 | attrs '.' attr_name
4149 { $$ = lappend($1, makeString($3)); }
4153 /*****************************************************************************
4156 * truncate table relname1, relname2, ...
4158 *****************************************************************************/
4161 TRUNCATE opt_table relation_expr_list opt_restart_seqs opt_drop_behavior
4163 TruncateStmt *n = makeNode(TruncateStmt);
4165 n->restart_seqs = $4;
4172 CONTINUE_P IDENTITY_P { $$ = false; }
4173 | RESTART IDENTITY_P { $$ = true; }
4174 | /* EMPTY */ { $$ = false; }
4177 /*****************************************************************************
4179 * The COMMENT ON statement can take different forms based upon the type of
4180 * the object associated with the comment. The form of the statement is:
4182 * COMMENT ON [ [ DATABASE | DOMAIN | INDEX | SEQUENCE | TABLE | TYPE | VIEW |
4183 * CONVERSION | LANGUAGE | OPERATOR CLASS | LARGE OBJECT |
4184 * CAST | COLUMN | SCHEMA | TABLESPACE | ROLE |
4185 * TEXT SEARCH PARSER | TEXT SEARCH DICTIONARY |
4186 * TEXT SEARCH TEMPLATE |
4187 * TEXT SEARCH CONFIGURATION ] <objname> |
4188 * AGGREGATE <aggname> (arg1, ...) |
4189 * FUNCTION <funcname> (arg1, arg2, ...) |
4190 * OPERATOR <op> (leftoperand_typ, rightoperand_typ) |
4191 * TRIGGER <triggername> ON <relname> |
4192 * CONSTRAINT <constraintname> ON <relname> |
4193 * RULE <rulename> ON <relname> ]
4196 *****************************************************************************/
4199 COMMENT ON comment_type any_name IS comment_text
4201 CommentStmt *n = makeNode(CommentStmt);
4208 | COMMENT ON AGGREGATE func_name aggr_args IS comment_text
4210 CommentStmt *n = makeNode(CommentStmt);
4211 n->objtype = OBJECT_AGGREGATE;
4217 | COMMENT ON FUNCTION func_name func_args IS comment_text
4219 CommentStmt *n = makeNode(CommentStmt);
4220 n->objtype = OBJECT_FUNCTION;
4222 n->objargs = extractArgTypes($5);
4226 | COMMENT ON OPERATOR any_operator oper_argtypes IS comment_text
4228 CommentStmt *n = makeNode(CommentStmt);
4229 n->objtype = OBJECT_OPERATOR;
4235 | COMMENT ON CONSTRAINT name ON any_name IS comment_text
4237 CommentStmt *n = makeNode(CommentStmt);
4238 n->objtype = OBJECT_CONSTRAINT;
4239 n->objname = lappend($6, makeString($4));
4244 | COMMENT ON RULE name ON any_name IS comment_text
4246 CommentStmt *n = makeNode(CommentStmt);
4247 n->objtype = OBJECT_RULE;
4248 n->objname = lappend($6, makeString($4));
4253 | COMMENT ON RULE name IS comment_text
4255 /* Obsolete syntax supported for awhile for compatibility */
4256 CommentStmt *n = makeNode(CommentStmt);
4257 n->objtype = OBJECT_RULE;
4258 n->objname = list_make1(makeString($4));
4263 | COMMENT ON TRIGGER name ON any_name IS comment_text
4265 CommentStmt *n = makeNode(CommentStmt);
4266 n->objtype = OBJECT_TRIGGER;
4267 n->objname = lappend($6, makeString($4));
4272 | COMMENT ON OPERATOR CLASS any_name USING access_method IS comment_text
4274 CommentStmt *n = makeNode(CommentStmt);
4275 n->objtype = OBJECT_OPCLASS;
4277 n->objargs = list_make1(makeString($7));
4281 | COMMENT ON OPERATOR FAMILY any_name USING access_method IS comment_text
4283 CommentStmt *n = makeNode(CommentStmt);
4284 n->objtype = OBJECT_OPFAMILY;
4286 n->objargs = list_make1(makeString($7));
4290 | COMMENT ON LARGE_P OBJECT_P NumericOnly IS comment_text
4292 CommentStmt *n = makeNode(CommentStmt);
4293 n->objtype = OBJECT_LARGEOBJECT;
4294 n->objname = list_make1($5);
4299 | COMMENT ON CAST '(' Typename AS Typename ')' IS comment_text
4301 CommentStmt *n = makeNode(CommentStmt);
4302 n->objtype = OBJECT_CAST;
4303 n->objname = list_make1($5);
4304 n->objargs = list_make1($7);
4308 | COMMENT ON opt_procedural LANGUAGE any_name IS comment_text
4310 CommentStmt *n = makeNode(CommentStmt);
4311 n->objtype = OBJECT_LANGUAGE;
4317 | COMMENT ON TEXT_P SEARCH PARSER any_name IS comment_text
4319 CommentStmt *n = makeNode(CommentStmt);
4320 n->objtype = OBJECT_TSPARSER;
4325 | COMMENT ON TEXT_P SEARCH DICTIONARY any_name IS comment_text
4327 CommentStmt *n = makeNode(CommentStmt);
4328 n->objtype = OBJECT_TSDICTIONARY;
4333 | COMMENT ON TEXT_P SEARCH TEMPLATE any_name IS comment_text
4335 CommentStmt *n = makeNode(CommentStmt);
4336 n->objtype = OBJECT_TSTEMPLATE;
4341 | COMMENT ON TEXT_P SEARCH CONFIGURATION any_name IS comment_text
4343 CommentStmt *n = makeNode(CommentStmt);
4344 n->objtype = OBJECT_TSCONFIGURATION;
4352 COLUMN { $$ = OBJECT_COLUMN; }
4353 | DATABASE { $$ = OBJECT_DATABASE; }
4354 | SCHEMA { $$ = OBJECT_SCHEMA; }
4355 | INDEX { $$ = OBJECT_INDEX; }
4356 | SEQUENCE { $$ = OBJECT_SEQUENCE; }
4357 | TABLE { $$ = OBJECT_TABLE; }
4358 | DOMAIN_P { $$ = OBJECT_TYPE; }
4359 | TYPE_P { $$ = OBJECT_TYPE; }
4360 | VIEW { $$ = OBJECT_VIEW; }
4361 | CONVERSION_P { $$ = OBJECT_CONVERSION; }
4362 | TABLESPACE { $$ = OBJECT_TABLESPACE; }
4363 | ROLE { $$ = OBJECT_ROLE; }
4368 | NULL_P { $$ = NULL; }
4371 /*****************************************************************************
4376 *****************************************************************************/
4378 FetchStmt: FETCH fetch_args
4380 FetchStmt *n = (FetchStmt *) $2;
4386 FetchStmt *n = (FetchStmt *) $2;
4392 fetch_args: cursor_name
4394 FetchStmt *n = makeNode(FetchStmt);
4396 n->direction = FETCH_FORWARD;
4400 | from_in cursor_name
4402 FetchStmt *n = makeNode(FetchStmt);
4404 n->direction = FETCH_FORWARD;
4408 | NEXT opt_from_in cursor_name
4410 FetchStmt *n = makeNode(FetchStmt);
4412 n->direction = FETCH_FORWARD;
4416 | PRIOR opt_from_in cursor_name
4418 FetchStmt *n = makeNode(FetchStmt);
4420 n->direction = FETCH_BACKWARD;
4424 | FIRST_P opt_from_in cursor_name
4426 FetchStmt *n = makeNode(FetchStmt);
4428 n->direction = FETCH_ABSOLUTE;
4432 | LAST_P opt_from_in cursor_name
4434 FetchStmt *n = makeNode(FetchStmt);
4436 n->direction = FETCH_ABSOLUTE;
4440 | ABSOLUTE_P SignedIconst opt_from_in cursor_name
4442 FetchStmt *n = makeNode(FetchStmt);
4444 n->direction = FETCH_ABSOLUTE;
4448 | RELATIVE_P SignedIconst opt_from_in cursor_name
4450 FetchStmt *n = makeNode(FetchStmt);
4452 n->direction = FETCH_RELATIVE;
4456 | SignedIconst opt_from_in cursor_name
4458 FetchStmt *n = makeNode(FetchStmt);
4460 n->direction = FETCH_FORWARD;
4464 | ALL opt_from_in cursor_name
4466 FetchStmt *n = makeNode(FetchStmt);
4468 n->direction = FETCH_FORWARD;
4469 n->howMany = FETCH_ALL;
4472 | FORWARD opt_from_in cursor_name
4474 FetchStmt *n = makeNode(FetchStmt);
4476 n->direction = FETCH_FORWARD;
4480 | FORWARD SignedIconst opt_from_in cursor_name
4482 FetchStmt *n = makeNode(FetchStmt);
4484 n->direction = FETCH_FORWARD;
4488 | FORWARD ALL opt_from_in cursor_name
4490 FetchStmt *n = makeNode(FetchStmt);
4492 n->direction = FETCH_FORWARD;
4493 n->howMany = FETCH_ALL;
4496 | BACKWARD opt_from_in cursor_name
4498 FetchStmt *n = makeNode(FetchStmt);
4500 n->direction = FETCH_BACKWARD;
4504 | BACKWARD SignedIconst opt_from_in cursor_name
4506 FetchStmt *n = makeNode(FetchStmt);
4508 n->direction = FETCH_BACKWARD;
4512 | BACKWARD ALL opt_from_in cursor_name
4514 FetchStmt *n = makeNode(FetchStmt);
4516 n->direction = FETCH_BACKWARD;
4517 n->howMany = FETCH_ALL;
4526 opt_from_in: from_in {}
4531 /*****************************************************************************
4533 * GRANT and REVOKE statements
4535 *****************************************************************************/
4537 GrantStmt: GRANT privileges ON privilege_target TO grantee_list
4538 opt_grant_grant_option
4540 GrantStmt *n = makeNode(GrantStmt);
4543 n->targtype = ($4)->targtype;
4544 n->objtype = ($4)->objtype;
4545 n->objects = ($4)->objs;
4547 n->grant_option = $7;
4553 REVOKE privileges ON privilege_target
4554 FROM grantee_list opt_drop_behavior
4556 GrantStmt *n = makeNode(GrantStmt);
4557 n->is_grant = false;
4558 n->grant_option = false;
4560 n->targtype = ($4)->targtype;
4561 n->objtype = ($4)->objtype;
4562 n->objects = ($4)->objs;
4567 | REVOKE GRANT OPTION FOR privileges ON privilege_target
4568 FROM grantee_list opt_drop_behavior
4570 GrantStmt *n = makeNode(GrantStmt);
4571 n->is_grant = false;
4572 n->grant_option = true;
4574 n->targtype = ($7)->targtype;
4575 n->objtype = ($7)->objtype;
4576 n->objects = ($7)->objs;
4585 * Privilege names are represented as strings; the validity of the privilege
4586 * names gets checked at execution. This is a bit annoying but we have little
4587 * choice because of the syntactic conflict with lists of role names in
4588 * GRANT/REVOKE. What's more, we have to call out in the "privilege"
4589 * production any reserved keywords that need to be usable as privilege names.
4592 /* either ALL [PRIVILEGES] or a list of individual privileges */
4593 privileges: privilege_list
4599 | ALL '(' columnList ')'
4601 AccessPriv *n = makeNode(AccessPriv);
4602 n->priv_name = NULL;
4606 | ALL PRIVILEGES '(' columnList ')'
4608 AccessPriv *n = makeNode(AccessPriv);
4609 n->priv_name = NULL;
4615 privilege_list: privilege { $$ = list_make1($1); }
4616 | privilege_list ',' privilege { $$ = lappend($1, $3); }
4619 privilege: SELECT opt_column_list
4621 AccessPriv *n = makeNode(AccessPriv);
4622 n->priv_name = pstrdup($1);
4626 | REFERENCES opt_column_list
4628 AccessPriv *n = makeNode(AccessPriv);
4629 n->priv_name = pstrdup($1);
4633 | CREATE opt_column_list
4635 AccessPriv *n = makeNode(AccessPriv);
4636 n->priv_name = pstrdup($1);
4640 | ColId opt_column_list
4642 AccessPriv *n = makeNode(AccessPriv);
4650 /* Don't bother trying to fold the first two rules into one using
4651 * opt_table. You're going to get conflicts.
4656 PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
4657 n->targtype = ACL_TARGET_OBJECT;
4658 n->objtype = ACL_OBJECT_RELATION;
4662 | TABLE qualified_name_list
4664 PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
4665 n->targtype = ACL_TARGET_OBJECT;
4666 n->objtype = ACL_OBJECT_RELATION;
4670 | SEQUENCE qualified_name_list
4672 PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
4673 n->targtype = ACL_TARGET_OBJECT;
4674 n->objtype = ACL_OBJECT_SEQUENCE;
4678 | FOREIGN DATA_P WRAPPER name_list
4680 PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
4681 n->targtype = ACL_TARGET_OBJECT;
4682 n->objtype = ACL_OBJECT_FDW;
4686 | FOREIGN SERVER name_list
4688 PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
4689 n->targtype = ACL_TARGET_OBJECT;
4690 n->objtype = ACL_OBJECT_FOREIGN_SERVER;
4694 | FUNCTION function_with_argtypes_list
4696 PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
4697 n->targtype = ACL_TARGET_OBJECT;
4698 n->objtype = ACL_OBJECT_FUNCTION;
4702 | DATABASE name_list
4704 PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
4705 n->targtype = ACL_TARGET_OBJECT;
4706 n->objtype = ACL_OBJECT_DATABASE;
4710 | LANGUAGE name_list
4712 PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
4713 n->targtype = ACL_TARGET_OBJECT;
4714 n->objtype = ACL_OBJECT_LANGUAGE;
4718 | LARGE_P OBJECT_P NumericOnly_list
4720 PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
4721 n->targtype = ACL_TARGET_OBJECT;
4722 n->objtype = ACL_OBJECT_LARGEOBJECT;
4728 PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
4729 n->targtype = ACL_TARGET_OBJECT;
4730 n->objtype = ACL_OBJECT_NAMESPACE;
4734 | TABLESPACE name_list
4736 PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
4737 n->targtype = ACL_TARGET_OBJECT;
4738 n->objtype = ACL_OBJECT_TABLESPACE;
4742 | ALL TABLES IN_P SCHEMA name_list
4744 PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
4745 n->targtype = ACL_TARGET_ALL_IN_SCHEMA;
4746 n->objtype = ACL_OBJECT_RELATION;
4750 | ALL SEQUENCES IN_P SCHEMA name_list
4752 PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
4753 n->targtype = ACL_TARGET_ALL_IN_SCHEMA;
4754 n->objtype = ACL_OBJECT_SEQUENCE;
4758 | ALL FUNCTIONS IN_P SCHEMA name_list
4760 PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
4761 n->targtype = ACL_TARGET_ALL_IN_SCHEMA;
4762 n->objtype = ACL_OBJECT_FUNCTION;
4770 grantee { $$ = list_make1($1); }
4771 | grantee_list ',' grantee { $$ = lappend($1, $3); }
4776 PrivGrantee *n = makeNode(PrivGrantee);
4777 /* This hack lets us avoid reserving PUBLIC as a keyword*/
4778 if (strcmp($1, "public") == 0)
4786 PrivGrantee *n = makeNode(PrivGrantee);
4787 /* Treat GROUP PUBLIC as a synonym for PUBLIC */
4788 if (strcmp($2, "public") == 0)
4797 opt_grant_grant_option:
4798 WITH GRANT OPTION { $$ = TRUE; }
4799 | /*EMPTY*/ { $$ = FALSE; }
4802 function_with_argtypes_list:
4803 function_with_argtypes { $$ = list_make1($1); }
4804 | function_with_argtypes_list ',' function_with_argtypes
4805 { $$ = lappend($1, $3); }
4808 function_with_argtypes:
4811 FuncWithArgs *n = makeNode(FuncWithArgs);
4813 n->funcargs = extractArgTypes($2);
4818 /*****************************************************************************
4820 * GRANT and REVOKE ROLE statements
4822 *****************************************************************************/
4825 GRANT privilege_list TO name_list opt_grant_admin_option opt_granted_by
4827 GrantRoleStmt *n = makeNode(GrantRoleStmt);
4829 n->granted_roles = $2;
4830 n->grantee_roles = $4;
4838 REVOKE privilege_list FROM name_list opt_granted_by opt_drop_behavior
4840 GrantRoleStmt *n = makeNode(GrantRoleStmt);
4841 n->is_grant = false;
4842 n->admin_opt = false;
4843 n->granted_roles = $2;
4844 n->grantee_roles = $4;
4848 | REVOKE ADMIN OPTION FOR privilege_list FROM name_list opt_granted_by opt_drop_behavior
4850 GrantRoleStmt *n = makeNode(GrantRoleStmt);
4851 n->is_grant = false;
4852 n->admin_opt = true;
4853 n->granted_roles = $5;
4854 n->grantee_roles = $7;
4860 opt_grant_admin_option: WITH ADMIN OPTION { $$ = TRUE; }
4861 | /*EMPTY*/ { $$ = FALSE; }
4864 opt_granted_by: GRANTED BY RoleId { $$ = $3; }
4865 | /*EMPTY*/ { $$ = NULL; }
4868 /*****************************************************************************
4870 * ALTER DEFAULT PRIVILEGES statement
4872 *****************************************************************************/
4874 AlterDefaultPrivilegesStmt:
4875 ALTER DEFAULT PRIVILEGES DefACLOptionList DefACLAction
4877 AlterDefaultPrivilegesStmt *n = makeNode(AlterDefaultPrivilegesStmt);
4879 n->action = (GrantStmt *) $5;
4885 DefACLOptionList DefACLOption { $$ = lappend($1, $2); }
4886 | /* EMPTY */ { $$ = NIL; }
4890 IN_P SCHEMA name_list
4892 $$ = makeDefElem("schemas", (Node *)$3);
4894 | FOR ROLE name_list
4896 $$ = makeDefElem("roles", (Node *)$3);
4898 | FOR USER name_list
4900 $$ = makeDefElem("roles", (Node *)$3);
4905 * This should match GRANT/REVOKE, except that individual target objects
4906 * are not mentioned and we only allow a subset of object types.
4909 GRANT privileges ON defacl_privilege_target TO grantee_list
4910 opt_grant_grant_option
4912 GrantStmt *n = makeNode(GrantStmt);
4915 n->targtype = ACL_TARGET_DEFAULTS;
4919 n->grant_option = $7;
4922 | REVOKE privileges ON defacl_privilege_target
4923 FROM grantee_list opt_drop_behavior
4925 GrantStmt *n = makeNode(GrantStmt);
4926 n->is_grant = false;
4927 n->grant_option = false;
4929 n->targtype = ACL_TARGET_DEFAULTS;
4936 | REVOKE GRANT OPTION FOR privileges ON defacl_privilege_target
4937 FROM grantee_list opt_drop_behavior
4939 GrantStmt *n = makeNode(GrantStmt);
4940 n->is_grant = false;
4941 n->grant_option = true;
4943 n->targtype = ACL_TARGET_DEFAULTS;
4952 defacl_privilege_target:
4953 TABLES { $$ = ACL_OBJECT_RELATION; }
4954 | FUNCTIONS { $$ = ACL_OBJECT_FUNCTION; }
4955 | SEQUENCES { $$ = ACL_OBJECT_SEQUENCE; }
4959 /*****************************************************************************
4961 * QUERY: CREATE INDEX
4963 * Note: we cannot put TABLESPACE clause after WHERE clause unless we are
4964 * willing to make TABLESPACE a fully reserved word.
4965 *****************************************************************************/
4967 IndexStmt: CREATE opt_unique INDEX opt_concurrently opt_index_name
4968 ON qualified_name access_method_clause '(' index_params ')'
4969 opt_reloptions OptTableSpace where_clause
4971 IndexStmt *n = makeNode(IndexStmt);
4976 n->accessMethod = $8;
4977 n->indexParams = $10;
4979 n->tableSpace = $13;
4980 n->whereClause = $14;
4986 UNIQUE { $$ = TRUE; }
4987 | /*EMPTY*/ { $$ = FALSE; }
4991 CONCURRENTLY { $$ = TRUE; }
4992 | /*EMPTY*/ { $$ = FALSE; }
4996 index_name { $$ = $1; }
4997 | /*EMPTY*/ { $$ = NULL; }
5000 access_method_clause:
5001 USING access_method { $$ = $2; }
5002 | /*EMPTY*/ { $$ = DEFAULT_INDEX_TYPE; }
5005 index_params: index_elem { $$ = list_make1($1); }
5006 | index_params ',' index_elem { $$ = lappend($1, $3); }
5010 * Index attributes can be either simple column references, or arbitrary
5011 * expressions in parens. For backwards-compatibility reasons, we allow
5012 * an expression that's just a function call to be written without parens.
5014 index_elem: ColId opt_class opt_asc_desc opt_nulls_order
5016 $$ = makeNode(IndexElem);
5019 $$->indexcolname = NULL;
5022 $$->nulls_ordering = $4;
5024 | func_expr opt_class opt_asc_desc opt_nulls_order
5026 $$ = makeNode(IndexElem);
5029 $$->indexcolname = NULL;
5032 $$->nulls_ordering = $4;
5034 | '(' a_expr ')' opt_class opt_asc_desc opt_nulls_order
5036 $$ = makeNode(IndexElem);
5039 $$->indexcolname = NULL;
5042 $$->nulls_ordering = $6;
5046 opt_class: any_name { $$ = $1; }
5047 | USING any_name { $$ = $2; }
5048 | /*EMPTY*/ { $$ = NIL; }
5051 opt_asc_desc: ASC { $$ = SORTBY_ASC; }
5052 | DESC { $$ = SORTBY_DESC; }
5053 | /*EMPTY*/ { $$ = SORTBY_DEFAULT; }
5056 opt_nulls_order: NULLS_FIRST { $$ = SORTBY_NULLS_FIRST; }
5057 | NULLS_LAST { $$ = SORTBY_NULLS_LAST; }
5058 | /*EMPTY*/ { $$ = SORTBY_NULLS_DEFAULT; }
5062 /*****************************************************************************
5065 * create [or replace] function <fname>
5066 * [(<type-1> { , <type-n>})]
5068 * as <filename or code in language as appropriate>
5069 * language <lang> [with parameters]
5071 *****************************************************************************/
5074 CREATE opt_or_replace FUNCTION func_name func_args_with_defaults
5075 RETURNS func_return createfunc_opt_list opt_definition
5077 CreateFunctionStmt *n = makeNode(CreateFunctionStmt);
5086 | CREATE opt_or_replace FUNCTION func_name func_args_with_defaults
5087 RETURNS TABLE '(' table_func_column_list ')' createfunc_opt_list opt_definition
5089 CreateFunctionStmt *n = makeNode(CreateFunctionStmt);
5092 n->parameters = mergeTableFuncParameters($5, $9);
5093 n->returnType = TableFuncTypeName($9);
5094 n->returnType->location = @7;
5096 n->withClause = $12;
5099 | CREATE opt_or_replace FUNCTION func_name func_args_with_defaults
5100 createfunc_opt_list opt_definition
5102 CreateFunctionStmt *n = makeNode(CreateFunctionStmt);
5106 n->returnType = NULL;
5114 OR REPLACE { $$ = TRUE; }
5115 | /*EMPTY*/ { $$ = FALSE; }
5118 func_args: '(' func_args_list ')' { $$ = $2; }
5119 | '(' ')' { $$ = NIL; }
5123 func_arg { $$ = list_make1($1); }
5124 | func_args_list ',' func_arg { $$ = lappend($1, $3); }
5128 * func_args_with_defaults is separate because we only want to accept
5129 * defaults in CREATE FUNCTION, not in ALTER etc.
5131 func_args_with_defaults:
5132 '(' func_args_with_defaults_list ')' { $$ = $2; }
5133 | '(' ')' { $$ = NIL; }
5136 func_args_with_defaults_list:
5137 func_arg_with_default { $$ = list_make1($1); }
5138 | func_args_with_defaults_list ',' func_arg_with_default
5139 { $$ = lappend($1, $3); }
5143 * The style with arg_class first is SQL99 standard, but Oracle puts
5144 * param_name first; accept both since it's likely people will try both
5145 * anyway. Don't bother trying to save productions by letting arg_class
5146 * have an empty alternative ... you'll get shift/reduce conflicts.
5148 * We can catch over-specified arguments here if we want to,
5149 * but for now better to silently swallow typmod, etc.
5150 * - thomas 2000-03-22
5153 arg_class param_name func_type
5155 FunctionParameter *n = makeNode(FunctionParameter);
5162 | param_name arg_class func_type
5164 FunctionParameter *n = makeNode(FunctionParameter);
5171 | param_name func_type
5173 FunctionParameter *n = makeNode(FunctionParameter);
5176 n->mode = FUNC_PARAM_IN;
5180 | arg_class func_type
5182 FunctionParameter *n = makeNode(FunctionParameter);
5191 FunctionParameter *n = makeNode(FunctionParameter);
5194 n->mode = FUNC_PARAM_IN;
5200 /* INOUT is SQL99 standard, IN OUT is for Oracle compatibility */
5201 arg_class: IN_P { $$ = FUNC_PARAM_IN; }
5202 | OUT_P { $$ = FUNC_PARAM_OUT; }
5203 | INOUT { $$ = FUNC_PARAM_INOUT; }
5204 | IN_P OUT_P { $$ = FUNC_PARAM_INOUT; }
5205 | VARIADIC { $$ = FUNC_PARAM_VARIADIC; }
5209 * Ideally param_name should be ColId, but that causes too many conflicts.
5211 param_name: type_function_name
5217 /* We can catch over-specified results here if we want to,
5218 * but for now better to silently swallow typmod, etc.
5219 * - thomas 2000-03-22
5226 * We would like to make the %TYPE productions here be ColId attrs etc,
5227 * but that causes reduce/reduce conflicts. type_function_name
5228 * is next best choice.
5230 func_type: Typename { $$ = $1; }
5231 | type_function_name attrs '%' TYPE_P
5233 $$ = makeTypeNameFromNameList(lcons(makeString($1), $2));
5234 $$->pct_type = true;
5237 | SETOF type_function_name attrs '%' TYPE_P
5239 $$ = makeTypeNameFromNameList(lcons(makeString($2), $3));
5240 $$->pct_type = true;
5246 func_arg_with_default:
5251 | func_arg DEFAULT a_expr
5256 | func_arg '=' a_expr
5264 createfunc_opt_list:
5265 /* Must be at least one to prevent conflict */
5266 createfunc_opt_item { $$ = list_make1($1); }
5267 | createfunc_opt_list createfunc_opt_item { $$ = lappend($1, $2); }
5271 * Options common to both CREATE FUNCTION and ALTER FUNCTION
5273 common_func_opt_item:
5274 CALLED ON NULL_P INPUT_P
5276 $$ = makeDefElem("strict", (Node *)makeInteger(FALSE));
5278 | RETURNS NULL_P ON NULL_P INPUT_P
5280 $$ = makeDefElem("strict", (Node *)makeInteger(TRUE));
5284 $$ = makeDefElem("strict", (Node *)makeInteger(TRUE));
5288 $$ = makeDefElem("volatility", (Node *)makeString("immutable"));
5292 $$ = makeDefElem("volatility", (Node *)makeString("stable"));
5296 $$ = makeDefElem("volatility", (Node *)makeString("volatile"));
5298 | EXTERNAL SECURITY DEFINER
5300 $$ = makeDefElem("security", (Node *)makeInteger(TRUE));
5302 | EXTERNAL SECURITY INVOKER
5304 $$ = makeDefElem("security", (Node *)makeInteger(FALSE));
5308 $$ = makeDefElem("security", (Node *)makeInteger(TRUE));
5312 $$ = makeDefElem("security", (Node *)makeInteger(FALSE));
5316 $$ = makeDefElem("cost", (Node *)$2);
5320 $$ = makeDefElem("rows", (Node *)$2);
5324 /* we abuse the normal content of a DefElem here */
5325 $$ = makeDefElem("set", (Node *)$1);
5329 createfunc_opt_item:
5332 $$ = makeDefElem("as", (Node *)$2);
5334 | LANGUAGE ColId_or_Sconst
5336 $$ = makeDefElem("language", (Node *)makeString($2));
5340 $$ = makeDefElem("window", (Node *)makeInteger(TRUE));
5342 | common_func_opt_item
5348 func_as: Sconst { $$ = list_make1(makeString($1)); }
5351 $$ = list_make2(makeString($1), makeString($3));
5356 WITH definition { $$ = $2; }
5357 | /*EMPTY*/ { $$ = NIL; }
5360 table_func_column: param_name func_type
5362 FunctionParameter *n = makeNode(FunctionParameter);
5365 n->mode = FUNC_PARAM_TABLE;
5371 table_func_column_list:
5374 $$ = list_make1($1);
5376 | table_func_column_list ',' table_func_column
5378 $$ = lappend($1, $3);
5382 /*****************************************************************************
5385 * RENAME and OWNER subcommands are already provided by the generic
5386 * ALTER infrastructure, here we just specify alterations that can
5387 * only be applied to functions.
5389 *****************************************************************************/
5391 ALTER FUNCTION function_with_argtypes alterfunc_opt_list opt_restrict
5393 AlterFunctionStmt *n = makeNode(AlterFunctionStmt);
5401 /* At least one option must be specified */
5402 common_func_opt_item { $$ = list_make1($1); }
5403 | alterfunc_opt_list common_func_opt_item { $$ = lappend($1, $2); }
5406 /* Ignored, merely for SQL compliance */
5413 /*****************************************************************************
5417 * DROP FUNCTION funcname (arg1, arg2, ...) [ RESTRICT | CASCADE ]
5418 * DROP AGGREGATE aggname (arg1, ...) [ RESTRICT | CASCADE ]
5419 * DROP OPERATOR opname (leftoperand_typ, rightoperand_typ) [ RESTRICT | CASCADE ]
5421 *****************************************************************************/
5424 DROP FUNCTION func_name func_args opt_drop_behavior
5426 RemoveFuncStmt *n = makeNode(RemoveFuncStmt);
5427 n->kind = OBJECT_FUNCTION;
5429 n->args = extractArgTypes($4);
5431 n->missing_ok = false;
5434 | DROP FUNCTION IF_P EXISTS func_name func_args opt_drop_behavior
5436 RemoveFuncStmt *n = makeNode(RemoveFuncStmt);
5437 n->kind = OBJECT_FUNCTION;
5439 n->args = extractArgTypes($6);
5441 n->missing_ok = true;
5447 DROP AGGREGATE func_name aggr_args opt_drop_behavior
5449 RemoveFuncStmt *n = makeNode(RemoveFuncStmt);
5450 n->kind = OBJECT_AGGREGATE;
5454 n->missing_ok = false;
5457 | DROP AGGREGATE IF_P EXISTS func_name aggr_args opt_drop_behavior
5459 RemoveFuncStmt *n = makeNode(RemoveFuncStmt);
5460 n->kind = OBJECT_AGGREGATE;
5464 n->missing_ok = true;
5470 DROP OPERATOR any_operator oper_argtypes opt_drop_behavior
5472 RemoveFuncStmt *n = makeNode(RemoveFuncStmt);
5473 n->kind = OBJECT_OPERATOR;
5477 n->missing_ok = false;
5480 | DROP OPERATOR IF_P EXISTS any_operator oper_argtypes opt_drop_behavior
5482 RemoveFuncStmt *n = makeNode(RemoveFuncStmt);
5483 n->kind = OBJECT_OPERATOR;
5487 n->missing_ok = true;
5496 (errcode(ERRCODE_SYNTAX_ERROR),
5497 errmsg("missing argument"),
5498 errhint("Use NONE to denote the missing argument of a unary operator."),
5499 parser_errposition(@3)));
5501 | '(' Typename ',' Typename ')'
5502 { $$ = list_make2($2, $4); }
5503 | '(' NONE ',' Typename ')' /* left unary */
5504 { $$ = list_make2(NULL, $4); }
5505 | '(' Typename ',' NONE ')' /* right unary */
5506 { $$ = list_make2($2, NULL); }
5511 { $$ = list_make1(makeString($1)); }
5512 | ColId '.' any_operator
5513 { $$ = lcons(makeString($1), $3); }
5516 /*****************************************************************************
5518 * DO <anonymous code block> [ LANGUAGE language ]
5520 * We use a DefElem list for future extensibility, and to allow flexibility
5521 * in the clause order.
5523 *****************************************************************************/
5525 DoStmt: DO dostmt_opt_list
5527 DoStmt *n = makeNode(DoStmt);
5534 dostmt_opt_item { $$ = list_make1($1); }
5535 | dostmt_opt_list dostmt_opt_item { $$ = lappend($1, $2); }
5541 $$ = makeDefElem("as", (Node *)makeString($1));
5543 | LANGUAGE ColId_or_Sconst
5545 $$ = makeDefElem("language", (Node *)makeString($2));
5549 /*****************************************************************************
5551 * CREATE CAST / DROP CAST
5553 *****************************************************************************/
5555 CreateCastStmt: CREATE CAST '(' Typename AS Typename ')'
5556 WITH FUNCTION function_with_argtypes cast_context
5558 CreateCastStmt *n = makeNode(CreateCastStmt);
5562 n->context = (CoercionContext) $11;
5566 | CREATE CAST '(' Typename AS Typename ')'
5567 WITHOUT FUNCTION cast_context
5569 CreateCastStmt *n = makeNode(CreateCastStmt);
5573 n->context = (CoercionContext) $10;
5577 | CREATE CAST '(' Typename AS Typename ')'
5578 WITH INOUT cast_context
5580 CreateCastStmt *n = makeNode(CreateCastStmt);
5584 n->context = (CoercionContext) $10;
5590 cast_context: AS IMPLICIT_P { $$ = COERCION_IMPLICIT; }
5591 | AS ASSIGNMENT { $$ = COERCION_ASSIGNMENT; }
5592 | /*EMPTY*/ { $$ = COERCION_EXPLICIT; }
5596 DropCastStmt: DROP CAST opt_if_exists '(' Typename AS Typename ')' opt_drop_behavior
5598 DropCastStmt *n = makeNode(DropCastStmt);
5607 opt_if_exists: IF_P EXISTS { $$ = TRUE; }
5608 | /*EMPTY*/ { $$ = FALSE; }
5612 /*****************************************************************************
5616 * REINDEX type <name> [FORCE]
5618 * FORCE no longer does anything, but we accept it for backwards compatibility
5619 *****************************************************************************/
5622 REINDEX reindex_type qualified_name opt_force
5624 ReindexStmt *n = makeNode(ReindexStmt);
5630 | REINDEX SYSTEM_P name opt_force
5632 ReindexStmt *n = makeNode(ReindexStmt);
5633 n->kind = OBJECT_DATABASE;
5636 n->do_system = true;
5640 | REINDEX DATABASE name opt_force
5642 ReindexStmt *n = makeNode(ReindexStmt);
5643 n->kind = OBJECT_DATABASE;
5646 n->do_system = true;
5653 INDEX { $$ = OBJECT_INDEX; }
5654 | TABLE { $$ = OBJECT_TABLE; }
5657 opt_force: FORCE { $$ = TRUE; }
5658 | /* EMPTY */ { $$ = FALSE; }
5662 /*****************************************************************************
5664 * ALTER THING name RENAME TO newname
5666 *****************************************************************************/
5668 RenameStmt: ALTER AGGREGATE func_name aggr_args RENAME TO name
5670 RenameStmt *n = makeNode(RenameStmt);
5671 n->renameType = OBJECT_AGGREGATE;
5677 | ALTER CONVERSION_P any_name RENAME TO name
5679 RenameStmt *n = makeNode(RenameStmt);
5680 n->renameType = OBJECT_CONVERSION;
5685 | ALTER DATABASE database_name RENAME TO database_name
5687 RenameStmt *n = makeNode(RenameStmt);
5688 n->renameType = OBJECT_DATABASE;
5693 | ALTER FUNCTION function_with_argtypes RENAME TO name
5695 RenameStmt *n = makeNode(RenameStmt);
5696 n->renameType = OBJECT_FUNCTION;
5697 n->object = $3->funcname;
5698 n->objarg = $3->funcargs;
5702 | ALTER GROUP_P RoleId RENAME TO RoleId
5704 RenameStmt *n = makeNode(RenameStmt);
5705 n->renameType = OBJECT_ROLE;
5710 | ALTER opt_procedural LANGUAGE name RENAME TO name
5712 RenameStmt *n = makeNode(RenameStmt);
5713 n->renameType = OBJECT_LANGUAGE;
5718 | ALTER OPERATOR CLASS any_name USING access_method RENAME TO name
5720 RenameStmt *n = makeNode(RenameStmt);
5721 n->renameType = OBJECT_OPCLASS;
5727 | ALTER OPERATOR FAMILY any_name USING access_method RENAME TO name
5729 RenameStmt *n = makeNode(RenameStmt);
5730 n->renameType = OBJECT_OPFAMILY;
5736 | ALTER SCHEMA name RENAME TO name
5738 RenameStmt *n = makeNode(RenameStmt);
5739 n->renameType = OBJECT_SCHEMA;
5744 | ALTER TABLE relation_expr RENAME TO name
5746 RenameStmt *n = makeNode(RenameStmt);
5747 n->renameType = OBJECT_TABLE;
5753 | ALTER SEQUENCE qualified_name RENAME TO name
5755 RenameStmt *n = makeNode(RenameStmt);
5756 n->renameType = OBJECT_SEQUENCE;
5762 | ALTER VIEW qualified_name RENAME TO name
5764 RenameStmt *n = makeNode(RenameStmt);
5765 n->renameType = OBJECT_VIEW;
5771 | ALTER INDEX qualified_name RENAME TO name
5773 RenameStmt *n = makeNode(RenameStmt);
5774 n->renameType = OBJECT_INDEX;
5780 | ALTER TABLE relation_expr RENAME opt_column name TO name
5782 RenameStmt *n = makeNode(RenameStmt);
5783 n->renameType = OBJECT_COLUMN;
5789 | ALTER TRIGGER name ON qualified_name RENAME TO name
5791 RenameStmt *n = makeNode(RenameStmt);
5792 n->renameType = OBJECT_TRIGGER;
5798 | ALTER ROLE RoleId RENAME TO RoleId
5800 RenameStmt *n = makeNode(RenameStmt);
5801 n->renameType = OBJECT_ROLE;
5806 | ALTER USER RoleId RENAME TO RoleId
5808 RenameStmt *n = makeNode(RenameStmt);
5809 n->renameType = OBJECT_ROLE;
5814 | ALTER TABLESPACE name RENAME TO name
5816 RenameStmt *n = makeNode(RenameStmt);
5817 n->renameType = OBJECT_TABLESPACE;
5822 | ALTER TABLESPACE name SET reloptions
5824 AlterTableSpaceOptionsStmt *n =
5825 makeNode(AlterTableSpaceOptionsStmt);
5826 n->tablespacename = $3;
5831 | ALTER TABLESPACE name RESET reloptions
5833 AlterTableSpaceOptionsStmt *n =
5834 makeNode(AlterTableSpaceOptionsStmt);
5835 n->tablespacename = $3;
5840 | ALTER TEXT_P SEARCH PARSER any_name RENAME TO name
5842 RenameStmt *n = makeNode(RenameStmt);
5843 n->renameType = OBJECT_TSPARSER;
5848 | ALTER TEXT_P SEARCH DICTIONARY any_name RENAME TO name
5850 RenameStmt *n = makeNode(RenameStmt);
5851 n->renameType = OBJECT_TSDICTIONARY;
5856 | ALTER TEXT_P SEARCH TEMPLATE any_name RENAME TO name
5858 RenameStmt *n = makeNode(RenameStmt);
5859 n->renameType = OBJECT_TSTEMPLATE;
5864 | ALTER TEXT_P SEARCH CONFIGURATION any_name RENAME TO name
5866 RenameStmt *n = makeNode(RenameStmt);
5867 n->renameType = OBJECT_TSCONFIGURATION;
5872 | ALTER TYPE_P any_name RENAME TO name
5874 RenameStmt *n = makeNode(RenameStmt);
5875 n->renameType = OBJECT_TYPE;
5880 | ALTER TYPE_P any_name RENAME ATTRIBUTE name TO name
5882 RenameStmt *n = makeNode(RenameStmt);
5883 n->renameType = OBJECT_ATTRIBUTE;
5884 n->relation = makeRangeVarFromAnyName($3, @3, yyscanner);
5891 opt_column: COLUMN { $$ = COLUMN; }
5892 | /*EMPTY*/ { $$ = 0; }
5895 opt_set_data: SET DATA_P { $$ = 1; }
5896 | /*EMPTY*/ { $$ = 0; }
5899 /*****************************************************************************
5901 * ALTER THING name SET SCHEMA name
5903 *****************************************************************************/
5905 AlterObjectSchemaStmt:
5906 ALTER AGGREGATE func_name aggr_args SET SCHEMA name
5908 AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
5909 n->objectType = OBJECT_AGGREGATE;
5915 | ALTER DOMAIN_P any_name SET SCHEMA name
5917 AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
5918 n->objectType = OBJECT_DOMAIN;
5923 | ALTER FUNCTION function_with_argtypes SET SCHEMA name
5925 AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
5926 n->objectType = OBJECT_FUNCTION;
5927 n->object = $3->funcname;
5928 n->objarg = $3->funcargs;
5932 | ALTER TABLE relation_expr SET SCHEMA name
5934 AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
5935 n->objectType = OBJECT_TABLE;
5940 | ALTER SEQUENCE qualified_name SET SCHEMA name
5942 AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
5943 n->objectType = OBJECT_SEQUENCE;
5948 | ALTER VIEW qualified_name SET SCHEMA name
5950 AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
5951 n->objectType = OBJECT_VIEW;
5956 | ALTER TYPE_P any_name SET SCHEMA name
5958 AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
5959 n->objectType = OBJECT_TYPE;
5966 /*****************************************************************************
5968 * ALTER THING name OWNER TO newname
5970 *****************************************************************************/
5972 AlterOwnerStmt: ALTER AGGREGATE func_name aggr_args OWNER TO RoleId
5974 AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
5975 n->objectType = OBJECT_AGGREGATE;
5981 | ALTER CONVERSION_P any_name OWNER TO RoleId
5983 AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
5984 n->objectType = OBJECT_CONVERSION;
5989 | ALTER DATABASE database_name OWNER TO RoleId
5991 AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
5992 n->objectType = OBJECT_DATABASE;
5993 n->object = list_make1(makeString($3));
5997 | ALTER DOMAIN_P any_name OWNER TO RoleId
5999 AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
6000 n->objectType = OBJECT_DOMAIN;
6005 | ALTER FUNCTION function_with_argtypes OWNER TO RoleId
6007 AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
6008 n->objectType = OBJECT_FUNCTION;
6009 n->object = $3->funcname;
6010 n->objarg = $3->funcargs;
6014 | ALTER opt_procedural LANGUAGE name OWNER TO RoleId
6016 AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
6017 n->objectType = OBJECT_LANGUAGE;
6018 n->object = list_make1(makeString($4));
6022 | ALTER LARGE_P OBJECT_P NumericOnly OWNER TO RoleId
6024 AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
6025 n->objectType = OBJECT_LARGEOBJECT;
6026 n->object = list_make1($4);
6030 | ALTER OPERATOR any_operator oper_argtypes OWNER TO RoleId
6032 AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
6033 n->objectType = OBJECT_OPERATOR;
6039 | ALTER OPERATOR CLASS any_name USING access_method OWNER TO RoleId
6041 AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
6042 n->objectType = OBJECT_OPCLASS;
6048 | ALTER OPERATOR FAMILY any_name USING access_method OWNER TO RoleId
6050 AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
6051 n->objectType = OBJECT_OPFAMILY;
6057 | ALTER SCHEMA name OWNER TO RoleId
6059 AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
6060 n->objectType = OBJECT_SCHEMA;
6061 n->object = list_make1(makeString($3));
6065 | ALTER TYPE_P any_name OWNER TO RoleId
6067 AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
6068 n->objectType = OBJECT_TYPE;
6073 | ALTER TABLESPACE name OWNER TO RoleId
6075 AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
6076 n->objectType = OBJECT_TABLESPACE;
6077 n->object = list_make1(makeString($3));
6081 | ALTER TEXT_P SEARCH DICTIONARY any_name OWNER TO RoleId
6083 AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
6084 n->objectType = OBJECT_TSDICTIONARY;
6089 | ALTER TEXT_P SEARCH CONFIGURATION any_name OWNER TO RoleId
6091 AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
6092 n->objectType = OBJECT_TSCONFIGURATION;
6097 | ALTER FOREIGN DATA_P WRAPPER name OWNER TO RoleId
6099 AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
6100 n->objectType = OBJECT_FDW;
6101 n->object = list_make1(makeString($5));
6105 | ALTER SERVER name OWNER TO RoleId
6107 AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
6108 n->objectType = OBJECT_FOREIGN_SERVER;
6109 n->object = list_make1(makeString($3));
6116 /*****************************************************************************
6118 * QUERY: Define Rewrite Rule
6120 *****************************************************************************/
6122 RuleStmt: CREATE opt_or_replace RULE name AS
6123 ON event TO qualified_name where_clause
6124 DO opt_instead RuleActionList
6126 RuleStmt *n = makeNode(RuleStmt);
6130 n->whereClause = $10;
6139 NOTHING { $$ = NIL; }
6140 | RuleActionStmt { $$ = list_make1($1); }
6141 | '(' RuleActionMulti ')' { $$ = $2; }
6144 /* the thrashing around here is to discard "empty" statements... */
6146 RuleActionMulti ';' RuleActionStmtOrEmpty
6148 $$ = lappend($1, $3);
6152 | RuleActionStmtOrEmpty
6154 $$ = list_make1($1);
6168 RuleActionStmtOrEmpty:
6169 RuleActionStmt { $$ = $1; }
6170 | /*EMPTY*/ { $$ = NULL; }
6173 event: SELECT { $$ = CMD_SELECT; }
6174 | UPDATE { $$ = CMD_UPDATE; }
6175 | DELETE_P { $$ = CMD_DELETE; }
6176 | INSERT { $$ = CMD_INSERT; }
6180 INSTEAD { $$ = TRUE; }
6181 | ALSO { $$ = FALSE; }
6182 | /*EMPTY*/ { $$ = FALSE; }
6187 DROP RULE name ON qualified_name opt_drop_behavior
6189 DropPropertyStmt *n = makeNode(DropPropertyStmt);
6193 n->removeType = OBJECT_RULE;
6194 n->missing_ok = false;
6197 | DROP RULE IF_P EXISTS name ON qualified_name opt_drop_behavior
6199 DropPropertyStmt *n = makeNode(DropPropertyStmt);
6203 n->removeType = OBJECT_RULE;
6204 n->missing_ok = true;
6210 /*****************************************************************************
6213 * NOTIFY <identifier> can appear both in rule bodies and
6214 * as a query-level command
6216 *****************************************************************************/
6218 NotifyStmt: NOTIFY ColId notify_payload
6220 NotifyStmt *n = makeNode(NotifyStmt);
6221 n->conditionname = $2;
6228 ',' Sconst { $$ = $2; }
6229 | /*EMPTY*/ { $$ = NULL; }
6232 ListenStmt: LISTEN ColId
6234 ListenStmt *n = makeNode(ListenStmt);
6235 n->conditionname = $2;
6243 UnlistenStmt *n = makeNode(UnlistenStmt);
6244 n->conditionname = $2;
6249 UnlistenStmt *n = makeNode(UnlistenStmt);
6250 n->conditionname = NULL;
6256 /*****************************************************************************
6260 * BEGIN / COMMIT / ROLLBACK
6261 * (also older versions END / ABORT)
6263 *****************************************************************************/
6266 ABORT_P opt_transaction
6268 TransactionStmt *n = makeNode(TransactionStmt);
6269 n->kind = TRANS_STMT_ROLLBACK;
6273 | BEGIN_P opt_transaction transaction_mode_list_or_empty
6275 TransactionStmt *n = makeNode(TransactionStmt);
6276 n->kind = TRANS_STMT_BEGIN;
6280 | START TRANSACTION transaction_mode_list_or_empty
6282 TransactionStmt *n = makeNode(TransactionStmt);
6283 n->kind = TRANS_STMT_START;
6287 | COMMIT opt_transaction
6289 TransactionStmt *n = makeNode(TransactionStmt);
6290 n->kind = TRANS_STMT_COMMIT;
6294 | END_P opt_transaction
6296 TransactionStmt *n = makeNode(TransactionStmt);
6297 n->kind = TRANS_STMT_COMMIT;
6301 | ROLLBACK opt_transaction
6303 TransactionStmt *n = makeNode(TransactionStmt);
6304 n->kind = TRANS_STMT_ROLLBACK;
6310 TransactionStmt *n = makeNode(TransactionStmt);
6311 n->kind = TRANS_STMT_SAVEPOINT;
6312 n->options = list_make1(makeDefElem("savepoint_name",
6313 (Node *)makeString($2)));
6316 | RELEASE SAVEPOINT ColId
6318 TransactionStmt *n = makeNode(TransactionStmt);
6319 n->kind = TRANS_STMT_RELEASE;
6320 n->options = list_make1(makeDefElem("savepoint_name",
6321 (Node *)makeString($3)));
6326 TransactionStmt *n = makeNode(TransactionStmt);
6327 n->kind = TRANS_STMT_RELEASE;
6328 n->options = list_make1(makeDefElem("savepoint_name",
6329 (Node *)makeString($2)));
6332 | ROLLBACK opt_transaction TO SAVEPOINT ColId
6334 TransactionStmt *n = makeNode(TransactionStmt);
6335 n->kind = TRANS_STMT_ROLLBACK_TO;
6336 n->options = list_make1(makeDefElem("savepoint_name",
6337 (Node *)makeString($5)));
6340 | ROLLBACK opt_transaction TO ColId
6342 TransactionStmt *n = makeNode(TransactionStmt);
6343 n->kind = TRANS_STMT_ROLLBACK_TO;
6344 n->options = list_make1(makeDefElem("savepoint_name",
6345 (Node *)makeString($4)));
6348 | PREPARE TRANSACTION Sconst
6350 TransactionStmt *n = makeNode(TransactionStmt);
6351 n->kind = TRANS_STMT_PREPARE;
6355 | COMMIT PREPARED Sconst
6357 TransactionStmt *n = makeNode(TransactionStmt);
6358 n->kind = TRANS_STMT_COMMIT_PREPARED;
6362 | ROLLBACK PREPARED Sconst
6364 TransactionStmt *n = makeNode(TransactionStmt);
6365 n->kind = TRANS_STMT_ROLLBACK_PREPARED;
6371 opt_transaction: WORK {}
6376 transaction_mode_item:
6377 ISOLATION LEVEL iso_level
6378 { $$ = makeDefElem("transaction_isolation",
6379 makeStringConst($3, @3)); }
6381 { $$ = makeDefElem("transaction_read_only",
6382 makeIntConst(TRUE, @1)); }
6384 { $$ = makeDefElem("transaction_read_only",
6385 makeIntConst(FALSE, @1)); }
6388 /* Syntax with commas is SQL-spec, without commas is Postgres historical */
6389 transaction_mode_list:
6390 transaction_mode_item
6391 { $$ = list_make1($1); }
6392 | transaction_mode_list ',' transaction_mode_item
6393 { $$ = lappend($1, $3); }
6394 | transaction_mode_list transaction_mode_item
6395 { $$ = lappend($1, $2); }
6398 transaction_mode_list_or_empty:
6399 transaction_mode_list
6405 /*****************************************************************************
6408 * CREATE [ OR REPLACE ] [ TEMP ] VIEW <viewname> '('target-list ')'
6409 * AS <query> [ WITH [ CASCADED | LOCAL ] CHECK OPTION ]
6411 *****************************************************************************/
6413 ViewStmt: CREATE OptTemp VIEW qualified_name opt_column_list
6414 AS SelectStmt opt_check_option
6416 ViewStmt *n = makeNode(ViewStmt);
6418 n->view->istemp = $2;
6424 | CREATE OR REPLACE OptTemp VIEW qualified_name opt_column_list
6425 AS SelectStmt opt_check_option
6427 ViewStmt *n = makeNode(ViewStmt);
6429 n->view->istemp = $4;
6441 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
6442 errmsg("WITH CHECK OPTION is not implemented")));
6444 | WITH CASCADED CHECK OPTION
6447 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
6448 errmsg("WITH CHECK OPTION is not implemented")));
6450 | WITH LOCAL CHECK OPTION
6453 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
6454 errmsg("WITH CHECK OPTION is not implemented")));
6456 | /* EMPTY */ { $$ = NIL; }
6459 /*****************************************************************************
6464 *****************************************************************************/
6466 LoadStmt: LOAD file_name
6468 LoadStmt *n = makeNode(LoadStmt);
6475 /*****************************************************************************
6479 *****************************************************************************/
6482 CREATE DATABASE database_name opt_with createdb_opt_list
6484 CreatedbStmt *n = makeNode(CreatedbStmt);
6492 createdb_opt_list createdb_opt_item { $$ = lappend($1, $2); }
6493 | /* EMPTY */ { $$ = NIL; }
6497 TABLESPACE opt_equal name
6499 $$ = makeDefElem("tablespace", (Node *)makeString($3));
6501 | TABLESPACE opt_equal DEFAULT
6503 $$ = makeDefElem("tablespace", NULL);
6505 | LOCATION opt_equal Sconst
6507 $$ = makeDefElem("location", (Node *)makeString($3));
6509 | LOCATION opt_equal DEFAULT
6511 $$ = makeDefElem("location", NULL);
6513 | TEMPLATE opt_equal name
6515 $$ = makeDefElem("template", (Node *)makeString($3));
6517 | TEMPLATE opt_equal DEFAULT
6519 $$ = makeDefElem("template", NULL);
6521 | ENCODING opt_equal Sconst
6523 $$ = makeDefElem("encoding", (Node *)makeString($3));
6525 | ENCODING opt_equal Iconst
6527 $$ = makeDefElem("encoding", (Node *)makeInteger($3));
6529 | ENCODING opt_equal DEFAULT
6531 $$ = makeDefElem("encoding", NULL);
6533 | LC_COLLATE_P opt_equal Sconst
6535 $$ = makeDefElem("lc_collate", (Node *)makeString($3));
6537 | LC_COLLATE_P opt_equal DEFAULT
6539 $$ = makeDefElem("lc_collate", NULL);
6541 | LC_CTYPE_P opt_equal Sconst
6543 $$ = makeDefElem("lc_ctype", (Node *)makeString($3));
6545 | LC_CTYPE_P opt_equal DEFAULT
6547 $$ = makeDefElem("lc_ctype", NULL);
6549 | CONNECTION LIMIT opt_equal SignedIconst
6551 $$ = makeDefElem("connectionlimit", (Node *)makeInteger($4));
6553 | OWNER opt_equal name
6555 $$ = makeDefElem("owner", (Node *)makeString($3));
6557 | OWNER opt_equal DEFAULT
6559 $$ = makeDefElem("owner", NULL);
6564 * Though the equals sign doesn't match other WITH options, pg_dump uses
6565 * equals for backward compatibility, and it doesn't seem worth removing it.
6572 /*****************************************************************************
6576 *****************************************************************************/
6579 ALTER DATABASE database_name opt_with alterdb_opt_list
6581 AlterDatabaseStmt *n = makeNode(AlterDatabaseStmt);
6586 | ALTER DATABASE database_name SET TABLESPACE name
6588 AlterDatabaseStmt *n = makeNode(AlterDatabaseStmt);
6590 n->options = list_make1(makeDefElem("tablespace",
6591 (Node *)makeString($6)));
6596 AlterDatabaseSetStmt:
6597 ALTER DATABASE database_name SetResetClause
6599 AlterDatabaseSetStmt *n = makeNode(AlterDatabaseSetStmt);
6608 alterdb_opt_list alterdb_opt_item { $$ = lappend($1, $2); }
6609 | /* EMPTY */ { $$ = NIL; }
6613 CONNECTION LIMIT opt_equal SignedIconst
6615 $$ = makeDefElem("connectionlimit", (Node *)makeInteger($4));
6620 /*****************************************************************************
6622 * DROP DATABASE [ IF EXISTS ]
6624 * This is implicitly CASCADE, no need for drop behavior
6625 *****************************************************************************/
6627 DropdbStmt: DROP DATABASE database_name
6629 DropdbStmt *n = makeNode(DropdbStmt);
6631 n->missing_ok = FALSE;
6634 | DROP DATABASE IF_P EXISTS database_name
6636 DropdbStmt *n = makeNode(DropdbStmt);
6638 n->missing_ok = TRUE;
6644 /*****************************************************************************
6646 * Manipulate a domain
6648 *****************************************************************************/
6651 CREATE DOMAIN_P any_name opt_as Typename ColQualList
6653 CreateDomainStmt *n = makeNode(CreateDomainStmt);
6656 n->constraints = $6;
6662 /* ALTER DOMAIN <domain> {SET DEFAULT <expr>|DROP DEFAULT} */
6663 ALTER DOMAIN_P any_name alter_column_default
6665 AlterDomainStmt *n = makeNode(AlterDomainStmt);
6671 /* ALTER DOMAIN <domain> DROP NOT NULL */
6672 | ALTER DOMAIN_P any_name DROP NOT NULL_P
6674 AlterDomainStmt *n = makeNode(AlterDomainStmt);
6679 /* ALTER DOMAIN <domain> SET NOT NULL */
6680 | ALTER DOMAIN_P any_name SET NOT NULL_P
6682 AlterDomainStmt *n = makeNode(AlterDomainStmt);
6687 /* ALTER DOMAIN <domain> ADD CONSTRAINT ... */
6688 | ALTER DOMAIN_P any_name ADD_P TableConstraint
6690 AlterDomainStmt *n = makeNode(AlterDomainStmt);
6696 /* ALTER DOMAIN <domain> DROP CONSTRAINT <name> [RESTRICT|CASCADE] */
6697 | ALTER DOMAIN_P any_name DROP CONSTRAINT name opt_drop_behavior
6699 AlterDomainStmt *n = makeNode(AlterDomainStmt);
6713 /*****************************************************************************
6715 * Manipulate a text search dictionary or configuration
6717 *****************************************************************************/
6719 AlterTSDictionaryStmt:
6720 ALTER TEXT_P SEARCH DICTIONARY any_name definition
6722 AlterTSDictionaryStmt *n = makeNode(AlterTSDictionaryStmt);
6729 AlterTSConfigurationStmt:
6730 ALTER TEXT_P SEARCH CONFIGURATION any_name ADD_P MAPPING FOR name_list WITH any_name_list
6732 AlterTSConfigurationStmt *n = makeNode(AlterTSConfigurationStmt);
6736 n->override = false;
6740 | ALTER TEXT_P SEARCH CONFIGURATION any_name ALTER MAPPING FOR name_list WITH any_name_list
6742 AlterTSConfigurationStmt *n = makeNode(AlterTSConfigurationStmt);
6750 | ALTER TEXT_P SEARCH CONFIGURATION any_name ALTER MAPPING REPLACE any_name WITH any_name
6752 AlterTSConfigurationStmt *n = makeNode(AlterTSConfigurationStmt);
6755 n->dicts = list_make2($9,$11);
6756 n->override = false;
6760 | ALTER TEXT_P SEARCH CONFIGURATION any_name ALTER MAPPING FOR name_list REPLACE any_name WITH any_name
6762 AlterTSConfigurationStmt *n = makeNode(AlterTSConfigurationStmt);
6765 n->dicts = list_make2($11,$13);
6766 n->override = false;
6770 | ALTER TEXT_P SEARCH CONFIGURATION any_name DROP MAPPING FOR name_list
6772 AlterTSConfigurationStmt *n = makeNode(AlterTSConfigurationStmt);
6775 n->missing_ok = false;
6778 | ALTER TEXT_P SEARCH CONFIGURATION any_name DROP MAPPING IF_P EXISTS FOR name_list
6780 AlterTSConfigurationStmt *n = makeNode(AlterTSConfigurationStmt);
6783 n->missing_ok = true;
6789 /*****************************************************************************
6791 * Manipulate a conversion
6793 * CREATE [DEFAULT] CONVERSION <conversion_name>
6794 * FOR <encoding_name> TO <encoding_name> FROM <func_name>
6796 *****************************************************************************/
6798 CreateConversionStmt:
6799 CREATE opt_default CONVERSION_P any_name FOR Sconst
6800 TO Sconst FROM any_name
6802 CreateConversionStmt *n = makeNode(CreateConversionStmt);
6803 n->conversion_name = $4;
6804 n->for_encoding_name = $6;
6805 n->to_encoding_name = $8;
6812 /*****************************************************************************
6815 * CLUSTER [VERBOSE] <qualified_name> [ USING <index_name> ]
6817 * CLUSTER [VERBOSE] <index_name> ON <qualified_name> (for pre-8.3)
6819 *****************************************************************************/
6822 CLUSTER opt_verbose qualified_name cluster_index_specification
6824 ClusterStmt *n = makeNode(ClusterStmt);
6830 | CLUSTER opt_verbose
6832 ClusterStmt *n = makeNode(ClusterStmt);
6834 n->indexname = NULL;
6838 /* kept for pre-8.3 compatibility */
6839 | CLUSTER opt_verbose index_name ON qualified_name
6841 ClusterStmt *n = makeNode(ClusterStmt);
6849 cluster_index_specification:
6850 USING index_name { $$ = $2; }
6851 | /*EMPTY*/ { $$ = NULL; }
6855 /*****************************************************************************
6861 *****************************************************************************/
6863 VacuumStmt: VACUUM opt_full opt_freeze opt_verbose
6865 VacuumStmt *n = makeNode(VacuumStmt);
6866 n->options = VACOPT_VACUUM;
6868 n->options |= VACOPT_FULL;
6870 n->options |= VACOPT_VERBOSE;
6871 n->freeze_min_age = $3 ? 0 : -1;
6872 n->freeze_table_age = $3 ? 0 : -1;
6877 | VACUUM opt_full opt_freeze opt_verbose qualified_name
6879 VacuumStmt *n = makeNode(VacuumStmt);
6880 n->options = VACOPT_VACUUM;
6882 n->options |= VACOPT_FULL;
6884 n->options |= VACOPT_VERBOSE;
6885 n->freeze_min_age = $3 ? 0 : -1;
6886 n->freeze_table_age = $3 ? 0 : -1;
6891 | VACUUM opt_full opt_freeze opt_verbose AnalyzeStmt
6893 VacuumStmt *n = (VacuumStmt *) $5;
6894 n->options |= VACOPT_VACUUM;
6896 n->options |= VACOPT_FULL;
6898 n->options |= VACOPT_VERBOSE;
6899 n->freeze_min_age = $3 ? 0 : -1;
6900 n->freeze_table_age = $3 ? 0 : -1;
6903 | VACUUM '(' vacuum_option_list ')'
6905 VacuumStmt *n = makeNode(VacuumStmt);
6906 n->options = VACOPT_VACUUM | $3;
6907 if (n->options & VACOPT_FREEZE)
6908 n->freeze_min_age = n->freeze_table_age = 0;
6910 n->freeze_min_age = n->freeze_table_age = -1;
6915 | VACUUM '(' vacuum_option_list ')' qualified_name opt_name_list
6917 VacuumStmt *n = makeNode(VacuumStmt);
6918 n->options = VACOPT_VACUUM | $3;
6919 if (n->options & VACOPT_FREEZE)
6920 n->freeze_min_age = n->freeze_table_age = 0;
6922 n->freeze_min_age = n->freeze_table_age = -1;
6925 if (n->va_cols != NIL) /* implies analyze */
6926 n->options |= VACOPT_ANALYZE;
6932 vacuum_option_elem { $$ = $1; }
6933 | vacuum_option_list ',' vacuum_option_elem { $$ = $1 | $3; }
6937 analyze_keyword { $$ = VACOPT_ANALYZE; }
6938 | VERBOSE { $$ = VACOPT_VERBOSE; }
6939 | FREEZE { $$ = VACOPT_FREEZE; }
6940 | FULL { $$ = VACOPT_FULL; }
6944 analyze_keyword opt_verbose
6946 VacuumStmt *n = makeNode(VacuumStmt);
6947 n->options = VACOPT_ANALYZE;
6949 n->options |= VACOPT_VERBOSE;
6950 n->freeze_min_age = -1;
6951 n->freeze_table_age = -1;
6956 | analyze_keyword opt_verbose qualified_name opt_name_list
6958 VacuumStmt *n = makeNode(VacuumStmt);
6959 n->options = VACOPT_ANALYZE;
6961 n->options |= VACOPT_VERBOSE;
6962 n->freeze_min_age = -1;
6963 n->freeze_table_age = -1;
6972 | ANALYSE /* British */ {}
6976 VERBOSE { $$ = TRUE; }
6977 | /*EMPTY*/ { $$ = FALSE; }
6980 opt_full: FULL { $$ = TRUE; }
6981 | /*EMPTY*/ { $$ = FALSE; }
6984 opt_freeze: FREEZE { $$ = TRUE; }
6985 | /*EMPTY*/ { $$ = FALSE; }
6989 '(' name_list ')' { $$ = $2; }
6990 | /*EMPTY*/ { $$ = NIL; }
6994 /*****************************************************************************
6997 * EXPLAIN [ANALYZE] [VERBOSE] query
6998 * EXPLAIN ( options ) query
7000 *****************************************************************************/
7003 EXPLAIN ExplainableStmt
7005 ExplainStmt *n = makeNode(ExplainStmt);
7010 | EXPLAIN analyze_keyword opt_verbose ExplainableStmt
7012 ExplainStmt *n = makeNode(ExplainStmt);
7014 n->options = list_make1(makeDefElem("analyze", NULL));
7016 n->options = lappend(n->options,
7017 makeDefElem("verbose", NULL));
7020 | EXPLAIN VERBOSE ExplainableStmt
7022 ExplainStmt *n = makeNode(ExplainStmt);
7024 n->options = list_make1(makeDefElem("verbose", NULL));
7027 | EXPLAIN '(' explain_option_list ')' ExplainableStmt
7029 ExplainStmt *n = makeNode(ExplainStmt);
7043 | ExecuteStmt /* by default all are $$=$1 */
7046 explain_option_list:
7049 $$ = list_make1($1);
7051 | explain_option_list ',' explain_option_elem
7053 $$ = lappend($1, $3);
7057 explain_option_elem:
7058 explain_option_name explain_option_arg
7060 $$ = makeDefElem($1, $2);
7064 explain_option_name:
7066 | analyze_keyword { $$ = "analyze"; }
7067 | VERBOSE { $$ = "verbose"; }
7071 opt_boolean { $$ = (Node *) makeString($1); }
7072 | ColId_or_Sconst { $$ = (Node *) makeString($1); }
7073 | NumericOnly { $$ = (Node *) $1; }
7074 | /* EMPTY */ { $$ = NULL; }
7077 /*****************************************************************************
7080 * PREPARE <plan_name> [(args, ...)] AS <query>
7082 *****************************************************************************/
7084 PrepareStmt: PREPARE name prep_type_clause AS PreparableStmt
7086 PrepareStmt *n = makeNode(PrepareStmt);
7094 prep_type_clause: '(' type_list ')' { $$ = $2; }
7095 | /* EMPTY */ { $$ = NIL; }
7102 | DeleteStmt /* by default all are $$=$1 */
7105 /*****************************************************************************
7107 * EXECUTE <plan_name> [(params, ...)]
7108 * CREATE TABLE <name> AS EXECUTE <plan_name> [(params, ...)]
7110 *****************************************************************************/
7112 ExecuteStmt: EXECUTE name execute_param_clause
7114 ExecuteStmt *n = makeNode(ExecuteStmt);
7120 | CREATE OptTemp TABLE create_as_target AS
7121 EXECUTE name execute_param_clause
7123 ExecuteStmt *n = makeNode(ExecuteStmt);
7126 $4->rel->istemp = $2;
7130 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
7131 errmsg("column name list not allowed in CREATE TABLE / AS EXECUTE")));
7132 /* ... because it's not implemented, but it could be */
7137 execute_param_clause: '(' expr_list ')' { $$ = $2; }
7138 | /* EMPTY */ { $$ = NIL; }
7141 /*****************************************************************************
7144 * DEALLOCATE [PREPARE] <plan_name>
7146 *****************************************************************************/
7148 DeallocateStmt: DEALLOCATE name
7150 DeallocateStmt *n = makeNode(DeallocateStmt);
7154 | DEALLOCATE PREPARE name
7156 DeallocateStmt *n = makeNode(DeallocateStmt);
7162 DeallocateStmt *n = makeNode(DeallocateStmt);
7166 | DEALLOCATE PREPARE ALL
7168 DeallocateStmt *n = makeNode(DeallocateStmt);
7174 /*****************************************************************************
7179 *****************************************************************************/
7182 INSERT INTO qualified_name insert_rest returning_clause
7185 $4->returningList = $5;
7193 $$ = makeNode(InsertStmt);
7195 $$->selectStmt = $1;
7197 | '(' insert_column_list ')' SelectStmt
7199 $$ = makeNode(InsertStmt);
7201 $$->selectStmt = $4;
7205 $$ = makeNode(InsertStmt);
7207 $$->selectStmt = NULL;
7213 { $$ = list_make1($1); }
7214 | insert_column_list ',' insert_column_item
7215 { $$ = lappend($1, $3); }
7219 ColId opt_indirection
7221 $$ = makeNode(ResTarget);
7223 $$->indirection = check_indirection($2, yyscanner);
7230 RETURNING target_list { $$ = $2; }
7231 | /* EMPTY */ { $$ = NIL; }
7235 /*****************************************************************************
7240 *****************************************************************************/
7242 DeleteStmt: DELETE_P FROM relation_expr_opt_alias
7243 using_clause where_or_current_clause returning_clause
7245 DeleteStmt *n = makeNode(DeleteStmt);
7247 n->usingClause = $4;
7248 n->whereClause = $5;
7249 n->returningList = $6;
7255 USING from_list { $$ = $2; }
7256 | /*EMPTY*/ { $$ = NIL; }
7260 /*****************************************************************************
7265 *****************************************************************************/
7267 LockStmt: LOCK_P opt_table relation_expr_list opt_lock opt_nowait
7269 LockStmt *n = makeNode(LockStmt);
7278 opt_lock: IN_P lock_type MODE { $$ = $2; }
7279 | /*EMPTY*/ { $$ = AccessExclusiveLock; }
7282 lock_type: ACCESS SHARE { $$ = AccessShareLock; }
7283 | ROW SHARE { $$ = RowShareLock; }
7284 | ROW EXCLUSIVE { $$ = RowExclusiveLock; }
7285 | SHARE UPDATE EXCLUSIVE { $$ = ShareUpdateExclusiveLock; }
7286 | SHARE { $$ = ShareLock; }
7287 | SHARE ROW EXCLUSIVE { $$ = ShareRowExclusiveLock; }
7288 | EXCLUSIVE { $$ = ExclusiveLock; }
7289 | ACCESS EXCLUSIVE { $$ = AccessExclusiveLock; }
7292 opt_nowait: NOWAIT { $$ = TRUE; }
7293 | /*EMPTY*/ { $$ = FALSE; }
7297 /*****************************************************************************
7300 * UpdateStmt (UPDATE)
7302 *****************************************************************************/
7304 UpdateStmt: UPDATE relation_expr_opt_alias
7307 where_or_current_clause
7310 UpdateStmt *n = makeNode(UpdateStmt);
7314 n->whereClause = $6;
7315 n->returningList = $7;
7321 set_clause { $$ = $1; }
7322 | set_clause_list ',' set_clause { $$ = list_concat($1,$3); }
7326 single_set_clause { $$ = list_make1($1); }
7327 | multiple_set_clause { $$ = $1; }
7331 set_target '=' ctext_expr
7334 $$->val = (Node *) $3;
7338 multiple_set_clause:
7339 '(' set_target_list ')' '=' ctext_row
7345 * Break the ctext_row apart, merge individual expressions
7346 * into the destination ResTargets. XXX this approach
7347 * cannot work for general row expressions as sources.
7349 if (list_length($2) != list_length($5))
7351 (errcode(ERRCODE_SYNTAX_ERROR),
7352 errmsg("number of columns does not match number of values"),
7353 parser_errposition(@1)));
7354 forboth(col_cell, $2, val_cell, $5)
7356 ResTarget *res_col = (ResTarget *) lfirst(col_cell);
7357 Node *res_val = (Node *) lfirst(val_cell);
7359 res_col->val = res_val;
7367 ColId opt_indirection
7369 $$ = makeNode(ResTarget);
7371 $$->indirection = check_indirection($2, yyscanner);
7372 $$->val = NULL; /* upper production sets this */
7378 set_target { $$ = list_make1($1); }
7379 | set_target_list ',' set_target { $$ = lappend($1,$3); }
7383 /*****************************************************************************
7388 *****************************************************************************/
7389 DeclareCursorStmt: DECLARE cursor_name cursor_options CURSOR opt_hold FOR SelectStmt
7391 DeclareCursorStmt *n = makeNode(DeclareCursorStmt);
7393 /* currently we always set FAST_PLAN option */
7394 n->options = $3 | $5 | CURSOR_OPT_FAST_PLAN;
7400 cursor_name: name { $$ = $1; }
7403 cursor_options: /*EMPTY*/ { $$ = 0; }
7404 | cursor_options NO SCROLL { $$ = $1 | CURSOR_OPT_NO_SCROLL; }
7405 | cursor_options SCROLL { $$ = $1 | CURSOR_OPT_SCROLL; }
7406 | cursor_options BINARY { $$ = $1 | CURSOR_OPT_BINARY; }
7407 | cursor_options INSENSITIVE { $$ = $1 | CURSOR_OPT_INSENSITIVE; }
7410 opt_hold: /* EMPTY */ { $$ = 0; }
7411 | WITH HOLD { $$ = CURSOR_OPT_HOLD; }
7412 | WITHOUT HOLD { $$ = 0; }
7415 /*****************************************************************************
7420 *****************************************************************************/
7422 /* A complete SELECT statement looks like this.
7424 * The rule returns either a single SelectStmt node or a tree of them,
7425 * representing a set-operation tree.
7427 * There is an ambiguity when a sub-SELECT is within an a_expr and there
7428 * are excess parentheses: do the parentheses belong to the sub-SELECT or
7429 * to the surrounding a_expr? We don't really care, but bison wants to know.
7430 * To resolve the ambiguity, we are careful to define the grammar so that
7431 * the decision is staved off as long as possible: as long as we can keep
7432 * absorbing parentheses into the sub-SELECT, we will do so, and only when
7433 * it's no longer possible to do that will we decide that parens belong to
7434 * the expression. For example, in "SELECT (((SELECT 2)) + 3)" the extra
7435 * parentheses are treated as part of the sub-select. The necessity of doing
7436 * it that way is shown by "SELECT (((SELECT 2)) UNION SELECT 2)". Had we
7437 * parsed "((SELECT 2))" as an a_expr, it'd be too late to go back to the
7438 * SELECT viewpoint when we see the UNION.
7440 * This approach is implemented by defining a nonterminal select_with_parens,
7441 * which represents a SELECT with at least one outer layer of parentheses,
7442 * and being careful to use select_with_parens, never '(' SelectStmt ')',
7443 * in the expression grammar. We will then have shift-reduce conflicts
7444 * which we can resolve in favor of always treating '(' <select> ')' as
7445 * a select_with_parens. To resolve the conflicts, the productions that
7446 * conflict with the select_with_parens productions are manually given
7447 * precedences lower than the precedence of ')', thereby ensuring that we
7448 * shift ')' (and then reduce to select_with_parens) rather than trying to
7449 * reduce the inner <select> nonterminal to something else. We use UMINUS
7450 * precedence for this, which is a fairly arbitrary choice.
7452 * To be able to define select_with_parens itself without ambiguity, we need
7453 * a nonterminal select_no_parens that represents a SELECT structure with no
7454 * outermost parentheses. This is a little bit tedious, but it works.
7456 * In non-expression contexts, we use SelectStmt which can represent a SELECT
7457 * with or without outer parentheses.
7460 SelectStmt: select_no_parens %prec UMINUS
7461 | select_with_parens %prec UMINUS
7465 '(' select_no_parens ')' { $$ = $2; }
7466 | '(' select_with_parens ')' { $$ = $2; }
7470 * This rule parses the equivalent of the standard's <query expression>.
7471 * The duplicative productions are annoying, but hard to get rid of without
7472 * creating shift/reduce conflicts.
7474 * FOR UPDATE/SHARE may be before or after LIMIT/OFFSET.
7475 * In <=7.2.X, LIMIT/OFFSET had to be after FOR UPDATE
7476 * We now support both orderings, but prefer LIMIT/OFFSET before FOR UPDATE/SHARE
7480 simple_select { $$ = $1; }
7481 | select_clause sort_clause
7483 insertSelectOptions((SelectStmt *) $1, $2, NIL,
7488 | select_clause opt_sort_clause for_locking_clause opt_select_limit
7490 insertSelectOptions((SelectStmt *) $1, $2, $3,
7491 list_nth($4, 0), list_nth($4, 1),
7496 | select_clause opt_sort_clause select_limit opt_for_locking_clause
7498 insertSelectOptions((SelectStmt *) $1, $2, $4,
7499 list_nth($3, 0), list_nth($3, 1),
7504 | with_clause select_clause
7506 insertSelectOptions((SelectStmt *) $2, NULL, NIL,
7512 | with_clause select_clause sort_clause
7514 insertSelectOptions((SelectStmt *) $2, $3, NIL,
7520 | with_clause select_clause opt_sort_clause for_locking_clause opt_select_limit
7522 insertSelectOptions((SelectStmt *) $2, $3, $4,
7523 list_nth($5, 0), list_nth($5, 1),
7528 | with_clause select_clause opt_sort_clause select_limit opt_for_locking_clause
7530 insertSelectOptions((SelectStmt *) $2, $3, $5,
7531 list_nth($4, 0), list_nth($4, 1),
7539 simple_select { $$ = $1; }
7540 | select_with_parens { $$ = $1; }
7544 * This rule parses SELECT statements that can appear within set operations,
7545 * including UNION, INTERSECT and EXCEPT. '(' and ')' can be used to specify
7546 * the ordering of the set operations. Without '(' and ')' we want the
7547 * operations to be ordered per the precedence specs at the head of this file.
7549 * As with select_no_parens, simple_select cannot have outer parentheses,
7550 * but can have parenthesized subclauses.
7552 * Note that sort clauses cannot be included at this level --- SQL92 requires
7553 * SELECT foo UNION SELECT bar ORDER BY baz
7555 * (SELECT foo UNION SELECT bar) ORDER BY baz
7557 * SELECT foo UNION (SELECT bar ORDER BY baz)
7558 * Likewise for WITH, FOR UPDATE and LIMIT. Therefore, those clauses are
7559 * described as part of the select_no_parens production, not simple_select.
7560 * This does not limit functionality, because you can reintroduce these
7561 * clauses inside parentheses.
7563 * NOTE: only the leftmost component SelectStmt should have INTO.
7564 * However, this is not checked by the grammar; parse analysis must check it.
7567 SELECT opt_distinct target_list
7568 into_clause from_clause where_clause
7569 group_clause having_clause window_clause
7571 SelectStmt *n = makeNode(SelectStmt);
7572 n->distinctClause = $2;
7576 n->whereClause = $6;
7577 n->groupClause = $7;
7578 n->havingClause = $8;
7579 n->windowClause = $9;
7582 | values_clause { $$ = $1; }
7583 | TABLE relation_expr
7585 /* same as SELECT * FROM relation_expr */
7586 ColumnRef *cr = makeNode(ColumnRef);
7587 ResTarget *rt = makeNode(ResTarget);
7588 SelectStmt *n = makeNode(SelectStmt);
7590 cr->fields = list_make1(makeNode(A_Star));
7594 rt->indirection = NIL;
7595 rt->val = (Node *)cr;
7598 n->targetList = list_make1(rt);
7599 n->fromClause = list_make1($2);
7602 | select_clause UNION opt_all select_clause
7604 $$ = makeSetOp(SETOP_UNION, $3, $1, $4);
7606 | select_clause INTERSECT opt_all select_clause
7608 $$ = makeSetOp(SETOP_INTERSECT, $3, $1, $4);
7610 | select_clause EXCEPT opt_all select_clause
7612 $$ = makeSetOp(SETOP_EXCEPT, $3, $1, $4);
7617 * SQL standard WITH clause looks like:
7619 * WITH [ RECURSIVE ] <query name> [ (<column>,...) ]
7620 * AS (query) [ SEARCH or CYCLE clause ]
7622 * We don't currently support the SEARCH or CYCLE clause.
7627 $$ = makeNode(WithClause);
7629 $$->recursive = false;
7632 | WITH RECURSIVE cte_list
7634 $$ = makeNode(WithClause);
7636 $$->recursive = true;
7642 common_table_expr { $$ = list_make1($1); }
7643 | cte_list ',' common_table_expr { $$ = lappend($1, $3); }
7646 common_table_expr: name opt_name_list AS select_with_parens
7648 CommonTableExpr *n = makeNode(CommonTableExpr);
7650 n->aliascolnames = $2;
7658 INTO OptTempTableName
7660 $$ = makeNode(IntoClause);
7664 $$->onCommit = ONCOMMIT_NOOP;
7665 $$->tableSpaceName = NULL;
7672 * Redundancy here is needed to avoid shift/reduce conflicts,
7673 * since TEMP is not a reserved word. See also OptTemp.
7676 TEMPORARY opt_table qualified_name
7681 | TEMP opt_table qualified_name
7686 | LOCAL TEMPORARY opt_table qualified_name
7691 | LOCAL TEMP opt_table qualified_name
7696 | GLOBAL TEMPORARY opt_table qualified_name
7701 | GLOBAL TEMP opt_table qualified_name
7706 | TABLE qualified_name
7722 opt_all: ALL { $$ = TRUE; }
7723 | DISTINCT { $$ = FALSE; }
7724 | /*EMPTY*/ { $$ = FALSE; }
7727 /* We use (NIL) as a placeholder to indicate that all target expressions
7728 * should be placed in the DISTINCT list during parsetree analysis.
7731 DISTINCT { $$ = list_make1(NIL); }
7732 | DISTINCT ON '(' expr_list ')' { $$ = $4; }
7734 | /*EMPTY*/ { $$ = NIL; }
7738 sort_clause { $$ = $1;}
7739 | /*EMPTY*/ { $$ = NIL; }
7743 ORDER BY sortby_list { $$ = $3; }
7747 sortby { $$ = list_make1($1); }
7748 | sortby_list ',' sortby { $$ = lappend($1, $3); }
7751 sortby: a_expr USING qual_all_Op opt_nulls_order
7753 $$ = makeNode(SortBy);
7755 $$->sortby_dir = SORTBY_USING;
7756 $$->sortby_nulls = $4;
7760 | a_expr opt_asc_desc opt_nulls_order
7762 $$ = makeNode(SortBy);
7764 $$->sortby_dir = $2;
7765 $$->sortby_nulls = $3;
7767 $$->location = -1; /* no operator */
7773 limit_clause offset_clause { $$ = list_make2($2, $1); }
7774 | offset_clause limit_clause { $$ = list_make2($1, $2); }
7775 | limit_clause { $$ = list_make2(NULL, $1); }
7776 | offset_clause { $$ = list_make2($1, NULL); }
7780 select_limit { $$ = $1; }
7781 | /* EMPTY */ { $$ = list_make2(NULL,NULL); }
7785 LIMIT select_limit_value
7787 | LIMIT select_limit_value ',' select_offset_value
7789 /* Disabled because it was too confusing, bjm 2002-02-18 */
7791 (errcode(ERRCODE_SYNTAX_ERROR),
7792 errmsg("LIMIT #,# syntax is not supported"),
7793 errhint("Use separate LIMIT and OFFSET clauses."),
7794 parser_errposition(@1)));
7796 /* SQL:2008 syntax */
7797 | FETCH first_or_next opt_select_fetch_first_value row_or_rows ONLY
7802 OFFSET select_offset_value
7804 /* SQL:2008 syntax */
7805 | OFFSET select_offset_value2 row_or_rows
7813 /* LIMIT ALL is represented as a NULL constant */
7814 $$ = makeNullAConst(@1);
7818 select_offset_value:
7823 * Allowing full expressions without parentheses causes various parsing
7824 * problems with the trailing ROW/ROWS key words. SQL only calls for
7825 * constants, so we allow the rest only with parentheses. If omitted,
7828 opt_select_fetch_first_value:
7829 SignedIconst { $$ = makeIntConst($1, @1); }
7830 | '(' a_expr ')' { $$ = $2; }
7831 | /*EMPTY*/ { $$ = makeIntConst(1, -1); }
7835 * Again, the trailing ROW/ROWS in this case prevent the full expression
7836 * syntax. c_expr is the best we can do.
7838 select_offset_value2:
7843 row_or_rows: ROW { $$ = 0; }
7847 first_or_next: FIRST_P { $$ = 0; }
7853 GROUP_P BY expr_list { $$ = $3; }
7854 | /*EMPTY*/ { $$ = NIL; }
7858 HAVING a_expr { $$ = $2; }
7859 | /*EMPTY*/ { $$ = NULL; }
7863 for_locking_items { $$ = $1; }
7864 | FOR READ ONLY { $$ = NIL; }
7867 opt_for_locking_clause:
7868 for_locking_clause { $$ = $1; }
7869 | /* EMPTY */ { $$ = NIL; }
7873 for_locking_item { $$ = list_make1($1); }
7874 | for_locking_items for_locking_item { $$ = lappend($1, $2); }
7878 FOR UPDATE locked_rels_list opt_nowait
7880 LockingClause *n = makeNode(LockingClause);
7882 n->forUpdate = TRUE;
7886 | FOR SHARE locked_rels_list opt_nowait
7888 LockingClause *n = makeNode(LockingClause);
7890 n->forUpdate = FALSE;
7897 OF qualified_name_list { $$ = $2; }
7898 | /* EMPTY */ { $$ = NIL; }
7905 SelectStmt *n = makeNode(SelectStmt);
7906 n->valuesLists = list_make1($2);
7909 | values_clause ',' ctext_row
7911 SelectStmt *n = (SelectStmt *) $1;
7912 n->valuesLists = lappend(n->valuesLists, $3);
7918 /*****************************************************************************
7920 * clauses common to all Optimizable Stmts:
7921 * from_clause - allow list of both JOIN expressions and table names
7922 * where_clause - qualifications for joins or restrictions
7924 *****************************************************************************/
7927 FROM from_list { $$ = $2; }
7928 | /*EMPTY*/ { $$ = NIL; }
7932 table_ref { $$ = list_make1($1); }
7933 | from_list ',' table_ref { $$ = lappend($1, $3); }
7937 * table_ref is where an alias clause can be attached. Note we cannot make
7938 * alias_clause have an empty production because that causes parse conflicts
7939 * between table_ref := '(' joined_table ')' alias_clause
7940 * and joined_table := '(' joined_table ')'. So, we must have the
7941 * redundant-looking productions here instead.
7943 table_ref: relation_expr
7947 | relation_expr alias_clause
7954 RangeFunction *n = makeNode(RangeFunction);
7955 n->funccallnode = $1;
7956 n->coldeflist = NIL;
7959 | func_table alias_clause
7961 RangeFunction *n = makeNode(RangeFunction);
7962 n->funccallnode = $1;
7964 n->coldeflist = NIL;
7967 | func_table AS '(' TableFuncElementList ')'
7969 RangeFunction *n = makeNode(RangeFunction);
7970 n->funccallnode = $1;
7974 | func_table AS ColId '(' TableFuncElementList ')'
7976 RangeFunction *n = makeNode(RangeFunction);
7977 Alias *a = makeNode(Alias);
7978 n->funccallnode = $1;
7984 | func_table ColId '(' TableFuncElementList ')'
7986 RangeFunction *n = makeNode(RangeFunction);
7987 Alias *a = makeNode(Alias);
7988 n->funccallnode = $1;
7994 | select_with_parens
7997 * The SQL spec does not permit a subselect
7998 * (<derived_table>) without an alias clause,
7999 * so we don't either. This avoids the problem
8000 * of needing to invent a unique refname for it.
8001 * That could be surmounted if there's sufficient
8002 * popular demand, but for now let's just implement
8003 * the spec and see if anyone complains.
8004 * However, it does seem like a good idea to emit
8005 * an error message that's better than "syntax error".
8007 if (IsA($1, SelectStmt) &&
8008 ((SelectStmt *) $1)->valuesLists)
8010 (errcode(ERRCODE_SYNTAX_ERROR),
8011 errmsg("VALUES in FROM must have an alias"),
8012 errhint("For example, FROM (VALUES ...) [AS] foo."),
8013 parser_errposition(@1)));
8016 (errcode(ERRCODE_SYNTAX_ERROR),
8017 errmsg("subquery in FROM must have an alias"),
8018 errhint("For example, FROM (SELECT ...) [AS] foo."),
8019 parser_errposition(@1)));
8022 | select_with_parens alias_clause
8024 RangeSubselect *n = makeNode(RangeSubselect);
8033 | '(' joined_table ')' alias_clause
8042 * It may seem silly to separate joined_table from table_ref, but there is
8043 * method in SQL92's madness: if you don't do it this way you get reduce-
8044 * reduce conflicts, because it's not clear to the parser generator whether
8045 * to expect alias_clause after ')' or not. For the same reason we must
8046 * treat 'JOIN' and 'join_type JOIN' separately, rather than allowing
8047 * join_type to expand to empty; if we try it, the parser generator can't
8048 * figure out when to reduce an empty join_type right after table_ref.
8050 * Note that a CROSS JOIN is the same as an unqualified
8051 * INNER JOIN, and an INNER JOIN/ON has the same shape
8052 * but a qualification expression to limit membership.
8053 * A NATURAL JOIN implicitly matches column names between
8054 * tables and the shape is determined by which columns are
8055 * in common. We'll collect columns during the later transformations.
8059 '(' joined_table ')'
8063 | table_ref CROSS JOIN table_ref
8065 /* CROSS JOIN is same as unqualified inner join */
8066 JoinExpr *n = makeNode(JoinExpr);
8067 n->jointype = JOIN_INNER;
8068 n->isNatural = FALSE;
8071 n->usingClause = NIL;
8075 | table_ref join_type JOIN table_ref join_qual
8077 JoinExpr *n = makeNode(JoinExpr);
8079 n->isNatural = FALSE;
8082 if ($5 != NULL && IsA($5, List))
8083 n->usingClause = (List *) $5; /* USING clause */
8085 n->quals = $5; /* ON clause */
8088 | table_ref JOIN table_ref join_qual
8090 /* letting join_type reduce to empty doesn't work */
8091 JoinExpr *n = makeNode(JoinExpr);
8092 n->jointype = JOIN_INNER;
8093 n->isNatural = FALSE;
8096 if ($4 != NULL && IsA($4, List))
8097 n->usingClause = (List *) $4; /* USING clause */
8099 n->quals = $4; /* ON clause */
8102 | table_ref NATURAL join_type JOIN table_ref
8104 JoinExpr *n = makeNode(JoinExpr);
8106 n->isNatural = TRUE;
8109 n->usingClause = NIL; /* figure out which columns later... */
8110 n->quals = NULL; /* fill later */
8113 | table_ref NATURAL JOIN table_ref
8115 /* letting join_type reduce to empty doesn't work */
8116 JoinExpr *n = makeNode(JoinExpr);
8117 n->jointype = JOIN_INNER;
8118 n->isNatural = TRUE;
8121 n->usingClause = NIL; /* figure out which columns later... */
8122 n->quals = NULL; /* fill later */
8128 AS ColId '(' name_list ')'
8130 $$ = makeNode(Alias);
8136 $$ = makeNode(Alias);
8139 | ColId '(' name_list ')'
8141 $$ = makeNode(Alias);
8147 $$ = makeNode(Alias);
8152 join_type: FULL join_outer { $$ = JOIN_FULL; }
8153 | LEFT join_outer { $$ = JOIN_LEFT; }
8154 | RIGHT join_outer { $$ = JOIN_RIGHT; }
8155 | INNER_P { $$ = JOIN_INNER; }
8158 /* OUTER is just noise... */
8159 join_outer: OUTER_P { $$ = NULL; }
8160 | /*EMPTY*/ { $$ = NULL; }
8163 /* JOIN qualification clauses
8164 * Possibilities are:
8165 * USING ( column list ) allows only unqualified column names,
8166 * which must match between tables.
8167 * ON expr allows more general qualifications.
8169 * We return USING as a List node, while an ON-expr will not be a List.
8172 join_qual: USING '(' name_list ')' { $$ = (Node *) $3; }
8173 | ON a_expr { $$ = $2; }
8180 /* default inheritance */
8182 $$->inhOpt = INH_DEFAULT;
8185 | qualified_name '*'
8187 /* inheritance query */
8189 $$->inhOpt = INH_YES;
8192 | ONLY qualified_name
8194 /* no inheritance */
8196 $$->inhOpt = INH_NO;
8199 | ONLY '(' qualified_name ')'
8201 /* no inheritance, SQL99-style syntax */
8203 $$->inhOpt = INH_NO;
8210 relation_expr { $$ = list_make1($1); }
8211 | relation_expr_list ',' relation_expr { $$ = lappend($1, $3); }
8216 * Given "UPDATE foo set set ...", we have to decide without looking any
8217 * further ahead whether the first "set" is an alias or the UPDATE's SET
8218 * keyword. Since "set" is allowed as a column name both interpretations
8219 * are feasible. We resolve the shift/reduce conflict by giving the first
8220 * relation_expr_opt_alias production a higher precedence than the SET token
8221 * has, causing the parser to prefer to reduce, in effect assuming that the
8222 * SET is not an alias.
8224 relation_expr_opt_alias: relation_expr %prec UMINUS
8228 | relation_expr ColId
8230 Alias *alias = makeNode(Alias);
8231 alias->aliasname = $2;
8235 | relation_expr AS ColId
8237 Alias *alias = makeNode(Alias);
8238 alias->aliasname = $3;
8245 func_table: func_expr { $$ = $1; }
8250 WHERE a_expr { $$ = $2; }
8251 | /*EMPTY*/ { $$ = NULL; }
8254 /* variant for UPDATE and DELETE */
8255 where_or_current_clause:
8256 WHERE a_expr { $$ = $2; }
8257 | WHERE CURRENT_P OF name
8259 CurrentOfExpr *n = makeNode(CurrentOfExpr);
8260 /* cvarno is filled in by parse analysis */
8261 n->cursor_name = $4;
8262 n->cursor_param = 0;
8265 | /*EMPTY*/ { $$ = NULL; }
8269 OptTableFuncElementList:
8270 TableFuncElementList { $$ = $1; }
8271 | /*EMPTY*/ { $$ = NIL; }
8274 TableFuncElementList:
8277 $$ = list_make1($1);
8279 | TableFuncElementList ',' TableFuncElement
8281 $$ = lappend($1, $3);
8285 TableFuncElement: ColId Typename
8287 ColumnDef *n = makeNode(ColumnDef);
8290 n->constraints = NIL;
8296 /*****************************************************************************
8299 * SQL92 introduces a large amount of type-specific syntax.
8300 * Define individual clauses to handle these cases, and use
8301 * the generic case to handle regular type-extensible Postgres syntax.
8302 * - thomas 1997-10-10
8304 *****************************************************************************/
8306 Typename: SimpleTypename opt_array_bounds
8309 $$->arrayBounds = $2;
8311 | SETOF SimpleTypename opt_array_bounds
8314 $$->arrayBounds = $3;
8317 /* SQL standard syntax, currently only one-dimensional */
8318 | SimpleTypename ARRAY '[' Iconst ']'
8321 $$->arrayBounds = list_make1(makeInteger($4));
8323 | SETOF SimpleTypename ARRAY '[' Iconst ']'
8326 $$->arrayBounds = list_make1(makeInteger($5));
8329 | SimpleTypename ARRAY
8332 $$->arrayBounds = list_make1(makeInteger(-1));
8334 | SETOF SimpleTypename ARRAY
8337 $$->arrayBounds = list_make1(makeInteger(-1));
8343 opt_array_bounds '[' ']'
8344 { $$ = lappend($1, makeInteger(-1)); }
8345 | opt_array_bounds '[' Iconst ']'
8346 { $$ = lappend($1, makeInteger($3)); }
8352 GenericType { $$ = $1; }
8353 | Numeric { $$ = $1; }
8355 | Character { $$ = $1; }
8356 | ConstDatetime { $$ = $1; }
8357 | ConstInterval opt_interval
8362 | ConstInterval '(' Iconst ')' opt_interval
8367 if (list_length($5) != 1)
8369 (errcode(ERRCODE_SYNTAX_ERROR),
8370 errmsg("interval precision specified twice"),
8371 parser_errposition(@1)));
8372 $$->typmods = lappend($5, makeIntConst($3, @3));
8375 $$->typmods = list_make2(makeIntConst(INTERVAL_FULL_RANGE, -1),
8376 makeIntConst($3, @3));
8380 /* We have a separate ConstTypename to allow defaulting fixed-length
8381 * types such as CHAR() and BIT() to an unspecified length.
8382 * SQL9x requires that these default to a length of one, but this
8383 * makes no sense for constructs like CHAR 'hi' and BIT '0101',
8384 * where there is an obvious better choice to make.
8385 * Note that ConstInterval is not included here since it must
8386 * be pushed up higher in the rules to accomodate the postfix
8387 * options (e.g. INTERVAL '1' YEAR). Likewise, we have to handle
8388 * the generic-type-name case in AExprConst to avoid premature
8389 * reduce/reduce conflicts against function names.
8392 Numeric { $$ = $1; }
8393 | ConstBit { $$ = $1; }
8394 | ConstCharacter { $$ = $1; }
8395 | ConstDatetime { $$ = $1; }
8399 * GenericType covers all type names that don't have special syntax mandated
8400 * by the standard, including qualified names. We also allow type modifiers.
8401 * To avoid parsing conflicts against function invocations, the modifiers
8402 * have to be shown as expr_list here, but parse analysis will only accept
8403 * constants for them.
8406 type_function_name opt_type_modifiers
8408 $$ = makeTypeName($1);
8412 | type_function_name attrs opt_type_modifiers
8414 $$ = makeTypeNameFromNameList(lcons(makeString($1), $2));
8420 opt_type_modifiers: '(' expr_list ')' { $$ = $2; }
8421 | /* EMPTY */ { $$ = NIL; }
8425 * SQL92 numeric data types
8429 $$ = SystemTypeName("int4");
8434 $$ = SystemTypeName("int4");
8439 $$ = SystemTypeName("int2");
8444 $$ = SystemTypeName("int8");
8449 $$ = SystemTypeName("float4");
8457 | DOUBLE_P PRECISION
8459 $$ = SystemTypeName("float8");
8462 | DECIMAL_P opt_type_modifiers
8464 $$ = SystemTypeName("numeric");
8468 | DEC opt_type_modifiers
8470 $$ = SystemTypeName("numeric");
8474 | NUMERIC opt_type_modifiers
8476 $$ = SystemTypeName("numeric");
8482 $$ = SystemTypeName("bool");
8487 opt_float: '(' Iconst ')'
8490 * Check FLOAT() precision limits assuming IEEE floating
8491 * types - thomas 1997-09-18
8495 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
8496 errmsg("precision for type float must be at least 1 bit"),
8497 parser_errposition(@2)));
8499 $$ = SystemTypeName("float4");
8501 $$ = SystemTypeName("float8");
8504 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
8505 errmsg("precision for type float must be less than 54 bits"),
8506 parser_errposition(@2)));
8510 $$ = SystemTypeName("float8");
8515 * SQL92 bit-field data types
8516 * The following implements BIT() and BIT VARYING().
8528 /* ConstBit is like Bit except "BIT" defaults to unspecified length */
8529 /* See notes for ConstCharacter, which addresses same issue for "CHAR" */
8530 ConstBit: BitWithLength
8542 BIT opt_varying '(' expr_list ')'
8546 typname = $2 ? "varbit" : "bit";
8547 $$ = SystemTypeName(typname);
8556 /* bit defaults to bit(1), varbit to no limit */
8559 $$ = SystemTypeName("varbit");
8563 $$ = SystemTypeName("bit");
8564 $$->typmods = list_make1(makeIntConst(1, -1));
8572 * SQL92 character data types
8573 * The following implements CHAR() and VARCHAR().
8575 Character: CharacterWithLength
8579 | CharacterWithoutLength
8585 ConstCharacter: CharacterWithLength
8589 | CharacterWithoutLength
8591 /* Length was not specified so allow to be unrestricted.
8592 * This handles problems with fixed-length (bpchar) strings
8593 * which in column definitions must default to a length
8594 * of one, but should not be constrained if the length
8595 * was not specified.
8602 CharacterWithLength: character '(' Iconst ')' opt_charset
8604 if (($5 != NULL) && (strcmp($5, "sql_text") != 0))
8608 type = palloc(strlen($1) + 1 + strlen($5) + 1);
8615 $$ = SystemTypeName($1);
8616 $$->typmods = list_make1(makeIntConst($3, @3));
8621 CharacterWithoutLength: character opt_charset
8623 if (($2 != NULL) && (strcmp($2, "sql_text") != 0))
8627 type = palloc(strlen($1) + 1 + strlen($2) + 1);
8634 $$ = SystemTypeName($1);
8636 /* char defaults to char(1), varchar to no limit */
8637 if (strcmp($1, "bpchar") == 0)
8638 $$->typmods = list_make1(makeIntConst(1, -1));
8644 character: CHARACTER opt_varying
8645 { $$ = $2 ? "varchar": "bpchar"; }
8646 | CHAR_P opt_varying
8647 { $$ = $2 ? "varchar": "bpchar"; }
8650 | NATIONAL CHARACTER opt_varying
8651 { $$ = $3 ? "varchar": "bpchar"; }
8652 | NATIONAL CHAR_P opt_varying
8653 { $$ = $3 ? "varchar": "bpchar"; }
8655 { $$ = $2 ? "varchar": "bpchar"; }
8659 VARYING { $$ = TRUE; }
8660 | /*EMPTY*/ { $$ = FALSE; }
8664 CHARACTER SET ColId { $$ = $3; }
8665 | /*EMPTY*/ { $$ = NULL; }
8669 * SQL92 date/time types
8672 TIMESTAMP '(' Iconst ')' opt_timezone
8675 $$ = SystemTypeName("timestamptz");
8677 $$ = SystemTypeName("timestamp");
8678 $$->typmods = list_make1(makeIntConst($3, @3));
8681 | TIMESTAMP opt_timezone
8684 $$ = SystemTypeName("timestamptz");
8686 $$ = SystemTypeName("timestamp");
8689 | TIME '(' Iconst ')' opt_timezone
8692 $$ = SystemTypeName("timetz");
8694 $$ = SystemTypeName("time");
8695 $$->typmods = list_make1(makeIntConst($3, @3));
8701 $$ = SystemTypeName("timetz");
8703 $$ = SystemTypeName("time");
8711 $$ = SystemTypeName("interval");
8717 WITH_TIME ZONE { $$ = TRUE; }
8718 | WITHOUT TIME ZONE { $$ = FALSE; }
8719 | /*EMPTY*/ { $$ = FALSE; }
8724 { $$ = list_make1(makeIntConst(INTERVAL_MASK(YEAR), @1)); }
8726 { $$ = list_make1(makeIntConst(INTERVAL_MASK(MONTH), @1)); }
8728 { $$ = list_make1(makeIntConst(INTERVAL_MASK(DAY), @1)); }
8730 { $$ = list_make1(makeIntConst(INTERVAL_MASK(HOUR), @1)); }
8732 { $$ = list_make1(makeIntConst(INTERVAL_MASK(MINUTE), @1)); }
8737 $$ = list_make1(makeIntConst(INTERVAL_MASK(YEAR) |
8738 INTERVAL_MASK(MONTH), @1));
8742 $$ = list_make1(makeIntConst(INTERVAL_MASK(DAY) |
8743 INTERVAL_MASK(HOUR), @1));
8747 $$ = list_make1(makeIntConst(INTERVAL_MASK(DAY) |
8748 INTERVAL_MASK(HOUR) |
8749 INTERVAL_MASK(MINUTE), @1));
8751 | DAY_P TO interval_second
8754 linitial($$) = makeIntConst(INTERVAL_MASK(DAY) |
8755 INTERVAL_MASK(HOUR) |
8756 INTERVAL_MASK(MINUTE) |
8757 INTERVAL_MASK(SECOND), @1);
8759 | HOUR_P TO MINUTE_P
8761 $$ = list_make1(makeIntConst(INTERVAL_MASK(HOUR) |
8762 INTERVAL_MASK(MINUTE), @1));
8764 | HOUR_P TO interval_second
8767 linitial($$) = makeIntConst(INTERVAL_MASK(HOUR) |
8768 INTERVAL_MASK(MINUTE) |
8769 INTERVAL_MASK(SECOND), @1);
8771 | MINUTE_P TO interval_second
8774 linitial($$) = makeIntConst(INTERVAL_MASK(MINUTE) |
8775 INTERVAL_MASK(SECOND), @1);
8784 $$ = list_make1(makeIntConst(INTERVAL_MASK(SECOND), @1));
8786 | SECOND_P '(' Iconst ')'
8788 $$ = list_make2(makeIntConst(INTERVAL_MASK(SECOND), @1),
8789 makeIntConst($3, @3));
8794 /*****************************************************************************
8796 * expression grammar
8798 *****************************************************************************/
8801 * General expressions
8802 * This is the heart of the expression syntax.
8804 * We have two expression types: a_expr is the unrestricted kind, and
8805 * b_expr is a subset that must be used in some places to avoid shift/reduce
8806 * conflicts. For example, we can't do BETWEEN as "BETWEEN a_expr AND a_expr"
8807 * because that use of AND conflicts with AND as a boolean operator. So,
8808 * b_expr is used in BETWEEN and we remove boolean keywords from b_expr.
8810 * Note that '(' a_expr ')' is a b_expr, so an unrestricted expression can
8811 * always be used by surrounding it with parens.
8813 * c_expr is all the productions that are common to a_expr and b_expr;
8814 * it's factored out just to eliminate redundant coding.
8816 a_expr: c_expr { $$ = $1; }
8817 | a_expr TYPECAST Typename
8818 { $$ = makeTypeCast($1, $3, @2); }
8819 | a_expr AT TIME ZONE a_expr
8821 FuncCall *n = makeNode(FuncCall);
8822 n->funcname = SystemFuncName("timezone");
8823 n->args = list_make2($5, $1);
8825 n->agg_star = FALSE;
8826 n->agg_distinct = FALSE;
8827 n->func_variadic = FALSE;
8833 * These operators must be called out explicitly in order to make use
8834 * of bison's automatic operator-precedence handling. All other
8835 * operator names are handled by the generic productions using "Op",
8836 * below; and all those operators will have the same precedence.
8838 * If you add more explicitly-known operators, be sure to add them
8839 * also to b_expr and to the MathOp list above.
8841 | '+' a_expr %prec UMINUS
8842 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "+", NULL, $2, @1); }
8843 | '-' a_expr %prec UMINUS
8844 { $$ = doNegate($2, @1); }
8846 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "+", $1, $3, @2); }
8848 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "-", $1, $3, @2); }
8850 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "*", $1, $3, @2); }
8852 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "/", $1, $3, @2); }
8854 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "%", $1, $3, @2); }
8856 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "^", $1, $3, @2); }
8858 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "<", $1, $3, @2); }
8860 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, ">", $1, $3, @2); }
8862 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "=", $1, $3, @2); }
8864 | a_expr qual_Op a_expr %prec Op
8865 { $$ = (Node *) makeA_Expr(AEXPR_OP, $2, $1, $3, @2); }
8866 | qual_Op a_expr %prec Op
8867 { $$ = (Node *) makeA_Expr(AEXPR_OP, $1, NULL, $2, @1); }
8868 | a_expr qual_Op %prec POSTFIXOP
8869 { $$ = (Node *) makeA_Expr(AEXPR_OP, $2, $1, NULL, @2); }
8872 { $$ = (Node *) makeA_Expr(AEXPR_AND, NIL, $1, $3, @2); }
8874 { $$ = (Node *) makeA_Expr(AEXPR_OR, NIL, $1, $3, @2); }
8876 { $$ = (Node *) makeA_Expr(AEXPR_NOT, NIL, NULL, $2, @1); }
8878 | a_expr LIKE a_expr
8879 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "~~", $1, $3, @2); }
8880 | a_expr LIKE a_expr ESCAPE a_expr
8882 FuncCall *n = makeNode(FuncCall);
8883 n->funcname = SystemFuncName("like_escape");
8884 n->args = list_make2($3, $5);
8886 n->agg_star = FALSE;
8887 n->agg_distinct = FALSE;
8888 n->func_variadic = FALSE;
8891 $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "~~", $1, (Node *) n, @2);
8893 | a_expr NOT LIKE a_expr
8894 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "!~~", $1, $4, @2); }
8895 | a_expr NOT LIKE a_expr ESCAPE a_expr
8897 FuncCall *n = makeNode(FuncCall);
8898 n->funcname = SystemFuncName("like_escape");
8899 n->args = list_make2($4, $6);
8901 n->agg_star = FALSE;
8902 n->agg_distinct = FALSE;
8903 n->func_variadic = FALSE;
8906 $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "!~~", $1, (Node *) n, @2);
8908 | a_expr ILIKE a_expr
8909 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "~~*", $1, $3, @2); }
8910 | a_expr ILIKE a_expr ESCAPE a_expr
8912 FuncCall *n = makeNode(FuncCall);
8913 n->funcname = SystemFuncName("like_escape");
8914 n->args = list_make2($3, $5);
8916 n->agg_star = FALSE;
8917 n->agg_distinct = FALSE;
8918 n->func_variadic = FALSE;
8921 $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "~~*", $1, (Node *) n, @2);
8923 | a_expr NOT ILIKE a_expr
8924 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "!~~*", $1, $4, @2); }
8925 | a_expr NOT ILIKE a_expr ESCAPE a_expr
8927 FuncCall *n = makeNode(FuncCall);
8928 n->funcname = SystemFuncName("like_escape");
8929 n->args = list_make2($4, $6);
8931 n->agg_star = FALSE;
8932 n->agg_distinct = FALSE;
8933 n->func_variadic = FALSE;
8936 $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "!~~*", $1, (Node *) n, @2);
8939 | a_expr SIMILAR TO a_expr %prec SIMILAR
8941 FuncCall *n = makeNode(FuncCall);
8942 n->funcname = SystemFuncName("similar_escape");
8943 n->args = list_make2($4, makeNullAConst(-1));
8945 n->agg_star = FALSE;
8946 n->agg_distinct = FALSE;
8947 n->func_variadic = FALSE;
8950 $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "~", $1, (Node *) n, @2);
8952 | a_expr SIMILAR TO a_expr ESCAPE a_expr
8954 FuncCall *n = makeNode(FuncCall);
8955 n->funcname = SystemFuncName("similar_escape");
8956 n->args = list_make2($4, $6);
8958 n->agg_star = FALSE;
8959 n->agg_distinct = FALSE;
8960 n->func_variadic = FALSE;
8963 $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "~", $1, (Node *) n, @2);
8965 | a_expr NOT SIMILAR TO a_expr %prec SIMILAR
8967 FuncCall *n = makeNode(FuncCall);
8968 n->funcname = SystemFuncName("similar_escape");
8969 n->args = list_make2($5, makeNullAConst(-1));
8971 n->agg_star = FALSE;
8972 n->agg_distinct = FALSE;
8973 n->func_variadic = FALSE;
8976 $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "!~", $1, (Node *) n, @2);
8978 | a_expr NOT SIMILAR TO a_expr ESCAPE a_expr
8980 FuncCall *n = makeNode(FuncCall);
8981 n->funcname = SystemFuncName("similar_escape");
8982 n->args = list_make2($5, $7);
8984 n->agg_star = FALSE;
8985 n->agg_distinct = FALSE;
8986 n->func_variadic = FALSE;
8989 $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "!~", $1, (Node *) n, @2);
8993 * Define SQL92-style Null test clause.
8994 * Allow two forms described in the standard:
8997 * Allow two SQL extensions
9003 NullTest *n = makeNode(NullTest);
9004 n->arg = (Expr *) $1;
9005 n->nulltesttype = IS_NULL;
9010 NullTest *n = makeNode(NullTest);
9011 n->arg = (Expr *) $1;
9012 n->nulltesttype = IS_NULL;
9015 | a_expr IS NOT NULL_P
9017 NullTest *n = makeNode(NullTest);
9018 n->arg = (Expr *) $1;
9019 n->nulltesttype = IS_NOT_NULL;
9024 NullTest *n = makeNode(NullTest);
9025 n->arg = (Expr *) $1;
9026 n->nulltesttype = IS_NOT_NULL;
9031 $$ = (Node *)makeOverlaps($1, $3, @2, yyscanner);
9035 BooleanTest *b = makeNode(BooleanTest);
9036 b->arg = (Expr *) $1;
9037 b->booltesttype = IS_TRUE;
9040 | a_expr IS NOT TRUE_P
9042 BooleanTest *b = makeNode(BooleanTest);
9043 b->arg = (Expr *) $1;
9044 b->booltesttype = IS_NOT_TRUE;
9049 BooleanTest *b = makeNode(BooleanTest);
9050 b->arg = (Expr *) $1;
9051 b->booltesttype = IS_FALSE;
9054 | a_expr IS NOT FALSE_P
9056 BooleanTest *b = makeNode(BooleanTest);
9057 b->arg = (Expr *) $1;
9058 b->booltesttype = IS_NOT_FALSE;
9063 BooleanTest *b = makeNode(BooleanTest);
9064 b->arg = (Expr *) $1;
9065 b->booltesttype = IS_UNKNOWN;
9068 | a_expr IS NOT UNKNOWN
9070 BooleanTest *b = makeNode(BooleanTest);
9071 b->arg = (Expr *) $1;
9072 b->booltesttype = IS_NOT_UNKNOWN;
9075 | a_expr IS DISTINCT FROM a_expr %prec IS
9077 $$ = (Node *) makeSimpleA_Expr(AEXPR_DISTINCT, "=", $1, $5, @2);
9079 | a_expr IS NOT DISTINCT FROM a_expr %prec IS
9081 $$ = (Node *) makeA_Expr(AEXPR_NOT, NIL, NULL,
9082 (Node *) makeSimpleA_Expr(AEXPR_DISTINCT,
9087 | a_expr IS OF '(' type_list ')' %prec IS
9089 $$ = (Node *) makeSimpleA_Expr(AEXPR_OF, "=", $1, (Node *) $5, @2);
9091 | a_expr IS NOT OF '(' type_list ')' %prec IS
9093 $$ = (Node *) makeSimpleA_Expr(AEXPR_OF, "<>", $1, (Node *) $6, @2);
9096 * Ideally we would not use hard-wired operators below but
9097 * instead use opclasses. However, mixed data types and other
9098 * issues make this difficult:
9099 * http://archives.postgresql.org/pgsql-hackers/2008-08/msg01142.php
9101 | a_expr BETWEEN opt_asymmetric b_expr AND b_expr %prec BETWEEN
9103 $$ = (Node *) makeA_Expr(AEXPR_AND, NIL,
9104 (Node *) makeSimpleA_Expr(AEXPR_OP, ">=", $1, $4, @2),
9105 (Node *) makeSimpleA_Expr(AEXPR_OP, "<=", $1, $6, @2),
9108 | a_expr NOT BETWEEN opt_asymmetric b_expr AND b_expr %prec BETWEEN
9110 $$ = (Node *) makeA_Expr(AEXPR_OR, NIL,
9111 (Node *) makeSimpleA_Expr(AEXPR_OP, "<", $1, $5, @2),
9112 (Node *) makeSimpleA_Expr(AEXPR_OP, ">", $1, $7, @2),
9115 | a_expr BETWEEN SYMMETRIC b_expr AND b_expr %prec BETWEEN
9117 $$ = (Node *) makeA_Expr(AEXPR_OR, NIL,
9118 (Node *) makeA_Expr(AEXPR_AND, NIL,
9119 (Node *) makeSimpleA_Expr(AEXPR_OP, ">=", $1, $4, @2),
9120 (Node *) makeSimpleA_Expr(AEXPR_OP, "<=", $1, $6, @2),
9122 (Node *) makeA_Expr(AEXPR_AND, NIL,
9123 (Node *) makeSimpleA_Expr(AEXPR_OP, ">=", $1, $6, @2),
9124 (Node *) makeSimpleA_Expr(AEXPR_OP, "<=", $1, $4, @2),
9128 | a_expr NOT BETWEEN SYMMETRIC b_expr AND b_expr %prec BETWEEN
9130 $$ = (Node *) makeA_Expr(AEXPR_AND, NIL,
9131 (Node *) makeA_Expr(AEXPR_OR, NIL,
9132 (Node *) makeSimpleA_Expr(AEXPR_OP, "<", $1, $5, @2),
9133 (Node *) makeSimpleA_Expr(AEXPR_OP, ">", $1, $7, @2),
9135 (Node *) makeA_Expr(AEXPR_OR, NIL,
9136 (Node *) makeSimpleA_Expr(AEXPR_OP, "<", $1, $7, @2),
9137 (Node *) makeSimpleA_Expr(AEXPR_OP, ">", $1, $5, @2),
9141 | a_expr IN_P in_expr
9143 /* in_expr returns a SubLink or a list of a_exprs */
9144 if (IsA($3, SubLink))
9146 /* generate foo = ANY (subquery) */
9147 SubLink *n = (SubLink *) $3;
9148 n->subLinkType = ANY_SUBLINK;
9150 n->operName = list_make1(makeString("="));
9156 /* generate scalar IN expression */
9157 $$ = (Node *) makeSimpleA_Expr(AEXPR_IN, "=", $1, $3, @2);
9160 | a_expr NOT IN_P in_expr
9162 /* in_expr returns a SubLink or a list of a_exprs */
9163 if (IsA($4, SubLink))
9165 /* generate NOT (foo = ANY (subquery)) */
9166 /* Make an = ANY node */
9167 SubLink *n = (SubLink *) $4;
9168 n->subLinkType = ANY_SUBLINK;
9170 n->operName = list_make1(makeString("="));
9172 /* Stick a NOT on top */
9173 $$ = (Node *) makeA_Expr(AEXPR_NOT, NIL, NULL, (Node *) n, @2);
9177 /* generate scalar NOT IN expression */
9178 $$ = (Node *) makeSimpleA_Expr(AEXPR_IN, "<>", $1, $4, @2);
9181 | a_expr subquery_Op sub_type select_with_parens %prec Op
9183 SubLink *n = makeNode(SubLink);
9184 n->subLinkType = $3;
9191 | a_expr subquery_Op sub_type '(' a_expr ')' %prec Op
9193 if ($3 == ANY_SUBLINK)
9194 $$ = (Node *) makeA_Expr(AEXPR_OP_ANY, $2, $1, $5, @2);
9196 $$ = (Node *) makeA_Expr(AEXPR_OP_ALL, $2, $1, $5, @2);
9198 | UNIQUE select_with_parens
9200 /* Not sure how to get rid of the parentheses
9201 * but there are lots of shift/reduce errors without them.
9203 * Should be able to implement this by plopping the entire
9204 * select into a node, then transforming the target expressions
9205 * from whatever they are into count(*), and testing the
9206 * entire result equal to one.
9207 * But, will probably implement a separate node in the executor.
9210 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
9211 errmsg("UNIQUE predicate is not yet implemented"),
9212 parser_errposition(@1)));
9214 | a_expr IS DOCUMENT_P %prec IS
9216 $$ = makeXmlExpr(IS_DOCUMENT, NULL, NIL,
9217 list_make1($1), @2);
9219 | a_expr IS NOT DOCUMENT_P %prec IS
9221 $$ = (Node *) makeA_Expr(AEXPR_NOT, NIL, NULL,
9222 makeXmlExpr(IS_DOCUMENT, NULL, NIL,
9223 list_make1($1), @2),
9229 * Restricted expressions
9231 * b_expr is a subset of the complete expression syntax defined by a_expr.
9233 * Presently, AND, NOT, IS, and IN are the a_expr keywords that would
9234 * cause trouble in the places where b_expr is used. For simplicity, we
9235 * just eliminate all the boolean-keyword-operator productions from b_expr.
9239 | b_expr TYPECAST Typename
9240 { $$ = makeTypeCast($1, $3, @2); }
9241 | '+' b_expr %prec UMINUS
9242 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "+", NULL, $2, @1); }
9243 | '-' b_expr %prec UMINUS
9244 { $$ = doNegate($2, @1); }
9246 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "+", $1, $3, @2); }
9248 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "-", $1, $3, @2); }
9250 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "*", $1, $3, @2); }
9252 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "/", $1, $3, @2); }
9254 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "%", $1, $3, @2); }
9256 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "^", $1, $3, @2); }
9258 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "<", $1, $3, @2); }
9260 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, ">", $1, $3, @2); }
9262 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "=", $1, $3, @2); }
9263 | b_expr qual_Op b_expr %prec Op
9264 { $$ = (Node *) makeA_Expr(AEXPR_OP, $2, $1, $3, @2); }
9265 | qual_Op b_expr %prec Op
9266 { $$ = (Node *) makeA_Expr(AEXPR_OP, $1, NULL, $2, @1); }
9267 | b_expr qual_Op %prec POSTFIXOP
9268 { $$ = (Node *) makeA_Expr(AEXPR_OP, $2, $1, NULL, @2); }
9269 | b_expr IS DISTINCT FROM b_expr %prec IS
9271 $$ = (Node *) makeSimpleA_Expr(AEXPR_DISTINCT, "=", $1, $5, @2);
9273 | b_expr IS NOT DISTINCT FROM b_expr %prec IS
9275 $$ = (Node *) makeA_Expr(AEXPR_NOT, NIL,
9276 NULL, (Node *) makeSimpleA_Expr(AEXPR_DISTINCT, "=", $1, $6, @2), @2);
9278 | b_expr IS OF '(' type_list ')' %prec IS
9280 $$ = (Node *) makeSimpleA_Expr(AEXPR_OF, "=", $1, (Node *) $5, @2);
9282 | b_expr IS NOT OF '(' type_list ')' %prec IS
9284 $$ = (Node *) makeSimpleA_Expr(AEXPR_OF, "<>", $1, (Node *) $6, @2);
9286 | b_expr IS DOCUMENT_P %prec IS
9288 $$ = makeXmlExpr(IS_DOCUMENT, NULL, NIL,
9289 list_make1($1), @2);
9291 | b_expr IS NOT DOCUMENT_P %prec IS
9293 $$ = (Node *) makeA_Expr(AEXPR_NOT, NIL, NULL,
9294 makeXmlExpr(IS_DOCUMENT, NULL, NIL,
9295 list_make1($1), @2),
9301 * Productions that can be used in both a_expr and b_expr.
9303 * Note: productions that refer recursively to a_expr or b_expr mostly
9304 * cannot appear here. However, it's OK to refer to a_exprs that occur
9305 * inside parentheses, such as function arguments; that cannot introduce
9306 * ambiguity to the b_expr syntax.
9308 c_expr: columnref { $$ = $1; }
9309 | AexprConst { $$ = $1; }
9310 | PARAM opt_indirection
9312 ParamRef *p = makeNode(ParamRef);
9317 A_Indirection *n = makeNode(A_Indirection);
9318 n->arg = (Node *) p;
9319 n->indirection = check_indirection($2, yyscanner);
9325 | '(' a_expr ')' opt_indirection
9329 A_Indirection *n = makeNode(A_Indirection);
9331 n->indirection = check_indirection($4, yyscanner);
9341 | select_with_parens %prec UMINUS
9343 SubLink *n = makeNode(SubLink);
9344 n->subLinkType = EXPR_SUBLINK;
9351 | EXISTS select_with_parens
9353 SubLink *n = makeNode(SubLink);
9354 n->subLinkType = EXISTS_SUBLINK;
9361 | ARRAY select_with_parens
9363 SubLink *n = makeNode(SubLink);
9364 n->subLinkType = ARRAY_SUBLINK;
9373 A_ArrayExpr *n = (A_ArrayExpr *) $2;
9374 Assert(IsA(n, A_ArrayExpr));
9375 /* point outermost A_ArrayExpr to the ARRAY keyword */
9381 RowExpr *r = makeNode(RowExpr);
9383 r->row_typeid = InvalidOid; /* not analyzed yet */
9390 * func_expr is split out from c_expr just so that we have a classification
9391 * for "everything that is a function call or looks like one". This isn't
9392 * very important, but it saves us having to document which variants are
9393 * legal in the backwards-compatible functional-index syntax for CREATE INDEX.
9394 * (Note that many of the special SQL functions wouldn't actually make any
9395 * sense as functional index entries, but we ignore that consideration here.)
9397 func_expr: func_name '(' ')' over_clause
9399 FuncCall *n = makeNode(FuncCall);
9403 n->agg_star = FALSE;
9404 n->agg_distinct = FALSE;
9405 n->func_variadic = FALSE;
9410 | func_name '(' func_arg_list ')' over_clause
9412 FuncCall *n = makeNode(FuncCall);
9416 n->agg_star = FALSE;
9417 n->agg_distinct = FALSE;
9418 n->func_variadic = FALSE;
9423 | func_name '(' VARIADIC func_arg_expr ')' over_clause
9425 FuncCall *n = makeNode(FuncCall);
9427 n->args = list_make1($4);
9429 n->agg_star = FALSE;
9430 n->agg_distinct = FALSE;
9431 n->func_variadic = TRUE;
9436 | func_name '(' func_arg_list ',' VARIADIC func_arg_expr ')' over_clause
9438 FuncCall *n = makeNode(FuncCall);
9440 n->args = lappend($3, $6);
9442 n->agg_star = FALSE;
9443 n->agg_distinct = FALSE;
9444 n->func_variadic = TRUE;
9449 | func_name '(' func_arg_list sort_clause ')' over_clause
9451 FuncCall *n = makeNode(FuncCall);
9455 n->agg_star = FALSE;
9456 n->agg_distinct = FALSE;
9457 n->func_variadic = FALSE;
9462 | func_name '(' ALL func_arg_list opt_sort_clause ')' over_clause
9464 FuncCall *n = makeNode(FuncCall);
9468 n->agg_star = FALSE;
9469 n->agg_distinct = FALSE;
9470 /* Ideally we'd mark the FuncCall node to indicate
9471 * "must be an aggregate", but there's no provision
9472 * for that in FuncCall at the moment.
9474 n->func_variadic = FALSE;
9479 | func_name '(' DISTINCT func_arg_list opt_sort_clause ')' over_clause
9481 FuncCall *n = makeNode(FuncCall);
9485 n->agg_star = FALSE;
9486 n->agg_distinct = TRUE;
9487 n->func_variadic = FALSE;
9492 | func_name '(' '*' ')' over_clause
9495 * We consider AGGREGATE(*) to invoke a parameterless
9496 * aggregate. This does the right thing for COUNT(*),
9497 * and there are no other aggregates in SQL92 that accept
9500 * The FuncCall node is also marked agg_star = true,
9501 * so that later processing can detect what the argument
9504 FuncCall *n = makeNode(FuncCall);
9509 n->agg_distinct = FALSE;
9510 n->func_variadic = FALSE;
9518 * Translate as "'now'::text::date".
9520 * We cannot use "'now'::date" because coerce_type() will
9521 * immediately reduce that to a constant representing
9522 * today's date. We need to delay the conversion until
9523 * runtime, else the wrong things will happen when
9524 * CURRENT_DATE is used in a column default value or rule.
9526 * This could be simplified if we had a way to generate
9527 * an expression tree representing runtime application
9528 * of type-input conversion functions. (As of PG 7.3
9529 * that is actually possible, but not clear that we want
9533 n = makeStringConstCast("now", @1, SystemTypeName("text"));
9534 $$ = makeTypeCast(n, SystemTypeName("date"), -1);
9539 * Translate as "'now'::text::timetz".
9540 * See comments for CURRENT_DATE.
9543 n = makeStringConstCast("now", @1, SystemTypeName("text"));
9544 $$ = makeTypeCast(n, SystemTypeName("timetz"), -1);
9546 | CURRENT_TIME '(' Iconst ')'
9549 * Translate as "'now'::text::timetz(n)".
9550 * See comments for CURRENT_DATE.
9554 n = makeStringConstCast("now", @1, SystemTypeName("text"));
9555 d = SystemTypeName("timetz");
9556 d->typmods = list_make1(makeIntConst($3, @3));
9557 $$ = makeTypeCast(n, d, -1);
9562 * Translate as "now()", since we have a function that
9563 * does exactly what is needed.
9565 FuncCall *n = makeNode(FuncCall);
9566 n->funcname = SystemFuncName("now");
9569 n->agg_star = FALSE;
9570 n->agg_distinct = FALSE;
9571 n->func_variadic = FALSE;
9576 | CURRENT_TIMESTAMP '(' Iconst ')'
9579 * Translate as "'now'::text::timestamptz(n)".
9580 * See comments for CURRENT_DATE.
9584 n = makeStringConstCast("now", @1, SystemTypeName("text"));
9585 d = SystemTypeName("timestamptz");
9586 d->typmods = list_make1(makeIntConst($3, @3));
9587 $$ = makeTypeCast(n, d, -1);
9592 * Translate as "'now'::text::time".
9593 * See comments for CURRENT_DATE.
9596 n = makeStringConstCast("now", @1, SystemTypeName("text"));
9597 $$ = makeTypeCast((Node *)n, SystemTypeName("time"), -1);
9599 | LOCALTIME '(' Iconst ')'
9602 * Translate as "'now'::text::time(n)".
9603 * See comments for CURRENT_DATE.
9607 n = makeStringConstCast("now", @1, SystemTypeName("text"));
9608 d = SystemTypeName("time");
9609 d->typmods = list_make1(makeIntConst($3, @3));
9610 $$ = makeTypeCast((Node *)n, d, -1);
9615 * Translate as "'now'::text::timestamp".
9616 * See comments for CURRENT_DATE.
9619 n = makeStringConstCast("now", @1, SystemTypeName("text"));
9620 $$ = makeTypeCast(n, SystemTypeName("timestamp"), -1);
9622 | LOCALTIMESTAMP '(' Iconst ')'
9625 * Translate as "'now'::text::timestamp(n)".
9626 * See comments for CURRENT_DATE.
9630 n = makeStringConstCast("now", @1, SystemTypeName("text"));
9631 d = SystemTypeName("timestamp");
9632 d->typmods = list_make1(makeIntConst($3, @3));
9633 $$ = makeTypeCast(n, d, -1);
9637 FuncCall *n = makeNode(FuncCall);
9638 n->funcname = SystemFuncName("current_user");
9641 n->agg_star = FALSE;
9642 n->agg_distinct = FALSE;
9643 n->func_variadic = FALSE;
9650 FuncCall *n = makeNode(FuncCall);
9651 n->funcname = SystemFuncName("current_user");
9654 n->agg_star = FALSE;
9655 n->agg_distinct = FALSE;
9656 n->func_variadic = FALSE;
9663 FuncCall *n = makeNode(FuncCall);
9664 n->funcname = SystemFuncName("session_user");
9667 n->agg_star = FALSE;
9668 n->agg_distinct = FALSE;
9669 n->func_variadic = FALSE;
9676 FuncCall *n = makeNode(FuncCall);
9677 n->funcname = SystemFuncName("current_user");
9680 n->agg_star = FALSE;
9681 n->agg_distinct = FALSE;
9682 n->func_variadic = FALSE;
9689 FuncCall *n = makeNode(FuncCall);
9690 n->funcname = SystemFuncName("current_database");
9693 n->agg_star = FALSE;
9694 n->agg_distinct = FALSE;
9695 n->func_variadic = FALSE;
9702 FuncCall *n = makeNode(FuncCall);
9703 n->funcname = SystemFuncName("current_schema");
9706 n->agg_star = FALSE;
9707 n->agg_distinct = FALSE;
9708 n->func_variadic = FALSE;
9713 | CAST '(' a_expr AS Typename ')'
9714 { $$ = makeTypeCast($3, $5, @1); }
9715 | EXTRACT '(' extract_list ')'
9717 FuncCall *n = makeNode(FuncCall);
9718 n->funcname = SystemFuncName("date_part");
9721 n->agg_star = FALSE;
9722 n->agg_distinct = FALSE;
9723 n->func_variadic = FALSE;
9728 | OVERLAY '(' overlay_list ')'
9730 /* overlay(A PLACING B FROM C FOR D) is converted to
9731 * overlay(A, B, C, D)
9732 * overlay(A PLACING B FROM C) is converted to
9735 FuncCall *n = makeNode(FuncCall);
9736 n->funcname = SystemFuncName("overlay");
9739 n->agg_star = FALSE;
9740 n->agg_distinct = FALSE;
9741 n->func_variadic = FALSE;
9746 | POSITION '(' position_list ')'
9748 /* position(A in B) is converted to position(B, A) */
9749 FuncCall *n = makeNode(FuncCall);
9750 n->funcname = SystemFuncName("position");
9753 n->agg_star = FALSE;
9754 n->agg_distinct = FALSE;
9755 n->func_variadic = FALSE;
9760 | SUBSTRING '(' substr_list ')'
9762 /* substring(A from B for C) is converted to
9763 * substring(A, B, C) - thomas 2000-11-28
9765 FuncCall *n = makeNode(FuncCall);
9766 n->funcname = SystemFuncName("substring");
9769 n->agg_star = FALSE;
9770 n->agg_distinct = FALSE;
9771 n->func_variadic = FALSE;
9776 | TREAT '(' a_expr AS Typename ')'
9778 /* TREAT(expr AS target) converts expr of a particular type to target,
9779 * which is defined to be a subtype of the original expression.
9780 * In SQL99, this is intended for use with structured UDTs,
9781 * but let's make this a generally useful form allowing stronger
9782 * coercions than are handled by implicit casting.
9784 FuncCall *n = makeNode(FuncCall);
9785 /* Convert SystemTypeName() to SystemFuncName() even though
9786 * at the moment they result in the same thing.
9788 n->funcname = SystemFuncName(((Value *)llast($5->names))->val.str);
9789 n->args = list_make1($3);
9791 n->agg_star = FALSE;
9792 n->agg_distinct = FALSE;
9793 n->func_variadic = FALSE;
9798 | TRIM '(' BOTH trim_list ')'
9800 /* various trim expressions are defined in SQL92
9801 * - thomas 1997-07-19
9803 FuncCall *n = makeNode(FuncCall);
9804 n->funcname = SystemFuncName("btrim");
9807 n->agg_star = FALSE;
9808 n->agg_distinct = FALSE;
9809 n->func_variadic = FALSE;
9814 | TRIM '(' LEADING trim_list ')'
9816 FuncCall *n = makeNode(FuncCall);
9817 n->funcname = SystemFuncName("ltrim");
9820 n->agg_star = FALSE;
9821 n->agg_distinct = FALSE;
9822 n->func_variadic = FALSE;
9827 | TRIM '(' TRAILING trim_list ')'
9829 FuncCall *n = makeNode(FuncCall);
9830 n->funcname = SystemFuncName("rtrim");
9833 n->agg_star = FALSE;
9834 n->agg_distinct = FALSE;
9835 n->func_variadic = FALSE;
9840 | TRIM '(' trim_list ')'
9842 FuncCall *n = makeNode(FuncCall);
9843 n->funcname = SystemFuncName("btrim");
9846 n->agg_star = FALSE;
9847 n->agg_distinct = FALSE;
9848 n->func_variadic = FALSE;
9853 | NULLIF '(' a_expr ',' a_expr ')'
9855 $$ = (Node *) makeSimpleA_Expr(AEXPR_NULLIF, "=", $3, $5, @1);
9857 | COALESCE '(' expr_list ')'
9859 CoalesceExpr *c = makeNode(CoalesceExpr);
9864 | GREATEST '(' expr_list ')'
9866 MinMaxExpr *v = makeNode(MinMaxExpr);
9868 v->op = IS_GREATEST;
9872 | LEAST '(' expr_list ')'
9874 MinMaxExpr *v = makeNode(MinMaxExpr);
9880 | XMLCONCAT '(' expr_list ')'
9882 $$ = makeXmlExpr(IS_XMLCONCAT, NULL, NIL, $3, @1);
9884 | XMLELEMENT '(' NAME_P ColLabel ')'
9886 $$ = makeXmlExpr(IS_XMLELEMENT, $4, NIL, NIL, @1);
9888 | XMLELEMENT '(' NAME_P ColLabel ',' xml_attributes ')'
9890 $$ = makeXmlExpr(IS_XMLELEMENT, $4, $6, NIL, @1);
9892 | XMLELEMENT '(' NAME_P ColLabel ',' expr_list ')'
9894 $$ = makeXmlExpr(IS_XMLELEMENT, $4, NIL, $6, @1);
9896 | XMLELEMENT '(' NAME_P ColLabel ',' xml_attributes ',' expr_list ')'
9898 $$ = makeXmlExpr(IS_XMLELEMENT, $4, $6, $8, @1);
9900 | XMLEXISTS '(' c_expr xmlexists_argument ')'
9902 /* xmlexists(A PASSING [BY REF] B [BY REF]) is
9903 * converted to xmlexists(A, B)*/
9904 FuncCall *n = makeNode(FuncCall);
9905 n->funcname = SystemFuncName("xmlexists");
9906 n->args = list_make2($3, $4);
9908 n->agg_star = FALSE;
9909 n->agg_distinct = FALSE;
9910 n->func_variadic = FALSE;
9915 | XMLFOREST '(' xml_attribute_list ')'
9917 $$ = makeXmlExpr(IS_XMLFOREST, NULL, $3, NIL, @1);
9919 | XMLPARSE '(' document_or_content a_expr xml_whitespace_option ')'
9921 XmlExpr *x = (XmlExpr *)
9922 makeXmlExpr(IS_XMLPARSE, NULL, NIL,
9923 list_make2($4, makeBoolAConst($5, -1)),
9928 | XMLPI '(' NAME_P ColLabel ')'
9930 $$ = makeXmlExpr(IS_XMLPI, $4, NULL, NIL, @1);
9932 | XMLPI '(' NAME_P ColLabel ',' a_expr ')'
9934 $$ = makeXmlExpr(IS_XMLPI, $4, NULL, list_make1($6), @1);
9936 | XMLROOT '(' a_expr ',' xml_root_version opt_xml_root_standalone ')'
9938 $$ = makeXmlExpr(IS_XMLROOT, NULL, NIL,
9939 list_make3($3, $5, $6), @1);
9941 | XMLSERIALIZE '(' document_or_content a_expr AS SimpleTypename ')'
9943 XmlSerialize *n = makeNode(XmlSerialize);
9955 xml_root_version: VERSION_P a_expr
9957 | VERSION_P NO VALUE_P
9958 { $$ = makeNullAConst(-1); }
9961 opt_xml_root_standalone: ',' STANDALONE_P YES_P
9962 { $$ = makeIntConst(XML_STANDALONE_YES, -1); }
9963 | ',' STANDALONE_P NO
9964 { $$ = makeIntConst(XML_STANDALONE_NO, -1); }
9965 | ',' STANDALONE_P NO VALUE_P
9966 { $$ = makeIntConst(XML_STANDALONE_NO_VALUE, -1); }
9968 { $$ = makeIntConst(XML_STANDALONE_OMITTED, -1); }
9971 xml_attributes: XMLATTRIBUTES '(' xml_attribute_list ')' { $$ = $3; }
9974 xml_attribute_list: xml_attribute_el { $$ = list_make1($1); }
9975 | xml_attribute_list ',' xml_attribute_el { $$ = lappend($1, $3); }
9978 xml_attribute_el: a_expr AS ColLabel
9980 $$ = makeNode(ResTarget);
9982 $$->indirection = NIL;
9983 $$->val = (Node *) $1;
9988 $$ = makeNode(ResTarget);
9990 $$->indirection = NIL;
9991 $$->val = (Node *) $1;
9996 document_or_content: DOCUMENT_P { $$ = XMLOPTION_DOCUMENT; }
9997 | CONTENT_P { $$ = XMLOPTION_CONTENT; }
10000 xml_whitespace_option: PRESERVE WHITESPACE_P { $$ = TRUE; }
10001 | STRIP_P WHITESPACE_P { $$ = FALSE; }
10002 | /*EMPTY*/ { $$ = FALSE; }
10005 /* We allow several variants for SQL and other compatibility. */
10006 xmlexists_argument:
10011 | PASSING c_expr BY REF
10015 | PASSING BY REF c_expr
10019 | PASSING BY REF c_expr BY REF
10027 * Window Definitions
10030 WINDOW window_definition_list { $$ = $2; }
10031 | /*EMPTY*/ { $$ = NIL; }
10034 window_definition_list:
10035 window_definition { $$ = list_make1($1); }
10036 | window_definition_list ',' window_definition
10037 { $$ = lappend($1, $3); }
10041 ColId AS window_specification
10049 over_clause: OVER window_specification
10053 WindowDef *n = makeNode(WindowDef);
10056 n->partitionClause = NIL;
10057 n->orderClause = NIL;
10058 n->frameOptions = FRAMEOPTION_DEFAULTS;
10059 n->startOffset = NULL;
10060 n->endOffset = NULL;
10068 window_specification: '(' opt_existing_window_name opt_partition_clause
10069 opt_sort_clause opt_frame_clause ')'
10071 WindowDef *n = makeNode(WindowDef);
10074 n->partitionClause = $3;
10075 n->orderClause = $4;
10076 /* copy relevant fields of opt_frame_clause */
10077 n->frameOptions = $5->frameOptions;
10078 n->startOffset = $5->startOffset;
10079 n->endOffset = $5->endOffset;
10086 * If we see PARTITION, RANGE, or ROWS as the first token after the '('
10087 * of a window_specification, we want the assumption to be that there is
10088 * no existing_window_name; but those keywords are unreserved and so could
10089 * be ColIds. We fix this by making them have the same precedence as IDENT
10090 * and giving the empty production here a slightly higher precedence, so
10091 * that the shift/reduce conflict is resolved in favor of reducing the rule.
10092 * These keywords are thus precluded from being an existing_window_name but
10093 * are not reserved for any other purpose.
10095 opt_existing_window_name: ColId { $$ = $1; }
10096 | /*EMPTY*/ %prec Op { $$ = NULL; }
10099 opt_partition_clause: PARTITION BY expr_list { $$ = $3; }
10100 | /*EMPTY*/ { $$ = NIL; }
10104 * For frame clauses, we return a WindowDef, but only some fields are used:
10105 * frameOptions, startOffset, and endOffset.
10107 * This is only a subset of the full SQL:2008 frame_clause grammar.
10108 * We don't support <window frame exclusion> yet.
10114 n->frameOptions |= FRAMEOPTION_NONDEFAULT | FRAMEOPTION_RANGE;
10115 if (n->frameOptions & (FRAMEOPTION_START_VALUE_PRECEDING |
10116 FRAMEOPTION_END_VALUE_PRECEDING))
10118 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
10119 errmsg("RANGE PRECEDING is only supported with UNBOUNDED"),
10120 parser_errposition(@1)));
10121 if (n->frameOptions & (FRAMEOPTION_START_VALUE_FOLLOWING |
10122 FRAMEOPTION_END_VALUE_FOLLOWING))
10124 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
10125 errmsg("RANGE FOLLOWING is only supported with UNBOUNDED"),
10126 parser_errposition(@1)));
10129 | ROWS frame_extent
10132 n->frameOptions |= FRAMEOPTION_NONDEFAULT | FRAMEOPTION_ROWS;
10137 WindowDef *n = makeNode(WindowDef);
10138 n->frameOptions = FRAMEOPTION_DEFAULTS;
10139 n->startOffset = NULL;
10140 n->endOffset = NULL;
10145 frame_extent: frame_bound
10148 /* reject invalid cases */
10149 if (n->frameOptions & FRAMEOPTION_START_UNBOUNDED_FOLLOWING)
10151 (errcode(ERRCODE_WINDOWING_ERROR),
10152 errmsg("frame start cannot be UNBOUNDED FOLLOWING"),
10153 parser_errposition(@1)));
10154 if (n->frameOptions & FRAMEOPTION_START_VALUE_FOLLOWING)
10156 (errcode(ERRCODE_WINDOWING_ERROR),
10157 errmsg("frame starting from following row cannot end with current row"),
10158 parser_errposition(@1)));
10159 n->frameOptions |= FRAMEOPTION_END_CURRENT_ROW;
10162 | BETWEEN frame_bound AND frame_bound
10164 WindowDef *n1 = $2;
10165 WindowDef *n2 = $4;
10166 /* form merged options */
10167 int frameOptions = n1->frameOptions;
10168 /* shift converts START_ options to END_ options */
10169 frameOptions |= n2->frameOptions << 1;
10170 frameOptions |= FRAMEOPTION_BETWEEN;
10171 /* reject invalid cases */
10172 if (frameOptions & FRAMEOPTION_START_UNBOUNDED_FOLLOWING)
10174 (errcode(ERRCODE_WINDOWING_ERROR),
10175 errmsg("frame start cannot be UNBOUNDED FOLLOWING"),
10176 parser_errposition(@2)));
10177 if (frameOptions & FRAMEOPTION_END_UNBOUNDED_PRECEDING)
10179 (errcode(ERRCODE_WINDOWING_ERROR),
10180 errmsg("frame end cannot be UNBOUNDED PRECEDING"),
10181 parser_errposition(@4)));
10182 if ((frameOptions & FRAMEOPTION_START_CURRENT_ROW) &&
10183 (frameOptions & FRAMEOPTION_END_VALUE_PRECEDING))
10185 (errcode(ERRCODE_WINDOWING_ERROR),
10186 errmsg("frame starting from current row cannot have preceding rows"),
10187 parser_errposition(@4)));
10188 if ((frameOptions & FRAMEOPTION_START_VALUE_FOLLOWING) &&
10189 (frameOptions & (FRAMEOPTION_END_VALUE_PRECEDING |
10190 FRAMEOPTION_END_CURRENT_ROW)))
10192 (errcode(ERRCODE_WINDOWING_ERROR),
10193 errmsg("frame starting from following row cannot have preceding rows"),
10194 parser_errposition(@4)));
10195 n1->frameOptions = frameOptions;
10196 n1->endOffset = n2->startOffset;
10202 * This is used for both frame start and frame end, with output set up on
10203 * the assumption it's frame start; the frame_extent productions must reject
10207 UNBOUNDED PRECEDING
10209 WindowDef *n = makeNode(WindowDef);
10210 n->frameOptions = FRAMEOPTION_START_UNBOUNDED_PRECEDING;
10211 n->startOffset = NULL;
10212 n->endOffset = NULL;
10215 | UNBOUNDED FOLLOWING
10217 WindowDef *n = makeNode(WindowDef);
10218 n->frameOptions = FRAMEOPTION_START_UNBOUNDED_FOLLOWING;
10219 n->startOffset = NULL;
10220 n->endOffset = NULL;
10225 WindowDef *n = makeNode(WindowDef);
10226 n->frameOptions = FRAMEOPTION_START_CURRENT_ROW;
10227 n->startOffset = NULL;
10228 n->endOffset = NULL;
10233 WindowDef *n = makeNode(WindowDef);
10234 n->frameOptions = FRAMEOPTION_START_VALUE_PRECEDING;
10235 n->startOffset = $1;
10236 n->endOffset = NULL;
10241 WindowDef *n = makeNode(WindowDef);
10242 n->frameOptions = FRAMEOPTION_START_VALUE_FOLLOWING;
10243 n->startOffset = $1;
10244 n->endOffset = NULL;
10251 * Supporting nonterminals for expressions.
10254 /* Explicit row production.
10256 * SQL99 allows an optional ROW keyword, so we can now do single-element rows
10257 * without conflicting with the parenthesized a_expr production. Without the
10258 * ROW keyword, there must be more than one a_expr inside the parens.
10260 row: ROW '(' expr_list ')' { $$ = $3; }
10261 | ROW '(' ')' { $$ = NIL; }
10262 | '(' expr_list ',' a_expr ')' { $$ = lappend($2, $4); }
10265 sub_type: ANY { $$ = ANY_SUBLINK; }
10266 | SOME { $$ = ANY_SUBLINK; }
10267 | ALL { $$ = ALL_SUBLINK; }
10270 all_Op: Op { $$ = $1; }
10271 | MathOp { $$ = $1; }
10274 MathOp: '+' { $$ = "+"; }
10275 | '-' { $$ = "-"; }
10276 | '*' { $$ = "*"; }
10277 | '/' { $$ = "/"; }
10278 | '%' { $$ = "%"; }
10279 | '^' { $$ = "^"; }
10280 | '<' { $$ = "<"; }
10281 | '>' { $$ = ">"; }
10282 | '=' { $$ = "="; }
10286 { $$ = list_make1(makeString($1)); }
10287 | OPERATOR '(' any_operator ')'
10293 { $$ = list_make1(makeString($1)); }
10294 | OPERATOR '(' any_operator ')'
10300 { $$ = list_make1(makeString($1)); }
10301 | OPERATOR '(' any_operator ')'
10304 { $$ = list_make1(makeString("~~")); }
10306 { $$ = list_make1(makeString("!~~")); }
10308 { $$ = list_make1(makeString("~~*")); }
10310 { $$ = list_make1(makeString("!~~*")); }
10311 /* cannot put SIMILAR TO here, because SIMILAR TO is a hack.
10312 * the regular expression is preprocessed by a function (similar_escape),
10313 * and the ~ operator for posix regular expressions is used.
10314 * x SIMILAR TO y -> x ~ similar_escape(y)
10315 * this transformation is made on the fly by the parser upwards.
10316 * however the SubLink structure which handles any/some/all stuff
10317 * is not ready for such a thing.
10323 $$ = list_make1($1);
10325 | expr_list ',' a_expr
10327 $$ = lappend($1, $3);
10331 /* function arguments can have names */
10332 func_arg_list: func_arg_expr
10334 $$ = list_make1($1);
10336 | func_arg_list ',' func_arg_expr
10338 $$ = lappend($1, $3);
10342 func_arg_expr: a_expr
10346 | param_name COLON_EQUALS a_expr
10348 NamedArgExpr *na = makeNode(NamedArgExpr);
10350 na->arg = (Expr *) $3;
10351 na->argnumber = -1; /* until determined */
10357 type_list: Typename { $$ = list_make1($1); }
10358 | type_list ',' Typename { $$ = lappend($1, $3); }
10361 array_expr: '[' expr_list ']'
10363 $$ = makeAArrayExpr($2, @1);
10365 | '[' array_expr_list ']'
10367 $$ = makeAArrayExpr($2, @1);
10371 $$ = makeAArrayExpr(NIL, @1);
10375 array_expr_list: array_expr { $$ = list_make1($1); }
10376 | array_expr_list ',' array_expr { $$ = lappend($1, $3); }
10381 extract_arg FROM a_expr
10383 $$ = list_make2(makeStringConst($1, @1), $3);
10385 | /*EMPTY*/ { $$ = NIL; }
10388 /* Allow delimited string Sconst in extract_arg as an SQL extension.
10389 * - thomas 2001-04-12
10393 | YEAR_P { $$ = "year"; }
10394 | MONTH_P { $$ = "month"; }
10395 | DAY_P { $$ = "day"; }
10396 | HOUR_P { $$ = "hour"; }
10397 | MINUTE_P { $$ = "minute"; }
10398 | SECOND_P { $$ = "second"; }
10399 | Sconst { $$ = $1; }
10402 /* OVERLAY() arguments
10403 * SQL99 defines the OVERLAY() function:
10404 * o overlay(text placing text from int for int)
10405 * o overlay(text placing text from int)
10406 * and similarly for binary strings
10409 a_expr overlay_placing substr_from substr_for
10411 $$ = list_make4($1, $2, $3, $4);
10413 | a_expr overlay_placing substr_from
10415 $$ = list_make3($1, $2, $3);
10424 /* position_list uses b_expr not a_expr to avoid conflict with general IN */
10427 b_expr IN_P b_expr { $$ = list_make2($3, $1); }
10428 | /*EMPTY*/ { $$ = NIL; }
10431 /* SUBSTRING() arguments
10432 * SQL9x defines a specific syntax for arguments to SUBSTRING():
10433 * o substring(text from int for int)
10434 * o substring(text from int) get entire string from starting point "int"
10435 * o substring(text for int) get first "int" characters of string
10436 * o substring(text from pattern) get entire string matching pattern
10437 * o substring(text from pattern for escape) same with specified escape char
10438 * We also want to support generic substring functions which accept
10439 * the usual generic list of arguments. So we will accept both styles
10440 * here, and convert the SQL9x style to the generic list for further
10441 * processing. - thomas 2000-11-28
10444 a_expr substr_from substr_for
10446 $$ = list_make3($1, $2, $3);
10448 | a_expr substr_for substr_from
10450 /* not legal per SQL99, but might as well allow it */
10451 $$ = list_make3($1, $3, $2);
10453 | a_expr substr_from
10455 $$ = list_make2($1, $2);
10457 | a_expr substr_for
10460 * Since there are no cases where this syntax allows
10461 * a textual FOR value, we forcibly cast the argument
10462 * to int4. The possible matches in pg_proc are
10463 * substring(text,int4) and substring(text,text),
10464 * and we don't want the parser to choose the latter,
10465 * which it is likely to do if the second argument
10466 * is unknown or doesn't have an implicit cast to int4.
10468 $$ = list_make3($1, makeIntConst(1, -1),
10470 SystemTypeName("int4"), -1));
10481 FROM a_expr { $$ = $2; }
10484 substr_for: FOR a_expr { $$ = $2; }
10487 trim_list: a_expr FROM expr_list { $$ = lappend($3, $1); }
10488 | FROM expr_list { $$ = $2; }
10489 | expr_list { $$ = $1; }
10492 in_expr: select_with_parens
10494 SubLink *n = makeNode(SubLink);
10496 /* other fields will be filled later */
10499 | '(' expr_list ')' { $$ = (Node *)$2; }
10503 * Define SQL92-style case clause.
10504 * - Full specification
10505 * CASE WHEN a = b THEN c ... ELSE d END
10506 * - Implicit argument
10507 * CASE a WHEN b THEN c ... ELSE d END
10509 case_expr: CASE case_arg when_clause_list case_default END_P
10511 CaseExpr *c = makeNode(CaseExpr);
10512 c->casetype = InvalidOid; /* not analyzed yet */
10513 c->arg = (Expr *) $2;
10515 c->defresult = (Expr *) $4;
10522 /* There must be at least one */
10523 when_clause { $$ = list_make1($1); }
10524 | when_clause_list when_clause { $$ = lappend($1, $2); }
10528 WHEN a_expr THEN a_expr
10530 CaseWhen *w = makeNode(CaseWhen);
10531 w->expr = (Expr *) $2;
10532 w->result = (Expr *) $4;
10539 ELSE a_expr { $$ = $2; }
10540 | /*EMPTY*/ { $$ = NULL; }
10543 case_arg: a_expr { $$ = $1; }
10544 | /*EMPTY*/ { $$ = NULL; }
10549 $$ = makeColumnRef($1, NIL, @1, yyscanner);
10551 | ColId indirection
10553 $$ = makeColumnRef($1, $2, @1, yyscanner);
10560 $$ = (Node *) makeString($2);
10564 $$ = (Node *) makeNode(A_Star);
10568 A_Indices *ai = makeNode(A_Indices);
10573 | '[' a_expr ':' a_expr ']'
10575 A_Indices *ai = makeNode(A_Indices);
10583 indirection_el { $$ = list_make1($1); }
10584 | indirection indirection_el { $$ = lappend($1, $2); }
10588 /*EMPTY*/ { $$ = NIL; }
10589 | opt_indirection indirection_el { $$ = lappend($1, $2); }
10592 opt_asymmetric: ASYMMETRIC
10597 * The SQL spec defines "contextually typed value expressions" and
10598 * "contextually typed row value constructors", which for our purposes
10599 * are the same as "a_expr" and "row" except that DEFAULT can appear at
10604 a_expr { $$ = (Node *) $1; }
10607 SetToDefault *n = makeNode(SetToDefault);
10614 ctext_expr { $$ = list_make1($1); }
10615 | ctext_expr_list ',' ctext_expr { $$ = lappend($1, $3); }
10619 * We should allow ROW '(' ctext_expr_list ')' too, but that seems to require
10620 * making VALUES a fully reserved word, which will probably break more apps
10621 * than allowing the noise-word is worth.
10623 ctext_row: '(' ctext_expr_list ')' { $$ = $2; }
10627 /*****************************************************************************
10629 * target list for SELECT
10631 *****************************************************************************/
10634 target_el { $$ = list_make1($1); }
10635 | target_list ',' target_el { $$ = lappend($1, $3); }
10638 target_el: a_expr AS ColLabel
10640 $$ = makeNode(ResTarget);
10642 $$->indirection = NIL;
10643 $$->val = (Node *)$1;
10647 * We support omitting AS only for column labels that aren't
10648 * any known keyword. There is an ambiguity against postfix
10649 * operators: is "a ! b" an infix expression, or a postfix
10650 * expression and a column label? We prefer to resolve this
10651 * as an infix expression, which we accomplish by assigning
10652 * IDENT a precedence higher than POSTFIXOP.
10656 $$ = makeNode(ResTarget);
10658 $$->indirection = NIL;
10659 $$->val = (Node *)$1;
10664 $$ = makeNode(ResTarget);
10666 $$->indirection = NIL;
10667 $$->val = (Node *)$1;
10672 ColumnRef *n = makeNode(ColumnRef);
10673 n->fields = list_make1(makeNode(A_Star));
10676 $$ = makeNode(ResTarget);
10678 $$->indirection = NIL;
10679 $$->val = (Node *)n;
10685 /*****************************************************************************
10687 * Names and constants
10689 *****************************************************************************/
10691 qualified_name_list:
10692 qualified_name { $$ = list_make1($1); }
10693 | qualified_name_list ',' qualified_name { $$ = lappend($1, $3); }
10697 * The production for a qualified relation name has to exactly match the
10698 * production for a qualified func_name, because in a FROM clause we cannot
10699 * tell which we are parsing until we see what comes after it ('(' for a
10700 * func_name, something else for a relation). Therefore we allow 'indirection'
10701 * which may contain subscripts, and reject that case in the C code.
10706 $$ = makeNode(RangeVar);
10707 $$->catalogname = NULL;
10708 $$->schemaname = NULL;
10712 | ColId indirection
10714 check_qualified_name($2, yyscanner);
10715 $$ = makeNode(RangeVar);
10716 switch (list_length($2))
10719 $$->catalogname = NULL;
10720 $$->schemaname = $1;
10721 $$->relname = strVal(linitial($2));
10724 $$->catalogname = $1;
10725 $$->schemaname = strVal(linitial($2));
10726 $$->relname = strVal(lsecond($2));
10730 (errcode(ERRCODE_SYNTAX_ERROR),
10731 errmsg("improper qualified name (too many dotted names): %s",
10732 NameListToString(lcons(makeString($1), $2))),
10733 parser_errposition(@1)));
10741 { $$ = list_make1(makeString($1)); }
10742 | name_list ',' name
10743 { $$ = lappend($1, makeString($3)); }
10747 name: ColId { $$ = $1; };
10750 ColId { $$ = $1; };
10753 ColId { $$ = $1; };
10755 attr_name: ColLabel { $$ = $1; };
10757 index_name: ColId { $$ = $1; };
10759 file_name: Sconst { $$ = $1; };
10762 * The production for a qualified func_name has to exactly match the
10763 * production for a qualified columnref, because we cannot tell which we
10764 * are parsing until we see what comes after it ('(' or Sconst for a func_name,
10765 * anything else for a columnref). Therefore we allow 'indirection' which
10766 * may contain subscripts, and reject that case in the C code. (If we
10767 * ever implement SQL99-like methods, such syntax may actually become legal!)
10769 func_name: type_function_name
10770 { $$ = list_make1(makeString($1)); }
10771 | ColId indirection
10773 $$ = check_func_name(lcons(makeString($1), $2),
10784 $$ = makeIntConst($1, @1);
10788 $$ = makeFloatConst($1, @1);
10792 $$ = makeStringConst($1, @1);
10796 $$ = makeBitStringConst($1, @1);
10800 /* This is a bit constant per SQL99:
10801 * Without Feature F511, "BIT data type",
10802 * a <general literal> shall not be a
10803 * <bit string literal> or a <hex string literal>.
10805 $$ = makeBitStringConst($1, @1);
10809 /* generic type 'literal' syntax */
10810 TypeName *t = makeTypeNameFromNameList($1);
10812 $$ = makeStringConstCast($2, @2, t);
10814 | func_name '(' func_arg_list ')' Sconst
10816 /* generic syntax with a type modifier */
10817 TypeName *t = makeTypeNameFromNameList($1);
10821 * We must use func_arg_list in the production to avoid
10822 * reduce/reduce conflicts, but we don't actually wish
10823 * to allow NamedArgExpr in this context.
10827 NamedArgExpr *arg = (NamedArgExpr *) lfirst(lc);
10829 if (IsA(arg, NamedArgExpr))
10831 (errcode(ERRCODE_SYNTAX_ERROR),
10832 errmsg("type modifier cannot have parameter name"),
10833 parser_errposition(arg->location)));
10837 $$ = makeStringConstCast($5, @5, t);
10839 | ConstTypename Sconst
10841 $$ = makeStringConstCast($2, @2, $1);
10843 | ConstInterval Sconst opt_interval
10847 $$ = makeStringConstCast($2, @2, t);
10849 | ConstInterval '(' Iconst ')' Sconst opt_interval
10854 if (list_length($6) != 1)
10856 (errcode(ERRCODE_SYNTAX_ERROR),
10857 errmsg("interval precision specified twice"),
10858 parser_errposition(@1)));
10859 t->typmods = lappend($6, makeIntConst($3, @3));
10862 t->typmods = list_make2(makeIntConst(INTERVAL_FULL_RANGE, -1),
10863 makeIntConst($3, @3));
10864 $$ = makeStringConstCast($5, @5, t);
10868 $$ = makeBoolAConst(TRUE, @1);
10872 $$ = makeBoolAConst(FALSE, @1);
10876 $$ = makeNullAConst(@1);
10880 Iconst: ICONST { $$ = $1; };
10881 Sconst: SCONST { $$ = $1; };
10882 RoleId: ColId { $$ = $1; };
10884 SignedIconst: Iconst { $$ = $1; }
10885 | '+' Iconst { $$ = + $2; }
10886 | '-' Iconst { $$ = - $2; }
10890 * Name classification hierarchy.
10892 * IDENT is the lexeme returned by the lexer for identifiers that match
10893 * no known keyword. In most cases, we can accept certain keywords as
10894 * names, not only IDENTs. We prefer to accept as many such keywords
10895 * as possible to minimize the impact of "reserved words" on programmers.
10896 * So, we divide names into several possible classes. The classification
10897 * is chosen in part to make keywords acceptable as names wherever possible.
10900 /* Column identifier --- names that can be column, table, etc names.
10902 ColId: IDENT { $$ = $1; }
10903 | unreserved_keyword { $$ = pstrdup($1); }
10904 | col_name_keyword { $$ = pstrdup($1); }
10907 /* Type/function identifier --- names that can be type or function names.
10909 type_function_name: IDENT { $$ = $1; }
10910 | unreserved_keyword { $$ = pstrdup($1); }
10911 | type_func_name_keyword { $$ = pstrdup($1); }
10914 /* Column label --- allowed labels in "AS" clauses.
10915 * This presently includes *all* Postgres keywords.
10917 ColLabel: IDENT { $$ = $1; }
10918 | unreserved_keyword { $$ = pstrdup($1); }
10919 | col_name_keyword { $$ = pstrdup($1); }
10920 | type_func_name_keyword { $$ = pstrdup($1); }
10921 | reserved_keyword { $$ = pstrdup($1); }
10926 * Keyword category lists. Generally, every keyword present in
10927 * the Postgres grammar should appear in exactly one of these lists.
10929 * Put a new keyword into the first list that it can go into without causing
10930 * shift or reduce conflicts. The earlier lists define "less reserved"
10931 * categories of keywords.
10933 * Make sure that each keyword's category in keywords.c matches where
10934 * it is listed here. (Someday we may be able to generate these lists and
10935 * keywords.c's table from a common master list.)
10938 /* "Unreserved" keywords --- available for use as any kind of name.
10940 unreserved_keyword:
11196 /* Column identifier --- keywords that can be column, table, etc names.
11198 * Many of these keywords will in fact be recognized as type or function
11199 * names too; but they have special productions for the purpose, and so
11200 * can't be treated as "generic" type or function names.
11202 * The type names appearing here are not usable as function names
11203 * because they can be followed by '(' in typename productions, which
11204 * looks too much like a function call for an LR(1) parser.
11256 /* Type/function identifier --- keywords that can be type or function names.
11258 * Most of these are keywords that are used as operators in expressions;
11259 * in general such keywords can't be column names because they would be
11260 * ambiguous with variables, but they are unambiguous as function identifiers.
11262 * Do not include POSITION, SUBSTRING, etc here since they have explicit
11263 * productions in a_expr to support the goofy SQL9x argument syntax.
11264 * - thomas 2000-11-28
11266 type_func_name_keyword:
11291 /* Reserved keyword --- these keywords are usable only as a ColLabel.
11293 * Keywords appear here if they could not be distinguished from variable,
11294 * type, or function names in some contexts. Don't put things here unless
11319 | CURRENT_TIMESTAMP
11380 * The signature of this function is required by bison. However, we
11381 * ignore the passed yylloc and instead use the last token position
11382 * available from the scanner.
11385 base_yyerror(YYLTYPE *yylloc, core_yyscan_t yyscanner, const char *msg)
11387 parser_yyerror(msg);
11391 makeColumnRef(char *colname, List *indirection,
11392 int location, core_yyscan_t yyscanner)
11395 * Generate a ColumnRef node, with an A_Indirection node added if there
11396 * is any subscripting in the specified indirection list. However,
11397 * any field selection at the start of the indirection list must be
11398 * transposed into the "fields" part of the ColumnRef node.
11400 ColumnRef *c = makeNode(ColumnRef);
11404 c->location = location;
11405 foreach(l, indirection)
11407 if (IsA(lfirst(l), A_Indices))
11409 A_Indirection *i = makeNode(A_Indirection);
11413 /* easy case - all indirection goes to A_Indirection */
11414 c->fields = list_make1(makeString(colname));
11415 i->indirection = check_indirection(indirection, yyscanner);
11419 /* got to split the list in two */
11420 i->indirection = check_indirection(list_copy_tail(indirection,
11423 indirection = list_truncate(indirection, nfields);
11424 c->fields = lcons(makeString(colname), indirection);
11426 i->arg = (Node *) c;
11429 else if (IsA(lfirst(l), A_Star))
11431 /* We only allow '*' at the end of a ColumnRef */
11432 if (lnext(l) != NULL)
11433 parser_yyerror("improper use of \"*\"");
11437 /* No subscripting, so all indirection gets added to field list */
11438 c->fields = lcons(makeString(colname), indirection);
11443 makeTypeCast(Node *arg, TypeName *typename, int location)
11445 TypeCast *n = makeNode(TypeCast);
11447 n->typeName = typename;
11448 n->location = location;
11453 makeStringConst(char *str, int location)
11455 A_Const *n = makeNode(A_Const);
11457 n->val.type = T_String;
11458 n->val.val.str = str;
11459 n->location = location;
11465 makeStringConstCast(char *str, int location, TypeName *typename)
11467 Node *s = makeStringConst(str, location);
11469 return makeTypeCast(s, typename, -1);
11473 makeIntConst(int val, int location)
11475 A_Const *n = makeNode(A_Const);
11477 n->val.type = T_Integer;
11478 n->val.val.ival = val;
11479 n->location = location;
11485 makeFloatConst(char *str, int location)
11487 A_Const *n = makeNode(A_Const);
11489 n->val.type = T_Float;
11490 n->val.val.str = str;
11491 n->location = location;
11497 makeBitStringConst(char *str, int location)
11499 A_Const *n = makeNode(A_Const);
11501 n->val.type = T_BitString;
11502 n->val.val.str = str;
11503 n->location = location;
11509 makeNullAConst(int location)
11511 A_Const *n = makeNode(A_Const);
11513 n->val.type = T_Null;
11514 n->location = location;
11520 makeAConst(Value *v, int location)
11527 n = makeFloatConst(v->val.str, location);
11531 n = makeIntConst(v->val.ival, location);
11536 n = makeStringConst(v->val.str, location);
11543 /* makeBoolAConst()
11544 * Create an A_Const string node and put it inside a boolean cast.
11547 makeBoolAConst(bool state, int location)
11549 A_Const *n = makeNode(A_Const);
11551 n->val.type = T_String;
11552 n->val.val.str = (state ? "t" : "f");
11553 n->location = location;
11555 return makeTypeCast((Node *)n, SystemTypeName("bool"), -1);
11559 * Create and populate a FuncCall node to support the OVERLAPS operator.
11562 makeOverlaps(List *largs, List *rargs, int location, core_yyscan_t yyscanner)
11564 FuncCall *n = makeNode(FuncCall);
11566 n->funcname = SystemFuncName("overlaps");
11567 if (list_length(largs) == 1)
11568 largs = lappend(largs, largs);
11569 else if (list_length(largs) != 2)
11571 (errcode(ERRCODE_SYNTAX_ERROR),
11572 errmsg("wrong number of parameters on left side of OVERLAPS expression"),
11573 parser_errposition(location)));
11574 if (list_length(rargs) == 1)
11575 rargs = lappend(rargs, rargs);
11576 else if (list_length(rargs) != 2)
11578 (errcode(ERRCODE_SYNTAX_ERROR),
11579 errmsg("wrong number of parameters on right side of OVERLAPS expression"),
11580 parser_errposition(location)));
11581 n->args = list_concat(largs, rargs);
11582 n->agg_order = NIL;
11583 n->agg_star = FALSE;
11584 n->agg_distinct = FALSE;
11585 n->func_variadic = FALSE;
11587 n->location = location;
11591 /* check_qualified_name --- check the result of qualified_name production
11593 * It's easiest to let the grammar production for qualified_name allow
11594 * subscripts and '*', which we then must reject here.
11597 check_qualified_name(List *names, core_yyscan_t yyscanner)
11603 if (!IsA(lfirst(i), String))
11604 parser_yyerror("syntax error");
11608 /* check_func_name --- check the result of func_name production
11610 * It's easiest to let the grammar production for func_name allow subscripts
11611 * and '*', which we then must reject here.
11614 check_func_name(List *names, core_yyscan_t yyscanner)
11620 if (!IsA(lfirst(i), String))
11621 parser_yyerror("syntax error");
11626 /* check_indirection --- check the result of indirection production
11628 * We only allow '*' at the end of the list, but it's hard to enforce that
11629 * in the grammar, so do it here.
11632 check_indirection(List *indirection, core_yyscan_t yyscanner)
11636 foreach(l, indirection)
11638 if (IsA(lfirst(l), A_Star))
11640 if (lnext(l) != NULL)
11641 parser_yyerror("improper use of \"*\"");
11644 return indirection;
11647 /* extractArgTypes()
11648 * Given a list of FunctionParameter nodes, extract a list of just the
11649 * argument types (TypeNames) for input parameters only. This is what
11650 * is needed to look up an existing function, which is what is wanted by
11651 * the productions that use this call.
11654 extractArgTypes(List *parameters)
11656 List *result = NIL;
11659 foreach(i, parameters)
11661 FunctionParameter *p = (FunctionParameter *) lfirst(i);
11663 if (p->mode != FUNC_PARAM_OUT && p->mode != FUNC_PARAM_TABLE)
11664 result = lappend(result, p->argType);
11669 /* findLeftmostSelect()
11670 * Find the leftmost component SelectStmt in a set-operation parsetree.
11672 static SelectStmt *
11673 findLeftmostSelect(SelectStmt *node)
11675 while (node && node->op != SETOP_NONE)
11677 Assert(node && IsA(node, SelectStmt) && node->larg == NULL);
11681 /* insertSelectOptions()
11682 * Insert ORDER BY, etc into an already-constructed SelectStmt.
11684 * This routine is just to avoid duplicating code in SelectStmt productions.
11687 insertSelectOptions(SelectStmt *stmt,
11688 List *sortClause, List *lockingClause,
11689 Node *limitOffset, Node *limitCount,
11690 WithClause *withClause,
11691 core_yyscan_t yyscanner)
11693 Assert(IsA(stmt, SelectStmt));
11696 * Tests here are to reject constructs like
11697 * (SELECT foo ORDER BY bar) ORDER BY baz
11701 if (stmt->sortClause)
11703 (errcode(ERRCODE_SYNTAX_ERROR),
11704 errmsg("multiple ORDER BY clauses not allowed"),
11705 parser_errposition(exprLocation((Node *) sortClause))));
11706 stmt->sortClause = sortClause;
11708 /* We can handle multiple locking clauses, though */
11709 stmt->lockingClause = list_concat(stmt->lockingClause, lockingClause);
11712 if (stmt->limitOffset)
11714 (errcode(ERRCODE_SYNTAX_ERROR),
11715 errmsg("multiple OFFSET clauses not allowed"),
11716 parser_errposition(exprLocation(limitOffset))));
11717 stmt->limitOffset = limitOffset;
11721 if (stmt->limitCount)
11723 (errcode(ERRCODE_SYNTAX_ERROR),
11724 errmsg("multiple LIMIT clauses not allowed"),
11725 parser_errposition(exprLocation(limitCount))));
11726 stmt->limitCount = limitCount;
11730 if (stmt->withClause)
11732 (errcode(ERRCODE_SYNTAX_ERROR),
11733 errmsg("multiple WITH clauses not allowed"),
11734 parser_errposition(exprLocation((Node *) withClause))));
11735 stmt->withClause = withClause;
11740 makeSetOp(SetOperation op, bool all, Node *larg, Node *rarg)
11742 SelectStmt *n = makeNode(SelectStmt);
11746 n->larg = (SelectStmt *) larg;
11747 n->rarg = (SelectStmt *) rarg;
11751 /* SystemFuncName()
11752 * Build a properly-qualified reference to a built-in function.
11755 SystemFuncName(char *name)
11757 return list_make2(makeString("pg_catalog"), makeString(name));
11760 /* SystemTypeName()
11761 * Build a properly-qualified reference to a built-in type.
11763 * typmod is defaulted, but may be changed afterwards by caller.
11764 * Likewise for the location.
11767 SystemTypeName(char *name)
11769 return makeTypeNameFromNameList(list_make2(makeString("pg_catalog"),
11770 makeString(name)));
11774 * Handle negation of a numeric constant.
11776 * Formerly, we did this here because the optimizer couldn't cope with
11777 * indexquals that looked like "var = -4" --- it wants "var = const"
11778 * and a unary minus operator applied to a constant didn't qualify.
11779 * As of Postgres 7.0, that problem doesn't exist anymore because there
11780 * is a constant-subexpression simplifier in the optimizer. However,
11781 * there's still a good reason for doing this here, which is that we can
11782 * postpone committing to a particular internal representation for simple
11783 * negative constants. It's better to leave "-123.456" in string form
11784 * until we know what the desired type is.
11787 doNegate(Node *n, int location)
11789 if (IsA(n, A_Const))
11791 A_Const *con = (A_Const *)n;
11793 /* report the constant's location as that of the '-' sign */
11794 con->location = location;
11796 if (con->val.type == T_Integer)
11798 con->val.val.ival = -con->val.val.ival;
11801 if (con->val.type == T_Float)
11803 doNegateFloat(&con->val);
11808 return (Node *) makeSimpleA_Expr(AEXPR_OP, "-", NULL, n, location);
11812 doNegateFloat(Value *v)
11814 char *oldval = v->val.str;
11816 Assert(IsA(v, Float));
11817 if (*oldval == '+')
11819 if (*oldval == '-')
11820 v->val.str = oldval+1; /* just strip the '-' */
11823 char *newval = (char *) palloc(strlen(oldval) + 2);
11826 strcpy(newval+1, oldval);
11827 v->val.str = newval;
11832 makeAArrayExpr(List *elements, int location)
11834 A_ArrayExpr *n = makeNode(A_ArrayExpr);
11836 n->elements = elements;
11837 n->location = location;
11842 makeXmlExpr(XmlExprOp op, char *name, List *named_args, List *args,
11845 XmlExpr *x = makeNode(XmlExpr);
11850 * named_args is a list of ResTarget; it'll be split apart into separate
11851 * expression and name lists in transformXmlExpr().
11853 x->named_args = named_args;
11854 x->arg_names = NIL;
11856 /* xmloption, if relevant, must be filled in by caller */
11857 /* type and typmod will be filled in during parse analysis */
11858 x->location = location;
11863 * Initialize to parse one query string
11866 parser_init(base_yy_extra_type *yyext)
11868 yyext->parsetree = NIL; /* in case grammar forgets to set it */
11872 * Merge the input and output parameters of a table function.
11875 mergeTableFuncParameters(List *func_args, List *columns)
11879 /* Explicit OUT and INOUT parameters shouldn't be used in this syntax */
11880 foreach(lc, func_args)
11882 FunctionParameter *p = (FunctionParameter *) lfirst(lc);
11884 if (p->mode != FUNC_PARAM_IN && p->mode != FUNC_PARAM_VARIADIC)
11886 (errcode(ERRCODE_SYNTAX_ERROR),
11887 errmsg("OUT and INOUT arguments aren't allowed in TABLE functions")));
11890 return list_concat(func_args, columns);
11894 * Determine return type of a TABLE function. A single result column
11895 * returns setof that column's type; otherwise return setof record.
11898 TableFuncTypeName(List *columns)
11902 if (list_length(columns) == 1)
11904 FunctionParameter *p = (FunctionParameter *) linitial(columns);
11906 result = (TypeName *) copyObject(p->argType);
11909 result = SystemTypeName("record");
11911 result->setof = true;
11917 * Convert a list of (dotted) names to a RangeVar (like
11918 * makeRangeVarFromNameList, but with position support). The
11919 * "AnyName" refers to the any_name production in the grammar.
11922 makeRangeVarFromAnyName(List *names, int position, core_yyscan_t yyscanner)
11924 RangeVar *r = makeNode(RangeVar);
11926 switch (list_length(names))
11929 r->catalogname = NULL;
11930 r->schemaname = NULL;
11931 r->relname = strVal(linitial(names));
11934 r->catalogname = NULL;
11935 r->schemaname = strVal(linitial(names));
11936 r->relname = strVal(lsecond(names));
11939 r->catalogname = strVal(linitial(names));;
11940 r->schemaname = strVal(lsecond(names));
11941 r->relname = strVal(lthird(names));
11945 (errcode(ERRCODE_SYNTAX_ERROR),
11946 errmsg("improper qualified name (too many dotted names): %s",
11947 NameListToString(names)),
11948 parser_errposition(position)));
11952 r->location = position;
11958 * Must undefine this stuff before including scan.c, since it has different
11959 * definitions for these macros.